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/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/erofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index d60089fd689b..924c16a40b00 100644
20 @@ -132,3 +132,4 @@ obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 obj-$(CONFIG_EROFS_FS) += erofs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs5.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index a50e97a63bc8..bd7c76319a85 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 541fd805fb88..3208fcf3b3c9 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 @@ -374,6 +376,7 @@ void __fput_sync(struct file *file)
806 +EXPORT_SYMBOL_GPL(__fput_sync);
808 void __init files_init(void)
810 diff --git a/fs/inode.c b/fs/inode.c
811 index 43df8452f97d..8a5c14630ff0 100644
814 @@ -1679,6 +1679,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
816 return update_time(inode, time, flags);
818 +EXPORT_SYMBOL_GPL(update_time);
821 * touch_atime - update the access time
822 diff --git a/fs/namespace.c b/fs/namespace.c
823 index 34c8093ddb1d..2b64af58b643 100644
826 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
827 mnt_dec_writers(real_mount(mnt));
830 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
833 * mnt_drop_write - give up write access to a mount
834 @@ -781,6 +782,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
836 return check_mnt(real_mount(mnt));
838 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
841 * vfsmount lock must be held for write
842 @@ -1900,6 +1902,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
846 +EXPORT_SYMBOL_GPL(iterate_mounts);
848 static void lock_mnt_tree(struct mount *mnt)
850 --- linux-5.4/fs/notify/group.c~ 2019-11-25 01:32:01.000000000 +0100
851 +++ linux-5.4/fs/notify/group.c 2019-11-26 20:14:34.917150671 +0100
852 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_
854 refcount_inc(&group->refcnt);
856 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
859 * Drop a reference to a group. Free it if it's through.
860 diff --git a/fs/open.c b/fs/open.c
861 index a59abe3c669a..78809163ba03 100644
864 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
865 inode_unlock(dentry->d_inode);
868 +EXPORT_SYMBOL_GPL(do_truncate);
870 long vfs_truncate(const struct path *path, loff_t length)
872 diff --git a/fs/read_write.c b/fs/read_write.c
873 index 3265bb84f152..5b2dbddb0efe 100644
874 --- a/fs/read_write.c
875 +++ b/fs/read_write.c
876 @@ -468,6 +468,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
880 +EXPORT_SYMBOL_GPL(vfs_read);
882 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
884 @@ -508,6 +509,7 @@ vfs_readf_t vfs_readf(struct file *file)
885 return new_sync_read;
886 return ERR_PTR(-ENOSYS);
888 +EXPORT_SYMBOL_GPL(vfs_readf);
890 vfs_writef_t vfs_writef(struct file *file)
892 @@ -519,6 +521,7 @@ vfs_writef_t vfs_writef(struct file *file)
893 return new_sync_write;
894 return ERR_PTR(-ENOSYS);
896 +EXPORT_SYMBOL_GPL(vfs_writef);
898 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
900 @@ -588,6 +591,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
904 +EXPORT_SYMBOL_GPL(vfs_write);
906 /* file_ppos returns &file->f_pos or NULL if file is stream */
907 static inline loff_t *file_ppos(struct file *file)
908 diff --git a/fs/splice.c b/fs/splice.c
909 index 75b489fcb66f..0a1f7498c22b 100644
912 @@ -847,6 +847,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
914 return splice_write(pipe, out, ppos, len, flags);
916 +EXPORT_SYMBOL_GPL(do_splice_from);
919 * Attempt to initiate a splice from a file to a pipe.
920 @@ -876,6 +877,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
922 return splice_read(in, ppos, pipe, len, flags);
924 +EXPORT_SYMBOL_GPL(do_splice_to);
927 * splice_direct_to_actor - splices data directly between two non-pipes
928 diff --git a/fs/sync.c b/fs/sync.c
929 index 457f4e4a5cc1..67c66358f3fe 100644
932 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
933 sb->s_op->sync_fs(sb, wait);
934 return __sync_blockdev(sb->s_bdev, wait);
936 +EXPORT_SYMBOL_GPL(__sync_filesystem);
939 * Write out and wait upon all dirty data associated with this
940 diff --git a/fs/xattr.c b/fs/xattr.c
941 index 90dd78f0eb27..40b01dd1b14a 100644
944 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
945 *xattr_value = value;
948 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
951 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
952 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
953 index ec87ccf82025..739d1c8a81f5 100644
954 --- a/kernel/locking/lockdep.c
955 +++ b/kernel/locking/lockdep.c
956 @@ -174,6 +174,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
958 return lock_classes + class_idx;
960 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
961 #define hlock_class(hlock) lockdep_hlock_class(hlock)
963 #ifdef CONFIG_LOCK_STAT
964 diff --git a/kernel/task_work.c b/kernel/task_work.c
965 index 0fef395662a6..83fb1ecfc33d 100644
966 --- a/kernel/task_work.c
967 +++ b/kernel/task_work.c
968 @@ -116,3 +116,4 @@ void task_work_run(void)
972 +EXPORT_SYMBOL_GPL(task_work_run);
973 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
974 index 725674f3276d..83f6494c52a2 100644
975 --- a/security/device_cgroup.c
976 +++ b/security/device_cgroup.c
977 @@ -824,3 +824,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
981 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
982 diff --git a/security/security.c b/security/security.c
983 index 250ee2d76406..2765042d4846 100644
984 --- a/security/security.c
985 +++ b/security/security.c
986 @@ -996,6 +996,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
988 return call_int_hook(path_rmdir, 0, dir, dentry);
990 +EXPORT_SYMBOL_GPL(security_path_rmdir);
992 int security_path_unlink(const struct path *dir, struct dentry *dentry)
994 @@ -1012,6 +1013,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
996 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
998 +EXPORT_SYMBOL_GPL(security_path_symlink);
1000 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1001 struct dentry *new_dentry)
1002 @@ -1020,6 +1022,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1004 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1006 +EXPORT_SYMBOL_GPL(security_path_link);
1008 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1009 const struct path *new_dir, struct dentry *new_dentry,
1010 @@ -1047,6 +1050,7 @@ int security_path_truncate(const struct path *path)
1012 return call_int_hook(path_truncate, 0, path);
1014 +EXPORT_SYMBOL_GPL(security_path_truncate);
1016 int security_path_chmod(const struct path *path, umode_t mode)
1018 @@ -1054,6 +1058,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1020 return call_int_hook(path_chmod, 0, path, mode);
1022 +EXPORT_SYMBOL_GPL(security_path_chmod);
1024 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1026 @@ -1061,6 +1066,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1028 return call_int_hook(path_chown, 0, path, uid, gid);
1030 +EXPORT_SYMBOL_GPL(security_path_chown);
1032 int security_path_chroot(const struct path *path)
1034 @@ -1161,6 +1167,7 @@ int security_inode_permission(struct inode *inode, int mask)
1036 return call_int_hook(inode_permission, 0, inode, mask);
1038 +EXPORT_SYMBOL_GPL(security_inode_permission);
1040 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1042 @@ -1338,6 +1345,7 @@ int security_file_permission(struct file *file, int mask)
1044 return fsnotify_perm(file, mask);
1046 +EXPORT_SYMBOL_GPL(security_file_permission);
1048 int security_file_alloc(struct file *file)
1050 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1051 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1052 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200
1054 +What: /debug/aufs/si_<id>/
1056 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1058 + Under /debug/aufs, a directory named si_<id> is created
1059 + per aufs mount, where <id> is a unique id generated
1062 +What: /debug/aufs/si_<id>/plink
1064 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1066 + It has three lines and shows the information about the
1067 + pseudo-link. The first line is a single number
1068 + representing a number of buckets. The second line is a
1069 + number of pseudo-links per buckets (separated by a
1070 + blank). The last line is a single number representing a
1071 + total number of psedo-links.
1072 + When the aufs mount option 'noplink' is specified, it
1073 + will show "1\n0\n0\n".
1075 +What: /debug/aufs/si_<id>/xib
1077 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1079 + It shows the consumed blocks by xib (External Inode Number
1080 + Bitmap), its block size and file size.
1081 + When the aufs mount option 'noxino' is specified, it
1082 + will be empty. About XINO files, see the aufs manual.
1084 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1086 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1088 + It shows the consumed blocks by xino (External Inode Number
1089 + Translation Table), its link count, block size and file
1091 + Due to the file size limit, there may exist multiple
1092 + xino files per branch. In this case, "-N" is added to
1093 + the filename and it corresponds to the index of the
1094 + internal xino array. "-0" is omitted.
1095 + When the aufs mount option 'noxino' is specified, Those
1096 + entries won't exist. About XINO files, see the aufs
1099 +What: /debug/aufs/si_<id>/xigen
1101 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1103 + It shows the consumed blocks by xigen (External Inode
1104 + Generation Table), its block size and file size.
1105 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1107 + When the aufs mount option 'noxino' is specified, it
1108 + will be empty. About XINO files, see the aufs manual.
1109 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1110 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1111 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200
1113 +What: /sys/fs/aufs/si_<id>/
1115 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1117 + Under /sys/fs/aufs, a directory named si_<id> is created
1118 + per aufs mount, where <id> is a unique id generated
1121 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1123 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1125 + It shows the abolute path of a member directory (which
1126 + is called branch) in aufs, and its permission.
1128 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1130 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1132 + It shows the id of a member directory (which is called
1135 +What: /sys/fs/aufs/si_<id>/xi_path
1137 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1139 + It shows the abolute path of XINO (External Inode Number
1140 + Bitmap, Translation Table and Generation Table) file
1141 + even if it is the default path.
1142 + When the aufs mount option 'noxino' is specified, it
1143 + will be empty. About XINO files, see the aufs manual.
1144 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1145 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1146 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2019-07-11 15:42:14.455570938 +0200
1149 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1151 +# This program is free software; you can redistribute it and/or modify
1152 +# it under the terms of the GNU General Public License as published by
1153 +# the Free Software Foundation; either version 2 of the License, or
1154 +# (at your option) any later version.
1156 +# This program is distributed in the hope that it will be useful,
1157 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1158 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1159 +# GNU General Public License for more details.
1161 +# You should have received a copy of the GNU General Public License
1162 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1165 +----------------------------------------
1167 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1168 +1. abbrev. for "advanced multi-layered unification filesystem".
1169 +2. abbrev. for "another unionfs".
1170 +3. abbrev. for "auf das" in German which means "on the" in English.
1171 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1172 + But "Filesystem aufs Filesystem" is hard to understand.
1173 +4. abbrev. for "African Urban Fashion Show".
1175 +AUFS is a filesystem with features:
1176 +- multi layered stackable unification filesystem, the member directory
1177 + is called as a branch.
1178 +- branch permission and attribute, 'readonly', 'real-readonly',
1179 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1181 +- internal "file copy-on-write".
1182 +- logical deletion, whiteout.
1183 +- dynamic branch manipulation, adding, deleting and changing permission.
1184 +- allow bypassing aufs, user's direct branch access.
1185 +- external inode number translation table and bitmap which maintains the
1186 + persistent aufs inode number.
1187 +- seekable directory, including NFS readdir.
1188 +- file mapping, mmap and sharing pages.
1189 +- pseudo-link, hardlink over branches.
1190 +- loopback mounted filesystem as a branch.
1191 +- several policies to select one among multiple writable branches.
1192 +- revert a single systemcall when an error occurs in aufs.
1196 +Multi Layered Stackable Unification Filesystem
1197 +----------------------------------------------------------------------
1198 +Most people already knows what it is.
1199 +It is a filesystem which unifies several directories and provides a
1200 +merged single directory. When users access a file, the access will be
1201 +passed/re-directed/converted (sorry, I am not sure which English word is
1202 +correct) to the real file on the member filesystem. The member
1203 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1204 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1205 +readonly branch is handled by creating 'whiteout' on the upper writable
1208 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1209 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1210 +different approaches to implement the merged-view.
1211 +The former tries putting it into VFS, and the latter implements as a
1212 +separate filesystem.
1213 +(If I misunderstand about these implementations, please let me know and
1214 +I shall correct it. Because it is a long time ago when I read their
1215 +source files last time).
1217 +UnionMount's approach will be able to small, but may be hard to share
1218 +branches between several UnionMount since the whiteout in it is
1219 +implemented in the inode on branch filesystem and always
1220 +shared. According to Bharata's post, readdir does not seems to be
1222 +There are several missing features known in this implementations such as
1223 +- for users, the inode number may change silently. eg. copy-up.
1224 +- link(2) may break by copy-up.
1225 +- read(2) may get an obsoleted filedata (fstat(2) too).
1226 +- fcntl(F_SETLK) may be broken by copy-up.
1227 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1230 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1231 +merged into mainline. This is another implementation of UnionMount as a
1232 +separated filesystem. All the limitations and known problems which
1233 +UnionMount are equally inherited to "overlay" filesystem.
1235 +Unionfs has a longer history. When I started implementing a stackable
1236 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1237 +inode, dentry and file objects and they have an array pointing lower
1238 +same kind objects. After contributing many patches for Unionfs, I
1239 +re-started my project AUFS (Jun 2006).
1241 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1242 +implemented my own ideas, approaches and enhancements and it became
1243 +totally different one.
1245 +Comparing DM snapshot and fs based implementation
1246 +- the number of bytes to be copied between devices is much smaller.
1247 +- the type of filesystem must be one and only.
1248 +- the fs must be writable, no readonly fs, even for the lower original
1249 + device. so the compression fs will not be usable. but if we use
1250 + loopback mount, we may address this issue.
1252 + mount /cdrom/squashfs.img /sq
1253 + losetup /sq/ext2.img
1254 + losetup /somewhere/cow
1255 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1256 +- it will be difficult (or needs more operations) to extract the
1257 + difference between the original device and COW.
1258 +- DM snapshot-merge may help a lot when users try merging. in the
1259 + fs-layer union, users will use rsync(1).
1261 +You may want to read my old paper "Filesystems in LiveCD"
1262 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1265 +Several characters/aspects/persona of aufs
1266 +----------------------------------------------------------------------
1268 +Aufs has several characters, aspects or persona.
1269 +1. a filesystem, callee of VFS helper
1270 +2. sub-VFS, caller of VFS helper for branches
1271 +3. a virtual filesystem which maintains persistent inode number
1272 +4. reader/writer of files on branches such like an application
1274 +1. Callee of VFS Helper
1275 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1276 +unlink(2) from an application reaches sys_unlink() kernel function and
1277 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1278 +calls filesystem specific unlink operation. Actually aufs implements the
1279 +unlink operation but it behaves like a redirector.
1281 +2. Caller of VFS Helper for Branches
1282 +aufs_unlink() passes the unlink request to the branch filesystem as if
1283 +it were called from VFS. So the called unlink operation of the branch
1284 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1285 +every necessary pre/post operation for the branch filesystem.
1286 +- acquire the lock for the parent dir on a branch
1287 +- lookup in a branch
1288 +- revalidate dentry on a branch
1289 +- mnt_want_write() for a branch
1290 +- vfs_unlink() for a branch
1291 +- mnt_drop_write() for a branch
1292 +- release the lock on a branch
1294 +3. Persistent Inode Number
1295 +One of the most important issue for a filesystem is to maintain inode
1296 +numbers. This is particularly important to support exporting a
1297 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1298 +backend block device for its own. But some storage is necessary to
1299 +keep and maintain the inode numbers. It may be a large space and may not
1300 +suit to keep in memory. Aufs rents some space from its first writable
1301 +branch filesystem (by default) and creates file(s) on it. These files
1302 +are created by aufs internally and removed soon (currently) keeping
1304 +Note: Because these files are removed, they are totally gone after
1305 + unmounting aufs. It means the inode numbers are not persistent
1306 + across unmount or reboot. I have a plan to make them really
1307 + persistent which will be important for aufs on NFS server.
1309 +4. Read/Write Files Internally (copy-on-write)
1310 +Because a branch can be readonly, when you write a file on it, aufs will
1311 +"copy-up" it to the upper writable branch internally. And then write the
1312 +originally requested thing to the file. Generally kernel doesn't
1313 +open/read/write file actively. In aufs, even a single write may cause a
1314 +internal "file copy". This behaviour is very similar to cp(1) command.
1316 +Some people may think it is better to pass such work to user space
1317 +helper, instead of doing in kernel space. Actually I am still thinking
1318 +about it. But currently I have implemented it in kernel space.
1319 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1320 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1321 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2019-07-11 15:42:14.455570938 +0200
1324 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1326 +# This program is free software; you can redistribute it and/or modify
1327 +# it under the terms of the GNU General Public License as published by
1328 +# the Free Software Foundation; either version 2 of the License, or
1329 +# (at your option) any later version.
1331 +# This program is distributed in the hope that it will be useful,
1332 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1333 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1334 +# GNU General Public License for more details.
1336 +# You should have received a copy of the GNU General Public License
1337 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1339 +Basic Aufs Internal Structure
1341 +Superblock/Inode/Dentry/File Objects
1342 +----------------------------------------------------------------------
1343 +As like an ordinary filesystem, aufs has its own
1344 +superblock/inode/dentry/file objects. All these objects have a
1345 +dynamically allocated array and store the same kind of pointers to the
1346 +lower filesystem, branch.
1347 +For example, when you build a union with one readwrite branch and one
1348 +readonly, mounted /au, /rw and /ro respectively.
1350 +- /ro/fileA exists but /rw/fileA
1352 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1353 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1354 +- [0] = NULL (because /rw/fileA doesn't exist)
1357 +This style of an array is essentially same to the aufs
1358 +superblock/inode/dentry/file objects.
1360 +Because aufs supports manipulating branches, ie. add/delete/change
1361 +branches dynamically, these objects has its own generation. When
1362 +branches are changed, the generation in aufs superblock is
1363 +incremented. And a generation in other object are compared when it is
1364 +accessed. When a generation in other objects are obsoleted, aufs
1365 +refreshes the internal array.
1369 +----------------------------------------------------------------------
1370 +Additionally aufs superblock has some data for policies to select one
1371 +among multiple writable branches, XIB files, pseudo-links and kobject.
1372 +See below in detail.
1373 +About the policies which supports copy-down a directory, see
1374 +wbr_policy.txt too.
1377 +Branch and XINO(External Inode Number Translation Table)
1378 +----------------------------------------------------------------------
1379 +Every branch has its own xino (external inode number translation table)
1380 +file. The xino file is created and unlinked by aufs internally. When two
1381 +members of a union exist on the same filesystem, they share the single
1383 +The struct of a xino file is simple, just a sequence of aufs inode
1384 +numbers which is indexed by the lower inode number.
1385 +In the above sample, assume the inode number of /ro/fileA is i111 and
1386 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1387 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1389 +When the inode numbers are not contiguous, the xino file will be sparse
1390 +which has a hole in it and doesn't consume as much disk space as it
1391 +might appear. If your branch filesystem consumes disk space for such
1392 +holes, then you should specify 'xino=' option at mounting aufs.
1394 +Aufs has a mount option to free the disk blocks for such holes in XINO
1395 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1396 +meet a problem of disk shortage due to XINO files, then you should try
1397 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1398 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1399 +the holes in XINO files.
1401 +Also a writable branch has three kinds of "whiteout bases". All these
1402 +are existed when the branch is joined to aufs, and their names are
1403 +whiteout-ed doubly, so that users will never see their names in aufs
1405 +1. a regular file which will be hardlinked to all whiteouts.
1406 +2. a directory to store a pseudo-link.
1407 +3. a directory to store an "orphan"-ed file temporary.
1410 + When you remove a file on a readonly branch, aufs handles it as a
1411 + logical deletion and creates a whiteout on the upper writable branch
1412 + as a hardlink of this file in order not to consume inode on the
1415 + See below, Pseudo-link.
1417 + When "fileC" exists on the lower readonly branch only and it is
1418 + opened and removed with its parent dir, and then user writes
1419 + something into it, then aufs copies-up fileC to this
1420 + directory. Because there is no other dir to store fileC. After
1421 + creating a file under this dir, the file is unlinked.
1423 +Because aufs supports manipulating branches, ie. add/delete/change
1424 +dynamically, a branch has its own id. When the branch order changes,
1425 +aufs finds the new index by searching the branch id.
1429 +----------------------------------------------------------------------
1430 +Assume "fileA" exists on the lower readonly branch only and it is
1431 +hardlinked to "fileB" on the branch. When you write something to fileA,
1432 +aufs copies-up it to the upper writable branch. Additionally aufs
1433 +creates a hardlink under the Pseudo-link Directory of the writable
1434 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1435 +simple list. If fileB is read after unlinking fileA, aufs returns
1436 +filedata from the pseudo-link instead of the lower readonly
1437 +branch. Because the pseudo-link is based upon the inode, to keep the
1438 +inode number by xino (see above) is essentially necessary.
1440 +All the hardlinks under the Pseudo-link Directory of the writable branch
1441 +should be restored in a proper location later. Aufs provides a utility
1442 +to do this. The userspace helpers executed at remounting and unmounting
1444 +During this utility is running, it puts aufs into the pseudo-link
1445 +maintenance mode. In this mode, only the process which began the
1446 +maintenance mode (and its child processes) is allowed to operate in
1447 +aufs. Some other processes which are not related to the pseudo-link will
1448 +be allowed to run too, but the rest have to return an error or wait
1449 +until the maintenance mode ends. If a process already acquires an inode
1450 +mutex (in VFS), it has to return an error.
1453 +XIB(external inode number bitmap)
1454 +----------------------------------------------------------------------
1455 +Addition to the xino file per a branch, aufs has an external inode number
1456 +bitmap in a superblock object. It is also an internal file such like a
1458 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1460 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1462 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1463 +reduce the number of consumed disk blocks for these files.
1466 +Virtual or Vertical Dir, and Readdir in Userspace
1467 +----------------------------------------------------------------------
1468 +In order to support multiple layers (branches), aufs readdir operation
1469 +constructs a virtual dir block on memory. For readdir, aufs calls
1470 +vfs_readdir() internally for each dir on branches, merges their entries
1471 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1472 +object. So the file object has its entry list until it is closed. The
1473 +entry list will be updated when the file position is zero and becomes
1474 +obsoleted. This decision is made in aufs automatically.
1476 +The dynamically allocated memory block for the name of entries has a
1477 +unit of 512 bytes (by default) and stores the names contiguously (no
1478 +padding). Another block for each entry is handled by kmem_cache too.
1479 +During building dir blocks, aufs creates hash list and judging whether
1480 +the entry is whiteouted by its upper branch or already listed.
1481 +The merged result is cached in the corresponding inode object and
1482 +maintained by a customizable life-time option.
1484 +Some people may call it can be a security hole or invite DoS attack
1485 +since the opened and once readdir-ed dir (file object) holds its entry
1486 +list and becomes a pressure for system memory. But I'd say it is similar
1487 +to files under /proc or /sys. The virtual files in them also holds a
1488 +memory page (generally) while they are opened. When an idea to reduce
1489 +memory for them is introduced, it will be applied to aufs too.
1490 +For those who really hate this situation, I've developed readdir(3)
1491 +library which operates this merging in userspace. You just need to set
1492 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1493 +kernel space for readdir(3).
1497 +----------------------------------------------------------------------
1498 +Aufs sometimes requires privilege access to a branch. For instance,
1499 +in copy-up/down operation. When a user process is going to make changes
1500 +to a file which exists in the lower readonly branch only, and the mode
1501 +of one of ancestor directories may not be writable by a user
1502 +process. Here aufs copy-up the file with its ancestors and they may
1503 +require privilege to set its owner/group/mode/etc.
1504 +This is a typical case of a application character of aufs (see
1507 +Aufs uses workqueue synchronously for this case. It creates its own
1508 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1509 +passes the request to call mkdir or write (for example), and wait for
1510 +its completion. This approach solves a problem of a signal handler
1512 +If aufs didn't adopt the workqueue and changed the privilege of the
1513 +process, then the process may receive the unexpected SIGXFSZ or other
1516 +Also aufs uses the system global workqueue ("events" kernel thread) too
1517 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1518 +whiteout base and etc. This is unrelated to a privilege.
1519 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1520 +superblock at the beginning, at the same time waits for the completion
1521 +of all queued asynchronous tasks.
1525 +----------------------------------------------------------------------
1526 +The whiteout in aufs is very similar to Unionfs's. That is represented
1527 +by its filename. UnionMount takes an approach of a file mode, but I am
1528 +afraid several utilities (find(1) or something) will have to support it.
1530 +Basically the whiteout represents "logical deletion" which stops aufs to
1531 +lookup further, but also it represents "dir is opaque" which also stop
1534 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1535 +In order to make several functions in a single systemcall to be
1536 +revertible, aufs adopts an approach to rename a directory to a temporary
1537 +unique whiteouted name.
1538 +For example, in rename(2) dir where the target dir already existed, aufs
1539 +renames the target dir to a temporary unique whiteouted name before the
1540 +actual rename on a branch, and then handles other actions (make it opaque,
1541 +update the attributes, etc). If an error happens in these actions, aufs
1542 +simply renames the whiteouted name back and returns an error. If all are
1543 +succeeded, aufs registers a function to remove the whiteouted unique
1544 +temporary name completely and asynchronously to the system global
1549 +----------------------------------------------------------------------
1550 +It is a well-known feature or concept.
1551 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1552 +internally and makes change to the new file on the upper writable branch.
1553 +When the trigger systemcall does not update the timestamps of the parent
1554 +dir, aufs reverts it after copy-up.
1557 +Move-down (aufs3.9 and later)
1558 +----------------------------------------------------------------------
1559 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1560 +the lower readonly branch to the upper writable branch when a user
1561 +changes something about the file.
1562 +"Move-down" is an opposite action of copy-up. Basically this action is
1563 +ran manually instead of automatically and internally.
1564 +For desgin and implementation, aufs has to consider these issues.
1565 +- whiteout for the file may exist on the lower branch.
1566 +- ancestor directories may not exist on the lower branch.
1567 +- diropq for the ancestor directories may exist on the upper branch.
1568 +- free space on the lower branch will reduce.
1569 +- another access to the file may happen during moving-down, including
1570 + UDBA (see "Revalidate Dentry and UDBA").
1571 +- the file should not be hard-linked nor pseudo-linked. they should be
1572 + handled by auplink utility later.
1574 +Sometimes users want to move-down a file from the upper writable branch
1575 +to the lower readonly or writable branch. For instance,
1576 +- the free space of the upper writable branch is going to run out.
1577 +- create a new intermediate branch between the upper and lower branch.
1580 +For this purpose, use "aumvdown" command in aufs-util.git.
1581 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1582 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1583 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2019-07-11 15:42:14.458904362 +0200
1586 +# Copyright (C) 2015-2019 Junjiro R. Okajima
1588 +# This program is free software; you can redistribute it and/or modify
1589 +# it under the terms of the GNU General Public License as published by
1590 +# the Free Software Foundation; either version 2 of the License, or
1591 +# (at your option) any later version.
1593 +# This program is distributed in the hope that it will be useful,
1594 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1595 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1596 +# GNU General Public License for more details.
1598 +# You should have received a copy of the GNU General Public License
1599 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1601 +Support for a branch who has its ->atomic_open()
1602 +----------------------------------------------------------------------
1603 +The filesystems who implement its ->atomic_open() are not majority. For
1604 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1605 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1606 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1607 +sure whether all filesystems who have ->atomic_open() behave like this,
1608 +but NFSv4 surely returns the error.
1610 +In order to support ->atomic_open() for aufs, there are a few
1613 +A. Introduce aufs_atomic_open()
1614 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1616 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1617 + an aufs user Pip Cet's approach
1618 + - calls aufs_create(), VFS finish_open() and notify_change().
1619 + - pass fake-mode to finish_open(), and then correct the mode by
1621 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1622 + - no aufs_atomic_open().
1623 + - aufs_lookup() registers the TID to an aufs internal object.
1624 + - aufs_create() does nothing when the matching TID is registered, but
1625 + registers the mode.
1626 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1627 + TID is registered.
1628 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1630 + - no aufs_atomic_open().
1631 + - aufs_create() registers the TID to an internal object. this info
1632 + represents "this process created this file just now."
1633 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1634 + registered TID and re-try open() with superuser's credential.
1636 +Pros and cons for each approach.
1639 + - straightforward but highly depends upon VFS internal.
1640 + - the atomic behavaiour is kept.
1641 + - some of parameters such as nameidata are hard to reproduce for
1645 + - easy to implement.
1646 + - the atomic behavaiour is lost.
1648 + - the atomic behavaiour is kept.
1649 + - dirty and tricky.
1650 + - VFS checks whether the file is created correctly after calling
1651 + ->create(), which means this approach doesn't work.
1653 + - easy to implement.
1654 + - the atomic behavaiour is lost.
1655 + - to open a file with superuser's credential and give it to a user
1656 + process is a bad idea, since the file object keeps the credential
1657 + in it. It may affect LSM or something. This approach doesn't work
1660 +The approach A is ideal, but it hard to implement. So here is a
1661 +variation of A, which is to be implemented.
1663 +A-1. Introduce aufs_atomic_open()
1664 + - calls branch fs ->atomic_open() if exists. otherwise calls
1665 + vfs_create() and finish_open().
1666 + - the demerit is that the several checks after branch fs
1667 + ->atomic_open() are lost. in the ordinary case, the checks are
1668 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1669 + be implemented in aufs, but not all I am afraid.
1670 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1671 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1672 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2019-07-11 15:42:14.458904362 +0200
1675 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1677 +# This program is free software; you can redistribute it and/or modify
1678 +# it under the terms of the GNU General Public License as published by
1679 +# the Free Software Foundation; either version 2 of the License, or
1680 +# (at your option) any later version.
1682 +# This program is distributed in the hope that it will be useful,
1683 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1684 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1685 +# GNU General Public License for more details.
1687 +# You should have received a copy of the GNU General Public License
1688 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1691 +----------------------------------------------------------------------
1692 +Since aufs has a character of sub-VFS (see Introduction), it operates
1693 +lookup for branches as VFS does. It may be a heavy work. But almost all
1694 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1695 +directly connected to its parent. Digging down the directory hierarchy
1696 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1699 +When a branch is a remote filesystem, aufs basically relies upon its
1700 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1702 +For d_revalidate, aufs implements three levels of revalidate tests. See
1703 +"Revalidate Dentry and UDBA" in detail.
1706 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1707 +----------------------------------------------------------------------
1708 +Let's try case study.
1709 +- aufs has two branches, upper readwrite and lower readonly.
1711 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1712 +- user invoked "chmod a+rx /au/dirA"
1713 +- the internal copy-up is activated and "/rw/dirA" is created and its
1714 + permission bits are set to world readable.
1715 +- then "/au/dirA" becomes world readable?
1717 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1718 +or it may be a natively readonly filesystem. If aufs respects the lower
1719 +branch, it should not respond readdir request from other users. But user
1720 +allowed it by chmod. Should really aufs rejects showing the entries
1723 +To be honest, I don't have a good solution for this case. So aufs
1724 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1726 +When dirperm1 is specified, aufs checks only the highest one for the
1727 +directory permission, and shows the entries. Otherwise, as usual, checks
1728 +every dir existing on all branches and rejects the request.
1730 +As a side effect, dirperm1 option improves the performance of aufs
1731 +because the number of permission check is reduced when the number of
1735 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1736 +----------------------------------------------------------------------
1737 +Generally VFS helpers re-validate a dentry as a part of lookup.
1738 +0. digging down the directory hierarchy.
1739 +1. lock the parent dir by its i_mutex.
1740 +2. lookup the final (child) entry.
1742 +4. call the actual operation (create, unlink, etc.)
1743 +5. unlock the parent dir
1745 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1746 +called. Actually aufs implements it and checks the dentry on a branch is
1748 +But it is not enough. Because aufs has to release the lock for the
1749 +parent dir on a branch at the end of ->lookup() (step 2) and
1750 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1752 +If the file on a branch is changed directly, eg. bypassing aufs, after
1753 +aufs released the lock, then the subsequent operation may cause
1754 +something unpleasant result.
1756 +This situation is a result of VFS architecture, ->lookup() and
1757 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1758 +design from VFS's point of view. It is just not suitable for sub-VFS
1761 +Aufs supports such case by three level of revalidation which is
1762 +selectable by user.
1763 +1. Simple Revalidate
1764 + Addition to the native flow in VFS's, confirm the child-parent
1765 + relationship on the branch just after locking the parent dir on the
1766 + branch in the "actual operation" (step 4). When this validation
1767 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1768 + checks the validation of the dentry on branches.
1769 +2. Monitor Changes Internally by Inotify/Fsnotify
1770 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1771 + the dentry on the branch, and returns EBUSY if it finds different
1773 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1774 + during it is in cache. When the event is notified, aufs registers a
1775 + function to kernel 'events' thread by schedule_work(). And the
1776 + function sets some special status to the cached aufs dentry and inode
1777 + private data. If they are not cached, then aufs has nothing to
1778 + do. When the same file is accessed through aufs (step 0-3) later,
1779 + aufs will detect the status and refresh all necessary data.
1780 + In this mode, aufs has to ignore the event which is fired by aufs
1782 +3. No Extra Validation
1783 + This is the simplest test and doesn't add any additional revalidation
1784 + test, and skip the revalidation in step 4. It is useful and improves
1785 + aufs performance when system surely hide the aufs branches from user,
1786 + by over-mounting something (or another method).
1787 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1788 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1789 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2019-07-11 15:42:14.458904362 +0200
1792 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1794 +# This program is free software; you can redistribute it and/or modify
1795 +# it under the terms of the GNU General Public License as published by
1796 +# the Free Software Foundation; either version 2 of the License, or
1797 +# (at your option) any later version.
1799 +# This program is distributed in the hope that it will be useful,
1800 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1801 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1802 +# GNU General Public License for more details.
1804 +# You should have received a copy of the GNU General Public License
1805 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1807 +Branch Manipulation
1809 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1810 +and changing its permission/attribute, there are a lot of works to do.
1814 +----------------------------------------------------------------------
1815 +o Confirm the adding dir exists outside of aufs, including loopback
1816 + mount, and its various attributes.
1817 +o Initialize the xino file and whiteout bases if necessary.
1820 +o Check the owner/group/mode of the directory
1821 + When the owner/group/mode of the adding directory differs from the
1822 + existing branch, aufs issues a warning because it may impose a
1824 + For example, when a upper writable branch has a world writable empty
1825 + top directory, a malicious user can create any files on the writable
1826 + branch directly, like copy-up and modify manually. If something like
1827 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1828 + writable branch, and the writable branch is world-writable, then a
1829 + malicious guy may create /etc/passwd on the writable branch directly
1830 + and the infected file will be valid in aufs.
1831 + I am afraid it can be a security issue, but aufs can do nothing except
1832 + producing a warning.
1836 +----------------------------------------------------------------------
1837 +o Confirm the deleting branch is not busy
1838 + To be general, there is one merit to adopt "remount" interface to
1839 + manipulate branches. It is to discard caches. At deleting a branch,
1840 + aufs checks the still cached (and connected) dentries and inodes. If
1841 + there are any, then they are all in-use. An inode without its
1842 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1844 + For the cached one, aufs checks whether the same named entry exists on
1846 + If the cached one is a directory, because aufs provides a merged view
1847 + to users, as long as one dir is left on any branch aufs can show the
1848 + dir to users. In this case, the branch can be removed from aufs.
1849 + Otherwise aufs rejects deleting the branch.
1851 + If any file on the deleting branch is opened by aufs, then aufs
1855 +Modify the Permission of a Branch
1856 +----------------------------------------------------------------------
1857 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1860 +o rw --> ro: Confirm the modifying branch is not busy
1861 + Aufs rejects the request if any of these conditions are true.
1862 + - a file on the branch is mmap-ed.
1863 + - a regular file on the branch is opened for write and there is no
1864 + same named entry on the upper branch.
1865 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1866 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1867 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2019-07-11 15:42:14.458904362 +0200
1870 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1872 +# This program is free software; you can redistribute it and/or modify
1873 +# it under the terms of the GNU General Public License as published by
1874 +# the Free Software Foundation; either version 2 of the License, or
1875 +# (at your option) any later version.
1877 +# This program is distributed in the hope that it will be useful,
1878 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1879 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1880 +# GNU General Public License for more details.
1882 +# You should have received a copy of the GNU General Public License
1883 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1885 +Policies to Select One among Multiple Writable Branches
1886 +----------------------------------------------------------------------
1887 +When the number of writable branch is more than one, aufs has to decide
1888 +the target branch for file creation or copy-up. By default, the highest
1889 +writable branch which has the parent (or ancestor) dir of the target
1890 +file is chosen (top-down-parent policy).
1891 +By user's request, aufs implements some other policies to select the
1892 +writable branch, for file creation several policies, round-robin,
1893 +most-free-space, and other policies. For copy-up, top-down-parent,
1894 +bottom-up-parent, bottom-up and others.
1896 +As expected, the round-robin policy selects the branch in circular. When
1897 +you have two writable branches and creates 10 new files, 5 files will be
1898 +created for each branch. mkdir(2) systemcall is an exception. When you
1899 +create 10 new directories, all will be created on the same branch.
1900 +And the most-free-space policy selects the one which has most free
1901 +space among the writable branches. The amount of free space will be
1902 +checked by aufs internally, and users can specify its time interval.
1904 +The policies for copy-up is more simple,
1905 +top-down-parent is equivalent to the same named on in create policy,
1906 +bottom-up-parent selects the writable branch where the parent dir
1907 +exists and the nearest upper one from the copyup-source,
1908 +bottom-up selects the nearest upper writable branch from the
1909 +copyup-source, regardless the existence of the parent dir.
1911 +There are some rules or exceptions to apply these policies.
1912 +- If there is a readonly branch above the policy-selected branch and
1913 + the parent dir is marked as opaque (a variation of whiteout), or the
1914 + target (creating) file is whiteout-ed on the upper readonly branch,
1915 + then the result of the policy is ignored and the target file will be
1916 + created on the nearest upper writable branch than the readonly branch.
1917 +- If there is a writable branch above the policy-selected branch and
1918 + the parent dir is marked as opaque or the target file is whiteouted
1919 + on the branch, then the result of the policy is ignored and the target
1920 + file will be created on the highest one among the upper writable
1921 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1923 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1924 + They try selecting the branch where the source exists as possible
1925 + since copyup a large file will take long time. If it can't be,
1926 + ie. the branch where the source exists is readonly, then they will
1927 + follow the copyup policy.
1928 +- There is an exception for rename(2) when the target exists.
1929 + If the rename target exists, aufs compares the index of the branches
1930 + where the source and the target exists and selects the higher
1931 + one. If the selected branch is readonly, then aufs follows the
1933 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1934 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1935 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200
1938 +// to view this graph, run dot(1) command in GRAPHVIZ.
1942 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1946 +aufs_rename -> whinfo [label="store/remove"];
1949 +inode_list [label="h_inum list in branch\ncache"];
1952 +whinode [label="h_inum list file"];
1955 +brmgmt [label="br_add/del/mod/umount"];
1957 +brmgmt -> inode_list [label="create/remove"];
1958 +brmgmt -> whinode [label="load/store"];
1960 +inode_list -> whinode [style=dashed,dir=both];
1962 +aufs_rename -> inode_list [label="add/del"];
1964 +aufs_lookup -> inode_list [label="search"];
1966 +aufs_lookup -> whinfo [label="load/remove"];
1968 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1969 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1970 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2019-07-11 15:42:14.458904362 +0200
1973 +# Copyright (C) 2017-2019 Junjiro R. Okajima
1975 +# This program is free software; you can redistribute it and/or modify
1976 +# it under the terms of the GNU General Public License as published by
1977 +# the Free Software Foundation; either version 2 of the License, or
1978 +# (at your option) any later version.
1980 +# This program is distributed in the hope that it will be useful,
1981 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1982 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1983 +# GNU General Public License for more details.
1985 +# You should have received a copy of the GNU General Public License
1986 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1988 +Special handling for renaming a directory (DIRREN)
1989 +----------------------------------------------------------------------
1990 +First, let's assume we have a simple usecase.
1994 +- /ro/dirA and /ro/dirA/file exist too
1995 +- there is no dirB on both branches
1996 +- a user issues rename("dirA", "dirB")
1998 +Now, what should aufs behave against this rename(2)?
1999 +There are a few possible cases.
2002 + since dirA exists on a readonly branch which cannot be renamed.
2004 + it is possible to copy-up dirA (only the dir itself), but the child
2005 + entries ("file" in this case) should not be. it must be a bad
2006 + approach to copy-up recursively.
2007 +C. returns a success.
2008 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2009 + is a violation of aufs' policy.
2010 +D. construct an extra information which indicates that /ro/dirA should
2011 + be handled as the name of dirB.
2012 + overlayfs has a similar feature called REDIRECT.
2014 +Until now, aufs implements the case B only which returns EXDEV, and
2015 +expects the userspace application behaves like mv(1) which tries
2016 +issueing rename(2) recursively.
2018 +A new aufs feature called DIRREN is introduced which implements the case
2019 +D. There are several "extra information" added.
2021 +1. detailed info per renamed directory
2022 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2023 +2. the inode-number list of directories on a branch
2024 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2026 +The filename of "detailed info per directory" represents the lower
2027 +branch, and its format is
2028 +- a type of the branch id
2030 + + uuid (not implemented yet)
2033 +- the inode-number of the branch root dir
2035 +And it contains these info in a single regular file.
2037 +- branch's inode-number of the logically renamed dir
2038 +- the name of the before-renamed dir
2040 +The "detailed info per directory" file is created in aufs rename(2), and
2041 +loaded in any lookup.
2042 +The info is considered in lookup for the matching case only. Here
2043 +"matching" means that the root of branch (in the info filename) is same
2044 +to the current looking-up branch. After looking-up the before-renamed
2045 +name, the inode-number is compared. And the matched dentry is used.
2047 +The "inode-number list of directories" is a regular file which contains
2048 +simply the inode-numbers on the branch. The file is created or updated
2049 +in removing the branch, and loaded in adding the branch. Its lifetime is
2050 +equal to the branch.
2051 +The list is refered in lookup, and when the current target inode is
2052 +found in the list, the aufs tries loading the "detailed info per
2053 +directory" and get the changed and valid name of the dir.
2055 +Theoretically these "extra informaiton" may be able to be put into XATTR
2056 +in the dir inode. But aufs doesn't choose this way because
2057 +1. XATTR may not be supported by the branch (or its configuration)
2058 +2. XATTR may have its size limit.
2059 +3. XATTR may be less easy to convert than a regular file, when the
2060 + format of the info is changed in the future.
2061 +At the same time, I agree that the regular file approach is much slower
2062 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2065 +This DIRREN feature is enabled by aufs configuration, and is activated
2066 +by a new mount option.
2068 +For the more complicated case, there is a work with UDBA option, which
2069 +is to dected the direct access to the branches (by-passing aufs) and to
2070 +maintain the cashes in aufs. Since a single cached aufs dentry may
2071 +contains two names, before- and after-rename, the name comparision in
2072 +UDBA handler may not work correctly. In this case, the behaviour will be
2073 +equivalen to udba=reval case.
2074 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2075 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2076 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2019-07-11 15:42:14.458904362 +0200
2079 +# Copyright (C) 2011-2019 Junjiro R. Okajima
2081 +# This program is free software; you can redistribute it and/or modify
2082 +# it under the terms of the GNU General Public License as published by
2083 +# the Free Software Foundation; either version 2 of the License, or
2084 +# (at your option) any later version.
2086 +# This program is distributed in the hope that it will be useful,
2087 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2088 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2089 +# GNU General Public License for more details.
2091 +# You should have received a copy of the GNU General Public License
2092 +# along with this program; if not, write to the Free Software
2093 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2096 +File-based Hierarchical Storage Management (FHSM)
2097 +----------------------------------------------------------------------
2098 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2099 +storage world. Aufs provides this feature as file-based with multiple
2100 +writable branches, based upon the principle of "Colder, the Lower".
2101 +Here the word "colder" means that the less used files, and "lower" means
2102 +that the position in the order of the stacked branches vertically.
2103 +These multiple writable branches are prioritized, ie. the topmost one
2104 +should be the fastest drive and be used heavily.
2106 +o Characters in aufs FHSM story
2107 +- aufs itself and a new branch attribute.
2108 +- a new ioctl interface to move-down and to establish a connection with
2109 + the daemon ("move-down" is a converse of "copy-up").
2110 +- userspace tool and daemon.
2112 +The userspace daemon establishes a connection with aufs and waits for
2113 +the notification. The notified information is very similar to struct
2114 +statfs containing the number of consumed blocks and inodes.
2115 +When the consumed blocks/inodes of a branch exceeds the user-specified
2116 +upper watermark, the daemon activates its move-down process until the
2117 +consumed blocks/inodes reaches the user-specified lower watermark.
2119 +The actual move-down is done by aufs based upon the request from
2120 +user-space since we need to maintain the inode number and the internal
2121 +pointer arrays in aufs.
2123 +Currently aufs FHSM handles the regular files only. Additionally they
2124 +must not be hard-linked nor pseudo-linked.
2127 +o Cowork of aufs and the user-space daemon
2128 + During the userspace daemon established the connection, aufs sends a
2129 + small notification to it whenever aufs writes something into the
2130 + writable branch. But it may cost high since aufs issues statfs(2)
2131 + internally. So user can specify a new option to cache the
2132 + info. Actually the notification is controlled by these factors.
2133 + + the specified cache time.
2134 + + classified as "force" by aufs internally.
2135 + Until the specified time expires, aufs doesn't send the info
2136 + except the forced cases. When aufs decide forcing, the info is always
2137 + notified to userspace.
2138 + For example, the number of free inodes is generally large enough and
2139 + the shortage of it happens rarely. So aufs doesn't force the
2140 + notification when creating a new file, directory and others. This is
2141 + the typical case which aufs doesn't force.
2142 + When aufs writes the actual filedata and the files consumes any of new
2143 + blocks, the aufs forces notifying.
2146 +o Interfaces in aufs
2147 +- New branch attribute.
2149 + Specifies that the branch is managed by FHSM feature. In other word,
2150 + participant in the FHSM.
2151 + When nofhsm is set to the branch, it will not be the source/target
2152 + branch of the move-down operation. This attribute is set
2153 + independently from coo and moo attributes, and if you want full
2154 + FHSM, you should specify them as well.
2155 +- New mount option.
2157 + Specifies a second to suppress many less important info to be
2160 + + AUFS_CTL_FHSM_FD
2161 + create a new file descriptor which userspace can read the notification
2162 + (a subset of struct statfs) from aufs.
2163 +- Module parameter 'brs'
2164 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2166 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2167 + When there are two or more branches with fhsm attributes,
2168 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2169 + terminates it. As a result of remounting and branch-manipulation, the
2170 + number of branches with fhsm attribute can be one. In this case,
2171 + /sbin/mount.aufs will terminate the user-space daemon.
2174 +Finally the operation is done as these steps in kernel-space.
2176 + + no one else is using the file.
2177 + + the file is not hard-linked.
2178 + + the file is not pseudo-linked.
2179 + + the file is a regular file.
2180 + + the parent dir is not opaqued.
2181 +- find the target writable branch.
2182 +- make sure the file is not whiteout-ed by the upper (than the target)
2184 +- make the parent dir on the target branch.
2185 +- mutex lock the inode on the branch.
2186 +- unlink the whiteout on the target branch (if exists).
2187 +- lookup and create the whiteout-ed temporary name on the target branch.
2188 +- copy the file as the whiteout-ed temporary name on the target branch.
2189 +- rename the whiteout-ed temporary name to the original name.
2190 +- unlink the file on the source branch.
2191 +- maintain the internal pointer array and the external inode number
2193 +- maintain the timestamps and other attributes of the parent dir and the
2196 +And of course, in every step, an error may happen. So the operation
2197 +should restore the original file state after an error happens.
2198 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2199 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2200 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2019-07-11 15:42:14.458904362 +0200
2203 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2205 +# This program is free software; you can redistribute it and/or modify
2206 +# it under the terms of the GNU General Public License as published by
2207 +# the Free Software Foundation; either version 2 of the License, or
2208 +# (at your option) any later version.
2210 +# This program is distributed in the hope that it will be useful,
2211 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2212 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2213 +# GNU General Public License for more details.
2215 +# You should have received a copy of the GNU General Public License
2216 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2218 +mmap(2) -- File Memory Mapping
2219 +----------------------------------------------------------------------
2220 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2221 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2223 +This approach is simple and good, but there is one problem.
2224 +Under /proc, several entries show the mmapped files by its path (with
2225 +device and inode number), and the printed path will be the path on the
2226 +branch fs's instead of virtual aufs's.
2227 +This is not a problem in most cases, but some utilities lsof(1) (and its
2228 +user) may expect the path on aufs.
2230 +To address this issue, aufs adds a new member called vm_prfile in struct
2231 +vm_area_struct (and struct vm_region). The original vm_file points to
2232 +the file on the branch fs in order to handle everything correctly as
2233 +usual. The new vm_prfile points to a virtual file in aufs, and the
2234 +show-functions in procfs refers to vm_prfile if it is set.
2235 +Also we need to maintain several other places where touching vm_file
2237 +- fork()/clone() copies vma and the reference count of vm_file is
2239 +- merging vma maintains the ref count too.
2241 +This is not a good approach. It just fakes the printed path. But it
2242 +leaves all behaviour around f_mapping unchanged. This is surely an
2244 +Actually aufs had adopted another complicated approach which calls
2245 +generic_file_mmap() and handles struct vm_operations_struct. In this
2246 +approach, aufs met a hard problem and I could not solve it without
2247 +switching the approach.
2249 +There may be one more another approach which is
2250 +- bind-mount the branch-root onto the aufs-root internally
2251 +- grab the new vfsmount (ie. struct mount)
2252 +- lazy-umount the branch-root internally
2253 +- in open(2) the aufs-file, open the branch-file with the hidden
2254 + vfsmount (instead of the original branch's vfsmount)
2255 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2256 + but it may be possible from userspace by the mount helper.
2258 +Adding the internal hidden vfsmount and using it in opening a file, the
2259 +file path under /proc will be printed correctly. This approach looks
2260 +smarter, but is not possible I am afraid.
2261 +- aufs-root may be bind-mount later. when it happens, another hidden
2262 + vfsmount will be required.
2263 +- it is hard to get the chance to bind-mount and lazy-umount
2264 + + in kernel-space, FS can have vfsmount in open(2) via
2265 + file->f_path, and aufs can know its vfsmount. But several locks are
2266 + already acquired, and if aufs tries to bind-mount and lazy-umount
2267 + here, then it may cause a deadlock.
2268 + + in user-space, bind-mount doesn't invoke the mount helper.
2269 +- since /proc shows dev and ino, aufs has to give vma these info. it
2270 + means a new member vm_prinode will be necessary. this is essentially
2271 + equivalent to vm_prfile described above.
2273 +I have to give up this "looks-smater" approach.
2274 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2275 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2276 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2019-07-11 15:42:14.458904362 +0200
2279 +# Copyright (C) 2014-2019 Junjiro R. Okajima
2281 +# This program is free software; you can redistribute it and/or modify
2282 +# it under the terms of the GNU General Public License as published by
2283 +# the Free Software Foundation; either version 2 of the License, or
2284 +# (at your option) any later version.
2286 +# This program is distributed in the hope that it will be useful,
2287 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2288 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2289 +# GNU General Public License for more details.
2291 +# You should have received a copy of the GNU General Public License
2292 +# along with this program; if not, write to the Free Software
2293 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2296 +Listing XATTR/EA and getting the value
2297 +----------------------------------------------------------------------
2298 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2299 +shows the values from the topmost existing file. This behaviour is good
2300 +for the non-dir entries since the bahaviour exactly matches the shown
2301 +information. But for the directories, aufs considers all the same named
2302 +entries on the lower branches. Which means, if one of the lower entry
2303 +rejects readdir call, then aufs returns an error even if the topmost
2304 +entry allows it. This behaviour is necessary to respect the branch fs's
2305 +security, but can make users confused since the user-visible standard
2306 +attributes don't match the behaviour.
2307 +To address this issue, aufs has a mount option called dirperm1 which
2308 +checks the permission for the topmost entry only, and ignores the lower
2309 +entry's permission.
2311 +A similar issue can happen around XATTR.
2312 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2313 +always set. Otherwise these very unpleasant situation would happen.
2314 +- listxattr(2) may return the duplicated entries.
2315 +- users may not be able to remove or reset the XATTR forever,
2318 +XATTR/EA support in the internal (copy,move)-(up,down)
2319 +----------------------------------------------------------------------
2320 +Generally the extended attributes of inode are categorized as these.
2321 +- "security" for LSM and capability.
2322 +- "system" for posix ACL, 'acl' mount option is required for the branch
2324 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2325 +- "user" for userspace, 'user_xattr' mount option is required for the
2326 + branch fs generally.
2328 +Moreover there are some other categories. Aufs handles these rather
2329 +unpopular categories as the ordinary ones, ie. there is no special
2330 +condition nor exception.
2332 +In copy-up, the support for XATTR on the dst branch may differ from the
2333 +src branch. In this case, the copy-up operation will get an error and
2334 +the original user operation which triggered the copy-up will fail. It
2335 +can happen that even all copy-up will fail.
2336 +When both of src and dst branches support XATTR and if an error occurs
2337 +during copying XATTR, then the copy-up should fail obviously. That is a
2338 +good reason and aufs should return an error to userspace. But when only
2339 +the src branch support that XATTR, aufs should not return an error.
2340 +For example, the src branch supports ACL but the dst branch doesn't
2341 +because the dst branch may natively un-support it or temporary
2342 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2343 +may NOT return an error even if the XATTR is not supported. It is
2344 +totally up to the branch fs.
2346 +Anyway when the aufs internal copy-up gets an error from the dst branch
2347 +fs, then aufs tries removing the just copied entry and returns the error
2348 +to the userspace. The worst case of this situation will be all copy-up
2351 +For the copy-up operation, there two basic approaches.
2352 +- copy the specified XATTR only (by category above), and return the
2353 + error unconditionally if it happens.
2354 +- copy all XATTR, and ignore the error on the specified category only.
2356 +In order to support XATTR and to implement the correct behaviour, aufs
2357 +chooses the latter approach and introduces some new branch attributes,
2358 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2359 +They correspond to the XATTR namespaces (see above). Additionally, to be
2360 +convenient, "icex" is also provided which means all "icex*" attributes
2361 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2363 +The meaning of these attributes is to ignore the error from setting
2364 +XATTR on that branch.
2365 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2366 +error from the dst branch according to the specified attributes.
2368 +Some XATTR may have its default value. The default value may come from
2369 +the parent dir or the environment. If the default value is set at the
2370 +file creating-time, it will be overwritten by copy-up.
2371 +Some contradiction may happen I am afraid.
2372 +Do we need another attribute to stop copying XATTR? I am unsure. For
2373 +now, aufs implements the branch attributes to ignore the error.
2374 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2375 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2376 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2019-07-11 15:42:14.458904362 +0200
2379 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2381 +# This program is free software; you can redistribute it and/or modify
2382 +# it under the terms of the GNU General Public License as published by
2383 +# the Free Software Foundation; either version 2 of the License, or
2384 +# (at your option) any later version.
2386 +# This program is distributed in the hope that it will be useful,
2387 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2388 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2389 +# GNU General Public License for more details.
2391 +# You should have received a copy of the GNU General Public License
2392 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2394 +Export Aufs via NFS
2395 +----------------------------------------------------------------------
2396 +Here is an approach.
2397 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2399 +- iget_locked(): initialize aufs inode generation for a new inode, and
2400 + store it in xigen file.
2401 +- destroy_inode(): increment aufs inode generation and store it in xigen
2402 + file. it is necessary even if it is not unlinked, because any data of
2403 + inode may be changed by UDBA.
2404 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2405 + build file handle by
2406 + + branch id (4 bytes)
2407 + + superblock generation (4 bytes)
2408 + + inode number (4 or 8 bytes)
2409 + + parent dir inode number (4 or 8 bytes)
2410 + + inode generation (4 bytes))
2411 + + return value of exportfs_encode_fh() for the parent on a branch (4
2413 + + file handle for a branch (by exportfs_encode_fh())
2415 + + find the index of a branch from its id in handle, and check it is
2416 + still exist in aufs.
2417 + + 1st level: get the inode number from handle and search it in cache.
2418 + + 2nd level: if not found in cache, get the parent inode number from
2419 + the handle and search it in cache. and then open the found parent
2420 + dir, find the matching inode number by vfs_readdir() and get its
2421 + name, and call lookup_one_len() for the target dentry.
2422 + + 3rd level: if the parent dir is not cached, call
2423 + exportfs_decode_fh() for a branch and get the parent on a branch,
2424 + build a pathname of it, convert it a pathname in aufs, call
2425 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2427 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2428 + for every branch, but not itself. to get this, (currently) aufs
2429 + searches in current->nsproxy->mnt_ns list. it may not be a good
2430 + idea, but I didn't get other approach.
2431 + + test the generation of the gotten inode.
2432 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2433 + convert it into ESTALE for NFSD.
2434 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2435 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2436 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2437 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2438 +++ linux/Documentation/filesystems/aufs/design/08shwh.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 +Show Whiteout Mode (shwh)
2457 +----------------------------------------------------------------------
2458 +Generally aufs hides the name of whiteouts. But in some cases, to show
2459 +them is very useful for users. For instance, creating a new middle layer
2460 +(branch) by merging existing layers.
2462 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2463 +When you have three branches,
2464 +- Bottom: 'system', squashfs (underlying base system), read-only
2465 +- Middle: 'mods', squashfs, read-only
2466 +- Top: 'overlay', ram (tmpfs), read-write
2468 +The top layer is loaded at boot time and saved at shutdown, to preserve
2469 +the changes made to the system during the session.
2470 +When larger changes have been made, or smaller changes have accumulated,
2471 +the size of the saved top layer data grows. At this point, it would be
2472 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2473 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2474 +restoring save and load speed.
2476 +This merging is simplified by the use of another aufs mount, of just the
2477 +two overlay branches using the 'shwh' option.
2478 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2479 + aufs /livesys/merge_union
2481 +A merged view of these two branches is then available at
2482 +/livesys/merge_union, and the new feature is that the whiteouts are
2484 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2485 +writing to all branches. Also the default mode for all branches is 'ro'.
2486 +It is now possible to save the combined contents of the two overlay
2487 +branches to a new squashfs, e.g.:
2488 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2490 +This new squashfs archive can be stored on the boot device and the
2491 +initramfs will use it to replace the old one at the next boot.
2492 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2493 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2494 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2019-07-11 15:42:14.458904362 +0200
2497 +# Copyright (C) 2010-2019 Junjiro R. Okajima
2499 +# This program is free software; you can redistribute it and/or modify
2500 +# it under the terms of the GNU General Public License as published by
2501 +# the Free Software Foundation; either version 2 of the License, or
2502 +# (at your option) any later version.
2504 +# This program is distributed in the hope that it will be useful,
2505 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2506 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2507 +# GNU General Public License for more details.
2509 +# You should have received a copy of the GNU General Public License
2510 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2512 +Dynamically customizable FS operations
2513 +----------------------------------------------------------------------
2514 +Generally FS operations (struct inode_operations, struct
2515 +address_space_operations, struct file_operations, etc.) are defined as
2516 +"static const", but it never means that FS have only one set of
2517 +operation. Some FS have multiple sets of them. For instance, ext2 has
2518 +three sets, one for XIP, for NOBH, and for normal.
2519 +Since aufs overrides and redirects these operations, sometimes aufs has
2520 +to change its behaviour according to the branch FS type. More importantly
2521 +VFS acts differently if a function (member in the struct) is set or
2522 +not. It means aufs should have several sets of operations and select one
2523 +among them according to the branch FS definition.
2525 +In order to solve this problem and not to affect the behaviour of VFS,
2526 +aufs defines these operations dynamically. For instance, aufs defines
2527 +dummy direct_IO function for struct address_space_operations, but it may
2528 +not be set to the address_space_operations actually. When the branch FS
2529 +doesn't have it, aufs doesn't set it to its address_space_operations
2530 +while the function definition itself is still alive. So the behaviour
2531 +itself will not change, and it will return an error when direct_IO is
2534 +The lifetime of these dynamically generated operation object is
2535 +maintained by aufs branch object. When the branch is removed from aufs,
2536 +the reference counter of the object is decremented. When it reaches
2537 +zero, the dynamically generated operation object will be freed.
2539 +This approach is designed to support AIO (io_submit), Direct I/O and
2541 +Currently this approach is applied to address_space_operations for
2542 +regular files only.
2543 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2544 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2545 +++ linux/Documentation/filesystems/aufs/README 2019-07-11 15:42:14.455570938 +0200
2548 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2554 +----------------------------------------
2555 +In the early days, aufs was entirely re-designed and re-implemented
2556 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2557 +improvements and implementations, it became totally different from
2558 +Unionfs while keeping the basic features.
2559 +Later, Unionfs Version 2.x series began taking some of the same
2560 +approaches to aufs1's.
2561 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2562 +University and his team.
2564 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2566 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2567 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2568 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2569 + or aufs1 from CVS on SourceForge.
2571 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2572 + According to Christoph Hellwig, linux rejects all union-type
2573 + filesystems but UnionMount.
2574 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2576 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2577 + UnionMount, and he pointed out an issue around a directory mutex
2578 + lock and aufs addressed it. But it is still unsure whether aufs will
2579 + be merged (or any other union solution).
2580 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2584 +----------------------------------------
2585 +- unite several directories into a single virtual filesystem. The member
2586 + directory is called as a branch.
2587 +- you can specify the permission flags to the branch, which are 'readonly',
2588 + 'readwrite' and 'whiteout-able.'
2589 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2590 + readonly branch are modifiable logically.
2591 +- dynamic branch manipulation, add, del.
2594 +Also there are many enhancements in aufs, such as:
2595 +- test only the highest one for the directory permission (dirperm1)
2596 +- copyup on open (coo=)
2597 +- 'move' policy for copy-up between two writable branches, after
2598 + checking free space.
2600 +- readdir(3) in userspace.
2601 +- keep inode number by external inode number table
2602 +- keep the timestamps of file/dir in internal copyup operation
2603 +- seekable directory, supporting NFS readdir.
2604 +- whiteout is hardlinked in order to reduce the consumption of inodes
2606 +- do not copyup, nor create a whiteout when it is unnecessary
2607 +- revert a single systemcall when an error occurs in aufs
2608 +- remount interface instead of ioctl
2609 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2610 +- loopback mounted filesystem as a branch
2611 +- kernel thread for removing the dir who has a plenty of whiteouts
2612 +- support copyup sparse file (a file which has a 'hole' in it)
2613 +- default permission flags for branches
2614 +- selectable permission flags for ro branch, whether whiteout can
2617 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2618 +- support multiple writable branches, some policies to select one
2619 + among multiple writable branches.
2620 +- a new semantics for link(2) and rename(2) to support multiple
2621 + writable branches.
2622 +- no glibc changes are required.
2623 +- pseudo hardlink (hardlink over branches)
2624 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2625 + including NFS or remote filesystem branch.
2626 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2629 +Currently these features are dropped temporary from aufs5.
2630 +See design/08plan.txt in detail.
2631 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2633 +- statistics of aufs thread (/sys/fs/aufs/stat)
2635 +Features or just an idea in the future (see also design/*.txt),
2636 +- reorder the branch index without del/re-add.
2637 +- permanent xino files for NFSD
2638 +- an option for refreshing the opened files after add/del branches
2639 +- light version, without branch manipulation. (unnecessary?)
2640 +- copyup in userspace
2641 +- inotify in userspace
2646 +----------------------------------------
2647 +There are three GIT trees for aufs5, aufs5-linux.git,
2648 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2650 +While the aufs-util is always necessary, you need either of aufs5-linux
2651 +or aufs5-standalone.
2653 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2654 +git://git.kernel.org/.../torvalds/linux.git.
2655 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2656 +build aufs5 as an external kernel module.
2657 +Several extra patches are not included in this tree. Only
2658 +aufs5-standalone tree contains them. They are described in the later
2659 +section "Configuration and Compilation."
2661 +On the other hand, the aufs5-standalone tree has only aufs source files
2662 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2663 +But you need to apply all aufs patches manually.
2665 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2666 +represents the linux kernel version, "linux-5.x". For instance,
2667 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2668 +"aufs5.x-rcN" branch.
2671 +$ git clone --reference /your/linux/git/tree \
2672 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2673 +- if you don't have linux GIT tree, then remove "--reference ..."
2674 +$ cd aufs5-linux.git
2675 +$ git checkout origin/aufs5.0
2677 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2678 +leave the patch-work to GIT.
2679 +$ cd /your/linux/git/tree
2680 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2682 +$ git checkout -b my5.0 v5.0
2683 +$ (add your local change...)
2684 +$ git pull aufs5 aufs5.0
2685 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2686 +- you may need to solve some conflicts between your_changes and
2687 + aufs5.0. in this case, git-rerere is recommended so that you can
2688 + solve the similar conflicts automatically when you upgrade to 5.1 or
2689 + later in the future.
2691 +o aufs5-standalone tree
2692 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2693 +$ cd aufs5-standalone.git
2694 +$ git checkout origin/aufs5.0
2697 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2698 +- note that the public aufs-util.git is on SourceForge instead of
2701 +$ git checkout origin/aufs5.0
2703 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2704 +The minor version number, 'x' in '5.x', of aufs may not always
2705 +follow the minor version number of the kernel.
2706 +Because changes in the kernel that cause the use of a new
2707 +minor version number do not always require changes to aufs-util.
2709 +Since aufs-util has its own minor version number, you may not be
2710 +able to find a GIT branch in aufs-util for your kernel's
2711 +exact minor version number.
2712 +In this case, you should git-checkout the branch for the
2713 +nearest lower number.
2715 +For (an unreleased) example:
2716 +If you are using "linux-5.10" and the "aufs5.10" branch
2717 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2718 +or something numerically smaller is the branch for your kernel.
2720 +Also you can view all branches by
2724 +3. Configuration and Compilation
2725 +----------------------------------------
2726 +Make sure you have git-checkout'ed the correct branch.
2728 +For aufs5-linux tree,
2729 +- enable CONFIG_AUFS_FS.
2730 +- set other aufs configurations if necessary.
2732 +For aufs5-standalone tree,
2733 +There are several ways to build.
2736 +- apply ./aufs5-kbuild.patch to your kernel source files.
2737 +- apply ./aufs5-base.patch too.
2738 +- apply ./aufs5-mmap.patch too.
2739 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2740 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2741 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2742 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2743 +- enable CONFIG_AUFS_FS, you can select either
2745 +- and build your kernel as usual.
2746 +- install the built kernel.
2747 +- install the header files too by "make headers_install" to the
2748 + directory where you specify. By default, it is $PWD/usr.
2749 + "make help" shows a brief note for headers_install.
2750 +- and reboot your system.
2753 +- module only (CONFIG_AUFS_FS=m).
2754 +- apply ./aufs5-base.patch to your kernel source files.
2755 +- apply ./aufs5-mmap.patch too.
2756 +- apply ./aufs5-standalone.patch too.
2757 +- build your kernel, don't forget "make headers_install", and reboot.
2758 +- edit ./config.mk and set other aufs configurations if necessary.
2759 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2760 + every aufs configurations.
2761 +- build the module by simple "make".
2762 +- you can specify ${KDIR} make variable which points to your kernel
2764 +- install the files
2765 + + run "make install" to install the aufs module, or copy the built
2766 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2767 + + run "make install_headers" (instead of headers_install) to install
2768 + the modified aufs header file (you can specify DESTDIR which is
2769 + available in aufs standalone version's Makefile only), or copy
2770 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2771 + you like manually. By default, the target directory is $PWD/usr.
2772 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2773 + kernel source tree.
2775 +Note: The header file aufs_type.h is necessary to build aufs-util
2776 + as well as "make headers_install" in the kernel source tree.
2777 + headers_install is subject to be forgotten, but it is essentially
2778 + necessary, not only for building aufs-util.
2779 + You may not meet problems without headers_install in some older
2783 +- read README in aufs-util, build and install it
2784 +- note that your distribution may contain an obsoleted version of
2785 + aufs_type.h in /usr/include/linux or something. When you build aufs
2786 + utilities, make sure that your compiler refers the correct aufs header
2787 + file which is built by "make headers_install."
2788 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2789 + then run "make install_ulib" too. And refer to the aufs manual in
2792 +There several other patches in aufs5-standalone.git. They are all
2793 +optional. When you meet some problems, they will help you.
2794 +- aufs5-loopback.patch
2795 + Supports a nested loopback mount in a branch-fs. This patch is
2796 + unnecessary until aufs produces a message like "you may want to try
2797 + another patch for loopback file".
2798 +- proc_mounts.patch
2799 + When there are many mountpoints and many mount(2)/umount(2) are
2800 + running, then /proc/mounts may not show the all mountpoints. This
2801 + patch makes /proc/mounts always show the full mountpoints list.
2802 + If you don't want to apply this patch and meet such problem, then you
2803 + need to increase the value of 'ProcMounts_Times' make-variable in
2804 + aufs-util.git as a second best solution.
2806 + Modifies a system global kernel internal function get_next_ino() in
2807 + order to stop assigning 0 for an inode-number. Not directly related to
2808 + aufs, but recommended generally.
2810 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2811 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2812 + duplication of inode number, which is important for backup tools and
2813 + other utilities. When you find aufs XINO files for tmpfs branch
2814 + growing too much, try this patch.
2815 +- lockdep-debug.patch
2816 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2817 + also a caller of VFS functions for branch filesystems, subclassing of
2818 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2819 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2820 + need to apply this debug patch to expand several constant values.
2821 + If don't know what LOCKDEP is, then you don't have apply this patch.
2825 +----------------------------------------
2826 +At first, make sure aufs-util are installed, and please read the aufs
2827 +manual, aufs.5 in aufs-util.git tree.
2831 +$ mkdir /tmp/rw /tmp/aufs
2832 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2834 +Here is another example. The result is equivalent.
2835 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2837 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2838 +# mount -o remount,append:${HOME} /tmp/aufs
2840 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2841 +you modify a file under /tmp/aufs, the one on your home directory is
2842 +not affected, instead the same named file will be newly created under
2843 +/tmp/rw. And all of your modification to a file will be applied to
2844 +the one under /tmp/rw. This is called the file based Copy on Write
2846 +Aufs mount options are described in aufs.5.
2847 +If you run chroot or something and make your aufs as a root directory,
2848 +then you need to customize the shutdown script. See the aufs manual in
2851 +Additionally, there are some sample usages of aufs which are a
2852 +diskless system with network booting, and LiveCD over NFS.
2853 +See sample dir in CVS tree on SourceForge.
2857 +----------------------------------------
2858 +When you have any problems or strange behaviour in aufs, please let me
2860 +- /proc/mounts (instead of the output of mount(8))
2861 +- /sys/module/aufs/*
2862 +- /sys/fs/aufs/* (if you have them)
2863 +- /debug/aufs/* (if you have them)
2864 +- linux kernel version
2865 + if your kernel is not plain, for example modified by distributor,
2866 + the url where i can download its source is necessary too.
2867 +- aufs version which was printed at loading the module or booting the
2868 + system, instead of the date you downloaded.
2869 +- configuration (define/undefine CONFIG_AUFS_xxx)
2870 +- kernel configuration or /proc/config.gz (if you have it)
2871 +- behaviour which you think to be incorrect
2872 +- actual operation, reproducible one is better
2873 +- mailto: aufs-users at lists.sourceforge.net
2875 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2876 +and Feature Requests) on SourceForge. Please join and write to
2880 +6. Acknowledgements
2881 +----------------------------------------
2882 +Thanks to everyone who have tried and are using aufs, whoever
2883 +have reported a bug or any feedback.
2885 +Especially donators:
2886 +Tomas Matejicek(slax.org) made a donation (much more than once).
2887 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2888 + scripts) is making "doubling" donations.
2889 + Unfortunately I cannot list all of the donators, but I really
2891 + It ends Aug 2010, but the ordinary donation URL is still available.
2892 + <http://sourceforge.net/donate/index.php?group_id=167503>
2893 +Dai Itasaka made a donation (2007/8).
2894 +Chuck Smith made a donation (2008/4, 10 and 12).
2895 +Henk Schoneveld made a donation (2008/9).
2896 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2897 +Francois Dupoux made a donation (2008/11).
2898 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2899 + aufs2 GIT tree (2009/2).
2900 +William Grant made a donation (2009/3).
2901 +Patrick Lane made a donation (2009/4).
2902 +The Mail Archive (mail-archive.com) made donations (2009/5).
2903 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2904 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2905 +Pavel Pronskiy made a donation (2011/2).
2906 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2907 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2908 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2910 +Sam Liddicott made a donation (2011/9).
2911 +Era Scarecrow made a donation (2013/4).
2912 +Bor Ratajc made a donation (2013/4).
2913 +Alessandro Gorreta made a donation (2013/4).
2914 +POIRETTE Marc made a donation (2013/4).
2915 +Alessandro Gorreta made a donation (2013/4).
2916 +lauri kasvandik made a donation (2013/5).
2917 +"pemasu from Finland" made a donation (2013/7).
2918 +The Parted Magic Project made a donation (2013/9 and 11).
2919 +Pavel Barta made a donation (2013/10).
2920 +Nikolay Pertsev made a donation (2014/5).
2921 +James B made a donation (2014/7 and 2015/7).
2922 +Stefano Di Biase made a donation (2014/8).
2923 +Daniel Epellei made a donation (2015/1).
2924 +OmegaPhil made a donation (2016/1, 2018/4).
2925 +Tomasz Szewczyk made a donation (2016/4).
2926 +James Burry made a donation (2016/12).
2927 +Carsten Rose made a donation (2018/9).
2928 +Porteus Kiosk made a donation (2018/10).
2930 +Thank you very much.
2931 +Donations are always, including future donations, very important and
2932 +helpful for me to keep on developing aufs.
2936 +----------------------------------------
2937 +If you are an experienced user, no explanation is needed. Aufs is
2938 +just a linux filesystem.
2943 +# Local variables: ;
2946 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2947 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2948 +++ linux/fs/aufs/aufs.h 2019-07-11 15:42:14.462237786 +0200
2950 +/* SPDX-License-Identifier: GPL-2.0 */
2952 + * Copyright (C) 2005-2019 Junjiro R. Okajima
2954 + * This program, aufs is free software; you can redistribute it and/or modify
2955 + * it under the terms of the GNU General Public License as published by
2956 + * the Free Software Foundation; either version 2 of the License, or
2957 + * (at your option) any later version.
2959 + * This program is distributed in the hope that it will be useful,
2960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2962 + * GNU General Public License for more details.
2964 + * You should have received a copy of the GNU General Public License
2965 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2969 + * all header files
2977 +#define AuStub(type, name, body, ...) \
2978 + static inline type name(__VA_ARGS__) { body; }
2980 +#define AuStubVoid(name, ...) \
2981 + AuStub(void, name, , __VA_ARGS__)
2982 +#define AuStubInt0(name, ...) \
2983 + AuStub(int, name, return 0, __VA_ARGS__)
2987 +#include "branch.h"
2990 +#include "dbgaufs.h"
2991 +#include "dentry.h"
2993 +#include "dirren.h"
2996 +#include "fstype.h"
3001 +#include "module.h"
3005 +#include "sysaufs.h"
3010 +#endif /* __KERNEL__ */
3011 +#endif /* __AUFS_H__ */
3012 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3013 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3014 +++ linux/fs/aufs/branch.c 2019-09-16 09:38:43.216175640 +0200
3016 +// SPDX-License-Identifier: GPL-2.0
3018 + * Copyright (C) 2005-2019 Junjiro R. Okajima
3020 + * This program, aufs is free software; you can redistribute it and/or modify
3021 + * it under the terms of the GNU General Public License as published by
3022 + * the Free Software Foundation; either version 2 of the License, or
3023 + * (at your option) any later version.
3025 + * This program is distributed in the hope that it will be useful,
3026 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3027 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3028 + * GNU General Public License for more details.
3030 + * You should have received a copy of the GNU General Public License
3031 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3035 + * branch management
3038 +#include <linux/compat.h>
3039 +#include <linux/statfs.h>
3043 + * free a single branch
3045 +static void au_br_do_free(struct au_branch *br)
3048 + struct au_wbr *wbr;
3049 + struct au_dykey **key;
3051 + au_hnotify_fin_br(br);
3052 + /* always, regardless the mount option */
3053 + au_dr_hino_free(&br->br_dirren);
3056 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3057 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3058 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3059 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3063 + for (i = 0; i < AuBrWh_Last; i++)
3064 + dput(wbr->wbr_wh[i]);
3065 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3066 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3069 + if (br->br_fhsm) {
3070 + au_br_fhsm_fin(br->br_fhsm);
3071 + au_kfree_try_rcu(br->br_fhsm);
3074 + key = br->br_dykey;
3075 + for (i = 0; i < AuBrDynOp; i++, key++)
3081 + /* recursive lock, s_umount of branch's */
3082 + /* synchronize_rcu(); */ /* why? */
3084 + path_put(&br->br_path);
3086 + au_kfree_rcu(wbr);
3087 + au_lcnt_wait_for_fin(&br->br_nfiles);
3088 + au_lcnt_wait_for_fin(&br->br_count);
3089 + /* I don't know why, but percpu_refcount requires this */
3090 + /* synchronize_rcu(); */
3095 + * frees all branches
3097 +void au_br_free(struct au_sbinfo *sbinfo)
3099 + aufs_bindex_t bmax;
3100 + struct au_branch **br;
3102 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3104 + bmax = sbinfo->si_bbot + 1;
3105 + br = sbinfo->si_branch;
3107 + au_br_do_free(*br++);
3111 + * find the index of a branch which is specified by @br_id.
3113 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3115 + aufs_bindex_t bindex, bbot;
3117 + bbot = au_sbbot(sb);
3118 + for (bindex = 0; bindex <= bbot; bindex++)
3119 + if (au_sbr_id(sb, bindex) == br_id)
3124 +/* ---------------------------------------------------------------------- */
3130 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3131 + struct dentry *h_root)
3133 + if (unlikely(h_adding == h_root
3134 + || au_test_loopback_overlap(sb, h_adding)))
3136 + if (h_adding->d_sb != h_root->d_sb)
3138 + return au_test_subdir(h_adding, h_root)
3139 + || au_test_subdir(h_root, h_adding);
3143 + * returns a newly allocated branch. @new_nbranch is a number of branches
3144 + * after adding a branch.
3146 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3149 + struct au_branch *add_branch;
3150 + struct dentry *root;
3151 + struct inode *inode;
3155 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3156 + if (unlikely(!add_branch))
3158 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3159 + if (unlikely(!add_branch->br_xino))
3161 + err = au_hnotify_init_br(add_branch, perm);
3162 + if (unlikely(err))
3165 + if (au_br_writable(perm)) {
3166 + /* may be freed separately at changing the branch permission */
3167 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3169 + if (unlikely(!add_branch->br_wbr))
3173 + if (au_br_fhsm(perm)) {
3174 + err = au_fhsm_br_alloc(add_branch);
3175 + if (unlikely(err))
3179 + root = sb->s_root;
3180 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3182 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3184 + inode = d_inode(root);
3185 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3189 + return add_branch; /* success */
3192 + au_kfree_rcu(add_branch->br_wbr);
3194 + au_hnotify_fin_br(add_branch);
3196 + au_xino_put(add_branch);
3198 + au_kfree_rcu(add_branch);
3200 + return ERR_PTR(err);
3204 + * test if the branch permission is legal or not.
3206 +static int test_br(struct inode *inode, int brperm, char *path)
3210 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3215 + pr_err("write permission for readonly mount or inode, %s\n", path);
3223 + * 0: success, the caller will add it
3224 + * plus: success, it is already unified, the caller should ignore it
3227 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3230 + aufs_bindex_t bbot, bindex;
3231 + struct dentry *root, *h_dentry;
3232 + struct inode *inode, *h_inode;
3234 + root = sb->s_root;
3235 + bbot = au_sbbot(sb);
3236 + if (unlikely(bbot >= 0
3237 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3241 + pr_err("%s duplicated\n", add->pathname);
3246 + err = -ENOSPC; /* -E2BIG; */
3247 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3248 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3249 + pr_err("number of branches exceeded %s\n", add->pathname);
3254 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3255 + pr_err("bad index %d\n", add->bindex);
3259 + inode = d_inode(add->path.dentry);
3261 + if (unlikely(!inode->i_nlink)) {
3262 + pr_err("no existence %s\n", add->pathname);
3267 + if (unlikely(inode->i_sb == sb)) {
3268 + pr_err("%s must be outside\n", add->pathname);
3272 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3273 + pr_err("unsupported filesystem, %s (%s)\n",
3274 + add->pathname, au_sbtype(inode->i_sb));
3278 + if (unlikely(inode->i_sb->s_stack_depth)) {
3279 + pr_err("already stacked, %s (%s)\n",
3280 + add->pathname, au_sbtype(inode->i_sb));
3284 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3285 + if (unlikely(err))
3289 + return 0; /* success */
3292 + for (bindex = 0; bindex <= bbot; bindex++)
3293 + if (unlikely(test_overlap(sb, add->path.dentry,
3294 + au_h_dptr(root, bindex)))) {
3295 + pr_err("%s is overlapped\n", add->pathname);
3300 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3301 + h_dentry = au_h_dptr(root, 0);
3302 + h_inode = d_inode(h_dentry);
3303 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3304 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3305 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3306 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3308 + i_uid_read(inode), i_gid_read(inode),
3309 + (inode->i_mode & S_IALLUGO),
3310 + i_uid_read(h_inode), i_gid_read(h_inode),
3311 + (h_inode->i_mode & S_IALLUGO));
3319 + * initialize or clean the whiteouts for an adding branch
3321 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3324 + int err, old_perm;
3325 + aufs_bindex_t bindex;
3326 + struct inode *h_inode;
3327 + struct au_wbr *wbr;
3328 + struct au_hinode *hdir;
3329 + struct dentry *h_dentry;
3331 + err = vfsub_mnt_want_write(au_br_mnt(br));
3332 + if (unlikely(err))
3336 + old_perm = br->br_perm;
3337 + br->br_perm = new_perm;
3340 + bindex = au_br_index(sb, br->br_id);
3341 + if (0 <= bindex) {
3342 + hdir = au_hi(d_inode(sb->s_root), bindex);
3343 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3345 + h_dentry = au_br_dentry(br);
3346 + h_inode = d_inode(h_dentry);
3347 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3350 + err = au_wh_init(br, sb);
3352 + wbr_wh_write_lock(wbr);
3353 + err = au_wh_init(br, sb);
3354 + wbr_wh_write_unlock(wbr);
3357 + au_hn_inode_unlock(hdir);
3359 + inode_unlock(h_inode);
3360 + vfsub_mnt_drop_write(au_br_mnt(br));
3361 + br->br_perm = old_perm;
3363 + if (!err && wbr && !au_br_writable(new_perm)) {
3364 + au_kfree_rcu(wbr);
3365 + br->br_wbr = NULL;
3372 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3376 + struct kstatfs kst;
3377 + struct au_wbr *wbr;
3380 + au_rw_init(&wbr->wbr_wh_rwsem);
3381 + atomic_set(&wbr->wbr_wh_running, 0);
3384 + * a limit for rmdir/rename a dir
3385 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3387 + err = vfs_statfs(&br->br_path, &kst);
3388 + if (unlikely(err))
3391 + if (kst.f_namelen >= NAME_MAX)
3392 + err = au_br_init_wh(sb, br, perm);
3394 + pr_err("%pd(%s), unsupported namelen %ld\n",
3396 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3402 +/* initialize a new branch */
3403 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3404 + struct au_opt_add *add)
3407 + struct au_branch *brbase;
3409 + struct inode *h_inode;
3412 + br->br_perm = add->perm;
3413 + br->br_path = add->path; /* set first, path_get() later */
3414 + spin_lock_init(&br->br_dykey_lock);
3415 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3416 + au_lcnt_init(&br->br_count, /*release*/NULL);
3417 + br->br_id = au_new_br_id(sb);
3418 + AuDebugOn(br->br_id < 0);
3420 + /* always, regardless the given option */
3421 + err = au_dr_br_init(sb, br, &add->path);
3422 + if (unlikely(err))
3425 + if (au_br_writable(add->perm)) {
3426 + err = au_wbr_init(br, sb, add->perm);
3427 + if (unlikely(err))
3431 + if (au_opt_test(au_mntflags(sb), XINO)) {
3432 + brbase = au_sbr(sb, 0);
3433 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3435 + h_inode = d_inode(add->path.dentry);
3436 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3437 + if (unlikely(err)) {
3438 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3443 + sysaufs_br_init(br);
3444 + path_get(&br->br_path);
3445 + goto out; /* success */
3448 + memset(&br->br_path, 0, sizeof(br->br_path));
3453 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3454 + struct au_branch *br, aufs_bindex_t bbot,
3455 + aufs_bindex_t amount)
3457 + struct au_branch **brp;
3459 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3461 + brp = sbinfo->si_branch + bindex;
3462 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3464 + sbinfo->si_bbot++;
3465 + if (unlikely(bbot < 0))
3466 + sbinfo->si_bbot = 0;
3469 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3470 + aufs_bindex_t bbot, aufs_bindex_t amount)
3472 + struct au_hdentry *hdp;
3474 + AuRwMustWriteLock(&dinfo->di_rwsem);
3476 + hdp = au_hdentry(dinfo, bindex);
3477 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3478 + au_h_dentry_init(hdp);
3480 + if (unlikely(bbot < 0))
3481 + dinfo->di_btop = 0;
3484 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3485 + aufs_bindex_t bbot, aufs_bindex_t amount)
3487 + struct au_hinode *hip;
3489 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3491 + hip = au_hinode(iinfo, bindex);
3492 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3493 + au_hinode_init(hip);
3495 + if (unlikely(bbot < 0))
3496 + iinfo->ii_btop = 0;
3499 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3500 + aufs_bindex_t bindex)
3502 + struct dentry *root, *h_dentry;
3503 + struct inode *root_inode, *h_inode;
3504 + aufs_bindex_t bbot, amount;
3506 + root = sb->s_root;
3507 + root_inode = d_inode(root);
3508 + bbot = au_sbbot(sb);
3509 + amount = bbot + 1 - bindex;
3510 + h_dentry = au_br_dentry(br);
3511 + au_sbilist_lock();
3512 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3513 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3514 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3515 + au_set_h_dptr(root, bindex, dget(h_dentry));
3516 + h_inode = d_inode(h_dentry);
3517 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3518 + au_sbilist_unlock();
3521 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3524 + aufs_bindex_t bbot, add_bindex;
3525 + struct dentry *root, *h_dentry;
3526 + struct inode *root_inode;
3527 + struct au_branch *add_branch;
3529 + root = sb->s_root;
3530 + root_inode = d_inode(root);
3531 + IMustLock(root_inode);
3532 + IiMustWriteLock(root_inode);
3533 + err = test_add(sb, add, remount);
3534 + if (unlikely(err < 0))
3538 + goto out; /* success */
3541 + bbot = au_sbbot(sb);
3542 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3543 + err = PTR_ERR(add_branch);
3544 + if (IS_ERR(add_branch))
3547 + err = au_br_init(add_branch, sb, add);
3548 + if (unlikely(err)) {
3549 + au_br_do_free(add_branch);
3553 + add_bindex = add->bindex;
3554 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3555 + au_br_do_add(sb, add_branch, add_bindex);
3556 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3557 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3559 + h_dentry = add->path.dentry;
3560 + if (!add_bindex) {
3561 + au_cpup_attr_all(root_inode, /*force*/1);
3562 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3564 + au_add_nlink(root_inode, d_inode(h_dentry));
3570 +/* ---------------------------------------------------------------------- */
3572 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3573 + unsigned long long max __maybe_unused,
3576 + unsigned long long n;
3577 + struct file **p, *f;
3578 + struct hlist_bl_head *files;
3579 + struct hlist_bl_node *pos;
3580 + struct au_finfo *finfo;
3584 + files = &au_sbi(sb)->si_files;
3585 + hlist_bl_lock(files);
3586 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3587 + f = finfo->fi_file;
3589 + && !special_file(file_inode(f)->i_mode)) {
3593 + AuDebugOn(n > max);
3596 + hlist_bl_unlock(files);
3601 +static struct file **au_farray_alloc(struct super_block *sb,
3602 + unsigned long long *max)
3604 + struct au_sbinfo *sbi;
3607 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3608 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3611 +static void au_farray_free(struct file **a, unsigned long long max)
3613 + unsigned long long ull;
3615 + for (ull = 0; ull < max; ull++)
3621 +/* ---------------------------------------------------------------------- */
3627 +/* to show the line number, do not make it inlined function */
3628 +#define AuVerbose(do_info, fmt, ...) do { \
3630 + pr_info(fmt, ##__VA_ARGS__); \
3633 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3634 + aufs_bindex_t bbot)
3636 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3639 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3640 + aufs_bindex_t bbot)
3642 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3646 + * test if the branch is deletable or not.
3648 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3649 + unsigned int sigen, const unsigned int verbose)
3651 + int err, i, j, ndentry;
3652 + aufs_bindex_t btop, bbot;
3653 + struct au_dcsub_pages dpages;
3654 + struct au_dpage *dpage;
3657 + err = au_dpages_init(&dpages, GFP_NOFS);
3658 + if (unlikely(err))
3660 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3661 + if (unlikely(err))
3664 + for (i = 0; !err && i < dpages.ndpage; i++) {
3665 + dpage = dpages.dpages + i;
3666 + ndentry = dpage->ndentry;
3667 + for (j = 0; !err && j < ndentry; j++) {
3668 + d = dpage->dentries[j];
3669 + AuDebugOn(au_dcount(d) <= 0);
3670 + if (!au_digen_test(d, sigen)) {
3671 + di_read_lock_child(d, AuLock_IR);
3672 + if (unlikely(au_dbrange_test(d))) {
3673 + di_read_unlock(d, AuLock_IR);
3677 + di_write_lock_child(d);
3678 + if (unlikely(au_dbrange_test(d))) {
3679 + di_write_unlock(d);
3682 + err = au_reval_dpath(d, sigen);
3684 + di_downgrade_lock(d, AuLock_IR);
3686 + di_write_unlock(d);
3691 + /* AuDbgDentry(d); */
3692 + btop = au_dbtop(d);
3693 + bbot = au_dbbot(d);
3694 + if (btop <= bindex
3696 + && au_h_dptr(d, bindex)
3697 + && au_test_dbusy(d, btop, bbot)) {
3699 + AuVerbose(verbose, "busy %pd\n", d);
3702 + di_read_unlock(d, AuLock_IR);
3707 + au_dpages_free(&dpages);
3712 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3713 + unsigned int sigen, const unsigned int verbose)
3716 + unsigned long long max, ull;
3717 + struct inode *i, **array;
3718 + aufs_bindex_t btop, bbot;
3720 + array = au_iarray_alloc(sb, &max);
3721 + err = PTR_ERR(array);
3722 + if (IS_ERR(array))
3726 + AuDbg("b%d\n", bindex);
3727 + for (ull = 0; !err && ull < max; ull++) {
3731 + if (i->i_ino == AUFS_ROOT_INO)
3734 + /* AuDbgInode(i); */
3735 + if (au_iigen(i, NULL) == sigen)
3736 + ii_read_lock_child(i);
3738 + ii_write_lock_child(i);
3739 + err = au_refresh_hinode_self(i);
3742 + ii_downgrade_lock(i);
3744 + ii_write_unlock(i);
3749 + btop = au_ibtop(i);
3750 + bbot = au_ibbot(i);
3751 + if (btop <= bindex
3753 + && au_h_iptr(i, bindex)
3754 + && au_test_ibusy(i, btop, bbot)) {
3756 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3759 + ii_read_unlock(i);
3761 + au_iarray_free(array, max);
3767 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3768 + const unsigned int verbose)
3771 + unsigned int sigen;
3773 + sigen = au_sigen(root->d_sb);
3774 + DiMustNoWaiters(root);
3775 + IiMustNoWaiters(d_inode(root));
3776 + di_write_unlock(root);
3777 + err = test_dentry_busy(root, bindex, sigen, verbose);
3779 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3780 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3785 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3786 + struct file **to_free, int *idx)
3789 + unsigned char matched, root;
3790 + aufs_bindex_t bindex, bbot;
3791 + struct au_fidir *fidir;
3792 + struct au_hfile *hfile;
3795 + root = IS_ROOT(file->f_path.dentry);
3798 + to_free[*idx] = file;
3804 + fidir = au_fi(file)->fi_hdir;
3805 + AuDebugOn(!fidir);
3806 + bbot = au_fbbot_dir(file);
3807 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3808 + hfile = fidir->fd_hfile + bindex;
3809 + if (!hfile->hf_file)
3812 + if (hfile->hf_br->br_id == br_id) {
3824 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3825 + struct file **to_free, int opened)
3828 + unsigned long long ull, max;
3829 + aufs_bindex_t btop;
3830 + struct file *file, **array;
3831 + struct dentry *root;
3832 + struct au_hfile *hfile;
3834 + array = au_farray_alloc(sb, &max);
3835 + err = PTR_ERR(array);
3836 + if (IS_ERR(array))
3841 + root = sb->s_root;
3842 + di_write_unlock(root);
3843 + for (ull = 0; ull < max; ull++) {
3844 + file = array[ull];
3845 + if (unlikely(!file))
3848 + /* AuDbg("%pD\n", file); */
3849 + fi_read_lock(file);
3850 + btop = au_fbtop(file);
3851 + if (!d_is_dir(file->f_path.dentry)) {
3852 + hfile = &au_fi(file)->fi_htop;
3853 + if (hfile->hf_br->br_id == br_id)
3856 + err = test_dir_busy(file, br_id, to_free, &idx);
3857 + fi_read_unlock(file);
3858 + if (unlikely(err))
3861 + di_write_lock_child(root);
3862 + au_farray_free(array, max);
3863 + AuDebugOn(idx > opened);
3869 +static void br_del_file(struct file **to_free, unsigned long long opened,
3870 + aufs_bindex_t br_id)
3872 + unsigned long long ull;
3873 + aufs_bindex_t bindex, btop, bbot, bfound;
3874 + struct file *file;
3875 + struct au_fidir *fidir;
3876 + struct au_hfile *hfile;
3878 + for (ull = 0; ull < opened; ull++) {
3879 + file = to_free[ull];
3880 + if (unlikely(!file))
3883 + /* AuDbg("%pD\n", file); */
3884 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3886 + fidir = au_fi(file)->fi_hdir;
3887 + AuDebugOn(!fidir);
3888 + fi_write_lock(file);
3889 + btop = au_fbtop(file);
3890 + bbot = au_fbbot_dir(file);
3891 + for (bindex = btop; bindex <= bbot; bindex++) {
3892 + hfile = fidir->fd_hfile + bindex;
3893 + if (!hfile->hf_file)
3896 + if (hfile->hf_br->br_id == br_id) {
3901 + AuDebugOn(bfound < 0);
3902 + au_set_h_fptr(file, bfound, NULL);
3903 + if (bfound == btop) {
3904 + for (btop++; btop <= bbot; btop++)
3905 + if (au_hf_dir(file, btop)) {
3906 + au_set_fbtop(file, btop);
3910 + fi_write_unlock(file);
3914 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3915 + const aufs_bindex_t bindex,
3916 + const aufs_bindex_t bbot)
3918 + struct au_branch **brp, **p;
3920 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3922 + brp = sbinfo->si_branch + bindex;
3923 + if (bindex < bbot)
3924 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3925 + sbinfo->si_branch[0 + bbot] = NULL;
3926 + sbinfo->si_bbot--;
3928 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3931 + sbinfo->si_branch = p;
3932 + /* harmless error */
3935 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3936 + const aufs_bindex_t bbot)
3938 + struct au_hdentry *hdp, *p;
3940 + AuRwMustWriteLock(&dinfo->di_rwsem);
3942 + hdp = au_hdentry(dinfo, bindex);
3943 + if (bindex < bbot)
3944 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3945 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3948 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3951 + dinfo->di_hdentry = p;
3952 + /* harmless error */
3955 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3956 + const aufs_bindex_t bbot)
3958 + struct au_hinode *hip, *p;
3960 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3962 + hip = au_hinode(iinfo, bindex);
3963 + if (bindex < bbot)
3964 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3965 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3968 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3971 + iinfo->ii_hinode = p;
3972 + /* harmless error */
3975 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3976 + struct au_branch *br)
3978 + aufs_bindex_t bbot;
3979 + struct au_sbinfo *sbinfo;
3980 + struct dentry *root, *h_root;
3981 + struct inode *inode, *h_inode;
3982 + struct au_hinode *hinode;
3984 + SiMustWriteLock(sb);
3986 + root = sb->s_root;
3987 + inode = d_inode(root);
3988 + sbinfo = au_sbi(sb);
3989 + bbot = sbinfo->si_bbot;
3991 + h_root = au_h_dptr(root, bindex);
3992 + hinode = au_hi(inode, bindex);
3993 + h_inode = au_igrab(hinode->hi_inode);
3996 + au_sbilist_lock();
3997 + au_br_do_del_brp(sbinfo, bindex, bbot);
3998 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3999 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4000 + au_sbilist_unlock();
4002 + /* ignore an error */
4003 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4007 + au_br_do_free(br);
4010 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4011 + unsigned long long max, void *arg)
4016 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4019 + unsigned long long opened;
4020 + unsigned int mnt_flags;
4021 + aufs_bindex_t bindex, bbot, br_id;
4022 + unsigned char do_wh, verbose;
4023 + struct au_branch *br;
4024 + struct au_wbr *wbr;
4025 + struct dentry *root;
4026 + struct file **to_free;
4031 + root = sb->s_root;
4032 + bindex = au_find_dbindex(root, del->h_path.dentry);
4035 + goto out; /* success */
4037 + pr_err("%s no such branch\n", del->pathname);
4040 + AuDbg("bindex b%d\n", bindex);
4043 + mnt_flags = au_mntflags(sb);
4044 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4045 + bbot = au_sbbot(sb);
4046 + if (unlikely(!bbot)) {
4047 + AuVerbose(verbose, "no more branches left\n");
4051 + br = au_sbr(sb, bindex);
4052 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4053 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4054 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4058 + br_id = br->br_id;
4059 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4060 + if (unlikely(opened)) {
4061 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4062 + err = PTR_ERR(to_free);
4063 + if (IS_ERR(to_free))
4066 + err = test_file_busy(sb, br_id, to_free, opened);
4067 + if (unlikely(err)) {
4068 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4074 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4076 + /* instead of WbrWhMustWriteLock(wbr) */
4077 + SiMustWriteLock(sb);
4078 + for (i = 0; i < AuBrWh_Last; i++) {
4079 + dput(wbr->wbr_wh[i]);
4080 + wbr->wbr_wh[i] = NULL;
4084 + err = test_children_busy(root, bindex, verbose);
4085 + if (unlikely(err)) {
4094 + * now we confirmed the branch is deletable.
4095 + * let's free the remaining opened dirs on the branch.
4097 + di_write_unlock(root);
4098 + br_del_file(to_free, opened, br_id);
4099 + di_write_lock_child(root);
4102 + sysaufs_brs_del(sb, bindex); /* remove successors */
4103 + dbgaufs_xino_del(br); /* remove one */
4104 + au_br_do_del(sb, bindex, br);
4105 + sysaufs_brs_add(sb, bindex); /* append successors */
4106 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4109 + au_cpup_attr_all(d_inode(root), /*force*/1);
4110 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4112 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4113 + if (au_opt_test(mnt_flags, PLINK))
4114 + au_plink_half_refresh(sb, br_id);
4116 + goto out; /* success */
4120 + rerr = au_br_init_wh(sb, br, br->br_perm);
4122 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4123 + del->pathname, rerr);
4126 + au_farray_free(to_free, opened);
4130 +/* ---------------------------------------------------------------------- */
4132 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4135 + aufs_bindex_t btop, bbot;
4136 + struct aufs_ibusy ibusy;
4137 + struct inode *inode, *h_inode;
4140 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4143 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4145 + /* VERIFY_WRITE */
4146 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4147 + if (unlikely(err)) {
4154 + si_read_lock(sb, AuLock_FLUSH);
4155 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4159 + ibusy.h_ino = 0; /* invalid */
4160 + inode = ilookup(sb, ibusy.ino);
4162 + || inode->i_ino == AUFS_ROOT_INO
4163 + || au_is_bad_inode(inode))
4166 + ii_read_lock_child(inode);
4167 + btop = au_ibtop(inode);
4168 + bbot = au_ibbot(inode);
4169 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4170 + h_inode = au_h_iptr(inode, ibusy.bindex);
4171 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4172 + ibusy.h_ino = h_inode->i_ino;
4174 + ii_read_unlock(inode);
4178 + si_read_unlock(sb);
4180 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4181 + if (unlikely(err)) {
4190 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4192 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4195 +#ifdef CONFIG_COMPAT
4196 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4198 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4202 +/* ---------------------------------------------------------------------- */
4205 + * change a branch permission
4208 +static void au_warn_ima(void)
4211 + /* since it doesn't support mark_files_ro() */
4212 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4216 +static int do_need_sigen_inc(int a, int b)
4218 + return au_br_whable(a) && !au_br_whable(b);
4221 +static int need_sigen_inc(int old, int new)
4223 + return do_need_sigen_inc(old, new)
4224 + || do_need_sigen_inc(new, old);
4227 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4230 + unsigned int mnt_flags;
4231 + unsigned long long ull, max;
4232 + aufs_bindex_t br_id;
4233 + unsigned char verbose, writer;
4234 + struct file *file, *hf, **array;
4235 + struct au_hfile *hfile;
4236 + struct inode *h_inode;
4238 + mnt_flags = au_mntflags(sb);
4239 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4241 + array = au_farray_alloc(sb, &max);
4242 + err = PTR_ERR(array);
4243 + if (IS_ERR(array))
4247 + br_id = au_sbr_id(sb, bindex);
4248 + for (ull = 0; ull < max; ull++) {
4249 + file = array[ull];
4250 + if (unlikely(!file))
4253 + /* AuDbg("%pD\n", file); */
4254 + fi_read_lock(file);
4255 + if (unlikely(au_test_mmapped(file))) {
4257 + AuVerbose(verbose, "mmapped %pD\n", file);
4259 + FiMustNoWaiters(file);
4260 + fi_read_unlock(file);
4264 + hfile = &au_fi(file)->fi_htop;
4265 + hf = hfile->hf_file;
4266 + if (!d_is_reg(file->f_path.dentry)
4267 + || !(file->f_mode & FMODE_WRITE)
4268 + || hfile->hf_br->br_id != br_id
4269 + || !(hf->f_mode & FMODE_WRITE))
4270 + array[ull] = NULL;
4276 + FiMustNoWaiters(file);
4277 + fi_read_unlock(file);
4285 + for (ull = 0; ull < max; ull++) {
4286 + file = array[ull];
4290 + /* todo: already flushed? */
4292 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4293 + * approach which resets f_mode and calls mnt_drop_write() and
4294 + * file_release_write() for each file, because the branch
4295 + * attribute in aufs world is totally different from the native
4298 + /* fi_read_lock(file); */
4299 + hfile = &au_fi(file)->fi_htop;
4300 + hf = hfile->hf_file;
4301 + /* fi_read_unlock(file); */
4302 + spin_lock(&hf->f_lock);
4303 + writer = !!(hf->f_mode & FMODE_WRITER);
4304 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4305 + spin_unlock(&hf->f_lock);
4307 + h_inode = file_inode(hf);
4308 + put_write_access(h_inode);
4309 + __mnt_drop_write(hf->f_path.mnt);
4310 + if ((hf->f_mode & (FMODE_READ | FMODE_WRITE))
4312 + i_readcount_inc(h_inode);
4317 + au_farray_free(array, max);
4323 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4327 + aufs_bindex_t bindex;
4328 + struct dentry *root;
4329 + struct au_branch *br;
4330 + struct au_br_fhsm *bf;
4332 + root = sb->s_root;
4333 + bindex = au_find_dbindex(root, mod->h_root);
4336 + return 0; /* success */
4338 + pr_err("%s no such branch\n", mod->path);
4341 + AuDbg("bindex b%d\n", bindex);
4343 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4344 + if (unlikely(err))
4347 + br = au_sbr(sb, bindex);
4348 + AuDebugOn(mod->h_root != au_br_dentry(br));
4349 + if (br->br_perm == mod->perm)
4350 + return 0; /* success */
4352 + /* pre-allocate for non-fhsm --> fhsm */
4354 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4355 + err = au_fhsm_br_alloc(br);
4356 + if (unlikely(err))
4359 + br->br_fhsm = NULL;
4362 + if (au_br_writable(br->br_perm)) {
4363 + /* remove whiteout base */
4364 + err = au_br_init_wh(sb, br, mod->perm);
4365 + if (unlikely(err))
4368 + if (!au_br_writable(mod->perm)) {
4369 + /* rw --> ro, file might be mmapped */
4370 + DiMustNoWaiters(root);
4371 + IiMustNoWaiters(d_inode(root));
4372 + di_write_unlock(root);
4373 + err = au_br_mod_files_ro(sb, bindex);
4374 + /* aufs_write_lock() calls ..._child() */
4375 + di_write_lock_child(root);
4377 + if (unlikely(err)) {
4379 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4382 + rerr = au_wbr_init(br, sb, br->br_perm);
4383 + if (unlikely(rerr)) {
4384 + AuIOErr("nested error %d (%d)\n",
4386 + br->br_perm = mod->perm;
4390 + } else if (au_br_writable(mod->perm)) {
4393 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4395 + err = au_wbr_init(br, sb, mod->perm);
4396 + if (unlikely(err)) {
4397 + au_kfree_rcu(br->br_wbr);
4398 + br->br_wbr = NULL;
4402 + if (unlikely(err))
4405 + if (au_br_fhsm(br->br_perm)) {
4406 + if (!au_br_fhsm(mod->perm)) {
4407 + /* fhsm --> non-fhsm */
4408 + au_br_fhsm_fin(br->br_fhsm);
4409 + au_kfree_rcu(br->br_fhsm);
4410 + br->br_fhsm = NULL;
4412 + } else if (au_br_fhsm(mod->perm))
4413 + /* non-fhsm --> fhsm */
4416 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4417 + br->br_perm = mod->perm;
4418 + goto out; /* success */
4421 + au_kfree_try_rcu(bf);
4427 +/* ---------------------------------------------------------------------- */
4429 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4432 + struct kstatfs kstfs;
4434 + err = vfs_statfs(&br->br_path, &kstfs);
4436 + stfs->f_blocks = kstfs.f_blocks;
4437 + stfs->f_bavail = kstfs.f_bavail;
4438 + stfs->f_files = kstfs.f_files;
4439 + stfs->f_ffree = kstfs.f_ffree;
4444 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4445 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4446 +++ linux/fs/aufs/branch.h 2019-07-11 15:42:14.462237786 +0200
4448 +/* SPDX-License-Identifier: GPL-2.0 */
4450 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4452 + * This program, aufs is free software; you can redistribute it and/or modify
4453 + * it under the terms of the GNU General Public License as published by
4454 + * the Free Software Foundation; either version 2 of the License, or
4455 + * (at your option) any later version.
4457 + * This program is distributed in the hope that it will be useful,
4458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4460 + * GNU General Public License for more details.
4462 + * You should have received a copy of the GNU General Public License
4463 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4467 + * branch filesystems and xino for them
4470 +#ifndef __AUFS_BRANCH_H__
4471 +#define __AUFS_BRANCH_H__
4475 +#include <linux/mount.h>
4476 +#include "dirren.h"
4482 +/* ---------------------------------------------------------------------- */
4486 + struct file **xi_file;
4487 + unsigned int xi_nfile;
4493 + /* reserved for future use */
4494 + /* unsigned long *bitmap; */
4495 + wait_queue_head_t wqh;
4498 + struct mutex xi_mtx; /* protects xi_file array */
4499 + struct hlist_bl_head xi_writing;
4501 + atomic_t xi_truncating;
4503 + struct kref xi_kref;
4506 +/* File-based Hierarchical Storage Management */
4507 +struct au_br_fhsm {
4508 +#ifdef CONFIG_AUFS_FHSM
4509 + struct mutex bf_lock;
4510 + unsigned long bf_jiffy;
4511 + struct aufs_stfs bf_stfs;
4516 +/* members for writable branch only */
4517 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4519 + struct au_rwsem wbr_wh_rwsem;
4520 + struct dentry *wbr_wh[AuBrWh_Last];
4521 + atomic_t wbr_wh_running;
4522 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4523 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4524 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4527 + unsigned long long wbr_bytes;
4530 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4531 +#define AuBrDynOp (AuDyLast * 4)
4533 +#ifdef CONFIG_AUFS_HFSNOTIFY
4534 +/* support for asynchronous destruction */
4535 +struct au_br_hfsnotify {
4536 + struct fsnotify_group *hfsn_group;
4540 +/* sysfs entries */
4541 +struct au_brsysfs {
4543 + struct attribute attr;
4552 +/* protected by superblock rwsem */
4554 + struct au_xino *br_xino;
4556 + aufs_bindex_t br_id;
4559 + struct path br_path;
4560 + spinlock_t br_dykey_lock;
4561 + struct au_dykey *br_dykey[AuBrDynOp];
4562 + au_lcnt_t br_nfiles; /* opened files */
4563 + au_lcnt_t br_count; /* in-use for other */
4565 + struct au_wbr *br_wbr;
4566 + struct au_br_fhsm *br_fhsm;
4568 +#ifdef CONFIG_AUFS_HFSNOTIFY
4569 + struct au_br_hfsnotify *br_hfsn;
4572 +#ifdef CONFIG_SYSFS
4573 + /* entries under sysfs per mount-point */
4574 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4577 +#ifdef CONFIG_DEBUG_FS
4578 + struct dentry *br_dbgaufs; /* xino */
4581 + struct au_dr_br br_dirren;
4584 +/* ---------------------------------------------------------------------- */
4586 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4588 + return br->br_path.mnt;
4591 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4593 + return br->br_path.dentry;
4596 +static inline struct super_block *au_br_sb(struct au_branch *br)
4598 + return au_br_mnt(br)->mnt_sb;
4601 +static inline int au_br_rdonly(struct au_branch *br)
4603 + return (sb_rdonly(au_br_sb(br))
4604 + || !au_br_writable(br->br_perm))
4608 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4610 +#ifdef CONFIG_AUFS_HNOTIFY
4611 + return !(brperm & AuBrPerm_RR);
4617 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4619 + int err, exec_flag;
4622 + exec_flag = oflag & __FMODE_EXEC;
4623 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4629 +static inline void au_xino_get(struct au_branch *br)
4631 + struct au_xino *xi;
4635 + kref_get(&xi->xi_kref);
4638 +static inline int au_xino_count(struct au_branch *br)
4641 + struct au_xino *xi;
4646 + v = kref_read(&xi->xi_kref);
4651 +/* ---------------------------------------------------------------------- */
4655 +void au_br_free(struct au_sbinfo *sinfo);
4656 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4658 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4660 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4661 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4662 +#ifdef CONFIG_COMPAT
4663 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4666 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4669 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4672 +static const loff_t au_loff_max = LLONG_MAX;
4674 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4675 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4677 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4678 + struct file *copy_src);
4680 + struct au_xino *xi; /* switch between xino and xigen */
4682 + struct path *base;
4683 + struct file *copy_src;
4685 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4687 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4689 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4691 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4693 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4694 + size_t size, loff_t *pos);
4696 +int au_xib_trunc(struct super_block *sb);
4697 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4699 +struct au_xino *au_xino_alloc(unsigned int nfile);
4700 +int au_xino_put(struct au_branch *br);
4701 +struct file *au_xino_file1(struct au_xino *xi);
4703 +struct au_opt_xino;
4704 +void au_xino_clr(struct super_block *sb);
4705 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4706 +struct file *au_xino_def(struct super_block *sb);
4707 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4708 + struct path *base);
4710 +ino_t au_xino_new_ino(struct super_block *sb);
4711 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4713 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4714 + ino_t h_ino, int idx);
4715 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4718 +int au_xino_path(struct seq_file *seq, struct file *file);
4720 +/* ---------------------------------------------------------------------- */
4722 +/* @idx is signed to accept -1 meaning the first file */
4723 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4725 + struct file *file;
4732 + if (idx < xi->xi_nfile)
4733 + file = xi->xi_file[idx];
4735 + file = au_xino_file1(xi);
4741 +/* ---------------------------------------------------------------------- */
4743 +/* Superblock to branch */
4745 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4747 + return au_sbr(sb, bindex)->br_id;
4751 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4753 + return au_br_mnt(au_sbr(sb, bindex));
4757 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4759 + return au_br_sb(au_sbr(sb, bindex));
4762 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4764 + return au_sbr(sb, bindex)->br_perm;
4767 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4769 + return au_br_whable(au_sbr_perm(sb, bindex));
4772 +/* ---------------------------------------------------------------------- */
4774 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4775 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4776 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4777 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4779 +#define wbr_wh_read_trylock_nested(wbr) \
4780 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4781 +#define wbr_wh_write_trylock_nested(wbr) \
4782 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4785 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4786 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4787 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4789 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4790 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4791 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4793 +/* ---------------------------------------------------------------------- */
4795 +#ifdef CONFIG_AUFS_FHSM
4796 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4798 + mutex_init(&brfhsm->bf_lock);
4799 + brfhsm->bf_jiffy = 0;
4800 + brfhsm->bf_readable = 0;
4803 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4805 + mutex_destroy(&brfhsm->bf_lock);
4808 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4809 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4812 +#endif /* __KERNEL__ */
4813 +#endif /* __AUFS_BRANCH_H__ */
4814 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4815 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4816 +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200
4818 +# SPDX-License-Identifier: GPL-2.0
4820 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4824 +AuConfStr += ${1}=${${1}}
4828 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4830 + HNOTIFY HFSNOTIFY \
4842 +$(foreach i, ${AuConfAll}, \
4843 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4845 +AuConfName = ${obj}/conf.str
4846 +${AuConfName}.tmp: FORCE
4847 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4848 +${AuConfName}: ${AuConfName}.tmp
4849 + @diff -q $< $@ > /dev/null 2>&1 || { \
4850 + echo ' GEN ' $@; \
4854 +clean-files += ${AuConfName} ${AuConfName}.tmp
4855 +${obj}/sysfs.o: ${AuConfName}
4857 +-include ${srctree}/${src}/conf_priv.mk
4858 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4859 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4860 +++ linux/fs/aufs/cpup.c 2019-07-11 15:42:14.462237786 +0200
4862 +// SPDX-License-Identifier: GPL-2.0
4864 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4866 + * This program, aufs is free software; you can redistribute it and/or modify
4867 + * it under the terms of the GNU General Public License as published by
4868 + * the Free Software Foundation; either version 2 of the License, or
4869 + * (at your option) any later version.
4871 + * This program is distributed in the hope that it will be useful,
4872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4874 + * GNU General Public License for more details.
4876 + * You should have received a copy of the GNU General Public License
4877 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4881 + * copy-up functions, see wbr_policy.c for copy-down
4884 +#include <linux/fs_stack.h>
4885 +#include <linux/mm.h>
4886 +#include <linux/task_work.h>
4889 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4891 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4892 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4894 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4896 + dst->i_flags |= iflags & ~mask;
4897 + if (au_test_fs_notime(dst->i_sb))
4898 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4901 +void au_cpup_attr_timesizes(struct inode *inode)
4903 + struct inode *h_inode;
4905 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4906 + fsstack_copy_attr_times(inode, h_inode);
4907 + fsstack_copy_inode_size(inode, h_inode);
4910 +void au_cpup_attr_nlink(struct inode *inode, int force)
4912 + struct inode *h_inode;
4913 + struct super_block *sb;
4914 + aufs_bindex_t bindex, bbot;
4917 + bindex = au_ibtop(inode);
4918 + h_inode = au_h_iptr(inode, bindex);
4920 + && !S_ISDIR(h_inode->i_mode)
4921 + && au_opt_test(au_mntflags(sb), PLINK)
4922 + && au_plink_test(inode))
4926 + * 0 can happen in revalidating.
4927 + * h_inode->i_mutex may not be held here, but it is harmless since once
4928 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4930 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4931 + * the incorrect link count.
4933 + set_nlink(inode, h_inode->i_nlink);
4936 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4937 + * it may includes whplink directory.
4939 + if (S_ISDIR(h_inode->i_mode)) {
4940 + bbot = au_ibbot(inode);
4941 + for (bindex++; bindex <= bbot; bindex++) {
4942 + h_inode = au_h_iptr(inode, bindex);
4944 + au_add_nlink(inode, h_inode);
4949 +void au_cpup_attr_changeable(struct inode *inode)
4951 + struct inode *h_inode;
4953 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4954 + inode->i_mode = h_inode->i_mode;
4955 + inode->i_uid = h_inode->i_uid;
4956 + inode->i_gid = h_inode->i_gid;
4957 + au_cpup_attr_timesizes(inode);
4958 + au_cpup_attr_flags(inode, h_inode->i_flags);
4961 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4963 + struct au_iinfo *iinfo = au_ii(inode);
4965 + IiMustWriteLock(inode);
4967 + iinfo->ii_higen = h_inode->i_generation;
4968 + iinfo->ii_hsb1 = h_inode->i_sb;
4971 +void au_cpup_attr_all(struct inode *inode, int force)
4973 + struct inode *h_inode;
4975 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4976 + au_cpup_attr_changeable(inode);
4977 + if (inode->i_nlink > 0)
4978 + au_cpup_attr_nlink(inode, force);
4979 + inode->i_rdev = h_inode->i_rdev;
4980 + inode->i_blkbits = h_inode->i_blkbits;
4981 + au_cpup_igen(inode, h_inode);
4984 +/* ---------------------------------------------------------------------- */
4986 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4988 +/* keep the timestamps of the parent dir when cpup */
4989 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4990 + struct path *h_path)
4992 + struct inode *h_inode;
4994 + dt->dt_dentry = dentry;
4995 + dt->dt_h_path = *h_path;
4996 + h_inode = d_inode(h_path->dentry);
4997 + dt->dt_atime = h_inode->i_atime;
4998 + dt->dt_mtime = h_inode->i_mtime;
5002 +void au_dtime_revert(struct au_dtime *dt)
5004 + struct iattr attr;
5007 + attr.ia_atime = dt->dt_atime;
5008 + attr.ia_mtime = dt->dt_mtime;
5009 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5010 + | ATTR_ATIME | ATTR_ATIME_SET;
5012 + /* no delegation since this is a directory */
5013 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5014 + if (unlikely(err))
5015 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5018 +/* ---------------------------------------------------------------------- */
5020 +/* internal use only */
5021 +struct au_cpup_reg_attr {
5024 + unsigned int iflags; /* inode->i_flags */
5027 +static noinline_for_stack
5028 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5029 + struct au_cpup_reg_attr *h_src_attr)
5031 + int err, sbits, icex;
5032 + unsigned int mnt_flags;
5033 + unsigned char verbose;
5035 + struct path h_path;
5036 + struct inode *h_isrc, *h_idst;
5037 + struct kstat *h_st;
5038 + struct au_branch *br;
5040 + h_path.dentry = au_h_dptr(dst, bindex);
5041 + h_idst = d_inode(h_path.dentry);
5042 + br = au_sbr(dst->d_sb, bindex);
5043 + h_path.mnt = au_br_mnt(br);
5044 + h_isrc = d_inode(h_src);
5045 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5046 + | ATTR_ATIME | ATTR_MTIME
5047 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5048 + if (h_src_attr && h_src_attr->valid) {
5049 + h_st = &h_src_attr->st;
5050 + ia.ia_uid = h_st->uid;
5051 + ia.ia_gid = h_st->gid;
5052 + ia.ia_atime = h_st->atime;
5053 + ia.ia_mtime = h_st->mtime;
5054 + if (h_idst->i_mode != h_st->mode
5055 + && !S_ISLNK(h_idst->i_mode)) {
5056 + ia.ia_valid |= ATTR_MODE;
5057 + ia.ia_mode = h_st->mode;
5059 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5060 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5062 + ia.ia_uid = h_isrc->i_uid;
5063 + ia.ia_gid = h_isrc->i_gid;
5064 + ia.ia_atime = h_isrc->i_atime;
5065 + ia.ia_mtime = h_isrc->i_mtime;
5066 + if (h_idst->i_mode != h_isrc->i_mode
5067 + && !S_ISLNK(h_idst->i_mode)) {
5068 + ia.ia_valid |= ATTR_MODE;
5069 + ia.ia_mode = h_isrc->i_mode;
5071 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5072 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5074 + /* no delegation since it is just created */
5075 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5077 + /* is this nfs only? */
5078 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5079 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5080 + ia.ia_mode = h_isrc->i_mode;
5081 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5084 + icex = br->br_perm & AuBrAttr_ICEX;
5086 + mnt_flags = au_mntflags(dst->d_sb);
5087 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5088 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5094 +/* ---------------------------------------------------------------------- */
5096 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5097 + char *buf, unsigned long blksize)
5100 + size_t sz, rbytes, wbytes;
5101 + unsigned char all_zero;
5103 + struct inode *h_inode;
5104 + /* reduce stack usage */
5107 + zp = page_address(ZERO_PAGE(0));
5108 + if (unlikely(!zp))
5109 + return -ENOMEM; /* possible? */
5114 + AuDbg("len %lld\n", len);
5116 + if (len < blksize)
5120 + /* todo: signal_pending? */
5121 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5122 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5125 + if (unlikely(err < 0))
5129 + if (len >= rbytes && rbytes == blksize)
5130 + all_zero = !memcmp(buf, zp, rbytes);
5137 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5139 + /* todo: signal_pending? */
5140 + if (unlikely(err == -EAGAIN || err == -EINTR))
5142 + if (unlikely(err < 0))
5147 + if (unlikely(err < 0))
5153 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5155 + if (unlikely(res < 0))
5162 + /* the last block may be a hole */
5163 + if (!err && all_zero) {
5164 + AuLabel(last hole);
5167 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5168 + /* nfs requires this step to make last hole */
5169 + /* is this only nfs? */
5171 + /* todo: signal_pending? */
5172 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5173 + } while (err == -EAGAIN || err == -EINTR);
5180 + ia->ia_size = dst->f_pos;
5181 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5182 + ia->ia_file = dst;
5183 + h_inode = file_inode(dst);
5184 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5185 + /* no delegation since it is just created */
5186 + err = vfsub_notify_change(&dst->f_path, ia,
5187 + /*delegated*/NULL);
5188 + inode_unlock(h_inode);
5195 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5198 + unsigned long blksize;
5199 + unsigned char do_kfree;
5201 + struct super_block *h_sb;
5204 + h_sb = file_inode(dst)->i_sb;
5205 + blksize = h_sb->s_blocksize;
5206 + if (!blksize || PAGE_SIZE < blksize)
5207 + blksize = PAGE_SIZE;
5208 + AuDbg("blksize %lu\n", blksize);
5209 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5211 + buf = kmalloc(blksize, GFP_NOFS);
5213 + buf = (void *)__get_free_page(GFP_NOFS);
5214 + if (unlikely(!buf))
5217 + if (len > (1 << 22))
5218 + AuDbg("copying a large file %lld\n", (long long)len);
5222 + err = au_do_copy_file(dst, src, len, buf, blksize);
5224 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5225 + au_kfree_do_rcu(buf);
5227 + free_page((unsigned long)buf);
5233 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5236 + struct super_block *h_src_sb;
5237 + struct inode *h_src_inode;
5239 + h_src_inode = file_inode(src);
5240 + h_src_sb = h_src_inode->i_sb;
5242 + /* XFS acquires inode_lock */
5243 + if (!au_test_xfs(h_src_sb))
5244 + err = au_copy_file(dst, src, len);
5246 + inode_unlock_shared(h_src_inode);
5247 + err = au_copy_file(dst, src, len);
5248 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5254 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5258 + struct super_block *h_src_sb;
5259 + struct inode *h_src_inode;
5261 + h_src_inode = file_inode(src);
5262 + h_src_sb = h_src_inode->i_sb;
5263 + if (h_src_sb != file_inode(dst)->i_sb
5264 + || !dst->f_op->remap_file_range) {
5265 + err = au_do_copy(dst, src, len);
5269 + if (!au_test_nfs(h_src_sb)) {
5270 + inode_unlock_shared(h_src_inode);
5271 + lo = vfsub_clone_file_range(src, dst, len);
5272 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5274 + lo = vfsub_clone_file_range(src, dst, len);
5277 + goto out; /* success */
5278 + } else if (lo >= 0)
5279 + /* todo: possible? */
5280 + /* paritially succeeded */
5281 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5282 + else if (lo != -EOPNOTSUPP) {
5283 + /* older XFS has a condition in cloning */
5288 + /* the backend fs on NFS may not support cloning */
5289 + err = au_do_copy(dst, src, len);
5297 + * to support a sparse file which is opened with O_APPEND,
5298 + * we need to close the file.
5300 +static int au_cp_regular(struct au_cp_generic *cpg)
5303 + enum { SRC, DST };
5305 + aufs_bindex_t bindex;
5306 + unsigned int flags;
5307 + struct dentry *dentry;
5309 + struct file *file;
5312 + .bindex = cpg->bsrc,
5313 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5316 + .bindex = cpg->bdst,
5317 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5318 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5321 + struct au_branch *br;
5322 + struct super_block *sb, *h_src_sb;
5323 + struct inode *h_src_inode;
5324 + struct task_struct *tsk = current;
5326 + /* bsrc branch can be ro/rw. */
5327 + sb = cpg->dentry->d_sb;
5329 + for (i = 0; i < 2; i++, f++) {
5330 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5331 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5332 + /*file*/NULL, f->force_wr);
5333 + if (IS_ERR(f->file)) {
5334 + err = PTR_ERR(f->file);
5342 + /* try stopping to update while we copyup */
5343 + h_src_inode = d_inode(file[SRC].dentry);
5344 + h_src_sb = h_src_inode->i_sb;
5345 + if (!au_test_nfs(h_src_sb))
5346 + IMustLock(h_src_inode);
5347 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5349 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5350 + if (tsk->flags & PF_KTHREAD)
5351 + __fput_sync(file[DST].file);
5353 + /* it happened actually */
5354 + fput(file[DST].file);
5357 + * we have to call both since we don't know which place the file
5361 + flush_delayed_fput();
5363 + br = au_sbr(sb, file[DST].bindex);
5364 + au_lcnt_dec(&br->br_nfiles);
5367 + fput(file[SRC].file);
5368 + br = au_sbr(sb, file[SRC].bindex);
5369 + au_lcnt_dec(&br->br_nfiles);
5374 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5375 + struct au_cpup_reg_attr *h_src_attr)
5379 + struct path h_path;
5380 + struct inode *h_src_inode, *h_dst_inode;
5383 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5384 + l = i_size_read(h_src_inode);
5385 + if (cpg->len == -1 || l < cpg->len)
5388 + /* try stopping to update while we are referencing */
5389 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5390 + au_pin_hdir_unlock(cpg->pin);
5392 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5393 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5394 + h_src_attr->iflags = h_src_inode->i_flags;
5395 + if (!au_test_nfs(h_src_inode->i_sb))
5396 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5398 + inode_unlock_shared(h_src_inode);
5399 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5400 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5402 + if (unlikely(err)) {
5403 + inode_unlock_shared(h_src_inode);
5406 + h_src_attr->valid = 1;
5407 + if (!au_test_nfs(h_src_inode->i_sb)) {
5408 + err = au_cp_regular(cpg);
5409 + inode_unlock_shared(h_src_inode);
5411 + inode_unlock_shared(h_src_inode);
5412 + err = au_cp_regular(cpg);
5414 + rerr = au_pin_hdir_relock(cpg->pin);
5418 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5419 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5420 + h_dst_inode = d_inode(h_path.dentry);
5421 + spin_lock(&h_dst_inode->i_lock);
5422 + h_dst_inode->i_state |= I_LINKABLE;
5423 + spin_unlock(&h_dst_inode->i_lock);
5430 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5431 + struct inode *h_dir)
5434 + mm_segment_t old_fs;
5441 + sym.k = (void *)__get_free_page(GFP_NOFS);
5442 + if (unlikely(!sym.k))
5445 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5446 + old_fs = get_fs();
5447 + set_fs(KERNEL_DS);
5448 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5453 + sym.k[symlen] = 0;
5454 + err = vfsub_symlink(h_dir, h_path, sym.k);
5456 + free_page((unsigned long)sym.k);
5463 + * regardless 'acl' option, reset all ACL.
5464 + * All ACL will be copied up later from the original entry on the lower branch.
5466 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5469 + struct dentry *h_dentry;
5470 + struct inode *h_inode;
5472 + h_dentry = h_path->dentry;
5473 + h_inode = d_inode(h_dentry);
5474 + /* forget_all_cached_acls(h_inode)); */
5475 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5477 + if (err == -EOPNOTSUPP)
5480 + err = vfsub_acl_chmod(h_inode, mode);
5486 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5487 + struct inode *h_dir, struct path *h_path)
5490 + struct inode *dir, *inode;
5492 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5494 + if (err == -EOPNOTSUPP)
5496 + if (unlikely(err))
5500 + * strange behaviour from the users view,
5501 + * particularly setattr case
5503 + dir = d_inode(dst_parent);
5504 + if (au_ibtop(dir) == cpg->bdst)
5505 + au_cpup_attr_nlink(dir, /*force*/1);
5506 + inode = d_inode(cpg->dentry);
5507 + au_cpup_attr_nlink(inode, /*force*/1);
5513 +static noinline_for_stack
5514 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5515 + struct au_cpup_reg_attr *h_src_attr)
5519 + unsigned int mnt_flags;
5520 + unsigned char isdir, isreg, force;
5521 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5522 + struct au_dtime dt;
5523 + struct path h_path;
5524 + struct dentry *h_src, *h_dst, *h_parent;
5525 + struct inode *h_inode, *h_dir;
5526 + struct super_block *sb;
5528 + /* bsrc branch can be ro/rw. */
5529 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5530 + h_inode = d_inode(h_src);
5531 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5533 + /* try stopping to be referenced while we are creating */
5534 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5535 + if (au_ftest_cpup(cpg->flags, RENAME))
5536 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5537 + AUFS_WH_PFX_LEN));
5538 + h_parent = h_dst->d_parent; /* dir inode is locked */
5539 + h_dir = d_inode(h_parent);
5541 + AuDebugOn(h_parent != h_dst->d_parent);
5543 + sb = cpg->dentry->d_sb;
5544 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5546 + h_path.dentry = h_parent;
5547 + au_dtime_store(&dt, dst_parent, &h_path);
5549 + h_path.dentry = h_dst;
5553 + mode = h_inode->i_mode;
5554 + switch (mode & S_IFMT) {
5557 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5559 + err = au_do_cpup_regular(cpg, h_src_attr);
5563 + err = vfsub_mkdir(h_dir, &h_path, mode);
5565 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5568 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5572 + AuDebugOn(!capable(CAP_MKNOD));
5576 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5579 + AuIOErr("Unknown inode type 0%o\n", mode);
5583 + err = au_reset_acl(h_dir, &h_path, mode);
5585 + mnt_flags = au_mntflags(sb);
5586 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5588 + && au_opt_test(mnt_flags, XINO)
5589 + && (h_inode->i_nlink == 1
5590 + || (h_inode->i_state & I_LINKABLE))
5591 + /* todo: unnecessary? */
5592 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5593 + && cpg->bdst < cpg->bsrc
5594 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5595 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5596 + /* ignore this error */
5601 + force = !!cpg->len;
5602 + if (cpg->len == -1)
5603 + force = !!i_size_read(h_inode);
5605 + au_fhsm_wrote(sb, cpg->bdst, force);
5609 + au_dtime_revert(&dt);
5613 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5616 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5617 + struct inode *h_dir;
5618 + aufs_bindex_t bdst;
5620 + dentry = cpg->dentry;
5622 + h_dentry = au_h_dptr(dentry, bdst);
5623 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5625 + au_set_h_dptr(dentry, bdst, NULL);
5626 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5628 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5629 + au_set_h_dptr(dentry, bdst, h_dentry);
5632 + parent = dget_parent(dentry);
5633 + h_parent = au_h_dptr(parent, bdst);
5635 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5636 + if (IS_ERR(h_path->dentry))
5637 + err = PTR_ERR(h_path->dentry);
5639 + if (unlikely(err))
5642 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5643 + h_dir = d_inode(h_parent);
5645 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5646 + /* no delegation since it is just created */
5647 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5649 + dput(h_path->dentry);
5656 + * copyup the @dentry from @bsrc to @bdst.
5657 + * the caller must set the both of lower dentries.
5658 + * @len is for truncating when it is -1 copyup the entire file.
5659 + * in link/rename cases, @dst_parent may be different from the real one.
5660 + * basic->bsrc can be larger than basic->bdst.
5661 + * aufs doesn't touch the credential so
5662 + * security_inode_copy_up{,_xattr}() are unnecessary.
5664 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5667 + aufs_bindex_t old_ibtop;
5668 + unsigned char isdir, plink;
5669 + struct dentry *h_src, *h_dst, *h_parent;
5670 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5671 + struct super_block *sb;
5672 + struct au_branch *br;
5673 + /* to reduce stack size */
5675 + struct au_dtime dt;
5676 + struct path h_path;
5677 + struct au_cpup_reg_attr h_src_attr;
5681 + a = kmalloc(sizeof(*a), GFP_NOFS);
5684 + a->h_src_attr.valid = 0;
5686 + sb = cpg->dentry->d_sb;
5687 + br = au_sbr(sb, cpg->bdst);
5688 + a->h_path.mnt = au_br_mnt(br);
5689 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5690 + h_parent = h_dst->d_parent; /* dir inode is locked */
5691 + h_dir = d_inode(h_parent);
5694 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5695 + inode = d_inode(cpg->dentry);
5698 + dst_parent = dget_parent(cpg->dentry);
5702 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5703 + dst_inode = au_h_iptr(inode, cpg->bdst);
5705 + if (unlikely(!plink)) {
5707 + AuIOErr("hi%lu(i%lu) exists on b%d "
5708 + "but plink is disabled\n",
5709 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5713 + if (dst_inode->i_nlink) {
5714 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5716 + h_src = au_plink_lkup(inode, cpg->bdst);
5717 + err = PTR_ERR(h_src);
5718 + if (IS_ERR(h_src))
5720 + if (unlikely(d_is_negative(h_src))) {
5722 + AuIOErr("i%lu exists on b%d "
5723 + "but not pseudo-linked\n",
5724 + inode->i_ino, cpg->bdst);
5730 + a->h_path.dentry = h_parent;
5731 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5734 + a->h_path.dentry = h_dst;
5736 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5737 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5738 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5740 + au_dtime_revert(&a->dt);
5741 + if (unlikely(err == -EWOULDBLOCK)) {
5742 + pr_warn("cannot retry for NFSv4 delegation"
5743 + " for an internal link\n");
5749 + /* todo: cpup_wh_file? */
5751 + au_update_ibrange(inode, /*do_put_zero*/1);
5754 + isdir = S_ISDIR(inode->i_mode);
5755 + old_ibtop = au_ibtop(inode);
5756 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5757 + if (unlikely(err))
5759 + dst_inode = d_inode(h_dst);
5760 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5761 + /* todo: necessary? */
5762 + /* au_pin_hdir_unlock(cpg->pin); */
5764 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5765 + if (unlikely(err)) {
5766 + /* todo: necessary? */
5767 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5768 + inode_unlock(dst_inode);
5772 + if (cpg->bdst < old_ibtop) {
5773 + if (S_ISREG(inode->i_mode)) {
5774 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5775 + if (unlikely(err)) {
5776 + /* ignore an error */
5777 + /* au_pin_hdir_relock(cpg->pin); */
5778 + inode_unlock(dst_inode);
5782 + au_set_ibtop(inode, cpg->bdst);
5784 + au_set_ibbot(inode, cpg->bdst);
5785 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5786 + au_hi_flags(inode, isdir));
5788 + /* todo: necessary? */
5789 + /* err = au_pin_hdir_relock(cpg->pin); */
5790 + inode_unlock(dst_inode);
5791 + if (unlikely(err))
5794 + src_inode = d_inode(h_src);
5796 + && (src_inode->i_nlink > 1
5797 + || src_inode->i_state & I_LINKABLE)
5799 + au_plink_append(inode, cpg->bdst, h_dst);
5801 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5802 + a->h_path.dentry = h_dst;
5803 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5806 + goto out_parent; /* success */
5810 + a->h_path.dentry = h_parent;
5811 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5812 + a->h_path.dentry = h_dst;
5814 + if (d_is_positive(h_dst)) {
5816 + /* no delegation since it is just created */
5817 + rerr = vfsub_unlink(h_dir, &a->h_path,
5818 + /*delegated*/NULL, /*force*/0);
5820 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5822 + au_dtime_revert(&a->dt);
5824 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5834 +#if 0 /* reserved */
5835 +struct au_cpup_single_args {
5837 + struct au_cp_generic *cpg;
5838 + struct dentry *dst_parent;
5841 +static void au_call_cpup_single(void *args)
5843 + struct au_cpup_single_args *a = args;
5845 + au_pin_hdir_acquire_nest(a->cpg->pin);
5846 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5847 + au_pin_hdir_release(a->cpg->pin);
5852 + * prevent SIGXFSZ in copy-up.
5853 + * testing CAP_MKNOD is for generic fs,
5854 + * but CAP_FSETID is for xfs only, currently.
5856 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5859 + struct super_block *sb;
5860 + struct inode *h_dir;
5863 + sb = au_pinned_parent(pin)->d_sb;
5864 + if (!au_wkq_test()
5865 + && (!au_sbi(sb)->si_plink_maint_pid
5866 + || au_plink_maint(sb, AuLock_NOPLM))) {
5867 + switch (mode & S_IFMT) {
5869 + /* no condition about RLIMIT_FSIZE and the file size */
5874 + do_sio = !capable(CAP_MKNOD);
5878 + do_sio = ((mode & (S_ISUID | S_ISGID))
5879 + && !capable(CAP_FSETID));
5880 + /* this workaround may be removed in the future */
5882 + h_dir = au_pinned_h_dir(pin);
5883 + do_sio = h_dir->i_mode & S_ISVTX;
5890 +#if 0 /* reserved */
5891 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5894 + struct dentry *h_dentry;
5896 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5897 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5898 + err = au_cpup_single(cpg, dst_parent);
5900 + struct au_cpup_single_args args = {
5903 + .dst_parent = dst_parent
5905 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5906 + if (unlikely(wkq_err))
5915 + * copyup the @dentry from the first active lower branch to @bdst,
5916 + * using au_cpup_single().
5918 +static int au_cpup_simple(struct au_cp_generic *cpg)
5921 + unsigned int flags_orig;
5922 + struct dentry *dentry;
5924 + AuDebugOn(cpg->bsrc < 0);
5926 + dentry = cpg->dentry;
5927 + DiMustWriteLock(dentry);
5929 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5931 + flags_orig = cpg->flags;
5932 + au_fset_cpup(cpg->flags, RENAME);
5933 + err = au_cpup_single(cpg, NULL);
5934 + cpg->flags = flags_orig;
5936 + return 0; /* success */
5939 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5940 + au_set_dbtop(dentry, cpg->bsrc);
5946 +struct au_cpup_simple_args {
5948 + struct au_cp_generic *cpg;
5951 +static void au_call_cpup_simple(void *args)
5953 + struct au_cpup_simple_args *a = args;
5955 + au_pin_hdir_acquire_nest(a->cpg->pin);
5956 + *a->errp = au_cpup_simple(a->cpg);
5957 + au_pin_hdir_release(a->cpg->pin);
5960 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5963 + struct dentry *dentry, *parent;
5964 + struct file *h_file;
5965 + struct inode *h_dir;
5967 + dentry = cpg->dentry;
5969 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5970 + AuDebugOn(cpg->bsrc < 0);
5971 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5972 + err = PTR_ERR(h_file);
5973 + if (IS_ERR(h_file))
5977 + parent = dget_parent(dentry);
5978 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5979 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5980 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5981 + err = au_cpup_simple(cpg);
5983 + struct au_cpup_simple_args args = {
5987 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5988 + if (unlikely(wkq_err))
5994 + au_h_open_post(dentry, cpg->bsrc, h_file);
6000 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6002 + aufs_bindex_t bsrc, bbot;
6003 + struct dentry *dentry, *h_dentry;
6005 + if (cpg->bsrc < 0) {
6006 + dentry = cpg->dentry;
6007 + bbot = au_dbbot(dentry);
6008 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6009 + h_dentry = au_h_dptr(dentry, bsrc);
6011 + AuDebugOn(d_is_negative(h_dentry));
6015 + AuDebugOn(bsrc > bbot);
6018 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6019 + return au_do_sio_cpup_simple(cpg);
6022 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6024 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6025 + return au_do_sio_cpup_simple(cpg);
6028 +/* ---------------------------------------------------------------------- */
6031 + * copyup the deleted file for writing.
6033 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6034 + struct file *file)
6037 + unsigned int flags_orig;
6038 + aufs_bindex_t bsrc_orig;
6039 + struct au_dinfo *dinfo;
6041 + struct au_hdentry *hd;
6042 + struct dentry *h_dentry;
6045 + dinfo = au_di(cpg->dentry);
6046 + AuRwMustWriteLock(&dinfo->di_rwsem);
6048 + bsrc_orig = cpg->bsrc;
6049 + cpg->bsrc = dinfo->di_btop;
6050 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6051 + hdst.h_dentry = hdst.hd->hd_dentry;
6052 + hdst.hd->hd_dentry = wh_dentry;
6053 + dinfo->di_btop = cpg->bdst;
6055 + hsrc.h_dentry = NULL;
6057 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6058 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6059 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6061 + flags_orig = cpg->flags;
6062 + cpg->flags = !AuCpup_DTIME;
6063 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6064 + cpg->flags = flags_orig;
6067 + err = au_reopen_nondir(file);
6068 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6070 + hdst.hd->hd_dentry = hdst.h_dentry;
6071 + dinfo->di_btop = cpg->bsrc;
6072 + cpg->bsrc = bsrc_orig;
6077 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6080 + aufs_bindex_t bdst;
6081 + struct au_dtime dt;
6082 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6083 + struct au_branch *br;
6084 + struct path h_path;
6086 + dentry = cpg->dentry;
6088 + br = au_sbr(dentry->d_sb, bdst);
6089 + parent = dget_parent(dentry);
6090 + h_parent = au_h_dptr(parent, bdst);
6091 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6092 + err = PTR_ERR(wh_dentry);
6093 + if (IS_ERR(wh_dentry))
6096 + h_path.dentry = h_parent;
6097 + h_path.mnt = au_br_mnt(br);
6098 + au_dtime_store(&dt, parent, &h_path);
6099 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6100 + if (unlikely(err))
6104 + h_path.dentry = wh_dentry;
6105 + if (!d_is_dir(wh_dentry)) {
6106 + /* no delegation since it is just created */
6107 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6108 + /*delegated*/NULL, /*force*/0);
6110 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6111 + if (unlikely(err)) {
6112 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6116 + au_dtime_revert(&dt);
6117 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6126 +struct au_cpup_wh_args {
6128 + struct au_cp_generic *cpg;
6129 + struct file *file;
6132 +static void au_call_cpup_wh(void *args)
6134 + struct au_cpup_wh_args *a = args;
6136 + au_pin_hdir_acquire_nest(a->cpg->pin);
6137 + *a->errp = au_cpup_wh(a->cpg, a->file);
6138 + au_pin_hdir_release(a->cpg->pin);
6141 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6144 + aufs_bindex_t bdst;
6145 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6146 + struct inode *dir, *h_dir, *h_tmpdir;
6147 + struct au_wbr *wbr;
6148 + struct au_pin wh_pin, *pin_orig;
6150 + dentry = cpg->dentry;
6152 + parent = dget_parent(dentry);
6153 + dir = d_inode(parent);
6156 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6159 + if (!h_dir->i_nlink) {
6160 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6161 + h_orph = wbr->wbr_orph;
6163 + h_parent = dget(au_h_dptr(parent, bdst));
6164 + au_set_h_dptr(parent, bdst, dget(h_orph));
6165 + h_tmpdir = d_inode(h_orph);
6166 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6168 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6169 + /* todo: au_h_open_pre()? */
6171 + pin_orig = cpg->pin;
6172 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6173 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6174 + cpg->pin = &wh_pin;
6177 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6178 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6179 + err = au_cpup_wh(cpg, file);
6181 + struct au_cpup_wh_args args = {
6186 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6187 + if (unlikely(wkq_err))
6192 + inode_unlock(h_tmpdir);
6193 + /* todo: au_h_open_post()? */
6194 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6195 + au_set_h_dptr(parent, bdst, h_parent);
6196 + AuDebugOn(!pin_orig);
6197 + cpg->pin = pin_orig;
6205 +/* ---------------------------------------------------------------------- */
6208 + * generic routine for both of copy-up and copy-down.
6210 +/* cf. revalidate function in file.c */
6211 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6212 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6213 + struct au_pin *pin,
6214 + struct dentry *h_parent, void *arg),
6218 + struct au_pin pin;
6219 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6222 + parent = dget_parent(dentry);
6223 + if (IS_ROOT(parent))
6226 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6227 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6229 + /* do not use au_dpage */
6230 + real_parent = parent;
6233 + parent = dget_parent(dentry);
6234 + h_parent = au_h_dptr(parent, bdst);
6236 + goto out; /* success */
6238 + /* find top dir which is necessary to cpup */
6242 + parent = dget_parent(d);
6243 + di_read_lock_parent3(parent, !AuLock_IR);
6244 + h_parent = au_h_dptr(parent, bdst);
6245 + di_read_unlock(parent, !AuLock_IR);
6246 + } while (!h_parent);
6248 + if (d != real_parent)
6249 + di_write_lock_child3(d);
6251 + /* somebody else might create while we were sleeping */
6252 + h_dentry = au_h_dptr(d, bdst);
6253 + if (!h_dentry || d_is_negative(h_dentry)) {
6255 + au_update_dbtop(d);
6257 + au_pin_set_dentry(&pin, d);
6258 + err = au_do_pin(&pin);
6260 + err = cp(d, bdst, &pin, h_parent, arg);
6265 + if (d != real_parent)
6266 + di_write_unlock(d);
6267 + if (unlikely(err))
6276 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6277 + struct au_pin *pin,
6278 + struct dentry *h_parent __maybe_unused,
6279 + void *arg __maybe_unused)
6281 + struct au_cp_generic cpg = {
6287 + .flags = AuCpup_DTIME
6289 + return au_sio_cpup_simple(&cpg);
6292 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6294 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6297 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6300 + struct dentry *parent;
6301 + struct inode *dir;
6303 + parent = dget_parent(dentry);
6304 + dir = d_inode(parent);
6306 + if (au_h_iptr(dir, bdst))
6309 + di_read_unlock(parent, AuLock_IR);
6310 + di_write_lock_parent(parent);
6311 + /* someone else might change our inode while we were sleeping */
6312 + if (!au_h_iptr(dir, bdst))
6313 + err = au_cpup_dirs(dentry, bdst);
6314 + di_downgrade_lock(parent, AuLock_IR);
6320 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6321 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6322 +++ linux/fs/aufs/cpup.h 2019-07-11 15:42:14.462237786 +0200
6324 +/* SPDX-License-Identifier: GPL-2.0 */
6326 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6328 + * This program, aufs is free software; you can redistribute it and/or modify
6329 + * it under the terms of the GNU General Public License as published by
6330 + * the Free Software Foundation; either version 2 of the License, or
6331 + * (at your option) any later version.
6333 + * This program is distributed in the hope that it will be useful,
6334 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6335 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6336 + * GNU General Public License for more details.
6338 + * You should have received a copy of the GNU General Public License
6339 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6343 + * copy-up/down functions
6346 +#ifndef __AUFS_CPUP_H__
6347 +#define __AUFS_CPUP_H__
6351 +#include <linux/path.h>
6357 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6358 +void au_cpup_attr_timesizes(struct inode *inode);
6359 +void au_cpup_attr_nlink(struct inode *inode, int force);
6360 +void au_cpup_attr_changeable(struct inode *inode);
6361 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6362 +void au_cpup_attr_all(struct inode *inode, int force);
6364 +/* ---------------------------------------------------------------------- */
6366 +struct au_cp_generic {
6367 + struct dentry *dentry;
6368 + aufs_bindex_t bdst, bsrc;
6370 + struct au_pin *pin;
6371 + unsigned int flags;
6375 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6376 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6378 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6379 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6381 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6383 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6384 + the branch is marked as RO */
6386 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6387 +#undef AuCpup_HOPEN
6388 +#define AuCpup_HOPEN 0
6391 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6392 +#define au_fset_cpup(flags, name) \
6393 + do { (flags) |= AuCpup_##name; } while (0)
6394 +#define au_fclr_cpup(flags, name) \
6395 + do { (flags) &= ~AuCpup_##name; } while (0)
6397 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6398 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6399 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6400 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6402 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6403 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6404 + struct au_pin *pin,
6405 + struct dentry *h_parent, void *arg),
6407 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6408 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6410 +/* ---------------------------------------------------------------------- */
6412 +/* keep timestamps when copyup */
6414 + struct dentry *dt_dentry;
6415 + struct path dt_h_path;
6416 + struct timespec64 dt_atime, dt_mtime;
6418 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6419 + struct path *h_path);
6420 +void au_dtime_revert(struct au_dtime *dt);
6422 +#endif /* __KERNEL__ */
6423 +#endif /* __AUFS_CPUP_H__ */
6424 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6425 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6426 +++ linux/fs/aufs/dbgaufs.c 2019-07-11 15:42:14.462237786 +0200
6428 +// SPDX-License-Identifier: GPL-2.0
6430 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6432 + * This program, aufs is free software; you can redistribute it and/or modify
6433 + * it under the terms of the GNU General Public License as published by
6434 + * the Free Software Foundation; either version 2 of the License, or
6435 + * (at your option) any later version.
6437 + * This program is distributed in the hope that it will be useful,
6438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6440 + * GNU General Public License for more details.
6442 + * You should have received a copy of the GNU General Public License
6443 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6447 + * debugfs interface
6450 +#include <linux/debugfs.h>
6453 +#ifndef CONFIG_SYSFS
6454 +#error DEBUG_FS depends upon SYSFS
6457 +static struct dentry *dbgaufs;
6458 +static const mode_t dbgaufs_mode = 0444;
6460 +/* 20 is max digits length of ulong 64 */
6461 +struct dbgaufs_arg {
6467 + * common function for all XINO files
6469 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6470 + struct file *file)
6474 + p = file->private_data;
6476 + /* this is struct dbgaufs_arg */
6477 + AuDebugOn(!au_kfree_sz_test(p));
6478 + au_kfree_do_rcu(p);
6483 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6488 + struct dbgaufs_arg *p;
6491 + p = kmalloc(sizeof(*p), GFP_NOFS);
6497 + file->private_data = p;
6501 + err = vfsub_getattr(&xf->f_path, &st);
6505 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6506 + cnt, st.blocks, st.blksize,
6507 + (long long)st.size);
6509 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6510 + st.blocks, st.blksize,
6511 + (long long)st.size);
6512 + AuDebugOn(p->n >= sizeof(p->a));
6514 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6522 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6523 + size_t count, loff_t *ppos)
6525 + struct dbgaufs_arg *p;
6527 + p = file->private_data;
6528 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6531 +/* ---------------------------------------------------------------------- */
6533 +struct dbgaufs_plink_arg {
6538 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6539 + struct file *file)
6541 + free_page((unsigned long)file->private_data);
6545 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6547 + int err, i, limit;
6548 + unsigned long n, sum;
6549 + struct dbgaufs_plink_arg *p;
6550 + struct au_sbinfo *sbinfo;
6551 + struct super_block *sb;
6552 + struct hlist_bl_head *hbl;
6555 + p = (void *)get_zeroed_page(GFP_NOFS);
6560 + sbinfo = inode->i_private;
6561 + sb = sbinfo->si_sb;
6562 + si_noflush_read_lock(sb);
6563 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6564 + limit = PAGE_SIZE - sizeof(p->n);
6566 + /* the number of buckets */
6567 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6572 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6574 + n = au_hbl_count(hbl);
6577 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6580 + if (unlikely(limit <= 0))
6583 + p->a[p->n - 1] = '\n';
6585 + /* the sum of plinks */
6586 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6589 + if (unlikely(limit <= 0))
6592 +#define str "1\n0\n0\n"
6593 + p->n = sizeof(str) - 1;
6594 + strcpy(p->a, str);
6597 + si_read_unlock(sb);
6600 + file->private_data = p;
6601 + goto out; /* success */
6604 + free_page((unsigned long)p);
6609 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6610 + size_t count, loff_t *ppos)
6612 + struct dbgaufs_plink_arg *p;
6614 + p = file->private_data;
6615 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6618 +static const struct file_operations dbgaufs_plink_fop = {
6619 + .owner = THIS_MODULE,
6620 + .open = dbgaufs_plink_open,
6621 + .release = dbgaufs_plink_release,
6622 + .read = dbgaufs_plink_read
6625 +/* ---------------------------------------------------------------------- */
6627 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6630 + struct au_sbinfo *sbinfo;
6631 + struct super_block *sb;
6633 + sbinfo = inode->i_private;
6634 + sb = sbinfo->si_sb;
6635 + si_noflush_read_lock(sb);
6636 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6637 + si_read_unlock(sb);
6641 +static const struct file_operations dbgaufs_xib_fop = {
6642 + .owner = THIS_MODULE,
6643 + .open = dbgaufs_xib_open,
6644 + .release = dbgaufs_xi_release,
6645 + .read = dbgaufs_xi_read
6648 +/* ---------------------------------------------------------------------- */
6650 +#define DbgaufsXi_PREFIX "xi"
6652 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6656 + aufs_bindex_t bindex;
6657 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6658 + struct au_sbinfo *sbinfo;
6659 + struct super_block *sb;
6660 + struct au_xino *xi;
6662 + struct qstr *name;
6663 + struct au_branch *br;
6666 + name = &file->f_path.dentry->d_name;
6667 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6668 + || memcmp(name->name, DbgaufsXi_PREFIX,
6669 + sizeof(DbgaufsXi_PREFIX) - 1)))
6672 + AuDebugOn(name->len >= sizeof(a));
6673 + memcpy(a, name->name, name->len);
6674 + a[name->len] = '\0';
6675 + p = strchr(a, '-');
6678 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6679 + if (unlikely(err))
6684 + err = kstrtol(p + 1, 10, &l);
6685 + if (unlikely(err))
6691 + sbinfo = inode->i_private;
6692 + sb = sbinfo->si_sb;
6693 + si_noflush_read_lock(sb);
6694 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6696 + br = au_sbr(sb, bindex);
6698 + if (unlikely(idx >= xi->xi_nfile))
6700 + xf = au_xino_file(xi, idx);
6702 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6703 + au_xino_count(br));
6706 + si_read_unlock(sb);
6712 +static const struct file_operations dbgaufs_xino_fop = {
6713 + .owner = THIS_MODULE,
6714 + .open = dbgaufs_xino_open,
6715 + .release = dbgaufs_xi_release,
6716 + .read = dbgaufs_xi_read
6719 +void dbgaufs_xino_del(struct au_branch *br)
6721 + struct dentry *dbgaufs;
6723 + dbgaufs = br->br_dbgaufs;
6727 + br->br_dbgaufs = NULL;
6728 + /* debugfs acquires the parent i_mutex */
6730 + debugfs_remove(dbgaufs);
6734 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6736 + aufs_bindex_t bbot;
6737 + struct au_branch *br;
6739 + if (!au_sbi(sb)->si_dbgaufs)
6742 + bbot = au_sbbot(sb);
6743 + for (; bindex <= bbot; bindex++) {
6744 + br = au_sbr(sb, bindex);
6745 + dbgaufs_xino_del(br);
6749 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6750 + unsigned int idx, struct dentry *parent,
6751 + struct au_sbinfo *sbinfo)
6753 + struct au_branch *br;
6755 + /* "xi" bindex(5) "-" idx(2) NULL */
6756 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6759 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6761 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6763 + br = au_sbr(sb, bindex);
6764 + if (br->br_dbgaufs) {
6765 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6767 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6768 + /* debugfs acquires the parent i_mutex */
6770 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6774 + pr_warn("failed renaming %pd/%s, ignored.\n",
6779 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6780 + sbinfo, &dbgaufs_xino_fop);
6782 + if (unlikely(!br->br_dbgaufs))
6783 + pr_warn("failed creating %pd/%s, ignored.\n",
6788 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6789 + struct dentry *parent, struct au_sbinfo *sbinfo)
6791 + struct au_branch *br;
6792 + struct au_xino *xi;
6795 + br = au_sbr(sb, bindex);
6797 + for (u = 0; u < xi->xi_nfile; u++)
6798 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6801 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6803 + struct au_sbinfo *sbinfo;
6804 + struct dentry *parent;
6805 + aufs_bindex_t bbot;
6807 + if (!au_opt_test(au_mntflags(sb), XINO))
6810 + sbinfo = au_sbi(sb);
6811 + parent = sbinfo->si_dbgaufs;
6815 + bbot = au_sbbot(sb);
6817 + for (; bindex <= bbot; bindex++)
6818 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6820 + for (; bbot >= bindex; bbot--)
6821 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6824 +/* ---------------------------------------------------------------------- */
6826 +#ifdef CONFIG_AUFS_EXPORT
6827 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6830 + struct au_sbinfo *sbinfo;
6831 + struct super_block *sb;
6833 + sbinfo = inode->i_private;
6834 + sb = sbinfo->si_sb;
6835 + si_noflush_read_lock(sb);
6836 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6837 + si_read_unlock(sb);
6841 +static const struct file_operations dbgaufs_xigen_fop = {
6842 + .owner = THIS_MODULE,
6843 + .open = dbgaufs_xigen_open,
6844 + .release = dbgaufs_xi_release,
6845 + .read = dbgaufs_xi_read
6848 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6853 + * This function is a dynamic '__init' function actually,
6854 + * so the tiny check for si_rwsem is unnecessary.
6856 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6859 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6860 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6861 + &dbgaufs_xigen_fop);
6862 + if (sbinfo->si_dbgaufs_xigen)
6868 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6872 +#endif /* CONFIG_AUFS_EXPORT */
6874 +/* ---------------------------------------------------------------------- */
6876 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6879 + * This function is a dynamic '__fin' function actually,
6880 + * so the tiny check for si_rwsem is unnecessary.
6882 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6884 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6885 + sbinfo->si_dbgaufs = NULL;
6888 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6891 + char name[SysaufsSiNameLen];
6894 + * This function is a dynamic '__init' function actually,
6895 + * so the tiny check for si_rwsem is unnecessary.
6897 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6901 + AuErr1("/debug/aufs is uninitialized\n");
6906 + sysaufs_name(sbinfo, name);
6907 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6908 + if (unlikely(!sbinfo->si_dbgaufs))
6911 + /* regardless plink/noplink option */
6912 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6913 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6914 + &dbgaufs_plink_fop);
6915 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6918 + /* regardless xino/noxino option */
6919 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6920 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6921 + &dbgaufs_xib_fop);
6922 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6925 + err = dbgaufs_xigen_init(sbinfo);
6927 + goto out; /* success */
6930 + dbgaufs_si_fin(sbinfo);
6932 + if (unlikely(err))
6933 + pr_err("debugfs/aufs failed\n");
6937 +/* ---------------------------------------------------------------------- */
6939 +void dbgaufs_fin(void)
6941 + debugfs_remove(dbgaufs);
6944 +int __init dbgaufs_init(void)
6949 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6954 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6955 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6956 +++ linux/fs/aufs/dbgaufs.h 2019-07-11 15:42:14.462237786 +0200
6958 +/* SPDX-License-Identifier: GPL-2.0 */
6960 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6962 + * This program, aufs is free software; you can redistribute it and/or modify
6963 + * it under the terms of the GNU General Public License as published by
6964 + * the Free Software Foundation; either version 2 of the License, or
6965 + * (at your option) any later version.
6967 + * This program is distributed in the hope that it will be useful,
6968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6970 + * GNU General Public License for more details.
6972 + * You should have received a copy of the GNU General Public License
6973 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6977 + * debugfs interface
6980 +#ifndef __DBGAUFS_H__
6981 +#define __DBGAUFS_H__
6985 +struct super_block;
6989 +#ifdef CONFIG_DEBUG_FS
6991 +void dbgaufs_xino_del(struct au_branch *br);
6992 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6993 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6994 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6995 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6996 +void dbgaufs_fin(void);
6997 +int __init dbgaufs_init(void);
6999 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7000 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7001 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7003 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7004 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7005 +AuStubVoid(dbgaufs_fin, void)
7006 +AuStubInt0(__init dbgaufs_init, void)
7007 +#endif /* CONFIG_DEBUG_FS */
7009 +#endif /* __KERNEL__ */
7010 +#endif /* __DBGAUFS_H__ */
7011 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7012 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7013 +++ linux/fs/aufs/dcsub.c 2019-07-11 15:42:14.462237786 +0200
7015 +// SPDX-License-Identifier: GPL-2.0
7017 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7019 + * This program, aufs is free software; you can redistribute it and/or modify
7020 + * it under the terms of the GNU General Public License as published by
7021 + * the Free Software Foundation; either version 2 of the License, or
7022 + * (at your option) any later version.
7024 + * This program is distributed in the hope that it will be useful,
7025 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7026 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7027 + * GNU General Public License for more details.
7029 + * You should have received a copy of the GNU General Public License
7030 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7034 + * sub-routines for dentry cache
7039 +static void au_dpage_free(struct au_dpage *dpage)
7042 + struct dentry **p;
7044 + p = dpage->dentries;
7045 + for (i = 0; i < dpage->ndentry; i++)
7047 + free_page((unsigned long)dpage->dentries);
7050 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7056 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7057 + if (unlikely(!dpages->dpages))
7060 + p = (void *)__get_free_page(gfp);
7064 + dpages->dpages[0].ndentry = 0;
7065 + dpages->dpages[0].dentries = p;
7066 + dpages->ndpage = 1;
7067 + return 0; /* success */
7070 + au_kfree_try_rcu(dpages->dpages);
7075 +void au_dpages_free(struct au_dcsub_pages *dpages)
7078 + struct au_dpage *p;
7080 + p = dpages->dpages;
7081 + for (i = 0; i < dpages->ndpage; i++)
7082 + au_dpage_free(p++);
7083 + au_kfree_try_rcu(dpages->dpages);
7086 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7087 + struct dentry *dentry, gfp_t gfp)
7090 + struct au_dpage *dpage;
7093 + dpage = dpages->dpages + dpages->ndpage - 1;
7094 + sz = PAGE_SIZE / sizeof(dentry);
7095 + if (unlikely(dpage->ndentry >= sz)) {
7096 + AuLabel(new dpage);
7098 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7099 + p = au_kzrealloc(dpages->dpages, sz,
7100 + sz + sizeof(*dpages->dpages), gfp,
7105 + dpages->dpages = p;
7106 + dpage = dpages->dpages + dpages->ndpage;
7107 + p = (void *)__get_free_page(gfp);
7111 + dpage->ndentry = 0;
7112 + dpage->dentries = p;
7116 + AuDebugOn(au_dcount(dentry) <= 0);
7117 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7118 + return 0; /* success */
7124 +/* todo: BAD approach */
7125 +/* copied from linux/fs/dcache.c */
7133 +extern void d_walk(struct dentry *parent, void *data,
7134 + enum d_walk_ret (*enter)(void *, struct dentry *));
7136 +struct ac_dpages_arg {
7138 + struct au_dcsub_pages *dpages;
7139 + struct super_block *sb;
7140 + au_dpages_test test;
7144 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7146 + enum d_walk_ret ret;
7147 + struct ac_dpages_arg *arg = _arg;
7149 + ret = D_WALK_CONTINUE;
7150 + if (dentry->d_sb == arg->sb
7151 + && !IS_ROOT(dentry)
7152 + && au_dcount(dentry) > 0
7154 + && (!arg->test || arg->test(dentry, arg->arg))) {
7155 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7156 + if (unlikely(arg->err))
7157 + ret = D_WALK_QUIT;
7163 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7164 + au_dpages_test test, void *arg)
7166 + struct ac_dpages_arg args = {
7174 + d_walk(root, &args, au_call_dpages_append);
7179 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7180 + int do_include, au_dpages_test test, void *arg)
7185 + write_seqlock(&rename_lock);
7186 + spin_lock(&dentry->d_lock);
7188 + && au_dcount(dentry) > 0
7189 + && (!test || test(dentry, arg)))
7190 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7191 + spin_unlock(&dentry->d_lock);
7192 + if (unlikely(err))
7196 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7199 + while (!IS_ROOT(dentry)) {
7200 + dentry = dentry->d_parent; /* rename_lock is locked */
7201 + spin_lock(&dentry->d_lock);
7202 + if (au_dcount(dentry) > 0
7203 + && (!test || test(dentry, arg)))
7204 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7205 + spin_unlock(&dentry->d_lock);
7206 + if (unlikely(err))
7211 + write_sequnlock(&rename_lock);
7215 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7217 + return au_di(dentry) && dentry->d_sb == arg;
7220 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7221 + struct dentry *dentry, int do_include)
7223 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7224 + au_dcsub_dpages_aufs, dentry->d_sb);
7227 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7229 + struct path path[2] = {
7238 + return path_is_under(path + 0, path + 1);
7240 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7241 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7242 +++ linux/fs/aufs/dcsub.h 2019-07-11 15:42:14.462237786 +0200
7244 +/* SPDX-License-Identifier: GPL-2.0 */
7246 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7248 + * This program, aufs is free software; you can redistribute it and/or modify
7249 + * it under the terms of the GNU General Public License as published by
7250 + * the Free Software Foundation; either version 2 of the License, or
7251 + * (at your option) any later version.
7253 + * This program is distributed in the hope that it will be useful,
7254 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7255 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7256 + * GNU General Public License for more details.
7258 + * You should have received a copy of the GNU General Public License
7259 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7263 + * sub-routines for dentry cache
7266 +#ifndef __AUFS_DCSUB_H__
7267 +#define __AUFS_DCSUB_H__
7271 +#include <linux/dcache.h>
7272 +#include <linux/fs.h>
7276 + struct dentry **dentries;
7279 +struct au_dcsub_pages {
7281 + struct au_dpage *dpages;
7284 +/* ---------------------------------------------------------------------- */
7287 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7288 +void au_dpages_free(struct au_dcsub_pages *dpages);
7289 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7290 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7291 + au_dpages_test test, void *arg);
7292 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7293 + int do_include, au_dpages_test test, void *arg);
7294 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7295 + struct dentry *dentry, int do_include);
7296 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7298 +/* ---------------------------------------------------------------------- */
7301 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7302 + * include/linux/dcache.h. Try them (in the future).
7305 +static inline int au_d_hashed_positive(struct dentry *d)
7308 + struct inode *inode = d_inode(d);
7311 + if (unlikely(d_unhashed(d)
7312 + || d_is_negative(d)
7313 + || !inode->i_nlink))
7318 +static inline int au_d_linkable(struct dentry *d)
7321 + struct inode *inode = d_inode(d);
7323 + err = au_d_hashed_positive(d);
7325 + && d_is_positive(d)
7326 + && (inode->i_state & I_LINKABLE))
7331 +static inline int au_d_alive(struct dentry *d)
7334 + struct inode *inode;
7338 + err = au_d_hashed_positive(d);
7340 + inode = d_inode(d);
7341 + if (unlikely(d_unlinked(d)
7342 + || d_is_negative(d)
7343 + || !inode->i_nlink))
7349 +static inline int au_alive_dir(struct dentry *d)
7353 + err = au_d_alive(d);
7354 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7359 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7361 + return a->len == b->len
7362 + && !memcmp(a->name, b->name, a->len);
7367 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7369 + * the type of d_lockref.count became int, but the inlined function d_count()
7370 + * still returns unsigned int.
7371 + * I don't know why. Maybe it is for every d_count() users?
7372 + * Anyway au_dcount() lives on.
7374 +static inline int au_dcount(struct dentry *d)
7376 + return (int)d_count(d);
7379 +#endif /* __KERNEL__ */
7380 +#endif /* __AUFS_DCSUB_H__ */
7381 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7382 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7383 +++ linux/fs/aufs/debug.c 2019-07-11 15:42:14.462237786 +0200
7385 +// SPDX-License-Identifier: GPL-2.0
7387 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7389 + * This program, aufs is free software; you can redistribute it and/or modify
7390 + * it under the terms of the GNU General Public License as published by
7391 + * the Free Software Foundation; either version 2 of the License, or
7392 + * (at your option) any later version.
7394 + * This program is distributed in the hope that it will be useful,
7395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7397 + * GNU General Public License for more details.
7399 + * You should have received a copy of the GNU General Public License
7400 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7404 + * debug print functions
7407 +#include <linux/iversion.h>
7410 +/* Returns 0, or -errno. arg is in kp->arg. */
7411 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7415 + err = kstrtoint(val, 0, &n);
7425 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7426 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7431 + return sprintf(buffer, "%d", atomic_read(a));
7434 +static struct kernel_param_ops param_ops_atomic_t = {
7435 + .set = param_atomic_t_set,
7436 + .get = param_atomic_t_get
7437 + /* void (*free)(void *arg) */
7440 +atomic_t aufs_debug = ATOMIC_INIT(0);
7441 +MODULE_PARM_DESC(debug, "debug print");
7442 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7444 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7445 +char *au_plevel = KERN_DEBUG;
7446 +#define dpri(fmt, ...) do { \
7448 + && strcmp(au_plevel, KERN_DEBUG)) \
7449 + || au_debug_test()) \
7450 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7453 +/* ---------------------------------------------------------------------- */
7455 +void au_dpri_whlist(struct au_nhash *whlist)
7457 + unsigned long ul, n;
7458 + struct hlist_head *head;
7459 + struct au_vdir_wh *pos;
7461 + n = whlist->nh_num;
7462 + head = whlist->nh_head;
7463 + for (ul = 0; ul < n; ul++) {
7464 + hlist_for_each_entry(pos, head, wh_hash)
7465 + dpri("b%d, %.*s, %d\n",
7467 + pos->wh_str.len, pos->wh_str.name,
7473 +void au_dpri_vdir(struct au_vdir *vdir)
7476 + union au_vdir_deblk_p p;
7479 + if (!vdir || IS_ERR(vdir)) {
7480 + dpri("err %ld\n", PTR_ERR(vdir));
7484 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7485 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7486 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7487 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7488 + p.deblk = vdir->vd_deblk[ul];
7490 + dpri("[%lu]: %p\n", ul, o);
7494 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7495 + struct dentry *wh)
7500 + if (!inode || IS_ERR(inode)) {
7501 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7505 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7506 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7507 + && sizeof(inode->i_blocks) != sizeof(u64));
7509 + n = (void *)wh->d_name.name;
7510 + l = wh->d_name.len;
7513 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7514 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7516 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7517 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7518 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7519 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7520 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7521 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7522 + inode->i_generation,
7523 + l ? ", wh " : "", l, n);
7527 +void au_dpri_inode(struct inode *inode)
7529 + struct au_iinfo *iinfo;
7530 + struct au_hinode *hi;
7531 + aufs_bindex_t bindex;
7534 + err = do_pri_inode(-1, inode, -1, NULL);
7535 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7538 + iinfo = au_ii(inode);
7539 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7540 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7541 + if (iinfo->ii_btop < 0)
7544 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7545 + hi = au_hinode(iinfo, bindex);
7547 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7551 +void au_dpri_dalias(struct inode *inode)
7555 + spin_lock(&inode->i_lock);
7556 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7557 + au_dpri_dentry(d);
7558 + spin_unlock(&inode->i_lock);
7561 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7563 + struct dentry *wh = NULL;
7565 + struct inode *inode;
7566 + struct au_iinfo *iinfo;
7567 + struct au_hinode *hi;
7569 + if (!dentry || IS_ERR(dentry)) {
7570 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7573 + /* do not call dget_parent() here */
7574 + /* note: access d_xxx without d_lock */
7575 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7576 + bindex, dentry, dentry,
7577 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7578 + au_dcount(dentry), dentry->d_flags,
7579 + d_unhashed(dentry) ? "un" : "");
7582 + if (d_is_positive(dentry))
7583 + inode = d_inode(dentry);
7585 + && au_test_aufs(dentry->d_sb)
7587 + && !au_is_bad_inode(inode)) {
7588 + iinfo = au_ii(inode);
7589 + hi = au_hinode(iinfo, bindex);
7591 + wh = hi->hi_whdentry;
7593 + do_pri_inode(bindex, inode, hn, wh);
7597 +void au_dpri_dentry(struct dentry *dentry)
7599 + struct au_dinfo *dinfo;
7600 + aufs_bindex_t bindex;
7603 + err = do_pri_dentry(-1, dentry);
7604 + if (err || !au_test_aufs(dentry->d_sb))
7607 + dinfo = au_di(dentry);
7610 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7611 + dinfo->di_btop, dinfo->di_bbot,
7612 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7613 + dinfo->di_tmpfile);
7614 + if (dinfo->di_btop < 0)
7616 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7617 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7620 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7624 + if (!file || IS_ERR(file)) {
7625 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7630 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7631 + && au_test_aufs(file->f_path.dentry->d_sb)
7633 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7634 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7635 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7636 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7637 + file->f_version, file->f_pos, a);
7638 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7639 + do_pri_dentry(bindex, file->f_path.dentry);
7643 +void au_dpri_file(struct file *file)
7645 + struct au_finfo *finfo;
7646 + struct au_fidir *fidir;
7647 + struct au_hfile *hfile;
7648 + aufs_bindex_t bindex;
7651 + err = do_pri_file(-1, file);
7653 + || IS_ERR_OR_NULL(file->f_path.dentry)
7654 + || !au_test_aufs(file->f_path.dentry->d_sb))
7657 + finfo = au_fi(file);
7660 + if (finfo->fi_btop < 0)
7662 + fidir = finfo->fi_hdir;
7664 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7666 + for (bindex = finfo->fi_btop;
7667 + bindex >= 0 && bindex <= fidir->fd_bbot;
7669 + hfile = fidir->fd_hfile + bindex;
7670 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7674 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7676 + struct vfsmount *mnt;
7677 + struct super_block *sb;
7679 + if (!br || IS_ERR(br))
7681 + mnt = au_br_mnt(br);
7682 + if (!mnt || IS_ERR(mnt))
7685 + if (!sb || IS_ERR(sb))
7688 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7689 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7691 + bindex, br->br_perm, br->br_id, br->br_wbr,
7692 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7693 + sb->s_flags, sb->s_count,
7694 + atomic_read(&sb->s_active),
7695 + !!au_xino_file(br->br_xino, /*idx*/-1));
7699 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7703 +void au_dpri_sb(struct super_block *sb)
7705 + struct au_sbinfo *sbinfo;
7706 + aufs_bindex_t bindex;
7708 + /* to reduce stack size */
7710 + struct vfsmount mnt;
7711 + struct au_branch fake;
7714 + /* this function can be called from magic sysrq */
7715 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7716 + if (unlikely(!a)) {
7717 + dpri("no memory\n");
7721 + a->mnt.mnt_sb = sb;
7722 + a->fake.br_path.mnt = &a->mnt;
7723 + err = do_pri_br(-1, &a->fake);
7725 + dpri("dev 0x%x\n", sb->s_dev);
7726 + if (err || !au_test_aufs(sb))
7729 + sbinfo = au_sbi(sb);
7732 + dpri("nw %d, gen %u, kobj %d\n",
7733 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7734 + kref_read(&sbinfo->si_kobj.kref));
7735 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7736 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7739 +/* ---------------------------------------------------------------------- */
7741 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7743 + struct inode *h_inode, *inode = d_inode(dentry);
7744 + struct dentry *h_dentry;
7745 + aufs_bindex_t bindex, bbot, bi;
7747 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7750 + bbot = au_dbbot(dentry);
7751 + bi = au_ibbot(inode);
7754 + bindex = au_dbtop(dentry);
7755 + bi = au_ibtop(inode);
7759 + for (; bindex <= bbot; bindex++) {
7760 + h_dentry = au_h_dptr(dentry, bindex);
7763 + h_inode = au_h_iptr(inode, bindex);
7764 + if (unlikely(h_inode != d_inode(h_dentry))) {
7766 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7767 + AuDbgDentry(dentry);
7768 + AuDbgInode(inode);
7775 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7778 + struct au_dcsub_pages dpages;
7779 + struct au_dpage *dpage;
7780 + struct dentry **dentries;
7782 + err = au_dpages_init(&dpages, GFP_NOFS);
7784 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7786 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7787 + dpage = dpages.dpages + i;
7788 + dentries = dpage->dentries;
7789 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7790 + AuDebugOn(au_digen_test(dentries[j], sigen));
7792 + au_dpages_free(&dpages);
7795 +void au_dbg_verify_kthread(void)
7797 + if (au_wkq_test()) {
7800 + * It may be recursive, but udba=notify between two aufs mounts,
7801 + * where a single ro branch is shared, is not a problem.
7807 +/* ---------------------------------------------------------------------- */
7809 +int __init au_debug_init(void)
7811 + aufs_bindex_t bindex;
7812 + struct au_vdir_destr destr;
7815 + AuDebugOn(bindex >= 0);
7818 + AuDebugOn(destr.len < NAME_MAX);
7820 +#ifdef CONFIG_4KSTACKS
7821 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7826 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7827 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7828 +++ linux/fs/aufs/debug.h 2019-07-11 15:42:14.462237786 +0200
7830 +/* SPDX-License-Identifier: GPL-2.0 */
7832 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7834 + * This program, aufs is free software; you can redistribute it and/or modify
7835 + * it under the terms of the GNU General Public License as published by
7836 + * the Free Software Foundation; either version 2 of the License, or
7837 + * (at your option) any later version.
7839 + * This program is distributed in the hope that it will be useful,
7840 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7841 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7842 + * GNU General Public License for more details.
7844 + * You should have received a copy of the GNU General Public License
7845 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7849 + * debug print functions
7852 +#ifndef __AUFS_DEBUG_H__
7853 +#define __AUFS_DEBUG_H__
7857 +#include <linux/atomic.h>
7858 +#include <linux/module.h>
7859 +#include <linux/kallsyms.h>
7860 +#include <linux/sysrq.h>
7862 +#ifdef CONFIG_AUFS_DEBUG
7863 +#define AuDebugOn(a) BUG_ON(a)
7865 +/* module parameter */
7866 +extern atomic_t aufs_debug;
7867 +static inline void au_debug_on(void)
7869 + atomic_inc(&aufs_debug);
7871 +static inline void au_debug_off(void)
7873 + atomic_dec_if_positive(&aufs_debug);
7876 +static inline int au_debug_test(void)
7878 + return atomic_read(&aufs_debug) > 0;
7881 +#define AuDebugOn(a) do {} while (0)
7882 +AuStubVoid(au_debug_on, void)
7883 +AuStubVoid(au_debug_off, void)
7884 +AuStubInt0(au_debug_test, void)
7885 +#endif /* CONFIG_AUFS_DEBUG */
7887 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7889 +/* ---------------------------------------------------------------------- */
7893 +#define AuDbg(fmt, ...) do { \
7894 + if (au_debug_test()) \
7895 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7897 +#define AuLabel(l) AuDbg(#l "\n")
7898 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7899 +#define AuWarn1(fmt, ...) do { \
7900 + static unsigned char _c; \
7902 + pr_warn(fmt, ##__VA_ARGS__); \
7905 +#define AuErr1(fmt, ...) do { \
7906 + static unsigned char _c; \
7908 + pr_err(fmt, ##__VA_ARGS__); \
7911 +#define AuIOErr1(fmt, ...) do { \
7912 + static unsigned char _c; \
7914 + AuIOErr(fmt, ##__VA_ARGS__); \
7917 +#define AuUnsupportMsg "This operation is not supported." \
7918 + " Please report this application to aufs-users ML."
7919 +#define AuUnsupport(fmt, ...) do { \
7920 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7924 +#define AuTraceErr(e) do { \
7925 + if (unlikely((e) < 0)) \
7926 + AuDbg("err %d\n", (int)(e)); \
7929 +#define AuTraceErrPtr(p) do { \
7931 + AuDbg("err %ld\n", PTR_ERR(p)); \
7934 +/* dirty macros for debug print, use with "%.*s" and caution */
7935 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7937 +/* ---------------------------------------------------------------------- */
7940 +#ifdef CONFIG_AUFS_DEBUG
7941 +extern struct mutex au_dbg_mtx;
7942 +extern char *au_plevel;
7944 +void au_dpri_whlist(struct au_nhash *whlist);
7946 +void au_dpri_vdir(struct au_vdir *vdir);
7948 +void au_dpri_inode(struct inode *inode);
7949 +void au_dpri_dalias(struct inode *inode);
7950 +void au_dpri_dentry(struct dentry *dentry);
7952 +void au_dpri_file(struct file *filp);
7953 +struct super_block;
7954 +void au_dpri_sb(struct super_block *sb);
7956 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7957 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7958 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7959 +void au_dbg_verify_kthread(void);
7961 +int __init au_debug_init(void);
7963 +#define AuDbgWhlist(w) do { \
7964 + mutex_lock(&au_dbg_mtx); \
7966 + au_dpri_whlist(w); \
7967 + mutex_unlock(&au_dbg_mtx); \
7970 +#define AuDbgVdir(v) do { \
7971 + mutex_lock(&au_dbg_mtx); \
7973 + au_dpri_vdir(v); \
7974 + mutex_unlock(&au_dbg_mtx); \
7977 +#define AuDbgInode(i) do { \
7978 + mutex_lock(&au_dbg_mtx); \
7980 + au_dpri_inode(i); \
7981 + mutex_unlock(&au_dbg_mtx); \
7984 +#define AuDbgDAlias(i) do { \
7985 + mutex_lock(&au_dbg_mtx); \
7987 + au_dpri_dalias(i); \
7988 + mutex_unlock(&au_dbg_mtx); \
7991 +#define AuDbgDentry(d) do { \
7992 + mutex_lock(&au_dbg_mtx); \
7994 + au_dpri_dentry(d); \
7995 + mutex_unlock(&au_dbg_mtx); \
7998 +#define AuDbgFile(f) do { \
7999 + mutex_lock(&au_dbg_mtx); \
8001 + au_dpri_file(f); \
8002 + mutex_unlock(&au_dbg_mtx); \
8005 +#define AuDbgSb(sb) do { \
8006 + mutex_lock(&au_dbg_mtx); \
8007 + AuDbg(#sb "\n"); \
8009 + mutex_unlock(&au_dbg_mtx); \
8012 +#define AuDbgSym(addr) do { \
8013 + char sym[KSYM_SYMBOL_LEN]; \
8014 + sprint_symbol(sym, (unsigned long)addr); \
8015 + AuDbg("%s\n", sym); \
8018 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8019 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8020 +AuStubVoid(au_dbg_verify_kthread, void)
8021 +AuStubInt0(__init au_debug_init, void)
8023 +#define AuDbgWhlist(w) do {} while (0)
8024 +#define AuDbgVdir(v) do {} while (0)
8025 +#define AuDbgInode(i) do {} while (0)
8026 +#define AuDbgDAlias(i) do {} while (0)
8027 +#define AuDbgDentry(d) do {} while (0)
8028 +#define AuDbgFile(f) do {} while (0)
8029 +#define AuDbgSb(sb) do {} while (0)
8030 +#define AuDbgSym(addr) do {} while (0)
8031 +#endif /* CONFIG_AUFS_DEBUG */
8033 +/* ---------------------------------------------------------------------- */
8035 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8036 +int __init au_sysrq_init(void);
8037 +void au_sysrq_fin(void);
8039 +#ifdef CONFIG_HW_CONSOLE
8040 +#define au_dbg_blocked() do { \
8042 + handle_sysrq('w'); \
8045 +AuStubVoid(au_dbg_blocked, void)
8049 +AuStubInt0(__init au_sysrq_init, void)
8050 +AuStubVoid(au_sysrq_fin, void)
8051 +AuStubVoid(au_dbg_blocked, void)
8052 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8054 +#endif /* __KERNEL__ */
8055 +#endif /* __AUFS_DEBUG_H__ */
8056 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8057 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8058 +++ linux/fs/aufs/dentry.c 2019-07-11 15:42:14.462237786 +0200
8060 +// SPDX-License-Identifier: GPL-2.0
8062 + * Copyright (C) 2005-2019 Junjiro R. Okajima
8064 + * This program, aufs is free software; you can redistribute it and/or modify
8065 + * it under the terms of the GNU General Public License as published by
8066 + * the Free Software Foundation; either version 2 of the License, or
8067 + * (at your option) any later version.
8069 + * This program is distributed in the hope that it will be useful,
8070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8072 + * GNU General Public License for more details.
8074 + * You should have received a copy of the GNU General Public License
8075 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8079 + * lookup and dentry operations
8082 +#include <linux/iversion.h>
8083 +#include <linux/namei.h>
8087 + * returns positive/negative dentry, NULL or an error.
8088 + * NULL means whiteout-ed or not-found.
8090 +static struct dentry*
8091 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8092 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8094 + struct dentry *h_dentry;
8095 + struct inode *h_inode;
8096 + struct au_branch *br;
8097 + int wh_found, opq;
8098 + unsigned char wh_able;
8099 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8100 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8104 + br = au_sbr(dentry->d_sb, bindex);
8105 + wh_able = !!au_br_whable(br->br_perm);
8107 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8108 + h_dentry = ERR_PTR(wh_found);
8111 + if (unlikely(wh_found < 0))
8114 + /* We found a whiteout */
8115 + /* au_set_dbbot(dentry, bindex); */
8116 + au_set_dbwh(dentry, bindex);
8118 + return NULL; /* success */
8122 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8124 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8125 + if (IS_ERR(h_dentry)) {
8126 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8132 + h_inode = d_inode(h_dentry);
8133 + if (d_is_negative(h_dentry)) {
8136 + } else if (wh_found
8137 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8139 + else if (au_ftest_lkup(args->flags, DIRREN)
8141 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8142 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8143 + (unsigned long long)h_inode->i_ino);
8147 + if (au_dbbot(dentry) <= bindex)
8148 + au_set_dbbot(dentry, bindex);
8149 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8150 + au_set_dbtop(dentry, bindex);
8151 + au_set_h_dptr(dentry, bindex, h_dentry);
8153 + if (!d_is_dir(h_dentry)
8155 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8156 + goto out; /* success */
8158 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8159 + opq = au_diropq_test(h_dentry);
8160 + inode_unlock_shared(h_inode);
8162 + au_set_dbdiropq(dentry, bindex);
8163 + else if (unlikely(opq < 0)) {
8164 + au_set_h_dptr(dentry, bindex, NULL);
8165 + h_dentry = ERR_PTR(opq);
8176 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8178 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8179 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8185 + * returns the number of lower positive dentries,
8186 + * otherwise an error.
8187 + * can be called at unlinking with @type is zero.
8189 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8190 + unsigned int flags)
8192 + int npositive, err;
8193 + aufs_bindex_t bindex, btail, bdiropq;
8194 + unsigned char isdir, dirperm1, dirren;
8195 + struct au_do_lookup_args args = {
8197 + .name = &dentry->d_name
8199 + struct dentry *parent;
8200 + struct super_block *sb;
8202 + sb = dentry->d_sb;
8203 + err = au_test_shwh(sb, args.name);
8204 + if (unlikely(err))
8207 + err = au_wh_name_alloc(&args.whname, args.name);
8208 + if (unlikely(err))
8211 + isdir = !!d_is_dir(dentry);
8212 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8213 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8215 + au_fset_lkup(args.flags, DIRREN);
8218 + parent = dget_parent(dentry);
8219 + btail = au_dbtaildir(parent);
8220 + for (bindex = btop; bindex <= btail; bindex++) {
8221 + struct dentry *h_parent, *h_dentry;
8222 + struct inode *h_inode, *h_dir;
8223 + struct au_branch *br;
8225 + h_dentry = au_h_dptr(dentry, bindex);
8227 + if (d_is_positive(h_dentry))
8231 + h_parent = au_h_dptr(parent, bindex);
8232 + if (!h_parent || !d_is_dir(h_parent))
8236 + /* if the inum matches, then use the prepared name */
8237 + err = au_dr_lkup_name(&args, bindex);
8238 + if (unlikely(err))
8242 + h_dir = d_inode(h_parent);
8243 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8244 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8245 + inode_unlock_shared(h_dir);
8246 + err = PTR_ERR(h_dentry);
8247 + if (IS_ERR(h_dentry))
8250 + au_fclr_lkup(args.flags, ALLOW_NEG);
8252 + au_fset_lkup(args.flags, IGNORE_PERM);
8254 + if (au_dbwh(dentry) == bindex)
8258 + if (d_is_negative(h_dentry))
8260 + h_inode = d_inode(h_dentry);
8263 + args.type = h_inode->i_mode & S_IFMT;
8264 + if (args.type != S_IFDIR)
8267 + /* the type of lower may be different */
8268 + bdiropq = au_dbdiropq(dentry);
8269 + if (bdiropq >= 0 && bdiropq <= bindex)
8272 + br = au_sbr(sb, bindex);
8274 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8275 + /*add_ent*/NULL)) {
8276 + /* prepare next name to lookup */
8277 + err = au_dr_lkup(&args, dentry, bindex);
8278 + if (unlikely(err))
8284 + AuLabel(positive);
8285 + au_update_dbtop(dentry);
8288 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8289 + && au_dbtop(dentry) < 0)) {
8291 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8297 + au_kfree_try_rcu(args.whname.name);
8299 + au_dr_lkup_fin(&args);
8304 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8306 + struct dentry *dentry;
8309 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8310 + dentry = vfsub_lkup_one(name, parent);
8312 + struct vfsub_lkup_one_args args = {
8318 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8319 + if (unlikely(wkq_err))
8320 + dentry = ERR_PTR(wkq_err);
8327 + * lookup @dentry on @bindex which should be negative.
8329 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8332 + struct dentry *parent, *h_parent, *h_dentry;
8333 + struct au_branch *br;
8335 + parent = dget_parent(dentry);
8336 + h_parent = au_h_dptr(parent, bindex);
8337 + br = au_sbr(dentry->d_sb, bindex);
8339 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8341 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8342 + err = PTR_ERR(h_dentry);
8343 + if (IS_ERR(h_dentry))
8345 + if (unlikely(d_is_positive(h_dentry))) {
8347 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8353 + if (bindex < au_dbtop(dentry))
8354 + au_set_dbtop(dentry, bindex);
8355 + if (au_dbbot(dentry) < bindex)
8356 + au_set_dbbot(dentry, bindex);
8357 + au_set_h_dptr(dentry, bindex, h_dentry);
8364 +/* ---------------------------------------------------------------------- */
8366 +/* subset of struct inode */
8368 + unsigned long i_ino;
8369 + /* unsigned int i_nlink; */
8375 + blkcnt_t i_blocks;
8380 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8382 + ia->i_ino = h_inode->i_ino;
8383 + /* ia->i_nlink = h_inode->i_nlink; */
8384 + ia->i_uid = h_inode->i_uid;
8385 + ia->i_gid = h_inode->i_gid;
8386 + ia->i_version = inode_query_iversion(h_inode);
8388 + ia->i_size = h_inode->i_size;
8389 + ia->i_blocks = h_inode->i_blocks;
8391 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8394 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8396 + return ia->i_ino != h_inode->i_ino
8397 + /* || ia->i_nlink != h_inode->i_nlink */
8398 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8399 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8400 + || !inode_eq_iversion(h_inode, ia->i_version)
8402 + || ia->i_size != h_inode->i_size
8403 + || ia->i_blocks != h_inode->i_blocks
8405 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8408 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8409 + struct au_branch *br)
8412 + struct au_iattr ia;
8413 + struct inode *h_inode;
8414 + struct dentry *h_d;
8415 + struct super_block *h_sb;
8418 + memset(&ia, -1, sizeof(ia));
8419 + h_sb = h_dentry->d_sb;
8421 + if (d_is_positive(h_dentry)) {
8422 + h_inode = d_inode(h_dentry);
8423 + au_iattr_save(&ia, h_inode);
8424 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8425 + /* nfs d_revalidate may return 0 for negative dentry */
8426 + /* fuse d_revalidate always return 0 for negative dentry */
8429 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8430 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8431 + err = PTR_ERR(h_d);
8436 + if (unlikely(h_d != h_dentry
8437 + || d_inode(h_d) != h_inode
8438 + || (h_inode && au_iattr_test(&ia, h_inode))))
8439 + err = au_busy_or_stale();
8447 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8448 + struct dentry *h_parent, struct au_branch *br)
8453 + if (udba == AuOpt_UDBA_REVAL
8454 + && !au_test_fs_remote(h_dentry->d_sb)) {
8456 + err = (d_inode(h_dentry->d_parent) != h_dir);
8457 + } else if (udba != AuOpt_UDBA_NONE)
8458 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8463 +/* ---------------------------------------------------------------------- */
8465 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8468 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8469 + struct au_hdentry tmp, *p, *q;
8470 + struct au_dinfo *dinfo;
8471 + struct super_block *sb;
8473 + DiMustWriteLock(dentry);
8475 + sb = dentry->d_sb;
8476 + dinfo = au_di(dentry);
8477 + bbot = dinfo->di_bbot;
8478 + bwh = dinfo->di_bwh;
8479 + bdiropq = dinfo->di_bdiropq;
8480 + bindex = dinfo->di_btop;
8481 + p = au_hdentry(dinfo, bindex);
8482 + for (; bindex <= bbot; bindex++, p++) {
8483 + if (!p->hd_dentry)
8486 + new_bindex = au_br_index(sb, p->hd_id);
8487 + if (new_bindex == bindex)
8490 + if (dinfo->di_bwh == bindex)
8492 + if (dinfo->di_bdiropq == bindex)
8493 + bdiropq = new_bindex;
8494 + if (new_bindex < 0) {
8496 + p->hd_dentry = NULL;
8500 + /* swap two lower dentries, and loop again */
8501 + q = au_hdentry(dinfo, new_bindex);
8505 + if (tmp.hd_dentry) {
8511 + dinfo->di_bwh = -1;
8512 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8513 + dinfo->di_bwh = bwh;
8515 + dinfo->di_bdiropq = -1;
8517 + && bdiropq <= au_sbbot(sb)
8518 + && au_sbr_whable(sb, bdiropq))
8519 + dinfo->di_bdiropq = bdiropq;
8522 + dinfo->di_btop = -1;
8523 + dinfo->di_bbot = -1;
8524 + bbot = au_dbbot(parent);
8526 + p = au_hdentry(dinfo, bindex);
8527 + for (; bindex <= bbot; bindex++, p++)
8528 + if (p->hd_dentry) {
8529 + dinfo->di_btop = bindex;
8533 + if (dinfo->di_btop >= 0) {
8535 + p = au_hdentry(dinfo, bindex);
8536 + for (; bindex >= 0; bindex--, p--)
8537 + if (p->hd_dentry) {
8538 + dinfo->di_bbot = bindex;
8547 +static void au_do_hide(struct dentry *dentry)
8549 + struct inode *inode;
8551 + if (d_really_is_positive(dentry)) {
8552 + inode = d_inode(dentry);
8553 + if (!d_is_dir(dentry)) {
8554 + if (inode->i_nlink && !d_unhashed(dentry))
8555 + drop_nlink(inode);
8557 + clear_nlink(inode);
8558 + /* stop next lookup */
8559 + inode->i_flags |= S_DEAD;
8561 + smp_mb(); /* necessary? */
8566 +static int au_hide_children(struct dentry *parent)
8568 + int err, i, j, ndentry;
8569 + struct au_dcsub_pages dpages;
8570 + struct au_dpage *dpage;
8571 + struct dentry *dentry;
8573 + err = au_dpages_init(&dpages, GFP_NOFS);
8574 + if (unlikely(err))
8576 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8577 + if (unlikely(err))
8580 + /* in reverse order */
8581 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8582 + dpage = dpages.dpages + i;
8583 + ndentry = dpage->ndentry;
8584 + for (j = ndentry - 1; j >= 0; j--) {
8585 + dentry = dpage->dentries[j];
8586 + if (dentry != parent)
8587 + au_do_hide(dentry);
8592 + au_dpages_free(&dpages);
8597 +static void au_hide(struct dentry *dentry)
8601 + AuDbgDentry(dentry);
8602 + if (d_is_dir(dentry)) {
8603 + /* shrink_dcache_parent(dentry); */
8604 + err = au_hide_children(dentry);
8605 + if (unlikely(err))
8606 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8609 + au_do_hide(dentry);
8613 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8615 + * a dirty branch is added
8616 + * - on the top of layers
8617 + * - in the middle of layers
8618 + * - to the bottom of layers
8620 + * on the added branch there exists
8623 + * - a same named entry
8625 + * * negative --> positive
8626 + * * positive --> positive
8627 + * - type is unchanged
8628 + * - type is changed
8630 + * * negative --> negative
8631 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8634 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8635 + struct au_dinfo *tmp)
8638 + aufs_bindex_t bindex, bbot;
8640 + struct dentry *dentry;
8641 + struct inode *inode;
8643 + } orig_h, tmp_h = {
8646 + struct au_hdentry *hd;
8647 + struct inode *inode, *h_inode;
8648 + struct dentry *h_dentry;
8651 + AuDebugOn(dinfo->di_btop < 0);
8653 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8654 + orig_h.inode = NULL;
8655 + if (d_is_positive(orig_h.dentry)) {
8656 + orig_h.inode = d_inode(orig_h.dentry);
8657 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8659 + if (tmp->di_btop >= 0) {
8660 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8661 + if (d_is_positive(tmp_h.dentry)) {
8662 + tmp_h.inode = d_inode(tmp_h.dentry);
8663 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8668 + if (d_really_is_positive(dentry))
8669 + inode = d_inode(dentry);
8670 + if (!orig_h.inode) {
8671 + AuDbg("negative originally\n");
8677 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8678 + AuDebugOn(dinfo->di_bdiropq != -1);
8680 + if (!tmp_h.inode) {
8681 + AuDbg("negative --> negative\n");
8682 + /* should have only one negative lower */
8683 + if (tmp->di_btop >= 0
8684 + && tmp->di_btop < dinfo->di_btop) {
8685 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8686 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8687 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8688 + au_di_cp(dinfo, tmp);
8689 + hd = au_hdentry(tmp, tmp->di_btop);
8690 + au_set_h_dptr(dentry, tmp->di_btop,
8691 + dget(hd->hd_dentry));
8693 + au_dbg_verify_dinode(dentry);
8695 + AuDbg("negative --> positive\n");
8697 + * similar to the behaviour of creating with bypassing
8699 + * unhash it in order to force an error in the
8700 + * succeeding create operation.
8701 + * we should not set S_DEAD here.
8704 + /* au_di_swap(tmp, dinfo); */
8705 + au_dbg_verify_dinode(dentry);
8708 + AuDbg("positive originally\n");
8709 + /* inode may be NULL */
8710 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8711 + if (!tmp_h.inode) {
8712 + AuDbg("positive --> negative\n");
8713 + /* or bypassing aufs */
8715 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8716 + dinfo->di_bwh = tmp->di_bwh;
8718 + err = au_refresh_hinode_self(inode);
8719 + au_dbg_verify_dinode(dentry);
8720 + } else if (orig_h.mode == tmp_h.mode) {
8721 + AuDbg("positive --> positive, same type\n");
8722 + if (!S_ISDIR(orig_h.mode)
8723 + && dinfo->di_btop > tmp->di_btop) {
8725 + * similar to the behaviour of removing and
8730 + err = au_refresh_hinode_self(inode);
8731 + au_dbg_verify_dinode(dentry);
8733 + /* fill empty slots */
8734 + if (dinfo->di_btop > tmp->di_btop)
8735 + dinfo->di_btop = tmp->di_btop;
8736 + if (dinfo->di_bbot < tmp->di_bbot)
8737 + dinfo->di_bbot = tmp->di_bbot;
8738 + dinfo->di_bwh = tmp->di_bwh;
8739 + dinfo->di_bdiropq = tmp->di_bdiropq;
8740 + bbot = dinfo->di_bbot;
8741 + bindex = tmp->di_btop;
8742 + hd = au_hdentry(tmp, bindex);
8743 + for (; bindex <= bbot; bindex++, hd++) {
8744 + if (au_h_dptr(dentry, bindex))
8746 + h_dentry = hd->hd_dentry;
8749 + AuDebugOn(d_is_negative(h_dentry));
8750 + h_inode = d_inode(h_dentry);
8751 + AuDebugOn(orig_h.mode
8752 + != (h_inode->i_mode
8754 + au_set_h_dptr(dentry, bindex,
8758 + err = au_refresh_hinode(inode, dentry);
8759 + au_dbg_verify_dinode(dentry);
8762 + AuDbg("positive --> positive, different type\n");
8763 + /* similar to the behaviour of removing and creating */
8766 + err = au_refresh_hinode_self(inode);
8767 + au_dbg_verify_dinode(dentry);
8775 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8777 + const struct dentry_operations *dop
8778 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8779 + static const unsigned int mask
8780 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8782 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8784 + if (dentry->d_op == dop)
8787 + AuDbg("%pd\n", dentry);
8788 + spin_lock(&dentry->d_lock);
8789 + if (dop == &aufs_dop)
8790 + dentry->d_flags |= mask;
8792 + dentry->d_flags &= ~mask;
8793 + dentry->d_op = dop;
8794 + spin_unlock(&dentry->d_lock);
8797 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8799 + int err, ebrange, nbr;
8800 + unsigned int sigen;
8801 + struct au_dinfo *dinfo, *tmp;
8802 + struct super_block *sb;
8803 + struct inode *inode;
8805 + DiMustWriteLock(dentry);
8806 + AuDebugOn(IS_ROOT(dentry));
8807 + AuDebugOn(d_really_is_negative(parent));
8809 + sb = dentry->d_sb;
8810 + sigen = au_sigen(sb);
8811 + err = au_digen_test(parent, sigen);
8812 + if (unlikely(err))
8815 + nbr = au_sbbot(sb) + 1;
8816 + dinfo = au_di(dentry);
8817 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8818 + if (unlikely(err))
8820 + ebrange = au_dbrange_test(dentry);
8822 + ebrange = au_do_refresh_hdentry(dentry, parent);
8824 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8825 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8826 + if (d_really_is_positive(dentry)) {
8827 + inode = d_inode(dentry);
8828 + err = au_refresh_hinode_self(inode);
8830 + au_dbg_verify_dinode(dentry);
8832 + goto out_dgen; /* success */
8836 + /* temporary dinfo */
8837 + AuDbgDentry(dentry);
8839 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8840 + if (unlikely(!tmp))
8842 + au_di_swap(tmp, dinfo);
8843 + /* returns the number of positive dentries */
8845 + * if current working dir is removed, it returns an error.
8846 + * but the dentry is legal.
8848 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8849 + AuDbgDentry(dentry);
8850 + au_di_swap(tmp, dinfo);
8851 + if (err == -ENOENT)
8854 + /* compare/refresh by dinfo */
8855 + AuDbgDentry(dentry);
8856 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8857 + au_dbg_verify_dinode(dentry);
8860 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8861 + au_rw_write_unlock(&tmp->di_rwsem);
8863 + if (unlikely(err))
8867 + au_update_digen(dentry);
8869 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8870 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8871 + AuDbgDentry(dentry);
8877 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8878 + struct dentry *dentry, aufs_bindex_t bindex)
8883 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8886 + AuDbg("b%d\n", bindex);
8888 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8889 + * due to whiteout and branch permission.
8891 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8892 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8893 + /* it may return tri-state */
8894 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8896 + if (unlikely(valid < 0))
8906 +/* todo: remove this */
8907 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8908 + unsigned int flags, int do_udba, int dirren)
8911 + umode_t mode, h_mode;
8912 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8913 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8914 + struct inode *h_inode, *h_cached_inode;
8915 + struct dentry *h_dentry;
8916 + struct qstr *name, *h_name;
8923 + unhashed = !!d_unhashed(dentry);
8924 + is_root = !!IS_ROOT(dentry);
8925 + name = &dentry->d_name;
8926 + tmpfile = au_di(dentry)->di_tmpfile;
8929 + * Theoretically, REVAL test should be unnecessary in case of
8931 + * But {fs,i}notify doesn't fire some necessary events,
8932 + * IN_ATTRIB for atime/nlink/pageio
8933 + * Let's do REVAL test too.
8935 + if (do_udba && inode) {
8936 + mode = (inode->i_mode & S_IFMT);
8937 + plus = (inode->i_nlink > 0);
8938 + ibs = au_ibtop(inode);
8939 + ibe = au_ibbot(inode);
8942 + btop = au_dbtop(dentry);
8944 + if (inode && S_ISDIR(inode->i_mode))
8945 + btail = au_dbtaildir(dentry);
8946 + for (bindex = btop; bindex <= btail; bindex++) {
8947 + h_dentry = au_h_dptr(dentry, bindex);
8951 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8952 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8953 + spin_lock(&h_dentry->d_lock);
8954 + h_name = &h_dentry->d_name;
8955 + if (unlikely(do_udba
8958 + && (unhashed != !!d_unhashed(h_dentry)
8959 + || (!tmpfile && !dirren
8960 + && !au_qstreq(name, h_name))
8963 + && !(flags & LOOKUP_OPEN)
8964 + && (h_dentry->d_flags
8965 + & DCACHE_NFSFS_RENAMED)))
8969 + h_unhashed = d_unhashed(h_dentry);
8970 + spin_unlock(&h_dentry->d_lock);
8971 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8972 + unhashed, h_unhashed, dentry, h_dentry);
8975 + spin_unlock(&h_dentry->d_lock);
8977 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8978 + if (unlikely(err))
8979 + /* do not goto err, to keep the errno */
8982 + /* todo: plink too? */
8987 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8991 + if (d_is_positive(h_dentry))
8992 + h_inode = d_inode(h_dentry);
8995 + h_cached_inode = h_inode;
8997 + h_mode = (h_inode->i_mode & S_IFMT);
8998 + h_plus = (h_inode->i_nlink > 0);
9000 + if (inode && ibs <= bindex && bindex <= ibe)
9001 + h_cached_inode = au_h_iptr(inode, bindex);
9004 + if (unlikely(plus != h_plus && !tmpfile))
9007 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9009 + && !IS_ROOT(h_dentry)
9010 + && unhashed != d_unhashed(h_dentry)))
9013 + if (unlikely(mode != h_mode
9014 + || h_cached_inode != h_inode))
9027 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9028 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9031 + struct dentry *parent;
9033 + if (!au_digen_test(dentry, sigen))
9036 + parent = dget_parent(dentry);
9037 + di_read_lock_parent(parent, AuLock_IR);
9038 + AuDebugOn(au_digen_test(parent, sigen));
9039 + au_dbg_verify_gen(parent, sigen);
9040 + err = au_refresh_dentry(dentry, parent);
9041 + di_read_unlock(parent, AuLock_IR);
9047 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9050 + struct dentry *d, *parent;
9052 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9053 + return simple_reval_dpath(dentry, sigen);
9055 + /* slow loop, keep it simple and stupid */
9056 + /* cf: au_cpup_dirs() */
9059 + while (au_digen_test(dentry, sigen)) {
9063 + parent = dget_parent(d);
9064 + if (!au_digen_test(parent, sigen))
9070 + di_write_lock_child2(d);
9072 + /* someone might update our dentry while we were sleeping */
9073 + if (au_digen_test(d, sigen)) {
9075 + * todo: consolidate with simple_reval_dpath(),
9076 + * do_refresh() and au_reval_for_attr().
9078 + di_read_lock_parent(parent, AuLock_IR);
9079 + err = au_refresh_dentry(d, parent);
9080 + di_read_unlock(parent, AuLock_IR);
9084 + di_write_unlock(d);
9086 + if (unlikely(err))
9094 + * if valid returns 1, otherwise 0.
9096 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9099 + unsigned int sigen;
9100 + unsigned char do_udba, dirren;
9101 + struct super_block *sb;
9102 + struct inode *inode;
9104 + /* todo: support rcu-walk? */
9105 + if (flags & LOOKUP_RCU)
9109 + if (unlikely(!au_di(dentry)))
9113 + sb = dentry->d_sb;
9116 + * i_mutex of parent dir may be held,
9117 + * but we should not return 'invalid' due to busy.
9119 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9120 + if (unlikely(err)) {
9126 + if (d_really_is_positive(dentry))
9127 + inode = d_inode(dentry);
9128 + if (unlikely(inode && au_is_bad_inode(inode))) {
9133 + if (unlikely(au_dbrange_test(dentry))) {
9139 + sigen = au_sigen(sb);
9140 + if (au_digen_test(dentry, sigen)) {
9141 + AuDebugOn(IS_ROOT(dentry));
9142 + err = au_reval_dpath(dentry, sigen);
9143 + if (unlikely(err)) {
9148 + di_downgrade_lock(dentry, AuLock_IR);
9151 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9153 + && !(inode->i_state && I_LINKABLE)
9154 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9159 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9160 + if (do_udba && inode) {
9161 + aufs_bindex_t btop = au_ibtop(inode);
9162 + struct inode *h_inode;
9165 + h_inode = au_h_iptr(inode, btop);
9166 + if (h_inode && au_test_higen(inode, h_inode)) {
9173 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9174 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9175 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9177 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9183 + di_downgrade_lock(dentry, AuLock_IR);
9185 + aufs_read_unlock(dentry, AuLock_IR);
9190 + AuDbg("%pd invalid, %d\n", dentry, valid);
9196 +static void aufs_d_release(struct dentry *dentry)
9198 + if (au_di(dentry)) {
9199 + au_di_fin(dentry);
9200 + au_hn_di_reinit(dentry);
9204 +const struct dentry_operations aufs_dop = {
9205 + .d_revalidate = aufs_d_revalidate,
9206 + .d_weak_revalidate = aufs_d_revalidate,
9207 + .d_release = aufs_d_release
9210 +/* aufs_dop without d_revalidate */
9211 +const struct dentry_operations aufs_dop_noreval = {
9212 + .d_release = aufs_d_release
9214 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9215 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9216 +++ linux/fs/aufs/dentry.h 2019-07-11 15:42:14.462237786 +0200
9218 +/* SPDX-License-Identifier: GPL-2.0 */
9220 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9222 + * This program, aufs is free software; you can redistribute it and/or modify
9223 + * it under the terms of the GNU General Public License as published by
9224 + * the Free Software Foundation; either version 2 of the License, or
9225 + * (at your option) any later version.
9227 + * This program is distributed in the hope that it will be useful,
9228 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9229 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9230 + * GNU General Public License for more details.
9232 + * You should have received a copy of the GNU General Public License
9233 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9237 + * lookup and dentry operations
9240 +#ifndef __AUFS_DENTRY_H__
9241 +#define __AUFS_DENTRY_H__
9245 +#include <linux/dcache.h>
9246 +#include "dirren.h"
9249 +struct au_hdentry {
9250 + struct dentry *hd_dentry;
9251 + aufs_bindex_t hd_id;
9255 + atomic_t di_generation;
9257 + struct au_rwsem di_rwsem;
9258 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9259 + unsigned char di_tmpfile; /* to allow the different name */
9260 + struct au_hdentry *di_hdentry;
9261 + struct rcu_head rcu;
9262 +} ____cacheline_aligned_in_smp;
9264 +/* ---------------------------------------------------------------------- */
9266 +/* flags for au_lkup_dentry() */
9267 +#define AuLkup_ALLOW_NEG 1
9268 +#define AuLkup_IGNORE_PERM (1 << 1)
9269 +#define AuLkup_DIRREN (1 << 2)
9270 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9271 +#define au_fset_lkup(flags, name) \
9272 + do { (flags) |= AuLkup_##name; } while (0)
9273 +#define au_fclr_lkup(flags, name) \
9274 + do { (flags) &= ~AuLkup_##name; } while (0)
9276 +#ifndef CONFIG_AUFS_DIRREN
9277 +#undef AuLkup_DIRREN
9278 +#define AuLkup_DIRREN 0
9281 +struct au_do_lookup_args {
9282 + unsigned int flags;
9284 + struct qstr whname, *name;
9285 + struct au_dr_lookup dirren;
9288 +/* ---------------------------------------------------------------------- */
9291 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9293 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9294 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9295 + struct dentry *h_parent, struct au_branch *br);
9297 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9298 + unsigned int flags);
9299 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9300 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9301 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9302 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9305 +void au_di_init_once(void *_di);
9306 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9307 +void au_di_free(struct au_dinfo *dinfo);
9308 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9309 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9310 +int au_di_init(struct dentry *dentry);
9311 +void au_di_fin(struct dentry *dentry);
9312 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9314 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9315 +void di_read_unlock(struct dentry *d, int flags);
9316 +void di_downgrade_lock(struct dentry *d, int flags);
9317 +void di_write_lock(struct dentry *d, unsigned int lsc);
9318 +void di_write_unlock(struct dentry *d);
9319 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9320 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9321 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9323 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9324 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9325 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9326 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9328 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9329 + struct dentry *h_dentry);
9330 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9331 +int au_dbrange_test(struct dentry *dentry);
9332 +void au_update_digen(struct dentry *dentry);
9333 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9334 +void au_update_dbtop(struct dentry *dentry);
9335 +void au_update_dbbot(struct dentry *dentry);
9336 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9338 +/* ---------------------------------------------------------------------- */
9340 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9342 + return dentry->d_fsdata;
9345 +/* ---------------------------------------------------------------------- */
9347 +/* lock subclass for dinfo */
9349 + AuLsc_DI_CHILD, /* child first */
9350 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9351 + AuLsc_DI_CHILD3, /* copyup dirs */
9355 + AuLsc_DI_TMP /* temp for replacing dinfo */
9359 + * di_read_lock_child, di_write_lock_child,
9360 + * di_read_lock_child2, di_write_lock_child2,
9361 + * di_read_lock_child3, di_write_lock_child3,
9362 + * di_read_lock_parent, di_write_lock_parent,
9363 + * di_read_lock_parent2, di_write_lock_parent2,
9364 + * di_read_lock_parent3, di_write_lock_parent3,
9366 +#define AuReadLockFunc(name, lsc) \
9367 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9368 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9370 +#define AuWriteLockFunc(name, lsc) \
9371 +static inline void di_write_lock_##name(struct dentry *d) \
9372 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9374 +#define AuRWLockFuncs(name, lsc) \
9375 + AuReadLockFunc(name, lsc) \
9376 + AuWriteLockFunc(name, lsc)
9378 +AuRWLockFuncs(child, CHILD);
9379 +AuRWLockFuncs(child2, CHILD2);
9380 +AuRWLockFuncs(child3, CHILD3);
9381 +AuRWLockFuncs(parent, PARENT);
9382 +AuRWLockFuncs(parent2, PARENT2);
9383 +AuRWLockFuncs(parent3, PARENT3);
9385 +#undef AuReadLockFunc
9386 +#undef AuWriteLockFunc
9387 +#undef AuRWLockFuncs
9389 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9390 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9391 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9393 +/* ---------------------------------------------------------------------- */
9395 +/* todo: memory barrier? */
9396 +static inline unsigned int au_digen(struct dentry *d)
9398 + return atomic_read(&au_di(d)->di_generation);
9401 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9403 + hdentry->hd_dentry = NULL;
9406 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9407 + aufs_bindex_t bindex)
9409 + return di->di_hdentry + bindex;
9412 +static inline void au_hdput(struct au_hdentry *hd)
9415 + dput(hd->hd_dentry);
9418 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9420 + DiMustAnyLock(dentry);
9421 + return au_di(dentry)->di_btop;
9424 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9426 + DiMustAnyLock(dentry);
9427 + return au_di(dentry)->di_bbot;
9430 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9432 + DiMustAnyLock(dentry);
9433 + return au_di(dentry)->di_bwh;
9436 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9438 + DiMustAnyLock(dentry);
9439 + return au_di(dentry)->di_bdiropq;
9442 +/* todo: hard/soft set? */
9443 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9445 + DiMustWriteLock(dentry);
9446 + au_di(dentry)->di_btop = bindex;
9449 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9451 + DiMustWriteLock(dentry);
9452 + au_di(dentry)->di_bbot = bindex;
9455 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9457 + DiMustWriteLock(dentry);
9458 + /* dbwh can be outside of btop - bbot range */
9459 + au_di(dentry)->di_bwh = bindex;
9462 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9464 + DiMustWriteLock(dentry);
9465 + au_di(dentry)->di_bdiropq = bindex;
9468 +/* ---------------------------------------------------------------------- */
9470 +#ifdef CONFIG_AUFS_HNOTIFY
9471 +static inline void au_digen_dec(struct dentry *d)
9473 + atomic_dec(&au_di(d)->di_generation);
9476 +static inline void au_hn_di_reinit(struct dentry *dentry)
9478 + dentry->d_fsdata = NULL;
9481 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9482 +#endif /* CONFIG_AUFS_HNOTIFY */
9484 +#endif /* __KERNEL__ */
9485 +#endif /* __AUFS_DENTRY_H__ */
9486 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9487 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9488 +++ linux/fs/aufs/dinfo.c 2019-07-11 15:42:14.462237786 +0200
9490 +// SPDX-License-Identifier: GPL-2.0
9492 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9494 + * This program, aufs is free software; you can redistribute it and/or modify
9495 + * it under the terms of the GNU General Public License as published by
9496 + * the Free Software Foundation; either version 2 of the License, or
9497 + * (at your option) any later version.
9499 + * This program is distributed in the hope that it will be useful,
9500 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9501 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9502 + * GNU General Public License for more details.
9504 + * You should have received a copy of the GNU General Public License
9505 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9509 + * dentry private data
9514 +void au_di_init_once(void *_dinfo)
9516 + struct au_dinfo *dinfo = _dinfo;
9518 + au_rw_init(&dinfo->di_rwsem);
9521 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9523 + struct au_dinfo *dinfo;
9526 + dinfo = au_cache_alloc_dinfo();
9527 + if (unlikely(!dinfo))
9530 + nbr = au_sbbot(sb) + 1;
9533 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9534 + if (dinfo->di_hdentry) {
9535 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9536 + dinfo->di_btop = -1;
9537 + dinfo->di_bbot = -1;
9538 + dinfo->di_bwh = -1;
9539 + dinfo->di_bdiropq = -1;
9540 + dinfo->di_tmpfile = 0;
9541 + for (i = 0; i < nbr; i++)
9542 + dinfo->di_hdentry[i].hd_id = -1;
9546 + au_cache_free_dinfo(dinfo);
9553 +void au_di_free(struct au_dinfo *dinfo)
9555 + struct au_hdentry *p;
9556 + aufs_bindex_t bbot, bindex;
9558 + /* dentry may not be revalidated */
9559 + bindex = dinfo->di_btop;
9560 + if (bindex >= 0) {
9561 + bbot = dinfo->di_bbot;
9562 + p = au_hdentry(dinfo, bindex);
9563 + while (bindex++ <= bbot)
9566 + au_kfree_try_rcu(dinfo->di_hdentry);
9567 + au_cache_free_dinfo(dinfo);
9570 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9572 + struct au_hdentry *p;
9575 + AuRwMustWriteLock(&a->di_rwsem);
9576 + AuRwMustWriteLock(&b->di_rwsem);
9578 +#define DiSwap(v, name) \
9580 + v = a->di_##name; \
9581 + a->di_##name = b->di_##name; \
9582 + b->di_##name = v; \
9585 + DiSwap(p, hdentry);
9589 + DiSwap(bi, bdiropq);
9595 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9597 + AuRwMustWriteLock(&dst->di_rwsem);
9598 + AuRwMustWriteLock(&src->di_rwsem);
9600 + dst->di_btop = src->di_btop;
9601 + dst->di_bbot = src->di_bbot;
9602 + dst->di_bwh = src->di_bwh;
9603 + dst->di_bdiropq = src->di_bdiropq;
9607 +int au_di_init(struct dentry *dentry)
9610 + struct super_block *sb;
9611 + struct au_dinfo *dinfo;
9614 + sb = dentry->d_sb;
9615 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9617 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9618 + /* smp_mb(); */ /* atomic_set */
9619 + dentry->d_fsdata = dinfo;
9626 +void au_di_fin(struct dentry *dentry)
9628 + struct au_dinfo *dinfo;
9630 + dinfo = au_di(dentry);
9631 + AuRwDestroy(&dinfo->di_rwsem);
9632 + au_di_free(dinfo);
9635 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9638 + struct au_hdentry *hdp;
9640 + AuRwMustWriteLock(&dinfo->di_rwsem);
9643 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9645 + sz = sizeof(*hdp);
9646 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9649 + dinfo->di_hdentry = hdp;
9656 +/* ---------------------------------------------------------------------- */
9658 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9661 + case AuLsc_DI_CHILD:
9662 + ii_write_lock_child(inode);
9664 + case AuLsc_DI_CHILD2:
9665 + ii_write_lock_child2(inode);
9667 + case AuLsc_DI_CHILD3:
9668 + ii_write_lock_child3(inode);
9670 + case AuLsc_DI_PARENT:
9671 + ii_write_lock_parent(inode);
9673 + case AuLsc_DI_PARENT2:
9674 + ii_write_lock_parent2(inode);
9676 + case AuLsc_DI_PARENT3:
9677 + ii_write_lock_parent3(inode);
9684 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9687 + case AuLsc_DI_CHILD:
9688 + ii_read_lock_child(inode);
9690 + case AuLsc_DI_CHILD2:
9691 + ii_read_lock_child2(inode);
9693 + case AuLsc_DI_CHILD3:
9694 + ii_read_lock_child3(inode);
9696 + case AuLsc_DI_PARENT:
9697 + ii_read_lock_parent(inode);
9699 + case AuLsc_DI_PARENT2:
9700 + ii_read_lock_parent2(inode);
9702 + case AuLsc_DI_PARENT3:
9703 + ii_read_lock_parent3(inode);
9710 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9712 + struct inode *inode;
9714 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9715 + if (d_really_is_positive(d)) {
9716 + inode = d_inode(d);
9717 + if (au_ftest_lock(flags, IW))
9718 + do_ii_write_lock(inode, lsc);
9719 + else if (au_ftest_lock(flags, IR))
9720 + do_ii_read_lock(inode, lsc);
9724 +void di_read_unlock(struct dentry *d, int flags)
9726 + struct inode *inode;
9728 + if (d_really_is_positive(d)) {
9729 + inode = d_inode(d);
9730 + if (au_ftest_lock(flags, IW)) {
9731 + au_dbg_verify_dinode(d);
9732 + ii_write_unlock(inode);
9733 + } else if (au_ftest_lock(flags, IR)) {
9734 + au_dbg_verify_dinode(d);
9735 + ii_read_unlock(inode);
9738 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9741 +void di_downgrade_lock(struct dentry *d, int flags)
9743 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9744 + ii_downgrade_lock(d_inode(d));
9745 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9748 +void di_write_lock(struct dentry *d, unsigned int lsc)
9750 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9751 + if (d_really_is_positive(d))
9752 + do_ii_write_lock(d_inode(d), lsc);
9755 +void di_write_unlock(struct dentry *d)
9757 + au_dbg_verify_dinode(d);
9758 + if (d_really_is_positive(d))
9759 + ii_write_unlock(d_inode(d));
9760 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9763 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9765 + AuDebugOn(d1 == d2
9766 + || d_inode(d1) == d_inode(d2)
9767 + || d1->d_sb != d2->d_sb);
9769 + if ((isdir && au_test_subdir(d1, d2))
9771 + di_write_lock_child(d1);
9772 + di_write_lock_child2(d2);
9774 + di_write_lock_child(d2);
9775 + di_write_lock_child2(d1);
9779 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9781 + AuDebugOn(d1 == d2
9782 + || d_inode(d1) == d_inode(d2)
9783 + || d1->d_sb != d2->d_sb);
9785 + if ((isdir && au_test_subdir(d1, d2))
9787 + di_write_lock_parent(d1);
9788 + di_write_lock_parent2(d2);
9790 + di_write_lock_parent(d2);
9791 + di_write_lock_parent2(d1);
9795 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9797 + di_write_unlock(d1);
9798 + if (d_inode(d1) == d_inode(d2))
9799 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9801 + di_write_unlock(d2);
9804 +/* ---------------------------------------------------------------------- */
9806 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9810 + DiMustAnyLock(dentry);
9812 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9814 + AuDebugOn(bindex < 0);
9815 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9816 + AuDebugOn(d && au_dcount(d) <= 0);
9821 + * extended version of au_h_dptr().
9822 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9825 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9827 + struct dentry *h_dentry;
9828 + struct inode *inode, *h_inode;
9830 + AuDebugOn(d_really_is_negative(dentry));
9833 + if (au_dbtop(dentry) <= bindex
9834 + && bindex <= au_dbbot(dentry))
9835 + h_dentry = au_h_dptr(dentry, bindex);
9836 + if (h_dentry && !au_d_linkable(h_dentry)) {
9838 + goto out; /* success */
9841 + inode = d_inode(dentry);
9842 + AuDebugOn(bindex < au_ibtop(inode));
9843 + AuDebugOn(au_ibbot(inode) < bindex);
9844 + h_inode = au_h_iptr(inode, bindex);
9845 + h_dentry = d_find_alias(h_inode);
9847 + if (!IS_ERR(h_dentry)) {
9848 + if (!au_d_linkable(h_dentry))
9849 + goto out; /* success */
9855 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9856 + h_dentry = au_plink_lkup(inode, bindex);
9857 + AuDebugOn(!h_dentry);
9858 + if (!IS_ERR(h_dentry)) {
9859 + if (!au_d_hashed_positive(h_dentry))
9860 + goto out; /* success */
9867 + AuDbgDentry(h_dentry);
9871 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9873 + aufs_bindex_t bbot, bwh;
9875 + bbot = au_dbbot(dentry);
9877 + bwh = au_dbwh(dentry);
9880 + if (0 < bwh && bwh < bbot)
9886 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9888 + aufs_bindex_t bbot, bopq;
9890 + bbot = au_dbtail(dentry);
9892 + bopq = au_dbdiropq(dentry);
9893 + if (0 <= bopq && bopq < bbot)
9899 +/* ---------------------------------------------------------------------- */
9901 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9902 + struct dentry *h_dentry)
9904 + struct au_dinfo *dinfo;
9905 + struct au_hdentry *hd;
9906 + struct au_branch *br;
9908 + DiMustWriteLock(dentry);
9910 + dinfo = au_di(dentry);
9911 + hd = au_hdentry(dinfo, bindex);
9913 + hd->hd_dentry = h_dentry;
9915 + br = au_sbr(dentry->d_sb, bindex);
9916 + hd->hd_id = br->br_id;
9920 +int au_dbrange_test(struct dentry *dentry)
9923 + aufs_bindex_t btop, bbot;
9926 + btop = au_dbtop(dentry);
9927 + bbot = au_dbbot(dentry);
9929 + AuDebugOn(bbot < 0 && btop > bbot);
9932 + AuDebugOn(bbot >= 0);
9938 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9943 + if (unlikely(au_digen(dentry) != sigen
9944 + || au_iigen_test(d_inode(dentry), sigen)))
9950 +void au_update_digen(struct dentry *dentry)
9952 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9953 + /* smp_mb(); */ /* atomic_set */
9956 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9958 + struct au_dinfo *dinfo;
9959 + struct dentry *h_d;
9960 + struct au_hdentry *hdp;
9961 + aufs_bindex_t bindex, bbot;
9963 + DiMustWriteLock(dentry);
9965 + dinfo = au_di(dentry);
9966 + if (!dinfo || dinfo->di_btop < 0)
9969 + if (do_put_zero) {
9970 + bbot = dinfo->di_bbot;
9971 + bindex = dinfo->di_btop;
9972 + hdp = au_hdentry(dinfo, bindex);
9973 + for (; bindex <= bbot; bindex++, hdp++) {
9974 + h_d = hdp->hd_dentry;
9975 + if (h_d && d_is_negative(h_d))
9976 + au_set_h_dptr(dentry, bindex, NULL);
9980 + dinfo->di_btop = 0;
9981 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9982 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9983 + if (hdp->hd_dentry)
9985 + if (dinfo->di_btop > dinfo->di_bbot) {
9986 + dinfo->di_btop = -1;
9987 + dinfo->di_bbot = -1;
9991 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9992 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9993 + if (hdp->hd_dentry)
9995 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9998 +void au_update_dbtop(struct dentry *dentry)
10000 + aufs_bindex_t bindex, bbot;
10001 + struct dentry *h_dentry;
10003 + bbot = au_dbbot(dentry);
10004 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10005 + h_dentry = au_h_dptr(dentry, bindex);
10008 + if (d_is_positive(h_dentry)) {
10009 + au_set_dbtop(dentry, bindex);
10012 + au_set_h_dptr(dentry, bindex, NULL);
10016 +void au_update_dbbot(struct dentry *dentry)
10018 + aufs_bindex_t bindex, btop;
10019 + struct dentry *h_dentry;
10021 + btop = au_dbtop(dentry);
10022 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10023 + h_dentry = au_h_dptr(dentry, bindex);
10026 + if (d_is_positive(h_dentry)) {
10027 + au_set_dbbot(dentry, bindex);
10030 + au_set_h_dptr(dentry, bindex, NULL);
10034 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10036 + aufs_bindex_t bindex, bbot;
10038 + bbot = au_dbbot(dentry);
10039 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10040 + if (au_h_dptr(dentry, bindex) == h_dentry)
10044 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10045 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10046 +++ linux/fs/aufs/dir.c 2019-07-11 15:42:14.462237786 +0200
10048 +// SPDX-License-Identifier: GPL-2.0
10050 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10052 + * This program, aufs is free software; you can redistribute it and/or modify
10053 + * it under the terms of the GNU General Public License as published by
10054 + * the Free Software Foundation; either version 2 of the License, or
10055 + * (at your option) any later version.
10057 + * This program is distributed in the hope that it will be useful,
10058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10060 + * GNU General Public License for more details.
10062 + * You should have received a copy of the GNU General Public License
10063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10067 + * directory operations
10070 +#include <linux/fs_stack.h>
10071 +#include <linux/iversion.h>
10074 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10076 + unsigned int nlink;
10078 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10080 + nlink = dir->i_nlink;
10081 + nlink += h_dir->i_nlink - 2;
10082 + if (h_dir->i_nlink < 2)
10084 + smp_mb(); /* for i_nlink */
10085 + /* 0 can happen in revaliding */
10086 + set_nlink(dir, nlink);
10089 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10091 + unsigned int nlink;
10093 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10095 + nlink = dir->i_nlink;
10096 + nlink -= h_dir->i_nlink - 2;
10097 + if (h_dir->i_nlink < 2)
10099 + smp_mb(); /* for i_nlink */
10100 + /* nlink == 0 means the branch-fs is broken */
10101 + set_nlink(dir, nlink);
10104 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10107 + aufs_bindex_t bindex, bbot;
10108 + struct file *h_file;
10109 + struct dentry *h_dentry;
10113 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10115 + bbot = au_fbbot_dir(file);
10116 + for (bindex = au_fbtop(file);
10117 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10119 + h_file = au_hf_dir(file, bindex);
10120 + if (h_file && file_inode(h_file))
10121 + sz += vfsub_f_size_read(h_file);
10124 + AuDebugOn(!dentry);
10125 + AuDebugOn(!d_is_dir(dentry));
10127 + bbot = au_dbtaildir(dentry);
10128 + for (bindex = au_dbtop(dentry);
10129 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10131 + h_dentry = au_h_dptr(dentry, bindex);
10132 + if (h_dentry && d_is_positive(h_dentry))
10133 + sz += i_size_read(d_inode(h_dentry));
10136 + if (sz < KMALLOC_MAX_SIZE)
10137 + sz = roundup_pow_of_two(sz);
10138 + if (sz > KMALLOC_MAX_SIZE)
10139 + sz = KMALLOC_MAX_SIZE;
10140 + else if (sz < NAME_MAX) {
10141 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10142 + sz = AUFS_RDBLK_DEF;
10147 +struct au_dir_ts_arg {
10148 + struct dentry *dentry;
10149 + aufs_bindex_t brid;
10152 +static void au_do_dir_ts(void *arg)
10154 + struct au_dir_ts_arg *a = arg;
10155 + struct au_dtime dt;
10156 + struct path h_path;
10157 + struct inode *dir, *h_dir;
10158 + struct super_block *sb;
10159 + struct au_branch *br;
10160 + struct au_hinode *hdir;
10162 + aufs_bindex_t btop, bindex;
10164 + sb = a->dentry->d_sb;
10165 + if (d_really_is_negative(a->dentry))
10167 + /* no dir->i_mutex lock */
10168 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10170 + dir = d_inode(a->dentry);
10171 + btop = au_ibtop(dir);
10172 + bindex = au_br_index(sb, a->brid);
10173 + if (bindex < btop)
10176 + br = au_sbr(sb, bindex);
10177 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10178 + if (!h_path.dentry)
10180 + h_path.mnt = au_br_mnt(br);
10181 + au_dtime_store(&dt, a->dentry, &h_path);
10183 + br = au_sbr(sb, btop);
10184 + if (!au_br_writable(br->br_perm))
10186 + h_path.dentry = au_h_dptr(a->dentry, btop);
10187 + h_path.mnt = au_br_mnt(br);
10188 + err = vfsub_mnt_want_write(h_path.mnt);
10191 + hdir = au_hi(dir, btop);
10192 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10193 + h_dir = au_h_iptr(dir, btop);
10194 + if (h_dir->i_nlink
10195 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10196 + dt.dt_h_path = h_path;
10197 + au_dtime_revert(&dt);
10199 + au_hn_inode_unlock(hdir);
10200 + vfsub_mnt_drop_write(h_path.mnt);
10201 + au_cpup_attr_timesizes(dir);
10204 + aufs_read_unlock(a->dentry, AuLock_DW);
10207 + au_nwt_done(&au_sbi(sb)->si_nowait);
10208 + au_kfree_try_rcu(arg);
10211 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10213 + int perm, wkq_err;
10214 + aufs_bindex_t btop;
10215 + struct au_dir_ts_arg *arg;
10216 + struct dentry *dentry;
10217 + struct super_block *sb;
10221 + dentry = d_find_any_alias(dir);
10222 + AuDebugOn(!dentry);
10223 + sb = dentry->d_sb;
10224 + btop = au_ibtop(dir);
10225 + if (btop == bindex) {
10226 + au_cpup_attr_timesizes(dir);
10230 + perm = au_sbr_perm(sb, btop);
10231 + if (!au_br_writable(perm))
10234 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10238 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10239 + arg->brid = au_sbr_id(sb, bindex);
10240 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10241 + if (unlikely(wkq_err)) {
10242 + pr_err("wkq %d\n", wkq_err);
10244 + au_kfree_try_rcu(arg);
10251 +/* ---------------------------------------------------------------------- */
10253 +static int reopen_dir(struct file *file)
10256 + unsigned int flags;
10257 + aufs_bindex_t bindex, btail, btop;
10258 + struct dentry *dentry, *h_dentry;
10259 + struct file *h_file;
10261 + /* open all lower dirs */
10262 + dentry = file->f_path.dentry;
10263 + btop = au_dbtop(dentry);
10264 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10265 + au_set_h_fptr(file, bindex, NULL);
10266 + au_set_fbtop(file, btop);
10268 + btail = au_dbtaildir(dentry);
10269 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10270 + au_set_h_fptr(file, bindex, NULL);
10271 + au_set_fbbot_dir(file, btail);
10273 + flags = vfsub_file_flags(file);
10274 + for (bindex = btop; bindex <= btail; bindex++) {
10275 + h_dentry = au_h_dptr(dentry, bindex);
10278 + h_file = au_hf_dir(file, bindex);
10282 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10283 + err = PTR_ERR(h_file);
10284 + if (IS_ERR(h_file))
10285 + goto out; /* close all? */
10286 + au_set_h_fptr(file, bindex, h_file);
10288 + au_update_figen(file);
10289 + /* todo: necessary? */
10290 + /* file->f_ra = h_file->f_ra; */
10297 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10300 + aufs_bindex_t bindex, btail;
10301 + struct dentry *dentry, *h_dentry;
10302 + struct vfsmount *mnt;
10304 + FiMustWriteLock(file);
10305 + AuDebugOn(h_file);
10308 + mnt = file->f_path.mnt;
10309 + dentry = file->f_path.dentry;
10310 + file->f_version = inode_query_iversion(d_inode(dentry));
10311 + bindex = au_dbtop(dentry);
10312 + au_set_fbtop(file, bindex);
10313 + btail = au_dbtaildir(dentry);
10314 + au_set_fbbot_dir(file, btail);
10315 + for (; !err && bindex <= btail; bindex++) {
10316 + h_dentry = au_h_dptr(dentry, bindex);
10320 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10321 + if (unlikely(err))
10323 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10324 + if (IS_ERR(h_file)) {
10325 + err = PTR_ERR(h_file);
10328 + au_set_h_fptr(file, bindex, h_file);
10330 + au_update_figen(file);
10331 + /* todo: necessary? */
10332 + /* file->f_ra = h_file->f_ra; */
10334 + return 0; /* success */
10337 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10338 + au_set_h_fptr(file, bindex, NULL);
10339 + au_set_fbtop(file, -1);
10340 + au_set_fbbot_dir(file, -1);
10345 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10346 + struct file *file)
10349 + struct super_block *sb;
10350 + struct au_fidir *fidir;
10353 + sb = file->f_path.dentry->d_sb;
10354 + si_read_lock(sb, AuLock_FLUSH);
10355 + fidir = au_fidir_alloc(sb);
10357 + struct au_do_open_args args = {
10358 + .open = do_open_dir,
10361 + err = au_do_open(file, &args);
10362 + if (unlikely(err))
10363 + au_kfree_rcu(fidir);
10365 + si_read_unlock(sb);
10369 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10370 + struct file *file)
10372 + struct au_vdir *vdir_cache;
10373 + struct au_finfo *finfo;
10374 + struct au_fidir *fidir;
10375 + struct au_hfile *hf;
10376 + aufs_bindex_t bindex, bbot;
10378 + finfo = au_fi(file);
10379 + fidir = finfo->fi_hdir;
10381 + au_hbl_del(&finfo->fi_hlist,
10382 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10383 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10385 + au_vdir_free(vdir_cache);
10387 + bindex = finfo->fi_btop;
10388 + if (bindex >= 0) {
10389 + hf = fidir->fd_hfile + bindex;
10391 + * calls fput() instead of filp_close(),
10392 + * since no dnotify or lock for the lower file.
10394 + bbot = fidir->fd_bbot;
10395 + for (; bindex <= bbot; bindex++, hf++)
10397 + au_hfput(hf, /*execed*/0);
10399 + au_kfree_rcu(fidir);
10400 + finfo->fi_hdir = NULL;
10402 + au_finfo_fin(file);
10406 +/* ---------------------------------------------------------------------- */
10408 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10411 + aufs_bindex_t bindex, bbot;
10412 + struct file *h_file;
10415 + bbot = au_fbbot_dir(file);
10416 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10417 + h_file = au_hf_dir(file, bindex);
10419 + err = vfsub_flush(h_file, id);
10424 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10426 + return au_do_flush(file, id, au_do_flush_dir);
10429 +/* ---------------------------------------------------------------------- */
10431 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10434 + aufs_bindex_t bbot, bindex;
10435 + struct inode *inode;
10436 + struct super_block *sb;
10439 + sb = dentry->d_sb;
10440 + inode = d_inode(dentry);
10441 + IMustLock(inode);
10442 + bbot = au_dbbot(dentry);
10443 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10444 + struct path h_path;
10446 + if (au_test_ro(sb, bindex, inode))
10448 + h_path.dentry = au_h_dptr(dentry, bindex);
10449 + if (!h_path.dentry)
10452 + h_path.mnt = au_sbr_mnt(sb, bindex);
10453 + err = vfsub_fsync(NULL, &h_path, datasync);
10459 +static int au_do_fsync_dir(struct file *file, int datasync)
10462 + aufs_bindex_t bbot, bindex;
10463 + struct file *h_file;
10464 + struct super_block *sb;
10465 + struct inode *inode;
10467 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10468 + if (unlikely(err))
10471 + inode = file_inode(file);
10472 + sb = inode->i_sb;
10473 + bbot = au_fbbot_dir(file);
10474 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10475 + h_file = au_hf_dir(file, bindex);
10476 + if (!h_file || au_test_ro(sb, bindex, inode))
10479 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10487 + * @file may be NULL
10489 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10493 + struct dentry *dentry;
10494 + struct inode *inode;
10495 + struct super_block *sb;
10498 + dentry = file->f_path.dentry;
10499 + inode = d_inode(dentry);
10500 + inode_lock(inode);
10501 + sb = dentry->d_sb;
10502 + si_noflush_read_lock(sb);
10504 + err = au_do_fsync_dir(file, datasync);
10506 + di_write_lock_child(dentry);
10507 + err = au_do_fsync_dir_no_file(dentry, datasync);
10509 + au_cpup_attr_timesizes(inode);
10510 + di_write_unlock(dentry);
10512 + fi_write_unlock(file);
10514 + si_read_unlock(sb);
10515 + inode_unlock(inode);
10519 +/* ---------------------------------------------------------------------- */
10521 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10524 + struct dentry *dentry;
10525 + struct inode *inode, *h_inode;
10526 + struct super_block *sb;
10528 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10530 + dentry = file->f_path.dentry;
10531 + inode = d_inode(dentry);
10532 + IMustLock(inode);
10534 + sb = dentry->d_sb;
10535 + si_read_lock(sb, AuLock_FLUSH);
10536 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10537 + if (unlikely(err))
10539 + err = au_alive_dir(dentry);
10541 + err = au_vdir_init(file);
10542 + di_downgrade_lock(dentry, AuLock_IR);
10543 + if (unlikely(err))
10546 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10547 + if (!au_test_nfsd()) {
10548 + err = au_vdir_fill_de(file, ctx);
10549 + fsstack_copy_attr_atime(inode, h_inode);
10552 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10553 + * encode_fh() and others.
10555 + atomic_inc(&h_inode->i_count);
10556 + di_read_unlock(dentry, AuLock_IR);
10557 + si_read_unlock(sb);
10558 + err = au_vdir_fill_de(file, ctx);
10559 + fsstack_copy_attr_atime(inode, h_inode);
10560 + fi_write_unlock(file);
10568 + di_read_unlock(dentry, AuLock_IR);
10569 + fi_write_unlock(file);
10571 + si_read_unlock(sb);
10575 +/* ---------------------------------------------------------------------- */
10577 +#define AuTestEmpty_WHONLY 1
10578 +#define AuTestEmpty_CALLED (1 << 1)
10579 +#define AuTestEmpty_SHWH (1 << 2)
10580 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10581 +#define au_fset_testempty(flags, name) \
10582 + do { (flags) |= AuTestEmpty_##name; } while (0)
10583 +#define au_fclr_testempty(flags, name) \
10584 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10586 +#ifndef CONFIG_AUFS_SHWH
10587 +#undef AuTestEmpty_SHWH
10588 +#define AuTestEmpty_SHWH 0
10591 +struct test_empty_arg {
10592 + struct dir_context ctx;
10593 + struct au_nhash *whlist;
10594 + unsigned int flags;
10596 + aufs_bindex_t bindex;
10599 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10600 + int namelen, loff_t offset __maybe_unused, u64 ino,
10601 + unsigned int d_type)
10603 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10605 + char *name = (void *)__name;
10608 + au_fset_testempty(arg->flags, CALLED);
10610 + if (name[0] == '.'
10611 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10612 + goto out; /* success */
10614 + if (namelen <= AUFS_WH_PFX_LEN
10615 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10616 + if (au_ftest_testempty(arg->flags, WHONLY)
10617 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10618 + arg->err = -ENOTEMPTY;
10622 + name += AUFS_WH_PFX_LEN;
10623 + namelen -= AUFS_WH_PFX_LEN;
10624 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10625 + arg->err = au_nhash_append_wh
10626 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10627 + au_ftest_testempty(arg->flags, SHWH));
10631 + AuTraceErr(arg->err);
10635 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10638 + struct file *h_file;
10639 + struct au_branch *br;
10641 + h_file = au_h_open(dentry, arg->bindex,
10642 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10643 + /*file*/NULL, /*force_wr*/0);
10644 + err = PTR_ERR(h_file);
10645 + if (IS_ERR(h_file))
10649 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10650 + && !file_inode(h_file)->i_nlink)
10655 + au_fclr_testempty(arg->flags, CALLED);
10657 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10660 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10664 + br = au_sbr(dentry->d_sb, arg->bindex);
10665 + au_lcnt_dec(&br->br_nfiles);
10670 +struct do_test_empty_args {
10672 + struct dentry *dentry;
10673 + struct test_empty_arg *arg;
10676 +static void call_do_test_empty(void *args)
10678 + struct do_test_empty_args *a = args;
10679 + *a->errp = do_test_empty(a->dentry, a->arg);
10682 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10684 + int err, wkq_err;
10685 + struct dentry *h_dentry;
10686 + struct inode *h_inode;
10688 + h_dentry = au_h_dptr(dentry, arg->bindex);
10689 + h_inode = d_inode(h_dentry);
10690 + /* todo: i_mode changes anytime? */
10691 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10692 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10693 + inode_unlock_shared(h_inode);
10695 + err = do_test_empty(dentry, arg);
10697 + struct do_test_empty_args args = {
10699 + .dentry = dentry,
10702 + unsigned int flags = arg->flags;
10704 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10705 + if (unlikely(wkq_err))
10707 + arg->flags = flags;
10713 +int au_test_empty_lower(struct dentry *dentry)
10716 + unsigned int rdhash;
10717 + aufs_bindex_t bindex, btop, btail;
10718 + struct au_nhash whlist;
10719 + struct test_empty_arg arg = {
10721 + .actor = test_empty_cb
10724 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10726 + SiMustAnyLock(dentry->d_sb);
10728 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10730 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10731 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10732 + if (unlikely(err))
10736 + arg.whlist = &whlist;
10737 + btop = au_dbtop(dentry);
10738 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10739 + au_fset_testempty(arg.flags, SHWH);
10740 + test_empty = do_test_empty;
10741 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10742 + test_empty = sio_test_empty;
10743 + arg.bindex = btop;
10744 + err = test_empty(dentry, &arg);
10745 + if (unlikely(err))
10748 + au_fset_testempty(arg.flags, WHONLY);
10749 + btail = au_dbtaildir(dentry);
10750 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10751 + struct dentry *h_dentry;
10753 + h_dentry = au_h_dptr(dentry, bindex);
10754 + if (h_dentry && d_is_positive(h_dentry)) {
10755 + arg.bindex = bindex;
10756 + err = test_empty(dentry, &arg);
10761 + au_nhash_wh_free(&whlist);
10766 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10769 + struct test_empty_arg arg = {
10771 + .actor = test_empty_cb
10774 + aufs_bindex_t bindex, btail;
10777 + arg.whlist = whlist;
10778 + arg.flags = AuTestEmpty_WHONLY;
10779 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10780 + au_fset_testempty(arg.flags, SHWH);
10781 + btail = au_dbtaildir(dentry);
10782 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10783 + struct dentry *h_dentry;
10785 + h_dentry = au_h_dptr(dentry, bindex);
10786 + if (h_dentry && d_is_positive(h_dentry)) {
10787 + arg.bindex = bindex;
10788 + err = sio_test_empty(dentry, &arg);
10795 +/* ---------------------------------------------------------------------- */
10797 +const struct file_operations aufs_dir_fop = {
10798 + .owner = THIS_MODULE,
10799 + .llseek = default_llseek,
10800 + .read = generic_read_dir,
10801 + .iterate_shared = aufs_iterate_shared,
10802 + .unlocked_ioctl = aufs_ioctl_dir,
10803 +#ifdef CONFIG_COMPAT
10804 + .compat_ioctl = aufs_compat_ioctl_dir,
10806 + .open = aufs_open_dir,
10807 + .release = aufs_release_dir,
10808 + .flush = aufs_flush_dir,
10809 + .fsync = aufs_fsync_dir
10811 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10812 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10813 +++ linux/fs/aufs/dir.h 2019-07-11 15:42:14.462237786 +0200
10815 +/* SPDX-License-Identifier: GPL-2.0 */
10817 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10819 + * This program, aufs is free software; you can redistribute it and/or modify
10820 + * it under the terms of the GNU General Public License as published by
10821 + * the Free Software Foundation; either version 2 of the License, or
10822 + * (at your option) any later version.
10824 + * This program is distributed in the hope that it will be useful,
10825 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10826 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10827 + * GNU General Public License for more details.
10829 + * You should have received a copy of the GNU General Public License
10830 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10834 + * directory operations
10837 +#ifndef __AUFS_DIR_H__
10838 +#define __AUFS_DIR_H__
10842 +#include <linux/fs.h>
10844 +/* ---------------------------------------------------------------------- */
10846 +/* need to be faster and smaller */
10849 + unsigned int nh_num;
10850 + struct hlist_head *nh_head;
10853 +struct au_vdir_destr {
10854 + unsigned char len;
10855 + unsigned char name[0];
10858 +struct au_vdir_dehstr {
10859 + struct hlist_node hash;
10860 + struct au_vdir_destr *str;
10861 + struct rcu_head rcu;
10862 +} ____cacheline_aligned_in_smp;
10864 +struct au_vdir_de {
10866 + unsigned char de_type;
10867 + /* caution: packed */
10868 + struct au_vdir_destr de_str;
10871 +struct au_vdir_wh {
10872 + struct hlist_node wh_hash;
10873 +#ifdef CONFIG_AUFS_SHWH
10875 + aufs_bindex_t wh_bindex;
10876 + unsigned char wh_type;
10878 + aufs_bindex_t wh_bindex;
10880 + /* caution: packed */
10881 + struct au_vdir_destr wh_str;
10884 +union au_vdir_deblk_p {
10885 + unsigned char *deblk;
10886 + struct au_vdir_de *de;
10890 + unsigned char **vd_deblk;
10891 + unsigned long vd_nblk;
10893 + unsigned long ul;
10894 + union au_vdir_deblk_p p;
10898 + unsigned int vd_deblk_sz;
10899 + unsigned long vd_jiffy;
10900 + struct rcu_head rcu;
10901 +} ____cacheline_aligned_in_smp;
10903 +/* ---------------------------------------------------------------------- */
10906 +extern const struct file_operations aufs_dir_fop;
10907 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10908 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10909 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10910 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10911 +int au_test_empty_lower(struct dentry *dentry);
10912 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10915 +unsigned int au_rdhash_est(loff_t sz);
10916 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10917 +void au_nhash_wh_free(struct au_nhash *whlist);
10918 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10920 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10921 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10922 + unsigned int d_type, aufs_bindex_t bindex,
10923 + unsigned char shwh);
10924 +void au_vdir_free(struct au_vdir *vdir);
10925 +int au_vdir_init(struct file *file);
10926 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10929 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10931 +#ifdef CONFIG_AUFS_RDU
10933 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10934 +#ifdef CONFIG_COMPAT
10935 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10936 + unsigned long arg);
10939 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10940 + unsigned int cmd, unsigned long arg)
10941 +#ifdef CONFIG_COMPAT
10942 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10943 + unsigned int cmd, unsigned long arg)
10947 +#endif /* __KERNEL__ */
10948 +#endif /* __AUFS_DIR_H__ */
10949 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10950 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10951 +++ linux/fs/aufs/dirren.c 2019-07-11 15:42:14.462237786 +0200
10953 +// SPDX-License-Identifier: GPL-2.0
10955 + * Copyright (C) 2017-2019 Junjiro R. Okajima
10957 + * This program, aufs is free software; you can redistribute it and/or modify
10958 + * it under the terms of the GNU General Public License as published by
10959 + * the Free Software Foundation; either version 2 of the License, or
10960 + * (at your option) any later version.
10962 + * This program is distributed in the hope that it will be useful,
10963 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10964 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10965 + * GNU General Public License for more details.
10967 + * You should have received a copy of the GNU General Public License
10968 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10972 + * special handling in renaming a directory
10973 + * in order to support looking-up the before-renamed name on the lower readonly
10977 +#include <linux/byteorder/generic.h>
10980 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10984 + idx = au_dr_ihash(ent->dr_h_ino);
10985 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10988 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10991 + struct hlist_bl_head *hbl;
10994 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10995 + hbl = dr->dr_h_ino + i;
10996 + hlist_bl_lock(hbl);
10997 + ret &= hlist_bl_empty(hbl);
10998 + hlist_bl_unlock(hbl);
11004 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11006 + struct au_dr_hino *found, *ent;
11007 + struct hlist_bl_head *hbl;
11008 + struct hlist_bl_node *pos;
11012 + idx = au_dr_ihash(ino);
11013 + hbl = dr->dr_h_ino + idx;
11014 + hlist_bl_lock(hbl);
11015 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11016 + if (ent->dr_h_ino == ino) {
11020 + hlist_bl_unlock(hbl);
11025 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11026 + struct au_dr_hino *add_ent)
11029 + struct hlist_bl_head *hbl;
11030 + struct hlist_bl_node *pos;
11031 + struct au_dr_hino *ent;
11034 + idx = au_dr_ihash(ino);
11035 + hbl = dr->dr_h_ino + idx;
11038 + struct hlist_bl_node *tmp;
11040 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11041 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11044 + hlist_bl_lock(hbl);
11045 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11046 + if (ent->dr_h_ino == ino) {
11050 + if (!found && add_ent)
11051 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11052 + hlist_bl_unlock(hbl);
11054 + if (!found && add_ent)
11055 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11060 +void au_dr_hino_free(struct au_dr_br *dr)
11063 + struct hlist_bl_head *hbl;
11064 + struct hlist_bl_node *pos, *tmp;
11065 + struct au_dr_hino *ent;
11067 + /* SiMustWriteLock(sb); */
11069 + for (i = 0; i < AuDirren_NHASH; i++) {
11070 + hbl = dr->dr_h_ino + i;
11071 + /* no spinlock since sbinfo must be write-locked */
11072 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11073 + au_kfree_rcu(ent);
11074 + INIT_HLIST_BL_HEAD(hbl);
11078 +/* returns the number of inodes or an error */
11079 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11080 + struct file *hinofile)
11084 + loff_t pos, oldsize;
11086 + struct inode *hinoinode;
11087 + struct hlist_bl_head *hbl;
11088 + struct hlist_bl_node *n1, *n2;
11089 + struct au_dr_hino *ent;
11091 + SiMustWriteLock(sb);
11092 + AuDebugOn(!au_br_writable(br->br_perm));
11094 + hinoinode = file_inode(hinofile);
11095 + oldsize = i_size_read(hinoinode);
11099 + hbl = br->br_dirren.dr_h_ino;
11100 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11101 + /* no bit-lock since sbinfo must be write-locked */
11102 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11103 + AuDbg("hi%llu, %pD2\n",
11104 + (unsigned long long)ent->dr_h_ino, hinofile);
11105 + u64 = cpu_to_be64(ent->dr_h_ino);
11106 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11107 + if (ssz == sizeof(u64))
11110 + /* write error */
11111 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11118 + /* regardless the error */
11119 + if (pos < oldsize) {
11120 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11128 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11135 + struct au_dr_hino *ent;
11136 + struct inode *hinoinode;
11137 + struct hlist_bl_head *hbl;
11141 + hbl = dr->dr_h_ino;
11142 + hinoinode = file_inode(hinofile);
11143 + sz = i_size_read(hinoinode);
11144 + AuDebugOn(sz % sizeof(u64));
11145 + n = sz / sizeof(u64);
11147 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11148 + if (unlikely(ssz != sizeof(u64))) {
11149 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11156 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11162 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11163 + AuDbg("hi%llu, %pD2\n",
11164 + (unsigned long long)ent->dr_h_ino, hinofile);
11165 + hidx = au_dr_ihash(ent->dr_h_ino);
11166 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11168 + goto out; /* success */
11171 + au_dr_hino_free(dr);
11178 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11179 + * @path is a switch to distinguish load and store.
11181 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11182 + struct au_branch *br, const struct path *path)
11185 + unsigned char load, suspend;
11186 + struct file *hinofile;
11187 + struct au_hinode *hdir;
11188 + struct inode *dir, *delegated;
11189 + struct path hinopath;
11190 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11191 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11193 + AuDebugOn(bindex < 0 && !br);
11194 + AuDebugOn(bindex >= 0 && br);
11199 + br = au_sbr(sb, bindex);
11202 + path = &br->br_path;
11203 + AuDebugOn(!au_br_writable(br->br_perm));
11204 + if (unlikely(!au_br_writable(br->br_perm)))
11210 + dir = d_inode(sb->s_root);
11211 + hdir = au_hinode(au_ii(dir), bindex);
11212 + dir = hdir->hi_inode;
11213 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11215 + dir = d_inode(path->dentry);
11216 + inode_lock_nested(dir, AuLsc_I_CHILD);
11218 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11219 + err = PTR_ERR(hinopath.dentry);
11220 + if (IS_ERR(hinopath.dentry))
11224 + flags = O_RDONLY;
11226 + if (d_is_negative(hinopath.dentry))
11227 + goto out_dput; /* success */
11229 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11230 + if (d_is_positive(hinopath.dentry)) {
11231 + delegated = NULL;
11232 + err = vfsub_unlink(dir, &hinopath, &delegated,
11235 + if (unlikely(err))
11236 + pr_err("ignored err %d, %pd2\n",
11237 + err, hinopath.dentry);
11238 + if (unlikely(err == -EWOULDBLOCK))
11243 + } else if (!d_is_positive(hinopath.dentry)) {
11244 + err = vfsub_create(dir, &hinopath, 0600,
11245 + /*want_excl*/false);
11247 + if (unlikely(err))
11250 + flags = O_WRONLY;
11252 + hinopath.mnt = path->mnt;
11253 + hinofile = vfsub_dentry_open(&hinopath, flags);
11255 + au_hn_inode_unlock(hdir);
11257 + inode_unlock(dir);
11258 + dput(hinopath.dentry);
11259 + AuTraceErrPtr(hinofile);
11260 + if (IS_ERR(hinofile)) {
11261 + err = PTR_ERR(hinofile);
11266 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11268 + err = au_dr_hino_store(sb, br, hinofile);
11273 + dput(hinopath.dentry);
11276 + au_hn_inode_unlock(hdir);
11278 + inode_unlock(dir);
11284 +/* ---------------------------------------------------------------------- */
11286 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11289 + struct kstatfs kstfs;
11291 + struct dentry *dentry;
11292 + struct super_block *sb;
11294 + err = vfs_statfs((void *)path, &kstfs);
11296 + if (unlikely(err))
11299 + /* todo: support for UUID */
11301 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11302 + brid->type = AuBrid_FSID;
11303 + brid->fsid = kstfs.f_fsid;
11305 + dentry = path->dentry;
11306 + sb = dentry->d_sb;
11309 + brid->type = AuBrid_DEV;
11318 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11319 + const struct path *path)
11322 + struct au_dr_br *dr;
11323 + struct hlist_bl_head *hbl;
11325 + dr = &br->br_dirren;
11326 + hbl = dr->dr_h_ino;
11327 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11328 + INIT_HLIST_BL_HEAD(hbl);
11330 + err = au_dr_brid_init(&dr->dr_brid, path);
11331 + if (unlikely(err))
11334 + if (au_opt_test(au_mntflags(sb), DIRREN))
11335 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11342 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11347 + if (au_br_writable(br->br_perm))
11348 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11350 + au_dr_hino_free(&br->br_dirren);
11355 +/* ---------------------------------------------------------------------- */
11357 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11358 + char *buf, size_t sz)
11361 + unsigned int major, minor;
11365 + err = snprintf(p, sz, "%d_", brid->type);
11366 + AuDebugOn(err > sz);
11369 + switch (brid->type) {
11370 + case AuBrid_Unset:
11372 + case AuBrid_UUID:
11373 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11375 + case AuBrid_FSID:
11376 + err = snprintf(p, sz, "%08x-%08x",
11377 + brid->fsid.val[0], brid->fsid.val[1]);
11380 + major = MAJOR(brid->dev);
11381 + minor = MINOR(brid->dev);
11382 + if (major <= 0xff && minor <= 0xff)
11383 + err = snprintf(p, sz, "%02x%02x", major, minor);
11385 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11388 + AuDebugOn(err > sz);
11391 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11392 + AuDebugOn(err > sz);
11399 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11402 + struct dentry *br_dentry;
11403 + struct inode *br_inode;
11405 + br_dentry = au_br_dentry(br);
11406 + br_inode = d_inode(br_dentry);
11407 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11408 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11409 + AuDebugOn(rlen > len);
11414 +/* ---------------------------------------------------------------------- */
11417 + * from the given @h_dentry, construct drinfo at @*fdata.
11418 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11421 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11422 + struct dentry *h_dentry,
11423 + unsigned char *allocated)
11426 + struct au_drinfo_fdata *f, *p;
11427 + struct au_drinfo *drinfo;
11428 + struct inode *h_inode;
11429 + struct qstr *qname;
11433 + h_inode = d_inode(h_dentry);
11434 + qname = &h_dentry->d_name;
11435 + drinfo = &f->drinfo;
11436 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11437 + drinfo->oldnamelen = qname->len;
11438 + if (*allocated < sizeof(*f) + qname->len) {
11439 + v = roundup_pow_of_two(*allocated + qname->len);
11440 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11441 + if (unlikely(!p)) {
11449 + drinfo = &f->drinfo;
11451 + memcpy(drinfo->oldname, qname->name, qname->len);
11452 + AuDbg("i%llu, %.*s\n",
11453 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11454 + drinfo->oldname);
11461 +/* callers have to free the return value */
11462 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11464 + struct au_drinfo *ret, *drinfo;
11465 + struct au_drinfo_fdata fdata;
11470 + ret = ERR_PTR(-EIO);
11472 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11473 + if (unlikely(ssz != sizeof(fdata))) {
11474 + AuIOErr("ssz %zd, %u, %pD2\n",
11475 + ssz, (unsigned int)sizeof(fdata), file);
11479 + fdata.magic = ntohl((__force __be32)fdata.magic);
11480 + switch (fdata.magic) {
11481 + case AUFS_DRINFO_MAGIC_V1:
11484 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11485 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11489 + drinfo = &fdata.drinfo;
11490 + len = drinfo->oldnamelen;
11492 + AuIOErr("broken drinfo %pD2\n", file);
11497 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11498 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11499 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11500 + (unsigned long long)drinfo->ino,
11501 + (unsigned long long)h_ino, file);
11502 + goto out; /* success */
11505 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11506 + if (unlikely(!ret)) {
11507 + ret = ERR_PTR(-ENOMEM);
11508 + AuTraceErrPtr(ret);
11513 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11514 + if (unlikely(ssz != len)) {
11515 + au_kfree_rcu(ret);
11516 + ret = ERR_PTR(-EIO);
11517 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11521 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11527 +/* ---------------------------------------------------------------------- */
11529 +/* in order to be revertible */
11530 +struct au_drinfo_rev_elm {
11532 + struct dentry *info_dentry;
11533 + struct au_drinfo *info_last;
11536 +struct au_drinfo_rev {
11537 + unsigned char already;
11538 + aufs_bindex_t nelm;
11539 + struct au_drinfo_rev_elm elm[0];
11542 +/* todo: isn't it too large? */
11543 +struct au_drinfo_store {
11544 + struct path h_ppath;
11545 + struct dentry *h_dentry;
11546 + struct au_drinfo_fdata *fdata;
11547 + char *infoname; /* inside of whname, just after PFX */
11548 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11549 + aufs_bindex_t btgt, btail;
11550 + unsigned char no_sio,
11551 + allocated, /* current size of *fdata */
11552 + infonamelen, /* room size for p */
11553 + whnamelen, /* length of the generated name */
11554 + renameback; /* renamed back */
11557 +/* on rename(2) error, the caller should revert it using @elm */
11558 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11559 + struct au_drinfo_rev_elm *elm)
11564 + struct path infopath = {
11565 + .mnt = w->h_ppath.mnt
11567 + struct inode *h_dir, *h_inode, *delegated;
11568 + struct file *infofile;
11569 + struct qstr *qname;
11572 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11574 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11576 + AuTraceErrPtr(infopath.dentry);
11577 + if (IS_ERR(infopath.dentry)) {
11578 + err = PTR_ERR(infopath.dentry);
11583 + h_dir = d_inode(w->h_ppath.dentry);
11584 + if (elm && d_is_negative(infopath.dentry)) {
11585 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11587 + if (unlikely(err))
11589 + elm->created = 1;
11590 + elm->info_dentry = dget(infopath.dentry);
11593 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11594 + AuTraceErrPtr(infofile);
11595 + if (IS_ERR(infofile)) {
11596 + err = PTR_ERR(infofile);
11600 + h_inode = d_inode(infopath.dentry);
11601 + if (elm && i_size_read(h_inode)) {
11602 + h_inode = d_inode(w->h_dentry);
11603 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11604 + AuTraceErrPtr(elm->info_last);
11605 + if (IS_ERR(elm->info_last)) {
11606 + err = PTR_ERR(elm->info_last);
11607 + elm->info_last = NULL;
11608 + AuDebugOn(elm->info_dentry);
11613 + if (elm && w->renameback) {
11614 + delegated = NULL;
11615 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11617 + if (unlikely(err == -EWOULDBLOCK))
11623 + qname = &w->h_dentry->d_name;
11624 + len = sizeof(*w->fdata) + qname->len;
11626 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11627 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11628 + if (ssz == len) {
11629 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11630 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11631 + goto out_fput; /* success */
11636 + /* the caller should revert it using @elm */
11642 + dput(infopath.dentry);
11648 +struct au_call_drinfo_do_store_args {
11650 + struct au_drinfo_store *w;
11651 + struct au_drinfo_rev_elm *elm;
11654 +static void au_call_drinfo_do_store(void *args)
11656 + struct au_call_drinfo_do_store_args *a = args;
11658 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11661 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11662 + struct au_drinfo_rev_elm *elm)
11664 + int err, wkq_err;
11667 + err = au_drinfo_do_store(w, elm);
11669 + struct au_call_drinfo_do_store_args a = {
11674 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11675 + if (unlikely(wkq_err))
11683 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11684 + aufs_bindex_t btgt)
11688 + memset(w, 0, sizeof(*w));
11689 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11690 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11691 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11692 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11694 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11697 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11698 + if (unlikely(!w->fdata)) {
11702 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11709 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11711 + au_kfree_rcu(w->fdata);
11714 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11715 + struct au_drinfo_store *w)
11717 + struct au_drinfo_rev_elm *elm;
11718 + struct inode *h_dir, *delegated;
11720 + struct path infopath = {
11721 + .mnt = w->h_ppath.mnt
11724 + h_dir = d_inode(w->h_ppath.dentry);
11725 + IMustLock(h_dir);
11729 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11730 + AuDebugOn(elm->created && elm->info_last);
11731 + if (elm->created) {
11733 + delegated = NULL;
11734 + infopath.dentry = elm->info_dentry;
11735 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11738 + if (unlikely(err == -EWOULDBLOCK))
11740 + dput(elm->info_dentry);
11741 + } else if (elm->info_last) {
11743 + w->fdata->drinfo = *elm->info_last;
11744 + memcpy(w->fdata->drinfo.oldname,
11745 + elm->info_last->oldname,
11746 + elm->info_last->oldnamelen);
11747 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11748 + au_kfree_rcu(elm->info_last);
11750 + if (unlikely(err))
11751 + AuIOErr("%d, %s\n", err, w->whname);
11752 + /* go on even if err */
11756 +/* caller has to call au_dr_rename_fin() later */
11757 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11758 + struct qstr *dst_name, void *_rev)
11760 + int err, sz, nelm;
11761 + aufs_bindex_t bindex, btail;
11762 + struct au_drinfo_store work;
11763 + struct au_drinfo_rev *rev, **p;
11764 + struct au_drinfo_rev_elm *elm;
11765 + struct super_block *sb;
11766 + struct au_branch *br;
11767 + struct au_hinode *hdir;
11769 + err = au_drinfo_store_work_init(&work, btgt);
11771 + if (unlikely(err))
11775 + btail = au_dbtaildir(dentry);
11776 + nelm = btail - btgt;
11777 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11778 + rev = kcalloc(1, sz, GFP_NOFS);
11779 + if (unlikely(!rev)) {
11783 + rev->nelm = nelm;
11789 + sb = dentry->d_sb;
11790 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11791 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11792 + hdir = au_hi(d_inode(dentry), btgt);
11793 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11794 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11795 + work.h_dentry = au_h_dptr(dentry, bindex);
11796 + if (!work.h_dentry)
11799 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11800 + &work.allocated);
11802 + if (unlikely(err))
11805 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11806 + br = au_sbr(sb, bindex);
11807 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11808 + work.whnamelen += au_drinfo_name(br, work.infoname,
11809 + work.infonamelen);
11810 + AuDbg("whname %.*s, i%llu, %.*s\n",
11811 + work.whnamelen, work.whname,
11812 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11813 + work.fdata->drinfo.oldnamelen,
11814 + work.fdata->drinfo.oldname);
11816 + err = au_drinfo_store_sio(&work, elm);
11818 + if (unlikely(err))
11821 + if (unlikely(err)) {
11822 + /* revert all drinfo */
11823 + au_drinfo_store_rev(rev, &work);
11824 + au_kfree_try_rcu(rev);
11827 + au_hn_inode_unlock(hdir);
11830 + au_drinfo_store_work_fin(&work);
11835 +/* ---------------------------------------------------------------------- */
11837 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11838 + struct qstr *dst_name, void *_rev)
11840 + int err, already;
11842 + struct super_block *sb;
11843 + struct au_branch *br;
11844 + struct au_dr_br *dr;
11845 + struct dentry *h_dentry;
11846 + struct inode *h_inode;
11847 + struct au_dr_hino *ent;
11848 + struct au_drinfo_rev *rev, **p;
11850 + AuDbg("bindex %d\n", bindex);
11853 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11854 + if (unlikely(!ent))
11858 + br = au_sbr(sb, bindex);
11859 + dr = &br->br_dirren;
11860 + h_dentry = au_h_dptr(src, bindex);
11861 + h_inode = d_inode(h_dentry);
11862 + ino = h_inode->i_ino;
11863 + ent->dr_h_ino = ino;
11864 + already = au_dr_hino_test_add(dr, ino, ent);
11865 + AuDbg("b%d, hi%llu, already %d\n",
11866 + bindex, (unsigned long long)ino, already);
11868 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11873 + rev->already = already;
11874 + goto out; /* success */
11879 + au_dr_hino_del(dr, ent);
11880 + au_kfree_rcu(ent);
11887 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11889 + struct au_drinfo_rev *rev;
11890 + struct au_drinfo_rev_elm *elm;
11895 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11896 + dput(elm->info_dentry);
11897 + au_kfree_rcu(elm->info_last);
11899 + au_kfree_try_rcu(rev);
11902 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11905 + struct au_drinfo_store work;
11906 + struct au_drinfo_rev *rev = _rev;
11907 + struct super_block *sb;
11908 + struct au_branch *br;
11909 + struct inode *h_inode;
11910 + struct au_dr_br *dr;
11911 + struct au_dr_hino *ent;
11913 + err = au_drinfo_store_work_init(&work, btgt);
11914 + if (unlikely(err))
11918 + br = au_sbr(sb, btgt);
11919 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11920 + work.h_ppath.mnt = au_br_mnt(br);
11921 + au_drinfo_store_rev(rev, &work);
11922 + au_drinfo_store_work_fin(&work);
11923 + if (rev->already)
11926 + dr = &br->br_dirren;
11927 + h_inode = d_inode(work.h_ppath.dentry);
11928 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11930 + au_dr_hino_del(dr, ent);
11931 + au_kfree_rcu(ent);
11934 + au_kfree_try_rcu(rev);
11935 + if (unlikely(err))
11936 + pr_err("failed to remove dirren info\n");
11939 +/* ---------------------------------------------------------------------- */
11941 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11942 + char *whname, int whnamelen,
11943 + struct dentry **info_dentry)
11945 + struct au_drinfo *drinfo;
11947 + struct inode *h_dir;
11948 + struct path infopath;
11951 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11953 + *info_dentry = NULL;
11956 + h_dir = d_inode(h_ppath->dentry);
11957 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11958 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11960 + if (IS_ERR(infopath.dentry)) {
11961 + drinfo = (void *)infopath.dentry;
11965 + if (d_is_negative(infopath.dentry))
11966 + goto out_dput; /* success */
11968 + infopath.mnt = h_ppath->mnt;
11969 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11970 + inode_unlock_shared(h_dir);
11973 + drinfo = (void *)f;
11977 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11978 + if (IS_ERR_OR_NULL(drinfo))
11981 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11982 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11987 + dput(infopath.dentry);
11990 + inode_unlock_shared(h_dir);
11991 + AuTraceErrPtr(drinfo);
11995 +struct au_drinfo_do_load_args {
11996 + struct au_drinfo **drinfop;
11997 + struct path *h_ppath;
12000 + struct dentry **info_dentry;
12003 +static void au_call_drinfo_do_load(void *args)
12005 + struct au_drinfo_do_load_args *a = args;
12007 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12011 +struct au_drinfo_load {
12012 + struct path h_ppath;
12013 + struct qstr *qname;
12014 + unsigned char no_sio;
12016 + aufs_bindex_t ninfo;
12017 + struct au_drinfo **drinfo;
12020 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12021 + struct au_branch *br)
12023 + int err, wkq_err, whnamelen, e;
12024 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12025 + = AUFS_WH_DR_INFO_PFX;
12026 + struct au_drinfo *drinfo;
12027 + struct qstr oldname;
12028 + struct inode *h_dir, *delegated;
12029 + struct dentry *info_dentry;
12030 + struct path infopath;
12032 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12033 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12034 + sizeof(whname) - whnamelen);
12036 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12039 + struct au_drinfo_do_load_args args = {
12040 + .drinfop = &drinfo,
12041 + .h_ppath = &w->h_ppath,
12042 + .whname = whname,
12043 + .whnamelen = whnamelen,
12044 + .info_dentry = &info_dentry
12046 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12047 + if (unlikely(wkq_err))
12048 + drinfo = ERR_PTR(wkq_err);
12050 + err = PTR_ERR(drinfo);
12051 + if (IS_ERR_OR_NULL(drinfo))
12055 + oldname.len = drinfo->oldnamelen;
12056 + oldname.name = drinfo->oldname;
12057 + if (au_qstreq(w->qname, &oldname)) {
12058 + /* the name is renamed back */
12059 + au_kfree_rcu(drinfo);
12062 + infopath.dentry = info_dentry;
12063 + infopath.mnt = w->h_ppath.mnt;
12064 + h_dir = d_inode(w->h_ppath.dentry);
12065 + delegated = NULL;
12066 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12067 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12068 + inode_unlock(h_dir);
12070 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12071 + if (unlikely(e == -EWOULDBLOCK))
12074 + au_kfree_rcu(w->drinfo[bindex]);
12075 + w->drinfo[bindex] = drinfo;
12076 + dput(info_dentry);
12083 +/* ---------------------------------------------------------------------- */
12085 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12087 + struct au_drinfo **p = drinfo;
12090 + au_kfree_rcu(*drinfo++);
12091 + au_kfree_try_rcu(p);
12094 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12095 + aufs_bindex_t btgt)
12098 + struct au_drinfo_load w;
12099 + aufs_bindex_t bindex, bbot;
12100 + struct au_branch *br;
12101 + struct inode *h_dir;
12102 + struct au_dr_hino *ent;
12103 + struct super_block *sb;
12105 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12106 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12107 + AuLNPair(&lkup->whname), btgt);
12109 + sb = dentry->d_sb;
12110 + bbot = au_sbbot(sb);
12111 + w.ninfo = bbot + 1;
12112 + if (!lkup->dirren.drinfo) {
12113 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12114 + sizeof(*lkup->dirren.drinfo),
12116 + if (unlikely(!lkup->dirren.drinfo)) {
12120 + lkup->dirren.ninfo = w.ninfo;
12122 + w.drinfo = lkup->dirren.drinfo;
12123 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12124 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12125 + AuDebugOn(!w.h_ppath.dentry);
12126 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12127 + w.qname = &dentry->d_name;
12130 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12131 + br = au_sbr(sb, bindex);
12132 + err = au_drinfo_load(&w, bindex, br);
12133 + if (unlikely(err))
12135 + if (w.drinfo[bindex])
12139 + br = au_sbr(sb, btgt);
12140 + h_dir = d_inode(w.h_ppath.dentry);
12141 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12143 + au_dr_hino_del(&br->br_dirren, ent);
12144 + au_kfree_rcu(ent);
12146 + goto out; /* success */
12149 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12150 + lkup->dirren.ninfo = 0;
12151 + lkup->dirren.drinfo = NULL;
12157 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12159 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12162 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12165 + struct au_drinfo *drinfo;
12168 + if (!lkup->dirren.drinfo)
12170 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12171 + drinfo = lkup->dirren.drinfo[btgt + 1];
12175 + au_kfree_try_rcu(lkup->whname.name);
12176 + lkup->whname.name = NULL;
12177 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12178 + lkup->dirren.dr_name.name = drinfo->oldname;
12179 + lkup->name = &lkup->dirren.dr_name;
12180 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12182 + AuDbg("name %.*s, whname %.*s, b%d\n",
12183 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12191 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12195 + struct au_drinfo *drinfo;
12198 + if (!lkup->dirren.drinfo)
12200 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12201 + drinfo = lkup->dirren.drinfo[bindex + 1];
12205 + match = (drinfo->ino == h_ino);
12206 + AuDbg("match %d\n", match);
12212 +/* ---------------------------------------------------------------------- */
12214 +int au_dr_opt_set(struct super_block *sb)
12217 + aufs_bindex_t bindex, bbot;
12218 + struct au_branch *br;
12221 + bbot = au_sbbot(sb);
12222 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12223 + br = au_sbr(sb, bindex);
12224 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12230 +int au_dr_opt_flush(struct super_block *sb)
12233 + aufs_bindex_t bindex, bbot;
12234 + struct au_branch *br;
12237 + bbot = au_sbbot(sb);
12238 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12239 + br = au_sbr(sb, bindex);
12240 + if (au_br_writable(br->br_perm))
12241 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12247 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12250 + aufs_bindex_t bindex, bbot;
12251 + struct au_branch *br;
12255 + err = au_dr_opt_flush(sb);
12256 + if (unlikely(err))
12260 + bbot = au_sbbot(sb);
12261 + for (bindex = 0; bindex <= bbot; bindex++) {
12262 + br = au_sbr(sb, bindex);
12263 + au_dr_hino_free(&br->br_dirren);
12269 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12270 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12271 +++ linux/fs/aufs/dirren.h 2019-07-11 15:42:14.462237786 +0200
12273 +/* SPDX-License-Identifier: GPL-2.0 */
12275 + * Copyright (C) 2017-2019 Junjiro R. Okajima
12277 + * This program, aufs is free software; you can redistribute it and/or modify
12278 + * it under the terms of the GNU General Public License as published by
12279 + * the Free Software Foundation; either version 2 of the License, or
12280 + * (at your option) any later version.
12282 + * This program is distributed in the hope that it will be useful,
12283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12285 + * GNU General Public License for more details.
12287 + * You should have received a copy of the GNU General Public License
12288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12292 + * renamed dir info
12295 +#ifndef __AUFS_DIRREN_H__
12296 +#define __AUFS_DIRREN_H__
12300 +#include <linux/dcache.h>
12301 +#include <linux/statfs.h>
12302 +#include <linux/uuid.h>
12305 +#define AuDirren_NHASH 100
12307 +#ifdef CONFIG_AUFS_DIRREN
12308 +enum au_brid_type {
12315 +struct au_dr_brid {
12316 + enum au_brid_type type;
12318 + uuid_t uuid; /* unimplemented yet */
12324 +/* 20 is the max digits length of ulong 64 */
12325 +/* brid-type "_" uuid "_" inum */
12326 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12327 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12329 +struct au_dr_hino {
12330 + struct hlist_bl_node dr_hnode;
12335 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12336 + struct au_dr_brid dr_brid;
12339 +struct au_dr_lookup {
12340 + /* dr_name is pointed by struct au_do_lookup_args.name */
12341 + struct qstr dr_name; /* subset of dr_info */
12342 + aufs_bindex_t ninfo;
12343 + struct au_drinfo **drinfo;
12346 +struct au_dr_hino;
12348 +struct au_dr_br { };
12349 +struct au_dr_lookup { };
12352 +/* ---------------------------------------------------------------------- */
12355 +struct au_do_lookup_args;
12357 +#ifdef CONFIG_AUFS_DIRREN
12358 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12359 + struct au_dr_hino *add_ent);
12360 +void au_dr_hino_free(struct au_dr_br *dr);
12361 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12362 + const struct path *path);
12363 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12364 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12365 + struct qstr *dst_name, void *_rev);
12366 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12367 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12368 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12369 + aufs_bindex_t bindex);
12370 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12371 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12373 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12374 +int au_dr_opt_set(struct super_block *sb);
12375 +int au_dr_opt_flush(struct super_block *sb);
12376 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12378 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12379 + struct au_dr_hino *add_ent);
12380 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12381 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12382 + const struct path *path);
12383 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12384 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12385 + struct qstr *dst_name, void *_rev);
12386 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12387 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12389 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12390 + aufs_bindex_t bindex);
12391 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12392 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12393 + aufs_bindex_t bindex, ino_t h_ino);
12394 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12395 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12396 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12397 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12400 +/* ---------------------------------------------------------------------- */
12402 +#ifdef CONFIG_AUFS_DIRREN
12403 +static inline int au_dr_ihash(ino_t h_ino)
12405 + return h_ino % AuDirren_NHASH;
12408 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12411 +#endif /* __KERNEL__ */
12412 +#endif /* __AUFS_DIRREN_H__ */
12413 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12414 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12415 +++ linux/fs/aufs/dynop.c 2019-07-11 15:42:14.465571210 +0200
12417 +// SPDX-License-Identifier: GPL-2.0
12419 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12421 + * This program, aufs is free software; you can redistribute it and/or modify
12422 + * it under the terms of the GNU General Public License as published by
12423 + * the Free Software Foundation; either version 2 of the License, or
12424 + * (at your option) any later version.
12426 + * This program is distributed in the hope that it will be useful,
12427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12429 + * GNU General Public License for more details.
12431 + * You should have received a copy of the GNU General Public License
12432 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12436 + * dynamically customizable operations for regular files
12441 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12444 + * How large will these lists be?
12445 + * Usually just a few elements, 20-30 at most for each, I guess.
12447 +static struct hlist_bl_head dynop[AuDyLast];
12449 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12450 + const void *h_op)
12452 + struct au_dykey *key, *tmp;
12453 + struct hlist_bl_node *pos;
12456 + hlist_bl_lock(hbl);
12457 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12458 + if (tmp->dk_op.dy_hop == h_op) {
12459 + if (kref_get_unless_zero(&tmp->dk_kref))
12463 + hlist_bl_unlock(hbl);
12468 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12470 + struct au_dykey **k, *found;
12471 + const void *h_op = key->dk_op.dy_hop;
12475 + k = br->br_dykey;
12476 + for (i = 0; i < AuBrDynOp; i++)
12478 + if (k[i]->dk_op.dy_hop == h_op) {
12485 + spin_lock(&br->br_dykey_lock);
12486 + for (; i < AuBrDynOp; i++)
12488 + if (k[i]->dk_op.dy_hop == h_op) {
12496 + spin_unlock(&br->br_dykey_lock);
12497 + BUG_ON(i == AuBrDynOp); /* expand the array */
12503 +/* kref_get() if @key is already added */
12504 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12506 + struct au_dykey *tmp, *found;
12507 + struct hlist_bl_node *pos;
12508 + const void *h_op = key->dk_op.dy_hop;
12511 + hlist_bl_lock(hbl);
12512 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12513 + if (tmp->dk_op.dy_hop == h_op) {
12514 + if (kref_get_unless_zero(&tmp->dk_kref))
12519 + hlist_bl_add_head(&key->dk_hnode, hbl);
12520 + hlist_bl_unlock(hbl);
12527 +static void dy_free_rcu(struct rcu_head *rcu)
12529 + struct au_dykey *key;
12531 + key = container_of(rcu, struct au_dykey, dk_rcu);
12536 +static void dy_free(struct kref *kref)
12538 + struct au_dykey *key;
12539 + struct hlist_bl_head *hbl;
12541 + key = container_of(kref, struct au_dykey, dk_kref);
12542 + hbl = dynop + key->dk_op.dy_type;
12543 + au_hbl_del(&key->dk_hnode, hbl);
12544 + call_rcu(&key->dk_rcu, dy_free_rcu);
12547 +void au_dy_put(struct au_dykey *key)
12549 + kref_put(&key->dk_kref, dy_free);
12552 +/* ---------------------------------------------------------------------- */
12554 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12556 +#ifdef CONFIG_AUFS_DEBUG
12557 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12558 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12560 +#define DyDbgDeclare(cnt) do {} while (0)
12561 +#define DyDbgInc(cnt) do {} while (0)
12564 +#define DySet(func, dst, src, h_op, h_sb) do { \
12566 + if (h_op->func) { \
12568 + dst.func = src.func; \
12570 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12574 +#define DySetForce(func, dst, src) do { \
12575 + AuDebugOn(!src.func); \
12577 + dst.func = src.func; \
12580 +#define DySetAop(func) \
12581 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12582 +#define DySetAopForce(func) \
12583 + DySetForce(func, dyaop->da_op, aufs_aop)
12585 +static void dy_aop(struct au_dykey *key, const void *h_op,
12586 + struct super_block *h_sb __maybe_unused)
12588 + struct au_dyaop *dyaop = (void *)key;
12589 + const struct address_space_operations *h_aop = h_op;
12590 + DyDbgDeclare(cnt);
12592 + AuDbg("%s\n", au_sbtype(h_sb));
12594 + DySetAop(writepage);
12595 + DySetAopForce(readpage); /* force */
12596 + DySetAop(writepages);
12597 + DySetAop(set_page_dirty);
12598 + DySetAop(readpages);
12599 + DySetAop(write_begin);
12600 + DySetAop(write_end);
12602 + DySetAop(invalidatepage);
12603 + DySetAop(releasepage);
12604 + DySetAop(freepage);
12605 + /* this one will be changed according to an aufs mount option */
12606 + DySetAop(direct_IO);
12607 + DySetAop(migratepage);
12608 + DySetAop(isolate_page);
12609 + DySetAop(putback_page);
12610 + DySetAop(launder_page);
12611 + DySetAop(is_partially_uptodate);
12612 + DySetAop(is_dirty_writeback);
12613 + DySetAop(error_remove_page);
12614 + DySetAop(swap_activate);
12615 + DySetAop(swap_deactivate);
12617 + DyDbgSize(cnt, *h_aop);
12620 +/* ---------------------------------------------------------------------- */
12622 +static void dy_bug(struct kref *kref)
12627 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12629 + struct au_dykey *key, *old;
12630 + struct hlist_bl_head *hbl;
12633 + void (*set)(struct au_dykey *key, const void *h_op,
12634 + struct super_block *h_sb __maybe_unused);
12636 + static const struct op a[] = {
12638 + .sz = sizeof(struct au_dyaop),
12642 + const struct op *p;
12644 + hbl = dynop + op->dy_type;
12645 + key = dy_gfind_get(hbl, op->dy_hop);
12647 + goto out_add; /* success */
12649 + p = a + op->dy_type;
12650 + key = kzalloc(p->sz, GFP_NOFS);
12651 + if (unlikely(!key)) {
12652 + key = ERR_PTR(-ENOMEM);
12656 + key->dk_op.dy_hop = op->dy_hop;
12657 + kref_init(&key->dk_kref);
12658 + p->set(key, op->dy_hop, au_br_sb(br));
12659 + old = dy_gadd(hbl, key);
12661 + au_kfree_rcu(key);
12666 + old = dy_bradd(br, key);
12668 + /* its ref-count should never be zero here */
12669 + kref_put(&key->dk_kref, dy_bug);
12674 +/* ---------------------------------------------------------------------- */
12676 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12677 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12678 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12679 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12680 + * See the aufs manual in detail.
12682 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12685 + dyaop->da_op.direct_IO = NULL;
12687 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12690 +static struct au_dyaop *dy_aget(struct au_branch *br,
12691 + const struct address_space_operations *h_aop,
12694 + struct au_dyaop *dyaop;
12695 + struct au_dynop op;
12697 + op.dy_type = AuDy_AOP;
12698 + op.dy_haop = h_aop;
12699 + dyaop = (void *)dy_get(&op, br);
12700 + if (IS_ERR(dyaop))
12702 + dy_adx(dyaop, do_dx);
12708 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12709 + struct inode *h_inode)
12712 + struct super_block *sb;
12713 + struct au_branch *br;
12714 + struct au_dyaop *dyaop;
12716 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12717 + IiMustWriteLock(inode);
12719 + sb = inode->i_sb;
12720 + br = au_sbr(sb, bindex);
12721 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12722 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12723 + err = PTR_ERR(dyaop);
12724 + if (IS_ERR(dyaop))
12725 + /* unnecessary to call dy_fput() */
12729 + inode->i_mapping->a_ops = &dyaop->da_op;
12736 + * Is it safe to replace a_ops during the inode/file is in operation?
12737 + * Yes, I hope so.
12739 +int au_dy_irefresh(struct inode *inode)
12742 + aufs_bindex_t btop;
12743 + struct inode *h_inode;
12746 + if (S_ISREG(inode->i_mode)) {
12747 + btop = au_ibtop(inode);
12748 + h_inode = au_h_iptr(inode, btop);
12749 + err = au_dy_iaop(inode, btop, h_inode);
12754 +void au_dy_arefresh(int do_dx)
12756 + struct hlist_bl_head *hbl;
12757 + struct hlist_bl_node *pos;
12758 + struct au_dykey *key;
12760 + hbl = dynop + AuDy_AOP;
12761 + hlist_bl_lock(hbl);
12762 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12763 + dy_adx((void *)key, do_dx);
12764 + hlist_bl_unlock(hbl);
12767 +/* ---------------------------------------------------------------------- */
12769 +void __init au_dy_init(void)
12773 + for (i = 0; i < AuDyLast; i++)
12774 + INIT_HLIST_BL_HEAD(dynop + i);
12777 +void au_dy_fin(void)
12781 + for (i = 0; i < AuDyLast; i++)
12782 + WARN_ON(!hlist_bl_empty(dynop + i));
12784 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12785 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12786 +++ linux/fs/aufs/dynop.h 2019-07-11 15:42:14.465571210 +0200
12788 +/* SPDX-License-Identifier: GPL-2.0 */
12790 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12792 + * This program, aufs is free software; you can redistribute it and/or modify
12793 + * it under the terms of the GNU General Public License as published by
12794 + * the Free Software Foundation; either version 2 of the License, or
12795 + * (at your option) any later version.
12797 + * This program is distributed in the hope that it will be useful,
12798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12800 + * GNU General Public License for more details.
12802 + * You should have received a copy of the GNU General Public License
12803 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12807 + * dynamically customizable operations (for regular files only)
12810 +#ifndef __AUFS_DYNOP_H__
12811 +#define __AUFS_DYNOP_H__
12815 +#include <linux/fs.h>
12816 +#include <linux/kref.h>
12818 +enum {AuDy_AOP, AuDyLast};
12823 + const void *dy_hop;
12824 + const struct address_space_operations *dy_haop;
12830 + struct hlist_bl_node dk_hnode;
12831 + struct rcu_head dk_rcu;
12833 + struct au_dynop dk_op;
12836 + * during I am in the branch local array, kref is gotten. when the
12837 + * branch is removed, kref is put.
12839 + struct kref dk_kref;
12842 +/* stop unioning since their sizes are very different from each other */
12844 + struct au_dykey da_key;
12845 + struct address_space_operations da_op; /* not const */
12847 +/* make sure that 'struct au_dykey *' can be any type */
12848 +static_assert(!offsetof(struct au_dyaop, da_key));
12850 +/* ---------------------------------------------------------------------- */
12854 +void au_dy_put(struct au_dykey *key);
12855 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12856 + struct inode *h_inode);
12857 +int au_dy_irefresh(struct inode *inode);
12858 +void au_dy_arefresh(int do_dio);
12860 +void __init au_dy_init(void);
12861 +void au_dy_fin(void);
12863 +#endif /* __KERNEL__ */
12864 +#endif /* __AUFS_DYNOP_H__ */
12865 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12866 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12867 +++ linux/fs/aufs/export.c 2019-07-11 15:42:14.465571210 +0200
12869 +// SPDX-License-Identifier: GPL-2.0
12871 + * Copyright (C) 2005-2019 Junjiro R. Okajima
12873 + * This program, aufs is free software; you can redistribute it and/or modify
12874 + * it under the terms of the GNU General Public License as published by
12875 + * the Free Software Foundation; either version 2 of the License, or
12876 + * (at your option) any later version.
12878 + * This program is distributed in the hope that it will be useful,
12879 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12880 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12881 + * GNU General Public License for more details.
12883 + * You should have received a copy of the GNU General Public License
12884 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12891 +#include <linux/exportfs.h>
12892 +#include <linux/fs_struct.h>
12893 +#include <linux/namei.h>
12894 +#include <linux/nsproxy.h>
12895 +#include <linux/random.h>
12896 +#include <linux/writeback.h>
12900 +#ifdef CONFIG_AUFS_INO_T_64
12908 +static ino_t decode_ino(__u32 *a)
12912 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12914 +#ifdef CONFIG_AUFS_INO_T_64
12920 +static void encode_ino(__u32 *a, ino_t ino)
12926 +#ifdef CONFIG_AUFS_INO_T_64
12931 +/* NFS file handle */
12935 +#ifdef CONFIG_AUFS_INO_T_64
12936 + /* support 64bit inode number */
12949 + Fh_ino = Fh_ino1,
12950 + Fh_dir_ino = Fh_dir_ino1
12953 +static int au_test_anon(struct dentry *dentry)
12955 + /* note: read d_flags without d_lock */
12956 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12959 +int au_test_nfsd(void)
12962 + struct task_struct *tsk = current;
12963 + char comm[sizeof(tsk->comm)];
12966 + if (tsk->flags & PF_KTHREAD) {
12967 + get_task_comm(comm, tsk);
12968 + ret = !strcmp(comm, "nfsd");
12974 +/* ---------------------------------------------------------------------- */
12975 +/* inode generation external table */
12977 +void au_xigen_inc(struct inode *inode)
12982 + struct super_block *sb;
12983 + struct au_sbinfo *sbinfo;
12985 + sb = inode->i_sb;
12986 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12988 + sbinfo = au_sbi(sb);
12989 + pos = inode->i_ino;
12990 + pos *= sizeof(igen);
12991 + igen = inode->i_generation + 1;
12992 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12993 + sizeof(igen), &pos);
12994 + if (sz == sizeof(igen))
12995 + return; /* success */
12997 + if (unlikely(sz >= 0))
12998 + AuIOErr("xigen error (%zd)\n", sz);
13001 +int au_xigen_new(struct inode *inode)
13006 + struct super_block *sb;
13007 + struct au_sbinfo *sbinfo;
13008 + struct file *file;
13011 + /* todo: dirty, at mount time */
13012 + if (inode->i_ino == AUFS_ROOT_INO)
13014 + sb = inode->i_sb;
13015 + SiMustAnyLock(sb);
13016 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13020 + pos = inode->i_ino;
13021 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13022 + AuIOErr1("too large i%lld\n", pos);
13025 + pos *= sizeof(inode->i_generation);
13028 + sbinfo = au_sbi(sb);
13029 + file = sbinfo->si_xigen;
13032 + if (vfsub_f_size_read(file)
13033 + < pos + sizeof(inode->i_generation)) {
13034 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13035 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13036 + sizeof(inode->i_generation), &pos);
13038 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13039 + sizeof(inode->i_generation), &pos);
13040 + if (sz == sizeof(inode->i_generation))
13041 + goto out; /* success */
13044 + if (unlikely(sz >= 0)) {
13046 + AuIOErr("xigen error (%zd)\n", sz);
13053 +int au_xigen_set(struct super_block *sb, struct path *path)
13056 + struct au_sbinfo *sbinfo;
13057 + struct file *file;
13059 + SiMustWriteLock(sb);
13061 + sbinfo = au_sbi(sb);
13062 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13063 + err = PTR_ERR(file);
13064 + if (IS_ERR(file))
13067 + if (sbinfo->si_xigen)
13068 + fput(sbinfo->si_xigen);
13069 + sbinfo->si_xigen = file;
13076 +void au_xigen_clr(struct super_block *sb)
13078 + struct au_sbinfo *sbinfo;
13080 + SiMustWriteLock(sb);
13082 + sbinfo = au_sbi(sb);
13083 + if (sbinfo->si_xigen) {
13084 + fput(sbinfo->si_xigen);
13085 + sbinfo->si_xigen = NULL;
13089 +/* ---------------------------------------------------------------------- */
13091 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13094 + struct dentry *dentry, *d;
13095 + struct inode *inode;
13096 + unsigned int sigen;
13099 + inode = ilookup(sb, ino);
13103 + dentry = ERR_PTR(-ESTALE);
13104 + sigen = au_sigen(sb);
13105 + if (unlikely(au_is_bad_inode(inode)
13106 + || IS_DEADDIR(inode)
13107 + || sigen != au_iigen(inode, NULL)))
13111 + if (!dir_ino || S_ISDIR(inode->i_mode))
13112 + dentry = d_find_alias(inode);
13114 + spin_lock(&inode->i_lock);
13115 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13116 + spin_lock(&d->d_lock);
13117 + if (!au_test_anon(d)
13118 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13119 + dentry = dget_dlock(d);
13120 + spin_unlock(&d->d_lock);
13123 + spin_unlock(&d->d_lock);
13125 + spin_unlock(&inode->i_lock);
13127 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13128 + /* need to refresh */
13136 + AuTraceErrPtr(dentry);
13140 +/* ---------------------------------------------------------------------- */
13142 +/* todo: dirty? */
13143 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13145 +struct au_compare_mnt_args {
13147 + struct super_block *sb;
13150 + struct vfsmount *mnt;
13153 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13155 + struct au_compare_mnt_args *a = arg;
13157 + if (mnt->mnt_sb != a->sb)
13159 + a->mnt = mntget(mnt);
13163 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13166 + struct path root;
13167 + struct au_compare_mnt_args args = {
13171 + get_fs_root(current->fs, &root);
13173 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13174 + rcu_read_unlock();
13177 + AuDebugOn(!args.mnt);
13181 +struct au_nfsd_si_lock {
13182 + unsigned int sigen;
13183 + aufs_bindex_t bindex, br_id;
13184 + unsigned char force_lock;
13187 +static int si_nfsd_read_lock(struct super_block *sb,
13188 + struct au_nfsd_si_lock *nsi_lock)
13191 + aufs_bindex_t bindex;
13193 + si_read_lock(sb, AuLock_FLUSH);
13195 + /* branch id may be wrapped around */
13197 + bindex = au_br_index(sb, nsi_lock->br_id);
13198 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13199 + goto out; /* success */
13203 + if (!nsi_lock->force_lock)
13204 + si_read_unlock(sb);
13207 + nsi_lock->bindex = bindex;
13211 +struct find_name_by_ino {
13212 + struct dir_context ctx;
13213 + int called, found;
13220 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13221 + loff_t offset, u64 ino, unsigned int d_type)
13223 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13227 + if (a->ino != ino)
13230 + memcpy(a->name, name, namelen);
13231 + a->namelen = namelen;
13236 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13237 + struct au_nfsd_si_lock *nsi_lock)
13239 + struct dentry *dentry, *parent;
13240 + struct file *file;
13241 + struct inode *dir;
13242 + struct find_name_by_ino arg = {
13244 + .actor = find_name_by_ino
13249 + parent = path->dentry;
13251 + si_read_unlock(parent->d_sb);
13252 + file = vfsub_dentry_open(path, au_dir_roflags);
13253 + dentry = (void *)file;
13254 + if (IS_ERR(file))
13257 + dentry = ERR_PTR(-ENOMEM);
13258 + arg.name = (void *)__get_free_page(GFP_NOFS);
13259 + if (unlikely(!arg.name))
13266 + err = vfsub_iterate_dir(file, &arg.ctx);
13267 + } while (!err && !arg.found && arg.called);
13268 + dentry = ERR_PTR(err);
13269 + if (unlikely(err))
13271 + /* instead of ENOENT */
13272 + dentry = ERR_PTR(-ESTALE);
13276 + /* do not call vfsub_lkup_one() */
13277 + dir = d_inode(parent);
13278 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13279 + AuTraceErrPtr(dentry);
13280 + if (IS_ERR(dentry))
13282 + AuDebugOn(au_test_anon(dentry));
13283 + if (unlikely(d_really_is_negative(dentry))) {
13285 + dentry = ERR_PTR(-ENOENT);
13289 + free_page((unsigned long)arg.name);
13293 + if (unlikely(nsi_lock
13294 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13295 + if (!IS_ERR(dentry)) {
13297 + dentry = ERR_PTR(-ESTALE);
13299 + AuTraceErrPtr(dentry);
13303 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13305 + struct au_nfsd_si_lock *nsi_lock)
13307 + struct dentry *dentry;
13308 + struct path path;
13310 + if (dir_ino != AUFS_ROOT_INO) {
13311 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13312 + dentry = path.dentry;
13313 + if (!path.dentry || IS_ERR(path.dentry))
13315 + AuDebugOn(au_test_anon(path.dentry));
13317 + path.dentry = dget(sb->s_root);
13319 + path.mnt = au_mnt_get(sb);
13320 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13324 + AuTraceErrPtr(dentry);
13328 +/* ---------------------------------------------------------------------- */
13330 +static int h_acceptable(void *expv, struct dentry *dentry)
13335 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13336 + char *buf, int len, struct super_block *sb)
13340 + struct path path;
13342 + p = d_path(h_rootpath, buf, len);
13347 + path.mnt = h_rootpath->mnt;
13348 + path.dentry = h_parent;
13349 + p = d_path(&path, buf, len);
13355 + path.mnt = au_mnt_get(sb);
13356 + path.dentry = sb->s_root;
13357 + p = d_path(&path, buf, len - strlen(p));
13358 + mntput(path.mnt);
13362 + p[strlen(p)] = '/';
13365 + AuTraceErrPtr(p);
13370 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13371 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13373 + struct dentry *dentry, *h_parent, *root;
13374 + struct super_block *h_sb;
13375 + char *pathname, *p;
13376 + struct vfsmount *h_mnt;
13377 + struct au_branch *br;
13379 + struct path path;
13381 + br = au_sbr(sb, nsi_lock->bindex);
13382 + h_mnt = au_br_mnt(br);
13383 + h_sb = h_mnt->mnt_sb;
13384 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13386 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13387 + fh_len - Fh_tail, fh[Fh_h_type],
13388 + h_acceptable, /*context*/NULL);
13390 + dentry = h_parent;
13391 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13392 + AuWarn1("%s decode_fh failed, %ld\n",
13393 + au_sbtype(h_sb), PTR_ERR(h_parent));
13397 + if (unlikely(au_test_anon(h_parent))) {
13398 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13399 + au_sbtype(h_sb));
13400 + goto out_h_parent;
13403 + dentry = ERR_PTR(-ENOMEM);
13404 + pathname = (void *)__get_free_page(GFP_NOFS);
13405 + if (unlikely(!pathname))
13406 + goto out_h_parent;
13408 + root = sb->s_root;
13409 + path.mnt = h_mnt;
13410 + di_read_lock_parent(root, !AuLock_IR);
13411 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13412 + di_read_unlock(root, !AuLock_IR);
13413 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13414 + dentry = (void *)p;
13416 + goto out_pathname;
13418 + si_read_unlock(sb);
13419 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13420 + dentry = ERR_PTR(err);
13421 + if (unlikely(err))
13424 + dentry = ERR_PTR(-ENOENT);
13425 + AuDebugOn(au_test_anon(path.dentry));
13426 + if (unlikely(d_really_is_negative(path.dentry)))
13429 + if (ino != d_inode(path.dentry)->i_ino)
13430 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13432 + dentry = dget(path.dentry);
13437 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13438 + if (!IS_ERR(dentry)) {
13440 + dentry = ERR_PTR(-ESTALE);
13443 + free_page((unsigned long)pathname);
13447 + AuTraceErrPtr(dentry);
13451 +/* ---------------------------------------------------------------------- */
13453 +static struct dentry *
13454 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13457 + struct dentry *dentry;
13458 + __u32 *fh = fid->raw;
13459 + struct au_branch *br;
13460 + ino_t ino, dir_ino;
13461 + struct au_nfsd_si_lock nsi_lock = {
13465 + dentry = ERR_PTR(-ESTALE);
13466 + /* it should never happen, but the file handle is unreliable */
13467 + if (unlikely(fh_len < Fh_tail))
13469 + nsi_lock.sigen = fh[Fh_sigen];
13470 + nsi_lock.br_id = fh[Fh_br_id];
13472 + /* branch id may be wrapped around */
13474 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13476 + nsi_lock.force_lock = 1;
13478 + /* is this inode still cached? */
13479 + ino = decode_ino(fh + Fh_ino);
13480 + /* it should never happen */
13481 + if (unlikely(ino == AUFS_ROOT_INO))
13484 + dir_ino = decode_ino(fh + Fh_dir_ino);
13485 + dentry = decode_by_ino(sb, ino, dir_ino);
13486 + if (IS_ERR(dentry))
13491 + /* is the parent dir cached? */
13492 + br = au_sbr(sb, nsi_lock.bindex);
13493 + au_lcnt_inc(&br->br_nfiles);
13494 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13495 + if (IS_ERR(dentry))
13500 + /* lookup path */
13501 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13502 + if (IS_ERR(dentry))
13504 + if (unlikely(!dentry))
13505 + /* todo?: make it ESTALE */
13509 + if (!au_digen_test(dentry, au_sigen(sb))
13510 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13511 + goto out_unlock; /* success */
13514 + dentry = ERR_PTR(-ESTALE);
13517 + au_lcnt_dec(&br->br_nfiles);
13518 + si_read_unlock(sb);
13520 + AuTraceErrPtr(dentry);
13524 +#if 0 /* reserved for future use */
13525 +/* support subtreecheck option */
13526 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13527 + int fh_len, int fh_type)
13529 + struct dentry *parent;
13530 + __u32 *fh = fid->raw;
13533 + dir_ino = decode_ino(fh + Fh_dir_ino);
13534 + parent = decode_by_ino(sb, dir_ino, 0);
13535 + if (IS_ERR(parent))
13538 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13539 + dir_ino, fh, fh_len);
13542 + AuTraceErrPtr(parent);
13547 +/* ---------------------------------------------------------------------- */
13549 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13550 + struct inode *dir)
13553 + aufs_bindex_t bindex;
13554 + struct super_block *sb, *h_sb;
13555 + struct dentry *dentry, *parent, *h_parent;
13556 + struct inode *h_dir;
13557 + struct au_branch *br;
13560 + if (unlikely(*max_len <= Fh_tail)) {
13561 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13565 + err = FILEID_ROOT;
13566 + if (inode->i_ino == AUFS_ROOT_INO) {
13567 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13572 + sb = inode->i_sb;
13573 + err = si_read_lock(sb, AuLock_FLUSH);
13574 + if (unlikely(err))
13577 +#ifdef CONFIG_AUFS_DEBUG
13578 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13579 + AuWarn1("NFS-exporting requires xino\n");
13583 + ii_read_lock_child(inode);
13584 + bindex = au_ibtop(inode);
13586 + dentry = d_find_any_alias(inode);
13587 + if (unlikely(!dentry))
13589 + AuDebugOn(au_test_anon(dentry));
13590 + parent = dget_parent(dentry);
13592 + if (unlikely(!parent))
13594 + if (d_really_is_positive(parent))
13595 + dir = d_inode(parent);
13598 + ii_read_lock_parent(dir);
13599 + h_dir = au_h_iptr(dir, bindex);
13600 + ii_read_unlock(dir);
13601 + if (unlikely(!h_dir))
13603 + h_parent = d_find_any_alias(h_dir);
13604 + if (unlikely(!h_parent))
13605 + goto out_hparent;
13608 + br = au_sbr(sb, bindex);
13609 + h_sb = au_br_sb(br);
13610 + if (unlikely(!h_sb->s_export_op)) {
13611 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13612 + goto out_hparent;
13615 + fh[Fh_br_id] = br->br_id;
13616 + fh[Fh_sigen] = au_sigen(sb);
13617 + encode_ino(fh + Fh_ino, inode->i_ino);
13618 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13619 + fh[Fh_igen] = inode->i_generation;
13621 + *max_len -= Fh_tail;
13622 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13624 + /*connectable or subtreecheck*/0);
13625 + err = fh[Fh_h_type];
13626 + *max_len += Fh_tail;
13627 + /* todo: macros? */
13628 + if (err != FILEID_INVALID)
13631 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13638 + ii_read_unlock(inode);
13639 + si_read_unlock(sb);
13641 + if (unlikely(err < 0))
13642 + err = FILEID_INVALID;
13646 +/* ---------------------------------------------------------------------- */
13648 +static int aufs_commit_metadata(struct inode *inode)
13651 + aufs_bindex_t bindex;
13652 + struct super_block *sb;
13653 + struct inode *h_inode;
13654 + int (*f)(struct inode *inode);
13656 + sb = inode->i_sb;
13657 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13658 + ii_write_lock_child(inode);
13659 + bindex = au_ibtop(inode);
13660 + AuDebugOn(bindex < 0);
13661 + h_inode = au_h_iptr(inode, bindex);
13663 + f = h_inode->i_sb->s_export_op->commit_metadata;
13665 + err = f(h_inode);
13667 + struct writeback_control wbc = {
13668 + .sync_mode = WB_SYNC_ALL,
13669 + .nr_to_write = 0 /* metadata only */
13672 + err = sync_inode(h_inode, &wbc);
13675 + au_cpup_attr_timesizes(inode);
13676 + ii_write_unlock(inode);
13677 + si_read_unlock(sb);
13681 +/* ---------------------------------------------------------------------- */
13683 +static struct export_operations aufs_export_op = {
13684 + .fh_to_dentry = aufs_fh_to_dentry,
13685 + /* .fh_to_parent = aufs_fh_to_parent, */
13686 + .encode_fh = aufs_encode_fh,
13687 + .commit_metadata = aufs_commit_metadata
13690 +void au_export_init(struct super_block *sb)
13692 + struct au_sbinfo *sbinfo;
13695 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13696 + && IS_MODULE(CONFIG_EXPORTFS),
13697 + AUFS_NAME ": unsupported configuration "
13698 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13700 + sb->s_export_op = &aufs_export_op;
13701 + sbinfo = au_sbi(sb);
13702 + sbinfo->si_xigen = NULL;
13703 + get_random_bytes(&u, sizeof(u));
13704 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13705 + atomic_set(&sbinfo->si_xigen_next, u);
13707 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13708 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13709 +++ linux/fs/aufs/fhsm.c 2019-07-11 15:42:14.465571210 +0200
13711 +// SPDX-License-Identifier: GPL-2.0
13713 + * Copyright (C) 2011-2019 Junjiro R. Okajima
13715 + * This program, aufs is free software; you can redistribute it and/or modify
13716 + * it under the terms of the GNU General Public License as published by
13717 + * the Free Software Foundation; either version 2 of the License, or
13718 + * (at your option) any later version.
13720 + * This program is distributed in the hope that it will be useful,
13721 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13722 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13723 + * GNU General Public License for more details.
13725 + * You should have received a copy of the GNU General Public License
13726 + * along with this program; if not, write to the Free Software
13727 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13731 + * File-based Hierarchy Storage Management
13734 +#include <linux/anon_inodes.h>
13735 +#include <linux/poll.h>
13736 +#include <linux/seq_file.h>
13737 +#include <linux/statfs.h>
13740 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13742 + struct au_sbinfo *sbinfo;
13743 + struct au_fhsm *fhsm;
13745 + SiMustAnyLock(sb);
13747 + sbinfo = au_sbi(sb);
13748 + fhsm = &sbinfo->si_fhsm;
13749 + AuDebugOn(!fhsm);
13750 + return fhsm->fhsm_bottom;
13753 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13755 + struct au_sbinfo *sbinfo;
13756 + struct au_fhsm *fhsm;
13758 + SiMustWriteLock(sb);
13760 + sbinfo = au_sbi(sb);
13761 + fhsm = &sbinfo->si_fhsm;
13762 + AuDebugOn(!fhsm);
13763 + fhsm->fhsm_bottom = bindex;
13766 +/* ---------------------------------------------------------------------- */
13768 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13770 + struct au_br_fhsm *bf;
13772 + bf = br->br_fhsm;
13773 + MtxMustLock(&bf->bf_lock);
13775 + return !bf->bf_readable
13776 + || time_after(jiffies,
13777 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13780 +/* ---------------------------------------------------------------------- */
13782 +static void au_fhsm_notify(struct super_block *sb, int val)
13784 + struct au_sbinfo *sbinfo;
13785 + struct au_fhsm *fhsm;
13787 + SiMustAnyLock(sb);
13789 + sbinfo = au_sbi(sb);
13790 + fhsm = &sbinfo->si_fhsm;
13791 + if (au_fhsm_pid(fhsm)
13792 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13793 + atomic_set(&fhsm->fhsm_readable, val);
13795 + wake_up(&fhsm->fhsm_wqh);
13799 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13800 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13803 + struct au_branch *br;
13804 + struct au_br_fhsm *bf;
13806 + br = au_sbr(sb, bindex);
13807 + AuDebugOn(au_br_rdonly(br));
13808 + bf = br->br_fhsm;
13812 + mutex_lock(&bf->bf_lock);
13814 + MtxMustLock(&bf->bf_lock);
13816 + /* sb->s_root for NFS is unreliable */
13817 + err = au_br_stfs(br, &bf->bf_stfs);
13818 + if (unlikely(err)) {
13819 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13823 + bf->bf_jiffy = jiffies;
13824 + bf->bf_readable = 1;
13826 + au_fhsm_notify(sb, /*val*/1);
13828 + *rstfs = bf->bf_stfs;
13832 + mutex_unlock(&bf->bf_lock);
13833 + au_fhsm_notify(sb, /*val*/1);
13838 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13841 + struct au_sbinfo *sbinfo;
13842 + struct au_fhsm *fhsm;
13843 + struct au_branch *br;
13844 + struct au_br_fhsm *bf;
13846 + AuDbg("b%d, force %d\n", bindex, force);
13847 + SiMustAnyLock(sb);
13849 + sbinfo = au_sbi(sb);
13850 + fhsm = &sbinfo->si_fhsm;
13851 + if (!au_ftest_si(sbinfo, FHSM)
13852 + || fhsm->fhsm_bottom == bindex)
13855 + br = au_sbr(sb, bindex);
13856 + bf = br->br_fhsm;
13858 + mutex_lock(&bf->bf_lock);
13860 + || au_fhsm_pid(fhsm)
13861 + || au_fhsm_test_jiffy(sbinfo, br))
13862 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13864 + mutex_unlock(&bf->bf_lock);
13867 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13869 + aufs_bindex_t bindex, bbot;
13870 + struct au_branch *br;
13872 + /* exclude the bottom */
13873 + bbot = au_fhsm_bottom(sb);
13874 + for (bindex = 0; bindex < bbot; bindex++) {
13875 + br = au_sbr(sb, bindex);
13876 + if (au_br_fhsm(br->br_perm))
13877 + au_fhsm_wrote(sb, bindex, force);
13881 +/* ---------------------------------------------------------------------- */
13883 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13886 + struct au_sbinfo *sbinfo;
13887 + struct au_fhsm *fhsm;
13890 + sbinfo = file->private_data;
13891 + fhsm = &sbinfo->si_fhsm;
13892 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13893 + if (atomic_read(&fhsm->fhsm_readable))
13894 + mask = EPOLLIN /* | EPOLLRDNORM */;
13897 + AuDbg("mask 0x%x\n", mask);
13901 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13902 + struct aufs_stfs *stfs, __s16 brid)
13906 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13908 + err = __put_user(brid, &stbr->brid);
13909 + if (unlikely(err))
13915 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13916 + struct aufs_stbr __user *stbr, size_t count)
13920 + aufs_bindex_t bindex, bbot;
13921 + struct au_branch *br;
13922 + struct au_br_fhsm *bf;
13924 + /* except the bottom branch */
13927 + bbot = au_fhsm_bottom(sb);
13928 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13929 + br = au_sbr(sb, bindex);
13930 + if (!au_br_fhsm(br->br_perm))
13933 + bf = br->br_fhsm;
13934 + mutex_lock(&bf->bf_lock);
13935 + if (bf->bf_readable) {
13937 + if (count >= sizeof(*stbr))
13938 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13941 + bf->bf_readable = 0;
13942 + count -= sizeof(*stbr);
13946 + mutex_unlock(&bf->bf_lock);
13949 + err = sizeof(*stbr) * nstbr;
13954 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13959 + aufs_bindex_t nfhsm, bindex, bbot;
13960 + struct au_sbinfo *sbinfo;
13961 + struct au_fhsm *fhsm;
13962 + struct au_branch *br;
13963 + struct super_block *sb;
13966 + sbinfo = file->private_data;
13967 + fhsm = &sbinfo->si_fhsm;
13969 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13970 + if (!atomic_read(&fhsm->fhsm_readable)) {
13971 + if (vfsub_file_flags(file) & O_NONBLOCK)
13974 + err = wait_event_interruptible_locked_irq
13976 + atomic_read(&fhsm->fhsm_readable));
13978 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13979 + if (unlikely(err))
13982 + /* sb may already be dead */
13983 + au_rw_read_lock(&sbinfo->si_rwsem);
13984 + readable = atomic_read(&fhsm->fhsm_readable);
13985 + if (readable > 0) {
13986 + sb = sbinfo->si_sb;
13988 + /* exclude the bottom branch */
13990 + bbot = au_fhsm_bottom(sb);
13991 + for (bindex = 0; bindex < bbot; bindex++) {
13992 + br = au_sbr(sb, bindex);
13993 + if (au_br_fhsm(br->br_perm))
13997 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13998 + atomic_set(&fhsm->fhsm_readable, 0);
13999 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14003 + au_rw_read_unlock(&sbinfo->si_rwsem);
14011 +static int au_fhsm_release(struct inode *inode, struct file *file)
14013 + struct au_sbinfo *sbinfo;
14014 + struct au_fhsm *fhsm;
14016 + /* sb may already be dead */
14017 + sbinfo = file->private_data;
14018 + fhsm = &sbinfo->si_fhsm;
14019 + spin_lock(&fhsm->fhsm_spin);
14020 + fhsm->fhsm_pid = 0;
14021 + spin_unlock(&fhsm->fhsm_spin);
14022 + kobject_put(&sbinfo->si_kobj);
14027 +static const struct file_operations au_fhsm_fops = {
14028 + .owner = THIS_MODULE,
14029 + .llseek = noop_llseek,
14030 + .read = au_fhsm_read,
14031 + .poll = au_fhsm_poll,
14032 + .release = au_fhsm_release
14035 +int au_fhsm_fd(struct super_block *sb, int oflags)
14038 + struct au_sbinfo *sbinfo;
14039 + struct au_fhsm *fhsm;
14042 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14046 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14050 + sbinfo = au_sbi(sb);
14051 + fhsm = &sbinfo->si_fhsm;
14052 + spin_lock(&fhsm->fhsm_spin);
14053 + if (!fhsm->fhsm_pid)
14054 + fhsm->fhsm_pid = current->pid;
14057 + spin_unlock(&fhsm->fhsm_spin);
14058 + if (unlikely(err))
14061 + oflags |= O_RDONLY;
14062 + /* oflags |= FMODE_NONOTIFY; */
14063 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14065 + if (unlikely(fd < 0))
14068 + /* succeed regardless 'fhsm' status */
14069 + kobject_get(&sbinfo->si_kobj);
14070 + si_noflush_read_lock(sb);
14071 + if (au_ftest_si(sbinfo, FHSM))
14072 + au_fhsm_wrote_all(sb, /*force*/0);
14073 + si_read_unlock(sb);
14074 + goto out; /* success */
14077 + spin_lock(&fhsm->fhsm_spin);
14078 + fhsm->fhsm_pid = 0;
14079 + spin_unlock(&fhsm->fhsm_spin);
14085 +/* ---------------------------------------------------------------------- */
14087 +int au_fhsm_br_alloc(struct au_branch *br)
14092 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14094 + au_br_fhsm_init(br->br_fhsm);
14101 +/* ---------------------------------------------------------------------- */
14103 +void au_fhsm_fin(struct super_block *sb)
14105 + au_fhsm_notify(sb, /*val*/-1);
14108 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14110 + struct au_fhsm *fhsm;
14112 + fhsm = &sbinfo->si_fhsm;
14113 + spin_lock_init(&fhsm->fhsm_spin);
14114 + init_waitqueue_head(&fhsm->fhsm_wqh);
14115 + atomic_set(&fhsm->fhsm_readable, 0);
14116 + fhsm->fhsm_expire
14117 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14118 + fhsm->fhsm_bottom = -1;
14121 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14123 + sbinfo->si_fhsm.fhsm_expire
14124 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14127 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14131 + if (!au_ftest_si(sbinfo, FHSM))
14134 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14135 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14136 + seq_printf(seq, ",fhsm_sec=%u", u);
14138 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14139 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14140 +++ linux/fs/aufs/file.c 2019-07-11 15:42:14.465571210 +0200
14142 +// SPDX-License-Identifier: GPL-2.0
14144 + * Copyright (C) 2005-2019 Junjiro R. Okajima
14146 + * This program, aufs is free software; you can redistribute it and/or modify
14147 + * it under the terms of the GNU General Public License as published by
14148 + * the Free Software Foundation; either version 2 of the License, or
14149 + * (at your option) any later version.
14151 + * This program is distributed in the hope that it will be useful,
14152 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14153 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14154 + * GNU General Public License for more details.
14156 + * You should have received a copy of the GNU General Public License
14157 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14161 + * handling file/dir, and address_space operation
14164 +#ifdef CONFIG_AUFS_DEBUG
14165 +#include <linux/migrate.h>
14167 +#include <linux/pagemap.h>
14170 +/* drop flags for writing */
14171 +unsigned int au_file_roflags(unsigned int flags)
14173 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14174 + flags |= O_RDONLY | O_NOATIME;
14178 +/* common functions to regular file and dir */
14179 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14180 + struct file *file, int force_wr)
14182 + struct file *h_file;
14183 + struct dentry *h_dentry;
14184 + struct inode *h_inode;
14185 + struct super_block *sb;
14186 + struct au_branch *br;
14187 + struct path h_path;
14190 + /* a race condition can happen between open and unlink/rmdir */
14191 + h_file = ERR_PTR(-ENOENT);
14192 + h_dentry = au_h_dptr(dentry, bindex);
14193 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14195 + h_inode = d_inode(h_dentry);
14196 + spin_lock(&h_dentry->d_lock);
14197 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14198 + /* || !d_inode(dentry)->i_nlink */
14200 + spin_unlock(&h_dentry->d_lock);
14201 + if (unlikely(err))
14204 + sb = dentry->d_sb;
14205 + br = au_sbr(sb, bindex);
14206 + err = au_br_test_oflag(flags, br);
14207 + h_file = ERR_PTR(err);
14208 + if (unlikely(err))
14211 + /* drop flags for writing */
14212 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14213 + if (force_wr && !(flags & O_WRONLY))
14215 + flags = au_file_roflags(flags);
14217 + h_file = ERR_PTR(-EROFS);
14218 + flags = au_file_roflags(flags);
14219 + if (unlikely(vfsub_native_ro(h_inode)
14220 + || IS_APPEND(h_inode)))
14222 + flags &= ~O_ACCMODE;
14223 + flags |= O_WRONLY;
14226 + flags &= ~O_CREAT;
14227 + au_lcnt_inc(&br->br_nfiles);
14228 + h_path.dentry = h_dentry;
14229 + h_path.mnt = au_br_mnt(br);
14230 + h_file = vfsub_dentry_open(&h_path, flags);
14231 + if (IS_ERR(h_file))
14234 + if (flags & __FMODE_EXEC) {
14235 + err = deny_write_access(h_file);
14236 + if (unlikely(err)) {
14238 + h_file = ERR_PTR(err);
14242 + fsnotify_open(h_file);
14243 + goto out; /* success */
14246 + au_lcnt_dec(&br->br_nfiles);
14251 +static int au_cmoo(struct dentry *dentry)
14253 + int err, cmoo, matched;
14254 + unsigned int udba;
14255 + struct path h_path;
14256 + struct au_pin pin;
14257 + struct au_cp_generic cpg = {
14258 + .dentry = dentry,
14263 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14265 + struct inode *delegated;
14266 + struct super_block *sb;
14267 + struct au_sbinfo *sbinfo;
14268 + struct au_fhsm *fhsm;
14270 + struct au_branch *br;
14271 + struct dentry *parent;
14272 + struct au_hinode *hdir;
14274 + DiMustWriteLock(dentry);
14275 + IiMustWriteLock(d_inode(dentry));
14278 + if (IS_ROOT(dentry))
14280 + cpg.bsrc = au_dbtop(dentry);
14284 + sb = dentry->d_sb;
14285 + sbinfo = au_sbi(sb);
14286 + fhsm = &sbinfo->si_fhsm;
14287 + pid = au_fhsm_pid(fhsm);
14290 + && (current->pid == pid
14291 + || rcu_dereference(current->real_parent)->pid == pid));
14292 + rcu_read_unlock();
14296 + br = au_sbr(sb, cpg.bsrc);
14297 + cmoo = au_br_cmoo(br->br_perm);
14300 + if (!d_is_reg(dentry))
14301 + cmoo &= AuBrAttr_COO_ALL;
14305 + parent = dget_parent(dentry);
14306 + di_write_lock_parent(parent);
14307 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14309 + if (unlikely(err < 0)) {
14310 + err = 0; /* there is no upper writable branch */
14313 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14315 + /* do not respect the coo attrib for the target branch */
14316 + err = au_cpup_dirs(dentry, cpg.bdst);
14317 + if (unlikely(err))
14320 + di_downgrade_lock(parent, AuLock_IR);
14321 + udba = au_opt_udba(sb);
14322 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14323 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14324 + if (unlikely(err))
14327 + err = au_sio_cpup_simple(&cpg);
14329 + if (unlikely(err))
14331 + if (!(cmoo & AuBrWAttr_MOO))
14332 + goto out_parent; /* success */
14334 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14335 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14336 + if (unlikely(err))
14339 + h_path.mnt = au_br_mnt(br);
14340 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14341 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14342 + delegated = NULL;
14343 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14345 + /* todo: keep h_dentry or not? */
14346 + if (unlikely(err == -EWOULDBLOCK)) {
14347 + pr_warn("cannot retry for NFSv4 delegation"
14348 + " for an internal unlink\n");
14351 + if (unlikely(err)) {
14352 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14356 + goto out_parent; /* success */
14359 + di_downgrade_lock(parent, AuLock_IR);
14361 + di_read_unlock(parent, AuLock_IR);
14368 +int au_do_open(struct file *file, struct au_do_open_args *args)
14370 + int err, aopen = args->aopen;
14371 + struct dentry *dentry;
14372 + struct au_finfo *finfo;
14375 + err = au_finfo_init(file, args->fidir);
14378 + err = au_finfo_init(file, args->fidir);
14381 + if (unlikely(err))
14384 + dentry = file->f_path.dentry;
14385 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14386 + di_write_lock_child(dentry);
14387 + err = au_cmoo(dentry);
14388 + di_downgrade_lock(dentry, AuLock_IR);
14391 + err = args->open(file, vfsub_file_flags(file), NULL);
14394 + err = args->open(file, vfsub_file_flags(file),
14399 + di_read_unlock(dentry, AuLock_IR);
14401 + finfo = au_fi(file);
14403 + finfo->fi_file = file;
14404 + au_hbl_add(&finfo->fi_hlist,
14405 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14408 + fi_write_unlock(file);
14411 + fi_write_unlock(file);
14414 + if (unlikely(err)) {
14415 + finfo->fi_hdir = NULL;
14416 + au_finfo_fin(file);
14424 +int au_reopen_nondir(struct file *file)
14427 + aufs_bindex_t btop;
14428 + struct dentry *dentry;
14429 + struct au_branch *br;
14430 + struct file *h_file, *h_file_tmp;
14432 + dentry = file->f_path.dentry;
14433 + btop = au_dbtop(dentry);
14434 + br = au_sbr(dentry->d_sb, btop);
14435 + h_file_tmp = NULL;
14436 + if (au_fbtop(file) == btop) {
14437 + h_file = au_hf_top(file);
14438 + if (file->f_mode == h_file->f_mode)
14439 + return 0; /* success */
14440 + h_file_tmp = h_file;
14441 + get_file(h_file_tmp);
14442 + au_lcnt_inc(&br->br_nfiles);
14443 + au_set_h_fptr(file, btop, NULL);
14445 + AuDebugOn(au_fi(file)->fi_hdir);
14448 + * file exists on both of rw and ro
14449 + * open --> dbtop and fbtop are both 0
14450 + * prepend a branch as rw, "rw" become ro
14452 + * delete the top branch, "rw" becomes rw again
14453 + * --> dbtop is 1, fbtop is still 0
14454 + * write --> fbtop is 0 but dbtop is 1
14456 + /* AuDebugOn(au_fbtop(file) < btop); */
14458 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14459 + file, /*force_wr*/0);
14460 + err = PTR_ERR(h_file);
14461 + if (IS_ERR(h_file)) {
14462 + if (h_file_tmp) {
14464 + au_set_h_fptr(file, btop, h_file_tmp);
14465 + h_file_tmp = NULL;
14467 + goto out; /* todo: close all? */
14471 + au_set_fbtop(file, btop);
14472 + au_set_h_fptr(file, btop, h_file);
14473 + au_update_figen(file);
14474 + /* todo: necessary? */
14475 + /* file->f_ra = h_file->f_ra; */
14478 + if (h_file_tmp) {
14479 + fput(h_file_tmp);
14480 + au_lcnt_dec(&br->br_nfiles);
14485 +/* ---------------------------------------------------------------------- */
14487 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14488 + struct dentry *hi_wh)
14491 + aufs_bindex_t btop;
14492 + struct au_dinfo *dinfo;
14493 + struct dentry *h_dentry;
14494 + struct au_hdentry *hdp;
14496 + dinfo = au_di(file->f_path.dentry);
14497 + AuRwMustWriteLock(&dinfo->di_rwsem);
14499 + btop = dinfo->di_btop;
14500 + dinfo->di_btop = btgt;
14501 + hdp = au_hdentry(dinfo, btgt);
14502 + h_dentry = hdp->hd_dentry;
14503 + hdp->hd_dentry = hi_wh;
14504 + err = au_reopen_nondir(file);
14505 + hdp->hd_dentry = h_dentry;
14506 + dinfo->di_btop = btop;
14511 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14512 + aufs_bindex_t bcpup, struct au_pin *pin)
14515 + struct inode *inode, *h_inode;
14516 + struct dentry *h_dentry, *hi_wh;
14517 + struct au_cp_generic cpg = {
14518 + .dentry = file->f_path.dentry,
14525 + au_update_dbtop(cpg.dentry);
14526 + inode = d_inode(cpg.dentry);
14528 + if (au_dbtop(cpg.dentry) <= bcpup
14529 + && au_dbbot(cpg.dentry) >= bcpup) {
14530 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14531 + if (h_dentry && d_is_positive(h_dentry))
14532 + h_inode = d_inode(h_dentry);
14534 + hi_wh = au_hi_wh(inode, bcpup);
14535 + if (!hi_wh && !h_inode)
14536 + err = au_sio_cpup_wh(&cpg, file);
14538 + /* already copied-up after unlink */
14539 + err = au_reopen_wh(file, bcpup, hi_wh);
14542 + && (inode->i_nlink > 1
14543 + || (inode->i_state & I_LINKABLE))
14544 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14545 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14551 + * prepare the @file for writing.
14553 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14556 + aufs_bindex_t dbtop;
14557 + struct dentry *parent;
14558 + struct inode *inode;
14559 + struct super_block *sb;
14560 + struct file *h_file;
14561 + struct au_cp_generic cpg = {
14562 + .dentry = file->f_path.dentry,
14567 + .flags = AuCpup_DTIME
14570 + sb = cpg.dentry->d_sb;
14571 + inode = d_inode(cpg.dentry);
14572 + cpg.bsrc = au_fbtop(file);
14573 + err = au_test_ro(sb, cpg.bsrc, inode);
14574 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14575 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14580 + /* need to cpup or reopen */
14581 + parent = dget_parent(cpg.dentry);
14582 + di_write_lock_parent(parent);
14583 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14585 + if (unlikely(err < 0))
14589 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14590 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14591 + if (unlikely(err))
14595 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14596 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14597 + if (unlikely(err))
14600 + dbtop = au_dbtop(cpg.dentry);
14601 + if (dbtop <= cpg.bdst)
14602 + cpg.bsrc = cpg.bdst;
14604 + if (dbtop <= cpg.bdst /* just reopen */
14605 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14607 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14608 + if (IS_ERR(h_file))
14609 + err = PTR_ERR(h_file);
14611 + di_downgrade_lock(parent, AuLock_IR);
14612 + if (dbtop > cpg.bdst)
14613 + err = au_sio_cpup_simple(&cpg);
14615 + err = au_reopen_nondir(file);
14616 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14618 + } else { /* copyup as wh and reopen */
14620 + * since writable hfsplus branch is not supported,
14621 + * h_open_pre/post() are unnecessary.
14623 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14624 + di_downgrade_lock(parent, AuLock_IR);
14628 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14629 + goto out_dput; /* success */
14635 + di_downgrade_lock(parent, AuLock_IR);
14637 + di_read_unlock(parent, AuLock_IR);
14644 +/* ---------------------------------------------------------------------- */
14646 +int au_do_flush(struct file *file, fl_owner_t id,
14647 + int (*flush)(struct file *file, fl_owner_t id))
14650 + struct super_block *sb;
14651 + struct inode *inode;
14653 + inode = file_inode(file);
14654 + sb = inode->i_sb;
14655 + si_noflush_read_lock(sb);
14656 + fi_read_lock(file);
14657 + ii_read_lock_child(inode);
14659 + err = flush(file, id);
14660 + au_cpup_attr_timesizes(inode);
14662 + ii_read_unlock(inode);
14663 + fi_read_unlock(file);
14664 + si_read_unlock(sb);
14668 +/* ---------------------------------------------------------------------- */
14670 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14673 + struct au_pin pin;
14674 + struct au_finfo *finfo;
14675 + struct dentry *parent, *hi_wh;
14676 + struct inode *inode;
14677 + struct super_block *sb;
14678 + struct au_cp_generic cpg = {
14679 + .dentry = file->f_path.dentry,
14684 + .flags = AuCpup_DTIME
14687 + FiMustWriteLock(file);
14690 + finfo = au_fi(file);
14691 + sb = cpg.dentry->d_sb;
14692 + inode = d_inode(cpg.dentry);
14693 + cpg.bdst = au_ibtop(inode);
14694 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14697 + parent = dget_parent(cpg.dentry);
14698 + if (au_test_ro(sb, cpg.bdst, inode)) {
14699 + di_read_lock_parent(parent, !AuLock_IR);
14700 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14702 + di_read_unlock(parent, !AuLock_IR);
14703 + if (unlikely(err < 0))
14708 + di_read_lock_parent(parent, AuLock_IR);
14709 + hi_wh = au_hi_wh(inode, cpg.bdst);
14710 + if (!S_ISDIR(inode->i_mode)
14711 + && au_opt_test(au_mntflags(sb), PLINK)
14712 + && au_plink_test(inode)
14713 + && !d_unhashed(cpg.dentry)
14714 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14715 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14716 + if (unlikely(err))
14719 + /* always superio. */
14720 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14721 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14723 + err = au_sio_cpup_simple(&cpg);
14726 + } else if (hi_wh) {
14727 + /* already copied-up after unlink */
14728 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14729 + *need_reopen = 0;
14733 + di_read_unlock(parent, AuLock_IR);
14740 +static void au_do_refresh_dir(struct file *file)
14742 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14743 + struct au_hfile *p, tmp, *q;
14744 + struct au_finfo *finfo;
14745 + struct super_block *sb;
14746 + struct au_fidir *fidir;
14748 + FiMustWriteLock(file);
14750 + sb = file->f_path.dentry->d_sb;
14751 + finfo = au_fi(file);
14752 + fidir = finfo->fi_hdir;
14753 + AuDebugOn(!fidir);
14754 + p = fidir->fd_hfile + finfo->fi_btop;
14755 + brid = p->hf_br->br_id;
14756 + bbot = fidir->fd_bbot;
14757 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14761 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14762 + if (new_bindex == bindex)
14764 + if (new_bindex < 0) {
14765 + au_set_h_fptr(file, bindex, NULL);
14769 + /* swap two lower inode, and loop again */
14770 + q = fidir->fd_hfile + new_bindex;
14774 + if (tmp.hf_file) {
14780 + p = fidir->fd_hfile;
14781 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14782 + bbot = au_sbbot(sb);
14783 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14784 + finfo->fi_btop++, p++)
14785 + if (p->hf_file) {
14786 + if (file_inode(p->hf_file))
14788 + au_hfput(p, /*execed*/0);
14791 + bbot = au_br_index(sb, brid);
14792 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14793 + finfo->fi_btop++, p++)
14795 + au_hfput(p, /*execed*/0);
14796 + bbot = au_sbbot(sb);
14799 + p = fidir->fd_hfile + bbot;
14800 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14801 + fidir->fd_bbot--, p--)
14802 + if (p->hf_file) {
14803 + if (file_inode(p->hf_file))
14805 + au_hfput(p, /*execed*/0);
14807 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14811 + * after branch manipulating, refresh the file.
14813 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14815 + int err, need_reopen, nbr;
14816 + aufs_bindex_t bbot, bindex;
14817 + struct dentry *dentry;
14818 + struct super_block *sb;
14819 + struct au_finfo *finfo;
14820 + struct au_hfile *hfile;
14822 + dentry = file->f_path.dentry;
14823 + sb = dentry->d_sb;
14824 + nbr = au_sbbot(sb) + 1;
14825 + finfo = au_fi(file);
14826 + if (!finfo->fi_hdir) {
14827 + hfile = &finfo->fi_htop;
14828 + AuDebugOn(!hfile->hf_file);
14829 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14830 + AuDebugOn(bindex < 0);
14831 + if (bindex != finfo->fi_btop)
14832 + au_set_fbtop(file, bindex);
14834 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14835 + if (unlikely(err))
14837 + au_do_refresh_dir(file);
14842 + if (!au_test_mmapped(file))
14843 + err = au_file_refresh_by_inode(file, &need_reopen);
14844 + if (finfo->fi_hdir)
14845 + /* harmless if err */
14846 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14847 + if (!err && need_reopen && !d_unlinked(dentry))
14848 + err = reopen(file);
14850 + au_update_figen(file);
14851 + goto out; /* success */
14854 + /* error, close all lower files */
14855 + if (finfo->fi_hdir) {
14856 + bbot = au_fbbot_dir(file);
14857 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14858 + au_set_h_fptr(file, bindex, NULL);
14865 +/* common function to regular file and dir */
14866 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14867 + int wlock, unsigned int fi_lsc)
14870 + unsigned int sigen, figen;
14871 + aufs_bindex_t btop;
14872 + unsigned char pseudo_link;
14873 + struct dentry *dentry;
14874 + struct inode *inode;
14877 + dentry = file->f_path.dentry;
14878 + inode = d_inode(dentry);
14879 + sigen = au_sigen(dentry->d_sb);
14880 + fi_write_lock_nested(file, fi_lsc);
14881 + figen = au_figen(file);
14883 + di_write_lock_child(dentry);
14885 + di_write_lock_child2(dentry);
14886 + btop = au_dbtop(dentry);
14887 + pseudo_link = (btop != au_ibtop(inode));
14888 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14890 + di_downgrade_lock(dentry, AuLock_IR);
14891 + fi_downgrade_lock(file);
14893 + goto out; /* success */
14896 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14897 + if (au_digen_test(dentry, sigen)) {
14898 + err = au_reval_dpath(dentry, sigen);
14899 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14903 + err = refresh_file(file, reopen);
14906 + di_downgrade_lock(dentry, AuLock_IR);
14907 + fi_downgrade_lock(file);
14910 + di_write_unlock(dentry);
14911 + fi_write_unlock(file);
14918 +/* ---------------------------------------------------------------------- */
14920 +/* cf. aufs_nopage() */
14921 +/* for madvise(2) */
14922 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14924 + unlock_page(page);
14928 +/* it will never be called, but necessary to support O_DIRECT */
14929 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14930 +{ BUG(); return 0; }
14932 +/* they will never be called. */
14933 +#ifdef CONFIG_AUFS_DEBUG
14934 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14935 + loff_t pos, unsigned len, unsigned flags,
14936 + struct page **pagep, void **fsdata)
14937 +{ AuUnsupport(); return 0; }
14938 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14939 + loff_t pos, unsigned len, unsigned copied,
14940 + struct page *page, void *fsdata)
14941 +{ AuUnsupport(); return 0; }
14942 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14943 +{ AuUnsupport(); return 0; }
14945 +static int aufs_set_page_dirty(struct page *page)
14946 +{ AuUnsupport(); return 0; }
14947 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14948 + unsigned int length)
14949 +{ AuUnsupport(); }
14950 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14951 +{ AuUnsupport(); return 0; }
14952 +#if 0 /* called by memory compaction regardless file */
14953 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14954 + struct page *page, enum migrate_mode mode)
14955 +{ AuUnsupport(); return 0; }
14957 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14958 +{ AuUnsupport(); return true; }
14959 +static void aufs_putback_page(struct page *page)
14960 +{ AuUnsupport(); }
14961 +static int aufs_launder_page(struct page *page)
14962 +{ AuUnsupport(); return 0; }
14963 +static int aufs_is_partially_uptodate(struct page *page,
14964 + unsigned long from,
14965 + unsigned long count)
14966 +{ AuUnsupport(); return 0; }
14967 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14969 +{ AuUnsupport(); }
14970 +static int aufs_error_remove_page(struct address_space *mapping,
14971 + struct page *page)
14972 +{ AuUnsupport(); return 0; }
14973 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14975 +{ AuUnsupport(); return 0; }
14976 +static void aufs_swap_deactivate(struct file *file)
14977 +{ AuUnsupport(); }
14978 +#endif /* CONFIG_AUFS_DEBUG */
14980 +const struct address_space_operations aufs_aop = {
14981 + .readpage = aufs_readpage,
14982 + .direct_IO = aufs_direct_IO,
14983 +#ifdef CONFIG_AUFS_DEBUG
14984 + .writepage = aufs_writepage,
14985 + /* no writepages, because of writepage */
14986 + .set_page_dirty = aufs_set_page_dirty,
14987 + /* no readpages, because of readpage */
14988 + .write_begin = aufs_write_begin,
14989 + .write_end = aufs_write_end,
14990 + /* no bmap, no block device */
14991 + .invalidatepage = aufs_invalidatepage,
14992 + .releasepage = aufs_releasepage,
14993 + /* is fallback_migrate_page ok? */
14994 + /* .migratepage = aufs_migratepage, */
14995 + .isolate_page = aufs_isolate_page,
14996 + .putback_page = aufs_putback_page,
14997 + .launder_page = aufs_launder_page,
14998 + .is_partially_uptodate = aufs_is_partially_uptodate,
14999 + .is_dirty_writeback = aufs_is_dirty_writeback,
15000 + .error_remove_page = aufs_error_remove_page,
15001 + .swap_activate = aufs_swap_activate,
15002 + .swap_deactivate = aufs_swap_deactivate
15003 +#endif /* CONFIG_AUFS_DEBUG */
15005 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15006 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15007 +++ linux/fs/aufs/file.h 2019-07-11 15:42:14.465571210 +0200
15009 +/* SPDX-License-Identifier: GPL-2.0 */
15011 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15013 + * This program, aufs is free software; you can redistribute it and/or modify
15014 + * it under the terms of the GNU General Public License as published by
15015 + * the Free Software Foundation; either version 2 of the License, or
15016 + * (at your option) any later version.
15018 + * This program is distributed in the hope that it will be useful,
15019 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15020 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15021 + * GNU General Public License for more details.
15023 + * You should have received a copy of the GNU General Public License
15024 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15028 + * file operations
15031 +#ifndef __AUFS_FILE_H__
15032 +#define __AUFS_FILE_H__
15036 +#include <linux/file.h>
15037 +#include <linux/fs.h>
15038 +#include <linux/mm_types.h>
15039 +#include <linux/poll.h>
15040 +#include "rwsem.h"
15044 + struct file *hf_file;
15045 + struct au_branch *hf_br;
15050 + aufs_bindex_t fd_bbot;
15051 + aufs_bindex_t fd_nent;
15052 + struct au_vdir *fd_vdir_cache;
15053 + struct au_hfile fd_hfile[];
15056 +static inline int au_fidir_sz(int nent)
15058 + AuDebugOn(nent < 0);
15059 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15063 + atomic_t fi_generation;
15065 + struct au_rwsem fi_rwsem;
15066 + aufs_bindex_t fi_btop;
15068 + /* do not union them */
15069 + struct { /* for non-dir */
15070 + struct au_hfile fi_htop;
15071 + atomic_t fi_mmapped;
15073 + struct au_fidir *fi_hdir; /* for dir only */
15075 + struct hlist_bl_node fi_hlist;
15076 + struct file *fi_file; /* very ugly */
15077 + struct rcu_head rcu;
15078 +} ____cacheline_aligned_in_smp;
15080 +/* ---------------------------------------------------------------------- */
15083 +extern const struct address_space_operations aufs_aop;
15084 +unsigned int au_file_roflags(unsigned int flags);
15085 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15086 + struct file *file, int force_wr);
15087 +struct au_do_open_args {
15089 + int (*open)(struct file *file, int flags,
15090 + struct file *h_file);
15091 + struct au_fidir *fidir;
15092 + struct file *h_file;
15094 +int au_do_open(struct file *file, struct au_do_open_args *args);
15095 +int au_reopen_nondir(struct file *file);
15097 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15098 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15099 + int wlock, unsigned int fi_lsc);
15100 +int au_do_flush(struct file *file, fl_owner_t id,
15101 + int (*flush)(struct file *file, fl_owner_t id));
15104 +#ifdef CONFIG_AUFS_POLL
15105 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15108 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15110 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15112 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15113 + struct file *h_file);
15115 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15116 + aufs_bindex_t bindex, int force_wr)
15117 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15118 + struct file *h_file);
15122 +extern const struct file_operations aufs_file_fop;
15123 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15124 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15125 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15128 +void au_hfput(struct au_hfile *hf, int execed);
15129 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15130 + struct file *h_file);
15132 +void au_update_figen(struct file *file);
15133 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15134 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15136 +void au_fi_init_once(void *_fi);
15137 +void au_finfo_fin(struct file *file);
15138 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15141 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15142 +#ifdef CONFIG_COMPAT
15143 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15144 + unsigned long arg);
15145 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15146 + unsigned long arg);
15149 +/* ---------------------------------------------------------------------- */
15151 +static inline struct au_finfo *au_fi(struct file *file)
15153 + return file->private_data;
15156 +/* ---------------------------------------------------------------------- */
15158 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15159 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15160 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15161 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15163 +#define fi_read_trylock_nested(f) \
15164 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15165 +#define fi_write_trylock_nested(f) \
15166 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15169 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15170 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15171 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15173 +/* lock subclass for finfo */
15179 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15181 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15184 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15186 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15190 + * fi_read_lock_1, fi_write_lock_1,
15191 + * fi_read_lock_2, fi_write_lock_2
15193 +#define AuReadLockFunc(name) \
15194 +static inline void fi_read_lock_##name(struct file *f) \
15195 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15197 +#define AuWriteLockFunc(name) \
15198 +static inline void fi_write_lock_##name(struct file *f) \
15199 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15201 +#define AuRWLockFuncs(name) \
15202 + AuReadLockFunc(name) \
15203 + AuWriteLockFunc(name)
15208 +#undef AuReadLockFunc
15209 +#undef AuWriteLockFunc
15210 +#undef AuRWLockFuncs
15212 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15213 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15214 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15216 +/* ---------------------------------------------------------------------- */
15218 +/* todo: hard/soft set? */
15219 +static inline aufs_bindex_t au_fbtop(struct file *file)
15221 + FiMustAnyLock(file);
15222 + return au_fi(file)->fi_btop;
15225 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15227 + FiMustAnyLock(file);
15228 + AuDebugOn(!au_fi(file)->fi_hdir);
15229 + return au_fi(file)->fi_hdir->fd_bbot;
15232 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15234 + FiMustAnyLock(file);
15235 + AuDebugOn(!au_fi(file)->fi_hdir);
15236 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15239 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15241 + FiMustWriteLock(file);
15242 + au_fi(file)->fi_btop = bindex;
15245 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15247 + FiMustWriteLock(file);
15248 + AuDebugOn(!au_fi(file)->fi_hdir);
15249 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15252 +static inline void au_set_fvdir_cache(struct file *file,
15253 + struct au_vdir *vdir_cache)
15255 + FiMustWriteLock(file);
15256 + AuDebugOn(!au_fi(file)->fi_hdir);
15257 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15260 +static inline struct file *au_hf_top(struct file *file)
15262 + FiMustAnyLock(file);
15263 + AuDebugOn(au_fi(file)->fi_hdir);
15264 + return au_fi(file)->fi_htop.hf_file;
15267 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15269 + FiMustAnyLock(file);
15270 + AuDebugOn(!au_fi(file)->fi_hdir);
15271 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15274 +/* todo: memory barrier? */
15275 +static inline unsigned int au_figen(struct file *f)
15277 + return atomic_read(&au_fi(f)->fi_generation);
15280 +static inline void au_set_mmapped(struct file *f)
15282 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15284 + pr_warn("fi_mmapped wrapped around\n");
15285 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15289 +static inline void au_unset_mmapped(struct file *f)
15291 + atomic_dec(&au_fi(f)->fi_mmapped);
15294 +static inline int au_test_mmapped(struct file *f)
15296 + return atomic_read(&au_fi(f)->fi_mmapped);
15299 +/* customize vma->vm_file */
15301 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15302 + struct file *file)
15306 + f = vma->vm_file;
15308 + vma->vm_file = file;
15313 +#define AuDbgVmRegion(file, vma) do {} while (0)
15315 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15316 + struct file *file)
15318 + au_do_vm_file_reset(vma, file);
15321 +#define AuDbgVmRegion(file, vma) \
15322 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15324 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15325 + struct file *file)
15329 + au_do_vm_file_reset(vma, file);
15330 + f = vma->vm_region->vm_file;
15332 + vma->vm_region->vm_file = file;
15335 +#endif /* CONFIG_MMU */
15337 +/* handle vma->vm_prfile */
15338 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15339 + struct file *file)
15342 + vma->vm_prfile = file;
15343 +#ifndef CONFIG_MMU
15345 + vma->vm_region->vm_prfile = file;
15349 +#endif /* __KERNEL__ */
15350 +#endif /* __AUFS_FILE_H__ */
15351 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15352 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15353 +++ linux/fs/aufs/finfo.c 2019-07-11 15:42:14.465571210 +0200
15355 +// SPDX-License-Identifier: GPL-2.0
15357 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15359 + * This program, aufs is free software; you can redistribute it and/or modify
15360 + * it under the terms of the GNU General Public License as published by
15361 + * the Free Software Foundation; either version 2 of the License, or
15362 + * (at your option) any later version.
15364 + * This program is distributed in the hope that it will be useful,
15365 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15366 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15367 + * GNU General Public License for more details.
15369 + * You should have received a copy of the GNU General Public License
15370 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15374 + * file private data
15379 +void au_hfput(struct au_hfile *hf, int execed)
15382 + allow_write_access(hf->hf_file);
15383 + fput(hf->hf_file);
15384 + hf->hf_file = NULL;
15385 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15386 + hf->hf_br = NULL;
15389 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15391 + struct au_finfo *finfo = au_fi(file);
15392 + struct au_hfile *hf;
15393 + struct au_fidir *fidir;
15395 + fidir = finfo->fi_hdir;
15397 + AuDebugOn(finfo->fi_btop != bindex);
15398 + hf = &finfo->fi_htop;
15400 + hf = fidir->fd_hfile + bindex;
15402 + if (hf && hf->hf_file)
15403 + au_hfput(hf, vfsub_file_execed(file));
15405 + FiMustWriteLock(file);
15406 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15407 + hf->hf_file = val;
15408 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15412 +void au_update_figen(struct file *file)
15414 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15415 + /* smp_mb(); */ /* atomic_set */
15418 +/* ---------------------------------------------------------------------- */
15420 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15422 + struct au_fidir *fidir;
15425 + nbr = au_sbbot(sb) + 1;
15427 + nbr = 2; /* initial allocate for 2 branches */
15428 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15430 + fidir->fd_bbot = -1;
15431 + fidir->fd_nent = nbr;
15437 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15440 + struct au_fidir *fidir, *p;
15442 + AuRwMustWriteLock(&finfo->fi_rwsem);
15443 + fidir = finfo->fi_hdir;
15444 + AuDebugOn(!fidir);
15447 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15448 + GFP_NOFS, may_shrink);
15450 + p->fd_nent = nbr;
15451 + finfo->fi_hdir = p;
15458 +/* ---------------------------------------------------------------------- */
15460 +void au_finfo_fin(struct file *file)
15462 + struct au_finfo *finfo;
15464 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15466 + finfo = au_fi(file);
15467 + AuDebugOn(finfo->fi_hdir);
15468 + AuRwDestroy(&finfo->fi_rwsem);
15469 + au_cache_free_finfo(finfo);
15472 +void au_fi_init_once(void *_finfo)
15474 + struct au_finfo *finfo = _finfo;
15476 + au_rw_init(&finfo->fi_rwsem);
15479 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15482 + struct au_finfo *finfo;
15483 + struct dentry *dentry;
15486 + dentry = file->f_path.dentry;
15487 + finfo = au_cache_alloc_finfo();
15488 + if (unlikely(!finfo))
15492 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15493 + au_rw_write_lock(&finfo->fi_rwsem);
15494 + finfo->fi_btop = -1;
15495 + finfo->fi_hdir = fidir;
15496 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15497 + /* smp_mb(); */ /* atomic_set */
15499 + file->private_data = finfo;
15504 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15505 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15506 +++ linux/fs/aufs/f_op.c 2019-07-11 15:42:14.465571210 +0200
15508 +// SPDX-License-Identifier: GPL-2.0
15510 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15512 + * This program, aufs is free software; you can redistribute it and/or modify
15513 + * it under the terms of the GNU General Public License as published by
15514 + * the Free Software Foundation; either version 2 of the License, or
15515 + * (at your option) any later version.
15517 + * This program is distributed in the hope that it will be useful,
15518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15520 + * GNU General Public License for more details.
15522 + * You should have received a copy of the GNU General Public License
15523 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15527 + * file and vm operations
15530 +#include <linux/aio.h>
15531 +#include <linux/fs_stack.h>
15532 +#include <linux/mman.h>
15533 +#include <linux/security.h>
15536 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15539 + aufs_bindex_t bindex;
15540 + struct dentry *dentry, *h_dentry;
15541 + struct au_finfo *finfo;
15542 + struct inode *h_inode;
15544 + FiMustWriteLock(file);
15547 + dentry = file->f_path.dentry;
15548 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15549 + finfo = au_fi(file);
15550 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15551 + atomic_set(&finfo->fi_mmapped, 0);
15552 + bindex = au_dbtop(dentry);
15554 + h_dentry = au_h_dptr(dentry, bindex);
15555 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15556 + if (unlikely(err))
15558 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15559 + if (IS_ERR(h_file)) {
15560 + err = PTR_ERR(h_file);
15564 + h_dentry = h_file->f_path.dentry;
15565 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15566 + if (unlikely(err))
15568 + /* br ref is already inc-ed */
15571 + if ((flags & __O_TMPFILE)
15572 + && !(flags & O_EXCL)) {
15573 + h_inode = file_inode(h_file);
15574 + spin_lock(&h_inode->i_lock);
15575 + h_inode->i_state |= I_LINKABLE;
15576 + spin_unlock(&h_inode->i_lock);
15578 + au_set_fbtop(file, bindex);
15579 + au_set_h_fptr(file, bindex, h_file);
15580 + au_update_figen(file);
15581 + /* todo: necessary? */
15582 + /* file->f_ra = h_file->f_ra; */
15588 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15589 + struct file *file)
15592 + struct super_block *sb;
15593 + struct au_do_open_args args = {
15594 + .open = au_do_open_nondir
15597 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15598 + file, vfsub_file_flags(file), file->f_mode);
15600 + sb = file->f_path.dentry->d_sb;
15601 + si_read_lock(sb, AuLock_FLUSH);
15602 + err = au_do_open(file, &args);
15603 + si_read_unlock(sb);
15607 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15609 + struct au_finfo *finfo;
15610 + aufs_bindex_t bindex;
15612 + finfo = au_fi(file);
15613 + au_hbl_del(&finfo->fi_hlist,
15614 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15615 + bindex = finfo->fi_btop;
15617 + au_set_h_fptr(file, bindex, NULL);
15619 + au_finfo_fin(file);
15623 +/* ---------------------------------------------------------------------- */
15625 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15628 + struct file *h_file;
15631 + h_file = au_hf_top(file);
15633 + err = vfsub_flush(h_file, id);
15637 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15639 + return au_do_flush(file, id, au_do_flush_nondir);
15642 +/* ---------------------------------------------------------------------- */
15644 + * read and write functions acquire [fdi]_rwsem once, but release before
15645 + * mmap_sem. This is because to stop a race condition between mmap(2).
15646 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15647 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15648 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15651 +/* Callers should call au_read_post() or fput() in the end */
15652 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15654 + struct file *h_file;
15657 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15659 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15660 + h_file = au_hf_top(file);
15661 + get_file(h_file);
15663 + fi_read_unlock(file);
15665 + h_file = ERR_PTR(err);
15670 +static void au_read_post(struct inode *inode, struct file *h_file)
15672 + /* update without lock, I don't think it a problem */
15673 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15677 +struct au_write_pre {
15679 + unsigned int lsc;
15683 + aufs_bindex_t btop;
15687 + * return with iinfo is write-locked
15688 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15691 +static struct file *au_write_pre(struct file *file, int do_ready,
15692 + struct au_write_pre *wpre)
15694 + struct file *h_file;
15695 + struct dentry *dentry;
15697 + unsigned int lsc;
15698 + struct au_pin pin;
15703 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15704 + h_file = ERR_PTR(err);
15705 + if (unlikely(err))
15708 + dentry = file->f_path.dentry;
15710 + err = au_ready_to_write(file, -1, &pin);
15711 + if (unlikely(err)) {
15712 + h_file = ERR_PTR(err);
15713 + di_write_unlock(dentry);
15718 + di_downgrade_lock(dentry, /*flags*/0);
15720 + wpre->btop = au_fbtop(file);
15721 + h_file = au_hf_top(file);
15722 + get_file(h_file);
15724 + wpre->blks = file_inode(h_file)->i_blocks;
15727 + di_read_unlock(dentry, /*flags*/0);
15730 + fi_write_unlock(file);
15735 +static void au_write_post(struct inode *inode, struct file *h_file,
15736 + struct au_write_pre *wpre, ssize_t written)
15738 + struct inode *h_inode;
15740 + au_cpup_attr_timesizes(inode);
15741 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15742 + h_inode = file_inode(h_file);
15743 + inode->i_mode = h_inode->i_mode;
15744 + ii_write_unlock(inode);
15745 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15747 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15748 + /*force*/h_inode->i_blocks > wpre->blks);
15752 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15756 + struct inode *inode;
15757 + struct file *h_file;
15758 + struct super_block *sb;
15760 + inode = file_inode(file);
15761 + sb = inode->i_sb;
15762 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15764 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15765 + err = PTR_ERR(h_file);
15766 + if (IS_ERR(h_file))
15769 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15770 + err = vfsub_read_u(h_file, buf, count, ppos);
15771 + /* todo: necessary? */
15772 + /* file->f_ra = h_file->f_ra; */
15773 + au_read_post(inode, h_file);
15776 + si_read_unlock(sb);
15781 + * todo: very ugly
15782 + * it locks both of i_mutex and si_rwsem for read in safe.
15783 + * if the plink maintenance mode continues forever (that is the problem),
15784 + * may loop forever.
15786 +static void au_mtx_and_read_lock(struct inode *inode)
15789 + struct super_block *sb = inode->i_sb;
15792 + inode_lock(inode);
15793 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15796 + inode_unlock(inode);
15797 + si_read_lock(sb, AuLock_NOPLMW);
15798 + si_read_unlock(sb);
15802 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15803 + size_t count, loff_t *ppos)
15806 + struct au_write_pre wpre;
15807 + struct inode *inode;
15808 + struct file *h_file;
15809 + char __user *buf = (char __user *)ubuf;
15811 + inode = file_inode(file);
15812 + au_mtx_and_read_lock(inode);
15815 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15816 + err = PTR_ERR(h_file);
15817 + if (IS_ERR(h_file))
15820 + err = vfsub_write_u(h_file, buf, count, ppos);
15821 + au_write_post(inode, h_file, &wpre, err);
15824 + si_read_unlock(inode->i_sb);
15825 + inode_unlock(inode);
15829 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15830 + struct iov_iter *iov_iter)
15833 + struct file *file;
15834 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15836 + err = security_file_permission(h_file, rw);
15837 + if (unlikely(err))
15842 + if (rw == MAY_READ)
15843 + iter = h_file->f_op->read_iter;
15844 + else if (rw == MAY_WRITE)
15845 + iter = h_file->f_op->write_iter;
15847 + file = kio->ki_filp;
15848 + kio->ki_filp = h_file;
15851 + err = iter(kio, iov_iter);
15854 + /* currently there is no such fs */
15856 + kio->ki_filp = file;
15862 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15865 + struct file *file, *h_file;
15866 + struct inode *inode;
15867 + struct super_block *sb;
15869 + file = kio->ki_filp;
15870 + inode = file_inode(file);
15871 + sb = inode->i_sb;
15872 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15874 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15875 + err = PTR_ERR(h_file);
15876 + if (IS_ERR(h_file))
15879 + if (au_test_loopback_kthread()) {
15880 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15881 + if (file->f_mapping != h_file->f_mapping) {
15882 + file->f_mapping = h_file->f_mapping;
15883 + smp_mb(); /* unnecessary? */
15886 + fi_read_unlock(file);
15888 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15889 + /* todo: necessary? */
15890 + /* file->f_ra = h_file->f_ra; */
15891 + au_read_post(inode, h_file);
15894 + si_read_unlock(sb);
15898 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15901 + struct au_write_pre wpre;
15902 + struct inode *inode;
15903 + struct file *file, *h_file;
15905 + file = kio->ki_filp;
15906 + inode = file_inode(file);
15907 + au_mtx_and_read_lock(inode);
15910 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15911 + err = PTR_ERR(h_file);
15912 + if (IS_ERR(h_file))
15915 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15916 + au_write_post(inode, h_file, &wpre, err);
15919 + si_read_unlock(inode->i_sb);
15920 + inode_unlock(inode);
15924 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15925 + struct pipe_inode_info *pipe, size_t len,
15926 + unsigned int flags)
15929 + struct file *h_file;
15930 + struct inode *inode;
15931 + struct super_block *sb;
15933 + inode = file_inode(file);
15934 + sb = inode->i_sb;
15935 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15937 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15938 + err = PTR_ERR(h_file);
15939 + if (IS_ERR(h_file))
15942 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15943 + /* todo: necessary? */
15944 + /* file->f_ra = h_file->f_ra; */
15945 + au_read_post(inode, h_file);
15948 + si_read_unlock(sb);
15953 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15954 + size_t len, unsigned int flags)
15957 + struct au_write_pre wpre;
15958 + struct inode *inode;
15959 + struct file *h_file;
15961 + inode = file_inode(file);
15962 + au_mtx_and_read_lock(inode);
15965 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15966 + err = PTR_ERR(h_file);
15967 + if (IS_ERR(h_file))
15970 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15971 + au_write_post(inode, h_file, &wpre, err);
15974 + si_read_unlock(inode->i_sb);
15975 + inode_unlock(inode);
15979 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15983 + struct au_write_pre wpre;
15984 + struct inode *inode;
15985 + struct file *h_file;
15987 + inode = file_inode(file);
15988 + au_mtx_and_read_lock(inode);
15991 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15992 + err = PTR_ERR(h_file);
15993 + if (IS_ERR(h_file))
15997 + err = vfs_fallocate(h_file, mode, offset, len);
15999 + au_write_post(inode, h_file, &wpre, /*written*/1);
16002 + si_read_unlock(inode->i_sb);
16003 + inode_unlock(inode);
16007 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16008 + struct file *dst, loff_t dst_pos,
16009 + size_t len, unsigned int flags)
16012 + struct au_write_pre wpre;
16013 + enum { SRC, DST };
16015 + struct inode *inode;
16016 + struct file *h_file;
16017 + struct super_block *h_sb;
16019 +#define a_src a[SRC]
16020 +#define a_dst a[DST]
16023 + a_src.inode = file_inode(src);
16024 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16026 + a_dst.inode = file_inode(dst);
16027 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16030 + au_mtx_and_read_lock(a_dst.inode);
16032 + * in order to match the order in di_write_lock2_{child,parent}(),
16033 + * use f_path.dentry for this comparison.
16035 + if (src->f_path.dentry < dst->f_path.dentry) {
16036 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16037 + err = PTR_ERR(a_src.h_file);
16038 + if (IS_ERR(a_src.h_file))
16041 + wpre.lsc = AuLsc_FI_2;
16042 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16043 + err = PTR_ERR(a_dst.h_file);
16044 + if (IS_ERR(a_dst.h_file)) {
16045 + au_read_post(a_src.inode, a_src.h_file);
16049 + wpre.lsc = AuLsc_FI_1;
16050 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16051 + err = PTR_ERR(a_dst.h_file);
16052 + if (IS_ERR(a_dst.h_file))
16055 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16056 + err = PTR_ERR(a_src.h_file);
16057 + if (IS_ERR(a_src.h_file)) {
16058 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16065 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16066 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16067 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16073 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16074 + dst_pos, len, flags);
16077 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16078 + fi_read_unlock(src);
16079 + au_read_post(a_src.inode, a_src.h_file);
16081 + si_read_unlock(a_dst.inode->i_sb);
16082 + inode_unlock(a_dst.inode);
16089 +/* ---------------------------------------------------------------------- */
16092 + * The locking order around current->mmap_sem.
16093 + * - in most and regular cases
16094 + * file I/O syscall -- aufs_read() or something
16095 + * -- si_rwsem for read -- mmap_sem
16096 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16098 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16099 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16100 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16101 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16102 + * It means that when aufs acquires si_rwsem for write, the process should never
16103 + * acquire mmap_sem.
16105 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16106 + * problem either since any directory is not able to be mmap-ed.
16107 + * The similar scenario is applied to aufs_readlink() too.
16110 +#if 0 /* stop calling security_file_mmap() */
16111 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16112 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16114 +static unsigned long au_arch_prot_conv(unsigned long flags)
16116 + /* currently ppc64 only */
16117 +#ifdef CONFIG_PPC64
16118 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16119 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16120 + return AuConv_VM_PROT(flags, SAO);
16122 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16127 +static unsigned long au_prot_conv(unsigned long flags)
16129 + return AuConv_VM_PROT(flags, READ)
16130 + | AuConv_VM_PROT(flags, WRITE)
16131 + | AuConv_VM_PROT(flags, EXEC)
16132 + | au_arch_prot_conv(flags);
16135 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16136 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16138 +static unsigned long au_flag_conv(unsigned long flags)
16140 + return AuConv_VM_MAP(flags, GROWSDOWN)
16141 + | AuConv_VM_MAP(flags, DENYWRITE)
16142 + | AuConv_VM_MAP(flags, LOCKED);
16146 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16149 + const unsigned char wlock
16150 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16151 + struct super_block *sb;
16152 + struct file *h_file;
16153 + struct inode *inode;
16155 + AuDbgVmRegion(file, vma);
16157 + inode = file_inode(file);
16158 + sb = inode->i_sb;
16160 + si_read_lock(sb, AuLock_NOPLMW);
16162 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16164 + err = PTR_ERR(h_file);
16165 + if (IS_ERR(h_file))
16169 + au_set_mmapped(file);
16170 + au_vm_file_reset(vma, h_file);
16172 + * we cannot call security_mmap_file() here since it may acquire
16173 + * mmap_sem or i_mutex.
16175 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16176 + * au_flag_conv(vma->vm_flags));
16179 + err = call_mmap(h_file, vma);
16181 + au_vm_prfile_set(vma, file);
16182 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16183 + goto out_fput; /* success */
16185 + au_unset_mmapped(file);
16186 + au_vm_file_reset(vma, file);
16190 + ii_write_unlock(inode);
16195 + si_read_unlock(sb);
16201 +/* ---------------------------------------------------------------------- */
16203 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16207 + struct au_write_pre wpre;
16208 + struct inode *inode;
16209 + struct file *h_file;
16211 + err = 0; /* -EBADF; */ /* posix? */
16212 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16215 + inode = file_inode(file);
16216 + au_mtx_and_read_lock(inode);
16219 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16220 + err = PTR_ERR(h_file);
16221 + if (IS_ERR(h_file))
16224 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16225 + au_write_post(inode, h_file, &wpre, /*written*/0);
16228 + si_read_unlock(inode->i_sb);
16229 + inode_unlock(inode);
16234 +static int aufs_fasync(int fd, struct file *file, int flag)
16237 + struct file *h_file;
16238 + struct super_block *sb;
16240 + sb = file->f_path.dentry->d_sb;
16241 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16243 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16244 + err = PTR_ERR(h_file);
16245 + if (IS_ERR(h_file))
16248 + if (h_file->f_op->fasync)
16249 + err = h_file->f_op->fasync(fd, h_file, flag);
16250 + fput(h_file); /* instead of au_read_post() */
16253 + si_read_unlock(sb);
16257 +static int aufs_setfl(struct file *file, unsigned long arg)
16260 + struct file *h_file;
16261 + struct super_block *sb;
16263 + sb = file->f_path.dentry->d_sb;
16264 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16266 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16267 + err = PTR_ERR(h_file);
16268 + if (IS_ERR(h_file))
16271 + /* stop calling h_file->fasync */
16272 + arg |= vfsub_file_flags(file) & FASYNC;
16273 + err = setfl(/*unused fd*/-1, h_file, arg);
16274 + fput(h_file); /* instead of au_read_post() */
16277 + si_read_unlock(sb);
16281 +/* ---------------------------------------------------------------------- */
16283 +/* no one supports this operation, currently */
16285 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16286 + size_t len, loff_t *pos, int more)
16291 +/* ---------------------------------------------------------------------- */
16293 +const struct file_operations aufs_file_fop = {
16294 + .owner = THIS_MODULE,
16296 + .llseek = default_llseek,
16298 + .read = aufs_read,
16299 + .write = aufs_write,
16300 + .read_iter = aufs_read_iter,
16301 + .write_iter = aufs_write_iter,
16303 +#ifdef CONFIG_AUFS_POLL
16304 + .poll = aufs_poll,
16306 + .unlocked_ioctl = aufs_ioctl_nondir,
16307 +#ifdef CONFIG_COMPAT
16308 + .compat_ioctl = aufs_compat_ioctl_nondir,
16310 + .mmap = aufs_mmap,
16311 + .open = aufs_open_nondir,
16312 + .flush = aufs_flush_nondir,
16313 + .release = aufs_release_nondir,
16314 + .fsync = aufs_fsync_nondir,
16315 + .fasync = aufs_fasync,
16316 + /* .sendpage = aufs_sendpage, */
16317 + .setfl = aufs_setfl,
16318 + .splice_write = aufs_splice_write,
16319 + .splice_read = aufs_splice_read,
16321 + .aio_splice_write = aufs_aio_splice_write,
16322 + .aio_splice_read = aufs_aio_splice_read,
16324 + .fallocate = aufs_fallocate,
16325 + .copy_file_range = aufs_copy_file_range
16327 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16328 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16329 +++ linux/fs/aufs/fstype.h 2019-07-11 15:42:14.465571210 +0200
16331 +/* SPDX-License-Identifier: GPL-2.0 */
16333 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16335 + * This program, aufs is free software; you can redistribute it and/or modify
16336 + * it under the terms of the GNU General Public License as published by
16337 + * the Free Software Foundation; either version 2 of the License, or
16338 + * (at your option) any later version.
16340 + * This program is distributed in the hope that it will be useful,
16341 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16342 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16343 + * GNU General Public License for more details.
16345 + * You should have received a copy of the GNU General Public License
16346 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16350 + * judging filesystem type
16353 +#ifndef __AUFS_FSTYPE_H__
16354 +#define __AUFS_FSTYPE_H__
16358 +#include <linux/fs.h>
16359 +#include <linux/magic.h>
16360 +#include <linux/nfs_fs.h>
16361 +#include <linux/romfs_fs.h>
16363 +static inline int au_test_aufs(struct super_block *sb)
16365 + return sb->s_magic == AUFS_SUPER_MAGIC;
16368 +static inline const char *au_sbtype(struct super_block *sb)
16370 + return sb->s_type->name;
16373 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16375 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16376 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16382 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16384 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16385 + return sb->s_magic == ROMFS_MAGIC;
16391 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16393 +#if IS_ENABLED(CONFIG_CRAMFS)
16394 + return sb->s_magic == CRAMFS_MAGIC;
16399 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16401 +#if IS_ENABLED(CONFIG_NFS_FS)
16402 + return sb->s_magic == NFS_SUPER_MAGIC;
16408 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16410 +#if IS_ENABLED(CONFIG_FUSE_FS)
16411 + return sb->s_magic == FUSE_SUPER_MAGIC;
16417 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16419 +#if IS_ENABLED(CONFIG_XFS_FS)
16420 + return sb->s_magic == XFS_SB_MAGIC;
16426 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16428 +#ifdef CONFIG_TMPFS
16429 + return sb->s_magic == TMPFS_MAGIC;
16435 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16437 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16438 + return !strcmp(au_sbtype(sb), "ecryptfs");
16444 +static inline int au_test_ramfs(struct super_block *sb)
16446 + return sb->s_magic == RAMFS_MAGIC;
16449 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16451 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16452 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16458 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16460 +#ifdef CONFIG_PROC_FS
16461 + return sb->s_magic == PROC_SUPER_MAGIC;
16467 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16469 +#ifdef CONFIG_SYSFS
16470 + return sb->s_magic == SYSFS_MAGIC;
16476 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16478 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16479 + return sb->s_magic == CONFIGFS_MAGIC;
16485 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16487 +#if IS_ENABLED(CONFIG_MINIX_FS)
16488 + return sb->s_magic == MINIX3_SUPER_MAGIC
16489 + || sb->s_magic == MINIX2_SUPER_MAGIC
16490 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16491 + || sb->s_magic == MINIX_SUPER_MAGIC
16492 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16498 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16500 +#if IS_ENABLED(CONFIG_FAT_FS)
16501 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16507 +static inline int au_test_msdos(struct super_block *sb)
16509 + return au_test_fat(sb);
16512 +static inline int au_test_vfat(struct super_block *sb)
16514 + return au_test_fat(sb);
16517 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16519 +#ifdef CONFIG_SECURITYFS
16520 + return sb->s_magic == SECURITYFS_MAGIC;
16526 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16528 +#if IS_ENABLED(CONFIG_SQUASHFS)
16529 + return sb->s_magic == SQUASHFS_MAGIC;
16535 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16537 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16538 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16544 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16546 +#if IS_ENABLED(CONFIG_XENFS)
16547 + return sb->s_magic == XENFS_SUPER_MAGIC;
16553 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16555 +#ifdef CONFIG_DEBUG_FS
16556 + return sb->s_magic == DEBUGFS_MAGIC;
16562 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16564 +#if IS_ENABLED(CONFIG_NILFS)
16565 + return sb->s_magic == NILFS_SUPER_MAGIC;
16571 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16573 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16574 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16580 +/* ---------------------------------------------------------------------- */
16582 + * they can't be an aufs branch.
16584 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16587 +#ifndef CONFIG_AUFS_BR_RAMFS
16588 + au_test_ramfs(sb) ||
16590 + au_test_procfs(sb)
16591 + || au_test_sysfs(sb)
16592 + || au_test_configfs(sb)
16593 + || au_test_debugfs(sb)
16594 + || au_test_securityfs(sb)
16595 + || au_test_xenfs(sb)
16596 + || au_test_ecryptfs(sb)
16597 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16598 + || au_test_aufs(sb); /* will be supported in next version */
16601 +static inline int au_test_fs_remote(struct super_block *sb)
16603 + return !au_test_tmpfs(sb)
16604 +#ifdef CONFIG_AUFS_BR_RAMFS
16605 + && !au_test_ramfs(sb)
16607 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16610 +/* ---------------------------------------------------------------------- */
16613 + * Note: these functions (below) are created after reading ->getattr() in all
16614 + * filesystems under linux/fs. it means we have to do so in every update...
16618 + * some filesystems require getattr to refresh the inode attributes before
16620 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16621 + * and leave the work for d_revalidate()
16623 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16625 + return au_test_nfs(sb)
16626 + || au_test_fuse(sb)
16627 + /* || au_test_btrfs(sb) */ /* untested */
16632 + * filesystems which don't maintain i_size or i_blocks.
16634 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16636 + return au_test_xfs(sb)
16637 + || au_test_btrfs(sb)
16638 + || au_test_ubifs(sb)
16639 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16640 + /* || au_test_minix(sb) */ /* untested */
16645 + * filesystems which don't store the correct value in some of their inode
16648 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16650 + return au_test_fs_bad_iattr_size(sb)
16651 + || au_test_fat(sb)
16652 + || au_test_msdos(sb)
16653 + || au_test_vfat(sb);
16656 +/* they don't check i_nlink in link(2) */
16657 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16659 + return au_test_tmpfs(sb)
16660 +#ifdef CONFIG_AUFS_BR_RAMFS
16661 + || au_test_ramfs(sb)
16663 + || au_test_ubifs(sb)
16664 + || au_test_hfsplus(sb);
16668 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16670 +static inline int au_test_fs_notime(struct super_block *sb)
16672 + return au_test_nfs(sb)
16673 + || au_test_fuse(sb)
16674 + || au_test_ubifs(sb)
16678 +/* temporary support for i#1 in cramfs */
16679 +static inline int au_test_fs_unique_ino(struct inode *inode)
16681 + if (au_test_cramfs(inode->i_sb))
16682 + return inode->i_ino != 1;
16686 +/* ---------------------------------------------------------------------- */
16689 + * the filesystem where the xino files placed must support i/o after unlink and
16690 + * maintain i_size and i_blocks.
16692 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16694 + return au_test_fs_remote(sb)
16695 + || au_test_fs_bad_iattr_size(sb)
16696 + /* don't want unnecessary work for xino */
16697 + || au_test_aufs(sb)
16698 + || au_test_ecryptfs(sb)
16699 + || au_test_nilfs(sb);
16702 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16704 + return au_test_tmpfs(sb)
16705 + || au_test_ramfs(sb);
16709 + * test if the @sb is real-readonly.
16711 +static inline int au_test_fs_rr(struct super_block *sb)
16713 + return au_test_squashfs(sb)
16714 + || au_test_iso9660(sb)
16715 + || au_test_cramfs(sb)
16716 + || au_test_romfs(sb);
16720 + * test if the @inode is nfs with 'noacl' option
16721 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16723 +static inline int au_test_nfs_noacl(struct inode *inode)
16725 + return au_test_nfs(inode->i_sb)
16726 + /* && IS_POSIXACL(inode) */
16727 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16730 +#endif /* __KERNEL__ */
16731 +#endif /* __AUFS_FSTYPE_H__ */
16732 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16733 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16734 +++ linux/fs/aufs/hbl.h 2019-07-11 15:42:14.465571210 +0200
16736 +/* SPDX-License-Identifier: GPL-2.0 */
16738 + * Copyright (C) 2017-2019 Junjiro R. Okajima
16740 + * This program, aufs is free software; you can redistribute it and/or modify
16741 + * it under the terms of the GNU General Public License as published by
16742 + * the Free Software Foundation; either version 2 of the License, or
16743 + * (at your option) any later version.
16745 + * This program is distributed in the hope that it will be useful,
16746 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16747 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16748 + * GNU General Public License for more details.
16750 + * You should have received a copy of the GNU General Public License
16751 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16755 + * helpers for hlist_bl.h
16758 +#ifndef __AUFS_HBL_H__
16759 +#define __AUFS_HBL_H__
16763 +#include <linux/list_bl.h>
16765 +static inline void au_hbl_add(struct hlist_bl_node *node,
16766 + struct hlist_bl_head *hbl)
16768 + hlist_bl_lock(hbl);
16769 + hlist_bl_add_head(node, hbl);
16770 + hlist_bl_unlock(hbl);
16773 +static inline void au_hbl_del(struct hlist_bl_node *node,
16774 + struct hlist_bl_head *hbl)
16776 + hlist_bl_lock(hbl);
16777 + hlist_bl_del(node);
16778 + hlist_bl_unlock(hbl);
16781 +#define au_hbl_for_each(pos, head) \
16782 + for (pos = hlist_bl_first(head); \
16786 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16788 + unsigned long cnt;
16789 + struct hlist_bl_node *pos;
16792 + hlist_bl_lock(hbl);
16793 + au_hbl_for_each(pos, hbl)
16795 + hlist_bl_unlock(hbl);
16799 +#endif /* __KERNEL__ */
16800 +#endif /* __AUFS_HBL_H__ */
16801 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16802 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16803 +++ linux/fs/aufs/hfsnotify.c 2019-07-11 15:42:14.465571210 +0200
16805 +// SPDX-License-Identifier: GPL-2.0
16807 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16809 + * This program, aufs is free software; you can redistribute it and/or modify
16810 + * it under the terms of the GNU General Public License as published by
16811 + * the Free Software Foundation; either version 2 of the License, or
16812 + * (at your option) any later version.
16814 + * This program is distributed in the hope that it will be useful,
16815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16817 + * GNU General Public License for more details.
16819 + * You should have received a copy of the GNU General Public License
16820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16824 + * fsnotify for the lower directories
16829 +/* FS_IN_IGNORED is unnecessary */
16830 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16831 + | FS_CREATE | FS_EVENT_ON_CHILD);
16832 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16833 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16835 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16837 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16839 + /* AuDbg("here\n"); */
16840 + au_cache_free_hnotify(hn);
16841 + smp_mb__before_atomic(); /* for atomic64_dec */
16842 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16843 + wake_up(&au_hfsn_wq);
16846 +static int au_hfsn_alloc(struct au_hinode *hinode)
16849 + struct au_hnotify *hn;
16850 + struct super_block *sb;
16851 + struct au_branch *br;
16852 + struct fsnotify_mark *mark;
16853 + aufs_bindex_t bindex;
16855 + hn = hinode->hi_notify;
16856 + sb = hn->hn_aufs_inode->i_sb;
16857 + bindex = au_br_index(sb, hinode->hi_id);
16858 + br = au_sbr(sb, bindex);
16859 + AuDebugOn(!br->br_hfsn);
16861 + mark = &hn->hn_mark;
16862 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16863 + mark->mask = AuHfsnMask;
16865 + * by udba rename or rmdir, aufs assign a new inode to the known
16866 + * h_inode, so specify 1 to allow dups.
16869 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16875 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16877 + struct fsnotify_mark *mark;
16878 + unsigned long long ull;
16879 + struct fsnotify_group *group;
16881 + ull = atomic64_inc_return(&au_hfsn_ifree);
16884 + mark = &hn->hn_mark;
16885 + spin_lock(&mark->lock);
16886 + group = mark->group;
16887 + fsnotify_get_group(group);
16888 + spin_unlock(&mark->lock);
16890 + fsnotify_destroy_mark(mark, group);
16891 + fsnotify_put_mark(mark);
16892 + fsnotify_put_group(group);
16895 + /* free hn by myself */
16899 +/* ---------------------------------------------------------------------- */
16901 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16903 + struct fsnotify_mark *mark;
16905 + mark = &hinode->hi_notify->hn_mark;
16906 + spin_lock(&mark->lock);
16908 + AuDebugOn(mark->mask & AuHfsnMask);
16909 + mark->mask |= AuHfsnMask;
16911 + AuDebugOn(!(mark->mask & AuHfsnMask));
16912 + mark->mask &= ~AuHfsnMask;
16914 + spin_unlock(&mark->lock);
16915 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16918 +/* ---------------------------------------------------------------------- */
16920 +/* #define AuDbgHnotify */
16921 +#ifdef AuDbgHnotify
16922 +static char *au_hfsn_name(u32 mask)
16924 +#ifdef CONFIG_AUFS_DEBUG
16925 +#define test_ret(flag) \
16927 + if (mask & flag) \
16930 + test_ret(FS_ACCESS);
16931 + test_ret(FS_MODIFY);
16932 + test_ret(FS_ATTRIB);
16933 + test_ret(FS_CLOSE_WRITE);
16934 + test_ret(FS_CLOSE_NOWRITE);
16935 + test_ret(FS_OPEN);
16936 + test_ret(FS_MOVED_FROM);
16937 + test_ret(FS_MOVED_TO);
16938 + test_ret(FS_CREATE);
16939 + test_ret(FS_DELETE);
16940 + test_ret(FS_DELETE_SELF);
16941 + test_ret(FS_MOVE_SELF);
16942 + test_ret(FS_UNMOUNT);
16943 + test_ret(FS_Q_OVERFLOW);
16944 + test_ret(FS_IN_IGNORED);
16945 + test_ret(FS_ISDIR);
16946 + test_ret(FS_IN_ONESHOT);
16947 + test_ret(FS_EVENT_ON_CHILD);
16956 +/* ---------------------------------------------------------------------- */
16958 +static void au_hfsn_free_group(struct fsnotify_group *group)
16960 + struct au_br_hfsnotify *hfsn = group->private;
16962 + /* AuDbg("here\n"); */
16963 + au_kfree_try_rcu(hfsn);
16966 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16967 + struct inode *inode,
16968 + u32 mask, const void *data, int data_type,
16969 + const struct qstr *file_name, u32 cookie,
16970 + struct fsnotify_iter_info *iter_info)
16973 + struct au_hnotify *hnotify;
16974 + struct inode *h_dir, *h_inode;
16975 + struct fsnotify_mark *inode_mark;
16977 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16980 + /* if FS_UNMOUNT happens, there must be another bug */
16981 + AuDebugOn(mask & FS_UNMOUNT);
16982 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16987 +#ifdef AuDbgHnotify
16989 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16990 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16991 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16992 + h_dir->i_ino, mask, au_hfsn_name(mask),
16993 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16994 + /* WARN_ON(1); */
16999 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17000 + AuDebugOn(!inode_mark);
17001 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17002 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
17008 +static struct fsnotify_ops au_hfsn_ops = {
17009 + .handle_event = au_hfsn_handle_event,
17010 + .free_group_priv = au_hfsn_free_group,
17011 + .free_mark = au_hfsn_free_mark
17014 +/* ---------------------------------------------------------------------- */
17016 +static void au_hfsn_fin_br(struct au_branch *br)
17018 + struct au_br_hfsnotify *hfsn;
17020 + hfsn = br->br_hfsn;
17023 + fsnotify_put_group(hfsn->hfsn_group);
17028 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17031 + struct fsnotify_group *group;
17032 + struct au_br_hfsnotify *hfsn;
17035 + br->br_hfsn = NULL;
17036 + if (!au_br_hnotifyable(perm))
17040 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17041 + if (unlikely(!hfsn))
17045 + group = fsnotify_alloc_group(&au_hfsn_ops);
17046 + if (IS_ERR(group)) {
17047 + err = PTR_ERR(group);
17048 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17052 + group->private = hfsn;
17053 + hfsn->hfsn_group = group;
17054 + br->br_hfsn = hfsn;
17055 + goto out; /* success */
17058 + au_kfree_try_rcu(hfsn);
17063 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17068 + if (!br->br_hfsn)
17069 + err = au_hfsn_init_br(br, perm);
17074 +/* ---------------------------------------------------------------------- */
17076 +static void au_hfsn_fin(void)
17078 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17079 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17082 +const struct au_hnotify_op au_hnotify_op = {
17083 + .ctl = au_hfsn_ctl,
17084 + .alloc = au_hfsn_alloc,
17085 + .free = au_hfsn_free,
17087 + .fin = au_hfsn_fin,
17089 + .reset_br = au_hfsn_reset_br,
17090 + .fin_br = au_hfsn_fin_br,
17091 + .init_br = au_hfsn_init_br
17093 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17094 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17095 +++ linux/fs/aufs/hfsplus.c 2019-07-11 15:42:14.465571210 +0200
17097 +// SPDX-License-Identifier: GPL-2.0
17099 + * Copyright (C) 2010-2019 Junjiro R. Okajima
17101 + * This program, aufs is free software; you can redistribute it and/or modify
17102 + * it under the terms of the GNU General Public License as published by
17103 + * the Free Software Foundation; either version 2 of the License, or
17104 + * (at your option) any later version.
17106 + * This program is distributed in the hope that it will be useful,
17107 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17109 + * GNU General Public License for more details.
17111 + * You should have received a copy of the GNU General Public License
17112 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17116 + * special support for filesystems which acquires an inode mutex
17117 + * at final closing a file, eg, hfsplus.
17119 + * This trick is very simple and stupid, just to open the file before really
17120 + * necessary open to tell hfsplus that this is not the final closing.
17121 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17122 + * and au_h_open_post() after releasing it.
17127 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17130 + struct file *h_file;
17131 + struct dentry *h_dentry;
17133 + h_dentry = au_h_dptr(dentry, bindex);
17134 + AuDebugOn(!h_dentry);
17135 + AuDebugOn(d_is_negative(h_dentry));
17138 + if (au_test_hfsplus(h_dentry->d_sb)
17139 + && d_is_reg(h_dentry))
17140 + h_file = au_h_open(dentry, bindex,
17141 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17142 + /*file*/NULL, force_wr);
17146 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17147 + struct file *h_file)
17149 + struct au_branch *br;
17153 + br = au_sbr(dentry->d_sb, bindex);
17154 + au_lcnt_dec(&br->br_nfiles);
17157 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17158 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17159 +++ linux/fs/aufs/hnotify.c 2019-07-11 15:42:14.465571210 +0200
17161 +// SPDX-License-Identifier: GPL-2.0
17163 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17165 + * This program, aufs is free software; you can redistribute it and/or modify
17166 + * it under the terms of the GNU General Public License as published by
17167 + * the Free Software Foundation; either version 2 of the License, or
17168 + * (at your option) any later version.
17170 + * This program is distributed in the hope that it will be useful,
17171 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17172 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17173 + * GNU General Public License for more details.
17175 + * You should have received a copy of the GNU General Public License
17176 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17180 + * abstraction to notify the direct changes on lower directories
17183 +/* #include <linux/iversion.h> */
17186 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17189 + struct au_hnotify *hn;
17192 + hn = au_cache_alloc_hnotify();
17194 + hn->hn_aufs_inode = inode;
17195 + hinode->hi_notify = hn;
17196 + err = au_hnotify_op.alloc(hinode);
17198 + if (unlikely(err)) {
17199 + hinode->hi_notify = NULL;
17200 + au_cache_free_hnotify(hn);
17202 + * The upper dir was removed by udba, but the same named
17203 + * dir left. In this case, aufs assigns a new inode
17204 + * number and set the monitor again.
17205 + * For the lower dir, the old monitor is still left.
17207 + if (err == -EEXIST)
17216 +void au_hn_free(struct au_hinode *hinode)
17218 + struct au_hnotify *hn;
17220 + hn = hinode->hi_notify;
17222 + hinode->hi_notify = NULL;
17223 + if (au_hnotify_op.free(hinode, hn))
17224 + au_cache_free_hnotify(hn);
17228 +/* ---------------------------------------------------------------------- */
17230 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17232 + if (hinode->hi_notify)
17233 + au_hnotify_op.ctl(hinode, do_set);
17236 +void au_hn_reset(struct inode *inode, unsigned int flags)
17238 + aufs_bindex_t bindex, bbot;
17239 + struct inode *hi;
17240 + struct dentry *iwhdentry;
17242 + bbot = au_ibbot(inode);
17243 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17244 + hi = au_h_iptr(inode, bindex);
17248 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17249 + iwhdentry = au_hi_wh(inode, bindex);
17253 + au_set_h_iptr(inode, bindex, NULL, 0);
17254 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17255 + flags & ~AuHi_XINO);
17258 + /* inode_unlock(hi); */
17262 +/* ---------------------------------------------------------------------- */
17264 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17267 + aufs_bindex_t bindex, bbot, bfound, btop;
17268 + struct inode *h_i;
17271 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17272 + pr_warn("branch root dir was changed\n");
17277 + bbot = au_ibbot(inode);
17278 + btop = au_ibtop(inode);
17279 +#if 0 /* reserved for future use */
17280 + if (bindex == bbot) {
17281 + /* keep this ino in rename case */
17285 + for (bindex = btop; bindex <= bbot; bindex++)
17286 + if (au_h_iptr(inode, bindex) == h_inode) {
17293 + for (bindex = btop; bindex <= bbot; bindex++) {
17294 + h_i = au_h_iptr(inode, bindex);
17298 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17299 + /* ignore this error */
17300 + /* bad action? */
17303 + /* children inode number will be broken */
17310 +static int hn_gen_tree(struct dentry *dentry)
17312 + int err, i, j, ndentry;
17313 + struct au_dcsub_pages dpages;
17314 + struct au_dpage *dpage;
17315 + struct dentry **dentries;
17317 + err = au_dpages_init(&dpages, GFP_NOFS);
17318 + if (unlikely(err))
17320 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17321 + if (unlikely(err))
17324 + for (i = 0; i < dpages.ndpage; i++) {
17325 + dpage = dpages.dpages + i;
17326 + dentries = dpage->dentries;
17327 + ndentry = dpage->ndentry;
17328 + for (j = 0; j < ndentry; j++) {
17329 + struct dentry *d;
17336 + if (d_really_is_positive(d))
17337 + /* todo: reset children xino?
17338 + cached children only? */
17339 + au_iigen_dec(d_inode(d));
17344 + au_dpages_free(&dpages);
17347 + /* discard children */
17348 + dentry_unhash(dentry);
17356 + * return 0 if processed.
17358 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17359 + const unsigned int isdir)
17362 + struct dentry *d;
17363 + struct qstr *dname;
17366 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17367 + pr_warn("branch root dir was changed\n");
17373 + AuDebugOn(!name);
17374 + au_iigen_dec(inode);
17375 + spin_lock(&inode->i_lock);
17376 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17377 + spin_lock(&d->d_lock);
17378 + dname = &d->d_name;
17379 + if (dname->len != nlen
17380 + && memcmp(dname->name, name, nlen)) {
17381 + spin_unlock(&d->d_lock);
17386 + spin_unlock(&d->d_lock);
17389 + spin_unlock(&inode->i_lock);
17391 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17392 + d = d_find_any_alias(inode);
17394 + au_iigen_dec(inode);
17398 + spin_lock(&d->d_lock);
17399 + dname = &d->d_name;
17400 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17401 + spin_unlock(&d->d_lock);
17402 + err = hn_gen_tree(d);
17403 + spin_lock(&d->d_lock);
17405 + spin_unlock(&d->d_lock);
17414 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17418 + if (IS_ROOT(dentry)) {
17419 + pr_warn("branch root dir was changed\n");
17425 + au_digen_dec(dentry);
17426 + if (d_really_is_positive(dentry))
17427 + au_iigen_dec(d_inode(dentry));
17429 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17430 + if (d_really_is_positive(dentry))
17431 + err = hn_gen_tree(dentry);
17438 +/* ---------------------------------------------------------------------- */
17440 +/* hnotify job flags */
17441 +#define AuHnJob_XINO0 1
17442 +#define AuHnJob_GEN (1 << 1)
17443 +#define AuHnJob_DIRENT (1 << 2)
17444 +#define AuHnJob_ISDIR (1 << 3)
17445 +#define AuHnJob_TRYXINO0 (1 << 4)
17446 +#define AuHnJob_MNTPNT (1 << 5)
17447 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17448 +#define au_fset_hnjob(flags, name) \
17449 + do { (flags) |= AuHnJob_##name; } while (0)
17450 +#define au_fclr_hnjob(flags, name) \
17451 + do { (flags) &= ~AuHnJob_##name; } while (0)
17459 +struct au_hnotify_args {
17460 + struct inode *h_dir, *dir, *h_child_inode;
17462 + unsigned int flags[AuHnLast];
17463 + unsigned int h_child_nlen;
17464 + char h_child_name[];
17467 +struct hn_job_args {
17468 + unsigned int flags;
17469 + struct inode *inode, *h_inode, *dir, *h_dir;
17470 + struct dentry *dentry;
17475 +static int hn_job(struct hn_job_args *a)
17477 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17481 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17482 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17484 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17487 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17488 + if (!a->h_inode->i_nlink
17489 + && !(a->h_inode->i_state & I_LINKABLE))
17490 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17491 + inode_unlock_shared(a->h_inode);
17494 + /* make the generation obsolete */
17495 + if (au_ftest_hnjob(a->flags, GEN)) {
17498 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17500 + if (e && a->dentry)
17501 + hn_gen_by_name(a->dentry, isdir);
17502 + /* ignore this error */
17505 + /* make dir entries obsolete */
17506 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17507 + struct au_vdir *vdir;
17509 + vdir = au_ivdir(a->inode);
17511 + vdir->vd_jiffy = 0;
17512 + /* IMustLock(a->inode); */
17513 + /* inode_inc_iversion(a->inode); */
17516 + /* can do nothing but warn */
17517 + if (au_ftest_hnjob(a->flags, MNTPNT)
17519 + && d_mountpoint(a->dentry))
17520 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17525 +/* ---------------------------------------------------------------------- */
17527 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17528 + struct inode *dir)
17530 + struct dentry *dentry, *d, *parent;
17531 + struct qstr *dname;
17533 + parent = d_find_any_alias(dir);
17538 + spin_lock(&parent->d_lock);
17539 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17540 + /* AuDbg("%pd\n", d); */
17541 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17542 + dname = &d->d_name;
17543 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17544 + goto cont_unlock;
17548 + goto cont_unlock;
17549 + if (au_dcount(d) > 0) {
17550 + dentry = dget_dlock(d);
17551 + spin_unlock(&d->d_lock);
17556 + spin_unlock(&d->d_lock);
17558 + spin_unlock(&parent->d_lock);
17562 + di_write_lock_child(dentry);
17567 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17568 + aufs_bindex_t bindex, ino_t h_ino)
17570 + struct inode *inode;
17575 + err = au_xino_read(sb, bindex, h_ino, &ino);
17577 + inode = ilookup(sb, ino);
17581 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17582 + pr_warn("wrong root branch\n");
17588 + ii_write_lock_child(inode);
17594 +static void au_hn_bh(void *_args)
17596 + struct au_hnotify_args *a = _args;
17597 + struct super_block *sb;
17598 + aufs_bindex_t bindex, bbot, bfound;
17599 + unsigned char xino, try_iput;
17601 + struct inode *inode;
17603 + struct hn_job_args args;
17604 + struct dentry *dentry;
17605 + struct au_sbinfo *sbinfo;
17607 + AuDebugOn(!_args);
17608 + AuDebugOn(!a->h_dir);
17609 + AuDebugOn(!a->dir);
17610 + AuDebugOn(!a->mask);
17611 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17612 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17613 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17618 + * do not lock a->dir->i_mutex here
17619 + * because of d_revalidate() may cause a deadlock.
17621 + sb = a->dir->i_sb;
17623 + sbinfo = au_sbi(sb);
17624 + AuDebugOn(!sbinfo);
17625 + si_write_lock(sb, AuLock_NOPLMW);
17627 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17628 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17629 + case FS_MOVED_FROM:
17630 + case FS_MOVED_TO:
17631 + AuWarn1("DIRREN with UDBA may not work correctly "
17632 + "for the direct rename(2)\n");
17635 + ii_read_lock_parent(a->dir);
17637 + bbot = au_ibbot(a->dir);
17638 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17639 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17643 + ii_read_unlock(a->dir);
17644 + if (unlikely(bfound < 0))
17647 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17649 + if (a->h_child_inode)
17650 + h_ino = a->h_child_inode->i_ino;
17652 + if (a->h_child_nlen
17653 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17654 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17655 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17658 + if (dentry && d_really_is_positive(dentry))
17659 + inode = d_inode(dentry);
17660 + if (xino && !inode && h_ino
17661 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17662 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17663 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17664 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17668 + args.flags = a->flags[AuHn_CHILD];
17669 + args.dentry = dentry;
17670 + args.inode = inode;
17671 + args.h_inode = a->h_child_inode;
17672 + args.dir = a->dir;
17673 + args.h_dir = a->h_dir;
17674 + args.h_name = a->h_child_name;
17675 + args.h_nlen = a->h_child_nlen;
17676 + err = hn_job(&args);
17678 + if (au_di(dentry))
17679 + di_write_unlock(dentry);
17682 + if (inode && try_iput) {
17683 + ii_write_unlock(inode);
17687 + ii_write_lock_parent(a->dir);
17688 + args.flags = a->flags[AuHn_PARENT];
17689 + args.dentry = NULL;
17690 + args.inode = a->dir;
17691 + args.h_inode = a->h_dir;
17693 + args.h_dir = NULL;
17694 + args.h_name = NULL;
17696 + err = hn_job(&args);
17697 + ii_write_unlock(a->dir);
17700 + iput(a->h_child_inode);
17703 + si_write_unlock(sb);
17704 + au_nwt_done(&sbinfo->si_nowait);
17708 +/* ---------------------------------------------------------------------- */
17710 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17711 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17714 + unsigned int flags[AuHnLast], f;
17715 + unsigned char isdir, isroot, wh;
17716 + struct inode *dir;
17717 + struct au_hnotify_args *args;
17718 + char *p, *h_child_name;
17721 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17722 + dir = igrab(hnotify->hn_aufs_inode);
17726 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17728 + h_child_name = (void *)h_child_qstr->name;
17729 + len = h_child_qstr->len;
17730 + if (h_child_name) {
17731 + if (len > AUFS_WH_PFX_LEN
17732 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17733 + h_child_name += AUFS_WH_PFX_LEN;
17734 + len -= AUFS_WH_PFX_LEN;
17740 + if (h_child_inode)
17741 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17742 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17743 + flags[AuHn_CHILD] = 0;
17745 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17746 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17747 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17748 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17749 + case FS_MOVED_FROM:
17750 + case FS_MOVED_TO:
17751 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17752 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17755 + AuDebugOn(!h_child_name);
17760 + * aufs never be able to get this child inode.
17761 + * revalidation should be in d_revalidate()
17762 + * by checking i_nlink, i_generation or d_unhashed().
17764 + AuDebugOn(!h_child_name);
17765 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17766 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17774 + h_child_inode = NULL;
17777 + /* iput() and kfree() will be called in au_hnotify() */
17778 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17779 + if (unlikely(!args)) {
17780 + AuErr1("no memory\n");
17784 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17785 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17786 + args->mask = mask;
17788 + args->h_dir = igrab(h_dir);
17789 + if (h_child_inode)
17790 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17791 + args->h_child_inode = h_child_inode;
17792 + args->h_child_nlen = len;
17794 + p = (void *)args;
17795 + p += sizeof(*args);
17796 + memcpy(p, h_child_name, len);
17800 + /* NFS fires the event for silly-renamed one from kworker */
17802 + if (!dir->i_nlink
17803 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17805 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17806 + if (unlikely(err)) {
17807 + pr_err("wkq %d\n", err);
17808 + iput(args->h_child_inode);
17809 + iput(args->h_dir);
17811 + au_kfree_rcu(args);
17818 +/* ---------------------------------------------------------------------- */
17820 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17824 + AuDebugOn(!(udba & AuOptMask_UDBA));
17827 + if (au_hnotify_op.reset_br)
17828 + err = au_hnotify_op.reset_br(udba, br, perm);
17833 +int au_hnotify_init_br(struct au_branch *br, int perm)
17838 + if (au_hnotify_op.init_br)
17839 + err = au_hnotify_op.init_br(br, perm);
17844 +void au_hnotify_fin_br(struct au_branch *br)
17846 + if (au_hnotify_op.fin_br)
17847 + au_hnotify_op.fin_br(br);
17850 +static void au_hn_destroy_cache(void)
17852 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17853 + au_cache[AuCache_HNOTIFY] = NULL;
17856 +int __init au_hnotify_init(void)
17861 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17862 + if (au_cache[AuCache_HNOTIFY]) {
17864 + if (au_hnotify_op.init)
17865 + err = au_hnotify_op.init();
17866 + if (unlikely(err))
17867 + au_hn_destroy_cache();
17873 +void au_hnotify_fin(void)
17875 + if (au_hnotify_op.fin)
17876 + au_hnotify_op.fin();
17878 + /* cf. au_cache_fin() */
17879 + if (au_cache[AuCache_HNOTIFY])
17880 + au_hn_destroy_cache();
17882 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17883 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17884 +++ linux/fs/aufs/iinfo.c 2019-07-11 15:42:14.468904634 +0200
17886 +// SPDX-License-Identifier: GPL-2.0
17888 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17890 + * This program, aufs is free software; you can redistribute it and/or modify
17891 + * it under the terms of the GNU General Public License as published by
17892 + * the Free Software Foundation; either version 2 of the License, or
17893 + * (at your option) any later version.
17895 + * This program is distributed in the hope that it will be useful,
17896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17898 + * GNU General Public License for more details.
17900 + * You should have received a copy of the GNU General Public License
17901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17905 + * inode private data
17910 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17912 + struct inode *h_inode;
17913 + struct au_hinode *hinode;
17915 + IiMustAnyLock(inode);
17917 + hinode = au_hinode(au_ii(inode), bindex);
17918 + h_inode = hinode->hi_inode;
17919 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17923 +/* todo: hard/soft set? */
17924 +void au_hiput(struct au_hinode *hinode)
17926 + au_hn_free(hinode);
17927 + dput(hinode->hi_whdentry);
17928 + iput(hinode->hi_inode);
17931 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17933 + unsigned int flags;
17934 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17937 + if (au_opt_test(mnt_flags, XINO))
17938 + au_fset_hi(flags, XINO);
17939 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17940 + au_fset_hi(flags, HNOTIFY);
17944 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17945 + struct inode *h_inode, unsigned int flags)
17947 + struct au_hinode *hinode;
17948 + struct inode *hi;
17949 + struct au_iinfo *iinfo = au_ii(inode);
17951 + IiMustWriteLock(inode);
17953 + hinode = au_hinode(iinfo, bindex);
17954 + hi = hinode->hi_inode;
17955 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17958 + au_hiput(hinode);
17959 + hinode->hi_inode = h_inode;
17962 + struct super_block *sb = inode->i_sb;
17963 + struct au_branch *br;
17965 + AuDebugOn(inode->i_mode
17966 + && (h_inode->i_mode & S_IFMT)
17967 + != (inode->i_mode & S_IFMT));
17968 + if (bindex == iinfo->ii_btop)
17969 + au_cpup_igen(inode, h_inode);
17970 + br = au_sbr(sb, bindex);
17971 + hinode->hi_id = br->br_id;
17972 + if (au_ftest_hi(flags, XINO)) {
17973 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17975 + if (unlikely(err))
17976 + AuIOErr1("failed au_xino_write() %d\n", err);
17979 + if (au_ftest_hi(flags, HNOTIFY)
17980 + && au_br_hnotifyable(br->br_perm)) {
17981 + err = au_hn_alloc(hinode, inode);
17982 + if (unlikely(err))
17983 + AuIOErr1("au_hn_alloc() %d\n", err);
17988 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17989 + struct dentry *h_wh)
17991 + struct au_hinode *hinode;
17993 + IiMustWriteLock(inode);
17995 + hinode = au_hinode(au_ii(inode), bindex);
17996 + AuDebugOn(hinode->hi_whdentry);
17997 + hinode->hi_whdentry = h_wh;
18000 +void au_update_iigen(struct inode *inode, int half)
18002 + struct au_iinfo *iinfo;
18003 + struct au_iigen *iigen;
18004 + unsigned int sigen;
18006 + sigen = au_sigen(inode->i_sb);
18007 + iinfo = au_ii(inode);
18008 + iigen = &iinfo->ii_generation;
18009 + spin_lock(&iigen->ig_spin);
18010 + iigen->ig_generation = sigen;
18012 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18014 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18015 + spin_unlock(&iigen->ig_spin);
18018 +/* it may be called at remount time, too */
18019 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18021 + struct au_iinfo *iinfo;
18022 + aufs_bindex_t bindex, bbot;
18024 + AuDebugOn(au_is_bad_inode(inode));
18025 + IiMustWriteLock(inode);
18027 + iinfo = au_ii(inode);
18028 + if (do_put_zero && iinfo->ii_btop >= 0) {
18029 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18031 + struct inode *h_i;
18033 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18036 + && !(h_i->i_state & I_LINKABLE))
18037 + au_set_h_iptr(inode, bindex, NULL, 0);
18041 + iinfo->ii_btop = -1;
18042 + iinfo->ii_bbot = -1;
18043 + bbot = au_sbbot(inode->i_sb);
18044 + for (bindex = 0; bindex <= bbot; bindex++)
18045 + if (au_hinode(iinfo, bindex)->hi_inode) {
18046 + iinfo->ii_btop = bindex;
18049 + if (iinfo->ii_btop >= 0)
18050 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18051 + if (au_hinode(iinfo, bindex)->hi_inode) {
18052 + iinfo->ii_bbot = bindex;
18055 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18058 +/* ---------------------------------------------------------------------- */
18060 +void au_icntnr_init_once(void *_c)
18062 + struct au_icntnr *c = _c;
18063 + struct au_iinfo *iinfo = &c->iinfo;
18065 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18066 + au_rw_init(&iinfo->ii_rwsem);
18067 + inode_init_once(&c->vfs_inode);
18070 +void au_hinode_init(struct au_hinode *hinode)
18072 + hinode->hi_inode = NULL;
18073 + hinode->hi_id = -1;
18074 + au_hn_init(hinode);
18075 + hinode->hi_whdentry = NULL;
18078 +int au_iinfo_init(struct inode *inode)
18080 + struct au_iinfo *iinfo;
18081 + struct super_block *sb;
18082 + struct au_hinode *hi;
18085 + sb = inode->i_sb;
18086 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18087 + nbr = au_sbbot(sb) + 1;
18088 + if (unlikely(nbr <= 0))
18090 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18092 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18094 + iinfo->ii_hinode = hi;
18095 + for (i = 0; i < nbr; i++, hi++)
18096 + au_hinode_init(hi);
18098 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18099 + iinfo->ii_btop = -1;
18100 + iinfo->ii_bbot = -1;
18101 + iinfo->ii_vdir = NULL;
18107 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18110 + struct au_hinode *hip;
18112 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18115 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18118 + iinfo->ii_hinode = hip;
18119 + i = iinfo->ii_bbot + 1;
18121 + for (; i < nbr; i++, hip++)
18122 + au_hinode_init(hip);
18129 +void au_iinfo_fin(struct inode *inode)
18131 + struct au_iinfo *iinfo;
18132 + struct au_hinode *hi;
18133 + struct super_block *sb;
18134 + aufs_bindex_t bindex, bbot;
18135 + const unsigned char unlinked = !inode->i_nlink;
18137 + AuDebugOn(au_is_bad_inode(inode));
18139 + sb = inode->i_sb;
18140 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18141 + if (si_pid_test(sb))
18142 + au_xino_delete_inode(inode, unlinked);
18145 + * it is safe to hide the dependency between sbinfo and
18149 + si_noflush_read_lock(sb);
18150 + au_xino_delete_inode(inode, unlinked);
18151 + si_read_unlock(sb);
18155 + iinfo = au_ii(inode);
18156 + if (iinfo->ii_vdir)
18157 + au_vdir_free(iinfo->ii_vdir);
18159 + bindex = iinfo->ii_btop;
18160 + if (bindex >= 0) {
18161 + hi = au_hinode(iinfo, bindex);
18162 + bbot = iinfo->ii_bbot;
18163 + while (bindex++ <= bbot) {
18164 + if (hi->hi_inode)
18169 + au_kfree_rcu(iinfo->ii_hinode);
18170 + AuRwDestroy(&iinfo->ii_rwsem);
18172 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18173 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18174 +++ linux/fs/aufs/inode.c 2019-07-11 15:42:14.468904634 +0200
18176 +// SPDX-License-Identifier: GPL-2.0
18178 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18180 + * This program, aufs is free software; you can redistribute it and/or modify
18181 + * it under the terms of the GNU General Public License as published by
18182 + * the Free Software Foundation; either version 2 of the License, or
18183 + * (at your option) any later version.
18185 + * This program is distributed in the hope that it will be useful,
18186 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18187 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18188 + * GNU General Public License for more details.
18190 + * You should have received a copy of the GNU General Public License
18191 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18195 + * inode functions
18198 +#include <linux/iversion.h>
18201 +struct inode *au_igrab(struct inode *inode)
18204 + AuDebugOn(!atomic_read(&inode->i_count));
18210 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18212 + au_cpup_attr_all(inode, /*force*/0);
18213 + au_update_iigen(inode, /*half*/1);
18215 + inode_inc_iversion(inode);
18218 +static int au_ii_refresh(struct inode *inode, int *update)
18222 + aufs_bindex_t bindex, new_bindex;
18223 + struct super_block *sb;
18224 + struct au_iinfo *iinfo;
18225 + struct au_hinode *p, *q, tmp;
18227 + AuDebugOn(au_is_bad_inode(inode));
18228 + IiMustWriteLock(inode);
18231 + sb = inode->i_sb;
18232 + nbr = au_sbbot(sb) + 1;
18233 + type = inode->i_mode & S_IFMT;
18234 + iinfo = au_ii(inode);
18235 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18236 + if (unlikely(err))
18239 + AuDebugOn(iinfo->ii_btop < 0);
18240 + p = au_hinode(iinfo, iinfo->ii_btop);
18241 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18243 + if (!p->hi_inode)
18246 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18247 + new_bindex = au_br_index(sb, p->hi_id);
18248 + if (new_bindex == bindex)
18251 + if (new_bindex < 0) {
18254 + p->hi_inode = NULL;
18258 + if (new_bindex < iinfo->ii_btop)
18259 + iinfo->ii_btop = new_bindex;
18260 + if (iinfo->ii_bbot < new_bindex)
18261 + iinfo->ii_bbot = new_bindex;
18262 + /* swap two lower inode, and loop again */
18263 + q = au_hinode(iinfo, new_bindex);
18267 + if (tmp.hi_inode) {
18272 + au_update_ibrange(inode, /*do_put_zero*/0);
18273 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18274 + e = au_dy_irefresh(inode);
18275 + if (unlikely(e && !err))
18283 +void au_refresh_iop(struct inode *inode, int force_getattr)
18286 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18287 + const struct inode_operations *iop
18288 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18290 + if (inode->i_op == iop)
18293 + switch (inode->i_mode & S_IFMT) {
18295 + type = AuIop_DIR;
18298 + type = AuIop_SYMLINK;
18301 + type = AuIop_OTHER;
18305 + inode->i_op = iop + type;
18306 + /* unnecessary smp_wmb() */
18309 +int au_refresh_hinode_self(struct inode *inode)
18313 + err = au_ii_refresh(inode, &update);
18315 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18321 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18323 + int err, e, update;
18324 + unsigned int flags;
18326 + aufs_bindex_t bindex, bbot;
18327 + unsigned char isdir;
18328 + struct au_hinode *p;
18329 + struct au_iinfo *iinfo;
18331 + err = au_ii_refresh(inode, &update);
18332 + if (unlikely(err))
18336 + iinfo = au_ii(inode);
18337 + p = au_hinode(iinfo, iinfo->ii_btop);
18338 + mode = (inode->i_mode & S_IFMT);
18339 + isdir = S_ISDIR(mode);
18340 + flags = au_hi_flags(inode, isdir);
18341 + bbot = au_dbbot(dentry);
18342 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18343 + struct inode *h_i, *h_inode;
18344 + struct dentry *h_d;
18346 + h_d = au_h_dptr(dentry, bindex);
18347 + if (!h_d || d_is_negative(h_d))
18350 + h_inode = d_inode(h_d);
18351 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18352 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18353 + h_i = au_h_iptr(inode, bindex);
18355 + if (h_i == h_inode)
18361 + if (bindex < iinfo->ii_btop)
18362 + iinfo->ii_btop = bindex;
18363 + if (iinfo->ii_bbot < bindex)
18364 + iinfo->ii_bbot = bindex;
18365 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18368 + au_update_ibrange(inode, /*do_put_zero*/0);
18369 + e = au_dy_irefresh(inode);
18370 + if (unlikely(e && !err))
18373 + au_refresh_hinode_attr(inode, update && isdir);
18380 +static int set_inode(struct inode *inode, struct dentry *dentry)
18383 + unsigned int flags;
18385 + aufs_bindex_t bindex, btop, btail;
18386 + unsigned char isdir;
18387 + struct dentry *h_dentry;
18388 + struct inode *h_inode;
18389 + struct au_iinfo *iinfo;
18390 + struct inode_operations *iop;
18392 + IiMustWriteLock(inode);
18396 + iop = au_sbi(inode->i_sb)->si_iop_array;
18397 + btop = au_dbtop(dentry);
18398 + h_dentry = au_h_dptr(dentry, btop);
18399 + h_inode = d_inode(h_dentry);
18400 + mode = h_inode->i_mode;
18401 + switch (mode & S_IFMT) {
18403 + btail = au_dbtail(dentry);
18404 + inode->i_op = iop + AuIop_OTHER;
18405 + inode->i_fop = &aufs_file_fop;
18406 + err = au_dy_iaop(inode, btop, h_inode);
18407 + if (unlikely(err))
18412 + btail = au_dbtaildir(dentry);
18413 + inode->i_op = iop + AuIop_DIR;
18414 + inode->i_fop = &aufs_dir_fop;
18417 + btail = au_dbtail(dentry);
18418 + inode->i_op = iop + AuIop_SYMLINK;
18424 + btail = au_dbtail(dentry);
18425 + inode->i_op = iop + AuIop_OTHER;
18426 + init_special_inode(inode, mode, h_inode->i_rdev);
18429 + AuIOErr("Unknown file type 0%o\n", mode);
18434 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18435 + flags = au_hi_flags(inode, isdir);
18436 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18437 + && au_ftest_hi(flags, HNOTIFY)
18438 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18439 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18440 + au_fclr_hi(flags, HNOTIFY);
18441 + iinfo = au_ii(inode);
18442 + iinfo->ii_btop = btop;
18443 + iinfo->ii_bbot = btail;
18444 + for (bindex = btop; bindex <= btail; bindex++) {
18445 + h_dentry = au_h_dptr(dentry, bindex);
18447 + au_set_h_iptr(inode, bindex,
18448 + au_igrab(d_inode(h_dentry)), flags);
18450 + au_cpup_attr_all(inode, /*force*/1);
18452 + * to force calling aufs_get_acl() every time,
18453 + * do not call cache_no_acl() for aufs inode.
18461 + * successful returns with iinfo write_locked
18463 + * zero: success, matched
18464 + * plus: no error, but unmatched
18466 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18469 + unsigned int gen, igflags;
18470 + aufs_bindex_t bindex, bbot;
18471 + struct inode *h_inode, *h_dinode;
18472 + struct dentry *h_dentry;
18475 + * before this function, if aufs got any iinfo lock, it must be only
18476 + * one, the parent dir.
18477 + * it can happen by UDBA and the obsoleted inode number.
18480 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18484 + ii_write_lock_new_child(inode);
18485 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18486 + h_dinode = d_inode(h_dentry);
18487 + bbot = au_ibbot(inode);
18488 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18489 + h_inode = au_h_iptr(inode, bindex);
18490 + if (!h_inode || h_inode != h_dinode)
18494 + gen = au_iigen(inode, &igflags);
18495 + if (gen == au_digen(dentry)
18496 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18499 + /* fully refresh inode using dentry */
18500 + err = au_refresh_hinode(inode, dentry);
18502 + au_update_iigen(inode, /*half*/0);
18506 + if (unlikely(err))
18507 + ii_write_unlock(inode);
18512 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18513 + unsigned int d_type, ino_t *ino)
18516 + const int isnondir = d_type != DT_DIR;
18518 + /* prevent hardlinked inode number from race condition */
18520 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18521 + if (unlikely(err))
18525 + err = au_xino_read(sb, bindex, h_ino, ino);
18526 + if (unlikely(err))
18527 + goto out_xinondir;
18531 + *ino = au_xino_new_ino(sb);
18532 + if (unlikely(!*ino))
18533 + goto out_xinondir;
18534 + err = au_xino_write(sb, bindex, h_ino, *ino);
18535 + if (unlikely(err))
18536 + goto out_xinondir;
18540 + if (isnondir && idx >= 0)
18541 + au_xinondir_leave(sb, bindex, h_ino, idx);
18546 +/* successful returns with iinfo write_locked */
18547 +/* todo: return with unlocked? */
18548 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18550 + struct inode *inode, *h_inode;
18551 + struct dentry *h_dentry;
18552 + struct super_block *sb;
18553 + ino_t h_ino, ino;
18554 + int err, idx, hlinked;
18555 + aufs_bindex_t btop;
18557 + sb = dentry->d_sb;
18558 + btop = au_dbtop(dentry);
18559 + h_dentry = au_h_dptr(dentry, btop);
18560 + h_inode = d_inode(h_dentry);
18561 + h_ino = h_inode->i_ino;
18562 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18566 + * stop 'race'-ing between hardlinks under different
18570 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18571 + inode = ERR_PTR(err);
18572 + if (unlikely(err))
18576 + err = au_xino_read(sb, btop, h_ino, &ino);
18577 + inode = ERR_PTR(err);
18578 + if (unlikely(err))
18579 + goto out_xinondir;
18582 + ino = au_xino_new_ino(sb);
18583 + if (unlikely(!ino)) {
18584 + inode = ERR_PTR(-EIO);
18585 + goto out_xinondir;
18589 + AuDbg("i%lu\n", (unsigned long)ino);
18590 + inode = au_iget_locked(sb, ino);
18591 + err = PTR_ERR(inode);
18592 + if (IS_ERR(inode))
18593 + goto out_xinondir;
18595 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18596 + if (inode->i_state & I_NEW) {
18597 + ii_write_lock_new_child(inode);
18598 + err = set_inode(inode, dentry);
18600 + unlock_new_inode(inode);
18601 + goto out_xinondir; /* success */
18605 + * iget_failed() calls iput(), but we need to call
18606 + * ii_write_unlock() after iget_failed(). so dirty hack for
18609 + atomic_inc(&inode->i_count);
18610 + iget_failed(inode);
18611 + ii_write_unlock(inode);
18612 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18613 + /* ignore this error */
18615 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18617 + * horrible race condition between lookup, readdir and copyup
18618 + * (or something).
18620 + if (hlinked && idx >= 0)
18621 + au_xinondir_leave(sb, btop, h_ino, idx);
18622 + err = reval_inode(inode, dentry);
18623 + if (unlikely(err < 0)) {
18628 + goto out; /* success */
18629 + else if (hlinked && idx >= 0) {
18630 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18631 + if (unlikely(err)) {
18633 + inode = ERR_PTR(err);
18639 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18640 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18641 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18642 + btop, au_sbtype(h_dentry->d_sb), dentry,
18643 + (unsigned long)h_ino, (unsigned long)ino);
18645 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18648 + if (hlinked && idx >= 0)
18649 + au_xinondir_leave(sb, btop, h_ino, idx);
18655 + inode = ERR_PTR(err);
18657 + if (hlinked && idx >= 0)
18658 + au_xinondir_leave(sb, btop, h_ino, idx);
18663 +/* ---------------------------------------------------------------------- */
18665 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18666 + struct inode *inode)
18669 + struct inode *hi;
18671 + err = au_br_rdonly(au_sbr(sb, bindex));
18673 + /* pseudo-link after flushed may happen out of bounds */
18676 + && au_ibtop(inode) <= bindex
18677 + && bindex <= au_ibbot(inode)) {
18679 + * permission check is unnecessary since vfsub routine
18680 + * will be called later
18682 + hi = au_h_iptr(inode, bindex);
18684 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18690 +int au_test_h_perm(struct inode *h_inode, int mask)
18692 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18694 + return inode_permission(h_inode, mask);
18697 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18699 + if (au_test_nfs(h_inode->i_sb)
18700 + && (mask & MAY_WRITE)
18701 + && S_ISDIR(h_inode->i_mode))
18702 + mask |= MAY_READ; /* force permission check */
18703 + return au_test_h_perm(h_inode, mask);
18705 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18706 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18707 +++ linux/fs/aufs/inode.h 2019-07-11 15:42:14.468904634 +0200
18709 +/* SPDX-License-Identifier: GPL-2.0 */
18711 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18713 + * This program, aufs is free software; you can redistribute it and/or modify
18714 + * it under the terms of the GNU General Public License as published by
18715 + * the Free Software Foundation; either version 2 of the License, or
18716 + * (at your option) any later version.
18718 + * This program is distributed in the hope that it will be useful,
18719 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18720 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18721 + * GNU General Public License for more details.
18723 + * You should have received a copy of the GNU General Public License
18724 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18728 + * inode operations
18731 +#ifndef __AUFS_INODE_H__
18732 +#define __AUFS_INODE_H__
18736 +#include <linux/fsnotify.h>
18737 +#include "rwsem.h"
18741 +struct au_hnotify {
18742 +#ifdef CONFIG_AUFS_HNOTIFY
18743 +#ifdef CONFIG_AUFS_HFSNOTIFY
18744 + /* never use fsnotify_add_vfsmount_mark() */
18745 + struct fsnotify_mark hn_mark;
18747 + struct inode *hn_aufs_inode; /* no get/put */
18748 + struct rcu_head rcu;
18750 +} ____cacheline_aligned_in_smp;
18752 +struct au_hinode {
18753 + struct inode *hi_inode;
18754 + aufs_bindex_t hi_id;
18755 +#ifdef CONFIG_AUFS_HNOTIFY
18756 + struct au_hnotify *hi_notify;
18759 + /* reference to the copied-up whiteout with get/put */
18760 + struct dentry *hi_whdentry;
18764 +#define AuIG_HALF_REFRESHED 1
18765 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18766 +#define au_ig_fset(flags, name) \
18767 + do { (flags) |= AuIG_##name; } while (0)
18768 +#define au_ig_fclr(flags, name) \
18769 + do { (flags) &= ~AuIG_##name; } while (0)
18772 + spinlock_t ig_spin;
18773 + __u32 ig_generation, ig_flags;
18778 + struct au_iigen ii_generation;
18779 + struct super_block *ii_hsb1; /* no get/put */
18781 + struct au_rwsem ii_rwsem;
18782 + aufs_bindex_t ii_btop, ii_bbot;
18784 + struct au_hinode *ii_hinode;
18785 + struct au_vdir *ii_vdir;
18788 +struct au_icntnr {
18789 + struct au_iinfo iinfo;
18790 + struct inode vfs_inode;
18791 + struct hlist_bl_node plink;
18792 + struct rcu_head rcu;
18793 +} ____cacheline_aligned_in_smp;
18795 +/* au_pin flags */
18796 +#define AuPin_DI_LOCKED 1
18797 +#define AuPin_MNT_WRITE (1 << 1)
18798 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18799 +#define au_fset_pin(flags, name) \
18800 + do { (flags) |= AuPin_##name; } while (0)
18801 +#define au_fclr_pin(flags, name) \
18802 + do { (flags) &= ~AuPin_##name; } while (0)
18806 + struct dentry *dentry;
18807 + unsigned int udba;
18808 + unsigned char lsc_di, lsc_hi, flags;
18809 + aufs_bindex_t bindex;
18812 + struct dentry *parent;
18813 + struct au_hinode *hdir;
18814 + struct vfsmount *h_mnt;
18816 + /* temporary unlock/relock for copyup */
18817 + struct dentry *h_dentry, *h_parent;
18818 + struct au_branch *br;
18819 + struct task_struct *task;
18822 +void au_pin_hdir_unlock(struct au_pin *p);
18823 +int au_pin_hdir_lock(struct au_pin *p);
18824 +int au_pin_hdir_relock(struct au_pin *p);
18825 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18826 +void au_pin_hdir_release(struct au_pin *p);
18828 +/* ---------------------------------------------------------------------- */
18830 +static inline struct au_iinfo *au_ii(struct inode *inode)
18832 + BUG_ON(is_bad_inode(inode));
18833 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18836 +/* ---------------------------------------------------------------------- */
18839 +struct inode *au_igrab(struct inode *inode);
18840 +void au_refresh_iop(struct inode *inode, int force_getattr);
18841 +int au_refresh_hinode_self(struct inode *inode);
18842 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18843 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18844 + unsigned int d_type, ino_t *ino);
18845 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18846 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18847 + struct inode *inode);
18848 +int au_test_h_perm(struct inode *h_inode, int mask);
18849 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18851 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18852 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18854 +#ifdef CONFIG_AUFS_SHWH
18855 + return au_ino(sb, bindex, h_ino, d_type, ino);
18868 +extern struct inode_operations aufs_iop[AuIop_Last],
18869 + aufs_iop_nogetattr[AuIop_Last];
18871 +/* au_wr_dir flags */
18872 +#define AuWrDir_ADD_ENTRY 1
18873 +#define AuWrDir_ISDIR (1 << 1)
18874 +#define AuWrDir_TMPFILE (1 << 2)
18875 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18876 +#define au_fset_wrdir(flags, name) \
18877 + do { (flags) |= AuWrDir_##name; } while (0)
18878 +#define au_fclr_wrdir(flags, name) \
18879 + do { (flags) &= ~AuWrDir_##name; } while (0)
18881 +struct au_wr_dir_args {
18882 + aufs_bindex_t force_btgt;
18883 + unsigned char flags;
18885 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18886 + struct au_wr_dir_args *args);
18888 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18889 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18890 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18891 + unsigned int udba, unsigned char flags);
18892 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18893 + unsigned int udba, unsigned char flags) __must_check;
18894 +int au_do_pin(struct au_pin *pin) __must_check;
18895 +void au_unpin(struct au_pin *pin);
18896 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18898 +#define AuIcpup_DID_CPUP 1
18899 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18900 +#define au_fset_icpup(flags, name) \
18901 + do { (flags) |= AuIcpup_##name; } while (0)
18902 +#define au_fclr_icpup(flags, name) \
18903 + do { (flags) &= ~AuIcpup_##name; } while (0)
18905 +struct au_icpup_args {
18906 + unsigned char flags;
18907 + unsigned char pin_flags;
18908 + aufs_bindex_t btgt;
18909 + unsigned int udba;
18910 + struct au_pin pin;
18911 + struct path h_path;
18912 + struct inode *h_inode;
18915 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18916 + struct au_icpup_args *a);
18918 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18922 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18923 + struct dentry *h_parent, int isdir);
18924 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18926 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18927 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18929 +struct vfsub_aopen_args;
18930 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18931 + struct vfsub_aopen_args *args);
18932 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18933 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18934 + struct dentry *dentry);
18935 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18938 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18939 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18940 + struct dentry *h_parent, int isdir);
18941 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18942 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18945 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18946 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18947 + struct inode *dir, struct dentry *dentry,
18948 + unsigned int flags);
18951 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18952 +void au_hiput(struct au_hinode *hinode);
18953 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18954 + struct dentry *h_wh);
18955 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18957 +/* hinode flags */
18958 +#define AuHi_XINO 1
18959 +#define AuHi_HNOTIFY (1 << 1)
18960 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18961 +#define au_fset_hi(flags, name) \
18962 + do { (flags) |= AuHi_##name; } while (0)
18963 +#define au_fclr_hi(flags, name) \
18964 + do { (flags) &= ~AuHi_##name; } while (0)
18966 +#ifndef CONFIG_AUFS_HNOTIFY
18967 +#undef AuHi_HNOTIFY
18968 +#define AuHi_HNOTIFY 0
18971 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18972 + struct inode *h_inode, unsigned int flags);
18974 +void au_update_iigen(struct inode *inode, int half);
18975 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18977 +void au_icntnr_init_once(void *_c);
18978 +void au_hinode_init(struct au_hinode *hinode);
18979 +int au_iinfo_init(struct inode *inode);
18980 +void au_iinfo_fin(struct inode *inode);
18981 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18983 +#ifdef CONFIG_PROC_FS
18985 +int au_plink_maint(struct super_block *sb, int flags);
18987 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18988 +int au_plink_maint_enter(struct super_block *sb);
18989 +#ifdef CONFIG_AUFS_DEBUG
18990 +void au_plink_list(struct super_block *sb);
18992 +AuStubVoid(au_plink_list, struct super_block *sb)
18994 +int au_plink_test(struct inode *inode);
18995 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18996 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18997 + struct dentry *h_dentry);
18998 +void au_plink_put(struct super_block *sb, int verbose);
18999 +void au_plink_clean(struct super_block *sb, int verbose);
19000 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19002 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19003 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19004 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19005 +AuStubVoid(au_plink_list, struct super_block *sb);
19006 +AuStubInt0(au_plink_test, struct inode *inode);
19007 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19008 + struct inode *inode, aufs_bindex_t bindex);
19009 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19010 + struct dentry *h_dentry);
19011 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19012 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19013 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19014 +#endif /* CONFIG_PROC_FS */
19016 +#ifdef CONFIG_AUFS_XATTR
19018 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19019 + unsigned int verbose);
19020 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19021 +void au_xattr_init(struct super_block *sb);
19023 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19024 + int ignore_flags, unsigned int verbose);
19025 +AuStubVoid(au_xattr_init, struct super_block *sb);
19028 +#ifdef CONFIG_FS_POSIX_ACL
19029 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19030 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19033 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19039 +struct au_sxattr {
19043 + const char *name;
19044 + const void *value;
19049 + struct posix_acl *acl;
19054 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19055 + struct au_sxattr *arg);
19058 +/* ---------------------------------------------------------------------- */
19060 +/* lock subclass for iinfo */
19062 + AuLsc_II_CHILD, /* child first */
19063 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19064 + AuLsc_II_CHILD3, /* copyup dirs */
19065 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19066 + AuLsc_II_PARENT2,
19067 + AuLsc_II_PARENT3, /* copyup dirs */
19068 + AuLsc_II_NEW_CHILD
19072 + * ii_read_lock_child, ii_write_lock_child,
19073 + * ii_read_lock_child2, ii_write_lock_child2,
19074 + * ii_read_lock_child3, ii_write_lock_child3,
19075 + * ii_read_lock_parent, ii_write_lock_parent,
19076 + * ii_read_lock_parent2, ii_write_lock_parent2,
19077 + * ii_read_lock_parent3, ii_write_lock_parent3,
19078 + * ii_read_lock_new_child, ii_write_lock_new_child,
19080 +#define AuReadLockFunc(name, lsc) \
19081 +static inline void ii_read_lock_##name(struct inode *i) \
19083 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19086 +#define AuWriteLockFunc(name, lsc) \
19087 +static inline void ii_write_lock_##name(struct inode *i) \
19089 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19092 +#define AuRWLockFuncs(name, lsc) \
19093 + AuReadLockFunc(name, lsc) \
19094 + AuWriteLockFunc(name, lsc)
19096 +AuRWLockFuncs(child, CHILD);
19097 +AuRWLockFuncs(child2, CHILD2);
19098 +AuRWLockFuncs(child3, CHILD3);
19099 +AuRWLockFuncs(parent, PARENT);
19100 +AuRWLockFuncs(parent2, PARENT2);
19101 +AuRWLockFuncs(parent3, PARENT3);
19102 +AuRWLockFuncs(new_child, NEW_CHILD);
19104 +#undef AuReadLockFunc
19105 +#undef AuWriteLockFunc
19106 +#undef AuRWLockFuncs
19108 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19109 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19110 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19112 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19113 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19114 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19116 +/* ---------------------------------------------------------------------- */
19118 +static inline void au_icntnr_init(struct au_icntnr *c)
19120 +#ifdef CONFIG_AUFS_DEBUG
19121 + c->vfs_inode.i_mode = 0;
19125 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19127 + unsigned int gen;
19128 + struct au_iinfo *iinfo;
19129 + struct au_iigen *iigen;
19131 + iinfo = au_ii(inode);
19132 + iigen = &iinfo->ii_generation;
19133 + spin_lock(&iigen->ig_spin);
19135 + *igflags = iigen->ig_flags;
19136 + gen = iigen->ig_generation;
19137 + spin_unlock(&iigen->ig_spin);
19142 +/* tiny test for inode number */
19143 +/* tmpfs generation is too rough */
19144 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19146 + struct au_iinfo *iinfo;
19148 + iinfo = au_ii(inode);
19149 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19150 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19151 + && iinfo->ii_higen == h_inode->i_generation);
19154 +static inline void au_iigen_dec(struct inode *inode)
19156 + struct au_iinfo *iinfo;
19157 + struct au_iigen *iigen;
19159 + iinfo = au_ii(inode);
19160 + iigen = &iinfo->ii_generation;
19161 + spin_lock(&iigen->ig_spin);
19162 + iigen->ig_generation--;
19163 + spin_unlock(&iigen->ig_spin);
19166 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19171 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19177 +/* ---------------------------------------------------------------------- */
19179 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19180 + aufs_bindex_t bindex)
19182 + return iinfo->ii_hinode + bindex;
19185 +static inline int au_is_bad_inode(struct inode *inode)
19187 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19190 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19191 + aufs_bindex_t bindex)
19193 + IiMustAnyLock(inode);
19194 + return au_hinode(au_ii(inode), bindex)->hi_id;
19197 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19199 + IiMustAnyLock(inode);
19200 + return au_ii(inode)->ii_btop;
19203 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19205 + IiMustAnyLock(inode);
19206 + return au_ii(inode)->ii_bbot;
19209 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19211 + IiMustAnyLock(inode);
19212 + return au_ii(inode)->ii_vdir;
19215 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19217 + IiMustAnyLock(inode);
19218 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19221 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19223 + IiMustWriteLock(inode);
19224 + au_ii(inode)->ii_btop = bindex;
19227 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19229 + IiMustWriteLock(inode);
19230 + au_ii(inode)->ii_bbot = bindex;
19233 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19235 + IiMustWriteLock(inode);
19236 + au_ii(inode)->ii_vdir = vdir;
19239 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19241 + IiMustAnyLock(inode);
19242 + return au_hinode(au_ii(inode), bindex);
19245 +/* ---------------------------------------------------------------------- */
19247 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19250 + return pin->parent;
19254 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19256 + if (pin && pin->hdir)
19257 + return pin->hdir->hi_inode;
19261 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19264 + return pin->hdir;
19268 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19271 + pin->dentry = dentry;
19274 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19275 + unsigned char lflag)
19279 + au_fset_pin(pin->flags, DI_LOCKED);
19281 + au_fclr_pin(pin->flags, DI_LOCKED);
19285 +#if 0 /* reserved */
19286 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19289 + dput(pin->parent);
19290 + pin->parent = dget(parent);
19295 +/* ---------------------------------------------------------------------- */
19298 +#ifdef CONFIG_AUFS_HNOTIFY
19299 +struct au_hnotify_op {
19300 + void (*ctl)(struct au_hinode *hinode, int do_set);
19301 + int (*alloc)(struct au_hinode *hinode);
19304 + * if it returns true, the the caller should free hinode->hi_notify,
19305 + * otherwise ->free() frees it.
19307 + int (*free)(struct au_hinode *hinode,
19308 + struct au_hnotify *hn) __must_check;
19310 + void (*fin)(void);
19311 + int (*init)(void);
19313 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19314 + void (*fin_br)(struct au_branch *br);
19315 + int (*init_br)(struct au_branch *br, int perm);
19319 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19320 +void au_hn_free(struct au_hinode *hinode);
19321 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19322 +void au_hn_reset(struct inode *inode, unsigned int flags);
19323 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19324 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19325 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19326 +int au_hnotify_init_br(struct au_branch *br, int perm);
19327 +void au_hnotify_fin_br(struct au_branch *br);
19328 +int __init au_hnotify_init(void);
19329 +void au_hnotify_fin(void);
19332 +extern const struct au_hnotify_op au_hnotify_op;
19335 +void au_hn_init(struct au_hinode *hinode)
19337 + hinode->hi_notify = NULL;
19340 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19342 + return hinode->hi_notify;
19346 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19347 + struct au_hinode *hinode __maybe_unused,
19348 + struct inode *inode __maybe_unused)
19349 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19350 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19351 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19352 + int do_set __maybe_unused)
19353 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19354 + unsigned int flags __maybe_unused)
19355 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19356 + struct au_branch *br __maybe_unused,
19357 + int perm __maybe_unused)
19358 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19359 + int perm __maybe_unused)
19360 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19361 +AuStubInt0(__init au_hnotify_init, void)
19362 +AuStubVoid(au_hnotify_fin, void)
19363 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19364 +#endif /* CONFIG_AUFS_HNOTIFY */
19366 +static inline void au_hn_suspend(struct au_hinode *hdir)
19368 + au_hn_ctl(hdir, /*do_set*/0);
19371 +static inline void au_hn_resume(struct au_hinode *hdir)
19373 + au_hn_ctl(hdir, /*do_set*/1);
19376 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19378 + inode_lock(hdir->hi_inode);
19379 + au_hn_suspend(hdir);
19382 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19383 + unsigned int sc __maybe_unused)
19385 + inode_lock_nested(hdir->hi_inode, sc);
19386 + au_hn_suspend(hdir);
19389 +#if 0 /* unused */
19390 +#include "vfsub.h"
19391 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19394 + inode_lock_shared_nested(hdir->hi_inode, sc);
19395 + au_hn_suspend(hdir);
19399 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19401 + au_hn_resume(hdir);
19402 + inode_unlock(hdir->hi_inode);
19405 +#endif /* __KERNEL__ */
19406 +#endif /* __AUFS_INODE_H__ */
19407 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19408 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19409 +++ linux/fs/aufs/ioctl.c 2019-07-11 15:42:14.468904634 +0200
19411 +// SPDX-License-Identifier: GPL-2.0
19413 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19415 + * This program, aufs is free software; you can redistribute it and/or modify
19416 + * it under the terms of the GNU General Public License as published by
19417 + * the Free Software Foundation; either version 2 of the License, or
19418 + * (at your option) any later version.
19420 + * This program is distributed in the hope that it will be useful,
19421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19423 + * GNU General Public License for more details.
19425 + * You should have received a copy of the GNU General Public License
19426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19431 + * plink-management and readdir in userspace.
19432 + * assist the pathconf(3) wrapper library.
19434 + * File-based Hierarchical Storage Management.
19437 +#include <linux/compat.h>
19438 +#include <linux/file.h>
19441 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19444 + aufs_bindex_t wbi, bindex, bbot;
19445 + struct file *h_file;
19446 + struct super_block *sb;
19447 + struct dentry *root;
19448 + struct au_branch *br;
19449 + struct aufs_wbr_fd wbrfd = {
19450 + .oflags = au_dir_roflags,
19453 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19454 + | O_NOATIME | O_CLOEXEC;
19456 + AuDebugOn(wbrfd.oflags & ~valid);
19459 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19460 + if (unlikely(err)) {
19466 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19467 + wbrfd.oflags |= au_dir_roflags;
19468 + AuDbg("0%o\n", wbrfd.oflags);
19469 + if (unlikely(wbrfd.oflags & ~valid))
19473 + fd = get_unused_fd_flags(0);
19475 + if (unlikely(fd < 0))
19478 + h_file = ERR_PTR(-EINVAL);
19481 + sb = path->dentry->d_sb;
19482 + root = sb->s_root;
19483 + aufs_read_lock(root, AuLock_IR);
19484 + bbot = au_sbbot(sb);
19485 + if (wbrfd.brid >= 0) {
19486 + wbi = au_br_index(sb, wbrfd.brid);
19487 + if (unlikely(wbi < 0 || wbi > bbot))
19491 + h_file = ERR_PTR(-ENOENT);
19492 + br = au_sbr(sb, wbi);
19493 + if (!au_br_writable(br->br_perm)) {
19497 + bindex = wbi + 1;
19499 + for (; bindex <= bbot; bindex++) {
19500 + br = au_sbr(sb, bindex);
19501 + if (au_br_writable(br->br_perm)) {
19503 + br = au_sbr(sb, wbi);
19508 + AuDbg("wbi %d\n", wbi);
19510 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19514 + aufs_read_unlock(root, AuLock_IR);
19515 + err = PTR_ERR(h_file);
19516 + if (IS_ERR(h_file))
19519 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19520 + fd_install(fd, h_file);
19522 + goto out; /* success */
19525 + put_unused_fd(fd);
19531 +/* ---------------------------------------------------------------------- */
19533 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19536 + struct dentry *dentry;
19539 + case AUFS_CTL_RDU:
19540 + case AUFS_CTL_RDU_INO:
19541 + err = au_rdu_ioctl(file, cmd, arg);
19544 + case AUFS_CTL_WBR_FD:
19545 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19548 + case AUFS_CTL_IBUSY:
19549 + err = au_ibusy_ioctl(file, arg);
19552 + case AUFS_CTL_BRINFO:
19553 + err = au_brinfo_ioctl(file, arg);
19556 + case AUFS_CTL_FHSM_FD:
19557 + dentry = file->f_path.dentry;
19558 + if (IS_ROOT(dentry))
19559 + err = au_fhsm_fd(dentry->d_sb, arg);
19565 + /* do not call the lower */
19566 + AuDbg("0x%x\n", cmd);
19574 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19579 + case AUFS_CTL_MVDOWN:
19580 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19583 + case AUFS_CTL_WBR_FD:
19584 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19588 + /* do not call the lower */
19589 + AuDbg("0x%x\n", cmd);
19597 +#ifdef CONFIG_COMPAT
19598 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19599 + unsigned long arg)
19604 + case AUFS_CTL_RDU:
19605 + case AUFS_CTL_RDU_INO:
19606 + err = au_rdu_compat_ioctl(file, cmd, arg);
19609 + case AUFS_CTL_IBUSY:
19610 + err = au_ibusy_compat_ioctl(file, arg);
19613 + case AUFS_CTL_BRINFO:
19614 + err = au_brinfo_compat_ioctl(file, arg);
19618 + err = aufs_ioctl_dir(file, cmd, arg);
19625 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19626 + unsigned long arg)
19628 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19631 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19632 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19633 +++ linux/fs/aufs/i_op_add.c 2019-07-11 15:42:14.468904634 +0200
19635 +// SPDX-License-Identifier: GPL-2.0
19637 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19639 + * This program, aufs is free software; you can redistribute it and/or modify
19640 + * it under the terms of the GNU General Public License as published by
19641 + * the Free Software Foundation; either version 2 of the License, or
19642 + * (at your option) any later version.
19644 + * This program is distributed in the hope that it will be useful,
19645 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19646 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19647 + * GNU General Public License for more details.
19649 + * You should have received a copy of the GNU General Public License
19650 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19654 + * inode operations (add entry)
19657 +#include <linux/iversion.h>
19661 + * final procedure of adding a new entry, except link(2).
19662 + * remove whiteout, instantiate, copyup the parent dir's times and size
19663 + * and update version.
19664 + * if it failed, re-create the removed whiteout.
19666 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19667 + struct dentry *wh_dentry, struct dentry *dentry)
19670 + aufs_bindex_t bwh;
19671 + struct path h_path;
19672 + struct super_block *sb;
19673 + struct inode *inode, *h_dir;
19674 + struct dentry *wh;
19679 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19680 + IMustLock(h_dir);
19681 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19682 + bwh = au_dbwh(dentry);
19683 + h_path.dentry = wh_dentry;
19684 + h_path.mnt = au_sbr_mnt(sb, bindex);
19685 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19687 + if (unlikely(err))
19691 + inode = au_new_inode(dentry, /*must_new*/1);
19692 + if (!IS_ERR(inode)) {
19693 + d_instantiate(dentry, inode);
19694 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19696 + au_dir_ts(dir, bindex);
19697 + inode_inc_iversion(dir);
19698 + au_fhsm_wrote(sb, bindex, /*force*/0);
19699 + return 0; /* success */
19702 + err = PTR_ERR(inode);
19707 + /* dir inode is locked */
19708 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19709 + rerr = PTR_ERR(wh);
19710 + if (IS_ERR(wh)) {
19711 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19712 + dentry, err, rerr);
19721 +static int au_d_may_add(struct dentry *dentry)
19726 + if (unlikely(d_unhashed(dentry)))
19728 + if (unlikely(d_really_is_positive(dentry)))
19734 + * simple tests for the adding inode operations.
19735 + * following the checks in vfs, plus the parent-child relationship.
19737 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19738 + struct dentry *h_parent, int isdir)
19742 + struct dentry *h_dentry;
19743 + struct inode *h_inode;
19745 + err = -ENAMETOOLONG;
19746 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19749 + h_dentry = au_h_dptr(dentry, bindex);
19750 + if (d_really_is_negative(dentry)) {
19752 + if (unlikely(d_is_positive(h_dentry)))
19755 + /* rename(2) case */
19757 + if (unlikely(d_is_negative(h_dentry)))
19759 + h_inode = d_inode(h_dentry);
19760 + if (unlikely(!h_inode->i_nlink))
19763 + h_mode = h_inode->i_mode;
19766 + if (unlikely(S_ISDIR(h_mode)))
19768 + } else if (unlikely(!S_ISDIR(h_mode))) {
19775 + /* expected parent dir is locked */
19776 + if (unlikely(h_parent != h_dentry->d_parent))
19785 + * initial procedure of adding a new entry.
19786 + * prepare writable branch and the parent dir, lock it,
19787 + * and lookup whiteout for the new entry.
19789 +static struct dentry*
19790 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19791 + struct dentry *src_dentry, struct au_pin *pin,
19792 + struct au_wr_dir_args *wr_dir_args)
19794 + struct dentry *wh_dentry, *h_parent;
19795 + struct super_block *sb;
19796 + struct au_branch *br;
19798 + unsigned int udba;
19799 + aufs_bindex_t bcpup;
19801 + AuDbg("%pd\n", dentry);
19803 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19805 + wh_dentry = ERR_PTR(err);
19806 + if (unlikely(err < 0))
19809 + sb = dentry->d_sb;
19810 + udba = au_opt_udba(sb);
19811 + err = au_pin(pin, dentry, bcpup, udba,
19812 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19813 + wh_dentry = ERR_PTR(err);
19814 + if (unlikely(err))
19817 + h_parent = au_pinned_h_parent(pin);
19818 + if (udba != AuOpt_UDBA_NONE
19819 + && au_dbtop(dentry) == bcpup)
19820 + err = au_may_add(dentry, bcpup, h_parent,
19821 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19822 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19823 + err = -ENAMETOOLONG;
19824 + wh_dentry = ERR_PTR(err);
19825 + if (unlikely(err))
19828 + br = au_sbr(sb, bcpup);
19830 + struct path tmp = {
19831 + .dentry = h_parent,
19832 + .mnt = au_br_mnt(br)
19834 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19837 + wh_dentry = NULL;
19838 + if (bcpup != au_dbwh(dentry))
19839 + goto out; /* success */
19842 + * ENAMETOOLONG here means that if we allowed create such name, then it
19843 + * would not be able to removed in the future. So we don't allow such
19844 + * name here and we don't handle ENAMETOOLONG differently here.
19846 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19849 + if (IS_ERR(wh_dentry))
19852 + return wh_dentry;
19855 +/* ---------------------------------------------------------------------- */
19857 +enum { Mknod, Symlink, Creat };
19858 +struct simple_arg {
19865 + struct vfsub_aopen_args *aopen;
19868 + const char *symname;
19877 +static int add_simple(struct inode *dir, struct dentry *dentry,
19878 + struct simple_arg *arg)
19881 + aufs_bindex_t btop;
19882 + unsigned char created;
19883 + const unsigned char try_aopen
19884 + = (arg->type == Creat && arg->u.c.try_aopen);
19885 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19886 + struct dentry *wh_dentry, *parent;
19887 + struct inode *h_dir;
19888 + struct super_block *sb;
19889 + struct au_branch *br;
19890 + /* to reduce stack size */
19892 + struct au_dtime dt;
19893 + struct au_pin pin;
19894 + struct path h_path;
19895 + struct au_wr_dir_args wr_dir_args;
19898 + AuDbg("%pd\n", dentry);
19902 + a = kmalloc(sizeof(*a), GFP_NOFS);
19903 + if (unlikely(!a))
19905 + a->wr_dir_args.force_btgt = -1;
19906 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19908 + parent = dentry->d_parent; /* dir inode is locked */
19909 + if (!try_aopen) {
19910 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19911 + if (unlikely(err))
19914 + err = au_d_may_add(dentry);
19915 + if (unlikely(err))
19918 + di_write_lock_parent(parent);
19919 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19920 + &a->pin, &a->wr_dir_args);
19921 + err = PTR_ERR(wh_dentry);
19922 + if (IS_ERR(wh_dentry))
19925 + btop = au_dbtop(dentry);
19926 + sb = dentry->d_sb;
19927 + br = au_sbr(sb, btop);
19928 + a->h_path.dentry = au_h_dptr(dentry, btop);
19929 + a->h_path.mnt = au_br_mnt(br);
19930 + h_dir = au_pinned_h_dir(&a->pin);
19931 + switch (arg->type) {
19933 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19934 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19935 + arg->u.c.want_excl);
19937 + if (!err && try_aopen)
19938 + aopen->file->f_mode |= FMODE_CREATED;
19941 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19942 + AuDbg("err %d\n", err);
19943 + AuDbgFile(aopen->file);
19944 + created = err >= 0
19945 + && !!(aopen->file->f_mode & FMODE_CREATED);
19949 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19953 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19960 + if (unlikely(err < 0))
19963 + err = epilog(dir, btop, wh_dentry, dentry);
19965 + goto out_unpin; /* success */
19968 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19969 + /* no delegation since it is just created */
19970 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19973 + AuIOErr("%pd revert failure(%d, %d)\n",
19974 + dentry, err, rerr);
19977 + au_dtime_revert(&a->dt);
19979 + if (try_aopen && h_dir->i_op->atomic_open
19980 + && (aopen->file->f_mode & FMODE_OPENED))
19981 + /* aopen->file is still opened */
19982 + au_lcnt_dec(&aopen->br->br_nfiles);
19985 + au_unpin(&a->pin);
19989 + di_write_unlock(parent);
19991 + if (unlikely(err)) {
19992 + au_update_dbtop(dentry);
19996 + aufs_read_unlock(dentry, AuLock_DW);
20003 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20006 + struct simple_arg arg = {
20013 + return add_simple(dir, dentry, &arg);
20016 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20018 + struct simple_arg arg = {
20020 + .u.s.symname = symname
20022 + return add_simple(dir, dentry, &arg);
20025 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20028 + struct simple_arg arg = {
20032 + .want_excl = want_excl
20035 + return add_simple(dir, dentry, &arg);
20038 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20039 + struct vfsub_aopen_args *aopen_args)
20041 + struct simple_arg arg = {
20044 + .mode = aopen_args->create_mode,
20045 + .want_excl = aopen_args->open_flag & O_EXCL,
20046 + .try_aopen = true,
20047 + .aopen = aopen_args
20050 + return add_simple(dir, dentry, &arg);
20053 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20056 + aufs_bindex_t bindex;
20057 + struct super_block *sb;
20058 + struct dentry *parent, *h_parent, *h_dentry;
20059 + struct inode *h_dir, *inode;
20060 + struct vfsmount *h_mnt;
20061 + struct au_wr_dir_args wr_dir_args = {
20062 + .force_btgt = -1,
20063 + .flags = AuWrDir_TMPFILE
20066 + /* copy-up may happen */
20070 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20071 + if (unlikely(err))
20074 + err = au_di_init(dentry);
20075 + if (unlikely(err))
20079 + parent = d_find_any_alias(dir);
20080 + AuDebugOn(!parent);
20081 + di_write_lock_parent(parent);
20082 + if (unlikely(d_inode(parent) != dir))
20085 + err = au_digen_test(parent, au_sigen(sb));
20086 + if (unlikely(err))
20089 + bindex = au_dbtop(parent);
20090 + au_set_dbtop(dentry, bindex);
20091 + au_set_dbbot(dentry, bindex);
20092 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20094 + if (unlikely(err < 0))
20097 + err = -EOPNOTSUPP;
20098 + h_dir = au_h_iptr(dir, bindex);
20099 + if (unlikely(!h_dir->i_op->tmpfile))
20102 + h_mnt = au_sbr_mnt(sb, bindex);
20103 + err = vfsub_mnt_want_write(h_mnt);
20104 + if (unlikely(err))
20107 + h_parent = au_h_dptr(parent, bindex);
20108 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20109 + if (IS_ERR(h_dentry)) {
20110 + err = PTR_ERR(h_dentry);
20114 + au_set_dbtop(dentry, bindex);
20115 + au_set_dbbot(dentry, bindex);
20116 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20117 + inode = au_new_inode(dentry, /*must_new*/1);
20118 + if (IS_ERR(inode)) {
20119 + err = PTR_ERR(inode);
20120 + au_set_h_dptr(dentry, bindex, NULL);
20121 + au_set_dbtop(dentry, -1);
20122 + au_set_dbbot(dentry, -1);
20124 + if (!inode->i_nlink)
20125 + set_nlink(inode, 1);
20126 + d_tmpfile(dentry, inode);
20127 + au_di(dentry)->di_tmpfile = 1;
20129 + /* update without i_mutex */
20130 + if (au_ibtop(dir) == au_dbtop(dentry))
20131 + au_cpup_attr_timesizes(dir);
20136 + vfsub_mnt_drop_write(h_mnt);
20138 + di_write_unlock(parent);
20140 + di_write_unlock(dentry);
20141 + if (unlikely(err)) {
20142 + au_di_fin(dentry);
20143 + dentry->d_fsdata = NULL;
20146 + si_read_unlock(sb);
20148 + inode_unlock(dir);
20152 +/* ---------------------------------------------------------------------- */
20154 +struct au_link_args {
20155 + aufs_bindex_t bdst, bsrc;
20156 + struct au_pin pin;
20157 + struct path h_path;
20158 + struct dentry *src_parent, *parent;
20161 +static int au_cpup_before_link(struct dentry *src_dentry,
20162 + struct au_link_args *a)
20165 + struct dentry *h_src_dentry;
20166 + struct au_cp_generic cpg = {
20167 + .dentry = src_dentry,
20172 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20175 + di_read_lock_parent(a->src_parent, AuLock_IR);
20176 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20177 + if (unlikely(err))
20180 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20181 + err = au_pin(&a->pin, src_dentry, a->bdst,
20182 + au_opt_udba(src_dentry->d_sb),
20183 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20184 + if (unlikely(err))
20187 + err = au_sio_cpup_simple(&cpg);
20188 + au_unpin(&a->pin);
20191 + di_read_unlock(a->src_parent, AuLock_IR);
20195 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20196 + struct au_link_args *a)
20199 + unsigned char plink;
20200 + aufs_bindex_t bbot;
20201 + struct dentry *h_src_dentry;
20202 + struct inode *h_inode, *inode, *delegated;
20203 + struct super_block *sb;
20204 + struct file *h_file;
20208 + sb = src_dentry->d_sb;
20209 + inode = d_inode(src_dentry);
20210 + if (au_ibtop(inode) <= a->bdst)
20211 + h_inode = au_h_iptr(inode, a->bdst);
20212 + if (!h_inode || !h_inode->i_nlink) {
20213 + /* copyup src_dentry as the name of dentry. */
20214 + bbot = au_dbbot(dentry);
20215 + if (bbot < a->bsrc)
20216 + au_set_dbbot(dentry, a->bsrc);
20217 + au_set_h_dptr(dentry, a->bsrc,
20218 + dget(au_h_dptr(src_dentry, a->bsrc)));
20219 + dget(a->h_path.dentry);
20220 + au_set_h_dptr(dentry, a->bdst, NULL);
20221 + AuDbg("temporary d_inode...\n");
20222 + spin_lock(&dentry->d_lock);
20223 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20224 + spin_unlock(&dentry->d_lock);
20225 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20226 + if (IS_ERR(h_file))
20227 + err = PTR_ERR(h_file);
20229 + struct au_cp_generic cpg = {
20230 + .dentry = dentry,
20235 + .flags = AuCpup_KEEPLINO
20237 + err = au_sio_cpup_simple(&cpg);
20238 + au_h_open_post(dentry, a->bsrc, h_file);
20240 + dput(a->h_path.dentry);
20241 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20243 + au_set_h_dptr(dentry, a->bdst,
20244 + a->h_path.dentry);
20246 + spin_lock(&dentry->d_lock);
20247 + dentry->d_inode = NULL; /* restore */
20248 + spin_unlock(&dentry->d_lock);
20249 + AuDbg("temporary d_inode...done\n");
20250 + au_set_h_dptr(dentry, a->bsrc, NULL);
20251 + au_set_dbbot(dentry, bbot);
20253 + /* the inode of src_dentry already exists on a.bdst branch */
20254 + h_src_dentry = d_find_alias(h_inode);
20255 + if (!h_src_dentry && au_plink_test(inode)) {
20257 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20258 + err = PTR_ERR(h_src_dentry);
20259 + if (IS_ERR(h_src_dentry))
20262 + if (unlikely(d_is_negative(h_src_dentry))) {
20263 + dput(h_src_dentry);
20264 + h_src_dentry = NULL;
20268 + if (h_src_dentry) {
20269 + delegated = NULL;
20270 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20271 + &a->h_path, &delegated);
20272 + if (unlikely(err == -EWOULDBLOCK)) {
20273 + pr_warn("cannot retry for NFSv4 delegation"
20274 + " for an internal link\n");
20277 + dput(h_src_dentry);
20279 + AuIOErr("no dentry found for hi%lu on b%d\n",
20280 + h_inode->i_ino, a->bdst);
20285 + if (!err && !plink)
20286 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20293 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20294 + struct dentry *dentry)
20297 + struct au_dtime dt;
20298 + struct au_link_args *a;
20299 + struct dentry *wh_dentry, *h_src_dentry;
20300 + struct inode *inode, *delegated;
20301 + struct super_block *sb;
20302 + struct au_wr_dir_args wr_dir_args = {
20303 + /* .force_btgt = -1, */
20304 + .flags = AuWrDir_ADD_ENTRY
20308 + inode = d_inode(src_dentry);
20309 + IMustLock(inode);
20312 + a = kzalloc(sizeof(*a), GFP_NOFS);
20313 + if (unlikely(!a))
20316 + a->parent = dentry->d_parent; /* dir inode is locked */
20317 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20318 + AuLock_NOPLM | AuLock_GEN);
20319 + if (unlikely(err))
20321 + err = au_d_linkable(src_dentry);
20322 + if (unlikely(err))
20324 + err = au_d_may_add(dentry);
20325 + if (unlikely(err))
20328 + a->src_parent = dget_parent(src_dentry);
20329 + wr_dir_args.force_btgt = au_ibtop(inode);
20331 + di_write_lock_parent(a->parent);
20332 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20333 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20335 + err = PTR_ERR(wh_dentry);
20336 + if (IS_ERR(wh_dentry))
20340 + sb = dentry->d_sb;
20341 + a->bdst = au_dbtop(dentry);
20342 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20343 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20344 + a->bsrc = au_ibtop(inode);
20345 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20346 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20347 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20348 + if (!h_src_dentry) {
20349 + a->bsrc = au_dbtop(src_dentry);
20350 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20351 + AuDebugOn(!h_src_dentry);
20352 + } else if (IS_ERR(h_src_dentry)) {
20353 + err = PTR_ERR(h_src_dentry);
20358 + * aufs doesn't touch the credential so
20359 + * security_dentry_create_files_as() is unnecessary.
20361 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20362 + if (a->bdst < a->bsrc
20363 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20364 + err = au_cpup_or_link(src_dentry, dentry, a);
20366 + delegated = NULL;
20367 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20368 + &a->h_path, &delegated);
20369 + if (unlikely(err == -EWOULDBLOCK)) {
20370 + pr_warn("cannot retry for NFSv4 delegation"
20371 + " for an internal link\n");
20375 + dput(h_src_dentry);
20378 + * copyup src_dentry to the branch we process,
20379 + * and then link(2) to it.
20381 + dput(h_src_dentry);
20382 + if (a->bdst < a->bsrc
20383 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20384 + au_unpin(&a->pin);
20385 + di_write_unlock(a->parent);
20386 + err = au_cpup_before_link(src_dentry, a);
20387 + di_write_lock_parent(a->parent);
20389 + err = au_pin(&a->pin, dentry, a->bdst,
20391 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20392 + if (unlikely(err))
20396 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20398 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20399 + delegated = NULL;
20400 + err = vfsub_link(h_src_dentry,
20401 + au_pinned_h_dir(&a->pin),
20402 + &a->h_path, &delegated);
20403 + if (unlikely(err == -EWOULDBLOCK)) {
20404 + pr_warn("cannot retry"
20405 + " for NFSv4 delegation"
20406 + " for an internal link\n");
20412 + if (unlikely(err))
20416 + a->h_path.dentry = wh_dentry;
20417 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20419 + if (unlikely(err))
20423 + au_dir_ts(dir, a->bdst);
20424 + inode_inc_iversion(dir);
20425 + inc_nlink(inode);
20426 + inode->i_ctime = dir->i_ctime;
20427 + d_instantiate(dentry, au_igrab(inode));
20428 + if (d_unhashed(a->h_path.dentry))
20429 + /* some filesystem calls d_drop() */
20431 + /* some filesystems consume an inode even hardlink */
20432 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20433 + goto out_unpin; /* success */
20436 + /* no delegation since it is just created */
20437 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20438 + /*delegated*/NULL, /*force*/0);
20439 + if (unlikely(rerr)) {
20440 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20443 + au_dtime_revert(&dt);
20445 + au_unpin(&a->pin);
20449 + di_write_unlock(a->parent);
20450 + dput(a->src_parent);
20452 + if (unlikely(err)) {
20453 + au_update_dbtop(dentry);
20456 + aufs_read_and_write_unlock2(dentry, src_dentry);
20464 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20467 + aufs_bindex_t bindex;
20468 + unsigned char diropq;
20469 + struct path h_path;
20470 + struct dentry *wh_dentry, *parent, *opq_dentry;
20471 + struct inode *h_inode;
20472 + struct super_block *sb;
20474 + struct au_pin pin;
20475 + struct au_dtime dt;
20476 + } *a; /* reduce the stack usage */
20477 + struct au_wr_dir_args wr_dir_args = {
20478 + .force_btgt = -1,
20479 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20485 + a = kmalloc(sizeof(*a), GFP_NOFS);
20486 + if (unlikely(!a))
20489 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20490 + if (unlikely(err))
20492 + err = au_d_may_add(dentry);
20493 + if (unlikely(err))
20496 + parent = dentry->d_parent; /* dir inode is locked */
20497 + di_write_lock_parent(parent);
20498 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20499 + &a->pin, &wr_dir_args);
20500 + err = PTR_ERR(wh_dentry);
20501 + if (IS_ERR(wh_dentry))
20504 + sb = dentry->d_sb;
20505 + bindex = au_dbtop(dentry);
20506 + h_path.dentry = au_h_dptr(dentry, bindex);
20507 + h_path.mnt = au_sbr_mnt(sb, bindex);
20508 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20509 + if (unlikely(err))
20512 + /* make the dir opaque */
20514 + h_inode = d_inode(h_path.dentry);
20516 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20517 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20518 + opq_dentry = au_diropq_create(dentry, bindex);
20519 + inode_unlock(h_inode);
20520 + err = PTR_ERR(opq_dentry);
20521 + if (IS_ERR(opq_dentry))
20523 + dput(opq_dentry);
20527 + err = epilog(dir, bindex, wh_dentry, dentry);
20530 + goto out_unpin; /* success */
20535 + AuLabel(revert opq);
20536 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20537 + rerr = au_diropq_remove(dentry, bindex);
20538 + inode_unlock(h_inode);
20540 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20541 + dentry, err, rerr);
20547 + AuLabel(revert dir);
20548 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20550 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20551 + dentry, err, rerr);
20554 + au_dtime_revert(&a->dt);
20556 + au_unpin(&a->pin);
20559 + di_write_unlock(parent);
20561 + if (unlikely(err)) {
20562 + au_update_dbtop(dentry);
20565 + aufs_read_unlock(dentry, AuLock_DW);
20571 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20572 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20573 +++ linux/fs/aufs/i_op.c 2019-09-16 09:38:43.216175640 +0200
20575 +// SPDX-License-Identifier: GPL-2.0
20577 + * Copyright (C) 2005-2019 Junjiro R. Okajima
20579 + * This program, aufs is free software; you can redistribute it and/or modify
20580 + * it under the terms of the GNU General Public License as published by
20581 + * the Free Software Foundation; either version 2 of the License, or
20582 + * (at your option) any later version.
20584 + * This program is distributed in the hope that it will be useful,
20585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20587 + * GNU General Public License for more details.
20589 + * You should have received a copy of the GNU General Public License
20590 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20594 + * inode operations (except add/del/rename)
20597 +#include <linux/device_cgroup.h>
20598 +#include <linux/fs_stack.h>
20599 +#include <linux/iversion.h>
20600 +#include <linux/namei.h>
20601 +#include <linux/security.h>
20604 +static int h_permission(struct inode *h_inode, int mask,
20605 + struct path *h_path, int brperm)
20608 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20611 + if (write_mask && IS_IMMUTABLE(h_inode))
20615 + if (((mask & MAY_EXEC)
20616 + && S_ISREG(h_inode->i_mode)
20617 + && (path_noexec(h_path)
20618 + || !(h_inode->i_mode & 0111))))
20622 + * - skip the lower fs test in the case of write to ro branch.
20623 + * - nfs dir permission write check is optimized, but a policy for
20624 + * link/rename requires a real check.
20625 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20626 + * in this case, generic_permission() returns -EOPNOTSUPP.
20628 + if ((write_mask && !au_br_writable(brperm))
20629 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20630 + && write_mask && !(mask & MAY_READ))
20631 + || !h_inode->i_op->permission) {
20632 + /* AuLabel(generic_permission); */
20633 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20634 + err = generic_permission(h_inode, mask);
20635 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20636 + err = h_inode->i_op->permission(h_inode, mask);
20639 + /* AuLabel(h_inode->permission); */
20640 + err = h_inode->i_op->permission(h_inode, mask);
20645 + err = devcgroup_inode_permission(h_inode, mask);
20647 + err = security_inode_permission(h_inode, mask);
20651 + /* todo: do we need to call ima_path_check()? */
20652 + struct path h_path = {
20656 + err = ima_path_check(&h_path,
20657 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20658 + IMA_COUNT_LEAVE);
20666 +static int aufs_permission(struct inode *inode, int mask)
20669 + aufs_bindex_t bindex, bbot;
20670 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20671 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20672 + struct inode *h_inode;
20673 + struct super_block *sb;
20674 + struct au_branch *br;
20676 + /* todo: support rcu-walk? */
20677 + if (mask & MAY_NOT_BLOCK)
20680 + sb = inode->i_sb;
20681 + si_read_lock(sb, AuLock_FLUSH);
20682 + ii_read_lock_child(inode);
20684 + err = au_iigen_test(inode, au_sigen(sb));
20685 + if (unlikely(err))
20691 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20692 + err = au_busy_or_stale();
20693 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20694 + if (unlikely(!h_inode
20695 + || (h_inode->i_mode & S_IFMT)
20696 + != (inode->i_mode & S_IFMT)))
20700 + bindex = au_ibtop(inode);
20701 + br = au_sbr(sb, bindex);
20702 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20705 + && !special_file(h_inode->i_mode)) {
20706 + /* test whether the upper writable branch exists */
20708 + for (; bindex >= 0; bindex--)
20709 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20717 + /* non-write to dir */
20719 + bbot = au_ibbot(inode);
20720 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20721 + h_inode = au_h_iptr(inode, bindex);
20723 + err = au_busy_or_stale();
20724 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20727 + br = au_sbr(sb, bindex);
20728 + err = h_permission(h_inode, mask, &br->br_path,
20734 + ii_read_unlock(inode);
20735 + si_read_unlock(sb);
20739 +/* ---------------------------------------------------------------------- */
20741 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20742 + unsigned int flags)
20744 + struct dentry *ret, *parent;
20745 + struct inode *inode;
20746 + struct super_block *sb;
20747 + int err, npositive;
20751 + /* todo: support rcu-walk? */
20752 + ret = ERR_PTR(-ECHILD);
20753 + if (flags & LOOKUP_RCU)
20756 + ret = ERR_PTR(-ENAMETOOLONG);
20757 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20761 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20762 + ret = ERR_PTR(err);
20763 + if (unlikely(err))
20766 + err = au_di_init(dentry);
20767 + ret = ERR_PTR(err);
20768 + if (unlikely(err))
20772 + npositive = 0; /* suppress a warning */
20773 + parent = dentry->d_parent; /* dir inode is locked */
20774 + di_read_lock_parent(parent, AuLock_IR);
20775 + err = au_alive_dir(parent);
20777 + err = au_digen_test(parent, au_sigen(sb));
20779 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20780 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20781 + AuLkup_ALLOW_NEG);
20784 + di_read_unlock(parent, AuLock_IR);
20785 + ret = ERR_PTR(err);
20786 + if (unlikely(err < 0))
20790 + inode = au_new_inode(dentry, /*must_new*/0);
20791 + if (IS_ERR(inode)) {
20792 + ret = (void *)inode;
20799 + atomic_inc(&inode->i_count);
20800 + ret = d_splice_alias(inode, dentry);
20802 + if (unlikely(d_need_lookup(dentry))) {
20803 + spin_lock(&dentry->d_lock);
20804 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20805 + spin_unlock(&dentry->d_lock);
20809 + if (!IS_ERR(ret)) {
20811 + if (ret && ret != dentry)
20812 + ii_write_unlock(inode);
20814 + ii_write_unlock(inode);
20821 + di_write_unlock(dentry);
20823 + si_read_unlock(sb);
20828 +/* ---------------------------------------------------------------------- */
20831 + * very dirty and complicated aufs ->atomic_open().
20832 + * aufs_atomic_open()
20833 + * + au_aopen_or_create()
20835 + * + vfsub_atomic_open()
20836 + * + branch fs ->atomic_open()
20837 + * may call the actual 'open' for h_file
20838 + * + inc br_nfiles only if opened
20839 + * + au_aopen_no_open() or au_aopen_do_open()
20841 + * au_aopen_do_open()
20842 + * + finish_open()
20843 + * + au_do_aopen()
20844 + * + au_do_open() the body of all 'open'
20845 + * + au_do_open_nondir()
20846 + * set the passed h_file
20848 + * au_aopen_no_open()
20849 + * + finish_no_open()
20852 +struct aopen_node {
20853 + struct hlist_bl_node hblist;
20854 + struct file *file, *h_file;
20857 +static int au_do_aopen(struct inode *inode, struct file *file)
20859 + struct hlist_bl_head *aopen;
20860 + struct hlist_bl_node *pos;
20861 + struct aopen_node *node;
20862 + struct au_do_open_args args = {
20864 + .open = au_do_open_nondir
20867 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20868 + hlist_bl_lock(aopen);
20869 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20870 + if (node->file == file) {
20871 + args.h_file = node->h_file;
20874 + hlist_bl_unlock(aopen);
20875 + /* AuDebugOn(!args.h_file); */
20877 + return au_do_open(file, &args);
20880 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20881 + struct aopen_node *aopen_node)
20884 + struct hlist_bl_head *aopen;
20887 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20888 + au_hbl_add(&aopen_node->hblist, aopen);
20889 + err = finish_open(file, dentry, au_do_aopen);
20890 + au_hbl_del(&aopen_node->hblist, aopen);
20891 + /* AuDbgFile(file); */
20892 + AuDbg("%pd%s%s\n", dentry,
20893 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20894 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20900 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20906 + err = finish_no_open(file, dentry);
20912 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20913 + struct file *file, unsigned int open_flag,
20914 + umode_t create_mode)
20916 + int err, did_open;
20917 + unsigned int lkup_flags;
20918 + aufs_bindex_t bindex;
20919 + struct super_block *sb;
20920 + struct dentry *parent, *d;
20921 + struct vfsub_aopen_args args = {
20922 + .open_flag = open_flag,
20923 + .create_mode = create_mode
20925 + struct aopen_node aopen_node = {
20930 + AuDbg("open_flag 0%o\n", open_flag);
20931 + AuDbgDentry(dentry);
20934 + if (!au_di(dentry)) {
20935 + lkup_flags = LOOKUP_OPEN;
20936 + if (open_flag & O_CREAT)
20937 + lkup_flags |= LOOKUP_CREATE;
20938 + d = aufs_lookup(dir, dentry, lkup_flags);
20940 + err = PTR_ERR(d);
20945 + * obsoleted dentry found.
20946 + * another error will be returned later.
20952 + AuDbgDentry(dentry);
20955 + if (d_is_positive(dentry)
20956 + || d_unhashed(dentry)
20957 + || d_unlinked(dentry)
20958 + || !(open_flag & O_CREAT)) {
20959 + err = au_aopen_no_open(file, dentry);
20960 + goto out; /* success */
20963 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20964 + if (unlikely(err))
20967 + sb = dentry->d_sb;
20968 + parent = dentry->d_parent; /* dir is locked */
20969 + di_write_lock_parent(parent);
20970 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20971 + if (unlikely(err < 0))
20974 + AuDbgDentry(dentry);
20975 + if (d_is_positive(dentry)) {
20976 + err = au_aopen_no_open(file, dentry);
20977 + goto out_parent; /* success */
20980 + args.file = alloc_empty_file(file->f_flags, current_cred());
20981 + err = PTR_ERR(args.file);
20982 + if (IS_ERR(args.file))
20985 + bindex = au_dbtop(dentry);
20986 + err = au_aopen_or_create(dir, dentry, &args);
20988 + AuDbgFile(args.file);
20989 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20990 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20993 + args.file = NULL;
20995 + di_write_unlock(parent);
20996 + di_write_unlock(dentry);
20997 + if (unlikely(err < 0)) {
21004 + err = au_aopen_no_open(file, dentry);
21006 + aopen_node.h_file = args.file;
21007 + err = au_aopen_do_open(file, dentry, &aopen_node);
21009 + if (unlikely(err < 0)) {
21013 + au_lcnt_dec(&args.br->br_nfiles);
21015 + goto out_sb; /* success */
21018 + di_write_unlock(parent);
21019 + di_write_unlock(dentry);
21021 + si_read_unlock(sb);
21029 +/* ---------------------------------------------------------------------- */
21031 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21032 + const unsigned char add_entry, aufs_bindex_t bcpup,
21033 + aufs_bindex_t btop)
21036 + struct dentry *h_parent;
21037 + struct inode *h_dir;
21040 + IMustLock(d_inode(parent));
21042 + di_write_lock_parent(parent);
21045 + if (!au_h_dptr(parent, bcpup)) {
21046 + if (btop > bcpup)
21047 + err = au_cpup_dirs(dentry, bcpup);
21048 + else if (btop < bcpup)
21049 + err = au_cpdown_dirs(dentry, bcpup);
21053 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21054 + h_parent = au_h_dptr(parent, bcpup);
21055 + h_dir = d_inode(h_parent);
21056 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21057 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21058 + /* todo: no unlock here */
21059 + inode_unlock_shared(h_dir);
21061 + AuDbg("bcpup %d\n", bcpup);
21063 + if (d_really_is_negative(dentry))
21064 + au_set_h_dptr(dentry, btop, NULL);
21065 + au_update_dbrange(dentry, /*do_put_zero*/0);
21070 + di_write_unlock(parent);
21072 + err = bcpup; /* success */
21079 + * decide the branch and the parent dir where we will create a new entry.
21080 + * returns new bindex or an error.
21081 + * copyup the parent dir if needed.
21083 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21084 + struct au_wr_dir_args *args)
21087 + unsigned int flags;
21088 + aufs_bindex_t bcpup, btop, src_btop;
21089 + const unsigned char add_entry
21090 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21091 + | au_ftest_wrdir(args->flags, TMPFILE);
21092 + struct super_block *sb;
21093 + struct dentry *parent;
21094 + struct au_sbinfo *sbinfo;
21096 + sb = dentry->d_sb;
21097 + sbinfo = au_sbi(sb);
21098 + parent = dget_parent(dentry);
21099 + btop = au_dbtop(dentry);
21101 + if (args->force_btgt < 0) {
21102 + if (src_dentry) {
21103 + src_btop = au_dbtop(src_dentry);
21104 + if (src_btop < btop)
21105 + bcpup = src_btop;
21106 + } else if (add_entry) {
21108 + if (au_ftest_wrdir(args->flags, ISDIR))
21109 + au_fset_wbr(flags, DIR);
21110 + err = AuWbrCreate(sbinfo, dentry, flags);
21114 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21116 + err = AuWbrCopyup(sbinfo, dentry);
21118 + if (!IS_ROOT(dentry)) {
21119 + di_read_lock_parent(parent, !AuLock_IR);
21120 + err = AuWbrCopyup(sbinfo, dentry);
21121 + di_read_unlock(parent, !AuLock_IR);
21123 + err = AuWbrCopyup(sbinfo, dentry);
21126 + if (unlikely(err < 0))
21130 + bcpup = args->force_btgt;
21131 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21134 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21136 + if (bcpup == btop)
21137 + goto out; /* success */
21139 + /* copyup the new parent into the branch we process */
21140 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21142 + if (d_really_is_negative(dentry)) {
21143 + au_set_h_dptr(dentry, btop, NULL);
21144 + au_set_dbtop(dentry, bcpup);
21145 + au_set_dbbot(dentry, bcpup);
21147 + AuDebugOn(add_entry
21148 + && !au_ftest_wrdir(args->flags, TMPFILE)
21149 + && !au_h_dptr(dentry, bcpup));
21157 +/* ---------------------------------------------------------------------- */
21159 +void au_pin_hdir_unlock(struct au_pin *p)
21162 + au_hn_inode_unlock(p->hdir);
21165 +int au_pin_hdir_lock(struct au_pin *p)
21173 + /* even if an error happens later, keep this lock */
21174 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21177 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21182 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21183 + p->h_parent, p->br);
21189 +int au_pin_hdir_relock(struct au_pin *p)
21192 + struct inode *h_i;
21193 + struct dentry *h_d[] = {
21198 + err = au_pin_hdir_lock(p);
21199 + if (unlikely(err))
21202 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21205 + if (d_is_positive(h_d[i])) {
21206 + h_i = d_inode(h_d[i]);
21207 + err = !h_i->i_nlink;
21215 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21217 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21220 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21223 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21224 + p->lsc_hi, 0, NULL, _RET_IP_);
21225 + au_pin_hdir_set_owner(p, current);
21229 +void au_pin_hdir_release(struct au_pin *p)
21232 + au_pin_hdir_set_owner(p, p->task);
21233 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21237 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21239 + if (pin && pin->parent)
21240 + return au_h_dptr(pin->parent, pin->bindex);
21244 +void au_unpin(struct au_pin *p)
21247 + au_pin_hdir_unlock(p);
21248 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21249 + vfsub_mnt_drop_write(p->h_mnt);
21253 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21254 + di_read_unlock(p->parent, AuLock_IR);
21255 + iput(p->hdir->hi_inode);
21257 + p->parent = NULL;
21260 + /* do not clear p->task */
21263 +int au_do_pin(struct au_pin *p)
21266 + struct super_block *sb;
21267 + struct inode *h_dir;
21270 + sb = p->dentry->d_sb;
21271 + p->br = au_sbr(sb, p->bindex);
21272 + if (IS_ROOT(p->dentry)) {
21273 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21274 + p->h_mnt = au_br_mnt(p->br);
21275 + err = vfsub_mnt_want_write(p->h_mnt);
21276 + if (unlikely(err)) {
21277 + au_fclr_pin(p->flags, MNT_WRITE);
21284 + p->h_dentry = NULL;
21285 + if (p->bindex <= au_dbbot(p->dentry))
21286 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21288 + p->parent = dget_parent(p->dentry);
21289 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21290 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21293 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21294 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21296 + h_dir = p->hdir->hi_inode;
21300 + * if DI_LOCKED is not set, then p->parent may be different
21301 + * and h_parent can be NULL.
21303 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21305 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21306 + di_read_unlock(p->parent, AuLock_IR);
21308 + p->parent = NULL;
21312 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21313 + p->h_mnt = au_br_mnt(p->br);
21314 + err = vfsub_mnt_want_write(p->h_mnt);
21315 + if (unlikely(err)) {
21316 + au_fclr_pin(p->flags, MNT_WRITE);
21317 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21318 + di_read_unlock(p->parent, AuLock_IR);
21320 + p->parent = NULL;
21326 + err = au_pin_hdir_lock(p);
21328 + goto out; /* success */
21333 + pr_err("err %d\n", err);
21334 + err = au_busy_or_stale();
21339 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21340 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21341 + unsigned int udba, unsigned char flags)
21343 + p->dentry = dentry;
21345 + p->lsc_di = lsc_di;
21346 + p->lsc_hi = lsc_hi;
21347 + p->flags = flags;
21348 + p->bindex = bindex;
21350 + p->parent = NULL;
21354 + p->h_dentry = NULL;
21355 + p->h_parent = NULL;
21357 + p->task = current;
21360 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21361 + unsigned int udba, unsigned char flags)
21363 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21365 + return au_do_pin(pin);
21368 +/* ---------------------------------------------------------------------- */
21371 + * ->setattr() and ->getattr() are called in various cases.
21372 + * chmod, stat: dentry is revalidated.
21373 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21375 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21377 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21378 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21381 + struct dentry *parent;
21384 + if (au_digen_test(dentry, sigen)) {
21385 + parent = dget_parent(dentry);
21386 + di_read_lock_parent(parent, AuLock_IR);
21387 + err = au_refresh_dentry(dentry, parent);
21388 + di_read_unlock(parent, AuLock_IR);
21396 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21397 + struct au_icpup_args *a)
21401 + aufs_bindex_t btop, ibtop;
21402 + struct dentry *hi_wh, *parent;
21403 + struct inode *inode;
21404 + struct au_wr_dir_args wr_dir_args = {
21405 + .force_btgt = -1,
21409 + if (d_is_dir(dentry))
21410 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21411 + /* plink or hi_wh() case */
21412 + btop = au_dbtop(dentry);
21413 + inode = d_inode(dentry);
21414 + ibtop = au_ibtop(inode);
21415 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21416 + wr_dir_args.force_btgt = ibtop;
21417 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21418 + if (unlikely(err < 0))
21422 + au_fset_icpup(a->flags, DID_CPUP);
21425 + a->pin_flags = AuPin_MNT_WRITE;
21427 + if (!IS_ROOT(dentry)) {
21428 + au_fset_pin(a->pin_flags, DI_LOCKED);
21429 + parent = dget_parent(dentry);
21430 + di_write_lock_parent(parent);
21433 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21434 + if (unlikely(err))
21438 + a->h_path.dentry = au_h_dptr(dentry, btop);
21439 + a->h_inode = d_inode(a->h_path.dentry);
21440 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21441 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21442 + if (ia->ia_size < i_size_read(a->h_inode))
21443 + sz = ia->ia_size;
21444 + inode_unlock_shared(a->h_inode);
21448 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21449 + hi_wh = au_hi_wh(inode, a->btgt);
21451 + struct au_cp_generic cpg = {
21452 + .dentry = dentry,
21458 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21459 + if (unlikely(err))
21461 + hi_wh = au_hi_wh(inode, a->btgt);
21462 + /* todo: revalidate hi_wh? */
21467 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21468 + di_downgrade_lock(parent, AuLock_IR);
21472 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21473 + goto out; /* success */
21475 + if (!d_unhashed(dentry)) {
21476 + struct au_cp_generic cpg = {
21477 + .dentry = dentry,
21482 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21484 + err = au_sio_cpup_simple(&cpg);
21486 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21487 + } else if (!hi_wh)
21488 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21490 + a->h_path.dentry = hi_wh; /* do not dget here */
21493 + a->h_inode = d_inode(a->h_path.dentry);
21495 + goto out; /* success */
21496 + au_unpin(&a->pin);
21499 + di_write_unlock(parent);
21504 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21508 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21511 + struct inode *inode, *delegated;
21512 + struct super_block *sb;
21513 + struct file *file;
21514 + struct au_icpup_args *a;
21516 + inode = d_inode(dentry);
21517 + IMustLock(inode);
21519 + err = setattr_prepare(dentry, ia);
21520 + if (unlikely(err))
21524 + a = kzalloc(sizeof(*a), GFP_NOFS);
21525 + if (unlikely(!a))
21528 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21529 + ia->ia_valid &= ~ATTR_MODE;
21532 + sb = dentry->d_sb;
21533 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21534 + if (unlikely(err))
21537 + if (ia->ia_valid & ATTR_FILE) {
21538 + /* currently ftruncate(2) only */
21539 + AuDebugOn(!d_is_reg(dentry));
21540 + file = ia->ia_file;
21541 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21543 + if (unlikely(err))
21545 + ia->ia_file = au_hf_top(file);
21546 + a->udba = AuOpt_UDBA_NONE;
21548 + /* fchmod() doesn't pass ia_file */
21549 + a->udba = au_opt_udba(sb);
21550 + di_write_lock_child(dentry);
21551 + /* no d_unlinked(), to set UDBA_NONE for root */
21552 + if (d_unhashed(dentry))
21553 + a->udba = AuOpt_UDBA_NONE;
21554 + if (a->udba != AuOpt_UDBA_NONE) {
21555 + AuDebugOn(IS_ROOT(dentry));
21556 + err = au_reval_for_attr(dentry, au_sigen(sb));
21557 + if (unlikely(err))
21562 + err = au_pin_and_icpup(dentry, ia, a);
21563 + if (unlikely(err < 0))
21565 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21566 + ia->ia_file = NULL;
21567 + ia->ia_valid &= ~ATTR_FILE;
21570 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21571 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21572 + == (ATTR_MODE | ATTR_CTIME)) {
21573 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21574 + if (unlikely(err))
21576 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21577 + && (ia->ia_valid & ATTR_CTIME)) {
21578 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21579 + if (unlikely(err))
21583 + if (ia->ia_valid & ATTR_SIZE) {
21586 + if (ia->ia_size < i_size_read(inode))
21588 + truncate_setsize(inode, ia->ia_size);
21591 + if (ia->ia_valid & ATTR_FILE)
21593 + inode_unlock(a->h_inode);
21594 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21595 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21597 + delegated = NULL;
21599 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21601 + err = break_deleg_wait(&delegated);
21609 + * regardless aufs 'acl' option setting.
21610 + * why don't all acl-aware fs call this func from their ->setattr()?
21612 + if (!err && (ia->ia_valid & ATTR_MODE))
21613 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21615 + au_cpup_attr_changeable(inode);
21618 + inode_unlock(a->h_inode);
21619 + au_unpin(&a->pin);
21620 + if (unlikely(err))
21621 + au_update_dbtop(dentry);
21623 + di_write_unlock(dentry);
21625 + fi_write_unlock(file);
21626 + ia->ia_file = file;
21627 + ia->ia_valid |= ATTR_FILE;
21630 + si_read_unlock(sb);
21638 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21639 +static int au_h_path_to_set_attr(struct dentry *dentry,
21640 + struct au_icpup_args *a, struct path *h_path)
21643 + struct super_block *sb;
21645 + sb = dentry->d_sb;
21646 + a->udba = au_opt_udba(sb);
21647 + /* no d_unlinked(), to set UDBA_NONE for root */
21648 + if (d_unhashed(dentry))
21649 + a->udba = AuOpt_UDBA_NONE;
21650 + if (a->udba != AuOpt_UDBA_NONE) {
21651 + AuDebugOn(IS_ROOT(dentry));
21652 + err = au_reval_for_attr(dentry, au_sigen(sb));
21653 + if (unlikely(err))
21656 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21657 + if (unlikely(err < 0))
21660 + h_path->dentry = a->h_path.dentry;
21661 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21667 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21668 + struct au_sxattr *arg)
21671 + struct path h_path;
21672 + struct super_block *sb;
21673 + struct au_icpup_args *a;
21674 + struct inode *h_inode;
21676 + IMustLock(inode);
21679 + a = kzalloc(sizeof(*a), GFP_NOFS);
21680 + if (unlikely(!a))
21683 + sb = dentry->d_sb;
21684 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21685 + if (unlikely(err))
21688 + h_path.dentry = NULL; /* silence gcc */
21689 + di_write_lock_child(dentry);
21690 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21691 + if (unlikely(err))
21694 + inode_unlock(a->h_inode);
21695 + switch (arg->type) {
21696 + case AU_XATTR_SET:
21697 + AuDebugOn(d_is_negative(h_path.dentry));
21698 + err = vfsub_setxattr(h_path.dentry,
21699 + arg->u.set.name, arg->u.set.value,
21700 + arg->u.set.size, arg->u.set.flags);
21703 + err = -EOPNOTSUPP;
21704 + h_inode = d_inode(h_path.dentry);
21705 + if (h_inode->i_op->set_acl)
21706 + /* this will call posix_acl_update_mode */
21707 + err = h_inode->i_op->set_acl(h_inode,
21708 + arg->u.acl_set.acl,
21709 + arg->u.acl_set.type);
21713 + au_cpup_attr_timesizes(inode);
21715 + au_unpin(&a->pin);
21716 + if (unlikely(err))
21717 + au_update_dbtop(dentry);
21720 + di_write_unlock(dentry);
21721 + si_read_unlock(sb);
21730 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21731 + unsigned int nlink)
21735 + inode->i_mode = st->mode;
21736 + /* don't i_[ug]id_write() here */
21737 + inode->i_uid = st->uid;
21738 + inode->i_gid = st->gid;
21739 + inode->i_atime = st->atime;
21740 + inode->i_mtime = st->mtime;
21741 + inode->i_ctime = st->ctime;
21743 + au_cpup_attr_nlink(inode, /*force*/0);
21744 + if (S_ISDIR(inode->i_mode)) {
21745 + n = inode->i_nlink;
21748 + smp_mb(); /* for i_nlink */
21749 + /* 0 can happen */
21750 + set_nlink(inode, n);
21753 + spin_lock(&inode->i_lock);
21754 + inode->i_blocks = st->blocks;
21755 + i_size_write(inode, st->size);
21756 + spin_unlock(&inode->i_lock);
21760 + * common routine for aufs_getattr() and au_getxattr().
21761 + * returns zero or negative (an error).
21762 + * @dentry will be read-locked in success.
21764 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21768 + unsigned int mnt_flags, sigen;
21769 + unsigned char udba_none;
21770 + aufs_bindex_t bindex;
21771 + struct super_block *sb, *h_sb;
21772 + struct inode *inode;
21774 + h_path->mnt = NULL;
21775 + h_path->dentry = NULL;
21778 + sb = dentry->d_sb;
21779 + mnt_flags = au_mntflags(sb);
21780 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21782 + if (unlikely(locked))
21783 + goto body; /* skip locking dinfo */
21785 + /* support fstat(2) */
21786 + if (!d_unlinked(dentry) && !udba_none) {
21787 + sigen = au_sigen(sb);
21788 + err = au_digen_test(dentry, sigen);
21790 + di_read_lock_child(dentry, AuLock_IR);
21791 + err = au_dbrange_test(dentry);
21792 + if (unlikely(err)) {
21793 + di_read_unlock(dentry, AuLock_IR);
21797 + AuDebugOn(IS_ROOT(dentry));
21798 + di_write_lock_child(dentry);
21799 + err = au_dbrange_test(dentry);
21801 + err = au_reval_for_attr(dentry, sigen);
21803 + di_downgrade_lock(dentry, AuLock_IR);
21805 + di_write_unlock(dentry);
21810 + di_read_lock_child(dentry, AuLock_IR);
21813 + inode = d_inode(dentry);
21814 + bindex = au_ibtop(inode);
21815 + h_path->mnt = au_sbr_mnt(sb, bindex);
21816 + h_sb = h_path->mnt->mnt_sb;
21818 + && !au_test_fs_bad_iattr(h_sb)
21820 + goto out; /* success */
21822 + if (au_dbtop(dentry) == bindex)
21823 + h_path->dentry = au_h_dptr(dentry, bindex);
21824 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21825 + h_path->dentry = au_plink_lkup(inode, bindex);
21826 + if (IS_ERR(h_path->dentry))
21827 + /* pretending success */
21828 + h_path->dentry = NULL;
21830 + dput(h_path->dentry);
21837 +static int aufs_getattr(const struct path *path, struct kstat *st,
21838 + u32 request, unsigned int query)
21841 + unsigned char positive;
21842 + struct path h_path;
21843 + struct dentry *dentry;
21844 + struct inode *inode;
21845 + struct super_block *sb;
21847 + dentry = path->dentry;
21848 + inode = d_inode(dentry);
21849 + sb = dentry->d_sb;
21850 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21851 + if (unlikely(err))
21853 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21854 + if (unlikely(err))
21856 + if (unlikely(!h_path.dentry))
21857 + /* illegally overlapped or something */
21858 + goto out_fill; /* pretending success */
21860 + positive = d_is_positive(h_path.dentry);
21862 + /* no vfsub version */
21863 + err = vfs_getattr(&h_path, st, request, query);
21866 + au_refresh_iattr(inode, st,
21867 + d_inode(h_path.dentry)->i_nlink);
21868 + goto out_fill; /* success */
21874 + generic_fillattr(inode, st);
21876 + di_read_unlock(dentry, AuLock_IR);
21878 + si_read_unlock(sb);
21884 +/* ---------------------------------------------------------------------- */
21886 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21887 + struct delayed_call *done)
21890 + struct dentry *h_dentry;
21891 + struct inode *h_inode;
21893 + aufs_bindex_t bindex;
21895 + ret = NULL; /* suppress a warning */
21900 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21901 + if (unlikely(err))
21904 + err = au_d_hashed_positive(dentry);
21905 + if (unlikely(err))
21909 + inode = d_inode(dentry);
21910 + bindex = au_ibtop(inode);
21911 + h_inode = au_h_iptr(inode, bindex);
21912 + if (unlikely(!h_inode->i_op->get_link))
21917 + if (au_dbtop(dentry) <= bindex) {
21918 + h_dentry = au_h_dptr(dentry, bindex);
21923 + h_dentry = d_find_any_alias(h_inode);
21924 + if (IS_ERR(h_dentry)) {
21925 + err = PTR_ERR(h_dentry);
21929 + if (unlikely(!h_dentry))
21933 + AuDbg("%ps\n", h_inode->i_op->get_link);
21934 + AuDbgDentry(h_dentry);
21935 + ret = vfs_get_link(h_dentry, done);
21938 + err = PTR_ERR(ret);
21941 + aufs_read_unlock(dentry, AuLock_IR);
21943 + if (unlikely(err))
21944 + ret = ERR_PTR(err);
21945 + AuTraceErrPtr(ret);
21949 +/* ---------------------------------------------------------------------- */
21951 +static int au_is_special(struct inode *inode)
21953 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21956 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21960 + aufs_bindex_t bindex;
21961 + struct super_block *sb;
21962 + struct inode *h_inode;
21963 + struct vfsmount *h_mnt;
21965 + sb = inode->i_sb;
21966 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21967 + "unexpected s_flags 0x%lx", sb->s_flags);
21969 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21971 + si_read_lock(sb, AuLock_FLUSH);
21972 + ii_write_lock_child(inode);
21975 + bindex = au_ibtop(inode);
21976 + h_inode = au_h_iptr(inode, bindex);
21977 + if (!au_test_ro(sb, bindex, inode)) {
21978 + h_mnt = au_sbr_mnt(sb, bindex);
21979 + err = vfsub_mnt_want_write(h_mnt);
21981 + err = vfsub_update_time(h_inode, ts, flags);
21982 + vfsub_mnt_drop_write(h_mnt);
21984 + } else if (au_is_special(h_inode)) {
21986 + * Never copy-up here.
21987 + * These special files may already be opened and used for
21988 + * communicating. If we copied it up, then the communication
21989 + * would be corrupted.
21991 + AuWarn1("timestamps for i%lu are ignored "
21992 + "since it is on readonly branch (hi%lu).\n",
21993 + inode->i_ino, h_inode->i_ino);
21994 + } else if (flags & ~S_ATIME) {
21996 + AuIOErr1("unexpected flags 0x%x\n", flags);
22001 + au_cpup_attr_timesizes(inode);
22002 + ii_write_unlock(inode);
22003 + si_read_unlock(sb);
22006 + if (!err && (flags & S_VERSION))
22007 + inode_inc_iversion(inode);
22012 +/* ---------------------------------------------------------------------- */
22014 +/* no getattr version will be set by module.c:aufs_init() */
22015 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22017 + [AuIop_SYMLINK] = {
22018 + .permission = aufs_permission,
22019 +#ifdef CONFIG_FS_POSIX_ACL
22020 + .get_acl = aufs_get_acl,
22021 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22024 + .setattr = aufs_setattr,
22025 + .getattr = aufs_getattr,
22027 +#ifdef CONFIG_AUFS_XATTR
22028 + .listxattr = aufs_listxattr,
22031 + .get_link = aufs_get_link,
22033 + /* .update_time = aufs_update_time */
22036 + .create = aufs_create,
22037 + .lookup = aufs_lookup,
22038 + .link = aufs_link,
22039 + .unlink = aufs_unlink,
22040 + .symlink = aufs_symlink,
22041 + .mkdir = aufs_mkdir,
22042 + .rmdir = aufs_rmdir,
22043 + .mknod = aufs_mknod,
22044 + .rename = aufs_rename,
22046 + .permission = aufs_permission,
22047 +#ifdef CONFIG_FS_POSIX_ACL
22048 + .get_acl = aufs_get_acl,
22049 + .set_acl = aufs_set_acl,
22052 + .setattr = aufs_setattr,
22053 + .getattr = aufs_getattr,
22055 +#ifdef CONFIG_AUFS_XATTR
22056 + .listxattr = aufs_listxattr,
22059 + .update_time = aufs_update_time,
22060 + .atomic_open = aufs_atomic_open,
22061 + .tmpfile = aufs_tmpfile
22063 + [AuIop_OTHER] = {
22064 + .permission = aufs_permission,
22065 +#ifdef CONFIG_FS_POSIX_ACL
22066 + .get_acl = aufs_get_acl,
22067 + .set_acl = aufs_set_acl,
22070 + .setattr = aufs_setattr,
22071 + .getattr = aufs_getattr,
22073 +#ifdef CONFIG_AUFS_XATTR
22074 + .listxattr = aufs_listxattr,
22077 + .update_time = aufs_update_time
22080 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22081 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22082 +++ linux/fs/aufs/i_op_del.c 2019-07-11 15:42:14.468904634 +0200
22084 +// SPDX-License-Identifier: GPL-2.0
22086 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22088 + * This program, aufs is free software; you can redistribute it and/or modify
22089 + * it under the terms of the GNU General Public License as published by
22090 + * the Free Software Foundation; either version 2 of the License, or
22091 + * (at your option) any later version.
22093 + * This program is distributed in the hope that it will be useful,
22094 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22095 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22096 + * GNU General Public License for more details.
22098 + * You should have received a copy of the GNU General Public License
22099 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22103 + * inode operations (del entry)
22106 +#include <linux/iversion.h>
22110 + * decide if a new whiteout for @dentry is necessary or not.
22111 + * when it is necessary, prepare the parent dir for the upper branch whose
22112 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22113 + * be done by caller.
22115 + * 0: wh is unnecessary
22116 + * plus: wh is necessary
22119 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22121 + int need_wh, err;
22122 + aufs_bindex_t btop;
22123 + struct super_block *sb;
22125 + sb = dentry->d_sb;
22126 + btop = au_dbtop(dentry);
22127 + if (*bcpup < 0) {
22129 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22130 + err = AuWbrCopyup(au_sbi(sb), dentry);
22132 + if (unlikely(err < 0))
22136 + AuDebugOn(btop < *bcpup
22137 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22138 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22140 + if (*bcpup != btop) {
22141 + err = au_cpup_dirs(dentry, *bcpup);
22142 + if (unlikely(err))
22146 + struct au_dinfo *dinfo, *tmp;
22148 + need_wh = -ENOMEM;
22149 + dinfo = au_di(dentry);
22150 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22152 + au_di_cp(tmp, dinfo);
22153 + au_di_swap(tmp, dinfo);
22154 + /* returns the number of positive dentries */
22155 + need_wh = au_lkup_dentry(dentry, btop + 1,
22156 + /* AuLkup_IGNORE_PERM */ 0);
22157 + au_di_swap(tmp, dinfo);
22158 + au_rw_write_unlock(&tmp->di_rwsem);
22162 + AuDbg("need_wh %d\n", need_wh);
22170 + * simple tests for the del-entry operations.
22171 + * following the checks in vfs, plus the parent-child relationship.
22173 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22174 + struct dentry *h_parent, int isdir)
22178 + struct dentry *h_dentry, *h_latest;
22179 + struct inode *h_inode;
22181 + h_dentry = au_h_dptr(dentry, bindex);
22182 + if (d_really_is_positive(dentry)) {
22184 + if (unlikely(d_is_negative(h_dentry)))
22186 + h_inode = d_inode(h_dentry);
22187 + if (unlikely(!h_inode->i_nlink))
22190 + h_mode = h_inode->i_mode;
22193 + if (unlikely(S_ISDIR(h_mode)))
22195 + } else if (unlikely(!S_ISDIR(h_mode))) {
22200 + /* rename(2) case */
22202 + if (unlikely(d_is_positive(h_dentry)))
22207 + /* expected parent dir is locked */
22208 + if (unlikely(h_parent != h_dentry->d_parent))
22213 + * rmdir a dir may break the consistency on some filesystem.
22214 + * let's try heavy test.
22217 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22218 + && au_test_h_perm(d_inode(h_parent),
22219 + MAY_EXEC | MAY_WRITE)))
22222 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22224 + if (IS_ERR(h_latest))
22226 + if (h_latest == h_dentry)
22235 + * decide the branch where we operate for @dentry. the branch index will be set
22236 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22237 + * dir for reverting.
22238 + * when a new whiteout is necessary, create it.
22240 +static struct dentry*
22241 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22242 + struct au_dtime *dt, struct au_pin *pin)
22244 + struct dentry *wh_dentry;
22245 + struct super_block *sb;
22246 + struct path h_path;
22247 + int err, need_wh;
22248 + unsigned int udba;
22249 + aufs_bindex_t bcpup;
22251 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22252 + wh_dentry = ERR_PTR(need_wh);
22253 + if (unlikely(need_wh < 0))
22256 + sb = dentry->d_sb;
22257 + udba = au_opt_udba(sb);
22259 + err = au_pin(pin, dentry, bcpup, udba,
22260 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22261 + wh_dentry = ERR_PTR(err);
22262 + if (unlikely(err))
22265 + h_path.dentry = au_pinned_h_parent(pin);
22266 + if (udba != AuOpt_UDBA_NONE
22267 + && au_dbtop(dentry) == bcpup) {
22268 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22269 + wh_dentry = ERR_PTR(err);
22270 + if (unlikely(err))
22274 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22275 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22276 + wh_dentry = NULL;
22278 + goto out; /* success, no need to create whiteout */
22280 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22281 + if (IS_ERR(wh_dentry))
22284 + /* returns with the parent is locked and wh_dentry is dget-ed */
22285 + goto out; /* success */
22290 + return wh_dentry;
22294 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22295 + * in order to be revertible and save time for removing many child whiteouts
22297 + * returns 1 when there are too many child whiteout and caller should remove
22298 + * them asynchronously. returns 0 when the number of children is enough small to
22299 + * remove now or the branch fs is a remote fs.
22300 + * otherwise return an error.
22302 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22303 + struct au_nhash *whlist, struct inode *dir)
22305 + int rmdir_later, err, dirwh;
22306 + struct dentry *h_dentry;
22307 + struct super_block *sb;
22308 + struct inode *inode;
22310 + sb = dentry->d_sb;
22311 + SiMustAnyLock(sb);
22312 + h_dentry = au_h_dptr(dentry, bindex);
22313 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22314 + if (unlikely(err))
22317 + /* stop monitoring */
22318 + inode = d_inode(dentry);
22319 + au_hn_free(au_hi(inode, bindex));
22321 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22322 + dirwh = au_sbi(sb)->si_dirwh;
22323 + rmdir_later = (dirwh <= 1);
22324 + if (!rmdir_later)
22325 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22328 + return rmdir_later;
22331 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22332 + if (unlikely(err)) {
22333 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22334 + h_dentry, bindex, err);
22344 + * final procedure for deleting a entry.
22345 + * maintain dentry and iattr.
22347 +static void epilog(struct inode *dir, struct dentry *dentry,
22348 + aufs_bindex_t bindex)
22350 + struct inode *inode;
22352 + inode = d_inode(dentry);
22354 + inode->i_ctime = dir->i_ctime;
22356 + au_dir_ts(dir, bindex);
22357 + inode_inc_iversion(dir);
22361 + * when an error happened, remove the created whiteout and revert everything.
22363 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22364 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22365 + struct dentry *dentry, struct au_dtime *dt)
22368 + struct path h_path = {
22369 + .dentry = wh_dentry,
22370 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22373 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22375 + au_set_dbwh(dentry, bwh);
22376 + au_dtime_revert(dt);
22380 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22384 +/* ---------------------------------------------------------------------- */
22386 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22389 + aufs_bindex_t bwh, bindex, btop;
22390 + struct inode *inode, *h_dir, *delegated;
22391 + struct dentry *parent, *wh_dentry;
22392 + /* to reduce stack size */
22394 + struct au_dtime dt;
22395 + struct au_pin pin;
22396 + struct path h_path;
22402 + a = kmalloc(sizeof(*a), GFP_NOFS);
22403 + if (unlikely(!a))
22406 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22407 + if (unlikely(err))
22409 + err = au_d_hashed_positive(dentry);
22410 + if (unlikely(err))
22412 + inode = d_inode(dentry);
22413 + IMustLock(inode);
22415 + if (unlikely(d_is_dir(dentry)))
22416 + goto out_unlock; /* possible? */
22418 + btop = au_dbtop(dentry);
22419 + bwh = au_dbwh(dentry);
22421 + parent = dentry->d_parent; /* dir inode is locked */
22422 + di_write_lock_parent(parent);
22423 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22425 + err = PTR_ERR(wh_dentry);
22426 + if (IS_ERR(wh_dentry))
22429 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22430 + a->h_path.dentry = au_h_dptr(dentry, btop);
22431 + dget(a->h_path.dentry);
22432 + if (bindex == btop) {
22433 + h_dir = au_pinned_h_dir(&a->pin);
22434 + delegated = NULL;
22435 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22436 + if (unlikely(err == -EWOULDBLOCK)) {
22437 + pr_warn("cannot retry for NFSv4 delegation"
22438 + " for an internal unlink\n");
22442 + /* dir inode is locked */
22443 + h_dir = d_inode(wh_dentry->d_parent);
22444 + IMustLock(h_dir);
22449 + vfsub_drop_nlink(inode);
22450 + epilog(dir, dentry, bindex);
22452 + /* update target timestamps */
22453 + if (bindex == btop) {
22454 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22456 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22458 + /* todo: this timestamp may be reverted later */
22459 + inode->i_ctime = h_dir->i_ctime;
22460 + goto out_unpin; /* success */
22467 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22474 + au_unpin(&a->pin);
22476 + dput(a->h_path.dentry);
22478 + di_write_unlock(parent);
22480 + aufs_read_unlock(dentry, AuLock_DW);
22487 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22489 + int err, rmdir_later;
22490 + aufs_bindex_t bwh, bindex, btop;
22491 + struct inode *inode;
22492 + struct dentry *parent, *wh_dentry, *h_dentry;
22493 + struct au_whtmp_rmdir *args;
22494 + /* to reduce stack size */
22496 + struct au_dtime dt;
22497 + struct au_pin pin;
22503 + a = kmalloc(sizeof(*a), GFP_NOFS);
22504 + if (unlikely(!a))
22507 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22508 + if (unlikely(err))
22510 + err = au_alive_dir(dentry);
22511 + if (unlikely(err))
22513 + inode = d_inode(dentry);
22514 + IMustLock(inode);
22516 + if (unlikely(!d_is_dir(dentry)))
22517 + goto out_unlock; /* possible? */
22520 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22521 + if (unlikely(!args))
22524 + parent = dentry->d_parent; /* dir inode is locked */
22525 + di_write_lock_parent(parent);
22526 + err = au_test_empty(dentry, &args->whlist);
22527 + if (unlikely(err))
22530 + btop = au_dbtop(dentry);
22531 + bwh = au_dbwh(dentry);
22533 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22535 + err = PTR_ERR(wh_dentry);
22536 + if (IS_ERR(wh_dentry))
22539 + h_dentry = au_h_dptr(dentry, btop);
22542 + if (bindex == btop) {
22543 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22545 + rmdir_later = err;
22549 + /* stop monitoring */
22550 + au_hn_free(au_hi(inode, btop));
22552 + /* dir inode is locked */
22553 + IMustLock(d_inode(wh_dentry->d_parent));
22558 + vfsub_dead_dir(inode);
22559 + au_set_dbdiropq(dentry, -1);
22560 + epilog(dir, dentry, bindex);
22562 + if (rmdir_later) {
22563 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22567 + goto out_unpin; /* success */
22575 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22582 + au_unpin(&a->pin);
22586 + di_write_unlock(parent);
22588 + au_whtmp_rmdir_free(args);
22590 + aufs_read_unlock(dentry, AuLock_DW);
22597 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22598 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22599 +++ linux/fs/aufs/i_op_ren.c 2019-07-11 15:42:14.468904634 +0200
22601 +// SPDX-License-Identifier: GPL-2.0
22603 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22605 + * This program, aufs is free software; you can redistribute it and/or modify
22606 + * it under the terms of the GNU General Public License as published by
22607 + * the Free Software Foundation; either version 2 of the License, or
22608 + * (at your option) any later version.
22610 + * This program is distributed in the hope that it will be useful,
22611 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22612 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22613 + * GNU General Public License for more details.
22615 + * You should have received a copy of the GNU General Public License
22616 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22620 + * inode operation (rename entry)
22621 + * todo: this is crazy monster
22624 +#include <linux/iversion.h>
22627 +enum { AuSRC, AuDST, AuSrcDst };
22628 +enum { AuPARENT, AuCHILD, AuParentChild };
22630 +#define AuRen_ISDIR_SRC 1
22631 +#define AuRen_ISDIR_DST (1 << 1)
22632 +#define AuRen_ISSAMEDIR (1 << 2)
22633 +#define AuRen_WHSRC (1 << 3)
22634 +#define AuRen_WHDST (1 << 4)
22635 +#define AuRen_MNT_WRITE (1 << 5)
22636 +#define AuRen_DT_DSTDIR (1 << 6)
22637 +#define AuRen_DIROPQ_SRC (1 << 7)
22638 +#define AuRen_DIROPQ_DST (1 << 8)
22639 +#define AuRen_DIRREN (1 << 9)
22640 +#define AuRen_DROPPED_SRC (1 << 10)
22641 +#define AuRen_DROPPED_DST (1 << 11)
22642 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22643 +#define au_fset_ren(flags, name) \
22644 + do { (flags) |= AuRen_##name; } while (0)
22645 +#define au_fclr_ren(flags, name) \
22646 + do { (flags) &= ~AuRen_##name; } while (0)
22648 +#ifndef CONFIG_AUFS_DIRREN
22649 +#undef AuRen_DIRREN
22650 +#define AuRen_DIRREN 0
22653 +struct au_ren_args {
22655 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22657 + struct inode *dir, *inode;
22658 + struct au_hinode *hdir, *hinode;
22659 + struct au_dtime dt[AuParentChild];
22660 + aufs_bindex_t btop, bdiropq;
22663 +#define src_dentry sd[AuSRC].dentry
22664 +#define src_dir sd[AuSRC].dir
22665 +#define src_inode sd[AuSRC].inode
22666 +#define src_h_dentry sd[AuSRC].h_dentry
22667 +#define src_parent sd[AuSRC].parent
22668 +#define src_h_parent sd[AuSRC].h_parent
22669 +#define src_wh_dentry sd[AuSRC].wh_dentry
22670 +#define src_hdir sd[AuSRC].hdir
22671 +#define src_hinode sd[AuSRC].hinode
22672 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22673 +#define src_dt sd[AuSRC].dt
22674 +#define src_btop sd[AuSRC].btop
22675 +#define src_bdiropq sd[AuSRC].bdiropq
22677 +#define dst_dentry sd[AuDST].dentry
22678 +#define dst_dir sd[AuDST].dir
22679 +#define dst_inode sd[AuDST].inode
22680 +#define dst_h_dentry sd[AuDST].h_dentry
22681 +#define dst_parent sd[AuDST].parent
22682 +#define dst_h_parent sd[AuDST].h_parent
22683 +#define dst_wh_dentry sd[AuDST].wh_dentry
22684 +#define dst_hdir sd[AuDST].hdir
22685 +#define dst_hinode sd[AuDST].hinode
22686 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22687 +#define dst_dt sd[AuDST].dt
22688 +#define dst_btop sd[AuDST].btop
22689 +#define dst_bdiropq sd[AuDST].bdiropq
22691 + struct dentry *h_trap;
22692 + struct au_branch *br;
22693 + struct path h_path;
22694 + struct au_nhash whlist;
22695 + aufs_bindex_t btgt, src_bwh;
22698 + unsigned short auren_flags;
22699 + unsigned char flags; /* syscall parameter */
22700 + unsigned char exchange;
22703 + struct au_whtmp_rmdir *thargs;
22704 + struct dentry *h_dst;
22705 + struct au_hinode *h_root;
22708 +/* ---------------------------------------------------------------------- */
22711 + * functions for reverting.
22712 + * when an error happened in a single rename systemcall, we should revert
22713 + * everything as if nothing happened.
22714 + * we don't need to revert the copied-up/down the parent dir since they are
22718 +#define RevertFailure(fmt, ...) do { \
22719 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22720 + ##__VA_ARGS__, err, rerr); \
22724 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22727 + struct dentry *d;
22728 +#define src_or_dst(member) a->sd[idx].member
22730 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22731 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22732 + rerr = au_diropq_remove(d, a->btgt);
22733 + au_hn_inode_unlock(src_or_dst(hinode));
22734 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22736 + RevertFailure("remove diropq %pd", d);
22738 +#undef src_or_dst_
22741 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22743 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22744 + au_ren_do_rev_diropq(err, a, AuSRC);
22745 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22746 + au_ren_do_rev_diropq(err, a, AuDST);
22749 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22752 + struct inode *delegated;
22754 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22755 + a->src_h_parent);
22756 + rerr = PTR_ERR(a->h_path.dentry);
22757 + if (IS_ERR(a->h_path.dentry)) {
22758 + RevertFailure("lkup one %pd", a->src_dentry);
22762 + delegated = NULL;
22763 + rerr = vfsub_rename(a->dst_h_dir,
22764 + au_h_dptr(a->src_dentry, a->btgt),
22765 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22766 + if (unlikely(rerr == -EWOULDBLOCK)) {
22767 + pr_warn("cannot retry for NFSv4 delegation"
22768 + " for an internal rename\n");
22771 + d_drop(a->h_path.dentry);
22772 + dput(a->h_path.dentry);
22773 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22775 + RevertFailure("rename %pd", a->src_dentry);
22778 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22781 + struct inode *delegated;
22783 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22784 + a->dst_h_parent);
22785 + rerr = PTR_ERR(a->h_path.dentry);
22786 + if (IS_ERR(a->h_path.dentry)) {
22787 + RevertFailure("lkup one %pd", a->dst_dentry);
22790 + if (d_is_positive(a->h_path.dentry)) {
22791 + d_drop(a->h_path.dentry);
22792 + dput(a->h_path.dentry);
22796 + delegated = NULL;
22797 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22798 + &delegated, a->flags);
22799 + if (unlikely(rerr == -EWOULDBLOCK)) {
22800 + pr_warn("cannot retry for NFSv4 delegation"
22801 + " for an internal rename\n");
22804 + d_drop(a->h_path.dentry);
22805 + dput(a->h_path.dentry);
22807 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22809 + RevertFailure("rename %pd", a->h_dst);
22812 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22816 + a->h_path.dentry = a->src_wh_dentry;
22817 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22818 + au_set_dbwh(a->src_dentry, a->src_bwh);
22820 + RevertFailure("unlink %pd", a->src_wh_dentry);
22822 +#undef RevertFailure
22824 +/* ---------------------------------------------------------------------- */
22827 + * when we have to copyup the renaming entry, do it with the rename-target name
22828 + * in order to minimize the cost (the later actual rename is unnecessary).
22829 + * otherwise rename it on the target branch.
22831 +static int au_ren_or_cpup(struct au_ren_args *a)
22834 + struct dentry *d;
22835 + struct inode *delegated;
22837 + d = a->src_dentry;
22838 + if (au_dbtop(d) == a->btgt) {
22839 + a->h_path.dentry = a->dst_h_dentry;
22840 + AuDebugOn(au_dbtop(d) != a->btgt);
22841 + delegated = NULL;
22842 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22843 + a->dst_h_dir, &a->h_path, &delegated,
22845 + if (unlikely(err == -EWOULDBLOCK)) {
22846 + pr_warn("cannot retry for NFSv4 delegation"
22847 + " for an internal rename\n");
22853 + if (!err && a->h_dst)
22854 + /* it will be set to dinfo later */
22860 +/* cf. aufs_rmdir() */
22861 +static int au_ren_del_whtmp(struct au_ren_args *a)
22864 + struct inode *dir;
22866 + dir = a->dst_dir;
22867 + SiMustAnyLock(dir->i_sb);
22868 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22869 + au_sbi(dir->i_sb)->si_dirwh)
22870 + || au_test_fs_remote(a->h_dst->d_sb)) {
22871 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22872 + if (unlikely(err))
22873 + pr_warn("failed removing whtmp dir %pd (%d), "
22874 + "ignored.\n", a->h_dst, err);
22876 + au_nhash_wh_free(&a->thargs->whlist);
22877 + a->thargs->whlist = a->whlist;
22878 + a->whlist.nh_num = 0;
22879 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22881 + a->thargs = NULL;
22887 +/* make it 'opaque' dir. */
22888 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22891 + struct dentry *d, *diropq;
22892 +#define src_or_dst(member) a->sd[idx].member
22895 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22896 + src_or_dst(bdiropq) = au_dbdiropq(d);
22897 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22898 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22899 + diropq = au_diropq_create(d, a->btgt);
22900 + au_hn_inode_unlock(src_or_dst(hinode));
22901 + if (IS_ERR(diropq))
22902 + err = PTR_ERR(diropq);
22906 +#undef src_or_dst_
22910 +static int au_ren_diropq(struct au_ren_args *a)
22913 + unsigned char always;
22914 + struct dentry *d;
22917 + d = a->dst_dentry; /* already renamed on the branch */
22918 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22919 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22920 + && !au_ftest_ren(a->auren_flags, DIRREN)
22921 + && a->btgt != au_dbdiropq(a->src_dentry)
22922 + && (a->dst_wh_dentry
22923 + || a->btgt <= au_dbdiropq(d)
22924 + /* hide the lower to keep xino */
22925 + /* the lowers may not be a dir, but we hide them anyway */
22926 + || a->btgt < au_dbbot(d)
22929 + err = au_ren_do_diropq(a, AuSRC);
22930 + if (unlikely(err))
22932 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22934 + if (!a->exchange)
22935 + goto out; /* success */
22937 + d = a->src_dentry; /* already renamed on the branch */
22938 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22939 + && a->btgt != au_dbdiropq(a->dst_dentry)
22940 + && (a->btgt < au_dbdiropq(d)
22941 + || a->btgt < au_dbbot(d)
22943 + AuDbgDentry(a->src_dentry);
22944 + AuDbgDentry(a->dst_dentry);
22945 + err = au_ren_do_diropq(a, AuDST);
22946 + if (unlikely(err))
22947 + goto out_rev_src;
22948 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22950 + goto out; /* success */
22953 + AuDbg("err %d, reverting src\n", err);
22954 + au_ren_rev_diropq(err, a);
22959 +static int do_rename(struct au_ren_args *a)
22962 + struct dentry *d, *h_d;
22964 + if (!a->exchange) {
22965 + /* prepare workqueue args for asynchronous rmdir */
22966 + h_d = a->dst_h_dentry;
22967 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22968 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22969 + && d_is_positive(h_d)) {
22971 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22973 + if (unlikely(!a->thargs))
22975 + a->h_dst = dget(h_d);
22978 + /* create whiteout for src_dentry */
22979 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22980 + a->src_bwh = au_dbwh(a->src_dentry);
22981 + AuDebugOn(a->src_bwh >= 0);
22982 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22983 + a->src_h_parent);
22984 + err = PTR_ERR(a->src_wh_dentry);
22985 + if (IS_ERR(a->src_wh_dentry))
22989 + /* lookup whiteout for dentry */
22990 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22991 + h_d = au_wh_lkup(a->dst_h_parent,
22992 + &a->dst_dentry->d_name, a->br);
22993 + err = PTR_ERR(h_d);
22996 + if (d_is_negative(h_d))
22999 + a->dst_wh_dentry = h_d;
23002 + /* rename dentry to tmpwh */
23004 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23005 + if (unlikely(err))
23008 + d = a->dst_dentry;
23009 + au_set_h_dptr(d, a->btgt, NULL);
23010 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23011 + if (unlikely(err))
23013 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23017 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23019 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23020 + && d_is_positive(a->dst_h_dentry)
23021 + && a->src_btop != a->btgt);
23024 + /* rename by vfs_rename or cpup */
23025 + err = au_ren_or_cpup(a);
23026 + if (unlikely(err))
23027 + /* leave the copied-up one */
23030 + /* make dir opaque */
23031 + err = au_ren_diropq(a);
23032 + if (unlikely(err))
23035 + /* update target timestamps */
23036 + if (a->exchange) {
23037 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23038 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23039 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23040 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23042 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23043 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23044 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23045 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23047 + if (!a->exchange) {
23048 + /* remove whiteout for dentry */
23049 + if (a->dst_wh_dentry) {
23050 + a->h_path.dentry = a->dst_wh_dentry;
23051 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23053 + if (unlikely(err))
23057 + /* remove whtmp */
23059 + au_ren_del_whtmp(a); /* ignore this error */
23061 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23064 + goto out_success;
23067 + au_ren_rev_diropq(err, a);
23069 + au_ren_rev_rename(err, a);
23073 + au_ren_rev_whtmp(err, a);
23075 + dput(a->dst_wh_dentry);
23076 + a->dst_wh_dentry = NULL;
23078 + if (a->src_wh_dentry)
23079 + au_ren_rev_whsrc(err, a);
23081 + dput(a->src_wh_dentry);
23082 + dput(a->dst_wh_dentry);
23086 + au_whtmp_rmdir_free(a->thargs);
23087 + a->thargs = NULL;
23093 +/* ---------------------------------------------------------------------- */
23096 + * test if @dentry dir can be rename destination or not.
23097 + * success means, it is a logically empty dir.
23099 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23101 + return au_test_empty(dentry, whlist);
23105 + * test if @a->src_dentry dir can be rename source or not.
23106 + * if it can, return 0.
23108 + * - it is a logically empty dir.
23109 + * - or, it exists on writable branch and has no children including whiteouts
23110 + * on the lower branch unless DIRREN is on.
23112 +static int may_rename_srcdir(struct au_ren_args *a)
23115 + unsigned int rdhash;
23116 + aufs_bindex_t btop, btgt;
23117 + struct dentry *dentry;
23118 + struct super_block *sb;
23119 + struct au_sbinfo *sbinfo;
23121 + dentry = a->src_dentry;
23122 + sb = dentry->d_sb;
23123 + sbinfo = au_sbi(sb);
23124 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23125 + au_fset_ren(a->auren_flags, DIRREN);
23128 + btop = au_dbtop(dentry);
23129 + if (btop != btgt) {
23130 + struct au_nhash whlist;
23132 + SiMustAnyLock(sb);
23133 + rdhash = sbinfo->si_rdhash;
23135 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23137 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23138 + if (unlikely(err))
23140 + err = au_test_empty(dentry, &whlist);
23141 + au_nhash_wh_free(&whlist);
23145 + if (btop == au_dbtaildir(dentry))
23146 + return 0; /* success */
23148 + err = au_test_empty_lower(dentry);
23151 + if (err == -ENOTEMPTY) {
23152 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23155 + AuWarn1("renaming dir who has child(ren) on multiple "
23156 + "branches, is not supported\n");
23163 +/* side effect: sets whlist and h_dentry */
23164 +static int au_ren_may_dir(struct au_ren_args *a)
23167 + unsigned int rdhash;
23168 + struct dentry *d;
23170 + d = a->dst_dentry;
23171 + SiMustAnyLock(d->d_sb);
23174 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23175 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23177 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23178 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23179 + if (unlikely(err))
23182 + if (!a->exchange) {
23183 + au_set_dbtop(d, a->dst_btop);
23184 + err = may_rename_dstdir(d, &a->whlist);
23185 + au_set_dbtop(d, a->btgt);
23187 + err = may_rename_srcdir(a);
23189 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23190 + if (unlikely(err))
23193 + d = a->src_dentry;
23194 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23195 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23196 + err = may_rename_srcdir(a);
23197 + if (unlikely(err)) {
23198 + au_nhash_wh_free(&a->whlist);
23199 + a->whlist.nh_num = 0;
23206 +/* ---------------------------------------------------------------------- */
23209 + * simple tests for rename.
23210 + * following the checks in vfs, plus the parent-child relationship.
23212 +static int au_may_ren(struct au_ren_args *a)
23215 + struct inode *h_inode;
23217 + if (a->src_btop == a->btgt) {
23218 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23219 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23220 + if (unlikely(err))
23223 + if (unlikely(a->src_h_dentry == a->h_trap))
23228 + if (a->dst_btop != a->btgt)
23231 + err = -ENOTEMPTY;
23232 + if (unlikely(a->dst_h_dentry == a->h_trap))
23236 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23237 + if (d_really_is_negative(a->dst_dentry)) {
23238 + if (d_is_negative(a->dst_h_dentry))
23239 + err = au_may_add(a->dst_dentry, a->btgt,
23240 + a->dst_h_parent, isdir);
23242 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23244 + h_inode = d_inode(a->dst_h_dentry);
23245 + if (h_inode->i_nlink)
23246 + err = au_may_del(a->dst_dentry, a->btgt,
23247 + a->dst_h_parent, isdir);
23251 + if (unlikely(err == -ENOENT || err == -EEXIST))
23257 +/* ---------------------------------------------------------------------- */
23262 + * - src_dir and dir by lock_rename()
23263 + * - inode if exists
23266 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23268 + * + di_write_lock2_child()
23269 + * + di_write_lock_child()
23270 + * + ii_write_lock_child()
23271 + * + di_write_lock_child2()
23272 + * + ii_write_lock_child2()
23273 + * + src_parent and parent
23274 + * + di_write_lock_parent()
23275 + * + ii_write_lock_parent()
23276 + * + di_write_lock_parent2()
23277 + * + ii_write_lock_parent2()
23278 + * + lower src_dir and dir by vfsub_lock_rename()
23279 + * + verify the every relationships between child and parent. if any
23280 + * of them failed, unlock all and return -EBUSY.
23282 +static void au_ren_unlock(struct au_ren_args *a)
23284 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23285 + a->dst_h_parent, a->dst_hdir);
23286 + if (au_ftest_ren(a->auren_flags, DIRREN)
23288 + au_hn_inode_unlock(a->h_root);
23289 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23290 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23293 +static int au_ren_lock(struct au_ren_args *a)
23296 + unsigned int udba;
23299 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23300 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23301 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23302 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23304 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23305 + if (unlikely(err))
23307 + au_fset_ren(a->auren_flags, MNT_WRITE);
23308 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23309 + struct dentry *root;
23310 + struct inode *dir;
23313 + * sbinfo is already locked, so this ii_read_lock is
23314 + * unnecessary. but our debugging feature checks it.
23316 + root = a->src_inode->i_sb->s_root;
23317 + if (root != a->src_parent && root != a->dst_parent) {
23318 + dir = d_inode(root);
23319 + ii_read_lock_parent3(dir);
23320 + a->h_root = au_hi(dir, a->btgt);
23321 + ii_read_unlock(dir);
23322 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23325 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23326 + a->dst_h_parent, a->dst_hdir);
23327 + udba = au_opt_udba(a->src_dentry->d_sb);
23328 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23329 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23330 + err = au_busy_or_stale();
23331 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23332 + err = au_h_verify(a->src_h_dentry, udba,
23333 + d_inode(a->src_h_parent), a->src_h_parent,
23335 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23336 + err = au_h_verify(a->dst_h_dentry, udba,
23337 + d_inode(a->dst_h_parent), a->dst_h_parent,
23340 + goto out; /* success */
23342 + err = au_busy_or_stale();
23343 + au_ren_unlock(a);
23349 +/* ---------------------------------------------------------------------- */
23351 +static void au_ren_refresh_dir(struct au_ren_args *a)
23353 + struct inode *dir;
23355 + dir = a->dst_dir;
23356 + inode_inc_iversion(dir);
23357 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23358 + /* is this updating defined in POSIX? */
23359 + au_cpup_attr_timesizes(a->src_inode);
23360 + au_cpup_attr_nlink(dir, /*force*/1);
23362 + au_dir_ts(dir, a->btgt);
23364 + if (a->exchange) {
23365 + dir = a->src_dir;
23366 + inode_inc_iversion(dir);
23367 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23368 + /* is this updating defined in POSIX? */
23369 + au_cpup_attr_timesizes(a->dst_inode);
23370 + au_cpup_attr_nlink(dir, /*force*/1);
23372 + au_dir_ts(dir, a->btgt);
23375 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23378 + dir = a->src_dir;
23379 + inode_inc_iversion(dir);
23380 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23381 + au_cpup_attr_nlink(dir, /*force*/1);
23382 + au_dir_ts(dir, a->btgt);
23385 +static void au_ren_refresh(struct au_ren_args *a)
23387 + aufs_bindex_t bbot, bindex;
23388 + struct dentry *d, *h_d;
23389 + struct inode *i, *h_i;
23390 + struct super_block *sb;
23392 + d = a->dst_dentry;
23395 + /* already dget-ed by au_ren_or_cpup() */
23396 + au_set_h_dptr(d, a->btgt, a->h_dst);
23398 + i = a->dst_inode;
23400 + if (!a->exchange) {
23401 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23402 + vfsub_drop_nlink(i);
23404 + vfsub_dead_dir(i);
23405 + au_cpup_attr_timesizes(i);
23407 + au_update_dbrange(d, /*do_put_zero*/1);
23409 + au_cpup_attr_nlink(i, /*force*/1);
23412 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23413 + au_set_h_dptr(d, bindex, NULL);
23414 + bbot = au_dbbot(d);
23415 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23416 + au_set_h_dptr(d, bindex, NULL);
23417 + au_update_dbrange(d, /*do_put_zero*/0);
23421 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23422 + d_drop(a->src_dentry);
23423 + if (au_ftest_ren(a->auren_flags, DIRREN))
23424 + au_set_dbwh(a->src_dentry, -1);
23428 + d = a->src_dentry;
23429 + au_set_dbwh(d, -1);
23430 + bbot = au_dbbot(d);
23431 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23432 + h_d = au_h_dptr(d, bindex);
23434 + au_set_h_dptr(d, bindex, NULL);
23436 + au_set_dbbot(d, a->btgt);
23439 + i = a->src_inode;
23440 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23441 + return; /* success */
23443 + bbot = au_ibbot(i);
23444 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23445 + h_i = au_h_iptr(i, bindex);
23447 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23448 + /* ignore this error */
23449 + au_set_h_iptr(i, bindex, NULL, 0);
23452 + au_set_ibbot(i, a->btgt);
23455 +/* ---------------------------------------------------------------------- */
23457 +/* mainly for link(2) and rename(2) */
23458 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23460 + aufs_bindex_t bdiropq, bwh;
23461 + struct dentry *parent;
23462 + struct au_branch *br;
23464 + parent = dentry->d_parent;
23465 + IMustLock(d_inode(parent)); /* dir is locked */
23467 + bdiropq = au_dbdiropq(parent);
23468 + bwh = au_dbwh(dentry);
23469 + br = au_sbr(dentry->d_sb, btgt);
23470 + if (au_br_rdonly(br)
23471 + || (0 <= bdiropq && bdiropq < btgt)
23472 + || (0 <= bwh && bwh < btgt))
23475 + AuDbg("btgt %d\n", btgt);
23479 +/* sets src_btop, dst_btop and btgt */
23480 +static int au_ren_wbr(struct au_ren_args *a)
23483 + struct au_wr_dir_args wr_dir_args = {
23484 + /* .force_btgt = -1, */
23485 + .flags = AuWrDir_ADD_ENTRY
23488 + a->src_btop = au_dbtop(a->src_dentry);
23489 + a->dst_btop = au_dbtop(a->dst_dentry);
23490 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23491 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23492 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23493 + wr_dir_args.force_btgt = a->src_btop;
23494 + if (a->dst_inode && a->dst_btop < a->src_btop)
23495 + wr_dir_args.force_btgt = a->dst_btop;
23496 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23497 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23500 + au_update_dbtop(a->dst_dentry);
23505 +static void au_ren_dt(struct au_ren_args *a)
23507 + a->h_path.dentry = a->src_h_parent;
23508 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23509 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23510 + a->h_path.dentry = a->dst_h_parent;
23511 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23514 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23515 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23519 + a->h_path.dentry = a->src_h_dentry;
23520 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23521 + if (d_is_positive(a->dst_h_dentry)) {
23522 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23523 + a->h_path.dentry = a->dst_h_dentry;
23524 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23528 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23530 + struct dentry *h_d;
23531 + struct inode *h_inode;
23533 + au_dtime_revert(a->src_dt + AuPARENT);
23534 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23535 + au_dtime_revert(a->dst_dt + AuPARENT);
23537 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23538 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23539 + h_inode = d_inode(h_d);
23540 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23541 + au_dtime_revert(a->src_dt + AuCHILD);
23542 + inode_unlock(h_inode);
23544 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23545 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23546 + h_inode = d_inode(h_d);
23547 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23548 + au_dtime_revert(a->dst_dt + AuCHILD);
23549 + inode_unlock(h_inode);
23554 +/* ---------------------------------------------------------------------- */
23556 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23557 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23558 + unsigned int _flags)
23560 + int err, lock_flags;
23562 + /* reduce stack space */
23563 + struct au_ren_args *a;
23564 + struct au_pin pin;
23566 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23567 + IMustLock(_src_dir);
23568 + IMustLock(_dst_dir);
23571 + if (unlikely(_flags & RENAME_WHITEOUT))
23575 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23576 + a = kzalloc(sizeof(*a), GFP_NOFS);
23577 + if (unlikely(!a))
23580 + a->flags = _flags;
23581 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23582 + && RENAME_EXCHANGE > U8_MAX);
23583 + a->exchange = _flags & RENAME_EXCHANGE;
23584 + a->src_dir = _src_dir;
23585 + a->src_dentry = _src_dentry;
23586 + a->src_inode = NULL;
23587 + if (d_really_is_positive(a->src_dentry))
23588 + a->src_inode = d_inode(a->src_dentry);
23589 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23590 + a->dst_dir = _dst_dir;
23591 + a->dst_dentry = _dst_dentry;
23592 + a->dst_inode = NULL;
23593 + if (d_really_is_positive(a->dst_dentry))
23594 + a->dst_inode = d_inode(a->dst_dentry);
23595 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23596 + if (a->dst_inode) {
23598 + * if EXCHANGE && src is non-dir && dst is dir,
23599 + * dst is not locked.
23601 + /* IMustLock(a->dst_inode); */
23602 + au_igrab(a->dst_inode);
23606 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23607 + if (d_is_dir(a->src_dentry)) {
23608 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23609 + if (unlikely(!a->exchange
23610 + && d_really_is_positive(a->dst_dentry)
23611 + && !d_is_dir(a->dst_dentry)))
23613 + lock_flags |= AuLock_DIRS;
23615 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23616 + au_fset_ren(a->auren_flags, ISDIR_DST);
23617 + if (unlikely(!a->exchange
23618 + && d_really_is_positive(a->src_dentry)
23619 + && !d_is_dir(a->src_dentry)))
23621 + lock_flags |= AuLock_DIRS;
23623 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23625 + if (unlikely(err))
23628 + err = au_d_hashed_positive(a->src_dentry);
23629 + if (unlikely(err))
23632 + if (a->dst_inode) {
23634 + * If it is a dir, VFS unhash it before this
23635 + * function. It means we cannot rely upon d_unhashed().
23637 + if (unlikely(!a->dst_inode->i_nlink))
23639 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23640 + err = au_d_hashed_positive(a->dst_dentry);
23641 + if (unlikely(err && !a->exchange))
23643 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23645 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23649 + * is it possible?
23650 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23651 + * there may exist a problem somewhere else.
23654 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23657 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23658 + di_write_lock_parent(a->dst_parent);
23660 + /* which branch we process */
23661 + err = au_ren_wbr(a);
23662 + if (unlikely(err < 0))
23664 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23665 + a->h_path.mnt = au_br_mnt(a->br);
23667 + /* are they available to be renamed */
23668 + err = au_ren_may_dir(a);
23669 + if (unlikely(err))
23670 + goto out_children;
23672 + /* prepare the writable parent dir on the same branch */
23673 + if (a->dst_btop == a->btgt) {
23674 + au_fset_ren(a->auren_flags, WHDST);
23676 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23677 + if (unlikely(err))
23678 + goto out_children;
23682 + if (!a->exchange) {
23683 + if (a->src_dir != a->dst_dir) {
23685 + * this temporary unlock is safe,
23686 + * because both dir->i_mutex are locked.
23688 + di_write_unlock(a->dst_parent);
23689 + di_write_lock_parent(a->src_parent);
23690 + err = au_wr_dir_need_wh(a->src_dentry,
23691 + au_ftest_ren(a->auren_flags,
23694 + di_write_unlock(a->src_parent);
23695 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23697 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23699 + err = au_wr_dir_need_wh(a->src_dentry,
23700 + au_ftest_ren(a->auren_flags,
23704 + if (unlikely(err < 0))
23705 + goto out_children;
23707 + au_fset_ren(a->auren_flags, WHSRC);
23710 + if (a->src_btop != a->btgt) {
23711 + err = au_pin(&pin, a->src_dentry, a->btgt,
23712 + au_opt_udba(a->src_dentry->d_sb),
23713 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23715 + struct au_cp_generic cpg = {
23716 + .dentry = a->src_dentry,
23718 + .bsrc = a->src_btop,
23721 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23723 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23724 + err = au_sio_cpup_simple(&cpg);
23727 + if (unlikely(err))
23728 + goto out_children;
23729 + a->src_btop = a->btgt;
23730 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23731 + if (!a->exchange)
23732 + au_fset_ren(a->auren_flags, WHSRC);
23736 + if (a->exchange && a->dst_inode
23737 + && a->dst_btop != a->btgt) {
23738 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23739 + au_opt_udba(a->dst_dentry->d_sb),
23740 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23742 + struct au_cp_generic cpg = {
23743 + .dentry = a->dst_dentry,
23745 + .bsrc = a->dst_btop,
23748 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23750 + err = au_sio_cpup_simple(&cpg);
23753 + if (unlikely(err))
23754 + goto out_children;
23755 + a->dst_btop = a->btgt;
23756 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23759 + /* lock them all */
23760 + err = au_ren_lock(a);
23761 + if (unlikely(err))
23762 + /* leave the copied-up one */
23763 + goto out_children;
23765 + if (!a->exchange) {
23766 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23767 + err = au_may_ren(a);
23768 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23769 + err = -ENAMETOOLONG;
23770 + if (unlikely(err))
23774 + /* store timestamps to be revertible */
23777 + /* store dirren info */
23778 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23779 + err = au_dr_rename(a->src_dentry, a->btgt,
23780 + &a->dst_dentry->d_name, &rev);
23782 + if (unlikely(err))
23787 + err = do_rename(a);
23788 + if (unlikely(err))
23791 + if (au_ftest_ren(a->auren_flags, DIRREN))
23792 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23794 + /* update dir attributes */
23795 + au_ren_refresh_dir(a);
23797 + /* dput/iput all lower dentries */
23798 + au_ren_refresh(a);
23800 + goto out_hdir; /* success */
23803 + if (au_ftest_ren(a->auren_flags, DIRREN))
23804 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23806 + au_ren_rev_dt(err, a);
23808 + au_ren_unlock(a);
23810 + au_nhash_wh_free(&a->whlist);
23811 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23812 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23813 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23814 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23818 + if (d_unhashed(a->src_dentry))
23819 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23820 + if (d_unhashed(a->dst_dentry))
23821 + au_fset_ren(a->auren_flags, DROPPED_DST);
23822 + if (!a->exchange)
23823 + d_move(a->src_dentry, a->dst_dentry);
23825 + d_exchange(a->src_dentry, a->dst_dentry);
23826 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23827 + d_drop(a->dst_dentry);
23829 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23830 + d_drop(a->src_dentry);
23832 + au_update_dbtop(a->dst_dentry);
23833 + if (!a->dst_inode)
23834 + d_drop(a->dst_dentry);
23836 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23837 + di_write_unlock(a->dst_parent);
23839 + di_write_unlock2(a->src_parent, a->dst_parent);
23841 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23843 + iput(a->dst_inode);
23845 + au_whtmp_rmdir_free(a->thargs);
23851 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23852 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23853 +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200
23855 +# SPDX-License-Identifier: GPL-2.0
23857 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23859 + Aufs is a stackable unification filesystem such as Unionfs,
23860 + which unifies several directories and provides a merged single
23862 + In the early days, aufs was entirely re-designed and
23863 + re-implemented Unionfs Version 1.x series. Introducing many
23864 + original ideas, approaches and improvements, it becomes totally
23865 + different from Unionfs while keeping the basic features.
23869 + prompt "Maximum number of branches"
23870 + default AUFS_BRANCH_MAX_127
23872 + Specifies the maximum number of branches (or member directories)
23873 + in a single aufs. The larger value consumes more system
23874 + resources and has a minor impact to performance.
23875 +config AUFS_BRANCH_MAX_127
23878 + Specifies the maximum number of branches (or member directories)
23879 + in a single aufs. The larger value consumes more system
23880 + resources and has a minor impact to performance.
23881 +config AUFS_BRANCH_MAX_511
23884 + Specifies the maximum number of branches (or member directories)
23885 + in a single aufs. The larger value consumes more system
23886 + resources and has a minor impact to performance.
23887 +config AUFS_BRANCH_MAX_1023
23890 + Specifies the maximum number of branches (or member directories)
23891 + in a single aufs. The larger value consumes more system
23892 + resources and has a minor impact to performance.
23893 +config AUFS_BRANCH_MAX_32767
23896 + Specifies the maximum number of branches (or member directories)
23897 + in a single aufs. The larger value consumes more system
23898 + resources and has a minor impact to performance.
23901 +config AUFS_SBILIST
23903 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23906 + Automatic configuration for internal use.
23907 + When aufs supports Magic SysRq or /proc, enabled automatically.
23909 +config AUFS_HNOTIFY
23910 + bool "Detect direct branch access (bypassing aufs)"
23912 + If you want to modify files on branches directly, eg. bypassing aufs,
23913 + and want aufs to detect the changes of them fully, then enable this
23914 + option and use 'udba=notify' mount option.
23915 + Currently there is only one available configuration, "fsnotify".
23916 + It will have a negative impact to the performance.
23917 + See detail in aufs.5.
23920 + prompt "method" if AUFS_HNOTIFY
23921 + default AUFS_HFSNOTIFY
23922 +config AUFS_HFSNOTIFY
23927 +config AUFS_EXPORT
23928 + bool "NFS-exportable aufs"
23929 + depends on EXPORTFS
23931 + If you want to export your mounted aufs via NFS, then enable this
23932 + option. There are several requirements for this configuration.
23933 + See detail in aufs.5.
23935 +config AUFS_INO_T_64
23937 + depends on AUFS_EXPORT
23938 + depends on 64BIT && !(ALPHA || S390)
23941 + Automatic configuration for internal use.
23942 + /* typedef unsigned long/int __kernel_ino_t */
23943 + /* alpha and s390x are int */
23946 + bool "support for XATTR/EA (including Security Labels)"
23948 + If your branch fs supports XATTR/EA and you want to make them
23949 + available in aufs too, then enable this opsion and specify the
23950 + branch attributes for EA.
23951 + See detail in aufs.5.
23954 + bool "File-based Hierarchical Storage Management"
23956 + Hierarchical Storage Management (or HSM) is a well-known feature
23957 + in the storage world. Aufs provides this feature as file-based.
23958 + with multiple branches.
23959 + These multiple branches are prioritized, ie. the topmost one
23960 + should be the fastest drive and be used heavily.
23963 + bool "Readdir in userspace"
23965 + Aufs has two methods to provide a merged view for a directory,
23966 + by a user-space library and by kernel-space natively. The latter
23967 + is always enabled but sometimes large and slow.
23968 + If you enable this option, install the library in aufs2-util
23969 + package, and set some environment variables for your readdir(3),
23970 + then the work will be handled in user-space which generally
23971 + shows better performance in most cases.
23972 + See detail in aufs.5.
23974 +config AUFS_DIRREN
23975 + bool "Workaround for rename(2)-ing a directory"
23977 + By default, aufs returns EXDEV error in renameing a dir who has
23978 + his child on the lower branch, since it is a bad idea to issue
23979 + rename(2) internally for every lower branch. But user may not
23980 + accept this behaviour. So here is a workaround to allow such
23981 + rename(2) and store some extra infromation on the writable
23982 + branch. Obviously this costs high (and I don't like it).
23983 + To use this feature, you need to enable this configuration AND
23984 + to specify the mount option `dirren.'
23985 + See details in aufs.5 and the design documents.
23988 + bool "Show whiteouts"
23990 + If you want to make the whiteouts in aufs visible, then enable
23991 + this option and specify 'shwh' mount option. Although it may
23992 + sounds like philosophy or something, but in technically it
23993 + simply shows the name of whiteout with keeping its behaviour.
23995 +config AUFS_BR_RAMFS
23996 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23998 + If you want to use ramfs as an aufs branch fs, then enable this
23999 + option. Generally tmpfs is recommended.
24000 + Aufs prohibited them to be a branch fs by default, because
24001 + initramfs becomes unusable after switch_root or something
24002 + generally. If you sets initramfs as an aufs branch and boot your
24003 + system by switch_root, you will meet a problem easily since the
24004 + files in initramfs may be inaccessible.
24005 + Unless you are going to use ramfs as an aufs branch fs without
24006 + switch_root or something, leave it N.
24008 +config AUFS_BR_FUSE
24009 + bool "Fuse fs as an aufs branch"
24010 + depends on FUSE_FS
24013 + If you want to use fuse-based userspace filesystem as an aufs
24014 + branch fs, then enable this option.
24015 + It implements the internal poll(2) operation which is
24016 + implemented by fuse only (curretnly).
24021 + Automatic configuration for internal use.
24023 +config AUFS_BR_HFSPLUS
24024 + bool "Hfsplus as an aufs branch"
24025 + depends on HFSPLUS_FS
24028 + If you want to use hfsplus fs as an aufs branch fs, then enable
24029 + this option. This option introduces a small overhead at
24030 + copying-up a file on hfsplus.
24032 +config AUFS_BDEV_LOOP
24034 + depends on BLK_DEV_LOOP
24037 + Automatic configuration for internal use.
24038 + Convert =[ym] into =y.
24041 + bool "Debug aufs"
24043 + Enable this to compile aufs internal debug code.
24044 + It will have a negative impact to the performance.
24046 +config AUFS_MAGIC_SYSRQ
24048 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24051 + Automatic configuration for internal use.
24052 + When aufs supports Magic SysRq, enabled automatically.
24054 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24055 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24056 +++ linux/fs/aufs/lcnt.h 2019-07-11 15:42:14.468904634 +0200
24058 +/* SPDX-License-Identifier: GPL-2.0 */
24060 + * Copyright (C) 2018-2019 Junjiro R. Okajima
24062 + * This program, aufs is free software; you can redistribute it and/or modify
24063 + * it under the terms of the GNU General Public License as published by
24064 + * the Free Software Foundation; either version 2 of the License, or
24065 + * (at your option) any later version.
24067 + * This program is distributed in the hope that it will be useful,
24068 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24070 + * GNU General Public License for more details.
24072 + * You should have received a copy of the GNU General Public License
24073 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24077 + * simple long counter wrapper
24080 +#ifndef __AUFS_LCNT_H__
24081 +#define __AUFS_LCNT_H__
24085 +#include "debug.h"
24087 +#define AuLCntATOMIC 1
24088 +#define AuLCntPCPUCNT 2
24090 + * why does percpu_refcount require extra synchronize_rcu()s in
24091 + * au_br_do_free()
24093 +#define AuLCntPCPUREF 3
24095 +/* #define AuLCntChosen AuLCntATOMIC */
24096 +#define AuLCntChosen AuLCntPCPUCNT
24097 +/* #define AuLCntChosen AuLCntPCPUREF */
24099 +#if AuLCntChosen == AuLCntATOMIC
24100 +#include <linux/atomic.h>
24102 +typedef atomic_long_t au_lcnt_t;
24104 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24106 + atomic_long_set(cnt, 0);
24110 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24115 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24116 + int do_sync __maybe_unused)
24121 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24123 + atomic_long_inc(cnt);
24126 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24128 + atomic_long_dec(cnt);
24131 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24133 + return atomic_long_read(cnt);
24137 +#if AuLCntChosen == AuLCntPCPUCNT
24138 +#include <linux/percpu_counter.h>
24140 +typedef struct percpu_counter au_lcnt_t;
24142 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24144 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24147 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24152 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24154 + percpu_counter_destroy(cnt);
24157 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24159 + percpu_counter_inc(cnt);
24162 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24164 + percpu_counter_dec(cnt);
24167 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24171 + n = percpu_counter_sum(cnt);
24173 + if (LONG_MAX != LLONG_MAX
24175 + AuWarn1("%s\n", "wrap-around");
24181 +#if AuLCntChosen == AuLCntPCPUREF
24182 +#include <linux/percpu-refcount.h>
24184 +typedef struct percpu_ref au_lcnt_t;
24186 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24189 + release = percpu_ref_exit;
24190 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24193 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24195 + synchronize_rcu();
24198 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24200 + percpu_ref_kill(cnt);
24202 + au_lcnt_wait_for_fin(cnt);
24205 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24207 + percpu_ref_get(cnt);
24210 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24212 + percpu_ref_put(cnt);
24216 + * avoid calling this func as possible.
24218 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24222 + percpu_ref_switch_to_atomic_sync(cnt);
24223 + l = atomic_long_read(&cnt->count);
24225 + percpu_ref_switch_to_percpu(cnt);
24227 + /* percpu_ref is initialized by 1 instead of 0 */
24232 +#ifdef CONFIG_AUFS_DEBUG
24233 +#define AuLCntZero(val) do { \
24236 + AuDbg("%s = %ld\n", #val, l); \
24239 +#define AuLCntZero(val) do {} while (0)
24242 +#endif /* __KERNEL__ */
24243 +#endif /* __AUFS_LCNT_H__ */
24244 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24245 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24246 +++ linux/fs/aufs/loop.c 2019-07-11 15:42:14.468904634 +0200
24248 +// SPDX-License-Identifier: GPL-2.0
24250 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24252 + * This program, aufs is free software; you can redistribute it and/or modify
24253 + * it under the terms of the GNU General Public License as published by
24254 + * the Free Software Foundation; either version 2 of the License, or
24255 + * (at your option) any later version.
24257 + * This program is distributed in the hope that it will be useful,
24258 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24259 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24260 + * GNU General Public License for more details.
24262 + * You should have received a copy of the GNU General Public License
24263 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24267 + * support for loopback block device as a branch
24272 +/* added into drivers/block/loop.c */
24273 +static struct file *(*backing_file_func)(struct super_block *sb);
24276 + * test if two lower dentries have overlapping branches.
24278 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24280 + struct super_block *h_sb;
24281 + struct file *backing_file;
24283 + if (unlikely(!backing_file_func)) {
24284 + /* don't load "loop" module here */
24285 + backing_file_func = symbol_get(loop_backing_file);
24286 + if (unlikely(!backing_file_func))
24287 + /* "loop" module is not loaded */
24291 + h_sb = h_adding->d_sb;
24292 + backing_file = backing_file_func(h_sb);
24293 + if (!backing_file)
24296 + h_adding = backing_file->f_path.dentry;
24298 + * h_adding can be local NFS.
24299 + * in this case aufs cannot detect the loop.
24301 + if (unlikely(h_adding->d_sb == sb))
24303 + return !!au_test_subdir(h_adding, sb->s_root);
24306 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24307 +int au_test_loopback_kthread(void)
24310 + struct task_struct *tsk = current;
24311 + char c, comm[sizeof(tsk->comm)];
24314 + if (tsk->flags & PF_KTHREAD) {
24315 + get_task_comm(comm, tsk);
24317 + ret = ('0' <= c && c <= '9'
24318 + && !strncmp(comm, "loop", 4));
24324 +/* ---------------------------------------------------------------------- */
24326 +#define au_warn_loopback_step 16
24327 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24328 +static unsigned long *au_warn_loopback_array;
24330 +void au_warn_loopback(struct super_block *h_sb)
24332 + int i, new_nelem;
24333 + unsigned long *a, magic;
24334 + static DEFINE_SPINLOCK(spin);
24336 + magic = h_sb->s_magic;
24337 + spin_lock(&spin);
24338 + a = au_warn_loopback_array;
24339 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24340 + if (a[i] == magic) {
24341 + spin_unlock(&spin);
24345 + /* h_sb is new to us, print it */
24346 + if (i < au_warn_loopback_nelem) {
24351 + /* expand the array */
24352 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24353 + a = au_kzrealloc(au_warn_loopback_array,
24354 + au_warn_loopback_nelem * sizeof(unsigned long),
24355 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24356 + /*may_shrink*/0);
24358 + au_warn_loopback_nelem = new_nelem;
24359 + au_warn_loopback_array = a;
24364 + spin_unlock(&spin);
24365 + AuWarn1("realloc failed, ignored\n");
24369 + spin_unlock(&spin);
24370 + pr_warn("you may want to try another patch for loopback file "
24371 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24374 +int au_loopback_init(void)
24377 + struct super_block *sb __maybe_unused;
24379 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24382 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24383 + sizeof(unsigned long), GFP_NOFS);
24384 + if (unlikely(!au_warn_loopback_array))
24390 +void au_loopback_fin(void)
24392 + if (backing_file_func)
24393 + symbol_put(loop_backing_file);
24394 + au_kfree_try_rcu(au_warn_loopback_array);
24396 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24397 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24398 +++ linux/fs/aufs/loop.h 2019-07-11 15:42:14.468904634 +0200
24400 +/* SPDX-License-Identifier: GPL-2.0 */
24402 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24404 + * This program, aufs is free software; you can redistribute it and/or modify
24405 + * it under the terms of the GNU General Public License as published by
24406 + * the Free Software Foundation; either version 2 of the License, or
24407 + * (at your option) any later version.
24409 + * This program is distributed in the hope that it will be useful,
24410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24412 + * GNU General Public License for more details.
24414 + * You should have received a copy of the GNU General Public License
24415 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24419 + * support for loopback mount as a branch
24422 +#ifndef __AUFS_LOOP_H__
24423 +#define __AUFS_LOOP_H__
24428 +struct super_block;
24430 +#ifdef CONFIG_AUFS_BDEV_LOOP
24431 +/* drivers/block/loop.c */
24432 +struct file *loop_backing_file(struct super_block *sb);
24435 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24436 +int au_test_loopback_kthread(void);
24437 +void au_warn_loopback(struct super_block *h_sb);
24439 +int au_loopback_init(void);
24440 +void au_loopback_fin(void);
24442 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24444 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24445 + struct dentry *h_adding)
24446 +AuStubInt0(au_test_loopback_kthread, void)
24447 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24449 +AuStubInt0(au_loopback_init, void)
24450 +AuStubVoid(au_loopback_fin, void)
24451 +#endif /* BLK_DEV_LOOP */
24453 +#endif /* __KERNEL__ */
24454 +#endif /* __AUFS_LOOP_H__ */
24455 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24456 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24457 +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200
24459 +# SPDX-License-Identifier: GPL-2.0
24461 +# defined in ${srctree}/fs/fuse/inode.c
24463 +ifdef CONFIG_FUSE_FS
24464 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24467 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24469 +ifdef CONFIG_XFS_FS
24470 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24473 +# defined in ${srctree}/fs/configfs/mount.c
24475 +ifdef CONFIG_CONFIGFS_FS
24476 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24479 +# defined in ${srctree}/fs/ubifs/ubifs.h
24481 +ifdef CONFIG_UBIFS_FS
24482 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24485 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24487 +ifdef CONFIG_HFSPLUS_FS
24488 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24490 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24491 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24492 +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200
24494 +# SPDX-License-Identifier: GPL-2.0
24496 +include ${src}/magic.mk
24497 +ifeq (${CONFIG_AUFS_FS},m)
24498 +include ${src}/conf.mk
24500 +-include ${src}/priv_def.mk
24502 +# cf. include/linux/kernel.h
24504 +ccflags-y += -DDEBUG
24505 +# sparse requires the full pathname
24507 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24509 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24512 +obj-$(CONFIG_AUFS_FS) += aufs.o
24513 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24514 + wkq.o vfsub.o dcsub.o \
24515 + cpup.o whout.o wbr_policy.o \
24516 + dinfo.o dentry.o \
24518 + finfo.o file.o f_op.o \
24520 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24524 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24525 +aufs-$(CONFIG_SYSFS) += sysfs.o
24526 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24527 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24528 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24529 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24530 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24531 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24532 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24533 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24534 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24535 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24536 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24537 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24538 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24539 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24540 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24541 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24542 +++ linux/fs/aufs/module.c 2019-07-11 15:42:14.468904634 +0200
24544 +// SPDX-License-Identifier: GPL-2.0
24546 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24548 + * This program, aufs is free software; you can redistribute it and/or modify
24549 + * it under the terms of the GNU General Public License as published by
24550 + * the Free Software Foundation; either version 2 of the License, or
24551 + * (at your option) any later version.
24553 + * This program is distributed in the hope that it will be useful,
24554 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24555 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24556 + * GNU General Public License for more details.
24558 + * You should have received a copy of the GNU General Public License
24559 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24563 + * module global variables and operations
24566 +#include <linux/module.h>
24567 +#include <linux/seq_file.h>
24570 +/* shrinkable realloc */
24571 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24579 +#if 0 /* unused */
24586 + AuDebugOn(!new_sz);
24589 + diff = au_kmidx_sub(sz, new_sz);
24595 + /* expand or SLOB */
24596 + p = krealloc(p, new_sz, gfp);
24597 + else if (new_sz < sz && may_shrink) {
24601 + q = kmalloc(new_sz, gfp);
24604 + memcpy(q, p, new_sz);
24605 + au_kfree_try_rcu(p);
24616 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24619 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24620 + if (p && new_sz > nused)
24621 + memset(p + nused, 0, new_sz - nused);
24625 +/* ---------------------------------------------------------------------- */
24629 +struct kmem_cache *au_cache[AuCache_Last];
24631 +static void au_cache_fin(void)
24636 + * Make sure all delayed rcu free inodes are flushed before we
24641 + /* excluding AuCache_HNOTIFY */
24642 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24643 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24644 + kmem_cache_destroy(au_cache[i]);
24645 + au_cache[i] = NULL;
24649 +static int __init au_cache_init(void)
24651 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24652 + if (au_cache[AuCache_DINFO])
24653 + /* SLAB_DESTROY_BY_RCU */
24654 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24655 + au_icntnr_init_once);
24656 + if (au_cache[AuCache_ICNTNR])
24657 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24658 + au_fi_init_once);
24659 + if (au_cache[AuCache_FINFO])
24660 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24661 + if (au_cache[AuCache_VDIR])
24662 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24663 + if (au_cache[AuCache_DEHSTR])
24670 +/* ---------------------------------------------------------------------- */
24672 +int au_dir_roflags;
24674 +#ifdef CONFIG_AUFS_SBILIST
24676 + * iterate_supers_type() doesn't protect us from
24677 + * remounting (branch management)
24679 +struct hlist_bl_head au_sbilist;
24683 + * functions for module interface.
24685 +MODULE_LICENSE("GPL");
24686 +/* MODULE_LICENSE("GPL v2"); */
24687 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24688 +MODULE_DESCRIPTION(AUFS_NAME
24689 + " -- Advanced multi layered unification filesystem");
24690 +MODULE_VERSION(AUFS_VERSION);
24691 +MODULE_ALIAS_FS(AUFS_NAME);
24693 +/* this module parameter has no meaning when SYSFS is disabled */
24694 +int sysaufs_brs = 1;
24695 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24696 +module_param_named(brs, sysaufs_brs, int, 0444);
24698 +/* this module parameter has no meaning when USER_NS is disabled */
24700 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24701 +module_param_named(allow_userns, au_userns, bool, 0444);
24703 +/* ---------------------------------------------------------------------- */
24705 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24707 +int au_seq_path(struct seq_file *seq, struct path *path)
24711 + err = seq_path(seq, path, au_esc_chars);
24720 +/* ---------------------------------------------------------------------- */
24722 +static int __init aufs_init(void)
24727 + p = au_esc_chars;
24728 + for (i = 1; i <= ' '; i++)
24734 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24736 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24737 + for (i = 0; i < AuIop_Last; i++)
24738 + aufs_iop_nogetattr[i].getattr = NULL;
24740 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24742 + au_sbilist_init();
24743 + sysaufs_brs_init();
24746 + err = sysaufs_init();
24747 + if (unlikely(err))
24749 + err = dbgaufs_init();
24750 + if (unlikely(err))
24751 + goto out_sysaufs;
24752 + err = au_procfs_init();
24753 + if (unlikely(err))
24754 + goto out_dbgaufs;
24755 + err = au_wkq_init();
24756 + if (unlikely(err))
24758 + err = au_loopback_init();
24759 + if (unlikely(err))
24761 + err = au_hnotify_init();
24762 + if (unlikely(err))
24763 + goto out_loopback;
24764 + err = au_sysrq_init();
24765 + if (unlikely(err))
24767 + err = au_cache_init();
24768 + if (unlikely(err))
24771 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24772 + err = register_filesystem(&aufs_fs_type);
24773 + if (unlikely(err))
24776 + /* since we define pr_fmt, call printk directly */
24777 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24778 + goto out; /* success */
24785 + au_hnotify_fin();
24787 + au_loopback_fin();
24801 +static void __exit aufs_exit(void)
24803 + unregister_filesystem(&aufs_fs_type);
24806 + au_hnotify_fin();
24807 + au_loopback_fin();
24815 +module_init(aufs_init);
24816 +module_exit(aufs_exit);
24817 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24818 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24819 +++ linux/fs/aufs/module.h 2019-07-11 15:42:14.468904634 +0200
24821 +/* SPDX-License-Identifier: GPL-2.0 */
24823 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24825 + * This program, aufs is free software; you can redistribute it and/or modify
24826 + * it under the terms of the GNU General Public License as published by
24827 + * the Free Software Foundation; either version 2 of the License, or
24828 + * (at your option) any later version.
24830 + * This program is distributed in the hope that it will be useful,
24831 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24832 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24833 + * GNU General Public License for more details.
24835 + * You should have received a copy of the GNU General Public License
24836 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24840 + * module initialization and module-global
24843 +#ifndef __AUFS_MODULE_H__
24844 +#define __AUFS_MODULE_H__
24848 +#include <linux/slab.h>
24849 +#include "debug.h"
24850 +#include "dentry.h"
24853 +#include "inode.h"
24858 +/* module parameters */
24859 +extern int sysaufs_brs;
24860 +extern bool au_userns;
24862 +/* ---------------------------------------------------------------------- */
24864 +extern int au_dir_roflags;
24866 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24867 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24871 + * Comparing the size of the object with sizeof(struct rcu_head)
24872 + * case 1: object is always larger
24873 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24874 + * case 2: object is always smaller
24875 + * --> au_kfree_small()
24876 + * case 3: object can be any size
24877 + * --> au_kfree_try_rcu()
24880 +static inline void au_kfree_do_rcu(const void *p)
24883 + struct rcu_head rcu;
24884 + } *a = (void *)p;
24886 + kfree_rcu(a, rcu);
24889 +#define au_kfree_rcu(_p) do { \
24890 + typeof(_p) p = (_p); \
24891 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24893 + au_kfree_do_rcu(p); \
24896 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24897 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24899 +static inline void au_kfree_try_rcu(const void *p)
24903 + if (au_kfree_sz_test(p))
24904 + au_kfree_do_rcu(p);
24909 +static inline void au_kfree_small(const void *p)
24913 + AuDebugOn(au_kfree_sz_test(p));
24917 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24919 +#ifndef CONFIG_SLOB
24920 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24922 + return -1; /* SLOB is untested */
24926 +int au_seq_path(struct seq_file *seq, struct path *path);
24928 +#ifdef CONFIG_PROC_FS
24930 +int __init au_procfs_init(void);
24931 +void au_procfs_fin(void);
24933 +AuStubInt0(au_procfs_init, void);
24934 +AuStubVoid(au_procfs_fin, void);
24937 +/* ---------------------------------------------------------------------- */
24946 + AuCache_HNOTIFY, /* must be last */
24950 +extern struct kmem_cache *au_cache[AuCache_Last];
24952 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24953 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24954 +#define AuCacheCtor(type, ctor) \
24955 + kmem_cache_create(#type, sizeof(struct type), \
24956 + __alignof__(struct type), AuCacheFlags, ctor)
24958 +#define AuCacheFuncs(name, index) \
24959 + static inline struct au_##name *au_cache_alloc_##name(void) \
24960 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24961 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24962 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24964 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24965 + { void *p = rcu; \
24966 + p -= offsetof(struct au_##name, rcu); \
24967 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24968 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24969 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24970 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24972 + static inline void au_cache_free_##name(struct au_##name *p) \
24973 + { /* au_cache_free_##name##_norcu(p); */ \
24974 + au_cache_free_##name##_rcu(p); }
24976 +AuCacheFuncs(dinfo, DINFO);
24977 +AuCacheFuncs(icntnr, ICNTNR);
24978 +AuCacheFuncs(finfo, FINFO);
24979 +AuCacheFuncs(vdir, VDIR);
24980 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24981 +#ifdef CONFIG_AUFS_HNOTIFY
24982 +AuCacheFuncs(hnotify, HNOTIFY);
24985 +#endif /* __KERNEL__ */
24986 +#endif /* __AUFS_MODULE_H__ */
24987 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24988 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24989 +++ linux/fs/aufs/mvdown.c 2019-07-11 15:42:14.472238057 +0200
24991 +// SPDX-License-Identifier: GPL-2.0
24993 + * Copyright (C) 2011-2019 Junjiro R. Okajima
24995 + * This program, aufs is free software; you can redistribute it and/or modify
24996 + * it under the terms of the GNU General Public License as published by
24997 + * the Free Software Foundation; either version 2 of the License, or
24998 + * (at your option) any later version.
25000 + * This program is distributed in the hope that it will be useful,
25001 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25002 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25003 + * GNU General Public License for more details.
25005 + * You should have received a copy of the GNU General Public License
25006 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25010 + * move-down, opposite of copy-up
25015 +struct au_mvd_args {
25017 + struct super_block *h_sb;
25018 + struct dentry *h_parent;
25019 + struct au_hinode *hdir;
25020 + struct inode *h_dir, *h_inode;
25021 + struct au_pin pin;
25022 + } info[AUFS_MVDOWN_NARRAY];
25024 + struct aufs_mvdown mvdown;
25025 + struct dentry *dentry, *parent;
25026 + struct inode *inode, *dir;
25027 + struct super_block *sb;
25028 + aufs_bindex_t bopq, bwh, bfound;
25029 + unsigned char rename_lock;
25032 +#define mvd_errno mvdown.au_errno
25033 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25034 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25035 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25036 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25038 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25039 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25040 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25041 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25042 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25043 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25045 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25046 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25047 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25048 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25049 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25050 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25052 +#define AU_MVD_PR(flag, ...) do { \
25054 + pr_err(__VA_ARGS__); \
25057 +static int find_lower_writable(struct au_mvd_args *a)
25059 + struct super_block *sb;
25060 + aufs_bindex_t bindex, bbot;
25061 + struct au_branch *br;
25064 + bindex = a->mvd_bsrc;
25065 + bbot = au_sbbot(sb);
25066 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25067 + for (bindex++; bindex <= bbot; bindex++) {
25068 + br = au_sbr(sb, bindex);
25069 + if (au_br_fhsm(br->br_perm)
25070 + && !sb_rdonly(au_br_sb(br)))
25073 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25074 + for (bindex++; bindex <= bbot; bindex++) {
25075 + br = au_sbr(sb, bindex);
25076 + if (!au_br_rdonly(br))
25080 + for (bindex++; bindex <= bbot; bindex++) {
25081 + br = au_sbr(sb, bindex);
25082 + if (!sb_rdonly(au_br_sb(br))) {
25083 + if (au_br_rdonly(br))
25085 + |= AUFS_MVDOWN_ROLOWER_R;
25093 +/* make the parent dir on bdst */
25094 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25099 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25100 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25101 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25102 + a->mvd_h_dst_parent = NULL;
25103 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25104 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25105 + if (!a->mvd_h_dst_parent) {
25106 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25107 + if (unlikely(err)) {
25108 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25111 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25119 +/* lock them all */
25120 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25123 + struct dentry *h_trap;
25125 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25126 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25127 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25128 + au_opt_udba(a->sb),
25129 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25131 + if (unlikely(err)) {
25132 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25136 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25137 + a->rename_lock = 0;
25138 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25139 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25140 + au_opt_udba(a->sb),
25141 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25142 + err = au_do_pin(&a->mvd_pin_src);
25144 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25145 + if (unlikely(err)) {
25146 + AU_MVD_PR(dmsg, "pin_src failed\n");
25149 + goto out; /* success */
25152 + a->rename_lock = 1;
25153 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25154 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25155 + au_opt_udba(a->sb),
25156 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25158 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25159 + if (unlikely(err)) {
25160 + AU_MVD_PR(dmsg, "pin_src failed\n");
25161 + au_pin_hdir_lock(&a->mvd_pin_dst);
25164 + au_pin_hdir_unlock(&a->mvd_pin_src);
25165 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25166 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25168 + err = (h_trap != a->mvd_h_src_parent);
25170 + err = (h_trap != a->mvd_h_dst_parent);
25172 + BUG_ON(err); /* it should never happen */
25173 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25176 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25177 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25178 + au_pin_hdir_lock(&a->mvd_pin_src);
25179 + au_unpin(&a->mvd_pin_src);
25180 + au_pin_hdir_lock(&a->mvd_pin_dst);
25183 + goto out; /* success */
25186 + au_unpin(&a->mvd_pin_dst);
25192 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25194 + if (!a->rename_lock)
25195 + au_unpin(&a->mvd_pin_src);
25197 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25198 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25199 + au_pin_hdir_lock(&a->mvd_pin_src);
25200 + au_unpin(&a->mvd_pin_src);
25201 + au_pin_hdir_lock(&a->mvd_pin_dst);
25203 + au_unpin(&a->mvd_pin_dst);
25206 +/* copy-down the file */
25207 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25210 + struct au_cp_generic cpg = {
25211 + .dentry = a->dentry,
25212 + .bdst = a->mvd_bdst,
25213 + .bsrc = a->mvd_bsrc,
25215 + .pin = &a->mvd_pin_dst,
25216 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25219 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25220 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25221 + au_fset_cpup(cpg.flags, OVERWRITE);
25222 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25223 + au_fset_cpup(cpg.flags, RWDST);
25224 + err = au_sio_cpdown_simple(&cpg);
25225 + if (unlikely(err))
25226 + AU_MVD_PR(dmsg, "cpdown failed\n");
25233 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25236 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25239 + struct path h_path;
25240 + struct au_branch *br;
25241 + struct inode *delegated;
25243 + br = au_sbr(a->sb, a->mvd_bdst);
25244 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25245 + err = PTR_ERR(h_path.dentry);
25246 + if (IS_ERR(h_path.dentry)) {
25247 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25252 + if (d_is_positive(h_path.dentry)) {
25253 + h_path.mnt = au_br_mnt(br);
25254 + delegated = NULL;
25255 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25256 + &delegated, /*force*/0);
25257 + if (unlikely(err == -EWOULDBLOCK)) {
25258 + pr_warn("cannot retry for NFSv4 delegation"
25259 + " for an internal unlink\n");
25262 + if (unlikely(err))
25263 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25265 + dput(h_path.dentry);
25273 + * unlink the topmost h_dentry
25275 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25278 + struct path h_path;
25279 + struct inode *delegated;
25281 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25282 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25283 + delegated = NULL;
25284 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25285 + if (unlikely(err == -EWOULDBLOCK)) {
25286 + pr_warn("cannot retry for NFSv4 delegation"
25287 + " for an internal unlink\n");
25290 + if (unlikely(err))
25291 + AU_MVD_PR(dmsg, "unlink failed\n");
25297 +/* Since mvdown succeeded, we ignore an error of this function */
25298 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25301 + struct au_branch *br;
25303 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25304 + br = au_sbr(a->sb, a->mvd_bsrc);
25305 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25307 + br = au_sbr(a->sb, a->mvd_bdst);
25308 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25309 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25312 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25314 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25318 + * copy-down the file and unlink the bsrc file.
25319 + * - unlink the bdst whout if exist
25320 + * - copy-down the file (with whtmp name and rename)
25321 + * - unlink the bsrc file
25323 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25327 + err = au_do_mkdir(dmsg, a);
25329 + err = au_do_lock(dmsg, a);
25330 + if (unlikely(err))
25334 + * do not revert the activities we made on bdst since they should be
25335 + * harmless in aufs.
25338 + err = au_do_cpdown(dmsg, a);
25340 + err = au_do_unlink_wh(dmsg, a);
25341 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25342 + err = au_do_unlink(dmsg, a);
25343 + if (unlikely(err))
25346 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25347 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25348 + if (find_lower_writable(a) < 0)
25349 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25351 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25352 + au_do_stfs(dmsg, a);
25354 + /* maintain internal array */
25355 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25356 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25357 + au_set_dbtop(a->dentry, a->mvd_bdst);
25358 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25359 + au_set_ibtop(a->inode, a->mvd_bdst);
25361 + /* hide the lower */
25362 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25363 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25364 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25365 + au_set_ibbot(a->inode, a->mvd_bsrc);
25367 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25368 + au_set_dbbot(a->dentry, a->mvd_bdst);
25369 + if (au_ibbot(a->inode) < a->mvd_bdst)
25370 + au_set_ibbot(a->inode, a->mvd_bdst);
25373 + au_do_unlock(dmsg, a);
25379 +/* ---------------------------------------------------------------------- */
25381 +/* make sure the file is idle */
25382 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25384 + int err, plinked;
25387 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25388 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25389 + && au_dcount(a->dentry) == 1
25390 + && atomic_read(&a->inode->i_count) == 1
25391 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25392 + && (!plinked || !au_plink_test(a->inode))
25393 + && a->inode->i_nlink == 1)
25398 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25399 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25400 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25401 + a->mvd_h_src_inode->i_nlink,
25402 + plinked, plinked ? au_plink_test(a->inode) : 0);
25409 +/* make sure the parent dir is fine */
25410 +static int au_mvd_args_parent(const unsigned char dmsg,
25411 + struct au_mvd_args *a)
25414 + aufs_bindex_t bindex;
25417 + if (unlikely(au_alive_dir(a->parent))) {
25419 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25423 + a->bopq = au_dbdiropq(a->parent);
25424 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25425 + AuDbg("b%d\n", bindex);
25426 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25427 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25429 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25430 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25431 + a->bopq, a->mvd_bdst);
25439 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25440 + struct au_mvd_args *a)
25443 + struct au_dinfo *dinfo, *tmp;
25445 + /* lookup the next lower positive entry */
25447 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25448 + if (unlikely(!tmp))
25453 + dinfo = au_di(a->dentry);
25454 + au_di_cp(tmp, dinfo);
25455 + au_di_swap(tmp, dinfo);
25457 + /* returns the number of positive dentries */
25458 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25459 + /* AuLkup_IGNORE_PERM */ 0);
25461 + a->bwh = au_dbwh(a->dentry);
25462 + else if (err > 0)
25463 + a->bfound = au_dbtop(a->dentry);
25465 + au_di_swap(tmp, dinfo);
25466 + au_rw_write_unlock(&tmp->di_rwsem);
25468 + if (unlikely(err < 0))
25469 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25472 + * here, we have these cases.
25474 + * no positive dentry under bsrc. there are more sub-cases.
25476 + * there no whiteout, we can safely move-down.
25479 + * bsrc < bwh && bwh < bdst
25480 + * there is a whiteout on RO branch. cannot proceed.
25482 + * there is a whiteout on the RW target branch. it should
25485 + * there is a whiteout somewhere unrelated branch.
25486 + * -1 < bfound && bfound <= bsrc
25489 + * found, but it is on RO branch between bsrc and bdst. cannot
25492 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25495 + * found, after we create the file on bdst, it will be hidden.
25498 + AuDebugOn(a->bfound == -1
25500 + && a->bwh <= a->mvd_bsrc);
25501 + AuDebugOn(-1 < a->bfound
25502 + && a->bfound <= a->mvd_bsrc);
25505 + if (a->bfound == -1
25506 + && a->mvd_bsrc < a->bwh
25508 + && a->bwh < a->mvd_bdst) {
25509 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25510 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25511 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25513 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25514 + a->mvd_errno = EAU_MVDOWN_UPPER;
25515 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25516 + a->mvd_bdst, a->bfound);
25520 + err = 0; /* success */
25527 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25532 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25533 + && a->bfound == a->mvd_bdst)
25539 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25542 + struct au_branch *br;
25545 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25549 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25550 + a->mvd_bsrc = au_ibtop(a->inode);
25552 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25553 + if (unlikely(a->mvd_bsrc < 0
25554 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25555 + || au_dbbot(a->dentry) < a->mvd_bsrc
25556 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25557 + || (a->mvd_bsrc < au_ibtop(a->inode)
25558 + || au_ibbot(a->inode) < a->mvd_bsrc
25559 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25560 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25561 + AU_MVD_PR(dmsg, "no upper\n");
25565 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25566 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25567 + AU_MVD_PR(dmsg, "on the bottom\n");
25570 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25571 + br = au_sbr(a->sb, a->mvd_bsrc);
25572 + err = au_br_rdonly(br);
25573 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25574 + if (unlikely(err))
25576 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25577 + || IS_APPEND(a->mvd_h_src_inode))) {
25579 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25585 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25586 + a->mvd_bdst = find_lower_writable(a);
25587 + if (unlikely(a->mvd_bdst < 0)) {
25588 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25589 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25593 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25594 + if (unlikely(a->mvd_bdst < 0
25595 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25596 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25597 + AU_MVD_PR(dmsg, "no lower brid\n");
25602 + err = au_mvd_args_busy(dmsg, a);
25604 + err = au_mvd_args_parent(dmsg, a);
25606 + err = au_mvd_args_intermediate(dmsg, a);
25608 + err = au_mvd_args_exist(dmsg, a);
25610 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25617 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25620 + unsigned char dmsg;
25621 + struct au_mvd_args *args;
25622 + struct inode *inode;
25624 + inode = d_inode(dentry);
25626 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25630 + args = kmalloc(sizeof(*args), GFP_NOFS);
25631 + if (unlikely(!args))
25634 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25636 + /* VERIFY_WRITE */
25637 + err = !access_ok(uarg, sizeof(*uarg));
25638 + if (unlikely(err)) {
25643 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25644 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25645 + args->mvdown.au_errno = 0;
25646 + args->dentry = dentry;
25647 + args->inode = inode;
25648 + args->sb = dentry->d_sb;
25651 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25652 + args->parent = dget_parent(dentry);
25653 + args->dir = d_inode(args->parent);
25654 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25655 + dput(args->parent);
25656 + if (unlikely(args->parent != dentry->d_parent)) {
25657 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25661 + inode_lock_nested(inode, I_MUTEX_CHILD);
25662 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25663 + if (unlikely(err))
25666 + di_write_lock_parent(args->parent);
25667 + err = au_mvd_args(dmsg, args);
25668 + if (unlikely(err))
25671 + err = au_do_mvdown(dmsg, args);
25672 + if (unlikely(err))
25675 + au_cpup_attr_timesizes(args->dir);
25676 + au_cpup_attr_timesizes(inode);
25677 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25678 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25679 + /* au_digen_dec(dentry); */
25682 + di_write_unlock(args->parent);
25683 + aufs_read_unlock(dentry, AuLock_DW);
25685 + inode_unlock(inode);
25687 + inode_unlock(args->dir);
25689 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25692 + au_kfree_rcu(args);
25697 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25698 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25699 +++ linux/fs/aufs/opts.c 2019-09-16 09:38:43.216175640 +0200
25701 +// SPDX-License-Identifier: GPL-2.0
25703 + * Copyright (C) 2005-2019 Junjiro R. Okajima
25705 + * This program, aufs is free software; you can redistribute it and/or modify
25706 + * it under the terms of the GNU General Public License as published by
25707 + * the Free Software Foundation; either version 2 of the License, or
25708 + * (at your option) any later version.
25710 + * This program is distributed in the hope that it will be useful,
25711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25713 + * GNU General Public License for more details.
25715 + * You should have received a copy of the GNU General Public License
25716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25720 + * mount options/flags
25723 +#include <linux/namei.h>
25724 +#include <linux/types.h> /* a distribution requires */
25725 +#include <linux/parser.h>
25728 +/* ---------------------------------------------------------------------- */
25732 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25733 + Opt_idel, Opt_imod,
25734 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25735 + Opt_rdblk_def, Opt_rdhash_def,
25736 + Opt_xino, Opt_noxino,
25737 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25738 + Opt_trunc_xino_path, Opt_itrunc_xino,
25739 + Opt_trunc_xib, Opt_notrunc_xib,
25740 + Opt_shwh, Opt_noshwh,
25741 + Opt_plink, Opt_noplink, Opt_list_plink,
25743 + Opt_dio, Opt_nodio,
25744 + Opt_diropq_a, Opt_diropq_w,
25745 + Opt_warn_perm, Opt_nowarn_perm,
25746 + Opt_wbr_copyup, Opt_wbr_create,
25748 + Opt_verbose, Opt_noverbose,
25749 + Opt_sum, Opt_nosum, Opt_wsum,
25750 + Opt_dirperm1, Opt_nodirperm1,
25751 + Opt_dirren, Opt_nodirren,
25752 + Opt_acl, Opt_noacl,
25753 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25756 +static match_table_t options = {
25757 + {Opt_br, "br=%s"},
25758 + {Opt_br, "br:%s"},
25760 + {Opt_add, "add=%d:%s"},
25761 + {Opt_add, "add:%d:%s"},
25762 + {Opt_add, "ins=%d:%s"},
25763 + {Opt_add, "ins:%d:%s"},
25764 + {Opt_append, "append=%s"},
25765 + {Opt_append, "append:%s"},
25766 + {Opt_prepend, "prepend=%s"},
25767 + {Opt_prepend, "prepend:%s"},
25769 + {Opt_del, "del=%s"},
25770 + {Opt_del, "del:%s"},
25771 + /* {Opt_idel, "idel:%d"}, */
25772 + {Opt_mod, "mod=%s"},
25773 + {Opt_mod, "mod:%s"},
25774 + /* {Opt_imod, "imod:%d:%s"}, */
25776 + {Opt_dirwh, "dirwh=%d"},
25778 + {Opt_xino, "xino=%s"},
25779 + {Opt_noxino, "noxino"},
25780 + {Opt_trunc_xino, "trunc_xino"},
25781 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25782 + {Opt_notrunc_xino, "notrunc_xino"},
25783 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25784 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25785 + /* {Opt_zxino, "zxino=%s"}, */
25786 + {Opt_trunc_xib, "trunc_xib"},
25787 + {Opt_notrunc_xib, "notrunc_xib"},
25789 +#ifdef CONFIG_PROC_FS
25790 + {Opt_plink, "plink"},
25792 + {Opt_ignore_silent, "plink"},
25795 + {Opt_noplink, "noplink"},
25797 +#ifdef CONFIG_AUFS_DEBUG
25798 + {Opt_list_plink, "list_plink"},
25801 + {Opt_udba, "udba=%s"},
25803 + {Opt_dio, "dio"},
25804 + {Opt_nodio, "nodio"},
25806 +#ifdef CONFIG_AUFS_DIRREN
25807 + {Opt_dirren, "dirren"},
25808 + {Opt_nodirren, "nodirren"},
25810 + {Opt_ignore, "dirren"},
25811 + {Opt_ignore_silent, "nodirren"},
25814 +#ifdef CONFIG_AUFS_FHSM
25815 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25817 + {Opt_ignore, "fhsm_sec=%d"},
25820 + {Opt_diropq_a, "diropq=always"},
25821 + {Opt_diropq_a, "diropq=a"},
25822 + {Opt_diropq_w, "diropq=whiteouted"},
25823 + {Opt_diropq_w, "diropq=w"},
25825 + {Opt_warn_perm, "warn_perm"},
25826 + {Opt_nowarn_perm, "nowarn_perm"},
25828 + /* keep them temporary */
25829 + {Opt_ignore_silent, "nodlgt"},
25830 + {Opt_ignore, "clean_plink"},
25832 +#ifdef CONFIG_AUFS_SHWH
25833 + {Opt_shwh, "shwh"},
25835 + {Opt_noshwh, "noshwh"},
25837 + {Opt_dirperm1, "dirperm1"},
25838 + {Opt_nodirperm1, "nodirperm1"},
25840 + {Opt_verbose, "verbose"},
25841 + {Opt_verbose, "v"},
25842 + {Opt_noverbose, "noverbose"},
25843 + {Opt_noverbose, "quiet"},
25844 + {Opt_noverbose, "q"},
25845 + {Opt_noverbose, "silent"},
25847 + {Opt_sum, "sum"},
25848 + {Opt_nosum, "nosum"},
25849 + {Opt_wsum, "wsum"},
25851 + {Opt_rdcache, "rdcache=%d"},
25852 + {Opt_rdblk, "rdblk=%d"},
25853 + {Opt_rdblk_def, "rdblk=def"},
25854 + {Opt_rdhash, "rdhash=%d"},
25855 + {Opt_rdhash_def, "rdhash=def"},
25857 + {Opt_wbr_create, "create=%s"},
25858 + {Opt_wbr_create, "create_policy=%s"},
25859 + {Opt_wbr_copyup, "cpup=%s"},
25860 + {Opt_wbr_copyup, "copyup=%s"},
25861 + {Opt_wbr_copyup, "copyup_policy=%s"},
25863 + /* generic VFS flag */
25864 +#ifdef CONFIG_FS_POSIX_ACL
25865 + {Opt_acl, "acl"},
25866 + {Opt_noacl, "noacl"},
25868 + {Opt_ignore, "acl"},
25869 + {Opt_ignore_silent, "noacl"},
25872 + /* internal use for the scripts */
25873 + {Opt_ignore_silent, "si=%s"},
25875 + {Opt_br, "dirs=%s"},
25876 + {Opt_ignore, "debug=%d"},
25877 + {Opt_ignore, "delete=whiteout"},
25878 + {Opt_ignore, "delete=all"},
25879 + {Opt_ignore, "imap=%s"},
25881 + /* temporary workaround, due to old mount(8)? */
25882 + {Opt_ignore_silent, "relatime"},
25887 +/* ---------------------------------------------------------------------- */
25889 +static const char *au_parser_pattern(int val, match_table_t tbl)
25891 + struct match_token *p;
25894 + while (p->pattern) {
25895 + if (p->token == val)
25896 + return p->pattern;
25903 +static const char *au_optstr(int *val, match_table_t tbl)
25905 + struct match_token *p;
25912 + while (p->pattern) {
25914 + && (v & p->token) == p->token) {
25915 + *val &= ~p->token;
25916 + return p->pattern;
25925 +/* ---------------------------------------------------------------------- */
25927 +static match_table_t brperm = {
25928 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25929 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25930 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25934 +static match_table_t brattr = {
25936 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25937 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25938 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25939 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25940 +#ifdef CONFIG_AUFS_FHSM
25941 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25943 +#ifdef CONFIG_AUFS_XATTR
25944 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25945 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25946 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25947 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25948 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25949 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25952 + /* ro/rr branch */
25953 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25956 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25957 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25962 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25969 + p = strchr(str, '+');
25972 + v = match_token(str, table, args);
25974 + if (v & AuBrAttr_CMOO_Mask)
25975 + attr &= ~AuBrAttr_CMOO_Mask;
25980 + pr_warn("ignored branch attribute %s\n", str);
25990 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25998 + p = au_optstr(&perm, brattr);
26001 + memcpy(q, p, sz + 1);
26007 + p = au_optstr(&perm, brattr);
26011 + memcpy(q, p, sz + 1);
26017 + return q - str->a;
26020 +static int noinline_for_stack br_perm_val(char *perm)
26022 + int val, bad, sz;
26024 + substring_t args[MAX_OPT_ARGS];
26025 + au_br_perm_str_t attr;
26027 + p = strchr(perm, '+');
26030 + val = match_token(perm, brperm, args);
26034 + pr_warn("ignored branch permission %s\n", perm);
26035 + val = AuBrPerm_RO;
26041 + val |= br_attr_val(p + 1, brattr, args);
26044 + switch (val & AuBrPerm_Mask) {
26045 + case AuBrPerm_RO:
26046 + case AuBrPerm_RR:
26047 + bad = val & AuBrWAttr_Mask;
26048 + val &= ~AuBrWAttr_Mask;
26050 + case AuBrPerm_RW:
26051 + bad = val & AuBrRAttr_Mask;
26052 + val &= ~AuBrRAttr_Mask;
26057 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26058 + * does not treat it as an error, just warning.
26059 + * this is a tiny guard for the user operation.
26061 + if (val & AuBrAttr_UNPIN) {
26062 + bad |= AuBrAttr_UNPIN;
26063 + val &= ~AuBrAttr_UNPIN;
26066 + if (unlikely(bad)) {
26067 + sz = au_do_optstr_br_attr(&attr, bad);
26069 + pr_warn("ignored branch attribute %s\n", attr.a);
26076 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26078 + au_br_perm_str_t attr;
26084 + p = au_optstr(&perm, brperm);
26085 + AuDebugOn(!p || !*p);
26087 + memcpy(q, p, sz + 1);
26090 + sz = au_do_optstr_br_attr(&attr, perm);
26093 + memcpy(q, attr.a, sz + 1);
26096 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26099 +/* ---------------------------------------------------------------------- */
26101 +static match_table_t udbalevel = {
26102 + {AuOpt_UDBA_REVAL, "reval"},
26103 + {AuOpt_UDBA_NONE, "none"},
26104 +#ifdef CONFIG_AUFS_HNOTIFY
26105 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26106 +#ifdef CONFIG_AUFS_HFSNOTIFY
26107 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26113 +static int noinline_for_stack udba_val(char *str)
26115 + substring_t args[MAX_OPT_ARGS];
26117 + return match_token(str, udbalevel, args);
26120 +const char *au_optstr_udba(int udba)
26122 + return au_parser_pattern(udba, udbalevel);
26125 +/* ---------------------------------------------------------------------- */
26127 +static match_table_t au_wbr_create_policy = {
26128 + {AuWbrCreate_TDP, "tdp"},
26129 + {AuWbrCreate_TDP, "top-down-parent"},
26130 + {AuWbrCreate_RR, "rr"},
26131 + {AuWbrCreate_RR, "round-robin"},
26132 + {AuWbrCreate_MFS, "mfs"},
26133 + {AuWbrCreate_MFS, "most-free-space"},
26134 + {AuWbrCreate_MFSV, "mfs:%d"},
26135 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26137 + /* top-down regardless the parent, and then mfs */
26138 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26139 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26141 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26142 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26143 + {AuWbrCreate_PMFS, "pmfs"},
26144 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26145 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26146 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26151 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26152 + struct au_opt_wbr_create *create)
26155 + unsigned long long ull;
26158 + if (!match_u64(arg, &ull))
26159 + create->mfsrr_watermark = ull;
26161 + pr_err("bad integer in %s\n", str);
26168 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26169 + struct au_opt_wbr_create *create)
26174 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26175 + create->mfs_second = n;
26177 + pr_err("bad integer in %s\n", str);
26184 +static int noinline_for_stack
26185 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26188 + substring_t args[MAX_OPT_ARGS];
26190 + err = match_token(str, au_wbr_create_policy, args);
26191 + create->wbr_create = err;
26193 + case AuWbrCreate_MFSRRV:
26194 + case AuWbrCreate_TDMFSV:
26195 + case AuWbrCreate_PMFSRRV:
26196 + e = au_wbr_mfs_wmark(&args[0], str, create);
26198 + e = au_wbr_mfs_sec(&args[1], str, create);
26202 + case AuWbrCreate_MFSRR:
26203 + case AuWbrCreate_TDMFS:
26204 + case AuWbrCreate_PMFSRR:
26205 + e = au_wbr_mfs_wmark(&args[0], str, create);
26206 + if (unlikely(e)) {
26211 + case AuWbrCreate_MFS:
26212 + case AuWbrCreate_PMFS:
26213 + create->mfs_second = AUFS_MFS_DEF_SEC;
26215 + case AuWbrCreate_MFSV:
26216 + case AuWbrCreate_PMFSV:
26217 + e = au_wbr_mfs_sec(&args[0], str, create);
26226 +const char *au_optstr_wbr_create(int wbr_create)
26228 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26231 +static match_table_t au_wbr_copyup_policy = {
26232 + {AuWbrCopyup_TDP, "tdp"},
26233 + {AuWbrCopyup_TDP, "top-down-parent"},
26234 + {AuWbrCopyup_BUP, "bup"},
26235 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26236 + {AuWbrCopyup_BU, "bu"},
26237 + {AuWbrCopyup_BU, "bottom-up"},
26241 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26243 + substring_t args[MAX_OPT_ARGS];
26245 + return match_token(str, au_wbr_copyup_policy, args);
26248 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26250 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26253 +/* ---------------------------------------------------------------------- */
26255 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26257 +static void dump_opts(struct au_opts *opts)
26259 +#ifdef CONFIG_AUFS_DEBUG
26260 + /* reduce stack space */
26262 + struct au_opt_add *add;
26263 + struct au_opt_del *del;
26264 + struct au_opt_mod *mod;
26265 + struct au_opt_xino *xino;
26266 + struct au_opt_xino_itrunc *xino_itrunc;
26267 + struct au_opt_wbr_create *create;
26269 + struct au_opt *opt;
26272 + while (opt->type != Opt_tail) {
26273 + switch (opt->type) {
26275 + u.add = &opt->add;
26276 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26277 + u.add->bindex, u.add->pathname, u.add->perm,
26278 + u.add->path.dentry);
26282 + u.del = &opt->del;
26283 + AuDbg("del {%s, %p}\n",
26284 + u.del->pathname, u.del->h_path.dentry);
26288 + u.mod = &opt->mod;
26289 + AuDbg("mod {%s, 0x%x, %p}\n",
26290 + u.mod->path, u.mod->perm, u.mod->h_root);
26293 + u.add = &opt->add;
26294 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26295 + u.add->bindex, u.add->pathname, u.add->perm,
26296 + u.add->path.dentry);
26298 + case Opt_prepend:
26299 + u.add = &opt->add;
26300 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26301 + u.add->bindex, u.add->pathname, u.add->perm,
26302 + u.add->path.dentry);
26305 + AuDbg("dirwh %d\n", opt->dirwh);
26307 + case Opt_rdcache:
26308 + AuDbg("rdcache %d\n", opt->rdcache);
26311 + AuDbg("rdblk %u\n", opt->rdblk);
26313 + case Opt_rdblk_def:
26314 + AuDbg("rdblk_def\n");
26317 + AuDbg("rdhash %u\n", opt->rdhash);
26319 + case Opt_rdhash_def:
26320 + AuDbg("rdhash_def\n");
26323 + u.xino = &opt->xino;
26324 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26326 + case Opt_trunc_xino:
26327 + AuLabel(trunc_xino);
26329 + case Opt_notrunc_xino:
26330 + AuLabel(notrunc_xino);
26332 + case Opt_trunc_xino_path:
26333 + case Opt_itrunc_xino:
26334 + u.xino_itrunc = &opt->xino_itrunc;
26335 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26340 + case Opt_trunc_xib:
26341 + AuLabel(trunc_xib);
26343 + case Opt_notrunc_xib:
26344 + AuLabel(notrunc_xib);
26352 + case Opt_dirperm1:
26353 + AuLabel(dirperm1);
26355 + case Opt_nodirperm1:
26356 + AuLabel(nodirperm1);
26361 + case Opt_noplink:
26362 + AuLabel(noplink);
26364 + case Opt_list_plink:
26365 + AuLabel(list_plink);
26368 + AuDbg("udba %d, %s\n",
26369 + opt->udba, au_optstr_udba(opt->udba));
26377 + case Opt_diropq_a:
26378 + AuLabel(diropq_a);
26380 + case Opt_diropq_w:
26381 + AuLabel(diropq_w);
26383 + case Opt_warn_perm:
26384 + AuLabel(warn_perm);
26386 + case Opt_nowarn_perm:
26387 + AuLabel(nowarn_perm);
26389 + case Opt_verbose:
26390 + AuLabel(verbose);
26392 + case Opt_noverbose:
26393 + AuLabel(noverbose);
26404 + case Opt_wbr_create:
26405 + u.create = &opt->wbr_create;
26406 + AuDbg("create %d, %s\n", u.create->wbr_create,
26407 + au_optstr_wbr_create(u.create->wbr_create));
26408 + switch (u.create->wbr_create) {
26409 + case AuWbrCreate_MFSV:
26410 + case AuWbrCreate_PMFSV:
26411 + AuDbg("%d sec\n", u.create->mfs_second);
26413 + case AuWbrCreate_MFSRR:
26414 + case AuWbrCreate_TDMFS:
26415 + AuDbg("%llu watermark\n",
26416 + u.create->mfsrr_watermark);
26418 + case AuWbrCreate_MFSRRV:
26419 + case AuWbrCreate_TDMFSV:
26420 + case AuWbrCreate_PMFSRRV:
26421 + AuDbg("%llu watermark, %d sec\n",
26422 + u.create->mfsrr_watermark,
26423 + u.create->mfs_second);
26427 + case Opt_wbr_copyup:
26428 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26429 + au_optstr_wbr_copyup(opt->wbr_copyup));
26431 + case Opt_fhsm_sec:
26432 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26437 + case Opt_nodirren:
26438 + AuLabel(nodirren);
26454 +void au_opts_free(struct au_opts *opts)
26456 + struct au_opt *opt;
26459 + while (opt->type != Opt_tail) {
26460 + switch (opt->type) {
26463 + case Opt_prepend:
26464 + path_put(&opt->add.path);
26468 + path_put(&opt->del.h_path);
26472 + dput(opt->mod.h_root);
26475 + fput(opt->xino.file);
26482 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26483 + aufs_bindex_t bindex)
26486 + struct au_opt_add *add = &opt->add;
26489 + add->bindex = bindex;
26490 + add->perm = AuBrPerm_RO;
26491 + add->pathname = opt_str;
26492 + p = strchr(opt_str, '=');
26496 + add->perm = br_perm_val(p);
26499 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26502 + add->perm = AuBrPerm_RO;
26503 + if (au_test_fs_rr(add->path.dentry->d_sb))
26504 + add->perm = AuBrPerm_RR;
26505 + else if (!bindex && !(sb_flags & SB_RDONLY))
26506 + add->perm = AuBrPerm_RW;
26508 + opt->type = Opt_add;
26511 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26518 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26522 + del->pathname = args[0].from;
26523 + AuDbg("del path %s\n", del->pathname);
26525 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26526 + if (unlikely(err))
26527 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26532 +#if 0 /* reserved for future use */
26533 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26534 + struct au_opt_del *del, substring_t args[])
26537 + struct dentry *root;
26540 + root = sb->s_root;
26541 + aufs_read_lock(root, AuLock_FLUSH);
26542 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26543 + pr_err("out of bounds, %d\n", bindex);
26548 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26549 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26552 + aufs_read_unlock(root, !AuLock_IR);
26557 +static int noinline_for_stack
26558 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26561 + struct path path;
26565 + mod->path = args[0].from;
26566 + p = strchr(mod->path, '=');
26567 + if (unlikely(!p)) {
26568 + pr_err("no permission %s\n", args[0].from);
26573 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26574 + if (unlikely(err)) {
26575 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26579 + mod->perm = br_perm_val(p);
26580 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26581 + mod->h_root = dget(path.dentry);
26588 +#if 0 /* reserved for future use */
26589 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26590 + struct au_opt_mod *mod, substring_t args[])
26593 + struct dentry *root;
26596 + root = sb->s_root;
26597 + aufs_read_lock(root, AuLock_FLUSH);
26598 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26599 + pr_err("out of bounds, %d\n", bindex);
26604 + mod->perm = br_perm_val(args[1].from);
26605 + AuDbg("mod path %s, perm 0x%x, %s\n",
26606 + mod->path, mod->perm, args[1].from);
26607 + mod->h_root = dget(au_h_dptr(root, bindex));
26610 + aufs_read_unlock(root, !AuLock_IR);
26615 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26616 + substring_t args[])
26619 + struct file *file;
26621 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26622 + err = PTR_ERR(file);
26623 + if (IS_ERR(file))
26627 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26629 + pr_err("%s must be outside\n", args[0].from);
26634 + xino->file = file;
26635 + xino->path = args[0].from;
26641 +static int noinline_for_stack
26642 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26643 + struct au_opt_xino_itrunc *xino_itrunc,
26644 + substring_t args[])
26647 + aufs_bindex_t bbot, bindex;
26648 + struct path path;
26649 + struct dentry *root;
26651 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26652 + if (unlikely(err)) {
26653 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26657 + xino_itrunc->bindex = -1;
26658 + root = sb->s_root;
26659 + aufs_read_lock(root, AuLock_FLUSH);
26660 + bbot = au_sbbot(sb);
26661 + for (bindex = 0; bindex <= bbot; bindex++) {
26662 + if (au_h_dptr(root, bindex) == path.dentry) {
26663 + xino_itrunc->bindex = bindex;
26667 + aufs_read_unlock(root, !AuLock_IR);
26670 + if (unlikely(xino_itrunc->bindex < 0)) {
26671 + pr_err("no such branch %s\n", args[0].from);
26679 +/* called without aufs lock */
26680 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26682 + int err, n, token;
26683 + aufs_bindex_t bindex;
26684 + unsigned char skipped;
26685 + struct dentry *root;
26686 + struct au_opt *opt, *opt_tail;
26688 + /* reduce the stack space */
26690 + struct au_opt_xino_itrunc *xino_itrunc;
26691 + struct au_opt_wbr_create *create;
26694 + substring_t args[MAX_OPT_ARGS];
26698 + a = kmalloc(sizeof(*a), GFP_NOFS);
26699 + if (unlikely(!a))
26702 + root = sb->s_root;
26706 + opt_tail = opt + opts->max_opt - 1;
26707 + opt->type = Opt_tail;
26708 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26711 + token = match_token(opt_str, options, a->args);
26715 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26717 + err = opt_add(opt, opt_str, opts->sb_flags,
26719 + if (unlikely(!err && ++opt > opt_tail)) {
26723 + opt->type = Opt_tail;
26728 + if (unlikely(match_int(&a->args[0], &n))) {
26729 + pr_err("bad integer in %s\n", opt_str);
26733 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26736 + opt->type = token;
26739 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26740 + /*dummy bindex*/1);
26742 + opt->type = token;
26744 + case Opt_prepend:
26745 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26748 + opt->type = token;
26751 + err = au_opts_parse_del(&opt->del, a->args);
26753 + opt->type = token;
26755 +#if 0 /* reserved for future use */
26757 + del->pathname = "(indexed)";
26758 + if (unlikely(match_int(&args[0], &n))) {
26759 + pr_err("bad integer in %s\n", opt_str);
26762 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26764 + opt->type = token;
26768 + err = au_opts_parse_mod(&opt->mod, a->args);
26770 + opt->type = token;
26772 +#ifdef IMOD /* reserved for future use */
26774 + u.mod->path = "(indexed)";
26775 + if (unlikely(match_int(&a->args[0], &n))) {
26776 + pr_err("bad integer in %s\n", opt_str);
26779 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26781 + opt->type = token;
26785 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26787 + opt->type = token;
26790 + case Opt_trunc_xino_path:
26791 + err = au_opts_parse_xino_itrunc_path
26792 + (sb, &opt->xino_itrunc, a->args);
26794 + opt->type = token;
26797 + case Opt_itrunc_xino:
26798 + u.xino_itrunc = &opt->xino_itrunc;
26799 + if (unlikely(match_int(&a->args[0], &n))) {
26800 + pr_err("bad integer in %s\n", opt_str);
26803 + u.xino_itrunc->bindex = n;
26804 + aufs_read_lock(root, AuLock_FLUSH);
26805 + if (n < 0 || au_sbbot(sb) < n) {
26806 + pr_err("out of bounds, %d\n", n);
26807 + aufs_read_unlock(root, !AuLock_IR);
26810 + aufs_read_unlock(root, !AuLock_IR);
26812 + opt->type = token;
26816 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26819 + opt->type = token;
26822 + case Opt_rdcache:
26823 + if (unlikely(match_int(&a->args[0], &n))) {
26824 + pr_err("bad integer in %s\n", opt_str);
26827 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26828 + pr_err("rdcache must be smaller than %d\n",
26829 + AUFS_RDCACHE_MAX);
26832 + opt->rdcache = n;
26834 + opt->type = token;
26837 + if (unlikely(match_int(&a->args[0], &n)
26839 + || n > KMALLOC_MAX_SIZE)) {
26840 + pr_err("bad integer in %s\n", opt_str);
26843 + if (unlikely(n && n < NAME_MAX)) {
26844 + pr_err("rdblk must be larger than %d\n",
26850 + opt->type = token;
26853 + if (unlikely(match_int(&a->args[0], &n)
26855 + || n * sizeof(struct hlist_head)
26856 + > KMALLOC_MAX_SIZE)) {
26857 + pr_err("bad integer in %s\n", opt_str);
26862 + opt->type = token;
26865 + case Opt_trunc_xino:
26866 + case Opt_notrunc_xino:
26868 + case Opt_trunc_xib:
26869 + case Opt_notrunc_xib:
26872 + case Opt_dirperm1:
26873 + case Opt_nodirperm1:
26875 + case Opt_noplink:
26876 + case Opt_list_plink:
26879 + case Opt_diropq_a:
26880 + case Opt_diropq_w:
26881 + case Opt_warn_perm:
26882 + case Opt_nowarn_perm:
26883 + case Opt_verbose:
26884 + case Opt_noverbose:
26888 + case Opt_rdblk_def:
26889 + case Opt_rdhash_def:
26891 + case Opt_nodirren:
26895 + opt->type = token;
26899 + opt->udba = udba_val(a->args[0].from);
26900 + if (opt->udba >= 0) {
26902 + opt->type = token;
26904 + pr_err("wrong value, %s\n", opt_str);
26907 + case Opt_wbr_create:
26908 + u.create = &opt->wbr_create;
26909 + u.create->wbr_create
26910 + = au_wbr_create_val(a->args[0].from, u.create);
26911 + if (u.create->wbr_create >= 0) {
26913 + opt->type = token;
26915 + pr_err("wrong value, %s\n", opt_str);
26917 + case Opt_wbr_copyup:
26918 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26919 + if (opt->wbr_copyup >= 0) {
26921 + opt->type = token;
26923 + pr_err("wrong value, %s\n", opt_str);
26926 + case Opt_fhsm_sec:
26927 + if (unlikely(match_int(&a->args[0], &n)
26929 + pr_err("bad integer in %s\n", opt_str);
26932 + if (sysaufs_brs) {
26933 + opt->fhsm_second = n;
26934 + opt->type = token;
26936 + pr_warn("ignored %s\n", opt_str);
26941 + pr_warn("ignored %s\n", opt_str);
26943 + case Opt_ignore_silent:
26948 + pr_err("unknown option %s\n", opt_str);
26952 + if (!err && !skipped) {
26953 + if (unlikely(++opt > opt_tail)) {
26956 + opt->type = Opt_tail;
26959 + opt->type = Opt_tail;
26965 + if (unlikely(err))
26966 + au_opts_free(opts);
26972 +static int au_opt_wbr_create(struct super_block *sb,
26973 + struct au_opt_wbr_create *create)
26976 + struct au_sbinfo *sbinfo;
26978 + SiMustWriteLock(sb);
26980 + err = 1; /* handled */
26981 + sbinfo = au_sbi(sb);
26982 + if (sbinfo->si_wbr_create_ops->fin) {
26983 + err = sbinfo->si_wbr_create_ops->fin(sb);
26988 + sbinfo->si_wbr_create = create->wbr_create;
26989 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26990 + switch (create->wbr_create) {
26991 + case AuWbrCreate_MFSRRV:
26992 + case AuWbrCreate_MFSRR:
26993 + case AuWbrCreate_TDMFS:
26994 + case AuWbrCreate_TDMFSV:
26995 + case AuWbrCreate_PMFSRR:
26996 + case AuWbrCreate_PMFSRRV:
26997 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26999 + case AuWbrCreate_MFS:
27000 + case AuWbrCreate_MFSV:
27001 + case AuWbrCreate_PMFS:
27002 + case AuWbrCreate_PMFSV:
27003 + sbinfo->si_wbr_mfs.mfs_expire
27004 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27008 + if (sbinfo->si_wbr_create_ops->init)
27009 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27016 + * plus: processed without an error
27017 + * zero: unprocessed
27019 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27020 + struct au_opts *opts)
27023 + struct au_sbinfo *sbinfo;
27025 + SiMustWriteLock(sb);
27027 + err = 1; /* handled */
27028 + sbinfo = au_sbi(sb);
27029 + switch (opt->type) {
27031 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27032 + sbinfo->si_mntflags |= opt->udba;
27033 + opts->given_udba |= opt->udba;
27037 + au_opt_set(sbinfo->si_mntflags, PLINK);
27039 + case Opt_noplink:
27040 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27041 + au_plink_put(sb, /*verbose*/1);
27042 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27044 + case Opt_list_plink:
27045 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27046 + au_plink_list(sb);
27050 + au_opt_set(sbinfo->si_mntflags, DIO);
27051 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27054 + au_opt_clr(sbinfo->si_mntflags, DIO);
27055 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27058 + case Opt_fhsm_sec:
27059 + au_fhsm_set(sbinfo, opt->fhsm_second);
27062 + case Opt_diropq_a:
27063 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27065 + case Opt_diropq_w:
27066 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27069 + case Opt_warn_perm:
27070 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27072 + case Opt_nowarn_perm:
27073 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27076 + case Opt_verbose:
27077 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27079 + case Opt_noverbose:
27080 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27084 + au_opt_set(sbinfo->si_mntflags, SUM);
27087 + au_opt_clr(sbinfo->si_mntflags, SUM);
27088 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27091 + au_opt_clr(sbinfo->si_mntflags, SUM);
27092 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27095 + case Opt_wbr_create:
27096 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27098 + case Opt_wbr_copyup:
27099 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27100 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27104 + sbinfo->si_dirwh = opt->dirwh;
27107 + case Opt_rdcache:
27108 + sbinfo->si_rdcache
27109 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27112 + sbinfo->si_rdblk = opt->rdblk;
27114 + case Opt_rdblk_def:
27115 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27118 + sbinfo->si_rdhash = opt->rdhash;
27120 + case Opt_rdhash_def:
27121 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27125 + au_opt_set(sbinfo->si_mntflags, SHWH);
27128 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27131 + case Opt_dirperm1:
27132 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27134 + case Opt_nodirperm1:
27135 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27138 + case Opt_trunc_xino:
27139 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27141 + case Opt_notrunc_xino:
27142 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27145 + case Opt_trunc_xino_path:
27146 + case Opt_itrunc_xino:
27147 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27153 + case Opt_trunc_xib:
27154 + au_fset_opts(opts->flags, TRUNC_XIB);
27156 + case Opt_notrunc_xib:
27157 + au_fclr_opts(opts->flags, TRUNC_XIB);
27162 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27163 + err = au_dr_opt_set(sb);
27168 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27170 + case Opt_nodirren:
27172 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27173 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27179 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27183 + sb->s_flags |= SB_POSIXACL;
27186 + sb->s_flags &= ~SB_POSIXACL;
27198 + * returns tri-state.
27199 + * plus: processed without an error
27200 + * zero: unprocessed
27203 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27204 + struct au_opts *opts)
27206 + int err, do_refresh;
27209 + switch (opt->type) {
27211 + opt->add.bindex = au_sbbot(sb) + 1;
27212 + if (opt->add.bindex < 0)
27213 + opt->add.bindex = 0;
27215 + /* Always goto add, not fallthrough */
27216 + case Opt_prepend:
27217 + opt->add.bindex = 0;
27218 + /* fallthrough */
27219 + add: /* indented label */
27221 + err = au_br_add(sb, &opt->add,
27222 + au_ftest_opts(opts->flags, REMOUNT));
27225 + au_fset_opts(opts->flags, REFRESH);
27231 + err = au_br_del(sb, &opt->del,
27232 + au_ftest_opts(opts->flags, REMOUNT));
27235 + au_fset_opts(opts->flags, TRUNC_XIB);
27236 + au_fset_opts(opts->flags, REFRESH);
27242 + err = au_br_mod(sb, &opt->mod,
27243 + au_ftest_opts(opts->flags, REMOUNT),
27248 + au_fset_opts(opts->flags, REFRESH);
27255 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27256 + struct au_opt_xino **opt_xino,
27257 + struct au_opts *opts)
27262 + switch (opt->type) {
27264 + err = au_xino_set(sb, &opt->xino,
27265 + !!au_ftest_opts(opts->flags, REMOUNT));
27266 + if (unlikely(err))
27269 + *opt_xino = &opt->xino;
27274 + *opt_xino = (void *)-1;
27281 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27282 + unsigned int pending)
27285 + aufs_bindex_t bindex, bbot;
27286 + unsigned char do_plink, skip, do_free, can_no_dreval;
27287 + struct au_branch *br;
27288 + struct au_wbr *wbr;
27289 + struct dentry *root, *dentry;
27290 + struct inode *dir, *h_dir;
27291 + struct au_sbinfo *sbinfo;
27292 + struct au_hinode *hdir;
27294 + SiMustAnyLock(sb);
27296 + sbinfo = au_sbi(sb);
27297 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27299 + if (!(sb_flags & SB_RDONLY)) {
27300 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27301 + pr_warn("first branch should be rw\n");
27302 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27303 + pr_warn_once("shwh should be used with ro\n");
27306 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27307 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27308 + pr_warn_once("udba=*notify requires xino\n");
27310 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27311 + pr_warn_once("dirperm1 breaks the protection"
27312 + " by the permission bits on the lower branch\n");
27316 + root = sb->s_root;
27317 + dir = d_inode(root);
27318 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27319 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27321 + bbot = au_sbbot(sb);
27322 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27324 + h_dir = au_h_iptr(dir, bindex);
27325 + br = au_sbr(sb, bindex);
27327 + if ((br->br_perm & AuBrAttr_ICEX)
27328 + && !h_dir->i_op->listxattr)
27329 + br->br_perm &= ~AuBrAttr_ICEX;
27331 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27332 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27333 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27337 + wbr = br->br_wbr;
27339 + wbr_wh_read_lock(wbr);
27341 + if (!au_br_writable(br->br_perm)) {
27344 + || (!wbr->wbr_whbase
27345 + && !wbr->wbr_plink
27346 + && !wbr->wbr_orph));
27347 + } else if (!au_br_wh_linkable(br->br_perm)) {
27348 + /* skip = (!br->br_whbase && !br->br_orph); */
27349 + skip = (!wbr || !wbr->wbr_whbase);
27350 + if (skip && wbr) {
27352 + skip = !!wbr->wbr_plink;
27354 + skip = !wbr->wbr_plink;
27357 + /* skip = (br->br_whbase && br->br_ohph); */
27358 + skip = (wbr && wbr->wbr_whbase);
27361 + skip = !!wbr->wbr_plink;
27363 + skip = !wbr->wbr_plink;
27367 + wbr_wh_read_unlock(wbr);
27369 + if (can_no_dreval) {
27370 + dentry = br->br_path.dentry;
27371 + spin_lock(&dentry->d_lock);
27372 + if (dentry->d_flags &
27373 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27374 + can_no_dreval = 0;
27375 + spin_unlock(&dentry->d_lock);
27378 + if (au_br_fhsm(br->br_perm)) {
27380 + AuDebugOn(!br->br_fhsm);
27386 + hdir = au_hi(dir, bindex);
27387 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27389 + wbr_wh_write_lock(wbr);
27390 + err = au_wh_init(br, sb);
27392 + wbr_wh_write_unlock(wbr);
27393 + au_hn_inode_unlock(hdir);
27395 + if (!err && do_free) {
27396 + au_kfree_rcu(wbr);
27397 + br->br_wbr = NULL;
27401 + if (can_no_dreval)
27402 + au_fset_si(sbinfo, NO_DREVAL);
27404 + au_fclr_si(sbinfo, NO_DREVAL);
27407 + au_fset_si(sbinfo, FHSM);
27408 + for (bindex = bbot; bindex >= 0; bindex--) {
27409 + br = au_sbr(sb, bindex);
27410 + if (au_br_fhsm(br->br_perm)) {
27411 + au_fhsm_set_bottom(sb, bindex);
27416 + au_fclr_si(sbinfo, FHSM);
27417 + au_fhsm_set_bottom(sb, -1);
27423 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27426 + unsigned int tmp;
27427 + aufs_bindex_t bindex, bbot;
27428 + struct au_opt *opt;
27429 + struct au_opt_xino *opt_xino, xino;
27430 + struct au_sbinfo *sbinfo;
27431 + struct au_branch *br;
27432 + struct inode *dir;
27434 + SiMustWriteLock(sb);
27439 + while (err >= 0 && opt->type != Opt_tail)
27440 + err = au_opt_simple(sb, opt++, opts);
27443 + else if (unlikely(err < 0))
27446 + /* disable xino and udba temporary */
27447 + sbinfo = au_sbi(sb);
27448 + tmp = sbinfo->si_mntflags;
27449 + au_opt_clr(sbinfo->si_mntflags, XINO);
27450 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27453 + while (err >= 0 && opt->type != Opt_tail)
27454 + err = au_opt_br(sb, opt++, opts);
27457 + else if (unlikely(err < 0))
27460 + bbot = au_sbbot(sb);
27461 + if (unlikely(bbot < 0)) {
27463 + pr_err("no branches\n");
27467 + if (au_opt_test(tmp, XINO))
27468 + au_opt_set(sbinfo->si_mntflags, XINO);
27470 + while (!err && opt->type != Opt_tail)
27471 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27472 + if (unlikely(err))
27475 + err = au_opts_verify(sb, sb->s_flags, tmp);
27476 + if (unlikely(err))
27479 + /* restore xino */
27480 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27481 + xino.file = au_xino_def(sb);
27482 + err = PTR_ERR(xino.file);
27483 + if (IS_ERR(xino.file))
27486 + err = au_xino_set(sb, &xino, /*remount*/0);
27488 + if (unlikely(err))
27492 + /* restore udba */
27493 + tmp &= AuOptMask_UDBA;
27494 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27495 + sbinfo->si_mntflags |= tmp;
27496 + bbot = au_sbbot(sb);
27497 + for (bindex = 0; bindex <= bbot; bindex++) {
27498 + br = au_sbr(sb, bindex);
27499 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27500 + if (unlikely(err))
27501 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27503 + /* go on even if err */
27505 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27506 + dir = d_inode(sb->s_root);
27507 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27514 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27517 + unsigned char no_dreval;
27518 + struct inode *dir;
27519 + struct au_opt_xino *opt_xino;
27520 + struct au_opt *opt;
27521 + struct au_sbinfo *sbinfo;
27523 + SiMustWriteLock(sb);
27525 + err = au_dr_opt_flush(sb);
27526 + if (unlikely(err))
27528 + au_fset_opts(opts->flags, DR_FLUSHED);
27530 + dir = d_inode(sb->s_root);
27531 + sbinfo = au_sbi(sb);
27534 + while (err >= 0 && opt->type != Opt_tail) {
27535 + err = au_opt_simple(sb, opt, opts);
27537 + err = au_opt_br(sb, opt, opts);
27539 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27545 + /* go on even err */
27547 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27548 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27549 + if (unlikely(rerr && !err))
27552 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27553 + au_fset_opts(opts->flags, REFRESH_IDOP);
27555 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27556 + rerr = au_xib_trunc(sb);
27557 + if (unlikely(rerr && !err))
27561 + /* will be handled by the caller */
27562 + if (!au_ftest_opts(opts->flags, REFRESH)
27563 + && (opts->given_udba
27564 + || au_opt_test(sbinfo->si_mntflags, XINO)
27565 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27567 + au_fset_opts(opts->flags, REFRESH);
27569 + AuDbg("status 0x%x\n", opts->flags);
27575 +/* ---------------------------------------------------------------------- */
27577 +unsigned int au_opt_udba(struct super_block *sb)
27579 + return au_mntflags(sb) & AuOptMask_UDBA;
27581 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27582 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27583 +++ linux/fs/aufs/opts.h 2019-07-11 15:42:14.472238057 +0200
27585 +/* SPDX-License-Identifier: GPL-2.0 */
27587 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27589 + * This program, aufs is free software; you can redistribute it and/or modify
27590 + * it under the terms of the GNU General Public License as published by
27591 + * the Free Software Foundation; either version 2 of the License, or
27592 + * (at your option) any later version.
27594 + * This program is distributed in the hope that it will be useful,
27595 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27596 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27597 + * GNU General Public License for more details.
27599 + * You should have received a copy of the GNU General Public License
27600 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27604 + * mount options/flags
27607 +#ifndef __AUFS_OPTS_H__
27608 +#define __AUFS_OPTS_H__
27612 +#include <linux/path.h>
27616 +/* ---------------------------------------------------------------------- */
27619 +#define AuOpt_XINO 1 /* external inode number bitmap
27620 + and translation table */
27621 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27622 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27623 +#define AuOpt_UDBA_REVAL (1 << 3)
27624 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27625 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27626 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27627 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27629 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27630 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27631 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27632 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27633 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27634 +#define AuOpt_DIO (1 << 14) /* direct io */
27635 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27637 +#ifndef CONFIG_AUFS_HNOTIFY
27638 +#undef AuOpt_UDBA_HNOTIFY
27639 +#define AuOpt_UDBA_HNOTIFY 0
27641 +#ifndef CONFIG_AUFS_DIRREN
27642 +#undef AuOpt_DIRREN
27643 +#define AuOpt_DIRREN 0
27645 +#ifndef CONFIG_AUFS_SHWH
27647 +#define AuOpt_SHWH 0
27650 +#define AuOpt_Def (AuOpt_XINO \
27651 + | AuOpt_UDBA_REVAL \
27653 + /* | AuOpt_DIRPERM1 */ \
27654 + | AuOpt_WARN_PERM)
27655 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27656 + | AuOpt_UDBA_REVAL \
27657 + | AuOpt_UDBA_HNOTIFY)
27659 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27660 +#define au_opt_set(flags, name) do { \
27661 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27662 + ((flags) |= AuOpt_##name); \
27664 +#define au_opt_set_udba(flags, name) do { \
27665 + (flags) &= ~AuOptMask_UDBA; \
27666 + ((flags) |= AuOpt_##name); \
27668 +#define au_opt_clr(flags, name) do { \
27669 + ((flags) &= ~AuOpt_##name); \
27672 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27674 +#ifdef CONFIG_PROC_FS
27677 + return mntflags & ~AuOpt_PLINK;
27681 +/* ---------------------------------------------------------------------- */
27683 +/* policies to select one among multiple writable branches */
27685 + AuWbrCreate_TDP, /* top down parent */
27686 + AuWbrCreate_RR, /* round robin */
27687 + AuWbrCreate_MFS, /* most free space */
27688 + AuWbrCreate_MFSV, /* mfs with seconds */
27689 + AuWbrCreate_MFSRR, /* mfs then rr */
27690 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27691 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27692 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27693 + AuWbrCreate_PMFS, /* parent and mfs */
27694 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27695 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27696 + AuWbrCreate_PMFSRRV, /* plus seconds */
27698 + AuWbrCreate_Def = AuWbrCreate_TDP
27702 + AuWbrCopyup_TDP, /* top down parent */
27703 + AuWbrCopyup_BUP, /* bottom up parent */
27704 + AuWbrCopyup_BU, /* bottom up */
27706 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27709 +/* ---------------------------------------------------------------------- */
27711 +struct au_opt_add {
27712 + aufs_bindex_t bindex;
27715 + struct path path;
27718 +struct au_opt_del {
27720 + struct path h_path;
27723 +struct au_opt_mod {
27726 + struct dentry *h_root;
27729 +struct au_opt_xino {
27731 + struct file *file;
27734 +struct au_opt_xino_itrunc {
27735 + aufs_bindex_t bindex;
27738 +struct au_opt_wbr_create {
27741 + unsigned long long mfsrr_watermark;
27747 + struct au_opt_xino xino;
27748 + struct au_opt_xino_itrunc xino_itrunc;
27749 + struct au_opt_add add;
27750 + struct au_opt_del del;
27751 + struct au_opt_mod mod;
27754 + unsigned int rdblk;
27755 + unsigned int rdhash;
27757 + struct au_opt_wbr_create wbr_create;
27759 + unsigned int fhsm_second;
27764 +#define AuOpts_REMOUNT 1
27765 +#define AuOpts_REFRESH (1 << 1)
27766 +#define AuOpts_TRUNC_XIB (1 << 2)
27767 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27768 +#define AuOpts_REFRESH_IDOP (1 << 4)
27769 +#define AuOpts_DR_FLUSHED (1 << 5)
27770 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27771 +#define au_fset_opts(flags, name) \
27772 + do { (flags) |= AuOpts_##name; } while (0)
27773 +#define au_fclr_opts(flags, name) \
27774 + do { (flags) &= ~AuOpts_##name; } while (0)
27776 +#ifndef CONFIG_AUFS_DIRREN
27777 +#undef AuOpts_DR_FLUSHED
27778 +#define AuOpts_DR_FLUSHED 0
27782 + struct au_opt *opt;
27785 + unsigned int given_udba;
27786 + unsigned int flags;
27787 + unsigned long sb_flags;
27790 +/* ---------------------------------------------------------------------- */
27793 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27794 +const char *au_optstr_udba(int udba);
27795 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27796 +const char *au_optstr_wbr_create(int wbr_create);
27798 +void au_opts_free(struct au_opts *opts);
27799 +struct super_block;
27800 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27801 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27802 + unsigned int pending);
27803 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27804 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27806 +unsigned int au_opt_udba(struct super_block *sb);
27808 +#endif /* __KERNEL__ */
27809 +#endif /* __AUFS_OPTS_H__ */
27810 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27811 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27812 +++ linux/fs/aufs/plink.c 2019-07-11 15:42:14.472238057 +0200
27814 +// SPDX-License-Identifier: GPL-2.0
27816 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27818 + * This program, aufs is free software; you can redistribute it and/or modify
27819 + * it under the terms of the GNU General Public License as published by
27820 + * the Free Software Foundation; either version 2 of the License, or
27821 + * (at your option) any later version.
27823 + * This program is distributed in the hope that it will be useful,
27824 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27825 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27826 + * GNU General Public License for more details.
27828 + * You should have received a copy of the GNU General Public License
27829 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27839 + * the pseudo-link maintenance mode.
27840 + * during a user process maintains the pseudo-links,
27841 + * prohibit adding a new plink and branch manipulation.
27845 + * For entry functions which will handle plink, and i_mutex is already held
27847 + * They cannot wait and should return an error at once.
27848 + * Callers has to check the error.
27850 + * For entry functions which will handle plink, but i_mutex is not held
27852 + * They can wait the plink maintenance mode to finish.
27854 + * They behave like F_SETLK and F_SETLKW.
27855 + * If the caller never handle plink, then both flags are unnecessary.
27858 +int au_plink_maint(struct super_block *sb, int flags)
27862 + struct task_struct *parent, *prev;
27863 + struct au_sbinfo *sbi;
27865 + SiMustAnyLock(sb);
27868 + if (!au_opt_test(au_mntflags(sb), PLINK))
27871 + sbi = au_sbi(sb);
27872 + pid = sbi->si_plink_maint_pid;
27873 + if (!pid || pid == current->pid)
27876 + /* todo: it highly depends upon /sbin/mount.aufs */
27878 + parent = current;
27882 + parent = rcu_dereference(parent->real_parent);
27883 + if (parent == prev)
27885 + ppid = task_pid_vnr(parent);
27886 + if (pid == ppid) {
27887 + rcu_read_unlock();
27892 + rcu_read_unlock();
27894 + if (au_ftest_lock(flags, NOPLMW)) {
27895 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27896 + /* AuDebugOn(!lockdep_depth(current)); */
27897 + while (sbi->si_plink_maint_pid) {
27898 + si_read_unlock(sb);
27899 + /* gave up wake_up_bit() */
27900 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27902 + if (au_ftest_lock(flags, FLUSH))
27903 + au_nwt_flush(&sbi->si_nowait);
27904 + si_noflush_read_lock(sb);
27906 + } else if (au_ftest_lock(flags, NOPLM)) {
27907 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27915 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27917 + spin_lock(&sbinfo->si_plink_maint_lock);
27918 + sbinfo->si_plink_maint_pid = 0;
27919 + spin_unlock(&sbinfo->si_plink_maint_lock);
27920 + wake_up_all(&sbinfo->si_plink_wq);
27923 +int au_plink_maint_enter(struct super_block *sb)
27926 + struct au_sbinfo *sbinfo;
27929 + sbinfo = au_sbi(sb);
27930 + /* make sure i am the only one in this fs */
27931 + si_write_lock(sb, AuLock_FLUSH);
27932 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27933 + spin_lock(&sbinfo->si_plink_maint_lock);
27934 + if (!sbinfo->si_plink_maint_pid)
27935 + sbinfo->si_plink_maint_pid = current->pid;
27938 + spin_unlock(&sbinfo->si_plink_maint_lock);
27940 + si_write_unlock(sb);
27945 +/* ---------------------------------------------------------------------- */
27947 +#ifdef CONFIG_AUFS_DEBUG
27948 +void au_plink_list(struct super_block *sb)
27951 + struct au_sbinfo *sbinfo;
27952 + struct hlist_bl_head *hbl;
27953 + struct hlist_bl_node *pos;
27954 + struct au_icntnr *icntnr;
27956 + SiMustAnyLock(sb);
27958 + sbinfo = au_sbi(sb);
27959 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27960 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27962 + for (i = 0; i < AuPlink_NHASH; i++) {
27963 + hbl = sbinfo->si_plink + i;
27964 + hlist_bl_lock(hbl);
27965 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27966 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27967 + hlist_bl_unlock(hbl);
27972 +/* is the inode pseudo-linked? */
27973 +int au_plink_test(struct inode *inode)
27976 + struct au_sbinfo *sbinfo;
27977 + struct hlist_bl_head *hbl;
27978 + struct hlist_bl_node *pos;
27979 + struct au_icntnr *icntnr;
27981 + sbinfo = au_sbi(inode->i_sb);
27982 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27983 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27984 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27987 + i = au_plink_hash(inode->i_ino);
27988 + hbl = sbinfo->si_plink + i;
27989 + hlist_bl_lock(hbl);
27990 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27991 + if (&icntnr->vfs_inode == inode) {
27995 + hlist_bl_unlock(hbl);
27999 +/* ---------------------------------------------------------------------- */
28002 + * generate a name for plink.
28003 + * the file will be stored under AUFS_WH_PLINKDIR.
28005 +/* 20 is max digits length of ulong 64 */
28006 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28008 +static int plink_name(char *name, int len, struct inode *inode,
28009 + aufs_bindex_t bindex)
28012 + struct inode *h_inode;
28014 + h_inode = au_h_iptr(inode, bindex);
28015 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28019 +struct au_do_plink_lkup_args {
28020 + struct dentry **errp;
28021 + struct qstr *tgtname;
28022 + struct dentry *h_parent;
28023 + struct au_branch *br;
28026 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28027 + struct dentry *h_parent,
28028 + struct au_branch *br)
28030 + struct dentry *h_dentry;
28031 + struct inode *h_inode;
28033 + h_inode = d_inode(h_parent);
28034 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28035 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28036 + inode_unlock_shared(h_inode);
28040 +static void au_call_do_plink_lkup(void *args)
28042 + struct au_do_plink_lkup_args *a = args;
28043 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28046 +/* lookup the plink-ed @inode under the branch at @bindex */
28047 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28049 + struct dentry *h_dentry, *h_parent;
28050 + struct au_branch *br;
28052 + char a[PLINK_NAME_LEN];
28053 + struct qstr tgtname = QSTR_INIT(a, 0);
28055 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28057 + br = au_sbr(inode->i_sb, bindex);
28058 + h_parent = br->br_wbr->wbr_plink;
28059 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28061 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28062 + struct au_do_plink_lkup_args args = {
28063 + .errp = &h_dentry,
28064 + .tgtname = &tgtname,
28065 + .h_parent = h_parent,
28069 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28070 + if (unlikely(wkq_err))
28071 + h_dentry = ERR_PTR(wkq_err);
28073 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28078 +/* create a pseudo-link */
28079 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28080 + struct dentry *h_dentry, struct au_branch *br)
28083 + struct path h_path = {
28084 + .mnt = au_br_mnt(br)
28086 + struct inode *h_dir, *delegated;
28088 + h_dir = d_inode(h_parent);
28089 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28091 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28092 + err = PTR_ERR(h_path.dentry);
28093 + if (IS_ERR(h_path.dentry))
28097 + /* wh.plink dir is not monitored */
28098 + /* todo: is it really safe? */
28099 + if (d_is_positive(h_path.dentry)
28100 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28101 + delegated = NULL;
28102 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28103 + if (unlikely(err == -EWOULDBLOCK)) {
28104 + pr_warn("cannot retry for NFSv4 delegation"
28105 + " for an internal unlink\n");
28108 + dput(h_path.dentry);
28109 + h_path.dentry = NULL;
28113 + if (!err && d_is_negative(h_path.dentry)) {
28114 + delegated = NULL;
28115 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28116 + if (unlikely(err == -EWOULDBLOCK)) {
28117 + pr_warn("cannot retry for NFSv4 delegation"
28118 + " for an internal link\n");
28122 + dput(h_path.dentry);
28125 + inode_unlock(h_dir);
28129 +struct do_whplink_args {
28131 + struct qstr *tgt;
28132 + struct dentry *h_parent;
28133 + struct dentry *h_dentry;
28134 + struct au_branch *br;
28137 +static void call_do_whplink(void *args)
28139 + struct do_whplink_args *a = args;
28140 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28143 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28144 + aufs_bindex_t bindex, struct au_branch *br)
28146 + int err, wkq_err;
28147 + struct au_wbr *wbr;
28148 + struct dentry *h_parent;
28149 + char a[PLINK_NAME_LEN];
28150 + struct qstr tgtname = QSTR_INIT(a, 0);
28152 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28153 + h_parent = wbr->wbr_plink;
28154 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28156 + /* always superio. */
28157 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28158 + struct do_whplink_args args = {
28161 + .h_parent = h_parent,
28162 + .h_dentry = h_dentry,
28165 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28166 + if (unlikely(wkq_err))
28169 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28175 + * create a new pseudo-link for @h_dentry on @bindex.
28176 + * the linked inode is held in aufs @inode.
28178 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28179 + struct dentry *h_dentry)
28181 + struct super_block *sb;
28182 + struct au_sbinfo *sbinfo;
28183 + struct hlist_bl_head *hbl;
28184 + struct hlist_bl_node *pos;
28185 + struct au_icntnr *icntnr;
28186 + int found, err, cnt, i;
28188 + sb = inode->i_sb;
28189 + sbinfo = au_sbi(sb);
28190 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28191 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28193 + found = au_plink_test(inode);
28197 + i = au_plink_hash(inode->i_ino);
28198 + hbl = sbinfo->si_plink + i;
28201 + hlist_bl_lock(hbl);
28202 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28203 + if (&icntnr->vfs_inode == inode) {
28209 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28210 + hlist_bl_add_head(&icntnr->plink, hbl);
28212 + hlist_bl_unlock(hbl);
28214 + cnt = au_hbl_count(hbl);
28215 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28216 + if (cnt > AUFS_PLINK_WARN)
28217 + AuWarn1(msg ", %d\n", cnt);
28219 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28220 + if (unlikely(err)) {
28221 + pr_warn("err %d, damaged pseudo link.\n", err);
28222 + au_hbl_del(&icntnr->plink, hbl);
28223 + iput(&icntnr->vfs_inode);
28226 + iput(&icntnr->vfs_inode);
28229 +/* free all plinks */
28230 +void au_plink_put(struct super_block *sb, int verbose)
28233 + struct au_sbinfo *sbinfo;
28234 + struct hlist_bl_head *hbl;
28235 + struct hlist_bl_node *pos, *tmp;
28236 + struct au_icntnr *icntnr;
28238 + SiMustWriteLock(sb);
28240 + sbinfo = au_sbi(sb);
28241 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28242 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28244 + /* no spin_lock since sbinfo is write-locked */
28246 + for (i = 0; i < AuPlink_NHASH; i++) {
28247 + hbl = sbinfo->si_plink + i;
28248 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28249 + pr_warn("pseudo-link is not flushed");
28252 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28253 + iput(&icntnr->vfs_inode);
28254 + INIT_HLIST_BL_HEAD(hbl);
28258 +void au_plink_clean(struct super_block *sb, int verbose)
28260 + struct dentry *root;
28262 + root = sb->s_root;
28263 + aufs_write_lock(root);
28264 + if (au_opt_test(au_mntflags(sb), PLINK))
28265 + au_plink_put(sb, verbose);
28266 + aufs_write_unlock(root);
28269 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28272 + aufs_bindex_t btop, bbot, bindex;
28275 + btop = au_ibtop(inode);
28276 + bbot = au_ibbot(inode);
28278 + for (bindex = btop; bindex <= bbot; bindex++) {
28279 + if (!au_h_iptr(inode, bindex)
28280 + || au_ii_br_id(inode, bindex) != br_id)
28282 + au_set_h_iptr(inode, bindex, NULL, 0);
28287 + for (bindex = btop; bindex <= bbot; bindex++)
28288 + if (au_h_iptr(inode, bindex)) {
28298 +/* free the plinks on a branch specified by @br_id */
28299 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28301 + struct au_sbinfo *sbinfo;
28302 + struct hlist_bl_head *hbl;
28303 + struct hlist_bl_node *pos, *tmp;
28304 + struct au_icntnr *icntnr;
28305 + struct inode *inode;
28308 + SiMustWriteLock(sb);
28310 + sbinfo = au_sbi(sb);
28311 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28312 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28314 + /* no bit_lock since sbinfo is write-locked */
28315 + for (i = 0; i < AuPlink_NHASH; i++) {
28316 + hbl = sbinfo->si_plink + i;
28317 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28318 + inode = au_igrab(&icntnr->vfs_inode);
28319 + ii_write_lock_child(inode);
28320 + do_put = au_plink_do_half_refresh(inode, br_id);
28322 + hlist_bl_del(&icntnr->plink);
28325 + ii_write_unlock(inode);
28330 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28331 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28332 +++ linux/fs/aufs/poll.c 2019-07-11 15:42:14.472238057 +0200
28334 +// SPDX-License-Identifier: GPL-2.0
28336 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28338 + * This program, aufs is free software; you can redistribute it and/or modify
28339 + * it under the terms of the GNU General Public License as published by
28340 + * the Free Software Foundation; either version 2 of the License, or
28341 + * (at your option) any later version.
28343 + * This program is distributed in the hope that it will be useful,
28344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28346 + * GNU General Public License for more details.
28348 + * You should have received a copy of the GNU General Public License
28349 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28354 + * There is only one filesystem which implements ->poll operation, currently.
28359 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28362 + struct file *h_file;
28363 + struct super_block *sb;
28365 + /* We should pretend an error happened. */
28366 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28367 + sb = file->f_path.dentry->d_sb;
28368 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28370 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28371 + if (IS_ERR(h_file)) {
28372 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28376 + mask = vfs_poll(h_file, pt);
28377 + fput(h_file); /* instead of au_read_post() */
28380 + si_read_unlock(sb);
28381 + if (mask & EPOLLERR)
28382 + AuDbg("mask 0x%x\n", mask);
28385 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28386 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28387 +++ linux/fs/aufs/posix_acl.c 2019-11-25 12:42:00.275843147 +0100
28389 +// SPDX-License-Identifier: GPL-2.0
28391 + * Copyright (C) 2014-2019 Junjiro R. Okajima
28393 + * This program, aufs is free software; you can redistribute it and/or modify
28394 + * it under the terms of the GNU General Public License as published by
28395 + * the Free Software Foundation; either version 2 of the License, or
28396 + * (at your option) any later version.
28398 + * This program is distributed in the hope that it will be useful,
28399 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28400 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28401 + * GNU General Public License for more details.
28403 + * You should have received a copy of the GNU General Public License
28404 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28408 + * posix acl operations
28411 +#include <linux/fs.h>
28414 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28416 + struct posix_acl *acl;
28418 + aufs_bindex_t bindex;
28419 + struct inode *h_inode;
28420 + struct super_block *sb;
28423 + sb = inode->i_sb;
28424 + si_read_lock(sb, AuLock_FLUSH);
28425 + ii_read_lock_child(inode);
28426 + if (!(sb->s_flags & SB_POSIXACL))
28429 + bindex = au_ibtop(inode);
28430 + h_inode = au_h_iptr(inode, bindex);
28431 + if (unlikely(!h_inode
28432 + || ((h_inode->i_mode & S_IFMT)
28433 + != (inode->i_mode & S_IFMT)))) {
28434 + err = au_busy_or_stale();
28435 + acl = ERR_PTR(err);
28439 + /* always topmost only */
28440 + acl = get_acl(h_inode, type);
28442 + forget_cached_acl(inode, type);
28444 + set_cached_acl(inode, type, acl);
28447 + ii_read_unlock(inode);
28448 + si_read_unlock(sb);
28450 + AuTraceErrPtr(acl);
28454 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28458 + struct dentry *dentry;
28459 + struct au_sxattr arg = {
28460 + .type = AU_ACL_SET,
28467 + IMustLock(inode);
28469 + if (inode->i_ino == AUFS_ROOT_INO)
28470 + dentry = dget(inode->i_sb->s_root);
28472 + dentry = d_find_alias(inode);
28474 + dentry = d_find_any_alias(inode);
28476 + pr_warn("cannot handle this inode, "
28477 + "please report to aufs-users ML\n");
28483 + ssz = au_sxattr(dentry, inode, &arg);
28484 + /* forget even it if succeeds since the branch might set differently */
28485 + forget_cached_acl(inode, type);
28494 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28495 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28496 +++ linux/fs/aufs/procfs.c 2019-07-11 15:42:14.472238057 +0200
28498 +// SPDX-License-Identifier: GPL-2.0
28500 + * Copyright (C) 2010-2019 Junjiro R. Okajima
28502 + * This program, aufs is free software; you can redistribute it and/or modify
28503 + * it under the terms of the GNU General Public License as published by
28504 + * the Free Software Foundation; either version 2 of the License, or
28505 + * (at your option) any later version.
28507 + * This program is distributed in the hope that it will be useful,
28508 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28509 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28510 + * GNU General Public License for more details.
28512 + * You should have received a copy of the GNU General Public License
28513 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28517 + * procfs interfaces
28520 +#include <linux/proc_fs.h>
28523 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28525 + struct au_sbinfo *sbinfo;
28527 + sbinfo = file->private_data;
28529 + au_plink_maint_leave(sbinfo);
28530 + kobject_put(&sbinfo->si_kobj);
28536 +static void au_procfs_plm_write_clean(struct file *file)
28538 + struct au_sbinfo *sbinfo;
28540 + sbinfo = file->private_data;
28542 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28545 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28548 + struct super_block *sb;
28549 + struct au_sbinfo *sbinfo;
28550 + struct hlist_bl_node *pos;
28553 + if (unlikely(file->private_data))
28557 + /* don't use au_sbilist_lock() here */
28558 + hlist_bl_lock(&au_sbilist);
28559 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28560 + if (id == sysaufs_si_id(sbinfo)) {
28561 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28562 + sb = sbinfo->si_sb;
28565 + hlist_bl_unlock(&au_sbilist);
28568 + if (unlikely(!sb))
28571 + err = au_plink_maint_enter(sb);
28573 + /* keep kobject_get() */
28574 + file->private_data = sbinfo;
28576 + kobject_put(&sbinfo->si_kobj);
28582 + * Accept a valid "si=xxxx" only.
28583 + * Once it is accepted successfully, accept "clean" too.
28585 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28586 + size_t count, loff_t *ppos)
28589 + unsigned long id;
28590 + /* last newline is allowed */
28591 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28594 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28598 + if (unlikely(count > sizeof(buf)))
28601 + err = copy_from_user(buf, ubuf, count);
28602 + if (unlikely(err)) {
28609 + if (!strcmp("clean", buf)) {
28610 + au_procfs_plm_write_clean(file);
28611 + goto out_success;
28612 + } else if (unlikely(strncmp("si=", buf, 3)))
28615 + err = kstrtoul(buf + 3, 16, &id);
28616 + if (unlikely(err))
28619 + err = au_procfs_plm_write_si(file, id);
28620 + if (unlikely(err))
28624 + err = count; /* success */
28629 +static const struct file_operations au_procfs_plm_fop = {
28630 + .write = au_procfs_plm_write,
28631 + .release = au_procfs_plm_release,
28632 + .owner = THIS_MODULE
28635 +/* ---------------------------------------------------------------------- */
28637 +static struct proc_dir_entry *au_procfs_dir;
28639 +void au_procfs_fin(void)
28641 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28642 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28645 +int __init au_procfs_init(void)
28648 + struct proc_dir_entry *entry;
28651 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28652 + if (unlikely(!au_procfs_dir))
28655 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28656 + au_procfs_dir, &au_procfs_plm_fop);
28657 + if (unlikely(!entry))
28661 + goto out; /* success */
28665 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28669 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28670 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28671 +++ linux/fs/aufs/rdu.c 2019-07-11 15:42:14.472238057 +0200
28673 +// SPDX-License-Identifier: GPL-2.0
28675 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28677 + * This program, aufs is free software; you can redistribute it and/or modify
28678 + * it under the terms of the GNU General Public License as published by
28679 + * the Free Software Foundation; either version 2 of the License, or
28680 + * (at your option) any later version.
28682 + * This program is distributed in the hope that it will be useful,
28683 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28684 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28685 + * GNU General Public License for more details.
28687 + * You should have received a copy of the GNU General Public License
28688 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28692 + * readdir in userspace.
28695 +#include <linux/compat.h>
28696 +#include <linux/fs_stack.h>
28697 +#include <linux/security.h>
28700 +/* bits for struct aufs_rdu.flags */
28701 +#define AuRdu_CALLED 1
28702 +#define AuRdu_CONT (1 << 1)
28703 +#define AuRdu_FULL (1 << 2)
28704 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28705 +#define au_fset_rdu(flags, name) \
28706 + do { (flags) |= AuRdu_##name; } while (0)
28707 +#define au_fclr_rdu(flags, name) \
28708 + do { (flags) &= ~AuRdu_##name; } while (0)
28710 +struct au_rdu_arg {
28711 + struct dir_context ctx;
28712 + struct aufs_rdu *rdu;
28713 + union au_rdu_ent_ul ent;
28714 + unsigned long end;
28716 + struct super_block *sb;
28720 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28721 + loff_t offset, u64 h_ino, unsigned int d_type)
28724 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28725 + struct aufs_rdu *rdu = arg->rdu;
28726 + struct au_rdu_ent ent;
28730 + au_fset_rdu(rdu->cookie.flags, CALLED);
28731 + len = au_rdu_len(nlen);
28732 + if (arg->ent.ul + len < arg->end) {
28734 + ent.bindex = rdu->cookie.bindex;
28735 + ent.type = d_type;
28737 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28738 + ent.type = DT_UNKNOWN;
28740 + /* unnecessary to support mmap_sem since this is a dir */
28742 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28744 + if (copy_to_user(arg->ent.e->name, name, nlen))
28746 + /* the terminating NULL */
28747 + if (__put_user(0, arg->ent.e->name + nlen))
28750 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28751 + arg->ent.ul += len;
28755 + au_fset_rdu(rdu->cookie.flags, FULL);
28757 + rdu->tail = arg->ent;
28761 + /* AuTraceErr(err); */
28765 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28769 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28771 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28772 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28774 + if (unlikely(offset != cookie->h_pos))
28780 + au_fclr_rdu(cookie->flags, CALLED);
28782 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28786 + && au_ftest_rdu(cookie->flags, CALLED)
28787 + && !au_ftest_rdu(cookie->flags, FULL));
28788 + cookie->h_pos = h_file->f_pos;
28795 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28798 + aufs_bindex_t bbot;
28799 + struct au_rdu_arg arg = {
28801 + .actor = au_rdu_fill
28804 + struct dentry *dentry;
28805 + struct inode *inode;
28806 + struct file *h_file;
28807 + struct au_rdu_cookie *cookie = &rdu->cookie;
28809 + /* VERIFY_WRITE */
28810 + err = !access_ok(rdu->ent.e, rdu->sz);
28811 + if (unlikely(err)) {
28817 + rdu->tail = rdu->ent;
28820 + arg.ent = rdu->ent;
28821 + arg.end = arg.ent.ul;
28822 + arg.end += rdu->sz;
28825 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28828 + err = security_file_permission(file, MAY_READ);
28830 + if (unlikely(err))
28833 + dentry = file->f_path.dentry;
28834 + inode = d_inode(dentry);
28835 + inode_lock_shared(inode);
28837 + arg.sb = inode->i_sb;
28838 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28839 + if (unlikely(err))
28841 + err = au_alive_dir(dentry);
28842 + if (unlikely(err))
28844 + /* todo: reval? */
28845 + fi_read_lock(file);
28848 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28849 + && cookie->generation != au_figen(file)))
28854 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28856 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28858 + bbot = au_fbtop(file);
28859 + if (cookie->bindex < bbot)
28860 + cookie->bindex = bbot;
28861 + bbot = au_fbbot_dir(file);
28862 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28863 + for (; !err && cookie->bindex <= bbot;
28864 + cookie->bindex++, cookie->h_pos = 0) {
28865 + h_file = au_hf_dir(file, cookie->bindex);
28869 + au_fclr_rdu(cookie->flags, FULL);
28870 + err = au_rdu_do(h_file, &arg);
28872 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28875 + AuDbg("rent %llu\n", rdu->rent);
28877 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28878 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28879 + au_fset_rdu(cookie->flags, CONT);
28880 + cookie->generation = au_figen(file);
28883 + ii_read_lock_child(inode);
28884 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28885 + ii_read_unlock(inode);
28888 + fi_read_unlock(file);
28890 + si_read_unlock(arg.sb);
28892 + inode_unlock_shared(inode);
28898 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28902 + unsigned long long nent;
28903 + union au_rdu_ent_ul *u;
28904 + struct au_rdu_ent ent;
28905 + struct super_block *sb;
28908 + nent = rdu->nent;
28910 + sb = file->f_path.dentry->d_sb;
28911 + si_read_lock(sb, AuLock_FLUSH);
28912 + while (nent-- > 0) {
28913 + /* unnecessary to support mmap_sem since this is a dir */
28914 + err = copy_from_user(&ent, u->e, sizeof(ent));
28916 + /* VERIFY_WRITE */
28917 + err = !access_ok(&u->e->ino, sizeof(ino));
28918 + if (unlikely(err)) {
28924 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28926 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28928 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28930 + if (unlikely(err)) {
28935 + err = __put_user(ino, &u->e->ino);
28936 + if (unlikely(err)) {
28941 + u->ul += au_rdu_len(ent.nlen);
28943 + si_read_unlock(sb);
28948 +/* ---------------------------------------------------------------------- */
28950 +static int au_rdu_verify(struct aufs_rdu *rdu)
28952 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28953 + "%llu, b%d, 0x%x, g%u}\n",
28954 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28956 + rdu->rent, rdu->shwh, rdu->full,
28957 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28958 + rdu->cookie.generation);
28960 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28964 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28968 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28971 + struct aufs_rdu rdu;
28972 + void __user *p = (void __user *)arg;
28974 + err = copy_from_user(&rdu, p, sizeof(rdu));
28975 + if (unlikely(err)) {
28980 + err = au_rdu_verify(&rdu);
28981 + if (unlikely(err))
28985 + case AUFS_CTL_RDU:
28986 + err = au_rdu(file, &rdu);
28987 + if (unlikely(err))
28990 + e = copy_to_user(p, &rdu, sizeof(rdu));
28991 + if (unlikely(e)) {
28996 + case AUFS_CTL_RDU_INO:
28997 + err = au_rdu_ino(file, &rdu);
29001 + /* err = -ENOTTY; */
29010 +#ifdef CONFIG_COMPAT
29011 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29014 + struct aufs_rdu rdu;
29015 + void __user *p = compat_ptr(arg);
29017 + /* todo: get_user()? */
29018 + err = copy_from_user(&rdu, p, sizeof(rdu));
29019 + if (unlikely(err)) {
29024 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29025 + err = au_rdu_verify(&rdu);
29026 + if (unlikely(err))
29030 + case AUFS_CTL_RDU:
29031 + err = au_rdu(file, &rdu);
29032 + if (unlikely(err))
29035 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29036 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29037 + e = copy_to_user(p, &rdu, sizeof(rdu));
29038 + if (unlikely(e)) {
29043 + case AUFS_CTL_RDU_INO:
29044 + err = au_rdu_ino(file, &rdu);
29048 + /* err = -ENOTTY; */
29057 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29058 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29059 +++ linux/fs/aufs/rwsem.h 2019-07-11 15:42:14.472238057 +0200
29061 +/* SPDX-License-Identifier: GPL-2.0 */
29063 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29065 + * This program, aufs is free software; you can redistribute it and/or modify
29066 + * it under the terms of the GNU General Public License as published by
29067 + * the Free Software Foundation; either version 2 of the License, or
29068 + * (at your option) any later version.
29070 + * This program is distributed in the hope that it will be useful,
29071 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29072 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29073 + * GNU General Public License for more details.
29075 + * You should have received a copy of the GNU General Public License
29076 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29080 + * simple read-write semaphore wrappers
29083 +#ifndef __AUFS_RWSEM_H__
29084 +#define __AUFS_RWSEM_H__
29088 +#include "debug.h"
29090 +/* in the future, the name 'au_rwsem' will be totally gone */
29091 +#define au_rwsem rw_semaphore
29093 +/* to debug easier, do not make them inlined functions */
29094 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29095 +/* rwsem_is_locked() is unusable */
29096 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29098 + && !lockdep_is_held_type(rw, 1))
29099 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29101 + && !lockdep_is_held_type(rw, 0))
29102 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29104 + && !lockdep_is_held(rw))
29105 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29107 + && lockdep_is_held(rw))
29109 +#define au_rw_init(rw) init_rwsem(rw)
29111 +#define au_rw_init_wlock(rw) do { \
29112 + au_rw_init(rw); \
29113 + down_write(rw); \
29116 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29117 + au_rw_init(rw); \
29118 + down_write_nested(rw, lsc); \
29121 +#define au_rw_read_lock(rw) down_read(rw)
29122 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29123 +#define au_rw_read_unlock(rw) up_read(rw)
29124 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29125 +#define au_rw_write_lock(rw) down_write(rw)
29126 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29127 +#define au_rw_write_unlock(rw) up_write(rw)
29128 +/* why is not _nested version defined? */
29129 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29130 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29132 +#endif /* __KERNEL__ */
29133 +#endif /* __AUFS_RWSEM_H__ */
29134 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29135 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29136 +++ linux/fs/aufs/sbinfo.c 2019-07-11 15:42:14.472238057 +0200
29138 +// SPDX-License-Identifier: GPL-2.0
29140 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29142 + * This program, aufs is free software; you can redistribute it and/or modify
29143 + * it under the terms of the GNU General Public License as published by
29144 + * the Free Software Foundation; either version 2 of the License, or
29145 + * (at your option) any later version.
29147 + * This program is distributed in the hope that it will be useful,
29148 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29149 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29150 + * GNU General Public License for more details.
29152 + * You should have received a copy of the GNU General Public License
29153 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29157 + * superblock private data
29160 +#include <linux/iversion.h>
29164 + * they are necessary regardless sysfs is disabled.
29166 +void au_si_free(struct kobject *kobj)
29169 + struct au_sbinfo *sbinfo;
29170 + char *locked __maybe_unused; /* debug only */
29172 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29173 + for (i = 0; i < AuPlink_NHASH; i++)
29174 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29175 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29177 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29178 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29179 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29180 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29182 + dbgaufs_si_fin(sbinfo);
29183 + au_rw_write_lock(&sbinfo->si_rwsem);
29184 + au_br_free(sbinfo);
29185 + au_rw_write_unlock(&sbinfo->si_rwsem);
29187 + au_kfree_try_rcu(sbinfo->si_branch);
29188 + mutex_destroy(&sbinfo->si_xib_mtx);
29189 + AuRwDestroy(&sbinfo->si_rwsem);
29191 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29192 + /* si_nfiles is waited too */
29193 + au_kfree_rcu(sbinfo);
29196 +int au_si_alloc(struct super_block *sb)
29199 + struct au_sbinfo *sbinfo;
29202 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29203 + if (unlikely(!sbinfo))
29206 + /* will be reallocated separately */
29207 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29208 + if (unlikely(!sbinfo->si_branch))
29211 + err = sysaufs_si_init(sbinfo);
29213 + dbgaufs_si_null(sbinfo);
29214 + err = dbgaufs_si_init(sbinfo);
29215 + if (unlikely(err))
29216 + kobject_put(&sbinfo->si_kobj);
29218 + if (unlikely(err))
29221 + au_nwt_init(&sbinfo->si_nowait);
29222 + au_rw_init_wlock(&sbinfo->si_rwsem);
29224 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29225 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29227 + sbinfo->si_bbot = -1;
29228 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29230 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29231 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29232 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29233 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29235 + au_fhsm_init(sbinfo);
29237 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29239 + sbinfo->si_xino_jiffy = jiffies;
29240 + sbinfo->si_xino_expire
29241 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29242 + mutex_init(&sbinfo->si_xib_mtx);
29243 + /* leave si_xib_last_pindex and si_xib_next_bit */
29245 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29247 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29248 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29249 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29250 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29252 + for (i = 0; i < AuPlink_NHASH; i++)
29253 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29254 + init_waitqueue_head(&sbinfo->si_plink_wq);
29255 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29257 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29259 + /* with getattr by default */
29260 + sbinfo->si_iop_array = aufs_iop;
29262 + /* leave other members for sysaufs and si_mnt. */
29263 + sbinfo->si_sb = sb;
29264 + sb->s_fs_info = sbinfo;
29266 + return 0; /* success */
29269 + au_kfree_try_rcu(sbinfo->si_branch);
29271 + au_kfree_rcu(sbinfo);
29276 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29279 + struct au_branch **brp;
29281 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29284 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29285 + if (unlikely(!sz))
29286 + sz = sizeof(*brp);
29287 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29290 + sbinfo->si_branch = brp;
29297 +/* ---------------------------------------------------------------------- */
29299 +unsigned int au_sigen_inc(struct super_block *sb)
29301 + unsigned int gen;
29302 + struct inode *inode;
29304 + SiMustWriteLock(sb);
29306 + gen = ++au_sbi(sb)->si_generation;
29307 + au_update_digen(sb->s_root);
29308 + inode = d_inode(sb->s_root);
29309 + au_update_iigen(inode, /*half*/0);
29310 + inode_inc_iversion(inode);
29314 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29316 + aufs_bindex_t br_id;
29318 + struct au_sbinfo *sbinfo;
29320 + SiMustWriteLock(sb);
29322 + sbinfo = au_sbi(sb);
29323 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29324 + br_id = ++sbinfo->si_last_br_id;
29325 + AuDebugOn(br_id < 0);
29326 + if (br_id && au_br_index(sb, br_id) < 0)
29333 +/* ---------------------------------------------------------------------- */
29335 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29336 +int si_read_lock(struct super_block *sb, int flags)
29341 + if (au_ftest_lock(flags, FLUSH))
29342 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29344 + si_noflush_read_lock(sb);
29345 + err = au_plink_maint(sb, flags);
29346 + if (unlikely(err))
29347 + si_read_unlock(sb);
29352 +int si_write_lock(struct super_block *sb, int flags)
29356 + if (au_ftest_lock(flags, FLUSH))
29357 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29359 + si_noflush_write_lock(sb);
29360 + err = au_plink_maint(sb, flags);
29361 + if (unlikely(err))
29362 + si_write_unlock(sb);
29367 +/* dentry and super_block lock. call at entry point */
29368 +int aufs_read_lock(struct dentry *dentry, int flags)
29371 + struct super_block *sb;
29373 + sb = dentry->d_sb;
29374 + err = si_read_lock(sb, flags);
29375 + if (unlikely(err))
29378 + if (au_ftest_lock(flags, DW))
29379 + di_write_lock_child(dentry);
29381 + di_read_lock_child(dentry, flags);
29383 + if (au_ftest_lock(flags, GEN)) {
29384 + err = au_digen_test(dentry, au_sigen(sb));
29385 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29386 + AuDebugOn(!err && au_dbrange_test(dentry));
29388 + err = au_dbrange_test(dentry);
29389 + if (unlikely(err))
29390 + aufs_read_unlock(dentry, flags);
29397 +void aufs_read_unlock(struct dentry *dentry, int flags)
29399 + if (au_ftest_lock(flags, DW))
29400 + di_write_unlock(dentry);
29402 + di_read_unlock(dentry, flags);
29403 + si_read_unlock(dentry->d_sb);
29406 +void aufs_write_lock(struct dentry *dentry)
29408 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29409 + di_write_lock_child(dentry);
29412 +void aufs_write_unlock(struct dentry *dentry)
29414 + di_write_unlock(dentry);
29415 + si_write_unlock(dentry->d_sb);
29418 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29421 + unsigned int sigen;
29422 + struct super_block *sb;
29425 + err = si_read_lock(sb, flags);
29426 + if (unlikely(err))
29429 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29431 + if (au_ftest_lock(flags, GEN)) {
29432 + sigen = au_sigen(sb);
29433 + err = au_digen_test(d1, sigen);
29434 + AuDebugOn(!err && au_dbrange_test(d1));
29436 + err = au_digen_test(d2, sigen);
29437 + AuDebugOn(!err && au_dbrange_test(d2));
29439 + if (unlikely(err))
29440 + aufs_read_and_write_unlock2(d1, d2);
29447 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29449 + di_write_unlock2(d1, d2);
29450 + si_read_unlock(d1->d_sb);
29452 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29453 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29454 +++ linux/fs/aufs/super.c 2019-07-11 15:42:14.472238057 +0200
29456 +// SPDX-License-Identifier: GPL-2.0
29458 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29460 + * This program, aufs is free software; you can redistribute it and/or modify
29461 + * it under the terms of the GNU General Public License as published by
29462 + * the Free Software Foundation; either version 2 of the License, or
29463 + * (at your option) any later version.
29465 + * This program is distributed in the hope that it will be useful,
29466 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29467 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29468 + * GNU General Public License for more details.
29470 + * You should have received a copy of the GNU General Public License
29471 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29475 + * mount and super_block operations
29478 +#include <linux/iversion.h>
29479 +#include <linux/mm.h>
29480 +#include <linux/seq_file.h>
29481 +#include <linux/statfs.h>
29482 +#include <linux/vmalloc.h>
29486 + * super_operations
29488 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29490 + struct au_icntnr *c;
29492 + c = au_cache_alloc_icntnr();
29494 + au_icntnr_init(c);
29495 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29496 + c->iinfo.ii_hinode = NULL;
29497 + return &c->vfs_inode;
29502 +static void aufs_destroy_inode(struct inode *inode)
29504 + if (!au_is_bad_inode(inode))
29505 + au_iinfo_fin(inode);
29508 +static void aufs_free_inode(struct inode *inode)
29510 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29513 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29515 + struct inode *inode;
29518 + inode = iget_locked(sb, ino);
29519 + if (unlikely(!inode)) {
29520 + inode = ERR_PTR(-ENOMEM);
29523 + if (!(inode->i_state & I_NEW))
29526 + err = au_xigen_new(inode);
29528 + err = au_iinfo_init(inode);
29530 + inode_inc_iversion(inode);
29532 + iget_failed(inode);
29533 + inode = ERR_PTR(err);
29537 + /* never return NULL */
29538 + AuDebugOn(!inode);
29539 + AuTraceErrPtr(inode);
29543 +/* lock free root dinfo */
29544 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29547 + aufs_bindex_t bindex, bbot;
29548 + struct path path;
29549 + struct au_hdentry *hdp;
29550 + struct au_branch *br;
29551 + au_br_perm_str_t perm;
29554 + bbot = au_sbbot(sb);
29556 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29557 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29558 + br = au_sbr(sb, bindex);
29559 + path.mnt = au_br_mnt(br);
29560 + path.dentry = hdp->hd_dentry;
29561 + err = au_seq_path(seq, &path);
29563 + au_optstr_br_perm(&perm, br->br_perm);
29564 + seq_printf(seq, "=%s", perm.a);
29565 + if (bindex != bbot)
29566 + seq_putc(seq, ':');
29569 + if (unlikely(err || seq_has_overflowed(seq)))
29575 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29576 + const char *append)
29581 + while (*pat != ':')
29584 + strcpy(p, append);
29585 + AuDebugOn(strlen(fmt) >= len);
29588 +static void au_show_wbr_create(struct seq_file *m, int v,
29589 + struct au_sbinfo *sbinfo)
29593 + struct au_wbr_mfs *mfs;
29595 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29597 + seq_puts(m, ",create=");
29598 + pat = au_optstr_wbr_create(v);
29599 + mfs = &sbinfo->si_wbr_mfs;
29601 + case AuWbrCreate_TDP:
29602 + case AuWbrCreate_RR:
29603 + case AuWbrCreate_MFS:
29604 + case AuWbrCreate_PMFS:
29605 + seq_puts(m, pat);
29607 + case AuWbrCreate_MFSRR:
29608 + case AuWbrCreate_TDMFS:
29609 + case AuWbrCreate_PMFSRR:
29610 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29611 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29613 + case AuWbrCreate_MFSV:
29614 + case AuWbrCreate_PMFSV:
29615 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29616 + seq_printf(m, fmt,
29617 + jiffies_to_msecs(mfs->mfs_expire)
29620 + case AuWbrCreate_MFSRRV:
29621 + case AuWbrCreate_TDMFSV:
29622 + case AuWbrCreate_PMFSRRV:
29623 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29624 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29625 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29632 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29634 +#ifdef CONFIG_SYSFS
29638 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29639 + aufs_bindex_t bindex, brid;
29640 + struct qstr *name;
29642 + struct dentry *d, *h_root;
29643 + struct au_branch *br;
29645 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29648 + f = au_sbi(sb)->si_xib;
29652 + /* stop printing the default xino path on the first writable branch */
29654 + bindex = au_xi_root(sb, f->f_path.dentry);
29655 + if (bindex >= 0) {
29656 + br = au_sbr_sb(sb, bindex);
29657 + h_root = au_br_dentry(br);
29660 + d = f->f_path.dentry;
29661 + name = &d->d_name;
29662 + /* safe ->d_parent because the file is unlinked */
29663 + if (d->d_parent == h_root
29664 + && name->len == len
29665 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29668 + seq_puts(seq, ",xino=");
29669 + err = au_xino_path(seq, f);
29676 +/* seq_file will re-call me in case of too long string */
29677 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29680 + unsigned int mnt_flags, v;
29681 + struct super_block *sb;
29682 + struct au_sbinfo *sbinfo;
29684 +#define AuBool(name, str) do { \
29685 + v = au_opt_test(mnt_flags, name); \
29686 + if (v != au_opt_test(AuOpt_Def, name)) \
29687 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29690 +#define AuStr(name, str) do { \
29691 + v = mnt_flags & AuOptMask_##name; \
29692 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29693 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29696 +#define AuUInt(name, str, val) do { \
29697 + if (val != AUFS_##name##_DEF) \
29698 + seq_printf(m, "," #str "=%u", val); \
29701 + sb = dentry->d_sb;
29702 + if (sb->s_flags & SB_POSIXACL)
29703 + seq_puts(m, ",acl");
29705 + if (sb->s_flags & SB_I_VERSION)
29706 + seq_puts(m, ",i_version");
29709 + /* lock free root dinfo */
29710 + si_noflush_read_lock(sb);
29711 + sbinfo = au_sbi(sb);
29712 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29714 + mnt_flags = au_mntflags(sb);
29715 + if (au_opt_test(mnt_flags, XINO)) {
29716 + err = au_show_xino(m, sb);
29717 + if (unlikely(err))
29720 + seq_puts(m, ",noxino");
29722 + AuBool(TRUNC_XINO, trunc_xino);
29723 + AuStr(UDBA, udba);
29724 + AuBool(SHWH, shwh);
29725 + AuBool(PLINK, plink);
29726 + AuBool(DIO, dio);
29727 + AuBool(DIRPERM1, dirperm1);
29729 + v = sbinfo->si_wbr_create;
29730 + if (v != AuWbrCreate_Def)
29731 + au_show_wbr_create(m, v, sbinfo);
29733 + v = sbinfo->si_wbr_copyup;
29734 + if (v != AuWbrCopyup_Def)
29735 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29737 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29738 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29739 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29741 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29743 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29744 + AuUInt(RDCACHE, rdcache, v);
29746 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29747 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29749 + au_fhsm_show(m, sbinfo);
29751 + AuBool(DIRREN, dirren);
29752 + AuBool(SUM, sum);
29753 + /* AuBool(SUM_W, wsum); */
29754 + AuBool(WARN_PERM, warn_perm);
29755 + AuBool(VERBOSE, verbose);
29758 + /* be sure to print "br:" last */
29759 + if (!sysaufs_brs) {
29760 + seq_puts(m, ",br:");
29761 + au_show_brs(m, sb);
29763 + si_read_unlock(sb);
29771 +/* ---------------------------------------------------------------------- */
29773 +/* sum mode which returns the summation for statfs(2) */
29775 +static u64 au_add_till_max(u64 a, u64 b)
29783 + return ULLONG_MAX;
29786 +static u64 au_mul_till_max(u64 a, long mul)
29794 + return ULLONG_MAX;
29797 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29800 + long bsize, factor;
29801 + u64 blocks, bfree, bavail, files, ffree;
29802 + aufs_bindex_t bbot, bindex, i;
29803 + unsigned char shared;
29804 + struct path h_path;
29805 + struct super_block *h_sb;
29808 + bsize = LONG_MAX;
29814 + bbot = au_sbbot(sb);
29815 + for (bindex = 0; bindex <= bbot; bindex++) {
29816 + h_path.mnt = au_sbr_mnt(sb, bindex);
29817 + h_sb = h_path.mnt->mnt_sb;
29819 + for (i = 0; !shared && i < bindex; i++)
29820 + shared = (au_sbr_sb(sb, i) == h_sb);
29824 + /* sb->s_root for NFS is unreliable */
29825 + h_path.dentry = h_path.mnt->mnt_root;
29826 + err = vfs_statfs(&h_path, buf);
29827 + if (unlikely(err))
29830 + if (bsize > buf->f_bsize) {
29832 + * we will reduce bsize, so we have to expand blocks
29833 + * etc. to match them again
29835 + factor = (bsize / buf->f_bsize);
29836 + blocks = au_mul_till_max(blocks, factor);
29837 + bfree = au_mul_till_max(bfree, factor);
29838 + bavail = au_mul_till_max(bavail, factor);
29839 + bsize = buf->f_bsize;
29842 + factor = (buf->f_bsize / bsize);
29843 + blocks = au_add_till_max(blocks,
29844 + au_mul_till_max(buf->f_blocks, factor));
29845 + bfree = au_add_till_max(bfree,
29846 + au_mul_till_max(buf->f_bfree, factor));
29847 + bavail = au_add_till_max(bavail,
29848 + au_mul_till_max(buf->f_bavail, factor));
29849 + files = au_add_till_max(files, buf->f_files);
29850 + ffree = au_add_till_max(ffree, buf->f_ffree);
29853 + buf->f_bsize = bsize;
29854 + buf->f_blocks = blocks;
29855 + buf->f_bfree = bfree;
29856 + buf->f_bavail = bavail;
29857 + buf->f_files = files;
29858 + buf->f_ffree = ffree;
29859 + buf->f_frsize = 0;
29865 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29868 + struct path h_path;
29869 + struct super_block *sb;
29871 + /* lock free root dinfo */
29872 + sb = dentry->d_sb;
29873 + si_noflush_read_lock(sb);
29874 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29875 + /* sb->s_root for NFS is unreliable */
29876 + h_path.mnt = au_sbr_mnt(sb, 0);
29877 + h_path.dentry = h_path.mnt->mnt_root;
29878 + err = vfs_statfs(&h_path, buf);
29880 + err = au_statfs_sum(sb, buf);
29881 + si_read_unlock(sb);
29884 + buf->f_type = AUFS_SUPER_MAGIC;
29885 + buf->f_namelen = AUFS_MAX_NAMELEN;
29886 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29888 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29893 +/* ---------------------------------------------------------------------- */
29895 +static int aufs_sync_fs(struct super_block *sb, int wait)
29898 + aufs_bindex_t bbot, bindex;
29899 + struct au_branch *br;
29900 + struct super_block *h_sb;
29903 + si_noflush_read_lock(sb);
29904 + bbot = au_sbbot(sb);
29905 + for (bindex = 0; bindex <= bbot; bindex++) {
29906 + br = au_sbr(sb, bindex);
29907 + if (!au_br_writable(br->br_perm))
29910 + h_sb = au_sbr_sb(sb, bindex);
29911 + e = vfsub_sync_filesystem(h_sb, wait);
29912 + if (unlikely(e && !err))
29914 + /* go on even if an error happens */
29916 + si_read_unlock(sb);
29921 +/* ---------------------------------------------------------------------- */
29923 +/* final actions when unmounting a file system */
29924 +static void aufs_put_super(struct super_block *sb)
29926 + struct au_sbinfo *sbinfo;
29928 + sbinfo = au_sbi(sb);
29930 + kobject_put(&sbinfo->si_kobj);
29933 +/* ---------------------------------------------------------------------- */
29935 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29936 + struct super_block *sb, void *arg)
29939 + unsigned long long n, sz;
29946 + if (*hint > ULLONG_MAX / sizeof(array)) {
29947 + array = ERR_PTR(-EMFILE);
29948 + pr_err("hint %llu\n", *hint);
29952 + sz = sizeof(array) * *hint;
29953 + array = kzalloc(sz, GFP_NOFS);
29954 + if (unlikely(!array))
29955 + array = vzalloc(sz);
29956 + if (unlikely(!array)) {
29957 + array = ERR_PTR(-ENOMEM);
29961 + n = cb(sb, array, *hint, arg);
29962 + AuDebugOn(n > *hint);
29969 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29970 + unsigned long long max __maybe_unused,
29973 + unsigned long long n;
29974 + struct inode **p, *inode;
29975 + struct list_head *head;
29980 + spin_lock(&sb->s_inode_list_lock);
29981 + list_for_each_entry(inode, head, i_sb_list) {
29982 + if (!au_is_bad_inode(inode)
29983 + && au_ii(inode)->ii_btop >= 0) {
29984 + spin_lock(&inode->i_lock);
29985 + if (atomic_read(&inode->i_count)) {
29989 + AuDebugOn(n > max);
29991 + spin_unlock(&inode->i_lock);
29994 + spin_unlock(&sb->s_inode_list_lock);
29999 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30001 + struct au_sbinfo *sbi;
30003 + sbi = au_sbi(sb);
30004 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30005 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30008 +void au_iarray_free(struct inode **a, unsigned long long max)
30010 + unsigned long long ull;
30012 + for (ull = 0; ull < max; ull++)
30017 +/* ---------------------------------------------------------------------- */
30020 + * refresh dentry and inode at remount time.
30022 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30023 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30024 + struct dentry *parent)
30028 + di_write_lock_child(dentry);
30029 + di_read_lock_parent(parent, AuLock_IR);
30030 + err = au_refresh_dentry(dentry, parent);
30031 + if (!err && dir_flags)
30032 + au_hn_reset(d_inode(dentry), dir_flags);
30033 + di_read_unlock(parent, AuLock_IR);
30034 + di_write_unlock(dentry);
30039 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30040 + struct au_sbinfo *sbinfo,
30041 + const unsigned int dir_flags, unsigned int do_idop)
30044 + struct dentry *parent;
30047 + parent = dget_parent(dentry);
30048 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30049 + if (d_really_is_positive(dentry)) {
30050 + if (!d_is_dir(dentry))
30051 + err = au_do_refresh(dentry, /*dir_flags*/0,
30054 + err = au_do_refresh(dentry, dir_flags, parent);
30055 + if (unlikely(err))
30056 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30059 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30060 + AuDbgDentry(dentry);
30066 + au_refresh_dop(dentry, /*force_reval*/0);
30068 + au_refresh_dop(dentry, /*force_reval*/1);
30074 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30076 + int err, i, j, ndentry, e;
30077 + unsigned int sigen;
30078 + struct au_dcsub_pages dpages;
30079 + struct au_dpage *dpage;
30080 + struct dentry **dentries, *d;
30081 + struct au_sbinfo *sbinfo;
30082 + struct dentry *root = sb->s_root;
30083 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30086 + au_refresh_dop(root, /*force_reval*/0);
30088 + err = au_dpages_init(&dpages, GFP_NOFS);
30089 + if (unlikely(err))
30091 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30092 + if (unlikely(err))
30095 + sigen = au_sigen(sb);
30096 + sbinfo = au_sbi(sb);
30097 + for (i = 0; i < dpages.ndpage; i++) {
30098 + dpage = dpages.dpages + i;
30099 + dentries = dpage->dentries;
30100 + ndentry = dpage->ndentry;
30101 + for (j = 0; j < ndentry; j++) {
30103 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30105 + if (unlikely(e && !err))
30107 + /* go on even err */
30112 + au_dpages_free(&dpages);
30117 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30120 + unsigned int sigen;
30121 + unsigned long long max, ull;
30122 + struct inode *inode, **array;
30124 + array = au_iarray_alloc(sb, &max);
30125 + err = PTR_ERR(array);
30126 + if (IS_ERR(array))
30130 + sigen = au_sigen(sb);
30131 + for (ull = 0; ull < max; ull++) {
30132 + inode = array[ull];
30133 + if (unlikely(!inode))
30137 + ii_write_lock_child(inode);
30138 + if (au_iigen(inode, NULL) != sigen) {
30139 + e = au_refresh_hinode_self(inode);
30140 + if (unlikely(e)) {
30141 + au_refresh_iop(inode, /*force_getattr*/1);
30142 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30145 + /* go on even if err */
30148 + if (!e && do_idop)
30149 + au_refresh_iop(inode, /*force_getattr*/0);
30150 + ii_write_unlock(inode);
30153 + au_iarray_free(array, max);
30159 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30162 + unsigned int udba;
30163 + aufs_bindex_t bindex, bbot;
30164 + struct dentry *root;
30165 + struct inode *inode;
30166 + struct au_branch *br;
30167 + struct au_sbinfo *sbi;
30169 + au_sigen_inc(sb);
30170 + sbi = au_sbi(sb);
30171 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30173 + root = sb->s_root;
30174 + DiMustNoWaiters(root);
30175 + inode = d_inode(root);
30176 + IiMustNoWaiters(inode);
30178 + udba = au_opt_udba(sb);
30179 + bbot = au_sbbot(sb);
30180 + for (bindex = 0; bindex <= bbot; bindex++) {
30181 + br = au_sbr(sb, bindex);
30182 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30183 + if (unlikely(err))
30184 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30186 + /* go on even if err */
30188 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30191 + if (au_ftest_si(sbi, NO_DREVAL)) {
30192 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30193 + sb->s_d_op = &aufs_dop_noreval;
30194 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30195 + sbi->si_iop_array = aufs_iop_nogetattr;
30197 + AuDebugOn(sb->s_d_op == &aufs_dop);
30198 + sb->s_d_op = &aufs_dop;
30199 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30200 + sbi->si_iop_array = aufs_iop;
30202 + pr_info("reset to %ps and %ps\n",
30203 + sb->s_d_op, sbi->si_iop_array);
30206 + di_write_unlock(root);
30207 + err = au_refresh_d(sb, do_idop);
30208 + e = au_refresh_i(sb, do_idop);
30209 + if (unlikely(e && !err))
30211 + /* aufs_write_lock() calls ..._child() */
30212 + di_write_lock_child(root);
30214 + au_cpup_attr_all(inode, /*force*/1);
30216 + if (unlikely(err))
30217 + AuIOErr("refresh failed, ignored, %d\n", err);
30220 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30221 +static int cvt_err(int err)
30235 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30238 + unsigned int mntflags;
30239 + struct au_opts opts = {
30242 + struct dentry *root;
30243 + struct inode *inode;
30244 + struct au_sbinfo *sbinfo;
30247 + root = sb->s_root;
30248 + if (!data || !*data) {
30249 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30251 + di_write_lock_child(root);
30252 + err = au_opts_verify(sb, *flags, /*pending*/0);
30253 + aufs_write_unlock(root);
30259 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30260 + if (unlikely(!opts.opt))
30262 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30263 + opts.flags = AuOpts_REMOUNT;
30264 + opts.sb_flags = *flags;
30266 + /* parse it before aufs lock */
30267 + err = au_opts_parse(sb, data, &opts);
30268 + if (unlikely(err))
30271 + sbinfo = au_sbi(sb);
30272 + inode = d_inode(root);
30273 + inode_lock(inode);
30274 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30275 + if (unlikely(err))
30277 + di_write_lock_child(root);
30279 + /* au_opts_remount() may return an error */
30280 + err = au_opts_remount(sb, &opts);
30281 + au_opts_free(&opts);
30283 + if (au_ftest_opts(opts.flags, REFRESH))
30284 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30286 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30287 + mntflags = au_mntflags(sb);
30288 + do_dx = !!au_opt_test(mntflags, DIO);
30289 + au_dy_arefresh(do_dx);
30292 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30293 + aufs_write_unlock(root);
30296 + inode_unlock(inode);
30298 + free_page((unsigned long)opts.opt);
30300 + err = cvt_err(err);
30305 +static const struct super_operations aufs_sop = {
30306 + .alloc_inode = aufs_alloc_inode,
30307 + .destroy_inode = aufs_destroy_inode,
30308 + .free_inode = aufs_free_inode,
30309 + /* always deleting, no clearing */
30310 + .drop_inode = generic_delete_inode,
30311 + .show_options = aufs_show_options,
30312 + .statfs = aufs_statfs,
30313 + .put_super = aufs_put_super,
30314 + .sync_fs = aufs_sync_fs,
30315 + .remount_fs = aufs_remount_fs
30318 +/* ---------------------------------------------------------------------- */
30320 +static int alloc_root(struct super_block *sb)
30323 + struct inode *inode;
30324 + struct dentry *root;
30327 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30328 + err = PTR_ERR(inode);
30329 + if (IS_ERR(inode))
30332 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30333 + inode->i_fop = &aufs_dir_fop;
30334 + inode->i_mode = S_IFDIR;
30335 + set_nlink(inode, 2);
30336 + unlock_new_inode(inode);
30338 + root = d_make_root(inode);
30339 + if (unlikely(!root))
30341 + err = PTR_ERR(root);
30342 + if (IS_ERR(root))
30345 + err = au_di_init(root);
30347 + sb->s_root = root;
30348 + return 0; /* success */
30356 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30357 + int silent __maybe_unused)
30360 + struct au_opts opts = {
30363 + struct au_sbinfo *sbinfo;
30364 + struct dentry *root;
30365 + struct inode *inode;
30366 + char *arg = raw_data;
30368 + if (unlikely(!arg || !*arg)) {
30370 + pr_err("no arg\n");
30375 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30376 + if (unlikely(!opts.opt))
30378 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30379 + opts.sb_flags = sb->s_flags;
30381 + err = au_si_alloc(sb);
30382 + if (unlikely(err))
30384 + sbinfo = au_sbi(sb);
30386 + /* all timestamps always follow the ones on the branch */
30387 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30388 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30389 + sb->s_op = &aufs_sop;
30390 + sb->s_d_op = &aufs_dop;
30391 + sb->s_magic = AUFS_SUPER_MAGIC;
30392 + sb->s_maxbytes = 0;
30393 + sb->s_stack_depth = 1;
30394 + au_export_init(sb);
30395 + au_xattr_init(sb);
30397 + err = alloc_root(sb);
30398 + if (unlikely(err)) {
30399 + si_write_unlock(sb);
30402 + root = sb->s_root;
30403 + inode = d_inode(root);
30406 + * actually we can parse options regardless aufs lock here.
30407 + * but at remount time, parsing must be done before aufs lock.
30408 + * so we follow the same rule.
30410 + ii_write_lock_parent(inode);
30411 + aufs_write_unlock(root);
30412 + err = au_opts_parse(sb, arg, &opts);
30413 + if (unlikely(err))
30416 + /* lock vfs_inode first, then aufs. */
30417 + inode_lock(inode);
30418 + aufs_write_lock(root);
30419 + err = au_opts_mount(sb, &opts);
30420 + au_opts_free(&opts);
30421 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30422 + sb->s_d_op = &aufs_dop_noreval;
30423 + pr_info("%ps\n", sb->s_d_op);
30424 + au_refresh_dop(root, /*force_reval*/0);
30425 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30426 + au_refresh_iop(inode, /*force_getattr*/0);
30428 + aufs_write_unlock(root);
30429 + inode_unlock(inode);
30431 + goto out_opts; /* success */
30435 + sb->s_root = NULL;
30437 + kobject_put(&sbinfo->si_kobj);
30438 + sb->s_fs_info = NULL;
30440 + free_page((unsigned long)opts.opt);
30443 + err = cvt_err(err);
30448 +/* ---------------------------------------------------------------------- */
30450 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30451 + const char *dev_name __maybe_unused,
30454 + struct dentry *root;
30456 + /* all timestamps always follow the ones on the branch */
30457 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30458 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30459 + if (IS_ERR(root))
30462 + au_sbilist_add(root->d_sb);
30468 +static void aufs_kill_sb(struct super_block *sb)
30470 + struct au_sbinfo *sbinfo;
30472 + sbinfo = au_sbi(sb);
30474 + au_sbilist_del(sb);
30475 + aufs_write_lock(sb->s_root);
30477 + if (sbinfo->si_wbr_create_ops->fin)
30478 + sbinfo->si_wbr_create_ops->fin(sb);
30479 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30480 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30481 + au_remount_refresh(sb, /*do_idop*/0);
30483 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30484 + au_plink_put(sb, /*verbose*/1);
30486 + au_dr_opt_flush(sb);
30487 + sbinfo->si_sb = NULL;
30488 + aufs_write_unlock(sb->s_root);
30489 + au_nwt_flush(&sbinfo->si_nowait);
30491 + kill_anon_super(sb);
30494 +struct file_system_type aufs_fs_type = {
30495 + .name = AUFS_FSTYPE,
30496 + /* a race between rename and others */
30497 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30498 + .mount = aufs_mount,
30499 + .kill_sb = aufs_kill_sb,
30500 + /* no need to __module_get() and module_put(). */
30501 + .owner = THIS_MODULE,
30503 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30504 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30505 +++ linux/fs/aufs/super.h 2019-07-11 15:42:14.472238057 +0200
30507 +/* SPDX-License-Identifier: GPL-2.0 */
30509 + * Copyright (C) 2005-2019 Junjiro R. Okajima
30511 + * This program, aufs is free software; you can redistribute it and/or modify
30512 + * it under the terms of the GNU General Public License as published by
30513 + * the Free Software Foundation; either version 2 of the License, or
30514 + * (at your option) any later version.
30516 + * This program is distributed in the hope that it will be useful,
30517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30519 + * GNU General Public License for more details.
30521 + * You should have received a copy of the GNU General Public License
30522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30526 + * super_block operations
30529 +#ifndef __AUFS_SUPER_H__
30530 +#define __AUFS_SUPER_H__
30534 +#include <linux/fs.h>
30535 +#include <linux/kobject.h>
30538 +#include "rwsem.h"
30541 +/* policies to select one among multiple writable branches */
30542 +struct au_wbr_copyup_operations {
30543 + int (*copyup)(struct dentry *dentry);
30546 +#define AuWbr_DIR 1 /* target is a dir */
30547 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30549 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30550 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30551 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30553 +struct au_wbr_create_operations {
30554 + int (*create)(struct dentry *dentry, unsigned int flags);
30555 + int (*init)(struct super_block *sb);
30556 + int (*fin)(struct super_block *sb);
30559 +struct au_wbr_mfs {
30560 + struct mutex mfs_lock; /* protect this structure */
30561 + unsigned long mfs_jiffy;
30562 + unsigned long mfs_expire;
30563 + aufs_bindex_t mfs_bindex;
30565 + unsigned long long mfsrr_bytes;
30566 + unsigned long long mfsrr_watermark;
30569 +#define AuPlink_NHASH 100
30570 +static inline int au_plink_hash(ino_t ino)
30572 + return ino % AuPlink_NHASH;
30575 +/* File-based Hierarchical Storage Management */
30577 +#ifdef CONFIG_AUFS_FHSM
30578 + /* allow only one process who can receive the notification */
30579 + spinlock_t fhsm_spin;
30581 + wait_queue_head_t fhsm_wqh;
30582 + atomic_t fhsm_readable;
30584 + /* these are protected by si_rwsem */
30585 + unsigned long fhsm_expire;
30586 + aufs_bindex_t fhsm_bottom;
30591 +struct au_sbinfo {
30592 + /* nowait tasks in the system-wide workqueue */
30593 + struct au_nowait_tasks si_nowait;
30596 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30597 + * rwsem for au_sbinfo is necessary.
30599 + struct au_rwsem si_rwsem;
30602 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30605 + au_lcnt_t si_ninodes, si_nfiles;
30607 + /* branch management */
30608 + unsigned int si_generation;
30610 + /* see AuSi_ flags */
30611 + unsigned char au_si_status;
30613 + aufs_bindex_t si_bbot;
30615 + /* dirty trick to keep br_id plus */
30616 + unsigned int si_last_br_id :
30617 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30618 + struct au_branch **si_branch;
30620 + /* policy to select a writable branch */
30621 + unsigned char si_wbr_copyup;
30622 + unsigned char si_wbr_create;
30623 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30624 + struct au_wbr_create_operations *si_wbr_create_ops;
30626 + /* round robin */
30627 + atomic_t si_wbr_rr_next;
30629 + /* most free space */
30630 + struct au_wbr_mfs si_wbr_mfs;
30632 + /* File-based Hierarchical Storage Management */
30633 + struct au_fhsm si_fhsm;
30635 + /* mount flags */
30636 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30637 + unsigned int si_mntflags;
30639 + /* external inode number (bitmap and translation table) */
30640 + vfs_readf_t si_xread;
30641 + vfs_writef_t si_xwrite;
30642 + loff_t si_ximaxent; /* max entries in a xino */
30644 + struct file *si_xib;
30645 + struct mutex si_xib_mtx; /* protect xib members */
30646 + unsigned long *si_xib_buf;
30647 + unsigned long si_xib_last_pindex;
30648 + int si_xib_next_bit;
30650 + unsigned long si_xino_jiffy;
30651 + unsigned long si_xino_expire;
30652 + /* reserved for future use */
30653 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30655 +#ifdef CONFIG_AUFS_EXPORT
30656 + /* i_generation */
30657 + /* todo: make xigen file an array to support many inode numbers */
30658 + struct file *si_xigen;
30659 + atomic_t si_xigen_next;
30662 + /* dirty trick to support atomic_open */
30663 + struct hlist_bl_head si_aopen;
30665 + /* vdir parameters */
30666 + unsigned long si_rdcache; /* max cache time in jiffies */
30667 + unsigned int si_rdblk; /* deblk size */
30668 + unsigned int si_rdhash; /* hash size */
30671 + * If the number of whiteouts are larger than si_dirwh, leave all of
30672 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30673 + * future fsck.aufs or kernel thread will remove them later.
30674 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30676 + unsigned int si_dirwh;
30678 + /* pseudo_link list */
30679 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30680 + wait_queue_head_t si_plink_wq;
30681 + spinlock_t si_plink_maint_lock;
30682 + pid_t si_plink_maint_pid;
30685 + struct hlist_bl_head si_files;
30687 + /* with/without getattr, brother of sb->s_d_op */
30688 + struct inode_operations *si_iop_array;
30691 + * sysfs and lifetime management.
30692 + * this is not a small structure and it may be a waste of memory in case
30693 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30694 + * but using sysfs is majority.
30696 + struct kobject si_kobj;
30697 +#ifdef CONFIG_DEBUG_FS
30698 + struct dentry *si_dbgaufs;
30699 + struct dentry *si_dbgaufs_plink;
30700 + struct dentry *si_dbgaufs_xib;
30701 +#ifdef CONFIG_AUFS_EXPORT
30702 + struct dentry *si_dbgaufs_xigen;
30706 +#ifdef CONFIG_AUFS_SBILIST
30707 + struct hlist_bl_node si_list;
30710 + /* dirty, necessary for unmounting, sysfs and sysrq */
30711 + struct super_block *si_sb;
30714 +/* sbinfo status flags */
30716 + * set true when refresh_dirs() failed at remount time.
30717 + * then try refreshing dirs at access time again.
30718 + * if it is false, refreshing dirs at access time is unnecessary
30720 +#define AuSi_FAILED_REFRESH_DIR 1
30721 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30722 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30724 +#ifndef CONFIG_AUFS_FHSM
30726 +#define AuSi_FHSM 0
30729 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30730 + unsigned int flag)
30732 + AuRwMustAnyLock(&sbi->si_rwsem);
30733 + return sbi->au_si_status & flag;
30735 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30736 +#define au_fset_si(sbinfo, name) do { \
30737 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30738 + (sbinfo)->au_si_status |= AuSi_##name; \
30740 +#define au_fclr_si(sbinfo, name) do { \
30741 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30742 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30745 +/* ---------------------------------------------------------------------- */
30747 +/* policy to select one among writable branches */
30748 +#define AuWbrCopyup(sbinfo, ...) \
30749 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30750 +#define AuWbrCreate(sbinfo, ...) \
30751 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30753 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30754 +#define AuLock_DW 1 /* write-lock dentry */
30755 +#define AuLock_IR (1 << 1) /* read-lock inode */
30756 +#define AuLock_IW (1 << 2) /* write-lock inode */
30757 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30758 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30759 + /* except RENAME_EXCHANGE */
30760 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30761 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30762 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30763 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30764 +#define au_fset_lock(flags, name) \
30765 + do { (flags) |= AuLock_##name; } while (0)
30766 +#define au_fclr_lock(flags, name) \
30767 + do { (flags) &= ~AuLock_##name; } while (0)
30769 +/* ---------------------------------------------------------------------- */
30772 +extern struct file_system_type aufs_fs_type;
30773 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30774 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30775 + unsigned long long max, void *arg);
30776 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30777 + struct super_block *sb, void *arg);
30778 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30779 +void au_iarray_free(struct inode **a, unsigned long long max);
30782 +void au_si_free(struct kobject *kobj);
30783 +int au_si_alloc(struct super_block *sb);
30784 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30786 +unsigned int au_sigen_inc(struct super_block *sb);
30787 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30789 +int si_read_lock(struct super_block *sb, int flags);
30790 +int si_write_lock(struct super_block *sb, int flags);
30791 +int aufs_read_lock(struct dentry *dentry, int flags);
30792 +void aufs_read_unlock(struct dentry *dentry, int flags);
30793 +void aufs_write_lock(struct dentry *dentry);
30794 +void aufs_write_unlock(struct dentry *dentry);
30795 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30796 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30798 +/* wbr_policy.c */
30799 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30800 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30801 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30802 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30803 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30806 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30808 +#ifdef CONFIG_AUFS_FHSM
30811 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30815 + spin_lock(&fhsm->fhsm_spin);
30816 + pid = fhsm->fhsm_pid;
30817 + spin_unlock(&fhsm->fhsm_spin);
30822 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30823 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30824 +int au_fhsm_fd(struct super_block *sb, int oflags);
30825 +int au_fhsm_br_alloc(struct au_branch *br);
30826 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30827 +void au_fhsm_fin(struct super_block *sb);
30828 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30829 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30830 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30832 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30834 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30835 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30836 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30837 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30838 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30839 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30840 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30841 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30842 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30845 +/* ---------------------------------------------------------------------- */
30847 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30849 + return sb->s_fs_info;
30852 +/* ---------------------------------------------------------------------- */
30854 +#ifdef CONFIG_AUFS_EXPORT
30855 +int au_test_nfsd(void);
30856 +void au_export_init(struct super_block *sb);
30857 +void au_xigen_inc(struct inode *inode);
30858 +int au_xigen_new(struct inode *inode);
30859 +int au_xigen_set(struct super_block *sb, struct path *path);
30860 +void au_xigen_clr(struct super_block *sb);
30862 +static inline int au_busy_or_stale(void)
30864 + if (!au_test_nfsd())
30869 +AuStubInt0(au_test_nfsd, void)
30870 +AuStubVoid(au_export_init, struct super_block *sb)
30871 +AuStubVoid(au_xigen_inc, struct inode *inode)
30872 +AuStubInt0(au_xigen_new, struct inode *inode)
30873 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30874 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30875 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30876 +#endif /* CONFIG_AUFS_EXPORT */
30878 +/* ---------------------------------------------------------------------- */
30880 +#ifdef CONFIG_AUFS_SBILIST
30882 +extern struct hlist_bl_head au_sbilist;
30884 +static inline void au_sbilist_init(void)
30886 + INIT_HLIST_BL_HEAD(&au_sbilist);
30889 +static inline void au_sbilist_add(struct super_block *sb)
30891 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30894 +static inline void au_sbilist_del(struct super_block *sb)
30896 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30899 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30900 +static inline void au_sbilist_lock(void)
30902 + hlist_bl_lock(&au_sbilist);
30905 +static inline void au_sbilist_unlock(void)
30907 + hlist_bl_unlock(&au_sbilist);
30909 +#define AuGFP_SBILIST GFP_ATOMIC
30911 +AuStubVoid(au_sbilist_lock, void)
30912 +AuStubVoid(au_sbilist_unlock, void)
30913 +#define AuGFP_SBILIST GFP_NOFS
30914 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30916 +AuStubVoid(au_sbilist_init, void)
30917 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30918 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30919 +AuStubVoid(au_sbilist_lock, void)
30920 +AuStubVoid(au_sbilist_unlock, void)
30921 +#define AuGFP_SBILIST GFP_NOFS
30924 +/* ---------------------------------------------------------------------- */
30926 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30929 + * This function is a dynamic '__init' function actually,
30930 + * so the tiny check for si_rwsem is unnecessary.
30932 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30933 +#ifdef CONFIG_DEBUG_FS
30934 + sbinfo->si_dbgaufs = NULL;
30935 + sbinfo->si_dbgaufs_plink = NULL;
30936 + sbinfo->si_dbgaufs_xib = NULL;
30937 +#ifdef CONFIG_AUFS_EXPORT
30938 + sbinfo->si_dbgaufs_xigen = NULL;
30943 +/* ---------------------------------------------------------------------- */
30945 +/* current->atomic_flags */
30946 +/* this value should never corrupt the ones defined in linux/sched.h */
30947 +#define PFA_AUFS 0x10
30949 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30950 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30951 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30953 +static inline int si_pid_test(struct super_block *sb)
30955 + return !!task_test_aufs(current);
30958 +static inline void si_pid_clr(struct super_block *sb)
30960 + AuDebugOn(!task_test_aufs(current));
30961 + task_clear_aufs(current);
30964 +static inline void si_pid_set(struct super_block *sb)
30966 + AuDebugOn(task_test_aufs(current));
30967 + task_set_aufs(current);
30970 +/* ---------------------------------------------------------------------- */
30972 +/* lock superblock. mainly for entry point functions */
30973 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30974 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30975 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30976 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30978 +#define __si_read_trylock_nested(sb) \
30979 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30980 +#define __si_write_trylock_nested(sb) \
30981 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30984 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30985 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30986 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30988 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30989 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30990 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30992 +static inline void si_noflush_read_lock(struct super_block *sb)
30994 + __si_read_lock(sb);
30998 +static inline int si_noflush_read_trylock(struct super_block *sb)
31002 + locked = __si_read_trylock(sb);
31008 +static inline void si_noflush_write_lock(struct super_block *sb)
31010 + __si_write_lock(sb);
31014 +static inline int si_noflush_write_trylock(struct super_block *sb)
31018 + locked = __si_write_trylock(sb);
31024 +#if 0 /* reserved */
31025 +static inline int si_read_trylock(struct super_block *sb, int flags)
31027 + if (au_ftest_lock(flags, FLUSH))
31028 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31029 + return si_noflush_read_trylock(sb);
31033 +static inline void si_read_unlock(struct super_block *sb)
31036 + __si_read_unlock(sb);
31039 +#if 0 /* reserved */
31040 +static inline int si_write_trylock(struct super_block *sb, int flags)
31042 + if (au_ftest_lock(flags, FLUSH))
31043 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31044 + return si_noflush_write_trylock(sb);
31048 +static inline void si_write_unlock(struct super_block *sb)
31051 + __si_write_unlock(sb);
31054 +#if 0 /* reserved */
31055 +static inline void si_downgrade_lock(struct super_block *sb)
31057 + __si_downgrade_lock(sb);
31061 +/* ---------------------------------------------------------------------- */
31063 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31065 + SiMustAnyLock(sb);
31066 + return au_sbi(sb)->si_bbot;
31069 +static inline unsigned int au_mntflags(struct super_block *sb)
31071 + SiMustAnyLock(sb);
31072 + return au_sbi(sb)->si_mntflags;
31075 +static inline unsigned int au_sigen(struct super_block *sb)
31077 + SiMustAnyLock(sb);
31078 + return au_sbi(sb)->si_generation;
31081 +static inline struct au_branch *au_sbr(struct super_block *sb,
31082 + aufs_bindex_t bindex)
31084 + SiMustAnyLock(sb);
31085 + return au_sbi(sb)->si_branch[0 + bindex];
31088 +static inline loff_t au_xi_maxent(struct super_block *sb)
31090 + SiMustAnyLock(sb);
31091 + return au_sbi(sb)->si_ximaxent;
31094 +#endif /* __KERNEL__ */
31095 +#endif /* __AUFS_SUPER_H__ */
31096 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31097 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31098 +++ linux/fs/aufs/sysaufs.c 2019-07-11 15:42:14.472238057 +0200
31100 +// SPDX-License-Identifier: GPL-2.0
31102 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31104 + * This program, aufs is free software; you can redistribute it and/or modify
31105 + * it under the terms of the GNU General Public License as published by
31106 + * the Free Software Foundation; either version 2 of the License, or
31107 + * (at your option) any later version.
31109 + * This program is distributed in the hope that it will be useful,
31110 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31111 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31112 + * GNU General Public License for more details.
31114 + * You should have received a copy of the GNU General Public License
31115 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31119 + * sysfs interface and lifetime management
31120 + * they are necessary regardless sysfs is disabled.
31123 +#include <linux/random.h>
31126 +unsigned long sysaufs_si_mask;
31127 +struct kset *sysaufs_kset;
31129 +#define AuSiAttr(_name) { \
31130 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31131 + .show = sysaufs_si_##_name, \
31134 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31135 +struct attribute *sysaufs_si_attrs[] = {
31136 + &sysaufs_si_attr_xi_path.attr,
31140 +static const struct sysfs_ops au_sbi_ops = {
31141 + .show = sysaufs_si_show
31144 +static struct kobj_type au_sbi_ktype = {
31145 + .release = au_si_free,
31146 + .sysfs_ops = &au_sbi_ops,
31147 + .default_attrs = sysaufs_si_attrs
31150 +/* ---------------------------------------------------------------------- */
31152 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31156 + sbinfo->si_kobj.kset = sysaufs_kset;
31157 + /* cf. sysaufs_name() */
31158 + err = kobject_init_and_add
31159 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31160 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31165 +void sysaufs_fin(void)
31167 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31168 + kset_unregister(sysaufs_kset);
31171 +int __init sysaufs_init(void)
31176 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31177 + } while (!sysaufs_si_mask);
31180 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31181 + if (unlikely(!sysaufs_kset))
31183 + err = PTR_ERR(sysaufs_kset);
31184 + if (IS_ERR(sysaufs_kset))
31186 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31187 + if (unlikely(err))
31188 + kset_unregister(sysaufs_kset);
31193 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31194 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31195 +++ linux/fs/aufs/sysaufs.h 2019-07-11 15:42:14.475571481 +0200
31197 +/* SPDX-License-Identifier: GPL-2.0 */
31199 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31201 + * This program, aufs is free software; you can redistribute it and/or modify
31202 + * it under the terms of the GNU General Public License as published by
31203 + * the Free Software Foundation; either version 2 of the License, or
31204 + * (at your option) any later version.
31206 + * This program is distributed in the hope that it will be useful,
31207 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31209 + * GNU General Public License for more details.
31211 + * You should have received a copy of the GNU General Public License
31212 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31216 + * sysfs interface and mount lifetime management
31219 +#ifndef __SYSAUFS_H__
31220 +#define __SYSAUFS_H__
31224 +#include <linux/sysfs.h>
31225 +#include "module.h"
31227 +struct super_block;
31230 +struct sysaufs_si_attr {
31231 + struct attribute attr;
31232 + int (*show)(struct seq_file *seq, struct super_block *sb);
31235 +/* ---------------------------------------------------------------------- */
31238 +extern unsigned long sysaufs_si_mask;
31239 +extern struct kset *sysaufs_kset;
31240 +extern struct attribute *sysaufs_si_attrs[];
31241 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31242 +int __init sysaufs_init(void);
31243 +void sysaufs_fin(void);
31245 +/* ---------------------------------------------------------------------- */
31247 +/* some people doesn't like to show a pointer in kernel */
31248 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31250 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31253 +#define SysaufsSiNamePrefix "si_"
31254 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31255 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31257 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31258 + sysaufs_si_id(sbinfo));
31262 +#ifdef CONFIG_SYSFS
31264 +extern struct attribute_group *sysaufs_attr_group;
31266 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31267 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31269 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31270 +#ifdef CONFIG_COMPAT
31271 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31274 +void sysaufs_br_init(struct au_branch *br);
31275 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31276 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31278 +#define sysaufs_brs_init() do {} while (0)
31281 +#define sysaufs_attr_group NULL
31283 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31284 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31285 + struct attribute *attr, char *buf)
31286 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31287 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31288 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31290 +static inline void sysaufs_brs_init(void)
31295 +#endif /* CONFIG_SYSFS */
31297 +#endif /* __KERNEL__ */
31298 +#endif /* __SYSAUFS_H__ */
31299 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31300 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31301 +++ linux/fs/aufs/sysfs.c 2019-07-11 15:42:14.475571481 +0200
31303 +// SPDX-License-Identifier: GPL-2.0
31305 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31307 + * This program, aufs is free software; you can redistribute it and/or modify
31308 + * it under the terms of the GNU General Public License as published by
31309 + * the Free Software Foundation; either version 2 of the License, or
31310 + * (at your option) any later version.
31312 + * This program is distributed in the hope that it will be useful,
31313 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31314 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31315 + * GNU General Public License for more details.
31317 + * You should have received a copy of the GNU General Public License
31318 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31322 + * sysfs interface
31325 +#include <linux/compat.h>
31326 +#include <linux/seq_file.h>
31329 +#ifdef CONFIG_AUFS_FS_MODULE
31330 +/* this entry violates the "one line per file" policy of sysfs */
31331 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31335 + static char *conf =
31336 +/* this file is generated at compiling */
31337 +#include "conf.str"
31340 + err = snprintf(buf, PAGE_SIZE, conf);
31341 + if (unlikely(err >= PAGE_SIZE))
31346 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31349 +static struct attribute *au_attr[] = {
31350 +#ifdef CONFIG_AUFS_FS_MODULE
31351 + &au_config_attr.attr,
31353 + NULL, /* need to NULL terminate the list of attributes */
31356 +static struct attribute_group sysaufs_attr_group_body = {
31360 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31362 +/* ---------------------------------------------------------------------- */
31364 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31368 + SiMustAnyLock(sb);
31371 + if (au_opt_test(au_mntflags(sb), XINO)) {
31372 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31373 + seq_putc(seq, '\n');
31379 + * the lifetime of branch is independent from the entry under sysfs.
31380 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31383 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31384 + aufs_bindex_t bindex, int idx)
31387 + struct path path;
31388 + struct dentry *root;
31389 + struct au_branch *br;
31390 + au_br_perm_str_t perm;
31392 + AuDbg("b%d\n", bindex);
31395 + root = sb->s_root;
31396 + di_read_lock_parent(root, !AuLock_IR);
31397 + br = au_sbr(sb, bindex);
31400 + case AuBrSysfs_BR:
31401 + path.mnt = au_br_mnt(br);
31402 + path.dentry = au_h_dptr(root, bindex);
31403 + err = au_seq_path(seq, &path);
31405 + au_optstr_br_perm(&perm, br->br_perm);
31406 + seq_printf(seq, "=%s\n", perm.a);
31409 + case AuBrSysfs_BRID:
31410 + seq_printf(seq, "%d\n", br->br_id);
31413 + di_read_unlock(root, !AuLock_IR);
31414 + if (unlikely(err || seq_has_overflowed(seq)))
31420 +/* ---------------------------------------------------------------------- */
31422 +static struct seq_file *au_seq(char *p, ssize_t len)
31424 + struct seq_file *seq;
31426 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31428 + /* mutex_init(&seq.lock); */
31431 + return seq; /* success */
31434 + seq = ERR_PTR(-ENOMEM);
31438 +#define SysaufsBr_PREFIX "br"
31439 +#define SysaufsBrid_PREFIX "brid"
31441 +/* todo: file size may exceed PAGE_SIZE */
31442 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31448 + aufs_bindex_t bbot;
31449 + struct au_sbinfo *sbinfo;
31450 + struct super_block *sb;
31451 + struct seq_file *seq;
31453 + struct attribute **cattr;
31455 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31456 + sb = sbinfo->si_sb;
31459 + * prevent a race condition between sysfs and aufs.
31460 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31461 + * prohibits maintaining the sysfs entries.
31462 + * hew we acquire read lock after sysfs_get_active_two().
31463 + * on the other hand, the remount process may maintain the sysfs/aufs
31464 + * entries after acquiring write lock.
31465 + * it can cause a deadlock.
31466 + * simply we gave up processing read here.
31469 + if (unlikely(!si_noflush_read_trylock(sb)))
31472 + seq = au_seq(buf, PAGE_SIZE);
31473 + err = PTR_ERR(seq);
31477 + name = (void *)attr->name;
31478 + cattr = sysaufs_si_attrs;
31480 + if (!strcmp(name, (*cattr)->name)) {
31481 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31488 + if (!strncmp(name, SysaufsBrid_PREFIX,
31489 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31490 + idx = AuBrSysfs_BRID;
31491 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31492 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31493 + sizeof(SysaufsBr_PREFIX) - 1)) {
31494 + idx = AuBrSysfs_BR;
31495 + name += sizeof(SysaufsBr_PREFIX) - 1;
31499 + err = kstrtol(name, 10, &l);
31501 + bbot = au_sbbot(sb);
31503 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31510 + err = seq->count;
31511 + /* sysfs limit */
31512 + if (unlikely(err == PAGE_SIZE))
31515 + au_kfree_rcu(seq);
31517 + si_read_unlock(sb);
31522 +/* ---------------------------------------------------------------------- */
31524 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31528 + aufs_bindex_t bindex, bbot;
31531 + struct seq_file *seq;
31532 + struct au_branch *br;
31534 + si_read_lock(sb, AuLock_FLUSH);
31535 + bbot = au_sbbot(sb);
31541 + buf = (void *)__get_free_page(GFP_NOFS);
31542 + if (unlikely(!buf))
31545 + seq = au_seq(buf, PAGE_SIZE);
31546 + err = PTR_ERR(seq);
31550 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31551 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31552 + /* VERIFY_WRITE */
31553 + err = !access_ok(arg, sizeof(*arg));
31554 + if (unlikely(err))
31557 + br = au_sbr(sb, bindex);
31558 + brid = br->br_id;
31559 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31560 + err = __put_user(brid, &arg->id);
31561 + if (unlikely(err))
31564 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31565 + err = __put_user(br->br_perm, &arg->perm);
31566 + if (unlikely(err))
31569 + err = au_seq_path(seq, &br->br_path);
31570 + if (unlikely(err))
31572 + seq_putc(seq, '\0');
31573 + if (!seq_has_overflowed(seq)) {
31574 + err = copy_to_user(arg->path, seq->buf, seq->count);
31576 + if (unlikely(err))
31583 + if (unlikely(err))
31587 + au_kfree_rcu(seq);
31589 + free_page((unsigned long)buf);
31591 + si_read_unlock(sb);
31595 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31597 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31600 +#ifdef CONFIG_COMPAT
31601 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31603 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31607 +/* ---------------------------------------------------------------------- */
31609 +void sysaufs_br_init(struct au_branch *br)
31612 + struct au_brsysfs *br_sysfs;
31613 + struct attribute *attr;
31615 + br_sysfs = br->br_sysfs;
31616 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31617 + attr = &br_sysfs->attr;
31618 + sysfs_attr_init(attr);
31619 + attr->name = br_sysfs->name;
31620 + attr->mode = 0444;
31625 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31627 + struct au_branch *br;
31628 + struct kobject *kobj;
31629 + struct au_brsysfs *br_sysfs;
31631 + aufs_bindex_t bbot;
31633 + if (!sysaufs_brs)
31636 + kobj = &au_sbi(sb)->si_kobj;
31637 + bbot = au_sbbot(sb);
31638 + for (; bindex <= bbot; bindex++) {
31639 + br = au_sbr(sb, bindex);
31640 + br_sysfs = br->br_sysfs;
31641 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31642 + sysfs_remove_file(kobj, &br_sysfs->attr);
31648 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31651 + aufs_bindex_t bbot;
31652 + struct kobject *kobj;
31653 + struct au_branch *br;
31654 + struct au_brsysfs *br_sysfs;
31656 + if (!sysaufs_brs)
31659 + kobj = &au_sbi(sb)->si_kobj;
31660 + bbot = au_sbbot(sb);
31661 + for (; bindex <= bbot; bindex++) {
31662 + br = au_sbr(sb, bindex);
31663 + br_sysfs = br->br_sysfs;
31664 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31665 + SysaufsBr_PREFIX "%d", bindex);
31666 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31667 + SysaufsBrid_PREFIX "%d", bindex);
31668 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31669 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31670 + if (unlikely(err))
31671 + pr_warn("failed %s under sysfs(%d)\n",
31672 + br_sysfs->name, err);
31677 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31678 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31679 +++ linux/fs/aufs/sysrq.c 2019-07-11 15:42:14.475571481 +0200
31681 +// SPDX-License-Identifier: GPL-2.0
31683 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31685 + * This program, aufs is free software; you can redistribute it and/or modify
31686 + * it under the terms of the GNU General Public License as published by
31687 + * the Free Software Foundation; either version 2 of the License, or
31688 + * (at your option) any later version.
31690 + * This program is distributed in the hope that it will be useful,
31691 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31692 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31693 + * GNU General Public License for more details.
31695 + * You should have received a copy of the GNU General Public License
31696 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31700 + * magic sysrq handler
31703 +/* #include <linux/sysrq.h> */
31704 +#include <linux/writeback.h>
31707 +/* ---------------------------------------------------------------------- */
31709 +static void sysrq_sb(struct super_block *sb)
31712 + struct au_sbinfo *sbinfo;
31713 + struct file *file;
31714 + struct hlist_bl_head *files;
31715 + struct hlist_bl_node *pos;
31716 + struct au_finfo *finfo;
31718 + plevel = au_plevel;
31719 + au_plevel = KERN_WARNING;
31721 + /* since we define pr_fmt, call printk directly */
31722 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31724 + sbinfo = au_sbi(sb);
31725 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31726 + pr("superblock\n");
31730 + pr("root dentry\n");
31731 + au_dpri_dentry(sb->s_root);
31732 + pr("root inode\n");
31733 + au_dpri_inode(d_inode(sb->s_root));
31738 + int err, i, j, ndentry;
31739 + struct au_dcsub_pages dpages;
31740 + struct au_dpage *dpage;
31742 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31743 + if (unlikely(err))
31745 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31747 + for (i = 0; i < dpages.ndpage; i++) {
31748 + dpage = dpages.dpages + i;
31749 + ndentry = dpage->ndentry;
31750 + for (j = 0; j < ndentry; j++)
31751 + au_dpri_dentry(dpage->dentries[j]);
31753 + au_dpages_free(&dpages);
31761 + pr("isolated inode\n");
31762 + spin_lock(&sb->s_inode_list_lock);
31763 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31764 + spin_lock(&i->i_lock);
31765 + if (1 || hlist_empty(&i->i_dentry))
31766 + au_dpri_inode(i);
31767 + spin_unlock(&i->i_lock);
31769 + spin_unlock(&sb->s_inode_list_lock);
31773 + files = &au_sbi(sb)->si_files;
31774 + hlist_bl_lock(files);
31775 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31778 + file = finfo->fi_file;
31779 + mode = file_inode(file)->i_mode;
31780 + if (!special_file(mode))
31781 + au_dpri_file(file);
31783 + hlist_bl_unlock(files);
31787 + au_plevel = plevel;
31790 +/* ---------------------------------------------------------------------- */
31792 +/* module parameter */
31793 +static char *aufs_sysrq_key = "a";
31794 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31795 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31797 +static void au_sysrq(int key __maybe_unused)
31799 + struct au_sbinfo *sbinfo;
31800 + struct hlist_bl_node *pos;
31803 + au_sbilist_lock();
31804 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31805 + sysrq_sb(sbinfo->si_sb);
31806 + au_sbilist_unlock();
31810 +static struct sysrq_key_op au_sysrq_op = {
31811 + .handler = au_sysrq,
31812 + .help_msg = "Aufs",
31813 + .action_msg = "Aufs",
31814 + .enable_mask = SYSRQ_ENABLE_DUMP
31817 +/* ---------------------------------------------------------------------- */
31819 +int __init au_sysrq_init(void)
31825 + key = *aufs_sysrq_key;
31826 + if ('a' <= key && key <= 'z')
31827 + err = register_sysrq_key(key, &au_sysrq_op);
31828 + if (unlikely(err))
31829 + pr_err("err %d, sysrq=%c\n", err, key);
31833 +void au_sysrq_fin(void)
31837 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31838 + if (unlikely(err))
31839 + pr_err("err %d (ignored)\n", err);
31841 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31842 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31843 +++ linux/fs/aufs/vdir.c 2019-07-11 15:42:14.475571481 +0200
31845 +// SPDX-License-Identifier: GPL-2.0
31847 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31849 + * This program, aufs is free software; you can redistribute it and/or modify
31850 + * it under the terms of the GNU General Public License as published by
31851 + * the Free Software Foundation; either version 2 of the License, or
31852 + * (at your option) any later version.
31854 + * This program is distributed in the hope that it will be useful,
31855 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31856 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31857 + * GNU General Public License for more details.
31859 + * You should have received a copy of the GNU General Public License
31860 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31864 + * virtual or vertical directory
31867 +#include <linux/iversion.h>
31870 +static unsigned int calc_size(int nlen)
31872 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31875 +static int set_deblk_end(union au_vdir_deblk_p *p,
31876 + union au_vdir_deblk_p *deblk_end)
31878 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31879 + p->de->de_str.len = 0;
31883 + return -1; /* error */
31886 +/* returns true or false */
31887 +static int is_deblk_end(union au_vdir_deblk_p *p,
31888 + union au_vdir_deblk_p *deblk_end)
31890 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31891 + return !p->de->de_str.len;
31895 +static unsigned char *last_deblk(struct au_vdir *vdir)
31897 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31900 +/* ---------------------------------------------------------------------- */
31902 +/* estimate the appropriate size for name hash table */
31903 +unsigned int au_rdhash_est(loff_t sz)
31911 + if (sz < AUFS_RDHASH_DEF)
31912 + n = AUFS_RDHASH_DEF;
31913 + /* pr_info("n %u\n", n); */
31918 + * the allocated memory has to be freed by
31919 + * au_nhash_wh_free() or au_nhash_de_free().
31921 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31923 + struct hlist_head *head;
31927 + sz = sizeof(*nhash->nh_head) * num_hash;
31928 + head = kmalloc(sz, gfp);
31930 + nhash->nh_num = num_hash;
31931 + nhash->nh_head = head;
31932 + for (u = 0; u < num_hash; u++)
31933 + INIT_HLIST_HEAD(head++);
31934 + return 0; /* success */
31940 +static void nhash_count(struct hlist_head *head)
31944 + struct hlist_node *pos;
31947 + hlist_for_each(pos, head)
31949 + pr_info("%lu\n", n);
31953 +static void au_nhash_wh_do_free(struct hlist_head *head)
31955 + struct au_vdir_wh *pos;
31956 + struct hlist_node *node;
31958 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31959 + au_kfree_rcu(pos);
31962 +static void au_nhash_de_do_free(struct hlist_head *head)
31964 + struct au_vdir_dehstr *pos;
31965 + struct hlist_node *node;
31967 + hlist_for_each_entry_safe(pos, node, head, hash)
31968 + au_cache_free_vdir_dehstr(pos);
31971 +static void au_nhash_do_free(struct au_nhash *nhash,
31972 + void (*free)(struct hlist_head *head))
31975 + struct hlist_head *head;
31977 + n = nhash->nh_num;
31981 + head = nhash->nh_head;
31982 + while (n-- > 0) {
31983 + nhash_count(head);
31986 + au_kfree_try_rcu(nhash->nh_head);
31989 +void au_nhash_wh_free(struct au_nhash *whlist)
31991 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31994 +static void au_nhash_de_free(struct au_nhash *delist)
31996 + au_nhash_do_free(delist, au_nhash_de_do_free);
31999 +/* ---------------------------------------------------------------------- */
32001 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32005 + unsigned int u, n;
32006 + struct hlist_head *head;
32007 + struct au_vdir_wh *pos;
32010 + n = whlist->nh_num;
32011 + head = whlist->nh_head;
32012 + for (u = 0; u < n; u++, head++)
32013 + hlist_for_each_entry(pos, head, wh_hash)
32014 + if (pos->wh_bindex == btgt && ++num > limit)
32019 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32020 + unsigned char *name,
32021 + unsigned int len)
32024 + /* const unsigned int magic_bit = 12; */
32026 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32033 + /* v = hash_long(v, magic_bit); */
32034 + v %= nhash->nh_num;
32035 + return nhash->nh_head + v;
32038 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32041 + return str->len == nlen && !memcmp(str->name, name, nlen);
32044 +/* returns found or not */
32045 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32047 + struct hlist_head *head;
32048 + struct au_vdir_wh *pos;
32049 + struct au_vdir_destr *str;
32051 + head = au_name_hash(whlist, name, nlen);
32052 + hlist_for_each_entry(pos, head, wh_hash) {
32053 + str = &pos->wh_str;
32054 + AuDbg("%.*s\n", str->len, str->name);
32055 + if (au_nhash_test_name(str, name, nlen))
32061 +/* returns found(true) or not */
32062 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32064 + struct hlist_head *head;
32065 + struct au_vdir_dehstr *pos;
32066 + struct au_vdir_destr *str;
32068 + head = au_name_hash(delist, name, nlen);
32069 + hlist_for_each_entry(pos, head, hash) {
32071 + AuDbg("%.*s\n", str->len, str->name);
32072 + if (au_nhash_test_name(str, name, nlen))
32078 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32079 + unsigned char d_type)
32081 +#ifdef CONFIG_AUFS_SHWH
32082 + wh->wh_ino = ino;
32083 + wh->wh_type = d_type;
32087 +/* ---------------------------------------------------------------------- */
32089 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32090 + unsigned int d_type, aufs_bindex_t bindex,
32091 + unsigned char shwh)
32094 + struct au_vdir_destr *str;
32095 + struct au_vdir_wh *wh;
32097 + AuDbg("%.*s\n", nlen, name);
32098 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32101 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32102 + if (unlikely(!wh))
32106 + wh->wh_bindex = bindex;
32108 + au_shwh_init_wh(wh, ino, d_type);
32109 + str = &wh->wh_str;
32111 + memcpy(str->name, name, nlen);
32112 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32119 +static int append_deblk(struct au_vdir *vdir)
32122 + unsigned long ul;
32123 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32124 + union au_vdir_deblk_p p, deblk_end;
32125 + unsigned char **o;
32128 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32129 + GFP_NOFS, /*may_shrink*/0);
32130 + if (unlikely(!o))
32133 + vdir->vd_deblk = o;
32134 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32136 + ul = vdir->vd_nblk++;
32137 + vdir->vd_deblk[ul] = p.deblk;
32138 + vdir->vd_last.ul = ul;
32139 + vdir->vd_last.p.deblk = p.deblk;
32140 + deblk_end.deblk = p.deblk + deblk_sz;
32141 + err = set_deblk_end(&p, &deblk_end);
32148 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32149 + unsigned int d_type, struct au_nhash *delist)
32153 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32154 + union au_vdir_deblk_p p, *room, deblk_end;
32155 + struct au_vdir_dehstr *dehstr;
32157 + p.deblk = last_deblk(vdir);
32158 + deblk_end.deblk = p.deblk + deblk_sz;
32159 + room = &vdir->vd_last.p;
32160 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32161 + || !is_deblk_end(room, &deblk_end));
32163 + sz = calc_size(nlen);
32164 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32165 + err = append_deblk(vdir);
32166 + if (unlikely(err))
32169 + p.deblk = last_deblk(vdir);
32170 + deblk_end.deblk = p.deblk + deblk_sz;
32172 + AuDebugOn(room->deblk != p.deblk);
32176 + dehstr = au_cache_alloc_vdir_dehstr();
32177 + if (unlikely(!dehstr))
32180 + dehstr->str = &room->de->de_str;
32181 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32182 + room->de->de_ino = ino;
32183 + room->de->de_type = d_type;
32184 + room->de->de_str.len = nlen;
32185 + memcpy(room->de->de_str.name, name, nlen);
32188 + room->deblk += sz;
32189 + if (unlikely(set_deblk_end(room, &deblk_end)))
32190 + err = append_deblk(vdir);
32197 +/* ---------------------------------------------------------------------- */
32199 +void au_vdir_free(struct au_vdir *vdir)
32201 + unsigned char **deblk;
32203 + deblk = vdir->vd_deblk;
32204 + while (vdir->vd_nblk--)
32205 + au_kfree_try_rcu(*deblk++);
32206 + au_kfree_try_rcu(vdir->vd_deblk);
32207 + au_cache_free_vdir(vdir);
32210 +static struct au_vdir *alloc_vdir(struct file *file)
32212 + struct au_vdir *vdir;
32213 + struct super_block *sb;
32216 + sb = file->f_path.dentry->d_sb;
32217 + SiMustAnyLock(sb);
32220 + vdir = au_cache_alloc_vdir();
32221 + if (unlikely(!vdir))
32224 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32225 + if (unlikely(!vdir->vd_deblk))
32228 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32229 + if (!vdir->vd_deblk_sz) {
32230 + /* estimate the appropriate size for deblk */
32231 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32232 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32234 + vdir->vd_nblk = 0;
32235 + vdir->vd_version = 0;
32236 + vdir->vd_jiffy = 0;
32237 + err = append_deblk(vdir);
32239 + return vdir; /* success */
32241 + au_kfree_try_rcu(vdir->vd_deblk);
32244 + au_cache_free_vdir(vdir);
32246 + vdir = ERR_PTR(err);
32250 +static int reinit_vdir(struct au_vdir *vdir)
32253 + union au_vdir_deblk_p p, deblk_end;
32255 + while (vdir->vd_nblk > 1) {
32256 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32257 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32260 + p.deblk = vdir->vd_deblk[0];
32261 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32262 + err = set_deblk_end(&p, &deblk_end);
32263 + /* keep vd_dblk_sz */
32264 + vdir->vd_last.ul = 0;
32265 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32266 + vdir->vd_version = 0;
32267 + vdir->vd_jiffy = 0;
32272 +/* ---------------------------------------------------------------------- */
32274 +#define AuFillVdir_CALLED 1
32275 +#define AuFillVdir_WHABLE (1 << 1)
32276 +#define AuFillVdir_SHWH (1 << 2)
32277 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32278 +#define au_fset_fillvdir(flags, name) \
32279 + do { (flags) |= AuFillVdir_##name; } while (0)
32280 +#define au_fclr_fillvdir(flags, name) \
32281 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32283 +#ifndef CONFIG_AUFS_SHWH
32284 +#undef AuFillVdir_SHWH
32285 +#define AuFillVdir_SHWH 0
32288 +struct fillvdir_arg {
32289 + struct dir_context ctx;
32290 + struct file *file;
32291 + struct au_vdir *vdir;
32292 + struct au_nhash delist;
32293 + struct au_nhash whlist;
32294 + aufs_bindex_t bindex;
32295 + unsigned int flags;
32299 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32300 + loff_t offset __maybe_unused, u64 h_ino,
32301 + unsigned int d_type)
32303 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32304 + char *name = (void *)__name;
32305 + struct super_block *sb;
32307 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32310 + sb = arg->file->f_path.dentry->d_sb;
32311 + au_fset_fillvdir(arg->flags, CALLED);
32313 + if (nlen <= AUFS_WH_PFX_LEN
32314 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32315 + if (test_known(&arg->delist, name, nlen)
32316 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32317 + goto out; /* already exists or whiteouted */
32319 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32321 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32322 + d_type = DT_UNKNOWN;
32323 + arg->err = append_de(arg->vdir, name, nlen, ino,
32324 + d_type, &arg->delist);
32326 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32327 + name += AUFS_WH_PFX_LEN;
32328 + nlen -= AUFS_WH_PFX_LEN;
32329 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32330 + goto out; /* already whiteouted */
32332 + ino = 0; /* just to suppress a warning */
32334 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32337 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32338 + d_type = DT_UNKNOWN;
32339 + arg->err = au_nhash_append_wh
32340 + (&arg->whlist, name, nlen, ino, d_type,
32341 + arg->bindex, shwh);
32347 + arg->vdir->vd_jiffy = jiffies;
32349 + AuTraceErr(arg->err);
32353 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32354 + struct au_nhash *whlist, struct au_nhash *delist)
32356 +#ifdef CONFIG_AUFS_SHWH
32358 + unsigned int nh, u;
32359 + struct hlist_head *head;
32360 + struct au_vdir_wh *pos;
32361 + struct hlist_node *n;
32363 + struct au_vdir_destr *destr;
32365 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32368 + o = p = (void *)__get_free_page(GFP_NOFS);
32369 + if (unlikely(!p))
32373 + nh = whlist->nh_num;
32374 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32375 + p += AUFS_WH_PFX_LEN;
32376 + for (u = 0; u < nh; u++) {
32377 + head = whlist->nh_head + u;
32378 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32379 + destr = &pos->wh_str;
32380 + memcpy(p, destr->name, destr->len);
32381 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32382 + pos->wh_ino, pos->wh_type, delist);
32383 + if (unlikely(err))
32388 + free_page((unsigned long)o);
32398 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32401 + unsigned int rdhash;
32403 + aufs_bindex_t bbot, bindex, btop;
32404 + unsigned char shwh;
32405 + struct file *hf, *file;
32406 + struct super_block *sb;
32408 + file = arg->file;
32409 + sb = file->f_path.dentry->d_sb;
32410 + SiMustAnyLock(sb);
32412 + rdhash = au_sbi(sb)->si_rdhash;
32414 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32415 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32416 + if (unlikely(err))
32418 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32419 + if (unlikely(err))
32425 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32427 + au_fset_fillvdir(arg->flags, SHWH);
32429 + btop = au_fbtop(file);
32430 + bbot = au_fbbot_dir(file);
32431 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32432 + hf = au_hf_dir(file, bindex);
32436 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32438 + if (unlikely(offset))
32441 + arg->bindex = bindex;
32442 + au_fclr_fillvdir(arg->flags, WHABLE);
32444 + || (bindex != bbot
32445 + && au_br_whable(au_sbr_perm(sb, bindex))))
32446 + au_fset_fillvdir(arg->flags, WHABLE);
32449 + au_fclr_fillvdir(arg->flags, CALLED);
32451 + err = vfsub_iterate_dir(hf, &arg->ctx);
32454 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32457 + * dir_relax() may be good for concurrency, but aufs should not
32458 + * use it since it will cause a lockdep problem.
32462 + if (!err && shwh)
32463 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32465 + au_nhash_wh_free(&arg->whlist);
32468 + au_nhash_de_free(&arg->delist);
32473 +static int read_vdir(struct file *file, int may_read)
32476 + unsigned long expire;
32477 + unsigned char do_read;
32478 + struct fillvdir_arg arg = {
32480 + .actor = fillvdir
32483 + struct inode *inode;
32484 + struct au_vdir *vdir, *allocated;
32487 + inode = file_inode(file);
32488 + IMustLock(inode);
32489 + IiMustWriteLock(inode);
32490 + SiMustAnyLock(inode->i_sb);
32492 + allocated = NULL;
32494 + expire = au_sbi(inode->i_sb)->si_rdcache;
32495 + vdir = au_ivdir(inode);
32498 + vdir = alloc_vdir(file);
32499 + err = PTR_ERR(vdir);
32500 + if (IS_ERR(vdir))
32503 + allocated = vdir;
32504 + } else if (may_read
32505 + && (!inode_eq_iversion(inode, vdir->vd_version)
32506 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32508 + err = reinit_vdir(vdir);
32509 + if (unlikely(err))
32514 + return 0; /* success */
32518 + err = au_do_read_vdir(&arg);
32520 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32521 + vdir->vd_version = inode_query_iversion(inode);
32522 + vdir->vd_last.ul = 0;
32523 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32525 + au_set_ivdir(inode, allocated);
32526 + } else if (allocated)
32527 + au_vdir_free(allocated);
32533 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32536 + unsigned long ul, n;
32537 + const unsigned int deblk_sz = src->vd_deblk_sz;
32539 + AuDebugOn(tgt->vd_nblk != 1);
32542 + if (tgt->vd_nblk < src->vd_nblk) {
32543 + unsigned char **p;
32545 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32546 + GFP_NOFS, /*may_shrink*/0);
32547 + if (unlikely(!p))
32549 + tgt->vd_deblk = p;
32552 + if (tgt->vd_deblk_sz != deblk_sz) {
32553 + unsigned char *p;
32555 + tgt->vd_deblk_sz = deblk_sz;
32556 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32557 + /*may_shrink*/1);
32558 + if (unlikely(!p))
32560 + tgt->vd_deblk[0] = p;
32562 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32563 + tgt->vd_version = src->vd_version;
32564 + tgt->vd_jiffy = src->vd_jiffy;
32566 + n = src->vd_nblk;
32567 + for (ul = 1; ul < n; ul++) {
32568 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32570 + if (unlikely(!tgt->vd_deblk[ul]))
32574 + tgt->vd_nblk = n;
32575 + tgt->vd_last.ul = tgt->vd_last.ul;
32576 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32577 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32578 + - src->vd_deblk[src->vd_last.ul];
32580 + return 0; /* success */
32583 + rerr = reinit_vdir(tgt);
32588 +int au_vdir_init(struct file *file)
32591 + struct inode *inode;
32592 + struct au_vdir *vdir_cache, *allocated;
32594 + /* test file->f_pos here instead of ctx->pos */
32595 + err = read_vdir(file, !file->f_pos);
32596 + if (unlikely(err))
32599 + allocated = NULL;
32600 + vdir_cache = au_fvdir_cache(file);
32601 + if (!vdir_cache) {
32602 + vdir_cache = alloc_vdir(file);
32603 + err = PTR_ERR(vdir_cache);
32604 + if (IS_ERR(vdir_cache))
32606 + allocated = vdir_cache;
32607 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32608 + /* test file->f_pos here instead of ctx->pos */
32609 + err = reinit_vdir(vdir_cache);
32610 + if (unlikely(err))
32613 + return 0; /* success */
32615 + inode = file_inode(file);
32616 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32618 + file->f_version = inode_query_iversion(inode);
32620 + au_set_fvdir_cache(file, allocated);
32621 + } else if (allocated)
32622 + au_vdir_free(allocated);
32628 +static loff_t calc_offset(struct au_vdir *vdir)
32631 + union au_vdir_deblk_p p;
32633 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32634 + offset = vdir->vd_last.p.deblk - p.deblk;
32635 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32639 +/* returns true or false */
32640 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32643 + unsigned int deblk_sz;
32644 + unsigned long ul, n;
32646 + union au_vdir_deblk_p p, deblk_end;
32647 + struct au_vdir *vdir_cache;
32650 + vdir_cache = au_fvdir_cache(file);
32651 + offset = calc_offset(vdir_cache);
32652 + AuDbg("offset %lld\n", offset);
32653 + if (ctx->pos == offset)
32656 + vdir_cache->vd_last.ul = 0;
32657 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32662 + deblk_sz = vdir_cache->vd_deblk_sz;
32663 + ul = div64_u64(ctx->pos, deblk_sz);
32664 + AuDbg("ul %lu\n", ul);
32665 + if (ul >= vdir_cache->vd_nblk)
32668 + n = vdir_cache->vd_nblk;
32669 + for (; ul < n; ul++) {
32670 + p.deblk = vdir_cache->vd_deblk[ul];
32671 + deblk_end.deblk = p.deblk + deblk_sz;
32673 + offset *= deblk_sz;
32674 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32677 + l = calc_size(p.de->de_str.len);
32681 + if (!is_deblk_end(&p, &deblk_end)) {
32683 + vdir_cache->vd_last.ul = ul;
32684 + vdir_cache->vd_last.p = p;
32692 + AuDbg("valid %d\n", !valid);
32696 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32698 + unsigned int l, deblk_sz;
32699 + union au_vdir_deblk_p deblk_end;
32700 + struct au_vdir *vdir_cache;
32701 + struct au_vdir_de *de;
32703 + if (!seek_vdir(file, ctx))
32706 + vdir_cache = au_fvdir_cache(file);
32707 + deblk_sz = vdir_cache->vd_deblk_sz;
32709 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32710 + deblk_end.deblk += deblk_sz;
32711 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32712 + de = vdir_cache->vd_last.p.de;
32713 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32714 + de->de_str.len, de->de_str.name, ctx->pos,
32715 + (unsigned long)de->de_ino, de->de_type);
32716 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32717 + de->de_str.len, de->de_ino,
32719 + /* todo: ignore the error caused by udba? */
32720 + /* return err; */
32724 + l = calc_size(de->de_str.len);
32725 + vdir_cache->vd_last.p.deblk += l;
32728 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32729 + vdir_cache->vd_last.ul++;
32730 + vdir_cache->vd_last.p.deblk
32731 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32732 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32741 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32742 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32743 +++ linux/fs/aufs/vfsub.c 2019-07-11 15:42:14.475571481 +0200
32745 +// SPDX-License-Identifier: GPL-2.0
32747 + * Copyright (C) 2005-2019 Junjiro R. Okajima
32749 + * This program, aufs is free software; you can redistribute it and/or modify
32750 + * it under the terms of the GNU General Public License as published by
32751 + * the Free Software Foundation; either version 2 of the License, or
32752 + * (at your option) any later version.
32754 + * This program is distributed in the hope that it will be useful,
32755 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32756 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32757 + * GNU General Public License for more details.
32759 + * You should have received a copy of the GNU General Public License
32760 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32764 + * sub-routines for VFS
32767 +#include <linux/mnt_namespace.h>
32768 +#include <linux/namei.h>
32769 +#include <linux/nsproxy.h>
32770 +#include <linux/security.h>
32771 +#include <linux/splice.h>
32774 +#ifdef CONFIG_AUFS_BR_FUSE
32775 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32777 + if (!au_test_fuse(h_sb) || !au_userns)
32780 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32784 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32789 + down_read(&h_sb->s_umount);
32790 + err = __sync_filesystem(h_sb, wait);
32791 + up_read(&h_sb->s_umount);
32797 +/* ---------------------------------------------------------------------- */
32799 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32803 + struct super_block *h_sb;
32805 + /* for remote fs, leave work for its getattr or d_revalidate */
32806 + /* for bad i_attr fs, handle them in aufs_getattr() */
32807 + /* still some fs may acquire i_mutex. we need to skip them */
32811 + h_sb = h_path->dentry->d_sb;
32812 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32814 + err = vfsub_getattr(h_path, &st);
32819 +/* ---------------------------------------------------------------------- */
32821 +struct file *vfsub_dentry_open(struct path *path, int flags)
32823 + struct file *file;
32825 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32827 + if (!IS_ERR_OR_NULL(file)
32828 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32829 + i_readcount_inc(d_inode(path->dentry));
32834 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32836 + struct file *file;
32839 + file = filp_open(path,
32840 + oflags /* | __FMODE_NONOTIFY */,
32843 + if (IS_ERR(file))
32845 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32852 + * Ideally this function should call VFS:do_last() in order to keep all its
32853 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32854 + * structure such as nameidata. This is a second (or third) best approach.
32855 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32857 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32858 + struct vfsub_aopen_args *args)
32861 + struct au_branch *br = args->br;
32862 + struct file *file = args->file;
32863 + /* copied from linux/fs/namei.c:atomic_open() */
32864 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32867 + AuDebugOn(!dir->i_op->atomic_open);
32869 + err = au_br_test_oflag(args->open_flag, br);
32870 + if (unlikely(err))
32873 + au_lcnt_inc(&br->br_nfiles);
32874 + file->f_path.dentry = DENTRY_NOT_SET;
32875 + file->f_path.mnt = au_br_mnt(br);
32876 + AuDbg("%ps\n", dir->i_op->atomic_open);
32877 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32878 + args->create_mode);
32879 + if (unlikely(err < 0)) {
32880 + au_lcnt_dec(&br->br_nfiles);
32884 + /* temporary workaround for nfsv4 branch */
32885 + if (au_test_nfs(dir->i_sb))
32886 + nfs_mark_for_revalidate(dir);
32888 + if (file->f_mode & FMODE_CREATED)
32889 + fsnotify_create(dir, dentry);
32890 + if (!(file->f_mode & FMODE_OPENED)) {
32891 + au_lcnt_dec(&br->br_nfiles);
32895 + /* todo: call VFS:may_open() here */
32896 + /* todo: ima_file_check() too? */
32897 + if (!err && (args->open_flag & __FMODE_EXEC))
32898 + err = deny_write_access(file);
32900 + fsnotify_open(file);
32902 + au_lcnt_dec(&br->br_nfiles);
32903 + /* note that the file is created and still opened */
32909 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32913 + err = kern_path(name, flags, path);
32914 + if (!err && d_is_positive(path->dentry))
32915 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32919 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32920 + struct dentry *parent, int len)
32922 + struct path path = {
32926 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32927 + if (IS_ERR(path.dentry))
32929 + if (d_is_positive(path.dentry))
32930 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32933 + AuTraceErrPtr(path.dentry);
32934 + return path.dentry;
32937 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32940 + struct path path = {
32944 + /* VFS checks it too, but by WARN_ON_ONCE() */
32945 + IMustLock(d_inode(parent));
32947 + path.dentry = lookup_one_len(name, parent, len);
32948 + if (IS_ERR(path.dentry))
32950 + if (d_is_positive(path.dentry))
32951 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32954 + AuTraceErrPtr(path.dentry);
32955 + return path.dentry;
32958 +void vfsub_call_lkup_one(void *args)
32960 + struct vfsub_lkup_one_args *a = args;
32961 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32964 +/* ---------------------------------------------------------------------- */
32966 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32967 + struct dentry *d2, struct au_hinode *hdir2)
32969 + struct dentry *d;
32972 + d = lock_rename(d1, d2);
32974 + au_hn_suspend(hdir1);
32975 + if (hdir1 != hdir2)
32976 + au_hn_suspend(hdir2);
32981 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32982 + struct dentry *d2, struct au_hinode *hdir2)
32984 + au_hn_resume(hdir1);
32985 + if (hdir1 != hdir2)
32986 + au_hn_resume(hdir2);
32988 + unlock_rename(d1, d2);
32992 +/* ---------------------------------------------------------------------- */
32994 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32997 + struct dentry *d;
33001 + d = path->dentry;
33002 + path->dentry = d->d_parent;
33003 + err = security_path_mknod(path, d, mode, 0);
33004 + path->dentry = d;
33005 + if (unlikely(err))
33009 + err = vfs_create(dir, path->dentry, mode, want_excl);
33012 + struct path tmp = *path;
33015 + vfsub_update_h_iattr(&tmp, &did);
33017 + tmp.dentry = path->dentry->d_parent;
33018 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33027 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33030 + struct dentry *d;
33034 + d = path->dentry;
33035 + path->dentry = d->d_parent;
33036 + err = security_path_symlink(path, d, symname);
33037 + path->dentry = d;
33038 + if (unlikely(err))
33042 + err = vfs_symlink(dir, path->dentry, symname);
33045 + struct path tmp = *path;
33048 + vfsub_update_h_iattr(&tmp, &did);
33050 + tmp.dentry = path->dentry->d_parent;
33051 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33060 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33063 + struct dentry *d;
33067 + d = path->dentry;
33068 + path->dentry = d->d_parent;
33069 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33070 + path->dentry = d;
33071 + if (unlikely(err))
33075 + err = vfs_mknod(dir, path->dentry, mode, dev);
33078 + struct path tmp = *path;
33081 + vfsub_update_h_iattr(&tmp, &did);
33083 + tmp.dentry = path->dentry->d_parent;
33084 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33093 +static int au_test_nlink(struct inode *inode)
33095 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33097 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33098 + || inode->i_nlink < link_max)
33103 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33104 + struct inode **delegated_inode)
33107 + struct dentry *d;
33111 + err = au_test_nlink(d_inode(src_dentry));
33112 + if (unlikely(err))
33115 + /* we don't call may_linkat() */
33116 + d = path->dentry;
33117 + path->dentry = d->d_parent;
33118 + err = security_path_link(src_dentry, path, d);
33119 + path->dentry = d;
33120 + if (unlikely(err))
33124 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33127 + struct path tmp = *path;
33130 + /* fuse has different memory inode for the same inumber */
33131 + vfsub_update_h_iattr(&tmp, &did);
33133 + tmp.dentry = path->dentry->d_parent;
33134 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33135 + tmp.dentry = src_dentry;
33136 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33145 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33146 + struct inode *dir, struct path *path,
33147 + struct inode **delegated_inode, unsigned int flags)
33150 + struct path tmp = {
33153 + struct dentry *d;
33156 + IMustLock(src_dir);
33158 + d = path->dentry;
33159 + path->dentry = d->d_parent;
33160 + tmp.dentry = src_dentry->d_parent;
33161 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33162 + path->dentry = d;
33163 + if (unlikely(err))
33167 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33168 + delegated_inode, flags);
33173 + tmp.dentry = d->d_parent;
33174 + vfsub_update_h_iattr(&tmp, &did);
33176 + tmp.dentry = src_dentry;
33177 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33178 + tmp.dentry = src_dentry->d_parent;
33179 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33188 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33191 + struct dentry *d;
33195 + d = path->dentry;
33196 + path->dentry = d->d_parent;
33197 + err = security_path_mkdir(path, d, mode);
33198 + path->dentry = d;
33199 + if (unlikely(err))
33203 + err = vfs_mkdir(dir, path->dentry, mode);
33206 + struct path tmp = *path;
33209 + vfsub_update_h_iattr(&tmp, &did);
33211 + tmp.dentry = path->dentry->d_parent;
33212 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33221 +int vfsub_rmdir(struct inode *dir, struct path *path)
33224 + struct dentry *d;
33228 + d = path->dentry;
33229 + path->dentry = d->d_parent;
33230 + err = security_path_rmdir(path, d);
33231 + path->dentry = d;
33232 + if (unlikely(err))
33236 + err = vfs_rmdir(dir, path->dentry);
33239 + struct path tmp = {
33240 + .dentry = path->dentry->d_parent,
33244 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33251 +/* ---------------------------------------------------------------------- */
33253 +/* todo: support mmap_sem? */
33254 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33260 + err = vfs_read(file, ubuf, count, ppos);
33263 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33267 +/* todo: kernel_read()? */
33268 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33272 + mm_segment_t oldfs;
33279 + oldfs = get_fs();
33280 + set_fs(KERNEL_DS);
33281 + err = vfsub_read_u(file, buf.u, count, ppos);
33286 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33292 + err = vfs_write(file, ubuf, count, ppos);
33295 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33299 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33302 + mm_segment_t oldfs;
33305 + const char __user *u;
33309 + oldfs = get_fs();
33310 + set_fs(KERNEL_DS);
33311 + err = vfsub_write_u(file, buf.u, count, ppos);
33316 +int vfsub_flush(struct file *file, fl_owner_t id)
33321 + if (file->f_op->flush) {
33322 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33323 + err = file->f_op->flush(file, id);
33326 + err = file->f_op->flush(file, id);
33330 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33336 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33340 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33343 + err = iterate_dir(file, ctx);
33346 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33351 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33352 + struct pipe_inode_info *pipe, size_t len,
33353 + unsigned int flags)
33358 + err = do_splice_to(in, ppos, pipe, len, flags);
33360 + file_accessed(in);
33362 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33366 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33367 + loff_t *ppos, size_t len, unsigned int flags)
33372 + err = do_splice_from(pipe, out, ppos, len, flags);
33375 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33379 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33383 + /* file can be NULL */
33385 + err = vfs_fsync(file, datasync);
33389 + AuDebugOn(!file);
33390 + path = &file->f_path;
33392 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33397 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33398 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33399 + struct file *h_file)
33402 + struct inode *h_inode;
33403 + struct super_block *h_sb;
33406 + err = vfsub_truncate(h_path, length);
33410 + h_inode = d_inode(h_path->dentry);
33411 + h_sb = h_inode->i_sb;
33413 + sb_start_write(h_sb);
33415 + err = locks_verify_truncate(h_inode, h_file, length);
33417 + err = security_path_truncate(h_path);
33420 + err = do_truncate(h_path->dentry, length, attr, h_file);
33424 + sb_end_write(h_sb);
33431 +/* ---------------------------------------------------------------------- */
33433 +struct au_vfsub_mkdir_args {
33435 + struct inode *dir;
33436 + struct path *path;
33440 +static void au_call_vfsub_mkdir(void *args)
33442 + struct au_vfsub_mkdir_args *a = args;
33443 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33446 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33448 + int err, do_sio, wkq_err;
33450 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33453 + err = vfsub_mkdir(dir, path, mode);
33456 + struct au_vfsub_mkdir_args args = {
33462 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33463 + if (unlikely(wkq_err))
33470 +struct au_vfsub_rmdir_args {
33472 + struct inode *dir;
33473 + struct path *path;
33476 +static void au_call_vfsub_rmdir(void *args)
33478 + struct au_vfsub_rmdir_args *a = args;
33479 + *a->errp = vfsub_rmdir(a->dir, a->path);
33482 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33484 + int err, do_sio, wkq_err;
33486 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33489 + err = vfsub_rmdir(dir, path);
33492 + struct au_vfsub_rmdir_args args = {
33497 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33498 + if (unlikely(wkq_err))
33505 +/* ---------------------------------------------------------------------- */
33507 +struct notify_change_args {
33509 + struct path *path;
33510 + struct iattr *ia;
33511 + struct inode **delegated_inode;
33514 +static void call_notify_change(void *args)
33516 + struct notify_change_args *a = args;
33517 + struct inode *h_inode;
33519 + h_inode = d_inode(a->path->dentry);
33520 + IMustLock(h_inode);
33522 + *a->errp = -EPERM;
33523 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33525 + *a->errp = notify_change(a->path->dentry, a->ia,
33526 + a->delegated_inode);
33529 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33531 + AuTraceErr(*a->errp);
33534 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33535 + struct inode **delegated_inode)
33538 + struct notify_change_args args = {
33542 + .delegated_inode = delegated_inode
33545 + call_notify_change(&args);
33550 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33551 + struct inode **delegated_inode)
33553 + int err, wkq_err;
33554 + struct notify_change_args args = {
33558 + .delegated_inode = delegated_inode
33561 + wkq_err = au_wkq_wait(call_notify_change, &args);
33562 + if (unlikely(wkq_err))
33568 +/* ---------------------------------------------------------------------- */
33570 +struct unlink_args {
33572 + struct inode *dir;
33573 + struct path *path;
33574 + struct inode **delegated_inode;
33577 +static void call_unlink(void *args)
33579 + struct unlink_args *a = args;
33580 + struct dentry *d = a->path->dentry;
33581 + struct inode *h_inode;
33582 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33583 + && au_dcount(d) == 1);
33585 + IMustLock(a->dir);
33587 + a->path->dentry = d->d_parent;
33588 + *a->errp = security_path_unlink(a->path, d);
33589 + a->path->dentry = d;
33590 + if (unlikely(*a->errp))
33593 + if (!stop_sillyrename)
33596 + if (d_is_positive(d)) {
33597 + h_inode = d_inode(d);
33602 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33605 + struct path tmp = {
33606 + .dentry = d->d_parent,
33607 + .mnt = a->path->mnt
33609 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33612 + if (!stop_sillyrename)
33617 + AuTraceErr(*a->errp);
33621 + * @dir: must be locked.
33622 + * @dentry: target dentry.
33624 +int vfsub_unlink(struct inode *dir, struct path *path,
33625 + struct inode **delegated_inode, int force)
33628 + struct unlink_args args = {
33632 + .delegated_inode = delegated_inode
33636 + call_unlink(&args);
33640 + wkq_err = au_wkq_wait(call_unlink, &args);
33641 + if (unlikely(wkq_err))
33647 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33648 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33649 +++ linux/fs/aufs/vfsub.h 2019-07-11 15:42:14.475571481 +0200
33651 +/* SPDX-License-Identifier: GPL-2.0 */
33653 + * Copyright (C) 2005-2019 Junjiro R. Okajima
33655 + * This program, aufs is free software; you can redistribute it and/or modify
33656 + * it under the terms of the GNU General Public License as published by
33657 + * the Free Software Foundation; either version 2 of the License, or
33658 + * (at your option) any later version.
33660 + * This program is distributed in the hope that it will be useful,
33661 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33662 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33663 + * GNU General Public License for more details.
33665 + * You should have received a copy of the GNU General Public License
33666 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33670 + * sub-routines for VFS
33673 +#ifndef __AUFS_VFSUB_H__
33674 +#define __AUFS_VFSUB_H__
33678 +#include <linux/fs.h>
33679 +#include <linux/mount.h>
33680 +#include <linux/posix_acl.h>
33681 +#include <linux/xattr.h>
33682 +#include "debug.h"
33684 +/* copied from linux/fs/internal.h */
33685 +/* todo: BAD approach!! */
33686 +extern void __mnt_drop_write(struct vfsmount *);
33687 +extern struct file *alloc_empty_file(int, const struct cred *);
33689 +/* ---------------------------------------------------------------------- */
33691 +/* lock subclass for lower inode */
33692 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33693 +/* reduce? gave up. */
33695 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33696 + AuLsc_I_PARENT, /* lower inode, parent first */
33697 + AuLsc_I_PARENT2, /* copyup dirs */
33698 + AuLsc_I_PARENT3, /* copyup wh */
33704 +/* to debug easier, do not make them inlined functions */
33705 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33706 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33708 +/* ---------------------------------------------------------------------- */
33710 +static inline void vfsub_drop_nlink(struct inode *inode)
33712 + AuDebugOn(!inode->i_nlink);
33713 + drop_nlink(inode);
33716 +static inline void vfsub_dead_dir(struct inode *inode)
33718 + AuDebugOn(!S_ISDIR(inode->i_mode));
33719 + inode->i_flags |= S_DEAD;
33720 + clear_nlink(inode);
33723 +static inline int vfsub_native_ro(struct inode *inode)
33725 + return sb_rdonly(inode->i_sb)
33726 + || IS_RDONLY(inode)
33727 + /* || IS_APPEND(inode) */
33728 + || IS_IMMUTABLE(inode);
33731 +#ifdef CONFIG_AUFS_BR_FUSE
33732 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33734 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33737 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33739 +/* ---------------------------------------------------------------------- */
33741 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33742 +struct file *vfsub_dentry_open(struct path *path, int flags);
33743 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33745 +struct vfsub_aopen_args {
33746 + struct file *file;
33747 + unsigned int open_flag;
33748 + umode_t create_mode;
33749 + struct au_branch *br;
33751 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33752 + struct vfsub_aopen_args *args);
33753 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33755 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33756 + struct dentry *parent, int len);
33757 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33760 +struct vfsub_lkup_one_args {
33761 + struct dentry **errp;
33762 + struct qstr *name;
33763 + struct dentry *parent;
33766 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33767 + struct dentry *parent)
33769 + return vfsub_lookup_one_len(name->name, parent, name->len);
33772 +void vfsub_call_lkup_one(void *args);
33774 +/* ---------------------------------------------------------------------- */
33776 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33781 + err = mnt_want_write(mnt);
33786 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33789 + mnt_drop_write(mnt);
33793 +#if 0 /* reserved */
33794 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33797 + mnt_drop_write_file(file);
33802 +/* ---------------------------------------------------------------------- */
33805 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33806 + struct dentry *d2, struct au_hinode *hdir2);
33807 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33808 + struct dentry *d2, struct au_hinode *hdir2);
33810 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33812 +int vfsub_symlink(struct inode *dir, struct path *path,
33813 + const char *symname);
33814 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33815 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33816 + struct path *path, struct inode **delegated_inode);
33817 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33818 + struct inode *hdir, struct path *path,
33819 + struct inode **delegated_inode, unsigned int flags);
33820 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33821 +int vfsub_rmdir(struct inode *dir, struct path *path);
33823 +/* ---------------------------------------------------------------------- */
33825 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33827 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33829 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33831 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33833 +int vfsub_flush(struct file *file, fl_owner_t id);
33834 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33836 +static inline loff_t vfsub_f_size_read(struct file *file)
33838 + return i_size_read(file_inode(file));
33841 +static inline unsigned int vfsub_file_flags(struct file *file)
33843 + unsigned int flags;
33845 + spin_lock(&file->f_lock);
33846 + flags = file->f_flags;
33847 + spin_unlock(&file->f_lock);
33852 +static inline int vfsub_file_execed(struct file *file)
33854 + /* todo: direct access f_flags */
33855 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33858 +#if 0 /* reserved */
33859 +static inline void vfsub_file_accessed(struct file *h_file)
33861 + file_accessed(h_file);
33862 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33866 +#if 0 /* reserved */
33867 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33868 + struct dentry *h_dentry)
33870 + struct path h_path = {
33871 + .dentry = h_dentry,
33874 + touch_atime(&h_path);
33875 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33879 +static inline int vfsub_update_time(struct inode *h_inode,
33880 + struct timespec64 *ts, int flags)
33882 + return update_time(h_inode, ts, flags);
33883 + /* no vfsub_update_h_iattr() since we don't have struct path */
33886 +#ifdef CONFIG_FS_POSIX_ACL
33887 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33891 + err = posix_acl_chmod(h_inode, h_mode);
33892 + if (err == -EOPNOTSUPP)
33897 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33900 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33901 + struct pipe_inode_info *pipe, size_t len,
33902 + unsigned int flags);
33903 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33904 + loff_t *ppos, size_t len, unsigned int flags);
33906 +static inline long vfsub_truncate(struct path *path, loff_t length)
33911 + err = vfs_truncate(path, length);
33916 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33917 + struct file *h_file);
33918 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33921 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33924 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33930 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33936 +/* copy_file_range(2) is a systemcall */
33937 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33938 + struct file *dst, loff_t dst_pos,
33939 + size_t len, unsigned int flags)
33944 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33950 +/* ---------------------------------------------------------------------- */
33952 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33957 + err = vfs_llseek(file, offset, origin);
33962 +/* ---------------------------------------------------------------------- */
33964 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33965 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33966 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33967 + struct inode **delegated_inode);
33968 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33969 + struct inode **delegated_inode);
33970 +int vfsub_unlink(struct inode *dir, struct path *path,
33971 + struct inode **delegated_inode, int force);
33973 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33975 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33978 +/* ---------------------------------------------------------------------- */
33980 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33981 + const void *value, size_t size, int flags)
33986 + err = vfs_setxattr(dentry, name, value, size, flags);
33992 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33997 + err = vfs_removexattr(dentry, name);
34003 +#endif /* __KERNEL__ */
34004 +#endif /* __AUFS_VFSUB_H__ */
34005 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34006 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34007 +++ linux/fs/aufs/wbr_policy.c 2019-07-11 15:42:14.475571481 +0200
34009 +// SPDX-License-Identifier: GPL-2.0
34011 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34013 + * This program, aufs is free software; you can redistribute it and/or modify
34014 + * it under the terms of the GNU General Public License as published by
34015 + * the Free Software Foundation; either version 2 of the License, or
34016 + * (at your option) any later version.
34018 + * This program is distributed in the hope that it will be useful,
34019 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34020 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34021 + * GNU General Public License for more details.
34023 + * You should have received a copy of the GNU General Public License
34024 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34028 + * policies for selecting one among multiple writable branches
34031 +#include <linux/statfs.h>
34034 +/* subset of cpup_attr() */
34035 +static noinline_for_stack
34036 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34040 + struct inode *h_isrc;
34042 + h_isrc = d_inode(h_src);
34043 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34044 + ia.ia_mode = h_isrc->i_mode;
34045 + ia.ia_uid = h_isrc->i_uid;
34046 + ia.ia_gid = h_isrc->i_gid;
34047 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34048 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34049 + /* no delegation since it is just created */
34050 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34052 + /* is this nfs only? */
34053 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34054 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34055 + ia.ia_mode = h_isrc->i_mode;
34056 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34062 +#define AuCpdown_PARENT_OPQ 1
34063 +#define AuCpdown_WHED (1 << 1)
34064 +#define AuCpdown_MADE_DIR (1 << 2)
34065 +#define AuCpdown_DIROPQ (1 << 3)
34066 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34067 +#define au_fset_cpdown(flags, name) \
34068 + do { (flags) |= AuCpdown_##name; } while (0)
34069 +#define au_fclr_cpdown(flags, name) \
34070 + do { (flags) &= ~AuCpdown_##name; } while (0)
34072 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34073 + unsigned int *flags)
34076 + struct dentry *opq_dentry;
34078 + opq_dentry = au_diropq_create(dentry, bdst);
34079 + err = PTR_ERR(opq_dentry);
34080 + if (IS_ERR(opq_dentry))
34082 + dput(opq_dentry);
34083 + au_fset_cpdown(*flags, DIROPQ);
34089 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34090 + struct inode *dir, aufs_bindex_t bdst)
34093 + struct path h_path;
34094 + struct au_branch *br;
34096 + br = au_sbr(dentry->d_sb, bdst);
34097 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34098 + err = PTR_ERR(h_path.dentry);
34099 + if (IS_ERR(h_path.dentry))
34103 + if (d_is_positive(h_path.dentry)) {
34104 + h_path.mnt = au_br_mnt(br);
34105 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34108 + dput(h_path.dentry);
34114 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34115 + struct au_pin *pin,
34116 + struct dentry *h_parent, void *arg)
34119 + aufs_bindex_t bopq, btop;
34120 + struct path h_path;
34121 + struct dentry *parent;
34122 + struct inode *h_dir, *h_inode, *inode, *dir;
34123 + unsigned int *flags = arg;
34125 + btop = au_dbtop(dentry);
34126 + /* dentry is di-locked */
34127 + parent = dget_parent(dentry);
34128 + dir = d_inode(parent);
34129 + h_dir = d_inode(h_parent);
34130 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34131 + IMustLock(h_dir);
34133 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34134 + if (unlikely(err < 0))
34136 + h_path.dentry = au_h_dptr(dentry, bdst);
34137 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34138 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34139 + if (unlikely(err))
34141 + au_fset_cpdown(*flags, MADE_DIR);
34143 + bopq = au_dbdiropq(dentry);
34144 + au_fclr_cpdown(*flags, WHED);
34145 + au_fclr_cpdown(*flags, DIROPQ);
34146 + if (au_dbwh(dentry) == bdst)
34147 + au_fset_cpdown(*flags, WHED);
34148 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34149 + au_fset_cpdown(*flags, PARENT_OPQ);
34150 + h_inode = d_inode(h_path.dentry);
34151 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34152 + if (au_ftest_cpdown(*flags, WHED)) {
34153 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34154 + if (unlikely(err)) {
34155 + inode_unlock(h_inode);
34160 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34161 + inode_unlock(h_inode);
34162 + if (unlikely(err))
34165 + if (au_ftest_cpdown(*flags, WHED)) {
34166 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34167 + if (unlikely(err))
34171 + inode = d_inode(dentry);
34172 + if (au_ibbot(inode) < bdst)
34173 + au_set_ibbot(inode, bdst);
34174 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34175 + au_hi_flags(inode, /*isdir*/1));
34176 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34177 + goto out; /* success */
34181 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34182 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34183 + rerr = au_diropq_remove(dentry, bdst);
34184 + inode_unlock(h_inode);
34185 + if (unlikely(rerr)) {
34186 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34187 + dentry, bdst, rerr);
34193 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34194 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34195 + if (unlikely(rerr)) {
34196 + AuIOErr("failed removing %pd b%d (%d)\n",
34197 + dentry, bdst, rerr);
34202 + au_set_h_dptr(dentry, bdst, NULL);
34203 + if (au_dbbot(dentry) == bdst)
34204 + au_update_dbbot(dentry);
34210 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34213 + unsigned int flags;
34216 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34221 +/* ---------------------------------------------------------------------- */
34223 +/* policies for create */
34225 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34227 + int err, i, j, ndentry;
34228 + aufs_bindex_t bopq;
34229 + struct au_dcsub_pages dpages;
34230 + struct au_dpage *dpage;
34231 + struct dentry **dentries, *parent, *d;
34233 + err = au_dpages_init(&dpages, GFP_NOFS);
34234 + if (unlikely(err))
34236 + parent = dget_parent(dentry);
34237 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34238 + if (unlikely(err))
34242 + for (i = 0; i < dpages.ndpage; i++) {
34243 + dpage = dpages.dpages + i;
34244 + dentries = dpage->dentries;
34245 + ndentry = dpage->ndentry;
34246 + for (j = 0; j < ndentry; j++) {
34248 + di_read_lock_parent2(d, !AuLock_IR);
34249 + bopq = au_dbdiropq(d);
34250 + di_read_unlock(d, !AuLock_IR);
34251 + if (bopq >= 0 && bopq < err)
34258 + au_dpages_free(&dpages);
34263 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34265 + for (; bindex >= 0; bindex--)
34266 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34271 +/* top down parent */
34272 +static int au_wbr_create_tdp(struct dentry *dentry,
34273 + unsigned int flags __maybe_unused)
34276 + aufs_bindex_t btop, bindex;
34277 + struct super_block *sb;
34278 + struct dentry *parent, *h_parent;
34280 + sb = dentry->d_sb;
34281 + btop = au_dbtop(dentry);
34283 + if (!au_br_rdonly(au_sbr(sb, btop)))
34287 + parent = dget_parent(dentry);
34288 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34289 + h_parent = au_h_dptr(parent, bindex);
34290 + if (!h_parent || d_is_negative(h_parent))
34293 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34300 + /* bottom up here */
34301 + if (unlikely(err < 0)) {
34302 + err = au_wbr_bu(sb, btop - 1);
34304 + err = au_wbr_nonopq(dentry, err);
34308 + AuDbg("b%d\n", err);
34312 +/* ---------------------------------------------------------------------- */
34314 +/* an exception for the policy other than tdp */
34315 +static int au_wbr_create_exp(struct dentry *dentry)
34318 + aufs_bindex_t bwh, bdiropq;
34319 + struct dentry *parent;
34322 + bwh = au_dbwh(dentry);
34323 + parent = dget_parent(dentry);
34324 + bdiropq = au_dbdiropq(parent);
34326 + if (bdiropq >= 0)
34327 + err = min(bdiropq, bwh);
34330 + AuDbg("%d\n", err);
34331 + } else if (bdiropq >= 0) {
34333 + AuDbg("%d\n", err);
34338 + err = au_wbr_nonopq(dentry, err);
34340 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34343 + AuDbg("%d\n", err);
34347 +/* ---------------------------------------------------------------------- */
34350 +static int au_wbr_create_init_rr(struct super_block *sb)
34354 + err = au_wbr_bu(sb, au_sbbot(sb));
34355 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34358 + AuDbg("b%d\n", err);
34362 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34366 + aufs_bindex_t bindex, bbot;
34367 + struct super_block *sb;
34370 + err = au_wbr_create_exp(dentry);
34374 + sb = dentry->d_sb;
34375 + next = &au_sbi(sb)->si_wbr_rr_next;
34376 + bbot = au_sbbot(sb);
34378 + for (bindex = 0; bindex <= bbot; bindex++) {
34379 + if (!au_ftest_wbr(flags, DIR)) {
34380 + err = atomic_dec_return(next) + 1;
34381 + /* modulo for 0 is meaningless */
34382 + if (unlikely(!err))
34383 + err = atomic_dec_return(next) + 1;
34385 + err = atomic_read(next);
34386 + AuDbg("%d\n", err);
34389 + AuDbg("%d\n", err);
34390 + if (!au_br_rdonly(au_sbr(sb, err)))
34396 + err = au_wbr_nonopq(dentry, err);
34399 + AuDbg("%d\n", err);
34403 +/* ---------------------------------------------------------------------- */
34405 +/* most free space */
34406 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34408 + struct super_block *sb;
34409 + struct au_branch *br;
34410 + struct au_wbr_mfs *mfs;
34411 + struct dentry *h_parent;
34412 + aufs_bindex_t bindex, bbot;
34414 + unsigned long long b, bavail;
34415 + struct path h_path;
34416 + /* reduce the stack usage */
34417 + struct kstatfs *st;
34419 + st = kmalloc(sizeof(*st), GFP_NOFS);
34420 + if (unlikely(!st)) {
34421 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34426 + sb = dentry->d_sb;
34427 + mfs = &au_sbi(sb)->si_wbr_mfs;
34428 + MtxMustLock(&mfs->mfs_lock);
34429 + mfs->mfs_bindex = -EROFS;
34430 + mfs->mfsrr_bytes = 0;
34433 + bbot = au_sbbot(sb);
34435 + bindex = au_dbtop(parent);
34436 + bbot = au_dbtaildir(parent);
34439 + for (; bindex <= bbot; bindex++) {
34441 + h_parent = au_h_dptr(parent, bindex);
34442 + if (!h_parent || d_is_negative(h_parent))
34445 + br = au_sbr(sb, bindex);
34446 + if (au_br_rdonly(br))
34449 + /* sb->s_root for NFS is unreliable */
34450 + h_path.mnt = au_br_mnt(br);
34451 + h_path.dentry = h_path.mnt->mnt_root;
34452 + err = vfs_statfs(&h_path, st);
34453 + if (unlikely(err)) {
34454 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34458 + /* when the available size is equal, select the lower one */
34459 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34460 + || sizeof(b) < sizeof(st->f_bsize));
34461 + b = st->f_bavail * st->f_bsize;
34462 + br->br_wbr->wbr_bytes = b;
34463 + if (b >= bavail) {
34465 + mfs->mfs_bindex = bindex;
34466 + mfs->mfs_jiffy = jiffies;
34470 + mfs->mfsrr_bytes = bavail;
34471 + AuDbg("b%d\n", mfs->mfs_bindex);
34472 + au_kfree_rcu(st);
34475 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34478 + struct dentry *parent;
34479 + struct super_block *sb;
34480 + struct au_wbr_mfs *mfs;
34482 + err = au_wbr_create_exp(dentry);
34486 + sb = dentry->d_sb;
34488 + if (au_ftest_wbr(flags, PARENT))
34489 + parent = dget_parent(dentry);
34490 + mfs = &au_sbi(sb)->si_wbr_mfs;
34491 + mutex_lock(&mfs->mfs_lock);
34492 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34493 + || mfs->mfs_bindex < 0
34494 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34495 + au_mfs(dentry, parent);
34496 + mutex_unlock(&mfs->mfs_lock);
34497 + err = mfs->mfs_bindex;
34501 + err = au_wbr_nonopq(dentry, err);
34504 + AuDbg("b%d\n", err);
34508 +static int au_wbr_create_init_mfs(struct super_block *sb)
34510 + struct au_wbr_mfs *mfs;
34512 + mfs = &au_sbi(sb)->si_wbr_mfs;
34513 + mutex_init(&mfs->mfs_lock);
34514 + mfs->mfs_jiffy = 0;
34515 + mfs->mfs_bindex = -EROFS;
34520 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34522 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34526 +/* ---------------------------------------------------------------------- */
34528 +/* top down regardless parent, and then mfs */
34529 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34530 + unsigned int flags __maybe_unused)
34533 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34534 + unsigned long long watermark;
34535 + struct super_block *sb;
34536 + struct au_wbr_mfs *mfs;
34537 + struct au_branch *br;
34538 + struct dentry *parent;
34540 + sb = dentry->d_sb;
34541 + mfs = &au_sbi(sb)->si_wbr_mfs;
34542 + mutex_lock(&mfs->mfs_lock);
34543 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34544 + || mfs->mfs_bindex < 0)
34545 + au_mfs(dentry, /*parent*/NULL);
34546 + watermark = mfs->mfsrr_watermark;
34547 + bmfs = mfs->mfs_bindex;
34548 + mutex_unlock(&mfs->mfs_lock);
34550 + /* another style of au_wbr_create_exp() */
34551 + bwh = au_dbwh(dentry);
34552 + parent = dget_parent(dentry);
34553 + btail = au_dbtaildir(parent);
34554 + if (bwh >= 0 && bwh < btail)
34557 + err = au_wbr_nonopq(dentry, btail);
34558 + if (unlikely(err < 0))
34562 + for (bindex = 0; bindex <= btail; bindex++) {
34563 + br = au_sbr(sb, bindex);
34564 + if (au_br_rdonly(br))
34566 + if (br->br_wbr->wbr_bytes > watermark) {
34577 + AuDbg("b%d\n", err);
34581 +/* ---------------------------------------------------------------------- */
34583 +/* most free space and then round robin */
34584 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34587 + struct au_wbr_mfs *mfs;
34589 + err = au_wbr_create_mfs(dentry, flags);
34591 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34592 + mutex_lock(&mfs->mfs_lock);
34593 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34594 + err = au_wbr_create_rr(dentry, flags);
34595 + mutex_unlock(&mfs->mfs_lock);
34598 + AuDbg("b%d\n", err);
34602 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34606 + au_wbr_create_init_mfs(sb); /* ignore */
34607 + err = au_wbr_create_init_rr(sb);
34612 +/* ---------------------------------------------------------------------- */
34614 +/* top down parent and most free space */
34615 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34618 + unsigned long long b;
34619 + aufs_bindex_t bindex, btop, bbot;
34620 + struct super_block *sb;
34621 + struct dentry *parent, *h_parent;
34622 + struct au_branch *br;
34624 + err = au_wbr_create_tdp(dentry, flags);
34625 + if (unlikely(err < 0))
34627 + parent = dget_parent(dentry);
34628 + btop = au_dbtop(parent);
34629 + bbot = au_dbtaildir(parent);
34630 + if (btop == bbot)
34631 + goto out_parent; /* success */
34633 + e2 = au_wbr_create_mfs(dentry, flags);
34635 + goto out_parent; /* success */
34637 + /* when the available size is equal, select upper one */
34638 + sb = dentry->d_sb;
34639 + br = au_sbr(sb, err);
34640 + b = br->br_wbr->wbr_bytes;
34641 + AuDbg("b%d, %llu\n", err, b);
34643 + for (bindex = btop; bindex <= bbot; bindex++) {
34644 + h_parent = au_h_dptr(parent, bindex);
34645 + if (!h_parent || d_is_negative(h_parent))
34648 + br = au_sbr(sb, bindex);
34649 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34650 + b = br->br_wbr->wbr_bytes;
34652 + AuDbg("b%d, %llu\n", err, b);
34657 + err = au_wbr_nonopq(dentry, err);
34662 + AuDbg("b%d\n", err);
34666 +/* ---------------------------------------------------------------------- */
34669 + * - top down parent
34670 + * - most free space with parent
34671 + * - most free space round-robin regardless parent
34673 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34676 + unsigned long long watermark;
34677 + struct super_block *sb;
34678 + struct au_branch *br;
34679 + struct au_wbr_mfs *mfs;
34681 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34682 + if (unlikely(err < 0))
34685 + sb = dentry->d_sb;
34686 + br = au_sbr(sb, err);
34687 + mfs = &au_sbi(sb)->si_wbr_mfs;
34688 + mutex_lock(&mfs->mfs_lock);
34689 + watermark = mfs->mfsrr_watermark;
34690 + mutex_unlock(&mfs->mfs_lock);
34691 + if (br->br_wbr->wbr_bytes < watermark)
34692 + /* regardless the parent dir */
34693 + err = au_wbr_create_mfsrr(dentry, flags);
34696 + AuDbg("b%d\n", err);
34700 +/* ---------------------------------------------------------------------- */
34702 +/* policies for copyup */
34704 +/* top down parent */
34705 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34707 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34710 +/* bottom up parent */
34711 +static int au_wbr_copyup_bup(struct dentry *dentry)
34714 + aufs_bindex_t bindex, btop;
34715 + struct dentry *parent, *h_parent;
34716 + struct super_block *sb;
34719 + sb = dentry->d_sb;
34720 + parent = dget_parent(dentry);
34721 + btop = au_dbtop(parent);
34722 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34723 + h_parent = au_h_dptr(parent, bindex);
34724 + if (!h_parent || d_is_negative(h_parent))
34727 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34734 + /* bottom up here */
34735 + if (unlikely(err < 0))
34736 + err = au_wbr_bu(sb, btop - 1);
34738 + AuDbg("b%d\n", err);
34743 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34747 + err = au_wbr_bu(dentry->d_sb, btop);
34748 + AuDbg("b%d\n", err);
34750 + err = au_wbr_nonopq(dentry, err);
34752 + AuDbg("b%d\n", err);
34756 +static int au_wbr_copyup_bu(struct dentry *dentry)
34759 + aufs_bindex_t btop;
34761 + btop = au_dbtop(dentry);
34762 + err = au_wbr_do_copyup_bu(dentry, btop);
34766 +/* ---------------------------------------------------------------------- */
34768 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34769 + [AuWbrCopyup_TDP] = {
34770 + .copyup = au_wbr_copyup_tdp
34772 + [AuWbrCopyup_BUP] = {
34773 + .copyup = au_wbr_copyup_bup
34775 + [AuWbrCopyup_BU] = {
34776 + .copyup = au_wbr_copyup_bu
34780 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34781 + [AuWbrCreate_TDP] = {
34782 + .create = au_wbr_create_tdp
34784 + [AuWbrCreate_RR] = {
34785 + .create = au_wbr_create_rr,
34786 + .init = au_wbr_create_init_rr
34788 + [AuWbrCreate_MFS] = {
34789 + .create = au_wbr_create_mfs,
34790 + .init = au_wbr_create_init_mfs,
34791 + .fin = au_wbr_create_fin_mfs
34793 + [AuWbrCreate_MFSV] = {
34794 + .create = au_wbr_create_mfs,
34795 + .init = au_wbr_create_init_mfs,
34796 + .fin = au_wbr_create_fin_mfs
34798 + [AuWbrCreate_MFSRR] = {
34799 + .create = au_wbr_create_mfsrr,
34800 + .init = au_wbr_create_init_mfsrr,
34801 + .fin = au_wbr_create_fin_mfs
34803 + [AuWbrCreate_MFSRRV] = {
34804 + .create = au_wbr_create_mfsrr,
34805 + .init = au_wbr_create_init_mfsrr,
34806 + .fin = au_wbr_create_fin_mfs
34808 + [AuWbrCreate_TDMFS] = {
34809 + .create = au_wbr_create_tdmfs,
34810 + .init = au_wbr_create_init_mfs,
34811 + .fin = au_wbr_create_fin_mfs
34813 + [AuWbrCreate_TDMFSV] = {
34814 + .create = au_wbr_create_tdmfs,
34815 + .init = au_wbr_create_init_mfs,
34816 + .fin = au_wbr_create_fin_mfs
34818 + [AuWbrCreate_PMFS] = {
34819 + .create = au_wbr_create_pmfs,
34820 + .init = au_wbr_create_init_mfs,
34821 + .fin = au_wbr_create_fin_mfs
34823 + [AuWbrCreate_PMFSV] = {
34824 + .create = au_wbr_create_pmfs,
34825 + .init = au_wbr_create_init_mfs,
34826 + .fin = au_wbr_create_fin_mfs
34828 + [AuWbrCreate_PMFSRR] = {
34829 + .create = au_wbr_create_pmfsrr,
34830 + .init = au_wbr_create_init_mfsrr,
34831 + .fin = au_wbr_create_fin_mfs
34833 + [AuWbrCreate_PMFSRRV] = {
34834 + .create = au_wbr_create_pmfsrr,
34835 + .init = au_wbr_create_init_mfsrr,
34836 + .fin = au_wbr_create_fin_mfs
34839 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34840 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34841 +++ linux/fs/aufs/whout.c 2019-07-11 15:42:14.475571481 +0200
34843 +// SPDX-License-Identifier: GPL-2.0
34845 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34847 + * This program, aufs is free software; you can redistribute it and/or modify
34848 + * it under the terms of the GNU General Public License as published by
34849 + * the Free Software Foundation; either version 2 of the License, or
34850 + * (at your option) any later version.
34852 + * This program is distributed in the hope that it will be useful,
34853 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34855 + * GNU General Public License for more details.
34857 + * You should have received a copy of the GNU General Public License
34858 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34862 + * whiteout for logical deletion and opaque directory
34867 +#define WH_MASK 0444
34870 + * If a directory contains this file, then it is opaque. We start with the
34871 + * .wh. flag so that it is blocked by lookup.
34873 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34874 + sizeof(AUFS_WH_DIROPQ) - 1);
34877 + * generate whiteout name, which is NOT terminated by NULL.
34878 + * @name: original d_name.name
34879 + * @len: original d_name.len
34880 + * @wh: whiteout qstr
34881 + * returns zero when succeeds, otherwise error.
34882 + * succeeded value as wh->name should be freed by kfree().
34884 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34888 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34889 + return -ENAMETOOLONG;
34891 + wh->len = name->len + AUFS_WH_PFX_LEN;
34892 + p = kmalloc(wh->len, GFP_NOFS);
34895 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34896 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34903 +/* ---------------------------------------------------------------------- */
34906 + * test if the @wh_name exists under @h_parent.
34907 + * @try_sio specifies the necessary of super-io.
34909 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34912 + struct dentry *wh_dentry;
34915 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34917 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34918 + err = PTR_ERR(wh_dentry);
34919 + if (IS_ERR(wh_dentry)) {
34920 + if (err == -ENAMETOOLONG)
34926 + if (d_is_negative(wh_dentry))
34927 + goto out_wh; /* success */
34930 + if (d_is_reg(wh_dentry))
34931 + goto out_wh; /* success */
34934 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34935 + wh_dentry, d_inode(wh_dentry)->i_mode);
34944 + * test if the @h_dentry sets opaque or not.
34946 +int au_diropq_test(struct dentry *h_dentry)
34949 + struct inode *h_dir;
34951 + h_dir = d_inode(h_dentry);
34952 + err = au_wh_test(h_dentry, &diropq_name,
34953 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34958 + * returns a negative dentry whose name is unique and temporary.
34960 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34961 + struct qstr *prefix)
34963 + struct dentry *dentry;
34965 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34967 + /* strict atomic_t is unnecessary here */
34968 + static unsigned short cnt;
34971 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34974 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34975 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34976 + dentry = ERR_PTR(-ENAMETOOLONG);
34977 + if (unlikely(qs.len > NAME_MAX))
34979 + dentry = ERR_PTR(-ENOMEM);
34980 + name = kmalloc(qs.len + 1, GFP_NOFS);
34981 + if (unlikely(!name))
34985 + /* doubly whiteout-ed */
34986 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34987 + p = name + AUFS_WH_PFX_LEN * 2;
34988 + memcpy(p, prefix->name, prefix->len);
34989 + p += prefix->len;
34991 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34994 + for (i = 0; i < 3; i++) {
34995 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34996 + dentry = au_sio_lkup_one(&qs, h_parent);
34997 + if (IS_ERR(dentry) || d_is_negative(dentry))
35001 + /* pr_warn("could not get random name\n"); */
35002 + dentry = ERR_PTR(-EEXIST);
35003 + AuDbg("%.*s\n", AuLNPair(&qs));
35007 + if (name != defname)
35008 + au_kfree_try_rcu(name);
35010 + AuTraceErrPtr(dentry);
35015 + * rename the @h_dentry on @br to the whiteouted temporary name.
35017 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35020 + struct path h_path = {
35021 + .mnt = au_br_mnt(br)
35023 + struct inode *h_dir, *delegated;
35024 + struct dentry *h_parent;
35026 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35027 + h_dir = d_inode(h_parent);
35028 + IMustLock(h_dir);
35030 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35031 + err = PTR_ERR(h_path.dentry);
35032 + if (IS_ERR(h_path.dentry))
35035 + /* under the same dir, no need to lock_rename() */
35036 + delegated = NULL;
35037 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35040 + if (unlikely(err == -EWOULDBLOCK)) {
35041 + pr_warn("cannot retry for NFSv4 delegation"
35042 + " for an internal rename\n");
35045 + dput(h_path.dentry);
35052 +/* ---------------------------------------------------------------------- */
35054 + * functions for removing a whiteout
35057 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35060 + struct inode *delegated;
35063 + * forces superio when the dir has a sticky bit.
35064 + * this may be a violation of unix fs semantics.
35066 + force = (h_dir->i_mode & S_ISVTX)
35067 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35068 + delegated = NULL;
35069 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35070 + if (unlikely(err == -EWOULDBLOCK)) {
35071 + pr_warn("cannot retry for NFSv4 delegation"
35072 + " for an internal unlink\n");
35078 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35079 + struct dentry *dentry)
35083 + err = do_unlink_wh(h_dir, h_path);
35084 + if (!err && dentry)
35085 + au_set_dbwh(dentry, -1);
35090 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35091 + struct au_branch *br)
35094 + struct path h_path = {
35095 + .mnt = au_br_mnt(br)
35099 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35100 + if (IS_ERR(h_path.dentry))
35101 + err = PTR_ERR(h_path.dentry);
35103 + if (d_is_reg(h_path.dentry))
35104 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35105 + dput(h_path.dentry);
35111 +/* ---------------------------------------------------------------------- */
35113 + * initialize/clean whiteout for a branch
35116 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35120 + struct inode *delegated;
35122 + if (d_is_negative(whpath->dentry))
35126 + err = vfsub_rmdir(h_dir, whpath);
35128 + delegated = NULL;
35129 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35130 + if (unlikely(err == -EWOULDBLOCK)) {
35131 + pr_warn("cannot retry for NFSv4 delegation"
35132 + " for an internal unlink\n");
35136 + if (unlikely(err))
35137 + pr_warn("failed removing %pd (%d), ignored.\n",
35138 + whpath->dentry, err);
35141 +static int test_linkable(struct dentry *h_root)
35143 + struct inode *h_dir = d_inode(h_root);
35145 + if (h_dir->i_op->link)
35148 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35149 + h_root, au_sbtype(h_root->d_sb));
35153 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35154 +static int au_whdir(struct inode *h_dir, struct path *path)
35159 + if (d_is_negative(path->dentry)) {
35162 + if (au_test_nfs(path->dentry->d_sb))
35164 + err = vfsub_mkdir(h_dir, path, mode);
35165 + } else if (d_is_dir(path->dentry))
35168 + pr_err("unknown %pd exists\n", path->dentry);
35173 +struct au_wh_base {
35174 + const struct qstr *name;
35175 + struct dentry *dentry;
35178 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35179 + struct path *h_path)
35181 + h_path->dentry = base[AuBrWh_BASE].dentry;
35182 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35183 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35184 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35185 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35186 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35190 + * returns tri-state,
35191 + * minus: error, caller should print the message
35193 + * plus: error, caller should NOT print the message
35195 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35196 + int do_plink, struct au_wh_base base[],
35197 + struct path *h_path)
35200 + struct inode *h_dir;
35202 + h_dir = d_inode(h_root);
35203 + h_path->dentry = base[AuBrWh_BASE].dentry;
35204 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35205 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35207 + err = test_linkable(h_root);
35208 + if (unlikely(err)) {
35213 + err = au_whdir(h_dir, h_path);
35214 + if (unlikely(err))
35216 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35218 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35219 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35220 + err = au_whdir(h_dir, h_path);
35221 + if (unlikely(err))
35223 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35230 + * for the moment, aufs supports the branch filesystem which does not support
35231 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35232 + * copyup failed. finally, such filesystem will not be used as the writable
35235 + * returns tri-state, see above.
35237 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35238 + int do_plink, struct au_wh_base base[],
35239 + struct path *h_path)
35242 + struct inode *h_dir;
35244 + WbrWhMustWriteLock(wbr);
35246 + err = test_linkable(h_root);
35247 + if (unlikely(err)) {
35253 + * todo: should this create be done in /sbin/mount.aufs helper?
35256 + h_dir = d_inode(h_root);
35257 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35258 + h_path->dentry = base[AuBrWh_BASE].dentry;
35259 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35260 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35263 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35264 + if (unlikely(err))
35267 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35269 + err = au_whdir(h_dir, h_path);
35270 + if (unlikely(err))
35272 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35274 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35275 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35277 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35278 + err = au_whdir(h_dir, h_path);
35279 + if (unlikely(err))
35281 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35288 + * initialize the whiteout base file/dir for @br.
35290 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35293 + const unsigned char do_plink
35294 + = !!au_opt_test(au_mntflags(sb), PLINK);
35295 + struct inode *h_dir;
35296 + struct path path = br->br_path;
35297 + struct dentry *h_root = path.dentry;
35298 + struct au_wbr *wbr = br->br_wbr;
35299 + static const struct qstr base_name[] = {
35300 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35301 + sizeof(AUFS_BASE_NAME) - 1),
35302 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35303 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35304 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35305 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35307 + struct au_wh_base base[] = {
35308 + [AuBrWh_BASE] = {
35309 + .name = base_name + AuBrWh_BASE,
35312 + [AuBrWh_PLINK] = {
35313 + .name = base_name + AuBrWh_PLINK,
35316 + [AuBrWh_ORPH] = {
35317 + .name = base_name + AuBrWh_ORPH,
35323 + WbrWhMustWriteLock(wbr);
35325 + for (i = 0; i < AuBrWh_Last; i++) {
35326 + /* doubly whiteouted */
35327 + struct dentry *d;
35329 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35330 + err = PTR_ERR(d);
35334 + base[i].dentry = d;
35336 + && wbr->wbr_wh[i]
35337 + && wbr->wbr_wh[i] != base[i].dentry);
35341 + for (i = 0; i < AuBrWh_Last; i++) {
35342 + dput(wbr->wbr_wh[i]);
35343 + wbr->wbr_wh[i] = NULL;
35347 + if (!au_br_writable(br->br_perm)) {
35348 + h_dir = d_inode(h_root);
35349 + au_wh_init_ro(h_dir, base, &path);
35350 + } else if (!au_br_wh_linkable(br->br_perm)) {
35351 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35357 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35363 + goto out; /* success */
35366 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35367 + err, h_root, au_sbtype(h_root->d_sb));
35369 + for (i = 0; i < AuBrWh_Last; i++)
35370 + dput(base[i].dentry);
35374 +/* ---------------------------------------------------------------------- */
35376 + * whiteouts are all hard-linked usually.
35377 + * when its link count reaches a ceiling, we create a new whiteout base
35378 + * asynchronously.
35381 +struct reinit_br_wh {
35382 + struct super_block *sb;
35383 + struct au_branch *br;
35386 +static void reinit_br_wh(void *arg)
35389 + aufs_bindex_t bindex;
35390 + struct path h_path;
35391 + struct reinit_br_wh *a = arg;
35392 + struct au_wbr *wbr;
35393 + struct inode *dir, *delegated;
35394 + struct dentry *h_root;
35395 + struct au_hinode *hdir;
35398 + wbr = a->br->br_wbr;
35399 + /* big aufs lock */
35400 + si_noflush_write_lock(a->sb);
35401 + if (!au_br_writable(a->br->br_perm))
35403 + bindex = au_br_index(a->sb, a->br->br_id);
35404 + if (unlikely(bindex < 0))
35407 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35408 + dir = d_inode(a->sb->s_root);
35409 + hdir = au_hi(dir, bindex);
35410 + h_root = au_h_dptr(a->sb->s_root, bindex);
35411 + AuDebugOn(h_root != au_br_dentry(a->br));
35413 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35414 + wbr_wh_write_lock(wbr);
35415 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35418 + h_path.dentry = wbr->wbr_whbase;
35419 + h_path.mnt = au_br_mnt(a->br);
35420 + delegated = NULL;
35421 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35423 + if (unlikely(err == -EWOULDBLOCK)) {
35424 + pr_warn("cannot retry for NFSv4 delegation"
35425 + " for an internal unlink\n");
35429 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35432 + dput(wbr->wbr_whbase);
35433 + wbr->wbr_whbase = NULL;
35435 + err = au_wh_init(a->br, a->sb);
35436 + wbr_wh_write_unlock(wbr);
35437 + au_hn_inode_unlock(hdir);
35438 + di_read_unlock(a->sb->s_root, AuLock_IR);
35440 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35444 + atomic_dec(&wbr->wbr_wh_running);
35445 + au_lcnt_dec(&a->br->br_count);
35446 + si_write_unlock(a->sb);
35447 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35449 + if (unlikely(err))
35450 + AuIOErr("err %d\n", err);
35453 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35455 + int do_dec, wkq_err;
35456 + struct reinit_br_wh *arg;
35459 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35462 + /* ignore ENOMEM */
35463 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35466 + * dec(wh_running), kfree(arg) and dec(br_count)
35467 + * in reinit function
35471 + au_lcnt_inc(&br->br_count);
35472 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35473 + if (unlikely(wkq_err)) {
35474 + atomic_dec(&br->br_wbr->wbr_wh_running);
35475 + au_lcnt_dec(&br->br_count);
35476 + au_kfree_rcu(arg);
35483 + atomic_dec(&br->br_wbr->wbr_wh_running);
35486 +/* ---------------------------------------------------------------------- */
35489 + * create the whiteout @wh.
35491 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35492 + struct dentry *wh)
35495 + struct path h_path = {
35498 + struct au_branch *br;
35499 + struct au_wbr *wbr;
35500 + struct dentry *h_parent;
35501 + struct inode *h_dir, *delegated;
35503 + h_parent = wh->d_parent; /* dir inode is locked */
35504 + h_dir = d_inode(h_parent);
35505 + IMustLock(h_dir);
35507 + br = au_sbr(sb, bindex);
35508 + h_path.mnt = au_br_mnt(br);
35509 + wbr = br->br_wbr;
35510 + wbr_wh_read_lock(wbr);
35511 + if (wbr->wbr_whbase) {
35512 + delegated = NULL;
35513 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35514 + if (unlikely(err == -EWOULDBLOCK)) {
35515 + pr_warn("cannot retry for NFSv4 delegation"
35516 + " for an internal link\n");
35519 + if (!err || err != -EMLINK)
35522 + /* link count full. re-initialize br_whbase. */
35523 + kick_reinit_br_wh(sb, br);
35526 + /* return this error in this context */
35527 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35529 + au_fhsm_wrote(sb, bindex, /*force*/0);
35532 + wbr_wh_read_unlock(wbr);
35536 +/* ---------------------------------------------------------------------- */
35539 + * create or remove the diropq.
35541 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35542 + unsigned int flags)
35544 + struct dentry *opq_dentry, *h_dentry;
35545 + struct super_block *sb;
35546 + struct au_branch *br;
35549 + sb = dentry->d_sb;
35550 + br = au_sbr(sb, bindex);
35551 + h_dentry = au_h_dptr(dentry, bindex);
35552 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35553 + if (IS_ERR(opq_dentry))
35556 + if (au_ftest_diropq(flags, CREATE)) {
35557 + err = link_or_create_wh(sb, bindex, opq_dentry);
35559 + au_set_dbdiropq(dentry, bindex);
35560 + goto out; /* success */
35563 + struct path tmp = {
35564 + .dentry = opq_dentry,
35565 + .mnt = au_br_mnt(br)
35567 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35569 + au_set_dbdiropq(dentry, -1);
35571 + dput(opq_dentry);
35572 + opq_dentry = ERR_PTR(err);
35575 + return opq_dentry;
35578 +struct do_diropq_args {
35579 + struct dentry **errp;
35580 + struct dentry *dentry;
35581 + aufs_bindex_t bindex;
35582 + unsigned int flags;
35585 +static void call_do_diropq(void *args)
35587 + struct do_diropq_args *a = args;
35588 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35591 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35592 + unsigned int flags)
35594 + struct dentry *diropq, *h_dentry;
35596 + h_dentry = au_h_dptr(dentry, bindex);
35597 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35598 + diropq = do_diropq(dentry, bindex, flags);
35601 + struct do_diropq_args args = {
35603 + .dentry = dentry,
35604 + .bindex = bindex,
35608 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35609 + if (unlikely(wkq_err))
35610 + diropq = ERR_PTR(wkq_err);
35616 +/* ---------------------------------------------------------------------- */
35619 + * lookup whiteout dentry.
35620 + * @h_parent: lower parent dentry which must exist and be locked
35621 + * @base_name: name of dentry which will be whiteouted
35622 + * returns dentry for whiteout.
35624 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35625 + struct au_branch *br)
35628 + struct qstr wh_name;
35629 + struct dentry *wh_dentry;
35631 + err = au_wh_name_alloc(&wh_name, base_name);
35632 + wh_dentry = ERR_PTR(err);
35634 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35635 + au_kfree_try_rcu(wh_name.name);
35637 + return wh_dentry;
35641 + * link/create a whiteout for @dentry on @bindex.
35643 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35644 + struct dentry *h_parent)
35646 + struct dentry *wh_dentry;
35647 + struct super_block *sb;
35650 + sb = dentry->d_sb;
35651 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35652 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35653 + err = link_or_create_wh(sb, bindex, wh_dentry);
35655 + au_set_dbwh(dentry, bindex);
35656 + au_fhsm_wrote(sb, bindex, /*force*/0);
35659 + wh_dentry = ERR_PTR(err);
35663 + return wh_dentry;
35666 +/* ---------------------------------------------------------------------- */
35668 +/* Delete all whiteouts in this directory on branch bindex. */
35669 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35670 + aufs_bindex_t bindex, struct au_branch *br)
35673 + unsigned long ul, n;
35674 + struct qstr wh_name;
35676 + struct hlist_head *head;
35677 + struct au_vdir_wh *pos;
35678 + struct au_vdir_destr *str;
35681 + p = (void *)__get_free_page(GFP_NOFS);
35682 + wh_name.name = p;
35683 + if (unlikely(!wh_name.name))
35687 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35688 + p += AUFS_WH_PFX_LEN;
35689 + n = whlist->nh_num;
35690 + head = whlist->nh_head;
35691 + for (ul = 0; !err && ul < n; ul++, head++) {
35692 + hlist_for_each_entry(pos, head, wh_hash) {
35693 + if (pos->wh_bindex != bindex)
35696 + str = &pos->wh_str;
35697 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35698 + memcpy(p, str->name, str->len);
35699 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35700 + err = unlink_wh_name(h_dentry, &wh_name, br);
35705 + AuIOErr("whiteout name too long %.*s\n",
35706 + str->len, str->name);
35711 + free_page((unsigned long)wh_name.name);
35717 +struct del_wh_children_args {
35719 + struct dentry *h_dentry;
35720 + struct au_nhash *whlist;
35721 + aufs_bindex_t bindex;
35722 + struct au_branch *br;
35725 +static void call_del_wh_children(void *args)
35727 + struct del_wh_children_args *a = args;
35728 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35731 +/* ---------------------------------------------------------------------- */
35733 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35735 + struct au_whtmp_rmdir *whtmp;
35737 + unsigned int rdhash;
35739 + SiMustAnyLock(sb);
35741 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35742 + if (unlikely(!whtmp)) {
35743 + whtmp = ERR_PTR(-ENOMEM);
35747 + /* no estimation for dir size */
35748 + rdhash = au_sbi(sb)->si_rdhash;
35750 + rdhash = AUFS_RDHASH_DEF;
35751 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35752 + if (unlikely(err)) {
35753 + au_kfree_rcu(whtmp);
35754 + whtmp = ERR_PTR(err);
35761 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35764 + au_lcnt_dec(&whtmp->br->br_count);
35765 + dput(whtmp->wh_dentry);
35766 + iput(whtmp->dir);
35767 + au_nhash_wh_free(&whtmp->whlist);
35768 + au_kfree_rcu(whtmp);
35772 + * rmdir the whiteouted temporary named dir @h_dentry.
35773 + * @whlist: whiteouted children.
35775 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35776 + struct dentry *wh_dentry, struct au_nhash *whlist)
35779 + unsigned int h_nlink;
35780 + struct path h_tmp;
35781 + struct inode *wh_inode, *h_dir;
35782 + struct au_branch *br;
35784 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35785 + IMustLock(h_dir);
35787 + br = au_sbr(dir->i_sb, bindex);
35788 + wh_inode = d_inode(wh_dentry);
35789 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35792 + * someone else might change some whiteouts while we were sleeping.
35793 + * it means this whlist may have an obsoleted entry.
35795 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35796 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35799 + struct del_wh_children_args args = {
35801 + .h_dentry = wh_dentry,
35802 + .whlist = whlist,
35803 + .bindex = bindex,
35807 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35808 + if (unlikely(wkq_err))
35811 + inode_unlock(wh_inode);
35814 + h_tmp.dentry = wh_dentry;
35815 + h_tmp.mnt = au_br_mnt(br);
35816 + h_nlink = h_dir->i_nlink;
35817 + err = vfsub_rmdir(h_dir, &h_tmp);
35818 + /* some fs doesn't change the parent nlink in some cases */
35819 + h_nlink -= h_dir->i_nlink;
35823 + if (au_ibtop(dir) == bindex) {
35824 + /* todo: dir->i_mutex is necessary */
35825 + au_cpup_attr_timesizes(dir);
35827 + vfsub_drop_nlink(dir);
35829 + return 0; /* success */
35832 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35836 +static void call_rmdir_whtmp(void *args)
35839 + aufs_bindex_t bindex;
35840 + struct au_whtmp_rmdir *a = args;
35841 + struct super_block *sb;
35842 + struct dentry *h_parent;
35843 + struct inode *h_dir;
35844 + struct au_hinode *hdir;
35846 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35847 + /* inode_lock(a->dir); */
35849 + sb = a->dir->i_sb;
35850 + si_read_lock(sb, !AuLock_FLUSH);
35851 + if (!au_br_writable(a->br->br_perm))
35853 + bindex = au_br_index(sb, a->br->br_id);
35854 + if (unlikely(bindex < 0))
35858 + ii_write_lock_parent(a->dir);
35859 + h_parent = dget_parent(a->wh_dentry);
35860 + h_dir = d_inode(h_parent);
35861 + hdir = au_hi(a->dir, bindex);
35862 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35863 + if (unlikely(err))
35865 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35866 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35869 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35870 + au_hn_inode_unlock(hdir);
35871 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35875 + ii_write_unlock(a->dir);
35877 + /* inode_unlock(a->dir); */
35878 + au_whtmp_rmdir_free(a);
35879 + si_read_unlock(sb);
35880 + au_nwt_done(&au_sbi(sb)->si_nowait);
35881 + if (unlikely(err))
35882 + AuIOErr("err %d\n", err);
35885 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35886 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35889 + struct super_block *sb;
35893 + /* all post-process will be done in do_rmdir_whtmp(). */
35895 + args->dir = au_igrab(dir);
35896 + args->br = au_sbr(sb, bindex);
35897 + au_lcnt_inc(&args->br->br_count);
35898 + args->wh_dentry = dget(wh_dentry);
35899 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35900 + if (unlikely(wkq_err)) {
35901 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35902 + au_whtmp_rmdir_free(args);
35905 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35906 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35907 +++ linux/fs/aufs/whout.h 2019-07-11 15:42:14.475571481 +0200
35909 +/* SPDX-License-Identifier: GPL-2.0 */
35911 + * Copyright (C) 2005-2019 Junjiro R. Okajima
35913 + * This program, aufs is free software; you can redistribute it and/or modify
35914 + * it under the terms of the GNU General Public License as published by
35915 + * the Free Software Foundation; either version 2 of the License, or
35916 + * (at your option) any later version.
35918 + * This program is distributed in the hope that it will be useful,
35919 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35920 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35921 + * GNU General Public License for more details.
35923 + * You should have received a copy of the GNU General Public License
35924 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35928 + * whiteout for logical deletion and opaque directory
35931 +#ifndef __AUFS_WHOUT_H__
35932 +#define __AUFS_WHOUT_H__
35939 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35940 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35941 +int au_diropq_test(struct dentry *h_dentry);
35943 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35944 + struct qstr *prefix);
35945 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35946 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35947 + struct dentry *dentry);
35948 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35950 +/* diropq flags */
35951 +#define AuDiropq_CREATE 1
35952 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35953 +#define au_fset_diropq(flags, name) \
35954 + do { (flags) |= AuDiropq_##name; } while (0)
35955 +#define au_fclr_diropq(flags, name) \
35956 + do { (flags) &= ~AuDiropq_##name; } while (0)
35958 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35959 + unsigned int flags);
35960 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35961 + struct au_branch *br);
35962 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35963 + struct dentry *h_parent);
35965 +/* real rmdir for the whiteout-ed dir */
35966 +struct au_whtmp_rmdir {
35967 + struct inode *dir;
35968 + struct au_branch *br;
35969 + struct dentry *wh_dentry;
35970 + struct au_nhash whlist;
35973 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35974 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35975 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35976 + struct dentry *wh_dentry, struct au_nhash *whlist);
35977 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35978 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35980 +/* ---------------------------------------------------------------------- */
35982 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35983 + aufs_bindex_t bindex)
35985 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35988 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35990 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35993 +#endif /* __KERNEL__ */
35994 +#endif /* __AUFS_WHOUT_H__ */
35995 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35996 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35997 +++ linux/fs/aufs/wkq.c 2019-07-11 15:42:14.475571481 +0200
35999 +// SPDX-License-Identifier: GPL-2.0
36001 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36003 + * This program, aufs is free software; you can redistribute it and/or modify
36004 + * it under the terms of the GNU General Public License as published by
36005 + * the Free Software Foundation; either version 2 of the License, or
36006 + * (at your option) any later version.
36008 + * This program is distributed in the hope that it will be useful,
36009 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36010 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36011 + * GNU General Public License for more details.
36013 + * You should have received a copy of the GNU General Public License
36014 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36018 + * workqueue for asynchronous/super-io operations
36019 + * todo: try new credential scheme
36022 +#include <linux/module.h>
36025 +/* internal workqueue named AUFS_WKQ_NAME */
36027 +static struct workqueue_struct *au_wkq;
36029 +struct au_wkinfo {
36030 + struct work_struct wk;
36031 + struct kobject *kobj;
36033 + unsigned int flags; /* see wkq.h */
36035 + au_wkq_func_t func;
36038 +#ifdef CONFIG_LOCKDEP
36040 + struct held_lock **hlock;
36043 + struct completion *comp;
36046 +/* ---------------------------------------------------------------------- */
36048 + * Aufs passes some operations to the workqueue such as the internal copyup.
36049 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36050 + * job run by workqueue depends upon the locks acquired in the other task.
36051 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36052 + * information too. And the job in the workqueue restores the info in order to
36053 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36054 + * correctly and expectedly.
36057 +#ifndef CONFIG_LOCKDEP
36058 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36059 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36060 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36061 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36062 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36064 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36066 + wkinfo->hlock = NULL;
36067 + wkinfo->dont_check = 0;
36074 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36076 + static DEFINE_SPINLOCK(spin);
36079 + struct lock_class_key *key;
36081 + { .name = "&sbinfo->si_rwsem" },
36082 + { .name = "&finfo->fi_rwsem" },
36083 + { .name = "&dinfo->di_rwsem" },
36084 + { .name = "&iinfo->ii_rwsem" }
36089 + /* lockless read from 'set.' see below */
36090 + if (set == ARRAY_SIZE(a)) {
36091 + for (i = 0; i < ARRAY_SIZE(a); i++)
36092 + if (a[i].key == key)
36097 + spin_lock(&spin);
36099 + for (i = 0; i < ARRAY_SIZE(a); i++)
36100 + if (a[i].key == key) {
36101 + spin_unlock(&spin);
36104 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36106 + if (unlikely(a[i].key == key)) { /* rare but possible */
36107 + spin_unlock(&spin);
36112 + if (strstr(a[i].name, name)) {
36114 + * the order of these three lines is important for the
36115 + * lockless read above.
36118 + spin_unlock(&spin);
36120 + /* AuDbg("%d, %s\n", set, name); */
36124 + spin_unlock(&spin);
36133 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36136 + struct task_struct *curr;
36137 + struct held_lock **hl, *held_locks, *p;
36141 + wkinfo->dont_check = lockdep_recursing(curr);
36142 + if (wkinfo->dont_check)
36144 + n = curr->lockdep_depth;
36149 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36150 + if (unlikely(!wkinfo->hlock))
36155 + if (0 && au_debug_test()) /* left for debugging */
36156 + lockdep_print_held_locks(curr);
36158 + held_locks = curr->held_locks;
36159 + hl = wkinfo->hlock;
36161 + p = held_locks++;
36162 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36171 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36173 + au_kfree_try_rcu(wkinfo->hlock);
36176 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36178 + struct held_lock *p, **hl = wkinfo->hlock;
36181 + if (wkinfo->dont_check)
36185 + while ((p = *hl++)) { /* assignment */
36186 + subclass = lockdep_hlock_class(p)->subclass;
36187 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36189 + rwsem_acquire_read(p->instance, subclass, 0,
36190 + /*p->acquire_ip*/_RET_IP_);
36192 + rwsem_acquire(p->instance, subclass, 0,
36193 + /*p->acquire_ip*/_RET_IP_);
36197 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36199 + struct held_lock *p, **hl = wkinfo->hlock;
36201 + if (wkinfo->dont_check)
36205 + while ((p = *hl++)) /* assignment */
36206 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36210 +static void wkq_func(struct work_struct *wk)
36212 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36214 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36215 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36217 + au_wkq_lockdep_pre(wkinfo);
36218 + wkinfo->func(wkinfo->args);
36219 + au_wkq_lockdep_post(wkinfo);
36220 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36221 + complete(wkinfo->comp);
36223 + kobject_put(wkinfo->kobj);
36224 + module_put(THIS_MODULE); /* todo: ?? */
36225 + au_kfree_rcu(wkinfo);
36230 + * Since struct completion is large, try allocating it dynamically.
36232 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36233 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36235 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36237 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36239 + init_completion(*comp);
36240 + wkinfo->comp = *comp;
36246 +static void au_wkq_comp_free(struct completion *comp)
36248 + au_kfree_rcu(comp);
36254 +#define AuWkqCompDeclare(name) \
36255 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36256 + struct completion *comp = &_ ## name
36258 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36260 + wkinfo->comp = *comp;
36264 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36268 +#endif /* 4KSTACKS */
36270 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36272 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36273 + if (au_wkq_test()) {
36274 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36275 + " due to a dead dir by UDBA,"
36276 + " or async xino write?\n");
36277 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36280 + au_dbg_verify_kthread();
36282 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36283 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36284 + queue_work(au_wkq, &wkinfo->wk);
36286 + INIT_WORK(&wkinfo->wk, wkq_func);
36287 + schedule_work(&wkinfo->wk);
36292 + * Be careful. It is easy to make deadlock happen.
36293 + * processA: lock, wkq and wait
36294 + * processB: wkq and wait, lock in wkq
36297 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36300 + AuWkqCompDeclare(comp);
36301 + struct au_wkinfo wkinfo = {
36307 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36308 + if (unlikely(err))
36310 + err = au_wkq_lockdep_alloc(&wkinfo);
36311 + if (unlikely(err))
36314 + au_wkq_run(&wkinfo);
36315 + /* no timeout, no interrupt */
36316 + wait_for_completion(wkinfo.comp);
36318 + au_wkq_lockdep_free(&wkinfo);
36321 + au_wkq_comp_free(comp);
36323 + destroy_work_on_stack(&wkinfo.wk);
36328 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36329 + * problem in a concurrent umounting.
36331 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36332 + unsigned int flags)
36335 + struct au_wkinfo *wkinfo;
36337 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36340 + * wkq_func() must free this wkinfo.
36341 + * it highly depends upon the implementation of workqueue.
36344 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36346 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36347 + wkinfo->flags = flags & ~AuWkq_WAIT;
36348 + wkinfo->func = func;
36349 + wkinfo->args = args;
36350 + wkinfo->comp = NULL;
36351 + au_wkq_lockdep_init(wkinfo);
36352 + kobject_get(wkinfo->kobj);
36353 + __module_get(THIS_MODULE); /* todo: ?? */
36355 + au_wkq_run(wkinfo);
36358 + au_nwt_done(&au_sbi(sb)->si_nowait);
36364 +/* ---------------------------------------------------------------------- */
36366 +void au_nwt_init(struct au_nowait_tasks *nwt)
36368 + atomic_set(&nwt->nw_len, 0);
36369 + /* smp_mb(); */ /* atomic_set */
36370 + init_waitqueue_head(&nwt->nw_wq);
36373 +void au_wkq_fin(void)
36375 + destroy_workqueue(au_wkq);
36378 +int __init au_wkq_init(void)
36383 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36384 + if (IS_ERR(au_wkq))
36385 + err = PTR_ERR(au_wkq);
36386 + else if (!au_wkq)
36391 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36392 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36393 +++ linux/fs/aufs/wkq.h 2019-07-11 15:42:14.475571481 +0200
36395 +/* SPDX-License-Identifier: GPL-2.0 */
36397 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36399 + * This program, aufs is free software; you can redistribute it and/or modify
36400 + * it under the terms of the GNU General Public License as published by
36401 + * the Free Software Foundation; either version 2 of the License, or
36402 + * (at your option) any later version.
36404 + * This program is distributed in the hope that it will be useful,
36405 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36407 + * GNU General Public License for more details.
36409 + * You should have received a copy of the GNU General Public License
36410 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36414 + * workqueue for asynchronous/super-io operations
36415 + * todo: try new credentials management scheme
36418 +#ifndef __AUFS_WKQ_H__
36419 +#define __AUFS_WKQ_H__
36423 +#include <linux/wait.h>
36425 +struct super_block;
36427 +/* ---------------------------------------------------------------------- */
36430 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36432 +struct au_nowait_tasks {
36434 + wait_queue_head_t nw_wq;
36437 +/* ---------------------------------------------------------------------- */
36439 +typedef void (*au_wkq_func_t)(void *args);
36442 +#define AuWkq_WAIT 1
36443 +#define AuWkq_NEST (1 << 1)
36444 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36445 +#define au_fset_wkq(flags, name) \
36446 + do { (flags) |= AuWkq_##name; } while (0)
36447 +#define au_fclr_wkq(flags, name) \
36448 + do { (flags) &= ~AuWkq_##name; } while (0)
36451 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36452 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36453 + unsigned int flags);
36454 +void au_nwt_init(struct au_nowait_tasks *nwt);
36455 +int __init au_wkq_init(void);
36456 +void au_wkq_fin(void);
36458 +/* ---------------------------------------------------------------------- */
36460 +static inline int au_wkq_test(void)
36462 + return current->flags & PF_WQ_WORKER;
36465 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36467 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36470 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36472 + if (atomic_dec_and_test(&nwt->nw_len))
36473 + wake_up_all(&nwt->nw_wq);
36476 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36478 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36482 +#endif /* __KERNEL__ */
36483 +#endif /* __AUFS_WKQ_H__ */
36484 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36485 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36486 +++ linux/fs/aufs/xattr.c 2019-07-11 15:42:14.475571481 +0200
36488 +// SPDX-License-Identifier: GPL-2.0
36490 + * Copyright (C) 2014-2019 Junjiro R. Okajima
36492 + * This program, aufs is free software; you can redistribute it and/or modify
36493 + * it under the terms of the GNU General Public License as published by
36494 + * the Free Software Foundation; either version 2 of the License, or
36495 + * (at your option) any later version.
36497 + * This program is distributed in the hope that it will be useful,
36498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36500 + * GNU General Public License for more details.
36502 + * You should have received a copy of the GNU General Public License
36503 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36507 + * handling xattr functions
36510 +#include <linux/fs.h>
36511 +#include <linux/posix_acl_xattr.h>
36512 +#include <linux/xattr.h>
36515 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36517 + if (!ignore_flags)
36525 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36530 +#define cmp(brattr, prefix) do { \
36531 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36532 + XATTR_##prefix##_PREFIX_LEN)) { \
36533 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36539 + cmp(SEC, SECURITY);
36540 + cmp(SYS, SYSTEM);
36541 + cmp(TR, TRUSTED);
36545 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36552 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36554 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36555 + char *name, char **buf, unsigned int ignore_flags,
36556 + unsigned int verbose)
36560 + struct inode *h_idst;
36562 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36564 + if (unlikely(err <= 0)) {
36565 + if (err == -ENODATA
36566 + || (err == -EOPNOTSUPP
36567 + && ((ignore_flags & au_xattr_out_of_list)
36568 + || (au_test_nfs_noacl(d_inode(h_src))
36569 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36571 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36574 + if (err && (verbose || au_debug_test()))
36575 + pr_err("%s, err %d\n", name, err);
36579 + /* unlock it temporary */
36580 + h_idst = d_inode(h_dst);
36581 + inode_unlock(h_idst);
36582 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36583 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36584 + if (unlikely(err)) {
36585 + if (verbose || au_debug_test())
36586 + pr_err("%s, err %d\n", name, err);
36587 + err = au_xattr_ignore(err, name, ignore_flags);
36594 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36595 + unsigned int verbose)
36597 + int err, unlocked, acl_access, acl_default;
36599 + struct inode *h_isrc, *h_idst;
36600 + char *value, *p, *o, *e;
36602 + /* try stopping to update the source inode while we are referencing */
36603 + /* there should not be the parent-child relationship between them */
36604 + h_isrc = d_inode(h_src);
36605 + h_idst = d_inode(h_dst);
36606 + inode_unlock(h_idst);
36607 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36608 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36611 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36612 + ssz = vfs_listxattr(h_src, NULL, 0);
36614 + if (unlikely(err < 0)) {
36616 + if (err == -ENODATA
36617 + || err == -EOPNOTSUPP)
36618 + err = 0; /* ignore */
36627 + p = kmalloc(ssz, GFP_NOFS);
36629 + if (unlikely(!p))
36631 + err = vfs_listxattr(h_src, p, ssz);
36633 + inode_unlock_shared(h_isrc);
36635 + AuDbg("err %d, ssz %zd\n", err, ssz);
36636 + if (unlikely(err < 0))
36644 + while (!err && p < e) {
36645 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36646 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36647 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36648 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36650 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36652 + p += strlen(p) + 1;
36655 + ignore_flags |= au_xattr_out_of_list;
36656 + if (!err && !acl_access) {
36657 + err = au_do_cpup_xattr(h_dst, h_src,
36658 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36659 + ignore_flags, verbose);
36662 + if (!err && !acl_default) {
36663 + err = au_do_cpup_xattr(h_dst, h_src,
36664 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36665 + ignore_flags, verbose);
36669 + au_kfree_try_rcu(value);
36672 + au_kfree_try_rcu(o);
36675 + inode_unlock_shared(h_isrc);
36680 +/* ---------------------------------------------------------------------- */
36682 +static int au_smack_reentering(struct super_block *sb)
36684 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36686 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36687 + * i_op->getxattr(). ouch.
36689 + return si_pid_test(sb);
36700 +struct au_lgxattr {
36708 + const char *name;
36715 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36719 + struct path h_path;
36720 + struct super_block *sb;
36722 + sb = dentry->d_sb;
36723 + reenter = au_smack_reentering(sb);
36725 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36726 + if (unlikely(err))
36729 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36730 + if (unlikely(err))
36732 + if (unlikely(!h_path.dentry))
36733 + /* illegally overlapped or something */
36734 + goto out_di; /* pretending success */
36736 + /* always topmost entry only */
36737 + switch (arg->type) {
36738 + case AU_XATTR_LIST:
36739 + err = vfs_listxattr(h_path.dentry,
36740 + arg->u.list.list, arg->u.list.size);
36742 + case AU_XATTR_GET:
36743 + AuDebugOn(d_is_negative(h_path.dentry));
36744 + err = vfs_getxattr(h_path.dentry,
36745 + arg->u.get.name, arg->u.get.value,
36746 + arg->u.get.size);
36752 + di_read_unlock(dentry, AuLock_IR);
36755 + si_read_unlock(sb);
36761 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36763 + struct au_lgxattr arg = {
36764 + .type = AU_XATTR_LIST,
36771 + return au_lgxattr(dentry, &arg);
36774 +static ssize_t au_getxattr(struct dentry *dentry,
36775 + struct inode *inode __maybe_unused,
36776 + const char *name, void *value, size_t size)
36778 + struct au_lgxattr arg = {
36779 + .type = AU_XATTR_GET,
36787 + return au_lgxattr(dentry, &arg);
36790 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36791 + const char *name, const void *value, size_t size,
36794 + struct au_sxattr arg = {
36795 + .type = AU_XATTR_SET,
36804 + return au_sxattr(dentry, inode, &arg);
36807 +/* ---------------------------------------------------------------------- */
36809 +static int au_xattr_get(const struct xattr_handler *handler,
36810 + struct dentry *dentry, struct inode *inode,
36811 + const char *name, void *buffer, size_t size)
36813 + return au_getxattr(dentry, inode, name, buffer, size);
36816 +static int au_xattr_set(const struct xattr_handler *handler,
36817 + struct dentry *dentry, struct inode *inode,
36818 + const char *name, const void *value, size_t size,
36821 + return au_setxattr(dentry, inode, name, value, size, flags);
36824 +static const struct xattr_handler au_xattr_handler = {
36827 + .get = au_xattr_get,
36828 + .set = au_xattr_set
36831 +static const struct xattr_handler *au_xattr_handlers[] = {
36832 +#ifdef CONFIG_FS_POSIX_ACL
36833 + &posix_acl_access_xattr_handler,
36834 + &posix_acl_default_xattr_handler,
36836 + &au_xattr_handler, /* must be last */
36840 +void au_xattr_init(struct super_block *sb)
36842 + sb->s_xattr = au_xattr_handlers;
36844 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36845 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36846 +++ linux/fs/aufs/xino.c 2019-07-11 15:42:14.475571481 +0200
36848 +// SPDX-License-Identifier: GPL-2.0
36850 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36852 + * This program, aufs is free software; you can redistribute it and/or modify
36853 + * it under the terms of the GNU General Public License as published by
36854 + * the Free Software Foundation; either version 2 of the License, or
36855 + * (at your option) any later version.
36857 + * This program is distributed in the hope that it will be useful,
36858 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36859 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36860 + * GNU General Public License for more details.
36862 + * You should have received a copy of the GNU General Public License
36863 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36867 + * external inode number translation table and bitmap
36869 + * things to consider
36871 + * + au_xino object
36872 + * + XINO files (xino, xib, xigen)
36873 + * + dynamic debugfs entries (xiN)
36874 + * + static debugfs entries (xib, xigen)
36875 + * + static sysfs entry (xi_path)
36876 + * - several entry points to handle them.
36877 + * + mount(2) without xino option (default)
36878 + * + mount(2) with xino option
36879 + * + mount(2) with noxino option
36881 + * + remount with add/del branches
36882 + * + remount with xino/noxino options
36885 +#include <linux/seq_file.h>
36886 +#include <linux/statfs.h>
36889 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36890 + aufs_bindex_t bbot,
36891 + struct super_block *h_sb)
36893 + /* todo: try binary-search if the branches are many */
36894 + for (; btop <= bbot; btop++)
36895 + if (h_sb == au_sbr_sb(sb, btop))
36901 + * find another branch who is on the same filesystem of the specified
36902 + * branch{@btgt}. search until @bbot.
36904 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36905 + aufs_bindex_t bbot)
36907 + aufs_bindex_t bindex;
36908 + struct super_block *tgt_sb;
36910 + tgt_sb = au_sbr_sb(sb, btgt);
36911 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36913 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36918 +/* ---------------------------------------------------------------------- */
36921 + * stop unnecessary notify events at creating xino files
36924 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36926 + aufs_bindex_t bfound, bindex, bbot;
36927 + struct dentry *parent;
36928 + struct au_branch *br;
36931 + parent = dentry->d_parent; /* safe d_parent access */
36932 + bbot = au_sbbot(sb);
36933 + for (bindex = 0; bindex <= bbot; bindex++) {
36934 + br = au_sbr(sb, bindex);
36935 + if (au_br_dentry(br) == parent) {
36941 + AuDbg("bfound b%d\n", bfound);
36945 +struct au_xino_lock_dir {
36946 + struct au_hinode *hdir;
36947 + struct dentry *parent;
36948 + struct inode *dir;
36951 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36952 + unsigned int lsc)
36954 + struct dentry *parent;
36955 + struct inode *dir;
36957 + parent = dget_parent(dentry);
36958 + dir = d_inode(parent);
36959 + inode_lock_nested(dir, lsc);
36960 +#if 0 /* it should not happen */
36961 + spin_lock(&dentry->d_lock);
36962 + if (unlikely(dentry->d_parent != parent)) {
36963 + spin_unlock(&dentry->d_lock);
36964 + inode_unlock(dir);
36969 + spin_unlock(&dentry->d_lock);
36976 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36977 + struct au_xino_lock_dir *ldir)
36979 + aufs_bindex_t bindex;
36981 + ldir->hdir = NULL;
36982 + bindex = au_xi_root(sb, xipath->dentry);
36983 + if (bindex >= 0) {
36984 + /* rw branch root */
36985 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36986 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36989 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36991 + ldir->dir = d_inode(ldir->parent);
36995 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36998 + au_hn_inode_unlock(ldir->hdir);
37000 + inode_unlock(ldir->dir);
37001 + dput(ldir->parent);
37005 +/* ---------------------------------------------------------------------- */
37008 + * create and set a new xino file
37010 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37013 + struct file *file;
37014 + struct dentry *h_parent, *d;
37015 + struct inode *h_dir, *inode;
37017 + static DEFINE_MUTEX(mtx);
37020 + * at mount-time, and the xino file is the default path,
37021 + * hnotify is disabled so we have no notify events to ignore.
37022 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37025 + mutex_lock(&mtx);
37026 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37027 + /* | __FMODE_NONOTIFY */,
37029 + if (IS_ERR(file)) {
37031 + mutex_unlock(&mtx);
37033 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37037 + /* keep file count */
37039 + d = file->f_path.dentry;
37040 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37042 + mutex_unlock(&mtx);
37043 + /* mnt_want_write() is unnecessary here */
37044 + h_dir = d_inode(h_parent);
37045 + inode = file_inode(file);
37046 + /* no delegation since it is just created */
37047 + if (inode->i_nlink)
37048 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37050 + inode_unlock(h_dir);
37052 + if (unlikely(err)) {
37054 + pr_err("unlink %s(%d)\n", fpath, err);
37059 + if (unlikely(sb == d->d_sb)) {
37061 + pr_err("%s must be outside\n", fpath);
37064 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37066 + pr_err("xino doesn't support %s(%s)\n",
37067 + fpath, au_sbtype(d->d_sb));
37070 + return file; /* success */
37074 + file = ERR_PTR(err);
37079 + * create a new xinofile at the same place/path as @base.
37081 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37082 + struct file *copy_src)
37084 + struct file *file;
37085 + struct dentry *dentry, *parent;
37086 + struct inode *dir, *delegated;
37087 + struct qstr *name;
37088 + struct path path;
37089 + int err, do_unlock;
37090 + struct au_xino_lock_dir ldir;
37093 + au_xino_lock_dir(sb, base, &ldir);
37094 + dentry = base->dentry;
37095 + parent = dentry->d_parent; /* dir inode is locked */
37096 + dir = d_inode(parent);
37099 + name = &dentry->d_name;
37100 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37101 + if (IS_ERR(path.dentry)) {
37102 + file = (void *)path.dentry;
37103 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37107 + /* no need to mnt_want_write() since we call dentry_open() later */
37108 + err = vfs_create(dir, path.dentry, 0666, NULL);
37109 + if (unlikely(err)) {
37110 + file = ERR_PTR(err);
37111 + pr_err("%pd create err %d\n", dentry, err);
37115 + path.mnt = base->mnt;
37116 + file = vfsub_dentry_open(&path,
37117 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37118 + /* | __FMODE_NONOTIFY */);
37119 + if (IS_ERR(file)) {
37120 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37124 + delegated = NULL;
37125 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37126 + au_xino_unlock_dir(&ldir);
37128 + if (unlikely(err == -EWOULDBLOCK)) {
37129 + pr_warn("cannot retry for NFSv4 delegation"
37130 + " for an internal unlink\n");
37133 + if (unlikely(err)) {
37134 + pr_err("%pd unlink err %d\n", dentry, err);
37139 + /* no one can touch copy_src xino */
37140 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37141 + if (unlikely(err)) {
37142 + pr_err("%pd copy err %d\n", dentry, err);
37146 + goto out_dput; /* success */
37150 + file = ERR_PTR(err);
37152 + dput(path.dentry);
37155 + au_xino_unlock_dir(&ldir);
37159 +struct file *au_xino_file1(struct au_xino *xi)
37161 + struct file *file;
37162 + unsigned int u, nfile;
37165 + nfile = xi->xi_nfile;
37166 + for (u = 0; u < nfile; u++) {
37167 + file = xi->xi_file[u];
37175 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37186 + if (idx < xi->xi_nfile) {
37187 + f = xi->xi_file[idx];
37191 + p = au_kzrealloc(xi->xi_file,
37192 + sizeof(*xi->xi_file) * xi->xi_nfile,
37193 + sizeof(*xi->xi_file) * (idx + 1),
37194 + GFP_NOFS, /*may_shrink*/0);
37196 + MtxMustLock(&xi->xi_mtx);
37198 + xi->xi_nfile = idx + 1;
37206 + xi->xi_file[idx] = file;
37213 + * if @xinew->xi is not set, then create new xigen file.
37215 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37217 + struct file *file;
37220 + SiMustAnyLock(sb);
37222 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37223 + if (IS_ERR(file)) {
37224 + err = PTR_ERR(file);
37225 + pr_err("%s[%d], err %d\n",
37226 + xinew->xi ? "xino" : "xigen",
37227 + xinew->idx, err);
37232 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37235 + /* todo: make xigen file an array */
37236 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37239 + if (unlikely(err))
37240 + file = ERR_PTR(err);
37246 +/* ---------------------------------------------------------------------- */
37249 + * truncate xino files
37251 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37252 + int idx, struct kstatfs *st)
37256 + struct file *file, *new_xino;
37257 + struct au_xi_new xinew = {
37262 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37263 + file = au_xino_file(xinew.xi, idx);
37267 + xinew.base = &file->f_path;
37268 + err = vfs_statfs(xinew.base, st);
37269 + if (unlikely(err)) {
37270 + AuErr1("statfs err %d, ignored\n", err);
37275 + blocks = file_inode(file)->i_blocks;
37276 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37277 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37279 + xinew.copy_src = file;
37280 + new_xino = au_xi_new(sb, &xinew);
37281 + if (IS_ERR(new_xino)) {
37282 + err = PTR_ERR(new_xino);
37283 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37287 + err = vfs_statfs(&new_xino->f_path, st);
37289 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37290 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37291 + st->f_bfree, st->f_blocks);
37293 + AuErr1("statfs err %d, ignored\n", err);
37301 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37304 + unsigned long jiffy;
37305 + aufs_bindex_t bbot;
37306 + struct kstatfs *st;
37307 + struct au_branch *br;
37308 + struct au_xino *xi;
37311 + st = kmalloc(sizeof(*st), GFP_NOFS);
37312 + if (unlikely(!st))
37316 + bbot = au_sbbot(sb);
37317 + if (unlikely(bindex < 0 || bbot < bindex))
37322 + br = au_sbr(sb, bindex);
37323 + xi = br->br_xino;
37324 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37325 + err = au_xino_do_trunc(sb, bindex, i, st);
37327 + au_sbi(sb)->si_xino_jiffy = jiffy;
37330 + au_kfree_rcu(st);
37335 +struct xino_do_trunc_args {
37336 + struct super_block *sb;
37337 + struct au_branch *br;
37341 +static void xino_do_trunc(void *_args)
37343 + struct xino_do_trunc_args *args = _args;
37344 + struct super_block *sb;
37345 + struct au_branch *br;
37346 + struct inode *dir;
37348 + aufs_bindex_t bindex;
37352 + dir = d_inode(sb->s_root);
37356 + si_noflush_write_lock(sb);
37357 + ii_read_lock_parent(dir);
37358 + bindex = au_br_index(sb, br->br_id);
37359 + err = au_xino_trunc(sb, bindex, idx);
37360 + ii_read_unlock(dir);
37361 + if (unlikely(err))
37362 + pr_warn("err b%d, (%d)\n", bindex, err);
37363 + atomic_dec(&br->br_xino->xi_truncating);
37364 + au_lcnt_dec(&br->br_count);
37365 + si_write_unlock(sb);
37366 + au_nwt_done(&au_sbi(sb)->si_nowait);
37367 + au_kfree_rcu(args);
37371 + * returns the index in the xi_file array whose corresponding file is necessary
37372 + * to truncate, or -1 which means no need to truncate.
37374 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37378 + struct kstatfs st;
37379 + struct au_sbinfo *sbinfo;
37380 + struct au_xino *xi;
37381 + struct file *file;
37383 + /* todo: si_xino_expire and the ratio should be customizable */
37384 + sbinfo = au_sbi(sb);
37385 + if (time_before(jiffies,
37386 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37389 + /* truncation border */
37390 + xi = br->br_xino;
37391 + for (u = 0; u < xi->xi_nfile; u++) {
37392 + file = au_xino_file(xi, u);
37396 + err = vfs_statfs(&file->f_path, &st);
37397 + if (unlikely(err)) {
37398 + AuErr1("statfs err %d, ignored\n", err);
37401 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37402 + >= AUFS_XINO_DEF_TRUNC)
37409 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37412 + struct xino_do_trunc_args *args;
37415 + idx = xino_trunc_test(sb, br);
37419 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37422 + /* lock and kfree() will be called in trunc_xino() */
37423 + args = kmalloc(sizeof(*args), GFP_NOFS);
37424 + if (unlikely(!args)) {
37425 + AuErr1("no memory\n");
37429 + au_lcnt_inc(&br->br_count);
37433 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37435 + return; /* success */
37437 + pr_err("wkq %d\n", wkq_err);
37438 + au_lcnt_dec(&br->br_count);
37439 + au_kfree_rcu(args);
37442 + atomic_dec(&br->br_xino->xi_truncating);
37445 +/* ---------------------------------------------------------------------- */
37447 +struct au_xi_calc {
37452 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37453 + struct au_xi_calc *calc)
37457 + maxent = au_xi_maxent(sb);
37458 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37459 + calc->pos *= sizeof(ino_t);
37462 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37463 + struct au_xi_calc *calc)
37466 + struct file *file;
37467 + struct au_xino *xi = br->br_xino;
37468 + struct au_xi_new xinew = {
37472 + SiMustAnyLock(sb);
37478 + mutex_lock(&xi->xi_mtx);
37479 + file = au_xino_file(xi, calc->idx);
37483 + file = au_xino_file(xi, /*idx*/-1);
37484 + AuDebugOn(!file);
37485 + xinew.idx = calc->idx;
37486 + xinew.base = &file->f_path;
37487 + /* xinew.copy_src = NULL; */
37488 + file = au_xi_new(sb, &xinew);
37489 + if (IS_ERR(file))
37490 + err = PTR_ERR(file);
37493 + mutex_unlock(&xi->xi_mtx);
37498 +struct au_xino_do_new_async_args {
37499 + struct super_block *sb;
37500 + struct au_branch *br;
37501 + struct au_xi_calc calc;
37505 +struct au_xi_writing {
37506 + struct hlist_bl_node node;
37507 + ino_t h_ino, ino;
37510 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37511 + struct au_xi_calc *calc, ino_t ino);
37513 +static void au_xino_call_do_new_async(void *args)
37515 + struct au_xino_do_new_async_args *a = args;
37516 + struct au_branch *br;
37517 + struct super_block *sb;
37518 + struct au_sbinfo *sbi;
37519 + struct inode *root;
37520 + struct file *file;
37521 + struct au_xi_writing *del, *p;
37522 + struct hlist_bl_head *hbl;
37523 + struct hlist_bl_node *pos;
37528 + sbi = au_sbi(sb);
37529 + si_noflush_read_lock(sb);
37530 + root = d_inode(sb->s_root);
37531 + ii_read_lock_child(root);
37532 + err = au_xino_do_new_async(sb, br, &a->calc);
37533 + if (unlikely(err)) {
37534 + AuIOErr("err %d\n", err);
37538 + file = au_xino_file(br->br_xino, a->calc.idx);
37539 + AuDebugOn(!file);
37540 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37541 + if (unlikely(err)) {
37542 + AuIOErr("err %d\n", err);
37547 + hbl = &br->br_xino->xi_writing;
37548 + hlist_bl_lock(hbl);
37549 + au_hbl_for_each(pos, hbl) {
37550 + p = container_of(pos, struct au_xi_writing, node);
37551 + if (p->ino == a->ino) {
37553 + hlist_bl_del(&p->node);
37557 + hlist_bl_unlock(hbl);
37558 + au_kfree_rcu(del);
37561 + au_lcnt_dec(&br->br_count);
37562 + ii_read_unlock(root);
37563 + si_read_unlock(sb);
37564 + au_nwt_done(&sbi->si_nowait);
37569 + * create a new xino file asynchronously
37571 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37572 + struct au_xi_calc *calc, ino_t ino)
37575 + struct au_xino_do_new_async_args *arg;
37578 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37579 + if (unlikely(!arg))
37584 + arg->calc = *calc;
37586 + au_lcnt_inc(&br->br_count);
37587 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37588 + if (unlikely(err)) {
37589 + pr_err("wkq %d\n", err);
37590 + au_lcnt_dec(&br->br_count);
37591 + au_kfree_rcu(arg);
37599 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37600 + * at the position of @h_ino.
37602 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37607 + struct au_xi_calc calc;
37608 + struct au_sbinfo *sbinfo;
37609 + struct file *file;
37610 + struct au_xino *xi;
37611 + struct hlist_bl_head *hbl;
37612 + struct hlist_bl_node *pos;
37613 + struct au_xi_writing *p;
37616 + if (!au_opt_test(au_mntflags(sb), XINO))
37617 + return 0; /* no xino */
37620 + au_xi_calc(sb, h_ino, &calc);
37621 + xi = au_sbr(sb, bindex)->br_xino;
37622 + file = au_xino_file(xi, calc.idx);
37624 + hbl = &xi->xi_writing;
37625 + hlist_bl_lock(hbl);
37626 + au_hbl_for_each(pos, hbl) {
37627 + p = container_of(pos, struct au_xi_writing, node);
37628 + if (p->h_ino == h_ino) {
37629 + AuDbg("hi%llu, i%llu, found\n",
37630 + (u64)p->h_ino, (u64)p->ino);
37635 + hlist_bl_unlock(hbl);
37637 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37638 + return 0; /* no xino */
37640 + sbinfo = au_sbi(sb);
37641 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37642 + if (sz == sizeof(*ino))
37643 + return 0; /* success */
37646 + if (unlikely(sz >= 0)) {
37648 + AuIOErr("xino read error (%zd)\n", sz);
37653 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37654 + struct au_xi_calc *calc, ino_t ino)
37658 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37659 + if (sz == sizeof(ino))
37660 + return 0; /* success */
37662 + AuIOErr("write failed (%zd)\n", sz);
37667 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37668 + * at the position of @h_ino.
37669 + * even if @ino is zero, it is written to the xinofile and means no entry.
37670 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37671 + * try truncating it.
37673 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37677 + unsigned int mnt_flags;
37678 + struct au_xi_calc calc;
37679 + struct file *file;
37680 + struct au_branch *br;
37681 + struct au_xino *xi;
37682 + struct au_xi_writing *p;
37684 + SiMustAnyLock(sb);
37686 + mnt_flags = au_mntflags(sb);
37687 + if (!au_opt_test(mnt_flags, XINO))
37690 + au_xi_calc(sb, h_ino, &calc);
37691 + br = au_sbr(sb, bindex);
37692 + xi = br->br_xino;
37693 + file = au_xino_file(xi, calc.idx);
37695 + /* store the inum pair into the list */
37696 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37697 + p->h_ino = h_ino;
37699 + au_hbl_add(&p->node, &xi->xi_writing);
37701 + /* create and write a new xino file asynchronously */
37702 + err = au_xino_new_async(sb, br, &calc, ino);
37704 + return 0; /* success */
37708 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37710 + br = au_sbr(sb, bindex);
37711 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37712 + && au_test_fs_trunc_xino(au_br_sb(br)))
37713 + xino_try_trunc(sb, br);
37714 + return 0; /* success */
37718 + AuIOErr("write failed (%d)\n", err);
37722 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37723 + size_t size, loff_t *pos);
37725 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37726 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37730 + mm_segment_t oldfs;
37736 + const int prevent_endless = 10;
37740 + oldfs = get_fs();
37741 + set_fs(KERNEL_DS);
37743 + err = func(file, buf.u, size, pos);
37744 + if (err == -EINTR
37745 + && !au_wkq_test()
37746 + && fatal_signal_pending(current)) {
37748 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37749 + BUG_ON(err == -EINTR);
37750 + oldfs = get_fs();
37751 + set_fs(KERNEL_DS);
37753 + } while (i++ < prevent_endless
37754 + && (err == -EAGAIN || err == -EINTR));
37757 +#if 0 /* reserved for future use */
37759 + fsnotify_access(file->f_path.dentry);
37765 +struct xino_fread_args {
37767 + vfs_readf_t func;
37768 + struct file *file;
37774 +static void call_xino_fread(void *args)
37776 + struct xino_fread_args *a = args;
37777 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37780 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37781 + size_t size, loff_t *pos)
37785 + struct xino_fread_args args = {
37794 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37795 + if (unlikely(wkq_err))
37801 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37802 + size_t size, loff_t *pos);
37804 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37805 + size_t size, loff_t *pos)
37808 + mm_segment_t oldfs;
37811 + const char __user *u;
37814 + const int prevent_endless = 10;
37818 + oldfs = get_fs();
37819 + set_fs(KERNEL_DS);
37821 + err = func(file, buf.u, size, pos);
37822 + if (err == -EINTR
37823 + && !au_wkq_test()
37824 + && fatal_signal_pending(current)) {
37826 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37827 + BUG_ON(err == -EINTR);
37828 + oldfs = get_fs();
37829 + set_fs(KERNEL_DS);
37831 + } while (i++ < prevent_endless
37832 + && (err == -EAGAIN || err == -EINTR));
37835 +#if 0 /* reserved for future use */
37837 + fsnotify_modify(file->f_path.dentry);
37843 +struct do_xino_fwrite_args {
37845 + vfs_writef_t func;
37846 + struct file *file;
37852 +static void call_do_xino_fwrite(void *args)
37854 + struct do_xino_fwrite_args *a = args;
37855 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37858 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37859 + size_t size, loff_t *pos)
37863 + struct do_xino_fwrite_args args = {
37873 + * it breaks RLIMIT_FSIZE and normal user's limit,
37874 + * users should care about quota and real 'filesystem full.'
37876 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37877 + if (unlikely(wkq_err))
37883 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37884 + size_t size, loff_t *pos)
37888 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37890 + err = do_xino_fwrite(func, file, buf, size, pos);
37894 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37901 +/* ---------------------------------------------------------------------- */
37904 + * inode number bitmap
37906 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37907 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37911 + AuDebugOn(bit < 0 || page_bits <= bit);
37912 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37916 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37918 + AuDebugOn(ino < AUFS_FIRST_INO);
37919 + ino -= AUFS_FIRST_INO;
37920 + *pindex = ino / page_bits;
37921 + *bit = ino % page_bits;
37924 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37929 + struct au_sbinfo *sbinfo;
37930 + struct file *xib;
37931 + unsigned long *p;
37933 + sbinfo = au_sbi(sb);
37934 + MtxMustLock(&sbinfo->si_xib_mtx);
37935 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37936 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37938 + if (pindex == sbinfo->si_xib_last_pindex)
37941 + xib = sbinfo->si_xib;
37942 + p = sbinfo->si_xib_buf;
37943 + pos = sbinfo->si_xib_last_pindex;
37944 + pos *= PAGE_SIZE;
37945 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37946 + if (unlikely(sz != PAGE_SIZE))
37950 + pos *= PAGE_SIZE;
37951 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37952 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37954 + memset(p, 0, PAGE_SIZE);
37955 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37957 + if (sz == PAGE_SIZE) {
37958 + sbinfo->si_xib_last_pindex = pindex;
37959 + return 0; /* success */
37963 + AuIOErr1("write failed (%zd)\n", sz);
37970 +static void au_xib_clear_bit(struct inode *inode)
37973 + unsigned long pindex;
37974 + struct super_block *sb;
37975 + struct au_sbinfo *sbinfo;
37977 + AuDebugOn(inode->i_nlink);
37979 + sb = inode->i_sb;
37980 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37981 + AuDebugOn(page_bits <= bit);
37982 + sbinfo = au_sbi(sb);
37983 + mutex_lock(&sbinfo->si_xib_mtx);
37984 + err = xib_pindex(sb, pindex);
37986 + clear_bit(bit, sbinfo->si_xib_buf);
37987 + sbinfo->si_xib_next_bit = bit;
37989 + mutex_unlock(&sbinfo->si_xib_mtx);
37992 +/* ---------------------------------------------------------------------- */
37995 + * truncate a xino bitmap file
37999 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38003 + unsigned long pindex;
38004 + loff_t pos, pend;
38005 + struct au_sbinfo *sbinfo;
38006 + vfs_readf_t func;
38008 + unsigned long *p;
38011 + sbinfo = au_sbi(sb);
38012 + MtxMustLock(&sbinfo->si_xib_mtx);
38013 + p = sbinfo->si_xib_buf;
38014 + func = sbinfo->si_xread;
38015 + pend = vfsub_f_size_read(file);
38017 + while (pos < pend) {
38018 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38020 + if (unlikely(sz <= 0))
38024 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38025 + if (unlikely(*ino < AUFS_FIRST_INO))
38028 + xib_calc_bit(*ino, &pindex, &bit);
38029 + AuDebugOn(page_bits <= bit);
38030 + err = xib_pindex(sb, pindex);
38042 +static int xib_restore(struct super_block *sb)
38045 + unsigned int nfile;
38046 + aufs_bindex_t bindex, bbot;
38048 + struct au_branch *br;
38049 + struct au_xino *xi;
38050 + struct file *file;
38053 + page = (void *)__get_free_page(GFP_NOFS);
38054 + if (unlikely(!page))
38058 + bbot = au_sbbot(sb);
38059 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38060 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38061 + br = au_sbr(sb, bindex);
38062 + xi = br->br_xino;
38063 + nfile = xi->xi_nfile;
38064 + for (i = 0; i < nfile; i++) {
38065 + file = au_xino_file(xi, i);
38067 + err = do_xib_restore(sb, file, page);
38070 + AuDbg("skip shared b%d\n", bindex);
38071 + free_page((unsigned long)page);
38077 +int au_xib_trunc(struct super_block *sb)
38082 + struct au_sbinfo *sbinfo;
38083 + unsigned long *p;
38084 + struct file *file;
38086 + SiMustWriteLock(sb);
38089 + sbinfo = au_sbi(sb);
38090 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38093 + file = sbinfo->si_xib;
38094 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38097 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38098 + err = PTR_ERR(file);
38099 + if (IS_ERR(file))
38101 + fput(sbinfo->si_xib);
38102 + sbinfo->si_xib = file;
38104 + p = sbinfo->si_xib_buf;
38105 + memset(p, 0, PAGE_SIZE);
38107 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38108 + if (unlikely(sz != PAGE_SIZE)) {
38110 + AuIOErr("err %d\n", err);
38116 + mutex_lock(&sbinfo->si_xib_mtx);
38117 + /* mnt_want_write() is unnecessary here */
38118 + err = xib_restore(sb);
38119 + mutex_unlock(&sbinfo->si_xib_mtx);
38125 +/* ---------------------------------------------------------------------- */
38127 +struct au_xino *au_xino_alloc(unsigned int nfile)
38129 + struct au_xino *xi;
38131 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38132 + if (unlikely(!xi))
38134 + xi->xi_nfile = nfile;
38135 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38136 + if (unlikely(!xi->xi_file))
38139 + xi->xi_nondir.total = 8; /* initial size */
38140 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38142 + if (unlikely(!xi->xi_nondir.array))
38145 + spin_lock_init(&xi->xi_nondir.spin);
38146 + init_waitqueue_head(&xi->xi_nondir.wqh);
38147 + mutex_init(&xi->xi_mtx);
38148 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38149 + atomic_set(&xi->xi_truncating, 0);
38150 + kref_init(&xi->xi_kref);
38151 + goto out; /* success */
38154 + au_kfree_try_rcu(xi->xi_file);
38156 + au_kfree_rcu(xi);
38162 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38165 + struct au_xino *xi;
38168 + xi = au_xino_alloc(idx + 1);
38169 + if (unlikely(!xi)) {
38176 + xi->xi_file[idx] = file;
38177 + AuDebugOn(br->br_xino);
38178 + br->br_xino = xi;
38184 +static void au_xino_release(struct kref *kref)
38186 + struct au_xino *xi;
38188 + unsigned long ul;
38189 + struct hlist_bl_head *hbl;
38190 + struct hlist_bl_node *pos, *n;
38191 + struct au_xi_writing *p;
38193 + xi = container_of(kref, struct au_xino, xi_kref);
38194 + for (i = 0; i < xi->xi_nfile; i++)
38195 + if (xi->xi_file[i])
38196 + fput(xi->xi_file[i]);
38197 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38198 + AuDebugOn(xi->xi_nondir.array[i]);
38199 + mutex_destroy(&xi->xi_mtx);
38200 + hbl = &xi->xi_writing;
38201 + ul = au_hbl_count(hbl);
38202 + if (unlikely(ul)) {
38203 + pr_warn("xi_writing %lu\n", ul);
38204 + hlist_bl_lock(hbl);
38205 + hlist_bl_for_each_entry_safe (p, pos, n, hbl, node) {
38206 + hlist_bl_del(&p->node);
38209 + hlist_bl_unlock(hbl);
38211 + au_kfree_try_rcu(xi->xi_file);
38212 + au_kfree_try_rcu(xi->xi_nondir.array);
38213 + au_kfree_rcu(xi);
38216 +int au_xino_put(struct au_branch *br)
38219 + struct au_xino *xi;
38222 + xi = br->br_xino;
38224 + br->br_xino = NULL;
38225 + ret = kref_put(&xi->xi_kref, au_xino_release);
38231 +/* ---------------------------------------------------------------------- */
38234 + * xino mount option handlers
38238 +static void xino_clear_xib(struct super_block *sb)
38240 + struct au_sbinfo *sbinfo;
38242 + SiMustWriteLock(sb);
38244 + sbinfo = au_sbi(sb);
38245 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38246 + if (sbinfo->si_xib)
38247 + fput(sbinfo->si_xib);
38248 + sbinfo->si_xib = NULL;
38249 + if (sbinfo->si_xib_buf)
38250 + free_page((unsigned long)sbinfo->si_xib_buf);
38251 + sbinfo->si_xib_buf = NULL;
38254 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38258 + struct au_sbinfo *sbinfo;
38259 + struct file *file;
38260 + struct super_block *xi_sb;
38262 + SiMustWriteLock(sb);
38264 + sbinfo = au_sbi(sb);
38265 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38266 + err = PTR_ERR(file);
38267 + if (IS_ERR(file))
38269 + if (sbinfo->si_xib)
38270 + fput(sbinfo->si_xib);
38271 + sbinfo->si_xib = file;
38272 + sbinfo->si_xread = vfs_readf(file);
38273 + sbinfo->si_xwrite = vfs_writef(file);
38274 + xi_sb = file_inode(file)->i_sb;
38275 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38276 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38278 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38279 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38282 + sbinfo->si_ximaxent /= sizeof(ino_t);
38285 + if (!sbinfo->si_xib_buf)
38286 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38287 + if (unlikely(!sbinfo->si_xib_buf))
38290 + sbinfo->si_xib_last_pindex = 0;
38291 + sbinfo->si_xib_next_bit = 0;
38292 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38294 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38295 + PAGE_SIZE, &pos);
38296 + if (unlikely(err != PAGE_SIZE))
38300 + goto out; /* success */
38303 + if (sbinfo->si_xib_buf)
38304 + free_page((unsigned long)sbinfo->si_xib_buf);
38305 + sbinfo->si_xib_buf = NULL;
38309 + fput(sbinfo->si_xib);
38310 + sbinfo->si_xib = NULL;
38316 +/* xino for each branch */
38317 +static void xino_clear_br(struct super_block *sb)
38319 + aufs_bindex_t bindex, bbot;
38320 + struct au_branch *br;
38322 + bbot = au_sbbot(sb);
38323 + for (bindex = 0; bindex <= bbot; bindex++) {
38324 + br = au_sbr(sb, bindex);
38330 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38331 + aufs_bindex_t bshared)
38333 + struct au_branch *brshared;
38335 + brshared = au_sbr(sb, bshared);
38336 + AuDebugOn(!brshared->br_xino);
38337 + AuDebugOn(!brshared->br_xino->xi_file);
38338 + if (br->br_xino != brshared->br_xino) {
38339 + au_xino_get(brshared);
38341 + br->br_xino = brshared->br_xino;
38345 +struct au_xino_do_set_br {
38346 + vfs_writef_t writef;
38347 + struct au_branch *br;
38349 + aufs_bindex_t bshared;
38352 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38353 + struct au_xino_do_set_br *args)
38356 + struct au_xi_calc calc;
38357 + struct file *file;
38358 + struct au_branch *br;
38359 + struct au_xi_new xinew = {
38364 + xinew.xi = br->br_xino;
38365 + au_xi_calc(sb, args->h_ino, &calc);
38366 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38367 + if (args->bshared >= 0)
38368 + /* shared xino */
38369 + au_xino_set_br_shared(sb, br, args->bshared);
38370 + else if (!xinew.xi) {
38372 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38373 + if (unlikely(err))
38377 + /* force re-creating */
38378 + xinew.xi = br->br_xino;
38379 + xinew.idx = calc.idx;
38380 + mutex_lock(&xinew.xi->xi_mtx);
38381 + file = au_xi_new(sb, &xinew);
38382 + mutex_unlock(&xinew.xi->xi_mtx);
38383 + err = PTR_ERR(file);
38384 + if (IS_ERR(file))
38386 + AuDebugOn(!file);
38388 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38389 + if (unlikely(err))
38397 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38400 + aufs_bindex_t bindex, bbot;
38401 + struct au_xino_do_set_br args;
38402 + struct inode *inode;
38404 + SiMustWriteLock(sb);
38406 + bbot = au_sbbot(sb);
38407 + inode = d_inode(sb->s_root);
38408 + args.writef = au_sbi(sb)->si_xwrite;
38409 + for (bindex = 0; bindex <= bbot; bindex++) {
38410 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38411 + args.br = au_sbr(sb, bindex);
38412 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38413 + err = au_xino_do_set_br(sb, path, &args);
38414 + if (unlikely(err))
38422 +void au_xino_clr(struct super_block *sb)
38424 + struct au_sbinfo *sbinfo;
38426 + au_xigen_clr(sb);
38427 + xino_clear_xib(sb);
38428 + xino_clear_br(sb);
38429 + dbgaufs_brs_del(sb, 0);
38430 + sbinfo = au_sbi(sb);
38431 + /* lvalue, do not call au_mntflags() */
38432 + au_opt_clr(sbinfo->si_mntflags, XINO);
38435 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38438 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38439 + struct qstr *dname, *cur_name;
38440 + struct file *cur_xino;
38441 + struct au_sbinfo *sbinfo;
38442 + struct path *path, *cur_path;
38444 + SiMustWriteLock(sb);
38447 + sbinfo = au_sbi(sb);
38448 + path = &xiopt->file->f_path;
38449 + dentry = path->dentry;
38450 + parent = dget_parent(dentry);
38453 + cur_xino = sbinfo->si_xib;
38455 + cur_path = &cur_xino->f_path;
38456 + cur_dentry = cur_path->dentry;
38457 + cur_parent = dget_parent(cur_dentry);
38458 + cur_name = &cur_dentry->d_name;
38459 + dname = &dentry->d_name;
38460 + skip = (cur_parent == parent
38461 + && au_qstreq(dname, cur_name));
38462 + dput(cur_parent);
38468 + au_opt_set(sbinfo->si_mntflags, XINO);
38469 + err = au_xino_set_xib(sb, path);
38470 + /* si_x{read,write} are set */
38472 + err = au_xigen_set(sb, path);
38474 + err = au_xino_set_br(sb, path);
38476 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38477 + goto out; /* success */
38481 + AuIOErr("failed setting xino(%d).\n", err);
38490 + * create a xinofile at the default place/path.
38492 +struct file *au_xino_def(struct super_block *sb)
38494 + struct file *file;
38496 + struct au_branch *br;
38497 + struct super_block *h_sb;
38498 + struct path path;
38499 + aufs_bindex_t bbot, bindex, bwr;
38502 + bbot = au_sbbot(sb);
38504 + for (bindex = 0; bindex <= bbot; bindex++) {
38505 + br = au_sbr(sb, bindex);
38506 + if (au_br_writable(br->br_perm)
38507 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38514 + file = ERR_PTR(-ENOMEM);
38515 + page = (void *)__get_free_page(GFP_NOFS);
38516 + if (unlikely(!page))
38518 + path.mnt = au_br_mnt(br);
38519 + path.dentry = au_h_dptr(sb->s_root, bwr);
38520 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38521 + file = (void *)p;
38522 + if (!IS_ERR(p)) {
38523 + strcat(p, "/" AUFS_XINO_FNAME);
38524 + AuDbg("%s\n", p);
38525 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38527 + free_page((unsigned long)page);
38529 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38531 + if (IS_ERR(file))
38533 + h_sb = file->f_path.dentry->d_sb;
38534 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38535 + pr_err("xino doesn't support %s(%s)\n",
38536 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38538 + file = ERR_PTR(-EINVAL);
38546 +/* ---------------------------------------------------------------------- */
38549 + * initialize the xinofile for the specified branch @br
38550 + * at the place/path where @base_file indicates.
38551 + * test whether another branch is on the same filesystem or not,
38552 + * if found then share the xinofile with another branch.
38554 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38555 + struct path *base)
38558 + struct au_xino_do_set_br args = {
38563 + args.writef = au_sbi(sb)->si_xwrite;
38564 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38566 + err = au_xino_do_set_br(sb, base, &args);
38567 + if (unlikely(err))
38573 +/* ---------------------------------------------------------------------- */
38576 + * get an unused inode number from bitmap
38578 +ino_t au_xino_new_ino(struct super_block *sb)
38581 + unsigned long *p, pindex, ul, pend;
38582 + struct au_sbinfo *sbinfo;
38583 + struct file *file;
38584 + int free_bit, err;
38586 + if (!au_opt_test(au_mntflags(sb), XINO))
38587 + return iunique(sb, AUFS_FIRST_INO);
38589 + sbinfo = au_sbi(sb);
38590 + mutex_lock(&sbinfo->si_xib_mtx);
38591 + p = sbinfo->si_xib_buf;
38592 + free_bit = sbinfo->si_xib_next_bit;
38593 + if (free_bit < page_bits && !test_bit(free_bit, p))
38594 + goto out; /* success */
38595 + free_bit = find_first_zero_bit(p, page_bits);
38596 + if (free_bit < page_bits)
38597 + goto out; /* success */
38599 + pindex = sbinfo->si_xib_last_pindex;
38600 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38601 + err = xib_pindex(sb, ul);
38602 + if (unlikely(err))
38604 + free_bit = find_first_zero_bit(p, page_bits);
38605 + if (free_bit < page_bits)
38606 + goto out; /* success */
38609 + file = sbinfo->si_xib;
38610 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38611 + for (ul = pindex + 1; ul <= pend; ul++) {
38612 + err = xib_pindex(sb, ul);
38613 + if (unlikely(err))
38615 + free_bit = find_first_zero_bit(p, page_bits);
38616 + if (free_bit < page_bits)
38617 + goto out; /* success */
38622 + set_bit(free_bit, p);
38623 + sbinfo->si_xib_next_bit = free_bit + 1;
38624 + pindex = sbinfo->si_xib_last_pindex;
38625 + mutex_unlock(&sbinfo->si_xib_mtx);
38626 + ino = xib_calc_ino(pindex, free_bit);
38627 + AuDbg("i%lu\n", (unsigned long)ino);
38630 + mutex_unlock(&sbinfo->si_xib_mtx);
38635 +/* for s_op->delete_inode() */
38636 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38639 + unsigned int mnt_flags;
38640 + aufs_bindex_t bindex, bbot, bi;
38641 + unsigned char try_trunc;
38642 + struct au_iinfo *iinfo;
38643 + struct super_block *sb;
38644 + struct au_hinode *hi;
38645 + struct inode *h_inode;
38646 + struct au_branch *br;
38647 + vfs_writef_t xwrite;
38648 + struct au_xi_calc calc;
38649 + struct file *file;
38651 + AuDebugOn(au_is_bad_inode(inode));
38653 + sb = inode->i_sb;
38654 + mnt_flags = au_mntflags(sb);
38655 + if (!au_opt_test(mnt_flags, XINO)
38656 + || inode->i_ino == AUFS_ROOT_INO)
38660 + au_xigen_inc(inode);
38661 + au_xib_clear_bit(inode);
38664 + iinfo = au_ii(inode);
38665 + bindex = iinfo->ii_btop;
38669 + xwrite = au_sbi(sb)->si_xwrite;
38670 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38671 + hi = au_hinode(iinfo, bindex);
38672 + bbot = iinfo->ii_bbot;
38673 + for (; bindex <= bbot; bindex++, hi++) {
38674 + h_inode = hi->hi_inode;
38676 + || (!unlinked && h_inode->i_nlink))
38679 + /* inode may not be revalidated */
38680 + bi = au_br_index(sb, hi->hi_id);
38684 + br = au_sbr(sb, bi);
38685 + au_xi_calc(sb, h_inode->i_ino, &calc);
38686 + file = au_xino_file(br->br_xino, calc.idx);
38687 + if (IS_ERR_OR_NULL(file))
38690 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38691 + if (!err && try_trunc
38692 + && au_test_fs_trunc_xino(au_br_sb(br)))
38693 + xino_try_trunc(sb, br);
38697 +/* ---------------------------------------------------------------------- */
38699 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38701 + int found, total, i;
38704 + total = xi->xi_nondir.total;
38705 + for (i = 0; i < total; i++) {
38706 + if (xi->xi_nondir.array[i] != h_ino)
38715 +static int au_xinondir_expand(struct au_xino *xi)
38720 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38723 + sz = xi->xi_nondir.total * sizeof(ino_t);
38724 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38726 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38727 + /*may_shrink*/0);
38729 + xi->xi_nondir.array = p;
38730 + xi->xi_nondir.total <<= 1;
38731 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38739 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38740 + ino_t h_ino, int idx)
38742 + struct au_xino *xi;
38744 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38745 + xi = au_sbr(sb, bindex)->br_xino;
38746 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38748 + spin_lock(&xi->xi_nondir.spin);
38749 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38750 + xi->xi_nondir.array[idx] = 0;
38751 + spin_unlock(&xi->xi_nondir.spin);
38752 + wake_up_all(&xi->xi_nondir.wqh);
38755 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38758 + int err, found, empty;
38759 + struct au_xino *xi;
38763 + if (!au_opt_test(au_mntflags(sb), XINO))
38764 + goto out; /* no xino */
38766 + xi = au_sbr(sb, bindex)->br_xino;
38769 + spin_lock(&xi->xi_nondir.spin);
38770 + found = au_xinondir_find(xi, h_ino);
38771 + if (found == -1) {
38772 + empty = au_xinondir_find(xi, /*h_ino*/0);
38773 + if (empty == -1) {
38774 + empty = xi->xi_nondir.total;
38775 + err = au_xinondir_expand(xi);
38776 + if (unlikely(err))
38779 + xi->xi_nondir.array[empty] = h_ino;
38782 + spin_unlock(&xi->xi_nondir.spin);
38783 + wait_event(xi->xi_nondir.wqh,
38784 + xi->xi_nondir.array[found] != h_ino);
38789 + spin_unlock(&xi->xi_nondir.spin);
38794 +/* ---------------------------------------------------------------------- */
38796 +int au_xino_path(struct seq_file *seq, struct file *file)
38800 + err = au_seq_path(seq, &file->f_path);
38801 + if (unlikely(err))
38804 +#define Deleted "\\040(deleted)"
38805 + seq->count -= sizeof(Deleted) - 1;
38806 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38807 + sizeof(Deleted) - 1));
38813 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38814 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38815 +++ linux/include/uapi/linux/aufs_type.h 2019-11-25 12:42:00.275843147 +0100
38817 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38819 + * Copyright (C) 2005-2019 Junjiro R. Okajima
38821 + * This program, aufs is free software; you can redistribute it and/or modify
38822 + * it under the terms of the GNU General Public License as published by
38823 + * the Free Software Foundation; either version 2 of the License, or
38824 + * (at your option) any later version.
38826 + * This program is distributed in the hope that it will be useful,
38827 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38828 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38829 + * GNU General Public License for more details.
38831 + * You should have received a copy of the GNU General Public License
38832 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38835 +#ifndef __AUFS_TYPE_H__
38836 +#define __AUFS_TYPE_H__
38838 +#define AUFS_NAME "aufs"
38842 + * define it before including all other headers.
38843 + * sched.h may use pr_* macros before defining "current", so define the
38844 + * no-current version first, and re-define later.
38846 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38847 +#include <linux/sched.h>
38849 +#define pr_fmt(fmt) \
38850 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38851 + (int)sizeof(current->comm), current->comm, current->pid
38853 +#include <stdint.h>
38854 +#include <sys/types.h>
38855 +#endif /* __KERNEL__ */
38857 +#include <linux/limits.h>
38859 +#define AUFS_VERSION "5.x-rcN-20191021"
38861 +/* todo? move this to linux-2.6.19/include/magic.h */
38862 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38864 +/* ---------------------------------------------------------------------- */
38866 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38867 +typedef int8_t aufs_bindex_t;
38868 +#define AUFS_BRANCH_MAX 127
38870 +typedef int16_t aufs_bindex_t;
38871 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38872 +#define AUFS_BRANCH_MAX 511
38873 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38874 +#define AUFS_BRANCH_MAX 1023
38875 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38876 +#define AUFS_BRANCH_MAX 32767
38881 +#ifndef AUFS_BRANCH_MAX
38882 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38884 +#endif /* __KERNEL__ */
38886 +/* ---------------------------------------------------------------------- */
38888 +#define AUFS_FSTYPE AUFS_NAME
38890 +#define AUFS_ROOT_INO 2
38891 +#define AUFS_FIRST_INO 11
38893 +#define AUFS_WH_PFX ".wh."
38894 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38895 +#define AUFS_WH_TMP_LEN 4
38896 +/* a limit for rmdir/rename a dir and copyup */
38897 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38898 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38900 + - AUFS_WH_TMP_LEN) /* hex */
38901 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38902 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38903 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38904 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38905 +#define AUFS_DIRWH_DEF 3
38906 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38907 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38908 +#define AUFS_RDBLK_DEF 512 /* bytes */
38909 +#define AUFS_RDHASH_DEF 32
38910 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38911 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38912 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38913 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38914 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38916 +/* pseudo-link maintenace under /proc */
38917 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38918 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38919 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38921 +/* dirren, renamed dir */
38922 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38923 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38924 +/* whiteouted doubly */
38925 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38926 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38928 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38929 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38931 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38932 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38933 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38935 +/* doubly whiteouted */
38936 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38937 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38938 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38940 +/* branch permissions and attributes */
38941 +#define AUFS_BRPERM_RW "rw"
38942 +#define AUFS_BRPERM_RO "ro"
38943 +#define AUFS_BRPERM_RR "rr"
38944 +#define AUFS_BRATTR_COO_REG "coo_reg"
38945 +#define AUFS_BRATTR_COO_ALL "coo_all"
38946 +#define AUFS_BRATTR_FHSM "fhsm"
38947 +#define AUFS_BRATTR_UNPIN "unpin"
38948 +#define AUFS_BRATTR_ICEX "icex"
38949 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38950 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38951 +#define AUFS_BRATTR_ICEX_TR "icextr"
38952 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38953 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38954 +#define AUFS_BRRATTR_WH "wh"
38955 +#define AUFS_BRWATTR_NLWH "nolwh"
38956 +#define AUFS_BRWATTR_MOO "moo"
38958 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38959 +#define AuBrPerm_RO (1 << 1) /* readonly */
38960 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38961 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38963 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38964 +#define AuBrAttr_COO_ALL (1 << 4)
38965 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38967 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38968 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38969 + branch. meaningless since
38970 + linux-3.18-rc1 */
38972 +/* ignore error in copying XATTR */
38973 +#define AuBrAttr_ICEX_SEC (1 << 7)
38974 +#define AuBrAttr_ICEX_SYS (1 << 8)
38975 +#define AuBrAttr_ICEX_TR (1 << 9)
38976 +#define AuBrAttr_ICEX_USR (1 << 10)
38977 +#define AuBrAttr_ICEX_OTH (1 << 11)
38978 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38979 + | AuBrAttr_ICEX_SYS \
38980 + | AuBrAttr_ICEX_TR \
38981 + | AuBrAttr_ICEX_USR \
38982 + | AuBrAttr_ICEX_OTH)
38984 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38985 +#define AuBrRAttr_Mask AuBrRAttr_WH
38987 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38988 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38989 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38991 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38993 +/* #warning test userspace */
38995 +#ifndef CONFIG_AUFS_FHSM
38996 +#undef AuBrAttr_FHSM
38997 +#define AuBrAttr_FHSM 0
38999 +#ifndef CONFIG_AUFS_XATTR
39000 +#undef AuBrAttr_ICEX
39001 +#define AuBrAttr_ICEX 0
39002 +#undef AuBrAttr_ICEX_SEC
39003 +#define AuBrAttr_ICEX_SEC 0
39004 +#undef AuBrAttr_ICEX_SYS
39005 +#define AuBrAttr_ICEX_SYS 0
39006 +#undef AuBrAttr_ICEX_TR
39007 +#define AuBrAttr_ICEX_TR 0
39008 +#undef AuBrAttr_ICEX_USR
39009 +#define AuBrAttr_ICEX_USR 0
39010 +#undef AuBrAttr_ICEX_OTH
39011 +#define AuBrAttr_ICEX_OTH 0
39015 +/* the longest combination */
39016 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39017 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39018 + "+" AUFS_BRATTR_COO_REG \
39019 + "+" AUFS_BRATTR_FHSM \
39020 + "+" AUFS_BRATTR_UNPIN \
39021 + "+" AUFS_BRATTR_ICEX_SEC \
39022 + "+" AUFS_BRATTR_ICEX_SYS \
39023 + "+" AUFS_BRATTR_ICEX_USR \
39024 + "+" AUFS_BRATTR_ICEX_OTH \
39025 + "+" AUFS_BRWATTR_NLWH)
39028 + char a[AuBrPermStrSz];
39029 +} au_br_perm_str_t;
39031 +static inline int au_br_writable(int brperm)
39033 + return brperm & AuBrPerm_RW;
39036 +static inline int au_br_whable(int brperm)
39038 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39041 +static inline int au_br_wh_linkable(int brperm)
39043 + return !(brperm & AuBrWAttr_NoLinkWH);
39046 +static inline int au_br_cmoo(int brperm)
39048 + return brperm & AuBrAttr_CMOO_Mask;
39051 +static inline int au_br_fhsm(int brperm)
39053 + return brperm & AuBrAttr_FHSM;
39056 +/* ---------------------------------------------------------------------- */
39060 + /* readdir in userspace */
39064 + AuCtl_WBR_FD, /* pathconf wrapper */
39065 + AuCtl_IBUSY, /* busy inode */
39066 + AuCtl_MVDOWN, /* move-down */
39067 + AuCtl_BR, /* info about branches */
39068 + AuCtl_FHSM_FD /* connection for fhsm */
39071 +/* borrowed from linux/include/linux/kernel.h */
39073 +#ifdef _GNU_SOURCE
39074 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39076 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39078 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39081 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39083 +#define __aligned(x) __attribute__((aligned(x)))
39088 +#define __packed __attribute__((packed))
39092 +struct au_rdu_cookie {
39097 + uint32_t generation;
39100 +struct au_rdu_ent {
39109 +static inline int au_rdu_len(int nlen)
39111 + /* include the terminating NULL */
39112 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39113 + sizeof(uint64_t));
39116 +union au_rdu_ent_ul {
39117 + struct au_rdu_ent __user *e;
39129 + uint64_t sz; /* AuCtl_RDU */
39130 + uint64_t nent; /* AuCtl_RDU_INO */
39132 + union au_rdu_ent_ul ent;
39133 + uint16_t verify[AufsCtlRduV_End];
39135 + /* input/output */
39139 + union au_rdu_ent_ul tail;
39140 + /* number of entries which were added in a single call */
39145 + struct au_rdu_cookie cookie;
39148 +/* ---------------------------------------------------------------------- */
39150 +/* dirren. the branch is identified by the filename who contains this */
39151 +struct au_drinfo {
39154 + uint8_t oldnamelen;
39155 + uint64_t _padding;
39157 + uint8_t oldname[0];
39160 +struct au_drinfo_fdata {
39162 + struct au_drinfo drinfo;
39165 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39167 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39169 +/* ---------------------------------------------------------------------- */
39171 +struct aufs_wbr_fd {
39176 +/* ---------------------------------------------------------------------- */
39178 +struct aufs_ibusy {
39179 + uint64_t ino, h_ino;
39183 +/* ---------------------------------------------------------------------- */
39185 +/* error code for move-down */
39186 +/* the actual message strings are implemented in aufs-util.git */
39188 + EAU_MVDOWN_OPAQUE = 1,
39189 + EAU_MVDOWN_WHITEOUT,
39190 + EAU_MVDOWN_UPPER,
39191 + EAU_MVDOWN_BOTTOM,
39192 + EAU_MVDOWN_NOUPPER,
39193 + EAU_MVDOWN_NOLOWERBR,
39197 +/* flags for move-down */
39198 +#define AUFS_MVDOWN_DMSG 1
39199 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39200 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39201 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39202 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39203 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39204 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39205 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39206 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39207 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39208 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39209 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39210 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39212 +/* index for move-down */
39214 + AUFS_MVDOWN_UPPER,
39215 + AUFS_MVDOWN_LOWER,
39216 + AUFS_MVDOWN_NARRAY
39220 + * additional info of move-down
39221 + * number of free blocks and inodes.
39222 + * subset of struct kstatfs, but smaller and always 64bit.
39224 +struct aufs_stfs {
39225 + uint64_t f_blocks;
39226 + uint64_t f_bavail;
39227 + uint64_t f_files;
39228 + uint64_t f_ffree;
39231 +struct aufs_stbr {
39232 + int16_t brid; /* optional input */
39233 + int16_t bindex; /* output */
39234 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39237 +struct aufs_mvdown {
39238 + uint32_t flags; /* input/output */
39239 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39240 + int8_t au_errno; /* output */
39243 +/* ---------------------------------------------------------------------- */
39245 +union aufs_brinfo {
39246 + /* PATH_MAX may differ between kernel-space and user-space */
39247 + char _spacer[4096];
39255 +/* ---------------------------------------------------------------------- */
39257 +#define AuCtlType 'A'
39258 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39259 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39260 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39261 + struct aufs_wbr_fd)
39262 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39263 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39264 + struct aufs_mvdown)
39265 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39266 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39268 +#endif /* __AUFS_TYPE_H__ */
39269 SPDX-License-Identifier: GPL-2.0
39270 aufs5.x-rcN loopback patch
39272 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39273 index 80d06084b043..a83cdfec7359 100644
39274 --- a/drivers/block/loop.c
39275 +++ b/drivers/block/loop.c
39276 @@ -625,6 +625,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39280 +static struct file *loop_real_file(struct file *file)
39282 + struct file *f = NULL;
39284 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39285 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39289 static void loop_reread_partitions(struct loop_device *lo,
39290 struct block_device *bdev)
39292 @@ -678,6 +687,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39295 struct file *file = NULL, *old_file;
39296 + struct file *f, *virt_file = NULL, *old_virt_file;
39300 @@ -697,12 +707,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39304 + f = loop_real_file(file);
39306 + virt_file = file;
39311 error = loop_validate_file(file, bdev);
39315 old_file = lo->lo_backing_file;
39316 + old_virt_file = lo->lo_backing_virt_file;
39320 @@ -714,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39321 blk_mq_freeze_queue(lo->lo_queue);
39322 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39323 lo->lo_backing_file = file;
39324 + lo->lo_backing_virt_file = virt_file;
39325 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39326 mapping_set_gfp_mask(file->f_mapping,
39327 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39328 @@ -727,6 +745,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39332 + if (old_virt_file)
39333 + fput(old_virt_file);
39335 loop_reread_partitions(lo, bdev);
39337 @@ -735,6 +755,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39338 mutex_unlock(&loop_ctl_mutex);
39346 @@ -939,7 +961,7 @@ static void loop_update_rotational(struct loop_device *lo)
39347 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39348 struct block_device *bdev, unsigned int arg)
39350 - struct file *file;
39351 + struct file *file, *f, *virt_file = NULL;
39352 struct inode *inode;
39353 struct address_space *mapping;
39354 struct block_device *claimed_bdev = NULL;
39355 @@ -955,6 +977,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39359 + f = loop_real_file(file);
39361 + virt_file = file;
39367 * If we don't hold exclusive handle for the device, upgrade to it
39368 @@ -1003,6 +1031,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39369 lo->lo_device = bdev;
39370 lo->lo_flags = lo_flags;
39371 lo->lo_backing_file = file;
39372 + lo->lo_backing_virt_file = virt_file;
39373 lo->transfer = NULL;
39375 lo->lo_sizelimit = 0;
39376 @@ -1046,6 +1075,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39377 bd_abort_claiming(bdev, claimed_bdev, loop_set_fd);
39383 /* This is safe: open() is still holding a reference. */
39384 module_put(THIS_MODULE);
39385 @@ -1092,6 +1123,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39386 static int __loop_clr_fd(struct loop_device *lo, bool release)
39388 struct file *filp = NULL;
39389 + struct file *virt_filp = lo->lo_backing_virt_file;
39390 gfp_t gfp = lo->old_gfp_mask;
39391 struct block_device *bdev = lo->lo_device;
39393 @@ -1115,6 +1147,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39395 spin_lock_irq(&lo->lo_lock);
39396 lo->lo_backing_file = NULL;
39397 + lo->lo_backing_virt_file = NULL;
39398 spin_unlock_irq(&lo->lo_lock);
39400 loop_release_xfer(lo);
39401 @@ -1197,6 +1230,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39410 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39411 index af75a5ee4094..1e6ee5a4f623 100644
39412 --- a/drivers/block/loop.h
39413 +++ b/drivers/block/loop.h
39414 @@ -46,7 +46,7 @@ struct loop_device {
39415 int (*ioctl)(struct loop_device *, int cmd,
39416 unsigned long arg);
39418 - struct file * lo_backing_file;
39419 + struct file * lo_backing_file, *lo_backing_virt_file;
39420 struct block_device *lo_device;
39423 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39424 index 0309f0d502ff..19feb4f3cb5f 100644
39425 --- a/fs/aufs/f_op.c
39426 +++ b/fs/aufs/f_op.c
39427 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39428 if (IS_ERR(h_file))
39431 - if (au_test_loopback_kthread()) {
39432 + if (0 && au_test_loopback_kthread()) {
39433 au_warn_loopback(h_file->f_path.dentry->d_sb);
39434 if (file->f_mapping != h_file->f_mapping) {
39435 file->f_mapping = h_file->f_mapping;
39436 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39437 index 9ba35a878ecd..4ed0ff03d5ab 100644
39438 --- a/fs/aufs/loop.c
39439 +++ b/fs/aufs/loop.c
39440 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39441 symbol_put(loop_backing_file);
39442 au_kfree_try_rcu(au_warn_loopback_array);
39445 +/* ---------------------------------------------------------------------- */
39447 +/* support the loopback block device insude aufs */
39449 +struct file *aufs_real_loop(struct file *file)
39453 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39454 + fi_read_lock(file);
39455 + f = au_hf_top(file);
39456 + fi_read_unlock(file);
39460 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39461 index f31e40aff267..e13fb1a0717a 100644
39462 --- a/fs/aufs/loop.h
39463 +++ b/fs/aufs/loop.h
39464 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39466 int au_loopback_init(void);
39467 void au_loopback_fin(void);
39469 +struct file *aufs_real_loop(struct file *file);
39471 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39473 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39475 AuStubInt0(au_loopback_init, void)
39476 AuStubVoid(au_loopback_fin, void)
39478 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39479 #endif /* BLK_DEV_LOOP */
39481 #endif /* __KERNEL__ */
39482 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39483 index a97e2921cb09..f74eb6962684 100644
39484 --- a/fs/aufs/super.c
39485 +++ b/fs/aufs/super.c
39486 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39487 .statfs = aufs_statfs,
39488 .put_super = aufs_put_super,
39489 .sync_fs = aufs_sync_fs,
39490 - .remount_fs = aufs_remount_fs
39491 + .remount_fs = aufs_remount_fs,
39492 +#ifdef CONFIG_AUFS_BDEV_LOOP
39493 + .real_loop = aufs_real_loop
39497 /* ---------------------------------------------------------------------- */
39498 diff --git a/include/linux/fs.h b/include/linux/fs.h
39499 index 3dbec51c2037..38ab7b6c7c6d 100644
39500 --- a/include/linux/fs.h
39501 +++ b/include/linux/fs.h
39502 @@ -1948,6 +1948,10 @@ struct super_operations {
39503 struct shrink_control *);
39504 long (*free_cached_objects)(struct super_block *,
39505 struct shrink_control *);
39506 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39508 + struct file *(*real_loop)(struct file *);