1 SPDX-License-Identifier: GPL-2.0
2 aufs5.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index bfb1c6095c7a..bddba5bb307e 100644
8 @@ -261,6 +261,7 @@ source "fs/romfs/Kconfig"
9 source "fs/pstore/Kconfig"
10 source "fs/sysv/Kconfig"
11 source "fs/ufs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index d60089fd689b..924c16a40b00 100644
20 @@ -130,3 +130,4 @@ obj-$(CONFIG_F2FS_FS) += f2fs/
21 obj-$(CONFIG_CEPH_FS) += ceph/
22 obj-$(CONFIG_PSTORE) += pstore/
23 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs5.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 9cbcf167bdd0..5a9cee826a8f 100644
32 @@ -2822,6 +2822,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 ab7ca5989097..80d06084b043 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..d62303c5472a 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 0f1e3b563c47..43df8452f97d 100644
120 @@ -1670,7 +1670,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 d28d30b13043..34c8093ddb1d 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..3265bb84f152 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);
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);
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 997a530ff4e9..3dbec51c2037 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1331,6 +1331,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 @@ -1810,6 +1811,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 @@ -1880,6 +1882,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 @@ -2298,6 +2306,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 @@ -2586,6 +2595,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 0b0d7259276d..12d18e180348 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -334,6 +334,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 @@ -476,6 +478,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 4861cf8e274b..ec87ccf82025 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
346 aufs5.x-rcN mmap patch
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 731642e0f5a0..e8d6259de65b 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 @@ -1807,7 +1810,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 mm_walk walk = {
401 .hugetlb_entry = gather_hugetlb_stats,
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 0334ca97c584..3bdae823daee 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1538,6 +1538,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 6a7a1083b6fb..461db8843e32 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -262,6 +262,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 @@ -336,6 +337,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 2852d0e76ea3..7b7f676b6465 100644
475 @@ -553,7 +553,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 d0b295c3b764..6156cd3d1ab0 100644
488 @@ -39,7 +39,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 d0cf700bf201..5cac93e7bf67 100644
501 @@ -2721,7 +2721,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 7e8c3e8ae75f..d8a903f61262 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 @@ -931,7 +931,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 @@ -1847,8 +1847,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 @@ -2680,7 +2680,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 @@ -2699,7 +2699,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 @@ -2890,7 +2890,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 @@ -2965,10 +2965,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 @@ -3258,7 +3275,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 fed1b6e9c89b..0d43b248ed54 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..024cdcfae1b1
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-2019 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.x-rcN 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 f7f6a140856a..1a740f3c42ba 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 d62303c5472a..d4ad34463848 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 b07b53f24ff5..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 @@ -327,6 +328,7 @@ void flush_delayed_fput(void)
806 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
808 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
810 @@ -374,6 +376,7 @@ void __fput_sync(struct file *file)
814 +EXPORT_SYMBOL_GPL(__fput_sync);
816 void __init files_init(void)
818 diff --git a/fs/inode.c b/fs/inode.c
819 index 43df8452f97d..8a5c14630ff0 100644
822 @@ -1679,6 +1679,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
824 return update_time(inode, time, flags);
826 +EXPORT_SYMBOL_GPL(update_time);
829 * touch_atime - update the access time
830 diff --git a/fs/namespace.c b/fs/namespace.c
831 index 34c8093ddb1d..2b64af58b643 100644
834 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
835 mnt_dec_writers(real_mount(mnt));
838 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
841 * mnt_drop_write - give up write access to a mount
842 @@ -781,6 +782,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
844 return check_mnt(real_mount(mnt));
846 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
849 * vfsmount lock must be held for write
850 @@ -1900,6 +1902,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
854 +EXPORT_SYMBOL_GPL(iterate_mounts);
856 static void lock_mnt_tree(struct mount *mnt)
858 diff --git a/fs/notify/group.c b/fs/notify/group.c
859 index 0391190305cc..0b9f7f6d8390 100644
860 --- a/fs/notify/group.c
861 +++ b/fs/notify/group.c
862 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
864 refcount_inc(&group->refcnt);
866 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
869 * Drop a reference to a group. Free it if it's through.
870 @@ -108,6 +109,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
871 if (refcount_dec_and_test(&group->refcnt))
872 fsnotify_final_destroy_group(group);
874 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
877 * Create a new fsnotify_group and hold a reference for the group returned.
878 @@ -137,6 +139,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
882 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
884 int fsnotify_fasync(int fd, struct file *file, int on)
886 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
887 index 99ddd126f6f0..2154d69a2c7a 100644
888 --- a/fs/notify/mark.c
889 +++ b/fs/notify/mark.c
890 @@ -276,6 +276,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
891 queue_delayed_work(system_unbound_wq, &reaper_work,
892 FSNOTIFY_REAPER_DELAY);
894 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
897 * Get mark reference when we found the mark via lockless traversal of object
898 @@ -430,6 +431,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
899 mutex_unlock(&group->mark_mutex);
900 fsnotify_free_mark(mark);
902 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
905 * Sorting function for lists of fsnotify marks.
906 @@ -685,6 +687,7 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
907 mutex_unlock(&group->mark_mutex);
910 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
913 * Given a list of marks, find the mark associated with given group. If found
914 @@ -809,6 +812,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
916 WRITE_ONCE(mark->connector, NULL);
918 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
921 * Destroy all marks in destroy_list, waits for SRCU period to finish before
922 diff --git a/fs/open.c b/fs/open.c
923 index a59abe3c669a..78809163ba03 100644
926 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
927 inode_unlock(dentry->d_inode);
930 +EXPORT_SYMBOL_GPL(do_truncate);
932 long vfs_truncate(const struct path *path, loff_t length)
934 diff --git a/fs/read_write.c b/fs/read_write.c
935 index 3265bb84f152..5b2dbddb0efe 100644
936 --- a/fs/read_write.c
937 +++ b/fs/read_write.c
938 @@ -468,6 +468,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
942 +EXPORT_SYMBOL_GPL(vfs_read);
944 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
946 @@ -508,6 +509,7 @@ vfs_readf_t vfs_readf(struct file *file)
947 return new_sync_read;
948 return ERR_PTR(-ENOSYS);
950 +EXPORT_SYMBOL_GPL(vfs_readf);
952 vfs_writef_t vfs_writef(struct file *file)
954 @@ -519,6 +521,7 @@ vfs_writef_t vfs_writef(struct file *file)
955 return new_sync_write;
956 return ERR_PTR(-ENOSYS);
958 +EXPORT_SYMBOL_GPL(vfs_writef);
960 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
962 @@ -588,6 +591,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
966 +EXPORT_SYMBOL_GPL(vfs_write);
968 /* file_ppos returns &file->f_pos or NULL if file is stream */
969 static inline loff_t *file_ppos(struct file *file)
970 diff --git a/fs/splice.c b/fs/splice.c
971 index 75b489fcb66f..0a1f7498c22b 100644
974 @@ -847,6 +847,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
976 return splice_write(pipe, out, ppos, len, flags);
978 +EXPORT_SYMBOL_GPL(do_splice_from);
981 * Attempt to initiate a splice from a file to a pipe.
982 @@ -876,6 +877,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
984 return splice_read(in, ppos, pipe, len, flags);
986 +EXPORT_SYMBOL_GPL(do_splice_to);
989 * splice_direct_to_actor - splices data directly between two non-pipes
990 diff --git a/fs/sync.c b/fs/sync.c
991 index 457f4e4a5cc1..67c66358f3fe 100644
994 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
995 sb->s_op->sync_fs(sb, wait);
996 return __sync_blockdev(sb->s_bdev, wait);
998 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1001 * Write out and wait upon all dirty data associated with this
1002 diff --git a/fs/xattr.c b/fs/xattr.c
1003 index 90dd78f0eb27..40b01dd1b14a 100644
1006 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1007 *xattr_value = value;
1010 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1013 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1014 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1015 index ec87ccf82025..739d1c8a81f5 100644
1016 --- a/kernel/locking/lockdep.c
1017 +++ b/kernel/locking/lockdep.c
1018 @@ -174,6 +174,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1020 return lock_classes + class_idx;
1022 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1023 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1025 #ifdef CONFIG_LOCK_STAT
1026 diff --git a/kernel/task_work.c b/kernel/task_work.c
1027 index 0fef395662a6..83fb1ecfc33d 100644
1028 --- a/kernel/task_work.c
1029 +++ b/kernel/task_work.c
1030 @@ -116,3 +116,4 @@ void task_work_run(void)
1034 +EXPORT_SYMBOL_GPL(task_work_run);
1035 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1036 index 725674f3276d..83f6494c52a2 100644
1037 --- a/security/device_cgroup.c
1038 +++ b/security/device_cgroup.c
1039 @@ -824,3 +824,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1043 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1044 diff --git a/security/security.c b/security/security.c
1045 index 250ee2d76406..2765042d4846 100644
1046 --- a/security/security.c
1047 +++ b/security/security.c
1048 @@ -996,6 +996,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1050 return call_int_hook(path_rmdir, 0, dir, dentry);
1052 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1054 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1056 @@ -1012,6 +1013,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1058 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1060 +EXPORT_SYMBOL_GPL(security_path_symlink);
1062 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1063 struct dentry *new_dentry)
1064 @@ -1020,6 +1022,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1066 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1068 +EXPORT_SYMBOL_GPL(security_path_link);
1070 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1071 const struct path *new_dir, struct dentry *new_dentry,
1072 @@ -1047,6 +1050,7 @@ int security_path_truncate(const struct path *path)
1074 return call_int_hook(path_truncate, 0, path);
1076 +EXPORT_SYMBOL_GPL(security_path_truncate);
1078 int security_path_chmod(const struct path *path, umode_t mode)
1080 @@ -1054,6 +1058,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1082 return call_int_hook(path_chmod, 0, path, mode);
1084 +EXPORT_SYMBOL_GPL(security_path_chmod);
1086 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1088 @@ -1061,6 +1066,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1090 return call_int_hook(path_chown, 0, path, uid, gid);
1092 +EXPORT_SYMBOL_GPL(security_path_chown);
1094 int security_path_chroot(const struct path *path)
1096 @@ -1161,6 +1167,7 @@ int security_inode_permission(struct inode *inode, int mask)
1098 return call_int_hook(inode_permission, 0, inode, mask);
1100 +EXPORT_SYMBOL_GPL(security_inode_permission);
1102 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1104 @@ -1338,6 +1345,7 @@ int security_file_permission(struct file *file, int mask)
1106 return fsnotify_perm(file, mask);
1108 +EXPORT_SYMBOL_GPL(security_file_permission);
1110 int security_file_alloc(struct file *file)
1112 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1113 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1114 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200
1116 +What: /debug/aufs/si_<id>/
1118 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1120 + Under /debug/aufs, a directory named si_<id> is created
1121 + per aufs mount, where <id> is a unique id generated
1124 +What: /debug/aufs/si_<id>/plink
1126 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1128 + It has three lines and shows the information about the
1129 + pseudo-link. The first line is a single number
1130 + representing a number of buckets. The second line is a
1131 + number of pseudo-links per buckets (separated by a
1132 + blank). The last line is a single number representing a
1133 + total number of psedo-links.
1134 + When the aufs mount option 'noplink' is specified, it
1135 + will show "1\n0\n0\n".
1137 +What: /debug/aufs/si_<id>/xib
1139 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1141 + It shows the consumed blocks by xib (External Inode Number
1142 + Bitmap), its block size and file size.
1143 + When the aufs mount option 'noxino' is specified, it
1144 + will be empty. About XINO files, see the aufs manual.
1146 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1148 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1150 + It shows the consumed blocks by xino (External Inode Number
1151 + Translation Table), its link count, block size and file
1153 + Due to the file size limit, there may exist multiple
1154 + xino files per branch. In this case, "-N" is added to
1155 + the filename and it corresponds to the index of the
1156 + internal xino array. "-0" is omitted.
1157 + When the aufs mount option 'noxino' is specified, Those
1158 + entries won't exist. About XINO files, see the aufs
1161 +What: /debug/aufs/si_<id>/xigen
1163 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1165 + It shows the consumed blocks by xigen (External Inode
1166 + Generation Table), its block size and file size.
1167 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1169 + When the aufs mount option 'noxino' is specified, it
1170 + will be empty. About XINO files, see the aufs manual.
1171 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1172 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1173 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200
1175 +What: /sys/fs/aufs/si_<id>/
1177 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1179 + Under /sys/fs/aufs, a directory named si_<id> is created
1180 + per aufs mount, where <id> is a unique id generated
1183 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1185 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1187 + It shows the abolute path of a member directory (which
1188 + is called branch) in aufs, and its permission.
1190 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1192 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1194 + It shows the id of a member directory (which is called
1197 +What: /sys/fs/aufs/si_<id>/xi_path
1199 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1201 + It shows the abolute path of XINO (External Inode Number
1202 + Bitmap, Translation Table and Generation Table) file
1203 + even if it is the default path.
1204 + When the aufs mount option 'noxino' is specified, it
1205 + will be empty. About XINO files, see the aufs manual.
1206 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1207 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1208 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2019-07-11 15:42:14.455570938 +0200
1211 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1213 +# This program is free software; you can redistribute it and/or modify
1214 +# it under the terms of the GNU General Public License as published by
1215 +# the Free Software Foundation; either version 2 of the License, or
1216 +# (at your option) any later version.
1218 +# This program is distributed in the hope that it will be useful,
1219 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1220 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1221 +# GNU General Public License for more details.
1223 +# You should have received a copy of the GNU General Public License
1224 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1227 +----------------------------------------
1229 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1230 +1. abbrev. for "advanced multi-layered unification filesystem".
1231 +2. abbrev. for "another unionfs".
1232 +3. abbrev. for "auf das" in German which means "on the" in English.
1233 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1234 + But "Filesystem aufs Filesystem" is hard to understand.
1235 +4. abbrev. for "African Urban Fashion Show".
1237 +AUFS is a filesystem with features:
1238 +- multi layered stackable unification filesystem, the member directory
1239 + is called as a branch.
1240 +- branch permission and attribute, 'readonly', 'real-readonly',
1241 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1243 +- internal "file copy-on-write".
1244 +- logical deletion, whiteout.
1245 +- dynamic branch manipulation, adding, deleting and changing permission.
1246 +- allow bypassing aufs, user's direct branch access.
1247 +- external inode number translation table and bitmap which maintains the
1248 + persistent aufs inode number.
1249 +- seekable directory, including NFS readdir.
1250 +- file mapping, mmap and sharing pages.
1251 +- pseudo-link, hardlink over branches.
1252 +- loopback mounted filesystem as a branch.
1253 +- several policies to select one among multiple writable branches.
1254 +- revert a single systemcall when an error occurs in aufs.
1258 +Multi Layered Stackable Unification Filesystem
1259 +----------------------------------------------------------------------
1260 +Most people already knows what it is.
1261 +It is a filesystem which unifies several directories and provides a
1262 +merged single directory. When users access a file, the access will be
1263 +passed/re-directed/converted (sorry, I am not sure which English word is
1264 +correct) to the real file on the member filesystem. The member
1265 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1266 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1267 +readonly branch is handled by creating 'whiteout' on the upper writable
1270 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1271 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1272 +different approaches to implement the merged-view.
1273 +The former tries putting it into VFS, and the latter implements as a
1274 +separate filesystem.
1275 +(If I misunderstand about these implementations, please let me know and
1276 +I shall correct it. Because it is a long time ago when I read their
1277 +source files last time).
1279 +UnionMount's approach will be able to small, but may be hard to share
1280 +branches between several UnionMount since the whiteout in it is
1281 +implemented in the inode on branch filesystem and always
1282 +shared. According to Bharata's post, readdir does not seems to be
1284 +There are several missing features known in this implementations such as
1285 +- for users, the inode number may change silently. eg. copy-up.
1286 +- link(2) may break by copy-up.
1287 +- read(2) may get an obsoleted filedata (fstat(2) too).
1288 +- fcntl(F_SETLK) may be broken by copy-up.
1289 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1292 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1293 +merged into mainline. This is another implementation of UnionMount as a
1294 +separated filesystem. All the limitations and known problems which
1295 +UnionMount are equally inherited to "overlay" filesystem.
1297 +Unionfs has a longer history. When I started implementing a stackable
1298 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1299 +inode, dentry and file objects and they have an array pointing lower
1300 +same kind objects. After contributing many patches for Unionfs, I
1301 +re-started my project AUFS (Jun 2006).
1303 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1304 +implemented my own ideas, approaches and enhancements and it became
1305 +totally different one.
1307 +Comparing DM snapshot and fs based implementation
1308 +- the number of bytes to be copied between devices is much smaller.
1309 +- the type of filesystem must be one and only.
1310 +- the fs must be writable, no readonly fs, even for the lower original
1311 + device. so the compression fs will not be usable. but if we use
1312 + loopback mount, we may address this issue.
1314 + mount /cdrom/squashfs.img /sq
1315 + losetup /sq/ext2.img
1316 + losetup /somewhere/cow
1317 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1318 +- it will be difficult (or needs more operations) to extract the
1319 + difference between the original device and COW.
1320 +- DM snapshot-merge may help a lot when users try merging. in the
1321 + fs-layer union, users will use rsync(1).
1323 +You may want to read my old paper "Filesystems in LiveCD"
1324 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1327 +Several characters/aspects/persona of aufs
1328 +----------------------------------------------------------------------
1330 +Aufs has several characters, aspects or persona.
1331 +1. a filesystem, callee of VFS helper
1332 +2. sub-VFS, caller of VFS helper for branches
1333 +3. a virtual filesystem which maintains persistent inode number
1334 +4. reader/writer of files on branches such like an application
1336 +1. Callee of VFS Helper
1337 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1338 +unlink(2) from an application reaches sys_unlink() kernel function and
1339 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1340 +calls filesystem specific unlink operation. Actually aufs implements the
1341 +unlink operation but it behaves like a redirector.
1343 +2. Caller of VFS Helper for Branches
1344 +aufs_unlink() passes the unlink request to the branch filesystem as if
1345 +it were called from VFS. So the called unlink operation of the branch
1346 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1347 +every necessary pre/post operation for the branch filesystem.
1348 +- acquire the lock for the parent dir on a branch
1349 +- lookup in a branch
1350 +- revalidate dentry on a branch
1351 +- mnt_want_write() for a branch
1352 +- vfs_unlink() for a branch
1353 +- mnt_drop_write() for a branch
1354 +- release the lock on a branch
1356 +3. Persistent Inode Number
1357 +One of the most important issue for a filesystem is to maintain inode
1358 +numbers. This is particularly important to support exporting a
1359 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1360 +backend block device for its own. But some storage is necessary to
1361 +keep and maintain the inode numbers. It may be a large space and may not
1362 +suit to keep in memory. Aufs rents some space from its first writable
1363 +branch filesystem (by default) and creates file(s) on it. These files
1364 +are created by aufs internally and removed soon (currently) keeping
1366 +Note: Because these files are removed, they are totally gone after
1367 + unmounting aufs. It means the inode numbers are not persistent
1368 + across unmount or reboot. I have a plan to make them really
1369 + persistent which will be important for aufs on NFS server.
1371 +4. Read/Write Files Internally (copy-on-write)
1372 +Because a branch can be readonly, when you write a file on it, aufs will
1373 +"copy-up" it to the upper writable branch internally. And then write the
1374 +originally requested thing to the file. Generally kernel doesn't
1375 +open/read/write file actively. In aufs, even a single write may cause a
1376 +internal "file copy". This behaviour is very similar to cp(1) command.
1378 +Some people may think it is better to pass such work to user space
1379 +helper, instead of doing in kernel space. Actually I am still thinking
1380 +about it. But currently I have implemented it in kernel space.
1381 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1382 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1383 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2019-07-11 15:42:14.455570938 +0200
1386 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1388 +# This program is free software; you can redistribute it and/or modify
1389 +# it under the terms of the GNU General Public License as published by
1390 +# the Free Software Foundation; either version 2 of the License, or
1391 +# (at your option) any later version.
1393 +# This program is distributed in the hope that it will be useful,
1394 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1395 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1396 +# GNU General Public License for more details.
1398 +# You should have received a copy of the GNU General Public License
1399 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1401 +Basic Aufs Internal Structure
1403 +Superblock/Inode/Dentry/File Objects
1404 +----------------------------------------------------------------------
1405 +As like an ordinary filesystem, aufs has its own
1406 +superblock/inode/dentry/file objects. All these objects have a
1407 +dynamically allocated array and store the same kind of pointers to the
1408 +lower filesystem, branch.
1409 +For example, when you build a union with one readwrite branch and one
1410 +readonly, mounted /au, /rw and /ro respectively.
1412 +- /ro/fileA exists but /rw/fileA
1414 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1415 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1416 +- [0] = NULL (because /rw/fileA doesn't exist)
1419 +This style of an array is essentially same to the aufs
1420 +superblock/inode/dentry/file objects.
1422 +Because aufs supports manipulating branches, ie. add/delete/change
1423 +branches dynamically, these objects has its own generation. When
1424 +branches are changed, the generation in aufs superblock is
1425 +incremented. And a generation in other object are compared when it is
1426 +accessed. When a generation in other objects are obsoleted, aufs
1427 +refreshes the internal array.
1431 +----------------------------------------------------------------------
1432 +Additionally aufs superblock has some data for policies to select one
1433 +among multiple writable branches, XIB files, pseudo-links and kobject.
1434 +See below in detail.
1435 +About the policies which supports copy-down a directory, see
1436 +wbr_policy.txt too.
1439 +Branch and XINO(External Inode Number Translation Table)
1440 +----------------------------------------------------------------------
1441 +Every branch has its own xino (external inode number translation table)
1442 +file. The xino file is created and unlinked by aufs internally. When two
1443 +members of a union exist on the same filesystem, they share the single
1445 +The struct of a xino file is simple, just a sequence of aufs inode
1446 +numbers which is indexed by the lower inode number.
1447 +In the above sample, assume the inode number of /ro/fileA is i111 and
1448 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1449 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1451 +When the inode numbers are not contiguous, the xino file will be sparse
1452 +which has a hole in it and doesn't consume as much disk space as it
1453 +might appear. If your branch filesystem consumes disk space for such
1454 +holes, then you should specify 'xino=' option at mounting aufs.
1456 +Aufs has a mount option to free the disk blocks for such holes in XINO
1457 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1458 +meet a problem of disk shortage due to XINO files, then you should try
1459 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1460 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1461 +the holes in XINO files.
1463 +Also a writable branch has three kinds of "whiteout bases". All these
1464 +are existed when the branch is joined to aufs, and their names are
1465 +whiteout-ed doubly, so that users will never see their names in aufs
1467 +1. a regular file which will be hardlinked to all whiteouts.
1468 +2. a directory to store a pseudo-link.
1469 +3. a directory to store an "orphan"-ed file temporary.
1472 + When you remove a file on a readonly branch, aufs handles it as a
1473 + logical deletion and creates a whiteout on the upper writable branch
1474 + as a hardlink of this file in order not to consume inode on the
1477 + See below, Pseudo-link.
1479 + When "fileC" exists on the lower readonly branch only and it is
1480 + opened and removed with its parent dir, and then user writes
1481 + something into it, then aufs copies-up fileC to this
1482 + directory. Because there is no other dir to store fileC. After
1483 + creating a file under this dir, the file is unlinked.
1485 +Because aufs supports manipulating branches, ie. add/delete/change
1486 +dynamically, a branch has its own id. When the branch order changes,
1487 +aufs finds the new index by searching the branch id.
1491 +----------------------------------------------------------------------
1492 +Assume "fileA" exists on the lower readonly branch only and it is
1493 +hardlinked to "fileB" on the branch. When you write something to fileA,
1494 +aufs copies-up it to the upper writable branch. Additionally aufs
1495 +creates a hardlink under the Pseudo-link Directory of the writable
1496 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1497 +simple list. If fileB is read after unlinking fileA, aufs returns
1498 +filedata from the pseudo-link instead of the lower readonly
1499 +branch. Because the pseudo-link is based upon the inode, to keep the
1500 +inode number by xino (see above) is essentially necessary.
1502 +All the hardlinks under the Pseudo-link Directory of the writable branch
1503 +should be restored in a proper location later. Aufs provides a utility
1504 +to do this. The userspace helpers executed at remounting and unmounting
1506 +During this utility is running, it puts aufs into the pseudo-link
1507 +maintenance mode. In this mode, only the process which began the
1508 +maintenance mode (and its child processes) is allowed to operate in
1509 +aufs. Some other processes which are not related to the pseudo-link will
1510 +be allowed to run too, but the rest have to return an error or wait
1511 +until the maintenance mode ends. If a process already acquires an inode
1512 +mutex (in VFS), it has to return an error.
1515 +XIB(external inode number bitmap)
1516 +----------------------------------------------------------------------
1517 +Addition to the xino file per a branch, aufs has an external inode number
1518 +bitmap in a superblock object. It is also an internal file such like a
1520 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1522 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1524 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1525 +reduce the number of consumed disk blocks for these files.
1528 +Virtual or Vertical Dir, and Readdir in Userspace
1529 +----------------------------------------------------------------------
1530 +In order to support multiple layers (branches), aufs readdir operation
1531 +constructs a virtual dir block on memory. For readdir, aufs calls
1532 +vfs_readdir() internally for each dir on branches, merges their entries
1533 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1534 +object. So the file object has its entry list until it is closed. The
1535 +entry list will be updated when the file position is zero and becomes
1536 +obsoleted. This decision is made in aufs automatically.
1538 +The dynamically allocated memory block for the name of entries has a
1539 +unit of 512 bytes (by default) and stores the names contiguously (no
1540 +padding). Another block for each entry is handled by kmem_cache too.
1541 +During building dir blocks, aufs creates hash list and judging whether
1542 +the entry is whiteouted by its upper branch or already listed.
1543 +The merged result is cached in the corresponding inode object and
1544 +maintained by a customizable life-time option.
1546 +Some people may call it can be a security hole or invite DoS attack
1547 +since the opened and once readdir-ed dir (file object) holds its entry
1548 +list and becomes a pressure for system memory. But I'd say it is similar
1549 +to files under /proc or /sys. The virtual files in them also holds a
1550 +memory page (generally) while they are opened. When an idea to reduce
1551 +memory for them is introduced, it will be applied to aufs too.
1552 +For those who really hate this situation, I've developed readdir(3)
1553 +library which operates this merging in userspace. You just need to set
1554 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1555 +kernel space for readdir(3).
1559 +----------------------------------------------------------------------
1560 +Aufs sometimes requires privilege access to a branch. For instance,
1561 +in copy-up/down operation. When a user process is going to make changes
1562 +to a file which exists in the lower readonly branch only, and the mode
1563 +of one of ancestor directories may not be writable by a user
1564 +process. Here aufs copy-up the file with its ancestors and they may
1565 +require privilege to set its owner/group/mode/etc.
1566 +This is a typical case of a application character of aufs (see
1569 +Aufs uses workqueue synchronously for this case. It creates its own
1570 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1571 +passes the request to call mkdir or write (for example), and wait for
1572 +its completion. This approach solves a problem of a signal handler
1574 +If aufs didn't adopt the workqueue and changed the privilege of the
1575 +process, then the process may receive the unexpected SIGXFSZ or other
1578 +Also aufs uses the system global workqueue ("events" kernel thread) too
1579 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1580 +whiteout base and etc. This is unrelated to a privilege.
1581 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1582 +superblock at the beginning, at the same time waits for the completion
1583 +of all queued asynchronous tasks.
1587 +----------------------------------------------------------------------
1588 +The whiteout in aufs is very similar to Unionfs's. That is represented
1589 +by its filename. UnionMount takes an approach of a file mode, but I am
1590 +afraid several utilities (find(1) or something) will have to support it.
1592 +Basically the whiteout represents "logical deletion" which stops aufs to
1593 +lookup further, but also it represents "dir is opaque" which also stop
1596 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1597 +In order to make several functions in a single systemcall to be
1598 +revertible, aufs adopts an approach to rename a directory to a temporary
1599 +unique whiteouted name.
1600 +For example, in rename(2) dir where the target dir already existed, aufs
1601 +renames the target dir to a temporary unique whiteouted name before the
1602 +actual rename on a branch, and then handles other actions (make it opaque,
1603 +update the attributes, etc). If an error happens in these actions, aufs
1604 +simply renames the whiteouted name back and returns an error. If all are
1605 +succeeded, aufs registers a function to remove the whiteouted unique
1606 +temporary name completely and asynchronously to the system global
1611 +----------------------------------------------------------------------
1612 +It is a well-known feature or concept.
1613 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1614 +internally and makes change to the new file on the upper writable branch.
1615 +When the trigger systemcall does not update the timestamps of the parent
1616 +dir, aufs reverts it after copy-up.
1619 +Move-down (aufs3.9 and later)
1620 +----------------------------------------------------------------------
1621 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1622 +the lower readonly branch to the upper writable branch when a user
1623 +changes something about the file.
1624 +"Move-down" is an opposite action of copy-up. Basically this action is
1625 +ran manually instead of automatically and internally.
1626 +For desgin and implementation, aufs has to consider these issues.
1627 +- whiteout for the file may exist on the lower branch.
1628 +- ancestor directories may not exist on the lower branch.
1629 +- diropq for the ancestor directories may exist on the upper branch.
1630 +- free space on the lower branch will reduce.
1631 +- another access to the file may happen during moving-down, including
1632 + UDBA (see "Revalidate Dentry and UDBA").
1633 +- the file should not be hard-linked nor pseudo-linked. they should be
1634 + handled by auplink utility later.
1636 +Sometimes users want to move-down a file from the upper writable branch
1637 +to the lower readonly or writable branch. For instance,
1638 +- the free space of the upper writable branch is going to run out.
1639 +- create a new intermediate branch between the upper and lower branch.
1642 +For this purpose, use "aumvdown" command in aufs-util.git.
1643 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1644 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1645 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2019-07-11 15:42:14.458904362 +0200
1648 +# Copyright (C) 2015-2019 Junjiro R. Okajima
1650 +# This program is free software; you can redistribute it and/or modify
1651 +# it under the terms of the GNU General Public License as published by
1652 +# the Free Software Foundation; either version 2 of the License, or
1653 +# (at your option) any later version.
1655 +# This program is distributed in the hope that it will be useful,
1656 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1657 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1658 +# GNU General Public License for more details.
1660 +# You should have received a copy of the GNU General Public License
1661 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1663 +Support for a branch who has its ->atomic_open()
1664 +----------------------------------------------------------------------
1665 +The filesystems who implement its ->atomic_open() are not majority. For
1666 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1667 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1668 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1669 +sure whether all filesystems who have ->atomic_open() behave like this,
1670 +but NFSv4 surely returns the error.
1672 +In order to support ->atomic_open() for aufs, there are a few
1675 +A. Introduce aufs_atomic_open()
1676 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1678 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1679 + an aufs user Pip Cet's approach
1680 + - calls aufs_create(), VFS finish_open() and notify_change().
1681 + - pass fake-mode to finish_open(), and then correct the mode by
1683 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1684 + - no aufs_atomic_open().
1685 + - aufs_lookup() registers the TID to an aufs internal object.
1686 + - aufs_create() does nothing when the matching TID is registered, but
1687 + registers the mode.
1688 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1689 + TID is registered.
1690 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1692 + - no aufs_atomic_open().
1693 + - aufs_create() registers the TID to an internal object. this info
1694 + represents "this process created this file just now."
1695 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1696 + registered TID and re-try open() with superuser's credential.
1698 +Pros and cons for each approach.
1701 + - straightforward but highly depends upon VFS internal.
1702 + - the atomic behavaiour is kept.
1703 + - some of parameters such as nameidata are hard to reproduce for
1707 + - easy to implement.
1708 + - the atomic behavaiour is lost.
1710 + - the atomic behavaiour is kept.
1711 + - dirty and tricky.
1712 + - VFS checks whether the file is created correctly after calling
1713 + ->create(), which means this approach doesn't work.
1715 + - easy to implement.
1716 + - the atomic behavaiour is lost.
1717 + - to open a file with superuser's credential and give it to a user
1718 + process is a bad idea, since the file object keeps the credential
1719 + in it. It may affect LSM or something. This approach doesn't work
1722 +The approach A is ideal, but it hard to implement. So here is a
1723 +variation of A, which is to be implemented.
1725 +A-1. Introduce aufs_atomic_open()
1726 + - calls branch fs ->atomic_open() if exists. otherwise calls
1727 + vfs_create() and finish_open().
1728 + - the demerit is that the several checks after branch fs
1729 + ->atomic_open() are lost. in the ordinary case, the checks are
1730 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1731 + be implemented in aufs, but not all I am afraid.
1732 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1733 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1734 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2019-07-11 15:42:14.458904362 +0200
1737 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1739 +# This program is free software; you can redistribute it and/or modify
1740 +# it under the terms of the GNU General Public License as published by
1741 +# the Free Software Foundation; either version 2 of the License, or
1742 +# (at your option) any later version.
1744 +# This program is distributed in the hope that it will be useful,
1745 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1746 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1747 +# GNU General Public License for more details.
1749 +# You should have received a copy of the GNU General Public License
1750 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1753 +----------------------------------------------------------------------
1754 +Since aufs has a character of sub-VFS (see Introduction), it operates
1755 +lookup for branches as VFS does. It may be a heavy work. But almost all
1756 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1757 +directly connected to its parent. Digging down the directory hierarchy
1758 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1761 +When a branch is a remote filesystem, aufs basically relies upon its
1762 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1764 +For d_revalidate, aufs implements three levels of revalidate tests. See
1765 +"Revalidate Dentry and UDBA" in detail.
1768 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1769 +----------------------------------------------------------------------
1770 +Let's try case study.
1771 +- aufs has two branches, upper readwrite and lower readonly.
1773 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1774 +- user invoked "chmod a+rx /au/dirA"
1775 +- the internal copy-up is activated and "/rw/dirA" is created and its
1776 + permission bits are set to world readable.
1777 +- then "/au/dirA" becomes world readable?
1779 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1780 +or it may be a natively readonly filesystem. If aufs respects the lower
1781 +branch, it should not respond readdir request from other users. But user
1782 +allowed it by chmod. Should really aufs rejects showing the entries
1785 +To be honest, I don't have a good solution for this case. So aufs
1786 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1788 +When dirperm1 is specified, aufs checks only the highest one for the
1789 +directory permission, and shows the entries. Otherwise, as usual, checks
1790 +every dir existing on all branches and rejects the request.
1792 +As a side effect, dirperm1 option improves the performance of aufs
1793 +because the number of permission check is reduced when the number of
1797 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1798 +----------------------------------------------------------------------
1799 +Generally VFS helpers re-validate a dentry as a part of lookup.
1800 +0. digging down the directory hierarchy.
1801 +1. lock the parent dir by its i_mutex.
1802 +2. lookup the final (child) entry.
1804 +4. call the actual operation (create, unlink, etc.)
1805 +5. unlock the parent dir
1807 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1808 +called. Actually aufs implements it and checks the dentry on a branch is
1810 +But it is not enough. Because aufs has to release the lock for the
1811 +parent dir on a branch at the end of ->lookup() (step 2) and
1812 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1814 +If the file on a branch is changed directly, eg. bypassing aufs, after
1815 +aufs released the lock, then the subsequent operation may cause
1816 +something unpleasant result.
1818 +This situation is a result of VFS architecture, ->lookup() and
1819 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1820 +design from VFS's point of view. It is just not suitable for sub-VFS
1823 +Aufs supports such case by three level of revalidation which is
1824 +selectable by user.
1825 +1. Simple Revalidate
1826 + Addition to the native flow in VFS's, confirm the child-parent
1827 + relationship on the branch just after locking the parent dir on the
1828 + branch in the "actual operation" (step 4). When this validation
1829 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1830 + checks the validation of the dentry on branches.
1831 +2. Monitor Changes Internally by Inotify/Fsnotify
1832 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1833 + the dentry on the branch, and returns EBUSY if it finds different
1835 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1836 + during it is in cache. When the event is notified, aufs registers a
1837 + function to kernel 'events' thread by schedule_work(). And the
1838 + function sets some special status to the cached aufs dentry and inode
1839 + private data. If they are not cached, then aufs has nothing to
1840 + do. When the same file is accessed through aufs (step 0-3) later,
1841 + aufs will detect the status and refresh all necessary data.
1842 + In this mode, aufs has to ignore the event which is fired by aufs
1844 +3. No Extra Validation
1845 + This is the simplest test and doesn't add any additional revalidation
1846 + test, and skip the revalidation in step 4. It is useful and improves
1847 + aufs performance when system surely hide the aufs branches from user,
1848 + by over-mounting something (or another method).
1849 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1850 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1851 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2019-07-11 15:42:14.458904362 +0200
1854 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1856 +# This program is free software; you can redistribute it and/or modify
1857 +# it under the terms of the GNU General Public License as published by
1858 +# the Free Software Foundation; either version 2 of the License, or
1859 +# (at your option) any later version.
1861 +# This program is distributed in the hope that it will be useful,
1862 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1863 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1864 +# GNU General Public License for more details.
1866 +# You should have received a copy of the GNU General Public License
1867 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1869 +Branch Manipulation
1871 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1872 +and changing its permission/attribute, there are a lot of works to do.
1876 +----------------------------------------------------------------------
1877 +o Confirm the adding dir exists outside of aufs, including loopback
1878 + mount, and its various attributes.
1879 +o Initialize the xino file and whiteout bases if necessary.
1882 +o Check the owner/group/mode of the directory
1883 + When the owner/group/mode of the adding directory differs from the
1884 + existing branch, aufs issues a warning because it may impose a
1886 + For example, when a upper writable branch has a world writable empty
1887 + top directory, a malicious user can create any files on the writable
1888 + branch directly, like copy-up and modify manually. If something like
1889 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1890 + writable branch, and the writable branch is world-writable, then a
1891 + malicious guy may create /etc/passwd on the writable branch directly
1892 + and the infected file will be valid in aufs.
1893 + I am afraid it can be a security issue, but aufs can do nothing except
1894 + producing a warning.
1898 +----------------------------------------------------------------------
1899 +o Confirm the deleting branch is not busy
1900 + To be general, there is one merit to adopt "remount" interface to
1901 + manipulate branches. It is to discard caches. At deleting a branch,
1902 + aufs checks the still cached (and connected) dentries and inodes. If
1903 + there are any, then they are all in-use. An inode without its
1904 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1906 + For the cached one, aufs checks whether the same named entry exists on
1908 + If the cached one is a directory, because aufs provides a merged view
1909 + to users, as long as one dir is left on any branch aufs can show the
1910 + dir to users. In this case, the branch can be removed from aufs.
1911 + Otherwise aufs rejects deleting the branch.
1913 + If any file on the deleting branch is opened by aufs, then aufs
1917 +Modify the Permission of a Branch
1918 +----------------------------------------------------------------------
1919 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1922 +o rw --> ro: Confirm the modifying branch is not busy
1923 + Aufs rejects the request if any of these conditions are true.
1924 + - a file on the branch is mmap-ed.
1925 + - a regular file on the branch is opened for write and there is no
1926 + same named entry on the upper branch.
1927 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1928 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1929 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2019-07-11 15:42:14.458904362 +0200
1932 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1934 +# This program is free software; you can redistribute it and/or modify
1935 +# it under the terms of the GNU General Public License as published by
1936 +# the Free Software Foundation; either version 2 of the License, or
1937 +# (at your option) any later version.
1939 +# This program is distributed in the hope that it will be useful,
1940 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1941 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1942 +# GNU General Public License for more details.
1944 +# You should have received a copy of the GNU General Public License
1945 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1947 +Policies to Select One among Multiple Writable Branches
1948 +----------------------------------------------------------------------
1949 +When the number of writable branch is more than one, aufs has to decide
1950 +the target branch for file creation or copy-up. By default, the highest
1951 +writable branch which has the parent (or ancestor) dir of the target
1952 +file is chosen (top-down-parent policy).
1953 +By user's request, aufs implements some other policies to select the
1954 +writable branch, for file creation several policies, round-robin,
1955 +most-free-space, and other policies. For copy-up, top-down-parent,
1956 +bottom-up-parent, bottom-up and others.
1958 +As expected, the round-robin policy selects the branch in circular. When
1959 +you have two writable branches and creates 10 new files, 5 files will be
1960 +created for each branch. mkdir(2) systemcall is an exception. When you
1961 +create 10 new directories, all will be created on the same branch.
1962 +And the most-free-space policy selects the one which has most free
1963 +space among the writable branches. The amount of free space will be
1964 +checked by aufs internally, and users can specify its time interval.
1966 +The policies for copy-up is more simple,
1967 +top-down-parent is equivalent to the same named on in create policy,
1968 +bottom-up-parent selects the writable branch where the parent dir
1969 +exists and the nearest upper one from the copyup-source,
1970 +bottom-up selects the nearest upper writable branch from the
1971 +copyup-source, regardless the existence of the parent dir.
1973 +There are some rules or exceptions to apply these policies.
1974 +- If there is a readonly branch above the policy-selected branch and
1975 + the parent dir is marked as opaque (a variation of whiteout), or the
1976 + target (creating) file is whiteout-ed on the upper readonly branch,
1977 + then the result of the policy is ignored and the target file will be
1978 + created on the nearest upper writable branch than the readonly branch.
1979 +- If there is a writable branch above the policy-selected branch and
1980 + the parent dir is marked as opaque or the target file is whiteouted
1981 + on the branch, then the result of the policy is ignored and the target
1982 + file will be created on the highest one among the upper writable
1983 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1985 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1986 + They try selecting the branch where the source exists as possible
1987 + since copyup a large file will take long time. If it can't be,
1988 + ie. the branch where the source exists is readonly, then they will
1989 + follow the copyup policy.
1990 +- There is an exception for rename(2) when the target exists.
1991 + If the rename target exists, aufs compares the index of the branches
1992 + where the source and the target exists and selects the higher
1993 + one. If the selected branch is readonly, then aufs follows the
1995 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1996 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1997 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200
2000 +// to view this graph, run dot(1) command in GRAPHVIZ.
2004 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2008 +aufs_rename -> whinfo [label="store/remove"];
2011 +inode_list [label="h_inum list in branch\ncache"];
2014 +whinode [label="h_inum list file"];
2017 +brmgmt [label="br_add/del/mod/umount"];
2019 +brmgmt -> inode_list [label="create/remove"];
2020 +brmgmt -> whinode [label="load/store"];
2022 +inode_list -> whinode [style=dashed,dir=both];
2024 +aufs_rename -> inode_list [label="add/del"];
2026 +aufs_lookup -> inode_list [label="search"];
2028 +aufs_lookup -> whinfo [label="load/remove"];
2030 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2031 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2032 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2019-07-11 15:42:14.458904362 +0200
2035 +# Copyright (C) 2017-2019 Junjiro R. Okajima
2037 +# This program is free software; you can redistribute it and/or modify
2038 +# it under the terms of the GNU General Public License as published by
2039 +# the Free Software Foundation; either version 2 of the License, or
2040 +# (at your option) any later version.
2042 +# This program is distributed in the hope that it will be useful,
2043 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2044 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2045 +# GNU General Public License for more details.
2047 +# You should have received a copy of the GNU General Public License
2048 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2050 +Special handling for renaming a directory (DIRREN)
2051 +----------------------------------------------------------------------
2052 +First, let's assume we have a simple usecase.
2056 +- /ro/dirA and /ro/dirA/file exist too
2057 +- there is no dirB on both branches
2058 +- a user issues rename("dirA", "dirB")
2060 +Now, what should aufs behave against this rename(2)?
2061 +There are a few possible cases.
2064 + since dirA exists on a readonly branch which cannot be renamed.
2066 + it is possible to copy-up dirA (only the dir itself), but the child
2067 + entries ("file" in this case) should not be. it must be a bad
2068 + approach to copy-up recursively.
2069 +C. returns a success.
2070 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2071 + is a violation of aufs' policy.
2072 +D. construct an extra information which indicates that /ro/dirA should
2073 + be handled as the name of dirB.
2074 + overlayfs has a similar feature called REDIRECT.
2076 +Until now, aufs implements the case B only which returns EXDEV, and
2077 +expects the userspace application behaves like mv(1) which tries
2078 +issueing rename(2) recursively.
2080 +A new aufs feature called DIRREN is introduced which implements the case
2081 +D. There are several "extra information" added.
2083 +1. detailed info per renamed directory
2084 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2085 +2. the inode-number list of directories on a branch
2086 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2088 +The filename of "detailed info per directory" represents the lower
2089 +branch, and its format is
2090 +- a type of the branch id
2092 + + uuid (not implemented yet)
2095 +- the inode-number of the branch root dir
2097 +And it contains these info in a single regular file.
2099 +- branch's inode-number of the logically renamed dir
2100 +- the name of the before-renamed dir
2102 +The "detailed info per directory" file is created in aufs rename(2), and
2103 +loaded in any lookup.
2104 +The info is considered in lookup for the matching case only. Here
2105 +"matching" means that the root of branch (in the info filename) is same
2106 +to the current looking-up branch. After looking-up the before-renamed
2107 +name, the inode-number is compared. And the matched dentry is used.
2109 +The "inode-number list of directories" is a regular file which contains
2110 +simply the inode-numbers on the branch. The file is created or updated
2111 +in removing the branch, and loaded in adding the branch. Its lifetime is
2112 +equal to the branch.
2113 +The list is refered in lookup, and when the current target inode is
2114 +found in the list, the aufs tries loading the "detailed info per
2115 +directory" and get the changed and valid name of the dir.
2117 +Theoretically these "extra informaiton" may be able to be put into XATTR
2118 +in the dir inode. But aufs doesn't choose this way because
2119 +1. XATTR may not be supported by the branch (or its configuration)
2120 +2. XATTR may have its size limit.
2121 +3. XATTR may be less easy to convert than a regular file, when the
2122 + format of the info is changed in the future.
2123 +At the same time, I agree that the regular file approach is much slower
2124 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2127 +This DIRREN feature is enabled by aufs configuration, and is activated
2128 +by a new mount option.
2130 +For the more complicated case, there is a work with UDBA option, which
2131 +is to dected the direct access to the branches (by-passing aufs) and to
2132 +maintain the cashes in aufs. Since a single cached aufs dentry may
2133 +contains two names, before- and after-rename, the name comparision in
2134 +UDBA handler may not work correctly. In this case, the behaviour will be
2135 +equivalen to udba=reval case.
2136 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2137 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2138 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2019-07-11 15:42:14.458904362 +0200
2141 +# Copyright (C) 2011-2019 Junjiro R. Okajima
2143 +# This program is free software; you can redistribute it and/or modify
2144 +# it under the terms of the GNU General Public License as published by
2145 +# the Free Software Foundation; either version 2 of the License, or
2146 +# (at your option) any later version.
2148 +# This program is distributed in the hope that it will be useful,
2149 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2150 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2151 +# GNU General Public License for more details.
2153 +# You should have received a copy of the GNU General Public License
2154 +# along with this program; if not, write to the Free Software
2155 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2158 +File-based Hierarchical Storage Management (FHSM)
2159 +----------------------------------------------------------------------
2160 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2161 +storage world. Aufs provides this feature as file-based with multiple
2162 +writable branches, based upon the principle of "Colder, the Lower".
2163 +Here the word "colder" means that the less used files, and "lower" means
2164 +that the position in the order of the stacked branches vertically.
2165 +These multiple writable branches are prioritized, ie. the topmost one
2166 +should be the fastest drive and be used heavily.
2168 +o Characters in aufs FHSM story
2169 +- aufs itself and a new branch attribute.
2170 +- a new ioctl interface to move-down and to establish a connection with
2171 + the daemon ("move-down" is a converse of "copy-up").
2172 +- userspace tool and daemon.
2174 +The userspace daemon establishes a connection with aufs and waits for
2175 +the notification. The notified information is very similar to struct
2176 +statfs containing the number of consumed blocks and inodes.
2177 +When the consumed blocks/inodes of a branch exceeds the user-specified
2178 +upper watermark, the daemon activates its move-down process until the
2179 +consumed blocks/inodes reaches the user-specified lower watermark.
2181 +The actual move-down is done by aufs based upon the request from
2182 +user-space since we need to maintain the inode number and the internal
2183 +pointer arrays in aufs.
2185 +Currently aufs FHSM handles the regular files only. Additionally they
2186 +must not be hard-linked nor pseudo-linked.
2189 +o Cowork of aufs and the user-space daemon
2190 + During the userspace daemon established the connection, aufs sends a
2191 + small notification to it whenever aufs writes something into the
2192 + writable branch. But it may cost high since aufs issues statfs(2)
2193 + internally. So user can specify a new option to cache the
2194 + info. Actually the notification is controlled by these factors.
2195 + + the specified cache time.
2196 + + classified as "force" by aufs internally.
2197 + Until the specified time expires, aufs doesn't send the info
2198 + except the forced cases. When aufs decide forcing, the info is always
2199 + notified to userspace.
2200 + For example, the number of free inodes is generally large enough and
2201 + the shortage of it happens rarely. So aufs doesn't force the
2202 + notification when creating a new file, directory and others. This is
2203 + the typical case which aufs doesn't force.
2204 + When aufs writes the actual filedata and the files consumes any of new
2205 + blocks, the aufs forces notifying.
2208 +o Interfaces in aufs
2209 +- New branch attribute.
2211 + Specifies that the branch is managed by FHSM feature. In other word,
2212 + participant in the FHSM.
2213 + When nofhsm is set to the branch, it will not be the source/target
2214 + branch of the move-down operation. This attribute is set
2215 + independently from coo and moo attributes, and if you want full
2216 + FHSM, you should specify them as well.
2217 +- New mount option.
2219 + Specifies a second to suppress many less important info to be
2222 + + AUFS_CTL_FHSM_FD
2223 + create a new file descriptor which userspace can read the notification
2224 + (a subset of struct statfs) from aufs.
2225 +- Module parameter 'brs'
2226 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2228 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2229 + When there are two or more branches with fhsm attributes,
2230 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2231 + terminates it. As a result of remounting and branch-manipulation, the
2232 + number of branches with fhsm attribute can be one. In this case,
2233 + /sbin/mount.aufs will terminate the user-space daemon.
2236 +Finally the operation is done as these steps in kernel-space.
2238 + + no one else is using the file.
2239 + + the file is not hard-linked.
2240 + + the file is not pseudo-linked.
2241 + + the file is a regular file.
2242 + + the parent dir is not opaqued.
2243 +- find the target writable branch.
2244 +- make sure the file is not whiteout-ed by the upper (than the target)
2246 +- make the parent dir on the target branch.
2247 +- mutex lock the inode on the branch.
2248 +- unlink the whiteout on the target branch (if exists).
2249 +- lookup and create the whiteout-ed temporary name on the target branch.
2250 +- copy the file as the whiteout-ed temporary name on the target branch.
2251 +- rename the whiteout-ed temporary name to the original name.
2252 +- unlink the file on the source branch.
2253 +- maintain the internal pointer array and the external inode number
2255 +- maintain the timestamps and other attributes of the parent dir and the
2258 +And of course, in every step, an error may happen. So the operation
2259 +should restore the original file state after an error happens.
2260 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2261 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2262 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2019-07-11 15:42:14.458904362 +0200
2265 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2267 +# This program is free software; you can redistribute it and/or modify
2268 +# it under the terms of the GNU General Public License as published by
2269 +# the Free Software Foundation; either version 2 of the License, or
2270 +# (at your option) any later version.
2272 +# This program is distributed in the hope that it will be useful,
2273 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2274 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2275 +# GNU General Public License for more details.
2277 +# You should have received a copy of the GNU General Public License
2278 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2280 +mmap(2) -- File Memory Mapping
2281 +----------------------------------------------------------------------
2282 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2283 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2285 +This approach is simple and good, but there is one problem.
2286 +Under /proc, several entries show the mmapped files by its path (with
2287 +device and inode number), and the printed path will be the path on the
2288 +branch fs's instead of virtual aufs's.
2289 +This is not a problem in most cases, but some utilities lsof(1) (and its
2290 +user) may expect the path on aufs.
2292 +To address this issue, aufs adds a new member called vm_prfile in struct
2293 +vm_area_struct (and struct vm_region). The original vm_file points to
2294 +the file on the branch fs in order to handle everything correctly as
2295 +usual. The new vm_prfile points to a virtual file in aufs, and the
2296 +show-functions in procfs refers to vm_prfile if it is set.
2297 +Also we need to maintain several other places where touching vm_file
2299 +- fork()/clone() copies vma and the reference count of vm_file is
2301 +- merging vma maintains the ref count too.
2303 +This is not a good approach. It just fakes the printed path. But it
2304 +leaves all behaviour around f_mapping unchanged. This is surely an
2306 +Actually aufs had adopted another complicated approach which calls
2307 +generic_file_mmap() and handles struct vm_operations_struct. In this
2308 +approach, aufs met a hard problem and I could not solve it without
2309 +switching the approach.
2311 +There may be one more another approach which is
2312 +- bind-mount the branch-root onto the aufs-root internally
2313 +- grab the new vfsmount (ie. struct mount)
2314 +- lazy-umount the branch-root internally
2315 +- in open(2) the aufs-file, open the branch-file with the hidden
2316 + vfsmount (instead of the original branch's vfsmount)
2317 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2318 + but it may be possible from userspace by the mount helper.
2320 +Adding the internal hidden vfsmount and using it in opening a file, the
2321 +file path under /proc will be printed correctly. This approach looks
2322 +smarter, but is not possible I am afraid.
2323 +- aufs-root may be bind-mount later. when it happens, another hidden
2324 + vfsmount will be required.
2325 +- it is hard to get the chance to bind-mount and lazy-umount
2326 + + in kernel-space, FS can have vfsmount in open(2) via
2327 + file->f_path, and aufs can know its vfsmount. But several locks are
2328 + already acquired, and if aufs tries to bind-mount and lazy-umount
2329 + here, then it may cause a deadlock.
2330 + + in user-space, bind-mount doesn't invoke the mount helper.
2331 +- since /proc shows dev and ino, aufs has to give vma these info. it
2332 + means a new member vm_prinode will be necessary. this is essentially
2333 + equivalent to vm_prfile described above.
2335 +I have to give up this "looks-smater" approach.
2336 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2337 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2338 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2019-07-11 15:42:14.458904362 +0200
2341 +# Copyright (C) 2014-2019 Junjiro R. Okajima
2343 +# This program is free software; you can redistribute it and/or modify
2344 +# it under the terms of the GNU General Public License as published by
2345 +# the Free Software Foundation; either version 2 of the License, or
2346 +# (at your option) any later version.
2348 +# This program is distributed in the hope that it will be useful,
2349 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2350 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2351 +# GNU General Public License for more details.
2353 +# You should have received a copy of the GNU General Public License
2354 +# along with this program; if not, write to the Free Software
2355 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2358 +Listing XATTR/EA and getting the value
2359 +----------------------------------------------------------------------
2360 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2361 +shows the values from the topmost existing file. This behaviour is good
2362 +for the non-dir entries since the bahaviour exactly matches the shown
2363 +information. But for the directories, aufs considers all the same named
2364 +entries on the lower branches. Which means, if one of the lower entry
2365 +rejects readdir call, then aufs returns an error even if the topmost
2366 +entry allows it. This behaviour is necessary to respect the branch fs's
2367 +security, but can make users confused since the user-visible standard
2368 +attributes don't match the behaviour.
2369 +To address this issue, aufs has a mount option called dirperm1 which
2370 +checks the permission for the topmost entry only, and ignores the lower
2371 +entry's permission.
2373 +A similar issue can happen around XATTR.
2374 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2375 +always set. Otherwise these very unpleasant situation would happen.
2376 +- listxattr(2) may return the duplicated entries.
2377 +- users may not be able to remove or reset the XATTR forever,
2380 +XATTR/EA support in the internal (copy,move)-(up,down)
2381 +----------------------------------------------------------------------
2382 +Generally the extended attributes of inode are categorized as these.
2383 +- "security" for LSM and capability.
2384 +- "system" for posix ACL, 'acl' mount option is required for the branch
2386 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2387 +- "user" for userspace, 'user_xattr' mount option is required for the
2388 + branch fs generally.
2390 +Moreover there are some other categories. Aufs handles these rather
2391 +unpopular categories as the ordinary ones, ie. there is no special
2392 +condition nor exception.
2394 +In copy-up, the support for XATTR on the dst branch may differ from the
2395 +src branch. In this case, the copy-up operation will get an error and
2396 +the original user operation which triggered the copy-up will fail. It
2397 +can happen that even all copy-up will fail.
2398 +When both of src and dst branches support XATTR and if an error occurs
2399 +during copying XATTR, then the copy-up should fail obviously. That is a
2400 +good reason and aufs should return an error to userspace. But when only
2401 +the src branch support that XATTR, aufs should not return an error.
2402 +For example, the src branch supports ACL but the dst branch doesn't
2403 +because the dst branch may natively un-support it or temporary
2404 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2405 +may NOT return an error even if the XATTR is not supported. It is
2406 +totally up to the branch fs.
2408 +Anyway when the aufs internal copy-up gets an error from the dst branch
2409 +fs, then aufs tries removing the just copied entry and returns the error
2410 +to the userspace. The worst case of this situation will be all copy-up
2413 +For the copy-up operation, there two basic approaches.
2414 +- copy the specified XATTR only (by category above), and return the
2415 + error unconditionally if it happens.
2416 +- copy all XATTR, and ignore the error on the specified category only.
2418 +In order to support XATTR and to implement the correct behaviour, aufs
2419 +chooses the latter approach and introduces some new branch attributes,
2420 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2421 +They correspond to the XATTR namespaces (see above). Additionally, to be
2422 +convenient, "icex" is also provided which means all "icex*" attributes
2423 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2425 +The meaning of these attributes is to ignore the error from setting
2426 +XATTR on that branch.
2427 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2428 +error from the dst branch according to the specified attributes.
2430 +Some XATTR may have its default value. The default value may come from
2431 +the parent dir or the environment. If the default value is set at the
2432 +file creating-time, it will be overwritten by copy-up.
2433 +Some contradiction may happen I am afraid.
2434 +Do we need another attribute to stop copying XATTR? I am unsure. For
2435 +now, aufs implements the branch attributes to ignore the error.
2436 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2437 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2438 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2019-07-11 15:42:14.458904362 +0200
2441 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2443 +# This program is free software; you can redistribute it and/or modify
2444 +# it under the terms of the GNU General Public License as published by
2445 +# the Free Software Foundation; either version 2 of the License, or
2446 +# (at your option) any later version.
2448 +# This program is distributed in the hope that it will be useful,
2449 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2450 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2451 +# GNU General Public License for more details.
2453 +# You should have received a copy of the GNU General Public License
2454 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2456 +Export Aufs via NFS
2457 +----------------------------------------------------------------------
2458 +Here is an approach.
2459 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2461 +- iget_locked(): initialize aufs inode generation for a new inode, and
2462 + store it in xigen file.
2463 +- destroy_inode(): increment aufs inode generation and store it in xigen
2464 + file. it is necessary even if it is not unlinked, because any data of
2465 + inode may be changed by UDBA.
2466 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2467 + build file handle by
2468 + + branch id (4 bytes)
2469 + + superblock generation (4 bytes)
2470 + + inode number (4 or 8 bytes)
2471 + + parent dir inode number (4 or 8 bytes)
2472 + + inode generation (4 bytes))
2473 + + return value of exportfs_encode_fh() for the parent on a branch (4
2475 + + file handle for a branch (by exportfs_encode_fh())
2477 + + find the index of a branch from its id in handle, and check it is
2478 + still exist in aufs.
2479 + + 1st level: get the inode number from handle and search it in cache.
2480 + + 2nd level: if not found in cache, get the parent inode number from
2481 + the handle and search it in cache. and then open the found parent
2482 + dir, find the matching inode number by vfs_readdir() and get its
2483 + name, and call lookup_one_len() for the target dentry.
2484 + + 3rd level: if the parent dir is not cached, call
2485 + exportfs_decode_fh() for a branch and get the parent on a branch,
2486 + build a pathname of it, convert it a pathname in aufs, call
2487 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2489 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2490 + for every branch, but not itself. to get this, (currently) aufs
2491 + searches in current->nsproxy->mnt_ns list. it may not be a good
2492 + idea, but I didn't get other approach.
2493 + + test the generation of the gotten inode.
2494 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2495 + convert it into ESTALE for NFSD.
2496 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2497 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2498 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2499 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2500 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2019-07-11 15:42:14.458904362 +0200
2503 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2505 +# This program is free software; you can redistribute it and/or modify
2506 +# it under the terms of the GNU General Public License as published by
2507 +# the Free Software Foundation; either version 2 of the License, or
2508 +# (at your option) any later version.
2510 +# This program is distributed in the hope that it will be useful,
2511 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2512 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2513 +# GNU General Public License for more details.
2515 +# You should have received a copy of the GNU General Public License
2516 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2518 +Show Whiteout Mode (shwh)
2519 +----------------------------------------------------------------------
2520 +Generally aufs hides the name of whiteouts. But in some cases, to show
2521 +them is very useful for users. For instance, creating a new middle layer
2522 +(branch) by merging existing layers.
2524 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2525 +When you have three branches,
2526 +- Bottom: 'system', squashfs (underlying base system), read-only
2527 +- Middle: 'mods', squashfs, read-only
2528 +- Top: 'overlay', ram (tmpfs), read-write
2530 +The top layer is loaded at boot time and saved at shutdown, to preserve
2531 +the changes made to the system during the session.
2532 +When larger changes have been made, or smaller changes have accumulated,
2533 +the size of the saved top layer data grows. At this point, it would be
2534 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2535 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2536 +restoring save and load speed.
2538 +This merging is simplified by the use of another aufs mount, of just the
2539 +two overlay branches using the 'shwh' option.
2540 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2541 + aufs /livesys/merge_union
2543 +A merged view of these two branches is then available at
2544 +/livesys/merge_union, and the new feature is that the whiteouts are
2546 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2547 +writing to all branches. Also the default mode for all branches is 'ro'.
2548 +It is now possible to save the combined contents of the two overlay
2549 +branches to a new squashfs, e.g.:
2550 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2552 +This new squashfs archive can be stored on the boot device and the
2553 +initramfs will use it to replace the old one at the next boot.
2554 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2555 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2556 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2019-07-11 15:42:14.458904362 +0200
2559 +# Copyright (C) 2010-2019 Junjiro R. Okajima
2561 +# This program is free software; you can redistribute it and/or modify
2562 +# it under the terms of the GNU General Public License as published by
2563 +# the Free Software Foundation; either version 2 of the License, or
2564 +# (at your option) any later version.
2566 +# This program is distributed in the hope that it will be useful,
2567 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2568 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2569 +# GNU General Public License for more details.
2571 +# You should have received a copy of the GNU General Public License
2572 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2574 +Dynamically customizable FS operations
2575 +----------------------------------------------------------------------
2576 +Generally FS operations (struct inode_operations, struct
2577 +address_space_operations, struct file_operations, etc.) are defined as
2578 +"static const", but it never means that FS have only one set of
2579 +operation. Some FS have multiple sets of them. For instance, ext2 has
2580 +three sets, one for XIP, for NOBH, and for normal.
2581 +Since aufs overrides and redirects these operations, sometimes aufs has
2582 +to change its behaviour according to the branch FS type. More importantly
2583 +VFS acts differently if a function (member in the struct) is set or
2584 +not. It means aufs should have several sets of operations and select one
2585 +among them according to the branch FS definition.
2587 +In order to solve this problem and not to affect the behaviour of VFS,
2588 +aufs defines these operations dynamically. For instance, aufs defines
2589 +dummy direct_IO function for struct address_space_operations, but it may
2590 +not be set to the address_space_operations actually. When the branch FS
2591 +doesn't have it, aufs doesn't set it to its address_space_operations
2592 +while the function definition itself is still alive. So the behaviour
2593 +itself will not change, and it will return an error when direct_IO is
2596 +The lifetime of these dynamically generated operation object is
2597 +maintained by aufs branch object. When the branch is removed from aufs,
2598 +the reference counter of the object is decremented. When it reaches
2599 +zero, the dynamically generated operation object will be freed.
2601 +This approach is designed to support AIO (io_submit), Direct I/O and
2603 +Currently this approach is applied to address_space_operations for
2604 +regular files only.
2605 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2606 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2607 +++ linux/Documentation/filesystems/aufs/README 2019-07-11 15:42:14.455570938 +0200
2610 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2616 +----------------------------------------
2617 +In the early days, aufs was entirely re-designed and re-implemented
2618 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2619 +improvements and implementations, it became totally different from
2620 +Unionfs while keeping the basic features.
2621 +Later, Unionfs Version 2.x series began taking some of the same
2622 +approaches to aufs1's.
2623 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2624 +University and his team.
2626 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2628 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2629 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2630 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2631 + or aufs1 from CVS on SourceForge.
2633 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2634 + According to Christoph Hellwig, linux rejects all union-type
2635 + filesystems but UnionMount.
2636 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2638 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2639 + UnionMount, and he pointed out an issue around a directory mutex
2640 + lock and aufs addressed it. But it is still unsure whether aufs will
2641 + be merged (or any other union solution).
2642 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2646 +----------------------------------------
2647 +- unite several directories into a single virtual filesystem. The member
2648 + directory is called as a branch.
2649 +- you can specify the permission flags to the branch, which are 'readonly',
2650 + 'readwrite' and 'whiteout-able.'
2651 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2652 + readonly branch are modifiable logically.
2653 +- dynamic branch manipulation, add, del.
2656 +Also there are many enhancements in aufs, such as:
2657 +- test only the highest one for the directory permission (dirperm1)
2658 +- copyup on open (coo=)
2659 +- 'move' policy for copy-up between two writable branches, after
2660 + checking free space.
2662 +- readdir(3) in userspace.
2663 +- keep inode number by external inode number table
2664 +- keep the timestamps of file/dir in internal copyup operation
2665 +- seekable directory, supporting NFS readdir.
2666 +- whiteout is hardlinked in order to reduce the consumption of inodes
2668 +- do not copyup, nor create a whiteout when it is unnecessary
2669 +- revert a single systemcall when an error occurs in aufs
2670 +- remount interface instead of ioctl
2671 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2672 +- loopback mounted filesystem as a branch
2673 +- kernel thread for removing the dir who has a plenty of whiteouts
2674 +- support copyup sparse file (a file which has a 'hole' in it)
2675 +- default permission flags for branches
2676 +- selectable permission flags for ro branch, whether whiteout can
2679 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2680 +- support multiple writable branches, some policies to select one
2681 + among multiple writable branches.
2682 +- a new semantics for link(2) and rename(2) to support multiple
2683 + writable branches.
2684 +- no glibc changes are required.
2685 +- pseudo hardlink (hardlink over branches)
2686 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2687 + including NFS or remote filesystem branch.
2688 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2691 +Currently these features are dropped temporary from aufs5.
2692 +See design/08plan.txt in detail.
2693 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2695 +- statistics of aufs thread (/sys/fs/aufs/stat)
2697 +Features or just an idea in the future (see also design/*.txt),
2698 +- reorder the branch index without del/re-add.
2699 +- permanent xino files for NFSD
2700 +- an option for refreshing the opened files after add/del branches
2701 +- light version, without branch manipulation. (unnecessary?)
2702 +- copyup in userspace
2703 +- inotify in userspace
2708 +----------------------------------------
2709 +There are three GIT trees for aufs5, aufs5-linux.git,
2710 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2712 +While the aufs-util is always necessary, you need either of aufs5-linux
2713 +or aufs5-standalone.
2715 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2716 +git://git.kernel.org/.../torvalds/linux.git.
2717 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2718 +build aufs5 as an external kernel module.
2719 +Several extra patches are not included in this tree. Only
2720 +aufs5-standalone tree contains them. They are described in the later
2721 +section "Configuration and Compilation."
2723 +On the other hand, the aufs5-standalone tree has only aufs source files
2724 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2725 +But you need to apply all aufs patches manually.
2727 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2728 +represents the linux kernel version, "linux-5.x". For instance,
2729 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2730 +"aufs5.x-rcN" branch.
2733 +$ git clone --reference /your/linux/git/tree \
2734 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2735 +- if you don't have linux GIT tree, then remove "--reference ..."
2736 +$ cd aufs5-linux.git
2737 +$ git checkout origin/aufs5.0
2739 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2740 +leave the patch-work to GIT.
2741 +$ cd /your/linux/git/tree
2742 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2744 +$ git checkout -b my5.0 v5.0
2745 +$ (add your local change...)
2746 +$ git pull aufs5 aufs5.0
2747 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2748 +- you may need to solve some conflicts between your_changes and
2749 + aufs5.0. in this case, git-rerere is recommended so that you can
2750 + solve the similar conflicts automatically when you upgrade to 5.1 or
2751 + later in the future.
2753 +o aufs5-standalone tree
2754 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2755 +$ cd aufs5-standalone.git
2756 +$ git checkout origin/aufs5.0
2759 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2760 +- note that the public aufs-util.git is on SourceForge instead of
2763 +$ git checkout origin/aufs5.0
2765 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2766 +The minor version number, 'x' in '5.x', of aufs may not always
2767 +follow the minor version number of the kernel.
2768 +Because changes in the kernel that cause the use of a new
2769 +minor version number do not always require changes to aufs-util.
2771 +Since aufs-util has its own minor version number, you may not be
2772 +able to find a GIT branch in aufs-util for your kernel's
2773 +exact minor version number.
2774 +In this case, you should git-checkout the branch for the
2775 +nearest lower number.
2777 +For (an unreleased) example:
2778 +If you are using "linux-5.10" and the "aufs5.10" branch
2779 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2780 +or something numerically smaller is the branch for your kernel.
2782 +Also you can view all branches by
2786 +3. Configuration and Compilation
2787 +----------------------------------------
2788 +Make sure you have git-checkout'ed the correct branch.
2790 +For aufs5-linux tree,
2791 +- enable CONFIG_AUFS_FS.
2792 +- set other aufs configurations if necessary.
2794 +For aufs5-standalone tree,
2795 +There are several ways to build.
2798 +- apply ./aufs5-kbuild.patch to your kernel source files.
2799 +- apply ./aufs5-base.patch too.
2800 +- apply ./aufs5-mmap.patch too.
2801 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2802 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2803 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2804 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2805 +- enable CONFIG_AUFS_FS, you can select either
2807 +- and build your kernel as usual.
2808 +- install the built kernel.
2809 +- install the header files too by "make headers_install" to the
2810 + directory where you specify. By default, it is $PWD/usr.
2811 + "make help" shows a brief note for headers_install.
2812 +- and reboot your system.
2815 +- module only (CONFIG_AUFS_FS=m).
2816 +- apply ./aufs5-base.patch to your kernel source files.
2817 +- apply ./aufs5-mmap.patch too.
2818 +- apply ./aufs5-standalone.patch too.
2819 +- build your kernel, don't forget "make headers_install", and reboot.
2820 +- edit ./config.mk and set other aufs configurations if necessary.
2821 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2822 + every aufs configurations.
2823 +- build the module by simple "make".
2824 +- you can specify ${KDIR} make variable which points to your kernel
2826 +- install the files
2827 + + run "make install" to install the aufs module, or copy the built
2828 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2829 + + run "make install_headers" (instead of headers_install) to install
2830 + the modified aufs header file (you can specify DESTDIR which is
2831 + available in aufs standalone version's Makefile only), or copy
2832 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2833 + you like manually. By default, the target directory is $PWD/usr.
2834 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2835 + kernel source tree.
2837 +Note: The header file aufs_type.h is necessary to build aufs-util
2838 + as well as "make headers_install" in the kernel source tree.
2839 + headers_install is subject to be forgotten, but it is essentially
2840 + necessary, not only for building aufs-util.
2841 + You may not meet problems without headers_install in some older
2845 +- read README in aufs-util, build and install it
2846 +- note that your distribution may contain an obsoleted version of
2847 + aufs_type.h in /usr/include/linux or something. When you build aufs
2848 + utilities, make sure that your compiler refers the correct aufs header
2849 + file which is built by "make headers_install."
2850 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2851 + then run "make install_ulib" too. And refer to the aufs manual in
2854 +There several other patches in aufs5-standalone.git. They are all
2855 +optional. When you meet some problems, they will help you.
2856 +- aufs5-loopback.patch
2857 + Supports a nested loopback mount in a branch-fs. This patch is
2858 + unnecessary until aufs produces a message like "you may want to try
2859 + another patch for loopback file".
2860 +- proc_mounts.patch
2861 + When there are many mountpoints and many mount(2)/umount(2) are
2862 + running, then /proc/mounts may not show the all mountpoints. This
2863 + patch makes /proc/mounts always show the full mountpoints list.
2864 + If you don't want to apply this patch and meet such problem, then you
2865 + need to increase the value of 'ProcMounts_Times' make-variable in
2866 + aufs-util.git as a second best solution.
2868 + Modifies a system global kernel internal function get_next_ino() in
2869 + order to stop assigning 0 for an inode-number. Not directly related to
2870 + aufs, but recommended generally.
2872 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2873 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2874 + duplication of inode number, which is important for backup tools and
2875 + other utilities. When you find aufs XINO files for tmpfs branch
2876 + growing too much, try this patch.
2877 +- lockdep-debug.patch
2878 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2879 + also a caller of VFS functions for branch filesystems, subclassing of
2880 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2881 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2882 + need to apply this debug patch to expand several constant values.
2883 + If don't know what LOCKDEP is, then you don't have apply this patch.
2887 +----------------------------------------
2888 +At first, make sure aufs-util are installed, and please read the aufs
2889 +manual, aufs.5 in aufs-util.git tree.
2893 +$ mkdir /tmp/rw /tmp/aufs
2894 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2896 +Here is another example. The result is equivalent.
2897 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2899 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2900 +# mount -o remount,append:${HOME} /tmp/aufs
2902 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2903 +you modify a file under /tmp/aufs, the one on your home directory is
2904 +not affected, instead the same named file will be newly created under
2905 +/tmp/rw. And all of your modification to a file will be applied to
2906 +the one under /tmp/rw. This is called the file based Copy on Write
2908 +Aufs mount options are described in aufs.5.
2909 +If you run chroot or something and make your aufs as a root directory,
2910 +then you need to customize the shutdown script. See the aufs manual in
2913 +Additionally, there are some sample usages of aufs which are a
2914 +diskless system with network booting, and LiveCD over NFS.
2915 +See sample dir in CVS tree on SourceForge.
2919 +----------------------------------------
2920 +When you have any problems or strange behaviour in aufs, please let me
2922 +- /proc/mounts (instead of the output of mount(8))
2923 +- /sys/module/aufs/*
2924 +- /sys/fs/aufs/* (if you have them)
2925 +- /debug/aufs/* (if you have them)
2926 +- linux kernel version
2927 + if your kernel is not plain, for example modified by distributor,
2928 + the url where i can download its source is necessary too.
2929 +- aufs version which was printed at loading the module or booting the
2930 + system, instead of the date you downloaded.
2931 +- configuration (define/undefine CONFIG_AUFS_xxx)
2932 +- kernel configuration or /proc/config.gz (if you have it)
2933 +- behaviour which you think to be incorrect
2934 +- actual operation, reproducible one is better
2935 +- mailto: aufs-users at lists.sourceforge.net
2937 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2938 +and Feature Requests) on SourceForge. Please join and write to
2942 +6. Acknowledgements
2943 +----------------------------------------
2944 +Thanks to everyone who have tried and are using aufs, whoever
2945 +have reported a bug or any feedback.
2947 +Especially donators:
2948 +Tomas Matejicek(slax.org) made a donation (much more than once).
2949 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2950 + scripts) is making "doubling" donations.
2951 + Unfortunately I cannot list all of the donators, but I really
2953 + It ends Aug 2010, but the ordinary donation URL is still available.
2954 + <http://sourceforge.net/donate/index.php?group_id=167503>
2955 +Dai Itasaka made a donation (2007/8).
2956 +Chuck Smith made a donation (2008/4, 10 and 12).
2957 +Henk Schoneveld made a donation (2008/9).
2958 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2959 +Francois Dupoux made a donation (2008/11).
2960 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2961 + aufs2 GIT tree (2009/2).
2962 +William Grant made a donation (2009/3).
2963 +Patrick Lane made a donation (2009/4).
2964 +The Mail Archive (mail-archive.com) made donations (2009/5).
2965 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2966 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2967 +Pavel Pronskiy made a donation (2011/2).
2968 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2969 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2970 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2972 +Sam Liddicott made a donation (2011/9).
2973 +Era Scarecrow made a donation (2013/4).
2974 +Bor Ratajc made a donation (2013/4).
2975 +Alessandro Gorreta made a donation (2013/4).
2976 +POIRETTE Marc made a donation (2013/4).
2977 +Alessandro Gorreta made a donation (2013/4).
2978 +lauri kasvandik made a donation (2013/5).
2979 +"pemasu from Finland" made a donation (2013/7).
2980 +The Parted Magic Project made a donation (2013/9 and 11).
2981 +Pavel Barta made a donation (2013/10).
2982 +Nikolay Pertsev made a donation (2014/5).
2983 +James B made a donation (2014/7 and 2015/7).
2984 +Stefano Di Biase made a donation (2014/8).
2985 +Daniel Epellei made a donation (2015/1).
2986 +OmegaPhil made a donation (2016/1, 2018/4).
2987 +Tomasz Szewczyk made a donation (2016/4).
2988 +James Burry made a donation (2016/12).
2989 +Carsten Rose made a donation (2018/9).
2990 +Porteus Kiosk made a donation (2018/10).
2992 +Thank you very much.
2993 +Donations are always, including future donations, very important and
2994 +helpful for me to keep on developing aufs.
2998 +----------------------------------------
2999 +If you are an experienced user, no explanation is needed. Aufs is
3000 +just a linux filesystem.
3005 +# Local variables: ;
3008 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3009 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3010 +++ linux/fs/aufs/aufs.h 2019-07-11 15:42:14.462237786 +0200
3012 +/* SPDX-License-Identifier: GPL-2.0 */
3014 + * Copyright (C) 2005-2019 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 + * all header files
3039 +#define AuStub(type, name, body, ...) \
3040 + static inline type name(__VA_ARGS__) { body; }
3042 +#define AuStubVoid(name, ...) \
3043 + AuStub(void, name, , __VA_ARGS__)
3044 +#define AuStubInt0(name, ...) \
3045 + AuStub(int, name, return 0, __VA_ARGS__)
3049 +#include "branch.h"
3052 +#include "dbgaufs.h"
3053 +#include "dentry.h"
3055 +#include "dirren.h"
3058 +#include "fstype.h"
3063 +#include "module.h"
3067 +#include "sysaufs.h"
3072 +#endif /* __KERNEL__ */
3073 +#endif /* __AUFS_H__ */
3074 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3075 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3076 +++ linux/fs/aufs/branch.c 2019-09-16 09:38:43.216175640 +0200
3078 +// SPDX-License-Identifier: GPL-2.0
3080 + * Copyright (C) 2005-2019 Junjiro R. Okajima
3082 + * This program, aufs is free software; you can redistribute it and/or modify
3083 + * it under the terms of the GNU General Public License as published by
3084 + * the Free Software Foundation; either version 2 of the License, or
3085 + * (at your option) any later version.
3087 + * This program is distributed in the hope that it will be useful,
3088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3090 + * GNU General Public License for more details.
3092 + * You should have received a copy of the GNU General Public License
3093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3097 + * branch management
3100 +#include <linux/compat.h>
3101 +#include <linux/statfs.h>
3105 + * free a single branch
3107 +static void au_br_do_free(struct au_branch *br)
3110 + struct au_wbr *wbr;
3111 + struct au_dykey **key;
3113 + au_hnotify_fin_br(br);
3114 + /* always, regardless the mount option */
3115 + au_dr_hino_free(&br->br_dirren);
3118 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3119 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3120 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3121 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3125 + for (i = 0; i < AuBrWh_Last; i++)
3126 + dput(wbr->wbr_wh[i]);
3127 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3128 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3131 + if (br->br_fhsm) {
3132 + au_br_fhsm_fin(br->br_fhsm);
3133 + au_kfree_try_rcu(br->br_fhsm);
3136 + key = br->br_dykey;
3137 + for (i = 0; i < AuBrDynOp; i++, key++)
3143 + /* recursive lock, s_umount of branch's */
3144 + /* synchronize_rcu(); */ /* why? */
3146 + path_put(&br->br_path);
3148 + au_kfree_rcu(wbr);
3149 + au_lcnt_wait_for_fin(&br->br_nfiles);
3150 + au_lcnt_wait_for_fin(&br->br_count);
3151 + /* I don't know why, but percpu_refcount requires this */
3152 + /* synchronize_rcu(); */
3157 + * frees all branches
3159 +void au_br_free(struct au_sbinfo *sbinfo)
3161 + aufs_bindex_t bmax;
3162 + struct au_branch **br;
3164 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3166 + bmax = sbinfo->si_bbot + 1;
3167 + br = sbinfo->si_branch;
3169 + au_br_do_free(*br++);
3173 + * find the index of a branch which is specified by @br_id.
3175 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3177 + aufs_bindex_t bindex, bbot;
3179 + bbot = au_sbbot(sb);
3180 + for (bindex = 0; bindex <= bbot; bindex++)
3181 + if (au_sbr_id(sb, bindex) == br_id)
3186 +/* ---------------------------------------------------------------------- */
3192 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3193 + struct dentry *h_root)
3195 + if (unlikely(h_adding == h_root
3196 + || au_test_loopback_overlap(sb, h_adding)))
3198 + if (h_adding->d_sb != h_root->d_sb)
3200 + return au_test_subdir(h_adding, h_root)
3201 + || au_test_subdir(h_root, h_adding);
3205 + * returns a newly allocated branch. @new_nbranch is a number of branches
3206 + * after adding a branch.
3208 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3211 + struct au_branch *add_branch;
3212 + struct dentry *root;
3213 + struct inode *inode;
3217 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3218 + if (unlikely(!add_branch))
3220 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3221 + if (unlikely(!add_branch->br_xino))
3223 + err = au_hnotify_init_br(add_branch, perm);
3224 + if (unlikely(err))
3227 + if (au_br_writable(perm)) {
3228 + /* may be freed separately at changing the branch permission */
3229 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3231 + if (unlikely(!add_branch->br_wbr))
3235 + if (au_br_fhsm(perm)) {
3236 + err = au_fhsm_br_alloc(add_branch);
3237 + if (unlikely(err))
3241 + root = sb->s_root;
3242 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3244 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3246 + inode = d_inode(root);
3247 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3251 + return add_branch; /* success */
3254 + au_kfree_rcu(add_branch->br_wbr);
3256 + au_hnotify_fin_br(add_branch);
3258 + au_xino_put(add_branch);
3260 + au_kfree_rcu(add_branch);
3262 + return ERR_PTR(err);
3266 + * test if the branch permission is legal or not.
3268 +static int test_br(struct inode *inode, int brperm, char *path)
3272 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3277 + pr_err("write permission for readonly mount or inode, %s\n", path);
3285 + * 0: success, the caller will add it
3286 + * plus: success, it is already unified, the caller should ignore it
3289 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3292 + aufs_bindex_t bbot, bindex;
3293 + struct dentry *root, *h_dentry;
3294 + struct inode *inode, *h_inode;
3296 + root = sb->s_root;
3297 + bbot = au_sbbot(sb);
3298 + if (unlikely(bbot >= 0
3299 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3303 + pr_err("%s duplicated\n", add->pathname);
3308 + err = -ENOSPC; /* -E2BIG; */
3309 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3310 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3311 + pr_err("number of branches exceeded %s\n", add->pathname);
3316 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3317 + pr_err("bad index %d\n", add->bindex);
3321 + inode = d_inode(add->path.dentry);
3323 + if (unlikely(!inode->i_nlink)) {
3324 + pr_err("no existence %s\n", add->pathname);
3329 + if (unlikely(inode->i_sb == sb)) {
3330 + pr_err("%s must be outside\n", add->pathname);
3334 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3335 + pr_err("unsupported filesystem, %s (%s)\n",
3336 + add->pathname, au_sbtype(inode->i_sb));
3340 + if (unlikely(inode->i_sb->s_stack_depth)) {
3341 + pr_err("already stacked, %s (%s)\n",
3342 + add->pathname, au_sbtype(inode->i_sb));
3346 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3347 + if (unlikely(err))
3351 + return 0; /* success */
3354 + for (bindex = 0; bindex <= bbot; bindex++)
3355 + if (unlikely(test_overlap(sb, add->path.dentry,
3356 + au_h_dptr(root, bindex)))) {
3357 + pr_err("%s is overlapped\n", add->pathname);
3362 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3363 + h_dentry = au_h_dptr(root, 0);
3364 + h_inode = d_inode(h_dentry);
3365 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3366 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3367 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3368 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3370 + i_uid_read(inode), i_gid_read(inode),
3371 + (inode->i_mode & S_IALLUGO),
3372 + i_uid_read(h_inode), i_gid_read(h_inode),
3373 + (h_inode->i_mode & S_IALLUGO));
3381 + * initialize or clean the whiteouts for an adding branch
3383 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3386 + int err, old_perm;
3387 + aufs_bindex_t bindex;
3388 + struct inode *h_inode;
3389 + struct au_wbr *wbr;
3390 + struct au_hinode *hdir;
3391 + struct dentry *h_dentry;
3393 + err = vfsub_mnt_want_write(au_br_mnt(br));
3394 + if (unlikely(err))
3398 + old_perm = br->br_perm;
3399 + br->br_perm = new_perm;
3402 + bindex = au_br_index(sb, br->br_id);
3403 + if (0 <= bindex) {
3404 + hdir = au_hi(d_inode(sb->s_root), bindex);
3405 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3407 + h_dentry = au_br_dentry(br);
3408 + h_inode = d_inode(h_dentry);
3409 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3412 + err = au_wh_init(br, sb);
3414 + wbr_wh_write_lock(wbr);
3415 + err = au_wh_init(br, sb);
3416 + wbr_wh_write_unlock(wbr);
3419 + au_hn_inode_unlock(hdir);
3421 + inode_unlock(h_inode);
3422 + vfsub_mnt_drop_write(au_br_mnt(br));
3423 + br->br_perm = old_perm;
3425 + if (!err && wbr && !au_br_writable(new_perm)) {
3426 + au_kfree_rcu(wbr);
3427 + br->br_wbr = NULL;
3434 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3438 + struct kstatfs kst;
3439 + struct au_wbr *wbr;
3442 + au_rw_init(&wbr->wbr_wh_rwsem);
3443 + atomic_set(&wbr->wbr_wh_running, 0);
3446 + * a limit for rmdir/rename a dir
3447 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3449 + err = vfs_statfs(&br->br_path, &kst);
3450 + if (unlikely(err))
3453 + if (kst.f_namelen >= NAME_MAX)
3454 + err = au_br_init_wh(sb, br, perm);
3456 + pr_err("%pd(%s), unsupported namelen %ld\n",
3458 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3464 +/* initialize a new branch */
3465 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3466 + struct au_opt_add *add)
3469 + struct au_branch *brbase;
3471 + struct inode *h_inode;
3474 + br->br_perm = add->perm;
3475 + br->br_path = add->path; /* set first, path_get() later */
3476 + spin_lock_init(&br->br_dykey_lock);
3477 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3478 + au_lcnt_init(&br->br_count, /*release*/NULL);
3479 + br->br_id = au_new_br_id(sb);
3480 + AuDebugOn(br->br_id < 0);
3482 + /* always, regardless the given option */
3483 + err = au_dr_br_init(sb, br, &add->path);
3484 + if (unlikely(err))
3487 + if (au_br_writable(add->perm)) {
3488 + err = au_wbr_init(br, sb, add->perm);
3489 + if (unlikely(err))
3493 + if (au_opt_test(au_mntflags(sb), XINO)) {
3494 + brbase = au_sbr(sb, 0);
3495 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3497 + h_inode = d_inode(add->path.dentry);
3498 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3499 + if (unlikely(err)) {
3500 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3505 + sysaufs_br_init(br);
3506 + path_get(&br->br_path);
3507 + goto out; /* success */
3510 + memset(&br->br_path, 0, sizeof(br->br_path));
3515 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3516 + struct au_branch *br, aufs_bindex_t bbot,
3517 + aufs_bindex_t amount)
3519 + struct au_branch **brp;
3521 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3523 + brp = sbinfo->si_branch + bindex;
3524 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3526 + sbinfo->si_bbot++;
3527 + if (unlikely(bbot < 0))
3528 + sbinfo->si_bbot = 0;
3531 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3532 + aufs_bindex_t bbot, aufs_bindex_t amount)
3534 + struct au_hdentry *hdp;
3536 + AuRwMustWriteLock(&dinfo->di_rwsem);
3538 + hdp = au_hdentry(dinfo, bindex);
3539 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3540 + au_h_dentry_init(hdp);
3542 + if (unlikely(bbot < 0))
3543 + dinfo->di_btop = 0;
3546 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3547 + aufs_bindex_t bbot, aufs_bindex_t amount)
3549 + struct au_hinode *hip;
3551 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3553 + hip = au_hinode(iinfo, bindex);
3554 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3555 + au_hinode_init(hip);
3557 + if (unlikely(bbot < 0))
3558 + iinfo->ii_btop = 0;
3561 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3562 + aufs_bindex_t bindex)
3564 + struct dentry *root, *h_dentry;
3565 + struct inode *root_inode, *h_inode;
3566 + aufs_bindex_t bbot, amount;
3568 + root = sb->s_root;
3569 + root_inode = d_inode(root);
3570 + bbot = au_sbbot(sb);
3571 + amount = bbot + 1 - bindex;
3572 + h_dentry = au_br_dentry(br);
3573 + au_sbilist_lock();
3574 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3575 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3576 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3577 + au_set_h_dptr(root, bindex, dget(h_dentry));
3578 + h_inode = d_inode(h_dentry);
3579 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3580 + au_sbilist_unlock();
3583 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3586 + aufs_bindex_t bbot, add_bindex;
3587 + struct dentry *root, *h_dentry;
3588 + struct inode *root_inode;
3589 + struct au_branch *add_branch;
3591 + root = sb->s_root;
3592 + root_inode = d_inode(root);
3593 + IMustLock(root_inode);
3594 + IiMustWriteLock(root_inode);
3595 + err = test_add(sb, add, remount);
3596 + if (unlikely(err < 0))
3600 + goto out; /* success */
3603 + bbot = au_sbbot(sb);
3604 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3605 + err = PTR_ERR(add_branch);
3606 + if (IS_ERR(add_branch))
3609 + err = au_br_init(add_branch, sb, add);
3610 + if (unlikely(err)) {
3611 + au_br_do_free(add_branch);
3615 + add_bindex = add->bindex;
3616 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3617 + au_br_do_add(sb, add_branch, add_bindex);
3618 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3619 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3621 + h_dentry = add->path.dentry;
3622 + if (!add_bindex) {
3623 + au_cpup_attr_all(root_inode, /*force*/1);
3624 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3626 + au_add_nlink(root_inode, d_inode(h_dentry));
3632 +/* ---------------------------------------------------------------------- */
3634 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3635 + unsigned long long max __maybe_unused,
3638 + unsigned long long n;
3639 + struct file **p, *f;
3640 + struct hlist_bl_head *files;
3641 + struct hlist_bl_node *pos;
3642 + struct au_finfo *finfo;
3646 + files = &au_sbi(sb)->si_files;
3647 + hlist_bl_lock(files);
3648 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3649 + f = finfo->fi_file;
3651 + && !special_file(file_inode(f)->i_mode)) {
3655 + AuDebugOn(n > max);
3658 + hlist_bl_unlock(files);
3663 +static struct file **au_farray_alloc(struct super_block *sb,
3664 + unsigned long long *max)
3666 + struct au_sbinfo *sbi;
3669 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3670 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3673 +static void au_farray_free(struct file **a, unsigned long long max)
3675 + unsigned long long ull;
3677 + for (ull = 0; ull < max; ull++)
3683 +/* ---------------------------------------------------------------------- */
3689 +/* to show the line number, do not make it inlined function */
3690 +#define AuVerbose(do_info, fmt, ...) do { \
3692 + pr_info(fmt, ##__VA_ARGS__); \
3695 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3696 + aufs_bindex_t bbot)
3698 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3701 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3702 + aufs_bindex_t bbot)
3704 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3708 + * test if the branch is deletable or not.
3710 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3711 + unsigned int sigen, const unsigned int verbose)
3713 + int err, i, j, ndentry;
3714 + aufs_bindex_t btop, bbot;
3715 + struct au_dcsub_pages dpages;
3716 + struct au_dpage *dpage;
3719 + err = au_dpages_init(&dpages, GFP_NOFS);
3720 + if (unlikely(err))
3722 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3723 + if (unlikely(err))
3726 + for (i = 0; !err && i < dpages.ndpage; i++) {
3727 + dpage = dpages.dpages + i;
3728 + ndentry = dpage->ndentry;
3729 + for (j = 0; !err && j < ndentry; j++) {
3730 + d = dpage->dentries[j];
3731 + AuDebugOn(au_dcount(d) <= 0);
3732 + if (!au_digen_test(d, sigen)) {
3733 + di_read_lock_child(d, AuLock_IR);
3734 + if (unlikely(au_dbrange_test(d))) {
3735 + di_read_unlock(d, AuLock_IR);
3739 + di_write_lock_child(d);
3740 + if (unlikely(au_dbrange_test(d))) {
3741 + di_write_unlock(d);
3744 + err = au_reval_dpath(d, sigen);
3746 + di_downgrade_lock(d, AuLock_IR);
3748 + di_write_unlock(d);
3753 + /* AuDbgDentry(d); */
3754 + btop = au_dbtop(d);
3755 + bbot = au_dbbot(d);
3756 + if (btop <= bindex
3758 + && au_h_dptr(d, bindex)
3759 + && au_test_dbusy(d, btop, bbot)) {
3761 + AuVerbose(verbose, "busy %pd\n", d);
3764 + di_read_unlock(d, AuLock_IR);
3769 + au_dpages_free(&dpages);
3774 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3775 + unsigned int sigen, const unsigned int verbose)
3778 + unsigned long long max, ull;
3779 + struct inode *i, **array;
3780 + aufs_bindex_t btop, bbot;
3782 + array = au_iarray_alloc(sb, &max);
3783 + err = PTR_ERR(array);
3784 + if (IS_ERR(array))
3788 + AuDbg("b%d\n", bindex);
3789 + for (ull = 0; !err && ull < max; ull++) {
3793 + if (i->i_ino == AUFS_ROOT_INO)
3796 + /* AuDbgInode(i); */
3797 + if (au_iigen(i, NULL) == sigen)
3798 + ii_read_lock_child(i);
3800 + ii_write_lock_child(i);
3801 + err = au_refresh_hinode_self(i);
3804 + ii_downgrade_lock(i);
3806 + ii_write_unlock(i);
3811 + btop = au_ibtop(i);
3812 + bbot = au_ibbot(i);
3813 + if (btop <= bindex
3815 + && au_h_iptr(i, bindex)
3816 + && au_test_ibusy(i, btop, bbot)) {
3818 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3821 + ii_read_unlock(i);
3823 + au_iarray_free(array, max);
3829 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3830 + const unsigned int verbose)
3833 + unsigned int sigen;
3835 + sigen = au_sigen(root->d_sb);
3836 + DiMustNoWaiters(root);
3837 + IiMustNoWaiters(d_inode(root));
3838 + di_write_unlock(root);
3839 + err = test_dentry_busy(root, bindex, sigen, verbose);
3841 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3842 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3847 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3848 + struct file **to_free, int *idx)
3851 + unsigned char matched, root;
3852 + aufs_bindex_t bindex, bbot;
3853 + struct au_fidir *fidir;
3854 + struct au_hfile *hfile;
3857 + root = IS_ROOT(file->f_path.dentry);
3860 + to_free[*idx] = file;
3866 + fidir = au_fi(file)->fi_hdir;
3867 + AuDebugOn(!fidir);
3868 + bbot = au_fbbot_dir(file);
3869 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3870 + hfile = fidir->fd_hfile + bindex;
3871 + if (!hfile->hf_file)
3874 + if (hfile->hf_br->br_id == br_id) {
3886 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3887 + struct file **to_free, int opened)
3890 + unsigned long long ull, max;
3891 + aufs_bindex_t btop;
3892 + struct file *file, **array;
3893 + struct dentry *root;
3894 + struct au_hfile *hfile;
3896 + array = au_farray_alloc(sb, &max);
3897 + err = PTR_ERR(array);
3898 + if (IS_ERR(array))
3903 + root = sb->s_root;
3904 + di_write_unlock(root);
3905 + for (ull = 0; ull < max; ull++) {
3906 + file = array[ull];
3907 + if (unlikely(!file))
3910 + /* AuDbg("%pD\n", file); */
3911 + fi_read_lock(file);
3912 + btop = au_fbtop(file);
3913 + if (!d_is_dir(file->f_path.dentry)) {
3914 + hfile = &au_fi(file)->fi_htop;
3915 + if (hfile->hf_br->br_id == br_id)
3918 + err = test_dir_busy(file, br_id, to_free, &idx);
3919 + fi_read_unlock(file);
3920 + if (unlikely(err))
3923 + di_write_lock_child(root);
3924 + au_farray_free(array, max);
3925 + AuDebugOn(idx > opened);
3931 +static void br_del_file(struct file **to_free, unsigned long long opened,
3932 + aufs_bindex_t br_id)
3934 + unsigned long long ull;
3935 + aufs_bindex_t bindex, btop, bbot, bfound;
3936 + struct file *file;
3937 + struct au_fidir *fidir;
3938 + struct au_hfile *hfile;
3940 + for (ull = 0; ull < opened; ull++) {
3941 + file = to_free[ull];
3942 + if (unlikely(!file))
3945 + /* AuDbg("%pD\n", file); */
3946 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3948 + fidir = au_fi(file)->fi_hdir;
3949 + AuDebugOn(!fidir);
3950 + fi_write_lock(file);
3951 + btop = au_fbtop(file);
3952 + bbot = au_fbbot_dir(file);
3953 + for (bindex = btop; bindex <= bbot; bindex++) {
3954 + hfile = fidir->fd_hfile + bindex;
3955 + if (!hfile->hf_file)
3958 + if (hfile->hf_br->br_id == br_id) {
3963 + AuDebugOn(bfound < 0);
3964 + au_set_h_fptr(file, bfound, NULL);
3965 + if (bfound == btop) {
3966 + for (btop++; btop <= bbot; btop++)
3967 + if (au_hf_dir(file, btop)) {
3968 + au_set_fbtop(file, btop);
3972 + fi_write_unlock(file);
3976 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3977 + const aufs_bindex_t bindex,
3978 + const aufs_bindex_t bbot)
3980 + struct au_branch **brp, **p;
3982 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3984 + brp = sbinfo->si_branch + bindex;
3985 + if (bindex < bbot)
3986 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3987 + sbinfo->si_branch[0 + bbot] = NULL;
3988 + sbinfo->si_bbot--;
3990 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3993 + sbinfo->si_branch = p;
3994 + /* harmless error */
3997 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3998 + const aufs_bindex_t bbot)
4000 + struct au_hdentry *hdp, *p;
4002 + AuRwMustWriteLock(&dinfo->di_rwsem);
4004 + hdp = au_hdentry(dinfo, bindex);
4005 + if (bindex < bbot)
4006 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4007 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4010 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4013 + dinfo->di_hdentry = p;
4014 + /* harmless error */
4017 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4018 + const aufs_bindex_t bbot)
4020 + struct au_hinode *hip, *p;
4022 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4024 + hip = au_hinode(iinfo, bindex);
4025 + if (bindex < bbot)
4026 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4027 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4030 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4033 + iinfo->ii_hinode = p;
4034 + /* harmless error */
4037 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4038 + struct au_branch *br)
4040 + aufs_bindex_t bbot;
4041 + struct au_sbinfo *sbinfo;
4042 + struct dentry *root, *h_root;
4043 + struct inode *inode, *h_inode;
4044 + struct au_hinode *hinode;
4046 + SiMustWriteLock(sb);
4048 + root = sb->s_root;
4049 + inode = d_inode(root);
4050 + sbinfo = au_sbi(sb);
4051 + bbot = sbinfo->si_bbot;
4053 + h_root = au_h_dptr(root, bindex);
4054 + hinode = au_hi(inode, bindex);
4055 + h_inode = au_igrab(hinode->hi_inode);
4058 + au_sbilist_lock();
4059 + au_br_do_del_brp(sbinfo, bindex, bbot);
4060 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4061 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4062 + au_sbilist_unlock();
4064 + /* ignore an error */
4065 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4069 + au_br_do_free(br);
4072 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4073 + unsigned long long max, void *arg)
4078 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4081 + unsigned long long opened;
4082 + unsigned int mnt_flags;
4083 + aufs_bindex_t bindex, bbot, br_id;
4084 + unsigned char do_wh, verbose;
4085 + struct au_branch *br;
4086 + struct au_wbr *wbr;
4087 + struct dentry *root;
4088 + struct file **to_free;
4093 + root = sb->s_root;
4094 + bindex = au_find_dbindex(root, del->h_path.dentry);
4097 + goto out; /* success */
4099 + pr_err("%s no such branch\n", del->pathname);
4102 + AuDbg("bindex b%d\n", bindex);
4105 + mnt_flags = au_mntflags(sb);
4106 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4107 + bbot = au_sbbot(sb);
4108 + if (unlikely(!bbot)) {
4109 + AuVerbose(verbose, "no more branches left\n");
4113 + br = au_sbr(sb, bindex);
4114 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4115 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4116 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4120 + br_id = br->br_id;
4121 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4122 + if (unlikely(opened)) {
4123 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4124 + err = PTR_ERR(to_free);
4125 + if (IS_ERR(to_free))
4128 + err = test_file_busy(sb, br_id, to_free, opened);
4129 + if (unlikely(err)) {
4130 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4136 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4138 + /* instead of WbrWhMustWriteLock(wbr) */
4139 + SiMustWriteLock(sb);
4140 + for (i = 0; i < AuBrWh_Last; i++) {
4141 + dput(wbr->wbr_wh[i]);
4142 + wbr->wbr_wh[i] = NULL;
4146 + err = test_children_busy(root, bindex, verbose);
4147 + if (unlikely(err)) {
4156 + * now we confirmed the branch is deletable.
4157 + * let's free the remaining opened dirs on the branch.
4159 + di_write_unlock(root);
4160 + br_del_file(to_free, opened, br_id);
4161 + di_write_lock_child(root);
4164 + sysaufs_brs_del(sb, bindex); /* remove successors */
4165 + dbgaufs_xino_del(br); /* remove one */
4166 + au_br_do_del(sb, bindex, br);
4167 + sysaufs_brs_add(sb, bindex); /* append successors */
4168 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4171 + au_cpup_attr_all(d_inode(root), /*force*/1);
4172 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4174 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4175 + if (au_opt_test(mnt_flags, PLINK))
4176 + au_plink_half_refresh(sb, br_id);
4178 + goto out; /* success */
4182 + rerr = au_br_init_wh(sb, br, br->br_perm);
4184 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4185 + del->pathname, rerr);
4188 + au_farray_free(to_free, opened);
4192 +/* ---------------------------------------------------------------------- */
4194 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4197 + aufs_bindex_t btop, bbot;
4198 + struct aufs_ibusy ibusy;
4199 + struct inode *inode, *h_inode;
4202 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4205 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4207 + /* VERIFY_WRITE */
4208 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4209 + if (unlikely(err)) {
4216 + si_read_lock(sb, AuLock_FLUSH);
4217 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4221 + ibusy.h_ino = 0; /* invalid */
4222 + inode = ilookup(sb, ibusy.ino);
4224 + || inode->i_ino == AUFS_ROOT_INO
4225 + || au_is_bad_inode(inode))
4228 + ii_read_lock_child(inode);
4229 + btop = au_ibtop(inode);
4230 + bbot = au_ibbot(inode);
4231 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4232 + h_inode = au_h_iptr(inode, ibusy.bindex);
4233 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4234 + ibusy.h_ino = h_inode->i_ino;
4236 + ii_read_unlock(inode);
4240 + si_read_unlock(sb);
4242 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4243 + if (unlikely(err)) {
4252 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4254 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4257 +#ifdef CONFIG_COMPAT
4258 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4260 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4264 +/* ---------------------------------------------------------------------- */
4267 + * change a branch permission
4270 +static void au_warn_ima(void)
4273 + /* since it doesn't support mark_files_ro() */
4274 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4278 +static int do_need_sigen_inc(int a, int b)
4280 + return au_br_whable(a) && !au_br_whable(b);
4283 +static int need_sigen_inc(int old, int new)
4285 + return do_need_sigen_inc(old, new)
4286 + || do_need_sigen_inc(new, old);
4289 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4292 + unsigned int mnt_flags;
4293 + unsigned long long ull, max;
4294 + aufs_bindex_t br_id;
4295 + unsigned char verbose, writer;
4296 + struct file *file, *hf, **array;
4297 + struct au_hfile *hfile;
4298 + struct inode *h_inode;
4300 + mnt_flags = au_mntflags(sb);
4301 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4303 + array = au_farray_alloc(sb, &max);
4304 + err = PTR_ERR(array);
4305 + if (IS_ERR(array))
4309 + br_id = au_sbr_id(sb, bindex);
4310 + for (ull = 0; ull < max; ull++) {
4311 + file = array[ull];
4312 + if (unlikely(!file))
4315 + /* AuDbg("%pD\n", file); */
4316 + fi_read_lock(file);
4317 + if (unlikely(au_test_mmapped(file))) {
4319 + AuVerbose(verbose, "mmapped %pD\n", file);
4321 + FiMustNoWaiters(file);
4322 + fi_read_unlock(file);
4326 + hfile = &au_fi(file)->fi_htop;
4327 + hf = hfile->hf_file;
4328 + if (!d_is_reg(file->f_path.dentry)
4329 + || !(file->f_mode & FMODE_WRITE)
4330 + || hfile->hf_br->br_id != br_id
4331 + || !(hf->f_mode & FMODE_WRITE))
4332 + array[ull] = NULL;
4338 + FiMustNoWaiters(file);
4339 + fi_read_unlock(file);
4347 + for (ull = 0; ull < max; ull++) {
4348 + file = array[ull];
4352 + /* todo: already flushed? */
4354 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4355 + * approach which resets f_mode and calls mnt_drop_write() and
4356 + * file_release_write() for each file, because the branch
4357 + * attribute in aufs world is totally different from the native
4360 + /* fi_read_lock(file); */
4361 + hfile = &au_fi(file)->fi_htop;
4362 + hf = hfile->hf_file;
4363 + /* fi_read_unlock(file); */
4364 + spin_lock(&hf->f_lock);
4365 + writer = !!(hf->f_mode & FMODE_WRITER);
4366 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4367 + spin_unlock(&hf->f_lock);
4369 + h_inode = file_inode(hf);
4370 + put_write_access(h_inode);
4371 + __mnt_drop_write(hf->f_path.mnt);
4372 + if ((hf->f_mode & (FMODE_READ | FMODE_WRITE))
4374 + i_readcount_inc(h_inode);
4379 + au_farray_free(array, max);
4385 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4389 + aufs_bindex_t bindex;
4390 + struct dentry *root;
4391 + struct au_branch *br;
4392 + struct au_br_fhsm *bf;
4394 + root = sb->s_root;
4395 + bindex = au_find_dbindex(root, mod->h_root);
4398 + return 0; /* success */
4400 + pr_err("%s no such branch\n", mod->path);
4403 + AuDbg("bindex b%d\n", bindex);
4405 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4406 + if (unlikely(err))
4409 + br = au_sbr(sb, bindex);
4410 + AuDebugOn(mod->h_root != au_br_dentry(br));
4411 + if (br->br_perm == mod->perm)
4412 + return 0; /* success */
4414 + /* pre-allocate for non-fhsm --> fhsm */
4416 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4417 + err = au_fhsm_br_alloc(br);
4418 + if (unlikely(err))
4421 + br->br_fhsm = NULL;
4424 + if (au_br_writable(br->br_perm)) {
4425 + /* remove whiteout base */
4426 + err = au_br_init_wh(sb, br, mod->perm);
4427 + if (unlikely(err))
4430 + if (!au_br_writable(mod->perm)) {
4431 + /* rw --> ro, file might be mmapped */
4432 + DiMustNoWaiters(root);
4433 + IiMustNoWaiters(d_inode(root));
4434 + di_write_unlock(root);
4435 + err = au_br_mod_files_ro(sb, bindex);
4436 + /* aufs_write_lock() calls ..._child() */
4437 + di_write_lock_child(root);
4439 + if (unlikely(err)) {
4441 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4444 + rerr = au_wbr_init(br, sb, br->br_perm);
4445 + if (unlikely(rerr)) {
4446 + AuIOErr("nested error %d (%d)\n",
4448 + br->br_perm = mod->perm;
4452 + } else if (au_br_writable(mod->perm)) {
4455 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4457 + err = au_wbr_init(br, sb, mod->perm);
4458 + if (unlikely(err)) {
4459 + au_kfree_rcu(br->br_wbr);
4460 + br->br_wbr = NULL;
4464 + if (unlikely(err))
4467 + if (au_br_fhsm(br->br_perm)) {
4468 + if (!au_br_fhsm(mod->perm)) {
4469 + /* fhsm --> non-fhsm */
4470 + au_br_fhsm_fin(br->br_fhsm);
4471 + au_kfree_rcu(br->br_fhsm);
4472 + br->br_fhsm = NULL;
4474 + } else if (au_br_fhsm(mod->perm))
4475 + /* non-fhsm --> fhsm */
4478 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4479 + br->br_perm = mod->perm;
4480 + goto out; /* success */
4483 + au_kfree_try_rcu(bf);
4489 +/* ---------------------------------------------------------------------- */
4491 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4494 + struct kstatfs kstfs;
4496 + err = vfs_statfs(&br->br_path, &kstfs);
4498 + stfs->f_blocks = kstfs.f_blocks;
4499 + stfs->f_bavail = kstfs.f_bavail;
4500 + stfs->f_files = kstfs.f_files;
4501 + stfs->f_ffree = kstfs.f_ffree;
4506 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4507 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4508 +++ linux/fs/aufs/branch.h 2019-07-11 15:42:14.462237786 +0200
4510 +/* SPDX-License-Identifier: GPL-2.0 */
4512 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4514 + * This program, aufs is free software; you can redistribute it and/or modify
4515 + * it under the terms of the GNU General Public License as published by
4516 + * the Free Software Foundation; either version 2 of the License, or
4517 + * (at your option) any later version.
4519 + * This program is distributed in the hope that it will be useful,
4520 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4521 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4522 + * GNU General Public License for more details.
4524 + * You should have received a copy of the GNU General Public License
4525 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4529 + * branch filesystems and xino for them
4532 +#ifndef __AUFS_BRANCH_H__
4533 +#define __AUFS_BRANCH_H__
4537 +#include <linux/mount.h>
4538 +#include "dirren.h"
4544 +/* ---------------------------------------------------------------------- */
4548 + struct file **xi_file;
4549 + unsigned int xi_nfile;
4555 + /* reserved for future use */
4556 + /* unsigned long *bitmap; */
4557 + wait_queue_head_t wqh;
4560 + struct mutex xi_mtx; /* protects xi_file array */
4561 + struct hlist_bl_head xi_writing;
4563 + atomic_t xi_truncating;
4565 + struct kref xi_kref;
4568 +/* File-based Hierarchical Storage Management */
4569 +struct au_br_fhsm {
4570 +#ifdef CONFIG_AUFS_FHSM
4571 + struct mutex bf_lock;
4572 + unsigned long bf_jiffy;
4573 + struct aufs_stfs bf_stfs;
4578 +/* members for writable branch only */
4579 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4581 + struct au_rwsem wbr_wh_rwsem;
4582 + struct dentry *wbr_wh[AuBrWh_Last];
4583 + atomic_t wbr_wh_running;
4584 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4585 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4586 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4589 + unsigned long long wbr_bytes;
4592 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4593 +#define AuBrDynOp (AuDyLast * 4)
4595 +#ifdef CONFIG_AUFS_HFSNOTIFY
4596 +/* support for asynchronous destruction */
4597 +struct au_br_hfsnotify {
4598 + struct fsnotify_group *hfsn_group;
4602 +/* sysfs entries */
4603 +struct au_brsysfs {
4605 + struct attribute attr;
4614 +/* protected by superblock rwsem */
4616 + struct au_xino *br_xino;
4618 + aufs_bindex_t br_id;
4621 + struct path br_path;
4622 + spinlock_t br_dykey_lock;
4623 + struct au_dykey *br_dykey[AuBrDynOp];
4624 + au_lcnt_t br_nfiles; /* opened files */
4625 + au_lcnt_t br_count; /* in-use for other */
4627 + struct au_wbr *br_wbr;
4628 + struct au_br_fhsm *br_fhsm;
4630 +#ifdef CONFIG_AUFS_HFSNOTIFY
4631 + struct au_br_hfsnotify *br_hfsn;
4634 +#ifdef CONFIG_SYSFS
4635 + /* entries under sysfs per mount-point */
4636 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4639 +#ifdef CONFIG_DEBUG_FS
4640 + struct dentry *br_dbgaufs; /* xino */
4643 + struct au_dr_br br_dirren;
4646 +/* ---------------------------------------------------------------------- */
4648 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4650 + return br->br_path.mnt;
4653 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4655 + return br->br_path.dentry;
4658 +static inline struct super_block *au_br_sb(struct au_branch *br)
4660 + return au_br_mnt(br)->mnt_sb;
4663 +static inline int au_br_rdonly(struct au_branch *br)
4665 + return (sb_rdonly(au_br_sb(br))
4666 + || !au_br_writable(br->br_perm))
4670 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4672 +#ifdef CONFIG_AUFS_HNOTIFY
4673 + return !(brperm & AuBrPerm_RR);
4679 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4681 + int err, exec_flag;
4684 + exec_flag = oflag & __FMODE_EXEC;
4685 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4691 +static inline void au_xino_get(struct au_branch *br)
4693 + struct au_xino *xi;
4697 + kref_get(&xi->xi_kref);
4700 +static inline int au_xino_count(struct au_branch *br)
4703 + struct au_xino *xi;
4708 + v = kref_read(&xi->xi_kref);
4713 +/* ---------------------------------------------------------------------- */
4717 +void au_br_free(struct au_sbinfo *sinfo);
4718 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4720 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4722 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4723 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4724 +#ifdef CONFIG_COMPAT
4725 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4728 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4731 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4734 +static const loff_t au_loff_max = LLONG_MAX;
4736 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4737 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4739 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4740 + struct file *copy_src);
4742 + struct au_xino *xi; /* switch between xino and xigen */
4744 + struct path *base;
4745 + struct file *copy_src;
4747 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4749 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4751 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4753 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4755 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4756 + size_t size, loff_t *pos);
4758 +int au_xib_trunc(struct super_block *sb);
4759 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4761 +struct au_xino *au_xino_alloc(unsigned int nfile);
4762 +int au_xino_put(struct au_branch *br);
4763 +struct file *au_xino_file1(struct au_xino *xi);
4765 +struct au_opt_xino;
4766 +void au_xino_clr(struct super_block *sb);
4767 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4768 +struct file *au_xino_def(struct super_block *sb);
4769 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4770 + struct path *base);
4772 +ino_t au_xino_new_ino(struct super_block *sb);
4773 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4775 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4776 + ino_t h_ino, int idx);
4777 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4780 +int au_xino_path(struct seq_file *seq, struct file *file);
4782 +/* ---------------------------------------------------------------------- */
4784 +/* @idx is signed to accept -1 meaning the first file */
4785 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4787 + struct file *file;
4794 + if (idx < xi->xi_nfile)
4795 + file = xi->xi_file[idx];
4797 + file = au_xino_file1(xi);
4803 +/* ---------------------------------------------------------------------- */
4805 +/* Superblock to branch */
4807 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4809 + return au_sbr(sb, bindex)->br_id;
4813 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4815 + return au_br_mnt(au_sbr(sb, bindex));
4819 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4821 + return au_br_sb(au_sbr(sb, bindex));
4824 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4826 + return au_sbr(sb, bindex)->br_perm;
4829 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4831 + return au_br_whable(au_sbr_perm(sb, bindex));
4834 +/* ---------------------------------------------------------------------- */
4836 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4837 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4838 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4839 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4841 +#define wbr_wh_read_trylock_nested(wbr) \
4842 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4843 +#define wbr_wh_write_trylock_nested(wbr) \
4844 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4847 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4848 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4849 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4851 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4852 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4853 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4855 +/* ---------------------------------------------------------------------- */
4857 +#ifdef CONFIG_AUFS_FHSM
4858 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4860 + mutex_init(&brfhsm->bf_lock);
4861 + brfhsm->bf_jiffy = 0;
4862 + brfhsm->bf_readable = 0;
4865 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4867 + mutex_destroy(&brfhsm->bf_lock);
4870 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4871 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4874 +#endif /* __KERNEL__ */
4875 +#endif /* __AUFS_BRANCH_H__ */
4876 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4877 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4878 +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200
4880 +# SPDX-License-Identifier: GPL-2.0
4882 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4886 +AuConfStr += ${1}=${${1}}
4890 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4892 + HNOTIFY HFSNOTIFY \
4904 +$(foreach i, ${AuConfAll}, \
4905 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4907 +AuConfName = ${obj}/conf.str
4908 +${AuConfName}.tmp: FORCE
4909 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4910 +${AuConfName}: ${AuConfName}.tmp
4911 + @diff -q $< $@ > /dev/null 2>&1 || { \
4912 + echo ' GEN ' $@; \
4916 +clean-files += ${AuConfName} ${AuConfName}.tmp
4917 +${obj}/sysfs.o: ${AuConfName}
4919 +-include ${srctree}/${src}/conf_priv.mk
4920 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4921 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4922 +++ linux/fs/aufs/cpup.c 2019-07-11 15:42:14.462237786 +0200
4924 +// SPDX-License-Identifier: GPL-2.0
4926 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4928 + * This program, aufs is free software; you can redistribute it and/or modify
4929 + * it under the terms of the GNU General Public License as published by
4930 + * the Free Software Foundation; either version 2 of the License, or
4931 + * (at your option) any later version.
4933 + * This program is distributed in the hope that it will be useful,
4934 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4935 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4936 + * GNU General Public License for more details.
4938 + * You should have received a copy of the GNU General Public License
4939 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4943 + * copy-up functions, see wbr_policy.c for copy-down
4946 +#include <linux/fs_stack.h>
4947 +#include <linux/mm.h>
4948 +#include <linux/task_work.h>
4951 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4953 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4954 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4956 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4958 + dst->i_flags |= iflags & ~mask;
4959 + if (au_test_fs_notime(dst->i_sb))
4960 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4963 +void au_cpup_attr_timesizes(struct inode *inode)
4965 + struct inode *h_inode;
4967 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4968 + fsstack_copy_attr_times(inode, h_inode);
4969 + fsstack_copy_inode_size(inode, h_inode);
4972 +void au_cpup_attr_nlink(struct inode *inode, int force)
4974 + struct inode *h_inode;
4975 + struct super_block *sb;
4976 + aufs_bindex_t bindex, bbot;
4979 + bindex = au_ibtop(inode);
4980 + h_inode = au_h_iptr(inode, bindex);
4982 + && !S_ISDIR(h_inode->i_mode)
4983 + && au_opt_test(au_mntflags(sb), PLINK)
4984 + && au_plink_test(inode))
4988 + * 0 can happen in revalidating.
4989 + * h_inode->i_mutex may not be held here, but it is harmless since once
4990 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4992 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4993 + * the incorrect link count.
4995 + set_nlink(inode, h_inode->i_nlink);
4998 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4999 + * it may includes whplink directory.
5001 + if (S_ISDIR(h_inode->i_mode)) {
5002 + bbot = au_ibbot(inode);
5003 + for (bindex++; bindex <= bbot; bindex++) {
5004 + h_inode = au_h_iptr(inode, bindex);
5006 + au_add_nlink(inode, h_inode);
5011 +void au_cpup_attr_changeable(struct inode *inode)
5013 + struct inode *h_inode;
5015 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5016 + inode->i_mode = h_inode->i_mode;
5017 + inode->i_uid = h_inode->i_uid;
5018 + inode->i_gid = h_inode->i_gid;
5019 + au_cpup_attr_timesizes(inode);
5020 + au_cpup_attr_flags(inode, h_inode->i_flags);
5023 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5025 + struct au_iinfo *iinfo = au_ii(inode);
5027 + IiMustWriteLock(inode);
5029 + iinfo->ii_higen = h_inode->i_generation;
5030 + iinfo->ii_hsb1 = h_inode->i_sb;
5033 +void au_cpup_attr_all(struct inode *inode, int force)
5035 + struct inode *h_inode;
5037 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5038 + au_cpup_attr_changeable(inode);
5039 + if (inode->i_nlink > 0)
5040 + au_cpup_attr_nlink(inode, force);
5041 + inode->i_rdev = h_inode->i_rdev;
5042 + inode->i_blkbits = h_inode->i_blkbits;
5043 + au_cpup_igen(inode, h_inode);
5046 +/* ---------------------------------------------------------------------- */
5048 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5050 +/* keep the timestamps of the parent dir when cpup */
5051 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5052 + struct path *h_path)
5054 + struct inode *h_inode;
5056 + dt->dt_dentry = dentry;
5057 + dt->dt_h_path = *h_path;
5058 + h_inode = d_inode(h_path->dentry);
5059 + dt->dt_atime = h_inode->i_atime;
5060 + dt->dt_mtime = h_inode->i_mtime;
5064 +void au_dtime_revert(struct au_dtime *dt)
5066 + struct iattr attr;
5069 + attr.ia_atime = dt->dt_atime;
5070 + attr.ia_mtime = dt->dt_mtime;
5071 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5072 + | ATTR_ATIME | ATTR_ATIME_SET;
5074 + /* no delegation since this is a directory */
5075 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5076 + if (unlikely(err))
5077 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5080 +/* ---------------------------------------------------------------------- */
5082 +/* internal use only */
5083 +struct au_cpup_reg_attr {
5086 + unsigned int iflags; /* inode->i_flags */
5089 +static noinline_for_stack
5090 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5091 + struct au_cpup_reg_attr *h_src_attr)
5093 + int err, sbits, icex;
5094 + unsigned int mnt_flags;
5095 + unsigned char verbose;
5097 + struct path h_path;
5098 + struct inode *h_isrc, *h_idst;
5099 + struct kstat *h_st;
5100 + struct au_branch *br;
5102 + h_path.dentry = au_h_dptr(dst, bindex);
5103 + h_idst = d_inode(h_path.dentry);
5104 + br = au_sbr(dst->d_sb, bindex);
5105 + h_path.mnt = au_br_mnt(br);
5106 + h_isrc = d_inode(h_src);
5107 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5108 + | ATTR_ATIME | ATTR_MTIME
5109 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5110 + if (h_src_attr && h_src_attr->valid) {
5111 + h_st = &h_src_attr->st;
5112 + ia.ia_uid = h_st->uid;
5113 + ia.ia_gid = h_st->gid;
5114 + ia.ia_atime = h_st->atime;
5115 + ia.ia_mtime = h_st->mtime;
5116 + if (h_idst->i_mode != h_st->mode
5117 + && !S_ISLNK(h_idst->i_mode)) {
5118 + ia.ia_valid |= ATTR_MODE;
5119 + ia.ia_mode = h_st->mode;
5121 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5122 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5124 + ia.ia_uid = h_isrc->i_uid;
5125 + ia.ia_gid = h_isrc->i_gid;
5126 + ia.ia_atime = h_isrc->i_atime;
5127 + ia.ia_mtime = h_isrc->i_mtime;
5128 + if (h_idst->i_mode != h_isrc->i_mode
5129 + && !S_ISLNK(h_idst->i_mode)) {
5130 + ia.ia_valid |= ATTR_MODE;
5131 + ia.ia_mode = h_isrc->i_mode;
5133 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5134 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5136 + /* no delegation since it is just created */
5137 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5139 + /* is this nfs only? */
5140 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5141 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5142 + ia.ia_mode = h_isrc->i_mode;
5143 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5146 + icex = br->br_perm & AuBrAttr_ICEX;
5148 + mnt_flags = au_mntflags(dst->d_sb);
5149 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5150 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5156 +/* ---------------------------------------------------------------------- */
5158 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5159 + char *buf, unsigned long blksize)
5162 + size_t sz, rbytes, wbytes;
5163 + unsigned char all_zero;
5165 + struct inode *h_inode;
5166 + /* reduce stack usage */
5169 + zp = page_address(ZERO_PAGE(0));
5170 + if (unlikely(!zp))
5171 + return -ENOMEM; /* possible? */
5176 + AuDbg("len %lld\n", len);
5178 + if (len < blksize)
5182 + /* todo: signal_pending? */
5183 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5184 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5187 + if (unlikely(err < 0))
5191 + if (len >= rbytes && rbytes == blksize)
5192 + all_zero = !memcmp(buf, zp, rbytes);
5199 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5201 + /* todo: signal_pending? */
5202 + if (unlikely(err == -EAGAIN || err == -EINTR))
5204 + if (unlikely(err < 0))
5209 + if (unlikely(err < 0))
5215 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5217 + if (unlikely(res < 0))
5224 + /* the last block may be a hole */
5225 + if (!err && all_zero) {
5226 + AuLabel(last hole);
5229 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5230 + /* nfs requires this step to make last hole */
5231 + /* is this only nfs? */
5233 + /* todo: signal_pending? */
5234 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5235 + } while (err == -EAGAIN || err == -EINTR);
5242 + ia->ia_size = dst->f_pos;
5243 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5244 + ia->ia_file = dst;
5245 + h_inode = file_inode(dst);
5246 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5247 + /* no delegation since it is just created */
5248 + err = vfsub_notify_change(&dst->f_path, ia,
5249 + /*delegated*/NULL);
5250 + inode_unlock(h_inode);
5257 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5260 + unsigned long blksize;
5261 + unsigned char do_kfree;
5263 + struct super_block *h_sb;
5266 + h_sb = file_inode(dst)->i_sb;
5267 + blksize = h_sb->s_blocksize;
5268 + if (!blksize || PAGE_SIZE < blksize)
5269 + blksize = PAGE_SIZE;
5270 + AuDbg("blksize %lu\n", blksize);
5271 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5273 + buf = kmalloc(blksize, GFP_NOFS);
5275 + buf = (void *)__get_free_page(GFP_NOFS);
5276 + if (unlikely(!buf))
5279 + if (len > (1 << 22))
5280 + AuDbg("copying a large file %lld\n", (long long)len);
5284 + err = au_do_copy_file(dst, src, len, buf, blksize);
5286 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5287 + au_kfree_do_rcu(buf);
5289 + free_page((unsigned long)buf);
5295 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5298 + struct super_block *h_src_sb;
5299 + struct inode *h_src_inode;
5301 + h_src_inode = file_inode(src);
5302 + h_src_sb = h_src_inode->i_sb;
5304 + /* XFS acquires inode_lock */
5305 + if (!au_test_xfs(h_src_sb))
5306 + err = au_copy_file(dst, src, len);
5308 + inode_unlock_shared(h_src_inode);
5309 + err = au_copy_file(dst, src, len);
5310 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5316 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5320 + struct super_block *h_src_sb;
5321 + struct inode *h_src_inode;
5323 + h_src_inode = file_inode(src);
5324 + h_src_sb = h_src_inode->i_sb;
5325 + if (h_src_sb != file_inode(dst)->i_sb
5326 + || !dst->f_op->remap_file_range) {
5327 + err = au_do_copy(dst, src, len);
5331 + if (!au_test_nfs(h_src_sb)) {
5332 + inode_unlock_shared(h_src_inode);
5333 + lo = vfsub_clone_file_range(src, dst, len);
5334 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5336 + lo = vfsub_clone_file_range(src, dst, len);
5339 + goto out; /* success */
5340 + } else if (lo >= 0)
5341 + /* todo: possible? */
5342 + /* paritially succeeded */
5343 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5344 + else if (lo != -EOPNOTSUPP) {
5345 + /* older XFS has a condition in cloning */
5350 + /* the backend fs on NFS may not support cloning */
5351 + err = au_do_copy(dst, src, len);
5359 + * to support a sparse file which is opened with O_APPEND,
5360 + * we need to close the file.
5362 +static int au_cp_regular(struct au_cp_generic *cpg)
5365 + enum { SRC, DST };
5367 + aufs_bindex_t bindex;
5368 + unsigned int flags;
5369 + struct dentry *dentry;
5371 + struct file *file;
5374 + .bindex = cpg->bsrc,
5375 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5378 + .bindex = cpg->bdst,
5379 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5380 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5383 + struct au_branch *br;
5384 + struct super_block *sb, *h_src_sb;
5385 + struct inode *h_src_inode;
5386 + struct task_struct *tsk = current;
5388 + /* bsrc branch can be ro/rw. */
5389 + sb = cpg->dentry->d_sb;
5391 + for (i = 0; i < 2; i++, f++) {
5392 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5393 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5394 + /*file*/NULL, f->force_wr);
5395 + if (IS_ERR(f->file)) {
5396 + err = PTR_ERR(f->file);
5404 + /* try stopping to update while we copyup */
5405 + h_src_inode = d_inode(file[SRC].dentry);
5406 + h_src_sb = h_src_inode->i_sb;
5407 + if (!au_test_nfs(h_src_sb))
5408 + IMustLock(h_src_inode);
5409 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5411 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5412 + if (tsk->flags & PF_KTHREAD)
5413 + __fput_sync(file[DST].file);
5415 + /* it happened actually */
5416 + fput(file[DST].file);
5419 + * we have to call both since we don't know which place the file
5423 + flush_delayed_fput();
5425 + br = au_sbr(sb, file[DST].bindex);
5426 + au_lcnt_dec(&br->br_nfiles);
5429 + fput(file[SRC].file);
5430 + br = au_sbr(sb, file[SRC].bindex);
5431 + au_lcnt_dec(&br->br_nfiles);
5436 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5437 + struct au_cpup_reg_attr *h_src_attr)
5441 + struct path h_path;
5442 + struct inode *h_src_inode, *h_dst_inode;
5445 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5446 + l = i_size_read(h_src_inode);
5447 + if (cpg->len == -1 || l < cpg->len)
5450 + /* try stopping to update while we are referencing */
5451 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5452 + au_pin_hdir_unlock(cpg->pin);
5454 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5455 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5456 + h_src_attr->iflags = h_src_inode->i_flags;
5457 + if (!au_test_nfs(h_src_inode->i_sb))
5458 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5460 + inode_unlock_shared(h_src_inode);
5461 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5462 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5464 + if (unlikely(err)) {
5465 + inode_unlock_shared(h_src_inode);
5468 + h_src_attr->valid = 1;
5469 + if (!au_test_nfs(h_src_inode->i_sb)) {
5470 + err = au_cp_regular(cpg);
5471 + inode_unlock_shared(h_src_inode);
5473 + inode_unlock_shared(h_src_inode);
5474 + err = au_cp_regular(cpg);
5476 + rerr = au_pin_hdir_relock(cpg->pin);
5480 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5481 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5482 + h_dst_inode = d_inode(h_path.dentry);
5483 + spin_lock(&h_dst_inode->i_lock);
5484 + h_dst_inode->i_state |= I_LINKABLE;
5485 + spin_unlock(&h_dst_inode->i_lock);
5492 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5493 + struct inode *h_dir)
5496 + mm_segment_t old_fs;
5503 + sym.k = (void *)__get_free_page(GFP_NOFS);
5504 + if (unlikely(!sym.k))
5507 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5508 + old_fs = get_fs();
5509 + set_fs(KERNEL_DS);
5510 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5515 + sym.k[symlen] = 0;
5516 + err = vfsub_symlink(h_dir, h_path, sym.k);
5518 + free_page((unsigned long)sym.k);
5525 + * regardless 'acl' option, reset all ACL.
5526 + * All ACL will be copied up later from the original entry on the lower branch.
5528 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5531 + struct dentry *h_dentry;
5532 + struct inode *h_inode;
5534 + h_dentry = h_path->dentry;
5535 + h_inode = d_inode(h_dentry);
5536 + /* forget_all_cached_acls(h_inode)); */
5537 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5539 + if (err == -EOPNOTSUPP)
5542 + err = vfsub_acl_chmod(h_inode, mode);
5548 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5549 + struct inode *h_dir, struct path *h_path)
5552 + struct inode *dir, *inode;
5554 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5556 + if (err == -EOPNOTSUPP)
5558 + if (unlikely(err))
5562 + * strange behaviour from the users view,
5563 + * particularly setattr case
5565 + dir = d_inode(dst_parent);
5566 + if (au_ibtop(dir) == cpg->bdst)
5567 + au_cpup_attr_nlink(dir, /*force*/1);
5568 + inode = d_inode(cpg->dentry);
5569 + au_cpup_attr_nlink(inode, /*force*/1);
5575 +static noinline_for_stack
5576 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5577 + struct au_cpup_reg_attr *h_src_attr)
5581 + unsigned int mnt_flags;
5582 + unsigned char isdir, isreg, force;
5583 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5584 + struct au_dtime dt;
5585 + struct path h_path;
5586 + struct dentry *h_src, *h_dst, *h_parent;
5587 + struct inode *h_inode, *h_dir;
5588 + struct super_block *sb;
5590 + /* bsrc branch can be ro/rw. */
5591 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5592 + h_inode = d_inode(h_src);
5593 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5595 + /* try stopping to be referenced while we are creating */
5596 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5597 + if (au_ftest_cpup(cpg->flags, RENAME))
5598 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5599 + AUFS_WH_PFX_LEN));
5600 + h_parent = h_dst->d_parent; /* dir inode is locked */
5601 + h_dir = d_inode(h_parent);
5603 + AuDebugOn(h_parent != h_dst->d_parent);
5605 + sb = cpg->dentry->d_sb;
5606 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5608 + h_path.dentry = h_parent;
5609 + au_dtime_store(&dt, dst_parent, &h_path);
5611 + h_path.dentry = h_dst;
5615 + mode = h_inode->i_mode;
5616 + switch (mode & S_IFMT) {
5619 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5621 + err = au_do_cpup_regular(cpg, h_src_attr);
5625 + err = vfsub_mkdir(h_dir, &h_path, mode);
5627 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5630 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5634 + AuDebugOn(!capable(CAP_MKNOD));
5638 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5641 + AuIOErr("Unknown inode type 0%o\n", mode);
5645 + err = au_reset_acl(h_dir, &h_path, mode);
5647 + mnt_flags = au_mntflags(sb);
5648 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5650 + && au_opt_test(mnt_flags, XINO)
5651 + && (h_inode->i_nlink == 1
5652 + || (h_inode->i_state & I_LINKABLE))
5653 + /* todo: unnecessary? */
5654 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5655 + && cpg->bdst < cpg->bsrc
5656 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5657 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5658 + /* ignore this error */
5663 + force = !!cpg->len;
5664 + if (cpg->len == -1)
5665 + force = !!i_size_read(h_inode);
5667 + au_fhsm_wrote(sb, cpg->bdst, force);
5671 + au_dtime_revert(&dt);
5675 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5678 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5679 + struct inode *h_dir;
5680 + aufs_bindex_t bdst;
5682 + dentry = cpg->dentry;
5684 + h_dentry = au_h_dptr(dentry, bdst);
5685 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5687 + au_set_h_dptr(dentry, bdst, NULL);
5688 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5690 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5691 + au_set_h_dptr(dentry, bdst, h_dentry);
5694 + parent = dget_parent(dentry);
5695 + h_parent = au_h_dptr(parent, bdst);
5697 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5698 + if (IS_ERR(h_path->dentry))
5699 + err = PTR_ERR(h_path->dentry);
5701 + if (unlikely(err))
5704 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5705 + h_dir = d_inode(h_parent);
5707 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5708 + /* no delegation since it is just created */
5709 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5711 + dput(h_path->dentry);
5718 + * copyup the @dentry from @bsrc to @bdst.
5719 + * the caller must set the both of lower dentries.
5720 + * @len is for truncating when it is -1 copyup the entire file.
5721 + * in link/rename cases, @dst_parent may be different from the real one.
5722 + * basic->bsrc can be larger than basic->bdst.
5723 + * aufs doesn't touch the credential so
5724 + * security_inode_copy_up{,_xattr}() are unnecessary.
5726 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5729 + aufs_bindex_t old_ibtop;
5730 + unsigned char isdir, plink;
5731 + struct dentry *h_src, *h_dst, *h_parent;
5732 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5733 + struct super_block *sb;
5734 + struct au_branch *br;
5735 + /* to reduce stack size */
5737 + struct au_dtime dt;
5738 + struct path h_path;
5739 + struct au_cpup_reg_attr h_src_attr;
5743 + a = kmalloc(sizeof(*a), GFP_NOFS);
5746 + a->h_src_attr.valid = 0;
5748 + sb = cpg->dentry->d_sb;
5749 + br = au_sbr(sb, cpg->bdst);
5750 + a->h_path.mnt = au_br_mnt(br);
5751 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5752 + h_parent = h_dst->d_parent; /* dir inode is locked */
5753 + h_dir = d_inode(h_parent);
5756 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5757 + inode = d_inode(cpg->dentry);
5760 + dst_parent = dget_parent(cpg->dentry);
5764 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5765 + dst_inode = au_h_iptr(inode, cpg->bdst);
5767 + if (unlikely(!plink)) {
5769 + AuIOErr("hi%lu(i%lu) exists on b%d "
5770 + "but plink is disabled\n",
5771 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5775 + if (dst_inode->i_nlink) {
5776 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5778 + h_src = au_plink_lkup(inode, cpg->bdst);
5779 + err = PTR_ERR(h_src);
5780 + if (IS_ERR(h_src))
5782 + if (unlikely(d_is_negative(h_src))) {
5784 + AuIOErr("i%lu exists on b%d "
5785 + "but not pseudo-linked\n",
5786 + inode->i_ino, cpg->bdst);
5792 + a->h_path.dentry = h_parent;
5793 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5796 + a->h_path.dentry = h_dst;
5798 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5799 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5800 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5802 + au_dtime_revert(&a->dt);
5803 + if (unlikely(err == -EWOULDBLOCK)) {
5804 + pr_warn("cannot retry for NFSv4 delegation"
5805 + " for an internal link\n");
5811 + /* todo: cpup_wh_file? */
5813 + au_update_ibrange(inode, /*do_put_zero*/1);
5816 + isdir = S_ISDIR(inode->i_mode);
5817 + old_ibtop = au_ibtop(inode);
5818 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5819 + if (unlikely(err))
5821 + dst_inode = d_inode(h_dst);
5822 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5823 + /* todo: necessary? */
5824 + /* au_pin_hdir_unlock(cpg->pin); */
5826 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5827 + if (unlikely(err)) {
5828 + /* todo: necessary? */
5829 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5830 + inode_unlock(dst_inode);
5834 + if (cpg->bdst < old_ibtop) {
5835 + if (S_ISREG(inode->i_mode)) {
5836 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5837 + if (unlikely(err)) {
5838 + /* ignore an error */
5839 + /* au_pin_hdir_relock(cpg->pin); */
5840 + inode_unlock(dst_inode);
5844 + au_set_ibtop(inode, cpg->bdst);
5846 + au_set_ibbot(inode, cpg->bdst);
5847 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5848 + au_hi_flags(inode, isdir));
5850 + /* todo: necessary? */
5851 + /* err = au_pin_hdir_relock(cpg->pin); */
5852 + inode_unlock(dst_inode);
5853 + if (unlikely(err))
5856 + src_inode = d_inode(h_src);
5858 + && (src_inode->i_nlink > 1
5859 + || src_inode->i_state & I_LINKABLE)
5861 + au_plink_append(inode, cpg->bdst, h_dst);
5863 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5864 + a->h_path.dentry = h_dst;
5865 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5868 + goto out_parent; /* success */
5872 + a->h_path.dentry = h_parent;
5873 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5874 + a->h_path.dentry = h_dst;
5876 + if (d_is_positive(h_dst)) {
5878 + /* no delegation since it is just created */
5879 + rerr = vfsub_unlink(h_dir, &a->h_path,
5880 + /*delegated*/NULL, /*force*/0);
5882 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5884 + au_dtime_revert(&a->dt);
5886 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5896 +#if 0 /* reserved */
5897 +struct au_cpup_single_args {
5899 + struct au_cp_generic *cpg;
5900 + struct dentry *dst_parent;
5903 +static void au_call_cpup_single(void *args)
5905 + struct au_cpup_single_args *a = args;
5907 + au_pin_hdir_acquire_nest(a->cpg->pin);
5908 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5909 + au_pin_hdir_release(a->cpg->pin);
5914 + * prevent SIGXFSZ in copy-up.
5915 + * testing CAP_MKNOD is for generic fs,
5916 + * but CAP_FSETID is for xfs only, currently.
5918 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5921 + struct super_block *sb;
5922 + struct inode *h_dir;
5925 + sb = au_pinned_parent(pin)->d_sb;
5926 + if (!au_wkq_test()
5927 + && (!au_sbi(sb)->si_plink_maint_pid
5928 + || au_plink_maint(sb, AuLock_NOPLM))) {
5929 + switch (mode & S_IFMT) {
5931 + /* no condition about RLIMIT_FSIZE and the file size */
5936 + do_sio = !capable(CAP_MKNOD);
5940 + do_sio = ((mode & (S_ISUID | S_ISGID))
5941 + && !capable(CAP_FSETID));
5942 + /* this workaround may be removed in the future */
5944 + h_dir = au_pinned_h_dir(pin);
5945 + do_sio = h_dir->i_mode & S_ISVTX;
5952 +#if 0 /* reserved */
5953 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5956 + struct dentry *h_dentry;
5958 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5959 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5960 + err = au_cpup_single(cpg, dst_parent);
5962 + struct au_cpup_single_args args = {
5965 + .dst_parent = dst_parent
5967 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5968 + if (unlikely(wkq_err))
5977 + * copyup the @dentry from the first active lower branch to @bdst,
5978 + * using au_cpup_single().
5980 +static int au_cpup_simple(struct au_cp_generic *cpg)
5983 + unsigned int flags_orig;
5984 + struct dentry *dentry;
5986 + AuDebugOn(cpg->bsrc < 0);
5988 + dentry = cpg->dentry;
5989 + DiMustWriteLock(dentry);
5991 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5993 + flags_orig = cpg->flags;
5994 + au_fset_cpup(cpg->flags, RENAME);
5995 + err = au_cpup_single(cpg, NULL);
5996 + cpg->flags = flags_orig;
5998 + return 0; /* success */
6001 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6002 + au_set_dbtop(dentry, cpg->bsrc);
6008 +struct au_cpup_simple_args {
6010 + struct au_cp_generic *cpg;
6013 +static void au_call_cpup_simple(void *args)
6015 + struct au_cpup_simple_args *a = args;
6017 + au_pin_hdir_acquire_nest(a->cpg->pin);
6018 + *a->errp = au_cpup_simple(a->cpg);
6019 + au_pin_hdir_release(a->cpg->pin);
6022 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6025 + struct dentry *dentry, *parent;
6026 + struct file *h_file;
6027 + struct inode *h_dir;
6029 + dentry = cpg->dentry;
6031 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6032 + AuDebugOn(cpg->bsrc < 0);
6033 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6034 + err = PTR_ERR(h_file);
6035 + if (IS_ERR(h_file))
6039 + parent = dget_parent(dentry);
6040 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6041 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6042 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6043 + err = au_cpup_simple(cpg);
6045 + struct au_cpup_simple_args args = {
6049 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6050 + if (unlikely(wkq_err))
6056 + au_h_open_post(dentry, cpg->bsrc, h_file);
6062 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6064 + aufs_bindex_t bsrc, bbot;
6065 + struct dentry *dentry, *h_dentry;
6067 + if (cpg->bsrc < 0) {
6068 + dentry = cpg->dentry;
6069 + bbot = au_dbbot(dentry);
6070 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6071 + h_dentry = au_h_dptr(dentry, bsrc);
6073 + AuDebugOn(d_is_negative(h_dentry));
6077 + AuDebugOn(bsrc > bbot);
6080 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6081 + return au_do_sio_cpup_simple(cpg);
6084 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6086 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6087 + return au_do_sio_cpup_simple(cpg);
6090 +/* ---------------------------------------------------------------------- */
6093 + * copyup the deleted file for writing.
6095 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6096 + struct file *file)
6099 + unsigned int flags_orig;
6100 + aufs_bindex_t bsrc_orig;
6101 + struct au_dinfo *dinfo;
6103 + struct au_hdentry *hd;
6104 + struct dentry *h_dentry;
6107 + dinfo = au_di(cpg->dentry);
6108 + AuRwMustWriteLock(&dinfo->di_rwsem);
6110 + bsrc_orig = cpg->bsrc;
6111 + cpg->bsrc = dinfo->di_btop;
6112 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6113 + hdst.h_dentry = hdst.hd->hd_dentry;
6114 + hdst.hd->hd_dentry = wh_dentry;
6115 + dinfo->di_btop = cpg->bdst;
6117 + hsrc.h_dentry = NULL;
6119 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6120 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6121 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6123 + flags_orig = cpg->flags;
6124 + cpg->flags = !AuCpup_DTIME;
6125 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6126 + cpg->flags = flags_orig;
6129 + err = au_reopen_nondir(file);
6130 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6132 + hdst.hd->hd_dentry = hdst.h_dentry;
6133 + dinfo->di_btop = cpg->bsrc;
6134 + cpg->bsrc = bsrc_orig;
6139 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6142 + aufs_bindex_t bdst;
6143 + struct au_dtime dt;
6144 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6145 + struct au_branch *br;
6146 + struct path h_path;
6148 + dentry = cpg->dentry;
6150 + br = au_sbr(dentry->d_sb, bdst);
6151 + parent = dget_parent(dentry);
6152 + h_parent = au_h_dptr(parent, bdst);
6153 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6154 + err = PTR_ERR(wh_dentry);
6155 + if (IS_ERR(wh_dentry))
6158 + h_path.dentry = h_parent;
6159 + h_path.mnt = au_br_mnt(br);
6160 + au_dtime_store(&dt, parent, &h_path);
6161 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6162 + if (unlikely(err))
6166 + h_path.dentry = wh_dentry;
6167 + if (!d_is_dir(wh_dentry)) {
6168 + /* no delegation since it is just created */
6169 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6170 + /*delegated*/NULL, /*force*/0);
6172 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6173 + if (unlikely(err)) {
6174 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6178 + au_dtime_revert(&dt);
6179 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6188 +struct au_cpup_wh_args {
6190 + struct au_cp_generic *cpg;
6191 + struct file *file;
6194 +static void au_call_cpup_wh(void *args)
6196 + struct au_cpup_wh_args *a = args;
6198 + au_pin_hdir_acquire_nest(a->cpg->pin);
6199 + *a->errp = au_cpup_wh(a->cpg, a->file);
6200 + au_pin_hdir_release(a->cpg->pin);
6203 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6206 + aufs_bindex_t bdst;
6207 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6208 + struct inode *dir, *h_dir, *h_tmpdir;
6209 + struct au_wbr *wbr;
6210 + struct au_pin wh_pin, *pin_orig;
6212 + dentry = cpg->dentry;
6214 + parent = dget_parent(dentry);
6215 + dir = d_inode(parent);
6218 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6221 + if (!h_dir->i_nlink) {
6222 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6223 + h_orph = wbr->wbr_orph;
6225 + h_parent = dget(au_h_dptr(parent, bdst));
6226 + au_set_h_dptr(parent, bdst, dget(h_orph));
6227 + h_tmpdir = d_inode(h_orph);
6228 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6230 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6231 + /* todo: au_h_open_pre()? */
6233 + pin_orig = cpg->pin;
6234 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6235 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6236 + cpg->pin = &wh_pin;
6239 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6240 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6241 + err = au_cpup_wh(cpg, file);
6243 + struct au_cpup_wh_args args = {
6248 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6249 + if (unlikely(wkq_err))
6254 + inode_unlock(h_tmpdir);
6255 + /* todo: au_h_open_post()? */
6256 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6257 + au_set_h_dptr(parent, bdst, h_parent);
6258 + AuDebugOn(!pin_orig);
6259 + cpg->pin = pin_orig;
6267 +/* ---------------------------------------------------------------------- */
6270 + * generic routine for both of copy-up and copy-down.
6272 +/* cf. revalidate function in file.c */
6273 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6274 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6275 + struct au_pin *pin,
6276 + struct dentry *h_parent, void *arg),
6280 + struct au_pin pin;
6281 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6284 + parent = dget_parent(dentry);
6285 + if (IS_ROOT(parent))
6288 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6289 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6291 + /* do not use au_dpage */
6292 + real_parent = parent;
6295 + parent = dget_parent(dentry);
6296 + h_parent = au_h_dptr(parent, bdst);
6298 + goto out; /* success */
6300 + /* find top dir which is necessary to cpup */
6304 + parent = dget_parent(d);
6305 + di_read_lock_parent3(parent, !AuLock_IR);
6306 + h_parent = au_h_dptr(parent, bdst);
6307 + di_read_unlock(parent, !AuLock_IR);
6308 + } while (!h_parent);
6310 + if (d != real_parent)
6311 + di_write_lock_child3(d);
6313 + /* somebody else might create while we were sleeping */
6314 + h_dentry = au_h_dptr(d, bdst);
6315 + if (!h_dentry || d_is_negative(h_dentry)) {
6317 + au_update_dbtop(d);
6319 + au_pin_set_dentry(&pin, d);
6320 + err = au_do_pin(&pin);
6322 + err = cp(d, bdst, &pin, h_parent, arg);
6327 + if (d != real_parent)
6328 + di_write_unlock(d);
6329 + if (unlikely(err))
6338 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6339 + struct au_pin *pin,
6340 + struct dentry *h_parent __maybe_unused,
6341 + void *arg __maybe_unused)
6343 + struct au_cp_generic cpg = {
6349 + .flags = AuCpup_DTIME
6351 + return au_sio_cpup_simple(&cpg);
6354 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6356 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6359 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6362 + struct dentry *parent;
6363 + struct inode *dir;
6365 + parent = dget_parent(dentry);
6366 + dir = d_inode(parent);
6368 + if (au_h_iptr(dir, bdst))
6371 + di_read_unlock(parent, AuLock_IR);
6372 + di_write_lock_parent(parent);
6373 + /* someone else might change our inode while we were sleeping */
6374 + if (!au_h_iptr(dir, bdst))
6375 + err = au_cpup_dirs(dentry, bdst);
6376 + di_downgrade_lock(parent, AuLock_IR);
6382 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6383 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6384 +++ linux/fs/aufs/cpup.h 2019-07-11 15:42:14.462237786 +0200
6386 +/* SPDX-License-Identifier: GPL-2.0 */
6388 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6390 + * This program, aufs is free software; you can redistribute it and/or modify
6391 + * it under the terms of the GNU General Public License as published by
6392 + * the Free Software Foundation; either version 2 of the License, or
6393 + * (at your option) any later version.
6395 + * This program is distributed in the hope that it will be useful,
6396 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6397 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6398 + * GNU General Public License for more details.
6400 + * You should have received a copy of the GNU General Public License
6401 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6405 + * copy-up/down functions
6408 +#ifndef __AUFS_CPUP_H__
6409 +#define __AUFS_CPUP_H__
6413 +#include <linux/path.h>
6419 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6420 +void au_cpup_attr_timesizes(struct inode *inode);
6421 +void au_cpup_attr_nlink(struct inode *inode, int force);
6422 +void au_cpup_attr_changeable(struct inode *inode);
6423 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6424 +void au_cpup_attr_all(struct inode *inode, int force);
6426 +/* ---------------------------------------------------------------------- */
6428 +struct au_cp_generic {
6429 + struct dentry *dentry;
6430 + aufs_bindex_t bdst, bsrc;
6432 + struct au_pin *pin;
6433 + unsigned int flags;
6437 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6438 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6440 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6441 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6443 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6445 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6446 + the branch is marked as RO */
6448 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6449 +#undef AuCpup_HOPEN
6450 +#define AuCpup_HOPEN 0
6453 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6454 +#define au_fset_cpup(flags, name) \
6455 + do { (flags) |= AuCpup_##name; } while (0)
6456 +#define au_fclr_cpup(flags, name) \
6457 + do { (flags) &= ~AuCpup_##name; } while (0)
6459 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6460 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6461 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6462 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6464 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6465 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6466 + struct au_pin *pin,
6467 + struct dentry *h_parent, void *arg),
6469 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6470 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6472 +/* ---------------------------------------------------------------------- */
6474 +/* keep timestamps when copyup */
6476 + struct dentry *dt_dentry;
6477 + struct path dt_h_path;
6478 + struct timespec64 dt_atime, dt_mtime;
6480 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6481 + struct path *h_path);
6482 +void au_dtime_revert(struct au_dtime *dt);
6484 +#endif /* __KERNEL__ */
6485 +#endif /* __AUFS_CPUP_H__ */
6486 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6487 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6488 +++ linux/fs/aufs/dbgaufs.c 2019-07-11 15:42:14.462237786 +0200
6490 +// SPDX-License-Identifier: GPL-2.0
6492 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6494 + * This program, aufs is free software; you can redistribute it and/or modify
6495 + * it under the terms of the GNU General Public License as published by
6496 + * the Free Software Foundation; either version 2 of the License, or
6497 + * (at your option) any later version.
6499 + * This program is distributed in the hope that it will be useful,
6500 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6501 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6502 + * GNU General Public License for more details.
6504 + * You should have received a copy of the GNU General Public License
6505 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6509 + * debugfs interface
6512 +#include <linux/debugfs.h>
6515 +#ifndef CONFIG_SYSFS
6516 +#error DEBUG_FS depends upon SYSFS
6519 +static struct dentry *dbgaufs;
6520 +static const mode_t dbgaufs_mode = 0444;
6522 +/* 20 is max digits length of ulong 64 */
6523 +struct dbgaufs_arg {
6529 + * common function for all XINO files
6531 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6532 + struct file *file)
6536 + p = file->private_data;
6538 + /* this is struct dbgaufs_arg */
6539 + AuDebugOn(!au_kfree_sz_test(p));
6540 + au_kfree_do_rcu(p);
6545 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6550 + struct dbgaufs_arg *p;
6553 + p = kmalloc(sizeof(*p), GFP_NOFS);
6559 + file->private_data = p;
6563 + err = vfsub_getattr(&xf->f_path, &st);
6567 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6568 + cnt, st.blocks, st.blksize,
6569 + (long long)st.size);
6571 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6572 + st.blocks, st.blksize,
6573 + (long long)st.size);
6574 + AuDebugOn(p->n >= sizeof(p->a));
6576 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6584 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6585 + size_t count, loff_t *ppos)
6587 + struct dbgaufs_arg *p;
6589 + p = file->private_data;
6590 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6593 +/* ---------------------------------------------------------------------- */
6595 +struct dbgaufs_plink_arg {
6600 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6601 + struct file *file)
6603 + free_page((unsigned long)file->private_data);
6607 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6609 + int err, i, limit;
6610 + unsigned long n, sum;
6611 + struct dbgaufs_plink_arg *p;
6612 + struct au_sbinfo *sbinfo;
6613 + struct super_block *sb;
6614 + struct hlist_bl_head *hbl;
6617 + p = (void *)get_zeroed_page(GFP_NOFS);
6622 + sbinfo = inode->i_private;
6623 + sb = sbinfo->si_sb;
6624 + si_noflush_read_lock(sb);
6625 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6626 + limit = PAGE_SIZE - sizeof(p->n);
6628 + /* the number of buckets */
6629 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6634 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6636 + n = au_hbl_count(hbl);
6639 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6642 + if (unlikely(limit <= 0))
6645 + p->a[p->n - 1] = '\n';
6647 + /* the sum of plinks */
6648 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6651 + if (unlikely(limit <= 0))
6654 +#define str "1\n0\n0\n"
6655 + p->n = sizeof(str) - 1;
6656 + strcpy(p->a, str);
6659 + si_read_unlock(sb);
6662 + file->private_data = p;
6663 + goto out; /* success */
6666 + free_page((unsigned long)p);
6671 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6672 + size_t count, loff_t *ppos)
6674 + struct dbgaufs_plink_arg *p;
6676 + p = file->private_data;
6677 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6680 +static const struct file_operations dbgaufs_plink_fop = {
6681 + .owner = THIS_MODULE,
6682 + .open = dbgaufs_plink_open,
6683 + .release = dbgaufs_plink_release,
6684 + .read = dbgaufs_plink_read
6687 +/* ---------------------------------------------------------------------- */
6689 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6692 + struct au_sbinfo *sbinfo;
6693 + struct super_block *sb;
6695 + sbinfo = inode->i_private;
6696 + sb = sbinfo->si_sb;
6697 + si_noflush_read_lock(sb);
6698 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6699 + si_read_unlock(sb);
6703 +static const struct file_operations dbgaufs_xib_fop = {
6704 + .owner = THIS_MODULE,
6705 + .open = dbgaufs_xib_open,
6706 + .release = dbgaufs_xi_release,
6707 + .read = dbgaufs_xi_read
6710 +/* ---------------------------------------------------------------------- */
6712 +#define DbgaufsXi_PREFIX "xi"
6714 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6718 + aufs_bindex_t bindex;
6719 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6720 + struct au_sbinfo *sbinfo;
6721 + struct super_block *sb;
6722 + struct au_xino *xi;
6724 + struct qstr *name;
6725 + struct au_branch *br;
6728 + name = &file->f_path.dentry->d_name;
6729 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6730 + || memcmp(name->name, DbgaufsXi_PREFIX,
6731 + sizeof(DbgaufsXi_PREFIX) - 1)))
6734 + AuDebugOn(name->len >= sizeof(a));
6735 + memcpy(a, name->name, name->len);
6736 + a[name->len] = '\0';
6737 + p = strchr(a, '-');
6740 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6741 + if (unlikely(err))
6746 + err = kstrtol(p + 1, 10, &l);
6747 + if (unlikely(err))
6753 + sbinfo = inode->i_private;
6754 + sb = sbinfo->si_sb;
6755 + si_noflush_read_lock(sb);
6756 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6758 + br = au_sbr(sb, bindex);
6760 + if (unlikely(idx >= xi->xi_nfile))
6762 + xf = au_xino_file(xi, idx);
6764 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6765 + au_xino_count(br));
6768 + si_read_unlock(sb);
6774 +static const struct file_operations dbgaufs_xino_fop = {
6775 + .owner = THIS_MODULE,
6776 + .open = dbgaufs_xino_open,
6777 + .release = dbgaufs_xi_release,
6778 + .read = dbgaufs_xi_read
6781 +void dbgaufs_xino_del(struct au_branch *br)
6783 + struct dentry *dbgaufs;
6785 + dbgaufs = br->br_dbgaufs;
6789 + br->br_dbgaufs = NULL;
6790 + /* debugfs acquires the parent i_mutex */
6792 + debugfs_remove(dbgaufs);
6796 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6798 + aufs_bindex_t bbot;
6799 + struct au_branch *br;
6801 + if (!au_sbi(sb)->si_dbgaufs)
6804 + bbot = au_sbbot(sb);
6805 + for (; bindex <= bbot; bindex++) {
6806 + br = au_sbr(sb, bindex);
6807 + dbgaufs_xino_del(br);
6811 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6812 + unsigned int idx, struct dentry *parent,
6813 + struct au_sbinfo *sbinfo)
6815 + struct au_branch *br;
6817 + /* "xi" bindex(5) "-" idx(2) NULL */
6818 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6821 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6823 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6825 + br = au_sbr(sb, bindex);
6826 + if (br->br_dbgaufs) {
6827 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6829 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6830 + /* debugfs acquires the parent i_mutex */
6832 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6836 + pr_warn("failed renaming %pd/%s, ignored.\n",
6841 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6842 + sbinfo, &dbgaufs_xino_fop);
6844 + if (unlikely(!br->br_dbgaufs))
6845 + pr_warn("failed creating %pd/%s, ignored.\n",
6850 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6851 + struct dentry *parent, struct au_sbinfo *sbinfo)
6853 + struct au_branch *br;
6854 + struct au_xino *xi;
6857 + br = au_sbr(sb, bindex);
6859 + for (u = 0; u < xi->xi_nfile; u++)
6860 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6863 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6865 + struct au_sbinfo *sbinfo;
6866 + struct dentry *parent;
6867 + aufs_bindex_t bbot;
6869 + if (!au_opt_test(au_mntflags(sb), XINO))
6872 + sbinfo = au_sbi(sb);
6873 + parent = sbinfo->si_dbgaufs;
6877 + bbot = au_sbbot(sb);
6879 + for (; bindex <= bbot; bindex++)
6880 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6882 + for (; bbot >= bindex; bbot--)
6883 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6886 +/* ---------------------------------------------------------------------- */
6888 +#ifdef CONFIG_AUFS_EXPORT
6889 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6892 + struct au_sbinfo *sbinfo;
6893 + struct super_block *sb;
6895 + sbinfo = inode->i_private;
6896 + sb = sbinfo->si_sb;
6897 + si_noflush_read_lock(sb);
6898 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6899 + si_read_unlock(sb);
6903 +static const struct file_operations dbgaufs_xigen_fop = {
6904 + .owner = THIS_MODULE,
6905 + .open = dbgaufs_xigen_open,
6906 + .release = dbgaufs_xi_release,
6907 + .read = dbgaufs_xi_read
6910 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6915 + * This function is a dynamic '__init' function actually,
6916 + * so the tiny check for si_rwsem is unnecessary.
6918 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6921 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6922 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6923 + &dbgaufs_xigen_fop);
6924 + if (sbinfo->si_dbgaufs_xigen)
6930 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6934 +#endif /* CONFIG_AUFS_EXPORT */
6936 +/* ---------------------------------------------------------------------- */
6938 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6941 + * This function is a dynamic '__fin' function actually,
6942 + * so the tiny check for si_rwsem is unnecessary.
6944 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6946 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6947 + sbinfo->si_dbgaufs = NULL;
6950 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6953 + char name[SysaufsSiNameLen];
6956 + * This function is a dynamic '__init' function actually,
6957 + * so the tiny check for si_rwsem is unnecessary.
6959 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6963 + AuErr1("/debug/aufs is uninitialized\n");
6968 + sysaufs_name(sbinfo, name);
6969 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6970 + if (unlikely(!sbinfo->si_dbgaufs))
6973 + /* regardless plink/noplink option */
6974 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6975 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6976 + &dbgaufs_plink_fop);
6977 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6980 + /* regardless xino/noxino option */
6981 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6982 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6983 + &dbgaufs_xib_fop);
6984 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6987 + err = dbgaufs_xigen_init(sbinfo);
6989 + goto out; /* success */
6992 + dbgaufs_si_fin(sbinfo);
6994 + if (unlikely(err))
6995 + pr_err("debugfs/aufs failed\n");
6999 +/* ---------------------------------------------------------------------- */
7001 +void dbgaufs_fin(void)
7003 + debugfs_remove(dbgaufs);
7006 +int __init dbgaufs_init(void)
7011 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7016 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7017 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7018 +++ linux/fs/aufs/dbgaufs.h 2019-07-11 15:42:14.462237786 +0200
7020 +/* SPDX-License-Identifier: GPL-2.0 */
7022 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7024 + * This program, aufs is free software; you can redistribute it and/or modify
7025 + * it under the terms of the GNU General Public License as published by
7026 + * the Free Software Foundation; either version 2 of the License, or
7027 + * (at your option) any later version.
7029 + * This program is distributed in the hope that it will be useful,
7030 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7031 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7032 + * GNU General Public License for more details.
7034 + * You should have received a copy of the GNU General Public License
7035 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7039 + * debugfs interface
7042 +#ifndef __DBGAUFS_H__
7043 +#define __DBGAUFS_H__
7047 +struct super_block;
7051 +#ifdef CONFIG_DEBUG_FS
7053 +void dbgaufs_xino_del(struct au_branch *br);
7054 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7055 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7056 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7057 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7058 +void dbgaufs_fin(void);
7059 +int __init dbgaufs_init(void);
7061 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7062 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7063 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7065 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7066 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7067 +AuStubVoid(dbgaufs_fin, void)
7068 +AuStubInt0(__init dbgaufs_init, void)
7069 +#endif /* CONFIG_DEBUG_FS */
7071 +#endif /* __KERNEL__ */
7072 +#endif /* __DBGAUFS_H__ */
7073 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7074 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7075 +++ linux/fs/aufs/dcsub.c 2019-07-11 15:42:14.462237786 +0200
7077 +// SPDX-License-Identifier: GPL-2.0
7079 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7081 + * This program, aufs is free software; you can redistribute it and/or modify
7082 + * it under the terms of the GNU General Public License as published by
7083 + * the Free Software Foundation; either version 2 of the License, or
7084 + * (at your option) any later version.
7086 + * This program is distributed in the hope that it will be useful,
7087 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7089 + * GNU General Public License for more details.
7091 + * You should have received a copy of the GNU General Public License
7092 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7096 + * sub-routines for dentry cache
7101 +static void au_dpage_free(struct au_dpage *dpage)
7104 + struct dentry **p;
7106 + p = dpage->dentries;
7107 + for (i = 0; i < dpage->ndentry; i++)
7109 + free_page((unsigned long)dpage->dentries);
7112 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7118 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7119 + if (unlikely(!dpages->dpages))
7122 + p = (void *)__get_free_page(gfp);
7126 + dpages->dpages[0].ndentry = 0;
7127 + dpages->dpages[0].dentries = p;
7128 + dpages->ndpage = 1;
7129 + return 0; /* success */
7132 + au_kfree_try_rcu(dpages->dpages);
7137 +void au_dpages_free(struct au_dcsub_pages *dpages)
7140 + struct au_dpage *p;
7142 + p = dpages->dpages;
7143 + for (i = 0; i < dpages->ndpage; i++)
7144 + au_dpage_free(p++);
7145 + au_kfree_try_rcu(dpages->dpages);
7148 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7149 + struct dentry *dentry, gfp_t gfp)
7152 + struct au_dpage *dpage;
7155 + dpage = dpages->dpages + dpages->ndpage - 1;
7156 + sz = PAGE_SIZE / sizeof(dentry);
7157 + if (unlikely(dpage->ndentry >= sz)) {
7158 + AuLabel(new dpage);
7160 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7161 + p = au_kzrealloc(dpages->dpages, sz,
7162 + sz + sizeof(*dpages->dpages), gfp,
7167 + dpages->dpages = p;
7168 + dpage = dpages->dpages + dpages->ndpage;
7169 + p = (void *)__get_free_page(gfp);
7173 + dpage->ndentry = 0;
7174 + dpage->dentries = p;
7178 + AuDebugOn(au_dcount(dentry) <= 0);
7179 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7180 + return 0; /* success */
7186 +/* todo: BAD approach */
7187 +/* copied from linux/fs/dcache.c */
7195 +extern void d_walk(struct dentry *parent, void *data,
7196 + enum d_walk_ret (*enter)(void *, struct dentry *));
7198 +struct ac_dpages_arg {
7200 + struct au_dcsub_pages *dpages;
7201 + struct super_block *sb;
7202 + au_dpages_test test;
7206 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7208 + enum d_walk_ret ret;
7209 + struct ac_dpages_arg *arg = _arg;
7211 + ret = D_WALK_CONTINUE;
7212 + if (dentry->d_sb == arg->sb
7213 + && !IS_ROOT(dentry)
7214 + && au_dcount(dentry) > 0
7216 + && (!arg->test || arg->test(dentry, arg->arg))) {
7217 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7218 + if (unlikely(arg->err))
7219 + ret = D_WALK_QUIT;
7225 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7226 + au_dpages_test test, void *arg)
7228 + struct ac_dpages_arg args = {
7236 + d_walk(root, &args, au_call_dpages_append);
7241 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7242 + int do_include, au_dpages_test test, void *arg)
7247 + write_seqlock(&rename_lock);
7248 + spin_lock(&dentry->d_lock);
7250 + && au_dcount(dentry) > 0
7251 + && (!test || test(dentry, arg)))
7252 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7253 + spin_unlock(&dentry->d_lock);
7254 + if (unlikely(err))
7258 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7261 + while (!IS_ROOT(dentry)) {
7262 + dentry = dentry->d_parent; /* rename_lock is locked */
7263 + spin_lock(&dentry->d_lock);
7264 + if (au_dcount(dentry) > 0
7265 + && (!test || test(dentry, arg)))
7266 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7267 + spin_unlock(&dentry->d_lock);
7268 + if (unlikely(err))
7273 + write_sequnlock(&rename_lock);
7277 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7279 + return au_di(dentry) && dentry->d_sb == arg;
7282 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7283 + struct dentry *dentry, int do_include)
7285 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7286 + au_dcsub_dpages_aufs, dentry->d_sb);
7289 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7291 + struct path path[2] = {
7300 + return path_is_under(path + 0, path + 1);
7302 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7303 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7304 +++ linux/fs/aufs/dcsub.h 2019-07-11 15:42:14.462237786 +0200
7306 +/* SPDX-License-Identifier: GPL-2.0 */
7308 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7310 + * This program, aufs is free software; you can redistribute it and/or modify
7311 + * it under the terms of the GNU General Public License as published by
7312 + * the Free Software Foundation; either version 2 of the License, or
7313 + * (at your option) any later version.
7315 + * This program is distributed in the hope that it will be useful,
7316 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7317 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7318 + * GNU General Public License for more details.
7320 + * You should have received a copy of the GNU General Public License
7321 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7325 + * sub-routines for dentry cache
7328 +#ifndef __AUFS_DCSUB_H__
7329 +#define __AUFS_DCSUB_H__
7333 +#include <linux/dcache.h>
7334 +#include <linux/fs.h>
7338 + struct dentry **dentries;
7341 +struct au_dcsub_pages {
7343 + struct au_dpage *dpages;
7346 +/* ---------------------------------------------------------------------- */
7349 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7350 +void au_dpages_free(struct au_dcsub_pages *dpages);
7351 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7352 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7353 + au_dpages_test test, void *arg);
7354 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7355 + int do_include, au_dpages_test test, void *arg);
7356 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7357 + struct dentry *dentry, int do_include);
7358 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7360 +/* ---------------------------------------------------------------------- */
7363 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7364 + * include/linux/dcache.h. Try them (in the future).
7367 +static inline int au_d_hashed_positive(struct dentry *d)
7370 + struct inode *inode = d_inode(d);
7373 + if (unlikely(d_unhashed(d)
7374 + || d_is_negative(d)
7375 + || !inode->i_nlink))
7380 +static inline int au_d_linkable(struct dentry *d)
7383 + struct inode *inode = d_inode(d);
7385 + err = au_d_hashed_positive(d);
7387 + && d_is_positive(d)
7388 + && (inode->i_state & I_LINKABLE))
7393 +static inline int au_d_alive(struct dentry *d)
7396 + struct inode *inode;
7400 + err = au_d_hashed_positive(d);
7402 + inode = d_inode(d);
7403 + if (unlikely(d_unlinked(d)
7404 + || d_is_negative(d)
7405 + || !inode->i_nlink))
7411 +static inline int au_alive_dir(struct dentry *d)
7415 + err = au_d_alive(d);
7416 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7421 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7423 + return a->len == b->len
7424 + && !memcmp(a->name, b->name, a->len);
7429 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7431 + * the type of d_lockref.count became int, but the inlined function d_count()
7432 + * still returns unsigned int.
7433 + * I don't know why. Maybe it is for every d_count() users?
7434 + * Anyway au_dcount() lives on.
7436 +static inline int au_dcount(struct dentry *d)
7438 + return (int)d_count(d);
7441 +#endif /* __KERNEL__ */
7442 +#endif /* __AUFS_DCSUB_H__ */
7443 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7444 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7445 +++ linux/fs/aufs/debug.c 2019-07-11 15:42:14.462237786 +0200
7447 +// SPDX-License-Identifier: GPL-2.0
7449 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7451 + * This program, aufs is free software; you can redistribute it and/or modify
7452 + * it under the terms of the GNU General Public License as published by
7453 + * the Free Software Foundation; either version 2 of the License, or
7454 + * (at your option) any later version.
7456 + * This program is distributed in the hope that it will be useful,
7457 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7458 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7459 + * GNU General Public License for more details.
7461 + * You should have received a copy of the GNU General Public License
7462 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7466 + * debug print functions
7469 +#include <linux/iversion.h>
7472 +/* Returns 0, or -errno. arg is in kp->arg. */
7473 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7477 + err = kstrtoint(val, 0, &n);
7487 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7488 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7493 + return sprintf(buffer, "%d", atomic_read(a));
7496 +static struct kernel_param_ops param_ops_atomic_t = {
7497 + .set = param_atomic_t_set,
7498 + .get = param_atomic_t_get
7499 + /* void (*free)(void *arg) */
7502 +atomic_t aufs_debug = ATOMIC_INIT(0);
7503 +MODULE_PARM_DESC(debug, "debug print");
7504 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7506 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7507 +char *au_plevel = KERN_DEBUG;
7508 +#define dpri(fmt, ...) do { \
7510 + && strcmp(au_plevel, KERN_DEBUG)) \
7511 + || au_debug_test()) \
7512 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7515 +/* ---------------------------------------------------------------------- */
7517 +void au_dpri_whlist(struct au_nhash *whlist)
7519 + unsigned long ul, n;
7520 + struct hlist_head *head;
7521 + struct au_vdir_wh *pos;
7523 + n = whlist->nh_num;
7524 + head = whlist->nh_head;
7525 + for (ul = 0; ul < n; ul++) {
7526 + hlist_for_each_entry(pos, head, wh_hash)
7527 + dpri("b%d, %.*s, %d\n",
7529 + pos->wh_str.len, pos->wh_str.name,
7535 +void au_dpri_vdir(struct au_vdir *vdir)
7538 + union au_vdir_deblk_p p;
7541 + if (!vdir || IS_ERR(vdir)) {
7542 + dpri("err %ld\n", PTR_ERR(vdir));
7546 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7547 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7548 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7549 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7550 + p.deblk = vdir->vd_deblk[ul];
7552 + dpri("[%lu]: %p\n", ul, o);
7556 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7557 + struct dentry *wh)
7562 + if (!inode || IS_ERR(inode)) {
7563 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7567 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7568 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7569 + && sizeof(inode->i_blocks) != sizeof(u64));
7571 + n = (void *)wh->d_name.name;
7572 + l = wh->d_name.len;
7575 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7576 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7578 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7579 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7580 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7581 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7582 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7583 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7584 + inode->i_generation,
7585 + l ? ", wh " : "", l, n);
7589 +void au_dpri_inode(struct inode *inode)
7591 + struct au_iinfo *iinfo;
7592 + struct au_hinode *hi;
7593 + aufs_bindex_t bindex;
7596 + err = do_pri_inode(-1, inode, -1, NULL);
7597 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7600 + iinfo = au_ii(inode);
7601 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7602 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7603 + if (iinfo->ii_btop < 0)
7606 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7607 + hi = au_hinode(iinfo, bindex);
7609 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7613 +void au_dpri_dalias(struct inode *inode)
7617 + spin_lock(&inode->i_lock);
7618 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7619 + au_dpri_dentry(d);
7620 + spin_unlock(&inode->i_lock);
7623 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7625 + struct dentry *wh = NULL;
7627 + struct inode *inode;
7628 + struct au_iinfo *iinfo;
7629 + struct au_hinode *hi;
7631 + if (!dentry || IS_ERR(dentry)) {
7632 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7635 + /* do not call dget_parent() here */
7636 + /* note: access d_xxx without d_lock */
7637 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7638 + bindex, dentry, dentry,
7639 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7640 + au_dcount(dentry), dentry->d_flags,
7641 + d_unhashed(dentry) ? "un" : "");
7644 + if (d_is_positive(dentry))
7645 + inode = d_inode(dentry);
7647 + && au_test_aufs(dentry->d_sb)
7649 + && !au_is_bad_inode(inode)) {
7650 + iinfo = au_ii(inode);
7651 + hi = au_hinode(iinfo, bindex);
7653 + wh = hi->hi_whdentry;
7655 + do_pri_inode(bindex, inode, hn, wh);
7659 +void au_dpri_dentry(struct dentry *dentry)
7661 + struct au_dinfo *dinfo;
7662 + aufs_bindex_t bindex;
7665 + err = do_pri_dentry(-1, dentry);
7666 + if (err || !au_test_aufs(dentry->d_sb))
7669 + dinfo = au_di(dentry);
7672 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7673 + dinfo->di_btop, dinfo->di_bbot,
7674 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7675 + dinfo->di_tmpfile);
7676 + if (dinfo->di_btop < 0)
7678 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7679 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7682 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7686 + if (!file || IS_ERR(file)) {
7687 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7692 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7693 + && au_test_aufs(file->f_path.dentry->d_sb)
7695 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7696 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7697 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7698 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7699 + file->f_version, file->f_pos, a);
7700 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7701 + do_pri_dentry(bindex, file->f_path.dentry);
7705 +void au_dpri_file(struct file *file)
7707 + struct au_finfo *finfo;
7708 + struct au_fidir *fidir;
7709 + struct au_hfile *hfile;
7710 + aufs_bindex_t bindex;
7713 + err = do_pri_file(-1, file);
7715 + || IS_ERR_OR_NULL(file->f_path.dentry)
7716 + || !au_test_aufs(file->f_path.dentry->d_sb))
7719 + finfo = au_fi(file);
7722 + if (finfo->fi_btop < 0)
7724 + fidir = finfo->fi_hdir;
7726 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7728 + for (bindex = finfo->fi_btop;
7729 + bindex >= 0 && bindex <= fidir->fd_bbot;
7731 + hfile = fidir->fd_hfile + bindex;
7732 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7736 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7738 + struct vfsmount *mnt;
7739 + struct super_block *sb;
7741 + if (!br || IS_ERR(br))
7743 + mnt = au_br_mnt(br);
7744 + if (!mnt || IS_ERR(mnt))
7747 + if (!sb || IS_ERR(sb))
7750 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7751 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7753 + bindex, br->br_perm, br->br_id, br->br_wbr,
7754 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7755 + sb->s_flags, sb->s_count,
7756 + atomic_read(&sb->s_active),
7757 + !!au_xino_file(br->br_xino, /*idx*/-1));
7761 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7765 +void au_dpri_sb(struct super_block *sb)
7767 + struct au_sbinfo *sbinfo;
7768 + aufs_bindex_t bindex;
7770 + /* to reduce stack size */
7772 + struct vfsmount mnt;
7773 + struct au_branch fake;
7776 + /* this function can be called from magic sysrq */
7777 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7778 + if (unlikely(!a)) {
7779 + dpri("no memory\n");
7783 + a->mnt.mnt_sb = sb;
7784 + a->fake.br_path.mnt = &a->mnt;
7785 + err = do_pri_br(-1, &a->fake);
7787 + dpri("dev 0x%x\n", sb->s_dev);
7788 + if (err || !au_test_aufs(sb))
7791 + sbinfo = au_sbi(sb);
7794 + dpri("nw %d, gen %u, kobj %d\n",
7795 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7796 + kref_read(&sbinfo->si_kobj.kref));
7797 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7798 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7801 +/* ---------------------------------------------------------------------- */
7803 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7805 + struct inode *h_inode, *inode = d_inode(dentry);
7806 + struct dentry *h_dentry;
7807 + aufs_bindex_t bindex, bbot, bi;
7809 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7812 + bbot = au_dbbot(dentry);
7813 + bi = au_ibbot(inode);
7816 + bindex = au_dbtop(dentry);
7817 + bi = au_ibtop(inode);
7821 + for (; bindex <= bbot; bindex++) {
7822 + h_dentry = au_h_dptr(dentry, bindex);
7825 + h_inode = au_h_iptr(inode, bindex);
7826 + if (unlikely(h_inode != d_inode(h_dentry))) {
7828 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7829 + AuDbgDentry(dentry);
7830 + AuDbgInode(inode);
7837 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7840 + struct au_dcsub_pages dpages;
7841 + struct au_dpage *dpage;
7842 + struct dentry **dentries;
7844 + err = au_dpages_init(&dpages, GFP_NOFS);
7846 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7848 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7849 + dpage = dpages.dpages + i;
7850 + dentries = dpage->dentries;
7851 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7852 + AuDebugOn(au_digen_test(dentries[j], sigen));
7854 + au_dpages_free(&dpages);
7857 +void au_dbg_verify_kthread(void)
7859 + if (au_wkq_test()) {
7862 + * It may be recursive, but udba=notify between two aufs mounts,
7863 + * where a single ro branch is shared, is not a problem.
7869 +/* ---------------------------------------------------------------------- */
7871 +int __init au_debug_init(void)
7873 + aufs_bindex_t bindex;
7874 + struct au_vdir_destr destr;
7877 + AuDebugOn(bindex >= 0);
7880 + AuDebugOn(destr.len < NAME_MAX);
7882 +#ifdef CONFIG_4KSTACKS
7883 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7888 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7889 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7890 +++ linux/fs/aufs/debug.h 2019-07-11 15:42:14.462237786 +0200
7892 +/* SPDX-License-Identifier: GPL-2.0 */
7894 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7896 + * This program, aufs is free software; you can redistribute it and/or modify
7897 + * it under the terms of the GNU General Public License as published by
7898 + * the Free Software Foundation; either version 2 of the License, or
7899 + * (at your option) any later version.
7901 + * This program is distributed in the hope that it will be useful,
7902 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7904 + * GNU General Public License for more details.
7906 + * You should have received a copy of the GNU General Public License
7907 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7911 + * debug print functions
7914 +#ifndef __AUFS_DEBUG_H__
7915 +#define __AUFS_DEBUG_H__
7919 +#include <linux/atomic.h>
7920 +#include <linux/module.h>
7921 +#include <linux/kallsyms.h>
7922 +#include <linux/sysrq.h>
7924 +#ifdef CONFIG_AUFS_DEBUG
7925 +#define AuDebugOn(a) BUG_ON(a)
7927 +/* module parameter */
7928 +extern atomic_t aufs_debug;
7929 +static inline void au_debug_on(void)
7931 + atomic_inc(&aufs_debug);
7933 +static inline void au_debug_off(void)
7935 + atomic_dec_if_positive(&aufs_debug);
7938 +static inline int au_debug_test(void)
7940 + return atomic_read(&aufs_debug) > 0;
7943 +#define AuDebugOn(a) do {} while (0)
7944 +AuStubVoid(au_debug_on, void)
7945 +AuStubVoid(au_debug_off, void)
7946 +AuStubInt0(au_debug_test, void)
7947 +#endif /* CONFIG_AUFS_DEBUG */
7949 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7951 +/* ---------------------------------------------------------------------- */
7955 +#define AuDbg(fmt, ...) do { \
7956 + if (au_debug_test()) \
7957 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7959 +#define AuLabel(l) AuDbg(#l "\n")
7960 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7961 +#define AuWarn1(fmt, ...) do { \
7962 + static unsigned char _c; \
7964 + pr_warn(fmt, ##__VA_ARGS__); \
7967 +#define AuErr1(fmt, ...) do { \
7968 + static unsigned char _c; \
7970 + pr_err(fmt, ##__VA_ARGS__); \
7973 +#define AuIOErr1(fmt, ...) do { \
7974 + static unsigned char _c; \
7976 + AuIOErr(fmt, ##__VA_ARGS__); \
7979 +#define AuUnsupportMsg "This operation is not supported." \
7980 + " Please report this application to aufs-users ML."
7981 +#define AuUnsupport(fmt, ...) do { \
7982 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7986 +#define AuTraceErr(e) do { \
7987 + if (unlikely((e) < 0)) \
7988 + AuDbg("err %d\n", (int)(e)); \
7991 +#define AuTraceErrPtr(p) do { \
7993 + AuDbg("err %ld\n", PTR_ERR(p)); \
7996 +/* dirty macros for debug print, use with "%.*s" and caution */
7997 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7999 +/* ---------------------------------------------------------------------- */
8002 +#ifdef CONFIG_AUFS_DEBUG
8003 +extern struct mutex au_dbg_mtx;
8004 +extern char *au_plevel;
8006 +void au_dpri_whlist(struct au_nhash *whlist);
8008 +void au_dpri_vdir(struct au_vdir *vdir);
8010 +void au_dpri_inode(struct inode *inode);
8011 +void au_dpri_dalias(struct inode *inode);
8012 +void au_dpri_dentry(struct dentry *dentry);
8014 +void au_dpri_file(struct file *filp);
8015 +struct super_block;
8016 +void au_dpri_sb(struct super_block *sb);
8018 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8019 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8020 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8021 +void au_dbg_verify_kthread(void);
8023 +int __init au_debug_init(void);
8025 +#define AuDbgWhlist(w) do { \
8026 + mutex_lock(&au_dbg_mtx); \
8028 + au_dpri_whlist(w); \
8029 + mutex_unlock(&au_dbg_mtx); \
8032 +#define AuDbgVdir(v) do { \
8033 + mutex_lock(&au_dbg_mtx); \
8035 + au_dpri_vdir(v); \
8036 + mutex_unlock(&au_dbg_mtx); \
8039 +#define AuDbgInode(i) do { \
8040 + mutex_lock(&au_dbg_mtx); \
8042 + au_dpri_inode(i); \
8043 + mutex_unlock(&au_dbg_mtx); \
8046 +#define AuDbgDAlias(i) do { \
8047 + mutex_lock(&au_dbg_mtx); \
8049 + au_dpri_dalias(i); \
8050 + mutex_unlock(&au_dbg_mtx); \
8053 +#define AuDbgDentry(d) do { \
8054 + mutex_lock(&au_dbg_mtx); \
8056 + au_dpri_dentry(d); \
8057 + mutex_unlock(&au_dbg_mtx); \
8060 +#define AuDbgFile(f) do { \
8061 + mutex_lock(&au_dbg_mtx); \
8063 + au_dpri_file(f); \
8064 + mutex_unlock(&au_dbg_mtx); \
8067 +#define AuDbgSb(sb) do { \
8068 + mutex_lock(&au_dbg_mtx); \
8069 + AuDbg(#sb "\n"); \
8071 + mutex_unlock(&au_dbg_mtx); \
8074 +#define AuDbgSym(addr) do { \
8075 + char sym[KSYM_SYMBOL_LEN]; \
8076 + sprint_symbol(sym, (unsigned long)addr); \
8077 + AuDbg("%s\n", sym); \
8080 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8081 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8082 +AuStubVoid(au_dbg_verify_kthread, void)
8083 +AuStubInt0(__init au_debug_init, void)
8085 +#define AuDbgWhlist(w) do {} while (0)
8086 +#define AuDbgVdir(v) do {} while (0)
8087 +#define AuDbgInode(i) do {} while (0)
8088 +#define AuDbgDAlias(i) do {} while (0)
8089 +#define AuDbgDentry(d) do {} while (0)
8090 +#define AuDbgFile(f) do {} while (0)
8091 +#define AuDbgSb(sb) do {} while (0)
8092 +#define AuDbgSym(addr) do {} while (0)
8093 +#endif /* CONFIG_AUFS_DEBUG */
8095 +/* ---------------------------------------------------------------------- */
8097 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8098 +int __init au_sysrq_init(void);
8099 +void au_sysrq_fin(void);
8101 +#ifdef CONFIG_HW_CONSOLE
8102 +#define au_dbg_blocked() do { \
8104 + handle_sysrq('w'); \
8107 +AuStubVoid(au_dbg_blocked, void)
8111 +AuStubInt0(__init au_sysrq_init, void)
8112 +AuStubVoid(au_sysrq_fin, void)
8113 +AuStubVoid(au_dbg_blocked, void)
8114 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8116 +#endif /* __KERNEL__ */
8117 +#endif /* __AUFS_DEBUG_H__ */
8118 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8119 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8120 +++ linux/fs/aufs/dentry.c 2019-07-11 15:42:14.462237786 +0200
8122 +// SPDX-License-Identifier: GPL-2.0
8124 + * Copyright (C) 2005-2019 Junjiro R. Okajima
8126 + * This program, aufs is free software; you can redistribute it and/or modify
8127 + * it under the terms of the GNU General Public License as published by
8128 + * the Free Software Foundation; either version 2 of the License, or
8129 + * (at your option) any later version.
8131 + * This program is distributed in the hope that it will be useful,
8132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8134 + * GNU General Public License for more details.
8136 + * You should have received a copy of the GNU General Public License
8137 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8141 + * lookup and dentry operations
8144 +#include <linux/iversion.h>
8145 +#include <linux/namei.h>
8149 + * returns positive/negative dentry, NULL or an error.
8150 + * NULL means whiteout-ed or not-found.
8152 +static struct dentry*
8153 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8154 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8156 + struct dentry *h_dentry;
8157 + struct inode *h_inode;
8158 + struct au_branch *br;
8159 + int wh_found, opq;
8160 + unsigned char wh_able;
8161 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8162 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8166 + br = au_sbr(dentry->d_sb, bindex);
8167 + wh_able = !!au_br_whable(br->br_perm);
8169 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8170 + h_dentry = ERR_PTR(wh_found);
8173 + if (unlikely(wh_found < 0))
8176 + /* We found a whiteout */
8177 + /* au_set_dbbot(dentry, bindex); */
8178 + au_set_dbwh(dentry, bindex);
8180 + return NULL; /* success */
8184 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8186 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8187 + if (IS_ERR(h_dentry)) {
8188 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8194 + h_inode = d_inode(h_dentry);
8195 + if (d_is_negative(h_dentry)) {
8198 + } else if (wh_found
8199 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8201 + else if (au_ftest_lkup(args->flags, DIRREN)
8203 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8204 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8205 + (unsigned long long)h_inode->i_ino);
8209 + if (au_dbbot(dentry) <= bindex)
8210 + au_set_dbbot(dentry, bindex);
8211 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8212 + au_set_dbtop(dentry, bindex);
8213 + au_set_h_dptr(dentry, bindex, h_dentry);
8215 + if (!d_is_dir(h_dentry)
8217 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8218 + goto out; /* success */
8220 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8221 + opq = au_diropq_test(h_dentry);
8222 + inode_unlock_shared(h_inode);
8224 + au_set_dbdiropq(dentry, bindex);
8225 + else if (unlikely(opq < 0)) {
8226 + au_set_h_dptr(dentry, bindex, NULL);
8227 + h_dentry = ERR_PTR(opq);
8238 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8240 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8241 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8247 + * returns the number of lower positive dentries,
8248 + * otherwise an error.
8249 + * can be called at unlinking with @type is zero.
8251 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8252 + unsigned int flags)
8254 + int npositive, err;
8255 + aufs_bindex_t bindex, btail, bdiropq;
8256 + unsigned char isdir, dirperm1, dirren;
8257 + struct au_do_lookup_args args = {
8259 + .name = &dentry->d_name
8261 + struct dentry *parent;
8262 + struct super_block *sb;
8264 + sb = dentry->d_sb;
8265 + err = au_test_shwh(sb, args.name);
8266 + if (unlikely(err))
8269 + err = au_wh_name_alloc(&args.whname, args.name);
8270 + if (unlikely(err))
8273 + isdir = !!d_is_dir(dentry);
8274 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8275 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8277 + au_fset_lkup(args.flags, DIRREN);
8280 + parent = dget_parent(dentry);
8281 + btail = au_dbtaildir(parent);
8282 + for (bindex = btop; bindex <= btail; bindex++) {
8283 + struct dentry *h_parent, *h_dentry;
8284 + struct inode *h_inode, *h_dir;
8285 + struct au_branch *br;
8287 + h_dentry = au_h_dptr(dentry, bindex);
8289 + if (d_is_positive(h_dentry))
8293 + h_parent = au_h_dptr(parent, bindex);
8294 + if (!h_parent || !d_is_dir(h_parent))
8298 + /* if the inum matches, then use the prepared name */
8299 + err = au_dr_lkup_name(&args, bindex);
8300 + if (unlikely(err))
8304 + h_dir = d_inode(h_parent);
8305 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8306 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8307 + inode_unlock_shared(h_dir);
8308 + err = PTR_ERR(h_dentry);
8309 + if (IS_ERR(h_dentry))
8312 + au_fclr_lkup(args.flags, ALLOW_NEG);
8314 + au_fset_lkup(args.flags, IGNORE_PERM);
8316 + if (au_dbwh(dentry) == bindex)
8320 + if (d_is_negative(h_dentry))
8322 + h_inode = d_inode(h_dentry);
8325 + args.type = h_inode->i_mode & S_IFMT;
8326 + if (args.type != S_IFDIR)
8329 + /* the type of lower may be different */
8330 + bdiropq = au_dbdiropq(dentry);
8331 + if (bdiropq >= 0 && bdiropq <= bindex)
8334 + br = au_sbr(sb, bindex);
8336 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8337 + /*add_ent*/NULL)) {
8338 + /* prepare next name to lookup */
8339 + err = au_dr_lkup(&args, dentry, bindex);
8340 + if (unlikely(err))
8346 + AuLabel(positive);
8347 + au_update_dbtop(dentry);
8350 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8351 + && au_dbtop(dentry) < 0)) {
8353 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8359 + au_kfree_try_rcu(args.whname.name);
8361 + au_dr_lkup_fin(&args);
8366 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8368 + struct dentry *dentry;
8371 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8372 + dentry = vfsub_lkup_one(name, parent);
8374 + struct vfsub_lkup_one_args args = {
8380 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8381 + if (unlikely(wkq_err))
8382 + dentry = ERR_PTR(wkq_err);
8389 + * lookup @dentry on @bindex which should be negative.
8391 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8394 + struct dentry *parent, *h_parent, *h_dentry;
8395 + struct au_branch *br;
8397 + parent = dget_parent(dentry);
8398 + h_parent = au_h_dptr(parent, bindex);
8399 + br = au_sbr(dentry->d_sb, bindex);
8401 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8403 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8404 + err = PTR_ERR(h_dentry);
8405 + if (IS_ERR(h_dentry))
8407 + if (unlikely(d_is_positive(h_dentry))) {
8409 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8415 + if (bindex < au_dbtop(dentry))
8416 + au_set_dbtop(dentry, bindex);
8417 + if (au_dbbot(dentry) < bindex)
8418 + au_set_dbbot(dentry, bindex);
8419 + au_set_h_dptr(dentry, bindex, h_dentry);
8426 +/* ---------------------------------------------------------------------- */
8428 +/* subset of struct inode */
8430 + unsigned long i_ino;
8431 + /* unsigned int i_nlink; */
8437 + blkcnt_t i_blocks;
8442 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8444 + ia->i_ino = h_inode->i_ino;
8445 + /* ia->i_nlink = h_inode->i_nlink; */
8446 + ia->i_uid = h_inode->i_uid;
8447 + ia->i_gid = h_inode->i_gid;
8448 + ia->i_version = inode_query_iversion(h_inode);
8450 + ia->i_size = h_inode->i_size;
8451 + ia->i_blocks = h_inode->i_blocks;
8453 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8456 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8458 + return ia->i_ino != h_inode->i_ino
8459 + /* || ia->i_nlink != h_inode->i_nlink */
8460 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8461 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8462 + || !inode_eq_iversion(h_inode, ia->i_version)
8464 + || ia->i_size != h_inode->i_size
8465 + || ia->i_blocks != h_inode->i_blocks
8467 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8470 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8471 + struct au_branch *br)
8474 + struct au_iattr ia;
8475 + struct inode *h_inode;
8476 + struct dentry *h_d;
8477 + struct super_block *h_sb;
8480 + memset(&ia, -1, sizeof(ia));
8481 + h_sb = h_dentry->d_sb;
8483 + if (d_is_positive(h_dentry)) {
8484 + h_inode = d_inode(h_dentry);
8485 + au_iattr_save(&ia, h_inode);
8486 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8487 + /* nfs d_revalidate may return 0 for negative dentry */
8488 + /* fuse d_revalidate always return 0 for negative dentry */
8491 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8492 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8493 + err = PTR_ERR(h_d);
8498 + if (unlikely(h_d != h_dentry
8499 + || d_inode(h_d) != h_inode
8500 + || (h_inode && au_iattr_test(&ia, h_inode))))
8501 + err = au_busy_or_stale();
8509 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8510 + struct dentry *h_parent, struct au_branch *br)
8515 + if (udba == AuOpt_UDBA_REVAL
8516 + && !au_test_fs_remote(h_dentry->d_sb)) {
8518 + err = (d_inode(h_dentry->d_parent) != h_dir);
8519 + } else if (udba != AuOpt_UDBA_NONE)
8520 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8525 +/* ---------------------------------------------------------------------- */
8527 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8530 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8531 + struct au_hdentry tmp, *p, *q;
8532 + struct au_dinfo *dinfo;
8533 + struct super_block *sb;
8535 + DiMustWriteLock(dentry);
8537 + sb = dentry->d_sb;
8538 + dinfo = au_di(dentry);
8539 + bbot = dinfo->di_bbot;
8540 + bwh = dinfo->di_bwh;
8541 + bdiropq = dinfo->di_bdiropq;
8542 + bindex = dinfo->di_btop;
8543 + p = au_hdentry(dinfo, bindex);
8544 + for (; bindex <= bbot; bindex++, p++) {
8545 + if (!p->hd_dentry)
8548 + new_bindex = au_br_index(sb, p->hd_id);
8549 + if (new_bindex == bindex)
8552 + if (dinfo->di_bwh == bindex)
8554 + if (dinfo->di_bdiropq == bindex)
8555 + bdiropq = new_bindex;
8556 + if (new_bindex < 0) {
8558 + p->hd_dentry = NULL;
8562 + /* swap two lower dentries, and loop again */
8563 + q = au_hdentry(dinfo, new_bindex);
8567 + if (tmp.hd_dentry) {
8573 + dinfo->di_bwh = -1;
8574 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8575 + dinfo->di_bwh = bwh;
8577 + dinfo->di_bdiropq = -1;
8579 + && bdiropq <= au_sbbot(sb)
8580 + && au_sbr_whable(sb, bdiropq))
8581 + dinfo->di_bdiropq = bdiropq;
8584 + dinfo->di_btop = -1;
8585 + dinfo->di_bbot = -1;
8586 + bbot = au_dbbot(parent);
8588 + p = au_hdentry(dinfo, bindex);
8589 + for (; bindex <= bbot; bindex++, p++)
8590 + if (p->hd_dentry) {
8591 + dinfo->di_btop = bindex;
8595 + if (dinfo->di_btop >= 0) {
8597 + p = au_hdentry(dinfo, bindex);
8598 + for (; bindex >= 0; bindex--, p--)
8599 + if (p->hd_dentry) {
8600 + dinfo->di_bbot = bindex;
8609 +static void au_do_hide(struct dentry *dentry)
8611 + struct inode *inode;
8613 + if (d_really_is_positive(dentry)) {
8614 + inode = d_inode(dentry);
8615 + if (!d_is_dir(dentry)) {
8616 + if (inode->i_nlink && !d_unhashed(dentry))
8617 + drop_nlink(inode);
8619 + clear_nlink(inode);
8620 + /* stop next lookup */
8621 + inode->i_flags |= S_DEAD;
8623 + smp_mb(); /* necessary? */
8628 +static int au_hide_children(struct dentry *parent)
8630 + int err, i, j, ndentry;
8631 + struct au_dcsub_pages dpages;
8632 + struct au_dpage *dpage;
8633 + struct dentry *dentry;
8635 + err = au_dpages_init(&dpages, GFP_NOFS);
8636 + if (unlikely(err))
8638 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8639 + if (unlikely(err))
8642 + /* in reverse order */
8643 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8644 + dpage = dpages.dpages + i;
8645 + ndentry = dpage->ndentry;
8646 + for (j = ndentry - 1; j >= 0; j--) {
8647 + dentry = dpage->dentries[j];
8648 + if (dentry != parent)
8649 + au_do_hide(dentry);
8654 + au_dpages_free(&dpages);
8659 +static void au_hide(struct dentry *dentry)
8663 + AuDbgDentry(dentry);
8664 + if (d_is_dir(dentry)) {
8665 + /* shrink_dcache_parent(dentry); */
8666 + err = au_hide_children(dentry);
8667 + if (unlikely(err))
8668 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8671 + au_do_hide(dentry);
8675 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8677 + * a dirty branch is added
8678 + * - on the top of layers
8679 + * - in the middle of layers
8680 + * - to the bottom of layers
8682 + * on the added branch there exists
8685 + * - a same named entry
8687 + * * negative --> positive
8688 + * * positive --> positive
8689 + * - type is unchanged
8690 + * - type is changed
8692 + * * negative --> negative
8693 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8696 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8697 + struct au_dinfo *tmp)
8700 + aufs_bindex_t bindex, bbot;
8702 + struct dentry *dentry;
8703 + struct inode *inode;
8705 + } orig_h, tmp_h = {
8708 + struct au_hdentry *hd;
8709 + struct inode *inode, *h_inode;
8710 + struct dentry *h_dentry;
8713 + AuDebugOn(dinfo->di_btop < 0);
8715 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8716 + orig_h.inode = NULL;
8717 + if (d_is_positive(orig_h.dentry)) {
8718 + orig_h.inode = d_inode(orig_h.dentry);
8719 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8721 + if (tmp->di_btop >= 0) {
8722 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8723 + if (d_is_positive(tmp_h.dentry)) {
8724 + tmp_h.inode = d_inode(tmp_h.dentry);
8725 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8730 + if (d_really_is_positive(dentry))
8731 + inode = d_inode(dentry);
8732 + if (!orig_h.inode) {
8733 + AuDbg("negative originally\n");
8739 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8740 + AuDebugOn(dinfo->di_bdiropq != -1);
8742 + if (!tmp_h.inode) {
8743 + AuDbg("negative --> negative\n");
8744 + /* should have only one negative lower */
8745 + if (tmp->di_btop >= 0
8746 + && tmp->di_btop < dinfo->di_btop) {
8747 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8748 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8749 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8750 + au_di_cp(dinfo, tmp);
8751 + hd = au_hdentry(tmp, tmp->di_btop);
8752 + au_set_h_dptr(dentry, tmp->di_btop,
8753 + dget(hd->hd_dentry));
8755 + au_dbg_verify_dinode(dentry);
8757 + AuDbg("negative --> positive\n");
8759 + * similar to the behaviour of creating with bypassing
8761 + * unhash it in order to force an error in the
8762 + * succeeding create operation.
8763 + * we should not set S_DEAD here.
8766 + /* au_di_swap(tmp, dinfo); */
8767 + au_dbg_verify_dinode(dentry);
8770 + AuDbg("positive originally\n");
8771 + /* inode may be NULL */
8772 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8773 + if (!tmp_h.inode) {
8774 + AuDbg("positive --> negative\n");
8775 + /* or bypassing aufs */
8777 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8778 + dinfo->di_bwh = tmp->di_bwh;
8780 + err = au_refresh_hinode_self(inode);
8781 + au_dbg_verify_dinode(dentry);
8782 + } else if (orig_h.mode == tmp_h.mode) {
8783 + AuDbg("positive --> positive, same type\n");
8784 + if (!S_ISDIR(orig_h.mode)
8785 + && dinfo->di_btop > tmp->di_btop) {
8787 + * similar to the behaviour of removing and
8792 + err = au_refresh_hinode_self(inode);
8793 + au_dbg_verify_dinode(dentry);
8795 + /* fill empty slots */
8796 + if (dinfo->di_btop > tmp->di_btop)
8797 + dinfo->di_btop = tmp->di_btop;
8798 + if (dinfo->di_bbot < tmp->di_bbot)
8799 + dinfo->di_bbot = tmp->di_bbot;
8800 + dinfo->di_bwh = tmp->di_bwh;
8801 + dinfo->di_bdiropq = tmp->di_bdiropq;
8802 + bbot = dinfo->di_bbot;
8803 + bindex = tmp->di_btop;
8804 + hd = au_hdentry(tmp, bindex);
8805 + for (; bindex <= bbot; bindex++, hd++) {
8806 + if (au_h_dptr(dentry, bindex))
8808 + h_dentry = hd->hd_dentry;
8811 + AuDebugOn(d_is_negative(h_dentry));
8812 + h_inode = d_inode(h_dentry);
8813 + AuDebugOn(orig_h.mode
8814 + != (h_inode->i_mode
8816 + au_set_h_dptr(dentry, bindex,
8820 + err = au_refresh_hinode(inode, dentry);
8821 + au_dbg_verify_dinode(dentry);
8824 + AuDbg("positive --> positive, different type\n");
8825 + /* similar to the behaviour of removing and creating */
8828 + err = au_refresh_hinode_self(inode);
8829 + au_dbg_verify_dinode(dentry);
8837 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8839 + const struct dentry_operations *dop
8840 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8841 + static const unsigned int mask
8842 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8844 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8846 + if (dentry->d_op == dop)
8849 + AuDbg("%pd\n", dentry);
8850 + spin_lock(&dentry->d_lock);
8851 + if (dop == &aufs_dop)
8852 + dentry->d_flags |= mask;
8854 + dentry->d_flags &= ~mask;
8855 + dentry->d_op = dop;
8856 + spin_unlock(&dentry->d_lock);
8859 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8861 + int err, ebrange, nbr;
8862 + unsigned int sigen;
8863 + struct au_dinfo *dinfo, *tmp;
8864 + struct super_block *sb;
8865 + struct inode *inode;
8867 + DiMustWriteLock(dentry);
8868 + AuDebugOn(IS_ROOT(dentry));
8869 + AuDebugOn(d_really_is_negative(parent));
8871 + sb = dentry->d_sb;
8872 + sigen = au_sigen(sb);
8873 + err = au_digen_test(parent, sigen);
8874 + if (unlikely(err))
8877 + nbr = au_sbbot(sb) + 1;
8878 + dinfo = au_di(dentry);
8879 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8880 + if (unlikely(err))
8882 + ebrange = au_dbrange_test(dentry);
8884 + ebrange = au_do_refresh_hdentry(dentry, parent);
8886 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8887 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8888 + if (d_really_is_positive(dentry)) {
8889 + inode = d_inode(dentry);
8890 + err = au_refresh_hinode_self(inode);
8892 + au_dbg_verify_dinode(dentry);
8894 + goto out_dgen; /* success */
8898 + /* temporary dinfo */
8899 + AuDbgDentry(dentry);
8901 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8902 + if (unlikely(!tmp))
8904 + au_di_swap(tmp, dinfo);
8905 + /* returns the number of positive dentries */
8907 + * if current working dir is removed, it returns an error.
8908 + * but the dentry is legal.
8910 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8911 + AuDbgDentry(dentry);
8912 + au_di_swap(tmp, dinfo);
8913 + if (err == -ENOENT)
8916 + /* compare/refresh by dinfo */
8917 + AuDbgDentry(dentry);
8918 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8919 + au_dbg_verify_dinode(dentry);
8922 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8923 + au_rw_write_unlock(&tmp->di_rwsem);
8925 + if (unlikely(err))
8929 + au_update_digen(dentry);
8931 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8932 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8933 + AuDbgDentry(dentry);
8939 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8940 + struct dentry *dentry, aufs_bindex_t bindex)
8945 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8948 + AuDbg("b%d\n", bindex);
8950 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8951 + * due to whiteout and branch permission.
8953 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8954 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8955 + /* it may return tri-state */
8956 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8958 + if (unlikely(valid < 0))
8968 +/* todo: remove this */
8969 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8970 + unsigned int flags, int do_udba, int dirren)
8973 + umode_t mode, h_mode;
8974 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8975 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8976 + struct inode *h_inode, *h_cached_inode;
8977 + struct dentry *h_dentry;
8978 + struct qstr *name, *h_name;
8985 + unhashed = !!d_unhashed(dentry);
8986 + is_root = !!IS_ROOT(dentry);
8987 + name = &dentry->d_name;
8988 + tmpfile = au_di(dentry)->di_tmpfile;
8991 + * Theoretically, REVAL test should be unnecessary in case of
8993 + * But {fs,i}notify doesn't fire some necessary events,
8994 + * IN_ATTRIB for atime/nlink/pageio
8995 + * Let's do REVAL test too.
8997 + if (do_udba && inode) {
8998 + mode = (inode->i_mode & S_IFMT);
8999 + plus = (inode->i_nlink > 0);
9000 + ibs = au_ibtop(inode);
9001 + ibe = au_ibbot(inode);
9004 + btop = au_dbtop(dentry);
9006 + if (inode && S_ISDIR(inode->i_mode))
9007 + btail = au_dbtaildir(dentry);
9008 + for (bindex = btop; bindex <= btail; bindex++) {
9009 + h_dentry = au_h_dptr(dentry, bindex);
9013 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9014 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9015 + spin_lock(&h_dentry->d_lock);
9016 + h_name = &h_dentry->d_name;
9017 + if (unlikely(do_udba
9020 + && (unhashed != !!d_unhashed(h_dentry)
9021 + || (!tmpfile && !dirren
9022 + && !au_qstreq(name, h_name))
9025 + && !(flags & LOOKUP_OPEN)
9026 + && (h_dentry->d_flags
9027 + & DCACHE_NFSFS_RENAMED)))
9031 + h_unhashed = d_unhashed(h_dentry);
9032 + spin_unlock(&h_dentry->d_lock);
9033 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9034 + unhashed, h_unhashed, dentry, h_dentry);
9037 + spin_unlock(&h_dentry->d_lock);
9039 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9040 + if (unlikely(err))
9041 + /* do not goto err, to keep the errno */
9044 + /* todo: plink too? */
9049 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9053 + if (d_is_positive(h_dentry))
9054 + h_inode = d_inode(h_dentry);
9057 + h_cached_inode = h_inode;
9059 + h_mode = (h_inode->i_mode & S_IFMT);
9060 + h_plus = (h_inode->i_nlink > 0);
9062 + if (inode && ibs <= bindex && bindex <= ibe)
9063 + h_cached_inode = au_h_iptr(inode, bindex);
9066 + if (unlikely(plus != h_plus && !tmpfile))
9069 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9071 + && !IS_ROOT(h_dentry)
9072 + && unhashed != d_unhashed(h_dentry)))
9075 + if (unlikely(mode != h_mode
9076 + || h_cached_inode != h_inode))
9089 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9090 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9093 + struct dentry *parent;
9095 + if (!au_digen_test(dentry, sigen))
9098 + parent = dget_parent(dentry);
9099 + di_read_lock_parent(parent, AuLock_IR);
9100 + AuDebugOn(au_digen_test(parent, sigen));
9101 + au_dbg_verify_gen(parent, sigen);
9102 + err = au_refresh_dentry(dentry, parent);
9103 + di_read_unlock(parent, AuLock_IR);
9109 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9112 + struct dentry *d, *parent;
9114 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9115 + return simple_reval_dpath(dentry, sigen);
9117 + /* slow loop, keep it simple and stupid */
9118 + /* cf: au_cpup_dirs() */
9121 + while (au_digen_test(dentry, sigen)) {
9125 + parent = dget_parent(d);
9126 + if (!au_digen_test(parent, sigen))
9132 + di_write_lock_child2(d);
9134 + /* someone might update our dentry while we were sleeping */
9135 + if (au_digen_test(d, sigen)) {
9137 + * todo: consolidate with simple_reval_dpath(),
9138 + * do_refresh() and au_reval_for_attr().
9140 + di_read_lock_parent(parent, AuLock_IR);
9141 + err = au_refresh_dentry(d, parent);
9142 + di_read_unlock(parent, AuLock_IR);
9146 + di_write_unlock(d);
9148 + if (unlikely(err))
9156 + * if valid returns 1, otherwise 0.
9158 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9161 + unsigned int sigen;
9162 + unsigned char do_udba, dirren;
9163 + struct super_block *sb;
9164 + struct inode *inode;
9166 + /* todo: support rcu-walk? */
9167 + if (flags & LOOKUP_RCU)
9171 + if (unlikely(!au_di(dentry)))
9175 + sb = dentry->d_sb;
9178 + * i_mutex of parent dir may be held,
9179 + * but we should not return 'invalid' due to busy.
9181 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9182 + if (unlikely(err)) {
9188 + if (d_really_is_positive(dentry))
9189 + inode = d_inode(dentry);
9190 + if (unlikely(inode && au_is_bad_inode(inode))) {
9195 + if (unlikely(au_dbrange_test(dentry))) {
9201 + sigen = au_sigen(sb);
9202 + if (au_digen_test(dentry, sigen)) {
9203 + AuDebugOn(IS_ROOT(dentry));
9204 + err = au_reval_dpath(dentry, sigen);
9205 + if (unlikely(err)) {
9210 + di_downgrade_lock(dentry, AuLock_IR);
9213 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9215 + && !(inode->i_state && I_LINKABLE)
9216 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9221 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9222 + if (do_udba && inode) {
9223 + aufs_bindex_t btop = au_ibtop(inode);
9224 + struct inode *h_inode;
9227 + h_inode = au_h_iptr(inode, btop);
9228 + if (h_inode && au_test_higen(inode, h_inode)) {
9235 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9236 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9237 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9239 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9245 + di_downgrade_lock(dentry, AuLock_IR);
9247 + aufs_read_unlock(dentry, AuLock_IR);
9252 + AuDbg("%pd invalid, %d\n", dentry, valid);
9258 +static void aufs_d_release(struct dentry *dentry)
9260 + if (au_di(dentry)) {
9261 + au_di_fin(dentry);
9262 + au_hn_di_reinit(dentry);
9266 +const struct dentry_operations aufs_dop = {
9267 + .d_revalidate = aufs_d_revalidate,
9268 + .d_weak_revalidate = aufs_d_revalidate,
9269 + .d_release = aufs_d_release
9272 +/* aufs_dop without d_revalidate */
9273 +const struct dentry_operations aufs_dop_noreval = {
9274 + .d_release = aufs_d_release
9276 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9277 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9278 +++ linux/fs/aufs/dentry.h 2019-07-11 15:42:14.462237786 +0200
9280 +/* SPDX-License-Identifier: GPL-2.0 */
9282 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9284 + * This program, aufs is free software; you can redistribute it and/or modify
9285 + * it under the terms of the GNU General Public License as published by
9286 + * the Free Software Foundation; either version 2 of the License, or
9287 + * (at your option) any later version.
9289 + * This program is distributed in the hope that it will be useful,
9290 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9291 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9292 + * GNU General Public License for more details.
9294 + * You should have received a copy of the GNU General Public License
9295 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9299 + * lookup and dentry operations
9302 +#ifndef __AUFS_DENTRY_H__
9303 +#define __AUFS_DENTRY_H__
9307 +#include <linux/dcache.h>
9308 +#include "dirren.h"
9311 +struct au_hdentry {
9312 + struct dentry *hd_dentry;
9313 + aufs_bindex_t hd_id;
9317 + atomic_t di_generation;
9319 + struct au_rwsem di_rwsem;
9320 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9321 + unsigned char di_tmpfile; /* to allow the different name */
9322 + struct au_hdentry *di_hdentry;
9323 + struct rcu_head rcu;
9324 +} ____cacheline_aligned_in_smp;
9326 +/* ---------------------------------------------------------------------- */
9328 +/* flags for au_lkup_dentry() */
9329 +#define AuLkup_ALLOW_NEG 1
9330 +#define AuLkup_IGNORE_PERM (1 << 1)
9331 +#define AuLkup_DIRREN (1 << 2)
9332 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9333 +#define au_fset_lkup(flags, name) \
9334 + do { (flags) |= AuLkup_##name; } while (0)
9335 +#define au_fclr_lkup(flags, name) \
9336 + do { (flags) &= ~AuLkup_##name; } while (0)
9338 +#ifndef CONFIG_AUFS_DIRREN
9339 +#undef AuLkup_DIRREN
9340 +#define AuLkup_DIRREN 0
9343 +struct au_do_lookup_args {
9344 + unsigned int flags;
9346 + struct qstr whname, *name;
9347 + struct au_dr_lookup dirren;
9350 +/* ---------------------------------------------------------------------- */
9353 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9355 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9356 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9357 + struct dentry *h_parent, struct au_branch *br);
9359 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9360 + unsigned int flags);
9361 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9362 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9363 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9364 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9367 +void au_di_init_once(void *_di);
9368 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9369 +void au_di_free(struct au_dinfo *dinfo);
9370 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9371 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9372 +int au_di_init(struct dentry *dentry);
9373 +void au_di_fin(struct dentry *dentry);
9374 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9376 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9377 +void di_read_unlock(struct dentry *d, int flags);
9378 +void di_downgrade_lock(struct dentry *d, int flags);
9379 +void di_write_lock(struct dentry *d, unsigned int lsc);
9380 +void di_write_unlock(struct dentry *d);
9381 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9382 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9383 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9385 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9386 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9387 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9388 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9390 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9391 + struct dentry *h_dentry);
9392 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9393 +int au_dbrange_test(struct dentry *dentry);
9394 +void au_update_digen(struct dentry *dentry);
9395 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9396 +void au_update_dbtop(struct dentry *dentry);
9397 +void au_update_dbbot(struct dentry *dentry);
9398 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9400 +/* ---------------------------------------------------------------------- */
9402 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9404 + return dentry->d_fsdata;
9407 +/* ---------------------------------------------------------------------- */
9409 +/* lock subclass for dinfo */
9411 + AuLsc_DI_CHILD, /* child first */
9412 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9413 + AuLsc_DI_CHILD3, /* copyup dirs */
9417 + AuLsc_DI_TMP /* temp for replacing dinfo */
9421 + * di_read_lock_child, di_write_lock_child,
9422 + * di_read_lock_child2, di_write_lock_child2,
9423 + * di_read_lock_child3, di_write_lock_child3,
9424 + * di_read_lock_parent, di_write_lock_parent,
9425 + * di_read_lock_parent2, di_write_lock_parent2,
9426 + * di_read_lock_parent3, di_write_lock_parent3,
9428 +#define AuReadLockFunc(name, lsc) \
9429 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9430 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9432 +#define AuWriteLockFunc(name, lsc) \
9433 +static inline void di_write_lock_##name(struct dentry *d) \
9434 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9436 +#define AuRWLockFuncs(name, lsc) \
9437 + AuReadLockFunc(name, lsc) \
9438 + AuWriteLockFunc(name, lsc)
9440 +AuRWLockFuncs(child, CHILD);
9441 +AuRWLockFuncs(child2, CHILD2);
9442 +AuRWLockFuncs(child3, CHILD3);
9443 +AuRWLockFuncs(parent, PARENT);
9444 +AuRWLockFuncs(parent2, PARENT2);
9445 +AuRWLockFuncs(parent3, PARENT3);
9447 +#undef AuReadLockFunc
9448 +#undef AuWriteLockFunc
9449 +#undef AuRWLockFuncs
9451 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9452 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9453 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9455 +/* ---------------------------------------------------------------------- */
9457 +/* todo: memory barrier? */
9458 +static inline unsigned int au_digen(struct dentry *d)
9460 + return atomic_read(&au_di(d)->di_generation);
9463 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9465 + hdentry->hd_dentry = NULL;
9468 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9469 + aufs_bindex_t bindex)
9471 + return di->di_hdentry + bindex;
9474 +static inline void au_hdput(struct au_hdentry *hd)
9477 + dput(hd->hd_dentry);
9480 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9482 + DiMustAnyLock(dentry);
9483 + return au_di(dentry)->di_btop;
9486 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9488 + DiMustAnyLock(dentry);
9489 + return au_di(dentry)->di_bbot;
9492 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9494 + DiMustAnyLock(dentry);
9495 + return au_di(dentry)->di_bwh;
9498 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9500 + DiMustAnyLock(dentry);
9501 + return au_di(dentry)->di_bdiropq;
9504 +/* todo: hard/soft set? */
9505 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9507 + DiMustWriteLock(dentry);
9508 + au_di(dentry)->di_btop = bindex;
9511 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9513 + DiMustWriteLock(dentry);
9514 + au_di(dentry)->di_bbot = bindex;
9517 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9519 + DiMustWriteLock(dentry);
9520 + /* dbwh can be outside of btop - bbot range */
9521 + au_di(dentry)->di_bwh = bindex;
9524 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9526 + DiMustWriteLock(dentry);
9527 + au_di(dentry)->di_bdiropq = bindex;
9530 +/* ---------------------------------------------------------------------- */
9532 +#ifdef CONFIG_AUFS_HNOTIFY
9533 +static inline void au_digen_dec(struct dentry *d)
9535 + atomic_dec(&au_di(d)->di_generation);
9538 +static inline void au_hn_di_reinit(struct dentry *dentry)
9540 + dentry->d_fsdata = NULL;
9543 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9544 +#endif /* CONFIG_AUFS_HNOTIFY */
9546 +#endif /* __KERNEL__ */
9547 +#endif /* __AUFS_DENTRY_H__ */
9548 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9549 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9550 +++ linux/fs/aufs/dinfo.c 2019-07-11 15:42:14.462237786 +0200
9552 +// SPDX-License-Identifier: GPL-2.0
9554 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9556 + * This program, aufs is free software; you can redistribute it and/or modify
9557 + * it under the terms of the GNU General Public License as published by
9558 + * the Free Software Foundation; either version 2 of the License, or
9559 + * (at your option) any later version.
9561 + * This program is distributed in the hope that it will be useful,
9562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9564 + * GNU General Public License for more details.
9566 + * You should have received a copy of the GNU General Public License
9567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9571 + * dentry private data
9576 +void au_di_init_once(void *_dinfo)
9578 + struct au_dinfo *dinfo = _dinfo;
9580 + au_rw_init(&dinfo->di_rwsem);
9583 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9585 + struct au_dinfo *dinfo;
9588 + dinfo = au_cache_alloc_dinfo();
9589 + if (unlikely(!dinfo))
9592 + nbr = au_sbbot(sb) + 1;
9595 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9596 + if (dinfo->di_hdentry) {
9597 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9598 + dinfo->di_btop = -1;
9599 + dinfo->di_bbot = -1;
9600 + dinfo->di_bwh = -1;
9601 + dinfo->di_bdiropq = -1;
9602 + dinfo->di_tmpfile = 0;
9603 + for (i = 0; i < nbr; i++)
9604 + dinfo->di_hdentry[i].hd_id = -1;
9608 + au_cache_free_dinfo(dinfo);
9615 +void au_di_free(struct au_dinfo *dinfo)
9617 + struct au_hdentry *p;
9618 + aufs_bindex_t bbot, bindex;
9620 + /* dentry may not be revalidated */
9621 + bindex = dinfo->di_btop;
9622 + if (bindex >= 0) {
9623 + bbot = dinfo->di_bbot;
9624 + p = au_hdentry(dinfo, bindex);
9625 + while (bindex++ <= bbot)
9628 + au_kfree_try_rcu(dinfo->di_hdentry);
9629 + au_cache_free_dinfo(dinfo);
9632 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9634 + struct au_hdentry *p;
9637 + AuRwMustWriteLock(&a->di_rwsem);
9638 + AuRwMustWriteLock(&b->di_rwsem);
9640 +#define DiSwap(v, name) \
9642 + v = a->di_##name; \
9643 + a->di_##name = b->di_##name; \
9644 + b->di_##name = v; \
9647 + DiSwap(p, hdentry);
9651 + DiSwap(bi, bdiropq);
9657 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9659 + AuRwMustWriteLock(&dst->di_rwsem);
9660 + AuRwMustWriteLock(&src->di_rwsem);
9662 + dst->di_btop = src->di_btop;
9663 + dst->di_bbot = src->di_bbot;
9664 + dst->di_bwh = src->di_bwh;
9665 + dst->di_bdiropq = src->di_bdiropq;
9669 +int au_di_init(struct dentry *dentry)
9672 + struct super_block *sb;
9673 + struct au_dinfo *dinfo;
9676 + sb = dentry->d_sb;
9677 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9679 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9680 + /* smp_mb(); */ /* atomic_set */
9681 + dentry->d_fsdata = dinfo;
9688 +void au_di_fin(struct dentry *dentry)
9690 + struct au_dinfo *dinfo;
9692 + dinfo = au_di(dentry);
9693 + AuRwDestroy(&dinfo->di_rwsem);
9694 + au_di_free(dinfo);
9697 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9700 + struct au_hdentry *hdp;
9702 + AuRwMustWriteLock(&dinfo->di_rwsem);
9705 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9707 + sz = sizeof(*hdp);
9708 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9711 + dinfo->di_hdentry = hdp;
9718 +/* ---------------------------------------------------------------------- */
9720 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9723 + case AuLsc_DI_CHILD:
9724 + ii_write_lock_child(inode);
9726 + case AuLsc_DI_CHILD2:
9727 + ii_write_lock_child2(inode);
9729 + case AuLsc_DI_CHILD3:
9730 + ii_write_lock_child3(inode);
9732 + case AuLsc_DI_PARENT:
9733 + ii_write_lock_parent(inode);
9735 + case AuLsc_DI_PARENT2:
9736 + ii_write_lock_parent2(inode);
9738 + case AuLsc_DI_PARENT3:
9739 + ii_write_lock_parent3(inode);
9746 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9749 + case AuLsc_DI_CHILD:
9750 + ii_read_lock_child(inode);
9752 + case AuLsc_DI_CHILD2:
9753 + ii_read_lock_child2(inode);
9755 + case AuLsc_DI_CHILD3:
9756 + ii_read_lock_child3(inode);
9758 + case AuLsc_DI_PARENT:
9759 + ii_read_lock_parent(inode);
9761 + case AuLsc_DI_PARENT2:
9762 + ii_read_lock_parent2(inode);
9764 + case AuLsc_DI_PARENT3:
9765 + ii_read_lock_parent3(inode);
9772 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9774 + struct inode *inode;
9776 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9777 + if (d_really_is_positive(d)) {
9778 + inode = d_inode(d);
9779 + if (au_ftest_lock(flags, IW))
9780 + do_ii_write_lock(inode, lsc);
9781 + else if (au_ftest_lock(flags, IR))
9782 + do_ii_read_lock(inode, lsc);
9786 +void di_read_unlock(struct dentry *d, int flags)
9788 + struct inode *inode;
9790 + if (d_really_is_positive(d)) {
9791 + inode = d_inode(d);
9792 + if (au_ftest_lock(flags, IW)) {
9793 + au_dbg_verify_dinode(d);
9794 + ii_write_unlock(inode);
9795 + } else if (au_ftest_lock(flags, IR)) {
9796 + au_dbg_verify_dinode(d);
9797 + ii_read_unlock(inode);
9800 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9803 +void di_downgrade_lock(struct dentry *d, int flags)
9805 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9806 + ii_downgrade_lock(d_inode(d));
9807 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9810 +void di_write_lock(struct dentry *d, unsigned int lsc)
9812 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9813 + if (d_really_is_positive(d))
9814 + do_ii_write_lock(d_inode(d), lsc);
9817 +void di_write_unlock(struct dentry *d)
9819 + au_dbg_verify_dinode(d);
9820 + if (d_really_is_positive(d))
9821 + ii_write_unlock(d_inode(d));
9822 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9825 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9827 + AuDebugOn(d1 == d2
9828 + || d_inode(d1) == d_inode(d2)
9829 + || d1->d_sb != d2->d_sb);
9831 + if ((isdir && au_test_subdir(d1, d2))
9833 + di_write_lock_child(d1);
9834 + di_write_lock_child2(d2);
9836 + di_write_lock_child(d2);
9837 + di_write_lock_child2(d1);
9841 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9843 + AuDebugOn(d1 == d2
9844 + || d_inode(d1) == d_inode(d2)
9845 + || d1->d_sb != d2->d_sb);
9847 + if ((isdir && au_test_subdir(d1, d2))
9849 + di_write_lock_parent(d1);
9850 + di_write_lock_parent2(d2);
9852 + di_write_lock_parent(d2);
9853 + di_write_lock_parent2(d1);
9857 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9859 + di_write_unlock(d1);
9860 + if (d_inode(d1) == d_inode(d2))
9861 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9863 + di_write_unlock(d2);
9866 +/* ---------------------------------------------------------------------- */
9868 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9872 + DiMustAnyLock(dentry);
9874 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9876 + AuDebugOn(bindex < 0);
9877 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9878 + AuDebugOn(d && au_dcount(d) <= 0);
9883 + * extended version of au_h_dptr().
9884 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9887 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9889 + struct dentry *h_dentry;
9890 + struct inode *inode, *h_inode;
9892 + AuDebugOn(d_really_is_negative(dentry));
9895 + if (au_dbtop(dentry) <= bindex
9896 + && bindex <= au_dbbot(dentry))
9897 + h_dentry = au_h_dptr(dentry, bindex);
9898 + if (h_dentry && !au_d_linkable(h_dentry)) {
9900 + goto out; /* success */
9903 + inode = d_inode(dentry);
9904 + AuDebugOn(bindex < au_ibtop(inode));
9905 + AuDebugOn(au_ibbot(inode) < bindex);
9906 + h_inode = au_h_iptr(inode, bindex);
9907 + h_dentry = d_find_alias(h_inode);
9909 + if (!IS_ERR(h_dentry)) {
9910 + if (!au_d_linkable(h_dentry))
9911 + goto out; /* success */
9917 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9918 + h_dentry = au_plink_lkup(inode, bindex);
9919 + AuDebugOn(!h_dentry);
9920 + if (!IS_ERR(h_dentry)) {
9921 + if (!au_d_hashed_positive(h_dentry))
9922 + goto out; /* success */
9929 + AuDbgDentry(h_dentry);
9933 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9935 + aufs_bindex_t bbot, bwh;
9937 + bbot = au_dbbot(dentry);
9939 + bwh = au_dbwh(dentry);
9942 + if (0 < bwh && bwh < bbot)
9948 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9950 + aufs_bindex_t bbot, bopq;
9952 + bbot = au_dbtail(dentry);
9954 + bopq = au_dbdiropq(dentry);
9955 + if (0 <= bopq && bopq < bbot)
9961 +/* ---------------------------------------------------------------------- */
9963 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9964 + struct dentry *h_dentry)
9966 + struct au_dinfo *dinfo;
9967 + struct au_hdentry *hd;
9968 + struct au_branch *br;
9970 + DiMustWriteLock(dentry);
9972 + dinfo = au_di(dentry);
9973 + hd = au_hdentry(dinfo, bindex);
9975 + hd->hd_dentry = h_dentry;
9977 + br = au_sbr(dentry->d_sb, bindex);
9978 + hd->hd_id = br->br_id;
9982 +int au_dbrange_test(struct dentry *dentry)
9985 + aufs_bindex_t btop, bbot;
9988 + btop = au_dbtop(dentry);
9989 + bbot = au_dbbot(dentry);
9991 + AuDebugOn(bbot < 0 && btop > bbot);
9994 + AuDebugOn(bbot >= 0);
10000 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10005 + if (unlikely(au_digen(dentry) != sigen
10006 + || au_iigen_test(d_inode(dentry), sigen)))
10012 +void au_update_digen(struct dentry *dentry)
10014 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10015 + /* smp_mb(); */ /* atomic_set */
10018 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10020 + struct au_dinfo *dinfo;
10021 + struct dentry *h_d;
10022 + struct au_hdentry *hdp;
10023 + aufs_bindex_t bindex, bbot;
10025 + DiMustWriteLock(dentry);
10027 + dinfo = au_di(dentry);
10028 + if (!dinfo || dinfo->di_btop < 0)
10031 + if (do_put_zero) {
10032 + bbot = dinfo->di_bbot;
10033 + bindex = dinfo->di_btop;
10034 + hdp = au_hdentry(dinfo, bindex);
10035 + for (; bindex <= bbot; bindex++, hdp++) {
10036 + h_d = hdp->hd_dentry;
10037 + if (h_d && d_is_negative(h_d))
10038 + au_set_h_dptr(dentry, bindex, NULL);
10042 + dinfo->di_btop = 0;
10043 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10044 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10045 + if (hdp->hd_dentry)
10047 + if (dinfo->di_btop > dinfo->di_bbot) {
10048 + dinfo->di_btop = -1;
10049 + dinfo->di_bbot = -1;
10053 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10054 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10055 + if (hdp->hd_dentry)
10057 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10060 +void au_update_dbtop(struct dentry *dentry)
10062 + aufs_bindex_t bindex, bbot;
10063 + struct dentry *h_dentry;
10065 + bbot = au_dbbot(dentry);
10066 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10067 + h_dentry = au_h_dptr(dentry, bindex);
10070 + if (d_is_positive(h_dentry)) {
10071 + au_set_dbtop(dentry, bindex);
10074 + au_set_h_dptr(dentry, bindex, NULL);
10078 +void au_update_dbbot(struct dentry *dentry)
10080 + aufs_bindex_t bindex, btop;
10081 + struct dentry *h_dentry;
10083 + btop = au_dbtop(dentry);
10084 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10085 + h_dentry = au_h_dptr(dentry, bindex);
10088 + if (d_is_positive(h_dentry)) {
10089 + au_set_dbbot(dentry, bindex);
10092 + au_set_h_dptr(dentry, bindex, NULL);
10096 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10098 + aufs_bindex_t bindex, bbot;
10100 + bbot = au_dbbot(dentry);
10101 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10102 + if (au_h_dptr(dentry, bindex) == h_dentry)
10106 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10107 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10108 +++ linux/fs/aufs/dir.c 2019-07-11 15:42:14.462237786 +0200
10110 +// SPDX-License-Identifier: GPL-2.0
10112 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10114 + * This program, aufs is free software; you can redistribute it and/or modify
10115 + * it under the terms of the GNU General Public License as published by
10116 + * the Free Software Foundation; either version 2 of the License, or
10117 + * (at your option) any later version.
10119 + * This program is distributed in the hope that it will be useful,
10120 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10121 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10122 + * GNU General Public License for more details.
10124 + * You should have received a copy of the GNU General Public License
10125 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10129 + * directory operations
10132 +#include <linux/fs_stack.h>
10133 +#include <linux/iversion.h>
10136 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10138 + unsigned int nlink;
10140 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10142 + nlink = dir->i_nlink;
10143 + nlink += h_dir->i_nlink - 2;
10144 + if (h_dir->i_nlink < 2)
10146 + smp_mb(); /* for i_nlink */
10147 + /* 0 can happen in revaliding */
10148 + set_nlink(dir, nlink);
10151 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10153 + unsigned int nlink;
10155 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10157 + nlink = dir->i_nlink;
10158 + nlink -= h_dir->i_nlink - 2;
10159 + if (h_dir->i_nlink < 2)
10161 + smp_mb(); /* for i_nlink */
10162 + /* nlink == 0 means the branch-fs is broken */
10163 + set_nlink(dir, nlink);
10166 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10169 + aufs_bindex_t bindex, bbot;
10170 + struct file *h_file;
10171 + struct dentry *h_dentry;
10175 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10177 + bbot = au_fbbot_dir(file);
10178 + for (bindex = au_fbtop(file);
10179 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10181 + h_file = au_hf_dir(file, bindex);
10182 + if (h_file && file_inode(h_file))
10183 + sz += vfsub_f_size_read(h_file);
10186 + AuDebugOn(!dentry);
10187 + AuDebugOn(!d_is_dir(dentry));
10189 + bbot = au_dbtaildir(dentry);
10190 + for (bindex = au_dbtop(dentry);
10191 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10193 + h_dentry = au_h_dptr(dentry, bindex);
10194 + if (h_dentry && d_is_positive(h_dentry))
10195 + sz += i_size_read(d_inode(h_dentry));
10198 + if (sz < KMALLOC_MAX_SIZE)
10199 + sz = roundup_pow_of_two(sz);
10200 + if (sz > KMALLOC_MAX_SIZE)
10201 + sz = KMALLOC_MAX_SIZE;
10202 + else if (sz < NAME_MAX) {
10203 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10204 + sz = AUFS_RDBLK_DEF;
10209 +struct au_dir_ts_arg {
10210 + struct dentry *dentry;
10211 + aufs_bindex_t brid;
10214 +static void au_do_dir_ts(void *arg)
10216 + struct au_dir_ts_arg *a = arg;
10217 + struct au_dtime dt;
10218 + struct path h_path;
10219 + struct inode *dir, *h_dir;
10220 + struct super_block *sb;
10221 + struct au_branch *br;
10222 + struct au_hinode *hdir;
10224 + aufs_bindex_t btop, bindex;
10226 + sb = a->dentry->d_sb;
10227 + if (d_really_is_negative(a->dentry))
10229 + /* no dir->i_mutex lock */
10230 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10232 + dir = d_inode(a->dentry);
10233 + btop = au_ibtop(dir);
10234 + bindex = au_br_index(sb, a->brid);
10235 + if (bindex < btop)
10238 + br = au_sbr(sb, bindex);
10239 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10240 + if (!h_path.dentry)
10242 + h_path.mnt = au_br_mnt(br);
10243 + au_dtime_store(&dt, a->dentry, &h_path);
10245 + br = au_sbr(sb, btop);
10246 + if (!au_br_writable(br->br_perm))
10248 + h_path.dentry = au_h_dptr(a->dentry, btop);
10249 + h_path.mnt = au_br_mnt(br);
10250 + err = vfsub_mnt_want_write(h_path.mnt);
10253 + hdir = au_hi(dir, btop);
10254 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10255 + h_dir = au_h_iptr(dir, btop);
10256 + if (h_dir->i_nlink
10257 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10258 + dt.dt_h_path = h_path;
10259 + au_dtime_revert(&dt);
10261 + au_hn_inode_unlock(hdir);
10262 + vfsub_mnt_drop_write(h_path.mnt);
10263 + au_cpup_attr_timesizes(dir);
10266 + aufs_read_unlock(a->dentry, AuLock_DW);
10269 + au_nwt_done(&au_sbi(sb)->si_nowait);
10270 + au_kfree_try_rcu(arg);
10273 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10275 + int perm, wkq_err;
10276 + aufs_bindex_t btop;
10277 + struct au_dir_ts_arg *arg;
10278 + struct dentry *dentry;
10279 + struct super_block *sb;
10283 + dentry = d_find_any_alias(dir);
10284 + AuDebugOn(!dentry);
10285 + sb = dentry->d_sb;
10286 + btop = au_ibtop(dir);
10287 + if (btop == bindex) {
10288 + au_cpup_attr_timesizes(dir);
10292 + perm = au_sbr_perm(sb, btop);
10293 + if (!au_br_writable(perm))
10296 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10300 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10301 + arg->brid = au_sbr_id(sb, bindex);
10302 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10303 + if (unlikely(wkq_err)) {
10304 + pr_err("wkq %d\n", wkq_err);
10306 + au_kfree_try_rcu(arg);
10313 +/* ---------------------------------------------------------------------- */
10315 +static int reopen_dir(struct file *file)
10318 + unsigned int flags;
10319 + aufs_bindex_t bindex, btail, btop;
10320 + struct dentry *dentry, *h_dentry;
10321 + struct file *h_file;
10323 + /* open all lower dirs */
10324 + dentry = file->f_path.dentry;
10325 + btop = au_dbtop(dentry);
10326 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10327 + au_set_h_fptr(file, bindex, NULL);
10328 + au_set_fbtop(file, btop);
10330 + btail = au_dbtaildir(dentry);
10331 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10332 + au_set_h_fptr(file, bindex, NULL);
10333 + au_set_fbbot_dir(file, btail);
10335 + flags = vfsub_file_flags(file);
10336 + for (bindex = btop; bindex <= btail; bindex++) {
10337 + h_dentry = au_h_dptr(dentry, bindex);
10340 + h_file = au_hf_dir(file, bindex);
10344 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10345 + err = PTR_ERR(h_file);
10346 + if (IS_ERR(h_file))
10347 + goto out; /* close all? */
10348 + au_set_h_fptr(file, bindex, h_file);
10350 + au_update_figen(file);
10351 + /* todo: necessary? */
10352 + /* file->f_ra = h_file->f_ra; */
10359 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10362 + aufs_bindex_t bindex, btail;
10363 + struct dentry *dentry, *h_dentry;
10364 + struct vfsmount *mnt;
10366 + FiMustWriteLock(file);
10367 + AuDebugOn(h_file);
10370 + mnt = file->f_path.mnt;
10371 + dentry = file->f_path.dentry;
10372 + file->f_version = inode_query_iversion(d_inode(dentry));
10373 + bindex = au_dbtop(dentry);
10374 + au_set_fbtop(file, bindex);
10375 + btail = au_dbtaildir(dentry);
10376 + au_set_fbbot_dir(file, btail);
10377 + for (; !err && bindex <= btail; bindex++) {
10378 + h_dentry = au_h_dptr(dentry, bindex);
10382 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10383 + if (unlikely(err))
10385 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10386 + if (IS_ERR(h_file)) {
10387 + err = PTR_ERR(h_file);
10390 + au_set_h_fptr(file, bindex, h_file);
10392 + au_update_figen(file);
10393 + /* todo: necessary? */
10394 + /* file->f_ra = h_file->f_ra; */
10396 + return 0; /* success */
10399 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10400 + au_set_h_fptr(file, bindex, NULL);
10401 + au_set_fbtop(file, -1);
10402 + au_set_fbbot_dir(file, -1);
10407 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10408 + struct file *file)
10411 + struct super_block *sb;
10412 + struct au_fidir *fidir;
10415 + sb = file->f_path.dentry->d_sb;
10416 + si_read_lock(sb, AuLock_FLUSH);
10417 + fidir = au_fidir_alloc(sb);
10419 + struct au_do_open_args args = {
10420 + .open = do_open_dir,
10423 + err = au_do_open(file, &args);
10424 + if (unlikely(err))
10425 + au_kfree_rcu(fidir);
10427 + si_read_unlock(sb);
10431 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10432 + struct file *file)
10434 + struct au_vdir *vdir_cache;
10435 + struct au_finfo *finfo;
10436 + struct au_fidir *fidir;
10437 + struct au_hfile *hf;
10438 + aufs_bindex_t bindex, bbot;
10440 + finfo = au_fi(file);
10441 + fidir = finfo->fi_hdir;
10443 + au_hbl_del(&finfo->fi_hlist,
10444 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10445 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10447 + au_vdir_free(vdir_cache);
10449 + bindex = finfo->fi_btop;
10450 + if (bindex >= 0) {
10451 + hf = fidir->fd_hfile + bindex;
10453 + * calls fput() instead of filp_close(),
10454 + * since no dnotify or lock for the lower file.
10456 + bbot = fidir->fd_bbot;
10457 + for (; bindex <= bbot; bindex++, hf++)
10459 + au_hfput(hf, /*execed*/0);
10461 + au_kfree_rcu(fidir);
10462 + finfo->fi_hdir = NULL;
10464 + au_finfo_fin(file);
10468 +/* ---------------------------------------------------------------------- */
10470 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10473 + aufs_bindex_t bindex, bbot;
10474 + struct file *h_file;
10477 + bbot = au_fbbot_dir(file);
10478 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10479 + h_file = au_hf_dir(file, bindex);
10481 + err = vfsub_flush(h_file, id);
10486 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10488 + return au_do_flush(file, id, au_do_flush_dir);
10491 +/* ---------------------------------------------------------------------- */
10493 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10496 + aufs_bindex_t bbot, bindex;
10497 + struct inode *inode;
10498 + struct super_block *sb;
10501 + sb = dentry->d_sb;
10502 + inode = d_inode(dentry);
10503 + IMustLock(inode);
10504 + bbot = au_dbbot(dentry);
10505 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10506 + struct path h_path;
10508 + if (au_test_ro(sb, bindex, inode))
10510 + h_path.dentry = au_h_dptr(dentry, bindex);
10511 + if (!h_path.dentry)
10514 + h_path.mnt = au_sbr_mnt(sb, bindex);
10515 + err = vfsub_fsync(NULL, &h_path, datasync);
10521 +static int au_do_fsync_dir(struct file *file, int datasync)
10524 + aufs_bindex_t bbot, bindex;
10525 + struct file *h_file;
10526 + struct super_block *sb;
10527 + struct inode *inode;
10529 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10530 + if (unlikely(err))
10533 + inode = file_inode(file);
10534 + sb = inode->i_sb;
10535 + bbot = au_fbbot_dir(file);
10536 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10537 + h_file = au_hf_dir(file, bindex);
10538 + if (!h_file || au_test_ro(sb, bindex, inode))
10541 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10549 + * @file may be NULL
10551 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10555 + struct dentry *dentry;
10556 + struct inode *inode;
10557 + struct super_block *sb;
10560 + dentry = file->f_path.dentry;
10561 + inode = d_inode(dentry);
10562 + inode_lock(inode);
10563 + sb = dentry->d_sb;
10564 + si_noflush_read_lock(sb);
10566 + err = au_do_fsync_dir(file, datasync);
10568 + di_write_lock_child(dentry);
10569 + err = au_do_fsync_dir_no_file(dentry, datasync);
10571 + au_cpup_attr_timesizes(inode);
10572 + di_write_unlock(dentry);
10574 + fi_write_unlock(file);
10576 + si_read_unlock(sb);
10577 + inode_unlock(inode);
10581 +/* ---------------------------------------------------------------------- */
10583 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10586 + struct dentry *dentry;
10587 + struct inode *inode, *h_inode;
10588 + struct super_block *sb;
10590 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10592 + dentry = file->f_path.dentry;
10593 + inode = d_inode(dentry);
10594 + IMustLock(inode);
10596 + sb = dentry->d_sb;
10597 + si_read_lock(sb, AuLock_FLUSH);
10598 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10599 + if (unlikely(err))
10601 + err = au_alive_dir(dentry);
10603 + err = au_vdir_init(file);
10604 + di_downgrade_lock(dentry, AuLock_IR);
10605 + if (unlikely(err))
10608 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10609 + if (!au_test_nfsd()) {
10610 + err = au_vdir_fill_de(file, ctx);
10611 + fsstack_copy_attr_atime(inode, h_inode);
10614 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10615 + * encode_fh() and others.
10617 + atomic_inc(&h_inode->i_count);
10618 + di_read_unlock(dentry, AuLock_IR);
10619 + si_read_unlock(sb);
10620 + err = au_vdir_fill_de(file, ctx);
10621 + fsstack_copy_attr_atime(inode, h_inode);
10622 + fi_write_unlock(file);
10630 + di_read_unlock(dentry, AuLock_IR);
10631 + fi_write_unlock(file);
10633 + si_read_unlock(sb);
10637 +/* ---------------------------------------------------------------------- */
10639 +#define AuTestEmpty_WHONLY 1
10640 +#define AuTestEmpty_CALLED (1 << 1)
10641 +#define AuTestEmpty_SHWH (1 << 2)
10642 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10643 +#define au_fset_testempty(flags, name) \
10644 + do { (flags) |= AuTestEmpty_##name; } while (0)
10645 +#define au_fclr_testempty(flags, name) \
10646 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10648 +#ifndef CONFIG_AUFS_SHWH
10649 +#undef AuTestEmpty_SHWH
10650 +#define AuTestEmpty_SHWH 0
10653 +struct test_empty_arg {
10654 + struct dir_context ctx;
10655 + struct au_nhash *whlist;
10656 + unsigned int flags;
10658 + aufs_bindex_t bindex;
10661 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10662 + int namelen, loff_t offset __maybe_unused, u64 ino,
10663 + unsigned int d_type)
10665 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10667 + char *name = (void *)__name;
10670 + au_fset_testempty(arg->flags, CALLED);
10672 + if (name[0] == '.'
10673 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10674 + goto out; /* success */
10676 + if (namelen <= AUFS_WH_PFX_LEN
10677 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10678 + if (au_ftest_testempty(arg->flags, WHONLY)
10679 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10680 + arg->err = -ENOTEMPTY;
10684 + name += AUFS_WH_PFX_LEN;
10685 + namelen -= AUFS_WH_PFX_LEN;
10686 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10687 + arg->err = au_nhash_append_wh
10688 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10689 + au_ftest_testempty(arg->flags, SHWH));
10693 + AuTraceErr(arg->err);
10697 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10700 + struct file *h_file;
10701 + struct au_branch *br;
10703 + h_file = au_h_open(dentry, arg->bindex,
10704 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10705 + /*file*/NULL, /*force_wr*/0);
10706 + err = PTR_ERR(h_file);
10707 + if (IS_ERR(h_file))
10711 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10712 + && !file_inode(h_file)->i_nlink)
10717 + au_fclr_testempty(arg->flags, CALLED);
10719 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10722 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10726 + br = au_sbr(dentry->d_sb, arg->bindex);
10727 + au_lcnt_dec(&br->br_nfiles);
10732 +struct do_test_empty_args {
10734 + struct dentry *dentry;
10735 + struct test_empty_arg *arg;
10738 +static void call_do_test_empty(void *args)
10740 + struct do_test_empty_args *a = args;
10741 + *a->errp = do_test_empty(a->dentry, a->arg);
10744 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10746 + int err, wkq_err;
10747 + struct dentry *h_dentry;
10748 + struct inode *h_inode;
10750 + h_dentry = au_h_dptr(dentry, arg->bindex);
10751 + h_inode = d_inode(h_dentry);
10752 + /* todo: i_mode changes anytime? */
10753 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10754 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10755 + inode_unlock_shared(h_inode);
10757 + err = do_test_empty(dentry, arg);
10759 + struct do_test_empty_args args = {
10761 + .dentry = dentry,
10764 + unsigned int flags = arg->flags;
10766 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10767 + if (unlikely(wkq_err))
10769 + arg->flags = flags;
10775 +int au_test_empty_lower(struct dentry *dentry)
10778 + unsigned int rdhash;
10779 + aufs_bindex_t bindex, btop, btail;
10780 + struct au_nhash whlist;
10781 + struct test_empty_arg arg = {
10783 + .actor = test_empty_cb
10786 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10788 + SiMustAnyLock(dentry->d_sb);
10790 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10792 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10793 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10794 + if (unlikely(err))
10798 + arg.whlist = &whlist;
10799 + btop = au_dbtop(dentry);
10800 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10801 + au_fset_testempty(arg.flags, SHWH);
10802 + test_empty = do_test_empty;
10803 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10804 + test_empty = sio_test_empty;
10805 + arg.bindex = btop;
10806 + err = test_empty(dentry, &arg);
10807 + if (unlikely(err))
10810 + au_fset_testempty(arg.flags, WHONLY);
10811 + btail = au_dbtaildir(dentry);
10812 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10813 + struct dentry *h_dentry;
10815 + h_dentry = au_h_dptr(dentry, bindex);
10816 + if (h_dentry && d_is_positive(h_dentry)) {
10817 + arg.bindex = bindex;
10818 + err = test_empty(dentry, &arg);
10823 + au_nhash_wh_free(&whlist);
10828 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10831 + struct test_empty_arg arg = {
10833 + .actor = test_empty_cb
10836 + aufs_bindex_t bindex, btail;
10839 + arg.whlist = whlist;
10840 + arg.flags = AuTestEmpty_WHONLY;
10841 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10842 + au_fset_testempty(arg.flags, SHWH);
10843 + btail = au_dbtaildir(dentry);
10844 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10845 + struct dentry *h_dentry;
10847 + h_dentry = au_h_dptr(dentry, bindex);
10848 + if (h_dentry && d_is_positive(h_dentry)) {
10849 + arg.bindex = bindex;
10850 + err = sio_test_empty(dentry, &arg);
10857 +/* ---------------------------------------------------------------------- */
10859 +const struct file_operations aufs_dir_fop = {
10860 + .owner = THIS_MODULE,
10861 + .llseek = default_llseek,
10862 + .read = generic_read_dir,
10863 + .iterate_shared = aufs_iterate_shared,
10864 + .unlocked_ioctl = aufs_ioctl_dir,
10865 +#ifdef CONFIG_COMPAT
10866 + .compat_ioctl = aufs_compat_ioctl_dir,
10868 + .open = aufs_open_dir,
10869 + .release = aufs_release_dir,
10870 + .flush = aufs_flush_dir,
10871 + .fsync = aufs_fsync_dir
10873 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10874 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10875 +++ linux/fs/aufs/dir.h 2019-07-11 15:42:14.462237786 +0200
10877 +/* SPDX-License-Identifier: GPL-2.0 */
10879 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10881 + * This program, aufs is free software; you can redistribute it and/or modify
10882 + * it under the terms of the GNU General Public License as published by
10883 + * the Free Software Foundation; either version 2 of the License, or
10884 + * (at your option) any later version.
10886 + * This program is distributed in the hope that it will be useful,
10887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10889 + * GNU General Public License for more details.
10891 + * You should have received a copy of the GNU General Public License
10892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10896 + * directory operations
10899 +#ifndef __AUFS_DIR_H__
10900 +#define __AUFS_DIR_H__
10904 +#include <linux/fs.h>
10906 +/* ---------------------------------------------------------------------- */
10908 +/* need to be faster and smaller */
10911 + unsigned int nh_num;
10912 + struct hlist_head *nh_head;
10915 +struct au_vdir_destr {
10916 + unsigned char len;
10917 + unsigned char name[0];
10920 +struct au_vdir_dehstr {
10921 + struct hlist_node hash;
10922 + struct au_vdir_destr *str;
10923 + struct rcu_head rcu;
10924 +} ____cacheline_aligned_in_smp;
10926 +struct au_vdir_de {
10928 + unsigned char de_type;
10929 + /* caution: packed */
10930 + struct au_vdir_destr de_str;
10933 +struct au_vdir_wh {
10934 + struct hlist_node wh_hash;
10935 +#ifdef CONFIG_AUFS_SHWH
10937 + aufs_bindex_t wh_bindex;
10938 + unsigned char wh_type;
10940 + aufs_bindex_t wh_bindex;
10942 + /* caution: packed */
10943 + struct au_vdir_destr wh_str;
10946 +union au_vdir_deblk_p {
10947 + unsigned char *deblk;
10948 + struct au_vdir_de *de;
10952 + unsigned char **vd_deblk;
10953 + unsigned long vd_nblk;
10955 + unsigned long ul;
10956 + union au_vdir_deblk_p p;
10960 + unsigned int vd_deblk_sz;
10961 + unsigned long vd_jiffy;
10962 + struct rcu_head rcu;
10963 +} ____cacheline_aligned_in_smp;
10965 +/* ---------------------------------------------------------------------- */
10968 +extern const struct file_operations aufs_dir_fop;
10969 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10970 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10971 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10972 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10973 +int au_test_empty_lower(struct dentry *dentry);
10974 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10977 +unsigned int au_rdhash_est(loff_t sz);
10978 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10979 +void au_nhash_wh_free(struct au_nhash *whlist);
10980 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10982 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10983 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10984 + unsigned int d_type, aufs_bindex_t bindex,
10985 + unsigned char shwh);
10986 +void au_vdir_free(struct au_vdir *vdir);
10987 +int au_vdir_init(struct file *file);
10988 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10991 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10993 +#ifdef CONFIG_AUFS_RDU
10995 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10996 +#ifdef CONFIG_COMPAT
10997 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10998 + unsigned long arg);
11001 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11002 + unsigned int cmd, unsigned long arg)
11003 +#ifdef CONFIG_COMPAT
11004 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11005 + unsigned int cmd, unsigned long arg)
11009 +#endif /* __KERNEL__ */
11010 +#endif /* __AUFS_DIR_H__ */
11011 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11012 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11013 +++ linux/fs/aufs/dirren.c 2019-07-11 15:42:14.462237786 +0200
11015 +// SPDX-License-Identifier: GPL-2.0
11017 + * Copyright (C) 2017-2019 Junjiro R. Okajima
11019 + * This program, aufs is free software; you can redistribute it and/or modify
11020 + * it under the terms of the GNU General Public License as published by
11021 + * the Free Software Foundation; either version 2 of the License, or
11022 + * (at your option) any later version.
11024 + * This program is distributed in the hope that it will be useful,
11025 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11026 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11027 + * GNU General Public License for more details.
11029 + * You should have received a copy of the GNU General Public License
11030 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11034 + * special handling in renaming a directory
11035 + * in order to support looking-up the before-renamed name on the lower readonly
11039 +#include <linux/byteorder/generic.h>
11042 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11046 + idx = au_dr_ihash(ent->dr_h_ino);
11047 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11050 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11053 + struct hlist_bl_head *hbl;
11056 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11057 + hbl = dr->dr_h_ino + i;
11058 + hlist_bl_lock(hbl);
11059 + ret &= hlist_bl_empty(hbl);
11060 + hlist_bl_unlock(hbl);
11066 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11068 + struct au_dr_hino *found, *ent;
11069 + struct hlist_bl_head *hbl;
11070 + struct hlist_bl_node *pos;
11074 + idx = au_dr_ihash(ino);
11075 + hbl = dr->dr_h_ino + idx;
11076 + hlist_bl_lock(hbl);
11077 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11078 + if (ent->dr_h_ino == ino) {
11082 + hlist_bl_unlock(hbl);
11087 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11088 + struct au_dr_hino *add_ent)
11091 + struct hlist_bl_head *hbl;
11092 + struct hlist_bl_node *pos;
11093 + struct au_dr_hino *ent;
11096 + idx = au_dr_ihash(ino);
11097 + hbl = dr->dr_h_ino + idx;
11100 + struct hlist_bl_node *tmp;
11102 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11103 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11106 + hlist_bl_lock(hbl);
11107 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11108 + if (ent->dr_h_ino == ino) {
11112 + if (!found && add_ent)
11113 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11114 + hlist_bl_unlock(hbl);
11116 + if (!found && add_ent)
11117 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11122 +void au_dr_hino_free(struct au_dr_br *dr)
11125 + struct hlist_bl_head *hbl;
11126 + struct hlist_bl_node *pos, *tmp;
11127 + struct au_dr_hino *ent;
11129 + /* SiMustWriteLock(sb); */
11131 + for (i = 0; i < AuDirren_NHASH; i++) {
11132 + hbl = dr->dr_h_ino + i;
11133 + /* no spinlock since sbinfo must be write-locked */
11134 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11135 + au_kfree_rcu(ent);
11136 + INIT_HLIST_BL_HEAD(hbl);
11140 +/* returns the number of inodes or an error */
11141 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11142 + struct file *hinofile)
11146 + loff_t pos, oldsize;
11148 + struct inode *hinoinode;
11149 + struct hlist_bl_head *hbl;
11150 + struct hlist_bl_node *n1, *n2;
11151 + struct au_dr_hino *ent;
11153 + SiMustWriteLock(sb);
11154 + AuDebugOn(!au_br_writable(br->br_perm));
11156 + hinoinode = file_inode(hinofile);
11157 + oldsize = i_size_read(hinoinode);
11161 + hbl = br->br_dirren.dr_h_ino;
11162 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11163 + /* no bit-lock since sbinfo must be write-locked */
11164 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11165 + AuDbg("hi%llu, %pD2\n",
11166 + (unsigned long long)ent->dr_h_ino, hinofile);
11167 + u64 = cpu_to_be64(ent->dr_h_ino);
11168 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11169 + if (ssz == sizeof(u64))
11172 + /* write error */
11173 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11180 + /* regardless the error */
11181 + if (pos < oldsize) {
11182 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11190 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11197 + struct au_dr_hino *ent;
11198 + struct inode *hinoinode;
11199 + struct hlist_bl_head *hbl;
11203 + hbl = dr->dr_h_ino;
11204 + hinoinode = file_inode(hinofile);
11205 + sz = i_size_read(hinoinode);
11206 + AuDebugOn(sz % sizeof(u64));
11207 + n = sz / sizeof(u64);
11209 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11210 + if (unlikely(ssz != sizeof(u64))) {
11211 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11218 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11224 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11225 + AuDbg("hi%llu, %pD2\n",
11226 + (unsigned long long)ent->dr_h_ino, hinofile);
11227 + hidx = au_dr_ihash(ent->dr_h_ino);
11228 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11230 + goto out; /* success */
11233 + au_dr_hino_free(dr);
11240 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11241 + * @path is a switch to distinguish load and store.
11243 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11244 + struct au_branch *br, const struct path *path)
11247 + unsigned char load, suspend;
11248 + struct file *hinofile;
11249 + struct au_hinode *hdir;
11250 + struct inode *dir, *delegated;
11251 + struct path hinopath;
11252 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11253 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11255 + AuDebugOn(bindex < 0 && !br);
11256 + AuDebugOn(bindex >= 0 && br);
11261 + br = au_sbr(sb, bindex);
11264 + path = &br->br_path;
11265 + AuDebugOn(!au_br_writable(br->br_perm));
11266 + if (unlikely(!au_br_writable(br->br_perm)))
11272 + dir = d_inode(sb->s_root);
11273 + hdir = au_hinode(au_ii(dir), bindex);
11274 + dir = hdir->hi_inode;
11275 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11277 + dir = d_inode(path->dentry);
11278 + inode_lock_nested(dir, AuLsc_I_CHILD);
11280 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11281 + err = PTR_ERR(hinopath.dentry);
11282 + if (IS_ERR(hinopath.dentry))
11286 + flags = O_RDONLY;
11288 + if (d_is_negative(hinopath.dentry))
11289 + goto out_dput; /* success */
11291 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11292 + if (d_is_positive(hinopath.dentry)) {
11293 + delegated = NULL;
11294 + err = vfsub_unlink(dir, &hinopath, &delegated,
11297 + if (unlikely(err))
11298 + pr_err("ignored err %d, %pd2\n",
11299 + err, hinopath.dentry);
11300 + if (unlikely(err == -EWOULDBLOCK))
11305 + } else if (!d_is_positive(hinopath.dentry)) {
11306 + err = vfsub_create(dir, &hinopath, 0600,
11307 + /*want_excl*/false);
11309 + if (unlikely(err))
11312 + flags = O_WRONLY;
11314 + hinopath.mnt = path->mnt;
11315 + hinofile = vfsub_dentry_open(&hinopath, flags);
11317 + au_hn_inode_unlock(hdir);
11319 + inode_unlock(dir);
11320 + dput(hinopath.dentry);
11321 + AuTraceErrPtr(hinofile);
11322 + if (IS_ERR(hinofile)) {
11323 + err = PTR_ERR(hinofile);
11328 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11330 + err = au_dr_hino_store(sb, br, hinofile);
11335 + dput(hinopath.dentry);
11338 + au_hn_inode_unlock(hdir);
11340 + inode_unlock(dir);
11346 +/* ---------------------------------------------------------------------- */
11348 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11351 + struct kstatfs kstfs;
11353 + struct dentry *dentry;
11354 + struct super_block *sb;
11356 + err = vfs_statfs((void *)path, &kstfs);
11358 + if (unlikely(err))
11361 + /* todo: support for UUID */
11363 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11364 + brid->type = AuBrid_FSID;
11365 + brid->fsid = kstfs.f_fsid;
11367 + dentry = path->dentry;
11368 + sb = dentry->d_sb;
11371 + brid->type = AuBrid_DEV;
11380 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11381 + const struct path *path)
11384 + struct au_dr_br *dr;
11385 + struct hlist_bl_head *hbl;
11387 + dr = &br->br_dirren;
11388 + hbl = dr->dr_h_ino;
11389 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11390 + INIT_HLIST_BL_HEAD(hbl);
11392 + err = au_dr_brid_init(&dr->dr_brid, path);
11393 + if (unlikely(err))
11396 + if (au_opt_test(au_mntflags(sb), DIRREN))
11397 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11404 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11409 + if (au_br_writable(br->br_perm))
11410 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11412 + au_dr_hino_free(&br->br_dirren);
11417 +/* ---------------------------------------------------------------------- */
11419 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11420 + char *buf, size_t sz)
11423 + unsigned int major, minor;
11427 + err = snprintf(p, sz, "%d_", brid->type);
11428 + AuDebugOn(err > sz);
11431 + switch (brid->type) {
11432 + case AuBrid_Unset:
11434 + case AuBrid_UUID:
11435 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11437 + case AuBrid_FSID:
11438 + err = snprintf(p, sz, "%08x-%08x",
11439 + brid->fsid.val[0], brid->fsid.val[1]);
11442 + major = MAJOR(brid->dev);
11443 + minor = MINOR(brid->dev);
11444 + if (major <= 0xff && minor <= 0xff)
11445 + err = snprintf(p, sz, "%02x%02x", major, minor);
11447 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11450 + AuDebugOn(err > sz);
11453 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11454 + AuDebugOn(err > sz);
11461 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11464 + struct dentry *br_dentry;
11465 + struct inode *br_inode;
11467 + br_dentry = au_br_dentry(br);
11468 + br_inode = d_inode(br_dentry);
11469 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11470 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11471 + AuDebugOn(rlen > len);
11476 +/* ---------------------------------------------------------------------- */
11479 + * from the given @h_dentry, construct drinfo at @*fdata.
11480 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11483 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11484 + struct dentry *h_dentry,
11485 + unsigned char *allocated)
11488 + struct au_drinfo_fdata *f, *p;
11489 + struct au_drinfo *drinfo;
11490 + struct inode *h_inode;
11491 + struct qstr *qname;
11495 + h_inode = d_inode(h_dentry);
11496 + qname = &h_dentry->d_name;
11497 + drinfo = &f->drinfo;
11498 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11499 + drinfo->oldnamelen = qname->len;
11500 + if (*allocated < sizeof(*f) + qname->len) {
11501 + v = roundup_pow_of_two(*allocated + qname->len);
11502 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11503 + if (unlikely(!p)) {
11511 + drinfo = &f->drinfo;
11513 + memcpy(drinfo->oldname, qname->name, qname->len);
11514 + AuDbg("i%llu, %.*s\n",
11515 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11516 + drinfo->oldname);
11523 +/* callers have to free the return value */
11524 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11526 + struct au_drinfo *ret, *drinfo;
11527 + struct au_drinfo_fdata fdata;
11532 + ret = ERR_PTR(-EIO);
11534 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11535 + if (unlikely(ssz != sizeof(fdata))) {
11536 + AuIOErr("ssz %zd, %u, %pD2\n",
11537 + ssz, (unsigned int)sizeof(fdata), file);
11541 + fdata.magic = ntohl((__force __be32)fdata.magic);
11542 + switch (fdata.magic) {
11543 + case AUFS_DRINFO_MAGIC_V1:
11546 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11547 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11551 + drinfo = &fdata.drinfo;
11552 + len = drinfo->oldnamelen;
11554 + AuIOErr("broken drinfo %pD2\n", file);
11559 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11560 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11561 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11562 + (unsigned long long)drinfo->ino,
11563 + (unsigned long long)h_ino, file);
11564 + goto out; /* success */
11567 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11568 + if (unlikely(!ret)) {
11569 + ret = ERR_PTR(-ENOMEM);
11570 + AuTraceErrPtr(ret);
11575 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11576 + if (unlikely(ssz != len)) {
11577 + au_kfree_rcu(ret);
11578 + ret = ERR_PTR(-EIO);
11579 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11583 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11589 +/* ---------------------------------------------------------------------- */
11591 +/* in order to be revertible */
11592 +struct au_drinfo_rev_elm {
11594 + struct dentry *info_dentry;
11595 + struct au_drinfo *info_last;
11598 +struct au_drinfo_rev {
11599 + unsigned char already;
11600 + aufs_bindex_t nelm;
11601 + struct au_drinfo_rev_elm elm[0];
11604 +/* todo: isn't it too large? */
11605 +struct au_drinfo_store {
11606 + struct path h_ppath;
11607 + struct dentry *h_dentry;
11608 + struct au_drinfo_fdata *fdata;
11609 + char *infoname; /* inside of whname, just after PFX */
11610 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11611 + aufs_bindex_t btgt, btail;
11612 + unsigned char no_sio,
11613 + allocated, /* current size of *fdata */
11614 + infonamelen, /* room size for p */
11615 + whnamelen, /* length of the generated name */
11616 + renameback; /* renamed back */
11619 +/* on rename(2) error, the caller should revert it using @elm */
11620 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11621 + struct au_drinfo_rev_elm *elm)
11626 + struct path infopath = {
11627 + .mnt = w->h_ppath.mnt
11629 + struct inode *h_dir, *h_inode, *delegated;
11630 + struct file *infofile;
11631 + struct qstr *qname;
11634 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11636 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11638 + AuTraceErrPtr(infopath.dentry);
11639 + if (IS_ERR(infopath.dentry)) {
11640 + err = PTR_ERR(infopath.dentry);
11645 + h_dir = d_inode(w->h_ppath.dentry);
11646 + if (elm && d_is_negative(infopath.dentry)) {
11647 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11649 + if (unlikely(err))
11651 + elm->created = 1;
11652 + elm->info_dentry = dget(infopath.dentry);
11655 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11656 + AuTraceErrPtr(infofile);
11657 + if (IS_ERR(infofile)) {
11658 + err = PTR_ERR(infofile);
11662 + h_inode = d_inode(infopath.dentry);
11663 + if (elm && i_size_read(h_inode)) {
11664 + h_inode = d_inode(w->h_dentry);
11665 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11666 + AuTraceErrPtr(elm->info_last);
11667 + if (IS_ERR(elm->info_last)) {
11668 + err = PTR_ERR(elm->info_last);
11669 + elm->info_last = NULL;
11670 + AuDebugOn(elm->info_dentry);
11675 + if (elm && w->renameback) {
11676 + delegated = NULL;
11677 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11679 + if (unlikely(err == -EWOULDBLOCK))
11685 + qname = &w->h_dentry->d_name;
11686 + len = sizeof(*w->fdata) + qname->len;
11688 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11689 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11690 + if (ssz == len) {
11691 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11692 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11693 + goto out_fput; /* success */
11698 + /* the caller should revert it using @elm */
11704 + dput(infopath.dentry);
11710 +struct au_call_drinfo_do_store_args {
11712 + struct au_drinfo_store *w;
11713 + struct au_drinfo_rev_elm *elm;
11716 +static void au_call_drinfo_do_store(void *args)
11718 + struct au_call_drinfo_do_store_args *a = args;
11720 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11723 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11724 + struct au_drinfo_rev_elm *elm)
11726 + int err, wkq_err;
11729 + err = au_drinfo_do_store(w, elm);
11731 + struct au_call_drinfo_do_store_args a = {
11736 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11737 + if (unlikely(wkq_err))
11745 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11746 + aufs_bindex_t btgt)
11750 + memset(w, 0, sizeof(*w));
11751 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11752 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11753 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11754 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11756 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11759 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11760 + if (unlikely(!w->fdata)) {
11764 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11771 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11773 + au_kfree_rcu(w->fdata);
11776 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11777 + struct au_drinfo_store *w)
11779 + struct au_drinfo_rev_elm *elm;
11780 + struct inode *h_dir, *delegated;
11782 + struct path infopath = {
11783 + .mnt = w->h_ppath.mnt
11786 + h_dir = d_inode(w->h_ppath.dentry);
11787 + IMustLock(h_dir);
11791 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11792 + AuDebugOn(elm->created && elm->info_last);
11793 + if (elm->created) {
11795 + delegated = NULL;
11796 + infopath.dentry = elm->info_dentry;
11797 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11800 + if (unlikely(err == -EWOULDBLOCK))
11802 + dput(elm->info_dentry);
11803 + } else if (elm->info_last) {
11805 + w->fdata->drinfo = *elm->info_last;
11806 + memcpy(w->fdata->drinfo.oldname,
11807 + elm->info_last->oldname,
11808 + elm->info_last->oldnamelen);
11809 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11810 + au_kfree_rcu(elm->info_last);
11812 + if (unlikely(err))
11813 + AuIOErr("%d, %s\n", err, w->whname);
11814 + /* go on even if err */
11818 +/* caller has to call au_dr_rename_fin() later */
11819 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11820 + struct qstr *dst_name, void *_rev)
11822 + int err, sz, nelm;
11823 + aufs_bindex_t bindex, btail;
11824 + struct au_drinfo_store work;
11825 + struct au_drinfo_rev *rev, **p;
11826 + struct au_drinfo_rev_elm *elm;
11827 + struct super_block *sb;
11828 + struct au_branch *br;
11829 + struct au_hinode *hdir;
11831 + err = au_drinfo_store_work_init(&work, btgt);
11833 + if (unlikely(err))
11837 + btail = au_dbtaildir(dentry);
11838 + nelm = btail - btgt;
11839 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11840 + rev = kcalloc(1, sz, GFP_NOFS);
11841 + if (unlikely(!rev)) {
11845 + rev->nelm = nelm;
11851 + sb = dentry->d_sb;
11852 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11853 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11854 + hdir = au_hi(d_inode(dentry), btgt);
11855 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11856 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11857 + work.h_dentry = au_h_dptr(dentry, bindex);
11858 + if (!work.h_dentry)
11861 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11862 + &work.allocated);
11864 + if (unlikely(err))
11867 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11868 + br = au_sbr(sb, bindex);
11869 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11870 + work.whnamelen += au_drinfo_name(br, work.infoname,
11871 + work.infonamelen);
11872 + AuDbg("whname %.*s, i%llu, %.*s\n",
11873 + work.whnamelen, work.whname,
11874 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11875 + work.fdata->drinfo.oldnamelen,
11876 + work.fdata->drinfo.oldname);
11878 + err = au_drinfo_store_sio(&work, elm);
11880 + if (unlikely(err))
11883 + if (unlikely(err)) {
11884 + /* revert all drinfo */
11885 + au_drinfo_store_rev(rev, &work);
11886 + au_kfree_try_rcu(rev);
11889 + au_hn_inode_unlock(hdir);
11892 + au_drinfo_store_work_fin(&work);
11897 +/* ---------------------------------------------------------------------- */
11899 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11900 + struct qstr *dst_name, void *_rev)
11902 + int err, already;
11904 + struct super_block *sb;
11905 + struct au_branch *br;
11906 + struct au_dr_br *dr;
11907 + struct dentry *h_dentry;
11908 + struct inode *h_inode;
11909 + struct au_dr_hino *ent;
11910 + struct au_drinfo_rev *rev, **p;
11912 + AuDbg("bindex %d\n", bindex);
11915 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11916 + if (unlikely(!ent))
11920 + br = au_sbr(sb, bindex);
11921 + dr = &br->br_dirren;
11922 + h_dentry = au_h_dptr(src, bindex);
11923 + h_inode = d_inode(h_dentry);
11924 + ino = h_inode->i_ino;
11925 + ent->dr_h_ino = ino;
11926 + already = au_dr_hino_test_add(dr, ino, ent);
11927 + AuDbg("b%d, hi%llu, already %d\n",
11928 + bindex, (unsigned long long)ino, already);
11930 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11935 + rev->already = already;
11936 + goto out; /* success */
11941 + au_dr_hino_del(dr, ent);
11942 + au_kfree_rcu(ent);
11949 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11951 + struct au_drinfo_rev *rev;
11952 + struct au_drinfo_rev_elm *elm;
11957 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11958 + dput(elm->info_dentry);
11959 + au_kfree_rcu(elm->info_last);
11961 + au_kfree_try_rcu(rev);
11964 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11967 + struct au_drinfo_store work;
11968 + struct au_drinfo_rev *rev = _rev;
11969 + struct super_block *sb;
11970 + struct au_branch *br;
11971 + struct inode *h_inode;
11972 + struct au_dr_br *dr;
11973 + struct au_dr_hino *ent;
11975 + err = au_drinfo_store_work_init(&work, btgt);
11976 + if (unlikely(err))
11980 + br = au_sbr(sb, btgt);
11981 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11982 + work.h_ppath.mnt = au_br_mnt(br);
11983 + au_drinfo_store_rev(rev, &work);
11984 + au_drinfo_store_work_fin(&work);
11985 + if (rev->already)
11988 + dr = &br->br_dirren;
11989 + h_inode = d_inode(work.h_ppath.dentry);
11990 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11992 + au_dr_hino_del(dr, ent);
11993 + au_kfree_rcu(ent);
11996 + au_kfree_try_rcu(rev);
11997 + if (unlikely(err))
11998 + pr_err("failed to remove dirren info\n");
12001 +/* ---------------------------------------------------------------------- */
12003 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12004 + char *whname, int whnamelen,
12005 + struct dentry **info_dentry)
12007 + struct au_drinfo *drinfo;
12009 + struct inode *h_dir;
12010 + struct path infopath;
12013 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12015 + *info_dentry = NULL;
12018 + h_dir = d_inode(h_ppath->dentry);
12019 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12020 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12022 + if (IS_ERR(infopath.dentry)) {
12023 + drinfo = (void *)infopath.dentry;
12027 + if (d_is_negative(infopath.dentry))
12028 + goto out_dput; /* success */
12030 + infopath.mnt = h_ppath->mnt;
12031 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12032 + inode_unlock_shared(h_dir);
12035 + drinfo = (void *)f;
12039 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12040 + if (IS_ERR_OR_NULL(drinfo))
12043 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12044 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12049 + dput(infopath.dentry);
12052 + inode_unlock_shared(h_dir);
12053 + AuTraceErrPtr(drinfo);
12057 +struct au_drinfo_do_load_args {
12058 + struct au_drinfo **drinfop;
12059 + struct path *h_ppath;
12062 + struct dentry **info_dentry;
12065 +static void au_call_drinfo_do_load(void *args)
12067 + struct au_drinfo_do_load_args *a = args;
12069 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12073 +struct au_drinfo_load {
12074 + struct path h_ppath;
12075 + struct qstr *qname;
12076 + unsigned char no_sio;
12078 + aufs_bindex_t ninfo;
12079 + struct au_drinfo **drinfo;
12082 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12083 + struct au_branch *br)
12085 + int err, wkq_err, whnamelen, e;
12086 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12087 + = AUFS_WH_DR_INFO_PFX;
12088 + struct au_drinfo *drinfo;
12089 + struct qstr oldname;
12090 + struct inode *h_dir, *delegated;
12091 + struct dentry *info_dentry;
12092 + struct path infopath;
12094 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12095 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12096 + sizeof(whname) - whnamelen);
12098 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12101 + struct au_drinfo_do_load_args args = {
12102 + .drinfop = &drinfo,
12103 + .h_ppath = &w->h_ppath,
12104 + .whname = whname,
12105 + .whnamelen = whnamelen,
12106 + .info_dentry = &info_dentry
12108 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12109 + if (unlikely(wkq_err))
12110 + drinfo = ERR_PTR(wkq_err);
12112 + err = PTR_ERR(drinfo);
12113 + if (IS_ERR_OR_NULL(drinfo))
12117 + oldname.len = drinfo->oldnamelen;
12118 + oldname.name = drinfo->oldname;
12119 + if (au_qstreq(w->qname, &oldname)) {
12120 + /* the name is renamed back */
12121 + au_kfree_rcu(drinfo);
12124 + infopath.dentry = info_dentry;
12125 + infopath.mnt = w->h_ppath.mnt;
12126 + h_dir = d_inode(w->h_ppath.dentry);
12127 + delegated = NULL;
12128 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12129 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12130 + inode_unlock(h_dir);
12132 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12133 + if (unlikely(e == -EWOULDBLOCK))
12136 + au_kfree_rcu(w->drinfo[bindex]);
12137 + w->drinfo[bindex] = drinfo;
12138 + dput(info_dentry);
12145 +/* ---------------------------------------------------------------------- */
12147 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12149 + struct au_drinfo **p = drinfo;
12152 + au_kfree_rcu(*drinfo++);
12153 + au_kfree_try_rcu(p);
12156 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12157 + aufs_bindex_t btgt)
12160 + struct au_drinfo_load w;
12161 + aufs_bindex_t bindex, bbot;
12162 + struct au_branch *br;
12163 + struct inode *h_dir;
12164 + struct au_dr_hino *ent;
12165 + struct super_block *sb;
12167 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12168 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12169 + AuLNPair(&lkup->whname), btgt);
12171 + sb = dentry->d_sb;
12172 + bbot = au_sbbot(sb);
12173 + w.ninfo = bbot + 1;
12174 + if (!lkup->dirren.drinfo) {
12175 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12176 + sizeof(*lkup->dirren.drinfo),
12178 + if (unlikely(!lkup->dirren.drinfo)) {
12182 + lkup->dirren.ninfo = w.ninfo;
12184 + w.drinfo = lkup->dirren.drinfo;
12185 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12186 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12187 + AuDebugOn(!w.h_ppath.dentry);
12188 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12189 + w.qname = &dentry->d_name;
12192 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12193 + br = au_sbr(sb, bindex);
12194 + err = au_drinfo_load(&w, bindex, br);
12195 + if (unlikely(err))
12197 + if (w.drinfo[bindex])
12201 + br = au_sbr(sb, btgt);
12202 + h_dir = d_inode(w.h_ppath.dentry);
12203 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12205 + au_dr_hino_del(&br->br_dirren, ent);
12206 + au_kfree_rcu(ent);
12208 + goto out; /* success */
12211 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12212 + lkup->dirren.ninfo = 0;
12213 + lkup->dirren.drinfo = NULL;
12219 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12221 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12224 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12227 + struct au_drinfo *drinfo;
12230 + if (!lkup->dirren.drinfo)
12232 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12233 + drinfo = lkup->dirren.drinfo[btgt + 1];
12237 + au_kfree_try_rcu(lkup->whname.name);
12238 + lkup->whname.name = NULL;
12239 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12240 + lkup->dirren.dr_name.name = drinfo->oldname;
12241 + lkup->name = &lkup->dirren.dr_name;
12242 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12244 + AuDbg("name %.*s, whname %.*s, b%d\n",
12245 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12253 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12257 + struct au_drinfo *drinfo;
12260 + if (!lkup->dirren.drinfo)
12262 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12263 + drinfo = lkup->dirren.drinfo[bindex + 1];
12267 + match = (drinfo->ino == h_ino);
12268 + AuDbg("match %d\n", match);
12274 +/* ---------------------------------------------------------------------- */
12276 +int au_dr_opt_set(struct super_block *sb)
12279 + aufs_bindex_t bindex, bbot;
12280 + struct au_branch *br;
12283 + bbot = au_sbbot(sb);
12284 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12285 + br = au_sbr(sb, bindex);
12286 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12292 +int au_dr_opt_flush(struct super_block *sb)
12295 + aufs_bindex_t bindex, bbot;
12296 + struct au_branch *br;
12299 + bbot = au_sbbot(sb);
12300 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12301 + br = au_sbr(sb, bindex);
12302 + if (au_br_writable(br->br_perm))
12303 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12309 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12312 + aufs_bindex_t bindex, bbot;
12313 + struct au_branch *br;
12317 + err = au_dr_opt_flush(sb);
12318 + if (unlikely(err))
12322 + bbot = au_sbbot(sb);
12323 + for (bindex = 0; bindex <= bbot; bindex++) {
12324 + br = au_sbr(sb, bindex);
12325 + au_dr_hino_free(&br->br_dirren);
12331 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12332 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12333 +++ linux/fs/aufs/dirren.h 2019-07-11 15:42:14.462237786 +0200
12335 +/* SPDX-License-Identifier: GPL-2.0 */
12337 + * Copyright (C) 2017-2019 Junjiro R. Okajima
12339 + * This program, aufs is free software; you can redistribute it and/or modify
12340 + * it under the terms of the GNU General Public License as published by
12341 + * the Free Software Foundation; either version 2 of the License, or
12342 + * (at your option) any later version.
12344 + * This program is distributed in the hope that it will be useful,
12345 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12346 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12347 + * GNU General Public License for more details.
12349 + * You should have received a copy of the GNU General Public License
12350 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12354 + * renamed dir info
12357 +#ifndef __AUFS_DIRREN_H__
12358 +#define __AUFS_DIRREN_H__
12362 +#include <linux/dcache.h>
12363 +#include <linux/statfs.h>
12364 +#include <linux/uuid.h>
12367 +#define AuDirren_NHASH 100
12369 +#ifdef CONFIG_AUFS_DIRREN
12370 +enum au_brid_type {
12377 +struct au_dr_brid {
12378 + enum au_brid_type type;
12380 + uuid_t uuid; /* unimplemented yet */
12386 +/* 20 is the max digits length of ulong 64 */
12387 +/* brid-type "_" uuid "_" inum */
12388 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12389 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12391 +struct au_dr_hino {
12392 + struct hlist_bl_node dr_hnode;
12397 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12398 + struct au_dr_brid dr_brid;
12401 +struct au_dr_lookup {
12402 + /* dr_name is pointed by struct au_do_lookup_args.name */
12403 + struct qstr dr_name; /* subset of dr_info */
12404 + aufs_bindex_t ninfo;
12405 + struct au_drinfo **drinfo;
12408 +struct au_dr_hino;
12410 +struct au_dr_br { };
12411 +struct au_dr_lookup { };
12414 +/* ---------------------------------------------------------------------- */
12417 +struct au_do_lookup_args;
12419 +#ifdef CONFIG_AUFS_DIRREN
12420 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12421 + struct au_dr_hino *add_ent);
12422 +void au_dr_hino_free(struct au_dr_br *dr);
12423 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12424 + const struct path *path);
12425 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12426 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12427 + struct qstr *dst_name, void *_rev);
12428 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12429 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12430 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12431 + aufs_bindex_t bindex);
12432 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12433 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12435 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12436 +int au_dr_opt_set(struct super_block *sb);
12437 +int au_dr_opt_flush(struct super_block *sb);
12438 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12440 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12441 + struct au_dr_hino *add_ent);
12442 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12443 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12444 + const struct path *path);
12445 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12446 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12447 + struct qstr *dst_name, void *_rev);
12448 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12449 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12451 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12452 + aufs_bindex_t bindex);
12453 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12454 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12455 + aufs_bindex_t bindex, ino_t h_ino);
12456 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12457 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12458 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12459 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12462 +/* ---------------------------------------------------------------------- */
12464 +#ifdef CONFIG_AUFS_DIRREN
12465 +static inline int au_dr_ihash(ino_t h_ino)
12467 + return h_ino % AuDirren_NHASH;
12470 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12473 +#endif /* __KERNEL__ */
12474 +#endif /* __AUFS_DIRREN_H__ */
12475 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12476 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12477 +++ linux/fs/aufs/dynop.c 2019-07-11 15:42:14.465571210 +0200
12479 +// SPDX-License-Identifier: GPL-2.0
12481 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12483 + * This program, aufs is free software; you can redistribute it and/or modify
12484 + * it under the terms of the GNU General Public License as published by
12485 + * the Free Software Foundation; either version 2 of the License, or
12486 + * (at your option) any later version.
12488 + * This program is distributed in the hope that it will be useful,
12489 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12490 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12491 + * GNU General Public License for more details.
12493 + * You should have received a copy of the GNU General Public License
12494 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12498 + * dynamically customizable operations for regular files
12503 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12506 + * How large will these lists be?
12507 + * Usually just a few elements, 20-30 at most for each, I guess.
12509 +static struct hlist_bl_head dynop[AuDyLast];
12511 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12512 + const void *h_op)
12514 + struct au_dykey *key, *tmp;
12515 + struct hlist_bl_node *pos;
12518 + hlist_bl_lock(hbl);
12519 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12520 + if (tmp->dk_op.dy_hop == h_op) {
12521 + if (kref_get_unless_zero(&tmp->dk_kref))
12525 + hlist_bl_unlock(hbl);
12530 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12532 + struct au_dykey **k, *found;
12533 + const void *h_op = key->dk_op.dy_hop;
12537 + k = br->br_dykey;
12538 + for (i = 0; i < AuBrDynOp; i++)
12540 + if (k[i]->dk_op.dy_hop == h_op) {
12547 + spin_lock(&br->br_dykey_lock);
12548 + for (; i < AuBrDynOp; i++)
12550 + if (k[i]->dk_op.dy_hop == h_op) {
12558 + spin_unlock(&br->br_dykey_lock);
12559 + BUG_ON(i == AuBrDynOp); /* expand the array */
12565 +/* kref_get() if @key is already added */
12566 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12568 + struct au_dykey *tmp, *found;
12569 + struct hlist_bl_node *pos;
12570 + const void *h_op = key->dk_op.dy_hop;
12573 + hlist_bl_lock(hbl);
12574 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12575 + if (tmp->dk_op.dy_hop == h_op) {
12576 + if (kref_get_unless_zero(&tmp->dk_kref))
12581 + hlist_bl_add_head(&key->dk_hnode, hbl);
12582 + hlist_bl_unlock(hbl);
12589 +static void dy_free_rcu(struct rcu_head *rcu)
12591 + struct au_dykey *key;
12593 + key = container_of(rcu, struct au_dykey, dk_rcu);
12598 +static void dy_free(struct kref *kref)
12600 + struct au_dykey *key;
12601 + struct hlist_bl_head *hbl;
12603 + key = container_of(kref, struct au_dykey, dk_kref);
12604 + hbl = dynop + key->dk_op.dy_type;
12605 + au_hbl_del(&key->dk_hnode, hbl);
12606 + call_rcu(&key->dk_rcu, dy_free_rcu);
12609 +void au_dy_put(struct au_dykey *key)
12611 + kref_put(&key->dk_kref, dy_free);
12614 +/* ---------------------------------------------------------------------- */
12616 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12618 +#ifdef CONFIG_AUFS_DEBUG
12619 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12620 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12622 +#define DyDbgDeclare(cnt) do {} while (0)
12623 +#define DyDbgInc(cnt) do {} while (0)
12626 +#define DySet(func, dst, src, h_op, h_sb) do { \
12628 + if (h_op->func) { \
12630 + dst.func = src.func; \
12632 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12636 +#define DySetForce(func, dst, src) do { \
12637 + AuDebugOn(!src.func); \
12639 + dst.func = src.func; \
12642 +#define DySetAop(func) \
12643 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12644 +#define DySetAopForce(func) \
12645 + DySetForce(func, dyaop->da_op, aufs_aop)
12647 +static void dy_aop(struct au_dykey *key, const void *h_op,
12648 + struct super_block *h_sb __maybe_unused)
12650 + struct au_dyaop *dyaop = (void *)key;
12651 + const struct address_space_operations *h_aop = h_op;
12652 + DyDbgDeclare(cnt);
12654 + AuDbg("%s\n", au_sbtype(h_sb));
12656 + DySetAop(writepage);
12657 + DySetAopForce(readpage); /* force */
12658 + DySetAop(writepages);
12659 + DySetAop(set_page_dirty);
12660 + DySetAop(readpages);
12661 + DySetAop(write_begin);
12662 + DySetAop(write_end);
12664 + DySetAop(invalidatepage);
12665 + DySetAop(releasepage);
12666 + DySetAop(freepage);
12667 + /* this one will be changed according to an aufs mount option */
12668 + DySetAop(direct_IO);
12669 + DySetAop(migratepage);
12670 + DySetAop(isolate_page);
12671 + DySetAop(putback_page);
12672 + DySetAop(launder_page);
12673 + DySetAop(is_partially_uptodate);
12674 + DySetAop(is_dirty_writeback);
12675 + DySetAop(error_remove_page);
12676 + DySetAop(swap_activate);
12677 + DySetAop(swap_deactivate);
12679 + DyDbgSize(cnt, *h_aop);
12682 +/* ---------------------------------------------------------------------- */
12684 +static void dy_bug(struct kref *kref)
12689 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12691 + struct au_dykey *key, *old;
12692 + struct hlist_bl_head *hbl;
12695 + void (*set)(struct au_dykey *key, const void *h_op,
12696 + struct super_block *h_sb __maybe_unused);
12698 + static const struct op a[] = {
12700 + .sz = sizeof(struct au_dyaop),
12704 + const struct op *p;
12706 + hbl = dynop + op->dy_type;
12707 + key = dy_gfind_get(hbl, op->dy_hop);
12709 + goto out_add; /* success */
12711 + p = a + op->dy_type;
12712 + key = kzalloc(p->sz, GFP_NOFS);
12713 + if (unlikely(!key)) {
12714 + key = ERR_PTR(-ENOMEM);
12718 + key->dk_op.dy_hop = op->dy_hop;
12719 + kref_init(&key->dk_kref);
12720 + p->set(key, op->dy_hop, au_br_sb(br));
12721 + old = dy_gadd(hbl, key);
12723 + au_kfree_rcu(key);
12728 + old = dy_bradd(br, key);
12730 + /* its ref-count should never be zero here */
12731 + kref_put(&key->dk_kref, dy_bug);
12736 +/* ---------------------------------------------------------------------- */
12738 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12739 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12740 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12741 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12742 + * See the aufs manual in detail.
12744 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12747 + dyaop->da_op.direct_IO = NULL;
12749 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12752 +static struct au_dyaop *dy_aget(struct au_branch *br,
12753 + const struct address_space_operations *h_aop,
12756 + struct au_dyaop *dyaop;
12757 + struct au_dynop op;
12759 + op.dy_type = AuDy_AOP;
12760 + op.dy_haop = h_aop;
12761 + dyaop = (void *)dy_get(&op, br);
12762 + if (IS_ERR(dyaop))
12764 + dy_adx(dyaop, do_dx);
12770 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12771 + struct inode *h_inode)
12774 + struct super_block *sb;
12775 + struct au_branch *br;
12776 + struct au_dyaop *dyaop;
12778 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12779 + IiMustWriteLock(inode);
12781 + sb = inode->i_sb;
12782 + br = au_sbr(sb, bindex);
12783 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12784 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12785 + err = PTR_ERR(dyaop);
12786 + if (IS_ERR(dyaop))
12787 + /* unnecessary to call dy_fput() */
12791 + inode->i_mapping->a_ops = &dyaop->da_op;
12798 + * Is it safe to replace a_ops during the inode/file is in operation?
12799 + * Yes, I hope so.
12801 +int au_dy_irefresh(struct inode *inode)
12804 + aufs_bindex_t btop;
12805 + struct inode *h_inode;
12808 + if (S_ISREG(inode->i_mode)) {
12809 + btop = au_ibtop(inode);
12810 + h_inode = au_h_iptr(inode, btop);
12811 + err = au_dy_iaop(inode, btop, h_inode);
12816 +void au_dy_arefresh(int do_dx)
12818 + struct hlist_bl_head *hbl;
12819 + struct hlist_bl_node *pos;
12820 + struct au_dykey *key;
12822 + hbl = dynop + AuDy_AOP;
12823 + hlist_bl_lock(hbl);
12824 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12825 + dy_adx((void *)key, do_dx);
12826 + hlist_bl_unlock(hbl);
12829 +/* ---------------------------------------------------------------------- */
12831 +void __init au_dy_init(void)
12835 + for (i = 0; i < AuDyLast; i++)
12836 + INIT_HLIST_BL_HEAD(dynop + i);
12839 +void au_dy_fin(void)
12843 + for (i = 0; i < AuDyLast; i++)
12844 + WARN_ON(!hlist_bl_empty(dynop + i));
12846 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12847 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12848 +++ linux/fs/aufs/dynop.h 2019-07-11 15:42:14.465571210 +0200
12850 +/* SPDX-License-Identifier: GPL-2.0 */
12852 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12854 + * This program, aufs is free software; you can redistribute it and/or modify
12855 + * it under the terms of the GNU General Public License as published by
12856 + * the Free Software Foundation; either version 2 of the License, or
12857 + * (at your option) any later version.
12859 + * This program is distributed in the hope that it will be useful,
12860 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12861 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12862 + * GNU General Public License for more details.
12864 + * You should have received a copy of the GNU General Public License
12865 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12869 + * dynamically customizable operations (for regular files only)
12872 +#ifndef __AUFS_DYNOP_H__
12873 +#define __AUFS_DYNOP_H__
12877 +#include <linux/fs.h>
12878 +#include <linux/kref.h>
12880 +enum {AuDy_AOP, AuDyLast};
12885 + const void *dy_hop;
12886 + const struct address_space_operations *dy_haop;
12892 + struct hlist_bl_node dk_hnode;
12893 + struct rcu_head dk_rcu;
12895 + struct au_dynop dk_op;
12898 + * during I am in the branch local array, kref is gotten. when the
12899 + * branch is removed, kref is put.
12901 + struct kref dk_kref;
12904 +/* stop unioning since their sizes are very different from each other */
12906 + struct au_dykey da_key;
12907 + struct address_space_operations da_op; /* not const */
12909 +/* make sure that 'struct au_dykey *' can be any type */
12910 +static_assert(!offsetof(struct au_dyaop, da_key));
12912 +/* ---------------------------------------------------------------------- */
12916 +void au_dy_put(struct au_dykey *key);
12917 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12918 + struct inode *h_inode);
12919 +int au_dy_irefresh(struct inode *inode);
12920 +void au_dy_arefresh(int do_dio);
12922 +void __init au_dy_init(void);
12923 +void au_dy_fin(void);
12925 +#endif /* __KERNEL__ */
12926 +#endif /* __AUFS_DYNOP_H__ */
12927 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12928 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12929 +++ linux/fs/aufs/export.c 2019-07-11 15:42:14.465571210 +0200
12931 +// SPDX-License-Identifier: GPL-2.0
12933 + * Copyright (C) 2005-2019 Junjiro R. Okajima
12935 + * This program, aufs is free software; you can redistribute it and/or modify
12936 + * it under the terms of the GNU General Public License as published by
12937 + * the Free Software Foundation; either version 2 of the License, or
12938 + * (at your option) any later version.
12940 + * This program is distributed in the hope that it will be useful,
12941 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12942 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12943 + * GNU General Public License for more details.
12945 + * You should have received a copy of the GNU General Public License
12946 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12953 +#include <linux/exportfs.h>
12954 +#include <linux/fs_struct.h>
12955 +#include <linux/namei.h>
12956 +#include <linux/nsproxy.h>
12957 +#include <linux/random.h>
12958 +#include <linux/writeback.h>
12962 +#ifdef CONFIG_AUFS_INO_T_64
12970 +static ino_t decode_ino(__u32 *a)
12974 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12976 +#ifdef CONFIG_AUFS_INO_T_64
12982 +static void encode_ino(__u32 *a, ino_t ino)
12988 +#ifdef CONFIG_AUFS_INO_T_64
12993 +/* NFS file handle */
12997 +#ifdef CONFIG_AUFS_INO_T_64
12998 + /* support 64bit inode number */
13011 + Fh_ino = Fh_ino1,
13012 + Fh_dir_ino = Fh_dir_ino1
13015 +static int au_test_anon(struct dentry *dentry)
13017 + /* note: read d_flags without d_lock */
13018 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13021 +int au_test_nfsd(void)
13024 + struct task_struct *tsk = current;
13025 + char comm[sizeof(tsk->comm)];
13028 + if (tsk->flags & PF_KTHREAD) {
13029 + get_task_comm(comm, tsk);
13030 + ret = !strcmp(comm, "nfsd");
13036 +/* ---------------------------------------------------------------------- */
13037 +/* inode generation external table */
13039 +void au_xigen_inc(struct inode *inode)
13044 + struct super_block *sb;
13045 + struct au_sbinfo *sbinfo;
13047 + sb = inode->i_sb;
13048 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13050 + sbinfo = au_sbi(sb);
13051 + pos = inode->i_ino;
13052 + pos *= sizeof(igen);
13053 + igen = inode->i_generation + 1;
13054 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13055 + sizeof(igen), &pos);
13056 + if (sz == sizeof(igen))
13057 + return; /* success */
13059 + if (unlikely(sz >= 0))
13060 + AuIOErr("xigen error (%zd)\n", sz);
13063 +int au_xigen_new(struct inode *inode)
13068 + struct super_block *sb;
13069 + struct au_sbinfo *sbinfo;
13070 + struct file *file;
13073 + /* todo: dirty, at mount time */
13074 + if (inode->i_ino == AUFS_ROOT_INO)
13076 + sb = inode->i_sb;
13077 + SiMustAnyLock(sb);
13078 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13082 + pos = inode->i_ino;
13083 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13084 + AuIOErr1("too large i%lld\n", pos);
13087 + pos *= sizeof(inode->i_generation);
13090 + sbinfo = au_sbi(sb);
13091 + file = sbinfo->si_xigen;
13094 + if (vfsub_f_size_read(file)
13095 + < pos + sizeof(inode->i_generation)) {
13096 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13097 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13098 + sizeof(inode->i_generation), &pos);
13100 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13101 + sizeof(inode->i_generation), &pos);
13102 + if (sz == sizeof(inode->i_generation))
13103 + goto out; /* success */
13106 + if (unlikely(sz >= 0)) {
13108 + AuIOErr("xigen error (%zd)\n", sz);
13115 +int au_xigen_set(struct super_block *sb, struct path *path)
13118 + struct au_sbinfo *sbinfo;
13119 + struct file *file;
13121 + SiMustWriteLock(sb);
13123 + sbinfo = au_sbi(sb);
13124 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13125 + err = PTR_ERR(file);
13126 + if (IS_ERR(file))
13129 + if (sbinfo->si_xigen)
13130 + fput(sbinfo->si_xigen);
13131 + sbinfo->si_xigen = file;
13138 +void au_xigen_clr(struct super_block *sb)
13140 + struct au_sbinfo *sbinfo;
13142 + SiMustWriteLock(sb);
13144 + sbinfo = au_sbi(sb);
13145 + if (sbinfo->si_xigen) {
13146 + fput(sbinfo->si_xigen);
13147 + sbinfo->si_xigen = NULL;
13151 +/* ---------------------------------------------------------------------- */
13153 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13156 + struct dentry *dentry, *d;
13157 + struct inode *inode;
13158 + unsigned int sigen;
13161 + inode = ilookup(sb, ino);
13165 + dentry = ERR_PTR(-ESTALE);
13166 + sigen = au_sigen(sb);
13167 + if (unlikely(au_is_bad_inode(inode)
13168 + || IS_DEADDIR(inode)
13169 + || sigen != au_iigen(inode, NULL)))
13173 + if (!dir_ino || S_ISDIR(inode->i_mode))
13174 + dentry = d_find_alias(inode);
13176 + spin_lock(&inode->i_lock);
13177 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13178 + spin_lock(&d->d_lock);
13179 + if (!au_test_anon(d)
13180 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13181 + dentry = dget_dlock(d);
13182 + spin_unlock(&d->d_lock);
13185 + spin_unlock(&d->d_lock);
13187 + spin_unlock(&inode->i_lock);
13189 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13190 + /* need to refresh */
13198 + AuTraceErrPtr(dentry);
13202 +/* ---------------------------------------------------------------------- */
13204 +/* todo: dirty? */
13205 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13207 +struct au_compare_mnt_args {
13209 + struct super_block *sb;
13212 + struct vfsmount *mnt;
13215 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13217 + struct au_compare_mnt_args *a = arg;
13219 + if (mnt->mnt_sb != a->sb)
13221 + a->mnt = mntget(mnt);
13225 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13228 + struct path root;
13229 + struct au_compare_mnt_args args = {
13233 + get_fs_root(current->fs, &root);
13235 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13236 + rcu_read_unlock();
13239 + AuDebugOn(!args.mnt);
13243 +struct au_nfsd_si_lock {
13244 + unsigned int sigen;
13245 + aufs_bindex_t bindex, br_id;
13246 + unsigned char force_lock;
13249 +static int si_nfsd_read_lock(struct super_block *sb,
13250 + struct au_nfsd_si_lock *nsi_lock)
13253 + aufs_bindex_t bindex;
13255 + si_read_lock(sb, AuLock_FLUSH);
13257 + /* branch id may be wrapped around */
13259 + bindex = au_br_index(sb, nsi_lock->br_id);
13260 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13261 + goto out; /* success */
13265 + if (!nsi_lock->force_lock)
13266 + si_read_unlock(sb);
13269 + nsi_lock->bindex = bindex;
13273 +struct find_name_by_ino {
13274 + struct dir_context ctx;
13275 + int called, found;
13282 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13283 + loff_t offset, u64 ino, unsigned int d_type)
13285 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13289 + if (a->ino != ino)
13292 + memcpy(a->name, name, namelen);
13293 + a->namelen = namelen;
13298 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13299 + struct au_nfsd_si_lock *nsi_lock)
13301 + struct dentry *dentry, *parent;
13302 + struct file *file;
13303 + struct inode *dir;
13304 + struct find_name_by_ino arg = {
13306 + .actor = find_name_by_ino
13311 + parent = path->dentry;
13313 + si_read_unlock(parent->d_sb);
13314 + file = vfsub_dentry_open(path, au_dir_roflags);
13315 + dentry = (void *)file;
13316 + if (IS_ERR(file))
13319 + dentry = ERR_PTR(-ENOMEM);
13320 + arg.name = (void *)__get_free_page(GFP_NOFS);
13321 + if (unlikely(!arg.name))
13328 + err = vfsub_iterate_dir(file, &arg.ctx);
13329 + } while (!err && !arg.found && arg.called);
13330 + dentry = ERR_PTR(err);
13331 + if (unlikely(err))
13333 + /* instead of ENOENT */
13334 + dentry = ERR_PTR(-ESTALE);
13338 + /* do not call vfsub_lkup_one() */
13339 + dir = d_inode(parent);
13340 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13341 + AuTraceErrPtr(dentry);
13342 + if (IS_ERR(dentry))
13344 + AuDebugOn(au_test_anon(dentry));
13345 + if (unlikely(d_really_is_negative(dentry))) {
13347 + dentry = ERR_PTR(-ENOENT);
13351 + free_page((unsigned long)arg.name);
13355 + if (unlikely(nsi_lock
13356 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13357 + if (!IS_ERR(dentry)) {
13359 + dentry = ERR_PTR(-ESTALE);
13361 + AuTraceErrPtr(dentry);
13365 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13367 + struct au_nfsd_si_lock *nsi_lock)
13369 + struct dentry *dentry;
13370 + struct path path;
13372 + if (dir_ino != AUFS_ROOT_INO) {
13373 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13374 + dentry = path.dentry;
13375 + if (!path.dentry || IS_ERR(path.dentry))
13377 + AuDebugOn(au_test_anon(path.dentry));
13379 + path.dentry = dget(sb->s_root);
13381 + path.mnt = au_mnt_get(sb);
13382 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13386 + AuTraceErrPtr(dentry);
13390 +/* ---------------------------------------------------------------------- */
13392 +static int h_acceptable(void *expv, struct dentry *dentry)
13397 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13398 + char *buf, int len, struct super_block *sb)
13402 + struct path path;
13404 + p = d_path(h_rootpath, buf, len);
13409 + path.mnt = h_rootpath->mnt;
13410 + path.dentry = h_parent;
13411 + p = d_path(&path, buf, len);
13417 + path.mnt = au_mnt_get(sb);
13418 + path.dentry = sb->s_root;
13419 + p = d_path(&path, buf, len - strlen(p));
13420 + mntput(path.mnt);
13424 + p[strlen(p)] = '/';
13427 + AuTraceErrPtr(p);
13432 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13433 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13435 + struct dentry *dentry, *h_parent, *root;
13436 + struct super_block *h_sb;
13437 + char *pathname, *p;
13438 + struct vfsmount *h_mnt;
13439 + struct au_branch *br;
13441 + struct path path;
13443 + br = au_sbr(sb, nsi_lock->bindex);
13444 + h_mnt = au_br_mnt(br);
13445 + h_sb = h_mnt->mnt_sb;
13446 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13448 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13449 + fh_len - Fh_tail, fh[Fh_h_type],
13450 + h_acceptable, /*context*/NULL);
13452 + dentry = h_parent;
13453 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13454 + AuWarn1("%s decode_fh failed, %ld\n",
13455 + au_sbtype(h_sb), PTR_ERR(h_parent));
13459 + if (unlikely(au_test_anon(h_parent))) {
13460 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13461 + au_sbtype(h_sb));
13462 + goto out_h_parent;
13465 + dentry = ERR_PTR(-ENOMEM);
13466 + pathname = (void *)__get_free_page(GFP_NOFS);
13467 + if (unlikely(!pathname))
13468 + goto out_h_parent;
13470 + root = sb->s_root;
13471 + path.mnt = h_mnt;
13472 + di_read_lock_parent(root, !AuLock_IR);
13473 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13474 + di_read_unlock(root, !AuLock_IR);
13475 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13476 + dentry = (void *)p;
13478 + goto out_pathname;
13480 + si_read_unlock(sb);
13481 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13482 + dentry = ERR_PTR(err);
13483 + if (unlikely(err))
13486 + dentry = ERR_PTR(-ENOENT);
13487 + AuDebugOn(au_test_anon(path.dentry));
13488 + if (unlikely(d_really_is_negative(path.dentry)))
13491 + if (ino != d_inode(path.dentry)->i_ino)
13492 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13494 + dentry = dget(path.dentry);
13499 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13500 + if (!IS_ERR(dentry)) {
13502 + dentry = ERR_PTR(-ESTALE);
13505 + free_page((unsigned long)pathname);
13509 + AuTraceErrPtr(dentry);
13513 +/* ---------------------------------------------------------------------- */
13515 +static struct dentry *
13516 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13519 + struct dentry *dentry;
13520 + __u32 *fh = fid->raw;
13521 + struct au_branch *br;
13522 + ino_t ino, dir_ino;
13523 + struct au_nfsd_si_lock nsi_lock = {
13527 + dentry = ERR_PTR(-ESTALE);
13528 + /* it should never happen, but the file handle is unreliable */
13529 + if (unlikely(fh_len < Fh_tail))
13531 + nsi_lock.sigen = fh[Fh_sigen];
13532 + nsi_lock.br_id = fh[Fh_br_id];
13534 + /* branch id may be wrapped around */
13536 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13538 + nsi_lock.force_lock = 1;
13540 + /* is this inode still cached? */
13541 + ino = decode_ino(fh + Fh_ino);
13542 + /* it should never happen */
13543 + if (unlikely(ino == AUFS_ROOT_INO))
13546 + dir_ino = decode_ino(fh + Fh_dir_ino);
13547 + dentry = decode_by_ino(sb, ino, dir_ino);
13548 + if (IS_ERR(dentry))
13553 + /* is the parent dir cached? */
13554 + br = au_sbr(sb, nsi_lock.bindex);
13555 + au_lcnt_inc(&br->br_nfiles);
13556 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13557 + if (IS_ERR(dentry))
13562 + /* lookup path */
13563 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13564 + if (IS_ERR(dentry))
13566 + if (unlikely(!dentry))
13567 + /* todo?: make it ESTALE */
13571 + if (!au_digen_test(dentry, au_sigen(sb))
13572 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13573 + goto out_unlock; /* success */
13576 + dentry = ERR_PTR(-ESTALE);
13579 + au_lcnt_dec(&br->br_nfiles);
13580 + si_read_unlock(sb);
13582 + AuTraceErrPtr(dentry);
13586 +#if 0 /* reserved for future use */
13587 +/* support subtreecheck option */
13588 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13589 + int fh_len, int fh_type)
13591 + struct dentry *parent;
13592 + __u32 *fh = fid->raw;
13595 + dir_ino = decode_ino(fh + Fh_dir_ino);
13596 + parent = decode_by_ino(sb, dir_ino, 0);
13597 + if (IS_ERR(parent))
13600 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13601 + dir_ino, fh, fh_len);
13604 + AuTraceErrPtr(parent);
13609 +/* ---------------------------------------------------------------------- */
13611 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13612 + struct inode *dir)
13615 + aufs_bindex_t bindex;
13616 + struct super_block *sb, *h_sb;
13617 + struct dentry *dentry, *parent, *h_parent;
13618 + struct inode *h_dir;
13619 + struct au_branch *br;
13622 + if (unlikely(*max_len <= Fh_tail)) {
13623 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13627 + err = FILEID_ROOT;
13628 + if (inode->i_ino == AUFS_ROOT_INO) {
13629 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13634 + sb = inode->i_sb;
13635 + err = si_read_lock(sb, AuLock_FLUSH);
13636 + if (unlikely(err))
13639 +#ifdef CONFIG_AUFS_DEBUG
13640 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13641 + AuWarn1("NFS-exporting requires xino\n");
13645 + ii_read_lock_child(inode);
13646 + bindex = au_ibtop(inode);
13648 + dentry = d_find_any_alias(inode);
13649 + if (unlikely(!dentry))
13651 + AuDebugOn(au_test_anon(dentry));
13652 + parent = dget_parent(dentry);
13654 + if (unlikely(!parent))
13656 + if (d_really_is_positive(parent))
13657 + dir = d_inode(parent);
13660 + ii_read_lock_parent(dir);
13661 + h_dir = au_h_iptr(dir, bindex);
13662 + ii_read_unlock(dir);
13663 + if (unlikely(!h_dir))
13665 + h_parent = d_find_any_alias(h_dir);
13666 + if (unlikely(!h_parent))
13667 + goto out_hparent;
13670 + br = au_sbr(sb, bindex);
13671 + h_sb = au_br_sb(br);
13672 + if (unlikely(!h_sb->s_export_op)) {
13673 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13674 + goto out_hparent;
13677 + fh[Fh_br_id] = br->br_id;
13678 + fh[Fh_sigen] = au_sigen(sb);
13679 + encode_ino(fh + Fh_ino, inode->i_ino);
13680 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13681 + fh[Fh_igen] = inode->i_generation;
13683 + *max_len -= Fh_tail;
13684 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13686 + /*connectable or subtreecheck*/0);
13687 + err = fh[Fh_h_type];
13688 + *max_len += Fh_tail;
13689 + /* todo: macros? */
13690 + if (err != FILEID_INVALID)
13693 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13700 + ii_read_unlock(inode);
13701 + si_read_unlock(sb);
13703 + if (unlikely(err < 0))
13704 + err = FILEID_INVALID;
13708 +/* ---------------------------------------------------------------------- */
13710 +static int aufs_commit_metadata(struct inode *inode)
13713 + aufs_bindex_t bindex;
13714 + struct super_block *sb;
13715 + struct inode *h_inode;
13716 + int (*f)(struct inode *inode);
13718 + sb = inode->i_sb;
13719 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13720 + ii_write_lock_child(inode);
13721 + bindex = au_ibtop(inode);
13722 + AuDebugOn(bindex < 0);
13723 + h_inode = au_h_iptr(inode, bindex);
13725 + f = h_inode->i_sb->s_export_op->commit_metadata;
13727 + err = f(h_inode);
13729 + struct writeback_control wbc = {
13730 + .sync_mode = WB_SYNC_ALL,
13731 + .nr_to_write = 0 /* metadata only */
13734 + err = sync_inode(h_inode, &wbc);
13737 + au_cpup_attr_timesizes(inode);
13738 + ii_write_unlock(inode);
13739 + si_read_unlock(sb);
13743 +/* ---------------------------------------------------------------------- */
13745 +static struct export_operations aufs_export_op = {
13746 + .fh_to_dentry = aufs_fh_to_dentry,
13747 + /* .fh_to_parent = aufs_fh_to_parent, */
13748 + .encode_fh = aufs_encode_fh,
13749 + .commit_metadata = aufs_commit_metadata
13752 +void au_export_init(struct super_block *sb)
13754 + struct au_sbinfo *sbinfo;
13757 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13758 + && IS_MODULE(CONFIG_EXPORTFS),
13759 + AUFS_NAME ": unsupported configuration "
13760 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13762 + sb->s_export_op = &aufs_export_op;
13763 + sbinfo = au_sbi(sb);
13764 + sbinfo->si_xigen = NULL;
13765 + get_random_bytes(&u, sizeof(u));
13766 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13767 + atomic_set(&sbinfo->si_xigen_next, u);
13769 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13770 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13771 +++ linux/fs/aufs/fhsm.c 2019-07-11 15:42:14.465571210 +0200
13773 +// SPDX-License-Identifier: GPL-2.0
13775 + * Copyright (C) 2011-2019 Junjiro R. Okajima
13777 + * This program, aufs is free software; you can redistribute it and/or modify
13778 + * it under the terms of the GNU General Public License as published by
13779 + * the Free Software Foundation; either version 2 of the License, or
13780 + * (at your option) any later version.
13782 + * This program is distributed in the hope that it will be useful,
13783 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13784 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13785 + * GNU General Public License for more details.
13787 + * You should have received a copy of the GNU General Public License
13788 + * along with this program; if not, write to the Free Software
13789 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13793 + * File-based Hierarchy Storage Management
13796 +#include <linux/anon_inodes.h>
13797 +#include <linux/poll.h>
13798 +#include <linux/seq_file.h>
13799 +#include <linux/statfs.h>
13802 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13804 + struct au_sbinfo *sbinfo;
13805 + struct au_fhsm *fhsm;
13807 + SiMustAnyLock(sb);
13809 + sbinfo = au_sbi(sb);
13810 + fhsm = &sbinfo->si_fhsm;
13811 + AuDebugOn(!fhsm);
13812 + return fhsm->fhsm_bottom;
13815 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13817 + struct au_sbinfo *sbinfo;
13818 + struct au_fhsm *fhsm;
13820 + SiMustWriteLock(sb);
13822 + sbinfo = au_sbi(sb);
13823 + fhsm = &sbinfo->si_fhsm;
13824 + AuDebugOn(!fhsm);
13825 + fhsm->fhsm_bottom = bindex;
13828 +/* ---------------------------------------------------------------------- */
13830 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13832 + struct au_br_fhsm *bf;
13834 + bf = br->br_fhsm;
13835 + MtxMustLock(&bf->bf_lock);
13837 + return !bf->bf_readable
13838 + || time_after(jiffies,
13839 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13842 +/* ---------------------------------------------------------------------- */
13844 +static void au_fhsm_notify(struct super_block *sb, int val)
13846 + struct au_sbinfo *sbinfo;
13847 + struct au_fhsm *fhsm;
13849 + SiMustAnyLock(sb);
13851 + sbinfo = au_sbi(sb);
13852 + fhsm = &sbinfo->si_fhsm;
13853 + if (au_fhsm_pid(fhsm)
13854 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13855 + atomic_set(&fhsm->fhsm_readable, val);
13857 + wake_up(&fhsm->fhsm_wqh);
13861 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13862 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13865 + struct au_branch *br;
13866 + struct au_br_fhsm *bf;
13868 + br = au_sbr(sb, bindex);
13869 + AuDebugOn(au_br_rdonly(br));
13870 + bf = br->br_fhsm;
13874 + mutex_lock(&bf->bf_lock);
13876 + MtxMustLock(&bf->bf_lock);
13878 + /* sb->s_root for NFS is unreliable */
13879 + err = au_br_stfs(br, &bf->bf_stfs);
13880 + if (unlikely(err)) {
13881 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13885 + bf->bf_jiffy = jiffies;
13886 + bf->bf_readable = 1;
13888 + au_fhsm_notify(sb, /*val*/1);
13890 + *rstfs = bf->bf_stfs;
13894 + mutex_unlock(&bf->bf_lock);
13895 + au_fhsm_notify(sb, /*val*/1);
13900 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13903 + struct au_sbinfo *sbinfo;
13904 + struct au_fhsm *fhsm;
13905 + struct au_branch *br;
13906 + struct au_br_fhsm *bf;
13908 + AuDbg("b%d, force %d\n", bindex, force);
13909 + SiMustAnyLock(sb);
13911 + sbinfo = au_sbi(sb);
13912 + fhsm = &sbinfo->si_fhsm;
13913 + if (!au_ftest_si(sbinfo, FHSM)
13914 + || fhsm->fhsm_bottom == bindex)
13917 + br = au_sbr(sb, bindex);
13918 + bf = br->br_fhsm;
13920 + mutex_lock(&bf->bf_lock);
13922 + || au_fhsm_pid(fhsm)
13923 + || au_fhsm_test_jiffy(sbinfo, br))
13924 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13926 + mutex_unlock(&bf->bf_lock);
13929 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13931 + aufs_bindex_t bindex, bbot;
13932 + struct au_branch *br;
13934 + /* exclude the bottom */
13935 + bbot = au_fhsm_bottom(sb);
13936 + for (bindex = 0; bindex < bbot; bindex++) {
13937 + br = au_sbr(sb, bindex);
13938 + if (au_br_fhsm(br->br_perm))
13939 + au_fhsm_wrote(sb, bindex, force);
13943 +/* ---------------------------------------------------------------------- */
13945 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13948 + struct au_sbinfo *sbinfo;
13949 + struct au_fhsm *fhsm;
13952 + sbinfo = file->private_data;
13953 + fhsm = &sbinfo->si_fhsm;
13954 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13955 + if (atomic_read(&fhsm->fhsm_readable))
13956 + mask = EPOLLIN /* | EPOLLRDNORM */;
13959 + AuDbg("mask 0x%x\n", mask);
13963 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13964 + struct aufs_stfs *stfs, __s16 brid)
13968 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13970 + err = __put_user(brid, &stbr->brid);
13971 + if (unlikely(err))
13977 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13978 + struct aufs_stbr __user *stbr, size_t count)
13982 + aufs_bindex_t bindex, bbot;
13983 + struct au_branch *br;
13984 + struct au_br_fhsm *bf;
13986 + /* except the bottom branch */
13989 + bbot = au_fhsm_bottom(sb);
13990 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13991 + br = au_sbr(sb, bindex);
13992 + if (!au_br_fhsm(br->br_perm))
13995 + bf = br->br_fhsm;
13996 + mutex_lock(&bf->bf_lock);
13997 + if (bf->bf_readable) {
13999 + if (count >= sizeof(*stbr))
14000 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14003 + bf->bf_readable = 0;
14004 + count -= sizeof(*stbr);
14008 + mutex_unlock(&bf->bf_lock);
14011 + err = sizeof(*stbr) * nstbr;
14016 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14021 + aufs_bindex_t nfhsm, bindex, bbot;
14022 + struct au_sbinfo *sbinfo;
14023 + struct au_fhsm *fhsm;
14024 + struct au_branch *br;
14025 + struct super_block *sb;
14028 + sbinfo = file->private_data;
14029 + fhsm = &sbinfo->si_fhsm;
14031 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14032 + if (!atomic_read(&fhsm->fhsm_readable)) {
14033 + if (vfsub_file_flags(file) & O_NONBLOCK)
14036 + err = wait_event_interruptible_locked_irq
14038 + atomic_read(&fhsm->fhsm_readable));
14040 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14041 + if (unlikely(err))
14044 + /* sb may already be dead */
14045 + au_rw_read_lock(&sbinfo->si_rwsem);
14046 + readable = atomic_read(&fhsm->fhsm_readable);
14047 + if (readable > 0) {
14048 + sb = sbinfo->si_sb;
14050 + /* exclude the bottom branch */
14052 + bbot = au_fhsm_bottom(sb);
14053 + for (bindex = 0; bindex < bbot; bindex++) {
14054 + br = au_sbr(sb, bindex);
14055 + if (au_br_fhsm(br->br_perm))
14059 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14060 + atomic_set(&fhsm->fhsm_readable, 0);
14061 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14065 + au_rw_read_unlock(&sbinfo->si_rwsem);
14073 +static int au_fhsm_release(struct inode *inode, struct file *file)
14075 + struct au_sbinfo *sbinfo;
14076 + struct au_fhsm *fhsm;
14078 + /* sb may already be dead */
14079 + sbinfo = file->private_data;
14080 + fhsm = &sbinfo->si_fhsm;
14081 + spin_lock(&fhsm->fhsm_spin);
14082 + fhsm->fhsm_pid = 0;
14083 + spin_unlock(&fhsm->fhsm_spin);
14084 + kobject_put(&sbinfo->si_kobj);
14089 +static const struct file_operations au_fhsm_fops = {
14090 + .owner = THIS_MODULE,
14091 + .llseek = noop_llseek,
14092 + .read = au_fhsm_read,
14093 + .poll = au_fhsm_poll,
14094 + .release = au_fhsm_release
14097 +int au_fhsm_fd(struct super_block *sb, int oflags)
14100 + struct au_sbinfo *sbinfo;
14101 + struct au_fhsm *fhsm;
14104 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14108 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14112 + sbinfo = au_sbi(sb);
14113 + fhsm = &sbinfo->si_fhsm;
14114 + spin_lock(&fhsm->fhsm_spin);
14115 + if (!fhsm->fhsm_pid)
14116 + fhsm->fhsm_pid = current->pid;
14119 + spin_unlock(&fhsm->fhsm_spin);
14120 + if (unlikely(err))
14123 + oflags |= O_RDONLY;
14124 + /* oflags |= FMODE_NONOTIFY; */
14125 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14127 + if (unlikely(fd < 0))
14130 + /* succeed regardless 'fhsm' status */
14131 + kobject_get(&sbinfo->si_kobj);
14132 + si_noflush_read_lock(sb);
14133 + if (au_ftest_si(sbinfo, FHSM))
14134 + au_fhsm_wrote_all(sb, /*force*/0);
14135 + si_read_unlock(sb);
14136 + goto out; /* success */
14139 + spin_lock(&fhsm->fhsm_spin);
14140 + fhsm->fhsm_pid = 0;
14141 + spin_unlock(&fhsm->fhsm_spin);
14147 +/* ---------------------------------------------------------------------- */
14149 +int au_fhsm_br_alloc(struct au_branch *br)
14154 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14156 + au_br_fhsm_init(br->br_fhsm);
14163 +/* ---------------------------------------------------------------------- */
14165 +void au_fhsm_fin(struct super_block *sb)
14167 + au_fhsm_notify(sb, /*val*/-1);
14170 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14172 + struct au_fhsm *fhsm;
14174 + fhsm = &sbinfo->si_fhsm;
14175 + spin_lock_init(&fhsm->fhsm_spin);
14176 + init_waitqueue_head(&fhsm->fhsm_wqh);
14177 + atomic_set(&fhsm->fhsm_readable, 0);
14178 + fhsm->fhsm_expire
14179 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14180 + fhsm->fhsm_bottom = -1;
14183 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14185 + sbinfo->si_fhsm.fhsm_expire
14186 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14189 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14193 + if (!au_ftest_si(sbinfo, FHSM))
14196 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14197 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14198 + seq_printf(seq, ",fhsm_sec=%u", u);
14200 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14201 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14202 +++ linux/fs/aufs/file.c 2019-07-11 15:42:14.465571210 +0200
14204 +// SPDX-License-Identifier: GPL-2.0
14206 + * Copyright (C) 2005-2019 Junjiro R. Okajima
14208 + * This program, aufs is free software; you can redistribute it and/or modify
14209 + * it under the terms of the GNU General Public License as published by
14210 + * the Free Software Foundation; either version 2 of the License, or
14211 + * (at your option) any later version.
14213 + * This program is distributed in the hope that it will be useful,
14214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14216 + * GNU General Public License for more details.
14218 + * You should have received a copy of the GNU General Public License
14219 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14223 + * handling file/dir, and address_space operation
14226 +#ifdef CONFIG_AUFS_DEBUG
14227 +#include <linux/migrate.h>
14229 +#include <linux/pagemap.h>
14232 +/* drop flags for writing */
14233 +unsigned int au_file_roflags(unsigned int flags)
14235 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14236 + flags |= O_RDONLY | O_NOATIME;
14240 +/* common functions to regular file and dir */
14241 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14242 + struct file *file, int force_wr)
14244 + struct file *h_file;
14245 + struct dentry *h_dentry;
14246 + struct inode *h_inode;
14247 + struct super_block *sb;
14248 + struct au_branch *br;
14249 + struct path h_path;
14252 + /* a race condition can happen between open and unlink/rmdir */
14253 + h_file = ERR_PTR(-ENOENT);
14254 + h_dentry = au_h_dptr(dentry, bindex);
14255 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14257 + h_inode = d_inode(h_dentry);
14258 + spin_lock(&h_dentry->d_lock);
14259 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14260 + /* || !d_inode(dentry)->i_nlink */
14262 + spin_unlock(&h_dentry->d_lock);
14263 + if (unlikely(err))
14266 + sb = dentry->d_sb;
14267 + br = au_sbr(sb, bindex);
14268 + err = au_br_test_oflag(flags, br);
14269 + h_file = ERR_PTR(err);
14270 + if (unlikely(err))
14273 + /* drop flags for writing */
14274 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14275 + if (force_wr && !(flags & O_WRONLY))
14277 + flags = au_file_roflags(flags);
14279 + h_file = ERR_PTR(-EROFS);
14280 + flags = au_file_roflags(flags);
14281 + if (unlikely(vfsub_native_ro(h_inode)
14282 + || IS_APPEND(h_inode)))
14284 + flags &= ~O_ACCMODE;
14285 + flags |= O_WRONLY;
14288 + flags &= ~O_CREAT;
14289 + au_lcnt_inc(&br->br_nfiles);
14290 + h_path.dentry = h_dentry;
14291 + h_path.mnt = au_br_mnt(br);
14292 + h_file = vfsub_dentry_open(&h_path, flags);
14293 + if (IS_ERR(h_file))
14296 + if (flags & __FMODE_EXEC) {
14297 + err = deny_write_access(h_file);
14298 + if (unlikely(err)) {
14300 + h_file = ERR_PTR(err);
14304 + fsnotify_open(h_file);
14305 + goto out; /* success */
14308 + au_lcnt_dec(&br->br_nfiles);
14313 +static int au_cmoo(struct dentry *dentry)
14315 + int err, cmoo, matched;
14316 + unsigned int udba;
14317 + struct path h_path;
14318 + struct au_pin pin;
14319 + struct au_cp_generic cpg = {
14320 + .dentry = dentry,
14325 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14327 + struct inode *delegated;
14328 + struct super_block *sb;
14329 + struct au_sbinfo *sbinfo;
14330 + struct au_fhsm *fhsm;
14332 + struct au_branch *br;
14333 + struct dentry *parent;
14334 + struct au_hinode *hdir;
14336 + DiMustWriteLock(dentry);
14337 + IiMustWriteLock(d_inode(dentry));
14340 + if (IS_ROOT(dentry))
14342 + cpg.bsrc = au_dbtop(dentry);
14346 + sb = dentry->d_sb;
14347 + sbinfo = au_sbi(sb);
14348 + fhsm = &sbinfo->si_fhsm;
14349 + pid = au_fhsm_pid(fhsm);
14352 + && (current->pid == pid
14353 + || rcu_dereference(current->real_parent)->pid == pid));
14354 + rcu_read_unlock();
14358 + br = au_sbr(sb, cpg.bsrc);
14359 + cmoo = au_br_cmoo(br->br_perm);
14362 + if (!d_is_reg(dentry))
14363 + cmoo &= AuBrAttr_COO_ALL;
14367 + parent = dget_parent(dentry);
14368 + di_write_lock_parent(parent);
14369 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14371 + if (unlikely(err < 0)) {
14372 + err = 0; /* there is no upper writable branch */
14375 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14377 + /* do not respect the coo attrib for the target branch */
14378 + err = au_cpup_dirs(dentry, cpg.bdst);
14379 + if (unlikely(err))
14382 + di_downgrade_lock(parent, AuLock_IR);
14383 + udba = au_opt_udba(sb);
14384 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14385 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14386 + if (unlikely(err))
14389 + err = au_sio_cpup_simple(&cpg);
14391 + if (unlikely(err))
14393 + if (!(cmoo & AuBrWAttr_MOO))
14394 + goto out_parent; /* success */
14396 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14397 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14398 + if (unlikely(err))
14401 + h_path.mnt = au_br_mnt(br);
14402 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14403 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14404 + delegated = NULL;
14405 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14407 + /* todo: keep h_dentry or not? */
14408 + if (unlikely(err == -EWOULDBLOCK)) {
14409 + pr_warn("cannot retry for NFSv4 delegation"
14410 + " for an internal unlink\n");
14413 + if (unlikely(err)) {
14414 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14418 + goto out_parent; /* success */
14421 + di_downgrade_lock(parent, AuLock_IR);
14423 + di_read_unlock(parent, AuLock_IR);
14430 +int au_do_open(struct file *file, struct au_do_open_args *args)
14432 + int err, aopen = args->aopen;
14433 + struct dentry *dentry;
14434 + struct au_finfo *finfo;
14437 + err = au_finfo_init(file, args->fidir);
14440 + err = au_finfo_init(file, args->fidir);
14443 + if (unlikely(err))
14446 + dentry = file->f_path.dentry;
14447 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14448 + di_write_lock_child(dentry);
14449 + err = au_cmoo(dentry);
14450 + di_downgrade_lock(dentry, AuLock_IR);
14453 + err = args->open(file, vfsub_file_flags(file), NULL);
14456 + err = args->open(file, vfsub_file_flags(file),
14461 + di_read_unlock(dentry, AuLock_IR);
14463 + finfo = au_fi(file);
14465 + finfo->fi_file = file;
14466 + au_hbl_add(&finfo->fi_hlist,
14467 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14470 + fi_write_unlock(file);
14473 + fi_write_unlock(file);
14476 + if (unlikely(err)) {
14477 + finfo->fi_hdir = NULL;
14478 + au_finfo_fin(file);
14486 +int au_reopen_nondir(struct file *file)
14489 + aufs_bindex_t btop;
14490 + struct dentry *dentry;
14491 + struct au_branch *br;
14492 + struct file *h_file, *h_file_tmp;
14494 + dentry = file->f_path.dentry;
14495 + btop = au_dbtop(dentry);
14496 + br = au_sbr(dentry->d_sb, btop);
14497 + h_file_tmp = NULL;
14498 + if (au_fbtop(file) == btop) {
14499 + h_file = au_hf_top(file);
14500 + if (file->f_mode == h_file->f_mode)
14501 + return 0; /* success */
14502 + h_file_tmp = h_file;
14503 + get_file(h_file_tmp);
14504 + au_lcnt_inc(&br->br_nfiles);
14505 + au_set_h_fptr(file, btop, NULL);
14507 + AuDebugOn(au_fi(file)->fi_hdir);
14510 + * file exists on both of rw and ro
14511 + * open --> dbtop and fbtop are both 0
14512 + * prepend a branch as rw, "rw" become ro
14514 + * delete the top branch, "rw" becomes rw again
14515 + * --> dbtop is 1, fbtop is still 0
14516 + * write --> fbtop is 0 but dbtop is 1
14518 + /* AuDebugOn(au_fbtop(file) < btop); */
14520 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14521 + file, /*force_wr*/0);
14522 + err = PTR_ERR(h_file);
14523 + if (IS_ERR(h_file)) {
14524 + if (h_file_tmp) {
14526 + au_set_h_fptr(file, btop, h_file_tmp);
14527 + h_file_tmp = NULL;
14529 + goto out; /* todo: close all? */
14533 + au_set_fbtop(file, btop);
14534 + au_set_h_fptr(file, btop, h_file);
14535 + au_update_figen(file);
14536 + /* todo: necessary? */
14537 + /* file->f_ra = h_file->f_ra; */
14540 + if (h_file_tmp) {
14541 + fput(h_file_tmp);
14542 + au_lcnt_dec(&br->br_nfiles);
14547 +/* ---------------------------------------------------------------------- */
14549 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14550 + struct dentry *hi_wh)
14553 + aufs_bindex_t btop;
14554 + struct au_dinfo *dinfo;
14555 + struct dentry *h_dentry;
14556 + struct au_hdentry *hdp;
14558 + dinfo = au_di(file->f_path.dentry);
14559 + AuRwMustWriteLock(&dinfo->di_rwsem);
14561 + btop = dinfo->di_btop;
14562 + dinfo->di_btop = btgt;
14563 + hdp = au_hdentry(dinfo, btgt);
14564 + h_dentry = hdp->hd_dentry;
14565 + hdp->hd_dentry = hi_wh;
14566 + err = au_reopen_nondir(file);
14567 + hdp->hd_dentry = h_dentry;
14568 + dinfo->di_btop = btop;
14573 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14574 + aufs_bindex_t bcpup, struct au_pin *pin)
14577 + struct inode *inode, *h_inode;
14578 + struct dentry *h_dentry, *hi_wh;
14579 + struct au_cp_generic cpg = {
14580 + .dentry = file->f_path.dentry,
14587 + au_update_dbtop(cpg.dentry);
14588 + inode = d_inode(cpg.dentry);
14590 + if (au_dbtop(cpg.dentry) <= bcpup
14591 + && au_dbbot(cpg.dentry) >= bcpup) {
14592 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14593 + if (h_dentry && d_is_positive(h_dentry))
14594 + h_inode = d_inode(h_dentry);
14596 + hi_wh = au_hi_wh(inode, bcpup);
14597 + if (!hi_wh && !h_inode)
14598 + err = au_sio_cpup_wh(&cpg, file);
14600 + /* already copied-up after unlink */
14601 + err = au_reopen_wh(file, bcpup, hi_wh);
14604 + && (inode->i_nlink > 1
14605 + || (inode->i_state & I_LINKABLE))
14606 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14607 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14613 + * prepare the @file for writing.
14615 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14618 + aufs_bindex_t dbtop;
14619 + struct dentry *parent;
14620 + struct inode *inode;
14621 + struct super_block *sb;
14622 + struct file *h_file;
14623 + struct au_cp_generic cpg = {
14624 + .dentry = file->f_path.dentry,
14629 + .flags = AuCpup_DTIME
14632 + sb = cpg.dentry->d_sb;
14633 + inode = d_inode(cpg.dentry);
14634 + cpg.bsrc = au_fbtop(file);
14635 + err = au_test_ro(sb, cpg.bsrc, inode);
14636 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14637 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14642 + /* need to cpup or reopen */
14643 + parent = dget_parent(cpg.dentry);
14644 + di_write_lock_parent(parent);
14645 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14647 + if (unlikely(err < 0))
14651 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14652 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14653 + if (unlikely(err))
14657 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14658 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14659 + if (unlikely(err))
14662 + dbtop = au_dbtop(cpg.dentry);
14663 + if (dbtop <= cpg.bdst)
14664 + cpg.bsrc = cpg.bdst;
14666 + if (dbtop <= cpg.bdst /* just reopen */
14667 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14669 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14670 + if (IS_ERR(h_file))
14671 + err = PTR_ERR(h_file);
14673 + di_downgrade_lock(parent, AuLock_IR);
14674 + if (dbtop > cpg.bdst)
14675 + err = au_sio_cpup_simple(&cpg);
14677 + err = au_reopen_nondir(file);
14678 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14680 + } else { /* copyup as wh and reopen */
14682 + * since writable hfsplus branch is not supported,
14683 + * h_open_pre/post() are unnecessary.
14685 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14686 + di_downgrade_lock(parent, AuLock_IR);
14690 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14691 + goto out_dput; /* success */
14697 + di_downgrade_lock(parent, AuLock_IR);
14699 + di_read_unlock(parent, AuLock_IR);
14706 +/* ---------------------------------------------------------------------- */
14708 +int au_do_flush(struct file *file, fl_owner_t id,
14709 + int (*flush)(struct file *file, fl_owner_t id))
14712 + struct super_block *sb;
14713 + struct inode *inode;
14715 + inode = file_inode(file);
14716 + sb = inode->i_sb;
14717 + si_noflush_read_lock(sb);
14718 + fi_read_lock(file);
14719 + ii_read_lock_child(inode);
14721 + err = flush(file, id);
14722 + au_cpup_attr_timesizes(inode);
14724 + ii_read_unlock(inode);
14725 + fi_read_unlock(file);
14726 + si_read_unlock(sb);
14730 +/* ---------------------------------------------------------------------- */
14732 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14735 + struct au_pin pin;
14736 + struct au_finfo *finfo;
14737 + struct dentry *parent, *hi_wh;
14738 + struct inode *inode;
14739 + struct super_block *sb;
14740 + struct au_cp_generic cpg = {
14741 + .dentry = file->f_path.dentry,
14746 + .flags = AuCpup_DTIME
14749 + FiMustWriteLock(file);
14752 + finfo = au_fi(file);
14753 + sb = cpg.dentry->d_sb;
14754 + inode = d_inode(cpg.dentry);
14755 + cpg.bdst = au_ibtop(inode);
14756 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14759 + parent = dget_parent(cpg.dentry);
14760 + if (au_test_ro(sb, cpg.bdst, inode)) {
14761 + di_read_lock_parent(parent, !AuLock_IR);
14762 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14764 + di_read_unlock(parent, !AuLock_IR);
14765 + if (unlikely(err < 0))
14770 + di_read_lock_parent(parent, AuLock_IR);
14771 + hi_wh = au_hi_wh(inode, cpg.bdst);
14772 + if (!S_ISDIR(inode->i_mode)
14773 + && au_opt_test(au_mntflags(sb), PLINK)
14774 + && au_plink_test(inode)
14775 + && !d_unhashed(cpg.dentry)
14776 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14777 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14778 + if (unlikely(err))
14781 + /* always superio. */
14782 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14783 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14785 + err = au_sio_cpup_simple(&cpg);
14788 + } else if (hi_wh) {
14789 + /* already copied-up after unlink */
14790 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14791 + *need_reopen = 0;
14795 + di_read_unlock(parent, AuLock_IR);
14802 +static void au_do_refresh_dir(struct file *file)
14804 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14805 + struct au_hfile *p, tmp, *q;
14806 + struct au_finfo *finfo;
14807 + struct super_block *sb;
14808 + struct au_fidir *fidir;
14810 + FiMustWriteLock(file);
14812 + sb = file->f_path.dentry->d_sb;
14813 + finfo = au_fi(file);
14814 + fidir = finfo->fi_hdir;
14815 + AuDebugOn(!fidir);
14816 + p = fidir->fd_hfile + finfo->fi_btop;
14817 + brid = p->hf_br->br_id;
14818 + bbot = fidir->fd_bbot;
14819 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14823 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14824 + if (new_bindex == bindex)
14826 + if (new_bindex < 0) {
14827 + au_set_h_fptr(file, bindex, NULL);
14831 + /* swap two lower inode, and loop again */
14832 + q = fidir->fd_hfile + new_bindex;
14836 + if (tmp.hf_file) {
14842 + p = fidir->fd_hfile;
14843 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14844 + bbot = au_sbbot(sb);
14845 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14846 + finfo->fi_btop++, p++)
14847 + if (p->hf_file) {
14848 + if (file_inode(p->hf_file))
14850 + au_hfput(p, /*execed*/0);
14853 + bbot = au_br_index(sb, brid);
14854 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14855 + finfo->fi_btop++, p++)
14857 + au_hfput(p, /*execed*/0);
14858 + bbot = au_sbbot(sb);
14861 + p = fidir->fd_hfile + bbot;
14862 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14863 + fidir->fd_bbot--, p--)
14864 + if (p->hf_file) {
14865 + if (file_inode(p->hf_file))
14867 + au_hfput(p, /*execed*/0);
14869 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14873 + * after branch manipulating, refresh the file.
14875 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14877 + int err, need_reopen, nbr;
14878 + aufs_bindex_t bbot, bindex;
14879 + struct dentry *dentry;
14880 + struct super_block *sb;
14881 + struct au_finfo *finfo;
14882 + struct au_hfile *hfile;
14884 + dentry = file->f_path.dentry;
14885 + sb = dentry->d_sb;
14886 + nbr = au_sbbot(sb) + 1;
14887 + finfo = au_fi(file);
14888 + if (!finfo->fi_hdir) {
14889 + hfile = &finfo->fi_htop;
14890 + AuDebugOn(!hfile->hf_file);
14891 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14892 + AuDebugOn(bindex < 0);
14893 + if (bindex != finfo->fi_btop)
14894 + au_set_fbtop(file, bindex);
14896 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14897 + if (unlikely(err))
14899 + au_do_refresh_dir(file);
14904 + if (!au_test_mmapped(file))
14905 + err = au_file_refresh_by_inode(file, &need_reopen);
14906 + if (finfo->fi_hdir)
14907 + /* harmless if err */
14908 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14909 + if (!err && need_reopen && !d_unlinked(dentry))
14910 + err = reopen(file);
14912 + au_update_figen(file);
14913 + goto out; /* success */
14916 + /* error, close all lower files */
14917 + if (finfo->fi_hdir) {
14918 + bbot = au_fbbot_dir(file);
14919 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14920 + au_set_h_fptr(file, bindex, NULL);
14927 +/* common function to regular file and dir */
14928 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14929 + int wlock, unsigned int fi_lsc)
14932 + unsigned int sigen, figen;
14933 + aufs_bindex_t btop;
14934 + unsigned char pseudo_link;
14935 + struct dentry *dentry;
14936 + struct inode *inode;
14939 + dentry = file->f_path.dentry;
14940 + inode = d_inode(dentry);
14941 + sigen = au_sigen(dentry->d_sb);
14942 + fi_write_lock_nested(file, fi_lsc);
14943 + figen = au_figen(file);
14945 + di_write_lock_child(dentry);
14947 + di_write_lock_child2(dentry);
14948 + btop = au_dbtop(dentry);
14949 + pseudo_link = (btop != au_ibtop(inode));
14950 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14952 + di_downgrade_lock(dentry, AuLock_IR);
14953 + fi_downgrade_lock(file);
14955 + goto out; /* success */
14958 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14959 + if (au_digen_test(dentry, sigen)) {
14960 + err = au_reval_dpath(dentry, sigen);
14961 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14965 + err = refresh_file(file, reopen);
14968 + di_downgrade_lock(dentry, AuLock_IR);
14969 + fi_downgrade_lock(file);
14972 + di_write_unlock(dentry);
14973 + fi_write_unlock(file);
14980 +/* ---------------------------------------------------------------------- */
14982 +/* cf. aufs_nopage() */
14983 +/* for madvise(2) */
14984 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14986 + unlock_page(page);
14990 +/* it will never be called, but necessary to support O_DIRECT */
14991 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14992 +{ BUG(); return 0; }
14994 +/* they will never be called. */
14995 +#ifdef CONFIG_AUFS_DEBUG
14996 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14997 + loff_t pos, unsigned len, unsigned flags,
14998 + struct page **pagep, void **fsdata)
14999 +{ AuUnsupport(); return 0; }
15000 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15001 + loff_t pos, unsigned len, unsigned copied,
15002 + struct page *page, void *fsdata)
15003 +{ AuUnsupport(); return 0; }
15004 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15005 +{ AuUnsupport(); return 0; }
15007 +static int aufs_set_page_dirty(struct page *page)
15008 +{ AuUnsupport(); return 0; }
15009 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15010 + unsigned int length)
15011 +{ AuUnsupport(); }
15012 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15013 +{ AuUnsupport(); return 0; }
15014 +#if 0 /* called by memory compaction regardless file */
15015 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15016 + struct page *page, enum migrate_mode mode)
15017 +{ AuUnsupport(); return 0; }
15019 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15020 +{ AuUnsupport(); return true; }
15021 +static void aufs_putback_page(struct page *page)
15022 +{ AuUnsupport(); }
15023 +static int aufs_launder_page(struct page *page)
15024 +{ AuUnsupport(); return 0; }
15025 +static int aufs_is_partially_uptodate(struct page *page,
15026 + unsigned long from,
15027 + unsigned long count)
15028 +{ AuUnsupport(); return 0; }
15029 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15031 +{ AuUnsupport(); }
15032 +static int aufs_error_remove_page(struct address_space *mapping,
15033 + struct page *page)
15034 +{ AuUnsupport(); return 0; }
15035 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15037 +{ AuUnsupport(); return 0; }
15038 +static void aufs_swap_deactivate(struct file *file)
15039 +{ AuUnsupport(); }
15040 +#endif /* CONFIG_AUFS_DEBUG */
15042 +const struct address_space_operations aufs_aop = {
15043 + .readpage = aufs_readpage,
15044 + .direct_IO = aufs_direct_IO,
15045 +#ifdef CONFIG_AUFS_DEBUG
15046 + .writepage = aufs_writepage,
15047 + /* no writepages, because of writepage */
15048 + .set_page_dirty = aufs_set_page_dirty,
15049 + /* no readpages, because of readpage */
15050 + .write_begin = aufs_write_begin,
15051 + .write_end = aufs_write_end,
15052 + /* no bmap, no block device */
15053 + .invalidatepage = aufs_invalidatepage,
15054 + .releasepage = aufs_releasepage,
15055 + /* is fallback_migrate_page ok? */
15056 + /* .migratepage = aufs_migratepage, */
15057 + .isolate_page = aufs_isolate_page,
15058 + .putback_page = aufs_putback_page,
15059 + .launder_page = aufs_launder_page,
15060 + .is_partially_uptodate = aufs_is_partially_uptodate,
15061 + .is_dirty_writeback = aufs_is_dirty_writeback,
15062 + .error_remove_page = aufs_error_remove_page,
15063 + .swap_activate = aufs_swap_activate,
15064 + .swap_deactivate = aufs_swap_deactivate
15065 +#endif /* CONFIG_AUFS_DEBUG */
15067 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15068 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15069 +++ linux/fs/aufs/file.h 2019-07-11 15:42:14.465571210 +0200
15071 +/* SPDX-License-Identifier: GPL-2.0 */
15073 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15075 + * This program, aufs is free software; you can redistribute it and/or modify
15076 + * it under the terms of the GNU General Public License as published by
15077 + * the Free Software Foundation; either version 2 of the License, or
15078 + * (at your option) any later version.
15080 + * This program is distributed in the hope that it will be useful,
15081 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15082 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15083 + * GNU General Public License for more details.
15085 + * You should have received a copy of the GNU General Public License
15086 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15090 + * file operations
15093 +#ifndef __AUFS_FILE_H__
15094 +#define __AUFS_FILE_H__
15098 +#include <linux/file.h>
15099 +#include <linux/fs.h>
15100 +#include <linux/mm_types.h>
15101 +#include <linux/poll.h>
15102 +#include "rwsem.h"
15106 + struct file *hf_file;
15107 + struct au_branch *hf_br;
15112 + aufs_bindex_t fd_bbot;
15113 + aufs_bindex_t fd_nent;
15114 + struct au_vdir *fd_vdir_cache;
15115 + struct au_hfile fd_hfile[];
15118 +static inline int au_fidir_sz(int nent)
15120 + AuDebugOn(nent < 0);
15121 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15125 + atomic_t fi_generation;
15127 + struct au_rwsem fi_rwsem;
15128 + aufs_bindex_t fi_btop;
15130 + /* do not union them */
15131 + struct { /* for non-dir */
15132 + struct au_hfile fi_htop;
15133 + atomic_t fi_mmapped;
15135 + struct au_fidir *fi_hdir; /* for dir only */
15137 + struct hlist_bl_node fi_hlist;
15138 + struct file *fi_file; /* very ugly */
15139 + struct rcu_head rcu;
15140 +} ____cacheline_aligned_in_smp;
15142 +/* ---------------------------------------------------------------------- */
15145 +extern const struct address_space_operations aufs_aop;
15146 +unsigned int au_file_roflags(unsigned int flags);
15147 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15148 + struct file *file, int force_wr);
15149 +struct au_do_open_args {
15151 + int (*open)(struct file *file, int flags,
15152 + struct file *h_file);
15153 + struct au_fidir *fidir;
15154 + struct file *h_file;
15156 +int au_do_open(struct file *file, struct au_do_open_args *args);
15157 +int au_reopen_nondir(struct file *file);
15159 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15160 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15161 + int wlock, unsigned int fi_lsc);
15162 +int au_do_flush(struct file *file, fl_owner_t id,
15163 + int (*flush)(struct file *file, fl_owner_t id));
15166 +#ifdef CONFIG_AUFS_POLL
15167 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15170 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15172 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15174 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15175 + struct file *h_file);
15177 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15178 + aufs_bindex_t bindex, int force_wr)
15179 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15180 + struct file *h_file);
15184 +extern const struct file_operations aufs_file_fop;
15185 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15186 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15187 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15190 +void au_hfput(struct au_hfile *hf, int execed);
15191 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15192 + struct file *h_file);
15194 +void au_update_figen(struct file *file);
15195 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15196 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15198 +void au_fi_init_once(void *_fi);
15199 +void au_finfo_fin(struct file *file);
15200 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15203 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15204 +#ifdef CONFIG_COMPAT
15205 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15206 + unsigned long arg);
15207 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15208 + unsigned long arg);
15211 +/* ---------------------------------------------------------------------- */
15213 +static inline struct au_finfo *au_fi(struct file *file)
15215 + return file->private_data;
15218 +/* ---------------------------------------------------------------------- */
15220 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15221 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15222 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15223 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15225 +#define fi_read_trylock_nested(f) \
15226 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15227 +#define fi_write_trylock_nested(f) \
15228 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15231 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15232 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15233 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15235 +/* lock subclass for finfo */
15241 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15243 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15246 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15248 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15252 + * fi_read_lock_1, fi_write_lock_1,
15253 + * fi_read_lock_2, fi_write_lock_2
15255 +#define AuReadLockFunc(name) \
15256 +static inline void fi_read_lock_##name(struct file *f) \
15257 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15259 +#define AuWriteLockFunc(name) \
15260 +static inline void fi_write_lock_##name(struct file *f) \
15261 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15263 +#define AuRWLockFuncs(name) \
15264 + AuReadLockFunc(name) \
15265 + AuWriteLockFunc(name)
15270 +#undef AuReadLockFunc
15271 +#undef AuWriteLockFunc
15272 +#undef AuRWLockFuncs
15274 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15275 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15276 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15278 +/* ---------------------------------------------------------------------- */
15280 +/* todo: hard/soft set? */
15281 +static inline aufs_bindex_t au_fbtop(struct file *file)
15283 + FiMustAnyLock(file);
15284 + return au_fi(file)->fi_btop;
15287 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15289 + FiMustAnyLock(file);
15290 + AuDebugOn(!au_fi(file)->fi_hdir);
15291 + return au_fi(file)->fi_hdir->fd_bbot;
15294 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15296 + FiMustAnyLock(file);
15297 + AuDebugOn(!au_fi(file)->fi_hdir);
15298 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15301 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15303 + FiMustWriteLock(file);
15304 + au_fi(file)->fi_btop = bindex;
15307 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15309 + FiMustWriteLock(file);
15310 + AuDebugOn(!au_fi(file)->fi_hdir);
15311 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15314 +static inline void au_set_fvdir_cache(struct file *file,
15315 + struct au_vdir *vdir_cache)
15317 + FiMustWriteLock(file);
15318 + AuDebugOn(!au_fi(file)->fi_hdir);
15319 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15322 +static inline struct file *au_hf_top(struct file *file)
15324 + FiMustAnyLock(file);
15325 + AuDebugOn(au_fi(file)->fi_hdir);
15326 + return au_fi(file)->fi_htop.hf_file;
15329 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15331 + FiMustAnyLock(file);
15332 + AuDebugOn(!au_fi(file)->fi_hdir);
15333 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15336 +/* todo: memory barrier? */
15337 +static inline unsigned int au_figen(struct file *f)
15339 + return atomic_read(&au_fi(f)->fi_generation);
15342 +static inline void au_set_mmapped(struct file *f)
15344 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15346 + pr_warn("fi_mmapped wrapped around\n");
15347 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15351 +static inline void au_unset_mmapped(struct file *f)
15353 + atomic_dec(&au_fi(f)->fi_mmapped);
15356 +static inline int au_test_mmapped(struct file *f)
15358 + return atomic_read(&au_fi(f)->fi_mmapped);
15361 +/* customize vma->vm_file */
15363 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15364 + struct file *file)
15368 + f = vma->vm_file;
15370 + vma->vm_file = file;
15375 +#define AuDbgVmRegion(file, vma) do {} while (0)
15377 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15378 + struct file *file)
15380 + au_do_vm_file_reset(vma, file);
15383 +#define AuDbgVmRegion(file, vma) \
15384 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15386 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15387 + struct file *file)
15391 + au_do_vm_file_reset(vma, file);
15392 + f = vma->vm_region->vm_file;
15394 + vma->vm_region->vm_file = file;
15397 +#endif /* CONFIG_MMU */
15399 +/* handle vma->vm_prfile */
15400 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15401 + struct file *file)
15404 + vma->vm_prfile = file;
15405 +#ifndef CONFIG_MMU
15407 + vma->vm_region->vm_prfile = file;
15411 +#endif /* __KERNEL__ */
15412 +#endif /* __AUFS_FILE_H__ */
15413 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15414 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15415 +++ linux/fs/aufs/finfo.c 2019-07-11 15:42:14.465571210 +0200
15417 +// SPDX-License-Identifier: GPL-2.0
15419 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15421 + * This program, aufs is free software; you can redistribute it and/or modify
15422 + * it under the terms of the GNU General Public License as published by
15423 + * the Free Software Foundation; either version 2 of the License, or
15424 + * (at your option) any later version.
15426 + * This program is distributed in the hope that it will be useful,
15427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15429 + * GNU General Public License for more details.
15431 + * You should have received a copy of the GNU General Public License
15432 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15436 + * file private data
15441 +void au_hfput(struct au_hfile *hf, int execed)
15444 + allow_write_access(hf->hf_file);
15445 + fput(hf->hf_file);
15446 + hf->hf_file = NULL;
15447 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15448 + hf->hf_br = NULL;
15451 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15453 + struct au_finfo *finfo = au_fi(file);
15454 + struct au_hfile *hf;
15455 + struct au_fidir *fidir;
15457 + fidir = finfo->fi_hdir;
15459 + AuDebugOn(finfo->fi_btop != bindex);
15460 + hf = &finfo->fi_htop;
15462 + hf = fidir->fd_hfile + bindex;
15464 + if (hf && hf->hf_file)
15465 + au_hfput(hf, vfsub_file_execed(file));
15467 + FiMustWriteLock(file);
15468 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15469 + hf->hf_file = val;
15470 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15474 +void au_update_figen(struct file *file)
15476 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15477 + /* smp_mb(); */ /* atomic_set */
15480 +/* ---------------------------------------------------------------------- */
15482 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15484 + struct au_fidir *fidir;
15487 + nbr = au_sbbot(sb) + 1;
15489 + nbr = 2; /* initial allocate for 2 branches */
15490 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15492 + fidir->fd_bbot = -1;
15493 + fidir->fd_nent = nbr;
15499 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15502 + struct au_fidir *fidir, *p;
15504 + AuRwMustWriteLock(&finfo->fi_rwsem);
15505 + fidir = finfo->fi_hdir;
15506 + AuDebugOn(!fidir);
15509 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15510 + GFP_NOFS, may_shrink);
15512 + p->fd_nent = nbr;
15513 + finfo->fi_hdir = p;
15520 +/* ---------------------------------------------------------------------- */
15522 +void au_finfo_fin(struct file *file)
15524 + struct au_finfo *finfo;
15526 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15528 + finfo = au_fi(file);
15529 + AuDebugOn(finfo->fi_hdir);
15530 + AuRwDestroy(&finfo->fi_rwsem);
15531 + au_cache_free_finfo(finfo);
15534 +void au_fi_init_once(void *_finfo)
15536 + struct au_finfo *finfo = _finfo;
15538 + au_rw_init(&finfo->fi_rwsem);
15541 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15544 + struct au_finfo *finfo;
15545 + struct dentry *dentry;
15548 + dentry = file->f_path.dentry;
15549 + finfo = au_cache_alloc_finfo();
15550 + if (unlikely(!finfo))
15554 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15555 + au_rw_write_lock(&finfo->fi_rwsem);
15556 + finfo->fi_btop = -1;
15557 + finfo->fi_hdir = fidir;
15558 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15559 + /* smp_mb(); */ /* atomic_set */
15561 + file->private_data = finfo;
15566 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15567 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15568 +++ linux/fs/aufs/f_op.c 2019-07-11 15:42:14.465571210 +0200
15570 +// SPDX-License-Identifier: GPL-2.0
15572 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15574 + * This program, aufs is free software; you can redistribute it and/or modify
15575 + * it under the terms of the GNU General Public License as published by
15576 + * the Free Software Foundation; either version 2 of the License, or
15577 + * (at your option) any later version.
15579 + * This program is distributed in the hope that it will be useful,
15580 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15581 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15582 + * GNU General Public License for more details.
15584 + * You should have received a copy of the GNU General Public License
15585 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15589 + * file and vm operations
15592 +#include <linux/aio.h>
15593 +#include <linux/fs_stack.h>
15594 +#include <linux/mman.h>
15595 +#include <linux/security.h>
15598 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15601 + aufs_bindex_t bindex;
15602 + struct dentry *dentry, *h_dentry;
15603 + struct au_finfo *finfo;
15604 + struct inode *h_inode;
15606 + FiMustWriteLock(file);
15609 + dentry = file->f_path.dentry;
15610 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15611 + finfo = au_fi(file);
15612 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15613 + atomic_set(&finfo->fi_mmapped, 0);
15614 + bindex = au_dbtop(dentry);
15616 + h_dentry = au_h_dptr(dentry, bindex);
15617 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15618 + if (unlikely(err))
15620 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15621 + if (IS_ERR(h_file)) {
15622 + err = PTR_ERR(h_file);
15626 + h_dentry = h_file->f_path.dentry;
15627 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15628 + if (unlikely(err))
15630 + /* br ref is already inc-ed */
15633 + if ((flags & __O_TMPFILE)
15634 + && !(flags & O_EXCL)) {
15635 + h_inode = file_inode(h_file);
15636 + spin_lock(&h_inode->i_lock);
15637 + h_inode->i_state |= I_LINKABLE;
15638 + spin_unlock(&h_inode->i_lock);
15640 + au_set_fbtop(file, bindex);
15641 + au_set_h_fptr(file, bindex, h_file);
15642 + au_update_figen(file);
15643 + /* todo: necessary? */
15644 + /* file->f_ra = h_file->f_ra; */
15650 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15651 + struct file *file)
15654 + struct super_block *sb;
15655 + struct au_do_open_args args = {
15656 + .open = au_do_open_nondir
15659 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15660 + file, vfsub_file_flags(file), file->f_mode);
15662 + sb = file->f_path.dentry->d_sb;
15663 + si_read_lock(sb, AuLock_FLUSH);
15664 + err = au_do_open(file, &args);
15665 + si_read_unlock(sb);
15669 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15671 + struct au_finfo *finfo;
15672 + aufs_bindex_t bindex;
15674 + finfo = au_fi(file);
15675 + au_hbl_del(&finfo->fi_hlist,
15676 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15677 + bindex = finfo->fi_btop;
15679 + au_set_h_fptr(file, bindex, NULL);
15681 + au_finfo_fin(file);
15685 +/* ---------------------------------------------------------------------- */
15687 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15690 + struct file *h_file;
15693 + h_file = au_hf_top(file);
15695 + err = vfsub_flush(h_file, id);
15699 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15701 + return au_do_flush(file, id, au_do_flush_nondir);
15704 +/* ---------------------------------------------------------------------- */
15706 + * read and write functions acquire [fdi]_rwsem once, but release before
15707 + * mmap_sem. This is because to stop a race condition between mmap(2).
15708 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15709 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15710 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15713 +/* Callers should call au_read_post() or fput() in the end */
15714 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15716 + struct file *h_file;
15719 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15721 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15722 + h_file = au_hf_top(file);
15723 + get_file(h_file);
15725 + fi_read_unlock(file);
15727 + h_file = ERR_PTR(err);
15732 +static void au_read_post(struct inode *inode, struct file *h_file)
15734 + /* update without lock, I don't think it a problem */
15735 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15739 +struct au_write_pre {
15741 + unsigned int lsc;
15745 + aufs_bindex_t btop;
15749 + * return with iinfo is write-locked
15750 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15753 +static struct file *au_write_pre(struct file *file, int do_ready,
15754 + struct au_write_pre *wpre)
15756 + struct file *h_file;
15757 + struct dentry *dentry;
15759 + unsigned int lsc;
15760 + struct au_pin pin;
15765 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15766 + h_file = ERR_PTR(err);
15767 + if (unlikely(err))
15770 + dentry = file->f_path.dentry;
15772 + err = au_ready_to_write(file, -1, &pin);
15773 + if (unlikely(err)) {
15774 + h_file = ERR_PTR(err);
15775 + di_write_unlock(dentry);
15780 + di_downgrade_lock(dentry, /*flags*/0);
15782 + wpre->btop = au_fbtop(file);
15783 + h_file = au_hf_top(file);
15784 + get_file(h_file);
15786 + wpre->blks = file_inode(h_file)->i_blocks;
15789 + di_read_unlock(dentry, /*flags*/0);
15792 + fi_write_unlock(file);
15797 +static void au_write_post(struct inode *inode, struct file *h_file,
15798 + struct au_write_pre *wpre, ssize_t written)
15800 + struct inode *h_inode;
15802 + au_cpup_attr_timesizes(inode);
15803 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15804 + h_inode = file_inode(h_file);
15805 + inode->i_mode = h_inode->i_mode;
15806 + ii_write_unlock(inode);
15807 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15809 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15810 + /*force*/h_inode->i_blocks > wpre->blks);
15814 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15818 + struct inode *inode;
15819 + struct file *h_file;
15820 + struct super_block *sb;
15822 + inode = file_inode(file);
15823 + sb = inode->i_sb;
15824 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15826 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15827 + err = PTR_ERR(h_file);
15828 + if (IS_ERR(h_file))
15831 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15832 + err = vfsub_read_u(h_file, buf, count, ppos);
15833 + /* todo: necessary? */
15834 + /* file->f_ra = h_file->f_ra; */
15835 + au_read_post(inode, h_file);
15838 + si_read_unlock(sb);
15843 + * todo: very ugly
15844 + * it locks both of i_mutex and si_rwsem for read in safe.
15845 + * if the plink maintenance mode continues forever (that is the problem),
15846 + * may loop forever.
15848 +static void au_mtx_and_read_lock(struct inode *inode)
15851 + struct super_block *sb = inode->i_sb;
15854 + inode_lock(inode);
15855 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15858 + inode_unlock(inode);
15859 + si_read_lock(sb, AuLock_NOPLMW);
15860 + si_read_unlock(sb);
15864 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15865 + size_t count, loff_t *ppos)
15868 + struct au_write_pre wpre;
15869 + struct inode *inode;
15870 + struct file *h_file;
15871 + char __user *buf = (char __user *)ubuf;
15873 + inode = file_inode(file);
15874 + au_mtx_and_read_lock(inode);
15877 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15878 + err = PTR_ERR(h_file);
15879 + if (IS_ERR(h_file))
15882 + err = vfsub_write_u(h_file, buf, count, ppos);
15883 + au_write_post(inode, h_file, &wpre, err);
15886 + si_read_unlock(inode->i_sb);
15887 + inode_unlock(inode);
15891 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15892 + struct iov_iter *iov_iter)
15895 + struct file *file;
15896 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15898 + err = security_file_permission(h_file, rw);
15899 + if (unlikely(err))
15904 + if (rw == MAY_READ)
15905 + iter = h_file->f_op->read_iter;
15906 + else if (rw == MAY_WRITE)
15907 + iter = h_file->f_op->write_iter;
15909 + file = kio->ki_filp;
15910 + kio->ki_filp = h_file;
15913 + err = iter(kio, iov_iter);
15916 + /* currently there is no such fs */
15918 + kio->ki_filp = file;
15924 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15927 + struct file *file, *h_file;
15928 + struct inode *inode;
15929 + struct super_block *sb;
15931 + file = kio->ki_filp;
15932 + inode = file_inode(file);
15933 + sb = inode->i_sb;
15934 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15936 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15937 + err = PTR_ERR(h_file);
15938 + if (IS_ERR(h_file))
15941 + if (au_test_loopback_kthread()) {
15942 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15943 + if (file->f_mapping != h_file->f_mapping) {
15944 + file->f_mapping = h_file->f_mapping;
15945 + smp_mb(); /* unnecessary? */
15948 + fi_read_unlock(file);
15950 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15951 + /* todo: necessary? */
15952 + /* file->f_ra = h_file->f_ra; */
15953 + au_read_post(inode, h_file);
15956 + si_read_unlock(sb);
15960 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15963 + struct au_write_pre wpre;
15964 + struct inode *inode;
15965 + struct file *file, *h_file;
15967 + file = kio->ki_filp;
15968 + inode = file_inode(file);
15969 + au_mtx_and_read_lock(inode);
15972 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15973 + err = PTR_ERR(h_file);
15974 + if (IS_ERR(h_file))
15977 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15978 + au_write_post(inode, h_file, &wpre, err);
15981 + si_read_unlock(inode->i_sb);
15982 + inode_unlock(inode);
15986 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15987 + struct pipe_inode_info *pipe, size_t len,
15988 + unsigned int flags)
15991 + struct file *h_file;
15992 + struct inode *inode;
15993 + struct super_block *sb;
15995 + inode = file_inode(file);
15996 + sb = inode->i_sb;
15997 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15999 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16000 + err = PTR_ERR(h_file);
16001 + if (IS_ERR(h_file))
16004 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16005 + /* todo: necessary? */
16006 + /* file->f_ra = h_file->f_ra; */
16007 + au_read_post(inode, h_file);
16010 + si_read_unlock(sb);
16015 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16016 + size_t len, unsigned int flags)
16019 + struct au_write_pre wpre;
16020 + struct inode *inode;
16021 + struct file *h_file;
16023 + inode = file_inode(file);
16024 + au_mtx_and_read_lock(inode);
16027 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16028 + err = PTR_ERR(h_file);
16029 + if (IS_ERR(h_file))
16032 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16033 + au_write_post(inode, h_file, &wpre, err);
16036 + si_read_unlock(inode->i_sb);
16037 + inode_unlock(inode);
16041 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16045 + struct au_write_pre wpre;
16046 + struct inode *inode;
16047 + struct file *h_file;
16049 + inode = file_inode(file);
16050 + au_mtx_and_read_lock(inode);
16053 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16054 + err = PTR_ERR(h_file);
16055 + if (IS_ERR(h_file))
16059 + err = vfs_fallocate(h_file, mode, offset, len);
16061 + au_write_post(inode, h_file, &wpre, /*written*/1);
16064 + si_read_unlock(inode->i_sb);
16065 + inode_unlock(inode);
16069 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16070 + struct file *dst, loff_t dst_pos,
16071 + size_t len, unsigned int flags)
16074 + struct au_write_pre wpre;
16075 + enum { SRC, DST };
16077 + struct inode *inode;
16078 + struct file *h_file;
16079 + struct super_block *h_sb;
16081 +#define a_src a[SRC]
16082 +#define a_dst a[DST]
16085 + a_src.inode = file_inode(src);
16086 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16088 + a_dst.inode = file_inode(dst);
16089 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16092 + au_mtx_and_read_lock(a_dst.inode);
16094 + * in order to match the order in di_write_lock2_{child,parent}(),
16095 + * use f_path.dentry for this comparison.
16097 + if (src->f_path.dentry < dst->f_path.dentry) {
16098 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16099 + err = PTR_ERR(a_src.h_file);
16100 + if (IS_ERR(a_src.h_file))
16103 + wpre.lsc = AuLsc_FI_2;
16104 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16105 + err = PTR_ERR(a_dst.h_file);
16106 + if (IS_ERR(a_dst.h_file)) {
16107 + au_read_post(a_src.inode, a_src.h_file);
16111 + wpre.lsc = AuLsc_FI_1;
16112 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16113 + err = PTR_ERR(a_dst.h_file);
16114 + if (IS_ERR(a_dst.h_file))
16117 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16118 + err = PTR_ERR(a_src.h_file);
16119 + if (IS_ERR(a_src.h_file)) {
16120 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16127 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16128 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16129 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16135 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16136 + dst_pos, len, flags);
16139 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16140 + fi_read_unlock(src);
16141 + au_read_post(a_src.inode, a_src.h_file);
16143 + si_read_unlock(a_dst.inode->i_sb);
16144 + inode_unlock(a_dst.inode);
16151 +/* ---------------------------------------------------------------------- */
16154 + * The locking order around current->mmap_sem.
16155 + * - in most and regular cases
16156 + * file I/O syscall -- aufs_read() or something
16157 + * -- si_rwsem for read -- mmap_sem
16158 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16160 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16161 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16162 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16163 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16164 + * It means that when aufs acquires si_rwsem for write, the process should never
16165 + * acquire mmap_sem.
16167 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16168 + * problem either since any directory is not able to be mmap-ed.
16169 + * The similar scenario is applied to aufs_readlink() too.
16172 +#if 0 /* stop calling security_file_mmap() */
16173 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16174 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16176 +static unsigned long au_arch_prot_conv(unsigned long flags)
16178 + /* currently ppc64 only */
16179 +#ifdef CONFIG_PPC64
16180 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16181 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16182 + return AuConv_VM_PROT(flags, SAO);
16184 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16189 +static unsigned long au_prot_conv(unsigned long flags)
16191 + return AuConv_VM_PROT(flags, READ)
16192 + | AuConv_VM_PROT(flags, WRITE)
16193 + | AuConv_VM_PROT(flags, EXEC)
16194 + | au_arch_prot_conv(flags);
16197 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16198 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16200 +static unsigned long au_flag_conv(unsigned long flags)
16202 + return AuConv_VM_MAP(flags, GROWSDOWN)
16203 + | AuConv_VM_MAP(flags, DENYWRITE)
16204 + | AuConv_VM_MAP(flags, LOCKED);
16208 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16211 + const unsigned char wlock
16212 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16213 + struct super_block *sb;
16214 + struct file *h_file;
16215 + struct inode *inode;
16217 + AuDbgVmRegion(file, vma);
16219 + inode = file_inode(file);
16220 + sb = inode->i_sb;
16222 + si_read_lock(sb, AuLock_NOPLMW);
16224 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16226 + err = PTR_ERR(h_file);
16227 + if (IS_ERR(h_file))
16231 + au_set_mmapped(file);
16232 + au_vm_file_reset(vma, h_file);
16234 + * we cannot call security_mmap_file() here since it may acquire
16235 + * mmap_sem or i_mutex.
16237 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16238 + * au_flag_conv(vma->vm_flags));
16241 + err = call_mmap(h_file, vma);
16243 + au_vm_prfile_set(vma, file);
16244 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16245 + goto out_fput; /* success */
16247 + au_unset_mmapped(file);
16248 + au_vm_file_reset(vma, file);
16252 + ii_write_unlock(inode);
16257 + si_read_unlock(sb);
16263 +/* ---------------------------------------------------------------------- */
16265 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16269 + struct au_write_pre wpre;
16270 + struct inode *inode;
16271 + struct file *h_file;
16273 + err = 0; /* -EBADF; */ /* posix? */
16274 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16277 + inode = file_inode(file);
16278 + au_mtx_and_read_lock(inode);
16281 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16282 + err = PTR_ERR(h_file);
16283 + if (IS_ERR(h_file))
16286 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16287 + au_write_post(inode, h_file, &wpre, /*written*/0);
16290 + si_read_unlock(inode->i_sb);
16291 + inode_unlock(inode);
16296 +static int aufs_fasync(int fd, struct file *file, int flag)
16299 + struct file *h_file;
16300 + struct super_block *sb;
16302 + sb = file->f_path.dentry->d_sb;
16303 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16305 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16306 + err = PTR_ERR(h_file);
16307 + if (IS_ERR(h_file))
16310 + if (h_file->f_op->fasync)
16311 + err = h_file->f_op->fasync(fd, h_file, flag);
16312 + fput(h_file); /* instead of au_read_post() */
16315 + si_read_unlock(sb);
16319 +static int aufs_setfl(struct file *file, unsigned long arg)
16322 + struct file *h_file;
16323 + struct super_block *sb;
16325 + sb = file->f_path.dentry->d_sb;
16326 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16328 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16329 + err = PTR_ERR(h_file);
16330 + if (IS_ERR(h_file))
16333 + /* stop calling h_file->fasync */
16334 + arg |= vfsub_file_flags(file) & FASYNC;
16335 + err = setfl(/*unused fd*/-1, h_file, arg);
16336 + fput(h_file); /* instead of au_read_post() */
16339 + si_read_unlock(sb);
16343 +/* ---------------------------------------------------------------------- */
16345 +/* no one supports this operation, currently */
16347 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16348 + size_t len, loff_t *pos, int more)
16353 +/* ---------------------------------------------------------------------- */
16355 +const struct file_operations aufs_file_fop = {
16356 + .owner = THIS_MODULE,
16358 + .llseek = default_llseek,
16360 + .read = aufs_read,
16361 + .write = aufs_write,
16362 + .read_iter = aufs_read_iter,
16363 + .write_iter = aufs_write_iter,
16365 +#ifdef CONFIG_AUFS_POLL
16366 + .poll = aufs_poll,
16368 + .unlocked_ioctl = aufs_ioctl_nondir,
16369 +#ifdef CONFIG_COMPAT
16370 + .compat_ioctl = aufs_compat_ioctl_nondir,
16372 + .mmap = aufs_mmap,
16373 + .open = aufs_open_nondir,
16374 + .flush = aufs_flush_nondir,
16375 + .release = aufs_release_nondir,
16376 + .fsync = aufs_fsync_nondir,
16377 + .fasync = aufs_fasync,
16378 + /* .sendpage = aufs_sendpage, */
16379 + .setfl = aufs_setfl,
16380 + .splice_write = aufs_splice_write,
16381 + .splice_read = aufs_splice_read,
16383 + .aio_splice_write = aufs_aio_splice_write,
16384 + .aio_splice_read = aufs_aio_splice_read,
16386 + .fallocate = aufs_fallocate,
16387 + .copy_file_range = aufs_copy_file_range
16389 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16390 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16391 +++ linux/fs/aufs/fstype.h 2019-07-11 15:42:14.465571210 +0200
16393 +/* SPDX-License-Identifier: GPL-2.0 */
16395 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16397 + * This program, aufs is free software; you can redistribute it and/or modify
16398 + * it under the terms of the GNU General Public License as published by
16399 + * the Free Software Foundation; either version 2 of the License, or
16400 + * (at your option) any later version.
16402 + * This program is distributed in the hope that it will be useful,
16403 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16404 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16405 + * GNU General Public License for more details.
16407 + * You should have received a copy of the GNU General Public License
16408 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16412 + * judging filesystem type
16415 +#ifndef __AUFS_FSTYPE_H__
16416 +#define __AUFS_FSTYPE_H__
16420 +#include <linux/fs.h>
16421 +#include <linux/magic.h>
16422 +#include <linux/nfs_fs.h>
16423 +#include <linux/romfs_fs.h>
16425 +static inline int au_test_aufs(struct super_block *sb)
16427 + return sb->s_magic == AUFS_SUPER_MAGIC;
16430 +static inline const char *au_sbtype(struct super_block *sb)
16432 + return sb->s_type->name;
16435 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16437 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16438 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16444 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16446 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16447 + return sb->s_magic == ROMFS_MAGIC;
16453 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16455 +#if IS_ENABLED(CONFIG_CRAMFS)
16456 + return sb->s_magic == CRAMFS_MAGIC;
16461 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16463 +#if IS_ENABLED(CONFIG_NFS_FS)
16464 + return sb->s_magic == NFS_SUPER_MAGIC;
16470 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16472 +#if IS_ENABLED(CONFIG_FUSE_FS)
16473 + return sb->s_magic == FUSE_SUPER_MAGIC;
16479 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16481 +#if IS_ENABLED(CONFIG_XFS_FS)
16482 + return sb->s_magic == XFS_SB_MAGIC;
16488 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16490 +#ifdef CONFIG_TMPFS
16491 + return sb->s_magic == TMPFS_MAGIC;
16497 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16499 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16500 + return !strcmp(au_sbtype(sb), "ecryptfs");
16506 +static inline int au_test_ramfs(struct super_block *sb)
16508 + return sb->s_magic == RAMFS_MAGIC;
16511 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16513 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16514 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16520 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16522 +#ifdef CONFIG_PROC_FS
16523 + return sb->s_magic == PROC_SUPER_MAGIC;
16529 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16531 +#ifdef CONFIG_SYSFS
16532 + return sb->s_magic == SYSFS_MAGIC;
16538 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16540 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16541 + return sb->s_magic == CONFIGFS_MAGIC;
16547 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16549 +#if IS_ENABLED(CONFIG_MINIX_FS)
16550 + return sb->s_magic == MINIX3_SUPER_MAGIC
16551 + || sb->s_magic == MINIX2_SUPER_MAGIC
16552 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16553 + || sb->s_magic == MINIX_SUPER_MAGIC
16554 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16560 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16562 +#if IS_ENABLED(CONFIG_FAT_FS)
16563 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16569 +static inline int au_test_msdos(struct super_block *sb)
16571 + return au_test_fat(sb);
16574 +static inline int au_test_vfat(struct super_block *sb)
16576 + return au_test_fat(sb);
16579 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16581 +#ifdef CONFIG_SECURITYFS
16582 + return sb->s_magic == SECURITYFS_MAGIC;
16588 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16590 +#if IS_ENABLED(CONFIG_SQUASHFS)
16591 + return sb->s_magic == SQUASHFS_MAGIC;
16597 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16599 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16600 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16606 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16608 +#if IS_ENABLED(CONFIG_XENFS)
16609 + return sb->s_magic == XENFS_SUPER_MAGIC;
16615 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16617 +#ifdef CONFIG_DEBUG_FS
16618 + return sb->s_magic == DEBUGFS_MAGIC;
16624 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16626 +#if IS_ENABLED(CONFIG_NILFS)
16627 + return sb->s_magic == NILFS_SUPER_MAGIC;
16633 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16635 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16636 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16642 +/* ---------------------------------------------------------------------- */
16644 + * they can't be an aufs branch.
16646 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16649 +#ifndef CONFIG_AUFS_BR_RAMFS
16650 + au_test_ramfs(sb) ||
16652 + au_test_procfs(sb)
16653 + || au_test_sysfs(sb)
16654 + || au_test_configfs(sb)
16655 + || au_test_debugfs(sb)
16656 + || au_test_securityfs(sb)
16657 + || au_test_xenfs(sb)
16658 + || au_test_ecryptfs(sb)
16659 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16660 + || au_test_aufs(sb); /* will be supported in next version */
16663 +static inline int au_test_fs_remote(struct super_block *sb)
16665 + return !au_test_tmpfs(sb)
16666 +#ifdef CONFIG_AUFS_BR_RAMFS
16667 + && !au_test_ramfs(sb)
16669 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16672 +/* ---------------------------------------------------------------------- */
16675 + * Note: these functions (below) are created after reading ->getattr() in all
16676 + * filesystems under linux/fs. it means we have to do so in every update...
16680 + * some filesystems require getattr to refresh the inode attributes before
16682 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16683 + * and leave the work for d_revalidate()
16685 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16687 + return au_test_nfs(sb)
16688 + || au_test_fuse(sb)
16689 + /* || au_test_btrfs(sb) */ /* untested */
16694 + * filesystems which don't maintain i_size or i_blocks.
16696 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16698 + return au_test_xfs(sb)
16699 + || au_test_btrfs(sb)
16700 + || au_test_ubifs(sb)
16701 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16702 + /* || au_test_minix(sb) */ /* untested */
16707 + * filesystems which don't store the correct value in some of their inode
16710 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16712 + return au_test_fs_bad_iattr_size(sb)
16713 + || au_test_fat(sb)
16714 + || au_test_msdos(sb)
16715 + || au_test_vfat(sb);
16718 +/* they don't check i_nlink in link(2) */
16719 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16721 + return au_test_tmpfs(sb)
16722 +#ifdef CONFIG_AUFS_BR_RAMFS
16723 + || au_test_ramfs(sb)
16725 + || au_test_ubifs(sb)
16726 + || au_test_hfsplus(sb);
16730 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16732 +static inline int au_test_fs_notime(struct super_block *sb)
16734 + return au_test_nfs(sb)
16735 + || au_test_fuse(sb)
16736 + || au_test_ubifs(sb)
16740 +/* temporary support for i#1 in cramfs */
16741 +static inline int au_test_fs_unique_ino(struct inode *inode)
16743 + if (au_test_cramfs(inode->i_sb))
16744 + return inode->i_ino != 1;
16748 +/* ---------------------------------------------------------------------- */
16751 + * the filesystem where the xino files placed must support i/o after unlink and
16752 + * maintain i_size and i_blocks.
16754 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16756 + return au_test_fs_remote(sb)
16757 + || au_test_fs_bad_iattr_size(sb)
16758 + /* don't want unnecessary work for xino */
16759 + || au_test_aufs(sb)
16760 + || au_test_ecryptfs(sb)
16761 + || au_test_nilfs(sb);
16764 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16766 + return au_test_tmpfs(sb)
16767 + || au_test_ramfs(sb);
16771 + * test if the @sb is real-readonly.
16773 +static inline int au_test_fs_rr(struct super_block *sb)
16775 + return au_test_squashfs(sb)
16776 + || au_test_iso9660(sb)
16777 + || au_test_cramfs(sb)
16778 + || au_test_romfs(sb);
16782 + * test if the @inode is nfs with 'noacl' option
16783 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16785 +static inline int au_test_nfs_noacl(struct inode *inode)
16787 + return au_test_nfs(inode->i_sb)
16788 + /* && IS_POSIXACL(inode) */
16789 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16792 +#endif /* __KERNEL__ */
16793 +#endif /* __AUFS_FSTYPE_H__ */
16794 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16795 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16796 +++ linux/fs/aufs/hbl.h 2019-07-11 15:42:14.465571210 +0200
16798 +/* SPDX-License-Identifier: GPL-2.0 */
16800 + * Copyright (C) 2017-2019 Junjiro R. Okajima
16802 + * This program, aufs is free software; you can redistribute it and/or modify
16803 + * it under the terms of the GNU General Public License as published by
16804 + * the Free Software Foundation; either version 2 of the License, or
16805 + * (at your option) any later version.
16807 + * This program is distributed in the hope that it will be useful,
16808 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16809 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16810 + * GNU General Public License for more details.
16812 + * You should have received a copy of the GNU General Public License
16813 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16817 + * helpers for hlist_bl.h
16820 +#ifndef __AUFS_HBL_H__
16821 +#define __AUFS_HBL_H__
16825 +#include <linux/list_bl.h>
16827 +static inline void au_hbl_add(struct hlist_bl_node *node,
16828 + struct hlist_bl_head *hbl)
16830 + hlist_bl_lock(hbl);
16831 + hlist_bl_add_head(node, hbl);
16832 + hlist_bl_unlock(hbl);
16835 +static inline void au_hbl_del(struct hlist_bl_node *node,
16836 + struct hlist_bl_head *hbl)
16838 + hlist_bl_lock(hbl);
16839 + hlist_bl_del(node);
16840 + hlist_bl_unlock(hbl);
16843 +#define au_hbl_for_each(pos, head) \
16844 + for (pos = hlist_bl_first(head); \
16848 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16850 + unsigned long cnt;
16851 + struct hlist_bl_node *pos;
16854 + hlist_bl_lock(hbl);
16855 + au_hbl_for_each(pos, hbl)
16857 + hlist_bl_unlock(hbl);
16861 +#endif /* __KERNEL__ */
16862 +#endif /* __AUFS_HBL_H__ */
16863 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16864 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16865 +++ linux/fs/aufs/hfsnotify.c 2019-07-11 15:42:14.465571210 +0200
16867 +// SPDX-License-Identifier: GPL-2.0
16869 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16871 + * This program, aufs is free software; you can redistribute it and/or modify
16872 + * it under the terms of the GNU General Public License as published by
16873 + * the Free Software Foundation; either version 2 of the License, or
16874 + * (at your option) any later version.
16876 + * This program is distributed in the hope that it will be useful,
16877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16879 + * GNU General Public License for more details.
16881 + * You should have received a copy of the GNU General Public License
16882 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16886 + * fsnotify for the lower directories
16891 +/* FS_IN_IGNORED is unnecessary */
16892 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16893 + | FS_CREATE | FS_EVENT_ON_CHILD);
16894 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16895 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16897 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16899 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16901 + /* AuDbg("here\n"); */
16902 + au_cache_free_hnotify(hn);
16903 + smp_mb__before_atomic(); /* for atomic64_dec */
16904 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16905 + wake_up(&au_hfsn_wq);
16908 +static int au_hfsn_alloc(struct au_hinode *hinode)
16911 + struct au_hnotify *hn;
16912 + struct super_block *sb;
16913 + struct au_branch *br;
16914 + struct fsnotify_mark *mark;
16915 + aufs_bindex_t bindex;
16917 + hn = hinode->hi_notify;
16918 + sb = hn->hn_aufs_inode->i_sb;
16919 + bindex = au_br_index(sb, hinode->hi_id);
16920 + br = au_sbr(sb, bindex);
16921 + AuDebugOn(!br->br_hfsn);
16923 + mark = &hn->hn_mark;
16924 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16925 + mark->mask = AuHfsnMask;
16927 + * by udba rename or rmdir, aufs assign a new inode to the known
16928 + * h_inode, so specify 1 to allow dups.
16931 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16937 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16939 + struct fsnotify_mark *mark;
16940 + unsigned long long ull;
16941 + struct fsnotify_group *group;
16943 + ull = atomic64_inc_return(&au_hfsn_ifree);
16946 + mark = &hn->hn_mark;
16947 + spin_lock(&mark->lock);
16948 + group = mark->group;
16949 + fsnotify_get_group(group);
16950 + spin_unlock(&mark->lock);
16952 + fsnotify_destroy_mark(mark, group);
16953 + fsnotify_put_mark(mark);
16954 + fsnotify_put_group(group);
16957 + /* free hn by myself */
16961 +/* ---------------------------------------------------------------------- */
16963 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16965 + struct fsnotify_mark *mark;
16967 + mark = &hinode->hi_notify->hn_mark;
16968 + spin_lock(&mark->lock);
16970 + AuDebugOn(mark->mask & AuHfsnMask);
16971 + mark->mask |= AuHfsnMask;
16973 + AuDebugOn(!(mark->mask & AuHfsnMask));
16974 + mark->mask &= ~AuHfsnMask;
16976 + spin_unlock(&mark->lock);
16977 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16980 +/* ---------------------------------------------------------------------- */
16982 +/* #define AuDbgHnotify */
16983 +#ifdef AuDbgHnotify
16984 +static char *au_hfsn_name(u32 mask)
16986 +#ifdef CONFIG_AUFS_DEBUG
16987 +#define test_ret(flag) \
16989 + if (mask & flag) \
16992 + test_ret(FS_ACCESS);
16993 + test_ret(FS_MODIFY);
16994 + test_ret(FS_ATTRIB);
16995 + test_ret(FS_CLOSE_WRITE);
16996 + test_ret(FS_CLOSE_NOWRITE);
16997 + test_ret(FS_OPEN);
16998 + test_ret(FS_MOVED_FROM);
16999 + test_ret(FS_MOVED_TO);
17000 + test_ret(FS_CREATE);
17001 + test_ret(FS_DELETE);
17002 + test_ret(FS_DELETE_SELF);
17003 + test_ret(FS_MOVE_SELF);
17004 + test_ret(FS_UNMOUNT);
17005 + test_ret(FS_Q_OVERFLOW);
17006 + test_ret(FS_IN_IGNORED);
17007 + test_ret(FS_ISDIR);
17008 + test_ret(FS_IN_ONESHOT);
17009 + test_ret(FS_EVENT_ON_CHILD);
17018 +/* ---------------------------------------------------------------------- */
17020 +static void au_hfsn_free_group(struct fsnotify_group *group)
17022 + struct au_br_hfsnotify *hfsn = group->private;
17024 + /* AuDbg("here\n"); */
17025 + au_kfree_try_rcu(hfsn);
17028 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17029 + struct inode *inode,
17030 + u32 mask, const void *data, int data_type,
17031 + const struct qstr *file_name, u32 cookie,
17032 + struct fsnotify_iter_info *iter_info)
17035 + struct au_hnotify *hnotify;
17036 + struct inode *h_dir, *h_inode;
17037 + struct fsnotify_mark *inode_mark;
17039 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17042 + /* if FS_UNMOUNT happens, there must be another bug */
17043 + AuDebugOn(mask & FS_UNMOUNT);
17044 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17049 +#ifdef AuDbgHnotify
17051 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17052 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17053 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17054 + h_dir->i_ino, mask, au_hfsn_name(mask),
17055 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17056 + /* WARN_ON(1); */
17061 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17062 + AuDebugOn(!inode_mark);
17063 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17064 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
17070 +static struct fsnotify_ops au_hfsn_ops = {
17071 + .handle_event = au_hfsn_handle_event,
17072 + .free_group_priv = au_hfsn_free_group,
17073 + .free_mark = au_hfsn_free_mark
17076 +/* ---------------------------------------------------------------------- */
17078 +static void au_hfsn_fin_br(struct au_branch *br)
17080 + struct au_br_hfsnotify *hfsn;
17082 + hfsn = br->br_hfsn;
17085 + fsnotify_put_group(hfsn->hfsn_group);
17090 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17093 + struct fsnotify_group *group;
17094 + struct au_br_hfsnotify *hfsn;
17097 + br->br_hfsn = NULL;
17098 + if (!au_br_hnotifyable(perm))
17102 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17103 + if (unlikely(!hfsn))
17107 + group = fsnotify_alloc_group(&au_hfsn_ops);
17108 + if (IS_ERR(group)) {
17109 + err = PTR_ERR(group);
17110 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17114 + group->private = hfsn;
17115 + hfsn->hfsn_group = group;
17116 + br->br_hfsn = hfsn;
17117 + goto out; /* success */
17120 + au_kfree_try_rcu(hfsn);
17125 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17130 + if (!br->br_hfsn)
17131 + err = au_hfsn_init_br(br, perm);
17136 +/* ---------------------------------------------------------------------- */
17138 +static void au_hfsn_fin(void)
17140 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17141 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17144 +const struct au_hnotify_op au_hnotify_op = {
17145 + .ctl = au_hfsn_ctl,
17146 + .alloc = au_hfsn_alloc,
17147 + .free = au_hfsn_free,
17149 + .fin = au_hfsn_fin,
17151 + .reset_br = au_hfsn_reset_br,
17152 + .fin_br = au_hfsn_fin_br,
17153 + .init_br = au_hfsn_init_br
17155 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17156 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17157 +++ linux/fs/aufs/hfsplus.c 2019-07-11 15:42:14.465571210 +0200
17159 +// SPDX-License-Identifier: GPL-2.0
17161 + * Copyright (C) 2010-2019 Junjiro R. Okajima
17163 + * This program, aufs is free software; you can redistribute it and/or modify
17164 + * it under the terms of the GNU General Public License as published by
17165 + * the Free Software Foundation; either version 2 of the License, or
17166 + * (at your option) any later version.
17168 + * This program is distributed in the hope that it will be useful,
17169 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17170 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17171 + * GNU General Public License for more details.
17173 + * You should have received a copy of the GNU General Public License
17174 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17178 + * special support for filesystems which acquires an inode mutex
17179 + * at final closing a file, eg, hfsplus.
17181 + * This trick is very simple and stupid, just to open the file before really
17182 + * necessary open to tell hfsplus that this is not the final closing.
17183 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17184 + * and au_h_open_post() after releasing it.
17189 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17192 + struct file *h_file;
17193 + struct dentry *h_dentry;
17195 + h_dentry = au_h_dptr(dentry, bindex);
17196 + AuDebugOn(!h_dentry);
17197 + AuDebugOn(d_is_negative(h_dentry));
17200 + if (au_test_hfsplus(h_dentry->d_sb)
17201 + && d_is_reg(h_dentry))
17202 + h_file = au_h_open(dentry, bindex,
17203 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17204 + /*file*/NULL, force_wr);
17208 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17209 + struct file *h_file)
17211 + struct au_branch *br;
17215 + br = au_sbr(dentry->d_sb, bindex);
17216 + au_lcnt_dec(&br->br_nfiles);
17219 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17220 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17221 +++ linux/fs/aufs/hnotify.c 2019-07-11 15:42:14.465571210 +0200
17223 +// SPDX-License-Identifier: GPL-2.0
17225 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17227 + * This program, aufs is free software; you can redistribute it and/or modify
17228 + * it under the terms of the GNU General Public License as published by
17229 + * the Free Software Foundation; either version 2 of the License, or
17230 + * (at your option) any later version.
17232 + * This program is distributed in the hope that it will be useful,
17233 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17234 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17235 + * GNU General Public License for more details.
17237 + * You should have received a copy of the GNU General Public License
17238 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17242 + * abstraction to notify the direct changes on lower directories
17245 +/* #include <linux/iversion.h> */
17248 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17251 + struct au_hnotify *hn;
17254 + hn = au_cache_alloc_hnotify();
17256 + hn->hn_aufs_inode = inode;
17257 + hinode->hi_notify = hn;
17258 + err = au_hnotify_op.alloc(hinode);
17260 + if (unlikely(err)) {
17261 + hinode->hi_notify = NULL;
17262 + au_cache_free_hnotify(hn);
17264 + * The upper dir was removed by udba, but the same named
17265 + * dir left. In this case, aufs assigns a new inode
17266 + * number and set the monitor again.
17267 + * For the lower dir, the old monitor is still left.
17269 + if (err == -EEXIST)
17278 +void au_hn_free(struct au_hinode *hinode)
17280 + struct au_hnotify *hn;
17282 + hn = hinode->hi_notify;
17284 + hinode->hi_notify = NULL;
17285 + if (au_hnotify_op.free(hinode, hn))
17286 + au_cache_free_hnotify(hn);
17290 +/* ---------------------------------------------------------------------- */
17292 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17294 + if (hinode->hi_notify)
17295 + au_hnotify_op.ctl(hinode, do_set);
17298 +void au_hn_reset(struct inode *inode, unsigned int flags)
17300 + aufs_bindex_t bindex, bbot;
17301 + struct inode *hi;
17302 + struct dentry *iwhdentry;
17304 + bbot = au_ibbot(inode);
17305 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17306 + hi = au_h_iptr(inode, bindex);
17310 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17311 + iwhdentry = au_hi_wh(inode, bindex);
17315 + au_set_h_iptr(inode, bindex, NULL, 0);
17316 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17317 + flags & ~AuHi_XINO);
17320 + /* inode_unlock(hi); */
17324 +/* ---------------------------------------------------------------------- */
17326 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17329 + aufs_bindex_t bindex, bbot, bfound, btop;
17330 + struct inode *h_i;
17333 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17334 + pr_warn("branch root dir was changed\n");
17339 + bbot = au_ibbot(inode);
17340 + btop = au_ibtop(inode);
17341 +#if 0 /* reserved for future use */
17342 + if (bindex == bbot) {
17343 + /* keep this ino in rename case */
17347 + for (bindex = btop; bindex <= bbot; bindex++)
17348 + if (au_h_iptr(inode, bindex) == h_inode) {
17355 + for (bindex = btop; bindex <= bbot; bindex++) {
17356 + h_i = au_h_iptr(inode, bindex);
17360 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17361 + /* ignore this error */
17362 + /* bad action? */
17365 + /* children inode number will be broken */
17372 +static int hn_gen_tree(struct dentry *dentry)
17374 + int err, i, j, ndentry;
17375 + struct au_dcsub_pages dpages;
17376 + struct au_dpage *dpage;
17377 + struct dentry **dentries;
17379 + err = au_dpages_init(&dpages, GFP_NOFS);
17380 + if (unlikely(err))
17382 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17383 + if (unlikely(err))
17386 + for (i = 0; i < dpages.ndpage; i++) {
17387 + dpage = dpages.dpages + i;
17388 + dentries = dpage->dentries;
17389 + ndentry = dpage->ndentry;
17390 + for (j = 0; j < ndentry; j++) {
17391 + struct dentry *d;
17398 + if (d_really_is_positive(d))
17399 + /* todo: reset children xino?
17400 + cached children only? */
17401 + au_iigen_dec(d_inode(d));
17406 + au_dpages_free(&dpages);
17409 + /* discard children */
17410 + dentry_unhash(dentry);
17418 + * return 0 if processed.
17420 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17421 + const unsigned int isdir)
17424 + struct dentry *d;
17425 + struct qstr *dname;
17428 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17429 + pr_warn("branch root dir was changed\n");
17435 + AuDebugOn(!name);
17436 + au_iigen_dec(inode);
17437 + spin_lock(&inode->i_lock);
17438 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17439 + spin_lock(&d->d_lock);
17440 + dname = &d->d_name;
17441 + if (dname->len != nlen
17442 + && memcmp(dname->name, name, nlen)) {
17443 + spin_unlock(&d->d_lock);
17448 + spin_unlock(&d->d_lock);
17451 + spin_unlock(&inode->i_lock);
17453 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17454 + d = d_find_any_alias(inode);
17456 + au_iigen_dec(inode);
17460 + spin_lock(&d->d_lock);
17461 + dname = &d->d_name;
17462 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17463 + spin_unlock(&d->d_lock);
17464 + err = hn_gen_tree(d);
17465 + spin_lock(&d->d_lock);
17467 + spin_unlock(&d->d_lock);
17476 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17480 + if (IS_ROOT(dentry)) {
17481 + pr_warn("branch root dir was changed\n");
17487 + au_digen_dec(dentry);
17488 + if (d_really_is_positive(dentry))
17489 + au_iigen_dec(d_inode(dentry));
17491 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17492 + if (d_really_is_positive(dentry))
17493 + err = hn_gen_tree(dentry);
17500 +/* ---------------------------------------------------------------------- */
17502 +/* hnotify job flags */
17503 +#define AuHnJob_XINO0 1
17504 +#define AuHnJob_GEN (1 << 1)
17505 +#define AuHnJob_DIRENT (1 << 2)
17506 +#define AuHnJob_ISDIR (1 << 3)
17507 +#define AuHnJob_TRYXINO0 (1 << 4)
17508 +#define AuHnJob_MNTPNT (1 << 5)
17509 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17510 +#define au_fset_hnjob(flags, name) \
17511 + do { (flags) |= AuHnJob_##name; } while (0)
17512 +#define au_fclr_hnjob(flags, name) \
17513 + do { (flags) &= ~AuHnJob_##name; } while (0)
17521 +struct au_hnotify_args {
17522 + struct inode *h_dir, *dir, *h_child_inode;
17524 + unsigned int flags[AuHnLast];
17525 + unsigned int h_child_nlen;
17526 + char h_child_name[];
17529 +struct hn_job_args {
17530 + unsigned int flags;
17531 + struct inode *inode, *h_inode, *dir, *h_dir;
17532 + struct dentry *dentry;
17537 +static int hn_job(struct hn_job_args *a)
17539 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17543 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17544 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17546 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17549 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17550 + if (!a->h_inode->i_nlink
17551 + && !(a->h_inode->i_state & I_LINKABLE))
17552 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17553 + inode_unlock_shared(a->h_inode);
17556 + /* make the generation obsolete */
17557 + if (au_ftest_hnjob(a->flags, GEN)) {
17560 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17562 + if (e && a->dentry)
17563 + hn_gen_by_name(a->dentry, isdir);
17564 + /* ignore this error */
17567 + /* make dir entries obsolete */
17568 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17569 + struct au_vdir *vdir;
17571 + vdir = au_ivdir(a->inode);
17573 + vdir->vd_jiffy = 0;
17574 + /* IMustLock(a->inode); */
17575 + /* inode_inc_iversion(a->inode); */
17578 + /* can do nothing but warn */
17579 + if (au_ftest_hnjob(a->flags, MNTPNT)
17581 + && d_mountpoint(a->dentry))
17582 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17587 +/* ---------------------------------------------------------------------- */
17589 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17590 + struct inode *dir)
17592 + struct dentry *dentry, *d, *parent;
17593 + struct qstr *dname;
17595 + parent = d_find_any_alias(dir);
17600 + spin_lock(&parent->d_lock);
17601 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17602 + /* AuDbg("%pd\n", d); */
17603 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17604 + dname = &d->d_name;
17605 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17606 + goto cont_unlock;
17610 + goto cont_unlock;
17611 + if (au_dcount(d) > 0) {
17612 + dentry = dget_dlock(d);
17613 + spin_unlock(&d->d_lock);
17618 + spin_unlock(&d->d_lock);
17620 + spin_unlock(&parent->d_lock);
17624 + di_write_lock_child(dentry);
17629 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17630 + aufs_bindex_t bindex, ino_t h_ino)
17632 + struct inode *inode;
17637 + err = au_xino_read(sb, bindex, h_ino, &ino);
17639 + inode = ilookup(sb, ino);
17643 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17644 + pr_warn("wrong root branch\n");
17650 + ii_write_lock_child(inode);
17656 +static void au_hn_bh(void *_args)
17658 + struct au_hnotify_args *a = _args;
17659 + struct super_block *sb;
17660 + aufs_bindex_t bindex, bbot, bfound;
17661 + unsigned char xino, try_iput;
17663 + struct inode *inode;
17665 + struct hn_job_args args;
17666 + struct dentry *dentry;
17667 + struct au_sbinfo *sbinfo;
17669 + AuDebugOn(!_args);
17670 + AuDebugOn(!a->h_dir);
17671 + AuDebugOn(!a->dir);
17672 + AuDebugOn(!a->mask);
17673 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17674 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17675 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17680 + * do not lock a->dir->i_mutex here
17681 + * because of d_revalidate() may cause a deadlock.
17683 + sb = a->dir->i_sb;
17685 + sbinfo = au_sbi(sb);
17686 + AuDebugOn(!sbinfo);
17687 + si_write_lock(sb, AuLock_NOPLMW);
17689 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17690 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17691 + case FS_MOVED_FROM:
17692 + case FS_MOVED_TO:
17693 + AuWarn1("DIRREN with UDBA may not work correctly "
17694 + "for the direct rename(2)\n");
17697 + ii_read_lock_parent(a->dir);
17699 + bbot = au_ibbot(a->dir);
17700 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17701 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17705 + ii_read_unlock(a->dir);
17706 + if (unlikely(bfound < 0))
17709 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17711 + if (a->h_child_inode)
17712 + h_ino = a->h_child_inode->i_ino;
17714 + if (a->h_child_nlen
17715 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17716 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17717 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17720 + if (dentry && d_really_is_positive(dentry))
17721 + inode = d_inode(dentry);
17722 + if (xino && !inode && h_ino
17723 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17724 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17725 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17726 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17730 + args.flags = a->flags[AuHn_CHILD];
17731 + args.dentry = dentry;
17732 + args.inode = inode;
17733 + args.h_inode = a->h_child_inode;
17734 + args.dir = a->dir;
17735 + args.h_dir = a->h_dir;
17736 + args.h_name = a->h_child_name;
17737 + args.h_nlen = a->h_child_nlen;
17738 + err = hn_job(&args);
17740 + if (au_di(dentry))
17741 + di_write_unlock(dentry);
17744 + if (inode && try_iput) {
17745 + ii_write_unlock(inode);
17749 + ii_write_lock_parent(a->dir);
17750 + args.flags = a->flags[AuHn_PARENT];
17751 + args.dentry = NULL;
17752 + args.inode = a->dir;
17753 + args.h_inode = a->h_dir;
17755 + args.h_dir = NULL;
17756 + args.h_name = NULL;
17758 + err = hn_job(&args);
17759 + ii_write_unlock(a->dir);
17762 + iput(a->h_child_inode);
17765 + si_write_unlock(sb);
17766 + au_nwt_done(&sbinfo->si_nowait);
17770 +/* ---------------------------------------------------------------------- */
17772 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17773 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17776 + unsigned int flags[AuHnLast], f;
17777 + unsigned char isdir, isroot, wh;
17778 + struct inode *dir;
17779 + struct au_hnotify_args *args;
17780 + char *p, *h_child_name;
17783 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17784 + dir = igrab(hnotify->hn_aufs_inode);
17788 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17790 + h_child_name = (void *)h_child_qstr->name;
17791 + len = h_child_qstr->len;
17792 + if (h_child_name) {
17793 + if (len > AUFS_WH_PFX_LEN
17794 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17795 + h_child_name += AUFS_WH_PFX_LEN;
17796 + len -= AUFS_WH_PFX_LEN;
17802 + if (h_child_inode)
17803 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17804 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17805 + flags[AuHn_CHILD] = 0;
17807 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17808 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17809 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17810 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17811 + case FS_MOVED_FROM:
17812 + case FS_MOVED_TO:
17813 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17814 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17817 + AuDebugOn(!h_child_name);
17822 + * aufs never be able to get this child inode.
17823 + * revalidation should be in d_revalidate()
17824 + * by checking i_nlink, i_generation or d_unhashed().
17826 + AuDebugOn(!h_child_name);
17827 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17828 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17836 + h_child_inode = NULL;
17839 + /* iput() and kfree() will be called in au_hnotify() */
17840 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17841 + if (unlikely(!args)) {
17842 + AuErr1("no memory\n");
17846 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17847 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17848 + args->mask = mask;
17850 + args->h_dir = igrab(h_dir);
17851 + if (h_child_inode)
17852 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17853 + args->h_child_inode = h_child_inode;
17854 + args->h_child_nlen = len;
17856 + p = (void *)args;
17857 + p += sizeof(*args);
17858 + memcpy(p, h_child_name, len);
17862 + /* NFS fires the event for silly-renamed one from kworker */
17864 + if (!dir->i_nlink
17865 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17867 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17868 + if (unlikely(err)) {
17869 + pr_err("wkq %d\n", err);
17870 + iput(args->h_child_inode);
17871 + iput(args->h_dir);
17873 + au_kfree_rcu(args);
17880 +/* ---------------------------------------------------------------------- */
17882 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17886 + AuDebugOn(!(udba & AuOptMask_UDBA));
17889 + if (au_hnotify_op.reset_br)
17890 + err = au_hnotify_op.reset_br(udba, br, perm);
17895 +int au_hnotify_init_br(struct au_branch *br, int perm)
17900 + if (au_hnotify_op.init_br)
17901 + err = au_hnotify_op.init_br(br, perm);
17906 +void au_hnotify_fin_br(struct au_branch *br)
17908 + if (au_hnotify_op.fin_br)
17909 + au_hnotify_op.fin_br(br);
17912 +static void au_hn_destroy_cache(void)
17914 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17915 + au_cache[AuCache_HNOTIFY] = NULL;
17918 +int __init au_hnotify_init(void)
17923 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17924 + if (au_cache[AuCache_HNOTIFY]) {
17926 + if (au_hnotify_op.init)
17927 + err = au_hnotify_op.init();
17928 + if (unlikely(err))
17929 + au_hn_destroy_cache();
17935 +void au_hnotify_fin(void)
17937 + if (au_hnotify_op.fin)
17938 + au_hnotify_op.fin();
17940 + /* cf. au_cache_fin() */
17941 + if (au_cache[AuCache_HNOTIFY])
17942 + au_hn_destroy_cache();
17944 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17945 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17946 +++ linux/fs/aufs/iinfo.c 2019-07-11 15:42:14.468904634 +0200
17948 +// SPDX-License-Identifier: GPL-2.0
17950 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17952 + * This program, aufs is free software; you can redistribute it and/or modify
17953 + * it under the terms of the GNU General Public License as published by
17954 + * the Free Software Foundation; either version 2 of the License, or
17955 + * (at your option) any later version.
17957 + * This program is distributed in the hope that it will be useful,
17958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17960 + * GNU General Public License for more details.
17962 + * You should have received a copy of the GNU General Public License
17963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17967 + * inode private data
17972 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17974 + struct inode *h_inode;
17975 + struct au_hinode *hinode;
17977 + IiMustAnyLock(inode);
17979 + hinode = au_hinode(au_ii(inode), bindex);
17980 + h_inode = hinode->hi_inode;
17981 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17985 +/* todo: hard/soft set? */
17986 +void au_hiput(struct au_hinode *hinode)
17988 + au_hn_free(hinode);
17989 + dput(hinode->hi_whdentry);
17990 + iput(hinode->hi_inode);
17993 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17995 + unsigned int flags;
17996 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17999 + if (au_opt_test(mnt_flags, XINO))
18000 + au_fset_hi(flags, XINO);
18001 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
18002 + au_fset_hi(flags, HNOTIFY);
18006 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18007 + struct inode *h_inode, unsigned int flags)
18009 + struct au_hinode *hinode;
18010 + struct inode *hi;
18011 + struct au_iinfo *iinfo = au_ii(inode);
18013 + IiMustWriteLock(inode);
18015 + hinode = au_hinode(iinfo, bindex);
18016 + hi = hinode->hi_inode;
18017 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18020 + au_hiput(hinode);
18021 + hinode->hi_inode = h_inode;
18024 + struct super_block *sb = inode->i_sb;
18025 + struct au_branch *br;
18027 + AuDebugOn(inode->i_mode
18028 + && (h_inode->i_mode & S_IFMT)
18029 + != (inode->i_mode & S_IFMT));
18030 + if (bindex == iinfo->ii_btop)
18031 + au_cpup_igen(inode, h_inode);
18032 + br = au_sbr(sb, bindex);
18033 + hinode->hi_id = br->br_id;
18034 + if (au_ftest_hi(flags, XINO)) {
18035 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18037 + if (unlikely(err))
18038 + AuIOErr1("failed au_xino_write() %d\n", err);
18041 + if (au_ftest_hi(flags, HNOTIFY)
18042 + && au_br_hnotifyable(br->br_perm)) {
18043 + err = au_hn_alloc(hinode, inode);
18044 + if (unlikely(err))
18045 + AuIOErr1("au_hn_alloc() %d\n", err);
18050 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18051 + struct dentry *h_wh)
18053 + struct au_hinode *hinode;
18055 + IiMustWriteLock(inode);
18057 + hinode = au_hinode(au_ii(inode), bindex);
18058 + AuDebugOn(hinode->hi_whdentry);
18059 + hinode->hi_whdentry = h_wh;
18062 +void au_update_iigen(struct inode *inode, int half)
18064 + struct au_iinfo *iinfo;
18065 + struct au_iigen *iigen;
18066 + unsigned int sigen;
18068 + sigen = au_sigen(inode->i_sb);
18069 + iinfo = au_ii(inode);
18070 + iigen = &iinfo->ii_generation;
18071 + spin_lock(&iigen->ig_spin);
18072 + iigen->ig_generation = sigen;
18074 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18076 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18077 + spin_unlock(&iigen->ig_spin);
18080 +/* it may be called at remount time, too */
18081 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18083 + struct au_iinfo *iinfo;
18084 + aufs_bindex_t bindex, bbot;
18086 + AuDebugOn(au_is_bad_inode(inode));
18087 + IiMustWriteLock(inode);
18089 + iinfo = au_ii(inode);
18090 + if (do_put_zero && iinfo->ii_btop >= 0) {
18091 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18093 + struct inode *h_i;
18095 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18098 + && !(h_i->i_state & I_LINKABLE))
18099 + au_set_h_iptr(inode, bindex, NULL, 0);
18103 + iinfo->ii_btop = -1;
18104 + iinfo->ii_bbot = -1;
18105 + bbot = au_sbbot(inode->i_sb);
18106 + for (bindex = 0; bindex <= bbot; bindex++)
18107 + if (au_hinode(iinfo, bindex)->hi_inode) {
18108 + iinfo->ii_btop = bindex;
18111 + if (iinfo->ii_btop >= 0)
18112 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18113 + if (au_hinode(iinfo, bindex)->hi_inode) {
18114 + iinfo->ii_bbot = bindex;
18117 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18120 +/* ---------------------------------------------------------------------- */
18122 +void au_icntnr_init_once(void *_c)
18124 + struct au_icntnr *c = _c;
18125 + struct au_iinfo *iinfo = &c->iinfo;
18127 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18128 + au_rw_init(&iinfo->ii_rwsem);
18129 + inode_init_once(&c->vfs_inode);
18132 +void au_hinode_init(struct au_hinode *hinode)
18134 + hinode->hi_inode = NULL;
18135 + hinode->hi_id = -1;
18136 + au_hn_init(hinode);
18137 + hinode->hi_whdentry = NULL;
18140 +int au_iinfo_init(struct inode *inode)
18142 + struct au_iinfo *iinfo;
18143 + struct super_block *sb;
18144 + struct au_hinode *hi;
18147 + sb = inode->i_sb;
18148 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18149 + nbr = au_sbbot(sb) + 1;
18150 + if (unlikely(nbr <= 0))
18152 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18154 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18156 + iinfo->ii_hinode = hi;
18157 + for (i = 0; i < nbr; i++, hi++)
18158 + au_hinode_init(hi);
18160 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18161 + iinfo->ii_btop = -1;
18162 + iinfo->ii_bbot = -1;
18163 + iinfo->ii_vdir = NULL;
18169 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18172 + struct au_hinode *hip;
18174 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18177 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18180 + iinfo->ii_hinode = hip;
18181 + i = iinfo->ii_bbot + 1;
18183 + for (; i < nbr; i++, hip++)
18184 + au_hinode_init(hip);
18191 +void au_iinfo_fin(struct inode *inode)
18193 + struct au_iinfo *iinfo;
18194 + struct au_hinode *hi;
18195 + struct super_block *sb;
18196 + aufs_bindex_t bindex, bbot;
18197 + const unsigned char unlinked = !inode->i_nlink;
18199 + AuDebugOn(au_is_bad_inode(inode));
18201 + sb = inode->i_sb;
18202 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18203 + if (si_pid_test(sb))
18204 + au_xino_delete_inode(inode, unlinked);
18207 + * it is safe to hide the dependency between sbinfo and
18211 + si_noflush_read_lock(sb);
18212 + au_xino_delete_inode(inode, unlinked);
18213 + si_read_unlock(sb);
18217 + iinfo = au_ii(inode);
18218 + if (iinfo->ii_vdir)
18219 + au_vdir_free(iinfo->ii_vdir);
18221 + bindex = iinfo->ii_btop;
18222 + if (bindex >= 0) {
18223 + hi = au_hinode(iinfo, bindex);
18224 + bbot = iinfo->ii_bbot;
18225 + while (bindex++ <= bbot) {
18226 + if (hi->hi_inode)
18231 + au_kfree_rcu(iinfo->ii_hinode);
18232 + AuRwDestroy(&iinfo->ii_rwsem);
18234 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18235 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18236 +++ linux/fs/aufs/inode.c 2019-07-11 15:42:14.468904634 +0200
18238 +// SPDX-License-Identifier: GPL-2.0
18240 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18242 + * This program, aufs is free software; you can redistribute it and/or modify
18243 + * it under the terms of the GNU General Public License as published by
18244 + * the Free Software Foundation; either version 2 of the License, or
18245 + * (at your option) any later version.
18247 + * This program is distributed in the hope that it will be useful,
18248 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18249 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18250 + * GNU General Public License for more details.
18252 + * You should have received a copy of the GNU General Public License
18253 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18257 + * inode functions
18260 +#include <linux/iversion.h>
18263 +struct inode *au_igrab(struct inode *inode)
18266 + AuDebugOn(!atomic_read(&inode->i_count));
18272 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18274 + au_cpup_attr_all(inode, /*force*/0);
18275 + au_update_iigen(inode, /*half*/1);
18277 + inode_inc_iversion(inode);
18280 +static int au_ii_refresh(struct inode *inode, int *update)
18284 + aufs_bindex_t bindex, new_bindex;
18285 + struct super_block *sb;
18286 + struct au_iinfo *iinfo;
18287 + struct au_hinode *p, *q, tmp;
18289 + AuDebugOn(au_is_bad_inode(inode));
18290 + IiMustWriteLock(inode);
18293 + sb = inode->i_sb;
18294 + nbr = au_sbbot(sb) + 1;
18295 + type = inode->i_mode & S_IFMT;
18296 + iinfo = au_ii(inode);
18297 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18298 + if (unlikely(err))
18301 + AuDebugOn(iinfo->ii_btop < 0);
18302 + p = au_hinode(iinfo, iinfo->ii_btop);
18303 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18305 + if (!p->hi_inode)
18308 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18309 + new_bindex = au_br_index(sb, p->hi_id);
18310 + if (new_bindex == bindex)
18313 + if (new_bindex < 0) {
18316 + p->hi_inode = NULL;
18320 + if (new_bindex < iinfo->ii_btop)
18321 + iinfo->ii_btop = new_bindex;
18322 + if (iinfo->ii_bbot < new_bindex)
18323 + iinfo->ii_bbot = new_bindex;
18324 + /* swap two lower inode, and loop again */
18325 + q = au_hinode(iinfo, new_bindex);
18329 + if (tmp.hi_inode) {
18334 + au_update_ibrange(inode, /*do_put_zero*/0);
18335 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18336 + e = au_dy_irefresh(inode);
18337 + if (unlikely(e && !err))
18345 +void au_refresh_iop(struct inode *inode, int force_getattr)
18348 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18349 + const struct inode_operations *iop
18350 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18352 + if (inode->i_op == iop)
18355 + switch (inode->i_mode & S_IFMT) {
18357 + type = AuIop_DIR;
18360 + type = AuIop_SYMLINK;
18363 + type = AuIop_OTHER;
18367 + inode->i_op = iop + type;
18368 + /* unnecessary smp_wmb() */
18371 +int au_refresh_hinode_self(struct inode *inode)
18375 + err = au_ii_refresh(inode, &update);
18377 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18383 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18385 + int err, e, update;
18386 + unsigned int flags;
18388 + aufs_bindex_t bindex, bbot;
18389 + unsigned char isdir;
18390 + struct au_hinode *p;
18391 + struct au_iinfo *iinfo;
18393 + err = au_ii_refresh(inode, &update);
18394 + if (unlikely(err))
18398 + iinfo = au_ii(inode);
18399 + p = au_hinode(iinfo, iinfo->ii_btop);
18400 + mode = (inode->i_mode & S_IFMT);
18401 + isdir = S_ISDIR(mode);
18402 + flags = au_hi_flags(inode, isdir);
18403 + bbot = au_dbbot(dentry);
18404 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18405 + struct inode *h_i, *h_inode;
18406 + struct dentry *h_d;
18408 + h_d = au_h_dptr(dentry, bindex);
18409 + if (!h_d || d_is_negative(h_d))
18412 + h_inode = d_inode(h_d);
18413 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18414 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18415 + h_i = au_h_iptr(inode, bindex);
18417 + if (h_i == h_inode)
18423 + if (bindex < iinfo->ii_btop)
18424 + iinfo->ii_btop = bindex;
18425 + if (iinfo->ii_bbot < bindex)
18426 + iinfo->ii_bbot = bindex;
18427 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18430 + au_update_ibrange(inode, /*do_put_zero*/0);
18431 + e = au_dy_irefresh(inode);
18432 + if (unlikely(e && !err))
18435 + au_refresh_hinode_attr(inode, update && isdir);
18442 +static int set_inode(struct inode *inode, struct dentry *dentry)
18445 + unsigned int flags;
18447 + aufs_bindex_t bindex, btop, btail;
18448 + unsigned char isdir;
18449 + struct dentry *h_dentry;
18450 + struct inode *h_inode;
18451 + struct au_iinfo *iinfo;
18452 + struct inode_operations *iop;
18454 + IiMustWriteLock(inode);
18458 + iop = au_sbi(inode->i_sb)->si_iop_array;
18459 + btop = au_dbtop(dentry);
18460 + h_dentry = au_h_dptr(dentry, btop);
18461 + h_inode = d_inode(h_dentry);
18462 + mode = h_inode->i_mode;
18463 + switch (mode & S_IFMT) {
18465 + btail = au_dbtail(dentry);
18466 + inode->i_op = iop + AuIop_OTHER;
18467 + inode->i_fop = &aufs_file_fop;
18468 + err = au_dy_iaop(inode, btop, h_inode);
18469 + if (unlikely(err))
18474 + btail = au_dbtaildir(dentry);
18475 + inode->i_op = iop + AuIop_DIR;
18476 + inode->i_fop = &aufs_dir_fop;
18479 + btail = au_dbtail(dentry);
18480 + inode->i_op = iop + AuIop_SYMLINK;
18486 + btail = au_dbtail(dentry);
18487 + inode->i_op = iop + AuIop_OTHER;
18488 + init_special_inode(inode, mode, h_inode->i_rdev);
18491 + AuIOErr("Unknown file type 0%o\n", mode);
18496 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18497 + flags = au_hi_flags(inode, isdir);
18498 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18499 + && au_ftest_hi(flags, HNOTIFY)
18500 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18501 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18502 + au_fclr_hi(flags, HNOTIFY);
18503 + iinfo = au_ii(inode);
18504 + iinfo->ii_btop = btop;
18505 + iinfo->ii_bbot = btail;
18506 + for (bindex = btop; bindex <= btail; bindex++) {
18507 + h_dentry = au_h_dptr(dentry, bindex);
18509 + au_set_h_iptr(inode, bindex,
18510 + au_igrab(d_inode(h_dentry)), flags);
18512 + au_cpup_attr_all(inode, /*force*/1);
18514 + * to force calling aufs_get_acl() every time,
18515 + * do not call cache_no_acl() for aufs inode.
18523 + * successful returns with iinfo write_locked
18525 + * zero: success, matched
18526 + * plus: no error, but unmatched
18528 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18531 + unsigned int gen, igflags;
18532 + aufs_bindex_t bindex, bbot;
18533 + struct inode *h_inode, *h_dinode;
18534 + struct dentry *h_dentry;
18537 + * before this function, if aufs got any iinfo lock, it must be only
18538 + * one, the parent dir.
18539 + * it can happen by UDBA and the obsoleted inode number.
18542 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18546 + ii_write_lock_new_child(inode);
18547 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18548 + h_dinode = d_inode(h_dentry);
18549 + bbot = au_ibbot(inode);
18550 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18551 + h_inode = au_h_iptr(inode, bindex);
18552 + if (!h_inode || h_inode != h_dinode)
18556 + gen = au_iigen(inode, &igflags);
18557 + if (gen == au_digen(dentry)
18558 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18561 + /* fully refresh inode using dentry */
18562 + err = au_refresh_hinode(inode, dentry);
18564 + au_update_iigen(inode, /*half*/0);
18568 + if (unlikely(err))
18569 + ii_write_unlock(inode);
18574 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18575 + unsigned int d_type, ino_t *ino)
18578 + const int isnondir = d_type != DT_DIR;
18580 + /* prevent hardlinked inode number from race condition */
18582 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18583 + if (unlikely(err))
18587 + err = au_xino_read(sb, bindex, h_ino, ino);
18588 + if (unlikely(err))
18589 + goto out_xinondir;
18593 + *ino = au_xino_new_ino(sb);
18594 + if (unlikely(!*ino))
18595 + goto out_xinondir;
18596 + err = au_xino_write(sb, bindex, h_ino, *ino);
18597 + if (unlikely(err))
18598 + goto out_xinondir;
18602 + if (isnondir && idx >= 0)
18603 + au_xinondir_leave(sb, bindex, h_ino, idx);
18608 +/* successful returns with iinfo write_locked */
18609 +/* todo: return with unlocked? */
18610 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18612 + struct inode *inode, *h_inode;
18613 + struct dentry *h_dentry;
18614 + struct super_block *sb;
18615 + ino_t h_ino, ino;
18616 + int err, idx, hlinked;
18617 + aufs_bindex_t btop;
18619 + sb = dentry->d_sb;
18620 + btop = au_dbtop(dentry);
18621 + h_dentry = au_h_dptr(dentry, btop);
18622 + h_inode = d_inode(h_dentry);
18623 + h_ino = h_inode->i_ino;
18624 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18628 + * stop 'race'-ing between hardlinks under different
18632 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18633 + inode = ERR_PTR(err);
18634 + if (unlikely(err))
18638 + err = au_xino_read(sb, btop, h_ino, &ino);
18639 + inode = ERR_PTR(err);
18640 + if (unlikely(err))
18641 + goto out_xinondir;
18644 + ino = au_xino_new_ino(sb);
18645 + if (unlikely(!ino)) {
18646 + inode = ERR_PTR(-EIO);
18647 + goto out_xinondir;
18651 + AuDbg("i%lu\n", (unsigned long)ino);
18652 + inode = au_iget_locked(sb, ino);
18653 + err = PTR_ERR(inode);
18654 + if (IS_ERR(inode))
18655 + goto out_xinondir;
18657 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18658 + if (inode->i_state & I_NEW) {
18659 + ii_write_lock_new_child(inode);
18660 + err = set_inode(inode, dentry);
18662 + unlock_new_inode(inode);
18663 + goto out_xinondir; /* success */
18667 + * iget_failed() calls iput(), but we need to call
18668 + * ii_write_unlock() after iget_failed(). so dirty hack for
18671 + atomic_inc(&inode->i_count);
18672 + iget_failed(inode);
18673 + ii_write_unlock(inode);
18674 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18675 + /* ignore this error */
18677 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18679 + * horrible race condition between lookup, readdir and copyup
18680 + * (or something).
18682 + if (hlinked && idx >= 0)
18683 + au_xinondir_leave(sb, btop, h_ino, idx);
18684 + err = reval_inode(inode, dentry);
18685 + if (unlikely(err < 0)) {
18690 + goto out; /* success */
18691 + else if (hlinked && idx >= 0) {
18692 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18693 + if (unlikely(err)) {
18695 + inode = ERR_PTR(err);
18701 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18702 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18703 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18704 + btop, au_sbtype(h_dentry->d_sb), dentry,
18705 + (unsigned long)h_ino, (unsigned long)ino);
18707 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18710 + if (hlinked && idx >= 0)
18711 + au_xinondir_leave(sb, btop, h_ino, idx);
18717 + inode = ERR_PTR(err);
18719 + if (hlinked && idx >= 0)
18720 + au_xinondir_leave(sb, btop, h_ino, idx);
18725 +/* ---------------------------------------------------------------------- */
18727 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18728 + struct inode *inode)
18731 + struct inode *hi;
18733 + err = au_br_rdonly(au_sbr(sb, bindex));
18735 + /* pseudo-link after flushed may happen out of bounds */
18738 + && au_ibtop(inode) <= bindex
18739 + && bindex <= au_ibbot(inode)) {
18741 + * permission check is unnecessary since vfsub routine
18742 + * will be called later
18744 + hi = au_h_iptr(inode, bindex);
18746 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18752 +int au_test_h_perm(struct inode *h_inode, int mask)
18754 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18756 + return inode_permission(h_inode, mask);
18759 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18761 + if (au_test_nfs(h_inode->i_sb)
18762 + && (mask & MAY_WRITE)
18763 + && S_ISDIR(h_inode->i_mode))
18764 + mask |= MAY_READ; /* force permission check */
18765 + return au_test_h_perm(h_inode, mask);
18767 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18768 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18769 +++ linux/fs/aufs/inode.h 2019-07-11 15:42:14.468904634 +0200
18771 +/* SPDX-License-Identifier: GPL-2.0 */
18773 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18775 + * This program, aufs is free software; you can redistribute it and/or modify
18776 + * it under the terms of the GNU General Public License as published by
18777 + * the Free Software Foundation; either version 2 of the License, or
18778 + * (at your option) any later version.
18780 + * This program is distributed in the hope that it will be useful,
18781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18783 + * GNU General Public License for more details.
18785 + * You should have received a copy of the GNU General Public License
18786 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18790 + * inode operations
18793 +#ifndef __AUFS_INODE_H__
18794 +#define __AUFS_INODE_H__
18798 +#include <linux/fsnotify.h>
18799 +#include "rwsem.h"
18803 +struct au_hnotify {
18804 +#ifdef CONFIG_AUFS_HNOTIFY
18805 +#ifdef CONFIG_AUFS_HFSNOTIFY
18806 + /* never use fsnotify_add_vfsmount_mark() */
18807 + struct fsnotify_mark hn_mark;
18809 + struct inode *hn_aufs_inode; /* no get/put */
18810 + struct rcu_head rcu;
18812 +} ____cacheline_aligned_in_smp;
18814 +struct au_hinode {
18815 + struct inode *hi_inode;
18816 + aufs_bindex_t hi_id;
18817 +#ifdef CONFIG_AUFS_HNOTIFY
18818 + struct au_hnotify *hi_notify;
18821 + /* reference to the copied-up whiteout with get/put */
18822 + struct dentry *hi_whdentry;
18826 +#define AuIG_HALF_REFRESHED 1
18827 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18828 +#define au_ig_fset(flags, name) \
18829 + do { (flags) |= AuIG_##name; } while (0)
18830 +#define au_ig_fclr(flags, name) \
18831 + do { (flags) &= ~AuIG_##name; } while (0)
18834 + spinlock_t ig_spin;
18835 + __u32 ig_generation, ig_flags;
18840 + struct au_iigen ii_generation;
18841 + struct super_block *ii_hsb1; /* no get/put */
18843 + struct au_rwsem ii_rwsem;
18844 + aufs_bindex_t ii_btop, ii_bbot;
18846 + struct au_hinode *ii_hinode;
18847 + struct au_vdir *ii_vdir;
18850 +struct au_icntnr {
18851 + struct au_iinfo iinfo;
18852 + struct inode vfs_inode;
18853 + struct hlist_bl_node plink;
18854 + struct rcu_head rcu;
18855 +} ____cacheline_aligned_in_smp;
18857 +/* au_pin flags */
18858 +#define AuPin_DI_LOCKED 1
18859 +#define AuPin_MNT_WRITE (1 << 1)
18860 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18861 +#define au_fset_pin(flags, name) \
18862 + do { (flags) |= AuPin_##name; } while (0)
18863 +#define au_fclr_pin(flags, name) \
18864 + do { (flags) &= ~AuPin_##name; } while (0)
18868 + struct dentry *dentry;
18869 + unsigned int udba;
18870 + unsigned char lsc_di, lsc_hi, flags;
18871 + aufs_bindex_t bindex;
18874 + struct dentry *parent;
18875 + struct au_hinode *hdir;
18876 + struct vfsmount *h_mnt;
18878 + /* temporary unlock/relock for copyup */
18879 + struct dentry *h_dentry, *h_parent;
18880 + struct au_branch *br;
18881 + struct task_struct *task;
18884 +void au_pin_hdir_unlock(struct au_pin *p);
18885 +int au_pin_hdir_lock(struct au_pin *p);
18886 +int au_pin_hdir_relock(struct au_pin *p);
18887 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18888 +void au_pin_hdir_release(struct au_pin *p);
18890 +/* ---------------------------------------------------------------------- */
18892 +static inline struct au_iinfo *au_ii(struct inode *inode)
18894 + BUG_ON(is_bad_inode(inode));
18895 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18898 +/* ---------------------------------------------------------------------- */
18901 +struct inode *au_igrab(struct inode *inode);
18902 +void au_refresh_iop(struct inode *inode, int force_getattr);
18903 +int au_refresh_hinode_self(struct inode *inode);
18904 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18905 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18906 + unsigned int d_type, ino_t *ino);
18907 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18908 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18909 + struct inode *inode);
18910 +int au_test_h_perm(struct inode *h_inode, int mask);
18911 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18913 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18914 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18916 +#ifdef CONFIG_AUFS_SHWH
18917 + return au_ino(sb, bindex, h_ino, d_type, ino);
18930 +extern struct inode_operations aufs_iop[AuIop_Last],
18931 + aufs_iop_nogetattr[AuIop_Last];
18933 +/* au_wr_dir flags */
18934 +#define AuWrDir_ADD_ENTRY 1
18935 +#define AuWrDir_ISDIR (1 << 1)
18936 +#define AuWrDir_TMPFILE (1 << 2)
18937 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18938 +#define au_fset_wrdir(flags, name) \
18939 + do { (flags) |= AuWrDir_##name; } while (0)
18940 +#define au_fclr_wrdir(flags, name) \
18941 + do { (flags) &= ~AuWrDir_##name; } while (0)
18943 +struct au_wr_dir_args {
18944 + aufs_bindex_t force_btgt;
18945 + unsigned char flags;
18947 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18948 + struct au_wr_dir_args *args);
18950 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18951 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18952 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18953 + unsigned int udba, unsigned char flags);
18954 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18955 + unsigned int udba, unsigned char flags) __must_check;
18956 +int au_do_pin(struct au_pin *pin) __must_check;
18957 +void au_unpin(struct au_pin *pin);
18958 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18960 +#define AuIcpup_DID_CPUP 1
18961 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18962 +#define au_fset_icpup(flags, name) \
18963 + do { (flags) |= AuIcpup_##name; } while (0)
18964 +#define au_fclr_icpup(flags, name) \
18965 + do { (flags) &= ~AuIcpup_##name; } while (0)
18967 +struct au_icpup_args {
18968 + unsigned char flags;
18969 + unsigned char pin_flags;
18970 + aufs_bindex_t btgt;
18971 + unsigned int udba;
18972 + struct au_pin pin;
18973 + struct path h_path;
18974 + struct inode *h_inode;
18977 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18978 + struct au_icpup_args *a);
18980 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18984 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18985 + struct dentry *h_parent, int isdir);
18986 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18988 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18989 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18991 +struct vfsub_aopen_args;
18992 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18993 + struct vfsub_aopen_args *args);
18994 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18995 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18996 + struct dentry *dentry);
18997 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
19000 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
19001 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19002 + struct dentry *h_parent, int isdir);
19003 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
19004 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19007 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19008 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19009 + struct inode *dir, struct dentry *dentry,
19010 + unsigned int flags);
19013 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19014 +void au_hiput(struct au_hinode *hinode);
19015 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19016 + struct dentry *h_wh);
19017 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19019 +/* hinode flags */
19020 +#define AuHi_XINO 1
19021 +#define AuHi_HNOTIFY (1 << 1)
19022 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19023 +#define au_fset_hi(flags, name) \
19024 + do { (flags) |= AuHi_##name; } while (0)
19025 +#define au_fclr_hi(flags, name) \
19026 + do { (flags) &= ~AuHi_##name; } while (0)
19028 +#ifndef CONFIG_AUFS_HNOTIFY
19029 +#undef AuHi_HNOTIFY
19030 +#define AuHi_HNOTIFY 0
19033 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19034 + struct inode *h_inode, unsigned int flags);
19036 +void au_update_iigen(struct inode *inode, int half);
19037 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19039 +void au_icntnr_init_once(void *_c);
19040 +void au_hinode_init(struct au_hinode *hinode);
19041 +int au_iinfo_init(struct inode *inode);
19042 +void au_iinfo_fin(struct inode *inode);
19043 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19045 +#ifdef CONFIG_PROC_FS
19047 +int au_plink_maint(struct super_block *sb, int flags);
19049 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19050 +int au_plink_maint_enter(struct super_block *sb);
19051 +#ifdef CONFIG_AUFS_DEBUG
19052 +void au_plink_list(struct super_block *sb);
19054 +AuStubVoid(au_plink_list, struct super_block *sb)
19056 +int au_plink_test(struct inode *inode);
19057 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19058 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19059 + struct dentry *h_dentry);
19060 +void au_plink_put(struct super_block *sb, int verbose);
19061 +void au_plink_clean(struct super_block *sb, int verbose);
19062 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19064 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19065 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19066 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19067 +AuStubVoid(au_plink_list, struct super_block *sb);
19068 +AuStubInt0(au_plink_test, struct inode *inode);
19069 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19070 + struct inode *inode, aufs_bindex_t bindex);
19071 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19072 + struct dentry *h_dentry);
19073 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19074 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19075 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19076 +#endif /* CONFIG_PROC_FS */
19078 +#ifdef CONFIG_AUFS_XATTR
19080 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19081 + unsigned int verbose);
19082 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19083 +void au_xattr_init(struct super_block *sb);
19085 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19086 + int ignore_flags, unsigned int verbose);
19087 +AuStubVoid(au_xattr_init, struct super_block *sb);
19090 +#ifdef CONFIG_FS_POSIX_ACL
19091 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19092 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19095 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19101 +struct au_sxattr {
19105 + const char *name;
19106 + const void *value;
19111 + struct posix_acl *acl;
19116 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19117 + struct au_sxattr *arg);
19120 +/* ---------------------------------------------------------------------- */
19122 +/* lock subclass for iinfo */
19124 + AuLsc_II_CHILD, /* child first */
19125 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19126 + AuLsc_II_CHILD3, /* copyup dirs */
19127 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19128 + AuLsc_II_PARENT2,
19129 + AuLsc_II_PARENT3, /* copyup dirs */
19130 + AuLsc_II_NEW_CHILD
19134 + * ii_read_lock_child, ii_write_lock_child,
19135 + * ii_read_lock_child2, ii_write_lock_child2,
19136 + * ii_read_lock_child3, ii_write_lock_child3,
19137 + * ii_read_lock_parent, ii_write_lock_parent,
19138 + * ii_read_lock_parent2, ii_write_lock_parent2,
19139 + * ii_read_lock_parent3, ii_write_lock_parent3,
19140 + * ii_read_lock_new_child, ii_write_lock_new_child,
19142 +#define AuReadLockFunc(name, lsc) \
19143 +static inline void ii_read_lock_##name(struct inode *i) \
19145 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19148 +#define AuWriteLockFunc(name, lsc) \
19149 +static inline void ii_write_lock_##name(struct inode *i) \
19151 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19154 +#define AuRWLockFuncs(name, lsc) \
19155 + AuReadLockFunc(name, lsc) \
19156 + AuWriteLockFunc(name, lsc)
19158 +AuRWLockFuncs(child, CHILD);
19159 +AuRWLockFuncs(child2, CHILD2);
19160 +AuRWLockFuncs(child3, CHILD3);
19161 +AuRWLockFuncs(parent, PARENT);
19162 +AuRWLockFuncs(parent2, PARENT2);
19163 +AuRWLockFuncs(parent3, PARENT3);
19164 +AuRWLockFuncs(new_child, NEW_CHILD);
19166 +#undef AuReadLockFunc
19167 +#undef AuWriteLockFunc
19168 +#undef AuRWLockFuncs
19170 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19171 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19172 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19174 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19175 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19176 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19178 +/* ---------------------------------------------------------------------- */
19180 +static inline void au_icntnr_init(struct au_icntnr *c)
19182 +#ifdef CONFIG_AUFS_DEBUG
19183 + c->vfs_inode.i_mode = 0;
19187 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19189 + unsigned int gen;
19190 + struct au_iinfo *iinfo;
19191 + struct au_iigen *iigen;
19193 + iinfo = au_ii(inode);
19194 + iigen = &iinfo->ii_generation;
19195 + spin_lock(&iigen->ig_spin);
19197 + *igflags = iigen->ig_flags;
19198 + gen = iigen->ig_generation;
19199 + spin_unlock(&iigen->ig_spin);
19204 +/* tiny test for inode number */
19205 +/* tmpfs generation is too rough */
19206 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19208 + struct au_iinfo *iinfo;
19210 + iinfo = au_ii(inode);
19211 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19212 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19213 + && iinfo->ii_higen == h_inode->i_generation);
19216 +static inline void au_iigen_dec(struct inode *inode)
19218 + struct au_iinfo *iinfo;
19219 + struct au_iigen *iigen;
19221 + iinfo = au_ii(inode);
19222 + iigen = &iinfo->ii_generation;
19223 + spin_lock(&iigen->ig_spin);
19224 + iigen->ig_generation--;
19225 + spin_unlock(&iigen->ig_spin);
19228 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19233 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19239 +/* ---------------------------------------------------------------------- */
19241 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19242 + aufs_bindex_t bindex)
19244 + return iinfo->ii_hinode + bindex;
19247 +static inline int au_is_bad_inode(struct inode *inode)
19249 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19252 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19253 + aufs_bindex_t bindex)
19255 + IiMustAnyLock(inode);
19256 + return au_hinode(au_ii(inode), bindex)->hi_id;
19259 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19261 + IiMustAnyLock(inode);
19262 + return au_ii(inode)->ii_btop;
19265 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19267 + IiMustAnyLock(inode);
19268 + return au_ii(inode)->ii_bbot;
19271 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19273 + IiMustAnyLock(inode);
19274 + return au_ii(inode)->ii_vdir;
19277 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19279 + IiMustAnyLock(inode);
19280 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19283 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19285 + IiMustWriteLock(inode);
19286 + au_ii(inode)->ii_btop = bindex;
19289 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19291 + IiMustWriteLock(inode);
19292 + au_ii(inode)->ii_bbot = bindex;
19295 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19297 + IiMustWriteLock(inode);
19298 + au_ii(inode)->ii_vdir = vdir;
19301 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19303 + IiMustAnyLock(inode);
19304 + return au_hinode(au_ii(inode), bindex);
19307 +/* ---------------------------------------------------------------------- */
19309 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19312 + return pin->parent;
19316 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19318 + if (pin && pin->hdir)
19319 + return pin->hdir->hi_inode;
19323 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19326 + return pin->hdir;
19330 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19333 + pin->dentry = dentry;
19336 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19337 + unsigned char lflag)
19341 + au_fset_pin(pin->flags, DI_LOCKED);
19343 + au_fclr_pin(pin->flags, DI_LOCKED);
19347 +#if 0 /* reserved */
19348 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19351 + dput(pin->parent);
19352 + pin->parent = dget(parent);
19357 +/* ---------------------------------------------------------------------- */
19360 +#ifdef CONFIG_AUFS_HNOTIFY
19361 +struct au_hnotify_op {
19362 + void (*ctl)(struct au_hinode *hinode, int do_set);
19363 + int (*alloc)(struct au_hinode *hinode);
19366 + * if it returns true, the the caller should free hinode->hi_notify,
19367 + * otherwise ->free() frees it.
19369 + int (*free)(struct au_hinode *hinode,
19370 + struct au_hnotify *hn) __must_check;
19372 + void (*fin)(void);
19373 + int (*init)(void);
19375 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19376 + void (*fin_br)(struct au_branch *br);
19377 + int (*init_br)(struct au_branch *br, int perm);
19381 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19382 +void au_hn_free(struct au_hinode *hinode);
19383 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19384 +void au_hn_reset(struct inode *inode, unsigned int flags);
19385 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19386 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19387 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19388 +int au_hnotify_init_br(struct au_branch *br, int perm);
19389 +void au_hnotify_fin_br(struct au_branch *br);
19390 +int __init au_hnotify_init(void);
19391 +void au_hnotify_fin(void);
19394 +extern const struct au_hnotify_op au_hnotify_op;
19397 +void au_hn_init(struct au_hinode *hinode)
19399 + hinode->hi_notify = NULL;
19402 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19404 + return hinode->hi_notify;
19408 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19409 + struct au_hinode *hinode __maybe_unused,
19410 + struct inode *inode __maybe_unused)
19411 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19412 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19413 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19414 + int do_set __maybe_unused)
19415 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19416 + unsigned int flags __maybe_unused)
19417 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19418 + struct au_branch *br __maybe_unused,
19419 + int perm __maybe_unused)
19420 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19421 + int perm __maybe_unused)
19422 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19423 +AuStubInt0(__init au_hnotify_init, void)
19424 +AuStubVoid(au_hnotify_fin, void)
19425 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19426 +#endif /* CONFIG_AUFS_HNOTIFY */
19428 +static inline void au_hn_suspend(struct au_hinode *hdir)
19430 + au_hn_ctl(hdir, /*do_set*/0);
19433 +static inline void au_hn_resume(struct au_hinode *hdir)
19435 + au_hn_ctl(hdir, /*do_set*/1);
19438 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19440 + inode_lock(hdir->hi_inode);
19441 + au_hn_suspend(hdir);
19444 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19445 + unsigned int sc __maybe_unused)
19447 + inode_lock_nested(hdir->hi_inode, sc);
19448 + au_hn_suspend(hdir);
19451 +#if 0 /* unused */
19452 +#include "vfsub.h"
19453 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19456 + inode_lock_shared_nested(hdir->hi_inode, sc);
19457 + au_hn_suspend(hdir);
19461 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19463 + au_hn_resume(hdir);
19464 + inode_unlock(hdir->hi_inode);
19467 +#endif /* __KERNEL__ */
19468 +#endif /* __AUFS_INODE_H__ */
19469 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19470 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19471 +++ linux/fs/aufs/ioctl.c 2019-07-11 15:42:14.468904634 +0200
19473 +// SPDX-License-Identifier: GPL-2.0
19475 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19477 + * This program, aufs is free software; you can redistribute it and/or modify
19478 + * it under the terms of the GNU General Public License as published by
19479 + * the Free Software Foundation; either version 2 of the License, or
19480 + * (at your option) any later version.
19482 + * This program is distributed in the hope that it will be useful,
19483 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19484 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19485 + * GNU General Public License for more details.
19487 + * You should have received a copy of the GNU General Public License
19488 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19493 + * plink-management and readdir in userspace.
19494 + * assist the pathconf(3) wrapper library.
19496 + * File-based Hierarchical Storage Management.
19499 +#include <linux/compat.h>
19500 +#include <linux/file.h>
19503 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19506 + aufs_bindex_t wbi, bindex, bbot;
19507 + struct file *h_file;
19508 + struct super_block *sb;
19509 + struct dentry *root;
19510 + struct au_branch *br;
19511 + struct aufs_wbr_fd wbrfd = {
19512 + .oflags = au_dir_roflags,
19515 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19516 + | O_NOATIME | O_CLOEXEC;
19518 + AuDebugOn(wbrfd.oflags & ~valid);
19521 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19522 + if (unlikely(err)) {
19528 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19529 + wbrfd.oflags |= au_dir_roflags;
19530 + AuDbg("0%o\n", wbrfd.oflags);
19531 + if (unlikely(wbrfd.oflags & ~valid))
19535 + fd = get_unused_fd_flags(0);
19537 + if (unlikely(fd < 0))
19540 + h_file = ERR_PTR(-EINVAL);
19543 + sb = path->dentry->d_sb;
19544 + root = sb->s_root;
19545 + aufs_read_lock(root, AuLock_IR);
19546 + bbot = au_sbbot(sb);
19547 + if (wbrfd.brid >= 0) {
19548 + wbi = au_br_index(sb, wbrfd.brid);
19549 + if (unlikely(wbi < 0 || wbi > bbot))
19553 + h_file = ERR_PTR(-ENOENT);
19554 + br = au_sbr(sb, wbi);
19555 + if (!au_br_writable(br->br_perm)) {
19559 + bindex = wbi + 1;
19561 + for (; bindex <= bbot; bindex++) {
19562 + br = au_sbr(sb, bindex);
19563 + if (au_br_writable(br->br_perm)) {
19565 + br = au_sbr(sb, wbi);
19570 + AuDbg("wbi %d\n", wbi);
19572 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19576 + aufs_read_unlock(root, AuLock_IR);
19577 + err = PTR_ERR(h_file);
19578 + if (IS_ERR(h_file))
19581 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19582 + fd_install(fd, h_file);
19584 + goto out; /* success */
19587 + put_unused_fd(fd);
19593 +/* ---------------------------------------------------------------------- */
19595 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19598 + struct dentry *dentry;
19601 + case AUFS_CTL_RDU:
19602 + case AUFS_CTL_RDU_INO:
19603 + err = au_rdu_ioctl(file, cmd, arg);
19606 + case AUFS_CTL_WBR_FD:
19607 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19610 + case AUFS_CTL_IBUSY:
19611 + err = au_ibusy_ioctl(file, arg);
19614 + case AUFS_CTL_BRINFO:
19615 + err = au_brinfo_ioctl(file, arg);
19618 + case AUFS_CTL_FHSM_FD:
19619 + dentry = file->f_path.dentry;
19620 + if (IS_ROOT(dentry))
19621 + err = au_fhsm_fd(dentry->d_sb, arg);
19627 + /* do not call the lower */
19628 + AuDbg("0x%x\n", cmd);
19636 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19641 + case AUFS_CTL_MVDOWN:
19642 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19645 + case AUFS_CTL_WBR_FD:
19646 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19650 + /* do not call the lower */
19651 + AuDbg("0x%x\n", cmd);
19659 +#ifdef CONFIG_COMPAT
19660 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19661 + unsigned long arg)
19666 + case AUFS_CTL_RDU:
19667 + case AUFS_CTL_RDU_INO:
19668 + err = au_rdu_compat_ioctl(file, cmd, arg);
19671 + case AUFS_CTL_IBUSY:
19672 + err = au_ibusy_compat_ioctl(file, arg);
19675 + case AUFS_CTL_BRINFO:
19676 + err = au_brinfo_compat_ioctl(file, arg);
19680 + err = aufs_ioctl_dir(file, cmd, arg);
19687 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19688 + unsigned long arg)
19690 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19693 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19694 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19695 +++ linux/fs/aufs/i_op_add.c 2019-07-11 15:42:14.468904634 +0200
19697 +// SPDX-License-Identifier: GPL-2.0
19699 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19701 + * This program, aufs is free software; you can redistribute it and/or modify
19702 + * it under the terms of the GNU General Public License as published by
19703 + * the Free Software Foundation; either version 2 of the License, or
19704 + * (at your option) any later version.
19706 + * This program is distributed in the hope that it will be useful,
19707 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19708 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19709 + * GNU General Public License for more details.
19711 + * You should have received a copy of the GNU General Public License
19712 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19716 + * inode operations (add entry)
19719 +#include <linux/iversion.h>
19723 + * final procedure of adding a new entry, except link(2).
19724 + * remove whiteout, instantiate, copyup the parent dir's times and size
19725 + * and update version.
19726 + * if it failed, re-create the removed whiteout.
19728 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19729 + struct dentry *wh_dentry, struct dentry *dentry)
19732 + aufs_bindex_t bwh;
19733 + struct path h_path;
19734 + struct super_block *sb;
19735 + struct inode *inode, *h_dir;
19736 + struct dentry *wh;
19741 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19742 + IMustLock(h_dir);
19743 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19744 + bwh = au_dbwh(dentry);
19745 + h_path.dentry = wh_dentry;
19746 + h_path.mnt = au_sbr_mnt(sb, bindex);
19747 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19749 + if (unlikely(err))
19753 + inode = au_new_inode(dentry, /*must_new*/1);
19754 + if (!IS_ERR(inode)) {
19755 + d_instantiate(dentry, inode);
19756 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19758 + au_dir_ts(dir, bindex);
19759 + inode_inc_iversion(dir);
19760 + au_fhsm_wrote(sb, bindex, /*force*/0);
19761 + return 0; /* success */
19764 + err = PTR_ERR(inode);
19769 + /* dir inode is locked */
19770 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19771 + rerr = PTR_ERR(wh);
19772 + if (IS_ERR(wh)) {
19773 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19774 + dentry, err, rerr);
19783 +static int au_d_may_add(struct dentry *dentry)
19788 + if (unlikely(d_unhashed(dentry)))
19790 + if (unlikely(d_really_is_positive(dentry)))
19796 + * simple tests for the adding inode operations.
19797 + * following the checks in vfs, plus the parent-child relationship.
19799 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19800 + struct dentry *h_parent, int isdir)
19804 + struct dentry *h_dentry;
19805 + struct inode *h_inode;
19807 + err = -ENAMETOOLONG;
19808 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19811 + h_dentry = au_h_dptr(dentry, bindex);
19812 + if (d_really_is_negative(dentry)) {
19814 + if (unlikely(d_is_positive(h_dentry)))
19817 + /* rename(2) case */
19819 + if (unlikely(d_is_negative(h_dentry)))
19821 + h_inode = d_inode(h_dentry);
19822 + if (unlikely(!h_inode->i_nlink))
19825 + h_mode = h_inode->i_mode;
19828 + if (unlikely(S_ISDIR(h_mode)))
19830 + } else if (unlikely(!S_ISDIR(h_mode))) {
19837 + /* expected parent dir is locked */
19838 + if (unlikely(h_parent != h_dentry->d_parent))
19847 + * initial procedure of adding a new entry.
19848 + * prepare writable branch and the parent dir, lock it,
19849 + * and lookup whiteout for the new entry.
19851 +static struct dentry*
19852 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19853 + struct dentry *src_dentry, struct au_pin *pin,
19854 + struct au_wr_dir_args *wr_dir_args)
19856 + struct dentry *wh_dentry, *h_parent;
19857 + struct super_block *sb;
19858 + struct au_branch *br;
19860 + unsigned int udba;
19861 + aufs_bindex_t bcpup;
19863 + AuDbg("%pd\n", dentry);
19865 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19867 + wh_dentry = ERR_PTR(err);
19868 + if (unlikely(err < 0))
19871 + sb = dentry->d_sb;
19872 + udba = au_opt_udba(sb);
19873 + err = au_pin(pin, dentry, bcpup, udba,
19874 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19875 + wh_dentry = ERR_PTR(err);
19876 + if (unlikely(err))
19879 + h_parent = au_pinned_h_parent(pin);
19880 + if (udba != AuOpt_UDBA_NONE
19881 + && au_dbtop(dentry) == bcpup)
19882 + err = au_may_add(dentry, bcpup, h_parent,
19883 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19884 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19885 + err = -ENAMETOOLONG;
19886 + wh_dentry = ERR_PTR(err);
19887 + if (unlikely(err))
19890 + br = au_sbr(sb, bcpup);
19892 + struct path tmp = {
19893 + .dentry = h_parent,
19894 + .mnt = au_br_mnt(br)
19896 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19899 + wh_dentry = NULL;
19900 + if (bcpup != au_dbwh(dentry))
19901 + goto out; /* success */
19904 + * ENAMETOOLONG here means that if we allowed create such name, then it
19905 + * would not be able to removed in the future. So we don't allow such
19906 + * name here and we don't handle ENAMETOOLONG differently here.
19908 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19911 + if (IS_ERR(wh_dentry))
19914 + return wh_dentry;
19917 +/* ---------------------------------------------------------------------- */
19919 +enum { Mknod, Symlink, Creat };
19920 +struct simple_arg {
19927 + struct vfsub_aopen_args *aopen;
19930 + const char *symname;
19939 +static int add_simple(struct inode *dir, struct dentry *dentry,
19940 + struct simple_arg *arg)
19943 + aufs_bindex_t btop;
19944 + unsigned char created;
19945 + const unsigned char try_aopen
19946 + = (arg->type == Creat && arg->u.c.try_aopen);
19947 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19948 + struct dentry *wh_dentry, *parent;
19949 + struct inode *h_dir;
19950 + struct super_block *sb;
19951 + struct au_branch *br;
19952 + /* to reduce stack size */
19954 + struct au_dtime dt;
19955 + struct au_pin pin;
19956 + struct path h_path;
19957 + struct au_wr_dir_args wr_dir_args;
19960 + AuDbg("%pd\n", dentry);
19964 + a = kmalloc(sizeof(*a), GFP_NOFS);
19965 + if (unlikely(!a))
19967 + a->wr_dir_args.force_btgt = -1;
19968 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19970 + parent = dentry->d_parent; /* dir inode is locked */
19971 + if (!try_aopen) {
19972 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19973 + if (unlikely(err))
19976 + err = au_d_may_add(dentry);
19977 + if (unlikely(err))
19980 + di_write_lock_parent(parent);
19981 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19982 + &a->pin, &a->wr_dir_args);
19983 + err = PTR_ERR(wh_dentry);
19984 + if (IS_ERR(wh_dentry))
19987 + btop = au_dbtop(dentry);
19988 + sb = dentry->d_sb;
19989 + br = au_sbr(sb, btop);
19990 + a->h_path.dentry = au_h_dptr(dentry, btop);
19991 + a->h_path.mnt = au_br_mnt(br);
19992 + h_dir = au_pinned_h_dir(&a->pin);
19993 + switch (arg->type) {
19995 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19996 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19997 + arg->u.c.want_excl);
19999 + if (!err && try_aopen)
20000 + aopen->file->f_mode |= FMODE_CREATED;
20003 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
20004 + AuDbg("err %d\n", err);
20005 + AuDbgFile(aopen->file);
20006 + created = err >= 0
20007 + && !!(aopen->file->f_mode & FMODE_CREATED);
20011 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20015 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20022 + if (unlikely(err < 0))
20025 + err = epilog(dir, btop, wh_dentry, dentry);
20027 + goto out_unpin; /* success */
20030 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20031 + /* no delegation since it is just created */
20032 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20035 + AuIOErr("%pd revert failure(%d, %d)\n",
20036 + dentry, err, rerr);
20039 + au_dtime_revert(&a->dt);
20041 + if (try_aopen && h_dir->i_op->atomic_open
20042 + && (aopen->file->f_mode & FMODE_OPENED))
20043 + /* aopen->file is still opened */
20044 + au_lcnt_dec(&aopen->br->br_nfiles);
20047 + au_unpin(&a->pin);
20051 + di_write_unlock(parent);
20053 + if (unlikely(err)) {
20054 + au_update_dbtop(dentry);
20058 + aufs_read_unlock(dentry, AuLock_DW);
20065 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20068 + struct simple_arg arg = {
20075 + return add_simple(dir, dentry, &arg);
20078 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20080 + struct simple_arg arg = {
20082 + .u.s.symname = symname
20084 + return add_simple(dir, dentry, &arg);
20087 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20090 + struct simple_arg arg = {
20094 + .want_excl = want_excl
20097 + return add_simple(dir, dentry, &arg);
20100 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20101 + struct vfsub_aopen_args *aopen_args)
20103 + struct simple_arg arg = {
20106 + .mode = aopen_args->create_mode,
20107 + .want_excl = aopen_args->open_flag & O_EXCL,
20108 + .try_aopen = true,
20109 + .aopen = aopen_args
20112 + return add_simple(dir, dentry, &arg);
20115 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20118 + aufs_bindex_t bindex;
20119 + struct super_block *sb;
20120 + struct dentry *parent, *h_parent, *h_dentry;
20121 + struct inode *h_dir, *inode;
20122 + struct vfsmount *h_mnt;
20123 + struct au_wr_dir_args wr_dir_args = {
20124 + .force_btgt = -1,
20125 + .flags = AuWrDir_TMPFILE
20128 + /* copy-up may happen */
20132 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20133 + if (unlikely(err))
20136 + err = au_di_init(dentry);
20137 + if (unlikely(err))
20141 + parent = d_find_any_alias(dir);
20142 + AuDebugOn(!parent);
20143 + di_write_lock_parent(parent);
20144 + if (unlikely(d_inode(parent) != dir))
20147 + err = au_digen_test(parent, au_sigen(sb));
20148 + if (unlikely(err))
20151 + bindex = au_dbtop(parent);
20152 + au_set_dbtop(dentry, bindex);
20153 + au_set_dbbot(dentry, bindex);
20154 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20156 + if (unlikely(err < 0))
20159 + err = -EOPNOTSUPP;
20160 + h_dir = au_h_iptr(dir, bindex);
20161 + if (unlikely(!h_dir->i_op->tmpfile))
20164 + h_mnt = au_sbr_mnt(sb, bindex);
20165 + err = vfsub_mnt_want_write(h_mnt);
20166 + if (unlikely(err))
20169 + h_parent = au_h_dptr(parent, bindex);
20170 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20171 + if (IS_ERR(h_dentry)) {
20172 + err = PTR_ERR(h_dentry);
20176 + au_set_dbtop(dentry, bindex);
20177 + au_set_dbbot(dentry, bindex);
20178 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20179 + inode = au_new_inode(dentry, /*must_new*/1);
20180 + if (IS_ERR(inode)) {
20181 + err = PTR_ERR(inode);
20182 + au_set_h_dptr(dentry, bindex, NULL);
20183 + au_set_dbtop(dentry, -1);
20184 + au_set_dbbot(dentry, -1);
20186 + if (!inode->i_nlink)
20187 + set_nlink(inode, 1);
20188 + d_tmpfile(dentry, inode);
20189 + au_di(dentry)->di_tmpfile = 1;
20191 + /* update without i_mutex */
20192 + if (au_ibtop(dir) == au_dbtop(dentry))
20193 + au_cpup_attr_timesizes(dir);
20198 + vfsub_mnt_drop_write(h_mnt);
20200 + di_write_unlock(parent);
20202 + di_write_unlock(dentry);
20203 + if (unlikely(err)) {
20204 + au_di_fin(dentry);
20205 + dentry->d_fsdata = NULL;
20208 + si_read_unlock(sb);
20210 + inode_unlock(dir);
20214 +/* ---------------------------------------------------------------------- */
20216 +struct au_link_args {
20217 + aufs_bindex_t bdst, bsrc;
20218 + struct au_pin pin;
20219 + struct path h_path;
20220 + struct dentry *src_parent, *parent;
20223 +static int au_cpup_before_link(struct dentry *src_dentry,
20224 + struct au_link_args *a)
20227 + struct dentry *h_src_dentry;
20228 + struct au_cp_generic cpg = {
20229 + .dentry = src_dentry,
20234 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20237 + di_read_lock_parent(a->src_parent, AuLock_IR);
20238 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20239 + if (unlikely(err))
20242 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20243 + err = au_pin(&a->pin, src_dentry, a->bdst,
20244 + au_opt_udba(src_dentry->d_sb),
20245 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20246 + if (unlikely(err))
20249 + err = au_sio_cpup_simple(&cpg);
20250 + au_unpin(&a->pin);
20253 + di_read_unlock(a->src_parent, AuLock_IR);
20257 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20258 + struct au_link_args *a)
20261 + unsigned char plink;
20262 + aufs_bindex_t bbot;
20263 + struct dentry *h_src_dentry;
20264 + struct inode *h_inode, *inode, *delegated;
20265 + struct super_block *sb;
20266 + struct file *h_file;
20270 + sb = src_dentry->d_sb;
20271 + inode = d_inode(src_dentry);
20272 + if (au_ibtop(inode) <= a->bdst)
20273 + h_inode = au_h_iptr(inode, a->bdst);
20274 + if (!h_inode || !h_inode->i_nlink) {
20275 + /* copyup src_dentry as the name of dentry. */
20276 + bbot = au_dbbot(dentry);
20277 + if (bbot < a->bsrc)
20278 + au_set_dbbot(dentry, a->bsrc);
20279 + au_set_h_dptr(dentry, a->bsrc,
20280 + dget(au_h_dptr(src_dentry, a->bsrc)));
20281 + dget(a->h_path.dentry);
20282 + au_set_h_dptr(dentry, a->bdst, NULL);
20283 + AuDbg("temporary d_inode...\n");
20284 + spin_lock(&dentry->d_lock);
20285 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20286 + spin_unlock(&dentry->d_lock);
20287 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20288 + if (IS_ERR(h_file))
20289 + err = PTR_ERR(h_file);
20291 + struct au_cp_generic cpg = {
20292 + .dentry = dentry,
20297 + .flags = AuCpup_KEEPLINO
20299 + err = au_sio_cpup_simple(&cpg);
20300 + au_h_open_post(dentry, a->bsrc, h_file);
20302 + dput(a->h_path.dentry);
20303 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20305 + au_set_h_dptr(dentry, a->bdst,
20306 + a->h_path.dentry);
20308 + spin_lock(&dentry->d_lock);
20309 + dentry->d_inode = NULL; /* restore */
20310 + spin_unlock(&dentry->d_lock);
20311 + AuDbg("temporary d_inode...done\n");
20312 + au_set_h_dptr(dentry, a->bsrc, NULL);
20313 + au_set_dbbot(dentry, bbot);
20315 + /* the inode of src_dentry already exists on a.bdst branch */
20316 + h_src_dentry = d_find_alias(h_inode);
20317 + if (!h_src_dentry && au_plink_test(inode)) {
20319 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20320 + err = PTR_ERR(h_src_dentry);
20321 + if (IS_ERR(h_src_dentry))
20324 + if (unlikely(d_is_negative(h_src_dentry))) {
20325 + dput(h_src_dentry);
20326 + h_src_dentry = NULL;
20330 + if (h_src_dentry) {
20331 + delegated = NULL;
20332 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20333 + &a->h_path, &delegated);
20334 + if (unlikely(err == -EWOULDBLOCK)) {
20335 + pr_warn("cannot retry for NFSv4 delegation"
20336 + " for an internal link\n");
20339 + dput(h_src_dentry);
20341 + AuIOErr("no dentry found for hi%lu on b%d\n",
20342 + h_inode->i_ino, a->bdst);
20347 + if (!err && !plink)
20348 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20355 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20356 + struct dentry *dentry)
20359 + struct au_dtime dt;
20360 + struct au_link_args *a;
20361 + struct dentry *wh_dentry, *h_src_dentry;
20362 + struct inode *inode, *delegated;
20363 + struct super_block *sb;
20364 + struct au_wr_dir_args wr_dir_args = {
20365 + /* .force_btgt = -1, */
20366 + .flags = AuWrDir_ADD_ENTRY
20370 + inode = d_inode(src_dentry);
20371 + IMustLock(inode);
20374 + a = kzalloc(sizeof(*a), GFP_NOFS);
20375 + if (unlikely(!a))
20378 + a->parent = dentry->d_parent; /* dir inode is locked */
20379 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20380 + AuLock_NOPLM | AuLock_GEN);
20381 + if (unlikely(err))
20383 + err = au_d_linkable(src_dentry);
20384 + if (unlikely(err))
20386 + err = au_d_may_add(dentry);
20387 + if (unlikely(err))
20390 + a->src_parent = dget_parent(src_dentry);
20391 + wr_dir_args.force_btgt = au_ibtop(inode);
20393 + di_write_lock_parent(a->parent);
20394 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20395 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20397 + err = PTR_ERR(wh_dentry);
20398 + if (IS_ERR(wh_dentry))
20402 + sb = dentry->d_sb;
20403 + a->bdst = au_dbtop(dentry);
20404 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20405 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20406 + a->bsrc = au_ibtop(inode);
20407 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20408 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20409 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20410 + if (!h_src_dentry) {
20411 + a->bsrc = au_dbtop(src_dentry);
20412 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20413 + AuDebugOn(!h_src_dentry);
20414 + } else if (IS_ERR(h_src_dentry)) {
20415 + err = PTR_ERR(h_src_dentry);
20420 + * aufs doesn't touch the credential so
20421 + * security_dentry_create_files_as() is unnecessary.
20423 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20424 + if (a->bdst < a->bsrc
20425 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20426 + err = au_cpup_or_link(src_dentry, dentry, a);
20428 + delegated = NULL;
20429 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20430 + &a->h_path, &delegated);
20431 + if (unlikely(err == -EWOULDBLOCK)) {
20432 + pr_warn("cannot retry for NFSv4 delegation"
20433 + " for an internal link\n");
20437 + dput(h_src_dentry);
20440 + * copyup src_dentry to the branch we process,
20441 + * and then link(2) to it.
20443 + dput(h_src_dentry);
20444 + if (a->bdst < a->bsrc
20445 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20446 + au_unpin(&a->pin);
20447 + di_write_unlock(a->parent);
20448 + err = au_cpup_before_link(src_dentry, a);
20449 + di_write_lock_parent(a->parent);
20451 + err = au_pin(&a->pin, dentry, a->bdst,
20453 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20454 + if (unlikely(err))
20458 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20460 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20461 + delegated = NULL;
20462 + err = vfsub_link(h_src_dentry,
20463 + au_pinned_h_dir(&a->pin),
20464 + &a->h_path, &delegated);
20465 + if (unlikely(err == -EWOULDBLOCK)) {
20466 + pr_warn("cannot retry"
20467 + " for NFSv4 delegation"
20468 + " for an internal link\n");
20474 + if (unlikely(err))
20478 + a->h_path.dentry = wh_dentry;
20479 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20481 + if (unlikely(err))
20485 + au_dir_ts(dir, a->bdst);
20486 + inode_inc_iversion(dir);
20487 + inc_nlink(inode);
20488 + inode->i_ctime = dir->i_ctime;
20489 + d_instantiate(dentry, au_igrab(inode));
20490 + if (d_unhashed(a->h_path.dentry))
20491 + /* some filesystem calls d_drop() */
20493 + /* some filesystems consume an inode even hardlink */
20494 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20495 + goto out_unpin; /* success */
20498 + /* no delegation since it is just created */
20499 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20500 + /*delegated*/NULL, /*force*/0);
20501 + if (unlikely(rerr)) {
20502 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20505 + au_dtime_revert(&dt);
20507 + au_unpin(&a->pin);
20511 + di_write_unlock(a->parent);
20512 + dput(a->src_parent);
20514 + if (unlikely(err)) {
20515 + au_update_dbtop(dentry);
20518 + aufs_read_and_write_unlock2(dentry, src_dentry);
20526 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20529 + aufs_bindex_t bindex;
20530 + unsigned char diropq;
20531 + struct path h_path;
20532 + struct dentry *wh_dentry, *parent, *opq_dentry;
20533 + struct inode *h_inode;
20534 + struct super_block *sb;
20536 + struct au_pin pin;
20537 + struct au_dtime dt;
20538 + } *a; /* reduce the stack usage */
20539 + struct au_wr_dir_args wr_dir_args = {
20540 + .force_btgt = -1,
20541 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20547 + a = kmalloc(sizeof(*a), GFP_NOFS);
20548 + if (unlikely(!a))
20551 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20552 + if (unlikely(err))
20554 + err = au_d_may_add(dentry);
20555 + if (unlikely(err))
20558 + parent = dentry->d_parent; /* dir inode is locked */
20559 + di_write_lock_parent(parent);
20560 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20561 + &a->pin, &wr_dir_args);
20562 + err = PTR_ERR(wh_dentry);
20563 + if (IS_ERR(wh_dentry))
20566 + sb = dentry->d_sb;
20567 + bindex = au_dbtop(dentry);
20568 + h_path.dentry = au_h_dptr(dentry, bindex);
20569 + h_path.mnt = au_sbr_mnt(sb, bindex);
20570 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20571 + if (unlikely(err))
20574 + /* make the dir opaque */
20576 + h_inode = d_inode(h_path.dentry);
20578 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20579 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20580 + opq_dentry = au_diropq_create(dentry, bindex);
20581 + inode_unlock(h_inode);
20582 + err = PTR_ERR(opq_dentry);
20583 + if (IS_ERR(opq_dentry))
20585 + dput(opq_dentry);
20589 + err = epilog(dir, bindex, wh_dentry, dentry);
20592 + goto out_unpin; /* success */
20597 + AuLabel(revert opq);
20598 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20599 + rerr = au_diropq_remove(dentry, bindex);
20600 + inode_unlock(h_inode);
20602 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20603 + dentry, err, rerr);
20609 + AuLabel(revert dir);
20610 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20612 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20613 + dentry, err, rerr);
20616 + au_dtime_revert(&a->dt);
20618 + au_unpin(&a->pin);
20621 + di_write_unlock(parent);
20623 + if (unlikely(err)) {
20624 + au_update_dbtop(dentry);
20627 + aufs_read_unlock(dentry, AuLock_DW);
20633 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20634 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20635 +++ linux/fs/aufs/i_op.c 2019-09-16 09:38:43.216175640 +0200
20637 +// SPDX-License-Identifier: GPL-2.0
20639 + * Copyright (C) 2005-2019 Junjiro R. Okajima
20641 + * This program, aufs is free software; you can redistribute it and/or modify
20642 + * it under the terms of the GNU General Public License as published by
20643 + * the Free Software Foundation; either version 2 of the License, or
20644 + * (at your option) any later version.
20646 + * This program is distributed in the hope that it will be useful,
20647 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20648 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20649 + * GNU General Public License for more details.
20651 + * You should have received a copy of the GNU General Public License
20652 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20656 + * inode operations (except add/del/rename)
20659 +#include <linux/device_cgroup.h>
20660 +#include <linux/fs_stack.h>
20661 +#include <linux/iversion.h>
20662 +#include <linux/namei.h>
20663 +#include <linux/security.h>
20666 +static int h_permission(struct inode *h_inode, int mask,
20667 + struct path *h_path, int brperm)
20670 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20673 + if (write_mask && IS_IMMUTABLE(h_inode))
20677 + if (((mask & MAY_EXEC)
20678 + && S_ISREG(h_inode->i_mode)
20679 + && (path_noexec(h_path)
20680 + || !(h_inode->i_mode & 0111))))
20684 + * - skip the lower fs test in the case of write to ro branch.
20685 + * - nfs dir permission write check is optimized, but a policy for
20686 + * link/rename requires a real check.
20687 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20688 + * in this case, generic_permission() returns -EOPNOTSUPP.
20690 + if ((write_mask && !au_br_writable(brperm))
20691 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20692 + && write_mask && !(mask & MAY_READ))
20693 + || !h_inode->i_op->permission) {
20694 + /* AuLabel(generic_permission); */
20695 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20696 + err = generic_permission(h_inode, mask);
20697 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20698 + err = h_inode->i_op->permission(h_inode, mask);
20701 + /* AuLabel(h_inode->permission); */
20702 + err = h_inode->i_op->permission(h_inode, mask);
20707 + err = devcgroup_inode_permission(h_inode, mask);
20709 + err = security_inode_permission(h_inode, mask);
20713 + /* todo: do we need to call ima_path_check()? */
20714 + struct path h_path = {
20718 + err = ima_path_check(&h_path,
20719 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20720 + IMA_COUNT_LEAVE);
20728 +static int aufs_permission(struct inode *inode, int mask)
20731 + aufs_bindex_t bindex, bbot;
20732 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20733 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20734 + struct inode *h_inode;
20735 + struct super_block *sb;
20736 + struct au_branch *br;
20738 + /* todo: support rcu-walk? */
20739 + if (mask & MAY_NOT_BLOCK)
20742 + sb = inode->i_sb;
20743 + si_read_lock(sb, AuLock_FLUSH);
20744 + ii_read_lock_child(inode);
20746 + err = au_iigen_test(inode, au_sigen(sb));
20747 + if (unlikely(err))
20753 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20754 + err = au_busy_or_stale();
20755 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20756 + if (unlikely(!h_inode
20757 + || (h_inode->i_mode & S_IFMT)
20758 + != (inode->i_mode & S_IFMT)))
20762 + bindex = au_ibtop(inode);
20763 + br = au_sbr(sb, bindex);
20764 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20767 + && !special_file(h_inode->i_mode)) {
20768 + /* test whether the upper writable branch exists */
20770 + for (; bindex >= 0; bindex--)
20771 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20779 + /* non-write to dir */
20781 + bbot = au_ibbot(inode);
20782 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20783 + h_inode = au_h_iptr(inode, bindex);
20785 + err = au_busy_or_stale();
20786 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20789 + br = au_sbr(sb, bindex);
20790 + err = h_permission(h_inode, mask, &br->br_path,
20796 + ii_read_unlock(inode);
20797 + si_read_unlock(sb);
20801 +/* ---------------------------------------------------------------------- */
20803 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20804 + unsigned int flags)
20806 + struct dentry *ret, *parent;
20807 + struct inode *inode;
20808 + struct super_block *sb;
20809 + int err, npositive;
20813 + /* todo: support rcu-walk? */
20814 + ret = ERR_PTR(-ECHILD);
20815 + if (flags & LOOKUP_RCU)
20818 + ret = ERR_PTR(-ENAMETOOLONG);
20819 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20823 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20824 + ret = ERR_PTR(err);
20825 + if (unlikely(err))
20828 + err = au_di_init(dentry);
20829 + ret = ERR_PTR(err);
20830 + if (unlikely(err))
20834 + npositive = 0; /* suppress a warning */
20835 + parent = dentry->d_parent; /* dir inode is locked */
20836 + di_read_lock_parent(parent, AuLock_IR);
20837 + err = au_alive_dir(parent);
20839 + err = au_digen_test(parent, au_sigen(sb));
20841 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20842 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20843 + AuLkup_ALLOW_NEG);
20846 + di_read_unlock(parent, AuLock_IR);
20847 + ret = ERR_PTR(err);
20848 + if (unlikely(err < 0))
20852 + inode = au_new_inode(dentry, /*must_new*/0);
20853 + if (IS_ERR(inode)) {
20854 + ret = (void *)inode;
20861 + atomic_inc(&inode->i_count);
20862 + ret = d_splice_alias(inode, dentry);
20864 + if (unlikely(d_need_lookup(dentry))) {
20865 + spin_lock(&dentry->d_lock);
20866 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20867 + spin_unlock(&dentry->d_lock);
20871 + if (!IS_ERR(ret)) {
20873 + if (ret && ret != dentry)
20874 + ii_write_unlock(inode);
20876 + ii_write_unlock(inode);
20883 + di_write_unlock(dentry);
20885 + si_read_unlock(sb);
20890 +/* ---------------------------------------------------------------------- */
20893 + * very dirty and complicated aufs ->atomic_open().
20894 + * aufs_atomic_open()
20895 + * + au_aopen_or_create()
20897 + * + vfsub_atomic_open()
20898 + * + branch fs ->atomic_open()
20899 + * may call the actual 'open' for h_file
20900 + * + inc br_nfiles only if opened
20901 + * + au_aopen_no_open() or au_aopen_do_open()
20903 + * au_aopen_do_open()
20904 + * + finish_open()
20905 + * + au_do_aopen()
20906 + * + au_do_open() the body of all 'open'
20907 + * + au_do_open_nondir()
20908 + * set the passed h_file
20910 + * au_aopen_no_open()
20911 + * + finish_no_open()
20914 +struct aopen_node {
20915 + struct hlist_bl_node hblist;
20916 + struct file *file, *h_file;
20919 +static int au_do_aopen(struct inode *inode, struct file *file)
20921 + struct hlist_bl_head *aopen;
20922 + struct hlist_bl_node *pos;
20923 + struct aopen_node *node;
20924 + struct au_do_open_args args = {
20926 + .open = au_do_open_nondir
20929 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20930 + hlist_bl_lock(aopen);
20931 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20932 + if (node->file == file) {
20933 + args.h_file = node->h_file;
20936 + hlist_bl_unlock(aopen);
20937 + /* AuDebugOn(!args.h_file); */
20939 + return au_do_open(file, &args);
20942 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20943 + struct aopen_node *aopen_node)
20946 + struct hlist_bl_head *aopen;
20949 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20950 + au_hbl_add(&aopen_node->hblist, aopen);
20951 + err = finish_open(file, dentry, au_do_aopen);
20952 + au_hbl_del(&aopen_node->hblist, aopen);
20953 + /* AuDbgFile(file); */
20954 + AuDbg("%pd%s%s\n", dentry,
20955 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20956 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20962 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20968 + err = finish_no_open(file, dentry);
20974 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20975 + struct file *file, unsigned int open_flag,
20976 + umode_t create_mode)
20978 + int err, did_open;
20979 + unsigned int lkup_flags;
20980 + aufs_bindex_t bindex;
20981 + struct super_block *sb;
20982 + struct dentry *parent, *d;
20983 + struct vfsub_aopen_args args = {
20984 + .open_flag = open_flag,
20985 + .create_mode = create_mode
20987 + struct aopen_node aopen_node = {
20992 + AuDbg("open_flag 0%o\n", open_flag);
20993 + AuDbgDentry(dentry);
20996 + if (!au_di(dentry)) {
20997 + lkup_flags = LOOKUP_OPEN;
20998 + if (open_flag & O_CREAT)
20999 + lkup_flags |= LOOKUP_CREATE;
21000 + d = aufs_lookup(dir, dentry, lkup_flags);
21002 + err = PTR_ERR(d);
21007 + * obsoleted dentry found.
21008 + * another error will be returned later.
21014 + AuDbgDentry(dentry);
21017 + if (d_is_positive(dentry)
21018 + || d_unhashed(dentry)
21019 + || d_unlinked(dentry)
21020 + || !(open_flag & O_CREAT)) {
21021 + err = au_aopen_no_open(file, dentry);
21022 + goto out; /* success */
21025 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21026 + if (unlikely(err))
21029 + sb = dentry->d_sb;
21030 + parent = dentry->d_parent; /* dir is locked */
21031 + di_write_lock_parent(parent);
21032 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21033 + if (unlikely(err < 0))
21036 + AuDbgDentry(dentry);
21037 + if (d_is_positive(dentry)) {
21038 + err = au_aopen_no_open(file, dentry);
21039 + goto out_parent; /* success */
21042 + args.file = alloc_empty_file(file->f_flags, current_cred());
21043 + err = PTR_ERR(args.file);
21044 + if (IS_ERR(args.file))
21047 + bindex = au_dbtop(dentry);
21048 + err = au_aopen_or_create(dir, dentry, &args);
21050 + AuDbgFile(args.file);
21051 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21052 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21055 + args.file = NULL;
21057 + di_write_unlock(parent);
21058 + di_write_unlock(dentry);
21059 + if (unlikely(err < 0)) {
21066 + err = au_aopen_no_open(file, dentry);
21068 + aopen_node.h_file = args.file;
21069 + err = au_aopen_do_open(file, dentry, &aopen_node);
21071 + if (unlikely(err < 0)) {
21075 + au_lcnt_dec(&args.br->br_nfiles);
21077 + goto out_sb; /* success */
21080 + di_write_unlock(parent);
21081 + di_write_unlock(dentry);
21083 + si_read_unlock(sb);
21091 +/* ---------------------------------------------------------------------- */
21093 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21094 + const unsigned char add_entry, aufs_bindex_t bcpup,
21095 + aufs_bindex_t btop)
21098 + struct dentry *h_parent;
21099 + struct inode *h_dir;
21102 + IMustLock(d_inode(parent));
21104 + di_write_lock_parent(parent);
21107 + if (!au_h_dptr(parent, bcpup)) {
21108 + if (btop > bcpup)
21109 + err = au_cpup_dirs(dentry, bcpup);
21110 + else if (btop < bcpup)
21111 + err = au_cpdown_dirs(dentry, bcpup);
21115 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21116 + h_parent = au_h_dptr(parent, bcpup);
21117 + h_dir = d_inode(h_parent);
21118 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21119 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21120 + /* todo: no unlock here */
21121 + inode_unlock_shared(h_dir);
21123 + AuDbg("bcpup %d\n", bcpup);
21125 + if (d_really_is_negative(dentry))
21126 + au_set_h_dptr(dentry, btop, NULL);
21127 + au_update_dbrange(dentry, /*do_put_zero*/0);
21132 + di_write_unlock(parent);
21134 + err = bcpup; /* success */
21141 + * decide the branch and the parent dir where we will create a new entry.
21142 + * returns new bindex or an error.
21143 + * copyup the parent dir if needed.
21145 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21146 + struct au_wr_dir_args *args)
21149 + unsigned int flags;
21150 + aufs_bindex_t bcpup, btop, src_btop;
21151 + const unsigned char add_entry
21152 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21153 + | au_ftest_wrdir(args->flags, TMPFILE);
21154 + struct super_block *sb;
21155 + struct dentry *parent;
21156 + struct au_sbinfo *sbinfo;
21158 + sb = dentry->d_sb;
21159 + sbinfo = au_sbi(sb);
21160 + parent = dget_parent(dentry);
21161 + btop = au_dbtop(dentry);
21163 + if (args->force_btgt < 0) {
21164 + if (src_dentry) {
21165 + src_btop = au_dbtop(src_dentry);
21166 + if (src_btop < btop)
21167 + bcpup = src_btop;
21168 + } else if (add_entry) {
21170 + if (au_ftest_wrdir(args->flags, ISDIR))
21171 + au_fset_wbr(flags, DIR);
21172 + err = AuWbrCreate(sbinfo, dentry, flags);
21176 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21178 + err = AuWbrCopyup(sbinfo, dentry);
21180 + if (!IS_ROOT(dentry)) {
21181 + di_read_lock_parent(parent, !AuLock_IR);
21182 + err = AuWbrCopyup(sbinfo, dentry);
21183 + di_read_unlock(parent, !AuLock_IR);
21185 + err = AuWbrCopyup(sbinfo, dentry);
21188 + if (unlikely(err < 0))
21192 + bcpup = args->force_btgt;
21193 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21196 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21198 + if (bcpup == btop)
21199 + goto out; /* success */
21201 + /* copyup the new parent into the branch we process */
21202 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21204 + if (d_really_is_negative(dentry)) {
21205 + au_set_h_dptr(dentry, btop, NULL);
21206 + au_set_dbtop(dentry, bcpup);
21207 + au_set_dbbot(dentry, bcpup);
21209 + AuDebugOn(add_entry
21210 + && !au_ftest_wrdir(args->flags, TMPFILE)
21211 + && !au_h_dptr(dentry, bcpup));
21219 +/* ---------------------------------------------------------------------- */
21221 +void au_pin_hdir_unlock(struct au_pin *p)
21224 + au_hn_inode_unlock(p->hdir);
21227 +int au_pin_hdir_lock(struct au_pin *p)
21235 + /* even if an error happens later, keep this lock */
21236 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21239 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21244 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21245 + p->h_parent, p->br);
21251 +int au_pin_hdir_relock(struct au_pin *p)
21254 + struct inode *h_i;
21255 + struct dentry *h_d[] = {
21260 + err = au_pin_hdir_lock(p);
21261 + if (unlikely(err))
21264 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21267 + if (d_is_positive(h_d[i])) {
21268 + h_i = d_inode(h_d[i]);
21269 + err = !h_i->i_nlink;
21277 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21279 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21282 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21285 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21286 + p->lsc_hi, 0, NULL, _RET_IP_);
21287 + au_pin_hdir_set_owner(p, current);
21291 +void au_pin_hdir_release(struct au_pin *p)
21294 + au_pin_hdir_set_owner(p, p->task);
21295 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21299 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21301 + if (pin && pin->parent)
21302 + return au_h_dptr(pin->parent, pin->bindex);
21306 +void au_unpin(struct au_pin *p)
21309 + au_pin_hdir_unlock(p);
21310 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21311 + vfsub_mnt_drop_write(p->h_mnt);
21315 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21316 + di_read_unlock(p->parent, AuLock_IR);
21317 + iput(p->hdir->hi_inode);
21319 + p->parent = NULL;
21322 + /* do not clear p->task */
21325 +int au_do_pin(struct au_pin *p)
21328 + struct super_block *sb;
21329 + struct inode *h_dir;
21332 + sb = p->dentry->d_sb;
21333 + p->br = au_sbr(sb, p->bindex);
21334 + if (IS_ROOT(p->dentry)) {
21335 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21336 + p->h_mnt = au_br_mnt(p->br);
21337 + err = vfsub_mnt_want_write(p->h_mnt);
21338 + if (unlikely(err)) {
21339 + au_fclr_pin(p->flags, MNT_WRITE);
21346 + p->h_dentry = NULL;
21347 + if (p->bindex <= au_dbbot(p->dentry))
21348 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21350 + p->parent = dget_parent(p->dentry);
21351 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21352 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21355 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21356 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21358 + h_dir = p->hdir->hi_inode;
21362 + * if DI_LOCKED is not set, then p->parent may be different
21363 + * and h_parent can be NULL.
21365 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21367 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21368 + di_read_unlock(p->parent, AuLock_IR);
21370 + p->parent = NULL;
21374 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21375 + p->h_mnt = au_br_mnt(p->br);
21376 + err = vfsub_mnt_want_write(p->h_mnt);
21377 + if (unlikely(err)) {
21378 + au_fclr_pin(p->flags, MNT_WRITE);
21379 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21380 + di_read_unlock(p->parent, AuLock_IR);
21382 + p->parent = NULL;
21388 + err = au_pin_hdir_lock(p);
21390 + goto out; /* success */
21395 + pr_err("err %d\n", err);
21396 + err = au_busy_or_stale();
21401 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21402 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21403 + unsigned int udba, unsigned char flags)
21405 + p->dentry = dentry;
21407 + p->lsc_di = lsc_di;
21408 + p->lsc_hi = lsc_hi;
21409 + p->flags = flags;
21410 + p->bindex = bindex;
21412 + p->parent = NULL;
21416 + p->h_dentry = NULL;
21417 + p->h_parent = NULL;
21419 + p->task = current;
21422 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21423 + unsigned int udba, unsigned char flags)
21425 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21427 + return au_do_pin(pin);
21430 +/* ---------------------------------------------------------------------- */
21433 + * ->setattr() and ->getattr() are called in various cases.
21434 + * chmod, stat: dentry is revalidated.
21435 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21437 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21439 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21440 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21443 + struct dentry *parent;
21446 + if (au_digen_test(dentry, sigen)) {
21447 + parent = dget_parent(dentry);
21448 + di_read_lock_parent(parent, AuLock_IR);
21449 + err = au_refresh_dentry(dentry, parent);
21450 + di_read_unlock(parent, AuLock_IR);
21458 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21459 + struct au_icpup_args *a)
21463 + aufs_bindex_t btop, ibtop;
21464 + struct dentry *hi_wh, *parent;
21465 + struct inode *inode;
21466 + struct au_wr_dir_args wr_dir_args = {
21467 + .force_btgt = -1,
21471 + if (d_is_dir(dentry))
21472 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21473 + /* plink or hi_wh() case */
21474 + btop = au_dbtop(dentry);
21475 + inode = d_inode(dentry);
21476 + ibtop = au_ibtop(inode);
21477 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21478 + wr_dir_args.force_btgt = ibtop;
21479 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21480 + if (unlikely(err < 0))
21484 + au_fset_icpup(a->flags, DID_CPUP);
21487 + a->pin_flags = AuPin_MNT_WRITE;
21489 + if (!IS_ROOT(dentry)) {
21490 + au_fset_pin(a->pin_flags, DI_LOCKED);
21491 + parent = dget_parent(dentry);
21492 + di_write_lock_parent(parent);
21495 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21496 + if (unlikely(err))
21500 + a->h_path.dentry = au_h_dptr(dentry, btop);
21501 + a->h_inode = d_inode(a->h_path.dentry);
21502 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21503 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21504 + if (ia->ia_size < i_size_read(a->h_inode))
21505 + sz = ia->ia_size;
21506 + inode_unlock_shared(a->h_inode);
21510 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21511 + hi_wh = au_hi_wh(inode, a->btgt);
21513 + struct au_cp_generic cpg = {
21514 + .dentry = dentry,
21520 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21521 + if (unlikely(err))
21523 + hi_wh = au_hi_wh(inode, a->btgt);
21524 + /* todo: revalidate hi_wh? */
21529 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21530 + di_downgrade_lock(parent, AuLock_IR);
21534 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21535 + goto out; /* success */
21537 + if (!d_unhashed(dentry)) {
21538 + struct au_cp_generic cpg = {
21539 + .dentry = dentry,
21544 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21546 + err = au_sio_cpup_simple(&cpg);
21548 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21549 + } else if (!hi_wh)
21550 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21552 + a->h_path.dentry = hi_wh; /* do not dget here */
21555 + a->h_inode = d_inode(a->h_path.dentry);
21557 + goto out; /* success */
21558 + au_unpin(&a->pin);
21561 + di_write_unlock(parent);
21566 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21570 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21573 + struct inode *inode, *delegated;
21574 + struct super_block *sb;
21575 + struct file *file;
21576 + struct au_icpup_args *a;
21578 + inode = d_inode(dentry);
21579 + IMustLock(inode);
21581 + err = setattr_prepare(dentry, ia);
21582 + if (unlikely(err))
21586 + a = kzalloc(sizeof(*a), GFP_NOFS);
21587 + if (unlikely(!a))
21590 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21591 + ia->ia_valid &= ~ATTR_MODE;
21594 + sb = dentry->d_sb;
21595 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21596 + if (unlikely(err))
21599 + if (ia->ia_valid & ATTR_FILE) {
21600 + /* currently ftruncate(2) only */
21601 + AuDebugOn(!d_is_reg(dentry));
21602 + file = ia->ia_file;
21603 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21605 + if (unlikely(err))
21607 + ia->ia_file = au_hf_top(file);
21608 + a->udba = AuOpt_UDBA_NONE;
21610 + /* fchmod() doesn't pass ia_file */
21611 + a->udba = au_opt_udba(sb);
21612 + di_write_lock_child(dentry);
21613 + /* no d_unlinked(), to set UDBA_NONE for root */
21614 + if (d_unhashed(dentry))
21615 + a->udba = AuOpt_UDBA_NONE;
21616 + if (a->udba != AuOpt_UDBA_NONE) {
21617 + AuDebugOn(IS_ROOT(dentry));
21618 + err = au_reval_for_attr(dentry, au_sigen(sb));
21619 + if (unlikely(err))
21624 + err = au_pin_and_icpup(dentry, ia, a);
21625 + if (unlikely(err < 0))
21627 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21628 + ia->ia_file = NULL;
21629 + ia->ia_valid &= ~ATTR_FILE;
21632 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21633 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21634 + == (ATTR_MODE | ATTR_CTIME)) {
21635 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21636 + if (unlikely(err))
21638 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21639 + && (ia->ia_valid & ATTR_CTIME)) {
21640 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21641 + if (unlikely(err))
21645 + if (ia->ia_valid & ATTR_SIZE) {
21648 + if (ia->ia_size < i_size_read(inode))
21650 + truncate_setsize(inode, ia->ia_size);
21653 + if (ia->ia_valid & ATTR_FILE)
21655 + inode_unlock(a->h_inode);
21656 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21657 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21659 + delegated = NULL;
21661 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21663 + err = break_deleg_wait(&delegated);
21671 + * regardless aufs 'acl' option setting.
21672 + * why don't all acl-aware fs call this func from their ->setattr()?
21674 + if (!err && (ia->ia_valid & ATTR_MODE))
21675 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21677 + au_cpup_attr_changeable(inode);
21680 + inode_unlock(a->h_inode);
21681 + au_unpin(&a->pin);
21682 + if (unlikely(err))
21683 + au_update_dbtop(dentry);
21685 + di_write_unlock(dentry);
21687 + fi_write_unlock(file);
21688 + ia->ia_file = file;
21689 + ia->ia_valid |= ATTR_FILE;
21692 + si_read_unlock(sb);
21700 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21701 +static int au_h_path_to_set_attr(struct dentry *dentry,
21702 + struct au_icpup_args *a, struct path *h_path)
21705 + struct super_block *sb;
21707 + sb = dentry->d_sb;
21708 + a->udba = au_opt_udba(sb);
21709 + /* no d_unlinked(), to set UDBA_NONE for root */
21710 + if (d_unhashed(dentry))
21711 + a->udba = AuOpt_UDBA_NONE;
21712 + if (a->udba != AuOpt_UDBA_NONE) {
21713 + AuDebugOn(IS_ROOT(dentry));
21714 + err = au_reval_for_attr(dentry, au_sigen(sb));
21715 + if (unlikely(err))
21718 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21719 + if (unlikely(err < 0))
21722 + h_path->dentry = a->h_path.dentry;
21723 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21729 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21730 + struct au_sxattr *arg)
21733 + struct path h_path;
21734 + struct super_block *sb;
21735 + struct au_icpup_args *a;
21736 + struct inode *h_inode;
21738 + IMustLock(inode);
21741 + a = kzalloc(sizeof(*a), GFP_NOFS);
21742 + if (unlikely(!a))
21745 + sb = dentry->d_sb;
21746 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21747 + if (unlikely(err))
21750 + h_path.dentry = NULL; /* silence gcc */
21751 + di_write_lock_child(dentry);
21752 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21753 + if (unlikely(err))
21756 + inode_unlock(a->h_inode);
21757 + switch (arg->type) {
21758 + case AU_XATTR_SET:
21759 + AuDebugOn(d_is_negative(h_path.dentry));
21760 + err = vfsub_setxattr(h_path.dentry,
21761 + arg->u.set.name, arg->u.set.value,
21762 + arg->u.set.size, arg->u.set.flags);
21765 + err = -EOPNOTSUPP;
21766 + h_inode = d_inode(h_path.dentry);
21767 + if (h_inode->i_op->set_acl)
21768 + /* this will call posix_acl_update_mode */
21769 + err = h_inode->i_op->set_acl(h_inode,
21770 + arg->u.acl_set.acl,
21771 + arg->u.acl_set.type);
21775 + au_cpup_attr_timesizes(inode);
21777 + au_unpin(&a->pin);
21778 + if (unlikely(err))
21779 + au_update_dbtop(dentry);
21782 + di_write_unlock(dentry);
21783 + si_read_unlock(sb);
21792 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21793 + unsigned int nlink)
21797 + inode->i_mode = st->mode;
21798 + /* don't i_[ug]id_write() here */
21799 + inode->i_uid = st->uid;
21800 + inode->i_gid = st->gid;
21801 + inode->i_atime = st->atime;
21802 + inode->i_mtime = st->mtime;
21803 + inode->i_ctime = st->ctime;
21805 + au_cpup_attr_nlink(inode, /*force*/0);
21806 + if (S_ISDIR(inode->i_mode)) {
21807 + n = inode->i_nlink;
21810 + smp_mb(); /* for i_nlink */
21811 + /* 0 can happen */
21812 + set_nlink(inode, n);
21815 + spin_lock(&inode->i_lock);
21816 + inode->i_blocks = st->blocks;
21817 + i_size_write(inode, st->size);
21818 + spin_unlock(&inode->i_lock);
21822 + * common routine for aufs_getattr() and au_getxattr().
21823 + * returns zero or negative (an error).
21824 + * @dentry will be read-locked in success.
21826 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21830 + unsigned int mnt_flags, sigen;
21831 + unsigned char udba_none;
21832 + aufs_bindex_t bindex;
21833 + struct super_block *sb, *h_sb;
21834 + struct inode *inode;
21836 + h_path->mnt = NULL;
21837 + h_path->dentry = NULL;
21840 + sb = dentry->d_sb;
21841 + mnt_flags = au_mntflags(sb);
21842 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21844 + if (unlikely(locked))
21845 + goto body; /* skip locking dinfo */
21847 + /* support fstat(2) */
21848 + if (!d_unlinked(dentry) && !udba_none) {
21849 + sigen = au_sigen(sb);
21850 + err = au_digen_test(dentry, sigen);
21852 + di_read_lock_child(dentry, AuLock_IR);
21853 + err = au_dbrange_test(dentry);
21854 + if (unlikely(err)) {
21855 + di_read_unlock(dentry, AuLock_IR);
21859 + AuDebugOn(IS_ROOT(dentry));
21860 + di_write_lock_child(dentry);
21861 + err = au_dbrange_test(dentry);
21863 + err = au_reval_for_attr(dentry, sigen);
21865 + di_downgrade_lock(dentry, AuLock_IR);
21867 + di_write_unlock(dentry);
21872 + di_read_lock_child(dentry, AuLock_IR);
21875 + inode = d_inode(dentry);
21876 + bindex = au_ibtop(inode);
21877 + h_path->mnt = au_sbr_mnt(sb, bindex);
21878 + h_sb = h_path->mnt->mnt_sb;
21880 + && !au_test_fs_bad_iattr(h_sb)
21882 + goto out; /* success */
21884 + if (au_dbtop(dentry) == bindex)
21885 + h_path->dentry = au_h_dptr(dentry, bindex);
21886 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21887 + h_path->dentry = au_plink_lkup(inode, bindex);
21888 + if (IS_ERR(h_path->dentry))
21889 + /* pretending success */
21890 + h_path->dentry = NULL;
21892 + dput(h_path->dentry);
21899 +static int aufs_getattr(const struct path *path, struct kstat *st,
21900 + u32 request, unsigned int query)
21903 + unsigned char positive;
21904 + struct path h_path;
21905 + struct dentry *dentry;
21906 + struct inode *inode;
21907 + struct super_block *sb;
21909 + dentry = path->dentry;
21910 + inode = d_inode(dentry);
21911 + sb = dentry->d_sb;
21912 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21913 + if (unlikely(err))
21915 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21916 + if (unlikely(err))
21918 + if (unlikely(!h_path.dentry))
21919 + /* illegally overlapped or something */
21920 + goto out_fill; /* pretending success */
21922 + positive = d_is_positive(h_path.dentry);
21924 + /* no vfsub version */
21925 + err = vfs_getattr(&h_path, st, request, query);
21928 + au_refresh_iattr(inode, st,
21929 + d_inode(h_path.dentry)->i_nlink);
21930 + goto out_fill; /* success */
21936 + generic_fillattr(inode, st);
21938 + di_read_unlock(dentry, AuLock_IR);
21940 + si_read_unlock(sb);
21946 +/* ---------------------------------------------------------------------- */
21948 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21949 + struct delayed_call *done)
21952 + struct dentry *h_dentry;
21953 + struct inode *h_inode;
21955 + aufs_bindex_t bindex;
21957 + ret = NULL; /* suppress a warning */
21962 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21963 + if (unlikely(err))
21966 + err = au_d_hashed_positive(dentry);
21967 + if (unlikely(err))
21971 + inode = d_inode(dentry);
21972 + bindex = au_ibtop(inode);
21973 + h_inode = au_h_iptr(inode, bindex);
21974 + if (unlikely(!h_inode->i_op->get_link))
21979 + if (au_dbtop(dentry) <= bindex) {
21980 + h_dentry = au_h_dptr(dentry, bindex);
21985 + h_dentry = d_find_any_alias(h_inode);
21986 + if (IS_ERR(h_dentry)) {
21987 + err = PTR_ERR(h_dentry);
21991 + if (unlikely(!h_dentry))
21995 + AuDbg("%ps\n", h_inode->i_op->get_link);
21996 + AuDbgDentry(h_dentry);
21997 + ret = vfs_get_link(h_dentry, done);
22000 + err = PTR_ERR(ret);
22003 + aufs_read_unlock(dentry, AuLock_IR);
22005 + if (unlikely(err))
22006 + ret = ERR_PTR(err);
22007 + AuTraceErrPtr(ret);
22011 +/* ---------------------------------------------------------------------- */
22013 +static int au_is_special(struct inode *inode)
22015 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
22018 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
22022 + aufs_bindex_t bindex;
22023 + struct super_block *sb;
22024 + struct inode *h_inode;
22025 + struct vfsmount *h_mnt;
22027 + sb = inode->i_sb;
22028 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
22029 + "unexpected s_flags 0x%lx", sb->s_flags);
22031 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
22033 + si_read_lock(sb, AuLock_FLUSH);
22034 + ii_write_lock_child(inode);
22037 + bindex = au_ibtop(inode);
22038 + h_inode = au_h_iptr(inode, bindex);
22039 + if (!au_test_ro(sb, bindex, inode)) {
22040 + h_mnt = au_sbr_mnt(sb, bindex);
22041 + err = vfsub_mnt_want_write(h_mnt);
22043 + err = vfsub_update_time(h_inode, ts, flags);
22044 + vfsub_mnt_drop_write(h_mnt);
22046 + } else if (au_is_special(h_inode)) {
22048 + * Never copy-up here.
22049 + * These special files may already be opened and used for
22050 + * communicating. If we copied it up, then the communication
22051 + * would be corrupted.
22053 + AuWarn1("timestamps for i%lu are ignored "
22054 + "since it is on readonly branch (hi%lu).\n",
22055 + inode->i_ino, h_inode->i_ino);
22056 + } else if (flags & ~S_ATIME) {
22058 + AuIOErr1("unexpected flags 0x%x\n", flags);
22063 + au_cpup_attr_timesizes(inode);
22064 + ii_write_unlock(inode);
22065 + si_read_unlock(sb);
22068 + if (!err && (flags & S_VERSION))
22069 + inode_inc_iversion(inode);
22074 +/* ---------------------------------------------------------------------- */
22076 +/* no getattr version will be set by module.c:aufs_init() */
22077 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22079 + [AuIop_SYMLINK] = {
22080 + .permission = aufs_permission,
22081 +#ifdef CONFIG_FS_POSIX_ACL
22082 + .get_acl = aufs_get_acl,
22083 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22086 + .setattr = aufs_setattr,
22087 + .getattr = aufs_getattr,
22089 +#ifdef CONFIG_AUFS_XATTR
22090 + .listxattr = aufs_listxattr,
22093 + .get_link = aufs_get_link,
22095 + /* .update_time = aufs_update_time */
22098 + .create = aufs_create,
22099 + .lookup = aufs_lookup,
22100 + .link = aufs_link,
22101 + .unlink = aufs_unlink,
22102 + .symlink = aufs_symlink,
22103 + .mkdir = aufs_mkdir,
22104 + .rmdir = aufs_rmdir,
22105 + .mknod = aufs_mknod,
22106 + .rename = aufs_rename,
22108 + .permission = aufs_permission,
22109 +#ifdef CONFIG_FS_POSIX_ACL
22110 + .get_acl = aufs_get_acl,
22111 + .set_acl = aufs_set_acl,
22114 + .setattr = aufs_setattr,
22115 + .getattr = aufs_getattr,
22117 +#ifdef CONFIG_AUFS_XATTR
22118 + .listxattr = aufs_listxattr,
22121 + .update_time = aufs_update_time,
22122 + .atomic_open = aufs_atomic_open,
22123 + .tmpfile = aufs_tmpfile
22125 + [AuIop_OTHER] = {
22126 + .permission = aufs_permission,
22127 +#ifdef CONFIG_FS_POSIX_ACL
22128 + .get_acl = aufs_get_acl,
22129 + .set_acl = aufs_set_acl,
22132 + .setattr = aufs_setattr,
22133 + .getattr = aufs_getattr,
22135 +#ifdef CONFIG_AUFS_XATTR
22136 + .listxattr = aufs_listxattr,
22139 + .update_time = aufs_update_time
22142 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22143 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22144 +++ linux/fs/aufs/i_op_del.c 2019-07-11 15:42:14.468904634 +0200
22146 +// SPDX-License-Identifier: GPL-2.0
22148 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22150 + * This program, aufs is free software; you can redistribute it and/or modify
22151 + * it under the terms of the GNU General Public License as published by
22152 + * the Free Software Foundation; either version 2 of the License, or
22153 + * (at your option) any later version.
22155 + * This program is distributed in the hope that it will be useful,
22156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22158 + * GNU General Public License for more details.
22160 + * You should have received a copy of the GNU General Public License
22161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22165 + * inode operations (del entry)
22168 +#include <linux/iversion.h>
22172 + * decide if a new whiteout for @dentry is necessary or not.
22173 + * when it is necessary, prepare the parent dir for the upper branch whose
22174 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22175 + * be done by caller.
22177 + * 0: wh is unnecessary
22178 + * plus: wh is necessary
22181 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22183 + int need_wh, err;
22184 + aufs_bindex_t btop;
22185 + struct super_block *sb;
22187 + sb = dentry->d_sb;
22188 + btop = au_dbtop(dentry);
22189 + if (*bcpup < 0) {
22191 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22192 + err = AuWbrCopyup(au_sbi(sb), dentry);
22194 + if (unlikely(err < 0))
22198 + AuDebugOn(btop < *bcpup
22199 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22200 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22202 + if (*bcpup != btop) {
22203 + err = au_cpup_dirs(dentry, *bcpup);
22204 + if (unlikely(err))
22208 + struct au_dinfo *dinfo, *tmp;
22210 + need_wh = -ENOMEM;
22211 + dinfo = au_di(dentry);
22212 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22214 + au_di_cp(tmp, dinfo);
22215 + au_di_swap(tmp, dinfo);
22216 + /* returns the number of positive dentries */
22217 + need_wh = au_lkup_dentry(dentry, btop + 1,
22218 + /* AuLkup_IGNORE_PERM */ 0);
22219 + au_di_swap(tmp, dinfo);
22220 + au_rw_write_unlock(&tmp->di_rwsem);
22224 + AuDbg("need_wh %d\n", need_wh);
22232 + * simple tests for the del-entry operations.
22233 + * following the checks in vfs, plus the parent-child relationship.
22235 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22236 + struct dentry *h_parent, int isdir)
22240 + struct dentry *h_dentry, *h_latest;
22241 + struct inode *h_inode;
22243 + h_dentry = au_h_dptr(dentry, bindex);
22244 + if (d_really_is_positive(dentry)) {
22246 + if (unlikely(d_is_negative(h_dentry)))
22248 + h_inode = d_inode(h_dentry);
22249 + if (unlikely(!h_inode->i_nlink))
22252 + h_mode = h_inode->i_mode;
22255 + if (unlikely(S_ISDIR(h_mode)))
22257 + } else if (unlikely(!S_ISDIR(h_mode))) {
22262 + /* rename(2) case */
22264 + if (unlikely(d_is_positive(h_dentry)))
22269 + /* expected parent dir is locked */
22270 + if (unlikely(h_parent != h_dentry->d_parent))
22275 + * rmdir a dir may break the consistency on some filesystem.
22276 + * let's try heavy test.
22279 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22280 + && au_test_h_perm(d_inode(h_parent),
22281 + MAY_EXEC | MAY_WRITE)))
22284 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22286 + if (IS_ERR(h_latest))
22288 + if (h_latest == h_dentry)
22297 + * decide the branch where we operate for @dentry. the branch index will be set
22298 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22299 + * dir for reverting.
22300 + * when a new whiteout is necessary, create it.
22302 +static struct dentry*
22303 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22304 + struct au_dtime *dt, struct au_pin *pin)
22306 + struct dentry *wh_dentry;
22307 + struct super_block *sb;
22308 + struct path h_path;
22309 + int err, need_wh;
22310 + unsigned int udba;
22311 + aufs_bindex_t bcpup;
22313 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22314 + wh_dentry = ERR_PTR(need_wh);
22315 + if (unlikely(need_wh < 0))
22318 + sb = dentry->d_sb;
22319 + udba = au_opt_udba(sb);
22321 + err = au_pin(pin, dentry, bcpup, udba,
22322 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22323 + wh_dentry = ERR_PTR(err);
22324 + if (unlikely(err))
22327 + h_path.dentry = au_pinned_h_parent(pin);
22328 + if (udba != AuOpt_UDBA_NONE
22329 + && au_dbtop(dentry) == bcpup) {
22330 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22331 + wh_dentry = ERR_PTR(err);
22332 + if (unlikely(err))
22336 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22337 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22338 + wh_dentry = NULL;
22340 + goto out; /* success, no need to create whiteout */
22342 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22343 + if (IS_ERR(wh_dentry))
22346 + /* returns with the parent is locked and wh_dentry is dget-ed */
22347 + goto out; /* success */
22352 + return wh_dentry;
22356 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22357 + * in order to be revertible and save time for removing many child whiteouts
22359 + * returns 1 when there are too many child whiteout and caller should remove
22360 + * them asynchronously. returns 0 when the number of children is enough small to
22361 + * remove now or the branch fs is a remote fs.
22362 + * otherwise return an error.
22364 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22365 + struct au_nhash *whlist, struct inode *dir)
22367 + int rmdir_later, err, dirwh;
22368 + struct dentry *h_dentry;
22369 + struct super_block *sb;
22370 + struct inode *inode;
22372 + sb = dentry->d_sb;
22373 + SiMustAnyLock(sb);
22374 + h_dentry = au_h_dptr(dentry, bindex);
22375 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22376 + if (unlikely(err))
22379 + /* stop monitoring */
22380 + inode = d_inode(dentry);
22381 + au_hn_free(au_hi(inode, bindex));
22383 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22384 + dirwh = au_sbi(sb)->si_dirwh;
22385 + rmdir_later = (dirwh <= 1);
22386 + if (!rmdir_later)
22387 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22390 + return rmdir_later;
22393 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22394 + if (unlikely(err)) {
22395 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22396 + h_dentry, bindex, err);
22406 + * final procedure for deleting a entry.
22407 + * maintain dentry and iattr.
22409 +static void epilog(struct inode *dir, struct dentry *dentry,
22410 + aufs_bindex_t bindex)
22412 + struct inode *inode;
22414 + inode = d_inode(dentry);
22416 + inode->i_ctime = dir->i_ctime;
22418 + au_dir_ts(dir, bindex);
22419 + inode_inc_iversion(dir);
22423 + * when an error happened, remove the created whiteout and revert everything.
22425 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22426 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22427 + struct dentry *dentry, struct au_dtime *dt)
22430 + struct path h_path = {
22431 + .dentry = wh_dentry,
22432 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22435 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22437 + au_set_dbwh(dentry, bwh);
22438 + au_dtime_revert(dt);
22442 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22446 +/* ---------------------------------------------------------------------- */
22448 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22451 + aufs_bindex_t bwh, bindex, btop;
22452 + struct inode *inode, *h_dir, *delegated;
22453 + struct dentry *parent, *wh_dentry;
22454 + /* to reduce stack size */
22456 + struct au_dtime dt;
22457 + struct au_pin pin;
22458 + struct path h_path;
22464 + a = kmalloc(sizeof(*a), GFP_NOFS);
22465 + if (unlikely(!a))
22468 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22469 + if (unlikely(err))
22471 + err = au_d_hashed_positive(dentry);
22472 + if (unlikely(err))
22474 + inode = d_inode(dentry);
22475 + IMustLock(inode);
22477 + if (unlikely(d_is_dir(dentry)))
22478 + goto out_unlock; /* possible? */
22480 + btop = au_dbtop(dentry);
22481 + bwh = au_dbwh(dentry);
22483 + parent = dentry->d_parent; /* dir inode is locked */
22484 + di_write_lock_parent(parent);
22485 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22487 + err = PTR_ERR(wh_dentry);
22488 + if (IS_ERR(wh_dentry))
22491 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22492 + a->h_path.dentry = au_h_dptr(dentry, btop);
22493 + dget(a->h_path.dentry);
22494 + if (bindex == btop) {
22495 + h_dir = au_pinned_h_dir(&a->pin);
22496 + delegated = NULL;
22497 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22498 + if (unlikely(err == -EWOULDBLOCK)) {
22499 + pr_warn("cannot retry for NFSv4 delegation"
22500 + " for an internal unlink\n");
22504 + /* dir inode is locked */
22505 + h_dir = d_inode(wh_dentry->d_parent);
22506 + IMustLock(h_dir);
22511 + vfsub_drop_nlink(inode);
22512 + epilog(dir, dentry, bindex);
22514 + /* update target timestamps */
22515 + if (bindex == btop) {
22516 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22518 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22520 + /* todo: this timestamp may be reverted later */
22521 + inode->i_ctime = h_dir->i_ctime;
22522 + goto out_unpin; /* success */
22529 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22536 + au_unpin(&a->pin);
22538 + dput(a->h_path.dentry);
22540 + di_write_unlock(parent);
22542 + aufs_read_unlock(dentry, AuLock_DW);
22549 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22551 + int err, rmdir_later;
22552 + aufs_bindex_t bwh, bindex, btop;
22553 + struct inode *inode;
22554 + struct dentry *parent, *wh_dentry, *h_dentry;
22555 + struct au_whtmp_rmdir *args;
22556 + /* to reduce stack size */
22558 + struct au_dtime dt;
22559 + struct au_pin pin;
22565 + a = kmalloc(sizeof(*a), GFP_NOFS);
22566 + if (unlikely(!a))
22569 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22570 + if (unlikely(err))
22572 + err = au_alive_dir(dentry);
22573 + if (unlikely(err))
22575 + inode = d_inode(dentry);
22576 + IMustLock(inode);
22578 + if (unlikely(!d_is_dir(dentry)))
22579 + goto out_unlock; /* possible? */
22582 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22583 + if (unlikely(!args))
22586 + parent = dentry->d_parent; /* dir inode is locked */
22587 + di_write_lock_parent(parent);
22588 + err = au_test_empty(dentry, &args->whlist);
22589 + if (unlikely(err))
22592 + btop = au_dbtop(dentry);
22593 + bwh = au_dbwh(dentry);
22595 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22597 + err = PTR_ERR(wh_dentry);
22598 + if (IS_ERR(wh_dentry))
22601 + h_dentry = au_h_dptr(dentry, btop);
22604 + if (bindex == btop) {
22605 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22607 + rmdir_later = err;
22611 + /* stop monitoring */
22612 + au_hn_free(au_hi(inode, btop));
22614 + /* dir inode is locked */
22615 + IMustLock(d_inode(wh_dentry->d_parent));
22620 + vfsub_dead_dir(inode);
22621 + au_set_dbdiropq(dentry, -1);
22622 + epilog(dir, dentry, bindex);
22624 + if (rmdir_later) {
22625 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22629 + goto out_unpin; /* success */
22637 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22644 + au_unpin(&a->pin);
22648 + di_write_unlock(parent);
22650 + au_whtmp_rmdir_free(args);
22652 + aufs_read_unlock(dentry, AuLock_DW);
22659 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22660 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22661 +++ linux/fs/aufs/i_op_ren.c 2019-07-11 15:42:14.468904634 +0200
22663 +// SPDX-License-Identifier: GPL-2.0
22665 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22667 + * This program, aufs is free software; you can redistribute it and/or modify
22668 + * it under the terms of the GNU General Public License as published by
22669 + * the Free Software Foundation; either version 2 of the License, or
22670 + * (at your option) any later version.
22672 + * This program is distributed in the hope that it will be useful,
22673 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22674 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22675 + * GNU General Public License for more details.
22677 + * You should have received a copy of the GNU General Public License
22678 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22682 + * inode operation (rename entry)
22683 + * todo: this is crazy monster
22686 +#include <linux/iversion.h>
22689 +enum { AuSRC, AuDST, AuSrcDst };
22690 +enum { AuPARENT, AuCHILD, AuParentChild };
22692 +#define AuRen_ISDIR_SRC 1
22693 +#define AuRen_ISDIR_DST (1 << 1)
22694 +#define AuRen_ISSAMEDIR (1 << 2)
22695 +#define AuRen_WHSRC (1 << 3)
22696 +#define AuRen_WHDST (1 << 4)
22697 +#define AuRen_MNT_WRITE (1 << 5)
22698 +#define AuRen_DT_DSTDIR (1 << 6)
22699 +#define AuRen_DIROPQ_SRC (1 << 7)
22700 +#define AuRen_DIROPQ_DST (1 << 8)
22701 +#define AuRen_DIRREN (1 << 9)
22702 +#define AuRen_DROPPED_SRC (1 << 10)
22703 +#define AuRen_DROPPED_DST (1 << 11)
22704 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22705 +#define au_fset_ren(flags, name) \
22706 + do { (flags) |= AuRen_##name; } while (0)
22707 +#define au_fclr_ren(flags, name) \
22708 + do { (flags) &= ~AuRen_##name; } while (0)
22710 +#ifndef CONFIG_AUFS_DIRREN
22711 +#undef AuRen_DIRREN
22712 +#define AuRen_DIRREN 0
22715 +struct au_ren_args {
22717 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22719 + struct inode *dir, *inode;
22720 + struct au_hinode *hdir, *hinode;
22721 + struct au_dtime dt[AuParentChild];
22722 + aufs_bindex_t btop, bdiropq;
22725 +#define src_dentry sd[AuSRC].dentry
22726 +#define src_dir sd[AuSRC].dir
22727 +#define src_inode sd[AuSRC].inode
22728 +#define src_h_dentry sd[AuSRC].h_dentry
22729 +#define src_parent sd[AuSRC].parent
22730 +#define src_h_parent sd[AuSRC].h_parent
22731 +#define src_wh_dentry sd[AuSRC].wh_dentry
22732 +#define src_hdir sd[AuSRC].hdir
22733 +#define src_hinode sd[AuSRC].hinode
22734 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22735 +#define src_dt sd[AuSRC].dt
22736 +#define src_btop sd[AuSRC].btop
22737 +#define src_bdiropq sd[AuSRC].bdiropq
22739 +#define dst_dentry sd[AuDST].dentry
22740 +#define dst_dir sd[AuDST].dir
22741 +#define dst_inode sd[AuDST].inode
22742 +#define dst_h_dentry sd[AuDST].h_dentry
22743 +#define dst_parent sd[AuDST].parent
22744 +#define dst_h_parent sd[AuDST].h_parent
22745 +#define dst_wh_dentry sd[AuDST].wh_dentry
22746 +#define dst_hdir sd[AuDST].hdir
22747 +#define dst_hinode sd[AuDST].hinode
22748 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22749 +#define dst_dt sd[AuDST].dt
22750 +#define dst_btop sd[AuDST].btop
22751 +#define dst_bdiropq sd[AuDST].bdiropq
22753 + struct dentry *h_trap;
22754 + struct au_branch *br;
22755 + struct path h_path;
22756 + struct au_nhash whlist;
22757 + aufs_bindex_t btgt, src_bwh;
22760 + unsigned short auren_flags;
22761 + unsigned char flags; /* syscall parameter */
22762 + unsigned char exchange;
22765 + struct au_whtmp_rmdir *thargs;
22766 + struct dentry *h_dst;
22767 + struct au_hinode *h_root;
22770 +/* ---------------------------------------------------------------------- */
22773 + * functions for reverting.
22774 + * when an error happened in a single rename systemcall, we should revert
22775 + * everything as if nothing happened.
22776 + * we don't need to revert the copied-up/down the parent dir since they are
22780 +#define RevertFailure(fmt, ...) do { \
22781 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22782 + ##__VA_ARGS__, err, rerr); \
22786 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22789 + struct dentry *d;
22790 +#define src_or_dst(member) a->sd[idx].member
22792 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22793 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22794 + rerr = au_diropq_remove(d, a->btgt);
22795 + au_hn_inode_unlock(src_or_dst(hinode));
22796 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22798 + RevertFailure("remove diropq %pd", d);
22800 +#undef src_or_dst_
22803 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22805 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22806 + au_ren_do_rev_diropq(err, a, AuSRC);
22807 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22808 + au_ren_do_rev_diropq(err, a, AuDST);
22811 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22814 + struct inode *delegated;
22816 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22817 + a->src_h_parent);
22818 + rerr = PTR_ERR(a->h_path.dentry);
22819 + if (IS_ERR(a->h_path.dentry)) {
22820 + RevertFailure("lkup one %pd", a->src_dentry);
22824 + delegated = NULL;
22825 + rerr = vfsub_rename(a->dst_h_dir,
22826 + au_h_dptr(a->src_dentry, a->btgt),
22827 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22828 + if (unlikely(rerr == -EWOULDBLOCK)) {
22829 + pr_warn("cannot retry for NFSv4 delegation"
22830 + " for an internal rename\n");
22833 + d_drop(a->h_path.dentry);
22834 + dput(a->h_path.dentry);
22835 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22837 + RevertFailure("rename %pd", a->src_dentry);
22840 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22843 + struct inode *delegated;
22845 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22846 + a->dst_h_parent);
22847 + rerr = PTR_ERR(a->h_path.dentry);
22848 + if (IS_ERR(a->h_path.dentry)) {
22849 + RevertFailure("lkup one %pd", a->dst_dentry);
22852 + if (d_is_positive(a->h_path.dentry)) {
22853 + d_drop(a->h_path.dentry);
22854 + dput(a->h_path.dentry);
22858 + delegated = NULL;
22859 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22860 + &delegated, a->flags);
22861 + if (unlikely(rerr == -EWOULDBLOCK)) {
22862 + pr_warn("cannot retry for NFSv4 delegation"
22863 + " for an internal rename\n");
22866 + d_drop(a->h_path.dentry);
22867 + dput(a->h_path.dentry);
22869 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22871 + RevertFailure("rename %pd", a->h_dst);
22874 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22878 + a->h_path.dentry = a->src_wh_dentry;
22879 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22880 + au_set_dbwh(a->src_dentry, a->src_bwh);
22882 + RevertFailure("unlink %pd", a->src_wh_dentry);
22884 +#undef RevertFailure
22886 +/* ---------------------------------------------------------------------- */
22889 + * when we have to copyup the renaming entry, do it with the rename-target name
22890 + * in order to minimize the cost (the later actual rename is unnecessary).
22891 + * otherwise rename it on the target branch.
22893 +static int au_ren_or_cpup(struct au_ren_args *a)
22896 + struct dentry *d;
22897 + struct inode *delegated;
22899 + d = a->src_dentry;
22900 + if (au_dbtop(d) == a->btgt) {
22901 + a->h_path.dentry = a->dst_h_dentry;
22902 + AuDebugOn(au_dbtop(d) != a->btgt);
22903 + delegated = NULL;
22904 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22905 + a->dst_h_dir, &a->h_path, &delegated,
22907 + if (unlikely(err == -EWOULDBLOCK)) {
22908 + pr_warn("cannot retry for NFSv4 delegation"
22909 + " for an internal rename\n");
22915 + if (!err && a->h_dst)
22916 + /* it will be set to dinfo later */
22922 +/* cf. aufs_rmdir() */
22923 +static int au_ren_del_whtmp(struct au_ren_args *a)
22926 + struct inode *dir;
22928 + dir = a->dst_dir;
22929 + SiMustAnyLock(dir->i_sb);
22930 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22931 + au_sbi(dir->i_sb)->si_dirwh)
22932 + || au_test_fs_remote(a->h_dst->d_sb)) {
22933 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22934 + if (unlikely(err))
22935 + pr_warn("failed removing whtmp dir %pd (%d), "
22936 + "ignored.\n", a->h_dst, err);
22938 + au_nhash_wh_free(&a->thargs->whlist);
22939 + a->thargs->whlist = a->whlist;
22940 + a->whlist.nh_num = 0;
22941 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22943 + a->thargs = NULL;
22949 +/* make it 'opaque' dir. */
22950 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22953 + struct dentry *d, *diropq;
22954 +#define src_or_dst(member) a->sd[idx].member
22957 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22958 + src_or_dst(bdiropq) = au_dbdiropq(d);
22959 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22960 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22961 + diropq = au_diropq_create(d, a->btgt);
22962 + au_hn_inode_unlock(src_or_dst(hinode));
22963 + if (IS_ERR(diropq))
22964 + err = PTR_ERR(diropq);
22968 +#undef src_or_dst_
22972 +static int au_ren_diropq(struct au_ren_args *a)
22975 + unsigned char always;
22976 + struct dentry *d;
22979 + d = a->dst_dentry; /* already renamed on the branch */
22980 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22981 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22982 + && !au_ftest_ren(a->auren_flags, DIRREN)
22983 + && a->btgt != au_dbdiropq(a->src_dentry)
22984 + && (a->dst_wh_dentry
22985 + || a->btgt <= au_dbdiropq(d)
22986 + /* hide the lower to keep xino */
22987 + /* the lowers may not be a dir, but we hide them anyway */
22988 + || a->btgt < au_dbbot(d)
22991 + err = au_ren_do_diropq(a, AuSRC);
22992 + if (unlikely(err))
22994 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22996 + if (!a->exchange)
22997 + goto out; /* success */
22999 + d = a->src_dentry; /* already renamed on the branch */
23000 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23001 + && a->btgt != au_dbdiropq(a->dst_dentry)
23002 + && (a->btgt < au_dbdiropq(d)
23003 + || a->btgt < au_dbbot(d)
23005 + AuDbgDentry(a->src_dentry);
23006 + AuDbgDentry(a->dst_dentry);
23007 + err = au_ren_do_diropq(a, AuDST);
23008 + if (unlikely(err))
23009 + goto out_rev_src;
23010 + au_fset_ren(a->auren_flags, DIROPQ_DST);
23012 + goto out; /* success */
23015 + AuDbg("err %d, reverting src\n", err);
23016 + au_ren_rev_diropq(err, a);
23021 +static int do_rename(struct au_ren_args *a)
23024 + struct dentry *d, *h_d;
23026 + if (!a->exchange) {
23027 + /* prepare workqueue args for asynchronous rmdir */
23028 + h_d = a->dst_h_dentry;
23029 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23030 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
23031 + && d_is_positive(h_d)) {
23033 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
23035 + if (unlikely(!a->thargs))
23037 + a->h_dst = dget(h_d);
23040 + /* create whiteout for src_dentry */
23041 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
23042 + a->src_bwh = au_dbwh(a->src_dentry);
23043 + AuDebugOn(a->src_bwh >= 0);
23044 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
23045 + a->src_h_parent);
23046 + err = PTR_ERR(a->src_wh_dentry);
23047 + if (IS_ERR(a->src_wh_dentry))
23051 + /* lookup whiteout for dentry */
23052 + if (au_ftest_ren(a->auren_flags, WHDST)) {
23053 + h_d = au_wh_lkup(a->dst_h_parent,
23054 + &a->dst_dentry->d_name, a->br);
23055 + err = PTR_ERR(h_d);
23058 + if (d_is_negative(h_d))
23061 + a->dst_wh_dentry = h_d;
23064 + /* rename dentry to tmpwh */
23066 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23067 + if (unlikely(err))
23070 + d = a->dst_dentry;
23071 + au_set_h_dptr(d, a->btgt, NULL);
23072 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23073 + if (unlikely(err))
23075 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23079 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23081 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23082 + && d_is_positive(a->dst_h_dentry)
23083 + && a->src_btop != a->btgt);
23086 + /* rename by vfs_rename or cpup */
23087 + err = au_ren_or_cpup(a);
23088 + if (unlikely(err))
23089 + /* leave the copied-up one */
23092 + /* make dir opaque */
23093 + err = au_ren_diropq(a);
23094 + if (unlikely(err))
23097 + /* update target timestamps */
23098 + if (a->exchange) {
23099 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23100 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23101 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23102 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23104 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23105 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23106 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23107 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23109 + if (!a->exchange) {
23110 + /* remove whiteout for dentry */
23111 + if (a->dst_wh_dentry) {
23112 + a->h_path.dentry = a->dst_wh_dentry;
23113 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23115 + if (unlikely(err))
23119 + /* remove whtmp */
23121 + au_ren_del_whtmp(a); /* ignore this error */
23123 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23126 + goto out_success;
23129 + au_ren_rev_diropq(err, a);
23131 + au_ren_rev_rename(err, a);
23135 + au_ren_rev_whtmp(err, a);
23137 + dput(a->dst_wh_dentry);
23138 + a->dst_wh_dentry = NULL;
23140 + if (a->src_wh_dentry)
23141 + au_ren_rev_whsrc(err, a);
23143 + dput(a->src_wh_dentry);
23144 + dput(a->dst_wh_dentry);
23148 + au_whtmp_rmdir_free(a->thargs);
23149 + a->thargs = NULL;
23155 +/* ---------------------------------------------------------------------- */
23158 + * test if @dentry dir can be rename destination or not.
23159 + * success means, it is a logically empty dir.
23161 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23163 + return au_test_empty(dentry, whlist);
23167 + * test if @a->src_dentry dir can be rename source or not.
23168 + * if it can, return 0.
23170 + * - it is a logically empty dir.
23171 + * - or, it exists on writable branch and has no children including whiteouts
23172 + * on the lower branch unless DIRREN is on.
23174 +static int may_rename_srcdir(struct au_ren_args *a)
23177 + unsigned int rdhash;
23178 + aufs_bindex_t btop, btgt;
23179 + struct dentry *dentry;
23180 + struct super_block *sb;
23181 + struct au_sbinfo *sbinfo;
23183 + dentry = a->src_dentry;
23184 + sb = dentry->d_sb;
23185 + sbinfo = au_sbi(sb);
23186 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23187 + au_fset_ren(a->auren_flags, DIRREN);
23190 + btop = au_dbtop(dentry);
23191 + if (btop != btgt) {
23192 + struct au_nhash whlist;
23194 + SiMustAnyLock(sb);
23195 + rdhash = sbinfo->si_rdhash;
23197 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23199 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23200 + if (unlikely(err))
23202 + err = au_test_empty(dentry, &whlist);
23203 + au_nhash_wh_free(&whlist);
23207 + if (btop == au_dbtaildir(dentry))
23208 + return 0; /* success */
23210 + err = au_test_empty_lower(dentry);
23213 + if (err == -ENOTEMPTY) {
23214 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23217 + AuWarn1("renaming dir who has child(ren) on multiple "
23218 + "branches, is not supported\n");
23225 +/* side effect: sets whlist and h_dentry */
23226 +static int au_ren_may_dir(struct au_ren_args *a)
23229 + unsigned int rdhash;
23230 + struct dentry *d;
23232 + d = a->dst_dentry;
23233 + SiMustAnyLock(d->d_sb);
23236 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23237 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23239 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23240 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23241 + if (unlikely(err))
23244 + if (!a->exchange) {
23245 + au_set_dbtop(d, a->dst_btop);
23246 + err = may_rename_dstdir(d, &a->whlist);
23247 + au_set_dbtop(d, a->btgt);
23249 + err = may_rename_srcdir(a);
23251 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23252 + if (unlikely(err))
23255 + d = a->src_dentry;
23256 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23257 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23258 + err = may_rename_srcdir(a);
23259 + if (unlikely(err)) {
23260 + au_nhash_wh_free(&a->whlist);
23261 + a->whlist.nh_num = 0;
23268 +/* ---------------------------------------------------------------------- */
23271 + * simple tests for rename.
23272 + * following the checks in vfs, plus the parent-child relationship.
23274 +static int au_may_ren(struct au_ren_args *a)
23277 + struct inode *h_inode;
23279 + if (a->src_btop == a->btgt) {
23280 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23281 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23282 + if (unlikely(err))
23285 + if (unlikely(a->src_h_dentry == a->h_trap))
23290 + if (a->dst_btop != a->btgt)
23293 + err = -ENOTEMPTY;
23294 + if (unlikely(a->dst_h_dentry == a->h_trap))
23298 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23299 + if (d_really_is_negative(a->dst_dentry)) {
23300 + if (d_is_negative(a->dst_h_dentry))
23301 + err = au_may_add(a->dst_dentry, a->btgt,
23302 + a->dst_h_parent, isdir);
23304 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23306 + h_inode = d_inode(a->dst_h_dentry);
23307 + if (h_inode->i_nlink)
23308 + err = au_may_del(a->dst_dentry, a->btgt,
23309 + a->dst_h_parent, isdir);
23313 + if (unlikely(err == -ENOENT || err == -EEXIST))
23319 +/* ---------------------------------------------------------------------- */
23324 + * - src_dir and dir by lock_rename()
23325 + * - inode if exists
23328 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23330 + * + di_write_lock2_child()
23331 + * + di_write_lock_child()
23332 + * + ii_write_lock_child()
23333 + * + di_write_lock_child2()
23334 + * + ii_write_lock_child2()
23335 + * + src_parent and parent
23336 + * + di_write_lock_parent()
23337 + * + ii_write_lock_parent()
23338 + * + di_write_lock_parent2()
23339 + * + ii_write_lock_parent2()
23340 + * + lower src_dir and dir by vfsub_lock_rename()
23341 + * + verify the every relationships between child and parent. if any
23342 + * of them failed, unlock all and return -EBUSY.
23344 +static void au_ren_unlock(struct au_ren_args *a)
23346 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23347 + a->dst_h_parent, a->dst_hdir);
23348 + if (au_ftest_ren(a->auren_flags, DIRREN)
23350 + au_hn_inode_unlock(a->h_root);
23351 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23352 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23355 +static int au_ren_lock(struct au_ren_args *a)
23358 + unsigned int udba;
23361 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23362 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23363 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23364 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23366 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23367 + if (unlikely(err))
23369 + au_fset_ren(a->auren_flags, MNT_WRITE);
23370 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23371 + struct dentry *root;
23372 + struct inode *dir;
23375 + * sbinfo is already locked, so this ii_read_lock is
23376 + * unnecessary. but our debugging feature checks it.
23378 + root = a->src_inode->i_sb->s_root;
23379 + if (root != a->src_parent && root != a->dst_parent) {
23380 + dir = d_inode(root);
23381 + ii_read_lock_parent3(dir);
23382 + a->h_root = au_hi(dir, a->btgt);
23383 + ii_read_unlock(dir);
23384 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23387 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23388 + a->dst_h_parent, a->dst_hdir);
23389 + udba = au_opt_udba(a->src_dentry->d_sb);
23390 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23391 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23392 + err = au_busy_or_stale();
23393 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23394 + err = au_h_verify(a->src_h_dentry, udba,
23395 + d_inode(a->src_h_parent), a->src_h_parent,
23397 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23398 + err = au_h_verify(a->dst_h_dentry, udba,
23399 + d_inode(a->dst_h_parent), a->dst_h_parent,
23402 + goto out; /* success */
23404 + err = au_busy_or_stale();
23405 + au_ren_unlock(a);
23411 +/* ---------------------------------------------------------------------- */
23413 +static void au_ren_refresh_dir(struct au_ren_args *a)
23415 + struct inode *dir;
23417 + dir = a->dst_dir;
23418 + inode_inc_iversion(dir);
23419 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23420 + /* is this updating defined in POSIX? */
23421 + au_cpup_attr_timesizes(a->src_inode);
23422 + au_cpup_attr_nlink(dir, /*force*/1);
23424 + au_dir_ts(dir, a->btgt);
23426 + if (a->exchange) {
23427 + dir = a->src_dir;
23428 + inode_inc_iversion(dir);
23429 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23430 + /* is this updating defined in POSIX? */
23431 + au_cpup_attr_timesizes(a->dst_inode);
23432 + au_cpup_attr_nlink(dir, /*force*/1);
23434 + au_dir_ts(dir, a->btgt);
23437 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23440 + dir = a->src_dir;
23441 + inode_inc_iversion(dir);
23442 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23443 + au_cpup_attr_nlink(dir, /*force*/1);
23444 + au_dir_ts(dir, a->btgt);
23447 +static void au_ren_refresh(struct au_ren_args *a)
23449 + aufs_bindex_t bbot, bindex;
23450 + struct dentry *d, *h_d;
23451 + struct inode *i, *h_i;
23452 + struct super_block *sb;
23454 + d = a->dst_dentry;
23457 + /* already dget-ed by au_ren_or_cpup() */
23458 + au_set_h_dptr(d, a->btgt, a->h_dst);
23460 + i = a->dst_inode;
23462 + if (!a->exchange) {
23463 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23464 + vfsub_drop_nlink(i);
23466 + vfsub_dead_dir(i);
23467 + au_cpup_attr_timesizes(i);
23469 + au_update_dbrange(d, /*do_put_zero*/1);
23471 + au_cpup_attr_nlink(i, /*force*/1);
23474 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23475 + au_set_h_dptr(d, bindex, NULL);
23476 + bbot = au_dbbot(d);
23477 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23478 + au_set_h_dptr(d, bindex, NULL);
23479 + au_update_dbrange(d, /*do_put_zero*/0);
23483 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23484 + d_drop(a->src_dentry);
23485 + if (au_ftest_ren(a->auren_flags, DIRREN))
23486 + au_set_dbwh(a->src_dentry, -1);
23490 + d = a->src_dentry;
23491 + au_set_dbwh(d, -1);
23492 + bbot = au_dbbot(d);
23493 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23494 + h_d = au_h_dptr(d, bindex);
23496 + au_set_h_dptr(d, bindex, NULL);
23498 + au_set_dbbot(d, a->btgt);
23501 + i = a->src_inode;
23502 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23503 + return; /* success */
23505 + bbot = au_ibbot(i);
23506 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23507 + h_i = au_h_iptr(i, bindex);
23509 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23510 + /* ignore this error */
23511 + au_set_h_iptr(i, bindex, NULL, 0);
23514 + au_set_ibbot(i, a->btgt);
23517 +/* ---------------------------------------------------------------------- */
23519 +/* mainly for link(2) and rename(2) */
23520 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23522 + aufs_bindex_t bdiropq, bwh;
23523 + struct dentry *parent;
23524 + struct au_branch *br;
23526 + parent = dentry->d_parent;
23527 + IMustLock(d_inode(parent)); /* dir is locked */
23529 + bdiropq = au_dbdiropq(parent);
23530 + bwh = au_dbwh(dentry);
23531 + br = au_sbr(dentry->d_sb, btgt);
23532 + if (au_br_rdonly(br)
23533 + || (0 <= bdiropq && bdiropq < btgt)
23534 + || (0 <= bwh && bwh < btgt))
23537 + AuDbg("btgt %d\n", btgt);
23541 +/* sets src_btop, dst_btop and btgt */
23542 +static int au_ren_wbr(struct au_ren_args *a)
23545 + struct au_wr_dir_args wr_dir_args = {
23546 + /* .force_btgt = -1, */
23547 + .flags = AuWrDir_ADD_ENTRY
23550 + a->src_btop = au_dbtop(a->src_dentry);
23551 + a->dst_btop = au_dbtop(a->dst_dentry);
23552 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23553 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23554 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23555 + wr_dir_args.force_btgt = a->src_btop;
23556 + if (a->dst_inode && a->dst_btop < a->src_btop)
23557 + wr_dir_args.force_btgt = a->dst_btop;
23558 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23559 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23562 + au_update_dbtop(a->dst_dentry);
23567 +static void au_ren_dt(struct au_ren_args *a)
23569 + a->h_path.dentry = a->src_h_parent;
23570 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23571 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23572 + a->h_path.dentry = a->dst_h_parent;
23573 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23576 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23577 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23581 + a->h_path.dentry = a->src_h_dentry;
23582 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23583 + if (d_is_positive(a->dst_h_dentry)) {
23584 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23585 + a->h_path.dentry = a->dst_h_dentry;
23586 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23590 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23592 + struct dentry *h_d;
23593 + struct inode *h_inode;
23595 + au_dtime_revert(a->src_dt + AuPARENT);
23596 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23597 + au_dtime_revert(a->dst_dt + AuPARENT);
23599 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23600 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23601 + h_inode = d_inode(h_d);
23602 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23603 + au_dtime_revert(a->src_dt + AuCHILD);
23604 + inode_unlock(h_inode);
23606 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23607 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23608 + h_inode = d_inode(h_d);
23609 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23610 + au_dtime_revert(a->dst_dt + AuCHILD);
23611 + inode_unlock(h_inode);
23616 +/* ---------------------------------------------------------------------- */
23618 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23619 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23620 + unsigned int _flags)
23622 + int err, lock_flags;
23624 + /* reduce stack space */
23625 + struct au_ren_args *a;
23626 + struct au_pin pin;
23628 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23629 + IMustLock(_src_dir);
23630 + IMustLock(_dst_dir);
23633 + if (unlikely(_flags & RENAME_WHITEOUT))
23637 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23638 + a = kzalloc(sizeof(*a), GFP_NOFS);
23639 + if (unlikely(!a))
23642 + a->flags = _flags;
23643 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23644 + && RENAME_EXCHANGE > U8_MAX);
23645 + a->exchange = _flags & RENAME_EXCHANGE;
23646 + a->src_dir = _src_dir;
23647 + a->src_dentry = _src_dentry;
23648 + a->src_inode = NULL;
23649 + if (d_really_is_positive(a->src_dentry))
23650 + a->src_inode = d_inode(a->src_dentry);
23651 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23652 + a->dst_dir = _dst_dir;
23653 + a->dst_dentry = _dst_dentry;
23654 + a->dst_inode = NULL;
23655 + if (d_really_is_positive(a->dst_dentry))
23656 + a->dst_inode = d_inode(a->dst_dentry);
23657 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23658 + if (a->dst_inode) {
23660 + * if EXCHANGE && src is non-dir && dst is dir,
23661 + * dst is not locked.
23663 + /* IMustLock(a->dst_inode); */
23664 + au_igrab(a->dst_inode);
23668 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23669 + if (d_is_dir(a->src_dentry)) {
23670 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23671 + if (unlikely(!a->exchange
23672 + && d_really_is_positive(a->dst_dentry)
23673 + && !d_is_dir(a->dst_dentry)))
23675 + lock_flags |= AuLock_DIRS;
23677 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23678 + au_fset_ren(a->auren_flags, ISDIR_DST);
23679 + if (unlikely(!a->exchange
23680 + && d_really_is_positive(a->src_dentry)
23681 + && !d_is_dir(a->src_dentry)))
23683 + lock_flags |= AuLock_DIRS;
23685 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23687 + if (unlikely(err))
23690 + err = au_d_hashed_positive(a->src_dentry);
23691 + if (unlikely(err))
23694 + if (a->dst_inode) {
23696 + * If it is a dir, VFS unhash it before this
23697 + * function. It means we cannot rely upon d_unhashed().
23699 + if (unlikely(!a->dst_inode->i_nlink))
23701 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23702 + err = au_d_hashed_positive(a->dst_dentry);
23703 + if (unlikely(err && !a->exchange))
23705 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23707 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23711 + * is it possible?
23712 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23713 + * there may exist a problem somewhere else.
23716 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23719 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23720 + di_write_lock_parent(a->dst_parent);
23722 + /* which branch we process */
23723 + err = au_ren_wbr(a);
23724 + if (unlikely(err < 0))
23726 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23727 + a->h_path.mnt = au_br_mnt(a->br);
23729 + /* are they available to be renamed */
23730 + err = au_ren_may_dir(a);
23731 + if (unlikely(err))
23732 + goto out_children;
23734 + /* prepare the writable parent dir on the same branch */
23735 + if (a->dst_btop == a->btgt) {
23736 + au_fset_ren(a->auren_flags, WHDST);
23738 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23739 + if (unlikely(err))
23740 + goto out_children;
23744 + if (!a->exchange) {
23745 + if (a->src_dir != a->dst_dir) {
23747 + * this temporary unlock is safe,
23748 + * because both dir->i_mutex are locked.
23750 + di_write_unlock(a->dst_parent);
23751 + di_write_lock_parent(a->src_parent);
23752 + err = au_wr_dir_need_wh(a->src_dentry,
23753 + au_ftest_ren(a->auren_flags,
23756 + di_write_unlock(a->src_parent);
23757 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23759 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23761 + err = au_wr_dir_need_wh(a->src_dentry,
23762 + au_ftest_ren(a->auren_flags,
23766 + if (unlikely(err < 0))
23767 + goto out_children;
23769 + au_fset_ren(a->auren_flags, WHSRC);
23772 + if (a->src_btop != a->btgt) {
23773 + err = au_pin(&pin, a->src_dentry, a->btgt,
23774 + au_opt_udba(a->src_dentry->d_sb),
23775 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23777 + struct au_cp_generic cpg = {
23778 + .dentry = a->src_dentry,
23780 + .bsrc = a->src_btop,
23783 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23785 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23786 + err = au_sio_cpup_simple(&cpg);
23789 + if (unlikely(err))
23790 + goto out_children;
23791 + a->src_btop = a->btgt;
23792 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23793 + if (!a->exchange)
23794 + au_fset_ren(a->auren_flags, WHSRC);
23798 + if (a->exchange && a->dst_inode
23799 + && a->dst_btop != a->btgt) {
23800 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23801 + au_opt_udba(a->dst_dentry->d_sb),
23802 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23804 + struct au_cp_generic cpg = {
23805 + .dentry = a->dst_dentry,
23807 + .bsrc = a->dst_btop,
23810 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23812 + err = au_sio_cpup_simple(&cpg);
23815 + if (unlikely(err))
23816 + goto out_children;
23817 + a->dst_btop = a->btgt;
23818 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23821 + /* lock them all */
23822 + err = au_ren_lock(a);
23823 + if (unlikely(err))
23824 + /* leave the copied-up one */
23825 + goto out_children;
23827 + if (!a->exchange) {
23828 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23829 + err = au_may_ren(a);
23830 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23831 + err = -ENAMETOOLONG;
23832 + if (unlikely(err))
23836 + /* store timestamps to be revertible */
23839 + /* store dirren info */
23840 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23841 + err = au_dr_rename(a->src_dentry, a->btgt,
23842 + &a->dst_dentry->d_name, &rev);
23844 + if (unlikely(err))
23849 + err = do_rename(a);
23850 + if (unlikely(err))
23853 + if (au_ftest_ren(a->auren_flags, DIRREN))
23854 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23856 + /* update dir attributes */
23857 + au_ren_refresh_dir(a);
23859 + /* dput/iput all lower dentries */
23860 + au_ren_refresh(a);
23862 + goto out_hdir; /* success */
23865 + if (au_ftest_ren(a->auren_flags, DIRREN))
23866 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23868 + au_ren_rev_dt(err, a);
23870 + au_ren_unlock(a);
23872 + au_nhash_wh_free(&a->whlist);
23873 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23874 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23875 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23876 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23880 + if (d_unhashed(a->src_dentry))
23881 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23882 + if (d_unhashed(a->dst_dentry))
23883 + au_fset_ren(a->auren_flags, DROPPED_DST);
23884 + if (!a->exchange)
23885 + d_move(a->src_dentry, a->dst_dentry);
23887 + d_exchange(a->src_dentry, a->dst_dentry);
23888 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23889 + d_drop(a->dst_dentry);
23891 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23892 + d_drop(a->src_dentry);
23894 + au_update_dbtop(a->dst_dentry);
23895 + if (!a->dst_inode)
23896 + d_drop(a->dst_dentry);
23898 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23899 + di_write_unlock(a->dst_parent);
23901 + di_write_unlock2(a->src_parent, a->dst_parent);
23903 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23905 + iput(a->dst_inode);
23907 + au_whtmp_rmdir_free(a->thargs);
23913 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23914 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23915 +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200
23917 +# SPDX-License-Identifier: GPL-2.0
23919 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23921 + Aufs is a stackable unification filesystem such as Unionfs,
23922 + which unifies several directories and provides a merged single
23924 + In the early days, aufs was entirely re-designed and
23925 + re-implemented Unionfs Version 1.x series. Introducing many
23926 + original ideas, approaches and improvements, it becomes totally
23927 + different from Unionfs while keeping the basic features.
23931 + prompt "Maximum number of branches"
23932 + default AUFS_BRANCH_MAX_127
23934 + Specifies the maximum number of branches (or member directories)
23935 + in a single aufs. The larger value consumes more system
23936 + resources and has a minor impact to performance.
23937 +config AUFS_BRANCH_MAX_127
23940 + Specifies the maximum number of branches (or member directories)
23941 + in a single aufs. The larger value consumes more system
23942 + resources and has a minor impact to performance.
23943 +config AUFS_BRANCH_MAX_511
23946 + Specifies the maximum number of branches (or member directories)
23947 + in a single aufs. The larger value consumes more system
23948 + resources and has a minor impact to performance.
23949 +config AUFS_BRANCH_MAX_1023
23952 + Specifies the maximum number of branches (or member directories)
23953 + in a single aufs. The larger value consumes more system
23954 + resources and has a minor impact to performance.
23955 +config AUFS_BRANCH_MAX_32767
23958 + Specifies the maximum number of branches (or member directories)
23959 + in a single aufs. The larger value consumes more system
23960 + resources and has a minor impact to performance.
23963 +config AUFS_SBILIST
23965 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23968 + Automatic configuration for internal use.
23969 + When aufs supports Magic SysRq or /proc, enabled automatically.
23971 +config AUFS_HNOTIFY
23972 + bool "Detect direct branch access (bypassing aufs)"
23974 + If you want to modify files on branches directly, eg. bypassing aufs,
23975 + and want aufs to detect the changes of them fully, then enable this
23976 + option and use 'udba=notify' mount option.
23977 + Currently there is only one available configuration, "fsnotify".
23978 + It will have a negative impact to the performance.
23979 + See detail in aufs.5.
23982 + prompt "method" if AUFS_HNOTIFY
23983 + default AUFS_HFSNOTIFY
23984 +config AUFS_HFSNOTIFY
23989 +config AUFS_EXPORT
23990 + bool "NFS-exportable aufs"
23991 + depends on EXPORTFS
23993 + If you want to export your mounted aufs via NFS, then enable this
23994 + option. There are several requirements for this configuration.
23995 + See detail in aufs.5.
23997 +config AUFS_INO_T_64
23999 + depends on AUFS_EXPORT
24000 + depends on 64BIT && !(ALPHA || S390)
24003 + Automatic configuration for internal use.
24004 + /* typedef unsigned long/int __kernel_ino_t */
24005 + /* alpha and s390x are int */
24008 + bool "support for XATTR/EA (including Security Labels)"
24010 + If your branch fs supports XATTR/EA and you want to make them
24011 + available in aufs too, then enable this opsion and specify the
24012 + branch attributes for EA.
24013 + See detail in aufs.5.
24016 + bool "File-based Hierarchical Storage Management"
24018 + Hierarchical Storage Management (or HSM) is a well-known feature
24019 + in the storage world. Aufs provides this feature as file-based.
24020 + with multiple branches.
24021 + These multiple branches are prioritized, ie. the topmost one
24022 + should be the fastest drive and be used heavily.
24025 + bool "Readdir in userspace"
24027 + Aufs has two methods to provide a merged view for a directory,
24028 + by a user-space library and by kernel-space natively. The latter
24029 + is always enabled but sometimes large and slow.
24030 + If you enable this option, install the library in aufs2-util
24031 + package, and set some environment variables for your readdir(3),
24032 + then the work will be handled in user-space which generally
24033 + shows better performance in most cases.
24034 + See detail in aufs.5.
24036 +config AUFS_DIRREN
24037 + bool "Workaround for rename(2)-ing a directory"
24039 + By default, aufs returns EXDEV error in renameing a dir who has
24040 + his child on the lower branch, since it is a bad idea to issue
24041 + rename(2) internally for every lower branch. But user may not
24042 + accept this behaviour. So here is a workaround to allow such
24043 + rename(2) and store some extra infromation on the writable
24044 + branch. Obviously this costs high (and I don't like it).
24045 + To use this feature, you need to enable this configuration AND
24046 + to specify the mount option `dirren.'
24047 + See details in aufs.5 and the design documents.
24050 + bool "Show whiteouts"
24052 + If you want to make the whiteouts in aufs visible, then enable
24053 + this option and specify 'shwh' mount option. Although it may
24054 + sounds like philosophy or something, but in technically it
24055 + simply shows the name of whiteout with keeping its behaviour.
24057 +config AUFS_BR_RAMFS
24058 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
24060 + If you want to use ramfs as an aufs branch fs, then enable this
24061 + option. Generally tmpfs is recommended.
24062 + Aufs prohibited them to be a branch fs by default, because
24063 + initramfs becomes unusable after switch_root or something
24064 + generally. If you sets initramfs as an aufs branch and boot your
24065 + system by switch_root, you will meet a problem easily since the
24066 + files in initramfs may be inaccessible.
24067 + Unless you are going to use ramfs as an aufs branch fs without
24068 + switch_root or something, leave it N.
24070 +config AUFS_BR_FUSE
24071 + bool "Fuse fs as an aufs branch"
24072 + depends on FUSE_FS
24075 + If you want to use fuse-based userspace filesystem as an aufs
24076 + branch fs, then enable this option.
24077 + It implements the internal poll(2) operation which is
24078 + implemented by fuse only (curretnly).
24083 + Automatic configuration for internal use.
24085 +config AUFS_BR_HFSPLUS
24086 + bool "Hfsplus as an aufs branch"
24087 + depends on HFSPLUS_FS
24090 + If you want to use hfsplus fs as an aufs branch fs, then enable
24091 + this option. This option introduces a small overhead at
24092 + copying-up a file on hfsplus.
24094 +config AUFS_BDEV_LOOP
24096 + depends on BLK_DEV_LOOP
24099 + Automatic configuration for internal use.
24100 + Convert =[ym] into =y.
24103 + bool "Debug aufs"
24105 + Enable this to compile aufs internal debug code.
24106 + It will have a negative impact to the performance.
24108 +config AUFS_MAGIC_SYSRQ
24110 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24113 + Automatic configuration for internal use.
24114 + When aufs supports Magic SysRq, enabled automatically.
24116 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24117 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24118 +++ linux/fs/aufs/lcnt.h 2019-07-11 15:42:14.468904634 +0200
24120 +/* SPDX-License-Identifier: GPL-2.0 */
24122 + * Copyright (C) 2018-2019 Junjiro R. Okajima
24124 + * This program, aufs is free software; you can redistribute it and/or modify
24125 + * it under the terms of the GNU General Public License as published by
24126 + * the Free Software Foundation; either version 2 of the License, or
24127 + * (at your option) any later version.
24129 + * This program is distributed in the hope that it will be useful,
24130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24132 + * GNU General Public License for more details.
24134 + * You should have received a copy of the GNU General Public License
24135 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24139 + * simple long counter wrapper
24142 +#ifndef __AUFS_LCNT_H__
24143 +#define __AUFS_LCNT_H__
24147 +#include "debug.h"
24149 +#define AuLCntATOMIC 1
24150 +#define AuLCntPCPUCNT 2
24152 + * why does percpu_refcount require extra synchronize_rcu()s in
24153 + * au_br_do_free()
24155 +#define AuLCntPCPUREF 3
24157 +/* #define AuLCntChosen AuLCntATOMIC */
24158 +#define AuLCntChosen AuLCntPCPUCNT
24159 +/* #define AuLCntChosen AuLCntPCPUREF */
24161 +#if AuLCntChosen == AuLCntATOMIC
24162 +#include <linux/atomic.h>
24164 +typedef atomic_long_t au_lcnt_t;
24166 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24168 + atomic_long_set(cnt, 0);
24172 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24177 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24178 + int do_sync __maybe_unused)
24183 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24185 + atomic_long_inc(cnt);
24188 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24190 + atomic_long_dec(cnt);
24193 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24195 + return atomic_long_read(cnt);
24199 +#if AuLCntChosen == AuLCntPCPUCNT
24200 +#include <linux/percpu_counter.h>
24202 +typedef struct percpu_counter au_lcnt_t;
24204 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24206 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24209 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24214 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24216 + percpu_counter_destroy(cnt);
24219 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24221 + percpu_counter_inc(cnt);
24224 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24226 + percpu_counter_dec(cnt);
24229 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24233 + n = percpu_counter_sum(cnt);
24235 + if (LONG_MAX != LLONG_MAX
24237 + AuWarn1("%s\n", "wrap-around");
24243 +#if AuLCntChosen == AuLCntPCPUREF
24244 +#include <linux/percpu-refcount.h>
24246 +typedef struct percpu_ref au_lcnt_t;
24248 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24251 + release = percpu_ref_exit;
24252 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24255 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24257 + synchronize_rcu();
24260 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24262 + percpu_ref_kill(cnt);
24264 + au_lcnt_wait_for_fin(cnt);
24267 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24269 + percpu_ref_get(cnt);
24272 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24274 + percpu_ref_put(cnt);
24278 + * avoid calling this func as possible.
24280 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24284 + percpu_ref_switch_to_atomic_sync(cnt);
24285 + l = atomic_long_read(&cnt->count);
24287 + percpu_ref_switch_to_percpu(cnt);
24289 + /* percpu_ref is initialized by 1 instead of 0 */
24294 +#ifdef CONFIG_AUFS_DEBUG
24295 +#define AuLCntZero(val) do { \
24298 + AuDbg("%s = %ld\n", #val, l); \
24301 +#define AuLCntZero(val) do {} while (0)
24304 +#endif /* __KERNEL__ */
24305 +#endif /* __AUFS_LCNT_H__ */
24306 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24307 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24308 +++ linux/fs/aufs/loop.c 2019-07-11 15:42:14.468904634 +0200
24310 +// SPDX-License-Identifier: GPL-2.0
24312 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24314 + * This program, aufs is free software; you can redistribute it and/or modify
24315 + * it under the terms of the GNU General Public License as published by
24316 + * the Free Software Foundation; either version 2 of the License, or
24317 + * (at your option) any later version.
24319 + * This program is distributed in the hope that it will be useful,
24320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24322 + * GNU General Public License for more details.
24324 + * You should have received a copy of the GNU General Public License
24325 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24329 + * support for loopback block device as a branch
24334 +/* added into drivers/block/loop.c */
24335 +static struct file *(*backing_file_func)(struct super_block *sb);
24338 + * test if two lower dentries have overlapping branches.
24340 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24342 + struct super_block *h_sb;
24343 + struct file *backing_file;
24345 + if (unlikely(!backing_file_func)) {
24346 + /* don't load "loop" module here */
24347 + backing_file_func = symbol_get(loop_backing_file);
24348 + if (unlikely(!backing_file_func))
24349 + /* "loop" module is not loaded */
24353 + h_sb = h_adding->d_sb;
24354 + backing_file = backing_file_func(h_sb);
24355 + if (!backing_file)
24358 + h_adding = backing_file->f_path.dentry;
24360 + * h_adding can be local NFS.
24361 + * in this case aufs cannot detect the loop.
24363 + if (unlikely(h_adding->d_sb == sb))
24365 + return !!au_test_subdir(h_adding, sb->s_root);
24368 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24369 +int au_test_loopback_kthread(void)
24372 + struct task_struct *tsk = current;
24373 + char c, comm[sizeof(tsk->comm)];
24376 + if (tsk->flags & PF_KTHREAD) {
24377 + get_task_comm(comm, tsk);
24379 + ret = ('0' <= c && c <= '9'
24380 + && !strncmp(comm, "loop", 4));
24386 +/* ---------------------------------------------------------------------- */
24388 +#define au_warn_loopback_step 16
24389 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24390 +static unsigned long *au_warn_loopback_array;
24392 +void au_warn_loopback(struct super_block *h_sb)
24394 + int i, new_nelem;
24395 + unsigned long *a, magic;
24396 + static DEFINE_SPINLOCK(spin);
24398 + magic = h_sb->s_magic;
24399 + spin_lock(&spin);
24400 + a = au_warn_loopback_array;
24401 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24402 + if (a[i] == magic) {
24403 + spin_unlock(&spin);
24407 + /* h_sb is new to us, print it */
24408 + if (i < au_warn_loopback_nelem) {
24413 + /* expand the array */
24414 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24415 + a = au_kzrealloc(au_warn_loopback_array,
24416 + au_warn_loopback_nelem * sizeof(unsigned long),
24417 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24418 + /*may_shrink*/0);
24420 + au_warn_loopback_nelem = new_nelem;
24421 + au_warn_loopback_array = a;
24426 + spin_unlock(&spin);
24427 + AuWarn1("realloc failed, ignored\n");
24431 + spin_unlock(&spin);
24432 + pr_warn("you may want to try another patch for loopback file "
24433 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24436 +int au_loopback_init(void)
24439 + struct super_block *sb __maybe_unused;
24441 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24444 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24445 + sizeof(unsigned long), GFP_NOFS);
24446 + if (unlikely(!au_warn_loopback_array))
24452 +void au_loopback_fin(void)
24454 + if (backing_file_func)
24455 + symbol_put(loop_backing_file);
24456 + au_kfree_try_rcu(au_warn_loopback_array);
24458 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24459 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24460 +++ linux/fs/aufs/loop.h 2019-07-11 15:42:14.468904634 +0200
24462 +/* SPDX-License-Identifier: GPL-2.0 */
24464 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24466 + * This program, aufs is free software; you can redistribute it and/or modify
24467 + * it under the terms of the GNU General Public License as published by
24468 + * the Free Software Foundation; either version 2 of the License, or
24469 + * (at your option) any later version.
24471 + * This program is distributed in the hope that it will be useful,
24472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24474 + * GNU General Public License for more details.
24476 + * You should have received a copy of the GNU General Public License
24477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24481 + * support for loopback mount as a branch
24484 +#ifndef __AUFS_LOOP_H__
24485 +#define __AUFS_LOOP_H__
24490 +struct super_block;
24492 +#ifdef CONFIG_AUFS_BDEV_LOOP
24493 +/* drivers/block/loop.c */
24494 +struct file *loop_backing_file(struct super_block *sb);
24497 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24498 +int au_test_loopback_kthread(void);
24499 +void au_warn_loopback(struct super_block *h_sb);
24501 +int au_loopback_init(void);
24502 +void au_loopback_fin(void);
24504 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24506 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24507 + struct dentry *h_adding)
24508 +AuStubInt0(au_test_loopback_kthread, void)
24509 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24511 +AuStubInt0(au_loopback_init, void)
24512 +AuStubVoid(au_loopback_fin, void)
24513 +#endif /* BLK_DEV_LOOP */
24515 +#endif /* __KERNEL__ */
24516 +#endif /* __AUFS_LOOP_H__ */
24517 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24518 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24519 +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200
24521 +# SPDX-License-Identifier: GPL-2.0
24523 +# defined in ${srctree}/fs/fuse/inode.c
24525 +ifdef CONFIG_FUSE_FS
24526 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24529 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24531 +ifdef CONFIG_XFS_FS
24532 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24535 +# defined in ${srctree}/fs/configfs/mount.c
24537 +ifdef CONFIG_CONFIGFS_FS
24538 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24541 +# defined in ${srctree}/fs/ubifs/ubifs.h
24543 +ifdef CONFIG_UBIFS_FS
24544 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24547 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24549 +ifdef CONFIG_HFSPLUS_FS
24550 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24552 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24553 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24554 +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200
24556 +# SPDX-License-Identifier: GPL-2.0
24558 +include ${src}/magic.mk
24559 +ifeq (${CONFIG_AUFS_FS},m)
24560 +include ${src}/conf.mk
24562 +-include ${src}/priv_def.mk
24564 +# cf. include/linux/kernel.h
24566 +ccflags-y += -DDEBUG
24567 +# sparse requires the full pathname
24569 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24571 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24574 +obj-$(CONFIG_AUFS_FS) += aufs.o
24575 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24576 + wkq.o vfsub.o dcsub.o \
24577 + cpup.o whout.o wbr_policy.o \
24578 + dinfo.o dentry.o \
24580 + finfo.o file.o f_op.o \
24582 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24586 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24587 +aufs-$(CONFIG_SYSFS) += sysfs.o
24588 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24589 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24590 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24591 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24592 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24593 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24594 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24595 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24596 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24597 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24598 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24599 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24600 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24601 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24602 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24603 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24604 +++ linux/fs/aufs/module.c 2019-07-11 15:42:14.468904634 +0200
24606 +// SPDX-License-Identifier: GPL-2.0
24608 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24610 + * This program, aufs is free software; you can redistribute it and/or modify
24611 + * it under the terms of the GNU General Public License as published by
24612 + * the Free Software Foundation; either version 2 of the License, or
24613 + * (at your option) any later version.
24615 + * This program is distributed in the hope that it will be useful,
24616 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24617 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24618 + * GNU General Public License for more details.
24620 + * You should have received a copy of the GNU General Public License
24621 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24625 + * module global variables and operations
24628 +#include <linux/module.h>
24629 +#include <linux/seq_file.h>
24632 +/* shrinkable realloc */
24633 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24641 +#if 0 /* unused */
24648 + AuDebugOn(!new_sz);
24651 + diff = au_kmidx_sub(sz, new_sz);
24657 + /* expand or SLOB */
24658 + p = krealloc(p, new_sz, gfp);
24659 + else if (new_sz < sz && may_shrink) {
24663 + q = kmalloc(new_sz, gfp);
24666 + memcpy(q, p, new_sz);
24667 + au_kfree_try_rcu(p);
24678 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24681 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24682 + if (p && new_sz > nused)
24683 + memset(p + nused, 0, new_sz - nused);
24687 +/* ---------------------------------------------------------------------- */
24691 +struct kmem_cache *au_cache[AuCache_Last];
24693 +static void au_cache_fin(void)
24698 + * Make sure all delayed rcu free inodes are flushed before we
24703 + /* excluding AuCache_HNOTIFY */
24704 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24705 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24706 + kmem_cache_destroy(au_cache[i]);
24707 + au_cache[i] = NULL;
24711 +static int __init au_cache_init(void)
24713 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24714 + if (au_cache[AuCache_DINFO])
24715 + /* SLAB_DESTROY_BY_RCU */
24716 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24717 + au_icntnr_init_once);
24718 + if (au_cache[AuCache_ICNTNR])
24719 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24720 + au_fi_init_once);
24721 + if (au_cache[AuCache_FINFO])
24722 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24723 + if (au_cache[AuCache_VDIR])
24724 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24725 + if (au_cache[AuCache_DEHSTR])
24732 +/* ---------------------------------------------------------------------- */
24734 +int au_dir_roflags;
24736 +#ifdef CONFIG_AUFS_SBILIST
24738 + * iterate_supers_type() doesn't protect us from
24739 + * remounting (branch management)
24741 +struct hlist_bl_head au_sbilist;
24745 + * functions for module interface.
24747 +MODULE_LICENSE("GPL");
24748 +/* MODULE_LICENSE("GPL v2"); */
24749 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24750 +MODULE_DESCRIPTION(AUFS_NAME
24751 + " -- Advanced multi layered unification filesystem");
24752 +MODULE_VERSION(AUFS_VERSION);
24753 +MODULE_ALIAS_FS(AUFS_NAME);
24755 +/* this module parameter has no meaning when SYSFS is disabled */
24756 +int sysaufs_brs = 1;
24757 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24758 +module_param_named(brs, sysaufs_brs, int, 0444);
24760 +/* this module parameter has no meaning when USER_NS is disabled */
24762 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24763 +module_param_named(allow_userns, au_userns, bool, 0444);
24765 +/* ---------------------------------------------------------------------- */
24767 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24769 +int au_seq_path(struct seq_file *seq, struct path *path)
24773 + err = seq_path(seq, path, au_esc_chars);
24782 +/* ---------------------------------------------------------------------- */
24784 +static int __init aufs_init(void)
24789 + p = au_esc_chars;
24790 + for (i = 1; i <= ' '; i++)
24796 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24798 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24799 + for (i = 0; i < AuIop_Last; i++)
24800 + aufs_iop_nogetattr[i].getattr = NULL;
24802 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24804 + au_sbilist_init();
24805 + sysaufs_brs_init();
24808 + err = sysaufs_init();
24809 + if (unlikely(err))
24811 + err = dbgaufs_init();
24812 + if (unlikely(err))
24813 + goto out_sysaufs;
24814 + err = au_procfs_init();
24815 + if (unlikely(err))
24816 + goto out_dbgaufs;
24817 + err = au_wkq_init();
24818 + if (unlikely(err))
24820 + err = au_loopback_init();
24821 + if (unlikely(err))
24823 + err = au_hnotify_init();
24824 + if (unlikely(err))
24825 + goto out_loopback;
24826 + err = au_sysrq_init();
24827 + if (unlikely(err))
24829 + err = au_cache_init();
24830 + if (unlikely(err))
24833 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24834 + err = register_filesystem(&aufs_fs_type);
24835 + if (unlikely(err))
24838 + /* since we define pr_fmt, call printk directly */
24839 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24840 + goto out; /* success */
24847 + au_hnotify_fin();
24849 + au_loopback_fin();
24863 +static void __exit aufs_exit(void)
24865 + unregister_filesystem(&aufs_fs_type);
24868 + au_hnotify_fin();
24869 + au_loopback_fin();
24877 +module_init(aufs_init);
24878 +module_exit(aufs_exit);
24879 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24880 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24881 +++ linux/fs/aufs/module.h 2019-07-11 15:42:14.468904634 +0200
24883 +/* SPDX-License-Identifier: GPL-2.0 */
24885 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24887 + * This program, aufs is free software; you can redistribute it and/or modify
24888 + * it under the terms of the GNU General Public License as published by
24889 + * the Free Software Foundation; either version 2 of the License, or
24890 + * (at your option) any later version.
24892 + * This program is distributed in the hope that it will be useful,
24893 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24894 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24895 + * GNU General Public License for more details.
24897 + * You should have received a copy of the GNU General Public License
24898 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24902 + * module initialization and module-global
24905 +#ifndef __AUFS_MODULE_H__
24906 +#define __AUFS_MODULE_H__
24910 +#include <linux/slab.h>
24911 +#include "debug.h"
24912 +#include "dentry.h"
24915 +#include "inode.h"
24920 +/* module parameters */
24921 +extern int sysaufs_brs;
24922 +extern bool au_userns;
24924 +/* ---------------------------------------------------------------------- */
24926 +extern int au_dir_roflags;
24928 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24929 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24933 + * Comparing the size of the object with sizeof(struct rcu_head)
24934 + * case 1: object is always larger
24935 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24936 + * case 2: object is always smaller
24937 + * --> au_kfree_small()
24938 + * case 3: object can be any size
24939 + * --> au_kfree_try_rcu()
24942 +static inline void au_kfree_do_rcu(const void *p)
24945 + struct rcu_head rcu;
24946 + } *a = (void *)p;
24948 + kfree_rcu(a, rcu);
24951 +#define au_kfree_rcu(_p) do { \
24952 + typeof(_p) p = (_p); \
24953 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24955 + au_kfree_do_rcu(p); \
24958 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24959 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24961 +static inline void au_kfree_try_rcu(const void *p)
24965 + if (au_kfree_sz_test(p))
24966 + au_kfree_do_rcu(p);
24971 +static inline void au_kfree_small(const void *p)
24975 + AuDebugOn(au_kfree_sz_test(p));
24979 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24981 +#ifndef CONFIG_SLOB
24982 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24984 + return -1; /* SLOB is untested */
24988 +int au_seq_path(struct seq_file *seq, struct path *path);
24990 +#ifdef CONFIG_PROC_FS
24992 +int __init au_procfs_init(void);
24993 +void au_procfs_fin(void);
24995 +AuStubInt0(au_procfs_init, void);
24996 +AuStubVoid(au_procfs_fin, void);
24999 +/* ---------------------------------------------------------------------- */
25008 + AuCache_HNOTIFY, /* must be last */
25012 +extern struct kmem_cache *au_cache[AuCache_Last];
25014 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
25015 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
25016 +#define AuCacheCtor(type, ctor) \
25017 + kmem_cache_create(#type, sizeof(struct type), \
25018 + __alignof__(struct type), AuCacheFlags, ctor)
25020 +#define AuCacheFuncs(name, index) \
25021 + static inline struct au_##name *au_cache_alloc_##name(void) \
25022 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
25023 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
25024 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
25026 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
25027 + { void *p = rcu; \
25028 + p -= offsetof(struct au_##name, rcu); \
25029 + kmem_cache_free(au_cache[AuCache_##index], p); } \
25030 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
25031 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
25032 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
25034 + static inline void au_cache_free_##name(struct au_##name *p) \
25035 + { /* au_cache_free_##name##_norcu(p); */ \
25036 + au_cache_free_##name##_rcu(p); }
25038 +AuCacheFuncs(dinfo, DINFO);
25039 +AuCacheFuncs(icntnr, ICNTNR);
25040 +AuCacheFuncs(finfo, FINFO);
25041 +AuCacheFuncs(vdir, VDIR);
25042 +AuCacheFuncs(vdir_dehstr, DEHSTR);
25043 +#ifdef CONFIG_AUFS_HNOTIFY
25044 +AuCacheFuncs(hnotify, HNOTIFY);
25047 +#endif /* __KERNEL__ */
25048 +#endif /* __AUFS_MODULE_H__ */
25049 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
25050 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
25051 +++ linux/fs/aufs/mvdown.c 2019-07-11 15:42:14.472238057 +0200
25053 +// SPDX-License-Identifier: GPL-2.0
25055 + * Copyright (C) 2011-2019 Junjiro R. Okajima
25057 + * This program, aufs is free software; you can redistribute it and/or modify
25058 + * it under the terms of the GNU General Public License as published by
25059 + * the Free Software Foundation; either version 2 of the License, or
25060 + * (at your option) any later version.
25062 + * This program is distributed in the hope that it will be useful,
25063 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25064 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25065 + * GNU General Public License for more details.
25067 + * You should have received a copy of the GNU General Public License
25068 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25072 + * move-down, opposite of copy-up
25077 +struct au_mvd_args {
25079 + struct super_block *h_sb;
25080 + struct dentry *h_parent;
25081 + struct au_hinode *hdir;
25082 + struct inode *h_dir, *h_inode;
25083 + struct au_pin pin;
25084 + } info[AUFS_MVDOWN_NARRAY];
25086 + struct aufs_mvdown mvdown;
25087 + struct dentry *dentry, *parent;
25088 + struct inode *inode, *dir;
25089 + struct super_block *sb;
25090 + aufs_bindex_t bopq, bwh, bfound;
25091 + unsigned char rename_lock;
25094 +#define mvd_errno mvdown.au_errno
25095 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25096 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25097 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25098 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25100 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25101 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25102 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25103 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25104 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25105 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25107 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25108 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25109 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25110 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25111 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25112 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25114 +#define AU_MVD_PR(flag, ...) do { \
25116 + pr_err(__VA_ARGS__); \
25119 +static int find_lower_writable(struct au_mvd_args *a)
25121 + struct super_block *sb;
25122 + aufs_bindex_t bindex, bbot;
25123 + struct au_branch *br;
25126 + bindex = a->mvd_bsrc;
25127 + bbot = au_sbbot(sb);
25128 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25129 + for (bindex++; bindex <= bbot; bindex++) {
25130 + br = au_sbr(sb, bindex);
25131 + if (au_br_fhsm(br->br_perm)
25132 + && !sb_rdonly(au_br_sb(br)))
25135 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25136 + for (bindex++; bindex <= bbot; bindex++) {
25137 + br = au_sbr(sb, bindex);
25138 + if (!au_br_rdonly(br))
25142 + for (bindex++; bindex <= bbot; bindex++) {
25143 + br = au_sbr(sb, bindex);
25144 + if (!sb_rdonly(au_br_sb(br))) {
25145 + if (au_br_rdonly(br))
25147 + |= AUFS_MVDOWN_ROLOWER_R;
25155 +/* make the parent dir on bdst */
25156 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25161 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25162 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25163 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25164 + a->mvd_h_dst_parent = NULL;
25165 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25166 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25167 + if (!a->mvd_h_dst_parent) {
25168 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25169 + if (unlikely(err)) {
25170 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25173 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25181 +/* lock them all */
25182 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25185 + struct dentry *h_trap;
25187 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25188 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25189 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25190 + au_opt_udba(a->sb),
25191 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25193 + if (unlikely(err)) {
25194 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25198 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25199 + a->rename_lock = 0;
25200 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25201 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25202 + au_opt_udba(a->sb),
25203 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25204 + err = au_do_pin(&a->mvd_pin_src);
25206 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25207 + if (unlikely(err)) {
25208 + AU_MVD_PR(dmsg, "pin_src failed\n");
25211 + goto out; /* success */
25214 + a->rename_lock = 1;
25215 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25216 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25217 + au_opt_udba(a->sb),
25218 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25220 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25221 + if (unlikely(err)) {
25222 + AU_MVD_PR(dmsg, "pin_src failed\n");
25223 + au_pin_hdir_lock(&a->mvd_pin_dst);
25226 + au_pin_hdir_unlock(&a->mvd_pin_src);
25227 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25228 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25230 + err = (h_trap != a->mvd_h_src_parent);
25232 + err = (h_trap != a->mvd_h_dst_parent);
25234 + BUG_ON(err); /* it should never happen */
25235 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25238 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25239 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25240 + au_pin_hdir_lock(&a->mvd_pin_src);
25241 + au_unpin(&a->mvd_pin_src);
25242 + au_pin_hdir_lock(&a->mvd_pin_dst);
25245 + goto out; /* success */
25248 + au_unpin(&a->mvd_pin_dst);
25254 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25256 + if (!a->rename_lock)
25257 + au_unpin(&a->mvd_pin_src);
25259 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25260 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25261 + au_pin_hdir_lock(&a->mvd_pin_src);
25262 + au_unpin(&a->mvd_pin_src);
25263 + au_pin_hdir_lock(&a->mvd_pin_dst);
25265 + au_unpin(&a->mvd_pin_dst);
25268 +/* copy-down the file */
25269 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25272 + struct au_cp_generic cpg = {
25273 + .dentry = a->dentry,
25274 + .bdst = a->mvd_bdst,
25275 + .bsrc = a->mvd_bsrc,
25277 + .pin = &a->mvd_pin_dst,
25278 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25281 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25282 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25283 + au_fset_cpup(cpg.flags, OVERWRITE);
25284 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25285 + au_fset_cpup(cpg.flags, RWDST);
25286 + err = au_sio_cpdown_simple(&cpg);
25287 + if (unlikely(err))
25288 + AU_MVD_PR(dmsg, "cpdown failed\n");
25295 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25298 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25301 + struct path h_path;
25302 + struct au_branch *br;
25303 + struct inode *delegated;
25305 + br = au_sbr(a->sb, a->mvd_bdst);
25306 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25307 + err = PTR_ERR(h_path.dentry);
25308 + if (IS_ERR(h_path.dentry)) {
25309 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25314 + if (d_is_positive(h_path.dentry)) {
25315 + h_path.mnt = au_br_mnt(br);
25316 + delegated = NULL;
25317 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25318 + &delegated, /*force*/0);
25319 + if (unlikely(err == -EWOULDBLOCK)) {
25320 + pr_warn("cannot retry for NFSv4 delegation"
25321 + " for an internal unlink\n");
25324 + if (unlikely(err))
25325 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25327 + dput(h_path.dentry);
25335 + * unlink the topmost h_dentry
25337 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25340 + struct path h_path;
25341 + struct inode *delegated;
25343 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25344 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25345 + delegated = NULL;
25346 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25347 + if (unlikely(err == -EWOULDBLOCK)) {
25348 + pr_warn("cannot retry for NFSv4 delegation"
25349 + " for an internal unlink\n");
25352 + if (unlikely(err))
25353 + AU_MVD_PR(dmsg, "unlink failed\n");
25359 +/* Since mvdown succeeded, we ignore an error of this function */
25360 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25363 + struct au_branch *br;
25365 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25366 + br = au_sbr(a->sb, a->mvd_bsrc);
25367 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25369 + br = au_sbr(a->sb, a->mvd_bdst);
25370 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25371 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25374 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25376 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25380 + * copy-down the file and unlink the bsrc file.
25381 + * - unlink the bdst whout if exist
25382 + * - copy-down the file (with whtmp name and rename)
25383 + * - unlink the bsrc file
25385 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25389 + err = au_do_mkdir(dmsg, a);
25391 + err = au_do_lock(dmsg, a);
25392 + if (unlikely(err))
25396 + * do not revert the activities we made on bdst since they should be
25397 + * harmless in aufs.
25400 + err = au_do_cpdown(dmsg, a);
25402 + err = au_do_unlink_wh(dmsg, a);
25403 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25404 + err = au_do_unlink(dmsg, a);
25405 + if (unlikely(err))
25408 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25409 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25410 + if (find_lower_writable(a) < 0)
25411 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25413 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25414 + au_do_stfs(dmsg, a);
25416 + /* maintain internal array */
25417 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25418 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25419 + au_set_dbtop(a->dentry, a->mvd_bdst);
25420 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25421 + au_set_ibtop(a->inode, a->mvd_bdst);
25423 + /* hide the lower */
25424 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25425 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25426 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25427 + au_set_ibbot(a->inode, a->mvd_bsrc);
25429 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25430 + au_set_dbbot(a->dentry, a->mvd_bdst);
25431 + if (au_ibbot(a->inode) < a->mvd_bdst)
25432 + au_set_ibbot(a->inode, a->mvd_bdst);
25435 + au_do_unlock(dmsg, a);
25441 +/* ---------------------------------------------------------------------- */
25443 +/* make sure the file is idle */
25444 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25446 + int err, plinked;
25449 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25450 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25451 + && au_dcount(a->dentry) == 1
25452 + && atomic_read(&a->inode->i_count) == 1
25453 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25454 + && (!plinked || !au_plink_test(a->inode))
25455 + && a->inode->i_nlink == 1)
25460 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25461 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25462 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25463 + a->mvd_h_src_inode->i_nlink,
25464 + plinked, plinked ? au_plink_test(a->inode) : 0);
25471 +/* make sure the parent dir is fine */
25472 +static int au_mvd_args_parent(const unsigned char dmsg,
25473 + struct au_mvd_args *a)
25476 + aufs_bindex_t bindex;
25479 + if (unlikely(au_alive_dir(a->parent))) {
25481 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25485 + a->bopq = au_dbdiropq(a->parent);
25486 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25487 + AuDbg("b%d\n", bindex);
25488 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25489 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25491 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25492 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25493 + a->bopq, a->mvd_bdst);
25501 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25502 + struct au_mvd_args *a)
25505 + struct au_dinfo *dinfo, *tmp;
25507 + /* lookup the next lower positive entry */
25509 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25510 + if (unlikely(!tmp))
25515 + dinfo = au_di(a->dentry);
25516 + au_di_cp(tmp, dinfo);
25517 + au_di_swap(tmp, dinfo);
25519 + /* returns the number of positive dentries */
25520 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25521 + /* AuLkup_IGNORE_PERM */ 0);
25523 + a->bwh = au_dbwh(a->dentry);
25524 + else if (err > 0)
25525 + a->bfound = au_dbtop(a->dentry);
25527 + au_di_swap(tmp, dinfo);
25528 + au_rw_write_unlock(&tmp->di_rwsem);
25530 + if (unlikely(err < 0))
25531 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25534 + * here, we have these cases.
25536 + * no positive dentry under bsrc. there are more sub-cases.
25538 + * there no whiteout, we can safely move-down.
25541 + * bsrc < bwh && bwh < bdst
25542 + * there is a whiteout on RO branch. cannot proceed.
25544 + * there is a whiteout on the RW target branch. it should
25547 + * there is a whiteout somewhere unrelated branch.
25548 + * -1 < bfound && bfound <= bsrc
25551 + * found, but it is on RO branch between bsrc and bdst. cannot
25554 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25557 + * found, after we create the file on bdst, it will be hidden.
25560 + AuDebugOn(a->bfound == -1
25562 + && a->bwh <= a->mvd_bsrc);
25563 + AuDebugOn(-1 < a->bfound
25564 + && a->bfound <= a->mvd_bsrc);
25567 + if (a->bfound == -1
25568 + && a->mvd_bsrc < a->bwh
25570 + && a->bwh < a->mvd_bdst) {
25571 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25572 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25573 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25575 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25576 + a->mvd_errno = EAU_MVDOWN_UPPER;
25577 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25578 + a->mvd_bdst, a->bfound);
25582 + err = 0; /* success */
25589 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25594 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25595 + && a->bfound == a->mvd_bdst)
25601 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25604 + struct au_branch *br;
25607 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25611 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25612 + a->mvd_bsrc = au_ibtop(a->inode);
25614 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25615 + if (unlikely(a->mvd_bsrc < 0
25616 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25617 + || au_dbbot(a->dentry) < a->mvd_bsrc
25618 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25619 + || (a->mvd_bsrc < au_ibtop(a->inode)
25620 + || au_ibbot(a->inode) < a->mvd_bsrc
25621 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25622 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25623 + AU_MVD_PR(dmsg, "no upper\n");
25627 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25628 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25629 + AU_MVD_PR(dmsg, "on the bottom\n");
25632 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25633 + br = au_sbr(a->sb, a->mvd_bsrc);
25634 + err = au_br_rdonly(br);
25635 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25636 + if (unlikely(err))
25638 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25639 + || IS_APPEND(a->mvd_h_src_inode))) {
25641 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25647 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25648 + a->mvd_bdst = find_lower_writable(a);
25649 + if (unlikely(a->mvd_bdst < 0)) {
25650 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25651 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25655 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25656 + if (unlikely(a->mvd_bdst < 0
25657 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25658 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25659 + AU_MVD_PR(dmsg, "no lower brid\n");
25664 + err = au_mvd_args_busy(dmsg, a);
25666 + err = au_mvd_args_parent(dmsg, a);
25668 + err = au_mvd_args_intermediate(dmsg, a);
25670 + err = au_mvd_args_exist(dmsg, a);
25672 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25679 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25682 + unsigned char dmsg;
25683 + struct au_mvd_args *args;
25684 + struct inode *inode;
25686 + inode = d_inode(dentry);
25688 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25692 + args = kmalloc(sizeof(*args), GFP_NOFS);
25693 + if (unlikely(!args))
25696 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25698 + /* VERIFY_WRITE */
25699 + err = !access_ok(uarg, sizeof(*uarg));
25700 + if (unlikely(err)) {
25705 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25706 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25707 + args->mvdown.au_errno = 0;
25708 + args->dentry = dentry;
25709 + args->inode = inode;
25710 + args->sb = dentry->d_sb;
25713 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25714 + args->parent = dget_parent(dentry);
25715 + args->dir = d_inode(args->parent);
25716 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25717 + dput(args->parent);
25718 + if (unlikely(args->parent != dentry->d_parent)) {
25719 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25723 + inode_lock_nested(inode, I_MUTEX_CHILD);
25724 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25725 + if (unlikely(err))
25728 + di_write_lock_parent(args->parent);
25729 + err = au_mvd_args(dmsg, args);
25730 + if (unlikely(err))
25733 + err = au_do_mvdown(dmsg, args);
25734 + if (unlikely(err))
25737 + au_cpup_attr_timesizes(args->dir);
25738 + au_cpup_attr_timesizes(inode);
25739 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25740 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25741 + /* au_digen_dec(dentry); */
25744 + di_write_unlock(args->parent);
25745 + aufs_read_unlock(dentry, AuLock_DW);
25747 + inode_unlock(inode);
25749 + inode_unlock(args->dir);
25751 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25754 + au_kfree_rcu(args);
25759 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25760 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25761 +++ linux/fs/aufs/opts.c 2019-09-16 09:38:43.216175640 +0200
25763 +// SPDX-License-Identifier: GPL-2.0
25765 + * Copyright (C) 2005-2019 Junjiro R. Okajima
25767 + * This program, aufs is free software; you can redistribute it and/or modify
25768 + * it under the terms of the GNU General Public License as published by
25769 + * the Free Software Foundation; either version 2 of the License, or
25770 + * (at your option) any later version.
25772 + * This program is distributed in the hope that it will be useful,
25773 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25774 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25775 + * GNU General Public License for more details.
25777 + * You should have received a copy of the GNU General Public License
25778 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25782 + * mount options/flags
25785 +#include <linux/namei.h>
25786 +#include <linux/types.h> /* a distribution requires */
25787 +#include <linux/parser.h>
25790 +/* ---------------------------------------------------------------------- */
25794 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25795 + Opt_idel, Opt_imod,
25796 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25797 + Opt_rdblk_def, Opt_rdhash_def,
25798 + Opt_xino, Opt_noxino,
25799 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25800 + Opt_trunc_xino_path, Opt_itrunc_xino,
25801 + Opt_trunc_xib, Opt_notrunc_xib,
25802 + Opt_shwh, Opt_noshwh,
25803 + Opt_plink, Opt_noplink, Opt_list_plink,
25805 + Opt_dio, Opt_nodio,
25806 + Opt_diropq_a, Opt_diropq_w,
25807 + Opt_warn_perm, Opt_nowarn_perm,
25808 + Opt_wbr_copyup, Opt_wbr_create,
25810 + Opt_verbose, Opt_noverbose,
25811 + Opt_sum, Opt_nosum, Opt_wsum,
25812 + Opt_dirperm1, Opt_nodirperm1,
25813 + Opt_dirren, Opt_nodirren,
25814 + Opt_acl, Opt_noacl,
25815 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25818 +static match_table_t options = {
25819 + {Opt_br, "br=%s"},
25820 + {Opt_br, "br:%s"},
25822 + {Opt_add, "add=%d:%s"},
25823 + {Opt_add, "add:%d:%s"},
25824 + {Opt_add, "ins=%d:%s"},
25825 + {Opt_add, "ins:%d:%s"},
25826 + {Opt_append, "append=%s"},
25827 + {Opt_append, "append:%s"},
25828 + {Opt_prepend, "prepend=%s"},
25829 + {Opt_prepend, "prepend:%s"},
25831 + {Opt_del, "del=%s"},
25832 + {Opt_del, "del:%s"},
25833 + /* {Opt_idel, "idel:%d"}, */
25834 + {Opt_mod, "mod=%s"},
25835 + {Opt_mod, "mod:%s"},
25836 + /* {Opt_imod, "imod:%d:%s"}, */
25838 + {Opt_dirwh, "dirwh=%d"},
25840 + {Opt_xino, "xino=%s"},
25841 + {Opt_noxino, "noxino"},
25842 + {Opt_trunc_xino, "trunc_xino"},
25843 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25844 + {Opt_notrunc_xino, "notrunc_xino"},
25845 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25846 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25847 + /* {Opt_zxino, "zxino=%s"}, */
25848 + {Opt_trunc_xib, "trunc_xib"},
25849 + {Opt_notrunc_xib, "notrunc_xib"},
25851 +#ifdef CONFIG_PROC_FS
25852 + {Opt_plink, "plink"},
25854 + {Opt_ignore_silent, "plink"},
25857 + {Opt_noplink, "noplink"},
25859 +#ifdef CONFIG_AUFS_DEBUG
25860 + {Opt_list_plink, "list_plink"},
25863 + {Opt_udba, "udba=%s"},
25865 + {Opt_dio, "dio"},
25866 + {Opt_nodio, "nodio"},
25868 +#ifdef CONFIG_AUFS_DIRREN
25869 + {Opt_dirren, "dirren"},
25870 + {Opt_nodirren, "nodirren"},
25872 + {Opt_ignore, "dirren"},
25873 + {Opt_ignore_silent, "nodirren"},
25876 +#ifdef CONFIG_AUFS_FHSM
25877 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25879 + {Opt_ignore, "fhsm_sec=%d"},
25882 + {Opt_diropq_a, "diropq=always"},
25883 + {Opt_diropq_a, "diropq=a"},
25884 + {Opt_diropq_w, "diropq=whiteouted"},
25885 + {Opt_diropq_w, "diropq=w"},
25887 + {Opt_warn_perm, "warn_perm"},
25888 + {Opt_nowarn_perm, "nowarn_perm"},
25890 + /* keep them temporary */
25891 + {Opt_ignore_silent, "nodlgt"},
25892 + {Opt_ignore, "clean_plink"},
25894 +#ifdef CONFIG_AUFS_SHWH
25895 + {Opt_shwh, "shwh"},
25897 + {Opt_noshwh, "noshwh"},
25899 + {Opt_dirperm1, "dirperm1"},
25900 + {Opt_nodirperm1, "nodirperm1"},
25902 + {Opt_verbose, "verbose"},
25903 + {Opt_verbose, "v"},
25904 + {Opt_noverbose, "noverbose"},
25905 + {Opt_noverbose, "quiet"},
25906 + {Opt_noverbose, "q"},
25907 + {Opt_noverbose, "silent"},
25909 + {Opt_sum, "sum"},
25910 + {Opt_nosum, "nosum"},
25911 + {Opt_wsum, "wsum"},
25913 + {Opt_rdcache, "rdcache=%d"},
25914 + {Opt_rdblk, "rdblk=%d"},
25915 + {Opt_rdblk_def, "rdblk=def"},
25916 + {Opt_rdhash, "rdhash=%d"},
25917 + {Opt_rdhash_def, "rdhash=def"},
25919 + {Opt_wbr_create, "create=%s"},
25920 + {Opt_wbr_create, "create_policy=%s"},
25921 + {Opt_wbr_copyup, "cpup=%s"},
25922 + {Opt_wbr_copyup, "copyup=%s"},
25923 + {Opt_wbr_copyup, "copyup_policy=%s"},
25925 + /* generic VFS flag */
25926 +#ifdef CONFIG_FS_POSIX_ACL
25927 + {Opt_acl, "acl"},
25928 + {Opt_noacl, "noacl"},
25930 + {Opt_ignore, "acl"},
25931 + {Opt_ignore_silent, "noacl"},
25934 + /* internal use for the scripts */
25935 + {Opt_ignore_silent, "si=%s"},
25937 + {Opt_br, "dirs=%s"},
25938 + {Opt_ignore, "debug=%d"},
25939 + {Opt_ignore, "delete=whiteout"},
25940 + {Opt_ignore, "delete=all"},
25941 + {Opt_ignore, "imap=%s"},
25943 + /* temporary workaround, due to old mount(8)? */
25944 + {Opt_ignore_silent, "relatime"},
25949 +/* ---------------------------------------------------------------------- */
25951 +static const char *au_parser_pattern(int val, match_table_t tbl)
25953 + struct match_token *p;
25956 + while (p->pattern) {
25957 + if (p->token == val)
25958 + return p->pattern;
25965 +static const char *au_optstr(int *val, match_table_t tbl)
25967 + struct match_token *p;
25974 + while (p->pattern) {
25976 + && (v & p->token) == p->token) {
25977 + *val &= ~p->token;
25978 + return p->pattern;
25987 +/* ---------------------------------------------------------------------- */
25989 +static match_table_t brperm = {
25990 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25991 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25992 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25996 +static match_table_t brattr = {
25998 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25999 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26000 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26001 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26002 +#ifdef CONFIG_AUFS_FHSM
26003 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26005 +#ifdef CONFIG_AUFS_XATTR
26006 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26007 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26008 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26009 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26010 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26011 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26014 + /* ro/rr branch */
26015 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26018 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26019 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26024 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26031 + p = strchr(str, '+');
26034 + v = match_token(str, table, args);
26036 + if (v & AuBrAttr_CMOO_Mask)
26037 + attr &= ~AuBrAttr_CMOO_Mask;
26042 + pr_warn("ignored branch attribute %s\n", str);
26052 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26060 + p = au_optstr(&perm, brattr);
26063 + memcpy(q, p, sz + 1);
26069 + p = au_optstr(&perm, brattr);
26073 + memcpy(q, p, sz + 1);
26079 + return q - str->a;
26082 +static int noinline_for_stack br_perm_val(char *perm)
26084 + int val, bad, sz;
26086 + substring_t args[MAX_OPT_ARGS];
26087 + au_br_perm_str_t attr;
26089 + p = strchr(perm, '+');
26092 + val = match_token(perm, brperm, args);
26096 + pr_warn("ignored branch permission %s\n", perm);
26097 + val = AuBrPerm_RO;
26103 + val |= br_attr_val(p + 1, brattr, args);
26106 + switch (val & AuBrPerm_Mask) {
26107 + case AuBrPerm_RO:
26108 + case AuBrPerm_RR:
26109 + bad = val & AuBrWAttr_Mask;
26110 + val &= ~AuBrWAttr_Mask;
26112 + case AuBrPerm_RW:
26113 + bad = val & AuBrRAttr_Mask;
26114 + val &= ~AuBrRAttr_Mask;
26119 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26120 + * does not treat it as an error, just warning.
26121 + * this is a tiny guard for the user operation.
26123 + if (val & AuBrAttr_UNPIN) {
26124 + bad |= AuBrAttr_UNPIN;
26125 + val &= ~AuBrAttr_UNPIN;
26128 + if (unlikely(bad)) {
26129 + sz = au_do_optstr_br_attr(&attr, bad);
26131 + pr_warn("ignored branch attribute %s\n", attr.a);
26138 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26140 + au_br_perm_str_t attr;
26146 + p = au_optstr(&perm, brperm);
26147 + AuDebugOn(!p || !*p);
26149 + memcpy(q, p, sz + 1);
26152 + sz = au_do_optstr_br_attr(&attr, perm);
26155 + memcpy(q, attr.a, sz + 1);
26158 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26161 +/* ---------------------------------------------------------------------- */
26163 +static match_table_t udbalevel = {
26164 + {AuOpt_UDBA_REVAL, "reval"},
26165 + {AuOpt_UDBA_NONE, "none"},
26166 +#ifdef CONFIG_AUFS_HNOTIFY
26167 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26168 +#ifdef CONFIG_AUFS_HFSNOTIFY
26169 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26175 +static int noinline_for_stack udba_val(char *str)
26177 + substring_t args[MAX_OPT_ARGS];
26179 + return match_token(str, udbalevel, args);
26182 +const char *au_optstr_udba(int udba)
26184 + return au_parser_pattern(udba, udbalevel);
26187 +/* ---------------------------------------------------------------------- */
26189 +static match_table_t au_wbr_create_policy = {
26190 + {AuWbrCreate_TDP, "tdp"},
26191 + {AuWbrCreate_TDP, "top-down-parent"},
26192 + {AuWbrCreate_RR, "rr"},
26193 + {AuWbrCreate_RR, "round-robin"},
26194 + {AuWbrCreate_MFS, "mfs"},
26195 + {AuWbrCreate_MFS, "most-free-space"},
26196 + {AuWbrCreate_MFSV, "mfs:%d"},
26197 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26199 + /* top-down regardless the parent, and then mfs */
26200 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26201 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26203 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26204 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26205 + {AuWbrCreate_PMFS, "pmfs"},
26206 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26207 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26208 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26213 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26214 + struct au_opt_wbr_create *create)
26217 + unsigned long long ull;
26220 + if (!match_u64(arg, &ull))
26221 + create->mfsrr_watermark = ull;
26223 + pr_err("bad integer in %s\n", str);
26230 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26231 + struct au_opt_wbr_create *create)
26236 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26237 + create->mfs_second = n;
26239 + pr_err("bad integer in %s\n", str);
26246 +static int noinline_for_stack
26247 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26250 + substring_t args[MAX_OPT_ARGS];
26252 + err = match_token(str, au_wbr_create_policy, args);
26253 + create->wbr_create = err;
26255 + case AuWbrCreate_MFSRRV:
26256 + case AuWbrCreate_TDMFSV:
26257 + case AuWbrCreate_PMFSRRV:
26258 + e = au_wbr_mfs_wmark(&args[0], str, create);
26260 + e = au_wbr_mfs_sec(&args[1], str, create);
26264 + case AuWbrCreate_MFSRR:
26265 + case AuWbrCreate_TDMFS:
26266 + case AuWbrCreate_PMFSRR:
26267 + e = au_wbr_mfs_wmark(&args[0], str, create);
26268 + if (unlikely(e)) {
26273 + case AuWbrCreate_MFS:
26274 + case AuWbrCreate_PMFS:
26275 + create->mfs_second = AUFS_MFS_DEF_SEC;
26277 + case AuWbrCreate_MFSV:
26278 + case AuWbrCreate_PMFSV:
26279 + e = au_wbr_mfs_sec(&args[0], str, create);
26288 +const char *au_optstr_wbr_create(int wbr_create)
26290 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26293 +static match_table_t au_wbr_copyup_policy = {
26294 + {AuWbrCopyup_TDP, "tdp"},
26295 + {AuWbrCopyup_TDP, "top-down-parent"},
26296 + {AuWbrCopyup_BUP, "bup"},
26297 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26298 + {AuWbrCopyup_BU, "bu"},
26299 + {AuWbrCopyup_BU, "bottom-up"},
26303 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26305 + substring_t args[MAX_OPT_ARGS];
26307 + return match_token(str, au_wbr_copyup_policy, args);
26310 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26312 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26315 +/* ---------------------------------------------------------------------- */
26317 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26319 +static void dump_opts(struct au_opts *opts)
26321 +#ifdef CONFIG_AUFS_DEBUG
26322 + /* reduce stack space */
26324 + struct au_opt_add *add;
26325 + struct au_opt_del *del;
26326 + struct au_opt_mod *mod;
26327 + struct au_opt_xino *xino;
26328 + struct au_opt_xino_itrunc *xino_itrunc;
26329 + struct au_opt_wbr_create *create;
26331 + struct au_opt *opt;
26334 + while (opt->type != Opt_tail) {
26335 + switch (opt->type) {
26337 + u.add = &opt->add;
26338 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26339 + u.add->bindex, u.add->pathname, u.add->perm,
26340 + u.add->path.dentry);
26344 + u.del = &opt->del;
26345 + AuDbg("del {%s, %p}\n",
26346 + u.del->pathname, u.del->h_path.dentry);
26350 + u.mod = &opt->mod;
26351 + AuDbg("mod {%s, 0x%x, %p}\n",
26352 + u.mod->path, u.mod->perm, u.mod->h_root);
26355 + u.add = &opt->add;
26356 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26357 + u.add->bindex, u.add->pathname, u.add->perm,
26358 + u.add->path.dentry);
26360 + case Opt_prepend:
26361 + u.add = &opt->add;
26362 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26363 + u.add->bindex, u.add->pathname, u.add->perm,
26364 + u.add->path.dentry);
26367 + AuDbg("dirwh %d\n", opt->dirwh);
26369 + case Opt_rdcache:
26370 + AuDbg("rdcache %d\n", opt->rdcache);
26373 + AuDbg("rdblk %u\n", opt->rdblk);
26375 + case Opt_rdblk_def:
26376 + AuDbg("rdblk_def\n");
26379 + AuDbg("rdhash %u\n", opt->rdhash);
26381 + case Opt_rdhash_def:
26382 + AuDbg("rdhash_def\n");
26385 + u.xino = &opt->xino;
26386 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26388 + case Opt_trunc_xino:
26389 + AuLabel(trunc_xino);
26391 + case Opt_notrunc_xino:
26392 + AuLabel(notrunc_xino);
26394 + case Opt_trunc_xino_path:
26395 + case Opt_itrunc_xino:
26396 + u.xino_itrunc = &opt->xino_itrunc;
26397 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26402 + case Opt_trunc_xib:
26403 + AuLabel(trunc_xib);
26405 + case Opt_notrunc_xib:
26406 + AuLabel(notrunc_xib);
26414 + case Opt_dirperm1:
26415 + AuLabel(dirperm1);
26417 + case Opt_nodirperm1:
26418 + AuLabel(nodirperm1);
26423 + case Opt_noplink:
26424 + AuLabel(noplink);
26426 + case Opt_list_plink:
26427 + AuLabel(list_plink);
26430 + AuDbg("udba %d, %s\n",
26431 + opt->udba, au_optstr_udba(opt->udba));
26439 + case Opt_diropq_a:
26440 + AuLabel(diropq_a);
26442 + case Opt_diropq_w:
26443 + AuLabel(diropq_w);
26445 + case Opt_warn_perm:
26446 + AuLabel(warn_perm);
26448 + case Opt_nowarn_perm:
26449 + AuLabel(nowarn_perm);
26451 + case Opt_verbose:
26452 + AuLabel(verbose);
26454 + case Opt_noverbose:
26455 + AuLabel(noverbose);
26466 + case Opt_wbr_create:
26467 + u.create = &opt->wbr_create;
26468 + AuDbg("create %d, %s\n", u.create->wbr_create,
26469 + au_optstr_wbr_create(u.create->wbr_create));
26470 + switch (u.create->wbr_create) {
26471 + case AuWbrCreate_MFSV:
26472 + case AuWbrCreate_PMFSV:
26473 + AuDbg("%d sec\n", u.create->mfs_second);
26475 + case AuWbrCreate_MFSRR:
26476 + case AuWbrCreate_TDMFS:
26477 + AuDbg("%llu watermark\n",
26478 + u.create->mfsrr_watermark);
26480 + case AuWbrCreate_MFSRRV:
26481 + case AuWbrCreate_TDMFSV:
26482 + case AuWbrCreate_PMFSRRV:
26483 + AuDbg("%llu watermark, %d sec\n",
26484 + u.create->mfsrr_watermark,
26485 + u.create->mfs_second);
26489 + case Opt_wbr_copyup:
26490 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26491 + au_optstr_wbr_copyup(opt->wbr_copyup));
26493 + case Opt_fhsm_sec:
26494 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26499 + case Opt_nodirren:
26500 + AuLabel(nodirren);
26516 +void au_opts_free(struct au_opts *opts)
26518 + struct au_opt *opt;
26521 + while (opt->type != Opt_tail) {
26522 + switch (opt->type) {
26525 + case Opt_prepend:
26526 + path_put(&opt->add.path);
26530 + path_put(&opt->del.h_path);
26534 + dput(opt->mod.h_root);
26537 + fput(opt->xino.file);
26544 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26545 + aufs_bindex_t bindex)
26548 + struct au_opt_add *add = &opt->add;
26551 + add->bindex = bindex;
26552 + add->perm = AuBrPerm_RO;
26553 + add->pathname = opt_str;
26554 + p = strchr(opt_str, '=');
26558 + add->perm = br_perm_val(p);
26561 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26564 + add->perm = AuBrPerm_RO;
26565 + if (au_test_fs_rr(add->path.dentry->d_sb))
26566 + add->perm = AuBrPerm_RR;
26567 + else if (!bindex && !(sb_flags & SB_RDONLY))
26568 + add->perm = AuBrPerm_RW;
26570 + opt->type = Opt_add;
26573 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26580 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26584 + del->pathname = args[0].from;
26585 + AuDbg("del path %s\n", del->pathname);
26587 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26588 + if (unlikely(err))
26589 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26594 +#if 0 /* reserved for future use */
26595 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26596 + struct au_opt_del *del, substring_t args[])
26599 + struct dentry *root;
26602 + root = sb->s_root;
26603 + aufs_read_lock(root, AuLock_FLUSH);
26604 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26605 + pr_err("out of bounds, %d\n", bindex);
26610 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26611 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26614 + aufs_read_unlock(root, !AuLock_IR);
26619 +static int noinline_for_stack
26620 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26623 + struct path path;
26627 + mod->path = args[0].from;
26628 + p = strchr(mod->path, '=');
26629 + if (unlikely(!p)) {
26630 + pr_err("no permission %s\n", args[0].from);
26635 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26636 + if (unlikely(err)) {
26637 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26641 + mod->perm = br_perm_val(p);
26642 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26643 + mod->h_root = dget(path.dentry);
26650 +#if 0 /* reserved for future use */
26651 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26652 + struct au_opt_mod *mod, substring_t args[])
26655 + struct dentry *root;
26658 + root = sb->s_root;
26659 + aufs_read_lock(root, AuLock_FLUSH);
26660 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26661 + pr_err("out of bounds, %d\n", bindex);
26666 + mod->perm = br_perm_val(args[1].from);
26667 + AuDbg("mod path %s, perm 0x%x, %s\n",
26668 + mod->path, mod->perm, args[1].from);
26669 + mod->h_root = dget(au_h_dptr(root, bindex));
26672 + aufs_read_unlock(root, !AuLock_IR);
26677 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26678 + substring_t args[])
26681 + struct file *file;
26683 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26684 + err = PTR_ERR(file);
26685 + if (IS_ERR(file))
26689 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26691 + pr_err("%s must be outside\n", args[0].from);
26696 + xino->file = file;
26697 + xino->path = args[0].from;
26703 +static int noinline_for_stack
26704 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26705 + struct au_opt_xino_itrunc *xino_itrunc,
26706 + substring_t args[])
26709 + aufs_bindex_t bbot, bindex;
26710 + struct path path;
26711 + struct dentry *root;
26713 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26714 + if (unlikely(err)) {
26715 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26719 + xino_itrunc->bindex = -1;
26720 + root = sb->s_root;
26721 + aufs_read_lock(root, AuLock_FLUSH);
26722 + bbot = au_sbbot(sb);
26723 + for (bindex = 0; bindex <= bbot; bindex++) {
26724 + if (au_h_dptr(root, bindex) == path.dentry) {
26725 + xino_itrunc->bindex = bindex;
26729 + aufs_read_unlock(root, !AuLock_IR);
26732 + if (unlikely(xino_itrunc->bindex < 0)) {
26733 + pr_err("no such branch %s\n", args[0].from);
26741 +/* called without aufs lock */
26742 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26744 + int err, n, token;
26745 + aufs_bindex_t bindex;
26746 + unsigned char skipped;
26747 + struct dentry *root;
26748 + struct au_opt *opt, *opt_tail;
26750 + /* reduce the stack space */
26752 + struct au_opt_xino_itrunc *xino_itrunc;
26753 + struct au_opt_wbr_create *create;
26756 + substring_t args[MAX_OPT_ARGS];
26760 + a = kmalloc(sizeof(*a), GFP_NOFS);
26761 + if (unlikely(!a))
26764 + root = sb->s_root;
26768 + opt_tail = opt + opts->max_opt - 1;
26769 + opt->type = Opt_tail;
26770 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26773 + token = match_token(opt_str, options, a->args);
26777 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26779 + err = opt_add(opt, opt_str, opts->sb_flags,
26781 + if (unlikely(!err && ++opt > opt_tail)) {
26785 + opt->type = Opt_tail;
26790 + if (unlikely(match_int(&a->args[0], &n))) {
26791 + pr_err("bad integer in %s\n", opt_str);
26795 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26798 + opt->type = token;
26801 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26802 + /*dummy bindex*/1);
26804 + opt->type = token;
26806 + case Opt_prepend:
26807 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26810 + opt->type = token;
26813 + err = au_opts_parse_del(&opt->del, a->args);
26815 + opt->type = token;
26817 +#if 0 /* reserved for future use */
26819 + del->pathname = "(indexed)";
26820 + if (unlikely(match_int(&args[0], &n))) {
26821 + pr_err("bad integer in %s\n", opt_str);
26824 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26826 + opt->type = token;
26830 + err = au_opts_parse_mod(&opt->mod, a->args);
26832 + opt->type = token;
26834 +#ifdef IMOD /* reserved for future use */
26836 + u.mod->path = "(indexed)";
26837 + if (unlikely(match_int(&a->args[0], &n))) {
26838 + pr_err("bad integer in %s\n", opt_str);
26841 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26843 + opt->type = token;
26847 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26849 + opt->type = token;
26852 + case Opt_trunc_xino_path:
26853 + err = au_opts_parse_xino_itrunc_path
26854 + (sb, &opt->xino_itrunc, a->args);
26856 + opt->type = token;
26859 + case Opt_itrunc_xino:
26860 + u.xino_itrunc = &opt->xino_itrunc;
26861 + if (unlikely(match_int(&a->args[0], &n))) {
26862 + pr_err("bad integer in %s\n", opt_str);
26865 + u.xino_itrunc->bindex = n;
26866 + aufs_read_lock(root, AuLock_FLUSH);
26867 + if (n < 0 || au_sbbot(sb) < n) {
26868 + pr_err("out of bounds, %d\n", n);
26869 + aufs_read_unlock(root, !AuLock_IR);
26872 + aufs_read_unlock(root, !AuLock_IR);
26874 + opt->type = token;
26878 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26881 + opt->type = token;
26884 + case Opt_rdcache:
26885 + if (unlikely(match_int(&a->args[0], &n))) {
26886 + pr_err("bad integer in %s\n", opt_str);
26889 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26890 + pr_err("rdcache must be smaller than %d\n",
26891 + AUFS_RDCACHE_MAX);
26894 + opt->rdcache = n;
26896 + opt->type = token;
26899 + if (unlikely(match_int(&a->args[0], &n)
26901 + || n > KMALLOC_MAX_SIZE)) {
26902 + pr_err("bad integer in %s\n", opt_str);
26905 + if (unlikely(n && n < NAME_MAX)) {
26906 + pr_err("rdblk must be larger than %d\n",
26912 + opt->type = token;
26915 + if (unlikely(match_int(&a->args[0], &n)
26917 + || n * sizeof(struct hlist_head)
26918 + > KMALLOC_MAX_SIZE)) {
26919 + pr_err("bad integer in %s\n", opt_str);
26924 + opt->type = token;
26927 + case Opt_trunc_xino:
26928 + case Opt_notrunc_xino:
26930 + case Opt_trunc_xib:
26931 + case Opt_notrunc_xib:
26934 + case Opt_dirperm1:
26935 + case Opt_nodirperm1:
26937 + case Opt_noplink:
26938 + case Opt_list_plink:
26941 + case Opt_diropq_a:
26942 + case Opt_diropq_w:
26943 + case Opt_warn_perm:
26944 + case Opt_nowarn_perm:
26945 + case Opt_verbose:
26946 + case Opt_noverbose:
26950 + case Opt_rdblk_def:
26951 + case Opt_rdhash_def:
26953 + case Opt_nodirren:
26957 + opt->type = token;
26961 + opt->udba = udba_val(a->args[0].from);
26962 + if (opt->udba >= 0) {
26964 + opt->type = token;
26966 + pr_err("wrong value, %s\n", opt_str);
26969 + case Opt_wbr_create:
26970 + u.create = &opt->wbr_create;
26971 + u.create->wbr_create
26972 + = au_wbr_create_val(a->args[0].from, u.create);
26973 + if (u.create->wbr_create >= 0) {
26975 + opt->type = token;
26977 + pr_err("wrong value, %s\n", opt_str);
26979 + case Opt_wbr_copyup:
26980 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26981 + if (opt->wbr_copyup >= 0) {
26983 + opt->type = token;
26985 + pr_err("wrong value, %s\n", opt_str);
26988 + case Opt_fhsm_sec:
26989 + if (unlikely(match_int(&a->args[0], &n)
26991 + pr_err("bad integer in %s\n", opt_str);
26994 + if (sysaufs_brs) {
26995 + opt->fhsm_second = n;
26996 + opt->type = token;
26998 + pr_warn("ignored %s\n", opt_str);
27003 + pr_warn("ignored %s\n", opt_str);
27005 + case Opt_ignore_silent:
27010 + pr_err("unknown option %s\n", opt_str);
27014 + if (!err && !skipped) {
27015 + if (unlikely(++opt > opt_tail)) {
27018 + opt->type = Opt_tail;
27021 + opt->type = Opt_tail;
27027 + if (unlikely(err))
27028 + au_opts_free(opts);
27034 +static int au_opt_wbr_create(struct super_block *sb,
27035 + struct au_opt_wbr_create *create)
27038 + struct au_sbinfo *sbinfo;
27040 + SiMustWriteLock(sb);
27042 + err = 1; /* handled */
27043 + sbinfo = au_sbi(sb);
27044 + if (sbinfo->si_wbr_create_ops->fin) {
27045 + err = sbinfo->si_wbr_create_ops->fin(sb);
27050 + sbinfo->si_wbr_create = create->wbr_create;
27051 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27052 + switch (create->wbr_create) {
27053 + case AuWbrCreate_MFSRRV:
27054 + case AuWbrCreate_MFSRR:
27055 + case AuWbrCreate_TDMFS:
27056 + case AuWbrCreate_TDMFSV:
27057 + case AuWbrCreate_PMFSRR:
27058 + case AuWbrCreate_PMFSRRV:
27059 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27061 + case AuWbrCreate_MFS:
27062 + case AuWbrCreate_MFSV:
27063 + case AuWbrCreate_PMFS:
27064 + case AuWbrCreate_PMFSV:
27065 + sbinfo->si_wbr_mfs.mfs_expire
27066 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27070 + if (sbinfo->si_wbr_create_ops->init)
27071 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27078 + * plus: processed without an error
27079 + * zero: unprocessed
27081 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27082 + struct au_opts *opts)
27085 + struct au_sbinfo *sbinfo;
27087 + SiMustWriteLock(sb);
27089 + err = 1; /* handled */
27090 + sbinfo = au_sbi(sb);
27091 + switch (opt->type) {
27093 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27094 + sbinfo->si_mntflags |= opt->udba;
27095 + opts->given_udba |= opt->udba;
27099 + au_opt_set(sbinfo->si_mntflags, PLINK);
27101 + case Opt_noplink:
27102 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27103 + au_plink_put(sb, /*verbose*/1);
27104 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27106 + case Opt_list_plink:
27107 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27108 + au_plink_list(sb);
27112 + au_opt_set(sbinfo->si_mntflags, DIO);
27113 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27116 + au_opt_clr(sbinfo->si_mntflags, DIO);
27117 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27120 + case Opt_fhsm_sec:
27121 + au_fhsm_set(sbinfo, opt->fhsm_second);
27124 + case Opt_diropq_a:
27125 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27127 + case Opt_diropq_w:
27128 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27131 + case Opt_warn_perm:
27132 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27134 + case Opt_nowarn_perm:
27135 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27138 + case Opt_verbose:
27139 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27141 + case Opt_noverbose:
27142 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27146 + au_opt_set(sbinfo->si_mntflags, SUM);
27149 + au_opt_clr(sbinfo->si_mntflags, SUM);
27150 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27153 + au_opt_clr(sbinfo->si_mntflags, SUM);
27154 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27157 + case Opt_wbr_create:
27158 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27160 + case Opt_wbr_copyup:
27161 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27162 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27166 + sbinfo->si_dirwh = opt->dirwh;
27169 + case Opt_rdcache:
27170 + sbinfo->si_rdcache
27171 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27174 + sbinfo->si_rdblk = opt->rdblk;
27176 + case Opt_rdblk_def:
27177 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27180 + sbinfo->si_rdhash = opt->rdhash;
27182 + case Opt_rdhash_def:
27183 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27187 + au_opt_set(sbinfo->si_mntflags, SHWH);
27190 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27193 + case Opt_dirperm1:
27194 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27196 + case Opt_nodirperm1:
27197 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27200 + case Opt_trunc_xino:
27201 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27203 + case Opt_notrunc_xino:
27204 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27207 + case Opt_trunc_xino_path:
27208 + case Opt_itrunc_xino:
27209 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27215 + case Opt_trunc_xib:
27216 + au_fset_opts(opts->flags, TRUNC_XIB);
27218 + case Opt_notrunc_xib:
27219 + au_fclr_opts(opts->flags, TRUNC_XIB);
27224 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27225 + err = au_dr_opt_set(sb);
27230 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27232 + case Opt_nodirren:
27234 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27235 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27241 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27245 + sb->s_flags |= SB_POSIXACL;
27248 + sb->s_flags &= ~SB_POSIXACL;
27260 + * returns tri-state.
27261 + * plus: processed without an error
27262 + * zero: unprocessed
27265 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27266 + struct au_opts *opts)
27268 + int err, do_refresh;
27271 + switch (opt->type) {
27273 + opt->add.bindex = au_sbbot(sb) + 1;
27274 + if (opt->add.bindex < 0)
27275 + opt->add.bindex = 0;
27277 + /* Always goto add, not fallthrough */
27278 + case Opt_prepend:
27279 + opt->add.bindex = 0;
27280 + /* fallthrough */
27281 + add: /* indented label */
27283 + err = au_br_add(sb, &opt->add,
27284 + au_ftest_opts(opts->flags, REMOUNT));
27287 + au_fset_opts(opts->flags, REFRESH);
27293 + err = au_br_del(sb, &opt->del,
27294 + au_ftest_opts(opts->flags, REMOUNT));
27297 + au_fset_opts(opts->flags, TRUNC_XIB);
27298 + au_fset_opts(opts->flags, REFRESH);
27304 + err = au_br_mod(sb, &opt->mod,
27305 + au_ftest_opts(opts->flags, REMOUNT),
27310 + au_fset_opts(opts->flags, REFRESH);
27317 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27318 + struct au_opt_xino **opt_xino,
27319 + struct au_opts *opts)
27324 + switch (opt->type) {
27326 + err = au_xino_set(sb, &opt->xino,
27327 + !!au_ftest_opts(opts->flags, REMOUNT));
27328 + if (unlikely(err))
27331 + *opt_xino = &opt->xino;
27336 + *opt_xino = (void *)-1;
27343 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27344 + unsigned int pending)
27347 + aufs_bindex_t bindex, bbot;
27348 + unsigned char do_plink, skip, do_free, can_no_dreval;
27349 + struct au_branch *br;
27350 + struct au_wbr *wbr;
27351 + struct dentry *root, *dentry;
27352 + struct inode *dir, *h_dir;
27353 + struct au_sbinfo *sbinfo;
27354 + struct au_hinode *hdir;
27356 + SiMustAnyLock(sb);
27358 + sbinfo = au_sbi(sb);
27359 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27361 + if (!(sb_flags & SB_RDONLY)) {
27362 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27363 + pr_warn("first branch should be rw\n");
27364 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27365 + pr_warn_once("shwh should be used with ro\n");
27368 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27369 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27370 + pr_warn_once("udba=*notify requires xino\n");
27372 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27373 + pr_warn_once("dirperm1 breaks the protection"
27374 + " by the permission bits on the lower branch\n");
27378 + root = sb->s_root;
27379 + dir = d_inode(root);
27380 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27381 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27383 + bbot = au_sbbot(sb);
27384 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27386 + h_dir = au_h_iptr(dir, bindex);
27387 + br = au_sbr(sb, bindex);
27389 + if ((br->br_perm & AuBrAttr_ICEX)
27390 + && !h_dir->i_op->listxattr)
27391 + br->br_perm &= ~AuBrAttr_ICEX;
27393 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27394 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27395 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27399 + wbr = br->br_wbr;
27401 + wbr_wh_read_lock(wbr);
27403 + if (!au_br_writable(br->br_perm)) {
27406 + || (!wbr->wbr_whbase
27407 + && !wbr->wbr_plink
27408 + && !wbr->wbr_orph));
27409 + } else if (!au_br_wh_linkable(br->br_perm)) {
27410 + /* skip = (!br->br_whbase && !br->br_orph); */
27411 + skip = (!wbr || !wbr->wbr_whbase);
27412 + if (skip && wbr) {
27414 + skip = !!wbr->wbr_plink;
27416 + skip = !wbr->wbr_plink;
27419 + /* skip = (br->br_whbase && br->br_ohph); */
27420 + skip = (wbr && wbr->wbr_whbase);
27423 + skip = !!wbr->wbr_plink;
27425 + skip = !wbr->wbr_plink;
27429 + wbr_wh_read_unlock(wbr);
27431 + if (can_no_dreval) {
27432 + dentry = br->br_path.dentry;
27433 + spin_lock(&dentry->d_lock);
27434 + if (dentry->d_flags &
27435 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27436 + can_no_dreval = 0;
27437 + spin_unlock(&dentry->d_lock);
27440 + if (au_br_fhsm(br->br_perm)) {
27442 + AuDebugOn(!br->br_fhsm);
27448 + hdir = au_hi(dir, bindex);
27449 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27451 + wbr_wh_write_lock(wbr);
27452 + err = au_wh_init(br, sb);
27454 + wbr_wh_write_unlock(wbr);
27455 + au_hn_inode_unlock(hdir);
27457 + if (!err && do_free) {
27458 + au_kfree_rcu(wbr);
27459 + br->br_wbr = NULL;
27463 + if (can_no_dreval)
27464 + au_fset_si(sbinfo, NO_DREVAL);
27466 + au_fclr_si(sbinfo, NO_DREVAL);
27469 + au_fset_si(sbinfo, FHSM);
27470 + for (bindex = bbot; bindex >= 0; bindex--) {
27471 + br = au_sbr(sb, bindex);
27472 + if (au_br_fhsm(br->br_perm)) {
27473 + au_fhsm_set_bottom(sb, bindex);
27478 + au_fclr_si(sbinfo, FHSM);
27479 + au_fhsm_set_bottom(sb, -1);
27485 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27488 + unsigned int tmp;
27489 + aufs_bindex_t bindex, bbot;
27490 + struct au_opt *opt;
27491 + struct au_opt_xino *opt_xino, xino;
27492 + struct au_sbinfo *sbinfo;
27493 + struct au_branch *br;
27494 + struct inode *dir;
27496 + SiMustWriteLock(sb);
27501 + while (err >= 0 && opt->type != Opt_tail)
27502 + err = au_opt_simple(sb, opt++, opts);
27505 + else if (unlikely(err < 0))
27508 + /* disable xino and udba temporary */
27509 + sbinfo = au_sbi(sb);
27510 + tmp = sbinfo->si_mntflags;
27511 + au_opt_clr(sbinfo->si_mntflags, XINO);
27512 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27515 + while (err >= 0 && opt->type != Opt_tail)
27516 + err = au_opt_br(sb, opt++, opts);
27519 + else if (unlikely(err < 0))
27522 + bbot = au_sbbot(sb);
27523 + if (unlikely(bbot < 0)) {
27525 + pr_err("no branches\n");
27529 + if (au_opt_test(tmp, XINO))
27530 + au_opt_set(sbinfo->si_mntflags, XINO);
27532 + while (!err && opt->type != Opt_tail)
27533 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27534 + if (unlikely(err))
27537 + err = au_opts_verify(sb, sb->s_flags, tmp);
27538 + if (unlikely(err))
27541 + /* restore xino */
27542 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27543 + xino.file = au_xino_def(sb);
27544 + err = PTR_ERR(xino.file);
27545 + if (IS_ERR(xino.file))
27548 + err = au_xino_set(sb, &xino, /*remount*/0);
27550 + if (unlikely(err))
27554 + /* restore udba */
27555 + tmp &= AuOptMask_UDBA;
27556 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27557 + sbinfo->si_mntflags |= tmp;
27558 + bbot = au_sbbot(sb);
27559 + for (bindex = 0; bindex <= bbot; bindex++) {
27560 + br = au_sbr(sb, bindex);
27561 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27562 + if (unlikely(err))
27563 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27565 + /* go on even if err */
27567 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27568 + dir = d_inode(sb->s_root);
27569 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27576 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27579 + unsigned char no_dreval;
27580 + struct inode *dir;
27581 + struct au_opt_xino *opt_xino;
27582 + struct au_opt *opt;
27583 + struct au_sbinfo *sbinfo;
27585 + SiMustWriteLock(sb);
27587 + err = au_dr_opt_flush(sb);
27588 + if (unlikely(err))
27590 + au_fset_opts(opts->flags, DR_FLUSHED);
27592 + dir = d_inode(sb->s_root);
27593 + sbinfo = au_sbi(sb);
27596 + while (err >= 0 && opt->type != Opt_tail) {
27597 + err = au_opt_simple(sb, opt, opts);
27599 + err = au_opt_br(sb, opt, opts);
27601 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27607 + /* go on even err */
27609 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27610 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27611 + if (unlikely(rerr && !err))
27614 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27615 + au_fset_opts(opts->flags, REFRESH_IDOP);
27617 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27618 + rerr = au_xib_trunc(sb);
27619 + if (unlikely(rerr && !err))
27623 + /* will be handled by the caller */
27624 + if (!au_ftest_opts(opts->flags, REFRESH)
27625 + && (opts->given_udba
27626 + || au_opt_test(sbinfo->si_mntflags, XINO)
27627 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27629 + au_fset_opts(opts->flags, REFRESH);
27631 + AuDbg("status 0x%x\n", opts->flags);
27637 +/* ---------------------------------------------------------------------- */
27639 +unsigned int au_opt_udba(struct super_block *sb)
27641 + return au_mntflags(sb) & AuOptMask_UDBA;
27643 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27644 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27645 +++ linux/fs/aufs/opts.h 2019-07-11 15:42:14.472238057 +0200
27647 +/* SPDX-License-Identifier: GPL-2.0 */
27649 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27651 + * This program, aufs is free software; you can redistribute it and/or modify
27652 + * it under the terms of the GNU General Public License as published by
27653 + * the Free Software Foundation; either version 2 of the License, or
27654 + * (at your option) any later version.
27656 + * This program is distributed in the hope that it will be useful,
27657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27659 + * GNU General Public License for more details.
27661 + * You should have received a copy of the GNU General Public License
27662 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27666 + * mount options/flags
27669 +#ifndef __AUFS_OPTS_H__
27670 +#define __AUFS_OPTS_H__
27674 +#include <linux/path.h>
27678 +/* ---------------------------------------------------------------------- */
27681 +#define AuOpt_XINO 1 /* external inode number bitmap
27682 + and translation table */
27683 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27684 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27685 +#define AuOpt_UDBA_REVAL (1 << 3)
27686 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27687 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27688 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27689 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27691 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27692 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27693 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27694 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27695 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27696 +#define AuOpt_DIO (1 << 14) /* direct io */
27697 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27699 +#ifndef CONFIG_AUFS_HNOTIFY
27700 +#undef AuOpt_UDBA_HNOTIFY
27701 +#define AuOpt_UDBA_HNOTIFY 0
27703 +#ifndef CONFIG_AUFS_DIRREN
27704 +#undef AuOpt_DIRREN
27705 +#define AuOpt_DIRREN 0
27707 +#ifndef CONFIG_AUFS_SHWH
27709 +#define AuOpt_SHWH 0
27712 +#define AuOpt_Def (AuOpt_XINO \
27713 + | AuOpt_UDBA_REVAL \
27715 + /* | AuOpt_DIRPERM1 */ \
27716 + | AuOpt_WARN_PERM)
27717 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27718 + | AuOpt_UDBA_REVAL \
27719 + | AuOpt_UDBA_HNOTIFY)
27721 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27722 +#define au_opt_set(flags, name) do { \
27723 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27724 + ((flags) |= AuOpt_##name); \
27726 +#define au_opt_set_udba(flags, name) do { \
27727 + (flags) &= ~AuOptMask_UDBA; \
27728 + ((flags) |= AuOpt_##name); \
27730 +#define au_opt_clr(flags, name) do { \
27731 + ((flags) &= ~AuOpt_##name); \
27734 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27736 +#ifdef CONFIG_PROC_FS
27739 + return mntflags & ~AuOpt_PLINK;
27743 +/* ---------------------------------------------------------------------- */
27745 +/* policies to select one among multiple writable branches */
27747 + AuWbrCreate_TDP, /* top down parent */
27748 + AuWbrCreate_RR, /* round robin */
27749 + AuWbrCreate_MFS, /* most free space */
27750 + AuWbrCreate_MFSV, /* mfs with seconds */
27751 + AuWbrCreate_MFSRR, /* mfs then rr */
27752 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27753 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27754 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27755 + AuWbrCreate_PMFS, /* parent and mfs */
27756 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27757 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27758 + AuWbrCreate_PMFSRRV, /* plus seconds */
27760 + AuWbrCreate_Def = AuWbrCreate_TDP
27764 + AuWbrCopyup_TDP, /* top down parent */
27765 + AuWbrCopyup_BUP, /* bottom up parent */
27766 + AuWbrCopyup_BU, /* bottom up */
27768 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27771 +/* ---------------------------------------------------------------------- */
27773 +struct au_opt_add {
27774 + aufs_bindex_t bindex;
27777 + struct path path;
27780 +struct au_opt_del {
27782 + struct path h_path;
27785 +struct au_opt_mod {
27788 + struct dentry *h_root;
27791 +struct au_opt_xino {
27793 + struct file *file;
27796 +struct au_opt_xino_itrunc {
27797 + aufs_bindex_t bindex;
27800 +struct au_opt_wbr_create {
27803 + unsigned long long mfsrr_watermark;
27809 + struct au_opt_xino xino;
27810 + struct au_opt_xino_itrunc xino_itrunc;
27811 + struct au_opt_add add;
27812 + struct au_opt_del del;
27813 + struct au_opt_mod mod;
27816 + unsigned int rdblk;
27817 + unsigned int rdhash;
27819 + struct au_opt_wbr_create wbr_create;
27821 + unsigned int fhsm_second;
27826 +#define AuOpts_REMOUNT 1
27827 +#define AuOpts_REFRESH (1 << 1)
27828 +#define AuOpts_TRUNC_XIB (1 << 2)
27829 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27830 +#define AuOpts_REFRESH_IDOP (1 << 4)
27831 +#define AuOpts_DR_FLUSHED (1 << 5)
27832 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27833 +#define au_fset_opts(flags, name) \
27834 + do { (flags) |= AuOpts_##name; } while (0)
27835 +#define au_fclr_opts(flags, name) \
27836 + do { (flags) &= ~AuOpts_##name; } while (0)
27838 +#ifndef CONFIG_AUFS_DIRREN
27839 +#undef AuOpts_DR_FLUSHED
27840 +#define AuOpts_DR_FLUSHED 0
27844 + struct au_opt *opt;
27847 + unsigned int given_udba;
27848 + unsigned int flags;
27849 + unsigned long sb_flags;
27852 +/* ---------------------------------------------------------------------- */
27855 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27856 +const char *au_optstr_udba(int udba);
27857 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27858 +const char *au_optstr_wbr_create(int wbr_create);
27860 +void au_opts_free(struct au_opts *opts);
27861 +struct super_block;
27862 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27863 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27864 + unsigned int pending);
27865 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27866 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27868 +unsigned int au_opt_udba(struct super_block *sb);
27870 +#endif /* __KERNEL__ */
27871 +#endif /* __AUFS_OPTS_H__ */
27872 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27873 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27874 +++ linux/fs/aufs/plink.c 2019-07-11 15:42:14.472238057 +0200
27876 +// SPDX-License-Identifier: GPL-2.0
27878 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27880 + * This program, aufs is free software; you can redistribute it and/or modify
27881 + * it under the terms of the GNU General Public License as published by
27882 + * the Free Software Foundation; either version 2 of the License, or
27883 + * (at your option) any later version.
27885 + * This program is distributed in the hope that it will be useful,
27886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27888 + * GNU General Public License for more details.
27890 + * You should have received a copy of the GNU General Public License
27891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27901 + * the pseudo-link maintenance mode.
27902 + * during a user process maintains the pseudo-links,
27903 + * prohibit adding a new plink and branch manipulation.
27907 + * For entry functions which will handle plink, and i_mutex is already held
27909 + * They cannot wait and should return an error at once.
27910 + * Callers has to check the error.
27912 + * For entry functions which will handle plink, but i_mutex is not held
27914 + * They can wait the plink maintenance mode to finish.
27916 + * They behave like F_SETLK and F_SETLKW.
27917 + * If the caller never handle plink, then both flags are unnecessary.
27920 +int au_plink_maint(struct super_block *sb, int flags)
27924 + struct task_struct *parent, *prev;
27925 + struct au_sbinfo *sbi;
27927 + SiMustAnyLock(sb);
27930 + if (!au_opt_test(au_mntflags(sb), PLINK))
27933 + sbi = au_sbi(sb);
27934 + pid = sbi->si_plink_maint_pid;
27935 + if (!pid || pid == current->pid)
27938 + /* todo: it highly depends upon /sbin/mount.aufs */
27940 + parent = current;
27944 + parent = rcu_dereference(parent->real_parent);
27945 + if (parent == prev)
27947 + ppid = task_pid_vnr(parent);
27948 + if (pid == ppid) {
27949 + rcu_read_unlock();
27954 + rcu_read_unlock();
27956 + if (au_ftest_lock(flags, NOPLMW)) {
27957 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27958 + /* AuDebugOn(!lockdep_depth(current)); */
27959 + while (sbi->si_plink_maint_pid) {
27960 + si_read_unlock(sb);
27961 + /* gave up wake_up_bit() */
27962 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27964 + if (au_ftest_lock(flags, FLUSH))
27965 + au_nwt_flush(&sbi->si_nowait);
27966 + si_noflush_read_lock(sb);
27968 + } else if (au_ftest_lock(flags, NOPLM)) {
27969 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27977 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27979 + spin_lock(&sbinfo->si_plink_maint_lock);
27980 + sbinfo->si_plink_maint_pid = 0;
27981 + spin_unlock(&sbinfo->si_plink_maint_lock);
27982 + wake_up_all(&sbinfo->si_plink_wq);
27985 +int au_plink_maint_enter(struct super_block *sb)
27988 + struct au_sbinfo *sbinfo;
27991 + sbinfo = au_sbi(sb);
27992 + /* make sure i am the only one in this fs */
27993 + si_write_lock(sb, AuLock_FLUSH);
27994 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27995 + spin_lock(&sbinfo->si_plink_maint_lock);
27996 + if (!sbinfo->si_plink_maint_pid)
27997 + sbinfo->si_plink_maint_pid = current->pid;
28000 + spin_unlock(&sbinfo->si_plink_maint_lock);
28002 + si_write_unlock(sb);
28007 +/* ---------------------------------------------------------------------- */
28009 +#ifdef CONFIG_AUFS_DEBUG
28010 +void au_plink_list(struct super_block *sb)
28013 + struct au_sbinfo *sbinfo;
28014 + struct hlist_bl_head *hbl;
28015 + struct hlist_bl_node *pos;
28016 + struct au_icntnr *icntnr;
28018 + SiMustAnyLock(sb);
28020 + sbinfo = au_sbi(sb);
28021 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28022 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28024 + for (i = 0; i < AuPlink_NHASH; i++) {
28025 + hbl = sbinfo->si_plink + i;
28026 + hlist_bl_lock(hbl);
28027 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28028 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28029 + hlist_bl_unlock(hbl);
28034 +/* is the inode pseudo-linked? */
28035 +int au_plink_test(struct inode *inode)
28038 + struct au_sbinfo *sbinfo;
28039 + struct hlist_bl_head *hbl;
28040 + struct hlist_bl_node *pos;
28041 + struct au_icntnr *icntnr;
28043 + sbinfo = au_sbi(inode->i_sb);
28044 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28045 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28046 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28049 + i = au_plink_hash(inode->i_ino);
28050 + hbl = sbinfo->si_plink + i;
28051 + hlist_bl_lock(hbl);
28052 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28053 + if (&icntnr->vfs_inode == inode) {
28057 + hlist_bl_unlock(hbl);
28061 +/* ---------------------------------------------------------------------- */
28064 + * generate a name for plink.
28065 + * the file will be stored under AUFS_WH_PLINKDIR.
28067 +/* 20 is max digits length of ulong 64 */
28068 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28070 +static int plink_name(char *name, int len, struct inode *inode,
28071 + aufs_bindex_t bindex)
28074 + struct inode *h_inode;
28076 + h_inode = au_h_iptr(inode, bindex);
28077 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28081 +struct au_do_plink_lkup_args {
28082 + struct dentry **errp;
28083 + struct qstr *tgtname;
28084 + struct dentry *h_parent;
28085 + struct au_branch *br;
28088 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28089 + struct dentry *h_parent,
28090 + struct au_branch *br)
28092 + struct dentry *h_dentry;
28093 + struct inode *h_inode;
28095 + h_inode = d_inode(h_parent);
28096 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28097 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28098 + inode_unlock_shared(h_inode);
28102 +static void au_call_do_plink_lkup(void *args)
28104 + struct au_do_plink_lkup_args *a = args;
28105 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28108 +/* lookup the plink-ed @inode under the branch at @bindex */
28109 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28111 + struct dentry *h_dentry, *h_parent;
28112 + struct au_branch *br;
28114 + char a[PLINK_NAME_LEN];
28115 + struct qstr tgtname = QSTR_INIT(a, 0);
28117 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28119 + br = au_sbr(inode->i_sb, bindex);
28120 + h_parent = br->br_wbr->wbr_plink;
28121 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28123 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28124 + struct au_do_plink_lkup_args args = {
28125 + .errp = &h_dentry,
28126 + .tgtname = &tgtname,
28127 + .h_parent = h_parent,
28131 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28132 + if (unlikely(wkq_err))
28133 + h_dentry = ERR_PTR(wkq_err);
28135 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28140 +/* create a pseudo-link */
28141 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28142 + struct dentry *h_dentry, struct au_branch *br)
28145 + struct path h_path = {
28146 + .mnt = au_br_mnt(br)
28148 + struct inode *h_dir, *delegated;
28150 + h_dir = d_inode(h_parent);
28151 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28153 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28154 + err = PTR_ERR(h_path.dentry);
28155 + if (IS_ERR(h_path.dentry))
28159 + /* wh.plink dir is not monitored */
28160 + /* todo: is it really safe? */
28161 + if (d_is_positive(h_path.dentry)
28162 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28163 + delegated = NULL;
28164 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28165 + if (unlikely(err == -EWOULDBLOCK)) {
28166 + pr_warn("cannot retry for NFSv4 delegation"
28167 + " for an internal unlink\n");
28170 + dput(h_path.dentry);
28171 + h_path.dentry = NULL;
28175 + if (!err && d_is_negative(h_path.dentry)) {
28176 + delegated = NULL;
28177 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28178 + if (unlikely(err == -EWOULDBLOCK)) {
28179 + pr_warn("cannot retry for NFSv4 delegation"
28180 + " for an internal link\n");
28184 + dput(h_path.dentry);
28187 + inode_unlock(h_dir);
28191 +struct do_whplink_args {
28193 + struct qstr *tgt;
28194 + struct dentry *h_parent;
28195 + struct dentry *h_dentry;
28196 + struct au_branch *br;
28199 +static void call_do_whplink(void *args)
28201 + struct do_whplink_args *a = args;
28202 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28205 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28206 + aufs_bindex_t bindex, struct au_branch *br)
28208 + int err, wkq_err;
28209 + struct au_wbr *wbr;
28210 + struct dentry *h_parent;
28211 + char a[PLINK_NAME_LEN];
28212 + struct qstr tgtname = QSTR_INIT(a, 0);
28214 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28215 + h_parent = wbr->wbr_plink;
28216 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28218 + /* always superio. */
28219 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28220 + struct do_whplink_args args = {
28223 + .h_parent = h_parent,
28224 + .h_dentry = h_dentry,
28227 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28228 + if (unlikely(wkq_err))
28231 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28237 + * create a new pseudo-link for @h_dentry on @bindex.
28238 + * the linked inode is held in aufs @inode.
28240 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28241 + struct dentry *h_dentry)
28243 + struct super_block *sb;
28244 + struct au_sbinfo *sbinfo;
28245 + struct hlist_bl_head *hbl;
28246 + struct hlist_bl_node *pos;
28247 + struct au_icntnr *icntnr;
28248 + int found, err, cnt, i;
28250 + sb = inode->i_sb;
28251 + sbinfo = au_sbi(sb);
28252 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28253 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28255 + found = au_plink_test(inode);
28259 + i = au_plink_hash(inode->i_ino);
28260 + hbl = sbinfo->si_plink + i;
28263 + hlist_bl_lock(hbl);
28264 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28265 + if (&icntnr->vfs_inode == inode) {
28271 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28272 + hlist_bl_add_head(&icntnr->plink, hbl);
28274 + hlist_bl_unlock(hbl);
28276 + cnt = au_hbl_count(hbl);
28277 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28278 + if (cnt > AUFS_PLINK_WARN)
28279 + AuWarn1(msg ", %d\n", cnt);
28281 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28282 + if (unlikely(err)) {
28283 + pr_warn("err %d, damaged pseudo link.\n", err);
28284 + au_hbl_del(&icntnr->plink, hbl);
28285 + iput(&icntnr->vfs_inode);
28288 + iput(&icntnr->vfs_inode);
28291 +/* free all plinks */
28292 +void au_plink_put(struct super_block *sb, int verbose)
28295 + struct au_sbinfo *sbinfo;
28296 + struct hlist_bl_head *hbl;
28297 + struct hlist_bl_node *pos, *tmp;
28298 + struct au_icntnr *icntnr;
28300 + SiMustWriteLock(sb);
28302 + sbinfo = au_sbi(sb);
28303 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28304 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28306 + /* no spin_lock since sbinfo is write-locked */
28308 + for (i = 0; i < AuPlink_NHASH; i++) {
28309 + hbl = sbinfo->si_plink + i;
28310 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28311 + pr_warn("pseudo-link is not flushed");
28314 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28315 + iput(&icntnr->vfs_inode);
28316 + INIT_HLIST_BL_HEAD(hbl);
28320 +void au_plink_clean(struct super_block *sb, int verbose)
28322 + struct dentry *root;
28324 + root = sb->s_root;
28325 + aufs_write_lock(root);
28326 + if (au_opt_test(au_mntflags(sb), PLINK))
28327 + au_plink_put(sb, verbose);
28328 + aufs_write_unlock(root);
28331 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28334 + aufs_bindex_t btop, bbot, bindex;
28337 + btop = au_ibtop(inode);
28338 + bbot = au_ibbot(inode);
28340 + for (bindex = btop; bindex <= bbot; bindex++) {
28341 + if (!au_h_iptr(inode, bindex)
28342 + || au_ii_br_id(inode, bindex) != br_id)
28344 + au_set_h_iptr(inode, bindex, NULL, 0);
28349 + for (bindex = btop; bindex <= bbot; bindex++)
28350 + if (au_h_iptr(inode, bindex)) {
28360 +/* free the plinks on a branch specified by @br_id */
28361 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28363 + struct au_sbinfo *sbinfo;
28364 + struct hlist_bl_head *hbl;
28365 + struct hlist_bl_node *pos, *tmp;
28366 + struct au_icntnr *icntnr;
28367 + struct inode *inode;
28370 + SiMustWriteLock(sb);
28372 + sbinfo = au_sbi(sb);
28373 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28374 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28376 + /* no bit_lock since sbinfo is write-locked */
28377 + for (i = 0; i < AuPlink_NHASH; i++) {
28378 + hbl = sbinfo->si_plink + i;
28379 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28380 + inode = au_igrab(&icntnr->vfs_inode);
28381 + ii_write_lock_child(inode);
28382 + do_put = au_plink_do_half_refresh(inode, br_id);
28384 + hlist_bl_del(&icntnr->plink);
28387 + ii_write_unlock(inode);
28392 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28393 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28394 +++ linux/fs/aufs/poll.c 2019-07-11 15:42:14.472238057 +0200
28396 +// SPDX-License-Identifier: GPL-2.0
28398 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28400 + * This program, aufs is free software; you can redistribute it and/or modify
28401 + * it under the terms of the GNU General Public License as published by
28402 + * the Free Software Foundation; either version 2 of the License, or
28403 + * (at your option) any later version.
28405 + * This program is distributed in the hope that it will be useful,
28406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28408 + * GNU General Public License for more details.
28410 + * You should have received a copy of the GNU General Public License
28411 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28416 + * There is only one filesystem which implements ->poll operation, currently.
28421 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28424 + struct file *h_file;
28425 + struct super_block *sb;
28427 + /* We should pretend an error happened. */
28428 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28429 + sb = file->f_path.dentry->d_sb;
28430 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28432 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28433 + if (IS_ERR(h_file)) {
28434 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28438 + mask = vfs_poll(h_file, pt);
28439 + fput(h_file); /* instead of au_read_post() */
28442 + si_read_unlock(sb);
28443 + if (mask & EPOLLERR)
28444 + AuDbg("mask 0x%x\n", mask);
28447 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28448 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28449 +++ linux/fs/aufs/posix_acl.c 2019-07-11 15:42:14.472238057 +0200
28451 +// SPDX-License-Identifier: GPL-2.0
28453 + * Copyright (C) 2014-2019 Junjiro R. Okajima
28455 + * This program, aufs is free software; you can redistribute it and/or modify
28456 + * it under the terms of the GNU General Public License as published by
28457 + * the Free Software Foundation; either version 2 of the License, or
28458 + * (at your option) any later version.
28460 + * This program is distributed in the hope that it will be useful,
28461 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28462 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28463 + * GNU General Public License for more details.
28465 + * You should have received a copy of the GNU General Public License
28466 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28470 + * posix acl operations
28473 +#include <linux/fs.h>
28476 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28478 + struct posix_acl *acl;
28480 + aufs_bindex_t bindex;
28481 + struct inode *h_inode;
28482 + struct super_block *sb;
28485 + sb = inode->i_sb;
28486 + si_read_lock(sb, AuLock_FLUSH);
28487 + ii_read_lock_child(inode);
28488 + if (!(sb->s_flags & SB_POSIXACL))
28491 + bindex = au_ibtop(inode);
28492 + h_inode = au_h_iptr(inode, bindex);
28493 + if (unlikely(!h_inode
28494 + || ((h_inode->i_mode & S_IFMT)
28495 + != (inode->i_mode & S_IFMT)))) {
28496 + err = au_busy_or_stale();
28497 + acl = ERR_PTR(err);
28501 + /* always topmost only */
28502 + acl = get_acl(h_inode, type);
28503 + if (!IS_ERR_OR_NULL(acl))
28504 + set_cached_acl(inode, type, acl);
28507 + ii_read_unlock(inode);
28508 + si_read_unlock(sb);
28510 + AuTraceErrPtr(acl);
28514 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28518 + struct dentry *dentry;
28519 + struct au_sxattr arg = {
28520 + .type = AU_ACL_SET,
28527 + IMustLock(inode);
28529 + if (inode->i_ino == AUFS_ROOT_INO)
28530 + dentry = dget(inode->i_sb->s_root);
28532 + dentry = d_find_alias(inode);
28534 + dentry = d_find_any_alias(inode);
28536 + pr_warn("cannot handle this inode, "
28537 + "please report to aufs-users ML\n");
28543 + ssz = au_sxattr(dentry, inode, &arg);
28548 + set_cached_acl(inode, type, acl);
28554 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28555 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28556 +++ linux/fs/aufs/procfs.c 2019-07-11 15:42:14.472238057 +0200
28558 +// SPDX-License-Identifier: GPL-2.0
28560 + * Copyright (C) 2010-2019 Junjiro R. Okajima
28562 + * This program, aufs is free software; you can redistribute it and/or modify
28563 + * it under the terms of the GNU General Public License as published by
28564 + * the Free Software Foundation; either version 2 of the License, or
28565 + * (at your option) any later version.
28567 + * This program is distributed in the hope that it will be useful,
28568 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28569 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28570 + * GNU General Public License for more details.
28572 + * You should have received a copy of the GNU General Public License
28573 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28577 + * procfs interfaces
28580 +#include <linux/proc_fs.h>
28583 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28585 + struct au_sbinfo *sbinfo;
28587 + sbinfo = file->private_data;
28589 + au_plink_maint_leave(sbinfo);
28590 + kobject_put(&sbinfo->si_kobj);
28596 +static void au_procfs_plm_write_clean(struct file *file)
28598 + struct au_sbinfo *sbinfo;
28600 + sbinfo = file->private_data;
28602 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28605 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28608 + struct super_block *sb;
28609 + struct au_sbinfo *sbinfo;
28610 + struct hlist_bl_node *pos;
28613 + if (unlikely(file->private_data))
28617 + /* don't use au_sbilist_lock() here */
28618 + hlist_bl_lock(&au_sbilist);
28619 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28620 + if (id == sysaufs_si_id(sbinfo)) {
28621 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28622 + sb = sbinfo->si_sb;
28625 + hlist_bl_unlock(&au_sbilist);
28628 + if (unlikely(!sb))
28631 + err = au_plink_maint_enter(sb);
28633 + /* keep kobject_get() */
28634 + file->private_data = sbinfo;
28636 + kobject_put(&sbinfo->si_kobj);
28642 + * Accept a valid "si=xxxx" only.
28643 + * Once it is accepted successfully, accept "clean" too.
28645 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28646 + size_t count, loff_t *ppos)
28649 + unsigned long id;
28650 + /* last newline is allowed */
28651 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28654 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28658 + if (unlikely(count > sizeof(buf)))
28661 + err = copy_from_user(buf, ubuf, count);
28662 + if (unlikely(err)) {
28669 + if (!strcmp("clean", buf)) {
28670 + au_procfs_plm_write_clean(file);
28671 + goto out_success;
28672 + } else if (unlikely(strncmp("si=", buf, 3)))
28675 + err = kstrtoul(buf + 3, 16, &id);
28676 + if (unlikely(err))
28679 + err = au_procfs_plm_write_si(file, id);
28680 + if (unlikely(err))
28684 + err = count; /* success */
28689 +static const struct file_operations au_procfs_plm_fop = {
28690 + .write = au_procfs_plm_write,
28691 + .release = au_procfs_plm_release,
28692 + .owner = THIS_MODULE
28695 +/* ---------------------------------------------------------------------- */
28697 +static struct proc_dir_entry *au_procfs_dir;
28699 +void au_procfs_fin(void)
28701 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28702 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28705 +int __init au_procfs_init(void)
28708 + struct proc_dir_entry *entry;
28711 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28712 + if (unlikely(!au_procfs_dir))
28715 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28716 + au_procfs_dir, &au_procfs_plm_fop);
28717 + if (unlikely(!entry))
28721 + goto out; /* success */
28725 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28729 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28730 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28731 +++ linux/fs/aufs/rdu.c 2019-07-11 15:42:14.472238057 +0200
28733 +// SPDX-License-Identifier: GPL-2.0
28735 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28737 + * This program, aufs is free software; you can redistribute it and/or modify
28738 + * it under the terms of the GNU General Public License as published by
28739 + * the Free Software Foundation; either version 2 of the License, or
28740 + * (at your option) any later version.
28742 + * This program is distributed in the hope that it will be useful,
28743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28745 + * GNU General Public License for more details.
28747 + * You should have received a copy of the GNU General Public License
28748 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28752 + * readdir in userspace.
28755 +#include <linux/compat.h>
28756 +#include <linux/fs_stack.h>
28757 +#include <linux/security.h>
28760 +/* bits for struct aufs_rdu.flags */
28761 +#define AuRdu_CALLED 1
28762 +#define AuRdu_CONT (1 << 1)
28763 +#define AuRdu_FULL (1 << 2)
28764 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28765 +#define au_fset_rdu(flags, name) \
28766 + do { (flags) |= AuRdu_##name; } while (0)
28767 +#define au_fclr_rdu(flags, name) \
28768 + do { (flags) &= ~AuRdu_##name; } while (0)
28770 +struct au_rdu_arg {
28771 + struct dir_context ctx;
28772 + struct aufs_rdu *rdu;
28773 + union au_rdu_ent_ul ent;
28774 + unsigned long end;
28776 + struct super_block *sb;
28780 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28781 + loff_t offset, u64 h_ino, unsigned int d_type)
28784 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28785 + struct aufs_rdu *rdu = arg->rdu;
28786 + struct au_rdu_ent ent;
28790 + au_fset_rdu(rdu->cookie.flags, CALLED);
28791 + len = au_rdu_len(nlen);
28792 + if (arg->ent.ul + len < arg->end) {
28794 + ent.bindex = rdu->cookie.bindex;
28795 + ent.type = d_type;
28797 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28798 + ent.type = DT_UNKNOWN;
28800 + /* unnecessary to support mmap_sem since this is a dir */
28802 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28804 + if (copy_to_user(arg->ent.e->name, name, nlen))
28806 + /* the terminating NULL */
28807 + if (__put_user(0, arg->ent.e->name + nlen))
28810 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28811 + arg->ent.ul += len;
28815 + au_fset_rdu(rdu->cookie.flags, FULL);
28817 + rdu->tail = arg->ent;
28821 + /* AuTraceErr(err); */
28825 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28829 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28831 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28832 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28834 + if (unlikely(offset != cookie->h_pos))
28840 + au_fclr_rdu(cookie->flags, CALLED);
28842 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28846 + && au_ftest_rdu(cookie->flags, CALLED)
28847 + && !au_ftest_rdu(cookie->flags, FULL));
28848 + cookie->h_pos = h_file->f_pos;
28855 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28858 + aufs_bindex_t bbot;
28859 + struct au_rdu_arg arg = {
28861 + .actor = au_rdu_fill
28864 + struct dentry *dentry;
28865 + struct inode *inode;
28866 + struct file *h_file;
28867 + struct au_rdu_cookie *cookie = &rdu->cookie;
28869 + /* VERIFY_WRITE */
28870 + err = !access_ok(rdu->ent.e, rdu->sz);
28871 + if (unlikely(err)) {
28877 + rdu->tail = rdu->ent;
28880 + arg.ent = rdu->ent;
28881 + arg.end = arg.ent.ul;
28882 + arg.end += rdu->sz;
28885 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28888 + err = security_file_permission(file, MAY_READ);
28890 + if (unlikely(err))
28893 + dentry = file->f_path.dentry;
28894 + inode = d_inode(dentry);
28895 + inode_lock_shared(inode);
28897 + arg.sb = inode->i_sb;
28898 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28899 + if (unlikely(err))
28901 + err = au_alive_dir(dentry);
28902 + if (unlikely(err))
28904 + /* todo: reval? */
28905 + fi_read_lock(file);
28908 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28909 + && cookie->generation != au_figen(file)))
28914 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28916 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28918 + bbot = au_fbtop(file);
28919 + if (cookie->bindex < bbot)
28920 + cookie->bindex = bbot;
28921 + bbot = au_fbbot_dir(file);
28922 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28923 + for (; !err && cookie->bindex <= bbot;
28924 + cookie->bindex++, cookie->h_pos = 0) {
28925 + h_file = au_hf_dir(file, cookie->bindex);
28929 + au_fclr_rdu(cookie->flags, FULL);
28930 + err = au_rdu_do(h_file, &arg);
28932 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28935 + AuDbg("rent %llu\n", rdu->rent);
28937 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28938 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28939 + au_fset_rdu(cookie->flags, CONT);
28940 + cookie->generation = au_figen(file);
28943 + ii_read_lock_child(inode);
28944 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28945 + ii_read_unlock(inode);
28948 + fi_read_unlock(file);
28950 + si_read_unlock(arg.sb);
28952 + inode_unlock_shared(inode);
28958 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28962 + unsigned long long nent;
28963 + union au_rdu_ent_ul *u;
28964 + struct au_rdu_ent ent;
28965 + struct super_block *sb;
28968 + nent = rdu->nent;
28970 + sb = file->f_path.dentry->d_sb;
28971 + si_read_lock(sb, AuLock_FLUSH);
28972 + while (nent-- > 0) {
28973 + /* unnecessary to support mmap_sem since this is a dir */
28974 + err = copy_from_user(&ent, u->e, sizeof(ent));
28976 + /* VERIFY_WRITE */
28977 + err = !access_ok(&u->e->ino, sizeof(ino));
28978 + if (unlikely(err)) {
28984 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28986 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28988 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28990 + if (unlikely(err)) {
28995 + err = __put_user(ino, &u->e->ino);
28996 + if (unlikely(err)) {
29001 + u->ul += au_rdu_len(ent.nlen);
29003 + si_read_unlock(sb);
29008 +/* ---------------------------------------------------------------------- */
29010 +static int au_rdu_verify(struct aufs_rdu *rdu)
29012 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29013 + "%llu, b%d, 0x%x, g%u}\n",
29014 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29016 + rdu->rent, rdu->shwh, rdu->full,
29017 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29018 + rdu->cookie.generation);
29020 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29024 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29028 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29031 + struct aufs_rdu rdu;
29032 + void __user *p = (void __user *)arg;
29034 + err = copy_from_user(&rdu, p, sizeof(rdu));
29035 + if (unlikely(err)) {
29040 + err = au_rdu_verify(&rdu);
29041 + if (unlikely(err))
29045 + case AUFS_CTL_RDU:
29046 + err = au_rdu(file, &rdu);
29047 + if (unlikely(err))
29050 + e = copy_to_user(p, &rdu, sizeof(rdu));
29051 + if (unlikely(e)) {
29056 + case AUFS_CTL_RDU_INO:
29057 + err = au_rdu_ino(file, &rdu);
29061 + /* err = -ENOTTY; */
29070 +#ifdef CONFIG_COMPAT
29071 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29074 + struct aufs_rdu rdu;
29075 + void __user *p = compat_ptr(arg);
29077 + /* todo: get_user()? */
29078 + err = copy_from_user(&rdu, p, sizeof(rdu));
29079 + if (unlikely(err)) {
29084 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29085 + err = au_rdu_verify(&rdu);
29086 + if (unlikely(err))
29090 + case AUFS_CTL_RDU:
29091 + err = au_rdu(file, &rdu);
29092 + if (unlikely(err))
29095 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29096 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29097 + e = copy_to_user(p, &rdu, sizeof(rdu));
29098 + if (unlikely(e)) {
29103 + case AUFS_CTL_RDU_INO:
29104 + err = au_rdu_ino(file, &rdu);
29108 + /* err = -ENOTTY; */
29117 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29118 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29119 +++ linux/fs/aufs/rwsem.h 2019-07-11 15:42:14.472238057 +0200
29121 +/* SPDX-License-Identifier: GPL-2.0 */
29123 + * Copyright (C) 2005-2019 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 + * simple read-write semaphore wrappers
29143 +#ifndef __AUFS_RWSEM_H__
29144 +#define __AUFS_RWSEM_H__
29148 +#include "debug.h"
29150 +/* in the future, the name 'au_rwsem' will be totally gone */
29151 +#define au_rwsem rw_semaphore
29153 +/* to debug easier, do not make them inlined functions */
29154 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29155 +/* rwsem_is_locked() is unusable */
29156 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29158 + && !lockdep_is_held_type(rw, 1))
29159 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29161 + && !lockdep_is_held_type(rw, 0))
29162 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29164 + && !lockdep_is_held(rw))
29165 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29167 + && lockdep_is_held(rw))
29169 +#define au_rw_init(rw) init_rwsem(rw)
29171 +#define au_rw_init_wlock(rw) do { \
29172 + au_rw_init(rw); \
29173 + down_write(rw); \
29176 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29177 + au_rw_init(rw); \
29178 + down_write_nested(rw, lsc); \
29181 +#define au_rw_read_lock(rw) down_read(rw)
29182 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29183 +#define au_rw_read_unlock(rw) up_read(rw)
29184 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29185 +#define au_rw_write_lock(rw) down_write(rw)
29186 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29187 +#define au_rw_write_unlock(rw) up_write(rw)
29188 +/* why is not _nested version defined? */
29189 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29190 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29192 +#endif /* __KERNEL__ */
29193 +#endif /* __AUFS_RWSEM_H__ */
29194 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29195 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29196 +++ linux/fs/aufs/sbinfo.c 2019-07-11 15:42:14.472238057 +0200
29198 +// SPDX-License-Identifier: GPL-2.0
29200 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29202 + * This program, aufs is free software; you can redistribute it and/or modify
29203 + * it under the terms of the GNU General Public License as published by
29204 + * the Free Software Foundation; either version 2 of the License, or
29205 + * (at your option) any later version.
29207 + * This program is distributed in the hope that it will be useful,
29208 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29209 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29210 + * GNU General Public License for more details.
29212 + * You should have received a copy of the GNU General Public License
29213 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29217 + * superblock private data
29220 +#include <linux/iversion.h>
29224 + * they are necessary regardless sysfs is disabled.
29226 +void au_si_free(struct kobject *kobj)
29229 + struct au_sbinfo *sbinfo;
29230 + char *locked __maybe_unused; /* debug only */
29232 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29233 + for (i = 0; i < AuPlink_NHASH; i++)
29234 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29235 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29237 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29238 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29239 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29240 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29242 + dbgaufs_si_fin(sbinfo);
29243 + au_rw_write_lock(&sbinfo->si_rwsem);
29244 + au_br_free(sbinfo);
29245 + au_rw_write_unlock(&sbinfo->si_rwsem);
29247 + au_kfree_try_rcu(sbinfo->si_branch);
29248 + mutex_destroy(&sbinfo->si_xib_mtx);
29249 + AuRwDestroy(&sbinfo->si_rwsem);
29251 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29252 + /* si_nfiles is waited too */
29253 + au_kfree_rcu(sbinfo);
29256 +int au_si_alloc(struct super_block *sb)
29259 + struct au_sbinfo *sbinfo;
29262 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29263 + if (unlikely(!sbinfo))
29266 + /* will be reallocated separately */
29267 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29268 + if (unlikely(!sbinfo->si_branch))
29271 + err = sysaufs_si_init(sbinfo);
29273 + dbgaufs_si_null(sbinfo);
29274 + err = dbgaufs_si_init(sbinfo);
29275 + if (unlikely(err))
29276 + kobject_put(&sbinfo->si_kobj);
29278 + if (unlikely(err))
29281 + au_nwt_init(&sbinfo->si_nowait);
29282 + au_rw_init_wlock(&sbinfo->si_rwsem);
29284 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29285 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29287 + sbinfo->si_bbot = -1;
29288 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29290 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29291 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29292 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29293 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29295 + au_fhsm_init(sbinfo);
29297 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29299 + sbinfo->si_xino_jiffy = jiffies;
29300 + sbinfo->si_xino_expire
29301 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29302 + mutex_init(&sbinfo->si_xib_mtx);
29303 + /* leave si_xib_last_pindex and si_xib_next_bit */
29305 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29307 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29308 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29309 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29310 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29312 + for (i = 0; i < AuPlink_NHASH; i++)
29313 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29314 + init_waitqueue_head(&sbinfo->si_plink_wq);
29315 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29317 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29319 + /* with getattr by default */
29320 + sbinfo->si_iop_array = aufs_iop;
29322 + /* leave other members for sysaufs and si_mnt. */
29323 + sbinfo->si_sb = sb;
29324 + sb->s_fs_info = sbinfo;
29326 + return 0; /* success */
29329 + au_kfree_try_rcu(sbinfo->si_branch);
29331 + au_kfree_rcu(sbinfo);
29336 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29339 + struct au_branch **brp;
29341 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29344 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29345 + if (unlikely(!sz))
29346 + sz = sizeof(*brp);
29347 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29350 + sbinfo->si_branch = brp;
29357 +/* ---------------------------------------------------------------------- */
29359 +unsigned int au_sigen_inc(struct super_block *sb)
29361 + unsigned int gen;
29362 + struct inode *inode;
29364 + SiMustWriteLock(sb);
29366 + gen = ++au_sbi(sb)->si_generation;
29367 + au_update_digen(sb->s_root);
29368 + inode = d_inode(sb->s_root);
29369 + au_update_iigen(inode, /*half*/0);
29370 + inode_inc_iversion(inode);
29374 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29376 + aufs_bindex_t br_id;
29378 + struct au_sbinfo *sbinfo;
29380 + SiMustWriteLock(sb);
29382 + sbinfo = au_sbi(sb);
29383 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29384 + br_id = ++sbinfo->si_last_br_id;
29385 + AuDebugOn(br_id < 0);
29386 + if (br_id && au_br_index(sb, br_id) < 0)
29393 +/* ---------------------------------------------------------------------- */
29395 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29396 +int si_read_lock(struct super_block *sb, int flags)
29401 + if (au_ftest_lock(flags, FLUSH))
29402 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29404 + si_noflush_read_lock(sb);
29405 + err = au_plink_maint(sb, flags);
29406 + if (unlikely(err))
29407 + si_read_unlock(sb);
29412 +int si_write_lock(struct super_block *sb, int flags)
29416 + if (au_ftest_lock(flags, FLUSH))
29417 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29419 + si_noflush_write_lock(sb);
29420 + err = au_plink_maint(sb, flags);
29421 + if (unlikely(err))
29422 + si_write_unlock(sb);
29427 +/* dentry and super_block lock. call at entry point */
29428 +int aufs_read_lock(struct dentry *dentry, int flags)
29431 + struct super_block *sb;
29433 + sb = dentry->d_sb;
29434 + err = si_read_lock(sb, flags);
29435 + if (unlikely(err))
29438 + if (au_ftest_lock(flags, DW))
29439 + di_write_lock_child(dentry);
29441 + di_read_lock_child(dentry, flags);
29443 + if (au_ftest_lock(flags, GEN)) {
29444 + err = au_digen_test(dentry, au_sigen(sb));
29445 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29446 + AuDebugOn(!err && au_dbrange_test(dentry));
29448 + err = au_dbrange_test(dentry);
29449 + if (unlikely(err))
29450 + aufs_read_unlock(dentry, flags);
29457 +void aufs_read_unlock(struct dentry *dentry, int flags)
29459 + if (au_ftest_lock(flags, DW))
29460 + di_write_unlock(dentry);
29462 + di_read_unlock(dentry, flags);
29463 + si_read_unlock(dentry->d_sb);
29466 +void aufs_write_lock(struct dentry *dentry)
29468 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29469 + di_write_lock_child(dentry);
29472 +void aufs_write_unlock(struct dentry *dentry)
29474 + di_write_unlock(dentry);
29475 + si_write_unlock(dentry->d_sb);
29478 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29481 + unsigned int sigen;
29482 + struct super_block *sb;
29485 + err = si_read_lock(sb, flags);
29486 + if (unlikely(err))
29489 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29491 + if (au_ftest_lock(flags, GEN)) {
29492 + sigen = au_sigen(sb);
29493 + err = au_digen_test(d1, sigen);
29494 + AuDebugOn(!err && au_dbrange_test(d1));
29496 + err = au_digen_test(d2, sigen);
29497 + AuDebugOn(!err && au_dbrange_test(d2));
29499 + if (unlikely(err))
29500 + aufs_read_and_write_unlock2(d1, d2);
29507 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29509 + di_write_unlock2(d1, d2);
29510 + si_read_unlock(d1->d_sb);
29512 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29513 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29514 +++ linux/fs/aufs/super.c 2019-07-11 15:42:14.472238057 +0200
29516 +// SPDX-License-Identifier: GPL-2.0
29518 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29520 + * This program, aufs is free software; you can redistribute it and/or modify
29521 + * it under the terms of the GNU General Public License as published by
29522 + * the Free Software Foundation; either version 2 of the License, or
29523 + * (at your option) any later version.
29525 + * This program is distributed in the hope that it will be useful,
29526 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29527 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29528 + * GNU General Public License for more details.
29530 + * You should have received a copy of the GNU General Public License
29531 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29535 + * mount and super_block operations
29538 +#include <linux/iversion.h>
29539 +#include <linux/mm.h>
29540 +#include <linux/seq_file.h>
29541 +#include <linux/statfs.h>
29542 +#include <linux/vmalloc.h>
29546 + * super_operations
29548 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29550 + struct au_icntnr *c;
29552 + c = au_cache_alloc_icntnr();
29554 + au_icntnr_init(c);
29555 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29556 + c->iinfo.ii_hinode = NULL;
29557 + return &c->vfs_inode;
29562 +static void aufs_destroy_inode(struct inode *inode)
29564 + if (!au_is_bad_inode(inode))
29565 + au_iinfo_fin(inode);
29568 +static void aufs_free_inode(struct inode *inode)
29570 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29573 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29575 + struct inode *inode;
29578 + inode = iget_locked(sb, ino);
29579 + if (unlikely(!inode)) {
29580 + inode = ERR_PTR(-ENOMEM);
29583 + if (!(inode->i_state & I_NEW))
29586 + err = au_xigen_new(inode);
29588 + err = au_iinfo_init(inode);
29590 + inode_inc_iversion(inode);
29592 + iget_failed(inode);
29593 + inode = ERR_PTR(err);
29597 + /* never return NULL */
29598 + AuDebugOn(!inode);
29599 + AuTraceErrPtr(inode);
29603 +/* lock free root dinfo */
29604 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29607 + aufs_bindex_t bindex, bbot;
29608 + struct path path;
29609 + struct au_hdentry *hdp;
29610 + struct au_branch *br;
29611 + au_br_perm_str_t perm;
29614 + bbot = au_sbbot(sb);
29616 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29617 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29618 + br = au_sbr(sb, bindex);
29619 + path.mnt = au_br_mnt(br);
29620 + path.dentry = hdp->hd_dentry;
29621 + err = au_seq_path(seq, &path);
29623 + au_optstr_br_perm(&perm, br->br_perm);
29624 + seq_printf(seq, "=%s", perm.a);
29625 + if (bindex != bbot)
29626 + seq_putc(seq, ':');
29629 + if (unlikely(err || seq_has_overflowed(seq)))
29635 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29636 + const char *append)
29641 + while (*pat != ':')
29644 + strcpy(p, append);
29645 + AuDebugOn(strlen(fmt) >= len);
29648 +static void au_show_wbr_create(struct seq_file *m, int v,
29649 + struct au_sbinfo *sbinfo)
29653 + struct au_wbr_mfs *mfs;
29655 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29657 + seq_puts(m, ",create=");
29658 + pat = au_optstr_wbr_create(v);
29659 + mfs = &sbinfo->si_wbr_mfs;
29661 + case AuWbrCreate_TDP:
29662 + case AuWbrCreate_RR:
29663 + case AuWbrCreate_MFS:
29664 + case AuWbrCreate_PMFS:
29665 + seq_puts(m, pat);
29667 + case AuWbrCreate_MFSRR:
29668 + case AuWbrCreate_TDMFS:
29669 + case AuWbrCreate_PMFSRR:
29670 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29671 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29673 + case AuWbrCreate_MFSV:
29674 + case AuWbrCreate_PMFSV:
29675 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29676 + seq_printf(m, fmt,
29677 + jiffies_to_msecs(mfs->mfs_expire)
29680 + case AuWbrCreate_MFSRRV:
29681 + case AuWbrCreate_TDMFSV:
29682 + case AuWbrCreate_PMFSRRV:
29683 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29684 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29685 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29692 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29694 +#ifdef CONFIG_SYSFS
29698 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29699 + aufs_bindex_t bindex, brid;
29700 + struct qstr *name;
29702 + struct dentry *d, *h_root;
29703 + struct au_branch *br;
29705 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29708 + f = au_sbi(sb)->si_xib;
29712 + /* stop printing the default xino path on the first writable branch */
29714 + bindex = au_xi_root(sb, f->f_path.dentry);
29715 + if (bindex >= 0) {
29716 + br = au_sbr_sb(sb, bindex);
29717 + h_root = au_br_dentry(br);
29720 + d = f->f_path.dentry;
29721 + name = &d->d_name;
29722 + /* safe ->d_parent because the file is unlinked */
29723 + if (d->d_parent == h_root
29724 + && name->len == len
29725 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29728 + seq_puts(seq, ",xino=");
29729 + err = au_xino_path(seq, f);
29736 +/* seq_file will re-call me in case of too long string */
29737 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29740 + unsigned int mnt_flags, v;
29741 + struct super_block *sb;
29742 + struct au_sbinfo *sbinfo;
29744 +#define AuBool(name, str) do { \
29745 + v = au_opt_test(mnt_flags, name); \
29746 + if (v != au_opt_test(AuOpt_Def, name)) \
29747 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29750 +#define AuStr(name, str) do { \
29751 + v = mnt_flags & AuOptMask_##name; \
29752 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29753 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29756 +#define AuUInt(name, str, val) do { \
29757 + if (val != AUFS_##name##_DEF) \
29758 + seq_printf(m, "," #str "=%u", val); \
29761 + sb = dentry->d_sb;
29762 + if (sb->s_flags & SB_POSIXACL)
29763 + seq_puts(m, ",acl");
29765 + if (sb->s_flags & SB_I_VERSION)
29766 + seq_puts(m, ",i_version");
29769 + /* lock free root dinfo */
29770 + si_noflush_read_lock(sb);
29771 + sbinfo = au_sbi(sb);
29772 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29774 + mnt_flags = au_mntflags(sb);
29775 + if (au_opt_test(mnt_flags, XINO)) {
29776 + err = au_show_xino(m, sb);
29777 + if (unlikely(err))
29780 + seq_puts(m, ",noxino");
29782 + AuBool(TRUNC_XINO, trunc_xino);
29783 + AuStr(UDBA, udba);
29784 + AuBool(SHWH, shwh);
29785 + AuBool(PLINK, plink);
29786 + AuBool(DIO, dio);
29787 + AuBool(DIRPERM1, dirperm1);
29789 + v = sbinfo->si_wbr_create;
29790 + if (v != AuWbrCreate_Def)
29791 + au_show_wbr_create(m, v, sbinfo);
29793 + v = sbinfo->si_wbr_copyup;
29794 + if (v != AuWbrCopyup_Def)
29795 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29797 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29798 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29799 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29801 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29803 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29804 + AuUInt(RDCACHE, rdcache, v);
29806 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29807 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29809 + au_fhsm_show(m, sbinfo);
29811 + AuBool(DIRREN, dirren);
29812 + AuBool(SUM, sum);
29813 + /* AuBool(SUM_W, wsum); */
29814 + AuBool(WARN_PERM, warn_perm);
29815 + AuBool(VERBOSE, verbose);
29818 + /* be sure to print "br:" last */
29819 + if (!sysaufs_brs) {
29820 + seq_puts(m, ",br:");
29821 + au_show_brs(m, sb);
29823 + si_read_unlock(sb);
29831 +/* ---------------------------------------------------------------------- */
29833 +/* sum mode which returns the summation for statfs(2) */
29835 +static u64 au_add_till_max(u64 a, u64 b)
29843 + return ULLONG_MAX;
29846 +static u64 au_mul_till_max(u64 a, long mul)
29854 + return ULLONG_MAX;
29857 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29860 + long bsize, factor;
29861 + u64 blocks, bfree, bavail, files, ffree;
29862 + aufs_bindex_t bbot, bindex, i;
29863 + unsigned char shared;
29864 + struct path h_path;
29865 + struct super_block *h_sb;
29868 + bsize = LONG_MAX;
29874 + bbot = au_sbbot(sb);
29875 + for (bindex = 0; bindex <= bbot; bindex++) {
29876 + h_path.mnt = au_sbr_mnt(sb, bindex);
29877 + h_sb = h_path.mnt->mnt_sb;
29879 + for (i = 0; !shared && i < bindex; i++)
29880 + shared = (au_sbr_sb(sb, i) == h_sb);
29884 + /* sb->s_root for NFS is unreliable */
29885 + h_path.dentry = h_path.mnt->mnt_root;
29886 + err = vfs_statfs(&h_path, buf);
29887 + if (unlikely(err))
29890 + if (bsize > buf->f_bsize) {
29892 + * we will reduce bsize, so we have to expand blocks
29893 + * etc. to match them again
29895 + factor = (bsize / buf->f_bsize);
29896 + blocks = au_mul_till_max(blocks, factor);
29897 + bfree = au_mul_till_max(bfree, factor);
29898 + bavail = au_mul_till_max(bavail, factor);
29899 + bsize = buf->f_bsize;
29902 + factor = (buf->f_bsize / bsize);
29903 + blocks = au_add_till_max(blocks,
29904 + au_mul_till_max(buf->f_blocks, factor));
29905 + bfree = au_add_till_max(bfree,
29906 + au_mul_till_max(buf->f_bfree, factor));
29907 + bavail = au_add_till_max(bavail,
29908 + au_mul_till_max(buf->f_bavail, factor));
29909 + files = au_add_till_max(files, buf->f_files);
29910 + ffree = au_add_till_max(ffree, buf->f_ffree);
29913 + buf->f_bsize = bsize;
29914 + buf->f_blocks = blocks;
29915 + buf->f_bfree = bfree;
29916 + buf->f_bavail = bavail;
29917 + buf->f_files = files;
29918 + buf->f_ffree = ffree;
29919 + buf->f_frsize = 0;
29925 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29928 + struct path h_path;
29929 + struct super_block *sb;
29931 + /* lock free root dinfo */
29932 + sb = dentry->d_sb;
29933 + si_noflush_read_lock(sb);
29934 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29935 + /* sb->s_root for NFS is unreliable */
29936 + h_path.mnt = au_sbr_mnt(sb, 0);
29937 + h_path.dentry = h_path.mnt->mnt_root;
29938 + err = vfs_statfs(&h_path, buf);
29940 + err = au_statfs_sum(sb, buf);
29941 + si_read_unlock(sb);
29944 + buf->f_type = AUFS_SUPER_MAGIC;
29945 + buf->f_namelen = AUFS_MAX_NAMELEN;
29946 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29948 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29953 +/* ---------------------------------------------------------------------- */
29955 +static int aufs_sync_fs(struct super_block *sb, int wait)
29958 + aufs_bindex_t bbot, bindex;
29959 + struct au_branch *br;
29960 + struct super_block *h_sb;
29963 + si_noflush_read_lock(sb);
29964 + bbot = au_sbbot(sb);
29965 + for (bindex = 0; bindex <= bbot; bindex++) {
29966 + br = au_sbr(sb, bindex);
29967 + if (!au_br_writable(br->br_perm))
29970 + h_sb = au_sbr_sb(sb, bindex);
29971 + e = vfsub_sync_filesystem(h_sb, wait);
29972 + if (unlikely(e && !err))
29974 + /* go on even if an error happens */
29976 + si_read_unlock(sb);
29981 +/* ---------------------------------------------------------------------- */
29983 +/* final actions when unmounting a file system */
29984 +static void aufs_put_super(struct super_block *sb)
29986 + struct au_sbinfo *sbinfo;
29988 + sbinfo = au_sbi(sb);
29990 + kobject_put(&sbinfo->si_kobj);
29993 +/* ---------------------------------------------------------------------- */
29995 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29996 + struct super_block *sb, void *arg)
29999 + unsigned long long n, sz;
30006 + if (*hint > ULLONG_MAX / sizeof(array)) {
30007 + array = ERR_PTR(-EMFILE);
30008 + pr_err("hint %llu\n", *hint);
30012 + sz = sizeof(array) * *hint;
30013 + array = kzalloc(sz, GFP_NOFS);
30014 + if (unlikely(!array))
30015 + array = vzalloc(sz);
30016 + if (unlikely(!array)) {
30017 + array = ERR_PTR(-ENOMEM);
30021 + n = cb(sb, array, *hint, arg);
30022 + AuDebugOn(n > *hint);
30029 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30030 + unsigned long long max __maybe_unused,
30033 + unsigned long long n;
30034 + struct inode **p, *inode;
30035 + struct list_head *head;
30040 + spin_lock(&sb->s_inode_list_lock);
30041 + list_for_each_entry(inode, head, i_sb_list) {
30042 + if (!au_is_bad_inode(inode)
30043 + && au_ii(inode)->ii_btop >= 0) {
30044 + spin_lock(&inode->i_lock);
30045 + if (atomic_read(&inode->i_count)) {
30049 + AuDebugOn(n > max);
30051 + spin_unlock(&inode->i_lock);
30054 + spin_unlock(&sb->s_inode_list_lock);
30059 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30061 + struct au_sbinfo *sbi;
30063 + sbi = au_sbi(sb);
30064 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30065 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30068 +void au_iarray_free(struct inode **a, unsigned long long max)
30070 + unsigned long long ull;
30072 + for (ull = 0; ull < max; ull++)
30077 +/* ---------------------------------------------------------------------- */
30080 + * refresh dentry and inode at remount time.
30082 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30083 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30084 + struct dentry *parent)
30088 + di_write_lock_child(dentry);
30089 + di_read_lock_parent(parent, AuLock_IR);
30090 + err = au_refresh_dentry(dentry, parent);
30091 + if (!err && dir_flags)
30092 + au_hn_reset(d_inode(dentry), dir_flags);
30093 + di_read_unlock(parent, AuLock_IR);
30094 + di_write_unlock(dentry);
30099 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30100 + struct au_sbinfo *sbinfo,
30101 + const unsigned int dir_flags, unsigned int do_idop)
30104 + struct dentry *parent;
30107 + parent = dget_parent(dentry);
30108 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30109 + if (d_really_is_positive(dentry)) {
30110 + if (!d_is_dir(dentry))
30111 + err = au_do_refresh(dentry, /*dir_flags*/0,
30114 + err = au_do_refresh(dentry, dir_flags, parent);
30115 + if (unlikely(err))
30116 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30119 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30120 + AuDbgDentry(dentry);
30126 + au_refresh_dop(dentry, /*force_reval*/0);
30128 + au_refresh_dop(dentry, /*force_reval*/1);
30134 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30136 + int err, i, j, ndentry, e;
30137 + unsigned int sigen;
30138 + struct au_dcsub_pages dpages;
30139 + struct au_dpage *dpage;
30140 + struct dentry **dentries, *d;
30141 + struct au_sbinfo *sbinfo;
30142 + struct dentry *root = sb->s_root;
30143 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30146 + au_refresh_dop(root, /*force_reval*/0);
30148 + err = au_dpages_init(&dpages, GFP_NOFS);
30149 + if (unlikely(err))
30151 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30152 + if (unlikely(err))
30155 + sigen = au_sigen(sb);
30156 + sbinfo = au_sbi(sb);
30157 + for (i = 0; i < dpages.ndpage; i++) {
30158 + dpage = dpages.dpages + i;
30159 + dentries = dpage->dentries;
30160 + ndentry = dpage->ndentry;
30161 + for (j = 0; j < ndentry; j++) {
30163 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30165 + if (unlikely(e && !err))
30167 + /* go on even err */
30172 + au_dpages_free(&dpages);
30177 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30180 + unsigned int sigen;
30181 + unsigned long long max, ull;
30182 + struct inode *inode, **array;
30184 + array = au_iarray_alloc(sb, &max);
30185 + err = PTR_ERR(array);
30186 + if (IS_ERR(array))
30190 + sigen = au_sigen(sb);
30191 + for (ull = 0; ull < max; ull++) {
30192 + inode = array[ull];
30193 + if (unlikely(!inode))
30197 + ii_write_lock_child(inode);
30198 + if (au_iigen(inode, NULL) != sigen) {
30199 + e = au_refresh_hinode_self(inode);
30200 + if (unlikely(e)) {
30201 + au_refresh_iop(inode, /*force_getattr*/1);
30202 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30205 + /* go on even if err */
30208 + if (!e && do_idop)
30209 + au_refresh_iop(inode, /*force_getattr*/0);
30210 + ii_write_unlock(inode);
30213 + au_iarray_free(array, max);
30219 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30222 + unsigned int udba;
30223 + aufs_bindex_t bindex, bbot;
30224 + struct dentry *root;
30225 + struct inode *inode;
30226 + struct au_branch *br;
30227 + struct au_sbinfo *sbi;
30229 + au_sigen_inc(sb);
30230 + sbi = au_sbi(sb);
30231 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30233 + root = sb->s_root;
30234 + DiMustNoWaiters(root);
30235 + inode = d_inode(root);
30236 + IiMustNoWaiters(inode);
30238 + udba = au_opt_udba(sb);
30239 + bbot = au_sbbot(sb);
30240 + for (bindex = 0; bindex <= bbot; bindex++) {
30241 + br = au_sbr(sb, bindex);
30242 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30243 + if (unlikely(err))
30244 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30246 + /* go on even if err */
30248 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30251 + if (au_ftest_si(sbi, NO_DREVAL)) {
30252 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30253 + sb->s_d_op = &aufs_dop_noreval;
30254 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30255 + sbi->si_iop_array = aufs_iop_nogetattr;
30257 + AuDebugOn(sb->s_d_op == &aufs_dop);
30258 + sb->s_d_op = &aufs_dop;
30259 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30260 + sbi->si_iop_array = aufs_iop;
30262 + pr_info("reset to %ps and %ps\n",
30263 + sb->s_d_op, sbi->si_iop_array);
30266 + di_write_unlock(root);
30267 + err = au_refresh_d(sb, do_idop);
30268 + e = au_refresh_i(sb, do_idop);
30269 + if (unlikely(e && !err))
30271 + /* aufs_write_lock() calls ..._child() */
30272 + di_write_lock_child(root);
30274 + au_cpup_attr_all(inode, /*force*/1);
30276 + if (unlikely(err))
30277 + AuIOErr("refresh failed, ignored, %d\n", err);
30280 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30281 +static int cvt_err(int err)
30295 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30298 + unsigned int mntflags;
30299 + struct au_opts opts = {
30302 + struct dentry *root;
30303 + struct inode *inode;
30304 + struct au_sbinfo *sbinfo;
30307 + root = sb->s_root;
30308 + if (!data || !*data) {
30309 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30311 + di_write_lock_child(root);
30312 + err = au_opts_verify(sb, *flags, /*pending*/0);
30313 + aufs_write_unlock(root);
30319 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30320 + if (unlikely(!opts.opt))
30322 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30323 + opts.flags = AuOpts_REMOUNT;
30324 + opts.sb_flags = *flags;
30326 + /* parse it before aufs lock */
30327 + err = au_opts_parse(sb, data, &opts);
30328 + if (unlikely(err))
30331 + sbinfo = au_sbi(sb);
30332 + inode = d_inode(root);
30333 + inode_lock(inode);
30334 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30335 + if (unlikely(err))
30337 + di_write_lock_child(root);
30339 + /* au_opts_remount() may return an error */
30340 + err = au_opts_remount(sb, &opts);
30341 + au_opts_free(&opts);
30343 + if (au_ftest_opts(opts.flags, REFRESH))
30344 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30346 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30347 + mntflags = au_mntflags(sb);
30348 + do_dx = !!au_opt_test(mntflags, DIO);
30349 + au_dy_arefresh(do_dx);
30352 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30353 + aufs_write_unlock(root);
30356 + inode_unlock(inode);
30358 + free_page((unsigned long)opts.opt);
30360 + err = cvt_err(err);
30365 +static const struct super_operations aufs_sop = {
30366 + .alloc_inode = aufs_alloc_inode,
30367 + .destroy_inode = aufs_destroy_inode,
30368 + .free_inode = aufs_free_inode,
30369 + /* always deleting, no clearing */
30370 + .drop_inode = generic_delete_inode,
30371 + .show_options = aufs_show_options,
30372 + .statfs = aufs_statfs,
30373 + .put_super = aufs_put_super,
30374 + .sync_fs = aufs_sync_fs,
30375 + .remount_fs = aufs_remount_fs
30378 +/* ---------------------------------------------------------------------- */
30380 +static int alloc_root(struct super_block *sb)
30383 + struct inode *inode;
30384 + struct dentry *root;
30387 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30388 + err = PTR_ERR(inode);
30389 + if (IS_ERR(inode))
30392 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30393 + inode->i_fop = &aufs_dir_fop;
30394 + inode->i_mode = S_IFDIR;
30395 + set_nlink(inode, 2);
30396 + unlock_new_inode(inode);
30398 + root = d_make_root(inode);
30399 + if (unlikely(!root))
30401 + err = PTR_ERR(root);
30402 + if (IS_ERR(root))
30405 + err = au_di_init(root);
30407 + sb->s_root = root;
30408 + return 0; /* success */
30416 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30417 + int silent __maybe_unused)
30420 + struct au_opts opts = {
30423 + struct au_sbinfo *sbinfo;
30424 + struct dentry *root;
30425 + struct inode *inode;
30426 + char *arg = raw_data;
30428 + if (unlikely(!arg || !*arg)) {
30430 + pr_err("no arg\n");
30435 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30436 + if (unlikely(!opts.opt))
30438 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30439 + opts.sb_flags = sb->s_flags;
30441 + err = au_si_alloc(sb);
30442 + if (unlikely(err))
30444 + sbinfo = au_sbi(sb);
30446 + /* all timestamps always follow the ones on the branch */
30447 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30448 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30449 + sb->s_op = &aufs_sop;
30450 + sb->s_d_op = &aufs_dop;
30451 + sb->s_magic = AUFS_SUPER_MAGIC;
30452 + sb->s_maxbytes = 0;
30453 + sb->s_stack_depth = 1;
30454 + au_export_init(sb);
30455 + au_xattr_init(sb);
30457 + err = alloc_root(sb);
30458 + if (unlikely(err)) {
30459 + si_write_unlock(sb);
30462 + root = sb->s_root;
30463 + inode = d_inode(root);
30466 + * actually we can parse options regardless aufs lock here.
30467 + * but at remount time, parsing must be done before aufs lock.
30468 + * so we follow the same rule.
30470 + ii_write_lock_parent(inode);
30471 + aufs_write_unlock(root);
30472 + err = au_opts_parse(sb, arg, &opts);
30473 + if (unlikely(err))
30476 + /* lock vfs_inode first, then aufs. */
30477 + inode_lock(inode);
30478 + aufs_write_lock(root);
30479 + err = au_opts_mount(sb, &opts);
30480 + au_opts_free(&opts);
30481 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30482 + sb->s_d_op = &aufs_dop_noreval;
30483 + pr_info("%ps\n", sb->s_d_op);
30484 + au_refresh_dop(root, /*force_reval*/0);
30485 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30486 + au_refresh_iop(inode, /*force_getattr*/0);
30488 + aufs_write_unlock(root);
30489 + inode_unlock(inode);
30491 + goto out_opts; /* success */
30495 + sb->s_root = NULL;
30497 + kobject_put(&sbinfo->si_kobj);
30498 + sb->s_fs_info = NULL;
30500 + free_page((unsigned long)opts.opt);
30503 + err = cvt_err(err);
30508 +/* ---------------------------------------------------------------------- */
30510 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30511 + const char *dev_name __maybe_unused,
30514 + struct dentry *root;
30516 + /* all timestamps always follow the ones on the branch */
30517 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30518 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30519 + if (IS_ERR(root))
30522 + au_sbilist_add(root->d_sb);
30528 +static void aufs_kill_sb(struct super_block *sb)
30530 + struct au_sbinfo *sbinfo;
30532 + sbinfo = au_sbi(sb);
30534 + au_sbilist_del(sb);
30535 + aufs_write_lock(sb->s_root);
30537 + if (sbinfo->si_wbr_create_ops->fin)
30538 + sbinfo->si_wbr_create_ops->fin(sb);
30539 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30540 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30541 + au_remount_refresh(sb, /*do_idop*/0);
30543 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30544 + au_plink_put(sb, /*verbose*/1);
30546 + au_dr_opt_flush(sb);
30547 + sbinfo->si_sb = NULL;
30548 + aufs_write_unlock(sb->s_root);
30549 + au_nwt_flush(&sbinfo->si_nowait);
30551 + kill_anon_super(sb);
30554 +struct file_system_type aufs_fs_type = {
30555 + .name = AUFS_FSTYPE,
30556 + /* a race between rename and others */
30557 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30558 + .mount = aufs_mount,
30559 + .kill_sb = aufs_kill_sb,
30560 + /* no need to __module_get() and module_put(). */
30561 + .owner = THIS_MODULE,
30563 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30564 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30565 +++ linux/fs/aufs/super.h 2019-07-11 15:42:14.472238057 +0200
30567 +/* SPDX-License-Identifier: GPL-2.0 */
30569 + * Copyright (C) 2005-2019 Junjiro R. Okajima
30571 + * This program, aufs is free software; you can redistribute it and/or modify
30572 + * it under the terms of the GNU General Public License as published by
30573 + * the Free Software Foundation; either version 2 of the License, or
30574 + * (at your option) any later version.
30576 + * This program is distributed in the hope that it will be useful,
30577 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30578 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30579 + * GNU General Public License for more details.
30581 + * You should have received a copy of the GNU General Public License
30582 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30586 + * super_block operations
30589 +#ifndef __AUFS_SUPER_H__
30590 +#define __AUFS_SUPER_H__
30594 +#include <linux/fs.h>
30595 +#include <linux/kobject.h>
30598 +#include "rwsem.h"
30601 +/* policies to select one among multiple writable branches */
30602 +struct au_wbr_copyup_operations {
30603 + int (*copyup)(struct dentry *dentry);
30606 +#define AuWbr_DIR 1 /* target is a dir */
30607 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30609 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30610 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30611 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30613 +struct au_wbr_create_operations {
30614 + int (*create)(struct dentry *dentry, unsigned int flags);
30615 + int (*init)(struct super_block *sb);
30616 + int (*fin)(struct super_block *sb);
30619 +struct au_wbr_mfs {
30620 + struct mutex mfs_lock; /* protect this structure */
30621 + unsigned long mfs_jiffy;
30622 + unsigned long mfs_expire;
30623 + aufs_bindex_t mfs_bindex;
30625 + unsigned long long mfsrr_bytes;
30626 + unsigned long long mfsrr_watermark;
30629 +#define AuPlink_NHASH 100
30630 +static inline int au_plink_hash(ino_t ino)
30632 + return ino % AuPlink_NHASH;
30635 +/* File-based Hierarchical Storage Management */
30637 +#ifdef CONFIG_AUFS_FHSM
30638 + /* allow only one process who can receive the notification */
30639 + spinlock_t fhsm_spin;
30641 + wait_queue_head_t fhsm_wqh;
30642 + atomic_t fhsm_readable;
30644 + /* these are protected by si_rwsem */
30645 + unsigned long fhsm_expire;
30646 + aufs_bindex_t fhsm_bottom;
30651 +struct au_sbinfo {
30652 + /* nowait tasks in the system-wide workqueue */
30653 + struct au_nowait_tasks si_nowait;
30656 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30657 + * rwsem for au_sbinfo is necessary.
30659 + struct au_rwsem si_rwsem;
30662 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30665 + au_lcnt_t si_ninodes, si_nfiles;
30667 + /* branch management */
30668 + unsigned int si_generation;
30670 + /* see AuSi_ flags */
30671 + unsigned char au_si_status;
30673 + aufs_bindex_t si_bbot;
30675 + /* dirty trick to keep br_id plus */
30676 + unsigned int si_last_br_id :
30677 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30678 + struct au_branch **si_branch;
30680 + /* policy to select a writable branch */
30681 + unsigned char si_wbr_copyup;
30682 + unsigned char si_wbr_create;
30683 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30684 + struct au_wbr_create_operations *si_wbr_create_ops;
30686 + /* round robin */
30687 + atomic_t si_wbr_rr_next;
30689 + /* most free space */
30690 + struct au_wbr_mfs si_wbr_mfs;
30692 + /* File-based Hierarchical Storage Management */
30693 + struct au_fhsm si_fhsm;
30695 + /* mount flags */
30696 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30697 + unsigned int si_mntflags;
30699 + /* external inode number (bitmap and translation table) */
30700 + vfs_readf_t si_xread;
30701 + vfs_writef_t si_xwrite;
30702 + loff_t si_ximaxent; /* max entries in a xino */
30704 + struct file *si_xib;
30705 + struct mutex si_xib_mtx; /* protect xib members */
30706 + unsigned long *si_xib_buf;
30707 + unsigned long si_xib_last_pindex;
30708 + int si_xib_next_bit;
30710 + unsigned long si_xino_jiffy;
30711 + unsigned long si_xino_expire;
30712 + /* reserved for future use */
30713 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30715 +#ifdef CONFIG_AUFS_EXPORT
30716 + /* i_generation */
30717 + /* todo: make xigen file an array to support many inode numbers */
30718 + struct file *si_xigen;
30719 + atomic_t si_xigen_next;
30722 + /* dirty trick to support atomic_open */
30723 + struct hlist_bl_head si_aopen;
30725 + /* vdir parameters */
30726 + unsigned long si_rdcache; /* max cache time in jiffies */
30727 + unsigned int si_rdblk; /* deblk size */
30728 + unsigned int si_rdhash; /* hash size */
30731 + * If the number of whiteouts are larger than si_dirwh, leave all of
30732 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30733 + * future fsck.aufs or kernel thread will remove them later.
30734 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30736 + unsigned int si_dirwh;
30738 + /* pseudo_link list */
30739 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30740 + wait_queue_head_t si_plink_wq;
30741 + spinlock_t si_plink_maint_lock;
30742 + pid_t si_plink_maint_pid;
30745 + struct hlist_bl_head si_files;
30747 + /* with/without getattr, brother of sb->s_d_op */
30748 + struct inode_operations *si_iop_array;
30751 + * sysfs and lifetime management.
30752 + * this is not a small structure and it may be a waste of memory in case
30753 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30754 + * but using sysfs is majority.
30756 + struct kobject si_kobj;
30757 +#ifdef CONFIG_DEBUG_FS
30758 + struct dentry *si_dbgaufs;
30759 + struct dentry *si_dbgaufs_plink;
30760 + struct dentry *si_dbgaufs_xib;
30761 +#ifdef CONFIG_AUFS_EXPORT
30762 + struct dentry *si_dbgaufs_xigen;
30766 +#ifdef CONFIG_AUFS_SBILIST
30767 + struct hlist_bl_node si_list;
30770 + /* dirty, necessary for unmounting, sysfs and sysrq */
30771 + struct super_block *si_sb;
30774 +/* sbinfo status flags */
30776 + * set true when refresh_dirs() failed at remount time.
30777 + * then try refreshing dirs at access time again.
30778 + * if it is false, refreshing dirs at access time is unnecessary
30780 +#define AuSi_FAILED_REFRESH_DIR 1
30781 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30782 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30784 +#ifndef CONFIG_AUFS_FHSM
30786 +#define AuSi_FHSM 0
30789 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30790 + unsigned int flag)
30792 + AuRwMustAnyLock(&sbi->si_rwsem);
30793 + return sbi->au_si_status & flag;
30795 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30796 +#define au_fset_si(sbinfo, name) do { \
30797 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30798 + (sbinfo)->au_si_status |= AuSi_##name; \
30800 +#define au_fclr_si(sbinfo, name) do { \
30801 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30802 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30805 +/* ---------------------------------------------------------------------- */
30807 +/* policy to select one among writable branches */
30808 +#define AuWbrCopyup(sbinfo, ...) \
30809 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30810 +#define AuWbrCreate(sbinfo, ...) \
30811 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30813 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30814 +#define AuLock_DW 1 /* write-lock dentry */
30815 +#define AuLock_IR (1 << 1) /* read-lock inode */
30816 +#define AuLock_IW (1 << 2) /* write-lock inode */
30817 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30818 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30819 + /* except RENAME_EXCHANGE */
30820 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30821 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30822 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30823 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30824 +#define au_fset_lock(flags, name) \
30825 + do { (flags) |= AuLock_##name; } while (0)
30826 +#define au_fclr_lock(flags, name) \
30827 + do { (flags) &= ~AuLock_##name; } while (0)
30829 +/* ---------------------------------------------------------------------- */
30832 +extern struct file_system_type aufs_fs_type;
30833 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30834 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30835 + unsigned long long max, void *arg);
30836 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30837 + struct super_block *sb, void *arg);
30838 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30839 +void au_iarray_free(struct inode **a, unsigned long long max);
30842 +void au_si_free(struct kobject *kobj);
30843 +int au_si_alloc(struct super_block *sb);
30844 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30846 +unsigned int au_sigen_inc(struct super_block *sb);
30847 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30849 +int si_read_lock(struct super_block *sb, int flags);
30850 +int si_write_lock(struct super_block *sb, int flags);
30851 +int aufs_read_lock(struct dentry *dentry, int flags);
30852 +void aufs_read_unlock(struct dentry *dentry, int flags);
30853 +void aufs_write_lock(struct dentry *dentry);
30854 +void aufs_write_unlock(struct dentry *dentry);
30855 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30856 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30858 +/* wbr_policy.c */
30859 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30860 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30861 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30862 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30863 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30866 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30868 +#ifdef CONFIG_AUFS_FHSM
30871 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30875 + spin_lock(&fhsm->fhsm_spin);
30876 + pid = fhsm->fhsm_pid;
30877 + spin_unlock(&fhsm->fhsm_spin);
30882 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30883 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30884 +int au_fhsm_fd(struct super_block *sb, int oflags);
30885 +int au_fhsm_br_alloc(struct au_branch *br);
30886 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30887 +void au_fhsm_fin(struct super_block *sb);
30888 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30889 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30890 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30892 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30894 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30895 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30896 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30897 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30898 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30899 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30900 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30901 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30902 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30905 +/* ---------------------------------------------------------------------- */
30907 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30909 + return sb->s_fs_info;
30912 +/* ---------------------------------------------------------------------- */
30914 +#ifdef CONFIG_AUFS_EXPORT
30915 +int au_test_nfsd(void);
30916 +void au_export_init(struct super_block *sb);
30917 +void au_xigen_inc(struct inode *inode);
30918 +int au_xigen_new(struct inode *inode);
30919 +int au_xigen_set(struct super_block *sb, struct path *path);
30920 +void au_xigen_clr(struct super_block *sb);
30922 +static inline int au_busy_or_stale(void)
30924 + if (!au_test_nfsd())
30929 +AuStubInt0(au_test_nfsd, void)
30930 +AuStubVoid(au_export_init, struct super_block *sb)
30931 +AuStubVoid(au_xigen_inc, struct inode *inode)
30932 +AuStubInt0(au_xigen_new, struct inode *inode)
30933 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30934 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30935 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30936 +#endif /* CONFIG_AUFS_EXPORT */
30938 +/* ---------------------------------------------------------------------- */
30940 +#ifdef CONFIG_AUFS_SBILIST
30942 +extern struct hlist_bl_head au_sbilist;
30944 +static inline void au_sbilist_init(void)
30946 + INIT_HLIST_BL_HEAD(&au_sbilist);
30949 +static inline void au_sbilist_add(struct super_block *sb)
30951 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30954 +static inline void au_sbilist_del(struct super_block *sb)
30956 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30959 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30960 +static inline void au_sbilist_lock(void)
30962 + hlist_bl_lock(&au_sbilist);
30965 +static inline void au_sbilist_unlock(void)
30967 + hlist_bl_unlock(&au_sbilist);
30969 +#define AuGFP_SBILIST GFP_ATOMIC
30971 +AuStubVoid(au_sbilist_lock, void)
30972 +AuStubVoid(au_sbilist_unlock, void)
30973 +#define AuGFP_SBILIST GFP_NOFS
30974 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30976 +AuStubVoid(au_sbilist_init, void)
30977 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30978 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30979 +AuStubVoid(au_sbilist_lock, void)
30980 +AuStubVoid(au_sbilist_unlock, void)
30981 +#define AuGFP_SBILIST GFP_NOFS
30984 +/* ---------------------------------------------------------------------- */
30986 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30989 + * This function is a dynamic '__init' function actually,
30990 + * so the tiny check for si_rwsem is unnecessary.
30992 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30993 +#ifdef CONFIG_DEBUG_FS
30994 + sbinfo->si_dbgaufs = NULL;
30995 + sbinfo->si_dbgaufs_plink = NULL;
30996 + sbinfo->si_dbgaufs_xib = NULL;
30997 +#ifdef CONFIG_AUFS_EXPORT
30998 + sbinfo->si_dbgaufs_xigen = NULL;
31003 +/* ---------------------------------------------------------------------- */
31005 +/* current->atomic_flags */
31006 +/* this value should never corrupt the ones defined in linux/sched.h */
31007 +#define PFA_AUFS 0x10
31009 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31010 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31011 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31013 +static inline int si_pid_test(struct super_block *sb)
31015 + return !!task_test_aufs(current);
31018 +static inline void si_pid_clr(struct super_block *sb)
31020 + AuDebugOn(!task_test_aufs(current));
31021 + task_clear_aufs(current);
31024 +static inline void si_pid_set(struct super_block *sb)
31026 + AuDebugOn(task_test_aufs(current));
31027 + task_set_aufs(current);
31030 +/* ---------------------------------------------------------------------- */
31032 +/* lock superblock. mainly for entry point functions */
31033 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31034 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31035 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31036 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31038 +#define __si_read_trylock_nested(sb) \
31039 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31040 +#define __si_write_trylock_nested(sb) \
31041 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31044 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31045 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31046 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31048 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31049 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31050 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31052 +static inline void si_noflush_read_lock(struct super_block *sb)
31054 + __si_read_lock(sb);
31058 +static inline int si_noflush_read_trylock(struct super_block *sb)
31062 + locked = __si_read_trylock(sb);
31068 +static inline void si_noflush_write_lock(struct super_block *sb)
31070 + __si_write_lock(sb);
31074 +static inline int si_noflush_write_trylock(struct super_block *sb)
31078 + locked = __si_write_trylock(sb);
31084 +#if 0 /* reserved */
31085 +static inline int si_read_trylock(struct super_block *sb, int flags)
31087 + if (au_ftest_lock(flags, FLUSH))
31088 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31089 + return si_noflush_read_trylock(sb);
31093 +static inline void si_read_unlock(struct super_block *sb)
31096 + __si_read_unlock(sb);
31099 +#if 0 /* reserved */
31100 +static inline int si_write_trylock(struct super_block *sb, int flags)
31102 + if (au_ftest_lock(flags, FLUSH))
31103 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31104 + return si_noflush_write_trylock(sb);
31108 +static inline void si_write_unlock(struct super_block *sb)
31111 + __si_write_unlock(sb);
31114 +#if 0 /* reserved */
31115 +static inline void si_downgrade_lock(struct super_block *sb)
31117 + __si_downgrade_lock(sb);
31121 +/* ---------------------------------------------------------------------- */
31123 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31125 + SiMustAnyLock(sb);
31126 + return au_sbi(sb)->si_bbot;
31129 +static inline unsigned int au_mntflags(struct super_block *sb)
31131 + SiMustAnyLock(sb);
31132 + return au_sbi(sb)->si_mntflags;
31135 +static inline unsigned int au_sigen(struct super_block *sb)
31137 + SiMustAnyLock(sb);
31138 + return au_sbi(sb)->si_generation;
31141 +static inline struct au_branch *au_sbr(struct super_block *sb,
31142 + aufs_bindex_t bindex)
31144 + SiMustAnyLock(sb);
31145 + return au_sbi(sb)->si_branch[0 + bindex];
31148 +static inline loff_t au_xi_maxent(struct super_block *sb)
31150 + SiMustAnyLock(sb);
31151 + return au_sbi(sb)->si_ximaxent;
31154 +#endif /* __KERNEL__ */
31155 +#endif /* __AUFS_SUPER_H__ */
31156 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31157 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31158 +++ linux/fs/aufs/sysaufs.c 2019-07-11 15:42:14.472238057 +0200
31160 +// SPDX-License-Identifier: GPL-2.0
31162 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31164 + * This program, aufs is free software; you can redistribute it and/or modify
31165 + * it under the terms of the GNU General Public License as published by
31166 + * the Free Software Foundation; either version 2 of the License, or
31167 + * (at your option) any later version.
31169 + * This program is distributed in the hope that it will be useful,
31170 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31171 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31172 + * GNU General Public License for more details.
31174 + * You should have received a copy of the GNU General Public License
31175 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31179 + * sysfs interface and lifetime management
31180 + * they are necessary regardless sysfs is disabled.
31183 +#include <linux/random.h>
31186 +unsigned long sysaufs_si_mask;
31187 +struct kset *sysaufs_kset;
31189 +#define AuSiAttr(_name) { \
31190 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31191 + .show = sysaufs_si_##_name, \
31194 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31195 +struct attribute *sysaufs_si_attrs[] = {
31196 + &sysaufs_si_attr_xi_path.attr,
31200 +static const struct sysfs_ops au_sbi_ops = {
31201 + .show = sysaufs_si_show
31204 +static struct kobj_type au_sbi_ktype = {
31205 + .release = au_si_free,
31206 + .sysfs_ops = &au_sbi_ops,
31207 + .default_attrs = sysaufs_si_attrs
31210 +/* ---------------------------------------------------------------------- */
31212 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31216 + sbinfo->si_kobj.kset = sysaufs_kset;
31217 + /* cf. sysaufs_name() */
31218 + err = kobject_init_and_add
31219 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31220 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31225 +void sysaufs_fin(void)
31227 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31228 + kset_unregister(sysaufs_kset);
31231 +int __init sysaufs_init(void)
31236 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31237 + } while (!sysaufs_si_mask);
31240 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31241 + if (unlikely(!sysaufs_kset))
31243 + err = PTR_ERR(sysaufs_kset);
31244 + if (IS_ERR(sysaufs_kset))
31246 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31247 + if (unlikely(err))
31248 + kset_unregister(sysaufs_kset);
31253 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31254 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31255 +++ linux/fs/aufs/sysaufs.h 2019-07-11 15:42:14.475571481 +0200
31257 +/* SPDX-License-Identifier: GPL-2.0 */
31259 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31261 + * This program, aufs is free software; you can redistribute it and/or modify
31262 + * it under the terms of the GNU General Public License as published by
31263 + * the Free Software Foundation; either version 2 of the License, or
31264 + * (at your option) any later version.
31266 + * This program is distributed in the hope that it will be useful,
31267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31269 + * GNU General Public License for more details.
31271 + * You should have received a copy of the GNU General Public License
31272 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31276 + * sysfs interface and mount lifetime management
31279 +#ifndef __SYSAUFS_H__
31280 +#define __SYSAUFS_H__
31284 +#include <linux/sysfs.h>
31285 +#include "module.h"
31287 +struct super_block;
31290 +struct sysaufs_si_attr {
31291 + struct attribute attr;
31292 + int (*show)(struct seq_file *seq, struct super_block *sb);
31295 +/* ---------------------------------------------------------------------- */
31298 +extern unsigned long sysaufs_si_mask;
31299 +extern struct kset *sysaufs_kset;
31300 +extern struct attribute *sysaufs_si_attrs[];
31301 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31302 +int __init sysaufs_init(void);
31303 +void sysaufs_fin(void);
31305 +/* ---------------------------------------------------------------------- */
31307 +/* some people doesn't like to show a pointer in kernel */
31308 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31310 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31313 +#define SysaufsSiNamePrefix "si_"
31314 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31315 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31317 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31318 + sysaufs_si_id(sbinfo));
31322 +#ifdef CONFIG_SYSFS
31324 +extern struct attribute_group *sysaufs_attr_group;
31326 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31327 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31329 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31330 +#ifdef CONFIG_COMPAT
31331 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31334 +void sysaufs_br_init(struct au_branch *br);
31335 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31336 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31338 +#define sysaufs_brs_init() do {} while (0)
31341 +#define sysaufs_attr_group NULL
31343 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31344 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31345 + struct attribute *attr, char *buf)
31346 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31347 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31348 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31350 +static inline void sysaufs_brs_init(void)
31355 +#endif /* CONFIG_SYSFS */
31357 +#endif /* __KERNEL__ */
31358 +#endif /* __SYSAUFS_H__ */
31359 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31360 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31361 +++ linux/fs/aufs/sysfs.c 2019-07-11 15:42:14.475571481 +0200
31363 +// SPDX-License-Identifier: GPL-2.0
31365 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31367 + * This program, aufs is free software; you can redistribute it and/or modify
31368 + * it under the terms of the GNU General Public License as published by
31369 + * the Free Software Foundation; either version 2 of the License, or
31370 + * (at your option) any later version.
31372 + * This program is distributed in the hope that it will be useful,
31373 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31374 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31375 + * GNU General Public License for more details.
31377 + * You should have received a copy of the GNU General Public License
31378 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31382 + * sysfs interface
31385 +#include <linux/compat.h>
31386 +#include <linux/seq_file.h>
31389 +#ifdef CONFIG_AUFS_FS_MODULE
31390 +/* this entry violates the "one line per file" policy of sysfs */
31391 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31395 + static char *conf =
31396 +/* this file is generated at compiling */
31397 +#include "conf.str"
31400 + err = snprintf(buf, PAGE_SIZE, conf);
31401 + if (unlikely(err >= PAGE_SIZE))
31406 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31409 +static struct attribute *au_attr[] = {
31410 +#ifdef CONFIG_AUFS_FS_MODULE
31411 + &au_config_attr.attr,
31413 + NULL, /* need to NULL terminate the list of attributes */
31416 +static struct attribute_group sysaufs_attr_group_body = {
31420 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31422 +/* ---------------------------------------------------------------------- */
31424 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31428 + SiMustAnyLock(sb);
31431 + if (au_opt_test(au_mntflags(sb), XINO)) {
31432 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31433 + seq_putc(seq, '\n');
31439 + * the lifetime of branch is independent from the entry under sysfs.
31440 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31443 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31444 + aufs_bindex_t bindex, int idx)
31447 + struct path path;
31448 + struct dentry *root;
31449 + struct au_branch *br;
31450 + au_br_perm_str_t perm;
31452 + AuDbg("b%d\n", bindex);
31455 + root = sb->s_root;
31456 + di_read_lock_parent(root, !AuLock_IR);
31457 + br = au_sbr(sb, bindex);
31460 + case AuBrSysfs_BR:
31461 + path.mnt = au_br_mnt(br);
31462 + path.dentry = au_h_dptr(root, bindex);
31463 + err = au_seq_path(seq, &path);
31465 + au_optstr_br_perm(&perm, br->br_perm);
31466 + seq_printf(seq, "=%s\n", perm.a);
31469 + case AuBrSysfs_BRID:
31470 + seq_printf(seq, "%d\n", br->br_id);
31473 + di_read_unlock(root, !AuLock_IR);
31474 + if (unlikely(err || seq_has_overflowed(seq)))
31480 +/* ---------------------------------------------------------------------- */
31482 +static struct seq_file *au_seq(char *p, ssize_t len)
31484 + struct seq_file *seq;
31486 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31488 + /* mutex_init(&seq.lock); */
31491 + return seq; /* success */
31494 + seq = ERR_PTR(-ENOMEM);
31498 +#define SysaufsBr_PREFIX "br"
31499 +#define SysaufsBrid_PREFIX "brid"
31501 +/* todo: file size may exceed PAGE_SIZE */
31502 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31508 + aufs_bindex_t bbot;
31509 + struct au_sbinfo *sbinfo;
31510 + struct super_block *sb;
31511 + struct seq_file *seq;
31513 + struct attribute **cattr;
31515 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31516 + sb = sbinfo->si_sb;
31519 + * prevent a race condition between sysfs and aufs.
31520 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31521 + * prohibits maintaining the sysfs entries.
31522 + * hew we acquire read lock after sysfs_get_active_two().
31523 + * on the other hand, the remount process may maintain the sysfs/aufs
31524 + * entries after acquiring write lock.
31525 + * it can cause a deadlock.
31526 + * simply we gave up processing read here.
31529 + if (unlikely(!si_noflush_read_trylock(sb)))
31532 + seq = au_seq(buf, PAGE_SIZE);
31533 + err = PTR_ERR(seq);
31537 + name = (void *)attr->name;
31538 + cattr = sysaufs_si_attrs;
31540 + if (!strcmp(name, (*cattr)->name)) {
31541 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31548 + if (!strncmp(name, SysaufsBrid_PREFIX,
31549 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31550 + idx = AuBrSysfs_BRID;
31551 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31552 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31553 + sizeof(SysaufsBr_PREFIX) - 1)) {
31554 + idx = AuBrSysfs_BR;
31555 + name += sizeof(SysaufsBr_PREFIX) - 1;
31559 + err = kstrtol(name, 10, &l);
31561 + bbot = au_sbbot(sb);
31563 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31570 + err = seq->count;
31571 + /* sysfs limit */
31572 + if (unlikely(err == PAGE_SIZE))
31575 + au_kfree_rcu(seq);
31577 + si_read_unlock(sb);
31582 +/* ---------------------------------------------------------------------- */
31584 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31588 + aufs_bindex_t bindex, bbot;
31591 + struct seq_file *seq;
31592 + struct au_branch *br;
31594 + si_read_lock(sb, AuLock_FLUSH);
31595 + bbot = au_sbbot(sb);
31601 + buf = (void *)__get_free_page(GFP_NOFS);
31602 + if (unlikely(!buf))
31605 + seq = au_seq(buf, PAGE_SIZE);
31606 + err = PTR_ERR(seq);
31610 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31611 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31612 + /* VERIFY_WRITE */
31613 + err = !access_ok(arg, sizeof(*arg));
31614 + if (unlikely(err))
31617 + br = au_sbr(sb, bindex);
31618 + brid = br->br_id;
31619 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31620 + err = __put_user(brid, &arg->id);
31621 + if (unlikely(err))
31624 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31625 + err = __put_user(br->br_perm, &arg->perm);
31626 + if (unlikely(err))
31629 + err = au_seq_path(seq, &br->br_path);
31630 + if (unlikely(err))
31632 + seq_putc(seq, '\0');
31633 + if (!seq_has_overflowed(seq)) {
31634 + err = copy_to_user(arg->path, seq->buf, seq->count);
31636 + if (unlikely(err))
31643 + if (unlikely(err))
31647 + au_kfree_rcu(seq);
31649 + free_page((unsigned long)buf);
31651 + si_read_unlock(sb);
31655 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31657 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31660 +#ifdef CONFIG_COMPAT
31661 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31663 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31667 +/* ---------------------------------------------------------------------- */
31669 +void sysaufs_br_init(struct au_branch *br)
31672 + struct au_brsysfs *br_sysfs;
31673 + struct attribute *attr;
31675 + br_sysfs = br->br_sysfs;
31676 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31677 + attr = &br_sysfs->attr;
31678 + sysfs_attr_init(attr);
31679 + attr->name = br_sysfs->name;
31680 + attr->mode = 0444;
31685 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31687 + struct au_branch *br;
31688 + struct kobject *kobj;
31689 + struct au_brsysfs *br_sysfs;
31691 + aufs_bindex_t bbot;
31693 + if (!sysaufs_brs)
31696 + kobj = &au_sbi(sb)->si_kobj;
31697 + bbot = au_sbbot(sb);
31698 + for (; bindex <= bbot; bindex++) {
31699 + br = au_sbr(sb, bindex);
31700 + br_sysfs = br->br_sysfs;
31701 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31702 + sysfs_remove_file(kobj, &br_sysfs->attr);
31708 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31711 + aufs_bindex_t bbot;
31712 + struct kobject *kobj;
31713 + struct au_branch *br;
31714 + struct au_brsysfs *br_sysfs;
31716 + if (!sysaufs_brs)
31719 + kobj = &au_sbi(sb)->si_kobj;
31720 + bbot = au_sbbot(sb);
31721 + for (; bindex <= bbot; bindex++) {
31722 + br = au_sbr(sb, bindex);
31723 + br_sysfs = br->br_sysfs;
31724 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31725 + SysaufsBr_PREFIX "%d", bindex);
31726 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31727 + SysaufsBrid_PREFIX "%d", bindex);
31728 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31729 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31730 + if (unlikely(err))
31731 + pr_warn("failed %s under sysfs(%d)\n",
31732 + br_sysfs->name, err);
31737 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31738 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31739 +++ linux/fs/aufs/sysrq.c 2019-07-11 15:42:14.475571481 +0200
31741 +// SPDX-License-Identifier: GPL-2.0
31743 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31745 + * This program, aufs is free software; you can redistribute it and/or modify
31746 + * it under the terms of the GNU General Public License as published by
31747 + * the Free Software Foundation; either version 2 of the License, or
31748 + * (at your option) any later version.
31750 + * This program is distributed in the hope that it will be useful,
31751 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31752 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31753 + * GNU General Public License for more details.
31755 + * You should have received a copy of the GNU General Public License
31756 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31760 + * magic sysrq handler
31763 +/* #include <linux/sysrq.h> */
31764 +#include <linux/writeback.h>
31767 +/* ---------------------------------------------------------------------- */
31769 +static void sysrq_sb(struct super_block *sb)
31772 + struct au_sbinfo *sbinfo;
31773 + struct file *file;
31774 + struct hlist_bl_head *files;
31775 + struct hlist_bl_node *pos;
31776 + struct au_finfo *finfo;
31778 + plevel = au_plevel;
31779 + au_plevel = KERN_WARNING;
31781 + /* since we define pr_fmt, call printk directly */
31782 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31784 + sbinfo = au_sbi(sb);
31785 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31786 + pr("superblock\n");
31790 + pr("root dentry\n");
31791 + au_dpri_dentry(sb->s_root);
31792 + pr("root inode\n");
31793 + au_dpri_inode(d_inode(sb->s_root));
31798 + int err, i, j, ndentry;
31799 + struct au_dcsub_pages dpages;
31800 + struct au_dpage *dpage;
31802 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31803 + if (unlikely(err))
31805 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31807 + for (i = 0; i < dpages.ndpage; i++) {
31808 + dpage = dpages.dpages + i;
31809 + ndentry = dpage->ndentry;
31810 + for (j = 0; j < ndentry; j++)
31811 + au_dpri_dentry(dpage->dentries[j]);
31813 + au_dpages_free(&dpages);
31821 + pr("isolated inode\n");
31822 + spin_lock(&sb->s_inode_list_lock);
31823 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31824 + spin_lock(&i->i_lock);
31825 + if (1 || hlist_empty(&i->i_dentry))
31826 + au_dpri_inode(i);
31827 + spin_unlock(&i->i_lock);
31829 + spin_unlock(&sb->s_inode_list_lock);
31833 + files = &au_sbi(sb)->si_files;
31834 + hlist_bl_lock(files);
31835 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31838 + file = finfo->fi_file;
31839 + mode = file_inode(file)->i_mode;
31840 + if (!special_file(mode))
31841 + au_dpri_file(file);
31843 + hlist_bl_unlock(files);
31847 + au_plevel = plevel;
31850 +/* ---------------------------------------------------------------------- */
31852 +/* module parameter */
31853 +static char *aufs_sysrq_key = "a";
31854 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31855 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31857 +static void au_sysrq(int key __maybe_unused)
31859 + struct au_sbinfo *sbinfo;
31860 + struct hlist_bl_node *pos;
31863 + au_sbilist_lock();
31864 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31865 + sysrq_sb(sbinfo->si_sb);
31866 + au_sbilist_unlock();
31870 +static struct sysrq_key_op au_sysrq_op = {
31871 + .handler = au_sysrq,
31872 + .help_msg = "Aufs",
31873 + .action_msg = "Aufs",
31874 + .enable_mask = SYSRQ_ENABLE_DUMP
31877 +/* ---------------------------------------------------------------------- */
31879 +int __init au_sysrq_init(void)
31885 + key = *aufs_sysrq_key;
31886 + if ('a' <= key && key <= 'z')
31887 + err = register_sysrq_key(key, &au_sysrq_op);
31888 + if (unlikely(err))
31889 + pr_err("err %d, sysrq=%c\n", err, key);
31893 +void au_sysrq_fin(void)
31897 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31898 + if (unlikely(err))
31899 + pr_err("err %d (ignored)\n", err);
31901 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31902 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31903 +++ linux/fs/aufs/vdir.c 2019-07-11 15:42:14.475571481 +0200
31905 +// SPDX-License-Identifier: GPL-2.0
31907 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31909 + * This program, aufs is free software; you can redistribute it and/or modify
31910 + * it under the terms of the GNU General Public License as published by
31911 + * the Free Software Foundation; either version 2 of the License, or
31912 + * (at your option) any later version.
31914 + * This program is distributed in the hope that it will be useful,
31915 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31916 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31917 + * GNU General Public License for more details.
31919 + * You should have received a copy of the GNU General Public License
31920 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31924 + * virtual or vertical directory
31927 +#include <linux/iversion.h>
31930 +static unsigned int calc_size(int nlen)
31932 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31935 +static int set_deblk_end(union au_vdir_deblk_p *p,
31936 + union au_vdir_deblk_p *deblk_end)
31938 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31939 + p->de->de_str.len = 0;
31943 + return -1; /* error */
31946 +/* returns true or false */
31947 +static int is_deblk_end(union au_vdir_deblk_p *p,
31948 + union au_vdir_deblk_p *deblk_end)
31950 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31951 + return !p->de->de_str.len;
31955 +static unsigned char *last_deblk(struct au_vdir *vdir)
31957 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31960 +/* ---------------------------------------------------------------------- */
31962 +/* estimate the appropriate size for name hash table */
31963 +unsigned int au_rdhash_est(loff_t sz)
31971 + if (sz < AUFS_RDHASH_DEF)
31972 + n = AUFS_RDHASH_DEF;
31973 + /* pr_info("n %u\n", n); */
31978 + * the allocated memory has to be freed by
31979 + * au_nhash_wh_free() or au_nhash_de_free().
31981 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31983 + struct hlist_head *head;
31987 + sz = sizeof(*nhash->nh_head) * num_hash;
31988 + head = kmalloc(sz, gfp);
31990 + nhash->nh_num = num_hash;
31991 + nhash->nh_head = head;
31992 + for (u = 0; u < num_hash; u++)
31993 + INIT_HLIST_HEAD(head++);
31994 + return 0; /* success */
32000 +static void nhash_count(struct hlist_head *head)
32004 + struct hlist_node *pos;
32007 + hlist_for_each(pos, head)
32009 + pr_info("%lu\n", n);
32013 +static void au_nhash_wh_do_free(struct hlist_head *head)
32015 + struct au_vdir_wh *pos;
32016 + struct hlist_node *node;
32018 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32019 + au_kfree_rcu(pos);
32022 +static void au_nhash_de_do_free(struct hlist_head *head)
32024 + struct au_vdir_dehstr *pos;
32025 + struct hlist_node *node;
32027 + hlist_for_each_entry_safe(pos, node, head, hash)
32028 + au_cache_free_vdir_dehstr(pos);
32031 +static void au_nhash_do_free(struct au_nhash *nhash,
32032 + void (*free)(struct hlist_head *head))
32035 + struct hlist_head *head;
32037 + n = nhash->nh_num;
32041 + head = nhash->nh_head;
32042 + while (n-- > 0) {
32043 + nhash_count(head);
32046 + au_kfree_try_rcu(nhash->nh_head);
32049 +void au_nhash_wh_free(struct au_nhash *whlist)
32051 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32054 +static void au_nhash_de_free(struct au_nhash *delist)
32056 + au_nhash_do_free(delist, au_nhash_de_do_free);
32059 +/* ---------------------------------------------------------------------- */
32061 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32065 + unsigned int u, n;
32066 + struct hlist_head *head;
32067 + struct au_vdir_wh *pos;
32070 + n = whlist->nh_num;
32071 + head = whlist->nh_head;
32072 + for (u = 0; u < n; u++, head++)
32073 + hlist_for_each_entry(pos, head, wh_hash)
32074 + if (pos->wh_bindex == btgt && ++num > limit)
32079 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32080 + unsigned char *name,
32081 + unsigned int len)
32084 + /* const unsigned int magic_bit = 12; */
32086 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32093 + /* v = hash_long(v, magic_bit); */
32094 + v %= nhash->nh_num;
32095 + return nhash->nh_head + v;
32098 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32101 + return str->len == nlen && !memcmp(str->name, name, nlen);
32104 +/* returns found or not */
32105 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32107 + struct hlist_head *head;
32108 + struct au_vdir_wh *pos;
32109 + struct au_vdir_destr *str;
32111 + head = au_name_hash(whlist, name, nlen);
32112 + hlist_for_each_entry(pos, head, wh_hash) {
32113 + str = &pos->wh_str;
32114 + AuDbg("%.*s\n", str->len, str->name);
32115 + if (au_nhash_test_name(str, name, nlen))
32121 +/* returns found(true) or not */
32122 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32124 + struct hlist_head *head;
32125 + struct au_vdir_dehstr *pos;
32126 + struct au_vdir_destr *str;
32128 + head = au_name_hash(delist, name, nlen);
32129 + hlist_for_each_entry(pos, head, hash) {
32131 + AuDbg("%.*s\n", str->len, str->name);
32132 + if (au_nhash_test_name(str, name, nlen))
32138 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32139 + unsigned char d_type)
32141 +#ifdef CONFIG_AUFS_SHWH
32142 + wh->wh_ino = ino;
32143 + wh->wh_type = d_type;
32147 +/* ---------------------------------------------------------------------- */
32149 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32150 + unsigned int d_type, aufs_bindex_t bindex,
32151 + unsigned char shwh)
32154 + struct au_vdir_destr *str;
32155 + struct au_vdir_wh *wh;
32157 + AuDbg("%.*s\n", nlen, name);
32158 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32161 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32162 + if (unlikely(!wh))
32166 + wh->wh_bindex = bindex;
32168 + au_shwh_init_wh(wh, ino, d_type);
32169 + str = &wh->wh_str;
32171 + memcpy(str->name, name, nlen);
32172 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32179 +static int append_deblk(struct au_vdir *vdir)
32182 + unsigned long ul;
32183 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32184 + union au_vdir_deblk_p p, deblk_end;
32185 + unsigned char **o;
32188 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32189 + GFP_NOFS, /*may_shrink*/0);
32190 + if (unlikely(!o))
32193 + vdir->vd_deblk = o;
32194 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32196 + ul = vdir->vd_nblk++;
32197 + vdir->vd_deblk[ul] = p.deblk;
32198 + vdir->vd_last.ul = ul;
32199 + vdir->vd_last.p.deblk = p.deblk;
32200 + deblk_end.deblk = p.deblk + deblk_sz;
32201 + err = set_deblk_end(&p, &deblk_end);
32208 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32209 + unsigned int d_type, struct au_nhash *delist)
32213 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32214 + union au_vdir_deblk_p p, *room, deblk_end;
32215 + struct au_vdir_dehstr *dehstr;
32217 + p.deblk = last_deblk(vdir);
32218 + deblk_end.deblk = p.deblk + deblk_sz;
32219 + room = &vdir->vd_last.p;
32220 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32221 + || !is_deblk_end(room, &deblk_end));
32223 + sz = calc_size(nlen);
32224 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32225 + err = append_deblk(vdir);
32226 + if (unlikely(err))
32229 + p.deblk = last_deblk(vdir);
32230 + deblk_end.deblk = p.deblk + deblk_sz;
32232 + AuDebugOn(room->deblk != p.deblk);
32236 + dehstr = au_cache_alloc_vdir_dehstr();
32237 + if (unlikely(!dehstr))
32240 + dehstr->str = &room->de->de_str;
32241 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32242 + room->de->de_ino = ino;
32243 + room->de->de_type = d_type;
32244 + room->de->de_str.len = nlen;
32245 + memcpy(room->de->de_str.name, name, nlen);
32248 + room->deblk += sz;
32249 + if (unlikely(set_deblk_end(room, &deblk_end)))
32250 + err = append_deblk(vdir);
32257 +/* ---------------------------------------------------------------------- */
32259 +void au_vdir_free(struct au_vdir *vdir)
32261 + unsigned char **deblk;
32263 + deblk = vdir->vd_deblk;
32264 + while (vdir->vd_nblk--)
32265 + au_kfree_try_rcu(*deblk++);
32266 + au_kfree_try_rcu(vdir->vd_deblk);
32267 + au_cache_free_vdir(vdir);
32270 +static struct au_vdir *alloc_vdir(struct file *file)
32272 + struct au_vdir *vdir;
32273 + struct super_block *sb;
32276 + sb = file->f_path.dentry->d_sb;
32277 + SiMustAnyLock(sb);
32280 + vdir = au_cache_alloc_vdir();
32281 + if (unlikely(!vdir))
32284 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32285 + if (unlikely(!vdir->vd_deblk))
32288 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32289 + if (!vdir->vd_deblk_sz) {
32290 + /* estimate the appropriate size for deblk */
32291 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32292 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32294 + vdir->vd_nblk = 0;
32295 + vdir->vd_version = 0;
32296 + vdir->vd_jiffy = 0;
32297 + err = append_deblk(vdir);
32299 + return vdir; /* success */
32301 + au_kfree_try_rcu(vdir->vd_deblk);
32304 + au_cache_free_vdir(vdir);
32306 + vdir = ERR_PTR(err);
32310 +static int reinit_vdir(struct au_vdir *vdir)
32313 + union au_vdir_deblk_p p, deblk_end;
32315 + while (vdir->vd_nblk > 1) {
32316 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32317 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32320 + p.deblk = vdir->vd_deblk[0];
32321 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32322 + err = set_deblk_end(&p, &deblk_end);
32323 + /* keep vd_dblk_sz */
32324 + vdir->vd_last.ul = 0;
32325 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32326 + vdir->vd_version = 0;
32327 + vdir->vd_jiffy = 0;
32332 +/* ---------------------------------------------------------------------- */
32334 +#define AuFillVdir_CALLED 1
32335 +#define AuFillVdir_WHABLE (1 << 1)
32336 +#define AuFillVdir_SHWH (1 << 2)
32337 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32338 +#define au_fset_fillvdir(flags, name) \
32339 + do { (flags) |= AuFillVdir_##name; } while (0)
32340 +#define au_fclr_fillvdir(flags, name) \
32341 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32343 +#ifndef CONFIG_AUFS_SHWH
32344 +#undef AuFillVdir_SHWH
32345 +#define AuFillVdir_SHWH 0
32348 +struct fillvdir_arg {
32349 + struct dir_context ctx;
32350 + struct file *file;
32351 + struct au_vdir *vdir;
32352 + struct au_nhash delist;
32353 + struct au_nhash whlist;
32354 + aufs_bindex_t bindex;
32355 + unsigned int flags;
32359 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32360 + loff_t offset __maybe_unused, u64 h_ino,
32361 + unsigned int d_type)
32363 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32364 + char *name = (void *)__name;
32365 + struct super_block *sb;
32367 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32370 + sb = arg->file->f_path.dentry->d_sb;
32371 + au_fset_fillvdir(arg->flags, CALLED);
32373 + if (nlen <= AUFS_WH_PFX_LEN
32374 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32375 + if (test_known(&arg->delist, name, nlen)
32376 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32377 + goto out; /* already exists or whiteouted */
32379 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32381 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32382 + d_type = DT_UNKNOWN;
32383 + arg->err = append_de(arg->vdir, name, nlen, ino,
32384 + d_type, &arg->delist);
32386 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32387 + name += AUFS_WH_PFX_LEN;
32388 + nlen -= AUFS_WH_PFX_LEN;
32389 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32390 + goto out; /* already whiteouted */
32392 + ino = 0; /* just to suppress a warning */
32394 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32397 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32398 + d_type = DT_UNKNOWN;
32399 + arg->err = au_nhash_append_wh
32400 + (&arg->whlist, name, nlen, ino, d_type,
32401 + arg->bindex, shwh);
32407 + arg->vdir->vd_jiffy = jiffies;
32409 + AuTraceErr(arg->err);
32413 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32414 + struct au_nhash *whlist, struct au_nhash *delist)
32416 +#ifdef CONFIG_AUFS_SHWH
32418 + unsigned int nh, u;
32419 + struct hlist_head *head;
32420 + struct au_vdir_wh *pos;
32421 + struct hlist_node *n;
32423 + struct au_vdir_destr *destr;
32425 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32428 + o = p = (void *)__get_free_page(GFP_NOFS);
32429 + if (unlikely(!p))
32433 + nh = whlist->nh_num;
32434 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32435 + p += AUFS_WH_PFX_LEN;
32436 + for (u = 0; u < nh; u++) {
32437 + head = whlist->nh_head + u;
32438 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32439 + destr = &pos->wh_str;
32440 + memcpy(p, destr->name, destr->len);
32441 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32442 + pos->wh_ino, pos->wh_type, delist);
32443 + if (unlikely(err))
32448 + free_page((unsigned long)o);
32458 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32461 + unsigned int rdhash;
32463 + aufs_bindex_t bbot, bindex, btop;
32464 + unsigned char shwh;
32465 + struct file *hf, *file;
32466 + struct super_block *sb;
32468 + file = arg->file;
32469 + sb = file->f_path.dentry->d_sb;
32470 + SiMustAnyLock(sb);
32472 + rdhash = au_sbi(sb)->si_rdhash;
32474 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32475 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32476 + if (unlikely(err))
32478 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32479 + if (unlikely(err))
32485 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32487 + au_fset_fillvdir(arg->flags, SHWH);
32489 + btop = au_fbtop(file);
32490 + bbot = au_fbbot_dir(file);
32491 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32492 + hf = au_hf_dir(file, bindex);
32496 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32498 + if (unlikely(offset))
32501 + arg->bindex = bindex;
32502 + au_fclr_fillvdir(arg->flags, WHABLE);
32504 + || (bindex != bbot
32505 + && au_br_whable(au_sbr_perm(sb, bindex))))
32506 + au_fset_fillvdir(arg->flags, WHABLE);
32509 + au_fclr_fillvdir(arg->flags, CALLED);
32511 + err = vfsub_iterate_dir(hf, &arg->ctx);
32514 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32517 + * dir_relax() may be good for concurrency, but aufs should not
32518 + * use it since it will cause a lockdep problem.
32522 + if (!err && shwh)
32523 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32525 + au_nhash_wh_free(&arg->whlist);
32528 + au_nhash_de_free(&arg->delist);
32533 +static int read_vdir(struct file *file, int may_read)
32536 + unsigned long expire;
32537 + unsigned char do_read;
32538 + struct fillvdir_arg arg = {
32540 + .actor = fillvdir
32543 + struct inode *inode;
32544 + struct au_vdir *vdir, *allocated;
32547 + inode = file_inode(file);
32548 + IMustLock(inode);
32549 + IiMustWriteLock(inode);
32550 + SiMustAnyLock(inode->i_sb);
32552 + allocated = NULL;
32554 + expire = au_sbi(inode->i_sb)->si_rdcache;
32555 + vdir = au_ivdir(inode);
32558 + vdir = alloc_vdir(file);
32559 + err = PTR_ERR(vdir);
32560 + if (IS_ERR(vdir))
32563 + allocated = vdir;
32564 + } else if (may_read
32565 + && (!inode_eq_iversion(inode, vdir->vd_version)
32566 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32568 + err = reinit_vdir(vdir);
32569 + if (unlikely(err))
32574 + return 0; /* success */
32578 + err = au_do_read_vdir(&arg);
32580 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32581 + vdir->vd_version = inode_query_iversion(inode);
32582 + vdir->vd_last.ul = 0;
32583 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32585 + au_set_ivdir(inode, allocated);
32586 + } else if (allocated)
32587 + au_vdir_free(allocated);
32593 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32596 + unsigned long ul, n;
32597 + const unsigned int deblk_sz = src->vd_deblk_sz;
32599 + AuDebugOn(tgt->vd_nblk != 1);
32602 + if (tgt->vd_nblk < src->vd_nblk) {
32603 + unsigned char **p;
32605 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32606 + GFP_NOFS, /*may_shrink*/0);
32607 + if (unlikely(!p))
32609 + tgt->vd_deblk = p;
32612 + if (tgt->vd_deblk_sz != deblk_sz) {
32613 + unsigned char *p;
32615 + tgt->vd_deblk_sz = deblk_sz;
32616 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32617 + /*may_shrink*/1);
32618 + if (unlikely(!p))
32620 + tgt->vd_deblk[0] = p;
32622 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32623 + tgt->vd_version = src->vd_version;
32624 + tgt->vd_jiffy = src->vd_jiffy;
32626 + n = src->vd_nblk;
32627 + for (ul = 1; ul < n; ul++) {
32628 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32630 + if (unlikely(!tgt->vd_deblk[ul]))
32634 + tgt->vd_nblk = n;
32635 + tgt->vd_last.ul = tgt->vd_last.ul;
32636 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32637 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32638 + - src->vd_deblk[src->vd_last.ul];
32640 + return 0; /* success */
32643 + rerr = reinit_vdir(tgt);
32648 +int au_vdir_init(struct file *file)
32651 + struct inode *inode;
32652 + struct au_vdir *vdir_cache, *allocated;
32654 + /* test file->f_pos here instead of ctx->pos */
32655 + err = read_vdir(file, !file->f_pos);
32656 + if (unlikely(err))
32659 + allocated = NULL;
32660 + vdir_cache = au_fvdir_cache(file);
32661 + if (!vdir_cache) {
32662 + vdir_cache = alloc_vdir(file);
32663 + err = PTR_ERR(vdir_cache);
32664 + if (IS_ERR(vdir_cache))
32666 + allocated = vdir_cache;
32667 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32668 + /* test file->f_pos here instead of ctx->pos */
32669 + err = reinit_vdir(vdir_cache);
32670 + if (unlikely(err))
32673 + return 0; /* success */
32675 + inode = file_inode(file);
32676 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32678 + file->f_version = inode_query_iversion(inode);
32680 + au_set_fvdir_cache(file, allocated);
32681 + } else if (allocated)
32682 + au_vdir_free(allocated);
32688 +static loff_t calc_offset(struct au_vdir *vdir)
32691 + union au_vdir_deblk_p p;
32693 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32694 + offset = vdir->vd_last.p.deblk - p.deblk;
32695 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32699 +/* returns true or false */
32700 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32703 + unsigned int deblk_sz;
32704 + unsigned long ul, n;
32706 + union au_vdir_deblk_p p, deblk_end;
32707 + struct au_vdir *vdir_cache;
32710 + vdir_cache = au_fvdir_cache(file);
32711 + offset = calc_offset(vdir_cache);
32712 + AuDbg("offset %lld\n", offset);
32713 + if (ctx->pos == offset)
32716 + vdir_cache->vd_last.ul = 0;
32717 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32722 + deblk_sz = vdir_cache->vd_deblk_sz;
32723 + ul = div64_u64(ctx->pos, deblk_sz);
32724 + AuDbg("ul %lu\n", ul);
32725 + if (ul >= vdir_cache->vd_nblk)
32728 + n = vdir_cache->vd_nblk;
32729 + for (; ul < n; ul++) {
32730 + p.deblk = vdir_cache->vd_deblk[ul];
32731 + deblk_end.deblk = p.deblk + deblk_sz;
32733 + offset *= deblk_sz;
32734 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32737 + l = calc_size(p.de->de_str.len);
32741 + if (!is_deblk_end(&p, &deblk_end)) {
32743 + vdir_cache->vd_last.ul = ul;
32744 + vdir_cache->vd_last.p = p;
32752 + AuDbg("valid %d\n", !valid);
32756 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32758 + unsigned int l, deblk_sz;
32759 + union au_vdir_deblk_p deblk_end;
32760 + struct au_vdir *vdir_cache;
32761 + struct au_vdir_de *de;
32763 + if (!seek_vdir(file, ctx))
32766 + vdir_cache = au_fvdir_cache(file);
32767 + deblk_sz = vdir_cache->vd_deblk_sz;
32769 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32770 + deblk_end.deblk += deblk_sz;
32771 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32772 + de = vdir_cache->vd_last.p.de;
32773 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32774 + de->de_str.len, de->de_str.name, ctx->pos,
32775 + (unsigned long)de->de_ino, de->de_type);
32776 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32777 + de->de_str.len, de->de_ino,
32779 + /* todo: ignore the error caused by udba? */
32780 + /* return err; */
32784 + l = calc_size(de->de_str.len);
32785 + vdir_cache->vd_last.p.deblk += l;
32788 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32789 + vdir_cache->vd_last.ul++;
32790 + vdir_cache->vd_last.p.deblk
32791 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32792 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32801 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32802 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32803 +++ linux/fs/aufs/vfsub.c 2019-07-11 15:42:14.475571481 +0200
32805 +// SPDX-License-Identifier: GPL-2.0
32807 + * Copyright (C) 2005-2019 Junjiro R. Okajima
32809 + * This program, aufs is free software; you can redistribute it and/or modify
32810 + * it under the terms of the GNU General Public License as published by
32811 + * the Free Software Foundation; either version 2 of the License, or
32812 + * (at your option) any later version.
32814 + * This program is distributed in the hope that it will be useful,
32815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32817 + * GNU General Public License for more details.
32819 + * You should have received a copy of the GNU General Public License
32820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32824 + * sub-routines for VFS
32827 +#include <linux/mnt_namespace.h>
32828 +#include <linux/namei.h>
32829 +#include <linux/nsproxy.h>
32830 +#include <linux/security.h>
32831 +#include <linux/splice.h>
32834 +#ifdef CONFIG_AUFS_BR_FUSE
32835 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32837 + if (!au_test_fuse(h_sb) || !au_userns)
32840 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32844 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32849 + down_read(&h_sb->s_umount);
32850 + err = __sync_filesystem(h_sb, wait);
32851 + up_read(&h_sb->s_umount);
32857 +/* ---------------------------------------------------------------------- */
32859 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32863 + struct super_block *h_sb;
32865 + /* for remote fs, leave work for its getattr or d_revalidate */
32866 + /* for bad i_attr fs, handle them in aufs_getattr() */
32867 + /* still some fs may acquire i_mutex. we need to skip them */
32871 + h_sb = h_path->dentry->d_sb;
32872 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32874 + err = vfsub_getattr(h_path, &st);
32879 +/* ---------------------------------------------------------------------- */
32881 +struct file *vfsub_dentry_open(struct path *path, int flags)
32883 + struct file *file;
32885 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32887 + if (!IS_ERR_OR_NULL(file)
32888 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32889 + i_readcount_inc(d_inode(path->dentry));
32894 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32896 + struct file *file;
32899 + file = filp_open(path,
32900 + oflags /* | __FMODE_NONOTIFY */,
32903 + if (IS_ERR(file))
32905 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32912 + * Ideally this function should call VFS:do_last() in order to keep all its
32913 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32914 + * structure such as nameidata. This is a second (or third) best approach.
32915 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32917 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32918 + struct vfsub_aopen_args *args)
32921 + struct au_branch *br = args->br;
32922 + struct file *file = args->file;
32923 + /* copied from linux/fs/namei.c:atomic_open() */
32924 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32927 + AuDebugOn(!dir->i_op->atomic_open);
32929 + err = au_br_test_oflag(args->open_flag, br);
32930 + if (unlikely(err))
32933 + au_lcnt_inc(&br->br_nfiles);
32934 + file->f_path.dentry = DENTRY_NOT_SET;
32935 + file->f_path.mnt = au_br_mnt(br);
32936 + AuDbg("%ps\n", dir->i_op->atomic_open);
32937 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32938 + args->create_mode);
32939 + if (unlikely(err < 0)) {
32940 + au_lcnt_dec(&br->br_nfiles);
32944 + /* temporary workaround for nfsv4 branch */
32945 + if (au_test_nfs(dir->i_sb))
32946 + nfs_mark_for_revalidate(dir);
32948 + if (file->f_mode & FMODE_CREATED)
32949 + fsnotify_create(dir, dentry);
32950 + if (!(file->f_mode & FMODE_OPENED)) {
32951 + au_lcnt_dec(&br->br_nfiles);
32955 + /* todo: call VFS:may_open() here */
32956 + /* todo: ima_file_check() too? */
32957 + if (!err && (args->open_flag & __FMODE_EXEC))
32958 + err = deny_write_access(file);
32960 + fsnotify_open(file);
32962 + au_lcnt_dec(&br->br_nfiles);
32963 + /* note that the file is created and still opened */
32969 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32973 + err = kern_path(name, flags, path);
32974 + if (!err && d_is_positive(path->dentry))
32975 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32979 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32980 + struct dentry *parent, int len)
32982 + struct path path = {
32986 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32987 + if (IS_ERR(path.dentry))
32989 + if (d_is_positive(path.dentry))
32990 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32993 + AuTraceErrPtr(path.dentry);
32994 + return path.dentry;
32997 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33000 + struct path path = {
33004 + /* VFS checks it too, but by WARN_ON_ONCE() */
33005 + IMustLock(d_inode(parent));
33007 + path.dentry = lookup_one_len(name, parent, len);
33008 + if (IS_ERR(path.dentry))
33010 + if (d_is_positive(path.dentry))
33011 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33014 + AuTraceErrPtr(path.dentry);
33015 + return path.dentry;
33018 +void vfsub_call_lkup_one(void *args)
33020 + struct vfsub_lkup_one_args *a = args;
33021 + *a->errp = vfsub_lkup_one(a->name, a->parent);
33024 +/* ---------------------------------------------------------------------- */
33026 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33027 + struct dentry *d2, struct au_hinode *hdir2)
33029 + struct dentry *d;
33032 + d = lock_rename(d1, d2);
33034 + au_hn_suspend(hdir1);
33035 + if (hdir1 != hdir2)
33036 + au_hn_suspend(hdir2);
33041 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33042 + struct dentry *d2, struct au_hinode *hdir2)
33044 + au_hn_resume(hdir1);
33045 + if (hdir1 != hdir2)
33046 + au_hn_resume(hdir2);
33048 + unlock_rename(d1, d2);
33052 +/* ---------------------------------------------------------------------- */
33054 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33057 + struct dentry *d;
33061 + d = path->dentry;
33062 + path->dentry = d->d_parent;
33063 + err = security_path_mknod(path, d, mode, 0);
33064 + path->dentry = d;
33065 + if (unlikely(err))
33069 + err = vfs_create(dir, path->dentry, mode, want_excl);
33072 + struct path tmp = *path;
33075 + vfsub_update_h_iattr(&tmp, &did);
33077 + tmp.dentry = path->dentry->d_parent;
33078 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33087 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33090 + struct dentry *d;
33094 + d = path->dentry;
33095 + path->dentry = d->d_parent;
33096 + err = security_path_symlink(path, d, symname);
33097 + path->dentry = d;
33098 + if (unlikely(err))
33102 + err = vfs_symlink(dir, path->dentry, symname);
33105 + struct path tmp = *path;
33108 + vfsub_update_h_iattr(&tmp, &did);
33110 + tmp.dentry = path->dentry->d_parent;
33111 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33120 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33123 + struct dentry *d;
33127 + d = path->dentry;
33128 + path->dentry = d->d_parent;
33129 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33130 + path->dentry = d;
33131 + if (unlikely(err))
33135 + err = vfs_mknod(dir, path->dentry, mode, dev);
33138 + struct path tmp = *path;
33141 + vfsub_update_h_iattr(&tmp, &did);
33143 + tmp.dentry = path->dentry->d_parent;
33144 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33153 +static int au_test_nlink(struct inode *inode)
33155 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33157 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33158 + || inode->i_nlink < link_max)
33163 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33164 + struct inode **delegated_inode)
33167 + struct dentry *d;
33171 + err = au_test_nlink(d_inode(src_dentry));
33172 + if (unlikely(err))
33175 + /* we don't call may_linkat() */
33176 + d = path->dentry;
33177 + path->dentry = d->d_parent;
33178 + err = security_path_link(src_dentry, path, d);
33179 + path->dentry = d;
33180 + if (unlikely(err))
33184 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33187 + struct path tmp = *path;
33190 + /* fuse has different memory inode for the same inumber */
33191 + vfsub_update_h_iattr(&tmp, &did);
33193 + tmp.dentry = path->dentry->d_parent;
33194 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33195 + tmp.dentry = src_dentry;
33196 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33205 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33206 + struct inode *dir, struct path *path,
33207 + struct inode **delegated_inode, unsigned int flags)
33210 + struct path tmp = {
33213 + struct dentry *d;
33216 + IMustLock(src_dir);
33218 + d = path->dentry;
33219 + path->dentry = d->d_parent;
33220 + tmp.dentry = src_dentry->d_parent;
33221 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33222 + path->dentry = d;
33223 + if (unlikely(err))
33227 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33228 + delegated_inode, flags);
33233 + tmp.dentry = d->d_parent;
33234 + vfsub_update_h_iattr(&tmp, &did);
33236 + tmp.dentry = src_dentry;
33237 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33238 + tmp.dentry = src_dentry->d_parent;
33239 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33248 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33251 + struct dentry *d;
33255 + d = path->dentry;
33256 + path->dentry = d->d_parent;
33257 + err = security_path_mkdir(path, d, mode);
33258 + path->dentry = d;
33259 + if (unlikely(err))
33263 + err = vfs_mkdir(dir, path->dentry, mode);
33266 + struct path tmp = *path;
33269 + vfsub_update_h_iattr(&tmp, &did);
33271 + tmp.dentry = path->dentry->d_parent;
33272 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33281 +int vfsub_rmdir(struct inode *dir, struct path *path)
33284 + struct dentry *d;
33288 + d = path->dentry;
33289 + path->dentry = d->d_parent;
33290 + err = security_path_rmdir(path, d);
33291 + path->dentry = d;
33292 + if (unlikely(err))
33296 + err = vfs_rmdir(dir, path->dentry);
33299 + struct path tmp = {
33300 + .dentry = path->dentry->d_parent,
33304 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33311 +/* ---------------------------------------------------------------------- */
33313 +/* todo: support mmap_sem? */
33314 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33320 + err = vfs_read(file, ubuf, count, ppos);
33323 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33327 +/* todo: kernel_read()? */
33328 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33332 + mm_segment_t oldfs;
33339 + oldfs = get_fs();
33340 + set_fs(KERNEL_DS);
33341 + err = vfsub_read_u(file, buf.u, count, ppos);
33346 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33352 + err = vfs_write(file, ubuf, count, ppos);
33355 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33359 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33362 + mm_segment_t oldfs;
33365 + const char __user *u;
33369 + oldfs = get_fs();
33370 + set_fs(KERNEL_DS);
33371 + err = vfsub_write_u(file, buf.u, count, ppos);
33376 +int vfsub_flush(struct file *file, fl_owner_t id)
33381 + if (file->f_op->flush) {
33382 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33383 + err = file->f_op->flush(file, id);
33386 + err = file->f_op->flush(file, id);
33390 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33396 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33400 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33403 + err = iterate_dir(file, ctx);
33406 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33411 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33412 + struct pipe_inode_info *pipe, size_t len,
33413 + unsigned int flags)
33418 + err = do_splice_to(in, ppos, pipe, len, flags);
33420 + file_accessed(in);
33422 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33426 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33427 + loff_t *ppos, size_t len, unsigned int flags)
33432 + err = do_splice_from(pipe, out, ppos, len, flags);
33435 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33439 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33443 + /* file can be NULL */
33445 + err = vfs_fsync(file, datasync);
33449 + AuDebugOn(!file);
33450 + path = &file->f_path;
33452 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33457 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33458 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33459 + struct file *h_file)
33462 + struct inode *h_inode;
33463 + struct super_block *h_sb;
33466 + err = vfsub_truncate(h_path, length);
33470 + h_inode = d_inode(h_path->dentry);
33471 + h_sb = h_inode->i_sb;
33473 + sb_start_write(h_sb);
33475 + err = locks_verify_truncate(h_inode, h_file, length);
33477 + err = security_path_truncate(h_path);
33480 + err = do_truncate(h_path->dentry, length, attr, h_file);
33484 + sb_end_write(h_sb);
33491 +/* ---------------------------------------------------------------------- */
33493 +struct au_vfsub_mkdir_args {
33495 + struct inode *dir;
33496 + struct path *path;
33500 +static void au_call_vfsub_mkdir(void *args)
33502 + struct au_vfsub_mkdir_args *a = args;
33503 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33506 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33508 + int err, do_sio, wkq_err;
33510 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33513 + err = vfsub_mkdir(dir, path, mode);
33516 + struct au_vfsub_mkdir_args args = {
33522 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33523 + if (unlikely(wkq_err))
33530 +struct au_vfsub_rmdir_args {
33532 + struct inode *dir;
33533 + struct path *path;
33536 +static void au_call_vfsub_rmdir(void *args)
33538 + struct au_vfsub_rmdir_args *a = args;
33539 + *a->errp = vfsub_rmdir(a->dir, a->path);
33542 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33544 + int err, do_sio, wkq_err;
33546 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33549 + err = vfsub_rmdir(dir, path);
33552 + struct au_vfsub_rmdir_args args = {
33557 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33558 + if (unlikely(wkq_err))
33565 +/* ---------------------------------------------------------------------- */
33567 +struct notify_change_args {
33569 + struct path *path;
33570 + struct iattr *ia;
33571 + struct inode **delegated_inode;
33574 +static void call_notify_change(void *args)
33576 + struct notify_change_args *a = args;
33577 + struct inode *h_inode;
33579 + h_inode = d_inode(a->path->dentry);
33580 + IMustLock(h_inode);
33582 + *a->errp = -EPERM;
33583 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33585 + *a->errp = notify_change(a->path->dentry, a->ia,
33586 + a->delegated_inode);
33589 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33591 + AuTraceErr(*a->errp);
33594 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33595 + struct inode **delegated_inode)
33598 + struct notify_change_args args = {
33602 + .delegated_inode = delegated_inode
33605 + call_notify_change(&args);
33610 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33611 + struct inode **delegated_inode)
33613 + int err, wkq_err;
33614 + struct notify_change_args args = {
33618 + .delegated_inode = delegated_inode
33621 + wkq_err = au_wkq_wait(call_notify_change, &args);
33622 + if (unlikely(wkq_err))
33628 +/* ---------------------------------------------------------------------- */
33630 +struct unlink_args {
33632 + struct inode *dir;
33633 + struct path *path;
33634 + struct inode **delegated_inode;
33637 +static void call_unlink(void *args)
33639 + struct unlink_args *a = args;
33640 + struct dentry *d = a->path->dentry;
33641 + struct inode *h_inode;
33642 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33643 + && au_dcount(d) == 1);
33645 + IMustLock(a->dir);
33647 + a->path->dentry = d->d_parent;
33648 + *a->errp = security_path_unlink(a->path, d);
33649 + a->path->dentry = d;
33650 + if (unlikely(*a->errp))
33653 + if (!stop_sillyrename)
33656 + if (d_is_positive(d)) {
33657 + h_inode = d_inode(d);
33662 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33665 + struct path tmp = {
33666 + .dentry = d->d_parent,
33667 + .mnt = a->path->mnt
33669 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33672 + if (!stop_sillyrename)
33677 + AuTraceErr(*a->errp);
33681 + * @dir: must be locked.
33682 + * @dentry: target dentry.
33684 +int vfsub_unlink(struct inode *dir, struct path *path,
33685 + struct inode **delegated_inode, int force)
33688 + struct unlink_args args = {
33692 + .delegated_inode = delegated_inode
33696 + call_unlink(&args);
33700 + wkq_err = au_wkq_wait(call_unlink, &args);
33701 + if (unlikely(wkq_err))
33707 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33708 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33709 +++ linux/fs/aufs/vfsub.h 2019-07-11 15:42:14.475571481 +0200
33711 +/* SPDX-License-Identifier: GPL-2.0 */
33713 + * Copyright (C) 2005-2019 Junjiro R. Okajima
33715 + * This program, aufs is free software; you can redistribute it and/or modify
33716 + * it under the terms of the GNU General Public License as published by
33717 + * the Free Software Foundation; either version 2 of the License, or
33718 + * (at your option) any later version.
33720 + * This program is distributed in the hope that it will be useful,
33721 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33722 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33723 + * GNU General Public License for more details.
33725 + * You should have received a copy of the GNU General Public License
33726 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33730 + * sub-routines for VFS
33733 +#ifndef __AUFS_VFSUB_H__
33734 +#define __AUFS_VFSUB_H__
33738 +#include <linux/fs.h>
33739 +#include <linux/mount.h>
33740 +#include <linux/posix_acl.h>
33741 +#include <linux/xattr.h>
33742 +#include "debug.h"
33744 +/* copied from linux/fs/internal.h */
33745 +/* todo: BAD approach!! */
33746 +extern void __mnt_drop_write(struct vfsmount *);
33747 +extern struct file *alloc_empty_file(int, const struct cred *);
33749 +/* ---------------------------------------------------------------------- */
33751 +/* lock subclass for lower inode */
33752 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33753 +/* reduce? gave up. */
33755 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33756 + AuLsc_I_PARENT, /* lower inode, parent first */
33757 + AuLsc_I_PARENT2, /* copyup dirs */
33758 + AuLsc_I_PARENT3, /* copyup wh */
33764 +/* to debug easier, do not make them inlined functions */
33765 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33766 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33768 +/* ---------------------------------------------------------------------- */
33770 +static inline void vfsub_drop_nlink(struct inode *inode)
33772 + AuDebugOn(!inode->i_nlink);
33773 + drop_nlink(inode);
33776 +static inline void vfsub_dead_dir(struct inode *inode)
33778 + AuDebugOn(!S_ISDIR(inode->i_mode));
33779 + inode->i_flags |= S_DEAD;
33780 + clear_nlink(inode);
33783 +static inline int vfsub_native_ro(struct inode *inode)
33785 + return sb_rdonly(inode->i_sb)
33786 + || IS_RDONLY(inode)
33787 + /* || IS_APPEND(inode) */
33788 + || IS_IMMUTABLE(inode);
33791 +#ifdef CONFIG_AUFS_BR_FUSE
33792 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33794 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33797 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33799 +/* ---------------------------------------------------------------------- */
33801 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33802 +struct file *vfsub_dentry_open(struct path *path, int flags);
33803 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33805 +struct vfsub_aopen_args {
33806 + struct file *file;
33807 + unsigned int open_flag;
33808 + umode_t create_mode;
33809 + struct au_branch *br;
33811 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33812 + struct vfsub_aopen_args *args);
33813 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33815 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33816 + struct dentry *parent, int len);
33817 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33820 +struct vfsub_lkup_one_args {
33821 + struct dentry **errp;
33822 + struct qstr *name;
33823 + struct dentry *parent;
33826 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33827 + struct dentry *parent)
33829 + return vfsub_lookup_one_len(name->name, parent, name->len);
33832 +void vfsub_call_lkup_one(void *args);
33834 +/* ---------------------------------------------------------------------- */
33836 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33841 + err = mnt_want_write(mnt);
33846 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33849 + mnt_drop_write(mnt);
33853 +#if 0 /* reserved */
33854 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33857 + mnt_drop_write_file(file);
33862 +/* ---------------------------------------------------------------------- */
33865 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33866 + struct dentry *d2, struct au_hinode *hdir2);
33867 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33868 + struct dentry *d2, struct au_hinode *hdir2);
33870 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33872 +int vfsub_symlink(struct inode *dir, struct path *path,
33873 + const char *symname);
33874 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33875 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33876 + struct path *path, struct inode **delegated_inode);
33877 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33878 + struct inode *hdir, struct path *path,
33879 + struct inode **delegated_inode, unsigned int flags);
33880 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33881 +int vfsub_rmdir(struct inode *dir, struct path *path);
33883 +/* ---------------------------------------------------------------------- */
33885 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33887 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33889 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33891 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33893 +int vfsub_flush(struct file *file, fl_owner_t id);
33894 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33896 +static inline loff_t vfsub_f_size_read(struct file *file)
33898 + return i_size_read(file_inode(file));
33901 +static inline unsigned int vfsub_file_flags(struct file *file)
33903 + unsigned int flags;
33905 + spin_lock(&file->f_lock);
33906 + flags = file->f_flags;
33907 + spin_unlock(&file->f_lock);
33912 +static inline int vfsub_file_execed(struct file *file)
33914 + /* todo: direct access f_flags */
33915 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33918 +#if 0 /* reserved */
33919 +static inline void vfsub_file_accessed(struct file *h_file)
33921 + file_accessed(h_file);
33922 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33926 +#if 0 /* reserved */
33927 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33928 + struct dentry *h_dentry)
33930 + struct path h_path = {
33931 + .dentry = h_dentry,
33934 + touch_atime(&h_path);
33935 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33939 +static inline int vfsub_update_time(struct inode *h_inode,
33940 + struct timespec64 *ts, int flags)
33942 + return update_time(h_inode, ts, flags);
33943 + /* no vfsub_update_h_iattr() since we don't have struct path */
33946 +#ifdef CONFIG_FS_POSIX_ACL
33947 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33951 + err = posix_acl_chmod(h_inode, h_mode);
33952 + if (err == -EOPNOTSUPP)
33957 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33960 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33961 + struct pipe_inode_info *pipe, size_t len,
33962 + unsigned int flags);
33963 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33964 + loff_t *ppos, size_t len, unsigned int flags);
33966 +static inline long vfsub_truncate(struct path *path, loff_t length)
33971 + err = vfs_truncate(path, length);
33976 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33977 + struct file *h_file);
33978 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33981 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33984 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33990 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33996 +/* copy_file_range(2) is a systemcall */
33997 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33998 + struct file *dst, loff_t dst_pos,
33999 + size_t len, unsigned int flags)
34004 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34010 +/* ---------------------------------------------------------------------- */
34012 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34017 + err = vfs_llseek(file, offset, origin);
34022 +/* ---------------------------------------------------------------------- */
34024 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34025 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34026 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34027 + struct inode **delegated_inode);
34028 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34029 + struct inode **delegated_inode);
34030 +int vfsub_unlink(struct inode *dir, struct path *path,
34031 + struct inode **delegated_inode, int force);
34033 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34035 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34038 +/* ---------------------------------------------------------------------- */
34040 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
34041 + const void *value, size_t size, int flags)
34046 + err = vfs_setxattr(dentry, name, value, size, flags);
34052 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
34057 + err = vfs_removexattr(dentry, name);
34063 +#endif /* __KERNEL__ */
34064 +#endif /* __AUFS_VFSUB_H__ */
34065 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34066 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34067 +++ linux/fs/aufs/wbr_policy.c 2019-07-11 15:42:14.475571481 +0200
34069 +// SPDX-License-Identifier: GPL-2.0
34071 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34073 + * This program, aufs is free software; you can redistribute it and/or modify
34074 + * it under the terms of the GNU General Public License as published by
34075 + * the Free Software Foundation; either version 2 of the License, or
34076 + * (at your option) any later version.
34078 + * This program is distributed in the hope that it will be useful,
34079 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34080 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34081 + * GNU General Public License for more details.
34083 + * You should have received a copy of the GNU General Public License
34084 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34088 + * policies for selecting one among multiple writable branches
34091 +#include <linux/statfs.h>
34094 +/* subset of cpup_attr() */
34095 +static noinline_for_stack
34096 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34100 + struct inode *h_isrc;
34102 + h_isrc = d_inode(h_src);
34103 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34104 + ia.ia_mode = h_isrc->i_mode;
34105 + ia.ia_uid = h_isrc->i_uid;
34106 + ia.ia_gid = h_isrc->i_gid;
34107 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34108 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34109 + /* no delegation since it is just created */
34110 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34112 + /* is this nfs only? */
34113 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34114 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34115 + ia.ia_mode = h_isrc->i_mode;
34116 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34122 +#define AuCpdown_PARENT_OPQ 1
34123 +#define AuCpdown_WHED (1 << 1)
34124 +#define AuCpdown_MADE_DIR (1 << 2)
34125 +#define AuCpdown_DIROPQ (1 << 3)
34126 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34127 +#define au_fset_cpdown(flags, name) \
34128 + do { (flags) |= AuCpdown_##name; } while (0)
34129 +#define au_fclr_cpdown(flags, name) \
34130 + do { (flags) &= ~AuCpdown_##name; } while (0)
34132 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34133 + unsigned int *flags)
34136 + struct dentry *opq_dentry;
34138 + opq_dentry = au_diropq_create(dentry, bdst);
34139 + err = PTR_ERR(opq_dentry);
34140 + if (IS_ERR(opq_dentry))
34142 + dput(opq_dentry);
34143 + au_fset_cpdown(*flags, DIROPQ);
34149 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34150 + struct inode *dir, aufs_bindex_t bdst)
34153 + struct path h_path;
34154 + struct au_branch *br;
34156 + br = au_sbr(dentry->d_sb, bdst);
34157 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34158 + err = PTR_ERR(h_path.dentry);
34159 + if (IS_ERR(h_path.dentry))
34163 + if (d_is_positive(h_path.dentry)) {
34164 + h_path.mnt = au_br_mnt(br);
34165 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34168 + dput(h_path.dentry);
34174 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34175 + struct au_pin *pin,
34176 + struct dentry *h_parent, void *arg)
34179 + aufs_bindex_t bopq, btop;
34180 + struct path h_path;
34181 + struct dentry *parent;
34182 + struct inode *h_dir, *h_inode, *inode, *dir;
34183 + unsigned int *flags = arg;
34185 + btop = au_dbtop(dentry);
34186 + /* dentry is di-locked */
34187 + parent = dget_parent(dentry);
34188 + dir = d_inode(parent);
34189 + h_dir = d_inode(h_parent);
34190 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34191 + IMustLock(h_dir);
34193 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34194 + if (unlikely(err < 0))
34196 + h_path.dentry = au_h_dptr(dentry, bdst);
34197 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34198 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34199 + if (unlikely(err))
34201 + au_fset_cpdown(*flags, MADE_DIR);
34203 + bopq = au_dbdiropq(dentry);
34204 + au_fclr_cpdown(*flags, WHED);
34205 + au_fclr_cpdown(*flags, DIROPQ);
34206 + if (au_dbwh(dentry) == bdst)
34207 + au_fset_cpdown(*flags, WHED);
34208 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34209 + au_fset_cpdown(*flags, PARENT_OPQ);
34210 + h_inode = d_inode(h_path.dentry);
34211 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34212 + if (au_ftest_cpdown(*flags, WHED)) {
34213 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34214 + if (unlikely(err)) {
34215 + inode_unlock(h_inode);
34220 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34221 + inode_unlock(h_inode);
34222 + if (unlikely(err))
34225 + if (au_ftest_cpdown(*flags, WHED)) {
34226 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34227 + if (unlikely(err))
34231 + inode = d_inode(dentry);
34232 + if (au_ibbot(inode) < bdst)
34233 + au_set_ibbot(inode, bdst);
34234 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34235 + au_hi_flags(inode, /*isdir*/1));
34236 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34237 + goto out; /* success */
34241 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34242 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34243 + rerr = au_diropq_remove(dentry, bdst);
34244 + inode_unlock(h_inode);
34245 + if (unlikely(rerr)) {
34246 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34247 + dentry, bdst, rerr);
34253 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34254 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34255 + if (unlikely(rerr)) {
34256 + AuIOErr("failed removing %pd b%d (%d)\n",
34257 + dentry, bdst, rerr);
34262 + au_set_h_dptr(dentry, bdst, NULL);
34263 + if (au_dbbot(dentry) == bdst)
34264 + au_update_dbbot(dentry);
34270 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34273 + unsigned int flags;
34276 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34281 +/* ---------------------------------------------------------------------- */
34283 +/* policies for create */
34285 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34287 + int err, i, j, ndentry;
34288 + aufs_bindex_t bopq;
34289 + struct au_dcsub_pages dpages;
34290 + struct au_dpage *dpage;
34291 + struct dentry **dentries, *parent, *d;
34293 + err = au_dpages_init(&dpages, GFP_NOFS);
34294 + if (unlikely(err))
34296 + parent = dget_parent(dentry);
34297 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34298 + if (unlikely(err))
34302 + for (i = 0; i < dpages.ndpage; i++) {
34303 + dpage = dpages.dpages + i;
34304 + dentries = dpage->dentries;
34305 + ndentry = dpage->ndentry;
34306 + for (j = 0; j < ndentry; j++) {
34308 + di_read_lock_parent2(d, !AuLock_IR);
34309 + bopq = au_dbdiropq(d);
34310 + di_read_unlock(d, !AuLock_IR);
34311 + if (bopq >= 0 && bopq < err)
34318 + au_dpages_free(&dpages);
34323 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34325 + for (; bindex >= 0; bindex--)
34326 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34331 +/* top down parent */
34332 +static int au_wbr_create_tdp(struct dentry *dentry,
34333 + unsigned int flags __maybe_unused)
34336 + aufs_bindex_t btop, bindex;
34337 + struct super_block *sb;
34338 + struct dentry *parent, *h_parent;
34340 + sb = dentry->d_sb;
34341 + btop = au_dbtop(dentry);
34343 + if (!au_br_rdonly(au_sbr(sb, btop)))
34347 + parent = dget_parent(dentry);
34348 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34349 + h_parent = au_h_dptr(parent, bindex);
34350 + if (!h_parent || d_is_negative(h_parent))
34353 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34360 + /* bottom up here */
34361 + if (unlikely(err < 0)) {
34362 + err = au_wbr_bu(sb, btop - 1);
34364 + err = au_wbr_nonopq(dentry, err);
34368 + AuDbg("b%d\n", err);
34372 +/* ---------------------------------------------------------------------- */
34374 +/* an exception for the policy other than tdp */
34375 +static int au_wbr_create_exp(struct dentry *dentry)
34378 + aufs_bindex_t bwh, bdiropq;
34379 + struct dentry *parent;
34382 + bwh = au_dbwh(dentry);
34383 + parent = dget_parent(dentry);
34384 + bdiropq = au_dbdiropq(parent);
34386 + if (bdiropq >= 0)
34387 + err = min(bdiropq, bwh);
34390 + AuDbg("%d\n", err);
34391 + } else if (bdiropq >= 0) {
34393 + AuDbg("%d\n", err);
34398 + err = au_wbr_nonopq(dentry, err);
34400 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34403 + AuDbg("%d\n", err);
34407 +/* ---------------------------------------------------------------------- */
34410 +static int au_wbr_create_init_rr(struct super_block *sb)
34414 + err = au_wbr_bu(sb, au_sbbot(sb));
34415 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34418 + AuDbg("b%d\n", err);
34422 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34426 + aufs_bindex_t bindex, bbot;
34427 + struct super_block *sb;
34430 + err = au_wbr_create_exp(dentry);
34434 + sb = dentry->d_sb;
34435 + next = &au_sbi(sb)->si_wbr_rr_next;
34436 + bbot = au_sbbot(sb);
34438 + for (bindex = 0; bindex <= bbot; bindex++) {
34439 + if (!au_ftest_wbr(flags, DIR)) {
34440 + err = atomic_dec_return(next) + 1;
34441 + /* modulo for 0 is meaningless */
34442 + if (unlikely(!err))
34443 + err = atomic_dec_return(next) + 1;
34445 + err = atomic_read(next);
34446 + AuDbg("%d\n", err);
34449 + AuDbg("%d\n", err);
34450 + if (!au_br_rdonly(au_sbr(sb, err)))
34456 + err = au_wbr_nonopq(dentry, err);
34459 + AuDbg("%d\n", err);
34463 +/* ---------------------------------------------------------------------- */
34465 +/* most free space */
34466 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34468 + struct super_block *sb;
34469 + struct au_branch *br;
34470 + struct au_wbr_mfs *mfs;
34471 + struct dentry *h_parent;
34472 + aufs_bindex_t bindex, bbot;
34474 + unsigned long long b, bavail;
34475 + struct path h_path;
34476 + /* reduce the stack usage */
34477 + struct kstatfs *st;
34479 + st = kmalloc(sizeof(*st), GFP_NOFS);
34480 + if (unlikely(!st)) {
34481 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34486 + sb = dentry->d_sb;
34487 + mfs = &au_sbi(sb)->si_wbr_mfs;
34488 + MtxMustLock(&mfs->mfs_lock);
34489 + mfs->mfs_bindex = -EROFS;
34490 + mfs->mfsrr_bytes = 0;
34493 + bbot = au_sbbot(sb);
34495 + bindex = au_dbtop(parent);
34496 + bbot = au_dbtaildir(parent);
34499 + for (; bindex <= bbot; bindex++) {
34501 + h_parent = au_h_dptr(parent, bindex);
34502 + if (!h_parent || d_is_negative(h_parent))
34505 + br = au_sbr(sb, bindex);
34506 + if (au_br_rdonly(br))
34509 + /* sb->s_root for NFS is unreliable */
34510 + h_path.mnt = au_br_mnt(br);
34511 + h_path.dentry = h_path.mnt->mnt_root;
34512 + err = vfs_statfs(&h_path, st);
34513 + if (unlikely(err)) {
34514 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34518 + /* when the available size is equal, select the lower one */
34519 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34520 + || sizeof(b) < sizeof(st->f_bsize));
34521 + b = st->f_bavail * st->f_bsize;
34522 + br->br_wbr->wbr_bytes = b;
34523 + if (b >= bavail) {
34525 + mfs->mfs_bindex = bindex;
34526 + mfs->mfs_jiffy = jiffies;
34530 + mfs->mfsrr_bytes = bavail;
34531 + AuDbg("b%d\n", mfs->mfs_bindex);
34532 + au_kfree_rcu(st);
34535 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34538 + struct dentry *parent;
34539 + struct super_block *sb;
34540 + struct au_wbr_mfs *mfs;
34542 + err = au_wbr_create_exp(dentry);
34546 + sb = dentry->d_sb;
34548 + if (au_ftest_wbr(flags, PARENT))
34549 + parent = dget_parent(dentry);
34550 + mfs = &au_sbi(sb)->si_wbr_mfs;
34551 + mutex_lock(&mfs->mfs_lock);
34552 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34553 + || mfs->mfs_bindex < 0
34554 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34555 + au_mfs(dentry, parent);
34556 + mutex_unlock(&mfs->mfs_lock);
34557 + err = mfs->mfs_bindex;
34561 + err = au_wbr_nonopq(dentry, err);
34564 + AuDbg("b%d\n", err);
34568 +static int au_wbr_create_init_mfs(struct super_block *sb)
34570 + struct au_wbr_mfs *mfs;
34572 + mfs = &au_sbi(sb)->si_wbr_mfs;
34573 + mutex_init(&mfs->mfs_lock);
34574 + mfs->mfs_jiffy = 0;
34575 + mfs->mfs_bindex = -EROFS;
34580 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34582 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34586 +/* ---------------------------------------------------------------------- */
34588 +/* top down regardless parent, and then mfs */
34589 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34590 + unsigned int flags __maybe_unused)
34593 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34594 + unsigned long long watermark;
34595 + struct super_block *sb;
34596 + struct au_wbr_mfs *mfs;
34597 + struct au_branch *br;
34598 + struct dentry *parent;
34600 + sb = dentry->d_sb;
34601 + mfs = &au_sbi(sb)->si_wbr_mfs;
34602 + mutex_lock(&mfs->mfs_lock);
34603 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34604 + || mfs->mfs_bindex < 0)
34605 + au_mfs(dentry, /*parent*/NULL);
34606 + watermark = mfs->mfsrr_watermark;
34607 + bmfs = mfs->mfs_bindex;
34608 + mutex_unlock(&mfs->mfs_lock);
34610 + /* another style of au_wbr_create_exp() */
34611 + bwh = au_dbwh(dentry);
34612 + parent = dget_parent(dentry);
34613 + btail = au_dbtaildir(parent);
34614 + if (bwh >= 0 && bwh < btail)
34617 + err = au_wbr_nonopq(dentry, btail);
34618 + if (unlikely(err < 0))
34622 + for (bindex = 0; bindex <= btail; bindex++) {
34623 + br = au_sbr(sb, bindex);
34624 + if (au_br_rdonly(br))
34626 + if (br->br_wbr->wbr_bytes > watermark) {
34637 + AuDbg("b%d\n", err);
34641 +/* ---------------------------------------------------------------------- */
34643 +/* most free space and then round robin */
34644 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34647 + struct au_wbr_mfs *mfs;
34649 + err = au_wbr_create_mfs(dentry, flags);
34651 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34652 + mutex_lock(&mfs->mfs_lock);
34653 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34654 + err = au_wbr_create_rr(dentry, flags);
34655 + mutex_unlock(&mfs->mfs_lock);
34658 + AuDbg("b%d\n", err);
34662 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34666 + au_wbr_create_init_mfs(sb); /* ignore */
34667 + err = au_wbr_create_init_rr(sb);
34672 +/* ---------------------------------------------------------------------- */
34674 +/* top down parent and most free space */
34675 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34678 + unsigned long long b;
34679 + aufs_bindex_t bindex, btop, bbot;
34680 + struct super_block *sb;
34681 + struct dentry *parent, *h_parent;
34682 + struct au_branch *br;
34684 + err = au_wbr_create_tdp(dentry, flags);
34685 + if (unlikely(err < 0))
34687 + parent = dget_parent(dentry);
34688 + btop = au_dbtop(parent);
34689 + bbot = au_dbtaildir(parent);
34690 + if (btop == bbot)
34691 + goto out_parent; /* success */
34693 + e2 = au_wbr_create_mfs(dentry, flags);
34695 + goto out_parent; /* success */
34697 + /* when the available size is equal, select upper one */
34698 + sb = dentry->d_sb;
34699 + br = au_sbr(sb, err);
34700 + b = br->br_wbr->wbr_bytes;
34701 + AuDbg("b%d, %llu\n", err, b);
34703 + for (bindex = btop; bindex <= bbot; bindex++) {
34704 + h_parent = au_h_dptr(parent, bindex);
34705 + if (!h_parent || d_is_negative(h_parent))
34708 + br = au_sbr(sb, bindex);
34709 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34710 + b = br->br_wbr->wbr_bytes;
34712 + AuDbg("b%d, %llu\n", err, b);
34717 + err = au_wbr_nonopq(dentry, err);
34722 + AuDbg("b%d\n", err);
34726 +/* ---------------------------------------------------------------------- */
34729 + * - top down parent
34730 + * - most free space with parent
34731 + * - most free space round-robin regardless parent
34733 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34736 + unsigned long long watermark;
34737 + struct super_block *sb;
34738 + struct au_branch *br;
34739 + struct au_wbr_mfs *mfs;
34741 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34742 + if (unlikely(err < 0))
34745 + sb = dentry->d_sb;
34746 + br = au_sbr(sb, err);
34747 + mfs = &au_sbi(sb)->si_wbr_mfs;
34748 + mutex_lock(&mfs->mfs_lock);
34749 + watermark = mfs->mfsrr_watermark;
34750 + mutex_unlock(&mfs->mfs_lock);
34751 + if (br->br_wbr->wbr_bytes < watermark)
34752 + /* regardless the parent dir */
34753 + err = au_wbr_create_mfsrr(dentry, flags);
34756 + AuDbg("b%d\n", err);
34760 +/* ---------------------------------------------------------------------- */
34762 +/* policies for copyup */
34764 +/* top down parent */
34765 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34767 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34770 +/* bottom up parent */
34771 +static int au_wbr_copyup_bup(struct dentry *dentry)
34774 + aufs_bindex_t bindex, btop;
34775 + struct dentry *parent, *h_parent;
34776 + struct super_block *sb;
34779 + sb = dentry->d_sb;
34780 + parent = dget_parent(dentry);
34781 + btop = au_dbtop(parent);
34782 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34783 + h_parent = au_h_dptr(parent, bindex);
34784 + if (!h_parent || d_is_negative(h_parent))
34787 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34794 + /* bottom up here */
34795 + if (unlikely(err < 0))
34796 + err = au_wbr_bu(sb, btop - 1);
34798 + AuDbg("b%d\n", err);
34803 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34807 + err = au_wbr_bu(dentry->d_sb, btop);
34808 + AuDbg("b%d\n", err);
34810 + err = au_wbr_nonopq(dentry, err);
34812 + AuDbg("b%d\n", err);
34816 +static int au_wbr_copyup_bu(struct dentry *dentry)
34819 + aufs_bindex_t btop;
34821 + btop = au_dbtop(dentry);
34822 + err = au_wbr_do_copyup_bu(dentry, btop);
34826 +/* ---------------------------------------------------------------------- */
34828 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34829 + [AuWbrCopyup_TDP] = {
34830 + .copyup = au_wbr_copyup_tdp
34832 + [AuWbrCopyup_BUP] = {
34833 + .copyup = au_wbr_copyup_bup
34835 + [AuWbrCopyup_BU] = {
34836 + .copyup = au_wbr_copyup_bu
34840 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34841 + [AuWbrCreate_TDP] = {
34842 + .create = au_wbr_create_tdp
34844 + [AuWbrCreate_RR] = {
34845 + .create = au_wbr_create_rr,
34846 + .init = au_wbr_create_init_rr
34848 + [AuWbrCreate_MFS] = {
34849 + .create = au_wbr_create_mfs,
34850 + .init = au_wbr_create_init_mfs,
34851 + .fin = au_wbr_create_fin_mfs
34853 + [AuWbrCreate_MFSV] = {
34854 + .create = au_wbr_create_mfs,
34855 + .init = au_wbr_create_init_mfs,
34856 + .fin = au_wbr_create_fin_mfs
34858 + [AuWbrCreate_MFSRR] = {
34859 + .create = au_wbr_create_mfsrr,
34860 + .init = au_wbr_create_init_mfsrr,
34861 + .fin = au_wbr_create_fin_mfs
34863 + [AuWbrCreate_MFSRRV] = {
34864 + .create = au_wbr_create_mfsrr,
34865 + .init = au_wbr_create_init_mfsrr,
34866 + .fin = au_wbr_create_fin_mfs
34868 + [AuWbrCreate_TDMFS] = {
34869 + .create = au_wbr_create_tdmfs,
34870 + .init = au_wbr_create_init_mfs,
34871 + .fin = au_wbr_create_fin_mfs
34873 + [AuWbrCreate_TDMFSV] = {
34874 + .create = au_wbr_create_tdmfs,
34875 + .init = au_wbr_create_init_mfs,
34876 + .fin = au_wbr_create_fin_mfs
34878 + [AuWbrCreate_PMFS] = {
34879 + .create = au_wbr_create_pmfs,
34880 + .init = au_wbr_create_init_mfs,
34881 + .fin = au_wbr_create_fin_mfs
34883 + [AuWbrCreate_PMFSV] = {
34884 + .create = au_wbr_create_pmfs,
34885 + .init = au_wbr_create_init_mfs,
34886 + .fin = au_wbr_create_fin_mfs
34888 + [AuWbrCreate_PMFSRR] = {
34889 + .create = au_wbr_create_pmfsrr,
34890 + .init = au_wbr_create_init_mfsrr,
34891 + .fin = au_wbr_create_fin_mfs
34893 + [AuWbrCreate_PMFSRRV] = {
34894 + .create = au_wbr_create_pmfsrr,
34895 + .init = au_wbr_create_init_mfsrr,
34896 + .fin = au_wbr_create_fin_mfs
34899 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34900 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34901 +++ linux/fs/aufs/whout.c 2019-07-11 15:42:14.475571481 +0200
34903 +// SPDX-License-Identifier: GPL-2.0
34905 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34907 + * This program, aufs is free software; you can redistribute it and/or modify
34908 + * it under the terms of the GNU General Public License as published by
34909 + * the Free Software Foundation; either version 2 of the License, or
34910 + * (at your option) any later version.
34912 + * This program is distributed in the hope that it will be useful,
34913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34915 + * GNU General Public License for more details.
34917 + * You should have received a copy of the GNU General Public License
34918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34922 + * whiteout for logical deletion and opaque directory
34927 +#define WH_MASK 0444
34930 + * If a directory contains this file, then it is opaque. We start with the
34931 + * .wh. flag so that it is blocked by lookup.
34933 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34934 + sizeof(AUFS_WH_DIROPQ) - 1);
34937 + * generate whiteout name, which is NOT terminated by NULL.
34938 + * @name: original d_name.name
34939 + * @len: original d_name.len
34940 + * @wh: whiteout qstr
34941 + * returns zero when succeeds, otherwise error.
34942 + * succeeded value as wh->name should be freed by kfree().
34944 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34948 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34949 + return -ENAMETOOLONG;
34951 + wh->len = name->len + AUFS_WH_PFX_LEN;
34952 + p = kmalloc(wh->len, GFP_NOFS);
34955 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34956 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34963 +/* ---------------------------------------------------------------------- */
34966 + * test if the @wh_name exists under @h_parent.
34967 + * @try_sio specifies the necessary of super-io.
34969 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34972 + struct dentry *wh_dentry;
34975 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34977 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34978 + err = PTR_ERR(wh_dentry);
34979 + if (IS_ERR(wh_dentry)) {
34980 + if (err == -ENAMETOOLONG)
34986 + if (d_is_negative(wh_dentry))
34987 + goto out_wh; /* success */
34990 + if (d_is_reg(wh_dentry))
34991 + goto out_wh; /* success */
34994 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34995 + wh_dentry, d_inode(wh_dentry)->i_mode);
35004 + * test if the @h_dentry sets opaque or not.
35006 +int au_diropq_test(struct dentry *h_dentry)
35009 + struct inode *h_dir;
35011 + h_dir = d_inode(h_dentry);
35012 + err = au_wh_test(h_dentry, &diropq_name,
35013 + au_test_h_perm_sio(h_dir, MAY_EXEC));
35018 + * returns a negative dentry whose name is unique and temporary.
35020 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35021 + struct qstr *prefix)
35023 + struct dentry *dentry;
35025 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35027 + /* strict atomic_t is unnecessary here */
35028 + static unsigned short cnt;
35031 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35034 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35035 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35036 + dentry = ERR_PTR(-ENAMETOOLONG);
35037 + if (unlikely(qs.len > NAME_MAX))
35039 + dentry = ERR_PTR(-ENOMEM);
35040 + name = kmalloc(qs.len + 1, GFP_NOFS);
35041 + if (unlikely(!name))
35045 + /* doubly whiteout-ed */
35046 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35047 + p = name + AUFS_WH_PFX_LEN * 2;
35048 + memcpy(p, prefix->name, prefix->len);
35049 + p += prefix->len;
35051 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35054 + for (i = 0; i < 3; i++) {
35055 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35056 + dentry = au_sio_lkup_one(&qs, h_parent);
35057 + if (IS_ERR(dentry) || d_is_negative(dentry))
35061 + /* pr_warn("could not get random name\n"); */
35062 + dentry = ERR_PTR(-EEXIST);
35063 + AuDbg("%.*s\n", AuLNPair(&qs));
35067 + if (name != defname)
35068 + au_kfree_try_rcu(name);
35070 + AuTraceErrPtr(dentry);
35075 + * rename the @h_dentry on @br to the whiteouted temporary name.
35077 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35080 + struct path h_path = {
35081 + .mnt = au_br_mnt(br)
35083 + struct inode *h_dir, *delegated;
35084 + struct dentry *h_parent;
35086 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35087 + h_dir = d_inode(h_parent);
35088 + IMustLock(h_dir);
35090 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35091 + err = PTR_ERR(h_path.dentry);
35092 + if (IS_ERR(h_path.dentry))
35095 + /* under the same dir, no need to lock_rename() */
35096 + delegated = NULL;
35097 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35100 + if (unlikely(err == -EWOULDBLOCK)) {
35101 + pr_warn("cannot retry for NFSv4 delegation"
35102 + " for an internal rename\n");
35105 + dput(h_path.dentry);
35112 +/* ---------------------------------------------------------------------- */
35114 + * functions for removing a whiteout
35117 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35120 + struct inode *delegated;
35123 + * forces superio when the dir has a sticky bit.
35124 + * this may be a violation of unix fs semantics.
35126 + force = (h_dir->i_mode & S_ISVTX)
35127 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35128 + delegated = NULL;
35129 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35130 + if (unlikely(err == -EWOULDBLOCK)) {
35131 + pr_warn("cannot retry for NFSv4 delegation"
35132 + " for an internal unlink\n");
35138 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35139 + struct dentry *dentry)
35143 + err = do_unlink_wh(h_dir, h_path);
35144 + if (!err && dentry)
35145 + au_set_dbwh(dentry, -1);
35150 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35151 + struct au_branch *br)
35154 + struct path h_path = {
35155 + .mnt = au_br_mnt(br)
35159 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35160 + if (IS_ERR(h_path.dentry))
35161 + err = PTR_ERR(h_path.dentry);
35163 + if (d_is_reg(h_path.dentry))
35164 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35165 + dput(h_path.dentry);
35171 +/* ---------------------------------------------------------------------- */
35173 + * initialize/clean whiteout for a branch
35176 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35180 + struct inode *delegated;
35182 + if (d_is_negative(whpath->dentry))
35186 + err = vfsub_rmdir(h_dir, whpath);
35188 + delegated = NULL;
35189 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35190 + if (unlikely(err == -EWOULDBLOCK)) {
35191 + pr_warn("cannot retry for NFSv4 delegation"
35192 + " for an internal unlink\n");
35196 + if (unlikely(err))
35197 + pr_warn("failed removing %pd (%d), ignored.\n",
35198 + whpath->dentry, err);
35201 +static int test_linkable(struct dentry *h_root)
35203 + struct inode *h_dir = d_inode(h_root);
35205 + if (h_dir->i_op->link)
35208 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35209 + h_root, au_sbtype(h_root->d_sb));
35213 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35214 +static int au_whdir(struct inode *h_dir, struct path *path)
35219 + if (d_is_negative(path->dentry)) {
35222 + if (au_test_nfs(path->dentry->d_sb))
35224 + err = vfsub_mkdir(h_dir, path, mode);
35225 + } else if (d_is_dir(path->dentry))
35228 + pr_err("unknown %pd exists\n", path->dentry);
35233 +struct au_wh_base {
35234 + const struct qstr *name;
35235 + struct dentry *dentry;
35238 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35239 + struct path *h_path)
35241 + h_path->dentry = base[AuBrWh_BASE].dentry;
35242 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35243 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35244 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35245 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35246 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35250 + * returns tri-state,
35251 + * minus: error, caller should print the message
35253 + * plus: error, caller should NOT print the message
35255 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35256 + int do_plink, struct au_wh_base base[],
35257 + struct path *h_path)
35260 + struct inode *h_dir;
35262 + h_dir = d_inode(h_root);
35263 + h_path->dentry = base[AuBrWh_BASE].dentry;
35264 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35265 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35267 + err = test_linkable(h_root);
35268 + if (unlikely(err)) {
35273 + err = au_whdir(h_dir, h_path);
35274 + if (unlikely(err))
35276 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35278 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35279 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35280 + err = au_whdir(h_dir, h_path);
35281 + if (unlikely(err))
35283 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35290 + * for the moment, aufs supports the branch filesystem which does not support
35291 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35292 + * copyup failed. finally, such filesystem will not be used as the writable
35295 + * returns tri-state, see above.
35297 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35298 + int do_plink, struct au_wh_base base[],
35299 + struct path *h_path)
35302 + struct inode *h_dir;
35304 + WbrWhMustWriteLock(wbr);
35306 + err = test_linkable(h_root);
35307 + if (unlikely(err)) {
35313 + * todo: should this create be done in /sbin/mount.aufs helper?
35316 + h_dir = d_inode(h_root);
35317 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35318 + h_path->dentry = base[AuBrWh_BASE].dentry;
35319 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35320 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35323 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35324 + if (unlikely(err))
35327 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35329 + err = au_whdir(h_dir, h_path);
35330 + if (unlikely(err))
35332 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35334 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35335 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35337 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35338 + err = au_whdir(h_dir, h_path);
35339 + if (unlikely(err))
35341 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35348 + * initialize the whiteout base file/dir for @br.
35350 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35353 + const unsigned char do_plink
35354 + = !!au_opt_test(au_mntflags(sb), PLINK);
35355 + struct inode *h_dir;
35356 + struct path path = br->br_path;
35357 + struct dentry *h_root = path.dentry;
35358 + struct au_wbr *wbr = br->br_wbr;
35359 + static const struct qstr base_name[] = {
35360 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35361 + sizeof(AUFS_BASE_NAME) - 1),
35362 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35363 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35364 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35365 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35367 + struct au_wh_base base[] = {
35368 + [AuBrWh_BASE] = {
35369 + .name = base_name + AuBrWh_BASE,
35372 + [AuBrWh_PLINK] = {
35373 + .name = base_name + AuBrWh_PLINK,
35376 + [AuBrWh_ORPH] = {
35377 + .name = base_name + AuBrWh_ORPH,
35383 + WbrWhMustWriteLock(wbr);
35385 + for (i = 0; i < AuBrWh_Last; i++) {
35386 + /* doubly whiteouted */
35387 + struct dentry *d;
35389 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35390 + err = PTR_ERR(d);
35394 + base[i].dentry = d;
35396 + && wbr->wbr_wh[i]
35397 + && wbr->wbr_wh[i] != base[i].dentry);
35401 + for (i = 0; i < AuBrWh_Last; i++) {
35402 + dput(wbr->wbr_wh[i]);
35403 + wbr->wbr_wh[i] = NULL;
35407 + if (!au_br_writable(br->br_perm)) {
35408 + h_dir = d_inode(h_root);
35409 + au_wh_init_ro(h_dir, base, &path);
35410 + } else if (!au_br_wh_linkable(br->br_perm)) {
35411 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35417 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35423 + goto out; /* success */
35426 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35427 + err, h_root, au_sbtype(h_root->d_sb));
35429 + for (i = 0; i < AuBrWh_Last; i++)
35430 + dput(base[i].dentry);
35434 +/* ---------------------------------------------------------------------- */
35436 + * whiteouts are all hard-linked usually.
35437 + * when its link count reaches a ceiling, we create a new whiteout base
35438 + * asynchronously.
35441 +struct reinit_br_wh {
35442 + struct super_block *sb;
35443 + struct au_branch *br;
35446 +static void reinit_br_wh(void *arg)
35449 + aufs_bindex_t bindex;
35450 + struct path h_path;
35451 + struct reinit_br_wh *a = arg;
35452 + struct au_wbr *wbr;
35453 + struct inode *dir, *delegated;
35454 + struct dentry *h_root;
35455 + struct au_hinode *hdir;
35458 + wbr = a->br->br_wbr;
35459 + /* big aufs lock */
35460 + si_noflush_write_lock(a->sb);
35461 + if (!au_br_writable(a->br->br_perm))
35463 + bindex = au_br_index(a->sb, a->br->br_id);
35464 + if (unlikely(bindex < 0))
35467 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35468 + dir = d_inode(a->sb->s_root);
35469 + hdir = au_hi(dir, bindex);
35470 + h_root = au_h_dptr(a->sb->s_root, bindex);
35471 + AuDebugOn(h_root != au_br_dentry(a->br));
35473 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35474 + wbr_wh_write_lock(wbr);
35475 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35478 + h_path.dentry = wbr->wbr_whbase;
35479 + h_path.mnt = au_br_mnt(a->br);
35480 + delegated = NULL;
35481 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35483 + if (unlikely(err == -EWOULDBLOCK)) {
35484 + pr_warn("cannot retry for NFSv4 delegation"
35485 + " for an internal unlink\n");
35489 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35492 + dput(wbr->wbr_whbase);
35493 + wbr->wbr_whbase = NULL;
35495 + err = au_wh_init(a->br, a->sb);
35496 + wbr_wh_write_unlock(wbr);
35497 + au_hn_inode_unlock(hdir);
35498 + di_read_unlock(a->sb->s_root, AuLock_IR);
35500 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35504 + atomic_dec(&wbr->wbr_wh_running);
35505 + au_lcnt_dec(&a->br->br_count);
35506 + si_write_unlock(a->sb);
35507 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35509 + if (unlikely(err))
35510 + AuIOErr("err %d\n", err);
35513 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35515 + int do_dec, wkq_err;
35516 + struct reinit_br_wh *arg;
35519 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35522 + /* ignore ENOMEM */
35523 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35526 + * dec(wh_running), kfree(arg) and dec(br_count)
35527 + * in reinit function
35531 + au_lcnt_inc(&br->br_count);
35532 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35533 + if (unlikely(wkq_err)) {
35534 + atomic_dec(&br->br_wbr->wbr_wh_running);
35535 + au_lcnt_dec(&br->br_count);
35536 + au_kfree_rcu(arg);
35543 + atomic_dec(&br->br_wbr->wbr_wh_running);
35546 +/* ---------------------------------------------------------------------- */
35549 + * create the whiteout @wh.
35551 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35552 + struct dentry *wh)
35555 + struct path h_path = {
35558 + struct au_branch *br;
35559 + struct au_wbr *wbr;
35560 + struct dentry *h_parent;
35561 + struct inode *h_dir, *delegated;
35563 + h_parent = wh->d_parent; /* dir inode is locked */
35564 + h_dir = d_inode(h_parent);
35565 + IMustLock(h_dir);
35567 + br = au_sbr(sb, bindex);
35568 + h_path.mnt = au_br_mnt(br);
35569 + wbr = br->br_wbr;
35570 + wbr_wh_read_lock(wbr);
35571 + if (wbr->wbr_whbase) {
35572 + delegated = NULL;
35573 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35574 + if (unlikely(err == -EWOULDBLOCK)) {
35575 + pr_warn("cannot retry for NFSv4 delegation"
35576 + " for an internal link\n");
35579 + if (!err || err != -EMLINK)
35582 + /* link count full. re-initialize br_whbase. */
35583 + kick_reinit_br_wh(sb, br);
35586 + /* return this error in this context */
35587 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35589 + au_fhsm_wrote(sb, bindex, /*force*/0);
35592 + wbr_wh_read_unlock(wbr);
35596 +/* ---------------------------------------------------------------------- */
35599 + * create or remove the diropq.
35601 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35602 + unsigned int flags)
35604 + struct dentry *opq_dentry, *h_dentry;
35605 + struct super_block *sb;
35606 + struct au_branch *br;
35609 + sb = dentry->d_sb;
35610 + br = au_sbr(sb, bindex);
35611 + h_dentry = au_h_dptr(dentry, bindex);
35612 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35613 + if (IS_ERR(opq_dentry))
35616 + if (au_ftest_diropq(flags, CREATE)) {
35617 + err = link_or_create_wh(sb, bindex, opq_dentry);
35619 + au_set_dbdiropq(dentry, bindex);
35620 + goto out; /* success */
35623 + struct path tmp = {
35624 + .dentry = opq_dentry,
35625 + .mnt = au_br_mnt(br)
35627 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35629 + au_set_dbdiropq(dentry, -1);
35631 + dput(opq_dentry);
35632 + opq_dentry = ERR_PTR(err);
35635 + return opq_dentry;
35638 +struct do_diropq_args {
35639 + struct dentry **errp;
35640 + struct dentry *dentry;
35641 + aufs_bindex_t bindex;
35642 + unsigned int flags;
35645 +static void call_do_diropq(void *args)
35647 + struct do_diropq_args *a = args;
35648 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35651 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35652 + unsigned int flags)
35654 + struct dentry *diropq, *h_dentry;
35656 + h_dentry = au_h_dptr(dentry, bindex);
35657 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35658 + diropq = do_diropq(dentry, bindex, flags);
35661 + struct do_diropq_args args = {
35663 + .dentry = dentry,
35664 + .bindex = bindex,
35668 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35669 + if (unlikely(wkq_err))
35670 + diropq = ERR_PTR(wkq_err);
35676 +/* ---------------------------------------------------------------------- */
35679 + * lookup whiteout dentry.
35680 + * @h_parent: lower parent dentry which must exist and be locked
35681 + * @base_name: name of dentry which will be whiteouted
35682 + * returns dentry for whiteout.
35684 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35685 + struct au_branch *br)
35688 + struct qstr wh_name;
35689 + struct dentry *wh_dentry;
35691 + err = au_wh_name_alloc(&wh_name, base_name);
35692 + wh_dentry = ERR_PTR(err);
35694 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35695 + au_kfree_try_rcu(wh_name.name);
35697 + return wh_dentry;
35701 + * link/create a whiteout for @dentry on @bindex.
35703 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35704 + struct dentry *h_parent)
35706 + struct dentry *wh_dentry;
35707 + struct super_block *sb;
35710 + sb = dentry->d_sb;
35711 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35712 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35713 + err = link_or_create_wh(sb, bindex, wh_dentry);
35715 + au_set_dbwh(dentry, bindex);
35716 + au_fhsm_wrote(sb, bindex, /*force*/0);
35719 + wh_dentry = ERR_PTR(err);
35723 + return wh_dentry;
35726 +/* ---------------------------------------------------------------------- */
35728 +/* Delete all whiteouts in this directory on branch bindex. */
35729 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35730 + aufs_bindex_t bindex, struct au_branch *br)
35733 + unsigned long ul, n;
35734 + struct qstr wh_name;
35736 + struct hlist_head *head;
35737 + struct au_vdir_wh *pos;
35738 + struct au_vdir_destr *str;
35741 + p = (void *)__get_free_page(GFP_NOFS);
35742 + wh_name.name = p;
35743 + if (unlikely(!wh_name.name))
35747 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35748 + p += AUFS_WH_PFX_LEN;
35749 + n = whlist->nh_num;
35750 + head = whlist->nh_head;
35751 + for (ul = 0; !err && ul < n; ul++, head++) {
35752 + hlist_for_each_entry(pos, head, wh_hash) {
35753 + if (pos->wh_bindex != bindex)
35756 + str = &pos->wh_str;
35757 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35758 + memcpy(p, str->name, str->len);
35759 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35760 + err = unlink_wh_name(h_dentry, &wh_name, br);
35765 + AuIOErr("whiteout name too long %.*s\n",
35766 + str->len, str->name);
35771 + free_page((unsigned long)wh_name.name);
35777 +struct del_wh_children_args {
35779 + struct dentry *h_dentry;
35780 + struct au_nhash *whlist;
35781 + aufs_bindex_t bindex;
35782 + struct au_branch *br;
35785 +static void call_del_wh_children(void *args)
35787 + struct del_wh_children_args *a = args;
35788 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35791 +/* ---------------------------------------------------------------------- */
35793 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35795 + struct au_whtmp_rmdir *whtmp;
35797 + unsigned int rdhash;
35799 + SiMustAnyLock(sb);
35801 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35802 + if (unlikely(!whtmp)) {
35803 + whtmp = ERR_PTR(-ENOMEM);
35807 + /* no estimation for dir size */
35808 + rdhash = au_sbi(sb)->si_rdhash;
35810 + rdhash = AUFS_RDHASH_DEF;
35811 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35812 + if (unlikely(err)) {
35813 + au_kfree_rcu(whtmp);
35814 + whtmp = ERR_PTR(err);
35821 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35824 + au_lcnt_dec(&whtmp->br->br_count);
35825 + dput(whtmp->wh_dentry);
35826 + iput(whtmp->dir);
35827 + au_nhash_wh_free(&whtmp->whlist);
35828 + au_kfree_rcu(whtmp);
35832 + * rmdir the whiteouted temporary named dir @h_dentry.
35833 + * @whlist: whiteouted children.
35835 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35836 + struct dentry *wh_dentry, struct au_nhash *whlist)
35839 + unsigned int h_nlink;
35840 + struct path h_tmp;
35841 + struct inode *wh_inode, *h_dir;
35842 + struct au_branch *br;
35844 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35845 + IMustLock(h_dir);
35847 + br = au_sbr(dir->i_sb, bindex);
35848 + wh_inode = d_inode(wh_dentry);
35849 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35852 + * someone else might change some whiteouts while we were sleeping.
35853 + * it means this whlist may have an obsoleted entry.
35855 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35856 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35859 + struct del_wh_children_args args = {
35861 + .h_dentry = wh_dentry,
35862 + .whlist = whlist,
35863 + .bindex = bindex,
35867 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35868 + if (unlikely(wkq_err))
35871 + inode_unlock(wh_inode);
35874 + h_tmp.dentry = wh_dentry;
35875 + h_tmp.mnt = au_br_mnt(br);
35876 + h_nlink = h_dir->i_nlink;
35877 + err = vfsub_rmdir(h_dir, &h_tmp);
35878 + /* some fs doesn't change the parent nlink in some cases */
35879 + h_nlink -= h_dir->i_nlink;
35883 + if (au_ibtop(dir) == bindex) {
35884 + /* todo: dir->i_mutex is necessary */
35885 + au_cpup_attr_timesizes(dir);
35887 + vfsub_drop_nlink(dir);
35889 + return 0; /* success */
35892 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35896 +static void call_rmdir_whtmp(void *args)
35899 + aufs_bindex_t bindex;
35900 + struct au_whtmp_rmdir *a = args;
35901 + struct super_block *sb;
35902 + struct dentry *h_parent;
35903 + struct inode *h_dir;
35904 + struct au_hinode *hdir;
35906 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35907 + /* inode_lock(a->dir); */
35909 + sb = a->dir->i_sb;
35910 + si_read_lock(sb, !AuLock_FLUSH);
35911 + if (!au_br_writable(a->br->br_perm))
35913 + bindex = au_br_index(sb, a->br->br_id);
35914 + if (unlikely(bindex < 0))
35918 + ii_write_lock_parent(a->dir);
35919 + h_parent = dget_parent(a->wh_dentry);
35920 + h_dir = d_inode(h_parent);
35921 + hdir = au_hi(a->dir, bindex);
35922 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35923 + if (unlikely(err))
35925 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35926 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35929 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35930 + au_hn_inode_unlock(hdir);
35931 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35935 + ii_write_unlock(a->dir);
35937 + /* inode_unlock(a->dir); */
35938 + au_whtmp_rmdir_free(a);
35939 + si_read_unlock(sb);
35940 + au_nwt_done(&au_sbi(sb)->si_nowait);
35941 + if (unlikely(err))
35942 + AuIOErr("err %d\n", err);
35945 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35946 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35949 + struct super_block *sb;
35953 + /* all post-process will be done in do_rmdir_whtmp(). */
35955 + args->dir = au_igrab(dir);
35956 + args->br = au_sbr(sb, bindex);
35957 + au_lcnt_inc(&args->br->br_count);
35958 + args->wh_dentry = dget(wh_dentry);
35959 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35960 + if (unlikely(wkq_err)) {
35961 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35962 + au_whtmp_rmdir_free(args);
35965 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35966 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35967 +++ linux/fs/aufs/whout.h 2019-07-11 15:42:14.475571481 +0200
35969 +/* SPDX-License-Identifier: GPL-2.0 */
35971 + * Copyright (C) 2005-2019 Junjiro R. Okajima
35973 + * This program, aufs is free software; you can redistribute it and/or modify
35974 + * it under the terms of the GNU General Public License as published by
35975 + * the Free Software Foundation; either version 2 of the License, or
35976 + * (at your option) any later version.
35978 + * This program is distributed in the hope that it will be useful,
35979 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35980 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35981 + * GNU General Public License for more details.
35983 + * You should have received a copy of the GNU General Public License
35984 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35988 + * whiteout for logical deletion and opaque directory
35991 +#ifndef __AUFS_WHOUT_H__
35992 +#define __AUFS_WHOUT_H__
35999 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36000 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
36001 +int au_diropq_test(struct dentry *h_dentry);
36003 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36004 + struct qstr *prefix);
36005 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36006 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36007 + struct dentry *dentry);
36008 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36010 +/* diropq flags */
36011 +#define AuDiropq_CREATE 1
36012 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36013 +#define au_fset_diropq(flags, name) \
36014 + do { (flags) |= AuDiropq_##name; } while (0)
36015 +#define au_fclr_diropq(flags, name) \
36016 + do { (flags) &= ~AuDiropq_##name; } while (0)
36018 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36019 + unsigned int flags);
36020 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36021 + struct au_branch *br);
36022 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36023 + struct dentry *h_parent);
36025 +/* real rmdir for the whiteout-ed dir */
36026 +struct au_whtmp_rmdir {
36027 + struct inode *dir;
36028 + struct au_branch *br;
36029 + struct dentry *wh_dentry;
36030 + struct au_nhash whlist;
36033 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36034 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36035 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36036 + struct dentry *wh_dentry, struct au_nhash *whlist);
36037 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36038 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36040 +/* ---------------------------------------------------------------------- */
36042 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36043 + aufs_bindex_t bindex)
36045 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36048 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36050 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36053 +#endif /* __KERNEL__ */
36054 +#endif /* __AUFS_WHOUT_H__ */
36055 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36056 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36057 +++ linux/fs/aufs/wkq.c 2019-07-11 15:42:14.475571481 +0200
36059 +// SPDX-License-Identifier: GPL-2.0
36061 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36063 + * This program, aufs is free software; you can redistribute it and/or modify
36064 + * it under the terms of the GNU General Public License as published by
36065 + * the Free Software Foundation; either version 2 of the License, or
36066 + * (at your option) any later version.
36068 + * This program is distributed in the hope that it will be useful,
36069 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36070 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36071 + * GNU General Public License for more details.
36073 + * You should have received a copy of the GNU General Public License
36074 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36078 + * workqueue for asynchronous/super-io operations
36079 + * todo: try new credential scheme
36082 +#include <linux/module.h>
36085 +/* internal workqueue named AUFS_WKQ_NAME */
36087 +static struct workqueue_struct *au_wkq;
36089 +struct au_wkinfo {
36090 + struct work_struct wk;
36091 + struct kobject *kobj;
36093 + unsigned int flags; /* see wkq.h */
36095 + au_wkq_func_t func;
36098 +#ifdef CONFIG_LOCKDEP
36100 + struct held_lock **hlock;
36103 + struct completion *comp;
36106 +/* ---------------------------------------------------------------------- */
36108 + * Aufs passes some operations to the workqueue such as the internal copyup.
36109 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36110 + * job run by workqueue depends upon the locks acquired in the other task.
36111 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36112 + * information too. And the job in the workqueue restores the info in order to
36113 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36114 + * correctly and expectedly.
36117 +#ifndef CONFIG_LOCKDEP
36118 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36119 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36120 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36121 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36122 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36124 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36126 + wkinfo->hlock = NULL;
36127 + wkinfo->dont_check = 0;
36134 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36136 + static DEFINE_SPINLOCK(spin);
36139 + struct lock_class_key *key;
36141 + { .name = "&sbinfo->si_rwsem" },
36142 + { .name = "&finfo->fi_rwsem" },
36143 + { .name = "&dinfo->di_rwsem" },
36144 + { .name = "&iinfo->ii_rwsem" }
36149 + /* lockless read from 'set.' see below */
36150 + if (set == ARRAY_SIZE(a)) {
36151 + for (i = 0; i < ARRAY_SIZE(a); i++)
36152 + if (a[i].key == key)
36157 + spin_lock(&spin);
36159 + for (i = 0; i < ARRAY_SIZE(a); i++)
36160 + if (a[i].key == key) {
36161 + spin_unlock(&spin);
36164 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36166 + if (unlikely(a[i].key == key)) { /* rare but possible */
36167 + spin_unlock(&spin);
36172 + if (strstr(a[i].name, name)) {
36174 + * the order of these three lines is important for the
36175 + * lockless read above.
36178 + spin_unlock(&spin);
36180 + /* AuDbg("%d, %s\n", set, name); */
36184 + spin_unlock(&spin);
36193 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36196 + struct task_struct *curr;
36197 + struct held_lock **hl, *held_locks, *p;
36201 + wkinfo->dont_check = lockdep_recursing(curr);
36202 + if (wkinfo->dont_check)
36204 + n = curr->lockdep_depth;
36209 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36210 + if (unlikely(!wkinfo->hlock))
36215 + if (0 && au_debug_test()) /* left for debugging */
36216 + lockdep_print_held_locks(curr);
36218 + held_locks = curr->held_locks;
36219 + hl = wkinfo->hlock;
36221 + p = held_locks++;
36222 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36231 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36233 + au_kfree_try_rcu(wkinfo->hlock);
36236 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36238 + struct held_lock *p, **hl = wkinfo->hlock;
36241 + if (wkinfo->dont_check)
36245 + while ((p = *hl++)) { /* assignment */
36246 + subclass = lockdep_hlock_class(p)->subclass;
36247 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36249 + rwsem_acquire_read(p->instance, subclass, 0,
36250 + /*p->acquire_ip*/_RET_IP_);
36252 + rwsem_acquire(p->instance, subclass, 0,
36253 + /*p->acquire_ip*/_RET_IP_);
36257 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36259 + struct held_lock *p, **hl = wkinfo->hlock;
36261 + if (wkinfo->dont_check)
36265 + while ((p = *hl++)) /* assignment */
36266 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36270 +static void wkq_func(struct work_struct *wk)
36272 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36274 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36275 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36277 + au_wkq_lockdep_pre(wkinfo);
36278 + wkinfo->func(wkinfo->args);
36279 + au_wkq_lockdep_post(wkinfo);
36280 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36281 + complete(wkinfo->comp);
36283 + kobject_put(wkinfo->kobj);
36284 + module_put(THIS_MODULE); /* todo: ?? */
36285 + au_kfree_rcu(wkinfo);
36290 + * Since struct completion is large, try allocating it dynamically.
36292 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36293 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36295 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36297 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36299 + init_completion(*comp);
36300 + wkinfo->comp = *comp;
36306 +static void au_wkq_comp_free(struct completion *comp)
36308 + au_kfree_rcu(comp);
36314 +#define AuWkqCompDeclare(name) \
36315 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36316 + struct completion *comp = &_ ## name
36318 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36320 + wkinfo->comp = *comp;
36324 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36328 +#endif /* 4KSTACKS */
36330 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36332 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36333 + if (au_wkq_test()) {
36334 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36335 + " due to a dead dir by UDBA,"
36336 + " or async xino write?\n");
36337 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36340 + au_dbg_verify_kthread();
36342 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36343 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36344 + queue_work(au_wkq, &wkinfo->wk);
36346 + INIT_WORK(&wkinfo->wk, wkq_func);
36347 + schedule_work(&wkinfo->wk);
36352 + * Be careful. It is easy to make deadlock happen.
36353 + * processA: lock, wkq and wait
36354 + * processB: wkq and wait, lock in wkq
36357 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36360 + AuWkqCompDeclare(comp);
36361 + struct au_wkinfo wkinfo = {
36367 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36368 + if (unlikely(err))
36370 + err = au_wkq_lockdep_alloc(&wkinfo);
36371 + if (unlikely(err))
36374 + au_wkq_run(&wkinfo);
36375 + /* no timeout, no interrupt */
36376 + wait_for_completion(wkinfo.comp);
36378 + au_wkq_lockdep_free(&wkinfo);
36381 + au_wkq_comp_free(comp);
36383 + destroy_work_on_stack(&wkinfo.wk);
36388 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36389 + * problem in a concurrent umounting.
36391 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36392 + unsigned int flags)
36395 + struct au_wkinfo *wkinfo;
36397 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36400 + * wkq_func() must free this wkinfo.
36401 + * it highly depends upon the implementation of workqueue.
36404 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36406 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36407 + wkinfo->flags = flags & ~AuWkq_WAIT;
36408 + wkinfo->func = func;
36409 + wkinfo->args = args;
36410 + wkinfo->comp = NULL;
36411 + au_wkq_lockdep_init(wkinfo);
36412 + kobject_get(wkinfo->kobj);
36413 + __module_get(THIS_MODULE); /* todo: ?? */
36415 + au_wkq_run(wkinfo);
36418 + au_nwt_done(&au_sbi(sb)->si_nowait);
36424 +/* ---------------------------------------------------------------------- */
36426 +void au_nwt_init(struct au_nowait_tasks *nwt)
36428 + atomic_set(&nwt->nw_len, 0);
36429 + /* smp_mb(); */ /* atomic_set */
36430 + init_waitqueue_head(&nwt->nw_wq);
36433 +void au_wkq_fin(void)
36435 + destroy_workqueue(au_wkq);
36438 +int __init au_wkq_init(void)
36443 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36444 + if (IS_ERR(au_wkq))
36445 + err = PTR_ERR(au_wkq);
36446 + else if (!au_wkq)
36451 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36452 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36453 +++ linux/fs/aufs/wkq.h 2019-07-11 15:42:14.475571481 +0200
36455 +/* SPDX-License-Identifier: GPL-2.0 */
36457 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36459 + * This program, aufs is free software; you can redistribute it and/or modify
36460 + * it under the terms of the GNU General Public License as published by
36461 + * the Free Software Foundation; either version 2 of the License, or
36462 + * (at your option) any later version.
36464 + * This program is distributed in the hope that it will be useful,
36465 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36466 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36467 + * GNU General Public License for more details.
36469 + * You should have received a copy of the GNU General Public License
36470 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36474 + * workqueue for asynchronous/super-io operations
36475 + * todo: try new credentials management scheme
36478 +#ifndef __AUFS_WKQ_H__
36479 +#define __AUFS_WKQ_H__
36483 +#include <linux/wait.h>
36485 +struct super_block;
36487 +/* ---------------------------------------------------------------------- */
36490 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36492 +struct au_nowait_tasks {
36494 + wait_queue_head_t nw_wq;
36497 +/* ---------------------------------------------------------------------- */
36499 +typedef void (*au_wkq_func_t)(void *args);
36502 +#define AuWkq_WAIT 1
36503 +#define AuWkq_NEST (1 << 1)
36504 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36505 +#define au_fset_wkq(flags, name) \
36506 + do { (flags) |= AuWkq_##name; } while (0)
36507 +#define au_fclr_wkq(flags, name) \
36508 + do { (flags) &= ~AuWkq_##name; } while (0)
36511 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36512 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36513 + unsigned int flags);
36514 +void au_nwt_init(struct au_nowait_tasks *nwt);
36515 +int __init au_wkq_init(void);
36516 +void au_wkq_fin(void);
36518 +/* ---------------------------------------------------------------------- */
36520 +static inline int au_wkq_test(void)
36522 + return current->flags & PF_WQ_WORKER;
36525 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36527 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36530 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36532 + if (atomic_dec_and_test(&nwt->nw_len))
36533 + wake_up_all(&nwt->nw_wq);
36536 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36538 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36542 +#endif /* __KERNEL__ */
36543 +#endif /* __AUFS_WKQ_H__ */
36544 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36545 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36546 +++ linux/fs/aufs/xattr.c 2019-07-11 15:42:14.475571481 +0200
36548 +// SPDX-License-Identifier: GPL-2.0
36550 + * Copyright (C) 2014-2019 Junjiro R. Okajima
36552 + * This program, aufs is free software; you can redistribute it and/or modify
36553 + * it under the terms of the GNU General Public License as published by
36554 + * the Free Software Foundation; either version 2 of the License, or
36555 + * (at your option) any later version.
36557 + * This program is distributed in the hope that it will be useful,
36558 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36559 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36560 + * GNU General Public License for more details.
36562 + * You should have received a copy of the GNU General Public License
36563 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36567 + * handling xattr functions
36570 +#include <linux/fs.h>
36571 +#include <linux/posix_acl_xattr.h>
36572 +#include <linux/xattr.h>
36575 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36577 + if (!ignore_flags)
36585 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36590 +#define cmp(brattr, prefix) do { \
36591 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36592 + XATTR_##prefix##_PREFIX_LEN)) { \
36593 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36599 + cmp(SEC, SECURITY);
36600 + cmp(SYS, SYSTEM);
36601 + cmp(TR, TRUSTED);
36605 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36612 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36614 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36615 + char *name, char **buf, unsigned int ignore_flags,
36616 + unsigned int verbose)
36620 + struct inode *h_idst;
36622 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36624 + if (unlikely(err <= 0)) {
36625 + if (err == -ENODATA
36626 + || (err == -EOPNOTSUPP
36627 + && ((ignore_flags & au_xattr_out_of_list)
36628 + || (au_test_nfs_noacl(d_inode(h_src))
36629 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36631 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36634 + if (err && (verbose || au_debug_test()))
36635 + pr_err("%s, err %d\n", name, err);
36639 + /* unlock it temporary */
36640 + h_idst = d_inode(h_dst);
36641 + inode_unlock(h_idst);
36642 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36643 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36644 + if (unlikely(err)) {
36645 + if (verbose || au_debug_test())
36646 + pr_err("%s, err %d\n", name, err);
36647 + err = au_xattr_ignore(err, name, ignore_flags);
36654 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36655 + unsigned int verbose)
36657 + int err, unlocked, acl_access, acl_default;
36659 + struct inode *h_isrc, *h_idst;
36660 + char *value, *p, *o, *e;
36662 + /* try stopping to update the source inode while we are referencing */
36663 + /* there should not be the parent-child relationship between them */
36664 + h_isrc = d_inode(h_src);
36665 + h_idst = d_inode(h_dst);
36666 + inode_unlock(h_idst);
36667 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36668 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36671 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36672 + ssz = vfs_listxattr(h_src, NULL, 0);
36674 + if (unlikely(err < 0)) {
36676 + if (err == -ENODATA
36677 + || err == -EOPNOTSUPP)
36678 + err = 0; /* ignore */
36687 + p = kmalloc(ssz, GFP_NOFS);
36689 + if (unlikely(!p))
36691 + err = vfs_listxattr(h_src, p, ssz);
36693 + inode_unlock_shared(h_isrc);
36695 + AuDbg("err %d, ssz %zd\n", err, ssz);
36696 + if (unlikely(err < 0))
36704 + while (!err && p < e) {
36705 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36706 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36707 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36708 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36710 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36712 + p += strlen(p) + 1;
36715 + ignore_flags |= au_xattr_out_of_list;
36716 + if (!err && !acl_access) {
36717 + err = au_do_cpup_xattr(h_dst, h_src,
36718 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36719 + ignore_flags, verbose);
36722 + if (!err && !acl_default) {
36723 + err = au_do_cpup_xattr(h_dst, h_src,
36724 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36725 + ignore_flags, verbose);
36729 + au_kfree_try_rcu(value);
36732 + au_kfree_try_rcu(o);
36735 + inode_unlock_shared(h_isrc);
36740 +/* ---------------------------------------------------------------------- */
36742 +static int au_smack_reentering(struct super_block *sb)
36744 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36746 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36747 + * i_op->getxattr(). ouch.
36749 + return si_pid_test(sb);
36760 +struct au_lgxattr {
36768 + const char *name;
36775 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36779 + struct path h_path;
36780 + struct super_block *sb;
36782 + sb = dentry->d_sb;
36783 + reenter = au_smack_reentering(sb);
36785 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36786 + if (unlikely(err))
36789 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36790 + if (unlikely(err))
36792 + if (unlikely(!h_path.dentry))
36793 + /* illegally overlapped or something */
36794 + goto out_di; /* pretending success */
36796 + /* always topmost entry only */
36797 + switch (arg->type) {
36798 + case AU_XATTR_LIST:
36799 + err = vfs_listxattr(h_path.dentry,
36800 + arg->u.list.list, arg->u.list.size);
36802 + case AU_XATTR_GET:
36803 + AuDebugOn(d_is_negative(h_path.dentry));
36804 + err = vfs_getxattr(h_path.dentry,
36805 + arg->u.get.name, arg->u.get.value,
36806 + arg->u.get.size);
36812 + di_read_unlock(dentry, AuLock_IR);
36815 + si_read_unlock(sb);
36821 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36823 + struct au_lgxattr arg = {
36824 + .type = AU_XATTR_LIST,
36831 + return au_lgxattr(dentry, &arg);
36834 +static ssize_t au_getxattr(struct dentry *dentry,
36835 + struct inode *inode __maybe_unused,
36836 + const char *name, void *value, size_t size)
36838 + struct au_lgxattr arg = {
36839 + .type = AU_XATTR_GET,
36847 + return au_lgxattr(dentry, &arg);
36850 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36851 + const char *name, const void *value, size_t size,
36854 + struct au_sxattr arg = {
36855 + .type = AU_XATTR_SET,
36864 + return au_sxattr(dentry, inode, &arg);
36867 +/* ---------------------------------------------------------------------- */
36869 +static int au_xattr_get(const struct xattr_handler *handler,
36870 + struct dentry *dentry, struct inode *inode,
36871 + const char *name, void *buffer, size_t size)
36873 + return au_getxattr(dentry, inode, name, buffer, size);
36876 +static int au_xattr_set(const struct xattr_handler *handler,
36877 + struct dentry *dentry, struct inode *inode,
36878 + const char *name, const void *value, size_t size,
36881 + return au_setxattr(dentry, inode, name, value, size, flags);
36884 +static const struct xattr_handler au_xattr_handler = {
36887 + .get = au_xattr_get,
36888 + .set = au_xattr_set
36891 +static const struct xattr_handler *au_xattr_handlers[] = {
36892 +#ifdef CONFIG_FS_POSIX_ACL
36893 + &posix_acl_access_xattr_handler,
36894 + &posix_acl_default_xattr_handler,
36896 + &au_xattr_handler, /* must be last */
36900 +void au_xattr_init(struct super_block *sb)
36902 + sb->s_xattr = au_xattr_handlers;
36904 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36905 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36906 +++ linux/fs/aufs/xino.c 2019-07-11 15:42:14.475571481 +0200
36908 +// SPDX-License-Identifier: GPL-2.0
36910 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36912 + * This program, aufs is free software; you can redistribute it and/or modify
36913 + * it under the terms of the GNU General Public License as published by
36914 + * the Free Software Foundation; either version 2 of the License, or
36915 + * (at your option) any later version.
36917 + * This program is distributed in the hope that it will be useful,
36918 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36920 + * GNU General Public License for more details.
36922 + * You should have received a copy of the GNU General Public License
36923 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36927 + * external inode number translation table and bitmap
36929 + * things to consider
36931 + * + au_xino object
36932 + * + XINO files (xino, xib, xigen)
36933 + * + dynamic debugfs entries (xiN)
36934 + * + static debugfs entries (xib, xigen)
36935 + * + static sysfs entry (xi_path)
36936 + * - several entry points to handle them.
36937 + * + mount(2) without xino option (default)
36938 + * + mount(2) with xino option
36939 + * + mount(2) with noxino option
36941 + * + remount with add/del branches
36942 + * + remount with xino/noxino options
36945 +#include <linux/seq_file.h>
36946 +#include <linux/statfs.h>
36949 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36950 + aufs_bindex_t bbot,
36951 + struct super_block *h_sb)
36953 + /* todo: try binary-search if the branches are many */
36954 + for (; btop <= bbot; btop++)
36955 + if (h_sb == au_sbr_sb(sb, btop))
36961 + * find another branch who is on the same filesystem of the specified
36962 + * branch{@btgt}. search until @bbot.
36964 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36965 + aufs_bindex_t bbot)
36967 + aufs_bindex_t bindex;
36968 + struct super_block *tgt_sb;
36970 + tgt_sb = au_sbr_sb(sb, btgt);
36971 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36973 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36978 +/* ---------------------------------------------------------------------- */
36981 + * stop unnecessary notify events at creating xino files
36984 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36986 + aufs_bindex_t bfound, bindex, bbot;
36987 + struct dentry *parent;
36988 + struct au_branch *br;
36991 + parent = dentry->d_parent; /* safe d_parent access */
36992 + bbot = au_sbbot(sb);
36993 + for (bindex = 0; bindex <= bbot; bindex++) {
36994 + br = au_sbr(sb, bindex);
36995 + if (au_br_dentry(br) == parent) {
37001 + AuDbg("bfound b%d\n", bfound);
37005 +struct au_xino_lock_dir {
37006 + struct au_hinode *hdir;
37007 + struct dentry *parent;
37008 + struct inode *dir;
37011 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37012 + unsigned int lsc)
37014 + struct dentry *parent;
37015 + struct inode *dir;
37017 + parent = dget_parent(dentry);
37018 + dir = d_inode(parent);
37019 + inode_lock_nested(dir, lsc);
37020 +#if 0 /* it should not happen */
37021 + spin_lock(&dentry->d_lock);
37022 + if (unlikely(dentry->d_parent != parent)) {
37023 + spin_unlock(&dentry->d_lock);
37024 + inode_unlock(dir);
37029 + spin_unlock(&dentry->d_lock);
37036 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37037 + struct au_xino_lock_dir *ldir)
37039 + aufs_bindex_t bindex;
37041 + ldir->hdir = NULL;
37042 + bindex = au_xi_root(sb, xipath->dentry);
37043 + if (bindex >= 0) {
37044 + /* rw branch root */
37045 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37046 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37049 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37051 + ldir->dir = d_inode(ldir->parent);
37055 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37058 + au_hn_inode_unlock(ldir->hdir);
37060 + inode_unlock(ldir->dir);
37061 + dput(ldir->parent);
37065 +/* ---------------------------------------------------------------------- */
37068 + * create and set a new xino file
37070 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37073 + struct file *file;
37074 + struct dentry *h_parent, *d;
37075 + struct inode *h_dir, *inode;
37077 + static DEFINE_MUTEX(mtx);
37080 + * at mount-time, and the xino file is the default path,
37081 + * hnotify is disabled so we have no notify events to ignore.
37082 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37085 + mutex_lock(&mtx);
37086 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37087 + /* | __FMODE_NONOTIFY */,
37089 + if (IS_ERR(file)) {
37091 + mutex_unlock(&mtx);
37093 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37097 + /* keep file count */
37099 + d = file->f_path.dentry;
37100 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37102 + mutex_unlock(&mtx);
37103 + /* mnt_want_write() is unnecessary here */
37104 + h_dir = d_inode(h_parent);
37105 + inode = file_inode(file);
37106 + /* no delegation since it is just created */
37107 + if (inode->i_nlink)
37108 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37110 + inode_unlock(h_dir);
37112 + if (unlikely(err)) {
37114 + pr_err("unlink %s(%d)\n", fpath, err);
37119 + if (unlikely(sb == d->d_sb)) {
37121 + pr_err("%s must be outside\n", fpath);
37124 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37126 + pr_err("xino doesn't support %s(%s)\n",
37127 + fpath, au_sbtype(d->d_sb));
37130 + return file; /* success */
37134 + file = ERR_PTR(err);
37139 + * create a new xinofile at the same place/path as @base.
37141 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37142 + struct file *copy_src)
37144 + struct file *file;
37145 + struct dentry *dentry, *parent;
37146 + struct inode *dir, *delegated;
37147 + struct qstr *name;
37148 + struct path path;
37149 + int err, do_unlock;
37150 + struct au_xino_lock_dir ldir;
37153 + au_xino_lock_dir(sb, base, &ldir);
37154 + dentry = base->dentry;
37155 + parent = dentry->d_parent; /* dir inode is locked */
37156 + dir = d_inode(parent);
37159 + name = &dentry->d_name;
37160 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37161 + if (IS_ERR(path.dentry)) {
37162 + file = (void *)path.dentry;
37163 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37167 + /* no need to mnt_want_write() since we call dentry_open() later */
37168 + err = vfs_create(dir, path.dentry, 0666, NULL);
37169 + if (unlikely(err)) {
37170 + file = ERR_PTR(err);
37171 + pr_err("%pd create err %d\n", dentry, err);
37175 + path.mnt = base->mnt;
37176 + file = vfsub_dentry_open(&path,
37177 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37178 + /* | __FMODE_NONOTIFY */);
37179 + if (IS_ERR(file)) {
37180 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37184 + delegated = NULL;
37185 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37186 + au_xino_unlock_dir(&ldir);
37188 + if (unlikely(err == -EWOULDBLOCK)) {
37189 + pr_warn("cannot retry for NFSv4 delegation"
37190 + " for an internal unlink\n");
37193 + if (unlikely(err)) {
37194 + pr_err("%pd unlink err %d\n", dentry, err);
37199 + /* no one can touch copy_src xino */
37200 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37201 + if (unlikely(err)) {
37202 + pr_err("%pd copy err %d\n", dentry, err);
37206 + goto out_dput; /* success */
37210 + file = ERR_PTR(err);
37212 + dput(path.dentry);
37215 + au_xino_unlock_dir(&ldir);
37219 +struct file *au_xino_file1(struct au_xino *xi)
37221 + struct file *file;
37222 + unsigned int u, nfile;
37225 + nfile = xi->xi_nfile;
37226 + for (u = 0; u < nfile; u++) {
37227 + file = xi->xi_file[u];
37235 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37246 + if (idx < xi->xi_nfile) {
37247 + f = xi->xi_file[idx];
37251 + p = au_kzrealloc(xi->xi_file,
37252 + sizeof(*xi->xi_file) * xi->xi_nfile,
37253 + sizeof(*xi->xi_file) * (idx + 1),
37254 + GFP_NOFS, /*may_shrink*/0);
37256 + MtxMustLock(&xi->xi_mtx);
37258 + xi->xi_nfile = idx + 1;
37266 + xi->xi_file[idx] = file;
37273 + * if @xinew->xi is not set, then create new xigen file.
37275 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37277 + struct file *file;
37280 + SiMustAnyLock(sb);
37282 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37283 + if (IS_ERR(file)) {
37284 + err = PTR_ERR(file);
37285 + pr_err("%s[%d], err %d\n",
37286 + xinew->xi ? "xino" : "xigen",
37287 + xinew->idx, err);
37292 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37295 + /* todo: make xigen file an array */
37296 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37299 + if (unlikely(err))
37300 + file = ERR_PTR(err);
37306 +/* ---------------------------------------------------------------------- */
37309 + * truncate xino files
37311 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37312 + int idx, struct kstatfs *st)
37316 + struct file *file, *new_xino;
37317 + struct au_xi_new xinew = {
37322 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37323 + file = au_xino_file(xinew.xi, idx);
37327 + xinew.base = &file->f_path;
37328 + err = vfs_statfs(xinew.base, st);
37329 + if (unlikely(err)) {
37330 + AuErr1("statfs err %d, ignored\n", err);
37335 + blocks = file_inode(file)->i_blocks;
37336 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37337 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37339 + xinew.copy_src = file;
37340 + new_xino = au_xi_new(sb, &xinew);
37341 + if (IS_ERR(new_xino)) {
37342 + err = PTR_ERR(new_xino);
37343 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37347 + err = vfs_statfs(&new_xino->f_path, st);
37349 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37350 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37351 + st->f_bfree, st->f_blocks);
37353 + AuErr1("statfs err %d, ignored\n", err);
37361 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37364 + unsigned long jiffy;
37365 + aufs_bindex_t bbot;
37366 + struct kstatfs *st;
37367 + struct au_branch *br;
37368 + struct au_xino *xi;
37371 + st = kmalloc(sizeof(*st), GFP_NOFS);
37372 + if (unlikely(!st))
37376 + bbot = au_sbbot(sb);
37377 + if (unlikely(bindex < 0 || bbot < bindex))
37382 + br = au_sbr(sb, bindex);
37383 + xi = br->br_xino;
37384 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37385 + err = au_xino_do_trunc(sb, bindex, i, st);
37387 + au_sbi(sb)->si_xino_jiffy = jiffy;
37390 + au_kfree_rcu(st);
37395 +struct xino_do_trunc_args {
37396 + struct super_block *sb;
37397 + struct au_branch *br;
37401 +static void xino_do_trunc(void *_args)
37403 + struct xino_do_trunc_args *args = _args;
37404 + struct super_block *sb;
37405 + struct au_branch *br;
37406 + struct inode *dir;
37408 + aufs_bindex_t bindex;
37412 + dir = d_inode(sb->s_root);
37416 + si_noflush_write_lock(sb);
37417 + ii_read_lock_parent(dir);
37418 + bindex = au_br_index(sb, br->br_id);
37419 + err = au_xino_trunc(sb, bindex, idx);
37420 + ii_read_unlock(dir);
37421 + if (unlikely(err))
37422 + pr_warn("err b%d, (%d)\n", bindex, err);
37423 + atomic_dec(&br->br_xino->xi_truncating);
37424 + au_lcnt_dec(&br->br_count);
37425 + si_write_unlock(sb);
37426 + au_nwt_done(&au_sbi(sb)->si_nowait);
37427 + au_kfree_rcu(args);
37431 + * returns the index in the xi_file array whose corresponding file is necessary
37432 + * to truncate, or -1 which means no need to truncate.
37434 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37438 + struct kstatfs st;
37439 + struct au_sbinfo *sbinfo;
37440 + struct au_xino *xi;
37441 + struct file *file;
37443 + /* todo: si_xino_expire and the ratio should be customizable */
37444 + sbinfo = au_sbi(sb);
37445 + if (time_before(jiffies,
37446 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37449 + /* truncation border */
37450 + xi = br->br_xino;
37451 + for (u = 0; u < xi->xi_nfile; u++) {
37452 + file = au_xino_file(xi, u);
37456 + err = vfs_statfs(&file->f_path, &st);
37457 + if (unlikely(err)) {
37458 + AuErr1("statfs err %d, ignored\n", err);
37461 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37462 + >= AUFS_XINO_DEF_TRUNC)
37469 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37472 + struct xino_do_trunc_args *args;
37475 + idx = xino_trunc_test(sb, br);
37479 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37482 + /* lock and kfree() will be called in trunc_xino() */
37483 + args = kmalloc(sizeof(*args), GFP_NOFS);
37484 + if (unlikely(!args)) {
37485 + AuErr1("no memory\n");
37489 + au_lcnt_inc(&br->br_count);
37493 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37495 + return; /* success */
37497 + pr_err("wkq %d\n", wkq_err);
37498 + au_lcnt_dec(&br->br_count);
37499 + au_kfree_rcu(args);
37502 + atomic_dec(&br->br_xino->xi_truncating);
37505 +/* ---------------------------------------------------------------------- */
37507 +struct au_xi_calc {
37512 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37513 + struct au_xi_calc *calc)
37517 + maxent = au_xi_maxent(sb);
37518 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37519 + calc->pos *= sizeof(ino_t);
37522 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37523 + struct au_xi_calc *calc)
37526 + struct file *file;
37527 + struct au_xino *xi = br->br_xino;
37528 + struct au_xi_new xinew = {
37532 + SiMustAnyLock(sb);
37538 + mutex_lock(&xi->xi_mtx);
37539 + file = au_xino_file(xi, calc->idx);
37543 + file = au_xino_file(xi, /*idx*/-1);
37544 + AuDebugOn(!file);
37545 + xinew.idx = calc->idx;
37546 + xinew.base = &file->f_path;
37547 + /* xinew.copy_src = NULL; */
37548 + file = au_xi_new(sb, &xinew);
37549 + if (IS_ERR(file))
37550 + err = PTR_ERR(file);
37553 + mutex_unlock(&xi->xi_mtx);
37558 +struct au_xino_do_new_async_args {
37559 + struct super_block *sb;
37560 + struct au_branch *br;
37561 + struct au_xi_calc calc;
37565 +struct au_xi_writing {
37566 + struct hlist_bl_node node;
37567 + ino_t h_ino, ino;
37570 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37571 + struct au_xi_calc *calc, ino_t ino);
37573 +static void au_xino_call_do_new_async(void *args)
37575 + struct au_xino_do_new_async_args *a = args;
37576 + struct au_branch *br;
37577 + struct super_block *sb;
37578 + struct au_sbinfo *sbi;
37579 + struct inode *root;
37580 + struct file *file;
37581 + struct au_xi_writing *del, *p;
37582 + struct hlist_bl_head *hbl;
37583 + struct hlist_bl_node *pos;
37588 + sbi = au_sbi(sb);
37589 + si_noflush_read_lock(sb);
37590 + root = d_inode(sb->s_root);
37591 + ii_read_lock_child(root);
37592 + err = au_xino_do_new_async(sb, br, &a->calc);
37593 + if (unlikely(err)) {
37594 + AuIOErr("err %d\n", err);
37598 + file = au_xino_file(br->br_xino, a->calc.idx);
37599 + AuDebugOn(!file);
37600 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37601 + if (unlikely(err)) {
37602 + AuIOErr("err %d\n", err);
37607 + hbl = &br->br_xino->xi_writing;
37608 + hlist_bl_lock(hbl);
37609 + au_hbl_for_each(pos, hbl) {
37610 + p = container_of(pos, struct au_xi_writing, node);
37611 + if (p->ino == a->ino) {
37613 + hlist_bl_del(&p->node);
37617 + hlist_bl_unlock(hbl);
37618 + au_kfree_rcu(del);
37621 + au_lcnt_dec(&br->br_count);
37622 + ii_read_unlock(root);
37623 + si_read_unlock(sb);
37624 + au_nwt_done(&sbi->si_nowait);
37629 + * create a new xino file asynchronously
37631 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37632 + struct au_xi_calc *calc, ino_t ino)
37635 + struct au_xino_do_new_async_args *arg;
37638 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37639 + if (unlikely(!arg))
37644 + arg->calc = *calc;
37646 + au_lcnt_inc(&br->br_count);
37647 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37648 + if (unlikely(err)) {
37649 + pr_err("wkq %d\n", err);
37650 + au_lcnt_dec(&br->br_count);
37651 + au_kfree_rcu(arg);
37659 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37660 + * at the position of @h_ino.
37662 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37667 + struct au_xi_calc calc;
37668 + struct au_sbinfo *sbinfo;
37669 + struct file *file;
37670 + struct au_xino *xi;
37671 + struct hlist_bl_head *hbl;
37672 + struct hlist_bl_node *pos;
37673 + struct au_xi_writing *p;
37676 + if (!au_opt_test(au_mntflags(sb), XINO))
37677 + return 0; /* no xino */
37680 + au_xi_calc(sb, h_ino, &calc);
37681 + xi = au_sbr(sb, bindex)->br_xino;
37682 + file = au_xino_file(xi, calc.idx);
37684 + hbl = &xi->xi_writing;
37685 + hlist_bl_lock(hbl);
37686 + au_hbl_for_each(pos, hbl) {
37687 + p = container_of(pos, struct au_xi_writing, node);
37688 + if (p->h_ino == h_ino) {
37689 + AuDbg("hi%llu, i%llu, found\n",
37690 + (u64)p->h_ino, (u64)p->ino);
37695 + hlist_bl_unlock(hbl);
37697 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37698 + return 0; /* no xino */
37700 + sbinfo = au_sbi(sb);
37701 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37702 + if (sz == sizeof(*ino))
37703 + return 0; /* success */
37706 + if (unlikely(sz >= 0)) {
37708 + AuIOErr("xino read error (%zd)\n", sz);
37713 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37714 + struct au_xi_calc *calc, ino_t ino)
37718 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37719 + if (sz == sizeof(ino))
37720 + return 0; /* success */
37722 + AuIOErr("write failed (%zd)\n", sz);
37727 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37728 + * at the position of @h_ino.
37729 + * even if @ino is zero, it is written to the xinofile and means no entry.
37730 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37731 + * try truncating it.
37733 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37737 + unsigned int mnt_flags;
37738 + struct au_xi_calc calc;
37739 + struct file *file;
37740 + struct au_branch *br;
37741 + struct au_xino *xi;
37742 + struct au_xi_writing *p;
37744 + SiMustAnyLock(sb);
37746 + mnt_flags = au_mntflags(sb);
37747 + if (!au_opt_test(mnt_flags, XINO))
37750 + au_xi_calc(sb, h_ino, &calc);
37751 + br = au_sbr(sb, bindex);
37752 + xi = br->br_xino;
37753 + file = au_xino_file(xi, calc.idx);
37755 + /* store the inum pair into the list */
37756 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37757 + p->h_ino = h_ino;
37759 + au_hbl_add(&p->node, &xi->xi_writing);
37761 + /* create and write a new xino file asynchronously */
37762 + err = au_xino_new_async(sb, br, &calc, ino);
37764 + return 0; /* success */
37768 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37770 + br = au_sbr(sb, bindex);
37771 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37772 + && au_test_fs_trunc_xino(au_br_sb(br)))
37773 + xino_try_trunc(sb, br);
37774 + return 0; /* success */
37778 + AuIOErr("write failed (%d)\n", err);
37782 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37783 + size_t size, loff_t *pos);
37785 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37786 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37790 + mm_segment_t oldfs;
37796 + const int prevent_endless = 10;
37800 + oldfs = get_fs();
37801 + set_fs(KERNEL_DS);
37803 + err = func(file, buf.u, size, pos);
37804 + if (err == -EINTR
37805 + && !au_wkq_test()
37806 + && fatal_signal_pending(current)) {
37808 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37809 + BUG_ON(err == -EINTR);
37810 + oldfs = get_fs();
37811 + set_fs(KERNEL_DS);
37813 + } while (i++ < prevent_endless
37814 + && (err == -EAGAIN || err == -EINTR));
37817 +#if 0 /* reserved for future use */
37819 + fsnotify_access(file->f_path.dentry);
37825 +struct xino_fread_args {
37827 + vfs_readf_t func;
37828 + struct file *file;
37834 +static void call_xino_fread(void *args)
37836 + struct xino_fread_args *a = args;
37837 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37840 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37841 + size_t size, loff_t *pos)
37845 + struct xino_fread_args args = {
37854 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37855 + if (unlikely(wkq_err))
37861 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37862 + size_t size, loff_t *pos);
37864 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37865 + size_t size, loff_t *pos)
37868 + mm_segment_t oldfs;
37871 + const char __user *u;
37874 + const int prevent_endless = 10;
37878 + oldfs = get_fs();
37879 + set_fs(KERNEL_DS);
37881 + err = func(file, buf.u, size, pos);
37882 + if (err == -EINTR
37883 + && !au_wkq_test()
37884 + && fatal_signal_pending(current)) {
37886 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37887 + BUG_ON(err == -EINTR);
37888 + oldfs = get_fs();
37889 + set_fs(KERNEL_DS);
37891 + } while (i++ < prevent_endless
37892 + && (err == -EAGAIN || err == -EINTR));
37895 +#if 0 /* reserved for future use */
37897 + fsnotify_modify(file->f_path.dentry);
37903 +struct do_xino_fwrite_args {
37905 + vfs_writef_t func;
37906 + struct file *file;
37912 +static void call_do_xino_fwrite(void *args)
37914 + struct do_xino_fwrite_args *a = args;
37915 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37918 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37919 + size_t size, loff_t *pos)
37923 + struct do_xino_fwrite_args args = {
37933 + * it breaks RLIMIT_FSIZE and normal user's limit,
37934 + * users should care about quota and real 'filesystem full.'
37936 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37937 + if (unlikely(wkq_err))
37943 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37944 + size_t size, loff_t *pos)
37948 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37950 + err = do_xino_fwrite(func, file, buf, size, pos);
37954 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37961 +/* ---------------------------------------------------------------------- */
37964 + * inode number bitmap
37966 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37967 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37971 + AuDebugOn(bit < 0 || page_bits <= bit);
37972 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37976 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37978 + AuDebugOn(ino < AUFS_FIRST_INO);
37979 + ino -= AUFS_FIRST_INO;
37980 + *pindex = ino / page_bits;
37981 + *bit = ino % page_bits;
37984 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37989 + struct au_sbinfo *sbinfo;
37990 + struct file *xib;
37991 + unsigned long *p;
37993 + sbinfo = au_sbi(sb);
37994 + MtxMustLock(&sbinfo->si_xib_mtx);
37995 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37996 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37998 + if (pindex == sbinfo->si_xib_last_pindex)
38001 + xib = sbinfo->si_xib;
38002 + p = sbinfo->si_xib_buf;
38003 + pos = sbinfo->si_xib_last_pindex;
38004 + pos *= PAGE_SIZE;
38005 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38006 + if (unlikely(sz != PAGE_SIZE))
38010 + pos *= PAGE_SIZE;
38011 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38012 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
38014 + memset(p, 0, PAGE_SIZE);
38015 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38017 + if (sz == PAGE_SIZE) {
38018 + sbinfo->si_xib_last_pindex = pindex;
38019 + return 0; /* success */
38023 + AuIOErr1("write failed (%zd)\n", sz);
38030 +static void au_xib_clear_bit(struct inode *inode)
38033 + unsigned long pindex;
38034 + struct super_block *sb;
38035 + struct au_sbinfo *sbinfo;
38037 + AuDebugOn(inode->i_nlink);
38039 + sb = inode->i_sb;
38040 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38041 + AuDebugOn(page_bits <= bit);
38042 + sbinfo = au_sbi(sb);
38043 + mutex_lock(&sbinfo->si_xib_mtx);
38044 + err = xib_pindex(sb, pindex);
38046 + clear_bit(bit, sbinfo->si_xib_buf);
38047 + sbinfo->si_xib_next_bit = bit;
38049 + mutex_unlock(&sbinfo->si_xib_mtx);
38052 +/* ---------------------------------------------------------------------- */
38055 + * truncate a xino bitmap file
38059 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38063 + unsigned long pindex;
38064 + loff_t pos, pend;
38065 + struct au_sbinfo *sbinfo;
38066 + vfs_readf_t func;
38068 + unsigned long *p;
38071 + sbinfo = au_sbi(sb);
38072 + MtxMustLock(&sbinfo->si_xib_mtx);
38073 + p = sbinfo->si_xib_buf;
38074 + func = sbinfo->si_xread;
38075 + pend = vfsub_f_size_read(file);
38077 + while (pos < pend) {
38078 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38080 + if (unlikely(sz <= 0))
38084 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38085 + if (unlikely(*ino < AUFS_FIRST_INO))
38088 + xib_calc_bit(*ino, &pindex, &bit);
38089 + AuDebugOn(page_bits <= bit);
38090 + err = xib_pindex(sb, pindex);
38102 +static int xib_restore(struct super_block *sb)
38105 + unsigned int nfile;
38106 + aufs_bindex_t bindex, bbot;
38108 + struct au_branch *br;
38109 + struct au_xino *xi;
38110 + struct file *file;
38113 + page = (void *)__get_free_page(GFP_NOFS);
38114 + if (unlikely(!page))
38118 + bbot = au_sbbot(sb);
38119 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38120 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38121 + br = au_sbr(sb, bindex);
38122 + xi = br->br_xino;
38123 + nfile = xi->xi_nfile;
38124 + for (i = 0; i < nfile; i++) {
38125 + file = au_xino_file(xi, i);
38127 + err = do_xib_restore(sb, file, page);
38130 + AuDbg("skip shared b%d\n", bindex);
38131 + free_page((unsigned long)page);
38137 +int au_xib_trunc(struct super_block *sb)
38142 + struct au_sbinfo *sbinfo;
38143 + unsigned long *p;
38144 + struct file *file;
38146 + SiMustWriteLock(sb);
38149 + sbinfo = au_sbi(sb);
38150 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38153 + file = sbinfo->si_xib;
38154 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38157 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38158 + err = PTR_ERR(file);
38159 + if (IS_ERR(file))
38161 + fput(sbinfo->si_xib);
38162 + sbinfo->si_xib = file;
38164 + p = sbinfo->si_xib_buf;
38165 + memset(p, 0, PAGE_SIZE);
38167 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38168 + if (unlikely(sz != PAGE_SIZE)) {
38170 + AuIOErr("err %d\n", err);
38176 + mutex_lock(&sbinfo->si_xib_mtx);
38177 + /* mnt_want_write() is unnecessary here */
38178 + err = xib_restore(sb);
38179 + mutex_unlock(&sbinfo->si_xib_mtx);
38185 +/* ---------------------------------------------------------------------- */
38187 +struct au_xino *au_xino_alloc(unsigned int nfile)
38189 + struct au_xino *xi;
38191 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38192 + if (unlikely(!xi))
38194 + xi->xi_nfile = nfile;
38195 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38196 + if (unlikely(!xi->xi_file))
38199 + xi->xi_nondir.total = 8; /* initial size */
38200 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38202 + if (unlikely(!xi->xi_nondir.array))
38205 + spin_lock_init(&xi->xi_nondir.spin);
38206 + init_waitqueue_head(&xi->xi_nondir.wqh);
38207 + mutex_init(&xi->xi_mtx);
38208 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38209 + atomic_set(&xi->xi_truncating, 0);
38210 + kref_init(&xi->xi_kref);
38211 + goto out; /* success */
38214 + au_kfree_try_rcu(xi->xi_file);
38216 + au_kfree_rcu(xi);
38222 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38225 + struct au_xino *xi;
38228 + xi = au_xino_alloc(idx + 1);
38229 + if (unlikely(!xi)) {
38236 + xi->xi_file[idx] = file;
38237 + AuDebugOn(br->br_xino);
38238 + br->br_xino = xi;
38244 +static void au_xino_release(struct kref *kref)
38246 + struct au_xino *xi;
38248 + unsigned long ul;
38249 + struct hlist_bl_head *hbl;
38250 + struct hlist_bl_node *pos, *n;
38251 + struct au_xi_writing *p;
38253 + xi = container_of(kref, struct au_xino, xi_kref);
38254 + for (i = 0; i < xi->xi_nfile; i++)
38255 + if (xi->xi_file[i])
38256 + fput(xi->xi_file[i]);
38257 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38258 + AuDebugOn(xi->xi_nondir.array[i]);
38259 + mutex_destroy(&xi->xi_mtx);
38260 + hbl = &xi->xi_writing;
38261 + ul = au_hbl_count(hbl);
38262 + if (unlikely(ul)) {
38263 + pr_warn("xi_writing %lu\n", ul);
38264 + hlist_bl_lock(hbl);
38265 + hlist_bl_for_each_entry_safe (p, pos, n, hbl, node) {
38266 + hlist_bl_del(&p->node);
38269 + hlist_bl_unlock(hbl);
38271 + au_kfree_try_rcu(xi->xi_file);
38272 + au_kfree_try_rcu(xi->xi_nondir.array);
38273 + au_kfree_rcu(xi);
38276 +int au_xino_put(struct au_branch *br)
38279 + struct au_xino *xi;
38282 + xi = br->br_xino;
38284 + br->br_xino = NULL;
38285 + ret = kref_put(&xi->xi_kref, au_xino_release);
38291 +/* ---------------------------------------------------------------------- */
38294 + * xino mount option handlers
38298 +static void xino_clear_xib(struct super_block *sb)
38300 + struct au_sbinfo *sbinfo;
38302 + SiMustWriteLock(sb);
38304 + sbinfo = au_sbi(sb);
38305 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38306 + if (sbinfo->si_xib)
38307 + fput(sbinfo->si_xib);
38308 + sbinfo->si_xib = NULL;
38309 + if (sbinfo->si_xib_buf)
38310 + free_page((unsigned long)sbinfo->si_xib_buf);
38311 + sbinfo->si_xib_buf = NULL;
38314 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38318 + struct au_sbinfo *sbinfo;
38319 + struct file *file;
38320 + struct super_block *xi_sb;
38322 + SiMustWriteLock(sb);
38324 + sbinfo = au_sbi(sb);
38325 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38326 + err = PTR_ERR(file);
38327 + if (IS_ERR(file))
38329 + if (sbinfo->si_xib)
38330 + fput(sbinfo->si_xib);
38331 + sbinfo->si_xib = file;
38332 + sbinfo->si_xread = vfs_readf(file);
38333 + sbinfo->si_xwrite = vfs_writef(file);
38334 + xi_sb = file_inode(file)->i_sb;
38335 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38336 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38338 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38339 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38342 + sbinfo->si_ximaxent /= sizeof(ino_t);
38345 + if (!sbinfo->si_xib_buf)
38346 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38347 + if (unlikely(!sbinfo->si_xib_buf))
38350 + sbinfo->si_xib_last_pindex = 0;
38351 + sbinfo->si_xib_next_bit = 0;
38352 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38354 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38355 + PAGE_SIZE, &pos);
38356 + if (unlikely(err != PAGE_SIZE))
38360 + goto out; /* success */
38363 + if (sbinfo->si_xib_buf)
38364 + free_page((unsigned long)sbinfo->si_xib_buf);
38365 + sbinfo->si_xib_buf = NULL;
38369 + fput(sbinfo->si_xib);
38370 + sbinfo->si_xib = NULL;
38376 +/* xino for each branch */
38377 +static void xino_clear_br(struct super_block *sb)
38379 + aufs_bindex_t bindex, bbot;
38380 + struct au_branch *br;
38382 + bbot = au_sbbot(sb);
38383 + for (bindex = 0; bindex <= bbot; bindex++) {
38384 + br = au_sbr(sb, bindex);
38390 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38391 + aufs_bindex_t bshared)
38393 + struct au_branch *brshared;
38395 + brshared = au_sbr(sb, bshared);
38396 + AuDebugOn(!brshared->br_xino);
38397 + AuDebugOn(!brshared->br_xino->xi_file);
38398 + if (br->br_xino != brshared->br_xino) {
38399 + au_xino_get(brshared);
38401 + br->br_xino = brshared->br_xino;
38405 +struct au_xino_do_set_br {
38406 + vfs_writef_t writef;
38407 + struct au_branch *br;
38409 + aufs_bindex_t bshared;
38412 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38413 + struct au_xino_do_set_br *args)
38416 + struct au_xi_calc calc;
38417 + struct file *file;
38418 + struct au_branch *br;
38419 + struct au_xi_new xinew = {
38424 + xinew.xi = br->br_xino;
38425 + au_xi_calc(sb, args->h_ino, &calc);
38426 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38427 + if (args->bshared >= 0)
38428 + /* shared xino */
38429 + au_xino_set_br_shared(sb, br, args->bshared);
38430 + else if (!xinew.xi) {
38432 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38433 + if (unlikely(err))
38437 + /* force re-creating */
38438 + xinew.xi = br->br_xino;
38439 + xinew.idx = calc.idx;
38440 + mutex_lock(&xinew.xi->xi_mtx);
38441 + file = au_xi_new(sb, &xinew);
38442 + mutex_unlock(&xinew.xi->xi_mtx);
38443 + err = PTR_ERR(file);
38444 + if (IS_ERR(file))
38446 + AuDebugOn(!file);
38448 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38449 + if (unlikely(err))
38457 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38460 + aufs_bindex_t bindex, bbot;
38461 + struct au_xino_do_set_br args;
38462 + struct inode *inode;
38464 + SiMustWriteLock(sb);
38466 + bbot = au_sbbot(sb);
38467 + inode = d_inode(sb->s_root);
38468 + args.writef = au_sbi(sb)->si_xwrite;
38469 + for (bindex = 0; bindex <= bbot; bindex++) {
38470 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38471 + args.br = au_sbr(sb, bindex);
38472 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38473 + err = au_xino_do_set_br(sb, path, &args);
38474 + if (unlikely(err))
38482 +void au_xino_clr(struct super_block *sb)
38484 + struct au_sbinfo *sbinfo;
38486 + au_xigen_clr(sb);
38487 + xino_clear_xib(sb);
38488 + xino_clear_br(sb);
38489 + dbgaufs_brs_del(sb, 0);
38490 + sbinfo = au_sbi(sb);
38491 + /* lvalue, do not call au_mntflags() */
38492 + au_opt_clr(sbinfo->si_mntflags, XINO);
38495 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38498 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38499 + struct qstr *dname, *cur_name;
38500 + struct file *cur_xino;
38501 + struct au_sbinfo *sbinfo;
38502 + struct path *path, *cur_path;
38504 + SiMustWriteLock(sb);
38507 + sbinfo = au_sbi(sb);
38508 + path = &xiopt->file->f_path;
38509 + dentry = path->dentry;
38510 + parent = dget_parent(dentry);
38513 + cur_xino = sbinfo->si_xib;
38515 + cur_path = &cur_xino->f_path;
38516 + cur_dentry = cur_path->dentry;
38517 + cur_parent = dget_parent(cur_dentry);
38518 + cur_name = &cur_dentry->d_name;
38519 + dname = &dentry->d_name;
38520 + skip = (cur_parent == parent
38521 + && au_qstreq(dname, cur_name));
38522 + dput(cur_parent);
38528 + au_opt_set(sbinfo->si_mntflags, XINO);
38529 + err = au_xino_set_xib(sb, path);
38530 + /* si_x{read,write} are set */
38532 + err = au_xigen_set(sb, path);
38534 + err = au_xino_set_br(sb, path);
38536 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38537 + goto out; /* success */
38541 + AuIOErr("failed setting xino(%d).\n", err);
38550 + * create a xinofile at the default place/path.
38552 +struct file *au_xino_def(struct super_block *sb)
38554 + struct file *file;
38556 + struct au_branch *br;
38557 + struct super_block *h_sb;
38558 + struct path path;
38559 + aufs_bindex_t bbot, bindex, bwr;
38562 + bbot = au_sbbot(sb);
38564 + for (bindex = 0; bindex <= bbot; bindex++) {
38565 + br = au_sbr(sb, bindex);
38566 + if (au_br_writable(br->br_perm)
38567 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38574 + file = ERR_PTR(-ENOMEM);
38575 + page = (void *)__get_free_page(GFP_NOFS);
38576 + if (unlikely(!page))
38578 + path.mnt = au_br_mnt(br);
38579 + path.dentry = au_h_dptr(sb->s_root, bwr);
38580 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38581 + file = (void *)p;
38582 + if (!IS_ERR(p)) {
38583 + strcat(p, "/" AUFS_XINO_FNAME);
38584 + AuDbg("%s\n", p);
38585 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38587 + free_page((unsigned long)page);
38589 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38591 + if (IS_ERR(file))
38593 + h_sb = file->f_path.dentry->d_sb;
38594 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38595 + pr_err("xino doesn't support %s(%s)\n",
38596 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38598 + file = ERR_PTR(-EINVAL);
38606 +/* ---------------------------------------------------------------------- */
38609 + * initialize the xinofile for the specified branch @br
38610 + * at the place/path where @base_file indicates.
38611 + * test whether another branch is on the same filesystem or not,
38612 + * if found then share the xinofile with another branch.
38614 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38615 + struct path *base)
38618 + struct au_xino_do_set_br args = {
38623 + args.writef = au_sbi(sb)->si_xwrite;
38624 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38626 + err = au_xino_do_set_br(sb, base, &args);
38627 + if (unlikely(err))
38633 +/* ---------------------------------------------------------------------- */
38636 + * get an unused inode number from bitmap
38638 +ino_t au_xino_new_ino(struct super_block *sb)
38641 + unsigned long *p, pindex, ul, pend;
38642 + struct au_sbinfo *sbinfo;
38643 + struct file *file;
38644 + int free_bit, err;
38646 + if (!au_opt_test(au_mntflags(sb), XINO))
38647 + return iunique(sb, AUFS_FIRST_INO);
38649 + sbinfo = au_sbi(sb);
38650 + mutex_lock(&sbinfo->si_xib_mtx);
38651 + p = sbinfo->si_xib_buf;
38652 + free_bit = sbinfo->si_xib_next_bit;
38653 + if (free_bit < page_bits && !test_bit(free_bit, p))
38654 + goto out; /* success */
38655 + free_bit = find_first_zero_bit(p, page_bits);
38656 + if (free_bit < page_bits)
38657 + goto out; /* success */
38659 + pindex = sbinfo->si_xib_last_pindex;
38660 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38661 + err = xib_pindex(sb, ul);
38662 + if (unlikely(err))
38664 + free_bit = find_first_zero_bit(p, page_bits);
38665 + if (free_bit < page_bits)
38666 + goto out; /* success */
38669 + file = sbinfo->si_xib;
38670 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38671 + for (ul = pindex + 1; ul <= pend; ul++) {
38672 + err = xib_pindex(sb, ul);
38673 + if (unlikely(err))
38675 + free_bit = find_first_zero_bit(p, page_bits);
38676 + if (free_bit < page_bits)
38677 + goto out; /* success */
38682 + set_bit(free_bit, p);
38683 + sbinfo->si_xib_next_bit = free_bit + 1;
38684 + pindex = sbinfo->si_xib_last_pindex;
38685 + mutex_unlock(&sbinfo->si_xib_mtx);
38686 + ino = xib_calc_ino(pindex, free_bit);
38687 + AuDbg("i%lu\n", (unsigned long)ino);
38690 + mutex_unlock(&sbinfo->si_xib_mtx);
38695 +/* for s_op->delete_inode() */
38696 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38699 + unsigned int mnt_flags;
38700 + aufs_bindex_t bindex, bbot, bi;
38701 + unsigned char try_trunc;
38702 + struct au_iinfo *iinfo;
38703 + struct super_block *sb;
38704 + struct au_hinode *hi;
38705 + struct inode *h_inode;
38706 + struct au_branch *br;
38707 + vfs_writef_t xwrite;
38708 + struct au_xi_calc calc;
38709 + struct file *file;
38711 + AuDebugOn(au_is_bad_inode(inode));
38713 + sb = inode->i_sb;
38714 + mnt_flags = au_mntflags(sb);
38715 + if (!au_opt_test(mnt_flags, XINO)
38716 + || inode->i_ino == AUFS_ROOT_INO)
38720 + au_xigen_inc(inode);
38721 + au_xib_clear_bit(inode);
38724 + iinfo = au_ii(inode);
38725 + bindex = iinfo->ii_btop;
38729 + xwrite = au_sbi(sb)->si_xwrite;
38730 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38731 + hi = au_hinode(iinfo, bindex);
38732 + bbot = iinfo->ii_bbot;
38733 + for (; bindex <= bbot; bindex++, hi++) {
38734 + h_inode = hi->hi_inode;
38736 + || (!unlinked && h_inode->i_nlink))
38739 + /* inode may not be revalidated */
38740 + bi = au_br_index(sb, hi->hi_id);
38744 + br = au_sbr(sb, bi);
38745 + au_xi_calc(sb, h_inode->i_ino, &calc);
38746 + file = au_xino_file(br->br_xino, calc.idx);
38747 + if (IS_ERR_OR_NULL(file))
38750 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38751 + if (!err && try_trunc
38752 + && au_test_fs_trunc_xino(au_br_sb(br)))
38753 + xino_try_trunc(sb, br);
38757 +/* ---------------------------------------------------------------------- */
38759 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38761 + int found, total, i;
38764 + total = xi->xi_nondir.total;
38765 + for (i = 0; i < total; i++) {
38766 + if (xi->xi_nondir.array[i] != h_ino)
38775 +static int au_xinondir_expand(struct au_xino *xi)
38780 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38783 + sz = xi->xi_nondir.total * sizeof(ino_t);
38784 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38786 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38787 + /*may_shrink*/0);
38789 + xi->xi_nondir.array = p;
38790 + xi->xi_nondir.total <<= 1;
38791 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38799 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38800 + ino_t h_ino, int idx)
38802 + struct au_xino *xi;
38804 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38805 + xi = au_sbr(sb, bindex)->br_xino;
38806 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38808 + spin_lock(&xi->xi_nondir.spin);
38809 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38810 + xi->xi_nondir.array[idx] = 0;
38811 + spin_unlock(&xi->xi_nondir.spin);
38812 + wake_up_all(&xi->xi_nondir.wqh);
38815 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38818 + int err, found, empty;
38819 + struct au_xino *xi;
38823 + if (!au_opt_test(au_mntflags(sb), XINO))
38824 + goto out; /* no xino */
38826 + xi = au_sbr(sb, bindex)->br_xino;
38829 + spin_lock(&xi->xi_nondir.spin);
38830 + found = au_xinondir_find(xi, h_ino);
38831 + if (found == -1) {
38832 + empty = au_xinondir_find(xi, /*h_ino*/0);
38833 + if (empty == -1) {
38834 + empty = xi->xi_nondir.total;
38835 + err = au_xinondir_expand(xi);
38836 + if (unlikely(err))
38839 + xi->xi_nondir.array[empty] = h_ino;
38842 + spin_unlock(&xi->xi_nondir.spin);
38843 + wait_event(xi->xi_nondir.wqh,
38844 + xi->xi_nondir.array[found] != h_ino);
38849 + spin_unlock(&xi->xi_nondir.spin);
38854 +/* ---------------------------------------------------------------------- */
38856 +int au_xino_path(struct seq_file *seq, struct file *file)
38860 + err = au_seq_path(seq, &file->f_path);
38861 + if (unlikely(err))
38864 +#define Deleted "\\040(deleted)"
38865 + seq->count -= sizeof(Deleted) - 1;
38866 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38867 + sizeof(Deleted) - 1));
38873 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38874 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38875 +++ linux/include/uapi/linux/aufs_type.h 2019-09-16 09:38:43.216175640 +0200
38877 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38879 + * Copyright (C) 2005-2019 Junjiro R. Okajima
38881 + * This program, aufs is free software; you can redistribute it and/or modify
38882 + * it under the terms of the GNU General Public License as published by
38883 + * the Free Software Foundation; either version 2 of the License, or
38884 + * (at your option) any later version.
38886 + * This program is distributed in the hope that it will be useful,
38887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38889 + * GNU General Public License for more details.
38891 + * You should have received a copy of the GNU General Public License
38892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38895 +#ifndef __AUFS_TYPE_H__
38896 +#define __AUFS_TYPE_H__
38898 +#define AUFS_NAME "aufs"
38902 + * define it before including all other headers.
38903 + * sched.h may use pr_* macros before defining "current", so define the
38904 + * no-current version first, and re-define later.
38906 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38907 +#include <linux/sched.h>
38909 +#define pr_fmt(fmt) \
38910 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38911 + (int)sizeof(current->comm), current->comm, current->pid
38913 +#include <stdint.h>
38914 +#include <sys/types.h>
38915 +#endif /* __KERNEL__ */
38917 +#include <linux/limits.h>
38919 +#define AUFS_VERSION "5.x-rcN-20190909"
38921 +/* todo? move this to linux-2.6.19/include/magic.h */
38922 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38924 +/* ---------------------------------------------------------------------- */
38926 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38927 +typedef int8_t aufs_bindex_t;
38928 +#define AUFS_BRANCH_MAX 127
38930 +typedef int16_t aufs_bindex_t;
38931 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38932 +#define AUFS_BRANCH_MAX 511
38933 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38934 +#define AUFS_BRANCH_MAX 1023
38935 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38936 +#define AUFS_BRANCH_MAX 32767
38941 +#ifndef AUFS_BRANCH_MAX
38942 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38944 +#endif /* __KERNEL__ */
38946 +/* ---------------------------------------------------------------------- */
38948 +#define AUFS_FSTYPE AUFS_NAME
38950 +#define AUFS_ROOT_INO 2
38951 +#define AUFS_FIRST_INO 11
38953 +#define AUFS_WH_PFX ".wh."
38954 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38955 +#define AUFS_WH_TMP_LEN 4
38956 +/* a limit for rmdir/rename a dir and copyup */
38957 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38958 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38960 + - AUFS_WH_TMP_LEN) /* hex */
38961 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38962 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38963 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38964 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38965 +#define AUFS_DIRWH_DEF 3
38966 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38967 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38968 +#define AUFS_RDBLK_DEF 512 /* bytes */
38969 +#define AUFS_RDHASH_DEF 32
38970 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38971 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38972 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38973 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38974 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38976 +/* pseudo-link maintenace under /proc */
38977 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38978 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38979 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38981 +/* dirren, renamed dir */
38982 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38983 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38984 +/* whiteouted doubly */
38985 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38986 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38988 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38989 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38991 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38992 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38993 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38995 +/* doubly whiteouted */
38996 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38997 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38998 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39000 +/* branch permissions and attributes */
39001 +#define AUFS_BRPERM_RW "rw"
39002 +#define AUFS_BRPERM_RO "ro"
39003 +#define AUFS_BRPERM_RR "rr"
39004 +#define AUFS_BRATTR_COO_REG "coo_reg"
39005 +#define AUFS_BRATTR_COO_ALL "coo_all"
39006 +#define AUFS_BRATTR_FHSM "fhsm"
39007 +#define AUFS_BRATTR_UNPIN "unpin"
39008 +#define AUFS_BRATTR_ICEX "icex"
39009 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39010 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39011 +#define AUFS_BRATTR_ICEX_TR "icextr"
39012 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39013 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39014 +#define AUFS_BRRATTR_WH "wh"
39015 +#define AUFS_BRWATTR_NLWH "nolwh"
39016 +#define AUFS_BRWATTR_MOO "moo"
39018 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39019 +#define AuBrPerm_RO (1 << 1) /* readonly */
39020 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39021 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39023 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39024 +#define AuBrAttr_COO_ALL (1 << 4)
39025 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39027 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39028 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39029 + branch. meaningless since
39030 + linux-3.18-rc1 */
39032 +/* ignore error in copying XATTR */
39033 +#define AuBrAttr_ICEX_SEC (1 << 7)
39034 +#define AuBrAttr_ICEX_SYS (1 << 8)
39035 +#define AuBrAttr_ICEX_TR (1 << 9)
39036 +#define AuBrAttr_ICEX_USR (1 << 10)
39037 +#define AuBrAttr_ICEX_OTH (1 << 11)
39038 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39039 + | AuBrAttr_ICEX_SYS \
39040 + | AuBrAttr_ICEX_TR \
39041 + | AuBrAttr_ICEX_USR \
39042 + | AuBrAttr_ICEX_OTH)
39044 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39045 +#define AuBrRAttr_Mask AuBrRAttr_WH
39047 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39048 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39049 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39051 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39053 +/* #warning test userspace */
39055 +#ifndef CONFIG_AUFS_FHSM
39056 +#undef AuBrAttr_FHSM
39057 +#define AuBrAttr_FHSM 0
39059 +#ifndef CONFIG_AUFS_XATTR
39060 +#undef AuBrAttr_ICEX
39061 +#define AuBrAttr_ICEX 0
39062 +#undef AuBrAttr_ICEX_SEC
39063 +#define AuBrAttr_ICEX_SEC 0
39064 +#undef AuBrAttr_ICEX_SYS
39065 +#define AuBrAttr_ICEX_SYS 0
39066 +#undef AuBrAttr_ICEX_TR
39067 +#define AuBrAttr_ICEX_TR 0
39068 +#undef AuBrAttr_ICEX_USR
39069 +#define AuBrAttr_ICEX_USR 0
39070 +#undef AuBrAttr_ICEX_OTH
39071 +#define AuBrAttr_ICEX_OTH 0
39075 +/* the longest combination */
39076 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39077 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39078 + "+" AUFS_BRATTR_COO_REG \
39079 + "+" AUFS_BRATTR_FHSM \
39080 + "+" AUFS_BRATTR_UNPIN \
39081 + "+" AUFS_BRATTR_ICEX_SEC \
39082 + "+" AUFS_BRATTR_ICEX_SYS \
39083 + "+" AUFS_BRATTR_ICEX_USR \
39084 + "+" AUFS_BRATTR_ICEX_OTH \
39085 + "+" AUFS_BRWATTR_NLWH)
39088 + char a[AuBrPermStrSz];
39089 +} au_br_perm_str_t;
39091 +static inline int au_br_writable(int brperm)
39093 + return brperm & AuBrPerm_RW;
39096 +static inline int au_br_whable(int brperm)
39098 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39101 +static inline int au_br_wh_linkable(int brperm)
39103 + return !(brperm & AuBrWAttr_NoLinkWH);
39106 +static inline int au_br_cmoo(int brperm)
39108 + return brperm & AuBrAttr_CMOO_Mask;
39111 +static inline int au_br_fhsm(int brperm)
39113 + return brperm & AuBrAttr_FHSM;
39116 +/* ---------------------------------------------------------------------- */
39120 + /* readdir in userspace */
39124 + AuCtl_WBR_FD, /* pathconf wrapper */
39125 + AuCtl_IBUSY, /* busy inode */
39126 + AuCtl_MVDOWN, /* move-down */
39127 + AuCtl_BR, /* info about branches */
39128 + AuCtl_FHSM_FD /* connection for fhsm */
39131 +/* borrowed from linux/include/linux/kernel.h */
39133 +#ifdef _GNU_SOURCE
39134 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39136 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39138 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39141 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39143 +#define __aligned(x) __attribute__((aligned(x)))
39148 +#define __packed __attribute__((packed))
39152 +struct au_rdu_cookie {
39157 + uint32_t generation;
39160 +struct au_rdu_ent {
39169 +static inline int au_rdu_len(int nlen)
39171 + /* include the terminating NULL */
39172 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39173 + sizeof(uint64_t));
39176 +union au_rdu_ent_ul {
39177 + struct au_rdu_ent __user *e;
39189 + uint64_t sz; /* AuCtl_RDU */
39190 + uint64_t nent; /* AuCtl_RDU_INO */
39192 + union au_rdu_ent_ul ent;
39193 + uint16_t verify[AufsCtlRduV_End];
39195 + /* input/output */
39199 + union au_rdu_ent_ul tail;
39200 + /* number of entries which were added in a single call */
39205 + struct au_rdu_cookie cookie;
39208 +/* ---------------------------------------------------------------------- */
39210 +/* dirren. the branch is identified by the filename who contains this */
39211 +struct au_drinfo {
39214 + uint8_t oldnamelen;
39215 + uint64_t _padding;
39217 + uint8_t oldname[0];
39220 +struct au_drinfo_fdata {
39222 + struct au_drinfo drinfo;
39225 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39227 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39229 +/* ---------------------------------------------------------------------- */
39231 +struct aufs_wbr_fd {
39236 +/* ---------------------------------------------------------------------- */
39238 +struct aufs_ibusy {
39239 + uint64_t ino, h_ino;
39243 +/* ---------------------------------------------------------------------- */
39245 +/* error code for move-down */
39246 +/* the actual message strings are implemented in aufs-util.git */
39248 + EAU_MVDOWN_OPAQUE = 1,
39249 + EAU_MVDOWN_WHITEOUT,
39250 + EAU_MVDOWN_UPPER,
39251 + EAU_MVDOWN_BOTTOM,
39252 + EAU_MVDOWN_NOUPPER,
39253 + EAU_MVDOWN_NOLOWERBR,
39257 +/* flags for move-down */
39258 +#define AUFS_MVDOWN_DMSG 1
39259 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39260 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39261 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39262 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39263 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39264 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39265 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39266 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39267 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39268 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39269 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39270 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39272 +/* index for move-down */
39274 + AUFS_MVDOWN_UPPER,
39275 + AUFS_MVDOWN_LOWER,
39276 + AUFS_MVDOWN_NARRAY
39280 + * additional info of move-down
39281 + * number of free blocks and inodes.
39282 + * subset of struct kstatfs, but smaller and always 64bit.
39284 +struct aufs_stfs {
39285 + uint64_t f_blocks;
39286 + uint64_t f_bavail;
39287 + uint64_t f_files;
39288 + uint64_t f_ffree;
39291 +struct aufs_stbr {
39292 + int16_t brid; /* optional input */
39293 + int16_t bindex; /* output */
39294 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39297 +struct aufs_mvdown {
39298 + uint32_t flags; /* input/output */
39299 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39300 + int8_t au_errno; /* output */
39303 +/* ---------------------------------------------------------------------- */
39305 +union aufs_brinfo {
39306 + /* PATH_MAX may differ between kernel-space and user-space */
39307 + char _spacer[4096];
39315 +/* ---------------------------------------------------------------------- */
39317 +#define AuCtlType 'A'
39318 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39319 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39320 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39321 + struct aufs_wbr_fd)
39322 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39323 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39324 + struct aufs_mvdown)
39325 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39326 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39328 +#endif /* __AUFS_TYPE_H__ */
39329 SPDX-License-Identifier: GPL-2.0
39330 aufs5.x-rcN loopback patch
39332 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39333 index 80d06084b043..a83cdfec7359 100644
39334 --- a/drivers/block/loop.c
39335 +++ b/drivers/block/loop.c
39336 @@ -625,6 +625,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39340 +static struct file *loop_real_file(struct file *file)
39342 + struct file *f = NULL;
39344 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39345 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39349 static void loop_reread_partitions(struct loop_device *lo,
39350 struct block_device *bdev)
39352 @@ -678,6 +687,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39355 struct file *file = NULL, *old_file;
39356 + struct file *f, *virt_file = NULL, *old_virt_file;
39360 @@ -697,12 +707,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39364 + f = loop_real_file(file);
39366 + virt_file = file;
39371 error = loop_validate_file(file, bdev);
39375 old_file = lo->lo_backing_file;
39376 + old_virt_file = lo->lo_backing_virt_file;
39380 @@ -714,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39381 blk_mq_freeze_queue(lo->lo_queue);
39382 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39383 lo->lo_backing_file = file;
39384 + lo->lo_backing_virt_file = virt_file;
39385 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39386 mapping_set_gfp_mask(file->f_mapping,
39387 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39388 @@ -727,6 +745,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39392 + if (old_virt_file)
39393 + fput(old_virt_file);
39395 loop_reread_partitions(lo, bdev);
39397 @@ -735,6 +755,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39398 mutex_unlock(&loop_ctl_mutex);
39406 @@ -939,7 +961,7 @@ static void loop_update_rotational(struct loop_device *lo)
39407 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39408 struct block_device *bdev, unsigned int arg)
39410 - struct file *file;
39411 + struct file *file, *f, *virt_file = NULL;
39412 struct inode *inode;
39413 struct address_space *mapping;
39414 struct block_device *claimed_bdev = NULL;
39415 @@ -955,6 +977,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39419 + f = loop_real_file(file);
39421 + virt_file = file;
39427 * If we don't hold exclusive handle for the device, upgrade to it
39428 @@ -1003,6 +1031,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39429 lo->lo_device = bdev;
39430 lo->lo_flags = lo_flags;
39431 lo->lo_backing_file = file;
39432 + lo->lo_backing_virt_file = virt_file;
39433 lo->transfer = NULL;
39435 lo->lo_sizelimit = 0;
39436 @@ -1046,6 +1075,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39437 bd_abort_claiming(bdev, claimed_bdev, loop_set_fd);
39443 /* This is safe: open() is still holding a reference. */
39444 module_put(THIS_MODULE);
39445 @@ -1092,6 +1123,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39446 static int __loop_clr_fd(struct loop_device *lo, bool release)
39448 struct file *filp = NULL;
39449 + struct file *virt_filp = lo->lo_backing_virt_file;
39450 gfp_t gfp = lo->old_gfp_mask;
39451 struct block_device *bdev = lo->lo_device;
39453 @@ -1115,6 +1147,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39455 spin_lock_irq(&lo->lo_lock);
39456 lo->lo_backing_file = NULL;
39457 + lo->lo_backing_virt_file = NULL;
39458 spin_unlock_irq(&lo->lo_lock);
39460 loop_release_xfer(lo);
39461 @@ -1197,6 +1230,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39470 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39471 index af75a5ee4094..1e6ee5a4f623 100644
39472 --- a/drivers/block/loop.h
39473 +++ b/drivers/block/loop.h
39474 @@ -46,7 +46,7 @@ struct loop_device {
39475 int (*ioctl)(struct loop_device *, int cmd,
39476 unsigned long arg);
39478 - struct file * lo_backing_file;
39479 + struct file * lo_backing_file, *lo_backing_virt_file;
39480 struct block_device *lo_device;
39483 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39484 index 0309f0d502ff..19feb4f3cb5f 100644
39485 --- a/fs/aufs/f_op.c
39486 +++ b/fs/aufs/f_op.c
39487 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39488 if (IS_ERR(h_file))
39491 - if (au_test_loopback_kthread()) {
39492 + if (0 && au_test_loopback_kthread()) {
39493 au_warn_loopback(h_file->f_path.dentry->d_sb);
39494 if (file->f_mapping != h_file->f_mapping) {
39495 file->f_mapping = h_file->f_mapping;
39496 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39497 index 9ba35a878ecd..4ed0ff03d5ab 100644
39498 --- a/fs/aufs/loop.c
39499 +++ b/fs/aufs/loop.c
39500 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39501 symbol_put(loop_backing_file);
39502 au_kfree_try_rcu(au_warn_loopback_array);
39505 +/* ---------------------------------------------------------------------- */
39507 +/* support the loopback block device insude aufs */
39509 +struct file *aufs_real_loop(struct file *file)
39513 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39514 + fi_read_lock(file);
39515 + f = au_hf_top(file);
39516 + fi_read_unlock(file);
39520 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39521 index f31e40aff267..e13fb1a0717a 100644
39522 --- a/fs/aufs/loop.h
39523 +++ b/fs/aufs/loop.h
39524 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39526 int au_loopback_init(void);
39527 void au_loopback_fin(void);
39529 +struct file *aufs_real_loop(struct file *file);
39531 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39533 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39535 AuStubInt0(au_loopback_init, void)
39536 AuStubVoid(au_loopback_fin, void)
39538 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39539 #endif /* BLK_DEV_LOOP */
39541 #endif /* __KERNEL__ */
39542 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39543 index a97e2921cb09..f74eb6962684 100644
39544 --- a/fs/aufs/super.c
39545 +++ b/fs/aufs/super.c
39546 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39547 .statfs = aufs_statfs,
39548 .put_super = aufs_put_super,
39549 .sync_fs = aufs_sync_fs,
39550 - .remount_fs = aufs_remount_fs
39551 + .remount_fs = aufs_remount_fs,
39552 +#ifdef CONFIG_AUFS_BDEV_LOOP
39553 + .real_loop = aufs_real_loop
39557 /* ---------------------------------------------------------------------- */
39558 diff --git a/include/linux/fs.h b/include/linux/fs.h
39559 index 3dbec51c2037..38ab7b6c7c6d 100644
39560 --- a/include/linux/fs.h
39561 +++ b/include/linux/fs.h
39562 @@ -1948,6 +1948,10 @@ struct super_operations {
39563 struct shrink_control *);
39564 long (*free_cached_objects)(struct super_block *,
39565 struct shrink_control *);
39566 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39568 + struct file *(*real_loop)(struct file *);