1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index 2501e6f1f965..38a6a5991da9 100644
8 @@ -264,6 +264,7 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/erofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 14231b4cf383..8765e191ebe0 100644
20 @@ -132,3 +132,4 @@ obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 obj-$(CONFIG_EROFS_FS) += erofs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 9d3a5c54a41d..f33398b47c42 100644
32 @@ -2832,6 +2832,19 @@ F: include/linux/audit.h
33 F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
40 +W: http://aufs.sourceforge.net
41 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/filesystems/aufs/
44 +F: Documentation/ABI/testing/debugfs-aufs
45 +F: Documentation/ABI/testing/sysfs-aufs
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index f6f77eaa7217..5e094699215e 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -738,6 +738,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index e88cf0554e65..7ce4ccf5a51c 100644
85 @@ -1264,7 +1264,7 @@ enum d_walk_ret {
87 * The @enter() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index 3d40771e8e7c..12dd73930961 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/inode.c b/fs/inode.c
117 index fef457a42882..aaeacde398ee 100644
120 @@ -1673,7 +1673,7 @@ EXPORT_SYMBOL(generic_update_time);
121 * This does the actual work of updating an inodes time or version. Must have
122 * had called mnt_want_write() before calling this.
124 -static int update_time(struct inode *inode, struct timespec64 *time, int flags)
125 +int update_time(struct inode *inode, struct timespec64 *time, int flags)
127 int (*update_time)(struct inode *, struct timespec64 *, int);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index 2adfe7b166a3..0f7e57e5f4b7 100644
133 @@ -776,6 +776,12 @@ static inline int check_mnt(struct mount *mnt)
134 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137 +/* for aufs, CONFIG_AUFS_BR_FUSE */
138 +int is_current_mnt_ns(struct vfsmount *mnt)
140 + return check_mnt(real_mount(mnt));
144 * vfsmount lock must be held for write
146 diff --git a/fs/read_write.c b/fs/read_write.c
147 index 5bbf587f5bc1..fa9b3994b34c 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -498,6 +498,28 @@ static ssize_t __vfs_write(struct file *file, const char __user *p,
154 +vfs_readf_t vfs_readf(struct file *file)
156 + const struct file_operations *fop = file->f_op;
160 + if (fop->read_iter)
161 + return new_sync_read;
162 + return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
165 +vfs_writef_t vfs_writef(struct file *file)
167 + const struct file_operations *fop = file->f_op;
171 + if (fop->write_iter)
172 + return new_sync_write;
173 + return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
176 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
179 diff --git a/fs/splice.c b/fs/splice.c
180 index 98412721f056..75b489fcb66f 100644
183 @@ -834,8 +834,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
185 * Attempt to initiate a splice from pipe to file.
187 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
188 - loff_t *ppos, size_t len, unsigned int flags)
189 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
190 + loff_t *ppos, size_t len, unsigned int flags)
192 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
193 loff_t *, size_t, unsigned int);
194 @@ -851,9 +851,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
196 * Attempt to initiate a splice from a file to a pipe.
198 -static long do_splice_to(struct file *in, loff_t *ppos,
199 - struct pipe_inode_info *pipe, size_t len,
200 - unsigned int flags)
201 +long do_splice_to(struct file *in, loff_t *ppos,
202 + struct pipe_inode_info *pipe, size_t len,
203 + unsigned int flags)
205 ssize_t (*splice_read)(struct file *, loff_t *,
206 struct pipe_inode_info *, size_t, unsigned int);
207 diff --git a/fs/sync.c b/fs/sync.c
208 index 4d1ff010bc5a..457f4e4a5cc1 100644
212 * wait == 1 case since in that case write_inode() functions do
213 * sync_dirty_buffer() and thus effectively write one block at a time.
215 -static int __sync_filesystem(struct super_block *sb, int wait)
216 +int __sync_filesystem(struct super_block *sb, int wait)
220 diff --git a/include/linux/fs.h b/include/linux/fs.h
221 index e0d909d35763..381a13995011 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1349,6 +1349,7 @@ extern void fasync_free(struct fasync_struct *);
225 /* can be called from interrupts */
226 extern void kill_fasync(struct fasync_struct **, int, int);
228 +extern int setfl(int fd, struct file *filp, unsigned long arg);
229 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
230 extern int f_setown(struct file *filp, unsigned long arg, int force);
231 extern void f_delown(struct file *filp);
232 @@ -1835,6 +1836,7 @@ struct file_operations {
233 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
234 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
235 int (*check_flags)(int);
236 + int (*setfl)(struct file *, unsigned long);
237 int (*flock) (struct file *, int, struct file_lock *);
238 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
239 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
240 @@ -1905,6 +1907,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
241 struct iovec *fast_pointer,
242 struct iovec **ret_pointer);
244 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
245 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
247 +vfs_readf_t vfs_readf(struct file *file);
248 +vfs_writef_t vfs_writef(struct file *file);
250 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
251 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
252 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
253 @@ -2325,6 +2333,7 @@ extern int current_umask(void);
254 extern void ihold(struct inode * inode);
255 extern void iput(struct inode *);
256 extern int generic_update_time(struct inode *, struct timespec64 *, int);
257 +extern int update_time(struct inode *, struct timespec64 *, int);
260 extern struct kobject *fs_kobj;
261 @@ -2613,6 +2622,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
265 +extern int __sync_filesystem(struct super_block *, int);
266 extern int sync_filesystem(struct super_block *);
267 extern const struct file_operations def_blk_fops;
268 extern const struct file_operations def_chr_fops;
269 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
270 index b8a835fd611b..f452521f2e05 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -331,6 +331,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
274 return lock->key == key;
277 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
282 @@ -473,6 +475,7 @@ struct lockdep_map { };
284 #define lockdep_depth(tsk) (0)
286 +#define lockdep_is_held(lock) (1)
287 #define lockdep_is_held_type(l, r) (1)
289 #define lockdep_assert_held(l) do { (void)(l); } while (0)
290 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
291 index 35942084cd40..24f5fd1a789d 100644
292 --- a/include/linux/mnt_namespace.h
293 +++ b/include/linux/mnt_namespace.h
295 struct mnt_namespace;
297 struct user_namespace;
300 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
301 struct user_namespace *, struct fs_struct *);
302 extern void put_mnt_ns(struct mnt_namespace *ns);
304 +extern int is_current_mnt_ns(struct vfsmount *mnt);
306 extern const struct file_operations proc_mounts_operations;
307 extern const struct file_operations proc_mountinfo_operations;
308 extern const struct file_operations proc_mountstats_operations;
309 diff --git a/include/linux/splice.h b/include/linux/splice.h
310 index 74b4911ac16d..19789fbea567 100644
311 --- a/include/linux/splice.h
312 +++ b/include/linux/splice.h
313 @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
315 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
316 extern const struct pipe_buf_operations default_pipe_buf_ops;
318 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
319 + loff_t *ppos, size_t len, unsigned int flags);
320 +extern long do_splice_to(struct file *in, loff_t *ppos,
321 + struct pipe_inode_info *pipe, size_t len,
322 + unsigned int flags);
324 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
325 index 233459c03b5a..407c08ac8ac8 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -153,7 +153,7 @@ static
329 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
330 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
332 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
333 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
335 unsigned int class_idx = hlock->class_idx;
337 @@ -174,6 +174,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
339 return lock_classes + class_idx;
341 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
343 #ifdef CONFIG_LOCK_STAT
344 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
345 SPDX-License-Identifier: GPL-2.0
348 diff --git a/fs/proc/base.c b/fs/proc/base.c
349 index ebea9501afb8..dc7edc5f7267 100644
352 @@ -2037,7 +2037,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
354 vma = find_exact_vma(mm, vm_start, vm_end);
355 if (vma && vma->vm_file) {
356 - *path = vma->vm_file->f_path;
357 + *path = vma_pr_or_file(vma)->f_path;
361 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
362 index 14c2badb8fd9..65afe5287e43 100644
363 --- a/fs/proc/nommu.c
364 +++ b/fs/proc/nommu.c
365 @@ -41,7 +41,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
366 file = region->vm_file;
369 - struct inode *inode = file_inode(region->vm_file);
370 + struct inode *inode;
372 + file = vmr_pr_or_file(region);
373 + inode = file_inode(file);
374 dev = inode->i_sb->s_dev;
377 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
378 index 9442631fd4af..1fa8a5fcdeee 100644
379 --- a/fs/proc/task_mmu.c
380 +++ b/fs/proc/task_mmu.c
381 @@ -309,7 +309,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
382 const char *name = NULL;
385 - struct inode *inode = file_inode(vma->vm_file);
386 + struct inode *inode;
388 + file = vma_pr_or_file(vma);
389 + inode = file_inode(file);
390 dev = inode->i_sb->s_dev;
392 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
393 @@ -1819,7 +1822,7 @@ static int show_numa_map(struct seq_file *m, void *v)
394 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
395 struct vm_area_struct *vma = v;
396 struct numa_maps *md = &numa_priv->md;
397 - struct file *file = vma->vm_file;
398 + struct file *file = vma_pr_or_file(vma);
399 struct mm_struct *mm = vma->vm_mm;
400 struct mempolicy *pol;
402 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
403 index 7907e6419e57..d17209cf52bc 100644
404 --- a/fs/proc/task_nommu.c
405 +++ b/fs/proc/task_nommu.c
406 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
410 - struct inode *inode = file_inode(vma->vm_file);
411 + struct inode *inode;
413 + file = vma_pr_or_file(vma);
414 + inode = file_inode(file);
415 dev = inode->i_sb->s_dev;
417 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
418 diff --git a/include/linux/mm.h b/include/linux/mm.h
419 index a2adf95b3f9c..70e1dccc1283 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1510,6 +1510,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
423 unmap_mapping_range(mapping, holebegin, holelen, 0);
426 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
427 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
429 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
430 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
432 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
434 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
436 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
437 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
440 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
441 +extern void vmr_do_fput(struct vm_region *, const char[], int);
443 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
445 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
446 +#endif /* !CONFIG_MMU */
448 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
449 void *buf, int len, unsigned int gup_flags);
450 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
451 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
452 index 270aa8fd2800..33848c2165e2 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -267,6 +267,7 @@ struct vm_region {
456 unsigned long vm_top; /* region allocated to here */
457 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
458 struct file *vm_file; /* the backing file or NULL */
459 + struct file *vm_prfile; /* the virtual backing file or NULL */
461 int vm_usage; /* region usage count (access under nommu_region_sem) */
462 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
463 @@ -341,6 +342,7 @@ struct vm_area_struct {
464 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
466 struct file * vm_file; /* File we map to (can be NULL). */
467 + struct file *vm_prfile; /* shadow of vm_file */
468 void * vm_private_data; /* was vm_pte (shared mem) */
471 diff --git a/kernel/fork.c b/kernel/fork.c
472 index 13b38794efb5..ede7225bae95 100644
475 @@ -562,7 +562,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
476 struct inode *inode = file_inode(file);
477 struct address_space *mapping = file->f_mapping;
481 if (tmp->vm_flags & VM_DENYWRITE)
482 atomic_dec(&inode->i_writecount);
483 i_mmap_lock_write(mapping);
484 diff --git a/mm/Makefile b/mm/Makefile
485 index d996846697ef..fbadb91df4e4 100644
488 @@ -42,7 +42,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
489 mm_init.o mmu_context.o percpu.o slab_common.o \
490 compaction.o vmacache.o \
491 interval_tree.o list_lru.o workingset.o \
492 - debug.o gup.o $(mmu-y)
493 + prfile.o debug.o gup.o $(mmu-y)
495 # Give 'page_alloc' its own module-parameter namespace
496 page-alloc-y := page_alloc.o
497 diff --git a/mm/filemap.c b/mm/filemap.c
498 index 85b7d087eb45..115275a4a0e2 100644
501 @@ -2696,7 +2696,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
502 vm_fault_t ret = VM_FAULT_LOCKED;
504 sb_start_pagefault(inode->i_sb);
505 - file_update_time(vmf->vma->vm_file);
506 + vma_file_update_time(vmf->vma);
508 if (page->mapping != inode->i_mapping) {
510 diff --git a/mm/mmap.c b/mm/mmap.c
511 index a7d8c84d19b7..9c350dc3f570 100644
514 @@ -182,7 +182,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
515 if (vma->vm_ops && vma->vm_ops->close)
516 vma->vm_ops->close(vma);
518 - fput(vma->vm_file);
520 mpol_put(vma_policy(vma));
523 @@ -940,7 +940,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
526 uprobe_munmap(next, next->vm_start, next->vm_end);
531 anon_vma_merge(vma, next);
532 @@ -1865,8 +1865,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
540 /* Undo any partial mapping done by a device driver. */
541 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
542 @@ -2695,7 +2695,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
546 - get_file(new->vm_file);
549 if (new->vm_ops && new->vm_ops->open)
550 new->vm_ops->open(new);
551 @@ -2714,7 +2714,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
552 if (new->vm_ops && new->vm_ops->close)
553 new->vm_ops->close(new);
555 - fput(new->vm_file);
557 unlink_anon_vmas(new);
559 mpol_put(vma_policy(new));
560 @@ -2906,7 +2906,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
561 struct vm_area_struct *vma;
562 unsigned long populate = 0;
563 unsigned long ret = -EINVAL;
565 + struct file *file, *prfile;
567 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
568 current->comm, current->pid);
569 @@ -2981,10 +2981,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 - file = get_file(vma->vm_file);
575 + file = vma->vm_file;
576 + prfile = vma->vm_prfile;
577 ret = do_mmap_pgoff(vma->vm_file, start, size,
578 prot, flags, pgoff, &populate, NULL);
579 + if (!IS_ERR_VALUE(ret) && file && prfile) {
580 + struct vm_area_struct *new_vma;
582 + new_vma = find_vma(mm, ret);
583 + if (!new_vma->vm_prfile)
584 + new_vma->vm_prfile = prfile;
585 + if (new_vma != vma)
589 + * two fput()s instead of vma_fput(vma),
590 + * coz vma may not be available anymore.
596 up_write(&mm->mmap_sem);
598 @@ -3274,7 +3291,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
599 if (anon_vma_clone(new_vma, vma))
600 goto out_free_mempol;
601 if (new_vma->vm_file)
602 - get_file(new_vma->vm_file);
603 + vma_get_file(new_vma);
604 if (new_vma->vm_ops && new_vma->vm_ops->open)
605 new_vma->vm_ops->open(new_vma);
606 vma_link(mm, new_vma, prev, rb_link, rb_parent);
607 diff --git a/mm/nommu.c b/mm/nommu.c
608 index 99b7ec318824..de5b6cd162fe 100644
611 @@ -552,7 +552,7 @@ static void __put_nommu_region(struct vm_region *region)
612 up_write(&nommu_region_sem);
615 - fput(region->vm_file);
618 /* IO memory and memory shared directly out of the pagecache
619 * from ramfs/tmpfs mustn't be released here */
620 @@ -690,7 +690,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
621 if (vma->vm_ops && vma->vm_ops->close)
622 vma->vm_ops->close(vma);
624 - fput(vma->vm_file);
626 put_nommu_region(vma->vm_region);
629 @@ -1213,7 +1213,7 @@ unsigned long do_mmap(struct file *file,
630 goto error_just_free;
633 - fput(region->vm_file);
635 kmem_cache_free(vm_region_jar, region);
638 @@ -1290,10 +1290,10 @@ unsigned long do_mmap(struct file *file,
639 up_write(&nommu_region_sem);
642 - fput(region->vm_file);
644 kmem_cache_free(vm_region_jar, region);
646 - fput(vma->vm_file);
651 diff --git a/mm/prfile.c b/mm/prfile.c
653 index 000000000000..00d51187c325
657 +// SPDX-License-Identifier: GPL-2.0
659 + * Mainly for aufs which mmap(2) different file and wants to print different
660 + * path in /proc/PID/maps.
661 + * Call these functions via macros defined in linux/mm.h.
663 + * See Documentation/filesystems/aufs/design/06mmap.txt
665 + * Copyright (c) 2014-2020 Junjro R. Okajima
666 + * Copyright (c) 2014 Ian Campbell
669 +#include <linux/mm.h>
670 +#include <linux/file.h>
671 +#include <linux/fs.h>
673 +/* #define PRFILE_TRACE */
674 +static inline void prfile_trace(struct file *f, struct file *pr,
675 + const char func[], int line, const char func2[])
679 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
683 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
686 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
688 + prfile_trace(f, pr, func, line, __func__);
689 + file_update_time(f);
691 + file_update_time(pr);
694 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
697 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
699 + prfile_trace(f, pr, func, line, __func__);
700 + return (f && pr) ? pr : f;
703 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
705 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
707 + prfile_trace(f, pr, func, line, __func__);
713 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
715 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
717 + prfile_trace(f, pr, func, line, __func__);
724 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
727 + struct file *f = region->vm_file, *pr = region->vm_prfile;
729 + prfile_trace(f, pr, func, line, __func__);
730 + return (f && pr) ? pr : f;
733 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
735 + struct file *f = region->vm_file, *pr = region->vm_prfile;
737 + prfile_trace(f, pr, func, line, __func__);
742 +#endif /* !CONFIG_MMU */
743 SPDX-License-Identifier: GPL-2.0
744 aufs5.4 standalone patch
746 diff --git a/fs/dcache.c b/fs/dcache.c
747 index 7ce4ccf5a51c..00d7e6a08026 100644
750 @@ -1369,6 +1369,7 @@ void d_walk(struct dentry *parent, void *data,
754 +EXPORT_SYMBOL_GPL(d_walk);
757 struct vfsmount *mnt;
758 @@ -2914,6 +2915,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
760 write_sequnlock(&rename_lock);
762 +EXPORT_SYMBOL_GPL(d_exchange);
765 * d_ancestor - search for an ancestor
766 diff --git a/fs/exec.c b/fs/exec.c
767 index 555e93c7dec8..dad39c6b3878 100644
770 @@ -110,6 +110,7 @@ bool path_noexec(const struct path *path)
771 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
772 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
774 +EXPORT_SYMBOL_GPL(path_noexec);
778 diff --git a/fs/fcntl.c b/fs/fcntl.c
779 index 12dd73930961..0468c845190f 100644
782 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
786 +EXPORT_SYMBOL_GPL(setfl);
788 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
790 diff --git a/fs/file_table.c b/fs/file_table.c
791 index 30d55c9a1744..34b9bbf4c556 100644
792 --- a/fs/file_table.c
793 +++ b/fs/file_table.c
794 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
796 return ERR_PTR(-ENFILE);
798 +EXPORT_SYMBOL_GPL(alloc_empty_file);
801 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
802 @@ -375,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 aaeacde398ee..5be87f2d3828 100644
814 @@ -1682,6 +1682,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 0f7e57e5f4b7..516c2f397d33 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 @@ -1903,6 +1905,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 diff --git a/fs/notify/group.c b/fs/notify/group.c
851 index 133f723aca07..0b9f7f6d8390 100644
852 --- a/fs/notify/group.c
853 +++ b/fs/notify/group.c
854 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
856 refcount_inc(&group->refcnt);
858 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
861 * Drop a reference to a group. Free it if it's through.
862 diff --git a/fs/open.c b/fs/open.c
863 index b62f5c0923a8..89af4b9c7319 100644
866 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
867 inode_unlock(dentry->d_inode);
870 +EXPORT_SYMBOL_GPL(do_truncate);
872 long vfs_truncate(const struct path *path, loff_t length)
874 diff --git a/fs/read_write.c b/fs/read_write.c
875 index fa9b3994b34c..eb0e2c6ebaff 100644
876 --- a/fs/read_write.c
877 +++ b/fs/read_write.c
878 @@ -468,6 +468,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
882 +EXPORT_SYMBOL_GPL(vfs_read);
884 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
886 @@ -508,6 +509,7 @@ vfs_readf_t vfs_readf(struct file *file)
887 return new_sync_read;
888 return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
890 +EXPORT_SYMBOL_GPL(vfs_readf);
892 vfs_writef_t vfs_writef(struct file *file)
894 @@ -519,6 +521,7 @@ vfs_writef_t vfs_writef(struct file *file)
895 return new_sync_write;
896 return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
898 +EXPORT_SYMBOL_GPL(vfs_writef);
900 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
902 @@ -588,6 +591,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
906 +EXPORT_SYMBOL_GPL(vfs_write);
908 /* file_ppos returns &file->f_pos or NULL if file is stream */
909 static inline loff_t *file_ppos(struct file *file)
910 diff --git a/fs/splice.c b/fs/splice.c
911 index 75b489fcb66f..0a1f7498c22b 100644
914 @@ -847,6 +847,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
916 return splice_write(pipe, out, ppos, len, flags);
918 +EXPORT_SYMBOL_GPL(do_splice_from);
921 * Attempt to initiate a splice from a file to a pipe.
922 @@ -876,6 +877,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
924 return splice_read(in, ppos, pipe, len, flags);
926 +EXPORT_SYMBOL_GPL(do_splice_to);
929 * splice_direct_to_actor - splices data directly between two non-pipes
930 diff --git a/fs/sync.c b/fs/sync.c
931 index 457f4e4a5cc1..67c66358f3fe 100644
934 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
935 sb->s_op->sync_fs(sb, wait);
936 return __sync_blockdev(sb->s_bdev, wait);
938 +EXPORT_SYMBOL_GPL(__sync_filesystem);
941 * Write out and wait upon all dirty data associated with this
942 diff --git a/fs/xattr.c b/fs/xattr.c
943 index 90dd78f0eb27..40b01dd1b14a 100644
946 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
947 *xattr_value = value;
950 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
953 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
954 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
955 index 407c08ac8ac8..d7f71842f8a2 100644
956 --- a/kernel/locking/lockdep.c
957 +++ b/kernel/locking/lockdep.c
958 @@ -174,6 +174,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
960 return lock_classes + class_idx;
962 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
963 #define hlock_class(hlock) lockdep_hlock_class(hlock)
965 #ifdef CONFIG_LOCK_STAT
966 diff --git a/kernel/task_work.c b/kernel/task_work.c
967 index 0fef395662a6..83fb1ecfc33d 100644
968 --- a/kernel/task_work.c
969 +++ b/kernel/task_work.c
970 @@ -116,3 +116,4 @@ void task_work_run(void)
974 +EXPORT_SYMBOL_GPL(task_work_run);
975 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
976 index 725674f3276d..83f6494c52a2 100644
977 --- a/security/device_cgroup.c
978 +++ b/security/device_cgroup.c
979 @@ -824,3 +824,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
983 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
984 diff --git a/security/security.c b/security/security.c
985 index 1bc000f834e2..306f2c9f7ee2 100644
986 --- a/security/security.c
987 +++ b/security/security.c
988 @@ -1036,6 +1036,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
990 return call_int_hook(path_rmdir, 0, dir, dentry);
992 +EXPORT_SYMBOL_GPL(security_path_rmdir);
994 int security_path_unlink(const struct path *dir, struct dentry *dentry)
996 @@ -1052,6 +1053,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
998 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1000 +EXPORT_SYMBOL_GPL(security_path_symlink);
1002 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1003 struct dentry *new_dentry)
1004 @@ -1060,6 +1062,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1006 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1008 +EXPORT_SYMBOL_GPL(security_path_link);
1010 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1011 const struct path *new_dir, struct dentry *new_dentry,
1012 @@ -1087,6 +1090,7 @@ int security_path_truncate(const struct path *path)
1014 return call_int_hook(path_truncate, 0, path);
1016 +EXPORT_SYMBOL_GPL(security_path_truncate);
1018 int security_path_chmod(const struct path *path, umode_t mode)
1020 @@ -1094,6 +1098,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1022 return call_int_hook(path_chmod, 0, path, mode);
1024 +EXPORT_SYMBOL_GPL(security_path_chmod);
1026 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1028 @@ -1101,6 +1106,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1030 return call_int_hook(path_chown, 0, path, uid, gid);
1032 +EXPORT_SYMBOL_GPL(security_path_chown);
1034 int security_path_chroot(const struct path *path)
1036 @@ -1201,6 +1207,7 @@ int security_inode_permission(struct inode *inode, int mask)
1038 return call_int_hook(inode_permission, 0, inode, mask);
1040 +EXPORT_SYMBOL_GPL(security_inode_permission);
1042 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1044 @@ -1378,6 +1385,7 @@ int security_file_permission(struct file *file, int mask)
1046 return fsnotify_perm(file, mask);
1048 +EXPORT_SYMBOL_GPL(security_file_permission);
1050 int security_file_alloc(struct file *file)
1052 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1053 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1054 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200
1056 +What: /debug/aufs/si_<id>/
1058 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1060 + Under /debug/aufs, a directory named si_<id> is created
1061 + per aufs mount, where <id> is a unique id generated
1064 +What: /debug/aufs/si_<id>/plink
1066 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1068 + It has three lines and shows the information about the
1069 + pseudo-link. The first line is a single number
1070 + representing a number of buckets. The second line is a
1071 + number of pseudo-links per buckets (separated by a
1072 + blank). The last line is a single number representing a
1073 + total number of psedo-links.
1074 + When the aufs mount option 'noplink' is specified, it
1075 + will show "1\n0\n0\n".
1077 +What: /debug/aufs/si_<id>/xib
1079 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1081 + It shows the consumed blocks by xib (External Inode Number
1082 + Bitmap), its block size and file size.
1083 + When the aufs mount option 'noxino' is specified, it
1084 + will be empty. About XINO files, see the aufs manual.
1086 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1088 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1090 + It shows the consumed blocks by xino (External Inode Number
1091 + Translation Table), its link count, block size and file
1093 + Due to the file size limit, there may exist multiple
1094 + xino files per branch. In this case, "-N" is added to
1095 + the filename and it corresponds to the index of the
1096 + internal xino array. "-0" is omitted.
1097 + When the aufs mount option 'noxino' is specified, Those
1098 + entries won't exist. About XINO files, see the aufs
1101 +What: /debug/aufs/si_<id>/xigen
1103 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1105 + It shows the consumed blocks by xigen (External Inode
1106 + Generation Table), its block size and file size.
1107 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1109 + When the aufs mount option 'noxino' is specified, it
1110 + will be empty. About XINO files, see the aufs manual.
1111 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1112 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1113 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200
1115 +What: /sys/fs/aufs/si_<id>/
1117 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1119 + Under /sys/fs/aufs, a directory named si_<id> is created
1120 + per aufs mount, where <id> is a unique id generated
1123 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1125 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1127 + It shows the abolute path of a member directory (which
1128 + is called branch) in aufs, and its permission.
1130 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1132 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1134 + It shows the id of a member directory (which is called
1137 +What: /sys/fs/aufs/si_<id>/xi_path
1139 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1141 + It shows the abolute path of XINO (External Inode Number
1142 + Bitmap, Translation Table and Generation Table) file
1143 + even if it is the default path.
1144 + When the aufs mount option 'noxino' is specified, it
1145 + will be empty. About XINO files, see the aufs manual.
1146 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1147 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1148 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2020-01-27 10:57:18.162204582 +0100
1151 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1153 +# This program is free software; you can redistribute it and/or modify
1154 +# it under the terms of the GNU General Public License as published by
1155 +# the Free Software Foundation; either version 2 of the License, or
1156 +# (at your option) any later version.
1158 +# This program is distributed in the hope that it will be useful,
1159 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1160 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1161 +# GNU General Public License for more details.
1163 +# You should have received a copy of the GNU General Public License
1164 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1167 +----------------------------------------
1169 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1170 +1. abbrev. for "advanced multi-layered unification filesystem".
1171 +2. abbrev. for "another unionfs".
1172 +3. abbrev. for "auf das" in German which means "on the" in English.
1173 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1174 + But "Filesystem aufs Filesystem" is hard to understand.
1175 +4. abbrev. for "African Urban Fashion Show".
1177 +AUFS is a filesystem with features:
1178 +- multi layered stackable unification filesystem, the member directory
1179 + is called as a branch.
1180 +- branch permission and attribute, 'readonly', 'real-readonly',
1181 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1183 +- internal "file copy-on-write".
1184 +- logical deletion, whiteout.
1185 +- dynamic branch manipulation, adding, deleting and changing permission.
1186 +- allow bypassing aufs, user's direct branch access.
1187 +- external inode number translation table and bitmap which maintains the
1188 + persistent aufs inode number.
1189 +- seekable directory, including NFS readdir.
1190 +- file mapping, mmap and sharing pages.
1191 +- pseudo-link, hardlink over branches.
1192 +- loopback mounted filesystem as a branch.
1193 +- several policies to select one among multiple writable branches.
1194 +- revert a single systemcall when an error occurs in aufs.
1198 +Multi Layered Stackable Unification Filesystem
1199 +----------------------------------------------------------------------
1200 +Most people already knows what it is.
1201 +It is a filesystem which unifies several directories and provides a
1202 +merged single directory. When users access a file, the access will be
1203 +passed/re-directed/converted (sorry, I am not sure which English word is
1204 +correct) to the real file on the member filesystem. The member
1205 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1206 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1207 +readonly branch is handled by creating 'whiteout' on the upper writable
1210 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1211 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1212 +different approaches to implement the merged-view.
1213 +The former tries putting it into VFS, and the latter implements as a
1214 +separate filesystem.
1215 +(If I misunderstand about these implementations, please let me know and
1216 +I shall correct it. Because it is a long time ago when I read their
1217 +source files last time).
1219 +UnionMount's approach will be able to small, but may be hard to share
1220 +branches between several UnionMount since the whiteout in it is
1221 +implemented in the inode on branch filesystem and always
1222 +shared. According to Bharata's post, readdir does not seems to be
1224 +There are several missing features known in this implementations such as
1225 +- for users, the inode number may change silently. eg. copy-up.
1226 +- link(2) may break by copy-up.
1227 +- read(2) may get an obsoleted filedata (fstat(2) too).
1228 +- fcntl(F_SETLK) may be broken by copy-up.
1229 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1232 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1233 +merged into mainline. This is another implementation of UnionMount as a
1234 +separated filesystem. All the limitations and known problems which
1235 +UnionMount are equally inherited to "overlay" filesystem.
1237 +Unionfs has a longer history. When I started implementing a stackable
1238 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1239 +inode, dentry and file objects and they have an array pointing lower
1240 +same kind objects. After contributing many patches for Unionfs, I
1241 +re-started my project AUFS (Jun 2006).
1243 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1244 +implemented my own ideas, approaches and enhancements and it became
1245 +totally different one.
1247 +Comparing DM snapshot and fs based implementation
1248 +- the number of bytes to be copied between devices is much smaller.
1249 +- the type of filesystem must be one and only.
1250 +- the fs must be writable, no readonly fs, even for the lower original
1251 + device. so the compression fs will not be usable. but if we use
1252 + loopback mount, we may address this issue.
1254 + mount /cdrom/squashfs.img /sq
1255 + losetup /sq/ext2.img
1256 + losetup /somewhere/cow
1257 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1258 +- it will be difficult (or needs more operations) to extract the
1259 + difference between the original device and COW.
1260 +- DM snapshot-merge may help a lot when users try merging. in the
1261 + fs-layer union, users will use rsync(1).
1263 +You may want to read my old paper "Filesystems in LiveCD"
1264 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1267 +Several characters/aspects/persona of aufs
1268 +----------------------------------------------------------------------
1270 +Aufs has several characters, aspects or persona.
1271 +1. a filesystem, callee of VFS helper
1272 +2. sub-VFS, caller of VFS helper for branches
1273 +3. a virtual filesystem which maintains persistent inode number
1274 +4. reader/writer of files on branches such like an application
1276 +1. Callee of VFS Helper
1277 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1278 +unlink(2) from an application reaches sys_unlink() kernel function and
1279 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1280 +calls filesystem specific unlink operation. Actually aufs implements the
1281 +unlink operation but it behaves like a redirector.
1283 +2. Caller of VFS Helper for Branches
1284 +aufs_unlink() passes the unlink request to the branch filesystem as if
1285 +it were called from VFS. So the called unlink operation of the branch
1286 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1287 +every necessary pre/post operation for the branch filesystem.
1288 +- acquire the lock for the parent dir on a branch
1289 +- lookup in a branch
1290 +- revalidate dentry on a branch
1291 +- mnt_want_write() for a branch
1292 +- vfs_unlink() for a branch
1293 +- mnt_drop_write() for a branch
1294 +- release the lock on a branch
1296 +3. Persistent Inode Number
1297 +One of the most important issue for a filesystem is to maintain inode
1298 +numbers. This is particularly important to support exporting a
1299 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1300 +backend block device for its own. But some storage is necessary to
1301 +keep and maintain the inode numbers. It may be a large space and may not
1302 +suit to keep in memory. Aufs rents some space from its first writable
1303 +branch filesystem (by default) and creates file(s) on it. These files
1304 +are created by aufs internally and removed soon (currently) keeping
1306 +Note: Because these files are removed, they are totally gone after
1307 + unmounting aufs. It means the inode numbers are not persistent
1308 + across unmount or reboot. I have a plan to make them really
1309 + persistent which will be important for aufs on NFS server.
1311 +4. Read/Write Files Internally (copy-on-write)
1312 +Because a branch can be readonly, when you write a file on it, aufs will
1313 +"copy-up" it to the upper writable branch internally. And then write the
1314 +originally requested thing to the file. Generally kernel doesn't
1315 +open/read/write file actively. In aufs, even a single write may cause a
1316 +internal "file copy". This behaviour is very similar to cp(1) command.
1318 +Some people may think it is better to pass such work to user space
1319 +helper, instead of doing in kernel space. Actually I am still thinking
1320 +about it. But currently I have implemented it in kernel space.
1321 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1322 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1323 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2020-01-27 10:57:18.162204582 +0100
1326 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1328 +# This program is free software; you can redistribute it and/or modify
1329 +# it under the terms of the GNU General Public License as published by
1330 +# the Free Software Foundation; either version 2 of the License, or
1331 +# (at your option) any later version.
1333 +# This program is distributed in the hope that it will be useful,
1334 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1335 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1336 +# GNU General Public License for more details.
1338 +# You should have received a copy of the GNU General Public License
1339 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1341 +Basic Aufs Internal Structure
1343 +Superblock/Inode/Dentry/File Objects
1344 +----------------------------------------------------------------------
1345 +As like an ordinary filesystem, aufs has its own
1346 +superblock/inode/dentry/file objects. All these objects have a
1347 +dynamically allocated array and store the same kind of pointers to the
1348 +lower filesystem, branch.
1349 +For example, when you build a union with one readwrite branch and one
1350 +readonly, mounted /au, /rw and /ro respectively.
1352 +- /ro/fileA exists but /rw/fileA
1354 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1355 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1356 +- [0] = NULL (because /rw/fileA doesn't exist)
1359 +This style of an array is essentially same to the aufs
1360 +superblock/inode/dentry/file objects.
1362 +Because aufs supports manipulating branches, ie. add/delete/change
1363 +branches dynamically, these objects has its own generation. When
1364 +branches are changed, the generation in aufs superblock is
1365 +incremented. And a generation in other object are compared when it is
1366 +accessed. When a generation in other objects are obsoleted, aufs
1367 +refreshes the internal array.
1371 +----------------------------------------------------------------------
1372 +Additionally aufs superblock has some data for policies to select one
1373 +among multiple writable branches, XIB files, pseudo-links and kobject.
1374 +See below in detail.
1375 +About the policies which supports copy-down a directory, see
1376 +wbr_policy.txt too.
1379 +Branch and XINO(External Inode Number Translation Table)
1380 +----------------------------------------------------------------------
1381 +Every branch has its own xino (external inode number translation table)
1382 +file. The xino file is created and unlinked by aufs internally. When two
1383 +members of a union exist on the same filesystem, they share the single
1385 +The struct of a xino file is simple, just a sequence of aufs inode
1386 +numbers which is indexed by the lower inode number.
1387 +In the above sample, assume the inode number of /ro/fileA is i111 and
1388 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1389 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1391 +When the inode numbers are not contiguous, the xino file will be sparse
1392 +which has a hole in it and doesn't consume as much disk space as it
1393 +might appear. If your branch filesystem consumes disk space for such
1394 +holes, then you should specify 'xino=' option at mounting aufs.
1396 +Aufs has a mount option to free the disk blocks for such holes in XINO
1397 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1398 +meet a problem of disk shortage due to XINO files, then you should try
1399 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1400 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1401 +the holes in XINO files.
1403 +Also a writable branch has three kinds of "whiteout bases". All these
1404 +are existed when the branch is joined to aufs, and their names are
1405 +whiteout-ed doubly, so that users will never see their names in aufs
1407 +1. a regular file which will be hardlinked to all whiteouts.
1408 +2. a directory to store a pseudo-link.
1409 +3. a directory to store an "orphan"-ed file temporary.
1412 + When you remove a file on a readonly branch, aufs handles it as a
1413 + logical deletion and creates a whiteout on the upper writable branch
1414 + as a hardlink of this file in order not to consume inode on the
1417 + See below, Pseudo-link.
1419 + When "fileC" exists on the lower readonly branch only and it is
1420 + opened and removed with its parent dir, and then user writes
1421 + something into it, then aufs copies-up fileC to this
1422 + directory. Because there is no other dir to store fileC. After
1423 + creating a file under this dir, the file is unlinked.
1425 +Because aufs supports manipulating branches, ie. add/delete/change
1426 +dynamically, a branch has its own id. When the branch order changes,
1427 +aufs finds the new index by searching the branch id.
1431 +----------------------------------------------------------------------
1432 +Assume "fileA" exists on the lower readonly branch only and it is
1433 +hardlinked to "fileB" on the branch. When you write something to fileA,
1434 +aufs copies-up it to the upper writable branch. Additionally aufs
1435 +creates a hardlink under the Pseudo-link Directory of the writable
1436 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1437 +simple list. If fileB is read after unlinking fileA, aufs returns
1438 +filedata from the pseudo-link instead of the lower readonly
1439 +branch. Because the pseudo-link is based upon the inode, to keep the
1440 +inode number by xino (see above) is essentially necessary.
1442 +All the hardlinks under the Pseudo-link Directory of the writable branch
1443 +should be restored in a proper location later. Aufs provides a utility
1444 +to do this. The userspace helpers executed at remounting and unmounting
1446 +During this utility is running, it puts aufs into the pseudo-link
1447 +maintenance mode. In this mode, only the process which began the
1448 +maintenance mode (and its child processes) is allowed to operate in
1449 +aufs. Some other processes which are not related to the pseudo-link will
1450 +be allowed to run too, but the rest have to return an error or wait
1451 +until the maintenance mode ends. If a process already acquires an inode
1452 +mutex (in VFS), it has to return an error.
1455 +XIB(external inode number bitmap)
1456 +----------------------------------------------------------------------
1457 +Addition to the xino file per a branch, aufs has an external inode number
1458 +bitmap in a superblock object. It is also an internal file such like a
1460 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1462 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1464 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1465 +reduce the number of consumed disk blocks for these files.
1468 +Virtual or Vertical Dir, and Readdir in Userspace
1469 +----------------------------------------------------------------------
1470 +In order to support multiple layers (branches), aufs readdir operation
1471 +constructs a virtual dir block on memory. For readdir, aufs calls
1472 +vfs_readdir() internally for each dir on branches, merges their entries
1473 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1474 +object. So the file object has its entry list until it is closed. The
1475 +entry list will be updated when the file position is zero and becomes
1476 +obsoleted. This decision is made in aufs automatically.
1478 +The dynamically allocated memory block for the name of entries has a
1479 +unit of 512 bytes (by default) and stores the names contiguously (no
1480 +padding). Another block for each entry is handled by kmem_cache too.
1481 +During building dir blocks, aufs creates hash list and judging whether
1482 +the entry is whiteouted by its upper branch or already listed.
1483 +The merged result is cached in the corresponding inode object and
1484 +maintained by a customizable life-time option.
1486 +Some people may call it can be a security hole or invite DoS attack
1487 +since the opened and once readdir-ed dir (file object) holds its entry
1488 +list and becomes a pressure for system memory. But I'd say it is similar
1489 +to files under /proc or /sys. The virtual files in them also holds a
1490 +memory page (generally) while they are opened. When an idea to reduce
1491 +memory for them is introduced, it will be applied to aufs too.
1492 +For those who really hate this situation, I've developed readdir(3)
1493 +library which operates this merging in userspace. You just need to set
1494 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1495 +kernel space for readdir(3).
1499 +----------------------------------------------------------------------
1500 +Aufs sometimes requires privilege access to a branch. For instance,
1501 +in copy-up/down operation. When a user process is going to make changes
1502 +to a file which exists in the lower readonly branch only, and the mode
1503 +of one of ancestor directories may not be writable by a user
1504 +process. Here aufs copy-up the file with its ancestors and they may
1505 +require privilege to set its owner/group/mode/etc.
1506 +This is a typical case of a application character of aufs (see
1509 +Aufs uses workqueue synchronously for this case. It creates its own
1510 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1511 +passes the request to call mkdir or write (for example), and wait for
1512 +its completion. This approach solves a problem of a signal handler
1514 +If aufs didn't adopt the workqueue and changed the privilege of the
1515 +process, then the process may receive the unexpected SIGXFSZ or other
1518 +Also aufs uses the system global workqueue ("events" kernel thread) too
1519 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1520 +whiteout base and etc. This is unrelated to a privilege.
1521 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1522 +superblock at the beginning, at the same time waits for the completion
1523 +of all queued asynchronous tasks.
1527 +----------------------------------------------------------------------
1528 +The whiteout in aufs is very similar to Unionfs's. That is represented
1529 +by its filename. UnionMount takes an approach of a file mode, but I am
1530 +afraid several utilities (find(1) or something) will have to support it.
1532 +Basically the whiteout represents "logical deletion" which stops aufs to
1533 +lookup further, but also it represents "dir is opaque" which also stop
1536 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1537 +In order to make several functions in a single systemcall to be
1538 +revertible, aufs adopts an approach to rename a directory to a temporary
1539 +unique whiteouted name.
1540 +For example, in rename(2) dir where the target dir already existed, aufs
1541 +renames the target dir to a temporary unique whiteouted name before the
1542 +actual rename on a branch, and then handles other actions (make it opaque,
1543 +update the attributes, etc). If an error happens in these actions, aufs
1544 +simply renames the whiteouted name back and returns an error. If all are
1545 +succeeded, aufs registers a function to remove the whiteouted unique
1546 +temporary name completely and asynchronously to the system global
1551 +----------------------------------------------------------------------
1552 +It is a well-known feature or concept.
1553 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1554 +internally and makes change to the new file on the upper writable branch.
1555 +When the trigger systemcall does not update the timestamps of the parent
1556 +dir, aufs reverts it after copy-up.
1559 +Move-down (aufs3.9 and later)
1560 +----------------------------------------------------------------------
1561 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1562 +the lower readonly branch to the upper writable branch when a user
1563 +changes something about the file.
1564 +"Move-down" is an opposite action of copy-up. Basically this action is
1565 +ran manually instead of automatically and internally.
1566 +For desgin and implementation, aufs has to consider these issues.
1567 +- whiteout for the file may exist on the lower branch.
1568 +- ancestor directories may not exist on the lower branch.
1569 +- diropq for the ancestor directories may exist on the upper branch.
1570 +- free space on the lower branch will reduce.
1571 +- another access to the file may happen during moving-down, including
1572 + UDBA (see "Revalidate Dentry and UDBA").
1573 +- the file should not be hard-linked nor pseudo-linked. they should be
1574 + handled by auplink utility later.
1576 +Sometimes users want to move-down a file from the upper writable branch
1577 +to the lower readonly or writable branch. For instance,
1578 +- the free space of the upper writable branch is going to run out.
1579 +- create a new intermediate branch between the upper and lower branch.
1582 +For this purpose, use "aumvdown" command in aufs-util.git.
1583 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1584 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1585 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2020-01-27 10:57:18.162204582 +0100
1588 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1590 +# This program is free software; you can redistribute it and/or modify
1591 +# it under the terms of the GNU General Public License as published by
1592 +# the Free Software Foundation; either version 2 of the License, or
1593 +# (at your option) any later version.
1595 +# This program is distributed in the hope that it will be useful,
1596 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1597 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1598 +# GNU General Public License for more details.
1600 +# You should have received a copy of the GNU General Public License
1601 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1603 +Support for a branch who has its ->atomic_open()
1604 +----------------------------------------------------------------------
1605 +The filesystems who implement its ->atomic_open() are not majority. For
1606 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1607 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1608 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1609 +sure whether all filesystems who have ->atomic_open() behave like this,
1610 +but NFSv4 surely returns the error.
1612 +In order to support ->atomic_open() for aufs, there are a few
1615 +A. Introduce aufs_atomic_open()
1616 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1618 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1619 + an aufs user Pip Cet's approach
1620 + - calls aufs_create(), VFS finish_open() and notify_change().
1621 + - pass fake-mode to finish_open(), and then correct the mode by
1623 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1624 + - no aufs_atomic_open().
1625 + - aufs_lookup() registers the TID to an aufs internal object.
1626 + - aufs_create() does nothing when the matching TID is registered, but
1627 + registers the mode.
1628 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1629 + TID is registered.
1630 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1632 + - no aufs_atomic_open().
1633 + - aufs_create() registers the TID to an internal object. this info
1634 + represents "this process created this file just now."
1635 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1636 + registered TID and re-try open() with superuser's credential.
1638 +Pros and cons for each approach.
1641 + - straightforward but highly depends upon VFS internal.
1642 + - the atomic behavaiour is kept.
1643 + - some of parameters such as nameidata are hard to reproduce for
1647 + - easy to implement.
1648 + - the atomic behavaiour is lost.
1650 + - the atomic behavaiour is kept.
1651 + - dirty and tricky.
1652 + - VFS checks whether the file is created correctly after calling
1653 + ->create(), which means this approach doesn't work.
1655 + - easy to implement.
1656 + - the atomic behavaiour is lost.
1657 + - to open a file with superuser's credential and give it to a user
1658 + process is a bad idea, since the file object keeps the credential
1659 + in it. It may affect LSM or something. This approach doesn't work
1662 +The approach A is ideal, but it hard to implement. So here is a
1663 +variation of A, which is to be implemented.
1665 +A-1. Introduce aufs_atomic_open()
1666 + - calls branch fs ->atomic_open() if exists. otherwise calls
1667 + vfs_create() and finish_open().
1668 + - the demerit is that the several checks after branch fs
1669 + ->atomic_open() are lost. in the ordinary case, the checks are
1670 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1671 + be implemented in aufs, but not all I am afraid.
1672 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1673 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1674 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2020-01-27 10:57:18.165538015 +0100
1677 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1679 +# This program is free software; you can redistribute it and/or modify
1680 +# it under the terms of the GNU General Public License as published by
1681 +# the Free Software Foundation; either version 2 of the License, or
1682 +# (at your option) any later version.
1684 +# This program is distributed in the hope that it will be useful,
1685 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1686 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1687 +# GNU General Public License for more details.
1689 +# You should have received a copy of the GNU General Public License
1690 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1693 +----------------------------------------------------------------------
1694 +Since aufs has a character of sub-VFS (see Introduction), it operates
1695 +lookup for branches as VFS does. It may be a heavy work. But almost all
1696 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1697 +directly connected to its parent. Digging down the directory hierarchy
1698 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1701 +When a branch is a remote filesystem, aufs basically relies upon its
1702 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1704 +For d_revalidate, aufs implements three levels of revalidate tests. See
1705 +"Revalidate Dentry and UDBA" in detail.
1708 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1709 +----------------------------------------------------------------------
1710 +Let's try case study.
1711 +- aufs has two branches, upper readwrite and lower readonly.
1713 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1714 +- user invoked "chmod a+rx /au/dirA"
1715 +- the internal copy-up is activated and "/rw/dirA" is created and its
1716 + permission bits are set to world readable.
1717 +- then "/au/dirA" becomes world readable?
1719 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1720 +or it may be a natively readonly filesystem. If aufs respects the lower
1721 +branch, it should not respond readdir request from other users. But user
1722 +allowed it by chmod. Should really aufs rejects showing the entries
1725 +To be honest, I don't have a good solution for this case. So aufs
1726 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1728 +When dirperm1 is specified, aufs checks only the highest one for the
1729 +directory permission, and shows the entries. Otherwise, as usual, checks
1730 +every dir existing on all branches and rejects the request.
1732 +As a side effect, dirperm1 option improves the performance of aufs
1733 +because the number of permission check is reduced when the number of
1737 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1738 +----------------------------------------------------------------------
1739 +Generally VFS helpers re-validate a dentry as a part of lookup.
1740 +0. digging down the directory hierarchy.
1741 +1. lock the parent dir by its i_mutex.
1742 +2. lookup the final (child) entry.
1744 +4. call the actual operation (create, unlink, etc.)
1745 +5. unlock the parent dir
1747 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1748 +called. Actually aufs implements it and checks the dentry on a branch is
1750 +But it is not enough. Because aufs has to release the lock for the
1751 +parent dir on a branch at the end of ->lookup() (step 2) and
1752 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1754 +If the file on a branch is changed directly, eg. bypassing aufs, after
1755 +aufs released the lock, then the subsequent operation may cause
1756 +something unpleasant result.
1758 +This situation is a result of VFS architecture, ->lookup() and
1759 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1760 +design from VFS's point of view. It is just not suitable for sub-VFS
1763 +Aufs supports such case by three level of revalidation which is
1764 +selectable by user.
1765 +1. Simple Revalidate
1766 + Addition to the native flow in VFS's, confirm the child-parent
1767 + relationship on the branch just after locking the parent dir on the
1768 + branch in the "actual operation" (step 4). When this validation
1769 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1770 + checks the validation of the dentry on branches.
1771 +2. Monitor Changes Internally by Inotify/Fsnotify
1772 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1773 + the dentry on the branch, and returns EBUSY if it finds different
1775 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1776 + during it is in cache. When the event is notified, aufs registers a
1777 + function to kernel 'events' thread by schedule_work(). And the
1778 + function sets some special status to the cached aufs dentry and inode
1779 + private data. If they are not cached, then aufs has nothing to
1780 + do. When the same file is accessed through aufs (step 0-3) later,
1781 + aufs will detect the status and refresh all necessary data.
1782 + In this mode, aufs has to ignore the event which is fired by aufs
1784 +3. No Extra Validation
1785 + This is the simplest test and doesn't add any additional revalidation
1786 + test, and skip the revalidation in step 4. It is useful and improves
1787 + aufs performance when system surely hide the aufs branches from user,
1788 + by over-mounting something (or another method).
1789 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1790 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1791 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2020-01-27 10:57:18.165538015 +0100
1794 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1796 +# This program is free software; you can redistribute it and/or modify
1797 +# it under the terms of the GNU General Public License as published by
1798 +# the Free Software Foundation; either version 2 of the License, or
1799 +# (at your option) any later version.
1801 +# This program is distributed in the hope that it will be useful,
1802 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1803 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1804 +# GNU General Public License for more details.
1806 +# You should have received a copy of the GNU General Public License
1807 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1809 +Branch Manipulation
1811 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1812 +and changing its permission/attribute, there are a lot of works to do.
1816 +----------------------------------------------------------------------
1817 +o Confirm the adding dir exists outside of aufs, including loopback
1818 + mount, and its various attributes.
1819 +o Initialize the xino file and whiteout bases if necessary.
1822 +o Check the owner/group/mode of the directory
1823 + When the owner/group/mode of the adding directory differs from the
1824 + existing branch, aufs issues a warning because it may impose a
1826 + For example, when a upper writable branch has a world writable empty
1827 + top directory, a malicious user can create any files on the writable
1828 + branch directly, like copy-up and modify manually. If something like
1829 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1830 + writable branch, and the writable branch is world-writable, then a
1831 + malicious guy may create /etc/passwd on the writable branch directly
1832 + and the infected file will be valid in aufs.
1833 + I am afraid it can be a security issue, but aufs can do nothing except
1834 + producing a warning.
1838 +----------------------------------------------------------------------
1839 +o Confirm the deleting branch is not busy
1840 + To be general, there is one merit to adopt "remount" interface to
1841 + manipulate branches. It is to discard caches. At deleting a branch,
1842 + aufs checks the still cached (and connected) dentries and inodes. If
1843 + there are any, then they are all in-use. An inode without its
1844 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1846 + For the cached one, aufs checks whether the same named entry exists on
1848 + If the cached one is a directory, because aufs provides a merged view
1849 + to users, as long as one dir is left on any branch aufs can show the
1850 + dir to users. In this case, the branch can be removed from aufs.
1851 + Otherwise aufs rejects deleting the branch.
1853 + If any file on the deleting branch is opened by aufs, then aufs
1857 +Modify the Permission of a Branch
1858 +----------------------------------------------------------------------
1859 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1862 +o rw --> ro: Confirm the modifying branch is not busy
1863 + Aufs rejects the request if any of these conditions are true.
1864 + - a file on the branch is mmap-ed.
1865 + - a regular file on the branch is opened for write and there is no
1866 + same named entry on the upper branch.
1867 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1868 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1869 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2020-01-27 10:57:18.165538015 +0100
1872 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1874 +# This program is free software; you can redistribute it and/or modify
1875 +# it under the terms of the GNU General Public License as published by
1876 +# the Free Software Foundation; either version 2 of the License, or
1877 +# (at your option) any later version.
1879 +# This program is distributed in the hope that it will be useful,
1880 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1881 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1882 +# GNU General Public License for more details.
1884 +# You should have received a copy of the GNU General Public License
1885 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1887 +Policies to Select One among Multiple Writable Branches
1888 +----------------------------------------------------------------------
1889 +When the number of writable branch is more than one, aufs has to decide
1890 +the target branch for file creation or copy-up. By default, the highest
1891 +writable branch which has the parent (or ancestor) dir of the target
1892 +file is chosen (top-down-parent policy).
1893 +By user's request, aufs implements some other policies to select the
1894 +writable branch, for file creation several policies, round-robin,
1895 +most-free-space, and other policies. For copy-up, top-down-parent,
1896 +bottom-up-parent, bottom-up and others.
1898 +As expected, the round-robin policy selects the branch in circular. When
1899 +you have two writable branches and creates 10 new files, 5 files will be
1900 +created for each branch. mkdir(2) systemcall is an exception. When you
1901 +create 10 new directories, all will be created on the same branch.
1902 +And the most-free-space policy selects the one which has most free
1903 +space among the writable branches. The amount of free space will be
1904 +checked by aufs internally, and users can specify its time interval.
1906 +The policies for copy-up is more simple,
1907 +top-down-parent is equivalent to the same named on in create policy,
1908 +bottom-up-parent selects the writable branch where the parent dir
1909 +exists and the nearest upper one from the copyup-source,
1910 +bottom-up selects the nearest upper writable branch from the
1911 +copyup-source, regardless the existence of the parent dir.
1913 +There are some rules or exceptions to apply these policies.
1914 +- If there is a readonly branch above the policy-selected branch and
1915 + the parent dir is marked as opaque (a variation of whiteout), or the
1916 + target (creating) file is whiteout-ed on the upper readonly branch,
1917 + then the result of the policy is ignored and the target file will be
1918 + created on the nearest upper writable branch than the readonly branch.
1919 +- If there is a writable branch above the policy-selected branch and
1920 + the parent dir is marked as opaque or the target file is whiteouted
1921 + on the branch, then the result of the policy is ignored and the target
1922 + file will be created on the highest one among the upper writable
1923 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1925 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1926 + They try selecting the branch where the source exists as possible
1927 + since copyup a large file will take long time. If it can't be,
1928 + ie. the branch where the source exists is readonly, then they will
1929 + follow the copyup policy.
1930 +- There is an exception for rename(2) when the target exists.
1931 + If the rename target exists, aufs compares the index of the branches
1932 + where the source and the target exists and selects the higher
1933 + one. If the selected branch is readonly, then aufs follows the
1935 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1936 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1937 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200
1940 +// to view this graph, run dot(1) command in GRAPHVIZ.
1944 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1948 +aufs_rename -> whinfo [label="store/remove"];
1951 +inode_list [label="h_inum list in branch\ncache"];
1954 +whinode [label="h_inum list file"];
1957 +brmgmt [label="br_add/del/mod/umount"];
1959 +brmgmt -> inode_list [label="create/remove"];
1960 +brmgmt -> whinode [label="load/store"];
1962 +inode_list -> whinode [style=dashed,dir=both];
1964 +aufs_rename -> inode_list [label="add/del"];
1966 +aufs_lookup -> inode_list [label="search"];
1968 +aufs_lookup -> whinfo [label="load/remove"];
1970 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1971 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1972 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2020-01-27 10:57:18.165538015 +0100
1975 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1977 +# This program is free software; you can redistribute it and/or modify
1978 +# it under the terms of the GNU General Public License as published by
1979 +# the Free Software Foundation; either version 2 of the License, or
1980 +# (at your option) any later version.
1982 +# This program is distributed in the hope that it will be useful,
1983 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1984 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1985 +# GNU General Public License for more details.
1987 +# You should have received a copy of the GNU General Public License
1988 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1990 +Special handling for renaming a directory (DIRREN)
1991 +----------------------------------------------------------------------
1992 +First, let's assume we have a simple usecase.
1996 +- /ro/dirA and /ro/dirA/file exist too
1997 +- there is no dirB on both branches
1998 +- a user issues rename("dirA", "dirB")
2000 +Now, what should aufs behave against this rename(2)?
2001 +There are a few possible cases.
2004 + since dirA exists on a readonly branch which cannot be renamed.
2006 + it is possible to copy-up dirA (only the dir itself), but the child
2007 + entries ("file" in this case) should not be. it must be a bad
2008 + approach to copy-up recursively.
2009 +C. returns a success.
2010 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2011 + is a violation of aufs' policy.
2012 +D. construct an extra information which indicates that /ro/dirA should
2013 + be handled as the name of dirB.
2014 + overlayfs has a similar feature called REDIRECT.
2016 +Until now, aufs implements the case B only which returns EXDEV, and
2017 +expects the userspace application behaves like mv(1) which tries
2018 +issueing rename(2) recursively.
2020 +A new aufs feature called DIRREN is introduced which implements the case
2021 +D. There are several "extra information" added.
2023 +1. detailed info per renamed directory
2024 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2025 +2. the inode-number list of directories on a branch
2026 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2028 +The filename of "detailed info per directory" represents the lower
2029 +branch, and its format is
2030 +- a type of the branch id
2032 + + uuid (not implemented yet)
2035 +- the inode-number of the branch root dir
2037 +And it contains these info in a single regular file.
2039 +- branch's inode-number of the logically renamed dir
2040 +- the name of the before-renamed dir
2042 +The "detailed info per directory" file is created in aufs rename(2), and
2043 +loaded in any lookup.
2044 +The info is considered in lookup for the matching case only. Here
2045 +"matching" means that the root of branch (in the info filename) is same
2046 +to the current looking-up branch. After looking-up the before-renamed
2047 +name, the inode-number is compared. And the matched dentry is used.
2049 +The "inode-number list of directories" is a regular file which contains
2050 +simply the inode-numbers on the branch. The file is created or updated
2051 +in removing the branch, and loaded in adding the branch. Its lifetime is
2052 +equal to the branch.
2053 +The list is refered in lookup, and when the current target inode is
2054 +found in the list, the aufs tries loading the "detailed info per
2055 +directory" and get the changed and valid name of the dir.
2057 +Theoretically these "extra informaiton" may be able to be put into XATTR
2058 +in the dir inode. But aufs doesn't choose this way because
2059 +1. XATTR may not be supported by the branch (or its configuration)
2060 +2. XATTR may have its size limit.
2061 +3. XATTR may be less easy to convert than a regular file, when the
2062 + format of the info is changed in the future.
2063 +At the same time, I agree that the regular file approach is much slower
2064 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2067 +This DIRREN feature is enabled by aufs configuration, and is activated
2068 +by a new mount option.
2070 +For the more complicated case, there is a work with UDBA option, which
2071 +is to dected the direct access to the branches (by-passing aufs) and to
2072 +maintain the cashes in aufs. Since a single cached aufs dentry may
2073 +contains two names, before- and after-rename, the name comparision in
2074 +UDBA handler may not work correctly. In this case, the behaviour will be
2075 +equivalen to udba=reval case.
2076 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2077 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2078 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2020-01-27 10:57:18.165538015 +0100
2081 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2083 +# This program is free software; you can redistribute it and/or modify
2084 +# it under the terms of the GNU General Public License as published by
2085 +# the Free Software Foundation; either version 2 of the License, or
2086 +# (at your option) any later version.
2088 +# This program is distributed in the hope that it will be useful,
2089 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2090 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2091 +# GNU General Public License for more details.
2093 +# You should have received a copy of the GNU General Public License
2094 +# along with this program; if not, write to the Free Software
2095 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2098 +File-based Hierarchical Storage Management (FHSM)
2099 +----------------------------------------------------------------------
2100 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2101 +storage world. Aufs provides this feature as file-based with multiple
2102 +writable branches, based upon the principle of "Colder, the Lower".
2103 +Here the word "colder" means that the less used files, and "lower" means
2104 +that the position in the order of the stacked branches vertically.
2105 +These multiple writable branches are prioritized, ie. the topmost one
2106 +should be the fastest drive and be used heavily.
2108 +o Characters in aufs FHSM story
2109 +- aufs itself and a new branch attribute.
2110 +- a new ioctl interface to move-down and to establish a connection with
2111 + the daemon ("move-down" is a converse of "copy-up").
2112 +- userspace tool and daemon.
2114 +The userspace daemon establishes a connection with aufs and waits for
2115 +the notification. The notified information is very similar to struct
2116 +statfs containing the number of consumed blocks and inodes.
2117 +When the consumed blocks/inodes of a branch exceeds the user-specified
2118 +upper watermark, the daemon activates its move-down process until the
2119 +consumed blocks/inodes reaches the user-specified lower watermark.
2121 +The actual move-down is done by aufs based upon the request from
2122 +user-space since we need to maintain the inode number and the internal
2123 +pointer arrays in aufs.
2125 +Currently aufs FHSM handles the regular files only. Additionally they
2126 +must not be hard-linked nor pseudo-linked.
2129 +o Cowork of aufs and the user-space daemon
2130 + During the userspace daemon established the connection, aufs sends a
2131 + small notification to it whenever aufs writes something into the
2132 + writable branch. But it may cost high since aufs issues statfs(2)
2133 + internally. So user can specify a new option to cache the
2134 + info. Actually the notification is controlled by these factors.
2135 + + the specified cache time.
2136 + + classified as "force" by aufs internally.
2137 + Until the specified time expires, aufs doesn't send the info
2138 + except the forced cases. When aufs decide forcing, the info is always
2139 + notified to userspace.
2140 + For example, the number of free inodes is generally large enough and
2141 + the shortage of it happens rarely. So aufs doesn't force the
2142 + notification when creating a new file, directory and others. This is
2143 + the typical case which aufs doesn't force.
2144 + When aufs writes the actual filedata and the files consumes any of new
2145 + blocks, the aufs forces notifying.
2148 +o Interfaces in aufs
2149 +- New branch attribute.
2151 + Specifies that the branch is managed by FHSM feature. In other word,
2152 + participant in the FHSM.
2153 + When nofhsm is set to the branch, it will not be the source/target
2154 + branch of the move-down operation. This attribute is set
2155 + independently from coo and moo attributes, and if you want full
2156 + FHSM, you should specify them as well.
2157 +- New mount option.
2159 + Specifies a second to suppress many less important info to be
2162 + + AUFS_CTL_FHSM_FD
2163 + create a new file descriptor which userspace can read the notification
2164 + (a subset of struct statfs) from aufs.
2165 +- Module parameter 'brs'
2166 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2168 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2169 + When there are two or more branches with fhsm attributes,
2170 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2171 + terminates it. As a result of remounting and branch-manipulation, the
2172 + number of branches with fhsm attribute can be one. In this case,
2173 + /sbin/mount.aufs will terminate the user-space daemon.
2176 +Finally the operation is done as these steps in kernel-space.
2178 + + no one else is using the file.
2179 + + the file is not hard-linked.
2180 + + the file is not pseudo-linked.
2181 + + the file is a regular file.
2182 + + the parent dir is not opaqued.
2183 +- find the target writable branch.
2184 +- make sure the file is not whiteout-ed by the upper (than the target)
2186 +- make the parent dir on the target branch.
2187 +- mutex lock the inode on the branch.
2188 +- unlink the whiteout on the target branch (if exists).
2189 +- lookup and create the whiteout-ed temporary name on the target branch.
2190 +- copy the file as the whiteout-ed temporary name on the target branch.
2191 +- rename the whiteout-ed temporary name to the original name.
2192 +- unlink the file on the source branch.
2193 +- maintain the internal pointer array and the external inode number
2195 +- maintain the timestamps and other attributes of the parent dir and the
2198 +And of course, in every step, an error may happen. So the operation
2199 +should restore the original file state after an error happens.
2200 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2201 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2202 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2020-01-27 10:57:18.165538015 +0100
2205 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2207 +# This program is free software; you can redistribute it and/or modify
2208 +# it under the terms of the GNU General Public License as published by
2209 +# the Free Software Foundation; either version 2 of the License, or
2210 +# (at your option) any later version.
2212 +# This program is distributed in the hope that it will be useful,
2213 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2214 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2215 +# GNU General Public License for more details.
2217 +# You should have received a copy of the GNU General Public License
2218 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2220 +mmap(2) -- File Memory Mapping
2221 +----------------------------------------------------------------------
2222 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2223 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2225 +This approach is simple and good, but there is one problem.
2226 +Under /proc, several entries show the mmapped files by its path (with
2227 +device and inode number), and the printed path will be the path on the
2228 +branch fs's instead of virtual aufs's.
2229 +This is not a problem in most cases, but some utilities lsof(1) (and its
2230 +user) may expect the path on aufs.
2232 +To address this issue, aufs adds a new member called vm_prfile in struct
2233 +vm_area_struct (and struct vm_region). The original vm_file points to
2234 +the file on the branch fs in order to handle everything correctly as
2235 +usual. The new vm_prfile points to a virtual file in aufs, and the
2236 +show-functions in procfs refers to vm_prfile if it is set.
2237 +Also we need to maintain several other places where touching vm_file
2239 +- fork()/clone() copies vma and the reference count of vm_file is
2241 +- merging vma maintains the ref count too.
2243 +This is not a good approach. It just fakes the printed path. But it
2244 +leaves all behaviour around f_mapping unchanged. This is surely an
2246 +Actually aufs had adopted another complicated approach which calls
2247 +generic_file_mmap() and handles struct vm_operations_struct. In this
2248 +approach, aufs met a hard problem and I could not solve it without
2249 +switching the approach.
2251 +There may be one more another approach which is
2252 +- bind-mount the branch-root onto the aufs-root internally
2253 +- grab the new vfsmount (ie. struct mount)
2254 +- lazy-umount the branch-root internally
2255 +- in open(2) the aufs-file, open the branch-file with the hidden
2256 + vfsmount (instead of the original branch's vfsmount)
2257 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2258 + but it may be possible from userspace by the mount helper.
2260 +Adding the internal hidden vfsmount and using it in opening a file, the
2261 +file path under /proc will be printed correctly. This approach looks
2262 +smarter, but is not possible I am afraid.
2263 +- aufs-root may be bind-mount later. when it happens, another hidden
2264 + vfsmount will be required.
2265 +- it is hard to get the chance to bind-mount and lazy-umount
2266 + + in kernel-space, FS can have vfsmount in open(2) via
2267 + file->f_path, and aufs can know its vfsmount. But several locks are
2268 + already acquired, and if aufs tries to bind-mount and lazy-umount
2269 + here, then it may cause a deadlock.
2270 + + in user-space, bind-mount doesn't invoke the mount helper.
2271 +- since /proc shows dev and ino, aufs has to give vma these info. it
2272 + means a new member vm_prinode will be necessary. this is essentially
2273 + equivalent to vm_prfile described above.
2275 +I have to give up this "looks-smater" approach.
2276 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2277 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2278 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2020-01-27 10:57:18.165538015 +0100
2281 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2283 +# This program is free software; you can redistribute it and/or modify
2284 +# it under the terms of the GNU General Public License as published by
2285 +# the Free Software Foundation; either version 2 of the License, or
2286 +# (at your option) any later version.
2288 +# This program is distributed in the hope that it will be useful,
2289 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2290 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2291 +# GNU General Public License for more details.
2293 +# You should have received a copy of the GNU General Public License
2294 +# along with this program; if not, write to the Free Software
2295 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2298 +Listing XATTR/EA and getting the value
2299 +----------------------------------------------------------------------
2300 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2301 +shows the values from the topmost existing file. This behaviour is good
2302 +for the non-dir entries since the bahaviour exactly matches the shown
2303 +information. But for the directories, aufs considers all the same named
2304 +entries on the lower branches. Which means, if one of the lower entry
2305 +rejects readdir call, then aufs returns an error even if the topmost
2306 +entry allows it. This behaviour is necessary to respect the branch fs's
2307 +security, but can make users confused since the user-visible standard
2308 +attributes don't match the behaviour.
2309 +To address this issue, aufs has a mount option called dirperm1 which
2310 +checks the permission for the topmost entry only, and ignores the lower
2311 +entry's permission.
2313 +A similar issue can happen around XATTR.
2314 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2315 +always set. Otherwise these very unpleasant situation would happen.
2316 +- listxattr(2) may return the duplicated entries.
2317 +- users may not be able to remove or reset the XATTR forever,
2320 +XATTR/EA support in the internal (copy,move)-(up,down)
2321 +----------------------------------------------------------------------
2322 +Generally the extended attributes of inode are categorized as these.
2323 +- "security" for LSM and capability.
2324 +- "system" for posix ACL, 'acl' mount option is required for the branch
2326 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2327 +- "user" for userspace, 'user_xattr' mount option is required for the
2328 + branch fs generally.
2330 +Moreover there are some other categories. Aufs handles these rather
2331 +unpopular categories as the ordinary ones, ie. there is no special
2332 +condition nor exception.
2334 +In copy-up, the support for XATTR on the dst branch may differ from the
2335 +src branch. In this case, the copy-up operation will get an error and
2336 +the original user operation which triggered the copy-up will fail. It
2337 +can happen that even all copy-up will fail.
2338 +When both of src and dst branches support XATTR and if an error occurs
2339 +during copying XATTR, then the copy-up should fail obviously. That is a
2340 +good reason and aufs should return an error to userspace. But when only
2341 +the src branch support that XATTR, aufs should not return an error.
2342 +For example, the src branch supports ACL but the dst branch doesn't
2343 +because the dst branch may natively un-support it or temporary
2344 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2345 +may NOT return an error even if the XATTR is not supported. It is
2346 +totally up to the branch fs.
2348 +Anyway when the aufs internal copy-up gets an error from the dst branch
2349 +fs, then aufs tries removing the just copied entry and returns the error
2350 +to the userspace. The worst case of this situation will be all copy-up
2353 +For the copy-up operation, there two basic approaches.
2354 +- copy the specified XATTR only (by category above), and return the
2355 + error unconditionally if it happens.
2356 +- copy all XATTR, and ignore the error on the specified category only.
2358 +In order to support XATTR and to implement the correct behaviour, aufs
2359 +chooses the latter approach and introduces some new branch attributes,
2360 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2361 +They correspond to the XATTR namespaces (see above). Additionally, to be
2362 +convenient, "icex" is also provided which means all "icex*" attributes
2363 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2365 +The meaning of these attributes is to ignore the error from setting
2366 +XATTR on that branch.
2367 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2368 +error from the dst branch according to the specified attributes.
2370 +Some XATTR may have its default value. The default value may come from
2371 +the parent dir or the environment. If the default value is set at the
2372 +file creating-time, it will be overwritten by copy-up.
2373 +Some contradiction may happen I am afraid.
2374 +Do we need another attribute to stop copying XATTR? I am unsure. For
2375 +now, aufs implements the branch attributes to ignore the error.
2376 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2377 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2378 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2020-01-27 10:57:18.165538015 +0100
2381 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2383 +# This program is free software; you can redistribute it and/or modify
2384 +# it under the terms of the GNU General Public License as published by
2385 +# the Free Software Foundation; either version 2 of the License, or
2386 +# (at your option) any later version.
2388 +# This program is distributed in the hope that it will be useful,
2389 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2390 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2391 +# GNU General Public License for more details.
2393 +# You should have received a copy of the GNU General Public License
2394 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2396 +Export Aufs via NFS
2397 +----------------------------------------------------------------------
2398 +Here is an approach.
2399 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2401 +- iget_locked(): initialize aufs inode generation for a new inode, and
2402 + store it in xigen file.
2403 +- destroy_inode(): increment aufs inode generation and store it in xigen
2404 + file. it is necessary even if it is not unlinked, because any data of
2405 + inode may be changed by UDBA.
2406 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2407 + build file handle by
2408 + + branch id (4 bytes)
2409 + + superblock generation (4 bytes)
2410 + + inode number (4 or 8 bytes)
2411 + + parent dir inode number (4 or 8 bytes)
2412 + + inode generation (4 bytes))
2413 + + return value of exportfs_encode_fh() for the parent on a branch (4
2415 + + file handle for a branch (by exportfs_encode_fh())
2417 + + find the index of a branch from its id in handle, and check it is
2418 + still exist in aufs.
2419 + + 1st level: get the inode number from handle and search it in cache.
2420 + + 2nd level: if not found in cache, get the parent inode number from
2421 + the handle and search it in cache. and then open the found parent
2422 + dir, find the matching inode number by vfs_readdir() and get its
2423 + name, and call lookup_one_len() for the target dentry.
2424 + + 3rd level: if the parent dir is not cached, call
2425 + exportfs_decode_fh() for a branch and get the parent on a branch,
2426 + build a pathname of it, convert it a pathname in aufs, call
2427 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2429 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2430 + for every branch, but not itself. to get this, (currently) aufs
2431 + searches in current->nsproxy->mnt_ns list. it may not be a good
2432 + idea, but I didn't get other approach.
2433 + + test the generation of the gotten inode.
2434 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2435 + convert it into ESTALE for NFSD.
2436 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2437 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2438 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2439 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2440 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2020-01-27 10:57:18.165538015 +0100
2443 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2445 +# This program is free software; you can redistribute it and/or modify
2446 +# it under the terms of the GNU General Public License as published by
2447 +# the Free Software Foundation; either version 2 of the License, or
2448 +# (at your option) any later version.
2450 +# This program is distributed in the hope that it will be useful,
2451 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2452 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2453 +# GNU General Public License for more details.
2455 +# You should have received a copy of the GNU General Public License
2456 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2458 +Show Whiteout Mode (shwh)
2459 +----------------------------------------------------------------------
2460 +Generally aufs hides the name of whiteouts. But in some cases, to show
2461 +them is very useful for users. For instance, creating a new middle layer
2462 +(branch) by merging existing layers.
2464 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2465 +When you have three branches,
2466 +- Bottom: 'system', squashfs (underlying base system), read-only
2467 +- Middle: 'mods', squashfs, read-only
2468 +- Top: 'overlay', ram (tmpfs), read-write
2470 +The top layer is loaded at boot time and saved at shutdown, to preserve
2471 +the changes made to the system during the session.
2472 +When larger changes have been made, or smaller changes have accumulated,
2473 +the size of the saved top layer data grows. At this point, it would be
2474 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2475 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2476 +restoring save and load speed.
2478 +This merging is simplified by the use of another aufs mount, of just the
2479 +two overlay branches using the 'shwh' option.
2480 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2481 + aufs /livesys/merge_union
2483 +A merged view of these two branches is then available at
2484 +/livesys/merge_union, and the new feature is that the whiteouts are
2486 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2487 +writing to all branches. Also the default mode for all branches is 'ro'.
2488 +It is now possible to save the combined contents of the two overlay
2489 +branches to a new squashfs, e.g.:
2490 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2492 +This new squashfs archive can be stored on the boot device and the
2493 +initramfs will use it to replace the old one at the next boot.
2494 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2495 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2496 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2020-01-27 10:57:18.165538015 +0100
2499 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2501 +# This program is free software; you can redistribute it and/or modify
2502 +# it under the terms of the GNU General Public License as published by
2503 +# the Free Software Foundation; either version 2 of the License, or
2504 +# (at your option) any later version.
2506 +# This program is distributed in the hope that it will be useful,
2507 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2508 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2509 +# GNU General Public License for more details.
2511 +# You should have received a copy of the GNU General Public License
2512 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2514 +Dynamically customizable FS operations
2515 +----------------------------------------------------------------------
2516 +Generally FS operations (struct inode_operations, struct
2517 +address_space_operations, struct file_operations, etc.) are defined as
2518 +"static const", but it never means that FS have only one set of
2519 +operation. Some FS have multiple sets of them. For instance, ext2 has
2520 +three sets, one for XIP, for NOBH, and for normal.
2521 +Since aufs overrides and redirects these operations, sometimes aufs has
2522 +to change its behaviour according to the branch FS type. More importantly
2523 +VFS acts differently if a function (member in the struct) is set or
2524 +not. It means aufs should have several sets of operations and select one
2525 +among them according to the branch FS definition.
2527 +In order to solve this problem and not to affect the behaviour of VFS,
2528 +aufs defines these operations dynamically. For instance, aufs defines
2529 +dummy direct_IO function for struct address_space_operations, but it may
2530 +not be set to the address_space_operations actually. When the branch FS
2531 +doesn't have it, aufs doesn't set it to its address_space_operations
2532 +while the function definition itself is still alive. So the behaviour
2533 +itself will not change, and it will return an error when direct_IO is
2536 +The lifetime of these dynamically generated operation object is
2537 +maintained by aufs branch object. When the branch is removed from aufs,
2538 +the reference counter of the object is decremented. When it reaches
2539 +zero, the dynamically generated operation object will be freed.
2541 +This approach is designed to support AIO (io_submit), Direct I/O and
2543 +Currently this approach is applied to address_space_operations for
2544 +regular files only.
2545 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2546 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2547 +++ linux/Documentation/filesystems/aufs/README 2020-01-23 09:59:36.748660743 +0100
2550 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2556 +----------------------------------------
2557 +In the early days, aufs was entirely re-designed and re-implemented
2558 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2559 +improvements and implementations, it became totally different from
2560 +Unionfs while keeping the basic features.
2561 +Later, Unionfs Version 2.x series began taking some of the same
2562 +approaches to aufs1's.
2563 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2564 +University and his team.
2566 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2568 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2569 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2570 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2571 + or aufs1 from CVS on SourceForge.
2573 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2574 + According to Christoph Hellwig, linux rejects all union-type
2575 + filesystems but UnionMount.
2576 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2578 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2579 + UnionMount, and he pointed out an issue around a directory mutex
2580 + lock and aufs addressed it. But it is still unsure whether aufs will
2581 + be merged (or any other union solution).
2582 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2586 +----------------------------------------
2587 +- unite several directories into a single virtual filesystem. The member
2588 + directory is called as a branch.
2589 +- you can specify the permission flags to the branch, which are 'readonly',
2590 + 'readwrite' and 'whiteout-able.'
2591 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2592 + readonly branch are modifiable logically.
2593 +- dynamic branch manipulation, add, del.
2596 +Also there are many enhancements in aufs, such as:
2597 +- test only the highest one for the directory permission (dirperm1)
2598 +- copyup on open (coo=)
2599 +- 'move' policy for copy-up between two writable branches, after
2600 + checking free space.
2602 +- readdir(3) in userspace.
2603 +- keep inode number by external inode number table
2604 +- keep the timestamps of file/dir in internal copyup operation
2605 +- seekable directory, supporting NFS readdir.
2606 +- whiteout is hardlinked in order to reduce the consumption of inodes
2608 +- do not copyup, nor create a whiteout when it is unnecessary
2609 +- revert a single systemcall when an error occurs in aufs
2610 +- remount interface instead of ioctl
2611 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2612 +- loopback mounted filesystem as a branch
2613 +- kernel thread for removing the dir who has a plenty of whiteouts
2614 +- support copyup sparse file (a file which has a 'hole' in it)
2615 +- default permission flags for branches
2616 +- selectable permission flags for ro branch, whether whiteout can
2619 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2620 +- support multiple writable branches, some policies to select one
2621 + among multiple writable branches.
2622 +- a new semantics for link(2) and rename(2) to support multiple
2623 + writable branches.
2624 +- no glibc changes are required.
2625 +- pseudo hardlink (hardlink over branches)
2626 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2627 + including NFS or remote filesystem branch.
2628 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2631 +Currently these features are dropped temporary from aufs5.
2632 +See design/08plan.txt in detail.
2633 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2635 +- statistics of aufs thread (/sys/fs/aufs/stat)
2637 +Features or just an idea in the future (see also design/*.txt),
2638 +- reorder the branch index without del/re-add.
2639 +- permanent xino files for NFSD
2640 +- an option for refreshing the opened files after add/del branches
2641 +- light version, without branch manipulation. (unnecessary?)
2642 +- copyup in userspace
2643 +- inotify in userspace
2648 +----------------------------------------
2649 +There are three GIT trees for aufs5, aufs5-linux.git,
2650 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2652 +While the aufs-util is always necessary, you need either of aufs5-linux
2653 +or aufs5-standalone.
2655 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2656 +git://git.kernel.org/.../torvalds/linux.git.
2657 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2658 +build aufs5 as an external kernel module.
2659 +Several extra patches are not included in this tree. Only
2660 +aufs5-standalone tree contains them. They are described in the later
2661 +section "Configuration and Compilation."
2663 +On the other hand, the aufs5-standalone tree has only aufs source files
2664 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2665 +But you need to apply all aufs patches manually.
2667 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2668 +represents the linux kernel version, "linux-5.x". For instance,
2669 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2670 +"aufs5.x-rcN" branch.
2673 +$ git clone --reference /your/linux/git/tree \
2674 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2675 +- if you don't have linux GIT tree, then remove "--reference ..."
2676 +$ cd aufs5-linux.git
2677 +$ git checkout origin/aufs5.0
2679 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2680 +leave the patch-work to GIT.
2681 +$ cd /your/linux/git/tree
2682 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2684 +$ git checkout -b my5.0 v5.0
2685 +$ (add your local change...)
2686 +$ git pull aufs5 aufs5.0
2687 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2688 +- you may need to solve some conflicts between your_changes and
2689 + aufs5.0. in this case, git-rerere is recommended so that you can
2690 + solve the similar conflicts automatically when you upgrade to 5.1 or
2691 + later in the future.
2693 +o aufs5-standalone tree
2694 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2695 +$ cd aufs5-standalone.git
2696 +$ git checkout origin/aufs5.0
2699 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2700 +- note that the public aufs-util.git is on SourceForge instead of
2703 +$ git checkout origin/aufs5.0
2705 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2706 +The minor version number, 'x' in '5.x', of aufs may not always
2707 +follow the minor version number of the kernel.
2708 +Because changes in the kernel that cause the use of a new
2709 +minor version number do not always require changes to aufs-util.
2711 +Since aufs-util has its own minor version number, you may not be
2712 +able to find a GIT branch in aufs-util for your kernel's
2713 +exact minor version number.
2714 +In this case, you should git-checkout the branch for the
2715 +nearest lower number.
2717 +For (an unreleased) example:
2718 +If you are using "linux-5.10" and the "aufs5.10" branch
2719 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2720 +or something numerically smaller is the branch for your kernel.
2722 +Also you can view all branches by
2726 +3. Configuration and Compilation
2727 +----------------------------------------
2728 +Make sure you have git-checkout'ed the correct branch.
2730 +For aufs5-linux tree,
2731 +- enable CONFIG_AUFS_FS.
2732 +- set other aufs configurations if necessary.
2734 +For aufs5-standalone tree,
2735 +There are several ways to build.
2738 +- apply ./aufs5-kbuild.patch to your kernel source files.
2739 +- apply ./aufs5-base.patch too.
2740 +- apply ./aufs5-mmap.patch too.
2741 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2742 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2743 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2744 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2745 +- enable CONFIG_AUFS_FS, you can select either
2747 +- and build your kernel as usual.
2748 +- install the built kernel.
2749 +- install the header files too by "make headers_install" to the
2750 + directory where you specify. By default, it is $PWD/usr.
2751 + "make help" shows a brief note for headers_install.
2752 +- and reboot your system.
2755 +- module only (CONFIG_AUFS_FS=m).
2756 +- apply ./aufs5-base.patch to your kernel source files.
2757 +- apply ./aufs5-mmap.patch too.
2758 +- apply ./aufs5-standalone.patch too.
2759 +- build your kernel, don't forget "make headers_install", and reboot.
2760 +- edit ./config.mk and set other aufs configurations if necessary.
2761 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2762 + every aufs configurations.
2763 +- build the module by simple "make".
2764 +- you can specify ${KDIR} make variable which points to your kernel
2766 +- install the files
2767 + + run "make install" to install the aufs module, or copy the built
2768 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2769 + + run "make install_headers" (instead of headers_install) to install
2770 + the modified aufs header file (you can specify DESTDIR which is
2771 + available in aufs standalone version's Makefile only), or copy
2772 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2773 + you like manually. By default, the target directory is $PWD/usr.
2774 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2775 + kernel source tree.
2777 +Note: The header file aufs_type.h is necessary to build aufs-util
2778 + as well as "make headers_install" in the kernel source tree.
2779 + headers_install is subject to be forgotten, but it is essentially
2780 + necessary, not only for building aufs-util.
2781 + You may not meet problems without headers_install in some older
2785 +- read README in aufs-util, build and install it
2786 +- note that your distribution may contain an obsoleted version of
2787 + aufs_type.h in /usr/include/linux or something. When you build aufs
2788 + utilities, make sure that your compiler refers the correct aufs header
2789 + file which is built by "make headers_install."
2790 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2791 + then run "make install_ulib" too. And refer to the aufs manual in
2794 +There several other patches in aufs5-standalone.git. They are all
2795 +optional. When you meet some problems, they will help you.
2796 +- aufs5-loopback.patch
2797 + Supports a nested loopback mount in a branch-fs. This patch is
2798 + unnecessary until aufs produces a message like "you may want to try
2799 + another patch for loopback file".
2800 +- proc_mounts.patch
2801 + When there are many mountpoints and many mount(2)/umount(2) are
2802 + running, then /proc/mounts may not show the all mountpoints. This
2803 + patch makes /proc/mounts always show the full mountpoints list.
2804 + If you don't want to apply this patch and meet such problem, then you
2805 + need to increase the value of 'ProcMounts_Times' make-variable in
2806 + aufs-util.git as a second best solution.
2808 + Modifies a system global kernel internal function get_next_ino() in
2809 + order to stop assigning 0 for an inode-number. Not directly related to
2810 + aufs, but recommended generally.
2812 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2813 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2814 + duplication of inode number, which is important for backup tools and
2815 + other utilities. When you find aufs XINO files for tmpfs branch
2816 + growing too much, try this patch.
2817 +- lockdep-debug.patch
2818 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2819 + also a caller of VFS functions for branch filesystems, subclassing of
2820 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2821 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2822 + need to apply this debug patch to expand several constant values.
2823 + If you don't know what LOCKDEP is, then you don't have apply this
2828 +----------------------------------------
2829 +At first, make sure aufs-util are installed, and please read the aufs
2830 +manual, aufs.5 in aufs-util.git tree.
2834 +$ mkdir /tmp/rw /tmp/aufs
2835 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2837 +Here is another example. The result is equivalent.
2838 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2840 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2841 +# mount -o remount,append:${HOME} /tmp/aufs
2843 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2844 +you modify a file under /tmp/aufs, the one on your home directory is
2845 +not affected, instead the same named file will be newly created under
2846 +/tmp/rw. And all of your modification to a file will be applied to
2847 +the one under /tmp/rw. This is called the file based Copy on Write
2849 +Aufs mount options are described in aufs.5.
2850 +If you run chroot or something and make your aufs as a root directory,
2851 +then you need to customize the shutdown script. See the aufs manual in
2854 +Additionally, there are some sample usages of aufs which are a
2855 +diskless system with network booting, and LiveCD over NFS.
2856 +See sample dir in CVS tree on SourceForge.
2860 +----------------------------------------
2861 +When you have any problems or strange behaviour in aufs, please let me
2863 +- /proc/mounts (instead of the output of mount(8))
2864 +- /sys/module/aufs/*
2865 +- /sys/fs/aufs/* (if you have them)
2866 +- /debug/aufs/* (if you have them)
2867 +- linux kernel version
2868 + if your kernel is not plain, for example modified by distributor,
2869 + the url where i can download its source is necessary too.
2870 +- aufs version which was printed at loading the module or booting the
2871 + system, instead of the date you downloaded.
2872 +- configuration (define/undefine CONFIG_AUFS_xxx)
2873 +- kernel configuration or /proc/config.gz (if you have it)
2874 +- LSM (linux security module, if you are using)
2875 +- behaviour which you think to be incorrect
2876 +- actual operation, reproducible one is better
2877 +- mailto: aufs-users at lists.sourceforge.net
2879 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2880 +and Feature Requests) on SourceForge. Please join and write to
2884 +6. Acknowledgements
2885 +----------------------------------------
2886 +Thanks to everyone who have tried and are using aufs, whoever
2887 +have reported a bug or any feedback.
2889 +Especially donators:
2890 +Tomas Matejicek(slax.org) made a donation (much more than once).
2891 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2892 + scripts) is making "doubling" donations.
2893 + Unfortunately I cannot list all of the donators, but I really
2895 + It ends Aug 2010, but the ordinary donation URL is still available.
2896 + <http://sourceforge.net/donate/index.php?group_id=167503>
2897 +Dai Itasaka made a donation (2007/8).
2898 +Chuck Smith made a donation (2008/4, 10 and 12).
2899 +Henk Schoneveld made a donation (2008/9).
2900 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2901 +Francois Dupoux made a donation (2008/11).
2902 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2903 + aufs2 GIT tree (2009/2).
2904 +William Grant made a donation (2009/3).
2905 +Patrick Lane made a donation (2009/4).
2906 +The Mail Archive (mail-archive.com) made donations (2009/5).
2907 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2908 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2909 +Pavel Pronskiy made a donation (2011/2).
2910 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2911 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2912 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2914 +Sam Liddicott made a donation (2011/9).
2915 +Era Scarecrow made a donation (2013/4).
2916 +Bor Ratajc made a donation (2013/4).
2917 +Alessandro Gorreta made a donation (2013/4).
2918 +POIRETTE Marc made a donation (2013/4).
2919 +Alessandro Gorreta made a donation (2013/4).
2920 +lauri kasvandik made a donation (2013/5).
2921 +"pemasu from Finland" made a donation (2013/7).
2922 +The Parted Magic Project made a donation (2013/9 and 11).
2923 +Pavel Barta made a donation (2013/10).
2924 +Nikolay Pertsev made a donation (2014/5).
2925 +James B made a donation (2014/7 and 2015/7).
2926 +Stefano Di Biase made a donation (2014/8).
2927 +Daniel Epellei made a donation (2015/1).
2928 +OmegaPhil made a donation (2016/1, 2018/4).
2929 +Tomasz Szewczyk made a donation (2016/4).
2930 +James Burry made a donation (2016/12).
2931 +Carsten Rose made a donation (2018/9).
2932 +Porteus Kiosk made a donation (2018/10).
2934 +Thank you very much.
2935 +Donations are always, including future donations, very important and
2936 +helpful for me to keep on developing aufs.
2940 +----------------------------------------
2941 +If you are an experienced user, no explanation is needed. Aufs is
2942 +just a linux filesystem.
2947 +# Local variables: ;
2950 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2951 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2952 +++ linux/fs/aufs/aufs.h 2020-01-27 10:57:18.165538015 +0100
2954 +/* SPDX-License-Identifier: GPL-2.0 */
2956 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2958 + * This program, aufs is free software; you can redistribute it and/or modify
2959 + * it under the terms of the GNU General Public License as published by
2960 + * the Free Software Foundation; either version 2 of the License, or
2961 + * (at your option) any later version.
2963 + * This program is distributed in the hope that it will be useful,
2964 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2965 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2966 + * GNU General Public License for more details.
2968 + * You should have received a copy of the GNU General Public License
2969 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2973 + * all header files
2981 +#define AuStub(type, name, body, ...) \
2982 + static inline type name(__VA_ARGS__) { body; }
2984 +#define AuStubVoid(name, ...) \
2985 + AuStub(void, name, , __VA_ARGS__)
2986 +#define AuStubInt0(name, ...) \
2987 + AuStub(int, name, return 0, __VA_ARGS__)
2991 +#include "branch.h"
2994 +#include "dbgaufs.h"
2995 +#include "dentry.h"
2997 +#include "dirren.h"
3000 +#include "fstype.h"
3005 +#include "module.h"
3009 +#include "sysaufs.h"
3014 +#endif /* __KERNEL__ */
3015 +#endif /* __AUFS_H__ */
3016 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3017 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3018 +++ linux/fs/aufs/branch.c 2020-01-27 10:57:18.165538015 +0100
3020 +// SPDX-License-Identifier: GPL-2.0
3022 + * Copyright (C) 2005-2020 Junjiro R. Okajima
3024 + * This program, aufs is free software; you can redistribute it and/or modify
3025 + * it under the terms of the GNU General Public License as published by
3026 + * the Free Software Foundation; either version 2 of the License, or
3027 + * (at your option) any later version.
3029 + * This program is distributed in the hope that it will be useful,
3030 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3031 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3032 + * GNU General Public License for more details.
3034 + * You should have received a copy of the GNU General Public License
3035 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3039 + * branch management
3042 +#include <linux/compat.h>
3043 +#include <linux/statfs.h>
3047 + * free a single branch
3049 +static void au_br_do_free(struct au_branch *br)
3052 + struct au_wbr *wbr;
3053 + struct au_dykey **key;
3055 + au_hnotify_fin_br(br);
3056 + /* always, regardless the mount option */
3057 + au_dr_hino_free(&br->br_dirren);
3060 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3061 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3062 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3063 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3067 + for (i = 0; i < AuBrWh_Last; i++)
3068 + dput(wbr->wbr_wh[i]);
3069 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3070 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3073 + if (br->br_fhsm) {
3074 + au_br_fhsm_fin(br->br_fhsm);
3075 + au_kfree_try_rcu(br->br_fhsm);
3078 + key = br->br_dykey;
3079 + for (i = 0; i < AuBrDynOp; i++, key++)
3085 + /* recursive lock, s_umount of branch's */
3086 + /* synchronize_rcu(); */ /* why? */
3088 + path_put(&br->br_path);
3090 + au_kfree_rcu(wbr);
3091 + au_lcnt_wait_for_fin(&br->br_nfiles);
3092 + au_lcnt_wait_for_fin(&br->br_count);
3093 + /* I don't know why, but percpu_refcount requires this */
3094 + /* synchronize_rcu(); */
3099 + * frees all branches
3101 +void au_br_free(struct au_sbinfo *sbinfo)
3103 + aufs_bindex_t bmax;
3104 + struct au_branch **br;
3106 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3108 + bmax = sbinfo->si_bbot + 1;
3109 + br = sbinfo->si_branch;
3111 + au_br_do_free(*br++);
3115 + * find the index of a branch which is specified by @br_id.
3117 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3119 + aufs_bindex_t bindex, bbot;
3121 + bbot = au_sbbot(sb);
3122 + for (bindex = 0; bindex <= bbot; bindex++)
3123 + if (au_sbr_id(sb, bindex) == br_id)
3128 +/* ---------------------------------------------------------------------- */
3134 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3135 + struct dentry *h_root)
3137 + if (unlikely(h_adding == h_root
3138 + || au_test_loopback_overlap(sb, h_adding)))
3140 + if (h_adding->d_sb != h_root->d_sb)
3142 + return au_test_subdir(h_adding, h_root)
3143 + || au_test_subdir(h_root, h_adding);
3147 + * returns a newly allocated branch. @new_nbranch is a number of branches
3148 + * after adding a branch.
3150 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3153 + struct au_branch *add_branch;
3154 + struct dentry *root;
3155 + struct inode *inode;
3159 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3160 + if (unlikely(!add_branch))
3162 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3163 + if (unlikely(!add_branch->br_xino))
3165 + err = au_hnotify_init_br(add_branch, perm);
3166 + if (unlikely(err))
3169 + if (au_br_writable(perm)) {
3170 + /* may be freed separately at changing the branch permission */
3171 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3173 + if (unlikely(!add_branch->br_wbr))
3177 + if (au_br_fhsm(perm)) {
3178 + err = au_fhsm_br_alloc(add_branch);
3179 + if (unlikely(err))
3183 + root = sb->s_root;
3184 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3186 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3188 + inode = d_inode(root);
3189 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3193 + return add_branch; /* success */
3196 + au_kfree_rcu(add_branch->br_wbr);
3198 + au_hnotify_fin_br(add_branch);
3200 + au_xino_put(add_branch);
3202 + au_kfree_rcu(add_branch);
3204 + return ERR_PTR(err);
3208 + * test if the branch permission is legal or not.
3210 +static int test_br(struct inode *inode, int brperm, char *path)
3214 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3219 + pr_err("write permission for readonly mount or inode, %s\n", path);
3227 + * 0: success, the caller will add it
3228 + * plus: success, it is already unified, the caller should ignore it
3231 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3234 + aufs_bindex_t bbot, bindex;
3235 + struct dentry *root, *h_dentry;
3236 + struct inode *inode, *h_inode;
3238 + root = sb->s_root;
3239 + bbot = au_sbbot(sb);
3240 + if (unlikely(bbot >= 0
3241 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3245 + pr_err("%s duplicated\n", add->pathname);
3250 + err = -ENOSPC; /* -E2BIG; */
3251 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3252 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3253 + pr_err("number of branches exceeded %s\n", add->pathname);
3258 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3259 + pr_err("bad index %d\n", add->bindex);
3263 + inode = d_inode(add->path.dentry);
3265 + if (unlikely(!inode->i_nlink)) {
3266 + pr_err("no existence %s\n", add->pathname);
3271 + if (unlikely(inode->i_sb == sb)) {
3272 + pr_err("%s must be outside\n", add->pathname);
3276 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3277 + pr_err("unsupported filesystem, %s (%s)\n",
3278 + add->pathname, au_sbtype(inode->i_sb));
3282 + if (unlikely(inode->i_sb->s_stack_depth)) {
3283 + pr_err("already stacked, %s (%s)\n",
3284 + add->pathname, au_sbtype(inode->i_sb));
3288 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3289 + if (unlikely(err))
3293 + return 0; /* success */
3296 + for (bindex = 0; bindex <= bbot; bindex++)
3297 + if (unlikely(test_overlap(sb, add->path.dentry,
3298 + au_h_dptr(root, bindex)))) {
3299 + pr_err("%s is overlapped\n", add->pathname);
3304 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3305 + h_dentry = au_h_dptr(root, 0);
3306 + h_inode = d_inode(h_dentry);
3307 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3308 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3309 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3310 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3312 + i_uid_read(inode), i_gid_read(inode),
3313 + (inode->i_mode & S_IALLUGO),
3314 + i_uid_read(h_inode), i_gid_read(h_inode),
3315 + (h_inode->i_mode & S_IALLUGO));
3323 + * initialize or clean the whiteouts for an adding branch
3325 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3328 + int err, old_perm;
3329 + aufs_bindex_t bindex;
3330 + struct inode *h_inode;
3331 + struct au_wbr *wbr;
3332 + struct au_hinode *hdir;
3333 + struct dentry *h_dentry;
3335 + err = vfsub_mnt_want_write(au_br_mnt(br));
3336 + if (unlikely(err))
3340 + old_perm = br->br_perm;
3341 + br->br_perm = new_perm;
3344 + bindex = au_br_index(sb, br->br_id);
3345 + if (0 <= bindex) {
3346 + hdir = au_hi(d_inode(sb->s_root), bindex);
3347 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3349 + h_dentry = au_br_dentry(br);
3350 + h_inode = d_inode(h_dentry);
3351 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3354 + err = au_wh_init(br, sb);
3356 + wbr_wh_write_lock(wbr);
3357 + err = au_wh_init(br, sb);
3358 + wbr_wh_write_unlock(wbr);
3361 + au_hn_inode_unlock(hdir);
3363 + inode_unlock(h_inode);
3364 + vfsub_mnt_drop_write(au_br_mnt(br));
3365 + br->br_perm = old_perm;
3367 + if (!err && wbr && !au_br_writable(new_perm)) {
3368 + au_kfree_rcu(wbr);
3369 + br->br_wbr = NULL;
3376 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3380 + struct kstatfs kst;
3381 + struct au_wbr *wbr;
3384 + au_rw_init(&wbr->wbr_wh_rwsem);
3385 + atomic_set(&wbr->wbr_wh_running, 0);
3388 + * a limit for rmdir/rename a dir
3389 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3391 + err = vfs_statfs(&br->br_path, &kst);
3392 + if (unlikely(err))
3395 + if (kst.f_namelen >= NAME_MAX)
3396 + err = au_br_init_wh(sb, br, perm);
3398 + pr_err("%pd(%s), unsupported namelen %ld\n",
3400 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3406 +/* initialize a new branch */
3407 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3408 + struct au_opt_add *add)
3411 + struct au_branch *brbase;
3413 + struct inode *h_inode;
3416 + br->br_perm = add->perm;
3417 + br->br_path = add->path; /* set first, path_get() later */
3418 + spin_lock_init(&br->br_dykey_lock);
3419 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3420 + au_lcnt_init(&br->br_count, /*release*/NULL);
3421 + br->br_id = au_new_br_id(sb);
3422 + AuDebugOn(br->br_id < 0);
3424 + /* always, regardless the given option */
3425 + err = au_dr_br_init(sb, br, &add->path);
3426 + if (unlikely(err))
3429 + if (au_br_writable(add->perm)) {
3430 + err = au_wbr_init(br, sb, add->perm);
3431 + if (unlikely(err))
3435 + if (au_opt_test(au_mntflags(sb), XINO)) {
3436 + brbase = au_sbr(sb, 0);
3437 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3439 + h_inode = d_inode(add->path.dentry);
3440 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3441 + if (unlikely(err)) {
3442 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3447 + sysaufs_br_init(br);
3448 + path_get(&br->br_path);
3449 + goto out; /* success */
3452 + memset(&br->br_path, 0, sizeof(br->br_path));
3457 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3458 + struct au_branch *br, aufs_bindex_t bbot,
3459 + aufs_bindex_t amount)
3461 + struct au_branch **brp;
3463 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3465 + brp = sbinfo->si_branch + bindex;
3466 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3468 + sbinfo->si_bbot++;
3469 + if (unlikely(bbot < 0))
3470 + sbinfo->si_bbot = 0;
3473 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3474 + aufs_bindex_t bbot, aufs_bindex_t amount)
3476 + struct au_hdentry *hdp;
3478 + AuRwMustWriteLock(&dinfo->di_rwsem);
3480 + hdp = au_hdentry(dinfo, bindex);
3481 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3482 + au_h_dentry_init(hdp);
3484 + if (unlikely(bbot < 0))
3485 + dinfo->di_btop = 0;
3488 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3489 + aufs_bindex_t bbot, aufs_bindex_t amount)
3491 + struct au_hinode *hip;
3493 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3495 + hip = au_hinode(iinfo, bindex);
3496 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3497 + au_hinode_init(hip);
3499 + if (unlikely(bbot < 0))
3500 + iinfo->ii_btop = 0;
3503 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3504 + aufs_bindex_t bindex)
3506 + struct dentry *root, *h_dentry;
3507 + struct inode *root_inode, *h_inode;
3508 + aufs_bindex_t bbot, amount;
3510 + root = sb->s_root;
3511 + root_inode = d_inode(root);
3512 + bbot = au_sbbot(sb);
3513 + amount = bbot + 1 - bindex;
3514 + h_dentry = au_br_dentry(br);
3515 + au_sbilist_lock();
3516 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3517 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3518 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3519 + au_set_h_dptr(root, bindex, dget(h_dentry));
3520 + h_inode = d_inode(h_dentry);
3521 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3522 + au_sbilist_unlock();
3525 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3528 + aufs_bindex_t bbot, add_bindex;
3529 + struct dentry *root, *h_dentry;
3530 + struct inode *root_inode;
3531 + struct au_branch *add_branch;
3533 + root = sb->s_root;
3534 + root_inode = d_inode(root);
3535 + IMustLock(root_inode);
3536 + IiMustWriteLock(root_inode);
3537 + err = test_add(sb, add, remount);
3538 + if (unlikely(err < 0))
3542 + goto out; /* success */
3545 + bbot = au_sbbot(sb);
3546 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3547 + err = PTR_ERR(add_branch);
3548 + if (IS_ERR(add_branch))
3551 + err = au_br_init(add_branch, sb, add);
3552 + if (unlikely(err)) {
3553 + au_br_do_free(add_branch);
3557 + add_bindex = add->bindex;
3558 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3559 + au_br_do_add(sb, add_branch, add_bindex);
3560 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3561 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3563 + h_dentry = add->path.dentry;
3564 + if (!add_bindex) {
3565 + au_cpup_attr_all(root_inode, /*force*/1);
3566 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3568 + au_add_nlink(root_inode, d_inode(h_dentry));
3574 +/* ---------------------------------------------------------------------- */
3576 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3577 + unsigned long long max __maybe_unused,
3580 + unsigned long long n;
3581 + struct file **p, *f;
3582 + struct hlist_bl_head *files;
3583 + struct hlist_bl_node *pos;
3584 + struct au_finfo *finfo;
3588 + files = &au_sbi(sb)->si_files;
3589 + hlist_bl_lock(files);
3590 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3591 + f = finfo->fi_file;
3593 + && !special_file(file_inode(f)->i_mode)) {
3597 + AuDebugOn(n > max);
3600 + hlist_bl_unlock(files);
3605 +static struct file **au_farray_alloc(struct super_block *sb,
3606 + unsigned long long *max)
3608 + struct au_sbinfo *sbi;
3611 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3612 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3615 +static void au_farray_free(struct file **a, unsigned long long max)
3617 + unsigned long long ull;
3619 + for (ull = 0; ull < max; ull++)
3625 +/* ---------------------------------------------------------------------- */
3631 +/* to show the line number, do not make it inlined function */
3632 +#define AuVerbose(do_info, fmt, ...) do { \
3634 + pr_info(fmt, ##__VA_ARGS__); \
3637 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3638 + aufs_bindex_t bbot)
3640 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3643 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3644 + aufs_bindex_t bbot)
3646 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3650 + * test if the branch is deletable or not.
3652 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3653 + unsigned int sigen, const unsigned int verbose)
3655 + int err, i, j, ndentry;
3656 + aufs_bindex_t btop, bbot;
3657 + struct au_dcsub_pages dpages;
3658 + struct au_dpage *dpage;
3661 + err = au_dpages_init(&dpages, GFP_NOFS);
3662 + if (unlikely(err))
3664 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3665 + if (unlikely(err))
3668 + for (i = 0; !err && i < dpages.ndpage; i++) {
3669 + dpage = dpages.dpages + i;
3670 + ndentry = dpage->ndentry;
3671 + for (j = 0; !err && j < ndentry; j++) {
3672 + d = dpage->dentries[j];
3673 + AuDebugOn(au_dcount(d) <= 0);
3674 + if (!au_digen_test(d, sigen)) {
3675 + di_read_lock_child(d, AuLock_IR);
3676 + if (unlikely(au_dbrange_test(d))) {
3677 + di_read_unlock(d, AuLock_IR);
3681 + di_write_lock_child(d);
3682 + if (unlikely(au_dbrange_test(d))) {
3683 + di_write_unlock(d);
3686 + err = au_reval_dpath(d, sigen);
3688 + di_downgrade_lock(d, AuLock_IR);
3690 + di_write_unlock(d);
3695 + /* AuDbgDentry(d); */
3696 + btop = au_dbtop(d);
3697 + bbot = au_dbbot(d);
3698 + if (btop <= bindex
3700 + && au_h_dptr(d, bindex)
3701 + && au_test_dbusy(d, btop, bbot)) {
3703 + AuVerbose(verbose, "busy %pd\n", d);
3706 + di_read_unlock(d, AuLock_IR);
3711 + au_dpages_free(&dpages);
3716 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3717 + unsigned int sigen, const unsigned int verbose)
3720 + unsigned long long max, ull;
3721 + struct inode *i, **array;
3722 + aufs_bindex_t btop, bbot;
3724 + array = au_iarray_alloc(sb, &max);
3725 + err = PTR_ERR(array);
3726 + if (IS_ERR(array))
3730 + AuDbg("b%d\n", bindex);
3731 + for (ull = 0; !err && ull < max; ull++) {
3735 + if (i->i_ino == AUFS_ROOT_INO)
3738 + /* AuDbgInode(i); */
3739 + if (au_iigen(i, NULL) == sigen)
3740 + ii_read_lock_child(i);
3742 + ii_write_lock_child(i);
3743 + err = au_refresh_hinode_self(i);
3746 + ii_downgrade_lock(i);
3748 + ii_write_unlock(i);
3753 + btop = au_ibtop(i);
3754 + bbot = au_ibbot(i);
3755 + if (btop <= bindex
3757 + && au_h_iptr(i, bindex)
3758 + && au_test_ibusy(i, btop, bbot)) {
3760 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3763 + ii_read_unlock(i);
3765 + au_iarray_free(array, max);
3771 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3772 + const unsigned int verbose)
3775 + unsigned int sigen;
3777 + sigen = au_sigen(root->d_sb);
3778 + DiMustNoWaiters(root);
3779 + IiMustNoWaiters(d_inode(root));
3780 + di_write_unlock(root);
3781 + err = test_dentry_busy(root, bindex, sigen, verbose);
3783 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3784 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3789 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3790 + struct file **to_free, int *idx)
3793 + unsigned char matched, root;
3794 + aufs_bindex_t bindex, bbot;
3795 + struct au_fidir *fidir;
3796 + struct au_hfile *hfile;
3799 + root = IS_ROOT(file->f_path.dentry);
3802 + to_free[*idx] = file;
3808 + fidir = au_fi(file)->fi_hdir;
3809 + AuDebugOn(!fidir);
3810 + bbot = au_fbbot_dir(file);
3811 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3812 + hfile = fidir->fd_hfile + bindex;
3813 + if (!hfile->hf_file)
3816 + if (hfile->hf_br->br_id == br_id) {
3828 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3829 + struct file **to_free, int opened)
3832 + unsigned long long ull, max;
3833 + aufs_bindex_t btop;
3834 + struct file *file, **array;
3835 + struct dentry *root;
3836 + struct au_hfile *hfile;
3838 + array = au_farray_alloc(sb, &max);
3839 + err = PTR_ERR(array);
3840 + if (IS_ERR(array))
3845 + root = sb->s_root;
3846 + di_write_unlock(root);
3847 + for (ull = 0; ull < max; ull++) {
3848 + file = array[ull];
3849 + if (unlikely(!file))
3852 + /* AuDbg("%pD\n", file); */
3853 + fi_read_lock(file);
3854 + btop = au_fbtop(file);
3855 + if (!d_is_dir(file->f_path.dentry)) {
3856 + hfile = &au_fi(file)->fi_htop;
3857 + if (hfile->hf_br->br_id == br_id)
3860 + err = test_dir_busy(file, br_id, to_free, &idx);
3861 + fi_read_unlock(file);
3862 + if (unlikely(err))
3865 + di_write_lock_child(root);
3866 + au_farray_free(array, max);
3867 + AuDebugOn(idx > opened);
3873 +static void br_del_file(struct file **to_free, unsigned long long opened,
3874 + aufs_bindex_t br_id)
3876 + unsigned long long ull;
3877 + aufs_bindex_t bindex, btop, bbot, bfound;
3878 + struct file *file;
3879 + struct au_fidir *fidir;
3880 + struct au_hfile *hfile;
3882 + for (ull = 0; ull < opened; ull++) {
3883 + file = to_free[ull];
3884 + if (unlikely(!file))
3887 + /* AuDbg("%pD\n", file); */
3888 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3890 + fidir = au_fi(file)->fi_hdir;
3891 + AuDebugOn(!fidir);
3892 + fi_write_lock(file);
3893 + btop = au_fbtop(file);
3894 + bbot = au_fbbot_dir(file);
3895 + for (bindex = btop; bindex <= bbot; bindex++) {
3896 + hfile = fidir->fd_hfile + bindex;
3897 + if (!hfile->hf_file)
3900 + if (hfile->hf_br->br_id == br_id) {
3905 + AuDebugOn(bfound < 0);
3906 + au_set_h_fptr(file, bfound, NULL);
3907 + if (bfound == btop) {
3908 + for (btop++; btop <= bbot; btop++)
3909 + if (au_hf_dir(file, btop)) {
3910 + au_set_fbtop(file, btop);
3914 + fi_write_unlock(file);
3918 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3919 + const aufs_bindex_t bindex,
3920 + const aufs_bindex_t bbot)
3922 + struct au_branch **brp, **p;
3924 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3926 + brp = sbinfo->si_branch + bindex;
3927 + if (bindex < bbot)
3928 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3929 + sbinfo->si_branch[0 + bbot] = NULL;
3930 + sbinfo->si_bbot--;
3932 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3935 + sbinfo->si_branch = p;
3936 + /* harmless error */
3939 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3940 + const aufs_bindex_t bbot)
3942 + struct au_hdentry *hdp, *p;
3944 + AuRwMustWriteLock(&dinfo->di_rwsem);
3946 + hdp = au_hdentry(dinfo, bindex);
3947 + if (bindex < bbot)
3948 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3949 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3952 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3955 + dinfo->di_hdentry = p;
3956 + /* harmless error */
3959 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3960 + const aufs_bindex_t bbot)
3962 + struct au_hinode *hip, *p;
3964 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3966 + hip = au_hinode(iinfo, bindex);
3967 + if (bindex < bbot)
3968 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3969 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3972 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3975 + iinfo->ii_hinode = p;
3976 + /* harmless error */
3979 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3980 + struct au_branch *br)
3982 + aufs_bindex_t bbot;
3983 + struct au_sbinfo *sbinfo;
3984 + struct dentry *root, *h_root;
3985 + struct inode *inode, *h_inode;
3986 + struct au_hinode *hinode;
3988 + SiMustWriteLock(sb);
3990 + root = sb->s_root;
3991 + inode = d_inode(root);
3992 + sbinfo = au_sbi(sb);
3993 + bbot = sbinfo->si_bbot;
3995 + h_root = au_h_dptr(root, bindex);
3996 + hinode = au_hi(inode, bindex);
3997 + h_inode = au_igrab(hinode->hi_inode);
4000 + au_sbilist_lock();
4001 + au_br_do_del_brp(sbinfo, bindex, bbot);
4002 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4003 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4004 + au_sbilist_unlock();
4006 + /* ignore an error */
4007 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4011 + au_br_do_free(br);
4014 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4015 + unsigned long long max, void *arg)
4020 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4023 + unsigned long long opened;
4024 + unsigned int mnt_flags;
4025 + aufs_bindex_t bindex, bbot, br_id;
4026 + unsigned char do_wh, verbose;
4027 + struct au_branch *br;
4028 + struct au_wbr *wbr;
4029 + struct dentry *root;
4030 + struct file **to_free;
4035 + root = sb->s_root;
4036 + bindex = au_find_dbindex(root, del->h_path.dentry);
4039 + goto out; /* success */
4041 + pr_err("%s no such branch\n", del->pathname);
4044 + AuDbg("bindex b%d\n", bindex);
4047 + mnt_flags = au_mntflags(sb);
4048 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4049 + bbot = au_sbbot(sb);
4050 + if (unlikely(!bbot)) {
4051 + AuVerbose(verbose, "no more branches left\n");
4055 + br = au_sbr(sb, bindex);
4056 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4057 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4058 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4062 + br_id = br->br_id;
4063 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4064 + if (unlikely(opened)) {
4065 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4066 + err = PTR_ERR(to_free);
4067 + if (IS_ERR(to_free))
4070 + err = test_file_busy(sb, br_id, to_free, opened);
4071 + if (unlikely(err)) {
4072 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4078 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4080 + /* instead of WbrWhMustWriteLock(wbr) */
4081 + SiMustWriteLock(sb);
4082 + for (i = 0; i < AuBrWh_Last; i++) {
4083 + dput(wbr->wbr_wh[i]);
4084 + wbr->wbr_wh[i] = NULL;
4088 + err = test_children_busy(root, bindex, verbose);
4089 + if (unlikely(err)) {
4098 + * now we confirmed the branch is deletable.
4099 + * let's free the remaining opened dirs on the branch.
4101 + di_write_unlock(root);
4102 + br_del_file(to_free, opened, br_id);
4103 + di_write_lock_child(root);
4106 + sysaufs_brs_del(sb, bindex); /* remove successors */
4107 + dbgaufs_xino_del(br); /* remove one */
4108 + au_br_do_del(sb, bindex, br);
4109 + sysaufs_brs_add(sb, bindex); /* append successors */
4110 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4113 + au_cpup_attr_all(d_inode(root), /*force*/1);
4114 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4116 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4117 + if (au_opt_test(mnt_flags, PLINK))
4118 + au_plink_half_refresh(sb, br_id);
4120 + goto out; /* success */
4124 + rerr = au_br_init_wh(sb, br, br->br_perm);
4126 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4127 + del->pathname, rerr);
4130 + au_farray_free(to_free, opened);
4134 +/* ---------------------------------------------------------------------- */
4136 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4139 + aufs_bindex_t btop, bbot;
4140 + struct aufs_ibusy ibusy;
4141 + struct inode *inode, *h_inode;
4144 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4147 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4149 + /* VERIFY_WRITE */
4150 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4151 + if (unlikely(err)) {
4158 + si_read_lock(sb, AuLock_FLUSH);
4159 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4163 + ibusy.h_ino = 0; /* invalid */
4164 + inode = ilookup(sb, ibusy.ino);
4166 + || inode->i_ino == AUFS_ROOT_INO
4167 + || au_is_bad_inode(inode))
4170 + ii_read_lock_child(inode);
4171 + btop = au_ibtop(inode);
4172 + bbot = au_ibbot(inode);
4173 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4174 + h_inode = au_h_iptr(inode, ibusy.bindex);
4175 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4176 + ibusy.h_ino = h_inode->i_ino;
4178 + ii_read_unlock(inode);
4182 + si_read_unlock(sb);
4184 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4185 + if (unlikely(err)) {
4194 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4196 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4199 +#ifdef CONFIG_COMPAT
4200 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4202 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4206 +/* ---------------------------------------------------------------------- */
4209 + * change a branch permission
4212 +static void au_warn_ima(void)
4215 + /* since it doesn't support mark_files_ro() */
4216 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4220 +static int do_need_sigen_inc(int a, int b)
4222 + return au_br_whable(a) && !au_br_whable(b);
4225 +static int need_sigen_inc(int old, int new)
4227 + return do_need_sigen_inc(old, new)
4228 + || do_need_sigen_inc(new, old);
4231 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4234 + unsigned int mnt_flags;
4235 + unsigned long long ull, max;
4236 + aufs_bindex_t br_id;
4237 + unsigned char verbose, writer;
4238 + struct file *file, *hf, **array;
4239 + struct au_hfile *hfile;
4240 + struct inode *h_inode;
4242 + mnt_flags = au_mntflags(sb);
4243 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4245 + array = au_farray_alloc(sb, &max);
4246 + err = PTR_ERR(array);
4247 + if (IS_ERR(array))
4251 + br_id = au_sbr_id(sb, bindex);
4252 + for (ull = 0; ull < max; ull++) {
4253 + file = array[ull];
4254 + if (unlikely(!file))
4257 + /* AuDbg("%pD\n", file); */
4258 + fi_read_lock(file);
4259 + if (unlikely(au_test_mmapped(file))) {
4261 + AuVerbose(verbose, "mmapped %pD\n", file);
4263 + FiMustNoWaiters(file);
4264 + fi_read_unlock(file);
4268 + hfile = &au_fi(file)->fi_htop;
4269 + hf = hfile->hf_file;
4270 + if (!d_is_reg(file->f_path.dentry)
4271 + || !(file->f_mode & FMODE_WRITE)
4272 + || hfile->hf_br->br_id != br_id
4273 + || !(hf->f_mode & FMODE_WRITE))
4274 + array[ull] = NULL;
4280 + FiMustNoWaiters(file);
4281 + fi_read_unlock(file);
4289 + for (ull = 0; ull < max; ull++) {
4290 + file = array[ull];
4294 + /* todo: already flushed? */
4296 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4297 + * approach which resets f_mode and calls mnt_drop_write() and
4298 + * file_release_write() for each file, because the branch
4299 + * attribute in aufs world is totally different from the native
4302 + /* fi_read_lock(file); */
4303 + hfile = &au_fi(file)->fi_htop;
4304 + hf = hfile->hf_file;
4305 + /* fi_read_unlock(file); */
4306 + spin_lock(&hf->f_lock);
4307 + writer = !!(hf->f_mode & FMODE_WRITER);
4308 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4309 + spin_unlock(&hf->f_lock);
4311 + h_inode = file_inode(hf);
4312 + put_write_access(h_inode);
4313 + __mnt_drop_write(hf->f_path.mnt);
4314 + if ((hf->f_mode & (FMODE_READ | FMODE_WRITE))
4316 + i_readcount_inc(h_inode);
4321 + au_farray_free(array, max);
4327 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4331 + aufs_bindex_t bindex;
4332 + struct dentry *root;
4333 + struct au_branch *br;
4334 + struct au_br_fhsm *bf;
4336 + root = sb->s_root;
4337 + bindex = au_find_dbindex(root, mod->h_root);
4340 + return 0; /* success */
4342 + pr_err("%s no such branch\n", mod->path);
4345 + AuDbg("bindex b%d\n", bindex);
4347 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4348 + if (unlikely(err))
4351 + br = au_sbr(sb, bindex);
4352 + AuDebugOn(mod->h_root != au_br_dentry(br));
4353 + if (br->br_perm == mod->perm)
4354 + return 0; /* success */
4356 + /* pre-allocate for non-fhsm --> fhsm */
4358 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4359 + err = au_fhsm_br_alloc(br);
4360 + if (unlikely(err))
4363 + br->br_fhsm = NULL;
4366 + if (au_br_writable(br->br_perm)) {
4367 + /* remove whiteout base */
4368 + err = au_br_init_wh(sb, br, mod->perm);
4369 + if (unlikely(err))
4372 + if (!au_br_writable(mod->perm)) {
4373 + /* rw --> ro, file might be mmapped */
4374 + DiMustNoWaiters(root);
4375 + IiMustNoWaiters(d_inode(root));
4376 + di_write_unlock(root);
4377 + err = au_br_mod_files_ro(sb, bindex);
4378 + /* aufs_write_lock() calls ..._child() */
4379 + di_write_lock_child(root);
4381 + if (unlikely(err)) {
4383 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4386 + rerr = au_wbr_init(br, sb, br->br_perm);
4387 + if (unlikely(rerr)) {
4388 + AuIOErr("nested error %d (%d)\n",
4390 + br->br_perm = mod->perm;
4394 + } else if (au_br_writable(mod->perm)) {
4397 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4399 + err = au_wbr_init(br, sb, mod->perm);
4400 + if (unlikely(err)) {
4401 + au_kfree_rcu(br->br_wbr);
4402 + br->br_wbr = NULL;
4406 + if (unlikely(err))
4409 + if (au_br_fhsm(br->br_perm)) {
4410 + if (!au_br_fhsm(mod->perm)) {
4411 + /* fhsm --> non-fhsm */
4412 + au_br_fhsm_fin(br->br_fhsm);
4413 + au_kfree_rcu(br->br_fhsm);
4414 + br->br_fhsm = NULL;
4416 + } else if (au_br_fhsm(mod->perm))
4417 + /* non-fhsm --> fhsm */
4420 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4421 + br->br_perm = mod->perm;
4422 + goto out; /* success */
4425 + au_kfree_try_rcu(bf);
4431 +/* ---------------------------------------------------------------------- */
4433 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4436 + struct kstatfs kstfs;
4438 + err = vfs_statfs(&br->br_path, &kstfs);
4440 + stfs->f_blocks = kstfs.f_blocks;
4441 + stfs->f_bavail = kstfs.f_bavail;
4442 + stfs->f_files = kstfs.f_files;
4443 + stfs->f_ffree = kstfs.f_ffree;
4448 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4449 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4450 +++ linux/fs/aufs/branch.h 2020-01-27 10:57:18.165538015 +0100
4452 +/* SPDX-License-Identifier: GPL-2.0 */
4454 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4456 + * This program, aufs is free software; you can redistribute it and/or modify
4457 + * it under the terms of the GNU General Public License as published by
4458 + * the Free Software Foundation; either version 2 of the License, or
4459 + * (at your option) any later version.
4461 + * This program is distributed in the hope that it will be useful,
4462 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4463 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4464 + * GNU General Public License for more details.
4466 + * You should have received a copy of the GNU General Public License
4467 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4471 + * branch filesystems and xino for them
4474 +#ifndef __AUFS_BRANCH_H__
4475 +#define __AUFS_BRANCH_H__
4479 +#include <linux/mount.h>
4480 +#include "dirren.h"
4486 +/* ---------------------------------------------------------------------- */
4490 + struct file **xi_file;
4491 + unsigned int xi_nfile;
4497 + /* reserved for future use */
4498 + /* unsigned long *bitmap; */
4499 + wait_queue_head_t wqh;
4502 + struct mutex xi_mtx; /* protects xi_file array */
4503 + struct hlist_bl_head xi_writing;
4505 + atomic_t xi_truncating;
4507 + struct kref xi_kref;
4510 +/* File-based Hierarchical Storage Management */
4511 +struct au_br_fhsm {
4512 +#ifdef CONFIG_AUFS_FHSM
4513 + struct mutex bf_lock;
4514 + unsigned long bf_jiffy;
4515 + struct aufs_stfs bf_stfs;
4520 +/* members for writable branch only */
4521 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4523 + struct au_rwsem wbr_wh_rwsem;
4524 + struct dentry *wbr_wh[AuBrWh_Last];
4525 + atomic_t wbr_wh_running;
4526 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4527 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4528 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4531 + unsigned long long wbr_bytes;
4534 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4535 +#define AuBrDynOp (AuDyLast * 4)
4537 +#ifdef CONFIG_AUFS_HFSNOTIFY
4538 +/* support for asynchronous destruction */
4539 +struct au_br_hfsnotify {
4540 + struct fsnotify_group *hfsn_group;
4544 +/* sysfs entries */
4545 +struct au_brsysfs {
4547 + struct attribute attr;
4556 +/* protected by superblock rwsem */
4558 + struct au_xino *br_xino;
4560 + aufs_bindex_t br_id;
4563 + struct path br_path;
4564 + spinlock_t br_dykey_lock;
4565 + struct au_dykey *br_dykey[AuBrDynOp];
4566 + au_lcnt_t br_nfiles; /* opened files */
4567 + au_lcnt_t br_count; /* in-use for other */
4569 + struct au_wbr *br_wbr;
4570 + struct au_br_fhsm *br_fhsm;
4572 +#ifdef CONFIG_AUFS_HFSNOTIFY
4573 + struct au_br_hfsnotify *br_hfsn;
4576 +#ifdef CONFIG_SYSFS
4577 + /* entries under sysfs per mount-point */
4578 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4581 +#ifdef CONFIG_DEBUG_FS
4582 + struct dentry *br_dbgaufs; /* xino */
4585 + struct au_dr_br br_dirren;
4588 +/* ---------------------------------------------------------------------- */
4590 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4592 + return br->br_path.mnt;
4595 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4597 + return br->br_path.dentry;
4600 +static inline struct super_block *au_br_sb(struct au_branch *br)
4602 + return au_br_mnt(br)->mnt_sb;
4605 +static inline int au_br_rdonly(struct au_branch *br)
4607 + return (sb_rdonly(au_br_sb(br))
4608 + || !au_br_writable(br->br_perm))
4612 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4614 +#ifdef CONFIG_AUFS_HNOTIFY
4615 + return !(brperm & AuBrPerm_RR);
4621 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4623 + int err, exec_flag;
4626 + exec_flag = oflag & __FMODE_EXEC;
4627 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4633 +static inline void au_xino_get(struct au_branch *br)
4635 + struct au_xino *xi;
4639 + kref_get(&xi->xi_kref);
4642 +static inline int au_xino_count(struct au_branch *br)
4645 + struct au_xino *xi;
4650 + v = kref_read(&xi->xi_kref);
4655 +/* ---------------------------------------------------------------------- */
4659 +void au_br_free(struct au_sbinfo *sinfo);
4660 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4662 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4664 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4665 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4666 +#ifdef CONFIG_COMPAT
4667 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4670 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4673 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4676 +static const loff_t au_loff_max = LLONG_MAX;
4678 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4679 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4681 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4682 + struct file *copy_src);
4684 + struct au_xino *xi; /* switch between xino and xigen */
4686 + struct path *base;
4687 + struct file *copy_src;
4689 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4691 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4693 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4695 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4697 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4698 + size_t size, loff_t *pos);
4700 +int au_xib_trunc(struct super_block *sb);
4701 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4703 +struct au_xino *au_xino_alloc(unsigned int nfile);
4704 +int au_xino_put(struct au_branch *br);
4705 +struct file *au_xino_file1(struct au_xino *xi);
4707 +struct au_opt_xino;
4708 +void au_xino_clr(struct super_block *sb);
4709 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4710 +struct file *au_xino_def(struct super_block *sb);
4711 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4712 + struct path *base);
4714 +ino_t au_xino_new_ino(struct super_block *sb);
4715 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4717 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4718 + ino_t h_ino, int idx);
4719 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4722 +int au_xino_path(struct seq_file *seq, struct file *file);
4724 +/* ---------------------------------------------------------------------- */
4726 +/* @idx is signed to accept -1 meaning the first file */
4727 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4729 + struct file *file;
4736 + if (idx < xi->xi_nfile)
4737 + file = xi->xi_file[idx];
4739 + file = au_xino_file1(xi);
4745 +/* ---------------------------------------------------------------------- */
4747 +/* Superblock to branch */
4749 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4751 + return au_sbr(sb, bindex)->br_id;
4755 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4757 + return au_br_mnt(au_sbr(sb, bindex));
4761 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4763 + return au_br_sb(au_sbr(sb, bindex));
4766 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4768 + return au_sbr(sb, bindex)->br_perm;
4771 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4773 + return au_br_whable(au_sbr_perm(sb, bindex));
4776 +/* ---------------------------------------------------------------------- */
4778 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4779 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4780 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4781 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4783 +#define wbr_wh_read_trylock_nested(wbr) \
4784 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4785 +#define wbr_wh_write_trylock_nested(wbr) \
4786 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4789 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4790 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4791 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4793 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4794 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4795 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4797 +/* ---------------------------------------------------------------------- */
4799 +#ifdef CONFIG_AUFS_FHSM
4800 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4802 + mutex_init(&brfhsm->bf_lock);
4803 + brfhsm->bf_jiffy = 0;
4804 + brfhsm->bf_readable = 0;
4807 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4809 + mutex_destroy(&brfhsm->bf_lock);
4812 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4813 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4816 +#endif /* __KERNEL__ */
4817 +#endif /* __AUFS_BRANCH_H__ */
4818 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4819 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4820 +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200
4822 +# SPDX-License-Identifier: GPL-2.0
4824 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4828 +AuConfStr += ${1}=${${1}}
4832 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4834 + HNOTIFY HFSNOTIFY \
4846 +$(foreach i, ${AuConfAll}, \
4847 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4849 +AuConfName = ${obj}/conf.str
4850 +${AuConfName}.tmp: FORCE
4851 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4852 +${AuConfName}: ${AuConfName}.tmp
4853 + @diff -q $< $@ > /dev/null 2>&1 || { \
4854 + echo ' GEN ' $@; \
4858 +clean-files += ${AuConfName} ${AuConfName}.tmp
4859 +${obj}/sysfs.o: ${AuConfName}
4861 +-include ${srctree}/${src}/conf_priv.mk
4862 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4863 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4864 +++ linux/fs/aufs/cpup.c 2020-01-27 10:57:18.165538015 +0100
4866 +// SPDX-License-Identifier: GPL-2.0
4868 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4870 + * This program, aufs is free software; you can redistribute it and/or modify
4871 + * it under the terms of the GNU General Public License as published by
4872 + * the Free Software Foundation; either version 2 of the License, or
4873 + * (at your option) any later version.
4875 + * This program is distributed in the hope that it will be useful,
4876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4878 + * GNU General Public License for more details.
4880 + * You should have received a copy of the GNU General Public License
4881 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4885 + * copy-up functions, see wbr_policy.c for copy-down
4888 +#include <linux/fs_stack.h>
4889 +#include <linux/mm.h>
4890 +#include <linux/task_work.h>
4893 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4895 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4896 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4898 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4900 + dst->i_flags |= iflags & ~mask;
4901 + if (au_test_fs_notime(dst->i_sb))
4902 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4905 +void au_cpup_attr_timesizes(struct inode *inode)
4907 + struct inode *h_inode;
4909 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4910 + fsstack_copy_attr_times(inode, h_inode);
4911 + fsstack_copy_inode_size(inode, h_inode);
4914 +void au_cpup_attr_nlink(struct inode *inode, int force)
4916 + struct inode *h_inode;
4917 + struct super_block *sb;
4918 + aufs_bindex_t bindex, bbot;
4921 + bindex = au_ibtop(inode);
4922 + h_inode = au_h_iptr(inode, bindex);
4924 + && !S_ISDIR(h_inode->i_mode)
4925 + && au_opt_test(au_mntflags(sb), PLINK)
4926 + && au_plink_test(inode))
4930 + * 0 can happen in revalidating.
4931 + * h_inode->i_mutex may not be held here, but it is harmless since once
4932 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4934 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4935 + * the incorrect link count.
4937 + set_nlink(inode, h_inode->i_nlink);
4940 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4941 + * it may includes whplink directory.
4943 + if (S_ISDIR(h_inode->i_mode)) {
4944 + bbot = au_ibbot(inode);
4945 + for (bindex++; bindex <= bbot; bindex++) {
4946 + h_inode = au_h_iptr(inode, bindex);
4948 + au_add_nlink(inode, h_inode);
4953 +void au_cpup_attr_changeable(struct inode *inode)
4955 + struct inode *h_inode;
4957 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4958 + inode->i_mode = h_inode->i_mode;
4959 + inode->i_uid = h_inode->i_uid;
4960 + inode->i_gid = h_inode->i_gid;
4961 + au_cpup_attr_timesizes(inode);
4962 + au_cpup_attr_flags(inode, h_inode->i_flags);
4965 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4967 + struct au_iinfo *iinfo = au_ii(inode);
4969 + IiMustWriteLock(inode);
4971 + iinfo->ii_higen = h_inode->i_generation;
4972 + iinfo->ii_hsb1 = h_inode->i_sb;
4975 +void au_cpup_attr_all(struct inode *inode, int force)
4977 + struct inode *h_inode;
4979 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4980 + au_cpup_attr_changeable(inode);
4981 + if (inode->i_nlink > 0)
4982 + au_cpup_attr_nlink(inode, force);
4983 + inode->i_rdev = h_inode->i_rdev;
4984 + inode->i_blkbits = h_inode->i_blkbits;
4985 + au_cpup_igen(inode, h_inode);
4988 +/* ---------------------------------------------------------------------- */
4990 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4992 +/* keep the timestamps of the parent dir when cpup */
4993 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4994 + struct path *h_path)
4996 + struct inode *h_inode;
4998 + dt->dt_dentry = dentry;
4999 + dt->dt_h_path = *h_path;
5000 + h_inode = d_inode(h_path->dentry);
5001 + dt->dt_atime = h_inode->i_atime;
5002 + dt->dt_mtime = h_inode->i_mtime;
5006 +void au_dtime_revert(struct au_dtime *dt)
5008 + struct iattr attr;
5011 + attr.ia_atime = dt->dt_atime;
5012 + attr.ia_mtime = dt->dt_mtime;
5013 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5014 + | ATTR_ATIME | ATTR_ATIME_SET;
5016 + /* no delegation since this is a directory */
5017 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5018 + if (unlikely(err))
5019 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5022 +/* ---------------------------------------------------------------------- */
5024 +/* internal use only */
5025 +struct au_cpup_reg_attr {
5028 + unsigned int iflags; /* inode->i_flags */
5031 +static noinline_for_stack
5032 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5033 + struct au_cpup_reg_attr *h_src_attr)
5035 + int err, sbits, icex;
5036 + unsigned int mnt_flags;
5037 + unsigned char verbose;
5039 + struct path h_path;
5040 + struct inode *h_isrc, *h_idst;
5041 + struct kstat *h_st;
5042 + struct au_branch *br;
5044 + h_path.dentry = au_h_dptr(dst, bindex);
5045 + h_idst = d_inode(h_path.dentry);
5046 + br = au_sbr(dst->d_sb, bindex);
5047 + h_path.mnt = au_br_mnt(br);
5048 + h_isrc = d_inode(h_src);
5049 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5050 + | ATTR_ATIME | ATTR_MTIME
5051 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5052 + if (h_src_attr && h_src_attr->valid) {
5053 + h_st = &h_src_attr->st;
5054 + ia.ia_uid = h_st->uid;
5055 + ia.ia_gid = h_st->gid;
5056 + ia.ia_atime = h_st->atime;
5057 + ia.ia_mtime = h_st->mtime;
5058 + if (h_idst->i_mode != h_st->mode
5059 + && !S_ISLNK(h_idst->i_mode)) {
5060 + ia.ia_valid |= ATTR_MODE;
5061 + ia.ia_mode = h_st->mode;
5063 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5064 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5066 + ia.ia_uid = h_isrc->i_uid;
5067 + ia.ia_gid = h_isrc->i_gid;
5068 + ia.ia_atime = h_isrc->i_atime;
5069 + ia.ia_mtime = h_isrc->i_mtime;
5070 + if (h_idst->i_mode != h_isrc->i_mode
5071 + && !S_ISLNK(h_idst->i_mode)) {
5072 + ia.ia_valid |= ATTR_MODE;
5073 + ia.ia_mode = h_isrc->i_mode;
5075 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5076 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5078 + /* no delegation since it is just created */
5079 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5081 + /* is this nfs only? */
5082 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5083 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5084 + ia.ia_mode = h_isrc->i_mode;
5085 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5088 + icex = br->br_perm & AuBrAttr_ICEX;
5090 + mnt_flags = au_mntflags(dst->d_sb);
5091 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5092 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5098 +/* ---------------------------------------------------------------------- */
5100 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5101 + char *buf, unsigned long blksize)
5104 + size_t sz, rbytes, wbytes;
5105 + unsigned char all_zero;
5107 + struct inode *h_inode;
5108 + /* reduce stack usage */
5111 + zp = page_address(ZERO_PAGE(0));
5112 + if (unlikely(!zp))
5113 + return -ENOMEM; /* possible? */
5118 + AuDbg("len %lld\n", len);
5120 + if (len < blksize)
5124 + /* todo: signal_pending? */
5125 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5126 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5129 + if (unlikely(err < 0))
5133 + if (len >= rbytes && rbytes == blksize)
5134 + all_zero = !memcmp(buf, zp, rbytes);
5141 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5143 + /* todo: signal_pending? */
5144 + if (unlikely(err == -EAGAIN || err == -EINTR))
5146 + if (unlikely(err < 0))
5151 + if (unlikely(err < 0))
5157 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5159 + if (unlikely(res < 0))
5166 + /* the last block may be a hole */
5167 + if (!err && all_zero) {
5168 + AuLabel(last hole);
5171 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5172 + /* nfs requires this step to make last hole */
5173 + /* is this only nfs? */
5175 + /* todo: signal_pending? */
5176 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5177 + } while (err == -EAGAIN || err == -EINTR);
5184 + ia->ia_size = dst->f_pos;
5185 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5186 + ia->ia_file = dst;
5187 + h_inode = file_inode(dst);
5188 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5189 + /* no delegation since it is just created */
5190 + err = vfsub_notify_change(&dst->f_path, ia,
5191 + /*delegated*/NULL);
5192 + inode_unlock(h_inode);
5199 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5202 + unsigned long blksize;
5203 + unsigned char do_kfree;
5205 + struct super_block *h_sb;
5208 + h_sb = file_inode(dst)->i_sb;
5209 + blksize = h_sb->s_blocksize;
5210 + if (!blksize || PAGE_SIZE < blksize)
5211 + blksize = PAGE_SIZE;
5212 + AuDbg("blksize %lu\n", blksize);
5213 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5215 + buf = kmalloc(blksize, GFP_NOFS);
5217 + buf = (void *)__get_free_page(GFP_NOFS);
5218 + if (unlikely(!buf))
5221 + if (len > (1 << 22))
5222 + AuDbg("copying a large file %lld\n", (long long)len);
5226 + err = au_do_copy_file(dst, src, len, buf, blksize);
5228 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5229 + au_kfree_do_rcu(buf);
5231 + free_page((unsigned long)buf);
5237 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5240 + struct super_block *h_src_sb;
5241 + struct inode *h_src_inode;
5243 + h_src_inode = file_inode(src);
5244 + h_src_sb = h_src_inode->i_sb;
5246 + /* XFS acquires inode_lock */
5247 + if (!au_test_xfs(h_src_sb))
5248 + err = au_copy_file(dst, src, len);
5250 + inode_unlock_shared(h_src_inode);
5251 + err = au_copy_file(dst, src, len);
5252 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5258 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5262 + struct super_block *h_src_sb;
5263 + struct inode *h_src_inode;
5265 + h_src_inode = file_inode(src);
5266 + h_src_sb = h_src_inode->i_sb;
5267 + if (h_src_sb != file_inode(dst)->i_sb
5268 + || !dst->f_op->remap_file_range) {
5269 + err = au_do_copy(dst, src, len);
5273 + if (!au_test_nfs(h_src_sb)) {
5274 + inode_unlock_shared(h_src_inode);
5275 + lo = vfsub_clone_file_range(src, dst, len);
5276 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5278 + lo = vfsub_clone_file_range(src, dst, len);
5281 + goto out; /* success */
5282 + } else if (lo >= 0)
5283 + /* todo: possible? */
5284 + /* paritially succeeded */
5285 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5286 + else if (lo != -EOPNOTSUPP) {
5287 + /* older XFS has a condition in cloning */
5292 + /* the backend fs on NFS may not support cloning */
5293 + err = au_do_copy(dst, src, len);
5301 + * to support a sparse file which is opened with O_APPEND,
5302 + * we need to close the file.
5304 +static int au_cp_regular(struct au_cp_generic *cpg)
5307 + enum { SRC, DST };
5309 + aufs_bindex_t bindex;
5310 + unsigned int flags;
5311 + struct dentry *dentry;
5313 + struct file *file;
5316 + .bindex = cpg->bsrc,
5317 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5320 + .bindex = cpg->bdst,
5321 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5322 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5325 + struct au_branch *br;
5326 + struct super_block *sb, *h_src_sb;
5327 + struct inode *h_src_inode;
5328 + struct task_struct *tsk = current;
5330 + /* bsrc branch can be ro/rw. */
5331 + sb = cpg->dentry->d_sb;
5333 + for (i = 0; i < 2; i++, f++) {
5334 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5335 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5336 + /*file*/NULL, f->force_wr);
5337 + if (IS_ERR(f->file)) {
5338 + err = PTR_ERR(f->file);
5346 + /* try stopping to update while we copyup */
5347 + h_src_inode = d_inode(file[SRC].dentry);
5348 + h_src_sb = h_src_inode->i_sb;
5349 + if (!au_test_nfs(h_src_sb))
5350 + IMustLock(h_src_inode);
5351 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5353 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5354 + if (tsk->flags & PF_KTHREAD)
5355 + __fput_sync(file[DST].file);
5357 + /* it happened actually */
5358 + fput(file[DST].file);
5361 + * we have to call both since we don't know which place the file
5365 + flush_delayed_fput();
5367 + br = au_sbr(sb, file[DST].bindex);
5368 + au_lcnt_dec(&br->br_nfiles);
5371 + fput(file[SRC].file);
5372 + br = au_sbr(sb, file[SRC].bindex);
5373 + au_lcnt_dec(&br->br_nfiles);
5378 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5379 + struct au_cpup_reg_attr *h_src_attr)
5383 + struct path h_path;
5384 + struct inode *h_src_inode, *h_dst_inode;
5387 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5388 + l = i_size_read(h_src_inode);
5389 + if (cpg->len == -1 || l < cpg->len)
5392 + /* try stopping to update while we are referencing */
5393 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5394 + au_pin_hdir_unlock(cpg->pin);
5396 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5397 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5398 + h_src_attr->iflags = h_src_inode->i_flags;
5399 + if (!au_test_nfs(h_src_inode->i_sb))
5400 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5402 + inode_unlock_shared(h_src_inode);
5403 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5404 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5406 + if (unlikely(err)) {
5407 + inode_unlock_shared(h_src_inode);
5410 + h_src_attr->valid = 1;
5411 + if (!au_test_nfs(h_src_inode->i_sb)) {
5412 + err = au_cp_regular(cpg);
5413 + inode_unlock_shared(h_src_inode);
5415 + inode_unlock_shared(h_src_inode);
5416 + err = au_cp_regular(cpg);
5418 + rerr = au_pin_hdir_relock(cpg->pin);
5422 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5423 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5424 + h_dst_inode = d_inode(h_path.dentry);
5425 + spin_lock(&h_dst_inode->i_lock);
5426 + h_dst_inode->i_state |= I_LINKABLE;
5427 + spin_unlock(&h_dst_inode->i_lock);
5434 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5435 + struct inode *h_dir)
5438 + mm_segment_t old_fs;
5445 + sym.k = (void *)__get_free_page(GFP_NOFS);
5446 + if (unlikely(!sym.k))
5449 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5450 + old_fs = get_fs();
5451 + set_fs(KERNEL_DS);
5452 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5457 + sym.k[symlen] = 0;
5458 + err = vfsub_symlink(h_dir, h_path, sym.k);
5460 + free_page((unsigned long)sym.k);
5467 + * regardless 'acl' option, reset all ACL.
5468 + * All ACL will be copied up later from the original entry on the lower branch.
5470 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5473 + struct dentry *h_dentry;
5474 + struct inode *h_inode;
5476 + h_dentry = h_path->dentry;
5477 + h_inode = d_inode(h_dentry);
5478 + /* forget_all_cached_acls(h_inode)); */
5479 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5481 + if (err == -EOPNOTSUPP)
5484 + err = vfsub_acl_chmod(h_inode, mode);
5490 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5491 + struct inode *h_dir, struct path *h_path)
5494 + struct inode *dir, *inode;
5496 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5498 + if (err == -EOPNOTSUPP)
5500 + if (unlikely(err))
5504 + * strange behaviour from the users view,
5505 + * particularly setattr case
5507 + dir = d_inode(dst_parent);
5508 + if (au_ibtop(dir) == cpg->bdst)
5509 + au_cpup_attr_nlink(dir, /*force*/1);
5510 + inode = d_inode(cpg->dentry);
5511 + au_cpup_attr_nlink(inode, /*force*/1);
5517 +static noinline_for_stack
5518 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5519 + struct au_cpup_reg_attr *h_src_attr)
5523 + unsigned int mnt_flags;
5524 + unsigned char isdir, isreg, force;
5525 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5526 + struct au_dtime dt;
5527 + struct path h_path;
5528 + struct dentry *h_src, *h_dst, *h_parent;
5529 + struct inode *h_inode, *h_dir;
5530 + struct super_block *sb;
5532 + /* bsrc branch can be ro/rw. */
5533 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5534 + h_inode = d_inode(h_src);
5535 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5537 + /* try stopping to be referenced while we are creating */
5538 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5539 + if (au_ftest_cpup(cpg->flags, RENAME))
5540 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5541 + AUFS_WH_PFX_LEN));
5542 + h_parent = h_dst->d_parent; /* dir inode is locked */
5543 + h_dir = d_inode(h_parent);
5545 + AuDebugOn(h_parent != h_dst->d_parent);
5547 + sb = cpg->dentry->d_sb;
5548 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5550 + h_path.dentry = h_parent;
5551 + au_dtime_store(&dt, dst_parent, &h_path);
5553 + h_path.dentry = h_dst;
5557 + mode = h_inode->i_mode;
5558 + switch (mode & S_IFMT) {
5561 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5563 + err = au_do_cpup_regular(cpg, h_src_attr);
5567 + err = vfsub_mkdir(h_dir, &h_path, mode);
5569 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5572 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5576 + AuDebugOn(!capable(CAP_MKNOD));
5580 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5583 + AuIOErr("Unknown inode type 0%o\n", mode);
5587 + err = au_reset_acl(h_dir, &h_path, mode);
5589 + mnt_flags = au_mntflags(sb);
5590 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5592 + && au_opt_test(mnt_flags, XINO)
5593 + && (h_inode->i_nlink == 1
5594 + || (h_inode->i_state & I_LINKABLE))
5595 + /* todo: unnecessary? */
5596 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5597 + && cpg->bdst < cpg->bsrc
5598 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5599 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5600 + /* ignore this error */
5605 + force = !!cpg->len;
5606 + if (cpg->len == -1)
5607 + force = !!i_size_read(h_inode);
5609 + au_fhsm_wrote(sb, cpg->bdst, force);
5613 + au_dtime_revert(&dt);
5617 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5620 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5621 + struct inode *h_dir;
5622 + aufs_bindex_t bdst;
5624 + dentry = cpg->dentry;
5626 + h_dentry = au_h_dptr(dentry, bdst);
5627 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5629 + au_set_h_dptr(dentry, bdst, NULL);
5630 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5632 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5633 + au_set_h_dptr(dentry, bdst, h_dentry);
5636 + parent = dget_parent(dentry);
5637 + h_parent = au_h_dptr(parent, bdst);
5639 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5640 + if (IS_ERR(h_path->dentry))
5641 + err = PTR_ERR(h_path->dentry);
5643 + if (unlikely(err))
5646 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5647 + h_dir = d_inode(h_parent);
5649 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5650 + /* no delegation since it is just created */
5651 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5653 + dput(h_path->dentry);
5660 + * copyup the @dentry from @bsrc to @bdst.
5661 + * the caller must set the both of lower dentries.
5662 + * @len is for truncating when it is -1 copyup the entire file.
5663 + * in link/rename cases, @dst_parent may be different from the real one.
5664 + * basic->bsrc can be larger than basic->bdst.
5665 + * aufs doesn't touch the credential so
5666 + * security_inode_copy_up{,_xattr}() are unnecessary.
5668 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5671 + aufs_bindex_t old_ibtop;
5672 + unsigned char isdir, plink;
5673 + struct dentry *h_src, *h_dst, *h_parent;
5674 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5675 + struct super_block *sb;
5676 + struct au_branch *br;
5677 + /* to reduce stack size */
5679 + struct au_dtime dt;
5680 + struct path h_path;
5681 + struct au_cpup_reg_attr h_src_attr;
5685 + a = kmalloc(sizeof(*a), GFP_NOFS);
5688 + a->h_src_attr.valid = 0;
5690 + sb = cpg->dentry->d_sb;
5691 + br = au_sbr(sb, cpg->bdst);
5692 + a->h_path.mnt = au_br_mnt(br);
5693 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5694 + h_parent = h_dst->d_parent; /* dir inode is locked */
5695 + h_dir = d_inode(h_parent);
5698 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5699 + inode = d_inode(cpg->dentry);
5702 + dst_parent = dget_parent(cpg->dentry);
5706 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5707 + dst_inode = au_h_iptr(inode, cpg->bdst);
5709 + if (unlikely(!plink)) {
5711 + AuIOErr("hi%lu(i%lu) exists on b%d "
5712 + "but plink is disabled\n",
5713 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5717 + if (dst_inode->i_nlink) {
5718 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5720 + h_src = au_plink_lkup(inode, cpg->bdst);
5721 + err = PTR_ERR(h_src);
5722 + if (IS_ERR(h_src))
5724 + if (unlikely(d_is_negative(h_src))) {
5726 + AuIOErr("i%lu exists on b%d "
5727 + "but not pseudo-linked\n",
5728 + inode->i_ino, cpg->bdst);
5734 + a->h_path.dentry = h_parent;
5735 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5738 + a->h_path.dentry = h_dst;
5740 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5741 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5742 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5744 + au_dtime_revert(&a->dt);
5745 + if (unlikely(err == -EWOULDBLOCK)) {
5746 + pr_warn("cannot retry for NFSv4 delegation"
5747 + " for an internal link\n");
5753 + /* todo: cpup_wh_file? */
5755 + au_update_ibrange(inode, /*do_put_zero*/1);
5758 + isdir = S_ISDIR(inode->i_mode);
5759 + old_ibtop = au_ibtop(inode);
5760 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5761 + if (unlikely(err))
5763 + dst_inode = d_inode(h_dst);
5764 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5765 + /* todo: necessary? */
5766 + /* au_pin_hdir_unlock(cpg->pin); */
5768 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5769 + if (unlikely(err)) {
5770 + /* todo: necessary? */
5771 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5772 + inode_unlock(dst_inode);
5776 + if (cpg->bdst < old_ibtop) {
5777 + if (S_ISREG(inode->i_mode)) {
5778 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5779 + if (unlikely(err)) {
5780 + /* ignore an error */
5781 + /* au_pin_hdir_relock(cpg->pin); */
5782 + inode_unlock(dst_inode);
5786 + au_set_ibtop(inode, cpg->bdst);
5788 + au_set_ibbot(inode, cpg->bdst);
5789 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5790 + au_hi_flags(inode, isdir));
5792 + /* todo: necessary? */
5793 + /* err = au_pin_hdir_relock(cpg->pin); */
5794 + inode_unlock(dst_inode);
5795 + if (unlikely(err))
5798 + src_inode = d_inode(h_src);
5800 + && (src_inode->i_nlink > 1
5801 + || src_inode->i_state & I_LINKABLE)
5803 + au_plink_append(inode, cpg->bdst, h_dst);
5805 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5806 + a->h_path.dentry = h_dst;
5807 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5810 + goto out_parent; /* success */
5814 + a->h_path.dentry = h_parent;
5815 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5816 + a->h_path.dentry = h_dst;
5818 + if (d_is_positive(h_dst)) {
5820 + /* no delegation since it is just created */
5821 + rerr = vfsub_unlink(h_dir, &a->h_path,
5822 + /*delegated*/NULL, /*force*/0);
5824 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5826 + au_dtime_revert(&a->dt);
5828 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5838 +#if 0 /* reserved */
5839 +struct au_cpup_single_args {
5841 + struct au_cp_generic *cpg;
5842 + struct dentry *dst_parent;
5845 +static void au_call_cpup_single(void *args)
5847 + struct au_cpup_single_args *a = args;
5849 + au_pin_hdir_acquire_nest(a->cpg->pin);
5850 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5851 + au_pin_hdir_release(a->cpg->pin);
5856 + * prevent SIGXFSZ in copy-up.
5857 + * testing CAP_MKNOD is for generic fs,
5858 + * but CAP_FSETID is for xfs only, currently.
5860 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5863 + struct super_block *sb;
5864 + struct inode *h_dir;
5867 + sb = au_pinned_parent(pin)->d_sb;
5868 + if (!au_wkq_test()
5869 + && (!au_sbi(sb)->si_plink_maint_pid
5870 + || au_plink_maint(sb, AuLock_NOPLM))) {
5871 + switch (mode & S_IFMT) {
5873 + /* no condition about RLIMIT_FSIZE and the file size */
5878 + do_sio = !capable(CAP_MKNOD);
5882 + do_sio = ((mode & (S_ISUID | S_ISGID))
5883 + && !capable(CAP_FSETID));
5884 + /* this workaround may be removed in the future */
5886 + h_dir = au_pinned_h_dir(pin);
5887 + do_sio = h_dir->i_mode & S_ISVTX;
5894 +#if 0 /* reserved */
5895 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5898 + struct dentry *h_dentry;
5900 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5901 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5902 + err = au_cpup_single(cpg, dst_parent);
5904 + struct au_cpup_single_args args = {
5907 + .dst_parent = dst_parent
5909 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5910 + if (unlikely(wkq_err))
5919 + * copyup the @dentry from the first active lower branch to @bdst,
5920 + * using au_cpup_single().
5922 +static int au_cpup_simple(struct au_cp_generic *cpg)
5925 + unsigned int flags_orig;
5926 + struct dentry *dentry;
5928 + AuDebugOn(cpg->bsrc < 0);
5930 + dentry = cpg->dentry;
5931 + DiMustWriteLock(dentry);
5933 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5935 + flags_orig = cpg->flags;
5936 + au_fset_cpup(cpg->flags, RENAME);
5937 + err = au_cpup_single(cpg, NULL);
5938 + cpg->flags = flags_orig;
5940 + return 0; /* success */
5943 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5944 + au_set_dbtop(dentry, cpg->bsrc);
5950 +struct au_cpup_simple_args {
5952 + struct au_cp_generic *cpg;
5955 +static void au_call_cpup_simple(void *args)
5957 + struct au_cpup_simple_args *a = args;
5959 + au_pin_hdir_acquire_nest(a->cpg->pin);
5960 + *a->errp = au_cpup_simple(a->cpg);
5961 + au_pin_hdir_release(a->cpg->pin);
5964 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5967 + struct dentry *dentry, *parent;
5968 + struct file *h_file;
5969 + struct inode *h_dir;
5971 + dentry = cpg->dentry;
5973 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5974 + AuDebugOn(cpg->bsrc < 0);
5975 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5976 + err = PTR_ERR(h_file);
5977 + if (IS_ERR(h_file))
5981 + parent = dget_parent(dentry);
5982 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5983 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5984 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5985 + err = au_cpup_simple(cpg);
5987 + struct au_cpup_simple_args args = {
5991 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5992 + if (unlikely(wkq_err))
5998 + au_h_open_post(dentry, cpg->bsrc, h_file);
6004 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6006 + aufs_bindex_t bsrc, bbot;
6007 + struct dentry *dentry, *h_dentry;
6009 + if (cpg->bsrc < 0) {
6010 + dentry = cpg->dentry;
6011 + bbot = au_dbbot(dentry);
6012 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6013 + h_dentry = au_h_dptr(dentry, bsrc);
6015 + AuDebugOn(d_is_negative(h_dentry));
6019 + AuDebugOn(bsrc > bbot);
6022 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6023 + return au_do_sio_cpup_simple(cpg);
6026 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6028 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6029 + return au_do_sio_cpup_simple(cpg);
6032 +/* ---------------------------------------------------------------------- */
6035 + * copyup the deleted file for writing.
6037 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6038 + struct file *file)
6041 + unsigned int flags_orig;
6042 + aufs_bindex_t bsrc_orig;
6043 + struct au_dinfo *dinfo;
6045 + struct au_hdentry *hd;
6046 + struct dentry *h_dentry;
6049 + dinfo = au_di(cpg->dentry);
6050 + AuRwMustWriteLock(&dinfo->di_rwsem);
6052 + bsrc_orig = cpg->bsrc;
6053 + cpg->bsrc = dinfo->di_btop;
6054 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6055 + hdst.h_dentry = hdst.hd->hd_dentry;
6056 + hdst.hd->hd_dentry = wh_dentry;
6057 + dinfo->di_btop = cpg->bdst;
6059 + hsrc.h_dentry = NULL;
6061 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6062 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6063 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6065 + flags_orig = cpg->flags;
6066 + cpg->flags = !AuCpup_DTIME;
6067 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6068 + cpg->flags = flags_orig;
6071 + err = au_reopen_nondir(file);
6072 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6074 + hdst.hd->hd_dentry = hdst.h_dentry;
6075 + dinfo->di_btop = cpg->bsrc;
6076 + cpg->bsrc = bsrc_orig;
6081 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6084 + aufs_bindex_t bdst;
6085 + struct au_dtime dt;
6086 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6087 + struct au_branch *br;
6088 + struct path h_path;
6090 + dentry = cpg->dentry;
6092 + br = au_sbr(dentry->d_sb, bdst);
6093 + parent = dget_parent(dentry);
6094 + h_parent = au_h_dptr(parent, bdst);
6095 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6096 + err = PTR_ERR(wh_dentry);
6097 + if (IS_ERR(wh_dentry))
6100 + h_path.dentry = h_parent;
6101 + h_path.mnt = au_br_mnt(br);
6102 + au_dtime_store(&dt, parent, &h_path);
6103 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6104 + if (unlikely(err))
6108 + h_path.dentry = wh_dentry;
6109 + if (!d_is_dir(wh_dentry)) {
6110 + /* no delegation since it is just created */
6111 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6112 + /*delegated*/NULL, /*force*/0);
6114 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6115 + if (unlikely(err)) {
6116 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6120 + au_dtime_revert(&dt);
6121 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6130 +struct au_cpup_wh_args {
6132 + struct au_cp_generic *cpg;
6133 + struct file *file;
6136 +static void au_call_cpup_wh(void *args)
6138 + struct au_cpup_wh_args *a = args;
6140 + au_pin_hdir_acquire_nest(a->cpg->pin);
6141 + *a->errp = au_cpup_wh(a->cpg, a->file);
6142 + au_pin_hdir_release(a->cpg->pin);
6145 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6148 + aufs_bindex_t bdst;
6149 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6150 + struct inode *dir, *h_dir, *h_tmpdir;
6151 + struct au_wbr *wbr;
6152 + struct au_pin wh_pin, *pin_orig;
6154 + dentry = cpg->dentry;
6156 + parent = dget_parent(dentry);
6157 + dir = d_inode(parent);
6160 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6163 + if (!h_dir->i_nlink) {
6164 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6165 + h_orph = wbr->wbr_orph;
6167 + h_parent = dget(au_h_dptr(parent, bdst));
6168 + au_set_h_dptr(parent, bdst, dget(h_orph));
6169 + h_tmpdir = d_inode(h_orph);
6170 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6172 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6173 + /* todo: au_h_open_pre()? */
6175 + pin_orig = cpg->pin;
6176 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6177 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6178 + cpg->pin = &wh_pin;
6181 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6182 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6183 + err = au_cpup_wh(cpg, file);
6185 + struct au_cpup_wh_args args = {
6190 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6191 + if (unlikely(wkq_err))
6196 + inode_unlock(h_tmpdir);
6197 + /* todo: au_h_open_post()? */
6198 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6199 + au_set_h_dptr(parent, bdst, h_parent);
6200 + AuDebugOn(!pin_orig);
6201 + cpg->pin = pin_orig;
6209 +/* ---------------------------------------------------------------------- */
6212 + * generic routine for both of copy-up and copy-down.
6214 +/* cf. revalidate function in file.c */
6215 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6216 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6217 + struct au_pin *pin,
6218 + struct dentry *h_parent, void *arg),
6222 + struct au_pin pin;
6223 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6226 + parent = dget_parent(dentry);
6227 + if (IS_ROOT(parent))
6230 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6231 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6233 + /* do not use au_dpage */
6234 + real_parent = parent;
6237 + parent = dget_parent(dentry);
6238 + h_parent = au_h_dptr(parent, bdst);
6240 + goto out; /* success */
6242 + /* find top dir which is necessary to cpup */
6246 + parent = dget_parent(d);
6247 + di_read_lock_parent3(parent, !AuLock_IR);
6248 + h_parent = au_h_dptr(parent, bdst);
6249 + di_read_unlock(parent, !AuLock_IR);
6250 + } while (!h_parent);
6252 + if (d != real_parent)
6253 + di_write_lock_child3(d);
6255 + /* somebody else might create while we were sleeping */
6256 + h_dentry = au_h_dptr(d, bdst);
6257 + if (!h_dentry || d_is_negative(h_dentry)) {
6259 + au_update_dbtop(d);
6261 + au_pin_set_dentry(&pin, d);
6262 + err = au_do_pin(&pin);
6264 + err = cp(d, bdst, &pin, h_parent, arg);
6269 + if (d != real_parent)
6270 + di_write_unlock(d);
6271 + if (unlikely(err))
6280 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6281 + struct au_pin *pin,
6282 + struct dentry *h_parent __maybe_unused,
6283 + void *arg __maybe_unused)
6285 + struct au_cp_generic cpg = {
6291 + .flags = AuCpup_DTIME
6293 + return au_sio_cpup_simple(&cpg);
6296 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6298 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6301 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6304 + struct dentry *parent;
6305 + struct inode *dir;
6307 + parent = dget_parent(dentry);
6308 + dir = d_inode(parent);
6310 + if (au_h_iptr(dir, bdst))
6313 + di_read_unlock(parent, AuLock_IR);
6314 + di_write_lock_parent(parent);
6315 + /* someone else might change our inode while we were sleeping */
6316 + if (!au_h_iptr(dir, bdst))
6317 + err = au_cpup_dirs(dentry, bdst);
6318 + di_downgrade_lock(parent, AuLock_IR);
6324 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6325 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6326 +++ linux/fs/aufs/cpup.h 2020-01-27 10:57:18.168871450 +0100
6328 +/* SPDX-License-Identifier: GPL-2.0 */
6330 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6332 + * This program, aufs is free software; you can redistribute it and/or modify
6333 + * it under the terms of the GNU General Public License as published by
6334 + * the Free Software Foundation; either version 2 of the License, or
6335 + * (at your option) any later version.
6337 + * This program is distributed in the hope that it will be useful,
6338 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6339 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6340 + * GNU General Public License for more details.
6342 + * You should have received a copy of the GNU General Public License
6343 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6347 + * copy-up/down functions
6350 +#ifndef __AUFS_CPUP_H__
6351 +#define __AUFS_CPUP_H__
6355 +#include <linux/path.h>
6361 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6362 +void au_cpup_attr_timesizes(struct inode *inode);
6363 +void au_cpup_attr_nlink(struct inode *inode, int force);
6364 +void au_cpup_attr_changeable(struct inode *inode);
6365 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6366 +void au_cpup_attr_all(struct inode *inode, int force);
6368 +/* ---------------------------------------------------------------------- */
6370 +struct au_cp_generic {
6371 + struct dentry *dentry;
6372 + aufs_bindex_t bdst, bsrc;
6374 + struct au_pin *pin;
6375 + unsigned int flags;
6379 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6380 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6382 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6383 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6385 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6387 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6388 + the branch is marked as RO */
6390 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6391 +#undef AuCpup_HOPEN
6392 +#define AuCpup_HOPEN 0
6395 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6396 +#define au_fset_cpup(flags, name) \
6397 + do { (flags) |= AuCpup_##name; } while (0)
6398 +#define au_fclr_cpup(flags, name) \
6399 + do { (flags) &= ~AuCpup_##name; } while (0)
6401 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6402 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6403 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6404 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6406 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6407 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6408 + struct au_pin *pin,
6409 + struct dentry *h_parent, void *arg),
6411 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6412 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6414 +/* ---------------------------------------------------------------------- */
6416 +/* keep timestamps when copyup */
6418 + struct dentry *dt_dentry;
6419 + struct path dt_h_path;
6420 + struct timespec64 dt_atime, dt_mtime;
6422 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6423 + struct path *h_path);
6424 +void au_dtime_revert(struct au_dtime *dt);
6426 +#endif /* __KERNEL__ */
6427 +#endif /* __AUFS_CPUP_H__ */
6428 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6429 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6430 +++ linux/fs/aufs/dbgaufs.c 2020-01-27 10:57:18.168871450 +0100
6432 +// SPDX-License-Identifier: GPL-2.0
6434 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6436 + * This program, aufs is free software; you can redistribute it and/or modify
6437 + * it under the terms of the GNU General Public License as published by
6438 + * the Free Software Foundation; either version 2 of the License, or
6439 + * (at your option) any later version.
6441 + * This program is distributed in the hope that it will be useful,
6442 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6443 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6444 + * GNU General Public License for more details.
6446 + * You should have received a copy of the GNU General Public License
6447 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6451 + * debugfs interface
6454 +#include <linux/debugfs.h>
6457 +#ifndef CONFIG_SYSFS
6458 +#error DEBUG_FS depends upon SYSFS
6461 +static struct dentry *dbgaufs;
6462 +static const mode_t dbgaufs_mode = 0444;
6464 +/* 20 is max digits length of ulong 64 */
6465 +struct dbgaufs_arg {
6471 + * common function for all XINO files
6473 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6474 + struct file *file)
6478 + p = file->private_data;
6480 + /* this is struct dbgaufs_arg */
6481 + AuDebugOn(!au_kfree_sz_test(p));
6482 + au_kfree_do_rcu(p);
6487 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6492 + struct dbgaufs_arg *p;
6495 + p = kmalloc(sizeof(*p), GFP_NOFS);
6501 + file->private_data = p;
6505 + err = vfsub_getattr(&xf->f_path, &st);
6509 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6510 + cnt, st.blocks, st.blksize,
6511 + (long long)st.size);
6513 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6514 + st.blocks, st.blksize,
6515 + (long long)st.size);
6516 + AuDebugOn(p->n >= sizeof(p->a));
6518 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6526 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6527 + size_t count, loff_t *ppos)
6529 + struct dbgaufs_arg *p;
6531 + p = file->private_data;
6532 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6535 +/* ---------------------------------------------------------------------- */
6537 +struct dbgaufs_plink_arg {
6542 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6543 + struct file *file)
6545 + free_page((unsigned long)file->private_data);
6549 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6551 + int err, i, limit;
6552 + unsigned long n, sum;
6553 + struct dbgaufs_plink_arg *p;
6554 + struct au_sbinfo *sbinfo;
6555 + struct super_block *sb;
6556 + struct hlist_bl_head *hbl;
6559 + p = (void *)get_zeroed_page(GFP_NOFS);
6564 + sbinfo = inode->i_private;
6565 + sb = sbinfo->si_sb;
6566 + si_noflush_read_lock(sb);
6567 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6568 + limit = PAGE_SIZE - sizeof(p->n);
6570 + /* the number of buckets */
6571 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6576 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6578 + n = au_hbl_count(hbl);
6581 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6584 + if (unlikely(limit <= 0))
6587 + p->a[p->n - 1] = '\n';
6589 + /* the sum of plinks */
6590 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6593 + if (unlikely(limit <= 0))
6596 +#define str "1\n0\n0\n"
6597 + p->n = sizeof(str) - 1;
6598 + strcpy(p->a, str);
6601 + si_read_unlock(sb);
6604 + file->private_data = p;
6605 + goto out; /* success */
6608 + free_page((unsigned long)p);
6613 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6614 + size_t count, loff_t *ppos)
6616 + struct dbgaufs_plink_arg *p;
6618 + p = file->private_data;
6619 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6622 +static const struct file_operations dbgaufs_plink_fop = {
6623 + .owner = THIS_MODULE,
6624 + .open = dbgaufs_plink_open,
6625 + .release = dbgaufs_plink_release,
6626 + .read = dbgaufs_plink_read
6629 +/* ---------------------------------------------------------------------- */
6631 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6634 + struct au_sbinfo *sbinfo;
6635 + struct super_block *sb;
6637 + sbinfo = inode->i_private;
6638 + sb = sbinfo->si_sb;
6639 + si_noflush_read_lock(sb);
6640 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6641 + si_read_unlock(sb);
6645 +static const struct file_operations dbgaufs_xib_fop = {
6646 + .owner = THIS_MODULE,
6647 + .open = dbgaufs_xib_open,
6648 + .release = dbgaufs_xi_release,
6649 + .read = dbgaufs_xi_read
6652 +/* ---------------------------------------------------------------------- */
6654 +#define DbgaufsXi_PREFIX "xi"
6656 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6660 + aufs_bindex_t bindex;
6661 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6662 + struct au_sbinfo *sbinfo;
6663 + struct super_block *sb;
6664 + struct au_xino *xi;
6666 + struct qstr *name;
6667 + struct au_branch *br;
6670 + name = &file->f_path.dentry->d_name;
6671 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6672 + || memcmp(name->name, DbgaufsXi_PREFIX,
6673 + sizeof(DbgaufsXi_PREFIX) - 1)))
6676 + AuDebugOn(name->len >= sizeof(a));
6677 + memcpy(a, name->name, name->len);
6678 + a[name->len] = '\0';
6679 + p = strchr(a, '-');
6682 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6683 + if (unlikely(err))
6688 + err = kstrtol(p + 1, 10, &l);
6689 + if (unlikely(err))
6695 + sbinfo = inode->i_private;
6696 + sb = sbinfo->si_sb;
6697 + si_noflush_read_lock(sb);
6698 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6700 + br = au_sbr(sb, bindex);
6702 + if (unlikely(idx >= xi->xi_nfile))
6704 + xf = au_xino_file(xi, idx);
6706 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6707 + au_xino_count(br));
6710 + si_read_unlock(sb);
6716 +static const struct file_operations dbgaufs_xino_fop = {
6717 + .owner = THIS_MODULE,
6718 + .open = dbgaufs_xino_open,
6719 + .release = dbgaufs_xi_release,
6720 + .read = dbgaufs_xi_read
6723 +void dbgaufs_xino_del(struct au_branch *br)
6725 + struct dentry *dbgaufs;
6727 + dbgaufs = br->br_dbgaufs;
6731 + br->br_dbgaufs = NULL;
6732 + /* debugfs acquires the parent i_mutex */
6734 + debugfs_remove(dbgaufs);
6738 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6740 + aufs_bindex_t bbot;
6741 + struct au_branch *br;
6743 + if (!au_sbi(sb)->si_dbgaufs)
6746 + bbot = au_sbbot(sb);
6747 + for (; bindex <= bbot; bindex++) {
6748 + br = au_sbr(sb, bindex);
6749 + dbgaufs_xino_del(br);
6753 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6754 + unsigned int idx, struct dentry *parent,
6755 + struct au_sbinfo *sbinfo)
6757 + struct au_branch *br;
6759 + /* "xi" bindex(5) "-" idx(2) NULL */
6760 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6763 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6765 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6767 + br = au_sbr(sb, bindex);
6768 + if (br->br_dbgaufs) {
6769 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6771 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6772 + /* debugfs acquires the parent i_mutex */
6774 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6778 + pr_warn("failed renaming %pd/%s, ignored.\n",
6783 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6784 + sbinfo, &dbgaufs_xino_fop);
6786 + if (unlikely(!br->br_dbgaufs))
6787 + pr_warn("failed creating %pd/%s, ignored.\n",
6792 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6793 + struct dentry *parent, struct au_sbinfo *sbinfo)
6795 + struct au_branch *br;
6796 + struct au_xino *xi;
6799 + br = au_sbr(sb, bindex);
6801 + for (u = 0; u < xi->xi_nfile; u++)
6802 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6805 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6807 + struct au_sbinfo *sbinfo;
6808 + struct dentry *parent;
6809 + aufs_bindex_t bbot;
6811 + if (!au_opt_test(au_mntflags(sb), XINO))
6814 + sbinfo = au_sbi(sb);
6815 + parent = sbinfo->si_dbgaufs;
6819 + bbot = au_sbbot(sb);
6821 + for (; bindex <= bbot; bindex++)
6822 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6824 + for (; bbot >= bindex; bbot--)
6825 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6828 +/* ---------------------------------------------------------------------- */
6830 +#ifdef CONFIG_AUFS_EXPORT
6831 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6834 + struct au_sbinfo *sbinfo;
6835 + struct super_block *sb;
6837 + sbinfo = inode->i_private;
6838 + sb = sbinfo->si_sb;
6839 + si_noflush_read_lock(sb);
6840 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6841 + si_read_unlock(sb);
6845 +static const struct file_operations dbgaufs_xigen_fop = {
6846 + .owner = THIS_MODULE,
6847 + .open = dbgaufs_xigen_open,
6848 + .release = dbgaufs_xi_release,
6849 + .read = dbgaufs_xi_read
6852 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6857 + * This function is a dynamic '__init' function actually,
6858 + * so the tiny check for si_rwsem is unnecessary.
6860 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6863 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6864 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6865 + &dbgaufs_xigen_fop);
6866 + if (sbinfo->si_dbgaufs_xigen)
6872 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6876 +#endif /* CONFIG_AUFS_EXPORT */
6878 +/* ---------------------------------------------------------------------- */
6880 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6883 + * This function is a dynamic '__fin' function actually,
6884 + * so the tiny check for si_rwsem is unnecessary.
6886 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6888 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6889 + sbinfo->si_dbgaufs = NULL;
6892 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6895 + char name[SysaufsSiNameLen];
6898 + * This function is a dynamic '__init' function actually,
6899 + * so the tiny check for si_rwsem is unnecessary.
6901 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6905 + AuErr1("/debug/aufs is uninitialized\n");
6910 + sysaufs_name(sbinfo, name);
6911 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6912 + if (unlikely(!sbinfo->si_dbgaufs))
6915 + /* regardless plink/noplink option */
6916 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6917 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6918 + &dbgaufs_plink_fop);
6919 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6922 + /* regardless xino/noxino option */
6923 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6924 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6925 + &dbgaufs_xib_fop);
6926 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6929 + err = dbgaufs_xigen_init(sbinfo);
6931 + goto out; /* success */
6934 + dbgaufs_si_fin(sbinfo);
6936 + if (unlikely(err))
6937 + pr_err("debugfs/aufs failed\n");
6941 +/* ---------------------------------------------------------------------- */
6943 +void dbgaufs_fin(void)
6945 + debugfs_remove(dbgaufs);
6948 +int __init dbgaufs_init(void)
6953 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6958 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6959 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6960 +++ linux/fs/aufs/dbgaufs.h 2020-01-27 10:57:18.168871450 +0100
6962 +/* SPDX-License-Identifier: GPL-2.0 */
6964 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6966 + * This program, aufs is free software; you can redistribute it and/or modify
6967 + * it under the terms of the GNU General Public License as published by
6968 + * the Free Software Foundation; either version 2 of the License, or
6969 + * (at your option) any later version.
6971 + * This program is distributed in the hope that it will be useful,
6972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6974 + * GNU General Public License for more details.
6976 + * You should have received a copy of the GNU General Public License
6977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6981 + * debugfs interface
6984 +#ifndef __DBGAUFS_H__
6985 +#define __DBGAUFS_H__
6989 +struct super_block;
6993 +#ifdef CONFIG_DEBUG_FS
6995 +void dbgaufs_xino_del(struct au_branch *br);
6996 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6997 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6998 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6999 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7000 +void dbgaufs_fin(void);
7001 +int __init dbgaufs_init(void);
7003 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7004 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7005 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7007 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7008 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7009 +AuStubVoid(dbgaufs_fin, void)
7010 +AuStubInt0(__init dbgaufs_init, void)
7011 +#endif /* CONFIG_DEBUG_FS */
7013 +#endif /* __KERNEL__ */
7014 +#endif /* __DBGAUFS_H__ */
7015 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7016 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7017 +++ linux/fs/aufs/dcsub.c 2020-01-27 10:57:18.168871450 +0100
7019 +// SPDX-License-Identifier: GPL-2.0
7021 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7023 + * This program, aufs is free software; you can redistribute it and/or modify
7024 + * it under the terms of the GNU General Public License as published by
7025 + * the Free Software Foundation; either version 2 of the License, or
7026 + * (at your option) any later version.
7028 + * This program is distributed in the hope that it will be useful,
7029 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7030 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7031 + * GNU General Public License for more details.
7033 + * You should have received a copy of the GNU General Public License
7034 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7038 + * sub-routines for dentry cache
7043 +static void au_dpage_free(struct au_dpage *dpage)
7046 + struct dentry **p;
7048 + p = dpage->dentries;
7049 + for (i = 0; i < dpage->ndentry; i++)
7051 + free_page((unsigned long)dpage->dentries);
7054 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7060 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7061 + if (unlikely(!dpages->dpages))
7064 + p = (void *)__get_free_page(gfp);
7068 + dpages->dpages[0].ndentry = 0;
7069 + dpages->dpages[0].dentries = p;
7070 + dpages->ndpage = 1;
7071 + return 0; /* success */
7074 + au_kfree_try_rcu(dpages->dpages);
7079 +void au_dpages_free(struct au_dcsub_pages *dpages)
7082 + struct au_dpage *p;
7084 + p = dpages->dpages;
7085 + for (i = 0; i < dpages->ndpage; i++)
7086 + au_dpage_free(p++);
7087 + au_kfree_try_rcu(dpages->dpages);
7090 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7091 + struct dentry *dentry, gfp_t gfp)
7094 + struct au_dpage *dpage;
7097 + dpage = dpages->dpages + dpages->ndpage - 1;
7098 + sz = PAGE_SIZE / sizeof(dentry);
7099 + if (unlikely(dpage->ndentry >= sz)) {
7100 + AuLabel(new dpage);
7102 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7103 + p = au_kzrealloc(dpages->dpages, sz,
7104 + sz + sizeof(*dpages->dpages), gfp,
7109 + dpages->dpages = p;
7110 + dpage = dpages->dpages + dpages->ndpage;
7111 + p = (void *)__get_free_page(gfp);
7115 + dpage->ndentry = 0;
7116 + dpage->dentries = p;
7120 + AuDebugOn(au_dcount(dentry) <= 0);
7121 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7122 + return 0; /* success */
7128 +/* todo: BAD approach */
7129 +/* copied from linux/fs/dcache.c */
7137 +extern void d_walk(struct dentry *parent, void *data,
7138 + enum d_walk_ret (*enter)(void *, struct dentry *));
7140 +struct ac_dpages_arg {
7142 + struct au_dcsub_pages *dpages;
7143 + struct super_block *sb;
7144 + au_dpages_test test;
7148 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7150 + enum d_walk_ret ret;
7151 + struct ac_dpages_arg *arg = _arg;
7153 + ret = D_WALK_CONTINUE;
7154 + if (dentry->d_sb == arg->sb
7155 + && !IS_ROOT(dentry)
7156 + && au_dcount(dentry) > 0
7158 + && (!arg->test || arg->test(dentry, arg->arg))) {
7159 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7160 + if (unlikely(arg->err))
7161 + ret = D_WALK_QUIT;
7167 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7168 + au_dpages_test test, void *arg)
7170 + struct ac_dpages_arg args = {
7178 + d_walk(root, &args, au_call_dpages_append);
7183 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7184 + int do_include, au_dpages_test test, void *arg)
7189 + write_seqlock(&rename_lock);
7190 + spin_lock(&dentry->d_lock);
7192 + && au_dcount(dentry) > 0
7193 + && (!test || test(dentry, arg)))
7194 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7195 + spin_unlock(&dentry->d_lock);
7196 + if (unlikely(err))
7200 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7203 + while (!IS_ROOT(dentry)) {
7204 + dentry = dentry->d_parent; /* rename_lock is locked */
7205 + spin_lock(&dentry->d_lock);
7206 + if (au_dcount(dentry) > 0
7207 + && (!test || test(dentry, arg)))
7208 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7209 + spin_unlock(&dentry->d_lock);
7210 + if (unlikely(err))
7215 + write_sequnlock(&rename_lock);
7219 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7221 + return au_di(dentry) && dentry->d_sb == arg;
7224 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7225 + struct dentry *dentry, int do_include)
7227 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7228 + au_dcsub_dpages_aufs, dentry->d_sb);
7231 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7233 + struct path path[2] = {
7242 + return path_is_under(path + 0, path + 1);
7244 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7245 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7246 +++ linux/fs/aufs/dcsub.h 2020-01-27 10:57:18.168871450 +0100
7248 +/* SPDX-License-Identifier: GPL-2.0 */
7250 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7252 + * This program, aufs is free software; you can redistribute it and/or modify
7253 + * it under the terms of the GNU General Public License as published by
7254 + * the Free Software Foundation; either version 2 of the License, or
7255 + * (at your option) any later version.
7257 + * This program is distributed in the hope that it will be useful,
7258 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7259 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7260 + * GNU General Public License for more details.
7262 + * You should have received a copy of the GNU General Public License
7263 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7267 + * sub-routines for dentry cache
7270 +#ifndef __AUFS_DCSUB_H__
7271 +#define __AUFS_DCSUB_H__
7275 +#include <linux/dcache.h>
7276 +#include <linux/fs.h>
7280 + struct dentry **dentries;
7283 +struct au_dcsub_pages {
7285 + struct au_dpage *dpages;
7288 +/* ---------------------------------------------------------------------- */
7291 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7292 +void au_dpages_free(struct au_dcsub_pages *dpages);
7293 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7294 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7295 + au_dpages_test test, void *arg);
7296 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7297 + int do_include, au_dpages_test test, void *arg);
7298 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7299 + struct dentry *dentry, int do_include);
7300 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7302 +/* ---------------------------------------------------------------------- */
7305 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7306 + * include/linux/dcache.h. Try them (in the future).
7309 +static inline int au_d_hashed_positive(struct dentry *d)
7312 + struct inode *inode = d_inode(d);
7315 + if (unlikely(d_unhashed(d)
7316 + || d_is_negative(d)
7317 + || !inode->i_nlink))
7322 +static inline int au_d_linkable(struct dentry *d)
7325 + struct inode *inode = d_inode(d);
7327 + err = au_d_hashed_positive(d);
7329 + && d_is_positive(d)
7330 + && (inode->i_state & I_LINKABLE))
7335 +static inline int au_d_alive(struct dentry *d)
7338 + struct inode *inode;
7342 + err = au_d_hashed_positive(d);
7344 + inode = d_inode(d);
7345 + if (unlikely(d_unlinked(d)
7346 + || d_is_negative(d)
7347 + || !inode->i_nlink))
7353 +static inline int au_alive_dir(struct dentry *d)
7357 + err = au_d_alive(d);
7358 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7363 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7365 + return a->len == b->len
7366 + && !memcmp(a->name, b->name, a->len);
7371 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7373 + * the type of d_lockref.count became int, but the inlined function d_count()
7374 + * still returns unsigned int.
7375 + * I don't know why. Maybe it is for every d_count() users?
7376 + * Anyway au_dcount() lives on.
7378 +static inline int au_dcount(struct dentry *d)
7380 + return (int)d_count(d);
7383 +#endif /* __KERNEL__ */
7384 +#endif /* __AUFS_DCSUB_H__ */
7385 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7386 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7387 +++ linux/fs/aufs/debug.c 2020-01-27 10:57:18.168871450 +0100
7389 +// SPDX-License-Identifier: GPL-2.0
7391 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7393 + * This program, aufs is free software; you can redistribute it and/or modify
7394 + * it under the terms of the GNU General Public License as published by
7395 + * the Free Software Foundation; either version 2 of the License, or
7396 + * (at your option) any later version.
7398 + * This program is distributed in the hope that it will be useful,
7399 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7400 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7401 + * GNU General Public License for more details.
7403 + * You should have received a copy of the GNU General Public License
7404 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7408 + * debug print functions
7411 +#include <linux/iversion.h>
7414 +/* Returns 0, or -errno. arg is in kp->arg. */
7415 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7419 + err = kstrtoint(val, 0, &n);
7429 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7430 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7435 + return sprintf(buffer, "%d", atomic_read(a));
7438 +static struct kernel_param_ops param_ops_atomic_t = {
7439 + .set = param_atomic_t_set,
7440 + .get = param_atomic_t_get
7441 + /* void (*free)(void *arg) */
7444 +atomic_t aufs_debug = ATOMIC_INIT(0);
7445 +MODULE_PARM_DESC(debug, "debug print");
7446 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7448 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7449 +char *au_plevel = KERN_DEBUG;
7450 +#define dpri(fmt, ...) do { \
7452 + && strcmp(au_plevel, KERN_DEBUG)) \
7453 + || au_debug_test()) \
7454 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7457 +/* ---------------------------------------------------------------------- */
7459 +void au_dpri_whlist(struct au_nhash *whlist)
7461 + unsigned long ul, n;
7462 + struct hlist_head *head;
7463 + struct au_vdir_wh *pos;
7465 + n = whlist->nh_num;
7466 + head = whlist->nh_head;
7467 + for (ul = 0; ul < n; ul++) {
7468 + hlist_for_each_entry(pos, head, wh_hash)
7469 + dpri("b%d, %.*s, %d\n",
7471 + pos->wh_str.len, pos->wh_str.name,
7477 +void au_dpri_vdir(struct au_vdir *vdir)
7480 + union au_vdir_deblk_p p;
7483 + if (!vdir || IS_ERR(vdir)) {
7484 + dpri("err %ld\n", PTR_ERR(vdir));
7488 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7489 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7490 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7491 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7492 + p.deblk = vdir->vd_deblk[ul];
7494 + dpri("[%lu]: %p\n", ul, o);
7498 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7499 + struct dentry *wh)
7504 + if (!inode || IS_ERR(inode)) {
7505 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7509 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7510 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7511 + && sizeof(inode->i_blocks) != sizeof(u64));
7513 + n = (void *)wh->d_name.name;
7514 + l = wh->d_name.len;
7517 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7518 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7520 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7521 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7522 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7523 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7524 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7525 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7526 + inode->i_generation,
7527 + l ? ", wh " : "", l, n);
7531 +void au_dpri_inode(struct inode *inode)
7533 + struct au_iinfo *iinfo;
7534 + struct au_hinode *hi;
7535 + aufs_bindex_t bindex;
7538 + err = do_pri_inode(-1, inode, -1, NULL);
7539 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7542 + iinfo = au_ii(inode);
7543 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7544 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7545 + if (iinfo->ii_btop < 0)
7548 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7549 + hi = au_hinode(iinfo, bindex);
7551 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7555 +void au_dpri_dalias(struct inode *inode)
7559 + spin_lock(&inode->i_lock);
7560 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7561 + au_dpri_dentry(d);
7562 + spin_unlock(&inode->i_lock);
7565 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7567 + struct dentry *wh = NULL;
7569 + struct inode *inode;
7570 + struct au_iinfo *iinfo;
7571 + struct au_hinode *hi;
7573 + if (!dentry || IS_ERR(dentry)) {
7574 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7577 + /* do not call dget_parent() here */
7578 + /* note: access d_xxx without d_lock */
7579 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7580 + bindex, dentry, dentry,
7581 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7582 + au_dcount(dentry), dentry->d_flags,
7583 + d_unhashed(dentry) ? "un" : "");
7586 + if (d_is_positive(dentry))
7587 + inode = d_inode(dentry);
7589 + && au_test_aufs(dentry->d_sb)
7591 + && !au_is_bad_inode(inode)) {
7592 + iinfo = au_ii(inode);
7593 + hi = au_hinode(iinfo, bindex);
7595 + wh = hi->hi_whdentry;
7597 + do_pri_inode(bindex, inode, hn, wh);
7601 +void au_dpri_dentry(struct dentry *dentry)
7603 + struct au_dinfo *dinfo;
7604 + aufs_bindex_t bindex;
7607 + err = do_pri_dentry(-1, dentry);
7608 + if (err || !au_test_aufs(dentry->d_sb))
7611 + dinfo = au_di(dentry);
7614 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7615 + dinfo->di_btop, dinfo->di_bbot,
7616 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7617 + dinfo->di_tmpfile);
7618 + if (dinfo->di_btop < 0)
7620 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7621 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7624 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7628 + if (!file || IS_ERR(file)) {
7629 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7634 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7635 + && au_test_aufs(file->f_path.dentry->d_sb)
7637 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7638 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7639 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7640 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7641 + file->f_version, file->f_pos, a);
7642 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7643 + do_pri_dentry(bindex, file->f_path.dentry);
7647 +void au_dpri_file(struct file *file)
7649 + struct au_finfo *finfo;
7650 + struct au_fidir *fidir;
7651 + struct au_hfile *hfile;
7652 + aufs_bindex_t bindex;
7655 + err = do_pri_file(-1, file);
7657 + || IS_ERR_OR_NULL(file->f_path.dentry)
7658 + || !au_test_aufs(file->f_path.dentry->d_sb))
7661 + finfo = au_fi(file);
7664 + if (finfo->fi_btop < 0)
7666 + fidir = finfo->fi_hdir;
7668 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7670 + for (bindex = finfo->fi_btop;
7671 + bindex >= 0 && bindex <= fidir->fd_bbot;
7673 + hfile = fidir->fd_hfile + bindex;
7674 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7678 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7680 + struct vfsmount *mnt;
7681 + struct super_block *sb;
7683 + if (!br || IS_ERR(br))
7685 + mnt = au_br_mnt(br);
7686 + if (!mnt || IS_ERR(mnt))
7689 + if (!sb || IS_ERR(sb))
7692 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7693 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7695 + bindex, br->br_perm, br->br_id, br->br_wbr,
7696 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7697 + sb->s_flags, sb->s_count,
7698 + atomic_read(&sb->s_active),
7699 + !!au_xino_file(br->br_xino, /*idx*/-1));
7703 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7707 +void au_dpri_sb(struct super_block *sb)
7709 + struct au_sbinfo *sbinfo;
7710 + aufs_bindex_t bindex;
7712 + /* to reduce stack size */
7714 + struct vfsmount mnt;
7715 + struct au_branch fake;
7718 + /* this function can be called from magic sysrq */
7719 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7720 + if (unlikely(!a)) {
7721 + dpri("no memory\n");
7725 + a->mnt.mnt_sb = sb;
7726 + a->fake.br_path.mnt = &a->mnt;
7727 + err = do_pri_br(-1, &a->fake);
7729 + dpri("dev 0x%x\n", sb->s_dev);
7730 + if (err || !au_test_aufs(sb))
7733 + sbinfo = au_sbi(sb);
7736 + dpri("nw %d, gen %u, kobj %d\n",
7737 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7738 + kref_read(&sbinfo->si_kobj.kref));
7739 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7740 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7743 +/* ---------------------------------------------------------------------- */
7745 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7747 + struct inode *h_inode, *inode = d_inode(dentry);
7748 + struct dentry *h_dentry;
7749 + aufs_bindex_t bindex, bbot, bi;
7751 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7754 + bbot = au_dbbot(dentry);
7755 + bi = au_ibbot(inode);
7758 + bindex = au_dbtop(dentry);
7759 + bi = au_ibtop(inode);
7763 + for (; bindex <= bbot; bindex++) {
7764 + h_dentry = au_h_dptr(dentry, bindex);
7767 + h_inode = au_h_iptr(inode, bindex);
7768 + if (unlikely(h_inode != d_inode(h_dentry))) {
7770 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7771 + AuDbgDentry(dentry);
7772 + AuDbgInode(inode);
7779 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7782 + struct au_dcsub_pages dpages;
7783 + struct au_dpage *dpage;
7784 + struct dentry **dentries;
7786 + err = au_dpages_init(&dpages, GFP_NOFS);
7788 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7790 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7791 + dpage = dpages.dpages + i;
7792 + dentries = dpage->dentries;
7793 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7794 + AuDebugOn(au_digen_test(dentries[j], sigen));
7796 + au_dpages_free(&dpages);
7799 +void au_dbg_verify_kthread(void)
7801 + if (au_wkq_test()) {
7804 + * It may be recursive, but udba=notify between two aufs mounts,
7805 + * where a single ro branch is shared, is not a problem.
7811 +/* ---------------------------------------------------------------------- */
7813 +int __init au_debug_init(void)
7815 + aufs_bindex_t bindex;
7816 + struct au_vdir_destr destr;
7819 + AuDebugOn(bindex >= 0);
7822 + AuDebugOn(destr.len < NAME_MAX);
7824 +#ifdef CONFIG_4KSTACKS
7825 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7830 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7831 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7832 +++ linux/fs/aufs/debug.h 2020-01-27 10:57:18.168871450 +0100
7834 +/* SPDX-License-Identifier: GPL-2.0 */
7836 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7838 + * This program, aufs is free software; you can redistribute it and/or modify
7839 + * it under the terms of the GNU General Public License as published by
7840 + * the Free Software Foundation; either version 2 of the License, or
7841 + * (at your option) any later version.
7843 + * This program is distributed in the hope that it will be useful,
7844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7846 + * GNU General Public License for more details.
7848 + * You should have received a copy of the GNU General Public License
7849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7853 + * debug print functions
7856 +#ifndef __AUFS_DEBUG_H__
7857 +#define __AUFS_DEBUG_H__
7861 +#include <linux/atomic.h>
7862 +#include <linux/module.h>
7863 +#include <linux/kallsyms.h>
7864 +#include <linux/sysrq.h>
7866 +#ifdef CONFIG_AUFS_DEBUG
7867 +#define AuDebugOn(a) BUG_ON(a)
7869 +/* module parameter */
7870 +extern atomic_t aufs_debug;
7871 +static inline void au_debug_on(void)
7873 + atomic_inc(&aufs_debug);
7875 +static inline void au_debug_off(void)
7877 + atomic_dec_if_positive(&aufs_debug);
7880 +static inline int au_debug_test(void)
7882 + return atomic_read(&aufs_debug) > 0;
7885 +#define AuDebugOn(a) do {} while (0)
7886 +AuStubVoid(au_debug_on, void)
7887 +AuStubVoid(au_debug_off, void)
7888 +AuStubInt0(au_debug_test, void)
7889 +#endif /* CONFIG_AUFS_DEBUG */
7891 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7893 +/* ---------------------------------------------------------------------- */
7897 +#define AuDbg(fmt, ...) do { \
7898 + if (au_debug_test()) \
7899 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7901 +#define AuLabel(l) AuDbg(#l "\n")
7902 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7903 +#define AuWarn1(fmt, ...) do { \
7904 + static unsigned char _c; \
7906 + pr_warn(fmt, ##__VA_ARGS__); \
7909 +#define AuErr1(fmt, ...) do { \
7910 + static unsigned char _c; \
7912 + pr_err(fmt, ##__VA_ARGS__); \
7915 +#define AuIOErr1(fmt, ...) do { \
7916 + static unsigned char _c; \
7918 + AuIOErr(fmt, ##__VA_ARGS__); \
7921 +#define AuUnsupportMsg "This operation is not supported." \
7922 + " Please report this application to aufs-users ML."
7923 +#define AuUnsupport(fmt, ...) do { \
7924 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7928 +#define AuTraceErr(e) do { \
7929 + if (unlikely((e) < 0)) \
7930 + AuDbg("err %d\n", (int)(e)); \
7933 +#define AuTraceErrPtr(p) do { \
7935 + AuDbg("err %ld\n", PTR_ERR(p)); \
7938 +/* dirty macros for debug print, use with "%.*s" and caution */
7939 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7941 +/* ---------------------------------------------------------------------- */
7944 +#ifdef CONFIG_AUFS_DEBUG
7945 +extern struct mutex au_dbg_mtx;
7946 +extern char *au_plevel;
7948 +void au_dpri_whlist(struct au_nhash *whlist);
7950 +void au_dpri_vdir(struct au_vdir *vdir);
7952 +void au_dpri_inode(struct inode *inode);
7953 +void au_dpri_dalias(struct inode *inode);
7954 +void au_dpri_dentry(struct dentry *dentry);
7956 +void au_dpri_file(struct file *filp);
7957 +struct super_block;
7958 +void au_dpri_sb(struct super_block *sb);
7960 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7961 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7962 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7963 +void au_dbg_verify_kthread(void);
7965 +int __init au_debug_init(void);
7967 +#define AuDbgWhlist(w) do { \
7968 + mutex_lock(&au_dbg_mtx); \
7970 + au_dpri_whlist(w); \
7971 + mutex_unlock(&au_dbg_mtx); \
7974 +#define AuDbgVdir(v) do { \
7975 + mutex_lock(&au_dbg_mtx); \
7977 + au_dpri_vdir(v); \
7978 + mutex_unlock(&au_dbg_mtx); \
7981 +#define AuDbgInode(i) do { \
7982 + mutex_lock(&au_dbg_mtx); \
7984 + au_dpri_inode(i); \
7985 + mutex_unlock(&au_dbg_mtx); \
7988 +#define AuDbgDAlias(i) do { \
7989 + mutex_lock(&au_dbg_mtx); \
7991 + au_dpri_dalias(i); \
7992 + mutex_unlock(&au_dbg_mtx); \
7995 +#define AuDbgDentry(d) do { \
7996 + mutex_lock(&au_dbg_mtx); \
7998 + au_dpri_dentry(d); \
7999 + mutex_unlock(&au_dbg_mtx); \
8002 +#define AuDbgFile(f) do { \
8003 + mutex_lock(&au_dbg_mtx); \
8005 + au_dpri_file(f); \
8006 + mutex_unlock(&au_dbg_mtx); \
8009 +#define AuDbgSb(sb) do { \
8010 + mutex_lock(&au_dbg_mtx); \
8011 + AuDbg(#sb "\n"); \
8013 + mutex_unlock(&au_dbg_mtx); \
8016 +#define AuDbgSym(addr) do { \
8017 + char sym[KSYM_SYMBOL_LEN]; \
8018 + sprint_symbol(sym, (unsigned long)addr); \
8019 + AuDbg("%s\n", sym); \
8022 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8023 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8024 +AuStubVoid(au_dbg_verify_kthread, void)
8025 +AuStubInt0(__init au_debug_init, void)
8027 +#define AuDbgWhlist(w) do {} while (0)
8028 +#define AuDbgVdir(v) do {} while (0)
8029 +#define AuDbgInode(i) do {} while (0)
8030 +#define AuDbgDAlias(i) do {} while (0)
8031 +#define AuDbgDentry(d) do {} while (0)
8032 +#define AuDbgFile(f) do {} while (0)
8033 +#define AuDbgSb(sb) do {} while (0)
8034 +#define AuDbgSym(addr) do {} while (0)
8035 +#endif /* CONFIG_AUFS_DEBUG */
8037 +/* ---------------------------------------------------------------------- */
8039 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8040 +int __init au_sysrq_init(void);
8041 +void au_sysrq_fin(void);
8043 +#ifdef CONFIG_HW_CONSOLE
8044 +#define au_dbg_blocked() do { \
8046 + handle_sysrq('w'); \
8049 +AuStubVoid(au_dbg_blocked, void)
8053 +AuStubInt0(__init au_sysrq_init, void)
8054 +AuStubVoid(au_sysrq_fin, void)
8055 +AuStubVoid(au_dbg_blocked, void)
8056 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8058 +#endif /* __KERNEL__ */
8059 +#endif /* __AUFS_DEBUG_H__ */
8060 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8061 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8062 +++ linux/fs/aufs/dentry.c 2020-01-27 10:57:18.168871450 +0100
8064 +// SPDX-License-Identifier: GPL-2.0
8066 + * Copyright (C) 2005-2020 Junjiro R. Okajima
8068 + * This program, aufs is free software; you can redistribute it and/or modify
8069 + * it under the terms of the GNU General Public License as published by
8070 + * the Free Software Foundation; either version 2 of the License, or
8071 + * (at your option) any later version.
8073 + * This program is distributed in the hope that it will be useful,
8074 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8075 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8076 + * GNU General Public License for more details.
8078 + * You should have received a copy of the GNU General Public License
8079 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8083 + * lookup and dentry operations
8086 +#include <linux/iversion.h>
8087 +#include <linux/namei.h>
8091 + * returns positive/negative dentry, NULL or an error.
8092 + * NULL means whiteout-ed or not-found.
8094 +static struct dentry*
8095 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8096 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8098 + struct dentry *h_dentry;
8099 + struct inode *h_inode;
8100 + struct au_branch *br;
8101 + int wh_found, opq;
8102 + unsigned char wh_able;
8103 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8104 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8108 + br = au_sbr(dentry->d_sb, bindex);
8109 + wh_able = !!au_br_whable(br->br_perm);
8111 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8112 + h_dentry = ERR_PTR(wh_found);
8115 + if (unlikely(wh_found < 0))
8118 + /* We found a whiteout */
8119 + /* au_set_dbbot(dentry, bindex); */
8120 + au_set_dbwh(dentry, bindex);
8122 + return NULL; /* success */
8126 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8128 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8129 + if (IS_ERR(h_dentry)) {
8130 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8136 + h_inode = d_inode(h_dentry);
8137 + if (d_is_negative(h_dentry)) {
8140 + } else if (wh_found
8141 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8143 + else if (au_ftest_lkup(args->flags, DIRREN)
8145 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8146 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8147 + (unsigned long long)h_inode->i_ino);
8151 + if (au_dbbot(dentry) <= bindex)
8152 + au_set_dbbot(dentry, bindex);
8153 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8154 + au_set_dbtop(dentry, bindex);
8155 + au_set_h_dptr(dentry, bindex, h_dentry);
8157 + if (!d_is_dir(h_dentry)
8159 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8160 + goto out; /* success */
8162 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8163 + opq = au_diropq_test(h_dentry);
8164 + inode_unlock_shared(h_inode);
8166 + au_set_dbdiropq(dentry, bindex);
8167 + else if (unlikely(opq < 0)) {
8168 + au_set_h_dptr(dentry, bindex, NULL);
8169 + h_dentry = ERR_PTR(opq);
8180 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8182 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8183 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8189 + * returns the number of lower positive dentries,
8190 + * otherwise an error.
8191 + * can be called at unlinking with @type is zero.
8193 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8194 + unsigned int flags)
8196 + int npositive, err;
8197 + aufs_bindex_t bindex, btail, bdiropq;
8198 + unsigned char isdir, dirperm1, dirren;
8199 + struct au_do_lookup_args args = {
8201 + .name = &dentry->d_name
8203 + struct dentry *parent;
8204 + struct super_block *sb;
8206 + sb = dentry->d_sb;
8207 + err = au_test_shwh(sb, args.name);
8208 + if (unlikely(err))
8211 + err = au_wh_name_alloc(&args.whname, args.name);
8212 + if (unlikely(err))
8215 + isdir = !!d_is_dir(dentry);
8216 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8217 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8219 + au_fset_lkup(args.flags, DIRREN);
8222 + parent = dget_parent(dentry);
8223 + btail = au_dbtaildir(parent);
8224 + for (bindex = btop; bindex <= btail; bindex++) {
8225 + struct dentry *h_parent, *h_dentry;
8226 + struct inode *h_inode, *h_dir;
8227 + struct au_branch *br;
8229 + h_dentry = au_h_dptr(dentry, bindex);
8231 + if (d_is_positive(h_dentry))
8235 + h_parent = au_h_dptr(parent, bindex);
8236 + if (!h_parent || !d_is_dir(h_parent))
8240 + /* if the inum matches, then use the prepared name */
8241 + err = au_dr_lkup_name(&args, bindex);
8242 + if (unlikely(err))
8246 + h_dir = d_inode(h_parent);
8247 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8248 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8249 + inode_unlock_shared(h_dir);
8250 + err = PTR_ERR(h_dentry);
8251 + if (IS_ERR(h_dentry))
8254 + au_fclr_lkup(args.flags, ALLOW_NEG);
8256 + au_fset_lkup(args.flags, IGNORE_PERM);
8258 + if (au_dbwh(dentry) == bindex)
8262 + if (d_is_negative(h_dentry))
8264 + h_inode = d_inode(h_dentry);
8267 + args.type = h_inode->i_mode & S_IFMT;
8268 + if (args.type != S_IFDIR)
8271 + /* the type of lower may be different */
8272 + bdiropq = au_dbdiropq(dentry);
8273 + if (bdiropq >= 0 && bdiropq <= bindex)
8276 + br = au_sbr(sb, bindex);
8278 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8279 + /*add_ent*/NULL)) {
8280 + /* prepare next name to lookup */
8281 + err = au_dr_lkup(&args, dentry, bindex);
8282 + if (unlikely(err))
8288 + AuLabel(positive);
8289 + au_update_dbtop(dentry);
8292 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8293 + && au_dbtop(dentry) < 0)) {
8295 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8301 + au_kfree_try_rcu(args.whname.name);
8303 + au_dr_lkup_fin(&args);
8308 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8310 + struct dentry *dentry;
8313 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8314 + dentry = vfsub_lkup_one(name, parent);
8316 + struct vfsub_lkup_one_args args = {
8322 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8323 + if (unlikely(wkq_err))
8324 + dentry = ERR_PTR(wkq_err);
8331 + * lookup @dentry on @bindex which should be negative.
8333 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8336 + struct dentry *parent, *h_parent, *h_dentry;
8337 + struct au_branch *br;
8339 + parent = dget_parent(dentry);
8340 + h_parent = au_h_dptr(parent, bindex);
8341 + br = au_sbr(dentry->d_sb, bindex);
8343 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8345 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8346 + err = PTR_ERR(h_dentry);
8347 + if (IS_ERR(h_dentry))
8349 + if (unlikely(d_is_positive(h_dentry))) {
8351 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8357 + if (bindex < au_dbtop(dentry))
8358 + au_set_dbtop(dentry, bindex);
8359 + if (au_dbbot(dentry) < bindex)
8360 + au_set_dbbot(dentry, bindex);
8361 + au_set_h_dptr(dentry, bindex, h_dentry);
8368 +/* ---------------------------------------------------------------------- */
8370 +/* subset of struct inode */
8372 + unsigned long i_ino;
8373 + /* unsigned int i_nlink; */
8379 + blkcnt_t i_blocks;
8384 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8386 + ia->i_ino = h_inode->i_ino;
8387 + /* ia->i_nlink = h_inode->i_nlink; */
8388 + ia->i_uid = h_inode->i_uid;
8389 + ia->i_gid = h_inode->i_gid;
8390 + ia->i_version = inode_query_iversion(h_inode);
8392 + ia->i_size = h_inode->i_size;
8393 + ia->i_blocks = h_inode->i_blocks;
8395 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8398 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8400 + return ia->i_ino != h_inode->i_ino
8401 + /* || ia->i_nlink != h_inode->i_nlink */
8402 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8403 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8404 + || !inode_eq_iversion(h_inode, ia->i_version)
8406 + || ia->i_size != h_inode->i_size
8407 + || ia->i_blocks != h_inode->i_blocks
8409 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8412 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8413 + struct au_branch *br)
8416 + struct au_iattr ia;
8417 + struct inode *h_inode;
8418 + struct dentry *h_d;
8419 + struct super_block *h_sb;
8422 + memset(&ia, -1, sizeof(ia));
8423 + h_sb = h_dentry->d_sb;
8425 + if (d_is_positive(h_dentry)) {
8426 + h_inode = d_inode(h_dentry);
8427 + au_iattr_save(&ia, h_inode);
8428 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8429 + /* nfs d_revalidate may return 0 for negative dentry */
8430 + /* fuse d_revalidate always return 0 for negative dentry */
8433 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8434 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8435 + err = PTR_ERR(h_d);
8440 + if (unlikely(h_d != h_dentry
8441 + || d_inode(h_d) != h_inode
8442 + || (h_inode && au_iattr_test(&ia, h_inode))))
8443 + err = au_busy_or_stale();
8451 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8452 + struct dentry *h_parent, struct au_branch *br)
8457 + if (udba == AuOpt_UDBA_REVAL
8458 + && !au_test_fs_remote(h_dentry->d_sb)) {
8460 + err = (d_inode(h_dentry->d_parent) != h_dir);
8461 + } else if (udba != AuOpt_UDBA_NONE)
8462 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8467 +/* ---------------------------------------------------------------------- */
8469 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8472 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8473 + struct au_hdentry tmp, *p, *q;
8474 + struct au_dinfo *dinfo;
8475 + struct super_block *sb;
8477 + DiMustWriteLock(dentry);
8479 + sb = dentry->d_sb;
8480 + dinfo = au_di(dentry);
8481 + bbot = dinfo->di_bbot;
8482 + bwh = dinfo->di_bwh;
8483 + bdiropq = dinfo->di_bdiropq;
8484 + bindex = dinfo->di_btop;
8485 + p = au_hdentry(dinfo, bindex);
8486 + for (; bindex <= bbot; bindex++, p++) {
8487 + if (!p->hd_dentry)
8490 + new_bindex = au_br_index(sb, p->hd_id);
8491 + if (new_bindex == bindex)
8494 + if (dinfo->di_bwh == bindex)
8496 + if (dinfo->di_bdiropq == bindex)
8497 + bdiropq = new_bindex;
8498 + if (new_bindex < 0) {
8500 + p->hd_dentry = NULL;
8504 + /* swap two lower dentries, and loop again */
8505 + q = au_hdentry(dinfo, new_bindex);
8509 + if (tmp.hd_dentry) {
8515 + dinfo->di_bwh = -1;
8516 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8517 + dinfo->di_bwh = bwh;
8519 + dinfo->di_bdiropq = -1;
8521 + && bdiropq <= au_sbbot(sb)
8522 + && au_sbr_whable(sb, bdiropq))
8523 + dinfo->di_bdiropq = bdiropq;
8526 + dinfo->di_btop = -1;
8527 + dinfo->di_bbot = -1;
8528 + bbot = au_dbbot(parent);
8530 + p = au_hdentry(dinfo, bindex);
8531 + for (; bindex <= bbot; bindex++, p++)
8532 + if (p->hd_dentry) {
8533 + dinfo->di_btop = bindex;
8537 + if (dinfo->di_btop >= 0) {
8539 + p = au_hdentry(dinfo, bindex);
8540 + for (; bindex >= 0; bindex--, p--)
8541 + if (p->hd_dentry) {
8542 + dinfo->di_bbot = bindex;
8551 +static void au_do_hide(struct dentry *dentry)
8553 + struct inode *inode;
8555 + if (d_really_is_positive(dentry)) {
8556 + inode = d_inode(dentry);
8557 + if (!d_is_dir(dentry)) {
8558 + if (inode->i_nlink && !d_unhashed(dentry))
8559 + drop_nlink(inode);
8561 + clear_nlink(inode);
8562 + /* stop next lookup */
8563 + inode->i_flags |= S_DEAD;
8565 + smp_mb(); /* necessary? */
8570 +static int au_hide_children(struct dentry *parent)
8572 + int err, i, j, ndentry;
8573 + struct au_dcsub_pages dpages;
8574 + struct au_dpage *dpage;
8575 + struct dentry *dentry;
8577 + err = au_dpages_init(&dpages, GFP_NOFS);
8578 + if (unlikely(err))
8580 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8581 + if (unlikely(err))
8584 + /* in reverse order */
8585 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8586 + dpage = dpages.dpages + i;
8587 + ndentry = dpage->ndentry;
8588 + for (j = ndentry - 1; j >= 0; j--) {
8589 + dentry = dpage->dentries[j];
8590 + if (dentry != parent)
8591 + au_do_hide(dentry);
8596 + au_dpages_free(&dpages);
8601 +static void au_hide(struct dentry *dentry)
8605 + AuDbgDentry(dentry);
8606 + if (d_is_dir(dentry)) {
8607 + /* shrink_dcache_parent(dentry); */
8608 + err = au_hide_children(dentry);
8609 + if (unlikely(err))
8610 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8613 + au_do_hide(dentry);
8617 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8619 + * a dirty branch is added
8620 + * - on the top of layers
8621 + * - in the middle of layers
8622 + * - to the bottom of layers
8624 + * on the added branch there exists
8627 + * - a same named entry
8629 + * * negative --> positive
8630 + * * positive --> positive
8631 + * - type is unchanged
8632 + * - type is changed
8634 + * * negative --> negative
8635 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8638 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8639 + struct au_dinfo *tmp)
8642 + aufs_bindex_t bindex, bbot;
8644 + struct dentry *dentry;
8645 + struct inode *inode;
8647 + } orig_h, tmp_h = {
8650 + struct au_hdentry *hd;
8651 + struct inode *inode, *h_inode;
8652 + struct dentry *h_dentry;
8655 + AuDebugOn(dinfo->di_btop < 0);
8657 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8658 + orig_h.inode = NULL;
8659 + if (d_is_positive(orig_h.dentry)) {
8660 + orig_h.inode = d_inode(orig_h.dentry);
8661 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8663 + if (tmp->di_btop >= 0) {
8664 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8665 + if (d_is_positive(tmp_h.dentry)) {
8666 + tmp_h.inode = d_inode(tmp_h.dentry);
8667 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8672 + if (d_really_is_positive(dentry))
8673 + inode = d_inode(dentry);
8674 + if (!orig_h.inode) {
8675 + AuDbg("negative originally\n");
8681 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8682 + AuDebugOn(dinfo->di_bdiropq != -1);
8684 + if (!tmp_h.inode) {
8685 + AuDbg("negative --> negative\n");
8686 + /* should have only one negative lower */
8687 + if (tmp->di_btop >= 0
8688 + && tmp->di_btop < dinfo->di_btop) {
8689 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8690 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8691 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8692 + au_di_cp(dinfo, tmp);
8693 + hd = au_hdentry(tmp, tmp->di_btop);
8694 + au_set_h_dptr(dentry, tmp->di_btop,
8695 + dget(hd->hd_dentry));
8697 + au_dbg_verify_dinode(dentry);
8699 + AuDbg("negative --> positive\n");
8701 + * similar to the behaviour of creating with bypassing
8703 + * unhash it in order to force an error in the
8704 + * succeeding create operation.
8705 + * we should not set S_DEAD here.
8708 + /* au_di_swap(tmp, dinfo); */
8709 + au_dbg_verify_dinode(dentry);
8712 + AuDbg("positive originally\n");
8713 + /* inode may be NULL */
8714 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8715 + if (!tmp_h.inode) {
8716 + AuDbg("positive --> negative\n");
8717 + /* or bypassing aufs */
8719 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8720 + dinfo->di_bwh = tmp->di_bwh;
8722 + err = au_refresh_hinode_self(inode);
8723 + au_dbg_verify_dinode(dentry);
8724 + } else if (orig_h.mode == tmp_h.mode) {
8725 + AuDbg("positive --> positive, same type\n");
8726 + if (!S_ISDIR(orig_h.mode)
8727 + && dinfo->di_btop > tmp->di_btop) {
8729 + * similar to the behaviour of removing and
8734 + err = au_refresh_hinode_self(inode);
8735 + au_dbg_verify_dinode(dentry);
8737 + /* fill empty slots */
8738 + if (dinfo->di_btop > tmp->di_btop)
8739 + dinfo->di_btop = tmp->di_btop;
8740 + if (dinfo->di_bbot < tmp->di_bbot)
8741 + dinfo->di_bbot = tmp->di_bbot;
8742 + dinfo->di_bwh = tmp->di_bwh;
8743 + dinfo->di_bdiropq = tmp->di_bdiropq;
8744 + bbot = dinfo->di_bbot;
8745 + bindex = tmp->di_btop;
8746 + hd = au_hdentry(tmp, bindex);
8747 + for (; bindex <= bbot; bindex++, hd++) {
8748 + if (au_h_dptr(dentry, bindex))
8750 + h_dentry = hd->hd_dentry;
8753 + AuDebugOn(d_is_negative(h_dentry));
8754 + h_inode = d_inode(h_dentry);
8755 + AuDebugOn(orig_h.mode
8756 + != (h_inode->i_mode
8758 + au_set_h_dptr(dentry, bindex,
8762 + err = au_refresh_hinode(inode, dentry);
8763 + au_dbg_verify_dinode(dentry);
8766 + AuDbg("positive --> positive, different type\n");
8767 + /* similar to the behaviour of removing and creating */
8770 + err = au_refresh_hinode_self(inode);
8771 + au_dbg_verify_dinode(dentry);
8779 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8781 + const struct dentry_operations *dop
8782 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8783 + static const unsigned int mask
8784 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8786 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8788 + if (dentry->d_op == dop)
8791 + AuDbg("%pd\n", dentry);
8792 + spin_lock(&dentry->d_lock);
8793 + if (dop == &aufs_dop)
8794 + dentry->d_flags |= mask;
8796 + dentry->d_flags &= ~mask;
8797 + dentry->d_op = dop;
8798 + spin_unlock(&dentry->d_lock);
8801 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8803 + int err, ebrange, nbr;
8804 + unsigned int sigen;
8805 + struct au_dinfo *dinfo, *tmp;
8806 + struct super_block *sb;
8807 + struct inode *inode;
8809 + DiMustWriteLock(dentry);
8810 + AuDebugOn(IS_ROOT(dentry));
8811 + AuDebugOn(d_really_is_negative(parent));
8813 + sb = dentry->d_sb;
8814 + sigen = au_sigen(sb);
8815 + err = au_digen_test(parent, sigen);
8816 + if (unlikely(err))
8819 + nbr = au_sbbot(sb) + 1;
8820 + dinfo = au_di(dentry);
8821 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8822 + if (unlikely(err))
8824 + ebrange = au_dbrange_test(dentry);
8826 + ebrange = au_do_refresh_hdentry(dentry, parent);
8828 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8829 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8830 + if (d_really_is_positive(dentry)) {
8831 + inode = d_inode(dentry);
8832 + err = au_refresh_hinode_self(inode);
8834 + au_dbg_verify_dinode(dentry);
8836 + goto out_dgen; /* success */
8840 + /* temporary dinfo */
8841 + AuDbgDentry(dentry);
8843 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8844 + if (unlikely(!tmp))
8846 + au_di_swap(tmp, dinfo);
8847 + /* returns the number of positive dentries */
8849 + * if current working dir is removed, it returns an error.
8850 + * but the dentry is legal.
8852 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8853 + AuDbgDentry(dentry);
8854 + au_di_swap(tmp, dinfo);
8855 + if (err == -ENOENT)
8858 + /* compare/refresh by dinfo */
8859 + AuDbgDentry(dentry);
8860 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8861 + au_dbg_verify_dinode(dentry);
8864 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8865 + au_rw_write_unlock(&tmp->di_rwsem);
8867 + if (unlikely(err))
8871 + au_update_digen(dentry);
8873 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8874 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8875 + AuDbgDentry(dentry);
8881 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8882 + struct dentry *dentry, aufs_bindex_t bindex)
8887 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8890 + AuDbg("b%d\n", bindex);
8892 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8893 + * due to whiteout and branch permission.
8895 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8896 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8897 + /* it may return tri-state */
8898 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8900 + if (unlikely(valid < 0))
8910 +/* todo: remove this */
8911 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8912 + unsigned int flags, int do_udba, int dirren)
8915 + umode_t mode, h_mode;
8916 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8917 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8918 + struct inode *h_inode, *h_cached_inode;
8919 + struct dentry *h_dentry;
8920 + struct qstr *name, *h_name;
8927 + unhashed = !!d_unhashed(dentry);
8928 + is_root = !!IS_ROOT(dentry);
8929 + name = &dentry->d_name;
8930 + tmpfile = au_di(dentry)->di_tmpfile;
8933 + * Theoretically, REVAL test should be unnecessary in case of
8935 + * But {fs,i}notify doesn't fire some necessary events,
8936 + * IN_ATTRIB for atime/nlink/pageio
8937 + * Let's do REVAL test too.
8939 + if (do_udba && inode) {
8940 + mode = (inode->i_mode & S_IFMT);
8941 + plus = (inode->i_nlink > 0);
8942 + ibs = au_ibtop(inode);
8943 + ibe = au_ibbot(inode);
8946 + btop = au_dbtop(dentry);
8948 + if (inode && S_ISDIR(inode->i_mode))
8949 + btail = au_dbtaildir(dentry);
8950 + for (bindex = btop; bindex <= btail; bindex++) {
8951 + h_dentry = au_h_dptr(dentry, bindex);
8955 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8956 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8957 + spin_lock(&h_dentry->d_lock);
8958 + h_name = &h_dentry->d_name;
8959 + if (unlikely(do_udba
8962 + && (unhashed != !!d_unhashed(h_dentry)
8963 + || (!tmpfile && !dirren
8964 + && !au_qstreq(name, h_name))
8967 + && !(flags & LOOKUP_OPEN)
8968 + && (h_dentry->d_flags
8969 + & DCACHE_NFSFS_RENAMED)))
8973 + h_unhashed = d_unhashed(h_dentry);
8974 + spin_unlock(&h_dentry->d_lock);
8975 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8976 + unhashed, h_unhashed, dentry, h_dentry);
8979 + spin_unlock(&h_dentry->d_lock);
8981 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8982 + if (unlikely(err))
8983 + /* do not goto err, to keep the errno */
8986 + /* todo: plink too? */
8991 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8995 + if (d_is_positive(h_dentry))
8996 + h_inode = d_inode(h_dentry);
8999 + h_cached_inode = h_inode;
9001 + h_mode = (h_inode->i_mode & S_IFMT);
9002 + h_plus = (h_inode->i_nlink > 0);
9004 + if (inode && ibs <= bindex && bindex <= ibe)
9005 + h_cached_inode = au_h_iptr(inode, bindex);
9008 + if (unlikely(plus != h_plus && !tmpfile))
9011 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9013 + && !IS_ROOT(h_dentry)
9014 + && unhashed != d_unhashed(h_dentry)))
9017 + if (unlikely(mode != h_mode
9018 + || h_cached_inode != h_inode))
9031 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9032 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9035 + struct dentry *parent;
9037 + if (!au_digen_test(dentry, sigen))
9040 + parent = dget_parent(dentry);
9041 + di_read_lock_parent(parent, AuLock_IR);
9042 + AuDebugOn(au_digen_test(parent, sigen));
9043 + au_dbg_verify_gen(parent, sigen);
9044 + err = au_refresh_dentry(dentry, parent);
9045 + di_read_unlock(parent, AuLock_IR);
9051 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9054 + struct dentry *d, *parent;
9056 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9057 + return simple_reval_dpath(dentry, sigen);
9059 + /* slow loop, keep it simple and stupid */
9060 + /* cf: au_cpup_dirs() */
9063 + while (au_digen_test(dentry, sigen)) {
9067 + parent = dget_parent(d);
9068 + if (!au_digen_test(parent, sigen))
9074 + di_write_lock_child2(d);
9076 + /* someone might update our dentry while we were sleeping */
9077 + if (au_digen_test(d, sigen)) {
9079 + * todo: consolidate with simple_reval_dpath(),
9080 + * do_refresh() and au_reval_for_attr().
9082 + di_read_lock_parent(parent, AuLock_IR);
9083 + err = au_refresh_dentry(d, parent);
9084 + di_read_unlock(parent, AuLock_IR);
9088 + di_write_unlock(d);
9090 + if (unlikely(err))
9098 + * if valid returns 1, otherwise 0.
9100 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9103 + unsigned int sigen;
9104 + unsigned char do_udba, dirren;
9105 + struct super_block *sb;
9106 + struct inode *inode;
9108 + /* todo: support rcu-walk? */
9109 + if (flags & LOOKUP_RCU)
9113 + if (unlikely(!au_di(dentry)))
9117 + sb = dentry->d_sb;
9120 + * i_mutex of parent dir may be held,
9121 + * but we should not return 'invalid' due to busy.
9123 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9124 + if (unlikely(err)) {
9130 + if (d_really_is_positive(dentry))
9131 + inode = d_inode(dentry);
9132 + if (unlikely(inode && au_is_bad_inode(inode))) {
9137 + if (unlikely(au_dbrange_test(dentry))) {
9143 + sigen = au_sigen(sb);
9144 + if (au_digen_test(dentry, sigen)) {
9145 + AuDebugOn(IS_ROOT(dentry));
9146 + err = au_reval_dpath(dentry, sigen);
9147 + if (unlikely(err)) {
9152 + di_downgrade_lock(dentry, AuLock_IR);
9155 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9157 + && !(inode->i_state && I_LINKABLE)
9158 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9163 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9164 + if (do_udba && inode) {
9165 + aufs_bindex_t btop = au_ibtop(inode);
9166 + struct inode *h_inode;
9169 + h_inode = au_h_iptr(inode, btop);
9170 + if (h_inode && au_test_higen(inode, h_inode)) {
9177 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9178 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9179 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9181 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9187 + di_downgrade_lock(dentry, AuLock_IR);
9189 + aufs_read_unlock(dentry, AuLock_IR);
9194 + AuDbg("%pd invalid, %d\n", dentry, valid);
9200 +static void aufs_d_release(struct dentry *dentry)
9202 + if (au_di(dentry)) {
9203 + au_di_fin(dentry);
9204 + au_hn_di_reinit(dentry);
9208 +const struct dentry_operations aufs_dop = {
9209 + .d_revalidate = aufs_d_revalidate,
9210 + .d_weak_revalidate = aufs_d_revalidate,
9211 + .d_release = aufs_d_release
9214 +/* aufs_dop without d_revalidate */
9215 +const struct dentry_operations aufs_dop_noreval = {
9216 + .d_release = aufs_d_release
9218 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9219 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9220 +++ linux/fs/aufs/dentry.h 2020-01-27 10:57:18.168871450 +0100
9222 +/* SPDX-License-Identifier: GPL-2.0 */
9224 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9226 + * This program, aufs is free software; you can redistribute it and/or modify
9227 + * it under the terms of the GNU General Public License as published by
9228 + * the Free Software Foundation; either version 2 of the License, or
9229 + * (at your option) any later version.
9231 + * This program is distributed in the hope that it will be useful,
9232 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9233 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9234 + * GNU General Public License for more details.
9236 + * You should have received a copy of the GNU General Public License
9237 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9241 + * lookup and dentry operations
9244 +#ifndef __AUFS_DENTRY_H__
9245 +#define __AUFS_DENTRY_H__
9249 +#include <linux/dcache.h>
9250 +#include "dirren.h"
9253 +struct au_hdentry {
9254 + struct dentry *hd_dentry;
9255 + aufs_bindex_t hd_id;
9259 + atomic_t di_generation;
9261 + struct au_rwsem di_rwsem;
9262 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9263 + unsigned char di_tmpfile; /* to allow the different name */
9264 + struct au_hdentry *di_hdentry;
9265 + struct rcu_head rcu;
9266 +} ____cacheline_aligned_in_smp;
9268 +/* ---------------------------------------------------------------------- */
9270 +/* flags for au_lkup_dentry() */
9271 +#define AuLkup_ALLOW_NEG 1
9272 +#define AuLkup_IGNORE_PERM (1 << 1)
9273 +#define AuLkup_DIRREN (1 << 2)
9274 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9275 +#define au_fset_lkup(flags, name) \
9276 + do { (flags) |= AuLkup_##name; } while (0)
9277 +#define au_fclr_lkup(flags, name) \
9278 + do { (flags) &= ~AuLkup_##name; } while (0)
9280 +#ifndef CONFIG_AUFS_DIRREN
9281 +#undef AuLkup_DIRREN
9282 +#define AuLkup_DIRREN 0
9285 +struct au_do_lookup_args {
9286 + unsigned int flags;
9288 + struct qstr whname, *name;
9289 + struct au_dr_lookup dirren;
9292 +/* ---------------------------------------------------------------------- */
9295 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9297 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9298 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9299 + struct dentry *h_parent, struct au_branch *br);
9301 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9302 + unsigned int flags);
9303 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9304 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9305 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9306 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9309 +void au_di_init_once(void *_di);
9310 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9311 +void au_di_free(struct au_dinfo *dinfo);
9312 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9313 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9314 +int au_di_init(struct dentry *dentry);
9315 +void au_di_fin(struct dentry *dentry);
9316 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9318 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9319 +void di_read_unlock(struct dentry *d, int flags);
9320 +void di_downgrade_lock(struct dentry *d, int flags);
9321 +void di_write_lock(struct dentry *d, unsigned int lsc);
9322 +void di_write_unlock(struct dentry *d);
9323 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9324 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9325 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9327 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9328 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9329 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9330 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9332 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9333 + struct dentry *h_dentry);
9334 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9335 +int au_dbrange_test(struct dentry *dentry);
9336 +void au_update_digen(struct dentry *dentry);
9337 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9338 +void au_update_dbtop(struct dentry *dentry);
9339 +void au_update_dbbot(struct dentry *dentry);
9340 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9342 +/* ---------------------------------------------------------------------- */
9344 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9346 + return dentry->d_fsdata;
9349 +/* ---------------------------------------------------------------------- */
9351 +/* lock subclass for dinfo */
9353 + AuLsc_DI_CHILD, /* child first */
9354 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9355 + AuLsc_DI_CHILD3, /* copyup dirs */
9359 + AuLsc_DI_TMP /* temp for replacing dinfo */
9363 + * di_read_lock_child, di_write_lock_child,
9364 + * di_read_lock_child2, di_write_lock_child2,
9365 + * di_read_lock_child3, di_write_lock_child3,
9366 + * di_read_lock_parent, di_write_lock_parent,
9367 + * di_read_lock_parent2, di_write_lock_parent2,
9368 + * di_read_lock_parent3, di_write_lock_parent3,
9370 +#define AuReadLockFunc(name, lsc) \
9371 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9372 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9374 +#define AuWriteLockFunc(name, lsc) \
9375 +static inline void di_write_lock_##name(struct dentry *d) \
9376 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9378 +#define AuRWLockFuncs(name, lsc) \
9379 + AuReadLockFunc(name, lsc) \
9380 + AuWriteLockFunc(name, lsc)
9382 +AuRWLockFuncs(child, CHILD);
9383 +AuRWLockFuncs(child2, CHILD2);
9384 +AuRWLockFuncs(child3, CHILD3);
9385 +AuRWLockFuncs(parent, PARENT);
9386 +AuRWLockFuncs(parent2, PARENT2);
9387 +AuRWLockFuncs(parent3, PARENT3);
9389 +#undef AuReadLockFunc
9390 +#undef AuWriteLockFunc
9391 +#undef AuRWLockFuncs
9393 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9394 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9395 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9397 +/* ---------------------------------------------------------------------- */
9399 +/* todo: memory barrier? */
9400 +static inline unsigned int au_digen(struct dentry *d)
9402 + return atomic_read(&au_di(d)->di_generation);
9405 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9407 + hdentry->hd_dentry = NULL;
9410 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9411 + aufs_bindex_t bindex)
9413 + return di->di_hdentry + bindex;
9416 +static inline void au_hdput(struct au_hdentry *hd)
9419 + dput(hd->hd_dentry);
9422 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9424 + DiMustAnyLock(dentry);
9425 + return au_di(dentry)->di_btop;
9428 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9430 + DiMustAnyLock(dentry);
9431 + return au_di(dentry)->di_bbot;
9434 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9436 + DiMustAnyLock(dentry);
9437 + return au_di(dentry)->di_bwh;
9440 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9442 + DiMustAnyLock(dentry);
9443 + return au_di(dentry)->di_bdiropq;
9446 +/* todo: hard/soft set? */
9447 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9449 + DiMustWriteLock(dentry);
9450 + au_di(dentry)->di_btop = bindex;
9453 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9455 + DiMustWriteLock(dentry);
9456 + au_di(dentry)->di_bbot = bindex;
9459 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9461 + DiMustWriteLock(dentry);
9462 + /* dbwh can be outside of btop - bbot range */
9463 + au_di(dentry)->di_bwh = bindex;
9466 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9468 + DiMustWriteLock(dentry);
9469 + au_di(dentry)->di_bdiropq = bindex;
9472 +/* ---------------------------------------------------------------------- */
9474 +#ifdef CONFIG_AUFS_HNOTIFY
9475 +static inline void au_digen_dec(struct dentry *d)
9477 + atomic_dec(&au_di(d)->di_generation);
9480 +static inline void au_hn_di_reinit(struct dentry *dentry)
9482 + dentry->d_fsdata = NULL;
9485 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9486 +#endif /* CONFIG_AUFS_HNOTIFY */
9488 +#endif /* __KERNEL__ */
9489 +#endif /* __AUFS_DENTRY_H__ */
9490 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9491 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9492 +++ linux/fs/aufs/dinfo.c 2020-01-27 10:57:18.168871450 +0100
9494 +// SPDX-License-Identifier: GPL-2.0
9496 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9498 + * This program, aufs is free software; you can redistribute it and/or modify
9499 + * it under the terms of the GNU General Public License as published by
9500 + * the Free Software Foundation; either version 2 of the License, or
9501 + * (at your option) any later version.
9503 + * This program is distributed in the hope that it will be useful,
9504 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9505 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9506 + * GNU General Public License for more details.
9508 + * You should have received a copy of the GNU General Public License
9509 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9513 + * dentry private data
9518 +void au_di_init_once(void *_dinfo)
9520 + struct au_dinfo *dinfo = _dinfo;
9522 + au_rw_init(&dinfo->di_rwsem);
9525 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9527 + struct au_dinfo *dinfo;
9530 + dinfo = au_cache_alloc_dinfo();
9531 + if (unlikely(!dinfo))
9534 + nbr = au_sbbot(sb) + 1;
9537 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9538 + if (dinfo->di_hdentry) {
9539 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9540 + dinfo->di_btop = -1;
9541 + dinfo->di_bbot = -1;
9542 + dinfo->di_bwh = -1;
9543 + dinfo->di_bdiropq = -1;
9544 + dinfo->di_tmpfile = 0;
9545 + for (i = 0; i < nbr; i++)
9546 + dinfo->di_hdentry[i].hd_id = -1;
9550 + au_cache_free_dinfo(dinfo);
9557 +void au_di_free(struct au_dinfo *dinfo)
9559 + struct au_hdentry *p;
9560 + aufs_bindex_t bbot, bindex;
9562 + /* dentry may not be revalidated */
9563 + bindex = dinfo->di_btop;
9564 + if (bindex >= 0) {
9565 + bbot = dinfo->di_bbot;
9566 + p = au_hdentry(dinfo, bindex);
9567 + while (bindex++ <= bbot)
9570 + au_kfree_try_rcu(dinfo->di_hdentry);
9571 + au_cache_free_dinfo(dinfo);
9574 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9576 + struct au_hdentry *p;
9579 + AuRwMustWriteLock(&a->di_rwsem);
9580 + AuRwMustWriteLock(&b->di_rwsem);
9582 +#define DiSwap(v, name) \
9584 + v = a->di_##name; \
9585 + a->di_##name = b->di_##name; \
9586 + b->di_##name = v; \
9589 + DiSwap(p, hdentry);
9593 + DiSwap(bi, bdiropq);
9599 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9601 + AuRwMustWriteLock(&dst->di_rwsem);
9602 + AuRwMustWriteLock(&src->di_rwsem);
9604 + dst->di_btop = src->di_btop;
9605 + dst->di_bbot = src->di_bbot;
9606 + dst->di_bwh = src->di_bwh;
9607 + dst->di_bdiropq = src->di_bdiropq;
9611 +int au_di_init(struct dentry *dentry)
9614 + struct super_block *sb;
9615 + struct au_dinfo *dinfo;
9618 + sb = dentry->d_sb;
9619 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9621 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9622 + /* smp_mb(); */ /* atomic_set */
9623 + dentry->d_fsdata = dinfo;
9630 +void au_di_fin(struct dentry *dentry)
9632 + struct au_dinfo *dinfo;
9634 + dinfo = au_di(dentry);
9635 + AuRwDestroy(&dinfo->di_rwsem);
9636 + au_di_free(dinfo);
9639 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9642 + struct au_hdentry *hdp;
9644 + AuRwMustWriteLock(&dinfo->di_rwsem);
9647 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9649 + sz = sizeof(*hdp);
9650 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9653 + dinfo->di_hdentry = hdp;
9660 +/* ---------------------------------------------------------------------- */
9662 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9665 + case AuLsc_DI_CHILD:
9666 + ii_write_lock_child(inode);
9668 + case AuLsc_DI_CHILD2:
9669 + ii_write_lock_child2(inode);
9671 + case AuLsc_DI_CHILD3:
9672 + ii_write_lock_child3(inode);
9674 + case AuLsc_DI_PARENT:
9675 + ii_write_lock_parent(inode);
9677 + case AuLsc_DI_PARENT2:
9678 + ii_write_lock_parent2(inode);
9680 + case AuLsc_DI_PARENT3:
9681 + ii_write_lock_parent3(inode);
9688 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9691 + case AuLsc_DI_CHILD:
9692 + ii_read_lock_child(inode);
9694 + case AuLsc_DI_CHILD2:
9695 + ii_read_lock_child2(inode);
9697 + case AuLsc_DI_CHILD3:
9698 + ii_read_lock_child3(inode);
9700 + case AuLsc_DI_PARENT:
9701 + ii_read_lock_parent(inode);
9703 + case AuLsc_DI_PARENT2:
9704 + ii_read_lock_parent2(inode);
9706 + case AuLsc_DI_PARENT3:
9707 + ii_read_lock_parent3(inode);
9714 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9716 + struct inode *inode;
9718 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9719 + if (d_really_is_positive(d)) {
9720 + inode = d_inode(d);
9721 + if (au_ftest_lock(flags, IW))
9722 + do_ii_write_lock(inode, lsc);
9723 + else if (au_ftest_lock(flags, IR))
9724 + do_ii_read_lock(inode, lsc);
9728 +void di_read_unlock(struct dentry *d, int flags)
9730 + struct inode *inode;
9732 + if (d_really_is_positive(d)) {
9733 + inode = d_inode(d);
9734 + if (au_ftest_lock(flags, IW)) {
9735 + au_dbg_verify_dinode(d);
9736 + ii_write_unlock(inode);
9737 + } else if (au_ftest_lock(flags, IR)) {
9738 + au_dbg_verify_dinode(d);
9739 + ii_read_unlock(inode);
9742 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9745 +void di_downgrade_lock(struct dentry *d, int flags)
9747 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9748 + ii_downgrade_lock(d_inode(d));
9749 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9752 +void di_write_lock(struct dentry *d, unsigned int lsc)
9754 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9755 + if (d_really_is_positive(d))
9756 + do_ii_write_lock(d_inode(d), lsc);
9759 +void di_write_unlock(struct dentry *d)
9761 + au_dbg_verify_dinode(d);
9762 + if (d_really_is_positive(d))
9763 + ii_write_unlock(d_inode(d));
9764 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9767 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9769 + AuDebugOn(d1 == d2
9770 + || d_inode(d1) == d_inode(d2)
9771 + || d1->d_sb != d2->d_sb);
9773 + if ((isdir && au_test_subdir(d1, d2))
9775 + di_write_lock_child(d1);
9776 + di_write_lock_child2(d2);
9778 + di_write_lock_child(d2);
9779 + di_write_lock_child2(d1);
9783 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9785 + AuDebugOn(d1 == d2
9786 + || d_inode(d1) == d_inode(d2)
9787 + || d1->d_sb != d2->d_sb);
9789 + if ((isdir && au_test_subdir(d1, d2))
9791 + di_write_lock_parent(d1);
9792 + di_write_lock_parent2(d2);
9794 + di_write_lock_parent(d2);
9795 + di_write_lock_parent2(d1);
9799 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9801 + di_write_unlock(d1);
9802 + if (d_inode(d1) == d_inode(d2))
9803 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9805 + di_write_unlock(d2);
9808 +/* ---------------------------------------------------------------------- */
9810 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9814 + DiMustAnyLock(dentry);
9816 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9818 + AuDebugOn(bindex < 0);
9819 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9820 + AuDebugOn(d && au_dcount(d) <= 0);
9825 + * extended version of au_h_dptr().
9826 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9829 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9831 + struct dentry *h_dentry;
9832 + struct inode *inode, *h_inode;
9834 + AuDebugOn(d_really_is_negative(dentry));
9837 + if (au_dbtop(dentry) <= bindex
9838 + && bindex <= au_dbbot(dentry))
9839 + h_dentry = au_h_dptr(dentry, bindex);
9840 + if (h_dentry && !au_d_linkable(h_dentry)) {
9842 + goto out; /* success */
9845 + inode = d_inode(dentry);
9846 + AuDebugOn(bindex < au_ibtop(inode));
9847 + AuDebugOn(au_ibbot(inode) < bindex);
9848 + h_inode = au_h_iptr(inode, bindex);
9849 + h_dentry = d_find_alias(h_inode);
9851 + if (!IS_ERR(h_dentry)) {
9852 + if (!au_d_linkable(h_dentry))
9853 + goto out; /* success */
9859 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9860 + h_dentry = au_plink_lkup(inode, bindex);
9861 + AuDebugOn(!h_dentry);
9862 + if (!IS_ERR(h_dentry)) {
9863 + if (!au_d_hashed_positive(h_dentry))
9864 + goto out; /* success */
9871 + AuDbgDentry(h_dentry);
9875 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9877 + aufs_bindex_t bbot, bwh;
9879 + bbot = au_dbbot(dentry);
9881 + bwh = au_dbwh(dentry);
9884 + if (0 < bwh && bwh < bbot)
9890 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9892 + aufs_bindex_t bbot, bopq;
9894 + bbot = au_dbtail(dentry);
9896 + bopq = au_dbdiropq(dentry);
9897 + if (0 <= bopq && bopq < bbot)
9903 +/* ---------------------------------------------------------------------- */
9905 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9906 + struct dentry *h_dentry)
9908 + struct au_dinfo *dinfo;
9909 + struct au_hdentry *hd;
9910 + struct au_branch *br;
9912 + DiMustWriteLock(dentry);
9914 + dinfo = au_di(dentry);
9915 + hd = au_hdentry(dinfo, bindex);
9917 + hd->hd_dentry = h_dentry;
9919 + br = au_sbr(dentry->d_sb, bindex);
9920 + hd->hd_id = br->br_id;
9924 +int au_dbrange_test(struct dentry *dentry)
9927 + aufs_bindex_t btop, bbot;
9930 + btop = au_dbtop(dentry);
9931 + bbot = au_dbbot(dentry);
9933 + AuDebugOn(bbot < 0 && btop > bbot);
9936 + AuDebugOn(bbot >= 0);
9942 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9947 + if (unlikely(au_digen(dentry) != sigen
9948 + || au_iigen_test(d_inode(dentry), sigen)))
9954 +void au_update_digen(struct dentry *dentry)
9956 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9957 + /* smp_mb(); */ /* atomic_set */
9960 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9962 + struct au_dinfo *dinfo;
9963 + struct dentry *h_d;
9964 + struct au_hdentry *hdp;
9965 + aufs_bindex_t bindex, bbot;
9967 + DiMustWriteLock(dentry);
9969 + dinfo = au_di(dentry);
9970 + if (!dinfo || dinfo->di_btop < 0)
9973 + if (do_put_zero) {
9974 + bbot = dinfo->di_bbot;
9975 + bindex = dinfo->di_btop;
9976 + hdp = au_hdentry(dinfo, bindex);
9977 + for (; bindex <= bbot; bindex++, hdp++) {
9978 + h_d = hdp->hd_dentry;
9979 + if (h_d && d_is_negative(h_d))
9980 + au_set_h_dptr(dentry, bindex, NULL);
9984 + dinfo->di_btop = 0;
9985 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9986 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9987 + if (hdp->hd_dentry)
9989 + if (dinfo->di_btop > dinfo->di_bbot) {
9990 + dinfo->di_btop = -1;
9991 + dinfo->di_bbot = -1;
9995 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9996 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9997 + if (hdp->hd_dentry)
9999 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10002 +void au_update_dbtop(struct dentry *dentry)
10004 + aufs_bindex_t bindex, bbot;
10005 + struct dentry *h_dentry;
10007 + bbot = au_dbbot(dentry);
10008 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10009 + h_dentry = au_h_dptr(dentry, bindex);
10012 + if (d_is_positive(h_dentry)) {
10013 + au_set_dbtop(dentry, bindex);
10016 + au_set_h_dptr(dentry, bindex, NULL);
10020 +void au_update_dbbot(struct dentry *dentry)
10022 + aufs_bindex_t bindex, btop;
10023 + struct dentry *h_dentry;
10025 + btop = au_dbtop(dentry);
10026 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10027 + h_dentry = au_h_dptr(dentry, bindex);
10030 + if (d_is_positive(h_dentry)) {
10031 + au_set_dbbot(dentry, bindex);
10034 + au_set_h_dptr(dentry, bindex, NULL);
10038 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10040 + aufs_bindex_t bindex, bbot;
10042 + bbot = au_dbbot(dentry);
10043 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10044 + if (au_h_dptr(dentry, bindex) == h_dentry)
10048 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10049 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10050 +++ linux/fs/aufs/dir.c 2020-01-27 10:57:18.168871450 +0100
10052 +// SPDX-License-Identifier: GPL-2.0
10054 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10056 + * This program, aufs is free software; you can redistribute it and/or modify
10057 + * it under the terms of the GNU General Public License as published by
10058 + * the Free Software Foundation; either version 2 of the License, or
10059 + * (at your option) any later version.
10061 + * This program is distributed in the hope that it will be useful,
10062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10064 + * GNU General Public License for more details.
10066 + * You should have received a copy of the GNU General Public License
10067 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10071 + * directory operations
10074 +#include <linux/fs_stack.h>
10075 +#include <linux/iversion.h>
10078 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10080 + unsigned int nlink;
10082 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10084 + nlink = dir->i_nlink;
10085 + nlink += h_dir->i_nlink - 2;
10086 + if (h_dir->i_nlink < 2)
10088 + smp_mb(); /* for i_nlink */
10089 + /* 0 can happen in revaliding */
10090 + set_nlink(dir, nlink);
10093 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10095 + unsigned int nlink;
10097 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10099 + nlink = dir->i_nlink;
10100 + nlink -= h_dir->i_nlink - 2;
10101 + if (h_dir->i_nlink < 2)
10103 + smp_mb(); /* for i_nlink */
10104 + /* nlink == 0 means the branch-fs is broken */
10105 + set_nlink(dir, nlink);
10108 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10111 + aufs_bindex_t bindex, bbot;
10112 + struct file *h_file;
10113 + struct dentry *h_dentry;
10117 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10119 + bbot = au_fbbot_dir(file);
10120 + for (bindex = au_fbtop(file);
10121 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10123 + h_file = au_hf_dir(file, bindex);
10124 + if (h_file && file_inode(h_file))
10125 + sz += vfsub_f_size_read(h_file);
10128 + AuDebugOn(!dentry);
10129 + AuDebugOn(!d_is_dir(dentry));
10131 + bbot = au_dbtaildir(dentry);
10132 + for (bindex = au_dbtop(dentry);
10133 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10135 + h_dentry = au_h_dptr(dentry, bindex);
10136 + if (h_dentry && d_is_positive(h_dentry))
10137 + sz += i_size_read(d_inode(h_dentry));
10140 + if (sz < KMALLOC_MAX_SIZE)
10141 + sz = roundup_pow_of_two(sz);
10142 + if (sz > KMALLOC_MAX_SIZE)
10143 + sz = KMALLOC_MAX_SIZE;
10144 + else if (sz < NAME_MAX) {
10145 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10146 + sz = AUFS_RDBLK_DEF;
10151 +struct au_dir_ts_arg {
10152 + struct dentry *dentry;
10153 + aufs_bindex_t brid;
10156 +static void au_do_dir_ts(void *arg)
10158 + struct au_dir_ts_arg *a = arg;
10159 + struct au_dtime dt;
10160 + struct path h_path;
10161 + struct inode *dir, *h_dir;
10162 + struct super_block *sb;
10163 + struct au_branch *br;
10164 + struct au_hinode *hdir;
10166 + aufs_bindex_t btop, bindex;
10168 + sb = a->dentry->d_sb;
10169 + if (d_really_is_negative(a->dentry))
10171 + /* no dir->i_mutex lock */
10172 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10174 + dir = d_inode(a->dentry);
10175 + btop = au_ibtop(dir);
10176 + bindex = au_br_index(sb, a->brid);
10177 + if (bindex < btop)
10180 + br = au_sbr(sb, bindex);
10181 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10182 + if (!h_path.dentry)
10184 + h_path.mnt = au_br_mnt(br);
10185 + au_dtime_store(&dt, a->dentry, &h_path);
10187 + br = au_sbr(sb, btop);
10188 + if (!au_br_writable(br->br_perm))
10190 + h_path.dentry = au_h_dptr(a->dentry, btop);
10191 + h_path.mnt = au_br_mnt(br);
10192 + err = vfsub_mnt_want_write(h_path.mnt);
10195 + hdir = au_hi(dir, btop);
10196 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10197 + h_dir = au_h_iptr(dir, btop);
10198 + if (h_dir->i_nlink
10199 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10200 + dt.dt_h_path = h_path;
10201 + au_dtime_revert(&dt);
10203 + au_hn_inode_unlock(hdir);
10204 + vfsub_mnt_drop_write(h_path.mnt);
10205 + au_cpup_attr_timesizes(dir);
10208 + aufs_read_unlock(a->dentry, AuLock_DW);
10211 + au_nwt_done(&au_sbi(sb)->si_nowait);
10212 + au_kfree_try_rcu(arg);
10215 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10217 + int perm, wkq_err;
10218 + aufs_bindex_t btop;
10219 + struct au_dir_ts_arg *arg;
10220 + struct dentry *dentry;
10221 + struct super_block *sb;
10225 + dentry = d_find_any_alias(dir);
10226 + AuDebugOn(!dentry);
10227 + sb = dentry->d_sb;
10228 + btop = au_ibtop(dir);
10229 + if (btop == bindex) {
10230 + au_cpup_attr_timesizes(dir);
10234 + perm = au_sbr_perm(sb, btop);
10235 + if (!au_br_writable(perm))
10238 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10242 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10243 + arg->brid = au_sbr_id(sb, bindex);
10244 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10245 + if (unlikely(wkq_err)) {
10246 + pr_err("wkq %d\n", wkq_err);
10248 + au_kfree_try_rcu(arg);
10255 +/* ---------------------------------------------------------------------- */
10257 +static int reopen_dir(struct file *file)
10260 + unsigned int flags;
10261 + aufs_bindex_t bindex, btail, btop;
10262 + struct dentry *dentry, *h_dentry;
10263 + struct file *h_file;
10265 + /* open all lower dirs */
10266 + dentry = file->f_path.dentry;
10267 + btop = au_dbtop(dentry);
10268 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10269 + au_set_h_fptr(file, bindex, NULL);
10270 + au_set_fbtop(file, btop);
10272 + btail = au_dbtaildir(dentry);
10273 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10274 + au_set_h_fptr(file, bindex, NULL);
10275 + au_set_fbbot_dir(file, btail);
10277 + flags = vfsub_file_flags(file);
10278 + for (bindex = btop; bindex <= btail; bindex++) {
10279 + h_dentry = au_h_dptr(dentry, bindex);
10282 + h_file = au_hf_dir(file, bindex);
10286 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10287 + err = PTR_ERR(h_file);
10288 + if (IS_ERR(h_file))
10289 + goto out; /* close all? */
10290 + au_set_h_fptr(file, bindex, h_file);
10292 + au_update_figen(file);
10293 + /* todo: necessary? */
10294 + /* file->f_ra = h_file->f_ra; */
10301 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10304 + aufs_bindex_t bindex, btail;
10305 + struct dentry *dentry, *h_dentry;
10306 + struct vfsmount *mnt;
10308 + FiMustWriteLock(file);
10309 + AuDebugOn(h_file);
10312 + mnt = file->f_path.mnt;
10313 + dentry = file->f_path.dentry;
10314 + file->f_version = inode_query_iversion(d_inode(dentry));
10315 + bindex = au_dbtop(dentry);
10316 + au_set_fbtop(file, bindex);
10317 + btail = au_dbtaildir(dentry);
10318 + au_set_fbbot_dir(file, btail);
10319 + for (; !err && bindex <= btail; bindex++) {
10320 + h_dentry = au_h_dptr(dentry, bindex);
10324 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10325 + if (unlikely(err))
10327 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10328 + if (IS_ERR(h_file)) {
10329 + err = PTR_ERR(h_file);
10332 + au_set_h_fptr(file, bindex, h_file);
10334 + au_update_figen(file);
10335 + /* todo: necessary? */
10336 + /* file->f_ra = h_file->f_ra; */
10338 + return 0; /* success */
10341 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10342 + au_set_h_fptr(file, bindex, NULL);
10343 + au_set_fbtop(file, -1);
10344 + au_set_fbbot_dir(file, -1);
10349 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10350 + struct file *file)
10353 + struct super_block *sb;
10354 + struct au_fidir *fidir;
10357 + sb = file->f_path.dentry->d_sb;
10358 + si_read_lock(sb, AuLock_FLUSH);
10359 + fidir = au_fidir_alloc(sb);
10361 + struct au_do_open_args args = {
10362 + .open = do_open_dir,
10365 + err = au_do_open(file, &args);
10366 + if (unlikely(err))
10367 + au_kfree_rcu(fidir);
10369 + si_read_unlock(sb);
10373 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10374 + struct file *file)
10376 + struct au_vdir *vdir_cache;
10377 + struct au_finfo *finfo;
10378 + struct au_fidir *fidir;
10379 + struct au_hfile *hf;
10380 + aufs_bindex_t bindex, bbot;
10382 + finfo = au_fi(file);
10383 + fidir = finfo->fi_hdir;
10385 + au_hbl_del(&finfo->fi_hlist,
10386 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10387 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10389 + au_vdir_free(vdir_cache);
10391 + bindex = finfo->fi_btop;
10392 + if (bindex >= 0) {
10393 + hf = fidir->fd_hfile + bindex;
10395 + * calls fput() instead of filp_close(),
10396 + * since no dnotify or lock for the lower file.
10398 + bbot = fidir->fd_bbot;
10399 + for (; bindex <= bbot; bindex++, hf++)
10401 + au_hfput(hf, /*execed*/0);
10403 + au_kfree_rcu(fidir);
10404 + finfo->fi_hdir = NULL;
10406 + au_finfo_fin(file);
10410 +/* ---------------------------------------------------------------------- */
10412 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10415 + aufs_bindex_t bindex, bbot;
10416 + struct file *h_file;
10419 + bbot = au_fbbot_dir(file);
10420 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10421 + h_file = au_hf_dir(file, bindex);
10423 + err = vfsub_flush(h_file, id);
10428 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10430 + return au_do_flush(file, id, au_do_flush_dir);
10433 +/* ---------------------------------------------------------------------- */
10435 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10438 + aufs_bindex_t bbot, bindex;
10439 + struct inode *inode;
10440 + struct super_block *sb;
10443 + sb = dentry->d_sb;
10444 + inode = d_inode(dentry);
10445 + IMustLock(inode);
10446 + bbot = au_dbbot(dentry);
10447 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10448 + struct path h_path;
10450 + if (au_test_ro(sb, bindex, inode))
10452 + h_path.dentry = au_h_dptr(dentry, bindex);
10453 + if (!h_path.dentry)
10456 + h_path.mnt = au_sbr_mnt(sb, bindex);
10457 + err = vfsub_fsync(NULL, &h_path, datasync);
10463 +static int au_do_fsync_dir(struct file *file, int datasync)
10466 + aufs_bindex_t bbot, bindex;
10467 + struct file *h_file;
10468 + struct super_block *sb;
10469 + struct inode *inode;
10471 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10472 + if (unlikely(err))
10475 + inode = file_inode(file);
10476 + sb = inode->i_sb;
10477 + bbot = au_fbbot_dir(file);
10478 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10479 + h_file = au_hf_dir(file, bindex);
10480 + if (!h_file || au_test_ro(sb, bindex, inode))
10483 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10491 + * @file may be NULL
10493 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10497 + struct dentry *dentry;
10498 + struct inode *inode;
10499 + struct super_block *sb;
10502 + dentry = file->f_path.dentry;
10503 + inode = d_inode(dentry);
10504 + inode_lock(inode);
10505 + sb = dentry->d_sb;
10506 + si_noflush_read_lock(sb);
10508 + err = au_do_fsync_dir(file, datasync);
10510 + di_write_lock_child(dentry);
10511 + err = au_do_fsync_dir_no_file(dentry, datasync);
10513 + au_cpup_attr_timesizes(inode);
10514 + di_write_unlock(dentry);
10516 + fi_write_unlock(file);
10518 + si_read_unlock(sb);
10519 + inode_unlock(inode);
10523 +/* ---------------------------------------------------------------------- */
10525 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10528 + struct dentry *dentry;
10529 + struct inode *inode, *h_inode;
10530 + struct super_block *sb;
10532 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10534 + dentry = file->f_path.dentry;
10535 + inode = d_inode(dentry);
10536 + IMustLock(inode);
10538 + sb = dentry->d_sb;
10539 + si_read_lock(sb, AuLock_FLUSH);
10540 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10541 + if (unlikely(err))
10543 + err = au_alive_dir(dentry);
10545 + err = au_vdir_init(file);
10546 + di_downgrade_lock(dentry, AuLock_IR);
10547 + if (unlikely(err))
10550 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10551 + if (!au_test_nfsd()) {
10552 + err = au_vdir_fill_de(file, ctx);
10553 + fsstack_copy_attr_atime(inode, h_inode);
10556 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10557 + * encode_fh() and others.
10559 + atomic_inc(&h_inode->i_count);
10560 + di_read_unlock(dentry, AuLock_IR);
10561 + si_read_unlock(sb);
10562 + err = au_vdir_fill_de(file, ctx);
10563 + fsstack_copy_attr_atime(inode, h_inode);
10564 + fi_write_unlock(file);
10572 + di_read_unlock(dentry, AuLock_IR);
10573 + fi_write_unlock(file);
10575 + si_read_unlock(sb);
10579 +/* ---------------------------------------------------------------------- */
10581 +#define AuTestEmpty_WHONLY 1
10582 +#define AuTestEmpty_CALLED (1 << 1)
10583 +#define AuTestEmpty_SHWH (1 << 2)
10584 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10585 +#define au_fset_testempty(flags, name) \
10586 + do { (flags) |= AuTestEmpty_##name; } while (0)
10587 +#define au_fclr_testempty(flags, name) \
10588 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10590 +#ifndef CONFIG_AUFS_SHWH
10591 +#undef AuTestEmpty_SHWH
10592 +#define AuTestEmpty_SHWH 0
10595 +struct test_empty_arg {
10596 + struct dir_context ctx;
10597 + struct au_nhash *whlist;
10598 + unsigned int flags;
10600 + aufs_bindex_t bindex;
10603 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10604 + int namelen, loff_t offset __maybe_unused, u64 ino,
10605 + unsigned int d_type)
10607 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10609 + char *name = (void *)__name;
10612 + au_fset_testempty(arg->flags, CALLED);
10614 + if (name[0] == '.'
10615 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10616 + goto out; /* success */
10618 + if (namelen <= AUFS_WH_PFX_LEN
10619 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10620 + if (au_ftest_testempty(arg->flags, WHONLY)
10621 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10622 + arg->err = -ENOTEMPTY;
10626 + name += AUFS_WH_PFX_LEN;
10627 + namelen -= AUFS_WH_PFX_LEN;
10628 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10629 + arg->err = au_nhash_append_wh
10630 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10631 + au_ftest_testempty(arg->flags, SHWH));
10635 + AuTraceErr(arg->err);
10639 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10642 + struct file *h_file;
10643 + struct au_branch *br;
10645 + h_file = au_h_open(dentry, arg->bindex,
10646 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10647 + /*file*/NULL, /*force_wr*/0);
10648 + err = PTR_ERR(h_file);
10649 + if (IS_ERR(h_file))
10653 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10654 + && !file_inode(h_file)->i_nlink)
10659 + au_fclr_testempty(arg->flags, CALLED);
10661 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10664 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10668 + br = au_sbr(dentry->d_sb, arg->bindex);
10669 + au_lcnt_dec(&br->br_nfiles);
10674 +struct do_test_empty_args {
10676 + struct dentry *dentry;
10677 + struct test_empty_arg *arg;
10680 +static void call_do_test_empty(void *args)
10682 + struct do_test_empty_args *a = args;
10683 + *a->errp = do_test_empty(a->dentry, a->arg);
10686 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10688 + int err, wkq_err;
10689 + struct dentry *h_dentry;
10690 + struct inode *h_inode;
10692 + h_dentry = au_h_dptr(dentry, arg->bindex);
10693 + h_inode = d_inode(h_dentry);
10694 + /* todo: i_mode changes anytime? */
10695 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10696 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10697 + inode_unlock_shared(h_inode);
10699 + err = do_test_empty(dentry, arg);
10701 + struct do_test_empty_args args = {
10703 + .dentry = dentry,
10706 + unsigned int flags = arg->flags;
10708 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10709 + if (unlikely(wkq_err))
10711 + arg->flags = flags;
10717 +int au_test_empty_lower(struct dentry *dentry)
10720 + unsigned int rdhash;
10721 + aufs_bindex_t bindex, btop, btail;
10722 + struct au_nhash whlist;
10723 + struct test_empty_arg arg = {
10725 + .actor = test_empty_cb
10728 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10730 + SiMustAnyLock(dentry->d_sb);
10732 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10734 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10735 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10736 + if (unlikely(err))
10740 + arg.whlist = &whlist;
10741 + btop = au_dbtop(dentry);
10742 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10743 + au_fset_testempty(arg.flags, SHWH);
10744 + test_empty = do_test_empty;
10745 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10746 + test_empty = sio_test_empty;
10747 + arg.bindex = btop;
10748 + err = test_empty(dentry, &arg);
10749 + if (unlikely(err))
10752 + au_fset_testempty(arg.flags, WHONLY);
10753 + btail = au_dbtaildir(dentry);
10754 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10755 + struct dentry *h_dentry;
10757 + h_dentry = au_h_dptr(dentry, bindex);
10758 + if (h_dentry && d_is_positive(h_dentry)) {
10759 + arg.bindex = bindex;
10760 + err = test_empty(dentry, &arg);
10765 + au_nhash_wh_free(&whlist);
10770 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10773 + struct test_empty_arg arg = {
10775 + .actor = test_empty_cb
10778 + aufs_bindex_t bindex, btail;
10781 + arg.whlist = whlist;
10782 + arg.flags = AuTestEmpty_WHONLY;
10783 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10784 + au_fset_testempty(arg.flags, SHWH);
10785 + btail = au_dbtaildir(dentry);
10786 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10787 + struct dentry *h_dentry;
10789 + h_dentry = au_h_dptr(dentry, bindex);
10790 + if (h_dentry && d_is_positive(h_dentry)) {
10791 + arg.bindex = bindex;
10792 + err = sio_test_empty(dentry, &arg);
10799 +/* ---------------------------------------------------------------------- */
10801 +const struct file_operations aufs_dir_fop = {
10802 + .owner = THIS_MODULE,
10803 + .llseek = default_llseek,
10804 + .read = generic_read_dir,
10805 + .iterate_shared = aufs_iterate_shared,
10806 + .unlocked_ioctl = aufs_ioctl_dir,
10807 +#ifdef CONFIG_COMPAT
10808 + .compat_ioctl = aufs_compat_ioctl_dir,
10810 + .open = aufs_open_dir,
10811 + .release = aufs_release_dir,
10812 + .flush = aufs_flush_dir,
10813 + .fsync = aufs_fsync_dir
10815 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10816 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10817 +++ linux/fs/aufs/dir.h 2020-01-27 10:57:18.168871450 +0100
10819 +/* SPDX-License-Identifier: GPL-2.0 */
10821 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10823 + * This program, aufs is free software; you can redistribute it and/or modify
10824 + * it under the terms of the GNU General Public License as published by
10825 + * the Free Software Foundation; either version 2 of the License, or
10826 + * (at your option) any later version.
10828 + * This program is distributed in the hope that it will be useful,
10829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10831 + * GNU General Public License for more details.
10833 + * You should have received a copy of the GNU General Public License
10834 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10838 + * directory operations
10841 +#ifndef __AUFS_DIR_H__
10842 +#define __AUFS_DIR_H__
10846 +#include <linux/fs.h>
10848 +/* ---------------------------------------------------------------------- */
10850 +/* need to be faster and smaller */
10853 + unsigned int nh_num;
10854 + struct hlist_head *nh_head;
10857 +struct au_vdir_destr {
10858 + unsigned char len;
10859 + unsigned char name[0];
10862 +struct au_vdir_dehstr {
10863 + struct hlist_node hash;
10864 + struct au_vdir_destr *str;
10865 + struct rcu_head rcu;
10866 +} ____cacheline_aligned_in_smp;
10868 +struct au_vdir_de {
10870 + unsigned char de_type;
10871 + /* caution: packed */
10872 + struct au_vdir_destr de_str;
10875 +struct au_vdir_wh {
10876 + struct hlist_node wh_hash;
10877 +#ifdef CONFIG_AUFS_SHWH
10879 + aufs_bindex_t wh_bindex;
10880 + unsigned char wh_type;
10882 + aufs_bindex_t wh_bindex;
10884 + /* caution: packed */
10885 + struct au_vdir_destr wh_str;
10888 +union au_vdir_deblk_p {
10889 + unsigned char *deblk;
10890 + struct au_vdir_de *de;
10894 + unsigned char **vd_deblk;
10895 + unsigned long vd_nblk;
10897 + unsigned long ul;
10898 + union au_vdir_deblk_p p;
10902 + unsigned int vd_deblk_sz;
10903 + unsigned long vd_jiffy;
10904 + struct rcu_head rcu;
10905 +} ____cacheline_aligned_in_smp;
10907 +/* ---------------------------------------------------------------------- */
10910 +extern const struct file_operations aufs_dir_fop;
10911 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10912 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10913 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10914 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10915 +int au_test_empty_lower(struct dentry *dentry);
10916 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10919 +unsigned int au_rdhash_est(loff_t sz);
10920 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10921 +void au_nhash_wh_free(struct au_nhash *whlist);
10922 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10924 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10925 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10926 + unsigned int d_type, aufs_bindex_t bindex,
10927 + unsigned char shwh);
10928 +void au_vdir_free(struct au_vdir *vdir);
10929 +int au_vdir_init(struct file *file);
10930 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10933 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10935 +#ifdef CONFIG_AUFS_RDU
10937 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10938 +#ifdef CONFIG_COMPAT
10939 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10940 + unsigned long arg);
10943 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10944 + unsigned int cmd, unsigned long arg)
10945 +#ifdef CONFIG_COMPAT
10946 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10947 + unsigned int cmd, unsigned long arg)
10951 +#endif /* __KERNEL__ */
10952 +#endif /* __AUFS_DIR_H__ */
10953 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10954 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10955 +++ linux/fs/aufs/dirren.c 2020-01-27 10:57:18.168871450 +0100
10957 +// SPDX-License-Identifier: GPL-2.0
10959 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10961 + * This program, aufs is free software; you can redistribute it and/or modify
10962 + * it under the terms of the GNU General Public License as published by
10963 + * the Free Software Foundation; either version 2 of the License, or
10964 + * (at your option) any later version.
10966 + * This program is distributed in the hope that it will be useful,
10967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10969 + * GNU General Public License for more details.
10971 + * You should have received a copy of the GNU General Public License
10972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10976 + * special handling in renaming a directory
10977 + * in order to support looking-up the before-renamed name on the lower readonly
10981 +#include <linux/byteorder/generic.h>
10984 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10988 + idx = au_dr_ihash(ent->dr_h_ino);
10989 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10992 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10995 + struct hlist_bl_head *hbl;
10998 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10999 + hbl = dr->dr_h_ino + i;
11000 + hlist_bl_lock(hbl);
11001 + ret &= hlist_bl_empty(hbl);
11002 + hlist_bl_unlock(hbl);
11008 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11010 + struct au_dr_hino *found, *ent;
11011 + struct hlist_bl_head *hbl;
11012 + struct hlist_bl_node *pos;
11016 + idx = au_dr_ihash(ino);
11017 + hbl = dr->dr_h_ino + idx;
11018 + hlist_bl_lock(hbl);
11019 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11020 + if (ent->dr_h_ino == ino) {
11024 + hlist_bl_unlock(hbl);
11029 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11030 + struct au_dr_hino *add_ent)
11033 + struct hlist_bl_head *hbl;
11034 + struct hlist_bl_node *pos;
11035 + struct au_dr_hino *ent;
11038 + idx = au_dr_ihash(ino);
11039 + hbl = dr->dr_h_ino + idx;
11040 +#if 0 /* debug print */
11042 + struct hlist_bl_node *tmp;
11044 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11045 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11048 + hlist_bl_lock(hbl);
11049 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11050 + if (ent->dr_h_ino == ino) {
11054 + if (!found && add_ent)
11055 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11056 + hlist_bl_unlock(hbl);
11058 + if (!found && add_ent)
11059 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11064 +void au_dr_hino_free(struct au_dr_br *dr)
11067 + struct hlist_bl_head *hbl;
11068 + struct hlist_bl_node *pos, *tmp;
11069 + struct au_dr_hino *ent;
11071 + /* SiMustWriteLock(sb); */
11073 + for (i = 0; i < AuDirren_NHASH; i++) {
11074 + hbl = dr->dr_h_ino + i;
11075 + /* no spinlock since sbinfo must be write-locked */
11076 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11077 + au_kfree_rcu(ent);
11078 + INIT_HLIST_BL_HEAD(hbl);
11082 +/* returns the number of inodes or an error */
11083 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11084 + struct file *hinofile)
11088 + loff_t pos, oldsize;
11090 + struct inode *hinoinode;
11091 + struct hlist_bl_head *hbl;
11092 + struct hlist_bl_node *n1, *n2;
11093 + struct au_dr_hino *ent;
11095 + SiMustWriteLock(sb);
11096 + AuDebugOn(!au_br_writable(br->br_perm));
11098 + hinoinode = file_inode(hinofile);
11099 + oldsize = i_size_read(hinoinode);
11103 + hbl = br->br_dirren.dr_h_ino;
11104 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11105 + /* no bit-lock since sbinfo must be write-locked */
11106 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11107 + AuDbg("hi%llu, %pD2\n",
11108 + (unsigned long long)ent->dr_h_ino, hinofile);
11109 + u64 = cpu_to_be64(ent->dr_h_ino);
11110 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11111 + if (ssz == sizeof(u64))
11114 + /* write error */
11115 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11122 + /* regardless the error */
11123 + if (pos < oldsize) {
11124 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11132 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11139 + struct au_dr_hino *ent;
11140 + struct inode *hinoinode;
11141 + struct hlist_bl_head *hbl;
11145 + hbl = dr->dr_h_ino;
11146 + hinoinode = file_inode(hinofile);
11147 + sz = i_size_read(hinoinode);
11148 + AuDebugOn(sz % sizeof(u64));
11149 + n = sz / sizeof(u64);
11151 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11152 + if (unlikely(ssz != sizeof(u64))) {
11153 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11160 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11166 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11167 + AuDbg("hi%llu, %pD2\n",
11168 + (unsigned long long)ent->dr_h_ino, hinofile);
11169 + hidx = au_dr_ihash(ent->dr_h_ino);
11170 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11172 + goto out; /* success */
11175 + au_dr_hino_free(dr);
11182 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11183 + * @path is a switch to distinguish load and store.
11185 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11186 + struct au_branch *br, const struct path *path)
11189 + unsigned char load, suspend;
11190 + struct file *hinofile;
11191 + struct au_hinode *hdir;
11192 + struct inode *dir, *delegated;
11193 + struct path hinopath;
11194 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11195 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11197 + AuDebugOn(bindex < 0 && !br);
11198 + AuDebugOn(bindex >= 0 && br);
11203 + br = au_sbr(sb, bindex);
11206 + path = &br->br_path;
11207 + AuDebugOn(!au_br_writable(br->br_perm));
11208 + if (unlikely(!au_br_writable(br->br_perm)))
11214 + dir = d_inode(sb->s_root);
11215 + hdir = au_hinode(au_ii(dir), bindex);
11216 + dir = hdir->hi_inode;
11217 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11219 + dir = d_inode(path->dentry);
11220 + inode_lock_nested(dir, AuLsc_I_CHILD);
11222 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11223 + err = PTR_ERR(hinopath.dentry);
11224 + if (IS_ERR(hinopath.dentry))
11228 + flags = O_RDONLY;
11230 + if (d_is_negative(hinopath.dentry))
11231 + goto out_dput; /* success */
11233 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11234 + if (d_is_positive(hinopath.dentry)) {
11235 + delegated = NULL;
11236 + err = vfsub_unlink(dir, &hinopath, &delegated,
11239 + if (unlikely(err))
11240 + pr_err("ignored err %d, %pd2\n",
11241 + err, hinopath.dentry);
11242 + if (unlikely(err == -EWOULDBLOCK))
11247 + } else if (!d_is_positive(hinopath.dentry)) {
11248 + err = vfsub_create(dir, &hinopath, 0600,
11249 + /*want_excl*/false);
11251 + if (unlikely(err))
11254 + flags = O_WRONLY;
11256 + hinopath.mnt = path->mnt;
11257 + hinofile = vfsub_dentry_open(&hinopath, flags);
11259 + au_hn_inode_unlock(hdir);
11261 + inode_unlock(dir);
11262 + dput(hinopath.dentry);
11263 + AuTraceErrPtr(hinofile);
11264 + if (IS_ERR(hinofile)) {
11265 + err = PTR_ERR(hinofile);
11270 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11272 + err = au_dr_hino_store(sb, br, hinofile);
11277 + dput(hinopath.dentry);
11280 + au_hn_inode_unlock(hdir);
11282 + inode_unlock(dir);
11288 +/* ---------------------------------------------------------------------- */
11290 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11293 + struct kstatfs kstfs;
11295 + struct dentry *dentry;
11296 + struct super_block *sb;
11298 + err = vfs_statfs((void *)path, &kstfs);
11300 + if (unlikely(err))
11303 + /* todo: support for UUID */
11305 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11306 + brid->type = AuBrid_FSID;
11307 + brid->fsid = kstfs.f_fsid;
11309 + dentry = path->dentry;
11310 + sb = dentry->d_sb;
11313 + brid->type = AuBrid_DEV;
11322 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11323 + const struct path *path)
11326 + struct au_dr_br *dr;
11327 + struct hlist_bl_head *hbl;
11329 + dr = &br->br_dirren;
11330 + hbl = dr->dr_h_ino;
11331 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11332 + INIT_HLIST_BL_HEAD(hbl);
11334 + err = au_dr_brid_init(&dr->dr_brid, path);
11335 + if (unlikely(err))
11338 + if (au_opt_test(au_mntflags(sb), DIRREN))
11339 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11346 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11351 + if (au_br_writable(br->br_perm))
11352 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11354 + au_dr_hino_free(&br->br_dirren);
11359 +/* ---------------------------------------------------------------------- */
11361 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11362 + char *buf, size_t sz)
11365 + unsigned int major, minor;
11369 + err = snprintf(p, sz, "%d_", brid->type);
11370 + AuDebugOn(err > sz);
11373 + switch (brid->type) {
11374 + case AuBrid_Unset:
11376 + case AuBrid_UUID:
11377 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11379 + case AuBrid_FSID:
11380 + err = snprintf(p, sz, "%08x-%08x",
11381 + brid->fsid.val[0], brid->fsid.val[1]);
11384 + major = MAJOR(brid->dev);
11385 + minor = MINOR(brid->dev);
11386 + if (major <= 0xff && minor <= 0xff)
11387 + err = snprintf(p, sz, "%02x%02x", major, minor);
11389 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11392 + AuDebugOn(err > sz);
11395 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11396 + AuDebugOn(err > sz);
11403 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11406 + struct dentry *br_dentry;
11407 + struct inode *br_inode;
11409 + br_dentry = au_br_dentry(br);
11410 + br_inode = d_inode(br_dentry);
11411 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11412 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11413 + AuDebugOn(rlen > len);
11418 +/* ---------------------------------------------------------------------- */
11421 + * from the given @h_dentry, construct drinfo at @*fdata.
11422 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11425 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11426 + struct dentry *h_dentry,
11427 + unsigned char *allocated)
11430 + struct au_drinfo_fdata *f, *p;
11431 + struct au_drinfo *drinfo;
11432 + struct inode *h_inode;
11433 + struct qstr *qname;
11437 + h_inode = d_inode(h_dentry);
11438 + qname = &h_dentry->d_name;
11439 + drinfo = &f->drinfo;
11440 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11441 + drinfo->oldnamelen = qname->len;
11442 + if (*allocated < sizeof(*f) + qname->len) {
11443 + v = roundup_pow_of_two(*allocated + qname->len);
11444 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11445 + if (unlikely(!p)) {
11453 + drinfo = &f->drinfo;
11455 + memcpy(drinfo->oldname, qname->name, qname->len);
11456 + AuDbg("i%llu, %.*s\n",
11457 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11458 + drinfo->oldname);
11465 +/* callers have to free the return value */
11466 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11468 + struct au_drinfo *ret, *drinfo;
11469 + struct au_drinfo_fdata fdata;
11474 + ret = ERR_PTR(-EIO);
11476 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11477 + if (unlikely(ssz != sizeof(fdata))) {
11478 + AuIOErr("ssz %zd, %u, %pD2\n",
11479 + ssz, (unsigned int)sizeof(fdata), file);
11483 + fdata.magic = ntohl((__force __be32)fdata.magic);
11484 + switch (fdata.magic) {
11485 + case AUFS_DRINFO_MAGIC_V1:
11488 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11489 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11493 + drinfo = &fdata.drinfo;
11494 + len = drinfo->oldnamelen;
11496 + AuIOErr("broken drinfo %pD2\n", file);
11501 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11502 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11503 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11504 + (unsigned long long)drinfo->ino,
11505 + (unsigned long long)h_ino, file);
11506 + goto out; /* success */
11509 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11510 + if (unlikely(!ret)) {
11511 + ret = ERR_PTR(-ENOMEM);
11512 + AuTraceErrPtr(ret);
11517 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11518 + if (unlikely(ssz != len)) {
11519 + au_kfree_rcu(ret);
11520 + ret = ERR_PTR(-EIO);
11521 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11525 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11531 +/* ---------------------------------------------------------------------- */
11533 +/* in order to be revertible */
11534 +struct au_drinfo_rev_elm {
11536 + struct dentry *info_dentry;
11537 + struct au_drinfo *info_last;
11540 +struct au_drinfo_rev {
11541 + unsigned char already;
11542 + aufs_bindex_t nelm;
11543 + struct au_drinfo_rev_elm elm[0];
11546 +/* todo: isn't it too large? */
11547 +struct au_drinfo_store {
11548 + struct path h_ppath;
11549 + struct dentry *h_dentry;
11550 + struct au_drinfo_fdata *fdata;
11551 + char *infoname; /* inside of whname, just after PFX */
11552 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11553 + aufs_bindex_t btgt, btail;
11554 + unsigned char no_sio,
11555 + allocated, /* current size of *fdata */
11556 + infonamelen, /* room size for p */
11557 + whnamelen, /* length of the generated name */
11558 + renameback; /* renamed back */
11561 +/* on rename(2) error, the caller should revert it using @elm */
11562 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11563 + struct au_drinfo_rev_elm *elm)
11568 + struct path infopath = {
11569 + .mnt = w->h_ppath.mnt
11571 + struct inode *h_dir, *h_inode, *delegated;
11572 + struct file *infofile;
11573 + struct qstr *qname;
11576 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11578 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11580 + AuTraceErrPtr(infopath.dentry);
11581 + if (IS_ERR(infopath.dentry)) {
11582 + err = PTR_ERR(infopath.dentry);
11587 + h_dir = d_inode(w->h_ppath.dentry);
11588 + if (elm && d_is_negative(infopath.dentry)) {
11589 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11591 + if (unlikely(err))
11593 + elm->created = 1;
11594 + elm->info_dentry = dget(infopath.dentry);
11597 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11598 + AuTraceErrPtr(infofile);
11599 + if (IS_ERR(infofile)) {
11600 + err = PTR_ERR(infofile);
11604 + h_inode = d_inode(infopath.dentry);
11605 + if (elm && i_size_read(h_inode)) {
11606 + h_inode = d_inode(w->h_dentry);
11607 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11608 + AuTraceErrPtr(elm->info_last);
11609 + if (IS_ERR(elm->info_last)) {
11610 + err = PTR_ERR(elm->info_last);
11611 + elm->info_last = NULL;
11612 + AuDebugOn(elm->info_dentry);
11617 + if (elm && w->renameback) {
11618 + delegated = NULL;
11619 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11621 + if (unlikely(err == -EWOULDBLOCK))
11627 + qname = &w->h_dentry->d_name;
11628 + len = sizeof(*w->fdata) + qname->len;
11630 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11631 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11632 + if (ssz == len) {
11633 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11634 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11635 + goto out_fput; /* success */
11640 + /* the caller should revert it using @elm */
11646 + dput(infopath.dentry);
11652 +struct au_call_drinfo_do_store_args {
11654 + struct au_drinfo_store *w;
11655 + struct au_drinfo_rev_elm *elm;
11658 +static void au_call_drinfo_do_store(void *args)
11660 + struct au_call_drinfo_do_store_args *a = args;
11662 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11665 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11666 + struct au_drinfo_rev_elm *elm)
11668 + int err, wkq_err;
11671 + err = au_drinfo_do_store(w, elm);
11673 + struct au_call_drinfo_do_store_args a = {
11678 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11679 + if (unlikely(wkq_err))
11687 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11688 + aufs_bindex_t btgt)
11692 + memset(w, 0, sizeof(*w));
11693 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11694 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11695 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11696 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11698 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11701 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11702 + if (unlikely(!w->fdata)) {
11706 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11713 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11715 + au_kfree_rcu(w->fdata);
11718 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11719 + struct au_drinfo_store *w)
11721 + struct au_drinfo_rev_elm *elm;
11722 + struct inode *h_dir, *delegated;
11724 + struct path infopath = {
11725 + .mnt = w->h_ppath.mnt
11728 + h_dir = d_inode(w->h_ppath.dentry);
11729 + IMustLock(h_dir);
11733 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11734 + AuDebugOn(elm->created && elm->info_last);
11735 + if (elm->created) {
11737 + delegated = NULL;
11738 + infopath.dentry = elm->info_dentry;
11739 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11742 + if (unlikely(err == -EWOULDBLOCK))
11744 + dput(elm->info_dentry);
11745 + } else if (elm->info_last) {
11747 + w->fdata->drinfo = *elm->info_last;
11748 + memcpy(w->fdata->drinfo.oldname,
11749 + elm->info_last->oldname,
11750 + elm->info_last->oldnamelen);
11751 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11752 + au_kfree_rcu(elm->info_last);
11754 + if (unlikely(err))
11755 + AuIOErr("%d, %s\n", err, w->whname);
11756 + /* go on even if err */
11760 +/* caller has to call au_dr_rename_fin() later */
11761 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11762 + struct qstr *dst_name, void *_rev)
11764 + int err, sz, nelm;
11765 + aufs_bindex_t bindex, btail;
11766 + struct au_drinfo_store work;
11767 + struct au_drinfo_rev *rev, **p;
11768 + struct au_drinfo_rev_elm *elm;
11769 + struct super_block *sb;
11770 + struct au_branch *br;
11771 + struct au_hinode *hdir;
11773 + err = au_drinfo_store_work_init(&work, btgt);
11775 + if (unlikely(err))
11779 + btail = au_dbtaildir(dentry);
11780 + nelm = btail - btgt;
11781 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11782 + rev = kcalloc(1, sz, GFP_NOFS);
11783 + if (unlikely(!rev)) {
11787 + rev->nelm = nelm;
11793 + sb = dentry->d_sb;
11794 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11795 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11796 + hdir = au_hi(d_inode(dentry), btgt);
11797 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11798 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11799 + work.h_dentry = au_h_dptr(dentry, bindex);
11800 + if (!work.h_dentry)
11803 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11804 + &work.allocated);
11806 + if (unlikely(err))
11809 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11810 + br = au_sbr(sb, bindex);
11811 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11812 + work.whnamelen += au_drinfo_name(br, work.infoname,
11813 + work.infonamelen);
11814 + AuDbg("whname %.*s, i%llu, %.*s\n",
11815 + work.whnamelen, work.whname,
11816 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11817 + work.fdata->drinfo.oldnamelen,
11818 + work.fdata->drinfo.oldname);
11820 + err = au_drinfo_store_sio(&work, elm);
11822 + if (unlikely(err))
11825 + if (unlikely(err)) {
11826 + /* revert all drinfo */
11827 + au_drinfo_store_rev(rev, &work);
11828 + au_kfree_try_rcu(rev);
11831 + au_hn_inode_unlock(hdir);
11834 + au_drinfo_store_work_fin(&work);
11839 +/* ---------------------------------------------------------------------- */
11841 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11842 + struct qstr *dst_name, void *_rev)
11844 + int err, already;
11846 + struct super_block *sb;
11847 + struct au_branch *br;
11848 + struct au_dr_br *dr;
11849 + struct dentry *h_dentry;
11850 + struct inode *h_inode;
11851 + struct au_dr_hino *ent;
11852 + struct au_drinfo_rev *rev, **p;
11854 + AuDbg("bindex %d\n", bindex);
11857 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11858 + if (unlikely(!ent))
11862 + br = au_sbr(sb, bindex);
11863 + dr = &br->br_dirren;
11864 + h_dentry = au_h_dptr(src, bindex);
11865 + h_inode = d_inode(h_dentry);
11866 + ino = h_inode->i_ino;
11867 + ent->dr_h_ino = ino;
11868 + already = au_dr_hino_test_add(dr, ino, ent);
11869 + AuDbg("b%d, hi%llu, already %d\n",
11870 + bindex, (unsigned long long)ino, already);
11872 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11877 + rev->already = already;
11878 + goto out; /* success */
11883 + au_dr_hino_del(dr, ent);
11884 + au_kfree_rcu(ent);
11891 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11893 + struct au_drinfo_rev *rev;
11894 + struct au_drinfo_rev_elm *elm;
11899 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11900 + dput(elm->info_dentry);
11901 + au_kfree_rcu(elm->info_last);
11903 + au_kfree_try_rcu(rev);
11906 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11909 + struct au_drinfo_store work;
11910 + struct au_drinfo_rev *rev = _rev;
11911 + struct super_block *sb;
11912 + struct au_branch *br;
11913 + struct inode *h_inode;
11914 + struct au_dr_br *dr;
11915 + struct au_dr_hino *ent;
11917 + err = au_drinfo_store_work_init(&work, btgt);
11918 + if (unlikely(err))
11922 + br = au_sbr(sb, btgt);
11923 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11924 + work.h_ppath.mnt = au_br_mnt(br);
11925 + au_drinfo_store_rev(rev, &work);
11926 + au_drinfo_store_work_fin(&work);
11927 + if (rev->already)
11930 + dr = &br->br_dirren;
11931 + h_inode = d_inode(work.h_ppath.dentry);
11932 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11934 + au_dr_hino_del(dr, ent);
11935 + au_kfree_rcu(ent);
11938 + au_kfree_try_rcu(rev);
11939 + if (unlikely(err))
11940 + pr_err("failed to remove dirren info\n");
11943 +/* ---------------------------------------------------------------------- */
11945 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11946 + char *whname, int whnamelen,
11947 + struct dentry **info_dentry)
11949 + struct au_drinfo *drinfo;
11951 + struct inode *h_dir;
11952 + struct path infopath;
11955 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11957 + *info_dentry = NULL;
11960 + h_dir = d_inode(h_ppath->dentry);
11961 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11962 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11964 + if (IS_ERR(infopath.dentry)) {
11965 + drinfo = (void *)infopath.dentry;
11969 + if (d_is_negative(infopath.dentry))
11970 + goto out_dput; /* success */
11972 + infopath.mnt = h_ppath->mnt;
11973 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11974 + inode_unlock_shared(h_dir);
11977 + drinfo = (void *)f;
11981 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11982 + if (IS_ERR_OR_NULL(drinfo))
11985 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11986 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11991 + dput(infopath.dentry);
11994 + inode_unlock_shared(h_dir);
11995 + AuTraceErrPtr(drinfo);
11999 +struct au_drinfo_do_load_args {
12000 + struct au_drinfo **drinfop;
12001 + struct path *h_ppath;
12004 + struct dentry **info_dentry;
12007 +static void au_call_drinfo_do_load(void *args)
12009 + struct au_drinfo_do_load_args *a = args;
12011 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12015 +struct au_drinfo_load {
12016 + struct path h_ppath;
12017 + struct qstr *qname;
12018 + unsigned char no_sio;
12020 + aufs_bindex_t ninfo;
12021 + struct au_drinfo **drinfo;
12024 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12025 + struct au_branch *br)
12027 + int err, wkq_err, whnamelen, e;
12028 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12029 + = AUFS_WH_DR_INFO_PFX;
12030 + struct au_drinfo *drinfo;
12031 + struct qstr oldname;
12032 + struct inode *h_dir, *delegated;
12033 + struct dentry *info_dentry;
12034 + struct path infopath;
12036 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12037 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12038 + sizeof(whname) - whnamelen);
12040 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12043 + struct au_drinfo_do_load_args args = {
12044 + .drinfop = &drinfo,
12045 + .h_ppath = &w->h_ppath,
12046 + .whname = whname,
12047 + .whnamelen = whnamelen,
12048 + .info_dentry = &info_dentry
12050 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12051 + if (unlikely(wkq_err))
12052 + drinfo = ERR_PTR(wkq_err);
12054 + err = PTR_ERR(drinfo);
12055 + if (IS_ERR_OR_NULL(drinfo))
12059 + oldname.len = drinfo->oldnamelen;
12060 + oldname.name = drinfo->oldname;
12061 + if (au_qstreq(w->qname, &oldname)) {
12062 + /* the name is renamed back */
12063 + au_kfree_rcu(drinfo);
12066 + infopath.dentry = info_dentry;
12067 + infopath.mnt = w->h_ppath.mnt;
12068 + h_dir = d_inode(w->h_ppath.dentry);
12069 + delegated = NULL;
12070 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12071 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12072 + inode_unlock(h_dir);
12074 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12075 + if (unlikely(e == -EWOULDBLOCK))
12078 + au_kfree_rcu(w->drinfo[bindex]);
12079 + w->drinfo[bindex] = drinfo;
12080 + dput(info_dentry);
12087 +/* ---------------------------------------------------------------------- */
12089 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12091 + struct au_drinfo **p = drinfo;
12094 + au_kfree_rcu(*drinfo++);
12095 + au_kfree_try_rcu(p);
12098 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12099 + aufs_bindex_t btgt)
12102 + struct au_drinfo_load w;
12103 + aufs_bindex_t bindex, bbot;
12104 + struct au_branch *br;
12105 + struct inode *h_dir;
12106 + struct au_dr_hino *ent;
12107 + struct super_block *sb;
12109 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12110 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12111 + AuLNPair(&lkup->whname), btgt);
12113 + sb = dentry->d_sb;
12114 + bbot = au_sbbot(sb);
12115 + w.ninfo = bbot + 1;
12116 + if (!lkup->dirren.drinfo) {
12117 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12118 + sizeof(*lkup->dirren.drinfo),
12120 + if (unlikely(!lkup->dirren.drinfo)) {
12124 + lkup->dirren.ninfo = w.ninfo;
12126 + w.drinfo = lkup->dirren.drinfo;
12127 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12128 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12129 + AuDebugOn(!w.h_ppath.dentry);
12130 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12131 + w.qname = &dentry->d_name;
12134 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12135 + br = au_sbr(sb, bindex);
12136 + err = au_drinfo_load(&w, bindex, br);
12137 + if (unlikely(err))
12139 + if (w.drinfo[bindex])
12143 + br = au_sbr(sb, btgt);
12144 + h_dir = d_inode(w.h_ppath.dentry);
12145 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12147 + au_dr_hino_del(&br->br_dirren, ent);
12148 + au_kfree_rcu(ent);
12150 + goto out; /* success */
12153 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12154 + lkup->dirren.ninfo = 0;
12155 + lkup->dirren.drinfo = NULL;
12161 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12163 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12166 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12169 + struct au_drinfo *drinfo;
12172 + if (!lkup->dirren.drinfo)
12174 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12175 + drinfo = lkup->dirren.drinfo[btgt];
12179 + au_kfree_try_rcu(lkup->whname.name);
12180 + lkup->whname.name = NULL;
12181 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12182 + lkup->dirren.dr_name.name = drinfo->oldname;
12183 + lkup->name = &lkup->dirren.dr_name;
12184 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12186 + AuDbg("name %.*s, whname %.*s, b%d\n",
12187 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12195 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12199 + struct au_drinfo *drinfo;
12202 + if (!lkup->dirren.drinfo)
12204 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12205 + drinfo = lkup->dirren.drinfo[bindex];
12209 + match = (drinfo->ino == h_ino);
12210 + AuDbg("match %d\n", match);
12216 +/* ---------------------------------------------------------------------- */
12218 +int au_dr_opt_set(struct super_block *sb)
12221 + aufs_bindex_t bindex, bbot;
12222 + struct au_branch *br;
12225 + bbot = au_sbbot(sb);
12226 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12227 + br = au_sbr(sb, bindex);
12228 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12234 +int au_dr_opt_flush(struct super_block *sb)
12237 + aufs_bindex_t bindex, bbot;
12238 + struct au_branch *br;
12241 + bbot = au_sbbot(sb);
12242 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12243 + br = au_sbr(sb, bindex);
12244 + if (au_br_writable(br->br_perm))
12245 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12251 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12254 + aufs_bindex_t bindex, bbot;
12255 + struct au_branch *br;
12259 + err = au_dr_opt_flush(sb);
12260 + if (unlikely(err))
12264 + bbot = au_sbbot(sb);
12265 + for (bindex = 0; bindex <= bbot; bindex++) {
12266 + br = au_sbr(sb, bindex);
12267 + au_dr_hino_free(&br->br_dirren);
12273 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12274 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12275 +++ linux/fs/aufs/dirren.h 2020-01-27 10:57:18.168871450 +0100
12277 +/* SPDX-License-Identifier: GPL-2.0 */
12279 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12281 + * This program, aufs is free software; you can redistribute it and/or modify
12282 + * it under the terms of the GNU General Public License as published by
12283 + * the Free Software Foundation; either version 2 of the License, or
12284 + * (at your option) any later version.
12286 + * This program is distributed in the hope that it will be useful,
12287 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12288 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12289 + * GNU General Public License for more details.
12291 + * You should have received a copy of the GNU General Public License
12292 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12296 + * renamed dir info
12299 +#ifndef __AUFS_DIRREN_H__
12300 +#define __AUFS_DIRREN_H__
12304 +#include <linux/dcache.h>
12305 +#include <linux/statfs.h>
12306 +#include <linux/uuid.h>
12309 +#define AuDirren_NHASH 100
12311 +#ifdef CONFIG_AUFS_DIRREN
12312 +enum au_brid_type {
12319 +struct au_dr_brid {
12320 + enum au_brid_type type;
12322 + uuid_t uuid; /* unimplemented yet */
12328 +/* 20 is the max digits length of ulong 64 */
12329 +/* brid-type "_" uuid "_" inum */
12330 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12331 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12333 +struct au_dr_hino {
12334 + struct hlist_bl_node dr_hnode;
12339 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12340 + struct au_dr_brid dr_brid;
12343 +struct au_dr_lookup {
12344 + /* dr_name is pointed by struct au_do_lookup_args.name */
12345 + struct qstr dr_name; /* subset of dr_info */
12346 + aufs_bindex_t ninfo;
12347 + struct au_drinfo **drinfo;
12350 +struct au_dr_hino;
12352 +struct au_dr_br { };
12353 +struct au_dr_lookup { };
12356 +/* ---------------------------------------------------------------------- */
12359 +struct au_do_lookup_args;
12361 +#ifdef CONFIG_AUFS_DIRREN
12362 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12363 + struct au_dr_hino *add_ent);
12364 +void au_dr_hino_free(struct au_dr_br *dr);
12365 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12366 + const struct path *path);
12367 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12368 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12369 + struct qstr *dst_name, void *_rev);
12370 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12371 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12372 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12373 + aufs_bindex_t bindex);
12374 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12375 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12377 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12378 +int au_dr_opt_set(struct super_block *sb);
12379 +int au_dr_opt_flush(struct super_block *sb);
12380 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12382 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12383 + struct au_dr_hino *add_ent);
12384 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12385 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12386 + const struct path *path);
12387 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12388 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12389 + struct qstr *dst_name, void *_rev);
12390 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12391 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12393 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12394 + aufs_bindex_t bindex);
12395 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12396 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12397 + aufs_bindex_t bindex, ino_t h_ino);
12398 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12399 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12400 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12401 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12404 +/* ---------------------------------------------------------------------- */
12406 +#ifdef CONFIG_AUFS_DIRREN
12407 +static inline int au_dr_ihash(ino_t h_ino)
12409 + return h_ino % AuDirren_NHASH;
12412 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12415 +#endif /* __KERNEL__ */
12416 +#endif /* __AUFS_DIRREN_H__ */
12417 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12418 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12419 +++ linux/fs/aufs/dynop.c 2020-01-27 10:57:18.168871450 +0100
12421 +// SPDX-License-Identifier: GPL-2.0
12423 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12425 + * This program, aufs is free software; you can redistribute it and/or modify
12426 + * it under the terms of the GNU General Public License as published by
12427 + * the Free Software Foundation; either version 2 of the License, or
12428 + * (at your option) any later version.
12430 + * This program is distributed in the hope that it will be useful,
12431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12433 + * GNU General Public License for more details.
12435 + * You should have received a copy of the GNU General Public License
12436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12440 + * dynamically customizable operations for regular files
12445 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12448 + * How large will these lists be?
12449 + * Usually just a few elements, 20-30 at most for each, I guess.
12451 +static struct hlist_bl_head dynop[AuDyLast];
12453 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12454 + const void *h_op)
12456 + struct au_dykey *key, *tmp;
12457 + struct hlist_bl_node *pos;
12460 + hlist_bl_lock(hbl);
12461 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12462 + if (tmp->dk_op.dy_hop == h_op) {
12463 + if (kref_get_unless_zero(&tmp->dk_kref))
12467 + hlist_bl_unlock(hbl);
12472 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12474 + struct au_dykey **k, *found;
12475 + const void *h_op = key->dk_op.dy_hop;
12479 + k = br->br_dykey;
12480 + for (i = 0; i < AuBrDynOp; i++)
12482 + if (k[i]->dk_op.dy_hop == h_op) {
12489 + spin_lock(&br->br_dykey_lock);
12490 + for (; i < AuBrDynOp; i++)
12492 + if (k[i]->dk_op.dy_hop == h_op) {
12500 + spin_unlock(&br->br_dykey_lock);
12501 + BUG_ON(i == AuBrDynOp); /* expand the array */
12507 +/* kref_get() if @key is already added */
12508 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12510 + struct au_dykey *tmp, *found;
12511 + struct hlist_bl_node *pos;
12512 + const void *h_op = key->dk_op.dy_hop;
12515 + hlist_bl_lock(hbl);
12516 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12517 + if (tmp->dk_op.dy_hop == h_op) {
12518 + if (kref_get_unless_zero(&tmp->dk_kref))
12523 + hlist_bl_add_head(&key->dk_hnode, hbl);
12524 + hlist_bl_unlock(hbl);
12531 +static void dy_free_rcu(struct rcu_head *rcu)
12533 + struct au_dykey *key;
12535 + key = container_of(rcu, struct au_dykey, dk_rcu);
12540 +static void dy_free(struct kref *kref)
12542 + struct au_dykey *key;
12543 + struct hlist_bl_head *hbl;
12545 + key = container_of(kref, struct au_dykey, dk_kref);
12546 + hbl = dynop + key->dk_op.dy_type;
12547 + au_hbl_del(&key->dk_hnode, hbl);
12548 + call_rcu(&key->dk_rcu, dy_free_rcu);
12551 +void au_dy_put(struct au_dykey *key)
12553 + kref_put(&key->dk_kref, dy_free);
12556 +/* ---------------------------------------------------------------------- */
12558 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12560 +#ifdef CONFIG_AUFS_DEBUG
12561 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12562 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12564 +#define DyDbgDeclare(cnt) do {} while (0)
12565 +#define DyDbgInc(cnt) do {} while (0)
12568 +#define DySet(func, dst, src, h_op, h_sb) do { \
12570 + if (h_op->func) { \
12572 + dst.func = src.func; \
12574 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12578 +#define DySetForce(func, dst, src) do { \
12579 + AuDebugOn(!src.func); \
12581 + dst.func = src.func; \
12584 +#define DySetAop(func) \
12585 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12586 +#define DySetAopForce(func) \
12587 + DySetForce(func, dyaop->da_op, aufs_aop)
12589 +static void dy_aop(struct au_dykey *key, const void *h_op,
12590 + struct super_block *h_sb __maybe_unused)
12592 + struct au_dyaop *dyaop = (void *)key;
12593 + const struct address_space_operations *h_aop = h_op;
12594 + DyDbgDeclare(cnt);
12596 + AuDbg("%s\n", au_sbtype(h_sb));
12598 + DySetAop(writepage);
12599 + DySetAopForce(readpage); /* force */
12600 + DySetAop(writepages);
12601 + DySetAop(set_page_dirty);
12602 + DySetAop(readpages);
12603 + DySetAop(write_begin);
12604 + DySetAop(write_end);
12606 + DySetAop(invalidatepage);
12607 + DySetAop(releasepage);
12608 + DySetAop(freepage);
12609 + /* this one will be changed according to an aufs mount option */
12610 + DySetAop(direct_IO);
12611 + DySetAop(migratepage);
12612 + DySetAop(isolate_page);
12613 + DySetAop(putback_page);
12614 + DySetAop(launder_page);
12615 + DySetAop(is_partially_uptodate);
12616 + DySetAop(is_dirty_writeback);
12617 + DySetAop(error_remove_page);
12618 + DySetAop(swap_activate);
12619 + DySetAop(swap_deactivate);
12621 + DyDbgSize(cnt, *h_aop);
12624 +/* ---------------------------------------------------------------------- */
12626 +static void dy_bug(struct kref *kref)
12631 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12633 + struct au_dykey *key, *old;
12634 + struct hlist_bl_head *hbl;
12637 + void (*set)(struct au_dykey *key, const void *h_op,
12638 + struct super_block *h_sb __maybe_unused);
12640 + static const struct op a[] = {
12642 + .sz = sizeof(struct au_dyaop),
12646 + const struct op *p;
12648 + hbl = dynop + op->dy_type;
12649 + key = dy_gfind_get(hbl, op->dy_hop);
12651 + goto out_add; /* success */
12653 + p = a + op->dy_type;
12654 + key = kzalloc(p->sz, GFP_NOFS);
12655 + if (unlikely(!key)) {
12656 + key = ERR_PTR(-ENOMEM);
12660 + key->dk_op.dy_hop = op->dy_hop;
12661 + kref_init(&key->dk_kref);
12662 + p->set(key, op->dy_hop, au_br_sb(br));
12663 + old = dy_gadd(hbl, key);
12665 + au_kfree_rcu(key);
12670 + old = dy_bradd(br, key);
12672 + /* its ref-count should never be zero here */
12673 + kref_put(&key->dk_kref, dy_bug);
12678 +/* ---------------------------------------------------------------------- */
12680 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12681 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12682 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12683 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12684 + * See the aufs manual in detail.
12686 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12689 + dyaop->da_op.direct_IO = NULL;
12691 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12694 +static struct au_dyaop *dy_aget(struct au_branch *br,
12695 + const struct address_space_operations *h_aop,
12698 + struct au_dyaop *dyaop;
12699 + struct au_dynop op;
12701 + op.dy_type = AuDy_AOP;
12702 + op.dy_haop = h_aop;
12703 + dyaop = (void *)dy_get(&op, br);
12704 + if (IS_ERR(dyaop))
12706 + dy_adx(dyaop, do_dx);
12712 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12713 + struct inode *h_inode)
12716 + struct super_block *sb;
12717 + struct au_branch *br;
12718 + struct au_dyaop *dyaop;
12720 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12721 + IiMustWriteLock(inode);
12723 + sb = inode->i_sb;
12724 + br = au_sbr(sb, bindex);
12725 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12726 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12727 + err = PTR_ERR(dyaop);
12728 + if (IS_ERR(dyaop))
12729 + /* unnecessary to call dy_fput() */
12733 + inode->i_mapping->a_ops = &dyaop->da_op;
12740 + * Is it safe to replace a_ops during the inode/file is in operation?
12741 + * Yes, I hope so.
12743 +int au_dy_irefresh(struct inode *inode)
12746 + aufs_bindex_t btop;
12747 + struct inode *h_inode;
12750 + if (S_ISREG(inode->i_mode)) {
12751 + btop = au_ibtop(inode);
12752 + h_inode = au_h_iptr(inode, btop);
12753 + err = au_dy_iaop(inode, btop, h_inode);
12758 +void au_dy_arefresh(int do_dx)
12760 + struct hlist_bl_head *hbl;
12761 + struct hlist_bl_node *pos;
12762 + struct au_dykey *key;
12764 + hbl = dynop + AuDy_AOP;
12765 + hlist_bl_lock(hbl);
12766 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12767 + dy_adx((void *)key, do_dx);
12768 + hlist_bl_unlock(hbl);
12771 +/* ---------------------------------------------------------------------- */
12773 +void __init au_dy_init(void)
12777 + for (i = 0; i < AuDyLast; i++)
12778 + INIT_HLIST_BL_HEAD(dynop + i);
12781 +void au_dy_fin(void)
12785 + for (i = 0; i < AuDyLast; i++)
12786 + WARN_ON(!hlist_bl_empty(dynop + i));
12788 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12789 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12790 +++ linux/fs/aufs/dynop.h 2020-01-27 10:57:18.168871450 +0100
12792 +/* SPDX-License-Identifier: GPL-2.0 */
12794 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12796 + * This program, aufs is free software; you can redistribute it and/or modify
12797 + * it under the terms of the GNU General Public License as published by
12798 + * the Free Software Foundation; either version 2 of the License, or
12799 + * (at your option) any later version.
12801 + * This program is distributed in the hope that it will be useful,
12802 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12803 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12804 + * GNU General Public License for more details.
12806 + * You should have received a copy of the GNU General Public License
12807 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12811 + * dynamically customizable operations (for regular files only)
12814 +#ifndef __AUFS_DYNOP_H__
12815 +#define __AUFS_DYNOP_H__
12819 +#include <linux/fs.h>
12820 +#include <linux/kref.h>
12822 +enum {AuDy_AOP, AuDyLast};
12827 + const void *dy_hop;
12828 + const struct address_space_operations *dy_haop;
12834 + struct hlist_bl_node dk_hnode;
12835 + struct rcu_head dk_rcu;
12837 + struct au_dynop dk_op;
12840 + * during I am in the branch local array, kref is gotten. when the
12841 + * branch is removed, kref is put.
12843 + struct kref dk_kref;
12846 +/* stop unioning since their sizes are very different from each other */
12848 + struct au_dykey da_key;
12849 + struct address_space_operations da_op; /* not const */
12851 +/* make sure that 'struct au_dykey *' can be any type */
12852 +static_assert(!offsetof(struct au_dyaop, da_key));
12854 +/* ---------------------------------------------------------------------- */
12858 +void au_dy_put(struct au_dykey *key);
12859 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12860 + struct inode *h_inode);
12861 +int au_dy_irefresh(struct inode *inode);
12862 +void au_dy_arefresh(int do_dio);
12864 +void __init au_dy_init(void);
12865 +void au_dy_fin(void);
12867 +#endif /* __KERNEL__ */
12868 +#endif /* __AUFS_DYNOP_H__ */
12869 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12870 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12871 +++ linux/fs/aufs/export.c 2020-01-27 10:57:18.168871450 +0100
12873 +// SPDX-License-Identifier: GPL-2.0
12875 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12877 + * This program, aufs is free software; you can redistribute it and/or modify
12878 + * it under the terms of the GNU General Public License as published by
12879 + * the Free Software Foundation; either version 2 of the License, or
12880 + * (at your option) any later version.
12882 + * This program is distributed in the hope that it will be useful,
12883 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12884 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12885 + * GNU General Public License for more details.
12887 + * You should have received a copy of the GNU General Public License
12888 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12895 +#include <linux/exportfs.h>
12896 +#include <linux/fs_struct.h>
12897 +#include <linux/namei.h>
12898 +#include <linux/nsproxy.h>
12899 +#include <linux/random.h>
12900 +#include <linux/writeback.h>
12904 +#ifdef CONFIG_AUFS_INO_T_64
12912 +static ino_t decode_ino(__u32 *a)
12916 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12918 +#ifdef CONFIG_AUFS_INO_T_64
12924 +static void encode_ino(__u32 *a, ino_t ino)
12930 +#ifdef CONFIG_AUFS_INO_T_64
12935 +/* NFS file handle */
12939 +#ifdef CONFIG_AUFS_INO_T_64
12940 + /* support 64bit inode number */
12953 + Fh_ino = Fh_ino1,
12954 + Fh_dir_ino = Fh_dir_ino1
12957 +static int au_test_anon(struct dentry *dentry)
12959 + /* note: read d_flags without d_lock */
12960 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12963 +int au_test_nfsd(void)
12966 + struct task_struct *tsk = current;
12967 + char comm[sizeof(tsk->comm)];
12970 + if (tsk->flags & PF_KTHREAD) {
12971 + get_task_comm(comm, tsk);
12972 + ret = !strcmp(comm, "nfsd");
12978 +/* ---------------------------------------------------------------------- */
12979 +/* inode generation external table */
12981 +void au_xigen_inc(struct inode *inode)
12986 + struct super_block *sb;
12987 + struct au_sbinfo *sbinfo;
12989 + sb = inode->i_sb;
12990 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12992 + sbinfo = au_sbi(sb);
12993 + pos = inode->i_ino;
12994 + pos *= sizeof(igen);
12995 + igen = inode->i_generation + 1;
12996 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
12997 + sizeof(igen), &pos);
12998 + if (sz == sizeof(igen))
12999 + return; /* success */
13001 + if (unlikely(sz >= 0))
13002 + AuIOErr("xigen error (%zd)\n", sz);
13005 +int au_xigen_new(struct inode *inode)
13010 + struct super_block *sb;
13011 + struct au_sbinfo *sbinfo;
13012 + struct file *file;
13015 + /* todo: dirty, at mount time */
13016 + if (inode->i_ino == AUFS_ROOT_INO)
13018 + sb = inode->i_sb;
13019 + SiMustAnyLock(sb);
13020 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13024 + pos = inode->i_ino;
13025 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13026 + AuIOErr1("too large i%lld\n", pos);
13029 + pos *= sizeof(inode->i_generation);
13032 + sbinfo = au_sbi(sb);
13033 + file = sbinfo->si_xigen;
13036 + if (vfsub_f_size_read(file)
13037 + < pos + sizeof(inode->i_generation)) {
13038 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13039 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13040 + sizeof(inode->i_generation), &pos);
13042 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13043 + sizeof(inode->i_generation), &pos);
13044 + if (sz == sizeof(inode->i_generation))
13045 + goto out; /* success */
13048 + if (unlikely(sz >= 0)) {
13050 + AuIOErr("xigen error (%zd)\n", sz);
13057 +int au_xigen_set(struct super_block *sb, struct path *path)
13060 + struct au_sbinfo *sbinfo;
13061 + struct file *file;
13063 + SiMustWriteLock(sb);
13065 + sbinfo = au_sbi(sb);
13066 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13067 + err = PTR_ERR(file);
13068 + if (IS_ERR(file))
13071 + if (sbinfo->si_xigen)
13072 + fput(sbinfo->si_xigen);
13073 + sbinfo->si_xigen = file;
13080 +void au_xigen_clr(struct super_block *sb)
13082 + struct au_sbinfo *sbinfo;
13084 + SiMustWriteLock(sb);
13086 + sbinfo = au_sbi(sb);
13087 + if (sbinfo->si_xigen) {
13088 + fput(sbinfo->si_xigen);
13089 + sbinfo->si_xigen = NULL;
13093 +/* ---------------------------------------------------------------------- */
13095 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13098 + struct dentry *dentry, *d;
13099 + struct inode *inode;
13100 + unsigned int sigen;
13103 + inode = ilookup(sb, ino);
13107 + dentry = ERR_PTR(-ESTALE);
13108 + sigen = au_sigen(sb);
13109 + if (unlikely(au_is_bad_inode(inode)
13110 + || IS_DEADDIR(inode)
13111 + || sigen != au_iigen(inode, NULL)))
13115 + if (!dir_ino || S_ISDIR(inode->i_mode))
13116 + dentry = d_find_alias(inode);
13118 + spin_lock(&inode->i_lock);
13119 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13120 + spin_lock(&d->d_lock);
13121 + if (!au_test_anon(d)
13122 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13123 + dentry = dget_dlock(d);
13124 + spin_unlock(&d->d_lock);
13127 + spin_unlock(&d->d_lock);
13129 + spin_unlock(&inode->i_lock);
13131 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13132 + /* need to refresh */
13140 + AuTraceErrPtr(dentry);
13144 +/* ---------------------------------------------------------------------- */
13146 +/* todo: dirty? */
13147 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13149 +struct au_compare_mnt_args {
13151 + struct super_block *sb;
13154 + struct vfsmount *mnt;
13157 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13159 + struct au_compare_mnt_args *a = arg;
13161 + if (mnt->mnt_sb != a->sb)
13163 + a->mnt = mntget(mnt);
13167 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13170 + struct path root;
13171 + struct au_compare_mnt_args args = {
13175 + get_fs_root(current->fs, &root);
13177 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13178 + rcu_read_unlock();
13181 + AuDebugOn(!args.mnt);
13185 +struct au_nfsd_si_lock {
13186 + unsigned int sigen;
13187 + aufs_bindex_t bindex, br_id;
13188 + unsigned char force_lock;
13191 +static int si_nfsd_read_lock(struct super_block *sb,
13192 + struct au_nfsd_si_lock *nsi_lock)
13195 + aufs_bindex_t bindex;
13197 + si_read_lock(sb, AuLock_FLUSH);
13199 + /* branch id may be wrapped around */
13201 + bindex = au_br_index(sb, nsi_lock->br_id);
13202 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13203 + goto out; /* success */
13207 + if (!nsi_lock->force_lock)
13208 + si_read_unlock(sb);
13211 + nsi_lock->bindex = bindex;
13215 +struct find_name_by_ino {
13216 + struct dir_context ctx;
13217 + int called, found;
13224 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13225 + loff_t offset, u64 ino, unsigned int d_type)
13227 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13231 + if (a->ino != ino)
13234 + memcpy(a->name, name, namelen);
13235 + a->namelen = namelen;
13240 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13241 + struct au_nfsd_si_lock *nsi_lock)
13243 + struct dentry *dentry, *parent;
13244 + struct file *file;
13245 + struct inode *dir;
13246 + struct find_name_by_ino arg = {
13248 + .actor = find_name_by_ino
13253 + parent = path->dentry;
13255 + si_read_unlock(parent->d_sb);
13256 + file = vfsub_dentry_open(path, au_dir_roflags);
13257 + dentry = (void *)file;
13258 + if (IS_ERR(file))
13261 + dentry = ERR_PTR(-ENOMEM);
13262 + arg.name = (void *)__get_free_page(GFP_NOFS);
13263 + if (unlikely(!arg.name))
13270 + err = vfsub_iterate_dir(file, &arg.ctx);
13271 + } while (!err && !arg.found && arg.called);
13272 + dentry = ERR_PTR(err);
13273 + if (unlikely(err))
13275 + /* instead of ENOENT */
13276 + dentry = ERR_PTR(-ESTALE);
13280 + /* do not call vfsub_lkup_one() */
13281 + dir = d_inode(parent);
13282 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13283 + AuTraceErrPtr(dentry);
13284 + if (IS_ERR(dentry))
13286 + AuDebugOn(au_test_anon(dentry));
13287 + if (unlikely(d_really_is_negative(dentry))) {
13289 + dentry = ERR_PTR(-ENOENT);
13293 + free_page((unsigned long)arg.name);
13297 + if (unlikely(nsi_lock
13298 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13299 + if (!IS_ERR(dentry)) {
13301 + dentry = ERR_PTR(-ESTALE);
13303 + AuTraceErrPtr(dentry);
13307 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13309 + struct au_nfsd_si_lock *nsi_lock)
13311 + struct dentry *dentry;
13312 + struct path path;
13314 + if (dir_ino != AUFS_ROOT_INO) {
13315 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13316 + dentry = path.dentry;
13317 + if (!path.dentry || IS_ERR(path.dentry))
13319 + AuDebugOn(au_test_anon(path.dentry));
13321 + path.dentry = dget(sb->s_root);
13323 + path.mnt = au_mnt_get(sb);
13324 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13328 + AuTraceErrPtr(dentry);
13332 +/* ---------------------------------------------------------------------- */
13334 +static int h_acceptable(void *expv, struct dentry *dentry)
13339 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13340 + char *buf, int len, struct super_block *sb)
13344 + struct path path;
13346 + p = d_path(h_rootpath, buf, len);
13351 + path.mnt = h_rootpath->mnt;
13352 + path.dentry = h_parent;
13353 + p = d_path(&path, buf, len);
13359 + path.mnt = au_mnt_get(sb);
13360 + path.dentry = sb->s_root;
13361 + p = d_path(&path, buf, len - strlen(p));
13362 + mntput(path.mnt);
13366 + p[strlen(p)] = '/';
13369 + AuTraceErrPtr(p);
13374 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13375 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13377 + struct dentry *dentry, *h_parent, *root;
13378 + struct super_block *h_sb;
13379 + char *pathname, *p;
13380 + struct vfsmount *h_mnt;
13381 + struct au_branch *br;
13383 + struct path path;
13385 + br = au_sbr(sb, nsi_lock->bindex);
13386 + h_mnt = au_br_mnt(br);
13387 + h_sb = h_mnt->mnt_sb;
13388 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13390 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13391 + fh_len - Fh_tail, fh[Fh_h_type],
13392 + h_acceptable, /*context*/NULL);
13394 + dentry = h_parent;
13395 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13396 + AuWarn1("%s decode_fh failed, %ld\n",
13397 + au_sbtype(h_sb), PTR_ERR(h_parent));
13401 + if (unlikely(au_test_anon(h_parent))) {
13402 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13403 + au_sbtype(h_sb));
13404 + goto out_h_parent;
13407 + dentry = ERR_PTR(-ENOMEM);
13408 + pathname = (void *)__get_free_page(GFP_NOFS);
13409 + if (unlikely(!pathname))
13410 + goto out_h_parent;
13412 + root = sb->s_root;
13413 + path.mnt = h_mnt;
13414 + di_read_lock_parent(root, !AuLock_IR);
13415 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13416 + di_read_unlock(root, !AuLock_IR);
13417 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13418 + dentry = (void *)p;
13420 + goto out_pathname;
13422 + si_read_unlock(sb);
13423 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13424 + dentry = ERR_PTR(err);
13425 + if (unlikely(err))
13428 + dentry = ERR_PTR(-ENOENT);
13429 + AuDebugOn(au_test_anon(path.dentry));
13430 + if (unlikely(d_really_is_negative(path.dentry)))
13433 + if (ino != d_inode(path.dentry)->i_ino)
13434 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13436 + dentry = dget(path.dentry);
13441 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13442 + if (!IS_ERR(dentry)) {
13444 + dentry = ERR_PTR(-ESTALE);
13447 + free_page((unsigned long)pathname);
13451 + AuTraceErrPtr(dentry);
13455 +/* ---------------------------------------------------------------------- */
13457 +static struct dentry *
13458 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13461 + struct dentry *dentry;
13462 + __u32 *fh = fid->raw;
13463 + struct au_branch *br;
13464 + ino_t ino, dir_ino;
13465 + struct au_nfsd_si_lock nsi_lock = {
13469 + dentry = ERR_PTR(-ESTALE);
13470 + /* it should never happen, but the file handle is unreliable */
13471 + if (unlikely(fh_len < Fh_tail))
13473 + nsi_lock.sigen = fh[Fh_sigen];
13474 + nsi_lock.br_id = fh[Fh_br_id];
13476 + /* branch id may be wrapped around */
13478 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13480 + nsi_lock.force_lock = 1;
13482 + /* is this inode still cached? */
13483 + ino = decode_ino(fh + Fh_ino);
13484 + /* it should never happen */
13485 + if (unlikely(ino == AUFS_ROOT_INO))
13488 + dir_ino = decode_ino(fh + Fh_dir_ino);
13489 + dentry = decode_by_ino(sb, ino, dir_ino);
13490 + if (IS_ERR(dentry))
13495 + /* is the parent dir cached? */
13496 + br = au_sbr(sb, nsi_lock.bindex);
13497 + au_lcnt_inc(&br->br_nfiles);
13498 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13499 + if (IS_ERR(dentry))
13504 + /* lookup path */
13505 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13506 + if (IS_ERR(dentry))
13508 + if (unlikely(!dentry))
13509 + /* todo?: make it ESTALE */
13513 + if (!au_digen_test(dentry, au_sigen(sb))
13514 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13515 + goto out_unlock; /* success */
13518 + dentry = ERR_PTR(-ESTALE);
13521 + au_lcnt_dec(&br->br_nfiles);
13522 + si_read_unlock(sb);
13524 + AuTraceErrPtr(dentry);
13528 +#if 0 /* reserved for future use */
13529 +/* support subtreecheck option */
13530 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13531 + int fh_len, int fh_type)
13533 + struct dentry *parent;
13534 + __u32 *fh = fid->raw;
13537 + dir_ino = decode_ino(fh + Fh_dir_ino);
13538 + parent = decode_by_ino(sb, dir_ino, 0);
13539 + if (IS_ERR(parent))
13542 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13543 + dir_ino, fh, fh_len);
13546 + AuTraceErrPtr(parent);
13551 +/* ---------------------------------------------------------------------- */
13553 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13554 + struct inode *dir)
13557 + aufs_bindex_t bindex;
13558 + struct super_block *sb, *h_sb;
13559 + struct dentry *dentry, *parent, *h_parent;
13560 + struct inode *h_dir;
13561 + struct au_branch *br;
13564 + if (unlikely(*max_len <= Fh_tail)) {
13565 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13569 + err = FILEID_ROOT;
13570 + if (inode->i_ino == AUFS_ROOT_INO) {
13571 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13576 + sb = inode->i_sb;
13577 + err = si_read_lock(sb, AuLock_FLUSH);
13578 + if (unlikely(err))
13581 +#ifdef CONFIG_AUFS_DEBUG
13582 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13583 + AuWarn1("NFS-exporting requires xino\n");
13587 + ii_read_lock_child(inode);
13588 + bindex = au_ibtop(inode);
13590 + dentry = d_find_any_alias(inode);
13591 + if (unlikely(!dentry))
13593 + AuDebugOn(au_test_anon(dentry));
13594 + parent = dget_parent(dentry);
13596 + if (unlikely(!parent))
13598 + if (d_really_is_positive(parent))
13599 + dir = d_inode(parent);
13602 + ii_read_lock_parent(dir);
13603 + h_dir = au_h_iptr(dir, bindex);
13604 + ii_read_unlock(dir);
13605 + if (unlikely(!h_dir))
13607 + h_parent = d_find_any_alias(h_dir);
13608 + if (unlikely(!h_parent))
13609 + goto out_hparent;
13612 + br = au_sbr(sb, bindex);
13613 + h_sb = au_br_sb(br);
13614 + if (unlikely(!h_sb->s_export_op)) {
13615 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13616 + goto out_hparent;
13619 + fh[Fh_br_id] = br->br_id;
13620 + fh[Fh_sigen] = au_sigen(sb);
13621 + encode_ino(fh + Fh_ino, inode->i_ino);
13622 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13623 + fh[Fh_igen] = inode->i_generation;
13625 + *max_len -= Fh_tail;
13626 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13628 + /*connectable or subtreecheck*/0);
13629 + err = fh[Fh_h_type];
13630 + *max_len += Fh_tail;
13631 + /* todo: macros? */
13632 + if (err != FILEID_INVALID)
13635 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13642 + ii_read_unlock(inode);
13643 + si_read_unlock(sb);
13645 + if (unlikely(err < 0))
13646 + err = FILEID_INVALID;
13650 +/* ---------------------------------------------------------------------- */
13652 +static int aufs_commit_metadata(struct inode *inode)
13655 + aufs_bindex_t bindex;
13656 + struct super_block *sb;
13657 + struct inode *h_inode;
13658 + int (*f)(struct inode *inode);
13660 + sb = inode->i_sb;
13661 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13662 + ii_write_lock_child(inode);
13663 + bindex = au_ibtop(inode);
13664 + AuDebugOn(bindex < 0);
13665 + h_inode = au_h_iptr(inode, bindex);
13667 + f = h_inode->i_sb->s_export_op->commit_metadata;
13669 + err = f(h_inode);
13671 + struct writeback_control wbc = {
13672 + .sync_mode = WB_SYNC_ALL,
13673 + .nr_to_write = 0 /* metadata only */
13676 + err = sync_inode(h_inode, &wbc);
13679 + au_cpup_attr_timesizes(inode);
13680 + ii_write_unlock(inode);
13681 + si_read_unlock(sb);
13685 +/* ---------------------------------------------------------------------- */
13687 +static struct export_operations aufs_export_op = {
13688 + .fh_to_dentry = aufs_fh_to_dentry,
13689 + /* .fh_to_parent = aufs_fh_to_parent, */
13690 + .encode_fh = aufs_encode_fh,
13691 + .commit_metadata = aufs_commit_metadata
13694 +void au_export_init(struct super_block *sb)
13696 + struct au_sbinfo *sbinfo;
13699 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13700 + && IS_MODULE(CONFIG_EXPORTFS),
13701 + AUFS_NAME ": unsupported configuration "
13702 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13704 + sb->s_export_op = &aufs_export_op;
13705 + sbinfo = au_sbi(sb);
13706 + sbinfo->si_xigen = NULL;
13707 + get_random_bytes(&u, sizeof(u));
13708 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13709 + atomic_set(&sbinfo->si_xigen_next, u);
13711 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13712 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13713 +++ linux/fs/aufs/fhsm.c 2020-01-27 10:57:18.172204883 +0100
13715 +// SPDX-License-Identifier: GPL-2.0
13717 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13719 + * This program, aufs is free software; you can redistribute it and/or modify
13720 + * it under the terms of the GNU General Public License as published by
13721 + * the Free Software Foundation; either version 2 of the License, or
13722 + * (at your option) any later version.
13724 + * This program is distributed in the hope that it will be useful,
13725 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13726 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13727 + * GNU General Public License for more details.
13729 + * You should have received a copy of the GNU General Public License
13730 + * along with this program; if not, write to the Free Software
13731 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13735 + * File-based Hierarchy Storage Management
13738 +#include <linux/anon_inodes.h>
13739 +#include <linux/poll.h>
13740 +#include <linux/seq_file.h>
13741 +#include <linux/statfs.h>
13744 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13746 + struct au_sbinfo *sbinfo;
13747 + struct au_fhsm *fhsm;
13749 + SiMustAnyLock(sb);
13751 + sbinfo = au_sbi(sb);
13752 + fhsm = &sbinfo->si_fhsm;
13753 + AuDebugOn(!fhsm);
13754 + return fhsm->fhsm_bottom;
13757 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13759 + struct au_sbinfo *sbinfo;
13760 + struct au_fhsm *fhsm;
13762 + SiMustWriteLock(sb);
13764 + sbinfo = au_sbi(sb);
13765 + fhsm = &sbinfo->si_fhsm;
13766 + AuDebugOn(!fhsm);
13767 + fhsm->fhsm_bottom = bindex;
13770 +/* ---------------------------------------------------------------------- */
13772 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13774 + struct au_br_fhsm *bf;
13776 + bf = br->br_fhsm;
13777 + MtxMustLock(&bf->bf_lock);
13779 + return !bf->bf_readable
13780 + || time_after(jiffies,
13781 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13784 +/* ---------------------------------------------------------------------- */
13786 +static void au_fhsm_notify(struct super_block *sb, int val)
13788 + struct au_sbinfo *sbinfo;
13789 + struct au_fhsm *fhsm;
13791 + SiMustAnyLock(sb);
13793 + sbinfo = au_sbi(sb);
13794 + fhsm = &sbinfo->si_fhsm;
13795 + if (au_fhsm_pid(fhsm)
13796 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13797 + atomic_set(&fhsm->fhsm_readable, val);
13799 + wake_up(&fhsm->fhsm_wqh);
13803 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13804 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13807 + struct au_branch *br;
13808 + struct au_br_fhsm *bf;
13810 + br = au_sbr(sb, bindex);
13811 + AuDebugOn(au_br_rdonly(br));
13812 + bf = br->br_fhsm;
13816 + mutex_lock(&bf->bf_lock);
13818 + MtxMustLock(&bf->bf_lock);
13820 + /* sb->s_root for NFS is unreliable */
13821 + err = au_br_stfs(br, &bf->bf_stfs);
13822 + if (unlikely(err)) {
13823 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13827 + bf->bf_jiffy = jiffies;
13828 + bf->bf_readable = 1;
13830 + au_fhsm_notify(sb, /*val*/1);
13832 + *rstfs = bf->bf_stfs;
13836 + mutex_unlock(&bf->bf_lock);
13837 + au_fhsm_notify(sb, /*val*/1);
13842 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13845 + struct au_sbinfo *sbinfo;
13846 + struct au_fhsm *fhsm;
13847 + struct au_branch *br;
13848 + struct au_br_fhsm *bf;
13850 + AuDbg("b%d, force %d\n", bindex, force);
13851 + SiMustAnyLock(sb);
13853 + sbinfo = au_sbi(sb);
13854 + fhsm = &sbinfo->si_fhsm;
13855 + if (!au_ftest_si(sbinfo, FHSM)
13856 + || fhsm->fhsm_bottom == bindex)
13859 + br = au_sbr(sb, bindex);
13860 + bf = br->br_fhsm;
13862 + mutex_lock(&bf->bf_lock);
13864 + || au_fhsm_pid(fhsm)
13865 + || au_fhsm_test_jiffy(sbinfo, br))
13866 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13868 + mutex_unlock(&bf->bf_lock);
13871 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13873 + aufs_bindex_t bindex, bbot;
13874 + struct au_branch *br;
13876 + /* exclude the bottom */
13877 + bbot = au_fhsm_bottom(sb);
13878 + for (bindex = 0; bindex < bbot; bindex++) {
13879 + br = au_sbr(sb, bindex);
13880 + if (au_br_fhsm(br->br_perm))
13881 + au_fhsm_wrote(sb, bindex, force);
13885 +/* ---------------------------------------------------------------------- */
13887 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13890 + struct au_sbinfo *sbinfo;
13891 + struct au_fhsm *fhsm;
13894 + sbinfo = file->private_data;
13895 + fhsm = &sbinfo->si_fhsm;
13896 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13897 + if (atomic_read(&fhsm->fhsm_readable))
13898 + mask = EPOLLIN /* | EPOLLRDNORM */;
13901 + AuDbg("mask 0x%x\n", mask);
13905 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13906 + struct aufs_stfs *stfs, __s16 brid)
13910 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13912 + err = __put_user(brid, &stbr->brid);
13913 + if (unlikely(err))
13919 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13920 + struct aufs_stbr __user *stbr, size_t count)
13924 + aufs_bindex_t bindex, bbot;
13925 + struct au_branch *br;
13926 + struct au_br_fhsm *bf;
13928 + /* except the bottom branch */
13931 + bbot = au_fhsm_bottom(sb);
13932 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13933 + br = au_sbr(sb, bindex);
13934 + if (!au_br_fhsm(br->br_perm))
13937 + bf = br->br_fhsm;
13938 + mutex_lock(&bf->bf_lock);
13939 + if (bf->bf_readable) {
13941 + if (count >= sizeof(*stbr))
13942 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13945 + bf->bf_readable = 0;
13946 + count -= sizeof(*stbr);
13950 + mutex_unlock(&bf->bf_lock);
13953 + err = sizeof(*stbr) * nstbr;
13958 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13963 + aufs_bindex_t nfhsm, bindex, bbot;
13964 + struct au_sbinfo *sbinfo;
13965 + struct au_fhsm *fhsm;
13966 + struct au_branch *br;
13967 + struct super_block *sb;
13970 + sbinfo = file->private_data;
13971 + fhsm = &sbinfo->si_fhsm;
13973 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13974 + if (!atomic_read(&fhsm->fhsm_readable)) {
13975 + if (vfsub_file_flags(file) & O_NONBLOCK)
13978 + err = wait_event_interruptible_locked_irq
13980 + atomic_read(&fhsm->fhsm_readable));
13982 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13983 + if (unlikely(err))
13986 + /* sb may already be dead */
13987 + au_rw_read_lock(&sbinfo->si_rwsem);
13988 + readable = atomic_read(&fhsm->fhsm_readable);
13989 + if (readable > 0) {
13990 + sb = sbinfo->si_sb;
13992 + /* exclude the bottom branch */
13994 + bbot = au_fhsm_bottom(sb);
13995 + for (bindex = 0; bindex < bbot; bindex++) {
13996 + br = au_sbr(sb, bindex);
13997 + if (au_br_fhsm(br->br_perm))
14001 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14002 + atomic_set(&fhsm->fhsm_readable, 0);
14003 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14007 + au_rw_read_unlock(&sbinfo->si_rwsem);
14015 +static int au_fhsm_release(struct inode *inode, struct file *file)
14017 + struct au_sbinfo *sbinfo;
14018 + struct au_fhsm *fhsm;
14020 + /* sb may already be dead */
14021 + sbinfo = file->private_data;
14022 + fhsm = &sbinfo->si_fhsm;
14023 + spin_lock(&fhsm->fhsm_spin);
14024 + fhsm->fhsm_pid = 0;
14025 + spin_unlock(&fhsm->fhsm_spin);
14026 + kobject_put(&sbinfo->si_kobj);
14031 +static const struct file_operations au_fhsm_fops = {
14032 + .owner = THIS_MODULE,
14033 + .llseek = noop_llseek,
14034 + .read = au_fhsm_read,
14035 + .poll = au_fhsm_poll,
14036 + .release = au_fhsm_release
14039 +int au_fhsm_fd(struct super_block *sb, int oflags)
14042 + struct au_sbinfo *sbinfo;
14043 + struct au_fhsm *fhsm;
14046 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14050 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14054 + sbinfo = au_sbi(sb);
14055 + fhsm = &sbinfo->si_fhsm;
14056 + spin_lock(&fhsm->fhsm_spin);
14057 + if (!fhsm->fhsm_pid)
14058 + fhsm->fhsm_pid = current->pid;
14061 + spin_unlock(&fhsm->fhsm_spin);
14062 + if (unlikely(err))
14065 + oflags |= O_RDONLY;
14066 + /* oflags |= FMODE_NONOTIFY; */
14067 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14069 + if (unlikely(fd < 0))
14072 + /* succeed regardless 'fhsm' status */
14073 + kobject_get(&sbinfo->si_kobj);
14074 + si_noflush_read_lock(sb);
14075 + if (au_ftest_si(sbinfo, FHSM))
14076 + au_fhsm_wrote_all(sb, /*force*/0);
14077 + si_read_unlock(sb);
14078 + goto out; /* success */
14081 + spin_lock(&fhsm->fhsm_spin);
14082 + fhsm->fhsm_pid = 0;
14083 + spin_unlock(&fhsm->fhsm_spin);
14089 +/* ---------------------------------------------------------------------- */
14091 +int au_fhsm_br_alloc(struct au_branch *br)
14096 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14098 + au_br_fhsm_init(br->br_fhsm);
14105 +/* ---------------------------------------------------------------------- */
14107 +void au_fhsm_fin(struct super_block *sb)
14109 + au_fhsm_notify(sb, /*val*/-1);
14112 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14114 + struct au_fhsm *fhsm;
14116 + fhsm = &sbinfo->si_fhsm;
14117 + spin_lock_init(&fhsm->fhsm_spin);
14118 + init_waitqueue_head(&fhsm->fhsm_wqh);
14119 + atomic_set(&fhsm->fhsm_readable, 0);
14120 + fhsm->fhsm_expire
14121 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14122 + fhsm->fhsm_bottom = -1;
14125 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14127 + sbinfo->si_fhsm.fhsm_expire
14128 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14131 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14135 + if (!au_ftest_si(sbinfo, FHSM))
14138 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14139 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14140 + seq_printf(seq, ",fhsm_sec=%u", u);
14142 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14143 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14144 +++ linux/fs/aufs/file.c 2020-01-27 10:57:18.172204883 +0100
14146 +// SPDX-License-Identifier: GPL-2.0
14148 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14150 + * This program, aufs is free software; you can redistribute it and/or modify
14151 + * it under the terms of the GNU General Public License as published by
14152 + * the Free Software Foundation; either version 2 of the License, or
14153 + * (at your option) any later version.
14155 + * This program is distributed in the hope that it will be useful,
14156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14158 + * GNU General Public License for more details.
14160 + * You should have received a copy of the GNU General Public License
14161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14165 + * handling file/dir, and address_space operation
14168 +#ifdef CONFIG_AUFS_DEBUG
14169 +#include <linux/migrate.h>
14171 +#include <linux/pagemap.h>
14174 +/* drop flags for writing */
14175 +unsigned int au_file_roflags(unsigned int flags)
14177 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14178 + flags |= O_RDONLY | O_NOATIME;
14182 +/* common functions to regular file and dir */
14183 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14184 + struct file *file, int force_wr)
14186 + struct file *h_file;
14187 + struct dentry *h_dentry;
14188 + struct inode *h_inode;
14189 + struct super_block *sb;
14190 + struct au_branch *br;
14191 + struct path h_path;
14194 + /* a race condition can happen between open and unlink/rmdir */
14195 + h_file = ERR_PTR(-ENOENT);
14196 + h_dentry = au_h_dptr(dentry, bindex);
14197 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14199 + h_inode = d_inode(h_dentry);
14200 + spin_lock(&h_dentry->d_lock);
14201 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14202 + /* || !d_inode(dentry)->i_nlink */
14204 + spin_unlock(&h_dentry->d_lock);
14205 + if (unlikely(err))
14208 + sb = dentry->d_sb;
14209 + br = au_sbr(sb, bindex);
14210 + err = au_br_test_oflag(flags, br);
14211 + h_file = ERR_PTR(err);
14212 + if (unlikely(err))
14215 + /* drop flags for writing */
14216 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14217 + if (force_wr && !(flags & O_WRONLY))
14219 + flags = au_file_roflags(flags);
14221 + h_file = ERR_PTR(-EROFS);
14222 + flags = au_file_roflags(flags);
14223 + if (unlikely(vfsub_native_ro(h_inode)
14224 + || IS_APPEND(h_inode)))
14226 + flags &= ~O_ACCMODE;
14227 + flags |= O_WRONLY;
14230 + flags &= ~O_CREAT;
14231 + au_lcnt_inc(&br->br_nfiles);
14232 + h_path.dentry = h_dentry;
14233 + h_path.mnt = au_br_mnt(br);
14234 + h_file = vfsub_dentry_open(&h_path, flags);
14235 + if (IS_ERR(h_file))
14238 + if (flags & __FMODE_EXEC) {
14239 + err = deny_write_access(h_file);
14240 + if (unlikely(err)) {
14242 + h_file = ERR_PTR(err);
14246 + fsnotify_open(h_file);
14247 + goto out; /* success */
14250 + au_lcnt_dec(&br->br_nfiles);
14255 +static int au_cmoo(struct dentry *dentry)
14257 + int err, cmoo, matched;
14258 + unsigned int udba;
14259 + struct path h_path;
14260 + struct au_pin pin;
14261 + struct au_cp_generic cpg = {
14262 + .dentry = dentry,
14267 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14269 + struct inode *delegated;
14270 + struct super_block *sb;
14271 + struct au_sbinfo *sbinfo;
14272 + struct au_fhsm *fhsm;
14274 + struct au_branch *br;
14275 + struct dentry *parent;
14276 + struct au_hinode *hdir;
14278 + DiMustWriteLock(dentry);
14279 + IiMustWriteLock(d_inode(dentry));
14282 + if (IS_ROOT(dentry))
14284 + cpg.bsrc = au_dbtop(dentry);
14288 + sb = dentry->d_sb;
14289 + sbinfo = au_sbi(sb);
14290 + fhsm = &sbinfo->si_fhsm;
14291 + pid = au_fhsm_pid(fhsm);
14294 + && (current->pid == pid
14295 + || rcu_dereference(current->real_parent)->pid == pid));
14296 + rcu_read_unlock();
14300 + br = au_sbr(sb, cpg.bsrc);
14301 + cmoo = au_br_cmoo(br->br_perm);
14304 + if (!d_is_reg(dentry))
14305 + cmoo &= AuBrAttr_COO_ALL;
14309 + parent = dget_parent(dentry);
14310 + di_write_lock_parent(parent);
14311 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14313 + if (unlikely(err < 0)) {
14314 + err = 0; /* there is no upper writable branch */
14317 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14319 + /* do not respect the coo attrib for the target branch */
14320 + err = au_cpup_dirs(dentry, cpg.bdst);
14321 + if (unlikely(err))
14324 + di_downgrade_lock(parent, AuLock_IR);
14325 + udba = au_opt_udba(sb);
14326 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14327 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14328 + if (unlikely(err))
14331 + err = au_sio_cpup_simple(&cpg);
14333 + if (unlikely(err))
14335 + if (!(cmoo & AuBrWAttr_MOO))
14336 + goto out_parent; /* success */
14338 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14339 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14340 + if (unlikely(err))
14343 + h_path.mnt = au_br_mnt(br);
14344 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14345 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14346 + delegated = NULL;
14347 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14349 + /* todo: keep h_dentry or not? */
14350 + if (unlikely(err == -EWOULDBLOCK)) {
14351 + pr_warn("cannot retry for NFSv4 delegation"
14352 + " for an internal unlink\n");
14355 + if (unlikely(err)) {
14356 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14360 + goto out_parent; /* success */
14363 + di_downgrade_lock(parent, AuLock_IR);
14365 + di_read_unlock(parent, AuLock_IR);
14372 +int au_do_open(struct file *file, struct au_do_open_args *args)
14374 + int err, aopen = args->aopen;
14375 + struct dentry *dentry;
14376 + struct au_finfo *finfo;
14379 + err = au_finfo_init(file, args->fidir);
14382 + err = au_finfo_init(file, args->fidir);
14385 + if (unlikely(err))
14388 + dentry = file->f_path.dentry;
14389 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14390 + di_write_lock_child(dentry);
14391 + err = au_cmoo(dentry);
14392 + di_downgrade_lock(dentry, AuLock_IR);
14395 + err = args->open(file, vfsub_file_flags(file), NULL);
14398 + err = args->open(file, vfsub_file_flags(file),
14403 + di_read_unlock(dentry, AuLock_IR);
14405 + finfo = au_fi(file);
14407 + finfo->fi_file = file;
14408 + au_hbl_add(&finfo->fi_hlist,
14409 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14412 + fi_write_unlock(file);
14415 + fi_write_unlock(file);
14418 + if (unlikely(err)) {
14419 + finfo->fi_hdir = NULL;
14420 + au_finfo_fin(file);
14428 +int au_reopen_nondir(struct file *file)
14431 + aufs_bindex_t btop;
14432 + struct dentry *dentry;
14433 + struct au_branch *br;
14434 + struct file *h_file, *h_file_tmp;
14436 + dentry = file->f_path.dentry;
14437 + btop = au_dbtop(dentry);
14438 + br = au_sbr(dentry->d_sb, btop);
14439 + h_file_tmp = NULL;
14440 + if (au_fbtop(file) == btop) {
14441 + h_file = au_hf_top(file);
14442 + if (file->f_mode == h_file->f_mode)
14443 + return 0; /* success */
14444 + h_file_tmp = h_file;
14445 + get_file(h_file_tmp);
14446 + au_lcnt_inc(&br->br_nfiles);
14447 + au_set_h_fptr(file, btop, NULL);
14449 + AuDebugOn(au_fi(file)->fi_hdir);
14452 + * file exists on both of rw and ro
14453 + * open --> dbtop and fbtop are both 0
14454 + * prepend a branch as rw, "rw" become ro
14456 + * delete the top branch, "rw" becomes rw again
14457 + * --> dbtop is 1, fbtop is still 0
14458 + * write --> fbtop is 0 but dbtop is 1
14460 + /* AuDebugOn(au_fbtop(file) < btop); */
14462 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14463 + file, /*force_wr*/0);
14464 + err = PTR_ERR(h_file);
14465 + if (IS_ERR(h_file)) {
14466 + if (h_file_tmp) {
14468 + au_set_h_fptr(file, btop, h_file_tmp);
14469 + h_file_tmp = NULL;
14471 + goto out; /* todo: close all? */
14475 + au_set_fbtop(file, btop);
14476 + au_set_h_fptr(file, btop, h_file);
14477 + au_update_figen(file);
14478 + /* todo: necessary? */
14479 + /* file->f_ra = h_file->f_ra; */
14482 + if (h_file_tmp) {
14483 + fput(h_file_tmp);
14484 + au_lcnt_dec(&br->br_nfiles);
14489 +/* ---------------------------------------------------------------------- */
14491 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14492 + struct dentry *hi_wh)
14495 + aufs_bindex_t btop;
14496 + struct au_dinfo *dinfo;
14497 + struct dentry *h_dentry;
14498 + struct au_hdentry *hdp;
14500 + dinfo = au_di(file->f_path.dentry);
14501 + AuRwMustWriteLock(&dinfo->di_rwsem);
14503 + btop = dinfo->di_btop;
14504 + dinfo->di_btop = btgt;
14505 + hdp = au_hdentry(dinfo, btgt);
14506 + h_dentry = hdp->hd_dentry;
14507 + hdp->hd_dentry = hi_wh;
14508 + err = au_reopen_nondir(file);
14509 + hdp->hd_dentry = h_dentry;
14510 + dinfo->di_btop = btop;
14515 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14516 + aufs_bindex_t bcpup, struct au_pin *pin)
14519 + struct inode *inode, *h_inode;
14520 + struct dentry *h_dentry, *hi_wh;
14521 + struct au_cp_generic cpg = {
14522 + .dentry = file->f_path.dentry,
14529 + au_update_dbtop(cpg.dentry);
14530 + inode = d_inode(cpg.dentry);
14532 + if (au_dbtop(cpg.dentry) <= bcpup
14533 + && au_dbbot(cpg.dentry) >= bcpup) {
14534 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14535 + if (h_dentry && d_is_positive(h_dentry))
14536 + h_inode = d_inode(h_dentry);
14538 + hi_wh = au_hi_wh(inode, bcpup);
14539 + if (!hi_wh && !h_inode)
14540 + err = au_sio_cpup_wh(&cpg, file);
14542 + /* already copied-up after unlink */
14543 + err = au_reopen_wh(file, bcpup, hi_wh);
14546 + && (inode->i_nlink > 1
14547 + || (inode->i_state & I_LINKABLE))
14548 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14549 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14555 + * prepare the @file for writing.
14557 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14560 + aufs_bindex_t dbtop;
14561 + struct dentry *parent;
14562 + struct inode *inode;
14563 + struct super_block *sb;
14564 + struct file *h_file;
14565 + struct au_cp_generic cpg = {
14566 + .dentry = file->f_path.dentry,
14571 + .flags = AuCpup_DTIME
14574 + sb = cpg.dentry->d_sb;
14575 + inode = d_inode(cpg.dentry);
14576 + cpg.bsrc = au_fbtop(file);
14577 + err = au_test_ro(sb, cpg.bsrc, inode);
14578 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14579 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14584 + /* need to cpup or reopen */
14585 + parent = dget_parent(cpg.dentry);
14586 + di_write_lock_parent(parent);
14587 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14589 + if (unlikely(err < 0))
14593 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14594 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14595 + if (unlikely(err))
14599 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14600 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14601 + if (unlikely(err))
14604 + dbtop = au_dbtop(cpg.dentry);
14605 + if (dbtop <= cpg.bdst)
14606 + cpg.bsrc = cpg.bdst;
14608 + if (dbtop <= cpg.bdst /* just reopen */
14609 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14611 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14612 + if (IS_ERR(h_file))
14613 + err = PTR_ERR(h_file);
14615 + di_downgrade_lock(parent, AuLock_IR);
14616 + if (dbtop > cpg.bdst)
14617 + err = au_sio_cpup_simple(&cpg);
14619 + err = au_reopen_nondir(file);
14620 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14622 + } else { /* copyup as wh and reopen */
14624 + * since writable hfsplus branch is not supported,
14625 + * h_open_pre/post() are unnecessary.
14627 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14628 + di_downgrade_lock(parent, AuLock_IR);
14632 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14633 + goto out_dput; /* success */
14639 + di_downgrade_lock(parent, AuLock_IR);
14641 + di_read_unlock(parent, AuLock_IR);
14648 +/* ---------------------------------------------------------------------- */
14650 +int au_do_flush(struct file *file, fl_owner_t id,
14651 + int (*flush)(struct file *file, fl_owner_t id))
14654 + struct super_block *sb;
14655 + struct inode *inode;
14657 + inode = file_inode(file);
14658 + sb = inode->i_sb;
14659 + si_noflush_read_lock(sb);
14660 + fi_read_lock(file);
14661 + ii_read_lock_child(inode);
14663 + err = flush(file, id);
14664 + au_cpup_attr_timesizes(inode);
14666 + ii_read_unlock(inode);
14667 + fi_read_unlock(file);
14668 + si_read_unlock(sb);
14672 +/* ---------------------------------------------------------------------- */
14674 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14677 + struct au_pin pin;
14678 + struct au_finfo *finfo;
14679 + struct dentry *parent, *hi_wh;
14680 + struct inode *inode;
14681 + struct super_block *sb;
14682 + struct au_cp_generic cpg = {
14683 + .dentry = file->f_path.dentry,
14688 + .flags = AuCpup_DTIME
14691 + FiMustWriteLock(file);
14694 + finfo = au_fi(file);
14695 + sb = cpg.dentry->d_sb;
14696 + inode = d_inode(cpg.dentry);
14697 + cpg.bdst = au_ibtop(inode);
14698 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14701 + parent = dget_parent(cpg.dentry);
14702 + if (au_test_ro(sb, cpg.bdst, inode)) {
14703 + di_read_lock_parent(parent, !AuLock_IR);
14704 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14706 + di_read_unlock(parent, !AuLock_IR);
14707 + if (unlikely(err < 0))
14712 + di_read_lock_parent(parent, AuLock_IR);
14713 + hi_wh = au_hi_wh(inode, cpg.bdst);
14714 + if (!S_ISDIR(inode->i_mode)
14715 + && au_opt_test(au_mntflags(sb), PLINK)
14716 + && au_plink_test(inode)
14717 + && !d_unhashed(cpg.dentry)
14718 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14719 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14720 + if (unlikely(err))
14723 + /* always superio. */
14724 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14725 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14727 + err = au_sio_cpup_simple(&cpg);
14730 + } else if (hi_wh) {
14731 + /* already copied-up after unlink */
14732 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14733 + *need_reopen = 0;
14737 + di_read_unlock(parent, AuLock_IR);
14744 +static void au_do_refresh_dir(struct file *file)
14746 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14747 + struct au_hfile *p, tmp, *q;
14748 + struct au_finfo *finfo;
14749 + struct super_block *sb;
14750 + struct au_fidir *fidir;
14752 + FiMustWriteLock(file);
14754 + sb = file->f_path.dentry->d_sb;
14755 + finfo = au_fi(file);
14756 + fidir = finfo->fi_hdir;
14757 + AuDebugOn(!fidir);
14758 + p = fidir->fd_hfile + finfo->fi_btop;
14759 + brid = p->hf_br->br_id;
14760 + bbot = fidir->fd_bbot;
14761 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14765 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14766 + if (new_bindex == bindex)
14768 + if (new_bindex < 0) {
14769 + au_set_h_fptr(file, bindex, NULL);
14773 + /* swap two lower inode, and loop again */
14774 + q = fidir->fd_hfile + new_bindex;
14778 + if (tmp.hf_file) {
14784 + p = fidir->fd_hfile;
14785 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14786 + bbot = au_sbbot(sb);
14787 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14788 + finfo->fi_btop++, p++)
14789 + if (p->hf_file) {
14790 + if (file_inode(p->hf_file))
14792 + au_hfput(p, /*execed*/0);
14795 + bbot = au_br_index(sb, brid);
14796 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14797 + finfo->fi_btop++, p++)
14799 + au_hfput(p, /*execed*/0);
14800 + bbot = au_sbbot(sb);
14803 + p = fidir->fd_hfile + bbot;
14804 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14805 + fidir->fd_bbot--, p--)
14806 + if (p->hf_file) {
14807 + if (file_inode(p->hf_file))
14809 + au_hfput(p, /*execed*/0);
14811 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14815 + * after branch manipulating, refresh the file.
14817 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14819 + int err, need_reopen, nbr;
14820 + aufs_bindex_t bbot, bindex;
14821 + struct dentry *dentry;
14822 + struct super_block *sb;
14823 + struct au_finfo *finfo;
14824 + struct au_hfile *hfile;
14826 + dentry = file->f_path.dentry;
14827 + sb = dentry->d_sb;
14828 + nbr = au_sbbot(sb) + 1;
14829 + finfo = au_fi(file);
14830 + if (!finfo->fi_hdir) {
14831 + hfile = &finfo->fi_htop;
14832 + AuDebugOn(!hfile->hf_file);
14833 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14834 + AuDebugOn(bindex < 0);
14835 + if (bindex != finfo->fi_btop)
14836 + au_set_fbtop(file, bindex);
14838 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14839 + if (unlikely(err))
14841 + au_do_refresh_dir(file);
14846 + if (!au_test_mmapped(file))
14847 + err = au_file_refresh_by_inode(file, &need_reopen);
14848 + if (finfo->fi_hdir)
14849 + /* harmless if err */
14850 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14851 + if (!err && need_reopen && !d_unlinked(dentry))
14852 + err = reopen(file);
14854 + au_update_figen(file);
14855 + goto out; /* success */
14858 + /* error, close all lower files */
14859 + if (finfo->fi_hdir) {
14860 + bbot = au_fbbot_dir(file);
14861 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14862 + au_set_h_fptr(file, bindex, NULL);
14869 +/* common function to regular file and dir */
14870 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14871 + int wlock, unsigned int fi_lsc)
14874 + unsigned int sigen, figen;
14875 + aufs_bindex_t btop;
14876 + unsigned char pseudo_link;
14877 + struct dentry *dentry;
14878 + struct inode *inode;
14881 + dentry = file->f_path.dentry;
14882 + inode = d_inode(dentry);
14883 + sigen = au_sigen(dentry->d_sb);
14884 + fi_write_lock_nested(file, fi_lsc);
14885 + figen = au_figen(file);
14887 + di_write_lock_child(dentry);
14889 + di_write_lock_child2(dentry);
14890 + btop = au_dbtop(dentry);
14891 + pseudo_link = (btop != au_ibtop(inode));
14892 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14894 + di_downgrade_lock(dentry, AuLock_IR);
14895 + fi_downgrade_lock(file);
14897 + goto out; /* success */
14900 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14901 + if (au_digen_test(dentry, sigen)) {
14902 + err = au_reval_dpath(dentry, sigen);
14903 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14907 + err = refresh_file(file, reopen);
14910 + di_downgrade_lock(dentry, AuLock_IR);
14911 + fi_downgrade_lock(file);
14914 + di_write_unlock(dentry);
14915 + fi_write_unlock(file);
14922 +/* ---------------------------------------------------------------------- */
14924 +/* cf. aufs_nopage() */
14925 +/* for madvise(2) */
14926 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14928 + unlock_page(page);
14932 +/* it will never be called, but necessary to support O_DIRECT */
14933 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14934 +{ BUG(); return 0; }
14936 +/* they will never be called. */
14937 +#ifdef CONFIG_AUFS_DEBUG
14938 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14939 + loff_t pos, unsigned len, unsigned flags,
14940 + struct page **pagep, void **fsdata)
14941 +{ AuUnsupport(); return 0; }
14942 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14943 + loff_t pos, unsigned len, unsigned copied,
14944 + struct page *page, void *fsdata)
14945 +{ AuUnsupport(); return 0; }
14946 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14947 +{ AuUnsupport(); return 0; }
14949 +static int aufs_set_page_dirty(struct page *page)
14950 +{ AuUnsupport(); return 0; }
14951 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14952 + unsigned int length)
14953 +{ AuUnsupport(); }
14954 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14955 +{ AuUnsupport(); return 0; }
14956 +#if 0 /* called by memory compaction regardless file */
14957 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14958 + struct page *page, enum migrate_mode mode)
14959 +{ AuUnsupport(); return 0; }
14961 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14962 +{ AuUnsupport(); return true; }
14963 +static void aufs_putback_page(struct page *page)
14964 +{ AuUnsupport(); }
14965 +static int aufs_launder_page(struct page *page)
14966 +{ AuUnsupport(); return 0; }
14967 +static int aufs_is_partially_uptodate(struct page *page,
14968 + unsigned long from,
14969 + unsigned long count)
14970 +{ AuUnsupport(); return 0; }
14971 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14973 +{ AuUnsupport(); }
14974 +static int aufs_error_remove_page(struct address_space *mapping,
14975 + struct page *page)
14976 +{ AuUnsupport(); return 0; }
14977 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14979 +{ AuUnsupport(); return 0; }
14980 +static void aufs_swap_deactivate(struct file *file)
14981 +{ AuUnsupport(); }
14982 +#endif /* CONFIG_AUFS_DEBUG */
14984 +const struct address_space_operations aufs_aop = {
14985 + .readpage = aufs_readpage,
14986 + .direct_IO = aufs_direct_IO,
14987 +#ifdef CONFIG_AUFS_DEBUG
14988 + .writepage = aufs_writepage,
14989 + /* no writepages, because of writepage */
14990 + .set_page_dirty = aufs_set_page_dirty,
14991 + /* no readpages, because of readpage */
14992 + .write_begin = aufs_write_begin,
14993 + .write_end = aufs_write_end,
14994 + /* no bmap, no block device */
14995 + .invalidatepage = aufs_invalidatepage,
14996 + .releasepage = aufs_releasepage,
14997 + /* is fallback_migrate_page ok? */
14998 + /* .migratepage = aufs_migratepage, */
14999 + .isolate_page = aufs_isolate_page,
15000 + .putback_page = aufs_putback_page,
15001 + .launder_page = aufs_launder_page,
15002 + .is_partially_uptodate = aufs_is_partially_uptodate,
15003 + .is_dirty_writeback = aufs_is_dirty_writeback,
15004 + .error_remove_page = aufs_error_remove_page,
15005 + .swap_activate = aufs_swap_activate,
15006 + .swap_deactivate = aufs_swap_deactivate
15007 +#endif /* CONFIG_AUFS_DEBUG */
15009 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15010 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15011 +++ linux/fs/aufs/file.h 2020-01-27 10:57:18.172204883 +0100
15013 +/* SPDX-License-Identifier: GPL-2.0 */
15015 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15017 + * This program, aufs is free software; you can redistribute it and/or modify
15018 + * it under the terms of the GNU General Public License as published by
15019 + * the Free Software Foundation; either version 2 of the License, or
15020 + * (at your option) any later version.
15022 + * This program is distributed in the hope that it will be useful,
15023 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15024 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15025 + * GNU General Public License for more details.
15027 + * You should have received a copy of the GNU General Public License
15028 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15032 + * file operations
15035 +#ifndef __AUFS_FILE_H__
15036 +#define __AUFS_FILE_H__
15040 +#include <linux/file.h>
15041 +#include <linux/fs.h>
15042 +#include <linux/mm_types.h>
15043 +#include <linux/poll.h>
15044 +#include "rwsem.h"
15048 + struct file *hf_file;
15049 + struct au_branch *hf_br;
15054 + aufs_bindex_t fd_bbot;
15055 + aufs_bindex_t fd_nent;
15056 + struct au_vdir *fd_vdir_cache;
15057 + struct au_hfile fd_hfile[];
15060 +static inline int au_fidir_sz(int nent)
15062 + AuDebugOn(nent < 0);
15063 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15067 + atomic_t fi_generation;
15069 + struct au_rwsem fi_rwsem;
15070 + aufs_bindex_t fi_btop;
15072 + /* do not union them */
15073 + struct { /* for non-dir */
15074 + struct au_hfile fi_htop;
15075 + atomic_t fi_mmapped;
15077 + struct au_fidir *fi_hdir; /* for dir only */
15079 + struct hlist_bl_node fi_hlist;
15080 + struct file *fi_file; /* very ugly */
15081 + struct rcu_head rcu;
15082 +} ____cacheline_aligned_in_smp;
15084 +/* ---------------------------------------------------------------------- */
15087 +extern const struct address_space_operations aufs_aop;
15088 +unsigned int au_file_roflags(unsigned int flags);
15089 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15090 + struct file *file, int force_wr);
15091 +struct au_do_open_args {
15093 + int (*open)(struct file *file, int flags,
15094 + struct file *h_file);
15095 + struct au_fidir *fidir;
15096 + struct file *h_file;
15098 +int au_do_open(struct file *file, struct au_do_open_args *args);
15099 +int au_reopen_nondir(struct file *file);
15101 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15102 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15103 + int wlock, unsigned int fi_lsc);
15104 +int au_do_flush(struct file *file, fl_owner_t id,
15105 + int (*flush)(struct file *file, fl_owner_t id));
15108 +#ifdef CONFIG_AUFS_POLL
15109 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15112 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15114 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15116 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15117 + struct file *h_file);
15119 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15120 + aufs_bindex_t bindex, int force_wr)
15121 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15122 + struct file *h_file);
15126 +extern const struct file_operations aufs_file_fop;
15127 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15128 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15129 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15132 +void au_hfput(struct au_hfile *hf, int execed);
15133 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15134 + struct file *h_file);
15136 +void au_update_figen(struct file *file);
15137 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15138 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15140 +void au_fi_init_once(void *_fi);
15141 +void au_finfo_fin(struct file *file);
15142 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15145 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15146 +#ifdef CONFIG_COMPAT
15147 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15148 + unsigned long arg);
15149 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15150 + unsigned long arg);
15153 +/* ---------------------------------------------------------------------- */
15155 +static inline struct au_finfo *au_fi(struct file *file)
15157 + return file->private_data;
15160 +/* ---------------------------------------------------------------------- */
15162 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15163 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15164 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15165 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15167 +#define fi_read_trylock_nested(f) \
15168 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15169 +#define fi_write_trylock_nested(f) \
15170 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15173 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15174 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15175 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15177 +/* lock subclass for finfo */
15183 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15185 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15188 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15190 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15194 + * fi_read_lock_1, fi_write_lock_1,
15195 + * fi_read_lock_2, fi_write_lock_2
15197 +#define AuReadLockFunc(name) \
15198 +static inline void fi_read_lock_##name(struct file *f) \
15199 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15201 +#define AuWriteLockFunc(name) \
15202 +static inline void fi_write_lock_##name(struct file *f) \
15203 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15205 +#define AuRWLockFuncs(name) \
15206 + AuReadLockFunc(name) \
15207 + AuWriteLockFunc(name)
15212 +#undef AuReadLockFunc
15213 +#undef AuWriteLockFunc
15214 +#undef AuRWLockFuncs
15216 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15217 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15218 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15220 +/* ---------------------------------------------------------------------- */
15222 +/* todo: hard/soft set? */
15223 +static inline aufs_bindex_t au_fbtop(struct file *file)
15225 + FiMustAnyLock(file);
15226 + return au_fi(file)->fi_btop;
15229 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15231 + FiMustAnyLock(file);
15232 + AuDebugOn(!au_fi(file)->fi_hdir);
15233 + return au_fi(file)->fi_hdir->fd_bbot;
15236 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15238 + FiMustAnyLock(file);
15239 + AuDebugOn(!au_fi(file)->fi_hdir);
15240 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15243 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15245 + FiMustWriteLock(file);
15246 + au_fi(file)->fi_btop = bindex;
15249 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15251 + FiMustWriteLock(file);
15252 + AuDebugOn(!au_fi(file)->fi_hdir);
15253 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15256 +static inline void au_set_fvdir_cache(struct file *file,
15257 + struct au_vdir *vdir_cache)
15259 + FiMustWriteLock(file);
15260 + AuDebugOn(!au_fi(file)->fi_hdir);
15261 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15264 +static inline struct file *au_hf_top(struct file *file)
15266 + FiMustAnyLock(file);
15267 + AuDebugOn(au_fi(file)->fi_hdir);
15268 + return au_fi(file)->fi_htop.hf_file;
15271 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15273 + FiMustAnyLock(file);
15274 + AuDebugOn(!au_fi(file)->fi_hdir);
15275 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15278 +/* todo: memory barrier? */
15279 +static inline unsigned int au_figen(struct file *f)
15281 + return atomic_read(&au_fi(f)->fi_generation);
15284 +static inline void au_set_mmapped(struct file *f)
15286 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15288 + pr_warn("fi_mmapped wrapped around\n");
15289 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15293 +static inline void au_unset_mmapped(struct file *f)
15295 + atomic_dec(&au_fi(f)->fi_mmapped);
15298 +static inline int au_test_mmapped(struct file *f)
15300 + return atomic_read(&au_fi(f)->fi_mmapped);
15303 +/* customize vma->vm_file */
15305 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15306 + struct file *file)
15310 + f = vma->vm_file;
15312 + vma->vm_file = file;
15317 +#define AuDbgVmRegion(file, vma) do {} while (0)
15319 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15320 + struct file *file)
15322 + au_do_vm_file_reset(vma, file);
15325 +#define AuDbgVmRegion(file, vma) \
15326 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15328 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15329 + struct file *file)
15333 + au_do_vm_file_reset(vma, file);
15334 + f = vma->vm_region->vm_file;
15336 + vma->vm_region->vm_file = file;
15339 +#endif /* CONFIG_MMU */
15341 +/* handle vma->vm_prfile */
15342 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15343 + struct file *file)
15346 + vma->vm_prfile = file;
15347 +#ifndef CONFIG_MMU
15349 + vma->vm_region->vm_prfile = file;
15353 +#endif /* __KERNEL__ */
15354 +#endif /* __AUFS_FILE_H__ */
15355 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15356 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15357 +++ linux/fs/aufs/finfo.c 2020-01-27 10:57:18.172204883 +0100
15359 +// SPDX-License-Identifier: GPL-2.0
15361 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15363 + * This program, aufs is free software; you can redistribute it and/or modify
15364 + * it under the terms of the GNU General Public License as published by
15365 + * the Free Software Foundation; either version 2 of the License, or
15366 + * (at your option) any later version.
15368 + * This program is distributed in the hope that it will be useful,
15369 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15370 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15371 + * GNU General Public License for more details.
15373 + * You should have received a copy of the GNU General Public License
15374 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15378 + * file private data
15383 +void au_hfput(struct au_hfile *hf, int execed)
15386 + allow_write_access(hf->hf_file);
15387 + fput(hf->hf_file);
15388 + hf->hf_file = NULL;
15389 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15390 + hf->hf_br = NULL;
15393 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15395 + struct au_finfo *finfo = au_fi(file);
15396 + struct au_hfile *hf;
15397 + struct au_fidir *fidir;
15399 + fidir = finfo->fi_hdir;
15401 + AuDebugOn(finfo->fi_btop != bindex);
15402 + hf = &finfo->fi_htop;
15404 + hf = fidir->fd_hfile + bindex;
15406 + if (hf && hf->hf_file)
15407 + au_hfput(hf, vfsub_file_execed(file));
15409 + FiMustWriteLock(file);
15410 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15411 + hf->hf_file = val;
15412 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15416 +void au_update_figen(struct file *file)
15418 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15419 + /* smp_mb(); */ /* atomic_set */
15422 +/* ---------------------------------------------------------------------- */
15424 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15426 + struct au_fidir *fidir;
15429 + nbr = au_sbbot(sb) + 1;
15431 + nbr = 2; /* initial allocate for 2 branches */
15432 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15434 + fidir->fd_bbot = -1;
15435 + fidir->fd_nent = nbr;
15441 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15444 + struct au_fidir *fidir, *p;
15446 + AuRwMustWriteLock(&finfo->fi_rwsem);
15447 + fidir = finfo->fi_hdir;
15448 + AuDebugOn(!fidir);
15451 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15452 + GFP_NOFS, may_shrink);
15454 + p->fd_nent = nbr;
15455 + finfo->fi_hdir = p;
15462 +/* ---------------------------------------------------------------------- */
15464 +void au_finfo_fin(struct file *file)
15466 + struct au_finfo *finfo;
15468 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15470 + finfo = au_fi(file);
15471 + AuDebugOn(finfo->fi_hdir);
15472 + AuRwDestroy(&finfo->fi_rwsem);
15473 + au_cache_free_finfo(finfo);
15476 +void au_fi_init_once(void *_finfo)
15478 + struct au_finfo *finfo = _finfo;
15480 + au_rw_init(&finfo->fi_rwsem);
15483 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15486 + struct au_finfo *finfo;
15487 + struct dentry *dentry;
15490 + dentry = file->f_path.dentry;
15491 + finfo = au_cache_alloc_finfo();
15492 + if (unlikely(!finfo))
15496 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15497 + au_rw_write_lock(&finfo->fi_rwsem);
15498 + finfo->fi_btop = -1;
15499 + finfo->fi_hdir = fidir;
15500 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15501 + /* smp_mb(); */ /* atomic_set */
15503 + file->private_data = finfo;
15508 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15509 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15510 +++ linux/fs/aufs/f_op.c 2020-01-27 10:57:18.172204883 +0100
15512 +// SPDX-License-Identifier: GPL-2.0
15514 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15516 + * This program, aufs is free software; you can redistribute it and/or modify
15517 + * it under the terms of the GNU General Public License as published by
15518 + * the Free Software Foundation; either version 2 of the License, or
15519 + * (at your option) any later version.
15521 + * This program is distributed in the hope that it will be useful,
15522 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15523 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15524 + * GNU General Public License for more details.
15526 + * You should have received a copy of the GNU General Public License
15527 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15531 + * file and vm operations
15534 +#include <linux/aio.h>
15535 +#include <linux/fs_stack.h>
15536 +#include <linux/mman.h>
15537 +#include <linux/security.h>
15540 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15543 + aufs_bindex_t bindex;
15544 + struct dentry *dentry, *h_dentry;
15545 + struct au_finfo *finfo;
15546 + struct inode *h_inode;
15548 + FiMustWriteLock(file);
15551 + dentry = file->f_path.dentry;
15552 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15553 + finfo = au_fi(file);
15554 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15555 + atomic_set(&finfo->fi_mmapped, 0);
15556 + bindex = au_dbtop(dentry);
15558 + h_dentry = au_h_dptr(dentry, bindex);
15559 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15560 + if (unlikely(err))
15562 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15563 + if (IS_ERR(h_file)) {
15564 + err = PTR_ERR(h_file);
15568 + h_dentry = h_file->f_path.dentry;
15569 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15570 + if (unlikely(err))
15572 + /* br ref is already inc-ed */
15575 + if ((flags & __O_TMPFILE)
15576 + && !(flags & O_EXCL)) {
15577 + h_inode = file_inode(h_file);
15578 + spin_lock(&h_inode->i_lock);
15579 + h_inode->i_state |= I_LINKABLE;
15580 + spin_unlock(&h_inode->i_lock);
15582 + au_set_fbtop(file, bindex);
15583 + au_set_h_fptr(file, bindex, h_file);
15584 + au_update_figen(file);
15585 + /* todo: necessary? */
15586 + /* file->f_ra = h_file->f_ra; */
15592 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15593 + struct file *file)
15596 + struct super_block *sb;
15597 + struct au_do_open_args args = {
15598 + .open = au_do_open_nondir
15601 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15602 + file, vfsub_file_flags(file), file->f_mode);
15604 + sb = file->f_path.dentry->d_sb;
15605 + si_read_lock(sb, AuLock_FLUSH);
15606 + err = au_do_open(file, &args);
15607 + si_read_unlock(sb);
15611 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15613 + struct au_finfo *finfo;
15614 + aufs_bindex_t bindex;
15616 + finfo = au_fi(file);
15617 + au_hbl_del(&finfo->fi_hlist,
15618 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15619 + bindex = finfo->fi_btop;
15621 + au_set_h_fptr(file, bindex, NULL);
15623 + au_finfo_fin(file);
15627 +/* ---------------------------------------------------------------------- */
15629 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15632 + struct file *h_file;
15635 + h_file = au_hf_top(file);
15637 + err = vfsub_flush(h_file, id);
15641 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15643 + return au_do_flush(file, id, au_do_flush_nondir);
15646 +/* ---------------------------------------------------------------------- */
15648 + * read and write functions acquire [fdi]_rwsem once, but release before
15649 + * mmap_sem. This is because to stop a race condition between mmap(2).
15650 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15651 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15652 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15655 +/* Callers should call au_read_post() or fput() in the end */
15656 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15658 + struct file *h_file;
15661 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15663 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15664 + h_file = au_hf_top(file);
15665 + get_file(h_file);
15667 + fi_read_unlock(file);
15669 + h_file = ERR_PTR(err);
15674 +static void au_read_post(struct inode *inode, struct file *h_file)
15676 + /* update without lock, I don't think it a problem */
15677 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15681 +struct au_write_pre {
15683 + unsigned int lsc;
15687 + aufs_bindex_t btop;
15691 + * return with iinfo is write-locked
15692 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15695 +static struct file *au_write_pre(struct file *file, int do_ready,
15696 + struct au_write_pre *wpre)
15698 + struct file *h_file;
15699 + struct dentry *dentry;
15701 + unsigned int lsc;
15702 + struct au_pin pin;
15707 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15708 + h_file = ERR_PTR(err);
15709 + if (unlikely(err))
15712 + dentry = file->f_path.dentry;
15714 + err = au_ready_to_write(file, -1, &pin);
15715 + if (unlikely(err)) {
15716 + h_file = ERR_PTR(err);
15717 + di_write_unlock(dentry);
15722 + di_downgrade_lock(dentry, /*flags*/0);
15724 + wpre->btop = au_fbtop(file);
15725 + h_file = au_hf_top(file);
15726 + get_file(h_file);
15728 + wpre->blks = file_inode(h_file)->i_blocks;
15731 + di_read_unlock(dentry, /*flags*/0);
15734 + fi_write_unlock(file);
15739 +static void au_write_post(struct inode *inode, struct file *h_file,
15740 + struct au_write_pre *wpre, ssize_t written)
15742 + struct inode *h_inode;
15744 + au_cpup_attr_timesizes(inode);
15745 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15746 + h_inode = file_inode(h_file);
15747 + inode->i_mode = h_inode->i_mode;
15748 + ii_write_unlock(inode);
15749 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15751 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15752 + /*force*/h_inode->i_blocks > wpre->blks);
15756 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15760 + struct inode *inode;
15761 + struct file *h_file;
15762 + struct super_block *sb;
15764 + inode = file_inode(file);
15765 + sb = inode->i_sb;
15766 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15768 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15769 + err = PTR_ERR(h_file);
15770 + if (IS_ERR(h_file))
15773 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15774 + err = vfsub_read_u(h_file, buf, count, ppos);
15775 + /* todo: necessary? */
15776 + /* file->f_ra = h_file->f_ra; */
15777 + au_read_post(inode, h_file);
15780 + si_read_unlock(sb);
15785 + * todo: very ugly
15786 + * it locks both of i_mutex and si_rwsem for read in safe.
15787 + * if the plink maintenance mode continues forever (that is the problem),
15788 + * may loop forever.
15790 +static void au_mtx_and_read_lock(struct inode *inode)
15793 + struct super_block *sb = inode->i_sb;
15796 + inode_lock(inode);
15797 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15800 + inode_unlock(inode);
15801 + si_read_lock(sb, AuLock_NOPLMW);
15802 + si_read_unlock(sb);
15806 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15807 + size_t count, loff_t *ppos)
15810 + struct au_write_pre wpre;
15811 + struct inode *inode;
15812 + struct file *h_file;
15813 + char __user *buf = (char __user *)ubuf;
15815 + inode = file_inode(file);
15816 + au_mtx_and_read_lock(inode);
15819 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15820 + err = PTR_ERR(h_file);
15821 + if (IS_ERR(h_file))
15824 + err = vfsub_write_u(h_file, buf, count, ppos);
15825 + au_write_post(inode, h_file, &wpre, err);
15828 + si_read_unlock(inode->i_sb);
15829 + inode_unlock(inode);
15833 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15834 + struct iov_iter *iov_iter)
15837 + struct file *file;
15838 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15840 + err = security_file_permission(h_file, rw);
15841 + if (unlikely(err))
15844 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15846 + if (rw == MAY_READ)
15847 + iter = h_file->f_op->read_iter;
15848 + else if (rw == MAY_WRITE)
15849 + iter = h_file->f_op->write_iter;
15851 + file = kio->ki_filp;
15852 + kio->ki_filp = h_file;
15855 + err = iter(kio, iov_iter);
15858 + /* currently there is no such fs */
15860 + kio->ki_filp = file;
15866 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15869 + struct file *file, *h_file;
15870 + struct inode *inode;
15871 + struct super_block *sb;
15873 + file = kio->ki_filp;
15874 + inode = file_inode(file);
15875 + sb = inode->i_sb;
15876 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15878 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15879 + err = PTR_ERR(h_file);
15880 + if (IS_ERR(h_file))
15883 + if (au_test_loopback_kthread()) {
15884 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15885 + if (file->f_mapping != h_file->f_mapping) {
15886 + file->f_mapping = h_file->f_mapping;
15887 + smp_mb(); /* unnecessary? */
15890 + fi_read_unlock(file);
15892 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15893 + /* todo: necessary? */
15894 + /* file->f_ra = h_file->f_ra; */
15895 + au_read_post(inode, h_file);
15898 + si_read_unlock(sb);
15902 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15905 + struct au_write_pre wpre;
15906 + struct inode *inode;
15907 + struct file *file, *h_file;
15909 + file = kio->ki_filp;
15910 + inode = file_inode(file);
15911 + au_mtx_and_read_lock(inode);
15914 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15915 + err = PTR_ERR(h_file);
15916 + if (IS_ERR(h_file))
15919 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15920 + au_write_post(inode, h_file, &wpre, err);
15923 + si_read_unlock(inode->i_sb);
15924 + inode_unlock(inode);
15928 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15929 + struct pipe_inode_info *pipe, size_t len,
15930 + unsigned int flags)
15933 + struct file *h_file;
15934 + struct inode *inode;
15935 + struct super_block *sb;
15937 + inode = file_inode(file);
15938 + sb = inode->i_sb;
15939 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15941 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15942 + err = PTR_ERR(h_file);
15943 + if (IS_ERR(h_file))
15946 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15947 + /* todo: necessary? */
15948 + /* file->f_ra = h_file->f_ra; */
15949 + au_read_post(inode, h_file);
15952 + si_read_unlock(sb);
15957 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15958 + size_t len, unsigned int flags)
15961 + struct au_write_pre wpre;
15962 + struct inode *inode;
15963 + struct file *h_file;
15965 + inode = file_inode(file);
15966 + au_mtx_and_read_lock(inode);
15969 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15970 + err = PTR_ERR(h_file);
15971 + if (IS_ERR(h_file))
15974 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15975 + au_write_post(inode, h_file, &wpre, err);
15978 + si_read_unlock(inode->i_sb);
15979 + inode_unlock(inode);
15983 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15987 + struct au_write_pre wpre;
15988 + struct inode *inode;
15989 + struct file *h_file;
15991 + inode = file_inode(file);
15992 + au_mtx_and_read_lock(inode);
15995 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15996 + err = PTR_ERR(h_file);
15997 + if (IS_ERR(h_file))
16001 + err = vfs_fallocate(h_file, mode, offset, len);
16003 + au_write_post(inode, h_file, &wpre, /*written*/1);
16006 + si_read_unlock(inode->i_sb);
16007 + inode_unlock(inode);
16011 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16012 + struct file *dst, loff_t dst_pos,
16013 + size_t len, unsigned int flags)
16016 + struct au_write_pre wpre;
16017 + enum { SRC, DST };
16019 + struct inode *inode;
16020 + struct file *h_file;
16021 + struct super_block *h_sb;
16023 +#define a_src a[SRC]
16024 +#define a_dst a[DST]
16027 + a_src.inode = file_inode(src);
16028 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16030 + a_dst.inode = file_inode(dst);
16031 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16034 + au_mtx_and_read_lock(a_dst.inode);
16036 + * in order to match the order in di_write_lock2_{child,parent}(),
16037 + * use f_path.dentry for this comparison.
16039 + if (src->f_path.dentry < dst->f_path.dentry) {
16040 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16041 + err = PTR_ERR(a_src.h_file);
16042 + if (IS_ERR(a_src.h_file))
16045 + wpre.lsc = AuLsc_FI_2;
16046 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16047 + err = PTR_ERR(a_dst.h_file);
16048 + if (IS_ERR(a_dst.h_file)) {
16049 + au_read_post(a_src.inode, a_src.h_file);
16053 + wpre.lsc = AuLsc_FI_1;
16054 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16055 + err = PTR_ERR(a_dst.h_file);
16056 + if (IS_ERR(a_dst.h_file))
16059 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16060 + err = PTR_ERR(a_src.h_file);
16061 + if (IS_ERR(a_src.h_file)) {
16062 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16069 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16070 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16071 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16077 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16078 + dst_pos, len, flags);
16081 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16082 + fi_read_unlock(src);
16083 + au_read_post(a_src.inode, a_src.h_file);
16085 + si_read_unlock(a_dst.inode->i_sb);
16086 + inode_unlock(a_dst.inode);
16093 +/* ---------------------------------------------------------------------- */
16096 + * The locking order around current->mmap_sem.
16097 + * - in most and regular cases
16098 + * file I/O syscall -- aufs_read() or something
16099 + * -- si_rwsem for read -- mmap_sem
16100 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16102 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16103 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16104 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16105 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16106 + * It means that when aufs acquires si_rwsem for write, the process should never
16107 + * acquire mmap_sem.
16109 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16110 + * problem either since any directory is not able to be mmap-ed.
16111 + * The similar scenario is applied to aufs_readlink() too.
16114 +#if 0 /* stop calling security_file_mmap() */
16115 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16116 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16118 +static unsigned long au_arch_prot_conv(unsigned long flags)
16120 + /* currently ppc64 only */
16121 +#ifdef CONFIG_PPC64
16122 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16123 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16124 + return AuConv_VM_PROT(flags, SAO);
16126 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16131 +static unsigned long au_prot_conv(unsigned long flags)
16133 + return AuConv_VM_PROT(flags, READ)
16134 + | AuConv_VM_PROT(flags, WRITE)
16135 + | AuConv_VM_PROT(flags, EXEC)
16136 + | au_arch_prot_conv(flags);
16139 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16140 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16142 +static unsigned long au_flag_conv(unsigned long flags)
16144 + return AuConv_VM_MAP(flags, GROWSDOWN)
16145 + | AuConv_VM_MAP(flags, DENYWRITE)
16146 + | AuConv_VM_MAP(flags, LOCKED);
16150 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16153 + const unsigned char wlock
16154 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16155 + struct super_block *sb;
16156 + struct file *h_file;
16157 + struct inode *inode;
16159 + AuDbgVmRegion(file, vma);
16161 + inode = file_inode(file);
16162 + sb = inode->i_sb;
16164 + si_read_lock(sb, AuLock_NOPLMW);
16166 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16168 + err = PTR_ERR(h_file);
16169 + if (IS_ERR(h_file))
16173 + au_set_mmapped(file);
16174 + au_vm_file_reset(vma, h_file);
16176 + * we cannot call security_mmap_file() here since it may acquire
16177 + * mmap_sem or i_mutex.
16179 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16180 + * au_flag_conv(vma->vm_flags));
16183 + err = call_mmap(h_file, vma);
16185 + au_vm_prfile_set(vma, file);
16186 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16187 + goto out_fput; /* success */
16189 + au_unset_mmapped(file);
16190 + au_vm_file_reset(vma, file);
16194 + ii_write_unlock(inode);
16199 + si_read_unlock(sb);
16205 +/* ---------------------------------------------------------------------- */
16207 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16211 + struct au_write_pre wpre;
16212 + struct inode *inode;
16213 + struct file *h_file;
16215 + err = 0; /* -EBADF; */ /* posix? */
16216 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16219 + inode = file_inode(file);
16220 + au_mtx_and_read_lock(inode);
16223 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16224 + err = PTR_ERR(h_file);
16225 + if (IS_ERR(h_file))
16228 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16229 + au_write_post(inode, h_file, &wpre, /*written*/0);
16232 + si_read_unlock(inode->i_sb);
16233 + inode_unlock(inode);
16238 +static int aufs_fasync(int fd, struct file *file, int flag)
16241 + struct file *h_file;
16242 + struct super_block *sb;
16244 + sb = file->f_path.dentry->d_sb;
16245 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16247 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16248 + err = PTR_ERR(h_file);
16249 + if (IS_ERR(h_file))
16252 + if (h_file->f_op->fasync)
16253 + err = h_file->f_op->fasync(fd, h_file, flag);
16254 + fput(h_file); /* instead of au_read_post() */
16257 + si_read_unlock(sb);
16261 +static int aufs_setfl(struct file *file, unsigned long arg)
16264 + struct file *h_file;
16265 + struct super_block *sb;
16267 + sb = file->f_path.dentry->d_sb;
16268 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16270 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16271 + err = PTR_ERR(h_file);
16272 + if (IS_ERR(h_file))
16275 + /* stop calling h_file->fasync */
16276 + arg |= vfsub_file_flags(file) & FASYNC;
16277 + err = setfl(/*unused fd*/-1, h_file, arg);
16278 + fput(h_file); /* instead of au_read_post() */
16281 + si_read_unlock(sb);
16285 +/* ---------------------------------------------------------------------- */
16287 +/* no one supports this operation, currently */
16288 +#if 0 /* reserved for future use */
16289 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16290 + size_t len, loff_t *pos, int more)
16295 +/* ---------------------------------------------------------------------- */
16297 +const struct file_operations aufs_file_fop = {
16298 + .owner = THIS_MODULE,
16300 + .llseek = default_llseek,
16302 + .read = aufs_read,
16303 + .write = aufs_write,
16304 + .read_iter = aufs_read_iter,
16305 + .write_iter = aufs_write_iter,
16307 +#ifdef CONFIG_AUFS_POLL
16308 + .poll = aufs_poll,
16310 + .unlocked_ioctl = aufs_ioctl_nondir,
16311 +#ifdef CONFIG_COMPAT
16312 + .compat_ioctl = aufs_compat_ioctl_nondir,
16314 + .mmap = aufs_mmap,
16315 + .open = aufs_open_nondir,
16316 + .flush = aufs_flush_nondir,
16317 + .release = aufs_release_nondir,
16318 + .fsync = aufs_fsync_nondir,
16319 + .fasync = aufs_fasync,
16320 + /* .sendpage = aufs_sendpage, */
16321 + .setfl = aufs_setfl,
16322 + .splice_write = aufs_splice_write,
16323 + .splice_read = aufs_splice_read,
16324 +#if 0 /* reserved for future use */
16325 + .aio_splice_write = aufs_aio_splice_write,
16326 + .aio_splice_read = aufs_aio_splice_read,
16328 + .fallocate = aufs_fallocate,
16329 + .copy_file_range = aufs_copy_file_range
16331 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16332 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16333 +++ linux/fs/aufs/fstype.h 2020-01-27 10:57:18.172204883 +0100
16335 +/* SPDX-License-Identifier: GPL-2.0 */
16337 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16339 + * This program, aufs is free software; you can redistribute it and/or modify
16340 + * it under the terms of the GNU General Public License as published by
16341 + * the Free Software Foundation; either version 2 of the License, or
16342 + * (at your option) any later version.
16344 + * This program is distributed in the hope that it will be useful,
16345 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16346 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16347 + * GNU General Public License for more details.
16349 + * You should have received a copy of the GNU General Public License
16350 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16354 + * judging filesystem type
16357 +#ifndef __AUFS_FSTYPE_H__
16358 +#define __AUFS_FSTYPE_H__
16362 +#include <linux/fs.h>
16363 +#include <linux/magic.h>
16364 +#include <linux/nfs_fs.h>
16365 +#include <linux/romfs_fs.h>
16367 +static inline int au_test_aufs(struct super_block *sb)
16369 + return sb->s_magic == AUFS_SUPER_MAGIC;
16372 +static inline const char *au_sbtype(struct super_block *sb)
16374 + return sb->s_type->name;
16377 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16379 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16380 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16386 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16388 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16389 + return sb->s_magic == ROMFS_MAGIC;
16395 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16397 +#if IS_ENABLED(CONFIG_CRAMFS)
16398 + return sb->s_magic == CRAMFS_MAGIC;
16403 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16405 +#if IS_ENABLED(CONFIG_NFS_FS)
16406 + return sb->s_magic == NFS_SUPER_MAGIC;
16412 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16414 +#if IS_ENABLED(CONFIG_FUSE_FS)
16415 + return sb->s_magic == FUSE_SUPER_MAGIC;
16421 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16423 +#if IS_ENABLED(CONFIG_XFS_FS)
16424 + return sb->s_magic == XFS_SB_MAGIC;
16430 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16432 +#ifdef CONFIG_TMPFS
16433 + return sb->s_magic == TMPFS_MAGIC;
16439 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16441 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16442 + return !strcmp(au_sbtype(sb), "ecryptfs");
16448 +static inline int au_test_ramfs(struct super_block *sb)
16450 + return sb->s_magic == RAMFS_MAGIC;
16453 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16455 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16456 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16462 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16464 +#ifdef CONFIG_PROC_FS
16465 + return sb->s_magic == PROC_SUPER_MAGIC;
16471 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16473 +#ifdef CONFIG_SYSFS
16474 + return sb->s_magic == SYSFS_MAGIC;
16480 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16482 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16483 + return sb->s_magic == CONFIGFS_MAGIC;
16489 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16491 +#if IS_ENABLED(CONFIG_MINIX_FS)
16492 + return sb->s_magic == MINIX3_SUPER_MAGIC
16493 + || sb->s_magic == MINIX2_SUPER_MAGIC
16494 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16495 + || sb->s_magic == MINIX_SUPER_MAGIC
16496 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16502 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16504 +#if IS_ENABLED(CONFIG_FAT_FS)
16505 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16511 +static inline int au_test_msdos(struct super_block *sb)
16513 + return au_test_fat(sb);
16516 +static inline int au_test_vfat(struct super_block *sb)
16518 + return au_test_fat(sb);
16521 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16523 +#ifdef CONFIG_SECURITYFS
16524 + return sb->s_magic == SECURITYFS_MAGIC;
16530 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16532 +#if IS_ENABLED(CONFIG_SQUASHFS)
16533 + return sb->s_magic == SQUASHFS_MAGIC;
16539 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16541 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16542 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16548 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16550 +#if IS_ENABLED(CONFIG_XENFS)
16551 + return sb->s_magic == XENFS_SUPER_MAGIC;
16557 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16559 +#ifdef CONFIG_DEBUG_FS
16560 + return sb->s_magic == DEBUGFS_MAGIC;
16566 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16568 +#if IS_ENABLED(CONFIG_NILFS)
16569 + return sb->s_magic == NILFS_SUPER_MAGIC;
16575 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16577 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16578 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16584 +/* ---------------------------------------------------------------------- */
16586 + * they can't be an aufs branch.
16588 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16591 +#ifndef CONFIG_AUFS_BR_RAMFS
16592 + au_test_ramfs(sb) ||
16594 + au_test_procfs(sb)
16595 + || au_test_sysfs(sb)
16596 + || au_test_configfs(sb)
16597 + || au_test_debugfs(sb)
16598 + || au_test_securityfs(sb)
16599 + || au_test_xenfs(sb)
16600 + || au_test_ecryptfs(sb)
16601 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16602 + || au_test_aufs(sb); /* will be supported in next version */
16605 +static inline int au_test_fs_remote(struct super_block *sb)
16607 + return !au_test_tmpfs(sb)
16608 +#ifdef CONFIG_AUFS_BR_RAMFS
16609 + && !au_test_ramfs(sb)
16611 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16614 +/* ---------------------------------------------------------------------- */
16617 + * Note: these functions (below) are created after reading ->getattr() in all
16618 + * filesystems under linux/fs. it means we have to do so in every update...
16622 + * some filesystems require getattr to refresh the inode attributes before
16624 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16625 + * and leave the work for d_revalidate()
16627 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16629 + return au_test_nfs(sb)
16630 + || au_test_fuse(sb)
16631 + /* || au_test_btrfs(sb) */ /* untested */
16636 + * filesystems which don't maintain i_size or i_blocks.
16638 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16640 + return au_test_xfs(sb)
16641 + || au_test_btrfs(sb)
16642 + || au_test_ubifs(sb)
16643 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16644 + /* || au_test_minix(sb) */ /* untested */
16649 + * filesystems which don't store the correct value in some of their inode
16652 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16654 + return au_test_fs_bad_iattr_size(sb)
16655 + || au_test_fat(sb)
16656 + || au_test_msdos(sb)
16657 + || au_test_vfat(sb);
16660 +/* they don't check i_nlink in link(2) */
16661 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16663 + return au_test_tmpfs(sb)
16664 +#ifdef CONFIG_AUFS_BR_RAMFS
16665 + || au_test_ramfs(sb)
16667 + || au_test_ubifs(sb)
16668 + || au_test_hfsplus(sb);
16672 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16674 +static inline int au_test_fs_notime(struct super_block *sb)
16676 + return au_test_nfs(sb)
16677 + || au_test_fuse(sb)
16678 + || au_test_ubifs(sb)
16682 +/* temporary support for i#1 in cramfs */
16683 +static inline int au_test_fs_unique_ino(struct inode *inode)
16685 + if (au_test_cramfs(inode->i_sb))
16686 + return inode->i_ino != 1;
16690 +/* ---------------------------------------------------------------------- */
16693 + * the filesystem where the xino files placed must support i/o after unlink and
16694 + * maintain i_size and i_blocks.
16696 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16698 + return au_test_fs_remote(sb)
16699 + || au_test_fs_bad_iattr_size(sb)
16700 + /* don't want unnecessary work for xino */
16701 + || au_test_aufs(sb)
16702 + || au_test_ecryptfs(sb)
16703 + || au_test_nilfs(sb);
16706 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16708 + return au_test_tmpfs(sb)
16709 + || au_test_ramfs(sb);
16713 + * test if the @sb is real-readonly.
16715 +static inline int au_test_fs_rr(struct super_block *sb)
16717 + return au_test_squashfs(sb)
16718 + || au_test_iso9660(sb)
16719 + || au_test_cramfs(sb)
16720 + || au_test_romfs(sb);
16724 + * test if the @inode is nfs with 'noacl' option
16725 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16727 +static inline int au_test_nfs_noacl(struct inode *inode)
16729 + return au_test_nfs(inode->i_sb)
16730 + /* && IS_POSIXACL(inode) */
16731 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16734 +#endif /* __KERNEL__ */
16735 +#endif /* __AUFS_FSTYPE_H__ */
16736 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16737 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16738 +++ linux/fs/aufs/hbl.h 2020-01-27 10:57:18.172204883 +0100
16740 +/* SPDX-License-Identifier: GPL-2.0 */
16742 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16744 + * This program, aufs is free software; you can redistribute it and/or modify
16745 + * it under the terms of the GNU General Public License as published by
16746 + * the Free Software Foundation; either version 2 of the License, or
16747 + * (at your option) any later version.
16749 + * This program is distributed in the hope that it will be useful,
16750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16752 + * GNU General Public License for more details.
16754 + * You should have received a copy of the GNU General Public License
16755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16759 + * helpers for hlist_bl.h
16762 +#ifndef __AUFS_HBL_H__
16763 +#define __AUFS_HBL_H__
16767 +#include <linux/list_bl.h>
16769 +static inline void au_hbl_add(struct hlist_bl_node *node,
16770 + struct hlist_bl_head *hbl)
16772 + hlist_bl_lock(hbl);
16773 + hlist_bl_add_head(node, hbl);
16774 + hlist_bl_unlock(hbl);
16777 +static inline void au_hbl_del(struct hlist_bl_node *node,
16778 + struct hlist_bl_head *hbl)
16780 + hlist_bl_lock(hbl);
16781 + hlist_bl_del(node);
16782 + hlist_bl_unlock(hbl);
16785 +#define au_hbl_for_each(pos, head) \
16786 + for (pos = hlist_bl_first(head); \
16790 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16792 + unsigned long cnt;
16793 + struct hlist_bl_node *pos;
16796 + hlist_bl_lock(hbl);
16797 + au_hbl_for_each(pos, hbl)
16799 + hlist_bl_unlock(hbl);
16803 +#endif /* __KERNEL__ */
16804 +#endif /* __AUFS_HBL_H__ */
16805 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16806 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16807 +++ linux/fs/aufs/hfsnotify.c 2020-01-27 10:57:18.172204883 +0100
16809 +// SPDX-License-Identifier: GPL-2.0
16811 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16813 + * This program, aufs is free software; you can redistribute it and/or modify
16814 + * it under the terms of the GNU General Public License as published by
16815 + * the Free Software Foundation; either version 2 of the License, or
16816 + * (at your option) any later version.
16818 + * This program is distributed in the hope that it will be useful,
16819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16821 + * GNU General Public License for more details.
16823 + * You should have received a copy of the GNU General Public License
16824 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16828 + * fsnotify for the lower directories
16833 +/* FS_IN_IGNORED is unnecessary */
16834 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16835 + | FS_CREATE | FS_EVENT_ON_CHILD);
16836 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16837 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16839 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16841 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16843 + /* AuDbg("here\n"); */
16844 + au_cache_free_hnotify(hn);
16845 + smp_mb__before_atomic(); /* for atomic64_dec */
16846 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16847 + wake_up(&au_hfsn_wq);
16850 +static int au_hfsn_alloc(struct au_hinode *hinode)
16853 + struct au_hnotify *hn;
16854 + struct super_block *sb;
16855 + struct au_branch *br;
16856 + struct fsnotify_mark *mark;
16857 + aufs_bindex_t bindex;
16859 + hn = hinode->hi_notify;
16860 + sb = hn->hn_aufs_inode->i_sb;
16861 + bindex = au_br_index(sb, hinode->hi_id);
16862 + br = au_sbr(sb, bindex);
16863 + AuDebugOn(!br->br_hfsn);
16865 + mark = &hn->hn_mark;
16866 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16867 + mark->mask = AuHfsnMask;
16869 + * by udba rename or rmdir, aufs assign a new inode to the known
16870 + * h_inode, so specify 1 to allow dups.
16873 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16879 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16881 + struct fsnotify_mark *mark;
16882 + unsigned long long ull;
16883 + struct fsnotify_group *group;
16885 + ull = atomic64_inc_return(&au_hfsn_ifree);
16888 + mark = &hn->hn_mark;
16889 + spin_lock(&mark->lock);
16890 + group = mark->group;
16891 + fsnotify_get_group(group);
16892 + spin_unlock(&mark->lock);
16894 + fsnotify_destroy_mark(mark, group);
16895 + fsnotify_put_mark(mark);
16896 + fsnotify_put_group(group);
16899 + /* free hn by myself */
16903 +/* ---------------------------------------------------------------------- */
16905 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16907 + struct fsnotify_mark *mark;
16909 + mark = &hinode->hi_notify->hn_mark;
16910 + spin_lock(&mark->lock);
16912 + AuDebugOn(mark->mask & AuHfsnMask);
16913 + mark->mask |= AuHfsnMask;
16915 + AuDebugOn(!(mark->mask & AuHfsnMask));
16916 + mark->mask &= ~AuHfsnMask;
16918 + spin_unlock(&mark->lock);
16919 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16922 +/* ---------------------------------------------------------------------- */
16924 +/* #define AuDbgHnotify */
16925 +#ifdef AuDbgHnotify
16926 +static char *au_hfsn_name(u32 mask)
16928 +#ifdef CONFIG_AUFS_DEBUG
16929 +#define test_ret(flag) \
16931 + if (mask & flag) \
16934 + test_ret(FS_ACCESS);
16935 + test_ret(FS_MODIFY);
16936 + test_ret(FS_ATTRIB);
16937 + test_ret(FS_CLOSE_WRITE);
16938 + test_ret(FS_CLOSE_NOWRITE);
16939 + test_ret(FS_OPEN);
16940 + test_ret(FS_MOVED_FROM);
16941 + test_ret(FS_MOVED_TO);
16942 + test_ret(FS_CREATE);
16943 + test_ret(FS_DELETE);
16944 + test_ret(FS_DELETE_SELF);
16945 + test_ret(FS_MOVE_SELF);
16946 + test_ret(FS_UNMOUNT);
16947 + test_ret(FS_Q_OVERFLOW);
16948 + test_ret(FS_IN_IGNORED);
16949 + test_ret(FS_ISDIR);
16950 + test_ret(FS_IN_ONESHOT);
16951 + test_ret(FS_EVENT_ON_CHILD);
16960 +/* ---------------------------------------------------------------------- */
16962 +static void au_hfsn_free_group(struct fsnotify_group *group)
16964 + struct au_br_hfsnotify *hfsn = group->private;
16966 + /* AuDbg("here\n"); */
16967 + au_kfree_try_rcu(hfsn);
16970 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16971 + struct inode *inode,
16972 + u32 mask, const void *data, int data_type,
16973 + const struct qstr *file_name, u32 cookie,
16974 + struct fsnotify_iter_info *iter_info)
16977 + struct au_hnotify *hnotify;
16978 + struct inode *h_dir, *h_inode;
16979 + struct fsnotify_mark *inode_mark;
16981 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16984 + /* if FS_UNMOUNT happens, there must be another bug */
16985 + AuDebugOn(mask & FS_UNMOUNT);
16986 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16991 +#ifdef AuDbgHnotify
16993 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16994 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16995 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16996 + h_dir->i_ino, mask, au_hfsn_name(mask),
16997 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16998 + /* WARN_ON(1); */
17003 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17004 + AuDebugOn(!inode_mark);
17005 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17006 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
17012 +static struct fsnotify_ops au_hfsn_ops = {
17013 + .handle_event = au_hfsn_handle_event,
17014 + .free_group_priv = au_hfsn_free_group,
17015 + .free_mark = au_hfsn_free_mark
17018 +/* ---------------------------------------------------------------------- */
17020 +static void au_hfsn_fin_br(struct au_branch *br)
17022 + struct au_br_hfsnotify *hfsn;
17024 + hfsn = br->br_hfsn;
17027 + fsnotify_put_group(hfsn->hfsn_group);
17032 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17035 + struct fsnotify_group *group;
17036 + struct au_br_hfsnotify *hfsn;
17039 + br->br_hfsn = NULL;
17040 + if (!au_br_hnotifyable(perm))
17044 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17045 + if (unlikely(!hfsn))
17049 + group = fsnotify_alloc_group(&au_hfsn_ops);
17050 + if (IS_ERR(group)) {
17051 + err = PTR_ERR(group);
17052 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17056 + group->private = hfsn;
17057 + hfsn->hfsn_group = group;
17058 + br->br_hfsn = hfsn;
17059 + goto out; /* success */
17062 + au_kfree_try_rcu(hfsn);
17067 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17072 + if (!br->br_hfsn)
17073 + err = au_hfsn_init_br(br, perm);
17078 +/* ---------------------------------------------------------------------- */
17080 +static void au_hfsn_fin(void)
17082 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17083 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17086 +const struct au_hnotify_op au_hnotify_op = {
17087 + .ctl = au_hfsn_ctl,
17088 + .alloc = au_hfsn_alloc,
17089 + .free = au_hfsn_free,
17091 + .fin = au_hfsn_fin,
17093 + .reset_br = au_hfsn_reset_br,
17094 + .fin_br = au_hfsn_fin_br,
17095 + .init_br = au_hfsn_init_br
17097 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17098 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17099 +++ linux/fs/aufs/hfsplus.c 2020-01-27 10:57:18.172204883 +0100
17101 +// SPDX-License-Identifier: GPL-2.0
17103 + * Copyright (C) 2010-2020 Junjiro R. Okajima
17105 + * This program, aufs is free software; you can redistribute it and/or modify
17106 + * it under the terms of the GNU General Public License as published by
17107 + * the Free Software Foundation; either version 2 of the License, or
17108 + * (at your option) any later version.
17110 + * This program is distributed in the hope that it will be useful,
17111 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17112 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17113 + * GNU General Public License for more details.
17115 + * You should have received a copy of the GNU General Public License
17116 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17120 + * special support for filesystems which acquires an inode mutex
17121 + * at final closing a file, eg, hfsplus.
17123 + * This trick is very simple and stupid, just to open the file before really
17124 + * necessary open to tell hfsplus that this is not the final closing.
17125 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17126 + * and au_h_open_post() after releasing it.
17131 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17134 + struct file *h_file;
17135 + struct dentry *h_dentry;
17137 + h_dentry = au_h_dptr(dentry, bindex);
17138 + AuDebugOn(!h_dentry);
17139 + AuDebugOn(d_is_negative(h_dentry));
17142 + if (au_test_hfsplus(h_dentry->d_sb)
17143 + && d_is_reg(h_dentry))
17144 + h_file = au_h_open(dentry, bindex,
17145 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17146 + /*file*/NULL, force_wr);
17150 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17151 + struct file *h_file)
17153 + struct au_branch *br;
17157 + br = au_sbr(dentry->d_sb, bindex);
17158 + au_lcnt_dec(&br->br_nfiles);
17161 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17162 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17163 +++ linux/fs/aufs/hnotify.c 2020-01-27 10:57:18.172204883 +0100
17165 +// SPDX-License-Identifier: GPL-2.0
17167 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17169 + * This program, aufs is free software; you can redistribute it and/or modify
17170 + * it under the terms of the GNU General Public License as published by
17171 + * the Free Software Foundation; either version 2 of the License, or
17172 + * (at your option) any later version.
17174 + * This program is distributed in the hope that it will be useful,
17175 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17176 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17177 + * GNU General Public License for more details.
17179 + * You should have received a copy of the GNU General Public License
17180 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17184 + * abstraction to notify the direct changes on lower directories
17187 +/* #include <linux/iversion.h> */
17190 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17193 + struct au_hnotify *hn;
17196 + hn = au_cache_alloc_hnotify();
17198 + hn->hn_aufs_inode = inode;
17199 + hinode->hi_notify = hn;
17200 + err = au_hnotify_op.alloc(hinode);
17202 + if (unlikely(err)) {
17203 + hinode->hi_notify = NULL;
17204 + au_cache_free_hnotify(hn);
17206 + * The upper dir was removed by udba, but the same named
17207 + * dir left. In this case, aufs assigns a new inode
17208 + * number and set the monitor again.
17209 + * For the lower dir, the old monitor is still left.
17211 + if (err == -EEXIST)
17220 +void au_hn_free(struct au_hinode *hinode)
17222 + struct au_hnotify *hn;
17224 + hn = hinode->hi_notify;
17226 + hinode->hi_notify = NULL;
17227 + if (au_hnotify_op.free(hinode, hn))
17228 + au_cache_free_hnotify(hn);
17232 +/* ---------------------------------------------------------------------- */
17234 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17236 + if (hinode->hi_notify)
17237 + au_hnotify_op.ctl(hinode, do_set);
17240 +void au_hn_reset(struct inode *inode, unsigned int flags)
17242 + aufs_bindex_t bindex, bbot;
17243 + struct inode *hi;
17244 + struct dentry *iwhdentry;
17246 + bbot = au_ibbot(inode);
17247 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17248 + hi = au_h_iptr(inode, bindex);
17252 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17253 + iwhdentry = au_hi_wh(inode, bindex);
17257 + au_set_h_iptr(inode, bindex, NULL, 0);
17258 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17259 + flags & ~AuHi_XINO);
17262 + /* inode_unlock(hi); */
17266 +/* ---------------------------------------------------------------------- */
17268 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17271 + aufs_bindex_t bindex, bbot, bfound, btop;
17272 + struct inode *h_i;
17275 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17276 + pr_warn("branch root dir was changed\n");
17281 + bbot = au_ibbot(inode);
17282 + btop = au_ibtop(inode);
17283 +#if 0 /* reserved for future use */
17284 + if (bindex == bbot) {
17285 + /* keep this ino in rename case */
17289 + for (bindex = btop; bindex <= bbot; bindex++)
17290 + if (au_h_iptr(inode, bindex) == h_inode) {
17297 + for (bindex = btop; bindex <= bbot; bindex++) {
17298 + h_i = au_h_iptr(inode, bindex);
17302 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17303 + /* ignore this error */
17304 + /* bad action? */
17307 + /* children inode number will be broken */
17314 +static int hn_gen_tree(struct dentry *dentry)
17316 + int err, i, j, ndentry;
17317 + struct au_dcsub_pages dpages;
17318 + struct au_dpage *dpage;
17319 + struct dentry **dentries;
17321 + err = au_dpages_init(&dpages, GFP_NOFS);
17322 + if (unlikely(err))
17324 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17325 + if (unlikely(err))
17328 + for (i = 0; i < dpages.ndpage; i++) {
17329 + dpage = dpages.dpages + i;
17330 + dentries = dpage->dentries;
17331 + ndentry = dpage->ndentry;
17332 + for (j = 0; j < ndentry; j++) {
17333 + struct dentry *d;
17340 + if (d_really_is_positive(d))
17341 + /* todo: reset children xino?
17342 + cached children only? */
17343 + au_iigen_dec(d_inode(d));
17348 + au_dpages_free(&dpages);
17354 + * return 0 if processed.
17356 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17357 + const unsigned int isdir)
17360 + struct dentry *d;
17361 + struct qstr *dname;
17364 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17365 + pr_warn("branch root dir was changed\n");
17371 + AuDebugOn(!name);
17372 + au_iigen_dec(inode);
17373 + spin_lock(&inode->i_lock);
17374 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17375 + spin_lock(&d->d_lock);
17376 + dname = &d->d_name;
17377 + if (dname->len != nlen
17378 + && memcmp(dname->name, name, nlen)) {
17379 + spin_unlock(&d->d_lock);
17384 + spin_unlock(&d->d_lock);
17387 + spin_unlock(&inode->i_lock);
17389 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17390 + d = d_find_any_alias(inode);
17392 + au_iigen_dec(inode);
17396 + spin_lock(&d->d_lock);
17397 + dname = &d->d_name;
17398 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17399 + spin_unlock(&d->d_lock);
17400 + err = hn_gen_tree(d);
17401 + spin_lock(&d->d_lock);
17403 + spin_unlock(&d->d_lock);
17412 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17416 + if (IS_ROOT(dentry)) {
17417 + pr_warn("branch root dir was changed\n");
17423 + au_digen_dec(dentry);
17424 + if (d_really_is_positive(dentry))
17425 + au_iigen_dec(d_inode(dentry));
17427 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17428 + if (d_really_is_positive(dentry))
17429 + err = hn_gen_tree(dentry);
17436 +/* ---------------------------------------------------------------------- */
17438 +/* hnotify job flags */
17439 +#define AuHnJob_XINO0 1
17440 +#define AuHnJob_GEN (1 << 1)
17441 +#define AuHnJob_DIRENT (1 << 2)
17442 +#define AuHnJob_ISDIR (1 << 3)
17443 +#define AuHnJob_TRYXINO0 (1 << 4)
17444 +#define AuHnJob_MNTPNT (1 << 5)
17445 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17446 +#define au_fset_hnjob(flags, name) \
17447 + do { (flags) |= AuHnJob_##name; } while (0)
17448 +#define au_fclr_hnjob(flags, name) \
17449 + do { (flags) &= ~AuHnJob_##name; } while (0)
17457 +struct au_hnotify_args {
17458 + struct inode *h_dir, *dir, *h_child_inode;
17460 + unsigned int flags[AuHnLast];
17461 + unsigned int h_child_nlen;
17462 + char h_child_name[];
17465 +struct hn_job_args {
17466 + unsigned int flags;
17467 + struct inode *inode, *h_inode, *dir, *h_dir;
17468 + struct dentry *dentry;
17473 +static int hn_job(struct hn_job_args *a)
17475 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17479 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17480 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17482 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17485 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17486 + if (!a->h_inode->i_nlink
17487 + && !(a->h_inode->i_state & I_LINKABLE))
17488 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17489 + inode_unlock_shared(a->h_inode);
17492 + /* make the generation obsolete */
17493 + if (au_ftest_hnjob(a->flags, GEN)) {
17496 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17498 + if (e && a->dentry)
17499 + hn_gen_by_name(a->dentry, isdir);
17500 + /* ignore this error */
17503 + /* make dir entries obsolete */
17504 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17505 + struct au_vdir *vdir;
17507 + vdir = au_ivdir(a->inode);
17509 + vdir->vd_jiffy = 0;
17510 + /* IMustLock(a->inode); */
17511 + /* inode_inc_iversion(a->inode); */
17514 + /* can do nothing but warn */
17515 + if (au_ftest_hnjob(a->flags, MNTPNT)
17517 + && d_mountpoint(a->dentry))
17518 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17523 +/* ---------------------------------------------------------------------- */
17525 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17526 + struct inode *dir)
17528 + struct dentry *dentry, *d, *parent;
17529 + struct qstr *dname;
17531 + parent = d_find_any_alias(dir);
17536 + spin_lock(&parent->d_lock);
17537 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17538 + /* AuDbg("%pd\n", d); */
17539 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17540 + dname = &d->d_name;
17541 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17542 + goto cont_unlock;
17546 + goto cont_unlock;
17547 + if (au_dcount(d) > 0) {
17548 + dentry = dget_dlock(d);
17549 + spin_unlock(&d->d_lock);
17554 + spin_unlock(&d->d_lock);
17556 + spin_unlock(&parent->d_lock);
17560 + di_write_lock_child(dentry);
17565 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17566 + aufs_bindex_t bindex, ino_t h_ino)
17568 + struct inode *inode;
17573 + err = au_xino_read(sb, bindex, h_ino, &ino);
17575 + inode = ilookup(sb, ino);
17579 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17580 + pr_warn("wrong root branch\n");
17586 + ii_write_lock_child(inode);
17592 +static void au_hn_bh(void *_args)
17594 + struct au_hnotify_args *a = _args;
17595 + struct super_block *sb;
17596 + aufs_bindex_t bindex, bbot, bfound;
17597 + unsigned char xino, try_iput;
17599 + struct inode *inode;
17601 + struct hn_job_args args;
17602 + struct dentry *dentry;
17603 + struct au_sbinfo *sbinfo;
17605 + AuDebugOn(!_args);
17606 + AuDebugOn(!a->h_dir);
17607 + AuDebugOn(!a->dir);
17608 + AuDebugOn(!a->mask);
17609 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17610 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17611 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17616 + * do not lock a->dir->i_mutex here
17617 + * because of d_revalidate() may cause a deadlock.
17619 + sb = a->dir->i_sb;
17621 + sbinfo = au_sbi(sb);
17622 + AuDebugOn(!sbinfo);
17623 + si_write_lock(sb, AuLock_NOPLMW);
17625 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17626 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17627 + case FS_MOVED_FROM:
17628 + case FS_MOVED_TO:
17629 + AuWarn1("DIRREN with UDBA may not work correctly "
17630 + "for the direct rename(2)\n");
17633 + ii_read_lock_parent(a->dir);
17635 + bbot = au_ibbot(a->dir);
17636 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17637 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17641 + ii_read_unlock(a->dir);
17642 + if (unlikely(bfound < 0))
17645 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17647 + if (a->h_child_inode)
17648 + h_ino = a->h_child_inode->i_ino;
17650 + if (a->h_child_nlen
17651 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17652 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17653 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17656 + if (dentry && d_really_is_positive(dentry))
17657 + inode = d_inode(dentry);
17658 + if (xino && !inode && h_ino
17659 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17660 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17661 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17662 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17666 + args.flags = a->flags[AuHn_CHILD];
17667 + args.dentry = dentry;
17668 + args.inode = inode;
17669 + args.h_inode = a->h_child_inode;
17670 + args.dir = a->dir;
17671 + args.h_dir = a->h_dir;
17672 + args.h_name = a->h_child_name;
17673 + args.h_nlen = a->h_child_nlen;
17674 + err = hn_job(&args);
17676 + if (au_di(dentry))
17677 + di_write_unlock(dentry);
17680 + if (inode && try_iput) {
17681 + ii_write_unlock(inode);
17685 + ii_write_lock_parent(a->dir);
17686 + args.flags = a->flags[AuHn_PARENT];
17687 + args.dentry = NULL;
17688 + args.inode = a->dir;
17689 + args.h_inode = a->h_dir;
17691 + args.h_dir = NULL;
17692 + args.h_name = NULL;
17694 + err = hn_job(&args);
17695 + ii_write_unlock(a->dir);
17698 + iput(a->h_child_inode);
17701 + si_write_unlock(sb);
17702 + au_nwt_done(&sbinfo->si_nowait);
17706 +/* ---------------------------------------------------------------------- */
17708 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17709 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17712 + unsigned int flags[AuHnLast], f;
17713 + unsigned char isdir, isroot, wh;
17714 + struct inode *dir;
17715 + struct au_hnotify_args *args;
17716 + char *p, *h_child_name;
17719 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17720 + dir = igrab(hnotify->hn_aufs_inode);
17724 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17726 + h_child_name = (void *)h_child_qstr->name;
17727 + len = h_child_qstr->len;
17728 + if (h_child_name) {
17729 + if (len > AUFS_WH_PFX_LEN
17730 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17731 + h_child_name += AUFS_WH_PFX_LEN;
17732 + len -= AUFS_WH_PFX_LEN;
17738 + if (h_child_inode)
17739 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17740 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17741 + flags[AuHn_CHILD] = 0;
17743 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17744 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17745 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17746 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17747 + case FS_MOVED_FROM:
17748 + case FS_MOVED_TO:
17749 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17750 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17753 + AuDebugOn(!h_child_name);
17758 + * aufs never be able to get this child inode.
17759 + * revalidation should be in d_revalidate()
17760 + * by checking i_nlink, i_generation or d_unhashed().
17762 + AuDebugOn(!h_child_name);
17763 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17764 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17772 + h_child_inode = NULL;
17775 + /* iput() and kfree() will be called in au_hnotify() */
17776 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17777 + if (unlikely(!args)) {
17778 + AuErr1("no memory\n");
17782 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17783 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17784 + args->mask = mask;
17786 + args->h_dir = igrab(h_dir);
17787 + if (h_child_inode)
17788 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17789 + args->h_child_inode = h_child_inode;
17790 + args->h_child_nlen = len;
17792 + p = (void *)args;
17793 + p += sizeof(*args);
17794 + memcpy(p, h_child_name, len);
17798 + /* NFS fires the event for silly-renamed one from kworker */
17800 + if (!dir->i_nlink
17801 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17803 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17804 + if (unlikely(err)) {
17805 + pr_err("wkq %d\n", err);
17806 + iput(args->h_child_inode);
17807 + iput(args->h_dir);
17809 + au_kfree_rcu(args);
17816 +/* ---------------------------------------------------------------------- */
17818 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17822 + AuDebugOn(!(udba & AuOptMask_UDBA));
17825 + if (au_hnotify_op.reset_br)
17826 + err = au_hnotify_op.reset_br(udba, br, perm);
17831 +int au_hnotify_init_br(struct au_branch *br, int perm)
17836 + if (au_hnotify_op.init_br)
17837 + err = au_hnotify_op.init_br(br, perm);
17842 +void au_hnotify_fin_br(struct au_branch *br)
17844 + if (au_hnotify_op.fin_br)
17845 + au_hnotify_op.fin_br(br);
17848 +static void au_hn_destroy_cache(void)
17850 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17851 + au_cache[AuCache_HNOTIFY] = NULL;
17854 +int __init au_hnotify_init(void)
17859 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17860 + if (au_cache[AuCache_HNOTIFY]) {
17862 + if (au_hnotify_op.init)
17863 + err = au_hnotify_op.init();
17864 + if (unlikely(err))
17865 + au_hn_destroy_cache();
17871 +void au_hnotify_fin(void)
17873 + if (au_hnotify_op.fin)
17874 + au_hnotify_op.fin();
17876 + /* cf. au_cache_fin() */
17877 + if (au_cache[AuCache_HNOTIFY])
17878 + au_hn_destroy_cache();
17880 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17881 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17882 +++ linux/fs/aufs/iinfo.c 2020-01-27 10:57:18.175538316 +0100
17884 +// SPDX-License-Identifier: GPL-2.0
17886 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17888 + * This program, aufs is free software; you can redistribute it and/or modify
17889 + * it under the terms of the GNU General Public License as published by
17890 + * the Free Software Foundation; either version 2 of the License, or
17891 + * (at your option) any later version.
17893 + * This program is distributed in the hope that it will be useful,
17894 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17895 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17896 + * GNU General Public License for more details.
17898 + * You should have received a copy of the GNU General Public License
17899 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17903 + * inode private data
17908 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17910 + struct inode *h_inode;
17911 + struct au_hinode *hinode;
17913 + IiMustAnyLock(inode);
17915 + hinode = au_hinode(au_ii(inode), bindex);
17916 + h_inode = hinode->hi_inode;
17917 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17921 +/* todo: hard/soft set? */
17922 +void au_hiput(struct au_hinode *hinode)
17924 + au_hn_free(hinode);
17925 + dput(hinode->hi_whdentry);
17926 + iput(hinode->hi_inode);
17929 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17931 + unsigned int flags;
17932 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17935 + if (au_opt_test(mnt_flags, XINO))
17936 + au_fset_hi(flags, XINO);
17937 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17938 + au_fset_hi(flags, HNOTIFY);
17942 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17943 + struct inode *h_inode, unsigned int flags)
17945 + struct au_hinode *hinode;
17946 + struct inode *hi;
17947 + struct au_iinfo *iinfo = au_ii(inode);
17949 + IiMustWriteLock(inode);
17951 + hinode = au_hinode(iinfo, bindex);
17952 + hi = hinode->hi_inode;
17953 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17956 + au_hiput(hinode);
17957 + hinode->hi_inode = h_inode;
17960 + struct super_block *sb = inode->i_sb;
17961 + struct au_branch *br;
17963 + AuDebugOn(inode->i_mode
17964 + && (h_inode->i_mode & S_IFMT)
17965 + != (inode->i_mode & S_IFMT));
17966 + if (bindex == iinfo->ii_btop)
17967 + au_cpup_igen(inode, h_inode);
17968 + br = au_sbr(sb, bindex);
17969 + hinode->hi_id = br->br_id;
17970 + if (au_ftest_hi(flags, XINO)) {
17971 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17973 + if (unlikely(err))
17974 + AuIOErr1("failed au_xino_write() %d\n", err);
17977 + if (au_ftest_hi(flags, HNOTIFY)
17978 + && au_br_hnotifyable(br->br_perm)) {
17979 + err = au_hn_alloc(hinode, inode);
17980 + if (unlikely(err))
17981 + AuIOErr1("au_hn_alloc() %d\n", err);
17986 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17987 + struct dentry *h_wh)
17989 + struct au_hinode *hinode;
17991 + IiMustWriteLock(inode);
17993 + hinode = au_hinode(au_ii(inode), bindex);
17994 + AuDebugOn(hinode->hi_whdentry);
17995 + hinode->hi_whdentry = h_wh;
17998 +void au_update_iigen(struct inode *inode, int half)
18000 + struct au_iinfo *iinfo;
18001 + struct au_iigen *iigen;
18002 + unsigned int sigen;
18004 + sigen = au_sigen(inode->i_sb);
18005 + iinfo = au_ii(inode);
18006 + iigen = &iinfo->ii_generation;
18007 + spin_lock(&iigen->ig_spin);
18008 + iigen->ig_generation = sigen;
18010 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18012 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18013 + spin_unlock(&iigen->ig_spin);
18016 +/* it may be called at remount time, too */
18017 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18019 + struct au_iinfo *iinfo;
18020 + aufs_bindex_t bindex, bbot;
18022 + AuDebugOn(au_is_bad_inode(inode));
18023 + IiMustWriteLock(inode);
18025 + iinfo = au_ii(inode);
18026 + if (do_put_zero && iinfo->ii_btop >= 0) {
18027 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18029 + struct inode *h_i;
18031 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18034 + && !(h_i->i_state & I_LINKABLE))
18035 + au_set_h_iptr(inode, bindex, NULL, 0);
18039 + iinfo->ii_btop = -1;
18040 + iinfo->ii_bbot = -1;
18041 + bbot = au_sbbot(inode->i_sb);
18042 + for (bindex = 0; bindex <= bbot; bindex++)
18043 + if (au_hinode(iinfo, bindex)->hi_inode) {
18044 + iinfo->ii_btop = bindex;
18047 + if (iinfo->ii_btop >= 0)
18048 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18049 + if (au_hinode(iinfo, bindex)->hi_inode) {
18050 + iinfo->ii_bbot = bindex;
18053 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18056 +/* ---------------------------------------------------------------------- */
18058 +void au_icntnr_init_once(void *_c)
18060 + struct au_icntnr *c = _c;
18061 + struct au_iinfo *iinfo = &c->iinfo;
18063 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18064 + au_rw_init(&iinfo->ii_rwsem);
18065 + inode_init_once(&c->vfs_inode);
18068 +void au_hinode_init(struct au_hinode *hinode)
18070 + hinode->hi_inode = NULL;
18071 + hinode->hi_id = -1;
18072 + au_hn_init(hinode);
18073 + hinode->hi_whdentry = NULL;
18076 +int au_iinfo_init(struct inode *inode)
18078 + struct au_iinfo *iinfo;
18079 + struct super_block *sb;
18080 + struct au_hinode *hi;
18083 + sb = inode->i_sb;
18084 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18085 + nbr = au_sbbot(sb) + 1;
18086 + if (unlikely(nbr <= 0))
18088 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18090 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18092 + iinfo->ii_hinode = hi;
18093 + for (i = 0; i < nbr; i++, hi++)
18094 + au_hinode_init(hi);
18096 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18097 + iinfo->ii_btop = -1;
18098 + iinfo->ii_bbot = -1;
18099 + iinfo->ii_vdir = NULL;
18105 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18108 + struct au_hinode *hip;
18110 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18113 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18116 + iinfo->ii_hinode = hip;
18117 + i = iinfo->ii_bbot + 1;
18119 + for (; i < nbr; i++, hip++)
18120 + au_hinode_init(hip);
18127 +void au_iinfo_fin(struct inode *inode)
18129 + struct au_iinfo *iinfo;
18130 + struct au_hinode *hi;
18131 + struct super_block *sb;
18132 + aufs_bindex_t bindex, bbot;
18133 + const unsigned char unlinked = !inode->i_nlink;
18135 + AuDebugOn(au_is_bad_inode(inode));
18137 + sb = inode->i_sb;
18138 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18139 + if (si_pid_test(sb))
18140 + au_xino_delete_inode(inode, unlinked);
18143 + * it is safe to hide the dependency between sbinfo and
18147 + si_noflush_read_lock(sb);
18148 + au_xino_delete_inode(inode, unlinked);
18149 + si_read_unlock(sb);
18153 + iinfo = au_ii(inode);
18154 + if (iinfo->ii_vdir)
18155 + au_vdir_free(iinfo->ii_vdir);
18157 + bindex = iinfo->ii_btop;
18158 + if (bindex >= 0) {
18159 + hi = au_hinode(iinfo, bindex);
18160 + bbot = iinfo->ii_bbot;
18161 + while (bindex++ <= bbot) {
18162 + if (hi->hi_inode)
18167 + au_kfree_rcu(iinfo->ii_hinode);
18168 + AuRwDestroy(&iinfo->ii_rwsem);
18170 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18171 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18172 +++ linux/fs/aufs/inode.c 2020-01-27 10:57:18.175538316 +0100
18174 +// SPDX-License-Identifier: GPL-2.0
18176 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18178 + * This program, aufs is free software; you can redistribute it and/or modify
18179 + * it under the terms of the GNU General Public License as published by
18180 + * the Free Software Foundation; either version 2 of the License, or
18181 + * (at your option) any later version.
18183 + * This program is distributed in the hope that it will be useful,
18184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18186 + * GNU General Public License for more details.
18188 + * You should have received a copy of the GNU General Public License
18189 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18193 + * inode functions
18196 +#include <linux/iversion.h>
18199 +struct inode *au_igrab(struct inode *inode)
18202 + AuDebugOn(!atomic_read(&inode->i_count));
18208 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18210 + au_cpup_attr_all(inode, /*force*/0);
18211 + au_update_iigen(inode, /*half*/1);
18213 + inode_inc_iversion(inode);
18216 +static int au_ii_refresh(struct inode *inode, int *update)
18220 + aufs_bindex_t bindex, new_bindex;
18221 + struct super_block *sb;
18222 + struct au_iinfo *iinfo;
18223 + struct au_hinode *p, *q, tmp;
18225 + AuDebugOn(au_is_bad_inode(inode));
18226 + IiMustWriteLock(inode);
18229 + sb = inode->i_sb;
18230 + nbr = au_sbbot(sb) + 1;
18231 + type = inode->i_mode & S_IFMT;
18232 + iinfo = au_ii(inode);
18233 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18234 + if (unlikely(err))
18237 + AuDebugOn(iinfo->ii_btop < 0);
18238 + p = au_hinode(iinfo, iinfo->ii_btop);
18239 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18241 + if (!p->hi_inode)
18244 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18245 + new_bindex = au_br_index(sb, p->hi_id);
18246 + if (new_bindex == bindex)
18249 + if (new_bindex < 0) {
18252 + p->hi_inode = NULL;
18256 + if (new_bindex < iinfo->ii_btop)
18257 + iinfo->ii_btop = new_bindex;
18258 + if (iinfo->ii_bbot < new_bindex)
18259 + iinfo->ii_bbot = new_bindex;
18260 + /* swap two lower inode, and loop again */
18261 + q = au_hinode(iinfo, new_bindex);
18265 + if (tmp.hi_inode) {
18270 + au_update_ibrange(inode, /*do_put_zero*/0);
18271 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18272 + e = au_dy_irefresh(inode);
18273 + if (unlikely(e && !err))
18281 +void au_refresh_iop(struct inode *inode, int force_getattr)
18284 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18285 + const struct inode_operations *iop
18286 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18288 + if (inode->i_op == iop)
18291 + switch (inode->i_mode & S_IFMT) {
18293 + type = AuIop_DIR;
18296 + type = AuIop_SYMLINK;
18299 + type = AuIop_OTHER;
18303 + inode->i_op = iop + type;
18304 + /* unnecessary smp_wmb() */
18307 +int au_refresh_hinode_self(struct inode *inode)
18311 + err = au_ii_refresh(inode, &update);
18313 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18319 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18321 + int err, e, update;
18322 + unsigned int flags;
18324 + aufs_bindex_t bindex, bbot;
18325 + unsigned char isdir;
18326 + struct au_hinode *p;
18327 + struct au_iinfo *iinfo;
18329 + err = au_ii_refresh(inode, &update);
18330 + if (unlikely(err))
18334 + iinfo = au_ii(inode);
18335 + p = au_hinode(iinfo, iinfo->ii_btop);
18336 + mode = (inode->i_mode & S_IFMT);
18337 + isdir = S_ISDIR(mode);
18338 + flags = au_hi_flags(inode, isdir);
18339 + bbot = au_dbbot(dentry);
18340 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18341 + struct inode *h_i, *h_inode;
18342 + struct dentry *h_d;
18344 + h_d = au_h_dptr(dentry, bindex);
18345 + if (!h_d || d_is_negative(h_d))
18348 + h_inode = d_inode(h_d);
18349 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18350 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18351 + h_i = au_h_iptr(inode, bindex);
18353 + if (h_i == h_inode)
18359 + if (bindex < iinfo->ii_btop)
18360 + iinfo->ii_btop = bindex;
18361 + if (iinfo->ii_bbot < bindex)
18362 + iinfo->ii_bbot = bindex;
18363 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18366 + au_update_ibrange(inode, /*do_put_zero*/0);
18367 + e = au_dy_irefresh(inode);
18368 + if (unlikely(e && !err))
18371 + au_refresh_hinode_attr(inode, update && isdir);
18378 +static int set_inode(struct inode *inode, struct dentry *dentry)
18381 + unsigned int flags;
18383 + aufs_bindex_t bindex, btop, btail;
18384 + unsigned char isdir;
18385 + struct dentry *h_dentry;
18386 + struct inode *h_inode;
18387 + struct au_iinfo *iinfo;
18388 + const struct inode_operations *iop;
18390 + IiMustWriteLock(inode);
18394 + iop = au_sbi(inode->i_sb)->si_iop_array;
18395 + btop = au_dbtop(dentry);
18396 + h_dentry = au_h_dptr(dentry, btop);
18397 + h_inode = d_inode(h_dentry);
18398 + mode = h_inode->i_mode;
18399 + switch (mode & S_IFMT) {
18401 + btail = au_dbtail(dentry);
18402 + inode->i_op = iop + AuIop_OTHER;
18403 + inode->i_fop = &aufs_file_fop;
18404 + err = au_dy_iaop(inode, btop, h_inode);
18405 + if (unlikely(err))
18410 + btail = au_dbtaildir(dentry);
18411 + inode->i_op = iop + AuIop_DIR;
18412 + inode->i_fop = &aufs_dir_fop;
18415 + btail = au_dbtail(dentry);
18416 + inode->i_op = iop + AuIop_SYMLINK;
18422 + btail = au_dbtail(dentry);
18423 + inode->i_op = iop + AuIop_OTHER;
18424 + init_special_inode(inode, mode, h_inode->i_rdev);
18427 + AuIOErr("Unknown file type 0%o\n", mode);
18432 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18433 + flags = au_hi_flags(inode, isdir);
18434 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18435 + && au_ftest_hi(flags, HNOTIFY)
18436 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18437 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18438 + au_fclr_hi(flags, HNOTIFY);
18439 + iinfo = au_ii(inode);
18440 + iinfo->ii_btop = btop;
18441 + iinfo->ii_bbot = btail;
18442 + for (bindex = btop; bindex <= btail; bindex++) {
18443 + h_dentry = au_h_dptr(dentry, bindex);
18445 + au_set_h_iptr(inode, bindex,
18446 + au_igrab(d_inode(h_dentry)), flags);
18448 + au_cpup_attr_all(inode, /*force*/1);
18450 + * to force calling aufs_get_acl() every time,
18451 + * do not call cache_no_acl() for aufs inode.
18459 + * successful returns with iinfo write_locked
18461 + * zero: success, matched
18462 + * plus: no error, but unmatched
18464 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18467 + unsigned int gen, igflags;
18468 + aufs_bindex_t bindex, bbot;
18469 + struct inode *h_inode, *h_dinode;
18470 + struct dentry *h_dentry;
18473 + * before this function, if aufs got any iinfo lock, it must be only
18474 + * one, the parent dir.
18475 + * it can happen by UDBA and the obsoleted inode number.
18478 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18482 + ii_write_lock_new_child(inode);
18483 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18484 + h_dinode = d_inode(h_dentry);
18485 + bbot = au_ibbot(inode);
18486 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18487 + h_inode = au_h_iptr(inode, bindex);
18488 + if (!h_inode || h_inode != h_dinode)
18492 + gen = au_iigen(inode, &igflags);
18493 + if (gen == au_digen(dentry)
18494 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18497 + /* fully refresh inode using dentry */
18498 + err = au_refresh_hinode(inode, dentry);
18500 + au_update_iigen(inode, /*half*/0);
18504 + if (unlikely(err))
18505 + ii_write_unlock(inode);
18510 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18511 + unsigned int d_type, ino_t *ino)
18514 + const int isnondir = d_type != DT_DIR;
18516 + /* prevent hardlinked inode number from race condition */
18518 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18519 + if (unlikely(err))
18523 + err = au_xino_read(sb, bindex, h_ino, ino);
18524 + if (unlikely(err))
18525 + goto out_xinondir;
18529 + *ino = au_xino_new_ino(sb);
18530 + if (unlikely(!*ino))
18531 + goto out_xinondir;
18532 + err = au_xino_write(sb, bindex, h_ino, *ino);
18533 + if (unlikely(err))
18534 + goto out_xinondir;
18538 + if (isnondir && idx >= 0)
18539 + au_xinondir_leave(sb, bindex, h_ino, idx);
18544 +/* successful returns with iinfo write_locked */
18545 +/* todo: return with unlocked? */
18546 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18548 + struct inode *inode, *h_inode;
18549 + struct dentry *h_dentry;
18550 + struct super_block *sb;
18551 + ino_t h_ino, ino;
18552 + int err, idx, hlinked;
18553 + aufs_bindex_t btop;
18555 + sb = dentry->d_sb;
18556 + btop = au_dbtop(dentry);
18557 + h_dentry = au_h_dptr(dentry, btop);
18558 + h_inode = d_inode(h_dentry);
18559 + h_ino = h_inode->i_ino;
18560 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18564 + * stop 'race'-ing between hardlinks under different
18568 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18569 + inode = ERR_PTR(err);
18570 + if (unlikely(err))
18574 + err = au_xino_read(sb, btop, h_ino, &ino);
18575 + inode = ERR_PTR(err);
18576 + if (unlikely(err))
18577 + goto out_xinondir;
18580 + ino = au_xino_new_ino(sb);
18581 + if (unlikely(!ino)) {
18582 + inode = ERR_PTR(-EIO);
18583 + goto out_xinondir;
18587 + AuDbg("i%lu\n", (unsigned long)ino);
18588 + inode = au_iget_locked(sb, ino);
18589 + err = PTR_ERR(inode);
18590 + if (IS_ERR(inode))
18591 + goto out_xinondir;
18593 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18594 + if (inode->i_state & I_NEW) {
18595 + ii_write_lock_new_child(inode);
18596 + err = set_inode(inode, dentry);
18598 + unlock_new_inode(inode);
18599 + goto out_xinondir; /* success */
18603 + * iget_failed() calls iput(), but we need to call
18604 + * ii_write_unlock() after iget_failed(). so dirty hack for
18607 + atomic_inc(&inode->i_count);
18608 + iget_failed(inode);
18609 + ii_write_unlock(inode);
18610 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18611 + /* ignore this error */
18613 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18615 + * horrible race condition between lookup, readdir and copyup
18616 + * (or something).
18618 + if (hlinked && idx >= 0)
18619 + au_xinondir_leave(sb, btop, h_ino, idx);
18620 + err = reval_inode(inode, dentry);
18621 + if (unlikely(err < 0)) {
18626 + goto out; /* success */
18627 + else if (hlinked && idx >= 0) {
18628 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18629 + if (unlikely(err)) {
18631 + inode = ERR_PTR(err);
18637 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18638 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18639 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18640 + btop, au_sbtype(h_dentry->d_sb), dentry,
18641 + (unsigned long)h_ino, (unsigned long)ino);
18643 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18646 + if (hlinked && idx >= 0)
18647 + au_xinondir_leave(sb, btop, h_ino, idx);
18653 + inode = ERR_PTR(err);
18655 + if (hlinked && idx >= 0)
18656 + au_xinondir_leave(sb, btop, h_ino, idx);
18661 +/* ---------------------------------------------------------------------- */
18663 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18664 + struct inode *inode)
18667 + struct inode *hi;
18669 + err = au_br_rdonly(au_sbr(sb, bindex));
18671 + /* pseudo-link after flushed may happen out of bounds */
18674 + && au_ibtop(inode) <= bindex
18675 + && bindex <= au_ibbot(inode)) {
18677 + * permission check is unnecessary since vfsub routine
18678 + * will be called later
18680 + hi = au_h_iptr(inode, bindex);
18682 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18688 +int au_test_h_perm(struct inode *h_inode, int mask)
18690 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18692 + return inode_permission(h_inode, mask);
18695 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18697 + if (au_test_nfs(h_inode->i_sb)
18698 + && (mask & MAY_WRITE)
18699 + && S_ISDIR(h_inode->i_mode))
18700 + mask |= MAY_READ; /* force permission check */
18701 + return au_test_h_perm(h_inode, mask);
18703 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18704 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18705 +++ linux/fs/aufs/inode.h 2020-01-27 10:57:18.175538316 +0100
18707 +/* SPDX-License-Identifier: GPL-2.0 */
18709 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18711 + * This program, aufs is free software; you can redistribute it and/or modify
18712 + * it under the terms of the GNU General Public License as published by
18713 + * the Free Software Foundation; either version 2 of the License, or
18714 + * (at your option) any later version.
18716 + * This program is distributed in the hope that it will be useful,
18717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18719 + * GNU General Public License for more details.
18721 + * You should have received a copy of the GNU General Public License
18722 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18726 + * inode operations
18729 +#ifndef __AUFS_INODE_H__
18730 +#define __AUFS_INODE_H__
18734 +#include <linux/fsnotify.h>
18735 +#include "rwsem.h"
18739 +struct au_hnotify {
18740 +#ifdef CONFIG_AUFS_HNOTIFY
18741 +#ifdef CONFIG_AUFS_HFSNOTIFY
18742 + /* never use fsnotify_add_vfsmount_mark() */
18743 + struct fsnotify_mark hn_mark;
18745 + struct inode *hn_aufs_inode; /* no get/put */
18746 + struct rcu_head rcu;
18748 +} ____cacheline_aligned_in_smp;
18750 +struct au_hinode {
18751 + struct inode *hi_inode;
18752 + aufs_bindex_t hi_id;
18753 +#ifdef CONFIG_AUFS_HNOTIFY
18754 + struct au_hnotify *hi_notify;
18757 + /* reference to the copied-up whiteout with get/put */
18758 + struct dentry *hi_whdentry;
18762 +#define AuIG_HALF_REFRESHED 1
18763 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18764 +#define au_ig_fset(flags, name) \
18765 + do { (flags) |= AuIG_##name; } while (0)
18766 +#define au_ig_fclr(flags, name) \
18767 + do { (flags) &= ~AuIG_##name; } while (0)
18770 + spinlock_t ig_spin;
18771 + __u32 ig_generation, ig_flags;
18776 + struct au_iigen ii_generation;
18777 + struct super_block *ii_hsb1; /* no get/put */
18779 + struct au_rwsem ii_rwsem;
18780 + aufs_bindex_t ii_btop, ii_bbot;
18782 + struct au_hinode *ii_hinode;
18783 + struct au_vdir *ii_vdir;
18786 +struct au_icntnr {
18787 + struct au_iinfo iinfo;
18788 + struct inode vfs_inode;
18789 + struct hlist_bl_node plink;
18790 + struct rcu_head rcu;
18791 +} ____cacheline_aligned_in_smp;
18793 +/* au_pin flags */
18794 +#define AuPin_DI_LOCKED 1
18795 +#define AuPin_MNT_WRITE (1 << 1)
18796 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18797 +#define au_fset_pin(flags, name) \
18798 + do { (flags) |= AuPin_##name; } while (0)
18799 +#define au_fclr_pin(flags, name) \
18800 + do { (flags) &= ~AuPin_##name; } while (0)
18804 + struct dentry *dentry;
18805 + unsigned int udba;
18806 + unsigned char lsc_di, lsc_hi, flags;
18807 + aufs_bindex_t bindex;
18810 + struct dentry *parent;
18811 + struct au_hinode *hdir;
18812 + struct vfsmount *h_mnt;
18814 + /* temporary unlock/relock for copyup */
18815 + struct dentry *h_dentry, *h_parent;
18816 + struct au_branch *br;
18817 + struct task_struct *task;
18820 +void au_pin_hdir_unlock(struct au_pin *p);
18821 +int au_pin_hdir_lock(struct au_pin *p);
18822 +int au_pin_hdir_relock(struct au_pin *p);
18823 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18824 +void au_pin_hdir_release(struct au_pin *p);
18826 +/* ---------------------------------------------------------------------- */
18828 +static inline struct au_iinfo *au_ii(struct inode *inode)
18830 + BUG_ON(is_bad_inode(inode));
18831 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18834 +/* ---------------------------------------------------------------------- */
18837 +struct inode *au_igrab(struct inode *inode);
18838 +void au_refresh_iop(struct inode *inode, int force_getattr);
18839 +int au_refresh_hinode_self(struct inode *inode);
18840 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18841 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18842 + unsigned int d_type, ino_t *ino);
18843 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18844 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18845 + struct inode *inode);
18846 +int au_test_h_perm(struct inode *h_inode, int mask);
18847 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18849 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18850 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18852 +#ifdef CONFIG_AUFS_SHWH
18853 + return au_ino(sb, bindex, h_ino, d_type, ino);
18866 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18867 + aufs_iop_nogetattr[AuIop_Last];
18869 +/* au_wr_dir flags */
18870 +#define AuWrDir_ADD_ENTRY 1
18871 +#define AuWrDir_ISDIR (1 << 1)
18872 +#define AuWrDir_TMPFILE (1 << 2)
18873 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18874 +#define au_fset_wrdir(flags, name) \
18875 + do { (flags) |= AuWrDir_##name; } while (0)
18876 +#define au_fclr_wrdir(flags, name) \
18877 + do { (flags) &= ~AuWrDir_##name; } while (0)
18879 +struct au_wr_dir_args {
18880 + aufs_bindex_t force_btgt;
18881 + unsigned char flags;
18883 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18884 + struct au_wr_dir_args *args);
18886 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18887 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18888 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18889 + unsigned int udba, unsigned char flags);
18890 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18891 + unsigned int udba, unsigned char flags) __must_check;
18892 +int au_do_pin(struct au_pin *pin) __must_check;
18893 +void au_unpin(struct au_pin *pin);
18894 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18896 +#define AuIcpup_DID_CPUP 1
18897 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18898 +#define au_fset_icpup(flags, name) \
18899 + do { (flags) |= AuIcpup_##name; } while (0)
18900 +#define au_fclr_icpup(flags, name) \
18901 + do { (flags) &= ~AuIcpup_##name; } while (0)
18903 +struct au_icpup_args {
18904 + unsigned char flags;
18905 + unsigned char pin_flags;
18906 + aufs_bindex_t btgt;
18907 + unsigned int udba;
18908 + struct au_pin pin;
18909 + struct path h_path;
18910 + struct inode *h_inode;
18913 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18914 + struct au_icpup_args *a);
18916 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18920 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18921 + struct dentry *h_parent, int isdir);
18922 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18924 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18925 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18927 +struct vfsub_aopen_args;
18928 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18929 + struct vfsub_aopen_args *args);
18930 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18931 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18932 + struct dentry *dentry);
18933 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18936 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18937 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18938 + struct dentry *h_parent, int isdir);
18939 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18940 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18943 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18944 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18945 + struct inode *dir, struct dentry *dentry,
18946 + unsigned int flags);
18949 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18950 +void au_hiput(struct au_hinode *hinode);
18951 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18952 + struct dentry *h_wh);
18953 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18955 +/* hinode flags */
18956 +#define AuHi_XINO 1
18957 +#define AuHi_HNOTIFY (1 << 1)
18958 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18959 +#define au_fset_hi(flags, name) \
18960 + do { (flags) |= AuHi_##name; } while (0)
18961 +#define au_fclr_hi(flags, name) \
18962 + do { (flags) &= ~AuHi_##name; } while (0)
18964 +#ifndef CONFIG_AUFS_HNOTIFY
18965 +#undef AuHi_HNOTIFY
18966 +#define AuHi_HNOTIFY 0
18969 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18970 + struct inode *h_inode, unsigned int flags);
18972 +void au_update_iigen(struct inode *inode, int half);
18973 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18975 +void au_icntnr_init_once(void *_c);
18976 +void au_hinode_init(struct au_hinode *hinode);
18977 +int au_iinfo_init(struct inode *inode);
18978 +void au_iinfo_fin(struct inode *inode);
18979 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18981 +#ifdef CONFIG_PROC_FS
18983 +int au_plink_maint(struct super_block *sb, int flags);
18985 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18986 +int au_plink_maint_enter(struct super_block *sb);
18987 +#ifdef CONFIG_AUFS_DEBUG
18988 +void au_plink_list(struct super_block *sb);
18990 +AuStubVoid(au_plink_list, struct super_block *sb)
18992 +int au_plink_test(struct inode *inode);
18993 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18994 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18995 + struct dentry *h_dentry);
18996 +void au_plink_put(struct super_block *sb, int verbose);
18997 +void au_plink_clean(struct super_block *sb, int verbose);
18998 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19000 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19001 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19002 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19003 +AuStubVoid(au_plink_list, struct super_block *sb);
19004 +AuStubInt0(au_plink_test, struct inode *inode);
19005 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19006 + struct inode *inode, aufs_bindex_t bindex);
19007 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19008 + struct dentry *h_dentry);
19009 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19010 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19011 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19012 +#endif /* CONFIG_PROC_FS */
19014 +#ifdef CONFIG_AUFS_XATTR
19016 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19017 + unsigned int verbose);
19018 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19019 +void au_xattr_init(struct super_block *sb);
19021 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19022 + int ignore_flags, unsigned int verbose);
19023 +AuStubVoid(au_xattr_init, struct super_block *sb);
19026 +#ifdef CONFIG_FS_POSIX_ACL
19027 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19028 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19031 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19037 +struct au_sxattr {
19041 + const char *name;
19042 + const void *value;
19047 + struct posix_acl *acl;
19052 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19053 + struct au_sxattr *arg);
19056 +/* ---------------------------------------------------------------------- */
19058 +/* lock subclass for iinfo */
19060 + AuLsc_II_CHILD, /* child first */
19061 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19062 + AuLsc_II_CHILD3, /* copyup dirs */
19063 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19064 + AuLsc_II_PARENT2,
19065 + AuLsc_II_PARENT3, /* copyup dirs */
19066 + AuLsc_II_NEW_CHILD
19070 + * ii_read_lock_child, ii_write_lock_child,
19071 + * ii_read_lock_child2, ii_write_lock_child2,
19072 + * ii_read_lock_child3, ii_write_lock_child3,
19073 + * ii_read_lock_parent, ii_write_lock_parent,
19074 + * ii_read_lock_parent2, ii_write_lock_parent2,
19075 + * ii_read_lock_parent3, ii_write_lock_parent3,
19076 + * ii_read_lock_new_child, ii_write_lock_new_child,
19078 +#define AuReadLockFunc(name, lsc) \
19079 +static inline void ii_read_lock_##name(struct inode *i) \
19081 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19084 +#define AuWriteLockFunc(name, lsc) \
19085 +static inline void ii_write_lock_##name(struct inode *i) \
19087 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19090 +#define AuRWLockFuncs(name, lsc) \
19091 + AuReadLockFunc(name, lsc) \
19092 + AuWriteLockFunc(name, lsc)
19094 +AuRWLockFuncs(child, CHILD);
19095 +AuRWLockFuncs(child2, CHILD2);
19096 +AuRWLockFuncs(child3, CHILD3);
19097 +AuRWLockFuncs(parent, PARENT);
19098 +AuRWLockFuncs(parent2, PARENT2);
19099 +AuRWLockFuncs(parent3, PARENT3);
19100 +AuRWLockFuncs(new_child, NEW_CHILD);
19102 +#undef AuReadLockFunc
19103 +#undef AuWriteLockFunc
19104 +#undef AuRWLockFuncs
19106 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19107 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19108 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19110 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19111 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19112 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19114 +/* ---------------------------------------------------------------------- */
19116 +static inline void au_icntnr_init(struct au_icntnr *c)
19118 +#ifdef CONFIG_AUFS_DEBUG
19119 + c->vfs_inode.i_mode = 0;
19123 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19125 + unsigned int gen;
19126 + struct au_iinfo *iinfo;
19127 + struct au_iigen *iigen;
19129 + iinfo = au_ii(inode);
19130 + iigen = &iinfo->ii_generation;
19131 + spin_lock(&iigen->ig_spin);
19133 + *igflags = iigen->ig_flags;
19134 + gen = iigen->ig_generation;
19135 + spin_unlock(&iigen->ig_spin);
19140 +/* tiny test for inode number */
19141 +/* tmpfs generation is too rough */
19142 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19144 + struct au_iinfo *iinfo;
19146 + iinfo = au_ii(inode);
19147 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19148 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19149 + && iinfo->ii_higen == h_inode->i_generation);
19152 +static inline void au_iigen_dec(struct inode *inode)
19154 + struct au_iinfo *iinfo;
19155 + struct au_iigen *iigen;
19157 + iinfo = au_ii(inode);
19158 + iigen = &iinfo->ii_generation;
19159 + spin_lock(&iigen->ig_spin);
19160 + iigen->ig_generation--;
19161 + spin_unlock(&iigen->ig_spin);
19164 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19169 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19175 +/* ---------------------------------------------------------------------- */
19177 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19178 + aufs_bindex_t bindex)
19180 + return iinfo->ii_hinode + bindex;
19183 +static inline int au_is_bad_inode(struct inode *inode)
19185 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19188 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19189 + aufs_bindex_t bindex)
19191 + IiMustAnyLock(inode);
19192 + return au_hinode(au_ii(inode), bindex)->hi_id;
19195 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19197 + IiMustAnyLock(inode);
19198 + return au_ii(inode)->ii_btop;
19201 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19203 + IiMustAnyLock(inode);
19204 + return au_ii(inode)->ii_bbot;
19207 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19209 + IiMustAnyLock(inode);
19210 + return au_ii(inode)->ii_vdir;
19213 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19215 + IiMustAnyLock(inode);
19216 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19219 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19221 + IiMustWriteLock(inode);
19222 + au_ii(inode)->ii_btop = bindex;
19225 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19227 + IiMustWriteLock(inode);
19228 + au_ii(inode)->ii_bbot = bindex;
19231 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19233 + IiMustWriteLock(inode);
19234 + au_ii(inode)->ii_vdir = vdir;
19237 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19239 + IiMustAnyLock(inode);
19240 + return au_hinode(au_ii(inode), bindex);
19243 +/* ---------------------------------------------------------------------- */
19245 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19248 + return pin->parent;
19252 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19254 + if (pin && pin->hdir)
19255 + return pin->hdir->hi_inode;
19259 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19262 + return pin->hdir;
19266 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19269 + pin->dentry = dentry;
19272 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19273 + unsigned char lflag)
19277 + au_fset_pin(pin->flags, DI_LOCKED);
19279 + au_fclr_pin(pin->flags, DI_LOCKED);
19283 +#if 0 /* reserved */
19284 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19287 + dput(pin->parent);
19288 + pin->parent = dget(parent);
19293 +/* ---------------------------------------------------------------------- */
19296 +#ifdef CONFIG_AUFS_HNOTIFY
19297 +struct au_hnotify_op {
19298 + void (*ctl)(struct au_hinode *hinode, int do_set);
19299 + int (*alloc)(struct au_hinode *hinode);
19302 + * if it returns true, the the caller should free hinode->hi_notify,
19303 + * otherwise ->free() frees it.
19305 + int (*free)(struct au_hinode *hinode,
19306 + struct au_hnotify *hn) __must_check;
19308 + void (*fin)(void);
19309 + int (*init)(void);
19311 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19312 + void (*fin_br)(struct au_branch *br);
19313 + int (*init_br)(struct au_branch *br, int perm);
19317 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19318 +void au_hn_free(struct au_hinode *hinode);
19319 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19320 +void au_hn_reset(struct inode *inode, unsigned int flags);
19321 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19322 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19323 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19324 +int au_hnotify_init_br(struct au_branch *br, int perm);
19325 +void au_hnotify_fin_br(struct au_branch *br);
19326 +int __init au_hnotify_init(void);
19327 +void au_hnotify_fin(void);
19330 +extern const struct au_hnotify_op au_hnotify_op;
19333 +void au_hn_init(struct au_hinode *hinode)
19335 + hinode->hi_notify = NULL;
19338 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19340 + return hinode->hi_notify;
19344 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19345 + struct au_hinode *hinode __maybe_unused,
19346 + struct inode *inode __maybe_unused)
19347 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19348 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19349 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19350 + int do_set __maybe_unused)
19351 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19352 + unsigned int flags __maybe_unused)
19353 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19354 + struct au_branch *br __maybe_unused,
19355 + int perm __maybe_unused)
19356 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19357 + int perm __maybe_unused)
19358 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19359 +AuStubInt0(__init au_hnotify_init, void)
19360 +AuStubVoid(au_hnotify_fin, void)
19361 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19362 +#endif /* CONFIG_AUFS_HNOTIFY */
19364 +static inline void au_hn_suspend(struct au_hinode *hdir)
19366 + au_hn_ctl(hdir, /*do_set*/0);
19369 +static inline void au_hn_resume(struct au_hinode *hdir)
19371 + au_hn_ctl(hdir, /*do_set*/1);
19374 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19376 + inode_lock(hdir->hi_inode);
19377 + au_hn_suspend(hdir);
19380 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19381 + unsigned int sc __maybe_unused)
19383 + inode_lock_nested(hdir->hi_inode, sc);
19384 + au_hn_suspend(hdir);
19387 +#if 0 /* unused */
19388 +#include "vfsub.h"
19389 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19392 + inode_lock_shared_nested(hdir->hi_inode, sc);
19393 + au_hn_suspend(hdir);
19397 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19399 + au_hn_resume(hdir);
19400 + inode_unlock(hdir->hi_inode);
19403 +#endif /* __KERNEL__ */
19404 +#endif /* __AUFS_INODE_H__ */
19405 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19406 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19407 +++ linux/fs/aufs/ioctl.c 2020-01-27 10:57:18.175538316 +0100
19409 +// SPDX-License-Identifier: GPL-2.0
19411 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19413 + * This program, aufs is free software; you can redistribute it and/or modify
19414 + * it under the terms of the GNU General Public License as published by
19415 + * the Free Software Foundation; either version 2 of the License, or
19416 + * (at your option) any later version.
19418 + * This program is distributed in the hope that it will be useful,
19419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19421 + * GNU General Public License for more details.
19423 + * You should have received a copy of the GNU General Public License
19424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19429 + * plink-management and readdir in userspace.
19430 + * assist the pathconf(3) wrapper library.
19432 + * File-based Hierarchical Storage Management.
19435 +#include <linux/compat.h>
19436 +#include <linux/file.h>
19439 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19442 + aufs_bindex_t wbi, bindex, bbot;
19443 + struct file *h_file;
19444 + struct super_block *sb;
19445 + struct dentry *root;
19446 + struct au_branch *br;
19447 + struct aufs_wbr_fd wbrfd = {
19448 + .oflags = au_dir_roflags,
19451 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19452 + | O_NOATIME | O_CLOEXEC;
19454 + AuDebugOn(wbrfd.oflags & ~valid);
19457 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19458 + if (unlikely(err)) {
19464 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19465 + wbrfd.oflags |= au_dir_roflags;
19466 + AuDbg("0%o\n", wbrfd.oflags);
19467 + if (unlikely(wbrfd.oflags & ~valid))
19471 + fd = get_unused_fd_flags(0);
19473 + if (unlikely(fd < 0))
19476 + h_file = ERR_PTR(-EINVAL);
19479 + sb = path->dentry->d_sb;
19480 + root = sb->s_root;
19481 + aufs_read_lock(root, AuLock_IR);
19482 + bbot = au_sbbot(sb);
19483 + if (wbrfd.brid >= 0) {
19484 + wbi = au_br_index(sb, wbrfd.brid);
19485 + if (unlikely(wbi < 0 || wbi > bbot))
19489 + h_file = ERR_PTR(-ENOENT);
19490 + br = au_sbr(sb, wbi);
19491 + if (!au_br_writable(br->br_perm)) {
19495 + bindex = wbi + 1;
19497 + for (; bindex <= bbot; bindex++) {
19498 + br = au_sbr(sb, bindex);
19499 + if (au_br_writable(br->br_perm)) {
19501 + br = au_sbr(sb, wbi);
19506 + AuDbg("wbi %d\n", wbi);
19508 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19512 + aufs_read_unlock(root, AuLock_IR);
19513 + err = PTR_ERR(h_file);
19514 + if (IS_ERR(h_file))
19517 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19518 + fd_install(fd, h_file);
19520 + goto out; /* success */
19523 + put_unused_fd(fd);
19529 +/* ---------------------------------------------------------------------- */
19531 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19534 + struct dentry *dentry;
19537 + case AUFS_CTL_RDU:
19538 + case AUFS_CTL_RDU_INO:
19539 + err = au_rdu_ioctl(file, cmd, arg);
19542 + case AUFS_CTL_WBR_FD:
19543 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19546 + case AUFS_CTL_IBUSY:
19547 + err = au_ibusy_ioctl(file, arg);
19550 + case AUFS_CTL_BRINFO:
19551 + err = au_brinfo_ioctl(file, arg);
19554 + case AUFS_CTL_FHSM_FD:
19555 + dentry = file->f_path.dentry;
19556 + if (IS_ROOT(dentry))
19557 + err = au_fhsm_fd(dentry->d_sb, arg);
19563 + /* do not call the lower */
19564 + AuDbg("0x%x\n", cmd);
19572 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19577 + case AUFS_CTL_MVDOWN:
19578 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19581 + case AUFS_CTL_WBR_FD:
19582 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19586 + /* do not call the lower */
19587 + AuDbg("0x%x\n", cmd);
19595 +#ifdef CONFIG_COMPAT
19596 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19597 + unsigned long arg)
19602 + case AUFS_CTL_RDU:
19603 + case AUFS_CTL_RDU_INO:
19604 + err = au_rdu_compat_ioctl(file, cmd, arg);
19607 + case AUFS_CTL_IBUSY:
19608 + err = au_ibusy_compat_ioctl(file, arg);
19611 + case AUFS_CTL_BRINFO:
19612 + err = au_brinfo_compat_ioctl(file, arg);
19616 + err = aufs_ioctl_dir(file, cmd, arg);
19623 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19624 + unsigned long arg)
19626 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19629 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19630 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19631 +++ linux/fs/aufs/i_op_add.c 2020-01-27 10:57:18.172204883 +0100
19633 +// SPDX-License-Identifier: GPL-2.0
19635 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19637 + * This program, aufs is free software; you can redistribute it and/or modify
19638 + * it under the terms of the GNU General Public License as published by
19639 + * the Free Software Foundation; either version 2 of the License, or
19640 + * (at your option) any later version.
19642 + * This program is distributed in the hope that it will be useful,
19643 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19644 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19645 + * GNU General Public License for more details.
19647 + * You should have received a copy of the GNU General Public License
19648 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19652 + * inode operations (add entry)
19655 +#include <linux/iversion.h>
19659 + * final procedure of adding a new entry, except link(2).
19660 + * remove whiteout, instantiate, copyup the parent dir's times and size
19661 + * and update version.
19662 + * if it failed, re-create the removed whiteout.
19664 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19665 + struct dentry *wh_dentry, struct dentry *dentry)
19668 + aufs_bindex_t bwh;
19669 + struct path h_path;
19670 + struct super_block *sb;
19671 + struct inode *inode, *h_dir;
19672 + struct dentry *wh;
19677 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19678 + IMustLock(h_dir);
19679 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19680 + bwh = au_dbwh(dentry);
19681 + h_path.dentry = wh_dentry;
19682 + h_path.mnt = au_sbr_mnt(sb, bindex);
19683 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19685 + if (unlikely(err))
19689 + inode = au_new_inode(dentry, /*must_new*/1);
19690 + if (!IS_ERR(inode)) {
19691 + d_instantiate(dentry, inode);
19692 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19694 + au_dir_ts(dir, bindex);
19695 + inode_inc_iversion(dir);
19696 + au_fhsm_wrote(sb, bindex, /*force*/0);
19697 + return 0; /* success */
19700 + err = PTR_ERR(inode);
19705 + /* dir inode is locked */
19706 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19707 + rerr = PTR_ERR(wh);
19708 + if (IS_ERR(wh)) {
19709 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19710 + dentry, err, rerr);
19719 +static int au_d_may_add(struct dentry *dentry)
19724 + if (unlikely(d_unhashed(dentry)))
19726 + if (unlikely(d_really_is_positive(dentry)))
19732 + * simple tests for the adding inode operations.
19733 + * following the checks in vfs, plus the parent-child relationship.
19735 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19736 + struct dentry *h_parent, int isdir)
19740 + struct dentry *h_dentry;
19741 + struct inode *h_inode;
19743 + err = -ENAMETOOLONG;
19744 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19747 + h_dentry = au_h_dptr(dentry, bindex);
19748 + if (d_really_is_negative(dentry)) {
19750 + if (unlikely(d_is_positive(h_dentry)))
19753 + /* rename(2) case */
19755 + if (unlikely(d_is_negative(h_dentry)))
19757 + h_inode = d_inode(h_dentry);
19758 + if (unlikely(!h_inode->i_nlink))
19761 + h_mode = h_inode->i_mode;
19764 + if (unlikely(S_ISDIR(h_mode)))
19766 + } else if (unlikely(!S_ISDIR(h_mode))) {
19773 + /* expected parent dir is locked */
19774 + if (unlikely(h_parent != h_dentry->d_parent))
19783 + * initial procedure of adding a new entry.
19784 + * prepare writable branch and the parent dir, lock it,
19785 + * and lookup whiteout for the new entry.
19787 +static struct dentry*
19788 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19789 + struct dentry *src_dentry, struct au_pin *pin,
19790 + struct au_wr_dir_args *wr_dir_args)
19792 + struct dentry *wh_dentry, *h_parent;
19793 + struct super_block *sb;
19794 + struct au_branch *br;
19796 + unsigned int udba;
19797 + aufs_bindex_t bcpup;
19799 + AuDbg("%pd\n", dentry);
19801 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19803 + wh_dentry = ERR_PTR(err);
19804 + if (unlikely(err < 0))
19807 + sb = dentry->d_sb;
19808 + udba = au_opt_udba(sb);
19809 + err = au_pin(pin, dentry, bcpup, udba,
19810 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19811 + wh_dentry = ERR_PTR(err);
19812 + if (unlikely(err))
19815 + h_parent = au_pinned_h_parent(pin);
19816 + if (udba != AuOpt_UDBA_NONE
19817 + && au_dbtop(dentry) == bcpup)
19818 + err = au_may_add(dentry, bcpup, h_parent,
19819 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19820 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19821 + err = -ENAMETOOLONG;
19822 + wh_dentry = ERR_PTR(err);
19823 + if (unlikely(err))
19826 + br = au_sbr(sb, bcpup);
19828 + struct path tmp = {
19829 + .dentry = h_parent,
19830 + .mnt = au_br_mnt(br)
19832 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19835 + wh_dentry = NULL;
19836 + if (bcpup != au_dbwh(dentry))
19837 + goto out; /* success */
19840 + * ENAMETOOLONG here means that if we allowed create such name, then it
19841 + * would not be able to removed in the future. So we don't allow such
19842 + * name here and we don't handle ENAMETOOLONG differently here.
19844 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19847 + if (IS_ERR(wh_dentry))
19850 + return wh_dentry;
19853 +/* ---------------------------------------------------------------------- */
19855 +enum { Mknod, Symlink, Creat };
19856 +struct simple_arg {
19863 + struct vfsub_aopen_args *aopen;
19866 + const char *symname;
19875 +static int add_simple(struct inode *dir, struct dentry *dentry,
19876 + struct simple_arg *arg)
19879 + aufs_bindex_t btop;
19880 + unsigned char created;
19881 + const unsigned char try_aopen
19882 + = (arg->type == Creat && arg->u.c.try_aopen);
19883 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19884 + struct dentry *wh_dentry, *parent;
19885 + struct inode *h_dir;
19886 + struct super_block *sb;
19887 + struct au_branch *br;
19888 + /* to reduce stack size */
19890 + struct au_dtime dt;
19891 + struct au_pin pin;
19892 + struct path h_path;
19893 + struct au_wr_dir_args wr_dir_args;
19896 + AuDbg("%pd\n", dentry);
19900 + a = kmalloc(sizeof(*a), GFP_NOFS);
19901 + if (unlikely(!a))
19903 + a->wr_dir_args.force_btgt = -1;
19904 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19906 + parent = dentry->d_parent; /* dir inode is locked */
19907 + if (!try_aopen) {
19908 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19909 + if (unlikely(err))
19912 + err = au_d_may_add(dentry);
19913 + if (unlikely(err))
19916 + di_write_lock_parent(parent);
19917 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19918 + &a->pin, &a->wr_dir_args);
19919 + err = PTR_ERR(wh_dentry);
19920 + if (IS_ERR(wh_dentry))
19923 + btop = au_dbtop(dentry);
19924 + sb = dentry->d_sb;
19925 + br = au_sbr(sb, btop);
19926 + a->h_path.dentry = au_h_dptr(dentry, btop);
19927 + a->h_path.mnt = au_br_mnt(br);
19928 + h_dir = au_pinned_h_dir(&a->pin);
19929 + switch (arg->type) {
19931 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19932 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19933 + arg->u.c.want_excl);
19935 + if (!err && try_aopen)
19936 + aopen->file->f_mode |= FMODE_CREATED;
19939 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19940 + AuDbg("err %d\n", err);
19941 + AuDbgFile(aopen->file);
19942 + created = err >= 0
19943 + && !!(aopen->file->f_mode & FMODE_CREATED);
19947 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19951 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19958 + if (unlikely(err < 0))
19961 + err = epilog(dir, btop, wh_dentry, dentry);
19963 + goto out_unpin; /* success */
19966 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19967 + /* no delegation since it is just created */
19968 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19971 + AuIOErr("%pd revert failure(%d, %d)\n",
19972 + dentry, err, rerr);
19975 + au_dtime_revert(&a->dt);
19977 + if (try_aopen && h_dir->i_op->atomic_open
19978 + && (aopen->file->f_mode & FMODE_OPENED))
19979 + /* aopen->file is still opened */
19980 + au_lcnt_dec(&aopen->br->br_nfiles);
19983 + au_unpin(&a->pin);
19987 + di_write_unlock(parent);
19989 + if (unlikely(err)) {
19990 + au_update_dbtop(dentry);
19994 + aufs_read_unlock(dentry, AuLock_DW);
20001 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20004 + struct simple_arg arg = {
20011 + return add_simple(dir, dentry, &arg);
20014 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20016 + struct simple_arg arg = {
20018 + .u.s.symname = symname
20020 + return add_simple(dir, dentry, &arg);
20023 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20026 + struct simple_arg arg = {
20030 + .want_excl = want_excl
20033 + return add_simple(dir, dentry, &arg);
20036 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20037 + struct vfsub_aopen_args *aopen_args)
20039 + struct simple_arg arg = {
20042 + .mode = aopen_args->create_mode,
20043 + .want_excl = aopen_args->open_flag & O_EXCL,
20044 + .try_aopen = true,
20045 + .aopen = aopen_args
20048 + return add_simple(dir, dentry, &arg);
20051 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20054 + aufs_bindex_t bindex;
20055 + struct super_block *sb;
20056 + struct dentry *parent, *h_parent, *h_dentry;
20057 + struct inode *h_dir, *inode;
20058 + struct vfsmount *h_mnt;
20059 + struct au_wr_dir_args wr_dir_args = {
20060 + .force_btgt = -1,
20061 + .flags = AuWrDir_TMPFILE
20064 + /* copy-up may happen */
20068 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20069 + if (unlikely(err))
20072 + err = au_di_init(dentry);
20073 + if (unlikely(err))
20077 + parent = d_find_any_alias(dir);
20078 + AuDebugOn(!parent);
20079 + di_write_lock_parent(parent);
20080 + if (unlikely(d_inode(parent) != dir))
20083 + err = au_digen_test(parent, au_sigen(sb));
20084 + if (unlikely(err))
20087 + bindex = au_dbtop(parent);
20088 + au_set_dbtop(dentry, bindex);
20089 + au_set_dbbot(dentry, bindex);
20090 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20092 + if (unlikely(err < 0))
20095 + err = -EOPNOTSUPP;
20096 + h_dir = au_h_iptr(dir, bindex);
20097 + if (unlikely(!h_dir->i_op->tmpfile))
20100 + h_mnt = au_sbr_mnt(sb, bindex);
20101 + err = vfsub_mnt_want_write(h_mnt);
20102 + if (unlikely(err))
20105 + h_parent = au_h_dptr(parent, bindex);
20106 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20107 + if (IS_ERR(h_dentry)) {
20108 + err = PTR_ERR(h_dentry);
20112 + au_set_dbtop(dentry, bindex);
20113 + au_set_dbbot(dentry, bindex);
20114 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20115 + inode = au_new_inode(dentry, /*must_new*/1);
20116 + if (IS_ERR(inode)) {
20117 + err = PTR_ERR(inode);
20118 + au_set_h_dptr(dentry, bindex, NULL);
20119 + au_set_dbtop(dentry, -1);
20120 + au_set_dbbot(dentry, -1);
20122 + if (!inode->i_nlink)
20123 + set_nlink(inode, 1);
20124 + d_tmpfile(dentry, inode);
20125 + au_di(dentry)->di_tmpfile = 1;
20127 + /* update without i_mutex */
20128 + if (au_ibtop(dir) == au_dbtop(dentry))
20129 + au_cpup_attr_timesizes(dir);
20134 + vfsub_mnt_drop_write(h_mnt);
20136 + di_write_unlock(parent);
20138 + di_write_unlock(dentry);
20139 + if (unlikely(err)) {
20140 + au_di_fin(dentry);
20141 + dentry->d_fsdata = NULL;
20144 + si_read_unlock(sb);
20146 + inode_unlock(dir);
20150 +/* ---------------------------------------------------------------------- */
20152 +struct au_link_args {
20153 + aufs_bindex_t bdst, bsrc;
20154 + struct au_pin pin;
20155 + struct path h_path;
20156 + struct dentry *src_parent, *parent;
20159 +static int au_cpup_before_link(struct dentry *src_dentry,
20160 + struct au_link_args *a)
20163 + struct dentry *h_src_dentry;
20164 + struct au_cp_generic cpg = {
20165 + .dentry = src_dentry,
20170 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20173 + di_read_lock_parent(a->src_parent, AuLock_IR);
20174 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20175 + if (unlikely(err))
20178 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20179 + err = au_pin(&a->pin, src_dentry, a->bdst,
20180 + au_opt_udba(src_dentry->d_sb),
20181 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20182 + if (unlikely(err))
20185 + err = au_sio_cpup_simple(&cpg);
20186 + au_unpin(&a->pin);
20189 + di_read_unlock(a->src_parent, AuLock_IR);
20193 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20194 + struct au_link_args *a)
20197 + unsigned char plink;
20198 + aufs_bindex_t bbot;
20199 + struct dentry *h_src_dentry;
20200 + struct inode *h_inode, *inode, *delegated;
20201 + struct super_block *sb;
20202 + struct file *h_file;
20206 + sb = src_dentry->d_sb;
20207 + inode = d_inode(src_dentry);
20208 + if (au_ibtop(inode) <= a->bdst)
20209 + h_inode = au_h_iptr(inode, a->bdst);
20210 + if (!h_inode || !h_inode->i_nlink) {
20211 + /* copyup src_dentry as the name of dentry. */
20212 + bbot = au_dbbot(dentry);
20213 + if (bbot < a->bsrc)
20214 + au_set_dbbot(dentry, a->bsrc);
20215 + au_set_h_dptr(dentry, a->bsrc,
20216 + dget(au_h_dptr(src_dentry, a->bsrc)));
20217 + dget(a->h_path.dentry);
20218 + au_set_h_dptr(dentry, a->bdst, NULL);
20219 + AuDbg("temporary d_inode...\n");
20220 + spin_lock(&dentry->d_lock);
20221 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20222 + spin_unlock(&dentry->d_lock);
20223 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20224 + if (IS_ERR(h_file))
20225 + err = PTR_ERR(h_file);
20227 + struct au_cp_generic cpg = {
20228 + .dentry = dentry,
20233 + .flags = AuCpup_KEEPLINO
20235 + err = au_sio_cpup_simple(&cpg);
20236 + au_h_open_post(dentry, a->bsrc, h_file);
20238 + dput(a->h_path.dentry);
20239 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20241 + au_set_h_dptr(dentry, a->bdst,
20242 + a->h_path.dentry);
20244 + spin_lock(&dentry->d_lock);
20245 + dentry->d_inode = NULL; /* restore */
20246 + spin_unlock(&dentry->d_lock);
20247 + AuDbg("temporary d_inode...done\n");
20248 + au_set_h_dptr(dentry, a->bsrc, NULL);
20249 + au_set_dbbot(dentry, bbot);
20251 + /* the inode of src_dentry already exists on a.bdst branch */
20252 + h_src_dentry = d_find_alias(h_inode);
20253 + if (!h_src_dentry && au_plink_test(inode)) {
20255 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20256 + err = PTR_ERR(h_src_dentry);
20257 + if (IS_ERR(h_src_dentry))
20260 + if (unlikely(d_is_negative(h_src_dentry))) {
20261 + dput(h_src_dentry);
20262 + h_src_dentry = NULL;
20266 + if (h_src_dentry) {
20267 + delegated = NULL;
20268 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20269 + &a->h_path, &delegated);
20270 + if (unlikely(err == -EWOULDBLOCK)) {
20271 + pr_warn("cannot retry for NFSv4 delegation"
20272 + " for an internal link\n");
20275 + dput(h_src_dentry);
20277 + AuIOErr("no dentry found for hi%lu on b%d\n",
20278 + h_inode->i_ino, a->bdst);
20283 + if (!err && !plink)
20284 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20291 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20292 + struct dentry *dentry)
20295 + struct au_dtime dt;
20296 + struct au_link_args *a;
20297 + struct dentry *wh_dentry, *h_src_dentry;
20298 + struct inode *inode, *delegated;
20299 + struct super_block *sb;
20300 + struct au_wr_dir_args wr_dir_args = {
20301 + /* .force_btgt = -1, */
20302 + .flags = AuWrDir_ADD_ENTRY
20306 + inode = d_inode(src_dentry);
20307 + IMustLock(inode);
20310 + a = kzalloc(sizeof(*a), GFP_NOFS);
20311 + if (unlikely(!a))
20314 + a->parent = dentry->d_parent; /* dir inode is locked */
20315 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20316 + AuLock_NOPLM | AuLock_GEN);
20317 + if (unlikely(err))
20319 + err = au_d_linkable(src_dentry);
20320 + if (unlikely(err))
20322 + err = au_d_may_add(dentry);
20323 + if (unlikely(err))
20326 + a->src_parent = dget_parent(src_dentry);
20327 + wr_dir_args.force_btgt = au_ibtop(inode);
20329 + di_write_lock_parent(a->parent);
20330 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20331 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20333 + err = PTR_ERR(wh_dentry);
20334 + if (IS_ERR(wh_dentry))
20338 + sb = dentry->d_sb;
20339 + a->bdst = au_dbtop(dentry);
20340 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20341 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20342 + a->bsrc = au_ibtop(inode);
20343 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20344 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20345 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20346 + if (!h_src_dentry) {
20347 + a->bsrc = au_dbtop(src_dentry);
20348 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20349 + AuDebugOn(!h_src_dentry);
20350 + } else if (IS_ERR(h_src_dentry)) {
20351 + err = PTR_ERR(h_src_dentry);
20356 + * aufs doesn't touch the credential so
20357 + * security_dentry_create_files_as() is unnecessary.
20359 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20360 + if (a->bdst < a->bsrc
20361 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20362 + err = au_cpup_or_link(src_dentry, dentry, a);
20364 + delegated = NULL;
20365 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20366 + &a->h_path, &delegated);
20367 + if (unlikely(err == -EWOULDBLOCK)) {
20368 + pr_warn("cannot retry for NFSv4 delegation"
20369 + " for an internal link\n");
20373 + dput(h_src_dentry);
20376 + * copyup src_dentry to the branch we process,
20377 + * and then link(2) to it.
20379 + dput(h_src_dentry);
20380 + if (a->bdst < a->bsrc
20381 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20382 + au_unpin(&a->pin);
20383 + di_write_unlock(a->parent);
20384 + err = au_cpup_before_link(src_dentry, a);
20385 + di_write_lock_parent(a->parent);
20387 + err = au_pin(&a->pin, dentry, a->bdst,
20389 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20390 + if (unlikely(err))
20394 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20396 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20397 + delegated = NULL;
20398 + err = vfsub_link(h_src_dentry,
20399 + au_pinned_h_dir(&a->pin),
20400 + &a->h_path, &delegated);
20401 + if (unlikely(err == -EWOULDBLOCK)) {
20402 + pr_warn("cannot retry"
20403 + " for NFSv4 delegation"
20404 + " for an internal link\n");
20410 + if (unlikely(err))
20414 + a->h_path.dentry = wh_dentry;
20415 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20417 + if (unlikely(err))
20421 + au_dir_ts(dir, a->bdst);
20422 + inode_inc_iversion(dir);
20423 + inc_nlink(inode);
20424 + inode->i_ctime = dir->i_ctime;
20425 + d_instantiate(dentry, au_igrab(inode));
20426 + if (d_unhashed(a->h_path.dentry))
20427 + /* some filesystem calls d_drop() */
20429 + /* some filesystems consume an inode even hardlink */
20430 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20431 + goto out_unpin; /* success */
20434 + /* no delegation since it is just created */
20435 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20436 + /*delegated*/NULL, /*force*/0);
20437 + if (unlikely(rerr)) {
20438 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20441 + au_dtime_revert(&dt);
20443 + au_unpin(&a->pin);
20447 + di_write_unlock(a->parent);
20448 + dput(a->src_parent);
20450 + if (unlikely(err)) {
20451 + au_update_dbtop(dentry);
20454 + aufs_read_and_write_unlock2(dentry, src_dentry);
20462 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20465 + aufs_bindex_t bindex;
20466 + unsigned char diropq;
20467 + struct path h_path;
20468 + struct dentry *wh_dentry, *parent, *opq_dentry;
20469 + struct inode *h_inode;
20470 + struct super_block *sb;
20472 + struct au_pin pin;
20473 + struct au_dtime dt;
20474 + } *a; /* reduce the stack usage */
20475 + struct au_wr_dir_args wr_dir_args = {
20476 + .force_btgt = -1,
20477 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20483 + a = kmalloc(sizeof(*a), GFP_NOFS);
20484 + if (unlikely(!a))
20487 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20488 + if (unlikely(err))
20490 + err = au_d_may_add(dentry);
20491 + if (unlikely(err))
20494 + parent = dentry->d_parent; /* dir inode is locked */
20495 + di_write_lock_parent(parent);
20496 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20497 + &a->pin, &wr_dir_args);
20498 + err = PTR_ERR(wh_dentry);
20499 + if (IS_ERR(wh_dentry))
20502 + sb = dentry->d_sb;
20503 + bindex = au_dbtop(dentry);
20504 + h_path.dentry = au_h_dptr(dentry, bindex);
20505 + h_path.mnt = au_sbr_mnt(sb, bindex);
20506 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20507 + if (unlikely(err))
20510 + /* make the dir opaque */
20512 + h_inode = d_inode(h_path.dentry);
20514 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20515 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20516 + opq_dentry = au_diropq_create(dentry, bindex);
20517 + inode_unlock(h_inode);
20518 + err = PTR_ERR(opq_dentry);
20519 + if (IS_ERR(opq_dentry))
20521 + dput(opq_dentry);
20525 + err = epilog(dir, bindex, wh_dentry, dentry);
20528 + goto out_unpin; /* success */
20533 + AuLabel(revert opq);
20534 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20535 + rerr = au_diropq_remove(dentry, bindex);
20536 + inode_unlock(h_inode);
20538 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20539 + dentry, err, rerr);
20545 + AuLabel(revert dir);
20546 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20548 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20549 + dentry, err, rerr);
20552 + au_dtime_revert(&a->dt);
20554 + au_unpin(&a->pin);
20557 + di_write_unlock(parent);
20559 + if (unlikely(err)) {
20560 + au_update_dbtop(dentry);
20563 + aufs_read_unlock(dentry, AuLock_DW);
20569 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20570 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20571 +++ linux/fs/aufs/i_op.c 2020-04-03 08:16:47.547461775 +0200
20573 +// SPDX-License-Identifier: GPL-2.0
20575 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20577 + * This program, aufs is free software; you can redistribute it and/or modify
20578 + * it under the terms of the GNU General Public License as published by
20579 + * the Free Software Foundation; either version 2 of the License, or
20580 + * (at your option) any later version.
20582 + * This program is distributed in the hope that it will be useful,
20583 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20584 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20585 + * GNU General Public License for more details.
20587 + * You should have received a copy of the GNU General Public License
20588 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20592 + * inode operations (except add/del/rename)
20595 +#include <linux/device_cgroup.h>
20596 +#include <linux/fs_stack.h>
20597 +#include <linux/iversion.h>
20598 +#include <linux/namei.h>
20599 +#include <linux/security.h>
20602 +static int h_permission(struct inode *h_inode, int mask,
20603 + struct path *h_path, int brperm)
20606 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20609 + if (write_mask && IS_IMMUTABLE(h_inode))
20613 + if (((mask & MAY_EXEC)
20614 + && S_ISREG(h_inode->i_mode)
20615 + && (path_noexec(h_path)
20616 + || !(h_inode->i_mode & 0111))))
20620 + * - skip the lower fs test in the case of write to ro branch.
20621 + * - nfs dir permission write check is optimized, but a policy for
20622 + * link/rename requires a real check.
20623 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20624 + * in this case, generic_permission() returns -EOPNOTSUPP.
20626 + if ((write_mask && !au_br_writable(brperm))
20627 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20628 + && write_mask && !(mask & MAY_READ))
20629 + || !h_inode->i_op->permission) {
20630 + /* AuLabel(generic_permission); */
20631 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20632 + err = generic_permission(h_inode, mask);
20633 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20634 + err = h_inode->i_op->permission(h_inode, mask);
20637 + /* AuLabel(h_inode->permission); */
20638 + err = h_inode->i_op->permission(h_inode, mask);
20643 + err = devcgroup_inode_permission(h_inode, mask);
20645 + err = security_inode_permission(h_inode, mask);
20651 +static int aufs_permission(struct inode *inode, int mask)
20654 + aufs_bindex_t bindex, bbot;
20655 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20656 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20657 + struct inode *h_inode;
20658 + struct super_block *sb;
20659 + struct au_branch *br;
20661 + /* todo: support rcu-walk? */
20662 + if (mask & MAY_NOT_BLOCK)
20665 + sb = inode->i_sb;
20666 + si_read_lock(sb, AuLock_FLUSH);
20667 + ii_read_lock_child(inode);
20668 +#if 0 /* reserved for future use */
20670 + * This test may be rather 'too much' since the test is essentially done
20671 + * in the aufs_lookup(). Theoretically it is possible that the inode
20672 + * generation doesn't match to the superblock's here. But it isn't a
20673 + * big deal I suppose.
20675 + err = au_iigen_test(inode, au_sigen(sb));
20676 + if (unlikely(err))
20682 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20683 + err = au_busy_or_stale();
20684 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20685 + if (unlikely(!h_inode
20686 + || (h_inode->i_mode & S_IFMT)
20687 + != (inode->i_mode & S_IFMT)))
20691 + bindex = au_ibtop(inode);
20692 + br = au_sbr(sb, bindex);
20693 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20696 + && !special_file(h_inode->i_mode)) {
20697 + /* test whether the upper writable branch exists */
20699 + for (; bindex >= 0; bindex--)
20700 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20708 + /* non-write to dir */
20710 + bbot = au_ibbot(inode);
20711 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20712 + h_inode = au_h_iptr(inode, bindex);
20714 + err = au_busy_or_stale();
20715 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20718 + br = au_sbr(sb, bindex);
20719 + err = h_permission(h_inode, mask, &br->br_path,
20725 + ii_read_unlock(inode);
20726 + si_read_unlock(sb);
20730 +/* ---------------------------------------------------------------------- */
20732 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20733 + unsigned int flags)
20735 + struct dentry *ret, *parent;
20736 + struct inode *inode;
20737 + struct super_block *sb;
20738 + int err, npositive;
20742 + /* todo: support rcu-walk? */
20743 + ret = ERR_PTR(-ECHILD);
20744 + if (flags & LOOKUP_RCU)
20747 + ret = ERR_PTR(-ENAMETOOLONG);
20748 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20752 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20753 + ret = ERR_PTR(err);
20754 + if (unlikely(err))
20757 + err = au_di_init(dentry);
20758 + ret = ERR_PTR(err);
20759 + if (unlikely(err))
20763 + npositive = 0; /* suppress a warning */
20764 + parent = dentry->d_parent; /* dir inode is locked */
20765 + di_read_lock_parent(parent, AuLock_IR);
20766 + err = au_alive_dir(parent);
20768 + err = au_digen_test(parent, au_sigen(sb));
20770 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20771 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20772 + AuLkup_ALLOW_NEG);
20775 + di_read_unlock(parent, AuLock_IR);
20776 + ret = ERR_PTR(err);
20777 + if (unlikely(err < 0))
20781 + inode = au_new_inode(dentry, /*must_new*/0);
20782 + if (IS_ERR(inode)) {
20783 + ret = (void *)inode;
20790 + atomic_inc(&inode->i_count);
20791 + ret = d_splice_alias(inode, dentry);
20792 +#if 0 /* reserved for future use */
20793 + if (unlikely(d_need_lookup(dentry))) {
20794 + spin_lock(&dentry->d_lock);
20795 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20796 + spin_unlock(&dentry->d_lock);
20800 + if (!IS_ERR(ret)) {
20802 + if (ret && ret != dentry)
20803 + ii_write_unlock(inode);
20805 + ii_write_unlock(inode);
20812 + di_write_unlock(dentry);
20814 + si_read_unlock(sb);
20819 +/* ---------------------------------------------------------------------- */
20822 + * very dirty and complicated aufs ->atomic_open().
20823 + * aufs_atomic_open()
20824 + * + au_aopen_or_create()
20826 + * + vfsub_atomic_open()
20827 + * + branch fs ->atomic_open()
20828 + * may call the actual 'open' for h_file
20829 + * + inc br_nfiles only if opened
20830 + * + au_aopen_no_open() or au_aopen_do_open()
20832 + * au_aopen_do_open()
20833 + * + finish_open()
20834 + * + au_do_aopen()
20835 + * + au_do_open() the body of all 'open'
20836 + * + au_do_open_nondir()
20837 + * set the passed h_file
20839 + * au_aopen_no_open()
20840 + * + finish_no_open()
20843 +struct aopen_node {
20844 + struct hlist_bl_node hblist;
20845 + struct file *file, *h_file;
20848 +static int au_do_aopen(struct inode *inode, struct file *file)
20850 + struct hlist_bl_head *aopen;
20851 + struct hlist_bl_node *pos;
20852 + struct aopen_node *node;
20853 + struct au_do_open_args args = {
20855 + .open = au_do_open_nondir
20858 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20859 + hlist_bl_lock(aopen);
20860 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20861 + if (node->file == file) {
20862 + args.h_file = node->h_file;
20865 + hlist_bl_unlock(aopen);
20866 + /* AuDebugOn(!args.h_file); */
20868 + return au_do_open(file, &args);
20871 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20872 + struct aopen_node *aopen_node)
20875 + struct hlist_bl_head *aopen;
20878 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20879 + au_hbl_add(&aopen_node->hblist, aopen);
20880 + err = finish_open(file, dentry, au_do_aopen);
20881 + au_hbl_del(&aopen_node->hblist, aopen);
20882 + /* AuDbgFile(file); */
20883 + AuDbg("%pd%s%s\n", dentry,
20884 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20885 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20891 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20897 + err = finish_no_open(file, dentry);
20903 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20904 + struct file *file, unsigned int open_flag,
20905 + umode_t create_mode)
20907 + int err, did_open;
20908 + unsigned int lkup_flags;
20909 + aufs_bindex_t bindex;
20910 + struct super_block *sb;
20911 + struct dentry *parent, *d;
20912 + struct vfsub_aopen_args args = {
20913 + .open_flag = open_flag,
20914 + .create_mode = create_mode
20916 + struct aopen_node aopen_node = {
20921 + AuDbg("open_flag 0%o\n", open_flag);
20922 + AuDbgDentry(dentry);
20925 + if (!au_di(dentry)) {
20926 + lkup_flags = LOOKUP_OPEN;
20927 + if (open_flag & O_CREAT)
20928 + lkup_flags |= LOOKUP_CREATE;
20929 + d = aufs_lookup(dir, dentry, lkup_flags);
20931 + err = PTR_ERR(d);
20936 + * obsoleted dentry found.
20937 + * another error will be returned later.
20943 + AuDbgDentry(dentry);
20946 + if (d_is_positive(dentry)
20947 + || d_unhashed(dentry)
20948 + || d_unlinked(dentry)
20949 + || !(open_flag & O_CREAT)) {
20950 + err = au_aopen_no_open(file, dentry);
20951 + goto out; /* success */
20954 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20955 + if (unlikely(err))
20958 + sb = dentry->d_sb;
20959 + parent = dentry->d_parent; /* dir is locked */
20960 + di_write_lock_parent(parent);
20961 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20962 + if (unlikely(err < 0))
20965 + AuDbgDentry(dentry);
20966 + if (d_is_positive(dentry)) {
20967 + err = au_aopen_no_open(file, dentry);
20968 + goto out_parent; /* success */
20971 + args.file = alloc_empty_file(file->f_flags, current_cred());
20972 + err = PTR_ERR(args.file);
20973 + if (IS_ERR(args.file))
20976 + bindex = au_dbtop(dentry);
20977 + err = au_aopen_or_create(dir, dentry, &args);
20979 + AuDbgFile(args.file);
20980 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20981 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20984 + args.file = NULL;
20986 + di_write_unlock(parent);
20987 + di_write_unlock(dentry);
20988 + if (unlikely(err < 0)) {
20995 + err = au_aopen_no_open(file, dentry);
20997 + aopen_node.h_file = args.file;
20998 + err = au_aopen_do_open(file, dentry, &aopen_node);
21000 + if (unlikely(err < 0)) {
21004 + au_lcnt_dec(&args.br->br_nfiles);
21006 + goto out_sb; /* success */
21009 + di_write_unlock(parent);
21010 + di_write_unlock(dentry);
21012 + si_read_unlock(sb);
21020 +/* ---------------------------------------------------------------------- */
21022 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21023 + const unsigned char add_entry, aufs_bindex_t bcpup,
21024 + aufs_bindex_t btop)
21027 + struct dentry *h_parent;
21028 + struct inode *h_dir;
21031 + IMustLock(d_inode(parent));
21033 + di_write_lock_parent(parent);
21036 + if (!au_h_dptr(parent, bcpup)) {
21037 + if (btop > bcpup)
21038 + err = au_cpup_dirs(dentry, bcpup);
21039 + else if (btop < bcpup)
21040 + err = au_cpdown_dirs(dentry, bcpup);
21044 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21045 + h_parent = au_h_dptr(parent, bcpup);
21046 + h_dir = d_inode(h_parent);
21047 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21048 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21049 + /* todo: no unlock here */
21050 + inode_unlock_shared(h_dir);
21052 + AuDbg("bcpup %d\n", bcpup);
21054 + if (d_really_is_negative(dentry))
21055 + au_set_h_dptr(dentry, btop, NULL);
21056 + au_update_dbrange(dentry, /*do_put_zero*/0);
21061 + di_write_unlock(parent);
21063 + err = bcpup; /* success */
21070 + * decide the branch and the parent dir where we will create a new entry.
21071 + * returns new bindex or an error.
21072 + * copyup the parent dir if needed.
21074 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21075 + struct au_wr_dir_args *args)
21078 + unsigned int flags;
21079 + aufs_bindex_t bcpup, btop, src_btop;
21080 + const unsigned char add_entry
21081 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21082 + | au_ftest_wrdir(args->flags, TMPFILE);
21083 + struct super_block *sb;
21084 + struct dentry *parent;
21085 + struct au_sbinfo *sbinfo;
21087 + sb = dentry->d_sb;
21088 + sbinfo = au_sbi(sb);
21089 + parent = dget_parent(dentry);
21090 + btop = au_dbtop(dentry);
21092 + if (args->force_btgt < 0) {
21093 + if (src_dentry) {
21094 + src_btop = au_dbtop(src_dentry);
21095 + if (src_btop < btop)
21096 + bcpup = src_btop;
21097 + } else if (add_entry) {
21099 + if (au_ftest_wrdir(args->flags, ISDIR))
21100 + au_fset_wbr(flags, DIR);
21101 + err = AuWbrCreate(sbinfo, dentry, flags);
21105 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21107 + err = AuWbrCopyup(sbinfo, dentry);
21109 + if (!IS_ROOT(dentry)) {
21110 + di_read_lock_parent(parent, !AuLock_IR);
21111 + err = AuWbrCopyup(sbinfo, dentry);
21112 + di_read_unlock(parent, !AuLock_IR);
21114 + err = AuWbrCopyup(sbinfo, dentry);
21117 + if (unlikely(err < 0))
21121 + bcpup = args->force_btgt;
21122 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21125 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21127 + if (bcpup == btop)
21128 + goto out; /* success */
21130 + /* copyup the new parent into the branch we process */
21131 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21133 + if (d_really_is_negative(dentry)) {
21134 + au_set_h_dptr(dentry, btop, NULL);
21135 + au_set_dbtop(dentry, bcpup);
21136 + au_set_dbbot(dentry, bcpup);
21138 + AuDebugOn(add_entry
21139 + && !au_ftest_wrdir(args->flags, TMPFILE)
21140 + && !au_h_dptr(dentry, bcpup));
21148 +/* ---------------------------------------------------------------------- */
21150 +void au_pin_hdir_unlock(struct au_pin *p)
21153 + au_hn_inode_unlock(p->hdir);
21156 +int au_pin_hdir_lock(struct au_pin *p)
21164 + /* even if an error happens later, keep this lock */
21165 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21168 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21173 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21174 + p->h_parent, p->br);
21180 +int au_pin_hdir_relock(struct au_pin *p)
21183 + struct inode *h_i;
21184 + struct dentry *h_d[] = {
21189 + err = au_pin_hdir_lock(p);
21190 + if (unlikely(err))
21193 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21196 + if (d_is_positive(h_d[i])) {
21197 + h_i = d_inode(h_d[i]);
21198 + err = !h_i->i_nlink;
21206 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21208 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21211 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21214 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21215 + p->lsc_hi, 0, NULL, _RET_IP_);
21216 + au_pin_hdir_set_owner(p, current);
21220 +void au_pin_hdir_release(struct au_pin *p)
21223 + au_pin_hdir_set_owner(p, p->task);
21224 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21228 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21230 + if (pin && pin->parent)
21231 + return au_h_dptr(pin->parent, pin->bindex);
21235 +void au_unpin(struct au_pin *p)
21238 + au_pin_hdir_unlock(p);
21239 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21240 + vfsub_mnt_drop_write(p->h_mnt);
21244 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21245 + di_read_unlock(p->parent, AuLock_IR);
21246 + iput(p->hdir->hi_inode);
21248 + p->parent = NULL;
21251 + /* do not clear p->task */
21254 +int au_do_pin(struct au_pin *p)
21257 + struct super_block *sb;
21258 + struct inode *h_dir;
21261 + sb = p->dentry->d_sb;
21262 + p->br = au_sbr(sb, p->bindex);
21263 + if (IS_ROOT(p->dentry)) {
21264 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21265 + p->h_mnt = au_br_mnt(p->br);
21266 + err = vfsub_mnt_want_write(p->h_mnt);
21267 + if (unlikely(err)) {
21268 + au_fclr_pin(p->flags, MNT_WRITE);
21275 + p->h_dentry = NULL;
21276 + if (p->bindex <= au_dbbot(p->dentry))
21277 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21279 + p->parent = dget_parent(p->dentry);
21280 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21281 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21284 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21285 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21287 + h_dir = p->hdir->hi_inode;
21291 + * if DI_LOCKED is not set, then p->parent may be different
21292 + * and h_parent can be NULL.
21294 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21296 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21297 + di_read_unlock(p->parent, AuLock_IR);
21299 + p->parent = NULL;
21303 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21304 + p->h_mnt = au_br_mnt(p->br);
21305 + err = vfsub_mnt_want_write(p->h_mnt);
21306 + if (unlikely(err)) {
21307 + au_fclr_pin(p->flags, MNT_WRITE);
21308 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21309 + di_read_unlock(p->parent, AuLock_IR);
21311 + p->parent = NULL;
21317 + err = au_pin_hdir_lock(p);
21319 + goto out; /* success */
21324 + pr_err("err %d\n", err);
21325 + err = au_busy_or_stale();
21330 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21331 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21332 + unsigned int udba, unsigned char flags)
21334 + p->dentry = dentry;
21336 + p->lsc_di = lsc_di;
21337 + p->lsc_hi = lsc_hi;
21338 + p->flags = flags;
21339 + p->bindex = bindex;
21341 + p->parent = NULL;
21345 + p->h_dentry = NULL;
21346 + p->h_parent = NULL;
21348 + p->task = current;
21351 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21352 + unsigned int udba, unsigned char flags)
21354 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21356 + return au_do_pin(pin);
21359 +/* ---------------------------------------------------------------------- */
21362 + * ->setattr() and ->getattr() are called in various cases.
21363 + * chmod, stat: dentry is revalidated.
21364 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21366 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21368 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21369 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21372 + struct dentry *parent;
21375 + if (au_digen_test(dentry, sigen)) {
21376 + parent = dget_parent(dentry);
21377 + di_read_lock_parent(parent, AuLock_IR);
21378 + err = au_refresh_dentry(dentry, parent);
21379 + di_read_unlock(parent, AuLock_IR);
21387 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21388 + struct au_icpup_args *a)
21392 + aufs_bindex_t btop, ibtop;
21393 + struct dentry *hi_wh, *parent;
21394 + struct inode *inode;
21395 + struct au_wr_dir_args wr_dir_args = {
21396 + .force_btgt = -1,
21400 + if (d_is_dir(dentry))
21401 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21402 + /* plink or hi_wh() case */
21403 + btop = au_dbtop(dentry);
21404 + inode = d_inode(dentry);
21405 + ibtop = au_ibtop(inode);
21406 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21407 + wr_dir_args.force_btgt = ibtop;
21408 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21409 + if (unlikely(err < 0))
21413 + au_fset_icpup(a->flags, DID_CPUP);
21416 + a->pin_flags = AuPin_MNT_WRITE;
21418 + if (!IS_ROOT(dentry)) {
21419 + au_fset_pin(a->pin_flags, DI_LOCKED);
21420 + parent = dget_parent(dentry);
21421 + di_write_lock_parent(parent);
21424 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21425 + if (unlikely(err))
21429 + a->h_path.dentry = au_h_dptr(dentry, btop);
21430 + a->h_inode = d_inode(a->h_path.dentry);
21431 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21432 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21433 + if (ia->ia_size < i_size_read(a->h_inode))
21434 + sz = ia->ia_size;
21435 + inode_unlock_shared(a->h_inode);
21439 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21440 + hi_wh = au_hi_wh(inode, a->btgt);
21442 + struct au_cp_generic cpg = {
21443 + .dentry = dentry,
21449 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21450 + if (unlikely(err))
21452 + hi_wh = au_hi_wh(inode, a->btgt);
21453 + /* todo: revalidate hi_wh? */
21458 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21459 + di_downgrade_lock(parent, AuLock_IR);
21463 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21464 + goto out; /* success */
21466 + if (!d_unhashed(dentry)) {
21467 + struct au_cp_generic cpg = {
21468 + .dentry = dentry,
21473 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21475 + err = au_sio_cpup_simple(&cpg);
21477 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21478 + } else if (!hi_wh)
21479 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21481 + a->h_path.dentry = hi_wh; /* do not dget here */
21484 + a->h_inode = d_inode(a->h_path.dentry);
21486 + goto out; /* success */
21487 + au_unpin(&a->pin);
21490 + di_write_unlock(parent);
21495 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21499 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21502 + struct inode *inode, *delegated;
21503 + struct super_block *sb;
21504 + struct file *file;
21505 + struct au_icpup_args *a;
21507 + inode = d_inode(dentry);
21508 + IMustLock(inode);
21510 + err = setattr_prepare(dentry, ia);
21511 + if (unlikely(err))
21515 + a = kzalloc(sizeof(*a), GFP_NOFS);
21516 + if (unlikely(!a))
21519 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21520 + ia->ia_valid &= ~ATTR_MODE;
21523 + sb = dentry->d_sb;
21524 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21525 + if (unlikely(err))
21528 + if (ia->ia_valid & ATTR_FILE) {
21529 + /* currently ftruncate(2) only */
21530 + AuDebugOn(!d_is_reg(dentry));
21531 + file = ia->ia_file;
21532 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21534 + if (unlikely(err))
21536 + ia->ia_file = au_hf_top(file);
21537 + a->udba = AuOpt_UDBA_NONE;
21539 + /* fchmod() doesn't pass ia_file */
21540 + a->udba = au_opt_udba(sb);
21541 + di_write_lock_child(dentry);
21542 + /* no d_unlinked(), to set UDBA_NONE for root */
21543 + if (d_unhashed(dentry))
21544 + a->udba = AuOpt_UDBA_NONE;
21545 + if (a->udba != AuOpt_UDBA_NONE) {
21546 + AuDebugOn(IS_ROOT(dentry));
21547 + err = au_reval_for_attr(dentry, au_sigen(sb));
21548 + if (unlikely(err))
21553 + err = au_pin_and_icpup(dentry, ia, a);
21554 + if (unlikely(err < 0))
21556 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21557 + ia->ia_file = NULL;
21558 + ia->ia_valid &= ~ATTR_FILE;
21561 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21562 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21563 + == (ATTR_MODE | ATTR_CTIME)) {
21564 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21565 + if (unlikely(err))
21567 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21568 + && (ia->ia_valid & ATTR_CTIME)) {
21569 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21570 + if (unlikely(err))
21574 + if (ia->ia_valid & ATTR_SIZE) {
21577 + if (ia->ia_size < i_size_read(inode))
21579 + truncate_setsize(inode, ia->ia_size);
21582 + if (ia->ia_valid & ATTR_FILE)
21584 + inode_unlock(a->h_inode);
21585 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21586 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21588 + delegated = NULL;
21590 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21592 + err = break_deleg_wait(&delegated);
21600 + * regardless aufs 'acl' option setting.
21601 + * why don't all acl-aware fs call this func from their ->setattr()?
21603 + if (!err && (ia->ia_valid & ATTR_MODE))
21604 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21606 + au_cpup_attr_changeable(inode);
21609 + inode_unlock(a->h_inode);
21610 + au_unpin(&a->pin);
21611 + if (unlikely(err))
21612 + au_update_dbtop(dentry);
21614 + di_write_unlock(dentry);
21616 + fi_write_unlock(file);
21617 + ia->ia_file = file;
21618 + ia->ia_valid |= ATTR_FILE;
21621 + si_read_unlock(sb);
21629 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21630 +static int au_h_path_to_set_attr(struct dentry *dentry,
21631 + struct au_icpup_args *a, struct path *h_path)
21634 + struct super_block *sb;
21636 + sb = dentry->d_sb;
21637 + a->udba = au_opt_udba(sb);
21638 + /* no d_unlinked(), to set UDBA_NONE for root */
21639 + if (d_unhashed(dentry))
21640 + a->udba = AuOpt_UDBA_NONE;
21641 + if (a->udba != AuOpt_UDBA_NONE) {
21642 + AuDebugOn(IS_ROOT(dentry));
21643 + err = au_reval_for_attr(dentry, au_sigen(sb));
21644 + if (unlikely(err))
21647 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21648 + if (unlikely(err < 0))
21651 + h_path->dentry = a->h_path.dentry;
21652 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21658 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21659 + struct au_sxattr *arg)
21662 + struct path h_path;
21663 + struct super_block *sb;
21664 + struct au_icpup_args *a;
21665 + struct inode *h_inode;
21667 + IMustLock(inode);
21670 + a = kzalloc(sizeof(*a), GFP_NOFS);
21671 + if (unlikely(!a))
21674 + sb = dentry->d_sb;
21675 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21676 + if (unlikely(err))
21679 + h_path.dentry = NULL; /* silence gcc */
21680 + di_write_lock_child(dentry);
21681 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21682 + if (unlikely(err))
21685 + inode_unlock(a->h_inode);
21686 + switch (arg->type) {
21687 + case AU_XATTR_SET:
21688 + AuDebugOn(d_is_negative(h_path.dentry));
21689 + err = vfsub_setxattr(h_path.dentry,
21690 + arg->u.set.name, arg->u.set.value,
21691 + arg->u.set.size, arg->u.set.flags);
21694 + err = -EOPNOTSUPP;
21695 + h_inode = d_inode(h_path.dentry);
21696 + if (h_inode->i_op->set_acl)
21697 + /* this will call posix_acl_update_mode */
21698 + err = h_inode->i_op->set_acl(h_inode,
21699 + arg->u.acl_set.acl,
21700 + arg->u.acl_set.type);
21704 + au_cpup_attr_timesizes(inode);
21706 + au_unpin(&a->pin);
21707 + if (unlikely(err))
21708 + au_update_dbtop(dentry);
21711 + di_write_unlock(dentry);
21712 + si_read_unlock(sb);
21721 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21722 + unsigned int nlink)
21726 + inode->i_mode = st->mode;
21727 + /* don't i_[ug]id_write() here */
21728 + inode->i_uid = st->uid;
21729 + inode->i_gid = st->gid;
21730 + inode->i_atime = st->atime;
21731 + inode->i_mtime = st->mtime;
21732 + inode->i_ctime = st->ctime;
21734 + au_cpup_attr_nlink(inode, /*force*/0);
21735 + if (S_ISDIR(inode->i_mode)) {
21736 + n = inode->i_nlink;
21739 + smp_mb(); /* for i_nlink */
21740 + /* 0 can happen */
21741 + set_nlink(inode, n);
21744 + spin_lock(&inode->i_lock);
21745 + inode->i_blocks = st->blocks;
21746 + i_size_write(inode, st->size);
21747 + spin_unlock(&inode->i_lock);
21751 + * common routine for aufs_getattr() and au_getxattr().
21752 + * returns zero or negative (an error).
21753 + * @dentry will be read-locked in success.
21755 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21759 + unsigned int mnt_flags, sigen;
21760 + unsigned char udba_none;
21761 + aufs_bindex_t bindex;
21762 + struct super_block *sb, *h_sb;
21763 + struct inode *inode;
21765 + h_path->mnt = NULL;
21766 + h_path->dentry = NULL;
21769 + sb = dentry->d_sb;
21770 + mnt_flags = au_mntflags(sb);
21771 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21773 + if (unlikely(locked))
21774 + goto body; /* skip locking dinfo */
21776 + /* support fstat(2) */
21777 + if (!d_unlinked(dentry) && !udba_none) {
21778 + sigen = au_sigen(sb);
21779 + err = au_digen_test(dentry, sigen);
21781 + di_read_lock_child(dentry, AuLock_IR);
21782 + err = au_dbrange_test(dentry);
21783 + if (unlikely(err)) {
21784 + di_read_unlock(dentry, AuLock_IR);
21788 + AuDebugOn(IS_ROOT(dentry));
21789 + di_write_lock_child(dentry);
21790 + err = au_dbrange_test(dentry);
21792 + err = au_reval_for_attr(dentry, sigen);
21794 + di_downgrade_lock(dentry, AuLock_IR);
21796 + di_write_unlock(dentry);
21801 + di_read_lock_child(dentry, AuLock_IR);
21804 + inode = d_inode(dentry);
21805 + bindex = au_ibtop(inode);
21806 + h_path->mnt = au_sbr_mnt(sb, bindex);
21807 + h_sb = h_path->mnt->mnt_sb;
21809 + && !au_test_fs_bad_iattr(h_sb)
21811 + goto out; /* success */
21813 + if (au_dbtop(dentry) == bindex)
21814 + h_path->dentry = au_h_dptr(dentry, bindex);
21815 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21816 + h_path->dentry = au_plink_lkup(inode, bindex);
21817 + if (IS_ERR(h_path->dentry))
21818 + /* pretending success */
21819 + h_path->dentry = NULL;
21821 + dput(h_path->dentry);
21828 +static int aufs_getattr(const struct path *path, struct kstat *st,
21829 + u32 request, unsigned int query)
21832 + unsigned char positive;
21833 + struct path h_path;
21834 + struct dentry *dentry;
21835 + struct inode *inode;
21836 + struct super_block *sb;
21838 + dentry = path->dentry;
21839 + inode = d_inode(dentry);
21840 + sb = dentry->d_sb;
21841 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21842 + if (unlikely(err))
21844 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21845 + if (unlikely(err))
21847 + if (unlikely(!h_path.dentry))
21848 + /* illegally overlapped or something */
21849 + goto out_fill; /* pretending success */
21851 + positive = d_is_positive(h_path.dentry);
21853 + /* no vfsub version */
21854 + err = vfs_getattr(&h_path, st, request, query);
21857 + au_refresh_iattr(inode, st,
21858 + d_inode(h_path.dentry)->i_nlink);
21859 + goto out_fill; /* success */
21865 + generic_fillattr(inode, st);
21867 + di_read_unlock(dentry, AuLock_IR);
21869 + si_read_unlock(sb);
21875 +/* ---------------------------------------------------------------------- */
21877 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21878 + struct delayed_call *done)
21881 + struct dentry *h_dentry;
21882 + struct inode *h_inode;
21884 + aufs_bindex_t bindex;
21886 + ret = NULL; /* suppress a warning */
21891 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21892 + if (unlikely(err))
21895 + err = au_d_hashed_positive(dentry);
21896 + if (unlikely(err))
21900 + inode = d_inode(dentry);
21901 + bindex = au_ibtop(inode);
21902 + h_inode = au_h_iptr(inode, bindex);
21903 + if (unlikely(!h_inode->i_op->get_link))
21908 + if (au_dbtop(dentry) <= bindex) {
21909 + h_dentry = au_h_dptr(dentry, bindex);
21914 + h_dentry = d_find_any_alias(h_inode);
21915 + if (IS_ERR(h_dentry)) {
21916 + err = PTR_ERR(h_dentry);
21920 + if (unlikely(!h_dentry))
21924 + AuDbg("%ps\n", h_inode->i_op->get_link);
21925 + AuDbgDentry(h_dentry);
21926 + ret = vfs_get_link(h_dentry, done);
21929 + err = PTR_ERR(ret);
21932 + aufs_read_unlock(dentry, AuLock_IR);
21934 + if (unlikely(err))
21935 + ret = ERR_PTR(err);
21936 + AuTraceErrPtr(ret);
21940 +/* ---------------------------------------------------------------------- */
21942 +static int au_is_special(struct inode *inode)
21944 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21947 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21951 + aufs_bindex_t bindex;
21952 + struct super_block *sb;
21953 + struct inode *h_inode;
21954 + struct vfsmount *h_mnt;
21956 + sb = inode->i_sb;
21957 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21958 + "unexpected s_flags 0x%lx", sb->s_flags);
21960 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21962 + si_read_lock(sb, AuLock_FLUSH);
21963 + ii_write_lock_child(inode);
21966 + bindex = au_ibtop(inode);
21967 + h_inode = au_h_iptr(inode, bindex);
21968 + if (!au_test_ro(sb, bindex, inode)) {
21969 + h_mnt = au_sbr_mnt(sb, bindex);
21970 + err = vfsub_mnt_want_write(h_mnt);
21972 + err = vfsub_update_time(h_inode, ts, flags);
21973 + vfsub_mnt_drop_write(h_mnt);
21975 + } else if (au_is_special(h_inode)) {
21977 + * Never copy-up here.
21978 + * These special files may already be opened and used for
21979 + * communicating. If we copied it up, then the communication
21980 + * would be corrupted.
21982 + AuWarn1("timestamps for i%lu are ignored "
21983 + "since it is on readonly branch (hi%lu).\n",
21984 + inode->i_ino, h_inode->i_ino);
21985 + } else if (flags & ~S_ATIME) {
21987 + AuIOErr1("unexpected flags 0x%x\n", flags);
21992 + au_cpup_attr_timesizes(inode);
21993 + ii_write_unlock(inode);
21994 + si_read_unlock(sb);
21997 + if (!err && (flags & S_VERSION))
21998 + inode_inc_iversion(inode);
22003 +/* ---------------------------------------------------------------------- */
22005 +/* no getattr version will be set by module.c:aufs_init() */
22006 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22008 + [AuIop_SYMLINK] = {
22009 + .permission = aufs_permission,
22010 +#ifdef CONFIG_FS_POSIX_ACL
22011 + .get_acl = aufs_get_acl,
22012 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22015 + .setattr = aufs_setattr,
22016 + .getattr = aufs_getattr,
22018 +#ifdef CONFIG_AUFS_XATTR
22019 + .listxattr = aufs_listxattr,
22022 + .get_link = aufs_get_link,
22024 + /* .update_time = aufs_update_time */
22027 + .create = aufs_create,
22028 + .lookup = aufs_lookup,
22029 + .link = aufs_link,
22030 + .unlink = aufs_unlink,
22031 + .symlink = aufs_symlink,
22032 + .mkdir = aufs_mkdir,
22033 + .rmdir = aufs_rmdir,
22034 + .mknod = aufs_mknod,
22035 + .rename = aufs_rename,
22037 + .permission = aufs_permission,
22038 +#ifdef CONFIG_FS_POSIX_ACL
22039 + .get_acl = aufs_get_acl,
22040 + .set_acl = aufs_set_acl,
22043 + .setattr = aufs_setattr,
22044 + .getattr = aufs_getattr,
22046 +#ifdef CONFIG_AUFS_XATTR
22047 + .listxattr = aufs_listxattr,
22050 + .update_time = aufs_update_time,
22051 + .atomic_open = aufs_atomic_open,
22052 + .tmpfile = aufs_tmpfile
22054 + [AuIop_OTHER] = {
22055 + .permission = aufs_permission,
22056 +#ifdef CONFIG_FS_POSIX_ACL
22057 + .get_acl = aufs_get_acl,
22058 + .set_acl = aufs_set_acl,
22061 + .setattr = aufs_setattr,
22062 + .getattr = aufs_getattr,
22064 +#ifdef CONFIG_AUFS_XATTR
22065 + .listxattr = aufs_listxattr,
22068 + .update_time = aufs_update_time
22071 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22072 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
22073 +++ linux/fs/aufs/i_op_del.c 2020-01-27 10:57:18.172204883 +0100
22075 +// SPDX-License-Identifier: GPL-2.0
22077 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22079 + * This program, aufs is free software; you can redistribute it and/or modify
22080 + * it under the terms of the GNU General Public License as published by
22081 + * the Free Software Foundation; either version 2 of the License, or
22082 + * (at your option) any later version.
22084 + * This program is distributed in the hope that it will be useful,
22085 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22086 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22087 + * GNU General Public License for more details.
22089 + * You should have received a copy of the GNU General Public License
22090 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22094 + * inode operations (del entry)
22097 +#include <linux/iversion.h>
22101 + * decide if a new whiteout for @dentry is necessary or not.
22102 + * when it is necessary, prepare the parent dir for the upper branch whose
22103 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22104 + * be done by caller.
22106 + * 0: wh is unnecessary
22107 + * plus: wh is necessary
22110 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22112 + int need_wh, err;
22113 + aufs_bindex_t btop;
22114 + struct super_block *sb;
22116 + sb = dentry->d_sb;
22117 + btop = au_dbtop(dentry);
22118 + if (*bcpup < 0) {
22120 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22121 + err = AuWbrCopyup(au_sbi(sb), dentry);
22123 + if (unlikely(err < 0))
22127 + AuDebugOn(btop < *bcpup
22128 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22129 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22131 + if (*bcpup != btop) {
22132 + err = au_cpup_dirs(dentry, *bcpup);
22133 + if (unlikely(err))
22137 + struct au_dinfo *dinfo, *tmp;
22139 + need_wh = -ENOMEM;
22140 + dinfo = au_di(dentry);
22141 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22143 + au_di_cp(tmp, dinfo);
22144 + au_di_swap(tmp, dinfo);
22145 + /* returns the number of positive dentries */
22146 + need_wh = au_lkup_dentry(dentry, btop + 1,
22147 + /* AuLkup_IGNORE_PERM */ 0);
22148 + au_di_swap(tmp, dinfo);
22149 + au_rw_write_unlock(&tmp->di_rwsem);
22153 + AuDbg("need_wh %d\n", need_wh);
22161 + * simple tests for the del-entry operations.
22162 + * following the checks in vfs, plus the parent-child relationship.
22164 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22165 + struct dentry *h_parent, int isdir)
22169 + struct dentry *h_dentry, *h_latest;
22170 + struct inode *h_inode;
22172 + h_dentry = au_h_dptr(dentry, bindex);
22173 + if (d_really_is_positive(dentry)) {
22175 + if (unlikely(d_is_negative(h_dentry)))
22177 + h_inode = d_inode(h_dentry);
22178 + if (unlikely(!h_inode->i_nlink))
22181 + h_mode = h_inode->i_mode;
22184 + if (unlikely(S_ISDIR(h_mode)))
22186 + } else if (unlikely(!S_ISDIR(h_mode))) {
22191 + /* rename(2) case */
22193 + if (unlikely(d_is_positive(h_dentry)))
22198 + /* expected parent dir is locked */
22199 + if (unlikely(h_parent != h_dentry->d_parent))
22204 + * rmdir a dir may break the consistency on some filesystem.
22205 + * let's try heavy test.
22208 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22209 + && au_test_h_perm(d_inode(h_parent),
22210 + MAY_EXEC | MAY_WRITE)))
22213 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22215 + if (IS_ERR(h_latest))
22217 + if (h_latest == h_dentry)
22226 + * decide the branch where we operate for @dentry. the branch index will be set
22227 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22228 + * dir for reverting.
22229 + * when a new whiteout is necessary, create it.
22231 +static struct dentry*
22232 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22233 + struct au_dtime *dt, struct au_pin *pin)
22235 + struct dentry *wh_dentry;
22236 + struct super_block *sb;
22237 + struct path h_path;
22238 + int err, need_wh;
22239 + unsigned int udba;
22240 + aufs_bindex_t bcpup;
22242 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22243 + wh_dentry = ERR_PTR(need_wh);
22244 + if (unlikely(need_wh < 0))
22247 + sb = dentry->d_sb;
22248 + udba = au_opt_udba(sb);
22250 + err = au_pin(pin, dentry, bcpup, udba,
22251 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22252 + wh_dentry = ERR_PTR(err);
22253 + if (unlikely(err))
22256 + h_path.dentry = au_pinned_h_parent(pin);
22257 + if (udba != AuOpt_UDBA_NONE
22258 + && au_dbtop(dentry) == bcpup) {
22259 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22260 + wh_dentry = ERR_PTR(err);
22261 + if (unlikely(err))
22265 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22266 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22267 + wh_dentry = NULL;
22269 + goto out; /* success, no need to create whiteout */
22271 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22272 + if (IS_ERR(wh_dentry))
22275 + /* returns with the parent is locked and wh_dentry is dget-ed */
22276 + goto out; /* success */
22281 + return wh_dentry;
22285 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22286 + * in order to be revertible and save time for removing many child whiteouts
22288 + * returns 1 when there are too many child whiteout and caller should remove
22289 + * them asynchronously. returns 0 when the number of children is enough small to
22290 + * remove now or the branch fs is a remote fs.
22291 + * otherwise return an error.
22293 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22294 + struct au_nhash *whlist, struct inode *dir)
22296 + int rmdir_later, err, dirwh;
22297 + struct dentry *h_dentry;
22298 + struct super_block *sb;
22299 + struct inode *inode;
22301 + sb = dentry->d_sb;
22302 + SiMustAnyLock(sb);
22303 + h_dentry = au_h_dptr(dentry, bindex);
22304 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22305 + if (unlikely(err))
22308 + /* stop monitoring */
22309 + inode = d_inode(dentry);
22310 + au_hn_free(au_hi(inode, bindex));
22312 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22313 + dirwh = au_sbi(sb)->si_dirwh;
22314 + rmdir_later = (dirwh <= 1);
22315 + if (!rmdir_later)
22316 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22319 + return rmdir_later;
22322 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22323 + if (unlikely(err)) {
22324 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22325 + h_dentry, bindex, err);
22335 + * final procedure for deleting a entry.
22336 + * maintain dentry and iattr.
22338 +static void epilog(struct inode *dir, struct dentry *dentry,
22339 + aufs_bindex_t bindex)
22341 + struct inode *inode;
22343 + inode = d_inode(dentry);
22345 + inode->i_ctime = dir->i_ctime;
22347 + au_dir_ts(dir, bindex);
22348 + inode_inc_iversion(dir);
22352 + * when an error happened, remove the created whiteout and revert everything.
22354 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22355 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22356 + struct dentry *dentry, struct au_dtime *dt)
22359 + struct path h_path = {
22360 + .dentry = wh_dentry,
22361 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22364 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22366 + au_set_dbwh(dentry, bwh);
22367 + au_dtime_revert(dt);
22371 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22375 +/* ---------------------------------------------------------------------- */
22377 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22380 + aufs_bindex_t bwh, bindex, btop;
22381 + struct inode *inode, *h_dir, *delegated;
22382 + struct dentry *parent, *wh_dentry;
22383 + /* to reduce stack size */
22385 + struct au_dtime dt;
22386 + struct au_pin pin;
22387 + struct path h_path;
22393 + a = kmalloc(sizeof(*a), GFP_NOFS);
22394 + if (unlikely(!a))
22397 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22398 + if (unlikely(err))
22400 + err = au_d_hashed_positive(dentry);
22401 + if (unlikely(err))
22403 + inode = d_inode(dentry);
22404 + IMustLock(inode);
22406 + if (unlikely(d_is_dir(dentry)))
22407 + goto out_unlock; /* possible? */
22409 + btop = au_dbtop(dentry);
22410 + bwh = au_dbwh(dentry);
22412 + parent = dentry->d_parent; /* dir inode is locked */
22413 + di_write_lock_parent(parent);
22414 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22416 + err = PTR_ERR(wh_dentry);
22417 + if (IS_ERR(wh_dentry))
22420 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22421 + a->h_path.dentry = au_h_dptr(dentry, btop);
22422 + dget(a->h_path.dentry);
22423 + if (bindex == btop) {
22424 + h_dir = au_pinned_h_dir(&a->pin);
22425 + delegated = NULL;
22426 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22427 + if (unlikely(err == -EWOULDBLOCK)) {
22428 + pr_warn("cannot retry for NFSv4 delegation"
22429 + " for an internal unlink\n");
22433 + /* dir inode is locked */
22434 + h_dir = d_inode(wh_dentry->d_parent);
22435 + IMustLock(h_dir);
22440 + vfsub_drop_nlink(inode);
22441 + epilog(dir, dentry, bindex);
22443 + /* update target timestamps */
22444 + if (bindex == btop) {
22445 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22447 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22449 + /* todo: this timestamp may be reverted later */
22450 + inode->i_ctime = h_dir->i_ctime;
22451 + goto out_unpin; /* success */
22458 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22465 + au_unpin(&a->pin);
22467 + dput(a->h_path.dentry);
22469 + di_write_unlock(parent);
22471 + aufs_read_unlock(dentry, AuLock_DW);
22478 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22480 + int err, rmdir_later;
22481 + aufs_bindex_t bwh, bindex, btop;
22482 + struct inode *inode;
22483 + struct dentry *parent, *wh_dentry, *h_dentry;
22484 + struct au_whtmp_rmdir *args;
22485 + /* to reduce stack size */
22487 + struct au_dtime dt;
22488 + struct au_pin pin;
22494 + a = kmalloc(sizeof(*a), GFP_NOFS);
22495 + if (unlikely(!a))
22498 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22499 + if (unlikely(err))
22501 + err = au_alive_dir(dentry);
22502 + if (unlikely(err))
22504 + inode = d_inode(dentry);
22505 + IMustLock(inode);
22507 + if (unlikely(!d_is_dir(dentry)))
22508 + goto out_unlock; /* possible? */
22511 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22512 + if (unlikely(!args))
22515 + parent = dentry->d_parent; /* dir inode is locked */
22516 + di_write_lock_parent(parent);
22517 + err = au_test_empty(dentry, &args->whlist);
22518 + if (unlikely(err))
22521 + btop = au_dbtop(dentry);
22522 + bwh = au_dbwh(dentry);
22524 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22526 + err = PTR_ERR(wh_dentry);
22527 + if (IS_ERR(wh_dentry))
22530 + h_dentry = au_h_dptr(dentry, btop);
22533 + if (bindex == btop) {
22534 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22536 + rmdir_later = err;
22540 + /* stop monitoring */
22541 + au_hn_free(au_hi(inode, btop));
22543 + /* dir inode is locked */
22544 + IMustLock(d_inode(wh_dentry->d_parent));
22549 + vfsub_dead_dir(inode);
22550 + au_set_dbdiropq(dentry, -1);
22551 + epilog(dir, dentry, bindex);
22553 + if (rmdir_later) {
22554 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22558 + goto out_unpin; /* success */
22566 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22573 + au_unpin(&a->pin);
22577 + di_write_unlock(parent);
22579 + au_whtmp_rmdir_free(args);
22581 + aufs_read_unlock(dentry, AuLock_DW);
22588 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22589 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22590 +++ linux/fs/aufs/i_op_ren.c 2020-01-27 10:57:18.172204883 +0100
22592 +// SPDX-License-Identifier: GPL-2.0
22594 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22596 + * This program, aufs is free software; you can redistribute it and/or modify
22597 + * it under the terms of the GNU General Public License as published by
22598 + * the Free Software Foundation; either version 2 of the License, or
22599 + * (at your option) any later version.
22601 + * This program is distributed in the hope that it will be useful,
22602 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22603 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22604 + * GNU General Public License for more details.
22606 + * You should have received a copy of the GNU General Public License
22607 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22611 + * inode operation (rename entry)
22612 + * todo: this is crazy monster
22615 +#include <linux/iversion.h>
22618 +enum { AuSRC, AuDST, AuSrcDst };
22619 +enum { AuPARENT, AuCHILD, AuParentChild };
22621 +#define AuRen_ISDIR_SRC 1
22622 +#define AuRen_ISDIR_DST (1 << 1)
22623 +#define AuRen_ISSAMEDIR (1 << 2)
22624 +#define AuRen_WHSRC (1 << 3)
22625 +#define AuRen_WHDST (1 << 4)
22626 +#define AuRen_MNT_WRITE (1 << 5)
22627 +#define AuRen_DT_DSTDIR (1 << 6)
22628 +#define AuRen_DIROPQ_SRC (1 << 7)
22629 +#define AuRen_DIROPQ_DST (1 << 8)
22630 +#define AuRen_DIRREN (1 << 9)
22631 +#define AuRen_DROPPED_SRC (1 << 10)
22632 +#define AuRen_DROPPED_DST (1 << 11)
22633 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22634 +#define au_fset_ren(flags, name) \
22635 + do { (flags) |= AuRen_##name; } while (0)
22636 +#define au_fclr_ren(flags, name) \
22637 + do { (flags) &= ~AuRen_##name; } while (0)
22639 +#ifndef CONFIG_AUFS_DIRREN
22640 +#undef AuRen_DIRREN
22641 +#define AuRen_DIRREN 0
22644 +struct au_ren_args {
22646 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22648 + struct inode *dir, *inode;
22649 + struct au_hinode *hdir, *hinode;
22650 + struct au_dtime dt[AuParentChild];
22651 + aufs_bindex_t btop, bdiropq;
22654 +#define src_dentry sd[AuSRC].dentry
22655 +#define src_dir sd[AuSRC].dir
22656 +#define src_inode sd[AuSRC].inode
22657 +#define src_h_dentry sd[AuSRC].h_dentry
22658 +#define src_parent sd[AuSRC].parent
22659 +#define src_h_parent sd[AuSRC].h_parent
22660 +#define src_wh_dentry sd[AuSRC].wh_dentry
22661 +#define src_hdir sd[AuSRC].hdir
22662 +#define src_hinode sd[AuSRC].hinode
22663 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22664 +#define src_dt sd[AuSRC].dt
22665 +#define src_btop sd[AuSRC].btop
22666 +#define src_bdiropq sd[AuSRC].bdiropq
22668 +#define dst_dentry sd[AuDST].dentry
22669 +#define dst_dir sd[AuDST].dir
22670 +#define dst_inode sd[AuDST].inode
22671 +#define dst_h_dentry sd[AuDST].h_dentry
22672 +#define dst_parent sd[AuDST].parent
22673 +#define dst_h_parent sd[AuDST].h_parent
22674 +#define dst_wh_dentry sd[AuDST].wh_dentry
22675 +#define dst_hdir sd[AuDST].hdir
22676 +#define dst_hinode sd[AuDST].hinode
22677 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22678 +#define dst_dt sd[AuDST].dt
22679 +#define dst_btop sd[AuDST].btop
22680 +#define dst_bdiropq sd[AuDST].bdiropq
22682 + struct dentry *h_trap;
22683 + struct au_branch *br;
22684 + struct path h_path;
22685 + struct au_nhash whlist;
22686 + aufs_bindex_t btgt, src_bwh;
22689 + unsigned short auren_flags;
22690 + unsigned char flags; /* syscall parameter */
22691 + unsigned char exchange;
22694 + struct au_whtmp_rmdir *thargs;
22695 + struct dentry *h_dst;
22696 + struct au_hinode *h_root;
22699 +/* ---------------------------------------------------------------------- */
22702 + * functions for reverting.
22703 + * when an error happened in a single rename systemcall, we should revert
22704 + * everything as if nothing happened.
22705 + * we don't need to revert the copied-up/down the parent dir since they are
22709 +#define RevertFailure(fmt, ...) do { \
22710 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22711 + ##__VA_ARGS__, err, rerr); \
22715 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22718 + struct dentry *d;
22719 +#define src_or_dst(member) a->sd[idx].member
22721 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22722 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22723 + rerr = au_diropq_remove(d, a->btgt);
22724 + au_hn_inode_unlock(src_or_dst(hinode));
22725 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22727 + RevertFailure("remove diropq %pd", d);
22729 +#undef src_or_dst_
22732 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22734 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22735 + au_ren_do_rev_diropq(err, a, AuSRC);
22736 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22737 + au_ren_do_rev_diropq(err, a, AuDST);
22740 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22743 + struct inode *delegated;
22745 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22746 + a->src_h_parent);
22747 + rerr = PTR_ERR(a->h_path.dentry);
22748 + if (IS_ERR(a->h_path.dentry)) {
22749 + RevertFailure("lkup one %pd", a->src_dentry);
22753 + delegated = NULL;
22754 + rerr = vfsub_rename(a->dst_h_dir,
22755 + au_h_dptr(a->src_dentry, a->btgt),
22756 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22757 + if (unlikely(rerr == -EWOULDBLOCK)) {
22758 + pr_warn("cannot retry for NFSv4 delegation"
22759 + " for an internal rename\n");
22762 + d_drop(a->h_path.dentry);
22763 + dput(a->h_path.dentry);
22764 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22766 + RevertFailure("rename %pd", a->src_dentry);
22769 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22772 + struct inode *delegated;
22774 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22775 + a->dst_h_parent);
22776 + rerr = PTR_ERR(a->h_path.dentry);
22777 + if (IS_ERR(a->h_path.dentry)) {
22778 + RevertFailure("lkup one %pd", a->dst_dentry);
22781 + if (d_is_positive(a->h_path.dentry)) {
22782 + d_drop(a->h_path.dentry);
22783 + dput(a->h_path.dentry);
22787 + delegated = NULL;
22788 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22789 + &delegated, a->flags);
22790 + if (unlikely(rerr == -EWOULDBLOCK)) {
22791 + pr_warn("cannot retry for NFSv4 delegation"
22792 + " for an internal rename\n");
22795 + d_drop(a->h_path.dentry);
22796 + dput(a->h_path.dentry);
22798 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22800 + RevertFailure("rename %pd", a->h_dst);
22803 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22807 + a->h_path.dentry = a->src_wh_dentry;
22808 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22809 + au_set_dbwh(a->src_dentry, a->src_bwh);
22811 + RevertFailure("unlink %pd", a->src_wh_dentry);
22813 +#undef RevertFailure
22815 +/* ---------------------------------------------------------------------- */
22818 + * when we have to copyup the renaming entry, do it with the rename-target name
22819 + * in order to minimize the cost (the later actual rename is unnecessary).
22820 + * otherwise rename it on the target branch.
22822 +static int au_ren_or_cpup(struct au_ren_args *a)
22825 + struct dentry *d;
22826 + struct inode *delegated;
22828 + d = a->src_dentry;
22829 + if (au_dbtop(d) == a->btgt) {
22830 + a->h_path.dentry = a->dst_h_dentry;
22831 + AuDebugOn(au_dbtop(d) != a->btgt);
22832 + delegated = NULL;
22833 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22834 + a->dst_h_dir, &a->h_path, &delegated,
22836 + if (unlikely(err == -EWOULDBLOCK)) {
22837 + pr_warn("cannot retry for NFSv4 delegation"
22838 + " for an internal rename\n");
22844 + if (!err && a->h_dst)
22845 + /* it will be set to dinfo later */
22851 +/* cf. aufs_rmdir() */
22852 +static int au_ren_del_whtmp(struct au_ren_args *a)
22855 + struct inode *dir;
22857 + dir = a->dst_dir;
22858 + SiMustAnyLock(dir->i_sb);
22859 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22860 + au_sbi(dir->i_sb)->si_dirwh)
22861 + || au_test_fs_remote(a->h_dst->d_sb)) {
22862 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22863 + if (unlikely(err))
22864 + pr_warn("failed removing whtmp dir %pd (%d), "
22865 + "ignored.\n", a->h_dst, err);
22867 + au_nhash_wh_free(&a->thargs->whlist);
22868 + a->thargs->whlist = a->whlist;
22869 + a->whlist.nh_num = 0;
22870 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22872 + a->thargs = NULL;
22878 +/* make it 'opaque' dir. */
22879 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22882 + struct dentry *d, *diropq;
22883 +#define src_or_dst(member) a->sd[idx].member
22886 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22887 + src_or_dst(bdiropq) = au_dbdiropq(d);
22888 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22889 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22890 + diropq = au_diropq_create(d, a->btgt);
22891 + au_hn_inode_unlock(src_or_dst(hinode));
22892 + if (IS_ERR(diropq))
22893 + err = PTR_ERR(diropq);
22897 +#undef src_or_dst_
22901 +static int au_ren_diropq(struct au_ren_args *a)
22904 + unsigned char always;
22905 + struct dentry *d;
22908 + d = a->dst_dentry; /* already renamed on the branch */
22909 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22910 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22911 + && !au_ftest_ren(a->auren_flags, DIRREN)
22912 + && a->btgt != au_dbdiropq(a->src_dentry)
22913 + && (a->dst_wh_dentry
22914 + || a->btgt <= au_dbdiropq(d)
22915 + /* hide the lower to keep xino */
22916 + /* the lowers may not be a dir, but we hide them anyway */
22917 + || a->btgt < au_dbbot(d)
22920 + err = au_ren_do_diropq(a, AuSRC);
22921 + if (unlikely(err))
22923 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22925 + if (!a->exchange)
22926 + goto out; /* success */
22928 + d = a->src_dentry; /* already renamed on the branch */
22929 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22930 + && a->btgt != au_dbdiropq(a->dst_dentry)
22931 + && (a->btgt < au_dbdiropq(d)
22932 + || a->btgt < au_dbbot(d)
22934 + AuDbgDentry(a->src_dentry);
22935 + AuDbgDentry(a->dst_dentry);
22936 + err = au_ren_do_diropq(a, AuDST);
22937 + if (unlikely(err))
22938 + goto out_rev_src;
22939 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22941 + goto out; /* success */
22944 + AuDbg("err %d, reverting src\n", err);
22945 + au_ren_rev_diropq(err, a);
22950 +static int do_rename(struct au_ren_args *a)
22953 + struct dentry *d, *h_d;
22955 + if (!a->exchange) {
22956 + /* prepare workqueue args for asynchronous rmdir */
22957 + h_d = a->dst_h_dentry;
22958 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22959 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22960 + && d_is_positive(h_d)) {
22962 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22964 + if (unlikely(!a->thargs))
22966 + a->h_dst = dget(h_d);
22969 + /* create whiteout for src_dentry */
22970 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22971 + a->src_bwh = au_dbwh(a->src_dentry);
22972 + AuDebugOn(a->src_bwh >= 0);
22973 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22974 + a->src_h_parent);
22975 + err = PTR_ERR(a->src_wh_dentry);
22976 + if (IS_ERR(a->src_wh_dentry))
22980 + /* lookup whiteout for dentry */
22981 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22982 + h_d = au_wh_lkup(a->dst_h_parent,
22983 + &a->dst_dentry->d_name, a->br);
22984 + err = PTR_ERR(h_d);
22987 + if (d_is_negative(h_d))
22990 + a->dst_wh_dentry = h_d;
22993 + /* rename dentry to tmpwh */
22995 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22996 + if (unlikely(err))
22999 + d = a->dst_dentry;
23000 + au_set_h_dptr(d, a->btgt, NULL);
23001 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23002 + if (unlikely(err))
23004 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23008 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23009 +#if 0 /* debugging */
23010 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23011 + && d_is_positive(a->dst_h_dentry)
23012 + && a->src_btop != a->btgt);
23015 + /* rename by vfs_rename or cpup */
23016 + err = au_ren_or_cpup(a);
23017 + if (unlikely(err))
23018 + /* leave the copied-up one */
23021 + /* make dir opaque */
23022 + err = au_ren_diropq(a);
23023 + if (unlikely(err))
23026 + /* update target timestamps */
23027 + if (a->exchange) {
23028 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23029 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23030 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23031 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23033 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23034 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23035 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23036 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23038 + if (!a->exchange) {
23039 + /* remove whiteout for dentry */
23040 + if (a->dst_wh_dentry) {
23041 + a->h_path.dentry = a->dst_wh_dentry;
23042 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23044 + if (unlikely(err))
23048 + /* remove whtmp */
23050 + au_ren_del_whtmp(a); /* ignore this error */
23052 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23055 + goto out_success;
23058 + au_ren_rev_diropq(err, a);
23060 + au_ren_rev_rename(err, a);
23064 + au_ren_rev_whtmp(err, a);
23066 + dput(a->dst_wh_dentry);
23067 + a->dst_wh_dentry = NULL;
23069 + if (a->src_wh_dentry)
23070 + au_ren_rev_whsrc(err, a);
23072 + dput(a->src_wh_dentry);
23073 + dput(a->dst_wh_dentry);
23077 + au_whtmp_rmdir_free(a->thargs);
23078 + a->thargs = NULL;
23084 +/* ---------------------------------------------------------------------- */
23087 + * test if @dentry dir can be rename destination or not.
23088 + * success means, it is a logically empty dir.
23090 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23092 + return au_test_empty(dentry, whlist);
23096 + * test if @a->src_dentry dir can be rename source or not.
23097 + * if it can, return 0.
23099 + * - it is a logically empty dir.
23100 + * - or, it exists on writable branch and has no children including whiteouts
23101 + * on the lower branch unless DIRREN is on.
23103 +static int may_rename_srcdir(struct au_ren_args *a)
23106 + unsigned int rdhash;
23107 + aufs_bindex_t btop, btgt;
23108 + struct dentry *dentry;
23109 + struct super_block *sb;
23110 + struct au_sbinfo *sbinfo;
23112 + dentry = a->src_dentry;
23113 + sb = dentry->d_sb;
23114 + sbinfo = au_sbi(sb);
23115 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23116 + au_fset_ren(a->auren_flags, DIRREN);
23119 + btop = au_dbtop(dentry);
23120 + if (btop != btgt) {
23121 + struct au_nhash whlist;
23123 + SiMustAnyLock(sb);
23124 + rdhash = sbinfo->si_rdhash;
23126 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23128 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23129 + if (unlikely(err))
23131 + err = au_test_empty(dentry, &whlist);
23132 + au_nhash_wh_free(&whlist);
23136 + if (btop == au_dbtaildir(dentry))
23137 + return 0; /* success */
23139 + err = au_test_empty_lower(dentry);
23142 + if (err == -ENOTEMPTY) {
23143 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23146 + AuWarn1("renaming dir who has child(ren) on multiple "
23147 + "branches, is not supported\n");
23154 +/* side effect: sets whlist and h_dentry */
23155 +static int au_ren_may_dir(struct au_ren_args *a)
23158 + unsigned int rdhash;
23159 + struct dentry *d;
23161 + d = a->dst_dentry;
23162 + SiMustAnyLock(d->d_sb);
23165 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23166 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23168 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23169 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23170 + if (unlikely(err))
23173 + if (!a->exchange) {
23174 + au_set_dbtop(d, a->dst_btop);
23175 + err = may_rename_dstdir(d, &a->whlist);
23176 + au_set_dbtop(d, a->btgt);
23178 + err = may_rename_srcdir(a);
23180 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23181 + if (unlikely(err))
23184 + d = a->src_dentry;
23185 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23186 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23187 + err = may_rename_srcdir(a);
23188 + if (unlikely(err)) {
23189 + au_nhash_wh_free(&a->whlist);
23190 + a->whlist.nh_num = 0;
23197 +/* ---------------------------------------------------------------------- */
23200 + * simple tests for rename.
23201 + * following the checks in vfs, plus the parent-child relationship.
23203 +static int au_may_ren(struct au_ren_args *a)
23206 + struct inode *h_inode;
23208 + if (a->src_btop == a->btgt) {
23209 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23210 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23211 + if (unlikely(err))
23214 + if (unlikely(a->src_h_dentry == a->h_trap))
23219 + if (a->dst_btop != a->btgt)
23222 + err = -ENOTEMPTY;
23223 + if (unlikely(a->dst_h_dentry == a->h_trap))
23227 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23228 + if (d_really_is_negative(a->dst_dentry)) {
23229 + if (d_is_negative(a->dst_h_dentry))
23230 + err = au_may_add(a->dst_dentry, a->btgt,
23231 + a->dst_h_parent, isdir);
23233 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23235 + h_inode = d_inode(a->dst_h_dentry);
23236 + if (h_inode->i_nlink)
23237 + err = au_may_del(a->dst_dentry, a->btgt,
23238 + a->dst_h_parent, isdir);
23242 + if (unlikely(err == -ENOENT || err == -EEXIST))
23248 +/* ---------------------------------------------------------------------- */
23253 + * - src_dir and dir by lock_rename()
23254 + * - inode if exists
23257 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23259 + * + di_write_lock2_child()
23260 + * + di_write_lock_child()
23261 + * + ii_write_lock_child()
23262 + * + di_write_lock_child2()
23263 + * + ii_write_lock_child2()
23264 + * + src_parent and parent
23265 + * + di_write_lock_parent()
23266 + * + ii_write_lock_parent()
23267 + * + di_write_lock_parent2()
23268 + * + ii_write_lock_parent2()
23269 + * + lower src_dir and dir by vfsub_lock_rename()
23270 + * + verify the every relationships between child and parent. if any
23271 + * of them failed, unlock all and return -EBUSY.
23273 +static void au_ren_unlock(struct au_ren_args *a)
23275 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23276 + a->dst_h_parent, a->dst_hdir);
23277 + if (au_ftest_ren(a->auren_flags, DIRREN)
23279 + au_hn_inode_unlock(a->h_root);
23280 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23281 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23284 +static int au_ren_lock(struct au_ren_args *a)
23287 + unsigned int udba;
23290 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23291 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23292 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23293 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23295 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23296 + if (unlikely(err))
23298 + au_fset_ren(a->auren_flags, MNT_WRITE);
23299 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23300 + struct dentry *root;
23301 + struct inode *dir;
23304 + * sbinfo is already locked, so this ii_read_lock is
23305 + * unnecessary. but our debugging feature checks it.
23307 + root = a->src_inode->i_sb->s_root;
23308 + if (root != a->src_parent && root != a->dst_parent) {
23309 + dir = d_inode(root);
23310 + ii_read_lock_parent3(dir);
23311 + a->h_root = au_hi(dir, a->btgt);
23312 + ii_read_unlock(dir);
23313 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23316 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23317 + a->dst_h_parent, a->dst_hdir);
23318 + udba = au_opt_udba(a->src_dentry->d_sb);
23319 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23320 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23321 + err = au_busy_or_stale();
23322 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23323 + err = au_h_verify(a->src_h_dentry, udba,
23324 + d_inode(a->src_h_parent), a->src_h_parent,
23326 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23327 + err = au_h_verify(a->dst_h_dentry, udba,
23328 + d_inode(a->dst_h_parent), a->dst_h_parent,
23331 + goto out; /* success */
23333 + err = au_busy_or_stale();
23334 + au_ren_unlock(a);
23340 +/* ---------------------------------------------------------------------- */
23342 +static void au_ren_refresh_dir(struct au_ren_args *a)
23344 + struct inode *dir;
23346 + dir = a->dst_dir;
23347 + inode_inc_iversion(dir);
23348 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23349 + /* is this updating defined in POSIX? */
23350 + au_cpup_attr_timesizes(a->src_inode);
23351 + au_cpup_attr_nlink(dir, /*force*/1);
23353 + au_dir_ts(dir, a->btgt);
23355 + if (a->exchange) {
23356 + dir = a->src_dir;
23357 + inode_inc_iversion(dir);
23358 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23359 + /* is this updating defined in POSIX? */
23360 + au_cpup_attr_timesizes(a->dst_inode);
23361 + au_cpup_attr_nlink(dir, /*force*/1);
23363 + au_dir_ts(dir, a->btgt);
23366 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23369 + dir = a->src_dir;
23370 + inode_inc_iversion(dir);
23371 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23372 + au_cpup_attr_nlink(dir, /*force*/1);
23373 + au_dir_ts(dir, a->btgt);
23376 +static void au_ren_refresh(struct au_ren_args *a)
23378 + aufs_bindex_t bbot, bindex;
23379 + struct dentry *d, *h_d;
23380 + struct inode *i, *h_i;
23381 + struct super_block *sb;
23383 + d = a->dst_dentry;
23386 + /* already dget-ed by au_ren_or_cpup() */
23387 + au_set_h_dptr(d, a->btgt, a->h_dst);
23389 + i = a->dst_inode;
23391 + if (!a->exchange) {
23392 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23393 + vfsub_drop_nlink(i);
23395 + vfsub_dead_dir(i);
23396 + au_cpup_attr_timesizes(i);
23398 + au_update_dbrange(d, /*do_put_zero*/1);
23400 + au_cpup_attr_nlink(i, /*force*/1);
23403 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23404 + au_set_h_dptr(d, bindex, NULL);
23405 + bbot = au_dbbot(d);
23406 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23407 + au_set_h_dptr(d, bindex, NULL);
23408 + au_update_dbrange(d, /*do_put_zero*/0);
23412 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23413 + d_drop(a->src_dentry);
23414 + if (au_ftest_ren(a->auren_flags, DIRREN))
23415 + au_set_dbwh(a->src_dentry, -1);
23419 + d = a->src_dentry;
23420 + au_set_dbwh(d, -1);
23421 + bbot = au_dbbot(d);
23422 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23423 + h_d = au_h_dptr(d, bindex);
23425 + au_set_h_dptr(d, bindex, NULL);
23427 + au_set_dbbot(d, a->btgt);
23430 + i = a->src_inode;
23431 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23432 + return; /* success */
23434 + bbot = au_ibbot(i);
23435 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23436 + h_i = au_h_iptr(i, bindex);
23438 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23439 + /* ignore this error */
23440 + au_set_h_iptr(i, bindex, NULL, 0);
23443 + au_set_ibbot(i, a->btgt);
23446 +/* ---------------------------------------------------------------------- */
23448 +/* mainly for link(2) and rename(2) */
23449 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23451 + aufs_bindex_t bdiropq, bwh;
23452 + struct dentry *parent;
23453 + struct au_branch *br;
23455 + parent = dentry->d_parent;
23456 + IMustLock(d_inode(parent)); /* dir is locked */
23458 + bdiropq = au_dbdiropq(parent);
23459 + bwh = au_dbwh(dentry);
23460 + br = au_sbr(dentry->d_sb, btgt);
23461 + if (au_br_rdonly(br)
23462 + || (0 <= bdiropq && bdiropq < btgt)
23463 + || (0 <= bwh && bwh < btgt))
23466 + AuDbg("btgt %d\n", btgt);
23470 +/* sets src_btop, dst_btop and btgt */
23471 +static int au_ren_wbr(struct au_ren_args *a)
23474 + struct au_wr_dir_args wr_dir_args = {
23475 + /* .force_btgt = -1, */
23476 + .flags = AuWrDir_ADD_ENTRY
23479 + a->src_btop = au_dbtop(a->src_dentry);
23480 + a->dst_btop = au_dbtop(a->dst_dentry);
23481 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23482 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23483 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23484 + wr_dir_args.force_btgt = a->src_btop;
23485 + if (a->dst_inode && a->dst_btop < a->src_btop)
23486 + wr_dir_args.force_btgt = a->dst_btop;
23487 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23488 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23491 + au_update_dbtop(a->dst_dentry);
23496 +static void au_ren_dt(struct au_ren_args *a)
23498 + a->h_path.dentry = a->src_h_parent;
23499 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23500 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23501 + a->h_path.dentry = a->dst_h_parent;
23502 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23505 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23506 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23510 + a->h_path.dentry = a->src_h_dentry;
23511 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23512 + if (d_is_positive(a->dst_h_dentry)) {
23513 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23514 + a->h_path.dentry = a->dst_h_dentry;
23515 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23519 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23521 + struct dentry *h_d;
23522 + struct inode *h_inode;
23524 + au_dtime_revert(a->src_dt + AuPARENT);
23525 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23526 + au_dtime_revert(a->dst_dt + AuPARENT);
23528 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23529 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23530 + h_inode = d_inode(h_d);
23531 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23532 + au_dtime_revert(a->src_dt + AuCHILD);
23533 + inode_unlock(h_inode);
23535 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23536 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23537 + h_inode = d_inode(h_d);
23538 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23539 + au_dtime_revert(a->dst_dt + AuCHILD);
23540 + inode_unlock(h_inode);
23545 +/* ---------------------------------------------------------------------- */
23547 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23548 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23549 + unsigned int _flags)
23551 + int err, lock_flags;
23553 + /* reduce stack space */
23554 + struct au_ren_args *a;
23555 + struct au_pin pin;
23557 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23558 + IMustLock(_src_dir);
23559 + IMustLock(_dst_dir);
23562 + if (unlikely(_flags & RENAME_WHITEOUT))
23566 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23567 + a = kzalloc(sizeof(*a), GFP_NOFS);
23568 + if (unlikely(!a))
23571 + a->flags = _flags;
23572 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23573 + && RENAME_EXCHANGE > U8_MAX);
23574 + a->exchange = _flags & RENAME_EXCHANGE;
23575 + a->src_dir = _src_dir;
23576 + a->src_dentry = _src_dentry;
23577 + a->src_inode = NULL;
23578 + if (d_really_is_positive(a->src_dentry))
23579 + a->src_inode = d_inode(a->src_dentry);
23580 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23581 + a->dst_dir = _dst_dir;
23582 + a->dst_dentry = _dst_dentry;
23583 + a->dst_inode = NULL;
23584 + if (d_really_is_positive(a->dst_dentry))
23585 + a->dst_inode = d_inode(a->dst_dentry);
23586 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23587 + if (a->dst_inode) {
23589 + * if EXCHANGE && src is non-dir && dst is dir,
23590 + * dst is not locked.
23592 + /* IMustLock(a->dst_inode); */
23593 + au_igrab(a->dst_inode);
23597 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23598 + if (d_is_dir(a->src_dentry)) {
23599 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23600 + if (unlikely(!a->exchange
23601 + && d_really_is_positive(a->dst_dentry)
23602 + && !d_is_dir(a->dst_dentry)))
23604 + lock_flags |= AuLock_DIRS;
23606 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23607 + au_fset_ren(a->auren_flags, ISDIR_DST);
23608 + if (unlikely(!a->exchange
23609 + && d_really_is_positive(a->src_dentry)
23610 + && !d_is_dir(a->src_dentry)))
23612 + lock_flags |= AuLock_DIRS;
23614 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23616 + if (unlikely(err))
23619 + err = au_d_hashed_positive(a->src_dentry);
23620 + if (unlikely(err))
23623 + if (a->dst_inode) {
23625 + * If it is a dir, VFS unhash it before this
23626 + * function. It means we cannot rely upon d_unhashed().
23628 + if (unlikely(!a->dst_inode->i_nlink))
23630 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23631 + err = au_d_hashed_positive(a->dst_dentry);
23632 + if (unlikely(err && !a->exchange))
23634 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23636 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23640 + * is it possible?
23641 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23642 + * there may exist a problem somewhere else.
23645 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23648 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23649 + di_write_lock_parent(a->dst_parent);
23651 + /* which branch we process */
23652 + err = au_ren_wbr(a);
23653 + if (unlikely(err < 0))
23655 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23656 + a->h_path.mnt = au_br_mnt(a->br);
23658 + /* are they available to be renamed */
23659 + err = au_ren_may_dir(a);
23660 + if (unlikely(err))
23661 + goto out_children;
23663 + /* prepare the writable parent dir on the same branch */
23664 + if (a->dst_btop == a->btgt) {
23665 + au_fset_ren(a->auren_flags, WHDST);
23667 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23668 + if (unlikely(err))
23669 + goto out_children;
23673 + if (!a->exchange) {
23674 + if (a->src_dir != a->dst_dir) {
23676 + * this temporary unlock is safe,
23677 + * because both dir->i_mutex are locked.
23679 + di_write_unlock(a->dst_parent);
23680 + di_write_lock_parent(a->src_parent);
23681 + err = au_wr_dir_need_wh(a->src_dentry,
23682 + au_ftest_ren(a->auren_flags,
23685 + di_write_unlock(a->src_parent);
23686 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23688 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23690 + err = au_wr_dir_need_wh(a->src_dentry,
23691 + au_ftest_ren(a->auren_flags,
23695 + if (unlikely(err < 0))
23696 + goto out_children;
23698 + au_fset_ren(a->auren_flags, WHSRC);
23701 + if (a->src_btop != a->btgt) {
23702 + err = au_pin(&pin, a->src_dentry, a->btgt,
23703 + au_opt_udba(a->src_dentry->d_sb),
23704 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23706 + struct au_cp_generic cpg = {
23707 + .dentry = a->src_dentry,
23709 + .bsrc = a->src_btop,
23712 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23714 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23715 + err = au_sio_cpup_simple(&cpg);
23718 + if (unlikely(err))
23719 + goto out_children;
23720 + a->src_btop = a->btgt;
23721 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23722 + if (!a->exchange)
23723 + au_fset_ren(a->auren_flags, WHSRC);
23727 + if (a->exchange && a->dst_inode
23728 + && a->dst_btop != a->btgt) {
23729 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23730 + au_opt_udba(a->dst_dentry->d_sb),
23731 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23733 + struct au_cp_generic cpg = {
23734 + .dentry = a->dst_dentry,
23736 + .bsrc = a->dst_btop,
23739 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23741 + err = au_sio_cpup_simple(&cpg);
23744 + if (unlikely(err))
23745 + goto out_children;
23746 + a->dst_btop = a->btgt;
23747 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23750 + /* lock them all */
23751 + err = au_ren_lock(a);
23752 + if (unlikely(err))
23753 + /* leave the copied-up one */
23754 + goto out_children;
23756 + if (!a->exchange) {
23757 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23758 + err = au_may_ren(a);
23759 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23760 + err = -ENAMETOOLONG;
23761 + if (unlikely(err))
23765 + /* store timestamps to be revertible */
23768 + /* store dirren info */
23769 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23770 + err = au_dr_rename(a->src_dentry, a->btgt,
23771 + &a->dst_dentry->d_name, &rev);
23773 + if (unlikely(err))
23778 + err = do_rename(a);
23779 + if (unlikely(err))
23782 + if (au_ftest_ren(a->auren_flags, DIRREN))
23783 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23785 + /* update dir attributes */
23786 + au_ren_refresh_dir(a);
23788 + /* dput/iput all lower dentries */
23789 + au_ren_refresh(a);
23791 + goto out_hdir; /* success */
23794 + if (au_ftest_ren(a->auren_flags, DIRREN))
23795 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23797 + au_ren_rev_dt(err, a);
23799 + au_ren_unlock(a);
23801 + au_nhash_wh_free(&a->whlist);
23802 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23803 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23804 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23805 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23809 + if (d_unhashed(a->src_dentry))
23810 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23811 + if (d_unhashed(a->dst_dentry))
23812 + au_fset_ren(a->auren_flags, DROPPED_DST);
23813 + if (!a->exchange)
23814 + d_move(a->src_dentry, a->dst_dentry);
23816 + d_exchange(a->src_dentry, a->dst_dentry);
23817 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23818 + d_drop(a->dst_dentry);
23820 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23821 + d_drop(a->src_dentry);
23823 + au_update_dbtop(a->dst_dentry);
23824 + if (!a->dst_inode)
23825 + d_drop(a->dst_dentry);
23827 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23828 + di_write_unlock(a->dst_parent);
23830 + di_write_unlock2(a->src_parent, a->dst_parent);
23832 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23834 + iput(a->dst_inode);
23836 + au_whtmp_rmdir_free(a->thargs);
23842 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23843 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23844 +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200
23846 +# SPDX-License-Identifier: GPL-2.0
23848 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23850 + Aufs is a stackable unification filesystem such as Unionfs,
23851 + which unifies several directories and provides a merged single
23853 + In the early days, aufs was entirely re-designed and
23854 + re-implemented Unionfs Version 1.x series. Introducing many
23855 + original ideas, approaches and improvements, it becomes totally
23856 + different from Unionfs while keeping the basic features.
23860 + prompt "Maximum number of branches"
23861 + default AUFS_BRANCH_MAX_127
23863 + Specifies the maximum number of branches (or member directories)
23864 + in a single aufs. The larger value consumes more system
23865 + resources and has a minor impact to performance.
23866 +config AUFS_BRANCH_MAX_127
23869 + Specifies the maximum number of branches (or member directories)
23870 + in a single aufs. The larger value consumes more system
23871 + resources and has a minor impact to performance.
23872 +config AUFS_BRANCH_MAX_511
23875 + Specifies the maximum number of branches (or member directories)
23876 + in a single aufs. The larger value consumes more system
23877 + resources and has a minor impact to performance.
23878 +config AUFS_BRANCH_MAX_1023
23881 + Specifies the maximum number of branches (or member directories)
23882 + in a single aufs. The larger value consumes more system
23883 + resources and has a minor impact to performance.
23884 +config AUFS_BRANCH_MAX_32767
23887 + Specifies the maximum number of branches (or member directories)
23888 + in a single aufs. The larger value consumes more system
23889 + resources and has a minor impact to performance.
23892 +config AUFS_SBILIST
23894 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23897 + Automatic configuration for internal use.
23898 + When aufs supports Magic SysRq or /proc, enabled automatically.
23900 +config AUFS_HNOTIFY
23901 + bool "Detect direct branch access (bypassing aufs)"
23903 + If you want to modify files on branches directly, eg. bypassing aufs,
23904 + and want aufs to detect the changes of them fully, then enable this
23905 + option and use 'udba=notify' mount option.
23906 + Currently there is only one available configuration, "fsnotify".
23907 + It will have a negative impact to the performance.
23908 + See detail in aufs.5.
23911 + prompt "method" if AUFS_HNOTIFY
23912 + default AUFS_HFSNOTIFY
23913 +config AUFS_HFSNOTIFY
23918 +config AUFS_EXPORT
23919 + bool "NFS-exportable aufs"
23920 + depends on EXPORTFS
23922 + If you want to export your mounted aufs via NFS, then enable this
23923 + option. There are several requirements for this configuration.
23924 + See detail in aufs.5.
23926 +config AUFS_INO_T_64
23928 + depends on AUFS_EXPORT
23929 + depends on 64BIT && !(ALPHA || S390)
23932 + Automatic configuration for internal use.
23933 + /* typedef unsigned long/int __kernel_ino_t */
23934 + /* alpha and s390x are int */
23937 + bool "support for XATTR/EA (including Security Labels)"
23939 + If your branch fs supports XATTR/EA and you want to make them
23940 + available in aufs too, then enable this opsion and specify the
23941 + branch attributes for EA.
23942 + See detail in aufs.5.
23945 + bool "File-based Hierarchical Storage Management"
23947 + Hierarchical Storage Management (or HSM) is a well-known feature
23948 + in the storage world. Aufs provides this feature as file-based.
23949 + with multiple branches.
23950 + These multiple branches are prioritized, ie. the topmost one
23951 + should be the fastest drive and be used heavily.
23954 + bool "Readdir in userspace"
23956 + Aufs has two methods to provide a merged view for a directory,
23957 + by a user-space library and by kernel-space natively. The latter
23958 + is always enabled but sometimes large and slow.
23959 + If you enable this option, install the library in aufs2-util
23960 + package, and set some environment variables for your readdir(3),
23961 + then the work will be handled in user-space which generally
23962 + shows better performance in most cases.
23963 + See detail in aufs.5.
23965 +config AUFS_DIRREN
23966 + bool "Workaround for rename(2)-ing a directory"
23968 + By default, aufs returns EXDEV error in renameing a dir who has
23969 + his child on the lower branch, since it is a bad idea to issue
23970 + rename(2) internally for every lower branch. But user may not
23971 + accept this behaviour. So here is a workaround to allow such
23972 + rename(2) and store some extra infromation on the writable
23973 + branch. Obviously this costs high (and I don't like it).
23974 + To use this feature, you need to enable this configuration AND
23975 + to specify the mount option `dirren.'
23976 + See details in aufs.5 and the design documents.
23979 + bool "Show whiteouts"
23981 + If you want to make the whiteouts in aufs visible, then enable
23982 + this option and specify 'shwh' mount option. Although it may
23983 + sounds like philosophy or something, but in technically it
23984 + simply shows the name of whiteout with keeping its behaviour.
23986 +config AUFS_BR_RAMFS
23987 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23989 + If you want to use ramfs as an aufs branch fs, then enable this
23990 + option. Generally tmpfs is recommended.
23991 + Aufs prohibited them to be a branch fs by default, because
23992 + initramfs becomes unusable after switch_root or something
23993 + generally. If you sets initramfs as an aufs branch and boot your
23994 + system by switch_root, you will meet a problem easily since the
23995 + files in initramfs may be inaccessible.
23996 + Unless you are going to use ramfs as an aufs branch fs without
23997 + switch_root or something, leave it N.
23999 +config AUFS_BR_FUSE
24000 + bool "Fuse fs as an aufs branch"
24001 + depends on FUSE_FS
24004 + If you want to use fuse-based userspace filesystem as an aufs
24005 + branch fs, then enable this option.
24006 + It implements the internal poll(2) operation which is
24007 + implemented by fuse only (curretnly).
24012 + Automatic configuration for internal use.
24014 +config AUFS_BR_HFSPLUS
24015 + bool "Hfsplus as an aufs branch"
24016 + depends on HFSPLUS_FS
24019 + If you want to use hfsplus fs as an aufs branch fs, then enable
24020 + this option. This option introduces a small overhead at
24021 + copying-up a file on hfsplus.
24023 +config AUFS_BDEV_LOOP
24025 + depends on BLK_DEV_LOOP
24028 + Automatic configuration for internal use.
24029 + Convert =[ym] into =y.
24032 + bool "Debug aufs"
24034 + Enable this to compile aufs internal debug code.
24035 + It will have a negative impact to the performance.
24037 +config AUFS_MAGIC_SYSRQ
24039 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24042 + Automatic configuration for internal use.
24043 + When aufs supports Magic SysRq, enabled automatically.
24045 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24046 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
24047 +++ linux/fs/aufs/lcnt.h 2020-01-27 10:57:18.175538316 +0100
24049 +/* SPDX-License-Identifier: GPL-2.0 */
24051 + * Copyright (C) 2018-2020 Junjiro R. Okajima
24053 + * This program, aufs is free software; you can redistribute it and/or modify
24054 + * it under the terms of the GNU General Public License as published by
24055 + * the Free Software Foundation; either version 2 of the License, or
24056 + * (at your option) any later version.
24058 + * This program is distributed in the hope that it will be useful,
24059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24061 + * GNU General Public License for more details.
24063 + * You should have received a copy of the GNU General Public License
24064 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24068 + * simple long counter wrapper
24071 +#ifndef __AUFS_LCNT_H__
24072 +#define __AUFS_LCNT_H__
24076 +#include "debug.h"
24078 +#define AuLCntATOMIC 1
24079 +#define AuLCntPCPUCNT 2
24081 + * why does percpu_refcount require extra synchronize_rcu()s in
24082 + * au_br_do_free()
24084 +#define AuLCntPCPUREF 3
24086 +/* #define AuLCntChosen AuLCntATOMIC */
24087 +#define AuLCntChosen AuLCntPCPUCNT
24088 +/* #define AuLCntChosen AuLCntPCPUREF */
24090 +#if AuLCntChosen == AuLCntATOMIC
24091 +#include <linux/atomic.h>
24093 +typedef atomic_long_t au_lcnt_t;
24095 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24097 + atomic_long_set(cnt, 0);
24101 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24106 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24107 + int do_sync __maybe_unused)
24112 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24114 + atomic_long_inc(cnt);
24117 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24119 + atomic_long_dec(cnt);
24122 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24124 + return atomic_long_read(cnt);
24128 +#if AuLCntChosen == AuLCntPCPUCNT
24129 +#include <linux/percpu_counter.h>
24131 +typedef struct percpu_counter au_lcnt_t;
24133 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24135 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24138 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24143 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24145 + percpu_counter_destroy(cnt);
24148 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24150 + percpu_counter_inc(cnt);
24153 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24155 + percpu_counter_dec(cnt);
24158 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24162 + n = percpu_counter_sum(cnt);
24164 + if (LONG_MAX != LLONG_MAX
24166 + AuWarn1("%s\n", "wrap-around");
24172 +#if AuLCntChosen == AuLCntPCPUREF
24173 +#include <linux/percpu-refcount.h>
24175 +typedef struct percpu_ref au_lcnt_t;
24177 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24180 + release = percpu_ref_exit;
24181 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24184 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24186 + synchronize_rcu();
24189 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24191 + percpu_ref_kill(cnt);
24193 + au_lcnt_wait_for_fin(cnt);
24196 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24198 + percpu_ref_get(cnt);
24201 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24203 + percpu_ref_put(cnt);
24207 + * avoid calling this func as possible.
24209 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24213 + percpu_ref_switch_to_atomic_sync(cnt);
24214 + l = atomic_long_read(&cnt->count);
24216 + percpu_ref_switch_to_percpu(cnt);
24218 + /* percpu_ref is initialized by 1 instead of 0 */
24223 +#ifdef CONFIG_AUFS_DEBUG
24224 +#define AuLCntZero(val) do { \
24227 + AuDbg("%s = %ld\n", #val, l); \
24230 +#define AuLCntZero(val) do {} while (0)
24233 +#endif /* __KERNEL__ */
24234 +#endif /* __AUFS_LCNT_H__ */
24235 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24236 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24237 +++ linux/fs/aufs/loop.c 2020-01-27 10:57:18.175538316 +0100
24239 +// SPDX-License-Identifier: GPL-2.0
24241 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24243 + * This program, aufs is free software; you can redistribute it and/or modify
24244 + * it under the terms of the GNU General Public License as published by
24245 + * the Free Software Foundation; either version 2 of the License, or
24246 + * (at your option) any later version.
24248 + * This program is distributed in the hope that it will be useful,
24249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24251 + * GNU General Public License for more details.
24253 + * You should have received a copy of the GNU General Public License
24254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24258 + * support for loopback block device as a branch
24263 +/* added into drivers/block/loop.c */
24264 +static struct file *(*backing_file_func)(struct super_block *sb);
24267 + * test if two lower dentries have overlapping branches.
24269 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24271 + struct super_block *h_sb;
24272 + struct file *backing_file;
24274 + if (unlikely(!backing_file_func)) {
24275 + /* don't load "loop" module here */
24276 + backing_file_func = symbol_get(loop_backing_file);
24277 + if (unlikely(!backing_file_func))
24278 + /* "loop" module is not loaded */
24282 + h_sb = h_adding->d_sb;
24283 + backing_file = backing_file_func(h_sb);
24284 + if (!backing_file)
24287 + h_adding = backing_file->f_path.dentry;
24289 + * h_adding can be local NFS.
24290 + * in this case aufs cannot detect the loop.
24292 + if (unlikely(h_adding->d_sb == sb))
24294 + return !!au_test_subdir(h_adding, sb->s_root);
24297 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24298 +int au_test_loopback_kthread(void)
24301 + struct task_struct *tsk = current;
24302 + char c, comm[sizeof(tsk->comm)];
24305 + if (tsk->flags & PF_KTHREAD) {
24306 + get_task_comm(comm, tsk);
24308 + ret = ('0' <= c && c <= '9'
24309 + && !strncmp(comm, "loop", 4));
24315 +/* ---------------------------------------------------------------------- */
24317 +#define au_warn_loopback_step 16
24318 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24319 +static unsigned long *au_warn_loopback_array;
24321 +void au_warn_loopback(struct super_block *h_sb)
24323 + int i, new_nelem;
24324 + unsigned long *a, magic;
24325 + static DEFINE_SPINLOCK(spin);
24327 + magic = h_sb->s_magic;
24328 + spin_lock(&spin);
24329 + a = au_warn_loopback_array;
24330 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24331 + if (a[i] == magic) {
24332 + spin_unlock(&spin);
24336 + /* h_sb is new to us, print it */
24337 + if (i < au_warn_loopback_nelem) {
24342 + /* expand the array */
24343 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24344 + a = au_kzrealloc(au_warn_loopback_array,
24345 + au_warn_loopback_nelem * sizeof(unsigned long),
24346 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24347 + /*may_shrink*/0);
24349 + au_warn_loopback_nelem = new_nelem;
24350 + au_warn_loopback_array = a;
24355 + spin_unlock(&spin);
24356 + AuWarn1("realloc failed, ignored\n");
24360 + spin_unlock(&spin);
24361 + pr_warn("you may want to try another patch for loopback file "
24362 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24365 +int au_loopback_init(void)
24368 + struct super_block *sb __maybe_unused;
24370 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24373 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24374 + sizeof(unsigned long), GFP_NOFS);
24375 + if (unlikely(!au_warn_loopback_array))
24381 +void au_loopback_fin(void)
24383 + if (backing_file_func)
24384 + symbol_put(loop_backing_file);
24385 + au_kfree_try_rcu(au_warn_loopback_array);
24387 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24388 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24389 +++ linux/fs/aufs/loop.h 2020-01-27 10:57:18.175538316 +0100
24391 +/* SPDX-License-Identifier: GPL-2.0 */
24393 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24395 + * This program, aufs is free software; you can redistribute it and/or modify
24396 + * it under the terms of the GNU General Public License as published by
24397 + * the Free Software Foundation; either version 2 of the License, or
24398 + * (at your option) any later version.
24400 + * This program is distributed in the hope that it will be useful,
24401 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24402 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24403 + * GNU General Public License for more details.
24405 + * You should have received a copy of the GNU General Public License
24406 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24410 + * support for loopback mount as a branch
24413 +#ifndef __AUFS_LOOP_H__
24414 +#define __AUFS_LOOP_H__
24419 +struct super_block;
24421 +#ifdef CONFIG_AUFS_BDEV_LOOP
24422 +/* drivers/block/loop.c */
24423 +struct file *loop_backing_file(struct super_block *sb);
24426 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24427 +int au_test_loopback_kthread(void);
24428 +void au_warn_loopback(struct super_block *h_sb);
24430 +int au_loopback_init(void);
24431 +void au_loopback_fin(void);
24433 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24435 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24436 + struct dentry *h_adding)
24437 +AuStubInt0(au_test_loopback_kthread, void)
24438 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24440 +AuStubInt0(au_loopback_init, void)
24441 +AuStubVoid(au_loopback_fin, void)
24442 +#endif /* BLK_DEV_LOOP */
24444 +#endif /* __KERNEL__ */
24445 +#endif /* __AUFS_LOOP_H__ */
24446 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24447 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24448 +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200
24450 +# SPDX-License-Identifier: GPL-2.0
24452 +# defined in ${srctree}/fs/fuse/inode.c
24454 +ifdef CONFIG_FUSE_FS
24455 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24458 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24460 +ifdef CONFIG_XFS_FS
24461 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24464 +# defined in ${srctree}/fs/configfs/mount.c
24466 +ifdef CONFIG_CONFIGFS_FS
24467 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24470 +# defined in ${srctree}/fs/ubifs/ubifs.h
24472 +ifdef CONFIG_UBIFS_FS
24473 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24476 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24478 +ifdef CONFIG_HFSPLUS_FS
24479 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24481 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24482 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24483 +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200
24485 +# SPDX-License-Identifier: GPL-2.0
24487 +include ${src}/magic.mk
24488 +ifeq (${CONFIG_AUFS_FS},m)
24489 +include ${src}/conf.mk
24491 +-include ${src}/priv_def.mk
24493 +# cf. include/linux/kernel.h
24495 +ccflags-y += -DDEBUG
24496 +# sparse requires the full pathname
24498 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24500 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24503 +obj-$(CONFIG_AUFS_FS) += aufs.o
24504 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24505 + wkq.o vfsub.o dcsub.o \
24506 + cpup.o whout.o wbr_policy.o \
24507 + dinfo.o dentry.o \
24509 + finfo.o file.o f_op.o \
24511 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24515 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24516 +aufs-$(CONFIG_SYSFS) += sysfs.o
24517 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24518 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24519 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24520 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24521 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24522 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24523 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24524 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24525 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24526 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24527 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24528 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24529 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24530 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24531 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24532 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24533 +++ linux/fs/aufs/module.c 2020-01-27 10:57:18.175538316 +0100
24535 +// SPDX-License-Identifier: GPL-2.0
24537 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24539 + * This program, aufs is free software; you can redistribute it and/or modify
24540 + * it under the terms of the GNU General Public License as published by
24541 + * the Free Software Foundation; either version 2 of the License, or
24542 + * (at your option) any later version.
24544 + * This program is distributed in the hope that it will be useful,
24545 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24546 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24547 + * GNU General Public License for more details.
24549 + * You should have received a copy of the GNU General Public License
24550 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24554 + * module global variables and operations
24557 +#include <linux/module.h>
24558 +#include <linux/seq_file.h>
24561 +/* shrinkable realloc */
24562 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24570 +#if 0 /* unused */
24577 + AuDebugOn(!new_sz);
24580 + diff = au_kmidx_sub(sz, new_sz);
24586 + /* expand or SLOB */
24587 + p = krealloc(p, new_sz, gfp);
24588 + else if (new_sz < sz && may_shrink) {
24592 + q = kmalloc(new_sz, gfp);
24595 + memcpy(q, p, new_sz);
24596 + au_kfree_try_rcu(p);
24607 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24610 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24611 + if (p && new_sz > nused)
24612 + memset(p + nused, 0, new_sz - nused);
24616 +/* ---------------------------------------------------------------------- */
24620 +struct kmem_cache *au_cache[AuCache_Last];
24622 +static void au_cache_fin(void)
24627 + * Make sure all delayed rcu free inodes are flushed before we
24632 + /* excluding AuCache_HNOTIFY */
24633 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24634 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24635 + kmem_cache_destroy(au_cache[i]);
24636 + au_cache[i] = NULL;
24640 +static int __init au_cache_init(void)
24642 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24643 + if (au_cache[AuCache_DINFO])
24644 + /* SLAB_DESTROY_BY_RCU */
24645 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24646 + au_icntnr_init_once);
24647 + if (au_cache[AuCache_ICNTNR])
24648 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24649 + au_fi_init_once);
24650 + if (au_cache[AuCache_FINFO])
24651 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24652 + if (au_cache[AuCache_VDIR])
24653 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24654 + if (au_cache[AuCache_DEHSTR])
24661 +/* ---------------------------------------------------------------------- */
24663 +int au_dir_roflags;
24665 +#ifdef CONFIG_AUFS_SBILIST
24667 + * iterate_supers_type() doesn't protect us from
24668 + * remounting (branch management)
24670 +struct hlist_bl_head au_sbilist;
24674 + * functions for module interface.
24676 +MODULE_LICENSE("GPL");
24677 +/* MODULE_LICENSE("GPL v2"); */
24678 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24679 +MODULE_DESCRIPTION(AUFS_NAME
24680 + " -- Advanced multi layered unification filesystem");
24681 +MODULE_VERSION(AUFS_VERSION);
24682 +MODULE_ALIAS_FS(AUFS_NAME);
24684 +/* this module parameter has no meaning when SYSFS is disabled */
24685 +int sysaufs_brs = 1;
24686 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24687 +module_param_named(brs, sysaufs_brs, int, 0444);
24689 +/* this module parameter has no meaning when USER_NS is disabled */
24691 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24692 +module_param_named(allow_userns, au_userns, bool, 0444);
24694 +/* ---------------------------------------------------------------------- */
24696 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24698 +int au_seq_path(struct seq_file *seq, struct path *path)
24702 + err = seq_path(seq, path, au_esc_chars);
24711 +/* ---------------------------------------------------------------------- */
24713 +static int __init aufs_init(void)
24718 + p = au_esc_chars;
24719 + for (i = 1; i <= ' '; i++)
24725 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24727 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24728 + for (i = 0; i < AuIop_Last; i++)
24729 + aufs_iop_nogetattr[i].getattr = NULL;
24731 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24733 + au_sbilist_init();
24734 + sysaufs_brs_init();
24737 + err = sysaufs_init();
24738 + if (unlikely(err))
24740 + err = dbgaufs_init();
24741 + if (unlikely(err))
24742 + goto out_sysaufs;
24743 + err = au_procfs_init();
24744 + if (unlikely(err))
24745 + goto out_dbgaufs;
24746 + err = au_wkq_init();
24747 + if (unlikely(err))
24749 + err = au_loopback_init();
24750 + if (unlikely(err))
24752 + err = au_hnotify_init();
24753 + if (unlikely(err))
24754 + goto out_loopback;
24755 + err = au_sysrq_init();
24756 + if (unlikely(err))
24758 + err = au_cache_init();
24759 + if (unlikely(err))
24762 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24763 + err = register_filesystem(&aufs_fs_type);
24764 + if (unlikely(err))
24767 + /* since we define pr_fmt, call printk directly */
24768 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24769 + goto out; /* success */
24776 + au_hnotify_fin();
24778 + au_loopback_fin();
24792 +static void __exit aufs_exit(void)
24794 + unregister_filesystem(&aufs_fs_type);
24797 + au_hnotify_fin();
24798 + au_loopback_fin();
24806 +module_init(aufs_init);
24807 +module_exit(aufs_exit);
24808 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24809 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24810 +++ linux/fs/aufs/module.h 2020-01-27 10:57:18.175538316 +0100
24812 +/* SPDX-License-Identifier: GPL-2.0 */
24814 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24816 + * This program, aufs is free software; you can redistribute it and/or modify
24817 + * it under the terms of the GNU General Public License as published by
24818 + * the Free Software Foundation; either version 2 of the License, or
24819 + * (at your option) any later version.
24821 + * This program is distributed in the hope that it will be useful,
24822 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24823 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24824 + * GNU General Public License for more details.
24826 + * You should have received a copy of the GNU General Public License
24827 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24831 + * module initialization and module-global
24834 +#ifndef __AUFS_MODULE_H__
24835 +#define __AUFS_MODULE_H__
24839 +#include <linux/slab.h>
24840 +#include "debug.h"
24841 +#include "dentry.h"
24844 +#include "inode.h"
24849 +/* module parameters */
24850 +extern int sysaufs_brs;
24851 +extern bool au_userns;
24853 +/* ---------------------------------------------------------------------- */
24855 +extern int au_dir_roflags;
24857 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24858 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24862 + * Comparing the size of the object with sizeof(struct rcu_head)
24863 + * case 1: object is always larger
24864 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24865 + * case 2: object is always smaller
24866 + * --> au_kfree_small()
24867 + * case 3: object can be any size
24868 + * --> au_kfree_try_rcu()
24871 +static inline void au_kfree_do_rcu(const void *p)
24874 + struct rcu_head rcu;
24875 + } *a = (void *)p;
24877 + kfree_rcu(a, rcu);
24880 +#define au_kfree_rcu(_p) do { \
24881 + typeof(_p) p = (_p); \
24882 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24884 + au_kfree_do_rcu(p); \
24887 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24888 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24890 +static inline void au_kfree_try_rcu(const void *p)
24894 + if (au_kfree_sz_test(p))
24895 + au_kfree_do_rcu(p);
24900 +static inline void au_kfree_small(const void *p)
24904 + AuDebugOn(au_kfree_sz_test(p));
24908 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24910 +#ifndef CONFIG_SLOB
24911 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24913 + return -1; /* SLOB is untested */
24917 +int au_seq_path(struct seq_file *seq, struct path *path);
24919 +#ifdef CONFIG_PROC_FS
24921 +int __init au_procfs_init(void);
24922 +void au_procfs_fin(void);
24924 +AuStubInt0(au_procfs_init, void);
24925 +AuStubVoid(au_procfs_fin, void);
24928 +/* ---------------------------------------------------------------------- */
24937 + AuCache_HNOTIFY, /* must be last */
24941 +extern struct kmem_cache *au_cache[AuCache_Last];
24943 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24944 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24945 +#define AuCacheCtor(type, ctor) \
24946 + kmem_cache_create(#type, sizeof(struct type), \
24947 + __alignof__(struct type), AuCacheFlags, ctor)
24949 +#define AuCacheFuncs(name, index) \
24950 + static inline struct au_##name *au_cache_alloc_##name(void) \
24951 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24952 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24953 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24955 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24956 + { void *p = rcu; \
24957 + p -= offsetof(struct au_##name, rcu); \
24958 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24959 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24960 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24961 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24963 + static inline void au_cache_free_##name(struct au_##name *p) \
24964 + { /* au_cache_free_##name##_norcu(p); */ \
24965 + au_cache_free_##name##_rcu(p); }
24967 +AuCacheFuncs(dinfo, DINFO);
24968 +AuCacheFuncs(icntnr, ICNTNR);
24969 +AuCacheFuncs(finfo, FINFO);
24970 +AuCacheFuncs(vdir, VDIR);
24971 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24972 +#ifdef CONFIG_AUFS_HNOTIFY
24973 +AuCacheFuncs(hnotify, HNOTIFY);
24976 +#endif /* __KERNEL__ */
24977 +#endif /* __AUFS_MODULE_H__ */
24978 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24979 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24980 +++ linux/fs/aufs/mvdown.c 2020-01-27 10:57:18.175538316 +0100
24982 +// SPDX-License-Identifier: GPL-2.0
24984 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24986 + * This program, aufs is free software; you can redistribute it and/or modify
24987 + * it under the terms of the GNU General Public License as published by
24988 + * the Free Software Foundation; either version 2 of the License, or
24989 + * (at your option) any later version.
24991 + * This program is distributed in the hope that it will be useful,
24992 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24993 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24994 + * GNU General Public License for more details.
24996 + * You should have received a copy of the GNU General Public License
24997 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25001 + * move-down, opposite of copy-up
25006 +struct au_mvd_args {
25008 + struct super_block *h_sb;
25009 + struct dentry *h_parent;
25010 + struct au_hinode *hdir;
25011 + struct inode *h_dir, *h_inode;
25012 + struct au_pin pin;
25013 + } info[AUFS_MVDOWN_NARRAY];
25015 + struct aufs_mvdown mvdown;
25016 + struct dentry *dentry, *parent;
25017 + struct inode *inode, *dir;
25018 + struct super_block *sb;
25019 + aufs_bindex_t bopq, bwh, bfound;
25020 + unsigned char rename_lock;
25023 +#define mvd_errno mvdown.au_errno
25024 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25025 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25026 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25027 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25029 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25030 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25031 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25032 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25033 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25034 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25036 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25037 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25038 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25039 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25040 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25041 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25043 +#define AU_MVD_PR(flag, ...) do { \
25045 + pr_err(__VA_ARGS__); \
25048 +static int find_lower_writable(struct au_mvd_args *a)
25050 + struct super_block *sb;
25051 + aufs_bindex_t bindex, bbot;
25052 + struct au_branch *br;
25055 + bindex = a->mvd_bsrc;
25056 + bbot = au_sbbot(sb);
25057 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25058 + for (bindex++; bindex <= bbot; bindex++) {
25059 + br = au_sbr(sb, bindex);
25060 + if (au_br_fhsm(br->br_perm)
25061 + && !sb_rdonly(au_br_sb(br)))
25064 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25065 + for (bindex++; bindex <= bbot; bindex++) {
25066 + br = au_sbr(sb, bindex);
25067 + if (!au_br_rdonly(br))
25071 + for (bindex++; bindex <= bbot; bindex++) {
25072 + br = au_sbr(sb, bindex);
25073 + if (!sb_rdonly(au_br_sb(br))) {
25074 + if (au_br_rdonly(br))
25076 + |= AUFS_MVDOWN_ROLOWER_R;
25084 +/* make the parent dir on bdst */
25085 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25090 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25091 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25092 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25093 + a->mvd_h_dst_parent = NULL;
25094 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25095 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25096 + if (!a->mvd_h_dst_parent) {
25097 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25098 + if (unlikely(err)) {
25099 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25102 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25110 +/* lock them all */
25111 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25114 + struct dentry *h_trap;
25116 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25117 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25118 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25119 + au_opt_udba(a->sb),
25120 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25122 + if (unlikely(err)) {
25123 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25127 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25128 + a->rename_lock = 0;
25129 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25130 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25131 + au_opt_udba(a->sb),
25132 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25133 + err = au_do_pin(&a->mvd_pin_src);
25135 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25136 + if (unlikely(err)) {
25137 + AU_MVD_PR(dmsg, "pin_src failed\n");
25140 + goto out; /* success */
25143 + a->rename_lock = 1;
25144 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25145 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25146 + au_opt_udba(a->sb),
25147 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25149 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25150 + if (unlikely(err)) {
25151 + AU_MVD_PR(dmsg, "pin_src failed\n");
25152 + au_pin_hdir_lock(&a->mvd_pin_dst);
25155 + au_pin_hdir_unlock(&a->mvd_pin_src);
25156 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25157 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25159 + err = (h_trap != a->mvd_h_src_parent);
25161 + err = (h_trap != a->mvd_h_dst_parent);
25163 + BUG_ON(err); /* it should never happen */
25164 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25167 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25168 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25169 + au_pin_hdir_lock(&a->mvd_pin_src);
25170 + au_unpin(&a->mvd_pin_src);
25171 + au_pin_hdir_lock(&a->mvd_pin_dst);
25174 + goto out; /* success */
25177 + au_unpin(&a->mvd_pin_dst);
25183 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25185 + if (!a->rename_lock)
25186 + au_unpin(&a->mvd_pin_src);
25188 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25189 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25190 + au_pin_hdir_lock(&a->mvd_pin_src);
25191 + au_unpin(&a->mvd_pin_src);
25192 + au_pin_hdir_lock(&a->mvd_pin_dst);
25194 + au_unpin(&a->mvd_pin_dst);
25197 +/* copy-down the file */
25198 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25201 + struct au_cp_generic cpg = {
25202 + .dentry = a->dentry,
25203 + .bdst = a->mvd_bdst,
25204 + .bsrc = a->mvd_bsrc,
25206 + .pin = &a->mvd_pin_dst,
25207 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25210 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25211 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25212 + au_fset_cpup(cpg.flags, OVERWRITE);
25213 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25214 + au_fset_cpup(cpg.flags, RWDST);
25215 + err = au_sio_cpdown_simple(&cpg);
25216 + if (unlikely(err))
25217 + AU_MVD_PR(dmsg, "cpdown failed\n");
25224 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25227 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25230 + struct path h_path;
25231 + struct au_branch *br;
25232 + struct inode *delegated;
25234 + br = au_sbr(a->sb, a->mvd_bdst);
25235 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25236 + err = PTR_ERR(h_path.dentry);
25237 + if (IS_ERR(h_path.dentry)) {
25238 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25243 + if (d_is_positive(h_path.dentry)) {
25244 + h_path.mnt = au_br_mnt(br);
25245 + delegated = NULL;
25246 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25247 + &delegated, /*force*/0);
25248 + if (unlikely(err == -EWOULDBLOCK)) {
25249 + pr_warn("cannot retry for NFSv4 delegation"
25250 + " for an internal unlink\n");
25253 + if (unlikely(err))
25254 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25256 + dput(h_path.dentry);
25264 + * unlink the topmost h_dentry
25266 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25269 + struct path h_path;
25270 + struct inode *delegated;
25272 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25273 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25274 + delegated = NULL;
25275 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25276 + if (unlikely(err == -EWOULDBLOCK)) {
25277 + pr_warn("cannot retry for NFSv4 delegation"
25278 + " for an internal unlink\n");
25281 + if (unlikely(err))
25282 + AU_MVD_PR(dmsg, "unlink failed\n");
25288 +/* Since mvdown succeeded, we ignore an error of this function */
25289 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25292 + struct au_branch *br;
25294 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25295 + br = au_sbr(a->sb, a->mvd_bsrc);
25296 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25298 + br = au_sbr(a->sb, a->mvd_bdst);
25299 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25300 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25303 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25305 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25309 + * copy-down the file and unlink the bsrc file.
25310 + * - unlink the bdst whout if exist
25311 + * - copy-down the file (with whtmp name and rename)
25312 + * - unlink the bsrc file
25314 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25318 + err = au_do_mkdir(dmsg, a);
25320 + err = au_do_lock(dmsg, a);
25321 + if (unlikely(err))
25325 + * do not revert the activities we made on bdst since they should be
25326 + * harmless in aufs.
25329 + err = au_do_cpdown(dmsg, a);
25331 + err = au_do_unlink_wh(dmsg, a);
25332 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25333 + err = au_do_unlink(dmsg, a);
25334 + if (unlikely(err))
25337 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25338 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25339 + if (find_lower_writable(a) < 0)
25340 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25342 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25343 + au_do_stfs(dmsg, a);
25345 + /* maintain internal array */
25346 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25347 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25348 + au_set_dbtop(a->dentry, a->mvd_bdst);
25349 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25350 + au_set_ibtop(a->inode, a->mvd_bdst);
25352 + /* hide the lower */
25353 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25354 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25355 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25356 + au_set_ibbot(a->inode, a->mvd_bsrc);
25358 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25359 + au_set_dbbot(a->dentry, a->mvd_bdst);
25360 + if (au_ibbot(a->inode) < a->mvd_bdst)
25361 + au_set_ibbot(a->inode, a->mvd_bdst);
25364 + au_do_unlock(dmsg, a);
25370 +/* ---------------------------------------------------------------------- */
25372 +/* make sure the file is idle */
25373 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25375 + int err, plinked;
25378 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25379 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25380 + && au_dcount(a->dentry) == 1
25381 + && atomic_read(&a->inode->i_count) == 1
25382 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25383 + && (!plinked || !au_plink_test(a->inode))
25384 + && a->inode->i_nlink == 1)
25389 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25390 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25391 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25392 + a->mvd_h_src_inode->i_nlink,
25393 + plinked, plinked ? au_plink_test(a->inode) : 0);
25400 +/* make sure the parent dir is fine */
25401 +static int au_mvd_args_parent(const unsigned char dmsg,
25402 + struct au_mvd_args *a)
25405 + aufs_bindex_t bindex;
25408 + if (unlikely(au_alive_dir(a->parent))) {
25410 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25414 + a->bopq = au_dbdiropq(a->parent);
25415 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25416 + AuDbg("b%d\n", bindex);
25417 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25418 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25420 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25421 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25422 + a->bopq, a->mvd_bdst);
25430 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25431 + struct au_mvd_args *a)
25434 + struct au_dinfo *dinfo, *tmp;
25436 + /* lookup the next lower positive entry */
25438 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25439 + if (unlikely(!tmp))
25444 + dinfo = au_di(a->dentry);
25445 + au_di_cp(tmp, dinfo);
25446 + au_di_swap(tmp, dinfo);
25448 + /* returns the number of positive dentries */
25449 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25450 + /* AuLkup_IGNORE_PERM */ 0);
25452 + a->bwh = au_dbwh(a->dentry);
25453 + else if (err > 0)
25454 + a->bfound = au_dbtop(a->dentry);
25456 + au_di_swap(tmp, dinfo);
25457 + au_rw_write_unlock(&tmp->di_rwsem);
25459 + if (unlikely(err < 0))
25460 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25463 + * here, we have these cases.
25465 + * no positive dentry under bsrc. there are more sub-cases.
25467 + * there no whiteout, we can safely move-down.
25470 + * bsrc < bwh && bwh < bdst
25471 + * there is a whiteout on RO branch. cannot proceed.
25473 + * there is a whiteout on the RW target branch. it should
25476 + * there is a whiteout somewhere unrelated branch.
25477 + * -1 < bfound && bfound <= bsrc
25480 + * found, but it is on RO branch between bsrc and bdst. cannot
25483 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25486 + * found, after we create the file on bdst, it will be hidden.
25489 + AuDebugOn(a->bfound == -1
25491 + && a->bwh <= a->mvd_bsrc);
25492 + AuDebugOn(-1 < a->bfound
25493 + && a->bfound <= a->mvd_bsrc);
25496 + if (a->bfound == -1
25497 + && a->mvd_bsrc < a->bwh
25499 + && a->bwh < a->mvd_bdst) {
25500 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25501 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25502 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25504 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25505 + a->mvd_errno = EAU_MVDOWN_UPPER;
25506 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25507 + a->mvd_bdst, a->bfound);
25511 + err = 0; /* success */
25518 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25523 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25524 + && a->bfound == a->mvd_bdst)
25530 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25533 + struct au_branch *br;
25536 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25540 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25541 + a->mvd_bsrc = au_ibtop(a->inode);
25543 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25544 + if (unlikely(a->mvd_bsrc < 0
25545 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25546 + || au_dbbot(a->dentry) < a->mvd_bsrc
25547 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25548 + || (a->mvd_bsrc < au_ibtop(a->inode)
25549 + || au_ibbot(a->inode) < a->mvd_bsrc
25550 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25551 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25552 + AU_MVD_PR(dmsg, "no upper\n");
25556 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25557 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25558 + AU_MVD_PR(dmsg, "on the bottom\n");
25561 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25562 + br = au_sbr(a->sb, a->mvd_bsrc);
25563 + err = au_br_rdonly(br);
25564 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25565 + if (unlikely(err))
25567 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25568 + || IS_APPEND(a->mvd_h_src_inode))) {
25570 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25576 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25577 + a->mvd_bdst = find_lower_writable(a);
25578 + if (unlikely(a->mvd_bdst < 0)) {
25579 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25580 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25584 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25585 + if (unlikely(a->mvd_bdst < 0
25586 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25587 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25588 + AU_MVD_PR(dmsg, "no lower brid\n");
25593 + err = au_mvd_args_busy(dmsg, a);
25595 + err = au_mvd_args_parent(dmsg, a);
25597 + err = au_mvd_args_intermediate(dmsg, a);
25599 + err = au_mvd_args_exist(dmsg, a);
25601 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25608 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25611 + unsigned char dmsg;
25612 + struct au_mvd_args *args;
25613 + struct inode *inode;
25615 + inode = d_inode(dentry);
25617 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25621 + args = kmalloc(sizeof(*args), GFP_NOFS);
25622 + if (unlikely(!args))
25625 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25627 + /* VERIFY_WRITE */
25628 + err = !access_ok(uarg, sizeof(*uarg));
25629 + if (unlikely(err)) {
25634 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25635 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25636 + args->mvdown.au_errno = 0;
25637 + args->dentry = dentry;
25638 + args->inode = inode;
25639 + args->sb = dentry->d_sb;
25642 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25643 + args->parent = dget_parent(dentry);
25644 + args->dir = d_inode(args->parent);
25645 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25646 + dput(args->parent);
25647 + if (unlikely(args->parent != dentry->d_parent)) {
25648 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25652 + inode_lock_nested(inode, I_MUTEX_CHILD);
25653 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25654 + if (unlikely(err))
25657 + di_write_lock_parent(args->parent);
25658 + err = au_mvd_args(dmsg, args);
25659 + if (unlikely(err))
25662 + err = au_do_mvdown(dmsg, args);
25663 + if (unlikely(err))
25666 + au_cpup_attr_timesizes(args->dir);
25667 + au_cpup_attr_timesizes(inode);
25668 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25669 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25670 + /* au_digen_dec(dentry); */
25673 + di_write_unlock(args->parent);
25674 + aufs_read_unlock(dentry, AuLock_DW);
25676 + inode_unlock(inode);
25678 + inode_unlock(args->dir);
25680 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25683 + au_kfree_rcu(args);
25688 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25689 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25690 +++ linux/fs/aufs/opts.c 2020-01-27 10:57:18.175538316 +0100
25692 +// SPDX-License-Identifier: GPL-2.0
25694 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25696 + * This program, aufs is free software; you can redistribute it and/or modify
25697 + * it under the terms of the GNU General Public License as published by
25698 + * the Free Software Foundation; either version 2 of the License, or
25699 + * (at your option) any later version.
25701 + * This program is distributed in the hope that it will be useful,
25702 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25703 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25704 + * GNU General Public License for more details.
25706 + * You should have received a copy of the GNU General Public License
25707 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25711 + * mount options/flags
25714 +#include <linux/namei.h>
25715 +#include <linux/types.h> /* a distribution requires */
25716 +#include <linux/parser.h>
25719 +/* ---------------------------------------------------------------------- */
25723 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25724 + Opt_idel, Opt_imod,
25725 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25726 + Opt_rdblk_def, Opt_rdhash_def,
25727 + Opt_xino, Opt_noxino,
25728 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25729 + Opt_trunc_xino_path, Opt_itrunc_xino,
25730 + Opt_trunc_xib, Opt_notrunc_xib,
25731 + Opt_shwh, Opt_noshwh,
25732 + Opt_plink, Opt_noplink, Opt_list_plink,
25734 + Opt_dio, Opt_nodio,
25735 + Opt_diropq_a, Opt_diropq_w,
25736 + Opt_warn_perm, Opt_nowarn_perm,
25737 + Opt_wbr_copyup, Opt_wbr_create,
25739 + Opt_verbose, Opt_noverbose,
25740 + Opt_sum, Opt_nosum, Opt_wsum,
25741 + Opt_dirperm1, Opt_nodirperm1,
25742 + Opt_dirren, Opt_nodirren,
25743 + Opt_acl, Opt_noacl,
25744 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25747 +static match_table_t options = {
25748 + {Opt_br, "br=%s"},
25749 + {Opt_br, "br:%s"},
25751 + {Opt_add, "add=%d:%s"},
25752 + {Opt_add, "add:%d:%s"},
25753 + {Opt_add, "ins=%d:%s"},
25754 + {Opt_add, "ins:%d:%s"},
25755 + {Opt_append, "append=%s"},
25756 + {Opt_append, "append:%s"},
25757 + {Opt_prepend, "prepend=%s"},
25758 + {Opt_prepend, "prepend:%s"},
25760 + {Opt_del, "del=%s"},
25761 + {Opt_del, "del:%s"},
25762 + /* {Opt_idel, "idel:%d"}, */
25763 + {Opt_mod, "mod=%s"},
25764 + {Opt_mod, "mod:%s"},
25765 + /* {Opt_imod, "imod:%d:%s"}, */
25767 + {Opt_dirwh, "dirwh=%d"},
25769 + {Opt_xino, "xino=%s"},
25770 + {Opt_noxino, "noxino"},
25771 + {Opt_trunc_xino, "trunc_xino"},
25772 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25773 + {Opt_notrunc_xino, "notrunc_xino"},
25774 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25775 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25776 + /* {Opt_zxino, "zxino=%s"}, */
25777 + {Opt_trunc_xib, "trunc_xib"},
25778 + {Opt_notrunc_xib, "notrunc_xib"},
25780 +#ifdef CONFIG_PROC_FS
25781 + {Opt_plink, "plink"},
25783 + {Opt_ignore_silent, "plink"},
25786 + {Opt_noplink, "noplink"},
25788 +#ifdef CONFIG_AUFS_DEBUG
25789 + {Opt_list_plink, "list_plink"},
25792 + {Opt_udba, "udba=%s"},
25794 + {Opt_dio, "dio"},
25795 + {Opt_nodio, "nodio"},
25797 +#ifdef CONFIG_AUFS_DIRREN
25798 + {Opt_dirren, "dirren"},
25799 + {Opt_nodirren, "nodirren"},
25801 + {Opt_ignore, "dirren"},
25802 + {Opt_ignore_silent, "nodirren"},
25805 +#ifdef CONFIG_AUFS_FHSM
25806 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25808 + {Opt_ignore, "fhsm_sec=%d"},
25811 + {Opt_diropq_a, "diropq=always"},
25812 + {Opt_diropq_a, "diropq=a"},
25813 + {Opt_diropq_w, "diropq=whiteouted"},
25814 + {Opt_diropq_w, "diropq=w"},
25816 + {Opt_warn_perm, "warn_perm"},
25817 + {Opt_nowarn_perm, "nowarn_perm"},
25819 + /* keep them temporary */
25820 + {Opt_ignore_silent, "nodlgt"},
25821 + {Opt_ignore, "clean_plink"},
25823 +#ifdef CONFIG_AUFS_SHWH
25824 + {Opt_shwh, "shwh"},
25826 + {Opt_noshwh, "noshwh"},
25828 + {Opt_dirperm1, "dirperm1"},
25829 + {Opt_nodirperm1, "nodirperm1"},
25831 + {Opt_verbose, "verbose"},
25832 + {Opt_verbose, "v"},
25833 + {Opt_noverbose, "noverbose"},
25834 + {Opt_noverbose, "quiet"},
25835 + {Opt_noverbose, "q"},
25836 + {Opt_noverbose, "silent"},
25838 + {Opt_sum, "sum"},
25839 + {Opt_nosum, "nosum"},
25840 + {Opt_wsum, "wsum"},
25842 + {Opt_rdcache, "rdcache=%d"},
25843 + {Opt_rdblk, "rdblk=%d"},
25844 + {Opt_rdblk_def, "rdblk=def"},
25845 + {Opt_rdhash, "rdhash=%d"},
25846 + {Opt_rdhash_def, "rdhash=def"},
25848 + {Opt_wbr_create, "create=%s"},
25849 + {Opt_wbr_create, "create_policy=%s"},
25850 + {Opt_wbr_copyup, "cpup=%s"},
25851 + {Opt_wbr_copyup, "copyup=%s"},
25852 + {Opt_wbr_copyup, "copyup_policy=%s"},
25854 + /* generic VFS flag */
25855 +#ifdef CONFIG_FS_POSIX_ACL
25856 + {Opt_acl, "acl"},
25857 + {Opt_noacl, "noacl"},
25859 + {Opt_ignore, "acl"},
25860 + {Opt_ignore_silent, "noacl"},
25863 + /* internal use for the scripts */
25864 + {Opt_ignore_silent, "si=%s"},
25866 + {Opt_br, "dirs=%s"},
25867 + {Opt_ignore, "debug=%d"},
25868 + {Opt_ignore, "delete=whiteout"},
25869 + {Opt_ignore, "delete=all"},
25870 + {Opt_ignore, "imap=%s"},
25872 + /* temporary workaround, due to old mount(8)? */
25873 + {Opt_ignore_silent, "relatime"},
25878 +/* ---------------------------------------------------------------------- */
25880 +static const char *au_parser_pattern(int val, match_table_t tbl)
25882 + struct match_token *p;
25885 + while (p->pattern) {
25886 + if (p->token == val)
25887 + return p->pattern;
25894 +static const char *au_optstr(int *val, match_table_t tbl)
25896 + struct match_token *p;
25903 + while (p->pattern) {
25905 + && (v & p->token) == p->token) {
25906 + *val &= ~p->token;
25907 + return p->pattern;
25916 +/* ---------------------------------------------------------------------- */
25918 +static match_table_t brperm = {
25919 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25920 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25921 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25925 +static match_table_t brattr = {
25927 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25928 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25929 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25930 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25931 +#ifdef CONFIG_AUFS_FHSM
25932 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25934 +#ifdef CONFIG_AUFS_XATTR
25935 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25936 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25937 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25938 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25939 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25940 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25943 + /* ro/rr branch */
25944 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25947 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25948 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25953 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25960 + p = strchr(str, '+');
25963 + v = match_token(str, table, args);
25965 + if (v & AuBrAttr_CMOO_Mask)
25966 + attr &= ~AuBrAttr_CMOO_Mask;
25971 + pr_warn("ignored branch attribute %s\n", str);
25981 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25989 + p = au_optstr(&perm, brattr);
25992 + memcpy(q, p, sz + 1);
25998 + p = au_optstr(&perm, brattr);
26002 + memcpy(q, p, sz + 1);
26008 + return q - str->a;
26011 +static int noinline_for_stack br_perm_val(char *perm)
26013 + int val, bad, sz;
26015 + substring_t args[MAX_OPT_ARGS];
26016 + au_br_perm_str_t attr;
26018 + p = strchr(perm, '+');
26021 + val = match_token(perm, brperm, args);
26025 + pr_warn("ignored branch permission %s\n", perm);
26026 + val = AuBrPerm_RO;
26032 + val |= br_attr_val(p + 1, brattr, args);
26035 + switch (val & AuBrPerm_Mask) {
26036 + case AuBrPerm_RO:
26037 + case AuBrPerm_RR:
26038 + bad = val & AuBrWAttr_Mask;
26039 + val &= ~AuBrWAttr_Mask;
26041 + case AuBrPerm_RW:
26042 + bad = val & AuBrRAttr_Mask;
26043 + val &= ~AuBrRAttr_Mask;
26048 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26049 + * does not treat it as an error, just warning.
26050 + * this is a tiny guard for the user operation.
26052 + if (val & AuBrAttr_UNPIN) {
26053 + bad |= AuBrAttr_UNPIN;
26054 + val &= ~AuBrAttr_UNPIN;
26057 + if (unlikely(bad)) {
26058 + sz = au_do_optstr_br_attr(&attr, bad);
26060 + pr_warn("ignored branch attribute %s\n", attr.a);
26067 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26069 + au_br_perm_str_t attr;
26075 + p = au_optstr(&perm, brperm);
26076 + AuDebugOn(!p || !*p);
26078 + memcpy(q, p, sz + 1);
26081 + sz = au_do_optstr_br_attr(&attr, perm);
26084 + memcpy(q, attr.a, sz + 1);
26087 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26090 +/* ---------------------------------------------------------------------- */
26092 +static match_table_t udbalevel = {
26093 + {AuOpt_UDBA_REVAL, "reval"},
26094 + {AuOpt_UDBA_NONE, "none"},
26095 +#ifdef CONFIG_AUFS_HNOTIFY
26096 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26097 +#ifdef CONFIG_AUFS_HFSNOTIFY
26098 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26104 +static int noinline_for_stack udba_val(char *str)
26106 + substring_t args[MAX_OPT_ARGS];
26108 + return match_token(str, udbalevel, args);
26111 +const char *au_optstr_udba(int udba)
26113 + return au_parser_pattern(udba, udbalevel);
26116 +/* ---------------------------------------------------------------------- */
26118 +static match_table_t au_wbr_create_policy = {
26119 + {AuWbrCreate_TDP, "tdp"},
26120 + {AuWbrCreate_TDP, "top-down-parent"},
26121 + {AuWbrCreate_RR, "rr"},
26122 + {AuWbrCreate_RR, "round-robin"},
26123 + {AuWbrCreate_MFS, "mfs"},
26124 + {AuWbrCreate_MFS, "most-free-space"},
26125 + {AuWbrCreate_MFSV, "mfs:%d"},
26126 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26128 + /* top-down regardless the parent, and then mfs */
26129 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26130 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26132 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26133 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26134 + {AuWbrCreate_PMFS, "pmfs"},
26135 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26136 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26137 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26142 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26143 + struct au_opt_wbr_create *create)
26146 + unsigned long long ull;
26149 + if (!match_u64(arg, &ull))
26150 + create->mfsrr_watermark = ull;
26152 + pr_err("bad integer in %s\n", str);
26159 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26160 + struct au_opt_wbr_create *create)
26165 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26166 + create->mfs_second = n;
26168 + pr_err("bad integer in %s\n", str);
26175 +static int noinline_for_stack
26176 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26179 + substring_t args[MAX_OPT_ARGS];
26181 + err = match_token(str, au_wbr_create_policy, args);
26182 + create->wbr_create = err;
26184 + case AuWbrCreate_MFSRRV:
26185 + case AuWbrCreate_TDMFSV:
26186 + case AuWbrCreate_PMFSRRV:
26187 + e = au_wbr_mfs_wmark(&args[0], str, create);
26189 + e = au_wbr_mfs_sec(&args[1], str, create);
26193 + case AuWbrCreate_MFSRR:
26194 + case AuWbrCreate_TDMFS:
26195 + case AuWbrCreate_PMFSRR:
26196 + e = au_wbr_mfs_wmark(&args[0], str, create);
26197 + if (unlikely(e)) {
26202 + case AuWbrCreate_MFS:
26203 + case AuWbrCreate_PMFS:
26204 + create->mfs_second = AUFS_MFS_DEF_SEC;
26206 + case AuWbrCreate_MFSV:
26207 + case AuWbrCreate_PMFSV:
26208 + e = au_wbr_mfs_sec(&args[0], str, create);
26217 +const char *au_optstr_wbr_create(int wbr_create)
26219 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26222 +static match_table_t au_wbr_copyup_policy = {
26223 + {AuWbrCopyup_TDP, "tdp"},
26224 + {AuWbrCopyup_TDP, "top-down-parent"},
26225 + {AuWbrCopyup_BUP, "bup"},
26226 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26227 + {AuWbrCopyup_BU, "bu"},
26228 + {AuWbrCopyup_BU, "bottom-up"},
26232 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26234 + substring_t args[MAX_OPT_ARGS];
26236 + return match_token(str, au_wbr_copyup_policy, args);
26239 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26241 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26244 +/* ---------------------------------------------------------------------- */
26246 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26248 +static void dump_opts(struct au_opts *opts)
26250 +#ifdef CONFIG_AUFS_DEBUG
26251 + /* reduce stack space */
26253 + struct au_opt_add *add;
26254 + struct au_opt_del *del;
26255 + struct au_opt_mod *mod;
26256 + struct au_opt_xino *xino;
26257 + struct au_opt_xino_itrunc *xino_itrunc;
26258 + struct au_opt_wbr_create *create;
26260 + struct au_opt *opt;
26263 + while (opt->type != Opt_tail) {
26264 + switch (opt->type) {
26266 + u.add = &opt->add;
26267 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26268 + u.add->bindex, u.add->pathname, u.add->perm,
26269 + u.add->path.dentry);
26273 + u.del = &opt->del;
26274 + AuDbg("del {%s, %p}\n",
26275 + u.del->pathname, u.del->h_path.dentry);
26279 + u.mod = &opt->mod;
26280 + AuDbg("mod {%s, 0x%x, %p}\n",
26281 + u.mod->path, u.mod->perm, u.mod->h_root);
26284 + u.add = &opt->add;
26285 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26286 + u.add->bindex, u.add->pathname, u.add->perm,
26287 + u.add->path.dentry);
26289 + case Opt_prepend:
26290 + u.add = &opt->add;
26291 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26292 + u.add->bindex, u.add->pathname, u.add->perm,
26293 + u.add->path.dentry);
26296 + AuDbg("dirwh %d\n", opt->dirwh);
26298 + case Opt_rdcache:
26299 + AuDbg("rdcache %d\n", opt->rdcache);
26302 + AuDbg("rdblk %u\n", opt->rdblk);
26304 + case Opt_rdblk_def:
26305 + AuDbg("rdblk_def\n");
26308 + AuDbg("rdhash %u\n", opt->rdhash);
26310 + case Opt_rdhash_def:
26311 + AuDbg("rdhash_def\n");
26314 + u.xino = &opt->xino;
26315 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26317 + case Opt_trunc_xino:
26318 + AuLabel(trunc_xino);
26320 + case Opt_notrunc_xino:
26321 + AuLabel(notrunc_xino);
26323 + case Opt_trunc_xino_path:
26324 + case Opt_itrunc_xino:
26325 + u.xino_itrunc = &opt->xino_itrunc;
26326 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26331 + case Opt_trunc_xib:
26332 + AuLabel(trunc_xib);
26334 + case Opt_notrunc_xib:
26335 + AuLabel(notrunc_xib);
26343 + case Opt_dirperm1:
26344 + AuLabel(dirperm1);
26346 + case Opt_nodirperm1:
26347 + AuLabel(nodirperm1);
26352 + case Opt_noplink:
26353 + AuLabel(noplink);
26355 + case Opt_list_plink:
26356 + AuLabel(list_plink);
26359 + AuDbg("udba %d, %s\n",
26360 + opt->udba, au_optstr_udba(opt->udba));
26368 + case Opt_diropq_a:
26369 + AuLabel(diropq_a);
26371 + case Opt_diropq_w:
26372 + AuLabel(diropq_w);
26374 + case Opt_warn_perm:
26375 + AuLabel(warn_perm);
26377 + case Opt_nowarn_perm:
26378 + AuLabel(nowarn_perm);
26380 + case Opt_verbose:
26381 + AuLabel(verbose);
26383 + case Opt_noverbose:
26384 + AuLabel(noverbose);
26395 + case Opt_wbr_create:
26396 + u.create = &opt->wbr_create;
26397 + AuDbg("create %d, %s\n", u.create->wbr_create,
26398 + au_optstr_wbr_create(u.create->wbr_create));
26399 + switch (u.create->wbr_create) {
26400 + case AuWbrCreate_MFSV:
26401 + case AuWbrCreate_PMFSV:
26402 + AuDbg("%d sec\n", u.create->mfs_second);
26404 + case AuWbrCreate_MFSRR:
26405 + case AuWbrCreate_TDMFS:
26406 + AuDbg("%llu watermark\n",
26407 + u.create->mfsrr_watermark);
26409 + case AuWbrCreate_MFSRRV:
26410 + case AuWbrCreate_TDMFSV:
26411 + case AuWbrCreate_PMFSRRV:
26412 + AuDbg("%llu watermark, %d sec\n",
26413 + u.create->mfsrr_watermark,
26414 + u.create->mfs_second);
26418 + case Opt_wbr_copyup:
26419 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26420 + au_optstr_wbr_copyup(opt->wbr_copyup));
26422 + case Opt_fhsm_sec:
26423 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26428 + case Opt_nodirren:
26429 + AuLabel(nodirren);
26445 +void au_opts_free(struct au_opts *opts)
26447 + struct au_opt *opt;
26450 + while (opt->type != Opt_tail) {
26451 + switch (opt->type) {
26454 + case Opt_prepend:
26455 + path_put(&opt->add.path);
26459 + path_put(&opt->del.h_path);
26463 + dput(opt->mod.h_root);
26466 + fput(opt->xino.file);
26473 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26474 + aufs_bindex_t bindex)
26477 + struct au_opt_add *add = &opt->add;
26480 + add->bindex = bindex;
26481 + add->perm = AuBrPerm_RO;
26482 + add->pathname = opt_str;
26483 + p = strchr(opt_str, '=');
26487 + add->perm = br_perm_val(p);
26490 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26493 + add->perm = AuBrPerm_RO;
26494 + if (au_test_fs_rr(add->path.dentry->d_sb))
26495 + add->perm = AuBrPerm_RR;
26496 + else if (!bindex && !(sb_flags & SB_RDONLY))
26497 + add->perm = AuBrPerm_RW;
26499 + opt->type = Opt_add;
26502 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26509 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26513 + del->pathname = args[0].from;
26514 + AuDbg("del path %s\n", del->pathname);
26516 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26517 + if (unlikely(err))
26518 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26523 +#if 0 /* reserved for future use */
26524 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26525 + struct au_opt_del *del, substring_t args[])
26528 + struct dentry *root;
26531 + root = sb->s_root;
26532 + aufs_read_lock(root, AuLock_FLUSH);
26533 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26534 + pr_err("out of bounds, %d\n", bindex);
26539 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26540 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26543 + aufs_read_unlock(root, !AuLock_IR);
26548 +static int noinline_for_stack
26549 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26552 + struct path path;
26556 + mod->path = args[0].from;
26557 + p = strchr(mod->path, '=');
26558 + if (unlikely(!p)) {
26559 + pr_err("no permission %s\n", args[0].from);
26564 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26565 + if (unlikely(err)) {
26566 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26570 + mod->perm = br_perm_val(p);
26571 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26572 + mod->h_root = dget(path.dentry);
26579 +#if 0 /* reserved for future use */
26580 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26581 + struct au_opt_mod *mod, substring_t args[])
26584 + struct dentry *root;
26587 + root = sb->s_root;
26588 + aufs_read_lock(root, AuLock_FLUSH);
26589 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26590 + pr_err("out of bounds, %d\n", bindex);
26595 + mod->perm = br_perm_val(args[1].from);
26596 + AuDbg("mod path %s, perm 0x%x, %s\n",
26597 + mod->path, mod->perm, args[1].from);
26598 + mod->h_root = dget(au_h_dptr(root, bindex));
26601 + aufs_read_unlock(root, !AuLock_IR);
26606 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26607 + substring_t args[])
26610 + struct file *file;
26612 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26613 + err = PTR_ERR(file);
26614 + if (IS_ERR(file))
26618 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26620 + pr_err("%s must be outside\n", args[0].from);
26625 + xino->file = file;
26626 + xino->path = args[0].from;
26632 +static int noinline_for_stack
26633 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26634 + struct au_opt_xino_itrunc *xino_itrunc,
26635 + substring_t args[])
26638 + aufs_bindex_t bbot, bindex;
26639 + struct path path;
26640 + struct dentry *root;
26642 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26643 + if (unlikely(err)) {
26644 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26648 + xino_itrunc->bindex = -1;
26649 + root = sb->s_root;
26650 + aufs_read_lock(root, AuLock_FLUSH);
26651 + bbot = au_sbbot(sb);
26652 + for (bindex = 0; bindex <= bbot; bindex++) {
26653 + if (au_h_dptr(root, bindex) == path.dentry) {
26654 + xino_itrunc->bindex = bindex;
26658 + aufs_read_unlock(root, !AuLock_IR);
26661 + if (unlikely(xino_itrunc->bindex < 0)) {
26662 + pr_err("no such branch %s\n", args[0].from);
26670 +/* called without aufs lock */
26671 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26673 + int err, n, token;
26674 + aufs_bindex_t bindex;
26675 + unsigned char skipped;
26676 + struct dentry *root;
26677 + struct au_opt *opt, *opt_tail;
26679 + /* reduce the stack space */
26681 + struct au_opt_xino_itrunc *xino_itrunc;
26682 + struct au_opt_wbr_create *create;
26685 + substring_t args[MAX_OPT_ARGS];
26689 + a = kmalloc(sizeof(*a), GFP_NOFS);
26690 + if (unlikely(!a))
26693 + root = sb->s_root;
26697 + opt_tail = opt + opts->max_opt - 1;
26698 + opt->type = Opt_tail;
26699 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26702 + token = match_token(opt_str, options, a->args);
26706 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26708 + err = opt_add(opt, opt_str, opts->sb_flags,
26710 + if (unlikely(!err && ++opt > opt_tail)) {
26714 + opt->type = Opt_tail;
26719 + if (unlikely(match_int(&a->args[0], &n))) {
26720 + pr_err("bad integer in %s\n", opt_str);
26724 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26727 + opt->type = token;
26730 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26731 + /*dummy bindex*/1);
26733 + opt->type = token;
26735 + case Opt_prepend:
26736 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26739 + opt->type = token;
26742 + err = au_opts_parse_del(&opt->del, a->args);
26744 + opt->type = token;
26746 +#if 0 /* reserved for future use */
26748 + del->pathname = "(indexed)";
26749 + if (unlikely(match_int(&args[0], &n))) {
26750 + pr_err("bad integer in %s\n", opt_str);
26753 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26755 + opt->type = token;
26759 + err = au_opts_parse_mod(&opt->mod, a->args);
26761 + opt->type = token;
26763 +#ifdef IMOD /* reserved for future use */
26765 + u.mod->path = "(indexed)";
26766 + if (unlikely(match_int(&a->args[0], &n))) {
26767 + pr_err("bad integer in %s\n", opt_str);
26770 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26772 + opt->type = token;
26776 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26778 + opt->type = token;
26781 + case Opt_trunc_xino_path:
26782 + err = au_opts_parse_xino_itrunc_path
26783 + (sb, &opt->xino_itrunc, a->args);
26785 + opt->type = token;
26788 + case Opt_itrunc_xino:
26789 + u.xino_itrunc = &opt->xino_itrunc;
26790 + if (unlikely(match_int(&a->args[0], &n))) {
26791 + pr_err("bad integer in %s\n", opt_str);
26794 + u.xino_itrunc->bindex = n;
26795 + aufs_read_lock(root, AuLock_FLUSH);
26796 + if (n < 0 || au_sbbot(sb) < n) {
26797 + pr_err("out of bounds, %d\n", n);
26798 + aufs_read_unlock(root, !AuLock_IR);
26801 + aufs_read_unlock(root, !AuLock_IR);
26803 + opt->type = token;
26807 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26810 + opt->type = token;
26813 + case Opt_rdcache:
26814 + if (unlikely(match_int(&a->args[0], &n))) {
26815 + pr_err("bad integer in %s\n", opt_str);
26818 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26819 + pr_err("rdcache must be smaller than %d\n",
26820 + AUFS_RDCACHE_MAX);
26823 + opt->rdcache = n;
26825 + opt->type = token;
26828 + if (unlikely(match_int(&a->args[0], &n)
26830 + || n > KMALLOC_MAX_SIZE)) {
26831 + pr_err("bad integer in %s\n", opt_str);
26834 + if (unlikely(n && n < NAME_MAX)) {
26835 + pr_err("rdblk must be larger than %d\n",
26841 + opt->type = token;
26844 + if (unlikely(match_int(&a->args[0], &n)
26846 + || n * sizeof(struct hlist_head)
26847 + > KMALLOC_MAX_SIZE)) {
26848 + pr_err("bad integer in %s\n", opt_str);
26853 + opt->type = token;
26856 + case Opt_trunc_xino:
26857 + case Opt_notrunc_xino:
26859 + case Opt_trunc_xib:
26860 + case Opt_notrunc_xib:
26863 + case Opt_dirperm1:
26864 + case Opt_nodirperm1:
26866 + case Opt_noplink:
26867 + case Opt_list_plink:
26870 + case Opt_diropq_a:
26871 + case Opt_diropq_w:
26872 + case Opt_warn_perm:
26873 + case Opt_nowarn_perm:
26874 + case Opt_verbose:
26875 + case Opt_noverbose:
26879 + case Opt_rdblk_def:
26880 + case Opt_rdhash_def:
26882 + case Opt_nodirren:
26886 + opt->type = token;
26890 + opt->udba = udba_val(a->args[0].from);
26891 + if (opt->udba >= 0) {
26893 + opt->type = token;
26895 + pr_err("wrong value, %s\n", opt_str);
26898 + case Opt_wbr_create:
26899 + u.create = &opt->wbr_create;
26900 + u.create->wbr_create
26901 + = au_wbr_create_val(a->args[0].from, u.create);
26902 + if (u.create->wbr_create >= 0) {
26904 + opt->type = token;
26906 + pr_err("wrong value, %s\n", opt_str);
26908 + case Opt_wbr_copyup:
26909 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26910 + if (opt->wbr_copyup >= 0) {
26912 + opt->type = token;
26914 + pr_err("wrong value, %s\n", opt_str);
26917 + case Opt_fhsm_sec:
26918 + if (unlikely(match_int(&a->args[0], &n)
26920 + pr_err("bad integer in %s\n", opt_str);
26923 + if (sysaufs_brs) {
26924 + opt->fhsm_second = n;
26925 + opt->type = token;
26927 + pr_warn("ignored %s\n", opt_str);
26932 + pr_warn("ignored %s\n", opt_str);
26934 + case Opt_ignore_silent:
26939 + pr_err("unknown option %s\n", opt_str);
26943 + if (!err && !skipped) {
26944 + if (unlikely(++opt > opt_tail)) {
26947 + opt->type = Opt_tail;
26950 + opt->type = Opt_tail;
26956 + if (unlikely(err))
26957 + au_opts_free(opts);
26963 +static int au_opt_wbr_create(struct super_block *sb,
26964 + struct au_opt_wbr_create *create)
26967 + struct au_sbinfo *sbinfo;
26969 + SiMustWriteLock(sb);
26971 + err = 1; /* handled */
26972 + sbinfo = au_sbi(sb);
26973 + if (sbinfo->si_wbr_create_ops->fin) {
26974 + err = sbinfo->si_wbr_create_ops->fin(sb);
26979 + sbinfo->si_wbr_create = create->wbr_create;
26980 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26981 + switch (create->wbr_create) {
26982 + case AuWbrCreate_MFSRRV:
26983 + case AuWbrCreate_MFSRR:
26984 + case AuWbrCreate_TDMFS:
26985 + case AuWbrCreate_TDMFSV:
26986 + case AuWbrCreate_PMFSRR:
26987 + case AuWbrCreate_PMFSRRV:
26988 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26990 + case AuWbrCreate_MFS:
26991 + case AuWbrCreate_MFSV:
26992 + case AuWbrCreate_PMFS:
26993 + case AuWbrCreate_PMFSV:
26994 + sbinfo->si_wbr_mfs.mfs_expire
26995 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26999 + if (sbinfo->si_wbr_create_ops->init)
27000 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27007 + * plus: processed without an error
27008 + * zero: unprocessed
27010 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27011 + struct au_opts *opts)
27014 + struct au_sbinfo *sbinfo;
27016 + SiMustWriteLock(sb);
27018 + err = 1; /* handled */
27019 + sbinfo = au_sbi(sb);
27020 + switch (opt->type) {
27022 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27023 + sbinfo->si_mntflags |= opt->udba;
27024 + opts->given_udba |= opt->udba;
27028 + au_opt_set(sbinfo->si_mntflags, PLINK);
27030 + case Opt_noplink:
27031 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27032 + au_plink_put(sb, /*verbose*/1);
27033 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27035 + case Opt_list_plink:
27036 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27037 + au_plink_list(sb);
27041 + au_opt_set(sbinfo->si_mntflags, DIO);
27042 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27045 + au_opt_clr(sbinfo->si_mntflags, DIO);
27046 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27049 + case Opt_fhsm_sec:
27050 + au_fhsm_set(sbinfo, opt->fhsm_second);
27053 + case Opt_diropq_a:
27054 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27056 + case Opt_diropq_w:
27057 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27060 + case Opt_warn_perm:
27061 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27063 + case Opt_nowarn_perm:
27064 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27067 + case Opt_verbose:
27068 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27070 + case Opt_noverbose:
27071 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27075 + au_opt_set(sbinfo->si_mntflags, SUM);
27078 + au_opt_clr(sbinfo->si_mntflags, SUM);
27079 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27082 + au_opt_clr(sbinfo->si_mntflags, SUM);
27083 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27086 + case Opt_wbr_create:
27087 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27089 + case Opt_wbr_copyup:
27090 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27091 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27095 + sbinfo->si_dirwh = opt->dirwh;
27098 + case Opt_rdcache:
27099 + sbinfo->si_rdcache
27100 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27103 + sbinfo->si_rdblk = opt->rdblk;
27105 + case Opt_rdblk_def:
27106 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27109 + sbinfo->si_rdhash = opt->rdhash;
27111 + case Opt_rdhash_def:
27112 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27116 + au_opt_set(sbinfo->si_mntflags, SHWH);
27119 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27122 + case Opt_dirperm1:
27123 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27125 + case Opt_nodirperm1:
27126 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27129 + case Opt_trunc_xino:
27130 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27132 + case Opt_notrunc_xino:
27133 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27136 + case Opt_trunc_xino_path:
27137 + case Opt_itrunc_xino:
27138 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27144 + case Opt_trunc_xib:
27145 + au_fset_opts(opts->flags, TRUNC_XIB);
27147 + case Opt_notrunc_xib:
27148 + au_fclr_opts(opts->flags, TRUNC_XIB);
27153 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27154 + err = au_dr_opt_set(sb);
27159 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27161 + case Opt_nodirren:
27163 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27164 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27170 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27174 + sb->s_flags |= SB_POSIXACL;
27177 + sb->s_flags &= ~SB_POSIXACL;
27189 + * returns tri-state.
27190 + * plus: processed without an error
27191 + * zero: unprocessed
27194 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27195 + struct au_opts *opts)
27197 + int err, do_refresh;
27200 + switch (opt->type) {
27202 + opt->add.bindex = au_sbbot(sb) + 1;
27203 + if (opt->add.bindex < 0)
27204 + opt->add.bindex = 0;
27206 + /* Always goto add, not fallthrough */
27207 + case Opt_prepend:
27208 + opt->add.bindex = 0;
27209 + /* fallthrough */
27210 + add: /* indented label */
27212 + err = au_br_add(sb, &opt->add,
27213 + au_ftest_opts(opts->flags, REMOUNT));
27216 + au_fset_opts(opts->flags, REFRESH);
27222 + err = au_br_del(sb, &opt->del,
27223 + au_ftest_opts(opts->flags, REMOUNT));
27226 + au_fset_opts(opts->flags, TRUNC_XIB);
27227 + au_fset_opts(opts->flags, REFRESH);
27233 + err = au_br_mod(sb, &opt->mod,
27234 + au_ftest_opts(opts->flags, REMOUNT),
27239 + au_fset_opts(opts->flags, REFRESH);
27246 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27247 + struct au_opt_xino **opt_xino,
27248 + struct au_opts *opts)
27253 + switch (opt->type) {
27255 + err = au_xino_set(sb, &opt->xino,
27256 + !!au_ftest_opts(opts->flags, REMOUNT));
27257 + if (unlikely(err))
27260 + *opt_xino = &opt->xino;
27265 + *opt_xino = (void *)-1;
27272 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27273 + unsigned int pending)
27276 + aufs_bindex_t bindex, bbot;
27277 + unsigned char do_plink, skip, do_free, can_no_dreval;
27278 + struct au_branch *br;
27279 + struct au_wbr *wbr;
27280 + struct dentry *root, *dentry;
27281 + struct inode *dir, *h_dir;
27282 + struct au_sbinfo *sbinfo;
27283 + struct au_hinode *hdir;
27285 + SiMustAnyLock(sb);
27287 + sbinfo = au_sbi(sb);
27288 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27290 + if (!(sb_flags & SB_RDONLY)) {
27291 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27292 + pr_warn("first branch should be rw\n");
27293 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27294 + pr_warn_once("shwh should be used with ro\n");
27297 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27298 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27299 + pr_warn_once("udba=*notify requires xino\n");
27301 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27302 + pr_warn_once("dirperm1 breaks the protection"
27303 + " by the permission bits on the lower branch\n");
27307 + root = sb->s_root;
27308 + dir = d_inode(root);
27309 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27310 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27312 + bbot = au_sbbot(sb);
27313 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27315 + h_dir = au_h_iptr(dir, bindex);
27316 + br = au_sbr(sb, bindex);
27318 + if ((br->br_perm & AuBrAttr_ICEX)
27319 + && !h_dir->i_op->listxattr)
27320 + br->br_perm &= ~AuBrAttr_ICEX;
27321 +#if 0 /* untested */
27322 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27323 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27324 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27328 + wbr = br->br_wbr;
27330 + wbr_wh_read_lock(wbr);
27332 + if (!au_br_writable(br->br_perm)) {
27335 + || (!wbr->wbr_whbase
27336 + && !wbr->wbr_plink
27337 + && !wbr->wbr_orph));
27338 + } else if (!au_br_wh_linkable(br->br_perm)) {
27339 + /* skip = (!br->br_whbase && !br->br_orph); */
27340 + skip = (!wbr || !wbr->wbr_whbase);
27341 + if (skip && wbr) {
27343 + skip = !!wbr->wbr_plink;
27345 + skip = !wbr->wbr_plink;
27348 + /* skip = (br->br_whbase && br->br_ohph); */
27349 + skip = (wbr && wbr->wbr_whbase);
27352 + skip = !!wbr->wbr_plink;
27354 + skip = !wbr->wbr_plink;
27358 + wbr_wh_read_unlock(wbr);
27360 + if (can_no_dreval) {
27361 + dentry = br->br_path.dentry;
27362 + spin_lock(&dentry->d_lock);
27363 + if (dentry->d_flags &
27364 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27365 + can_no_dreval = 0;
27366 + spin_unlock(&dentry->d_lock);
27369 + if (au_br_fhsm(br->br_perm)) {
27371 + AuDebugOn(!br->br_fhsm);
27377 + hdir = au_hi(dir, bindex);
27378 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27380 + wbr_wh_write_lock(wbr);
27381 + err = au_wh_init(br, sb);
27383 + wbr_wh_write_unlock(wbr);
27384 + au_hn_inode_unlock(hdir);
27386 + if (!err && do_free) {
27387 + au_kfree_rcu(wbr);
27388 + br->br_wbr = NULL;
27392 + if (can_no_dreval)
27393 + au_fset_si(sbinfo, NO_DREVAL);
27395 + au_fclr_si(sbinfo, NO_DREVAL);
27398 + au_fset_si(sbinfo, FHSM);
27399 + for (bindex = bbot; bindex >= 0; bindex--) {
27400 + br = au_sbr(sb, bindex);
27401 + if (au_br_fhsm(br->br_perm)) {
27402 + au_fhsm_set_bottom(sb, bindex);
27407 + au_fclr_si(sbinfo, FHSM);
27408 + au_fhsm_set_bottom(sb, -1);
27414 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27417 + unsigned int tmp;
27418 + aufs_bindex_t bindex, bbot;
27419 + struct au_opt *opt;
27420 + struct au_opt_xino *opt_xino, xino;
27421 + struct au_sbinfo *sbinfo;
27422 + struct au_branch *br;
27423 + struct inode *dir;
27425 + SiMustWriteLock(sb);
27430 + while (err >= 0 && opt->type != Opt_tail)
27431 + err = au_opt_simple(sb, opt++, opts);
27434 + else if (unlikely(err < 0))
27437 + /* disable xino and udba temporary */
27438 + sbinfo = au_sbi(sb);
27439 + tmp = sbinfo->si_mntflags;
27440 + au_opt_clr(sbinfo->si_mntflags, XINO);
27441 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27444 + while (err >= 0 && opt->type != Opt_tail)
27445 + err = au_opt_br(sb, opt++, opts);
27448 + else if (unlikely(err < 0))
27451 + bbot = au_sbbot(sb);
27452 + if (unlikely(bbot < 0)) {
27454 + pr_err("no branches\n");
27458 + if (au_opt_test(tmp, XINO))
27459 + au_opt_set(sbinfo->si_mntflags, XINO);
27461 + while (!err && opt->type != Opt_tail)
27462 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27463 + if (unlikely(err))
27466 + err = au_opts_verify(sb, sb->s_flags, tmp);
27467 + if (unlikely(err))
27470 + /* restore xino */
27471 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27472 + xino.file = au_xino_def(sb);
27473 + err = PTR_ERR(xino.file);
27474 + if (IS_ERR(xino.file))
27477 + err = au_xino_set(sb, &xino, /*remount*/0);
27479 + if (unlikely(err))
27483 + /* restore udba */
27484 + tmp &= AuOptMask_UDBA;
27485 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27486 + sbinfo->si_mntflags |= tmp;
27487 + bbot = au_sbbot(sb);
27488 + for (bindex = 0; bindex <= bbot; bindex++) {
27489 + br = au_sbr(sb, bindex);
27490 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27491 + if (unlikely(err))
27492 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27494 + /* go on even if err */
27496 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27497 + dir = d_inode(sb->s_root);
27498 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27505 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27508 + unsigned char no_dreval;
27509 + struct inode *dir;
27510 + struct au_opt_xino *opt_xino;
27511 + struct au_opt *opt;
27512 + struct au_sbinfo *sbinfo;
27514 + SiMustWriteLock(sb);
27516 + err = au_dr_opt_flush(sb);
27517 + if (unlikely(err))
27519 + au_fset_opts(opts->flags, DR_FLUSHED);
27521 + dir = d_inode(sb->s_root);
27522 + sbinfo = au_sbi(sb);
27525 + while (err >= 0 && opt->type != Opt_tail) {
27526 + err = au_opt_simple(sb, opt, opts);
27528 + err = au_opt_br(sb, opt, opts);
27530 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27536 + /* go on even err */
27538 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27539 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27540 + if (unlikely(rerr && !err))
27543 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27544 + au_fset_opts(opts->flags, REFRESH_IDOP);
27546 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27547 + rerr = au_xib_trunc(sb);
27548 + if (unlikely(rerr && !err))
27552 + /* will be handled by the caller */
27553 + if (!au_ftest_opts(opts->flags, REFRESH)
27554 + && (opts->given_udba
27555 + || au_opt_test(sbinfo->si_mntflags, XINO)
27556 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27558 + au_fset_opts(opts->flags, REFRESH);
27560 + AuDbg("status 0x%x\n", opts->flags);
27566 +/* ---------------------------------------------------------------------- */
27568 +unsigned int au_opt_udba(struct super_block *sb)
27570 + return au_mntflags(sb) & AuOptMask_UDBA;
27572 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27573 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27574 +++ linux/fs/aufs/opts.h 2020-01-27 10:57:18.175538316 +0100
27576 +/* SPDX-License-Identifier: GPL-2.0 */
27578 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27580 + * This program, aufs is free software; you can redistribute it and/or modify
27581 + * it under the terms of the GNU General Public License as published by
27582 + * the Free Software Foundation; either version 2 of the License, or
27583 + * (at your option) any later version.
27585 + * This program is distributed in the hope that it will be useful,
27586 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27587 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27588 + * GNU General Public License for more details.
27590 + * You should have received a copy of the GNU General Public License
27591 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27595 + * mount options/flags
27598 +#ifndef __AUFS_OPTS_H__
27599 +#define __AUFS_OPTS_H__
27603 +#include <linux/path.h>
27607 +/* ---------------------------------------------------------------------- */
27610 +#define AuOpt_XINO 1 /* external inode number bitmap
27611 + and translation table */
27612 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27613 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27614 +#define AuOpt_UDBA_REVAL (1 << 3)
27615 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27616 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27617 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27618 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27620 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27621 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27622 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27623 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27624 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27625 +#define AuOpt_DIO (1 << 14) /* direct io */
27626 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27628 +#ifndef CONFIG_AUFS_HNOTIFY
27629 +#undef AuOpt_UDBA_HNOTIFY
27630 +#define AuOpt_UDBA_HNOTIFY 0
27632 +#ifndef CONFIG_AUFS_DIRREN
27633 +#undef AuOpt_DIRREN
27634 +#define AuOpt_DIRREN 0
27636 +#ifndef CONFIG_AUFS_SHWH
27638 +#define AuOpt_SHWH 0
27641 +#define AuOpt_Def (AuOpt_XINO \
27642 + | AuOpt_UDBA_REVAL \
27644 + /* | AuOpt_DIRPERM1 */ \
27645 + | AuOpt_WARN_PERM)
27646 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27647 + | AuOpt_UDBA_REVAL \
27648 + | AuOpt_UDBA_HNOTIFY)
27650 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27651 +#define au_opt_set(flags, name) do { \
27652 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27653 + ((flags) |= AuOpt_##name); \
27655 +#define au_opt_set_udba(flags, name) do { \
27656 + (flags) &= ~AuOptMask_UDBA; \
27657 + ((flags) |= AuOpt_##name); \
27659 +#define au_opt_clr(flags, name) do { \
27660 + ((flags) &= ~AuOpt_##name); \
27663 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27665 +#ifdef CONFIG_PROC_FS
27668 + return mntflags & ~AuOpt_PLINK;
27672 +/* ---------------------------------------------------------------------- */
27674 +/* policies to select one among multiple writable branches */
27676 + AuWbrCreate_TDP, /* top down parent */
27677 + AuWbrCreate_RR, /* round robin */
27678 + AuWbrCreate_MFS, /* most free space */
27679 + AuWbrCreate_MFSV, /* mfs with seconds */
27680 + AuWbrCreate_MFSRR, /* mfs then rr */
27681 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27682 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27683 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27684 + AuWbrCreate_PMFS, /* parent and mfs */
27685 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27686 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27687 + AuWbrCreate_PMFSRRV, /* plus seconds */
27689 + AuWbrCreate_Def = AuWbrCreate_TDP
27693 + AuWbrCopyup_TDP, /* top down parent */
27694 + AuWbrCopyup_BUP, /* bottom up parent */
27695 + AuWbrCopyup_BU, /* bottom up */
27697 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27700 +/* ---------------------------------------------------------------------- */
27702 +struct au_opt_add {
27703 + aufs_bindex_t bindex;
27706 + struct path path;
27709 +struct au_opt_del {
27711 + struct path h_path;
27714 +struct au_opt_mod {
27717 + struct dentry *h_root;
27720 +struct au_opt_xino {
27722 + struct file *file;
27725 +struct au_opt_xino_itrunc {
27726 + aufs_bindex_t bindex;
27729 +struct au_opt_wbr_create {
27732 + unsigned long long mfsrr_watermark;
27738 + struct au_opt_xino xino;
27739 + struct au_opt_xino_itrunc xino_itrunc;
27740 + struct au_opt_add add;
27741 + struct au_opt_del del;
27742 + struct au_opt_mod mod;
27745 + unsigned int rdblk;
27746 + unsigned int rdhash;
27748 + struct au_opt_wbr_create wbr_create;
27750 + unsigned int fhsm_second;
27755 +#define AuOpts_REMOUNT 1
27756 +#define AuOpts_REFRESH (1 << 1)
27757 +#define AuOpts_TRUNC_XIB (1 << 2)
27758 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27759 +#define AuOpts_REFRESH_IDOP (1 << 4)
27760 +#define AuOpts_DR_FLUSHED (1 << 5)
27761 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27762 +#define au_fset_opts(flags, name) \
27763 + do { (flags) |= AuOpts_##name; } while (0)
27764 +#define au_fclr_opts(flags, name) \
27765 + do { (flags) &= ~AuOpts_##name; } while (0)
27767 +#ifndef CONFIG_AUFS_DIRREN
27768 +#undef AuOpts_DR_FLUSHED
27769 +#define AuOpts_DR_FLUSHED 0
27773 + struct au_opt *opt;
27776 + unsigned int given_udba;
27777 + unsigned int flags;
27778 + unsigned long sb_flags;
27781 +/* ---------------------------------------------------------------------- */
27784 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27785 +const char *au_optstr_udba(int udba);
27786 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27787 +const char *au_optstr_wbr_create(int wbr_create);
27789 +void au_opts_free(struct au_opts *opts);
27790 +struct super_block;
27791 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27792 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27793 + unsigned int pending);
27794 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27795 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27797 +unsigned int au_opt_udba(struct super_block *sb);
27799 +#endif /* __KERNEL__ */
27800 +#endif /* __AUFS_OPTS_H__ */
27801 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27802 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27803 +++ linux/fs/aufs/plink.c 2020-01-27 10:57:18.175538316 +0100
27805 +// SPDX-License-Identifier: GPL-2.0
27807 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27809 + * This program, aufs is free software; you can redistribute it and/or modify
27810 + * it under the terms of the GNU General Public License as published by
27811 + * the Free Software Foundation; either version 2 of the License, or
27812 + * (at your option) any later version.
27814 + * This program is distributed in the hope that it will be useful,
27815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27817 + * GNU General Public License for more details.
27819 + * You should have received a copy of the GNU General Public License
27820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27830 + * the pseudo-link maintenance mode.
27831 + * during a user process maintains the pseudo-links,
27832 + * prohibit adding a new plink and branch manipulation.
27836 + * For entry functions which will handle plink, and i_mutex is already held
27838 + * They cannot wait and should return an error at once.
27839 + * Callers has to check the error.
27841 + * For entry functions which will handle plink, but i_mutex is not held
27843 + * They can wait the plink maintenance mode to finish.
27845 + * They behave like F_SETLK and F_SETLKW.
27846 + * If the caller never handle plink, then both flags are unnecessary.
27849 +int au_plink_maint(struct super_block *sb, int flags)
27853 + struct task_struct *parent, *prev;
27854 + struct au_sbinfo *sbi;
27856 + SiMustAnyLock(sb);
27859 + if (!au_opt_test(au_mntflags(sb), PLINK))
27862 + sbi = au_sbi(sb);
27863 + pid = sbi->si_plink_maint_pid;
27864 + if (!pid || pid == current->pid)
27867 + /* todo: it highly depends upon /sbin/mount.aufs */
27869 + parent = current;
27873 + parent = rcu_dereference(parent->real_parent);
27874 + if (parent == prev)
27876 + ppid = task_pid_vnr(parent);
27877 + if (pid == ppid) {
27878 + rcu_read_unlock();
27883 + rcu_read_unlock();
27885 + if (au_ftest_lock(flags, NOPLMW)) {
27886 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27887 + /* AuDebugOn(!lockdep_depth(current)); */
27888 + while (sbi->si_plink_maint_pid) {
27889 + si_read_unlock(sb);
27890 + /* gave up wake_up_bit() */
27891 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27893 + if (au_ftest_lock(flags, FLUSH))
27894 + au_nwt_flush(&sbi->si_nowait);
27895 + si_noflush_read_lock(sb);
27897 + } else if (au_ftest_lock(flags, NOPLM)) {
27898 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27906 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27908 + spin_lock(&sbinfo->si_plink_maint_lock);
27909 + sbinfo->si_plink_maint_pid = 0;
27910 + spin_unlock(&sbinfo->si_plink_maint_lock);
27911 + wake_up_all(&sbinfo->si_plink_wq);
27914 +int au_plink_maint_enter(struct super_block *sb)
27917 + struct au_sbinfo *sbinfo;
27920 + sbinfo = au_sbi(sb);
27921 + /* make sure i am the only one in this fs */
27922 + si_write_lock(sb, AuLock_FLUSH);
27923 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27924 + spin_lock(&sbinfo->si_plink_maint_lock);
27925 + if (!sbinfo->si_plink_maint_pid)
27926 + sbinfo->si_plink_maint_pid = current->pid;
27929 + spin_unlock(&sbinfo->si_plink_maint_lock);
27931 + si_write_unlock(sb);
27936 +/* ---------------------------------------------------------------------- */
27938 +#ifdef CONFIG_AUFS_DEBUG
27939 +void au_plink_list(struct super_block *sb)
27942 + struct au_sbinfo *sbinfo;
27943 + struct hlist_bl_head *hbl;
27944 + struct hlist_bl_node *pos;
27945 + struct au_icntnr *icntnr;
27947 + SiMustAnyLock(sb);
27949 + sbinfo = au_sbi(sb);
27950 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27951 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27953 + for (i = 0; i < AuPlink_NHASH; i++) {
27954 + hbl = sbinfo->si_plink + i;
27955 + hlist_bl_lock(hbl);
27956 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27957 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27958 + hlist_bl_unlock(hbl);
27963 +/* is the inode pseudo-linked? */
27964 +int au_plink_test(struct inode *inode)
27967 + struct au_sbinfo *sbinfo;
27968 + struct hlist_bl_head *hbl;
27969 + struct hlist_bl_node *pos;
27970 + struct au_icntnr *icntnr;
27972 + sbinfo = au_sbi(inode->i_sb);
27973 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27974 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27975 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27978 + i = au_plink_hash(inode->i_ino);
27979 + hbl = sbinfo->si_plink + i;
27980 + hlist_bl_lock(hbl);
27981 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27982 + if (&icntnr->vfs_inode == inode) {
27986 + hlist_bl_unlock(hbl);
27990 +/* ---------------------------------------------------------------------- */
27993 + * generate a name for plink.
27994 + * the file will be stored under AUFS_WH_PLINKDIR.
27996 +/* 20 is max digits length of ulong 64 */
27997 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27999 +static int plink_name(char *name, int len, struct inode *inode,
28000 + aufs_bindex_t bindex)
28003 + struct inode *h_inode;
28005 + h_inode = au_h_iptr(inode, bindex);
28006 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28010 +struct au_do_plink_lkup_args {
28011 + struct dentry **errp;
28012 + struct qstr *tgtname;
28013 + struct dentry *h_parent;
28014 + struct au_branch *br;
28017 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28018 + struct dentry *h_parent,
28019 + struct au_branch *br)
28021 + struct dentry *h_dentry;
28022 + struct inode *h_inode;
28024 + h_inode = d_inode(h_parent);
28025 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28026 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28027 + inode_unlock_shared(h_inode);
28031 +static void au_call_do_plink_lkup(void *args)
28033 + struct au_do_plink_lkup_args *a = args;
28034 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28037 +/* lookup the plink-ed @inode under the branch at @bindex */
28038 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28040 + struct dentry *h_dentry, *h_parent;
28041 + struct au_branch *br;
28043 + char a[PLINK_NAME_LEN];
28044 + struct qstr tgtname = QSTR_INIT(a, 0);
28046 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28048 + br = au_sbr(inode->i_sb, bindex);
28049 + h_parent = br->br_wbr->wbr_plink;
28050 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28052 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28053 + struct au_do_plink_lkup_args args = {
28054 + .errp = &h_dentry,
28055 + .tgtname = &tgtname,
28056 + .h_parent = h_parent,
28060 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28061 + if (unlikely(wkq_err))
28062 + h_dentry = ERR_PTR(wkq_err);
28064 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28069 +/* create a pseudo-link */
28070 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28071 + struct dentry *h_dentry, struct au_branch *br)
28074 + struct path h_path = {
28075 + .mnt = au_br_mnt(br)
28077 + struct inode *h_dir, *delegated;
28079 + h_dir = d_inode(h_parent);
28080 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28082 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28083 + err = PTR_ERR(h_path.dentry);
28084 + if (IS_ERR(h_path.dentry))
28088 + /* wh.plink dir is not monitored */
28089 + /* todo: is it really safe? */
28090 + if (d_is_positive(h_path.dentry)
28091 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28092 + delegated = NULL;
28093 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28094 + if (unlikely(err == -EWOULDBLOCK)) {
28095 + pr_warn("cannot retry for NFSv4 delegation"
28096 + " for an internal unlink\n");
28099 + dput(h_path.dentry);
28100 + h_path.dentry = NULL;
28104 + if (!err && d_is_negative(h_path.dentry)) {
28105 + delegated = NULL;
28106 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28107 + if (unlikely(err == -EWOULDBLOCK)) {
28108 + pr_warn("cannot retry for NFSv4 delegation"
28109 + " for an internal link\n");
28113 + dput(h_path.dentry);
28116 + inode_unlock(h_dir);
28120 +struct do_whplink_args {
28122 + struct qstr *tgt;
28123 + struct dentry *h_parent;
28124 + struct dentry *h_dentry;
28125 + struct au_branch *br;
28128 +static void call_do_whplink(void *args)
28130 + struct do_whplink_args *a = args;
28131 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28134 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28135 + aufs_bindex_t bindex, struct au_branch *br)
28137 + int err, wkq_err;
28138 + struct au_wbr *wbr;
28139 + struct dentry *h_parent;
28140 + char a[PLINK_NAME_LEN];
28141 + struct qstr tgtname = QSTR_INIT(a, 0);
28143 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28144 + h_parent = wbr->wbr_plink;
28145 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28147 + /* always superio. */
28148 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28149 + struct do_whplink_args args = {
28152 + .h_parent = h_parent,
28153 + .h_dentry = h_dentry,
28156 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28157 + if (unlikely(wkq_err))
28160 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28166 + * create a new pseudo-link for @h_dentry on @bindex.
28167 + * the linked inode is held in aufs @inode.
28169 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28170 + struct dentry *h_dentry)
28172 + struct super_block *sb;
28173 + struct au_sbinfo *sbinfo;
28174 + struct hlist_bl_head *hbl;
28175 + struct hlist_bl_node *pos;
28176 + struct au_icntnr *icntnr;
28177 + int found, err, cnt, i;
28179 + sb = inode->i_sb;
28180 + sbinfo = au_sbi(sb);
28181 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28182 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28184 + found = au_plink_test(inode);
28188 + i = au_plink_hash(inode->i_ino);
28189 + hbl = sbinfo->si_plink + i;
28192 + hlist_bl_lock(hbl);
28193 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28194 + if (&icntnr->vfs_inode == inode) {
28200 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28201 + hlist_bl_add_head(&icntnr->plink, hbl);
28203 + hlist_bl_unlock(hbl);
28205 + cnt = au_hbl_count(hbl);
28206 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28207 + if (cnt > AUFS_PLINK_WARN)
28208 + AuWarn1(msg ", %d\n", cnt);
28210 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28211 + if (unlikely(err)) {
28212 + pr_warn("err %d, damaged pseudo link.\n", err);
28213 + au_hbl_del(&icntnr->plink, hbl);
28214 + iput(&icntnr->vfs_inode);
28217 + iput(&icntnr->vfs_inode);
28220 +/* free all plinks */
28221 +void au_plink_put(struct super_block *sb, int verbose)
28224 + struct au_sbinfo *sbinfo;
28225 + struct hlist_bl_head *hbl;
28226 + struct hlist_bl_node *pos, *tmp;
28227 + struct au_icntnr *icntnr;
28229 + SiMustWriteLock(sb);
28231 + sbinfo = au_sbi(sb);
28232 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28233 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28235 + /* no spin_lock since sbinfo is write-locked */
28237 + for (i = 0; i < AuPlink_NHASH; i++) {
28238 + hbl = sbinfo->si_plink + i;
28239 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28240 + pr_warn("pseudo-link is not flushed");
28243 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28244 + iput(&icntnr->vfs_inode);
28245 + INIT_HLIST_BL_HEAD(hbl);
28249 +void au_plink_clean(struct super_block *sb, int verbose)
28251 + struct dentry *root;
28253 + root = sb->s_root;
28254 + aufs_write_lock(root);
28255 + if (au_opt_test(au_mntflags(sb), PLINK))
28256 + au_plink_put(sb, verbose);
28257 + aufs_write_unlock(root);
28260 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28263 + aufs_bindex_t btop, bbot, bindex;
28266 + btop = au_ibtop(inode);
28267 + bbot = au_ibbot(inode);
28269 + for (bindex = btop; bindex <= bbot; bindex++) {
28270 + if (!au_h_iptr(inode, bindex)
28271 + || au_ii_br_id(inode, bindex) != br_id)
28273 + au_set_h_iptr(inode, bindex, NULL, 0);
28278 + for (bindex = btop; bindex <= bbot; bindex++)
28279 + if (au_h_iptr(inode, bindex)) {
28289 +/* free the plinks on a branch specified by @br_id */
28290 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28292 + struct au_sbinfo *sbinfo;
28293 + struct hlist_bl_head *hbl;
28294 + struct hlist_bl_node *pos, *tmp;
28295 + struct au_icntnr *icntnr;
28296 + struct inode *inode;
28299 + SiMustWriteLock(sb);
28301 + sbinfo = au_sbi(sb);
28302 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28303 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28305 + /* no bit_lock since sbinfo is write-locked */
28306 + for (i = 0; i < AuPlink_NHASH; i++) {
28307 + hbl = sbinfo->si_plink + i;
28308 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28309 + inode = au_igrab(&icntnr->vfs_inode);
28310 + ii_write_lock_child(inode);
28311 + do_put = au_plink_do_half_refresh(inode, br_id);
28313 + hlist_bl_del(&icntnr->plink);
28316 + ii_write_unlock(inode);
28321 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28322 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28323 +++ linux/fs/aufs/poll.c 2020-01-27 10:57:18.175538316 +0100
28325 +// SPDX-License-Identifier: GPL-2.0
28327 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28329 + * This program, aufs is free software; you can redistribute it and/or modify
28330 + * it under the terms of the GNU General Public License as published by
28331 + * the Free Software Foundation; either version 2 of the License, or
28332 + * (at your option) any later version.
28334 + * This program is distributed in the hope that it will be useful,
28335 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28336 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28337 + * GNU General Public License for more details.
28339 + * You should have received a copy of the GNU General Public License
28340 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28345 + * There is only one filesystem which implements ->poll operation, currently.
28350 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28353 + struct file *h_file;
28354 + struct super_block *sb;
28356 + /* We should pretend an error happened. */
28357 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28358 + sb = file->f_path.dentry->d_sb;
28359 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28361 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28362 + if (IS_ERR(h_file)) {
28363 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28367 + mask = vfs_poll(h_file, pt);
28368 + fput(h_file); /* instead of au_read_post() */
28371 + si_read_unlock(sb);
28372 + if (mask & EPOLLERR)
28373 + AuDbg("mask 0x%x\n", mask);
28376 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28377 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28378 +++ linux/fs/aufs/posix_acl.c 2020-01-27 10:57:18.175538316 +0100
28380 +// SPDX-License-Identifier: GPL-2.0
28382 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28384 + * This program, aufs is free software; you can redistribute it and/or modify
28385 + * it under the terms of the GNU General Public License as published by
28386 + * the Free Software Foundation; either version 2 of the License, or
28387 + * (at your option) any later version.
28389 + * This program is distributed in the hope that it will be useful,
28390 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28391 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28392 + * GNU General Public License for more details.
28394 + * You should have received a copy of the GNU General Public License
28395 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28399 + * posix acl operations
28402 +#include <linux/fs.h>
28405 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28407 + struct posix_acl *acl;
28409 + aufs_bindex_t bindex;
28410 + struct inode *h_inode;
28411 + struct super_block *sb;
28414 + sb = inode->i_sb;
28415 + si_read_lock(sb, AuLock_FLUSH);
28416 + ii_read_lock_child(inode);
28417 + if (!(sb->s_flags & SB_POSIXACL))
28420 + bindex = au_ibtop(inode);
28421 + h_inode = au_h_iptr(inode, bindex);
28422 + if (unlikely(!h_inode
28423 + || ((h_inode->i_mode & S_IFMT)
28424 + != (inode->i_mode & S_IFMT)))) {
28425 + err = au_busy_or_stale();
28426 + acl = ERR_PTR(err);
28430 + /* always topmost only */
28431 + acl = get_acl(h_inode, type);
28433 + forget_cached_acl(inode, type);
28435 + set_cached_acl(inode, type, acl);
28438 + ii_read_unlock(inode);
28439 + si_read_unlock(sb);
28441 + AuTraceErrPtr(acl);
28445 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28449 + struct dentry *dentry;
28450 + struct au_sxattr arg = {
28451 + .type = AU_ACL_SET,
28458 + IMustLock(inode);
28460 + if (inode->i_ino == AUFS_ROOT_INO)
28461 + dentry = dget(inode->i_sb->s_root);
28463 + dentry = d_find_alias(inode);
28465 + dentry = d_find_any_alias(inode);
28467 + pr_warn("cannot handle this inode, "
28468 + "please report to aufs-users ML\n");
28474 + ssz = au_sxattr(dentry, inode, &arg);
28475 + /* forget even it if succeeds since the branch might set differently */
28476 + forget_cached_acl(inode, type);
28485 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28486 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28487 +++ linux/fs/aufs/procfs.c 2020-04-03 08:16:47.547461775 +0200
28489 +// SPDX-License-Identifier: GPL-2.0
28491 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28493 + * This program, aufs is free software; you can redistribute it and/or modify
28494 + * it under the terms of the GNU General Public License as published by
28495 + * the Free Software Foundation; either version 2 of the License, or
28496 + * (at your option) any later version.
28498 + * This program is distributed in the hope that it will be useful,
28499 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28500 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28501 + * GNU General Public License for more details.
28503 + * You should have received a copy of the GNU General Public License
28504 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28508 + * procfs interfaces
28511 +#include <linux/proc_fs.h>
28514 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28516 + struct au_sbinfo *sbinfo;
28518 + sbinfo = file->private_data;
28520 + au_plink_maint_leave(sbinfo);
28521 + kobject_put(&sbinfo->si_kobj);
28527 +static void au_procfs_plm_write_clean(struct file *file)
28529 + struct au_sbinfo *sbinfo;
28531 + sbinfo = file->private_data;
28533 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28536 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28539 + struct super_block *sb;
28540 + struct au_sbinfo *sbinfo;
28541 + struct hlist_bl_node *pos;
28544 + if (unlikely(file->private_data))
28548 + /* don't use au_sbilist_lock() here */
28549 + hlist_bl_lock(&au_sbilist);
28550 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28551 + if (id == sysaufs_si_id(sbinfo)) {
28552 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28553 + sb = sbinfo->si_sb;
28556 + hlist_bl_unlock(&au_sbilist);
28559 + if (unlikely(!sb))
28562 + err = au_plink_maint_enter(sb);
28564 + /* keep kobject_get() */
28565 + file->private_data = sbinfo;
28567 + kobject_put(&sbinfo->si_kobj);
28573 + * Accept a valid "si=xxxx" only.
28574 + * Once it is accepted successfully, accept "clean" too.
28576 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28577 + size_t count, loff_t *ppos)
28580 + unsigned long id;
28581 + /* last newline is allowed */
28582 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28585 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28589 + if (unlikely(count > sizeof(buf)))
28592 + err = copy_from_user(buf, ubuf, count);
28593 + if (unlikely(err)) {
28600 + if (!strcmp("clean", buf)) {
28601 + au_procfs_plm_write_clean(file);
28602 + goto out_success;
28603 + } else if (unlikely(strncmp("si=", buf, 3)))
28606 + err = kstrtoul(buf + 3, 16, &id);
28607 + if (unlikely(err))
28610 + err = au_procfs_plm_write_si(file, id);
28611 + if (unlikely(err))
28615 + err = count; /* success */
28620 +static const struct file_operations au_procfs_plm_fop = {
28621 + .write = au_procfs_plm_write,
28622 + .release = au_procfs_plm_release,
28623 + .owner = THIS_MODULE
28626 +/* ---------------------------------------------------------------------- */
28628 +static struct proc_dir_entry *au_procfs_dir;
28630 +void au_procfs_fin(void)
28632 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28633 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28636 +int __init au_procfs_init(void)
28639 + struct proc_dir_entry *entry;
28642 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28643 + if (unlikely(!au_procfs_dir))
28646 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28647 + au_procfs_dir, &au_procfs_plm_fop);
28648 + if (unlikely(!entry))
28652 + goto out; /* success */
28656 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28660 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28661 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28662 +++ linux/fs/aufs/rdu.c 2020-01-27 10:57:18.178871751 +0100
28664 +// SPDX-License-Identifier: GPL-2.0
28666 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28668 + * This program, aufs is free software; you can redistribute it and/or modify
28669 + * it under the terms of the GNU General Public License as published by
28670 + * the Free Software Foundation; either version 2 of the License, or
28671 + * (at your option) any later version.
28673 + * This program is distributed in the hope that it will be useful,
28674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28676 + * GNU General Public License for more details.
28678 + * You should have received a copy of the GNU General Public License
28679 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28683 + * readdir in userspace.
28686 +#include <linux/compat.h>
28687 +#include <linux/fs_stack.h>
28688 +#include <linux/security.h>
28691 +/* bits for struct aufs_rdu.flags */
28692 +#define AuRdu_CALLED 1
28693 +#define AuRdu_CONT (1 << 1)
28694 +#define AuRdu_FULL (1 << 2)
28695 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28696 +#define au_fset_rdu(flags, name) \
28697 + do { (flags) |= AuRdu_##name; } while (0)
28698 +#define au_fclr_rdu(flags, name) \
28699 + do { (flags) &= ~AuRdu_##name; } while (0)
28701 +struct au_rdu_arg {
28702 + struct dir_context ctx;
28703 + struct aufs_rdu *rdu;
28704 + union au_rdu_ent_ul ent;
28705 + unsigned long end;
28707 + struct super_block *sb;
28711 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28712 + loff_t offset, u64 h_ino, unsigned int d_type)
28715 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28716 + struct aufs_rdu *rdu = arg->rdu;
28717 + struct au_rdu_ent ent;
28721 + au_fset_rdu(rdu->cookie.flags, CALLED);
28722 + len = au_rdu_len(nlen);
28723 + if (arg->ent.ul + len < arg->end) {
28725 + ent.bindex = rdu->cookie.bindex;
28726 + ent.type = d_type;
28728 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28729 + ent.type = DT_UNKNOWN;
28731 + /* unnecessary to support mmap_sem since this is a dir */
28733 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28735 + if (copy_to_user(arg->ent.e->name, name, nlen))
28737 + /* the terminating NULL */
28738 + if (__put_user(0, arg->ent.e->name + nlen))
28741 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28742 + arg->ent.ul += len;
28746 + au_fset_rdu(rdu->cookie.flags, FULL);
28748 + rdu->tail = arg->ent;
28752 + /* AuTraceErr(err); */
28756 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28760 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28762 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28763 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28765 + if (unlikely(offset != cookie->h_pos))
28771 + au_fclr_rdu(cookie->flags, CALLED);
28773 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28777 + && au_ftest_rdu(cookie->flags, CALLED)
28778 + && !au_ftest_rdu(cookie->flags, FULL));
28779 + cookie->h_pos = h_file->f_pos;
28786 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28789 + aufs_bindex_t bbot;
28790 + struct au_rdu_arg arg = {
28792 + .actor = au_rdu_fill
28795 + struct dentry *dentry;
28796 + struct inode *inode;
28797 + struct file *h_file;
28798 + struct au_rdu_cookie *cookie = &rdu->cookie;
28800 + /* VERIFY_WRITE */
28801 + err = !access_ok(rdu->ent.e, rdu->sz);
28802 + if (unlikely(err)) {
28808 + rdu->tail = rdu->ent;
28811 + arg.ent = rdu->ent;
28812 + arg.end = arg.ent.ul;
28813 + arg.end += rdu->sz;
28816 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28819 + err = security_file_permission(file, MAY_READ);
28821 + if (unlikely(err))
28824 + dentry = file->f_path.dentry;
28825 + inode = d_inode(dentry);
28826 + inode_lock_shared(inode);
28828 + arg.sb = inode->i_sb;
28829 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28830 + if (unlikely(err))
28832 + err = au_alive_dir(dentry);
28833 + if (unlikely(err))
28835 + /* todo: reval? */
28836 + fi_read_lock(file);
28839 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28840 + && cookie->generation != au_figen(file)))
28845 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28847 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28849 + bbot = au_fbtop(file);
28850 + if (cookie->bindex < bbot)
28851 + cookie->bindex = bbot;
28852 + bbot = au_fbbot_dir(file);
28853 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28854 + for (; !err && cookie->bindex <= bbot;
28855 + cookie->bindex++, cookie->h_pos = 0) {
28856 + h_file = au_hf_dir(file, cookie->bindex);
28860 + au_fclr_rdu(cookie->flags, FULL);
28861 + err = au_rdu_do(h_file, &arg);
28863 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28866 + AuDbg("rent %llu\n", rdu->rent);
28868 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28869 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28870 + au_fset_rdu(cookie->flags, CONT);
28871 + cookie->generation = au_figen(file);
28874 + ii_read_lock_child(inode);
28875 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28876 + ii_read_unlock(inode);
28879 + fi_read_unlock(file);
28881 + si_read_unlock(arg.sb);
28883 + inode_unlock_shared(inode);
28889 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28893 + unsigned long long nent;
28894 + union au_rdu_ent_ul *u;
28895 + struct au_rdu_ent ent;
28896 + struct super_block *sb;
28899 + nent = rdu->nent;
28901 + sb = file->f_path.dentry->d_sb;
28902 + si_read_lock(sb, AuLock_FLUSH);
28903 + while (nent-- > 0) {
28904 + /* unnecessary to support mmap_sem since this is a dir */
28905 + err = copy_from_user(&ent, u->e, sizeof(ent));
28907 + /* VERIFY_WRITE */
28908 + err = !access_ok(&u->e->ino, sizeof(ino));
28909 + if (unlikely(err)) {
28915 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28917 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28919 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28921 + if (unlikely(err)) {
28926 + err = __put_user(ino, &u->e->ino);
28927 + if (unlikely(err)) {
28932 + u->ul += au_rdu_len(ent.nlen);
28934 + si_read_unlock(sb);
28939 +/* ---------------------------------------------------------------------- */
28941 +static int au_rdu_verify(struct aufs_rdu *rdu)
28943 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28944 + "%llu, b%d, 0x%x, g%u}\n",
28945 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28947 + rdu->rent, rdu->shwh, rdu->full,
28948 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28949 + rdu->cookie.generation);
28951 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28955 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28959 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28962 + struct aufs_rdu rdu;
28963 + void __user *p = (void __user *)arg;
28965 + err = copy_from_user(&rdu, p, sizeof(rdu));
28966 + if (unlikely(err)) {
28971 + err = au_rdu_verify(&rdu);
28972 + if (unlikely(err))
28976 + case AUFS_CTL_RDU:
28977 + err = au_rdu(file, &rdu);
28978 + if (unlikely(err))
28981 + e = copy_to_user(p, &rdu, sizeof(rdu));
28982 + if (unlikely(e)) {
28987 + case AUFS_CTL_RDU_INO:
28988 + err = au_rdu_ino(file, &rdu);
28992 + /* err = -ENOTTY; */
29001 +#ifdef CONFIG_COMPAT
29002 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29005 + struct aufs_rdu rdu;
29006 + void __user *p = compat_ptr(arg);
29008 + /* todo: get_user()? */
29009 + err = copy_from_user(&rdu, p, sizeof(rdu));
29010 + if (unlikely(err)) {
29015 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29016 + err = au_rdu_verify(&rdu);
29017 + if (unlikely(err))
29021 + case AUFS_CTL_RDU:
29022 + err = au_rdu(file, &rdu);
29023 + if (unlikely(err))
29026 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29027 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29028 + e = copy_to_user(p, &rdu, sizeof(rdu));
29029 + if (unlikely(e)) {
29034 + case AUFS_CTL_RDU_INO:
29035 + err = au_rdu_ino(file, &rdu);
29039 + /* err = -ENOTTY; */
29048 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29049 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29050 +++ linux/fs/aufs/rwsem.h 2020-01-27 10:57:18.178871751 +0100
29052 +/* SPDX-License-Identifier: GPL-2.0 */
29054 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29056 + * This program, aufs is free software; you can redistribute it and/or modify
29057 + * it under the terms of the GNU General Public License as published by
29058 + * the Free Software Foundation; either version 2 of the License, or
29059 + * (at your option) any later version.
29061 + * This program is distributed in the hope that it will be useful,
29062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29064 + * GNU General Public License for more details.
29066 + * You should have received a copy of the GNU General Public License
29067 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29071 + * simple read-write semaphore wrappers
29074 +#ifndef __AUFS_RWSEM_H__
29075 +#define __AUFS_RWSEM_H__
29079 +#include "debug.h"
29081 +/* in the future, the name 'au_rwsem' will be totally gone */
29082 +#define au_rwsem rw_semaphore
29084 +/* to debug easier, do not make them inlined functions */
29085 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29086 +/* rwsem_is_locked() is unusable */
29087 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29089 + && !lockdep_is_held_type(rw, 1))
29090 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29092 + && !lockdep_is_held_type(rw, 0))
29093 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29095 + && !lockdep_is_held(rw))
29096 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29098 + && lockdep_is_held(rw))
29100 +#define au_rw_init(rw) init_rwsem(rw)
29102 +#define au_rw_init_wlock(rw) do { \
29103 + au_rw_init(rw); \
29104 + down_write(rw); \
29107 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29108 + au_rw_init(rw); \
29109 + down_write_nested(rw, lsc); \
29112 +#define au_rw_read_lock(rw) down_read(rw)
29113 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29114 +#define au_rw_read_unlock(rw) up_read(rw)
29115 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29116 +#define au_rw_write_lock(rw) down_write(rw)
29117 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29118 +#define au_rw_write_unlock(rw) up_write(rw)
29119 +/* why is not _nested version defined? */
29120 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29121 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29123 +#endif /* __KERNEL__ */
29124 +#endif /* __AUFS_RWSEM_H__ */
29125 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29126 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29127 +++ linux/fs/aufs/sbinfo.c 2020-01-27 10:57:18.178871751 +0100
29129 +// SPDX-License-Identifier: GPL-2.0
29131 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29133 + * This program, aufs is free software; you can redistribute it and/or modify
29134 + * it under the terms of the GNU General Public License as published by
29135 + * the Free Software Foundation; either version 2 of the License, or
29136 + * (at your option) any later version.
29138 + * This program is distributed in the hope that it will be useful,
29139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29141 + * GNU General Public License for more details.
29143 + * You should have received a copy of the GNU General Public License
29144 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29148 + * superblock private data
29151 +#include <linux/iversion.h>
29155 + * they are necessary regardless sysfs is disabled.
29157 +void au_si_free(struct kobject *kobj)
29160 + struct au_sbinfo *sbinfo;
29161 + char *locked __maybe_unused; /* debug only */
29163 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29164 + for (i = 0; i < AuPlink_NHASH; i++)
29165 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29166 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29168 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29169 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29170 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29171 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29173 + dbgaufs_si_fin(sbinfo);
29174 + au_rw_write_lock(&sbinfo->si_rwsem);
29175 + au_br_free(sbinfo);
29176 + au_rw_write_unlock(&sbinfo->si_rwsem);
29178 + au_kfree_try_rcu(sbinfo->si_branch);
29179 + mutex_destroy(&sbinfo->si_xib_mtx);
29180 + AuRwDestroy(&sbinfo->si_rwsem);
29182 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29183 + /* si_nfiles is waited too */
29184 + au_kfree_rcu(sbinfo);
29187 +int au_si_alloc(struct super_block *sb)
29190 + struct au_sbinfo *sbinfo;
29193 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29194 + if (unlikely(!sbinfo))
29197 + /* will be reallocated separately */
29198 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29199 + if (unlikely(!sbinfo->si_branch))
29202 + err = sysaufs_si_init(sbinfo);
29204 + dbgaufs_si_null(sbinfo);
29205 + err = dbgaufs_si_init(sbinfo);
29206 + if (unlikely(err))
29207 + kobject_put(&sbinfo->si_kobj);
29209 + if (unlikely(err))
29212 + au_nwt_init(&sbinfo->si_nowait);
29213 + au_rw_init_wlock(&sbinfo->si_rwsem);
29215 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29216 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29218 + sbinfo->si_bbot = -1;
29219 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29221 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29222 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29223 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29224 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29226 + au_fhsm_init(sbinfo);
29228 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29230 + sbinfo->si_xino_jiffy = jiffies;
29231 + sbinfo->si_xino_expire
29232 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29233 + mutex_init(&sbinfo->si_xib_mtx);
29234 + /* leave si_xib_last_pindex and si_xib_next_bit */
29236 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29238 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29239 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29240 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29241 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29243 + for (i = 0; i < AuPlink_NHASH; i++)
29244 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29245 + init_waitqueue_head(&sbinfo->si_plink_wq);
29246 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29248 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29250 + /* with getattr by default */
29251 + sbinfo->si_iop_array = aufs_iop;
29253 + /* leave other members for sysaufs and si_mnt. */
29254 + sbinfo->si_sb = sb;
29255 + sb->s_fs_info = sbinfo;
29257 + return 0; /* success */
29260 + au_kfree_try_rcu(sbinfo->si_branch);
29262 + au_kfree_rcu(sbinfo);
29267 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29270 + struct au_branch **brp;
29272 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29275 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29276 + if (unlikely(!sz))
29277 + sz = sizeof(*brp);
29278 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29281 + sbinfo->si_branch = brp;
29288 +/* ---------------------------------------------------------------------- */
29290 +unsigned int au_sigen_inc(struct super_block *sb)
29292 + unsigned int gen;
29293 + struct inode *inode;
29295 + SiMustWriteLock(sb);
29297 + gen = ++au_sbi(sb)->si_generation;
29298 + au_update_digen(sb->s_root);
29299 + inode = d_inode(sb->s_root);
29300 + au_update_iigen(inode, /*half*/0);
29301 + inode_inc_iversion(inode);
29305 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29307 + aufs_bindex_t br_id;
29309 + struct au_sbinfo *sbinfo;
29311 + SiMustWriteLock(sb);
29313 + sbinfo = au_sbi(sb);
29314 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29315 + br_id = ++sbinfo->si_last_br_id;
29316 + AuDebugOn(br_id < 0);
29317 + if (br_id && au_br_index(sb, br_id) < 0)
29324 +/* ---------------------------------------------------------------------- */
29326 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29327 +int si_read_lock(struct super_block *sb, int flags)
29332 + if (au_ftest_lock(flags, FLUSH))
29333 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29335 + si_noflush_read_lock(sb);
29336 + err = au_plink_maint(sb, flags);
29337 + if (unlikely(err))
29338 + si_read_unlock(sb);
29343 +int si_write_lock(struct super_block *sb, int flags)
29347 + if (au_ftest_lock(flags, FLUSH))
29348 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29350 + si_noflush_write_lock(sb);
29351 + err = au_plink_maint(sb, flags);
29352 + if (unlikely(err))
29353 + si_write_unlock(sb);
29358 +/* dentry and super_block lock. call at entry point */
29359 +int aufs_read_lock(struct dentry *dentry, int flags)
29362 + struct super_block *sb;
29364 + sb = dentry->d_sb;
29365 + err = si_read_lock(sb, flags);
29366 + if (unlikely(err))
29369 + if (au_ftest_lock(flags, DW))
29370 + di_write_lock_child(dentry);
29372 + di_read_lock_child(dentry, flags);
29374 + if (au_ftest_lock(flags, GEN)) {
29375 + err = au_digen_test(dentry, au_sigen(sb));
29376 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29377 + AuDebugOn(!err && au_dbrange_test(dentry));
29379 + err = au_dbrange_test(dentry);
29380 + if (unlikely(err))
29381 + aufs_read_unlock(dentry, flags);
29388 +void aufs_read_unlock(struct dentry *dentry, int flags)
29390 + if (au_ftest_lock(flags, DW))
29391 + di_write_unlock(dentry);
29393 + di_read_unlock(dentry, flags);
29394 + si_read_unlock(dentry->d_sb);
29397 +void aufs_write_lock(struct dentry *dentry)
29399 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29400 + di_write_lock_child(dentry);
29403 +void aufs_write_unlock(struct dentry *dentry)
29405 + di_write_unlock(dentry);
29406 + si_write_unlock(dentry->d_sb);
29409 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29412 + unsigned int sigen;
29413 + struct super_block *sb;
29416 + err = si_read_lock(sb, flags);
29417 + if (unlikely(err))
29420 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29422 + if (au_ftest_lock(flags, GEN)) {
29423 + sigen = au_sigen(sb);
29424 + err = au_digen_test(d1, sigen);
29425 + AuDebugOn(!err && au_dbrange_test(d1));
29427 + err = au_digen_test(d2, sigen);
29428 + AuDebugOn(!err && au_dbrange_test(d2));
29430 + if (unlikely(err))
29431 + aufs_read_and_write_unlock2(d1, d2);
29438 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29440 + di_write_unlock2(d1, d2);
29441 + si_read_unlock(d1->d_sb);
29443 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29444 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29445 +++ linux/fs/aufs/super.c 2020-01-27 10:57:18.178871751 +0100
29447 +// SPDX-License-Identifier: GPL-2.0
29449 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29451 + * This program, aufs is free software; you can redistribute it and/or modify
29452 + * it under the terms of the GNU General Public License as published by
29453 + * the Free Software Foundation; either version 2 of the License, or
29454 + * (at your option) any later version.
29456 + * This program is distributed in the hope that it will be useful,
29457 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29458 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29459 + * GNU General Public License for more details.
29461 + * You should have received a copy of the GNU General Public License
29462 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29466 + * mount and super_block operations
29469 +#include <linux/iversion.h>
29470 +#include <linux/mm.h>
29471 +#include <linux/seq_file.h>
29472 +#include <linux/statfs.h>
29473 +#include <linux/vmalloc.h>
29477 + * super_operations
29479 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29481 + struct au_icntnr *c;
29483 + c = au_cache_alloc_icntnr();
29485 + au_icntnr_init(c);
29486 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29487 + c->iinfo.ii_hinode = NULL;
29488 + return &c->vfs_inode;
29493 +static void aufs_destroy_inode(struct inode *inode)
29495 + if (!au_is_bad_inode(inode))
29496 + au_iinfo_fin(inode);
29499 +static void aufs_free_inode(struct inode *inode)
29501 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29504 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29506 + struct inode *inode;
29509 + inode = iget_locked(sb, ino);
29510 + if (unlikely(!inode)) {
29511 + inode = ERR_PTR(-ENOMEM);
29514 + if (!(inode->i_state & I_NEW))
29517 + err = au_xigen_new(inode);
29519 + err = au_iinfo_init(inode);
29521 + inode_inc_iversion(inode);
29523 + iget_failed(inode);
29524 + inode = ERR_PTR(err);
29528 + /* never return NULL */
29529 + AuDebugOn(!inode);
29530 + AuTraceErrPtr(inode);
29534 +/* lock free root dinfo */
29535 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29538 + aufs_bindex_t bindex, bbot;
29539 + struct path path;
29540 + struct au_hdentry *hdp;
29541 + struct au_branch *br;
29542 + au_br_perm_str_t perm;
29545 + bbot = au_sbbot(sb);
29547 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29548 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29549 + br = au_sbr(sb, bindex);
29550 + path.mnt = au_br_mnt(br);
29551 + path.dentry = hdp->hd_dentry;
29552 + err = au_seq_path(seq, &path);
29554 + au_optstr_br_perm(&perm, br->br_perm);
29555 + seq_printf(seq, "=%s", perm.a);
29556 + if (bindex != bbot)
29557 + seq_putc(seq, ':');
29560 + if (unlikely(err || seq_has_overflowed(seq)))
29566 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29567 + const char *append)
29572 + while (*pat != ':')
29575 + strcpy(p, append);
29576 + AuDebugOn(strlen(fmt) >= len);
29579 +static void au_show_wbr_create(struct seq_file *m, int v,
29580 + struct au_sbinfo *sbinfo)
29584 + struct au_wbr_mfs *mfs;
29586 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29588 + seq_puts(m, ",create=");
29589 + pat = au_optstr_wbr_create(v);
29590 + mfs = &sbinfo->si_wbr_mfs;
29592 + case AuWbrCreate_TDP:
29593 + case AuWbrCreate_RR:
29594 + case AuWbrCreate_MFS:
29595 + case AuWbrCreate_PMFS:
29596 + seq_puts(m, pat);
29598 + case AuWbrCreate_MFSRR:
29599 + case AuWbrCreate_TDMFS:
29600 + case AuWbrCreate_PMFSRR:
29601 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29602 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29604 + case AuWbrCreate_MFSV:
29605 + case AuWbrCreate_PMFSV:
29606 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29607 + seq_printf(m, fmt,
29608 + jiffies_to_msecs(mfs->mfs_expire)
29611 + case AuWbrCreate_MFSRRV:
29612 + case AuWbrCreate_TDMFSV:
29613 + case AuWbrCreate_PMFSRRV:
29614 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29615 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29616 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29623 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29625 +#ifdef CONFIG_SYSFS
29629 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29630 + aufs_bindex_t bindex, brid;
29631 + struct qstr *name;
29633 + struct dentry *d, *h_root;
29634 + struct au_branch *br;
29636 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29639 + f = au_sbi(sb)->si_xib;
29643 + /* stop printing the default xino path on the first writable branch */
29645 + bindex = au_xi_root(sb, f->f_path.dentry);
29646 + if (bindex >= 0) {
29647 + br = au_sbr_sb(sb, bindex);
29648 + h_root = au_br_dentry(br);
29651 + d = f->f_path.dentry;
29652 + name = &d->d_name;
29653 + /* safe ->d_parent because the file is unlinked */
29654 + if (d->d_parent == h_root
29655 + && name->len == len
29656 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29659 + seq_puts(seq, ",xino=");
29660 + err = au_xino_path(seq, f);
29667 +/* seq_file will re-call me in case of too long string */
29668 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29671 + unsigned int mnt_flags, v;
29672 + struct super_block *sb;
29673 + struct au_sbinfo *sbinfo;
29675 +#define AuBool(name, str) do { \
29676 + v = au_opt_test(mnt_flags, name); \
29677 + if (v != au_opt_test(AuOpt_Def, name)) \
29678 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29681 +#define AuStr(name, str) do { \
29682 + v = mnt_flags & AuOptMask_##name; \
29683 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29684 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29687 +#define AuUInt(name, str, val) do { \
29688 + if (val != AUFS_##name##_DEF) \
29689 + seq_printf(m, "," #str "=%u", val); \
29692 + sb = dentry->d_sb;
29693 + if (sb->s_flags & SB_POSIXACL)
29694 + seq_puts(m, ",acl");
29695 +#if 0 /* reserved for future use */
29696 + if (sb->s_flags & SB_I_VERSION)
29697 + seq_puts(m, ",i_version");
29700 + /* lock free root dinfo */
29701 + si_noflush_read_lock(sb);
29702 + sbinfo = au_sbi(sb);
29703 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29705 + mnt_flags = au_mntflags(sb);
29706 + if (au_opt_test(mnt_flags, XINO)) {
29707 + err = au_show_xino(m, sb);
29708 + if (unlikely(err))
29711 + seq_puts(m, ",noxino");
29713 + AuBool(TRUNC_XINO, trunc_xino);
29714 + AuStr(UDBA, udba);
29715 + AuBool(SHWH, shwh);
29716 + AuBool(PLINK, plink);
29717 + AuBool(DIO, dio);
29718 + AuBool(DIRPERM1, dirperm1);
29720 + v = sbinfo->si_wbr_create;
29721 + if (v != AuWbrCreate_Def)
29722 + au_show_wbr_create(m, v, sbinfo);
29724 + v = sbinfo->si_wbr_copyup;
29725 + if (v != AuWbrCopyup_Def)
29726 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29728 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29729 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29730 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29732 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29734 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29735 + AuUInt(RDCACHE, rdcache, v);
29737 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29738 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29740 + au_fhsm_show(m, sbinfo);
29742 + AuBool(DIRREN, dirren);
29743 + AuBool(SUM, sum);
29744 + /* AuBool(SUM_W, wsum); */
29745 + AuBool(WARN_PERM, warn_perm);
29746 + AuBool(VERBOSE, verbose);
29749 + /* be sure to print "br:" last */
29750 + if (!sysaufs_brs) {
29751 + seq_puts(m, ",br:");
29752 + au_show_brs(m, sb);
29754 + si_read_unlock(sb);
29762 +/* ---------------------------------------------------------------------- */
29764 +/* sum mode which returns the summation for statfs(2) */
29766 +static u64 au_add_till_max(u64 a, u64 b)
29774 + return ULLONG_MAX;
29777 +static u64 au_mul_till_max(u64 a, long mul)
29785 + return ULLONG_MAX;
29788 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29791 + long bsize, factor;
29792 + u64 blocks, bfree, bavail, files, ffree;
29793 + aufs_bindex_t bbot, bindex, i;
29794 + unsigned char shared;
29795 + struct path h_path;
29796 + struct super_block *h_sb;
29799 + bsize = LONG_MAX;
29805 + bbot = au_sbbot(sb);
29806 + for (bindex = 0; bindex <= bbot; bindex++) {
29807 + h_path.mnt = au_sbr_mnt(sb, bindex);
29808 + h_sb = h_path.mnt->mnt_sb;
29810 + for (i = 0; !shared && i < bindex; i++)
29811 + shared = (au_sbr_sb(sb, i) == h_sb);
29815 + /* sb->s_root for NFS is unreliable */
29816 + h_path.dentry = h_path.mnt->mnt_root;
29817 + err = vfs_statfs(&h_path, buf);
29818 + if (unlikely(err))
29821 + if (bsize > buf->f_bsize) {
29823 + * we will reduce bsize, so we have to expand blocks
29824 + * etc. to match them again
29826 + factor = (bsize / buf->f_bsize);
29827 + blocks = au_mul_till_max(blocks, factor);
29828 + bfree = au_mul_till_max(bfree, factor);
29829 + bavail = au_mul_till_max(bavail, factor);
29830 + bsize = buf->f_bsize;
29833 + factor = (buf->f_bsize / bsize);
29834 + blocks = au_add_till_max(blocks,
29835 + au_mul_till_max(buf->f_blocks, factor));
29836 + bfree = au_add_till_max(bfree,
29837 + au_mul_till_max(buf->f_bfree, factor));
29838 + bavail = au_add_till_max(bavail,
29839 + au_mul_till_max(buf->f_bavail, factor));
29840 + files = au_add_till_max(files, buf->f_files);
29841 + ffree = au_add_till_max(ffree, buf->f_ffree);
29844 + buf->f_bsize = bsize;
29845 + buf->f_blocks = blocks;
29846 + buf->f_bfree = bfree;
29847 + buf->f_bavail = bavail;
29848 + buf->f_files = files;
29849 + buf->f_ffree = ffree;
29850 + buf->f_frsize = 0;
29856 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29859 + struct path h_path;
29860 + struct super_block *sb;
29862 + /* lock free root dinfo */
29863 + sb = dentry->d_sb;
29864 + si_noflush_read_lock(sb);
29865 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29866 + /* sb->s_root for NFS is unreliable */
29867 + h_path.mnt = au_sbr_mnt(sb, 0);
29868 + h_path.dentry = h_path.mnt->mnt_root;
29869 + err = vfs_statfs(&h_path, buf);
29871 + err = au_statfs_sum(sb, buf);
29872 + si_read_unlock(sb);
29875 + buf->f_type = AUFS_SUPER_MAGIC;
29876 + buf->f_namelen = AUFS_MAX_NAMELEN;
29877 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29879 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29884 +/* ---------------------------------------------------------------------- */
29886 +static int aufs_sync_fs(struct super_block *sb, int wait)
29889 + aufs_bindex_t bbot, bindex;
29890 + struct au_branch *br;
29891 + struct super_block *h_sb;
29894 + si_noflush_read_lock(sb);
29895 + bbot = au_sbbot(sb);
29896 + for (bindex = 0; bindex <= bbot; bindex++) {
29897 + br = au_sbr(sb, bindex);
29898 + if (!au_br_writable(br->br_perm))
29901 + h_sb = au_sbr_sb(sb, bindex);
29902 + e = vfsub_sync_filesystem(h_sb, wait);
29903 + if (unlikely(e && !err))
29905 + /* go on even if an error happens */
29907 + si_read_unlock(sb);
29912 +/* ---------------------------------------------------------------------- */
29914 +/* final actions when unmounting a file system */
29915 +static void aufs_put_super(struct super_block *sb)
29917 + struct au_sbinfo *sbinfo;
29919 + sbinfo = au_sbi(sb);
29921 + kobject_put(&sbinfo->si_kobj);
29924 +/* ---------------------------------------------------------------------- */
29926 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29927 + struct super_block *sb, void *arg)
29930 + unsigned long long n, sz;
29937 + if (*hint > ULLONG_MAX / sizeof(array)) {
29938 + array = ERR_PTR(-EMFILE);
29939 + pr_err("hint %llu\n", *hint);
29943 + sz = sizeof(array) * *hint;
29944 + array = kzalloc(sz, GFP_NOFS);
29945 + if (unlikely(!array))
29946 + array = vzalloc(sz);
29947 + if (unlikely(!array)) {
29948 + array = ERR_PTR(-ENOMEM);
29952 + n = cb(sb, array, *hint, arg);
29953 + AuDebugOn(n > *hint);
29960 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29961 + unsigned long long max __maybe_unused,
29964 + unsigned long long n;
29965 + struct inode **p, *inode;
29966 + struct list_head *head;
29971 + spin_lock(&sb->s_inode_list_lock);
29972 + list_for_each_entry(inode, head, i_sb_list) {
29973 + if (!au_is_bad_inode(inode)
29974 + && au_ii(inode)->ii_btop >= 0) {
29975 + spin_lock(&inode->i_lock);
29976 + if (atomic_read(&inode->i_count)) {
29980 + AuDebugOn(n > max);
29982 + spin_unlock(&inode->i_lock);
29985 + spin_unlock(&sb->s_inode_list_lock);
29990 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29992 + struct au_sbinfo *sbi;
29994 + sbi = au_sbi(sb);
29995 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29996 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29999 +void au_iarray_free(struct inode **a, unsigned long long max)
30001 + unsigned long long ull;
30003 + for (ull = 0; ull < max; ull++)
30008 +/* ---------------------------------------------------------------------- */
30011 + * refresh dentry and inode at remount time.
30013 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30014 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30015 + struct dentry *parent)
30019 + di_write_lock_child(dentry);
30020 + di_read_lock_parent(parent, AuLock_IR);
30021 + err = au_refresh_dentry(dentry, parent);
30022 + if (!err && dir_flags)
30023 + au_hn_reset(d_inode(dentry), dir_flags);
30024 + di_read_unlock(parent, AuLock_IR);
30025 + di_write_unlock(dentry);
30030 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30031 + struct au_sbinfo *sbinfo,
30032 + const unsigned int dir_flags, unsigned int do_idop)
30035 + struct dentry *parent;
30038 + parent = dget_parent(dentry);
30039 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30040 + if (d_really_is_positive(dentry)) {
30041 + if (!d_is_dir(dentry))
30042 + err = au_do_refresh(dentry, /*dir_flags*/0,
30045 + err = au_do_refresh(dentry, dir_flags, parent);
30046 + if (unlikely(err))
30047 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30050 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30051 + AuDbgDentry(dentry);
30057 + au_refresh_dop(dentry, /*force_reval*/0);
30059 + au_refresh_dop(dentry, /*force_reval*/1);
30065 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30067 + int err, i, j, ndentry, e;
30068 + unsigned int sigen;
30069 + struct au_dcsub_pages dpages;
30070 + struct au_dpage *dpage;
30071 + struct dentry **dentries, *d;
30072 + struct au_sbinfo *sbinfo;
30073 + struct dentry *root = sb->s_root;
30074 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30077 + au_refresh_dop(root, /*force_reval*/0);
30079 + err = au_dpages_init(&dpages, GFP_NOFS);
30080 + if (unlikely(err))
30082 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30083 + if (unlikely(err))
30086 + sigen = au_sigen(sb);
30087 + sbinfo = au_sbi(sb);
30088 + for (i = 0; i < dpages.ndpage; i++) {
30089 + dpage = dpages.dpages + i;
30090 + dentries = dpage->dentries;
30091 + ndentry = dpage->ndentry;
30092 + for (j = 0; j < ndentry; j++) {
30094 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30096 + if (unlikely(e && !err))
30098 + /* go on even err */
30103 + au_dpages_free(&dpages);
30108 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30111 + unsigned int sigen;
30112 + unsigned long long max, ull;
30113 + struct inode *inode, **array;
30115 + array = au_iarray_alloc(sb, &max);
30116 + err = PTR_ERR(array);
30117 + if (IS_ERR(array))
30121 + sigen = au_sigen(sb);
30122 + for (ull = 0; ull < max; ull++) {
30123 + inode = array[ull];
30124 + if (unlikely(!inode))
30128 + ii_write_lock_child(inode);
30129 + if (au_iigen(inode, NULL) != sigen) {
30130 + e = au_refresh_hinode_self(inode);
30131 + if (unlikely(e)) {
30132 + au_refresh_iop(inode, /*force_getattr*/1);
30133 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30136 + /* go on even if err */
30139 + if (!e && do_idop)
30140 + au_refresh_iop(inode, /*force_getattr*/0);
30141 + ii_write_unlock(inode);
30144 + au_iarray_free(array, max);
30150 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30153 + unsigned int udba;
30154 + aufs_bindex_t bindex, bbot;
30155 + struct dentry *root;
30156 + struct inode *inode;
30157 + struct au_branch *br;
30158 + struct au_sbinfo *sbi;
30160 + au_sigen_inc(sb);
30161 + sbi = au_sbi(sb);
30162 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30164 + root = sb->s_root;
30165 + DiMustNoWaiters(root);
30166 + inode = d_inode(root);
30167 + IiMustNoWaiters(inode);
30169 + udba = au_opt_udba(sb);
30170 + bbot = au_sbbot(sb);
30171 + for (bindex = 0; bindex <= bbot; bindex++) {
30172 + br = au_sbr(sb, bindex);
30173 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30174 + if (unlikely(err))
30175 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30177 + /* go on even if err */
30179 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30182 + if (au_ftest_si(sbi, NO_DREVAL)) {
30183 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30184 + sb->s_d_op = &aufs_dop_noreval;
30185 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30186 + sbi->si_iop_array = aufs_iop_nogetattr;
30188 + AuDebugOn(sb->s_d_op == &aufs_dop);
30189 + sb->s_d_op = &aufs_dop;
30190 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30191 + sbi->si_iop_array = aufs_iop;
30193 + pr_info("reset to %ps and %ps\n",
30194 + sb->s_d_op, sbi->si_iop_array);
30197 + di_write_unlock(root);
30198 + err = au_refresh_d(sb, do_idop);
30199 + e = au_refresh_i(sb, do_idop);
30200 + if (unlikely(e && !err))
30202 + /* aufs_write_lock() calls ..._child() */
30203 + di_write_lock_child(root);
30205 + au_cpup_attr_all(inode, /*force*/1);
30207 + if (unlikely(err))
30208 + AuIOErr("refresh failed, ignored, %d\n", err);
30211 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30212 +static int cvt_err(int err)
30226 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30229 + unsigned int mntflags;
30230 + struct au_opts opts = {
30233 + struct dentry *root;
30234 + struct inode *inode;
30235 + struct au_sbinfo *sbinfo;
30238 + root = sb->s_root;
30239 + if (!data || !*data) {
30240 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30242 + di_write_lock_child(root);
30243 + err = au_opts_verify(sb, *flags, /*pending*/0);
30244 + aufs_write_unlock(root);
30250 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30251 + if (unlikely(!opts.opt))
30253 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30254 + opts.flags = AuOpts_REMOUNT;
30255 + opts.sb_flags = *flags;
30257 + /* parse it before aufs lock */
30258 + err = au_opts_parse(sb, data, &opts);
30259 + if (unlikely(err))
30262 + sbinfo = au_sbi(sb);
30263 + inode = d_inode(root);
30264 + inode_lock(inode);
30265 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30266 + if (unlikely(err))
30268 + di_write_lock_child(root);
30270 + /* au_opts_remount() may return an error */
30271 + err = au_opts_remount(sb, &opts);
30272 + au_opts_free(&opts);
30274 + if (au_ftest_opts(opts.flags, REFRESH))
30275 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30277 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30278 + mntflags = au_mntflags(sb);
30279 + do_dx = !!au_opt_test(mntflags, DIO);
30280 + au_dy_arefresh(do_dx);
30283 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30284 + aufs_write_unlock(root);
30287 + inode_unlock(inode);
30289 + free_page((unsigned long)opts.opt);
30291 + err = cvt_err(err);
30296 +static const struct super_operations aufs_sop = {
30297 + .alloc_inode = aufs_alloc_inode,
30298 + .destroy_inode = aufs_destroy_inode,
30299 + .free_inode = aufs_free_inode,
30300 + /* always deleting, no clearing */
30301 + .drop_inode = generic_delete_inode,
30302 + .show_options = aufs_show_options,
30303 + .statfs = aufs_statfs,
30304 + .put_super = aufs_put_super,
30305 + .sync_fs = aufs_sync_fs,
30306 + .remount_fs = aufs_remount_fs
30309 +/* ---------------------------------------------------------------------- */
30311 +static int alloc_root(struct super_block *sb)
30314 + struct inode *inode;
30315 + struct dentry *root;
30318 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30319 + err = PTR_ERR(inode);
30320 + if (IS_ERR(inode))
30323 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30324 + inode->i_fop = &aufs_dir_fop;
30325 + inode->i_mode = S_IFDIR;
30326 + set_nlink(inode, 2);
30327 + unlock_new_inode(inode);
30329 + root = d_make_root(inode);
30330 + if (unlikely(!root))
30332 + err = PTR_ERR(root);
30333 + if (IS_ERR(root))
30336 + err = au_di_init(root);
30338 + sb->s_root = root;
30339 + return 0; /* success */
30347 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30348 + int silent __maybe_unused)
30351 + struct au_opts opts = {
30354 + struct au_sbinfo *sbinfo;
30355 + struct dentry *root;
30356 + struct inode *inode;
30357 + char *arg = raw_data;
30359 + if (unlikely(!arg || !*arg)) {
30361 + pr_err("no arg\n");
30366 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30367 + if (unlikely(!opts.opt))
30369 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30370 + opts.sb_flags = sb->s_flags;
30372 + err = au_si_alloc(sb);
30373 + if (unlikely(err))
30375 + sbinfo = au_sbi(sb);
30377 + /* all timestamps always follow the ones on the branch */
30378 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30379 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30380 + sb->s_op = &aufs_sop;
30381 + sb->s_d_op = &aufs_dop;
30382 + sb->s_magic = AUFS_SUPER_MAGIC;
30383 + sb->s_maxbytes = 0;
30384 + sb->s_stack_depth = 1;
30385 + au_export_init(sb);
30386 + au_xattr_init(sb);
30388 + err = alloc_root(sb);
30389 + if (unlikely(err)) {
30390 + si_write_unlock(sb);
30393 + root = sb->s_root;
30394 + inode = d_inode(root);
30397 + * actually we can parse options regardless aufs lock here.
30398 + * but at remount time, parsing must be done before aufs lock.
30399 + * so we follow the same rule.
30401 + ii_write_lock_parent(inode);
30402 + aufs_write_unlock(root);
30403 + err = au_opts_parse(sb, arg, &opts);
30404 + if (unlikely(err))
30407 + /* lock vfs_inode first, then aufs. */
30408 + inode_lock(inode);
30409 + aufs_write_lock(root);
30410 + err = au_opts_mount(sb, &opts);
30411 + au_opts_free(&opts);
30412 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30413 + sb->s_d_op = &aufs_dop_noreval;
30414 + pr_info("%ps\n", sb->s_d_op);
30415 + au_refresh_dop(root, /*force_reval*/0);
30416 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30417 + au_refresh_iop(inode, /*force_getattr*/0);
30419 + aufs_write_unlock(root);
30420 + inode_unlock(inode);
30422 + goto out_opts; /* success */
30426 + sb->s_root = NULL;
30428 + kobject_put(&sbinfo->si_kobj);
30429 + sb->s_fs_info = NULL;
30431 + free_page((unsigned long)opts.opt);
30434 + err = cvt_err(err);
30439 +/* ---------------------------------------------------------------------- */
30441 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30442 + const char *dev_name __maybe_unused,
30445 + struct dentry *root;
30447 + /* all timestamps always follow the ones on the branch */
30448 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30449 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30450 + if (IS_ERR(root))
30453 + au_sbilist_add(root->d_sb);
30459 +static void aufs_kill_sb(struct super_block *sb)
30461 + struct au_sbinfo *sbinfo;
30463 + sbinfo = au_sbi(sb);
30465 + au_sbilist_del(sb);
30466 + aufs_write_lock(sb->s_root);
30468 + if (sbinfo->si_wbr_create_ops->fin)
30469 + sbinfo->si_wbr_create_ops->fin(sb);
30470 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30471 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30472 + au_remount_refresh(sb, /*do_idop*/0);
30474 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30475 + au_plink_put(sb, /*verbose*/1);
30477 + au_dr_opt_flush(sb);
30478 + sbinfo->si_sb = NULL;
30479 + aufs_write_unlock(sb->s_root);
30480 + au_nwt_flush(&sbinfo->si_nowait);
30482 + kill_anon_super(sb);
30485 +struct file_system_type aufs_fs_type = {
30486 + .name = AUFS_FSTYPE,
30487 + /* a race between rename and others */
30488 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30489 + .mount = aufs_mount,
30490 + .kill_sb = aufs_kill_sb,
30491 + /* no need to __module_get() and module_put(). */
30492 + .owner = THIS_MODULE,
30494 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30495 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30496 +++ linux/fs/aufs/super.h 2020-01-27 10:57:18.178871751 +0100
30498 +/* SPDX-License-Identifier: GPL-2.0 */
30500 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30502 + * This program, aufs is free software; you can redistribute it and/or modify
30503 + * it under the terms of the GNU General Public License as published by
30504 + * the Free Software Foundation; either version 2 of the License, or
30505 + * (at your option) any later version.
30507 + * This program is distributed in the hope that it will be useful,
30508 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30509 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30510 + * GNU General Public License for more details.
30512 + * You should have received a copy of the GNU General Public License
30513 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30517 + * super_block operations
30520 +#ifndef __AUFS_SUPER_H__
30521 +#define __AUFS_SUPER_H__
30525 +#include <linux/fs.h>
30526 +#include <linux/kobject.h>
30529 +#include "rwsem.h"
30532 +/* policies to select one among multiple writable branches */
30533 +struct au_wbr_copyup_operations {
30534 + int (*copyup)(struct dentry *dentry);
30537 +#define AuWbr_DIR 1 /* target is a dir */
30538 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30540 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30541 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30542 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30544 +struct au_wbr_create_operations {
30545 + int (*create)(struct dentry *dentry, unsigned int flags);
30546 + int (*init)(struct super_block *sb);
30547 + int (*fin)(struct super_block *sb);
30550 +struct au_wbr_mfs {
30551 + struct mutex mfs_lock; /* protect this structure */
30552 + unsigned long mfs_jiffy;
30553 + unsigned long mfs_expire;
30554 + aufs_bindex_t mfs_bindex;
30556 + unsigned long long mfsrr_bytes;
30557 + unsigned long long mfsrr_watermark;
30560 +#define AuPlink_NHASH 100
30561 +static inline int au_plink_hash(ino_t ino)
30563 + return ino % AuPlink_NHASH;
30566 +/* File-based Hierarchical Storage Management */
30568 +#ifdef CONFIG_AUFS_FHSM
30569 + /* allow only one process who can receive the notification */
30570 + spinlock_t fhsm_spin;
30572 + wait_queue_head_t fhsm_wqh;
30573 + atomic_t fhsm_readable;
30575 + /* these are protected by si_rwsem */
30576 + unsigned long fhsm_expire;
30577 + aufs_bindex_t fhsm_bottom;
30582 +struct au_sbinfo {
30583 + /* nowait tasks in the system-wide workqueue */
30584 + struct au_nowait_tasks si_nowait;
30587 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30588 + * rwsem for au_sbinfo is necessary.
30590 + struct au_rwsem si_rwsem;
30593 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30596 + au_lcnt_t si_ninodes, si_nfiles;
30598 + /* branch management */
30599 + unsigned int si_generation;
30601 + /* see AuSi_ flags */
30602 + unsigned char au_si_status;
30604 + aufs_bindex_t si_bbot;
30606 + /* dirty trick to keep br_id plus */
30607 + unsigned int si_last_br_id :
30608 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30609 + struct au_branch **si_branch;
30611 + /* policy to select a writable branch */
30612 + unsigned char si_wbr_copyup;
30613 + unsigned char si_wbr_create;
30614 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30615 + struct au_wbr_create_operations *si_wbr_create_ops;
30617 + /* round robin */
30618 + atomic_t si_wbr_rr_next;
30620 + /* most free space */
30621 + struct au_wbr_mfs si_wbr_mfs;
30623 + /* File-based Hierarchical Storage Management */
30624 + struct au_fhsm si_fhsm;
30626 + /* mount flags */
30627 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30628 + unsigned int si_mntflags;
30630 + /* external inode number (bitmap and translation table) */
30631 + vfs_readf_t si_xread;
30632 + vfs_writef_t si_xwrite;
30633 + loff_t si_ximaxent; /* max entries in a xino */
30635 + struct file *si_xib;
30636 + struct mutex si_xib_mtx; /* protect xib members */
30637 + unsigned long *si_xib_buf;
30638 + unsigned long si_xib_last_pindex;
30639 + int si_xib_next_bit;
30641 + unsigned long si_xino_jiffy;
30642 + unsigned long si_xino_expire;
30643 + /* reserved for future use */
30644 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30646 +#ifdef CONFIG_AUFS_EXPORT
30647 + /* i_generation */
30648 + /* todo: make xigen file an array to support many inode numbers */
30649 + struct file *si_xigen;
30650 + atomic_t si_xigen_next;
30653 + /* dirty trick to support atomic_open */
30654 + struct hlist_bl_head si_aopen;
30656 + /* vdir parameters */
30657 + unsigned long si_rdcache; /* max cache time in jiffies */
30658 + unsigned int si_rdblk; /* deblk size */
30659 + unsigned int si_rdhash; /* hash size */
30662 + * If the number of whiteouts are larger than si_dirwh, leave all of
30663 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30664 + * future fsck.aufs or kernel thread will remove them later.
30665 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30667 + unsigned int si_dirwh;
30669 + /* pseudo_link list */
30670 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30671 + wait_queue_head_t si_plink_wq;
30672 + spinlock_t si_plink_maint_lock;
30673 + pid_t si_plink_maint_pid;
30676 + struct hlist_bl_head si_files;
30678 + /* with/without getattr, brother of sb->s_d_op */
30679 + const struct inode_operations *si_iop_array;
30682 + * sysfs and lifetime management.
30683 + * this is not a small structure and it may be a waste of memory in case
30684 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30685 + * but using sysfs is majority.
30687 + struct kobject si_kobj;
30688 +#ifdef CONFIG_DEBUG_FS
30689 + struct dentry *si_dbgaufs;
30690 + struct dentry *si_dbgaufs_plink;
30691 + struct dentry *si_dbgaufs_xib;
30692 +#ifdef CONFIG_AUFS_EXPORT
30693 + struct dentry *si_dbgaufs_xigen;
30697 +#ifdef CONFIG_AUFS_SBILIST
30698 + struct hlist_bl_node si_list;
30701 + /* dirty, necessary for unmounting, sysfs and sysrq */
30702 + struct super_block *si_sb;
30705 +/* sbinfo status flags */
30707 + * set true when refresh_dirs() failed at remount time.
30708 + * then try refreshing dirs at access time again.
30709 + * if it is false, refreshing dirs at access time is unnecessary
30711 +#define AuSi_FAILED_REFRESH_DIR 1
30712 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30713 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30715 +#ifndef CONFIG_AUFS_FHSM
30717 +#define AuSi_FHSM 0
30720 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30721 + unsigned int flag)
30723 + AuRwMustAnyLock(&sbi->si_rwsem);
30724 + return sbi->au_si_status & flag;
30726 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30727 +#define au_fset_si(sbinfo, name) do { \
30728 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30729 + (sbinfo)->au_si_status |= AuSi_##name; \
30731 +#define au_fclr_si(sbinfo, name) do { \
30732 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30733 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30736 +/* ---------------------------------------------------------------------- */
30738 +/* policy to select one among writable branches */
30739 +#define AuWbrCopyup(sbinfo, ...) \
30740 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30741 +#define AuWbrCreate(sbinfo, ...) \
30742 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30744 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30745 +#define AuLock_DW 1 /* write-lock dentry */
30746 +#define AuLock_IR (1 << 1) /* read-lock inode */
30747 +#define AuLock_IW (1 << 2) /* write-lock inode */
30748 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30749 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30750 + /* except RENAME_EXCHANGE */
30751 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30752 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30753 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30754 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30755 +#define au_fset_lock(flags, name) \
30756 + do { (flags) |= AuLock_##name; } while (0)
30757 +#define au_fclr_lock(flags, name) \
30758 + do { (flags) &= ~AuLock_##name; } while (0)
30760 +/* ---------------------------------------------------------------------- */
30763 +extern struct file_system_type aufs_fs_type;
30764 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30765 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30766 + unsigned long long max, void *arg);
30767 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30768 + struct super_block *sb, void *arg);
30769 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30770 +void au_iarray_free(struct inode **a, unsigned long long max);
30773 +void au_si_free(struct kobject *kobj);
30774 +int au_si_alloc(struct super_block *sb);
30775 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30777 +unsigned int au_sigen_inc(struct super_block *sb);
30778 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30780 +int si_read_lock(struct super_block *sb, int flags);
30781 +int si_write_lock(struct super_block *sb, int flags);
30782 +int aufs_read_lock(struct dentry *dentry, int flags);
30783 +void aufs_read_unlock(struct dentry *dentry, int flags);
30784 +void aufs_write_lock(struct dentry *dentry);
30785 +void aufs_write_unlock(struct dentry *dentry);
30786 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30787 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30789 +/* wbr_policy.c */
30790 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30791 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30792 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30793 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30794 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30797 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30799 +#ifdef CONFIG_AUFS_FHSM
30802 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30806 + spin_lock(&fhsm->fhsm_spin);
30807 + pid = fhsm->fhsm_pid;
30808 + spin_unlock(&fhsm->fhsm_spin);
30813 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30814 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30815 +int au_fhsm_fd(struct super_block *sb, int oflags);
30816 +int au_fhsm_br_alloc(struct au_branch *br);
30817 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30818 +void au_fhsm_fin(struct super_block *sb);
30819 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30820 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30821 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30823 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30825 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30826 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30827 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30828 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30829 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30830 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30831 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30832 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30833 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30836 +/* ---------------------------------------------------------------------- */
30838 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30840 + return sb->s_fs_info;
30843 +/* ---------------------------------------------------------------------- */
30845 +#ifdef CONFIG_AUFS_EXPORT
30846 +int au_test_nfsd(void);
30847 +void au_export_init(struct super_block *sb);
30848 +void au_xigen_inc(struct inode *inode);
30849 +int au_xigen_new(struct inode *inode);
30850 +int au_xigen_set(struct super_block *sb, struct path *path);
30851 +void au_xigen_clr(struct super_block *sb);
30853 +static inline int au_busy_or_stale(void)
30855 + if (!au_test_nfsd())
30860 +AuStubInt0(au_test_nfsd, void)
30861 +AuStubVoid(au_export_init, struct super_block *sb)
30862 +AuStubVoid(au_xigen_inc, struct inode *inode)
30863 +AuStubInt0(au_xigen_new, struct inode *inode)
30864 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30865 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30866 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30867 +#endif /* CONFIG_AUFS_EXPORT */
30869 +/* ---------------------------------------------------------------------- */
30871 +#ifdef CONFIG_AUFS_SBILIST
30873 +extern struct hlist_bl_head au_sbilist;
30875 +static inline void au_sbilist_init(void)
30877 + INIT_HLIST_BL_HEAD(&au_sbilist);
30880 +static inline void au_sbilist_add(struct super_block *sb)
30882 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30885 +static inline void au_sbilist_del(struct super_block *sb)
30887 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30890 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30891 +static inline void au_sbilist_lock(void)
30893 + hlist_bl_lock(&au_sbilist);
30896 +static inline void au_sbilist_unlock(void)
30898 + hlist_bl_unlock(&au_sbilist);
30900 +#define AuGFP_SBILIST GFP_ATOMIC
30902 +AuStubVoid(au_sbilist_lock, void)
30903 +AuStubVoid(au_sbilist_unlock, void)
30904 +#define AuGFP_SBILIST GFP_NOFS
30905 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30907 +AuStubVoid(au_sbilist_init, void)
30908 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30909 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30910 +AuStubVoid(au_sbilist_lock, void)
30911 +AuStubVoid(au_sbilist_unlock, void)
30912 +#define AuGFP_SBILIST GFP_NOFS
30915 +/* ---------------------------------------------------------------------- */
30917 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30920 + * This function is a dynamic '__init' function actually,
30921 + * so the tiny check for si_rwsem is unnecessary.
30923 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30924 +#ifdef CONFIG_DEBUG_FS
30925 + sbinfo->si_dbgaufs = NULL;
30926 + sbinfo->si_dbgaufs_plink = NULL;
30927 + sbinfo->si_dbgaufs_xib = NULL;
30928 +#ifdef CONFIG_AUFS_EXPORT
30929 + sbinfo->si_dbgaufs_xigen = NULL;
30934 +/* ---------------------------------------------------------------------- */
30936 +/* current->atomic_flags */
30937 +/* this value should never corrupt the ones defined in linux/sched.h */
30938 +#define PFA_AUFS 0x10
30940 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30941 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30942 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30944 +static inline int si_pid_test(struct super_block *sb)
30946 + return !!task_test_aufs(current);
30949 +static inline void si_pid_clr(struct super_block *sb)
30951 + AuDebugOn(!task_test_aufs(current));
30952 + task_clear_aufs(current);
30955 +static inline void si_pid_set(struct super_block *sb)
30957 + AuDebugOn(task_test_aufs(current));
30958 + task_set_aufs(current);
30961 +/* ---------------------------------------------------------------------- */
30963 +/* lock superblock. mainly for entry point functions */
30964 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30965 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30966 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30967 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30969 +#define __si_read_trylock_nested(sb) \
30970 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30971 +#define __si_write_trylock_nested(sb) \
30972 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30975 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30976 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30977 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30979 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30980 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30981 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30983 +static inline void si_noflush_read_lock(struct super_block *sb)
30985 + __si_read_lock(sb);
30989 +static inline int si_noflush_read_trylock(struct super_block *sb)
30993 + locked = __si_read_trylock(sb);
30999 +static inline void si_noflush_write_lock(struct super_block *sb)
31001 + __si_write_lock(sb);
31005 +static inline int si_noflush_write_trylock(struct super_block *sb)
31009 + locked = __si_write_trylock(sb);
31015 +#if 0 /* reserved */
31016 +static inline int si_read_trylock(struct super_block *sb, int flags)
31018 + if (au_ftest_lock(flags, FLUSH))
31019 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31020 + return si_noflush_read_trylock(sb);
31024 +static inline void si_read_unlock(struct super_block *sb)
31027 + __si_read_unlock(sb);
31030 +#if 0 /* reserved */
31031 +static inline int si_write_trylock(struct super_block *sb, int flags)
31033 + if (au_ftest_lock(flags, FLUSH))
31034 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31035 + return si_noflush_write_trylock(sb);
31039 +static inline void si_write_unlock(struct super_block *sb)
31042 + __si_write_unlock(sb);
31045 +#if 0 /* reserved */
31046 +static inline void si_downgrade_lock(struct super_block *sb)
31048 + __si_downgrade_lock(sb);
31052 +/* ---------------------------------------------------------------------- */
31054 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31056 + SiMustAnyLock(sb);
31057 + return au_sbi(sb)->si_bbot;
31060 +static inline unsigned int au_mntflags(struct super_block *sb)
31062 + SiMustAnyLock(sb);
31063 + return au_sbi(sb)->si_mntflags;
31066 +static inline unsigned int au_sigen(struct super_block *sb)
31068 + SiMustAnyLock(sb);
31069 + return au_sbi(sb)->si_generation;
31072 +static inline struct au_branch *au_sbr(struct super_block *sb,
31073 + aufs_bindex_t bindex)
31075 + SiMustAnyLock(sb);
31076 + return au_sbi(sb)->si_branch[0 + bindex];
31079 +static inline loff_t au_xi_maxent(struct super_block *sb)
31081 + SiMustAnyLock(sb);
31082 + return au_sbi(sb)->si_ximaxent;
31085 +#endif /* __KERNEL__ */
31086 +#endif /* __AUFS_SUPER_H__ */
31087 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31088 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31089 +++ linux/fs/aufs/sysaufs.c 2020-01-27 10:57:18.178871751 +0100
31091 +// SPDX-License-Identifier: GPL-2.0
31093 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31095 + * This program, aufs is free software; you can redistribute it and/or modify
31096 + * it under the terms of the GNU General Public License as published by
31097 + * the Free Software Foundation; either version 2 of the License, or
31098 + * (at your option) any later version.
31100 + * This program is distributed in the hope that it will be useful,
31101 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31102 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31103 + * GNU General Public License for more details.
31105 + * You should have received a copy of the GNU General Public License
31106 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31110 + * sysfs interface and lifetime management
31111 + * they are necessary regardless sysfs is disabled.
31114 +#include <linux/random.h>
31117 +unsigned long sysaufs_si_mask;
31118 +struct kset *sysaufs_kset;
31120 +#define AuSiAttr(_name) { \
31121 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31122 + .show = sysaufs_si_##_name, \
31125 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31126 +struct attribute *sysaufs_si_attrs[] = {
31127 + &sysaufs_si_attr_xi_path.attr,
31131 +static const struct sysfs_ops au_sbi_ops = {
31132 + .show = sysaufs_si_show
31135 +static struct kobj_type au_sbi_ktype = {
31136 + .release = au_si_free,
31137 + .sysfs_ops = &au_sbi_ops,
31138 + .default_attrs = sysaufs_si_attrs
31141 +/* ---------------------------------------------------------------------- */
31143 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31147 + sbinfo->si_kobj.kset = sysaufs_kset;
31148 + /* cf. sysaufs_name() */
31149 + err = kobject_init_and_add
31150 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31151 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31156 +void sysaufs_fin(void)
31158 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31159 + kset_unregister(sysaufs_kset);
31162 +int __init sysaufs_init(void)
31167 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31168 + } while (!sysaufs_si_mask);
31171 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31172 + if (unlikely(!sysaufs_kset))
31174 + err = PTR_ERR(sysaufs_kset);
31175 + if (IS_ERR(sysaufs_kset))
31177 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31178 + if (unlikely(err))
31179 + kset_unregister(sysaufs_kset);
31184 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31185 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31186 +++ linux/fs/aufs/sysaufs.h 2020-01-27 10:57:18.178871751 +0100
31188 +/* SPDX-License-Identifier: GPL-2.0 */
31190 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31192 + * This program, aufs is free software; you can redistribute it and/or modify
31193 + * it under the terms of the GNU General Public License as published by
31194 + * the Free Software Foundation; either version 2 of the License, or
31195 + * (at your option) any later version.
31197 + * This program is distributed in the hope that it will be useful,
31198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31200 + * GNU General Public License for more details.
31202 + * You should have received a copy of the GNU General Public License
31203 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31207 + * sysfs interface and mount lifetime management
31210 +#ifndef __SYSAUFS_H__
31211 +#define __SYSAUFS_H__
31215 +#include <linux/sysfs.h>
31216 +#include "module.h"
31218 +struct super_block;
31221 +struct sysaufs_si_attr {
31222 + struct attribute attr;
31223 + int (*show)(struct seq_file *seq, struct super_block *sb);
31226 +/* ---------------------------------------------------------------------- */
31229 +extern unsigned long sysaufs_si_mask;
31230 +extern struct kset *sysaufs_kset;
31231 +extern struct attribute *sysaufs_si_attrs[];
31232 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31233 +int __init sysaufs_init(void);
31234 +void sysaufs_fin(void);
31236 +/* ---------------------------------------------------------------------- */
31238 +/* some people doesn't like to show a pointer in kernel */
31239 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31241 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31244 +#define SysaufsSiNamePrefix "si_"
31245 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31246 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31248 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31249 + sysaufs_si_id(sbinfo));
31253 +#ifdef CONFIG_SYSFS
31255 +extern struct attribute_group *sysaufs_attr_group;
31257 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31258 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31260 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31261 +#ifdef CONFIG_COMPAT
31262 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31265 +void sysaufs_br_init(struct au_branch *br);
31266 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31267 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31269 +#define sysaufs_brs_init() do {} while (0)
31272 +#define sysaufs_attr_group NULL
31274 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31275 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31276 + struct attribute *attr, char *buf)
31277 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31278 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31279 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31281 +static inline void sysaufs_brs_init(void)
31286 +#endif /* CONFIG_SYSFS */
31288 +#endif /* __KERNEL__ */
31289 +#endif /* __SYSAUFS_H__ */
31290 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31291 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31292 +++ linux/fs/aufs/sysfs.c 2020-01-27 10:57:18.178871751 +0100
31294 +// SPDX-License-Identifier: GPL-2.0
31296 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31298 + * This program, aufs is free software; you can redistribute it and/or modify
31299 + * it under the terms of the GNU General Public License as published by
31300 + * the Free Software Foundation; either version 2 of the License, or
31301 + * (at your option) any later version.
31303 + * This program is distributed in the hope that it will be useful,
31304 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31305 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31306 + * GNU General Public License for more details.
31308 + * You should have received a copy of the GNU General Public License
31309 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31313 + * sysfs interface
31316 +#include <linux/compat.h>
31317 +#include <linux/seq_file.h>
31320 +#ifdef CONFIG_AUFS_FS_MODULE
31321 +/* this entry violates the "one line per file" policy of sysfs */
31322 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31326 + static char *conf =
31327 +/* this file is generated at compiling */
31328 +#include "conf.str"
31331 + err = snprintf(buf, PAGE_SIZE, conf);
31332 + if (unlikely(err >= PAGE_SIZE))
31337 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31340 +static struct attribute *au_attr[] = {
31341 +#ifdef CONFIG_AUFS_FS_MODULE
31342 + &au_config_attr.attr,
31344 + NULL, /* need to NULL terminate the list of attributes */
31347 +static struct attribute_group sysaufs_attr_group_body = {
31351 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31353 +/* ---------------------------------------------------------------------- */
31355 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31359 + SiMustAnyLock(sb);
31362 + if (au_opt_test(au_mntflags(sb), XINO)) {
31363 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31364 + seq_putc(seq, '\n');
31370 + * the lifetime of branch is independent from the entry under sysfs.
31371 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31374 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31375 + aufs_bindex_t bindex, int idx)
31378 + struct path path;
31379 + struct dentry *root;
31380 + struct au_branch *br;
31381 + au_br_perm_str_t perm;
31383 + AuDbg("b%d\n", bindex);
31386 + root = sb->s_root;
31387 + di_read_lock_parent(root, !AuLock_IR);
31388 + br = au_sbr(sb, bindex);
31391 + case AuBrSysfs_BR:
31392 + path.mnt = au_br_mnt(br);
31393 + path.dentry = au_h_dptr(root, bindex);
31394 + err = au_seq_path(seq, &path);
31396 + au_optstr_br_perm(&perm, br->br_perm);
31397 + seq_printf(seq, "=%s\n", perm.a);
31400 + case AuBrSysfs_BRID:
31401 + seq_printf(seq, "%d\n", br->br_id);
31404 + di_read_unlock(root, !AuLock_IR);
31405 + if (unlikely(err || seq_has_overflowed(seq)))
31411 +/* ---------------------------------------------------------------------- */
31413 +static struct seq_file *au_seq(char *p, ssize_t len)
31415 + struct seq_file *seq;
31417 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31419 + /* mutex_init(&seq.lock); */
31422 + return seq; /* success */
31425 + seq = ERR_PTR(-ENOMEM);
31429 +#define SysaufsBr_PREFIX "br"
31430 +#define SysaufsBrid_PREFIX "brid"
31432 +/* todo: file size may exceed PAGE_SIZE */
31433 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31439 + aufs_bindex_t bbot;
31440 + struct au_sbinfo *sbinfo;
31441 + struct super_block *sb;
31442 + struct seq_file *seq;
31444 + struct attribute **cattr;
31446 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31447 + sb = sbinfo->si_sb;
31450 + * prevent a race condition between sysfs and aufs.
31451 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31452 + * prohibits maintaining the sysfs entries.
31453 + * hew we acquire read lock after sysfs_get_active_two().
31454 + * on the other hand, the remount process may maintain the sysfs/aufs
31455 + * entries after acquiring write lock.
31456 + * it can cause a deadlock.
31457 + * simply we gave up processing read here.
31460 + if (unlikely(!si_noflush_read_trylock(sb)))
31463 + seq = au_seq(buf, PAGE_SIZE);
31464 + err = PTR_ERR(seq);
31468 + name = (void *)attr->name;
31469 + cattr = sysaufs_si_attrs;
31471 + if (!strcmp(name, (*cattr)->name)) {
31472 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31479 + if (!strncmp(name, SysaufsBrid_PREFIX,
31480 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31481 + idx = AuBrSysfs_BRID;
31482 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31483 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31484 + sizeof(SysaufsBr_PREFIX) - 1)) {
31485 + idx = AuBrSysfs_BR;
31486 + name += sizeof(SysaufsBr_PREFIX) - 1;
31490 + err = kstrtol(name, 10, &l);
31492 + bbot = au_sbbot(sb);
31494 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31501 + err = seq->count;
31502 + /* sysfs limit */
31503 + if (unlikely(err == PAGE_SIZE))
31506 + au_kfree_rcu(seq);
31508 + si_read_unlock(sb);
31513 +/* ---------------------------------------------------------------------- */
31515 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31519 + aufs_bindex_t bindex, bbot;
31522 + struct seq_file *seq;
31523 + struct au_branch *br;
31525 + si_read_lock(sb, AuLock_FLUSH);
31526 + bbot = au_sbbot(sb);
31532 + buf = (void *)__get_free_page(GFP_NOFS);
31533 + if (unlikely(!buf))
31536 + seq = au_seq(buf, PAGE_SIZE);
31537 + err = PTR_ERR(seq);
31541 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31542 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31543 + /* VERIFY_WRITE */
31544 + err = !access_ok(arg, sizeof(*arg));
31545 + if (unlikely(err))
31548 + br = au_sbr(sb, bindex);
31549 + brid = br->br_id;
31550 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31551 + err = __put_user(brid, &arg->id);
31552 + if (unlikely(err))
31555 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31556 + err = __put_user(br->br_perm, &arg->perm);
31557 + if (unlikely(err))
31560 + err = au_seq_path(seq, &br->br_path);
31561 + if (unlikely(err))
31563 + seq_putc(seq, '\0');
31564 + if (!seq_has_overflowed(seq)) {
31565 + err = copy_to_user(arg->path, seq->buf, seq->count);
31567 + if (unlikely(err))
31574 + if (unlikely(err))
31578 + au_kfree_rcu(seq);
31580 + free_page((unsigned long)buf);
31582 + si_read_unlock(sb);
31586 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31588 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31591 +#ifdef CONFIG_COMPAT
31592 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31594 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31598 +/* ---------------------------------------------------------------------- */
31600 +void sysaufs_br_init(struct au_branch *br)
31603 + struct au_brsysfs *br_sysfs;
31604 + struct attribute *attr;
31606 + br_sysfs = br->br_sysfs;
31607 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31608 + attr = &br_sysfs->attr;
31609 + sysfs_attr_init(attr);
31610 + attr->name = br_sysfs->name;
31611 + attr->mode = 0444;
31616 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31618 + struct au_branch *br;
31619 + struct kobject *kobj;
31620 + struct au_brsysfs *br_sysfs;
31622 + aufs_bindex_t bbot;
31624 + if (!sysaufs_brs)
31627 + kobj = &au_sbi(sb)->si_kobj;
31628 + bbot = au_sbbot(sb);
31629 + for (; bindex <= bbot; bindex++) {
31630 + br = au_sbr(sb, bindex);
31631 + br_sysfs = br->br_sysfs;
31632 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31633 + sysfs_remove_file(kobj, &br_sysfs->attr);
31639 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31642 + aufs_bindex_t bbot;
31643 + struct kobject *kobj;
31644 + struct au_branch *br;
31645 + struct au_brsysfs *br_sysfs;
31647 + if (!sysaufs_brs)
31650 + kobj = &au_sbi(sb)->si_kobj;
31651 + bbot = au_sbbot(sb);
31652 + for (; bindex <= bbot; bindex++) {
31653 + br = au_sbr(sb, bindex);
31654 + br_sysfs = br->br_sysfs;
31655 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31656 + SysaufsBr_PREFIX "%d", bindex);
31657 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31658 + SysaufsBrid_PREFIX "%d", bindex);
31659 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31660 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31661 + if (unlikely(err))
31662 + pr_warn("failed %s under sysfs(%d)\n",
31663 + br_sysfs->name, err);
31668 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31669 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31670 +++ linux/fs/aufs/sysrq.c 2020-01-27 10:57:18.178871751 +0100
31672 +// SPDX-License-Identifier: GPL-2.0
31674 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31676 + * This program, aufs is free software; you can redistribute it and/or modify
31677 + * it under the terms of the GNU General Public License as published by
31678 + * the Free Software Foundation; either version 2 of the License, or
31679 + * (at your option) any later version.
31681 + * This program is distributed in the hope that it will be useful,
31682 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31683 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31684 + * GNU General Public License for more details.
31686 + * You should have received a copy of the GNU General Public License
31687 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31691 + * magic sysrq handler
31694 +/* #include <linux/sysrq.h> */
31695 +#include <linux/writeback.h>
31698 +/* ---------------------------------------------------------------------- */
31700 +static void sysrq_sb(struct super_block *sb)
31703 + struct au_sbinfo *sbinfo;
31704 + struct file *file;
31705 + struct hlist_bl_head *files;
31706 + struct hlist_bl_node *pos;
31707 + struct au_finfo *finfo;
31710 + plevel = au_plevel;
31711 + au_plevel = KERN_WARNING;
31713 + /* since we define pr_fmt, call printk directly */
31714 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31716 + sbinfo = au_sbi(sb);
31717 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31718 + pr("superblock\n");
31721 +#if 0 /* reserved */
31723 + int err, i, j, ndentry;
31724 + struct au_dcsub_pages dpages;
31725 + struct au_dpage *dpage;
31727 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31728 + if (unlikely(err))
31730 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31732 + for (i = 0; i < dpages.ndpage; i++) {
31733 + dpage = dpages.dpages + i;
31734 + ndentry = dpage->ndentry;
31735 + for (j = 0; j < ndentry; j++)
31736 + au_dpri_dentry(dpage->dentries[j]);
31738 + au_dpages_free(&dpages);
31742 + pr("isolated inode\n");
31743 + spin_lock(&sb->s_inode_list_lock);
31744 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31745 + spin_lock(&i->i_lock);
31746 + if (hlist_empty(&i->i_dentry))
31747 + au_dpri_inode(i);
31748 + spin_unlock(&i->i_lock);
31750 + spin_unlock(&sb->s_inode_list_lock);
31753 + files = &au_sbi(sb)->si_files;
31754 + hlist_bl_lock(files);
31755 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31758 + file = finfo->fi_file;
31759 + mode = file_inode(file)->i_mode;
31760 + if (!special_file(mode))
31761 + au_dpri_file(file);
31763 + hlist_bl_unlock(files);
31767 + au_plevel = plevel;
31770 +/* ---------------------------------------------------------------------- */
31772 +/* module parameter */
31773 +static char *aufs_sysrq_key = "a";
31774 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31775 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31777 +static void au_sysrq(int key __maybe_unused)
31779 + struct au_sbinfo *sbinfo;
31780 + struct hlist_bl_node *pos;
31783 + au_sbilist_lock();
31784 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31785 + sysrq_sb(sbinfo->si_sb);
31786 + au_sbilist_unlock();
31790 +static struct sysrq_key_op au_sysrq_op = {
31791 + .handler = au_sysrq,
31792 + .help_msg = "Aufs",
31793 + .action_msg = "Aufs",
31794 + .enable_mask = SYSRQ_ENABLE_DUMP
31797 +/* ---------------------------------------------------------------------- */
31799 +int __init au_sysrq_init(void)
31805 + key = *aufs_sysrq_key;
31806 + if ('a' <= key && key <= 'z')
31807 + err = register_sysrq_key(key, &au_sysrq_op);
31808 + if (unlikely(err))
31809 + pr_err("err %d, sysrq=%c\n", err, key);
31813 +void au_sysrq_fin(void)
31817 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31818 + if (unlikely(err))
31819 + pr_err("err %d (ignored)\n", err);
31821 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31822 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31823 +++ linux/fs/aufs/vdir.c 2020-01-27 10:57:18.178871751 +0100
31825 +// SPDX-License-Identifier: GPL-2.0
31827 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31829 + * This program, aufs is free software; you can redistribute it and/or modify
31830 + * it under the terms of the GNU General Public License as published by
31831 + * the Free Software Foundation; either version 2 of the License, or
31832 + * (at your option) any later version.
31834 + * This program is distributed in the hope that it will be useful,
31835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31837 + * GNU General Public License for more details.
31839 + * You should have received a copy of the GNU General Public License
31840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31844 + * virtual or vertical directory
31847 +#include <linux/iversion.h>
31850 +static unsigned int calc_size(int nlen)
31852 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31855 +static int set_deblk_end(union au_vdir_deblk_p *p,
31856 + union au_vdir_deblk_p *deblk_end)
31858 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31859 + p->de->de_str.len = 0;
31863 + return -1; /* error */
31866 +/* returns true or false */
31867 +static int is_deblk_end(union au_vdir_deblk_p *p,
31868 + union au_vdir_deblk_p *deblk_end)
31870 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31871 + return !p->de->de_str.len;
31875 +static unsigned char *last_deblk(struct au_vdir *vdir)
31877 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31880 +/* ---------------------------------------------------------------------- */
31882 +/* estimate the appropriate size for name hash table */
31883 +unsigned int au_rdhash_est(loff_t sz)
31891 + if (sz < AUFS_RDHASH_DEF)
31892 + n = AUFS_RDHASH_DEF;
31893 + /* pr_info("n %u\n", n); */
31898 + * the allocated memory has to be freed by
31899 + * au_nhash_wh_free() or au_nhash_de_free().
31901 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31903 + struct hlist_head *head;
31907 + sz = sizeof(*nhash->nh_head) * num_hash;
31908 + head = kmalloc(sz, gfp);
31910 + nhash->nh_num = num_hash;
31911 + nhash->nh_head = head;
31912 + for (u = 0; u < num_hash; u++)
31913 + INIT_HLIST_HEAD(head++);
31914 + return 0; /* success */
31920 +static void nhash_count(struct hlist_head *head)
31922 +#if 0 /* debugging */
31924 + struct hlist_node *pos;
31927 + hlist_for_each(pos, head)
31929 + pr_info("%lu\n", n);
31933 +static void au_nhash_wh_do_free(struct hlist_head *head)
31935 + struct au_vdir_wh *pos;
31936 + struct hlist_node *node;
31938 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31939 + au_kfree_rcu(pos);
31942 +static void au_nhash_de_do_free(struct hlist_head *head)
31944 + struct au_vdir_dehstr *pos;
31945 + struct hlist_node *node;
31947 + hlist_for_each_entry_safe(pos, node, head, hash)
31948 + au_cache_free_vdir_dehstr(pos);
31951 +static void au_nhash_do_free(struct au_nhash *nhash,
31952 + void (*free)(struct hlist_head *head))
31955 + struct hlist_head *head;
31957 + n = nhash->nh_num;
31961 + head = nhash->nh_head;
31962 + while (n-- > 0) {
31963 + nhash_count(head);
31966 + au_kfree_try_rcu(nhash->nh_head);
31969 +void au_nhash_wh_free(struct au_nhash *whlist)
31971 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31974 +static void au_nhash_de_free(struct au_nhash *delist)
31976 + au_nhash_do_free(delist, au_nhash_de_do_free);
31979 +/* ---------------------------------------------------------------------- */
31981 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31985 + unsigned int u, n;
31986 + struct hlist_head *head;
31987 + struct au_vdir_wh *pos;
31990 + n = whlist->nh_num;
31991 + head = whlist->nh_head;
31992 + for (u = 0; u < n; u++, head++)
31993 + hlist_for_each_entry(pos, head, wh_hash)
31994 + if (pos->wh_bindex == btgt && ++num > limit)
31999 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32000 + unsigned char *name,
32001 + unsigned int len)
32004 + /* const unsigned int magic_bit = 12; */
32006 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32013 + /* v = hash_long(v, magic_bit); */
32014 + v %= nhash->nh_num;
32015 + return nhash->nh_head + v;
32018 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32021 + return str->len == nlen && !memcmp(str->name, name, nlen);
32024 +/* returns found or not */
32025 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32027 + struct hlist_head *head;
32028 + struct au_vdir_wh *pos;
32029 + struct au_vdir_destr *str;
32031 + head = au_name_hash(whlist, name, nlen);
32032 + hlist_for_each_entry(pos, head, wh_hash) {
32033 + str = &pos->wh_str;
32034 + AuDbg("%.*s\n", str->len, str->name);
32035 + if (au_nhash_test_name(str, name, nlen))
32041 +/* returns found(true) or not */
32042 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32044 + struct hlist_head *head;
32045 + struct au_vdir_dehstr *pos;
32046 + struct au_vdir_destr *str;
32048 + head = au_name_hash(delist, name, nlen);
32049 + hlist_for_each_entry(pos, head, hash) {
32051 + AuDbg("%.*s\n", str->len, str->name);
32052 + if (au_nhash_test_name(str, name, nlen))
32058 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32059 + unsigned char d_type)
32061 +#ifdef CONFIG_AUFS_SHWH
32062 + wh->wh_ino = ino;
32063 + wh->wh_type = d_type;
32067 +/* ---------------------------------------------------------------------- */
32069 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32070 + unsigned int d_type, aufs_bindex_t bindex,
32071 + unsigned char shwh)
32074 + struct au_vdir_destr *str;
32075 + struct au_vdir_wh *wh;
32077 + AuDbg("%.*s\n", nlen, name);
32078 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32081 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32082 + if (unlikely(!wh))
32086 + wh->wh_bindex = bindex;
32088 + au_shwh_init_wh(wh, ino, d_type);
32089 + str = &wh->wh_str;
32091 + memcpy(str->name, name, nlen);
32092 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32099 +static int append_deblk(struct au_vdir *vdir)
32102 + unsigned long ul;
32103 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32104 + union au_vdir_deblk_p p, deblk_end;
32105 + unsigned char **o;
32108 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32109 + GFP_NOFS, /*may_shrink*/0);
32110 + if (unlikely(!o))
32113 + vdir->vd_deblk = o;
32114 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32116 + ul = vdir->vd_nblk++;
32117 + vdir->vd_deblk[ul] = p.deblk;
32118 + vdir->vd_last.ul = ul;
32119 + vdir->vd_last.p.deblk = p.deblk;
32120 + deblk_end.deblk = p.deblk + deblk_sz;
32121 + err = set_deblk_end(&p, &deblk_end);
32128 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32129 + unsigned int d_type, struct au_nhash *delist)
32133 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32134 + union au_vdir_deblk_p p, *room, deblk_end;
32135 + struct au_vdir_dehstr *dehstr;
32137 + p.deblk = last_deblk(vdir);
32138 + deblk_end.deblk = p.deblk + deblk_sz;
32139 + room = &vdir->vd_last.p;
32140 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32141 + || !is_deblk_end(room, &deblk_end));
32143 + sz = calc_size(nlen);
32144 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32145 + err = append_deblk(vdir);
32146 + if (unlikely(err))
32149 + p.deblk = last_deblk(vdir);
32150 + deblk_end.deblk = p.deblk + deblk_sz;
32152 + AuDebugOn(room->deblk != p.deblk);
32156 + dehstr = au_cache_alloc_vdir_dehstr();
32157 + if (unlikely(!dehstr))
32160 + dehstr->str = &room->de->de_str;
32161 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32162 + room->de->de_ino = ino;
32163 + room->de->de_type = d_type;
32164 + room->de->de_str.len = nlen;
32165 + memcpy(room->de->de_str.name, name, nlen);
32168 + room->deblk += sz;
32169 + if (unlikely(set_deblk_end(room, &deblk_end)))
32170 + err = append_deblk(vdir);
32177 +/* ---------------------------------------------------------------------- */
32179 +void au_vdir_free(struct au_vdir *vdir)
32181 + unsigned char **deblk;
32183 + deblk = vdir->vd_deblk;
32184 + while (vdir->vd_nblk--)
32185 + au_kfree_try_rcu(*deblk++);
32186 + au_kfree_try_rcu(vdir->vd_deblk);
32187 + au_cache_free_vdir(vdir);
32190 +static struct au_vdir *alloc_vdir(struct file *file)
32192 + struct au_vdir *vdir;
32193 + struct super_block *sb;
32196 + sb = file->f_path.dentry->d_sb;
32197 + SiMustAnyLock(sb);
32200 + vdir = au_cache_alloc_vdir();
32201 + if (unlikely(!vdir))
32204 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32205 + if (unlikely(!vdir->vd_deblk))
32208 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32209 + if (!vdir->vd_deblk_sz) {
32210 + /* estimate the appropriate size for deblk */
32211 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32212 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32214 + vdir->vd_nblk = 0;
32215 + vdir->vd_version = 0;
32216 + vdir->vd_jiffy = 0;
32217 + err = append_deblk(vdir);
32219 + return vdir; /* success */
32221 + au_kfree_try_rcu(vdir->vd_deblk);
32224 + au_cache_free_vdir(vdir);
32226 + vdir = ERR_PTR(err);
32230 +static int reinit_vdir(struct au_vdir *vdir)
32233 + union au_vdir_deblk_p p, deblk_end;
32235 + while (vdir->vd_nblk > 1) {
32236 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32237 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32240 + p.deblk = vdir->vd_deblk[0];
32241 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32242 + err = set_deblk_end(&p, &deblk_end);
32243 + /* keep vd_dblk_sz */
32244 + vdir->vd_last.ul = 0;
32245 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32246 + vdir->vd_version = 0;
32247 + vdir->vd_jiffy = 0;
32252 +/* ---------------------------------------------------------------------- */
32254 +#define AuFillVdir_CALLED 1
32255 +#define AuFillVdir_WHABLE (1 << 1)
32256 +#define AuFillVdir_SHWH (1 << 2)
32257 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32258 +#define au_fset_fillvdir(flags, name) \
32259 + do { (flags) |= AuFillVdir_##name; } while (0)
32260 +#define au_fclr_fillvdir(flags, name) \
32261 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32263 +#ifndef CONFIG_AUFS_SHWH
32264 +#undef AuFillVdir_SHWH
32265 +#define AuFillVdir_SHWH 0
32268 +struct fillvdir_arg {
32269 + struct dir_context ctx;
32270 + struct file *file;
32271 + struct au_vdir *vdir;
32272 + struct au_nhash delist;
32273 + struct au_nhash whlist;
32274 + aufs_bindex_t bindex;
32275 + unsigned int flags;
32279 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32280 + loff_t offset __maybe_unused, u64 h_ino,
32281 + unsigned int d_type)
32283 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32284 + char *name = (void *)__name;
32285 + struct super_block *sb;
32287 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32290 + sb = arg->file->f_path.dentry->d_sb;
32291 + au_fset_fillvdir(arg->flags, CALLED);
32293 + if (nlen <= AUFS_WH_PFX_LEN
32294 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32295 + if (test_known(&arg->delist, name, nlen)
32296 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32297 + goto out; /* already exists or whiteouted */
32299 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32301 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32302 + d_type = DT_UNKNOWN;
32303 + arg->err = append_de(arg->vdir, name, nlen, ino,
32304 + d_type, &arg->delist);
32306 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32307 + name += AUFS_WH_PFX_LEN;
32308 + nlen -= AUFS_WH_PFX_LEN;
32309 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32310 + goto out; /* already whiteouted */
32312 + ino = 0; /* just to suppress a warning */
32314 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32317 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32318 + d_type = DT_UNKNOWN;
32319 + arg->err = au_nhash_append_wh
32320 + (&arg->whlist, name, nlen, ino, d_type,
32321 + arg->bindex, shwh);
32327 + arg->vdir->vd_jiffy = jiffies;
32329 + AuTraceErr(arg->err);
32333 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32334 + struct au_nhash *whlist, struct au_nhash *delist)
32336 +#ifdef CONFIG_AUFS_SHWH
32338 + unsigned int nh, u;
32339 + struct hlist_head *head;
32340 + struct au_vdir_wh *pos;
32341 + struct hlist_node *n;
32343 + struct au_vdir_destr *destr;
32345 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32348 + o = p = (void *)__get_free_page(GFP_NOFS);
32349 + if (unlikely(!p))
32353 + nh = whlist->nh_num;
32354 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32355 + p += AUFS_WH_PFX_LEN;
32356 + for (u = 0; u < nh; u++) {
32357 + head = whlist->nh_head + u;
32358 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32359 + destr = &pos->wh_str;
32360 + memcpy(p, destr->name, destr->len);
32361 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32362 + pos->wh_ino, pos->wh_type, delist);
32363 + if (unlikely(err))
32368 + free_page((unsigned long)o);
32378 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32381 + unsigned int rdhash;
32383 + aufs_bindex_t bbot, bindex, btop;
32384 + unsigned char shwh;
32385 + struct file *hf, *file;
32386 + struct super_block *sb;
32388 + file = arg->file;
32389 + sb = file->f_path.dentry->d_sb;
32390 + SiMustAnyLock(sb);
32392 + rdhash = au_sbi(sb)->si_rdhash;
32394 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32395 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32396 + if (unlikely(err))
32398 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32399 + if (unlikely(err))
32405 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32407 + au_fset_fillvdir(arg->flags, SHWH);
32409 + btop = au_fbtop(file);
32410 + bbot = au_fbbot_dir(file);
32411 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32412 + hf = au_hf_dir(file, bindex);
32416 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32418 + if (unlikely(offset))
32421 + arg->bindex = bindex;
32422 + au_fclr_fillvdir(arg->flags, WHABLE);
32424 + || (bindex != bbot
32425 + && au_br_whable(au_sbr_perm(sb, bindex))))
32426 + au_fset_fillvdir(arg->flags, WHABLE);
32429 + au_fclr_fillvdir(arg->flags, CALLED);
32431 + err = vfsub_iterate_dir(hf, &arg->ctx);
32434 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32437 + * dir_relax() may be good for concurrency, but aufs should not
32438 + * use it since it will cause a lockdep problem.
32442 + if (!err && shwh)
32443 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32445 + au_nhash_wh_free(&arg->whlist);
32448 + au_nhash_de_free(&arg->delist);
32453 +static int read_vdir(struct file *file, int may_read)
32456 + unsigned long expire;
32457 + unsigned char do_read;
32458 + struct fillvdir_arg arg = {
32460 + .actor = fillvdir
32463 + struct inode *inode;
32464 + struct au_vdir *vdir, *allocated;
32467 + inode = file_inode(file);
32468 + IMustLock(inode);
32469 + IiMustWriteLock(inode);
32470 + SiMustAnyLock(inode->i_sb);
32472 + allocated = NULL;
32474 + expire = au_sbi(inode->i_sb)->si_rdcache;
32475 + vdir = au_ivdir(inode);
32478 + vdir = alloc_vdir(file);
32479 + err = PTR_ERR(vdir);
32480 + if (IS_ERR(vdir))
32483 + allocated = vdir;
32484 + } else if (may_read
32485 + && (!inode_eq_iversion(inode, vdir->vd_version)
32486 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32488 + err = reinit_vdir(vdir);
32489 + if (unlikely(err))
32494 + return 0; /* success */
32498 + err = au_do_read_vdir(&arg);
32500 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32501 + vdir->vd_version = inode_query_iversion(inode);
32502 + vdir->vd_last.ul = 0;
32503 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32505 + au_set_ivdir(inode, allocated);
32506 + } else if (allocated)
32507 + au_vdir_free(allocated);
32513 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32516 + unsigned long ul, n;
32517 + const unsigned int deblk_sz = src->vd_deblk_sz;
32519 + AuDebugOn(tgt->vd_nblk != 1);
32522 + if (tgt->vd_nblk < src->vd_nblk) {
32523 + unsigned char **p;
32525 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32526 + GFP_NOFS, /*may_shrink*/0);
32527 + if (unlikely(!p))
32529 + tgt->vd_deblk = p;
32532 + if (tgt->vd_deblk_sz != deblk_sz) {
32533 + unsigned char *p;
32535 + tgt->vd_deblk_sz = deblk_sz;
32536 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32537 + /*may_shrink*/1);
32538 + if (unlikely(!p))
32540 + tgt->vd_deblk[0] = p;
32542 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32543 + tgt->vd_version = src->vd_version;
32544 + tgt->vd_jiffy = src->vd_jiffy;
32546 + n = src->vd_nblk;
32547 + for (ul = 1; ul < n; ul++) {
32548 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32550 + if (unlikely(!tgt->vd_deblk[ul]))
32554 + tgt->vd_nblk = n;
32555 + tgt->vd_last.ul = tgt->vd_last.ul;
32556 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32557 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32558 + - src->vd_deblk[src->vd_last.ul];
32560 + return 0; /* success */
32563 + rerr = reinit_vdir(tgt);
32568 +int au_vdir_init(struct file *file)
32571 + struct inode *inode;
32572 + struct au_vdir *vdir_cache, *allocated;
32574 + /* test file->f_pos here instead of ctx->pos */
32575 + err = read_vdir(file, !file->f_pos);
32576 + if (unlikely(err))
32579 + allocated = NULL;
32580 + vdir_cache = au_fvdir_cache(file);
32581 + if (!vdir_cache) {
32582 + vdir_cache = alloc_vdir(file);
32583 + err = PTR_ERR(vdir_cache);
32584 + if (IS_ERR(vdir_cache))
32586 + allocated = vdir_cache;
32587 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32588 + /* test file->f_pos here instead of ctx->pos */
32589 + err = reinit_vdir(vdir_cache);
32590 + if (unlikely(err))
32593 + return 0; /* success */
32595 + inode = file_inode(file);
32596 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32598 + file->f_version = inode_query_iversion(inode);
32600 + au_set_fvdir_cache(file, allocated);
32601 + } else if (allocated)
32602 + au_vdir_free(allocated);
32608 +static loff_t calc_offset(struct au_vdir *vdir)
32611 + union au_vdir_deblk_p p;
32613 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32614 + offset = vdir->vd_last.p.deblk - p.deblk;
32615 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32619 +/* returns true or false */
32620 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32623 + unsigned int deblk_sz;
32624 + unsigned long ul, n;
32626 + union au_vdir_deblk_p p, deblk_end;
32627 + struct au_vdir *vdir_cache;
32630 + vdir_cache = au_fvdir_cache(file);
32631 + offset = calc_offset(vdir_cache);
32632 + AuDbg("offset %lld\n", offset);
32633 + if (ctx->pos == offset)
32636 + vdir_cache->vd_last.ul = 0;
32637 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32642 + deblk_sz = vdir_cache->vd_deblk_sz;
32643 + ul = div64_u64(ctx->pos, deblk_sz);
32644 + AuDbg("ul %lu\n", ul);
32645 + if (ul >= vdir_cache->vd_nblk)
32648 + n = vdir_cache->vd_nblk;
32649 + for (; ul < n; ul++) {
32650 + p.deblk = vdir_cache->vd_deblk[ul];
32651 + deblk_end.deblk = p.deblk + deblk_sz;
32653 + offset *= deblk_sz;
32654 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32657 + l = calc_size(p.de->de_str.len);
32661 + if (!is_deblk_end(&p, &deblk_end)) {
32663 + vdir_cache->vd_last.ul = ul;
32664 + vdir_cache->vd_last.p = p;
32672 + AuDbg("valid %d\n", !valid);
32676 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32678 + unsigned int l, deblk_sz;
32679 + union au_vdir_deblk_p deblk_end;
32680 + struct au_vdir *vdir_cache;
32681 + struct au_vdir_de *de;
32683 + if (!seek_vdir(file, ctx))
32686 + vdir_cache = au_fvdir_cache(file);
32687 + deblk_sz = vdir_cache->vd_deblk_sz;
32689 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32690 + deblk_end.deblk += deblk_sz;
32691 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32692 + de = vdir_cache->vd_last.p.de;
32693 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32694 + de->de_str.len, de->de_str.name, ctx->pos,
32695 + (unsigned long)de->de_ino, de->de_type);
32696 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32697 + de->de_str.len, de->de_ino,
32699 + /* todo: ignore the error caused by udba? */
32700 + /* return err; */
32704 + l = calc_size(de->de_str.len);
32705 + vdir_cache->vd_last.p.deblk += l;
32708 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32709 + vdir_cache->vd_last.ul++;
32710 + vdir_cache->vd_last.p.deblk
32711 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32712 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32721 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32722 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32723 +++ linux/fs/aufs/vfsub.c 2020-01-27 10:57:18.178871751 +0100
32725 +// SPDX-License-Identifier: GPL-2.0
32727 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32729 + * This program, aufs is free software; you can redistribute it and/or modify
32730 + * it under the terms of the GNU General Public License as published by
32731 + * the Free Software Foundation; either version 2 of the License, or
32732 + * (at your option) any later version.
32734 + * This program is distributed in the hope that it will be useful,
32735 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32736 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32737 + * GNU General Public License for more details.
32739 + * You should have received a copy of the GNU General Public License
32740 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32744 + * sub-routines for VFS
32747 +#include <linux/mnt_namespace.h>
32748 +#include <linux/namei.h>
32749 +#include <linux/nsproxy.h>
32750 +#include <linux/security.h>
32751 +#include <linux/splice.h>
32754 +#ifdef CONFIG_AUFS_BR_FUSE
32755 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32757 + if (!au_test_fuse(h_sb) || !au_userns)
32760 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32764 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32769 + down_read(&h_sb->s_umount);
32770 + err = __sync_filesystem(h_sb, wait);
32771 + up_read(&h_sb->s_umount);
32777 +/* ---------------------------------------------------------------------- */
32779 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32783 + struct super_block *h_sb;
32785 + /* for remote fs, leave work for its getattr or d_revalidate */
32786 + /* for bad i_attr fs, handle them in aufs_getattr() */
32787 + /* still some fs may acquire i_mutex. we need to skip them */
32791 + h_sb = h_path->dentry->d_sb;
32792 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32794 + err = vfsub_getattr(h_path, &st);
32799 +/* ---------------------------------------------------------------------- */
32801 +struct file *vfsub_dentry_open(struct path *path, int flags)
32803 + struct file *file;
32805 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32807 + if (!IS_ERR_OR_NULL(file)
32808 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32809 + i_readcount_inc(d_inode(path->dentry));
32814 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32816 + struct file *file;
32819 + file = filp_open(path,
32820 + oflags /* | __FMODE_NONOTIFY */,
32823 + if (IS_ERR(file))
32825 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32832 + * Ideally this function should call VFS:do_last() in order to keep all its
32833 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32834 + * structure such as nameidata. This is a second (or third) best approach.
32835 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32837 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32838 + struct vfsub_aopen_args *args)
32841 + struct au_branch *br = args->br;
32842 + struct file *file = args->file;
32843 + /* copied from linux/fs/namei.c:atomic_open() */
32844 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32847 + AuDebugOn(!dir->i_op->atomic_open);
32849 + err = au_br_test_oflag(args->open_flag, br);
32850 + if (unlikely(err))
32853 + au_lcnt_inc(&br->br_nfiles);
32854 + file->f_path.dentry = DENTRY_NOT_SET;
32855 + file->f_path.mnt = au_br_mnt(br);
32856 + AuDbg("%ps\n", dir->i_op->atomic_open);
32857 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32858 + args->create_mode);
32859 + if (unlikely(err < 0)) {
32860 + au_lcnt_dec(&br->br_nfiles);
32864 + /* temporary workaround for nfsv4 branch */
32865 + if (au_test_nfs(dir->i_sb))
32866 + nfs_mark_for_revalidate(dir);
32868 + if (file->f_mode & FMODE_CREATED)
32869 + fsnotify_create(dir, dentry);
32870 + if (!(file->f_mode & FMODE_OPENED)) {
32871 + au_lcnt_dec(&br->br_nfiles);
32875 + /* todo: call VFS:may_open() here */
32876 + /* todo: ima_file_check() too? */
32877 + if (!err && (args->open_flag & __FMODE_EXEC))
32878 + err = deny_write_access(file);
32880 + fsnotify_open(file);
32882 + au_lcnt_dec(&br->br_nfiles);
32883 + /* note that the file is created and still opened */
32889 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32893 + err = kern_path(name, flags, path);
32894 + if (!err && d_is_positive(path->dentry))
32895 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32899 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32900 + struct dentry *parent, int len)
32902 + struct path path = {
32906 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32907 + if (IS_ERR(path.dentry))
32909 + if (d_is_positive(path.dentry))
32910 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32913 + AuTraceErrPtr(path.dentry);
32914 + return path.dentry;
32917 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32920 + struct path path = {
32924 + /* VFS checks it too, but by WARN_ON_ONCE() */
32925 + IMustLock(d_inode(parent));
32927 + path.dentry = lookup_one_len(name, parent, len);
32928 + if (IS_ERR(path.dentry))
32930 + if (d_is_positive(path.dentry))
32931 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32934 + AuTraceErrPtr(path.dentry);
32935 + return path.dentry;
32938 +void vfsub_call_lkup_one(void *args)
32940 + struct vfsub_lkup_one_args *a = args;
32941 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32944 +/* ---------------------------------------------------------------------- */
32946 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32947 + struct dentry *d2, struct au_hinode *hdir2)
32949 + struct dentry *d;
32952 + d = lock_rename(d1, d2);
32954 + au_hn_suspend(hdir1);
32955 + if (hdir1 != hdir2)
32956 + au_hn_suspend(hdir2);
32961 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32962 + struct dentry *d2, struct au_hinode *hdir2)
32964 + au_hn_resume(hdir1);
32965 + if (hdir1 != hdir2)
32966 + au_hn_resume(hdir2);
32968 + unlock_rename(d1, d2);
32972 +/* ---------------------------------------------------------------------- */
32974 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32977 + struct dentry *d;
32981 + d = path->dentry;
32982 + path->dentry = d->d_parent;
32983 + err = security_path_mknod(path, d, mode, 0);
32984 + path->dentry = d;
32985 + if (unlikely(err))
32989 + err = vfs_create(dir, path->dentry, mode, want_excl);
32992 + struct path tmp = *path;
32995 + vfsub_update_h_iattr(&tmp, &did);
32997 + tmp.dentry = path->dentry->d_parent;
32998 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33007 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33010 + struct dentry *d;
33014 + d = path->dentry;
33015 + path->dentry = d->d_parent;
33016 + err = security_path_symlink(path, d, symname);
33017 + path->dentry = d;
33018 + if (unlikely(err))
33022 + err = vfs_symlink(dir, path->dentry, symname);
33025 + struct path tmp = *path;
33028 + vfsub_update_h_iattr(&tmp, &did);
33030 + tmp.dentry = path->dentry->d_parent;
33031 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33040 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33043 + struct dentry *d;
33047 + d = path->dentry;
33048 + path->dentry = d->d_parent;
33049 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33050 + path->dentry = d;
33051 + if (unlikely(err))
33055 + err = vfs_mknod(dir, path->dentry, mode, dev);
33058 + struct path tmp = *path;
33061 + vfsub_update_h_iattr(&tmp, &did);
33063 + tmp.dentry = path->dentry->d_parent;
33064 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33073 +static int au_test_nlink(struct inode *inode)
33075 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33077 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33078 + || inode->i_nlink < link_max)
33083 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33084 + struct inode **delegated_inode)
33087 + struct dentry *d;
33091 + err = au_test_nlink(d_inode(src_dentry));
33092 + if (unlikely(err))
33095 + /* we don't call may_linkat() */
33096 + d = path->dentry;
33097 + path->dentry = d->d_parent;
33098 + err = security_path_link(src_dentry, path, d);
33099 + path->dentry = d;
33100 + if (unlikely(err))
33104 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33107 + struct path tmp = *path;
33110 + /* fuse has different memory inode for the same inumber */
33111 + vfsub_update_h_iattr(&tmp, &did);
33113 + tmp.dentry = path->dentry->d_parent;
33114 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33115 + tmp.dentry = src_dentry;
33116 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33125 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33126 + struct inode *dir, struct path *path,
33127 + struct inode **delegated_inode, unsigned int flags)
33130 + struct path tmp = {
33133 + struct dentry *d;
33136 + IMustLock(src_dir);
33138 + d = path->dentry;
33139 + path->dentry = d->d_parent;
33140 + tmp.dentry = src_dentry->d_parent;
33141 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33142 + path->dentry = d;
33143 + if (unlikely(err))
33147 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33148 + delegated_inode, flags);
33153 + tmp.dentry = d->d_parent;
33154 + vfsub_update_h_iattr(&tmp, &did);
33156 + tmp.dentry = src_dentry;
33157 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33158 + tmp.dentry = src_dentry->d_parent;
33159 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33168 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33171 + struct dentry *d;
33175 + d = path->dentry;
33176 + path->dentry = d->d_parent;
33177 + err = security_path_mkdir(path, d, mode);
33178 + path->dentry = d;
33179 + if (unlikely(err))
33183 + err = vfs_mkdir(dir, path->dentry, mode);
33186 + struct path tmp = *path;
33189 + vfsub_update_h_iattr(&tmp, &did);
33191 + tmp.dentry = path->dentry->d_parent;
33192 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33201 +int vfsub_rmdir(struct inode *dir, struct path *path)
33204 + struct dentry *d;
33208 + d = path->dentry;
33209 + path->dentry = d->d_parent;
33210 + err = security_path_rmdir(path, d);
33211 + path->dentry = d;
33212 + if (unlikely(err))
33216 + err = vfs_rmdir(dir, path->dentry);
33219 + struct path tmp = {
33220 + .dentry = path->dentry->d_parent,
33224 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33231 +/* ---------------------------------------------------------------------- */
33233 +/* todo: support mmap_sem? */
33234 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33240 + err = vfs_read(file, ubuf, count, ppos);
33243 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33247 +/* todo: kernel_read()? */
33248 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33252 + mm_segment_t oldfs;
33259 + oldfs = get_fs();
33260 + set_fs(KERNEL_DS);
33261 + err = vfsub_read_u(file, buf.u, count, ppos);
33266 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33272 + err = vfs_write(file, ubuf, count, ppos);
33275 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33279 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33282 + mm_segment_t oldfs;
33285 + const char __user *u;
33289 + oldfs = get_fs();
33290 + set_fs(KERNEL_DS);
33291 + err = vfsub_write_u(file, buf.u, count, ppos);
33296 +int vfsub_flush(struct file *file, fl_owner_t id)
33301 + if (file->f_op->flush) {
33302 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33303 + err = file->f_op->flush(file, id);
33306 + err = file->f_op->flush(file, id);
33310 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33316 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33320 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33323 + err = iterate_dir(file, ctx);
33326 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33331 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33332 + struct pipe_inode_info *pipe, size_t len,
33333 + unsigned int flags)
33338 + err = do_splice_to(in, ppos, pipe, len, flags);
33340 + file_accessed(in);
33342 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33346 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33347 + loff_t *ppos, size_t len, unsigned int flags)
33352 + err = do_splice_from(pipe, out, ppos, len, flags);
33355 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33359 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33363 + /* file can be NULL */
33365 + err = vfs_fsync(file, datasync);
33369 + AuDebugOn(!file);
33370 + path = &file->f_path;
33372 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33377 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33378 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33379 + struct file *h_file)
33382 + struct inode *h_inode;
33383 + struct super_block *h_sb;
33386 + err = vfsub_truncate(h_path, length);
33390 + h_inode = d_inode(h_path->dentry);
33391 + h_sb = h_inode->i_sb;
33393 + sb_start_write(h_sb);
33395 + err = locks_verify_truncate(h_inode, h_file, length);
33397 + err = security_path_truncate(h_path);
33400 + err = do_truncate(h_path->dentry, length, attr, h_file);
33404 + sb_end_write(h_sb);
33411 +/* ---------------------------------------------------------------------- */
33413 +struct au_vfsub_mkdir_args {
33415 + struct inode *dir;
33416 + struct path *path;
33420 +static void au_call_vfsub_mkdir(void *args)
33422 + struct au_vfsub_mkdir_args *a = args;
33423 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33426 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33428 + int err, do_sio, wkq_err;
33430 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33433 + err = vfsub_mkdir(dir, path, mode);
33436 + struct au_vfsub_mkdir_args args = {
33442 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33443 + if (unlikely(wkq_err))
33450 +struct au_vfsub_rmdir_args {
33452 + struct inode *dir;
33453 + struct path *path;
33456 +static void au_call_vfsub_rmdir(void *args)
33458 + struct au_vfsub_rmdir_args *a = args;
33459 + *a->errp = vfsub_rmdir(a->dir, a->path);
33462 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33464 + int err, do_sio, wkq_err;
33466 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33469 + err = vfsub_rmdir(dir, path);
33472 + struct au_vfsub_rmdir_args args = {
33477 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33478 + if (unlikely(wkq_err))
33485 +/* ---------------------------------------------------------------------- */
33487 +struct notify_change_args {
33489 + struct path *path;
33490 + struct iattr *ia;
33491 + struct inode **delegated_inode;
33494 +static void call_notify_change(void *args)
33496 + struct notify_change_args *a = args;
33497 + struct inode *h_inode;
33499 + h_inode = d_inode(a->path->dentry);
33500 + IMustLock(h_inode);
33502 + *a->errp = -EPERM;
33503 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33505 + *a->errp = notify_change(a->path->dentry, a->ia,
33506 + a->delegated_inode);
33509 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33511 + AuTraceErr(*a->errp);
33514 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33515 + struct inode **delegated_inode)
33518 + struct notify_change_args args = {
33522 + .delegated_inode = delegated_inode
33525 + call_notify_change(&args);
33530 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33531 + struct inode **delegated_inode)
33533 + int err, wkq_err;
33534 + struct notify_change_args args = {
33538 + .delegated_inode = delegated_inode
33541 + wkq_err = au_wkq_wait(call_notify_change, &args);
33542 + if (unlikely(wkq_err))
33548 +/* ---------------------------------------------------------------------- */
33550 +struct unlink_args {
33552 + struct inode *dir;
33553 + struct path *path;
33554 + struct inode **delegated_inode;
33557 +static void call_unlink(void *args)
33559 + struct unlink_args *a = args;
33560 + struct dentry *d = a->path->dentry;
33561 + struct inode *h_inode;
33562 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33563 + && au_dcount(d) == 1);
33565 + IMustLock(a->dir);
33567 + a->path->dentry = d->d_parent;
33568 + *a->errp = security_path_unlink(a->path, d);
33569 + a->path->dentry = d;
33570 + if (unlikely(*a->errp))
33573 + if (!stop_sillyrename)
33576 + if (d_is_positive(d)) {
33577 + h_inode = d_inode(d);
33582 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33585 + struct path tmp = {
33586 + .dentry = d->d_parent,
33587 + .mnt = a->path->mnt
33589 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33592 + if (!stop_sillyrename)
33597 + AuTraceErr(*a->errp);
33601 + * @dir: must be locked.
33602 + * @dentry: target dentry.
33604 +int vfsub_unlink(struct inode *dir, struct path *path,
33605 + struct inode **delegated_inode, int force)
33608 + struct unlink_args args = {
33612 + .delegated_inode = delegated_inode
33616 + call_unlink(&args);
33620 + wkq_err = au_wkq_wait(call_unlink, &args);
33621 + if (unlikely(wkq_err))
33627 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33628 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33629 +++ linux/fs/aufs/vfsub.h 2020-01-27 10:57:18.178871751 +0100
33631 +/* SPDX-License-Identifier: GPL-2.0 */
33633 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33635 + * This program, aufs is free software; you can redistribute it and/or modify
33636 + * it under the terms of the GNU General Public License as published by
33637 + * the Free Software Foundation; either version 2 of the License, or
33638 + * (at your option) any later version.
33640 + * This program is distributed in the hope that it will be useful,
33641 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33642 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33643 + * GNU General Public License for more details.
33645 + * You should have received a copy of the GNU General Public License
33646 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33650 + * sub-routines for VFS
33653 +#ifndef __AUFS_VFSUB_H__
33654 +#define __AUFS_VFSUB_H__
33658 +#include <linux/fs.h>
33659 +#include <linux/mount.h>
33660 +#include <linux/posix_acl.h>
33661 +#include <linux/xattr.h>
33662 +#include "debug.h"
33664 +/* copied from linux/fs/internal.h */
33665 +/* todo: BAD approach!! */
33666 +extern void __mnt_drop_write(struct vfsmount *);
33667 +extern struct file *alloc_empty_file(int, const struct cred *);
33669 +/* ---------------------------------------------------------------------- */
33671 +/* lock subclass for lower inode */
33672 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33673 +/* reduce? gave up. */
33675 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33676 + AuLsc_I_PARENT, /* lower inode, parent first */
33677 + AuLsc_I_PARENT2, /* copyup dirs */
33678 + AuLsc_I_PARENT3, /* copyup wh */
33684 +/* to debug easier, do not make them inlined functions */
33685 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33686 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33688 +/* ---------------------------------------------------------------------- */
33690 +static inline void vfsub_drop_nlink(struct inode *inode)
33692 + AuDebugOn(!inode->i_nlink);
33693 + drop_nlink(inode);
33696 +static inline void vfsub_dead_dir(struct inode *inode)
33698 + AuDebugOn(!S_ISDIR(inode->i_mode));
33699 + inode->i_flags |= S_DEAD;
33700 + clear_nlink(inode);
33703 +static inline int vfsub_native_ro(struct inode *inode)
33705 + return sb_rdonly(inode->i_sb)
33706 + || IS_RDONLY(inode)
33707 + /* || IS_APPEND(inode) */
33708 + || IS_IMMUTABLE(inode);
33711 +#ifdef CONFIG_AUFS_BR_FUSE
33712 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33714 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33717 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33719 +/* ---------------------------------------------------------------------- */
33721 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33722 +struct file *vfsub_dentry_open(struct path *path, int flags);
33723 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33725 +struct vfsub_aopen_args {
33726 + struct file *file;
33727 + unsigned int open_flag;
33728 + umode_t create_mode;
33729 + struct au_branch *br;
33731 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33732 + struct vfsub_aopen_args *args);
33733 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33735 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33736 + struct dentry *parent, int len);
33737 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33740 +struct vfsub_lkup_one_args {
33741 + struct dentry **errp;
33742 + struct qstr *name;
33743 + struct dentry *parent;
33746 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33747 + struct dentry *parent)
33749 + return vfsub_lookup_one_len(name->name, parent, name->len);
33752 +void vfsub_call_lkup_one(void *args);
33754 +/* ---------------------------------------------------------------------- */
33756 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33761 + err = mnt_want_write(mnt);
33766 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33769 + mnt_drop_write(mnt);
33773 +#if 0 /* reserved */
33774 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33777 + mnt_drop_write_file(file);
33782 +/* ---------------------------------------------------------------------- */
33785 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33786 + struct dentry *d2, struct au_hinode *hdir2);
33787 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33788 + struct dentry *d2, struct au_hinode *hdir2);
33790 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33792 +int vfsub_symlink(struct inode *dir, struct path *path,
33793 + const char *symname);
33794 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33795 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33796 + struct path *path, struct inode **delegated_inode);
33797 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33798 + struct inode *hdir, struct path *path,
33799 + struct inode **delegated_inode, unsigned int flags);
33800 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33801 +int vfsub_rmdir(struct inode *dir, struct path *path);
33803 +/* ---------------------------------------------------------------------- */
33805 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33807 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33809 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33811 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33813 +int vfsub_flush(struct file *file, fl_owner_t id);
33814 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33816 +static inline loff_t vfsub_f_size_read(struct file *file)
33818 + return i_size_read(file_inode(file));
33821 +static inline unsigned int vfsub_file_flags(struct file *file)
33823 + unsigned int flags;
33825 + spin_lock(&file->f_lock);
33826 + flags = file->f_flags;
33827 + spin_unlock(&file->f_lock);
33832 +static inline int vfsub_file_execed(struct file *file)
33834 + /* todo: direct access f_flags */
33835 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33838 +#if 0 /* reserved */
33839 +static inline void vfsub_file_accessed(struct file *h_file)
33841 + file_accessed(h_file);
33842 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33846 +#if 0 /* reserved */
33847 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33848 + struct dentry *h_dentry)
33850 + struct path h_path = {
33851 + .dentry = h_dentry,
33854 + touch_atime(&h_path);
33855 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33859 +static inline int vfsub_update_time(struct inode *h_inode,
33860 + struct timespec64 *ts, int flags)
33862 + return update_time(h_inode, ts, flags);
33863 + /* no vfsub_update_h_iattr() since we don't have struct path */
33866 +#ifdef CONFIG_FS_POSIX_ACL
33867 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33871 + err = posix_acl_chmod(h_inode, h_mode);
33872 + if (err == -EOPNOTSUPP)
33877 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33880 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33881 + struct pipe_inode_info *pipe, size_t len,
33882 + unsigned int flags);
33883 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33884 + loff_t *ppos, size_t len, unsigned int flags);
33886 +static inline long vfsub_truncate(struct path *path, loff_t length)
33891 + err = vfs_truncate(path, length);
33896 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33897 + struct file *h_file);
33898 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33901 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33904 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33910 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33916 +/* copy_file_range(2) is a systemcall */
33917 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33918 + struct file *dst, loff_t dst_pos,
33919 + size_t len, unsigned int flags)
33924 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33930 +/* ---------------------------------------------------------------------- */
33932 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33937 + err = vfs_llseek(file, offset, origin);
33942 +/* ---------------------------------------------------------------------- */
33944 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33945 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33946 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33947 + struct inode **delegated_inode);
33948 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33949 + struct inode **delegated_inode);
33950 +int vfsub_unlink(struct inode *dir, struct path *path,
33951 + struct inode **delegated_inode, int force);
33953 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33955 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33958 +/* ---------------------------------------------------------------------- */
33960 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33961 + const void *value, size_t size, int flags)
33966 + err = vfs_setxattr(dentry, name, value, size, flags);
33972 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33977 + err = vfs_removexattr(dentry, name);
33983 +#endif /* __KERNEL__ */
33984 +#endif /* __AUFS_VFSUB_H__ */
33985 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33986 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33987 +++ linux/fs/aufs/wbr_policy.c 2020-01-27 10:57:18.178871751 +0100
33989 +// SPDX-License-Identifier: GPL-2.0
33991 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33993 + * This program, aufs is free software; you can redistribute it and/or modify
33994 + * it under the terms of the GNU General Public License as published by
33995 + * the Free Software Foundation; either version 2 of the License, or
33996 + * (at your option) any later version.
33998 + * This program is distributed in the hope that it will be useful,
33999 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34000 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34001 + * GNU General Public License for more details.
34003 + * You should have received a copy of the GNU General Public License
34004 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34008 + * policies for selecting one among multiple writable branches
34011 +#include <linux/statfs.h>
34014 +/* subset of cpup_attr() */
34015 +static noinline_for_stack
34016 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34020 + struct inode *h_isrc;
34022 + h_isrc = d_inode(h_src);
34023 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34024 + ia.ia_mode = h_isrc->i_mode;
34025 + ia.ia_uid = h_isrc->i_uid;
34026 + ia.ia_gid = h_isrc->i_gid;
34027 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34028 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34029 + /* no delegation since it is just created */
34030 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34032 + /* is this nfs only? */
34033 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34034 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34035 + ia.ia_mode = h_isrc->i_mode;
34036 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34042 +#define AuCpdown_PARENT_OPQ 1
34043 +#define AuCpdown_WHED (1 << 1)
34044 +#define AuCpdown_MADE_DIR (1 << 2)
34045 +#define AuCpdown_DIROPQ (1 << 3)
34046 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34047 +#define au_fset_cpdown(flags, name) \
34048 + do { (flags) |= AuCpdown_##name; } while (0)
34049 +#define au_fclr_cpdown(flags, name) \
34050 + do { (flags) &= ~AuCpdown_##name; } while (0)
34052 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34053 + unsigned int *flags)
34056 + struct dentry *opq_dentry;
34058 + opq_dentry = au_diropq_create(dentry, bdst);
34059 + err = PTR_ERR(opq_dentry);
34060 + if (IS_ERR(opq_dentry))
34062 + dput(opq_dentry);
34063 + au_fset_cpdown(*flags, DIROPQ);
34069 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34070 + struct inode *dir, aufs_bindex_t bdst)
34073 + struct path h_path;
34074 + struct au_branch *br;
34076 + br = au_sbr(dentry->d_sb, bdst);
34077 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34078 + err = PTR_ERR(h_path.dentry);
34079 + if (IS_ERR(h_path.dentry))
34083 + if (d_is_positive(h_path.dentry)) {
34084 + h_path.mnt = au_br_mnt(br);
34085 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34088 + dput(h_path.dentry);
34094 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34095 + struct au_pin *pin,
34096 + struct dentry *h_parent, void *arg)
34099 + aufs_bindex_t bopq, btop;
34100 + struct path h_path;
34101 + struct dentry *parent;
34102 + struct inode *h_dir, *h_inode, *inode, *dir;
34103 + unsigned int *flags = arg;
34105 + btop = au_dbtop(dentry);
34106 + /* dentry is di-locked */
34107 + parent = dget_parent(dentry);
34108 + dir = d_inode(parent);
34109 + h_dir = d_inode(h_parent);
34110 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34111 + IMustLock(h_dir);
34113 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34114 + if (unlikely(err < 0))
34116 + h_path.dentry = au_h_dptr(dentry, bdst);
34117 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34118 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34119 + if (unlikely(err))
34121 + au_fset_cpdown(*flags, MADE_DIR);
34123 + bopq = au_dbdiropq(dentry);
34124 + au_fclr_cpdown(*flags, WHED);
34125 + au_fclr_cpdown(*flags, DIROPQ);
34126 + if (au_dbwh(dentry) == bdst)
34127 + au_fset_cpdown(*flags, WHED);
34128 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34129 + au_fset_cpdown(*flags, PARENT_OPQ);
34130 + h_inode = d_inode(h_path.dentry);
34131 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34132 + if (au_ftest_cpdown(*flags, WHED)) {
34133 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34134 + if (unlikely(err)) {
34135 + inode_unlock(h_inode);
34140 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34141 + inode_unlock(h_inode);
34142 + if (unlikely(err))
34145 + if (au_ftest_cpdown(*flags, WHED)) {
34146 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34147 + if (unlikely(err))
34151 + inode = d_inode(dentry);
34152 + if (au_ibbot(inode) < bdst)
34153 + au_set_ibbot(inode, bdst);
34154 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34155 + au_hi_flags(inode, /*isdir*/1));
34156 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34157 + goto out; /* success */
34161 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34162 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34163 + rerr = au_diropq_remove(dentry, bdst);
34164 + inode_unlock(h_inode);
34165 + if (unlikely(rerr)) {
34166 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34167 + dentry, bdst, rerr);
34173 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34174 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34175 + if (unlikely(rerr)) {
34176 + AuIOErr("failed removing %pd b%d (%d)\n",
34177 + dentry, bdst, rerr);
34182 + au_set_h_dptr(dentry, bdst, NULL);
34183 + if (au_dbbot(dentry) == bdst)
34184 + au_update_dbbot(dentry);
34190 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34193 + unsigned int flags;
34196 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34201 +/* ---------------------------------------------------------------------- */
34203 +/* policies for create */
34205 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34207 + int err, i, j, ndentry;
34208 + aufs_bindex_t bopq;
34209 + struct au_dcsub_pages dpages;
34210 + struct au_dpage *dpage;
34211 + struct dentry **dentries, *parent, *d;
34213 + err = au_dpages_init(&dpages, GFP_NOFS);
34214 + if (unlikely(err))
34216 + parent = dget_parent(dentry);
34217 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34218 + if (unlikely(err))
34222 + for (i = 0; i < dpages.ndpage; i++) {
34223 + dpage = dpages.dpages + i;
34224 + dentries = dpage->dentries;
34225 + ndentry = dpage->ndentry;
34226 + for (j = 0; j < ndentry; j++) {
34228 + di_read_lock_parent2(d, !AuLock_IR);
34229 + bopq = au_dbdiropq(d);
34230 + di_read_unlock(d, !AuLock_IR);
34231 + if (bopq >= 0 && bopq < err)
34238 + au_dpages_free(&dpages);
34243 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34245 + for (; bindex >= 0; bindex--)
34246 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34251 +/* top down parent */
34252 +static int au_wbr_create_tdp(struct dentry *dentry,
34253 + unsigned int flags __maybe_unused)
34256 + aufs_bindex_t btop, bindex;
34257 + struct super_block *sb;
34258 + struct dentry *parent, *h_parent;
34260 + sb = dentry->d_sb;
34261 + btop = au_dbtop(dentry);
34263 + if (!au_br_rdonly(au_sbr(sb, btop)))
34267 + parent = dget_parent(dentry);
34268 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34269 + h_parent = au_h_dptr(parent, bindex);
34270 + if (!h_parent || d_is_negative(h_parent))
34273 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34280 + /* bottom up here */
34281 + if (unlikely(err < 0)) {
34282 + err = au_wbr_bu(sb, btop - 1);
34284 + err = au_wbr_nonopq(dentry, err);
34288 + AuDbg("b%d\n", err);
34292 +/* ---------------------------------------------------------------------- */
34294 +/* an exception for the policy other than tdp */
34295 +static int au_wbr_create_exp(struct dentry *dentry)
34298 + aufs_bindex_t bwh, bdiropq;
34299 + struct dentry *parent;
34302 + bwh = au_dbwh(dentry);
34303 + parent = dget_parent(dentry);
34304 + bdiropq = au_dbdiropq(parent);
34306 + if (bdiropq >= 0)
34307 + err = min(bdiropq, bwh);
34310 + AuDbg("%d\n", err);
34311 + } else if (bdiropq >= 0) {
34313 + AuDbg("%d\n", err);
34318 + err = au_wbr_nonopq(dentry, err);
34320 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34323 + AuDbg("%d\n", err);
34327 +/* ---------------------------------------------------------------------- */
34330 +static int au_wbr_create_init_rr(struct super_block *sb)
34334 + err = au_wbr_bu(sb, au_sbbot(sb));
34335 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34338 + AuDbg("b%d\n", err);
34342 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34346 + aufs_bindex_t bindex, bbot;
34347 + struct super_block *sb;
34350 + err = au_wbr_create_exp(dentry);
34354 + sb = dentry->d_sb;
34355 + next = &au_sbi(sb)->si_wbr_rr_next;
34356 + bbot = au_sbbot(sb);
34358 + for (bindex = 0; bindex <= bbot; bindex++) {
34359 + if (!au_ftest_wbr(flags, DIR)) {
34360 + err = atomic_dec_return(next) + 1;
34361 + /* modulo for 0 is meaningless */
34362 + if (unlikely(!err))
34363 + err = atomic_dec_return(next) + 1;
34365 + err = atomic_read(next);
34366 + AuDbg("%d\n", err);
34369 + AuDbg("%d\n", err);
34370 + if (!au_br_rdonly(au_sbr(sb, err)))
34376 + err = au_wbr_nonopq(dentry, err);
34379 + AuDbg("%d\n", err);
34383 +/* ---------------------------------------------------------------------- */
34385 +/* most free space */
34386 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34388 + struct super_block *sb;
34389 + struct au_branch *br;
34390 + struct au_wbr_mfs *mfs;
34391 + struct dentry *h_parent;
34392 + aufs_bindex_t bindex, bbot;
34394 + unsigned long long b, bavail;
34395 + struct path h_path;
34396 + /* reduce the stack usage */
34397 + struct kstatfs *st;
34399 + st = kmalloc(sizeof(*st), GFP_NOFS);
34400 + if (unlikely(!st)) {
34401 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34406 + sb = dentry->d_sb;
34407 + mfs = &au_sbi(sb)->si_wbr_mfs;
34408 + MtxMustLock(&mfs->mfs_lock);
34409 + mfs->mfs_bindex = -EROFS;
34410 + mfs->mfsrr_bytes = 0;
34413 + bbot = au_sbbot(sb);
34415 + bindex = au_dbtop(parent);
34416 + bbot = au_dbtaildir(parent);
34419 + for (; bindex <= bbot; bindex++) {
34421 + h_parent = au_h_dptr(parent, bindex);
34422 + if (!h_parent || d_is_negative(h_parent))
34425 + br = au_sbr(sb, bindex);
34426 + if (au_br_rdonly(br))
34429 + /* sb->s_root for NFS is unreliable */
34430 + h_path.mnt = au_br_mnt(br);
34431 + h_path.dentry = h_path.mnt->mnt_root;
34432 + err = vfs_statfs(&h_path, st);
34433 + if (unlikely(err)) {
34434 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34438 + /* when the available size is equal, select the lower one */
34439 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34440 + || sizeof(b) < sizeof(st->f_bsize));
34441 + b = st->f_bavail * st->f_bsize;
34442 + br->br_wbr->wbr_bytes = b;
34443 + if (b >= bavail) {
34445 + mfs->mfs_bindex = bindex;
34446 + mfs->mfs_jiffy = jiffies;
34450 + mfs->mfsrr_bytes = bavail;
34451 + AuDbg("b%d\n", mfs->mfs_bindex);
34452 + au_kfree_rcu(st);
34455 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34458 + struct dentry *parent;
34459 + struct super_block *sb;
34460 + struct au_wbr_mfs *mfs;
34462 + err = au_wbr_create_exp(dentry);
34466 + sb = dentry->d_sb;
34468 + if (au_ftest_wbr(flags, PARENT))
34469 + parent = dget_parent(dentry);
34470 + mfs = &au_sbi(sb)->si_wbr_mfs;
34471 + mutex_lock(&mfs->mfs_lock);
34472 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34473 + || mfs->mfs_bindex < 0
34474 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34475 + au_mfs(dentry, parent);
34476 + mutex_unlock(&mfs->mfs_lock);
34477 + err = mfs->mfs_bindex;
34481 + err = au_wbr_nonopq(dentry, err);
34484 + AuDbg("b%d\n", err);
34488 +static int au_wbr_create_init_mfs(struct super_block *sb)
34490 + struct au_wbr_mfs *mfs;
34492 + mfs = &au_sbi(sb)->si_wbr_mfs;
34493 + mutex_init(&mfs->mfs_lock);
34494 + mfs->mfs_jiffy = 0;
34495 + mfs->mfs_bindex = -EROFS;
34500 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34502 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34506 +/* ---------------------------------------------------------------------- */
34508 +/* top down regardless parent, and then mfs */
34509 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34510 + unsigned int flags __maybe_unused)
34513 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34514 + unsigned long long watermark;
34515 + struct super_block *sb;
34516 + struct au_wbr_mfs *mfs;
34517 + struct au_branch *br;
34518 + struct dentry *parent;
34520 + sb = dentry->d_sb;
34521 + mfs = &au_sbi(sb)->si_wbr_mfs;
34522 + mutex_lock(&mfs->mfs_lock);
34523 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34524 + || mfs->mfs_bindex < 0)
34525 + au_mfs(dentry, /*parent*/NULL);
34526 + watermark = mfs->mfsrr_watermark;
34527 + bmfs = mfs->mfs_bindex;
34528 + mutex_unlock(&mfs->mfs_lock);
34530 + /* another style of au_wbr_create_exp() */
34531 + bwh = au_dbwh(dentry);
34532 + parent = dget_parent(dentry);
34533 + btail = au_dbtaildir(parent);
34534 + if (bwh >= 0 && bwh < btail)
34537 + err = au_wbr_nonopq(dentry, btail);
34538 + if (unlikely(err < 0))
34542 + for (bindex = 0; bindex <= btail; bindex++) {
34543 + br = au_sbr(sb, bindex);
34544 + if (au_br_rdonly(br))
34546 + if (br->br_wbr->wbr_bytes > watermark) {
34557 + AuDbg("b%d\n", err);
34561 +/* ---------------------------------------------------------------------- */
34563 +/* most free space and then round robin */
34564 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34567 + struct au_wbr_mfs *mfs;
34569 + err = au_wbr_create_mfs(dentry, flags);
34571 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34572 + mutex_lock(&mfs->mfs_lock);
34573 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34574 + err = au_wbr_create_rr(dentry, flags);
34575 + mutex_unlock(&mfs->mfs_lock);
34578 + AuDbg("b%d\n", err);
34582 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34586 + au_wbr_create_init_mfs(sb); /* ignore */
34587 + err = au_wbr_create_init_rr(sb);
34592 +/* ---------------------------------------------------------------------- */
34594 +/* top down parent and most free space */
34595 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34598 + unsigned long long b;
34599 + aufs_bindex_t bindex, btop, bbot;
34600 + struct super_block *sb;
34601 + struct dentry *parent, *h_parent;
34602 + struct au_branch *br;
34604 + err = au_wbr_create_tdp(dentry, flags);
34605 + if (unlikely(err < 0))
34607 + parent = dget_parent(dentry);
34608 + btop = au_dbtop(parent);
34609 + bbot = au_dbtaildir(parent);
34610 + if (btop == bbot)
34611 + goto out_parent; /* success */
34613 + e2 = au_wbr_create_mfs(dentry, flags);
34615 + goto out_parent; /* success */
34617 + /* when the available size is equal, select upper one */
34618 + sb = dentry->d_sb;
34619 + br = au_sbr(sb, err);
34620 + b = br->br_wbr->wbr_bytes;
34621 + AuDbg("b%d, %llu\n", err, b);
34623 + for (bindex = btop; bindex <= bbot; bindex++) {
34624 + h_parent = au_h_dptr(parent, bindex);
34625 + if (!h_parent || d_is_negative(h_parent))
34628 + br = au_sbr(sb, bindex);
34629 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34630 + b = br->br_wbr->wbr_bytes;
34632 + AuDbg("b%d, %llu\n", err, b);
34637 + err = au_wbr_nonopq(dentry, err);
34642 + AuDbg("b%d\n", err);
34646 +/* ---------------------------------------------------------------------- */
34649 + * - top down parent
34650 + * - most free space with parent
34651 + * - most free space round-robin regardless parent
34653 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34656 + unsigned long long watermark;
34657 + struct super_block *sb;
34658 + struct au_branch *br;
34659 + struct au_wbr_mfs *mfs;
34661 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34662 + if (unlikely(err < 0))
34665 + sb = dentry->d_sb;
34666 + br = au_sbr(sb, err);
34667 + mfs = &au_sbi(sb)->si_wbr_mfs;
34668 + mutex_lock(&mfs->mfs_lock);
34669 + watermark = mfs->mfsrr_watermark;
34670 + mutex_unlock(&mfs->mfs_lock);
34671 + if (br->br_wbr->wbr_bytes < watermark)
34672 + /* regardless the parent dir */
34673 + err = au_wbr_create_mfsrr(dentry, flags);
34676 + AuDbg("b%d\n", err);
34680 +/* ---------------------------------------------------------------------- */
34682 +/* policies for copyup */
34684 +/* top down parent */
34685 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34687 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34690 +/* bottom up parent */
34691 +static int au_wbr_copyup_bup(struct dentry *dentry)
34694 + aufs_bindex_t bindex, btop;
34695 + struct dentry *parent, *h_parent;
34696 + struct super_block *sb;
34699 + sb = dentry->d_sb;
34700 + parent = dget_parent(dentry);
34701 + btop = au_dbtop(parent);
34702 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34703 + h_parent = au_h_dptr(parent, bindex);
34704 + if (!h_parent || d_is_negative(h_parent))
34707 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34714 + /* bottom up here */
34715 + if (unlikely(err < 0))
34716 + err = au_wbr_bu(sb, btop - 1);
34718 + AuDbg("b%d\n", err);
34723 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34727 + err = au_wbr_bu(dentry->d_sb, btop);
34728 + AuDbg("b%d\n", err);
34730 + err = au_wbr_nonopq(dentry, err);
34732 + AuDbg("b%d\n", err);
34736 +static int au_wbr_copyup_bu(struct dentry *dentry)
34739 + aufs_bindex_t btop;
34741 + btop = au_dbtop(dentry);
34742 + err = au_wbr_do_copyup_bu(dentry, btop);
34746 +/* ---------------------------------------------------------------------- */
34748 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34749 + [AuWbrCopyup_TDP] = {
34750 + .copyup = au_wbr_copyup_tdp
34752 + [AuWbrCopyup_BUP] = {
34753 + .copyup = au_wbr_copyup_bup
34755 + [AuWbrCopyup_BU] = {
34756 + .copyup = au_wbr_copyup_bu
34760 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34761 + [AuWbrCreate_TDP] = {
34762 + .create = au_wbr_create_tdp
34764 + [AuWbrCreate_RR] = {
34765 + .create = au_wbr_create_rr,
34766 + .init = au_wbr_create_init_rr
34768 + [AuWbrCreate_MFS] = {
34769 + .create = au_wbr_create_mfs,
34770 + .init = au_wbr_create_init_mfs,
34771 + .fin = au_wbr_create_fin_mfs
34773 + [AuWbrCreate_MFSV] = {
34774 + .create = au_wbr_create_mfs,
34775 + .init = au_wbr_create_init_mfs,
34776 + .fin = au_wbr_create_fin_mfs
34778 + [AuWbrCreate_MFSRR] = {
34779 + .create = au_wbr_create_mfsrr,
34780 + .init = au_wbr_create_init_mfsrr,
34781 + .fin = au_wbr_create_fin_mfs
34783 + [AuWbrCreate_MFSRRV] = {
34784 + .create = au_wbr_create_mfsrr,
34785 + .init = au_wbr_create_init_mfsrr,
34786 + .fin = au_wbr_create_fin_mfs
34788 + [AuWbrCreate_TDMFS] = {
34789 + .create = au_wbr_create_tdmfs,
34790 + .init = au_wbr_create_init_mfs,
34791 + .fin = au_wbr_create_fin_mfs
34793 + [AuWbrCreate_TDMFSV] = {
34794 + .create = au_wbr_create_tdmfs,
34795 + .init = au_wbr_create_init_mfs,
34796 + .fin = au_wbr_create_fin_mfs
34798 + [AuWbrCreate_PMFS] = {
34799 + .create = au_wbr_create_pmfs,
34800 + .init = au_wbr_create_init_mfs,
34801 + .fin = au_wbr_create_fin_mfs
34803 + [AuWbrCreate_PMFSV] = {
34804 + .create = au_wbr_create_pmfs,
34805 + .init = au_wbr_create_init_mfs,
34806 + .fin = au_wbr_create_fin_mfs
34808 + [AuWbrCreate_PMFSRR] = {
34809 + .create = au_wbr_create_pmfsrr,
34810 + .init = au_wbr_create_init_mfsrr,
34811 + .fin = au_wbr_create_fin_mfs
34813 + [AuWbrCreate_PMFSRRV] = {
34814 + .create = au_wbr_create_pmfsrr,
34815 + .init = au_wbr_create_init_mfsrr,
34816 + .fin = au_wbr_create_fin_mfs
34819 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34820 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34821 +++ linux/fs/aufs/whout.c 2020-01-27 10:57:18.178871751 +0100
34823 +// SPDX-License-Identifier: GPL-2.0
34825 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34827 + * This program, aufs is free software; you can redistribute it and/or modify
34828 + * it under the terms of the GNU General Public License as published by
34829 + * the Free Software Foundation; either version 2 of the License, or
34830 + * (at your option) any later version.
34832 + * This program is distributed in the hope that it will be useful,
34833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34835 + * GNU General Public License for more details.
34837 + * You should have received a copy of the GNU General Public License
34838 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34842 + * whiteout for logical deletion and opaque directory
34847 +#define WH_MASK 0444
34850 + * If a directory contains this file, then it is opaque. We start with the
34851 + * .wh. flag so that it is blocked by lookup.
34853 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34854 + sizeof(AUFS_WH_DIROPQ) - 1);
34857 + * generate whiteout name, which is NOT terminated by NULL.
34858 + * @name: original d_name.name
34859 + * @len: original d_name.len
34860 + * @wh: whiteout qstr
34861 + * returns zero when succeeds, otherwise error.
34862 + * succeeded value as wh->name should be freed by kfree().
34864 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34868 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34869 + return -ENAMETOOLONG;
34871 + wh->len = name->len + AUFS_WH_PFX_LEN;
34872 + p = kmalloc(wh->len, GFP_NOFS);
34875 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34876 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34883 +/* ---------------------------------------------------------------------- */
34886 + * test if the @wh_name exists under @h_parent.
34887 + * @try_sio specifies the necessary of super-io.
34889 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34892 + struct dentry *wh_dentry;
34895 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34897 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34898 + err = PTR_ERR(wh_dentry);
34899 + if (IS_ERR(wh_dentry)) {
34900 + if (err == -ENAMETOOLONG)
34906 + if (d_is_negative(wh_dentry))
34907 + goto out_wh; /* success */
34910 + if (d_is_reg(wh_dentry))
34911 + goto out_wh; /* success */
34914 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34915 + wh_dentry, d_inode(wh_dentry)->i_mode);
34924 + * test if the @h_dentry sets opaque or not.
34926 +int au_diropq_test(struct dentry *h_dentry)
34929 + struct inode *h_dir;
34931 + h_dir = d_inode(h_dentry);
34932 + err = au_wh_test(h_dentry, &diropq_name,
34933 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34938 + * returns a negative dentry whose name is unique and temporary.
34940 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34941 + struct qstr *prefix)
34943 + struct dentry *dentry;
34945 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34947 + /* strict atomic_t is unnecessary here */
34948 + static unsigned short cnt;
34951 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34954 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34955 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34956 + dentry = ERR_PTR(-ENAMETOOLONG);
34957 + if (unlikely(qs.len > NAME_MAX))
34959 + dentry = ERR_PTR(-ENOMEM);
34960 + name = kmalloc(qs.len + 1, GFP_NOFS);
34961 + if (unlikely(!name))
34965 + /* doubly whiteout-ed */
34966 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34967 + p = name + AUFS_WH_PFX_LEN * 2;
34968 + memcpy(p, prefix->name, prefix->len);
34969 + p += prefix->len;
34971 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34974 + for (i = 0; i < 3; i++) {
34975 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34976 + dentry = au_sio_lkup_one(&qs, h_parent);
34977 + if (IS_ERR(dentry) || d_is_negative(dentry))
34981 + /* pr_warn("could not get random name\n"); */
34982 + dentry = ERR_PTR(-EEXIST);
34983 + AuDbg("%.*s\n", AuLNPair(&qs));
34987 + if (name != defname)
34988 + au_kfree_try_rcu(name);
34990 + AuTraceErrPtr(dentry);
34995 + * rename the @h_dentry on @br to the whiteouted temporary name.
34997 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35000 + struct path h_path = {
35001 + .mnt = au_br_mnt(br)
35003 + struct inode *h_dir, *delegated;
35004 + struct dentry *h_parent;
35006 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35007 + h_dir = d_inode(h_parent);
35008 + IMustLock(h_dir);
35010 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35011 + err = PTR_ERR(h_path.dentry);
35012 + if (IS_ERR(h_path.dentry))
35015 + /* under the same dir, no need to lock_rename() */
35016 + delegated = NULL;
35017 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35020 + if (unlikely(err == -EWOULDBLOCK)) {
35021 + pr_warn("cannot retry for NFSv4 delegation"
35022 + " for an internal rename\n");
35025 + dput(h_path.dentry);
35032 +/* ---------------------------------------------------------------------- */
35034 + * functions for removing a whiteout
35037 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35040 + struct inode *delegated;
35043 + * forces superio when the dir has a sticky bit.
35044 + * this may be a violation of unix fs semantics.
35046 + force = (h_dir->i_mode & S_ISVTX)
35047 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35048 + delegated = NULL;
35049 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35050 + if (unlikely(err == -EWOULDBLOCK)) {
35051 + pr_warn("cannot retry for NFSv4 delegation"
35052 + " for an internal unlink\n");
35058 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35059 + struct dentry *dentry)
35063 + err = do_unlink_wh(h_dir, h_path);
35064 + if (!err && dentry)
35065 + au_set_dbwh(dentry, -1);
35070 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35071 + struct au_branch *br)
35074 + struct path h_path = {
35075 + .mnt = au_br_mnt(br)
35079 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35080 + if (IS_ERR(h_path.dentry))
35081 + err = PTR_ERR(h_path.dentry);
35083 + if (d_is_reg(h_path.dentry))
35084 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35085 + dput(h_path.dentry);
35091 +/* ---------------------------------------------------------------------- */
35093 + * initialize/clean whiteout for a branch
35096 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35100 + struct inode *delegated;
35102 + if (d_is_negative(whpath->dentry))
35106 + err = vfsub_rmdir(h_dir, whpath);
35108 + delegated = NULL;
35109 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35110 + if (unlikely(err == -EWOULDBLOCK)) {
35111 + pr_warn("cannot retry for NFSv4 delegation"
35112 + " for an internal unlink\n");
35116 + if (unlikely(err))
35117 + pr_warn("failed removing %pd (%d), ignored.\n",
35118 + whpath->dentry, err);
35121 +static int test_linkable(struct dentry *h_root)
35123 + struct inode *h_dir = d_inode(h_root);
35125 + if (h_dir->i_op->link)
35128 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35129 + h_root, au_sbtype(h_root->d_sb));
35130 + return -ENOSYS; /* the branch doesn't have its ->link() */
35133 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35134 +static int au_whdir(struct inode *h_dir, struct path *path)
35139 + if (d_is_negative(path->dentry)) {
35142 + if (au_test_nfs(path->dentry->d_sb))
35144 + err = vfsub_mkdir(h_dir, path, mode);
35145 + } else if (d_is_dir(path->dentry))
35148 + pr_err("unknown %pd exists\n", path->dentry);
35153 +struct au_wh_base {
35154 + const struct qstr *name;
35155 + struct dentry *dentry;
35158 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35159 + struct path *h_path)
35161 + h_path->dentry = base[AuBrWh_BASE].dentry;
35162 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35163 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35164 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35165 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35166 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35170 + * returns tri-state,
35171 + * minus: error, caller should print the message
35173 + * plus: error, caller should NOT print the message
35175 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35176 + int do_plink, struct au_wh_base base[],
35177 + struct path *h_path)
35180 + struct inode *h_dir;
35182 + h_dir = d_inode(h_root);
35183 + h_path->dentry = base[AuBrWh_BASE].dentry;
35184 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35185 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35187 + err = test_linkable(h_root);
35188 + if (unlikely(err)) {
35193 + err = au_whdir(h_dir, h_path);
35194 + if (unlikely(err))
35196 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35198 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35199 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35200 + err = au_whdir(h_dir, h_path);
35201 + if (unlikely(err))
35203 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35210 + * for the moment, aufs supports the branch filesystem which does not support
35211 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35212 + * copyup failed. finally, such filesystem will not be used as the writable
35215 + * returns tri-state, see above.
35217 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35218 + int do_plink, struct au_wh_base base[],
35219 + struct path *h_path)
35222 + struct inode *h_dir;
35224 + WbrWhMustWriteLock(wbr);
35226 + err = test_linkable(h_root);
35227 + if (unlikely(err)) {
35233 + * todo: should this create be done in /sbin/mount.aufs helper?
35236 + h_dir = d_inode(h_root);
35237 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35238 + h_path->dentry = base[AuBrWh_BASE].dentry;
35239 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35240 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35243 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35244 + if (unlikely(err))
35247 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35249 + err = au_whdir(h_dir, h_path);
35250 + if (unlikely(err))
35252 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35254 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35255 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35257 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35258 + err = au_whdir(h_dir, h_path);
35259 + if (unlikely(err))
35261 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35268 + * initialize the whiteout base file/dir for @br.
35270 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35273 + const unsigned char do_plink
35274 + = !!au_opt_test(au_mntflags(sb), PLINK);
35275 + struct inode *h_dir;
35276 + struct path path = br->br_path;
35277 + struct dentry *h_root = path.dentry;
35278 + struct au_wbr *wbr = br->br_wbr;
35279 + static const struct qstr base_name[] = {
35280 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35281 + sizeof(AUFS_BASE_NAME) - 1),
35282 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35283 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35284 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35285 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35287 + struct au_wh_base base[] = {
35288 + [AuBrWh_BASE] = {
35289 + .name = base_name + AuBrWh_BASE,
35292 + [AuBrWh_PLINK] = {
35293 + .name = base_name + AuBrWh_PLINK,
35296 + [AuBrWh_ORPH] = {
35297 + .name = base_name + AuBrWh_ORPH,
35303 + WbrWhMustWriteLock(wbr);
35305 + for (i = 0; i < AuBrWh_Last; i++) {
35306 + /* doubly whiteouted */
35307 + struct dentry *d;
35309 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35310 + err = PTR_ERR(d);
35314 + base[i].dentry = d;
35316 + && wbr->wbr_wh[i]
35317 + && wbr->wbr_wh[i] != base[i].dentry);
35321 + for (i = 0; i < AuBrWh_Last; i++) {
35322 + dput(wbr->wbr_wh[i]);
35323 + wbr->wbr_wh[i] = NULL;
35327 + if (!au_br_writable(br->br_perm)) {
35328 + h_dir = d_inode(h_root);
35329 + au_wh_init_ro(h_dir, base, &path);
35330 + } else if (!au_br_wh_linkable(br->br_perm)) {
35331 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35337 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35343 + goto out; /* success */
35346 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35347 + err, h_root, au_sbtype(h_root->d_sb));
35349 + for (i = 0; i < AuBrWh_Last; i++)
35350 + dput(base[i].dentry);
35354 +/* ---------------------------------------------------------------------- */
35356 + * whiteouts are all hard-linked usually.
35357 + * when its link count reaches a ceiling, we create a new whiteout base
35358 + * asynchronously.
35361 +struct reinit_br_wh {
35362 + struct super_block *sb;
35363 + struct au_branch *br;
35366 +static void reinit_br_wh(void *arg)
35369 + aufs_bindex_t bindex;
35370 + struct path h_path;
35371 + struct reinit_br_wh *a = arg;
35372 + struct au_wbr *wbr;
35373 + struct inode *dir, *delegated;
35374 + struct dentry *h_root;
35375 + struct au_hinode *hdir;
35378 + wbr = a->br->br_wbr;
35379 + /* big aufs lock */
35380 + si_noflush_write_lock(a->sb);
35381 + if (!au_br_writable(a->br->br_perm))
35383 + bindex = au_br_index(a->sb, a->br->br_id);
35384 + if (unlikely(bindex < 0))
35387 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35388 + dir = d_inode(a->sb->s_root);
35389 + hdir = au_hi(dir, bindex);
35390 + h_root = au_h_dptr(a->sb->s_root, bindex);
35391 + AuDebugOn(h_root != au_br_dentry(a->br));
35393 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35394 + wbr_wh_write_lock(wbr);
35395 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35398 + h_path.dentry = wbr->wbr_whbase;
35399 + h_path.mnt = au_br_mnt(a->br);
35400 + delegated = NULL;
35401 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35403 + if (unlikely(err == -EWOULDBLOCK)) {
35404 + pr_warn("cannot retry for NFSv4 delegation"
35405 + " for an internal unlink\n");
35409 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35412 + dput(wbr->wbr_whbase);
35413 + wbr->wbr_whbase = NULL;
35415 + err = au_wh_init(a->br, a->sb);
35416 + wbr_wh_write_unlock(wbr);
35417 + au_hn_inode_unlock(hdir);
35418 + di_read_unlock(a->sb->s_root, AuLock_IR);
35420 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35424 + atomic_dec(&wbr->wbr_wh_running);
35425 + au_lcnt_dec(&a->br->br_count);
35426 + si_write_unlock(a->sb);
35427 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35429 + if (unlikely(err))
35430 + AuIOErr("err %d\n", err);
35433 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35435 + int do_dec, wkq_err;
35436 + struct reinit_br_wh *arg;
35439 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35442 + /* ignore ENOMEM */
35443 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35446 + * dec(wh_running), kfree(arg) and dec(br_count)
35447 + * in reinit function
35451 + au_lcnt_inc(&br->br_count);
35452 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35453 + if (unlikely(wkq_err)) {
35454 + atomic_dec(&br->br_wbr->wbr_wh_running);
35455 + au_lcnt_dec(&br->br_count);
35456 + au_kfree_rcu(arg);
35463 + atomic_dec(&br->br_wbr->wbr_wh_running);
35466 +/* ---------------------------------------------------------------------- */
35469 + * create the whiteout @wh.
35471 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35472 + struct dentry *wh)
35475 + struct path h_path = {
35478 + struct au_branch *br;
35479 + struct au_wbr *wbr;
35480 + struct dentry *h_parent;
35481 + struct inode *h_dir, *delegated;
35483 + h_parent = wh->d_parent; /* dir inode is locked */
35484 + h_dir = d_inode(h_parent);
35485 + IMustLock(h_dir);
35487 + br = au_sbr(sb, bindex);
35488 + h_path.mnt = au_br_mnt(br);
35489 + wbr = br->br_wbr;
35490 + wbr_wh_read_lock(wbr);
35491 + if (wbr->wbr_whbase) {
35492 + delegated = NULL;
35493 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35494 + if (unlikely(err == -EWOULDBLOCK)) {
35495 + pr_warn("cannot retry for NFSv4 delegation"
35496 + " for an internal link\n");
35499 + if (!err || err != -EMLINK)
35502 + /* link count full. re-initialize br_whbase. */
35503 + kick_reinit_br_wh(sb, br);
35506 + /* return this error in this context */
35507 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35509 + au_fhsm_wrote(sb, bindex, /*force*/0);
35512 + wbr_wh_read_unlock(wbr);
35516 +/* ---------------------------------------------------------------------- */
35519 + * create or remove the diropq.
35521 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35522 + unsigned int flags)
35524 + struct dentry *opq_dentry, *h_dentry;
35525 + struct super_block *sb;
35526 + struct au_branch *br;
35529 + sb = dentry->d_sb;
35530 + br = au_sbr(sb, bindex);
35531 + h_dentry = au_h_dptr(dentry, bindex);
35532 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35533 + if (IS_ERR(opq_dentry))
35536 + if (au_ftest_diropq(flags, CREATE)) {
35537 + err = link_or_create_wh(sb, bindex, opq_dentry);
35539 + au_set_dbdiropq(dentry, bindex);
35540 + goto out; /* success */
35543 + struct path tmp = {
35544 + .dentry = opq_dentry,
35545 + .mnt = au_br_mnt(br)
35547 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35549 + au_set_dbdiropq(dentry, -1);
35551 + dput(opq_dentry);
35552 + opq_dentry = ERR_PTR(err);
35555 + return opq_dentry;
35558 +struct do_diropq_args {
35559 + struct dentry **errp;
35560 + struct dentry *dentry;
35561 + aufs_bindex_t bindex;
35562 + unsigned int flags;
35565 +static void call_do_diropq(void *args)
35567 + struct do_diropq_args *a = args;
35568 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35571 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35572 + unsigned int flags)
35574 + struct dentry *diropq, *h_dentry;
35576 + h_dentry = au_h_dptr(dentry, bindex);
35577 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35578 + diropq = do_diropq(dentry, bindex, flags);
35581 + struct do_diropq_args args = {
35583 + .dentry = dentry,
35584 + .bindex = bindex,
35588 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35589 + if (unlikely(wkq_err))
35590 + diropq = ERR_PTR(wkq_err);
35596 +/* ---------------------------------------------------------------------- */
35599 + * lookup whiteout dentry.
35600 + * @h_parent: lower parent dentry which must exist and be locked
35601 + * @base_name: name of dentry which will be whiteouted
35602 + * returns dentry for whiteout.
35604 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35605 + struct au_branch *br)
35608 + struct qstr wh_name;
35609 + struct dentry *wh_dentry;
35611 + err = au_wh_name_alloc(&wh_name, base_name);
35612 + wh_dentry = ERR_PTR(err);
35614 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35615 + au_kfree_try_rcu(wh_name.name);
35617 + return wh_dentry;
35621 + * link/create a whiteout for @dentry on @bindex.
35623 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35624 + struct dentry *h_parent)
35626 + struct dentry *wh_dentry;
35627 + struct super_block *sb;
35630 + sb = dentry->d_sb;
35631 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35632 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35633 + err = link_or_create_wh(sb, bindex, wh_dentry);
35635 + au_set_dbwh(dentry, bindex);
35636 + au_fhsm_wrote(sb, bindex, /*force*/0);
35639 + wh_dentry = ERR_PTR(err);
35643 + return wh_dentry;
35646 +/* ---------------------------------------------------------------------- */
35648 +/* Delete all whiteouts in this directory on branch bindex. */
35649 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35650 + aufs_bindex_t bindex, struct au_branch *br)
35653 + unsigned long ul, n;
35654 + struct qstr wh_name;
35656 + struct hlist_head *head;
35657 + struct au_vdir_wh *pos;
35658 + struct au_vdir_destr *str;
35661 + p = (void *)__get_free_page(GFP_NOFS);
35662 + wh_name.name = p;
35663 + if (unlikely(!wh_name.name))
35667 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35668 + p += AUFS_WH_PFX_LEN;
35669 + n = whlist->nh_num;
35670 + head = whlist->nh_head;
35671 + for (ul = 0; !err && ul < n; ul++, head++) {
35672 + hlist_for_each_entry(pos, head, wh_hash) {
35673 + if (pos->wh_bindex != bindex)
35676 + str = &pos->wh_str;
35677 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35678 + memcpy(p, str->name, str->len);
35679 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35680 + err = unlink_wh_name(h_dentry, &wh_name, br);
35685 + AuIOErr("whiteout name too long %.*s\n",
35686 + str->len, str->name);
35691 + free_page((unsigned long)wh_name.name);
35697 +struct del_wh_children_args {
35699 + struct dentry *h_dentry;
35700 + struct au_nhash *whlist;
35701 + aufs_bindex_t bindex;
35702 + struct au_branch *br;
35705 +static void call_del_wh_children(void *args)
35707 + struct del_wh_children_args *a = args;
35708 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35711 +/* ---------------------------------------------------------------------- */
35713 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35715 + struct au_whtmp_rmdir *whtmp;
35717 + unsigned int rdhash;
35719 + SiMustAnyLock(sb);
35721 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35722 + if (unlikely(!whtmp)) {
35723 + whtmp = ERR_PTR(-ENOMEM);
35727 + /* no estimation for dir size */
35728 + rdhash = au_sbi(sb)->si_rdhash;
35730 + rdhash = AUFS_RDHASH_DEF;
35731 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35732 + if (unlikely(err)) {
35733 + au_kfree_rcu(whtmp);
35734 + whtmp = ERR_PTR(err);
35741 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35744 + au_lcnt_dec(&whtmp->br->br_count);
35745 + dput(whtmp->wh_dentry);
35746 + iput(whtmp->dir);
35747 + au_nhash_wh_free(&whtmp->whlist);
35748 + au_kfree_rcu(whtmp);
35752 + * rmdir the whiteouted temporary named dir @h_dentry.
35753 + * @whlist: whiteouted children.
35755 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35756 + struct dentry *wh_dentry, struct au_nhash *whlist)
35759 + unsigned int h_nlink;
35760 + struct path h_tmp;
35761 + struct inode *wh_inode, *h_dir;
35762 + struct au_branch *br;
35764 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35765 + IMustLock(h_dir);
35767 + br = au_sbr(dir->i_sb, bindex);
35768 + wh_inode = d_inode(wh_dentry);
35769 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35772 + * someone else might change some whiteouts while we were sleeping.
35773 + * it means this whlist may have an obsoleted entry.
35775 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35776 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35779 + struct del_wh_children_args args = {
35781 + .h_dentry = wh_dentry,
35782 + .whlist = whlist,
35783 + .bindex = bindex,
35787 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35788 + if (unlikely(wkq_err))
35791 + inode_unlock(wh_inode);
35794 + h_tmp.dentry = wh_dentry;
35795 + h_tmp.mnt = au_br_mnt(br);
35796 + h_nlink = h_dir->i_nlink;
35797 + err = vfsub_rmdir(h_dir, &h_tmp);
35798 + /* some fs doesn't change the parent nlink in some cases */
35799 + h_nlink -= h_dir->i_nlink;
35803 + if (au_ibtop(dir) == bindex) {
35804 + /* todo: dir->i_mutex is necessary */
35805 + au_cpup_attr_timesizes(dir);
35807 + vfsub_drop_nlink(dir);
35809 + return 0; /* success */
35812 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35816 +static void call_rmdir_whtmp(void *args)
35819 + aufs_bindex_t bindex;
35820 + struct au_whtmp_rmdir *a = args;
35821 + struct super_block *sb;
35822 + struct dentry *h_parent;
35823 + struct inode *h_dir;
35824 + struct au_hinode *hdir;
35826 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35827 + /* inode_lock(a->dir); */
35829 + sb = a->dir->i_sb;
35830 + si_read_lock(sb, !AuLock_FLUSH);
35831 + if (!au_br_writable(a->br->br_perm))
35833 + bindex = au_br_index(sb, a->br->br_id);
35834 + if (unlikely(bindex < 0))
35838 + ii_write_lock_parent(a->dir);
35839 + h_parent = dget_parent(a->wh_dentry);
35840 + h_dir = d_inode(h_parent);
35841 + hdir = au_hi(a->dir, bindex);
35842 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35843 + if (unlikely(err))
35845 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35846 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35849 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35850 + au_hn_inode_unlock(hdir);
35851 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35855 + ii_write_unlock(a->dir);
35857 + /* inode_unlock(a->dir); */
35858 + au_whtmp_rmdir_free(a);
35859 + si_read_unlock(sb);
35860 + au_nwt_done(&au_sbi(sb)->si_nowait);
35861 + if (unlikely(err))
35862 + AuIOErr("err %d\n", err);
35865 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35866 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35869 + struct super_block *sb;
35873 + /* all post-process will be done in do_rmdir_whtmp(). */
35875 + args->dir = au_igrab(dir);
35876 + args->br = au_sbr(sb, bindex);
35877 + au_lcnt_inc(&args->br->br_count);
35878 + args->wh_dentry = dget(wh_dentry);
35879 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35880 + if (unlikely(wkq_err)) {
35881 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35882 + au_whtmp_rmdir_free(args);
35885 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35886 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35887 +++ linux/fs/aufs/whout.h 2020-01-27 10:57:18.178871751 +0100
35889 +/* SPDX-License-Identifier: GPL-2.0 */
35891 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35893 + * This program, aufs is free software; you can redistribute it and/or modify
35894 + * it under the terms of the GNU General Public License as published by
35895 + * the Free Software Foundation; either version 2 of the License, or
35896 + * (at your option) any later version.
35898 + * This program is distributed in the hope that it will be useful,
35899 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35900 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35901 + * GNU General Public License for more details.
35903 + * You should have received a copy of the GNU General Public License
35904 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35908 + * whiteout for logical deletion and opaque directory
35911 +#ifndef __AUFS_WHOUT_H__
35912 +#define __AUFS_WHOUT_H__
35919 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35920 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35921 +int au_diropq_test(struct dentry *h_dentry);
35923 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35924 + struct qstr *prefix);
35925 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35926 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35927 + struct dentry *dentry);
35928 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35930 +/* diropq flags */
35931 +#define AuDiropq_CREATE 1
35932 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35933 +#define au_fset_diropq(flags, name) \
35934 + do { (flags) |= AuDiropq_##name; } while (0)
35935 +#define au_fclr_diropq(flags, name) \
35936 + do { (flags) &= ~AuDiropq_##name; } while (0)
35938 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35939 + unsigned int flags);
35940 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35941 + struct au_branch *br);
35942 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35943 + struct dentry *h_parent);
35945 +/* real rmdir for the whiteout-ed dir */
35946 +struct au_whtmp_rmdir {
35947 + struct inode *dir;
35948 + struct au_branch *br;
35949 + struct dentry *wh_dentry;
35950 + struct au_nhash whlist;
35953 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35954 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35955 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35956 + struct dentry *wh_dentry, struct au_nhash *whlist);
35957 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35958 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35960 +/* ---------------------------------------------------------------------- */
35962 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35963 + aufs_bindex_t bindex)
35965 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35968 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35970 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35973 +#endif /* __KERNEL__ */
35974 +#endif /* __AUFS_WHOUT_H__ */
35975 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35976 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35977 +++ linux/fs/aufs/wkq.c 2020-04-03 08:16:47.547461775 +0200
35979 +// SPDX-License-Identifier: GPL-2.0
35981 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35983 + * This program, aufs is free software; you can redistribute it and/or modify
35984 + * it under the terms of the GNU General Public License as published by
35985 + * the Free Software Foundation; either version 2 of the License, or
35986 + * (at your option) any later version.
35988 + * This program is distributed in the hope that it will be useful,
35989 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35990 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35991 + * GNU General Public License for more details.
35993 + * You should have received a copy of the GNU General Public License
35994 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35998 + * workqueue for asynchronous/super-io operations
35999 + * todo: try new credential scheme
36002 +#include <linux/module.h>
36005 +/* internal workqueue named AUFS_WKQ_NAME */
36007 +static struct workqueue_struct *au_wkq;
36009 +struct au_wkinfo {
36010 + struct work_struct wk;
36011 + struct kobject *kobj;
36013 + unsigned int flags; /* see wkq.h */
36015 + au_wkq_func_t func;
36018 +#ifdef CONFIG_LOCKDEP
36020 + struct held_lock **hlock;
36023 + struct completion *comp;
36026 +/* ---------------------------------------------------------------------- */
36028 + * Aufs passes some operations to the workqueue such as the internal copyup.
36029 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36030 + * job run by workqueue depends upon the locks acquired in the other task.
36031 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36032 + * information too. And the job in the workqueue restores the info in order to
36033 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36034 + * correctly and expectedly.
36037 +#ifndef CONFIG_LOCKDEP
36038 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36039 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36040 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36041 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36042 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36044 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36046 + wkinfo->hlock = NULL;
36047 + wkinfo->dont_check = 0;
36054 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36056 + static DEFINE_SPINLOCK(spin);
36059 + struct lock_class_key *key;
36061 + { .name = "&sbinfo->si_rwsem" },
36062 + { .name = "&finfo->fi_rwsem" },
36063 + { .name = "&dinfo->di_rwsem" },
36064 + { .name = "&iinfo->ii_rwsem" }
36069 + /* lockless read from 'set.' see below */
36070 + if (set == ARRAY_SIZE(a)) {
36071 + for (i = 0; i < ARRAY_SIZE(a); i++)
36072 + if (a[i].key == key)
36077 + spin_lock(&spin);
36079 + for (i = 0; i < ARRAY_SIZE(a); i++)
36080 + if (a[i].key == key) {
36081 + spin_unlock(&spin);
36084 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36086 + if (unlikely(a[i].key == key)) { /* rare but possible */
36087 + spin_unlock(&spin);
36092 + if (strstr(a[i].name, name)) {
36094 + * the order of these three lines is important for the
36095 + * lockless read above.
36098 + spin_unlock(&spin);
36100 + /* AuDbg("%d, %s\n", set, name); */
36104 + spin_unlock(&spin);
36113 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36116 + struct task_struct *curr;
36117 + struct held_lock **hl, *held_locks, *p;
36121 + wkinfo->dont_check = lockdep_recursing(curr);
36122 + if (wkinfo->dont_check)
36124 + n = curr->lockdep_depth;
36129 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36130 + if (unlikely(!wkinfo->hlock))
36134 +#if 0 /* left for debugging */
36135 + if (0 && au_debug_test())
36136 + lockdep_print_held_locks(curr);
36138 + held_locks = curr->held_locks;
36139 + hl = wkinfo->hlock;
36141 + p = held_locks++;
36142 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36151 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36153 + au_kfree_try_rcu(wkinfo->hlock);
36156 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36158 + struct held_lock *p, **hl = wkinfo->hlock;
36161 + if (wkinfo->dont_check)
36165 + while ((p = *hl++)) { /* assignment */
36166 + subclass = lockdep_hlock_class(p)->subclass;
36167 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36169 + rwsem_acquire_read(p->instance, subclass, 0,
36170 + /*p->acquire_ip*/_RET_IP_);
36172 + rwsem_acquire(p->instance, subclass, 0,
36173 + /*p->acquire_ip*/_RET_IP_);
36177 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36179 + struct held_lock *p, **hl = wkinfo->hlock;
36181 + if (wkinfo->dont_check)
36185 + while ((p = *hl++)) /* assignment */
36186 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36190 +static void wkq_func(struct work_struct *wk)
36192 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36194 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36195 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36197 + au_wkq_lockdep_pre(wkinfo);
36198 + wkinfo->func(wkinfo->args);
36199 + au_wkq_lockdep_post(wkinfo);
36200 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36201 + complete(wkinfo->comp);
36203 + kobject_put(wkinfo->kobj);
36204 + module_put(THIS_MODULE); /* todo: ?? */
36205 + au_kfree_rcu(wkinfo);
36210 + * Since struct completion is large, try allocating it dynamically.
36212 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36214 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36216 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36218 + init_completion(*comp);
36219 + wkinfo->comp = *comp;
36225 +static void au_wkq_comp_free(struct completion *comp)
36227 + au_kfree_rcu(comp);
36230 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36232 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36233 + if (au_wkq_test()) {
36234 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36235 + " due to a dead dir by UDBA,"
36236 + " or async xino write?\n");
36237 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36240 + au_dbg_verify_kthread();
36242 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36243 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36244 + queue_work(au_wkq, &wkinfo->wk);
36246 + INIT_WORK(&wkinfo->wk, wkq_func);
36247 + schedule_work(&wkinfo->wk);
36252 + * Be careful. It is easy to make deadlock happen.
36253 + * processA: lock, wkq and wait
36254 + * processB: wkq and wait, lock in wkq
36257 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36260 + AuWkqCompDeclare(comp);
36261 + struct au_wkinfo wkinfo = {
36267 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36268 + if (unlikely(err))
36270 + err = au_wkq_lockdep_alloc(&wkinfo);
36271 + if (unlikely(err))
36274 + au_wkq_run(&wkinfo);
36275 + /* no timeout, no interrupt */
36276 + wait_for_completion(wkinfo.comp);
36278 + au_wkq_lockdep_free(&wkinfo);
36281 + au_wkq_comp_free(comp);
36283 + destroy_work_on_stack(&wkinfo.wk);
36288 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36289 + * problem in a concurrent umounting.
36291 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36292 + unsigned int flags)
36295 + struct au_wkinfo *wkinfo;
36297 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36300 + * wkq_func() must free this wkinfo.
36301 + * it highly depends upon the implementation of workqueue.
36304 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36306 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36307 + wkinfo->flags = flags & ~AuWkq_WAIT;
36308 + wkinfo->func = func;
36309 + wkinfo->args = args;
36310 + wkinfo->comp = NULL;
36311 + au_wkq_lockdep_init(wkinfo);
36312 + kobject_get(wkinfo->kobj);
36313 + __module_get(THIS_MODULE); /* todo: ?? */
36315 + au_wkq_run(wkinfo);
36318 + au_nwt_done(&au_sbi(sb)->si_nowait);
36324 +/* ---------------------------------------------------------------------- */
36326 +void au_nwt_init(struct au_nowait_tasks *nwt)
36328 + atomic_set(&nwt->nw_len, 0);
36329 + /* smp_mb(); */ /* atomic_set */
36330 + init_waitqueue_head(&nwt->nw_wq);
36333 +void au_wkq_fin(void)
36335 + destroy_workqueue(au_wkq);
36338 +int __init au_wkq_init(void)
36343 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36344 + if (IS_ERR(au_wkq))
36345 + err = PTR_ERR(au_wkq);
36346 + else if (!au_wkq)
36351 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36352 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36353 +++ linux/fs/aufs/wkq.h 2020-01-27 10:57:18.182205184 +0100
36355 +/* SPDX-License-Identifier: GPL-2.0 */
36357 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36359 + * This program, aufs is free software; you can redistribute it and/or modify
36360 + * it under the terms of the GNU General Public License as published by
36361 + * the Free Software Foundation; either version 2 of the License, or
36362 + * (at your option) any later version.
36364 + * This program is distributed in the hope that it will be useful,
36365 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36366 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36367 + * GNU General Public License for more details.
36369 + * You should have received a copy of the GNU General Public License
36370 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36374 + * workqueue for asynchronous/super-io operations
36375 + * todo: try new credentials management scheme
36378 +#ifndef __AUFS_WKQ_H__
36379 +#define __AUFS_WKQ_H__
36383 +#include <linux/wait.h>
36385 +struct super_block;
36387 +/* ---------------------------------------------------------------------- */
36390 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36392 +struct au_nowait_tasks {
36394 + wait_queue_head_t nw_wq;
36397 +/* ---------------------------------------------------------------------- */
36399 +typedef void (*au_wkq_func_t)(void *args);
36402 +#define AuWkq_WAIT 1
36403 +#define AuWkq_NEST (1 << 1)
36404 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36405 +#define au_fset_wkq(flags, name) \
36406 + do { (flags) |= AuWkq_##name; } while (0)
36407 +#define au_fclr_wkq(flags, name) \
36408 + do { (flags) &= ~AuWkq_##name; } while (0)
36411 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36412 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36413 + unsigned int flags);
36414 +void au_nwt_init(struct au_nowait_tasks *nwt);
36415 +int __init au_wkq_init(void);
36416 +void au_wkq_fin(void);
36418 +/* ---------------------------------------------------------------------- */
36420 +static inline int au_wkq_test(void)
36422 + return current->flags & PF_WQ_WORKER;
36425 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36427 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36430 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36432 + if (atomic_dec_and_test(&nwt->nw_len))
36433 + wake_up_all(&nwt->nw_wq);
36436 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36438 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36442 +#endif /* __KERNEL__ */
36443 +#endif /* __AUFS_WKQ_H__ */
36444 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36445 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36446 +++ linux/fs/aufs/xattr.c 2020-01-27 10:57:18.182205184 +0100
36448 +// SPDX-License-Identifier: GPL-2.0
36450 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36452 + * This program, aufs is free software; you can redistribute it and/or modify
36453 + * it under the terms of the GNU General Public License as published by
36454 + * the Free Software Foundation; either version 2 of the License, or
36455 + * (at your option) any later version.
36457 + * This program is distributed in the hope that it will be useful,
36458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36460 + * GNU General Public License for more details.
36462 + * You should have received a copy of the GNU General Public License
36463 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36467 + * handling xattr functions
36470 +#include <linux/fs.h>
36471 +#include <linux/posix_acl_xattr.h>
36472 +#include <linux/xattr.h>
36475 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36477 + if (!ignore_flags)
36485 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36490 +#define cmp(brattr, prefix) do { \
36491 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36492 + XATTR_##prefix##_PREFIX_LEN)) { \
36493 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36499 + cmp(SEC, SECURITY);
36500 + cmp(SYS, SYSTEM);
36501 + cmp(TR, TRUSTED);
36505 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36512 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36514 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36515 + char *name, char **buf, unsigned int ignore_flags,
36516 + unsigned int verbose)
36520 + struct inode *h_idst;
36522 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36524 + if (unlikely(err <= 0)) {
36525 + if (err == -ENODATA
36526 + || (err == -EOPNOTSUPP
36527 + && ((ignore_flags & au_xattr_out_of_list)
36528 + || (au_test_nfs_noacl(d_inode(h_src))
36529 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36531 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36534 + if (err && (verbose || au_debug_test()))
36535 + pr_err("%s, err %d\n", name, err);
36539 + /* unlock it temporary */
36540 + h_idst = d_inode(h_dst);
36541 + inode_unlock(h_idst);
36542 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36543 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36544 + if (unlikely(err)) {
36545 + if (verbose || au_debug_test())
36546 + pr_err("%s, err %d\n", name, err);
36547 + err = au_xattr_ignore(err, name, ignore_flags);
36554 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36555 + unsigned int verbose)
36557 + int err, unlocked, acl_access, acl_default;
36559 + struct inode *h_isrc, *h_idst;
36560 + char *value, *p, *o, *e;
36562 + /* try stopping to update the source inode while we are referencing */
36563 + /* there should not be the parent-child relationship between them */
36564 + h_isrc = d_inode(h_src);
36565 + h_idst = d_inode(h_dst);
36566 + inode_unlock(h_idst);
36567 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36568 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36571 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36572 + ssz = vfs_listxattr(h_src, NULL, 0);
36574 + if (unlikely(err < 0)) {
36576 + if (err == -ENODATA
36577 + || err == -EOPNOTSUPP)
36578 + err = 0; /* ignore */
36587 + p = kmalloc(ssz, GFP_NOFS);
36589 + if (unlikely(!p))
36591 + err = vfs_listxattr(h_src, p, ssz);
36593 + inode_unlock_shared(h_isrc);
36595 + AuDbg("err %d, ssz %zd\n", err, ssz);
36596 + if (unlikely(err < 0))
36604 + while (!err && p < e) {
36605 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36606 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36607 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36608 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36610 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36612 + p += strlen(p) + 1;
36615 + ignore_flags |= au_xattr_out_of_list;
36616 + if (!err && !acl_access) {
36617 + err = au_do_cpup_xattr(h_dst, h_src,
36618 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36619 + ignore_flags, verbose);
36622 + if (!err && !acl_default) {
36623 + err = au_do_cpup_xattr(h_dst, h_src,
36624 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36625 + ignore_flags, verbose);
36629 + au_kfree_try_rcu(value);
36632 + au_kfree_try_rcu(o);
36635 + inode_unlock_shared(h_isrc);
36640 +/* ---------------------------------------------------------------------- */
36642 +static int au_smack_reentering(struct super_block *sb)
36644 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36646 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36647 + * i_op->getxattr(). ouch.
36649 + return si_pid_test(sb);
36660 +struct au_lgxattr {
36668 + const char *name;
36675 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36679 + struct path h_path;
36680 + struct super_block *sb;
36682 + sb = dentry->d_sb;
36683 + reenter = au_smack_reentering(sb);
36685 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36686 + if (unlikely(err))
36689 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36690 + if (unlikely(err))
36692 + if (unlikely(!h_path.dentry))
36693 + /* illegally overlapped or something */
36694 + goto out_di; /* pretending success */
36696 + /* always topmost entry only */
36697 + switch (arg->type) {
36698 + case AU_XATTR_LIST:
36699 + err = vfs_listxattr(h_path.dentry,
36700 + arg->u.list.list, arg->u.list.size);
36702 + case AU_XATTR_GET:
36703 + AuDebugOn(d_is_negative(h_path.dentry));
36704 + err = vfs_getxattr(h_path.dentry,
36705 + arg->u.get.name, arg->u.get.value,
36706 + arg->u.get.size);
36712 + di_read_unlock(dentry, AuLock_IR);
36715 + si_read_unlock(sb);
36721 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36723 + struct au_lgxattr arg = {
36724 + .type = AU_XATTR_LIST,
36731 + return au_lgxattr(dentry, &arg);
36734 +static ssize_t au_getxattr(struct dentry *dentry,
36735 + struct inode *inode __maybe_unused,
36736 + const char *name, void *value, size_t size)
36738 + struct au_lgxattr arg = {
36739 + .type = AU_XATTR_GET,
36747 + return au_lgxattr(dentry, &arg);
36750 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36751 + const char *name, const void *value, size_t size,
36754 + struct au_sxattr arg = {
36755 + .type = AU_XATTR_SET,
36764 + return au_sxattr(dentry, inode, &arg);
36767 +/* ---------------------------------------------------------------------- */
36769 +static int au_xattr_get(const struct xattr_handler *handler,
36770 + struct dentry *dentry, struct inode *inode,
36771 + const char *name, void *buffer, size_t size)
36773 + return au_getxattr(dentry, inode, name, buffer, size);
36776 +static int au_xattr_set(const struct xattr_handler *handler,
36777 + struct dentry *dentry, struct inode *inode,
36778 + const char *name, const void *value, size_t size,
36781 + return au_setxattr(dentry, inode, name, value, size, flags);
36784 +static const struct xattr_handler au_xattr_handler = {
36787 + .get = au_xattr_get,
36788 + .set = au_xattr_set
36791 +static const struct xattr_handler *au_xattr_handlers[] = {
36792 +#ifdef CONFIG_FS_POSIX_ACL
36793 + &posix_acl_access_xattr_handler,
36794 + &posix_acl_default_xattr_handler,
36796 + &au_xattr_handler, /* must be last */
36800 +void au_xattr_init(struct super_block *sb)
36802 + sb->s_xattr = au_xattr_handlers;
36804 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36805 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36806 +++ linux/fs/aufs/xino.c 2020-04-03 08:16:49.834195677 +0200
36808 +// SPDX-License-Identifier: GPL-2.0
36810 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36812 + * This program, aufs is free software; you can redistribute it and/or modify
36813 + * it under the terms of the GNU General Public License as published by
36814 + * the Free Software Foundation; either version 2 of the License, or
36815 + * (at your option) any later version.
36817 + * This program is distributed in the hope that it will be useful,
36818 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36819 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36820 + * GNU General Public License for more details.
36822 + * You should have received a copy of the GNU General Public License
36823 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36827 + * external inode number translation table and bitmap
36829 + * things to consider
36831 + * + au_xino object
36832 + * + XINO files (xino, xib, xigen)
36833 + * + dynamic debugfs entries (xiN)
36834 + * + static debugfs entries (xib, xigen)
36835 + * + static sysfs entry (xi_path)
36836 + * - several entry points to handle them.
36837 + * + mount(2) without xino option (default)
36838 + * + mount(2) with xino option
36839 + * + mount(2) with noxino option
36841 + * + remount with add/del branches
36842 + * + remount with xino/noxino options
36845 +#include <linux/seq_file.h>
36846 +#include <linux/statfs.h>
36849 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36850 + aufs_bindex_t bbot,
36851 + struct super_block *h_sb)
36853 + /* todo: try binary-search if the branches are many */
36854 + for (; btop <= bbot; btop++)
36855 + if (h_sb == au_sbr_sb(sb, btop))
36861 + * find another branch who is on the same filesystem of the specified
36862 + * branch{@btgt}. search until @bbot.
36864 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36865 + aufs_bindex_t bbot)
36867 + aufs_bindex_t bindex;
36868 + struct super_block *tgt_sb;
36870 + tgt_sb = au_sbr_sb(sb, btgt);
36871 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36873 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36878 +/* ---------------------------------------------------------------------- */
36881 + * stop unnecessary notify events at creating xino files
36884 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36886 + aufs_bindex_t bfound, bindex, bbot;
36887 + struct dentry *parent;
36888 + struct au_branch *br;
36891 + parent = dentry->d_parent; /* safe d_parent access */
36892 + bbot = au_sbbot(sb);
36893 + for (bindex = 0; bindex <= bbot; bindex++) {
36894 + br = au_sbr(sb, bindex);
36895 + if (au_br_dentry(br) == parent) {
36901 + AuDbg("bfound b%d\n", bfound);
36905 +struct au_xino_lock_dir {
36906 + struct au_hinode *hdir;
36907 + struct dentry *parent;
36908 + struct inode *dir;
36911 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36912 + unsigned int lsc)
36914 + struct dentry *parent;
36915 + struct inode *dir;
36917 + parent = dget_parent(dentry);
36918 + dir = d_inode(parent);
36919 + inode_lock_nested(dir, lsc);
36920 +#if 0 /* it should not happen */
36921 + spin_lock(&dentry->d_lock);
36922 + if (unlikely(dentry->d_parent != parent)) {
36923 + spin_unlock(&dentry->d_lock);
36924 + inode_unlock(dir);
36929 + spin_unlock(&dentry->d_lock);
36936 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36937 + struct au_xino_lock_dir *ldir)
36939 + aufs_bindex_t bindex;
36941 + ldir->hdir = NULL;
36942 + bindex = au_xi_root(sb, xipath->dentry);
36943 + if (bindex >= 0) {
36944 + /* rw branch root */
36945 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36946 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36949 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36951 + ldir->dir = d_inode(ldir->parent);
36955 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36958 + au_hn_inode_unlock(ldir->hdir);
36960 + inode_unlock(ldir->dir);
36961 + dput(ldir->parent);
36965 +/* ---------------------------------------------------------------------- */
36968 + * create and set a new xino file
36970 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36973 + struct file *file;
36974 + struct dentry *h_parent, *d;
36975 + struct inode *h_dir, *inode;
36977 + static DEFINE_MUTEX(mtx);
36980 + * at mount-time, and the xino file is the default path,
36981 + * hnotify is disabled so we have no notify events to ignore.
36982 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36985 + mutex_lock(&mtx);
36986 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36987 + /* | __FMODE_NONOTIFY */,
36989 + if (IS_ERR(file)) {
36991 + mutex_unlock(&mtx);
36993 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36997 + /* keep file count */
36999 + d = file->f_path.dentry;
37000 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37002 + mutex_unlock(&mtx);
37003 + /* mnt_want_write() is unnecessary here */
37004 + h_dir = d_inode(h_parent);
37005 + inode = file_inode(file);
37006 + /* no delegation since it is just created */
37007 + if (inode->i_nlink)
37008 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37010 + inode_unlock(h_dir);
37012 + if (unlikely(err)) {
37014 + pr_err("unlink %s(%d)\n", fpath, err);
37019 + if (unlikely(sb == d->d_sb)) {
37021 + pr_err("%s must be outside\n", fpath);
37024 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37026 + pr_err("xino doesn't support %s(%s)\n",
37027 + fpath, au_sbtype(d->d_sb));
37030 + return file; /* success */
37034 + file = ERR_PTR(err);
37039 + * create a new xinofile at the same place/path as @base.
37041 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37042 + struct file *copy_src)
37044 + struct file *file;
37045 + struct dentry *dentry, *parent;
37046 + struct inode *dir, *delegated;
37047 + struct qstr *name;
37048 + struct path path;
37049 + int err, do_unlock;
37050 + struct au_xino_lock_dir ldir;
37053 + au_xino_lock_dir(sb, base, &ldir);
37054 + dentry = base->dentry;
37055 + parent = dentry->d_parent; /* dir inode is locked */
37056 + dir = d_inode(parent);
37059 + name = &dentry->d_name;
37060 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37061 + if (IS_ERR(path.dentry)) {
37062 + file = (void *)path.dentry;
37063 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37067 + /* no need to mnt_want_write() since we call dentry_open() later */
37068 + err = vfs_create(dir, path.dentry, 0666, NULL);
37069 + if (unlikely(err)) {
37070 + file = ERR_PTR(err);
37071 + pr_err("%pd create err %d\n", dentry, err);
37075 + path.mnt = base->mnt;
37076 + file = vfsub_dentry_open(&path,
37077 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37078 + /* | __FMODE_NONOTIFY */);
37079 + if (IS_ERR(file)) {
37080 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37084 + delegated = NULL;
37085 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37086 + au_xino_unlock_dir(&ldir);
37088 + if (unlikely(err == -EWOULDBLOCK)) {
37089 + pr_warn("cannot retry for NFSv4 delegation"
37090 + " for an internal unlink\n");
37093 + if (unlikely(err)) {
37094 + pr_err("%pd unlink err %d\n", dentry, err);
37099 + /* no one can touch copy_src xino */
37100 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37101 + if (unlikely(err)) {
37102 + pr_err("%pd copy err %d\n", dentry, err);
37106 + goto out_dput; /* success */
37110 + file = ERR_PTR(err);
37112 + dput(path.dentry);
37115 + au_xino_unlock_dir(&ldir);
37119 +struct file *au_xino_file1(struct au_xino *xi)
37121 + struct file *file;
37122 + unsigned int u, nfile;
37125 + nfile = xi->xi_nfile;
37126 + for (u = 0; u < nfile; u++) {
37127 + file = xi->xi_file[u];
37135 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37146 + if (idx < xi->xi_nfile) {
37147 + f = xi->xi_file[idx];
37151 + p = au_kzrealloc(xi->xi_file,
37152 + sizeof(*xi->xi_file) * xi->xi_nfile,
37153 + sizeof(*xi->xi_file) * (idx + 1),
37154 + GFP_NOFS, /*may_shrink*/0);
37156 + MtxMustLock(&xi->xi_mtx);
37158 + xi->xi_nfile = idx + 1;
37166 + xi->xi_file[idx] = file;
37173 + * if @xinew->xi is not set, then create new xigen file.
37175 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37177 + struct file *file;
37180 + SiMustAnyLock(sb);
37182 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37183 + if (IS_ERR(file)) {
37184 + err = PTR_ERR(file);
37185 + pr_err("%s[%d], err %d\n",
37186 + xinew->xi ? "xino" : "xigen",
37187 + xinew->idx, err);
37192 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37195 + /* todo: make xigen file an array */
37196 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37199 + if (unlikely(err))
37200 + file = ERR_PTR(err);
37206 +/* ---------------------------------------------------------------------- */
37209 + * truncate xino files
37211 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37212 + int idx, struct kstatfs *st)
37216 + struct file *file, *new_xino;
37217 + struct au_xi_new xinew = {
37222 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37223 + file = au_xino_file(xinew.xi, idx);
37227 + xinew.base = &file->f_path;
37228 + err = vfs_statfs(xinew.base, st);
37229 + if (unlikely(err)) {
37230 + AuErr1("statfs err %d, ignored\n", err);
37235 + blocks = file_inode(file)->i_blocks;
37236 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37237 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37239 + xinew.copy_src = file;
37240 + new_xino = au_xi_new(sb, &xinew);
37241 + if (IS_ERR(new_xino)) {
37242 + err = PTR_ERR(new_xino);
37243 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37247 + err = vfs_statfs(&new_xino->f_path, st);
37249 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37250 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37251 + st->f_bfree, st->f_blocks);
37253 + AuErr1("statfs err %d, ignored\n", err);
37261 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37264 + unsigned long jiffy;
37265 + aufs_bindex_t bbot;
37266 + struct kstatfs *st;
37267 + struct au_branch *br;
37268 + struct au_xino *xi;
37271 + st = kmalloc(sizeof(*st), GFP_NOFS);
37272 + if (unlikely(!st))
37276 + bbot = au_sbbot(sb);
37277 + if (unlikely(bindex < 0 || bbot < bindex))
37282 + br = au_sbr(sb, bindex);
37283 + xi = br->br_xino;
37284 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37285 + err = au_xino_do_trunc(sb, bindex, i, st);
37287 + au_sbi(sb)->si_xino_jiffy = jiffy;
37290 + au_kfree_rcu(st);
37295 +struct xino_do_trunc_args {
37296 + struct super_block *sb;
37297 + struct au_branch *br;
37301 +static void xino_do_trunc(void *_args)
37303 + struct xino_do_trunc_args *args = _args;
37304 + struct super_block *sb;
37305 + struct au_branch *br;
37306 + struct inode *dir;
37308 + aufs_bindex_t bindex;
37312 + dir = d_inode(sb->s_root);
37316 + si_noflush_write_lock(sb);
37317 + ii_read_lock_parent(dir);
37318 + bindex = au_br_index(sb, br->br_id);
37319 + err = au_xino_trunc(sb, bindex, idx);
37320 + ii_read_unlock(dir);
37321 + if (unlikely(err))
37322 + pr_warn("err b%d, (%d)\n", bindex, err);
37323 + atomic_dec(&br->br_xino->xi_truncating);
37324 + au_lcnt_dec(&br->br_count);
37325 + si_write_unlock(sb);
37326 + au_nwt_done(&au_sbi(sb)->si_nowait);
37327 + au_kfree_rcu(args);
37331 + * returns the index in the xi_file array whose corresponding file is necessary
37332 + * to truncate, or -1 which means no need to truncate.
37334 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37338 + struct kstatfs st;
37339 + struct au_sbinfo *sbinfo;
37340 + struct au_xino *xi;
37341 + struct file *file;
37343 + /* todo: si_xino_expire and the ratio should be customizable */
37344 + sbinfo = au_sbi(sb);
37345 + if (time_before(jiffies,
37346 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37349 + /* truncation border */
37350 + xi = br->br_xino;
37351 + for (u = 0; u < xi->xi_nfile; u++) {
37352 + file = au_xino_file(xi, u);
37356 + err = vfs_statfs(&file->f_path, &st);
37357 + if (unlikely(err)) {
37358 + AuErr1("statfs err %d, ignored\n", err);
37361 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37362 + >= AUFS_XINO_DEF_TRUNC)
37369 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37372 + struct xino_do_trunc_args *args;
37375 + idx = xino_trunc_test(sb, br);
37379 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37382 + /* lock and kfree() will be called in trunc_xino() */
37383 + args = kmalloc(sizeof(*args), GFP_NOFS);
37384 + if (unlikely(!args)) {
37385 + AuErr1("no memory\n");
37389 + au_lcnt_inc(&br->br_count);
37393 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37395 + return; /* success */
37397 + pr_err("wkq %d\n", wkq_err);
37398 + au_lcnt_dec(&br->br_count);
37399 + au_kfree_rcu(args);
37402 + atomic_dec(&br->br_xino->xi_truncating);
37405 +/* ---------------------------------------------------------------------- */
37407 +struct au_xi_calc {
37412 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37413 + struct au_xi_calc *calc)
37417 + maxent = au_xi_maxent(sb);
37418 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37419 + calc->pos *= sizeof(ino_t);
37422 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37423 + struct au_xi_calc *calc)
37426 + struct file *file;
37427 + struct au_xino *xi = br->br_xino;
37428 + struct au_xi_new xinew = {
37432 + SiMustAnyLock(sb);
37438 + mutex_lock(&xi->xi_mtx);
37439 + file = au_xino_file(xi, calc->idx);
37443 + file = au_xino_file(xi, /*idx*/-1);
37444 + AuDebugOn(!file);
37445 + xinew.idx = calc->idx;
37446 + xinew.base = &file->f_path;
37447 + /* xinew.copy_src = NULL; */
37448 + file = au_xi_new(sb, &xinew);
37449 + if (IS_ERR(file))
37450 + err = PTR_ERR(file);
37453 + mutex_unlock(&xi->xi_mtx);
37458 +struct au_xino_do_new_async_args {
37459 + struct super_block *sb;
37460 + struct au_branch *br;
37461 + struct au_xi_calc calc;
37465 +struct au_xi_writing {
37466 + struct hlist_bl_node node;
37467 + ino_t h_ino, ino;
37470 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37471 + struct au_xi_calc *calc, ino_t ino);
37473 +static void au_xino_call_do_new_async(void *args)
37475 + struct au_xino_do_new_async_args *a = args;
37476 + struct au_branch *br;
37477 + struct super_block *sb;
37478 + struct au_sbinfo *sbi;
37479 + struct inode *root;
37480 + struct file *file;
37481 + struct au_xi_writing *del, *p;
37482 + struct hlist_bl_head *hbl;
37483 + struct hlist_bl_node *pos;
37488 + sbi = au_sbi(sb);
37489 + si_noflush_read_lock(sb);
37490 + root = d_inode(sb->s_root);
37491 + ii_read_lock_child(root);
37492 + err = au_xino_do_new_async(sb, br, &a->calc);
37493 + if (unlikely(err)) {
37494 + AuIOErr("err %d\n", err);
37498 + file = au_xino_file(br->br_xino, a->calc.idx);
37499 + AuDebugOn(!file);
37500 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37501 + if (unlikely(err)) {
37502 + AuIOErr("err %d\n", err);
37507 + hbl = &br->br_xino->xi_writing;
37508 + hlist_bl_lock(hbl);
37509 + au_hbl_for_each(pos, hbl) {
37510 + p = container_of(pos, struct au_xi_writing, node);
37511 + if (p->ino == a->ino) {
37513 + hlist_bl_del(&p->node);
37517 + hlist_bl_unlock(hbl);
37518 + au_kfree_rcu(del);
37521 + au_lcnt_dec(&br->br_count);
37522 + ii_read_unlock(root);
37523 + si_read_unlock(sb);
37524 + au_nwt_done(&sbi->si_nowait);
37529 + * create a new xino file asynchronously
37531 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37532 + struct au_xi_calc *calc, ino_t ino)
37535 + struct au_xino_do_new_async_args *arg;
37538 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37539 + if (unlikely(!arg))
37544 + arg->calc = *calc;
37546 + au_lcnt_inc(&br->br_count);
37547 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37548 + if (unlikely(err)) {
37549 + pr_err("wkq %d\n", err);
37550 + au_lcnt_dec(&br->br_count);
37551 + au_kfree_rcu(arg);
37559 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37560 + * at the position of @h_ino.
37562 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37567 + struct au_xi_calc calc;
37568 + struct au_sbinfo *sbinfo;
37569 + struct file *file;
37570 + struct au_xino *xi;
37571 + struct hlist_bl_head *hbl;
37572 + struct hlist_bl_node *pos;
37573 + struct au_xi_writing *p;
37576 + if (!au_opt_test(au_mntflags(sb), XINO))
37577 + return 0; /* no xino */
37580 + au_xi_calc(sb, h_ino, &calc);
37581 + xi = au_sbr(sb, bindex)->br_xino;
37582 + file = au_xino_file(xi, calc.idx);
37584 + hbl = &xi->xi_writing;
37585 + hlist_bl_lock(hbl);
37586 + au_hbl_for_each(pos, hbl) {
37587 + p = container_of(pos, struct au_xi_writing, node);
37588 + if (p->h_ino == h_ino) {
37589 + AuDbg("hi%llu, i%llu, found\n",
37590 + (u64)p->h_ino, (u64)p->ino);
37595 + hlist_bl_unlock(hbl);
37597 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37598 + return 0; /* no xino */
37600 + sbinfo = au_sbi(sb);
37601 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37602 + if (sz == sizeof(*ino))
37603 + return 0; /* success */
37606 + if (unlikely(sz >= 0)) {
37608 + AuIOErr("xino read error (%zd)\n", sz);
37613 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37614 + struct au_xi_calc *calc, ino_t ino)
37618 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37619 + if (sz == sizeof(ino))
37620 + return 0; /* success */
37622 + AuIOErr("write failed (%zd)\n", sz);
37627 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37628 + * at the position of @h_ino.
37629 + * even if @ino is zero, it is written to the xinofile and means no entry.
37630 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37631 + * try truncating it.
37633 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37637 + unsigned int mnt_flags;
37638 + struct au_xi_calc calc;
37639 + struct file *file;
37640 + struct au_branch *br;
37641 + struct au_xino *xi;
37642 + struct au_xi_writing *p;
37644 + SiMustAnyLock(sb);
37646 + mnt_flags = au_mntflags(sb);
37647 + if (!au_opt_test(mnt_flags, XINO))
37650 + au_xi_calc(sb, h_ino, &calc);
37651 + br = au_sbr(sb, bindex);
37652 + xi = br->br_xino;
37653 + file = au_xino_file(xi, calc.idx);
37655 + /* store the inum pair into the list */
37656 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37657 + p->h_ino = h_ino;
37659 + au_hbl_add(&p->node, &xi->xi_writing);
37661 + /* create and write a new xino file asynchronously */
37662 + err = au_xino_new_async(sb, br, &calc, ino);
37664 + return 0; /* success */
37668 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37670 + br = au_sbr(sb, bindex);
37671 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37672 + && au_test_fs_trunc_xino(au_br_sb(br)))
37673 + xino_try_trunc(sb, br);
37674 + return 0; /* success */
37678 + AuIOErr("write failed (%d)\n", err);
37682 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37683 + size_t size, loff_t *pos);
37685 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37686 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37690 + mm_segment_t oldfs;
37696 + const int prevent_endless = 10;
37700 + oldfs = get_fs();
37701 + set_fs(KERNEL_DS);
37703 + err = func(file, buf.u, size, pos);
37704 + if (err == -EINTR
37705 + && !au_wkq_test()
37706 + && fatal_signal_pending(current)) {
37708 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37709 + BUG_ON(err == -EINTR);
37710 + oldfs = get_fs();
37711 + set_fs(KERNEL_DS);
37713 + } while (i++ < prevent_endless
37714 + && (err == -EAGAIN || err == -EINTR));
37717 +#if 0 /* reserved for future use */
37719 + fsnotify_access(file->f_path.dentry);
37725 +struct xino_fread_args {
37727 + vfs_readf_t func;
37728 + struct file *file;
37734 +static void call_xino_fread(void *args)
37736 + struct xino_fread_args *a = args;
37737 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37740 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37741 + size_t size, loff_t *pos)
37745 + struct xino_fread_args args = {
37754 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37755 + if (unlikely(wkq_err))
37761 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37762 + size_t size, loff_t *pos);
37764 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37765 + size_t size, loff_t *pos)
37768 + mm_segment_t oldfs;
37771 + const char __user *u;
37774 + const int prevent_endless = 10;
37778 + oldfs = get_fs();
37779 + set_fs(KERNEL_DS);
37781 + err = func(file, buf.u, size, pos);
37782 + if (err == -EINTR
37783 + && !au_wkq_test()
37784 + && fatal_signal_pending(current)) {
37786 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37787 + BUG_ON(err == -EINTR);
37788 + oldfs = get_fs();
37789 + set_fs(KERNEL_DS);
37791 + } while (i++ < prevent_endless
37792 + && (err == -EAGAIN || err == -EINTR));
37795 +#if 0 /* reserved for future use */
37797 + fsnotify_modify(file->f_path.dentry);
37803 +struct do_xino_fwrite_args {
37805 + vfs_writef_t func;
37806 + struct file *file;
37812 +static void call_do_xino_fwrite(void *args)
37814 + struct do_xino_fwrite_args *a = args;
37815 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37818 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37819 + size_t size, loff_t *pos)
37823 + struct do_xino_fwrite_args args = {
37833 + * it breaks RLIMIT_FSIZE and normal user's limit,
37834 + * users should care about quota and real 'filesystem full.'
37836 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37837 + if (unlikely(wkq_err))
37843 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37844 + size_t size, loff_t *pos)
37848 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37850 + err = do_xino_fwrite(func, file, buf, size, pos);
37854 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37861 +/* ---------------------------------------------------------------------- */
37864 + * inode number bitmap
37866 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37867 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37871 + AuDebugOn(bit < 0 || page_bits <= bit);
37872 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37876 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37878 + AuDebugOn(ino < AUFS_FIRST_INO);
37879 + ino -= AUFS_FIRST_INO;
37880 + *pindex = ino / page_bits;
37881 + *bit = ino % page_bits;
37884 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37889 + struct au_sbinfo *sbinfo;
37890 + struct file *xib;
37891 + unsigned long *p;
37893 + sbinfo = au_sbi(sb);
37894 + MtxMustLock(&sbinfo->si_xib_mtx);
37895 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37896 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37898 + if (pindex == sbinfo->si_xib_last_pindex)
37901 + xib = sbinfo->si_xib;
37902 + p = sbinfo->si_xib_buf;
37903 + pos = sbinfo->si_xib_last_pindex;
37904 + pos *= PAGE_SIZE;
37905 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37906 + if (unlikely(sz != PAGE_SIZE))
37910 + pos *= PAGE_SIZE;
37911 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37912 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37914 + memset(p, 0, PAGE_SIZE);
37915 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37917 + if (sz == PAGE_SIZE) {
37918 + sbinfo->si_xib_last_pindex = pindex;
37919 + return 0; /* success */
37923 + AuIOErr1("write failed (%zd)\n", sz);
37930 +static void au_xib_clear_bit(struct inode *inode)
37933 + unsigned long pindex;
37934 + struct super_block *sb;
37935 + struct au_sbinfo *sbinfo;
37937 + AuDebugOn(inode->i_nlink);
37939 + sb = inode->i_sb;
37940 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37941 + AuDebugOn(page_bits <= bit);
37942 + sbinfo = au_sbi(sb);
37943 + mutex_lock(&sbinfo->si_xib_mtx);
37944 + err = xib_pindex(sb, pindex);
37946 + clear_bit(bit, sbinfo->si_xib_buf);
37947 + sbinfo->si_xib_next_bit = bit;
37949 + mutex_unlock(&sbinfo->si_xib_mtx);
37952 +/* ---------------------------------------------------------------------- */
37955 + * truncate a xino bitmap file
37959 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37963 + unsigned long pindex;
37964 + loff_t pos, pend;
37965 + struct au_sbinfo *sbinfo;
37966 + vfs_readf_t func;
37968 + unsigned long *p;
37971 + sbinfo = au_sbi(sb);
37972 + MtxMustLock(&sbinfo->si_xib_mtx);
37973 + p = sbinfo->si_xib_buf;
37974 + func = sbinfo->si_xread;
37975 + pend = vfsub_f_size_read(file);
37977 + while (pos < pend) {
37978 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
37980 + if (unlikely(sz <= 0))
37984 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37985 + if (unlikely(*ino < AUFS_FIRST_INO))
37988 + xib_calc_bit(*ino, &pindex, &bit);
37989 + AuDebugOn(page_bits <= bit);
37990 + err = xib_pindex(sb, pindex);
38002 +static int xib_restore(struct super_block *sb)
38005 + unsigned int nfile;
38006 + aufs_bindex_t bindex, bbot;
38008 + struct au_branch *br;
38009 + struct au_xino *xi;
38010 + struct file *file;
38013 + page = (void *)__get_free_page(GFP_NOFS);
38014 + if (unlikely(!page))
38018 + bbot = au_sbbot(sb);
38019 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38020 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38021 + br = au_sbr(sb, bindex);
38022 + xi = br->br_xino;
38023 + nfile = xi->xi_nfile;
38024 + for (i = 0; i < nfile; i++) {
38025 + file = au_xino_file(xi, i);
38027 + err = do_xib_restore(sb, file, page);
38030 + AuDbg("skip shared b%d\n", bindex);
38031 + free_page((unsigned long)page);
38037 +int au_xib_trunc(struct super_block *sb)
38042 + struct au_sbinfo *sbinfo;
38043 + unsigned long *p;
38044 + struct file *file;
38046 + SiMustWriteLock(sb);
38049 + sbinfo = au_sbi(sb);
38050 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38053 + file = sbinfo->si_xib;
38054 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38057 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38058 + err = PTR_ERR(file);
38059 + if (IS_ERR(file))
38061 + fput(sbinfo->si_xib);
38062 + sbinfo->si_xib = file;
38064 + p = sbinfo->si_xib_buf;
38065 + memset(p, 0, PAGE_SIZE);
38067 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38068 + if (unlikely(sz != PAGE_SIZE)) {
38070 + AuIOErr("err %d\n", err);
38076 + mutex_lock(&sbinfo->si_xib_mtx);
38077 + /* mnt_want_write() is unnecessary here */
38078 + err = xib_restore(sb);
38079 + mutex_unlock(&sbinfo->si_xib_mtx);
38085 +/* ---------------------------------------------------------------------- */
38087 +struct au_xino *au_xino_alloc(unsigned int nfile)
38089 + struct au_xino *xi;
38091 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38092 + if (unlikely(!xi))
38094 + xi->xi_nfile = nfile;
38095 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38096 + if (unlikely(!xi->xi_file))
38099 + xi->xi_nondir.total = 8; /* initial size */
38100 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38102 + if (unlikely(!xi->xi_nondir.array))
38105 + spin_lock_init(&xi->xi_nondir.spin);
38106 + init_waitqueue_head(&xi->xi_nondir.wqh);
38107 + mutex_init(&xi->xi_mtx);
38108 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38109 + atomic_set(&xi->xi_truncating, 0);
38110 + kref_init(&xi->xi_kref);
38111 + goto out; /* success */
38114 + au_kfree_try_rcu(xi->xi_file);
38116 + au_kfree_rcu(xi);
38122 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38125 + struct au_xino *xi;
38128 + xi = au_xino_alloc(idx + 1);
38129 + if (unlikely(!xi)) {
38136 + xi->xi_file[idx] = file;
38137 + AuDebugOn(br->br_xino);
38138 + br->br_xino = xi;
38144 +static void au_xino_release(struct kref *kref)
38146 + struct au_xino *xi;
38148 + unsigned long ul;
38149 + struct hlist_bl_head *hbl;
38150 + struct hlist_bl_node *pos, *n;
38151 + struct au_xi_writing *p;
38153 + xi = container_of(kref, struct au_xino, xi_kref);
38154 + for (i = 0; i < xi->xi_nfile; i++)
38155 + if (xi->xi_file[i])
38156 + fput(xi->xi_file[i]);
38157 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38158 + AuDebugOn(xi->xi_nondir.array[i]);
38159 + mutex_destroy(&xi->xi_mtx);
38160 + hbl = &xi->xi_writing;
38161 + ul = au_hbl_count(hbl);
38162 + if (unlikely(ul)) {
38163 + pr_warn("xi_writing %lu\n", ul);
38164 + hlist_bl_lock(hbl);
38165 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38166 + hlist_bl_del(&p->node);
38167 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38170 + hlist_bl_unlock(hbl);
38172 + au_kfree_try_rcu(xi->xi_file);
38173 + au_kfree_try_rcu(xi->xi_nondir.array);
38174 + au_kfree_rcu(xi);
38177 +int au_xino_put(struct au_branch *br)
38180 + struct au_xino *xi;
38183 + xi = br->br_xino;
38185 + br->br_xino = NULL;
38186 + ret = kref_put(&xi->xi_kref, au_xino_release);
38192 +/* ---------------------------------------------------------------------- */
38195 + * xino mount option handlers
38199 +static void xino_clear_xib(struct super_block *sb)
38201 + struct au_sbinfo *sbinfo;
38203 + SiMustWriteLock(sb);
38205 + sbinfo = au_sbi(sb);
38206 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38207 + if (sbinfo->si_xib)
38208 + fput(sbinfo->si_xib);
38209 + sbinfo->si_xib = NULL;
38210 + if (sbinfo->si_xib_buf)
38211 + free_page((unsigned long)sbinfo->si_xib_buf);
38212 + sbinfo->si_xib_buf = NULL;
38215 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38219 + struct au_sbinfo *sbinfo;
38220 + struct file *file;
38221 + struct super_block *xi_sb;
38223 + SiMustWriteLock(sb);
38225 + sbinfo = au_sbi(sb);
38226 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38227 + err = PTR_ERR(file);
38228 + if (IS_ERR(file))
38230 + if (sbinfo->si_xib)
38231 + fput(sbinfo->si_xib);
38232 + sbinfo->si_xib = file;
38233 + sbinfo->si_xread = vfs_readf(file);
38234 + sbinfo->si_xwrite = vfs_writef(file);
38235 + xi_sb = file_inode(file)->i_sb;
38236 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38237 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38239 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38240 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38243 + sbinfo->si_ximaxent /= sizeof(ino_t);
38246 + if (!sbinfo->si_xib_buf)
38247 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38248 + if (unlikely(!sbinfo->si_xib_buf))
38251 + sbinfo->si_xib_last_pindex = 0;
38252 + sbinfo->si_xib_next_bit = 0;
38253 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38255 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38256 + PAGE_SIZE, &pos);
38257 + if (unlikely(err != PAGE_SIZE))
38261 + goto out; /* success */
38264 + if (sbinfo->si_xib_buf)
38265 + free_page((unsigned long)sbinfo->si_xib_buf);
38266 + sbinfo->si_xib_buf = NULL;
38270 + fput(sbinfo->si_xib);
38271 + sbinfo->si_xib = NULL;
38277 +/* xino for each branch */
38278 +static void xino_clear_br(struct super_block *sb)
38280 + aufs_bindex_t bindex, bbot;
38281 + struct au_branch *br;
38283 + bbot = au_sbbot(sb);
38284 + for (bindex = 0; bindex <= bbot; bindex++) {
38285 + br = au_sbr(sb, bindex);
38291 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38292 + aufs_bindex_t bshared)
38294 + struct au_branch *brshared;
38296 + brshared = au_sbr(sb, bshared);
38297 + AuDebugOn(!brshared->br_xino);
38298 + AuDebugOn(!brshared->br_xino->xi_file);
38299 + if (br->br_xino != brshared->br_xino) {
38300 + au_xino_get(brshared);
38302 + br->br_xino = brshared->br_xino;
38306 +struct au_xino_do_set_br {
38307 + vfs_writef_t writef;
38308 + struct au_branch *br;
38310 + aufs_bindex_t bshared;
38313 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38314 + struct au_xino_do_set_br *args)
38317 + struct au_xi_calc calc;
38318 + struct file *file;
38319 + struct au_branch *br;
38320 + struct au_xi_new xinew = {
38325 + xinew.xi = br->br_xino;
38326 + au_xi_calc(sb, args->h_ino, &calc);
38327 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38328 + if (args->bshared >= 0)
38329 + /* shared xino */
38330 + au_xino_set_br_shared(sb, br, args->bshared);
38331 + else if (!xinew.xi) {
38333 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38334 + if (unlikely(err))
38338 + /* force re-creating */
38339 + xinew.xi = br->br_xino;
38340 + xinew.idx = calc.idx;
38341 + mutex_lock(&xinew.xi->xi_mtx);
38342 + file = au_xi_new(sb, &xinew);
38343 + mutex_unlock(&xinew.xi->xi_mtx);
38344 + err = PTR_ERR(file);
38345 + if (IS_ERR(file))
38347 + AuDebugOn(!file);
38349 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38350 + if (unlikely(err))
38358 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38361 + aufs_bindex_t bindex, bbot;
38362 + struct au_xino_do_set_br args;
38363 + struct inode *inode;
38365 + SiMustWriteLock(sb);
38367 + bbot = au_sbbot(sb);
38368 + inode = d_inode(sb->s_root);
38369 + args.writef = au_sbi(sb)->si_xwrite;
38370 + for (bindex = 0; bindex <= bbot; bindex++) {
38371 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38372 + args.br = au_sbr(sb, bindex);
38373 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38374 + err = au_xino_do_set_br(sb, path, &args);
38375 + if (unlikely(err))
38383 +void au_xino_clr(struct super_block *sb)
38385 + struct au_sbinfo *sbinfo;
38387 + au_xigen_clr(sb);
38388 + xino_clear_xib(sb);
38389 + xino_clear_br(sb);
38390 + dbgaufs_brs_del(sb, 0);
38391 + sbinfo = au_sbi(sb);
38392 + /* lvalue, do not call au_mntflags() */
38393 + au_opt_clr(sbinfo->si_mntflags, XINO);
38396 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38399 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38400 + struct qstr *dname, *cur_name;
38401 + struct file *cur_xino;
38402 + struct au_sbinfo *sbinfo;
38403 + struct path *path, *cur_path;
38405 + SiMustWriteLock(sb);
38408 + sbinfo = au_sbi(sb);
38409 + path = &xiopt->file->f_path;
38410 + dentry = path->dentry;
38411 + parent = dget_parent(dentry);
38414 + cur_xino = sbinfo->si_xib;
38416 + cur_path = &cur_xino->f_path;
38417 + cur_dentry = cur_path->dentry;
38418 + cur_parent = dget_parent(cur_dentry);
38419 + cur_name = &cur_dentry->d_name;
38420 + dname = &dentry->d_name;
38421 + skip = (cur_parent == parent
38422 + && au_qstreq(dname, cur_name));
38423 + dput(cur_parent);
38429 + au_opt_set(sbinfo->si_mntflags, XINO);
38430 + err = au_xino_set_xib(sb, path);
38431 + /* si_x{read,write} are set */
38433 + err = au_xigen_set(sb, path);
38435 + err = au_xino_set_br(sb, path);
38437 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38438 + goto out; /* success */
38442 + AuIOErr("failed setting xino(%d).\n", err);
38451 + * create a xinofile at the default place/path.
38453 +struct file *au_xino_def(struct super_block *sb)
38455 + struct file *file;
38457 + struct au_branch *br;
38458 + struct super_block *h_sb;
38459 + struct path path;
38460 + aufs_bindex_t bbot, bindex, bwr;
38463 + bbot = au_sbbot(sb);
38465 + for (bindex = 0; bindex <= bbot; bindex++) {
38466 + br = au_sbr(sb, bindex);
38467 + if (au_br_writable(br->br_perm)
38468 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38475 + file = ERR_PTR(-ENOMEM);
38476 + page = (void *)__get_free_page(GFP_NOFS);
38477 + if (unlikely(!page))
38479 + path.mnt = au_br_mnt(br);
38480 + path.dentry = au_h_dptr(sb->s_root, bwr);
38481 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38482 + file = (void *)p;
38483 + if (!IS_ERR(p)) {
38484 + strcat(p, "/" AUFS_XINO_FNAME);
38485 + AuDbg("%s\n", p);
38486 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38488 + free_page((unsigned long)page);
38490 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38492 + if (IS_ERR(file))
38494 + h_sb = file->f_path.dentry->d_sb;
38495 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38496 + pr_err("xino doesn't support %s(%s)\n",
38497 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38499 + file = ERR_PTR(-EINVAL);
38507 +/* ---------------------------------------------------------------------- */
38510 + * initialize the xinofile for the specified branch @br
38511 + * at the place/path where @base_file indicates.
38512 + * test whether another branch is on the same filesystem or not,
38513 + * if found then share the xinofile with another branch.
38515 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38516 + struct path *base)
38519 + struct au_xino_do_set_br args = {
38524 + args.writef = au_sbi(sb)->si_xwrite;
38525 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38527 + err = au_xino_do_set_br(sb, base, &args);
38528 + if (unlikely(err))
38534 +/* ---------------------------------------------------------------------- */
38537 + * get an unused inode number from bitmap
38539 +ino_t au_xino_new_ino(struct super_block *sb)
38542 + unsigned long *p, pindex, ul, pend;
38543 + struct au_sbinfo *sbinfo;
38544 + struct file *file;
38545 + int free_bit, err;
38547 + if (!au_opt_test(au_mntflags(sb), XINO))
38548 + return iunique(sb, AUFS_FIRST_INO);
38550 + sbinfo = au_sbi(sb);
38551 + mutex_lock(&sbinfo->si_xib_mtx);
38552 + p = sbinfo->si_xib_buf;
38553 + free_bit = sbinfo->si_xib_next_bit;
38554 + if (free_bit < page_bits && !test_bit(free_bit, p))
38555 + goto out; /* success */
38556 + free_bit = find_first_zero_bit(p, page_bits);
38557 + if (free_bit < page_bits)
38558 + goto out; /* success */
38560 + pindex = sbinfo->si_xib_last_pindex;
38561 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38562 + err = xib_pindex(sb, ul);
38563 + if (unlikely(err))
38565 + free_bit = find_first_zero_bit(p, page_bits);
38566 + if (free_bit < page_bits)
38567 + goto out; /* success */
38570 + file = sbinfo->si_xib;
38571 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38572 + for (ul = pindex + 1; ul <= pend; ul++) {
38573 + err = xib_pindex(sb, ul);
38574 + if (unlikely(err))
38576 + free_bit = find_first_zero_bit(p, page_bits);
38577 + if (free_bit < page_bits)
38578 + goto out; /* success */
38583 + set_bit(free_bit, p);
38584 + sbinfo->si_xib_next_bit = free_bit + 1;
38585 + pindex = sbinfo->si_xib_last_pindex;
38586 + mutex_unlock(&sbinfo->si_xib_mtx);
38587 + ino = xib_calc_ino(pindex, free_bit);
38588 + AuDbg("i%lu\n", (unsigned long)ino);
38591 + mutex_unlock(&sbinfo->si_xib_mtx);
38596 +/* for s_op->delete_inode() */
38597 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38600 + unsigned int mnt_flags;
38601 + aufs_bindex_t bindex, bbot, bi;
38602 + unsigned char try_trunc;
38603 + struct au_iinfo *iinfo;
38604 + struct super_block *sb;
38605 + struct au_hinode *hi;
38606 + struct inode *h_inode;
38607 + struct au_branch *br;
38608 + vfs_writef_t xwrite;
38609 + struct au_xi_calc calc;
38610 + struct file *file;
38612 + AuDebugOn(au_is_bad_inode(inode));
38614 + sb = inode->i_sb;
38615 + mnt_flags = au_mntflags(sb);
38616 + if (!au_opt_test(mnt_flags, XINO)
38617 + || inode->i_ino == AUFS_ROOT_INO)
38621 + au_xigen_inc(inode);
38622 + au_xib_clear_bit(inode);
38625 + iinfo = au_ii(inode);
38626 + bindex = iinfo->ii_btop;
38630 + xwrite = au_sbi(sb)->si_xwrite;
38631 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38632 + hi = au_hinode(iinfo, bindex);
38633 + bbot = iinfo->ii_bbot;
38634 + for (; bindex <= bbot; bindex++, hi++) {
38635 + h_inode = hi->hi_inode;
38637 + || (!unlinked && h_inode->i_nlink))
38640 + /* inode may not be revalidated */
38641 + bi = au_br_index(sb, hi->hi_id);
38645 + br = au_sbr(sb, bi);
38646 + au_xi_calc(sb, h_inode->i_ino, &calc);
38647 + file = au_xino_file(br->br_xino, calc.idx);
38648 + if (IS_ERR_OR_NULL(file))
38651 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38652 + if (!err && try_trunc
38653 + && au_test_fs_trunc_xino(au_br_sb(br)))
38654 + xino_try_trunc(sb, br);
38658 +/* ---------------------------------------------------------------------- */
38660 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38662 + int found, total, i;
38665 + total = xi->xi_nondir.total;
38666 + for (i = 0; i < total; i++) {
38667 + if (xi->xi_nondir.array[i] != h_ino)
38676 +static int au_xinondir_expand(struct au_xino *xi)
38681 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38684 + sz = xi->xi_nondir.total * sizeof(ino_t);
38685 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38687 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38688 + /*may_shrink*/0);
38690 + xi->xi_nondir.array = p;
38691 + xi->xi_nondir.total <<= 1;
38692 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38700 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38701 + ino_t h_ino, int idx)
38703 + struct au_xino *xi;
38705 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38706 + xi = au_sbr(sb, bindex)->br_xino;
38707 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38709 + spin_lock(&xi->xi_nondir.spin);
38710 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38711 + xi->xi_nondir.array[idx] = 0;
38712 + spin_unlock(&xi->xi_nondir.spin);
38713 + wake_up_all(&xi->xi_nondir.wqh);
38716 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38719 + int err, found, empty;
38720 + struct au_xino *xi;
38724 + if (!au_opt_test(au_mntflags(sb), XINO))
38725 + goto out; /* no xino */
38727 + xi = au_sbr(sb, bindex)->br_xino;
38730 + spin_lock(&xi->xi_nondir.spin);
38731 + found = au_xinondir_find(xi, h_ino);
38732 + if (found == -1) {
38733 + empty = au_xinondir_find(xi, /*h_ino*/0);
38734 + if (empty == -1) {
38735 + empty = xi->xi_nondir.total;
38736 + err = au_xinondir_expand(xi);
38737 + if (unlikely(err))
38740 + xi->xi_nondir.array[empty] = h_ino;
38743 + spin_unlock(&xi->xi_nondir.spin);
38744 + wait_event(xi->xi_nondir.wqh,
38745 + xi->xi_nondir.array[found] != h_ino);
38750 + spin_unlock(&xi->xi_nondir.spin);
38755 +/* ---------------------------------------------------------------------- */
38757 +int au_xino_path(struct seq_file *seq, struct file *file)
38761 + err = au_seq_path(seq, &file->f_path);
38762 + if (unlikely(err))
38765 +#define Deleted "\\040(deleted)"
38766 + seq->count -= sizeof(Deleted) - 1;
38767 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38768 + sizeof(Deleted) - 1));
38774 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38775 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38776 +++ linux/include/uapi/linux/aufs_type.h 2020-04-03 08:16:49.834195677 +0200
38778 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38780 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38782 + * This program, aufs is free software; you can redistribute it and/or modify
38783 + * it under the terms of the GNU General Public License as published by
38784 + * the Free Software Foundation; either version 2 of the License, or
38785 + * (at your option) any later version.
38787 + * This program is distributed in the hope that it will be useful,
38788 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38789 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38790 + * GNU General Public License for more details.
38792 + * You should have received a copy of the GNU General Public License
38793 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38796 +#ifndef __AUFS_TYPE_H__
38797 +#define __AUFS_TYPE_H__
38799 +#define AUFS_NAME "aufs"
38803 + * define it before including all other headers.
38804 + * sched.h may use pr_* macros before defining "current", so define the
38805 + * no-current version first, and re-define later.
38807 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38808 +#include <linux/sched.h>
38810 +#define pr_fmt(fmt) \
38811 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38812 + (int)sizeof(current->comm), current->comm, current->pid
38813 +#include <linux/limits.h>
38815 +#include <stdint.h>
38816 +#include <sys/types.h>
38817 +#include <limits.h>
38818 +#endif /* __KERNEL__ */
38820 +#define AUFS_VERSION "5.4-20200302"
38822 +/* todo? move this to linux-2.6.19/include/magic.h */
38823 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38825 +/* ---------------------------------------------------------------------- */
38828 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38829 +typedef int8_t aufs_bindex_t;
38830 +#define AUFS_BRANCH_MAX 127
38832 +typedef int16_t aufs_bindex_t;
38833 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38834 +#define AUFS_BRANCH_MAX 511
38835 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38836 +#define AUFS_BRANCH_MAX 1023
38837 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38838 +#define AUFS_BRANCH_MAX 32767
38842 +#ifndef AUFS_BRANCH_MAX
38843 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38845 +#endif /* __KERNEL__ */
38847 +/* ---------------------------------------------------------------------- */
38849 +#define AUFS_FSTYPE AUFS_NAME
38851 +#define AUFS_ROOT_INO 2
38852 +#define AUFS_FIRST_INO 11
38854 +#define AUFS_WH_PFX ".wh."
38855 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38856 +#define AUFS_WH_TMP_LEN 4
38857 +/* a limit for rmdir/rename a dir and copyup */
38858 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38859 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38861 + - AUFS_WH_TMP_LEN) /* hex */
38862 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38863 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38864 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38865 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38866 +#define AUFS_DIRWH_DEF 3
38867 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38868 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38869 +#define AUFS_RDBLK_DEF 512 /* bytes */
38870 +#define AUFS_RDHASH_DEF 32
38871 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38872 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38873 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38874 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38875 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38877 +/* pseudo-link maintenace under /proc */
38878 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38879 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38880 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38882 +/* dirren, renamed dir */
38883 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38884 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38885 +/* whiteouted doubly */
38886 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38887 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38889 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38890 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38892 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38893 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38894 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38896 +/* doubly whiteouted */
38897 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38898 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38899 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38901 +/* branch permissions and attributes */
38902 +#define AUFS_BRPERM_RW "rw"
38903 +#define AUFS_BRPERM_RO "ro"
38904 +#define AUFS_BRPERM_RR "rr"
38905 +#define AUFS_BRATTR_COO_REG "coo_reg"
38906 +#define AUFS_BRATTR_COO_ALL "coo_all"
38907 +#define AUFS_BRATTR_FHSM "fhsm"
38908 +#define AUFS_BRATTR_UNPIN "unpin"
38909 +#define AUFS_BRATTR_ICEX "icex"
38910 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38911 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38912 +#define AUFS_BRATTR_ICEX_TR "icextr"
38913 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38914 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38915 +#define AUFS_BRRATTR_WH "wh"
38916 +#define AUFS_BRWATTR_NLWH "nolwh"
38917 +#define AUFS_BRWATTR_MOO "moo"
38919 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38920 +#define AuBrPerm_RO (1 << 1) /* readonly */
38921 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38922 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38924 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38925 +#define AuBrAttr_COO_ALL (1 << 4)
38926 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38928 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38929 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38930 + branch. meaningless since
38931 + linux-3.18-rc1 */
38933 +/* ignore error in copying XATTR */
38934 +#define AuBrAttr_ICEX_SEC (1 << 7)
38935 +#define AuBrAttr_ICEX_SYS (1 << 8)
38936 +#define AuBrAttr_ICEX_TR (1 << 9)
38937 +#define AuBrAttr_ICEX_USR (1 << 10)
38938 +#define AuBrAttr_ICEX_OTH (1 << 11)
38939 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38940 + | AuBrAttr_ICEX_SYS \
38941 + | AuBrAttr_ICEX_TR \
38942 + | AuBrAttr_ICEX_USR \
38943 + | AuBrAttr_ICEX_OTH)
38945 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38946 +#define AuBrRAttr_Mask AuBrRAttr_WH
38948 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38949 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38950 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38952 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38954 +/* #warning test userspace */
38956 +#ifndef CONFIG_AUFS_FHSM
38957 +#undef AuBrAttr_FHSM
38958 +#define AuBrAttr_FHSM 0
38960 +#ifndef CONFIG_AUFS_XATTR
38961 +#undef AuBrAttr_ICEX
38962 +#define AuBrAttr_ICEX 0
38963 +#undef AuBrAttr_ICEX_SEC
38964 +#define AuBrAttr_ICEX_SEC 0
38965 +#undef AuBrAttr_ICEX_SYS
38966 +#define AuBrAttr_ICEX_SYS 0
38967 +#undef AuBrAttr_ICEX_TR
38968 +#define AuBrAttr_ICEX_TR 0
38969 +#undef AuBrAttr_ICEX_USR
38970 +#define AuBrAttr_ICEX_USR 0
38971 +#undef AuBrAttr_ICEX_OTH
38972 +#define AuBrAttr_ICEX_OTH 0
38976 +/* the longest combination */
38977 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38978 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38979 + "+" AUFS_BRATTR_COO_REG \
38980 + "+" AUFS_BRATTR_FHSM \
38981 + "+" AUFS_BRATTR_UNPIN \
38982 + "+" AUFS_BRATTR_ICEX_SEC \
38983 + "+" AUFS_BRATTR_ICEX_SYS \
38984 + "+" AUFS_BRATTR_ICEX_USR \
38985 + "+" AUFS_BRATTR_ICEX_OTH \
38986 + "+" AUFS_BRWATTR_NLWH)
38989 + char a[AuBrPermStrSz];
38990 +} au_br_perm_str_t;
38992 +static inline int au_br_writable(int brperm)
38994 + return brperm & AuBrPerm_RW;
38997 +static inline int au_br_whable(int brperm)
38999 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39002 +static inline int au_br_wh_linkable(int brperm)
39004 + return !(brperm & AuBrWAttr_NoLinkWH);
39007 +static inline int au_br_cmoo(int brperm)
39009 + return brperm & AuBrAttr_CMOO_Mask;
39012 +static inline int au_br_fhsm(int brperm)
39014 + return brperm & AuBrAttr_FHSM;
39017 +/* ---------------------------------------------------------------------- */
39021 + /* readdir in userspace */
39025 + AuCtl_WBR_FD, /* pathconf wrapper */
39026 + AuCtl_IBUSY, /* busy inode */
39027 + AuCtl_MVDOWN, /* move-down */
39028 + AuCtl_BR, /* info about branches */
39029 + AuCtl_FHSM_FD /* connection for fhsm */
39032 +/* borrowed from linux/include/linux/kernel.h */
39034 +#ifdef _GNU_SOURCE
39035 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39037 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39039 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39042 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39044 +#define __aligned(x) __attribute__((aligned(x)))
39049 +#define __packed __attribute__((packed))
39053 +struct au_rdu_cookie {
39058 + uint32_t generation;
39061 +struct au_rdu_ent {
39070 +static inline int au_rdu_len(int nlen)
39072 + /* include the terminating NULL */
39073 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39074 + sizeof(uint64_t));
39077 +union au_rdu_ent_ul {
39078 + struct au_rdu_ent __user *e;
39090 + uint64_t sz; /* AuCtl_RDU */
39091 + uint64_t nent; /* AuCtl_RDU_INO */
39093 + union au_rdu_ent_ul ent;
39094 + uint16_t verify[AufsCtlRduV_End];
39096 + /* input/output */
39100 + union au_rdu_ent_ul tail;
39101 + /* number of entries which were added in a single call */
39106 + struct au_rdu_cookie cookie;
39109 +/* ---------------------------------------------------------------------- */
39111 +/* dirren. the branch is identified by the filename who contains this */
39112 +struct au_drinfo {
39115 + uint8_t oldnamelen;
39116 + uint64_t _padding;
39118 + uint8_t oldname[0];
39121 +struct au_drinfo_fdata {
39123 + struct au_drinfo drinfo;
39126 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39128 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39130 +/* ---------------------------------------------------------------------- */
39132 +struct aufs_wbr_fd {
39137 +/* ---------------------------------------------------------------------- */
39139 +struct aufs_ibusy {
39140 + uint64_t ino, h_ino;
39144 +/* ---------------------------------------------------------------------- */
39146 +/* error code for move-down */
39147 +/* the actual message strings are implemented in aufs-util.git */
39149 + EAU_MVDOWN_OPAQUE = 1,
39150 + EAU_MVDOWN_WHITEOUT,
39151 + EAU_MVDOWN_UPPER,
39152 + EAU_MVDOWN_BOTTOM,
39153 + EAU_MVDOWN_NOUPPER,
39154 + EAU_MVDOWN_NOLOWERBR,
39158 +/* flags for move-down */
39159 +#define AUFS_MVDOWN_DMSG 1
39160 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39161 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39162 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39163 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39164 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39165 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39166 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39167 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39168 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39169 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39170 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39171 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39173 +/* index for move-down */
39175 + AUFS_MVDOWN_UPPER,
39176 + AUFS_MVDOWN_LOWER,
39177 + AUFS_MVDOWN_NARRAY
39181 + * additional info of move-down
39182 + * number of free blocks and inodes.
39183 + * subset of struct kstatfs, but smaller and always 64bit.
39185 +struct aufs_stfs {
39186 + uint64_t f_blocks;
39187 + uint64_t f_bavail;
39188 + uint64_t f_files;
39189 + uint64_t f_ffree;
39192 +struct aufs_stbr {
39193 + int16_t brid; /* optional input */
39194 + int16_t bindex; /* output */
39195 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39198 +struct aufs_mvdown {
39199 + uint32_t flags; /* input/output */
39200 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39201 + int8_t au_errno; /* output */
39204 +/* ---------------------------------------------------------------------- */
39206 +union aufs_brinfo {
39207 + /* PATH_MAX may differ between kernel-space and user-space */
39208 + char _spacer[4096];
39216 +/* ---------------------------------------------------------------------- */
39218 +#define AuCtlType 'A'
39219 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39220 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39221 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39222 + struct aufs_wbr_fd)
39223 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39224 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39225 + struct aufs_mvdown)
39226 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39227 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39229 +#endif /* __AUFS_TYPE_H__ */
39230 SPDX-License-Identifier: GPL-2.0
39231 aufs5.4 loopback patch
39233 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39234 index 5e094699215e..22b2ecb6cfe8 100644
39235 --- a/drivers/block/loop.c
39236 +++ b/drivers/block/loop.c
39237 @@ -625,6 +625,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39241 +static struct file *loop_real_file(struct file *file)
39243 + struct file *f = NULL;
39245 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39246 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39250 static void loop_reread_partitions(struct loop_device *lo,
39251 struct block_device *bdev)
39253 @@ -678,6 +687,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39256 struct file *file = NULL, *old_file;
39257 + struct file *f, *virt_file = NULL, *old_virt_file;
39261 @@ -697,12 +707,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39265 + f = loop_real_file(file);
39267 + virt_file = file;
39272 error = loop_validate_file(file, bdev);
39276 old_file = lo->lo_backing_file;
39277 + old_virt_file = lo->lo_backing_virt_file;
39281 @@ -714,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39282 blk_mq_freeze_queue(lo->lo_queue);
39283 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39284 lo->lo_backing_file = file;
39285 + lo->lo_backing_virt_file = virt_file;
39286 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39287 mapping_set_gfp_mask(file->f_mapping,
39288 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39289 @@ -727,6 +745,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39293 + if (old_virt_file)
39294 + fput(old_virt_file);
39296 loop_reread_partitions(lo, bdev);
39298 @@ -735,6 +755,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39299 mutex_unlock(&loop_ctl_mutex);
39307 @@ -939,7 +961,7 @@ static void loop_update_rotational(struct loop_device *lo)
39308 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39309 struct block_device *bdev, unsigned int arg)
39311 - struct file *file;
39312 + struct file *file, *f, *virt_file = NULL;
39313 struct inode *inode;
39314 struct address_space *mapping;
39315 struct block_device *claimed_bdev = NULL;
39316 @@ -955,6 +977,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39320 + f = loop_real_file(file);
39322 + virt_file = file;
39328 * If we don't hold exclusive handle for the device, upgrade to it
39329 @@ -1003,6 +1031,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39330 lo->lo_device = bdev;
39331 lo->lo_flags = lo_flags;
39332 lo->lo_backing_file = file;
39333 + lo->lo_backing_virt_file = virt_file;
39334 lo->transfer = NULL;
39336 lo->lo_sizelimit = 0;
39337 @@ -1056,6 +1085,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39338 bd_abort_claiming(bdev, claimed_bdev, loop_set_fd);
39344 /* This is safe: open() is still holding a reference. */
39345 module_put(THIS_MODULE);
39346 @@ -1102,6 +1133,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39347 static int __loop_clr_fd(struct loop_device *lo, bool release)
39349 struct file *filp = NULL;
39350 + struct file *virt_filp = lo->lo_backing_virt_file;
39351 gfp_t gfp = lo->old_gfp_mask;
39352 struct block_device *bdev = lo->lo_device;
39354 @@ -1125,6 +1157,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39356 spin_lock_irq(&lo->lo_lock);
39357 lo->lo_backing_file = NULL;
39358 + lo->lo_backing_virt_file = NULL;
39359 spin_unlock_irq(&lo->lo_lock);
39361 loop_release_xfer(lo);
39362 @@ -1207,6 +1240,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39371 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39372 index af75a5ee4094..1d847cb194ff 100644
39373 --- a/drivers/block/loop.h
39374 +++ b/drivers/block/loop.h
39375 @@ -46,7 +46,7 @@ struct loop_device {
39376 int (*ioctl)(struct loop_device *, int cmd,
39377 unsigned long arg);
39379 - struct file * lo_backing_file;
39380 + struct file *lo_backing_file, *lo_backing_virt_file;
39381 struct block_device *lo_device;
39384 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39385 index 6fb4a4ed8cc7..ba9a959f2db2 100644
39386 --- a/fs/aufs/f_op.c
39387 +++ b/fs/aufs/f_op.c
39388 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39389 if (IS_ERR(h_file))
39392 - if (au_test_loopback_kthread()) {
39393 + if (0 && au_test_loopback_kthread()) {
39394 au_warn_loopback(h_file->f_path.dentry->d_sb);
39395 if (file->f_mapping != h_file->f_mapping) {
39396 file->f_mapping = h_file->f_mapping;
39397 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39398 index a8b63acc6204..9d97c3af5686 100644
39399 --- a/fs/aufs/loop.c
39400 +++ b/fs/aufs/loop.c
39401 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39402 symbol_put(loop_backing_file);
39403 au_kfree_try_rcu(au_warn_loopback_array);
39406 +/* ---------------------------------------------------------------------- */
39408 +/* support the loopback block device insude aufs */
39410 +struct file *aufs_real_loop(struct file *file)
39414 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39415 + fi_read_lock(file);
39416 + f = au_hf_top(file);
39417 + fi_read_unlock(file);
39421 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39422 index 94f4f80ae33b..ca1194354aff 100644
39423 --- a/fs/aufs/loop.h
39424 +++ b/fs/aufs/loop.h
39425 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39427 int au_loopback_init(void);
39428 void au_loopback_fin(void);
39430 +struct file *aufs_real_loop(struct file *file);
39432 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39434 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39436 AuStubInt0(au_loopback_init, void)
39437 AuStubVoid(au_loopback_fin, void)
39439 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39440 #endif /* BLK_DEV_LOOP */
39442 #endif /* __KERNEL__ */
39443 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39444 index 589dd0122020..801e0a7faec5 100644
39445 --- a/fs/aufs/super.c
39446 +++ b/fs/aufs/super.c
39447 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39448 .statfs = aufs_statfs,
39449 .put_super = aufs_put_super,
39450 .sync_fs = aufs_sync_fs,
39451 - .remount_fs = aufs_remount_fs
39452 + .remount_fs = aufs_remount_fs,
39453 +#ifdef CONFIG_AUFS_BDEV_LOOP
39454 + .real_loop = aufs_real_loop
39458 /* ---------------------------------------------------------------------- */
39459 diff --git a/include/linux/fs.h b/include/linux/fs.h
39460 index 381a13995011..215b76e0f9dc 100644
39461 --- a/include/linux/fs.h
39462 +++ b/include/linux/fs.h
39463 @@ -1973,6 +1973,10 @@ struct super_operations {
39464 struct shrink_control *);
39465 long (*free_cached_objects)(struct super_block *,
39466 struct shrink_control *);
39467 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39469 + struct file *(*real_loop)(struct file *);