1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index 2501e6f1f965..38a6a5991da9 100644
8 @@ -264,6 +264,7 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/erofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 14231b4cf383..8765e191ebe0 100644
20 @@ -132,3 +132,4 @@ obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 obj-$(CONFIG_EROFS_FS) += erofs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 9d3a5c54a41d..f33398b47c42 100644
32 @@ -2832,6 +2832,19 @@ F: include/linux/audit.h
33 F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
40 +W: http://aufs.sourceforge.net
41 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/filesystems/aufs/
44 +F: Documentation/ABI/testing/debugfs-aufs
45 +F: Documentation/ABI/testing/sysfs-aufs
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index f6f77eaa7217..5e094699215e 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -738,6 +738,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index e88cf0554e65..7ce4ccf5a51c 100644
85 @@ -1264,7 +1264,7 @@ enum d_walk_ret {
87 * The @enter() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index 3d40771e8e7c..12dd73930961 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
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);
116 diff --git a/fs/inode.c b/fs/inode.c
117 index fef457a42882..aaeacde398ee 100644
120 @@ -1673,7 +1673,7 @@ EXPORT_SYMBOL(generic_update_time);
121 * This does the actual work of updating an inodes time or version. Must have
122 * had called mnt_want_write() before calling this.
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)
127 int (*update_time)(struct inode *, struct timespec64 *, int);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index 2adfe7b166a3..0f7e57e5f4b7 100644
133 @@ -776,6 +776,12 @@ static inline int check_mnt(struct mount *mnt)
134 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137 +/* for aufs, CONFIG_AUFS_BR_FUSE */
138 +int is_current_mnt_ns(struct vfsmount *mnt)
140 + return check_mnt(real_mount(mnt));
144 * vfsmount lock must be held for write
146 diff --git a/fs/read_write.c b/fs/read_write.c
147 index 5bbf587f5bc1..fa9b3994b34c 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -498,6 +498,28 @@ static ssize_t __vfs_write(struct file *file, const char __user *p,
154 +vfs_readf_t vfs_readf(struct file *file)
156 + const struct file_operations *fop = file->f_op;
160 + if (fop->read_iter)
161 + return new_sync_read;
162 + return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
165 +vfs_writef_t vfs_writef(struct file *file)
167 + const struct file_operations *fop = file->f_op;
171 + if (fop->write_iter)
172 + return new_sync_write;
173 + return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
176 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
179 diff --git a/fs/splice.c b/fs/splice.c
180 index 98412721f056..75b489fcb66f 100644
183 @@ -834,8 +834,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
185 * Attempt to initiate a splice from pipe to file.
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)
192 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
193 loff_t *, size_t, unsigned int);
194 @@ -851,9 +851,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
196 * Attempt to initiate a splice from a file to a pipe.
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)
205 ssize_t (*splice_read)(struct file *, loff_t *,
206 struct pipe_inode_info *, size_t, unsigned int);
207 diff --git a/fs/sync.c b/fs/sync.c
208 index 4d1ff010bc5a..457f4e4a5cc1 100644
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.
215 -static int __sync_filesystem(struct super_block *sb, int wait)
216 +int __sync_filesystem(struct super_block *sb, int wait)
220 diff --git a/include/linux/fs.h b/include/linux/fs.h
221 index e0d909d35763..381a13995011 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1349,6 +1349,7 @@ extern void fasync_free(struct fasync_struct *);
225 /* can be called from interrupts */
226 extern void kill_fasync(struct fasync_struct **, int, int);
228 +extern int setfl(int fd, struct file *filp, unsigned long arg);
229 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
230 extern int f_setown(struct file *filp, unsigned long arg, int force);
231 extern void f_delown(struct file *filp);
232 @@ -1835,6 +1836,7 @@ struct file_operations {
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);
240 @@ -1905,6 +1907,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
241 struct iovec *fast_pointer,
242 struct iovec **ret_pointer);
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,
247 +vfs_readf_t vfs_readf(struct file *file);
248 +vfs_writef_t vfs_writef(struct file *file);
250 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
251 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
252 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
253 @@ -2325,6 +2333,7 @@ extern int current_umask(void);
254 extern void ihold(struct inode * inode);
255 extern void iput(struct inode *);
256 extern int generic_update_time(struct inode *, struct timespec64 *, int);
257 +extern int update_time(struct inode *, struct timespec64 *, int);
260 extern struct kobject *fs_kobj;
261 @@ -2613,6 +2622,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
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;
269 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
270 index b8a835fd611b..f452521f2e05 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -331,6 +331,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
274 return lock->key == key;
277 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
282 @@ -473,6 +475,7 @@ struct lockdep_map { };
284 #define lockdep_depth(tsk) (0)
286 +#define lockdep_is_held(lock) (1)
287 #define lockdep_is_held_type(l, r) (1)
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
291 index 35942084cd40..24f5fd1a789d 100644
292 --- a/include/linux/mnt_namespace.h
293 +++ b/include/linux/mnt_namespace.h
295 struct mnt_namespace;
297 struct user_namespace;
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);
304 +extern int is_current_mnt_ns(struct vfsmount *mnt);
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;
309 diff --git a/include/linux/splice.h b/include/linux/splice.h
310 index 74b4911ac16d..19789fbea567 100644
311 --- a/include/linux/splice.h
312 +++ b/include/linux/splice.h
313 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
315 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
316 extern const struct pipe_buf_operations default_pipe_buf_ops;
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);
324 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
325 index 233459c03b5a..407c08ac8ac8 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -153,7 +153,7 @@ static
329 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
330 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
332 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
333 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
335 unsigned int class_idx = hlock->class_idx;
337 @@ -174,6 +174,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
339 return lock_classes + class_idx;
341 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
343 #ifdef CONFIG_LOCK_STAT
344 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
345 SPDX-License-Identifier: GPL-2.0
348 diff --git a/fs/proc/base.c b/fs/proc/base.c
349 index ebea9501afb8..dc7edc5f7267 100644
352 @@ -2037,7 +2037,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
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;
361 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
362 index 14c2badb8fd9..65afe5287e43 100644
363 --- a/fs/proc/nommu.c
364 +++ b/fs/proc/nommu.c
365 @@ -41,7 +41,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
366 file = region->vm_file;
369 - struct inode *inode = file_inode(region->vm_file);
370 + struct inode *inode;
372 + file = vmr_pr_or_file(region);
373 + inode = file_inode(file);
374 dev = inode->i_sb->s_dev;
377 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
378 index 9442631fd4af..1fa8a5fcdeee 100644
379 --- a/fs/proc/task_mmu.c
380 +++ b/fs/proc/task_mmu.c
381 @@ -309,7 +309,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
382 const char *name = NULL;
385 - struct inode *inode = file_inode(vma->vm_file);
386 + struct inode *inode;
388 + file = vma_pr_or_file(vma);
389 + inode = file_inode(file);
390 dev = inode->i_sb->s_dev;
392 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
393 @@ -1819,7 +1822,7 @@ static int show_numa_map(struct seq_file *m, void *v)
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);
399 struct mm_struct *mm = vma->vm_mm;
400 struct mempolicy *pol;
402 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
403 index 7907e6419e57..d17209cf52bc 100644
404 --- a/fs/proc/task_nommu.c
405 +++ b/fs/proc/task_nommu.c
406 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
410 - struct inode *inode = file_inode(vma->vm_file);
411 + struct inode *inode;
413 + file = vma_pr_or_file(vma);
414 + inode = file_inode(file);
415 dev = inode->i_sb->s_dev;
417 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
418 diff --git a/include/linux/mm.h b/include/linux/mm.h
419 index a2adf95b3f9c..70e1dccc1283 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1510,6 +1510,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
423 unmap_mapping_range(mapping, holebegin, holelen, 0);
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[],
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);
432 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
434 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
436 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
437 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
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);
443 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
445 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
446 +#endif /* !CONFIG_MMU */
448 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
449 void *buf, int len, unsigned int gup_flags);
450 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
451 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
452 index 270aa8fd2800..33848c2165e2 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -267,6 +267,7 @@ struct vm_region {
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 */
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
463 @@ -341,6 +342,7 @@ struct vm_area_struct {
464 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
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) */
471 diff --git a/kernel/fork.c b/kernel/fork.c
472 index 13b38794efb5..ede7225bae95 100644
475 @@ -562,7 +562,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
476 struct inode *inode = file_inode(file);
477 struct address_space *mapping = file->f_mapping;
481 if (tmp->vm_flags & VM_DENYWRITE)
482 atomic_dec(&inode->i_writecount);
483 i_mmap_lock_write(mapping);
484 diff --git a/mm/Makefile b/mm/Makefile
485 index d996846697ef..fbadb91df4e4 100644
488 @@ -42,7 +42,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
489 mm_init.o mmu_context.o percpu.o slab_common.o \
490 compaction.o vmacache.o \
491 interval_tree.o list_lru.o workingset.o \
492 - debug.o gup.o $(mmu-y)
493 + prfile.o debug.o gup.o $(mmu-y)
495 # Give 'page_alloc' its own module-parameter namespace
496 page-alloc-y := page_alloc.o
497 diff --git a/mm/filemap.c b/mm/filemap.c
498 index 85b7d087eb45..115275a4a0e2 100644
501 @@ -2696,7 +2696,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
502 vm_fault_t ret = VM_FAULT_LOCKED;
504 sb_start_pagefault(inode->i_sb);
505 - file_update_time(vmf->vma->vm_file);
506 + vma_file_update_time(vmf->vma);
508 if (page->mapping != inode->i_mapping) {
510 diff --git a/mm/mmap.c b/mm/mmap.c
511 index a7d8c84d19b7..9c350dc3f570 100644
514 @@ -182,7 +182,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
515 if (vma->vm_ops && vma->vm_ops->close)
516 vma->vm_ops->close(vma);
518 - fput(vma->vm_file);
520 mpol_put(vma_policy(vma));
523 @@ -940,7 +940,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
526 uprobe_munmap(next, next->vm_start, next->vm_end);
531 anon_vma_merge(vma, next);
532 @@ -1865,8 +1865,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
540 /* Undo any partial mapping done by a device driver. */
541 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
542 @@ -2695,7 +2695,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
546 - get_file(new->vm_file);
549 if (new->vm_ops && new->vm_ops->open)
550 new->vm_ops->open(new);
551 @@ -2714,7 +2714,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
552 if (new->vm_ops && new->vm_ops->close)
553 new->vm_ops->close(new);
555 - fput(new->vm_file);
557 unlink_anon_vmas(new);
559 mpol_put(vma_policy(new));
560 @@ -2906,7 +2906,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
561 struct vm_area_struct *vma;
562 unsigned long populate = 0;
563 unsigned long ret = -EINVAL;
565 + struct file *file, *prfile;
567 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
568 current->comm, current->pid);
569 @@ -2981,10 +2981,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 - file = get_file(vma->vm_file);
575 + file = vma->vm_file;
576 + prfile = vma->vm_prfile;
577 ret = do_mmap_pgoff(vma->vm_file, start, size,
578 prot, flags, pgoff, &populate, NULL);
579 + if (!IS_ERR_VALUE(ret) && file && prfile) {
580 + struct vm_area_struct *new_vma;
582 + new_vma = find_vma(mm, ret);
583 + if (!new_vma->vm_prfile)
584 + new_vma->vm_prfile = prfile;
585 + if (new_vma != vma)
589 + * two fput()s instead of vma_fput(vma),
590 + * coz vma may not be available anymore.
596 up_write(&mm->mmap_sem);
598 @@ -3274,7 +3291,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
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);
607 diff --git a/mm/nommu.c b/mm/nommu.c
608 index 99b7ec318824..de5b6cd162fe 100644
611 @@ -552,7 +552,7 @@ static void __put_nommu_region(struct vm_region *region)
612 up_write(&nommu_region_sem);
615 - fput(region->vm_file);
618 /* IO memory and memory shared directly out of the pagecache
619 * from ramfs/tmpfs mustn't be released here */
620 @@ -690,7 +690,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
621 if (vma->vm_ops && vma->vm_ops->close)
622 vma->vm_ops->close(vma);
624 - fput(vma->vm_file);
626 put_nommu_region(vma->vm_region);
629 @@ -1213,7 +1213,7 @@ unsigned long do_mmap(struct file *file,
630 goto error_just_free;
633 - fput(region->vm_file);
635 kmem_cache_free(vm_region_jar, region);
638 @@ -1290,10 +1290,10 @@ unsigned long do_mmap(struct file *file,
639 up_write(&nommu_region_sem);
642 - fput(region->vm_file);
644 kmem_cache_free(vm_region_jar, region);
646 - fput(vma->vm_file);
651 diff --git a/mm/prfile.c b/mm/prfile.c
653 index 000000000000..00d51187c325
657 +// SPDX-License-Identifier: GPL-2.0
659 + * Mainly for aufs which mmap(2) different file and wants to print different
660 + * path in /proc/PID/maps.
661 + * Call these functions via macros defined in linux/mm.h.
663 + * See Documentation/filesystems/aufs/design/06mmap.txt
665 + * Copyright (c) 2014-2020 Junjro R. Okajima
666 + * Copyright (c) 2014 Ian Campbell
669 +#include <linux/mm.h>
670 +#include <linux/file.h>
671 +#include <linux/fs.h>
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[])
679 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
683 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
686 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
688 + prfile_trace(f, pr, func, line, __func__);
689 + file_update_time(f);
691 + file_update_time(pr);
694 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
697 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
699 + prfile_trace(f, pr, func, line, __func__);
700 + return (f && pr) ? pr : f;
703 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
705 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
707 + prfile_trace(f, pr, func, line, __func__);
713 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
715 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
717 + prfile_trace(f, pr, func, line, __func__);
724 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
727 + struct file *f = region->vm_file, *pr = region->vm_prfile;
729 + prfile_trace(f, pr, func, line, __func__);
730 + return (f && pr) ? pr : f;
733 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
735 + struct file *f = region->vm_file, *pr = region->vm_prfile;
737 + prfile_trace(f, pr, func, line, __func__);
742 +#endif /* !CONFIG_MMU */
743 SPDX-License-Identifier: GPL-2.0
744 aufs5.4 standalone patch
746 diff --git a/fs/dcache.c b/fs/dcache.c
747 index 7ce4ccf5a51c..00d7e6a08026 100644
750 @@ -1369,6 +1369,7 @@ void d_walk(struct dentry *parent, void *data,
754 +EXPORT_SYMBOL_GPL(d_walk);
757 struct vfsmount *mnt;
758 @@ -2914,6 +2915,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
760 write_sequnlock(&rename_lock);
762 +EXPORT_SYMBOL_GPL(d_exchange);
765 * d_ancestor - search for an ancestor
766 diff --git a/fs/exec.c b/fs/exec.c
767 index 555e93c7dec8..dad39c6b3878 100644
770 @@ -110,6 +110,7 @@ bool path_noexec(const struct path *path)
771 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
772 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
774 +EXPORT_SYMBOL_GPL(path_noexec);
778 diff --git a/fs/fcntl.c b/fs/fcntl.c
779 index 12dd73930961..0468c845190f 100644
782 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
786 +EXPORT_SYMBOL_GPL(setfl);
788 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
790 diff --git a/fs/file_table.c b/fs/file_table.c
791 index 30d55c9a1744..34b9bbf4c556 100644
792 --- a/fs/file_table.c
793 +++ b/fs/file_table.c
794 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
796 return ERR_PTR(-ENFILE);
798 +EXPORT_SYMBOL_GPL(alloc_empty_file);
801 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
802 diff --git a/fs/inode.c b/fs/inode.c
803 index aaeacde398ee..5be87f2d3828 100644
806 @@ -1682,6 +1682,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
808 return update_time(inode, time, flags);
810 +EXPORT_SYMBOL_GPL(update_time);
813 * touch_atime - update the access time
814 diff --git a/fs/namespace.c b/fs/namespace.c
815 index 0f7e57e5f4b7..516c2f397d33 100644
818 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
819 mnt_dec_writers(real_mount(mnt));
822 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
825 * mnt_drop_write - give up write access to a mount
826 @@ -781,6 +782,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
828 return check_mnt(real_mount(mnt));
830 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
833 * vfsmount lock must be held for write
834 @@ -1903,6 +1905,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
838 +EXPORT_SYMBOL_GPL(iterate_mounts);
840 static void lock_mnt_tree(struct mount *mnt)
842 diff --git a/fs/notify/group.c b/fs/notify/group.c
843 index 133f723aca07..0b9f7f6d8390 100644
844 --- a/fs/notify/group.c
845 +++ b/fs/notify/group.c
846 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
848 refcount_inc(&group->refcnt);
850 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
853 * Drop a reference to a group. Free it if it's through.
854 diff --git a/fs/open.c b/fs/open.c
855 index b62f5c0923a8..89af4b9c7319 100644
858 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
859 inode_unlock(dentry->d_inode);
862 +EXPORT_SYMBOL_GPL(do_truncate);
864 long vfs_truncate(const struct path *path, loff_t length)
866 diff --git a/fs/read_write.c b/fs/read_write.c
867 index fa9b3994b34c..eb0e2c6ebaff 100644
868 --- a/fs/read_write.c
869 +++ b/fs/read_write.c
870 @@ -468,6 +468,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
874 +EXPORT_SYMBOL_GPL(vfs_read);
876 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
878 @@ -508,6 +509,7 @@ vfs_readf_t vfs_readf(struct file *file)
879 return new_sync_read;
880 return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
882 +EXPORT_SYMBOL_GPL(vfs_readf);
884 vfs_writef_t vfs_writef(struct file *file)
886 @@ -519,6 +521,7 @@ vfs_writef_t vfs_writef(struct file *file)
887 return new_sync_write;
888 return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
890 +EXPORT_SYMBOL_GPL(vfs_writef);
892 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
894 @@ -588,6 +591,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
898 +EXPORT_SYMBOL_GPL(vfs_write);
900 /* file_ppos returns &file->f_pos or NULL if file is stream */
901 static inline loff_t *file_ppos(struct file *file)
902 diff --git a/fs/splice.c b/fs/splice.c
903 index 75b489fcb66f..0a1f7498c22b 100644
906 @@ -847,6 +847,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
908 return splice_write(pipe, out, ppos, len, flags);
910 +EXPORT_SYMBOL_GPL(do_splice_from);
913 * Attempt to initiate a splice from a file to a pipe.
914 @@ -876,6 +877,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
916 return splice_read(in, ppos, pipe, len, flags);
918 +EXPORT_SYMBOL_GPL(do_splice_to);
921 * splice_direct_to_actor - splices data directly between two non-pipes
922 diff --git a/fs/sync.c b/fs/sync.c
923 index 457f4e4a5cc1..67c66358f3fe 100644
926 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
927 sb->s_op->sync_fs(sb, wait);
928 return __sync_blockdev(sb->s_bdev, wait);
930 +EXPORT_SYMBOL_GPL(__sync_filesystem);
933 * Write out and wait upon all dirty data associated with this
934 diff --git a/fs/xattr.c b/fs/xattr.c
935 index 90dd78f0eb27..40b01dd1b14a 100644
938 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
939 *xattr_value = value;
942 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
945 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
946 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
947 index 407c08ac8ac8..d7f71842f8a2 100644
948 --- a/kernel/locking/lockdep.c
949 +++ b/kernel/locking/lockdep.c
950 @@ -174,6 +174,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
952 return lock_classes + class_idx;
954 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
955 #define hlock_class(hlock) lockdep_hlock_class(hlock)
957 #ifdef CONFIG_LOCK_STAT
958 diff --git a/kernel/task_work.c b/kernel/task_work.c
959 index 0fef395662a6..83fb1ecfc33d 100644
960 --- a/kernel/task_work.c
961 +++ b/kernel/task_work.c
962 @@ -116,3 +116,4 @@ void task_work_run(void)
966 +EXPORT_SYMBOL_GPL(task_work_run);
967 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
968 index 725674f3276d..83f6494c52a2 100644
969 --- a/security/device_cgroup.c
970 +++ b/security/device_cgroup.c
971 @@ -824,3 +824,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
975 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
976 diff --git a/security/security.c b/security/security.c
977 index 1bc000f834e2..306f2c9f7ee2 100644
978 --- a/security/security.c
979 +++ b/security/security.c
980 @@ -1036,6 +1036,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
982 return call_int_hook(path_rmdir, 0, dir, dentry);
984 +EXPORT_SYMBOL_GPL(security_path_rmdir);
986 int security_path_unlink(const struct path *dir, struct dentry *dentry)
988 @@ -1052,6 +1053,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
990 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
992 +EXPORT_SYMBOL_GPL(security_path_symlink);
994 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
995 struct dentry *new_dentry)
996 @@ -1060,6 +1062,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
998 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1000 +EXPORT_SYMBOL_GPL(security_path_link);
1002 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1003 const struct path *new_dir, struct dentry *new_dentry,
1004 @@ -1087,6 +1090,7 @@ int security_path_truncate(const struct path *path)
1006 return call_int_hook(path_truncate, 0, path);
1008 +EXPORT_SYMBOL_GPL(security_path_truncate);
1010 int security_path_chmod(const struct path *path, umode_t mode)
1012 @@ -1094,6 +1098,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1014 return call_int_hook(path_chmod, 0, path, mode);
1016 +EXPORT_SYMBOL_GPL(security_path_chmod);
1018 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1020 @@ -1101,6 +1106,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1022 return call_int_hook(path_chown, 0, path, uid, gid);
1024 +EXPORT_SYMBOL_GPL(security_path_chown);
1026 int security_path_chroot(const struct path *path)
1028 @@ -1201,6 +1207,7 @@ int security_inode_permission(struct inode *inode, int mask)
1030 return call_int_hook(inode_permission, 0, inode, mask);
1032 +EXPORT_SYMBOL_GPL(security_inode_permission);
1034 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1036 @@ -1378,6 +1385,7 @@ int security_file_permission(struct file *file, int mask)
1038 return fsnotify_perm(file, mask);
1040 +EXPORT_SYMBOL_GPL(security_file_permission);
1042 int security_file_alloc(struct file *file)
1044 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1045 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1046 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200
1048 +What: /debug/aufs/si_<id>/
1050 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1052 + Under /debug/aufs, a directory named si_<id> is created
1053 + per aufs mount, where <id> is a unique id generated
1056 +What: /debug/aufs/si_<id>/plink
1058 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1060 + It has three lines and shows the information about the
1061 + pseudo-link. The first line is a single number
1062 + representing a number of buckets. The second line is a
1063 + number of pseudo-links per buckets (separated by a
1064 + blank). The last line is a single number representing a
1065 + total number of psedo-links.
1066 + When the aufs mount option 'noplink' is specified, it
1067 + will show "1\n0\n0\n".
1069 +What: /debug/aufs/si_<id>/xib
1071 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1073 + It shows the consumed blocks by xib (External Inode Number
1074 + Bitmap), its block size and file size.
1075 + When the aufs mount option 'noxino' is specified, it
1076 + will be empty. About XINO files, see the aufs manual.
1078 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1080 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1082 + It shows the consumed blocks by xino (External Inode Number
1083 + Translation Table), its link count, block size and file
1085 + Due to the file size limit, there may exist multiple
1086 + xino files per branch. In this case, "-N" is added to
1087 + the filename and it corresponds to the index of the
1088 + internal xino array. "-0" is omitted.
1089 + When the aufs mount option 'noxino' is specified, Those
1090 + entries won't exist. About XINO files, see the aufs
1093 +What: /debug/aufs/si_<id>/xigen
1095 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1097 + It shows the consumed blocks by xigen (External Inode
1098 + Generation Table), its block size and file size.
1099 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1101 + When the aufs mount option 'noxino' is specified, it
1102 + will be empty. About XINO files, see the aufs manual.
1103 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1104 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1105 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200
1107 +What: /sys/fs/aufs/si_<id>/
1109 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1111 + Under /sys/fs/aufs, a directory named si_<id> is created
1112 + per aufs mount, where <id> is a unique id generated
1115 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1117 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1119 + It shows the abolute path of a member directory (which
1120 + is called branch) in aufs, and its permission.
1122 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1124 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1126 + It shows the id of a member directory (which is called
1129 +What: /sys/fs/aufs/si_<id>/xi_path
1131 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1133 + It shows the abolute path of XINO (External Inode Number
1134 + Bitmap, Translation Table and Generation Table) file
1135 + even if it is the default path.
1136 + When the aufs mount option 'noxino' is specified, it
1137 + will be empty. About XINO files, see the aufs manual.
1138 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1139 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1140 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2020-01-27 10:57:18.162204582 +0100
1143 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1145 +# This program is free software; you can redistribute it and/or modify
1146 +# it under the terms of the GNU General Public License as published by
1147 +# the Free Software Foundation; either version 2 of the License, or
1148 +# (at your option) any later version.
1150 +# This program is distributed in the hope that it will be useful,
1151 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1152 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1153 +# GNU General Public License for more details.
1155 +# You should have received a copy of the GNU General Public License
1156 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1159 +----------------------------------------
1161 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1162 +1. abbrev. for "advanced multi-layered unification filesystem".
1163 +2. abbrev. for "another unionfs".
1164 +3. abbrev. for "auf das" in German which means "on the" in English.
1165 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1166 + But "Filesystem aufs Filesystem" is hard to understand.
1167 +4. abbrev. for "African Urban Fashion Show".
1169 +AUFS is a filesystem with features:
1170 +- multi layered stackable unification filesystem, the member directory
1171 + is called as a branch.
1172 +- branch permission and attribute, 'readonly', 'real-readonly',
1173 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1175 +- internal "file copy-on-write".
1176 +- logical deletion, whiteout.
1177 +- dynamic branch manipulation, adding, deleting and changing permission.
1178 +- allow bypassing aufs, user's direct branch access.
1179 +- external inode number translation table and bitmap which maintains the
1180 + persistent aufs inode number.
1181 +- seekable directory, including NFS readdir.
1182 +- file mapping, mmap and sharing pages.
1183 +- pseudo-link, hardlink over branches.
1184 +- loopback mounted filesystem as a branch.
1185 +- several policies to select one among multiple writable branches.
1186 +- revert a single systemcall when an error occurs in aufs.
1190 +Multi Layered Stackable Unification Filesystem
1191 +----------------------------------------------------------------------
1192 +Most people already knows what it is.
1193 +It is a filesystem which unifies several directories and provides a
1194 +merged single directory. When users access a file, the access will be
1195 +passed/re-directed/converted (sorry, I am not sure which English word is
1196 +correct) to the real file on the member filesystem. The member
1197 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1198 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1199 +readonly branch is handled by creating 'whiteout' on the upper writable
1202 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1203 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1204 +different approaches to implement the merged-view.
1205 +The former tries putting it into VFS, and the latter implements as a
1206 +separate filesystem.
1207 +(If I misunderstand about these implementations, please let me know and
1208 +I shall correct it. Because it is a long time ago when I read their
1209 +source files last time).
1211 +UnionMount's approach will be able to small, but may be hard to share
1212 +branches between several UnionMount since the whiteout in it is
1213 +implemented in the inode on branch filesystem and always
1214 +shared. According to Bharata's post, readdir does not seems to be
1216 +There are several missing features known in this implementations such as
1217 +- for users, the inode number may change silently. eg. copy-up.
1218 +- link(2) may break by copy-up.
1219 +- read(2) may get an obsoleted filedata (fstat(2) too).
1220 +- fcntl(F_SETLK) may be broken by copy-up.
1221 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1224 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1225 +merged into mainline. This is another implementation of UnionMount as a
1226 +separated filesystem. All the limitations and known problems which
1227 +UnionMount are equally inherited to "overlay" filesystem.
1229 +Unionfs has a longer history. When I started implementing a stackable
1230 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1231 +inode, dentry and file objects and they have an array pointing lower
1232 +same kind objects. After contributing many patches for Unionfs, I
1233 +re-started my project AUFS (Jun 2006).
1235 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1236 +implemented my own ideas, approaches and enhancements and it became
1237 +totally different one.
1239 +Comparing DM snapshot and fs based implementation
1240 +- the number of bytes to be copied between devices is much smaller.
1241 +- the type of filesystem must be one and only.
1242 +- the fs must be writable, no readonly fs, even for the lower original
1243 + device. so the compression fs will not be usable. but if we use
1244 + loopback mount, we may address this issue.
1246 + mount /cdrom/squashfs.img /sq
1247 + losetup /sq/ext2.img
1248 + losetup /somewhere/cow
1249 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1250 +- it will be difficult (or needs more operations) to extract the
1251 + difference between the original device and COW.
1252 +- DM snapshot-merge may help a lot when users try merging. in the
1253 + fs-layer union, users will use rsync(1).
1255 +You may want to read my old paper "Filesystems in LiveCD"
1256 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1259 +Several characters/aspects/persona of aufs
1260 +----------------------------------------------------------------------
1262 +Aufs has several characters, aspects or persona.
1263 +1. a filesystem, callee of VFS helper
1264 +2. sub-VFS, caller of VFS helper for branches
1265 +3. a virtual filesystem which maintains persistent inode number
1266 +4. reader/writer of files on branches such like an application
1268 +1. Callee of VFS Helper
1269 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1270 +unlink(2) from an application reaches sys_unlink() kernel function and
1271 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1272 +calls filesystem specific unlink operation. Actually aufs implements the
1273 +unlink operation but it behaves like a redirector.
1275 +2. Caller of VFS Helper for Branches
1276 +aufs_unlink() passes the unlink request to the branch filesystem as if
1277 +it were called from VFS. So the called unlink operation of the branch
1278 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1279 +every necessary pre/post operation for the branch filesystem.
1280 +- acquire the lock for the parent dir on a branch
1281 +- lookup in a branch
1282 +- revalidate dentry on a branch
1283 +- mnt_want_write() for a branch
1284 +- vfs_unlink() for a branch
1285 +- mnt_drop_write() for a branch
1286 +- release the lock on a branch
1288 +3. Persistent Inode Number
1289 +One of the most important issue for a filesystem is to maintain inode
1290 +numbers. This is particularly important to support exporting a
1291 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1292 +backend block device for its own. But some storage is necessary to
1293 +keep and maintain the inode numbers. It may be a large space and may not
1294 +suit to keep in memory. Aufs rents some space from its first writable
1295 +branch filesystem (by default) and creates file(s) on it. These files
1296 +are created by aufs internally and removed soon (currently) keeping
1298 +Note: Because these files are removed, they are totally gone after
1299 + unmounting aufs. It means the inode numbers are not persistent
1300 + across unmount or reboot. I have a plan to make them really
1301 + persistent which will be important for aufs on NFS server.
1303 +4. Read/Write Files Internally (copy-on-write)
1304 +Because a branch can be readonly, when you write a file on it, aufs will
1305 +"copy-up" it to the upper writable branch internally. And then write the
1306 +originally requested thing to the file. Generally kernel doesn't
1307 +open/read/write file actively. In aufs, even a single write may cause a
1308 +internal "file copy". This behaviour is very similar to cp(1) command.
1310 +Some people may think it is better to pass such work to user space
1311 +helper, instead of doing in kernel space. Actually I am still thinking
1312 +about it. But currently I have implemented it in kernel space.
1313 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1314 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1315 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2020-01-27 10:57:18.162204582 +0100
1318 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1320 +# This program is free software; you can redistribute it and/or modify
1321 +# it under the terms of the GNU General Public License as published by
1322 +# the Free Software Foundation; either version 2 of the License, or
1323 +# (at your option) any later version.
1325 +# This program is distributed in the hope that it will be useful,
1326 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1327 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1328 +# GNU General Public License for more details.
1330 +# You should have received a copy of the GNU General Public License
1331 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1333 +Basic Aufs Internal Structure
1335 +Superblock/Inode/Dentry/File Objects
1336 +----------------------------------------------------------------------
1337 +As like an ordinary filesystem, aufs has its own
1338 +superblock/inode/dentry/file objects. All these objects have a
1339 +dynamically allocated array and store the same kind of pointers to the
1340 +lower filesystem, branch.
1341 +For example, when you build a union with one readwrite branch and one
1342 +readonly, mounted /au, /rw and /ro respectively.
1344 +- /ro/fileA exists but /rw/fileA
1346 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1347 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1348 +- [0] = NULL (because /rw/fileA doesn't exist)
1351 +This style of an array is essentially same to the aufs
1352 +superblock/inode/dentry/file objects.
1354 +Because aufs supports manipulating branches, ie. add/delete/change
1355 +branches dynamically, these objects has its own generation. When
1356 +branches are changed, the generation in aufs superblock is
1357 +incremented. And a generation in other object are compared when it is
1358 +accessed. When a generation in other objects are obsoleted, aufs
1359 +refreshes the internal array.
1363 +----------------------------------------------------------------------
1364 +Additionally aufs superblock has some data for policies to select one
1365 +among multiple writable branches, XIB files, pseudo-links and kobject.
1366 +See below in detail.
1367 +About the policies which supports copy-down a directory, see
1368 +wbr_policy.txt too.
1371 +Branch and XINO(External Inode Number Translation Table)
1372 +----------------------------------------------------------------------
1373 +Every branch has its own xino (external inode number translation table)
1374 +file. The xino file is created and unlinked by aufs internally. When two
1375 +members of a union exist on the same filesystem, they share the single
1377 +The struct of a xino file is simple, just a sequence of aufs inode
1378 +numbers which is indexed by the lower inode number.
1379 +In the above sample, assume the inode number of /ro/fileA is i111 and
1380 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1381 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1383 +When the inode numbers are not contiguous, the xino file will be sparse
1384 +which has a hole in it and doesn't consume as much disk space as it
1385 +might appear. If your branch filesystem consumes disk space for such
1386 +holes, then you should specify 'xino=' option at mounting aufs.
1388 +Aufs has a mount option to free the disk blocks for such holes in XINO
1389 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1390 +meet a problem of disk shortage due to XINO files, then you should try
1391 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1392 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1393 +the holes in XINO files.
1395 +Also a writable branch has three kinds of "whiteout bases". All these
1396 +are existed when the branch is joined to aufs, and their names are
1397 +whiteout-ed doubly, so that users will never see their names in aufs
1399 +1. a regular file which will be hardlinked to all whiteouts.
1400 +2. a directory to store a pseudo-link.
1401 +3. a directory to store an "orphan"-ed file temporary.
1404 + When you remove a file on a readonly branch, aufs handles it as a
1405 + logical deletion and creates a whiteout on the upper writable branch
1406 + as a hardlink of this file in order not to consume inode on the
1409 + See below, Pseudo-link.
1411 + When "fileC" exists on the lower readonly branch only and it is
1412 + opened and removed with its parent dir, and then user writes
1413 + something into it, then aufs copies-up fileC to this
1414 + directory. Because there is no other dir to store fileC. After
1415 + creating a file under this dir, the file is unlinked.
1417 +Because aufs supports manipulating branches, ie. add/delete/change
1418 +dynamically, a branch has its own id. When the branch order changes,
1419 +aufs finds the new index by searching the branch id.
1423 +----------------------------------------------------------------------
1424 +Assume "fileA" exists on the lower readonly branch only and it is
1425 +hardlinked to "fileB" on the branch. When you write something to fileA,
1426 +aufs copies-up it to the upper writable branch. Additionally aufs
1427 +creates a hardlink under the Pseudo-link Directory of the writable
1428 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1429 +simple list. If fileB is read after unlinking fileA, aufs returns
1430 +filedata from the pseudo-link instead of the lower readonly
1431 +branch. Because the pseudo-link is based upon the inode, to keep the
1432 +inode number by xino (see above) is essentially necessary.
1434 +All the hardlinks under the Pseudo-link Directory of the writable branch
1435 +should be restored in a proper location later. Aufs provides a utility
1436 +to do this. The userspace helpers executed at remounting and unmounting
1438 +During this utility is running, it puts aufs into the pseudo-link
1439 +maintenance mode. In this mode, only the process which began the
1440 +maintenance mode (and its child processes) is allowed to operate in
1441 +aufs. Some other processes which are not related to the pseudo-link will
1442 +be allowed to run too, but the rest have to return an error or wait
1443 +until the maintenance mode ends. If a process already acquires an inode
1444 +mutex (in VFS), it has to return an error.
1447 +XIB(external inode number bitmap)
1448 +----------------------------------------------------------------------
1449 +Addition to the xino file per a branch, aufs has an external inode number
1450 +bitmap in a superblock object. It is also an internal file such like a
1452 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1454 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1456 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1457 +reduce the number of consumed disk blocks for these files.
1460 +Virtual or Vertical Dir, and Readdir in Userspace
1461 +----------------------------------------------------------------------
1462 +In order to support multiple layers (branches), aufs readdir operation
1463 +constructs a virtual dir block on memory. For readdir, aufs calls
1464 +vfs_readdir() internally for each dir on branches, merges their entries
1465 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1466 +object. So the file object has its entry list until it is closed. The
1467 +entry list will be updated when the file position is zero and becomes
1468 +obsoleted. This decision is made in aufs automatically.
1470 +The dynamically allocated memory block for the name of entries has a
1471 +unit of 512 bytes (by default) and stores the names contiguously (no
1472 +padding). Another block for each entry is handled by kmem_cache too.
1473 +During building dir blocks, aufs creates hash list and judging whether
1474 +the entry is whiteouted by its upper branch or already listed.
1475 +The merged result is cached in the corresponding inode object and
1476 +maintained by a customizable life-time option.
1478 +Some people may call it can be a security hole or invite DoS attack
1479 +since the opened and once readdir-ed dir (file object) holds its entry
1480 +list and becomes a pressure for system memory. But I'd say it is similar
1481 +to files under /proc or /sys. The virtual files in them also holds a
1482 +memory page (generally) while they are opened. When an idea to reduce
1483 +memory for them is introduced, it will be applied to aufs too.
1484 +For those who really hate this situation, I've developed readdir(3)
1485 +library which operates this merging in userspace. You just need to set
1486 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1487 +kernel space for readdir(3).
1491 +----------------------------------------------------------------------
1492 +Aufs sometimes requires privilege access to a branch. For instance,
1493 +in copy-up/down operation. When a user process is going to make changes
1494 +to a file which exists in the lower readonly branch only, and the mode
1495 +of one of ancestor directories may not be writable by a user
1496 +process. Here aufs copy-up the file with its ancestors and they may
1497 +require privilege to set its owner/group/mode/etc.
1498 +This is a typical case of a application character of aufs (see
1501 +Aufs uses workqueue synchronously for this case. It creates its own
1502 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1503 +passes the request to call mkdir or write (for example), and wait for
1504 +its completion. This approach solves a problem of a signal handler
1506 +If aufs didn't adopt the workqueue and changed the privilege of the
1507 +process, then the process may receive the unexpected SIGXFSZ or other
1510 +Also aufs uses the system global workqueue ("events" kernel thread) too
1511 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1512 +whiteout base and etc. This is unrelated to a privilege.
1513 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1514 +superblock at the beginning, at the same time waits for the completion
1515 +of all queued asynchronous tasks.
1519 +----------------------------------------------------------------------
1520 +The whiteout in aufs is very similar to Unionfs's. That is represented
1521 +by its filename. UnionMount takes an approach of a file mode, but I am
1522 +afraid several utilities (find(1) or something) will have to support it.
1524 +Basically the whiteout represents "logical deletion" which stops aufs to
1525 +lookup further, but also it represents "dir is opaque" which also stop
1528 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1529 +In order to make several functions in a single systemcall to be
1530 +revertible, aufs adopts an approach to rename a directory to a temporary
1531 +unique whiteouted name.
1532 +For example, in rename(2) dir where the target dir already existed, aufs
1533 +renames the target dir to a temporary unique whiteouted name before the
1534 +actual rename on a branch, and then handles other actions (make it opaque,
1535 +update the attributes, etc). If an error happens in these actions, aufs
1536 +simply renames the whiteouted name back and returns an error. If all are
1537 +succeeded, aufs registers a function to remove the whiteouted unique
1538 +temporary name completely and asynchronously to the system global
1543 +----------------------------------------------------------------------
1544 +It is a well-known feature or concept.
1545 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1546 +internally and makes change to the new file on the upper writable branch.
1547 +When the trigger systemcall does not update the timestamps of the parent
1548 +dir, aufs reverts it after copy-up.
1551 +Move-down (aufs3.9 and later)
1552 +----------------------------------------------------------------------
1553 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1554 +the lower readonly branch to the upper writable branch when a user
1555 +changes something about the file.
1556 +"Move-down" is an opposite action of copy-up. Basically this action is
1557 +ran manually instead of automatically and internally.
1558 +For desgin and implementation, aufs has to consider these issues.
1559 +- whiteout for the file may exist on the lower branch.
1560 +- ancestor directories may not exist on the lower branch.
1561 +- diropq for the ancestor directories may exist on the upper branch.
1562 +- free space on the lower branch will reduce.
1563 +- another access to the file may happen during moving-down, including
1564 + UDBA (see "Revalidate Dentry and UDBA").
1565 +- the file should not be hard-linked nor pseudo-linked. they should be
1566 + handled by auplink utility later.
1568 +Sometimes users want to move-down a file from the upper writable branch
1569 +to the lower readonly or writable branch. For instance,
1570 +- the free space of the upper writable branch is going to run out.
1571 +- create a new intermediate branch between the upper and lower branch.
1574 +For this purpose, use "aumvdown" command in aufs-util.git.
1575 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1576 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1577 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2020-01-27 10:57:18.162204582 +0100
1580 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1582 +# This program is free software; you can redistribute it and/or modify
1583 +# it under the terms of the GNU General Public License as published by
1584 +# the Free Software Foundation; either version 2 of the License, or
1585 +# (at your option) any later version.
1587 +# This program is distributed in the hope that it will be useful,
1588 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1589 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1590 +# GNU General Public License for more details.
1592 +# You should have received a copy of the GNU General Public License
1593 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1595 +Support for a branch who has its ->atomic_open()
1596 +----------------------------------------------------------------------
1597 +The filesystems who implement its ->atomic_open() are not majority. For
1598 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1599 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1600 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1601 +sure whether all filesystems who have ->atomic_open() behave like this,
1602 +but NFSv4 surely returns the error.
1604 +In order to support ->atomic_open() for aufs, there are a few
1607 +A. Introduce aufs_atomic_open()
1608 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1610 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1611 + an aufs user Pip Cet's approach
1612 + - calls aufs_create(), VFS finish_open() and notify_change().
1613 + - pass fake-mode to finish_open(), and then correct the mode by
1615 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1616 + - no aufs_atomic_open().
1617 + - aufs_lookup() registers the TID to an aufs internal object.
1618 + - aufs_create() does nothing when the matching TID is registered, but
1619 + registers the mode.
1620 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1621 + TID is registered.
1622 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1624 + - no aufs_atomic_open().
1625 + - aufs_create() registers the TID to an internal object. this info
1626 + represents "this process created this file just now."
1627 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1628 + registered TID and re-try open() with superuser's credential.
1630 +Pros and cons for each approach.
1633 + - straightforward but highly depends upon VFS internal.
1634 + - the atomic behavaiour is kept.
1635 + - some of parameters such as nameidata are hard to reproduce for
1639 + - easy to implement.
1640 + - the atomic behavaiour is lost.
1642 + - the atomic behavaiour is kept.
1643 + - dirty and tricky.
1644 + - VFS checks whether the file is created correctly after calling
1645 + ->create(), which means this approach doesn't work.
1647 + - easy to implement.
1648 + - the atomic behavaiour is lost.
1649 + - to open a file with superuser's credential and give it to a user
1650 + process is a bad idea, since the file object keeps the credential
1651 + in it. It may affect LSM or something. This approach doesn't work
1654 +The approach A is ideal, but it hard to implement. So here is a
1655 +variation of A, which is to be implemented.
1657 +A-1. Introduce aufs_atomic_open()
1658 + - calls branch fs ->atomic_open() if exists. otherwise calls
1659 + vfs_create() and finish_open().
1660 + - the demerit is that the several checks after branch fs
1661 + ->atomic_open() are lost. in the ordinary case, the checks are
1662 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1663 + be implemented in aufs, but not all I am afraid.
1664 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1665 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1666 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2020-01-27 10:57:18.165538015 +0100
1669 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1671 +# This program is free software; you can redistribute it and/or modify
1672 +# it under the terms of the GNU General Public License as published by
1673 +# the Free Software Foundation; either version 2 of the License, or
1674 +# (at your option) any later version.
1676 +# This program is distributed in the hope that it will be useful,
1677 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1678 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1679 +# GNU General Public License for more details.
1681 +# You should have received a copy of the GNU General Public License
1682 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1685 +----------------------------------------------------------------------
1686 +Since aufs has a character of sub-VFS (see Introduction), it operates
1687 +lookup for branches as VFS does. It may be a heavy work. But almost all
1688 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1689 +directly connected to its parent. Digging down the directory hierarchy
1690 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1693 +When a branch is a remote filesystem, aufs basically relies upon its
1694 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1696 +For d_revalidate, aufs implements three levels of revalidate tests. See
1697 +"Revalidate Dentry and UDBA" in detail.
1700 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1701 +----------------------------------------------------------------------
1702 +Let's try case study.
1703 +- aufs has two branches, upper readwrite and lower readonly.
1705 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1706 +- user invoked "chmod a+rx /au/dirA"
1707 +- the internal copy-up is activated and "/rw/dirA" is created and its
1708 + permission bits are set to world readable.
1709 +- then "/au/dirA" becomes world readable?
1711 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1712 +or it may be a natively readonly filesystem. If aufs respects the lower
1713 +branch, it should not respond readdir request from other users. But user
1714 +allowed it by chmod. Should really aufs rejects showing the entries
1717 +To be honest, I don't have a good solution for this case. So aufs
1718 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1720 +When dirperm1 is specified, aufs checks only the highest one for the
1721 +directory permission, and shows the entries. Otherwise, as usual, checks
1722 +every dir existing on all branches and rejects the request.
1724 +As a side effect, dirperm1 option improves the performance of aufs
1725 +because the number of permission check is reduced when the number of
1729 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1730 +----------------------------------------------------------------------
1731 +Generally VFS helpers re-validate a dentry as a part of lookup.
1732 +0. digging down the directory hierarchy.
1733 +1. lock the parent dir by its i_mutex.
1734 +2. lookup the final (child) entry.
1736 +4. call the actual operation (create, unlink, etc.)
1737 +5. unlock the parent dir
1739 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1740 +called. Actually aufs implements it and checks the dentry on a branch is
1742 +But it is not enough. Because aufs has to release the lock for the
1743 +parent dir on a branch at the end of ->lookup() (step 2) and
1744 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1746 +If the file on a branch is changed directly, eg. bypassing aufs, after
1747 +aufs released the lock, then the subsequent operation may cause
1748 +something unpleasant result.
1750 +This situation is a result of VFS architecture, ->lookup() and
1751 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1752 +design from VFS's point of view. It is just not suitable for sub-VFS
1755 +Aufs supports such case by three level of revalidation which is
1756 +selectable by user.
1757 +1. Simple Revalidate
1758 + Addition to the native flow in VFS's, confirm the child-parent
1759 + relationship on the branch just after locking the parent dir on the
1760 + branch in the "actual operation" (step 4). When this validation
1761 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1762 + checks the validation of the dentry on branches.
1763 +2. Monitor Changes Internally by Inotify/Fsnotify
1764 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1765 + the dentry on the branch, and returns EBUSY if it finds different
1767 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1768 + during it is in cache. When the event is notified, aufs registers a
1769 + function to kernel 'events' thread by schedule_work(). And the
1770 + function sets some special status to the cached aufs dentry and inode
1771 + private data. If they are not cached, then aufs has nothing to
1772 + do. When the same file is accessed through aufs (step 0-3) later,
1773 + aufs will detect the status and refresh all necessary data.
1774 + In this mode, aufs has to ignore the event which is fired by aufs
1776 +3. No Extra Validation
1777 + This is the simplest test and doesn't add any additional revalidation
1778 + test, and skip the revalidation in step 4. It is useful and improves
1779 + aufs performance when system surely hide the aufs branches from user,
1780 + by over-mounting something (or another method).
1781 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1782 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1783 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2020-01-27 10:57:18.165538015 +0100
1786 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1788 +# This program is free software; you can redistribute it and/or modify
1789 +# it under the terms of the GNU General Public License as published by
1790 +# the Free Software Foundation; either version 2 of the License, or
1791 +# (at your option) any later version.
1793 +# This program is distributed in the hope that it will be useful,
1794 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1795 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1796 +# GNU General Public License for more details.
1798 +# You should have received a copy of the GNU General Public License
1799 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1801 +Branch Manipulation
1803 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1804 +and changing its permission/attribute, there are a lot of works to do.
1808 +----------------------------------------------------------------------
1809 +o Confirm the adding dir exists outside of aufs, including loopback
1810 + mount, and its various attributes.
1811 +o Initialize the xino file and whiteout bases if necessary.
1814 +o Check the owner/group/mode of the directory
1815 + When the owner/group/mode of the adding directory differs from the
1816 + existing branch, aufs issues a warning because it may impose a
1818 + For example, when a upper writable branch has a world writable empty
1819 + top directory, a malicious user can create any files on the writable
1820 + branch directly, like copy-up and modify manually. If something like
1821 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1822 + writable branch, and the writable branch is world-writable, then a
1823 + malicious guy may create /etc/passwd on the writable branch directly
1824 + and the infected file will be valid in aufs.
1825 + I am afraid it can be a security issue, but aufs can do nothing except
1826 + producing a warning.
1830 +----------------------------------------------------------------------
1831 +o Confirm the deleting branch is not busy
1832 + To be general, there is one merit to adopt "remount" interface to
1833 + manipulate branches. It is to discard caches. At deleting a branch,
1834 + aufs checks the still cached (and connected) dentries and inodes. If
1835 + there are any, then they are all in-use. An inode without its
1836 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1838 + For the cached one, aufs checks whether the same named entry exists on
1840 + If the cached one is a directory, because aufs provides a merged view
1841 + to users, as long as one dir is left on any branch aufs can show the
1842 + dir to users. In this case, the branch can be removed from aufs.
1843 + Otherwise aufs rejects deleting the branch.
1845 + If any file on the deleting branch is opened by aufs, then aufs
1849 +Modify the Permission of a Branch
1850 +----------------------------------------------------------------------
1851 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1854 +o rw --> ro: Confirm the modifying branch is not busy
1855 + Aufs rejects the request if any of these conditions are true.
1856 + - a file on the branch is mmap-ed.
1857 + - a regular file on the branch is opened for write and there is no
1858 + same named entry on the upper branch.
1859 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1860 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1861 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2020-01-27 10:57:18.165538015 +0100
1864 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1866 +# This program is free software; you can redistribute it and/or modify
1867 +# it under the terms of the GNU General Public License as published by
1868 +# the Free Software Foundation; either version 2 of the License, or
1869 +# (at your option) any later version.
1871 +# This program is distributed in the hope that it will be useful,
1872 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1873 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1874 +# GNU General Public License for more details.
1876 +# You should have received a copy of the GNU General Public License
1877 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1879 +Policies to Select One among Multiple Writable Branches
1880 +----------------------------------------------------------------------
1881 +When the number of writable branch is more than one, aufs has to decide
1882 +the target branch for file creation or copy-up. By default, the highest
1883 +writable branch which has the parent (or ancestor) dir of the target
1884 +file is chosen (top-down-parent policy).
1885 +By user's request, aufs implements some other policies to select the
1886 +writable branch, for file creation several policies, round-robin,
1887 +most-free-space, and other policies. For copy-up, top-down-parent,
1888 +bottom-up-parent, bottom-up and others.
1890 +As expected, the round-robin policy selects the branch in circular. When
1891 +you have two writable branches and creates 10 new files, 5 files will be
1892 +created for each branch. mkdir(2) systemcall is an exception. When you
1893 +create 10 new directories, all will be created on the same branch.
1894 +And the most-free-space policy selects the one which has most free
1895 +space among the writable branches. The amount of free space will be
1896 +checked by aufs internally, and users can specify its time interval.
1898 +The policies for copy-up is more simple,
1899 +top-down-parent is equivalent to the same named on in create policy,
1900 +bottom-up-parent selects the writable branch where the parent dir
1901 +exists and the nearest upper one from the copyup-source,
1902 +bottom-up selects the nearest upper writable branch from the
1903 +copyup-source, regardless the existence of the parent dir.
1905 +There are some rules or exceptions to apply these policies.
1906 +- If there is a readonly branch above the policy-selected branch and
1907 + the parent dir is marked as opaque (a variation of whiteout), or the
1908 + target (creating) file is whiteout-ed on the upper readonly branch,
1909 + then the result of the policy is ignored and the target file will be
1910 + created on the nearest upper writable branch than the readonly branch.
1911 +- If there is a writable branch above the policy-selected branch and
1912 + the parent dir is marked as opaque or the target file is whiteouted
1913 + on the branch, then the result of the policy is ignored and the target
1914 + file will be created on the highest one among the upper writable
1915 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1917 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1918 + They try selecting the branch where the source exists as possible
1919 + since copyup a large file will take long time. If it can't be,
1920 + ie. the branch where the source exists is readonly, then they will
1921 + follow the copyup policy.
1922 +- There is an exception for rename(2) when the target exists.
1923 + If the rename target exists, aufs compares the index of the branches
1924 + where the source and the target exists and selects the higher
1925 + one. If the selected branch is readonly, then aufs follows the
1927 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1928 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1929 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200
1932 +// to view this graph, run dot(1) command in GRAPHVIZ.
1936 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1940 +aufs_rename -> whinfo [label="store/remove"];
1943 +inode_list [label="h_inum list in branch\ncache"];
1946 +whinode [label="h_inum list file"];
1949 +brmgmt [label="br_add/del/mod/umount"];
1951 +brmgmt -> inode_list [label="create/remove"];
1952 +brmgmt -> whinode [label="load/store"];
1954 +inode_list -> whinode [style=dashed,dir=both];
1956 +aufs_rename -> inode_list [label="add/del"];
1958 +aufs_lookup -> inode_list [label="search"];
1960 +aufs_lookup -> whinfo [label="load/remove"];
1962 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1963 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1964 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2020-01-27 10:57:18.165538015 +0100
1967 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1969 +# This program is free software; you can redistribute it and/or modify
1970 +# it under the terms of the GNU General Public License as published by
1971 +# the Free Software Foundation; either version 2 of the License, or
1972 +# (at your option) any later version.
1974 +# This program is distributed in the hope that it will be useful,
1975 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1976 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1977 +# GNU General Public License for more details.
1979 +# You should have received a copy of the GNU General Public License
1980 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1982 +Special handling for renaming a directory (DIRREN)
1983 +----------------------------------------------------------------------
1984 +First, let's assume we have a simple usecase.
1988 +- /ro/dirA and /ro/dirA/file exist too
1989 +- there is no dirB on both branches
1990 +- a user issues rename("dirA", "dirB")
1992 +Now, what should aufs behave against this rename(2)?
1993 +There are a few possible cases.
1996 + since dirA exists on a readonly branch which cannot be renamed.
1998 + it is possible to copy-up dirA (only the dir itself), but the child
1999 + entries ("file" in this case) should not be. it must be a bad
2000 + approach to copy-up recursively.
2001 +C. returns a success.
2002 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2003 + is a violation of aufs' policy.
2004 +D. construct an extra information which indicates that /ro/dirA should
2005 + be handled as the name of dirB.
2006 + overlayfs has a similar feature called REDIRECT.
2008 +Until now, aufs implements the case B only which returns EXDEV, and
2009 +expects the userspace application behaves like mv(1) which tries
2010 +issueing rename(2) recursively.
2012 +A new aufs feature called DIRREN is introduced which implements the case
2013 +D. There are several "extra information" added.
2015 +1. detailed info per renamed directory
2016 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2017 +2. the inode-number list of directories on a branch
2018 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2020 +The filename of "detailed info per directory" represents the lower
2021 +branch, and its format is
2022 +- a type of the branch id
2024 + + uuid (not implemented yet)
2027 +- the inode-number of the branch root dir
2029 +And it contains these info in a single regular file.
2031 +- branch's inode-number of the logically renamed dir
2032 +- the name of the before-renamed dir
2034 +The "detailed info per directory" file is created in aufs rename(2), and
2035 +loaded in any lookup.
2036 +The info is considered in lookup for the matching case only. Here
2037 +"matching" means that the root of branch (in the info filename) is same
2038 +to the current looking-up branch. After looking-up the before-renamed
2039 +name, the inode-number is compared. And the matched dentry is used.
2041 +The "inode-number list of directories" is a regular file which contains
2042 +simply the inode-numbers on the branch. The file is created or updated
2043 +in removing the branch, and loaded in adding the branch. Its lifetime is
2044 +equal to the branch.
2045 +The list is refered in lookup, and when the current target inode is
2046 +found in the list, the aufs tries loading the "detailed info per
2047 +directory" and get the changed and valid name of the dir.
2049 +Theoretically these "extra informaiton" may be able to be put into XATTR
2050 +in the dir inode. But aufs doesn't choose this way because
2051 +1. XATTR may not be supported by the branch (or its configuration)
2052 +2. XATTR may have its size limit.
2053 +3. XATTR may be less easy to convert than a regular file, when the
2054 + format of the info is changed in the future.
2055 +At the same time, I agree that the regular file approach is much slower
2056 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2059 +This DIRREN feature is enabled by aufs configuration, and is activated
2060 +by a new mount option.
2062 +For the more complicated case, there is a work with UDBA option, which
2063 +is to dected the direct access to the branches (by-passing aufs) and to
2064 +maintain the cashes in aufs. Since a single cached aufs dentry may
2065 +contains two names, before- and after-rename, the name comparision in
2066 +UDBA handler may not work correctly. In this case, the behaviour will be
2067 +equivalen to udba=reval case.
2068 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2069 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2070 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2020-01-27 10:57:18.165538015 +0100
2073 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2075 +# This program is free software; you can redistribute it and/or modify
2076 +# it under the terms of the GNU General Public License as published by
2077 +# the Free Software Foundation; either version 2 of the License, or
2078 +# (at your option) any later version.
2080 +# This program is distributed in the hope that it will be useful,
2081 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2082 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2083 +# GNU General Public License for more details.
2085 +# You should have received a copy of the GNU General Public License
2086 +# along with this program; if not, write to the Free Software
2087 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2090 +File-based Hierarchical Storage Management (FHSM)
2091 +----------------------------------------------------------------------
2092 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2093 +storage world. Aufs provides this feature as file-based with multiple
2094 +writable branches, based upon the principle of "Colder, the Lower".
2095 +Here the word "colder" means that the less used files, and "lower" means
2096 +that the position in the order of the stacked branches vertically.
2097 +These multiple writable branches are prioritized, ie. the topmost one
2098 +should be the fastest drive and be used heavily.
2100 +o Characters in aufs FHSM story
2101 +- aufs itself and a new branch attribute.
2102 +- a new ioctl interface to move-down and to establish a connection with
2103 + the daemon ("move-down" is a converse of "copy-up").
2104 +- userspace tool and daemon.
2106 +The userspace daemon establishes a connection with aufs and waits for
2107 +the notification. The notified information is very similar to struct
2108 +statfs containing the number of consumed blocks and inodes.
2109 +When the consumed blocks/inodes of a branch exceeds the user-specified
2110 +upper watermark, the daemon activates its move-down process until the
2111 +consumed blocks/inodes reaches the user-specified lower watermark.
2113 +The actual move-down is done by aufs based upon the request from
2114 +user-space since we need to maintain the inode number and the internal
2115 +pointer arrays in aufs.
2117 +Currently aufs FHSM handles the regular files only. Additionally they
2118 +must not be hard-linked nor pseudo-linked.
2121 +o Cowork of aufs and the user-space daemon
2122 + During the userspace daemon established the connection, aufs sends a
2123 + small notification to it whenever aufs writes something into the
2124 + writable branch. But it may cost high since aufs issues statfs(2)
2125 + internally. So user can specify a new option to cache the
2126 + info. Actually the notification is controlled by these factors.
2127 + + the specified cache time.
2128 + + classified as "force" by aufs internally.
2129 + Until the specified time expires, aufs doesn't send the info
2130 + except the forced cases. When aufs decide forcing, the info is always
2131 + notified to userspace.
2132 + For example, the number of free inodes is generally large enough and
2133 + the shortage of it happens rarely. So aufs doesn't force the
2134 + notification when creating a new file, directory and others. This is
2135 + the typical case which aufs doesn't force.
2136 + When aufs writes the actual filedata and the files consumes any of new
2137 + blocks, the aufs forces notifying.
2140 +o Interfaces in aufs
2141 +- New branch attribute.
2143 + Specifies that the branch is managed by FHSM feature. In other word,
2144 + participant in the FHSM.
2145 + When nofhsm is set to the branch, it will not be the source/target
2146 + branch of the move-down operation. This attribute is set
2147 + independently from coo and moo attributes, and if you want full
2148 + FHSM, you should specify them as well.
2149 +- New mount option.
2151 + Specifies a second to suppress many less important info to be
2154 + + AUFS_CTL_FHSM_FD
2155 + create a new file descriptor which userspace can read the notification
2156 + (a subset of struct statfs) from aufs.
2157 +- Module parameter 'brs'
2158 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2160 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2161 + When there are two or more branches with fhsm attributes,
2162 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2163 + terminates it. As a result of remounting and branch-manipulation, the
2164 + number of branches with fhsm attribute can be one. In this case,
2165 + /sbin/mount.aufs will terminate the user-space daemon.
2168 +Finally the operation is done as these steps in kernel-space.
2170 + + no one else is using the file.
2171 + + the file is not hard-linked.
2172 + + the file is not pseudo-linked.
2173 + + the file is a regular file.
2174 + + the parent dir is not opaqued.
2175 +- find the target writable branch.
2176 +- make sure the file is not whiteout-ed by the upper (than the target)
2178 +- make the parent dir on the target branch.
2179 +- mutex lock the inode on the branch.
2180 +- unlink the whiteout on the target branch (if exists).
2181 +- lookup and create the whiteout-ed temporary name on the target branch.
2182 +- copy the file as the whiteout-ed temporary name on the target branch.
2183 +- rename the whiteout-ed temporary name to the original name.
2184 +- unlink the file on the source branch.
2185 +- maintain the internal pointer array and the external inode number
2187 +- maintain the timestamps and other attributes of the parent dir and the
2190 +And of course, in every step, an error may happen. So the operation
2191 +should restore the original file state after an error happens.
2192 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2193 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2194 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2020-01-27 10:57:18.165538015 +0100
2197 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2199 +# This program is free software; you can redistribute it and/or modify
2200 +# it under the terms of the GNU General Public License as published by
2201 +# the Free Software Foundation; either version 2 of the License, or
2202 +# (at your option) any later version.
2204 +# This program is distributed in the hope that it will be useful,
2205 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2206 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2207 +# GNU General Public License for more details.
2209 +# You should have received a copy of the GNU General Public License
2210 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2212 +mmap(2) -- File Memory Mapping
2213 +----------------------------------------------------------------------
2214 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2215 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2217 +This approach is simple and good, but there is one problem.
2218 +Under /proc, several entries show the mmapped files by its path (with
2219 +device and inode number), and the printed path will be the path on the
2220 +branch fs's instead of virtual aufs's.
2221 +This is not a problem in most cases, but some utilities lsof(1) (and its
2222 +user) may expect the path on aufs.
2224 +To address this issue, aufs adds a new member called vm_prfile in struct
2225 +vm_area_struct (and struct vm_region). The original vm_file points to
2226 +the file on the branch fs in order to handle everything correctly as
2227 +usual. The new vm_prfile points to a virtual file in aufs, and the
2228 +show-functions in procfs refers to vm_prfile if it is set.
2229 +Also we need to maintain several other places where touching vm_file
2231 +- fork()/clone() copies vma and the reference count of vm_file is
2233 +- merging vma maintains the ref count too.
2235 +This is not a good approach. It just fakes the printed path. But it
2236 +leaves all behaviour around f_mapping unchanged. This is surely an
2238 +Actually aufs had adopted another complicated approach which calls
2239 +generic_file_mmap() and handles struct vm_operations_struct. In this
2240 +approach, aufs met a hard problem and I could not solve it without
2241 +switching the approach.
2243 +There may be one more another approach which is
2244 +- bind-mount the branch-root onto the aufs-root internally
2245 +- grab the new vfsmount (ie. struct mount)
2246 +- lazy-umount the branch-root internally
2247 +- in open(2) the aufs-file, open the branch-file with the hidden
2248 + vfsmount (instead of the original branch's vfsmount)
2249 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2250 + but it may be possible from userspace by the mount helper.
2252 +Adding the internal hidden vfsmount and using it in opening a file, the
2253 +file path under /proc will be printed correctly. This approach looks
2254 +smarter, but is not possible I am afraid.
2255 +- aufs-root may be bind-mount later. when it happens, another hidden
2256 + vfsmount will be required.
2257 +- it is hard to get the chance to bind-mount and lazy-umount
2258 + + in kernel-space, FS can have vfsmount in open(2) via
2259 + file->f_path, and aufs can know its vfsmount. But several locks are
2260 + already acquired, and if aufs tries to bind-mount and lazy-umount
2261 + here, then it may cause a deadlock.
2262 + + in user-space, bind-mount doesn't invoke the mount helper.
2263 +- since /proc shows dev and ino, aufs has to give vma these info. it
2264 + means a new member vm_prinode will be necessary. this is essentially
2265 + equivalent to vm_prfile described above.
2267 +I have to give up this "looks-smater" approach.
2268 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2269 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2270 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2020-01-27 10:57:18.165538015 +0100
2273 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2275 +# This program is free software; you can redistribute it and/or modify
2276 +# it under the terms of the GNU General Public License as published by
2277 +# the Free Software Foundation; either version 2 of the License, or
2278 +# (at your option) any later version.
2280 +# This program is distributed in the hope that it will be useful,
2281 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2282 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2283 +# GNU General Public License for more details.
2285 +# You should have received a copy of the GNU General Public License
2286 +# along with this program; if not, write to the Free Software
2287 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2290 +Listing XATTR/EA and getting the value
2291 +----------------------------------------------------------------------
2292 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2293 +shows the values from the topmost existing file. This behaviour is good
2294 +for the non-dir entries since the bahaviour exactly matches the shown
2295 +information. But for the directories, aufs considers all the same named
2296 +entries on the lower branches. Which means, if one of the lower entry
2297 +rejects readdir call, then aufs returns an error even if the topmost
2298 +entry allows it. This behaviour is necessary to respect the branch fs's
2299 +security, but can make users confused since the user-visible standard
2300 +attributes don't match the behaviour.
2301 +To address this issue, aufs has a mount option called dirperm1 which
2302 +checks the permission for the topmost entry only, and ignores the lower
2303 +entry's permission.
2305 +A similar issue can happen around XATTR.
2306 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2307 +always set. Otherwise these very unpleasant situation would happen.
2308 +- listxattr(2) may return the duplicated entries.
2309 +- users may not be able to remove or reset the XATTR forever,
2312 +XATTR/EA support in the internal (copy,move)-(up,down)
2313 +----------------------------------------------------------------------
2314 +Generally the extended attributes of inode are categorized as these.
2315 +- "security" for LSM and capability.
2316 +- "system" for posix ACL, 'acl' mount option is required for the branch
2318 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2319 +- "user" for userspace, 'user_xattr' mount option is required for the
2320 + branch fs generally.
2322 +Moreover there are some other categories. Aufs handles these rather
2323 +unpopular categories as the ordinary ones, ie. there is no special
2324 +condition nor exception.
2326 +In copy-up, the support for XATTR on the dst branch may differ from the
2327 +src branch. In this case, the copy-up operation will get an error and
2328 +the original user operation which triggered the copy-up will fail. It
2329 +can happen that even all copy-up will fail.
2330 +When both of src and dst branches support XATTR and if an error occurs
2331 +during copying XATTR, then the copy-up should fail obviously. That is a
2332 +good reason and aufs should return an error to userspace. But when only
2333 +the src branch support that XATTR, aufs should not return an error.
2334 +For example, the src branch supports ACL but the dst branch doesn't
2335 +because the dst branch may natively un-support it or temporary
2336 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2337 +may NOT return an error even if the XATTR is not supported. It is
2338 +totally up to the branch fs.
2340 +Anyway when the aufs internal copy-up gets an error from the dst branch
2341 +fs, then aufs tries removing the just copied entry and returns the error
2342 +to the userspace. The worst case of this situation will be all copy-up
2345 +For the copy-up operation, there two basic approaches.
2346 +- copy the specified XATTR only (by category above), and return the
2347 + error unconditionally if it happens.
2348 +- copy all XATTR, and ignore the error on the specified category only.
2350 +In order to support XATTR and to implement the correct behaviour, aufs
2351 +chooses the latter approach and introduces some new branch attributes,
2352 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2353 +They correspond to the XATTR namespaces (see above). Additionally, to be
2354 +convenient, "icex" is also provided which means all "icex*" attributes
2355 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2357 +The meaning of these attributes is to ignore the error from setting
2358 +XATTR on that branch.
2359 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2360 +error from the dst branch according to the specified attributes.
2362 +Some XATTR may have its default value. The default value may come from
2363 +the parent dir or the environment. If the default value is set at the
2364 +file creating-time, it will be overwritten by copy-up.
2365 +Some contradiction may happen I am afraid.
2366 +Do we need another attribute to stop copying XATTR? I am unsure. For
2367 +now, aufs implements the branch attributes to ignore the error.
2368 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2369 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2370 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2020-01-27 10:57:18.165538015 +0100
2373 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2375 +# This program is free software; you can redistribute it and/or modify
2376 +# it under the terms of the GNU General Public License as published by
2377 +# the Free Software Foundation; either version 2 of the License, or
2378 +# (at your option) any later version.
2380 +# This program is distributed in the hope that it will be useful,
2381 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2382 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2383 +# GNU General Public License for more details.
2385 +# You should have received a copy of the GNU General Public License
2386 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2388 +Export Aufs via NFS
2389 +----------------------------------------------------------------------
2390 +Here is an approach.
2391 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2393 +- iget_locked(): initialize aufs inode generation for a new inode, and
2394 + store it in xigen file.
2395 +- destroy_inode(): increment aufs inode generation and store it in xigen
2396 + file. it is necessary even if it is not unlinked, because any data of
2397 + inode may be changed by UDBA.
2398 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2399 + build file handle by
2400 + + branch id (4 bytes)
2401 + + superblock generation (4 bytes)
2402 + + inode number (4 or 8 bytes)
2403 + + parent dir inode number (4 or 8 bytes)
2404 + + inode generation (4 bytes))
2405 + + return value of exportfs_encode_fh() for the parent on a branch (4
2407 + + file handle for a branch (by exportfs_encode_fh())
2409 + + find the index of a branch from its id in handle, and check it is
2410 + still exist in aufs.
2411 + + 1st level: get the inode number from handle and search it in cache.
2412 + + 2nd level: if not found in cache, get the parent inode number from
2413 + the handle and search it in cache. and then open the found parent
2414 + dir, find the matching inode number by vfs_readdir() and get its
2415 + name, and call lookup_one_len() for the target dentry.
2416 + + 3rd level: if the parent dir is not cached, call
2417 + exportfs_decode_fh() for a branch and get the parent on a branch,
2418 + build a pathname of it, convert it a pathname in aufs, call
2419 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2421 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2422 + for every branch, but not itself. to get this, (currently) aufs
2423 + searches in current->nsproxy->mnt_ns list. it may not be a good
2424 + idea, but I didn't get other approach.
2425 + + test the generation of the gotten inode.
2426 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2427 + convert it into ESTALE for NFSD.
2428 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2429 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2430 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2431 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2432 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2020-01-27 10:57:18.165538015 +0100
2435 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2437 +# This program is free software; you can redistribute it and/or modify
2438 +# it under the terms of the GNU General Public License as published by
2439 +# the Free Software Foundation; either version 2 of the License, or
2440 +# (at your option) any later version.
2442 +# This program is distributed in the hope that it will be useful,
2443 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2444 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2445 +# GNU General Public License for more details.
2447 +# You should have received a copy of the GNU General Public License
2448 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2450 +Show Whiteout Mode (shwh)
2451 +----------------------------------------------------------------------
2452 +Generally aufs hides the name of whiteouts. But in some cases, to show
2453 +them is very useful for users. For instance, creating a new middle layer
2454 +(branch) by merging existing layers.
2456 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2457 +When you have three branches,
2458 +- Bottom: 'system', squashfs (underlying base system), read-only
2459 +- Middle: 'mods', squashfs, read-only
2460 +- Top: 'overlay', ram (tmpfs), read-write
2462 +The top layer is loaded at boot time and saved at shutdown, to preserve
2463 +the changes made to the system during the session.
2464 +When larger changes have been made, or smaller changes have accumulated,
2465 +the size of the saved top layer data grows. At this point, it would be
2466 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2467 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2468 +restoring save and load speed.
2470 +This merging is simplified by the use of another aufs mount, of just the
2471 +two overlay branches using the 'shwh' option.
2472 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2473 + aufs /livesys/merge_union
2475 +A merged view of these two branches is then available at
2476 +/livesys/merge_union, and the new feature is that the whiteouts are
2478 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2479 +writing to all branches. Also the default mode for all branches is 'ro'.
2480 +It is now possible to save the combined contents of the two overlay
2481 +branches to a new squashfs, e.g.:
2482 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2484 +This new squashfs archive can be stored on the boot device and the
2485 +initramfs will use it to replace the old one at the next boot.
2486 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2487 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2488 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2020-01-27 10:57:18.165538015 +0100
2491 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2493 +# This program is free software; you can redistribute it and/or modify
2494 +# it under the terms of the GNU General Public License as published by
2495 +# the Free Software Foundation; either version 2 of the License, or
2496 +# (at your option) any later version.
2498 +# This program is distributed in the hope that it will be useful,
2499 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2500 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2501 +# GNU General Public License for more details.
2503 +# You should have received a copy of the GNU General Public License
2504 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2506 +Dynamically customizable FS operations
2507 +----------------------------------------------------------------------
2508 +Generally FS operations (struct inode_operations, struct
2509 +address_space_operations, struct file_operations, etc.) are defined as
2510 +"static const", but it never means that FS have only one set of
2511 +operation. Some FS have multiple sets of them. For instance, ext2 has
2512 +three sets, one for XIP, for NOBH, and for normal.
2513 +Since aufs overrides and redirects these operations, sometimes aufs has
2514 +to change its behaviour according to the branch FS type. More importantly
2515 +VFS acts differently if a function (member in the struct) is set or
2516 +not. It means aufs should have several sets of operations and select one
2517 +among them according to the branch FS definition.
2519 +In order to solve this problem and not to affect the behaviour of VFS,
2520 +aufs defines these operations dynamically. For instance, aufs defines
2521 +dummy direct_IO function for struct address_space_operations, but it may
2522 +not be set to the address_space_operations actually. When the branch FS
2523 +doesn't have it, aufs doesn't set it to its address_space_operations
2524 +while the function definition itself is still alive. So the behaviour
2525 +itself will not change, and it will return an error when direct_IO is
2528 +The lifetime of these dynamically generated operation object is
2529 +maintained by aufs branch object. When the branch is removed from aufs,
2530 +the reference counter of the object is decremented. When it reaches
2531 +zero, the dynamically generated operation object will be freed.
2533 +This approach is designed to support AIO (io_submit), Direct I/O and
2535 +Currently this approach is applied to address_space_operations for
2536 +regular files only.
2537 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2538 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2539 +++ linux/Documentation/filesystems/aufs/README 2020-01-23 09:59:36.748660743 +0100
2542 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2548 +----------------------------------------
2549 +In the early days, aufs was entirely re-designed and re-implemented
2550 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2551 +improvements and implementations, it became totally different from
2552 +Unionfs while keeping the basic features.
2553 +Later, Unionfs Version 2.x series began taking some of the same
2554 +approaches to aufs1's.
2555 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2556 +University and his team.
2558 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2560 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2561 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2562 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2563 + or aufs1 from CVS on SourceForge.
2565 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2566 + According to Christoph Hellwig, linux rejects all union-type
2567 + filesystems but UnionMount.
2568 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2570 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2571 + UnionMount, and he pointed out an issue around a directory mutex
2572 + lock and aufs addressed it. But it is still unsure whether aufs will
2573 + be merged (or any other union solution).
2574 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2578 +----------------------------------------
2579 +- unite several directories into a single virtual filesystem. The member
2580 + directory is called as a branch.
2581 +- you can specify the permission flags to the branch, which are 'readonly',
2582 + 'readwrite' and 'whiteout-able.'
2583 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2584 + readonly branch are modifiable logically.
2585 +- dynamic branch manipulation, add, del.
2588 +Also there are many enhancements in aufs, such as:
2589 +- test only the highest one for the directory permission (dirperm1)
2590 +- copyup on open (coo=)
2591 +- 'move' policy for copy-up between two writable branches, after
2592 + checking free space.
2594 +- readdir(3) in userspace.
2595 +- keep inode number by external inode number table
2596 +- keep the timestamps of file/dir in internal copyup operation
2597 +- seekable directory, supporting NFS readdir.
2598 +- whiteout is hardlinked in order to reduce the consumption of inodes
2600 +- do not copyup, nor create a whiteout when it is unnecessary
2601 +- revert a single systemcall when an error occurs in aufs
2602 +- remount interface instead of ioctl
2603 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2604 +- loopback mounted filesystem as a branch
2605 +- kernel thread for removing the dir who has a plenty of whiteouts
2606 +- support copyup sparse file (a file which has a 'hole' in it)
2607 +- default permission flags for branches
2608 +- selectable permission flags for ro branch, whether whiteout can
2611 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2612 +- support multiple writable branches, some policies to select one
2613 + among multiple writable branches.
2614 +- a new semantics for link(2) and rename(2) to support multiple
2615 + writable branches.
2616 +- no glibc changes are required.
2617 +- pseudo hardlink (hardlink over branches)
2618 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2619 + including NFS or remote filesystem branch.
2620 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2623 +Currently these features are dropped temporary from aufs5.
2624 +See design/08plan.txt in detail.
2625 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2627 +- statistics of aufs thread (/sys/fs/aufs/stat)
2629 +Features or just an idea in the future (see also design/*.txt),
2630 +- reorder the branch index without del/re-add.
2631 +- permanent xino files for NFSD
2632 +- an option for refreshing the opened files after add/del branches
2633 +- light version, without branch manipulation. (unnecessary?)
2634 +- copyup in userspace
2635 +- inotify in userspace
2640 +----------------------------------------
2641 +There are three GIT trees for aufs5, aufs5-linux.git,
2642 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2644 +While the aufs-util is always necessary, you need either of aufs5-linux
2645 +or aufs5-standalone.
2647 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2648 +git://git.kernel.org/.../torvalds/linux.git.
2649 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2650 +build aufs5 as an external kernel module.
2651 +Several extra patches are not included in this tree. Only
2652 +aufs5-standalone tree contains them. They are described in the later
2653 +section "Configuration and Compilation."
2655 +On the other hand, the aufs5-standalone tree has only aufs source files
2656 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2657 +But you need to apply all aufs patches manually.
2659 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2660 +represents the linux kernel version, "linux-5.x". For instance,
2661 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2662 +"aufs5.x-rcN" branch.
2665 +$ git clone --reference /your/linux/git/tree \
2666 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2667 +- if you don't have linux GIT tree, then remove "--reference ..."
2668 +$ cd aufs5-linux.git
2669 +$ git checkout origin/aufs5.0
2671 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2672 +leave the patch-work to GIT.
2673 +$ cd /your/linux/git/tree
2674 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2676 +$ git checkout -b my5.0 v5.0
2677 +$ (add your local change...)
2678 +$ git pull aufs5 aufs5.0
2679 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2680 +- you may need to solve some conflicts between your_changes and
2681 + aufs5.0. in this case, git-rerere is recommended so that you can
2682 + solve the similar conflicts automatically when you upgrade to 5.1 or
2683 + later in the future.
2685 +o aufs5-standalone tree
2686 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2687 +$ cd aufs5-standalone.git
2688 +$ git checkout origin/aufs5.0
2691 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2692 +- note that the public aufs-util.git is on SourceForge instead of
2695 +$ git checkout origin/aufs5.0
2697 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2698 +The minor version number, 'x' in '5.x', of aufs may not always
2699 +follow the minor version number of the kernel.
2700 +Because changes in the kernel that cause the use of a new
2701 +minor version number do not always require changes to aufs-util.
2703 +Since aufs-util has its own minor version number, you may not be
2704 +able to find a GIT branch in aufs-util for your kernel's
2705 +exact minor version number.
2706 +In this case, you should git-checkout the branch for the
2707 +nearest lower number.
2709 +For (an unreleased) example:
2710 +If you are using "linux-5.10" and the "aufs5.10" branch
2711 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2712 +or something numerically smaller is the branch for your kernel.
2714 +Also you can view all branches by
2718 +3. Configuration and Compilation
2719 +----------------------------------------
2720 +Make sure you have git-checkout'ed the correct branch.
2722 +For aufs5-linux tree,
2723 +- enable CONFIG_AUFS_FS.
2724 +- set other aufs configurations if necessary.
2726 +For aufs5-standalone tree,
2727 +There are several ways to build.
2730 +- apply ./aufs5-kbuild.patch to your kernel source files.
2731 +- apply ./aufs5-base.patch too.
2732 +- apply ./aufs5-mmap.patch too.
2733 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2734 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2735 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2736 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2737 +- enable CONFIG_AUFS_FS, you can select either
2739 +- and build your kernel as usual.
2740 +- install the built kernel.
2741 +- install the header files too by "make headers_install" to the
2742 + directory where you specify. By default, it is $PWD/usr.
2743 + "make help" shows a brief note for headers_install.
2744 +- and reboot your system.
2747 +- module only (CONFIG_AUFS_FS=m).
2748 +- apply ./aufs5-base.patch to your kernel source files.
2749 +- apply ./aufs5-mmap.patch too.
2750 +- apply ./aufs5-standalone.patch too.
2751 +- build your kernel, don't forget "make headers_install", and reboot.
2752 +- edit ./config.mk and set other aufs configurations if necessary.
2753 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2754 + every aufs configurations.
2755 +- build the module by simple "make".
2756 +- you can specify ${KDIR} make variable which points to your kernel
2758 +- install the files
2759 + + run "make install" to install the aufs module, or copy the built
2760 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2761 + + run "make install_headers" (instead of headers_install) to install
2762 + the modified aufs header file (you can specify DESTDIR which is
2763 + available in aufs standalone version's Makefile only), or copy
2764 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2765 + you like manually. By default, the target directory is $PWD/usr.
2766 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2767 + kernel source tree.
2769 +Note: The header file aufs_type.h is necessary to build aufs-util
2770 + as well as "make headers_install" in the kernel source tree.
2771 + headers_install is subject to be forgotten, but it is essentially
2772 + necessary, not only for building aufs-util.
2773 + You may not meet problems without headers_install in some older
2777 +- read README in aufs-util, build and install it
2778 +- note that your distribution may contain an obsoleted version of
2779 + aufs_type.h in /usr/include/linux or something. When you build aufs
2780 + utilities, make sure that your compiler refers the correct aufs header
2781 + file which is built by "make headers_install."
2782 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2783 + then run "make install_ulib" too. And refer to the aufs manual in
2786 +There several other patches in aufs5-standalone.git. They are all
2787 +optional. When you meet some problems, they will help you.
2788 +- aufs5-loopback.patch
2789 + Supports a nested loopback mount in a branch-fs. This patch is
2790 + unnecessary until aufs produces a message like "you may want to try
2791 + another patch for loopback file".
2792 +- proc_mounts.patch
2793 + When there are many mountpoints and many mount(2)/umount(2) are
2794 + running, then /proc/mounts may not show the all mountpoints. This
2795 + patch makes /proc/mounts always show the full mountpoints list.
2796 + If you don't want to apply this patch and meet such problem, then you
2797 + need to increase the value of 'ProcMounts_Times' make-variable in
2798 + aufs-util.git as a second best solution.
2800 + Modifies a system global kernel internal function get_next_ino() in
2801 + order to stop assigning 0 for an inode-number. Not directly related to
2802 + aufs, but recommended generally.
2804 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2805 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2806 + duplication of inode number, which is important for backup tools and
2807 + other utilities. When you find aufs XINO files for tmpfs branch
2808 + growing too much, try this patch.
2809 +- lockdep-debug.patch
2810 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2811 + also a caller of VFS functions for branch filesystems, subclassing of
2812 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2813 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2814 + need to apply this debug patch to expand several constant values.
2815 + If you don't know what LOCKDEP is, then you don't have apply this
2820 +----------------------------------------
2821 +At first, make sure aufs-util are installed, and please read the aufs
2822 +manual, aufs.5 in aufs-util.git tree.
2826 +$ mkdir /tmp/rw /tmp/aufs
2827 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2829 +Here is another example. The result is equivalent.
2830 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2832 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2833 +# mount -o remount,append:${HOME} /tmp/aufs
2835 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2836 +you modify a file under /tmp/aufs, the one on your home directory is
2837 +not affected, instead the same named file will be newly created under
2838 +/tmp/rw. And all of your modification to a file will be applied to
2839 +the one under /tmp/rw. This is called the file based Copy on Write
2841 +Aufs mount options are described in aufs.5.
2842 +If you run chroot or something and make your aufs as a root directory,
2843 +then you need to customize the shutdown script. See the aufs manual in
2846 +Additionally, there are some sample usages of aufs which are a
2847 +diskless system with network booting, and LiveCD over NFS.
2848 +See sample dir in CVS tree on SourceForge.
2852 +----------------------------------------
2853 +When you have any problems or strange behaviour in aufs, please let me
2855 +- /proc/mounts (instead of the output of mount(8))
2856 +- /sys/module/aufs/*
2857 +- /sys/fs/aufs/* (if you have them)
2858 +- /debug/aufs/* (if you have them)
2859 +- linux kernel version
2860 + if your kernel is not plain, for example modified by distributor,
2861 + the url where i can download its source is necessary too.
2862 +- aufs version which was printed at loading the module or booting the
2863 + system, instead of the date you downloaded.
2864 +- configuration (define/undefine CONFIG_AUFS_xxx)
2865 +- kernel configuration or /proc/config.gz (if you have it)
2866 +- LSM (linux security module, if you are using)
2867 +- behaviour which you think to be incorrect
2868 +- actual operation, reproducible one is better
2869 +- mailto: aufs-users at lists.sourceforge.net
2871 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2872 +and Feature Requests) on SourceForge. Please join and write to
2876 +6. Acknowledgements
2877 +----------------------------------------
2878 +Thanks to everyone who have tried and are using aufs, whoever
2879 +have reported a bug or any feedback.
2881 +Especially donators:
2882 +Tomas Matejicek(slax.org) made a donation (much more than once).
2883 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2884 + scripts) is making "doubling" donations.
2885 + Unfortunately I cannot list all of the donators, but I really
2887 + It ends Aug 2010, but the ordinary donation URL is still available.
2888 + <http://sourceforge.net/donate/index.php?group_id=167503>
2889 +Dai Itasaka made a donation (2007/8).
2890 +Chuck Smith made a donation (2008/4, 10 and 12).
2891 +Henk Schoneveld made a donation (2008/9).
2892 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2893 +Francois Dupoux made a donation (2008/11).
2894 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2895 + aufs2 GIT tree (2009/2).
2896 +William Grant made a donation (2009/3).
2897 +Patrick Lane made a donation (2009/4).
2898 +The Mail Archive (mail-archive.com) made donations (2009/5).
2899 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2900 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2901 +Pavel Pronskiy made a donation (2011/2).
2902 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2903 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2904 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2906 +Sam Liddicott made a donation (2011/9).
2907 +Era Scarecrow made a donation (2013/4).
2908 +Bor Ratajc made a donation (2013/4).
2909 +Alessandro Gorreta made a donation (2013/4).
2910 +POIRETTE Marc made a donation (2013/4).
2911 +Alessandro Gorreta made a donation (2013/4).
2912 +lauri kasvandik made a donation (2013/5).
2913 +"pemasu from Finland" made a donation (2013/7).
2914 +The Parted Magic Project made a donation (2013/9 and 11).
2915 +Pavel Barta made a donation (2013/10).
2916 +Nikolay Pertsev made a donation (2014/5).
2917 +James B made a donation (2014/7 and 2015/7).
2918 +Stefano Di Biase made a donation (2014/8).
2919 +Daniel Epellei made a donation (2015/1).
2920 +OmegaPhil made a donation (2016/1, 2018/4).
2921 +Tomasz Szewczyk made a donation (2016/4).
2922 +James Burry made a donation (2016/12).
2923 +Carsten Rose made a donation (2018/9).
2924 +Porteus Kiosk made a donation (2018/10).
2926 +Thank you very much.
2927 +Donations are always, including future donations, very important and
2928 +helpful for me to keep on developing aufs.
2932 +----------------------------------------
2933 +If you are an experienced user, no explanation is needed. Aufs is
2934 +just a linux filesystem.
2939 +# Local variables: ;
2942 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2943 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2944 +++ linux/fs/aufs/aufs.h 2020-01-27 10:57:18.165538015 +0100
2946 +/* SPDX-License-Identifier: GPL-2.0 */
2948 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2950 + * This program, aufs is free software; you can redistribute it and/or modify
2951 + * it under the terms of the GNU General Public License as published by
2952 + * the Free Software Foundation; either version 2 of the License, or
2953 + * (at your option) any later version.
2955 + * This program is distributed in the hope that it will be useful,
2956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2958 + * GNU General Public License for more details.
2960 + * You should have received a copy of the GNU General Public License
2961 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2965 + * all header files
2973 +#define AuStub(type, name, body, ...) \
2974 + static inline type name(__VA_ARGS__) { body; }
2976 +#define AuStubVoid(name, ...) \
2977 + AuStub(void, name, , __VA_ARGS__)
2978 +#define AuStubInt0(name, ...) \
2979 + AuStub(int, name, return 0, __VA_ARGS__)
2983 +#include "branch.h"
2986 +#include "dbgaufs.h"
2987 +#include "dentry.h"
2989 +#include "dirren.h"
2992 +#include "fstype.h"
2997 +#include "module.h"
3001 +#include "sysaufs.h"
3006 +#endif /* __KERNEL__ */
3007 +#endif /* __AUFS_H__ */
3008 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3009 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3010 +++ linux/fs/aufs/branch.c 2020-01-27 10:57:18.165538015 +0100
3012 +// SPDX-License-Identifier: GPL-2.0
3014 + * Copyright (C) 2005-2020 Junjiro R. Okajima
3016 + * This program, aufs is free software; you can redistribute it and/or modify
3017 + * it under the terms of the GNU General Public License as published by
3018 + * the Free Software Foundation; either version 2 of the License, or
3019 + * (at your option) any later version.
3021 + * This program is distributed in the hope that it will be useful,
3022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3024 + * GNU General Public License for more details.
3026 + * You should have received a copy of the GNU General Public License
3027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3031 + * branch management
3034 +#include <linux/compat.h>
3035 +#include <linux/statfs.h>
3039 + * free a single branch
3041 +static void au_br_do_free(struct au_branch *br)
3044 + struct au_wbr *wbr;
3045 + struct au_dykey **key;
3047 + au_hnotify_fin_br(br);
3048 + /* always, regardless the mount option */
3049 + au_dr_hino_free(&br->br_dirren);
3052 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3053 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3054 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3055 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3059 + for (i = 0; i < AuBrWh_Last; i++)
3060 + dput(wbr->wbr_wh[i]);
3061 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3062 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3065 + if (br->br_fhsm) {
3066 + au_br_fhsm_fin(br->br_fhsm);
3067 + au_kfree_try_rcu(br->br_fhsm);
3070 + key = br->br_dykey;
3071 + for (i = 0; i < AuBrDynOp; i++, key++)
3077 + /* recursive lock, s_umount of branch's */
3078 + /* synchronize_rcu(); */ /* why? */
3080 + path_put(&br->br_path);
3082 + au_kfree_rcu(wbr);
3083 + au_lcnt_wait_for_fin(&br->br_nfiles);
3084 + au_lcnt_wait_for_fin(&br->br_count);
3085 + /* I don't know why, but percpu_refcount requires this */
3086 + /* synchronize_rcu(); */
3091 + * frees all branches
3093 +void au_br_free(struct au_sbinfo *sbinfo)
3095 + aufs_bindex_t bmax;
3096 + struct au_branch **br;
3098 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3100 + bmax = sbinfo->si_bbot + 1;
3101 + br = sbinfo->si_branch;
3103 + au_br_do_free(*br++);
3107 + * find the index of a branch which is specified by @br_id.
3109 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3111 + aufs_bindex_t bindex, bbot;
3113 + bbot = au_sbbot(sb);
3114 + for (bindex = 0; bindex <= bbot; bindex++)
3115 + if (au_sbr_id(sb, bindex) == br_id)
3120 +/* ---------------------------------------------------------------------- */
3126 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3127 + struct dentry *h_root)
3129 + if (unlikely(h_adding == h_root
3130 + || au_test_loopback_overlap(sb, h_adding)))
3132 + if (h_adding->d_sb != h_root->d_sb)
3134 + return au_test_subdir(h_adding, h_root)
3135 + || au_test_subdir(h_root, h_adding);
3139 + * returns a newly allocated branch. @new_nbranch is a number of branches
3140 + * after adding a branch.
3142 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3145 + struct au_branch *add_branch;
3146 + struct dentry *root;
3147 + struct inode *inode;
3151 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3152 + if (unlikely(!add_branch))
3154 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3155 + if (unlikely(!add_branch->br_xino))
3157 + err = au_hnotify_init_br(add_branch, perm);
3158 + if (unlikely(err))
3161 + if (au_br_writable(perm)) {
3162 + /* may be freed separately at changing the branch permission */
3163 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3165 + if (unlikely(!add_branch->br_wbr))
3169 + if (au_br_fhsm(perm)) {
3170 + err = au_fhsm_br_alloc(add_branch);
3171 + if (unlikely(err))
3175 + root = sb->s_root;
3176 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3178 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3180 + inode = d_inode(root);
3181 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3185 + return add_branch; /* success */
3188 + au_kfree_rcu(add_branch->br_wbr);
3190 + au_hnotify_fin_br(add_branch);
3192 + au_xino_put(add_branch);
3194 + au_kfree_rcu(add_branch);
3196 + return ERR_PTR(err);
3200 + * test if the branch permission is legal or not.
3202 +static int test_br(struct inode *inode, int brperm, char *path)
3206 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3211 + pr_err("write permission for readonly mount or inode, %s\n", path);
3219 + * 0: success, the caller will add it
3220 + * plus: success, it is already unified, the caller should ignore it
3223 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3226 + aufs_bindex_t bbot, bindex;
3227 + struct dentry *root, *h_dentry;
3228 + struct inode *inode, *h_inode;
3230 + root = sb->s_root;
3231 + bbot = au_sbbot(sb);
3232 + if (unlikely(bbot >= 0
3233 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3237 + pr_err("%s duplicated\n", add->pathname);
3242 + err = -ENOSPC; /* -E2BIG; */
3243 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3244 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3245 + pr_err("number of branches exceeded %s\n", add->pathname);
3250 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3251 + pr_err("bad index %d\n", add->bindex);
3255 + inode = d_inode(add->path.dentry);
3257 + if (unlikely(!inode->i_nlink)) {
3258 + pr_err("no existence %s\n", add->pathname);
3263 + if (unlikely(inode->i_sb == sb)) {
3264 + pr_err("%s must be outside\n", add->pathname);
3268 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3269 + pr_err("unsupported filesystem, %s (%s)\n",
3270 + add->pathname, au_sbtype(inode->i_sb));
3274 + if (unlikely(inode->i_sb->s_stack_depth)) {
3275 + pr_err("already stacked, %s (%s)\n",
3276 + add->pathname, au_sbtype(inode->i_sb));
3280 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3281 + if (unlikely(err))
3285 + return 0; /* success */
3288 + for (bindex = 0; bindex <= bbot; bindex++)
3289 + if (unlikely(test_overlap(sb, add->path.dentry,
3290 + au_h_dptr(root, bindex)))) {
3291 + pr_err("%s is overlapped\n", add->pathname);
3296 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3297 + h_dentry = au_h_dptr(root, 0);
3298 + h_inode = d_inode(h_dentry);
3299 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3300 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3301 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3302 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3304 + i_uid_read(inode), i_gid_read(inode),
3305 + (inode->i_mode & S_IALLUGO),
3306 + i_uid_read(h_inode), i_gid_read(h_inode),
3307 + (h_inode->i_mode & S_IALLUGO));
3315 + * initialize or clean the whiteouts for an adding branch
3317 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3320 + int err, old_perm;
3321 + aufs_bindex_t bindex;
3322 + struct inode *h_inode;
3323 + struct au_wbr *wbr;
3324 + struct au_hinode *hdir;
3325 + struct dentry *h_dentry;
3327 + err = vfsub_mnt_want_write(au_br_mnt(br));
3328 + if (unlikely(err))
3332 + old_perm = br->br_perm;
3333 + br->br_perm = new_perm;
3336 + bindex = au_br_index(sb, br->br_id);
3337 + if (0 <= bindex) {
3338 + hdir = au_hi(d_inode(sb->s_root), bindex);
3339 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3341 + h_dentry = au_br_dentry(br);
3342 + h_inode = d_inode(h_dentry);
3343 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3346 + err = au_wh_init(br, sb);
3348 + wbr_wh_write_lock(wbr);
3349 + err = au_wh_init(br, sb);
3350 + wbr_wh_write_unlock(wbr);
3353 + au_hn_inode_unlock(hdir);
3355 + inode_unlock(h_inode);
3356 + vfsub_mnt_drop_write(au_br_mnt(br));
3357 + br->br_perm = old_perm;
3359 + if (!err && wbr && !au_br_writable(new_perm)) {
3360 + au_kfree_rcu(wbr);
3361 + br->br_wbr = NULL;
3368 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3372 + struct kstatfs kst;
3373 + struct au_wbr *wbr;
3376 + au_rw_init(&wbr->wbr_wh_rwsem);
3377 + atomic_set(&wbr->wbr_wh_running, 0);
3380 + * a limit for rmdir/rename a dir
3381 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3383 + err = vfs_statfs(&br->br_path, &kst);
3384 + if (unlikely(err))
3387 + if (kst.f_namelen >= NAME_MAX)
3388 + err = au_br_init_wh(sb, br, perm);
3390 + pr_err("%pd(%s), unsupported namelen %ld\n",
3392 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3398 +/* initialize a new branch */
3399 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3400 + struct au_opt_add *add)
3403 + struct au_branch *brbase;
3405 + struct inode *h_inode;
3408 + br->br_perm = add->perm;
3409 + br->br_path = add->path; /* set first, path_get() later */
3410 + spin_lock_init(&br->br_dykey_lock);
3411 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3412 + au_lcnt_init(&br->br_count, /*release*/NULL);
3413 + br->br_id = au_new_br_id(sb);
3414 + AuDebugOn(br->br_id < 0);
3416 + /* always, regardless the given option */
3417 + err = au_dr_br_init(sb, br, &add->path);
3418 + if (unlikely(err))
3421 + if (au_br_writable(add->perm)) {
3422 + err = au_wbr_init(br, sb, add->perm);
3423 + if (unlikely(err))
3427 + if (au_opt_test(au_mntflags(sb), XINO)) {
3428 + brbase = au_sbr(sb, 0);
3429 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3431 + h_inode = d_inode(add->path.dentry);
3432 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3433 + if (unlikely(err)) {
3434 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3439 + sysaufs_br_init(br);
3440 + path_get(&br->br_path);
3441 + goto out; /* success */
3444 + memset(&br->br_path, 0, sizeof(br->br_path));
3449 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3450 + struct au_branch *br, aufs_bindex_t bbot,
3451 + aufs_bindex_t amount)
3453 + struct au_branch **brp;
3455 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3457 + brp = sbinfo->si_branch + bindex;
3458 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3460 + sbinfo->si_bbot++;
3461 + if (unlikely(bbot < 0))
3462 + sbinfo->si_bbot = 0;
3465 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3466 + aufs_bindex_t bbot, aufs_bindex_t amount)
3468 + struct au_hdentry *hdp;
3470 + AuRwMustWriteLock(&dinfo->di_rwsem);
3472 + hdp = au_hdentry(dinfo, bindex);
3473 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3474 + au_h_dentry_init(hdp);
3476 + if (unlikely(bbot < 0))
3477 + dinfo->di_btop = 0;
3480 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3481 + aufs_bindex_t bbot, aufs_bindex_t amount)
3483 + struct au_hinode *hip;
3485 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3487 + hip = au_hinode(iinfo, bindex);
3488 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3489 + au_hinode_init(hip);
3491 + if (unlikely(bbot < 0))
3492 + iinfo->ii_btop = 0;
3495 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3496 + aufs_bindex_t bindex)
3498 + struct dentry *root, *h_dentry;
3499 + struct inode *root_inode, *h_inode;
3500 + aufs_bindex_t bbot, amount;
3502 + root = sb->s_root;
3503 + root_inode = d_inode(root);
3504 + bbot = au_sbbot(sb);
3505 + amount = bbot + 1 - bindex;
3506 + h_dentry = au_br_dentry(br);
3507 + au_sbilist_lock();
3508 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3509 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3510 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3511 + au_set_h_dptr(root, bindex, dget(h_dentry));
3512 + h_inode = d_inode(h_dentry);
3513 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3514 + au_sbilist_unlock();
3517 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3520 + aufs_bindex_t bbot, add_bindex;
3521 + struct dentry *root, *h_dentry;
3522 + struct inode *root_inode;
3523 + struct au_branch *add_branch;
3525 + root = sb->s_root;
3526 + root_inode = d_inode(root);
3527 + IMustLock(root_inode);
3528 + IiMustWriteLock(root_inode);
3529 + err = test_add(sb, add, remount);
3530 + if (unlikely(err < 0))
3534 + goto out; /* success */
3537 + bbot = au_sbbot(sb);
3538 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3539 + err = PTR_ERR(add_branch);
3540 + if (IS_ERR(add_branch))
3543 + err = au_br_init(add_branch, sb, add);
3544 + if (unlikely(err)) {
3545 + au_br_do_free(add_branch);
3549 + add_bindex = add->bindex;
3550 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3551 + au_br_do_add(sb, add_branch, add_bindex);
3552 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3553 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3555 + h_dentry = add->path.dentry;
3556 + if (!add_bindex) {
3557 + au_cpup_attr_all(root_inode, /*force*/1);
3558 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3560 + au_add_nlink(root_inode, d_inode(h_dentry));
3566 +/* ---------------------------------------------------------------------- */
3568 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3569 + unsigned long long max __maybe_unused,
3572 + unsigned long long n;
3573 + struct file **p, *f;
3574 + struct hlist_bl_head *files;
3575 + struct hlist_bl_node *pos;
3576 + struct au_finfo *finfo;
3580 + files = &au_sbi(sb)->si_files;
3581 + hlist_bl_lock(files);
3582 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3583 + f = finfo->fi_file;
3585 + && !special_file(file_inode(f)->i_mode)) {
3589 + AuDebugOn(n > max);
3592 + hlist_bl_unlock(files);
3597 +static struct file **au_farray_alloc(struct super_block *sb,
3598 + unsigned long long *max)
3600 + struct au_sbinfo *sbi;
3603 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3604 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3607 +static void au_farray_free(struct file **a, unsigned long long max)
3609 + unsigned long long ull;
3611 + for (ull = 0; ull < max; ull++)
3617 +/* ---------------------------------------------------------------------- */
3623 +/* to show the line number, do not make it inlined function */
3624 +#define AuVerbose(do_info, fmt, ...) do { \
3626 + pr_info(fmt, ##__VA_ARGS__); \
3629 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3630 + aufs_bindex_t bbot)
3632 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3635 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3636 + aufs_bindex_t bbot)
3638 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3642 + * test if the branch is deletable or not.
3644 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3645 + unsigned int sigen, const unsigned int verbose)
3647 + int err, i, j, ndentry;
3648 + aufs_bindex_t btop, bbot;
3649 + struct au_dcsub_pages dpages;
3650 + struct au_dpage *dpage;
3653 + err = au_dpages_init(&dpages, GFP_NOFS);
3654 + if (unlikely(err))
3656 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3657 + if (unlikely(err))
3660 + for (i = 0; !err && i < dpages.ndpage; i++) {
3661 + dpage = dpages.dpages + i;
3662 + ndentry = dpage->ndentry;
3663 + for (j = 0; !err && j < ndentry; j++) {
3664 + d = dpage->dentries[j];
3665 + AuDebugOn(au_dcount(d) <= 0);
3666 + if (!au_digen_test(d, sigen)) {
3667 + di_read_lock_child(d, AuLock_IR);
3668 + if (unlikely(au_dbrange_test(d))) {
3669 + di_read_unlock(d, AuLock_IR);
3673 + di_write_lock_child(d);
3674 + if (unlikely(au_dbrange_test(d))) {
3675 + di_write_unlock(d);
3678 + err = au_reval_dpath(d, sigen);
3680 + di_downgrade_lock(d, AuLock_IR);
3682 + di_write_unlock(d);
3687 + /* AuDbgDentry(d); */
3688 + btop = au_dbtop(d);
3689 + bbot = au_dbbot(d);
3690 + if (btop <= bindex
3692 + && au_h_dptr(d, bindex)
3693 + && au_test_dbusy(d, btop, bbot)) {
3695 + AuVerbose(verbose, "busy %pd\n", d);
3698 + di_read_unlock(d, AuLock_IR);
3703 + au_dpages_free(&dpages);
3708 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3709 + unsigned int sigen, const unsigned int verbose)
3712 + unsigned long long max, ull;
3713 + struct inode *i, **array;
3714 + aufs_bindex_t btop, bbot;
3716 + array = au_iarray_alloc(sb, &max);
3717 + err = PTR_ERR(array);
3718 + if (IS_ERR(array))
3722 + AuDbg("b%d\n", bindex);
3723 + for (ull = 0; !err && ull < max; ull++) {
3727 + if (i->i_ino == AUFS_ROOT_INO)
3730 + /* AuDbgInode(i); */
3731 + if (au_iigen(i, NULL) == sigen)
3732 + ii_read_lock_child(i);
3734 + ii_write_lock_child(i);
3735 + err = au_refresh_hinode_self(i);
3738 + ii_downgrade_lock(i);
3740 + ii_write_unlock(i);
3745 + btop = au_ibtop(i);
3746 + bbot = au_ibbot(i);
3747 + if (btop <= bindex
3749 + && au_h_iptr(i, bindex)
3750 + && au_test_ibusy(i, btop, bbot)) {
3752 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3755 + ii_read_unlock(i);
3757 + au_iarray_free(array, max);
3763 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3764 + const unsigned int verbose)
3767 + unsigned int sigen;
3769 + sigen = au_sigen(root->d_sb);
3770 + DiMustNoWaiters(root);
3771 + IiMustNoWaiters(d_inode(root));
3772 + di_write_unlock(root);
3773 + err = test_dentry_busy(root, bindex, sigen, verbose);
3775 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3776 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3781 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3782 + struct file **to_free, int *idx)
3785 + unsigned char matched, root;
3786 + aufs_bindex_t bindex, bbot;
3787 + struct au_fidir *fidir;
3788 + struct au_hfile *hfile;
3791 + root = IS_ROOT(file->f_path.dentry);
3794 + to_free[*idx] = file;
3800 + fidir = au_fi(file)->fi_hdir;
3801 + AuDebugOn(!fidir);
3802 + bbot = au_fbbot_dir(file);
3803 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3804 + hfile = fidir->fd_hfile + bindex;
3805 + if (!hfile->hf_file)
3808 + if (hfile->hf_br->br_id == br_id) {
3820 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3821 + struct file **to_free, int opened)
3824 + unsigned long long ull, max;
3825 + aufs_bindex_t btop;
3826 + struct file *file, **array;
3827 + struct dentry *root;
3828 + struct au_hfile *hfile;
3830 + array = au_farray_alloc(sb, &max);
3831 + err = PTR_ERR(array);
3832 + if (IS_ERR(array))
3837 + root = sb->s_root;
3838 + di_write_unlock(root);
3839 + for (ull = 0; ull < max; ull++) {
3840 + file = array[ull];
3841 + if (unlikely(!file))
3844 + /* AuDbg("%pD\n", file); */
3845 + fi_read_lock(file);
3846 + btop = au_fbtop(file);
3847 + if (!d_is_dir(file->f_path.dentry)) {
3848 + hfile = &au_fi(file)->fi_htop;
3849 + if (hfile->hf_br->br_id == br_id)
3852 + err = test_dir_busy(file, br_id, to_free, &idx);
3853 + fi_read_unlock(file);
3854 + if (unlikely(err))
3857 + di_write_lock_child(root);
3858 + au_farray_free(array, max);
3859 + AuDebugOn(idx > opened);
3865 +static void br_del_file(struct file **to_free, unsigned long long opened,
3866 + aufs_bindex_t br_id)
3868 + unsigned long long ull;
3869 + aufs_bindex_t bindex, btop, bbot, bfound;
3870 + struct file *file;
3871 + struct au_fidir *fidir;
3872 + struct au_hfile *hfile;
3874 + for (ull = 0; ull < opened; ull++) {
3875 + file = to_free[ull];
3876 + if (unlikely(!file))
3879 + /* AuDbg("%pD\n", file); */
3880 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3882 + fidir = au_fi(file)->fi_hdir;
3883 + AuDebugOn(!fidir);
3884 + fi_write_lock(file);
3885 + btop = au_fbtop(file);
3886 + bbot = au_fbbot_dir(file);
3887 + for (bindex = btop; bindex <= bbot; bindex++) {
3888 + hfile = fidir->fd_hfile + bindex;
3889 + if (!hfile->hf_file)
3892 + if (hfile->hf_br->br_id == br_id) {
3897 + AuDebugOn(bfound < 0);
3898 + au_set_h_fptr(file, bfound, NULL);
3899 + if (bfound == btop) {
3900 + for (btop++; btop <= bbot; btop++)
3901 + if (au_hf_dir(file, btop)) {
3902 + au_set_fbtop(file, btop);
3906 + fi_write_unlock(file);
3910 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3911 + const aufs_bindex_t bindex,
3912 + const aufs_bindex_t bbot)
3914 + struct au_branch **brp, **p;
3916 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3918 + brp = sbinfo->si_branch + bindex;
3919 + if (bindex < bbot)
3920 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3921 + sbinfo->si_branch[0 + bbot] = NULL;
3922 + sbinfo->si_bbot--;
3924 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3927 + sbinfo->si_branch = p;
3928 + /* harmless error */
3931 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3932 + const aufs_bindex_t bbot)
3934 + struct au_hdentry *hdp, *p;
3936 + AuRwMustWriteLock(&dinfo->di_rwsem);
3938 + hdp = au_hdentry(dinfo, bindex);
3939 + if (bindex < bbot)
3940 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3941 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3944 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3947 + dinfo->di_hdentry = p;
3948 + /* harmless error */
3951 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3952 + const aufs_bindex_t bbot)
3954 + struct au_hinode *hip, *p;
3956 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3958 + hip = au_hinode(iinfo, bindex);
3959 + if (bindex < bbot)
3960 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3961 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3964 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3967 + iinfo->ii_hinode = p;
3968 + /* harmless error */
3971 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3972 + struct au_branch *br)
3974 + aufs_bindex_t bbot;
3975 + struct au_sbinfo *sbinfo;
3976 + struct dentry *root, *h_root;
3977 + struct inode *inode, *h_inode;
3978 + struct au_hinode *hinode;
3980 + SiMustWriteLock(sb);
3982 + root = sb->s_root;
3983 + inode = d_inode(root);
3984 + sbinfo = au_sbi(sb);
3985 + bbot = sbinfo->si_bbot;
3987 + h_root = au_h_dptr(root, bindex);
3988 + hinode = au_hi(inode, bindex);
3989 + h_inode = au_igrab(hinode->hi_inode);
3992 + au_sbilist_lock();
3993 + au_br_do_del_brp(sbinfo, bindex, bbot);
3994 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3995 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3996 + au_sbilist_unlock();
3998 + /* ignore an error */
3999 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4003 + au_br_do_free(br);
4006 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4007 + unsigned long long max, void *arg)
4012 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4015 + unsigned long long opened;
4016 + unsigned int mnt_flags;
4017 + aufs_bindex_t bindex, bbot, br_id;
4018 + unsigned char do_wh, verbose;
4019 + struct au_branch *br;
4020 + struct au_wbr *wbr;
4021 + struct dentry *root;
4022 + struct file **to_free;
4027 + root = sb->s_root;
4028 + bindex = au_find_dbindex(root, del->h_path.dentry);
4031 + goto out; /* success */
4033 + pr_err("%s no such branch\n", del->pathname);
4036 + AuDbg("bindex b%d\n", bindex);
4039 + mnt_flags = au_mntflags(sb);
4040 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4041 + bbot = au_sbbot(sb);
4042 + if (unlikely(!bbot)) {
4043 + AuVerbose(verbose, "no more branches left\n");
4047 + br = au_sbr(sb, bindex);
4048 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4049 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4050 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4054 + br_id = br->br_id;
4055 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4056 + if (unlikely(opened)) {
4057 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4058 + err = PTR_ERR(to_free);
4059 + if (IS_ERR(to_free))
4062 + err = test_file_busy(sb, br_id, to_free, opened);
4063 + if (unlikely(err)) {
4064 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4070 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4072 + /* instead of WbrWhMustWriteLock(wbr) */
4073 + SiMustWriteLock(sb);
4074 + for (i = 0; i < AuBrWh_Last; i++) {
4075 + dput(wbr->wbr_wh[i]);
4076 + wbr->wbr_wh[i] = NULL;
4080 + err = test_children_busy(root, bindex, verbose);
4081 + if (unlikely(err)) {
4090 + * now we confirmed the branch is deletable.
4091 + * let's free the remaining opened dirs on the branch.
4093 + di_write_unlock(root);
4094 + br_del_file(to_free, opened, br_id);
4095 + di_write_lock_child(root);
4098 + sysaufs_brs_del(sb, bindex); /* remove successors */
4099 + dbgaufs_xino_del(br); /* remove one */
4100 + au_br_do_del(sb, bindex, br);
4101 + sysaufs_brs_add(sb, bindex); /* append successors */
4102 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4105 + au_cpup_attr_all(d_inode(root), /*force*/1);
4106 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4108 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4109 + if (au_opt_test(mnt_flags, PLINK))
4110 + au_plink_half_refresh(sb, br_id);
4112 + goto out; /* success */
4116 + rerr = au_br_init_wh(sb, br, br->br_perm);
4118 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4119 + del->pathname, rerr);
4122 + au_farray_free(to_free, opened);
4126 +/* ---------------------------------------------------------------------- */
4128 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4131 + aufs_bindex_t btop, bbot;
4132 + struct aufs_ibusy ibusy;
4133 + struct inode *inode, *h_inode;
4136 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4139 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4141 + /* VERIFY_WRITE */
4142 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4143 + if (unlikely(err)) {
4150 + si_read_lock(sb, AuLock_FLUSH);
4151 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4155 + ibusy.h_ino = 0; /* invalid */
4156 + inode = ilookup(sb, ibusy.ino);
4158 + || inode->i_ino == AUFS_ROOT_INO
4159 + || au_is_bad_inode(inode))
4162 + ii_read_lock_child(inode);
4163 + btop = au_ibtop(inode);
4164 + bbot = au_ibbot(inode);
4165 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4166 + h_inode = au_h_iptr(inode, ibusy.bindex);
4167 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4168 + ibusy.h_ino = h_inode->i_ino;
4170 + ii_read_unlock(inode);
4174 + si_read_unlock(sb);
4176 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4177 + if (unlikely(err)) {
4186 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4188 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4191 +#ifdef CONFIG_COMPAT
4192 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4194 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4198 +/* ---------------------------------------------------------------------- */
4201 + * change a branch permission
4204 +static void au_warn_ima(void)
4207 + /* since it doesn't support mark_files_ro() */
4208 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4212 +static int do_need_sigen_inc(int a, int b)
4214 + return au_br_whable(a) && !au_br_whable(b);
4217 +static int need_sigen_inc(int old, int new)
4219 + return do_need_sigen_inc(old, new)
4220 + || do_need_sigen_inc(new, old);
4223 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4226 + unsigned int mnt_flags;
4227 + unsigned long long ull, max;
4228 + aufs_bindex_t br_id;
4229 + unsigned char verbose, writer;
4230 + struct file *file, *hf, **array;
4231 + struct au_hfile *hfile;
4232 + struct inode *h_inode;
4234 + mnt_flags = au_mntflags(sb);
4235 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4237 + array = au_farray_alloc(sb, &max);
4238 + err = PTR_ERR(array);
4239 + if (IS_ERR(array))
4243 + br_id = au_sbr_id(sb, bindex);
4244 + for (ull = 0; ull < max; ull++) {
4245 + file = array[ull];
4246 + if (unlikely(!file))
4249 + /* AuDbg("%pD\n", file); */
4250 + fi_read_lock(file);
4251 + if (unlikely(au_test_mmapped(file))) {
4253 + AuVerbose(verbose, "mmapped %pD\n", file);
4255 + FiMustNoWaiters(file);
4256 + fi_read_unlock(file);
4260 + hfile = &au_fi(file)->fi_htop;
4261 + hf = hfile->hf_file;
4262 + if (!d_is_reg(file->f_path.dentry)
4263 + || !(file->f_mode & FMODE_WRITE)
4264 + || hfile->hf_br->br_id != br_id
4265 + || !(hf->f_mode & FMODE_WRITE))
4266 + array[ull] = NULL;
4272 + FiMustNoWaiters(file);
4273 + fi_read_unlock(file);
4281 + for (ull = 0; ull < max; ull++) {
4282 + file = array[ull];
4286 + /* todo: already flushed? */
4288 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4289 + * approach which resets f_mode and calls mnt_drop_write() and
4290 + * file_release_write() for each file, because the branch
4291 + * attribute in aufs world is totally different from the native
4294 + /* fi_read_lock(file); */
4295 + hfile = &au_fi(file)->fi_htop;
4296 + hf = hfile->hf_file;
4297 + /* fi_read_unlock(file); */
4298 + spin_lock(&hf->f_lock);
4299 + writer = !!(hf->f_mode & FMODE_WRITER);
4300 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4301 + spin_unlock(&hf->f_lock);
4303 + h_inode = file_inode(hf);
4304 + put_write_access(h_inode);
4305 + __mnt_drop_write(hf->f_path.mnt);
4306 + if ((hf->f_mode & (FMODE_READ | FMODE_WRITE))
4308 + i_readcount_inc(h_inode);
4313 + au_farray_free(array, max);
4319 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4323 + aufs_bindex_t bindex;
4324 + struct dentry *root;
4325 + struct au_branch *br;
4326 + struct au_br_fhsm *bf;
4328 + root = sb->s_root;
4329 + bindex = au_find_dbindex(root, mod->h_root);
4332 + return 0; /* success */
4334 + pr_err("%s no such branch\n", mod->path);
4337 + AuDbg("bindex b%d\n", bindex);
4339 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4340 + if (unlikely(err))
4343 + br = au_sbr(sb, bindex);
4344 + AuDebugOn(mod->h_root != au_br_dentry(br));
4345 + if (br->br_perm == mod->perm)
4346 + return 0; /* success */
4348 + /* pre-allocate for non-fhsm --> fhsm */
4350 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4351 + err = au_fhsm_br_alloc(br);
4352 + if (unlikely(err))
4355 + br->br_fhsm = NULL;
4358 + if (au_br_writable(br->br_perm)) {
4359 + /* remove whiteout base */
4360 + err = au_br_init_wh(sb, br, mod->perm);
4361 + if (unlikely(err))
4364 + if (!au_br_writable(mod->perm)) {
4365 + /* rw --> ro, file might be mmapped */
4366 + DiMustNoWaiters(root);
4367 + IiMustNoWaiters(d_inode(root));
4368 + di_write_unlock(root);
4369 + err = au_br_mod_files_ro(sb, bindex);
4370 + /* aufs_write_lock() calls ..._child() */
4371 + di_write_lock_child(root);
4373 + if (unlikely(err)) {
4375 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4378 + rerr = au_wbr_init(br, sb, br->br_perm);
4379 + if (unlikely(rerr)) {
4380 + AuIOErr("nested error %d (%d)\n",
4382 + br->br_perm = mod->perm;
4386 + } else if (au_br_writable(mod->perm)) {
4389 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4391 + err = au_wbr_init(br, sb, mod->perm);
4392 + if (unlikely(err)) {
4393 + au_kfree_rcu(br->br_wbr);
4394 + br->br_wbr = NULL;
4398 + if (unlikely(err))
4401 + if (au_br_fhsm(br->br_perm)) {
4402 + if (!au_br_fhsm(mod->perm)) {
4403 + /* fhsm --> non-fhsm */
4404 + au_br_fhsm_fin(br->br_fhsm);
4405 + au_kfree_rcu(br->br_fhsm);
4406 + br->br_fhsm = NULL;
4408 + } else if (au_br_fhsm(mod->perm))
4409 + /* non-fhsm --> fhsm */
4412 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4413 + br->br_perm = mod->perm;
4414 + goto out; /* success */
4417 + au_kfree_try_rcu(bf);
4423 +/* ---------------------------------------------------------------------- */
4425 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4428 + struct kstatfs kstfs;
4430 + err = vfs_statfs(&br->br_path, &kstfs);
4432 + stfs->f_blocks = kstfs.f_blocks;
4433 + stfs->f_bavail = kstfs.f_bavail;
4434 + stfs->f_files = kstfs.f_files;
4435 + stfs->f_ffree = kstfs.f_ffree;
4440 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4441 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4442 +++ linux/fs/aufs/branch.h 2020-01-27 10:57:18.165538015 +0100
4444 +/* SPDX-License-Identifier: GPL-2.0 */
4446 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4448 + * This program, aufs is free software; you can redistribute it and/or modify
4449 + * it under the terms of the GNU General Public License as published by
4450 + * the Free Software Foundation; either version 2 of the License, or
4451 + * (at your option) any later version.
4453 + * This program is distributed in the hope that it will be useful,
4454 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4455 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4456 + * GNU General Public License for more details.
4458 + * You should have received a copy of the GNU General Public License
4459 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4463 + * branch filesystems and xino for them
4466 +#ifndef __AUFS_BRANCH_H__
4467 +#define __AUFS_BRANCH_H__
4471 +#include <linux/mount.h>
4472 +#include "dirren.h"
4478 +/* ---------------------------------------------------------------------- */
4482 + struct file **xi_file;
4483 + unsigned int xi_nfile;
4489 + /* reserved for future use */
4490 + /* unsigned long *bitmap; */
4491 + wait_queue_head_t wqh;
4494 + struct mutex xi_mtx; /* protects xi_file array */
4495 + struct hlist_bl_head xi_writing;
4497 + atomic_t xi_truncating;
4499 + struct kref xi_kref;
4502 +/* File-based Hierarchical Storage Management */
4503 +struct au_br_fhsm {
4504 +#ifdef CONFIG_AUFS_FHSM
4505 + struct mutex bf_lock;
4506 + unsigned long bf_jiffy;
4507 + struct aufs_stfs bf_stfs;
4512 +/* members for writable branch only */
4513 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4515 + struct au_rwsem wbr_wh_rwsem;
4516 + struct dentry *wbr_wh[AuBrWh_Last];
4517 + atomic_t wbr_wh_running;
4518 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4519 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4520 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4523 + unsigned long long wbr_bytes;
4526 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4527 +#define AuBrDynOp (AuDyLast * 4)
4529 +#ifdef CONFIG_AUFS_HFSNOTIFY
4530 +/* support for asynchronous destruction */
4531 +struct au_br_hfsnotify {
4532 + struct fsnotify_group *hfsn_group;
4536 +/* sysfs entries */
4537 +struct au_brsysfs {
4539 + struct attribute attr;
4548 +/* protected by superblock rwsem */
4550 + struct au_xino *br_xino;
4552 + aufs_bindex_t br_id;
4555 + struct path br_path;
4556 + spinlock_t br_dykey_lock;
4557 + struct au_dykey *br_dykey[AuBrDynOp];
4558 + au_lcnt_t br_nfiles; /* opened files */
4559 + au_lcnt_t br_count; /* in-use for other */
4561 + struct au_wbr *br_wbr;
4562 + struct au_br_fhsm *br_fhsm;
4564 +#ifdef CONFIG_AUFS_HFSNOTIFY
4565 + struct au_br_hfsnotify *br_hfsn;
4568 +#ifdef CONFIG_SYSFS
4569 + /* entries under sysfs per mount-point */
4570 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4573 +#ifdef CONFIG_DEBUG_FS
4574 + struct dentry *br_dbgaufs; /* xino */
4577 + struct au_dr_br br_dirren;
4580 +/* ---------------------------------------------------------------------- */
4582 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4584 + return br->br_path.mnt;
4587 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4589 + return br->br_path.dentry;
4592 +static inline struct super_block *au_br_sb(struct au_branch *br)
4594 + return au_br_mnt(br)->mnt_sb;
4597 +static inline int au_br_rdonly(struct au_branch *br)
4599 + return (sb_rdonly(au_br_sb(br))
4600 + || !au_br_writable(br->br_perm))
4604 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4606 +#ifdef CONFIG_AUFS_HNOTIFY
4607 + return !(brperm & AuBrPerm_RR);
4613 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4615 + int err, exec_flag;
4618 + exec_flag = oflag & __FMODE_EXEC;
4619 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4625 +static inline void au_xino_get(struct au_branch *br)
4627 + struct au_xino *xi;
4631 + kref_get(&xi->xi_kref);
4634 +static inline int au_xino_count(struct au_branch *br)
4637 + struct au_xino *xi;
4642 + v = kref_read(&xi->xi_kref);
4647 +/* ---------------------------------------------------------------------- */
4651 +void au_br_free(struct au_sbinfo *sinfo);
4652 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4654 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4656 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4657 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4658 +#ifdef CONFIG_COMPAT
4659 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4662 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4665 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4668 +static const loff_t au_loff_max = LLONG_MAX;
4670 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4671 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4673 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4674 + struct file *copy_src);
4676 + struct au_xino *xi; /* switch between xino and xigen */
4678 + struct path *base;
4679 + struct file *copy_src;
4681 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4683 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4685 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4687 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4689 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4690 + size_t size, loff_t *pos);
4692 +int au_xib_trunc(struct super_block *sb);
4693 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4695 +struct au_xino *au_xino_alloc(unsigned int nfile);
4696 +int au_xino_put(struct au_branch *br);
4697 +struct file *au_xino_file1(struct au_xino *xi);
4699 +struct au_opt_xino;
4700 +void au_xino_clr(struct super_block *sb);
4701 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4702 +struct file *au_xino_def(struct super_block *sb);
4703 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4704 + struct path *base);
4706 +ino_t au_xino_new_ino(struct super_block *sb);
4707 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4709 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4710 + ino_t h_ino, int idx);
4711 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4714 +int au_xino_path(struct seq_file *seq, struct file *file);
4716 +/* ---------------------------------------------------------------------- */
4718 +/* @idx is signed to accept -1 meaning the first file */
4719 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4721 + struct file *file;
4728 + if (idx < xi->xi_nfile)
4729 + file = xi->xi_file[idx];
4731 + file = au_xino_file1(xi);
4737 +/* ---------------------------------------------------------------------- */
4739 +/* Superblock to branch */
4741 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4743 + return au_sbr(sb, bindex)->br_id;
4747 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4749 + return au_br_mnt(au_sbr(sb, bindex));
4753 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4755 + return au_br_sb(au_sbr(sb, bindex));
4758 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4760 + return au_sbr(sb, bindex)->br_perm;
4763 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4765 + return au_br_whable(au_sbr_perm(sb, bindex));
4768 +/* ---------------------------------------------------------------------- */
4770 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4771 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4772 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4773 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4775 +#define wbr_wh_read_trylock_nested(wbr) \
4776 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4777 +#define wbr_wh_write_trylock_nested(wbr) \
4778 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4781 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4782 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4783 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4785 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4786 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4787 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4789 +/* ---------------------------------------------------------------------- */
4791 +#ifdef CONFIG_AUFS_FHSM
4792 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4794 + mutex_init(&brfhsm->bf_lock);
4795 + brfhsm->bf_jiffy = 0;
4796 + brfhsm->bf_readable = 0;
4799 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4801 + mutex_destroy(&brfhsm->bf_lock);
4804 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4805 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4808 +#endif /* __KERNEL__ */
4809 +#endif /* __AUFS_BRANCH_H__ */
4810 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4811 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4812 +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200
4814 +# SPDX-License-Identifier: GPL-2.0
4816 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4820 +AuConfStr += ${1}=${${1}}
4824 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4826 + HNOTIFY HFSNOTIFY \
4838 +$(foreach i, ${AuConfAll}, \
4839 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4841 +AuConfName = ${obj}/conf.str
4842 +${AuConfName}.tmp: FORCE
4843 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4844 +${AuConfName}: ${AuConfName}.tmp
4845 + @diff -q $< $@ > /dev/null 2>&1 || { \
4846 + echo ' GEN ' $@; \
4850 +clean-files += ${AuConfName} ${AuConfName}.tmp
4851 +${obj}/sysfs.o: ${AuConfName}
4853 +-include ${srctree}/${src}/conf_priv.mk
4854 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4855 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4856 +++ linux/fs/aufs/cpup.c 2020-01-27 10:57:18.165538015 +0100
4858 +// SPDX-License-Identifier: GPL-2.0
4860 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4862 + * This program, aufs is free software; you can redistribute it and/or modify
4863 + * it under the terms of the GNU General Public License as published by
4864 + * the Free Software Foundation; either version 2 of the License, or
4865 + * (at your option) any later version.
4867 + * This program is distributed in the hope that it will be useful,
4868 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4869 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4870 + * GNU General Public License for more details.
4872 + * You should have received a copy of the GNU General Public License
4873 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4877 + * copy-up functions, see wbr_policy.c for copy-down
4880 +#include <linux/fs_stack.h>
4881 +#include <linux/mm.h>
4882 +#include <linux/task_work.h>
4885 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4887 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4888 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4890 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4892 + dst->i_flags |= iflags & ~mask;
4893 + if (au_test_fs_notime(dst->i_sb))
4894 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4897 +void au_cpup_attr_timesizes(struct inode *inode)
4899 + struct inode *h_inode;
4901 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4902 + fsstack_copy_attr_times(inode, h_inode);
4903 + fsstack_copy_inode_size(inode, h_inode);
4906 +void au_cpup_attr_nlink(struct inode *inode, int force)
4908 + struct inode *h_inode;
4909 + struct super_block *sb;
4910 + aufs_bindex_t bindex, bbot;
4913 + bindex = au_ibtop(inode);
4914 + h_inode = au_h_iptr(inode, bindex);
4916 + && !S_ISDIR(h_inode->i_mode)
4917 + && au_opt_test(au_mntflags(sb), PLINK)
4918 + && au_plink_test(inode))
4922 + * 0 can happen in revalidating.
4923 + * h_inode->i_mutex may not be held here, but it is harmless since once
4924 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4926 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4927 + * the incorrect link count.
4929 + set_nlink(inode, h_inode->i_nlink);
4932 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4933 + * it may includes whplink directory.
4935 + if (S_ISDIR(h_inode->i_mode)) {
4936 + bbot = au_ibbot(inode);
4937 + for (bindex++; bindex <= bbot; bindex++) {
4938 + h_inode = au_h_iptr(inode, bindex);
4940 + au_add_nlink(inode, h_inode);
4945 +void au_cpup_attr_changeable(struct inode *inode)
4947 + struct inode *h_inode;
4949 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4950 + inode->i_mode = h_inode->i_mode;
4951 + inode->i_uid = h_inode->i_uid;
4952 + inode->i_gid = h_inode->i_gid;
4953 + au_cpup_attr_timesizes(inode);
4954 + au_cpup_attr_flags(inode, h_inode->i_flags);
4957 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4959 + struct au_iinfo *iinfo = au_ii(inode);
4961 + IiMustWriteLock(inode);
4963 + iinfo->ii_higen = h_inode->i_generation;
4964 + iinfo->ii_hsb1 = h_inode->i_sb;
4967 +void au_cpup_attr_all(struct inode *inode, int force)
4969 + struct inode *h_inode;
4971 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4972 + au_cpup_attr_changeable(inode);
4973 + if (inode->i_nlink > 0)
4974 + au_cpup_attr_nlink(inode, force);
4975 + inode->i_rdev = h_inode->i_rdev;
4976 + inode->i_blkbits = h_inode->i_blkbits;
4977 + au_cpup_igen(inode, h_inode);
4980 +/* ---------------------------------------------------------------------- */
4982 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4984 +/* keep the timestamps of the parent dir when cpup */
4985 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4986 + struct path *h_path)
4988 + struct inode *h_inode;
4990 + dt->dt_dentry = dentry;
4991 + dt->dt_h_path = *h_path;
4992 + h_inode = d_inode(h_path->dentry);
4993 + dt->dt_atime = h_inode->i_atime;
4994 + dt->dt_mtime = h_inode->i_mtime;
4998 +void au_dtime_revert(struct au_dtime *dt)
5000 + struct iattr attr;
5003 + attr.ia_atime = dt->dt_atime;
5004 + attr.ia_mtime = dt->dt_mtime;
5005 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5006 + | ATTR_ATIME | ATTR_ATIME_SET;
5008 + /* no delegation since this is a directory */
5009 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5010 + if (unlikely(err))
5011 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5014 +/* ---------------------------------------------------------------------- */
5016 +/* internal use only */
5017 +struct au_cpup_reg_attr {
5020 + unsigned int iflags; /* inode->i_flags */
5023 +static noinline_for_stack
5024 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5025 + struct au_cpup_reg_attr *h_src_attr)
5027 + int err, sbits, icex;
5028 + unsigned int mnt_flags;
5029 + unsigned char verbose;
5031 + struct path h_path;
5032 + struct inode *h_isrc, *h_idst;
5033 + struct kstat *h_st;
5034 + struct au_branch *br;
5036 + h_path.dentry = au_h_dptr(dst, bindex);
5037 + h_idst = d_inode(h_path.dentry);
5038 + br = au_sbr(dst->d_sb, bindex);
5039 + h_path.mnt = au_br_mnt(br);
5040 + h_isrc = d_inode(h_src);
5041 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5042 + | ATTR_ATIME | ATTR_MTIME
5043 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5044 + if (h_src_attr && h_src_attr->valid) {
5045 + h_st = &h_src_attr->st;
5046 + ia.ia_uid = h_st->uid;
5047 + ia.ia_gid = h_st->gid;
5048 + ia.ia_atime = h_st->atime;
5049 + ia.ia_mtime = h_st->mtime;
5050 + if (h_idst->i_mode != h_st->mode
5051 + && !S_ISLNK(h_idst->i_mode)) {
5052 + ia.ia_valid |= ATTR_MODE;
5053 + ia.ia_mode = h_st->mode;
5055 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5056 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5058 + ia.ia_uid = h_isrc->i_uid;
5059 + ia.ia_gid = h_isrc->i_gid;
5060 + ia.ia_atime = h_isrc->i_atime;
5061 + ia.ia_mtime = h_isrc->i_mtime;
5062 + if (h_idst->i_mode != h_isrc->i_mode
5063 + && !S_ISLNK(h_idst->i_mode)) {
5064 + ia.ia_valid |= ATTR_MODE;
5065 + ia.ia_mode = h_isrc->i_mode;
5067 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5068 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5070 + /* no delegation since it is just created */
5071 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5073 + /* is this nfs only? */
5074 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5075 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5076 + ia.ia_mode = h_isrc->i_mode;
5077 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5080 + icex = br->br_perm & AuBrAttr_ICEX;
5082 + mnt_flags = au_mntflags(dst->d_sb);
5083 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5084 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5090 +/* ---------------------------------------------------------------------- */
5092 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5093 + char *buf, unsigned long blksize)
5096 + size_t sz, rbytes, wbytes;
5097 + unsigned char all_zero;
5099 + struct inode *h_inode;
5100 + /* reduce stack usage */
5103 + zp = page_address(ZERO_PAGE(0));
5104 + if (unlikely(!zp))
5105 + return -ENOMEM; /* possible? */
5110 + AuDbg("len %lld\n", len);
5112 + if (len < blksize)
5116 + /* todo: signal_pending? */
5117 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5118 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5121 + if (unlikely(err < 0))
5125 + if (len >= rbytes && rbytes == blksize)
5126 + all_zero = !memcmp(buf, zp, rbytes);
5133 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5135 + /* todo: signal_pending? */
5136 + if (unlikely(err == -EAGAIN || err == -EINTR))
5138 + if (unlikely(err < 0))
5143 + if (unlikely(err < 0))
5149 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5151 + if (unlikely(res < 0))
5158 + /* the last block may be a hole */
5159 + if (!err && all_zero) {
5160 + AuLabel(last hole);
5163 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5164 + /* nfs requires this step to make last hole */
5165 + /* is this only nfs? */
5167 + /* todo: signal_pending? */
5168 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5169 + } while (err == -EAGAIN || err == -EINTR);
5176 + ia->ia_size = dst->f_pos;
5177 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5178 + ia->ia_file = dst;
5179 + h_inode = file_inode(dst);
5180 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5181 + /* no delegation since it is just created */
5182 + err = vfsub_notify_change(&dst->f_path, ia,
5183 + /*delegated*/NULL);
5184 + inode_unlock(h_inode);
5191 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5194 + unsigned long blksize;
5195 + unsigned char do_kfree;
5197 + struct super_block *h_sb;
5200 + h_sb = file_inode(dst)->i_sb;
5201 + blksize = h_sb->s_blocksize;
5202 + if (!blksize || PAGE_SIZE < blksize)
5203 + blksize = PAGE_SIZE;
5204 + AuDbg("blksize %lu\n", blksize);
5205 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5207 + buf = kmalloc(blksize, GFP_NOFS);
5209 + buf = (void *)__get_free_page(GFP_NOFS);
5210 + if (unlikely(!buf))
5213 + if (len > (1 << 22))
5214 + AuDbg("copying a large file %lld\n", (long long)len);
5218 + err = au_do_copy_file(dst, src, len, buf, blksize);
5220 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5221 + au_kfree_do_rcu(buf);
5223 + free_page((unsigned long)buf);
5229 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5232 + struct super_block *h_src_sb;
5233 + struct inode *h_src_inode;
5235 + h_src_inode = file_inode(src);
5236 + h_src_sb = h_src_inode->i_sb;
5238 + /* XFS acquires inode_lock */
5239 + if (!au_test_xfs(h_src_sb))
5240 + err = au_copy_file(dst, src, len);
5242 + inode_unlock_shared(h_src_inode);
5243 + err = au_copy_file(dst, src, len);
5244 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5250 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5254 + struct super_block *h_src_sb;
5255 + struct inode *h_src_inode;
5257 + h_src_inode = file_inode(src);
5258 + h_src_sb = h_src_inode->i_sb;
5259 + if (h_src_sb != file_inode(dst)->i_sb
5260 + || !dst->f_op->remap_file_range) {
5261 + err = au_do_copy(dst, src, len);
5265 + if (!au_test_nfs(h_src_sb)) {
5266 + inode_unlock_shared(h_src_inode);
5267 + lo = vfsub_clone_file_range(src, dst, len);
5268 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5270 + lo = vfsub_clone_file_range(src, dst, len);
5273 + goto out; /* success */
5274 + } else if (lo >= 0)
5275 + /* todo: possible? */
5276 + /* paritially succeeded */
5277 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5278 + else if (lo != -EOPNOTSUPP) {
5279 + /* older XFS has a condition in cloning */
5284 + /* the backend fs on NFS may not support cloning */
5285 + err = au_do_copy(dst, src, len);
5293 + * to support a sparse file which is opened with O_APPEND,
5294 + * we need to close the file.
5296 +static int au_cp_regular(struct au_cp_generic *cpg)
5299 + enum { SRC, DST };
5301 + aufs_bindex_t bindex;
5302 + unsigned int flags;
5303 + struct dentry *dentry;
5305 + struct file *file;
5308 + .bindex = cpg->bsrc,
5309 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5312 + .bindex = cpg->bdst,
5313 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5314 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5317 + struct au_branch *br;
5318 + struct super_block *sb, *h_src_sb;
5319 + struct inode *h_src_inode;
5320 + struct task_struct *tsk = current;
5322 + /* bsrc branch can be ro/rw. */
5323 + sb = cpg->dentry->d_sb;
5325 + for (i = 0; i < 2; i++, f++) {
5326 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5327 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5328 + /*file*/NULL, f->force_wr);
5329 + if (IS_ERR(f->file)) {
5330 + err = PTR_ERR(f->file);
5338 + /* try stopping to update while we copyup */
5339 + h_src_inode = d_inode(file[SRC].dentry);
5340 + h_src_sb = h_src_inode->i_sb;
5341 + if (!au_test_nfs(h_src_sb))
5342 + IMustLock(h_src_inode);
5343 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5345 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5346 + if (tsk->flags & PF_KTHREAD)
5347 + __fput_sync(file[DST].file);
5349 + /* it happened actually */
5350 + fput(file[DST].file);
5353 + * we have to call both since we don't know which place the file
5357 + flush_delayed_fput();
5359 + br = au_sbr(sb, file[DST].bindex);
5360 + au_lcnt_dec(&br->br_nfiles);
5363 + fput(file[SRC].file);
5364 + br = au_sbr(sb, file[SRC].bindex);
5365 + au_lcnt_dec(&br->br_nfiles);
5370 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5371 + struct au_cpup_reg_attr *h_src_attr)
5375 + struct path h_path;
5376 + struct inode *h_src_inode, *h_dst_inode;
5379 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5380 + l = i_size_read(h_src_inode);
5381 + if (cpg->len == -1 || l < cpg->len)
5384 + /* try stopping to update while we are referencing */
5385 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5386 + au_pin_hdir_unlock(cpg->pin);
5388 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5389 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5390 + h_src_attr->iflags = h_src_inode->i_flags;
5391 + if (!au_test_nfs(h_src_inode->i_sb))
5392 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5394 + inode_unlock_shared(h_src_inode);
5395 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5396 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5398 + if (unlikely(err)) {
5399 + inode_unlock_shared(h_src_inode);
5402 + h_src_attr->valid = 1;
5403 + if (!au_test_nfs(h_src_inode->i_sb)) {
5404 + err = au_cp_regular(cpg);
5405 + inode_unlock_shared(h_src_inode);
5407 + inode_unlock_shared(h_src_inode);
5408 + err = au_cp_regular(cpg);
5410 + rerr = au_pin_hdir_relock(cpg->pin);
5414 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5415 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5416 + h_dst_inode = d_inode(h_path.dentry);
5417 + spin_lock(&h_dst_inode->i_lock);
5418 + h_dst_inode->i_state |= I_LINKABLE;
5419 + spin_unlock(&h_dst_inode->i_lock);
5426 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5427 + struct inode *h_dir)
5430 + mm_segment_t old_fs;
5437 + sym.k = (void *)__get_free_page(GFP_NOFS);
5438 + if (unlikely(!sym.k))
5441 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5442 + old_fs = get_fs();
5443 + set_fs(KERNEL_DS);
5444 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5449 + sym.k[symlen] = 0;
5450 + err = vfsub_symlink(h_dir, h_path, sym.k);
5452 + free_page((unsigned long)sym.k);
5459 + * regardless 'acl' option, reset all ACL.
5460 + * All ACL will be copied up later from the original entry on the lower branch.
5462 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5465 + struct dentry *h_dentry;
5466 + struct inode *h_inode;
5468 + h_dentry = h_path->dentry;
5469 + h_inode = d_inode(h_dentry);
5470 + /* forget_all_cached_acls(h_inode)); */
5471 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5473 + if (err == -EOPNOTSUPP)
5476 + err = vfsub_acl_chmod(h_inode, mode);
5482 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5483 + struct inode *h_dir, struct path *h_path)
5486 + struct inode *dir, *inode;
5488 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5490 + if (err == -EOPNOTSUPP)
5492 + if (unlikely(err))
5496 + * strange behaviour from the users view,
5497 + * particularly setattr case
5499 + dir = d_inode(dst_parent);
5500 + if (au_ibtop(dir) == cpg->bdst)
5501 + au_cpup_attr_nlink(dir, /*force*/1);
5502 + inode = d_inode(cpg->dentry);
5503 + au_cpup_attr_nlink(inode, /*force*/1);
5509 +static noinline_for_stack
5510 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5511 + struct au_cpup_reg_attr *h_src_attr)
5515 + unsigned int mnt_flags;
5516 + unsigned char isdir, isreg, force;
5517 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5518 + struct au_dtime dt;
5519 + struct path h_path;
5520 + struct dentry *h_src, *h_dst, *h_parent;
5521 + struct inode *h_inode, *h_dir;
5522 + struct super_block *sb;
5524 + /* bsrc branch can be ro/rw. */
5525 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5526 + h_inode = d_inode(h_src);
5527 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5529 + /* try stopping to be referenced while we are creating */
5530 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5531 + if (au_ftest_cpup(cpg->flags, RENAME))
5532 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5533 + AUFS_WH_PFX_LEN));
5534 + h_parent = h_dst->d_parent; /* dir inode is locked */
5535 + h_dir = d_inode(h_parent);
5537 + AuDebugOn(h_parent != h_dst->d_parent);
5539 + sb = cpg->dentry->d_sb;
5540 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5542 + h_path.dentry = h_parent;
5543 + au_dtime_store(&dt, dst_parent, &h_path);
5545 + h_path.dentry = h_dst;
5549 + mode = h_inode->i_mode;
5550 + switch (mode & S_IFMT) {
5553 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5555 + err = au_do_cpup_regular(cpg, h_src_attr);
5559 + err = vfsub_mkdir(h_dir, &h_path, mode);
5561 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5564 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5568 + AuDebugOn(!capable(CAP_MKNOD));
5572 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5575 + AuIOErr("Unknown inode type 0%o\n", mode);
5579 + err = au_reset_acl(h_dir, &h_path, mode);
5581 + mnt_flags = au_mntflags(sb);
5582 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5584 + && au_opt_test(mnt_flags, XINO)
5585 + && (h_inode->i_nlink == 1
5586 + || (h_inode->i_state & I_LINKABLE))
5587 + /* todo: unnecessary? */
5588 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5589 + && cpg->bdst < cpg->bsrc
5590 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5591 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5592 + /* ignore this error */
5597 + force = !!cpg->len;
5598 + if (cpg->len == -1)
5599 + force = !!i_size_read(h_inode);
5601 + au_fhsm_wrote(sb, cpg->bdst, force);
5605 + au_dtime_revert(&dt);
5609 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5612 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5613 + struct inode *h_dir;
5614 + aufs_bindex_t bdst;
5616 + dentry = cpg->dentry;
5618 + h_dentry = au_h_dptr(dentry, bdst);
5619 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5621 + au_set_h_dptr(dentry, bdst, NULL);
5622 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5624 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5625 + au_set_h_dptr(dentry, bdst, h_dentry);
5628 + parent = dget_parent(dentry);
5629 + h_parent = au_h_dptr(parent, bdst);
5631 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5632 + if (IS_ERR(h_path->dentry))
5633 + err = PTR_ERR(h_path->dentry);
5635 + if (unlikely(err))
5638 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5639 + h_dir = d_inode(h_parent);
5641 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5642 + /* no delegation since it is just created */
5643 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5645 + dput(h_path->dentry);
5652 + * copyup the @dentry from @bsrc to @bdst.
5653 + * the caller must set the both of lower dentries.
5654 + * @len is for truncating when it is -1 copyup the entire file.
5655 + * in link/rename cases, @dst_parent may be different from the real one.
5656 + * basic->bsrc can be larger than basic->bdst.
5657 + * aufs doesn't touch the credential so
5658 + * security_inode_copy_up{,_xattr}() are unnecessary.
5660 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5663 + aufs_bindex_t old_ibtop;
5664 + unsigned char isdir, plink;
5665 + struct dentry *h_src, *h_dst, *h_parent;
5666 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5667 + struct super_block *sb;
5668 + struct au_branch *br;
5669 + /* to reduce stack size */
5671 + struct au_dtime dt;
5672 + struct path h_path;
5673 + struct au_cpup_reg_attr h_src_attr;
5677 + a = kmalloc(sizeof(*a), GFP_NOFS);
5680 + a->h_src_attr.valid = 0;
5682 + sb = cpg->dentry->d_sb;
5683 + br = au_sbr(sb, cpg->bdst);
5684 + a->h_path.mnt = au_br_mnt(br);
5685 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5686 + h_parent = h_dst->d_parent; /* dir inode is locked */
5687 + h_dir = d_inode(h_parent);
5690 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5691 + inode = d_inode(cpg->dentry);
5694 + dst_parent = dget_parent(cpg->dentry);
5698 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5699 + dst_inode = au_h_iptr(inode, cpg->bdst);
5701 + if (unlikely(!plink)) {
5703 + AuIOErr("hi%lu(i%lu) exists on b%d "
5704 + "but plink is disabled\n",
5705 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5709 + if (dst_inode->i_nlink) {
5710 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5712 + h_src = au_plink_lkup(inode, cpg->bdst);
5713 + err = PTR_ERR(h_src);
5714 + if (IS_ERR(h_src))
5716 + if (unlikely(d_is_negative(h_src))) {
5718 + AuIOErr("i%lu exists on b%d "
5719 + "but not pseudo-linked\n",
5720 + inode->i_ino, cpg->bdst);
5726 + a->h_path.dentry = h_parent;
5727 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5730 + a->h_path.dentry = h_dst;
5732 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5733 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5734 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5736 + au_dtime_revert(&a->dt);
5737 + if (unlikely(err == -EWOULDBLOCK)) {
5738 + pr_warn("cannot retry for NFSv4 delegation"
5739 + " for an internal link\n");
5745 + /* todo: cpup_wh_file? */
5747 + au_update_ibrange(inode, /*do_put_zero*/1);
5750 + isdir = S_ISDIR(inode->i_mode);
5751 + old_ibtop = au_ibtop(inode);
5752 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5753 + if (unlikely(err))
5755 + dst_inode = d_inode(h_dst);
5756 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5757 + /* todo: necessary? */
5758 + /* au_pin_hdir_unlock(cpg->pin); */
5760 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5761 + if (unlikely(err)) {
5762 + /* todo: necessary? */
5763 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5764 + inode_unlock(dst_inode);
5768 + if (cpg->bdst < old_ibtop) {
5769 + if (S_ISREG(inode->i_mode)) {
5770 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5771 + if (unlikely(err)) {
5772 + /* ignore an error */
5773 + /* au_pin_hdir_relock(cpg->pin); */
5774 + inode_unlock(dst_inode);
5778 + au_set_ibtop(inode, cpg->bdst);
5780 + au_set_ibbot(inode, cpg->bdst);
5781 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5782 + au_hi_flags(inode, isdir));
5784 + /* todo: necessary? */
5785 + /* err = au_pin_hdir_relock(cpg->pin); */
5786 + inode_unlock(dst_inode);
5787 + if (unlikely(err))
5790 + src_inode = d_inode(h_src);
5792 + && (src_inode->i_nlink > 1
5793 + || src_inode->i_state & I_LINKABLE)
5795 + au_plink_append(inode, cpg->bdst, h_dst);
5797 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5798 + a->h_path.dentry = h_dst;
5799 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5802 + goto out_parent; /* success */
5806 + a->h_path.dentry = h_parent;
5807 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5808 + a->h_path.dentry = h_dst;
5810 + if (d_is_positive(h_dst)) {
5812 + /* no delegation since it is just created */
5813 + rerr = vfsub_unlink(h_dir, &a->h_path,
5814 + /*delegated*/NULL, /*force*/0);
5816 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5818 + au_dtime_revert(&a->dt);
5820 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5830 +#if 0 /* reserved */
5831 +struct au_cpup_single_args {
5833 + struct au_cp_generic *cpg;
5834 + struct dentry *dst_parent;
5837 +static void au_call_cpup_single(void *args)
5839 + struct au_cpup_single_args *a = args;
5841 + au_pin_hdir_acquire_nest(a->cpg->pin);
5842 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5843 + au_pin_hdir_release(a->cpg->pin);
5848 + * prevent SIGXFSZ in copy-up.
5849 + * testing CAP_MKNOD is for generic fs,
5850 + * but CAP_FSETID is for xfs only, currently.
5852 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5855 + struct super_block *sb;
5856 + struct inode *h_dir;
5859 + sb = au_pinned_parent(pin)->d_sb;
5860 + if (!au_wkq_test()
5861 + && (!au_sbi(sb)->si_plink_maint_pid
5862 + || au_plink_maint(sb, AuLock_NOPLM))) {
5863 + switch (mode & S_IFMT) {
5865 + /* no condition about RLIMIT_FSIZE and the file size */
5870 + do_sio = !capable(CAP_MKNOD);
5874 + do_sio = ((mode & (S_ISUID | S_ISGID))
5875 + && !capable(CAP_FSETID));
5876 + /* this workaround may be removed in the future */
5878 + h_dir = au_pinned_h_dir(pin);
5879 + do_sio = h_dir->i_mode & S_ISVTX;
5886 +#if 0 /* reserved */
5887 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5890 + struct dentry *h_dentry;
5892 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5893 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5894 + err = au_cpup_single(cpg, dst_parent);
5896 + struct au_cpup_single_args args = {
5899 + .dst_parent = dst_parent
5901 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5902 + if (unlikely(wkq_err))
5911 + * copyup the @dentry from the first active lower branch to @bdst,
5912 + * using au_cpup_single().
5914 +static int au_cpup_simple(struct au_cp_generic *cpg)
5917 + unsigned int flags_orig;
5918 + struct dentry *dentry;
5920 + AuDebugOn(cpg->bsrc < 0);
5922 + dentry = cpg->dentry;
5923 + DiMustWriteLock(dentry);
5925 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5927 + flags_orig = cpg->flags;
5928 + au_fset_cpup(cpg->flags, RENAME);
5929 + err = au_cpup_single(cpg, NULL);
5930 + cpg->flags = flags_orig;
5932 + return 0; /* success */
5935 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5936 + au_set_dbtop(dentry, cpg->bsrc);
5942 +struct au_cpup_simple_args {
5944 + struct au_cp_generic *cpg;
5947 +static void au_call_cpup_simple(void *args)
5949 + struct au_cpup_simple_args *a = args;
5951 + au_pin_hdir_acquire_nest(a->cpg->pin);
5952 + *a->errp = au_cpup_simple(a->cpg);
5953 + au_pin_hdir_release(a->cpg->pin);
5956 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5959 + struct dentry *dentry, *parent;
5960 + struct file *h_file;
5961 + struct inode *h_dir;
5963 + dentry = cpg->dentry;
5965 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5966 + AuDebugOn(cpg->bsrc < 0);
5967 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5968 + err = PTR_ERR(h_file);
5969 + if (IS_ERR(h_file))
5973 + parent = dget_parent(dentry);
5974 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5975 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5976 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5977 + err = au_cpup_simple(cpg);
5979 + struct au_cpup_simple_args args = {
5983 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5984 + if (unlikely(wkq_err))
5990 + au_h_open_post(dentry, cpg->bsrc, h_file);
5996 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5998 + aufs_bindex_t bsrc, bbot;
5999 + struct dentry *dentry, *h_dentry;
6001 + if (cpg->bsrc < 0) {
6002 + dentry = cpg->dentry;
6003 + bbot = au_dbbot(dentry);
6004 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6005 + h_dentry = au_h_dptr(dentry, bsrc);
6007 + AuDebugOn(d_is_negative(h_dentry));
6011 + AuDebugOn(bsrc > bbot);
6014 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6015 + return au_do_sio_cpup_simple(cpg);
6018 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6020 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6021 + return au_do_sio_cpup_simple(cpg);
6024 +/* ---------------------------------------------------------------------- */
6027 + * copyup the deleted file for writing.
6029 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6030 + struct file *file)
6033 + unsigned int flags_orig;
6034 + aufs_bindex_t bsrc_orig;
6035 + struct au_dinfo *dinfo;
6037 + struct au_hdentry *hd;
6038 + struct dentry *h_dentry;
6041 + dinfo = au_di(cpg->dentry);
6042 + AuRwMustWriteLock(&dinfo->di_rwsem);
6044 + bsrc_orig = cpg->bsrc;
6045 + cpg->bsrc = dinfo->di_btop;
6046 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6047 + hdst.h_dentry = hdst.hd->hd_dentry;
6048 + hdst.hd->hd_dentry = wh_dentry;
6049 + dinfo->di_btop = cpg->bdst;
6051 + hsrc.h_dentry = NULL;
6053 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6054 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6055 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6057 + flags_orig = cpg->flags;
6058 + cpg->flags = !AuCpup_DTIME;
6059 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6060 + cpg->flags = flags_orig;
6063 + err = au_reopen_nondir(file);
6064 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6066 + hdst.hd->hd_dentry = hdst.h_dentry;
6067 + dinfo->di_btop = cpg->bsrc;
6068 + cpg->bsrc = bsrc_orig;
6073 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6076 + aufs_bindex_t bdst;
6077 + struct au_dtime dt;
6078 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6079 + struct au_branch *br;
6080 + struct path h_path;
6082 + dentry = cpg->dentry;
6084 + br = au_sbr(dentry->d_sb, bdst);
6085 + parent = dget_parent(dentry);
6086 + h_parent = au_h_dptr(parent, bdst);
6087 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6088 + err = PTR_ERR(wh_dentry);
6089 + if (IS_ERR(wh_dentry))
6092 + h_path.dentry = h_parent;
6093 + h_path.mnt = au_br_mnt(br);
6094 + au_dtime_store(&dt, parent, &h_path);
6095 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6096 + if (unlikely(err))
6100 + h_path.dentry = wh_dentry;
6101 + if (!d_is_dir(wh_dentry)) {
6102 + /* no delegation since it is just created */
6103 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6104 + /*delegated*/NULL, /*force*/0);
6106 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6107 + if (unlikely(err)) {
6108 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6112 + au_dtime_revert(&dt);
6113 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6122 +struct au_cpup_wh_args {
6124 + struct au_cp_generic *cpg;
6125 + struct file *file;
6128 +static void au_call_cpup_wh(void *args)
6130 + struct au_cpup_wh_args *a = args;
6132 + au_pin_hdir_acquire_nest(a->cpg->pin);
6133 + *a->errp = au_cpup_wh(a->cpg, a->file);
6134 + au_pin_hdir_release(a->cpg->pin);
6137 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6140 + aufs_bindex_t bdst;
6141 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6142 + struct inode *dir, *h_dir, *h_tmpdir;
6143 + struct au_wbr *wbr;
6144 + struct au_pin wh_pin, *pin_orig;
6146 + dentry = cpg->dentry;
6148 + parent = dget_parent(dentry);
6149 + dir = d_inode(parent);
6152 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6155 + if (!h_dir->i_nlink) {
6156 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6157 + h_orph = wbr->wbr_orph;
6159 + h_parent = dget(au_h_dptr(parent, bdst));
6160 + au_set_h_dptr(parent, bdst, dget(h_orph));
6161 + h_tmpdir = d_inode(h_orph);
6162 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6164 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6165 + /* todo: au_h_open_pre()? */
6167 + pin_orig = cpg->pin;
6168 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6169 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6170 + cpg->pin = &wh_pin;
6173 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6174 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6175 + err = au_cpup_wh(cpg, file);
6177 + struct au_cpup_wh_args args = {
6182 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6183 + if (unlikely(wkq_err))
6188 + inode_unlock(h_tmpdir);
6189 + /* todo: au_h_open_post()? */
6190 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6191 + au_set_h_dptr(parent, bdst, h_parent);
6192 + AuDebugOn(!pin_orig);
6193 + cpg->pin = pin_orig;
6201 +/* ---------------------------------------------------------------------- */
6204 + * generic routine for both of copy-up and copy-down.
6206 +/* cf. revalidate function in file.c */
6207 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6208 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6209 + struct au_pin *pin,
6210 + struct dentry *h_parent, void *arg),
6214 + struct au_pin pin;
6215 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6218 + parent = dget_parent(dentry);
6219 + if (IS_ROOT(parent))
6222 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6223 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6225 + /* do not use au_dpage */
6226 + real_parent = parent;
6229 + parent = dget_parent(dentry);
6230 + h_parent = au_h_dptr(parent, bdst);
6232 + goto out; /* success */
6234 + /* find top dir which is necessary to cpup */
6238 + parent = dget_parent(d);
6239 + di_read_lock_parent3(parent, !AuLock_IR);
6240 + h_parent = au_h_dptr(parent, bdst);
6241 + di_read_unlock(parent, !AuLock_IR);
6242 + } while (!h_parent);
6244 + if (d != real_parent)
6245 + di_write_lock_child3(d);
6247 + /* somebody else might create while we were sleeping */
6248 + h_dentry = au_h_dptr(d, bdst);
6249 + if (!h_dentry || d_is_negative(h_dentry)) {
6251 + au_update_dbtop(d);
6253 + au_pin_set_dentry(&pin, d);
6254 + err = au_do_pin(&pin);
6256 + err = cp(d, bdst, &pin, h_parent, arg);
6261 + if (d != real_parent)
6262 + di_write_unlock(d);
6263 + if (unlikely(err))
6272 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6273 + struct au_pin *pin,
6274 + struct dentry *h_parent __maybe_unused,
6275 + void *arg __maybe_unused)
6277 + struct au_cp_generic cpg = {
6283 + .flags = AuCpup_DTIME
6285 + return au_sio_cpup_simple(&cpg);
6288 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6290 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6293 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6296 + struct dentry *parent;
6297 + struct inode *dir;
6299 + parent = dget_parent(dentry);
6300 + dir = d_inode(parent);
6302 + if (au_h_iptr(dir, bdst))
6305 + di_read_unlock(parent, AuLock_IR);
6306 + di_write_lock_parent(parent);
6307 + /* someone else might change our inode while we were sleeping */
6308 + if (!au_h_iptr(dir, bdst))
6309 + err = au_cpup_dirs(dentry, bdst);
6310 + di_downgrade_lock(parent, AuLock_IR);
6316 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6317 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6318 +++ linux/fs/aufs/cpup.h 2020-01-27 10:57:18.168871450 +0100
6320 +/* SPDX-License-Identifier: GPL-2.0 */
6322 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6324 + * This program, aufs is free software; you can redistribute it and/or modify
6325 + * it under the terms of the GNU General Public License as published by
6326 + * the Free Software Foundation; either version 2 of the License, or
6327 + * (at your option) any later version.
6329 + * This program is distributed in the hope that it will be useful,
6330 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6331 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6332 + * GNU General Public License for more details.
6334 + * You should have received a copy of the GNU General Public License
6335 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6339 + * copy-up/down functions
6342 +#ifndef __AUFS_CPUP_H__
6343 +#define __AUFS_CPUP_H__
6347 +#include <linux/path.h>
6353 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6354 +void au_cpup_attr_timesizes(struct inode *inode);
6355 +void au_cpup_attr_nlink(struct inode *inode, int force);
6356 +void au_cpup_attr_changeable(struct inode *inode);
6357 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6358 +void au_cpup_attr_all(struct inode *inode, int force);
6360 +/* ---------------------------------------------------------------------- */
6362 +struct au_cp_generic {
6363 + struct dentry *dentry;
6364 + aufs_bindex_t bdst, bsrc;
6366 + struct au_pin *pin;
6367 + unsigned int flags;
6371 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6372 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6374 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6375 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6377 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6379 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6380 + the branch is marked as RO */
6382 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6383 +#undef AuCpup_HOPEN
6384 +#define AuCpup_HOPEN 0
6387 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6388 +#define au_fset_cpup(flags, name) \
6389 + do { (flags) |= AuCpup_##name; } while (0)
6390 +#define au_fclr_cpup(flags, name) \
6391 + do { (flags) &= ~AuCpup_##name; } while (0)
6393 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6394 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6395 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6396 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6398 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6399 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6400 + struct au_pin *pin,
6401 + struct dentry *h_parent, void *arg),
6403 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6404 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6406 +/* ---------------------------------------------------------------------- */
6408 +/* keep timestamps when copyup */
6410 + struct dentry *dt_dentry;
6411 + struct path dt_h_path;
6412 + struct timespec64 dt_atime, dt_mtime;
6414 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6415 + struct path *h_path);
6416 +void au_dtime_revert(struct au_dtime *dt);
6418 +#endif /* __KERNEL__ */
6419 +#endif /* __AUFS_CPUP_H__ */
6420 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6421 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6422 +++ linux/fs/aufs/dbgaufs.c 2020-01-27 10:57:18.168871450 +0100
6424 +// SPDX-License-Identifier: GPL-2.0
6426 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6428 + * This program, aufs is free software; you can redistribute it and/or modify
6429 + * it under the terms of the GNU General Public License as published by
6430 + * the Free Software Foundation; either version 2 of the License, or
6431 + * (at your option) any later version.
6433 + * This program is distributed in the hope that it will be useful,
6434 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6435 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6436 + * GNU General Public License for more details.
6438 + * You should have received a copy of the GNU General Public License
6439 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6443 + * debugfs interface
6446 +#include <linux/debugfs.h>
6449 +#ifndef CONFIG_SYSFS
6450 +#error DEBUG_FS depends upon SYSFS
6453 +static struct dentry *dbgaufs;
6454 +static const mode_t dbgaufs_mode = 0444;
6456 +/* 20 is max digits length of ulong 64 */
6457 +struct dbgaufs_arg {
6463 + * common function for all XINO files
6465 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6466 + struct file *file)
6470 + p = file->private_data;
6472 + /* this is struct dbgaufs_arg */
6473 + AuDebugOn(!au_kfree_sz_test(p));
6474 + au_kfree_do_rcu(p);
6479 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6484 + struct dbgaufs_arg *p;
6487 + p = kmalloc(sizeof(*p), GFP_NOFS);
6493 + file->private_data = p;
6497 + err = vfsub_getattr(&xf->f_path, &st);
6501 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6502 + cnt, st.blocks, st.blksize,
6503 + (long long)st.size);
6505 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6506 + st.blocks, st.blksize,
6507 + (long long)st.size);
6508 + AuDebugOn(p->n >= sizeof(p->a));
6510 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6518 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6519 + size_t count, loff_t *ppos)
6521 + struct dbgaufs_arg *p;
6523 + p = file->private_data;
6524 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6527 +/* ---------------------------------------------------------------------- */
6529 +struct dbgaufs_plink_arg {
6534 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6535 + struct file *file)
6537 + free_page((unsigned long)file->private_data);
6541 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6543 + int err, i, limit;
6544 + unsigned long n, sum;
6545 + struct dbgaufs_plink_arg *p;
6546 + struct au_sbinfo *sbinfo;
6547 + struct super_block *sb;
6548 + struct hlist_bl_head *hbl;
6551 + p = (void *)get_zeroed_page(GFP_NOFS);
6556 + sbinfo = inode->i_private;
6557 + sb = sbinfo->si_sb;
6558 + si_noflush_read_lock(sb);
6559 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6560 + limit = PAGE_SIZE - sizeof(p->n);
6562 + /* the number of buckets */
6563 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6568 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6570 + n = au_hbl_count(hbl);
6573 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6576 + if (unlikely(limit <= 0))
6579 + p->a[p->n - 1] = '\n';
6581 + /* the sum of plinks */
6582 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6585 + if (unlikely(limit <= 0))
6588 +#define str "1\n0\n0\n"
6589 + p->n = sizeof(str) - 1;
6590 + strcpy(p->a, str);
6593 + si_read_unlock(sb);
6596 + file->private_data = p;
6597 + goto out; /* success */
6600 + free_page((unsigned long)p);
6605 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6606 + size_t count, loff_t *ppos)
6608 + struct dbgaufs_plink_arg *p;
6610 + p = file->private_data;
6611 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6614 +static const struct file_operations dbgaufs_plink_fop = {
6615 + .owner = THIS_MODULE,
6616 + .open = dbgaufs_plink_open,
6617 + .release = dbgaufs_plink_release,
6618 + .read = dbgaufs_plink_read
6621 +/* ---------------------------------------------------------------------- */
6623 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6626 + struct au_sbinfo *sbinfo;
6627 + struct super_block *sb;
6629 + sbinfo = inode->i_private;
6630 + sb = sbinfo->si_sb;
6631 + si_noflush_read_lock(sb);
6632 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6633 + si_read_unlock(sb);
6637 +static const struct file_operations dbgaufs_xib_fop = {
6638 + .owner = THIS_MODULE,
6639 + .open = dbgaufs_xib_open,
6640 + .release = dbgaufs_xi_release,
6641 + .read = dbgaufs_xi_read
6644 +/* ---------------------------------------------------------------------- */
6646 +#define DbgaufsXi_PREFIX "xi"
6648 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6652 + aufs_bindex_t bindex;
6653 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6654 + struct au_sbinfo *sbinfo;
6655 + struct super_block *sb;
6656 + struct au_xino *xi;
6658 + struct qstr *name;
6659 + struct au_branch *br;
6662 + name = &file->f_path.dentry->d_name;
6663 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6664 + || memcmp(name->name, DbgaufsXi_PREFIX,
6665 + sizeof(DbgaufsXi_PREFIX) - 1)))
6668 + AuDebugOn(name->len >= sizeof(a));
6669 + memcpy(a, name->name, name->len);
6670 + a[name->len] = '\0';
6671 + p = strchr(a, '-');
6674 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6675 + if (unlikely(err))
6680 + err = kstrtol(p + 1, 10, &l);
6681 + if (unlikely(err))
6687 + sbinfo = inode->i_private;
6688 + sb = sbinfo->si_sb;
6689 + si_noflush_read_lock(sb);
6690 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6692 + br = au_sbr(sb, bindex);
6694 + if (unlikely(idx >= xi->xi_nfile))
6696 + xf = au_xino_file(xi, idx);
6698 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6699 + au_xino_count(br));
6702 + si_read_unlock(sb);
6708 +static const struct file_operations dbgaufs_xino_fop = {
6709 + .owner = THIS_MODULE,
6710 + .open = dbgaufs_xino_open,
6711 + .release = dbgaufs_xi_release,
6712 + .read = dbgaufs_xi_read
6715 +void dbgaufs_xino_del(struct au_branch *br)
6717 + struct dentry *dbgaufs;
6719 + dbgaufs = br->br_dbgaufs;
6723 + br->br_dbgaufs = NULL;
6724 + /* debugfs acquires the parent i_mutex */
6726 + debugfs_remove(dbgaufs);
6730 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6732 + aufs_bindex_t bbot;
6733 + struct au_branch *br;
6735 + if (!au_sbi(sb)->si_dbgaufs)
6738 + bbot = au_sbbot(sb);
6739 + for (; bindex <= bbot; bindex++) {
6740 + br = au_sbr(sb, bindex);
6741 + dbgaufs_xino_del(br);
6745 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6746 + unsigned int idx, struct dentry *parent,
6747 + struct au_sbinfo *sbinfo)
6749 + struct au_branch *br;
6751 + /* "xi" bindex(5) "-" idx(2) NULL */
6752 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6755 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6757 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6759 + br = au_sbr(sb, bindex);
6760 + if (br->br_dbgaufs) {
6761 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6763 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6764 + /* debugfs acquires the parent i_mutex */
6766 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6770 + pr_warn("failed renaming %pd/%s, ignored.\n",
6775 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6776 + sbinfo, &dbgaufs_xino_fop);
6778 + if (unlikely(!br->br_dbgaufs))
6779 + pr_warn("failed creating %pd/%s, ignored.\n",
6784 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6785 + struct dentry *parent, struct au_sbinfo *sbinfo)
6787 + struct au_branch *br;
6788 + struct au_xino *xi;
6791 + br = au_sbr(sb, bindex);
6793 + for (u = 0; u < xi->xi_nfile; u++)
6794 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6797 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6799 + struct au_sbinfo *sbinfo;
6800 + struct dentry *parent;
6801 + aufs_bindex_t bbot;
6803 + if (!au_opt_test(au_mntflags(sb), XINO))
6806 + sbinfo = au_sbi(sb);
6807 + parent = sbinfo->si_dbgaufs;
6811 + bbot = au_sbbot(sb);
6813 + for (; bindex <= bbot; bindex++)
6814 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6816 + for (; bbot >= bindex; bbot--)
6817 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6820 +/* ---------------------------------------------------------------------- */
6822 +#ifdef CONFIG_AUFS_EXPORT
6823 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6826 + struct au_sbinfo *sbinfo;
6827 + struct super_block *sb;
6829 + sbinfo = inode->i_private;
6830 + sb = sbinfo->si_sb;
6831 + si_noflush_read_lock(sb);
6832 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6833 + si_read_unlock(sb);
6837 +static const struct file_operations dbgaufs_xigen_fop = {
6838 + .owner = THIS_MODULE,
6839 + .open = dbgaufs_xigen_open,
6840 + .release = dbgaufs_xi_release,
6841 + .read = dbgaufs_xi_read
6844 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6849 + * This function is a dynamic '__init' function actually,
6850 + * so the tiny check for si_rwsem is unnecessary.
6852 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6855 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6856 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6857 + &dbgaufs_xigen_fop);
6858 + if (sbinfo->si_dbgaufs_xigen)
6864 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6868 +#endif /* CONFIG_AUFS_EXPORT */
6870 +/* ---------------------------------------------------------------------- */
6872 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6875 + * This function is a dynamic '__fin' function actually,
6876 + * so the tiny check for si_rwsem is unnecessary.
6878 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6880 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6881 + sbinfo->si_dbgaufs = NULL;
6884 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6887 + char name[SysaufsSiNameLen];
6890 + * This function is a dynamic '__init' function actually,
6891 + * so the tiny check for si_rwsem is unnecessary.
6893 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6897 + AuErr1("/debug/aufs is uninitialized\n");
6902 + sysaufs_name(sbinfo, name);
6903 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6904 + if (unlikely(!sbinfo->si_dbgaufs))
6907 + /* regardless plink/noplink option */
6908 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6909 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6910 + &dbgaufs_plink_fop);
6911 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6914 + /* regardless xino/noxino option */
6915 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6916 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6917 + &dbgaufs_xib_fop);
6918 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6921 + err = dbgaufs_xigen_init(sbinfo);
6923 + goto out; /* success */
6926 + dbgaufs_si_fin(sbinfo);
6928 + if (unlikely(err))
6929 + pr_err("debugfs/aufs failed\n");
6933 +/* ---------------------------------------------------------------------- */
6935 +void dbgaufs_fin(void)
6937 + debugfs_remove(dbgaufs);
6940 +int __init dbgaufs_init(void)
6945 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6950 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6951 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6952 +++ linux/fs/aufs/dbgaufs.h 2020-01-27 10:57:18.168871450 +0100
6954 +/* SPDX-License-Identifier: GPL-2.0 */
6956 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6958 + * This program, aufs is free software; you can redistribute it and/or modify
6959 + * it under the terms of the GNU General Public License as published by
6960 + * the Free Software Foundation; either version 2 of the License, or
6961 + * (at your option) any later version.
6963 + * This program is distributed in the hope that it will be useful,
6964 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6965 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6966 + * GNU General Public License for more details.
6968 + * You should have received a copy of the GNU General Public License
6969 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6973 + * debugfs interface
6976 +#ifndef __DBGAUFS_H__
6977 +#define __DBGAUFS_H__
6981 +struct super_block;
6985 +#ifdef CONFIG_DEBUG_FS
6987 +void dbgaufs_xino_del(struct au_branch *br);
6988 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6989 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6990 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6991 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6992 +void dbgaufs_fin(void);
6993 +int __init dbgaufs_init(void);
6995 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6996 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6997 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6999 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7000 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7001 +AuStubVoid(dbgaufs_fin, void)
7002 +AuStubInt0(__init dbgaufs_init, void)
7003 +#endif /* CONFIG_DEBUG_FS */
7005 +#endif /* __KERNEL__ */
7006 +#endif /* __DBGAUFS_H__ */
7007 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7008 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7009 +++ linux/fs/aufs/dcsub.c 2020-01-27 10:57:18.168871450 +0100
7011 +// SPDX-License-Identifier: GPL-2.0
7013 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7015 + * This program, aufs is free software; you can redistribute it and/or modify
7016 + * it under the terms of the GNU General Public License as published by
7017 + * the Free Software Foundation; either version 2 of the License, or
7018 + * (at your option) any later version.
7020 + * This program is distributed in the hope that it will be useful,
7021 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7022 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7023 + * GNU General Public License for more details.
7025 + * You should have received a copy of the GNU General Public License
7026 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7030 + * sub-routines for dentry cache
7035 +static void au_dpage_free(struct au_dpage *dpage)
7038 + struct dentry **p;
7040 + p = dpage->dentries;
7041 + for (i = 0; i < dpage->ndentry; i++)
7043 + free_page((unsigned long)dpage->dentries);
7046 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7052 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7053 + if (unlikely(!dpages->dpages))
7056 + p = (void *)__get_free_page(gfp);
7060 + dpages->dpages[0].ndentry = 0;
7061 + dpages->dpages[0].dentries = p;
7062 + dpages->ndpage = 1;
7063 + return 0; /* success */
7066 + au_kfree_try_rcu(dpages->dpages);
7071 +void au_dpages_free(struct au_dcsub_pages *dpages)
7074 + struct au_dpage *p;
7076 + p = dpages->dpages;
7077 + for (i = 0; i < dpages->ndpage; i++)
7078 + au_dpage_free(p++);
7079 + au_kfree_try_rcu(dpages->dpages);
7082 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7083 + struct dentry *dentry, gfp_t gfp)
7086 + struct au_dpage *dpage;
7089 + dpage = dpages->dpages + dpages->ndpage - 1;
7090 + sz = PAGE_SIZE / sizeof(dentry);
7091 + if (unlikely(dpage->ndentry >= sz)) {
7092 + AuLabel(new dpage);
7094 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7095 + p = au_kzrealloc(dpages->dpages, sz,
7096 + sz + sizeof(*dpages->dpages), gfp,
7101 + dpages->dpages = p;
7102 + dpage = dpages->dpages + dpages->ndpage;
7103 + p = (void *)__get_free_page(gfp);
7107 + dpage->ndentry = 0;
7108 + dpage->dentries = p;
7112 + AuDebugOn(au_dcount(dentry) <= 0);
7113 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7114 + return 0; /* success */
7120 +/* todo: BAD approach */
7121 +/* copied from linux/fs/dcache.c */
7129 +extern void d_walk(struct dentry *parent, void *data,
7130 + enum d_walk_ret (*enter)(void *, struct dentry *));
7132 +struct ac_dpages_arg {
7134 + struct au_dcsub_pages *dpages;
7135 + struct super_block *sb;
7136 + au_dpages_test test;
7140 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7142 + enum d_walk_ret ret;
7143 + struct ac_dpages_arg *arg = _arg;
7145 + ret = D_WALK_CONTINUE;
7146 + if (dentry->d_sb == arg->sb
7147 + && !IS_ROOT(dentry)
7148 + && au_dcount(dentry) > 0
7150 + && (!arg->test || arg->test(dentry, arg->arg))) {
7151 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7152 + if (unlikely(arg->err))
7153 + ret = D_WALK_QUIT;
7159 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7160 + au_dpages_test test, void *arg)
7162 + struct ac_dpages_arg args = {
7170 + d_walk(root, &args, au_call_dpages_append);
7175 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7176 + int do_include, au_dpages_test test, void *arg)
7181 + write_seqlock(&rename_lock);
7182 + spin_lock(&dentry->d_lock);
7184 + && au_dcount(dentry) > 0
7185 + && (!test || test(dentry, arg)))
7186 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7187 + spin_unlock(&dentry->d_lock);
7188 + if (unlikely(err))
7192 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7195 + while (!IS_ROOT(dentry)) {
7196 + dentry = dentry->d_parent; /* rename_lock is locked */
7197 + spin_lock(&dentry->d_lock);
7198 + if (au_dcount(dentry) > 0
7199 + && (!test || test(dentry, arg)))
7200 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7201 + spin_unlock(&dentry->d_lock);
7202 + if (unlikely(err))
7207 + write_sequnlock(&rename_lock);
7211 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7213 + return au_di(dentry) && dentry->d_sb == arg;
7216 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7217 + struct dentry *dentry, int do_include)
7219 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7220 + au_dcsub_dpages_aufs, dentry->d_sb);
7223 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7225 + struct path path[2] = {
7234 + return path_is_under(path + 0, path + 1);
7236 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7237 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7238 +++ linux/fs/aufs/dcsub.h 2020-01-27 10:57:18.168871450 +0100
7240 +/* SPDX-License-Identifier: GPL-2.0 */
7242 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7244 + * This program, aufs is free software; you can redistribute it and/or modify
7245 + * it under the terms of the GNU General Public License as published by
7246 + * the Free Software Foundation; either version 2 of the License, or
7247 + * (at your option) any later version.
7249 + * This program is distributed in the hope that it will be useful,
7250 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7251 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7252 + * GNU General Public License for more details.
7254 + * You should have received a copy of the GNU General Public License
7255 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7259 + * sub-routines for dentry cache
7262 +#ifndef __AUFS_DCSUB_H__
7263 +#define __AUFS_DCSUB_H__
7267 +#include <linux/dcache.h>
7268 +#include <linux/fs.h>
7272 + struct dentry **dentries;
7275 +struct au_dcsub_pages {
7277 + struct au_dpage *dpages;
7280 +/* ---------------------------------------------------------------------- */
7283 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7284 +void au_dpages_free(struct au_dcsub_pages *dpages);
7285 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7286 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7287 + au_dpages_test test, void *arg);
7288 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7289 + int do_include, au_dpages_test test, void *arg);
7290 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7291 + struct dentry *dentry, int do_include);
7292 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7294 +/* ---------------------------------------------------------------------- */
7297 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7298 + * include/linux/dcache.h. Try them (in the future).
7301 +static inline int au_d_hashed_positive(struct dentry *d)
7304 + struct inode *inode = d_inode(d);
7307 + if (unlikely(d_unhashed(d)
7308 + || d_is_negative(d)
7309 + || !inode->i_nlink))
7314 +static inline int au_d_linkable(struct dentry *d)
7317 + struct inode *inode = d_inode(d);
7319 + err = au_d_hashed_positive(d);
7321 + && d_is_positive(d)
7322 + && (inode->i_state & I_LINKABLE))
7327 +static inline int au_d_alive(struct dentry *d)
7330 + struct inode *inode;
7334 + err = au_d_hashed_positive(d);
7336 + inode = d_inode(d);
7337 + if (unlikely(d_unlinked(d)
7338 + || d_is_negative(d)
7339 + || !inode->i_nlink))
7345 +static inline int au_alive_dir(struct dentry *d)
7349 + err = au_d_alive(d);
7350 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7355 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7357 + return a->len == b->len
7358 + && !memcmp(a->name, b->name, a->len);
7363 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7365 + * the type of d_lockref.count became int, but the inlined function d_count()
7366 + * still returns unsigned int.
7367 + * I don't know why. Maybe it is for every d_count() users?
7368 + * Anyway au_dcount() lives on.
7370 +static inline int au_dcount(struct dentry *d)
7372 + return (int)d_count(d);
7375 +#endif /* __KERNEL__ */
7376 +#endif /* __AUFS_DCSUB_H__ */
7377 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7378 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7379 +++ linux/fs/aufs/debug.c 2020-01-27 10:57:18.168871450 +0100
7381 +// SPDX-License-Identifier: GPL-2.0
7383 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7385 + * This program, aufs is free software; you can redistribute it and/or modify
7386 + * it under the terms of the GNU General Public License as published by
7387 + * the Free Software Foundation; either version 2 of the License, or
7388 + * (at your option) any later version.
7390 + * This program is distributed in the hope that it will be useful,
7391 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7392 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7393 + * GNU General Public License for more details.
7395 + * You should have received a copy of the GNU General Public License
7396 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7400 + * debug print functions
7403 +#include <linux/iversion.h>
7406 +/* Returns 0, or -errno. arg is in kp->arg. */
7407 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7411 + err = kstrtoint(val, 0, &n);
7421 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7422 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7427 + return sprintf(buffer, "%d", atomic_read(a));
7430 +static struct kernel_param_ops param_ops_atomic_t = {
7431 + .set = param_atomic_t_set,
7432 + .get = param_atomic_t_get
7433 + /* void (*free)(void *arg) */
7436 +atomic_t aufs_debug = ATOMIC_INIT(0);
7437 +MODULE_PARM_DESC(debug, "debug print");
7438 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7440 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7441 +char *au_plevel = KERN_DEBUG;
7442 +#define dpri(fmt, ...) do { \
7444 + && strcmp(au_plevel, KERN_DEBUG)) \
7445 + || au_debug_test()) \
7446 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7449 +/* ---------------------------------------------------------------------- */
7451 +void au_dpri_whlist(struct au_nhash *whlist)
7453 + unsigned long ul, n;
7454 + struct hlist_head *head;
7455 + struct au_vdir_wh *pos;
7457 + n = whlist->nh_num;
7458 + head = whlist->nh_head;
7459 + for (ul = 0; ul < n; ul++) {
7460 + hlist_for_each_entry(pos, head, wh_hash)
7461 + dpri("b%d, %.*s, %d\n",
7463 + pos->wh_str.len, pos->wh_str.name,
7469 +void au_dpri_vdir(struct au_vdir *vdir)
7472 + union au_vdir_deblk_p p;
7475 + if (!vdir || IS_ERR(vdir)) {
7476 + dpri("err %ld\n", PTR_ERR(vdir));
7480 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7481 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7482 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7483 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7484 + p.deblk = vdir->vd_deblk[ul];
7486 + dpri("[%lu]: %p\n", ul, o);
7490 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7491 + struct dentry *wh)
7496 + if (!inode || IS_ERR(inode)) {
7497 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7501 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7502 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7503 + && sizeof(inode->i_blocks) != sizeof(u64));
7505 + n = (void *)wh->d_name.name;
7506 + l = wh->d_name.len;
7509 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7510 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7512 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7513 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7514 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7515 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7516 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7517 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7518 + inode->i_generation,
7519 + l ? ", wh " : "", l, n);
7523 +void au_dpri_inode(struct inode *inode)
7525 + struct au_iinfo *iinfo;
7526 + struct au_hinode *hi;
7527 + aufs_bindex_t bindex;
7530 + err = do_pri_inode(-1, inode, -1, NULL);
7531 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7534 + iinfo = au_ii(inode);
7535 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7536 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7537 + if (iinfo->ii_btop < 0)
7540 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7541 + hi = au_hinode(iinfo, bindex);
7543 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7547 +void au_dpri_dalias(struct inode *inode)
7551 + spin_lock(&inode->i_lock);
7552 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7553 + au_dpri_dentry(d);
7554 + spin_unlock(&inode->i_lock);
7557 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7559 + struct dentry *wh = NULL;
7561 + struct inode *inode;
7562 + struct au_iinfo *iinfo;
7563 + struct au_hinode *hi;
7565 + if (!dentry || IS_ERR(dentry)) {
7566 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7569 + /* do not call dget_parent() here */
7570 + /* note: access d_xxx without d_lock */
7571 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7572 + bindex, dentry, dentry,
7573 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7574 + au_dcount(dentry), dentry->d_flags,
7575 + d_unhashed(dentry) ? "un" : "");
7578 + if (d_is_positive(dentry))
7579 + inode = d_inode(dentry);
7581 + && au_test_aufs(dentry->d_sb)
7583 + && !au_is_bad_inode(inode)) {
7584 + iinfo = au_ii(inode);
7585 + hi = au_hinode(iinfo, bindex);
7587 + wh = hi->hi_whdentry;
7589 + do_pri_inode(bindex, inode, hn, wh);
7593 +void au_dpri_dentry(struct dentry *dentry)
7595 + struct au_dinfo *dinfo;
7596 + aufs_bindex_t bindex;
7599 + err = do_pri_dentry(-1, dentry);
7600 + if (err || !au_test_aufs(dentry->d_sb))
7603 + dinfo = au_di(dentry);
7606 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7607 + dinfo->di_btop, dinfo->di_bbot,
7608 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7609 + dinfo->di_tmpfile);
7610 + if (dinfo->di_btop < 0)
7612 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7613 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7616 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7620 + if (!file || IS_ERR(file)) {
7621 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7626 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7627 + && au_test_aufs(file->f_path.dentry->d_sb)
7629 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7630 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7631 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7632 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7633 + file->f_version, file->f_pos, a);
7634 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7635 + do_pri_dentry(bindex, file->f_path.dentry);
7639 +void au_dpri_file(struct file *file)
7641 + struct au_finfo *finfo;
7642 + struct au_fidir *fidir;
7643 + struct au_hfile *hfile;
7644 + aufs_bindex_t bindex;
7647 + err = do_pri_file(-1, file);
7649 + || IS_ERR_OR_NULL(file->f_path.dentry)
7650 + || !au_test_aufs(file->f_path.dentry->d_sb))
7653 + finfo = au_fi(file);
7656 + if (finfo->fi_btop < 0)
7658 + fidir = finfo->fi_hdir;
7660 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7662 + for (bindex = finfo->fi_btop;
7663 + bindex >= 0 && bindex <= fidir->fd_bbot;
7665 + hfile = fidir->fd_hfile + bindex;
7666 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7670 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7672 + struct vfsmount *mnt;
7673 + struct super_block *sb;
7675 + if (!br || IS_ERR(br))
7677 + mnt = au_br_mnt(br);
7678 + if (!mnt || IS_ERR(mnt))
7681 + if (!sb || IS_ERR(sb))
7684 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7685 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7687 + bindex, br->br_perm, br->br_id, br->br_wbr,
7688 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7689 + sb->s_flags, sb->s_count,
7690 + atomic_read(&sb->s_active),
7691 + !!au_xino_file(br->br_xino, /*idx*/-1));
7695 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7699 +void au_dpri_sb(struct super_block *sb)
7701 + struct au_sbinfo *sbinfo;
7702 + aufs_bindex_t bindex;
7704 + /* to reduce stack size */
7706 + struct vfsmount mnt;
7707 + struct au_branch fake;
7710 + /* this function can be called from magic sysrq */
7711 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7712 + if (unlikely(!a)) {
7713 + dpri("no memory\n");
7717 + a->mnt.mnt_sb = sb;
7718 + a->fake.br_path.mnt = &a->mnt;
7719 + err = do_pri_br(-1, &a->fake);
7721 + dpri("dev 0x%x\n", sb->s_dev);
7722 + if (err || !au_test_aufs(sb))
7725 + sbinfo = au_sbi(sb);
7728 + dpri("nw %d, gen %u, kobj %d\n",
7729 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7730 + kref_read(&sbinfo->si_kobj.kref));
7731 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7732 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7735 +/* ---------------------------------------------------------------------- */
7737 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7739 + struct inode *h_inode, *inode = d_inode(dentry);
7740 + struct dentry *h_dentry;
7741 + aufs_bindex_t bindex, bbot, bi;
7743 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7746 + bbot = au_dbbot(dentry);
7747 + bi = au_ibbot(inode);
7750 + bindex = au_dbtop(dentry);
7751 + bi = au_ibtop(inode);
7755 + for (; bindex <= bbot; bindex++) {
7756 + h_dentry = au_h_dptr(dentry, bindex);
7759 + h_inode = au_h_iptr(inode, bindex);
7760 + if (unlikely(h_inode != d_inode(h_dentry))) {
7762 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7763 + AuDbgDentry(dentry);
7764 + AuDbgInode(inode);
7771 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7774 + struct au_dcsub_pages dpages;
7775 + struct au_dpage *dpage;
7776 + struct dentry **dentries;
7778 + err = au_dpages_init(&dpages, GFP_NOFS);
7780 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7782 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7783 + dpage = dpages.dpages + i;
7784 + dentries = dpage->dentries;
7785 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7786 + AuDebugOn(au_digen_test(dentries[j], sigen));
7788 + au_dpages_free(&dpages);
7791 +void au_dbg_verify_kthread(void)
7793 + if (au_wkq_test()) {
7796 + * It may be recursive, but udba=notify between two aufs mounts,
7797 + * where a single ro branch is shared, is not a problem.
7803 +/* ---------------------------------------------------------------------- */
7805 +int __init au_debug_init(void)
7807 + aufs_bindex_t bindex;
7808 + struct au_vdir_destr destr;
7811 + AuDebugOn(bindex >= 0);
7814 + AuDebugOn(destr.len < NAME_MAX);
7816 +#ifdef CONFIG_4KSTACKS
7817 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7822 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7823 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7824 +++ linux/fs/aufs/debug.h 2020-01-27 10:57:18.168871450 +0100
7826 +/* SPDX-License-Identifier: GPL-2.0 */
7828 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7830 + * This program, aufs is free software; you can redistribute it and/or modify
7831 + * it under the terms of the GNU General Public License as published by
7832 + * the Free Software Foundation; either version 2 of the License, or
7833 + * (at your option) any later version.
7835 + * This program is distributed in the hope that it will be useful,
7836 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7837 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7838 + * GNU General Public License for more details.
7840 + * You should have received a copy of the GNU General Public License
7841 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7845 + * debug print functions
7848 +#ifndef __AUFS_DEBUG_H__
7849 +#define __AUFS_DEBUG_H__
7853 +#include <linux/atomic.h>
7854 +#include <linux/module.h>
7855 +#include <linux/kallsyms.h>
7856 +#include <linux/sysrq.h>
7858 +#ifdef CONFIG_AUFS_DEBUG
7859 +#define AuDebugOn(a) BUG_ON(a)
7861 +/* module parameter */
7862 +extern atomic_t aufs_debug;
7863 +static inline void au_debug_on(void)
7865 + atomic_inc(&aufs_debug);
7867 +static inline void au_debug_off(void)
7869 + atomic_dec_if_positive(&aufs_debug);
7872 +static inline int au_debug_test(void)
7874 + return atomic_read(&aufs_debug) > 0;
7877 +#define AuDebugOn(a) do {} while (0)
7878 +AuStubVoid(au_debug_on, void)
7879 +AuStubVoid(au_debug_off, void)
7880 +AuStubInt0(au_debug_test, void)
7881 +#endif /* CONFIG_AUFS_DEBUG */
7883 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7885 +/* ---------------------------------------------------------------------- */
7889 +#define AuDbg(fmt, ...) do { \
7890 + if (au_debug_test()) \
7891 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7893 +#define AuLabel(l) AuDbg(#l "\n")
7894 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7895 +#define AuWarn1(fmt, ...) do { \
7896 + static unsigned char _c; \
7898 + pr_warn(fmt, ##__VA_ARGS__); \
7901 +#define AuErr1(fmt, ...) do { \
7902 + static unsigned char _c; \
7904 + pr_err(fmt, ##__VA_ARGS__); \
7907 +#define AuIOErr1(fmt, ...) do { \
7908 + static unsigned char _c; \
7910 + AuIOErr(fmt, ##__VA_ARGS__); \
7913 +#define AuUnsupportMsg "This operation is not supported." \
7914 + " Please report this application to aufs-users ML."
7915 +#define AuUnsupport(fmt, ...) do { \
7916 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7920 +#define AuTraceErr(e) do { \
7921 + if (unlikely((e) < 0)) \
7922 + AuDbg("err %d\n", (int)(e)); \
7925 +#define AuTraceErrPtr(p) do { \
7927 + AuDbg("err %ld\n", PTR_ERR(p)); \
7930 +/* dirty macros for debug print, use with "%.*s" and caution */
7931 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7933 +/* ---------------------------------------------------------------------- */
7936 +#ifdef CONFIG_AUFS_DEBUG
7937 +extern struct mutex au_dbg_mtx;
7938 +extern char *au_plevel;
7940 +void au_dpri_whlist(struct au_nhash *whlist);
7942 +void au_dpri_vdir(struct au_vdir *vdir);
7944 +void au_dpri_inode(struct inode *inode);
7945 +void au_dpri_dalias(struct inode *inode);
7946 +void au_dpri_dentry(struct dentry *dentry);
7948 +void au_dpri_file(struct file *filp);
7949 +struct super_block;
7950 +void au_dpri_sb(struct super_block *sb);
7952 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7953 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7954 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7955 +void au_dbg_verify_kthread(void);
7957 +int __init au_debug_init(void);
7959 +#define AuDbgWhlist(w) do { \
7960 + mutex_lock(&au_dbg_mtx); \
7962 + au_dpri_whlist(w); \
7963 + mutex_unlock(&au_dbg_mtx); \
7966 +#define AuDbgVdir(v) do { \
7967 + mutex_lock(&au_dbg_mtx); \
7969 + au_dpri_vdir(v); \
7970 + mutex_unlock(&au_dbg_mtx); \
7973 +#define AuDbgInode(i) do { \
7974 + mutex_lock(&au_dbg_mtx); \
7976 + au_dpri_inode(i); \
7977 + mutex_unlock(&au_dbg_mtx); \
7980 +#define AuDbgDAlias(i) do { \
7981 + mutex_lock(&au_dbg_mtx); \
7983 + au_dpri_dalias(i); \
7984 + mutex_unlock(&au_dbg_mtx); \
7987 +#define AuDbgDentry(d) do { \
7988 + mutex_lock(&au_dbg_mtx); \
7990 + au_dpri_dentry(d); \
7991 + mutex_unlock(&au_dbg_mtx); \
7994 +#define AuDbgFile(f) do { \
7995 + mutex_lock(&au_dbg_mtx); \
7997 + au_dpri_file(f); \
7998 + mutex_unlock(&au_dbg_mtx); \
8001 +#define AuDbgSb(sb) do { \
8002 + mutex_lock(&au_dbg_mtx); \
8003 + AuDbg(#sb "\n"); \
8005 + mutex_unlock(&au_dbg_mtx); \
8008 +#define AuDbgSym(addr) do { \
8009 + char sym[KSYM_SYMBOL_LEN]; \
8010 + sprint_symbol(sym, (unsigned long)addr); \
8011 + AuDbg("%s\n", sym); \
8014 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8015 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8016 +AuStubVoid(au_dbg_verify_kthread, void)
8017 +AuStubInt0(__init au_debug_init, void)
8019 +#define AuDbgWhlist(w) do {} while (0)
8020 +#define AuDbgVdir(v) do {} while (0)
8021 +#define AuDbgInode(i) do {} while (0)
8022 +#define AuDbgDAlias(i) do {} while (0)
8023 +#define AuDbgDentry(d) do {} while (0)
8024 +#define AuDbgFile(f) do {} while (0)
8025 +#define AuDbgSb(sb) do {} while (0)
8026 +#define AuDbgSym(addr) do {} while (0)
8027 +#endif /* CONFIG_AUFS_DEBUG */
8029 +/* ---------------------------------------------------------------------- */
8031 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8032 +int __init au_sysrq_init(void);
8033 +void au_sysrq_fin(void);
8035 +#ifdef CONFIG_HW_CONSOLE
8036 +#define au_dbg_blocked() do { \
8038 + handle_sysrq('w'); \
8041 +AuStubVoid(au_dbg_blocked, void)
8045 +AuStubInt0(__init au_sysrq_init, void)
8046 +AuStubVoid(au_sysrq_fin, void)
8047 +AuStubVoid(au_dbg_blocked, void)
8048 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8050 +#endif /* __KERNEL__ */
8051 +#endif /* __AUFS_DEBUG_H__ */
8052 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8053 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8054 +++ linux/fs/aufs/dentry.c 2020-01-27 10:57:18.168871450 +0100
8056 +// SPDX-License-Identifier: GPL-2.0
8058 + * Copyright (C) 2005-2020 Junjiro R. Okajima
8060 + * This program, aufs is free software; you can redistribute it and/or modify
8061 + * it under the terms of the GNU General Public License as published by
8062 + * the Free Software Foundation; either version 2 of the License, or
8063 + * (at your option) any later version.
8065 + * This program is distributed in the hope that it will be useful,
8066 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8067 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8068 + * GNU General Public License for more details.
8070 + * You should have received a copy of the GNU General Public License
8071 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8075 + * lookup and dentry operations
8078 +#include <linux/iversion.h>
8079 +#include <linux/namei.h>
8083 + * returns positive/negative dentry, NULL or an error.
8084 + * NULL means whiteout-ed or not-found.
8086 +static struct dentry*
8087 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8088 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8090 + struct dentry *h_dentry;
8091 + struct inode *h_inode;
8092 + struct au_branch *br;
8093 + int wh_found, opq;
8094 + unsigned char wh_able;
8095 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8096 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8100 + br = au_sbr(dentry->d_sb, bindex);
8101 + wh_able = !!au_br_whable(br->br_perm);
8103 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8104 + h_dentry = ERR_PTR(wh_found);
8107 + if (unlikely(wh_found < 0))
8110 + /* We found a whiteout */
8111 + /* au_set_dbbot(dentry, bindex); */
8112 + au_set_dbwh(dentry, bindex);
8114 + return NULL; /* success */
8118 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8120 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8121 + if (IS_ERR(h_dentry)) {
8122 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8128 + h_inode = d_inode(h_dentry);
8129 + if (d_is_negative(h_dentry)) {
8132 + } else if (wh_found
8133 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8135 + else if (au_ftest_lkup(args->flags, DIRREN)
8137 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8138 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8139 + (unsigned long long)h_inode->i_ino);
8143 + if (au_dbbot(dentry) <= bindex)
8144 + au_set_dbbot(dentry, bindex);
8145 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8146 + au_set_dbtop(dentry, bindex);
8147 + au_set_h_dptr(dentry, bindex, h_dentry);
8149 + if (!d_is_dir(h_dentry)
8151 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8152 + goto out; /* success */
8154 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8155 + opq = au_diropq_test(h_dentry);
8156 + inode_unlock_shared(h_inode);
8158 + au_set_dbdiropq(dentry, bindex);
8159 + else if (unlikely(opq < 0)) {
8160 + au_set_h_dptr(dentry, bindex, NULL);
8161 + h_dentry = ERR_PTR(opq);
8172 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8174 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8175 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8181 + * returns the number of lower positive dentries,
8182 + * otherwise an error.
8183 + * can be called at unlinking with @type is zero.
8185 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8186 + unsigned int flags)
8188 + int npositive, err;
8189 + aufs_bindex_t bindex, btail, bdiropq;
8190 + unsigned char isdir, dirperm1, dirren;
8191 + struct au_do_lookup_args args = {
8193 + .name = &dentry->d_name
8195 + struct dentry *parent;
8196 + struct super_block *sb;
8198 + sb = dentry->d_sb;
8199 + err = au_test_shwh(sb, args.name);
8200 + if (unlikely(err))
8203 + err = au_wh_name_alloc(&args.whname, args.name);
8204 + if (unlikely(err))
8207 + isdir = !!d_is_dir(dentry);
8208 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8209 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8211 + au_fset_lkup(args.flags, DIRREN);
8214 + parent = dget_parent(dentry);
8215 + btail = au_dbtaildir(parent);
8216 + for (bindex = btop; bindex <= btail; bindex++) {
8217 + struct dentry *h_parent, *h_dentry;
8218 + struct inode *h_inode, *h_dir;
8219 + struct au_branch *br;
8221 + h_dentry = au_h_dptr(dentry, bindex);
8223 + if (d_is_positive(h_dentry))
8227 + h_parent = au_h_dptr(parent, bindex);
8228 + if (!h_parent || !d_is_dir(h_parent))
8232 + /* if the inum matches, then use the prepared name */
8233 + err = au_dr_lkup_name(&args, bindex);
8234 + if (unlikely(err))
8238 + h_dir = d_inode(h_parent);
8239 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8240 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8241 + inode_unlock_shared(h_dir);
8242 + err = PTR_ERR(h_dentry);
8243 + if (IS_ERR(h_dentry))
8246 + au_fclr_lkup(args.flags, ALLOW_NEG);
8248 + au_fset_lkup(args.flags, IGNORE_PERM);
8250 + if (au_dbwh(dentry) == bindex)
8254 + if (d_is_negative(h_dentry))
8256 + h_inode = d_inode(h_dentry);
8259 + args.type = h_inode->i_mode & S_IFMT;
8260 + if (args.type != S_IFDIR)
8263 + /* the type of lower may be different */
8264 + bdiropq = au_dbdiropq(dentry);
8265 + if (bdiropq >= 0 && bdiropq <= bindex)
8268 + br = au_sbr(sb, bindex);
8270 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8271 + /*add_ent*/NULL)) {
8272 + /* prepare next name to lookup */
8273 + err = au_dr_lkup(&args, dentry, bindex);
8274 + if (unlikely(err))
8280 + AuLabel(positive);
8281 + au_update_dbtop(dentry);
8284 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8285 + && au_dbtop(dentry) < 0)) {
8287 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8293 + au_kfree_try_rcu(args.whname.name);
8295 + au_dr_lkup_fin(&args);
8300 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8302 + struct dentry *dentry;
8305 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8306 + dentry = vfsub_lkup_one(name, parent);
8308 + struct vfsub_lkup_one_args args = {
8314 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8315 + if (unlikely(wkq_err))
8316 + dentry = ERR_PTR(wkq_err);
8323 + * lookup @dentry on @bindex which should be negative.
8325 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8328 + struct dentry *parent, *h_parent, *h_dentry;
8329 + struct au_branch *br;
8331 + parent = dget_parent(dentry);
8332 + h_parent = au_h_dptr(parent, bindex);
8333 + br = au_sbr(dentry->d_sb, bindex);
8335 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8337 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8338 + err = PTR_ERR(h_dentry);
8339 + if (IS_ERR(h_dentry))
8341 + if (unlikely(d_is_positive(h_dentry))) {
8343 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8349 + if (bindex < au_dbtop(dentry))
8350 + au_set_dbtop(dentry, bindex);
8351 + if (au_dbbot(dentry) < bindex)
8352 + au_set_dbbot(dentry, bindex);
8353 + au_set_h_dptr(dentry, bindex, h_dentry);
8360 +/* ---------------------------------------------------------------------- */
8362 +/* subset of struct inode */
8364 + unsigned long i_ino;
8365 + /* unsigned int i_nlink; */
8371 + blkcnt_t i_blocks;
8376 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8378 + ia->i_ino = h_inode->i_ino;
8379 + /* ia->i_nlink = h_inode->i_nlink; */
8380 + ia->i_uid = h_inode->i_uid;
8381 + ia->i_gid = h_inode->i_gid;
8382 + ia->i_version = inode_query_iversion(h_inode);
8384 + ia->i_size = h_inode->i_size;
8385 + ia->i_blocks = h_inode->i_blocks;
8387 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8390 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8392 + return ia->i_ino != h_inode->i_ino
8393 + /* || ia->i_nlink != h_inode->i_nlink */
8394 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8395 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8396 + || !inode_eq_iversion(h_inode, ia->i_version)
8398 + || ia->i_size != h_inode->i_size
8399 + || ia->i_blocks != h_inode->i_blocks
8401 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8404 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8405 + struct au_branch *br)
8408 + struct au_iattr ia;
8409 + struct inode *h_inode;
8410 + struct dentry *h_d;
8411 + struct super_block *h_sb;
8414 + memset(&ia, -1, sizeof(ia));
8415 + h_sb = h_dentry->d_sb;
8417 + if (d_is_positive(h_dentry)) {
8418 + h_inode = d_inode(h_dentry);
8419 + au_iattr_save(&ia, h_inode);
8420 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8421 + /* nfs d_revalidate may return 0 for negative dentry */
8422 + /* fuse d_revalidate always return 0 for negative dentry */
8425 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8426 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8427 + err = PTR_ERR(h_d);
8432 + if (unlikely(h_d != h_dentry
8433 + || d_inode(h_d) != h_inode
8434 + || (h_inode && au_iattr_test(&ia, h_inode))))
8435 + err = au_busy_or_stale();
8443 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8444 + struct dentry *h_parent, struct au_branch *br)
8449 + if (udba == AuOpt_UDBA_REVAL
8450 + && !au_test_fs_remote(h_dentry->d_sb)) {
8452 + err = (d_inode(h_dentry->d_parent) != h_dir);
8453 + } else if (udba != AuOpt_UDBA_NONE)
8454 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8459 +/* ---------------------------------------------------------------------- */
8461 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8464 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8465 + struct au_hdentry tmp, *p, *q;
8466 + struct au_dinfo *dinfo;
8467 + struct super_block *sb;
8469 + DiMustWriteLock(dentry);
8471 + sb = dentry->d_sb;
8472 + dinfo = au_di(dentry);
8473 + bbot = dinfo->di_bbot;
8474 + bwh = dinfo->di_bwh;
8475 + bdiropq = dinfo->di_bdiropq;
8476 + bindex = dinfo->di_btop;
8477 + p = au_hdentry(dinfo, bindex);
8478 + for (; bindex <= bbot; bindex++, p++) {
8479 + if (!p->hd_dentry)
8482 + new_bindex = au_br_index(sb, p->hd_id);
8483 + if (new_bindex == bindex)
8486 + if (dinfo->di_bwh == bindex)
8488 + if (dinfo->di_bdiropq == bindex)
8489 + bdiropq = new_bindex;
8490 + if (new_bindex < 0) {
8492 + p->hd_dentry = NULL;
8496 + /* swap two lower dentries, and loop again */
8497 + q = au_hdentry(dinfo, new_bindex);
8501 + if (tmp.hd_dentry) {
8507 + dinfo->di_bwh = -1;
8508 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8509 + dinfo->di_bwh = bwh;
8511 + dinfo->di_bdiropq = -1;
8513 + && bdiropq <= au_sbbot(sb)
8514 + && au_sbr_whable(sb, bdiropq))
8515 + dinfo->di_bdiropq = bdiropq;
8518 + dinfo->di_btop = -1;
8519 + dinfo->di_bbot = -1;
8520 + bbot = au_dbbot(parent);
8522 + p = au_hdentry(dinfo, bindex);
8523 + for (; bindex <= bbot; bindex++, p++)
8524 + if (p->hd_dentry) {
8525 + dinfo->di_btop = bindex;
8529 + if (dinfo->di_btop >= 0) {
8531 + p = au_hdentry(dinfo, bindex);
8532 + for (; bindex >= 0; bindex--, p--)
8533 + if (p->hd_dentry) {
8534 + dinfo->di_bbot = bindex;
8543 +static void au_do_hide(struct dentry *dentry)
8545 + struct inode *inode;
8547 + if (d_really_is_positive(dentry)) {
8548 + inode = d_inode(dentry);
8549 + if (!d_is_dir(dentry)) {
8550 + if (inode->i_nlink && !d_unhashed(dentry))
8551 + drop_nlink(inode);
8553 + clear_nlink(inode);
8554 + /* stop next lookup */
8555 + inode->i_flags |= S_DEAD;
8557 + smp_mb(); /* necessary? */
8562 +static int au_hide_children(struct dentry *parent)
8564 + int err, i, j, ndentry;
8565 + struct au_dcsub_pages dpages;
8566 + struct au_dpage *dpage;
8567 + struct dentry *dentry;
8569 + err = au_dpages_init(&dpages, GFP_NOFS);
8570 + if (unlikely(err))
8572 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8573 + if (unlikely(err))
8576 + /* in reverse order */
8577 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8578 + dpage = dpages.dpages + i;
8579 + ndentry = dpage->ndentry;
8580 + for (j = ndentry - 1; j >= 0; j--) {
8581 + dentry = dpage->dentries[j];
8582 + if (dentry != parent)
8583 + au_do_hide(dentry);
8588 + au_dpages_free(&dpages);
8593 +static void au_hide(struct dentry *dentry)
8597 + AuDbgDentry(dentry);
8598 + if (d_is_dir(dentry)) {
8599 + /* shrink_dcache_parent(dentry); */
8600 + err = au_hide_children(dentry);
8601 + if (unlikely(err))
8602 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8605 + au_do_hide(dentry);
8609 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8611 + * a dirty branch is added
8612 + * - on the top of layers
8613 + * - in the middle of layers
8614 + * - to the bottom of layers
8616 + * on the added branch there exists
8619 + * - a same named entry
8621 + * * negative --> positive
8622 + * * positive --> positive
8623 + * - type is unchanged
8624 + * - type is changed
8626 + * * negative --> negative
8627 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8630 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8631 + struct au_dinfo *tmp)
8634 + aufs_bindex_t bindex, bbot;
8636 + struct dentry *dentry;
8637 + struct inode *inode;
8639 + } orig_h, tmp_h = {
8642 + struct au_hdentry *hd;
8643 + struct inode *inode, *h_inode;
8644 + struct dentry *h_dentry;
8647 + AuDebugOn(dinfo->di_btop < 0);
8649 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8650 + orig_h.inode = NULL;
8651 + if (d_is_positive(orig_h.dentry)) {
8652 + orig_h.inode = d_inode(orig_h.dentry);
8653 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8655 + if (tmp->di_btop >= 0) {
8656 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8657 + if (d_is_positive(tmp_h.dentry)) {
8658 + tmp_h.inode = d_inode(tmp_h.dentry);
8659 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8664 + if (d_really_is_positive(dentry))
8665 + inode = d_inode(dentry);
8666 + if (!orig_h.inode) {
8667 + AuDbg("negative originally\n");
8673 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8674 + AuDebugOn(dinfo->di_bdiropq != -1);
8676 + if (!tmp_h.inode) {
8677 + AuDbg("negative --> negative\n");
8678 + /* should have only one negative lower */
8679 + if (tmp->di_btop >= 0
8680 + && tmp->di_btop < dinfo->di_btop) {
8681 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8682 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8683 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8684 + au_di_cp(dinfo, tmp);
8685 + hd = au_hdentry(tmp, tmp->di_btop);
8686 + au_set_h_dptr(dentry, tmp->di_btop,
8687 + dget(hd->hd_dentry));
8689 + au_dbg_verify_dinode(dentry);
8691 + AuDbg("negative --> positive\n");
8693 + * similar to the behaviour of creating with bypassing
8695 + * unhash it in order to force an error in the
8696 + * succeeding create operation.
8697 + * we should not set S_DEAD here.
8700 + /* au_di_swap(tmp, dinfo); */
8701 + au_dbg_verify_dinode(dentry);
8704 + AuDbg("positive originally\n");
8705 + /* inode may be NULL */
8706 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8707 + if (!tmp_h.inode) {
8708 + AuDbg("positive --> negative\n");
8709 + /* or bypassing aufs */
8711 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8712 + dinfo->di_bwh = tmp->di_bwh;
8714 + err = au_refresh_hinode_self(inode);
8715 + au_dbg_verify_dinode(dentry);
8716 + } else if (orig_h.mode == tmp_h.mode) {
8717 + AuDbg("positive --> positive, same type\n");
8718 + if (!S_ISDIR(orig_h.mode)
8719 + && dinfo->di_btop > tmp->di_btop) {
8721 + * similar to the behaviour of removing and
8726 + err = au_refresh_hinode_self(inode);
8727 + au_dbg_verify_dinode(dentry);
8729 + /* fill empty slots */
8730 + if (dinfo->di_btop > tmp->di_btop)
8731 + dinfo->di_btop = tmp->di_btop;
8732 + if (dinfo->di_bbot < tmp->di_bbot)
8733 + dinfo->di_bbot = tmp->di_bbot;
8734 + dinfo->di_bwh = tmp->di_bwh;
8735 + dinfo->di_bdiropq = tmp->di_bdiropq;
8736 + bbot = dinfo->di_bbot;
8737 + bindex = tmp->di_btop;
8738 + hd = au_hdentry(tmp, bindex);
8739 + for (; bindex <= bbot; bindex++, hd++) {
8740 + if (au_h_dptr(dentry, bindex))
8742 + h_dentry = hd->hd_dentry;
8745 + AuDebugOn(d_is_negative(h_dentry));
8746 + h_inode = d_inode(h_dentry);
8747 + AuDebugOn(orig_h.mode
8748 + != (h_inode->i_mode
8750 + au_set_h_dptr(dentry, bindex,
8754 + err = au_refresh_hinode(inode, dentry);
8755 + au_dbg_verify_dinode(dentry);
8758 + AuDbg("positive --> positive, different type\n");
8759 + /* similar to the behaviour of removing and creating */
8762 + err = au_refresh_hinode_self(inode);
8763 + au_dbg_verify_dinode(dentry);
8771 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8773 + const struct dentry_operations *dop
8774 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8775 + static const unsigned int mask
8776 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8778 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8780 + if (dentry->d_op == dop)
8783 + AuDbg("%pd\n", dentry);
8784 + spin_lock(&dentry->d_lock);
8785 + if (dop == &aufs_dop)
8786 + dentry->d_flags |= mask;
8788 + dentry->d_flags &= ~mask;
8789 + dentry->d_op = dop;
8790 + spin_unlock(&dentry->d_lock);
8793 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8795 + int err, ebrange, nbr;
8796 + unsigned int sigen;
8797 + struct au_dinfo *dinfo, *tmp;
8798 + struct super_block *sb;
8799 + struct inode *inode;
8801 + DiMustWriteLock(dentry);
8802 + AuDebugOn(IS_ROOT(dentry));
8803 + AuDebugOn(d_really_is_negative(parent));
8805 + sb = dentry->d_sb;
8806 + sigen = au_sigen(sb);
8807 + err = au_digen_test(parent, sigen);
8808 + if (unlikely(err))
8811 + nbr = au_sbbot(sb) + 1;
8812 + dinfo = au_di(dentry);
8813 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8814 + if (unlikely(err))
8816 + ebrange = au_dbrange_test(dentry);
8818 + ebrange = au_do_refresh_hdentry(dentry, parent);
8820 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8821 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8822 + if (d_really_is_positive(dentry)) {
8823 + inode = d_inode(dentry);
8824 + err = au_refresh_hinode_self(inode);
8826 + au_dbg_verify_dinode(dentry);
8828 + goto out_dgen; /* success */
8832 + /* temporary dinfo */
8833 + AuDbgDentry(dentry);
8835 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8836 + if (unlikely(!tmp))
8838 + au_di_swap(tmp, dinfo);
8839 + /* returns the number of positive dentries */
8841 + * if current working dir is removed, it returns an error.
8842 + * but the dentry is legal.
8844 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8845 + AuDbgDentry(dentry);
8846 + au_di_swap(tmp, dinfo);
8847 + if (err == -ENOENT)
8850 + /* compare/refresh by dinfo */
8851 + AuDbgDentry(dentry);
8852 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8853 + au_dbg_verify_dinode(dentry);
8856 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8857 + au_rw_write_unlock(&tmp->di_rwsem);
8859 + if (unlikely(err))
8863 + au_update_digen(dentry);
8865 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8866 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8867 + AuDbgDentry(dentry);
8873 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8874 + struct dentry *dentry, aufs_bindex_t bindex)
8879 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8882 + AuDbg("b%d\n", bindex);
8884 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8885 + * due to whiteout and branch permission.
8887 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8888 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8889 + /* it may return tri-state */
8890 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8892 + if (unlikely(valid < 0))
8902 +/* todo: remove this */
8903 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8904 + unsigned int flags, int do_udba, int dirren)
8907 + umode_t mode, h_mode;
8908 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8909 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8910 + struct inode *h_inode, *h_cached_inode;
8911 + struct dentry *h_dentry;
8912 + struct qstr *name, *h_name;
8919 + unhashed = !!d_unhashed(dentry);
8920 + is_root = !!IS_ROOT(dentry);
8921 + name = &dentry->d_name;
8922 + tmpfile = au_di(dentry)->di_tmpfile;
8925 + * Theoretically, REVAL test should be unnecessary in case of
8927 + * But {fs,i}notify doesn't fire some necessary events,
8928 + * IN_ATTRIB for atime/nlink/pageio
8929 + * Let's do REVAL test too.
8931 + if (do_udba && inode) {
8932 + mode = (inode->i_mode & S_IFMT);
8933 + plus = (inode->i_nlink > 0);
8934 + ibs = au_ibtop(inode);
8935 + ibe = au_ibbot(inode);
8938 + btop = au_dbtop(dentry);
8940 + if (inode && S_ISDIR(inode->i_mode))
8941 + btail = au_dbtaildir(dentry);
8942 + for (bindex = btop; bindex <= btail; bindex++) {
8943 + h_dentry = au_h_dptr(dentry, bindex);
8947 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8948 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8949 + spin_lock(&h_dentry->d_lock);
8950 + h_name = &h_dentry->d_name;
8951 + if (unlikely(do_udba
8954 + && (unhashed != !!d_unhashed(h_dentry)
8955 + || (!tmpfile && !dirren
8956 + && !au_qstreq(name, h_name))
8959 + && !(flags & LOOKUP_OPEN)
8960 + && (h_dentry->d_flags
8961 + & DCACHE_NFSFS_RENAMED)))
8965 + h_unhashed = d_unhashed(h_dentry);
8966 + spin_unlock(&h_dentry->d_lock);
8967 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8968 + unhashed, h_unhashed, dentry, h_dentry);
8971 + spin_unlock(&h_dentry->d_lock);
8973 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8974 + if (unlikely(err))
8975 + /* do not goto err, to keep the errno */
8978 + /* todo: plink too? */
8983 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8987 + if (d_is_positive(h_dentry))
8988 + h_inode = d_inode(h_dentry);
8991 + h_cached_inode = h_inode;
8993 + h_mode = (h_inode->i_mode & S_IFMT);
8994 + h_plus = (h_inode->i_nlink > 0);
8996 + if (inode && ibs <= bindex && bindex <= ibe)
8997 + h_cached_inode = au_h_iptr(inode, bindex);
9000 + if (unlikely(plus != h_plus && !tmpfile))
9003 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9005 + && !IS_ROOT(h_dentry)
9006 + && unhashed != d_unhashed(h_dentry)))
9009 + if (unlikely(mode != h_mode
9010 + || h_cached_inode != h_inode))
9023 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9024 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9027 + struct dentry *parent;
9029 + if (!au_digen_test(dentry, sigen))
9032 + parent = dget_parent(dentry);
9033 + di_read_lock_parent(parent, AuLock_IR);
9034 + AuDebugOn(au_digen_test(parent, sigen));
9035 + au_dbg_verify_gen(parent, sigen);
9036 + err = au_refresh_dentry(dentry, parent);
9037 + di_read_unlock(parent, AuLock_IR);
9043 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9046 + struct dentry *d, *parent;
9048 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9049 + return simple_reval_dpath(dentry, sigen);
9051 + /* slow loop, keep it simple and stupid */
9052 + /* cf: au_cpup_dirs() */
9055 + while (au_digen_test(dentry, sigen)) {
9059 + parent = dget_parent(d);
9060 + if (!au_digen_test(parent, sigen))
9066 + di_write_lock_child2(d);
9068 + /* someone might update our dentry while we were sleeping */
9069 + if (au_digen_test(d, sigen)) {
9071 + * todo: consolidate with simple_reval_dpath(),
9072 + * do_refresh() and au_reval_for_attr().
9074 + di_read_lock_parent(parent, AuLock_IR);
9075 + err = au_refresh_dentry(d, parent);
9076 + di_read_unlock(parent, AuLock_IR);
9080 + di_write_unlock(d);
9082 + if (unlikely(err))
9090 + * if valid returns 1, otherwise 0.
9092 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9095 + unsigned int sigen;
9096 + unsigned char do_udba, dirren;
9097 + struct super_block *sb;
9098 + struct inode *inode;
9100 + /* todo: support rcu-walk? */
9101 + if (flags & LOOKUP_RCU)
9105 + if (unlikely(!au_di(dentry)))
9109 + sb = dentry->d_sb;
9112 + * i_mutex of parent dir may be held,
9113 + * but we should not return 'invalid' due to busy.
9115 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9116 + if (unlikely(err)) {
9122 + if (d_really_is_positive(dentry))
9123 + inode = d_inode(dentry);
9124 + if (unlikely(inode && au_is_bad_inode(inode))) {
9129 + if (unlikely(au_dbrange_test(dentry))) {
9135 + sigen = au_sigen(sb);
9136 + if (au_digen_test(dentry, sigen)) {
9137 + AuDebugOn(IS_ROOT(dentry));
9138 + err = au_reval_dpath(dentry, sigen);
9139 + if (unlikely(err)) {
9144 + di_downgrade_lock(dentry, AuLock_IR);
9147 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9149 + && !(inode->i_state && I_LINKABLE)
9150 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9155 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9156 + if (do_udba && inode) {
9157 + aufs_bindex_t btop = au_ibtop(inode);
9158 + struct inode *h_inode;
9161 + h_inode = au_h_iptr(inode, btop);
9162 + if (h_inode && au_test_higen(inode, h_inode)) {
9169 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9170 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9171 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9173 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9179 + di_downgrade_lock(dentry, AuLock_IR);
9181 + aufs_read_unlock(dentry, AuLock_IR);
9186 + AuDbg("%pd invalid, %d\n", dentry, valid);
9192 +static void aufs_d_release(struct dentry *dentry)
9194 + if (au_di(dentry)) {
9195 + au_di_fin(dentry);
9196 + au_hn_di_reinit(dentry);
9200 +const struct dentry_operations aufs_dop = {
9201 + .d_revalidate = aufs_d_revalidate,
9202 + .d_weak_revalidate = aufs_d_revalidate,
9203 + .d_release = aufs_d_release
9206 +/* aufs_dop without d_revalidate */
9207 +const struct dentry_operations aufs_dop_noreval = {
9208 + .d_release = aufs_d_release
9210 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9211 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9212 +++ linux/fs/aufs/dentry.h 2020-01-27 10:57:18.168871450 +0100
9214 +/* SPDX-License-Identifier: GPL-2.0 */
9216 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9218 + * This program, aufs is free software; you can redistribute it and/or modify
9219 + * it under the terms of the GNU General Public License as published by
9220 + * the Free Software Foundation; either version 2 of the License, or
9221 + * (at your option) any later version.
9223 + * This program is distributed in the hope that it will be useful,
9224 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9225 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9226 + * GNU General Public License for more details.
9228 + * You should have received a copy of the GNU General Public License
9229 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9233 + * lookup and dentry operations
9236 +#ifndef __AUFS_DENTRY_H__
9237 +#define __AUFS_DENTRY_H__
9241 +#include <linux/dcache.h>
9242 +#include "dirren.h"
9245 +struct au_hdentry {
9246 + struct dentry *hd_dentry;
9247 + aufs_bindex_t hd_id;
9251 + atomic_t di_generation;
9253 + struct au_rwsem di_rwsem;
9254 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9255 + unsigned char di_tmpfile; /* to allow the different name */
9256 + struct au_hdentry *di_hdentry;
9257 + struct rcu_head rcu;
9258 +} ____cacheline_aligned_in_smp;
9260 +/* ---------------------------------------------------------------------- */
9262 +/* flags for au_lkup_dentry() */
9263 +#define AuLkup_ALLOW_NEG 1
9264 +#define AuLkup_IGNORE_PERM (1 << 1)
9265 +#define AuLkup_DIRREN (1 << 2)
9266 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9267 +#define au_fset_lkup(flags, name) \
9268 + do { (flags) |= AuLkup_##name; } while (0)
9269 +#define au_fclr_lkup(flags, name) \
9270 + do { (flags) &= ~AuLkup_##name; } while (0)
9272 +#ifndef CONFIG_AUFS_DIRREN
9273 +#undef AuLkup_DIRREN
9274 +#define AuLkup_DIRREN 0
9277 +struct au_do_lookup_args {
9278 + unsigned int flags;
9280 + struct qstr whname, *name;
9281 + struct au_dr_lookup dirren;
9284 +/* ---------------------------------------------------------------------- */
9287 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9289 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9290 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9291 + struct dentry *h_parent, struct au_branch *br);
9293 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9294 + unsigned int flags);
9295 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9296 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9297 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9298 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9301 +void au_di_init_once(void *_di);
9302 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9303 +void au_di_free(struct au_dinfo *dinfo);
9304 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9305 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9306 +int au_di_init(struct dentry *dentry);
9307 +void au_di_fin(struct dentry *dentry);
9308 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9310 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9311 +void di_read_unlock(struct dentry *d, int flags);
9312 +void di_downgrade_lock(struct dentry *d, int flags);
9313 +void di_write_lock(struct dentry *d, unsigned int lsc);
9314 +void di_write_unlock(struct dentry *d);
9315 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9316 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9317 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9319 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9320 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9321 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9322 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9324 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9325 + struct dentry *h_dentry);
9326 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9327 +int au_dbrange_test(struct dentry *dentry);
9328 +void au_update_digen(struct dentry *dentry);
9329 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9330 +void au_update_dbtop(struct dentry *dentry);
9331 +void au_update_dbbot(struct dentry *dentry);
9332 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9334 +/* ---------------------------------------------------------------------- */
9336 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9338 + return dentry->d_fsdata;
9341 +/* ---------------------------------------------------------------------- */
9343 +/* lock subclass for dinfo */
9345 + AuLsc_DI_CHILD, /* child first */
9346 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9347 + AuLsc_DI_CHILD3, /* copyup dirs */
9351 + AuLsc_DI_TMP /* temp for replacing dinfo */
9355 + * di_read_lock_child, di_write_lock_child,
9356 + * di_read_lock_child2, di_write_lock_child2,
9357 + * di_read_lock_child3, di_write_lock_child3,
9358 + * di_read_lock_parent, di_write_lock_parent,
9359 + * di_read_lock_parent2, di_write_lock_parent2,
9360 + * di_read_lock_parent3, di_write_lock_parent3,
9362 +#define AuReadLockFunc(name, lsc) \
9363 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9364 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9366 +#define AuWriteLockFunc(name, lsc) \
9367 +static inline void di_write_lock_##name(struct dentry *d) \
9368 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9370 +#define AuRWLockFuncs(name, lsc) \
9371 + AuReadLockFunc(name, lsc) \
9372 + AuWriteLockFunc(name, lsc)
9374 +AuRWLockFuncs(child, CHILD);
9375 +AuRWLockFuncs(child2, CHILD2);
9376 +AuRWLockFuncs(child3, CHILD3);
9377 +AuRWLockFuncs(parent, PARENT);
9378 +AuRWLockFuncs(parent2, PARENT2);
9379 +AuRWLockFuncs(parent3, PARENT3);
9381 +#undef AuReadLockFunc
9382 +#undef AuWriteLockFunc
9383 +#undef AuRWLockFuncs
9385 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9386 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9387 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9389 +/* ---------------------------------------------------------------------- */
9391 +/* todo: memory barrier? */
9392 +static inline unsigned int au_digen(struct dentry *d)
9394 + return atomic_read(&au_di(d)->di_generation);
9397 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9399 + hdentry->hd_dentry = NULL;
9402 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9403 + aufs_bindex_t bindex)
9405 + return di->di_hdentry + bindex;
9408 +static inline void au_hdput(struct au_hdentry *hd)
9411 + dput(hd->hd_dentry);
9414 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9416 + DiMustAnyLock(dentry);
9417 + return au_di(dentry)->di_btop;
9420 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9422 + DiMustAnyLock(dentry);
9423 + return au_di(dentry)->di_bbot;
9426 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9428 + DiMustAnyLock(dentry);
9429 + return au_di(dentry)->di_bwh;
9432 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9434 + DiMustAnyLock(dentry);
9435 + return au_di(dentry)->di_bdiropq;
9438 +/* todo: hard/soft set? */
9439 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9441 + DiMustWriteLock(dentry);
9442 + au_di(dentry)->di_btop = bindex;
9445 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9447 + DiMustWriteLock(dentry);
9448 + au_di(dentry)->di_bbot = bindex;
9451 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9453 + DiMustWriteLock(dentry);
9454 + /* dbwh can be outside of btop - bbot range */
9455 + au_di(dentry)->di_bwh = bindex;
9458 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9460 + DiMustWriteLock(dentry);
9461 + au_di(dentry)->di_bdiropq = bindex;
9464 +/* ---------------------------------------------------------------------- */
9466 +#ifdef CONFIG_AUFS_HNOTIFY
9467 +static inline void au_digen_dec(struct dentry *d)
9469 + atomic_dec(&au_di(d)->di_generation);
9472 +static inline void au_hn_di_reinit(struct dentry *dentry)
9474 + dentry->d_fsdata = NULL;
9477 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9478 +#endif /* CONFIG_AUFS_HNOTIFY */
9480 +#endif /* __KERNEL__ */
9481 +#endif /* __AUFS_DENTRY_H__ */
9482 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9483 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9484 +++ linux/fs/aufs/dinfo.c 2020-01-27 10:57:18.168871450 +0100
9486 +// SPDX-License-Identifier: GPL-2.0
9488 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9490 + * This program, aufs is free software; you can redistribute it and/or modify
9491 + * it under the terms of the GNU General Public License as published by
9492 + * the Free Software Foundation; either version 2 of the License, or
9493 + * (at your option) any later version.
9495 + * This program is distributed in the hope that it will be useful,
9496 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9497 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9498 + * GNU General Public License for more details.
9500 + * You should have received a copy of the GNU General Public License
9501 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9505 + * dentry private data
9510 +void au_di_init_once(void *_dinfo)
9512 + struct au_dinfo *dinfo = _dinfo;
9514 + au_rw_init(&dinfo->di_rwsem);
9517 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9519 + struct au_dinfo *dinfo;
9522 + dinfo = au_cache_alloc_dinfo();
9523 + if (unlikely(!dinfo))
9526 + nbr = au_sbbot(sb) + 1;
9529 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9530 + if (dinfo->di_hdentry) {
9531 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9532 + dinfo->di_btop = -1;
9533 + dinfo->di_bbot = -1;
9534 + dinfo->di_bwh = -1;
9535 + dinfo->di_bdiropq = -1;
9536 + dinfo->di_tmpfile = 0;
9537 + for (i = 0; i < nbr; i++)
9538 + dinfo->di_hdentry[i].hd_id = -1;
9542 + au_cache_free_dinfo(dinfo);
9549 +void au_di_free(struct au_dinfo *dinfo)
9551 + struct au_hdentry *p;
9552 + aufs_bindex_t bbot, bindex;
9554 + /* dentry may not be revalidated */
9555 + bindex = dinfo->di_btop;
9556 + if (bindex >= 0) {
9557 + bbot = dinfo->di_bbot;
9558 + p = au_hdentry(dinfo, bindex);
9559 + while (bindex++ <= bbot)
9562 + au_kfree_try_rcu(dinfo->di_hdentry);
9563 + au_cache_free_dinfo(dinfo);
9566 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9568 + struct au_hdentry *p;
9571 + AuRwMustWriteLock(&a->di_rwsem);
9572 + AuRwMustWriteLock(&b->di_rwsem);
9574 +#define DiSwap(v, name) \
9576 + v = a->di_##name; \
9577 + a->di_##name = b->di_##name; \
9578 + b->di_##name = v; \
9581 + DiSwap(p, hdentry);
9585 + DiSwap(bi, bdiropq);
9591 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9593 + AuRwMustWriteLock(&dst->di_rwsem);
9594 + AuRwMustWriteLock(&src->di_rwsem);
9596 + dst->di_btop = src->di_btop;
9597 + dst->di_bbot = src->di_bbot;
9598 + dst->di_bwh = src->di_bwh;
9599 + dst->di_bdiropq = src->di_bdiropq;
9603 +int au_di_init(struct dentry *dentry)
9606 + struct super_block *sb;
9607 + struct au_dinfo *dinfo;
9610 + sb = dentry->d_sb;
9611 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9613 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9614 + /* smp_mb(); */ /* atomic_set */
9615 + dentry->d_fsdata = dinfo;
9622 +void au_di_fin(struct dentry *dentry)
9624 + struct au_dinfo *dinfo;
9626 + dinfo = au_di(dentry);
9627 + AuRwDestroy(&dinfo->di_rwsem);
9628 + au_di_free(dinfo);
9631 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9634 + struct au_hdentry *hdp;
9636 + AuRwMustWriteLock(&dinfo->di_rwsem);
9639 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9641 + sz = sizeof(*hdp);
9642 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9645 + dinfo->di_hdentry = hdp;
9652 +/* ---------------------------------------------------------------------- */
9654 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9657 + case AuLsc_DI_CHILD:
9658 + ii_write_lock_child(inode);
9660 + case AuLsc_DI_CHILD2:
9661 + ii_write_lock_child2(inode);
9663 + case AuLsc_DI_CHILD3:
9664 + ii_write_lock_child3(inode);
9666 + case AuLsc_DI_PARENT:
9667 + ii_write_lock_parent(inode);
9669 + case AuLsc_DI_PARENT2:
9670 + ii_write_lock_parent2(inode);
9672 + case AuLsc_DI_PARENT3:
9673 + ii_write_lock_parent3(inode);
9680 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9683 + case AuLsc_DI_CHILD:
9684 + ii_read_lock_child(inode);
9686 + case AuLsc_DI_CHILD2:
9687 + ii_read_lock_child2(inode);
9689 + case AuLsc_DI_CHILD3:
9690 + ii_read_lock_child3(inode);
9692 + case AuLsc_DI_PARENT:
9693 + ii_read_lock_parent(inode);
9695 + case AuLsc_DI_PARENT2:
9696 + ii_read_lock_parent2(inode);
9698 + case AuLsc_DI_PARENT3:
9699 + ii_read_lock_parent3(inode);
9706 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9708 + struct inode *inode;
9710 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9711 + if (d_really_is_positive(d)) {
9712 + inode = d_inode(d);
9713 + if (au_ftest_lock(flags, IW))
9714 + do_ii_write_lock(inode, lsc);
9715 + else if (au_ftest_lock(flags, IR))
9716 + do_ii_read_lock(inode, lsc);
9720 +void di_read_unlock(struct dentry *d, int flags)
9722 + struct inode *inode;
9724 + if (d_really_is_positive(d)) {
9725 + inode = d_inode(d);
9726 + if (au_ftest_lock(flags, IW)) {
9727 + au_dbg_verify_dinode(d);
9728 + ii_write_unlock(inode);
9729 + } else if (au_ftest_lock(flags, IR)) {
9730 + au_dbg_verify_dinode(d);
9731 + ii_read_unlock(inode);
9734 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9737 +void di_downgrade_lock(struct dentry *d, int flags)
9739 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9740 + ii_downgrade_lock(d_inode(d));
9741 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9744 +void di_write_lock(struct dentry *d, unsigned int lsc)
9746 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9747 + if (d_really_is_positive(d))
9748 + do_ii_write_lock(d_inode(d), lsc);
9751 +void di_write_unlock(struct dentry *d)
9753 + au_dbg_verify_dinode(d);
9754 + if (d_really_is_positive(d))
9755 + ii_write_unlock(d_inode(d));
9756 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9759 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9761 + AuDebugOn(d1 == d2
9762 + || d_inode(d1) == d_inode(d2)
9763 + || d1->d_sb != d2->d_sb);
9765 + if ((isdir && au_test_subdir(d1, d2))
9767 + di_write_lock_child(d1);
9768 + di_write_lock_child2(d2);
9770 + di_write_lock_child(d2);
9771 + di_write_lock_child2(d1);
9775 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9777 + AuDebugOn(d1 == d2
9778 + || d_inode(d1) == d_inode(d2)
9779 + || d1->d_sb != d2->d_sb);
9781 + if ((isdir && au_test_subdir(d1, d2))
9783 + di_write_lock_parent(d1);
9784 + di_write_lock_parent2(d2);
9786 + di_write_lock_parent(d2);
9787 + di_write_lock_parent2(d1);
9791 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9793 + di_write_unlock(d1);
9794 + if (d_inode(d1) == d_inode(d2))
9795 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9797 + di_write_unlock(d2);
9800 +/* ---------------------------------------------------------------------- */
9802 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9806 + DiMustAnyLock(dentry);
9808 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9810 + AuDebugOn(bindex < 0);
9811 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9812 + AuDebugOn(d && au_dcount(d) <= 0);
9817 + * extended version of au_h_dptr().
9818 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9821 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9823 + struct dentry *h_dentry;
9824 + struct inode *inode, *h_inode;
9826 + AuDebugOn(d_really_is_negative(dentry));
9829 + if (au_dbtop(dentry) <= bindex
9830 + && bindex <= au_dbbot(dentry))
9831 + h_dentry = au_h_dptr(dentry, bindex);
9832 + if (h_dentry && !au_d_linkable(h_dentry)) {
9834 + goto out; /* success */
9837 + inode = d_inode(dentry);
9838 + AuDebugOn(bindex < au_ibtop(inode));
9839 + AuDebugOn(au_ibbot(inode) < bindex);
9840 + h_inode = au_h_iptr(inode, bindex);
9841 + h_dentry = d_find_alias(h_inode);
9843 + if (!IS_ERR(h_dentry)) {
9844 + if (!au_d_linkable(h_dentry))
9845 + goto out; /* success */
9851 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9852 + h_dentry = au_plink_lkup(inode, bindex);
9853 + AuDebugOn(!h_dentry);
9854 + if (!IS_ERR(h_dentry)) {
9855 + if (!au_d_hashed_positive(h_dentry))
9856 + goto out; /* success */
9863 + AuDbgDentry(h_dentry);
9867 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9869 + aufs_bindex_t bbot, bwh;
9871 + bbot = au_dbbot(dentry);
9873 + bwh = au_dbwh(dentry);
9876 + if (0 < bwh && bwh < bbot)
9882 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9884 + aufs_bindex_t bbot, bopq;
9886 + bbot = au_dbtail(dentry);
9888 + bopq = au_dbdiropq(dentry);
9889 + if (0 <= bopq && bopq < bbot)
9895 +/* ---------------------------------------------------------------------- */
9897 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9898 + struct dentry *h_dentry)
9900 + struct au_dinfo *dinfo;
9901 + struct au_hdentry *hd;
9902 + struct au_branch *br;
9904 + DiMustWriteLock(dentry);
9906 + dinfo = au_di(dentry);
9907 + hd = au_hdentry(dinfo, bindex);
9909 + hd->hd_dentry = h_dentry;
9911 + br = au_sbr(dentry->d_sb, bindex);
9912 + hd->hd_id = br->br_id;
9916 +int au_dbrange_test(struct dentry *dentry)
9919 + aufs_bindex_t btop, bbot;
9922 + btop = au_dbtop(dentry);
9923 + bbot = au_dbbot(dentry);
9925 + AuDebugOn(bbot < 0 && btop > bbot);
9928 + AuDebugOn(bbot >= 0);
9934 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9939 + if (unlikely(au_digen(dentry) != sigen
9940 + || au_iigen_test(d_inode(dentry), sigen)))
9946 +void au_update_digen(struct dentry *dentry)
9948 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9949 + /* smp_mb(); */ /* atomic_set */
9952 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9954 + struct au_dinfo *dinfo;
9955 + struct dentry *h_d;
9956 + struct au_hdentry *hdp;
9957 + aufs_bindex_t bindex, bbot;
9959 + DiMustWriteLock(dentry);
9961 + dinfo = au_di(dentry);
9962 + if (!dinfo || dinfo->di_btop < 0)
9965 + if (do_put_zero) {
9966 + bbot = dinfo->di_bbot;
9967 + bindex = dinfo->di_btop;
9968 + hdp = au_hdentry(dinfo, bindex);
9969 + for (; bindex <= bbot; bindex++, hdp++) {
9970 + h_d = hdp->hd_dentry;
9971 + if (h_d && d_is_negative(h_d))
9972 + au_set_h_dptr(dentry, bindex, NULL);
9976 + dinfo->di_btop = 0;
9977 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9978 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9979 + if (hdp->hd_dentry)
9981 + if (dinfo->di_btop > dinfo->di_bbot) {
9982 + dinfo->di_btop = -1;
9983 + dinfo->di_bbot = -1;
9987 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9988 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9989 + if (hdp->hd_dentry)
9991 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9994 +void au_update_dbtop(struct dentry *dentry)
9996 + aufs_bindex_t bindex, bbot;
9997 + struct dentry *h_dentry;
9999 + bbot = au_dbbot(dentry);
10000 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10001 + h_dentry = au_h_dptr(dentry, bindex);
10004 + if (d_is_positive(h_dentry)) {
10005 + au_set_dbtop(dentry, bindex);
10008 + au_set_h_dptr(dentry, bindex, NULL);
10012 +void au_update_dbbot(struct dentry *dentry)
10014 + aufs_bindex_t bindex, btop;
10015 + struct dentry *h_dentry;
10017 + btop = au_dbtop(dentry);
10018 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10019 + h_dentry = au_h_dptr(dentry, bindex);
10022 + if (d_is_positive(h_dentry)) {
10023 + au_set_dbbot(dentry, bindex);
10026 + au_set_h_dptr(dentry, bindex, NULL);
10030 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10032 + aufs_bindex_t bindex, bbot;
10034 + bbot = au_dbbot(dentry);
10035 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10036 + if (au_h_dptr(dentry, bindex) == h_dentry)
10040 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10041 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10042 +++ linux/fs/aufs/dir.c 2020-01-27 10:57:18.168871450 +0100
10044 +// SPDX-License-Identifier: GPL-2.0
10046 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10048 + * This program, aufs is free software; you can redistribute it and/or modify
10049 + * it under the terms of the GNU General Public License as published by
10050 + * the Free Software Foundation; either version 2 of the License, or
10051 + * (at your option) any later version.
10053 + * This program is distributed in the hope that it will be useful,
10054 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10055 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10056 + * GNU General Public License for more details.
10058 + * You should have received a copy of the GNU General Public License
10059 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10063 + * directory operations
10066 +#include <linux/fs_stack.h>
10067 +#include <linux/iversion.h>
10070 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10072 + unsigned int nlink;
10074 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10076 + nlink = dir->i_nlink;
10077 + nlink += h_dir->i_nlink - 2;
10078 + if (h_dir->i_nlink < 2)
10080 + smp_mb(); /* for i_nlink */
10081 + /* 0 can happen in revaliding */
10082 + set_nlink(dir, nlink);
10085 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10087 + unsigned int nlink;
10089 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10091 + nlink = dir->i_nlink;
10092 + nlink -= h_dir->i_nlink - 2;
10093 + if (h_dir->i_nlink < 2)
10095 + smp_mb(); /* for i_nlink */
10096 + /* nlink == 0 means the branch-fs is broken */
10097 + set_nlink(dir, nlink);
10100 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10103 + aufs_bindex_t bindex, bbot;
10104 + struct file *h_file;
10105 + struct dentry *h_dentry;
10109 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10111 + bbot = au_fbbot_dir(file);
10112 + for (bindex = au_fbtop(file);
10113 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10115 + h_file = au_hf_dir(file, bindex);
10116 + if (h_file && file_inode(h_file))
10117 + sz += vfsub_f_size_read(h_file);
10120 + AuDebugOn(!dentry);
10121 + AuDebugOn(!d_is_dir(dentry));
10123 + bbot = au_dbtaildir(dentry);
10124 + for (bindex = au_dbtop(dentry);
10125 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10127 + h_dentry = au_h_dptr(dentry, bindex);
10128 + if (h_dentry && d_is_positive(h_dentry))
10129 + sz += i_size_read(d_inode(h_dentry));
10132 + if (sz < KMALLOC_MAX_SIZE)
10133 + sz = roundup_pow_of_two(sz);
10134 + if (sz > KMALLOC_MAX_SIZE)
10135 + sz = KMALLOC_MAX_SIZE;
10136 + else if (sz < NAME_MAX) {
10137 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10138 + sz = AUFS_RDBLK_DEF;
10143 +struct au_dir_ts_arg {
10144 + struct dentry *dentry;
10145 + aufs_bindex_t brid;
10148 +static void au_do_dir_ts(void *arg)
10150 + struct au_dir_ts_arg *a = arg;
10151 + struct au_dtime dt;
10152 + struct path h_path;
10153 + struct inode *dir, *h_dir;
10154 + struct super_block *sb;
10155 + struct au_branch *br;
10156 + struct au_hinode *hdir;
10158 + aufs_bindex_t btop, bindex;
10160 + sb = a->dentry->d_sb;
10161 + if (d_really_is_negative(a->dentry))
10163 + /* no dir->i_mutex lock */
10164 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10166 + dir = d_inode(a->dentry);
10167 + btop = au_ibtop(dir);
10168 + bindex = au_br_index(sb, a->brid);
10169 + if (bindex < btop)
10172 + br = au_sbr(sb, bindex);
10173 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10174 + if (!h_path.dentry)
10176 + h_path.mnt = au_br_mnt(br);
10177 + au_dtime_store(&dt, a->dentry, &h_path);
10179 + br = au_sbr(sb, btop);
10180 + if (!au_br_writable(br->br_perm))
10182 + h_path.dentry = au_h_dptr(a->dentry, btop);
10183 + h_path.mnt = au_br_mnt(br);
10184 + err = vfsub_mnt_want_write(h_path.mnt);
10187 + hdir = au_hi(dir, btop);
10188 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10189 + h_dir = au_h_iptr(dir, btop);
10190 + if (h_dir->i_nlink
10191 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10192 + dt.dt_h_path = h_path;
10193 + au_dtime_revert(&dt);
10195 + au_hn_inode_unlock(hdir);
10196 + vfsub_mnt_drop_write(h_path.mnt);
10197 + au_cpup_attr_timesizes(dir);
10200 + aufs_read_unlock(a->dentry, AuLock_DW);
10203 + au_nwt_done(&au_sbi(sb)->si_nowait);
10204 + au_kfree_try_rcu(arg);
10207 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10209 + int perm, wkq_err;
10210 + aufs_bindex_t btop;
10211 + struct au_dir_ts_arg *arg;
10212 + struct dentry *dentry;
10213 + struct super_block *sb;
10217 + dentry = d_find_any_alias(dir);
10218 + AuDebugOn(!dentry);
10219 + sb = dentry->d_sb;
10220 + btop = au_ibtop(dir);
10221 + if (btop == bindex) {
10222 + au_cpup_attr_timesizes(dir);
10226 + perm = au_sbr_perm(sb, btop);
10227 + if (!au_br_writable(perm))
10230 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10234 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10235 + arg->brid = au_sbr_id(sb, bindex);
10236 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10237 + if (unlikely(wkq_err)) {
10238 + pr_err("wkq %d\n", wkq_err);
10240 + au_kfree_try_rcu(arg);
10247 +/* ---------------------------------------------------------------------- */
10249 +static int reopen_dir(struct file *file)
10252 + unsigned int flags;
10253 + aufs_bindex_t bindex, btail, btop;
10254 + struct dentry *dentry, *h_dentry;
10255 + struct file *h_file;
10257 + /* open all lower dirs */
10258 + dentry = file->f_path.dentry;
10259 + btop = au_dbtop(dentry);
10260 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10261 + au_set_h_fptr(file, bindex, NULL);
10262 + au_set_fbtop(file, btop);
10264 + btail = au_dbtaildir(dentry);
10265 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10266 + au_set_h_fptr(file, bindex, NULL);
10267 + au_set_fbbot_dir(file, btail);
10269 + flags = vfsub_file_flags(file);
10270 + for (bindex = btop; bindex <= btail; bindex++) {
10271 + h_dentry = au_h_dptr(dentry, bindex);
10274 + h_file = au_hf_dir(file, bindex);
10278 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10279 + err = PTR_ERR(h_file);
10280 + if (IS_ERR(h_file))
10281 + goto out; /* close all? */
10282 + au_set_h_fptr(file, bindex, h_file);
10284 + au_update_figen(file);
10285 + /* todo: necessary? */
10286 + /* file->f_ra = h_file->f_ra; */
10293 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10296 + aufs_bindex_t bindex, btail;
10297 + struct dentry *dentry, *h_dentry;
10298 + struct vfsmount *mnt;
10300 + FiMustWriteLock(file);
10301 + AuDebugOn(h_file);
10304 + mnt = file->f_path.mnt;
10305 + dentry = file->f_path.dentry;
10306 + file->f_version = inode_query_iversion(d_inode(dentry));
10307 + bindex = au_dbtop(dentry);
10308 + au_set_fbtop(file, bindex);
10309 + btail = au_dbtaildir(dentry);
10310 + au_set_fbbot_dir(file, btail);
10311 + for (; !err && bindex <= btail; bindex++) {
10312 + h_dentry = au_h_dptr(dentry, bindex);
10316 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10317 + if (unlikely(err))
10319 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10320 + if (IS_ERR(h_file)) {
10321 + err = PTR_ERR(h_file);
10324 + au_set_h_fptr(file, bindex, h_file);
10326 + au_update_figen(file);
10327 + /* todo: necessary? */
10328 + /* file->f_ra = h_file->f_ra; */
10330 + return 0; /* success */
10333 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10334 + au_set_h_fptr(file, bindex, NULL);
10335 + au_set_fbtop(file, -1);
10336 + au_set_fbbot_dir(file, -1);
10341 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10342 + struct file *file)
10345 + struct super_block *sb;
10346 + struct au_fidir *fidir;
10349 + sb = file->f_path.dentry->d_sb;
10350 + si_read_lock(sb, AuLock_FLUSH);
10351 + fidir = au_fidir_alloc(sb);
10353 + struct au_do_open_args args = {
10354 + .open = do_open_dir,
10357 + err = au_do_open(file, &args);
10358 + if (unlikely(err))
10359 + au_kfree_rcu(fidir);
10361 + si_read_unlock(sb);
10365 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10366 + struct file *file)
10368 + struct au_vdir *vdir_cache;
10369 + struct au_finfo *finfo;
10370 + struct au_fidir *fidir;
10371 + struct au_hfile *hf;
10372 + aufs_bindex_t bindex, bbot;
10374 + finfo = au_fi(file);
10375 + fidir = finfo->fi_hdir;
10377 + au_hbl_del(&finfo->fi_hlist,
10378 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10379 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10381 + au_vdir_free(vdir_cache);
10383 + bindex = finfo->fi_btop;
10384 + if (bindex >= 0) {
10385 + hf = fidir->fd_hfile + bindex;
10387 + * calls fput() instead of filp_close(),
10388 + * since no dnotify or lock for the lower file.
10390 + bbot = fidir->fd_bbot;
10391 + for (; bindex <= bbot; bindex++, hf++)
10393 + au_hfput(hf, /*execed*/0);
10395 + au_kfree_rcu(fidir);
10396 + finfo->fi_hdir = NULL;
10398 + au_finfo_fin(file);
10402 +/* ---------------------------------------------------------------------- */
10404 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10407 + aufs_bindex_t bindex, bbot;
10408 + struct file *h_file;
10411 + bbot = au_fbbot_dir(file);
10412 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10413 + h_file = au_hf_dir(file, bindex);
10415 + err = vfsub_flush(h_file, id);
10420 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10422 + return au_do_flush(file, id, au_do_flush_dir);
10425 +/* ---------------------------------------------------------------------- */
10427 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10430 + aufs_bindex_t bbot, bindex;
10431 + struct inode *inode;
10432 + struct super_block *sb;
10435 + sb = dentry->d_sb;
10436 + inode = d_inode(dentry);
10437 + IMustLock(inode);
10438 + bbot = au_dbbot(dentry);
10439 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10440 + struct path h_path;
10442 + if (au_test_ro(sb, bindex, inode))
10444 + h_path.dentry = au_h_dptr(dentry, bindex);
10445 + if (!h_path.dentry)
10448 + h_path.mnt = au_sbr_mnt(sb, bindex);
10449 + err = vfsub_fsync(NULL, &h_path, datasync);
10455 +static int au_do_fsync_dir(struct file *file, int datasync)
10458 + aufs_bindex_t bbot, bindex;
10459 + struct file *h_file;
10460 + struct super_block *sb;
10461 + struct inode *inode;
10463 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10464 + if (unlikely(err))
10467 + inode = file_inode(file);
10468 + sb = inode->i_sb;
10469 + bbot = au_fbbot_dir(file);
10470 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10471 + h_file = au_hf_dir(file, bindex);
10472 + if (!h_file || au_test_ro(sb, bindex, inode))
10475 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10483 + * @file may be NULL
10485 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10489 + struct dentry *dentry;
10490 + struct inode *inode;
10491 + struct super_block *sb;
10494 + dentry = file->f_path.dentry;
10495 + inode = d_inode(dentry);
10496 + inode_lock(inode);
10497 + sb = dentry->d_sb;
10498 + si_noflush_read_lock(sb);
10500 + err = au_do_fsync_dir(file, datasync);
10502 + di_write_lock_child(dentry);
10503 + err = au_do_fsync_dir_no_file(dentry, datasync);
10505 + au_cpup_attr_timesizes(inode);
10506 + di_write_unlock(dentry);
10508 + fi_write_unlock(file);
10510 + si_read_unlock(sb);
10511 + inode_unlock(inode);
10515 +/* ---------------------------------------------------------------------- */
10517 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10520 + struct dentry *dentry;
10521 + struct inode *inode, *h_inode;
10522 + struct super_block *sb;
10524 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10526 + dentry = file->f_path.dentry;
10527 + inode = d_inode(dentry);
10528 + IMustLock(inode);
10530 + sb = dentry->d_sb;
10531 + si_read_lock(sb, AuLock_FLUSH);
10532 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10533 + if (unlikely(err))
10535 + err = au_alive_dir(dentry);
10537 + err = au_vdir_init(file);
10538 + di_downgrade_lock(dentry, AuLock_IR);
10539 + if (unlikely(err))
10542 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10543 + if (!au_test_nfsd()) {
10544 + err = au_vdir_fill_de(file, ctx);
10545 + fsstack_copy_attr_atime(inode, h_inode);
10548 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10549 + * encode_fh() and others.
10551 + atomic_inc(&h_inode->i_count);
10552 + di_read_unlock(dentry, AuLock_IR);
10553 + si_read_unlock(sb);
10554 + err = au_vdir_fill_de(file, ctx);
10555 + fsstack_copy_attr_atime(inode, h_inode);
10556 + fi_write_unlock(file);
10564 + di_read_unlock(dentry, AuLock_IR);
10565 + fi_write_unlock(file);
10567 + si_read_unlock(sb);
10571 +/* ---------------------------------------------------------------------- */
10573 +#define AuTestEmpty_WHONLY 1
10574 +#define AuTestEmpty_CALLED (1 << 1)
10575 +#define AuTestEmpty_SHWH (1 << 2)
10576 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10577 +#define au_fset_testempty(flags, name) \
10578 + do { (flags) |= AuTestEmpty_##name; } while (0)
10579 +#define au_fclr_testempty(flags, name) \
10580 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10582 +#ifndef CONFIG_AUFS_SHWH
10583 +#undef AuTestEmpty_SHWH
10584 +#define AuTestEmpty_SHWH 0
10587 +struct test_empty_arg {
10588 + struct dir_context ctx;
10589 + struct au_nhash *whlist;
10590 + unsigned int flags;
10592 + aufs_bindex_t bindex;
10595 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10596 + int namelen, loff_t offset __maybe_unused, u64 ino,
10597 + unsigned int d_type)
10599 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10601 + char *name = (void *)__name;
10604 + au_fset_testempty(arg->flags, CALLED);
10606 + if (name[0] == '.'
10607 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10608 + goto out; /* success */
10610 + if (namelen <= AUFS_WH_PFX_LEN
10611 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10612 + if (au_ftest_testempty(arg->flags, WHONLY)
10613 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10614 + arg->err = -ENOTEMPTY;
10618 + name += AUFS_WH_PFX_LEN;
10619 + namelen -= AUFS_WH_PFX_LEN;
10620 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10621 + arg->err = au_nhash_append_wh
10622 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10623 + au_ftest_testempty(arg->flags, SHWH));
10627 + AuTraceErr(arg->err);
10631 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10634 + struct file *h_file;
10635 + struct au_branch *br;
10637 + h_file = au_h_open(dentry, arg->bindex,
10638 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10639 + /*file*/NULL, /*force_wr*/0);
10640 + err = PTR_ERR(h_file);
10641 + if (IS_ERR(h_file))
10645 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10646 + && !file_inode(h_file)->i_nlink)
10651 + au_fclr_testempty(arg->flags, CALLED);
10653 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10656 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10660 + br = au_sbr(dentry->d_sb, arg->bindex);
10661 + au_lcnt_dec(&br->br_nfiles);
10666 +struct do_test_empty_args {
10668 + struct dentry *dentry;
10669 + struct test_empty_arg *arg;
10672 +static void call_do_test_empty(void *args)
10674 + struct do_test_empty_args *a = args;
10675 + *a->errp = do_test_empty(a->dentry, a->arg);
10678 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10680 + int err, wkq_err;
10681 + struct dentry *h_dentry;
10682 + struct inode *h_inode;
10684 + h_dentry = au_h_dptr(dentry, arg->bindex);
10685 + h_inode = d_inode(h_dentry);
10686 + /* todo: i_mode changes anytime? */
10687 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10688 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10689 + inode_unlock_shared(h_inode);
10691 + err = do_test_empty(dentry, arg);
10693 + struct do_test_empty_args args = {
10695 + .dentry = dentry,
10698 + unsigned int flags = arg->flags;
10700 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10701 + if (unlikely(wkq_err))
10703 + arg->flags = flags;
10709 +int au_test_empty_lower(struct dentry *dentry)
10712 + unsigned int rdhash;
10713 + aufs_bindex_t bindex, btop, btail;
10714 + struct au_nhash whlist;
10715 + struct test_empty_arg arg = {
10717 + .actor = test_empty_cb
10720 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10722 + SiMustAnyLock(dentry->d_sb);
10724 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10726 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10727 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10728 + if (unlikely(err))
10732 + arg.whlist = &whlist;
10733 + btop = au_dbtop(dentry);
10734 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10735 + au_fset_testempty(arg.flags, SHWH);
10736 + test_empty = do_test_empty;
10737 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10738 + test_empty = sio_test_empty;
10739 + arg.bindex = btop;
10740 + err = test_empty(dentry, &arg);
10741 + if (unlikely(err))
10744 + au_fset_testempty(arg.flags, WHONLY);
10745 + btail = au_dbtaildir(dentry);
10746 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10747 + struct dentry *h_dentry;
10749 + h_dentry = au_h_dptr(dentry, bindex);
10750 + if (h_dentry && d_is_positive(h_dentry)) {
10751 + arg.bindex = bindex;
10752 + err = test_empty(dentry, &arg);
10757 + au_nhash_wh_free(&whlist);
10762 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10765 + struct test_empty_arg arg = {
10767 + .actor = test_empty_cb
10770 + aufs_bindex_t bindex, btail;
10773 + arg.whlist = whlist;
10774 + arg.flags = AuTestEmpty_WHONLY;
10775 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10776 + au_fset_testempty(arg.flags, SHWH);
10777 + btail = au_dbtaildir(dentry);
10778 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10779 + struct dentry *h_dentry;
10781 + h_dentry = au_h_dptr(dentry, bindex);
10782 + if (h_dentry && d_is_positive(h_dentry)) {
10783 + arg.bindex = bindex;
10784 + err = sio_test_empty(dentry, &arg);
10791 +/* ---------------------------------------------------------------------- */
10793 +const struct file_operations aufs_dir_fop = {
10794 + .owner = THIS_MODULE,
10795 + .llseek = default_llseek,
10796 + .read = generic_read_dir,
10797 + .iterate_shared = aufs_iterate_shared,
10798 + .unlocked_ioctl = aufs_ioctl_dir,
10799 +#ifdef CONFIG_COMPAT
10800 + .compat_ioctl = aufs_compat_ioctl_dir,
10802 + .open = aufs_open_dir,
10803 + .release = aufs_release_dir,
10804 + .flush = aufs_flush_dir,
10805 + .fsync = aufs_fsync_dir
10807 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10808 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10809 +++ linux/fs/aufs/dir.h 2020-01-27 10:57:18.168871450 +0100
10811 +/* SPDX-License-Identifier: GPL-2.0 */
10813 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10815 + * This program, aufs is free software; you can redistribute it and/or modify
10816 + * it under the terms of the GNU General Public License as published by
10817 + * the Free Software Foundation; either version 2 of the License, or
10818 + * (at your option) any later version.
10820 + * This program is distributed in the hope that it will be useful,
10821 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10822 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10823 + * GNU General Public License for more details.
10825 + * You should have received a copy of the GNU General Public License
10826 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10830 + * directory operations
10833 +#ifndef __AUFS_DIR_H__
10834 +#define __AUFS_DIR_H__
10838 +#include <linux/fs.h>
10840 +/* ---------------------------------------------------------------------- */
10842 +/* need to be faster and smaller */
10845 + unsigned int nh_num;
10846 + struct hlist_head *nh_head;
10849 +struct au_vdir_destr {
10850 + unsigned char len;
10851 + unsigned char name[0];
10854 +struct au_vdir_dehstr {
10855 + struct hlist_node hash;
10856 + struct au_vdir_destr *str;
10857 + struct rcu_head rcu;
10858 +} ____cacheline_aligned_in_smp;
10860 +struct au_vdir_de {
10862 + unsigned char de_type;
10863 + /* caution: packed */
10864 + struct au_vdir_destr de_str;
10867 +struct au_vdir_wh {
10868 + struct hlist_node wh_hash;
10869 +#ifdef CONFIG_AUFS_SHWH
10871 + aufs_bindex_t wh_bindex;
10872 + unsigned char wh_type;
10874 + aufs_bindex_t wh_bindex;
10876 + /* caution: packed */
10877 + struct au_vdir_destr wh_str;
10880 +union au_vdir_deblk_p {
10881 + unsigned char *deblk;
10882 + struct au_vdir_de *de;
10886 + unsigned char **vd_deblk;
10887 + unsigned long vd_nblk;
10889 + unsigned long ul;
10890 + union au_vdir_deblk_p p;
10894 + unsigned int vd_deblk_sz;
10895 + unsigned long vd_jiffy;
10896 + struct rcu_head rcu;
10897 +} ____cacheline_aligned_in_smp;
10899 +/* ---------------------------------------------------------------------- */
10902 +extern const struct file_operations aufs_dir_fop;
10903 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10904 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10905 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10906 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10907 +int au_test_empty_lower(struct dentry *dentry);
10908 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10911 +unsigned int au_rdhash_est(loff_t sz);
10912 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10913 +void au_nhash_wh_free(struct au_nhash *whlist);
10914 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10916 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10917 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10918 + unsigned int d_type, aufs_bindex_t bindex,
10919 + unsigned char shwh);
10920 +void au_vdir_free(struct au_vdir *vdir);
10921 +int au_vdir_init(struct file *file);
10922 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10925 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10927 +#ifdef CONFIG_AUFS_RDU
10929 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10930 +#ifdef CONFIG_COMPAT
10931 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10932 + unsigned long arg);
10935 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10936 + unsigned int cmd, unsigned long arg)
10937 +#ifdef CONFIG_COMPAT
10938 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10939 + unsigned int cmd, unsigned long arg)
10943 +#endif /* __KERNEL__ */
10944 +#endif /* __AUFS_DIR_H__ */
10945 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10946 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10947 +++ linux/fs/aufs/dirren.c 2020-01-27 10:57:18.168871450 +0100
10949 +// SPDX-License-Identifier: GPL-2.0
10951 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10953 + * This program, aufs is free software; you can redistribute it and/or modify
10954 + * it under the terms of the GNU General Public License as published by
10955 + * the Free Software Foundation; either version 2 of the License, or
10956 + * (at your option) any later version.
10958 + * This program is distributed in the hope that it will be useful,
10959 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10960 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10961 + * GNU General Public License for more details.
10963 + * You should have received a copy of the GNU General Public License
10964 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10968 + * special handling in renaming a directory
10969 + * in order to support looking-up the before-renamed name on the lower readonly
10973 +#include <linux/byteorder/generic.h>
10976 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10980 + idx = au_dr_ihash(ent->dr_h_ino);
10981 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10984 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10987 + struct hlist_bl_head *hbl;
10990 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10991 + hbl = dr->dr_h_ino + i;
10992 + hlist_bl_lock(hbl);
10993 + ret &= hlist_bl_empty(hbl);
10994 + hlist_bl_unlock(hbl);
11000 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11002 + struct au_dr_hino *found, *ent;
11003 + struct hlist_bl_head *hbl;
11004 + struct hlist_bl_node *pos;
11008 + idx = au_dr_ihash(ino);
11009 + hbl = dr->dr_h_ino + idx;
11010 + hlist_bl_lock(hbl);
11011 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11012 + if (ent->dr_h_ino == ino) {
11016 + hlist_bl_unlock(hbl);
11021 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11022 + struct au_dr_hino *add_ent)
11025 + struct hlist_bl_head *hbl;
11026 + struct hlist_bl_node *pos;
11027 + struct au_dr_hino *ent;
11030 + idx = au_dr_ihash(ino);
11031 + hbl = dr->dr_h_ino + idx;
11032 +#if 0 /* debug print */
11034 + struct hlist_bl_node *tmp;
11036 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11037 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11040 + hlist_bl_lock(hbl);
11041 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11042 + if (ent->dr_h_ino == ino) {
11046 + if (!found && add_ent)
11047 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11048 + hlist_bl_unlock(hbl);
11050 + if (!found && add_ent)
11051 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11056 +void au_dr_hino_free(struct au_dr_br *dr)
11059 + struct hlist_bl_head *hbl;
11060 + struct hlist_bl_node *pos, *tmp;
11061 + struct au_dr_hino *ent;
11063 + /* SiMustWriteLock(sb); */
11065 + for (i = 0; i < AuDirren_NHASH; i++) {
11066 + hbl = dr->dr_h_ino + i;
11067 + /* no spinlock since sbinfo must be write-locked */
11068 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11069 + au_kfree_rcu(ent);
11070 + INIT_HLIST_BL_HEAD(hbl);
11074 +/* returns the number of inodes or an error */
11075 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11076 + struct file *hinofile)
11080 + loff_t pos, oldsize;
11082 + struct inode *hinoinode;
11083 + struct hlist_bl_head *hbl;
11084 + struct hlist_bl_node *n1, *n2;
11085 + struct au_dr_hino *ent;
11087 + SiMustWriteLock(sb);
11088 + AuDebugOn(!au_br_writable(br->br_perm));
11090 + hinoinode = file_inode(hinofile);
11091 + oldsize = i_size_read(hinoinode);
11095 + hbl = br->br_dirren.dr_h_ino;
11096 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11097 + /* no bit-lock since sbinfo must be write-locked */
11098 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11099 + AuDbg("hi%llu, %pD2\n",
11100 + (unsigned long long)ent->dr_h_ino, hinofile);
11101 + u64 = cpu_to_be64(ent->dr_h_ino);
11102 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11103 + if (ssz == sizeof(u64))
11106 + /* write error */
11107 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11114 + /* regardless the error */
11115 + if (pos < oldsize) {
11116 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11124 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11131 + struct au_dr_hino *ent;
11132 + struct inode *hinoinode;
11133 + struct hlist_bl_head *hbl;
11137 + hbl = dr->dr_h_ino;
11138 + hinoinode = file_inode(hinofile);
11139 + sz = i_size_read(hinoinode);
11140 + AuDebugOn(sz % sizeof(u64));
11141 + n = sz / sizeof(u64);
11143 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11144 + if (unlikely(ssz != sizeof(u64))) {
11145 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11152 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11158 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11159 + AuDbg("hi%llu, %pD2\n",
11160 + (unsigned long long)ent->dr_h_ino, hinofile);
11161 + hidx = au_dr_ihash(ent->dr_h_ino);
11162 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11164 + goto out; /* success */
11167 + au_dr_hino_free(dr);
11174 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11175 + * @path is a switch to distinguish load and store.
11177 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11178 + struct au_branch *br, const struct path *path)
11181 + unsigned char load, suspend;
11182 + struct file *hinofile;
11183 + struct au_hinode *hdir;
11184 + struct inode *dir, *delegated;
11185 + struct path hinopath;
11186 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11187 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11189 + AuDebugOn(bindex < 0 && !br);
11190 + AuDebugOn(bindex >= 0 && br);
11195 + br = au_sbr(sb, bindex);
11198 + path = &br->br_path;
11199 + AuDebugOn(!au_br_writable(br->br_perm));
11200 + if (unlikely(!au_br_writable(br->br_perm)))
11206 + dir = d_inode(sb->s_root);
11207 + hdir = au_hinode(au_ii(dir), bindex);
11208 + dir = hdir->hi_inode;
11209 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11211 + dir = d_inode(path->dentry);
11212 + inode_lock_nested(dir, AuLsc_I_CHILD);
11214 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11215 + err = PTR_ERR(hinopath.dentry);
11216 + if (IS_ERR(hinopath.dentry))
11220 + flags = O_RDONLY;
11222 + if (d_is_negative(hinopath.dentry))
11223 + goto out_dput; /* success */
11225 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11226 + if (d_is_positive(hinopath.dentry)) {
11227 + delegated = NULL;
11228 + err = vfsub_unlink(dir, &hinopath, &delegated,
11231 + if (unlikely(err))
11232 + pr_err("ignored err %d, %pd2\n",
11233 + err, hinopath.dentry);
11234 + if (unlikely(err == -EWOULDBLOCK))
11239 + } else if (!d_is_positive(hinopath.dentry)) {
11240 + err = vfsub_create(dir, &hinopath, 0600,
11241 + /*want_excl*/false);
11243 + if (unlikely(err))
11246 + flags = O_WRONLY;
11248 + hinopath.mnt = path->mnt;
11249 + hinofile = vfsub_dentry_open(&hinopath, flags);
11251 + au_hn_inode_unlock(hdir);
11253 + inode_unlock(dir);
11254 + dput(hinopath.dentry);
11255 + AuTraceErrPtr(hinofile);
11256 + if (IS_ERR(hinofile)) {
11257 + err = PTR_ERR(hinofile);
11262 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11264 + err = au_dr_hino_store(sb, br, hinofile);
11269 + dput(hinopath.dentry);
11272 + au_hn_inode_unlock(hdir);
11274 + inode_unlock(dir);
11280 +/* ---------------------------------------------------------------------- */
11282 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11285 + struct kstatfs kstfs;
11287 + struct dentry *dentry;
11288 + struct super_block *sb;
11290 + err = vfs_statfs((void *)path, &kstfs);
11292 + if (unlikely(err))
11295 + /* todo: support for UUID */
11297 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11298 + brid->type = AuBrid_FSID;
11299 + brid->fsid = kstfs.f_fsid;
11301 + dentry = path->dentry;
11302 + sb = dentry->d_sb;
11305 + brid->type = AuBrid_DEV;
11314 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11315 + const struct path *path)
11318 + struct au_dr_br *dr;
11319 + struct hlist_bl_head *hbl;
11321 + dr = &br->br_dirren;
11322 + hbl = dr->dr_h_ino;
11323 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11324 + INIT_HLIST_BL_HEAD(hbl);
11326 + err = au_dr_brid_init(&dr->dr_brid, path);
11327 + if (unlikely(err))
11330 + if (au_opt_test(au_mntflags(sb), DIRREN))
11331 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11338 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11343 + if (au_br_writable(br->br_perm))
11344 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11346 + au_dr_hino_free(&br->br_dirren);
11351 +/* ---------------------------------------------------------------------- */
11353 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11354 + char *buf, size_t sz)
11357 + unsigned int major, minor;
11361 + err = snprintf(p, sz, "%d_", brid->type);
11362 + AuDebugOn(err > sz);
11365 + switch (brid->type) {
11366 + case AuBrid_Unset:
11368 + case AuBrid_UUID:
11369 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11371 + case AuBrid_FSID:
11372 + err = snprintf(p, sz, "%08x-%08x",
11373 + brid->fsid.val[0], brid->fsid.val[1]);
11376 + major = MAJOR(brid->dev);
11377 + minor = MINOR(brid->dev);
11378 + if (major <= 0xff && minor <= 0xff)
11379 + err = snprintf(p, sz, "%02x%02x", major, minor);
11381 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11384 + AuDebugOn(err > sz);
11387 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11388 + AuDebugOn(err > sz);
11395 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11398 + struct dentry *br_dentry;
11399 + struct inode *br_inode;
11401 + br_dentry = au_br_dentry(br);
11402 + br_inode = d_inode(br_dentry);
11403 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11404 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11405 + AuDebugOn(rlen > len);
11410 +/* ---------------------------------------------------------------------- */
11413 + * from the given @h_dentry, construct drinfo at @*fdata.
11414 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11417 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11418 + struct dentry *h_dentry,
11419 + unsigned char *allocated)
11422 + struct au_drinfo_fdata *f, *p;
11423 + struct au_drinfo *drinfo;
11424 + struct inode *h_inode;
11425 + struct qstr *qname;
11429 + h_inode = d_inode(h_dentry);
11430 + qname = &h_dentry->d_name;
11431 + drinfo = &f->drinfo;
11432 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11433 + drinfo->oldnamelen = qname->len;
11434 + if (*allocated < sizeof(*f) + qname->len) {
11435 + v = roundup_pow_of_two(*allocated + qname->len);
11436 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11437 + if (unlikely(!p)) {
11445 + drinfo = &f->drinfo;
11447 + memcpy(drinfo->oldname, qname->name, qname->len);
11448 + AuDbg("i%llu, %.*s\n",
11449 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11450 + drinfo->oldname);
11457 +/* callers have to free the return value */
11458 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11460 + struct au_drinfo *ret, *drinfo;
11461 + struct au_drinfo_fdata fdata;
11466 + ret = ERR_PTR(-EIO);
11468 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11469 + if (unlikely(ssz != sizeof(fdata))) {
11470 + AuIOErr("ssz %zd, %u, %pD2\n",
11471 + ssz, (unsigned int)sizeof(fdata), file);
11475 + fdata.magic = ntohl((__force __be32)fdata.magic);
11476 + switch (fdata.magic) {
11477 + case AUFS_DRINFO_MAGIC_V1:
11480 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11481 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11485 + drinfo = &fdata.drinfo;
11486 + len = drinfo->oldnamelen;
11488 + AuIOErr("broken drinfo %pD2\n", file);
11493 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11494 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11495 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11496 + (unsigned long long)drinfo->ino,
11497 + (unsigned long long)h_ino, file);
11498 + goto out; /* success */
11501 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11502 + if (unlikely(!ret)) {
11503 + ret = ERR_PTR(-ENOMEM);
11504 + AuTraceErrPtr(ret);
11509 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11510 + if (unlikely(ssz != len)) {
11511 + au_kfree_rcu(ret);
11512 + ret = ERR_PTR(-EIO);
11513 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11517 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11523 +/* ---------------------------------------------------------------------- */
11525 +/* in order to be revertible */
11526 +struct au_drinfo_rev_elm {
11528 + struct dentry *info_dentry;
11529 + struct au_drinfo *info_last;
11532 +struct au_drinfo_rev {
11533 + unsigned char already;
11534 + aufs_bindex_t nelm;
11535 + struct au_drinfo_rev_elm elm[0];
11538 +/* todo: isn't it too large? */
11539 +struct au_drinfo_store {
11540 + struct path h_ppath;
11541 + struct dentry *h_dentry;
11542 + struct au_drinfo_fdata *fdata;
11543 + char *infoname; /* inside of whname, just after PFX */
11544 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11545 + aufs_bindex_t btgt, btail;
11546 + unsigned char no_sio,
11547 + allocated, /* current size of *fdata */
11548 + infonamelen, /* room size for p */
11549 + whnamelen, /* length of the generated name */
11550 + renameback; /* renamed back */
11553 +/* on rename(2) error, the caller should revert it using @elm */
11554 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11555 + struct au_drinfo_rev_elm *elm)
11560 + struct path infopath = {
11561 + .mnt = w->h_ppath.mnt
11563 + struct inode *h_dir, *h_inode, *delegated;
11564 + struct file *infofile;
11565 + struct qstr *qname;
11568 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11570 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11572 + AuTraceErrPtr(infopath.dentry);
11573 + if (IS_ERR(infopath.dentry)) {
11574 + err = PTR_ERR(infopath.dentry);
11579 + h_dir = d_inode(w->h_ppath.dentry);
11580 + if (elm && d_is_negative(infopath.dentry)) {
11581 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11583 + if (unlikely(err))
11585 + elm->created = 1;
11586 + elm->info_dentry = dget(infopath.dentry);
11589 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11590 + AuTraceErrPtr(infofile);
11591 + if (IS_ERR(infofile)) {
11592 + err = PTR_ERR(infofile);
11596 + h_inode = d_inode(infopath.dentry);
11597 + if (elm && i_size_read(h_inode)) {
11598 + h_inode = d_inode(w->h_dentry);
11599 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11600 + AuTraceErrPtr(elm->info_last);
11601 + if (IS_ERR(elm->info_last)) {
11602 + err = PTR_ERR(elm->info_last);
11603 + elm->info_last = NULL;
11604 + AuDebugOn(elm->info_dentry);
11609 + if (elm && w->renameback) {
11610 + delegated = NULL;
11611 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11613 + if (unlikely(err == -EWOULDBLOCK))
11619 + qname = &w->h_dentry->d_name;
11620 + len = sizeof(*w->fdata) + qname->len;
11622 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11623 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11624 + if (ssz == len) {
11625 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11626 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11627 + goto out_fput; /* success */
11632 + /* the caller should revert it using @elm */
11638 + dput(infopath.dentry);
11644 +struct au_call_drinfo_do_store_args {
11646 + struct au_drinfo_store *w;
11647 + struct au_drinfo_rev_elm *elm;
11650 +static void au_call_drinfo_do_store(void *args)
11652 + struct au_call_drinfo_do_store_args *a = args;
11654 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11657 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11658 + struct au_drinfo_rev_elm *elm)
11660 + int err, wkq_err;
11663 + err = au_drinfo_do_store(w, elm);
11665 + struct au_call_drinfo_do_store_args a = {
11670 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11671 + if (unlikely(wkq_err))
11679 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11680 + aufs_bindex_t btgt)
11684 + memset(w, 0, sizeof(*w));
11685 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11686 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11687 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11688 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11690 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11693 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11694 + if (unlikely(!w->fdata)) {
11698 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11705 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11707 + au_kfree_rcu(w->fdata);
11710 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11711 + struct au_drinfo_store *w)
11713 + struct au_drinfo_rev_elm *elm;
11714 + struct inode *h_dir, *delegated;
11716 + struct path infopath = {
11717 + .mnt = w->h_ppath.mnt
11720 + h_dir = d_inode(w->h_ppath.dentry);
11721 + IMustLock(h_dir);
11725 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11726 + AuDebugOn(elm->created && elm->info_last);
11727 + if (elm->created) {
11729 + delegated = NULL;
11730 + infopath.dentry = elm->info_dentry;
11731 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11734 + if (unlikely(err == -EWOULDBLOCK))
11736 + dput(elm->info_dentry);
11737 + } else if (elm->info_last) {
11739 + w->fdata->drinfo = *elm->info_last;
11740 + memcpy(w->fdata->drinfo.oldname,
11741 + elm->info_last->oldname,
11742 + elm->info_last->oldnamelen);
11743 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11744 + au_kfree_rcu(elm->info_last);
11746 + if (unlikely(err))
11747 + AuIOErr("%d, %s\n", err, w->whname);
11748 + /* go on even if err */
11752 +/* caller has to call au_dr_rename_fin() later */
11753 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11754 + struct qstr *dst_name, void *_rev)
11756 + int err, sz, nelm;
11757 + aufs_bindex_t bindex, btail;
11758 + struct au_drinfo_store work;
11759 + struct au_drinfo_rev *rev, **p;
11760 + struct au_drinfo_rev_elm *elm;
11761 + struct super_block *sb;
11762 + struct au_branch *br;
11763 + struct au_hinode *hdir;
11765 + err = au_drinfo_store_work_init(&work, btgt);
11767 + if (unlikely(err))
11771 + btail = au_dbtaildir(dentry);
11772 + nelm = btail - btgt;
11773 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11774 + rev = kcalloc(1, sz, GFP_NOFS);
11775 + if (unlikely(!rev)) {
11779 + rev->nelm = nelm;
11785 + sb = dentry->d_sb;
11786 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11787 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11788 + hdir = au_hi(d_inode(dentry), btgt);
11789 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11790 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11791 + work.h_dentry = au_h_dptr(dentry, bindex);
11792 + if (!work.h_dentry)
11795 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11796 + &work.allocated);
11798 + if (unlikely(err))
11801 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11802 + br = au_sbr(sb, bindex);
11803 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11804 + work.whnamelen += au_drinfo_name(br, work.infoname,
11805 + work.infonamelen);
11806 + AuDbg("whname %.*s, i%llu, %.*s\n",
11807 + work.whnamelen, work.whname,
11808 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11809 + work.fdata->drinfo.oldnamelen,
11810 + work.fdata->drinfo.oldname);
11812 + err = au_drinfo_store_sio(&work, elm);
11814 + if (unlikely(err))
11817 + if (unlikely(err)) {
11818 + /* revert all drinfo */
11819 + au_drinfo_store_rev(rev, &work);
11820 + au_kfree_try_rcu(rev);
11823 + au_hn_inode_unlock(hdir);
11826 + au_drinfo_store_work_fin(&work);
11831 +/* ---------------------------------------------------------------------- */
11833 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11834 + struct qstr *dst_name, void *_rev)
11836 + int err, already;
11838 + struct super_block *sb;
11839 + struct au_branch *br;
11840 + struct au_dr_br *dr;
11841 + struct dentry *h_dentry;
11842 + struct inode *h_inode;
11843 + struct au_dr_hino *ent;
11844 + struct au_drinfo_rev *rev, **p;
11846 + AuDbg("bindex %d\n", bindex);
11849 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11850 + if (unlikely(!ent))
11854 + br = au_sbr(sb, bindex);
11855 + dr = &br->br_dirren;
11856 + h_dentry = au_h_dptr(src, bindex);
11857 + h_inode = d_inode(h_dentry);
11858 + ino = h_inode->i_ino;
11859 + ent->dr_h_ino = ino;
11860 + already = au_dr_hino_test_add(dr, ino, ent);
11861 + AuDbg("b%d, hi%llu, already %d\n",
11862 + bindex, (unsigned long long)ino, already);
11864 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11869 + rev->already = already;
11870 + goto out; /* success */
11875 + au_dr_hino_del(dr, ent);
11876 + au_kfree_rcu(ent);
11883 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11885 + struct au_drinfo_rev *rev;
11886 + struct au_drinfo_rev_elm *elm;
11891 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11892 + dput(elm->info_dentry);
11893 + au_kfree_rcu(elm->info_last);
11895 + au_kfree_try_rcu(rev);
11898 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11901 + struct au_drinfo_store work;
11902 + struct au_drinfo_rev *rev = _rev;
11903 + struct super_block *sb;
11904 + struct au_branch *br;
11905 + struct inode *h_inode;
11906 + struct au_dr_br *dr;
11907 + struct au_dr_hino *ent;
11909 + err = au_drinfo_store_work_init(&work, btgt);
11910 + if (unlikely(err))
11914 + br = au_sbr(sb, btgt);
11915 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11916 + work.h_ppath.mnt = au_br_mnt(br);
11917 + au_drinfo_store_rev(rev, &work);
11918 + au_drinfo_store_work_fin(&work);
11919 + if (rev->already)
11922 + dr = &br->br_dirren;
11923 + h_inode = d_inode(work.h_ppath.dentry);
11924 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11926 + au_dr_hino_del(dr, ent);
11927 + au_kfree_rcu(ent);
11930 + au_kfree_try_rcu(rev);
11931 + if (unlikely(err))
11932 + pr_err("failed to remove dirren info\n");
11935 +/* ---------------------------------------------------------------------- */
11937 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11938 + char *whname, int whnamelen,
11939 + struct dentry **info_dentry)
11941 + struct au_drinfo *drinfo;
11943 + struct inode *h_dir;
11944 + struct path infopath;
11947 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11949 + *info_dentry = NULL;
11952 + h_dir = d_inode(h_ppath->dentry);
11953 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11954 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11956 + if (IS_ERR(infopath.dentry)) {
11957 + drinfo = (void *)infopath.dentry;
11961 + if (d_is_negative(infopath.dentry))
11962 + goto out_dput; /* success */
11964 + infopath.mnt = h_ppath->mnt;
11965 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11966 + inode_unlock_shared(h_dir);
11969 + drinfo = (void *)f;
11973 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11974 + if (IS_ERR_OR_NULL(drinfo))
11977 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11978 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11983 + dput(infopath.dentry);
11986 + inode_unlock_shared(h_dir);
11987 + AuTraceErrPtr(drinfo);
11991 +struct au_drinfo_do_load_args {
11992 + struct au_drinfo **drinfop;
11993 + struct path *h_ppath;
11996 + struct dentry **info_dentry;
11999 +static void au_call_drinfo_do_load(void *args)
12001 + struct au_drinfo_do_load_args *a = args;
12003 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12007 +struct au_drinfo_load {
12008 + struct path h_ppath;
12009 + struct qstr *qname;
12010 + unsigned char no_sio;
12012 + aufs_bindex_t ninfo;
12013 + struct au_drinfo **drinfo;
12016 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12017 + struct au_branch *br)
12019 + int err, wkq_err, whnamelen, e;
12020 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12021 + = AUFS_WH_DR_INFO_PFX;
12022 + struct au_drinfo *drinfo;
12023 + struct qstr oldname;
12024 + struct inode *h_dir, *delegated;
12025 + struct dentry *info_dentry;
12026 + struct path infopath;
12028 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12029 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12030 + sizeof(whname) - whnamelen);
12032 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12035 + struct au_drinfo_do_load_args args = {
12036 + .drinfop = &drinfo,
12037 + .h_ppath = &w->h_ppath,
12038 + .whname = whname,
12039 + .whnamelen = whnamelen,
12040 + .info_dentry = &info_dentry
12042 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12043 + if (unlikely(wkq_err))
12044 + drinfo = ERR_PTR(wkq_err);
12046 + err = PTR_ERR(drinfo);
12047 + if (IS_ERR_OR_NULL(drinfo))
12051 + oldname.len = drinfo->oldnamelen;
12052 + oldname.name = drinfo->oldname;
12053 + if (au_qstreq(w->qname, &oldname)) {
12054 + /* the name is renamed back */
12055 + au_kfree_rcu(drinfo);
12058 + infopath.dentry = info_dentry;
12059 + infopath.mnt = w->h_ppath.mnt;
12060 + h_dir = d_inode(w->h_ppath.dentry);
12061 + delegated = NULL;
12062 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12063 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12064 + inode_unlock(h_dir);
12066 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12067 + if (unlikely(e == -EWOULDBLOCK))
12070 + au_kfree_rcu(w->drinfo[bindex]);
12071 + w->drinfo[bindex] = drinfo;
12072 + dput(info_dentry);
12079 +/* ---------------------------------------------------------------------- */
12081 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12083 + struct au_drinfo **p = drinfo;
12086 + au_kfree_rcu(*drinfo++);
12087 + au_kfree_try_rcu(p);
12090 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12091 + aufs_bindex_t btgt)
12094 + struct au_drinfo_load w;
12095 + aufs_bindex_t bindex, bbot;
12096 + struct au_branch *br;
12097 + struct inode *h_dir;
12098 + struct au_dr_hino *ent;
12099 + struct super_block *sb;
12101 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12102 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12103 + AuLNPair(&lkup->whname), btgt);
12105 + sb = dentry->d_sb;
12106 + bbot = au_sbbot(sb);
12107 + w.ninfo = bbot + 1;
12108 + if (!lkup->dirren.drinfo) {
12109 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12110 + sizeof(*lkup->dirren.drinfo),
12112 + if (unlikely(!lkup->dirren.drinfo)) {
12116 + lkup->dirren.ninfo = w.ninfo;
12118 + w.drinfo = lkup->dirren.drinfo;
12119 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12120 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12121 + AuDebugOn(!w.h_ppath.dentry);
12122 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12123 + w.qname = &dentry->d_name;
12126 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12127 + br = au_sbr(sb, bindex);
12128 + err = au_drinfo_load(&w, bindex, br);
12129 + if (unlikely(err))
12131 + if (w.drinfo[bindex])
12135 + br = au_sbr(sb, btgt);
12136 + h_dir = d_inode(w.h_ppath.dentry);
12137 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12139 + au_dr_hino_del(&br->br_dirren, ent);
12140 + au_kfree_rcu(ent);
12142 + goto out; /* success */
12145 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12146 + lkup->dirren.ninfo = 0;
12147 + lkup->dirren.drinfo = NULL;
12153 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12155 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12158 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12161 + struct au_drinfo *drinfo;
12164 + if (!lkup->dirren.drinfo)
12166 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12167 + drinfo = lkup->dirren.drinfo[btgt];
12171 + au_kfree_try_rcu(lkup->whname.name);
12172 + lkup->whname.name = NULL;
12173 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12174 + lkup->dirren.dr_name.name = drinfo->oldname;
12175 + lkup->name = &lkup->dirren.dr_name;
12176 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12178 + AuDbg("name %.*s, whname %.*s, b%d\n",
12179 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12187 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12191 + struct au_drinfo *drinfo;
12194 + if (!lkup->dirren.drinfo)
12196 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12197 + drinfo = lkup->dirren.drinfo[bindex];
12201 + match = (drinfo->ino == h_ino);
12202 + AuDbg("match %d\n", match);
12208 +/* ---------------------------------------------------------------------- */
12210 +int au_dr_opt_set(struct super_block *sb)
12213 + aufs_bindex_t bindex, bbot;
12214 + struct au_branch *br;
12217 + bbot = au_sbbot(sb);
12218 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12219 + br = au_sbr(sb, bindex);
12220 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12226 +int au_dr_opt_flush(struct super_block *sb)
12229 + aufs_bindex_t bindex, bbot;
12230 + struct au_branch *br;
12233 + bbot = au_sbbot(sb);
12234 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12235 + br = au_sbr(sb, bindex);
12236 + if (au_br_writable(br->br_perm))
12237 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12243 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12246 + aufs_bindex_t bindex, bbot;
12247 + struct au_branch *br;
12251 + err = au_dr_opt_flush(sb);
12252 + if (unlikely(err))
12256 + bbot = au_sbbot(sb);
12257 + for (bindex = 0; bindex <= bbot; bindex++) {
12258 + br = au_sbr(sb, bindex);
12259 + au_dr_hino_free(&br->br_dirren);
12265 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12266 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12267 +++ linux/fs/aufs/dirren.h 2020-01-27 10:57:18.168871450 +0100
12269 +/* SPDX-License-Identifier: GPL-2.0 */
12271 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12273 + * This program, aufs is free software; you can redistribute it and/or modify
12274 + * it under the terms of the GNU General Public License as published by
12275 + * the Free Software Foundation; either version 2 of the License, or
12276 + * (at your option) any later version.
12278 + * This program is distributed in the hope that it will be useful,
12279 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12280 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12281 + * GNU General Public License for more details.
12283 + * You should have received a copy of the GNU General Public License
12284 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12288 + * renamed dir info
12291 +#ifndef __AUFS_DIRREN_H__
12292 +#define __AUFS_DIRREN_H__
12296 +#include <linux/dcache.h>
12297 +#include <linux/statfs.h>
12298 +#include <linux/uuid.h>
12301 +#define AuDirren_NHASH 100
12303 +#ifdef CONFIG_AUFS_DIRREN
12304 +enum au_brid_type {
12311 +struct au_dr_brid {
12312 + enum au_brid_type type;
12314 + uuid_t uuid; /* unimplemented yet */
12320 +/* 20 is the max digits length of ulong 64 */
12321 +/* brid-type "_" uuid "_" inum */
12322 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12323 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12325 +struct au_dr_hino {
12326 + struct hlist_bl_node dr_hnode;
12331 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12332 + struct au_dr_brid dr_brid;
12335 +struct au_dr_lookup {
12336 + /* dr_name is pointed by struct au_do_lookup_args.name */
12337 + struct qstr dr_name; /* subset of dr_info */
12338 + aufs_bindex_t ninfo;
12339 + struct au_drinfo **drinfo;
12342 +struct au_dr_hino;
12344 +struct au_dr_br { };
12345 +struct au_dr_lookup { };
12348 +/* ---------------------------------------------------------------------- */
12351 +struct au_do_lookup_args;
12353 +#ifdef CONFIG_AUFS_DIRREN
12354 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12355 + struct au_dr_hino *add_ent);
12356 +void au_dr_hino_free(struct au_dr_br *dr);
12357 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12358 + const struct path *path);
12359 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12360 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12361 + struct qstr *dst_name, void *_rev);
12362 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12363 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12364 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12365 + aufs_bindex_t bindex);
12366 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12367 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12369 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12370 +int au_dr_opt_set(struct super_block *sb);
12371 +int au_dr_opt_flush(struct super_block *sb);
12372 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12374 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12375 + struct au_dr_hino *add_ent);
12376 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12377 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12378 + const struct path *path);
12379 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12380 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12381 + struct qstr *dst_name, void *_rev);
12382 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12383 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12385 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12386 + aufs_bindex_t bindex);
12387 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12388 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12389 + aufs_bindex_t bindex, ino_t h_ino);
12390 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12391 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12392 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12393 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12396 +/* ---------------------------------------------------------------------- */
12398 +#ifdef CONFIG_AUFS_DIRREN
12399 +static inline int au_dr_ihash(ino_t h_ino)
12401 + return h_ino % AuDirren_NHASH;
12404 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12407 +#endif /* __KERNEL__ */
12408 +#endif /* __AUFS_DIRREN_H__ */
12409 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12410 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12411 +++ linux/fs/aufs/dynop.c 2020-01-27 10:57:18.168871450 +0100
12413 +// SPDX-License-Identifier: GPL-2.0
12415 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12417 + * This program, aufs is free software; you can redistribute it and/or modify
12418 + * it under the terms of the GNU General Public License as published by
12419 + * the Free Software Foundation; either version 2 of the License, or
12420 + * (at your option) any later version.
12422 + * This program is distributed in the hope that it will be useful,
12423 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12424 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12425 + * GNU General Public License for more details.
12427 + * You should have received a copy of the GNU General Public License
12428 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12432 + * dynamically customizable operations for regular files
12437 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12440 + * How large will these lists be?
12441 + * Usually just a few elements, 20-30 at most for each, I guess.
12443 +static struct hlist_bl_head dynop[AuDyLast];
12445 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12446 + const void *h_op)
12448 + struct au_dykey *key, *tmp;
12449 + struct hlist_bl_node *pos;
12452 + hlist_bl_lock(hbl);
12453 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12454 + if (tmp->dk_op.dy_hop == h_op) {
12455 + if (kref_get_unless_zero(&tmp->dk_kref))
12459 + hlist_bl_unlock(hbl);
12464 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12466 + struct au_dykey **k, *found;
12467 + const void *h_op = key->dk_op.dy_hop;
12471 + k = br->br_dykey;
12472 + for (i = 0; i < AuBrDynOp; i++)
12474 + if (k[i]->dk_op.dy_hop == h_op) {
12481 + spin_lock(&br->br_dykey_lock);
12482 + for (; i < AuBrDynOp; i++)
12484 + if (k[i]->dk_op.dy_hop == h_op) {
12492 + spin_unlock(&br->br_dykey_lock);
12493 + BUG_ON(i == AuBrDynOp); /* expand the array */
12499 +/* kref_get() if @key is already added */
12500 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12502 + struct au_dykey *tmp, *found;
12503 + struct hlist_bl_node *pos;
12504 + const void *h_op = key->dk_op.dy_hop;
12507 + hlist_bl_lock(hbl);
12508 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12509 + if (tmp->dk_op.dy_hop == h_op) {
12510 + if (kref_get_unless_zero(&tmp->dk_kref))
12515 + hlist_bl_add_head(&key->dk_hnode, hbl);
12516 + hlist_bl_unlock(hbl);
12523 +static void dy_free_rcu(struct rcu_head *rcu)
12525 + struct au_dykey *key;
12527 + key = container_of(rcu, struct au_dykey, dk_rcu);
12532 +static void dy_free(struct kref *kref)
12534 + struct au_dykey *key;
12535 + struct hlist_bl_head *hbl;
12537 + key = container_of(kref, struct au_dykey, dk_kref);
12538 + hbl = dynop + key->dk_op.dy_type;
12539 + au_hbl_del(&key->dk_hnode, hbl);
12540 + call_rcu(&key->dk_rcu, dy_free_rcu);
12543 +void au_dy_put(struct au_dykey *key)
12545 + kref_put(&key->dk_kref, dy_free);
12548 +/* ---------------------------------------------------------------------- */
12550 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12552 +#ifdef CONFIG_AUFS_DEBUG
12553 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12554 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12556 +#define DyDbgDeclare(cnt) do {} while (0)
12557 +#define DyDbgInc(cnt) do {} while (0)
12560 +#define DySet(func, dst, src, h_op, h_sb) do { \
12562 + if (h_op->func) { \
12564 + dst.func = src.func; \
12566 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12570 +#define DySetForce(func, dst, src) do { \
12571 + AuDebugOn(!src.func); \
12573 + dst.func = src.func; \
12576 +#define DySetAop(func) \
12577 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12578 +#define DySetAopForce(func) \
12579 + DySetForce(func, dyaop->da_op, aufs_aop)
12581 +static void dy_aop(struct au_dykey *key, const void *h_op,
12582 + struct super_block *h_sb __maybe_unused)
12584 + struct au_dyaop *dyaop = (void *)key;
12585 + const struct address_space_operations *h_aop = h_op;
12586 + DyDbgDeclare(cnt);
12588 + AuDbg("%s\n", au_sbtype(h_sb));
12590 + DySetAop(writepage);
12591 + DySetAopForce(readpage); /* force */
12592 + DySetAop(writepages);
12593 + DySetAop(set_page_dirty);
12594 + DySetAop(readpages);
12595 + DySetAop(write_begin);
12596 + DySetAop(write_end);
12598 + DySetAop(invalidatepage);
12599 + DySetAop(releasepage);
12600 + DySetAop(freepage);
12601 + /* this one will be changed according to an aufs mount option */
12602 + DySetAop(direct_IO);
12603 + DySetAop(migratepage);
12604 + DySetAop(isolate_page);
12605 + DySetAop(putback_page);
12606 + DySetAop(launder_page);
12607 + DySetAop(is_partially_uptodate);
12608 + DySetAop(is_dirty_writeback);
12609 + DySetAop(error_remove_page);
12610 + DySetAop(swap_activate);
12611 + DySetAop(swap_deactivate);
12613 + DyDbgSize(cnt, *h_aop);
12616 +/* ---------------------------------------------------------------------- */
12618 +static void dy_bug(struct kref *kref)
12623 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12625 + struct au_dykey *key, *old;
12626 + struct hlist_bl_head *hbl;
12629 + void (*set)(struct au_dykey *key, const void *h_op,
12630 + struct super_block *h_sb __maybe_unused);
12632 + static const struct op a[] = {
12634 + .sz = sizeof(struct au_dyaop),
12638 + const struct op *p;
12640 + hbl = dynop + op->dy_type;
12641 + key = dy_gfind_get(hbl, op->dy_hop);
12643 + goto out_add; /* success */
12645 + p = a + op->dy_type;
12646 + key = kzalloc(p->sz, GFP_NOFS);
12647 + if (unlikely(!key)) {
12648 + key = ERR_PTR(-ENOMEM);
12652 + key->dk_op.dy_hop = op->dy_hop;
12653 + kref_init(&key->dk_kref);
12654 + p->set(key, op->dy_hop, au_br_sb(br));
12655 + old = dy_gadd(hbl, key);
12657 + au_kfree_rcu(key);
12662 + old = dy_bradd(br, key);
12664 + /* its ref-count should never be zero here */
12665 + kref_put(&key->dk_kref, dy_bug);
12670 +/* ---------------------------------------------------------------------- */
12672 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12673 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12674 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12675 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12676 + * See the aufs manual in detail.
12678 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12681 + dyaop->da_op.direct_IO = NULL;
12683 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12686 +static struct au_dyaop *dy_aget(struct au_branch *br,
12687 + const struct address_space_operations *h_aop,
12690 + struct au_dyaop *dyaop;
12691 + struct au_dynop op;
12693 + op.dy_type = AuDy_AOP;
12694 + op.dy_haop = h_aop;
12695 + dyaop = (void *)dy_get(&op, br);
12696 + if (IS_ERR(dyaop))
12698 + dy_adx(dyaop, do_dx);
12704 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12705 + struct inode *h_inode)
12708 + struct super_block *sb;
12709 + struct au_branch *br;
12710 + struct au_dyaop *dyaop;
12712 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12713 + IiMustWriteLock(inode);
12715 + sb = inode->i_sb;
12716 + br = au_sbr(sb, bindex);
12717 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12718 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12719 + err = PTR_ERR(dyaop);
12720 + if (IS_ERR(dyaop))
12721 + /* unnecessary to call dy_fput() */
12725 + inode->i_mapping->a_ops = &dyaop->da_op;
12732 + * Is it safe to replace a_ops during the inode/file is in operation?
12733 + * Yes, I hope so.
12735 +int au_dy_irefresh(struct inode *inode)
12738 + aufs_bindex_t btop;
12739 + struct inode *h_inode;
12742 + if (S_ISREG(inode->i_mode)) {
12743 + btop = au_ibtop(inode);
12744 + h_inode = au_h_iptr(inode, btop);
12745 + err = au_dy_iaop(inode, btop, h_inode);
12750 +void au_dy_arefresh(int do_dx)
12752 + struct hlist_bl_head *hbl;
12753 + struct hlist_bl_node *pos;
12754 + struct au_dykey *key;
12756 + hbl = dynop + AuDy_AOP;
12757 + hlist_bl_lock(hbl);
12758 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12759 + dy_adx((void *)key, do_dx);
12760 + hlist_bl_unlock(hbl);
12763 +/* ---------------------------------------------------------------------- */
12765 +void __init au_dy_init(void)
12769 + for (i = 0; i < AuDyLast; i++)
12770 + INIT_HLIST_BL_HEAD(dynop + i);
12773 +void au_dy_fin(void)
12777 + for (i = 0; i < AuDyLast; i++)
12778 + WARN_ON(!hlist_bl_empty(dynop + i));
12780 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12781 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12782 +++ linux/fs/aufs/dynop.h 2020-01-27 10:57:18.168871450 +0100
12784 +/* SPDX-License-Identifier: GPL-2.0 */
12786 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12788 + * This program, aufs is free software; you can redistribute it and/or modify
12789 + * it under the terms of the GNU General Public License as published by
12790 + * the Free Software Foundation; either version 2 of the License, or
12791 + * (at your option) any later version.
12793 + * This program is distributed in the hope that it will be useful,
12794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12796 + * GNU General Public License for more details.
12798 + * You should have received a copy of the GNU General Public License
12799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12803 + * dynamically customizable operations (for regular files only)
12806 +#ifndef __AUFS_DYNOP_H__
12807 +#define __AUFS_DYNOP_H__
12811 +#include <linux/fs.h>
12812 +#include <linux/kref.h>
12814 +enum {AuDy_AOP, AuDyLast};
12819 + const void *dy_hop;
12820 + const struct address_space_operations *dy_haop;
12826 + struct hlist_bl_node dk_hnode;
12827 + struct rcu_head dk_rcu;
12829 + struct au_dynop dk_op;
12832 + * during I am in the branch local array, kref is gotten. when the
12833 + * branch is removed, kref is put.
12835 + struct kref dk_kref;
12838 +/* stop unioning since their sizes are very different from each other */
12840 + struct au_dykey da_key;
12841 + struct address_space_operations da_op; /* not const */
12843 +/* make sure that 'struct au_dykey *' can be any type */
12844 +static_assert(!offsetof(struct au_dyaop, da_key));
12846 +/* ---------------------------------------------------------------------- */
12850 +void au_dy_put(struct au_dykey *key);
12851 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12852 + struct inode *h_inode);
12853 +int au_dy_irefresh(struct inode *inode);
12854 +void au_dy_arefresh(int do_dio);
12856 +void __init au_dy_init(void);
12857 +void au_dy_fin(void);
12859 +#endif /* __KERNEL__ */
12860 +#endif /* __AUFS_DYNOP_H__ */
12861 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12862 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12863 +++ linux/fs/aufs/export.c 2020-01-27 10:57:18.168871450 +0100
12865 +// SPDX-License-Identifier: GPL-2.0
12867 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12869 + * This program, aufs is free software; you can redistribute it and/or modify
12870 + * it under the terms of the GNU General Public License as published by
12871 + * the Free Software Foundation; either version 2 of the License, or
12872 + * (at your option) any later version.
12874 + * This program is distributed in the hope that it will be useful,
12875 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12876 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12877 + * GNU General Public License for more details.
12879 + * You should have received a copy of the GNU General Public License
12880 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12887 +#include <linux/exportfs.h>
12888 +#include <linux/fs_struct.h>
12889 +#include <linux/namei.h>
12890 +#include <linux/nsproxy.h>
12891 +#include <linux/random.h>
12892 +#include <linux/writeback.h>
12896 +#ifdef CONFIG_AUFS_INO_T_64
12904 +static ino_t decode_ino(__u32 *a)
12908 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12910 +#ifdef CONFIG_AUFS_INO_T_64
12916 +static void encode_ino(__u32 *a, ino_t ino)
12922 +#ifdef CONFIG_AUFS_INO_T_64
12927 +/* NFS file handle */
12931 +#ifdef CONFIG_AUFS_INO_T_64
12932 + /* support 64bit inode number */
12945 + Fh_ino = Fh_ino1,
12946 + Fh_dir_ino = Fh_dir_ino1
12949 +static int au_test_anon(struct dentry *dentry)
12951 + /* note: read d_flags without d_lock */
12952 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12955 +int au_test_nfsd(void)
12958 + struct task_struct *tsk = current;
12959 + char comm[sizeof(tsk->comm)];
12962 + if (tsk->flags & PF_KTHREAD) {
12963 + get_task_comm(comm, tsk);
12964 + ret = !strcmp(comm, "nfsd");
12970 +/* ---------------------------------------------------------------------- */
12971 +/* inode generation external table */
12973 +void au_xigen_inc(struct inode *inode)
12978 + struct super_block *sb;
12979 + struct au_sbinfo *sbinfo;
12981 + sb = inode->i_sb;
12982 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12984 + sbinfo = au_sbi(sb);
12985 + pos = inode->i_ino;
12986 + pos *= sizeof(igen);
12987 + igen = inode->i_generation + 1;
12988 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12989 + sizeof(igen), &pos);
12990 + if (sz == sizeof(igen))
12991 + return; /* success */
12993 + if (unlikely(sz >= 0))
12994 + AuIOErr("xigen error (%zd)\n", sz);
12997 +int au_xigen_new(struct inode *inode)
13002 + struct super_block *sb;
13003 + struct au_sbinfo *sbinfo;
13004 + struct file *file;
13007 + /* todo: dirty, at mount time */
13008 + if (inode->i_ino == AUFS_ROOT_INO)
13010 + sb = inode->i_sb;
13011 + SiMustAnyLock(sb);
13012 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13016 + pos = inode->i_ino;
13017 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13018 + AuIOErr1("too large i%lld\n", pos);
13021 + pos *= sizeof(inode->i_generation);
13024 + sbinfo = au_sbi(sb);
13025 + file = sbinfo->si_xigen;
13028 + if (vfsub_f_size_read(file)
13029 + < pos + sizeof(inode->i_generation)) {
13030 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13031 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13032 + sizeof(inode->i_generation), &pos);
13034 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13035 + sizeof(inode->i_generation), &pos);
13036 + if (sz == sizeof(inode->i_generation))
13037 + goto out; /* success */
13040 + if (unlikely(sz >= 0)) {
13042 + AuIOErr("xigen error (%zd)\n", sz);
13049 +int au_xigen_set(struct super_block *sb, struct path *path)
13052 + struct au_sbinfo *sbinfo;
13053 + struct file *file;
13055 + SiMustWriteLock(sb);
13057 + sbinfo = au_sbi(sb);
13058 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13059 + err = PTR_ERR(file);
13060 + if (IS_ERR(file))
13063 + if (sbinfo->si_xigen)
13064 + fput(sbinfo->si_xigen);
13065 + sbinfo->si_xigen = file;
13072 +void au_xigen_clr(struct super_block *sb)
13074 + struct au_sbinfo *sbinfo;
13076 + SiMustWriteLock(sb);
13078 + sbinfo = au_sbi(sb);
13079 + if (sbinfo->si_xigen) {
13080 + fput(sbinfo->si_xigen);
13081 + sbinfo->si_xigen = NULL;
13085 +/* ---------------------------------------------------------------------- */
13087 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13090 + struct dentry *dentry, *d;
13091 + struct inode *inode;
13092 + unsigned int sigen;
13095 + inode = ilookup(sb, ino);
13099 + dentry = ERR_PTR(-ESTALE);
13100 + sigen = au_sigen(sb);
13101 + if (unlikely(au_is_bad_inode(inode)
13102 + || IS_DEADDIR(inode)
13103 + || sigen != au_iigen(inode, NULL)))
13107 + if (!dir_ino || S_ISDIR(inode->i_mode))
13108 + dentry = d_find_alias(inode);
13110 + spin_lock(&inode->i_lock);
13111 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13112 + spin_lock(&d->d_lock);
13113 + if (!au_test_anon(d)
13114 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13115 + dentry = dget_dlock(d);
13116 + spin_unlock(&d->d_lock);
13119 + spin_unlock(&d->d_lock);
13121 + spin_unlock(&inode->i_lock);
13123 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13124 + /* need to refresh */
13132 + AuTraceErrPtr(dentry);
13136 +/* ---------------------------------------------------------------------- */
13138 +/* todo: dirty? */
13139 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13141 +struct au_compare_mnt_args {
13143 + struct super_block *sb;
13146 + struct vfsmount *mnt;
13149 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13151 + struct au_compare_mnt_args *a = arg;
13153 + if (mnt->mnt_sb != a->sb)
13155 + a->mnt = mntget(mnt);
13159 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13162 + struct path root;
13163 + struct au_compare_mnt_args args = {
13167 + get_fs_root(current->fs, &root);
13169 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13170 + rcu_read_unlock();
13173 + AuDebugOn(!args.mnt);
13177 +struct au_nfsd_si_lock {
13178 + unsigned int sigen;
13179 + aufs_bindex_t bindex, br_id;
13180 + unsigned char force_lock;
13183 +static int si_nfsd_read_lock(struct super_block *sb,
13184 + struct au_nfsd_si_lock *nsi_lock)
13187 + aufs_bindex_t bindex;
13189 + si_read_lock(sb, AuLock_FLUSH);
13191 + /* branch id may be wrapped around */
13193 + bindex = au_br_index(sb, nsi_lock->br_id);
13194 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13195 + goto out; /* success */
13199 + if (!nsi_lock->force_lock)
13200 + si_read_unlock(sb);
13203 + nsi_lock->bindex = bindex;
13207 +struct find_name_by_ino {
13208 + struct dir_context ctx;
13209 + int called, found;
13216 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13217 + loff_t offset, u64 ino, unsigned int d_type)
13219 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13223 + if (a->ino != ino)
13226 + memcpy(a->name, name, namelen);
13227 + a->namelen = namelen;
13232 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13233 + struct au_nfsd_si_lock *nsi_lock)
13235 + struct dentry *dentry, *parent;
13236 + struct file *file;
13237 + struct inode *dir;
13238 + struct find_name_by_ino arg = {
13240 + .actor = find_name_by_ino
13245 + parent = path->dentry;
13247 + si_read_unlock(parent->d_sb);
13248 + file = vfsub_dentry_open(path, au_dir_roflags);
13249 + dentry = (void *)file;
13250 + if (IS_ERR(file))
13253 + dentry = ERR_PTR(-ENOMEM);
13254 + arg.name = (void *)__get_free_page(GFP_NOFS);
13255 + if (unlikely(!arg.name))
13262 + err = vfsub_iterate_dir(file, &arg.ctx);
13263 + } while (!err && !arg.found && arg.called);
13264 + dentry = ERR_PTR(err);
13265 + if (unlikely(err))
13267 + /* instead of ENOENT */
13268 + dentry = ERR_PTR(-ESTALE);
13272 + /* do not call vfsub_lkup_one() */
13273 + dir = d_inode(parent);
13274 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13275 + AuTraceErrPtr(dentry);
13276 + if (IS_ERR(dentry))
13278 + AuDebugOn(au_test_anon(dentry));
13279 + if (unlikely(d_really_is_negative(dentry))) {
13281 + dentry = ERR_PTR(-ENOENT);
13285 + free_page((unsigned long)arg.name);
13289 + if (unlikely(nsi_lock
13290 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13291 + if (!IS_ERR(dentry)) {
13293 + dentry = ERR_PTR(-ESTALE);
13295 + AuTraceErrPtr(dentry);
13299 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13301 + struct au_nfsd_si_lock *nsi_lock)
13303 + struct dentry *dentry;
13304 + struct path path;
13306 + if (dir_ino != AUFS_ROOT_INO) {
13307 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13308 + dentry = path.dentry;
13309 + if (!path.dentry || IS_ERR(path.dentry))
13311 + AuDebugOn(au_test_anon(path.dentry));
13313 + path.dentry = dget(sb->s_root);
13315 + path.mnt = au_mnt_get(sb);
13316 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13320 + AuTraceErrPtr(dentry);
13324 +/* ---------------------------------------------------------------------- */
13326 +static int h_acceptable(void *expv, struct dentry *dentry)
13331 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13332 + char *buf, int len, struct super_block *sb)
13336 + struct path path;
13338 + p = d_path(h_rootpath, buf, len);
13343 + path.mnt = h_rootpath->mnt;
13344 + path.dentry = h_parent;
13345 + p = d_path(&path, buf, len);
13351 + path.mnt = au_mnt_get(sb);
13352 + path.dentry = sb->s_root;
13353 + p = d_path(&path, buf, len - strlen(p));
13354 + mntput(path.mnt);
13358 + p[strlen(p)] = '/';
13361 + AuTraceErrPtr(p);
13366 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13367 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13369 + struct dentry *dentry, *h_parent, *root;
13370 + struct super_block *h_sb;
13371 + char *pathname, *p;
13372 + struct vfsmount *h_mnt;
13373 + struct au_branch *br;
13375 + struct path path;
13377 + br = au_sbr(sb, nsi_lock->bindex);
13378 + h_mnt = au_br_mnt(br);
13379 + h_sb = h_mnt->mnt_sb;
13380 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13382 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13383 + fh_len - Fh_tail, fh[Fh_h_type],
13384 + h_acceptable, /*context*/NULL);
13386 + dentry = h_parent;
13387 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13388 + AuWarn1("%s decode_fh failed, %ld\n",
13389 + au_sbtype(h_sb), PTR_ERR(h_parent));
13393 + if (unlikely(au_test_anon(h_parent))) {
13394 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13395 + au_sbtype(h_sb));
13396 + goto out_h_parent;
13399 + dentry = ERR_PTR(-ENOMEM);
13400 + pathname = (void *)__get_free_page(GFP_NOFS);
13401 + if (unlikely(!pathname))
13402 + goto out_h_parent;
13404 + root = sb->s_root;
13405 + path.mnt = h_mnt;
13406 + di_read_lock_parent(root, !AuLock_IR);
13407 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13408 + di_read_unlock(root, !AuLock_IR);
13409 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13410 + dentry = (void *)p;
13412 + goto out_pathname;
13414 + si_read_unlock(sb);
13415 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13416 + dentry = ERR_PTR(err);
13417 + if (unlikely(err))
13420 + dentry = ERR_PTR(-ENOENT);
13421 + AuDebugOn(au_test_anon(path.dentry));
13422 + if (unlikely(d_really_is_negative(path.dentry)))
13425 + if (ino != d_inode(path.dentry)->i_ino)
13426 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13428 + dentry = dget(path.dentry);
13433 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13434 + if (!IS_ERR(dentry)) {
13436 + dentry = ERR_PTR(-ESTALE);
13439 + free_page((unsigned long)pathname);
13443 + AuTraceErrPtr(dentry);
13447 +/* ---------------------------------------------------------------------- */
13449 +static struct dentry *
13450 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13453 + struct dentry *dentry;
13454 + __u32 *fh = fid->raw;
13455 + struct au_branch *br;
13456 + ino_t ino, dir_ino;
13457 + struct au_nfsd_si_lock nsi_lock = {
13461 + dentry = ERR_PTR(-ESTALE);
13462 + /* it should never happen, but the file handle is unreliable */
13463 + if (unlikely(fh_len < Fh_tail))
13465 + nsi_lock.sigen = fh[Fh_sigen];
13466 + nsi_lock.br_id = fh[Fh_br_id];
13468 + /* branch id may be wrapped around */
13470 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13472 + nsi_lock.force_lock = 1;
13474 + /* is this inode still cached? */
13475 + ino = decode_ino(fh + Fh_ino);
13476 + /* it should never happen */
13477 + if (unlikely(ino == AUFS_ROOT_INO))
13480 + dir_ino = decode_ino(fh + Fh_dir_ino);
13481 + dentry = decode_by_ino(sb, ino, dir_ino);
13482 + if (IS_ERR(dentry))
13487 + /* is the parent dir cached? */
13488 + br = au_sbr(sb, nsi_lock.bindex);
13489 + au_lcnt_inc(&br->br_nfiles);
13490 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13491 + if (IS_ERR(dentry))
13496 + /* lookup path */
13497 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13498 + if (IS_ERR(dentry))
13500 + if (unlikely(!dentry))
13501 + /* todo?: make it ESTALE */
13505 + if (!au_digen_test(dentry, au_sigen(sb))
13506 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13507 + goto out_unlock; /* success */
13510 + dentry = ERR_PTR(-ESTALE);
13513 + au_lcnt_dec(&br->br_nfiles);
13514 + si_read_unlock(sb);
13516 + AuTraceErrPtr(dentry);
13520 +#if 0 /* reserved for future use */
13521 +/* support subtreecheck option */
13522 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13523 + int fh_len, int fh_type)
13525 + struct dentry *parent;
13526 + __u32 *fh = fid->raw;
13529 + dir_ino = decode_ino(fh + Fh_dir_ino);
13530 + parent = decode_by_ino(sb, dir_ino, 0);
13531 + if (IS_ERR(parent))
13534 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13535 + dir_ino, fh, fh_len);
13538 + AuTraceErrPtr(parent);
13543 +/* ---------------------------------------------------------------------- */
13545 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13546 + struct inode *dir)
13549 + aufs_bindex_t bindex;
13550 + struct super_block *sb, *h_sb;
13551 + struct dentry *dentry, *parent, *h_parent;
13552 + struct inode *h_dir;
13553 + struct au_branch *br;
13556 + if (unlikely(*max_len <= Fh_tail)) {
13557 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13561 + err = FILEID_ROOT;
13562 + if (inode->i_ino == AUFS_ROOT_INO) {
13563 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13568 + sb = inode->i_sb;
13569 + err = si_read_lock(sb, AuLock_FLUSH);
13570 + if (unlikely(err))
13573 +#ifdef CONFIG_AUFS_DEBUG
13574 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13575 + AuWarn1("NFS-exporting requires xino\n");
13579 + ii_read_lock_child(inode);
13580 + bindex = au_ibtop(inode);
13582 + dentry = d_find_any_alias(inode);
13583 + if (unlikely(!dentry))
13585 + AuDebugOn(au_test_anon(dentry));
13586 + parent = dget_parent(dentry);
13588 + if (unlikely(!parent))
13590 + if (d_really_is_positive(parent))
13591 + dir = d_inode(parent);
13594 + ii_read_lock_parent(dir);
13595 + h_dir = au_h_iptr(dir, bindex);
13596 + ii_read_unlock(dir);
13597 + if (unlikely(!h_dir))
13599 + h_parent = d_find_any_alias(h_dir);
13600 + if (unlikely(!h_parent))
13601 + goto out_hparent;
13604 + br = au_sbr(sb, bindex);
13605 + h_sb = au_br_sb(br);
13606 + if (unlikely(!h_sb->s_export_op)) {
13607 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13608 + goto out_hparent;
13611 + fh[Fh_br_id] = br->br_id;
13612 + fh[Fh_sigen] = au_sigen(sb);
13613 + encode_ino(fh + Fh_ino, inode->i_ino);
13614 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13615 + fh[Fh_igen] = inode->i_generation;
13617 + *max_len -= Fh_tail;
13618 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13620 + /*connectable or subtreecheck*/0);
13621 + err = fh[Fh_h_type];
13622 + *max_len += Fh_tail;
13623 + /* todo: macros? */
13624 + if (err != FILEID_INVALID)
13627 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13634 + ii_read_unlock(inode);
13635 + si_read_unlock(sb);
13637 + if (unlikely(err < 0))
13638 + err = FILEID_INVALID;
13642 +/* ---------------------------------------------------------------------- */
13644 +static int aufs_commit_metadata(struct inode *inode)
13647 + aufs_bindex_t bindex;
13648 + struct super_block *sb;
13649 + struct inode *h_inode;
13650 + int (*f)(struct inode *inode);
13652 + sb = inode->i_sb;
13653 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13654 + ii_write_lock_child(inode);
13655 + bindex = au_ibtop(inode);
13656 + AuDebugOn(bindex < 0);
13657 + h_inode = au_h_iptr(inode, bindex);
13659 + f = h_inode->i_sb->s_export_op->commit_metadata;
13661 + err = f(h_inode);
13663 + struct writeback_control wbc = {
13664 + .sync_mode = WB_SYNC_ALL,
13665 + .nr_to_write = 0 /* metadata only */
13668 + err = sync_inode(h_inode, &wbc);
13671 + au_cpup_attr_timesizes(inode);
13672 + ii_write_unlock(inode);
13673 + si_read_unlock(sb);
13677 +/* ---------------------------------------------------------------------- */
13679 +static struct export_operations aufs_export_op = {
13680 + .fh_to_dentry = aufs_fh_to_dentry,
13681 + /* .fh_to_parent = aufs_fh_to_parent, */
13682 + .encode_fh = aufs_encode_fh,
13683 + .commit_metadata = aufs_commit_metadata
13686 +void au_export_init(struct super_block *sb)
13688 + struct au_sbinfo *sbinfo;
13691 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13692 + && IS_MODULE(CONFIG_EXPORTFS),
13693 + AUFS_NAME ": unsupported configuration "
13694 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13696 + sb->s_export_op = &aufs_export_op;
13697 + sbinfo = au_sbi(sb);
13698 + sbinfo->si_xigen = NULL;
13699 + get_random_bytes(&u, sizeof(u));
13700 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13701 + atomic_set(&sbinfo->si_xigen_next, u);
13703 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13704 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13705 +++ linux/fs/aufs/fhsm.c 2020-01-27 10:57:18.172204883 +0100
13707 +// SPDX-License-Identifier: GPL-2.0
13709 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13711 + * This program, aufs is free software; you can redistribute it and/or modify
13712 + * it under the terms of the GNU General Public License as published by
13713 + * the Free Software Foundation; either version 2 of the License, or
13714 + * (at your option) any later version.
13716 + * This program is distributed in the hope that it will be useful,
13717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13719 + * GNU General Public License for more details.
13721 + * You should have received a copy of the GNU General Public License
13722 + * along with this program; if not, write to the Free Software
13723 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13727 + * File-based Hierarchy Storage Management
13730 +#include <linux/anon_inodes.h>
13731 +#include <linux/poll.h>
13732 +#include <linux/seq_file.h>
13733 +#include <linux/statfs.h>
13736 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13738 + struct au_sbinfo *sbinfo;
13739 + struct au_fhsm *fhsm;
13741 + SiMustAnyLock(sb);
13743 + sbinfo = au_sbi(sb);
13744 + fhsm = &sbinfo->si_fhsm;
13745 + AuDebugOn(!fhsm);
13746 + return fhsm->fhsm_bottom;
13749 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13751 + struct au_sbinfo *sbinfo;
13752 + struct au_fhsm *fhsm;
13754 + SiMustWriteLock(sb);
13756 + sbinfo = au_sbi(sb);
13757 + fhsm = &sbinfo->si_fhsm;
13758 + AuDebugOn(!fhsm);
13759 + fhsm->fhsm_bottom = bindex;
13762 +/* ---------------------------------------------------------------------- */
13764 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13766 + struct au_br_fhsm *bf;
13768 + bf = br->br_fhsm;
13769 + MtxMustLock(&bf->bf_lock);
13771 + return !bf->bf_readable
13772 + || time_after(jiffies,
13773 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13776 +/* ---------------------------------------------------------------------- */
13778 +static void au_fhsm_notify(struct super_block *sb, int val)
13780 + struct au_sbinfo *sbinfo;
13781 + struct au_fhsm *fhsm;
13783 + SiMustAnyLock(sb);
13785 + sbinfo = au_sbi(sb);
13786 + fhsm = &sbinfo->si_fhsm;
13787 + if (au_fhsm_pid(fhsm)
13788 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13789 + atomic_set(&fhsm->fhsm_readable, val);
13791 + wake_up(&fhsm->fhsm_wqh);
13795 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13796 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13799 + struct au_branch *br;
13800 + struct au_br_fhsm *bf;
13802 + br = au_sbr(sb, bindex);
13803 + AuDebugOn(au_br_rdonly(br));
13804 + bf = br->br_fhsm;
13808 + mutex_lock(&bf->bf_lock);
13810 + MtxMustLock(&bf->bf_lock);
13812 + /* sb->s_root for NFS is unreliable */
13813 + err = au_br_stfs(br, &bf->bf_stfs);
13814 + if (unlikely(err)) {
13815 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13819 + bf->bf_jiffy = jiffies;
13820 + bf->bf_readable = 1;
13822 + au_fhsm_notify(sb, /*val*/1);
13824 + *rstfs = bf->bf_stfs;
13828 + mutex_unlock(&bf->bf_lock);
13829 + au_fhsm_notify(sb, /*val*/1);
13834 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13837 + struct au_sbinfo *sbinfo;
13838 + struct au_fhsm *fhsm;
13839 + struct au_branch *br;
13840 + struct au_br_fhsm *bf;
13842 + AuDbg("b%d, force %d\n", bindex, force);
13843 + SiMustAnyLock(sb);
13845 + sbinfo = au_sbi(sb);
13846 + fhsm = &sbinfo->si_fhsm;
13847 + if (!au_ftest_si(sbinfo, FHSM)
13848 + || fhsm->fhsm_bottom == bindex)
13851 + br = au_sbr(sb, bindex);
13852 + bf = br->br_fhsm;
13854 + mutex_lock(&bf->bf_lock);
13856 + || au_fhsm_pid(fhsm)
13857 + || au_fhsm_test_jiffy(sbinfo, br))
13858 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13860 + mutex_unlock(&bf->bf_lock);
13863 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13865 + aufs_bindex_t bindex, bbot;
13866 + struct au_branch *br;
13868 + /* exclude the bottom */
13869 + bbot = au_fhsm_bottom(sb);
13870 + for (bindex = 0; bindex < bbot; bindex++) {
13871 + br = au_sbr(sb, bindex);
13872 + if (au_br_fhsm(br->br_perm))
13873 + au_fhsm_wrote(sb, bindex, force);
13877 +/* ---------------------------------------------------------------------- */
13879 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13882 + struct au_sbinfo *sbinfo;
13883 + struct au_fhsm *fhsm;
13886 + sbinfo = file->private_data;
13887 + fhsm = &sbinfo->si_fhsm;
13888 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13889 + if (atomic_read(&fhsm->fhsm_readable))
13890 + mask = EPOLLIN /* | EPOLLRDNORM */;
13893 + AuDbg("mask 0x%x\n", mask);
13897 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13898 + struct aufs_stfs *stfs, __s16 brid)
13902 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13904 + err = __put_user(brid, &stbr->brid);
13905 + if (unlikely(err))
13911 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13912 + struct aufs_stbr __user *stbr, size_t count)
13916 + aufs_bindex_t bindex, bbot;
13917 + struct au_branch *br;
13918 + struct au_br_fhsm *bf;
13920 + /* except the bottom branch */
13923 + bbot = au_fhsm_bottom(sb);
13924 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13925 + br = au_sbr(sb, bindex);
13926 + if (!au_br_fhsm(br->br_perm))
13929 + bf = br->br_fhsm;
13930 + mutex_lock(&bf->bf_lock);
13931 + if (bf->bf_readable) {
13933 + if (count >= sizeof(*stbr))
13934 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13937 + bf->bf_readable = 0;
13938 + count -= sizeof(*stbr);
13942 + mutex_unlock(&bf->bf_lock);
13945 + err = sizeof(*stbr) * nstbr;
13950 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13955 + aufs_bindex_t nfhsm, bindex, bbot;
13956 + struct au_sbinfo *sbinfo;
13957 + struct au_fhsm *fhsm;
13958 + struct au_branch *br;
13959 + struct super_block *sb;
13962 + sbinfo = file->private_data;
13963 + fhsm = &sbinfo->si_fhsm;
13965 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13966 + if (!atomic_read(&fhsm->fhsm_readable)) {
13967 + if (vfsub_file_flags(file) & O_NONBLOCK)
13970 + err = wait_event_interruptible_locked_irq
13972 + atomic_read(&fhsm->fhsm_readable));
13974 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13975 + if (unlikely(err))
13978 + /* sb may already be dead */
13979 + au_rw_read_lock(&sbinfo->si_rwsem);
13980 + readable = atomic_read(&fhsm->fhsm_readable);
13981 + if (readable > 0) {
13982 + sb = sbinfo->si_sb;
13984 + /* exclude the bottom branch */
13986 + bbot = au_fhsm_bottom(sb);
13987 + for (bindex = 0; bindex < bbot; bindex++) {
13988 + br = au_sbr(sb, bindex);
13989 + if (au_br_fhsm(br->br_perm))
13993 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13994 + atomic_set(&fhsm->fhsm_readable, 0);
13995 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13999 + au_rw_read_unlock(&sbinfo->si_rwsem);
14007 +static int au_fhsm_release(struct inode *inode, struct file *file)
14009 + struct au_sbinfo *sbinfo;
14010 + struct au_fhsm *fhsm;
14012 + /* sb may already be dead */
14013 + sbinfo = file->private_data;
14014 + fhsm = &sbinfo->si_fhsm;
14015 + spin_lock(&fhsm->fhsm_spin);
14016 + fhsm->fhsm_pid = 0;
14017 + spin_unlock(&fhsm->fhsm_spin);
14018 + kobject_put(&sbinfo->si_kobj);
14023 +static const struct file_operations au_fhsm_fops = {
14024 + .owner = THIS_MODULE,
14025 + .llseek = noop_llseek,
14026 + .read = au_fhsm_read,
14027 + .poll = au_fhsm_poll,
14028 + .release = au_fhsm_release
14031 +int au_fhsm_fd(struct super_block *sb, int oflags)
14034 + struct au_sbinfo *sbinfo;
14035 + struct au_fhsm *fhsm;
14038 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14042 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14046 + sbinfo = au_sbi(sb);
14047 + fhsm = &sbinfo->si_fhsm;
14048 + spin_lock(&fhsm->fhsm_spin);
14049 + if (!fhsm->fhsm_pid)
14050 + fhsm->fhsm_pid = current->pid;
14053 + spin_unlock(&fhsm->fhsm_spin);
14054 + if (unlikely(err))
14057 + oflags |= O_RDONLY;
14058 + /* oflags |= FMODE_NONOTIFY; */
14059 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14061 + if (unlikely(fd < 0))
14064 + /* succeed regardless 'fhsm' status */
14065 + kobject_get(&sbinfo->si_kobj);
14066 + si_noflush_read_lock(sb);
14067 + if (au_ftest_si(sbinfo, FHSM))
14068 + au_fhsm_wrote_all(sb, /*force*/0);
14069 + si_read_unlock(sb);
14070 + goto out; /* success */
14073 + spin_lock(&fhsm->fhsm_spin);
14074 + fhsm->fhsm_pid = 0;
14075 + spin_unlock(&fhsm->fhsm_spin);
14081 +/* ---------------------------------------------------------------------- */
14083 +int au_fhsm_br_alloc(struct au_branch *br)
14088 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14090 + au_br_fhsm_init(br->br_fhsm);
14097 +/* ---------------------------------------------------------------------- */
14099 +void au_fhsm_fin(struct super_block *sb)
14101 + au_fhsm_notify(sb, /*val*/-1);
14104 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14106 + struct au_fhsm *fhsm;
14108 + fhsm = &sbinfo->si_fhsm;
14109 + spin_lock_init(&fhsm->fhsm_spin);
14110 + init_waitqueue_head(&fhsm->fhsm_wqh);
14111 + atomic_set(&fhsm->fhsm_readable, 0);
14112 + fhsm->fhsm_expire
14113 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14114 + fhsm->fhsm_bottom = -1;
14117 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14119 + sbinfo->si_fhsm.fhsm_expire
14120 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14123 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14127 + if (!au_ftest_si(sbinfo, FHSM))
14130 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14131 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14132 + seq_printf(seq, ",fhsm_sec=%u", u);
14134 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14135 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14136 +++ linux/fs/aufs/file.c 2020-01-27 10:57:18.172204883 +0100
14138 +// SPDX-License-Identifier: GPL-2.0
14140 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14142 + * This program, aufs is free software; you can redistribute it and/or modify
14143 + * it under the terms of the GNU General Public License as published by
14144 + * the Free Software Foundation; either version 2 of the License, or
14145 + * (at your option) any later version.
14147 + * This program is distributed in the hope that it will be useful,
14148 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14149 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14150 + * GNU General Public License for more details.
14152 + * You should have received a copy of the GNU General Public License
14153 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14157 + * handling file/dir, and address_space operation
14160 +#ifdef CONFIG_AUFS_DEBUG
14161 +#include <linux/migrate.h>
14163 +#include <linux/pagemap.h>
14166 +/* drop flags for writing */
14167 +unsigned int au_file_roflags(unsigned int flags)
14169 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14170 + flags |= O_RDONLY | O_NOATIME;
14174 +/* common functions to regular file and dir */
14175 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14176 + struct file *file, int force_wr)
14178 + struct file *h_file;
14179 + struct dentry *h_dentry;
14180 + struct inode *h_inode;
14181 + struct super_block *sb;
14182 + struct au_branch *br;
14183 + struct path h_path;
14186 + /* a race condition can happen between open and unlink/rmdir */
14187 + h_file = ERR_PTR(-ENOENT);
14188 + h_dentry = au_h_dptr(dentry, bindex);
14189 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14191 + h_inode = d_inode(h_dentry);
14192 + spin_lock(&h_dentry->d_lock);
14193 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14194 + /* || !d_inode(dentry)->i_nlink */
14196 + spin_unlock(&h_dentry->d_lock);
14197 + if (unlikely(err))
14200 + sb = dentry->d_sb;
14201 + br = au_sbr(sb, bindex);
14202 + err = au_br_test_oflag(flags, br);
14203 + h_file = ERR_PTR(err);
14204 + if (unlikely(err))
14207 + /* drop flags for writing */
14208 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14209 + if (force_wr && !(flags & O_WRONLY))
14211 + flags = au_file_roflags(flags);
14213 + h_file = ERR_PTR(-EROFS);
14214 + flags = au_file_roflags(flags);
14215 + if (unlikely(vfsub_native_ro(h_inode)
14216 + || IS_APPEND(h_inode)))
14218 + flags &= ~O_ACCMODE;
14219 + flags |= O_WRONLY;
14222 + flags &= ~O_CREAT;
14223 + au_lcnt_inc(&br->br_nfiles);
14224 + h_path.dentry = h_dentry;
14225 + h_path.mnt = au_br_mnt(br);
14226 + h_file = vfsub_dentry_open(&h_path, flags);
14227 + if (IS_ERR(h_file))
14230 + if (flags & __FMODE_EXEC) {
14231 + err = deny_write_access(h_file);
14232 + if (unlikely(err)) {
14234 + h_file = ERR_PTR(err);
14238 + fsnotify_open(h_file);
14239 + goto out; /* success */
14242 + au_lcnt_dec(&br->br_nfiles);
14247 +static int au_cmoo(struct dentry *dentry)
14249 + int err, cmoo, matched;
14250 + unsigned int udba;
14251 + struct path h_path;
14252 + struct au_pin pin;
14253 + struct au_cp_generic cpg = {
14254 + .dentry = dentry,
14259 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14261 + struct inode *delegated;
14262 + struct super_block *sb;
14263 + struct au_sbinfo *sbinfo;
14264 + struct au_fhsm *fhsm;
14266 + struct au_branch *br;
14267 + struct dentry *parent;
14268 + struct au_hinode *hdir;
14270 + DiMustWriteLock(dentry);
14271 + IiMustWriteLock(d_inode(dentry));
14274 + if (IS_ROOT(dentry))
14276 + cpg.bsrc = au_dbtop(dentry);
14280 + sb = dentry->d_sb;
14281 + sbinfo = au_sbi(sb);
14282 + fhsm = &sbinfo->si_fhsm;
14283 + pid = au_fhsm_pid(fhsm);
14286 + && (current->pid == pid
14287 + || rcu_dereference(current->real_parent)->pid == pid));
14288 + rcu_read_unlock();
14292 + br = au_sbr(sb, cpg.bsrc);
14293 + cmoo = au_br_cmoo(br->br_perm);
14296 + if (!d_is_reg(dentry))
14297 + cmoo &= AuBrAttr_COO_ALL;
14301 + parent = dget_parent(dentry);
14302 + di_write_lock_parent(parent);
14303 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14305 + if (unlikely(err < 0)) {
14306 + err = 0; /* there is no upper writable branch */
14309 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14311 + /* do not respect the coo attrib for the target branch */
14312 + err = au_cpup_dirs(dentry, cpg.bdst);
14313 + if (unlikely(err))
14316 + di_downgrade_lock(parent, AuLock_IR);
14317 + udba = au_opt_udba(sb);
14318 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14319 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14320 + if (unlikely(err))
14323 + err = au_sio_cpup_simple(&cpg);
14325 + if (unlikely(err))
14327 + if (!(cmoo & AuBrWAttr_MOO))
14328 + goto out_parent; /* success */
14330 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14331 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14332 + if (unlikely(err))
14335 + h_path.mnt = au_br_mnt(br);
14336 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14337 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14338 + delegated = NULL;
14339 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14341 + /* todo: keep h_dentry or not? */
14342 + if (unlikely(err == -EWOULDBLOCK)) {
14343 + pr_warn("cannot retry for NFSv4 delegation"
14344 + " for an internal unlink\n");
14347 + if (unlikely(err)) {
14348 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14352 + goto out_parent; /* success */
14355 + di_downgrade_lock(parent, AuLock_IR);
14357 + di_read_unlock(parent, AuLock_IR);
14364 +int au_do_open(struct file *file, struct au_do_open_args *args)
14366 + int err, aopen = args->aopen;
14367 + struct dentry *dentry;
14368 + struct au_finfo *finfo;
14371 + err = au_finfo_init(file, args->fidir);
14374 + err = au_finfo_init(file, args->fidir);
14377 + if (unlikely(err))
14380 + dentry = file->f_path.dentry;
14381 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14382 + di_write_lock_child(dentry);
14383 + err = au_cmoo(dentry);
14384 + di_downgrade_lock(dentry, AuLock_IR);
14387 + err = args->open(file, vfsub_file_flags(file), NULL);
14390 + err = args->open(file, vfsub_file_flags(file),
14395 + di_read_unlock(dentry, AuLock_IR);
14397 + finfo = au_fi(file);
14399 + finfo->fi_file = file;
14400 + au_hbl_add(&finfo->fi_hlist,
14401 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14404 + fi_write_unlock(file);
14407 + fi_write_unlock(file);
14410 + if (unlikely(err)) {
14411 + finfo->fi_hdir = NULL;
14412 + au_finfo_fin(file);
14420 +int au_reopen_nondir(struct file *file)
14423 + aufs_bindex_t btop;
14424 + struct dentry *dentry;
14425 + struct au_branch *br;
14426 + struct file *h_file, *h_file_tmp;
14428 + dentry = file->f_path.dentry;
14429 + btop = au_dbtop(dentry);
14430 + br = au_sbr(dentry->d_sb, btop);
14431 + h_file_tmp = NULL;
14432 + if (au_fbtop(file) == btop) {
14433 + h_file = au_hf_top(file);
14434 + if (file->f_mode == h_file->f_mode)
14435 + return 0; /* success */
14436 + h_file_tmp = h_file;
14437 + get_file(h_file_tmp);
14438 + au_lcnt_inc(&br->br_nfiles);
14439 + au_set_h_fptr(file, btop, NULL);
14441 + AuDebugOn(au_fi(file)->fi_hdir);
14444 + * file exists on both of rw and ro
14445 + * open --> dbtop and fbtop are both 0
14446 + * prepend a branch as rw, "rw" become ro
14448 + * delete the top branch, "rw" becomes rw again
14449 + * --> dbtop is 1, fbtop is still 0
14450 + * write --> fbtop is 0 but dbtop is 1
14452 + /* AuDebugOn(au_fbtop(file) < btop); */
14454 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14455 + file, /*force_wr*/0);
14456 + err = PTR_ERR(h_file);
14457 + if (IS_ERR(h_file)) {
14458 + if (h_file_tmp) {
14460 + au_set_h_fptr(file, btop, h_file_tmp);
14461 + h_file_tmp = NULL;
14463 + goto out; /* todo: close all? */
14467 + au_set_fbtop(file, btop);
14468 + au_set_h_fptr(file, btop, h_file);
14469 + au_update_figen(file);
14470 + /* todo: necessary? */
14471 + /* file->f_ra = h_file->f_ra; */
14474 + if (h_file_tmp) {
14475 + fput(h_file_tmp);
14476 + au_lcnt_dec(&br->br_nfiles);
14481 +/* ---------------------------------------------------------------------- */
14483 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14484 + struct dentry *hi_wh)
14487 + aufs_bindex_t btop;
14488 + struct au_dinfo *dinfo;
14489 + struct dentry *h_dentry;
14490 + struct au_hdentry *hdp;
14492 + dinfo = au_di(file->f_path.dentry);
14493 + AuRwMustWriteLock(&dinfo->di_rwsem);
14495 + btop = dinfo->di_btop;
14496 + dinfo->di_btop = btgt;
14497 + hdp = au_hdentry(dinfo, btgt);
14498 + h_dentry = hdp->hd_dentry;
14499 + hdp->hd_dentry = hi_wh;
14500 + err = au_reopen_nondir(file);
14501 + hdp->hd_dentry = h_dentry;
14502 + dinfo->di_btop = btop;
14507 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14508 + aufs_bindex_t bcpup, struct au_pin *pin)
14511 + struct inode *inode, *h_inode;
14512 + struct dentry *h_dentry, *hi_wh;
14513 + struct au_cp_generic cpg = {
14514 + .dentry = file->f_path.dentry,
14521 + au_update_dbtop(cpg.dentry);
14522 + inode = d_inode(cpg.dentry);
14524 + if (au_dbtop(cpg.dentry) <= bcpup
14525 + && au_dbbot(cpg.dentry) >= bcpup) {
14526 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14527 + if (h_dentry && d_is_positive(h_dentry))
14528 + h_inode = d_inode(h_dentry);
14530 + hi_wh = au_hi_wh(inode, bcpup);
14531 + if (!hi_wh && !h_inode)
14532 + err = au_sio_cpup_wh(&cpg, file);
14534 + /* already copied-up after unlink */
14535 + err = au_reopen_wh(file, bcpup, hi_wh);
14538 + && (inode->i_nlink > 1
14539 + || (inode->i_state & I_LINKABLE))
14540 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14541 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14547 + * prepare the @file for writing.
14549 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14552 + aufs_bindex_t dbtop;
14553 + struct dentry *parent;
14554 + struct inode *inode;
14555 + struct super_block *sb;
14556 + struct file *h_file;
14557 + struct au_cp_generic cpg = {
14558 + .dentry = file->f_path.dentry,
14563 + .flags = AuCpup_DTIME
14566 + sb = cpg.dentry->d_sb;
14567 + inode = d_inode(cpg.dentry);
14568 + cpg.bsrc = au_fbtop(file);
14569 + err = au_test_ro(sb, cpg.bsrc, inode);
14570 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14571 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14576 + /* need to cpup or reopen */
14577 + parent = dget_parent(cpg.dentry);
14578 + di_write_lock_parent(parent);
14579 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14581 + if (unlikely(err < 0))
14585 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14586 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14587 + if (unlikely(err))
14591 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14592 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14593 + if (unlikely(err))
14596 + dbtop = au_dbtop(cpg.dentry);
14597 + if (dbtop <= cpg.bdst)
14598 + cpg.bsrc = cpg.bdst;
14600 + if (dbtop <= cpg.bdst /* just reopen */
14601 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14603 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14604 + if (IS_ERR(h_file))
14605 + err = PTR_ERR(h_file);
14607 + di_downgrade_lock(parent, AuLock_IR);
14608 + if (dbtop > cpg.bdst)
14609 + err = au_sio_cpup_simple(&cpg);
14611 + err = au_reopen_nondir(file);
14612 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14614 + } else { /* copyup as wh and reopen */
14616 + * since writable hfsplus branch is not supported,
14617 + * h_open_pre/post() are unnecessary.
14619 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14620 + di_downgrade_lock(parent, AuLock_IR);
14624 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14625 + goto out_dput; /* success */
14631 + di_downgrade_lock(parent, AuLock_IR);
14633 + di_read_unlock(parent, AuLock_IR);
14640 +/* ---------------------------------------------------------------------- */
14642 +int au_do_flush(struct file *file, fl_owner_t id,
14643 + int (*flush)(struct file *file, fl_owner_t id))
14646 + struct super_block *sb;
14647 + struct inode *inode;
14649 + inode = file_inode(file);
14650 + sb = inode->i_sb;
14651 + si_noflush_read_lock(sb);
14652 + fi_read_lock(file);
14653 + ii_read_lock_child(inode);
14655 + err = flush(file, id);
14656 + au_cpup_attr_timesizes(inode);
14658 + ii_read_unlock(inode);
14659 + fi_read_unlock(file);
14660 + si_read_unlock(sb);
14664 +/* ---------------------------------------------------------------------- */
14666 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14669 + struct au_pin pin;
14670 + struct au_finfo *finfo;
14671 + struct dentry *parent, *hi_wh;
14672 + struct inode *inode;
14673 + struct super_block *sb;
14674 + struct au_cp_generic cpg = {
14675 + .dentry = file->f_path.dentry,
14680 + .flags = AuCpup_DTIME
14683 + FiMustWriteLock(file);
14686 + finfo = au_fi(file);
14687 + sb = cpg.dentry->d_sb;
14688 + inode = d_inode(cpg.dentry);
14689 + cpg.bdst = au_ibtop(inode);
14690 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14693 + parent = dget_parent(cpg.dentry);
14694 + if (au_test_ro(sb, cpg.bdst, inode)) {
14695 + di_read_lock_parent(parent, !AuLock_IR);
14696 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14698 + di_read_unlock(parent, !AuLock_IR);
14699 + if (unlikely(err < 0))
14704 + di_read_lock_parent(parent, AuLock_IR);
14705 + hi_wh = au_hi_wh(inode, cpg.bdst);
14706 + if (!S_ISDIR(inode->i_mode)
14707 + && au_opt_test(au_mntflags(sb), PLINK)
14708 + && au_plink_test(inode)
14709 + && !d_unhashed(cpg.dentry)
14710 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14711 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14712 + if (unlikely(err))
14715 + /* always superio. */
14716 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14717 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14719 + err = au_sio_cpup_simple(&cpg);
14722 + } else if (hi_wh) {
14723 + /* already copied-up after unlink */
14724 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14725 + *need_reopen = 0;
14729 + di_read_unlock(parent, AuLock_IR);
14736 +static void au_do_refresh_dir(struct file *file)
14738 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14739 + struct au_hfile *p, tmp, *q;
14740 + struct au_finfo *finfo;
14741 + struct super_block *sb;
14742 + struct au_fidir *fidir;
14744 + FiMustWriteLock(file);
14746 + sb = file->f_path.dentry->d_sb;
14747 + finfo = au_fi(file);
14748 + fidir = finfo->fi_hdir;
14749 + AuDebugOn(!fidir);
14750 + p = fidir->fd_hfile + finfo->fi_btop;
14751 + brid = p->hf_br->br_id;
14752 + bbot = fidir->fd_bbot;
14753 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14757 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14758 + if (new_bindex == bindex)
14760 + if (new_bindex < 0) {
14761 + au_set_h_fptr(file, bindex, NULL);
14765 + /* swap two lower inode, and loop again */
14766 + q = fidir->fd_hfile + new_bindex;
14770 + if (tmp.hf_file) {
14776 + p = fidir->fd_hfile;
14777 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14778 + bbot = au_sbbot(sb);
14779 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14780 + finfo->fi_btop++, p++)
14781 + if (p->hf_file) {
14782 + if (file_inode(p->hf_file))
14784 + au_hfput(p, /*execed*/0);
14787 + bbot = au_br_index(sb, brid);
14788 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14789 + finfo->fi_btop++, p++)
14791 + au_hfput(p, /*execed*/0);
14792 + bbot = au_sbbot(sb);
14795 + p = fidir->fd_hfile + bbot;
14796 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14797 + fidir->fd_bbot--, p--)
14798 + if (p->hf_file) {
14799 + if (file_inode(p->hf_file))
14801 + au_hfput(p, /*execed*/0);
14803 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14807 + * after branch manipulating, refresh the file.
14809 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14811 + int err, need_reopen, nbr;
14812 + aufs_bindex_t bbot, bindex;
14813 + struct dentry *dentry;
14814 + struct super_block *sb;
14815 + struct au_finfo *finfo;
14816 + struct au_hfile *hfile;
14818 + dentry = file->f_path.dentry;
14819 + sb = dentry->d_sb;
14820 + nbr = au_sbbot(sb) + 1;
14821 + finfo = au_fi(file);
14822 + if (!finfo->fi_hdir) {
14823 + hfile = &finfo->fi_htop;
14824 + AuDebugOn(!hfile->hf_file);
14825 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14826 + AuDebugOn(bindex < 0);
14827 + if (bindex != finfo->fi_btop)
14828 + au_set_fbtop(file, bindex);
14830 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14831 + if (unlikely(err))
14833 + au_do_refresh_dir(file);
14838 + if (!au_test_mmapped(file))
14839 + err = au_file_refresh_by_inode(file, &need_reopen);
14840 + if (finfo->fi_hdir)
14841 + /* harmless if err */
14842 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14843 + if (!err && need_reopen && !d_unlinked(dentry))
14844 + err = reopen(file);
14846 + au_update_figen(file);
14847 + goto out; /* success */
14850 + /* error, close all lower files */
14851 + if (finfo->fi_hdir) {
14852 + bbot = au_fbbot_dir(file);
14853 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14854 + au_set_h_fptr(file, bindex, NULL);
14861 +/* common function to regular file and dir */
14862 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14863 + int wlock, unsigned int fi_lsc)
14866 + unsigned int sigen, figen;
14867 + aufs_bindex_t btop;
14868 + unsigned char pseudo_link;
14869 + struct dentry *dentry;
14870 + struct inode *inode;
14873 + dentry = file->f_path.dentry;
14874 + inode = d_inode(dentry);
14875 + sigen = au_sigen(dentry->d_sb);
14876 + fi_write_lock_nested(file, fi_lsc);
14877 + figen = au_figen(file);
14879 + di_write_lock_child(dentry);
14881 + di_write_lock_child2(dentry);
14882 + btop = au_dbtop(dentry);
14883 + pseudo_link = (btop != au_ibtop(inode));
14884 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14886 + di_downgrade_lock(dentry, AuLock_IR);
14887 + fi_downgrade_lock(file);
14889 + goto out; /* success */
14892 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14893 + if (au_digen_test(dentry, sigen)) {
14894 + err = au_reval_dpath(dentry, sigen);
14895 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14899 + err = refresh_file(file, reopen);
14902 + di_downgrade_lock(dentry, AuLock_IR);
14903 + fi_downgrade_lock(file);
14906 + di_write_unlock(dentry);
14907 + fi_write_unlock(file);
14914 +/* ---------------------------------------------------------------------- */
14916 +/* cf. aufs_nopage() */
14917 +/* for madvise(2) */
14918 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14920 + unlock_page(page);
14924 +/* it will never be called, but necessary to support O_DIRECT */
14925 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14926 +{ BUG(); return 0; }
14928 +/* they will never be called. */
14929 +#ifdef CONFIG_AUFS_DEBUG
14930 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14931 + loff_t pos, unsigned len, unsigned flags,
14932 + struct page **pagep, void **fsdata)
14933 +{ AuUnsupport(); return 0; }
14934 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14935 + loff_t pos, unsigned len, unsigned copied,
14936 + struct page *page, void *fsdata)
14937 +{ AuUnsupport(); return 0; }
14938 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14939 +{ AuUnsupport(); return 0; }
14941 +static int aufs_set_page_dirty(struct page *page)
14942 +{ AuUnsupport(); return 0; }
14943 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14944 + unsigned int length)
14945 +{ AuUnsupport(); }
14946 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14947 +{ AuUnsupport(); return 0; }
14948 +#if 0 /* called by memory compaction regardless file */
14949 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14950 + struct page *page, enum migrate_mode mode)
14951 +{ AuUnsupport(); return 0; }
14953 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14954 +{ AuUnsupport(); return true; }
14955 +static void aufs_putback_page(struct page *page)
14956 +{ AuUnsupport(); }
14957 +static int aufs_launder_page(struct page *page)
14958 +{ AuUnsupport(); return 0; }
14959 +static int aufs_is_partially_uptodate(struct page *page,
14960 + unsigned long from,
14961 + unsigned long count)
14962 +{ AuUnsupport(); return 0; }
14963 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14965 +{ AuUnsupport(); }
14966 +static int aufs_error_remove_page(struct address_space *mapping,
14967 + struct page *page)
14968 +{ AuUnsupport(); return 0; }
14969 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14971 +{ AuUnsupport(); return 0; }
14972 +static void aufs_swap_deactivate(struct file *file)
14973 +{ AuUnsupport(); }
14974 +#endif /* CONFIG_AUFS_DEBUG */
14976 +const struct address_space_operations aufs_aop = {
14977 + .readpage = aufs_readpage,
14978 + .direct_IO = aufs_direct_IO,
14979 +#ifdef CONFIG_AUFS_DEBUG
14980 + .writepage = aufs_writepage,
14981 + /* no writepages, because of writepage */
14982 + .set_page_dirty = aufs_set_page_dirty,
14983 + /* no readpages, because of readpage */
14984 + .write_begin = aufs_write_begin,
14985 + .write_end = aufs_write_end,
14986 + /* no bmap, no block device */
14987 + .invalidatepage = aufs_invalidatepage,
14988 + .releasepage = aufs_releasepage,
14989 + /* is fallback_migrate_page ok? */
14990 + /* .migratepage = aufs_migratepage, */
14991 + .isolate_page = aufs_isolate_page,
14992 + .putback_page = aufs_putback_page,
14993 + .launder_page = aufs_launder_page,
14994 + .is_partially_uptodate = aufs_is_partially_uptodate,
14995 + .is_dirty_writeback = aufs_is_dirty_writeback,
14996 + .error_remove_page = aufs_error_remove_page,
14997 + .swap_activate = aufs_swap_activate,
14998 + .swap_deactivate = aufs_swap_deactivate
14999 +#endif /* CONFIG_AUFS_DEBUG */
15001 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15002 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15003 +++ linux/fs/aufs/file.h 2020-01-27 10:57:18.172204883 +0100
15005 +/* SPDX-License-Identifier: GPL-2.0 */
15007 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15009 + * This program, aufs is free software; you can redistribute it and/or modify
15010 + * it under the terms of the GNU General Public License as published by
15011 + * the Free Software Foundation; either version 2 of the License, or
15012 + * (at your option) any later version.
15014 + * This program is distributed in the hope that it will be useful,
15015 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15016 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15017 + * GNU General Public License for more details.
15019 + * You should have received a copy of the GNU General Public License
15020 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15024 + * file operations
15027 +#ifndef __AUFS_FILE_H__
15028 +#define __AUFS_FILE_H__
15032 +#include <linux/file.h>
15033 +#include <linux/fs.h>
15034 +#include <linux/mm_types.h>
15035 +#include <linux/poll.h>
15036 +#include "rwsem.h"
15040 + struct file *hf_file;
15041 + struct au_branch *hf_br;
15046 + aufs_bindex_t fd_bbot;
15047 + aufs_bindex_t fd_nent;
15048 + struct au_vdir *fd_vdir_cache;
15049 + struct au_hfile fd_hfile[];
15052 +static inline int au_fidir_sz(int nent)
15054 + AuDebugOn(nent < 0);
15055 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15059 + atomic_t fi_generation;
15061 + struct au_rwsem fi_rwsem;
15062 + aufs_bindex_t fi_btop;
15064 + /* do not union them */
15065 + struct { /* for non-dir */
15066 + struct au_hfile fi_htop;
15067 + atomic_t fi_mmapped;
15069 + struct au_fidir *fi_hdir; /* for dir only */
15071 + struct hlist_bl_node fi_hlist;
15072 + struct file *fi_file; /* very ugly */
15073 + struct rcu_head rcu;
15074 +} ____cacheline_aligned_in_smp;
15076 +/* ---------------------------------------------------------------------- */
15079 +extern const struct address_space_operations aufs_aop;
15080 +unsigned int au_file_roflags(unsigned int flags);
15081 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15082 + struct file *file, int force_wr);
15083 +struct au_do_open_args {
15085 + int (*open)(struct file *file, int flags,
15086 + struct file *h_file);
15087 + struct au_fidir *fidir;
15088 + struct file *h_file;
15090 +int au_do_open(struct file *file, struct au_do_open_args *args);
15091 +int au_reopen_nondir(struct file *file);
15093 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15094 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15095 + int wlock, unsigned int fi_lsc);
15096 +int au_do_flush(struct file *file, fl_owner_t id,
15097 + int (*flush)(struct file *file, fl_owner_t id));
15100 +#ifdef CONFIG_AUFS_POLL
15101 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15104 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15106 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15108 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15109 + struct file *h_file);
15111 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15112 + aufs_bindex_t bindex, int force_wr)
15113 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15114 + struct file *h_file);
15118 +extern const struct file_operations aufs_file_fop;
15119 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15120 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15121 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15124 +void au_hfput(struct au_hfile *hf, int execed);
15125 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15126 + struct file *h_file);
15128 +void au_update_figen(struct file *file);
15129 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15130 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15132 +void au_fi_init_once(void *_fi);
15133 +void au_finfo_fin(struct file *file);
15134 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15137 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15138 +#ifdef CONFIG_COMPAT
15139 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15140 + unsigned long arg);
15141 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15142 + unsigned long arg);
15145 +/* ---------------------------------------------------------------------- */
15147 +static inline struct au_finfo *au_fi(struct file *file)
15149 + return file->private_data;
15152 +/* ---------------------------------------------------------------------- */
15154 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15155 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15156 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15157 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15159 +#define fi_read_trylock_nested(f) \
15160 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15161 +#define fi_write_trylock_nested(f) \
15162 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15165 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15166 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15167 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15169 +/* lock subclass for finfo */
15175 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15177 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15180 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15182 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15186 + * fi_read_lock_1, fi_write_lock_1,
15187 + * fi_read_lock_2, fi_write_lock_2
15189 +#define AuReadLockFunc(name) \
15190 +static inline void fi_read_lock_##name(struct file *f) \
15191 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15193 +#define AuWriteLockFunc(name) \
15194 +static inline void fi_write_lock_##name(struct file *f) \
15195 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15197 +#define AuRWLockFuncs(name) \
15198 + AuReadLockFunc(name) \
15199 + AuWriteLockFunc(name)
15204 +#undef AuReadLockFunc
15205 +#undef AuWriteLockFunc
15206 +#undef AuRWLockFuncs
15208 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15209 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15210 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15212 +/* ---------------------------------------------------------------------- */
15214 +/* todo: hard/soft set? */
15215 +static inline aufs_bindex_t au_fbtop(struct file *file)
15217 + FiMustAnyLock(file);
15218 + return au_fi(file)->fi_btop;
15221 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15223 + FiMustAnyLock(file);
15224 + AuDebugOn(!au_fi(file)->fi_hdir);
15225 + return au_fi(file)->fi_hdir->fd_bbot;
15228 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15230 + FiMustAnyLock(file);
15231 + AuDebugOn(!au_fi(file)->fi_hdir);
15232 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15235 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15237 + FiMustWriteLock(file);
15238 + au_fi(file)->fi_btop = bindex;
15241 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15243 + FiMustWriteLock(file);
15244 + AuDebugOn(!au_fi(file)->fi_hdir);
15245 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15248 +static inline void au_set_fvdir_cache(struct file *file,
15249 + struct au_vdir *vdir_cache)
15251 + FiMustWriteLock(file);
15252 + AuDebugOn(!au_fi(file)->fi_hdir);
15253 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15256 +static inline struct file *au_hf_top(struct file *file)
15258 + FiMustAnyLock(file);
15259 + AuDebugOn(au_fi(file)->fi_hdir);
15260 + return au_fi(file)->fi_htop.hf_file;
15263 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15265 + FiMustAnyLock(file);
15266 + AuDebugOn(!au_fi(file)->fi_hdir);
15267 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15270 +/* todo: memory barrier? */
15271 +static inline unsigned int au_figen(struct file *f)
15273 + return atomic_read(&au_fi(f)->fi_generation);
15276 +static inline void au_set_mmapped(struct file *f)
15278 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15280 + pr_warn("fi_mmapped wrapped around\n");
15281 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15285 +static inline void au_unset_mmapped(struct file *f)
15287 + atomic_dec(&au_fi(f)->fi_mmapped);
15290 +static inline int au_test_mmapped(struct file *f)
15292 + return atomic_read(&au_fi(f)->fi_mmapped);
15295 +/* customize vma->vm_file */
15297 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15298 + struct file *file)
15302 + f = vma->vm_file;
15304 + vma->vm_file = file;
15309 +#define AuDbgVmRegion(file, vma) do {} while (0)
15311 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15312 + struct file *file)
15314 + au_do_vm_file_reset(vma, file);
15317 +#define AuDbgVmRegion(file, vma) \
15318 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15320 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15321 + struct file *file)
15325 + au_do_vm_file_reset(vma, file);
15326 + f = vma->vm_region->vm_file;
15328 + vma->vm_region->vm_file = file;
15331 +#endif /* CONFIG_MMU */
15333 +/* handle vma->vm_prfile */
15334 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15335 + struct file *file)
15338 + vma->vm_prfile = file;
15339 +#ifndef CONFIG_MMU
15341 + vma->vm_region->vm_prfile = file;
15345 +#endif /* __KERNEL__ */
15346 +#endif /* __AUFS_FILE_H__ */
15347 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15348 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15349 +++ linux/fs/aufs/finfo.c 2020-01-27 10:57:18.172204883 +0100
15351 +// SPDX-License-Identifier: GPL-2.0
15353 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15355 + * This program, aufs is free software; you can redistribute it and/or modify
15356 + * it under the terms of the GNU General Public License as published by
15357 + * the Free Software Foundation; either version 2 of the License, or
15358 + * (at your option) any later version.
15360 + * This program is distributed in the hope that it will be useful,
15361 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15362 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15363 + * GNU General Public License for more details.
15365 + * You should have received a copy of the GNU General Public License
15366 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15370 + * file private data
15375 +void au_hfput(struct au_hfile *hf, int execed)
15378 + allow_write_access(hf->hf_file);
15379 + fput(hf->hf_file);
15380 + hf->hf_file = NULL;
15381 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15382 + hf->hf_br = NULL;
15385 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15387 + struct au_finfo *finfo = au_fi(file);
15388 + struct au_hfile *hf;
15389 + struct au_fidir *fidir;
15391 + fidir = finfo->fi_hdir;
15393 + AuDebugOn(finfo->fi_btop != bindex);
15394 + hf = &finfo->fi_htop;
15396 + hf = fidir->fd_hfile + bindex;
15398 + if (hf && hf->hf_file)
15399 + au_hfput(hf, vfsub_file_execed(file));
15401 + FiMustWriteLock(file);
15402 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15403 + hf->hf_file = val;
15404 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15408 +void au_update_figen(struct file *file)
15410 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15411 + /* smp_mb(); */ /* atomic_set */
15414 +/* ---------------------------------------------------------------------- */
15416 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15418 + struct au_fidir *fidir;
15421 + nbr = au_sbbot(sb) + 1;
15423 + nbr = 2; /* initial allocate for 2 branches */
15424 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15426 + fidir->fd_bbot = -1;
15427 + fidir->fd_nent = nbr;
15433 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15436 + struct au_fidir *fidir, *p;
15438 + AuRwMustWriteLock(&finfo->fi_rwsem);
15439 + fidir = finfo->fi_hdir;
15440 + AuDebugOn(!fidir);
15443 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15444 + GFP_NOFS, may_shrink);
15446 + p->fd_nent = nbr;
15447 + finfo->fi_hdir = p;
15454 +/* ---------------------------------------------------------------------- */
15456 +void au_finfo_fin(struct file *file)
15458 + struct au_finfo *finfo;
15460 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15462 + finfo = au_fi(file);
15463 + AuDebugOn(finfo->fi_hdir);
15464 + AuRwDestroy(&finfo->fi_rwsem);
15465 + au_cache_free_finfo(finfo);
15468 +void au_fi_init_once(void *_finfo)
15470 + struct au_finfo *finfo = _finfo;
15472 + au_rw_init(&finfo->fi_rwsem);
15475 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15478 + struct au_finfo *finfo;
15479 + struct dentry *dentry;
15482 + dentry = file->f_path.dentry;
15483 + finfo = au_cache_alloc_finfo();
15484 + if (unlikely(!finfo))
15488 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15489 + au_rw_write_lock(&finfo->fi_rwsem);
15490 + finfo->fi_btop = -1;
15491 + finfo->fi_hdir = fidir;
15492 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15493 + /* smp_mb(); */ /* atomic_set */
15495 + file->private_data = finfo;
15500 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15501 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15502 +++ linux/fs/aufs/f_op.c 2020-01-27 10:57:18.172204883 +0100
15504 +// SPDX-License-Identifier: GPL-2.0
15506 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15508 + * This program, aufs is free software; you can redistribute it and/or modify
15509 + * it under the terms of the GNU General Public License as published by
15510 + * the Free Software Foundation; either version 2 of the License, or
15511 + * (at your option) any later version.
15513 + * This program is distributed in the hope that it will be useful,
15514 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15515 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15516 + * GNU General Public License for more details.
15518 + * You should have received a copy of the GNU General Public License
15519 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15523 + * file and vm operations
15526 +#include <linux/aio.h>
15527 +#include <linux/fs_stack.h>
15528 +#include <linux/mman.h>
15529 +#include <linux/security.h>
15532 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15535 + aufs_bindex_t bindex;
15536 + struct dentry *dentry, *h_dentry;
15537 + struct au_finfo *finfo;
15538 + struct inode *h_inode;
15540 + FiMustWriteLock(file);
15543 + dentry = file->f_path.dentry;
15544 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15545 + finfo = au_fi(file);
15546 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15547 + atomic_set(&finfo->fi_mmapped, 0);
15548 + bindex = au_dbtop(dentry);
15550 + h_dentry = au_h_dptr(dentry, bindex);
15551 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15552 + if (unlikely(err))
15554 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15555 + if (IS_ERR(h_file)) {
15556 + err = PTR_ERR(h_file);
15560 + h_dentry = h_file->f_path.dentry;
15561 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15562 + if (unlikely(err))
15564 + /* br ref is already inc-ed */
15567 + if ((flags & __O_TMPFILE)
15568 + && !(flags & O_EXCL)) {
15569 + h_inode = file_inode(h_file);
15570 + spin_lock(&h_inode->i_lock);
15571 + h_inode->i_state |= I_LINKABLE;
15572 + spin_unlock(&h_inode->i_lock);
15574 + au_set_fbtop(file, bindex);
15575 + au_set_h_fptr(file, bindex, h_file);
15576 + au_update_figen(file);
15577 + /* todo: necessary? */
15578 + /* file->f_ra = h_file->f_ra; */
15584 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15585 + struct file *file)
15588 + struct super_block *sb;
15589 + struct au_do_open_args args = {
15590 + .open = au_do_open_nondir
15593 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15594 + file, vfsub_file_flags(file), file->f_mode);
15596 + sb = file->f_path.dentry->d_sb;
15597 + si_read_lock(sb, AuLock_FLUSH);
15598 + err = au_do_open(file, &args);
15599 + si_read_unlock(sb);
15603 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15605 + struct au_finfo *finfo;
15606 + aufs_bindex_t bindex;
15608 + finfo = au_fi(file);
15609 + au_hbl_del(&finfo->fi_hlist,
15610 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15611 + bindex = finfo->fi_btop;
15613 + au_set_h_fptr(file, bindex, NULL);
15615 + au_finfo_fin(file);
15619 +/* ---------------------------------------------------------------------- */
15621 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15624 + struct file *h_file;
15627 + h_file = au_hf_top(file);
15629 + err = vfsub_flush(h_file, id);
15633 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15635 + return au_do_flush(file, id, au_do_flush_nondir);
15638 +/* ---------------------------------------------------------------------- */
15640 + * read and write functions acquire [fdi]_rwsem once, but release before
15641 + * mmap_sem. This is because to stop a race condition between mmap(2).
15642 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15643 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15644 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15647 +/* Callers should call au_read_post() or fput() in the end */
15648 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15650 + struct file *h_file;
15653 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15655 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15656 + h_file = au_hf_top(file);
15657 + get_file(h_file);
15659 + fi_read_unlock(file);
15661 + h_file = ERR_PTR(err);
15666 +static void au_read_post(struct inode *inode, struct file *h_file)
15668 + /* update without lock, I don't think it a problem */
15669 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15673 +struct au_write_pre {
15675 + unsigned int lsc;
15679 + aufs_bindex_t btop;
15683 + * return with iinfo is write-locked
15684 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15687 +static struct file *au_write_pre(struct file *file, int do_ready,
15688 + struct au_write_pre *wpre)
15690 + struct file *h_file;
15691 + struct dentry *dentry;
15693 + unsigned int lsc;
15694 + struct au_pin pin;
15699 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15700 + h_file = ERR_PTR(err);
15701 + if (unlikely(err))
15704 + dentry = file->f_path.dentry;
15706 + err = au_ready_to_write(file, -1, &pin);
15707 + if (unlikely(err)) {
15708 + h_file = ERR_PTR(err);
15709 + di_write_unlock(dentry);
15714 + di_downgrade_lock(dentry, /*flags*/0);
15716 + wpre->btop = au_fbtop(file);
15717 + h_file = au_hf_top(file);
15718 + get_file(h_file);
15720 + wpre->blks = file_inode(h_file)->i_blocks;
15723 + di_read_unlock(dentry, /*flags*/0);
15726 + fi_write_unlock(file);
15731 +static void au_write_post(struct inode *inode, struct file *h_file,
15732 + struct au_write_pre *wpre, ssize_t written)
15734 + struct inode *h_inode;
15736 + au_cpup_attr_timesizes(inode);
15737 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15738 + h_inode = file_inode(h_file);
15739 + inode->i_mode = h_inode->i_mode;
15740 + ii_write_unlock(inode);
15741 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15743 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15744 + /*force*/h_inode->i_blocks > wpre->blks);
15748 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15752 + struct inode *inode;
15753 + struct file *h_file;
15754 + struct super_block *sb;
15756 + inode = file_inode(file);
15757 + sb = inode->i_sb;
15758 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15760 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15761 + err = PTR_ERR(h_file);
15762 + if (IS_ERR(h_file))
15765 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15766 + err = vfsub_read_u(h_file, buf, count, ppos);
15767 + /* todo: necessary? */
15768 + /* file->f_ra = h_file->f_ra; */
15769 + au_read_post(inode, h_file);
15772 + si_read_unlock(sb);
15777 + * todo: very ugly
15778 + * it locks both of i_mutex and si_rwsem for read in safe.
15779 + * if the plink maintenance mode continues forever (that is the problem),
15780 + * may loop forever.
15782 +static void au_mtx_and_read_lock(struct inode *inode)
15785 + struct super_block *sb = inode->i_sb;
15788 + inode_lock(inode);
15789 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15792 + inode_unlock(inode);
15793 + si_read_lock(sb, AuLock_NOPLMW);
15794 + si_read_unlock(sb);
15798 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15799 + size_t count, loff_t *ppos)
15802 + struct au_write_pre wpre;
15803 + struct inode *inode;
15804 + struct file *h_file;
15805 + char __user *buf = (char __user *)ubuf;
15807 + inode = file_inode(file);
15808 + au_mtx_and_read_lock(inode);
15811 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15812 + err = PTR_ERR(h_file);
15813 + if (IS_ERR(h_file))
15816 + err = vfsub_write_u(h_file, buf, count, ppos);
15817 + au_write_post(inode, h_file, &wpre, err);
15820 + si_read_unlock(inode->i_sb);
15821 + inode_unlock(inode);
15825 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15826 + struct iov_iter *iov_iter)
15829 + struct file *file;
15830 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15832 + err = security_file_permission(h_file, rw);
15833 + if (unlikely(err))
15836 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15838 + if (rw == MAY_READ)
15839 + iter = h_file->f_op->read_iter;
15840 + else if (rw == MAY_WRITE)
15841 + iter = h_file->f_op->write_iter;
15843 + file = kio->ki_filp;
15844 + kio->ki_filp = h_file;
15847 + err = iter(kio, iov_iter);
15850 + /* currently there is no such fs */
15852 + kio->ki_filp = file;
15858 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15861 + struct file *file, *h_file;
15862 + struct inode *inode;
15863 + struct super_block *sb;
15865 + file = kio->ki_filp;
15866 + inode = file_inode(file);
15867 + sb = inode->i_sb;
15868 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15870 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15871 + err = PTR_ERR(h_file);
15872 + if (IS_ERR(h_file))
15875 + if (au_test_loopback_kthread()) {
15876 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15877 + if (file->f_mapping != h_file->f_mapping) {
15878 + file->f_mapping = h_file->f_mapping;
15879 + smp_mb(); /* unnecessary? */
15882 + fi_read_unlock(file);
15884 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15885 + /* todo: necessary? */
15886 + /* file->f_ra = h_file->f_ra; */
15887 + au_read_post(inode, h_file);
15890 + si_read_unlock(sb);
15894 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15897 + struct au_write_pre wpre;
15898 + struct inode *inode;
15899 + struct file *file, *h_file;
15901 + file = kio->ki_filp;
15902 + inode = file_inode(file);
15903 + au_mtx_and_read_lock(inode);
15906 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15907 + err = PTR_ERR(h_file);
15908 + if (IS_ERR(h_file))
15911 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15912 + au_write_post(inode, h_file, &wpre, err);
15915 + si_read_unlock(inode->i_sb);
15916 + inode_unlock(inode);
15920 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15921 + struct pipe_inode_info *pipe, size_t len,
15922 + unsigned int flags)
15925 + struct file *h_file;
15926 + struct inode *inode;
15927 + struct super_block *sb;
15929 + inode = file_inode(file);
15930 + sb = inode->i_sb;
15931 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15933 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15934 + err = PTR_ERR(h_file);
15935 + if (IS_ERR(h_file))
15938 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15939 + /* todo: necessary? */
15940 + /* file->f_ra = h_file->f_ra; */
15941 + au_read_post(inode, h_file);
15944 + si_read_unlock(sb);
15949 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15950 + size_t len, unsigned int flags)
15953 + struct au_write_pre wpre;
15954 + struct inode *inode;
15955 + struct file *h_file;
15957 + inode = file_inode(file);
15958 + au_mtx_and_read_lock(inode);
15961 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15962 + err = PTR_ERR(h_file);
15963 + if (IS_ERR(h_file))
15966 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15967 + au_write_post(inode, h_file, &wpre, err);
15970 + si_read_unlock(inode->i_sb);
15971 + inode_unlock(inode);
15975 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15979 + struct au_write_pre wpre;
15980 + struct inode *inode;
15981 + struct file *h_file;
15983 + inode = file_inode(file);
15984 + au_mtx_and_read_lock(inode);
15987 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15988 + err = PTR_ERR(h_file);
15989 + if (IS_ERR(h_file))
15993 + err = vfs_fallocate(h_file, mode, offset, len);
15995 + au_write_post(inode, h_file, &wpre, /*written*/1);
15998 + si_read_unlock(inode->i_sb);
15999 + inode_unlock(inode);
16003 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16004 + struct file *dst, loff_t dst_pos,
16005 + size_t len, unsigned int flags)
16008 + struct au_write_pre wpre;
16009 + enum { SRC, DST };
16011 + struct inode *inode;
16012 + struct file *h_file;
16013 + struct super_block *h_sb;
16015 +#define a_src a[SRC]
16016 +#define a_dst a[DST]
16019 + a_src.inode = file_inode(src);
16020 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16022 + a_dst.inode = file_inode(dst);
16023 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16026 + au_mtx_and_read_lock(a_dst.inode);
16028 + * in order to match the order in di_write_lock2_{child,parent}(),
16029 + * use f_path.dentry for this comparison.
16031 + if (src->f_path.dentry < dst->f_path.dentry) {
16032 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16033 + err = PTR_ERR(a_src.h_file);
16034 + if (IS_ERR(a_src.h_file))
16037 + wpre.lsc = AuLsc_FI_2;
16038 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16039 + err = PTR_ERR(a_dst.h_file);
16040 + if (IS_ERR(a_dst.h_file)) {
16041 + au_read_post(a_src.inode, a_src.h_file);
16045 + wpre.lsc = AuLsc_FI_1;
16046 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16047 + err = PTR_ERR(a_dst.h_file);
16048 + if (IS_ERR(a_dst.h_file))
16051 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16052 + err = PTR_ERR(a_src.h_file);
16053 + if (IS_ERR(a_src.h_file)) {
16054 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16061 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16062 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16063 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16069 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16070 + dst_pos, len, flags);
16073 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16074 + fi_read_unlock(src);
16075 + au_read_post(a_src.inode, a_src.h_file);
16077 + si_read_unlock(a_dst.inode->i_sb);
16078 + inode_unlock(a_dst.inode);
16085 +/* ---------------------------------------------------------------------- */
16088 + * The locking order around current->mmap_sem.
16089 + * - in most and regular cases
16090 + * file I/O syscall -- aufs_read() or something
16091 + * -- si_rwsem for read -- mmap_sem
16092 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16094 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16095 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16096 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16097 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16098 + * It means that when aufs acquires si_rwsem for write, the process should never
16099 + * acquire mmap_sem.
16101 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16102 + * problem either since any directory is not able to be mmap-ed.
16103 + * The similar scenario is applied to aufs_readlink() too.
16106 +#if 0 /* stop calling security_file_mmap() */
16107 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16108 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16110 +static unsigned long au_arch_prot_conv(unsigned long flags)
16112 + /* currently ppc64 only */
16113 +#ifdef CONFIG_PPC64
16114 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16115 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16116 + return AuConv_VM_PROT(flags, SAO);
16118 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16123 +static unsigned long au_prot_conv(unsigned long flags)
16125 + return AuConv_VM_PROT(flags, READ)
16126 + | AuConv_VM_PROT(flags, WRITE)
16127 + | AuConv_VM_PROT(flags, EXEC)
16128 + | au_arch_prot_conv(flags);
16131 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16132 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16134 +static unsigned long au_flag_conv(unsigned long flags)
16136 + return AuConv_VM_MAP(flags, GROWSDOWN)
16137 + | AuConv_VM_MAP(flags, DENYWRITE)
16138 + | AuConv_VM_MAP(flags, LOCKED);
16142 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16145 + const unsigned char wlock
16146 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16147 + struct super_block *sb;
16148 + struct file *h_file;
16149 + struct inode *inode;
16151 + AuDbgVmRegion(file, vma);
16153 + inode = file_inode(file);
16154 + sb = inode->i_sb;
16156 + si_read_lock(sb, AuLock_NOPLMW);
16158 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16160 + err = PTR_ERR(h_file);
16161 + if (IS_ERR(h_file))
16165 + au_set_mmapped(file);
16166 + au_vm_file_reset(vma, h_file);
16168 + * we cannot call security_mmap_file() here since it may acquire
16169 + * mmap_sem or i_mutex.
16171 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16172 + * au_flag_conv(vma->vm_flags));
16175 + err = call_mmap(h_file, vma);
16177 + au_vm_prfile_set(vma, file);
16178 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16179 + goto out_fput; /* success */
16181 + au_unset_mmapped(file);
16182 + au_vm_file_reset(vma, file);
16186 + ii_write_unlock(inode);
16191 + si_read_unlock(sb);
16197 +/* ---------------------------------------------------------------------- */
16199 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16203 + struct au_write_pre wpre;
16204 + struct inode *inode;
16205 + struct file *h_file;
16207 + err = 0; /* -EBADF; */ /* posix? */
16208 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16211 + inode = file_inode(file);
16212 + au_mtx_and_read_lock(inode);
16215 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16216 + err = PTR_ERR(h_file);
16217 + if (IS_ERR(h_file))
16220 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16221 + au_write_post(inode, h_file, &wpre, /*written*/0);
16224 + si_read_unlock(inode->i_sb);
16225 + inode_unlock(inode);
16230 +static int aufs_fasync(int fd, struct file *file, int flag)
16233 + struct file *h_file;
16234 + struct super_block *sb;
16236 + sb = file->f_path.dentry->d_sb;
16237 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16239 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16240 + err = PTR_ERR(h_file);
16241 + if (IS_ERR(h_file))
16244 + if (h_file->f_op->fasync)
16245 + err = h_file->f_op->fasync(fd, h_file, flag);
16246 + fput(h_file); /* instead of au_read_post() */
16249 + si_read_unlock(sb);
16253 +static int aufs_setfl(struct file *file, unsigned long arg)
16256 + struct file *h_file;
16257 + struct super_block *sb;
16259 + sb = file->f_path.dentry->d_sb;
16260 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16262 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16263 + err = PTR_ERR(h_file);
16264 + if (IS_ERR(h_file))
16267 + /* stop calling h_file->fasync */
16268 + arg |= vfsub_file_flags(file) & FASYNC;
16269 + err = setfl(/*unused fd*/-1, h_file, arg);
16270 + fput(h_file); /* instead of au_read_post() */
16273 + si_read_unlock(sb);
16277 +/* ---------------------------------------------------------------------- */
16279 +/* no one supports this operation, currently */
16280 +#if 0 /* reserved for future use */
16281 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16282 + size_t len, loff_t *pos, int more)
16287 +/* ---------------------------------------------------------------------- */
16289 +const struct file_operations aufs_file_fop = {
16290 + .owner = THIS_MODULE,
16292 + .llseek = default_llseek,
16294 + .read = aufs_read,
16295 + .write = aufs_write,
16296 + .read_iter = aufs_read_iter,
16297 + .write_iter = aufs_write_iter,
16299 +#ifdef CONFIG_AUFS_POLL
16300 + .poll = aufs_poll,
16302 + .unlocked_ioctl = aufs_ioctl_nondir,
16303 +#ifdef CONFIG_COMPAT
16304 + .compat_ioctl = aufs_compat_ioctl_nondir,
16306 + .mmap = aufs_mmap,
16307 + .open = aufs_open_nondir,
16308 + .flush = aufs_flush_nondir,
16309 + .release = aufs_release_nondir,
16310 + .fsync = aufs_fsync_nondir,
16311 + .fasync = aufs_fasync,
16312 + /* .sendpage = aufs_sendpage, */
16313 + .setfl = aufs_setfl,
16314 + .splice_write = aufs_splice_write,
16315 + .splice_read = aufs_splice_read,
16316 +#if 0 /* reserved for future use */
16317 + .aio_splice_write = aufs_aio_splice_write,
16318 + .aio_splice_read = aufs_aio_splice_read,
16320 + .fallocate = aufs_fallocate,
16321 + .copy_file_range = aufs_copy_file_range
16323 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16324 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16325 +++ linux/fs/aufs/fstype.h 2020-01-27 10:57:18.172204883 +0100
16327 +/* SPDX-License-Identifier: GPL-2.0 */
16329 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16331 + * This program, aufs is free software; you can redistribute it and/or modify
16332 + * it under the terms of the GNU General Public License as published by
16333 + * the Free Software Foundation; either version 2 of the License, or
16334 + * (at your option) any later version.
16336 + * This program is distributed in the hope that it will be useful,
16337 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16338 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16339 + * GNU General Public License for more details.
16341 + * You should have received a copy of the GNU General Public License
16342 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16346 + * judging filesystem type
16349 +#ifndef __AUFS_FSTYPE_H__
16350 +#define __AUFS_FSTYPE_H__
16354 +#include <linux/fs.h>
16355 +#include <linux/magic.h>
16356 +#include <linux/nfs_fs.h>
16357 +#include <linux/romfs_fs.h>
16359 +static inline int au_test_aufs(struct super_block *sb)
16361 + return sb->s_magic == AUFS_SUPER_MAGIC;
16364 +static inline const char *au_sbtype(struct super_block *sb)
16366 + return sb->s_type->name;
16369 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16371 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16372 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16378 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16380 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16381 + return sb->s_magic == ROMFS_MAGIC;
16387 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16389 +#if IS_ENABLED(CONFIG_CRAMFS)
16390 + return sb->s_magic == CRAMFS_MAGIC;
16395 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16397 +#if IS_ENABLED(CONFIG_NFS_FS)
16398 + return sb->s_magic == NFS_SUPER_MAGIC;
16404 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16406 +#if IS_ENABLED(CONFIG_FUSE_FS)
16407 + return sb->s_magic == FUSE_SUPER_MAGIC;
16413 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16415 +#if IS_ENABLED(CONFIG_XFS_FS)
16416 + return sb->s_magic == XFS_SB_MAGIC;
16422 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16424 +#ifdef CONFIG_TMPFS
16425 + return sb->s_magic == TMPFS_MAGIC;
16431 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16433 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16434 + return !strcmp(au_sbtype(sb), "ecryptfs");
16440 +static inline int au_test_ramfs(struct super_block *sb)
16442 + return sb->s_magic == RAMFS_MAGIC;
16445 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16447 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16448 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16454 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16456 +#ifdef CONFIG_PROC_FS
16457 + return sb->s_magic == PROC_SUPER_MAGIC;
16463 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16465 +#ifdef CONFIG_SYSFS
16466 + return sb->s_magic == SYSFS_MAGIC;
16472 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16474 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16475 + return sb->s_magic == CONFIGFS_MAGIC;
16481 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16483 +#if IS_ENABLED(CONFIG_MINIX_FS)
16484 + return sb->s_magic == MINIX3_SUPER_MAGIC
16485 + || sb->s_magic == MINIX2_SUPER_MAGIC
16486 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16487 + || sb->s_magic == MINIX_SUPER_MAGIC
16488 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16494 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16496 +#if IS_ENABLED(CONFIG_FAT_FS)
16497 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16503 +static inline int au_test_msdos(struct super_block *sb)
16505 + return au_test_fat(sb);
16508 +static inline int au_test_vfat(struct super_block *sb)
16510 + return au_test_fat(sb);
16513 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16515 +#ifdef CONFIG_SECURITYFS
16516 + return sb->s_magic == SECURITYFS_MAGIC;
16522 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16524 +#if IS_ENABLED(CONFIG_SQUASHFS)
16525 + return sb->s_magic == SQUASHFS_MAGIC;
16531 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16533 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16534 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16540 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16542 +#if IS_ENABLED(CONFIG_XENFS)
16543 + return sb->s_magic == XENFS_SUPER_MAGIC;
16549 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16551 +#ifdef CONFIG_DEBUG_FS
16552 + return sb->s_magic == DEBUGFS_MAGIC;
16558 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16560 +#if IS_ENABLED(CONFIG_NILFS)
16561 + return sb->s_magic == NILFS_SUPER_MAGIC;
16567 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16569 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16570 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16576 +/* ---------------------------------------------------------------------- */
16578 + * they can't be an aufs branch.
16580 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16583 +#ifndef CONFIG_AUFS_BR_RAMFS
16584 + au_test_ramfs(sb) ||
16586 + au_test_procfs(sb)
16587 + || au_test_sysfs(sb)
16588 + || au_test_configfs(sb)
16589 + || au_test_debugfs(sb)
16590 + || au_test_securityfs(sb)
16591 + || au_test_xenfs(sb)
16592 + || au_test_ecryptfs(sb)
16593 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16594 + || au_test_aufs(sb); /* will be supported in next version */
16597 +static inline int au_test_fs_remote(struct super_block *sb)
16599 + return !au_test_tmpfs(sb)
16600 +#ifdef CONFIG_AUFS_BR_RAMFS
16601 + && !au_test_ramfs(sb)
16603 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16606 +/* ---------------------------------------------------------------------- */
16609 + * Note: these functions (below) are created after reading ->getattr() in all
16610 + * filesystems under linux/fs. it means we have to do so in every update...
16614 + * some filesystems require getattr to refresh the inode attributes before
16616 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16617 + * and leave the work for d_revalidate()
16619 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16621 + return au_test_nfs(sb)
16622 + || au_test_fuse(sb)
16623 + /* || au_test_btrfs(sb) */ /* untested */
16628 + * filesystems which don't maintain i_size or i_blocks.
16630 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16632 + return au_test_xfs(sb)
16633 + || au_test_btrfs(sb)
16634 + || au_test_ubifs(sb)
16635 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16636 + /* || au_test_minix(sb) */ /* untested */
16641 + * filesystems which don't store the correct value in some of their inode
16644 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16646 + return au_test_fs_bad_iattr_size(sb)
16647 + || au_test_fat(sb)
16648 + || au_test_msdos(sb)
16649 + || au_test_vfat(sb);
16652 +/* they don't check i_nlink in link(2) */
16653 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16655 + return au_test_tmpfs(sb)
16656 +#ifdef CONFIG_AUFS_BR_RAMFS
16657 + || au_test_ramfs(sb)
16659 + || au_test_ubifs(sb)
16660 + || au_test_hfsplus(sb);
16664 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16666 +static inline int au_test_fs_notime(struct super_block *sb)
16668 + return au_test_nfs(sb)
16669 + || au_test_fuse(sb)
16670 + || au_test_ubifs(sb)
16674 +/* temporary support for i#1 in cramfs */
16675 +static inline int au_test_fs_unique_ino(struct inode *inode)
16677 + if (au_test_cramfs(inode->i_sb))
16678 + return inode->i_ino != 1;
16682 +/* ---------------------------------------------------------------------- */
16685 + * the filesystem where the xino files placed must support i/o after unlink and
16686 + * maintain i_size and i_blocks.
16688 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16690 + return au_test_fs_remote(sb)
16691 + || au_test_fs_bad_iattr_size(sb)
16692 + /* don't want unnecessary work for xino */
16693 + || au_test_aufs(sb)
16694 + || au_test_ecryptfs(sb)
16695 + || au_test_nilfs(sb);
16698 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16700 + return au_test_tmpfs(sb)
16701 + || au_test_ramfs(sb);
16705 + * test if the @sb is real-readonly.
16707 +static inline int au_test_fs_rr(struct super_block *sb)
16709 + return au_test_squashfs(sb)
16710 + || au_test_iso9660(sb)
16711 + || au_test_cramfs(sb)
16712 + || au_test_romfs(sb);
16716 + * test if the @inode is nfs with 'noacl' option
16717 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16719 +static inline int au_test_nfs_noacl(struct inode *inode)
16721 + return au_test_nfs(inode->i_sb)
16722 + /* && IS_POSIXACL(inode) */
16723 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16726 +#endif /* __KERNEL__ */
16727 +#endif /* __AUFS_FSTYPE_H__ */
16728 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16729 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16730 +++ linux/fs/aufs/hbl.h 2020-01-27 10:57:18.172204883 +0100
16732 +/* SPDX-License-Identifier: GPL-2.0 */
16734 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16736 + * This program, aufs is free software; you can redistribute it and/or modify
16737 + * it under the terms of the GNU General Public License as published by
16738 + * the Free Software Foundation; either version 2 of the License, or
16739 + * (at your option) any later version.
16741 + * This program is distributed in the hope that it will be useful,
16742 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16743 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16744 + * GNU General Public License for more details.
16746 + * You should have received a copy of the GNU General Public License
16747 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16751 + * helpers for hlist_bl.h
16754 +#ifndef __AUFS_HBL_H__
16755 +#define __AUFS_HBL_H__
16759 +#include <linux/list_bl.h>
16761 +static inline void au_hbl_add(struct hlist_bl_node *node,
16762 + struct hlist_bl_head *hbl)
16764 + hlist_bl_lock(hbl);
16765 + hlist_bl_add_head(node, hbl);
16766 + hlist_bl_unlock(hbl);
16769 +static inline void au_hbl_del(struct hlist_bl_node *node,
16770 + struct hlist_bl_head *hbl)
16772 + hlist_bl_lock(hbl);
16773 + hlist_bl_del(node);
16774 + hlist_bl_unlock(hbl);
16777 +#define au_hbl_for_each(pos, head) \
16778 + for (pos = hlist_bl_first(head); \
16782 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16784 + unsigned long cnt;
16785 + struct hlist_bl_node *pos;
16788 + hlist_bl_lock(hbl);
16789 + au_hbl_for_each(pos, hbl)
16791 + hlist_bl_unlock(hbl);
16795 +#endif /* __KERNEL__ */
16796 +#endif /* __AUFS_HBL_H__ */
16797 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16798 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16799 +++ linux/fs/aufs/hfsnotify.c 2020-01-27 10:57:18.172204883 +0100
16801 +// SPDX-License-Identifier: GPL-2.0
16803 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16805 + * This program, aufs is free software; you can redistribute it and/or modify
16806 + * it under the terms of the GNU General Public License as published by
16807 + * the Free Software Foundation; either version 2 of the License, or
16808 + * (at your option) any later version.
16810 + * This program is distributed in the hope that it will be useful,
16811 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16812 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16813 + * GNU General Public License for more details.
16815 + * You should have received a copy of the GNU General Public License
16816 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16820 + * fsnotify for the lower directories
16825 +/* FS_IN_IGNORED is unnecessary */
16826 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16827 + | FS_CREATE | FS_EVENT_ON_CHILD);
16828 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16829 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16831 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16833 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16835 + /* AuDbg("here\n"); */
16836 + au_cache_free_hnotify(hn);
16837 + smp_mb__before_atomic(); /* for atomic64_dec */
16838 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16839 + wake_up(&au_hfsn_wq);
16842 +static int au_hfsn_alloc(struct au_hinode *hinode)
16845 + struct au_hnotify *hn;
16846 + struct super_block *sb;
16847 + struct au_branch *br;
16848 + struct fsnotify_mark *mark;
16849 + aufs_bindex_t bindex;
16851 + hn = hinode->hi_notify;
16852 + sb = hn->hn_aufs_inode->i_sb;
16853 + bindex = au_br_index(sb, hinode->hi_id);
16854 + br = au_sbr(sb, bindex);
16855 + AuDebugOn(!br->br_hfsn);
16857 + mark = &hn->hn_mark;
16858 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16859 + mark->mask = AuHfsnMask;
16861 + * by udba rename or rmdir, aufs assign a new inode to the known
16862 + * h_inode, so specify 1 to allow dups.
16865 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16871 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16873 + struct fsnotify_mark *mark;
16874 + unsigned long long ull;
16875 + struct fsnotify_group *group;
16877 + ull = atomic64_inc_return(&au_hfsn_ifree);
16880 + mark = &hn->hn_mark;
16881 + spin_lock(&mark->lock);
16882 + group = mark->group;
16883 + fsnotify_get_group(group);
16884 + spin_unlock(&mark->lock);
16886 + fsnotify_destroy_mark(mark, group);
16887 + fsnotify_put_mark(mark);
16888 + fsnotify_put_group(group);
16891 + /* free hn by myself */
16895 +/* ---------------------------------------------------------------------- */
16897 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16899 + struct fsnotify_mark *mark;
16901 + mark = &hinode->hi_notify->hn_mark;
16902 + spin_lock(&mark->lock);
16904 + AuDebugOn(mark->mask & AuHfsnMask);
16905 + mark->mask |= AuHfsnMask;
16907 + AuDebugOn(!(mark->mask & AuHfsnMask));
16908 + mark->mask &= ~AuHfsnMask;
16910 + spin_unlock(&mark->lock);
16911 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16914 +/* ---------------------------------------------------------------------- */
16916 +/* #define AuDbgHnotify */
16917 +#ifdef AuDbgHnotify
16918 +static char *au_hfsn_name(u32 mask)
16920 +#ifdef CONFIG_AUFS_DEBUG
16921 +#define test_ret(flag) \
16923 + if (mask & flag) \
16926 + test_ret(FS_ACCESS);
16927 + test_ret(FS_MODIFY);
16928 + test_ret(FS_ATTRIB);
16929 + test_ret(FS_CLOSE_WRITE);
16930 + test_ret(FS_CLOSE_NOWRITE);
16931 + test_ret(FS_OPEN);
16932 + test_ret(FS_MOVED_FROM);
16933 + test_ret(FS_MOVED_TO);
16934 + test_ret(FS_CREATE);
16935 + test_ret(FS_DELETE);
16936 + test_ret(FS_DELETE_SELF);
16937 + test_ret(FS_MOVE_SELF);
16938 + test_ret(FS_UNMOUNT);
16939 + test_ret(FS_Q_OVERFLOW);
16940 + test_ret(FS_IN_IGNORED);
16941 + test_ret(FS_ISDIR);
16942 + test_ret(FS_IN_ONESHOT);
16943 + test_ret(FS_EVENT_ON_CHILD);
16952 +/* ---------------------------------------------------------------------- */
16954 +static void au_hfsn_free_group(struct fsnotify_group *group)
16956 + struct au_br_hfsnotify *hfsn = group->private;
16958 + /* AuDbg("here\n"); */
16959 + au_kfree_try_rcu(hfsn);
16962 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16963 + struct inode *inode,
16964 + u32 mask, const void *data, int data_type,
16965 + const struct qstr *file_name, u32 cookie,
16966 + struct fsnotify_iter_info *iter_info)
16969 + struct au_hnotify *hnotify;
16970 + struct inode *h_dir, *h_inode;
16971 + struct fsnotify_mark *inode_mark;
16973 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16976 + /* if FS_UNMOUNT happens, there must be another bug */
16977 + AuDebugOn(mask & FS_UNMOUNT);
16978 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16983 +#ifdef AuDbgHnotify
16985 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16986 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16987 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16988 + h_dir->i_ino, mask, au_hfsn_name(mask),
16989 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16990 + /* WARN_ON(1); */
16995 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16996 + AuDebugOn(!inode_mark);
16997 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16998 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
17004 +static struct fsnotify_ops au_hfsn_ops = {
17005 + .handle_event = au_hfsn_handle_event,
17006 + .free_group_priv = au_hfsn_free_group,
17007 + .free_mark = au_hfsn_free_mark
17010 +/* ---------------------------------------------------------------------- */
17012 +static void au_hfsn_fin_br(struct au_branch *br)
17014 + struct au_br_hfsnotify *hfsn;
17016 + hfsn = br->br_hfsn;
17019 + fsnotify_put_group(hfsn->hfsn_group);
17024 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17027 + struct fsnotify_group *group;
17028 + struct au_br_hfsnotify *hfsn;
17031 + br->br_hfsn = NULL;
17032 + if (!au_br_hnotifyable(perm))
17036 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17037 + if (unlikely(!hfsn))
17041 + group = fsnotify_alloc_group(&au_hfsn_ops);
17042 + if (IS_ERR(group)) {
17043 + err = PTR_ERR(group);
17044 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17048 + group->private = hfsn;
17049 + hfsn->hfsn_group = group;
17050 + br->br_hfsn = hfsn;
17051 + goto out; /* success */
17054 + au_kfree_try_rcu(hfsn);
17059 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17064 + if (!br->br_hfsn)
17065 + err = au_hfsn_init_br(br, perm);
17070 +/* ---------------------------------------------------------------------- */
17072 +static void au_hfsn_fin(void)
17074 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17075 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17078 +const struct au_hnotify_op au_hnotify_op = {
17079 + .ctl = au_hfsn_ctl,
17080 + .alloc = au_hfsn_alloc,
17081 + .free = au_hfsn_free,
17083 + .fin = au_hfsn_fin,
17085 + .reset_br = au_hfsn_reset_br,
17086 + .fin_br = au_hfsn_fin_br,
17087 + .init_br = au_hfsn_init_br
17089 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17090 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17091 +++ linux/fs/aufs/hfsplus.c 2020-01-27 10:57:18.172204883 +0100
17093 +// SPDX-License-Identifier: GPL-2.0
17095 + * Copyright (C) 2010-2020 Junjiro R. Okajima
17097 + * This program, aufs is free software; you can redistribute it and/or modify
17098 + * it under the terms of the GNU General Public License as published by
17099 + * the Free Software Foundation; either version 2 of the License, or
17100 + * (at your option) any later version.
17102 + * This program is distributed in the hope that it will be useful,
17103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17105 + * GNU General Public License for more details.
17107 + * You should have received a copy of the GNU General Public License
17108 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17112 + * special support for filesystems which acquires an inode mutex
17113 + * at final closing a file, eg, hfsplus.
17115 + * This trick is very simple and stupid, just to open the file before really
17116 + * necessary open to tell hfsplus that this is not the final closing.
17117 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17118 + * and au_h_open_post() after releasing it.
17123 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17126 + struct file *h_file;
17127 + struct dentry *h_dentry;
17129 + h_dentry = au_h_dptr(dentry, bindex);
17130 + AuDebugOn(!h_dentry);
17131 + AuDebugOn(d_is_negative(h_dentry));
17134 + if (au_test_hfsplus(h_dentry->d_sb)
17135 + && d_is_reg(h_dentry))
17136 + h_file = au_h_open(dentry, bindex,
17137 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17138 + /*file*/NULL, force_wr);
17142 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17143 + struct file *h_file)
17145 + struct au_branch *br;
17149 + br = au_sbr(dentry->d_sb, bindex);
17150 + au_lcnt_dec(&br->br_nfiles);
17153 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17154 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17155 +++ linux/fs/aufs/hnotify.c 2020-01-27 10:57:18.172204883 +0100
17157 +// SPDX-License-Identifier: GPL-2.0
17159 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17161 + * This program, aufs is free software; you can redistribute it and/or modify
17162 + * it under the terms of the GNU General Public License as published by
17163 + * the Free Software Foundation; either version 2 of the License, or
17164 + * (at your option) any later version.
17166 + * This program is distributed in the hope that it will be useful,
17167 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17168 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17169 + * GNU General Public License for more details.
17171 + * You should have received a copy of the GNU General Public License
17172 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17176 + * abstraction to notify the direct changes on lower directories
17179 +/* #include <linux/iversion.h> */
17182 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17185 + struct au_hnotify *hn;
17188 + hn = au_cache_alloc_hnotify();
17190 + hn->hn_aufs_inode = inode;
17191 + hinode->hi_notify = hn;
17192 + err = au_hnotify_op.alloc(hinode);
17194 + if (unlikely(err)) {
17195 + hinode->hi_notify = NULL;
17196 + au_cache_free_hnotify(hn);
17198 + * The upper dir was removed by udba, but the same named
17199 + * dir left. In this case, aufs assigns a new inode
17200 + * number and set the monitor again.
17201 + * For the lower dir, the old monitor is still left.
17203 + if (err == -EEXIST)
17212 +void au_hn_free(struct au_hinode *hinode)
17214 + struct au_hnotify *hn;
17216 + hn = hinode->hi_notify;
17218 + hinode->hi_notify = NULL;
17219 + if (au_hnotify_op.free(hinode, hn))
17220 + au_cache_free_hnotify(hn);
17224 +/* ---------------------------------------------------------------------- */
17226 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17228 + if (hinode->hi_notify)
17229 + au_hnotify_op.ctl(hinode, do_set);
17232 +void au_hn_reset(struct inode *inode, unsigned int flags)
17234 + aufs_bindex_t bindex, bbot;
17235 + struct inode *hi;
17236 + struct dentry *iwhdentry;
17238 + bbot = au_ibbot(inode);
17239 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17240 + hi = au_h_iptr(inode, bindex);
17244 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17245 + iwhdentry = au_hi_wh(inode, bindex);
17249 + au_set_h_iptr(inode, bindex, NULL, 0);
17250 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17251 + flags & ~AuHi_XINO);
17254 + /* inode_unlock(hi); */
17258 +/* ---------------------------------------------------------------------- */
17260 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17263 + aufs_bindex_t bindex, bbot, bfound, btop;
17264 + struct inode *h_i;
17267 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17268 + pr_warn("branch root dir was changed\n");
17273 + bbot = au_ibbot(inode);
17274 + btop = au_ibtop(inode);
17275 +#if 0 /* reserved for future use */
17276 + if (bindex == bbot) {
17277 + /* keep this ino in rename case */
17281 + for (bindex = btop; bindex <= bbot; bindex++)
17282 + if (au_h_iptr(inode, bindex) == h_inode) {
17289 + for (bindex = btop; bindex <= bbot; bindex++) {
17290 + h_i = au_h_iptr(inode, bindex);
17294 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17295 + /* ignore this error */
17296 + /* bad action? */
17299 + /* children inode number will be broken */
17306 +static int hn_gen_tree(struct dentry *dentry)
17308 + int err, i, j, ndentry;
17309 + struct au_dcsub_pages dpages;
17310 + struct au_dpage *dpage;
17311 + struct dentry **dentries;
17313 + err = au_dpages_init(&dpages, GFP_NOFS);
17314 + if (unlikely(err))
17316 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17317 + if (unlikely(err))
17320 + for (i = 0; i < dpages.ndpage; i++) {
17321 + dpage = dpages.dpages + i;
17322 + dentries = dpage->dentries;
17323 + ndentry = dpage->ndentry;
17324 + for (j = 0; j < ndentry; j++) {
17325 + struct dentry *d;
17332 + if (d_really_is_positive(d))
17333 + /* todo: reset children xino?
17334 + cached children only? */
17335 + au_iigen_dec(d_inode(d));
17340 + au_dpages_free(&dpages);
17346 + * return 0 if processed.
17348 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17349 + const unsigned int isdir)
17352 + struct dentry *d;
17353 + struct qstr *dname;
17356 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17357 + pr_warn("branch root dir was changed\n");
17363 + AuDebugOn(!name);
17364 + au_iigen_dec(inode);
17365 + spin_lock(&inode->i_lock);
17366 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17367 + spin_lock(&d->d_lock);
17368 + dname = &d->d_name;
17369 + if (dname->len != nlen
17370 + && memcmp(dname->name, name, nlen)) {
17371 + spin_unlock(&d->d_lock);
17376 + spin_unlock(&d->d_lock);
17379 + spin_unlock(&inode->i_lock);
17381 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17382 + d = d_find_any_alias(inode);
17384 + au_iigen_dec(inode);
17388 + spin_lock(&d->d_lock);
17389 + dname = &d->d_name;
17390 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17391 + spin_unlock(&d->d_lock);
17392 + err = hn_gen_tree(d);
17393 + spin_lock(&d->d_lock);
17395 + spin_unlock(&d->d_lock);
17404 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17408 + if (IS_ROOT(dentry)) {
17409 + pr_warn("branch root dir was changed\n");
17415 + au_digen_dec(dentry);
17416 + if (d_really_is_positive(dentry))
17417 + au_iigen_dec(d_inode(dentry));
17419 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17420 + if (d_really_is_positive(dentry))
17421 + err = hn_gen_tree(dentry);
17428 +/* ---------------------------------------------------------------------- */
17430 +/* hnotify job flags */
17431 +#define AuHnJob_XINO0 1
17432 +#define AuHnJob_GEN (1 << 1)
17433 +#define AuHnJob_DIRENT (1 << 2)
17434 +#define AuHnJob_ISDIR (1 << 3)
17435 +#define AuHnJob_TRYXINO0 (1 << 4)
17436 +#define AuHnJob_MNTPNT (1 << 5)
17437 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17438 +#define au_fset_hnjob(flags, name) \
17439 + do { (flags) |= AuHnJob_##name; } while (0)
17440 +#define au_fclr_hnjob(flags, name) \
17441 + do { (flags) &= ~AuHnJob_##name; } while (0)
17449 +struct au_hnotify_args {
17450 + struct inode *h_dir, *dir, *h_child_inode;
17452 + unsigned int flags[AuHnLast];
17453 + unsigned int h_child_nlen;
17454 + char h_child_name[];
17457 +struct hn_job_args {
17458 + unsigned int flags;
17459 + struct inode *inode, *h_inode, *dir, *h_dir;
17460 + struct dentry *dentry;
17465 +static int hn_job(struct hn_job_args *a)
17467 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17471 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17472 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17474 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17477 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17478 + if (!a->h_inode->i_nlink
17479 + && !(a->h_inode->i_state & I_LINKABLE))
17480 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17481 + inode_unlock_shared(a->h_inode);
17484 + /* make the generation obsolete */
17485 + if (au_ftest_hnjob(a->flags, GEN)) {
17488 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17490 + if (e && a->dentry)
17491 + hn_gen_by_name(a->dentry, isdir);
17492 + /* ignore this error */
17495 + /* make dir entries obsolete */
17496 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17497 + struct au_vdir *vdir;
17499 + vdir = au_ivdir(a->inode);
17501 + vdir->vd_jiffy = 0;
17502 + /* IMustLock(a->inode); */
17503 + /* inode_inc_iversion(a->inode); */
17506 + /* can do nothing but warn */
17507 + if (au_ftest_hnjob(a->flags, MNTPNT)
17509 + && d_mountpoint(a->dentry))
17510 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17515 +/* ---------------------------------------------------------------------- */
17517 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17518 + struct inode *dir)
17520 + struct dentry *dentry, *d, *parent;
17521 + struct qstr *dname;
17523 + parent = d_find_any_alias(dir);
17528 + spin_lock(&parent->d_lock);
17529 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17530 + /* AuDbg("%pd\n", d); */
17531 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17532 + dname = &d->d_name;
17533 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17534 + goto cont_unlock;
17538 + goto cont_unlock;
17539 + if (au_dcount(d) > 0) {
17540 + dentry = dget_dlock(d);
17541 + spin_unlock(&d->d_lock);
17546 + spin_unlock(&d->d_lock);
17548 + spin_unlock(&parent->d_lock);
17552 + di_write_lock_child(dentry);
17557 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17558 + aufs_bindex_t bindex, ino_t h_ino)
17560 + struct inode *inode;
17565 + err = au_xino_read(sb, bindex, h_ino, &ino);
17567 + inode = ilookup(sb, ino);
17571 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17572 + pr_warn("wrong root branch\n");
17578 + ii_write_lock_child(inode);
17584 +static void au_hn_bh(void *_args)
17586 + struct au_hnotify_args *a = _args;
17587 + struct super_block *sb;
17588 + aufs_bindex_t bindex, bbot, bfound;
17589 + unsigned char xino, try_iput;
17591 + struct inode *inode;
17593 + struct hn_job_args args;
17594 + struct dentry *dentry;
17595 + struct au_sbinfo *sbinfo;
17597 + AuDebugOn(!_args);
17598 + AuDebugOn(!a->h_dir);
17599 + AuDebugOn(!a->dir);
17600 + AuDebugOn(!a->mask);
17601 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17602 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17603 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17608 + * do not lock a->dir->i_mutex here
17609 + * because of d_revalidate() may cause a deadlock.
17611 + sb = a->dir->i_sb;
17613 + sbinfo = au_sbi(sb);
17614 + AuDebugOn(!sbinfo);
17615 + si_write_lock(sb, AuLock_NOPLMW);
17617 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17618 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17619 + case FS_MOVED_FROM:
17620 + case FS_MOVED_TO:
17621 + AuWarn1("DIRREN with UDBA may not work correctly "
17622 + "for the direct rename(2)\n");
17625 + ii_read_lock_parent(a->dir);
17627 + bbot = au_ibbot(a->dir);
17628 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17629 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17633 + ii_read_unlock(a->dir);
17634 + if (unlikely(bfound < 0))
17637 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17639 + if (a->h_child_inode)
17640 + h_ino = a->h_child_inode->i_ino;
17642 + if (a->h_child_nlen
17643 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17644 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17645 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17648 + if (dentry && d_really_is_positive(dentry))
17649 + inode = d_inode(dentry);
17650 + if (xino && !inode && h_ino
17651 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17652 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17653 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17654 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17658 + args.flags = a->flags[AuHn_CHILD];
17659 + args.dentry = dentry;
17660 + args.inode = inode;
17661 + args.h_inode = a->h_child_inode;
17662 + args.dir = a->dir;
17663 + args.h_dir = a->h_dir;
17664 + args.h_name = a->h_child_name;
17665 + args.h_nlen = a->h_child_nlen;
17666 + err = hn_job(&args);
17668 + if (au_di(dentry))
17669 + di_write_unlock(dentry);
17672 + if (inode && try_iput) {
17673 + ii_write_unlock(inode);
17677 + ii_write_lock_parent(a->dir);
17678 + args.flags = a->flags[AuHn_PARENT];
17679 + args.dentry = NULL;
17680 + args.inode = a->dir;
17681 + args.h_inode = a->h_dir;
17683 + args.h_dir = NULL;
17684 + args.h_name = NULL;
17686 + err = hn_job(&args);
17687 + ii_write_unlock(a->dir);
17690 + iput(a->h_child_inode);
17693 + si_write_unlock(sb);
17694 + au_nwt_done(&sbinfo->si_nowait);
17698 +/* ---------------------------------------------------------------------- */
17700 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17701 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17704 + unsigned int flags[AuHnLast], f;
17705 + unsigned char isdir, isroot, wh;
17706 + struct inode *dir;
17707 + struct au_hnotify_args *args;
17708 + char *p, *h_child_name;
17711 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17712 + dir = igrab(hnotify->hn_aufs_inode);
17716 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17718 + h_child_name = (void *)h_child_qstr->name;
17719 + len = h_child_qstr->len;
17720 + if (h_child_name) {
17721 + if (len > AUFS_WH_PFX_LEN
17722 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17723 + h_child_name += AUFS_WH_PFX_LEN;
17724 + len -= AUFS_WH_PFX_LEN;
17730 + if (h_child_inode)
17731 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17732 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17733 + flags[AuHn_CHILD] = 0;
17735 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17736 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17737 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17738 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17739 + case FS_MOVED_FROM:
17740 + case FS_MOVED_TO:
17741 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17742 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17745 + AuDebugOn(!h_child_name);
17750 + * aufs never be able to get this child inode.
17751 + * revalidation should be in d_revalidate()
17752 + * by checking i_nlink, i_generation or d_unhashed().
17754 + AuDebugOn(!h_child_name);
17755 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17756 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17764 + h_child_inode = NULL;
17767 + /* iput() and kfree() will be called in au_hnotify() */
17768 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17769 + if (unlikely(!args)) {
17770 + AuErr1("no memory\n");
17774 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17775 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17776 + args->mask = mask;
17778 + args->h_dir = igrab(h_dir);
17779 + if (h_child_inode)
17780 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17781 + args->h_child_inode = h_child_inode;
17782 + args->h_child_nlen = len;
17784 + p = (void *)args;
17785 + p += sizeof(*args);
17786 + memcpy(p, h_child_name, len);
17790 + /* NFS fires the event for silly-renamed one from kworker */
17792 + if (!dir->i_nlink
17793 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17795 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17796 + if (unlikely(err)) {
17797 + pr_err("wkq %d\n", err);
17798 + iput(args->h_child_inode);
17799 + iput(args->h_dir);
17801 + au_kfree_rcu(args);
17808 +/* ---------------------------------------------------------------------- */
17810 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17814 + AuDebugOn(!(udba & AuOptMask_UDBA));
17817 + if (au_hnotify_op.reset_br)
17818 + err = au_hnotify_op.reset_br(udba, br, perm);
17823 +int au_hnotify_init_br(struct au_branch *br, int perm)
17828 + if (au_hnotify_op.init_br)
17829 + err = au_hnotify_op.init_br(br, perm);
17834 +void au_hnotify_fin_br(struct au_branch *br)
17836 + if (au_hnotify_op.fin_br)
17837 + au_hnotify_op.fin_br(br);
17840 +static void au_hn_destroy_cache(void)
17842 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17843 + au_cache[AuCache_HNOTIFY] = NULL;
17846 +int __init au_hnotify_init(void)
17851 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17852 + if (au_cache[AuCache_HNOTIFY]) {
17854 + if (au_hnotify_op.init)
17855 + err = au_hnotify_op.init();
17856 + if (unlikely(err))
17857 + au_hn_destroy_cache();
17863 +void au_hnotify_fin(void)
17865 + if (au_hnotify_op.fin)
17866 + au_hnotify_op.fin();
17868 + /* cf. au_cache_fin() */
17869 + if (au_cache[AuCache_HNOTIFY])
17870 + au_hn_destroy_cache();
17872 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17873 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17874 +++ linux/fs/aufs/iinfo.c 2020-01-27 10:57:18.175538316 +0100
17876 +// SPDX-License-Identifier: GPL-2.0
17878 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17880 + * This program, aufs is free software; you can redistribute it and/or modify
17881 + * it under the terms of the GNU General Public License as published by
17882 + * the Free Software Foundation; either version 2 of the License, or
17883 + * (at your option) any later version.
17885 + * This program is distributed in the hope that it will be useful,
17886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17888 + * GNU General Public License for more details.
17890 + * You should have received a copy of the GNU General Public License
17891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17895 + * inode private data
17900 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17902 + struct inode *h_inode;
17903 + struct au_hinode *hinode;
17905 + IiMustAnyLock(inode);
17907 + hinode = au_hinode(au_ii(inode), bindex);
17908 + h_inode = hinode->hi_inode;
17909 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17913 +/* todo: hard/soft set? */
17914 +void au_hiput(struct au_hinode *hinode)
17916 + au_hn_free(hinode);
17917 + dput(hinode->hi_whdentry);
17918 + iput(hinode->hi_inode);
17921 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17923 + unsigned int flags;
17924 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17927 + if (au_opt_test(mnt_flags, XINO))
17928 + au_fset_hi(flags, XINO);
17929 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17930 + au_fset_hi(flags, HNOTIFY);
17934 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17935 + struct inode *h_inode, unsigned int flags)
17937 + struct au_hinode *hinode;
17938 + struct inode *hi;
17939 + struct au_iinfo *iinfo = au_ii(inode);
17941 + IiMustWriteLock(inode);
17943 + hinode = au_hinode(iinfo, bindex);
17944 + hi = hinode->hi_inode;
17945 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17948 + au_hiput(hinode);
17949 + hinode->hi_inode = h_inode;
17952 + struct super_block *sb = inode->i_sb;
17953 + struct au_branch *br;
17955 + AuDebugOn(inode->i_mode
17956 + && (h_inode->i_mode & S_IFMT)
17957 + != (inode->i_mode & S_IFMT));
17958 + if (bindex == iinfo->ii_btop)
17959 + au_cpup_igen(inode, h_inode);
17960 + br = au_sbr(sb, bindex);
17961 + hinode->hi_id = br->br_id;
17962 + if (au_ftest_hi(flags, XINO)) {
17963 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17965 + if (unlikely(err))
17966 + AuIOErr1("failed au_xino_write() %d\n", err);
17969 + if (au_ftest_hi(flags, HNOTIFY)
17970 + && au_br_hnotifyable(br->br_perm)) {
17971 + err = au_hn_alloc(hinode, inode);
17972 + if (unlikely(err))
17973 + AuIOErr1("au_hn_alloc() %d\n", err);
17978 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17979 + struct dentry *h_wh)
17981 + struct au_hinode *hinode;
17983 + IiMustWriteLock(inode);
17985 + hinode = au_hinode(au_ii(inode), bindex);
17986 + AuDebugOn(hinode->hi_whdentry);
17987 + hinode->hi_whdentry = h_wh;
17990 +void au_update_iigen(struct inode *inode, int half)
17992 + struct au_iinfo *iinfo;
17993 + struct au_iigen *iigen;
17994 + unsigned int sigen;
17996 + sigen = au_sigen(inode->i_sb);
17997 + iinfo = au_ii(inode);
17998 + iigen = &iinfo->ii_generation;
17999 + spin_lock(&iigen->ig_spin);
18000 + iigen->ig_generation = sigen;
18002 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18004 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18005 + spin_unlock(&iigen->ig_spin);
18008 +/* it may be called at remount time, too */
18009 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18011 + struct au_iinfo *iinfo;
18012 + aufs_bindex_t bindex, bbot;
18014 + AuDebugOn(au_is_bad_inode(inode));
18015 + IiMustWriteLock(inode);
18017 + iinfo = au_ii(inode);
18018 + if (do_put_zero && iinfo->ii_btop >= 0) {
18019 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18021 + struct inode *h_i;
18023 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18026 + && !(h_i->i_state & I_LINKABLE))
18027 + au_set_h_iptr(inode, bindex, NULL, 0);
18031 + iinfo->ii_btop = -1;
18032 + iinfo->ii_bbot = -1;
18033 + bbot = au_sbbot(inode->i_sb);
18034 + for (bindex = 0; bindex <= bbot; bindex++)
18035 + if (au_hinode(iinfo, bindex)->hi_inode) {
18036 + iinfo->ii_btop = bindex;
18039 + if (iinfo->ii_btop >= 0)
18040 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18041 + if (au_hinode(iinfo, bindex)->hi_inode) {
18042 + iinfo->ii_bbot = bindex;
18045 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18048 +/* ---------------------------------------------------------------------- */
18050 +void au_icntnr_init_once(void *_c)
18052 + struct au_icntnr *c = _c;
18053 + struct au_iinfo *iinfo = &c->iinfo;
18055 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18056 + au_rw_init(&iinfo->ii_rwsem);
18057 + inode_init_once(&c->vfs_inode);
18060 +void au_hinode_init(struct au_hinode *hinode)
18062 + hinode->hi_inode = NULL;
18063 + hinode->hi_id = -1;
18064 + au_hn_init(hinode);
18065 + hinode->hi_whdentry = NULL;
18068 +int au_iinfo_init(struct inode *inode)
18070 + struct au_iinfo *iinfo;
18071 + struct super_block *sb;
18072 + struct au_hinode *hi;
18075 + sb = inode->i_sb;
18076 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18077 + nbr = au_sbbot(sb) + 1;
18078 + if (unlikely(nbr <= 0))
18080 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18082 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18084 + iinfo->ii_hinode = hi;
18085 + for (i = 0; i < nbr; i++, hi++)
18086 + au_hinode_init(hi);
18088 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18089 + iinfo->ii_btop = -1;
18090 + iinfo->ii_bbot = -1;
18091 + iinfo->ii_vdir = NULL;
18097 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18100 + struct au_hinode *hip;
18102 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18105 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18108 + iinfo->ii_hinode = hip;
18109 + i = iinfo->ii_bbot + 1;
18111 + for (; i < nbr; i++, hip++)
18112 + au_hinode_init(hip);
18119 +void au_iinfo_fin(struct inode *inode)
18121 + struct au_iinfo *iinfo;
18122 + struct au_hinode *hi;
18123 + struct super_block *sb;
18124 + aufs_bindex_t bindex, bbot;
18125 + const unsigned char unlinked = !inode->i_nlink;
18127 + AuDebugOn(au_is_bad_inode(inode));
18129 + sb = inode->i_sb;
18130 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18131 + if (si_pid_test(sb))
18132 + au_xino_delete_inode(inode, unlinked);
18135 + * it is safe to hide the dependency between sbinfo and
18139 + si_noflush_read_lock(sb);
18140 + au_xino_delete_inode(inode, unlinked);
18141 + si_read_unlock(sb);
18145 + iinfo = au_ii(inode);
18146 + if (iinfo->ii_vdir)
18147 + au_vdir_free(iinfo->ii_vdir);
18149 + bindex = iinfo->ii_btop;
18150 + if (bindex >= 0) {
18151 + hi = au_hinode(iinfo, bindex);
18152 + bbot = iinfo->ii_bbot;
18153 + while (bindex++ <= bbot) {
18154 + if (hi->hi_inode)
18159 + au_kfree_rcu(iinfo->ii_hinode);
18160 + AuRwDestroy(&iinfo->ii_rwsem);
18162 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18163 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18164 +++ linux/fs/aufs/inode.c 2020-01-27 10:57:18.175538316 +0100
18166 +// SPDX-License-Identifier: GPL-2.0
18168 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18170 + * This program, aufs is free software; you can redistribute it and/or modify
18171 + * it under the terms of the GNU General Public License as published by
18172 + * the Free Software Foundation; either version 2 of the License, or
18173 + * (at your option) any later version.
18175 + * This program is distributed in the hope that it will be useful,
18176 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18177 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18178 + * GNU General Public License for more details.
18180 + * You should have received a copy of the GNU General Public License
18181 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18185 + * inode functions
18188 +#include <linux/iversion.h>
18191 +struct inode *au_igrab(struct inode *inode)
18194 + AuDebugOn(!atomic_read(&inode->i_count));
18200 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18202 + au_cpup_attr_all(inode, /*force*/0);
18203 + au_update_iigen(inode, /*half*/1);
18205 + inode_inc_iversion(inode);
18208 +static int au_ii_refresh(struct inode *inode, int *update)
18212 + aufs_bindex_t bindex, new_bindex;
18213 + struct super_block *sb;
18214 + struct au_iinfo *iinfo;
18215 + struct au_hinode *p, *q, tmp;
18217 + AuDebugOn(au_is_bad_inode(inode));
18218 + IiMustWriteLock(inode);
18221 + sb = inode->i_sb;
18222 + nbr = au_sbbot(sb) + 1;
18223 + type = inode->i_mode & S_IFMT;
18224 + iinfo = au_ii(inode);
18225 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18226 + if (unlikely(err))
18229 + AuDebugOn(iinfo->ii_btop < 0);
18230 + p = au_hinode(iinfo, iinfo->ii_btop);
18231 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18233 + if (!p->hi_inode)
18236 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18237 + new_bindex = au_br_index(sb, p->hi_id);
18238 + if (new_bindex == bindex)
18241 + if (new_bindex < 0) {
18244 + p->hi_inode = NULL;
18248 + if (new_bindex < iinfo->ii_btop)
18249 + iinfo->ii_btop = new_bindex;
18250 + if (iinfo->ii_bbot < new_bindex)
18251 + iinfo->ii_bbot = new_bindex;
18252 + /* swap two lower inode, and loop again */
18253 + q = au_hinode(iinfo, new_bindex);
18257 + if (tmp.hi_inode) {
18262 + au_update_ibrange(inode, /*do_put_zero*/0);
18263 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18264 + e = au_dy_irefresh(inode);
18265 + if (unlikely(e && !err))
18273 +void au_refresh_iop(struct inode *inode, int force_getattr)
18276 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18277 + const struct inode_operations *iop
18278 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18280 + if (inode->i_op == iop)
18283 + switch (inode->i_mode & S_IFMT) {
18285 + type = AuIop_DIR;
18288 + type = AuIop_SYMLINK;
18291 + type = AuIop_OTHER;
18295 + inode->i_op = iop + type;
18296 + /* unnecessary smp_wmb() */
18299 +int au_refresh_hinode_self(struct inode *inode)
18303 + err = au_ii_refresh(inode, &update);
18305 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18311 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18313 + int err, e, update;
18314 + unsigned int flags;
18316 + aufs_bindex_t bindex, bbot;
18317 + unsigned char isdir;
18318 + struct au_hinode *p;
18319 + struct au_iinfo *iinfo;
18321 + err = au_ii_refresh(inode, &update);
18322 + if (unlikely(err))
18326 + iinfo = au_ii(inode);
18327 + p = au_hinode(iinfo, iinfo->ii_btop);
18328 + mode = (inode->i_mode & S_IFMT);
18329 + isdir = S_ISDIR(mode);
18330 + flags = au_hi_flags(inode, isdir);
18331 + bbot = au_dbbot(dentry);
18332 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18333 + struct inode *h_i, *h_inode;
18334 + struct dentry *h_d;
18336 + h_d = au_h_dptr(dentry, bindex);
18337 + if (!h_d || d_is_negative(h_d))
18340 + h_inode = d_inode(h_d);
18341 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18342 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18343 + h_i = au_h_iptr(inode, bindex);
18345 + if (h_i == h_inode)
18351 + if (bindex < iinfo->ii_btop)
18352 + iinfo->ii_btop = bindex;
18353 + if (iinfo->ii_bbot < bindex)
18354 + iinfo->ii_bbot = bindex;
18355 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18358 + au_update_ibrange(inode, /*do_put_zero*/0);
18359 + e = au_dy_irefresh(inode);
18360 + if (unlikely(e && !err))
18363 + au_refresh_hinode_attr(inode, update && isdir);
18370 +static int set_inode(struct inode *inode, struct dentry *dentry)
18373 + unsigned int flags;
18375 + aufs_bindex_t bindex, btop, btail;
18376 + unsigned char isdir;
18377 + struct dentry *h_dentry;
18378 + struct inode *h_inode;
18379 + struct au_iinfo *iinfo;
18380 + const struct inode_operations *iop;
18382 + IiMustWriteLock(inode);
18386 + iop = au_sbi(inode->i_sb)->si_iop_array;
18387 + btop = au_dbtop(dentry);
18388 + h_dentry = au_h_dptr(dentry, btop);
18389 + h_inode = d_inode(h_dentry);
18390 + mode = h_inode->i_mode;
18391 + switch (mode & S_IFMT) {
18393 + btail = au_dbtail(dentry);
18394 + inode->i_op = iop + AuIop_OTHER;
18395 + inode->i_fop = &aufs_file_fop;
18396 + err = au_dy_iaop(inode, btop, h_inode);
18397 + if (unlikely(err))
18402 + btail = au_dbtaildir(dentry);
18403 + inode->i_op = iop + AuIop_DIR;
18404 + inode->i_fop = &aufs_dir_fop;
18407 + btail = au_dbtail(dentry);
18408 + inode->i_op = iop + AuIop_SYMLINK;
18414 + btail = au_dbtail(dentry);
18415 + inode->i_op = iop + AuIop_OTHER;
18416 + init_special_inode(inode, mode, h_inode->i_rdev);
18419 + AuIOErr("Unknown file type 0%o\n", mode);
18424 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18425 + flags = au_hi_flags(inode, isdir);
18426 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18427 + && au_ftest_hi(flags, HNOTIFY)
18428 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18429 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18430 + au_fclr_hi(flags, HNOTIFY);
18431 + iinfo = au_ii(inode);
18432 + iinfo->ii_btop = btop;
18433 + iinfo->ii_bbot = btail;
18434 + for (bindex = btop; bindex <= btail; bindex++) {
18435 + h_dentry = au_h_dptr(dentry, bindex);
18437 + au_set_h_iptr(inode, bindex,
18438 + au_igrab(d_inode(h_dentry)), flags);
18440 + au_cpup_attr_all(inode, /*force*/1);
18442 + * to force calling aufs_get_acl() every time,
18443 + * do not call cache_no_acl() for aufs inode.
18451 + * successful returns with iinfo write_locked
18453 + * zero: success, matched
18454 + * plus: no error, but unmatched
18456 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18459 + unsigned int gen, igflags;
18460 + aufs_bindex_t bindex, bbot;
18461 + struct inode *h_inode, *h_dinode;
18462 + struct dentry *h_dentry;
18465 + * before this function, if aufs got any iinfo lock, it must be only
18466 + * one, the parent dir.
18467 + * it can happen by UDBA and the obsoleted inode number.
18470 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18474 + ii_write_lock_new_child(inode);
18475 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18476 + h_dinode = d_inode(h_dentry);
18477 + bbot = au_ibbot(inode);
18478 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18479 + h_inode = au_h_iptr(inode, bindex);
18480 + if (!h_inode || h_inode != h_dinode)
18484 + gen = au_iigen(inode, &igflags);
18485 + if (gen == au_digen(dentry)
18486 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18489 + /* fully refresh inode using dentry */
18490 + err = au_refresh_hinode(inode, dentry);
18492 + au_update_iigen(inode, /*half*/0);
18496 + if (unlikely(err))
18497 + ii_write_unlock(inode);
18502 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18503 + unsigned int d_type, ino_t *ino)
18506 + const int isnondir = d_type != DT_DIR;
18508 + /* prevent hardlinked inode number from race condition */
18510 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18511 + if (unlikely(err))
18515 + err = au_xino_read(sb, bindex, h_ino, ino);
18516 + if (unlikely(err))
18517 + goto out_xinondir;
18521 + *ino = au_xino_new_ino(sb);
18522 + if (unlikely(!*ino))
18523 + goto out_xinondir;
18524 + err = au_xino_write(sb, bindex, h_ino, *ino);
18525 + if (unlikely(err))
18526 + goto out_xinondir;
18530 + if (isnondir && idx >= 0)
18531 + au_xinondir_leave(sb, bindex, h_ino, idx);
18536 +/* successful returns with iinfo write_locked */
18537 +/* todo: return with unlocked? */
18538 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18540 + struct inode *inode, *h_inode;
18541 + struct dentry *h_dentry;
18542 + struct super_block *sb;
18543 + ino_t h_ino, ino;
18544 + int err, idx, hlinked;
18545 + aufs_bindex_t btop;
18547 + sb = dentry->d_sb;
18548 + btop = au_dbtop(dentry);
18549 + h_dentry = au_h_dptr(dentry, btop);
18550 + h_inode = d_inode(h_dentry);
18551 + h_ino = h_inode->i_ino;
18552 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18556 + * stop 'race'-ing between hardlinks under different
18560 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18561 + inode = ERR_PTR(err);
18562 + if (unlikely(err))
18566 + err = au_xino_read(sb, btop, h_ino, &ino);
18567 + inode = ERR_PTR(err);
18568 + if (unlikely(err))
18569 + goto out_xinondir;
18572 + ino = au_xino_new_ino(sb);
18573 + if (unlikely(!ino)) {
18574 + inode = ERR_PTR(-EIO);
18575 + goto out_xinondir;
18579 + AuDbg("i%lu\n", (unsigned long)ino);
18580 + inode = au_iget_locked(sb, ino);
18581 + err = PTR_ERR(inode);
18582 + if (IS_ERR(inode))
18583 + goto out_xinondir;
18585 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18586 + if (inode->i_state & I_NEW) {
18587 + ii_write_lock_new_child(inode);
18588 + err = set_inode(inode, dentry);
18590 + unlock_new_inode(inode);
18591 + goto out_xinondir; /* success */
18595 + * iget_failed() calls iput(), but we need to call
18596 + * ii_write_unlock() after iget_failed(). so dirty hack for
18599 + atomic_inc(&inode->i_count);
18600 + iget_failed(inode);
18601 + ii_write_unlock(inode);
18602 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18603 + /* ignore this error */
18605 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18607 + * horrible race condition between lookup, readdir and copyup
18608 + * (or something).
18610 + if (hlinked && idx >= 0)
18611 + au_xinondir_leave(sb, btop, h_ino, idx);
18612 + err = reval_inode(inode, dentry);
18613 + if (unlikely(err < 0)) {
18618 + goto out; /* success */
18619 + else if (hlinked && idx >= 0) {
18620 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18621 + if (unlikely(err)) {
18623 + inode = ERR_PTR(err);
18629 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18630 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18631 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18632 + btop, au_sbtype(h_dentry->d_sb), dentry,
18633 + (unsigned long)h_ino, (unsigned long)ino);
18635 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18638 + if (hlinked && idx >= 0)
18639 + au_xinondir_leave(sb, btop, h_ino, idx);
18645 + inode = ERR_PTR(err);
18647 + if (hlinked && idx >= 0)
18648 + au_xinondir_leave(sb, btop, h_ino, idx);
18653 +/* ---------------------------------------------------------------------- */
18655 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18656 + struct inode *inode)
18659 + struct inode *hi;
18661 + err = au_br_rdonly(au_sbr(sb, bindex));
18663 + /* pseudo-link after flushed may happen out of bounds */
18666 + && au_ibtop(inode) <= bindex
18667 + && bindex <= au_ibbot(inode)) {
18669 + * permission check is unnecessary since vfsub routine
18670 + * will be called later
18672 + hi = au_h_iptr(inode, bindex);
18674 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18680 +int au_test_h_perm(struct inode *h_inode, int mask)
18682 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18684 + return inode_permission(h_inode, mask);
18687 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18689 + if (au_test_nfs(h_inode->i_sb)
18690 + && (mask & MAY_WRITE)
18691 + && S_ISDIR(h_inode->i_mode))
18692 + mask |= MAY_READ; /* force permission check */
18693 + return au_test_h_perm(h_inode, mask);
18695 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18696 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18697 +++ linux/fs/aufs/inode.h 2020-01-27 10:57:18.175538316 +0100
18699 +/* SPDX-License-Identifier: GPL-2.0 */
18701 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18703 + * This program, aufs is free software; you can redistribute it and/or modify
18704 + * it under the terms of the GNU General Public License as published by
18705 + * the Free Software Foundation; either version 2 of the License, or
18706 + * (at your option) any later version.
18708 + * This program is distributed in the hope that it will be useful,
18709 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18710 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18711 + * GNU General Public License for more details.
18713 + * You should have received a copy of the GNU General Public License
18714 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18718 + * inode operations
18721 +#ifndef __AUFS_INODE_H__
18722 +#define __AUFS_INODE_H__
18726 +#include <linux/fsnotify.h>
18727 +#include "rwsem.h"
18731 +struct au_hnotify {
18732 +#ifdef CONFIG_AUFS_HNOTIFY
18733 +#ifdef CONFIG_AUFS_HFSNOTIFY
18734 + /* never use fsnotify_add_vfsmount_mark() */
18735 + struct fsnotify_mark hn_mark;
18737 + struct inode *hn_aufs_inode; /* no get/put */
18738 + struct rcu_head rcu;
18740 +} ____cacheline_aligned_in_smp;
18742 +struct au_hinode {
18743 + struct inode *hi_inode;
18744 + aufs_bindex_t hi_id;
18745 +#ifdef CONFIG_AUFS_HNOTIFY
18746 + struct au_hnotify *hi_notify;
18749 + /* reference to the copied-up whiteout with get/put */
18750 + struct dentry *hi_whdentry;
18754 +#define AuIG_HALF_REFRESHED 1
18755 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18756 +#define au_ig_fset(flags, name) \
18757 + do { (flags) |= AuIG_##name; } while (0)
18758 +#define au_ig_fclr(flags, name) \
18759 + do { (flags) &= ~AuIG_##name; } while (0)
18762 + spinlock_t ig_spin;
18763 + __u32 ig_generation, ig_flags;
18768 + struct au_iigen ii_generation;
18769 + struct super_block *ii_hsb1; /* no get/put */
18771 + struct au_rwsem ii_rwsem;
18772 + aufs_bindex_t ii_btop, ii_bbot;
18774 + struct au_hinode *ii_hinode;
18775 + struct au_vdir *ii_vdir;
18778 +struct au_icntnr {
18779 + struct au_iinfo iinfo;
18780 + struct inode vfs_inode;
18781 + struct hlist_bl_node plink;
18782 + struct rcu_head rcu;
18783 +} ____cacheline_aligned_in_smp;
18785 +/* au_pin flags */
18786 +#define AuPin_DI_LOCKED 1
18787 +#define AuPin_MNT_WRITE (1 << 1)
18788 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18789 +#define au_fset_pin(flags, name) \
18790 + do { (flags) |= AuPin_##name; } while (0)
18791 +#define au_fclr_pin(flags, name) \
18792 + do { (flags) &= ~AuPin_##name; } while (0)
18796 + struct dentry *dentry;
18797 + unsigned int udba;
18798 + unsigned char lsc_di, lsc_hi, flags;
18799 + aufs_bindex_t bindex;
18802 + struct dentry *parent;
18803 + struct au_hinode *hdir;
18804 + struct vfsmount *h_mnt;
18806 + /* temporary unlock/relock for copyup */
18807 + struct dentry *h_dentry, *h_parent;
18808 + struct au_branch *br;
18809 + struct task_struct *task;
18812 +void au_pin_hdir_unlock(struct au_pin *p);
18813 +int au_pin_hdir_lock(struct au_pin *p);
18814 +int au_pin_hdir_relock(struct au_pin *p);
18815 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18816 +void au_pin_hdir_release(struct au_pin *p);
18818 +/* ---------------------------------------------------------------------- */
18820 +static inline struct au_iinfo *au_ii(struct inode *inode)
18822 + BUG_ON(is_bad_inode(inode));
18823 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18826 +/* ---------------------------------------------------------------------- */
18829 +struct inode *au_igrab(struct inode *inode);
18830 +void au_refresh_iop(struct inode *inode, int force_getattr);
18831 +int au_refresh_hinode_self(struct inode *inode);
18832 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18833 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18834 + unsigned int d_type, ino_t *ino);
18835 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18836 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18837 + struct inode *inode);
18838 +int au_test_h_perm(struct inode *h_inode, int mask);
18839 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18841 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18842 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18844 +#ifdef CONFIG_AUFS_SHWH
18845 + return au_ino(sb, bindex, h_ino, d_type, ino);
18858 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18859 + aufs_iop_nogetattr[AuIop_Last];
18861 +/* au_wr_dir flags */
18862 +#define AuWrDir_ADD_ENTRY 1
18863 +#define AuWrDir_ISDIR (1 << 1)
18864 +#define AuWrDir_TMPFILE (1 << 2)
18865 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18866 +#define au_fset_wrdir(flags, name) \
18867 + do { (flags) |= AuWrDir_##name; } while (0)
18868 +#define au_fclr_wrdir(flags, name) \
18869 + do { (flags) &= ~AuWrDir_##name; } while (0)
18871 +struct au_wr_dir_args {
18872 + aufs_bindex_t force_btgt;
18873 + unsigned char flags;
18875 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18876 + struct au_wr_dir_args *args);
18878 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18879 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18880 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18881 + unsigned int udba, unsigned char flags);
18882 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18883 + unsigned int udba, unsigned char flags) __must_check;
18884 +int au_do_pin(struct au_pin *pin) __must_check;
18885 +void au_unpin(struct au_pin *pin);
18886 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18888 +#define AuIcpup_DID_CPUP 1
18889 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18890 +#define au_fset_icpup(flags, name) \
18891 + do { (flags) |= AuIcpup_##name; } while (0)
18892 +#define au_fclr_icpup(flags, name) \
18893 + do { (flags) &= ~AuIcpup_##name; } while (0)
18895 +struct au_icpup_args {
18896 + unsigned char flags;
18897 + unsigned char pin_flags;
18898 + aufs_bindex_t btgt;
18899 + unsigned int udba;
18900 + struct au_pin pin;
18901 + struct path h_path;
18902 + struct inode *h_inode;
18905 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18906 + struct au_icpup_args *a);
18908 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18912 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18913 + struct dentry *h_parent, int isdir);
18914 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18916 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18917 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18919 +struct vfsub_aopen_args;
18920 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18921 + struct vfsub_aopen_args *args);
18922 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18923 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18924 + struct dentry *dentry);
18925 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18928 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18929 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18930 + struct dentry *h_parent, int isdir);
18931 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18932 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18935 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18936 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18937 + struct inode *dir, struct dentry *dentry,
18938 + unsigned int flags);
18941 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18942 +void au_hiput(struct au_hinode *hinode);
18943 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18944 + struct dentry *h_wh);
18945 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18947 +/* hinode flags */
18948 +#define AuHi_XINO 1
18949 +#define AuHi_HNOTIFY (1 << 1)
18950 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18951 +#define au_fset_hi(flags, name) \
18952 + do { (flags) |= AuHi_##name; } while (0)
18953 +#define au_fclr_hi(flags, name) \
18954 + do { (flags) &= ~AuHi_##name; } while (0)
18956 +#ifndef CONFIG_AUFS_HNOTIFY
18957 +#undef AuHi_HNOTIFY
18958 +#define AuHi_HNOTIFY 0
18961 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18962 + struct inode *h_inode, unsigned int flags);
18964 +void au_update_iigen(struct inode *inode, int half);
18965 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18967 +void au_icntnr_init_once(void *_c);
18968 +void au_hinode_init(struct au_hinode *hinode);
18969 +int au_iinfo_init(struct inode *inode);
18970 +void au_iinfo_fin(struct inode *inode);
18971 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18973 +#ifdef CONFIG_PROC_FS
18975 +int au_plink_maint(struct super_block *sb, int flags);
18977 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18978 +int au_plink_maint_enter(struct super_block *sb);
18979 +#ifdef CONFIG_AUFS_DEBUG
18980 +void au_plink_list(struct super_block *sb);
18982 +AuStubVoid(au_plink_list, struct super_block *sb)
18984 +int au_plink_test(struct inode *inode);
18985 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18986 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18987 + struct dentry *h_dentry);
18988 +void au_plink_put(struct super_block *sb, int verbose);
18989 +void au_plink_clean(struct super_block *sb, int verbose);
18990 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18992 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18993 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18994 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18995 +AuStubVoid(au_plink_list, struct super_block *sb);
18996 +AuStubInt0(au_plink_test, struct inode *inode);
18997 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18998 + struct inode *inode, aufs_bindex_t bindex);
18999 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19000 + struct dentry *h_dentry);
19001 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19002 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19003 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19004 +#endif /* CONFIG_PROC_FS */
19006 +#ifdef CONFIG_AUFS_XATTR
19008 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19009 + unsigned int verbose);
19010 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19011 +void au_xattr_init(struct super_block *sb);
19013 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19014 + int ignore_flags, unsigned int verbose);
19015 +AuStubVoid(au_xattr_init, struct super_block *sb);
19018 +#ifdef CONFIG_FS_POSIX_ACL
19019 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19020 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19023 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19029 +struct au_sxattr {
19033 + const char *name;
19034 + const void *value;
19039 + struct posix_acl *acl;
19044 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19045 + struct au_sxattr *arg);
19048 +/* ---------------------------------------------------------------------- */
19050 +/* lock subclass for iinfo */
19052 + AuLsc_II_CHILD, /* child first */
19053 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19054 + AuLsc_II_CHILD3, /* copyup dirs */
19055 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19056 + AuLsc_II_PARENT2,
19057 + AuLsc_II_PARENT3, /* copyup dirs */
19058 + AuLsc_II_NEW_CHILD
19062 + * ii_read_lock_child, ii_write_lock_child,
19063 + * ii_read_lock_child2, ii_write_lock_child2,
19064 + * ii_read_lock_child3, ii_write_lock_child3,
19065 + * ii_read_lock_parent, ii_write_lock_parent,
19066 + * ii_read_lock_parent2, ii_write_lock_parent2,
19067 + * ii_read_lock_parent3, ii_write_lock_parent3,
19068 + * ii_read_lock_new_child, ii_write_lock_new_child,
19070 +#define AuReadLockFunc(name, lsc) \
19071 +static inline void ii_read_lock_##name(struct inode *i) \
19073 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19076 +#define AuWriteLockFunc(name, lsc) \
19077 +static inline void ii_write_lock_##name(struct inode *i) \
19079 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19082 +#define AuRWLockFuncs(name, lsc) \
19083 + AuReadLockFunc(name, lsc) \
19084 + AuWriteLockFunc(name, lsc)
19086 +AuRWLockFuncs(child, CHILD);
19087 +AuRWLockFuncs(child2, CHILD2);
19088 +AuRWLockFuncs(child3, CHILD3);
19089 +AuRWLockFuncs(parent, PARENT);
19090 +AuRWLockFuncs(parent2, PARENT2);
19091 +AuRWLockFuncs(parent3, PARENT3);
19092 +AuRWLockFuncs(new_child, NEW_CHILD);
19094 +#undef AuReadLockFunc
19095 +#undef AuWriteLockFunc
19096 +#undef AuRWLockFuncs
19098 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19099 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19100 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19102 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19103 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19104 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19106 +/* ---------------------------------------------------------------------- */
19108 +static inline void au_icntnr_init(struct au_icntnr *c)
19110 +#ifdef CONFIG_AUFS_DEBUG
19111 + c->vfs_inode.i_mode = 0;
19115 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19117 + unsigned int gen;
19118 + struct au_iinfo *iinfo;
19119 + struct au_iigen *iigen;
19121 + iinfo = au_ii(inode);
19122 + iigen = &iinfo->ii_generation;
19123 + spin_lock(&iigen->ig_spin);
19125 + *igflags = iigen->ig_flags;
19126 + gen = iigen->ig_generation;
19127 + spin_unlock(&iigen->ig_spin);
19132 +/* tiny test for inode number */
19133 +/* tmpfs generation is too rough */
19134 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19136 + struct au_iinfo *iinfo;
19138 + iinfo = au_ii(inode);
19139 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19140 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19141 + && iinfo->ii_higen == h_inode->i_generation);
19144 +static inline void au_iigen_dec(struct inode *inode)
19146 + struct au_iinfo *iinfo;
19147 + struct au_iigen *iigen;
19149 + iinfo = au_ii(inode);
19150 + iigen = &iinfo->ii_generation;
19151 + spin_lock(&iigen->ig_spin);
19152 + iigen->ig_generation--;
19153 + spin_unlock(&iigen->ig_spin);
19156 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19161 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19167 +/* ---------------------------------------------------------------------- */
19169 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19170 + aufs_bindex_t bindex)
19172 + return iinfo->ii_hinode + bindex;
19175 +static inline int au_is_bad_inode(struct inode *inode)
19177 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19180 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19181 + aufs_bindex_t bindex)
19183 + IiMustAnyLock(inode);
19184 + return au_hinode(au_ii(inode), bindex)->hi_id;
19187 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19189 + IiMustAnyLock(inode);
19190 + return au_ii(inode)->ii_btop;
19193 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19195 + IiMustAnyLock(inode);
19196 + return au_ii(inode)->ii_bbot;
19199 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19201 + IiMustAnyLock(inode);
19202 + return au_ii(inode)->ii_vdir;
19205 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19207 + IiMustAnyLock(inode);
19208 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19211 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19213 + IiMustWriteLock(inode);
19214 + au_ii(inode)->ii_btop = bindex;
19217 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19219 + IiMustWriteLock(inode);
19220 + au_ii(inode)->ii_bbot = bindex;
19223 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19225 + IiMustWriteLock(inode);
19226 + au_ii(inode)->ii_vdir = vdir;
19229 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19231 + IiMustAnyLock(inode);
19232 + return au_hinode(au_ii(inode), bindex);
19235 +/* ---------------------------------------------------------------------- */
19237 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19240 + return pin->parent;
19244 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19246 + if (pin && pin->hdir)
19247 + return pin->hdir->hi_inode;
19251 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19254 + return pin->hdir;
19258 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19261 + pin->dentry = dentry;
19264 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19265 + unsigned char lflag)
19269 + au_fset_pin(pin->flags, DI_LOCKED);
19271 + au_fclr_pin(pin->flags, DI_LOCKED);
19275 +#if 0 /* reserved */
19276 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19279 + dput(pin->parent);
19280 + pin->parent = dget(parent);
19285 +/* ---------------------------------------------------------------------- */
19288 +#ifdef CONFIG_AUFS_HNOTIFY
19289 +struct au_hnotify_op {
19290 + void (*ctl)(struct au_hinode *hinode, int do_set);
19291 + int (*alloc)(struct au_hinode *hinode);
19294 + * if it returns true, the the caller should free hinode->hi_notify,
19295 + * otherwise ->free() frees it.
19297 + int (*free)(struct au_hinode *hinode,
19298 + struct au_hnotify *hn) __must_check;
19300 + void (*fin)(void);
19301 + int (*init)(void);
19303 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19304 + void (*fin_br)(struct au_branch *br);
19305 + int (*init_br)(struct au_branch *br, int perm);
19309 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19310 +void au_hn_free(struct au_hinode *hinode);
19311 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19312 +void au_hn_reset(struct inode *inode, unsigned int flags);
19313 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19314 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19315 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19316 +int au_hnotify_init_br(struct au_branch *br, int perm);
19317 +void au_hnotify_fin_br(struct au_branch *br);
19318 +int __init au_hnotify_init(void);
19319 +void au_hnotify_fin(void);
19322 +extern const struct au_hnotify_op au_hnotify_op;
19325 +void au_hn_init(struct au_hinode *hinode)
19327 + hinode->hi_notify = NULL;
19330 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19332 + return hinode->hi_notify;
19336 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19337 + struct au_hinode *hinode __maybe_unused,
19338 + struct inode *inode __maybe_unused)
19339 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19340 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19341 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19342 + int do_set __maybe_unused)
19343 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19344 + unsigned int flags __maybe_unused)
19345 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19346 + struct au_branch *br __maybe_unused,
19347 + int perm __maybe_unused)
19348 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19349 + int perm __maybe_unused)
19350 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19351 +AuStubInt0(__init au_hnotify_init, void)
19352 +AuStubVoid(au_hnotify_fin, void)
19353 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19354 +#endif /* CONFIG_AUFS_HNOTIFY */
19356 +static inline void au_hn_suspend(struct au_hinode *hdir)
19358 + au_hn_ctl(hdir, /*do_set*/0);
19361 +static inline void au_hn_resume(struct au_hinode *hdir)
19363 + au_hn_ctl(hdir, /*do_set*/1);
19366 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19368 + inode_lock(hdir->hi_inode);
19369 + au_hn_suspend(hdir);
19372 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19373 + unsigned int sc __maybe_unused)
19375 + inode_lock_nested(hdir->hi_inode, sc);
19376 + au_hn_suspend(hdir);
19379 +#if 0 /* unused */
19380 +#include "vfsub.h"
19381 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19384 + inode_lock_shared_nested(hdir->hi_inode, sc);
19385 + au_hn_suspend(hdir);
19389 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19391 + au_hn_resume(hdir);
19392 + inode_unlock(hdir->hi_inode);
19395 +#endif /* __KERNEL__ */
19396 +#endif /* __AUFS_INODE_H__ */
19397 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19398 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19399 +++ linux/fs/aufs/ioctl.c 2020-01-27 10:57:18.175538316 +0100
19401 +// SPDX-License-Identifier: GPL-2.0
19403 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19405 + * This program, aufs is free software; you can redistribute it and/or modify
19406 + * it under the terms of the GNU General Public License as published by
19407 + * the Free Software Foundation; either version 2 of the License, or
19408 + * (at your option) any later version.
19410 + * This program is distributed in the hope that it will be useful,
19411 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19412 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19413 + * GNU General Public License for more details.
19415 + * You should have received a copy of the GNU General Public License
19416 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19421 + * plink-management and readdir in userspace.
19422 + * assist the pathconf(3) wrapper library.
19424 + * File-based Hierarchical Storage Management.
19427 +#include <linux/compat.h>
19428 +#include <linux/file.h>
19431 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19434 + aufs_bindex_t wbi, bindex, bbot;
19435 + struct file *h_file;
19436 + struct super_block *sb;
19437 + struct dentry *root;
19438 + struct au_branch *br;
19439 + struct aufs_wbr_fd wbrfd = {
19440 + .oflags = au_dir_roflags,
19443 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19444 + | O_NOATIME | O_CLOEXEC;
19446 + AuDebugOn(wbrfd.oflags & ~valid);
19449 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19450 + if (unlikely(err)) {
19456 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19457 + wbrfd.oflags |= au_dir_roflags;
19458 + AuDbg("0%o\n", wbrfd.oflags);
19459 + if (unlikely(wbrfd.oflags & ~valid))
19463 + fd = get_unused_fd_flags(0);
19465 + if (unlikely(fd < 0))
19468 + h_file = ERR_PTR(-EINVAL);
19471 + sb = path->dentry->d_sb;
19472 + root = sb->s_root;
19473 + aufs_read_lock(root, AuLock_IR);
19474 + bbot = au_sbbot(sb);
19475 + if (wbrfd.brid >= 0) {
19476 + wbi = au_br_index(sb, wbrfd.brid);
19477 + if (unlikely(wbi < 0 || wbi > bbot))
19481 + h_file = ERR_PTR(-ENOENT);
19482 + br = au_sbr(sb, wbi);
19483 + if (!au_br_writable(br->br_perm)) {
19487 + bindex = wbi + 1;
19489 + for (; bindex <= bbot; bindex++) {
19490 + br = au_sbr(sb, bindex);
19491 + if (au_br_writable(br->br_perm)) {
19493 + br = au_sbr(sb, wbi);
19498 + AuDbg("wbi %d\n", wbi);
19500 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19504 + aufs_read_unlock(root, AuLock_IR);
19505 + err = PTR_ERR(h_file);
19506 + if (IS_ERR(h_file))
19509 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19510 + fd_install(fd, h_file);
19512 + goto out; /* success */
19515 + put_unused_fd(fd);
19521 +/* ---------------------------------------------------------------------- */
19523 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19526 + struct dentry *dentry;
19529 + case AUFS_CTL_RDU:
19530 + case AUFS_CTL_RDU_INO:
19531 + err = au_rdu_ioctl(file, cmd, arg);
19534 + case AUFS_CTL_WBR_FD:
19535 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19538 + case AUFS_CTL_IBUSY:
19539 + err = au_ibusy_ioctl(file, arg);
19542 + case AUFS_CTL_BRINFO:
19543 + err = au_brinfo_ioctl(file, arg);
19546 + case AUFS_CTL_FHSM_FD:
19547 + dentry = file->f_path.dentry;
19548 + if (IS_ROOT(dentry))
19549 + err = au_fhsm_fd(dentry->d_sb, arg);
19555 + /* do not call the lower */
19556 + AuDbg("0x%x\n", cmd);
19564 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19569 + case AUFS_CTL_MVDOWN:
19570 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19573 + case AUFS_CTL_WBR_FD:
19574 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19578 + /* do not call the lower */
19579 + AuDbg("0x%x\n", cmd);
19587 +#ifdef CONFIG_COMPAT
19588 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19589 + unsigned long arg)
19594 + case AUFS_CTL_RDU:
19595 + case AUFS_CTL_RDU_INO:
19596 + err = au_rdu_compat_ioctl(file, cmd, arg);
19599 + case AUFS_CTL_IBUSY:
19600 + err = au_ibusy_compat_ioctl(file, arg);
19603 + case AUFS_CTL_BRINFO:
19604 + err = au_brinfo_compat_ioctl(file, arg);
19608 + err = aufs_ioctl_dir(file, cmd, arg);
19615 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19616 + unsigned long arg)
19618 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19621 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19622 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19623 +++ linux/fs/aufs/i_op_add.c 2020-01-27 10:57:18.172204883 +0100
19625 +// SPDX-License-Identifier: GPL-2.0
19627 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19629 + * This program, aufs is free software; you can redistribute it and/or modify
19630 + * it under the terms of the GNU General Public License as published by
19631 + * the Free Software Foundation; either version 2 of the License, or
19632 + * (at your option) any later version.
19634 + * This program is distributed in the hope that it will be useful,
19635 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19636 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19637 + * GNU General Public License for more details.
19639 + * You should have received a copy of the GNU General Public License
19640 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19644 + * inode operations (add entry)
19647 +#include <linux/iversion.h>
19651 + * final procedure of adding a new entry, except link(2).
19652 + * remove whiteout, instantiate, copyup the parent dir's times and size
19653 + * and update version.
19654 + * if it failed, re-create the removed whiteout.
19656 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19657 + struct dentry *wh_dentry, struct dentry *dentry)
19660 + aufs_bindex_t bwh;
19661 + struct path h_path;
19662 + struct super_block *sb;
19663 + struct inode *inode, *h_dir;
19664 + struct dentry *wh;
19669 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19670 + IMustLock(h_dir);
19671 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19672 + bwh = au_dbwh(dentry);
19673 + h_path.dentry = wh_dentry;
19674 + h_path.mnt = au_sbr_mnt(sb, bindex);
19675 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19677 + if (unlikely(err))
19681 + inode = au_new_inode(dentry, /*must_new*/1);
19682 + if (!IS_ERR(inode)) {
19683 + d_instantiate(dentry, inode);
19684 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19686 + au_dir_ts(dir, bindex);
19687 + inode_inc_iversion(dir);
19688 + au_fhsm_wrote(sb, bindex, /*force*/0);
19689 + return 0; /* success */
19692 + err = PTR_ERR(inode);
19697 + /* dir inode is locked */
19698 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19699 + rerr = PTR_ERR(wh);
19700 + if (IS_ERR(wh)) {
19701 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19702 + dentry, err, rerr);
19711 +static int au_d_may_add(struct dentry *dentry)
19716 + if (unlikely(d_unhashed(dentry)))
19718 + if (unlikely(d_really_is_positive(dentry)))
19724 + * simple tests for the adding inode operations.
19725 + * following the checks in vfs, plus the parent-child relationship.
19727 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19728 + struct dentry *h_parent, int isdir)
19732 + struct dentry *h_dentry;
19733 + struct inode *h_inode;
19735 + err = -ENAMETOOLONG;
19736 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19739 + h_dentry = au_h_dptr(dentry, bindex);
19740 + if (d_really_is_negative(dentry)) {
19742 + if (unlikely(d_is_positive(h_dentry)))
19745 + /* rename(2) case */
19747 + if (unlikely(d_is_negative(h_dentry)))
19749 + h_inode = d_inode(h_dentry);
19750 + if (unlikely(!h_inode->i_nlink))
19753 + h_mode = h_inode->i_mode;
19756 + if (unlikely(S_ISDIR(h_mode)))
19758 + } else if (unlikely(!S_ISDIR(h_mode))) {
19765 + /* expected parent dir is locked */
19766 + if (unlikely(h_parent != h_dentry->d_parent))
19775 + * initial procedure of adding a new entry.
19776 + * prepare writable branch and the parent dir, lock it,
19777 + * and lookup whiteout for the new entry.
19779 +static struct dentry*
19780 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19781 + struct dentry *src_dentry, struct au_pin *pin,
19782 + struct au_wr_dir_args *wr_dir_args)
19784 + struct dentry *wh_dentry, *h_parent;
19785 + struct super_block *sb;
19786 + struct au_branch *br;
19788 + unsigned int udba;
19789 + aufs_bindex_t bcpup;
19791 + AuDbg("%pd\n", dentry);
19793 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19795 + wh_dentry = ERR_PTR(err);
19796 + if (unlikely(err < 0))
19799 + sb = dentry->d_sb;
19800 + udba = au_opt_udba(sb);
19801 + err = au_pin(pin, dentry, bcpup, udba,
19802 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19803 + wh_dentry = ERR_PTR(err);
19804 + if (unlikely(err))
19807 + h_parent = au_pinned_h_parent(pin);
19808 + if (udba != AuOpt_UDBA_NONE
19809 + && au_dbtop(dentry) == bcpup)
19810 + err = au_may_add(dentry, bcpup, h_parent,
19811 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19812 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19813 + err = -ENAMETOOLONG;
19814 + wh_dentry = ERR_PTR(err);
19815 + if (unlikely(err))
19818 + br = au_sbr(sb, bcpup);
19820 + struct path tmp = {
19821 + .dentry = h_parent,
19822 + .mnt = au_br_mnt(br)
19824 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19827 + wh_dentry = NULL;
19828 + if (bcpup != au_dbwh(dentry))
19829 + goto out; /* success */
19832 + * ENAMETOOLONG here means that if we allowed create such name, then it
19833 + * would not be able to removed in the future. So we don't allow such
19834 + * name here and we don't handle ENAMETOOLONG differently here.
19836 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19839 + if (IS_ERR(wh_dentry))
19842 + return wh_dentry;
19845 +/* ---------------------------------------------------------------------- */
19847 +enum { Mknod, Symlink, Creat };
19848 +struct simple_arg {
19855 + struct vfsub_aopen_args *aopen;
19858 + const char *symname;
19867 +static int add_simple(struct inode *dir, struct dentry *dentry,
19868 + struct simple_arg *arg)
19871 + aufs_bindex_t btop;
19872 + unsigned char created;
19873 + const unsigned char try_aopen
19874 + = (arg->type == Creat && arg->u.c.try_aopen);
19875 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19876 + struct dentry *wh_dentry, *parent;
19877 + struct inode *h_dir;
19878 + struct super_block *sb;
19879 + struct au_branch *br;
19880 + /* to reduce stack size */
19882 + struct au_dtime dt;
19883 + struct au_pin pin;
19884 + struct path h_path;
19885 + struct au_wr_dir_args wr_dir_args;
19888 + AuDbg("%pd\n", dentry);
19892 + a = kmalloc(sizeof(*a), GFP_NOFS);
19893 + if (unlikely(!a))
19895 + a->wr_dir_args.force_btgt = -1;
19896 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19898 + parent = dentry->d_parent; /* dir inode is locked */
19899 + if (!try_aopen) {
19900 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19901 + if (unlikely(err))
19904 + err = au_d_may_add(dentry);
19905 + if (unlikely(err))
19908 + di_write_lock_parent(parent);
19909 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19910 + &a->pin, &a->wr_dir_args);
19911 + err = PTR_ERR(wh_dentry);
19912 + if (IS_ERR(wh_dentry))
19915 + btop = au_dbtop(dentry);
19916 + sb = dentry->d_sb;
19917 + br = au_sbr(sb, btop);
19918 + a->h_path.dentry = au_h_dptr(dentry, btop);
19919 + a->h_path.mnt = au_br_mnt(br);
19920 + h_dir = au_pinned_h_dir(&a->pin);
19921 + switch (arg->type) {
19923 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19924 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19925 + arg->u.c.want_excl);
19927 + if (!err && try_aopen)
19928 + aopen->file->f_mode |= FMODE_CREATED;
19931 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19932 + AuDbg("err %d\n", err);
19933 + AuDbgFile(aopen->file);
19934 + created = err >= 0
19935 + && !!(aopen->file->f_mode & FMODE_CREATED);
19939 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19943 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19950 + if (unlikely(err < 0))
19953 + err = epilog(dir, btop, wh_dentry, dentry);
19955 + goto out_unpin; /* success */
19958 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19959 + /* no delegation since it is just created */
19960 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19963 + AuIOErr("%pd revert failure(%d, %d)\n",
19964 + dentry, err, rerr);
19967 + au_dtime_revert(&a->dt);
19969 + if (try_aopen && h_dir->i_op->atomic_open
19970 + && (aopen->file->f_mode & FMODE_OPENED))
19971 + /* aopen->file is still opened */
19972 + au_lcnt_dec(&aopen->br->br_nfiles);
19975 + au_unpin(&a->pin);
19979 + di_write_unlock(parent);
19981 + if (unlikely(err)) {
19982 + au_update_dbtop(dentry);
19986 + aufs_read_unlock(dentry, AuLock_DW);
19993 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19996 + struct simple_arg arg = {
20003 + return add_simple(dir, dentry, &arg);
20006 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20008 + struct simple_arg arg = {
20010 + .u.s.symname = symname
20012 + return add_simple(dir, dentry, &arg);
20015 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20018 + struct simple_arg arg = {
20022 + .want_excl = want_excl
20025 + return add_simple(dir, dentry, &arg);
20028 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20029 + struct vfsub_aopen_args *aopen_args)
20031 + struct simple_arg arg = {
20034 + .mode = aopen_args->create_mode,
20035 + .want_excl = aopen_args->open_flag & O_EXCL,
20036 + .try_aopen = true,
20037 + .aopen = aopen_args
20040 + return add_simple(dir, dentry, &arg);
20043 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20046 + aufs_bindex_t bindex;
20047 + struct super_block *sb;
20048 + struct dentry *parent, *h_parent, *h_dentry;
20049 + struct inode *h_dir, *inode;
20050 + struct vfsmount *h_mnt;
20051 + struct au_wr_dir_args wr_dir_args = {
20052 + .force_btgt = -1,
20053 + .flags = AuWrDir_TMPFILE
20056 + /* copy-up may happen */
20060 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20061 + if (unlikely(err))
20064 + err = au_di_init(dentry);
20065 + if (unlikely(err))
20069 + parent = d_find_any_alias(dir);
20070 + AuDebugOn(!parent);
20071 + di_write_lock_parent(parent);
20072 + if (unlikely(d_inode(parent) != dir))
20075 + err = au_digen_test(parent, au_sigen(sb));
20076 + if (unlikely(err))
20079 + bindex = au_dbtop(parent);
20080 + au_set_dbtop(dentry, bindex);
20081 + au_set_dbbot(dentry, bindex);
20082 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20084 + if (unlikely(err < 0))
20087 + err = -EOPNOTSUPP;
20088 + h_dir = au_h_iptr(dir, bindex);
20089 + if (unlikely(!h_dir->i_op->tmpfile))
20092 + h_mnt = au_sbr_mnt(sb, bindex);
20093 + err = vfsub_mnt_want_write(h_mnt);
20094 + if (unlikely(err))
20097 + h_parent = au_h_dptr(parent, bindex);
20098 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20099 + if (IS_ERR(h_dentry)) {
20100 + err = PTR_ERR(h_dentry);
20104 + au_set_dbtop(dentry, bindex);
20105 + au_set_dbbot(dentry, bindex);
20106 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20107 + inode = au_new_inode(dentry, /*must_new*/1);
20108 + if (IS_ERR(inode)) {
20109 + err = PTR_ERR(inode);
20110 + au_set_h_dptr(dentry, bindex, NULL);
20111 + au_set_dbtop(dentry, -1);
20112 + au_set_dbbot(dentry, -1);
20114 + if (!inode->i_nlink)
20115 + set_nlink(inode, 1);
20116 + d_tmpfile(dentry, inode);
20117 + au_di(dentry)->di_tmpfile = 1;
20119 + /* update without i_mutex */
20120 + if (au_ibtop(dir) == au_dbtop(dentry))
20121 + au_cpup_attr_timesizes(dir);
20126 + vfsub_mnt_drop_write(h_mnt);
20128 + di_write_unlock(parent);
20130 + di_write_unlock(dentry);
20131 + if (unlikely(err)) {
20132 + au_di_fin(dentry);
20133 + dentry->d_fsdata = NULL;
20136 + si_read_unlock(sb);
20138 + inode_unlock(dir);
20142 +/* ---------------------------------------------------------------------- */
20144 +struct au_link_args {
20145 + aufs_bindex_t bdst, bsrc;
20146 + struct au_pin pin;
20147 + struct path h_path;
20148 + struct dentry *src_parent, *parent;
20151 +static int au_cpup_before_link(struct dentry *src_dentry,
20152 + struct au_link_args *a)
20155 + struct dentry *h_src_dentry;
20156 + struct au_cp_generic cpg = {
20157 + .dentry = src_dentry,
20162 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20165 + di_read_lock_parent(a->src_parent, AuLock_IR);
20166 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20167 + if (unlikely(err))
20170 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20171 + err = au_pin(&a->pin, src_dentry, a->bdst,
20172 + au_opt_udba(src_dentry->d_sb),
20173 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20174 + if (unlikely(err))
20177 + err = au_sio_cpup_simple(&cpg);
20178 + au_unpin(&a->pin);
20181 + di_read_unlock(a->src_parent, AuLock_IR);
20185 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20186 + struct au_link_args *a)
20189 + unsigned char plink;
20190 + aufs_bindex_t bbot;
20191 + struct dentry *h_src_dentry;
20192 + struct inode *h_inode, *inode, *delegated;
20193 + struct super_block *sb;
20194 + struct file *h_file;
20198 + sb = src_dentry->d_sb;
20199 + inode = d_inode(src_dentry);
20200 + if (au_ibtop(inode) <= a->bdst)
20201 + h_inode = au_h_iptr(inode, a->bdst);
20202 + if (!h_inode || !h_inode->i_nlink) {
20203 + /* copyup src_dentry as the name of dentry. */
20204 + bbot = au_dbbot(dentry);
20205 + if (bbot < a->bsrc)
20206 + au_set_dbbot(dentry, a->bsrc);
20207 + au_set_h_dptr(dentry, a->bsrc,
20208 + dget(au_h_dptr(src_dentry, a->bsrc)));
20209 + dget(a->h_path.dentry);
20210 + au_set_h_dptr(dentry, a->bdst, NULL);
20211 + AuDbg("temporary d_inode...\n");
20212 + spin_lock(&dentry->d_lock);
20213 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20214 + spin_unlock(&dentry->d_lock);
20215 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20216 + if (IS_ERR(h_file))
20217 + err = PTR_ERR(h_file);
20219 + struct au_cp_generic cpg = {
20220 + .dentry = dentry,
20225 + .flags = AuCpup_KEEPLINO
20227 + err = au_sio_cpup_simple(&cpg);
20228 + au_h_open_post(dentry, a->bsrc, h_file);
20230 + dput(a->h_path.dentry);
20231 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20233 + au_set_h_dptr(dentry, a->bdst,
20234 + a->h_path.dentry);
20236 + spin_lock(&dentry->d_lock);
20237 + dentry->d_inode = NULL; /* restore */
20238 + spin_unlock(&dentry->d_lock);
20239 + AuDbg("temporary d_inode...done\n");
20240 + au_set_h_dptr(dentry, a->bsrc, NULL);
20241 + au_set_dbbot(dentry, bbot);
20243 + /* the inode of src_dentry already exists on a.bdst branch */
20244 + h_src_dentry = d_find_alias(h_inode);
20245 + if (!h_src_dentry && au_plink_test(inode)) {
20247 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20248 + err = PTR_ERR(h_src_dentry);
20249 + if (IS_ERR(h_src_dentry))
20252 + if (unlikely(d_is_negative(h_src_dentry))) {
20253 + dput(h_src_dentry);
20254 + h_src_dentry = NULL;
20258 + if (h_src_dentry) {
20259 + delegated = NULL;
20260 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20261 + &a->h_path, &delegated);
20262 + if (unlikely(err == -EWOULDBLOCK)) {
20263 + pr_warn("cannot retry for NFSv4 delegation"
20264 + " for an internal link\n");
20267 + dput(h_src_dentry);
20269 + AuIOErr("no dentry found for hi%lu on b%d\n",
20270 + h_inode->i_ino, a->bdst);
20275 + if (!err && !plink)
20276 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20283 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20284 + struct dentry *dentry)
20287 + struct au_dtime dt;
20288 + struct au_link_args *a;
20289 + struct dentry *wh_dentry, *h_src_dentry;
20290 + struct inode *inode, *delegated;
20291 + struct super_block *sb;
20292 + struct au_wr_dir_args wr_dir_args = {
20293 + /* .force_btgt = -1, */
20294 + .flags = AuWrDir_ADD_ENTRY
20298 + inode = d_inode(src_dentry);
20299 + IMustLock(inode);
20302 + a = kzalloc(sizeof(*a), GFP_NOFS);
20303 + if (unlikely(!a))
20306 + a->parent = dentry->d_parent; /* dir inode is locked */
20307 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20308 + AuLock_NOPLM | AuLock_GEN);
20309 + if (unlikely(err))
20311 + err = au_d_linkable(src_dentry);
20312 + if (unlikely(err))
20314 + err = au_d_may_add(dentry);
20315 + if (unlikely(err))
20318 + a->src_parent = dget_parent(src_dentry);
20319 + wr_dir_args.force_btgt = au_ibtop(inode);
20321 + di_write_lock_parent(a->parent);
20322 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20323 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20325 + err = PTR_ERR(wh_dentry);
20326 + if (IS_ERR(wh_dentry))
20330 + sb = dentry->d_sb;
20331 + a->bdst = au_dbtop(dentry);
20332 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20333 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20334 + a->bsrc = au_ibtop(inode);
20335 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20336 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20337 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20338 + if (!h_src_dentry) {
20339 + a->bsrc = au_dbtop(src_dentry);
20340 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20341 + AuDebugOn(!h_src_dentry);
20342 + } else if (IS_ERR(h_src_dentry)) {
20343 + err = PTR_ERR(h_src_dentry);
20348 + * aufs doesn't touch the credential so
20349 + * security_dentry_create_files_as() is unnecessary.
20351 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20352 + if (a->bdst < a->bsrc
20353 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20354 + err = au_cpup_or_link(src_dentry, dentry, a);
20356 + delegated = NULL;
20357 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20358 + &a->h_path, &delegated);
20359 + if (unlikely(err == -EWOULDBLOCK)) {
20360 + pr_warn("cannot retry for NFSv4 delegation"
20361 + " for an internal link\n");
20365 + dput(h_src_dentry);
20368 + * copyup src_dentry to the branch we process,
20369 + * and then link(2) to it.
20371 + dput(h_src_dentry);
20372 + if (a->bdst < a->bsrc
20373 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20374 + au_unpin(&a->pin);
20375 + di_write_unlock(a->parent);
20376 + err = au_cpup_before_link(src_dentry, a);
20377 + di_write_lock_parent(a->parent);
20379 + err = au_pin(&a->pin, dentry, a->bdst,
20381 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20382 + if (unlikely(err))
20386 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20388 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20389 + delegated = NULL;
20390 + err = vfsub_link(h_src_dentry,
20391 + au_pinned_h_dir(&a->pin),
20392 + &a->h_path, &delegated);
20393 + if (unlikely(err == -EWOULDBLOCK)) {
20394 + pr_warn("cannot retry"
20395 + " for NFSv4 delegation"
20396 + " for an internal link\n");
20402 + if (unlikely(err))
20406 + a->h_path.dentry = wh_dentry;
20407 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20409 + if (unlikely(err))
20413 + au_dir_ts(dir, a->bdst);
20414 + inode_inc_iversion(dir);
20415 + inc_nlink(inode);
20416 + inode->i_ctime = dir->i_ctime;
20417 + d_instantiate(dentry, au_igrab(inode));
20418 + if (d_unhashed(a->h_path.dentry))
20419 + /* some filesystem calls d_drop() */
20421 + /* some filesystems consume an inode even hardlink */
20422 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20423 + goto out_unpin; /* success */
20426 + /* no delegation since it is just created */
20427 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20428 + /*delegated*/NULL, /*force*/0);
20429 + if (unlikely(rerr)) {
20430 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20433 + au_dtime_revert(&dt);
20435 + au_unpin(&a->pin);
20439 + di_write_unlock(a->parent);
20440 + dput(a->src_parent);
20442 + if (unlikely(err)) {
20443 + au_update_dbtop(dentry);
20446 + aufs_read_and_write_unlock2(dentry, src_dentry);
20454 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20457 + aufs_bindex_t bindex;
20458 + unsigned char diropq;
20459 + struct path h_path;
20460 + struct dentry *wh_dentry, *parent, *opq_dentry;
20461 + struct inode *h_inode;
20462 + struct super_block *sb;
20464 + struct au_pin pin;
20465 + struct au_dtime dt;
20466 + } *a; /* reduce the stack usage */
20467 + struct au_wr_dir_args wr_dir_args = {
20468 + .force_btgt = -1,
20469 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20475 + a = kmalloc(sizeof(*a), GFP_NOFS);
20476 + if (unlikely(!a))
20479 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20480 + if (unlikely(err))
20482 + err = au_d_may_add(dentry);
20483 + if (unlikely(err))
20486 + parent = dentry->d_parent; /* dir inode is locked */
20487 + di_write_lock_parent(parent);
20488 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20489 + &a->pin, &wr_dir_args);
20490 + err = PTR_ERR(wh_dentry);
20491 + if (IS_ERR(wh_dentry))
20494 + sb = dentry->d_sb;
20495 + bindex = au_dbtop(dentry);
20496 + h_path.dentry = au_h_dptr(dentry, bindex);
20497 + h_path.mnt = au_sbr_mnt(sb, bindex);
20498 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20499 + if (unlikely(err))
20502 + /* make the dir opaque */
20504 + h_inode = d_inode(h_path.dentry);
20506 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20507 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20508 + opq_dentry = au_diropq_create(dentry, bindex);
20509 + inode_unlock(h_inode);
20510 + err = PTR_ERR(opq_dentry);
20511 + if (IS_ERR(opq_dentry))
20513 + dput(opq_dentry);
20517 + err = epilog(dir, bindex, wh_dentry, dentry);
20520 + goto out_unpin; /* success */
20525 + AuLabel(revert opq);
20526 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20527 + rerr = au_diropq_remove(dentry, bindex);
20528 + inode_unlock(h_inode);
20530 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20531 + dentry, err, rerr);
20537 + AuLabel(revert dir);
20538 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20540 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20541 + dentry, err, rerr);
20544 + au_dtime_revert(&a->dt);
20546 + au_unpin(&a->pin);
20549 + di_write_unlock(parent);
20551 + if (unlikely(err)) {
20552 + au_update_dbtop(dentry);
20555 + aufs_read_unlock(dentry, AuLock_DW);
20561 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20562 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20563 +++ linux/fs/aufs/i_op.c 2020-04-03 08:16:47.547461775 +0200
20565 +// SPDX-License-Identifier: GPL-2.0
20567 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20569 + * This program, aufs is free software; you can redistribute it and/or modify
20570 + * it under the terms of the GNU General Public License as published by
20571 + * the Free Software Foundation; either version 2 of the License, or
20572 + * (at your option) any later version.
20574 + * This program is distributed in the hope that it will be useful,
20575 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20576 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20577 + * GNU General Public License for more details.
20579 + * You should have received a copy of the GNU General Public License
20580 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20584 + * inode operations (except add/del/rename)
20587 +#include <linux/device_cgroup.h>
20588 +#include <linux/fs_stack.h>
20589 +#include <linux/iversion.h>
20590 +#include <linux/namei.h>
20591 +#include <linux/security.h>
20594 +static int h_permission(struct inode *h_inode, int mask,
20595 + struct path *h_path, int brperm)
20598 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20601 + if (write_mask && IS_IMMUTABLE(h_inode))
20605 + if (((mask & MAY_EXEC)
20606 + && S_ISREG(h_inode->i_mode)
20607 + && (path_noexec(h_path)
20608 + || !(h_inode->i_mode & 0111))))
20612 + * - skip the lower fs test in the case of write to ro branch.
20613 + * - nfs dir permission write check is optimized, but a policy for
20614 + * link/rename requires a real check.
20615 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20616 + * in this case, generic_permission() returns -EOPNOTSUPP.
20618 + if ((write_mask && !au_br_writable(brperm))
20619 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20620 + && write_mask && !(mask & MAY_READ))
20621 + || !h_inode->i_op->permission) {
20622 + /* AuLabel(generic_permission); */
20623 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20624 + err = generic_permission(h_inode, mask);
20625 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20626 + err = h_inode->i_op->permission(h_inode, mask);
20629 + /* AuLabel(h_inode->permission); */
20630 + err = h_inode->i_op->permission(h_inode, mask);
20635 + err = devcgroup_inode_permission(h_inode, mask);
20637 + err = security_inode_permission(h_inode, mask);
20643 +static int aufs_permission(struct inode *inode, int mask)
20646 + aufs_bindex_t bindex, bbot;
20647 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20648 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20649 + struct inode *h_inode;
20650 + struct super_block *sb;
20651 + struct au_branch *br;
20653 + /* todo: support rcu-walk? */
20654 + if (mask & MAY_NOT_BLOCK)
20657 + sb = inode->i_sb;
20658 + si_read_lock(sb, AuLock_FLUSH);
20659 + ii_read_lock_child(inode);
20660 +#if 0 /* reserved for future use */
20662 + * This test may be rather 'too much' since the test is essentially done
20663 + * in the aufs_lookup(). Theoretically it is possible that the inode
20664 + * generation doesn't match to the superblock's here. But it isn't a
20665 + * big deal I suppose.
20667 + err = au_iigen_test(inode, au_sigen(sb));
20668 + if (unlikely(err))
20674 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20675 + err = au_busy_or_stale();
20676 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20677 + if (unlikely(!h_inode
20678 + || (h_inode->i_mode & S_IFMT)
20679 + != (inode->i_mode & S_IFMT)))
20683 + bindex = au_ibtop(inode);
20684 + br = au_sbr(sb, bindex);
20685 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20688 + && !special_file(h_inode->i_mode)) {
20689 + /* test whether the upper writable branch exists */
20691 + for (; bindex >= 0; bindex--)
20692 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20700 + /* non-write to dir */
20702 + bbot = au_ibbot(inode);
20703 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20704 + h_inode = au_h_iptr(inode, bindex);
20706 + err = au_busy_or_stale();
20707 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20710 + br = au_sbr(sb, bindex);
20711 + err = h_permission(h_inode, mask, &br->br_path,
20717 + ii_read_unlock(inode);
20718 + si_read_unlock(sb);
20722 +/* ---------------------------------------------------------------------- */
20724 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20725 + unsigned int flags)
20727 + struct dentry *ret, *parent;
20728 + struct inode *inode;
20729 + struct super_block *sb;
20730 + int err, npositive;
20734 + /* todo: support rcu-walk? */
20735 + ret = ERR_PTR(-ECHILD);
20736 + if (flags & LOOKUP_RCU)
20739 + ret = ERR_PTR(-ENAMETOOLONG);
20740 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20744 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20745 + ret = ERR_PTR(err);
20746 + if (unlikely(err))
20749 + err = au_di_init(dentry);
20750 + ret = ERR_PTR(err);
20751 + if (unlikely(err))
20755 + npositive = 0; /* suppress a warning */
20756 + parent = dentry->d_parent; /* dir inode is locked */
20757 + di_read_lock_parent(parent, AuLock_IR);
20758 + err = au_alive_dir(parent);
20760 + err = au_digen_test(parent, au_sigen(sb));
20762 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20763 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20764 + AuLkup_ALLOW_NEG);
20767 + di_read_unlock(parent, AuLock_IR);
20768 + ret = ERR_PTR(err);
20769 + if (unlikely(err < 0))
20773 + inode = au_new_inode(dentry, /*must_new*/0);
20774 + if (IS_ERR(inode)) {
20775 + ret = (void *)inode;
20782 + atomic_inc(&inode->i_count);
20783 + ret = d_splice_alias(inode, dentry);
20784 +#if 0 /* reserved for future use */
20785 + if (unlikely(d_need_lookup(dentry))) {
20786 + spin_lock(&dentry->d_lock);
20787 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20788 + spin_unlock(&dentry->d_lock);
20792 + if (!IS_ERR(ret)) {
20794 + if (ret && ret != dentry)
20795 + ii_write_unlock(inode);
20797 + ii_write_unlock(inode);
20804 + di_write_unlock(dentry);
20806 + si_read_unlock(sb);
20811 +/* ---------------------------------------------------------------------- */
20814 + * very dirty and complicated aufs ->atomic_open().
20815 + * aufs_atomic_open()
20816 + * + au_aopen_or_create()
20818 + * + vfsub_atomic_open()
20819 + * + branch fs ->atomic_open()
20820 + * may call the actual 'open' for h_file
20821 + * + inc br_nfiles only if opened
20822 + * + au_aopen_no_open() or au_aopen_do_open()
20824 + * au_aopen_do_open()
20825 + * + finish_open()
20826 + * + au_do_aopen()
20827 + * + au_do_open() the body of all 'open'
20828 + * + au_do_open_nondir()
20829 + * set the passed h_file
20831 + * au_aopen_no_open()
20832 + * + finish_no_open()
20835 +struct aopen_node {
20836 + struct hlist_bl_node hblist;
20837 + struct file *file, *h_file;
20840 +static int au_do_aopen(struct inode *inode, struct file *file)
20842 + struct hlist_bl_head *aopen;
20843 + struct hlist_bl_node *pos;
20844 + struct aopen_node *node;
20845 + struct au_do_open_args args = {
20847 + .open = au_do_open_nondir
20850 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20851 + hlist_bl_lock(aopen);
20852 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20853 + if (node->file == file) {
20854 + args.h_file = node->h_file;
20857 + hlist_bl_unlock(aopen);
20858 + /* AuDebugOn(!args.h_file); */
20860 + return au_do_open(file, &args);
20863 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20864 + struct aopen_node *aopen_node)
20867 + struct hlist_bl_head *aopen;
20870 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20871 + au_hbl_add(&aopen_node->hblist, aopen);
20872 + err = finish_open(file, dentry, au_do_aopen);
20873 + au_hbl_del(&aopen_node->hblist, aopen);
20874 + /* AuDbgFile(file); */
20875 + AuDbg("%pd%s%s\n", dentry,
20876 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20877 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20883 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20889 + err = finish_no_open(file, dentry);
20895 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20896 + struct file *file, unsigned int open_flag,
20897 + umode_t create_mode)
20899 + int err, did_open;
20900 + unsigned int lkup_flags;
20901 + aufs_bindex_t bindex;
20902 + struct super_block *sb;
20903 + struct dentry *parent, *d;
20904 + struct vfsub_aopen_args args = {
20905 + .open_flag = open_flag,
20906 + .create_mode = create_mode
20908 + struct aopen_node aopen_node = {
20913 + AuDbg("open_flag 0%o\n", open_flag);
20914 + AuDbgDentry(dentry);
20917 + if (!au_di(dentry)) {
20918 + lkup_flags = LOOKUP_OPEN;
20919 + if (open_flag & O_CREAT)
20920 + lkup_flags |= LOOKUP_CREATE;
20921 + d = aufs_lookup(dir, dentry, lkup_flags);
20923 + err = PTR_ERR(d);
20928 + * obsoleted dentry found.
20929 + * another error will be returned later.
20935 + AuDbgDentry(dentry);
20938 + if (d_is_positive(dentry)
20939 + || d_unhashed(dentry)
20940 + || d_unlinked(dentry)
20941 + || !(open_flag & O_CREAT)) {
20942 + err = au_aopen_no_open(file, dentry);
20943 + goto out; /* success */
20946 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20947 + if (unlikely(err))
20950 + sb = dentry->d_sb;
20951 + parent = dentry->d_parent; /* dir is locked */
20952 + di_write_lock_parent(parent);
20953 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20954 + if (unlikely(err < 0))
20957 + AuDbgDentry(dentry);
20958 + if (d_is_positive(dentry)) {
20959 + err = au_aopen_no_open(file, dentry);
20960 + goto out_parent; /* success */
20963 + args.file = alloc_empty_file(file->f_flags, current_cred());
20964 + err = PTR_ERR(args.file);
20965 + if (IS_ERR(args.file))
20968 + bindex = au_dbtop(dentry);
20969 + err = au_aopen_or_create(dir, dentry, &args);
20971 + AuDbgFile(args.file);
20972 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20973 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20976 + args.file = NULL;
20978 + di_write_unlock(parent);
20979 + di_write_unlock(dentry);
20980 + if (unlikely(err < 0)) {
20987 + err = au_aopen_no_open(file, dentry);
20989 + aopen_node.h_file = args.file;
20990 + err = au_aopen_do_open(file, dentry, &aopen_node);
20992 + if (unlikely(err < 0)) {
20996 + au_lcnt_dec(&args.br->br_nfiles);
20998 + goto out_sb; /* success */
21001 + di_write_unlock(parent);
21002 + di_write_unlock(dentry);
21004 + si_read_unlock(sb);
21012 +/* ---------------------------------------------------------------------- */
21014 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21015 + const unsigned char add_entry, aufs_bindex_t bcpup,
21016 + aufs_bindex_t btop)
21019 + struct dentry *h_parent;
21020 + struct inode *h_dir;
21023 + IMustLock(d_inode(parent));
21025 + di_write_lock_parent(parent);
21028 + if (!au_h_dptr(parent, bcpup)) {
21029 + if (btop > bcpup)
21030 + err = au_cpup_dirs(dentry, bcpup);
21031 + else if (btop < bcpup)
21032 + err = au_cpdown_dirs(dentry, bcpup);
21036 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21037 + h_parent = au_h_dptr(parent, bcpup);
21038 + h_dir = d_inode(h_parent);
21039 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21040 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21041 + /* todo: no unlock here */
21042 + inode_unlock_shared(h_dir);
21044 + AuDbg("bcpup %d\n", bcpup);
21046 + if (d_really_is_negative(dentry))
21047 + au_set_h_dptr(dentry, btop, NULL);
21048 + au_update_dbrange(dentry, /*do_put_zero*/0);
21053 + di_write_unlock(parent);
21055 + err = bcpup; /* success */
21062 + * decide the branch and the parent dir where we will create a new entry.
21063 + * returns new bindex or an error.
21064 + * copyup the parent dir if needed.
21066 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21067 + struct au_wr_dir_args *args)
21070 + unsigned int flags;
21071 + aufs_bindex_t bcpup, btop, src_btop;
21072 + const unsigned char add_entry
21073 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21074 + | au_ftest_wrdir(args->flags, TMPFILE);
21075 + struct super_block *sb;
21076 + struct dentry *parent;
21077 + struct au_sbinfo *sbinfo;
21079 + sb = dentry->d_sb;
21080 + sbinfo = au_sbi(sb);
21081 + parent = dget_parent(dentry);
21082 + btop = au_dbtop(dentry);
21084 + if (args->force_btgt < 0) {
21085 + if (src_dentry) {
21086 + src_btop = au_dbtop(src_dentry);
21087 + if (src_btop < btop)
21088 + bcpup = src_btop;
21089 + } else if (add_entry) {
21091 + if (au_ftest_wrdir(args->flags, ISDIR))
21092 + au_fset_wbr(flags, DIR);
21093 + err = AuWbrCreate(sbinfo, dentry, flags);
21097 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21099 + err = AuWbrCopyup(sbinfo, dentry);
21101 + if (!IS_ROOT(dentry)) {
21102 + di_read_lock_parent(parent, !AuLock_IR);
21103 + err = AuWbrCopyup(sbinfo, dentry);
21104 + di_read_unlock(parent, !AuLock_IR);
21106 + err = AuWbrCopyup(sbinfo, dentry);
21109 + if (unlikely(err < 0))
21113 + bcpup = args->force_btgt;
21114 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21117 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21119 + if (bcpup == btop)
21120 + goto out; /* success */
21122 + /* copyup the new parent into the branch we process */
21123 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21125 + if (d_really_is_negative(dentry)) {
21126 + au_set_h_dptr(dentry, btop, NULL);
21127 + au_set_dbtop(dentry, bcpup);
21128 + au_set_dbbot(dentry, bcpup);
21130 + AuDebugOn(add_entry
21131 + && !au_ftest_wrdir(args->flags, TMPFILE)
21132 + && !au_h_dptr(dentry, bcpup));
21140 +/* ---------------------------------------------------------------------- */
21142 +void au_pin_hdir_unlock(struct au_pin *p)
21145 + au_hn_inode_unlock(p->hdir);
21148 +int au_pin_hdir_lock(struct au_pin *p)
21156 + /* even if an error happens later, keep this lock */
21157 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21160 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21165 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21166 + p->h_parent, p->br);
21172 +int au_pin_hdir_relock(struct au_pin *p)
21175 + struct inode *h_i;
21176 + struct dentry *h_d[] = {
21181 + err = au_pin_hdir_lock(p);
21182 + if (unlikely(err))
21185 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21188 + if (d_is_positive(h_d[i])) {
21189 + h_i = d_inode(h_d[i]);
21190 + err = !h_i->i_nlink;
21198 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21200 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21203 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21206 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21207 + p->lsc_hi, 0, NULL, _RET_IP_);
21208 + au_pin_hdir_set_owner(p, current);
21212 +void au_pin_hdir_release(struct au_pin *p)
21215 + au_pin_hdir_set_owner(p, p->task);
21216 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21220 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21222 + if (pin && pin->parent)
21223 + return au_h_dptr(pin->parent, pin->bindex);
21227 +void au_unpin(struct au_pin *p)
21230 + au_pin_hdir_unlock(p);
21231 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21232 + vfsub_mnt_drop_write(p->h_mnt);
21236 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21237 + di_read_unlock(p->parent, AuLock_IR);
21238 + iput(p->hdir->hi_inode);
21240 + p->parent = NULL;
21243 + /* do not clear p->task */
21246 +int au_do_pin(struct au_pin *p)
21249 + struct super_block *sb;
21250 + struct inode *h_dir;
21253 + sb = p->dentry->d_sb;
21254 + p->br = au_sbr(sb, p->bindex);
21255 + if (IS_ROOT(p->dentry)) {
21256 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21257 + p->h_mnt = au_br_mnt(p->br);
21258 + err = vfsub_mnt_want_write(p->h_mnt);
21259 + if (unlikely(err)) {
21260 + au_fclr_pin(p->flags, MNT_WRITE);
21267 + p->h_dentry = NULL;
21268 + if (p->bindex <= au_dbbot(p->dentry))
21269 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21271 + p->parent = dget_parent(p->dentry);
21272 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21273 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21276 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21277 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21279 + h_dir = p->hdir->hi_inode;
21283 + * if DI_LOCKED is not set, then p->parent may be different
21284 + * and h_parent can be NULL.
21286 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21288 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21289 + di_read_unlock(p->parent, AuLock_IR);
21291 + p->parent = NULL;
21295 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21296 + p->h_mnt = au_br_mnt(p->br);
21297 + err = vfsub_mnt_want_write(p->h_mnt);
21298 + if (unlikely(err)) {
21299 + au_fclr_pin(p->flags, MNT_WRITE);
21300 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21301 + di_read_unlock(p->parent, AuLock_IR);
21303 + p->parent = NULL;
21309 + err = au_pin_hdir_lock(p);
21311 + goto out; /* success */
21316 + pr_err("err %d\n", err);
21317 + err = au_busy_or_stale();
21322 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21323 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21324 + unsigned int udba, unsigned char flags)
21326 + p->dentry = dentry;
21328 + p->lsc_di = lsc_di;
21329 + p->lsc_hi = lsc_hi;
21330 + p->flags = flags;
21331 + p->bindex = bindex;
21333 + p->parent = NULL;
21337 + p->h_dentry = NULL;
21338 + p->h_parent = NULL;
21340 + p->task = current;
21343 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21344 + unsigned int udba, unsigned char flags)
21346 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21348 + return au_do_pin(pin);
21351 +/* ---------------------------------------------------------------------- */
21354 + * ->setattr() and ->getattr() are called in various cases.
21355 + * chmod, stat: dentry is revalidated.
21356 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21358 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21360 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21361 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21364 + struct dentry *parent;
21367 + if (au_digen_test(dentry, sigen)) {
21368 + parent = dget_parent(dentry);
21369 + di_read_lock_parent(parent, AuLock_IR);
21370 + err = au_refresh_dentry(dentry, parent);
21371 + di_read_unlock(parent, AuLock_IR);
21379 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21380 + struct au_icpup_args *a)
21384 + aufs_bindex_t btop, ibtop;
21385 + struct dentry *hi_wh, *parent;
21386 + struct inode *inode;
21387 + struct au_wr_dir_args wr_dir_args = {
21388 + .force_btgt = -1,
21392 + if (d_is_dir(dentry))
21393 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21394 + /* plink or hi_wh() case */
21395 + btop = au_dbtop(dentry);
21396 + inode = d_inode(dentry);
21397 + ibtop = au_ibtop(inode);
21398 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21399 + wr_dir_args.force_btgt = ibtop;
21400 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21401 + if (unlikely(err < 0))
21405 + au_fset_icpup(a->flags, DID_CPUP);
21408 + a->pin_flags = AuPin_MNT_WRITE;
21410 + if (!IS_ROOT(dentry)) {
21411 + au_fset_pin(a->pin_flags, DI_LOCKED);
21412 + parent = dget_parent(dentry);
21413 + di_write_lock_parent(parent);
21416 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21417 + if (unlikely(err))
21421 + a->h_path.dentry = au_h_dptr(dentry, btop);
21422 + a->h_inode = d_inode(a->h_path.dentry);
21423 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21424 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21425 + if (ia->ia_size < i_size_read(a->h_inode))
21426 + sz = ia->ia_size;
21427 + inode_unlock_shared(a->h_inode);
21431 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21432 + hi_wh = au_hi_wh(inode, a->btgt);
21434 + struct au_cp_generic cpg = {
21435 + .dentry = dentry,
21441 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21442 + if (unlikely(err))
21444 + hi_wh = au_hi_wh(inode, a->btgt);
21445 + /* todo: revalidate hi_wh? */
21450 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21451 + di_downgrade_lock(parent, AuLock_IR);
21455 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21456 + goto out; /* success */
21458 + if (!d_unhashed(dentry)) {
21459 + struct au_cp_generic cpg = {
21460 + .dentry = dentry,
21465 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21467 + err = au_sio_cpup_simple(&cpg);
21469 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21470 + } else if (!hi_wh)
21471 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21473 + a->h_path.dentry = hi_wh; /* do not dget here */
21476 + a->h_inode = d_inode(a->h_path.dentry);
21478 + goto out; /* success */
21479 + au_unpin(&a->pin);
21482 + di_write_unlock(parent);
21487 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21491 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21494 + struct inode *inode, *delegated;
21495 + struct super_block *sb;
21496 + struct file *file;
21497 + struct au_icpup_args *a;
21499 + inode = d_inode(dentry);
21500 + IMustLock(inode);
21502 + err = setattr_prepare(dentry, ia);
21503 + if (unlikely(err))
21507 + a = kzalloc(sizeof(*a), GFP_NOFS);
21508 + if (unlikely(!a))
21511 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21512 + ia->ia_valid &= ~ATTR_MODE;
21515 + sb = dentry->d_sb;
21516 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21517 + if (unlikely(err))
21520 + if (ia->ia_valid & ATTR_FILE) {
21521 + /* currently ftruncate(2) only */
21522 + AuDebugOn(!d_is_reg(dentry));
21523 + file = ia->ia_file;
21524 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21526 + if (unlikely(err))
21528 + ia->ia_file = au_hf_top(file);
21529 + a->udba = AuOpt_UDBA_NONE;
21531 + /* fchmod() doesn't pass ia_file */
21532 + a->udba = au_opt_udba(sb);
21533 + di_write_lock_child(dentry);
21534 + /* no d_unlinked(), to set UDBA_NONE for root */
21535 + if (d_unhashed(dentry))
21536 + a->udba = AuOpt_UDBA_NONE;
21537 + if (a->udba != AuOpt_UDBA_NONE) {
21538 + AuDebugOn(IS_ROOT(dentry));
21539 + err = au_reval_for_attr(dentry, au_sigen(sb));
21540 + if (unlikely(err))
21545 + err = au_pin_and_icpup(dentry, ia, a);
21546 + if (unlikely(err < 0))
21548 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21549 + ia->ia_file = NULL;
21550 + ia->ia_valid &= ~ATTR_FILE;
21553 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21554 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21555 + == (ATTR_MODE | ATTR_CTIME)) {
21556 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21557 + if (unlikely(err))
21559 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21560 + && (ia->ia_valid & ATTR_CTIME)) {
21561 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21562 + if (unlikely(err))
21566 + if (ia->ia_valid & ATTR_SIZE) {
21569 + if (ia->ia_size < i_size_read(inode))
21571 + truncate_setsize(inode, ia->ia_size);
21574 + if (ia->ia_valid & ATTR_FILE)
21576 + inode_unlock(a->h_inode);
21577 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21578 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21580 + delegated = NULL;
21582 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21584 + err = break_deleg_wait(&delegated);
21592 + * regardless aufs 'acl' option setting.
21593 + * why don't all acl-aware fs call this func from their ->setattr()?
21595 + if (!err && (ia->ia_valid & ATTR_MODE))
21596 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21598 + au_cpup_attr_changeable(inode);
21601 + inode_unlock(a->h_inode);
21602 + au_unpin(&a->pin);
21603 + if (unlikely(err))
21604 + au_update_dbtop(dentry);
21606 + di_write_unlock(dentry);
21608 + fi_write_unlock(file);
21609 + ia->ia_file = file;
21610 + ia->ia_valid |= ATTR_FILE;
21613 + si_read_unlock(sb);
21621 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21622 +static int au_h_path_to_set_attr(struct dentry *dentry,
21623 + struct au_icpup_args *a, struct path *h_path)
21626 + struct super_block *sb;
21628 + sb = dentry->d_sb;
21629 + a->udba = au_opt_udba(sb);
21630 + /* no d_unlinked(), to set UDBA_NONE for root */
21631 + if (d_unhashed(dentry))
21632 + a->udba = AuOpt_UDBA_NONE;
21633 + if (a->udba != AuOpt_UDBA_NONE) {
21634 + AuDebugOn(IS_ROOT(dentry));
21635 + err = au_reval_for_attr(dentry, au_sigen(sb));
21636 + if (unlikely(err))
21639 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21640 + if (unlikely(err < 0))
21643 + h_path->dentry = a->h_path.dentry;
21644 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21650 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21651 + struct au_sxattr *arg)
21654 + struct path h_path;
21655 + struct super_block *sb;
21656 + struct au_icpup_args *a;
21657 + struct inode *h_inode;
21659 + IMustLock(inode);
21662 + a = kzalloc(sizeof(*a), GFP_NOFS);
21663 + if (unlikely(!a))
21666 + sb = dentry->d_sb;
21667 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21668 + if (unlikely(err))
21671 + h_path.dentry = NULL; /* silence gcc */
21672 + di_write_lock_child(dentry);
21673 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21674 + if (unlikely(err))
21677 + inode_unlock(a->h_inode);
21678 + switch (arg->type) {
21679 + case AU_XATTR_SET:
21680 + AuDebugOn(d_is_negative(h_path.dentry));
21681 + err = vfsub_setxattr(h_path.dentry,
21682 + arg->u.set.name, arg->u.set.value,
21683 + arg->u.set.size, arg->u.set.flags);
21686 + err = -EOPNOTSUPP;
21687 + h_inode = d_inode(h_path.dentry);
21688 + if (h_inode->i_op->set_acl)
21689 + /* this will call posix_acl_update_mode */
21690 + err = h_inode->i_op->set_acl(h_inode,
21691 + arg->u.acl_set.acl,
21692 + arg->u.acl_set.type);
21696 + au_cpup_attr_timesizes(inode);
21698 + au_unpin(&a->pin);
21699 + if (unlikely(err))
21700 + au_update_dbtop(dentry);
21703 + di_write_unlock(dentry);
21704 + si_read_unlock(sb);
21713 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21714 + unsigned int nlink)
21718 + inode->i_mode = st->mode;
21719 + /* don't i_[ug]id_write() here */
21720 + inode->i_uid = st->uid;
21721 + inode->i_gid = st->gid;
21722 + inode->i_atime = st->atime;
21723 + inode->i_mtime = st->mtime;
21724 + inode->i_ctime = st->ctime;
21726 + au_cpup_attr_nlink(inode, /*force*/0);
21727 + if (S_ISDIR(inode->i_mode)) {
21728 + n = inode->i_nlink;
21731 + smp_mb(); /* for i_nlink */
21732 + /* 0 can happen */
21733 + set_nlink(inode, n);
21736 + spin_lock(&inode->i_lock);
21737 + inode->i_blocks = st->blocks;
21738 + i_size_write(inode, st->size);
21739 + spin_unlock(&inode->i_lock);
21743 + * common routine for aufs_getattr() and au_getxattr().
21744 + * returns zero or negative (an error).
21745 + * @dentry will be read-locked in success.
21747 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21751 + unsigned int mnt_flags, sigen;
21752 + unsigned char udba_none;
21753 + aufs_bindex_t bindex;
21754 + struct super_block *sb, *h_sb;
21755 + struct inode *inode;
21757 + h_path->mnt = NULL;
21758 + h_path->dentry = NULL;
21761 + sb = dentry->d_sb;
21762 + mnt_flags = au_mntflags(sb);
21763 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21765 + if (unlikely(locked))
21766 + goto body; /* skip locking dinfo */
21768 + /* support fstat(2) */
21769 + if (!d_unlinked(dentry) && !udba_none) {
21770 + sigen = au_sigen(sb);
21771 + err = au_digen_test(dentry, sigen);
21773 + di_read_lock_child(dentry, AuLock_IR);
21774 + err = au_dbrange_test(dentry);
21775 + if (unlikely(err)) {
21776 + di_read_unlock(dentry, AuLock_IR);
21780 + AuDebugOn(IS_ROOT(dentry));
21781 + di_write_lock_child(dentry);
21782 + err = au_dbrange_test(dentry);
21784 + err = au_reval_for_attr(dentry, sigen);
21786 + di_downgrade_lock(dentry, AuLock_IR);
21788 + di_write_unlock(dentry);
21793 + di_read_lock_child(dentry, AuLock_IR);
21796 + inode = d_inode(dentry);
21797 + bindex = au_ibtop(inode);
21798 + h_path->mnt = au_sbr_mnt(sb, bindex);
21799 + h_sb = h_path->mnt->mnt_sb;
21801 + && !au_test_fs_bad_iattr(h_sb)
21803 + goto out; /* success */
21805 + if (au_dbtop(dentry) == bindex)
21806 + h_path->dentry = au_h_dptr(dentry, bindex);
21807 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21808 + h_path->dentry = au_plink_lkup(inode, bindex);
21809 + if (IS_ERR(h_path->dentry))
21810 + /* pretending success */
21811 + h_path->dentry = NULL;
21813 + dput(h_path->dentry);
21820 +static int aufs_getattr(const struct path *path, struct kstat *st,
21821 + u32 request, unsigned int query)
21824 + unsigned char positive;
21825 + struct path h_path;
21826 + struct dentry *dentry;
21827 + struct inode *inode;
21828 + struct super_block *sb;
21830 + dentry = path->dentry;
21831 + inode = d_inode(dentry);
21832 + sb = dentry->d_sb;
21833 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21834 + if (unlikely(err))
21836 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21837 + if (unlikely(err))
21839 + if (unlikely(!h_path.dentry))
21840 + /* illegally overlapped or something */
21841 + goto out_fill; /* pretending success */
21843 + positive = d_is_positive(h_path.dentry);
21845 + /* no vfsub version */
21846 + err = vfs_getattr(&h_path, st, request, query);
21849 + au_refresh_iattr(inode, st,
21850 + d_inode(h_path.dentry)->i_nlink);
21851 + goto out_fill; /* success */
21857 + generic_fillattr(inode, st);
21859 + di_read_unlock(dentry, AuLock_IR);
21861 + si_read_unlock(sb);
21867 +/* ---------------------------------------------------------------------- */
21869 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21870 + struct delayed_call *done)
21873 + struct dentry *h_dentry;
21874 + struct inode *h_inode;
21876 + aufs_bindex_t bindex;
21878 + ret = NULL; /* suppress a warning */
21883 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21884 + if (unlikely(err))
21887 + err = au_d_hashed_positive(dentry);
21888 + if (unlikely(err))
21892 + inode = d_inode(dentry);
21893 + bindex = au_ibtop(inode);
21894 + h_inode = au_h_iptr(inode, bindex);
21895 + if (unlikely(!h_inode->i_op->get_link))
21900 + if (au_dbtop(dentry) <= bindex) {
21901 + h_dentry = au_h_dptr(dentry, bindex);
21906 + h_dentry = d_find_any_alias(h_inode);
21907 + if (IS_ERR(h_dentry)) {
21908 + err = PTR_ERR(h_dentry);
21912 + if (unlikely(!h_dentry))
21916 + AuDbg("%ps\n", h_inode->i_op->get_link);
21917 + AuDbgDentry(h_dentry);
21918 + ret = vfs_get_link(h_dentry, done);
21921 + err = PTR_ERR(ret);
21924 + aufs_read_unlock(dentry, AuLock_IR);
21926 + if (unlikely(err))
21927 + ret = ERR_PTR(err);
21928 + AuTraceErrPtr(ret);
21932 +/* ---------------------------------------------------------------------- */
21934 +static int au_is_special(struct inode *inode)
21936 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21939 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21943 + aufs_bindex_t bindex;
21944 + struct super_block *sb;
21945 + struct inode *h_inode;
21946 + struct vfsmount *h_mnt;
21948 + sb = inode->i_sb;
21949 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21950 + "unexpected s_flags 0x%lx", sb->s_flags);
21952 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21954 + si_read_lock(sb, AuLock_FLUSH);
21955 + ii_write_lock_child(inode);
21958 + bindex = au_ibtop(inode);
21959 + h_inode = au_h_iptr(inode, bindex);
21960 + if (!au_test_ro(sb, bindex, inode)) {
21961 + h_mnt = au_sbr_mnt(sb, bindex);
21962 + err = vfsub_mnt_want_write(h_mnt);
21964 + err = vfsub_update_time(h_inode, ts, flags);
21965 + vfsub_mnt_drop_write(h_mnt);
21967 + } else if (au_is_special(h_inode)) {
21969 + * Never copy-up here.
21970 + * These special files may already be opened and used for
21971 + * communicating. If we copied it up, then the communication
21972 + * would be corrupted.
21974 + AuWarn1("timestamps for i%lu are ignored "
21975 + "since it is on readonly branch (hi%lu).\n",
21976 + inode->i_ino, h_inode->i_ino);
21977 + } else if (flags & ~S_ATIME) {
21979 + AuIOErr1("unexpected flags 0x%x\n", flags);
21984 + au_cpup_attr_timesizes(inode);
21985 + ii_write_unlock(inode);
21986 + si_read_unlock(sb);
21989 + if (!err && (flags & S_VERSION))
21990 + inode_inc_iversion(inode);
21995 +/* ---------------------------------------------------------------------- */
21997 +/* no getattr version will be set by module.c:aufs_init() */
21998 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22000 + [AuIop_SYMLINK] = {
22001 + .permission = aufs_permission,
22002 +#ifdef CONFIG_FS_POSIX_ACL
22003 + .get_acl = aufs_get_acl,
22004 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22007 + .setattr = aufs_setattr,
22008 + .getattr = aufs_getattr,
22010 +#ifdef CONFIG_AUFS_XATTR
22011 + .listxattr = aufs_listxattr,
22014 + .get_link = aufs_get_link,
22016 + /* .update_time = aufs_update_time */
22019 + .create = aufs_create,
22020 + .lookup = aufs_lookup,
22021 + .link = aufs_link,
22022 + .unlink = aufs_unlink,
22023 + .symlink = aufs_symlink,
22024 + .mkdir = aufs_mkdir,
22025 + .rmdir = aufs_rmdir,
22026 + .mknod = aufs_mknod,
22027 + .rename = aufs_rename,
22029 + .permission = aufs_permission,
22030 +#ifdef CONFIG_FS_POSIX_ACL
22031 + .get_acl = aufs_get_acl,
22032 + .set_acl = aufs_set_acl,
22035 + .setattr = aufs_setattr,
22036 + .getattr = aufs_getattr,
22038 +#ifdef CONFIG_AUFS_XATTR
22039 + .listxattr = aufs_listxattr,
22042 + .update_time = aufs_update_time,
22043 + .atomic_open = aufs_atomic_open,
22044 + .tmpfile = aufs_tmpfile
22046 + [AuIop_OTHER] = {
22047 + .permission = aufs_permission,
22048 +#ifdef CONFIG_FS_POSIX_ACL
22049 + .get_acl = aufs_get_acl,
22050 + .set_acl = aufs_set_acl,
22053 + .setattr = aufs_setattr,
22054 + .getattr = aufs_getattr,
22056 +#ifdef CONFIG_AUFS_XATTR
22057 + .listxattr = aufs_listxattr,
22060 + .update_time = aufs_update_time
22063 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22064 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22065 +++ linux/fs/aufs/i_op_del.c 2020-01-27 10:57:18.172204883 +0100
22067 +// SPDX-License-Identifier: GPL-2.0
22069 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22071 + * This program, aufs is free software; you can redistribute it and/or modify
22072 + * it under the terms of the GNU General Public License as published by
22073 + * the Free Software Foundation; either version 2 of the License, or
22074 + * (at your option) any later version.
22076 + * This program is distributed in the hope that it will be useful,
22077 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22078 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22079 + * GNU General Public License for more details.
22081 + * You should have received a copy of the GNU General Public License
22082 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22086 + * inode operations (del entry)
22089 +#include <linux/iversion.h>
22093 + * decide if a new whiteout for @dentry is necessary or not.
22094 + * when it is necessary, prepare the parent dir for the upper branch whose
22095 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22096 + * be done by caller.
22098 + * 0: wh is unnecessary
22099 + * plus: wh is necessary
22102 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22104 + int need_wh, err;
22105 + aufs_bindex_t btop;
22106 + struct super_block *sb;
22108 + sb = dentry->d_sb;
22109 + btop = au_dbtop(dentry);
22110 + if (*bcpup < 0) {
22112 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22113 + err = AuWbrCopyup(au_sbi(sb), dentry);
22115 + if (unlikely(err < 0))
22119 + AuDebugOn(btop < *bcpup
22120 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22121 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22123 + if (*bcpup != btop) {
22124 + err = au_cpup_dirs(dentry, *bcpup);
22125 + if (unlikely(err))
22129 + struct au_dinfo *dinfo, *tmp;
22131 + need_wh = -ENOMEM;
22132 + dinfo = au_di(dentry);
22133 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22135 + au_di_cp(tmp, dinfo);
22136 + au_di_swap(tmp, dinfo);
22137 + /* returns the number of positive dentries */
22138 + need_wh = au_lkup_dentry(dentry, btop + 1,
22139 + /* AuLkup_IGNORE_PERM */ 0);
22140 + au_di_swap(tmp, dinfo);
22141 + au_rw_write_unlock(&tmp->di_rwsem);
22145 + AuDbg("need_wh %d\n", need_wh);
22153 + * simple tests for the del-entry operations.
22154 + * following the checks in vfs, plus the parent-child relationship.
22156 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22157 + struct dentry *h_parent, int isdir)
22161 + struct dentry *h_dentry, *h_latest;
22162 + struct inode *h_inode;
22164 + h_dentry = au_h_dptr(dentry, bindex);
22165 + if (d_really_is_positive(dentry)) {
22167 + if (unlikely(d_is_negative(h_dentry)))
22169 + h_inode = d_inode(h_dentry);
22170 + if (unlikely(!h_inode->i_nlink))
22173 + h_mode = h_inode->i_mode;
22176 + if (unlikely(S_ISDIR(h_mode)))
22178 + } else if (unlikely(!S_ISDIR(h_mode))) {
22183 + /* rename(2) case */
22185 + if (unlikely(d_is_positive(h_dentry)))
22190 + /* expected parent dir is locked */
22191 + if (unlikely(h_parent != h_dentry->d_parent))
22196 + * rmdir a dir may break the consistency on some filesystem.
22197 + * let's try heavy test.
22200 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22201 + && au_test_h_perm(d_inode(h_parent),
22202 + MAY_EXEC | MAY_WRITE)))
22205 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22207 + if (IS_ERR(h_latest))
22209 + if (h_latest == h_dentry)
22218 + * decide the branch where we operate for @dentry. the branch index will be set
22219 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22220 + * dir for reverting.
22221 + * when a new whiteout is necessary, create it.
22223 +static struct dentry*
22224 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22225 + struct au_dtime *dt, struct au_pin *pin)
22227 + struct dentry *wh_dentry;
22228 + struct super_block *sb;
22229 + struct path h_path;
22230 + int err, need_wh;
22231 + unsigned int udba;
22232 + aufs_bindex_t bcpup;
22234 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22235 + wh_dentry = ERR_PTR(need_wh);
22236 + if (unlikely(need_wh < 0))
22239 + sb = dentry->d_sb;
22240 + udba = au_opt_udba(sb);
22242 + err = au_pin(pin, dentry, bcpup, udba,
22243 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22244 + wh_dentry = ERR_PTR(err);
22245 + if (unlikely(err))
22248 + h_path.dentry = au_pinned_h_parent(pin);
22249 + if (udba != AuOpt_UDBA_NONE
22250 + && au_dbtop(dentry) == bcpup) {
22251 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22252 + wh_dentry = ERR_PTR(err);
22253 + if (unlikely(err))
22257 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22258 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22259 + wh_dentry = NULL;
22261 + goto out; /* success, no need to create whiteout */
22263 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22264 + if (IS_ERR(wh_dentry))
22267 + /* returns with the parent is locked and wh_dentry is dget-ed */
22268 + goto out; /* success */
22273 + return wh_dentry;
22277 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22278 + * in order to be revertible and save time for removing many child whiteouts
22280 + * returns 1 when there are too many child whiteout and caller should remove
22281 + * them asynchronously. returns 0 when the number of children is enough small to
22282 + * remove now or the branch fs is a remote fs.
22283 + * otherwise return an error.
22285 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22286 + struct au_nhash *whlist, struct inode *dir)
22288 + int rmdir_later, err, dirwh;
22289 + struct dentry *h_dentry;
22290 + struct super_block *sb;
22291 + struct inode *inode;
22293 + sb = dentry->d_sb;
22294 + SiMustAnyLock(sb);
22295 + h_dentry = au_h_dptr(dentry, bindex);
22296 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22297 + if (unlikely(err))
22300 + /* stop monitoring */
22301 + inode = d_inode(dentry);
22302 + au_hn_free(au_hi(inode, bindex));
22304 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22305 + dirwh = au_sbi(sb)->si_dirwh;
22306 + rmdir_later = (dirwh <= 1);
22307 + if (!rmdir_later)
22308 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22311 + return rmdir_later;
22314 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22315 + if (unlikely(err)) {
22316 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22317 + h_dentry, bindex, err);
22327 + * final procedure for deleting a entry.
22328 + * maintain dentry and iattr.
22330 +static void epilog(struct inode *dir, struct dentry *dentry,
22331 + aufs_bindex_t bindex)
22333 + struct inode *inode;
22335 + inode = d_inode(dentry);
22337 + inode->i_ctime = dir->i_ctime;
22339 + au_dir_ts(dir, bindex);
22340 + inode_inc_iversion(dir);
22344 + * when an error happened, remove the created whiteout and revert everything.
22346 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22347 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22348 + struct dentry *dentry, struct au_dtime *dt)
22351 + struct path h_path = {
22352 + .dentry = wh_dentry,
22353 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22356 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22358 + au_set_dbwh(dentry, bwh);
22359 + au_dtime_revert(dt);
22363 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22367 +/* ---------------------------------------------------------------------- */
22369 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22372 + aufs_bindex_t bwh, bindex, btop;
22373 + struct inode *inode, *h_dir, *delegated;
22374 + struct dentry *parent, *wh_dentry;
22375 + /* to reduce stack size */
22377 + struct au_dtime dt;
22378 + struct au_pin pin;
22379 + struct path h_path;
22385 + a = kmalloc(sizeof(*a), GFP_NOFS);
22386 + if (unlikely(!a))
22389 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22390 + if (unlikely(err))
22392 + err = au_d_hashed_positive(dentry);
22393 + if (unlikely(err))
22395 + inode = d_inode(dentry);
22396 + IMustLock(inode);
22398 + if (unlikely(d_is_dir(dentry)))
22399 + goto out_unlock; /* possible? */
22401 + btop = au_dbtop(dentry);
22402 + bwh = au_dbwh(dentry);
22404 + parent = dentry->d_parent; /* dir inode is locked */
22405 + di_write_lock_parent(parent);
22406 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22408 + err = PTR_ERR(wh_dentry);
22409 + if (IS_ERR(wh_dentry))
22412 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22413 + a->h_path.dentry = au_h_dptr(dentry, btop);
22414 + dget(a->h_path.dentry);
22415 + if (bindex == btop) {
22416 + h_dir = au_pinned_h_dir(&a->pin);
22417 + delegated = NULL;
22418 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22419 + if (unlikely(err == -EWOULDBLOCK)) {
22420 + pr_warn("cannot retry for NFSv4 delegation"
22421 + " for an internal unlink\n");
22425 + /* dir inode is locked */
22426 + h_dir = d_inode(wh_dentry->d_parent);
22427 + IMustLock(h_dir);
22432 + vfsub_drop_nlink(inode);
22433 + epilog(dir, dentry, bindex);
22435 + /* update target timestamps */
22436 + if (bindex == btop) {
22437 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22439 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22441 + /* todo: this timestamp may be reverted later */
22442 + inode->i_ctime = h_dir->i_ctime;
22443 + goto out_unpin; /* success */
22450 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22457 + au_unpin(&a->pin);
22459 + dput(a->h_path.dentry);
22461 + di_write_unlock(parent);
22463 + aufs_read_unlock(dentry, AuLock_DW);
22470 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22472 + int err, rmdir_later;
22473 + aufs_bindex_t bwh, bindex, btop;
22474 + struct inode *inode;
22475 + struct dentry *parent, *wh_dentry, *h_dentry;
22476 + struct au_whtmp_rmdir *args;
22477 + /* to reduce stack size */
22479 + struct au_dtime dt;
22480 + struct au_pin pin;
22486 + a = kmalloc(sizeof(*a), GFP_NOFS);
22487 + if (unlikely(!a))
22490 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22491 + if (unlikely(err))
22493 + err = au_alive_dir(dentry);
22494 + if (unlikely(err))
22496 + inode = d_inode(dentry);
22497 + IMustLock(inode);
22499 + if (unlikely(!d_is_dir(dentry)))
22500 + goto out_unlock; /* possible? */
22503 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22504 + if (unlikely(!args))
22507 + parent = dentry->d_parent; /* dir inode is locked */
22508 + di_write_lock_parent(parent);
22509 + err = au_test_empty(dentry, &args->whlist);
22510 + if (unlikely(err))
22513 + btop = au_dbtop(dentry);
22514 + bwh = au_dbwh(dentry);
22516 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22518 + err = PTR_ERR(wh_dentry);
22519 + if (IS_ERR(wh_dentry))
22522 + h_dentry = au_h_dptr(dentry, btop);
22525 + if (bindex == btop) {
22526 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22528 + rmdir_later = err;
22532 + /* stop monitoring */
22533 + au_hn_free(au_hi(inode, btop));
22535 + /* dir inode is locked */
22536 + IMustLock(d_inode(wh_dentry->d_parent));
22541 + vfsub_dead_dir(inode);
22542 + au_set_dbdiropq(dentry, -1);
22543 + epilog(dir, dentry, bindex);
22545 + if (rmdir_later) {
22546 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22550 + goto out_unpin; /* success */
22558 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22565 + au_unpin(&a->pin);
22569 + di_write_unlock(parent);
22571 + au_whtmp_rmdir_free(args);
22573 + aufs_read_unlock(dentry, AuLock_DW);
22580 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22581 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22582 +++ linux/fs/aufs/i_op_ren.c 2020-01-27 10:57:18.172204883 +0100
22584 +// SPDX-License-Identifier: GPL-2.0
22586 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22588 + * This program, aufs is free software; you can redistribute it and/or modify
22589 + * it under the terms of the GNU General Public License as published by
22590 + * the Free Software Foundation; either version 2 of the License, or
22591 + * (at your option) any later version.
22593 + * This program is distributed in the hope that it will be useful,
22594 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22595 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22596 + * GNU General Public License for more details.
22598 + * You should have received a copy of the GNU General Public License
22599 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22603 + * inode operation (rename entry)
22604 + * todo: this is crazy monster
22607 +#include <linux/iversion.h>
22610 +enum { AuSRC, AuDST, AuSrcDst };
22611 +enum { AuPARENT, AuCHILD, AuParentChild };
22613 +#define AuRen_ISDIR_SRC 1
22614 +#define AuRen_ISDIR_DST (1 << 1)
22615 +#define AuRen_ISSAMEDIR (1 << 2)
22616 +#define AuRen_WHSRC (1 << 3)
22617 +#define AuRen_WHDST (1 << 4)
22618 +#define AuRen_MNT_WRITE (1 << 5)
22619 +#define AuRen_DT_DSTDIR (1 << 6)
22620 +#define AuRen_DIROPQ_SRC (1 << 7)
22621 +#define AuRen_DIROPQ_DST (1 << 8)
22622 +#define AuRen_DIRREN (1 << 9)
22623 +#define AuRen_DROPPED_SRC (1 << 10)
22624 +#define AuRen_DROPPED_DST (1 << 11)
22625 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22626 +#define au_fset_ren(flags, name) \
22627 + do { (flags) |= AuRen_##name; } while (0)
22628 +#define au_fclr_ren(flags, name) \
22629 + do { (flags) &= ~AuRen_##name; } while (0)
22631 +#ifndef CONFIG_AUFS_DIRREN
22632 +#undef AuRen_DIRREN
22633 +#define AuRen_DIRREN 0
22636 +struct au_ren_args {
22638 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22640 + struct inode *dir, *inode;
22641 + struct au_hinode *hdir, *hinode;
22642 + struct au_dtime dt[AuParentChild];
22643 + aufs_bindex_t btop, bdiropq;
22646 +#define src_dentry sd[AuSRC].dentry
22647 +#define src_dir sd[AuSRC].dir
22648 +#define src_inode sd[AuSRC].inode
22649 +#define src_h_dentry sd[AuSRC].h_dentry
22650 +#define src_parent sd[AuSRC].parent
22651 +#define src_h_parent sd[AuSRC].h_parent
22652 +#define src_wh_dentry sd[AuSRC].wh_dentry
22653 +#define src_hdir sd[AuSRC].hdir
22654 +#define src_hinode sd[AuSRC].hinode
22655 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22656 +#define src_dt sd[AuSRC].dt
22657 +#define src_btop sd[AuSRC].btop
22658 +#define src_bdiropq sd[AuSRC].bdiropq
22660 +#define dst_dentry sd[AuDST].dentry
22661 +#define dst_dir sd[AuDST].dir
22662 +#define dst_inode sd[AuDST].inode
22663 +#define dst_h_dentry sd[AuDST].h_dentry
22664 +#define dst_parent sd[AuDST].parent
22665 +#define dst_h_parent sd[AuDST].h_parent
22666 +#define dst_wh_dentry sd[AuDST].wh_dentry
22667 +#define dst_hdir sd[AuDST].hdir
22668 +#define dst_hinode sd[AuDST].hinode
22669 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22670 +#define dst_dt sd[AuDST].dt
22671 +#define dst_btop sd[AuDST].btop
22672 +#define dst_bdiropq sd[AuDST].bdiropq
22674 + struct dentry *h_trap;
22675 + struct au_branch *br;
22676 + struct path h_path;
22677 + struct au_nhash whlist;
22678 + aufs_bindex_t btgt, src_bwh;
22681 + unsigned short auren_flags;
22682 + unsigned char flags; /* syscall parameter */
22683 + unsigned char exchange;
22686 + struct au_whtmp_rmdir *thargs;
22687 + struct dentry *h_dst;
22688 + struct au_hinode *h_root;
22691 +/* ---------------------------------------------------------------------- */
22694 + * functions for reverting.
22695 + * when an error happened in a single rename systemcall, we should revert
22696 + * everything as if nothing happened.
22697 + * we don't need to revert the copied-up/down the parent dir since they are
22701 +#define RevertFailure(fmt, ...) do { \
22702 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22703 + ##__VA_ARGS__, err, rerr); \
22707 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22710 + struct dentry *d;
22711 +#define src_or_dst(member) a->sd[idx].member
22713 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22714 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22715 + rerr = au_diropq_remove(d, a->btgt);
22716 + au_hn_inode_unlock(src_or_dst(hinode));
22717 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22719 + RevertFailure("remove diropq %pd", d);
22721 +#undef src_or_dst_
22724 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22726 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22727 + au_ren_do_rev_diropq(err, a, AuSRC);
22728 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22729 + au_ren_do_rev_diropq(err, a, AuDST);
22732 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22735 + struct inode *delegated;
22737 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22738 + a->src_h_parent);
22739 + rerr = PTR_ERR(a->h_path.dentry);
22740 + if (IS_ERR(a->h_path.dentry)) {
22741 + RevertFailure("lkup one %pd", a->src_dentry);
22745 + delegated = NULL;
22746 + rerr = vfsub_rename(a->dst_h_dir,
22747 + au_h_dptr(a->src_dentry, a->btgt),
22748 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22749 + if (unlikely(rerr == -EWOULDBLOCK)) {
22750 + pr_warn("cannot retry for NFSv4 delegation"
22751 + " for an internal rename\n");
22754 + d_drop(a->h_path.dentry);
22755 + dput(a->h_path.dentry);
22756 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22758 + RevertFailure("rename %pd", a->src_dentry);
22761 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22764 + struct inode *delegated;
22766 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22767 + a->dst_h_parent);
22768 + rerr = PTR_ERR(a->h_path.dentry);
22769 + if (IS_ERR(a->h_path.dentry)) {
22770 + RevertFailure("lkup one %pd", a->dst_dentry);
22773 + if (d_is_positive(a->h_path.dentry)) {
22774 + d_drop(a->h_path.dentry);
22775 + dput(a->h_path.dentry);
22779 + delegated = NULL;
22780 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22781 + &delegated, a->flags);
22782 + if (unlikely(rerr == -EWOULDBLOCK)) {
22783 + pr_warn("cannot retry for NFSv4 delegation"
22784 + " for an internal rename\n");
22787 + d_drop(a->h_path.dentry);
22788 + dput(a->h_path.dentry);
22790 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22792 + RevertFailure("rename %pd", a->h_dst);
22795 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22799 + a->h_path.dentry = a->src_wh_dentry;
22800 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22801 + au_set_dbwh(a->src_dentry, a->src_bwh);
22803 + RevertFailure("unlink %pd", a->src_wh_dentry);
22805 +#undef RevertFailure
22807 +/* ---------------------------------------------------------------------- */
22810 + * when we have to copyup the renaming entry, do it with the rename-target name
22811 + * in order to minimize the cost (the later actual rename is unnecessary).
22812 + * otherwise rename it on the target branch.
22814 +static int au_ren_or_cpup(struct au_ren_args *a)
22817 + struct dentry *d;
22818 + struct inode *delegated;
22820 + d = a->src_dentry;
22821 + if (au_dbtop(d) == a->btgt) {
22822 + a->h_path.dentry = a->dst_h_dentry;
22823 + AuDebugOn(au_dbtop(d) != a->btgt);
22824 + delegated = NULL;
22825 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22826 + a->dst_h_dir, &a->h_path, &delegated,
22828 + if (unlikely(err == -EWOULDBLOCK)) {
22829 + pr_warn("cannot retry for NFSv4 delegation"
22830 + " for an internal rename\n");
22836 + if (!err && a->h_dst)
22837 + /* it will be set to dinfo later */
22843 +/* cf. aufs_rmdir() */
22844 +static int au_ren_del_whtmp(struct au_ren_args *a)
22847 + struct inode *dir;
22849 + dir = a->dst_dir;
22850 + SiMustAnyLock(dir->i_sb);
22851 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22852 + au_sbi(dir->i_sb)->si_dirwh)
22853 + || au_test_fs_remote(a->h_dst->d_sb)) {
22854 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22855 + if (unlikely(err))
22856 + pr_warn("failed removing whtmp dir %pd (%d), "
22857 + "ignored.\n", a->h_dst, err);
22859 + au_nhash_wh_free(&a->thargs->whlist);
22860 + a->thargs->whlist = a->whlist;
22861 + a->whlist.nh_num = 0;
22862 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22864 + a->thargs = NULL;
22870 +/* make it 'opaque' dir. */
22871 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22874 + struct dentry *d, *diropq;
22875 +#define src_or_dst(member) a->sd[idx].member
22878 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22879 + src_or_dst(bdiropq) = au_dbdiropq(d);
22880 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22881 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22882 + diropq = au_diropq_create(d, a->btgt);
22883 + au_hn_inode_unlock(src_or_dst(hinode));
22884 + if (IS_ERR(diropq))
22885 + err = PTR_ERR(diropq);
22889 +#undef src_or_dst_
22893 +static int au_ren_diropq(struct au_ren_args *a)
22896 + unsigned char always;
22897 + struct dentry *d;
22900 + d = a->dst_dentry; /* already renamed on the branch */
22901 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22902 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22903 + && !au_ftest_ren(a->auren_flags, DIRREN)
22904 + && a->btgt != au_dbdiropq(a->src_dentry)
22905 + && (a->dst_wh_dentry
22906 + || a->btgt <= au_dbdiropq(d)
22907 + /* hide the lower to keep xino */
22908 + /* the lowers may not be a dir, but we hide them anyway */
22909 + || a->btgt < au_dbbot(d)
22912 + err = au_ren_do_diropq(a, AuSRC);
22913 + if (unlikely(err))
22915 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22917 + if (!a->exchange)
22918 + goto out; /* success */
22920 + d = a->src_dentry; /* already renamed on the branch */
22921 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22922 + && a->btgt != au_dbdiropq(a->dst_dentry)
22923 + && (a->btgt < au_dbdiropq(d)
22924 + || a->btgt < au_dbbot(d)
22926 + AuDbgDentry(a->src_dentry);
22927 + AuDbgDentry(a->dst_dentry);
22928 + err = au_ren_do_diropq(a, AuDST);
22929 + if (unlikely(err))
22930 + goto out_rev_src;
22931 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22933 + goto out; /* success */
22936 + AuDbg("err %d, reverting src\n", err);
22937 + au_ren_rev_diropq(err, a);
22942 +static int do_rename(struct au_ren_args *a)
22945 + struct dentry *d, *h_d;
22947 + if (!a->exchange) {
22948 + /* prepare workqueue args for asynchronous rmdir */
22949 + h_d = a->dst_h_dentry;
22950 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22951 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22952 + && d_is_positive(h_d)) {
22954 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22956 + if (unlikely(!a->thargs))
22958 + a->h_dst = dget(h_d);
22961 + /* create whiteout for src_dentry */
22962 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22963 + a->src_bwh = au_dbwh(a->src_dentry);
22964 + AuDebugOn(a->src_bwh >= 0);
22965 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22966 + a->src_h_parent);
22967 + err = PTR_ERR(a->src_wh_dentry);
22968 + if (IS_ERR(a->src_wh_dentry))
22972 + /* lookup whiteout for dentry */
22973 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22974 + h_d = au_wh_lkup(a->dst_h_parent,
22975 + &a->dst_dentry->d_name, a->br);
22976 + err = PTR_ERR(h_d);
22979 + if (d_is_negative(h_d))
22982 + a->dst_wh_dentry = h_d;
22985 + /* rename dentry to tmpwh */
22987 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22988 + if (unlikely(err))
22991 + d = a->dst_dentry;
22992 + au_set_h_dptr(d, a->btgt, NULL);
22993 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22994 + if (unlikely(err))
22996 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23000 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23001 +#if 0 /* debugging */
23002 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23003 + && d_is_positive(a->dst_h_dentry)
23004 + && a->src_btop != a->btgt);
23007 + /* rename by vfs_rename or cpup */
23008 + err = au_ren_or_cpup(a);
23009 + if (unlikely(err))
23010 + /* leave the copied-up one */
23013 + /* make dir opaque */
23014 + err = au_ren_diropq(a);
23015 + if (unlikely(err))
23018 + /* update target timestamps */
23019 + if (a->exchange) {
23020 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23021 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23022 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23023 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23025 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23026 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23027 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23028 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23030 + if (!a->exchange) {
23031 + /* remove whiteout for dentry */
23032 + if (a->dst_wh_dentry) {
23033 + a->h_path.dentry = a->dst_wh_dentry;
23034 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23036 + if (unlikely(err))
23040 + /* remove whtmp */
23042 + au_ren_del_whtmp(a); /* ignore this error */
23044 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23047 + goto out_success;
23050 + au_ren_rev_diropq(err, a);
23052 + au_ren_rev_rename(err, a);
23056 + au_ren_rev_whtmp(err, a);
23058 + dput(a->dst_wh_dentry);
23059 + a->dst_wh_dentry = NULL;
23061 + if (a->src_wh_dentry)
23062 + au_ren_rev_whsrc(err, a);
23064 + dput(a->src_wh_dentry);
23065 + dput(a->dst_wh_dentry);
23069 + au_whtmp_rmdir_free(a->thargs);
23070 + a->thargs = NULL;
23076 +/* ---------------------------------------------------------------------- */
23079 + * test if @dentry dir can be rename destination or not.
23080 + * success means, it is a logically empty dir.
23082 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23084 + return au_test_empty(dentry, whlist);
23088 + * test if @a->src_dentry dir can be rename source or not.
23089 + * if it can, return 0.
23091 + * - it is a logically empty dir.
23092 + * - or, it exists on writable branch and has no children including whiteouts
23093 + * on the lower branch unless DIRREN is on.
23095 +static int may_rename_srcdir(struct au_ren_args *a)
23098 + unsigned int rdhash;
23099 + aufs_bindex_t btop, btgt;
23100 + struct dentry *dentry;
23101 + struct super_block *sb;
23102 + struct au_sbinfo *sbinfo;
23104 + dentry = a->src_dentry;
23105 + sb = dentry->d_sb;
23106 + sbinfo = au_sbi(sb);
23107 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23108 + au_fset_ren(a->auren_flags, DIRREN);
23111 + btop = au_dbtop(dentry);
23112 + if (btop != btgt) {
23113 + struct au_nhash whlist;
23115 + SiMustAnyLock(sb);
23116 + rdhash = sbinfo->si_rdhash;
23118 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23120 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23121 + if (unlikely(err))
23123 + err = au_test_empty(dentry, &whlist);
23124 + au_nhash_wh_free(&whlist);
23128 + if (btop == au_dbtaildir(dentry))
23129 + return 0; /* success */
23131 + err = au_test_empty_lower(dentry);
23134 + if (err == -ENOTEMPTY) {
23135 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23138 + AuWarn1("renaming dir who has child(ren) on multiple "
23139 + "branches, is not supported\n");
23146 +/* side effect: sets whlist and h_dentry */
23147 +static int au_ren_may_dir(struct au_ren_args *a)
23150 + unsigned int rdhash;
23151 + struct dentry *d;
23153 + d = a->dst_dentry;
23154 + SiMustAnyLock(d->d_sb);
23157 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23158 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23160 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23161 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23162 + if (unlikely(err))
23165 + if (!a->exchange) {
23166 + au_set_dbtop(d, a->dst_btop);
23167 + err = may_rename_dstdir(d, &a->whlist);
23168 + au_set_dbtop(d, a->btgt);
23170 + err = may_rename_srcdir(a);
23172 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23173 + if (unlikely(err))
23176 + d = a->src_dentry;
23177 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23178 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23179 + err = may_rename_srcdir(a);
23180 + if (unlikely(err)) {
23181 + au_nhash_wh_free(&a->whlist);
23182 + a->whlist.nh_num = 0;
23189 +/* ---------------------------------------------------------------------- */
23192 + * simple tests for rename.
23193 + * following the checks in vfs, plus the parent-child relationship.
23195 +static int au_may_ren(struct au_ren_args *a)
23198 + struct inode *h_inode;
23200 + if (a->src_btop == a->btgt) {
23201 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23202 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23203 + if (unlikely(err))
23206 + if (unlikely(a->src_h_dentry == a->h_trap))
23211 + if (a->dst_btop != a->btgt)
23214 + err = -ENOTEMPTY;
23215 + if (unlikely(a->dst_h_dentry == a->h_trap))
23219 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23220 + if (d_really_is_negative(a->dst_dentry)) {
23221 + if (d_is_negative(a->dst_h_dentry))
23222 + err = au_may_add(a->dst_dentry, a->btgt,
23223 + a->dst_h_parent, isdir);
23225 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23227 + h_inode = d_inode(a->dst_h_dentry);
23228 + if (h_inode->i_nlink)
23229 + err = au_may_del(a->dst_dentry, a->btgt,
23230 + a->dst_h_parent, isdir);
23234 + if (unlikely(err == -ENOENT || err == -EEXIST))
23240 +/* ---------------------------------------------------------------------- */
23245 + * - src_dir and dir by lock_rename()
23246 + * - inode if exists
23249 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23251 + * + di_write_lock2_child()
23252 + * + di_write_lock_child()
23253 + * + ii_write_lock_child()
23254 + * + di_write_lock_child2()
23255 + * + ii_write_lock_child2()
23256 + * + src_parent and parent
23257 + * + di_write_lock_parent()
23258 + * + ii_write_lock_parent()
23259 + * + di_write_lock_parent2()
23260 + * + ii_write_lock_parent2()
23261 + * + lower src_dir and dir by vfsub_lock_rename()
23262 + * + verify the every relationships between child and parent. if any
23263 + * of them failed, unlock all and return -EBUSY.
23265 +static void au_ren_unlock(struct au_ren_args *a)
23267 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23268 + a->dst_h_parent, a->dst_hdir);
23269 + if (au_ftest_ren(a->auren_flags, DIRREN)
23271 + au_hn_inode_unlock(a->h_root);
23272 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23273 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23276 +static int au_ren_lock(struct au_ren_args *a)
23279 + unsigned int udba;
23282 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23283 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23284 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23285 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23287 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23288 + if (unlikely(err))
23290 + au_fset_ren(a->auren_flags, MNT_WRITE);
23291 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23292 + struct dentry *root;
23293 + struct inode *dir;
23296 + * sbinfo is already locked, so this ii_read_lock is
23297 + * unnecessary. but our debugging feature checks it.
23299 + root = a->src_inode->i_sb->s_root;
23300 + if (root != a->src_parent && root != a->dst_parent) {
23301 + dir = d_inode(root);
23302 + ii_read_lock_parent3(dir);
23303 + a->h_root = au_hi(dir, a->btgt);
23304 + ii_read_unlock(dir);
23305 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23308 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23309 + a->dst_h_parent, a->dst_hdir);
23310 + udba = au_opt_udba(a->src_dentry->d_sb);
23311 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23312 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23313 + err = au_busy_or_stale();
23314 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23315 + err = au_h_verify(a->src_h_dentry, udba,
23316 + d_inode(a->src_h_parent), a->src_h_parent,
23318 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23319 + err = au_h_verify(a->dst_h_dentry, udba,
23320 + d_inode(a->dst_h_parent), a->dst_h_parent,
23323 + goto out; /* success */
23325 + err = au_busy_or_stale();
23326 + au_ren_unlock(a);
23332 +/* ---------------------------------------------------------------------- */
23334 +static void au_ren_refresh_dir(struct au_ren_args *a)
23336 + struct inode *dir;
23338 + dir = a->dst_dir;
23339 + inode_inc_iversion(dir);
23340 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23341 + /* is this updating defined in POSIX? */
23342 + au_cpup_attr_timesizes(a->src_inode);
23343 + au_cpup_attr_nlink(dir, /*force*/1);
23345 + au_dir_ts(dir, a->btgt);
23347 + if (a->exchange) {
23348 + dir = a->src_dir;
23349 + inode_inc_iversion(dir);
23350 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23351 + /* is this updating defined in POSIX? */
23352 + au_cpup_attr_timesizes(a->dst_inode);
23353 + au_cpup_attr_nlink(dir, /*force*/1);
23355 + au_dir_ts(dir, a->btgt);
23358 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23361 + dir = a->src_dir;
23362 + inode_inc_iversion(dir);
23363 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23364 + au_cpup_attr_nlink(dir, /*force*/1);
23365 + au_dir_ts(dir, a->btgt);
23368 +static void au_ren_refresh(struct au_ren_args *a)
23370 + aufs_bindex_t bbot, bindex;
23371 + struct dentry *d, *h_d;
23372 + struct inode *i, *h_i;
23373 + struct super_block *sb;
23375 + d = a->dst_dentry;
23378 + /* already dget-ed by au_ren_or_cpup() */
23379 + au_set_h_dptr(d, a->btgt, a->h_dst);
23381 + i = a->dst_inode;
23383 + if (!a->exchange) {
23384 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23385 + vfsub_drop_nlink(i);
23387 + vfsub_dead_dir(i);
23388 + au_cpup_attr_timesizes(i);
23390 + au_update_dbrange(d, /*do_put_zero*/1);
23392 + au_cpup_attr_nlink(i, /*force*/1);
23395 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23396 + au_set_h_dptr(d, bindex, NULL);
23397 + bbot = au_dbbot(d);
23398 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23399 + au_set_h_dptr(d, bindex, NULL);
23400 + au_update_dbrange(d, /*do_put_zero*/0);
23404 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23405 + d_drop(a->src_dentry);
23406 + if (au_ftest_ren(a->auren_flags, DIRREN))
23407 + au_set_dbwh(a->src_dentry, -1);
23411 + d = a->src_dentry;
23412 + au_set_dbwh(d, -1);
23413 + bbot = au_dbbot(d);
23414 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23415 + h_d = au_h_dptr(d, bindex);
23417 + au_set_h_dptr(d, bindex, NULL);
23419 + au_set_dbbot(d, a->btgt);
23422 + i = a->src_inode;
23423 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23424 + return; /* success */
23426 + bbot = au_ibbot(i);
23427 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23428 + h_i = au_h_iptr(i, bindex);
23430 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23431 + /* ignore this error */
23432 + au_set_h_iptr(i, bindex, NULL, 0);
23435 + au_set_ibbot(i, a->btgt);
23438 +/* ---------------------------------------------------------------------- */
23440 +/* mainly for link(2) and rename(2) */
23441 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23443 + aufs_bindex_t bdiropq, bwh;
23444 + struct dentry *parent;
23445 + struct au_branch *br;
23447 + parent = dentry->d_parent;
23448 + IMustLock(d_inode(parent)); /* dir is locked */
23450 + bdiropq = au_dbdiropq(parent);
23451 + bwh = au_dbwh(dentry);
23452 + br = au_sbr(dentry->d_sb, btgt);
23453 + if (au_br_rdonly(br)
23454 + || (0 <= bdiropq && bdiropq < btgt)
23455 + || (0 <= bwh && bwh < btgt))
23458 + AuDbg("btgt %d\n", btgt);
23462 +/* sets src_btop, dst_btop and btgt */
23463 +static int au_ren_wbr(struct au_ren_args *a)
23466 + struct au_wr_dir_args wr_dir_args = {
23467 + /* .force_btgt = -1, */
23468 + .flags = AuWrDir_ADD_ENTRY
23471 + a->src_btop = au_dbtop(a->src_dentry);
23472 + a->dst_btop = au_dbtop(a->dst_dentry);
23473 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23474 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23475 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23476 + wr_dir_args.force_btgt = a->src_btop;
23477 + if (a->dst_inode && a->dst_btop < a->src_btop)
23478 + wr_dir_args.force_btgt = a->dst_btop;
23479 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23480 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23483 + au_update_dbtop(a->dst_dentry);
23488 +static void au_ren_dt(struct au_ren_args *a)
23490 + a->h_path.dentry = a->src_h_parent;
23491 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23492 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23493 + a->h_path.dentry = a->dst_h_parent;
23494 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23497 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23498 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23502 + a->h_path.dentry = a->src_h_dentry;
23503 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23504 + if (d_is_positive(a->dst_h_dentry)) {
23505 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23506 + a->h_path.dentry = a->dst_h_dentry;
23507 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23511 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23513 + struct dentry *h_d;
23514 + struct inode *h_inode;
23516 + au_dtime_revert(a->src_dt + AuPARENT);
23517 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23518 + au_dtime_revert(a->dst_dt + AuPARENT);
23520 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23521 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23522 + h_inode = d_inode(h_d);
23523 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23524 + au_dtime_revert(a->src_dt + AuCHILD);
23525 + inode_unlock(h_inode);
23527 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23528 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23529 + h_inode = d_inode(h_d);
23530 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23531 + au_dtime_revert(a->dst_dt + AuCHILD);
23532 + inode_unlock(h_inode);
23537 +/* ---------------------------------------------------------------------- */
23539 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23540 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23541 + unsigned int _flags)
23543 + int err, lock_flags;
23545 + /* reduce stack space */
23546 + struct au_ren_args *a;
23547 + struct au_pin pin;
23549 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23550 + IMustLock(_src_dir);
23551 + IMustLock(_dst_dir);
23554 + if (unlikely(_flags & RENAME_WHITEOUT))
23558 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23559 + a = kzalloc(sizeof(*a), GFP_NOFS);
23560 + if (unlikely(!a))
23563 + a->flags = _flags;
23564 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23565 + && RENAME_EXCHANGE > U8_MAX);
23566 + a->exchange = _flags & RENAME_EXCHANGE;
23567 + a->src_dir = _src_dir;
23568 + a->src_dentry = _src_dentry;
23569 + a->src_inode = NULL;
23570 + if (d_really_is_positive(a->src_dentry))
23571 + a->src_inode = d_inode(a->src_dentry);
23572 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23573 + a->dst_dir = _dst_dir;
23574 + a->dst_dentry = _dst_dentry;
23575 + a->dst_inode = NULL;
23576 + if (d_really_is_positive(a->dst_dentry))
23577 + a->dst_inode = d_inode(a->dst_dentry);
23578 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23579 + if (a->dst_inode) {
23581 + * if EXCHANGE && src is non-dir && dst is dir,
23582 + * dst is not locked.
23584 + /* IMustLock(a->dst_inode); */
23585 + au_igrab(a->dst_inode);
23589 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23590 + if (d_is_dir(a->src_dentry)) {
23591 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23592 + if (unlikely(!a->exchange
23593 + && d_really_is_positive(a->dst_dentry)
23594 + && !d_is_dir(a->dst_dentry)))
23596 + lock_flags |= AuLock_DIRS;
23598 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23599 + au_fset_ren(a->auren_flags, ISDIR_DST);
23600 + if (unlikely(!a->exchange
23601 + && d_really_is_positive(a->src_dentry)
23602 + && !d_is_dir(a->src_dentry)))
23604 + lock_flags |= AuLock_DIRS;
23606 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23608 + if (unlikely(err))
23611 + err = au_d_hashed_positive(a->src_dentry);
23612 + if (unlikely(err))
23615 + if (a->dst_inode) {
23617 + * If it is a dir, VFS unhash it before this
23618 + * function. It means we cannot rely upon d_unhashed().
23620 + if (unlikely(!a->dst_inode->i_nlink))
23622 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23623 + err = au_d_hashed_positive(a->dst_dentry);
23624 + if (unlikely(err && !a->exchange))
23626 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23628 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23632 + * is it possible?
23633 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23634 + * there may exist a problem somewhere else.
23637 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23640 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23641 + di_write_lock_parent(a->dst_parent);
23643 + /* which branch we process */
23644 + err = au_ren_wbr(a);
23645 + if (unlikely(err < 0))
23647 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23648 + a->h_path.mnt = au_br_mnt(a->br);
23650 + /* are they available to be renamed */
23651 + err = au_ren_may_dir(a);
23652 + if (unlikely(err))
23653 + goto out_children;
23655 + /* prepare the writable parent dir on the same branch */
23656 + if (a->dst_btop == a->btgt) {
23657 + au_fset_ren(a->auren_flags, WHDST);
23659 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23660 + if (unlikely(err))
23661 + goto out_children;
23665 + if (!a->exchange) {
23666 + if (a->src_dir != a->dst_dir) {
23668 + * this temporary unlock is safe,
23669 + * because both dir->i_mutex are locked.
23671 + di_write_unlock(a->dst_parent);
23672 + di_write_lock_parent(a->src_parent);
23673 + err = au_wr_dir_need_wh(a->src_dentry,
23674 + au_ftest_ren(a->auren_flags,
23677 + di_write_unlock(a->src_parent);
23678 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23680 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23682 + err = au_wr_dir_need_wh(a->src_dentry,
23683 + au_ftest_ren(a->auren_flags,
23687 + if (unlikely(err < 0))
23688 + goto out_children;
23690 + au_fset_ren(a->auren_flags, WHSRC);
23693 + if (a->src_btop != a->btgt) {
23694 + err = au_pin(&pin, a->src_dentry, a->btgt,
23695 + au_opt_udba(a->src_dentry->d_sb),
23696 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23698 + struct au_cp_generic cpg = {
23699 + .dentry = a->src_dentry,
23701 + .bsrc = a->src_btop,
23704 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23706 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23707 + err = au_sio_cpup_simple(&cpg);
23710 + if (unlikely(err))
23711 + goto out_children;
23712 + a->src_btop = a->btgt;
23713 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23714 + if (!a->exchange)
23715 + au_fset_ren(a->auren_flags, WHSRC);
23719 + if (a->exchange && a->dst_inode
23720 + && a->dst_btop != a->btgt) {
23721 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23722 + au_opt_udba(a->dst_dentry->d_sb),
23723 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23725 + struct au_cp_generic cpg = {
23726 + .dentry = a->dst_dentry,
23728 + .bsrc = a->dst_btop,
23731 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23733 + err = au_sio_cpup_simple(&cpg);
23736 + if (unlikely(err))
23737 + goto out_children;
23738 + a->dst_btop = a->btgt;
23739 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23742 + /* lock them all */
23743 + err = au_ren_lock(a);
23744 + if (unlikely(err))
23745 + /* leave the copied-up one */
23746 + goto out_children;
23748 + if (!a->exchange) {
23749 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23750 + err = au_may_ren(a);
23751 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23752 + err = -ENAMETOOLONG;
23753 + if (unlikely(err))
23757 + /* store timestamps to be revertible */
23760 + /* store dirren info */
23761 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23762 + err = au_dr_rename(a->src_dentry, a->btgt,
23763 + &a->dst_dentry->d_name, &rev);
23765 + if (unlikely(err))
23770 + err = do_rename(a);
23771 + if (unlikely(err))
23774 + if (au_ftest_ren(a->auren_flags, DIRREN))
23775 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23777 + /* update dir attributes */
23778 + au_ren_refresh_dir(a);
23780 + /* dput/iput all lower dentries */
23781 + au_ren_refresh(a);
23783 + goto out_hdir; /* success */
23786 + if (au_ftest_ren(a->auren_flags, DIRREN))
23787 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23789 + au_ren_rev_dt(err, a);
23791 + au_ren_unlock(a);
23793 + au_nhash_wh_free(&a->whlist);
23794 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23795 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23796 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23797 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23801 + if (d_unhashed(a->src_dentry))
23802 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23803 + if (d_unhashed(a->dst_dentry))
23804 + au_fset_ren(a->auren_flags, DROPPED_DST);
23805 + if (!a->exchange)
23806 + d_move(a->src_dentry, a->dst_dentry);
23808 + d_exchange(a->src_dentry, a->dst_dentry);
23809 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23810 + d_drop(a->dst_dentry);
23812 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23813 + d_drop(a->src_dentry);
23815 + au_update_dbtop(a->dst_dentry);
23816 + if (!a->dst_inode)
23817 + d_drop(a->dst_dentry);
23819 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23820 + di_write_unlock(a->dst_parent);
23822 + di_write_unlock2(a->src_parent, a->dst_parent);
23824 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23826 + iput(a->dst_inode);
23828 + au_whtmp_rmdir_free(a->thargs);
23834 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23835 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23836 +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200
23838 +# SPDX-License-Identifier: GPL-2.0
23840 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23842 + Aufs is a stackable unification filesystem such as Unionfs,
23843 + which unifies several directories and provides a merged single
23845 + In the early days, aufs was entirely re-designed and
23846 + re-implemented Unionfs Version 1.x series. Introducing many
23847 + original ideas, approaches and improvements, it becomes totally
23848 + different from Unionfs while keeping the basic features.
23852 + prompt "Maximum number of branches"
23853 + default AUFS_BRANCH_MAX_127
23855 + Specifies the maximum number of branches (or member directories)
23856 + in a single aufs. The larger value consumes more system
23857 + resources and has a minor impact to performance.
23858 +config AUFS_BRANCH_MAX_127
23861 + Specifies the maximum number of branches (or member directories)
23862 + in a single aufs. The larger value consumes more system
23863 + resources and has a minor impact to performance.
23864 +config AUFS_BRANCH_MAX_511
23867 + Specifies the maximum number of branches (or member directories)
23868 + in a single aufs. The larger value consumes more system
23869 + resources and has a minor impact to performance.
23870 +config AUFS_BRANCH_MAX_1023
23873 + Specifies the maximum number of branches (or member directories)
23874 + in a single aufs. The larger value consumes more system
23875 + resources and has a minor impact to performance.
23876 +config AUFS_BRANCH_MAX_32767
23879 + Specifies the maximum number of branches (or member directories)
23880 + in a single aufs. The larger value consumes more system
23881 + resources and has a minor impact to performance.
23884 +config AUFS_SBILIST
23886 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23889 + Automatic configuration for internal use.
23890 + When aufs supports Magic SysRq or /proc, enabled automatically.
23892 +config AUFS_HNOTIFY
23893 + bool "Detect direct branch access (bypassing aufs)"
23895 + If you want to modify files on branches directly, eg. bypassing aufs,
23896 + and want aufs to detect the changes of them fully, then enable this
23897 + option and use 'udba=notify' mount option.
23898 + Currently there is only one available configuration, "fsnotify".
23899 + It will have a negative impact to the performance.
23900 + See detail in aufs.5.
23903 + prompt "method" if AUFS_HNOTIFY
23904 + default AUFS_HFSNOTIFY
23905 +config AUFS_HFSNOTIFY
23910 +config AUFS_EXPORT
23911 + bool "NFS-exportable aufs"
23912 + depends on EXPORTFS
23914 + If you want to export your mounted aufs via NFS, then enable this
23915 + option. There are several requirements for this configuration.
23916 + See detail in aufs.5.
23918 +config AUFS_INO_T_64
23920 + depends on AUFS_EXPORT
23921 + depends on 64BIT && !(ALPHA || S390)
23924 + Automatic configuration for internal use.
23925 + /* typedef unsigned long/int __kernel_ino_t */
23926 + /* alpha and s390x are int */
23929 + bool "support for XATTR/EA (including Security Labels)"
23931 + If your branch fs supports XATTR/EA and you want to make them
23932 + available in aufs too, then enable this opsion and specify the
23933 + branch attributes for EA.
23934 + See detail in aufs.5.
23937 + bool "File-based Hierarchical Storage Management"
23939 + Hierarchical Storage Management (or HSM) is a well-known feature
23940 + in the storage world. Aufs provides this feature as file-based.
23941 + with multiple branches.
23942 + These multiple branches are prioritized, ie. the topmost one
23943 + should be the fastest drive and be used heavily.
23946 + bool "Readdir in userspace"
23948 + Aufs has two methods to provide a merged view for a directory,
23949 + by a user-space library and by kernel-space natively. The latter
23950 + is always enabled but sometimes large and slow.
23951 + If you enable this option, install the library in aufs2-util
23952 + package, and set some environment variables for your readdir(3),
23953 + then the work will be handled in user-space which generally
23954 + shows better performance in most cases.
23955 + See detail in aufs.5.
23957 +config AUFS_DIRREN
23958 + bool "Workaround for rename(2)-ing a directory"
23960 + By default, aufs returns EXDEV error in renameing a dir who has
23961 + his child on the lower branch, since it is a bad idea to issue
23962 + rename(2) internally for every lower branch. But user may not
23963 + accept this behaviour. So here is a workaround to allow such
23964 + rename(2) and store some extra infromation on the writable
23965 + branch. Obviously this costs high (and I don't like it).
23966 + To use this feature, you need to enable this configuration AND
23967 + to specify the mount option `dirren.'
23968 + See details in aufs.5 and the design documents.
23971 + bool "Show whiteouts"
23973 + If you want to make the whiteouts in aufs visible, then enable
23974 + this option and specify 'shwh' mount option. Although it may
23975 + sounds like philosophy or something, but in technically it
23976 + simply shows the name of whiteout with keeping its behaviour.
23978 +config AUFS_BR_RAMFS
23979 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23981 + If you want to use ramfs as an aufs branch fs, then enable this
23982 + option. Generally tmpfs is recommended.
23983 + Aufs prohibited them to be a branch fs by default, because
23984 + initramfs becomes unusable after switch_root or something
23985 + generally. If you sets initramfs as an aufs branch and boot your
23986 + system by switch_root, you will meet a problem easily since the
23987 + files in initramfs may be inaccessible.
23988 + Unless you are going to use ramfs as an aufs branch fs without
23989 + switch_root or something, leave it N.
23991 +config AUFS_BR_FUSE
23992 + bool "Fuse fs as an aufs branch"
23993 + depends on FUSE_FS
23996 + If you want to use fuse-based userspace filesystem as an aufs
23997 + branch fs, then enable this option.
23998 + It implements the internal poll(2) operation which is
23999 + implemented by fuse only (curretnly).
24004 + Automatic configuration for internal use.
24006 +config AUFS_BR_HFSPLUS
24007 + bool "Hfsplus as an aufs branch"
24008 + depends on HFSPLUS_FS
24011 + If you want to use hfsplus fs as an aufs branch fs, then enable
24012 + this option. This option introduces a small overhead at
24013 + copying-up a file on hfsplus.
24015 +config AUFS_BDEV_LOOP
24017 + depends on BLK_DEV_LOOP
24020 + Automatic configuration for internal use.
24021 + Convert =[ym] into =y.
24024 + bool "Debug aufs"
24026 + Enable this to compile aufs internal debug code.
24027 + It will have a negative impact to the performance.
24029 +config AUFS_MAGIC_SYSRQ
24031 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24034 + Automatic configuration for internal use.
24035 + When aufs supports Magic SysRq, enabled automatically.
24037 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24038 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24039 +++ linux/fs/aufs/lcnt.h 2020-01-27 10:57:18.175538316 +0100
24041 +/* SPDX-License-Identifier: GPL-2.0 */
24043 + * Copyright (C) 2018-2020 Junjiro R. Okajima
24045 + * This program, aufs is free software; you can redistribute it and/or modify
24046 + * it under the terms of the GNU General Public License as published by
24047 + * the Free Software Foundation; either version 2 of the License, or
24048 + * (at your option) any later version.
24050 + * This program is distributed in the hope that it will be useful,
24051 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24052 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24053 + * GNU General Public License for more details.
24055 + * You should have received a copy of the GNU General Public License
24056 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24060 + * simple long counter wrapper
24063 +#ifndef __AUFS_LCNT_H__
24064 +#define __AUFS_LCNT_H__
24068 +#include "debug.h"
24070 +#define AuLCntATOMIC 1
24071 +#define AuLCntPCPUCNT 2
24073 + * why does percpu_refcount require extra synchronize_rcu()s in
24074 + * au_br_do_free()
24076 +#define AuLCntPCPUREF 3
24078 +/* #define AuLCntChosen AuLCntATOMIC */
24079 +#define AuLCntChosen AuLCntPCPUCNT
24080 +/* #define AuLCntChosen AuLCntPCPUREF */
24082 +#if AuLCntChosen == AuLCntATOMIC
24083 +#include <linux/atomic.h>
24085 +typedef atomic_long_t au_lcnt_t;
24087 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24089 + atomic_long_set(cnt, 0);
24093 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24098 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24099 + int do_sync __maybe_unused)
24104 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24106 + atomic_long_inc(cnt);
24109 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24111 + atomic_long_dec(cnt);
24114 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24116 + return atomic_long_read(cnt);
24120 +#if AuLCntChosen == AuLCntPCPUCNT
24121 +#include <linux/percpu_counter.h>
24123 +typedef struct percpu_counter au_lcnt_t;
24125 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24127 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24130 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24135 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24137 + percpu_counter_destroy(cnt);
24140 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24142 + percpu_counter_inc(cnt);
24145 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24147 + percpu_counter_dec(cnt);
24150 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24154 + n = percpu_counter_sum(cnt);
24156 + if (LONG_MAX != LLONG_MAX
24158 + AuWarn1("%s\n", "wrap-around");
24164 +#if AuLCntChosen == AuLCntPCPUREF
24165 +#include <linux/percpu-refcount.h>
24167 +typedef struct percpu_ref au_lcnt_t;
24169 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24172 + release = percpu_ref_exit;
24173 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24176 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24178 + synchronize_rcu();
24181 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24183 + percpu_ref_kill(cnt);
24185 + au_lcnt_wait_for_fin(cnt);
24188 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24190 + percpu_ref_get(cnt);
24193 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24195 + percpu_ref_put(cnt);
24199 + * avoid calling this func as possible.
24201 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24205 + percpu_ref_switch_to_atomic_sync(cnt);
24206 + l = atomic_long_read(&cnt->count);
24208 + percpu_ref_switch_to_percpu(cnt);
24210 + /* percpu_ref is initialized by 1 instead of 0 */
24215 +#ifdef CONFIG_AUFS_DEBUG
24216 +#define AuLCntZero(val) do { \
24219 + AuDbg("%s = %ld\n", #val, l); \
24222 +#define AuLCntZero(val) do {} while (0)
24225 +#endif /* __KERNEL__ */
24226 +#endif /* __AUFS_LCNT_H__ */
24227 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24228 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24229 +++ linux/fs/aufs/loop.c 2020-01-27 10:57:18.175538316 +0100
24231 +// SPDX-License-Identifier: GPL-2.0
24233 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24235 + * This program, aufs is free software; you can redistribute it and/or modify
24236 + * it under the terms of the GNU General Public License as published by
24237 + * the Free Software Foundation; either version 2 of the License, or
24238 + * (at your option) any later version.
24240 + * This program is distributed in the hope that it will be useful,
24241 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24242 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24243 + * GNU General Public License for more details.
24245 + * You should have received a copy of the GNU General Public License
24246 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24250 + * support for loopback block device as a branch
24255 +/* added into drivers/block/loop.c */
24256 +static struct file *(*backing_file_func)(struct super_block *sb);
24259 + * test if two lower dentries have overlapping branches.
24261 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24263 + struct super_block *h_sb;
24264 + struct file *backing_file;
24266 + if (unlikely(!backing_file_func)) {
24267 + /* don't load "loop" module here */
24268 + backing_file_func = symbol_get(loop_backing_file);
24269 + if (unlikely(!backing_file_func))
24270 + /* "loop" module is not loaded */
24274 + h_sb = h_adding->d_sb;
24275 + backing_file = backing_file_func(h_sb);
24276 + if (!backing_file)
24279 + h_adding = backing_file->f_path.dentry;
24281 + * h_adding can be local NFS.
24282 + * in this case aufs cannot detect the loop.
24284 + if (unlikely(h_adding->d_sb == sb))
24286 + return !!au_test_subdir(h_adding, sb->s_root);
24289 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24290 +int au_test_loopback_kthread(void)
24293 + struct task_struct *tsk = current;
24294 + char c, comm[sizeof(tsk->comm)];
24297 + if (tsk->flags & PF_KTHREAD) {
24298 + get_task_comm(comm, tsk);
24300 + ret = ('0' <= c && c <= '9'
24301 + && !strncmp(comm, "loop", 4));
24307 +/* ---------------------------------------------------------------------- */
24309 +#define au_warn_loopback_step 16
24310 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24311 +static unsigned long *au_warn_loopback_array;
24313 +void au_warn_loopback(struct super_block *h_sb)
24315 + int i, new_nelem;
24316 + unsigned long *a, magic;
24317 + static DEFINE_SPINLOCK(spin);
24319 + magic = h_sb->s_magic;
24320 + spin_lock(&spin);
24321 + a = au_warn_loopback_array;
24322 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24323 + if (a[i] == magic) {
24324 + spin_unlock(&spin);
24328 + /* h_sb is new to us, print it */
24329 + if (i < au_warn_loopback_nelem) {
24334 + /* expand the array */
24335 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24336 + a = au_kzrealloc(au_warn_loopback_array,
24337 + au_warn_loopback_nelem * sizeof(unsigned long),
24338 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24339 + /*may_shrink*/0);
24341 + au_warn_loopback_nelem = new_nelem;
24342 + au_warn_loopback_array = a;
24347 + spin_unlock(&spin);
24348 + AuWarn1("realloc failed, ignored\n");
24352 + spin_unlock(&spin);
24353 + pr_warn("you may want to try another patch for loopback file "
24354 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24357 +int au_loopback_init(void)
24360 + struct super_block *sb __maybe_unused;
24362 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24365 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24366 + sizeof(unsigned long), GFP_NOFS);
24367 + if (unlikely(!au_warn_loopback_array))
24373 +void au_loopback_fin(void)
24375 + if (backing_file_func)
24376 + symbol_put(loop_backing_file);
24377 + au_kfree_try_rcu(au_warn_loopback_array);
24379 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24380 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24381 +++ linux/fs/aufs/loop.h 2020-01-27 10:57:18.175538316 +0100
24383 +/* SPDX-License-Identifier: GPL-2.0 */
24385 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24387 + * This program, aufs is free software; you can redistribute it and/or modify
24388 + * it under the terms of the GNU General Public License as published by
24389 + * the Free Software Foundation; either version 2 of the License, or
24390 + * (at your option) any later version.
24392 + * This program is distributed in the hope that it will be useful,
24393 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24394 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24395 + * GNU General Public License for more details.
24397 + * You should have received a copy of the GNU General Public License
24398 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24402 + * support for loopback mount as a branch
24405 +#ifndef __AUFS_LOOP_H__
24406 +#define __AUFS_LOOP_H__
24411 +struct super_block;
24413 +#ifdef CONFIG_AUFS_BDEV_LOOP
24414 +/* drivers/block/loop.c */
24415 +struct file *loop_backing_file(struct super_block *sb);
24418 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24419 +int au_test_loopback_kthread(void);
24420 +void au_warn_loopback(struct super_block *h_sb);
24422 +int au_loopback_init(void);
24423 +void au_loopback_fin(void);
24425 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24427 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24428 + struct dentry *h_adding)
24429 +AuStubInt0(au_test_loopback_kthread, void)
24430 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24432 +AuStubInt0(au_loopback_init, void)
24433 +AuStubVoid(au_loopback_fin, void)
24434 +#endif /* BLK_DEV_LOOP */
24436 +#endif /* __KERNEL__ */
24437 +#endif /* __AUFS_LOOP_H__ */
24438 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24439 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24440 +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200
24442 +# SPDX-License-Identifier: GPL-2.0
24444 +# defined in ${srctree}/fs/fuse/inode.c
24446 +ifdef CONFIG_FUSE_FS
24447 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24450 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24452 +ifdef CONFIG_XFS_FS
24453 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24456 +# defined in ${srctree}/fs/configfs/mount.c
24458 +ifdef CONFIG_CONFIGFS_FS
24459 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24462 +# defined in ${srctree}/fs/ubifs/ubifs.h
24464 +ifdef CONFIG_UBIFS_FS
24465 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24468 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24470 +ifdef CONFIG_HFSPLUS_FS
24471 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24473 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24474 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24475 +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200
24477 +# SPDX-License-Identifier: GPL-2.0
24479 +include ${src}/magic.mk
24480 +ifeq (${CONFIG_AUFS_FS},m)
24481 +include ${src}/conf.mk
24483 +-include ${src}/priv_def.mk
24485 +# cf. include/linux/kernel.h
24487 +ccflags-y += -DDEBUG
24488 +# sparse requires the full pathname
24490 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24492 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24495 +obj-$(CONFIG_AUFS_FS) += aufs.o
24496 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24497 + wkq.o vfsub.o dcsub.o \
24498 + cpup.o whout.o wbr_policy.o \
24499 + dinfo.o dentry.o \
24501 + finfo.o file.o f_op.o \
24503 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24507 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24508 +aufs-$(CONFIG_SYSFS) += sysfs.o
24509 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24510 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24511 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24512 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24513 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24514 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24515 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24516 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24517 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24518 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24519 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24520 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24521 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24522 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24523 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24524 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24525 +++ linux/fs/aufs/module.c 2020-01-27 10:57:18.175538316 +0100
24527 +// SPDX-License-Identifier: GPL-2.0
24529 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24531 + * This program, aufs is free software; you can redistribute it and/or modify
24532 + * it under the terms of the GNU General Public License as published by
24533 + * the Free Software Foundation; either version 2 of the License, or
24534 + * (at your option) any later version.
24536 + * This program is distributed in the hope that it will be useful,
24537 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24538 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24539 + * GNU General Public License for more details.
24541 + * You should have received a copy of the GNU General Public License
24542 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24546 + * module global variables and operations
24549 +#include <linux/module.h>
24550 +#include <linux/seq_file.h>
24553 +/* shrinkable realloc */
24554 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24562 +#if 0 /* unused */
24569 + AuDebugOn(!new_sz);
24572 + diff = au_kmidx_sub(sz, new_sz);
24578 + /* expand or SLOB */
24579 + p = krealloc(p, new_sz, gfp);
24580 + else if (new_sz < sz && may_shrink) {
24584 + q = kmalloc(new_sz, gfp);
24587 + memcpy(q, p, new_sz);
24588 + au_kfree_try_rcu(p);
24599 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24602 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24603 + if (p && new_sz > nused)
24604 + memset(p + nused, 0, new_sz - nused);
24608 +/* ---------------------------------------------------------------------- */
24612 +struct kmem_cache *au_cache[AuCache_Last];
24614 +static void au_cache_fin(void)
24619 + * Make sure all delayed rcu free inodes are flushed before we
24624 + /* excluding AuCache_HNOTIFY */
24625 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24626 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24627 + kmem_cache_destroy(au_cache[i]);
24628 + au_cache[i] = NULL;
24632 +static int __init au_cache_init(void)
24634 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24635 + if (au_cache[AuCache_DINFO])
24636 + /* SLAB_DESTROY_BY_RCU */
24637 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24638 + au_icntnr_init_once);
24639 + if (au_cache[AuCache_ICNTNR])
24640 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24641 + au_fi_init_once);
24642 + if (au_cache[AuCache_FINFO])
24643 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24644 + if (au_cache[AuCache_VDIR])
24645 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24646 + if (au_cache[AuCache_DEHSTR])
24653 +/* ---------------------------------------------------------------------- */
24655 +int au_dir_roflags;
24657 +#ifdef CONFIG_AUFS_SBILIST
24659 + * iterate_supers_type() doesn't protect us from
24660 + * remounting (branch management)
24662 +struct hlist_bl_head au_sbilist;
24666 + * functions for module interface.
24668 +MODULE_LICENSE("GPL");
24669 +/* MODULE_LICENSE("GPL v2"); */
24670 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24671 +MODULE_DESCRIPTION(AUFS_NAME
24672 + " -- Advanced multi layered unification filesystem");
24673 +MODULE_VERSION(AUFS_VERSION);
24674 +MODULE_ALIAS_FS(AUFS_NAME);
24676 +/* this module parameter has no meaning when SYSFS is disabled */
24677 +int sysaufs_brs = 1;
24678 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24679 +module_param_named(brs, sysaufs_brs, int, 0444);
24681 +/* this module parameter has no meaning when USER_NS is disabled */
24683 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24684 +module_param_named(allow_userns, au_userns, bool, 0444);
24686 +/* ---------------------------------------------------------------------- */
24688 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24690 +int au_seq_path(struct seq_file *seq, struct path *path)
24694 + err = seq_path(seq, path, au_esc_chars);
24703 +/* ---------------------------------------------------------------------- */
24705 +static int __init aufs_init(void)
24710 + p = au_esc_chars;
24711 + for (i = 1; i <= ' '; i++)
24717 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24719 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24720 + for (i = 0; i < AuIop_Last; i++)
24721 + aufs_iop_nogetattr[i].getattr = NULL;
24723 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24725 + au_sbilist_init();
24726 + sysaufs_brs_init();
24729 + err = sysaufs_init();
24730 + if (unlikely(err))
24732 + err = dbgaufs_init();
24733 + if (unlikely(err))
24734 + goto out_sysaufs;
24735 + err = au_procfs_init();
24736 + if (unlikely(err))
24737 + goto out_dbgaufs;
24738 + err = au_wkq_init();
24739 + if (unlikely(err))
24741 + err = au_loopback_init();
24742 + if (unlikely(err))
24744 + err = au_hnotify_init();
24745 + if (unlikely(err))
24746 + goto out_loopback;
24747 + err = au_sysrq_init();
24748 + if (unlikely(err))
24750 + err = au_cache_init();
24751 + if (unlikely(err))
24754 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24755 + err = register_filesystem(&aufs_fs_type);
24756 + if (unlikely(err))
24759 + /* since we define pr_fmt, call printk directly */
24760 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24761 + goto out; /* success */
24768 + au_hnotify_fin();
24770 + au_loopback_fin();
24784 +static void __exit aufs_exit(void)
24786 + unregister_filesystem(&aufs_fs_type);
24789 + au_hnotify_fin();
24790 + au_loopback_fin();
24798 +module_init(aufs_init);
24799 +module_exit(aufs_exit);
24800 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24801 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24802 +++ linux/fs/aufs/module.h 2020-01-27 10:57:18.175538316 +0100
24804 +/* SPDX-License-Identifier: GPL-2.0 */
24806 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24808 + * This program, aufs is free software; you can redistribute it and/or modify
24809 + * it under the terms of the GNU General Public License as published by
24810 + * the Free Software Foundation; either version 2 of the License, or
24811 + * (at your option) any later version.
24813 + * This program is distributed in the hope that it will be useful,
24814 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24815 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24816 + * GNU General Public License for more details.
24818 + * You should have received a copy of the GNU General Public License
24819 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24823 + * module initialization and module-global
24826 +#ifndef __AUFS_MODULE_H__
24827 +#define __AUFS_MODULE_H__
24831 +#include <linux/slab.h>
24832 +#include "debug.h"
24833 +#include "dentry.h"
24836 +#include "inode.h"
24841 +/* module parameters */
24842 +extern int sysaufs_brs;
24843 +extern bool au_userns;
24845 +/* ---------------------------------------------------------------------- */
24847 +extern int au_dir_roflags;
24849 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24850 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24854 + * Comparing the size of the object with sizeof(struct rcu_head)
24855 + * case 1: object is always larger
24856 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24857 + * case 2: object is always smaller
24858 + * --> au_kfree_small()
24859 + * case 3: object can be any size
24860 + * --> au_kfree_try_rcu()
24863 +static inline void au_kfree_do_rcu(const void *p)
24866 + struct rcu_head rcu;
24867 + } *a = (void *)p;
24869 + kfree_rcu(a, rcu);
24872 +#define au_kfree_rcu(_p) do { \
24873 + typeof(_p) p = (_p); \
24874 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24876 + au_kfree_do_rcu(p); \
24879 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24880 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24882 +static inline void au_kfree_try_rcu(const void *p)
24886 + if (au_kfree_sz_test(p))
24887 + au_kfree_do_rcu(p);
24892 +static inline void au_kfree_small(const void *p)
24896 + AuDebugOn(au_kfree_sz_test(p));
24900 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24902 +#ifndef CONFIG_SLOB
24903 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24905 + return -1; /* SLOB is untested */
24909 +int au_seq_path(struct seq_file *seq, struct path *path);
24911 +#ifdef CONFIG_PROC_FS
24913 +int __init au_procfs_init(void);
24914 +void au_procfs_fin(void);
24916 +AuStubInt0(au_procfs_init, void);
24917 +AuStubVoid(au_procfs_fin, void);
24920 +/* ---------------------------------------------------------------------- */
24929 + AuCache_HNOTIFY, /* must be last */
24933 +extern struct kmem_cache *au_cache[AuCache_Last];
24935 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24936 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24937 +#define AuCacheCtor(type, ctor) \
24938 + kmem_cache_create(#type, sizeof(struct type), \
24939 + __alignof__(struct type), AuCacheFlags, ctor)
24941 +#define AuCacheFuncs(name, index) \
24942 + static inline struct au_##name *au_cache_alloc_##name(void) \
24943 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24944 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24945 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24947 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24948 + { void *p = rcu; \
24949 + p -= offsetof(struct au_##name, rcu); \
24950 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24951 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24952 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24953 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24955 + static inline void au_cache_free_##name(struct au_##name *p) \
24956 + { /* au_cache_free_##name##_norcu(p); */ \
24957 + au_cache_free_##name##_rcu(p); }
24959 +AuCacheFuncs(dinfo, DINFO);
24960 +AuCacheFuncs(icntnr, ICNTNR);
24961 +AuCacheFuncs(finfo, FINFO);
24962 +AuCacheFuncs(vdir, VDIR);
24963 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24964 +#ifdef CONFIG_AUFS_HNOTIFY
24965 +AuCacheFuncs(hnotify, HNOTIFY);
24968 +#endif /* __KERNEL__ */
24969 +#endif /* __AUFS_MODULE_H__ */
24970 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24971 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24972 +++ linux/fs/aufs/mvdown.c 2020-01-27 10:57:18.175538316 +0100
24974 +// SPDX-License-Identifier: GPL-2.0
24976 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24978 + * This program, aufs is free software; you can redistribute it and/or modify
24979 + * it under the terms of the GNU General Public License as published by
24980 + * the Free Software Foundation; either version 2 of the License, or
24981 + * (at your option) any later version.
24983 + * This program is distributed in the hope that it will be useful,
24984 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24985 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24986 + * GNU General Public License for more details.
24988 + * You should have received a copy of the GNU General Public License
24989 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24993 + * move-down, opposite of copy-up
24998 +struct au_mvd_args {
25000 + struct super_block *h_sb;
25001 + struct dentry *h_parent;
25002 + struct au_hinode *hdir;
25003 + struct inode *h_dir, *h_inode;
25004 + struct au_pin pin;
25005 + } info[AUFS_MVDOWN_NARRAY];
25007 + struct aufs_mvdown mvdown;
25008 + struct dentry *dentry, *parent;
25009 + struct inode *inode, *dir;
25010 + struct super_block *sb;
25011 + aufs_bindex_t bopq, bwh, bfound;
25012 + unsigned char rename_lock;
25015 +#define mvd_errno mvdown.au_errno
25016 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25017 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25018 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25019 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25021 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25022 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25023 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25024 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25025 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25026 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25028 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25029 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25030 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25031 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25032 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25033 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25035 +#define AU_MVD_PR(flag, ...) do { \
25037 + pr_err(__VA_ARGS__); \
25040 +static int find_lower_writable(struct au_mvd_args *a)
25042 + struct super_block *sb;
25043 + aufs_bindex_t bindex, bbot;
25044 + struct au_branch *br;
25047 + bindex = a->mvd_bsrc;
25048 + bbot = au_sbbot(sb);
25049 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25050 + for (bindex++; bindex <= bbot; bindex++) {
25051 + br = au_sbr(sb, bindex);
25052 + if (au_br_fhsm(br->br_perm)
25053 + && !sb_rdonly(au_br_sb(br)))
25056 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25057 + for (bindex++; bindex <= bbot; bindex++) {
25058 + br = au_sbr(sb, bindex);
25059 + if (!au_br_rdonly(br))
25063 + for (bindex++; bindex <= bbot; bindex++) {
25064 + br = au_sbr(sb, bindex);
25065 + if (!sb_rdonly(au_br_sb(br))) {
25066 + if (au_br_rdonly(br))
25068 + |= AUFS_MVDOWN_ROLOWER_R;
25076 +/* make the parent dir on bdst */
25077 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25082 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25083 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25084 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25085 + a->mvd_h_dst_parent = NULL;
25086 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25087 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25088 + if (!a->mvd_h_dst_parent) {
25089 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25090 + if (unlikely(err)) {
25091 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25094 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25102 +/* lock them all */
25103 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25106 + struct dentry *h_trap;
25108 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25109 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25110 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25111 + au_opt_udba(a->sb),
25112 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25114 + if (unlikely(err)) {
25115 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25119 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25120 + a->rename_lock = 0;
25121 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25122 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25123 + au_opt_udba(a->sb),
25124 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25125 + err = au_do_pin(&a->mvd_pin_src);
25127 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25128 + if (unlikely(err)) {
25129 + AU_MVD_PR(dmsg, "pin_src failed\n");
25132 + goto out; /* success */
25135 + a->rename_lock = 1;
25136 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25137 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25138 + au_opt_udba(a->sb),
25139 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25141 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25142 + if (unlikely(err)) {
25143 + AU_MVD_PR(dmsg, "pin_src failed\n");
25144 + au_pin_hdir_lock(&a->mvd_pin_dst);
25147 + au_pin_hdir_unlock(&a->mvd_pin_src);
25148 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25149 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25151 + err = (h_trap != a->mvd_h_src_parent);
25153 + err = (h_trap != a->mvd_h_dst_parent);
25155 + BUG_ON(err); /* it should never happen */
25156 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25159 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25160 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25161 + au_pin_hdir_lock(&a->mvd_pin_src);
25162 + au_unpin(&a->mvd_pin_src);
25163 + au_pin_hdir_lock(&a->mvd_pin_dst);
25166 + goto out; /* success */
25169 + au_unpin(&a->mvd_pin_dst);
25175 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25177 + if (!a->rename_lock)
25178 + au_unpin(&a->mvd_pin_src);
25180 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25181 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25182 + au_pin_hdir_lock(&a->mvd_pin_src);
25183 + au_unpin(&a->mvd_pin_src);
25184 + au_pin_hdir_lock(&a->mvd_pin_dst);
25186 + au_unpin(&a->mvd_pin_dst);
25189 +/* copy-down the file */
25190 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25193 + struct au_cp_generic cpg = {
25194 + .dentry = a->dentry,
25195 + .bdst = a->mvd_bdst,
25196 + .bsrc = a->mvd_bsrc,
25198 + .pin = &a->mvd_pin_dst,
25199 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25202 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25203 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25204 + au_fset_cpup(cpg.flags, OVERWRITE);
25205 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25206 + au_fset_cpup(cpg.flags, RWDST);
25207 + err = au_sio_cpdown_simple(&cpg);
25208 + if (unlikely(err))
25209 + AU_MVD_PR(dmsg, "cpdown failed\n");
25216 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25219 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25222 + struct path h_path;
25223 + struct au_branch *br;
25224 + struct inode *delegated;
25226 + br = au_sbr(a->sb, a->mvd_bdst);
25227 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25228 + err = PTR_ERR(h_path.dentry);
25229 + if (IS_ERR(h_path.dentry)) {
25230 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25235 + if (d_is_positive(h_path.dentry)) {
25236 + h_path.mnt = au_br_mnt(br);
25237 + delegated = NULL;
25238 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25239 + &delegated, /*force*/0);
25240 + if (unlikely(err == -EWOULDBLOCK)) {
25241 + pr_warn("cannot retry for NFSv4 delegation"
25242 + " for an internal unlink\n");
25245 + if (unlikely(err))
25246 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25248 + dput(h_path.dentry);
25256 + * unlink the topmost h_dentry
25258 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25261 + struct path h_path;
25262 + struct inode *delegated;
25264 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25265 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25266 + delegated = NULL;
25267 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25268 + if (unlikely(err == -EWOULDBLOCK)) {
25269 + pr_warn("cannot retry for NFSv4 delegation"
25270 + " for an internal unlink\n");
25273 + if (unlikely(err))
25274 + AU_MVD_PR(dmsg, "unlink failed\n");
25280 +/* Since mvdown succeeded, we ignore an error of this function */
25281 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25284 + struct au_branch *br;
25286 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25287 + br = au_sbr(a->sb, a->mvd_bsrc);
25288 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25290 + br = au_sbr(a->sb, a->mvd_bdst);
25291 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25292 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25295 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25297 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25301 + * copy-down the file and unlink the bsrc file.
25302 + * - unlink the bdst whout if exist
25303 + * - copy-down the file (with whtmp name and rename)
25304 + * - unlink the bsrc file
25306 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25310 + err = au_do_mkdir(dmsg, a);
25312 + err = au_do_lock(dmsg, a);
25313 + if (unlikely(err))
25317 + * do not revert the activities we made on bdst since they should be
25318 + * harmless in aufs.
25321 + err = au_do_cpdown(dmsg, a);
25323 + err = au_do_unlink_wh(dmsg, a);
25324 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25325 + err = au_do_unlink(dmsg, a);
25326 + if (unlikely(err))
25329 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25330 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25331 + if (find_lower_writable(a) < 0)
25332 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25334 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25335 + au_do_stfs(dmsg, a);
25337 + /* maintain internal array */
25338 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25339 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25340 + au_set_dbtop(a->dentry, a->mvd_bdst);
25341 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25342 + au_set_ibtop(a->inode, a->mvd_bdst);
25344 + /* hide the lower */
25345 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25346 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25347 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25348 + au_set_ibbot(a->inode, a->mvd_bsrc);
25350 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25351 + au_set_dbbot(a->dentry, a->mvd_bdst);
25352 + if (au_ibbot(a->inode) < a->mvd_bdst)
25353 + au_set_ibbot(a->inode, a->mvd_bdst);
25356 + au_do_unlock(dmsg, a);
25362 +/* ---------------------------------------------------------------------- */
25364 +/* make sure the file is idle */
25365 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25367 + int err, plinked;
25370 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25371 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25372 + && au_dcount(a->dentry) == 1
25373 + && atomic_read(&a->inode->i_count) == 1
25374 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25375 + && (!plinked || !au_plink_test(a->inode))
25376 + && a->inode->i_nlink == 1)
25381 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25382 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25383 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25384 + a->mvd_h_src_inode->i_nlink,
25385 + plinked, plinked ? au_plink_test(a->inode) : 0);
25392 +/* make sure the parent dir is fine */
25393 +static int au_mvd_args_parent(const unsigned char dmsg,
25394 + struct au_mvd_args *a)
25397 + aufs_bindex_t bindex;
25400 + if (unlikely(au_alive_dir(a->parent))) {
25402 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25406 + a->bopq = au_dbdiropq(a->parent);
25407 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25408 + AuDbg("b%d\n", bindex);
25409 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25410 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25412 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25413 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25414 + a->bopq, a->mvd_bdst);
25422 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25423 + struct au_mvd_args *a)
25426 + struct au_dinfo *dinfo, *tmp;
25428 + /* lookup the next lower positive entry */
25430 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25431 + if (unlikely(!tmp))
25436 + dinfo = au_di(a->dentry);
25437 + au_di_cp(tmp, dinfo);
25438 + au_di_swap(tmp, dinfo);
25440 + /* returns the number of positive dentries */
25441 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25442 + /* AuLkup_IGNORE_PERM */ 0);
25444 + a->bwh = au_dbwh(a->dentry);
25445 + else if (err > 0)
25446 + a->bfound = au_dbtop(a->dentry);
25448 + au_di_swap(tmp, dinfo);
25449 + au_rw_write_unlock(&tmp->di_rwsem);
25451 + if (unlikely(err < 0))
25452 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25455 + * here, we have these cases.
25457 + * no positive dentry under bsrc. there are more sub-cases.
25459 + * there no whiteout, we can safely move-down.
25462 + * bsrc < bwh && bwh < bdst
25463 + * there is a whiteout on RO branch. cannot proceed.
25465 + * there is a whiteout on the RW target branch. it should
25468 + * there is a whiteout somewhere unrelated branch.
25469 + * -1 < bfound && bfound <= bsrc
25472 + * found, but it is on RO branch between bsrc and bdst. cannot
25475 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25478 + * found, after we create the file on bdst, it will be hidden.
25481 + AuDebugOn(a->bfound == -1
25483 + && a->bwh <= a->mvd_bsrc);
25484 + AuDebugOn(-1 < a->bfound
25485 + && a->bfound <= a->mvd_bsrc);
25488 + if (a->bfound == -1
25489 + && a->mvd_bsrc < a->bwh
25491 + && a->bwh < a->mvd_bdst) {
25492 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25493 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25494 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25496 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25497 + a->mvd_errno = EAU_MVDOWN_UPPER;
25498 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25499 + a->mvd_bdst, a->bfound);
25503 + err = 0; /* success */
25510 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25515 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25516 + && a->bfound == a->mvd_bdst)
25522 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25525 + struct au_branch *br;
25528 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25532 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25533 + a->mvd_bsrc = au_ibtop(a->inode);
25535 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25536 + if (unlikely(a->mvd_bsrc < 0
25537 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25538 + || au_dbbot(a->dentry) < a->mvd_bsrc
25539 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25540 + || (a->mvd_bsrc < au_ibtop(a->inode)
25541 + || au_ibbot(a->inode) < a->mvd_bsrc
25542 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25543 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25544 + AU_MVD_PR(dmsg, "no upper\n");
25548 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25549 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25550 + AU_MVD_PR(dmsg, "on the bottom\n");
25553 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25554 + br = au_sbr(a->sb, a->mvd_bsrc);
25555 + err = au_br_rdonly(br);
25556 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25557 + if (unlikely(err))
25559 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25560 + || IS_APPEND(a->mvd_h_src_inode))) {
25562 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25568 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25569 + a->mvd_bdst = find_lower_writable(a);
25570 + if (unlikely(a->mvd_bdst < 0)) {
25571 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25572 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25576 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25577 + if (unlikely(a->mvd_bdst < 0
25578 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25579 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25580 + AU_MVD_PR(dmsg, "no lower brid\n");
25585 + err = au_mvd_args_busy(dmsg, a);
25587 + err = au_mvd_args_parent(dmsg, a);
25589 + err = au_mvd_args_intermediate(dmsg, a);
25591 + err = au_mvd_args_exist(dmsg, a);
25593 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25600 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25603 + unsigned char dmsg;
25604 + struct au_mvd_args *args;
25605 + struct inode *inode;
25607 + inode = d_inode(dentry);
25609 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25613 + args = kmalloc(sizeof(*args), GFP_NOFS);
25614 + if (unlikely(!args))
25617 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25619 + /* VERIFY_WRITE */
25620 + err = !access_ok(uarg, sizeof(*uarg));
25621 + if (unlikely(err)) {
25626 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25627 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25628 + args->mvdown.au_errno = 0;
25629 + args->dentry = dentry;
25630 + args->inode = inode;
25631 + args->sb = dentry->d_sb;
25634 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25635 + args->parent = dget_parent(dentry);
25636 + args->dir = d_inode(args->parent);
25637 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25638 + dput(args->parent);
25639 + if (unlikely(args->parent != dentry->d_parent)) {
25640 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25644 + inode_lock_nested(inode, I_MUTEX_CHILD);
25645 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25646 + if (unlikely(err))
25649 + di_write_lock_parent(args->parent);
25650 + err = au_mvd_args(dmsg, args);
25651 + if (unlikely(err))
25654 + err = au_do_mvdown(dmsg, args);
25655 + if (unlikely(err))
25658 + au_cpup_attr_timesizes(args->dir);
25659 + au_cpup_attr_timesizes(inode);
25660 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25661 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25662 + /* au_digen_dec(dentry); */
25665 + di_write_unlock(args->parent);
25666 + aufs_read_unlock(dentry, AuLock_DW);
25668 + inode_unlock(inode);
25670 + inode_unlock(args->dir);
25672 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25675 + au_kfree_rcu(args);
25680 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25681 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25682 +++ linux/fs/aufs/opts.c 2020-01-27 10:57:18.175538316 +0100
25684 +// SPDX-License-Identifier: GPL-2.0
25686 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25688 + * This program, aufs is free software; you can redistribute it and/or modify
25689 + * it under the terms of the GNU General Public License as published by
25690 + * the Free Software Foundation; either version 2 of the License, or
25691 + * (at your option) any later version.
25693 + * This program is distributed in the hope that it will be useful,
25694 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25695 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25696 + * GNU General Public License for more details.
25698 + * You should have received a copy of the GNU General Public License
25699 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25703 + * mount options/flags
25706 +#include <linux/namei.h>
25707 +#include <linux/types.h> /* a distribution requires */
25708 +#include <linux/parser.h>
25711 +/* ---------------------------------------------------------------------- */
25715 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25716 + Opt_idel, Opt_imod,
25717 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25718 + Opt_rdblk_def, Opt_rdhash_def,
25719 + Opt_xino, Opt_noxino,
25720 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25721 + Opt_trunc_xino_path, Opt_itrunc_xino,
25722 + Opt_trunc_xib, Opt_notrunc_xib,
25723 + Opt_shwh, Opt_noshwh,
25724 + Opt_plink, Opt_noplink, Opt_list_plink,
25726 + Opt_dio, Opt_nodio,
25727 + Opt_diropq_a, Opt_diropq_w,
25728 + Opt_warn_perm, Opt_nowarn_perm,
25729 + Opt_wbr_copyup, Opt_wbr_create,
25731 + Opt_verbose, Opt_noverbose,
25732 + Opt_sum, Opt_nosum, Opt_wsum,
25733 + Opt_dirperm1, Opt_nodirperm1,
25734 + Opt_dirren, Opt_nodirren,
25735 + Opt_acl, Opt_noacl,
25736 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25739 +static match_table_t options = {
25740 + {Opt_br, "br=%s"},
25741 + {Opt_br, "br:%s"},
25743 + {Opt_add, "add=%d:%s"},
25744 + {Opt_add, "add:%d:%s"},
25745 + {Opt_add, "ins=%d:%s"},
25746 + {Opt_add, "ins:%d:%s"},
25747 + {Opt_append, "append=%s"},
25748 + {Opt_append, "append:%s"},
25749 + {Opt_prepend, "prepend=%s"},
25750 + {Opt_prepend, "prepend:%s"},
25752 + {Opt_del, "del=%s"},
25753 + {Opt_del, "del:%s"},
25754 + /* {Opt_idel, "idel:%d"}, */
25755 + {Opt_mod, "mod=%s"},
25756 + {Opt_mod, "mod:%s"},
25757 + /* {Opt_imod, "imod:%d:%s"}, */
25759 + {Opt_dirwh, "dirwh=%d"},
25761 + {Opt_xino, "xino=%s"},
25762 + {Opt_noxino, "noxino"},
25763 + {Opt_trunc_xino, "trunc_xino"},
25764 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25765 + {Opt_notrunc_xino, "notrunc_xino"},
25766 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25767 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25768 + /* {Opt_zxino, "zxino=%s"}, */
25769 + {Opt_trunc_xib, "trunc_xib"},
25770 + {Opt_notrunc_xib, "notrunc_xib"},
25772 +#ifdef CONFIG_PROC_FS
25773 + {Opt_plink, "plink"},
25775 + {Opt_ignore_silent, "plink"},
25778 + {Opt_noplink, "noplink"},
25780 +#ifdef CONFIG_AUFS_DEBUG
25781 + {Opt_list_plink, "list_plink"},
25784 + {Opt_udba, "udba=%s"},
25786 + {Opt_dio, "dio"},
25787 + {Opt_nodio, "nodio"},
25789 +#ifdef CONFIG_AUFS_DIRREN
25790 + {Opt_dirren, "dirren"},
25791 + {Opt_nodirren, "nodirren"},
25793 + {Opt_ignore, "dirren"},
25794 + {Opt_ignore_silent, "nodirren"},
25797 +#ifdef CONFIG_AUFS_FHSM
25798 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25800 + {Opt_ignore, "fhsm_sec=%d"},
25803 + {Opt_diropq_a, "diropq=always"},
25804 + {Opt_diropq_a, "diropq=a"},
25805 + {Opt_diropq_w, "diropq=whiteouted"},
25806 + {Opt_diropq_w, "diropq=w"},
25808 + {Opt_warn_perm, "warn_perm"},
25809 + {Opt_nowarn_perm, "nowarn_perm"},
25811 + /* keep them temporary */
25812 + {Opt_ignore_silent, "nodlgt"},
25813 + {Opt_ignore, "clean_plink"},
25815 +#ifdef CONFIG_AUFS_SHWH
25816 + {Opt_shwh, "shwh"},
25818 + {Opt_noshwh, "noshwh"},
25820 + {Opt_dirperm1, "dirperm1"},
25821 + {Opt_nodirperm1, "nodirperm1"},
25823 + {Opt_verbose, "verbose"},
25824 + {Opt_verbose, "v"},
25825 + {Opt_noverbose, "noverbose"},
25826 + {Opt_noverbose, "quiet"},
25827 + {Opt_noverbose, "q"},
25828 + {Opt_noverbose, "silent"},
25830 + {Opt_sum, "sum"},
25831 + {Opt_nosum, "nosum"},
25832 + {Opt_wsum, "wsum"},
25834 + {Opt_rdcache, "rdcache=%d"},
25835 + {Opt_rdblk, "rdblk=%d"},
25836 + {Opt_rdblk_def, "rdblk=def"},
25837 + {Opt_rdhash, "rdhash=%d"},
25838 + {Opt_rdhash_def, "rdhash=def"},
25840 + {Opt_wbr_create, "create=%s"},
25841 + {Opt_wbr_create, "create_policy=%s"},
25842 + {Opt_wbr_copyup, "cpup=%s"},
25843 + {Opt_wbr_copyup, "copyup=%s"},
25844 + {Opt_wbr_copyup, "copyup_policy=%s"},
25846 + /* generic VFS flag */
25847 +#ifdef CONFIG_FS_POSIX_ACL
25848 + {Opt_acl, "acl"},
25849 + {Opt_noacl, "noacl"},
25851 + {Opt_ignore, "acl"},
25852 + {Opt_ignore_silent, "noacl"},
25855 + /* internal use for the scripts */
25856 + {Opt_ignore_silent, "si=%s"},
25858 + {Opt_br, "dirs=%s"},
25859 + {Opt_ignore, "debug=%d"},
25860 + {Opt_ignore, "delete=whiteout"},
25861 + {Opt_ignore, "delete=all"},
25862 + {Opt_ignore, "imap=%s"},
25864 + /* temporary workaround, due to old mount(8)? */
25865 + {Opt_ignore_silent, "relatime"},
25870 +/* ---------------------------------------------------------------------- */
25872 +static const char *au_parser_pattern(int val, match_table_t tbl)
25874 + struct match_token *p;
25877 + while (p->pattern) {
25878 + if (p->token == val)
25879 + return p->pattern;
25886 +static const char *au_optstr(int *val, match_table_t tbl)
25888 + struct match_token *p;
25895 + while (p->pattern) {
25897 + && (v & p->token) == p->token) {
25898 + *val &= ~p->token;
25899 + return p->pattern;
25908 +/* ---------------------------------------------------------------------- */
25910 +static match_table_t brperm = {
25911 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25912 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25913 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25917 +static match_table_t brattr = {
25919 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25920 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25921 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25922 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25923 +#ifdef CONFIG_AUFS_FHSM
25924 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25926 +#ifdef CONFIG_AUFS_XATTR
25927 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25928 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25929 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25930 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25931 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25932 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25935 + /* ro/rr branch */
25936 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25939 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25940 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25945 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25952 + p = strchr(str, '+');
25955 + v = match_token(str, table, args);
25957 + if (v & AuBrAttr_CMOO_Mask)
25958 + attr &= ~AuBrAttr_CMOO_Mask;
25963 + pr_warn("ignored branch attribute %s\n", str);
25973 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25981 + p = au_optstr(&perm, brattr);
25984 + memcpy(q, p, sz + 1);
25990 + p = au_optstr(&perm, brattr);
25994 + memcpy(q, p, sz + 1);
26000 + return q - str->a;
26003 +static int noinline_for_stack br_perm_val(char *perm)
26005 + int val, bad, sz;
26007 + substring_t args[MAX_OPT_ARGS];
26008 + au_br_perm_str_t attr;
26010 + p = strchr(perm, '+');
26013 + val = match_token(perm, brperm, args);
26017 + pr_warn("ignored branch permission %s\n", perm);
26018 + val = AuBrPerm_RO;
26024 + val |= br_attr_val(p + 1, brattr, args);
26027 + switch (val & AuBrPerm_Mask) {
26028 + case AuBrPerm_RO:
26029 + case AuBrPerm_RR:
26030 + bad = val & AuBrWAttr_Mask;
26031 + val &= ~AuBrWAttr_Mask;
26033 + case AuBrPerm_RW:
26034 + bad = val & AuBrRAttr_Mask;
26035 + val &= ~AuBrRAttr_Mask;
26040 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26041 + * does not treat it as an error, just warning.
26042 + * this is a tiny guard for the user operation.
26044 + if (val & AuBrAttr_UNPIN) {
26045 + bad |= AuBrAttr_UNPIN;
26046 + val &= ~AuBrAttr_UNPIN;
26049 + if (unlikely(bad)) {
26050 + sz = au_do_optstr_br_attr(&attr, bad);
26052 + pr_warn("ignored branch attribute %s\n", attr.a);
26059 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26061 + au_br_perm_str_t attr;
26067 + p = au_optstr(&perm, brperm);
26068 + AuDebugOn(!p || !*p);
26070 + memcpy(q, p, sz + 1);
26073 + sz = au_do_optstr_br_attr(&attr, perm);
26076 + memcpy(q, attr.a, sz + 1);
26079 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26082 +/* ---------------------------------------------------------------------- */
26084 +static match_table_t udbalevel = {
26085 + {AuOpt_UDBA_REVAL, "reval"},
26086 + {AuOpt_UDBA_NONE, "none"},
26087 +#ifdef CONFIG_AUFS_HNOTIFY
26088 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26089 +#ifdef CONFIG_AUFS_HFSNOTIFY
26090 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26096 +static int noinline_for_stack udba_val(char *str)
26098 + substring_t args[MAX_OPT_ARGS];
26100 + return match_token(str, udbalevel, args);
26103 +const char *au_optstr_udba(int udba)
26105 + return au_parser_pattern(udba, udbalevel);
26108 +/* ---------------------------------------------------------------------- */
26110 +static match_table_t au_wbr_create_policy = {
26111 + {AuWbrCreate_TDP, "tdp"},
26112 + {AuWbrCreate_TDP, "top-down-parent"},
26113 + {AuWbrCreate_RR, "rr"},
26114 + {AuWbrCreate_RR, "round-robin"},
26115 + {AuWbrCreate_MFS, "mfs"},
26116 + {AuWbrCreate_MFS, "most-free-space"},
26117 + {AuWbrCreate_MFSV, "mfs:%d"},
26118 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26120 + /* top-down regardless the parent, and then mfs */
26121 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26122 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26124 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26125 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26126 + {AuWbrCreate_PMFS, "pmfs"},
26127 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26128 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26129 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26134 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26135 + struct au_opt_wbr_create *create)
26138 + unsigned long long ull;
26141 + if (!match_u64(arg, &ull))
26142 + create->mfsrr_watermark = ull;
26144 + pr_err("bad integer in %s\n", str);
26151 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26152 + struct au_opt_wbr_create *create)
26157 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26158 + create->mfs_second = n;
26160 + pr_err("bad integer in %s\n", str);
26167 +static int noinline_for_stack
26168 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26171 + substring_t args[MAX_OPT_ARGS];
26173 + err = match_token(str, au_wbr_create_policy, args);
26174 + create->wbr_create = err;
26176 + case AuWbrCreate_MFSRRV:
26177 + case AuWbrCreate_TDMFSV:
26178 + case AuWbrCreate_PMFSRRV:
26179 + e = au_wbr_mfs_wmark(&args[0], str, create);
26181 + e = au_wbr_mfs_sec(&args[1], str, create);
26185 + case AuWbrCreate_MFSRR:
26186 + case AuWbrCreate_TDMFS:
26187 + case AuWbrCreate_PMFSRR:
26188 + e = au_wbr_mfs_wmark(&args[0], str, create);
26189 + if (unlikely(e)) {
26194 + case AuWbrCreate_MFS:
26195 + case AuWbrCreate_PMFS:
26196 + create->mfs_second = AUFS_MFS_DEF_SEC;
26198 + case AuWbrCreate_MFSV:
26199 + case AuWbrCreate_PMFSV:
26200 + e = au_wbr_mfs_sec(&args[0], str, create);
26209 +const char *au_optstr_wbr_create(int wbr_create)
26211 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26214 +static match_table_t au_wbr_copyup_policy = {
26215 + {AuWbrCopyup_TDP, "tdp"},
26216 + {AuWbrCopyup_TDP, "top-down-parent"},
26217 + {AuWbrCopyup_BUP, "bup"},
26218 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26219 + {AuWbrCopyup_BU, "bu"},
26220 + {AuWbrCopyup_BU, "bottom-up"},
26224 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26226 + substring_t args[MAX_OPT_ARGS];
26228 + return match_token(str, au_wbr_copyup_policy, args);
26231 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26233 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26236 +/* ---------------------------------------------------------------------- */
26238 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26240 +static void dump_opts(struct au_opts *opts)
26242 +#ifdef CONFIG_AUFS_DEBUG
26243 + /* reduce stack space */
26245 + struct au_opt_add *add;
26246 + struct au_opt_del *del;
26247 + struct au_opt_mod *mod;
26248 + struct au_opt_xino *xino;
26249 + struct au_opt_xino_itrunc *xino_itrunc;
26250 + struct au_opt_wbr_create *create;
26252 + struct au_opt *opt;
26255 + while (opt->type != Opt_tail) {
26256 + switch (opt->type) {
26258 + u.add = &opt->add;
26259 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26260 + u.add->bindex, u.add->pathname, u.add->perm,
26261 + u.add->path.dentry);
26265 + u.del = &opt->del;
26266 + AuDbg("del {%s, %p}\n",
26267 + u.del->pathname, u.del->h_path.dentry);
26271 + u.mod = &opt->mod;
26272 + AuDbg("mod {%s, 0x%x, %p}\n",
26273 + u.mod->path, u.mod->perm, u.mod->h_root);
26276 + u.add = &opt->add;
26277 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26278 + u.add->bindex, u.add->pathname, u.add->perm,
26279 + u.add->path.dentry);
26281 + case Opt_prepend:
26282 + u.add = &opt->add;
26283 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26284 + u.add->bindex, u.add->pathname, u.add->perm,
26285 + u.add->path.dentry);
26288 + AuDbg("dirwh %d\n", opt->dirwh);
26290 + case Opt_rdcache:
26291 + AuDbg("rdcache %d\n", opt->rdcache);
26294 + AuDbg("rdblk %u\n", opt->rdblk);
26296 + case Opt_rdblk_def:
26297 + AuDbg("rdblk_def\n");
26300 + AuDbg("rdhash %u\n", opt->rdhash);
26302 + case Opt_rdhash_def:
26303 + AuDbg("rdhash_def\n");
26306 + u.xino = &opt->xino;
26307 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26309 + case Opt_trunc_xino:
26310 + AuLabel(trunc_xino);
26312 + case Opt_notrunc_xino:
26313 + AuLabel(notrunc_xino);
26315 + case Opt_trunc_xino_path:
26316 + case Opt_itrunc_xino:
26317 + u.xino_itrunc = &opt->xino_itrunc;
26318 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26323 + case Opt_trunc_xib:
26324 + AuLabel(trunc_xib);
26326 + case Opt_notrunc_xib:
26327 + AuLabel(notrunc_xib);
26335 + case Opt_dirperm1:
26336 + AuLabel(dirperm1);
26338 + case Opt_nodirperm1:
26339 + AuLabel(nodirperm1);
26344 + case Opt_noplink:
26345 + AuLabel(noplink);
26347 + case Opt_list_plink:
26348 + AuLabel(list_plink);
26351 + AuDbg("udba %d, %s\n",
26352 + opt->udba, au_optstr_udba(opt->udba));
26360 + case Opt_diropq_a:
26361 + AuLabel(diropq_a);
26363 + case Opt_diropq_w:
26364 + AuLabel(diropq_w);
26366 + case Opt_warn_perm:
26367 + AuLabel(warn_perm);
26369 + case Opt_nowarn_perm:
26370 + AuLabel(nowarn_perm);
26372 + case Opt_verbose:
26373 + AuLabel(verbose);
26375 + case Opt_noverbose:
26376 + AuLabel(noverbose);
26387 + case Opt_wbr_create:
26388 + u.create = &opt->wbr_create;
26389 + AuDbg("create %d, %s\n", u.create->wbr_create,
26390 + au_optstr_wbr_create(u.create->wbr_create));
26391 + switch (u.create->wbr_create) {
26392 + case AuWbrCreate_MFSV:
26393 + case AuWbrCreate_PMFSV:
26394 + AuDbg("%d sec\n", u.create->mfs_second);
26396 + case AuWbrCreate_MFSRR:
26397 + case AuWbrCreate_TDMFS:
26398 + AuDbg("%llu watermark\n",
26399 + u.create->mfsrr_watermark);
26401 + case AuWbrCreate_MFSRRV:
26402 + case AuWbrCreate_TDMFSV:
26403 + case AuWbrCreate_PMFSRRV:
26404 + AuDbg("%llu watermark, %d sec\n",
26405 + u.create->mfsrr_watermark,
26406 + u.create->mfs_second);
26410 + case Opt_wbr_copyup:
26411 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26412 + au_optstr_wbr_copyup(opt->wbr_copyup));
26414 + case Opt_fhsm_sec:
26415 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26420 + case Opt_nodirren:
26421 + AuLabel(nodirren);
26437 +void au_opts_free(struct au_opts *opts)
26439 + struct au_opt *opt;
26442 + while (opt->type != Opt_tail) {
26443 + switch (opt->type) {
26446 + case Opt_prepend:
26447 + path_put(&opt->add.path);
26451 + path_put(&opt->del.h_path);
26455 + dput(opt->mod.h_root);
26458 + fput(opt->xino.file);
26465 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26466 + aufs_bindex_t bindex)
26469 + struct au_opt_add *add = &opt->add;
26472 + add->bindex = bindex;
26473 + add->perm = AuBrPerm_RO;
26474 + add->pathname = opt_str;
26475 + p = strchr(opt_str, '=');
26479 + add->perm = br_perm_val(p);
26482 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26485 + add->perm = AuBrPerm_RO;
26486 + if (au_test_fs_rr(add->path.dentry->d_sb))
26487 + add->perm = AuBrPerm_RR;
26488 + else if (!bindex && !(sb_flags & SB_RDONLY))
26489 + add->perm = AuBrPerm_RW;
26491 + opt->type = Opt_add;
26494 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26501 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26505 + del->pathname = args[0].from;
26506 + AuDbg("del path %s\n", del->pathname);
26508 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26509 + if (unlikely(err))
26510 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26515 +#if 0 /* reserved for future use */
26516 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26517 + struct au_opt_del *del, substring_t args[])
26520 + struct dentry *root;
26523 + root = sb->s_root;
26524 + aufs_read_lock(root, AuLock_FLUSH);
26525 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26526 + pr_err("out of bounds, %d\n", bindex);
26531 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26532 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26535 + aufs_read_unlock(root, !AuLock_IR);
26540 +static int noinline_for_stack
26541 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26544 + struct path path;
26548 + mod->path = args[0].from;
26549 + p = strchr(mod->path, '=');
26550 + if (unlikely(!p)) {
26551 + pr_err("no permission %s\n", args[0].from);
26556 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26557 + if (unlikely(err)) {
26558 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26562 + mod->perm = br_perm_val(p);
26563 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26564 + mod->h_root = dget(path.dentry);
26571 +#if 0 /* reserved for future use */
26572 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26573 + struct au_opt_mod *mod, substring_t args[])
26576 + struct dentry *root;
26579 + root = sb->s_root;
26580 + aufs_read_lock(root, AuLock_FLUSH);
26581 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26582 + pr_err("out of bounds, %d\n", bindex);
26587 + mod->perm = br_perm_val(args[1].from);
26588 + AuDbg("mod path %s, perm 0x%x, %s\n",
26589 + mod->path, mod->perm, args[1].from);
26590 + mod->h_root = dget(au_h_dptr(root, bindex));
26593 + aufs_read_unlock(root, !AuLock_IR);
26598 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26599 + substring_t args[])
26602 + struct file *file;
26604 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26605 + err = PTR_ERR(file);
26606 + if (IS_ERR(file))
26610 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26612 + pr_err("%s must be outside\n", args[0].from);
26617 + xino->file = file;
26618 + xino->path = args[0].from;
26624 +static int noinline_for_stack
26625 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26626 + struct au_opt_xino_itrunc *xino_itrunc,
26627 + substring_t args[])
26630 + aufs_bindex_t bbot, bindex;
26631 + struct path path;
26632 + struct dentry *root;
26634 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26635 + if (unlikely(err)) {
26636 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26640 + xino_itrunc->bindex = -1;
26641 + root = sb->s_root;
26642 + aufs_read_lock(root, AuLock_FLUSH);
26643 + bbot = au_sbbot(sb);
26644 + for (bindex = 0; bindex <= bbot; bindex++) {
26645 + if (au_h_dptr(root, bindex) == path.dentry) {
26646 + xino_itrunc->bindex = bindex;
26650 + aufs_read_unlock(root, !AuLock_IR);
26653 + if (unlikely(xino_itrunc->bindex < 0)) {
26654 + pr_err("no such branch %s\n", args[0].from);
26662 +/* called without aufs lock */
26663 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26665 + int err, n, token;
26666 + aufs_bindex_t bindex;
26667 + unsigned char skipped;
26668 + struct dentry *root;
26669 + struct au_opt *opt, *opt_tail;
26671 + /* reduce the stack space */
26673 + struct au_opt_xino_itrunc *xino_itrunc;
26674 + struct au_opt_wbr_create *create;
26677 + substring_t args[MAX_OPT_ARGS];
26681 + a = kmalloc(sizeof(*a), GFP_NOFS);
26682 + if (unlikely(!a))
26685 + root = sb->s_root;
26689 + opt_tail = opt + opts->max_opt - 1;
26690 + opt->type = Opt_tail;
26691 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26694 + token = match_token(opt_str, options, a->args);
26698 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26700 + err = opt_add(opt, opt_str, opts->sb_flags,
26702 + if (unlikely(!err && ++opt > opt_tail)) {
26706 + opt->type = Opt_tail;
26711 + if (unlikely(match_int(&a->args[0], &n))) {
26712 + pr_err("bad integer in %s\n", opt_str);
26716 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26719 + opt->type = token;
26722 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26723 + /*dummy bindex*/1);
26725 + opt->type = token;
26727 + case Opt_prepend:
26728 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26731 + opt->type = token;
26734 + err = au_opts_parse_del(&opt->del, a->args);
26736 + opt->type = token;
26738 +#if 0 /* reserved for future use */
26740 + del->pathname = "(indexed)";
26741 + if (unlikely(match_int(&args[0], &n))) {
26742 + pr_err("bad integer in %s\n", opt_str);
26745 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26747 + opt->type = token;
26751 + err = au_opts_parse_mod(&opt->mod, a->args);
26753 + opt->type = token;
26755 +#ifdef IMOD /* reserved for future use */
26757 + u.mod->path = "(indexed)";
26758 + if (unlikely(match_int(&a->args[0], &n))) {
26759 + pr_err("bad integer in %s\n", opt_str);
26762 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26764 + opt->type = token;
26768 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26770 + opt->type = token;
26773 + case Opt_trunc_xino_path:
26774 + err = au_opts_parse_xino_itrunc_path
26775 + (sb, &opt->xino_itrunc, a->args);
26777 + opt->type = token;
26780 + case Opt_itrunc_xino:
26781 + u.xino_itrunc = &opt->xino_itrunc;
26782 + if (unlikely(match_int(&a->args[0], &n))) {
26783 + pr_err("bad integer in %s\n", opt_str);
26786 + u.xino_itrunc->bindex = n;
26787 + aufs_read_lock(root, AuLock_FLUSH);
26788 + if (n < 0 || au_sbbot(sb) < n) {
26789 + pr_err("out of bounds, %d\n", n);
26790 + aufs_read_unlock(root, !AuLock_IR);
26793 + aufs_read_unlock(root, !AuLock_IR);
26795 + opt->type = token;
26799 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26802 + opt->type = token;
26805 + case Opt_rdcache:
26806 + if (unlikely(match_int(&a->args[0], &n))) {
26807 + pr_err("bad integer in %s\n", opt_str);
26810 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26811 + pr_err("rdcache must be smaller than %d\n",
26812 + AUFS_RDCACHE_MAX);
26815 + opt->rdcache = n;
26817 + opt->type = token;
26820 + if (unlikely(match_int(&a->args[0], &n)
26822 + || n > KMALLOC_MAX_SIZE)) {
26823 + pr_err("bad integer in %s\n", opt_str);
26826 + if (unlikely(n && n < NAME_MAX)) {
26827 + pr_err("rdblk must be larger than %d\n",
26833 + opt->type = token;
26836 + if (unlikely(match_int(&a->args[0], &n)
26838 + || n * sizeof(struct hlist_head)
26839 + > KMALLOC_MAX_SIZE)) {
26840 + pr_err("bad integer in %s\n", opt_str);
26845 + opt->type = token;
26848 + case Opt_trunc_xino:
26849 + case Opt_notrunc_xino:
26851 + case Opt_trunc_xib:
26852 + case Opt_notrunc_xib:
26855 + case Opt_dirperm1:
26856 + case Opt_nodirperm1:
26858 + case Opt_noplink:
26859 + case Opt_list_plink:
26862 + case Opt_diropq_a:
26863 + case Opt_diropq_w:
26864 + case Opt_warn_perm:
26865 + case Opt_nowarn_perm:
26866 + case Opt_verbose:
26867 + case Opt_noverbose:
26871 + case Opt_rdblk_def:
26872 + case Opt_rdhash_def:
26874 + case Opt_nodirren:
26878 + opt->type = token;
26882 + opt->udba = udba_val(a->args[0].from);
26883 + if (opt->udba >= 0) {
26885 + opt->type = token;
26887 + pr_err("wrong value, %s\n", opt_str);
26890 + case Opt_wbr_create:
26891 + u.create = &opt->wbr_create;
26892 + u.create->wbr_create
26893 + = au_wbr_create_val(a->args[0].from, u.create);
26894 + if (u.create->wbr_create >= 0) {
26896 + opt->type = token;
26898 + pr_err("wrong value, %s\n", opt_str);
26900 + case Opt_wbr_copyup:
26901 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26902 + if (opt->wbr_copyup >= 0) {
26904 + opt->type = token;
26906 + pr_err("wrong value, %s\n", opt_str);
26909 + case Opt_fhsm_sec:
26910 + if (unlikely(match_int(&a->args[0], &n)
26912 + pr_err("bad integer in %s\n", opt_str);
26915 + if (sysaufs_brs) {
26916 + opt->fhsm_second = n;
26917 + opt->type = token;
26919 + pr_warn("ignored %s\n", opt_str);
26924 + pr_warn("ignored %s\n", opt_str);
26926 + case Opt_ignore_silent:
26931 + pr_err("unknown option %s\n", opt_str);
26935 + if (!err && !skipped) {
26936 + if (unlikely(++opt > opt_tail)) {
26939 + opt->type = Opt_tail;
26942 + opt->type = Opt_tail;
26948 + if (unlikely(err))
26949 + au_opts_free(opts);
26955 +static int au_opt_wbr_create(struct super_block *sb,
26956 + struct au_opt_wbr_create *create)
26959 + struct au_sbinfo *sbinfo;
26961 + SiMustWriteLock(sb);
26963 + err = 1; /* handled */
26964 + sbinfo = au_sbi(sb);
26965 + if (sbinfo->si_wbr_create_ops->fin) {
26966 + err = sbinfo->si_wbr_create_ops->fin(sb);
26971 + sbinfo->si_wbr_create = create->wbr_create;
26972 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26973 + switch (create->wbr_create) {
26974 + case AuWbrCreate_MFSRRV:
26975 + case AuWbrCreate_MFSRR:
26976 + case AuWbrCreate_TDMFS:
26977 + case AuWbrCreate_TDMFSV:
26978 + case AuWbrCreate_PMFSRR:
26979 + case AuWbrCreate_PMFSRRV:
26980 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26982 + case AuWbrCreate_MFS:
26983 + case AuWbrCreate_MFSV:
26984 + case AuWbrCreate_PMFS:
26985 + case AuWbrCreate_PMFSV:
26986 + sbinfo->si_wbr_mfs.mfs_expire
26987 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26991 + if (sbinfo->si_wbr_create_ops->init)
26992 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26999 + * plus: processed without an error
27000 + * zero: unprocessed
27002 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27003 + struct au_opts *opts)
27006 + struct au_sbinfo *sbinfo;
27008 + SiMustWriteLock(sb);
27010 + err = 1; /* handled */
27011 + sbinfo = au_sbi(sb);
27012 + switch (opt->type) {
27014 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27015 + sbinfo->si_mntflags |= opt->udba;
27016 + opts->given_udba |= opt->udba;
27020 + au_opt_set(sbinfo->si_mntflags, PLINK);
27022 + case Opt_noplink:
27023 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27024 + au_plink_put(sb, /*verbose*/1);
27025 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27027 + case Opt_list_plink:
27028 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27029 + au_plink_list(sb);
27033 + au_opt_set(sbinfo->si_mntflags, DIO);
27034 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27037 + au_opt_clr(sbinfo->si_mntflags, DIO);
27038 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27041 + case Opt_fhsm_sec:
27042 + au_fhsm_set(sbinfo, opt->fhsm_second);
27045 + case Opt_diropq_a:
27046 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27048 + case Opt_diropq_w:
27049 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27052 + case Opt_warn_perm:
27053 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27055 + case Opt_nowarn_perm:
27056 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27059 + case Opt_verbose:
27060 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27062 + case Opt_noverbose:
27063 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27067 + au_opt_set(sbinfo->si_mntflags, SUM);
27070 + au_opt_clr(sbinfo->si_mntflags, SUM);
27071 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27074 + au_opt_clr(sbinfo->si_mntflags, SUM);
27075 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27078 + case Opt_wbr_create:
27079 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27081 + case Opt_wbr_copyup:
27082 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27083 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27087 + sbinfo->si_dirwh = opt->dirwh;
27090 + case Opt_rdcache:
27091 + sbinfo->si_rdcache
27092 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27095 + sbinfo->si_rdblk = opt->rdblk;
27097 + case Opt_rdblk_def:
27098 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27101 + sbinfo->si_rdhash = opt->rdhash;
27103 + case Opt_rdhash_def:
27104 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27108 + au_opt_set(sbinfo->si_mntflags, SHWH);
27111 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27114 + case Opt_dirperm1:
27115 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27117 + case Opt_nodirperm1:
27118 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27121 + case Opt_trunc_xino:
27122 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27124 + case Opt_notrunc_xino:
27125 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27128 + case Opt_trunc_xino_path:
27129 + case Opt_itrunc_xino:
27130 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27136 + case Opt_trunc_xib:
27137 + au_fset_opts(opts->flags, TRUNC_XIB);
27139 + case Opt_notrunc_xib:
27140 + au_fclr_opts(opts->flags, TRUNC_XIB);
27145 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27146 + err = au_dr_opt_set(sb);
27151 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27153 + case Opt_nodirren:
27155 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27156 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27162 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27166 + sb->s_flags |= SB_POSIXACL;
27169 + sb->s_flags &= ~SB_POSIXACL;
27181 + * returns tri-state.
27182 + * plus: processed without an error
27183 + * zero: unprocessed
27186 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27187 + struct au_opts *opts)
27189 + int err, do_refresh;
27192 + switch (opt->type) {
27194 + opt->add.bindex = au_sbbot(sb) + 1;
27195 + if (opt->add.bindex < 0)
27196 + opt->add.bindex = 0;
27198 + /* Always goto add, not fallthrough */
27199 + case Opt_prepend:
27200 + opt->add.bindex = 0;
27201 + /* fallthrough */
27202 + add: /* indented label */
27204 + err = au_br_add(sb, &opt->add,
27205 + au_ftest_opts(opts->flags, REMOUNT));
27208 + au_fset_opts(opts->flags, REFRESH);
27214 + err = au_br_del(sb, &opt->del,
27215 + au_ftest_opts(opts->flags, REMOUNT));
27218 + au_fset_opts(opts->flags, TRUNC_XIB);
27219 + au_fset_opts(opts->flags, REFRESH);
27225 + err = au_br_mod(sb, &opt->mod,
27226 + au_ftest_opts(opts->flags, REMOUNT),
27231 + au_fset_opts(opts->flags, REFRESH);
27238 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27239 + struct au_opt_xino **opt_xino,
27240 + struct au_opts *opts)
27245 + switch (opt->type) {
27247 + err = au_xino_set(sb, &opt->xino,
27248 + !!au_ftest_opts(opts->flags, REMOUNT));
27249 + if (unlikely(err))
27252 + *opt_xino = &opt->xino;
27257 + *opt_xino = (void *)-1;
27264 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27265 + unsigned int pending)
27268 + aufs_bindex_t bindex, bbot;
27269 + unsigned char do_plink, skip, do_free, can_no_dreval;
27270 + struct au_branch *br;
27271 + struct au_wbr *wbr;
27272 + struct dentry *root, *dentry;
27273 + struct inode *dir, *h_dir;
27274 + struct au_sbinfo *sbinfo;
27275 + struct au_hinode *hdir;
27277 + SiMustAnyLock(sb);
27279 + sbinfo = au_sbi(sb);
27280 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27282 + if (!(sb_flags & SB_RDONLY)) {
27283 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27284 + pr_warn("first branch should be rw\n");
27285 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27286 + pr_warn_once("shwh should be used with ro\n");
27289 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27290 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27291 + pr_warn_once("udba=*notify requires xino\n");
27293 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27294 + pr_warn_once("dirperm1 breaks the protection"
27295 + " by the permission bits on the lower branch\n");
27299 + root = sb->s_root;
27300 + dir = d_inode(root);
27301 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27302 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27304 + bbot = au_sbbot(sb);
27305 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27307 + h_dir = au_h_iptr(dir, bindex);
27308 + br = au_sbr(sb, bindex);
27310 + if ((br->br_perm & AuBrAttr_ICEX)
27311 + && !h_dir->i_op->listxattr)
27312 + br->br_perm &= ~AuBrAttr_ICEX;
27313 +#if 0 /* untested */
27314 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27315 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27316 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27320 + wbr = br->br_wbr;
27322 + wbr_wh_read_lock(wbr);
27324 + if (!au_br_writable(br->br_perm)) {
27327 + || (!wbr->wbr_whbase
27328 + && !wbr->wbr_plink
27329 + && !wbr->wbr_orph));
27330 + } else if (!au_br_wh_linkable(br->br_perm)) {
27331 + /* skip = (!br->br_whbase && !br->br_orph); */
27332 + skip = (!wbr || !wbr->wbr_whbase);
27333 + if (skip && wbr) {
27335 + skip = !!wbr->wbr_plink;
27337 + skip = !wbr->wbr_plink;
27340 + /* skip = (br->br_whbase && br->br_ohph); */
27341 + skip = (wbr && wbr->wbr_whbase);
27344 + skip = !!wbr->wbr_plink;
27346 + skip = !wbr->wbr_plink;
27350 + wbr_wh_read_unlock(wbr);
27352 + if (can_no_dreval) {
27353 + dentry = br->br_path.dentry;
27354 + spin_lock(&dentry->d_lock);
27355 + if (dentry->d_flags &
27356 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27357 + can_no_dreval = 0;
27358 + spin_unlock(&dentry->d_lock);
27361 + if (au_br_fhsm(br->br_perm)) {
27363 + AuDebugOn(!br->br_fhsm);
27369 + hdir = au_hi(dir, bindex);
27370 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27372 + wbr_wh_write_lock(wbr);
27373 + err = au_wh_init(br, sb);
27375 + wbr_wh_write_unlock(wbr);
27376 + au_hn_inode_unlock(hdir);
27378 + if (!err && do_free) {
27379 + au_kfree_rcu(wbr);
27380 + br->br_wbr = NULL;
27384 + if (can_no_dreval)
27385 + au_fset_si(sbinfo, NO_DREVAL);
27387 + au_fclr_si(sbinfo, NO_DREVAL);
27390 + au_fset_si(sbinfo, FHSM);
27391 + for (bindex = bbot; bindex >= 0; bindex--) {
27392 + br = au_sbr(sb, bindex);
27393 + if (au_br_fhsm(br->br_perm)) {
27394 + au_fhsm_set_bottom(sb, bindex);
27399 + au_fclr_si(sbinfo, FHSM);
27400 + au_fhsm_set_bottom(sb, -1);
27406 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27409 + unsigned int tmp;
27410 + aufs_bindex_t bindex, bbot;
27411 + struct au_opt *opt;
27412 + struct au_opt_xino *opt_xino, xino;
27413 + struct au_sbinfo *sbinfo;
27414 + struct au_branch *br;
27415 + struct inode *dir;
27417 + SiMustWriteLock(sb);
27422 + while (err >= 0 && opt->type != Opt_tail)
27423 + err = au_opt_simple(sb, opt++, opts);
27426 + else if (unlikely(err < 0))
27429 + /* disable xino and udba temporary */
27430 + sbinfo = au_sbi(sb);
27431 + tmp = sbinfo->si_mntflags;
27432 + au_opt_clr(sbinfo->si_mntflags, XINO);
27433 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27436 + while (err >= 0 && opt->type != Opt_tail)
27437 + err = au_opt_br(sb, opt++, opts);
27440 + else if (unlikely(err < 0))
27443 + bbot = au_sbbot(sb);
27444 + if (unlikely(bbot < 0)) {
27446 + pr_err("no branches\n");
27450 + if (au_opt_test(tmp, XINO))
27451 + au_opt_set(sbinfo->si_mntflags, XINO);
27453 + while (!err && opt->type != Opt_tail)
27454 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27455 + if (unlikely(err))
27458 + err = au_opts_verify(sb, sb->s_flags, tmp);
27459 + if (unlikely(err))
27462 + /* restore xino */
27463 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27464 + xino.file = au_xino_def(sb);
27465 + err = PTR_ERR(xino.file);
27466 + if (IS_ERR(xino.file))
27469 + err = au_xino_set(sb, &xino, /*remount*/0);
27471 + if (unlikely(err))
27475 + /* restore udba */
27476 + tmp &= AuOptMask_UDBA;
27477 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27478 + sbinfo->si_mntflags |= tmp;
27479 + bbot = au_sbbot(sb);
27480 + for (bindex = 0; bindex <= bbot; bindex++) {
27481 + br = au_sbr(sb, bindex);
27482 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27483 + if (unlikely(err))
27484 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27486 + /* go on even if err */
27488 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27489 + dir = d_inode(sb->s_root);
27490 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27497 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27500 + unsigned char no_dreval;
27501 + struct inode *dir;
27502 + struct au_opt_xino *opt_xino;
27503 + struct au_opt *opt;
27504 + struct au_sbinfo *sbinfo;
27506 + SiMustWriteLock(sb);
27508 + err = au_dr_opt_flush(sb);
27509 + if (unlikely(err))
27511 + au_fset_opts(opts->flags, DR_FLUSHED);
27513 + dir = d_inode(sb->s_root);
27514 + sbinfo = au_sbi(sb);
27517 + while (err >= 0 && opt->type != Opt_tail) {
27518 + err = au_opt_simple(sb, opt, opts);
27520 + err = au_opt_br(sb, opt, opts);
27522 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27528 + /* go on even err */
27530 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27531 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27532 + if (unlikely(rerr && !err))
27535 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27536 + au_fset_opts(opts->flags, REFRESH_IDOP);
27538 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27539 + rerr = au_xib_trunc(sb);
27540 + if (unlikely(rerr && !err))
27544 + /* will be handled by the caller */
27545 + if (!au_ftest_opts(opts->flags, REFRESH)
27546 + && (opts->given_udba
27547 + || au_opt_test(sbinfo->si_mntflags, XINO)
27548 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27550 + au_fset_opts(opts->flags, REFRESH);
27552 + AuDbg("status 0x%x\n", opts->flags);
27558 +/* ---------------------------------------------------------------------- */
27560 +unsigned int au_opt_udba(struct super_block *sb)
27562 + return au_mntflags(sb) & AuOptMask_UDBA;
27564 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27565 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27566 +++ linux/fs/aufs/opts.h 2020-01-27 10:57:18.175538316 +0100
27568 +/* SPDX-License-Identifier: GPL-2.0 */
27570 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27572 + * This program, aufs is free software; you can redistribute it and/or modify
27573 + * it under the terms of the GNU General Public License as published by
27574 + * the Free Software Foundation; either version 2 of the License, or
27575 + * (at your option) any later version.
27577 + * This program is distributed in the hope that it will be useful,
27578 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27579 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27580 + * GNU General Public License for more details.
27582 + * You should have received a copy of the GNU General Public License
27583 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27587 + * mount options/flags
27590 +#ifndef __AUFS_OPTS_H__
27591 +#define __AUFS_OPTS_H__
27595 +#include <linux/path.h>
27599 +/* ---------------------------------------------------------------------- */
27602 +#define AuOpt_XINO 1 /* external inode number bitmap
27603 + and translation table */
27604 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27605 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27606 +#define AuOpt_UDBA_REVAL (1 << 3)
27607 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27608 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27609 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27610 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27612 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27613 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27614 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27615 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27616 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27617 +#define AuOpt_DIO (1 << 14) /* direct io */
27618 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27620 +#ifndef CONFIG_AUFS_HNOTIFY
27621 +#undef AuOpt_UDBA_HNOTIFY
27622 +#define AuOpt_UDBA_HNOTIFY 0
27624 +#ifndef CONFIG_AUFS_DIRREN
27625 +#undef AuOpt_DIRREN
27626 +#define AuOpt_DIRREN 0
27628 +#ifndef CONFIG_AUFS_SHWH
27630 +#define AuOpt_SHWH 0
27633 +#define AuOpt_Def (AuOpt_XINO \
27634 + | AuOpt_UDBA_REVAL \
27636 + /* | AuOpt_DIRPERM1 */ \
27637 + | AuOpt_WARN_PERM)
27638 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27639 + | AuOpt_UDBA_REVAL \
27640 + | AuOpt_UDBA_HNOTIFY)
27642 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27643 +#define au_opt_set(flags, name) do { \
27644 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27645 + ((flags) |= AuOpt_##name); \
27647 +#define au_opt_set_udba(flags, name) do { \
27648 + (flags) &= ~AuOptMask_UDBA; \
27649 + ((flags) |= AuOpt_##name); \
27651 +#define au_opt_clr(flags, name) do { \
27652 + ((flags) &= ~AuOpt_##name); \
27655 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27657 +#ifdef CONFIG_PROC_FS
27660 + return mntflags & ~AuOpt_PLINK;
27664 +/* ---------------------------------------------------------------------- */
27666 +/* policies to select one among multiple writable branches */
27668 + AuWbrCreate_TDP, /* top down parent */
27669 + AuWbrCreate_RR, /* round robin */
27670 + AuWbrCreate_MFS, /* most free space */
27671 + AuWbrCreate_MFSV, /* mfs with seconds */
27672 + AuWbrCreate_MFSRR, /* mfs then rr */
27673 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27674 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27675 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27676 + AuWbrCreate_PMFS, /* parent and mfs */
27677 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27678 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27679 + AuWbrCreate_PMFSRRV, /* plus seconds */
27681 + AuWbrCreate_Def = AuWbrCreate_TDP
27685 + AuWbrCopyup_TDP, /* top down parent */
27686 + AuWbrCopyup_BUP, /* bottom up parent */
27687 + AuWbrCopyup_BU, /* bottom up */
27689 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27692 +/* ---------------------------------------------------------------------- */
27694 +struct au_opt_add {
27695 + aufs_bindex_t bindex;
27698 + struct path path;
27701 +struct au_opt_del {
27703 + struct path h_path;
27706 +struct au_opt_mod {
27709 + struct dentry *h_root;
27712 +struct au_opt_xino {
27714 + struct file *file;
27717 +struct au_opt_xino_itrunc {
27718 + aufs_bindex_t bindex;
27721 +struct au_opt_wbr_create {
27724 + unsigned long long mfsrr_watermark;
27730 + struct au_opt_xino xino;
27731 + struct au_opt_xino_itrunc xino_itrunc;
27732 + struct au_opt_add add;
27733 + struct au_opt_del del;
27734 + struct au_opt_mod mod;
27737 + unsigned int rdblk;
27738 + unsigned int rdhash;
27740 + struct au_opt_wbr_create wbr_create;
27742 + unsigned int fhsm_second;
27747 +#define AuOpts_REMOUNT 1
27748 +#define AuOpts_REFRESH (1 << 1)
27749 +#define AuOpts_TRUNC_XIB (1 << 2)
27750 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27751 +#define AuOpts_REFRESH_IDOP (1 << 4)
27752 +#define AuOpts_DR_FLUSHED (1 << 5)
27753 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27754 +#define au_fset_opts(flags, name) \
27755 + do { (flags) |= AuOpts_##name; } while (0)
27756 +#define au_fclr_opts(flags, name) \
27757 + do { (flags) &= ~AuOpts_##name; } while (0)
27759 +#ifndef CONFIG_AUFS_DIRREN
27760 +#undef AuOpts_DR_FLUSHED
27761 +#define AuOpts_DR_FLUSHED 0
27765 + struct au_opt *opt;
27768 + unsigned int given_udba;
27769 + unsigned int flags;
27770 + unsigned long sb_flags;
27773 +/* ---------------------------------------------------------------------- */
27776 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27777 +const char *au_optstr_udba(int udba);
27778 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27779 +const char *au_optstr_wbr_create(int wbr_create);
27781 +void au_opts_free(struct au_opts *opts);
27782 +struct super_block;
27783 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27784 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27785 + unsigned int pending);
27786 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27787 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27789 +unsigned int au_opt_udba(struct super_block *sb);
27791 +#endif /* __KERNEL__ */
27792 +#endif /* __AUFS_OPTS_H__ */
27793 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27794 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27795 +++ linux/fs/aufs/plink.c 2020-01-27 10:57:18.175538316 +0100
27797 +// SPDX-License-Identifier: GPL-2.0
27799 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27801 + * This program, aufs is free software; you can redistribute it and/or modify
27802 + * it under the terms of the GNU General Public License as published by
27803 + * the Free Software Foundation; either version 2 of the License, or
27804 + * (at your option) any later version.
27806 + * This program is distributed in the hope that it will be useful,
27807 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27808 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27809 + * GNU General Public License for more details.
27811 + * You should have received a copy of the GNU General Public License
27812 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27822 + * the pseudo-link maintenance mode.
27823 + * during a user process maintains the pseudo-links,
27824 + * prohibit adding a new plink and branch manipulation.
27828 + * For entry functions which will handle plink, and i_mutex is already held
27830 + * They cannot wait and should return an error at once.
27831 + * Callers has to check the error.
27833 + * For entry functions which will handle plink, but i_mutex is not held
27835 + * They can wait the plink maintenance mode to finish.
27837 + * They behave like F_SETLK and F_SETLKW.
27838 + * If the caller never handle plink, then both flags are unnecessary.
27841 +int au_plink_maint(struct super_block *sb, int flags)
27845 + struct task_struct *parent, *prev;
27846 + struct au_sbinfo *sbi;
27848 + SiMustAnyLock(sb);
27851 + if (!au_opt_test(au_mntflags(sb), PLINK))
27854 + sbi = au_sbi(sb);
27855 + pid = sbi->si_plink_maint_pid;
27856 + if (!pid || pid == current->pid)
27859 + /* todo: it highly depends upon /sbin/mount.aufs */
27861 + parent = current;
27865 + parent = rcu_dereference(parent->real_parent);
27866 + if (parent == prev)
27868 + ppid = task_pid_vnr(parent);
27869 + if (pid == ppid) {
27870 + rcu_read_unlock();
27875 + rcu_read_unlock();
27877 + if (au_ftest_lock(flags, NOPLMW)) {
27878 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27879 + /* AuDebugOn(!lockdep_depth(current)); */
27880 + while (sbi->si_plink_maint_pid) {
27881 + si_read_unlock(sb);
27882 + /* gave up wake_up_bit() */
27883 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27885 + if (au_ftest_lock(flags, FLUSH))
27886 + au_nwt_flush(&sbi->si_nowait);
27887 + si_noflush_read_lock(sb);
27889 + } else if (au_ftest_lock(flags, NOPLM)) {
27890 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27898 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27900 + spin_lock(&sbinfo->si_plink_maint_lock);
27901 + sbinfo->si_plink_maint_pid = 0;
27902 + spin_unlock(&sbinfo->si_plink_maint_lock);
27903 + wake_up_all(&sbinfo->si_plink_wq);
27906 +int au_plink_maint_enter(struct super_block *sb)
27909 + struct au_sbinfo *sbinfo;
27912 + sbinfo = au_sbi(sb);
27913 + /* make sure i am the only one in this fs */
27914 + si_write_lock(sb, AuLock_FLUSH);
27915 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27916 + spin_lock(&sbinfo->si_plink_maint_lock);
27917 + if (!sbinfo->si_plink_maint_pid)
27918 + sbinfo->si_plink_maint_pid = current->pid;
27921 + spin_unlock(&sbinfo->si_plink_maint_lock);
27923 + si_write_unlock(sb);
27928 +/* ---------------------------------------------------------------------- */
27930 +#ifdef CONFIG_AUFS_DEBUG
27931 +void au_plink_list(struct super_block *sb)
27934 + struct au_sbinfo *sbinfo;
27935 + struct hlist_bl_head *hbl;
27936 + struct hlist_bl_node *pos;
27937 + struct au_icntnr *icntnr;
27939 + SiMustAnyLock(sb);
27941 + sbinfo = au_sbi(sb);
27942 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27943 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27945 + for (i = 0; i < AuPlink_NHASH; i++) {
27946 + hbl = sbinfo->si_plink + i;
27947 + hlist_bl_lock(hbl);
27948 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27949 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27950 + hlist_bl_unlock(hbl);
27955 +/* is the inode pseudo-linked? */
27956 +int au_plink_test(struct inode *inode)
27959 + struct au_sbinfo *sbinfo;
27960 + struct hlist_bl_head *hbl;
27961 + struct hlist_bl_node *pos;
27962 + struct au_icntnr *icntnr;
27964 + sbinfo = au_sbi(inode->i_sb);
27965 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27966 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27967 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27970 + i = au_plink_hash(inode->i_ino);
27971 + hbl = sbinfo->si_plink + i;
27972 + hlist_bl_lock(hbl);
27973 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27974 + if (&icntnr->vfs_inode == inode) {
27978 + hlist_bl_unlock(hbl);
27982 +/* ---------------------------------------------------------------------- */
27985 + * generate a name for plink.
27986 + * the file will be stored under AUFS_WH_PLINKDIR.
27988 +/* 20 is max digits length of ulong 64 */
27989 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27991 +static int plink_name(char *name, int len, struct inode *inode,
27992 + aufs_bindex_t bindex)
27995 + struct inode *h_inode;
27997 + h_inode = au_h_iptr(inode, bindex);
27998 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28002 +struct au_do_plink_lkup_args {
28003 + struct dentry **errp;
28004 + struct qstr *tgtname;
28005 + struct dentry *h_parent;
28006 + struct au_branch *br;
28009 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28010 + struct dentry *h_parent,
28011 + struct au_branch *br)
28013 + struct dentry *h_dentry;
28014 + struct inode *h_inode;
28016 + h_inode = d_inode(h_parent);
28017 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28018 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28019 + inode_unlock_shared(h_inode);
28023 +static void au_call_do_plink_lkup(void *args)
28025 + struct au_do_plink_lkup_args *a = args;
28026 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28029 +/* lookup the plink-ed @inode under the branch at @bindex */
28030 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28032 + struct dentry *h_dentry, *h_parent;
28033 + struct au_branch *br;
28035 + char a[PLINK_NAME_LEN];
28036 + struct qstr tgtname = QSTR_INIT(a, 0);
28038 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28040 + br = au_sbr(inode->i_sb, bindex);
28041 + h_parent = br->br_wbr->wbr_plink;
28042 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28044 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28045 + struct au_do_plink_lkup_args args = {
28046 + .errp = &h_dentry,
28047 + .tgtname = &tgtname,
28048 + .h_parent = h_parent,
28052 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28053 + if (unlikely(wkq_err))
28054 + h_dentry = ERR_PTR(wkq_err);
28056 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28061 +/* create a pseudo-link */
28062 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28063 + struct dentry *h_dentry, struct au_branch *br)
28066 + struct path h_path = {
28067 + .mnt = au_br_mnt(br)
28069 + struct inode *h_dir, *delegated;
28071 + h_dir = d_inode(h_parent);
28072 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28074 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28075 + err = PTR_ERR(h_path.dentry);
28076 + if (IS_ERR(h_path.dentry))
28080 + /* wh.plink dir is not monitored */
28081 + /* todo: is it really safe? */
28082 + if (d_is_positive(h_path.dentry)
28083 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28084 + delegated = NULL;
28085 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28086 + if (unlikely(err == -EWOULDBLOCK)) {
28087 + pr_warn("cannot retry for NFSv4 delegation"
28088 + " for an internal unlink\n");
28091 + dput(h_path.dentry);
28092 + h_path.dentry = NULL;
28096 + if (!err && d_is_negative(h_path.dentry)) {
28097 + delegated = NULL;
28098 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28099 + if (unlikely(err == -EWOULDBLOCK)) {
28100 + pr_warn("cannot retry for NFSv4 delegation"
28101 + " for an internal link\n");
28105 + dput(h_path.dentry);
28108 + inode_unlock(h_dir);
28112 +struct do_whplink_args {
28114 + struct qstr *tgt;
28115 + struct dentry *h_parent;
28116 + struct dentry *h_dentry;
28117 + struct au_branch *br;
28120 +static void call_do_whplink(void *args)
28122 + struct do_whplink_args *a = args;
28123 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28126 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28127 + aufs_bindex_t bindex, struct au_branch *br)
28129 + int err, wkq_err;
28130 + struct au_wbr *wbr;
28131 + struct dentry *h_parent;
28132 + char a[PLINK_NAME_LEN];
28133 + struct qstr tgtname = QSTR_INIT(a, 0);
28135 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28136 + h_parent = wbr->wbr_plink;
28137 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28139 + /* always superio. */
28140 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28141 + struct do_whplink_args args = {
28144 + .h_parent = h_parent,
28145 + .h_dentry = h_dentry,
28148 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28149 + if (unlikely(wkq_err))
28152 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28158 + * create a new pseudo-link for @h_dentry on @bindex.
28159 + * the linked inode is held in aufs @inode.
28161 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28162 + struct dentry *h_dentry)
28164 + struct super_block *sb;
28165 + struct au_sbinfo *sbinfo;
28166 + struct hlist_bl_head *hbl;
28167 + struct hlist_bl_node *pos;
28168 + struct au_icntnr *icntnr;
28169 + int found, err, cnt, i;
28171 + sb = inode->i_sb;
28172 + sbinfo = au_sbi(sb);
28173 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28174 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28176 + found = au_plink_test(inode);
28180 + i = au_plink_hash(inode->i_ino);
28181 + hbl = sbinfo->si_plink + i;
28184 + hlist_bl_lock(hbl);
28185 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28186 + if (&icntnr->vfs_inode == inode) {
28192 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28193 + hlist_bl_add_head(&icntnr->plink, hbl);
28195 + hlist_bl_unlock(hbl);
28197 + cnt = au_hbl_count(hbl);
28198 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28199 + if (cnt > AUFS_PLINK_WARN)
28200 + AuWarn1(msg ", %d\n", cnt);
28202 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28203 + if (unlikely(err)) {
28204 + pr_warn("err %d, damaged pseudo link.\n", err);
28205 + au_hbl_del(&icntnr->plink, hbl);
28206 + iput(&icntnr->vfs_inode);
28209 + iput(&icntnr->vfs_inode);
28212 +/* free all plinks */
28213 +void au_plink_put(struct super_block *sb, int verbose)
28216 + struct au_sbinfo *sbinfo;
28217 + struct hlist_bl_head *hbl;
28218 + struct hlist_bl_node *pos, *tmp;
28219 + struct au_icntnr *icntnr;
28221 + SiMustWriteLock(sb);
28223 + sbinfo = au_sbi(sb);
28224 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28225 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28227 + /* no spin_lock since sbinfo is write-locked */
28229 + for (i = 0; i < AuPlink_NHASH; i++) {
28230 + hbl = sbinfo->si_plink + i;
28231 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28232 + pr_warn("pseudo-link is not flushed");
28235 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28236 + iput(&icntnr->vfs_inode);
28237 + INIT_HLIST_BL_HEAD(hbl);
28241 +void au_plink_clean(struct super_block *sb, int verbose)
28243 + struct dentry *root;
28245 + root = sb->s_root;
28246 + aufs_write_lock(root);
28247 + if (au_opt_test(au_mntflags(sb), PLINK))
28248 + au_plink_put(sb, verbose);
28249 + aufs_write_unlock(root);
28252 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28255 + aufs_bindex_t btop, bbot, bindex;
28258 + btop = au_ibtop(inode);
28259 + bbot = au_ibbot(inode);
28261 + for (bindex = btop; bindex <= bbot; bindex++) {
28262 + if (!au_h_iptr(inode, bindex)
28263 + || au_ii_br_id(inode, bindex) != br_id)
28265 + au_set_h_iptr(inode, bindex, NULL, 0);
28270 + for (bindex = btop; bindex <= bbot; bindex++)
28271 + if (au_h_iptr(inode, bindex)) {
28281 +/* free the plinks on a branch specified by @br_id */
28282 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28284 + struct au_sbinfo *sbinfo;
28285 + struct hlist_bl_head *hbl;
28286 + struct hlist_bl_node *pos, *tmp;
28287 + struct au_icntnr *icntnr;
28288 + struct inode *inode;
28291 + SiMustWriteLock(sb);
28293 + sbinfo = au_sbi(sb);
28294 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28295 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28297 + /* no bit_lock since sbinfo is write-locked */
28298 + for (i = 0; i < AuPlink_NHASH; i++) {
28299 + hbl = sbinfo->si_plink + i;
28300 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28301 + inode = au_igrab(&icntnr->vfs_inode);
28302 + ii_write_lock_child(inode);
28303 + do_put = au_plink_do_half_refresh(inode, br_id);
28305 + hlist_bl_del(&icntnr->plink);
28308 + ii_write_unlock(inode);
28313 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28314 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28315 +++ linux/fs/aufs/poll.c 2020-01-27 10:57:18.175538316 +0100
28317 +// SPDX-License-Identifier: GPL-2.0
28319 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28321 + * This program, aufs is free software; you can redistribute it and/or modify
28322 + * it under the terms of the GNU General Public License as published by
28323 + * the Free Software Foundation; either version 2 of the License, or
28324 + * (at your option) any later version.
28326 + * This program is distributed in the hope that it will be useful,
28327 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28329 + * GNU General Public License for more details.
28331 + * You should have received a copy of the GNU General Public License
28332 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28337 + * There is only one filesystem which implements ->poll operation, currently.
28342 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28345 + struct file *h_file;
28346 + struct super_block *sb;
28348 + /* We should pretend an error happened. */
28349 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28350 + sb = file->f_path.dentry->d_sb;
28351 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28353 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28354 + if (IS_ERR(h_file)) {
28355 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28359 + mask = vfs_poll(h_file, pt);
28360 + fput(h_file); /* instead of au_read_post() */
28363 + si_read_unlock(sb);
28364 + if (mask & EPOLLERR)
28365 + AuDbg("mask 0x%x\n", mask);
28368 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28369 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28370 +++ linux/fs/aufs/posix_acl.c 2020-01-27 10:57:18.175538316 +0100
28372 +// SPDX-License-Identifier: GPL-2.0
28374 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28376 + * This program, aufs is free software; you can redistribute it and/or modify
28377 + * it under the terms of the GNU General Public License as published by
28378 + * the Free Software Foundation; either version 2 of the License, or
28379 + * (at your option) any later version.
28381 + * This program is distributed in the hope that it will be useful,
28382 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28383 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28384 + * GNU General Public License for more details.
28386 + * You should have received a copy of the GNU General Public License
28387 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28391 + * posix acl operations
28394 +#include <linux/fs.h>
28397 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28399 + struct posix_acl *acl;
28401 + aufs_bindex_t bindex;
28402 + struct inode *h_inode;
28403 + struct super_block *sb;
28406 + sb = inode->i_sb;
28407 + si_read_lock(sb, AuLock_FLUSH);
28408 + ii_read_lock_child(inode);
28409 + if (!(sb->s_flags & SB_POSIXACL))
28412 + bindex = au_ibtop(inode);
28413 + h_inode = au_h_iptr(inode, bindex);
28414 + if (unlikely(!h_inode
28415 + || ((h_inode->i_mode & S_IFMT)
28416 + != (inode->i_mode & S_IFMT)))) {
28417 + err = au_busy_or_stale();
28418 + acl = ERR_PTR(err);
28422 + /* always topmost only */
28423 + acl = get_acl(h_inode, type);
28425 + forget_cached_acl(inode, type);
28427 + set_cached_acl(inode, type, acl);
28430 + ii_read_unlock(inode);
28431 + si_read_unlock(sb);
28433 + AuTraceErrPtr(acl);
28437 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28441 + struct dentry *dentry;
28442 + struct au_sxattr arg = {
28443 + .type = AU_ACL_SET,
28450 + IMustLock(inode);
28452 + if (inode->i_ino == AUFS_ROOT_INO)
28453 + dentry = dget(inode->i_sb->s_root);
28455 + dentry = d_find_alias(inode);
28457 + dentry = d_find_any_alias(inode);
28459 + pr_warn("cannot handle this inode, "
28460 + "please report to aufs-users ML\n");
28466 + ssz = au_sxattr(dentry, inode, &arg);
28467 + /* forget even it if succeeds since the branch might set differently */
28468 + forget_cached_acl(inode, type);
28477 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28478 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28479 +++ linux/fs/aufs/procfs.c 2020-04-03 08:16:47.547461775 +0200
28481 +// SPDX-License-Identifier: GPL-2.0
28483 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28485 + * This program, aufs is free software; you can redistribute it and/or modify
28486 + * it under the terms of the GNU General Public License as published by
28487 + * the Free Software Foundation; either version 2 of the License, or
28488 + * (at your option) any later version.
28490 + * This program is distributed in the hope that it will be useful,
28491 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28492 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28493 + * GNU General Public License for more details.
28495 + * You should have received a copy of the GNU General Public License
28496 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28500 + * procfs interfaces
28503 +#include <linux/proc_fs.h>
28506 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28508 + struct au_sbinfo *sbinfo;
28510 + sbinfo = file->private_data;
28512 + au_plink_maint_leave(sbinfo);
28513 + kobject_put(&sbinfo->si_kobj);
28519 +static void au_procfs_plm_write_clean(struct file *file)
28521 + struct au_sbinfo *sbinfo;
28523 + sbinfo = file->private_data;
28525 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28528 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28531 + struct super_block *sb;
28532 + struct au_sbinfo *sbinfo;
28533 + struct hlist_bl_node *pos;
28536 + if (unlikely(file->private_data))
28540 + /* don't use au_sbilist_lock() here */
28541 + hlist_bl_lock(&au_sbilist);
28542 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28543 + if (id == sysaufs_si_id(sbinfo)) {
28544 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28545 + sb = sbinfo->si_sb;
28548 + hlist_bl_unlock(&au_sbilist);
28551 + if (unlikely(!sb))
28554 + err = au_plink_maint_enter(sb);
28556 + /* keep kobject_get() */
28557 + file->private_data = sbinfo;
28559 + kobject_put(&sbinfo->si_kobj);
28565 + * Accept a valid "si=xxxx" only.
28566 + * Once it is accepted successfully, accept "clean" too.
28568 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28569 + size_t count, loff_t *ppos)
28572 + unsigned long id;
28573 + /* last newline is allowed */
28574 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28577 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28581 + if (unlikely(count > sizeof(buf)))
28584 + err = copy_from_user(buf, ubuf, count);
28585 + if (unlikely(err)) {
28592 + if (!strcmp("clean", buf)) {
28593 + au_procfs_plm_write_clean(file);
28594 + goto out_success;
28595 + } else if (unlikely(strncmp("si=", buf, 3)))
28598 + err = kstrtoul(buf + 3, 16, &id);
28599 + if (unlikely(err))
28602 + err = au_procfs_plm_write_si(file, id);
28603 + if (unlikely(err))
28607 + err = count; /* success */
28612 +static const struct file_operations au_procfs_plm_fop = {
28613 + .write = au_procfs_plm_write,
28614 + .release = au_procfs_plm_release,
28615 + .owner = THIS_MODULE
28618 +/* ---------------------------------------------------------------------- */
28620 +static struct proc_dir_entry *au_procfs_dir;
28622 +void au_procfs_fin(void)
28624 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28625 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28628 +int __init au_procfs_init(void)
28631 + struct proc_dir_entry *entry;
28634 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28635 + if (unlikely(!au_procfs_dir))
28638 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28639 + au_procfs_dir, &au_procfs_plm_fop);
28640 + if (unlikely(!entry))
28644 + goto out; /* success */
28648 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28652 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28653 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28654 +++ linux/fs/aufs/rdu.c 2020-01-27 10:57:18.178871751 +0100
28656 +// SPDX-License-Identifier: GPL-2.0
28658 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28660 + * This program, aufs is free software; you can redistribute it and/or modify
28661 + * it under the terms of the GNU General Public License as published by
28662 + * the Free Software Foundation; either version 2 of the License, or
28663 + * (at your option) any later version.
28665 + * This program is distributed in the hope that it will be useful,
28666 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28667 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28668 + * GNU General Public License for more details.
28670 + * You should have received a copy of the GNU General Public License
28671 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28675 + * readdir in userspace.
28678 +#include <linux/compat.h>
28679 +#include <linux/fs_stack.h>
28680 +#include <linux/security.h>
28683 +/* bits for struct aufs_rdu.flags */
28684 +#define AuRdu_CALLED 1
28685 +#define AuRdu_CONT (1 << 1)
28686 +#define AuRdu_FULL (1 << 2)
28687 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28688 +#define au_fset_rdu(flags, name) \
28689 + do { (flags) |= AuRdu_##name; } while (0)
28690 +#define au_fclr_rdu(flags, name) \
28691 + do { (flags) &= ~AuRdu_##name; } while (0)
28693 +struct au_rdu_arg {
28694 + struct dir_context ctx;
28695 + struct aufs_rdu *rdu;
28696 + union au_rdu_ent_ul ent;
28697 + unsigned long end;
28699 + struct super_block *sb;
28703 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28704 + loff_t offset, u64 h_ino, unsigned int d_type)
28707 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28708 + struct aufs_rdu *rdu = arg->rdu;
28709 + struct au_rdu_ent ent;
28713 + au_fset_rdu(rdu->cookie.flags, CALLED);
28714 + len = au_rdu_len(nlen);
28715 + if (arg->ent.ul + len < arg->end) {
28717 + ent.bindex = rdu->cookie.bindex;
28718 + ent.type = d_type;
28720 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28721 + ent.type = DT_UNKNOWN;
28723 + /* unnecessary to support mmap_sem since this is a dir */
28725 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28727 + if (copy_to_user(arg->ent.e->name, name, nlen))
28729 + /* the terminating NULL */
28730 + if (__put_user(0, arg->ent.e->name + nlen))
28733 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28734 + arg->ent.ul += len;
28738 + au_fset_rdu(rdu->cookie.flags, FULL);
28740 + rdu->tail = arg->ent;
28744 + /* AuTraceErr(err); */
28748 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28752 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28754 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28755 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28757 + if (unlikely(offset != cookie->h_pos))
28763 + au_fclr_rdu(cookie->flags, CALLED);
28765 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28769 + && au_ftest_rdu(cookie->flags, CALLED)
28770 + && !au_ftest_rdu(cookie->flags, FULL));
28771 + cookie->h_pos = h_file->f_pos;
28778 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28781 + aufs_bindex_t bbot;
28782 + struct au_rdu_arg arg = {
28784 + .actor = au_rdu_fill
28787 + struct dentry *dentry;
28788 + struct inode *inode;
28789 + struct file *h_file;
28790 + struct au_rdu_cookie *cookie = &rdu->cookie;
28792 + /* VERIFY_WRITE */
28793 + err = !access_ok(rdu->ent.e, rdu->sz);
28794 + if (unlikely(err)) {
28800 + rdu->tail = rdu->ent;
28803 + arg.ent = rdu->ent;
28804 + arg.end = arg.ent.ul;
28805 + arg.end += rdu->sz;
28808 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28811 + err = security_file_permission(file, MAY_READ);
28813 + if (unlikely(err))
28816 + dentry = file->f_path.dentry;
28817 + inode = d_inode(dentry);
28818 + inode_lock_shared(inode);
28820 + arg.sb = inode->i_sb;
28821 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28822 + if (unlikely(err))
28824 + err = au_alive_dir(dentry);
28825 + if (unlikely(err))
28827 + /* todo: reval? */
28828 + fi_read_lock(file);
28831 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28832 + && cookie->generation != au_figen(file)))
28837 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28839 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28841 + bbot = au_fbtop(file);
28842 + if (cookie->bindex < bbot)
28843 + cookie->bindex = bbot;
28844 + bbot = au_fbbot_dir(file);
28845 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28846 + for (; !err && cookie->bindex <= bbot;
28847 + cookie->bindex++, cookie->h_pos = 0) {
28848 + h_file = au_hf_dir(file, cookie->bindex);
28852 + au_fclr_rdu(cookie->flags, FULL);
28853 + err = au_rdu_do(h_file, &arg);
28855 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28858 + AuDbg("rent %llu\n", rdu->rent);
28860 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28861 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28862 + au_fset_rdu(cookie->flags, CONT);
28863 + cookie->generation = au_figen(file);
28866 + ii_read_lock_child(inode);
28867 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28868 + ii_read_unlock(inode);
28871 + fi_read_unlock(file);
28873 + si_read_unlock(arg.sb);
28875 + inode_unlock_shared(inode);
28881 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28885 + unsigned long long nent;
28886 + union au_rdu_ent_ul *u;
28887 + struct au_rdu_ent ent;
28888 + struct super_block *sb;
28891 + nent = rdu->nent;
28893 + sb = file->f_path.dentry->d_sb;
28894 + si_read_lock(sb, AuLock_FLUSH);
28895 + while (nent-- > 0) {
28896 + /* unnecessary to support mmap_sem since this is a dir */
28897 + err = copy_from_user(&ent, u->e, sizeof(ent));
28899 + /* VERIFY_WRITE */
28900 + err = !access_ok(&u->e->ino, sizeof(ino));
28901 + if (unlikely(err)) {
28907 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28909 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28911 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28913 + if (unlikely(err)) {
28918 + err = __put_user(ino, &u->e->ino);
28919 + if (unlikely(err)) {
28924 + u->ul += au_rdu_len(ent.nlen);
28926 + si_read_unlock(sb);
28931 +/* ---------------------------------------------------------------------- */
28933 +static int au_rdu_verify(struct aufs_rdu *rdu)
28935 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28936 + "%llu, b%d, 0x%x, g%u}\n",
28937 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28939 + rdu->rent, rdu->shwh, rdu->full,
28940 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28941 + rdu->cookie.generation);
28943 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28947 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28951 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28954 + struct aufs_rdu rdu;
28955 + void __user *p = (void __user *)arg;
28957 + err = copy_from_user(&rdu, p, sizeof(rdu));
28958 + if (unlikely(err)) {
28963 + err = au_rdu_verify(&rdu);
28964 + if (unlikely(err))
28968 + case AUFS_CTL_RDU:
28969 + err = au_rdu(file, &rdu);
28970 + if (unlikely(err))
28973 + e = copy_to_user(p, &rdu, sizeof(rdu));
28974 + if (unlikely(e)) {
28979 + case AUFS_CTL_RDU_INO:
28980 + err = au_rdu_ino(file, &rdu);
28984 + /* err = -ENOTTY; */
28993 +#ifdef CONFIG_COMPAT
28994 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28997 + struct aufs_rdu rdu;
28998 + void __user *p = compat_ptr(arg);
29000 + /* todo: get_user()? */
29001 + err = copy_from_user(&rdu, p, sizeof(rdu));
29002 + if (unlikely(err)) {
29007 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29008 + err = au_rdu_verify(&rdu);
29009 + if (unlikely(err))
29013 + case AUFS_CTL_RDU:
29014 + err = au_rdu(file, &rdu);
29015 + if (unlikely(err))
29018 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29019 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29020 + e = copy_to_user(p, &rdu, sizeof(rdu));
29021 + if (unlikely(e)) {
29026 + case AUFS_CTL_RDU_INO:
29027 + err = au_rdu_ino(file, &rdu);
29031 + /* err = -ENOTTY; */
29040 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29041 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29042 +++ linux/fs/aufs/rwsem.h 2020-01-27 10:57:18.178871751 +0100
29044 +/* SPDX-License-Identifier: GPL-2.0 */
29046 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29048 + * This program, aufs is free software; you can redistribute it and/or modify
29049 + * it under the terms of the GNU General Public License as published by
29050 + * the Free Software Foundation; either version 2 of the License, or
29051 + * (at your option) any later version.
29053 + * This program is distributed in the hope that it will be useful,
29054 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29055 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29056 + * GNU General Public License for more details.
29058 + * You should have received a copy of the GNU General Public License
29059 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29063 + * simple read-write semaphore wrappers
29066 +#ifndef __AUFS_RWSEM_H__
29067 +#define __AUFS_RWSEM_H__
29071 +#include "debug.h"
29073 +/* in the future, the name 'au_rwsem' will be totally gone */
29074 +#define au_rwsem rw_semaphore
29076 +/* to debug easier, do not make them inlined functions */
29077 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29078 +/* rwsem_is_locked() is unusable */
29079 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29081 + && !lockdep_is_held_type(rw, 1))
29082 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29084 + && !lockdep_is_held_type(rw, 0))
29085 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29087 + && !lockdep_is_held(rw))
29088 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29090 + && lockdep_is_held(rw))
29092 +#define au_rw_init(rw) init_rwsem(rw)
29094 +#define au_rw_init_wlock(rw) do { \
29095 + au_rw_init(rw); \
29096 + down_write(rw); \
29099 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29100 + au_rw_init(rw); \
29101 + down_write_nested(rw, lsc); \
29104 +#define au_rw_read_lock(rw) down_read(rw)
29105 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29106 +#define au_rw_read_unlock(rw) up_read(rw)
29107 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29108 +#define au_rw_write_lock(rw) down_write(rw)
29109 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29110 +#define au_rw_write_unlock(rw) up_write(rw)
29111 +/* why is not _nested version defined? */
29112 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29113 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29115 +#endif /* __KERNEL__ */
29116 +#endif /* __AUFS_RWSEM_H__ */
29117 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29118 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29119 +++ linux/fs/aufs/sbinfo.c 2020-01-27 10:57:18.178871751 +0100
29121 +// SPDX-License-Identifier: GPL-2.0
29123 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29125 + * This program, aufs is free software; you can redistribute it and/or modify
29126 + * it under the terms of the GNU General Public License as published by
29127 + * the Free Software Foundation; either version 2 of the License, or
29128 + * (at your option) any later version.
29130 + * This program is distributed in the hope that it will be useful,
29131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29133 + * GNU General Public License for more details.
29135 + * You should have received a copy of the GNU General Public License
29136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29140 + * superblock private data
29143 +#include <linux/iversion.h>
29147 + * they are necessary regardless sysfs is disabled.
29149 +void au_si_free(struct kobject *kobj)
29152 + struct au_sbinfo *sbinfo;
29153 + char *locked __maybe_unused; /* debug only */
29155 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29156 + for (i = 0; i < AuPlink_NHASH; i++)
29157 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29158 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29160 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29161 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29162 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29163 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29165 + dbgaufs_si_fin(sbinfo);
29166 + au_rw_write_lock(&sbinfo->si_rwsem);
29167 + au_br_free(sbinfo);
29168 + au_rw_write_unlock(&sbinfo->si_rwsem);
29170 + au_kfree_try_rcu(sbinfo->si_branch);
29171 + mutex_destroy(&sbinfo->si_xib_mtx);
29172 + AuRwDestroy(&sbinfo->si_rwsem);
29174 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29175 + /* si_nfiles is waited too */
29176 + au_kfree_rcu(sbinfo);
29179 +int au_si_alloc(struct super_block *sb)
29182 + struct au_sbinfo *sbinfo;
29185 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29186 + if (unlikely(!sbinfo))
29189 + /* will be reallocated separately */
29190 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29191 + if (unlikely(!sbinfo->si_branch))
29194 + err = sysaufs_si_init(sbinfo);
29196 + dbgaufs_si_null(sbinfo);
29197 + err = dbgaufs_si_init(sbinfo);
29198 + if (unlikely(err))
29199 + kobject_put(&sbinfo->si_kobj);
29201 + if (unlikely(err))
29204 + au_nwt_init(&sbinfo->si_nowait);
29205 + au_rw_init_wlock(&sbinfo->si_rwsem);
29207 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29208 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29210 + sbinfo->si_bbot = -1;
29211 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29213 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29214 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29215 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29216 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29218 + au_fhsm_init(sbinfo);
29220 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29222 + sbinfo->si_xino_jiffy = jiffies;
29223 + sbinfo->si_xino_expire
29224 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29225 + mutex_init(&sbinfo->si_xib_mtx);
29226 + /* leave si_xib_last_pindex and si_xib_next_bit */
29228 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29230 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29231 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29232 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29233 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29235 + for (i = 0; i < AuPlink_NHASH; i++)
29236 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29237 + init_waitqueue_head(&sbinfo->si_plink_wq);
29238 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29240 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29242 + /* with getattr by default */
29243 + sbinfo->si_iop_array = aufs_iop;
29245 + /* leave other members for sysaufs and si_mnt. */
29246 + sbinfo->si_sb = sb;
29247 + sb->s_fs_info = sbinfo;
29249 + return 0; /* success */
29252 + au_kfree_try_rcu(sbinfo->si_branch);
29254 + au_kfree_rcu(sbinfo);
29259 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29262 + struct au_branch **brp;
29264 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29267 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29268 + if (unlikely(!sz))
29269 + sz = sizeof(*brp);
29270 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29273 + sbinfo->si_branch = brp;
29280 +/* ---------------------------------------------------------------------- */
29282 +unsigned int au_sigen_inc(struct super_block *sb)
29284 + unsigned int gen;
29285 + struct inode *inode;
29287 + SiMustWriteLock(sb);
29289 + gen = ++au_sbi(sb)->si_generation;
29290 + au_update_digen(sb->s_root);
29291 + inode = d_inode(sb->s_root);
29292 + au_update_iigen(inode, /*half*/0);
29293 + inode_inc_iversion(inode);
29297 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29299 + aufs_bindex_t br_id;
29301 + struct au_sbinfo *sbinfo;
29303 + SiMustWriteLock(sb);
29305 + sbinfo = au_sbi(sb);
29306 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29307 + br_id = ++sbinfo->si_last_br_id;
29308 + AuDebugOn(br_id < 0);
29309 + if (br_id && au_br_index(sb, br_id) < 0)
29316 +/* ---------------------------------------------------------------------- */
29318 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29319 +int si_read_lock(struct super_block *sb, int flags)
29324 + if (au_ftest_lock(flags, FLUSH))
29325 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29327 + si_noflush_read_lock(sb);
29328 + err = au_plink_maint(sb, flags);
29329 + if (unlikely(err))
29330 + si_read_unlock(sb);
29335 +int si_write_lock(struct super_block *sb, int flags)
29339 + if (au_ftest_lock(flags, FLUSH))
29340 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29342 + si_noflush_write_lock(sb);
29343 + err = au_plink_maint(sb, flags);
29344 + if (unlikely(err))
29345 + si_write_unlock(sb);
29350 +/* dentry and super_block lock. call at entry point */
29351 +int aufs_read_lock(struct dentry *dentry, int flags)
29354 + struct super_block *sb;
29356 + sb = dentry->d_sb;
29357 + err = si_read_lock(sb, flags);
29358 + if (unlikely(err))
29361 + if (au_ftest_lock(flags, DW))
29362 + di_write_lock_child(dentry);
29364 + di_read_lock_child(dentry, flags);
29366 + if (au_ftest_lock(flags, GEN)) {
29367 + err = au_digen_test(dentry, au_sigen(sb));
29368 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29369 + AuDebugOn(!err && au_dbrange_test(dentry));
29371 + err = au_dbrange_test(dentry);
29372 + if (unlikely(err))
29373 + aufs_read_unlock(dentry, flags);
29380 +void aufs_read_unlock(struct dentry *dentry, int flags)
29382 + if (au_ftest_lock(flags, DW))
29383 + di_write_unlock(dentry);
29385 + di_read_unlock(dentry, flags);
29386 + si_read_unlock(dentry->d_sb);
29389 +void aufs_write_lock(struct dentry *dentry)
29391 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29392 + di_write_lock_child(dentry);
29395 +void aufs_write_unlock(struct dentry *dentry)
29397 + di_write_unlock(dentry);
29398 + si_write_unlock(dentry->d_sb);
29401 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29404 + unsigned int sigen;
29405 + struct super_block *sb;
29408 + err = si_read_lock(sb, flags);
29409 + if (unlikely(err))
29412 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29414 + if (au_ftest_lock(flags, GEN)) {
29415 + sigen = au_sigen(sb);
29416 + err = au_digen_test(d1, sigen);
29417 + AuDebugOn(!err && au_dbrange_test(d1));
29419 + err = au_digen_test(d2, sigen);
29420 + AuDebugOn(!err && au_dbrange_test(d2));
29422 + if (unlikely(err))
29423 + aufs_read_and_write_unlock2(d1, d2);
29430 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29432 + di_write_unlock2(d1, d2);
29433 + si_read_unlock(d1->d_sb);
29435 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29436 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29437 +++ linux/fs/aufs/super.c 2020-01-27 10:57:18.178871751 +0100
29439 +// SPDX-License-Identifier: GPL-2.0
29441 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29443 + * This program, aufs is free software; you can redistribute it and/or modify
29444 + * it under the terms of the GNU General Public License as published by
29445 + * the Free Software Foundation; either version 2 of the License, or
29446 + * (at your option) any later version.
29448 + * This program is distributed in the hope that it will be useful,
29449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29451 + * GNU General Public License for more details.
29453 + * You should have received a copy of the GNU General Public License
29454 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29458 + * mount and super_block operations
29461 +#include <linux/iversion.h>
29462 +#include <linux/mm.h>
29463 +#include <linux/seq_file.h>
29464 +#include <linux/statfs.h>
29465 +#include <linux/vmalloc.h>
29469 + * super_operations
29471 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29473 + struct au_icntnr *c;
29475 + c = au_cache_alloc_icntnr();
29477 + au_icntnr_init(c);
29478 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29479 + c->iinfo.ii_hinode = NULL;
29480 + return &c->vfs_inode;
29485 +static void aufs_destroy_inode(struct inode *inode)
29487 + if (!au_is_bad_inode(inode))
29488 + au_iinfo_fin(inode);
29491 +static void aufs_free_inode(struct inode *inode)
29493 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29496 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29498 + struct inode *inode;
29501 + inode = iget_locked(sb, ino);
29502 + if (unlikely(!inode)) {
29503 + inode = ERR_PTR(-ENOMEM);
29506 + if (!(inode->i_state & I_NEW))
29509 + err = au_xigen_new(inode);
29511 + err = au_iinfo_init(inode);
29513 + inode_inc_iversion(inode);
29515 + iget_failed(inode);
29516 + inode = ERR_PTR(err);
29520 + /* never return NULL */
29521 + AuDebugOn(!inode);
29522 + AuTraceErrPtr(inode);
29526 +/* lock free root dinfo */
29527 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29530 + aufs_bindex_t bindex, bbot;
29531 + struct path path;
29532 + struct au_hdentry *hdp;
29533 + struct au_branch *br;
29534 + au_br_perm_str_t perm;
29537 + bbot = au_sbbot(sb);
29539 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29540 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29541 + br = au_sbr(sb, bindex);
29542 + path.mnt = au_br_mnt(br);
29543 + path.dentry = hdp->hd_dentry;
29544 + err = au_seq_path(seq, &path);
29546 + au_optstr_br_perm(&perm, br->br_perm);
29547 + seq_printf(seq, "=%s", perm.a);
29548 + if (bindex != bbot)
29549 + seq_putc(seq, ':');
29552 + if (unlikely(err || seq_has_overflowed(seq)))
29558 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29559 + const char *append)
29564 + while (*pat != ':')
29567 + strcpy(p, append);
29568 + AuDebugOn(strlen(fmt) >= len);
29571 +static void au_show_wbr_create(struct seq_file *m, int v,
29572 + struct au_sbinfo *sbinfo)
29576 + struct au_wbr_mfs *mfs;
29578 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29580 + seq_puts(m, ",create=");
29581 + pat = au_optstr_wbr_create(v);
29582 + mfs = &sbinfo->si_wbr_mfs;
29584 + case AuWbrCreate_TDP:
29585 + case AuWbrCreate_RR:
29586 + case AuWbrCreate_MFS:
29587 + case AuWbrCreate_PMFS:
29588 + seq_puts(m, pat);
29590 + case AuWbrCreate_MFSRR:
29591 + case AuWbrCreate_TDMFS:
29592 + case AuWbrCreate_PMFSRR:
29593 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29594 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29596 + case AuWbrCreate_MFSV:
29597 + case AuWbrCreate_PMFSV:
29598 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29599 + seq_printf(m, fmt,
29600 + jiffies_to_msecs(mfs->mfs_expire)
29603 + case AuWbrCreate_MFSRRV:
29604 + case AuWbrCreate_TDMFSV:
29605 + case AuWbrCreate_PMFSRRV:
29606 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29607 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29608 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29615 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29617 +#ifdef CONFIG_SYSFS
29621 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29622 + aufs_bindex_t bindex, brid;
29623 + struct qstr *name;
29625 + struct dentry *d, *h_root;
29626 + struct au_branch *br;
29628 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29631 + f = au_sbi(sb)->si_xib;
29635 + /* stop printing the default xino path on the first writable branch */
29637 + bindex = au_xi_root(sb, f->f_path.dentry);
29638 + if (bindex >= 0) {
29639 + br = au_sbr_sb(sb, bindex);
29640 + h_root = au_br_dentry(br);
29643 + d = f->f_path.dentry;
29644 + name = &d->d_name;
29645 + /* safe ->d_parent because the file is unlinked */
29646 + if (d->d_parent == h_root
29647 + && name->len == len
29648 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29651 + seq_puts(seq, ",xino=");
29652 + err = au_xino_path(seq, f);
29659 +/* seq_file will re-call me in case of too long string */
29660 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29663 + unsigned int mnt_flags, v;
29664 + struct super_block *sb;
29665 + struct au_sbinfo *sbinfo;
29667 +#define AuBool(name, str) do { \
29668 + v = au_opt_test(mnt_flags, name); \
29669 + if (v != au_opt_test(AuOpt_Def, name)) \
29670 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29673 +#define AuStr(name, str) do { \
29674 + v = mnt_flags & AuOptMask_##name; \
29675 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29676 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29679 +#define AuUInt(name, str, val) do { \
29680 + if (val != AUFS_##name##_DEF) \
29681 + seq_printf(m, "," #str "=%u", val); \
29684 + sb = dentry->d_sb;
29685 + if (sb->s_flags & SB_POSIXACL)
29686 + seq_puts(m, ",acl");
29687 +#if 0 /* reserved for future use */
29688 + if (sb->s_flags & SB_I_VERSION)
29689 + seq_puts(m, ",i_version");
29692 + /* lock free root dinfo */
29693 + si_noflush_read_lock(sb);
29694 + sbinfo = au_sbi(sb);
29695 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29697 + mnt_flags = au_mntflags(sb);
29698 + if (au_opt_test(mnt_flags, XINO)) {
29699 + err = au_show_xino(m, sb);
29700 + if (unlikely(err))
29703 + seq_puts(m, ",noxino");
29705 + AuBool(TRUNC_XINO, trunc_xino);
29706 + AuStr(UDBA, udba);
29707 + AuBool(SHWH, shwh);
29708 + AuBool(PLINK, plink);
29709 + AuBool(DIO, dio);
29710 + AuBool(DIRPERM1, dirperm1);
29712 + v = sbinfo->si_wbr_create;
29713 + if (v != AuWbrCreate_Def)
29714 + au_show_wbr_create(m, v, sbinfo);
29716 + v = sbinfo->si_wbr_copyup;
29717 + if (v != AuWbrCopyup_Def)
29718 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29720 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29721 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29722 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29724 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29726 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29727 + AuUInt(RDCACHE, rdcache, v);
29729 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29730 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29732 + au_fhsm_show(m, sbinfo);
29734 + AuBool(DIRREN, dirren);
29735 + AuBool(SUM, sum);
29736 + /* AuBool(SUM_W, wsum); */
29737 + AuBool(WARN_PERM, warn_perm);
29738 + AuBool(VERBOSE, verbose);
29741 + /* be sure to print "br:" last */
29742 + if (!sysaufs_brs) {
29743 + seq_puts(m, ",br:");
29744 + au_show_brs(m, sb);
29746 + si_read_unlock(sb);
29754 +/* ---------------------------------------------------------------------- */
29756 +/* sum mode which returns the summation for statfs(2) */
29758 +static u64 au_add_till_max(u64 a, u64 b)
29766 + return ULLONG_MAX;
29769 +static u64 au_mul_till_max(u64 a, long mul)
29777 + return ULLONG_MAX;
29780 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29783 + long bsize, factor;
29784 + u64 blocks, bfree, bavail, files, ffree;
29785 + aufs_bindex_t bbot, bindex, i;
29786 + unsigned char shared;
29787 + struct path h_path;
29788 + struct super_block *h_sb;
29791 + bsize = LONG_MAX;
29797 + bbot = au_sbbot(sb);
29798 + for (bindex = 0; bindex <= bbot; bindex++) {
29799 + h_path.mnt = au_sbr_mnt(sb, bindex);
29800 + h_sb = h_path.mnt->mnt_sb;
29802 + for (i = 0; !shared && i < bindex; i++)
29803 + shared = (au_sbr_sb(sb, i) == h_sb);
29807 + /* sb->s_root for NFS is unreliable */
29808 + h_path.dentry = h_path.mnt->mnt_root;
29809 + err = vfs_statfs(&h_path, buf);
29810 + if (unlikely(err))
29813 + if (bsize > buf->f_bsize) {
29815 + * we will reduce bsize, so we have to expand blocks
29816 + * etc. to match them again
29818 + factor = (bsize / buf->f_bsize);
29819 + blocks = au_mul_till_max(blocks, factor);
29820 + bfree = au_mul_till_max(bfree, factor);
29821 + bavail = au_mul_till_max(bavail, factor);
29822 + bsize = buf->f_bsize;
29825 + factor = (buf->f_bsize / bsize);
29826 + blocks = au_add_till_max(blocks,
29827 + au_mul_till_max(buf->f_blocks, factor));
29828 + bfree = au_add_till_max(bfree,
29829 + au_mul_till_max(buf->f_bfree, factor));
29830 + bavail = au_add_till_max(bavail,
29831 + au_mul_till_max(buf->f_bavail, factor));
29832 + files = au_add_till_max(files, buf->f_files);
29833 + ffree = au_add_till_max(ffree, buf->f_ffree);
29836 + buf->f_bsize = bsize;
29837 + buf->f_blocks = blocks;
29838 + buf->f_bfree = bfree;
29839 + buf->f_bavail = bavail;
29840 + buf->f_files = files;
29841 + buf->f_ffree = ffree;
29842 + buf->f_frsize = 0;
29848 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29851 + struct path h_path;
29852 + struct super_block *sb;
29854 + /* lock free root dinfo */
29855 + sb = dentry->d_sb;
29856 + si_noflush_read_lock(sb);
29857 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29858 + /* sb->s_root for NFS is unreliable */
29859 + h_path.mnt = au_sbr_mnt(sb, 0);
29860 + h_path.dentry = h_path.mnt->mnt_root;
29861 + err = vfs_statfs(&h_path, buf);
29863 + err = au_statfs_sum(sb, buf);
29864 + si_read_unlock(sb);
29867 + buf->f_type = AUFS_SUPER_MAGIC;
29868 + buf->f_namelen = AUFS_MAX_NAMELEN;
29869 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29871 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29876 +/* ---------------------------------------------------------------------- */
29878 +static int aufs_sync_fs(struct super_block *sb, int wait)
29881 + aufs_bindex_t bbot, bindex;
29882 + struct au_branch *br;
29883 + struct super_block *h_sb;
29886 + si_noflush_read_lock(sb);
29887 + bbot = au_sbbot(sb);
29888 + for (bindex = 0; bindex <= bbot; bindex++) {
29889 + br = au_sbr(sb, bindex);
29890 + if (!au_br_writable(br->br_perm))
29893 + h_sb = au_sbr_sb(sb, bindex);
29894 + e = vfsub_sync_filesystem(h_sb, wait);
29895 + if (unlikely(e && !err))
29897 + /* go on even if an error happens */
29899 + si_read_unlock(sb);
29904 +/* ---------------------------------------------------------------------- */
29906 +/* final actions when unmounting a file system */
29907 +static void aufs_put_super(struct super_block *sb)
29909 + struct au_sbinfo *sbinfo;
29911 + sbinfo = au_sbi(sb);
29913 + kobject_put(&sbinfo->si_kobj);
29916 +/* ---------------------------------------------------------------------- */
29918 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29919 + struct super_block *sb, void *arg)
29922 + unsigned long long n, sz;
29929 + if (*hint > ULLONG_MAX / sizeof(array)) {
29930 + array = ERR_PTR(-EMFILE);
29931 + pr_err("hint %llu\n", *hint);
29935 + sz = sizeof(array) * *hint;
29936 + array = kzalloc(sz, GFP_NOFS);
29937 + if (unlikely(!array))
29938 + array = vzalloc(sz);
29939 + if (unlikely(!array)) {
29940 + array = ERR_PTR(-ENOMEM);
29944 + n = cb(sb, array, *hint, arg);
29945 + AuDebugOn(n > *hint);
29952 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29953 + unsigned long long max __maybe_unused,
29956 + unsigned long long n;
29957 + struct inode **p, *inode;
29958 + struct list_head *head;
29963 + spin_lock(&sb->s_inode_list_lock);
29964 + list_for_each_entry(inode, head, i_sb_list) {
29965 + if (!au_is_bad_inode(inode)
29966 + && au_ii(inode)->ii_btop >= 0) {
29967 + spin_lock(&inode->i_lock);
29968 + if (atomic_read(&inode->i_count)) {
29972 + AuDebugOn(n > max);
29974 + spin_unlock(&inode->i_lock);
29977 + spin_unlock(&sb->s_inode_list_lock);
29982 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29984 + struct au_sbinfo *sbi;
29986 + sbi = au_sbi(sb);
29987 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29988 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29991 +void au_iarray_free(struct inode **a, unsigned long long max)
29993 + unsigned long long ull;
29995 + for (ull = 0; ull < max; ull++)
30000 +/* ---------------------------------------------------------------------- */
30003 + * refresh dentry and inode at remount time.
30005 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30006 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30007 + struct dentry *parent)
30011 + di_write_lock_child(dentry);
30012 + di_read_lock_parent(parent, AuLock_IR);
30013 + err = au_refresh_dentry(dentry, parent);
30014 + if (!err && dir_flags)
30015 + au_hn_reset(d_inode(dentry), dir_flags);
30016 + di_read_unlock(parent, AuLock_IR);
30017 + di_write_unlock(dentry);
30022 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30023 + struct au_sbinfo *sbinfo,
30024 + const unsigned int dir_flags, unsigned int do_idop)
30027 + struct dentry *parent;
30030 + parent = dget_parent(dentry);
30031 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30032 + if (d_really_is_positive(dentry)) {
30033 + if (!d_is_dir(dentry))
30034 + err = au_do_refresh(dentry, /*dir_flags*/0,
30037 + err = au_do_refresh(dentry, dir_flags, parent);
30038 + if (unlikely(err))
30039 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30042 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30043 + AuDbgDentry(dentry);
30049 + au_refresh_dop(dentry, /*force_reval*/0);
30051 + au_refresh_dop(dentry, /*force_reval*/1);
30057 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30059 + int err, i, j, ndentry, e;
30060 + unsigned int sigen;
30061 + struct au_dcsub_pages dpages;
30062 + struct au_dpage *dpage;
30063 + struct dentry **dentries, *d;
30064 + struct au_sbinfo *sbinfo;
30065 + struct dentry *root = sb->s_root;
30066 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30069 + au_refresh_dop(root, /*force_reval*/0);
30071 + err = au_dpages_init(&dpages, GFP_NOFS);
30072 + if (unlikely(err))
30074 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30075 + if (unlikely(err))
30078 + sigen = au_sigen(sb);
30079 + sbinfo = au_sbi(sb);
30080 + for (i = 0; i < dpages.ndpage; i++) {
30081 + dpage = dpages.dpages + i;
30082 + dentries = dpage->dentries;
30083 + ndentry = dpage->ndentry;
30084 + for (j = 0; j < ndentry; j++) {
30086 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30088 + if (unlikely(e && !err))
30090 + /* go on even err */
30095 + au_dpages_free(&dpages);
30100 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30103 + unsigned int sigen;
30104 + unsigned long long max, ull;
30105 + struct inode *inode, **array;
30107 + array = au_iarray_alloc(sb, &max);
30108 + err = PTR_ERR(array);
30109 + if (IS_ERR(array))
30113 + sigen = au_sigen(sb);
30114 + for (ull = 0; ull < max; ull++) {
30115 + inode = array[ull];
30116 + if (unlikely(!inode))
30120 + ii_write_lock_child(inode);
30121 + if (au_iigen(inode, NULL) != sigen) {
30122 + e = au_refresh_hinode_self(inode);
30123 + if (unlikely(e)) {
30124 + au_refresh_iop(inode, /*force_getattr*/1);
30125 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30128 + /* go on even if err */
30131 + if (!e && do_idop)
30132 + au_refresh_iop(inode, /*force_getattr*/0);
30133 + ii_write_unlock(inode);
30136 + au_iarray_free(array, max);
30142 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30145 + unsigned int udba;
30146 + aufs_bindex_t bindex, bbot;
30147 + struct dentry *root;
30148 + struct inode *inode;
30149 + struct au_branch *br;
30150 + struct au_sbinfo *sbi;
30152 + au_sigen_inc(sb);
30153 + sbi = au_sbi(sb);
30154 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30156 + root = sb->s_root;
30157 + DiMustNoWaiters(root);
30158 + inode = d_inode(root);
30159 + IiMustNoWaiters(inode);
30161 + udba = au_opt_udba(sb);
30162 + bbot = au_sbbot(sb);
30163 + for (bindex = 0; bindex <= bbot; bindex++) {
30164 + br = au_sbr(sb, bindex);
30165 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30166 + if (unlikely(err))
30167 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30169 + /* go on even if err */
30171 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30174 + if (au_ftest_si(sbi, NO_DREVAL)) {
30175 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30176 + sb->s_d_op = &aufs_dop_noreval;
30177 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30178 + sbi->si_iop_array = aufs_iop_nogetattr;
30180 + AuDebugOn(sb->s_d_op == &aufs_dop);
30181 + sb->s_d_op = &aufs_dop;
30182 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30183 + sbi->si_iop_array = aufs_iop;
30185 + pr_info("reset to %ps and %ps\n",
30186 + sb->s_d_op, sbi->si_iop_array);
30189 + di_write_unlock(root);
30190 + err = au_refresh_d(sb, do_idop);
30191 + e = au_refresh_i(sb, do_idop);
30192 + if (unlikely(e && !err))
30194 + /* aufs_write_lock() calls ..._child() */
30195 + di_write_lock_child(root);
30197 + au_cpup_attr_all(inode, /*force*/1);
30199 + if (unlikely(err))
30200 + AuIOErr("refresh failed, ignored, %d\n", err);
30203 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30204 +static int cvt_err(int err)
30218 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30221 + unsigned int mntflags;
30222 + struct au_opts opts = {
30225 + struct dentry *root;
30226 + struct inode *inode;
30227 + struct au_sbinfo *sbinfo;
30230 + root = sb->s_root;
30231 + if (!data || !*data) {
30232 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30234 + di_write_lock_child(root);
30235 + err = au_opts_verify(sb, *flags, /*pending*/0);
30236 + aufs_write_unlock(root);
30242 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30243 + if (unlikely(!opts.opt))
30245 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30246 + opts.flags = AuOpts_REMOUNT;
30247 + opts.sb_flags = *flags;
30249 + /* parse it before aufs lock */
30250 + err = au_opts_parse(sb, data, &opts);
30251 + if (unlikely(err))
30254 + sbinfo = au_sbi(sb);
30255 + inode = d_inode(root);
30256 + inode_lock(inode);
30257 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30258 + if (unlikely(err))
30260 + di_write_lock_child(root);
30262 + /* au_opts_remount() may return an error */
30263 + err = au_opts_remount(sb, &opts);
30264 + au_opts_free(&opts);
30266 + if (au_ftest_opts(opts.flags, REFRESH))
30267 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30269 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30270 + mntflags = au_mntflags(sb);
30271 + do_dx = !!au_opt_test(mntflags, DIO);
30272 + au_dy_arefresh(do_dx);
30275 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30276 + aufs_write_unlock(root);
30279 + inode_unlock(inode);
30281 + free_page((unsigned long)opts.opt);
30283 + err = cvt_err(err);
30288 +static const struct super_operations aufs_sop = {
30289 + .alloc_inode = aufs_alloc_inode,
30290 + .destroy_inode = aufs_destroy_inode,
30291 + .free_inode = aufs_free_inode,
30292 + /* always deleting, no clearing */
30293 + .drop_inode = generic_delete_inode,
30294 + .show_options = aufs_show_options,
30295 + .statfs = aufs_statfs,
30296 + .put_super = aufs_put_super,
30297 + .sync_fs = aufs_sync_fs,
30298 + .remount_fs = aufs_remount_fs
30301 +/* ---------------------------------------------------------------------- */
30303 +static int alloc_root(struct super_block *sb)
30306 + struct inode *inode;
30307 + struct dentry *root;
30310 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30311 + err = PTR_ERR(inode);
30312 + if (IS_ERR(inode))
30315 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30316 + inode->i_fop = &aufs_dir_fop;
30317 + inode->i_mode = S_IFDIR;
30318 + set_nlink(inode, 2);
30319 + unlock_new_inode(inode);
30321 + root = d_make_root(inode);
30322 + if (unlikely(!root))
30324 + err = PTR_ERR(root);
30325 + if (IS_ERR(root))
30328 + err = au_di_init(root);
30330 + sb->s_root = root;
30331 + return 0; /* success */
30339 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30340 + int silent __maybe_unused)
30343 + struct au_opts opts = {
30346 + struct au_sbinfo *sbinfo;
30347 + struct dentry *root;
30348 + struct inode *inode;
30349 + char *arg = raw_data;
30351 + if (unlikely(!arg || !*arg)) {
30353 + pr_err("no arg\n");
30358 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30359 + if (unlikely(!opts.opt))
30361 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30362 + opts.sb_flags = sb->s_flags;
30364 + err = au_si_alloc(sb);
30365 + if (unlikely(err))
30367 + sbinfo = au_sbi(sb);
30369 + /* all timestamps always follow the ones on the branch */
30370 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30371 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30372 + sb->s_op = &aufs_sop;
30373 + sb->s_d_op = &aufs_dop;
30374 + sb->s_magic = AUFS_SUPER_MAGIC;
30375 + sb->s_maxbytes = 0;
30376 + sb->s_stack_depth = 1;
30377 + au_export_init(sb);
30378 + au_xattr_init(sb);
30380 + err = alloc_root(sb);
30381 + if (unlikely(err)) {
30382 + si_write_unlock(sb);
30385 + root = sb->s_root;
30386 + inode = d_inode(root);
30389 + * actually we can parse options regardless aufs lock here.
30390 + * but at remount time, parsing must be done before aufs lock.
30391 + * so we follow the same rule.
30393 + ii_write_lock_parent(inode);
30394 + aufs_write_unlock(root);
30395 + err = au_opts_parse(sb, arg, &opts);
30396 + if (unlikely(err))
30399 + /* lock vfs_inode first, then aufs. */
30400 + inode_lock(inode);
30401 + aufs_write_lock(root);
30402 + err = au_opts_mount(sb, &opts);
30403 + au_opts_free(&opts);
30404 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30405 + sb->s_d_op = &aufs_dop_noreval;
30406 + pr_info("%ps\n", sb->s_d_op);
30407 + au_refresh_dop(root, /*force_reval*/0);
30408 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30409 + au_refresh_iop(inode, /*force_getattr*/0);
30411 + aufs_write_unlock(root);
30412 + inode_unlock(inode);
30414 + goto out_opts; /* success */
30418 + sb->s_root = NULL;
30420 + kobject_put(&sbinfo->si_kobj);
30421 + sb->s_fs_info = NULL;
30423 + free_page((unsigned long)opts.opt);
30426 + err = cvt_err(err);
30431 +/* ---------------------------------------------------------------------- */
30433 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30434 + const char *dev_name __maybe_unused,
30437 + struct dentry *root;
30439 + /* all timestamps always follow the ones on the branch */
30440 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30441 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30442 + if (IS_ERR(root))
30445 + au_sbilist_add(root->d_sb);
30451 +static void aufs_kill_sb(struct super_block *sb)
30453 + struct au_sbinfo *sbinfo;
30455 + sbinfo = au_sbi(sb);
30457 + au_sbilist_del(sb);
30458 + aufs_write_lock(sb->s_root);
30460 + if (sbinfo->si_wbr_create_ops->fin)
30461 + sbinfo->si_wbr_create_ops->fin(sb);
30462 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30463 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30464 + au_remount_refresh(sb, /*do_idop*/0);
30466 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30467 + au_plink_put(sb, /*verbose*/1);
30469 + au_dr_opt_flush(sb);
30470 + sbinfo->si_sb = NULL;
30471 + aufs_write_unlock(sb->s_root);
30472 + au_nwt_flush(&sbinfo->si_nowait);
30474 + kill_anon_super(sb);
30477 +struct file_system_type aufs_fs_type = {
30478 + .name = AUFS_FSTYPE,
30479 + /* a race between rename and others */
30480 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30481 + .mount = aufs_mount,
30482 + .kill_sb = aufs_kill_sb,
30483 + /* no need to __module_get() and module_put(). */
30484 + .owner = THIS_MODULE,
30486 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30487 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30488 +++ linux/fs/aufs/super.h 2020-01-27 10:57:18.178871751 +0100
30490 +/* SPDX-License-Identifier: GPL-2.0 */
30492 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30494 + * This program, aufs is free software; you can redistribute it and/or modify
30495 + * it under the terms of the GNU General Public License as published by
30496 + * the Free Software Foundation; either version 2 of the License, or
30497 + * (at your option) any later version.
30499 + * This program is distributed in the hope that it will be useful,
30500 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30501 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30502 + * GNU General Public License for more details.
30504 + * You should have received a copy of the GNU General Public License
30505 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30509 + * super_block operations
30512 +#ifndef __AUFS_SUPER_H__
30513 +#define __AUFS_SUPER_H__
30517 +#include <linux/fs.h>
30518 +#include <linux/kobject.h>
30521 +#include "rwsem.h"
30524 +/* policies to select one among multiple writable branches */
30525 +struct au_wbr_copyup_operations {
30526 + int (*copyup)(struct dentry *dentry);
30529 +#define AuWbr_DIR 1 /* target is a dir */
30530 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30532 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30533 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30534 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30536 +struct au_wbr_create_operations {
30537 + int (*create)(struct dentry *dentry, unsigned int flags);
30538 + int (*init)(struct super_block *sb);
30539 + int (*fin)(struct super_block *sb);
30542 +struct au_wbr_mfs {
30543 + struct mutex mfs_lock; /* protect this structure */
30544 + unsigned long mfs_jiffy;
30545 + unsigned long mfs_expire;
30546 + aufs_bindex_t mfs_bindex;
30548 + unsigned long long mfsrr_bytes;
30549 + unsigned long long mfsrr_watermark;
30552 +#define AuPlink_NHASH 100
30553 +static inline int au_plink_hash(ino_t ino)
30555 + return ino % AuPlink_NHASH;
30558 +/* File-based Hierarchical Storage Management */
30560 +#ifdef CONFIG_AUFS_FHSM
30561 + /* allow only one process who can receive the notification */
30562 + spinlock_t fhsm_spin;
30564 + wait_queue_head_t fhsm_wqh;
30565 + atomic_t fhsm_readable;
30567 + /* these are protected by si_rwsem */
30568 + unsigned long fhsm_expire;
30569 + aufs_bindex_t fhsm_bottom;
30574 +struct au_sbinfo {
30575 + /* nowait tasks in the system-wide workqueue */
30576 + struct au_nowait_tasks si_nowait;
30579 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30580 + * rwsem for au_sbinfo is necessary.
30582 + struct au_rwsem si_rwsem;
30585 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30588 + au_lcnt_t si_ninodes, si_nfiles;
30590 + /* branch management */
30591 + unsigned int si_generation;
30593 + /* see AuSi_ flags */
30594 + unsigned char au_si_status;
30596 + aufs_bindex_t si_bbot;
30598 + /* dirty trick to keep br_id plus */
30599 + unsigned int si_last_br_id :
30600 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30601 + struct au_branch **si_branch;
30603 + /* policy to select a writable branch */
30604 + unsigned char si_wbr_copyup;
30605 + unsigned char si_wbr_create;
30606 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30607 + struct au_wbr_create_operations *si_wbr_create_ops;
30609 + /* round robin */
30610 + atomic_t si_wbr_rr_next;
30612 + /* most free space */
30613 + struct au_wbr_mfs si_wbr_mfs;
30615 + /* File-based Hierarchical Storage Management */
30616 + struct au_fhsm si_fhsm;
30618 + /* mount flags */
30619 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30620 + unsigned int si_mntflags;
30622 + /* external inode number (bitmap and translation table) */
30623 + vfs_readf_t si_xread;
30624 + vfs_writef_t si_xwrite;
30625 + loff_t si_ximaxent; /* max entries in a xino */
30627 + struct file *si_xib;
30628 + struct mutex si_xib_mtx; /* protect xib members */
30629 + unsigned long *si_xib_buf;
30630 + unsigned long si_xib_last_pindex;
30631 + int si_xib_next_bit;
30633 + unsigned long si_xino_jiffy;
30634 + unsigned long si_xino_expire;
30635 + /* reserved for future use */
30636 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30638 +#ifdef CONFIG_AUFS_EXPORT
30639 + /* i_generation */
30640 + /* todo: make xigen file an array to support many inode numbers */
30641 + struct file *si_xigen;
30642 + atomic_t si_xigen_next;
30645 + /* dirty trick to support atomic_open */
30646 + struct hlist_bl_head si_aopen;
30648 + /* vdir parameters */
30649 + unsigned long si_rdcache; /* max cache time in jiffies */
30650 + unsigned int si_rdblk; /* deblk size */
30651 + unsigned int si_rdhash; /* hash size */
30654 + * If the number of whiteouts are larger than si_dirwh, leave all of
30655 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30656 + * future fsck.aufs or kernel thread will remove them later.
30657 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30659 + unsigned int si_dirwh;
30661 + /* pseudo_link list */
30662 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30663 + wait_queue_head_t si_plink_wq;
30664 + spinlock_t si_plink_maint_lock;
30665 + pid_t si_plink_maint_pid;
30668 + struct hlist_bl_head si_files;
30670 + /* with/without getattr, brother of sb->s_d_op */
30671 + const struct inode_operations *si_iop_array;
30674 + * sysfs and lifetime management.
30675 + * this is not a small structure and it may be a waste of memory in case
30676 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30677 + * but using sysfs is majority.
30679 + struct kobject si_kobj;
30680 +#ifdef CONFIG_DEBUG_FS
30681 + struct dentry *si_dbgaufs;
30682 + struct dentry *si_dbgaufs_plink;
30683 + struct dentry *si_dbgaufs_xib;
30684 +#ifdef CONFIG_AUFS_EXPORT
30685 + struct dentry *si_dbgaufs_xigen;
30689 +#ifdef CONFIG_AUFS_SBILIST
30690 + struct hlist_bl_node si_list;
30693 + /* dirty, necessary for unmounting, sysfs and sysrq */
30694 + struct super_block *si_sb;
30697 +/* sbinfo status flags */
30699 + * set true when refresh_dirs() failed at remount time.
30700 + * then try refreshing dirs at access time again.
30701 + * if it is false, refreshing dirs at access time is unnecessary
30703 +#define AuSi_FAILED_REFRESH_DIR 1
30704 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30705 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30707 +#ifndef CONFIG_AUFS_FHSM
30709 +#define AuSi_FHSM 0
30712 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30713 + unsigned int flag)
30715 + AuRwMustAnyLock(&sbi->si_rwsem);
30716 + return sbi->au_si_status & flag;
30718 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30719 +#define au_fset_si(sbinfo, name) do { \
30720 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30721 + (sbinfo)->au_si_status |= AuSi_##name; \
30723 +#define au_fclr_si(sbinfo, name) do { \
30724 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30725 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30728 +/* ---------------------------------------------------------------------- */
30730 +/* policy to select one among writable branches */
30731 +#define AuWbrCopyup(sbinfo, ...) \
30732 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30733 +#define AuWbrCreate(sbinfo, ...) \
30734 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30736 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30737 +#define AuLock_DW 1 /* write-lock dentry */
30738 +#define AuLock_IR (1 << 1) /* read-lock inode */
30739 +#define AuLock_IW (1 << 2) /* write-lock inode */
30740 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30741 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30742 + /* except RENAME_EXCHANGE */
30743 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30744 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30745 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30746 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30747 +#define au_fset_lock(flags, name) \
30748 + do { (flags) |= AuLock_##name; } while (0)
30749 +#define au_fclr_lock(flags, name) \
30750 + do { (flags) &= ~AuLock_##name; } while (0)
30752 +/* ---------------------------------------------------------------------- */
30755 +extern struct file_system_type aufs_fs_type;
30756 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30757 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30758 + unsigned long long max, void *arg);
30759 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30760 + struct super_block *sb, void *arg);
30761 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30762 +void au_iarray_free(struct inode **a, unsigned long long max);
30765 +void au_si_free(struct kobject *kobj);
30766 +int au_si_alloc(struct super_block *sb);
30767 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30769 +unsigned int au_sigen_inc(struct super_block *sb);
30770 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30772 +int si_read_lock(struct super_block *sb, int flags);
30773 +int si_write_lock(struct super_block *sb, int flags);
30774 +int aufs_read_lock(struct dentry *dentry, int flags);
30775 +void aufs_read_unlock(struct dentry *dentry, int flags);
30776 +void aufs_write_lock(struct dentry *dentry);
30777 +void aufs_write_unlock(struct dentry *dentry);
30778 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30779 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30781 +/* wbr_policy.c */
30782 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30783 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30784 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30785 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30786 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30789 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30791 +#ifdef CONFIG_AUFS_FHSM
30794 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30798 + spin_lock(&fhsm->fhsm_spin);
30799 + pid = fhsm->fhsm_pid;
30800 + spin_unlock(&fhsm->fhsm_spin);
30805 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30806 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30807 +int au_fhsm_fd(struct super_block *sb, int oflags);
30808 +int au_fhsm_br_alloc(struct au_branch *br);
30809 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30810 +void au_fhsm_fin(struct super_block *sb);
30811 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30812 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30813 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30815 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30817 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30818 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30819 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30820 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30821 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30822 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30823 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30824 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30825 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30828 +/* ---------------------------------------------------------------------- */
30830 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30832 + return sb->s_fs_info;
30835 +/* ---------------------------------------------------------------------- */
30837 +#ifdef CONFIG_AUFS_EXPORT
30838 +int au_test_nfsd(void);
30839 +void au_export_init(struct super_block *sb);
30840 +void au_xigen_inc(struct inode *inode);
30841 +int au_xigen_new(struct inode *inode);
30842 +int au_xigen_set(struct super_block *sb, struct path *path);
30843 +void au_xigen_clr(struct super_block *sb);
30845 +static inline int au_busy_or_stale(void)
30847 + if (!au_test_nfsd())
30852 +AuStubInt0(au_test_nfsd, void)
30853 +AuStubVoid(au_export_init, struct super_block *sb)
30854 +AuStubVoid(au_xigen_inc, struct inode *inode)
30855 +AuStubInt0(au_xigen_new, struct inode *inode)
30856 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30857 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30858 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30859 +#endif /* CONFIG_AUFS_EXPORT */
30861 +/* ---------------------------------------------------------------------- */
30863 +#ifdef CONFIG_AUFS_SBILIST
30865 +extern struct hlist_bl_head au_sbilist;
30867 +static inline void au_sbilist_init(void)
30869 + INIT_HLIST_BL_HEAD(&au_sbilist);
30872 +static inline void au_sbilist_add(struct super_block *sb)
30874 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30877 +static inline void au_sbilist_del(struct super_block *sb)
30879 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30882 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30883 +static inline void au_sbilist_lock(void)
30885 + hlist_bl_lock(&au_sbilist);
30888 +static inline void au_sbilist_unlock(void)
30890 + hlist_bl_unlock(&au_sbilist);
30892 +#define AuGFP_SBILIST GFP_ATOMIC
30894 +AuStubVoid(au_sbilist_lock, void)
30895 +AuStubVoid(au_sbilist_unlock, void)
30896 +#define AuGFP_SBILIST GFP_NOFS
30897 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30899 +AuStubVoid(au_sbilist_init, void)
30900 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30901 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30902 +AuStubVoid(au_sbilist_lock, void)
30903 +AuStubVoid(au_sbilist_unlock, void)
30904 +#define AuGFP_SBILIST GFP_NOFS
30907 +/* ---------------------------------------------------------------------- */
30909 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30912 + * This function is a dynamic '__init' function actually,
30913 + * so the tiny check for si_rwsem is unnecessary.
30915 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30916 +#ifdef CONFIG_DEBUG_FS
30917 + sbinfo->si_dbgaufs = NULL;
30918 + sbinfo->si_dbgaufs_plink = NULL;
30919 + sbinfo->si_dbgaufs_xib = NULL;
30920 +#ifdef CONFIG_AUFS_EXPORT
30921 + sbinfo->si_dbgaufs_xigen = NULL;
30926 +/* ---------------------------------------------------------------------- */
30928 +/* current->atomic_flags */
30929 +/* this value should never corrupt the ones defined in linux/sched.h */
30930 +#define PFA_AUFS 0x10
30932 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30933 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30934 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30936 +static inline int si_pid_test(struct super_block *sb)
30938 + return !!task_test_aufs(current);
30941 +static inline void si_pid_clr(struct super_block *sb)
30943 + AuDebugOn(!task_test_aufs(current));
30944 + task_clear_aufs(current);
30947 +static inline void si_pid_set(struct super_block *sb)
30949 + AuDebugOn(task_test_aufs(current));
30950 + task_set_aufs(current);
30953 +/* ---------------------------------------------------------------------- */
30955 +/* lock superblock. mainly for entry point functions */
30956 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30957 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30958 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30959 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30961 +#define __si_read_trylock_nested(sb) \
30962 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30963 +#define __si_write_trylock_nested(sb) \
30964 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30967 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30968 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30969 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30971 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30972 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30973 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30975 +static inline void si_noflush_read_lock(struct super_block *sb)
30977 + __si_read_lock(sb);
30981 +static inline int si_noflush_read_trylock(struct super_block *sb)
30985 + locked = __si_read_trylock(sb);
30991 +static inline void si_noflush_write_lock(struct super_block *sb)
30993 + __si_write_lock(sb);
30997 +static inline int si_noflush_write_trylock(struct super_block *sb)
31001 + locked = __si_write_trylock(sb);
31007 +#if 0 /* reserved */
31008 +static inline int si_read_trylock(struct super_block *sb, int flags)
31010 + if (au_ftest_lock(flags, FLUSH))
31011 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31012 + return si_noflush_read_trylock(sb);
31016 +static inline void si_read_unlock(struct super_block *sb)
31019 + __si_read_unlock(sb);
31022 +#if 0 /* reserved */
31023 +static inline int si_write_trylock(struct super_block *sb, int flags)
31025 + if (au_ftest_lock(flags, FLUSH))
31026 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31027 + return si_noflush_write_trylock(sb);
31031 +static inline void si_write_unlock(struct super_block *sb)
31034 + __si_write_unlock(sb);
31037 +#if 0 /* reserved */
31038 +static inline void si_downgrade_lock(struct super_block *sb)
31040 + __si_downgrade_lock(sb);
31044 +/* ---------------------------------------------------------------------- */
31046 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31048 + SiMustAnyLock(sb);
31049 + return au_sbi(sb)->si_bbot;
31052 +static inline unsigned int au_mntflags(struct super_block *sb)
31054 + SiMustAnyLock(sb);
31055 + return au_sbi(sb)->si_mntflags;
31058 +static inline unsigned int au_sigen(struct super_block *sb)
31060 + SiMustAnyLock(sb);
31061 + return au_sbi(sb)->si_generation;
31064 +static inline struct au_branch *au_sbr(struct super_block *sb,
31065 + aufs_bindex_t bindex)
31067 + SiMustAnyLock(sb);
31068 + return au_sbi(sb)->si_branch[0 + bindex];
31071 +static inline loff_t au_xi_maxent(struct super_block *sb)
31073 + SiMustAnyLock(sb);
31074 + return au_sbi(sb)->si_ximaxent;
31077 +#endif /* __KERNEL__ */
31078 +#endif /* __AUFS_SUPER_H__ */
31079 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31080 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31081 +++ linux/fs/aufs/sysaufs.c 2020-01-27 10:57:18.178871751 +0100
31083 +// SPDX-License-Identifier: GPL-2.0
31085 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31087 + * This program, aufs is free software; you can redistribute it and/or modify
31088 + * it under the terms of the GNU General Public License as published by
31089 + * the Free Software Foundation; either version 2 of the License, or
31090 + * (at your option) any later version.
31092 + * This program is distributed in the hope that it will be useful,
31093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31095 + * GNU General Public License for more details.
31097 + * You should have received a copy of the GNU General Public License
31098 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31102 + * sysfs interface and lifetime management
31103 + * they are necessary regardless sysfs is disabled.
31106 +#include <linux/random.h>
31109 +unsigned long sysaufs_si_mask;
31110 +struct kset *sysaufs_kset;
31112 +#define AuSiAttr(_name) { \
31113 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31114 + .show = sysaufs_si_##_name, \
31117 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31118 +struct attribute *sysaufs_si_attrs[] = {
31119 + &sysaufs_si_attr_xi_path.attr,
31123 +static const struct sysfs_ops au_sbi_ops = {
31124 + .show = sysaufs_si_show
31127 +static struct kobj_type au_sbi_ktype = {
31128 + .release = au_si_free,
31129 + .sysfs_ops = &au_sbi_ops,
31130 + .default_attrs = sysaufs_si_attrs
31133 +/* ---------------------------------------------------------------------- */
31135 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31139 + sbinfo->si_kobj.kset = sysaufs_kset;
31140 + /* cf. sysaufs_name() */
31141 + err = kobject_init_and_add
31142 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31143 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31148 +void sysaufs_fin(void)
31150 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31151 + kset_unregister(sysaufs_kset);
31154 +int __init sysaufs_init(void)
31159 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31160 + } while (!sysaufs_si_mask);
31163 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31164 + if (unlikely(!sysaufs_kset))
31166 + err = PTR_ERR(sysaufs_kset);
31167 + if (IS_ERR(sysaufs_kset))
31169 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31170 + if (unlikely(err))
31171 + kset_unregister(sysaufs_kset);
31176 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31177 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31178 +++ linux/fs/aufs/sysaufs.h 2020-01-27 10:57:18.178871751 +0100
31180 +/* SPDX-License-Identifier: GPL-2.0 */
31182 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31184 + * This program, aufs is free software; you can redistribute it and/or modify
31185 + * it under the terms of the GNU General Public License as published by
31186 + * the Free Software Foundation; either version 2 of the License, or
31187 + * (at your option) any later version.
31189 + * This program is distributed in the hope that it will be useful,
31190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31192 + * GNU General Public License for more details.
31194 + * You should have received a copy of the GNU General Public License
31195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31199 + * sysfs interface and mount lifetime management
31202 +#ifndef __SYSAUFS_H__
31203 +#define __SYSAUFS_H__
31207 +#include <linux/sysfs.h>
31208 +#include "module.h"
31210 +struct super_block;
31213 +struct sysaufs_si_attr {
31214 + struct attribute attr;
31215 + int (*show)(struct seq_file *seq, struct super_block *sb);
31218 +/* ---------------------------------------------------------------------- */
31221 +extern unsigned long sysaufs_si_mask;
31222 +extern struct kset *sysaufs_kset;
31223 +extern struct attribute *sysaufs_si_attrs[];
31224 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31225 +int __init sysaufs_init(void);
31226 +void sysaufs_fin(void);
31228 +/* ---------------------------------------------------------------------- */
31230 +/* some people doesn't like to show a pointer in kernel */
31231 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31233 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31236 +#define SysaufsSiNamePrefix "si_"
31237 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31238 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31240 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31241 + sysaufs_si_id(sbinfo));
31245 +#ifdef CONFIG_SYSFS
31247 +extern struct attribute_group *sysaufs_attr_group;
31249 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31250 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31252 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31253 +#ifdef CONFIG_COMPAT
31254 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31257 +void sysaufs_br_init(struct au_branch *br);
31258 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31259 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31261 +#define sysaufs_brs_init() do {} while (0)
31264 +#define sysaufs_attr_group NULL
31266 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31267 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31268 + struct attribute *attr, char *buf)
31269 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31270 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31271 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31273 +static inline void sysaufs_brs_init(void)
31278 +#endif /* CONFIG_SYSFS */
31280 +#endif /* __KERNEL__ */
31281 +#endif /* __SYSAUFS_H__ */
31282 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31283 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31284 +++ linux/fs/aufs/sysfs.c 2020-01-27 10:57:18.178871751 +0100
31286 +// SPDX-License-Identifier: GPL-2.0
31288 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31290 + * This program, aufs is free software; you can redistribute it and/or modify
31291 + * it under the terms of the GNU General Public License as published by
31292 + * the Free Software Foundation; either version 2 of the License, or
31293 + * (at your option) any later version.
31295 + * This program is distributed in the hope that it will be useful,
31296 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31297 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31298 + * GNU General Public License for more details.
31300 + * You should have received a copy of the GNU General Public License
31301 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31305 + * sysfs interface
31308 +#include <linux/compat.h>
31309 +#include <linux/seq_file.h>
31312 +#ifdef CONFIG_AUFS_FS_MODULE
31313 +/* this entry violates the "one line per file" policy of sysfs */
31314 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31318 + static char *conf =
31319 +/* this file is generated at compiling */
31320 +#include "conf.str"
31323 + err = snprintf(buf, PAGE_SIZE, conf);
31324 + if (unlikely(err >= PAGE_SIZE))
31329 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31332 +static struct attribute *au_attr[] = {
31333 +#ifdef CONFIG_AUFS_FS_MODULE
31334 + &au_config_attr.attr,
31336 + NULL, /* need to NULL terminate the list of attributes */
31339 +static struct attribute_group sysaufs_attr_group_body = {
31343 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31345 +/* ---------------------------------------------------------------------- */
31347 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31351 + SiMustAnyLock(sb);
31354 + if (au_opt_test(au_mntflags(sb), XINO)) {
31355 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31356 + seq_putc(seq, '\n');
31362 + * the lifetime of branch is independent from the entry under sysfs.
31363 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31366 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31367 + aufs_bindex_t bindex, int idx)
31370 + struct path path;
31371 + struct dentry *root;
31372 + struct au_branch *br;
31373 + au_br_perm_str_t perm;
31375 + AuDbg("b%d\n", bindex);
31378 + root = sb->s_root;
31379 + di_read_lock_parent(root, !AuLock_IR);
31380 + br = au_sbr(sb, bindex);
31383 + case AuBrSysfs_BR:
31384 + path.mnt = au_br_mnt(br);
31385 + path.dentry = au_h_dptr(root, bindex);
31386 + err = au_seq_path(seq, &path);
31388 + au_optstr_br_perm(&perm, br->br_perm);
31389 + seq_printf(seq, "=%s\n", perm.a);
31392 + case AuBrSysfs_BRID:
31393 + seq_printf(seq, "%d\n", br->br_id);
31396 + di_read_unlock(root, !AuLock_IR);
31397 + if (unlikely(err || seq_has_overflowed(seq)))
31403 +/* ---------------------------------------------------------------------- */
31405 +static struct seq_file *au_seq(char *p, ssize_t len)
31407 + struct seq_file *seq;
31409 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31411 + /* mutex_init(&seq.lock); */
31414 + return seq; /* success */
31417 + seq = ERR_PTR(-ENOMEM);
31421 +#define SysaufsBr_PREFIX "br"
31422 +#define SysaufsBrid_PREFIX "brid"
31424 +/* todo: file size may exceed PAGE_SIZE */
31425 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31431 + aufs_bindex_t bbot;
31432 + struct au_sbinfo *sbinfo;
31433 + struct super_block *sb;
31434 + struct seq_file *seq;
31436 + struct attribute **cattr;
31438 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31439 + sb = sbinfo->si_sb;
31442 + * prevent a race condition between sysfs and aufs.
31443 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31444 + * prohibits maintaining the sysfs entries.
31445 + * hew we acquire read lock after sysfs_get_active_two().
31446 + * on the other hand, the remount process may maintain the sysfs/aufs
31447 + * entries after acquiring write lock.
31448 + * it can cause a deadlock.
31449 + * simply we gave up processing read here.
31452 + if (unlikely(!si_noflush_read_trylock(sb)))
31455 + seq = au_seq(buf, PAGE_SIZE);
31456 + err = PTR_ERR(seq);
31460 + name = (void *)attr->name;
31461 + cattr = sysaufs_si_attrs;
31463 + if (!strcmp(name, (*cattr)->name)) {
31464 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31471 + if (!strncmp(name, SysaufsBrid_PREFIX,
31472 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31473 + idx = AuBrSysfs_BRID;
31474 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31475 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31476 + sizeof(SysaufsBr_PREFIX) - 1)) {
31477 + idx = AuBrSysfs_BR;
31478 + name += sizeof(SysaufsBr_PREFIX) - 1;
31482 + err = kstrtol(name, 10, &l);
31484 + bbot = au_sbbot(sb);
31486 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31493 + err = seq->count;
31494 + /* sysfs limit */
31495 + if (unlikely(err == PAGE_SIZE))
31498 + au_kfree_rcu(seq);
31500 + si_read_unlock(sb);
31505 +/* ---------------------------------------------------------------------- */
31507 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31511 + aufs_bindex_t bindex, bbot;
31514 + struct seq_file *seq;
31515 + struct au_branch *br;
31517 + si_read_lock(sb, AuLock_FLUSH);
31518 + bbot = au_sbbot(sb);
31524 + buf = (void *)__get_free_page(GFP_NOFS);
31525 + if (unlikely(!buf))
31528 + seq = au_seq(buf, PAGE_SIZE);
31529 + err = PTR_ERR(seq);
31533 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31534 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31535 + /* VERIFY_WRITE */
31536 + err = !access_ok(arg, sizeof(*arg));
31537 + if (unlikely(err))
31540 + br = au_sbr(sb, bindex);
31541 + brid = br->br_id;
31542 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31543 + err = __put_user(brid, &arg->id);
31544 + if (unlikely(err))
31547 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31548 + err = __put_user(br->br_perm, &arg->perm);
31549 + if (unlikely(err))
31552 + err = au_seq_path(seq, &br->br_path);
31553 + if (unlikely(err))
31555 + seq_putc(seq, '\0');
31556 + if (!seq_has_overflowed(seq)) {
31557 + err = copy_to_user(arg->path, seq->buf, seq->count);
31559 + if (unlikely(err))
31566 + if (unlikely(err))
31570 + au_kfree_rcu(seq);
31572 + free_page((unsigned long)buf);
31574 + si_read_unlock(sb);
31578 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31580 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31583 +#ifdef CONFIG_COMPAT
31584 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31586 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31590 +/* ---------------------------------------------------------------------- */
31592 +void sysaufs_br_init(struct au_branch *br)
31595 + struct au_brsysfs *br_sysfs;
31596 + struct attribute *attr;
31598 + br_sysfs = br->br_sysfs;
31599 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31600 + attr = &br_sysfs->attr;
31601 + sysfs_attr_init(attr);
31602 + attr->name = br_sysfs->name;
31603 + attr->mode = 0444;
31608 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31610 + struct au_branch *br;
31611 + struct kobject *kobj;
31612 + struct au_brsysfs *br_sysfs;
31614 + aufs_bindex_t bbot;
31616 + if (!sysaufs_brs)
31619 + kobj = &au_sbi(sb)->si_kobj;
31620 + bbot = au_sbbot(sb);
31621 + for (; bindex <= bbot; bindex++) {
31622 + br = au_sbr(sb, bindex);
31623 + br_sysfs = br->br_sysfs;
31624 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31625 + sysfs_remove_file(kobj, &br_sysfs->attr);
31631 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31634 + aufs_bindex_t bbot;
31635 + struct kobject *kobj;
31636 + struct au_branch *br;
31637 + struct au_brsysfs *br_sysfs;
31639 + if (!sysaufs_brs)
31642 + kobj = &au_sbi(sb)->si_kobj;
31643 + bbot = au_sbbot(sb);
31644 + for (; bindex <= bbot; bindex++) {
31645 + br = au_sbr(sb, bindex);
31646 + br_sysfs = br->br_sysfs;
31647 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31648 + SysaufsBr_PREFIX "%d", bindex);
31649 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31650 + SysaufsBrid_PREFIX "%d", bindex);
31651 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31652 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31653 + if (unlikely(err))
31654 + pr_warn("failed %s under sysfs(%d)\n",
31655 + br_sysfs->name, err);
31660 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31661 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31662 +++ linux/fs/aufs/sysrq.c 2020-01-27 10:57:18.178871751 +0100
31664 +// SPDX-License-Identifier: GPL-2.0
31666 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31668 + * This program, aufs is free software; you can redistribute it and/or modify
31669 + * it under the terms of the GNU General Public License as published by
31670 + * the Free Software Foundation; either version 2 of the License, or
31671 + * (at your option) any later version.
31673 + * This program is distributed in the hope that it will be useful,
31674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31676 + * GNU General Public License for more details.
31678 + * You should have received a copy of the GNU General Public License
31679 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31683 + * magic sysrq handler
31686 +/* #include <linux/sysrq.h> */
31687 +#include <linux/writeback.h>
31690 +/* ---------------------------------------------------------------------- */
31692 +static void sysrq_sb(struct super_block *sb)
31695 + struct au_sbinfo *sbinfo;
31696 + struct file *file;
31697 + struct hlist_bl_head *files;
31698 + struct hlist_bl_node *pos;
31699 + struct au_finfo *finfo;
31702 + plevel = au_plevel;
31703 + au_plevel = KERN_WARNING;
31705 + /* since we define pr_fmt, call printk directly */
31706 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31708 + sbinfo = au_sbi(sb);
31709 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31710 + pr("superblock\n");
31713 +#if 0 /* reserved */
31715 + int err, i, j, ndentry;
31716 + struct au_dcsub_pages dpages;
31717 + struct au_dpage *dpage;
31719 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31720 + if (unlikely(err))
31722 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31724 + for (i = 0; i < dpages.ndpage; i++) {
31725 + dpage = dpages.dpages + i;
31726 + ndentry = dpage->ndentry;
31727 + for (j = 0; j < ndentry; j++)
31728 + au_dpri_dentry(dpage->dentries[j]);
31730 + au_dpages_free(&dpages);
31734 + pr("isolated inode\n");
31735 + spin_lock(&sb->s_inode_list_lock);
31736 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31737 + spin_lock(&i->i_lock);
31738 + if (hlist_empty(&i->i_dentry))
31739 + au_dpri_inode(i);
31740 + spin_unlock(&i->i_lock);
31742 + spin_unlock(&sb->s_inode_list_lock);
31745 + files = &au_sbi(sb)->si_files;
31746 + hlist_bl_lock(files);
31747 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31750 + file = finfo->fi_file;
31751 + mode = file_inode(file)->i_mode;
31752 + if (!special_file(mode))
31753 + au_dpri_file(file);
31755 + hlist_bl_unlock(files);
31759 + au_plevel = plevel;
31762 +/* ---------------------------------------------------------------------- */
31764 +/* module parameter */
31765 +static char *aufs_sysrq_key = "a";
31766 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31767 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31769 +static void au_sysrq(int key __maybe_unused)
31771 + struct au_sbinfo *sbinfo;
31772 + struct hlist_bl_node *pos;
31775 + au_sbilist_lock();
31776 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31777 + sysrq_sb(sbinfo->si_sb);
31778 + au_sbilist_unlock();
31782 +static struct sysrq_key_op au_sysrq_op = {
31783 + .handler = au_sysrq,
31784 + .help_msg = "Aufs",
31785 + .action_msg = "Aufs",
31786 + .enable_mask = SYSRQ_ENABLE_DUMP
31789 +/* ---------------------------------------------------------------------- */
31791 +int __init au_sysrq_init(void)
31797 + key = *aufs_sysrq_key;
31798 + if ('a' <= key && key <= 'z')
31799 + err = register_sysrq_key(key, &au_sysrq_op);
31800 + if (unlikely(err))
31801 + pr_err("err %d, sysrq=%c\n", err, key);
31805 +void au_sysrq_fin(void)
31809 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31810 + if (unlikely(err))
31811 + pr_err("err %d (ignored)\n", err);
31813 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31814 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31815 +++ linux/fs/aufs/vdir.c 2020-01-27 10:57:18.178871751 +0100
31817 +// SPDX-License-Identifier: GPL-2.0
31819 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31821 + * This program, aufs is free software; you can redistribute it and/or modify
31822 + * it under the terms of the GNU General Public License as published by
31823 + * the Free Software Foundation; either version 2 of the License, or
31824 + * (at your option) any later version.
31826 + * This program is distributed in the hope that it will be useful,
31827 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31828 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31829 + * GNU General Public License for more details.
31831 + * You should have received a copy of the GNU General Public License
31832 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31836 + * virtual or vertical directory
31839 +#include <linux/iversion.h>
31842 +static unsigned int calc_size(int nlen)
31844 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31847 +static int set_deblk_end(union au_vdir_deblk_p *p,
31848 + union au_vdir_deblk_p *deblk_end)
31850 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31851 + p->de->de_str.len = 0;
31855 + return -1; /* error */
31858 +/* returns true or false */
31859 +static int is_deblk_end(union au_vdir_deblk_p *p,
31860 + union au_vdir_deblk_p *deblk_end)
31862 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31863 + return !p->de->de_str.len;
31867 +static unsigned char *last_deblk(struct au_vdir *vdir)
31869 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31872 +/* ---------------------------------------------------------------------- */
31874 +/* estimate the appropriate size for name hash table */
31875 +unsigned int au_rdhash_est(loff_t sz)
31883 + if (sz < AUFS_RDHASH_DEF)
31884 + n = AUFS_RDHASH_DEF;
31885 + /* pr_info("n %u\n", n); */
31890 + * the allocated memory has to be freed by
31891 + * au_nhash_wh_free() or au_nhash_de_free().
31893 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31895 + struct hlist_head *head;
31899 + sz = sizeof(*nhash->nh_head) * num_hash;
31900 + head = kmalloc(sz, gfp);
31902 + nhash->nh_num = num_hash;
31903 + nhash->nh_head = head;
31904 + for (u = 0; u < num_hash; u++)
31905 + INIT_HLIST_HEAD(head++);
31906 + return 0; /* success */
31912 +static void nhash_count(struct hlist_head *head)
31914 +#if 0 /* debugging */
31916 + struct hlist_node *pos;
31919 + hlist_for_each(pos, head)
31921 + pr_info("%lu\n", n);
31925 +static void au_nhash_wh_do_free(struct hlist_head *head)
31927 + struct au_vdir_wh *pos;
31928 + struct hlist_node *node;
31930 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31931 + au_kfree_rcu(pos);
31934 +static void au_nhash_de_do_free(struct hlist_head *head)
31936 + struct au_vdir_dehstr *pos;
31937 + struct hlist_node *node;
31939 + hlist_for_each_entry_safe(pos, node, head, hash)
31940 + au_cache_free_vdir_dehstr(pos);
31943 +static void au_nhash_do_free(struct au_nhash *nhash,
31944 + void (*free)(struct hlist_head *head))
31947 + struct hlist_head *head;
31949 + n = nhash->nh_num;
31953 + head = nhash->nh_head;
31954 + while (n-- > 0) {
31955 + nhash_count(head);
31958 + au_kfree_try_rcu(nhash->nh_head);
31961 +void au_nhash_wh_free(struct au_nhash *whlist)
31963 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31966 +static void au_nhash_de_free(struct au_nhash *delist)
31968 + au_nhash_do_free(delist, au_nhash_de_do_free);
31971 +/* ---------------------------------------------------------------------- */
31973 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31977 + unsigned int u, n;
31978 + struct hlist_head *head;
31979 + struct au_vdir_wh *pos;
31982 + n = whlist->nh_num;
31983 + head = whlist->nh_head;
31984 + for (u = 0; u < n; u++, head++)
31985 + hlist_for_each_entry(pos, head, wh_hash)
31986 + if (pos->wh_bindex == btgt && ++num > limit)
31991 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31992 + unsigned char *name,
31993 + unsigned int len)
31996 + /* const unsigned int magic_bit = 12; */
31998 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32005 + /* v = hash_long(v, magic_bit); */
32006 + v %= nhash->nh_num;
32007 + return nhash->nh_head + v;
32010 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32013 + return str->len == nlen && !memcmp(str->name, name, nlen);
32016 +/* returns found or not */
32017 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32019 + struct hlist_head *head;
32020 + struct au_vdir_wh *pos;
32021 + struct au_vdir_destr *str;
32023 + head = au_name_hash(whlist, name, nlen);
32024 + hlist_for_each_entry(pos, head, wh_hash) {
32025 + str = &pos->wh_str;
32026 + AuDbg("%.*s\n", str->len, str->name);
32027 + if (au_nhash_test_name(str, name, nlen))
32033 +/* returns found(true) or not */
32034 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32036 + struct hlist_head *head;
32037 + struct au_vdir_dehstr *pos;
32038 + struct au_vdir_destr *str;
32040 + head = au_name_hash(delist, name, nlen);
32041 + hlist_for_each_entry(pos, head, hash) {
32043 + AuDbg("%.*s\n", str->len, str->name);
32044 + if (au_nhash_test_name(str, name, nlen))
32050 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32051 + unsigned char d_type)
32053 +#ifdef CONFIG_AUFS_SHWH
32054 + wh->wh_ino = ino;
32055 + wh->wh_type = d_type;
32059 +/* ---------------------------------------------------------------------- */
32061 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32062 + unsigned int d_type, aufs_bindex_t bindex,
32063 + unsigned char shwh)
32066 + struct au_vdir_destr *str;
32067 + struct au_vdir_wh *wh;
32069 + AuDbg("%.*s\n", nlen, name);
32070 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32073 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32074 + if (unlikely(!wh))
32078 + wh->wh_bindex = bindex;
32080 + au_shwh_init_wh(wh, ino, d_type);
32081 + str = &wh->wh_str;
32083 + memcpy(str->name, name, nlen);
32084 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32091 +static int append_deblk(struct au_vdir *vdir)
32094 + unsigned long ul;
32095 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32096 + union au_vdir_deblk_p p, deblk_end;
32097 + unsigned char **o;
32100 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32101 + GFP_NOFS, /*may_shrink*/0);
32102 + if (unlikely(!o))
32105 + vdir->vd_deblk = o;
32106 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32108 + ul = vdir->vd_nblk++;
32109 + vdir->vd_deblk[ul] = p.deblk;
32110 + vdir->vd_last.ul = ul;
32111 + vdir->vd_last.p.deblk = p.deblk;
32112 + deblk_end.deblk = p.deblk + deblk_sz;
32113 + err = set_deblk_end(&p, &deblk_end);
32120 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32121 + unsigned int d_type, struct au_nhash *delist)
32125 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32126 + union au_vdir_deblk_p p, *room, deblk_end;
32127 + struct au_vdir_dehstr *dehstr;
32129 + p.deblk = last_deblk(vdir);
32130 + deblk_end.deblk = p.deblk + deblk_sz;
32131 + room = &vdir->vd_last.p;
32132 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32133 + || !is_deblk_end(room, &deblk_end));
32135 + sz = calc_size(nlen);
32136 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32137 + err = append_deblk(vdir);
32138 + if (unlikely(err))
32141 + p.deblk = last_deblk(vdir);
32142 + deblk_end.deblk = p.deblk + deblk_sz;
32144 + AuDebugOn(room->deblk != p.deblk);
32148 + dehstr = au_cache_alloc_vdir_dehstr();
32149 + if (unlikely(!dehstr))
32152 + dehstr->str = &room->de->de_str;
32153 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32154 + room->de->de_ino = ino;
32155 + room->de->de_type = d_type;
32156 + room->de->de_str.len = nlen;
32157 + memcpy(room->de->de_str.name, name, nlen);
32160 + room->deblk += sz;
32161 + if (unlikely(set_deblk_end(room, &deblk_end)))
32162 + err = append_deblk(vdir);
32169 +/* ---------------------------------------------------------------------- */
32171 +void au_vdir_free(struct au_vdir *vdir)
32173 + unsigned char **deblk;
32175 + deblk = vdir->vd_deblk;
32176 + while (vdir->vd_nblk--)
32177 + au_kfree_try_rcu(*deblk++);
32178 + au_kfree_try_rcu(vdir->vd_deblk);
32179 + au_cache_free_vdir(vdir);
32182 +static struct au_vdir *alloc_vdir(struct file *file)
32184 + struct au_vdir *vdir;
32185 + struct super_block *sb;
32188 + sb = file->f_path.dentry->d_sb;
32189 + SiMustAnyLock(sb);
32192 + vdir = au_cache_alloc_vdir();
32193 + if (unlikely(!vdir))
32196 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32197 + if (unlikely(!vdir->vd_deblk))
32200 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32201 + if (!vdir->vd_deblk_sz) {
32202 + /* estimate the appropriate size for deblk */
32203 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32204 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32206 + vdir->vd_nblk = 0;
32207 + vdir->vd_version = 0;
32208 + vdir->vd_jiffy = 0;
32209 + err = append_deblk(vdir);
32211 + return vdir; /* success */
32213 + au_kfree_try_rcu(vdir->vd_deblk);
32216 + au_cache_free_vdir(vdir);
32218 + vdir = ERR_PTR(err);
32222 +static int reinit_vdir(struct au_vdir *vdir)
32225 + union au_vdir_deblk_p p, deblk_end;
32227 + while (vdir->vd_nblk > 1) {
32228 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32229 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32232 + p.deblk = vdir->vd_deblk[0];
32233 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32234 + err = set_deblk_end(&p, &deblk_end);
32235 + /* keep vd_dblk_sz */
32236 + vdir->vd_last.ul = 0;
32237 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32238 + vdir->vd_version = 0;
32239 + vdir->vd_jiffy = 0;
32244 +/* ---------------------------------------------------------------------- */
32246 +#define AuFillVdir_CALLED 1
32247 +#define AuFillVdir_WHABLE (1 << 1)
32248 +#define AuFillVdir_SHWH (1 << 2)
32249 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32250 +#define au_fset_fillvdir(flags, name) \
32251 + do { (flags) |= AuFillVdir_##name; } while (0)
32252 +#define au_fclr_fillvdir(flags, name) \
32253 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32255 +#ifndef CONFIG_AUFS_SHWH
32256 +#undef AuFillVdir_SHWH
32257 +#define AuFillVdir_SHWH 0
32260 +struct fillvdir_arg {
32261 + struct dir_context ctx;
32262 + struct file *file;
32263 + struct au_vdir *vdir;
32264 + struct au_nhash delist;
32265 + struct au_nhash whlist;
32266 + aufs_bindex_t bindex;
32267 + unsigned int flags;
32271 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32272 + loff_t offset __maybe_unused, u64 h_ino,
32273 + unsigned int d_type)
32275 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32276 + char *name = (void *)__name;
32277 + struct super_block *sb;
32279 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32282 + sb = arg->file->f_path.dentry->d_sb;
32283 + au_fset_fillvdir(arg->flags, CALLED);
32285 + if (nlen <= AUFS_WH_PFX_LEN
32286 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32287 + if (test_known(&arg->delist, name, nlen)
32288 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32289 + goto out; /* already exists or whiteouted */
32291 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32293 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32294 + d_type = DT_UNKNOWN;
32295 + arg->err = append_de(arg->vdir, name, nlen, ino,
32296 + d_type, &arg->delist);
32298 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32299 + name += AUFS_WH_PFX_LEN;
32300 + nlen -= AUFS_WH_PFX_LEN;
32301 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32302 + goto out; /* already whiteouted */
32304 + ino = 0; /* just to suppress a warning */
32306 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32309 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32310 + d_type = DT_UNKNOWN;
32311 + arg->err = au_nhash_append_wh
32312 + (&arg->whlist, name, nlen, ino, d_type,
32313 + arg->bindex, shwh);
32319 + arg->vdir->vd_jiffy = jiffies;
32321 + AuTraceErr(arg->err);
32325 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32326 + struct au_nhash *whlist, struct au_nhash *delist)
32328 +#ifdef CONFIG_AUFS_SHWH
32330 + unsigned int nh, u;
32331 + struct hlist_head *head;
32332 + struct au_vdir_wh *pos;
32333 + struct hlist_node *n;
32335 + struct au_vdir_destr *destr;
32337 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32340 + o = p = (void *)__get_free_page(GFP_NOFS);
32341 + if (unlikely(!p))
32345 + nh = whlist->nh_num;
32346 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32347 + p += AUFS_WH_PFX_LEN;
32348 + for (u = 0; u < nh; u++) {
32349 + head = whlist->nh_head + u;
32350 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32351 + destr = &pos->wh_str;
32352 + memcpy(p, destr->name, destr->len);
32353 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32354 + pos->wh_ino, pos->wh_type, delist);
32355 + if (unlikely(err))
32360 + free_page((unsigned long)o);
32370 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32373 + unsigned int rdhash;
32375 + aufs_bindex_t bbot, bindex, btop;
32376 + unsigned char shwh;
32377 + struct file *hf, *file;
32378 + struct super_block *sb;
32380 + file = arg->file;
32381 + sb = file->f_path.dentry->d_sb;
32382 + SiMustAnyLock(sb);
32384 + rdhash = au_sbi(sb)->si_rdhash;
32386 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32387 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32388 + if (unlikely(err))
32390 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32391 + if (unlikely(err))
32397 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32399 + au_fset_fillvdir(arg->flags, SHWH);
32401 + btop = au_fbtop(file);
32402 + bbot = au_fbbot_dir(file);
32403 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32404 + hf = au_hf_dir(file, bindex);
32408 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32410 + if (unlikely(offset))
32413 + arg->bindex = bindex;
32414 + au_fclr_fillvdir(arg->flags, WHABLE);
32416 + || (bindex != bbot
32417 + && au_br_whable(au_sbr_perm(sb, bindex))))
32418 + au_fset_fillvdir(arg->flags, WHABLE);
32421 + au_fclr_fillvdir(arg->flags, CALLED);
32423 + err = vfsub_iterate_dir(hf, &arg->ctx);
32426 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32429 + * dir_relax() may be good for concurrency, but aufs should not
32430 + * use it since it will cause a lockdep problem.
32434 + if (!err && shwh)
32435 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32437 + au_nhash_wh_free(&arg->whlist);
32440 + au_nhash_de_free(&arg->delist);
32445 +static int read_vdir(struct file *file, int may_read)
32448 + unsigned long expire;
32449 + unsigned char do_read;
32450 + struct fillvdir_arg arg = {
32452 + .actor = fillvdir
32455 + struct inode *inode;
32456 + struct au_vdir *vdir, *allocated;
32459 + inode = file_inode(file);
32460 + IMustLock(inode);
32461 + IiMustWriteLock(inode);
32462 + SiMustAnyLock(inode->i_sb);
32464 + allocated = NULL;
32466 + expire = au_sbi(inode->i_sb)->si_rdcache;
32467 + vdir = au_ivdir(inode);
32470 + vdir = alloc_vdir(file);
32471 + err = PTR_ERR(vdir);
32472 + if (IS_ERR(vdir))
32475 + allocated = vdir;
32476 + } else if (may_read
32477 + && (!inode_eq_iversion(inode, vdir->vd_version)
32478 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32480 + err = reinit_vdir(vdir);
32481 + if (unlikely(err))
32486 + return 0; /* success */
32490 + err = au_do_read_vdir(&arg);
32492 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32493 + vdir->vd_version = inode_query_iversion(inode);
32494 + vdir->vd_last.ul = 0;
32495 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32497 + au_set_ivdir(inode, allocated);
32498 + } else if (allocated)
32499 + au_vdir_free(allocated);
32505 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32508 + unsigned long ul, n;
32509 + const unsigned int deblk_sz = src->vd_deblk_sz;
32511 + AuDebugOn(tgt->vd_nblk != 1);
32514 + if (tgt->vd_nblk < src->vd_nblk) {
32515 + unsigned char **p;
32517 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32518 + GFP_NOFS, /*may_shrink*/0);
32519 + if (unlikely(!p))
32521 + tgt->vd_deblk = p;
32524 + if (tgt->vd_deblk_sz != deblk_sz) {
32525 + unsigned char *p;
32527 + tgt->vd_deblk_sz = deblk_sz;
32528 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32529 + /*may_shrink*/1);
32530 + if (unlikely(!p))
32532 + tgt->vd_deblk[0] = p;
32534 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32535 + tgt->vd_version = src->vd_version;
32536 + tgt->vd_jiffy = src->vd_jiffy;
32538 + n = src->vd_nblk;
32539 + for (ul = 1; ul < n; ul++) {
32540 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32542 + if (unlikely(!tgt->vd_deblk[ul]))
32546 + tgt->vd_nblk = n;
32547 + tgt->vd_last.ul = tgt->vd_last.ul;
32548 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32549 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32550 + - src->vd_deblk[src->vd_last.ul];
32552 + return 0; /* success */
32555 + rerr = reinit_vdir(tgt);
32560 +int au_vdir_init(struct file *file)
32563 + struct inode *inode;
32564 + struct au_vdir *vdir_cache, *allocated;
32566 + /* test file->f_pos here instead of ctx->pos */
32567 + err = read_vdir(file, !file->f_pos);
32568 + if (unlikely(err))
32571 + allocated = NULL;
32572 + vdir_cache = au_fvdir_cache(file);
32573 + if (!vdir_cache) {
32574 + vdir_cache = alloc_vdir(file);
32575 + err = PTR_ERR(vdir_cache);
32576 + if (IS_ERR(vdir_cache))
32578 + allocated = vdir_cache;
32579 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32580 + /* test file->f_pos here instead of ctx->pos */
32581 + err = reinit_vdir(vdir_cache);
32582 + if (unlikely(err))
32585 + return 0; /* success */
32587 + inode = file_inode(file);
32588 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32590 + file->f_version = inode_query_iversion(inode);
32592 + au_set_fvdir_cache(file, allocated);
32593 + } else if (allocated)
32594 + au_vdir_free(allocated);
32600 +static loff_t calc_offset(struct au_vdir *vdir)
32603 + union au_vdir_deblk_p p;
32605 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32606 + offset = vdir->vd_last.p.deblk - p.deblk;
32607 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32611 +/* returns true or false */
32612 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32615 + unsigned int deblk_sz;
32616 + unsigned long ul, n;
32618 + union au_vdir_deblk_p p, deblk_end;
32619 + struct au_vdir *vdir_cache;
32622 + vdir_cache = au_fvdir_cache(file);
32623 + offset = calc_offset(vdir_cache);
32624 + AuDbg("offset %lld\n", offset);
32625 + if (ctx->pos == offset)
32628 + vdir_cache->vd_last.ul = 0;
32629 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32634 + deblk_sz = vdir_cache->vd_deblk_sz;
32635 + ul = div64_u64(ctx->pos, deblk_sz);
32636 + AuDbg("ul %lu\n", ul);
32637 + if (ul >= vdir_cache->vd_nblk)
32640 + n = vdir_cache->vd_nblk;
32641 + for (; ul < n; ul++) {
32642 + p.deblk = vdir_cache->vd_deblk[ul];
32643 + deblk_end.deblk = p.deblk + deblk_sz;
32645 + offset *= deblk_sz;
32646 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32649 + l = calc_size(p.de->de_str.len);
32653 + if (!is_deblk_end(&p, &deblk_end)) {
32655 + vdir_cache->vd_last.ul = ul;
32656 + vdir_cache->vd_last.p = p;
32664 + AuDbg("valid %d\n", !valid);
32668 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32670 + unsigned int l, deblk_sz;
32671 + union au_vdir_deblk_p deblk_end;
32672 + struct au_vdir *vdir_cache;
32673 + struct au_vdir_de *de;
32675 + if (!seek_vdir(file, ctx))
32678 + vdir_cache = au_fvdir_cache(file);
32679 + deblk_sz = vdir_cache->vd_deblk_sz;
32681 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32682 + deblk_end.deblk += deblk_sz;
32683 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32684 + de = vdir_cache->vd_last.p.de;
32685 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32686 + de->de_str.len, de->de_str.name, ctx->pos,
32687 + (unsigned long)de->de_ino, de->de_type);
32688 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32689 + de->de_str.len, de->de_ino,
32691 + /* todo: ignore the error caused by udba? */
32692 + /* return err; */
32696 + l = calc_size(de->de_str.len);
32697 + vdir_cache->vd_last.p.deblk += l;
32700 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32701 + vdir_cache->vd_last.ul++;
32702 + vdir_cache->vd_last.p.deblk
32703 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32704 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32713 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32714 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32715 +++ linux/fs/aufs/vfsub.c 2020-01-27 10:57:18.178871751 +0100
32717 +// SPDX-License-Identifier: GPL-2.0
32719 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32721 + * This program, aufs is free software; you can redistribute it and/or modify
32722 + * it under the terms of the GNU General Public License as published by
32723 + * the Free Software Foundation; either version 2 of the License, or
32724 + * (at your option) any later version.
32726 + * This program is distributed in the hope that it will be useful,
32727 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32728 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32729 + * GNU General Public License for more details.
32731 + * You should have received a copy of the GNU General Public License
32732 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32736 + * sub-routines for VFS
32739 +#include <linux/mnt_namespace.h>
32740 +#include <linux/namei.h>
32741 +#include <linux/nsproxy.h>
32742 +#include <linux/security.h>
32743 +#include <linux/splice.h>
32746 +#ifdef CONFIG_AUFS_BR_FUSE
32747 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32749 + if (!au_test_fuse(h_sb) || !au_userns)
32752 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32756 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32761 + down_read(&h_sb->s_umount);
32762 + err = __sync_filesystem(h_sb, wait);
32763 + up_read(&h_sb->s_umount);
32769 +/* ---------------------------------------------------------------------- */
32771 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32775 + struct super_block *h_sb;
32777 + /* for remote fs, leave work for its getattr or d_revalidate */
32778 + /* for bad i_attr fs, handle them in aufs_getattr() */
32779 + /* still some fs may acquire i_mutex. we need to skip them */
32783 + h_sb = h_path->dentry->d_sb;
32784 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32786 + err = vfsub_getattr(h_path, &st);
32791 +/* ---------------------------------------------------------------------- */
32793 +struct file *vfsub_dentry_open(struct path *path, int flags)
32795 + struct file *file;
32797 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32799 + if (!IS_ERR_OR_NULL(file)
32800 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32801 + i_readcount_inc(d_inode(path->dentry));
32806 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32808 + struct file *file;
32811 + file = filp_open(path,
32812 + oflags /* | __FMODE_NONOTIFY */,
32815 + if (IS_ERR(file))
32817 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32824 + * Ideally this function should call VFS:do_last() in order to keep all its
32825 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32826 + * structure such as nameidata. This is a second (or third) best approach.
32827 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32829 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32830 + struct vfsub_aopen_args *args)
32833 + struct au_branch *br = args->br;
32834 + struct file *file = args->file;
32835 + /* copied from linux/fs/namei.c:atomic_open() */
32836 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32839 + AuDebugOn(!dir->i_op->atomic_open);
32841 + err = au_br_test_oflag(args->open_flag, br);
32842 + if (unlikely(err))
32845 + au_lcnt_inc(&br->br_nfiles);
32846 + file->f_path.dentry = DENTRY_NOT_SET;
32847 + file->f_path.mnt = au_br_mnt(br);
32848 + AuDbg("%ps\n", dir->i_op->atomic_open);
32849 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32850 + args->create_mode);
32851 + if (unlikely(err < 0)) {
32852 + au_lcnt_dec(&br->br_nfiles);
32856 + /* temporary workaround for nfsv4 branch */
32857 + if (au_test_nfs(dir->i_sb))
32858 + nfs_mark_for_revalidate(dir);
32860 + if (file->f_mode & FMODE_CREATED)
32861 + fsnotify_create(dir, dentry);
32862 + if (!(file->f_mode & FMODE_OPENED)) {
32863 + au_lcnt_dec(&br->br_nfiles);
32867 + /* todo: call VFS:may_open() here */
32868 + /* todo: ima_file_check() too? */
32869 + if (!err && (args->open_flag & __FMODE_EXEC))
32870 + err = deny_write_access(file);
32872 + fsnotify_open(file);
32874 + au_lcnt_dec(&br->br_nfiles);
32875 + /* note that the file is created and still opened */
32881 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32885 + err = kern_path(name, flags, path);
32886 + if (!err && d_is_positive(path->dentry))
32887 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32891 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32892 + struct dentry *parent, int len)
32894 + struct path path = {
32898 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32899 + if (IS_ERR(path.dentry))
32901 + if (d_is_positive(path.dentry))
32902 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32905 + AuTraceErrPtr(path.dentry);
32906 + return path.dentry;
32909 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32912 + struct path path = {
32916 + /* VFS checks it too, but by WARN_ON_ONCE() */
32917 + IMustLock(d_inode(parent));
32919 + path.dentry = lookup_one_len(name, parent, len);
32920 + if (IS_ERR(path.dentry))
32922 + if (d_is_positive(path.dentry))
32923 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32926 + AuTraceErrPtr(path.dentry);
32927 + return path.dentry;
32930 +void vfsub_call_lkup_one(void *args)
32932 + struct vfsub_lkup_one_args *a = args;
32933 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32936 +/* ---------------------------------------------------------------------- */
32938 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32939 + struct dentry *d2, struct au_hinode *hdir2)
32941 + struct dentry *d;
32944 + d = lock_rename(d1, d2);
32946 + au_hn_suspend(hdir1);
32947 + if (hdir1 != hdir2)
32948 + au_hn_suspend(hdir2);
32953 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32954 + struct dentry *d2, struct au_hinode *hdir2)
32956 + au_hn_resume(hdir1);
32957 + if (hdir1 != hdir2)
32958 + au_hn_resume(hdir2);
32960 + unlock_rename(d1, d2);
32964 +/* ---------------------------------------------------------------------- */
32966 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32969 + struct dentry *d;
32973 + d = path->dentry;
32974 + path->dentry = d->d_parent;
32975 + err = security_path_mknod(path, d, mode, 0);
32976 + path->dentry = d;
32977 + if (unlikely(err))
32981 + err = vfs_create(dir, path->dentry, mode, want_excl);
32984 + struct path tmp = *path;
32987 + vfsub_update_h_iattr(&tmp, &did);
32989 + tmp.dentry = path->dentry->d_parent;
32990 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32999 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33002 + struct dentry *d;
33006 + d = path->dentry;
33007 + path->dentry = d->d_parent;
33008 + err = security_path_symlink(path, d, symname);
33009 + path->dentry = d;
33010 + if (unlikely(err))
33014 + err = vfs_symlink(dir, path->dentry, symname);
33017 + struct path tmp = *path;
33020 + vfsub_update_h_iattr(&tmp, &did);
33022 + tmp.dentry = path->dentry->d_parent;
33023 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33032 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33035 + struct dentry *d;
33039 + d = path->dentry;
33040 + path->dentry = d->d_parent;
33041 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33042 + path->dentry = d;
33043 + if (unlikely(err))
33047 + err = vfs_mknod(dir, path->dentry, mode, dev);
33050 + struct path tmp = *path;
33053 + vfsub_update_h_iattr(&tmp, &did);
33055 + tmp.dentry = path->dentry->d_parent;
33056 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33065 +static int au_test_nlink(struct inode *inode)
33067 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33069 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33070 + || inode->i_nlink < link_max)
33075 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33076 + struct inode **delegated_inode)
33079 + struct dentry *d;
33083 + err = au_test_nlink(d_inode(src_dentry));
33084 + if (unlikely(err))
33087 + /* we don't call may_linkat() */
33088 + d = path->dentry;
33089 + path->dentry = d->d_parent;
33090 + err = security_path_link(src_dentry, path, d);
33091 + path->dentry = d;
33092 + if (unlikely(err))
33096 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33099 + struct path tmp = *path;
33102 + /* fuse has different memory inode for the same inumber */
33103 + vfsub_update_h_iattr(&tmp, &did);
33105 + tmp.dentry = path->dentry->d_parent;
33106 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33107 + tmp.dentry = src_dentry;
33108 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33117 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33118 + struct inode *dir, struct path *path,
33119 + struct inode **delegated_inode, unsigned int flags)
33122 + struct path tmp = {
33125 + struct dentry *d;
33128 + IMustLock(src_dir);
33130 + d = path->dentry;
33131 + path->dentry = d->d_parent;
33132 + tmp.dentry = src_dentry->d_parent;
33133 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33134 + path->dentry = d;
33135 + if (unlikely(err))
33139 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33140 + delegated_inode, flags);
33145 + tmp.dentry = d->d_parent;
33146 + vfsub_update_h_iattr(&tmp, &did);
33148 + tmp.dentry = src_dentry;
33149 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33150 + tmp.dentry = src_dentry->d_parent;
33151 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33160 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33163 + struct dentry *d;
33167 + d = path->dentry;
33168 + path->dentry = d->d_parent;
33169 + err = security_path_mkdir(path, d, mode);
33170 + path->dentry = d;
33171 + if (unlikely(err))
33175 + err = vfs_mkdir(dir, path->dentry, mode);
33178 + struct path tmp = *path;
33181 + vfsub_update_h_iattr(&tmp, &did);
33183 + tmp.dentry = path->dentry->d_parent;
33184 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33193 +int vfsub_rmdir(struct inode *dir, struct path *path)
33196 + struct dentry *d;
33200 + d = path->dentry;
33201 + path->dentry = d->d_parent;
33202 + err = security_path_rmdir(path, d);
33203 + path->dentry = d;
33204 + if (unlikely(err))
33208 + err = vfs_rmdir(dir, path->dentry);
33211 + struct path tmp = {
33212 + .dentry = path->dentry->d_parent,
33216 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33223 +/* ---------------------------------------------------------------------- */
33225 +/* todo: support mmap_sem? */
33226 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33232 + err = vfs_read(file, ubuf, count, ppos);
33235 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33239 +/* todo: kernel_read()? */
33240 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33244 + mm_segment_t oldfs;
33251 + oldfs = get_fs();
33252 + set_fs(KERNEL_DS);
33253 + err = vfsub_read_u(file, buf.u, count, ppos);
33258 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33264 + err = vfs_write(file, ubuf, count, ppos);
33267 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33271 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33274 + mm_segment_t oldfs;
33277 + const char __user *u;
33281 + oldfs = get_fs();
33282 + set_fs(KERNEL_DS);
33283 + err = vfsub_write_u(file, buf.u, count, ppos);
33288 +int vfsub_flush(struct file *file, fl_owner_t id)
33293 + if (file->f_op->flush) {
33294 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33295 + err = file->f_op->flush(file, id);
33298 + err = file->f_op->flush(file, id);
33302 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33308 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33312 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33315 + err = iterate_dir(file, ctx);
33318 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33323 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33324 + struct pipe_inode_info *pipe, size_t len,
33325 + unsigned int flags)
33330 + err = do_splice_to(in, ppos, pipe, len, flags);
33332 + file_accessed(in);
33334 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33338 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33339 + loff_t *ppos, size_t len, unsigned int flags)
33344 + err = do_splice_from(pipe, out, ppos, len, flags);
33347 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33351 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33355 + /* file can be NULL */
33357 + err = vfs_fsync(file, datasync);
33361 + AuDebugOn(!file);
33362 + path = &file->f_path;
33364 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33369 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33370 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33371 + struct file *h_file)
33374 + struct inode *h_inode;
33375 + struct super_block *h_sb;
33378 + err = vfsub_truncate(h_path, length);
33382 + h_inode = d_inode(h_path->dentry);
33383 + h_sb = h_inode->i_sb;
33385 + sb_start_write(h_sb);
33387 + err = locks_verify_truncate(h_inode, h_file, length);
33389 + err = security_path_truncate(h_path);
33392 + err = do_truncate(h_path->dentry, length, attr, h_file);
33396 + sb_end_write(h_sb);
33403 +/* ---------------------------------------------------------------------- */
33405 +struct au_vfsub_mkdir_args {
33407 + struct inode *dir;
33408 + struct path *path;
33412 +static void au_call_vfsub_mkdir(void *args)
33414 + struct au_vfsub_mkdir_args *a = args;
33415 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33418 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33420 + int err, do_sio, wkq_err;
33422 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33425 + err = vfsub_mkdir(dir, path, mode);
33428 + struct au_vfsub_mkdir_args args = {
33434 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33435 + if (unlikely(wkq_err))
33442 +struct au_vfsub_rmdir_args {
33444 + struct inode *dir;
33445 + struct path *path;
33448 +static void au_call_vfsub_rmdir(void *args)
33450 + struct au_vfsub_rmdir_args *a = args;
33451 + *a->errp = vfsub_rmdir(a->dir, a->path);
33454 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33456 + int err, do_sio, wkq_err;
33458 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33461 + err = vfsub_rmdir(dir, path);
33464 + struct au_vfsub_rmdir_args args = {
33469 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33470 + if (unlikely(wkq_err))
33477 +/* ---------------------------------------------------------------------- */
33479 +struct notify_change_args {
33481 + struct path *path;
33482 + struct iattr *ia;
33483 + struct inode **delegated_inode;
33486 +static void call_notify_change(void *args)
33488 + struct notify_change_args *a = args;
33489 + struct inode *h_inode;
33491 + h_inode = d_inode(a->path->dentry);
33492 + IMustLock(h_inode);
33494 + *a->errp = -EPERM;
33495 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33497 + *a->errp = notify_change(a->path->dentry, a->ia,
33498 + a->delegated_inode);
33501 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33503 + AuTraceErr(*a->errp);
33506 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33507 + struct inode **delegated_inode)
33510 + struct notify_change_args args = {
33514 + .delegated_inode = delegated_inode
33517 + call_notify_change(&args);
33522 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33523 + struct inode **delegated_inode)
33525 + int err, wkq_err;
33526 + struct notify_change_args args = {
33530 + .delegated_inode = delegated_inode
33533 + wkq_err = au_wkq_wait(call_notify_change, &args);
33534 + if (unlikely(wkq_err))
33540 +/* ---------------------------------------------------------------------- */
33542 +struct unlink_args {
33544 + struct inode *dir;
33545 + struct path *path;
33546 + struct inode **delegated_inode;
33549 +static void call_unlink(void *args)
33551 + struct unlink_args *a = args;
33552 + struct dentry *d = a->path->dentry;
33553 + struct inode *h_inode;
33554 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33555 + && au_dcount(d) == 1);
33557 + IMustLock(a->dir);
33559 + a->path->dentry = d->d_parent;
33560 + *a->errp = security_path_unlink(a->path, d);
33561 + a->path->dentry = d;
33562 + if (unlikely(*a->errp))
33565 + if (!stop_sillyrename)
33568 + if (d_is_positive(d)) {
33569 + h_inode = d_inode(d);
33574 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33577 + struct path tmp = {
33578 + .dentry = d->d_parent,
33579 + .mnt = a->path->mnt
33581 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33584 + if (!stop_sillyrename)
33589 + AuTraceErr(*a->errp);
33593 + * @dir: must be locked.
33594 + * @dentry: target dentry.
33596 +int vfsub_unlink(struct inode *dir, struct path *path,
33597 + struct inode **delegated_inode, int force)
33600 + struct unlink_args args = {
33604 + .delegated_inode = delegated_inode
33608 + call_unlink(&args);
33612 + wkq_err = au_wkq_wait(call_unlink, &args);
33613 + if (unlikely(wkq_err))
33619 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33620 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33621 +++ linux/fs/aufs/vfsub.h 2020-01-27 10:57:18.178871751 +0100
33623 +/* SPDX-License-Identifier: GPL-2.0 */
33625 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33627 + * This program, aufs is free software; you can redistribute it and/or modify
33628 + * it under the terms of the GNU General Public License as published by
33629 + * the Free Software Foundation; either version 2 of the License, or
33630 + * (at your option) any later version.
33632 + * This program is distributed in the hope that it will be useful,
33633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33635 + * GNU General Public License for more details.
33637 + * You should have received a copy of the GNU General Public License
33638 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33642 + * sub-routines for VFS
33645 +#ifndef __AUFS_VFSUB_H__
33646 +#define __AUFS_VFSUB_H__
33650 +#include <linux/fs.h>
33651 +#include <linux/mount.h>
33652 +#include <linux/posix_acl.h>
33653 +#include <linux/xattr.h>
33654 +#include "debug.h"
33656 +/* copied from linux/fs/internal.h */
33657 +/* todo: BAD approach!! */
33658 +extern void __mnt_drop_write(struct vfsmount *);
33659 +extern struct file *alloc_empty_file(int, const struct cred *);
33661 +/* ---------------------------------------------------------------------- */
33663 +/* lock subclass for lower inode */
33664 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33665 +/* reduce? gave up. */
33667 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33668 + AuLsc_I_PARENT, /* lower inode, parent first */
33669 + AuLsc_I_PARENT2, /* copyup dirs */
33670 + AuLsc_I_PARENT3, /* copyup wh */
33676 +/* to debug easier, do not make them inlined functions */
33677 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33678 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33680 +/* ---------------------------------------------------------------------- */
33682 +static inline void vfsub_drop_nlink(struct inode *inode)
33684 + AuDebugOn(!inode->i_nlink);
33685 + drop_nlink(inode);
33688 +static inline void vfsub_dead_dir(struct inode *inode)
33690 + AuDebugOn(!S_ISDIR(inode->i_mode));
33691 + inode->i_flags |= S_DEAD;
33692 + clear_nlink(inode);
33695 +static inline int vfsub_native_ro(struct inode *inode)
33697 + return sb_rdonly(inode->i_sb)
33698 + || IS_RDONLY(inode)
33699 + /* || IS_APPEND(inode) */
33700 + || IS_IMMUTABLE(inode);
33703 +#ifdef CONFIG_AUFS_BR_FUSE
33704 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33706 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33709 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33711 +/* ---------------------------------------------------------------------- */
33713 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33714 +struct file *vfsub_dentry_open(struct path *path, int flags);
33715 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33717 +struct vfsub_aopen_args {
33718 + struct file *file;
33719 + unsigned int open_flag;
33720 + umode_t create_mode;
33721 + struct au_branch *br;
33723 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33724 + struct vfsub_aopen_args *args);
33725 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33727 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33728 + struct dentry *parent, int len);
33729 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33732 +struct vfsub_lkup_one_args {
33733 + struct dentry **errp;
33734 + struct qstr *name;
33735 + struct dentry *parent;
33738 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33739 + struct dentry *parent)
33741 + return vfsub_lookup_one_len(name->name, parent, name->len);
33744 +void vfsub_call_lkup_one(void *args);
33746 +/* ---------------------------------------------------------------------- */
33748 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33753 + err = mnt_want_write(mnt);
33758 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33761 + mnt_drop_write(mnt);
33765 +#if 0 /* reserved */
33766 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33769 + mnt_drop_write_file(file);
33774 +/* ---------------------------------------------------------------------- */
33777 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33778 + struct dentry *d2, struct au_hinode *hdir2);
33779 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33780 + struct dentry *d2, struct au_hinode *hdir2);
33782 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33784 +int vfsub_symlink(struct inode *dir, struct path *path,
33785 + const char *symname);
33786 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33787 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33788 + struct path *path, struct inode **delegated_inode);
33789 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33790 + struct inode *hdir, struct path *path,
33791 + struct inode **delegated_inode, unsigned int flags);
33792 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33793 +int vfsub_rmdir(struct inode *dir, struct path *path);
33795 +/* ---------------------------------------------------------------------- */
33797 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33799 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33801 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33803 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33805 +int vfsub_flush(struct file *file, fl_owner_t id);
33806 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33808 +static inline loff_t vfsub_f_size_read(struct file *file)
33810 + return i_size_read(file_inode(file));
33813 +static inline unsigned int vfsub_file_flags(struct file *file)
33815 + unsigned int flags;
33817 + spin_lock(&file->f_lock);
33818 + flags = file->f_flags;
33819 + spin_unlock(&file->f_lock);
33824 +static inline int vfsub_file_execed(struct file *file)
33826 + /* todo: direct access f_flags */
33827 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33830 +#if 0 /* reserved */
33831 +static inline void vfsub_file_accessed(struct file *h_file)
33833 + file_accessed(h_file);
33834 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33838 +#if 0 /* reserved */
33839 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33840 + struct dentry *h_dentry)
33842 + struct path h_path = {
33843 + .dentry = h_dentry,
33846 + touch_atime(&h_path);
33847 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33851 +static inline int vfsub_update_time(struct inode *h_inode,
33852 + struct timespec64 *ts, int flags)
33854 + return update_time(h_inode, ts, flags);
33855 + /* no vfsub_update_h_iattr() since we don't have struct path */
33858 +#ifdef CONFIG_FS_POSIX_ACL
33859 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33863 + err = posix_acl_chmod(h_inode, h_mode);
33864 + if (err == -EOPNOTSUPP)
33869 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33872 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33873 + struct pipe_inode_info *pipe, size_t len,
33874 + unsigned int flags);
33875 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33876 + loff_t *ppos, size_t len, unsigned int flags);
33878 +static inline long vfsub_truncate(struct path *path, loff_t length)
33883 + err = vfs_truncate(path, length);
33888 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33889 + struct file *h_file);
33890 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33893 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33896 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33902 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33908 +/* copy_file_range(2) is a systemcall */
33909 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33910 + struct file *dst, loff_t dst_pos,
33911 + size_t len, unsigned int flags)
33916 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33922 +/* ---------------------------------------------------------------------- */
33924 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33929 + err = vfs_llseek(file, offset, origin);
33934 +/* ---------------------------------------------------------------------- */
33936 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33937 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33938 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33939 + struct inode **delegated_inode);
33940 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33941 + struct inode **delegated_inode);
33942 +int vfsub_unlink(struct inode *dir, struct path *path,
33943 + struct inode **delegated_inode, int force);
33945 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33947 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33950 +/* ---------------------------------------------------------------------- */
33952 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33953 + const void *value, size_t size, int flags)
33958 + err = vfs_setxattr(dentry, name, value, size, flags);
33964 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33969 + err = vfs_removexattr(dentry, name);
33975 +#endif /* __KERNEL__ */
33976 +#endif /* __AUFS_VFSUB_H__ */
33977 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33978 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33979 +++ linux/fs/aufs/wbr_policy.c 2020-01-27 10:57:18.178871751 +0100
33981 +// SPDX-License-Identifier: GPL-2.0
33983 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33985 + * This program, aufs is free software; you can redistribute it and/or modify
33986 + * it under the terms of the GNU General Public License as published by
33987 + * the Free Software Foundation; either version 2 of the License, or
33988 + * (at your option) any later version.
33990 + * This program is distributed in the hope that it will be useful,
33991 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33992 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33993 + * GNU General Public License for more details.
33995 + * You should have received a copy of the GNU General Public License
33996 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34000 + * policies for selecting one among multiple writable branches
34003 +#include <linux/statfs.h>
34006 +/* subset of cpup_attr() */
34007 +static noinline_for_stack
34008 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34012 + struct inode *h_isrc;
34014 + h_isrc = d_inode(h_src);
34015 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34016 + ia.ia_mode = h_isrc->i_mode;
34017 + ia.ia_uid = h_isrc->i_uid;
34018 + ia.ia_gid = h_isrc->i_gid;
34019 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34020 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34021 + /* no delegation since it is just created */
34022 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34024 + /* is this nfs only? */
34025 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34026 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34027 + ia.ia_mode = h_isrc->i_mode;
34028 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34034 +#define AuCpdown_PARENT_OPQ 1
34035 +#define AuCpdown_WHED (1 << 1)
34036 +#define AuCpdown_MADE_DIR (1 << 2)
34037 +#define AuCpdown_DIROPQ (1 << 3)
34038 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34039 +#define au_fset_cpdown(flags, name) \
34040 + do { (flags) |= AuCpdown_##name; } while (0)
34041 +#define au_fclr_cpdown(flags, name) \
34042 + do { (flags) &= ~AuCpdown_##name; } while (0)
34044 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34045 + unsigned int *flags)
34048 + struct dentry *opq_dentry;
34050 + opq_dentry = au_diropq_create(dentry, bdst);
34051 + err = PTR_ERR(opq_dentry);
34052 + if (IS_ERR(opq_dentry))
34054 + dput(opq_dentry);
34055 + au_fset_cpdown(*flags, DIROPQ);
34061 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34062 + struct inode *dir, aufs_bindex_t bdst)
34065 + struct path h_path;
34066 + struct au_branch *br;
34068 + br = au_sbr(dentry->d_sb, bdst);
34069 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34070 + err = PTR_ERR(h_path.dentry);
34071 + if (IS_ERR(h_path.dentry))
34075 + if (d_is_positive(h_path.dentry)) {
34076 + h_path.mnt = au_br_mnt(br);
34077 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34080 + dput(h_path.dentry);
34086 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34087 + struct au_pin *pin,
34088 + struct dentry *h_parent, void *arg)
34091 + aufs_bindex_t bopq, btop;
34092 + struct path h_path;
34093 + struct dentry *parent;
34094 + struct inode *h_dir, *h_inode, *inode, *dir;
34095 + unsigned int *flags = arg;
34097 + btop = au_dbtop(dentry);
34098 + /* dentry is di-locked */
34099 + parent = dget_parent(dentry);
34100 + dir = d_inode(parent);
34101 + h_dir = d_inode(h_parent);
34102 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34103 + IMustLock(h_dir);
34105 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34106 + if (unlikely(err < 0))
34108 + h_path.dentry = au_h_dptr(dentry, bdst);
34109 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34110 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34111 + if (unlikely(err))
34113 + au_fset_cpdown(*flags, MADE_DIR);
34115 + bopq = au_dbdiropq(dentry);
34116 + au_fclr_cpdown(*flags, WHED);
34117 + au_fclr_cpdown(*flags, DIROPQ);
34118 + if (au_dbwh(dentry) == bdst)
34119 + au_fset_cpdown(*flags, WHED);
34120 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34121 + au_fset_cpdown(*flags, PARENT_OPQ);
34122 + h_inode = d_inode(h_path.dentry);
34123 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34124 + if (au_ftest_cpdown(*flags, WHED)) {
34125 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34126 + if (unlikely(err)) {
34127 + inode_unlock(h_inode);
34132 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34133 + inode_unlock(h_inode);
34134 + if (unlikely(err))
34137 + if (au_ftest_cpdown(*flags, WHED)) {
34138 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34139 + if (unlikely(err))
34143 + inode = d_inode(dentry);
34144 + if (au_ibbot(inode) < bdst)
34145 + au_set_ibbot(inode, bdst);
34146 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34147 + au_hi_flags(inode, /*isdir*/1));
34148 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34149 + goto out; /* success */
34153 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34154 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34155 + rerr = au_diropq_remove(dentry, bdst);
34156 + inode_unlock(h_inode);
34157 + if (unlikely(rerr)) {
34158 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34159 + dentry, bdst, rerr);
34165 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34166 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34167 + if (unlikely(rerr)) {
34168 + AuIOErr("failed removing %pd b%d (%d)\n",
34169 + dentry, bdst, rerr);
34174 + au_set_h_dptr(dentry, bdst, NULL);
34175 + if (au_dbbot(dentry) == bdst)
34176 + au_update_dbbot(dentry);
34182 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34185 + unsigned int flags;
34188 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34193 +/* ---------------------------------------------------------------------- */
34195 +/* policies for create */
34197 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34199 + int err, i, j, ndentry;
34200 + aufs_bindex_t bopq;
34201 + struct au_dcsub_pages dpages;
34202 + struct au_dpage *dpage;
34203 + struct dentry **dentries, *parent, *d;
34205 + err = au_dpages_init(&dpages, GFP_NOFS);
34206 + if (unlikely(err))
34208 + parent = dget_parent(dentry);
34209 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34210 + if (unlikely(err))
34214 + for (i = 0; i < dpages.ndpage; i++) {
34215 + dpage = dpages.dpages + i;
34216 + dentries = dpage->dentries;
34217 + ndentry = dpage->ndentry;
34218 + for (j = 0; j < ndentry; j++) {
34220 + di_read_lock_parent2(d, !AuLock_IR);
34221 + bopq = au_dbdiropq(d);
34222 + di_read_unlock(d, !AuLock_IR);
34223 + if (bopq >= 0 && bopq < err)
34230 + au_dpages_free(&dpages);
34235 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34237 + for (; bindex >= 0; bindex--)
34238 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34243 +/* top down parent */
34244 +static int au_wbr_create_tdp(struct dentry *dentry,
34245 + unsigned int flags __maybe_unused)
34248 + aufs_bindex_t btop, bindex;
34249 + struct super_block *sb;
34250 + struct dentry *parent, *h_parent;
34252 + sb = dentry->d_sb;
34253 + btop = au_dbtop(dentry);
34255 + if (!au_br_rdonly(au_sbr(sb, btop)))
34259 + parent = dget_parent(dentry);
34260 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34261 + h_parent = au_h_dptr(parent, bindex);
34262 + if (!h_parent || d_is_negative(h_parent))
34265 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34272 + /* bottom up here */
34273 + if (unlikely(err < 0)) {
34274 + err = au_wbr_bu(sb, btop - 1);
34276 + err = au_wbr_nonopq(dentry, err);
34280 + AuDbg("b%d\n", err);
34284 +/* ---------------------------------------------------------------------- */
34286 +/* an exception for the policy other than tdp */
34287 +static int au_wbr_create_exp(struct dentry *dentry)
34290 + aufs_bindex_t bwh, bdiropq;
34291 + struct dentry *parent;
34294 + bwh = au_dbwh(dentry);
34295 + parent = dget_parent(dentry);
34296 + bdiropq = au_dbdiropq(parent);
34298 + if (bdiropq >= 0)
34299 + err = min(bdiropq, bwh);
34302 + AuDbg("%d\n", err);
34303 + } else if (bdiropq >= 0) {
34305 + AuDbg("%d\n", err);
34310 + err = au_wbr_nonopq(dentry, err);
34312 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34315 + AuDbg("%d\n", err);
34319 +/* ---------------------------------------------------------------------- */
34322 +static int au_wbr_create_init_rr(struct super_block *sb)
34326 + err = au_wbr_bu(sb, au_sbbot(sb));
34327 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34330 + AuDbg("b%d\n", err);
34334 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34338 + aufs_bindex_t bindex, bbot;
34339 + struct super_block *sb;
34342 + err = au_wbr_create_exp(dentry);
34346 + sb = dentry->d_sb;
34347 + next = &au_sbi(sb)->si_wbr_rr_next;
34348 + bbot = au_sbbot(sb);
34350 + for (bindex = 0; bindex <= bbot; bindex++) {
34351 + if (!au_ftest_wbr(flags, DIR)) {
34352 + err = atomic_dec_return(next) + 1;
34353 + /* modulo for 0 is meaningless */
34354 + if (unlikely(!err))
34355 + err = atomic_dec_return(next) + 1;
34357 + err = atomic_read(next);
34358 + AuDbg("%d\n", err);
34361 + AuDbg("%d\n", err);
34362 + if (!au_br_rdonly(au_sbr(sb, err)))
34368 + err = au_wbr_nonopq(dentry, err);
34371 + AuDbg("%d\n", err);
34375 +/* ---------------------------------------------------------------------- */
34377 +/* most free space */
34378 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34380 + struct super_block *sb;
34381 + struct au_branch *br;
34382 + struct au_wbr_mfs *mfs;
34383 + struct dentry *h_parent;
34384 + aufs_bindex_t bindex, bbot;
34386 + unsigned long long b, bavail;
34387 + struct path h_path;
34388 + /* reduce the stack usage */
34389 + struct kstatfs *st;
34391 + st = kmalloc(sizeof(*st), GFP_NOFS);
34392 + if (unlikely(!st)) {
34393 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34398 + sb = dentry->d_sb;
34399 + mfs = &au_sbi(sb)->si_wbr_mfs;
34400 + MtxMustLock(&mfs->mfs_lock);
34401 + mfs->mfs_bindex = -EROFS;
34402 + mfs->mfsrr_bytes = 0;
34405 + bbot = au_sbbot(sb);
34407 + bindex = au_dbtop(parent);
34408 + bbot = au_dbtaildir(parent);
34411 + for (; bindex <= bbot; bindex++) {
34413 + h_parent = au_h_dptr(parent, bindex);
34414 + if (!h_parent || d_is_negative(h_parent))
34417 + br = au_sbr(sb, bindex);
34418 + if (au_br_rdonly(br))
34421 + /* sb->s_root for NFS is unreliable */
34422 + h_path.mnt = au_br_mnt(br);
34423 + h_path.dentry = h_path.mnt->mnt_root;
34424 + err = vfs_statfs(&h_path, st);
34425 + if (unlikely(err)) {
34426 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34430 + /* when the available size is equal, select the lower one */
34431 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34432 + || sizeof(b) < sizeof(st->f_bsize));
34433 + b = st->f_bavail * st->f_bsize;
34434 + br->br_wbr->wbr_bytes = b;
34435 + if (b >= bavail) {
34437 + mfs->mfs_bindex = bindex;
34438 + mfs->mfs_jiffy = jiffies;
34442 + mfs->mfsrr_bytes = bavail;
34443 + AuDbg("b%d\n", mfs->mfs_bindex);
34444 + au_kfree_rcu(st);
34447 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34450 + struct dentry *parent;
34451 + struct super_block *sb;
34452 + struct au_wbr_mfs *mfs;
34454 + err = au_wbr_create_exp(dentry);
34458 + sb = dentry->d_sb;
34460 + if (au_ftest_wbr(flags, PARENT))
34461 + parent = dget_parent(dentry);
34462 + mfs = &au_sbi(sb)->si_wbr_mfs;
34463 + mutex_lock(&mfs->mfs_lock);
34464 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34465 + || mfs->mfs_bindex < 0
34466 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34467 + au_mfs(dentry, parent);
34468 + mutex_unlock(&mfs->mfs_lock);
34469 + err = mfs->mfs_bindex;
34473 + err = au_wbr_nonopq(dentry, err);
34476 + AuDbg("b%d\n", err);
34480 +static int au_wbr_create_init_mfs(struct super_block *sb)
34482 + struct au_wbr_mfs *mfs;
34484 + mfs = &au_sbi(sb)->si_wbr_mfs;
34485 + mutex_init(&mfs->mfs_lock);
34486 + mfs->mfs_jiffy = 0;
34487 + mfs->mfs_bindex = -EROFS;
34492 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34494 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34498 +/* ---------------------------------------------------------------------- */
34500 +/* top down regardless parent, and then mfs */
34501 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34502 + unsigned int flags __maybe_unused)
34505 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34506 + unsigned long long watermark;
34507 + struct super_block *sb;
34508 + struct au_wbr_mfs *mfs;
34509 + struct au_branch *br;
34510 + struct dentry *parent;
34512 + sb = dentry->d_sb;
34513 + mfs = &au_sbi(sb)->si_wbr_mfs;
34514 + mutex_lock(&mfs->mfs_lock);
34515 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34516 + || mfs->mfs_bindex < 0)
34517 + au_mfs(dentry, /*parent*/NULL);
34518 + watermark = mfs->mfsrr_watermark;
34519 + bmfs = mfs->mfs_bindex;
34520 + mutex_unlock(&mfs->mfs_lock);
34522 + /* another style of au_wbr_create_exp() */
34523 + bwh = au_dbwh(dentry);
34524 + parent = dget_parent(dentry);
34525 + btail = au_dbtaildir(parent);
34526 + if (bwh >= 0 && bwh < btail)
34529 + err = au_wbr_nonopq(dentry, btail);
34530 + if (unlikely(err < 0))
34534 + for (bindex = 0; bindex <= btail; bindex++) {
34535 + br = au_sbr(sb, bindex);
34536 + if (au_br_rdonly(br))
34538 + if (br->br_wbr->wbr_bytes > watermark) {
34549 + AuDbg("b%d\n", err);
34553 +/* ---------------------------------------------------------------------- */
34555 +/* most free space and then round robin */
34556 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34559 + struct au_wbr_mfs *mfs;
34561 + err = au_wbr_create_mfs(dentry, flags);
34563 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34564 + mutex_lock(&mfs->mfs_lock);
34565 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34566 + err = au_wbr_create_rr(dentry, flags);
34567 + mutex_unlock(&mfs->mfs_lock);
34570 + AuDbg("b%d\n", err);
34574 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34578 + au_wbr_create_init_mfs(sb); /* ignore */
34579 + err = au_wbr_create_init_rr(sb);
34584 +/* ---------------------------------------------------------------------- */
34586 +/* top down parent and most free space */
34587 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34590 + unsigned long long b;
34591 + aufs_bindex_t bindex, btop, bbot;
34592 + struct super_block *sb;
34593 + struct dentry *parent, *h_parent;
34594 + struct au_branch *br;
34596 + err = au_wbr_create_tdp(dentry, flags);
34597 + if (unlikely(err < 0))
34599 + parent = dget_parent(dentry);
34600 + btop = au_dbtop(parent);
34601 + bbot = au_dbtaildir(parent);
34602 + if (btop == bbot)
34603 + goto out_parent; /* success */
34605 + e2 = au_wbr_create_mfs(dentry, flags);
34607 + goto out_parent; /* success */
34609 + /* when the available size is equal, select upper one */
34610 + sb = dentry->d_sb;
34611 + br = au_sbr(sb, err);
34612 + b = br->br_wbr->wbr_bytes;
34613 + AuDbg("b%d, %llu\n", err, b);
34615 + for (bindex = btop; bindex <= bbot; bindex++) {
34616 + h_parent = au_h_dptr(parent, bindex);
34617 + if (!h_parent || d_is_negative(h_parent))
34620 + br = au_sbr(sb, bindex);
34621 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34622 + b = br->br_wbr->wbr_bytes;
34624 + AuDbg("b%d, %llu\n", err, b);
34629 + err = au_wbr_nonopq(dentry, err);
34634 + AuDbg("b%d\n", err);
34638 +/* ---------------------------------------------------------------------- */
34641 + * - top down parent
34642 + * - most free space with parent
34643 + * - most free space round-robin regardless parent
34645 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34648 + unsigned long long watermark;
34649 + struct super_block *sb;
34650 + struct au_branch *br;
34651 + struct au_wbr_mfs *mfs;
34653 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34654 + if (unlikely(err < 0))
34657 + sb = dentry->d_sb;
34658 + br = au_sbr(sb, err);
34659 + mfs = &au_sbi(sb)->si_wbr_mfs;
34660 + mutex_lock(&mfs->mfs_lock);
34661 + watermark = mfs->mfsrr_watermark;
34662 + mutex_unlock(&mfs->mfs_lock);
34663 + if (br->br_wbr->wbr_bytes < watermark)
34664 + /* regardless the parent dir */
34665 + err = au_wbr_create_mfsrr(dentry, flags);
34668 + AuDbg("b%d\n", err);
34672 +/* ---------------------------------------------------------------------- */
34674 +/* policies for copyup */
34676 +/* top down parent */
34677 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34679 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34682 +/* bottom up parent */
34683 +static int au_wbr_copyup_bup(struct dentry *dentry)
34686 + aufs_bindex_t bindex, btop;
34687 + struct dentry *parent, *h_parent;
34688 + struct super_block *sb;
34691 + sb = dentry->d_sb;
34692 + parent = dget_parent(dentry);
34693 + btop = au_dbtop(parent);
34694 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34695 + h_parent = au_h_dptr(parent, bindex);
34696 + if (!h_parent || d_is_negative(h_parent))
34699 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34706 + /* bottom up here */
34707 + if (unlikely(err < 0))
34708 + err = au_wbr_bu(sb, btop - 1);
34710 + AuDbg("b%d\n", err);
34715 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34719 + err = au_wbr_bu(dentry->d_sb, btop);
34720 + AuDbg("b%d\n", err);
34722 + err = au_wbr_nonopq(dentry, err);
34724 + AuDbg("b%d\n", err);
34728 +static int au_wbr_copyup_bu(struct dentry *dentry)
34731 + aufs_bindex_t btop;
34733 + btop = au_dbtop(dentry);
34734 + err = au_wbr_do_copyup_bu(dentry, btop);
34738 +/* ---------------------------------------------------------------------- */
34740 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34741 + [AuWbrCopyup_TDP] = {
34742 + .copyup = au_wbr_copyup_tdp
34744 + [AuWbrCopyup_BUP] = {
34745 + .copyup = au_wbr_copyup_bup
34747 + [AuWbrCopyup_BU] = {
34748 + .copyup = au_wbr_copyup_bu
34752 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34753 + [AuWbrCreate_TDP] = {
34754 + .create = au_wbr_create_tdp
34756 + [AuWbrCreate_RR] = {
34757 + .create = au_wbr_create_rr,
34758 + .init = au_wbr_create_init_rr
34760 + [AuWbrCreate_MFS] = {
34761 + .create = au_wbr_create_mfs,
34762 + .init = au_wbr_create_init_mfs,
34763 + .fin = au_wbr_create_fin_mfs
34765 + [AuWbrCreate_MFSV] = {
34766 + .create = au_wbr_create_mfs,
34767 + .init = au_wbr_create_init_mfs,
34768 + .fin = au_wbr_create_fin_mfs
34770 + [AuWbrCreate_MFSRR] = {
34771 + .create = au_wbr_create_mfsrr,
34772 + .init = au_wbr_create_init_mfsrr,
34773 + .fin = au_wbr_create_fin_mfs
34775 + [AuWbrCreate_MFSRRV] = {
34776 + .create = au_wbr_create_mfsrr,
34777 + .init = au_wbr_create_init_mfsrr,
34778 + .fin = au_wbr_create_fin_mfs
34780 + [AuWbrCreate_TDMFS] = {
34781 + .create = au_wbr_create_tdmfs,
34782 + .init = au_wbr_create_init_mfs,
34783 + .fin = au_wbr_create_fin_mfs
34785 + [AuWbrCreate_TDMFSV] = {
34786 + .create = au_wbr_create_tdmfs,
34787 + .init = au_wbr_create_init_mfs,
34788 + .fin = au_wbr_create_fin_mfs
34790 + [AuWbrCreate_PMFS] = {
34791 + .create = au_wbr_create_pmfs,
34792 + .init = au_wbr_create_init_mfs,
34793 + .fin = au_wbr_create_fin_mfs
34795 + [AuWbrCreate_PMFSV] = {
34796 + .create = au_wbr_create_pmfs,
34797 + .init = au_wbr_create_init_mfs,
34798 + .fin = au_wbr_create_fin_mfs
34800 + [AuWbrCreate_PMFSRR] = {
34801 + .create = au_wbr_create_pmfsrr,
34802 + .init = au_wbr_create_init_mfsrr,
34803 + .fin = au_wbr_create_fin_mfs
34805 + [AuWbrCreate_PMFSRRV] = {
34806 + .create = au_wbr_create_pmfsrr,
34807 + .init = au_wbr_create_init_mfsrr,
34808 + .fin = au_wbr_create_fin_mfs
34811 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34812 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34813 +++ linux/fs/aufs/whout.c 2020-01-27 10:57:18.178871751 +0100
34815 +// SPDX-License-Identifier: GPL-2.0
34817 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34819 + * This program, aufs is free software; you can redistribute it and/or modify
34820 + * it under the terms of the GNU General Public License as published by
34821 + * the Free Software Foundation; either version 2 of the License, or
34822 + * (at your option) any later version.
34824 + * This program is distributed in the hope that it will be useful,
34825 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34826 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34827 + * GNU General Public License for more details.
34829 + * You should have received a copy of the GNU General Public License
34830 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34834 + * whiteout for logical deletion and opaque directory
34839 +#define WH_MASK 0444
34842 + * If a directory contains this file, then it is opaque. We start with the
34843 + * .wh. flag so that it is blocked by lookup.
34845 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34846 + sizeof(AUFS_WH_DIROPQ) - 1);
34849 + * generate whiteout name, which is NOT terminated by NULL.
34850 + * @name: original d_name.name
34851 + * @len: original d_name.len
34852 + * @wh: whiteout qstr
34853 + * returns zero when succeeds, otherwise error.
34854 + * succeeded value as wh->name should be freed by kfree().
34856 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34860 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34861 + return -ENAMETOOLONG;
34863 + wh->len = name->len + AUFS_WH_PFX_LEN;
34864 + p = kmalloc(wh->len, GFP_NOFS);
34867 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34868 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34875 +/* ---------------------------------------------------------------------- */
34878 + * test if the @wh_name exists under @h_parent.
34879 + * @try_sio specifies the necessary of super-io.
34881 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34884 + struct dentry *wh_dentry;
34887 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34889 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34890 + err = PTR_ERR(wh_dentry);
34891 + if (IS_ERR(wh_dentry)) {
34892 + if (err == -ENAMETOOLONG)
34898 + if (d_is_negative(wh_dentry))
34899 + goto out_wh; /* success */
34902 + if (d_is_reg(wh_dentry))
34903 + goto out_wh; /* success */
34906 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34907 + wh_dentry, d_inode(wh_dentry)->i_mode);
34916 + * test if the @h_dentry sets opaque or not.
34918 +int au_diropq_test(struct dentry *h_dentry)
34921 + struct inode *h_dir;
34923 + h_dir = d_inode(h_dentry);
34924 + err = au_wh_test(h_dentry, &diropq_name,
34925 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34930 + * returns a negative dentry whose name is unique and temporary.
34932 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34933 + struct qstr *prefix)
34935 + struct dentry *dentry;
34937 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34939 + /* strict atomic_t is unnecessary here */
34940 + static unsigned short cnt;
34943 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34946 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34947 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34948 + dentry = ERR_PTR(-ENAMETOOLONG);
34949 + if (unlikely(qs.len > NAME_MAX))
34951 + dentry = ERR_PTR(-ENOMEM);
34952 + name = kmalloc(qs.len + 1, GFP_NOFS);
34953 + if (unlikely(!name))
34957 + /* doubly whiteout-ed */
34958 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34959 + p = name + AUFS_WH_PFX_LEN * 2;
34960 + memcpy(p, prefix->name, prefix->len);
34961 + p += prefix->len;
34963 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34966 + for (i = 0; i < 3; i++) {
34967 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34968 + dentry = au_sio_lkup_one(&qs, h_parent);
34969 + if (IS_ERR(dentry) || d_is_negative(dentry))
34973 + /* pr_warn("could not get random name\n"); */
34974 + dentry = ERR_PTR(-EEXIST);
34975 + AuDbg("%.*s\n", AuLNPair(&qs));
34979 + if (name != defname)
34980 + au_kfree_try_rcu(name);
34982 + AuTraceErrPtr(dentry);
34987 + * rename the @h_dentry on @br to the whiteouted temporary name.
34989 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34992 + struct path h_path = {
34993 + .mnt = au_br_mnt(br)
34995 + struct inode *h_dir, *delegated;
34996 + struct dentry *h_parent;
34998 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34999 + h_dir = d_inode(h_parent);
35000 + IMustLock(h_dir);
35002 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35003 + err = PTR_ERR(h_path.dentry);
35004 + if (IS_ERR(h_path.dentry))
35007 + /* under the same dir, no need to lock_rename() */
35008 + delegated = NULL;
35009 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35012 + if (unlikely(err == -EWOULDBLOCK)) {
35013 + pr_warn("cannot retry for NFSv4 delegation"
35014 + " for an internal rename\n");
35017 + dput(h_path.dentry);
35024 +/* ---------------------------------------------------------------------- */
35026 + * functions for removing a whiteout
35029 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35032 + struct inode *delegated;
35035 + * forces superio when the dir has a sticky bit.
35036 + * this may be a violation of unix fs semantics.
35038 + force = (h_dir->i_mode & S_ISVTX)
35039 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35040 + delegated = NULL;
35041 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35042 + if (unlikely(err == -EWOULDBLOCK)) {
35043 + pr_warn("cannot retry for NFSv4 delegation"
35044 + " for an internal unlink\n");
35050 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35051 + struct dentry *dentry)
35055 + err = do_unlink_wh(h_dir, h_path);
35056 + if (!err && dentry)
35057 + au_set_dbwh(dentry, -1);
35062 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35063 + struct au_branch *br)
35066 + struct path h_path = {
35067 + .mnt = au_br_mnt(br)
35071 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35072 + if (IS_ERR(h_path.dentry))
35073 + err = PTR_ERR(h_path.dentry);
35075 + if (d_is_reg(h_path.dentry))
35076 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35077 + dput(h_path.dentry);
35083 +/* ---------------------------------------------------------------------- */
35085 + * initialize/clean whiteout for a branch
35088 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35092 + struct inode *delegated;
35094 + if (d_is_negative(whpath->dentry))
35098 + err = vfsub_rmdir(h_dir, whpath);
35100 + delegated = NULL;
35101 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35102 + if (unlikely(err == -EWOULDBLOCK)) {
35103 + pr_warn("cannot retry for NFSv4 delegation"
35104 + " for an internal unlink\n");
35108 + if (unlikely(err))
35109 + pr_warn("failed removing %pd (%d), ignored.\n",
35110 + whpath->dentry, err);
35113 +static int test_linkable(struct dentry *h_root)
35115 + struct inode *h_dir = d_inode(h_root);
35117 + if (h_dir->i_op->link)
35120 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35121 + h_root, au_sbtype(h_root->d_sb));
35122 + return -ENOSYS; /* the branch doesn't have its ->link() */
35125 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35126 +static int au_whdir(struct inode *h_dir, struct path *path)
35131 + if (d_is_negative(path->dentry)) {
35134 + if (au_test_nfs(path->dentry->d_sb))
35136 + err = vfsub_mkdir(h_dir, path, mode);
35137 + } else if (d_is_dir(path->dentry))
35140 + pr_err("unknown %pd exists\n", path->dentry);
35145 +struct au_wh_base {
35146 + const struct qstr *name;
35147 + struct dentry *dentry;
35150 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35151 + struct path *h_path)
35153 + h_path->dentry = base[AuBrWh_BASE].dentry;
35154 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35155 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35156 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35157 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35158 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35162 + * returns tri-state,
35163 + * minus: error, caller should print the message
35165 + * plus: error, caller should NOT print the message
35167 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35168 + int do_plink, struct au_wh_base base[],
35169 + struct path *h_path)
35172 + struct inode *h_dir;
35174 + h_dir = d_inode(h_root);
35175 + h_path->dentry = base[AuBrWh_BASE].dentry;
35176 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35177 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35179 + err = test_linkable(h_root);
35180 + if (unlikely(err)) {
35185 + err = au_whdir(h_dir, h_path);
35186 + if (unlikely(err))
35188 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35190 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35191 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35192 + err = au_whdir(h_dir, h_path);
35193 + if (unlikely(err))
35195 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35202 + * for the moment, aufs supports the branch filesystem which does not support
35203 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35204 + * copyup failed. finally, such filesystem will not be used as the writable
35207 + * returns tri-state, see above.
35209 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35210 + int do_plink, struct au_wh_base base[],
35211 + struct path *h_path)
35214 + struct inode *h_dir;
35216 + WbrWhMustWriteLock(wbr);
35218 + err = test_linkable(h_root);
35219 + if (unlikely(err)) {
35225 + * todo: should this create be done in /sbin/mount.aufs helper?
35228 + h_dir = d_inode(h_root);
35229 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35230 + h_path->dentry = base[AuBrWh_BASE].dentry;
35231 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35232 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35235 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35236 + if (unlikely(err))
35239 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35241 + err = au_whdir(h_dir, h_path);
35242 + if (unlikely(err))
35244 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35246 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35247 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35249 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35250 + err = au_whdir(h_dir, h_path);
35251 + if (unlikely(err))
35253 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35260 + * initialize the whiteout base file/dir for @br.
35262 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35265 + const unsigned char do_plink
35266 + = !!au_opt_test(au_mntflags(sb), PLINK);
35267 + struct inode *h_dir;
35268 + struct path path = br->br_path;
35269 + struct dentry *h_root = path.dentry;
35270 + struct au_wbr *wbr = br->br_wbr;
35271 + static const struct qstr base_name[] = {
35272 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35273 + sizeof(AUFS_BASE_NAME) - 1),
35274 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35275 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35276 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35277 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35279 + struct au_wh_base base[] = {
35280 + [AuBrWh_BASE] = {
35281 + .name = base_name + AuBrWh_BASE,
35284 + [AuBrWh_PLINK] = {
35285 + .name = base_name + AuBrWh_PLINK,
35288 + [AuBrWh_ORPH] = {
35289 + .name = base_name + AuBrWh_ORPH,
35295 + WbrWhMustWriteLock(wbr);
35297 + for (i = 0; i < AuBrWh_Last; i++) {
35298 + /* doubly whiteouted */
35299 + struct dentry *d;
35301 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35302 + err = PTR_ERR(d);
35306 + base[i].dentry = d;
35308 + && wbr->wbr_wh[i]
35309 + && wbr->wbr_wh[i] != base[i].dentry);
35313 + for (i = 0; i < AuBrWh_Last; i++) {
35314 + dput(wbr->wbr_wh[i]);
35315 + wbr->wbr_wh[i] = NULL;
35319 + if (!au_br_writable(br->br_perm)) {
35320 + h_dir = d_inode(h_root);
35321 + au_wh_init_ro(h_dir, base, &path);
35322 + } else if (!au_br_wh_linkable(br->br_perm)) {
35323 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35329 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35335 + goto out; /* success */
35338 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35339 + err, h_root, au_sbtype(h_root->d_sb));
35341 + for (i = 0; i < AuBrWh_Last; i++)
35342 + dput(base[i].dentry);
35346 +/* ---------------------------------------------------------------------- */
35348 + * whiteouts are all hard-linked usually.
35349 + * when its link count reaches a ceiling, we create a new whiteout base
35350 + * asynchronously.
35353 +struct reinit_br_wh {
35354 + struct super_block *sb;
35355 + struct au_branch *br;
35358 +static void reinit_br_wh(void *arg)
35361 + aufs_bindex_t bindex;
35362 + struct path h_path;
35363 + struct reinit_br_wh *a = arg;
35364 + struct au_wbr *wbr;
35365 + struct inode *dir, *delegated;
35366 + struct dentry *h_root;
35367 + struct au_hinode *hdir;
35370 + wbr = a->br->br_wbr;
35371 + /* big aufs lock */
35372 + si_noflush_write_lock(a->sb);
35373 + if (!au_br_writable(a->br->br_perm))
35375 + bindex = au_br_index(a->sb, a->br->br_id);
35376 + if (unlikely(bindex < 0))
35379 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35380 + dir = d_inode(a->sb->s_root);
35381 + hdir = au_hi(dir, bindex);
35382 + h_root = au_h_dptr(a->sb->s_root, bindex);
35383 + AuDebugOn(h_root != au_br_dentry(a->br));
35385 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35386 + wbr_wh_write_lock(wbr);
35387 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35390 + h_path.dentry = wbr->wbr_whbase;
35391 + h_path.mnt = au_br_mnt(a->br);
35392 + delegated = NULL;
35393 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35395 + if (unlikely(err == -EWOULDBLOCK)) {
35396 + pr_warn("cannot retry for NFSv4 delegation"
35397 + " for an internal unlink\n");
35401 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35404 + dput(wbr->wbr_whbase);
35405 + wbr->wbr_whbase = NULL;
35407 + err = au_wh_init(a->br, a->sb);
35408 + wbr_wh_write_unlock(wbr);
35409 + au_hn_inode_unlock(hdir);
35410 + di_read_unlock(a->sb->s_root, AuLock_IR);
35412 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35416 + atomic_dec(&wbr->wbr_wh_running);
35417 + au_lcnt_dec(&a->br->br_count);
35418 + si_write_unlock(a->sb);
35419 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35421 + if (unlikely(err))
35422 + AuIOErr("err %d\n", err);
35425 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35427 + int do_dec, wkq_err;
35428 + struct reinit_br_wh *arg;
35431 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35434 + /* ignore ENOMEM */
35435 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35438 + * dec(wh_running), kfree(arg) and dec(br_count)
35439 + * in reinit function
35443 + au_lcnt_inc(&br->br_count);
35444 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35445 + if (unlikely(wkq_err)) {
35446 + atomic_dec(&br->br_wbr->wbr_wh_running);
35447 + au_lcnt_dec(&br->br_count);
35448 + au_kfree_rcu(arg);
35455 + atomic_dec(&br->br_wbr->wbr_wh_running);
35458 +/* ---------------------------------------------------------------------- */
35461 + * create the whiteout @wh.
35463 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35464 + struct dentry *wh)
35467 + struct path h_path = {
35470 + struct au_branch *br;
35471 + struct au_wbr *wbr;
35472 + struct dentry *h_parent;
35473 + struct inode *h_dir, *delegated;
35475 + h_parent = wh->d_parent; /* dir inode is locked */
35476 + h_dir = d_inode(h_parent);
35477 + IMustLock(h_dir);
35479 + br = au_sbr(sb, bindex);
35480 + h_path.mnt = au_br_mnt(br);
35481 + wbr = br->br_wbr;
35482 + wbr_wh_read_lock(wbr);
35483 + if (wbr->wbr_whbase) {
35484 + delegated = NULL;
35485 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35486 + if (unlikely(err == -EWOULDBLOCK)) {
35487 + pr_warn("cannot retry for NFSv4 delegation"
35488 + " for an internal link\n");
35491 + if (!err || err != -EMLINK)
35494 + /* link count full. re-initialize br_whbase. */
35495 + kick_reinit_br_wh(sb, br);
35498 + /* return this error in this context */
35499 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35501 + au_fhsm_wrote(sb, bindex, /*force*/0);
35504 + wbr_wh_read_unlock(wbr);
35508 +/* ---------------------------------------------------------------------- */
35511 + * create or remove the diropq.
35513 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35514 + unsigned int flags)
35516 + struct dentry *opq_dentry, *h_dentry;
35517 + struct super_block *sb;
35518 + struct au_branch *br;
35521 + sb = dentry->d_sb;
35522 + br = au_sbr(sb, bindex);
35523 + h_dentry = au_h_dptr(dentry, bindex);
35524 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35525 + if (IS_ERR(opq_dentry))
35528 + if (au_ftest_diropq(flags, CREATE)) {
35529 + err = link_or_create_wh(sb, bindex, opq_dentry);
35531 + au_set_dbdiropq(dentry, bindex);
35532 + goto out; /* success */
35535 + struct path tmp = {
35536 + .dentry = opq_dentry,
35537 + .mnt = au_br_mnt(br)
35539 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35541 + au_set_dbdiropq(dentry, -1);
35543 + dput(opq_dentry);
35544 + opq_dentry = ERR_PTR(err);
35547 + return opq_dentry;
35550 +struct do_diropq_args {
35551 + struct dentry **errp;
35552 + struct dentry *dentry;
35553 + aufs_bindex_t bindex;
35554 + unsigned int flags;
35557 +static void call_do_diropq(void *args)
35559 + struct do_diropq_args *a = args;
35560 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35563 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35564 + unsigned int flags)
35566 + struct dentry *diropq, *h_dentry;
35568 + h_dentry = au_h_dptr(dentry, bindex);
35569 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35570 + diropq = do_diropq(dentry, bindex, flags);
35573 + struct do_diropq_args args = {
35575 + .dentry = dentry,
35576 + .bindex = bindex,
35580 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35581 + if (unlikely(wkq_err))
35582 + diropq = ERR_PTR(wkq_err);
35588 +/* ---------------------------------------------------------------------- */
35591 + * lookup whiteout dentry.
35592 + * @h_parent: lower parent dentry which must exist and be locked
35593 + * @base_name: name of dentry which will be whiteouted
35594 + * returns dentry for whiteout.
35596 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35597 + struct au_branch *br)
35600 + struct qstr wh_name;
35601 + struct dentry *wh_dentry;
35603 + err = au_wh_name_alloc(&wh_name, base_name);
35604 + wh_dentry = ERR_PTR(err);
35606 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35607 + au_kfree_try_rcu(wh_name.name);
35609 + return wh_dentry;
35613 + * link/create a whiteout for @dentry on @bindex.
35615 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35616 + struct dentry *h_parent)
35618 + struct dentry *wh_dentry;
35619 + struct super_block *sb;
35622 + sb = dentry->d_sb;
35623 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35624 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35625 + err = link_or_create_wh(sb, bindex, wh_dentry);
35627 + au_set_dbwh(dentry, bindex);
35628 + au_fhsm_wrote(sb, bindex, /*force*/0);
35631 + wh_dentry = ERR_PTR(err);
35635 + return wh_dentry;
35638 +/* ---------------------------------------------------------------------- */
35640 +/* Delete all whiteouts in this directory on branch bindex. */
35641 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35642 + aufs_bindex_t bindex, struct au_branch *br)
35645 + unsigned long ul, n;
35646 + struct qstr wh_name;
35648 + struct hlist_head *head;
35649 + struct au_vdir_wh *pos;
35650 + struct au_vdir_destr *str;
35653 + p = (void *)__get_free_page(GFP_NOFS);
35654 + wh_name.name = p;
35655 + if (unlikely(!wh_name.name))
35659 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35660 + p += AUFS_WH_PFX_LEN;
35661 + n = whlist->nh_num;
35662 + head = whlist->nh_head;
35663 + for (ul = 0; !err && ul < n; ul++, head++) {
35664 + hlist_for_each_entry(pos, head, wh_hash) {
35665 + if (pos->wh_bindex != bindex)
35668 + str = &pos->wh_str;
35669 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35670 + memcpy(p, str->name, str->len);
35671 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35672 + err = unlink_wh_name(h_dentry, &wh_name, br);
35677 + AuIOErr("whiteout name too long %.*s\n",
35678 + str->len, str->name);
35683 + free_page((unsigned long)wh_name.name);
35689 +struct del_wh_children_args {
35691 + struct dentry *h_dentry;
35692 + struct au_nhash *whlist;
35693 + aufs_bindex_t bindex;
35694 + struct au_branch *br;
35697 +static void call_del_wh_children(void *args)
35699 + struct del_wh_children_args *a = args;
35700 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35703 +/* ---------------------------------------------------------------------- */
35705 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35707 + struct au_whtmp_rmdir *whtmp;
35709 + unsigned int rdhash;
35711 + SiMustAnyLock(sb);
35713 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35714 + if (unlikely(!whtmp)) {
35715 + whtmp = ERR_PTR(-ENOMEM);
35719 + /* no estimation for dir size */
35720 + rdhash = au_sbi(sb)->si_rdhash;
35722 + rdhash = AUFS_RDHASH_DEF;
35723 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35724 + if (unlikely(err)) {
35725 + au_kfree_rcu(whtmp);
35726 + whtmp = ERR_PTR(err);
35733 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35736 + au_lcnt_dec(&whtmp->br->br_count);
35737 + dput(whtmp->wh_dentry);
35738 + iput(whtmp->dir);
35739 + au_nhash_wh_free(&whtmp->whlist);
35740 + au_kfree_rcu(whtmp);
35744 + * rmdir the whiteouted temporary named dir @h_dentry.
35745 + * @whlist: whiteouted children.
35747 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35748 + struct dentry *wh_dentry, struct au_nhash *whlist)
35751 + unsigned int h_nlink;
35752 + struct path h_tmp;
35753 + struct inode *wh_inode, *h_dir;
35754 + struct au_branch *br;
35756 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35757 + IMustLock(h_dir);
35759 + br = au_sbr(dir->i_sb, bindex);
35760 + wh_inode = d_inode(wh_dentry);
35761 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35764 + * someone else might change some whiteouts while we were sleeping.
35765 + * it means this whlist may have an obsoleted entry.
35767 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35768 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35771 + struct del_wh_children_args args = {
35773 + .h_dentry = wh_dentry,
35774 + .whlist = whlist,
35775 + .bindex = bindex,
35779 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35780 + if (unlikely(wkq_err))
35783 + inode_unlock(wh_inode);
35786 + h_tmp.dentry = wh_dentry;
35787 + h_tmp.mnt = au_br_mnt(br);
35788 + h_nlink = h_dir->i_nlink;
35789 + err = vfsub_rmdir(h_dir, &h_tmp);
35790 + /* some fs doesn't change the parent nlink in some cases */
35791 + h_nlink -= h_dir->i_nlink;
35795 + if (au_ibtop(dir) == bindex) {
35796 + /* todo: dir->i_mutex is necessary */
35797 + au_cpup_attr_timesizes(dir);
35799 + vfsub_drop_nlink(dir);
35801 + return 0; /* success */
35804 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35808 +static void call_rmdir_whtmp(void *args)
35811 + aufs_bindex_t bindex;
35812 + struct au_whtmp_rmdir *a = args;
35813 + struct super_block *sb;
35814 + struct dentry *h_parent;
35815 + struct inode *h_dir;
35816 + struct au_hinode *hdir;
35818 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35819 + /* inode_lock(a->dir); */
35821 + sb = a->dir->i_sb;
35822 + si_read_lock(sb, !AuLock_FLUSH);
35823 + if (!au_br_writable(a->br->br_perm))
35825 + bindex = au_br_index(sb, a->br->br_id);
35826 + if (unlikely(bindex < 0))
35830 + ii_write_lock_parent(a->dir);
35831 + h_parent = dget_parent(a->wh_dentry);
35832 + h_dir = d_inode(h_parent);
35833 + hdir = au_hi(a->dir, bindex);
35834 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35835 + if (unlikely(err))
35837 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35838 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35841 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35842 + au_hn_inode_unlock(hdir);
35843 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35847 + ii_write_unlock(a->dir);
35849 + /* inode_unlock(a->dir); */
35850 + au_whtmp_rmdir_free(a);
35851 + si_read_unlock(sb);
35852 + au_nwt_done(&au_sbi(sb)->si_nowait);
35853 + if (unlikely(err))
35854 + AuIOErr("err %d\n", err);
35857 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35858 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35861 + struct super_block *sb;
35865 + /* all post-process will be done in do_rmdir_whtmp(). */
35867 + args->dir = au_igrab(dir);
35868 + args->br = au_sbr(sb, bindex);
35869 + au_lcnt_inc(&args->br->br_count);
35870 + args->wh_dentry = dget(wh_dentry);
35871 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35872 + if (unlikely(wkq_err)) {
35873 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35874 + au_whtmp_rmdir_free(args);
35877 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35878 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35879 +++ linux/fs/aufs/whout.h 2020-01-27 10:57:18.178871751 +0100
35881 +/* SPDX-License-Identifier: GPL-2.0 */
35883 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35885 + * This program, aufs is free software; you can redistribute it and/or modify
35886 + * it under the terms of the GNU General Public License as published by
35887 + * the Free Software Foundation; either version 2 of the License, or
35888 + * (at your option) any later version.
35890 + * This program is distributed in the hope that it will be useful,
35891 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35892 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35893 + * GNU General Public License for more details.
35895 + * You should have received a copy of the GNU General Public License
35896 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35900 + * whiteout for logical deletion and opaque directory
35903 +#ifndef __AUFS_WHOUT_H__
35904 +#define __AUFS_WHOUT_H__
35911 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35912 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35913 +int au_diropq_test(struct dentry *h_dentry);
35915 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35916 + struct qstr *prefix);
35917 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35918 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35919 + struct dentry *dentry);
35920 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35922 +/* diropq flags */
35923 +#define AuDiropq_CREATE 1
35924 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35925 +#define au_fset_diropq(flags, name) \
35926 + do { (flags) |= AuDiropq_##name; } while (0)
35927 +#define au_fclr_diropq(flags, name) \
35928 + do { (flags) &= ~AuDiropq_##name; } while (0)
35930 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35931 + unsigned int flags);
35932 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35933 + struct au_branch *br);
35934 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35935 + struct dentry *h_parent);
35937 +/* real rmdir for the whiteout-ed dir */
35938 +struct au_whtmp_rmdir {
35939 + struct inode *dir;
35940 + struct au_branch *br;
35941 + struct dentry *wh_dentry;
35942 + struct au_nhash whlist;
35945 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35946 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35947 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35948 + struct dentry *wh_dentry, struct au_nhash *whlist);
35949 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35950 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35952 +/* ---------------------------------------------------------------------- */
35954 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35955 + aufs_bindex_t bindex)
35957 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35960 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35962 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35965 +#endif /* __KERNEL__ */
35966 +#endif /* __AUFS_WHOUT_H__ */
35967 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35968 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35969 +++ linux/fs/aufs/wkq.c 2020-04-03 08:16:47.547461775 +0200
35971 +// SPDX-License-Identifier: GPL-2.0
35973 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35975 + * This program, aufs is free software; you can redistribute it and/or modify
35976 + * it under the terms of the GNU General Public License as published by
35977 + * the Free Software Foundation; either version 2 of the License, or
35978 + * (at your option) any later version.
35980 + * This program is distributed in the hope that it will be useful,
35981 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35982 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35983 + * GNU General Public License for more details.
35985 + * You should have received a copy of the GNU General Public License
35986 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35990 + * workqueue for asynchronous/super-io operations
35991 + * todo: try new credential scheme
35994 +#include <linux/module.h>
35997 +/* internal workqueue named AUFS_WKQ_NAME */
35999 +static struct workqueue_struct *au_wkq;
36001 +struct au_wkinfo {
36002 + struct work_struct wk;
36003 + struct kobject *kobj;
36005 + unsigned int flags; /* see wkq.h */
36007 + au_wkq_func_t func;
36010 +#ifdef CONFIG_LOCKDEP
36012 + struct held_lock **hlock;
36015 + struct completion *comp;
36018 +/* ---------------------------------------------------------------------- */
36020 + * Aufs passes some operations to the workqueue such as the internal copyup.
36021 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36022 + * job run by workqueue depends upon the locks acquired in the other task.
36023 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36024 + * information too. And the job in the workqueue restores the info in order to
36025 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36026 + * correctly and expectedly.
36029 +#ifndef CONFIG_LOCKDEP
36030 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36031 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36032 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36033 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36034 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36036 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36038 + wkinfo->hlock = NULL;
36039 + wkinfo->dont_check = 0;
36046 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36048 + static DEFINE_SPINLOCK(spin);
36051 + struct lock_class_key *key;
36053 + { .name = "&sbinfo->si_rwsem" },
36054 + { .name = "&finfo->fi_rwsem" },
36055 + { .name = "&dinfo->di_rwsem" },
36056 + { .name = "&iinfo->ii_rwsem" }
36061 + /* lockless read from 'set.' see below */
36062 + if (set == ARRAY_SIZE(a)) {
36063 + for (i = 0; i < ARRAY_SIZE(a); i++)
36064 + if (a[i].key == key)
36069 + spin_lock(&spin);
36071 + for (i = 0; i < ARRAY_SIZE(a); i++)
36072 + if (a[i].key == key) {
36073 + spin_unlock(&spin);
36076 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36078 + if (unlikely(a[i].key == key)) { /* rare but possible */
36079 + spin_unlock(&spin);
36084 + if (strstr(a[i].name, name)) {
36086 + * the order of these three lines is important for the
36087 + * lockless read above.
36090 + spin_unlock(&spin);
36092 + /* AuDbg("%d, %s\n", set, name); */
36096 + spin_unlock(&spin);
36105 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36108 + struct task_struct *curr;
36109 + struct held_lock **hl, *held_locks, *p;
36113 + wkinfo->dont_check = lockdep_recursing(curr);
36114 + if (wkinfo->dont_check)
36116 + n = curr->lockdep_depth;
36121 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36122 + if (unlikely(!wkinfo->hlock))
36126 +#if 0 /* left for debugging */
36127 + if (0 && au_debug_test())
36128 + lockdep_print_held_locks(curr);
36130 + held_locks = curr->held_locks;
36131 + hl = wkinfo->hlock;
36133 + p = held_locks++;
36134 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36143 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36145 + au_kfree_try_rcu(wkinfo->hlock);
36148 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36150 + struct held_lock *p, **hl = wkinfo->hlock;
36153 + if (wkinfo->dont_check)
36157 + while ((p = *hl++)) { /* assignment */
36158 + subclass = lockdep_hlock_class(p)->subclass;
36159 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36161 + rwsem_acquire_read(p->instance, subclass, 0,
36162 + /*p->acquire_ip*/_RET_IP_);
36164 + rwsem_acquire(p->instance, subclass, 0,
36165 + /*p->acquire_ip*/_RET_IP_);
36169 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36171 + struct held_lock *p, **hl = wkinfo->hlock;
36173 + if (wkinfo->dont_check)
36177 + while ((p = *hl++)) /* assignment */
36178 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36182 +static void wkq_func(struct work_struct *wk)
36184 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36186 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36187 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36189 + au_wkq_lockdep_pre(wkinfo);
36190 + wkinfo->func(wkinfo->args);
36191 + au_wkq_lockdep_post(wkinfo);
36192 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36193 + complete(wkinfo->comp);
36195 + kobject_put(wkinfo->kobj);
36196 + module_put(THIS_MODULE); /* todo: ?? */
36197 + au_kfree_rcu(wkinfo);
36202 + * Since struct completion is large, try allocating it dynamically.
36204 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36206 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36208 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36210 + init_completion(*comp);
36211 + wkinfo->comp = *comp;
36217 +static void au_wkq_comp_free(struct completion *comp)
36219 + au_kfree_rcu(comp);
36222 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36224 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36225 + if (au_wkq_test()) {
36226 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36227 + " due to a dead dir by UDBA,"
36228 + " or async xino write?\n");
36229 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36232 + au_dbg_verify_kthread();
36234 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36235 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36236 + queue_work(au_wkq, &wkinfo->wk);
36238 + INIT_WORK(&wkinfo->wk, wkq_func);
36239 + schedule_work(&wkinfo->wk);
36244 + * Be careful. It is easy to make deadlock happen.
36245 + * processA: lock, wkq and wait
36246 + * processB: wkq and wait, lock in wkq
36249 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36252 + AuWkqCompDeclare(comp);
36253 + struct au_wkinfo wkinfo = {
36259 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36260 + if (unlikely(err))
36262 + err = au_wkq_lockdep_alloc(&wkinfo);
36263 + if (unlikely(err))
36266 + au_wkq_run(&wkinfo);
36267 + /* no timeout, no interrupt */
36268 + wait_for_completion(wkinfo.comp);
36270 + au_wkq_lockdep_free(&wkinfo);
36273 + au_wkq_comp_free(comp);
36275 + destroy_work_on_stack(&wkinfo.wk);
36280 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36281 + * problem in a concurrent umounting.
36283 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36284 + unsigned int flags)
36287 + struct au_wkinfo *wkinfo;
36289 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36292 + * wkq_func() must free this wkinfo.
36293 + * it highly depends upon the implementation of workqueue.
36296 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36298 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36299 + wkinfo->flags = flags & ~AuWkq_WAIT;
36300 + wkinfo->func = func;
36301 + wkinfo->args = args;
36302 + wkinfo->comp = NULL;
36303 + au_wkq_lockdep_init(wkinfo);
36304 + kobject_get(wkinfo->kobj);
36305 + __module_get(THIS_MODULE); /* todo: ?? */
36307 + au_wkq_run(wkinfo);
36310 + au_nwt_done(&au_sbi(sb)->si_nowait);
36316 +/* ---------------------------------------------------------------------- */
36318 +void au_nwt_init(struct au_nowait_tasks *nwt)
36320 + atomic_set(&nwt->nw_len, 0);
36321 + /* smp_mb(); */ /* atomic_set */
36322 + init_waitqueue_head(&nwt->nw_wq);
36325 +void au_wkq_fin(void)
36327 + destroy_workqueue(au_wkq);
36330 +int __init au_wkq_init(void)
36335 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36336 + if (IS_ERR(au_wkq))
36337 + err = PTR_ERR(au_wkq);
36338 + else if (!au_wkq)
36343 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36344 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36345 +++ linux/fs/aufs/wkq.h 2020-01-27 10:57:18.182205184 +0100
36347 +/* SPDX-License-Identifier: GPL-2.0 */
36349 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36351 + * This program, aufs is free software; you can redistribute it and/or modify
36352 + * it under the terms of the GNU General Public License as published by
36353 + * the Free Software Foundation; either version 2 of the License, or
36354 + * (at your option) any later version.
36356 + * This program is distributed in the hope that it will be useful,
36357 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36358 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36359 + * GNU General Public License for more details.
36361 + * You should have received a copy of the GNU General Public License
36362 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36366 + * workqueue for asynchronous/super-io operations
36367 + * todo: try new credentials management scheme
36370 +#ifndef __AUFS_WKQ_H__
36371 +#define __AUFS_WKQ_H__
36375 +#include <linux/wait.h>
36377 +struct super_block;
36379 +/* ---------------------------------------------------------------------- */
36382 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36384 +struct au_nowait_tasks {
36386 + wait_queue_head_t nw_wq;
36389 +/* ---------------------------------------------------------------------- */
36391 +typedef void (*au_wkq_func_t)(void *args);
36394 +#define AuWkq_WAIT 1
36395 +#define AuWkq_NEST (1 << 1)
36396 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36397 +#define au_fset_wkq(flags, name) \
36398 + do { (flags) |= AuWkq_##name; } while (0)
36399 +#define au_fclr_wkq(flags, name) \
36400 + do { (flags) &= ~AuWkq_##name; } while (0)
36403 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36404 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36405 + unsigned int flags);
36406 +void au_nwt_init(struct au_nowait_tasks *nwt);
36407 +int __init au_wkq_init(void);
36408 +void au_wkq_fin(void);
36410 +/* ---------------------------------------------------------------------- */
36412 +static inline int au_wkq_test(void)
36414 + return current->flags & PF_WQ_WORKER;
36417 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36419 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36422 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36424 + if (atomic_dec_and_test(&nwt->nw_len))
36425 + wake_up_all(&nwt->nw_wq);
36428 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36430 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36434 +#endif /* __KERNEL__ */
36435 +#endif /* __AUFS_WKQ_H__ */
36436 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36437 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36438 +++ linux/fs/aufs/xattr.c 2020-01-27 10:57:18.182205184 +0100
36440 +// SPDX-License-Identifier: GPL-2.0
36442 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36444 + * This program, aufs is free software; you can redistribute it and/or modify
36445 + * it under the terms of the GNU General Public License as published by
36446 + * the Free Software Foundation; either version 2 of the License, or
36447 + * (at your option) any later version.
36449 + * This program is distributed in the hope that it will be useful,
36450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36452 + * GNU General Public License for more details.
36454 + * You should have received a copy of the GNU General Public License
36455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36459 + * handling xattr functions
36462 +#include <linux/fs.h>
36463 +#include <linux/posix_acl_xattr.h>
36464 +#include <linux/xattr.h>
36467 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36469 + if (!ignore_flags)
36477 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36482 +#define cmp(brattr, prefix) do { \
36483 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36484 + XATTR_##prefix##_PREFIX_LEN)) { \
36485 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36491 + cmp(SEC, SECURITY);
36492 + cmp(SYS, SYSTEM);
36493 + cmp(TR, TRUSTED);
36497 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36504 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36506 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36507 + char *name, char **buf, unsigned int ignore_flags,
36508 + unsigned int verbose)
36512 + struct inode *h_idst;
36514 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36516 + if (unlikely(err <= 0)) {
36517 + if (err == -ENODATA
36518 + || (err == -EOPNOTSUPP
36519 + && ((ignore_flags & au_xattr_out_of_list)
36520 + || (au_test_nfs_noacl(d_inode(h_src))
36521 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36523 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36526 + if (err && (verbose || au_debug_test()))
36527 + pr_err("%s, err %d\n", name, err);
36531 + /* unlock it temporary */
36532 + h_idst = d_inode(h_dst);
36533 + inode_unlock(h_idst);
36534 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36535 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36536 + if (unlikely(err)) {
36537 + if (verbose || au_debug_test())
36538 + pr_err("%s, err %d\n", name, err);
36539 + err = au_xattr_ignore(err, name, ignore_flags);
36546 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36547 + unsigned int verbose)
36549 + int err, unlocked, acl_access, acl_default;
36551 + struct inode *h_isrc, *h_idst;
36552 + char *value, *p, *o, *e;
36554 + /* try stopping to update the source inode while we are referencing */
36555 + /* there should not be the parent-child relationship between them */
36556 + h_isrc = d_inode(h_src);
36557 + h_idst = d_inode(h_dst);
36558 + inode_unlock(h_idst);
36559 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36560 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36563 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36564 + ssz = vfs_listxattr(h_src, NULL, 0);
36566 + if (unlikely(err < 0)) {
36568 + if (err == -ENODATA
36569 + || err == -EOPNOTSUPP)
36570 + err = 0; /* ignore */
36579 + p = kmalloc(ssz, GFP_NOFS);
36581 + if (unlikely(!p))
36583 + err = vfs_listxattr(h_src, p, ssz);
36585 + inode_unlock_shared(h_isrc);
36587 + AuDbg("err %d, ssz %zd\n", err, ssz);
36588 + if (unlikely(err < 0))
36596 + while (!err && p < e) {
36597 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36598 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36599 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36600 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36602 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36604 + p += strlen(p) + 1;
36607 + ignore_flags |= au_xattr_out_of_list;
36608 + if (!err && !acl_access) {
36609 + err = au_do_cpup_xattr(h_dst, h_src,
36610 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36611 + ignore_flags, verbose);
36614 + if (!err && !acl_default) {
36615 + err = au_do_cpup_xattr(h_dst, h_src,
36616 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36617 + ignore_flags, verbose);
36621 + au_kfree_try_rcu(value);
36624 + au_kfree_try_rcu(o);
36627 + inode_unlock_shared(h_isrc);
36632 +/* ---------------------------------------------------------------------- */
36634 +static int au_smack_reentering(struct super_block *sb)
36636 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36638 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36639 + * i_op->getxattr(). ouch.
36641 + return si_pid_test(sb);
36652 +struct au_lgxattr {
36660 + const char *name;
36667 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36671 + struct path h_path;
36672 + struct super_block *sb;
36674 + sb = dentry->d_sb;
36675 + reenter = au_smack_reentering(sb);
36677 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36678 + if (unlikely(err))
36681 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36682 + if (unlikely(err))
36684 + if (unlikely(!h_path.dentry))
36685 + /* illegally overlapped or something */
36686 + goto out_di; /* pretending success */
36688 + /* always topmost entry only */
36689 + switch (arg->type) {
36690 + case AU_XATTR_LIST:
36691 + err = vfs_listxattr(h_path.dentry,
36692 + arg->u.list.list, arg->u.list.size);
36694 + case AU_XATTR_GET:
36695 + AuDebugOn(d_is_negative(h_path.dentry));
36696 + err = vfs_getxattr(h_path.dentry,
36697 + arg->u.get.name, arg->u.get.value,
36698 + arg->u.get.size);
36704 + di_read_unlock(dentry, AuLock_IR);
36707 + si_read_unlock(sb);
36713 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36715 + struct au_lgxattr arg = {
36716 + .type = AU_XATTR_LIST,
36723 + return au_lgxattr(dentry, &arg);
36726 +static ssize_t au_getxattr(struct dentry *dentry,
36727 + struct inode *inode __maybe_unused,
36728 + const char *name, void *value, size_t size)
36730 + struct au_lgxattr arg = {
36731 + .type = AU_XATTR_GET,
36739 + return au_lgxattr(dentry, &arg);
36742 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36743 + const char *name, const void *value, size_t size,
36746 + struct au_sxattr arg = {
36747 + .type = AU_XATTR_SET,
36756 + return au_sxattr(dentry, inode, &arg);
36759 +/* ---------------------------------------------------------------------- */
36761 +static int au_xattr_get(const struct xattr_handler *handler,
36762 + struct dentry *dentry, struct inode *inode,
36763 + const char *name, void *buffer, size_t size)
36765 + return au_getxattr(dentry, inode, name, buffer, size);
36768 +static int au_xattr_set(const struct xattr_handler *handler,
36769 + struct dentry *dentry, struct inode *inode,
36770 + const char *name, const void *value, size_t size,
36773 + return au_setxattr(dentry, inode, name, value, size, flags);
36776 +static const struct xattr_handler au_xattr_handler = {
36779 + .get = au_xattr_get,
36780 + .set = au_xattr_set
36783 +static const struct xattr_handler *au_xattr_handlers[] = {
36784 +#ifdef CONFIG_FS_POSIX_ACL
36785 + &posix_acl_access_xattr_handler,
36786 + &posix_acl_default_xattr_handler,
36788 + &au_xattr_handler, /* must be last */
36792 +void au_xattr_init(struct super_block *sb)
36794 + sb->s_xattr = au_xattr_handlers;
36796 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36797 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36798 +++ linux/fs/aufs/xino.c 2020-04-03 08:16:49.834195677 +0200
36800 +// SPDX-License-Identifier: GPL-2.0
36802 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36804 + * This program, aufs is free software; you can redistribute it and/or modify
36805 + * it under the terms of the GNU General Public License as published by
36806 + * the Free Software Foundation; either version 2 of the License, or
36807 + * (at your option) any later version.
36809 + * This program is distributed in the hope that it will be useful,
36810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36812 + * GNU General Public License for more details.
36814 + * You should have received a copy of the GNU General Public License
36815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36819 + * external inode number translation table and bitmap
36821 + * things to consider
36823 + * + au_xino object
36824 + * + XINO files (xino, xib, xigen)
36825 + * + dynamic debugfs entries (xiN)
36826 + * + static debugfs entries (xib, xigen)
36827 + * + static sysfs entry (xi_path)
36828 + * - several entry points to handle them.
36829 + * + mount(2) without xino option (default)
36830 + * + mount(2) with xino option
36831 + * + mount(2) with noxino option
36833 + * + remount with add/del branches
36834 + * + remount with xino/noxino options
36837 +#include <linux/seq_file.h>
36838 +#include <linux/statfs.h>
36841 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36842 + aufs_bindex_t bbot,
36843 + struct super_block *h_sb)
36845 + /* todo: try binary-search if the branches are many */
36846 + for (; btop <= bbot; btop++)
36847 + if (h_sb == au_sbr_sb(sb, btop))
36853 + * find another branch who is on the same filesystem of the specified
36854 + * branch{@btgt}. search until @bbot.
36856 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36857 + aufs_bindex_t bbot)
36859 + aufs_bindex_t bindex;
36860 + struct super_block *tgt_sb;
36862 + tgt_sb = au_sbr_sb(sb, btgt);
36863 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36865 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36870 +/* ---------------------------------------------------------------------- */
36873 + * stop unnecessary notify events at creating xino files
36876 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36878 + aufs_bindex_t bfound, bindex, bbot;
36879 + struct dentry *parent;
36880 + struct au_branch *br;
36883 + parent = dentry->d_parent; /* safe d_parent access */
36884 + bbot = au_sbbot(sb);
36885 + for (bindex = 0; bindex <= bbot; bindex++) {
36886 + br = au_sbr(sb, bindex);
36887 + if (au_br_dentry(br) == parent) {
36893 + AuDbg("bfound b%d\n", bfound);
36897 +struct au_xino_lock_dir {
36898 + struct au_hinode *hdir;
36899 + struct dentry *parent;
36900 + struct inode *dir;
36903 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36904 + unsigned int lsc)
36906 + struct dentry *parent;
36907 + struct inode *dir;
36909 + parent = dget_parent(dentry);
36910 + dir = d_inode(parent);
36911 + inode_lock_nested(dir, lsc);
36912 +#if 0 /* it should not happen */
36913 + spin_lock(&dentry->d_lock);
36914 + if (unlikely(dentry->d_parent != parent)) {
36915 + spin_unlock(&dentry->d_lock);
36916 + inode_unlock(dir);
36921 + spin_unlock(&dentry->d_lock);
36928 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36929 + struct au_xino_lock_dir *ldir)
36931 + aufs_bindex_t bindex;
36933 + ldir->hdir = NULL;
36934 + bindex = au_xi_root(sb, xipath->dentry);
36935 + if (bindex >= 0) {
36936 + /* rw branch root */
36937 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36938 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36941 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36943 + ldir->dir = d_inode(ldir->parent);
36947 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36950 + au_hn_inode_unlock(ldir->hdir);
36952 + inode_unlock(ldir->dir);
36953 + dput(ldir->parent);
36957 +/* ---------------------------------------------------------------------- */
36960 + * create and set a new xino file
36962 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36965 + struct file *file;
36966 + struct dentry *h_parent, *d;
36967 + struct inode *h_dir, *inode;
36969 + static DEFINE_MUTEX(mtx);
36972 + * at mount-time, and the xino file is the default path,
36973 + * hnotify is disabled so we have no notify events to ignore.
36974 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36977 + mutex_lock(&mtx);
36978 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36979 + /* | __FMODE_NONOTIFY */,
36981 + if (IS_ERR(file)) {
36983 + mutex_unlock(&mtx);
36985 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36989 + /* keep file count */
36991 + d = file->f_path.dentry;
36992 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36994 + mutex_unlock(&mtx);
36995 + /* mnt_want_write() is unnecessary here */
36996 + h_dir = d_inode(h_parent);
36997 + inode = file_inode(file);
36998 + /* no delegation since it is just created */
36999 + if (inode->i_nlink)
37000 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37002 + inode_unlock(h_dir);
37004 + if (unlikely(err)) {
37006 + pr_err("unlink %s(%d)\n", fpath, err);
37011 + if (unlikely(sb == d->d_sb)) {
37013 + pr_err("%s must be outside\n", fpath);
37016 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37018 + pr_err("xino doesn't support %s(%s)\n",
37019 + fpath, au_sbtype(d->d_sb));
37022 + return file; /* success */
37026 + file = ERR_PTR(err);
37031 + * create a new xinofile at the same place/path as @base.
37033 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37034 + struct file *copy_src)
37036 + struct file *file;
37037 + struct dentry *dentry, *parent;
37038 + struct inode *dir, *delegated;
37039 + struct qstr *name;
37040 + struct path path;
37041 + int err, do_unlock;
37042 + struct au_xino_lock_dir ldir;
37045 + au_xino_lock_dir(sb, base, &ldir);
37046 + dentry = base->dentry;
37047 + parent = dentry->d_parent; /* dir inode is locked */
37048 + dir = d_inode(parent);
37051 + name = &dentry->d_name;
37052 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37053 + if (IS_ERR(path.dentry)) {
37054 + file = (void *)path.dentry;
37055 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37059 + /* no need to mnt_want_write() since we call dentry_open() later */
37060 + err = vfs_create(dir, path.dentry, 0666, NULL);
37061 + if (unlikely(err)) {
37062 + file = ERR_PTR(err);
37063 + pr_err("%pd create err %d\n", dentry, err);
37067 + path.mnt = base->mnt;
37068 + file = vfsub_dentry_open(&path,
37069 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37070 + /* | __FMODE_NONOTIFY */);
37071 + if (IS_ERR(file)) {
37072 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37076 + delegated = NULL;
37077 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37078 + au_xino_unlock_dir(&ldir);
37080 + if (unlikely(err == -EWOULDBLOCK)) {
37081 + pr_warn("cannot retry for NFSv4 delegation"
37082 + " for an internal unlink\n");
37085 + if (unlikely(err)) {
37086 + pr_err("%pd unlink err %d\n", dentry, err);
37091 + /* no one can touch copy_src xino */
37092 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37093 + if (unlikely(err)) {
37094 + pr_err("%pd copy err %d\n", dentry, err);
37098 + goto out_dput; /* success */
37102 + file = ERR_PTR(err);
37104 + dput(path.dentry);
37107 + au_xino_unlock_dir(&ldir);
37111 +struct file *au_xino_file1(struct au_xino *xi)
37113 + struct file *file;
37114 + unsigned int u, nfile;
37117 + nfile = xi->xi_nfile;
37118 + for (u = 0; u < nfile; u++) {
37119 + file = xi->xi_file[u];
37127 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37138 + if (idx < xi->xi_nfile) {
37139 + f = xi->xi_file[idx];
37143 + p = au_kzrealloc(xi->xi_file,
37144 + sizeof(*xi->xi_file) * xi->xi_nfile,
37145 + sizeof(*xi->xi_file) * (idx + 1),
37146 + GFP_NOFS, /*may_shrink*/0);
37148 + MtxMustLock(&xi->xi_mtx);
37150 + xi->xi_nfile = idx + 1;
37158 + xi->xi_file[idx] = file;
37165 + * if @xinew->xi is not set, then create new xigen file.
37167 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37169 + struct file *file;
37172 + SiMustAnyLock(sb);
37174 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37175 + if (IS_ERR(file)) {
37176 + err = PTR_ERR(file);
37177 + pr_err("%s[%d], err %d\n",
37178 + xinew->xi ? "xino" : "xigen",
37179 + xinew->idx, err);
37184 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37187 + /* todo: make xigen file an array */
37188 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37191 + if (unlikely(err))
37192 + file = ERR_PTR(err);
37198 +/* ---------------------------------------------------------------------- */
37201 + * truncate xino files
37203 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37204 + int idx, struct kstatfs *st)
37208 + struct file *file, *new_xino;
37209 + struct au_xi_new xinew = {
37214 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37215 + file = au_xino_file(xinew.xi, idx);
37219 + xinew.base = &file->f_path;
37220 + err = vfs_statfs(xinew.base, st);
37221 + if (unlikely(err)) {
37222 + AuErr1("statfs err %d, ignored\n", err);
37227 + blocks = file_inode(file)->i_blocks;
37228 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37229 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37231 + xinew.copy_src = file;
37232 + new_xino = au_xi_new(sb, &xinew);
37233 + if (IS_ERR(new_xino)) {
37234 + err = PTR_ERR(new_xino);
37235 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37239 + err = vfs_statfs(&new_xino->f_path, st);
37241 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37242 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37243 + st->f_bfree, st->f_blocks);
37245 + AuErr1("statfs err %d, ignored\n", err);
37253 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37256 + unsigned long jiffy;
37257 + aufs_bindex_t bbot;
37258 + struct kstatfs *st;
37259 + struct au_branch *br;
37260 + struct au_xino *xi;
37263 + st = kmalloc(sizeof(*st), GFP_NOFS);
37264 + if (unlikely(!st))
37268 + bbot = au_sbbot(sb);
37269 + if (unlikely(bindex < 0 || bbot < bindex))
37274 + br = au_sbr(sb, bindex);
37275 + xi = br->br_xino;
37276 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37277 + err = au_xino_do_trunc(sb, bindex, i, st);
37279 + au_sbi(sb)->si_xino_jiffy = jiffy;
37282 + au_kfree_rcu(st);
37287 +struct xino_do_trunc_args {
37288 + struct super_block *sb;
37289 + struct au_branch *br;
37293 +static void xino_do_trunc(void *_args)
37295 + struct xino_do_trunc_args *args = _args;
37296 + struct super_block *sb;
37297 + struct au_branch *br;
37298 + struct inode *dir;
37300 + aufs_bindex_t bindex;
37304 + dir = d_inode(sb->s_root);
37308 + si_noflush_write_lock(sb);
37309 + ii_read_lock_parent(dir);
37310 + bindex = au_br_index(sb, br->br_id);
37311 + err = au_xino_trunc(sb, bindex, idx);
37312 + ii_read_unlock(dir);
37313 + if (unlikely(err))
37314 + pr_warn("err b%d, (%d)\n", bindex, err);
37315 + atomic_dec(&br->br_xino->xi_truncating);
37316 + au_lcnt_dec(&br->br_count);
37317 + si_write_unlock(sb);
37318 + au_nwt_done(&au_sbi(sb)->si_nowait);
37319 + au_kfree_rcu(args);
37323 + * returns the index in the xi_file array whose corresponding file is necessary
37324 + * to truncate, or -1 which means no need to truncate.
37326 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37330 + struct kstatfs st;
37331 + struct au_sbinfo *sbinfo;
37332 + struct au_xino *xi;
37333 + struct file *file;
37335 + /* todo: si_xino_expire and the ratio should be customizable */
37336 + sbinfo = au_sbi(sb);
37337 + if (time_before(jiffies,
37338 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37341 + /* truncation border */
37342 + xi = br->br_xino;
37343 + for (u = 0; u < xi->xi_nfile; u++) {
37344 + file = au_xino_file(xi, u);
37348 + err = vfs_statfs(&file->f_path, &st);
37349 + if (unlikely(err)) {
37350 + AuErr1("statfs err %d, ignored\n", err);
37353 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37354 + >= AUFS_XINO_DEF_TRUNC)
37361 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37364 + struct xino_do_trunc_args *args;
37367 + idx = xino_trunc_test(sb, br);
37371 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37374 + /* lock and kfree() will be called in trunc_xino() */
37375 + args = kmalloc(sizeof(*args), GFP_NOFS);
37376 + if (unlikely(!args)) {
37377 + AuErr1("no memory\n");
37381 + au_lcnt_inc(&br->br_count);
37385 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37387 + return; /* success */
37389 + pr_err("wkq %d\n", wkq_err);
37390 + au_lcnt_dec(&br->br_count);
37391 + au_kfree_rcu(args);
37394 + atomic_dec(&br->br_xino->xi_truncating);
37397 +/* ---------------------------------------------------------------------- */
37399 +struct au_xi_calc {
37404 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37405 + struct au_xi_calc *calc)
37409 + maxent = au_xi_maxent(sb);
37410 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37411 + calc->pos *= sizeof(ino_t);
37414 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37415 + struct au_xi_calc *calc)
37418 + struct file *file;
37419 + struct au_xino *xi = br->br_xino;
37420 + struct au_xi_new xinew = {
37424 + SiMustAnyLock(sb);
37430 + mutex_lock(&xi->xi_mtx);
37431 + file = au_xino_file(xi, calc->idx);
37435 + file = au_xino_file(xi, /*idx*/-1);
37436 + AuDebugOn(!file);
37437 + xinew.idx = calc->idx;
37438 + xinew.base = &file->f_path;
37439 + /* xinew.copy_src = NULL; */
37440 + file = au_xi_new(sb, &xinew);
37441 + if (IS_ERR(file))
37442 + err = PTR_ERR(file);
37445 + mutex_unlock(&xi->xi_mtx);
37450 +struct au_xino_do_new_async_args {
37451 + struct super_block *sb;
37452 + struct au_branch *br;
37453 + struct au_xi_calc calc;
37457 +struct au_xi_writing {
37458 + struct hlist_bl_node node;
37459 + ino_t h_ino, ino;
37462 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37463 + struct au_xi_calc *calc, ino_t ino);
37465 +static void au_xino_call_do_new_async(void *args)
37467 + struct au_xino_do_new_async_args *a = args;
37468 + struct au_branch *br;
37469 + struct super_block *sb;
37470 + struct au_sbinfo *sbi;
37471 + struct inode *root;
37472 + struct file *file;
37473 + struct au_xi_writing *del, *p;
37474 + struct hlist_bl_head *hbl;
37475 + struct hlist_bl_node *pos;
37480 + sbi = au_sbi(sb);
37481 + si_noflush_read_lock(sb);
37482 + root = d_inode(sb->s_root);
37483 + ii_read_lock_child(root);
37484 + err = au_xino_do_new_async(sb, br, &a->calc);
37485 + if (unlikely(err)) {
37486 + AuIOErr("err %d\n", err);
37490 + file = au_xino_file(br->br_xino, a->calc.idx);
37491 + AuDebugOn(!file);
37492 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37493 + if (unlikely(err)) {
37494 + AuIOErr("err %d\n", err);
37499 + hbl = &br->br_xino->xi_writing;
37500 + hlist_bl_lock(hbl);
37501 + au_hbl_for_each(pos, hbl) {
37502 + p = container_of(pos, struct au_xi_writing, node);
37503 + if (p->ino == a->ino) {
37505 + hlist_bl_del(&p->node);
37509 + hlist_bl_unlock(hbl);
37510 + au_kfree_rcu(del);
37513 + au_lcnt_dec(&br->br_count);
37514 + ii_read_unlock(root);
37515 + si_read_unlock(sb);
37516 + au_nwt_done(&sbi->si_nowait);
37521 + * create a new xino file asynchronously
37523 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37524 + struct au_xi_calc *calc, ino_t ino)
37527 + struct au_xino_do_new_async_args *arg;
37530 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37531 + if (unlikely(!arg))
37536 + arg->calc = *calc;
37538 + au_lcnt_inc(&br->br_count);
37539 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37540 + if (unlikely(err)) {
37541 + pr_err("wkq %d\n", err);
37542 + au_lcnt_dec(&br->br_count);
37543 + au_kfree_rcu(arg);
37551 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37552 + * at the position of @h_ino.
37554 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37559 + struct au_xi_calc calc;
37560 + struct au_sbinfo *sbinfo;
37561 + struct file *file;
37562 + struct au_xino *xi;
37563 + struct hlist_bl_head *hbl;
37564 + struct hlist_bl_node *pos;
37565 + struct au_xi_writing *p;
37568 + if (!au_opt_test(au_mntflags(sb), XINO))
37569 + return 0; /* no xino */
37572 + au_xi_calc(sb, h_ino, &calc);
37573 + xi = au_sbr(sb, bindex)->br_xino;
37574 + file = au_xino_file(xi, calc.idx);
37576 + hbl = &xi->xi_writing;
37577 + hlist_bl_lock(hbl);
37578 + au_hbl_for_each(pos, hbl) {
37579 + p = container_of(pos, struct au_xi_writing, node);
37580 + if (p->h_ino == h_ino) {
37581 + AuDbg("hi%llu, i%llu, found\n",
37582 + (u64)p->h_ino, (u64)p->ino);
37587 + hlist_bl_unlock(hbl);
37589 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37590 + return 0; /* no xino */
37592 + sbinfo = au_sbi(sb);
37593 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37594 + if (sz == sizeof(*ino))
37595 + return 0; /* success */
37598 + if (unlikely(sz >= 0)) {
37600 + AuIOErr("xino read error (%zd)\n", sz);
37605 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37606 + struct au_xi_calc *calc, ino_t ino)
37610 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37611 + if (sz == sizeof(ino))
37612 + return 0; /* success */
37614 + AuIOErr("write failed (%zd)\n", sz);
37619 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37620 + * at the position of @h_ino.
37621 + * even if @ino is zero, it is written to the xinofile and means no entry.
37622 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37623 + * try truncating it.
37625 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37629 + unsigned int mnt_flags;
37630 + struct au_xi_calc calc;
37631 + struct file *file;
37632 + struct au_branch *br;
37633 + struct au_xino *xi;
37634 + struct au_xi_writing *p;
37636 + SiMustAnyLock(sb);
37638 + mnt_flags = au_mntflags(sb);
37639 + if (!au_opt_test(mnt_flags, XINO))
37642 + au_xi_calc(sb, h_ino, &calc);
37643 + br = au_sbr(sb, bindex);
37644 + xi = br->br_xino;
37645 + file = au_xino_file(xi, calc.idx);
37647 + /* store the inum pair into the list */
37648 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37649 + p->h_ino = h_ino;
37651 + au_hbl_add(&p->node, &xi->xi_writing);
37653 + /* create and write a new xino file asynchronously */
37654 + err = au_xino_new_async(sb, br, &calc, ino);
37656 + return 0; /* success */
37660 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37662 + br = au_sbr(sb, bindex);
37663 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37664 + && au_test_fs_trunc_xino(au_br_sb(br)))
37665 + xino_try_trunc(sb, br);
37666 + return 0; /* success */
37670 + AuIOErr("write failed (%d)\n", err);
37674 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37675 + size_t size, loff_t *pos);
37677 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37678 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37682 + mm_segment_t oldfs;
37688 + const int prevent_endless = 10;
37692 + oldfs = get_fs();
37693 + set_fs(KERNEL_DS);
37695 + err = func(file, buf.u, size, pos);
37696 + if (err == -EINTR
37697 + && !au_wkq_test()
37698 + && fatal_signal_pending(current)) {
37700 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37701 + BUG_ON(err == -EINTR);
37702 + oldfs = get_fs();
37703 + set_fs(KERNEL_DS);
37705 + } while (i++ < prevent_endless
37706 + && (err == -EAGAIN || err == -EINTR));
37709 +#if 0 /* reserved for future use */
37711 + fsnotify_access(file->f_path.dentry);
37717 +struct xino_fread_args {
37719 + vfs_readf_t func;
37720 + struct file *file;
37726 +static void call_xino_fread(void *args)
37728 + struct xino_fread_args *a = args;
37729 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37732 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37733 + size_t size, loff_t *pos)
37737 + struct xino_fread_args args = {
37746 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37747 + if (unlikely(wkq_err))
37753 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37754 + size_t size, loff_t *pos);
37756 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37757 + size_t size, loff_t *pos)
37760 + mm_segment_t oldfs;
37763 + const char __user *u;
37766 + const int prevent_endless = 10;
37770 + oldfs = get_fs();
37771 + set_fs(KERNEL_DS);
37773 + err = func(file, buf.u, size, pos);
37774 + if (err == -EINTR
37775 + && !au_wkq_test()
37776 + && fatal_signal_pending(current)) {
37778 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37779 + BUG_ON(err == -EINTR);
37780 + oldfs = get_fs();
37781 + set_fs(KERNEL_DS);
37783 + } while (i++ < prevent_endless
37784 + && (err == -EAGAIN || err == -EINTR));
37787 +#if 0 /* reserved for future use */
37789 + fsnotify_modify(file->f_path.dentry);
37795 +struct do_xino_fwrite_args {
37797 + vfs_writef_t func;
37798 + struct file *file;
37804 +static void call_do_xino_fwrite(void *args)
37806 + struct do_xino_fwrite_args *a = args;
37807 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37810 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37811 + size_t size, loff_t *pos)
37815 + struct do_xino_fwrite_args args = {
37825 + * it breaks RLIMIT_FSIZE and normal user's limit,
37826 + * users should care about quota and real 'filesystem full.'
37828 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37829 + if (unlikely(wkq_err))
37835 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37836 + size_t size, loff_t *pos)
37840 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37842 + err = do_xino_fwrite(func, file, buf, size, pos);
37846 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37853 +/* ---------------------------------------------------------------------- */
37856 + * inode number bitmap
37858 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37859 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37863 + AuDebugOn(bit < 0 || page_bits <= bit);
37864 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37868 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37870 + AuDebugOn(ino < AUFS_FIRST_INO);
37871 + ino -= AUFS_FIRST_INO;
37872 + *pindex = ino / page_bits;
37873 + *bit = ino % page_bits;
37876 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37881 + struct au_sbinfo *sbinfo;
37882 + struct file *xib;
37883 + unsigned long *p;
37885 + sbinfo = au_sbi(sb);
37886 + MtxMustLock(&sbinfo->si_xib_mtx);
37887 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37888 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37890 + if (pindex == sbinfo->si_xib_last_pindex)
37893 + xib = sbinfo->si_xib;
37894 + p = sbinfo->si_xib_buf;
37895 + pos = sbinfo->si_xib_last_pindex;
37896 + pos *= PAGE_SIZE;
37897 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37898 + if (unlikely(sz != PAGE_SIZE))
37902 + pos *= PAGE_SIZE;
37903 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37904 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37906 + memset(p, 0, PAGE_SIZE);
37907 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37909 + if (sz == PAGE_SIZE) {
37910 + sbinfo->si_xib_last_pindex = pindex;
37911 + return 0; /* success */
37915 + AuIOErr1("write failed (%zd)\n", sz);
37922 +static void au_xib_clear_bit(struct inode *inode)
37925 + unsigned long pindex;
37926 + struct super_block *sb;
37927 + struct au_sbinfo *sbinfo;
37929 + AuDebugOn(inode->i_nlink);
37931 + sb = inode->i_sb;
37932 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37933 + AuDebugOn(page_bits <= bit);
37934 + sbinfo = au_sbi(sb);
37935 + mutex_lock(&sbinfo->si_xib_mtx);
37936 + err = xib_pindex(sb, pindex);
37938 + clear_bit(bit, sbinfo->si_xib_buf);
37939 + sbinfo->si_xib_next_bit = bit;
37941 + mutex_unlock(&sbinfo->si_xib_mtx);
37944 +/* ---------------------------------------------------------------------- */
37947 + * truncate a xino bitmap file
37951 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37955 + unsigned long pindex;
37956 + loff_t pos, pend;
37957 + struct au_sbinfo *sbinfo;
37958 + vfs_readf_t func;
37960 + unsigned long *p;
37963 + sbinfo = au_sbi(sb);
37964 + MtxMustLock(&sbinfo->si_xib_mtx);
37965 + p = sbinfo->si_xib_buf;
37966 + func = sbinfo->si_xread;
37967 + pend = vfsub_f_size_read(file);
37969 + while (pos < pend) {
37970 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37972 + if (unlikely(sz <= 0))
37976 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37977 + if (unlikely(*ino < AUFS_FIRST_INO))
37980 + xib_calc_bit(*ino, &pindex, &bit);
37981 + AuDebugOn(page_bits <= bit);
37982 + err = xib_pindex(sb, pindex);
37994 +static int xib_restore(struct super_block *sb)
37997 + unsigned int nfile;
37998 + aufs_bindex_t bindex, bbot;
38000 + struct au_branch *br;
38001 + struct au_xino *xi;
38002 + struct file *file;
38005 + page = (void *)__get_free_page(GFP_NOFS);
38006 + if (unlikely(!page))
38010 + bbot = au_sbbot(sb);
38011 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38012 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38013 + br = au_sbr(sb, bindex);
38014 + xi = br->br_xino;
38015 + nfile = xi->xi_nfile;
38016 + for (i = 0; i < nfile; i++) {
38017 + file = au_xino_file(xi, i);
38019 + err = do_xib_restore(sb, file, page);
38022 + AuDbg("skip shared b%d\n", bindex);
38023 + free_page((unsigned long)page);
38029 +int au_xib_trunc(struct super_block *sb)
38034 + struct au_sbinfo *sbinfo;
38035 + unsigned long *p;
38036 + struct file *file;
38038 + SiMustWriteLock(sb);
38041 + sbinfo = au_sbi(sb);
38042 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38045 + file = sbinfo->si_xib;
38046 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38049 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38050 + err = PTR_ERR(file);
38051 + if (IS_ERR(file))
38053 + fput(sbinfo->si_xib);
38054 + sbinfo->si_xib = file;
38056 + p = sbinfo->si_xib_buf;
38057 + memset(p, 0, PAGE_SIZE);
38059 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38060 + if (unlikely(sz != PAGE_SIZE)) {
38062 + AuIOErr("err %d\n", err);
38068 + mutex_lock(&sbinfo->si_xib_mtx);
38069 + /* mnt_want_write() is unnecessary here */
38070 + err = xib_restore(sb);
38071 + mutex_unlock(&sbinfo->si_xib_mtx);
38077 +/* ---------------------------------------------------------------------- */
38079 +struct au_xino *au_xino_alloc(unsigned int nfile)
38081 + struct au_xino *xi;
38083 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38084 + if (unlikely(!xi))
38086 + xi->xi_nfile = nfile;
38087 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38088 + if (unlikely(!xi->xi_file))
38091 + xi->xi_nondir.total = 8; /* initial size */
38092 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38094 + if (unlikely(!xi->xi_nondir.array))
38097 + spin_lock_init(&xi->xi_nondir.spin);
38098 + init_waitqueue_head(&xi->xi_nondir.wqh);
38099 + mutex_init(&xi->xi_mtx);
38100 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38101 + atomic_set(&xi->xi_truncating, 0);
38102 + kref_init(&xi->xi_kref);
38103 + goto out; /* success */
38106 + au_kfree_try_rcu(xi->xi_file);
38108 + au_kfree_rcu(xi);
38114 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38117 + struct au_xino *xi;
38120 + xi = au_xino_alloc(idx + 1);
38121 + if (unlikely(!xi)) {
38128 + xi->xi_file[idx] = file;
38129 + AuDebugOn(br->br_xino);
38130 + br->br_xino = xi;
38136 +static void au_xino_release(struct kref *kref)
38138 + struct au_xino *xi;
38140 + unsigned long ul;
38141 + struct hlist_bl_head *hbl;
38142 + struct hlist_bl_node *pos, *n;
38143 + struct au_xi_writing *p;
38145 + xi = container_of(kref, struct au_xino, xi_kref);
38146 + for (i = 0; i < xi->xi_nfile; i++)
38147 + if (xi->xi_file[i])
38148 + fput(xi->xi_file[i]);
38149 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38150 + AuDebugOn(xi->xi_nondir.array[i]);
38151 + mutex_destroy(&xi->xi_mtx);
38152 + hbl = &xi->xi_writing;
38153 + ul = au_hbl_count(hbl);
38154 + if (unlikely(ul)) {
38155 + pr_warn("xi_writing %lu\n", ul);
38156 + hlist_bl_lock(hbl);
38157 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38158 + hlist_bl_del(&p->node);
38159 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38162 + hlist_bl_unlock(hbl);
38164 + au_kfree_try_rcu(xi->xi_file);
38165 + au_kfree_try_rcu(xi->xi_nondir.array);
38166 + au_kfree_rcu(xi);
38169 +int au_xino_put(struct au_branch *br)
38172 + struct au_xino *xi;
38175 + xi = br->br_xino;
38177 + br->br_xino = NULL;
38178 + ret = kref_put(&xi->xi_kref, au_xino_release);
38184 +/* ---------------------------------------------------------------------- */
38187 + * xino mount option handlers
38191 +static void xino_clear_xib(struct super_block *sb)
38193 + struct au_sbinfo *sbinfo;
38195 + SiMustWriteLock(sb);
38197 + sbinfo = au_sbi(sb);
38198 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38199 + if (sbinfo->si_xib)
38200 + fput(sbinfo->si_xib);
38201 + sbinfo->si_xib = NULL;
38202 + if (sbinfo->si_xib_buf)
38203 + free_page((unsigned long)sbinfo->si_xib_buf);
38204 + sbinfo->si_xib_buf = NULL;
38207 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38211 + struct au_sbinfo *sbinfo;
38212 + struct file *file;
38213 + struct super_block *xi_sb;
38215 + SiMustWriteLock(sb);
38217 + sbinfo = au_sbi(sb);
38218 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38219 + err = PTR_ERR(file);
38220 + if (IS_ERR(file))
38222 + if (sbinfo->si_xib)
38223 + fput(sbinfo->si_xib);
38224 + sbinfo->si_xib = file;
38225 + sbinfo->si_xread = vfs_readf(file);
38226 + sbinfo->si_xwrite = vfs_writef(file);
38227 + xi_sb = file_inode(file)->i_sb;
38228 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38229 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38231 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38232 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38235 + sbinfo->si_ximaxent /= sizeof(ino_t);
38238 + if (!sbinfo->si_xib_buf)
38239 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38240 + if (unlikely(!sbinfo->si_xib_buf))
38243 + sbinfo->si_xib_last_pindex = 0;
38244 + sbinfo->si_xib_next_bit = 0;
38245 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38247 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38248 + PAGE_SIZE, &pos);
38249 + if (unlikely(err != PAGE_SIZE))
38253 + goto out; /* success */
38256 + if (sbinfo->si_xib_buf)
38257 + free_page((unsigned long)sbinfo->si_xib_buf);
38258 + sbinfo->si_xib_buf = NULL;
38262 + fput(sbinfo->si_xib);
38263 + sbinfo->si_xib = NULL;
38269 +/* xino for each branch */
38270 +static void xino_clear_br(struct super_block *sb)
38272 + aufs_bindex_t bindex, bbot;
38273 + struct au_branch *br;
38275 + bbot = au_sbbot(sb);
38276 + for (bindex = 0; bindex <= bbot; bindex++) {
38277 + br = au_sbr(sb, bindex);
38283 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38284 + aufs_bindex_t bshared)
38286 + struct au_branch *brshared;
38288 + brshared = au_sbr(sb, bshared);
38289 + AuDebugOn(!brshared->br_xino);
38290 + AuDebugOn(!brshared->br_xino->xi_file);
38291 + if (br->br_xino != brshared->br_xino) {
38292 + au_xino_get(brshared);
38294 + br->br_xino = brshared->br_xino;
38298 +struct au_xino_do_set_br {
38299 + vfs_writef_t writef;
38300 + struct au_branch *br;
38302 + aufs_bindex_t bshared;
38305 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38306 + struct au_xino_do_set_br *args)
38309 + struct au_xi_calc calc;
38310 + struct file *file;
38311 + struct au_branch *br;
38312 + struct au_xi_new xinew = {
38317 + xinew.xi = br->br_xino;
38318 + au_xi_calc(sb, args->h_ino, &calc);
38319 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38320 + if (args->bshared >= 0)
38321 + /* shared xino */
38322 + au_xino_set_br_shared(sb, br, args->bshared);
38323 + else if (!xinew.xi) {
38325 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38326 + if (unlikely(err))
38330 + /* force re-creating */
38331 + xinew.xi = br->br_xino;
38332 + xinew.idx = calc.idx;
38333 + mutex_lock(&xinew.xi->xi_mtx);
38334 + file = au_xi_new(sb, &xinew);
38335 + mutex_unlock(&xinew.xi->xi_mtx);
38336 + err = PTR_ERR(file);
38337 + if (IS_ERR(file))
38339 + AuDebugOn(!file);
38341 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38342 + if (unlikely(err))
38350 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38353 + aufs_bindex_t bindex, bbot;
38354 + struct au_xino_do_set_br args;
38355 + struct inode *inode;
38357 + SiMustWriteLock(sb);
38359 + bbot = au_sbbot(sb);
38360 + inode = d_inode(sb->s_root);
38361 + args.writef = au_sbi(sb)->si_xwrite;
38362 + for (bindex = 0; bindex <= bbot; bindex++) {
38363 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38364 + args.br = au_sbr(sb, bindex);
38365 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38366 + err = au_xino_do_set_br(sb, path, &args);
38367 + if (unlikely(err))
38375 +void au_xino_clr(struct super_block *sb)
38377 + struct au_sbinfo *sbinfo;
38379 + au_xigen_clr(sb);
38380 + xino_clear_xib(sb);
38381 + xino_clear_br(sb);
38382 + dbgaufs_brs_del(sb, 0);
38383 + sbinfo = au_sbi(sb);
38384 + /* lvalue, do not call au_mntflags() */
38385 + au_opt_clr(sbinfo->si_mntflags, XINO);
38388 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38391 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38392 + struct qstr *dname, *cur_name;
38393 + struct file *cur_xino;
38394 + struct au_sbinfo *sbinfo;
38395 + struct path *path, *cur_path;
38397 + SiMustWriteLock(sb);
38400 + sbinfo = au_sbi(sb);
38401 + path = &xiopt->file->f_path;
38402 + dentry = path->dentry;
38403 + parent = dget_parent(dentry);
38406 + cur_xino = sbinfo->si_xib;
38408 + cur_path = &cur_xino->f_path;
38409 + cur_dentry = cur_path->dentry;
38410 + cur_parent = dget_parent(cur_dentry);
38411 + cur_name = &cur_dentry->d_name;
38412 + dname = &dentry->d_name;
38413 + skip = (cur_parent == parent
38414 + && au_qstreq(dname, cur_name));
38415 + dput(cur_parent);
38421 + au_opt_set(sbinfo->si_mntflags, XINO);
38422 + err = au_xino_set_xib(sb, path);
38423 + /* si_x{read,write} are set */
38425 + err = au_xigen_set(sb, path);
38427 + err = au_xino_set_br(sb, path);
38429 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38430 + goto out; /* success */
38434 + AuIOErr("failed setting xino(%d).\n", err);
38443 + * create a xinofile at the default place/path.
38445 +struct file *au_xino_def(struct super_block *sb)
38447 + struct file *file;
38449 + struct au_branch *br;
38450 + struct super_block *h_sb;
38451 + struct path path;
38452 + aufs_bindex_t bbot, bindex, bwr;
38455 + bbot = au_sbbot(sb);
38457 + for (bindex = 0; bindex <= bbot; bindex++) {
38458 + br = au_sbr(sb, bindex);
38459 + if (au_br_writable(br->br_perm)
38460 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38467 + file = ERR_PTR(-ENOMEM);
38468 + page = (void *)__get_free_page(GFP_NOFS);
38469 + if (unlikely(!page))
38471 + path.mnt = au_br_mnt(br);
38472 + path.dentry = au_h_dptr(sb->s_root, bwr);
38473 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38474 + file = (void *)p;
38475 + if (!IS_ERR(p)) {
38476 + strcat(p, "/" AUFS_XINO_FNAME);
38477 + AuDbg("%s\n", p);
38478 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38480 + free_page((unsigned long)page);
38482 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38484 + if (IS_ERR(file))
38486 + h_sb = file->f_path.dentry->d_sb;
38487 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38488 + pr_err("xino doesn't support %s(%s)\n",
38489 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38491 + file = ERR_PTR(-EINVAL);
38499 +/* ---------------------------------------------------------------------- */
38502 + * initialize the xinofile for the specified branch @br
38503 + * at the place/path where @base_file indicates.
38504 + * test whether another branch is on the same filesystem or not,
38505 + * if found then share the xinofile with another branch.
38507 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38508 + struct path *base)
38511 + struct au_xino_do_set_br args = {
38516 + args.writef = au_sbi(sb)->si_xwrite;
38517 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38519 + err = au_xino_do_set_br(sb, base, &args);
38520 + if (unlikely(err))
38526 +/* ---------------------------------------------------------------------- */
38529 + * get an unused inode number from bitmap
38531 +ino_t au_xino_new_ino(struct super_block *sb)
38534 + unsigned long *p, pindex, ul, pend;
38535 + struct au_sbinfo *sbinfo;
38536 + struct file *file;
38537 + int free_bit, err;
38539 + if (!au_opt_test(au_mntflags(sb), XINO))
38540 + return iunique(sb, AUFS_FIRST_INO);
38542 + sbinfo = au_sbi(sb);
38543 + mutex_lock(&sbinfo->si_xib_mtx);
38544 + p = sbinfo->si_xib_buf;
38545 + free_bit = sbinfo->si_xib_next_bit;
38546 + if (free_bit < page_bits && !test_bit(free_bit, p))
38547 + goto out; /* success */
38548 + free_bit = find_first_zero_bit(p, page_bits);
38549 + if (free_bit < page_bits)
38550 + goto out; /* success */
38552 + pindex = sbinfo->si_xib_last_pindex;
38553 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38554 + err = xib_pindex(sb, ul);
38555 + if (unlikely(err))
38557 + free_bit = find_first_zero_bit(p, page_bits);
38558 + if (free_bit < page_bits)
38559 + goto out; /* success */
38562 + file = sbinfo->si_xib;
38563 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38564 + for (ul = pindex + 1; ul <= pend; ul++) {
38565 + err = xib_pindex(sb, ul);
38566 + if (unlikely(err))
38568 + free_bit = find_first_zero_bit(p, page_bits);
38569 + if (free_bit < page_bits)
38570 + goto out; /* success */
38575 + set_bit(free_bit, p);
38576 + sbinfo->si_xib_next_bit = free_bit + 1;
38577 + pindex = sbinfo->si_xib_last_pindex;
38578 + mutex_unlock(&sbinfo->si_xib_mtx);
38579 + ino = xib_calc_ino(pindex, free_bit);
38580 + AuDbg("i%lu\n", (unsigned long)ino);
38583 + mutex_unlock(&sbinfo->si_xib_mtx);
38588 +/* for s_op->delete_inode() */
38589 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38592 + unsigned int mnt_flags;
38593 + aufs_bindex_t bindex, bbot, bi;
38594 + unsigned char try_trunc;
38595 + struct au_iinfo *iinfo;
38596 + struct super_block *sb;
38597 + struct au_hinode *hi;
38598 + struct inode *h_inode;
38599 + struct au_branch *br;
38600 + vfs_writef_t xwrite;
38601 + struct au_xi_calc calc;
38602 + struct file *file;
38604 + AuDebugOn(au_is_bad_inode(inode));
38606 + sb = inode->i_sb;
38607 + mnt_flags = au_mntflags(sb);
38608 + if (!au_opt_test(mnt_flags, XINO)
38609 + || inode->i_ino == AUFS_ROOT_INO)
38613 + au_xigen_inc(inode);
38614 + au_xib_clear_bit(inode);
38617 + iinfo = au_ii(inode);
38618 + bindex = iinfo->ii_btop;
38622 + xwrite = au_sbi(sb)->si_xwrite;
38623 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38624 + hi = au_hinode(iinfo, bindex);
38625 + bbot = iinfo->ii_bbot;
38626 + for (; bindex <= bbot; bindex++, hi++) {
38627 + h_inode = hi->hi_inode;
38629 + || (!unlinked && h_inode->i_nlink))
38632 + /* inode may not be revalidated */
38633 + bi = au_br_index(sb, hi->hi_id);
38637 + br = au_sbr(sb, bi);
38638 + au_xi_calc(sb, h_inode->i_ino, &calc);
38639 + file = au_xino_file(br->br_xino, calc.idx);
38640 + if (IS_ERR_OR_NULL(file))
38643 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38644 + if (!err && try_trunc
38645 + && au_test_fs_trunc_xino(au_br_sb(br)))
38646 + xino_try_trunc(sb, br);
38650 +/* ---------------------------------------------------------------------- */
38652 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38654 + int found, total, i;
38657 + total = xi->xi_nondir.total;
38658 + for (i = 0; i < total; i++) {
38659 + if (xi->xi_nondir.array[i] != h_ino)
38668 +static int au_xinondir_expand(struct au_xino *xi)
38673 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38676 + sz = xi->xi_nondir.total * sizeof(ino_t);
38677 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38679 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38680 + /*may_shrink*/0);
38682 + xi->xi_nondir.array = p;
38683 + xi->xi_nondir.total <<= 1;
38684 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38692 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38693 + ino_t h_ino, int idx)
38695 + struct au_xino *xi;
38697 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38698 + xi = au_sbr(sb, bindex)->br_xino;
38699 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38701 + spin_lock(&xi->xi_nondir.spin);
38702 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38703 + xi->xi_nondir.array[idx] = 0;
38704 + spin_unlock(&xi->xi_nondir.spin);
38705 + wake_up_all(&xi->xi_nondir.wqh);
38708 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38711 + int err, found, empty;
38712 + struct au_xino *xi;
38716 + if (!au_opt_test(au_mntflags(sb), XINO))
38717 + goto out; /* no xino */
38719 + xi = au_sbr(sb, bindex)->br_xino;
38722 + spin_lock(&xi->xi_nondir.spin);
38723 + found = au_xinondir_find(xi, h_ino);
38724 + if (found == -1) {
38725 + empty = au_xinondir_find(xi, /*h_ino*/0);
38726 + if (empty == -1) {
38727 + empty = xi->xi_nondir.total;
38728 + err = au_xinondir_expand(xi);
38729 + if (unlikely(err))
38732 + xi->xi_nondir.array[empty] = h_ino;
38735 + spin_unlock(&xi->xi_nondir.spin);
38736 + wait_event(xi->xi_nondir.wqh,
38737 + xi->xi_nondir.array[found] != h_ino);
38742 + spin_unlock(&xi->xi_nondir.spin);
38747 +/* ---------------------------------------------------------------------- */
38749 +int au_xino_path(struct seq_file *seq, struct file *file)
38753 + err = au_seq_path(seq, &file->f_path);
38754 + if (unlikely(err))
38757 +#define Deleted "\\040(deleted)"
38758 + seq->count -= sizeof(Deleted) - 1;
38759 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38760 + sizeof(Deleted) - 1));
38766 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38767 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38768 +++ linux/include/uapi/linux/aufs_type.h 2020-04-03 08:16:49.834195677 +0200
38770 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38772 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38774 + * This program, aufs is free software; you can redistribute it and/or modify
38775 + * it under the terms of the GNU General Public License as published by
38776 + * the Free Software Foundation; either version 2 of the License, or
38777 + * (at your option) any later version.
38779 + * This program is distributed in the hope that it will be useful,
38780 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38781 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38782 + * GNU General Public License for more details.
38784 + * You should have received a copy of the GNU General Public License
38785 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38788 +#ifndef __AUFS_TYPE_H__
38789 +#define __AUFS_TYPE_H__
38791 +#define AUFS_NAME "aufs"
38795 + * define it before including all other headers.
38796 + * sched.h may use pr_* macros before defining "current", so define the
38797 + * no-current version first, and re-define later.
38799 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38800 +#include <linux/sched.h>
38802 +#define pr_fmt(fmt) \
38803 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38804 + (int)sizeof(current->comm), current->comm, current->pid
38805 +#include <linux/limits.h>
38807 +#include <stdint.h>
38808 +#include <sys/types.h>
38809 +#include <limits.h>
38810 +#endif /* __KERNEL__ */
38812 +#define AUFS_VERSION "5.4-20200302"
38814 +/* todo? move this to linux-2.6.19/include/magic.h */
38815 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38817 +/* ---------------------------------------------------------------------- */
38820 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38821 +typedef int8_t aufs_bindex_t;
38822 +#define AUFS_BRANCH_MAX 127
38824 +typedef int16_t aufs_bindex_t;
38825 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38826 +#define AUFS_BRANCH_MAX 511
38827 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38828 +#define AUFS_BRANCH_MAX 1023
38829 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38830 +#define AUFS_BRANCH_MAX 32767
38834 +#ifndef AUFS_BRANCH_MAX
38835 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38837 +#endif /* __KERNEL__ */
38839 +/* ---------------------------------------------------------------------- */
38841 +#define AUFS_FSTYPE AUFS_NAME
38843 +#define AUFS_ROOT_INO 2
38844 +#define AUFS_FIRST_INO 11
38846 +#define AUFS_WH_PFX ".wh."
38847 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38848 +#define AUFS_WH_TMP_LEN 4
38849 +/* a limit for rmdir/rename a dir and copyup */
38850 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38851 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38853 + - AUFS_WH_TMP_LEN) /* hex */
38854 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38855 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38856 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38857 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38858 +#define AUFS_DIRWH_DEF 3
38859 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38860 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38861 +#define AUFS_RDBLK_DEF 512 /* bytes */
38862 +#define AUFS_RDHASH_DEF 32
38863 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38864 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38865 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38866 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38867 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38869 +/* pseudo-link maintenace under /proc */
38870 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38871 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38872 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38874 +/* dirren, renamed dir */
38875 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38876 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38877 +/* whiteouted doubly */
38878 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38879 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38881 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38882 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38884 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38885 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38886 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38888 +/* doubly whiteouted */
38889 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38890 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38891 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38893 +/* branch permissions and attributes */
38894 +#define AUFS_BRPERM_RW "rw"
38895 +#define AUFS_BRPERM_RO "ro"
38896 +#define AUFS_BRPERM_RR "rr"
38897 +#define AUFS_BRATTR_COO_REG "coo_reg"
38898 +#define AUFS_BRATTR_COO_ALL "coo_all"
38899 +#define AUFS_BRATTR_FHSM "fhsm"
38900 +#define AUFS_BRATTR_UNPIN "unpin"
38901 +#define AUFS_BRATTR_ICEX "icex"
38902 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38903 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38904 +#define AUFS_BRATTR_ICEX_TR "icextr"
38905 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38906 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38907 +#define AUFS_BRRATTR_WH "wh"
38908 +#define AUFS_BRWATTR_NLWH "nolwh"
38909 +#define AUFS_BRWATTR_MOO "moo"
38911 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38912 +#define AuBrPerm_RO (1 << 1) /* readonly */
38913 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38914 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38916 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38917 +#define AuBrAttr_COO_ALL (1 << 4)
38918 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38920 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38921 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38922 + branch. meaningless since
38923 + linux-3.18-rc1 */
38925 +/* ignore error in copying XATTR */
38926 +#define AuBrAttr_ICEX_SEC (1 << 7)
38927 +#define AuBrAttr_ICEX_SYS (1 << 8)
38928 +#define AuBrAttr_ICEX_TR (1 << 9)
38929 +#define AuBrAttr_ICEX_USR (1 << 10)
38930 +#define AuBrAttr_ICEX_OTH (1 << 11)
38931 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38932 + | AuBrAttr_ICEX_SYS \
38933 + | AuBrAttr_ICEX_TR \
38934 + | AuBrAttr_ICEX_USR \
38935 + | AuBrAttr_ICEX_OTH)
38937 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38938 +#define AuBrRAttr_Mask AuBrRAttr_WH
38940 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38941 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38942 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38944 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38946 +/* #warning test userspace */
38948 +#ifndef CONFIG_AUFS_FHSM
38949 +#undef AuBrAttr_FHSM
38950 +#define AuBrAttr_FHSM 0
38952 +#ifndef CONFIG_AUFS_XATTR
38953 +#undef AuBrAttr_ICEX
38954 +#define AuBrAttr_ICEX 0
38955 +#undef AuBrAttr_ICEX_SEC
38956 +#define AuBrAttr_ICEX_SEC 0
38957 +#undef AuBrAttr_ICEX_SYS
38958 +#define AuBrAttr_ICEX_SYS 0
38959 +#undef AuBrAttr_ICEX_TR
38960 +#define AuBrAttr_ICEX_TR 0
38961 +#undef AuBrAttr_ICEX_USR
38962 +#define AuBrAttr_ICEX_USR 0
38963 +#undef AuBrAttr_ICEX_OTH
38964 +#define AuBrAttr_ICEX_OTH 0
38968 +/* the longest combination */
38969 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38970 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38971 + "+" AUFS_BRATTR_COO_REG \
38972 + "+" AUFS_BRATTR_FHSM \
38973 + "+" AUFS_BRATTR_UNPIN \
38974 + "+" AUFS_BRATTR_ICEX_SEC \
38975 + "+" AUFS_BRATTR_ICEX_SYS \
38976 + "+" AUFS_BRATTR_ICEX_USR \
38977 + "+" AUFS_BRATTR_ICEX_OTH \
38978 + "+" AUFS_BRWATTR_NLWH)
38981 + char a[AuBrPermStrSz];
38982 +} au_br_perm_str_t;
38984 +static inline int au_br_writable(int brperm)
38986 + return brperm & AuBrPerm_RW;
38989 +static inline int au_br_whable(int brperm)
38991 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38994 +static inline int au_br_wh_linkable(int brperm)
38996 + return !(brperm & AuBrWAttr_NoLinkWH);
38999 +static inline int au_br_cmoo(int brperm)
39001 + return brperm & AuBrAttr_CMOO_Mask;
39004 +static inline int au_br_fhsm(int brperm)
39006 + return brperm & AuBrAttr_FHSM;
39009 +/* ---------------------------------------------------------------------- */
39013 + /* readdir in userspace */
39017 + AuCtl_WBR_FD, /* pathconf wrapper */
39018 + AuCtl_IBUSY, /* busy inode */
39019 + AuCtl_MVDOWN, /* move-down */
39020 + AuCtl_BR, /* info about branches */
39021 + AuCtl_FHSM_FD /* connection for fhsm */
39024 +/* borrowed from linux/include/linux/kernel.h */
39026 +#ifdef _GNU_SOURCE
39027 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39029 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39031 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39034 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39036 +#define __aligned(x) __attribute__((aligned(x)))
39041 +#define __packed __attribute__((packed))
39045 +struct au_rdu_cookie {
39050 + uint32_t generation;
39053 +struct au_rdu_ent {
39062 +static inline int au_rdu_len(int nlen)
39064 + /* include the terminating NULL */
39065 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39066 + sizeof(uint64_t));
39069 +union au_rdu_ent_ul {
39070 + struct au_rdu_ent __user *e;
39082 + uint64_t sz; /* AuCtl_RDU */
39083 + uint64_t nent; /* AuCtl_RDU_INO */
39085 + union au_rdu_ent_ul ent;
39086 + uint16_t verify[AufsCtlRduV_End];
39088 + /* input/output */
39092 + union au_rdu_ent_ul tail;
39093 + /* number of entries which were added in a single call */
39098 + struct au_rdu_cookie cookie;
39101 +/* ---------------------------------------------------------------------- */
39103 +/* dirren. the branch is identified by the filename who contains this */
39104 +struct au_drinfo {
39107 + uint8_t oldnamelen;
39108 + uint64_t _padding;
39110 + uint8_t oldname[0];
39113 +struct au_drinfo_fdata {
39115 + struct au_drinfo drinfo;
39118 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39120 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39122 +/* ---------------------------------------------------------------------- */
39124 +struct aufs_wbr_fd {
39129 +/* ---------------------------------------------------------------------- */
39131 +struct aufs_ibusy {
39132 + uint64_t ino, h_ino;
39136 +/* ---------------------------------------------------------------------- */
39138 +/* error code for move-down */
39139 +/* the actual message strings are implemented in aufs-util.git */
39141 + EAU_MVDOWN_OPAQUE = 1,
39142 + EAU_MVDOWN_WHITEOUT,
39143 + EAU_MVDOWN_UPPER,
39144 + EAU_MVDOWN_BOTTOM,
39145 + EAU_MVDOWN_NOUPPER,
39146 + EAU_MVDOWN_NOLOWERBR,
39150 +/* flags for move-down */
39151 +#define AUFS_MVDOWN_DMSG 1
39152 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39153 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39154 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39155 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39156 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39157 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39158 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39159 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39160 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39161 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39162 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39163 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39165 +/* index for move-down */
39167 + AUFS_MVDOWN_UPPER,
39168 + AUFS_MVDOWN_LOWER,
39169 + AUFS_MVDOWN_NARRAY
39173 + * additional info of move-down
39174 + * number of free blocks and inodes.
39175 + * subset of struct kstatfs, but smaller and always 64bit.
39177 +struct aufs_stfs {
39178 + uint64_t f_blocks;
39179 + uint64_t f_bavail;
39180 + uint64_t f_files;
39181 + uint64_t f_ffree;
39184 +struct aufs_stbr {
39185 + int16_t brid; /* optional input */
39186 + int16_t bindex; /* output */
39187 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39190 +struct aufs_mvdown {
39191 + uint32_t flags; /* input/output */
39192 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39193 + int8_t au_errno; /* output */
39196 +/* ---------------------------------------------------------------------- */
39198 +union aufs_brinfo {
39199 + /* PATH_MAX may differ between kernel-space and user-space */
39200 + char _spacer[4096];
39208 +/* ---------------------------------------------------------------------- */
39210 +#define AuCtlType 'A'
39211 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39212 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39213 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39214 + struct aufs_wbr_fd)
39215 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39216 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39217 + struct aufs_mvdown)
39218 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39219 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39221 +#endif /* __AUFS_TYPE_H__ */
39222 SPDX-License-Identifier: GPL-2.0
39223 aufs5.4 loopback patch
39225 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39226 index 5e094699215e..22b2ecb6cfe8 100644
39227 --- a/drivers/block/loop.c
39228 +++ b/drivers/block/loop.c
39229 @@ -625,6 +625,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39233 +static struct file *loop_real_file(struct file *file)
39235 + struct file *f = NULL;
39237 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39238 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39242 static void loop_reread_partitions(struct loop_device *lo,
39243 struct block_device *bdev)
39245 @@ -678,6 +687,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39248 struct file *file = NULL, *old_file;
39249 + struct file *f, *virt_file = NULL, *old_virt_file;
39253 @@ -697,12 +707,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39257 + f = loop_real_file(file);
39259 + virt_file = file;
39264 error = loop_validate_file(file, bdev);
39268 old_file = lo->lo_backing_file;
39269 + old_virt_file = lo->lo_backing_virt_file;
39273 @@ -714,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39274 blk_mq_freeze_queue(lo->lo_queue);
39275 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39276 lo->lo_backing_file = file;
39277 + lo->lo_backing_virt_file = virt_file;
39278 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39279 mapping_set_gfp_mask(file->f_mapping,
39280 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39281 @@ -727,6 +745,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39285 + if (old_virt_file)
39286 + fput(old_virt_file);
39288 loop_reread_partitions(lo, bdev);
39290 @@ -735,6 +755,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39291 mutex_unlock(&loop_ctl_mutex);
39299 @@ -939,7 +961,7 @@ static void loop_update_rotational(struct loop_device *lo)
39300 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39301 struct block_device *bdev, unsigned int arg)
39303 - struct file *file;
39304 + struct file *file, *f, *virt_file = NULL;
39305 struct inode *inode;
39306 struct address_space *mapping;
39307 struct block_device *claimed_bdev = NULL;
39308 @@ -955,6 +977,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39312 + f = loop_real_file(file);
39314 + virt_file = file;
39320 * If we don't hold exclusive handle for the device, upgrade to it
39321 @@ -1003,6 +1031,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39322 lo->lo_device = bdev;
39323 lo->lo_flags = lo_flags;
39324 lo->lo_backing_file = file;
39325 + lo->lo_backing_virt_file = virt_file;
39326 lo->transfer = NULL;
39328 lo->lo_sizelimit = 0;
39329 @@ -1056,6 +1085,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39330 bd_abort_claiming(bdev, claimed_bdev, loop_set_fd);
39336 /* This is safe: open() is still holding a reference. */
39337 module_put(THIS_MODULE);
39338 @@ -1102,6 +1133,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39339 static int __loop_clr_fd(struct loop_device *lo, bool release)
39341 struct file *filp = NULL;
39342 + struct file *virt_filp = lo->lo_backing_virt_file;
39343 gfp_t gfp = lo->old_gfp_mask;
39344 struct block_device *bdev = lo->lo_device;
39346 @@ -1125,6 +1157,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39348 spin_lock_irq(&lo->lo_lock);
39349 lo->lo_backing_file = NULL;
39350 + lo->lo_backing_virt_file = NULL;
39351 spin_unlock_irq(&lo->lo_lock);
39353 loop_release_xfer(lo);
39354 @@ -1207,6 +1240,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39363 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39364 index af75a5ee4094..1d847cb194ff 100644
39365 --- a/drivers/block/loop.h
39366 +++ b/drivers/block/loop.h
39367 @@ -46,7 +46,7 @@ struct loop_device {
39368 int (*ioctl)(struct loop_device *, int cmd,
39369 unsigned long arg);
39371 - struct file * lo_backing_file;
39372 + struct file *lo_backing_file, *lo_backing_virt_file;
39373 struct block_device *lo_device;
39376 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39377 index 6fb4a4ed8cc7..ba9a959f2db2 100644
39378 --- a/fs/aufs/f_op.c
39379 +++ b/fs/aufs/f_op.c
39380 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39381 if (IS_ERR(h_file))
39384 - if (au_test_loopback_kthread()) {
39385 + if (0 && au_test_loopback_kthread()) {
39386 au_warn_loopback(h_file->f_path.dentry->d_sb);
39387 if (file->f_mapping != h_file->f_mapping) {
39388 file->f_mapping = h_file->f_mapping;
39389 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39390 index a8b63acc6204..9d97c3af5686 100644
39391 --- a/fs/aufs/loop.c
39392 +++ b/fs/aufs/loop.c
39393 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39394 symbol_put(loop_backing_file);
39395 au_kfree_try_rcu(au_warn_loopback_array);
39398 +/* ---------------------------------------------------------------------- */
39400 +/* support the loopback block device insude aufs */
39402 +struct file *aufs_real_loop(struct file *file)
39406 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39407 + fi_read_lock(file);
39408 + f = au_hf_top(file);
39409 + fi_read_unlock(file);
39413 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39414 index 94f4f80ae33b..ca1194354aff 100644
39415 --- a/fs/aufs/loop.h
39416 +++ b/fs/aufs/loop.h
39417 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39419 int au_loopback_init(void);
39420 void au_loopback_fin(void);
39422 +struct file *aufs_real_loop(struct file *file);
39424 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39426 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39428 AuStubInt0(au_loopback_init, void)
39429 AuStubVoid(au_loopback_fin, void)
39431 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39432 #endif /* BLK_DEV_LOOP */
39434 #endif /* __KERNEL__ */
39435 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39436 index 589dd0122020..801e0a7faec5 100644
39437 --- a/fs/aufs/super.c
39438 +++ b/fs/aufs/super.c
39439 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39440 .statfs = aufs_statfs,
39441 .put_super = aufs_put_super,
39442 .sync_fs = aufs_sync_fs,
39443 - .remount_fs = aufs_remount_fs
39444 + .remount_fs = aufs_remount_fs,
39445 +#ifdef CONFIG_AUFS_BDEV_LOOP
39446 + .real_loop = aufs_real_loop
39450 /* ---------------------------------------------------------------------- */
39451 diff --git a/include/linux/fs.h b/include/linux/fs.h
39452 index 381a13995011..215b76e0f9dc 100644
39453 --- a/include/linux/fs.h
39454 +++ b/include/linux/fs.h
39455 @@ -1973,6 +1973,10 @@ struct super_operations {
39456 struct shrink_control *);
39457 long (*free_cached_objects)(struct super_block *,
39458 struct shrink_control *);
39459 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39461 + struct file *(*real_loop)(struct file *);