1 SPDX-License-Identifier: GPL-2.0
2 aufs5.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index f1046cf6ad85..95c957c2e2c3 100644
8 @@ -262,6 +262,7 @@ source "fs/romfs/Kconfig"
9 source "fs/pstore/Kconfig"
10 source "fs/sysv/Kconfig"
11 source "fs/ufs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index c9aea23aba56..57c6f47b0185 100644
20 @@ -130,3 +130,4 @@ obj-$(CONFIG_F2FS_FS) += f2fs/
21 obj-$(CONFIG_CEPH_FS) += ceph/
22 obj-$(CONFIG_PSTORE) += pstore/
23 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs5.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index a6954776a37e..c30c2d323711 100644
32 @@ -2769,6 +2769,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 f11b7dc16e9d..1b723737592b 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -746,6 +746,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 c435398f2c81..a688a042d022 100644
85 @@ -1247,7 +1247,7 @@ enum d_walk_ret {
87 * The @enter() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index 3d40771e8e7c..d62303c5472a 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file * filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/inode.c b/fs/inode.c
117 index df6542ec3b88..407d7b45e2ee 100644
120 @@ -1670,7 +1670,7 @@ EXPORT_SYMBOL(generic_update_time);
121 * This does the actual work of updating an inodes time or version. Must have
122 * had called mnt_want_write() before calling this.
124 -static int update_time(struct inode *inode, struct timespec64 *time, int flags)
125 +int update_time(struct inode *inode, struct timespec64 *time, int flags)
127 int (*update_time)(struct inode *, struct timespec64 *, int);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index b26778bdc236..b460383a4228 100644
133 @@ -770,6 +770,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 c543d965e288..35ab54e0a994 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -498,6 +498,28 @@ static ssize_t __vfs_write(struct file *file, const char __user *p,
154 +vfs_readf_t vfs_readf(struct file *file)
156 + const struct file_operations *fop = file->f_op;
160 + if (fop->read_iter)
161 + return new_sync_read;
162 + return ERR_PTR(-ENOSYS);
165 +vfs_writef_t vfs_writef(struct file *file)
167 + const struct file_operations *fop = file->f_op;
171 + if (fop->write_iter)
172 + return new_sync_write;
173 + return ERR_PTR(-ENOSYS);
176 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
179 diff --git a/fs/splice.c b/fs/splice.c
180 index 14cb602d9a2f..58d2692c5f30 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 f7fdfe93e25d..28593b894e7b 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1333,6 +1333,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 @@ -1812,6 +1813,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 @@ -1882,6 +1884,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 @@ -2315,6 +2323,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 @@ -2603,6 +2612,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 6e2377e6c1d6..5a945d18a72a 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -325,6 +325,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 @@ -463,6 +465,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 c47788fa85f9..3c35a1059890 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -152,7 +152,7 @@ static
330 struct lock_class lock_classes[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 if (!hlock->class_idx) {
337 @@ -163,6 +163,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
339 return lock_classes + hlock->class_idx - 1;
341 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
343 #ifdef CONFIG_LOCK_STAT
344 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
345 SPDX-License-Identifier: GPL-2.0
346 aufs5.x-rcN mmap patch
348 diff --git a/fs/proc/base.c b/fs/proc/base.c
349 index 9c8ca6cd3ce4..2ae2c94aceca 100644
352 @@ -2014,7 +2014,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
353 down_read(&mm->mmap_sem);
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 01d4eb0e6bd1..fedfaa012768 100644
379 --- a/fs/proc/task_mmu.c
380 +++ b/fs/proc/task_mmu.c
381 @@ -305,7 +305,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 @@ -1761,7 +1764,7 @@ static int show_numa_map(struct seq_file *m, void *v)
394 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
395 struct vm_area_struct *vma = v;
396 struct numa_maps *md = &numa_priv->md;
397 - struct file *file = vma->vm_file;
398 + struct file *file = vma_pr_or_file(vma);
399 struct mm_struct *mm = vma->vm_mm;
400 struct mm_walk walk = {
401 .hugetlb_entry = gather_hugetlb_stats,
402 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
403 index 36bf0f2e102e..8df6cbc58756 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 0e8834ac32b7..b3f42f01aaf0 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1542,6 +1542,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 8ec38b11b361..d3f5492a2611 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -253,6 +253,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 @@ -327,6 +328,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) */
470 atomic_long_t swap_readahead_info;
471 diff --git a/kernel/fork.c b/kernel/fork.c
472 index 75675b9bf6df..dc333a5e6926 100644
475 @@ -549,7 +549,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 ac5e5ba78874..5decb22d13a0 100644
488 @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
489 mm_init.o mmu_context.o percpu.o slab_common.o \
490 compaction.o vmacache.o \
491 interval_tree.o list_lru.o workingset.o \
493 + prfile.o debug.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 df2006ba0cfa..d5221dedfe56 100644
501 @@ -2671,7 +2671,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
502 vm_fault_t ret = VM_FAULT_LOCKED;
504 sb_start_pagefault(inode->i_sb);
505 - file_update_time(vmf->vma->vm_file);
506 + vma_file_update_time(vmf->vma);
508 if (page->mapping != inode->i_mapping) {
510 diff --git a/mm/mmap.c b/mm/mmap.c
511 index 7e8c3e8ae75f..d8a903f61262 100644
514 @@ -182,7 +182,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
515 if (vma->vm_ops && vma->vm_ops->close)
516 vma->vm_ops->close(vma);
518 - fput(vma->vm_file);
520 mpol_put(vma_policy(vma));
523 @@ -931,7 +931,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
526 uprobe_munmap(next, next->vm_start, next->vm_end);
531 anon_vma_merge(vma, next);
532 @@ -1847,8 +1847,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
540 /* Undo any partial mapping done by a device driver. */
541 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
542 @@ -2680,7 +2680,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
546 - get_file(new->vm_file);
549 if (new->vm_ops && new->vm_ops->open)
550 new->vm_ops->open(new);
551 @@ -2699,7 +2699,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
552 if (new->vm_ops && new->vm_ops->close)
553 new->vm_ops->close(new);
555 - fput(new->vm_file);
557 unlink_anon_vmas(new);
559 mpol_put(vma_policy(new));
560 @@ -2890,7 +2890,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
561 struct vm_area_struct *vma;
562 unsigned long populate = 0;
563 unsigned long ret = -EINVAL;
565 + struct file *file, *prfile;
567 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
568 current->comm, current->pid);
569 @@ -2965,10 +2965,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
573 - file = get_file(vma->vm_file);
575 + file = vma->vm_file;
576 + prfile = vma->vm_prfile;
577 ret = do_mmap_pgoff(vma->vm_file, start, size,
578 prot, flags, pgoff, &populate, NULL);
579 + if (!IS_ERR_VALUE(ret) && file && prfile) {
580 + struct vm_area_struct *new_vma;
582 + new_vma = find_vma(mm, ret);
583 + if (!new_vma->vm_prfile)
584 + new_vma->vm_prfile = prfile;
585 + if (new_vma != vma)
589 + * two fput()s instead of vma_fput(vma),
590 + * coz vma may not be available anymore.
596 up_write(&mm->mmap_sem);
598 @@ -3258,7 +3275,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
599 if (anon_vma_clone(new_vma, vma))
600 goto out_free_mempol;
601 if (new_vma->vm_file)
602 - get_file(new_vma->vm_file);
603 + vma_get_file(new_vma);
604 if (new_vma->vm_ops && new_vma->vm_ops->open)
605 new_vma->vm_ops->open(new_vma);
606 vma_link(mm, new_vma, prev, rb_link, rb_parent);
607 diff --git a/mm/nommu.c b/mm/nommu.c
608 index d8c02fbe03b5..22dae8b7216a 100644
611 @@ -640,7 +640,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 @@ -778,7 +778,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 @@ -1301,7 +1301,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 @@ -1376,10 +1376,10 @@ unsigned long do_mmap(struct file *file,
639 up_write(&nommu_region_sem);
642 - fput(region->vm_file);
644 kmem_cache_free(vm_region_jar, region);
646 - fput(vma->vm_file);
651 diff --git a/mm/prfile.c b/mm/prfile.c
653 index 000000000000..024cdcfae1b1
657 +// SPDX-License-Identifier: GPL-2.0
659 + * Mainly for aufs which mmap(2) different file and wants to print different
660 + * path in /proc/PID/maps.
661 + * Call these functions via macros defined in linux/mm.h.
663 + * See Documentation/filesystems/aufs/design/06mmap.txt
665 + * Copyright (c) 2014-2019 Junjro R. Okajima
666 + * Copyright (c) 2014 Ian Campbell
669 +#include <linux/mm.h>
670 +#include <linux/file.h>
671 +#include <linux/fs.h>
673 +/* #define PRFILE_TRACE */
674 +static inline void prfile_trace(struct file *f, struct file *pr,
675 + const char func[], int line, const char func2[])
679 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
683 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
686 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
688 + prfile_trace(f, pr, func, line, __func__);
689 + file_update_time(f);
691 + file_update_time(pr);
694 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
697 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
699 + prfile_trace(f, pr, func, line, __func__);
700 + return (f && pr) ? pr : f;
703 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
705 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
707 + prfile_trace(f, pr, func, line, __func__);
713 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
715 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
717 + prfile_trace(f, pr, func, line, __func__);
724 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
727 + struct file *f = region->vm_file, *pr = region->vm_prfile;
729 + prfile_trace(f, pr, func, line, __func__);
730 + return (f && pr) ? pr : f;
733 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
735 + struct file *f = region->vm_file, *pr = region->vm_prfile;
737 + prfile_trace(f, pr, func, line, __func__);
742 +#endif /* !CONFIG_MMU */
743 SPDX-License-Identifier: GPL-2.0
744 aufs5.x-rcN standalone patch
746 diff --git a/fs/dcache.c b/fs/dcache.c
747 index a688a042d022..3fc74e471924 100644
750 @@ -1352,6 +1352,7 @@ void d_walk(struct dentry *parent, void *data,
754 +EXPORT_SYMBOL_GPL(d_walk);
757 struct vfsmount *mnt;
758 @@ -2850,6 +2851,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 89a500bb897a..1a722915ed77 100644
770 @@ -110,6 +110,7 @@ bool path_noexec(const struct path *path)
771 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
772 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
774 +EXPORT_SYMBOL_GPL(path_noexec);
778 diff --git a/fs/fcntl.c b/fs/fcntl.c
779 index d62303c5472a..d4ad34463848 100644
782 @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
786 +EXPORT_SYMBOL_GPL(setfl);
788 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
790 diff --git a/fs/file_table.c b/fs/file_table.c
791 index b07b53f24ff5..34b9bbf4c556 100644
792 --- a/fs/file_table.c
793 +++ b/fs/file_table.c
794 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
796 return ERR_PTR(-ENFILE);
798 +EXPORT_SYMBOL_GPL(alloc_empty_file);
801 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
802 @@ -327,6 +328,7 @@ void flush_delayed_fput(void)
806 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
808 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
810 @@ -374,6 +376,7 @@ void __fput_sync(struct file *file)
814 +EXPORT_SYMBOL_GPL(__fput_sync);
816 void __init files_init(void)
818 diff --git a/fs/inode.c b/fs/inode.c
819 index 407d7b45e2ee..b4d3e100abd0 100644
822 @@ -1679,6 +1679,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
824 return update_time(inode, time, flags);
826 +EXPORT_SYMBOL_GPL(update_time);
829 * touch_atime - update the access time
830 diff --git a/fs/namespace.c b/fs/namespace.c
831 index b460383a4228..b74d15701ed7 100644
834 @@ -436,6 +436,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
835 mnt_dec_writers(real_mount(mnt));
838 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
841 * mnt_drop_write - give up write access to a mount
842 @@ -775,6 +776,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
844 return check_mnt(real_mount(mnt));
846 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
849 * vfsmount lock must be held for write
850 @@ -1908,6 +1910,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
854 +EXPORT_SYMBOL_GPL(iterate_mounts);
856 static void lock_mnt_tree(struct mount *mnt)
858 diff --git a/fs/notify/group.c b/fs/notify/group.c
859 index 0391190305cc..0b9f7f6d8390 100644
860 --- a/fs/notify/group.c
861 +++ b/fs/notify/group.c
862 @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
864 refcount_inc(&group->refcnt);
866 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
869 * Drop a reference to a group. Free it if it's through.
870 @@ -108,6 +109,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
871 if (refcount_dec_and_test(&group->refcnt))
872 fsnotify_final_destroy_group(group);
874 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
877 * Create a new fsnotify_group and hold a reference for the group returned.
878 @@ -137,6 +139,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
882 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
884 int fsnotify_fasync(int fd, struct file *file, int on)
886 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
887 index 25eb247ea85a..6a2a2f722eae 100644
888 --- a/fs/notify/mark.c
889 +++ b/fs/notify/mark.c
890 @@ -276,6 +276,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
891 queue_delayed_work(system_unbound_wq, &reaper_work,
892 FSNOTIFY_REAPER_DELAY);
894 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
897 * Get mark reference when we found the mark via lockless traversal of object
898 @@ -430,6 +431,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
899 mutex_unlock(&group->mark_mutex);
900 fsnotify_free_mark(mark);
902 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
905 * Sorting function for lists of fsnotify marks.
906 @@ -677,6 +679,7 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,
907 mutex_unlock(&group->mark_mutex);
910 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
913 * Given a list of marks, find the mark associated with given group. If found
914 @@ -801,6 +804,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
916 WRITE_ONCE(mark->connector, NULL);
918 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
921 * Destroy all marks in destroy_list, waits for SRCU period to finish before
922 diff --git a/fs/open.c b/fs/open.c
923 index b5b80469b93d..eb818f6b9519 100644
926 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
927 inode_unlock(dentry->d_inode);
930 +EXPORT_SYMBOL_GPL(do_truncate);
932 long vfs_truncate(const struct path *path, loff_t length)
934 diff --git a/fs/read_write.c b/fs/read_write.c
935 index 35ab54e0a994..9da238d64ea4 100644
936 --- a/fs/read_write.c
937 +++ b/fs/read_write.c
938 @@ -468,6 +468,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
942 +EXPORT_SYMBOL_GPL(vfs_read);
944 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
946 @@ -508,6 +509,7 @@ vfs_readf_t vfs_readf(struct file *file)
947 return new_sync_read;
948 return ERR_PTR(-ENOSYS);
950 +EXPORT_SYMBOL_GPL(vfs_readf);
952 vfs_writef_t vfs_writef(struct file *file)
954 @@ -519,6 +521,7 @@ vfs_writef_t vfs_writef(struct file *file)
955 return new_sync_write;
956 return ERR_PTR(-ENOSYS);
958 +EXPORT_SYMBOL_GPL(vfs_writef);
960 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
962 @@ -588,6 +591,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
966 +EXPORT_SYMBOL_GPL(vfs_write);
968 /* file_ppos returns &file->f_pos or NULL if file is stream */
969 static inline loff_t *file_ppos(struct file *file)
970 diff --git a/fs/splice.c b/fs/splice.c
971 index 58d2692c5f30..4fe4afa7f6b1 100644
974 @@ -847,6 +847,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
976 return splice_write(pipe, out, ppos, len, flags);
978 +EXPORT_SYMBOL_GPL(do_splice_from);
981 * Attempt to initiate a splice from a file to a pipe.
982 @@ -876,6 +877,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
984 return splice_read(in, ppos, pipe, len, flags);
986 +EXPORT_SYMBOL_GPL(do_splice_to);
989 * splice_direct_to_actor - splices data directly between two non-pipes
990 diff --git a/fs/sync.c b/fs/sync.c
991 index 457f4e4a5cc1..67c66358f3fe 100644
994 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
995 sb->s_op->sync_fs(sb, wait);
996 return __sync_blockdev(sb->s_bdev, wait);
998 +EXPORT_SYMBOL_GPL(__sync_filesystem);
1001 * Write out and wait upon all dirty data associated with this
1002 diff --git a/fs/xattr.c b/fs/xattr.c
1003 index 90dd78f0eb27..40b01dd1b14a 100644
1006 @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
1007 *xattr_value = value;
1010 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
1013 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
1014 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
1015 index 3c35a1059890..67dccde036a2 100644
1016 --- a/kernel/locking/lockdep.c
1017 +++ b/kernel/locking/lockdep.c
1018 @@ -163,6 +163,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
1020 return lock_classes + hlock->class_idx - 1;
1022 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
1023 #define hlock_class(hlock) lockdep_hlock_class(hlock)
1025 #ifdef CONFIG_LOCK_STAT
1026 diff --git a/kernel/task_work.c b/kernel/task_work.c
1027 index 0fef395662a6..83fb1ecfc33d 100644
1028 --- a/kernel/task_work.c
1029 +++ b/kernel/task_work.c
1030 @@ -116,3 +116,4 @@ void task_work_run(void)
1034 +EXPORT_SYMBOL_GPL(task_work_run);
1035 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
1036 index dc28914fa72e..c2ddfea2b280 100644
1037 --- a/security/device_cgroup.c
1038 +++ b/security/device_cgroup.c
1039 @@ -824,3 +824,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor,
1043 +EXPORT_SYMBOL_GPL(__devcgroup_check_permission);
1044 diff --git a/security/security.c b/security/security.c
1045 index f493db0bf62a..96f118be469f 100644
1046 --- a/security/security.c
1047 +++ b/security/security.c
1048 @@ -993,6 +993,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
1050 return call_int_hook(path_rmdir, 0, dir, dentry);
1052 +EXPORT_SYMBOL_GPL(security_path_rmdir);
1054 int security_path_unlink(const struct path *dir, struct dentry *dentry)
1056 @@ -1009,6 +1010,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
1058 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1060 +EXPORT_SYMBOL_GPL(security_path_symlink);
1062 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1063 struct dentry *new_dentry)
1064 @@ -1017,6 +1019,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1066 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1068 +EXPORT_SYMBOL_GPL(security_path_link);
1070 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1071 const struct path *new_dir, struct dentry *new_dentry,
1072 @@ -1044,6 +1047,7 @@ int security_path_truncate(const struct path *path)
1074 return call_int_hook(path_truncate, 0, path);
1076 +EXPORT_SYMBOL_GPL(security_path_truncate);
1078 int security_path_chmod(const struct path *path, umode_t mode)
1080 @@ -1051,6 +1055,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1082 return call_int_hook(path_chmod, 0, path, mode);
1084 +EXPORT_SYMBOL_GPL(security_path_chmod);
1086 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1088 @@ -1058,6 +1063,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1090 return call_int_hook(path_chown, 0, path, uid, gid);
1092 +EXPORT_SYMBOL_GPL(security_path_chown);
1094 int security_path_chroot(const struct path *path)
1096 @@ -1158,6 +1164,7 @@ int security_inode_permission(struct inode *inode, int mask)
1098 return call_int_hook(inode_permission, 0, inode, mask);
1100 +EXPORT_SYMBOL_GPL(security_inode_permission);
1102 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1104 @@ -1335,6 +1342,7 @@ int security_file_permission(struct file *file, int mask)
1106 return fsnotify_perm(file, mask);
1108 +EXPORT_SYMBOL_GPL(security_file_permission);
1110 int security_file_alloc(struct file *file)
1112 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1113 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 08:00:00.000000000 +0800
1114 +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 21:21:54.375717654 +0800
1116 +What: /debug/aufs/si_<id>/
1118 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1120 + Under /debug/aufs, a directory named si_<id> is created
1121 + per aufs mount, where <id> is a unique id generated
1124 +What: /debug/aufs/si_<id>/plink
1126 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1128 + It has three lines and shows the information about the
1129 + pseudo-link. The first line is a single number
1130 + representing a number of buckets. The second line is a
1131 + number of pseudo-links per buckets (separated by a
1132 + blank). The last line is a single number representing a
1133 + total number of psedo-links.
1134 + When the aufs mount option 'noplink' is specified, it
1135 + will show "1\n0\n0\n".
1137 +What: /debug/aufs/si_<id>/xib
1139 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1141 + It shows the consumed blocks by xib (External Inode Number
1142 + Bitmap), its block size and file size.
1143 + When the aufs mount option 'noxino' is specified, it
1144 + will be empty. About XINO files, see the aufs manual.
1146 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1148 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1150 + It shows the consumed blocks by xino (External Inode Number
1151 + Translation Table), its link count, block size and file
1153 + Due to the file size limit, there may exist multiple
1154 + xino files per branch. In this case, "-N" is added to
1155 + the filename and it corresponds to the index of the
1156 + internal xino array. "-0" is omitted.
1157 + When the aufs mount option 'noxino' is specified, Those
1158 + entries won't exist. About XINO files, see the aufs
1161 +What: /debug/aufs/si_<id>/xigen
1163 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1165 + It shows the consumed blocks by xigen (External Inode
1166 + Generation Table), its block size and file size.
1167 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1169 + When the aufs mount option 'noxino' is specified, it
1170 + will be empty. About XINO files, see the aufs manual.
1171 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1172 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 08:00:00.000000000 +0800
1173 +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 21:21:54.375717654 +0800
1175 +What: /sys/fs/aufs/si_<id>/
1177 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1179 + Under /sys/fs/aufs, a directory named si_<id> is created
1180 + per aufs mount, where <id> is a unique id generated
1183 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1185 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1187 + It shows the abolute path of a member directory (which
1188 + is called branch) in aufs, and its permission.
1190 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1192 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1194 + It shows the id of a member directory (which is called
1197 +What: /sys/fs/aufs/si_<id>/xi_path
1199 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1201 + It shows the abolute path of XINO (External Inode Number
1202 + Bitmap, Translation Table and Generation Table) file
1203 + even if it is the default path.
1204 + When the aufs mount option 'noxino' is specified, it
1205 + will be empty. About XINO files, see the aufs manual.
1206 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1207 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 08:00:00.000000000 +0800
1208 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2019-07-11 21:21:54.375717654 +0800
1211 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1213 +# This program is free software; you can redistribute it and/or modify
1214 +# it under the terms of the GNU General Public License as published by
1215 +# the Free Software Foundation; either version 2 of the License, or
1216 +# (at your option) any later version.
1218 +# This program is distributed in the hope that it will be useful,
1219 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1220 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1221 +# GNU General Public License for more details.
1223 +# You should have received a copy of the GNU General Public License
1224 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1227 +----------------------------------------
1229 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1230 +1. abbrev. for "advanced multi-layered unification filesystem".
1231 +2. abbrev. for "another unionfs".
1232 +3. abbrev. for "auf das" in German which means "on the" in English.
1233 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1234 + But "Filesystem aufs Filesystem" is hard to understand.
1235 +4. abbrev. for "African Urban Fashion Show".
1237 +AUFS is a filesystem with features:
1238 +- multi layered stackable unification filesystem, the member directory
1239 + is called as a branch.
1240 +- branch permission and attribute, 'readonly', 'real-readonly',
1241 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1243 +- internal "file copy-on-write".
1244 +- logical deletion, whiteout.
1245 +- dynamic branch manipulation, adding, deleting and changing permission.
1246 +- allow bypassing aufs, user's direct branch access.
1247 +- external inode number translation table and bitmap which maintains the
1248 + persistent aufs inode number.
1249 +- seekable directory, including NFS readdir.
1250 +- file mapping, mmap and sharing pages.
1251 +- pseudo-link, hardlink over branches.
1252 +- loopback mounted filesystem as a branch.
1253 +- several policies to select one among multiple writable branches.
1254 +- revert a single systemcall when an error occurs in aufs.
1258 +Multi Layered Stackable Unification Filesystem
1259 +----------------------------------------------------------------------
1260 +Most people already knows what it is.
1261 +It is a filesystem which unifies several directories and provides a
1262 +merged single directory. When users access a file, the access will be
1263 +passed/re-directed/converted (sorry, I am not sure which English word is
1264 +correct) to the real file on the member filesystem. The member
1265 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1266 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1267 +readonly branch is handled by creating 'whiteout' on the upper writable
1270 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1271 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1272 +different approaches to implement the merged-view.
1273 +The former tries putting it into VFS, and the latter implements as a
1274 +separate filesystem.
1275 +(If I misunderstand about these implementations, please let me know and
1276 +I shall correct it. Because it is a long time ago when I read their
1277 +source files last time).
1279 +UnionMount's approach will be able to small, but may be hard to share
1280 +branches between several UnionMount since the whiteout in it is
1281 +implemented in the inode on branch filesystem and always
1282 +shared. According to Bharata's post, readdir does not seems to be
1284 +There are several missing features known in this implementations such as
1285 +- for users, the inode number may change silently. eg. copy-up.
1286 +- link(2) may break by copy-up.
1287 +- read(2) may get an obsoleted filedata (fstat(2) too).
1288 +- fcntl(F_SETLK) may be broken by copy-up.
1289 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1292 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1293 +merged into mainline. This is another implementation of UnionMount as a
1294 +separated filesystem. All the limitations and known problems which
1295 +UnionMount are equally inherited to "overlay" filesystem.
1297 +Unionfs has a longer history. When I started implementing a stackable
1298 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1299 +inode, dentry and file objects and they have an array pointing lower
1300 +same kind objects. After contributing many patches for Unionfs, I
1301 +re-started my project AUFS (Jun 2006).
1303 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1304 +implemented my own ideas, approaches and enhancements and it became
1305 +totally different one.
1307 +Comparing DM snapshot and fs based implementation
1308 +- the number of bytes to be copied between devices is much smaller.
1309 +- the type of filesystem must be one and only.
1310 +- the fs must be writable, no readonly fs, even for the lower original
1311 + device. so the compression fs will not be usable. but if we use
1312 + loopback mount, we may address this issue.
1314 + mount /cdrom/squashfs.img /sq
1315 + losetup /sq/ext2.img
1316 + losetup /somewhere/cow
1317 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1318 +- it will be difficult (or needs more operations) to extract the
1319 + difference between the original device and COW.
1320 +- DM snapshot-merge may help a lot when users try merging. in the
1321 + fs-layer union, users will use rsync(1).
1323 +You may want to read my old paper "Filesystems in LiveCD"
1324 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1327 +Several characters/aspects/persona of aufs
1328 +----------------------------------------------------------------------
1330 +Aufs has several characters, aspects or persona.
1331 +1. a filesystem, callee of VFS helper
1332 +2. sub-VFS, caller of VFS helper for branches
1333 +3. a virtual filesystem which maintains persistent inode number
1334 +4. reader/writer of files on branches such like an application
1336 +1. Callee of VFS Helper
1337 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1338 +unlink(2) from an application reaches sys_unlink() kernel function and
1339 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1340 +calls filesystem specific unlink operation. Actually aufs implements the
1341 +unlink operation but it behaves like a redirector.
1343 +2. Caller of VFS Helper for Branches
1344 +aufs_unlink() passes the unlink request to the branch filesystem as if
1345 +it were called from VFS. So the called unlink operation of the branch
1346 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1347 +every necessary pre/post operation for the branch filesystem.
1348 +- acquire the lock for the parent dir on a branch
1349 +- lookup in a branch
1350 +- revalidate dentry on a branch
1351 +- mnt_want_write() for a branch
1352 +- vfs_unlink() for a branch
1353 +- mnt_drop_write() for a branch
1354 +- release the lock on a branch
1356 +3. Persistent Inode Number
1357 +One of the most important issue for a filesystem is to maintain inode
1358 +numbers. This is particularly important to support exporting a
1359 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1360 +backend block device for its own. But some storage is necessary to
1361 +keep and maintain the inode numbers. It may be a large space and may not
1362 +suit to keep in memory. Aufs rents some space from its first writable
1363 +branch filesystem (by default) and creates file(s) on it. These files
1364 +are created by aufs internally and removed soon (currently) keeping
1366 +Note: Because these files are removed, they are totally gone after
1367 + unmounting aufs. It means the inode numbers are not persistent
1368 + across unmount or reboot. I have a plan to make them really
1369 + persistent which will be important for aufs on NFS server.
1371 +4. Read/Write Files Internally (copy-on-write)
1372 +Because a branch can be readonly, when you write a file on it, aufs will
1373 +"copy-up" it to the upper writable branch internally. And then write the
1374 +originally requested thing to the file. Generally kernel doesn't
1375 +open/read/write file actively. In aufs, even a single write may cause a
1376 +internal "file copy". This behaviour is very similar to cp(1) command.
1378 +Some people may think it is better to pass such work to user space
1379 +helper, instead of doing in kernel space. Actually I am still thinking
1380 +about it. But currently I have implemented it in kernel space.
1381 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1382 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 08:00:00.000000000 +0800
1383 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2019-07-11 21:21:54.375717654 +0800
1386 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1388 +# This program is free software; you can redistribute it and/or modify
1389 +# it under the terms of the GNU General Public License as published by
1390 +# the Free Software Foundation; either version 2 of the License, or
1391 +# (at your option) any later version.
1393 +# This program is distributed in the hope that it will be useful,
1394 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1395 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1396 +# GNU General Public License for more details.
1398 +# You should have received a copy of the GNU General Public License
1399 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1401 +Basic Aufs Internal Structure
1403 +Superblock/Inode/Dentry/File Objects
1404 +----------------------------------------------------------------------
1405 +As like an ordinary filesystem, aufs has its own
1406 +superblock/inode/dentry/file objects. All these objects have a
1407 +dynamically allocated array and store the same kind of pointers to the
1408 +lower filesystem, branch.
1409 +For example, when you build a union with one readwrite branch and one
1410 +readonly, mounted /au, /rw and /ro respectively.
1412 +- /ro/fileA exists but /rw/fileA
1414 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1415 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1416 +- [0] = NULL (because /rw/fileA doesn't exist)
1419 +This style of an array is essentially same to the aufs
1420 +superblock/inode/dentry/file objects.
1422 +Because aufs supports manipulating branches, ie. add/delete/change
1423 +branches dynamically, these objects has its own generation. When
1424 +branches are changed, the generation in aufs superblock is
1425 +incremented. And a generation in other object are compared when it is
1426 +accessed. When a generation in other objects are obsoleted, aufs
1427 +refreshes the internal array.
1431 +----------------------------------------------------------------------
1432 +Additionally aufs superblock has some data for policies to select one
1433 +among multiple writable branches, XIB files, pseudo-links and kobject.
1434 +See below in detail.
1435 +About the policies which supports copy-down a directory, see
1436 +wbr_policy.txt too.
1439 +Branch and XINO(External Inode Number Translation Table)
1440 +----------------------------------------------------------------------
1441 +Every branch has its own xino (external inode number translation table)
1442 +file. The xino file is created and unlinked by aufs internally. When two
1443 +members of a union exist on the same filesystem, they share the single
1445 +The struct of a xino file is simple, just a sequence of aufs inode
1446 +numbers which is indexed by the lower inode number.
1447 +In the above sample, assume the inode number of /ro/fileA is i111 and
1448 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1449 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1451 +When the inode numbers are not contiguous, the xino file will be sparse
1452 +which has a hole in it and doesn't consume as much disk space as it
1453 +might appear. If your branch filesystem consumes disk space for such
1454 +holes, then you should specify 'xino=' option at mounting aufs.
1456 +Aufs has a mount option to free the disk blocks for such holes in XINO
1457 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1458 +meet a problem of disk shortage due to XINO files, then you should try
1459 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1460 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1461 +the holes in XINO files.
1463 +Also a writable branch has three kinds of "whiteout bases". All these
1464 +are existed when the branch is joined to aufs, and their names are
1465 +whiteout-ed doubly, so that users will never see their names in aufs
1467 +1. a regular file which will be hardlinked to all whiteouts.
1468 +2. a directory to store a pseudo-link.
1469 +3. a directory to store an "orphan"-ed file temporary.
1472 + When you remove a file on a readonly branch, aufs handles it as a
1473 + logical deletion and creates a whiteout on the upper writable branch
1474 + as a hardlink of this file in order not to consume inode on the
1477 + See below, Pseudo-link.
1479 + When "fileC" exists on the lower readonly branch only and it is
1480 + opened and removed with its parent dir, and then user writes
1481 + something into it, then aufs copies-up fileC to this
1482 + directory. Because there is no other dir to store fileC. After
1483 + creating a file under this dir, the file is unlinked.
1485 +Because aufs supports manipulating branches, ie. add/delete/change
1486 +dynamically, a branch has its own id. When the branch order changes,
1487 +aufs finds the new index by searching the branch id.
1491 +----------------------------------------------------------------------
1492 +Assume "fileA" exists on the lower readonly branch only and it is
1493 +hardlinked to "fileB" on the branch. When you write something to fileA,
1494 +aufs copies-up it to the upper writable branch. Additionally aufs
1495 +creates a hardlink under the Pseudo-link Directory of the writable
1496 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1497 +simple list. If fileB is read after unlinking fileA, aufs returns
1498 +filedata from the pseudo-link instead of the lower readonly
1499 +branch. Because the pseudo-link is based upon the inode, to keep the
1500 +inode number by xino (see above) is essentially necessary.
1502 +All the hardlinks under the Pseudo-link Directory of the writable branch
1503 +should be restored in a proper location later. Aufs provides a utility
1504 +to do this. The userspace helpers executed at remounting and unmounting
1506 +During this utility is running, it puts aufs into the pseudo-link
1507 +maintenance mode. In this mode, only the process which began the
1508 +maintenance mode (and its child processes) is allowed to operate in
1509 +aufs. Some other processes which are not related to the pseudo-link will
1510 +be allowed to run too, but the rest have to return an error or wait
1511 +until the maintenance mode ends. If a process already acquires an inode
1512 +mutex (in VFS), it has to return an error.
1515 +XIB(external inode number bitmap)
1516 +----------------------------------------------------------------------
1517 +Addition to the xino file per a branch, aufs has an external inode number
1518 +bitmap in a superblock object. It is also an internal file such like a
1520 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1522 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1524 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1525 +reduce the number of consumed disk blocks for these files.
1528 +Virtual or Vertical Dir, and Readdir in Userspace
1529 +----------------------------------------------------------------------
1530 +In order to support multiple layers (branches), aufs readdir operation
1531 +constructs a virtual dir block on memory. For readdir, aufs calls
1532 +vfs_readdir() internally for each dir on branches, merges their entries
1533 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1534 +object. So the file object has its entry list until it is closed. The
1535 +entry list will be updated when the file position is zero and becomes
1536 +obsoleted. This decision is made in aufs automatically.
1538 +The dynamically allocated memory block for the name of entries has a
1539 +unit of 512 bytes (by default) and stores the names contiguously (no
1540 +padding). Another block for each entry is handled by kmem_cache too.
1541 +During building dir blocks, aufs creates hash list and judging whether
1542 +the entry is whiteouted by its upper branch or already listed.
1543 +The merged result is cached in the corresponding inode object and
1544 +maintained by a customizable life-time option.
1546 +Some people may call it can be a security hole or invite DoS attack
1547 +since the opened and once readdir-ed dir (file object) holds its entry
1548 +list and becomes a pressure for system memory. But I'd say it is similar
1549 +to files under /proc or /sys. The virtual files in them also holds a
1550 +memory page (generally) while they are opened. When an idea to reduce
1551 +memory for them is introduced, it will be applied to aufs too.
1552 +For those who really hate this situation, I've developed readdir(3)
1553 +library which operates this merging in userspace. You just need to set
1554 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1555 +kernel space for readdir(3).
1559 +----------------------------------------------------------------------
1560 +Aufs sometimes requires privilege access to a branch. For instance,
1561 +in copy-up/down operation. When a user process is going to make changes
1562 +to a file which exists in the lower readonly branch only, and the mode
1563 +of one of ancestor directories may not be writable by a user
1564 +process. Here aufs copy-up the file with its ancestors and they may
1565 +require privilege to set its owner/group/mode/etc.
1566 +This is a typical case of a application character of aufs (see
1569 +Aufs uses workqueue synchronously for this case. It creates its own
1570 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1571 +passes the request to call mkdir or write (for example), and wait for
1572 +its completion. This approach solves a problem of a signal handler
1574 +If aufs didn't adopt the workqueue and changed the privilege of the
1575 +process, then the process may receive the unexpected SIGXFSZ or other
1578 +Also aufs uses the system global workqueue ("events" kernel thread) too
1579 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1580 +whiteout base and etc. This is unrelated to a privilege.
1581 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1582 +superblock at the beginning, at the same time waits for the completion
1583 +of all queued asynchronous tasks.
1587 +----------------------------------------------------------------------
1588 +The whiteout in aufs is very similar to Unionfs's. That is represented
1589 +by its filename. UnionMount takes an approach of a file mode, but I am
1590 +afraid several utilities (find(1) or something) will have to support it.
1592 +Basically the whiteout represents "logical deletion" which stops aufs to
1593 +lookup further, but also it represents "dir is opaque" which also stop
1596 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1597 +In order to make several functions in a single systemcall to be
1598 +revertible, aufs adopts an approach to rename a directory to a temporary
1599 +unique whiteouted name.
1600 +For example, in rename(2) dir where the target dir already existed, aufs
1601 +renames the target dir to a temporary unique whiteouted name before the
1602 +actual rename on a branch, and then handles other actions (make it opaque,
1603 +update the attributes, etc). If an error happens in these actions, aufs
1604 +simply renames the whiteouted name back and returns an error. If all are
1605 +succeeded, aufs registers a function to remove the whiteouted unique
1606 +temporary name completely and asynchronously to the system global
1611 +----------------------------------------------------------------------
1612 +It is a well-known feature or concept.
1613 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1614 +internally and makes change to the new file on the upper writable branch.
1615 +When the trigger systemcall does not update the timestamps of the parent
1616 +dir, aufs reverts it after copy-up.
1619 +Move-down (aufs3.9 and later)
1620 +----------------------------------------------------------------------
1621 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1622 +the lower readonly branch to the upper writable branch when a user
1623 +changes something about the file.
1624 +"Move-down" is an opposite action of copy-up. Basically this action is
1625 +ran manually instead of automatically and internally.
1626 +For desgin and implementation, aufs has to consider these issues.
1627 +- whiteout for the file may exist on the lower branch.
1628 +- ancestor directories may not exist on the lower branch.
1629 +- diropq for the ancestor directories may exist on the upper branch.
1630 +- free space on the lower branch will reduce.
1631 +- another access to the file may happen during moving-down, including
1632 + UDBA (see "Revalidate Dentry and UDBA").
1633 +- the file should not be hard-linked nor pseudo-linked. they should be
1634 + handled by auplink utility later.
1636 +Sometimes users want to move-down a file from the upper writable branch
1637 +to the lower readonly or writable branch. For instance,
1638 +- the free space of the upper writable branch is going to run out.
1639 +- create a new intermediate branch between the upper and lower branch.
1642 +For this purpose, use "aumvdown" command in aufs-util.git.
1643 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1644 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 08:00:00.000000000 +0800
1645 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2019-07-11 21:21:54.375717654 +0800
1648 +# Copyright (C) 2015-2019 Junjiro R. Okajima
1650 +# This program is free software; you can redistribute it and/or modify
1651 +# it under the terms of the GNU General Public License as published by
1652 +# the Free Software Foundation; either version 2 of the License, or
1653 +# (at your option) any later version.
1655 +# This program is distributed in the hope that it will be useful,
1656 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1657 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1658 +# GNU General Public License for more details.
1660 +# You should have received a copy of the GNU General Public License
1661 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1663 +Support for a branch who has its ->atomic_open()
1664 +----------------------------------------------------------------------
1665 +The filesystems who implement its ->atomic_open() are not majority. For
1666 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1667 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1668 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1669 +sure whether all filesystems who have ->atomic_open() behave like this,
1670 +but NFSv4 surely returns the error.
1672 +In order to support ->atomic_open() for aufs, there are a few
1675 +A. Introduce aufs_atomic_open()
1676 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1678 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1679 + an aufs user Pip Cet's approach
1680 + - calls aufs_create(), VFS finish_open() and notify_change().
1681 + - pass fake-mode to finish_open(), and then correct the mode by
1683 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1684 + - no aufs_atomic_open().
1685 + - aufs_lookup() registers the TID to an aufs internal object.
1686 + - aufs_create() does nothing when the matching TID is registered, but
1687 + registers the mode.
1688 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1689 + TID is registered.
1690 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1692 + - no aufs_atomic_open().
1693 + - aufs_create() registers the TID to an internal object. this info
1694 + represents "this process created this file just now."
1695 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1696 + registered TID and re-try open() with superuser's credential.
1698 +Pros and cons for each approach.
1701 + - straightforward but highly depends upon VFS internal.
1702 + - the atomic behavaiour is kept.
1703 + - some of parameters such as nameidata are hard to reproduce for
1707 + - easy to implement.
1708 + - the atomic behavaiour is lost.
1710 + - the atomic behavaiour is kept.
1711 + - dirty and tricky.
1712 + - VFS checks whether the file is created correctly after calling
1713 + ->create(), which means this approach doesn't work.
1715 + - easy to implement.
1716 + - the atomic behavaiour is lost.
1717 + - to open a file with superuser's credential and give it to a user
1718 + process is a bad idea, since the file object keeps the credential
1719 + in it. It may affect LSM or something. This approach doesn't work
1722 +The approach A is ideal, but it hard to implement. So here is a
1723 +variation of A, which is to be implemented.
1725 +A-1. Introduce aufs_atomic_open()
1726 + - calls branch fs ->atomic_open() if exists. otherwise calls
1727 + vfs_create() and finish_open().
1728 + - the demerit is that the several checks after branch fs
1729 + ->atomic_open() are lost. in the ordinary case, the checks are
1730 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1731 + be implemented in aufs, but not all I am afraid.
1732 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1733 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 08:00:00.000000000 +0800
1734 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2019-07-11 21:21:54.375717654 +0800
1737 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1739 +# This program is free software; you can redistribute it and/or modify
1740 +# it under the terms of the GNU General Public License as published by
1741 +# the Free Software Foundation; either version 2 of the License, or
1742 +# (at your option) any later version.
1744 +# This program is distributed in the hope that it will be useful,
1745 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1746 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1747 +# GNU General Public License for more details.
1749 +# You should have received a copy of the GNU General Public License
1750 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1753 +----------------------------------------------------------------------
1754 +Since aufs has a character of sub-VFS (see Introduction), it operates
1755 +lookup for branches as VFS does. It may be a heavy work. But almost all
1756 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1757 +directly connected to its parent. Digging down the directory hierarchy
1758 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1761 +When a branch is a remote filesystem, aufs basically relies upon its
1762 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1764 +For d_revalidate, aufs implements three levels of revalidate tests. See
1765 +"Revalidate Dentry and UDBA" in detail.
1768 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1769 +----------------------------------------------------------------------
1770 +Let's try case study.
1771 +- aufs has two branches, upper readwrite and lower readonly.
1773 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1774 +- user invoked "chmod a+rx /au/dirA"
1775 +- the internal copy-up is activated and "/rw/dirA" is created and its
1776 + permission bits are set to world readable.
1777 +- then "/au/dirA" becomes world readable?
1779 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1780 +or it may be a natively readonly filesystem. If aufs respects the lower
1781 +branch, it should not respond readdir request from other users. But user
1782 +allowed it by chmod. Should really aufs rejects showing the entries
1785 +To be honest, I don't have a good solution for this case. So aufs
1786 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1788 +When dirperm1 is specified, aufs checks only the highest one for the
1789 +directory permission, and shows the entries. Otherwise, as usual, checks
1790 +every dir existing on all branches and rejects the request.
1792 +As a side effect, dirperm1 option improves the performance of aufs
1793 +because the number of permission check is reduced when the number of
1797 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1798 +----------------------------------------------------------------------
1799 +Generally VFS helpers re-validate a dentry as a part of lookup.
1800 +0. digging down the directory hierarchy.
1801 +1. lock the parent dir by its i_mutex.
1802 +2. lookup the final (child) entry.
1804 +4. call the actual operation (create, unlink, etc.)
1805 +5. unlock the parent dir
1807 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1808 +called. Actually aufs implements it and checks the dentry on a branch is
1810 +But it is not enough. Because aufs has to release the lock for the
1811 +parent dir on a branch at the end of ->lookup() (step 2) and
1812 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1814 +If the file on a branch is changed directly, eg. bypassing aufs, after
1815 +aufs released the lock, then the subsequent operation may cause
1816 +something unpleasant result.
1818 +This situation is a result of VFS architecture, ->lookup() and
1819 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1820 +design from VFS's point of view. It is just not suitable for sub-VFS
1823 +Aufs supports such case by three level of revalidation which is
1824 +selectable by user.
1825 +1. Simple Revalidate
1826 + Addition to the native flow in VFS's, confirm the child-parent
1827 + relationship on the branch just after locking the parent dir on the
1828 + branch in the "actual operation" (step 4). When this validation
1829 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1830 + checks the validation of the dentry on branches.
1831 +2. Monitor Changes Internally by Inotify/Fsnotify
1832 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1833 + the dentry on the branch, and returns EBUSY if it finds different
1835 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1836 + during it is in cache. When the event is notified, aufs registers a
1837 + function to kernel 'events' thread by schedule_work(). And the
1838 + function sets some special status to the cached aufs dentry and inode
1839 + private data. If they are not cached, then aufs has nothing to
1840 + do. When the same file is accessed through aufs (step 0-3) later,
1841 + aufs will detect the status and refresh all necessary data.
1842 + In this mode, aufs has to ignore the event which is fired by aufs
1844 +3. No Extra Validation
1845 + This is the simplest test and doesn't add any additional revalidation
1846 + test, and skip the revalidation in step 4. It is useful and improves
1847 + aufs performance when system surely hide the aufs branches from user,
1848 + by over-mounting something (or another method).
1849 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1850 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 08:00:00.000000000 +0800
1851 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2019-07-11 21:21:54.375717654 +0800
1854 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1856 +# This program is free software; you can redistribute it and/or modify
1857 +# it under the terms of the GNU General Public License as published by
1858 +# the Free Software Foundation; either version 2 of the License, or
1859 +# (at your option) any later version.
1861 +# This program is distributed in the hope that it will be useful,
1862 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1863 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1864 +# GNU General Public License for more details.
1866 +# You should have received a copy of the GNU General Public License
1867 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1869 +Branch Manipulation
1871 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1872 +and changing its permission/attribute, there are a lot of works to do.
1876 +----------------------------------------------------------------------
1877 +o Confirm the adding dir exists outside of aufs, including loopback
1878 + mount, and its various attributes.
1879 +o Initialize the xino file and whiteout bases if necessary.
1882 +o Check the owner/group/mode of the directory
1883 + When the owner/group/mode of the adding directory differs from the
1884 + existing branch, aufs issues a warning because it may impose a
1886 + For example, when a upper writable branch has a world writable empty
1887 + top directory, a malicious user can create any files on the writable
1888 + branch directly, like copy-up and modify manually. If something like
1889 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1890 + writable branch, and the writable branch is world-writable, then a
1891 + malicious guy may create /etc/passwd on the writable branch directly
1892 + and the infected file will be valid in aufs.
1893 + I am afraid it can be a security issue, but aufs can do nothing except
1894 + producing a warning.
1898 +----------------------------------------------------------------------
1899 +o Confirm the deleting branch is not busy
1900 + To be general, there is one merit to adopt "remount" interface to
1901 + manipulate branches. It is to discard caches. At deleting a branch,
1902 + aufs checks the still cached (and connected) dentries and inodes. If
1903 + there are any, then they are all in-use. An inode without its
1904 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1906 + For the cached one, aufs checks whether the same named entry exists on
1908 + If the cached one is a directory, because aufs provides a merged view
1909 + to users, as long as one dir is left on any branch aufs can show the
1910 + dir to users. In this case, the branch can be removed from aufs.
1911 + Otherwise aufs rejects deleting the branch.
1913 + If any file on the deleting branch is opened by aufs, then aufs
1917 +Modify the Permission of a Branch
1918 +----------------------------------------------------------------------
1919 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1922 +o rw --> ro: Confirm the modifying branch is not busy
1923 + Aufs rejects the request if any of these conditions are true.
1924 + - a file on the branch is mmap-ed.
1925 + - a regular file on the branch is opened for write and there is no
1926 + same named entry on the upper branch.
1927 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1928 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 08:00:00.000000000 +0800
1929 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2019-07-11 21:21:54.375717654 +0800
1932 +# Copyright (C) 2005-2019 Junjiro R. Okajima
1934 +# This program is free software; you can redistribute it and/or modify
1935 +# it under the terms of the GNU General Public License as published by
1936 +# the Free Software Foundation; either version 2 of the License, or
1937 +# (at your option) any later version.
1939 +# This program is distributed in the hope that it will be useful,
1940 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1941 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1942 +# GNU General Public License for more details.
1944 +# You should have received a copy of the GNU General Public License
1945 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1947 +Policies to Select One among Multiple Writable Branches
1948 +----------------------------------------------------------------------
1949 +When the number of writable branch is more than one, aufs has to decide
1950 +the target branch for file creation or copy-up. By default, the highest
1951 +writable branch which has the parent (or ancestor) dir of the target
1952 +file is chosen (top-down-parent policy).
1953 +By user's request, aufs implements some other policies to select the
1954 +writable branch, for file creation several policies, round-robin,
1955 +most-free-space, and other policies. For copy-up, top-down-parent,
1956 +bottom-up-parent, bottom-up and others.
1958 +As expected, the round-robin policy selects the branch in circular. When
1959 +you have two writable branches and creates 10 new files, 5 files will be
1960 +created for each branch. mkdir(2) systemcall is an exception. When you
1961 +create 10 new directories, all will be created on the same branch.
1962 +And the most-free-space policy selects the one which has most free
1963 +space among the writable branches. The amount of free space will be
1964 +checked by aufs internally, and users can specify its time interval.
1966 +The policies for copy-up is more simple,
1967 +top-down-parent is equivalent to the same named on in create policy,
1968 +bottom-up-parent selects the writable branch where the parent dir
1969 +exists and the nearest upper one from the copyup-source,
1970 +bottom-up selects the nearest upper writable branch from the
1971 +copyup-source, regardless the existence of the parent dir.
1973 +There are some rules or exceptions to apply these policies.
1974 +- If there is a readonly branch above the policy-selected branch and
1975 + the parent dir is marked as opaque (a variation of whiteout), or the
1976 + target (creating) file is whiteout-ed on the upper readonly branch,
1977 + then the result of the policy is ignored and the target file will be
1978 + created on the nearest upper writable branch than the readonly branch.
1979 +- If there is a writable branch above the policy-selected branch and
1980 + the parent dir is marked as opaque or the target file is whiteouted
1981 + on the branch, then the result of the policy is ignored and the target
1982 + file will be created on the highest one among the upper writable
1983 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1985 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1986 + They try selecting the branch where the source exists as possible
1987 + since copyup a large file will take long time. If it can't be,
1988 + ie. the branch where the source exists is readonly, then they will
1989 + follow the copyup policy.
1990 +- There is an exception for rename(2) when the target exists.
1991 + If the rename target exists, aufs compares the index of the branches
1992 + where the source and the target exists and selects the higher
1993 + one. If the selected branch is readonly, then aufs follows the
1995 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1996 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 08:00:00.000000000 +0800
1997 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 21:21:54.375717654 +0800
2000 +// to view this graph, run dot(1) command in GRAPHVIZ.
2004 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2008 +aufs_rename -> whinfo [label="store/remove"];
2011 +inode_list [label="h_inum list in branch\ncache"];
2014 +whinode [label="h_inum list file"];
2017 +brmgmt [label="br_add/del/mod/umount"];
2019 +brmgmt -> inode_list [label="create/remove"];
2020 +brmgmt -> whinode [label="load/store"];
2022 +inode_list -> whinode [style=dashed,dir=both];
2024 +aufs_rename -> inode_list [label="add/del"];
2026 +aufs_lookup -> inode_list [label="search"];
2028 +aufs_lookup -> whinfo [label="load/remove"];
2030 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2031 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 08:00:00.000000000 +0800
2032 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2019-07-11 21:21:54.375717654 +0800
2035 +# Copyright (C) 2017-2019 Junjiro R. Okajima
2037 +# This program is free software; you can redistribute it and/or modify
2038 +# it under the terms of the GNU General Public License as published by
2039 +# the Free Software Foundation; either version 2 of the License, or
2040 +# (at your option) any later version.
2042 +# This program is distributed in the hope that it will be useful,
2043 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2044 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2045 +# GNU General Public License for more details.
2047 +# You should have received a copy of the GNU General Public License
2048 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2050 +Special handling for renaming a directory (DIRREN)
2051 +----------------------------------------------------------------------
2052 +First, let's assume we have a simple usecase.
2056 +- /ro/dirA and /ro/dirA/file exist too
2057 +- there is no dirB on both branches
2058 +- a user issues rename("dirA", "dirB")
2060 +Now, what should aufs behave against this rename(2)?
2061 +There are a few possible cases.
2064 + since dirA exists on a readonly branch which cannot be renamed.
2066 + it is possible to copy-up dirA (only the dir itself), but the child
2067 + entries ("file" in this case) should not be. it must be a bad
2068 + approach to copy-up recursively.
2069 +C. returns a success.
2070 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2071 + is a violation of aufs' policy.
2072 +D. construct an extra information which indicates that /ro/dirA should
2073 + be handled as the name of dirB.
2074 + overlayfs has a similar feature called REDIRECT.
2076 +Until now, aufs implements the case B only which returns EXDEV, and
2077 +expects the userspace application behaves like mv(1) which tries
2078 +issueing rename(2) recursively.
2080 +A new aufs feature called DIRREN is introduced which implements the case
2081 +D. There are several "extra information" added.
2083 +1. detailed info per renamed directory
2084 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2085 +2. the inode-number list of directories on a branch
2086 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2088 +The filename of "detailed info per directory" represents the lower
2089 +branch, and its format is
2090 +- a type of the branch id
2092 + + uuid (not implemented yet)
2095 +- the inode-number of the branch root dir
2097 +And it contains these info in a single regular file.
2099 +- branch's inode-number of the logically renamed dir
2100 +- the name of the before-renamed dir
2102 +The "detailed info per directory" file is created in aufs rename(2), and
2103 +loaded in any lookup.
2104 +The info is considered in lookup for the matching case only. Here
2105 +"matching" means that the root of branch (in the info filename) is same
2106 +to the current looking-up branch. After looking-up the before-renamed
2107 +name, the inode-number is compared. And the matched dentry is used.
2109 +The "inode-number list of directories" is a regular file which contains
2110 +simply the inode-numbers on the branch. The file is created or updated
2111 +in removing the branch, and loaded in adding the branch. Its lifetime is
2112 +equal to the branch.
2113 +The list is refered in lookup, and when the current target inode is
2114 +found in the list, the aufs tries loading the "detailed info per
2115 +directory" and get the changed and valid name of the dir.
2117 +Theoretically these "extra informaiton" may be able to be put into XATTR
2118 +in the dir inode. But aufs doesn't choose this way because
2119 +1. XATTR may not be supported by the branch (or its configuration)
2120 +2. XATTR may have its size limit.
2121 +3. XATTR may be less easy to convert than a regular file, when the
2122 + format of the info is changed in the future.
2123 +At the same time, I agree that the regular file approach is much slower
2124 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2127 +This DIRREN feature is enabled by aufs configuration, and is activated
2128 +by a new mount option.
2130 +For the more complicated case, there is a work with UDBA option, which
2131 +is to dected the direct access to the branches (by-passing aufs) and to
2132 +maintain the cashes in aufs. Since a single cached aufs dentry may
2133 +contains two names, before- and after-rename, the name comparision in
2134 +UDBA handler may not work correctly. In this case, the behaviour will be
2135 +equivalen to udba=reval case.
2136 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2137 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 08:00:00.000000000 +0800
2138 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2019-07-11 21:21:54.375717654 +0800
2141 +# Copyright (C) 2011-2019 Junjiro R. Okajima
2143 +# This program is free software; you can redistribute it and/or modify
2144 +# it under the terms of the GNU General Public License as published by
2145 +# the Free Software Foundation; either version 2 of the License, or
2146 +# (at your option) any later version.
2148 +# This program is distributed in the hope that it will be useful,
2149 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2150 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2151 +# GNU General Public License for more details.
2153 +# You should have received a copy of the GNU General Public License
2154 +# along with this program; if not, write to the Free Software
2155 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2158 +File-based Hierarchical Storage Management (FHSM)
2159 +----------------------------------------------------------------------
2160 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2161 +storage world. Aufs provides this feature as file-based with multiple
2162 +writable branches, based upon the principle of "Colder, the Lower".
2163 +Here the word "colder" means that the less used files, and "lower" means
2164 +that the position in the order of the stacked branches vertically.
2165 +These multiple writable branches are prioritized, ie. the topmost one
2166 +should be the fastest drive and be used heavily.
2168 +o Characters in aufs FHSM story
2169 +- aufs itself and a new branch attribute.
2170 +- a new ioctl interface to move-down and to establish a connection with
2171 + the daemon ("move-down" is a converse of "copy-up").
2172 +- userspace tool and daemon.
2174 +The userspace daemon establishes a connection with aufs and waits for
2175 +the notification. The notified information is very similar to struct
2176 +statfs containing the number of consumed blocks and inodes.
2177 +When the consumed blocks/inodes of a branch exceeds the user-specified
2178 +upper watermark, the daemon activates its move-down process until the
2179 +consumed blocks/inodes reaches the user-specified lower watermark.
2181 +The actual move-down is done by aufs based upon the request from
2182 +user-space since we need to maintain the inode number and the internal
2183 +pointer arrays in aufs.
2185 +Currently aufs FHSM handles the regular files only. Additionally they
2186 +must not be hard-linked nor pseudo-linked.
2189 +o Cowork of aufs and the user-space daemon
2190 + During the userspace daemon established the connection, aufs sends a
2191 + small notification to it whenever aufs writes something into the
2192 + writable branch. But it may cost high since aufs issues statfs(2)
2193 + internally. So user can specify a new option to cache the
2194 + info. Actually the notification is controlled by these factors.
2195 + + the specified cache time.
2196 + + classified as "force" by aufs internally.
2197 + Until the specified time expires, aufs doesn't send the info
2198 + except the forced cases. When aufs decide forcing, the info is always
2199 + notified to userspace.
2200 + For example, the number of free inodes is generally large enough and
2201 + the shortage of it happens rarely. So aufs doesn't force the
2202 + notification when creating a new file, directory and others. This is
2203 + the typical case which aufs doesn't force.
2204 + When aufs writes the actual filedata and the files consumes any of new
2205 + blocks, the aufs forces notifying.
2208 +o Interfaces in aufs
2209 +- New branch attribute.
2211 + Specifies that the branch is managed by FHSM feature. In other word,
2212 + participant in the FHSM.
2213 + When nofhsm is set to the branch, it will not be the source/target
2214 + branch of the move-down operation. This attribute is set
2215 + independently from coo and moo attributes, and if you want full
2216 + FHSM, you should specify them as well.
2217 +- New mount option.
2219 + Specifies a second to suppress many less important info to be
2222 + + AUFS_CTL_FHSM_FD
2223 + create a new file descriptor which userspace can read the notification
2224 + (a subset of struct statfs) from aufs.
2225 +- Module parameter 'brs'
2226 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2228 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2229 + When there are two or more branches with fhsm attributes,
2230 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2231 + terminates it. As a result of remounting and branch-manipulation, the
2232 + number of branches with fhsm attribute can be one. In this case,
2233 + /sbin/mount.aufs will terminate the user-space daemon.
2236 +Finally the operation is done as these steps in kernel-space.
2238 + + no one else is using the file.
2239 + + the file is not hard-linked.
2240 + + the file is not pseudo-linked.
2241 + + the file is a regular file.
2242 + + the parent dir is not opaqued.
2243 +- find the target writable branch.
2244 +- make sure the file is not whiteout-ed by the upper (than the target)
2246 +- make the parent dir on the target branch.
2247 +- mutex lock the inode on the branch.
2248 +- unlink the whiteout on the target branch (if exists).
2249 +- lookup and create the whiteout-ed temporary name on the target branch.
2250 +- copy the file as the whiteout-ed temporary name on the target branch.
2251 +- rename the whiteout-ed temporary name to the original name.
2252 +- unlink the file on the source branch.
2253 +- maintain the internal pointer array and the external inode number
2255 +- maintain the timestamps and other attributes of the parent dir and the
2258 +And of course, in every step, an error may happen. So the operation
2259 +should restore the original file state after an error happens.
2260 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2261 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 08:00:00.000000000 +0800
2262 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2019-07-11 21:21:54.375717654 +0800
2265 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2267 +# This program is free software; you can redistribute it and/or modify
2268 +# it under the terms of the GNU General Public License as published by
2269 +# the Free Software Foundation; either version 2 of the License, or
2270 +# (at your option) any later version.
2272 +# This program is distributed in the hope that it will be useful,
2273 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2274 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2275 +# GNU General Public License for more details.
2277 +# You should have received a copy of the GNU General Public License
2278 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2280 +mmap(2) -- File Memory Mapping
2281 +----------------------------------------------------------------------
2282 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2283 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2285 +This approach is simple and good, but there is one problem.
2286 +Under /proc, several entries show the mmapped files by its path (with
2287 +device and inode number), and the printed path will be the path on the
2288 +branch fs's instead of virtual aufs's.
2289 +This is not a problem in most cases, but some utilities lsof(1) (and its
2290 +user) may expect the path on aufs.
2292 +To address this issue, aufs adds a new member called vm_prfile in struct
2293 +vm_area_struct (and struct vm_region). The original vm_file points to
2294 +the file on the branch fs in order to handle everything correctly as
2295 +usual. The new vm_prfile points to a virtual file in aufs, and the
2296 +show-functions in procfs refers to vm_prfile if it is set.
2297 +Also we need to maintain several other places where touching vm_file
2299 +- fork()/clone() copies vma and the reference count of vm_file is
2301 +- merging vma maintains the ref count too.
2303 +This is not a good approach. It just fakes the printed path. But it
2304 +leaves all behaviour around f_mapping unchanged. This is surely an
2306 +Actually aufs had adopted another complicated approach which calls
2307 +generic_file_mmap() and handles struct vm_operations_struct. In this
2308 +approach, aufs met a hard problem and I could not solve it without
2309 +switching the approach.
2311 +There may be one more another approach which is
2312 +- bind-mount the branch-root onto the aufs-root internally
2313 +- grab the new vfsmount (ie. struct mount)
2314 +- lazy-umount the branch-root internally
2315 +- in open(2) the aufs-file, open the branch-file with the hidden
2316 + vfsmount (instead of the original branch's vfsmount)
2317 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2318 + but it may be possible from userspace by the mount helper.
2320 +Adding the internal hidden vfsmount and using it in opening a file, the
2321 +file path under /proc will be printed correctly. This approach looks
2322 +smarter, but is not possible I am afraid.
2323 +- aufs-root may be bind-mount later. when it happens, another hidden
2324 + vfsmount will be required.
2325 +- it is hard to get the chance to bind-mount and lazy-umount
2326 + + in kernel-space, FS can have vfsmount in open(2) via
2327 + file->f_path, and aufs can know its vfsmount. But several locks are
2328 + already acquired, and if aufs tries to bind-mount and lazy-umount
2329 + here, then it may cause a deadlock.
2330 + + in user-space, bind-mount doesn't invoke the mount helper.
2331 +- since /proc shows dev and ino, aufs has to give vma these info. it
2332 + means a new member vm_prinode will be necessary. this is essentially
2333 + equivalent to vm_prfile described above.
2335 +I have to give up this "looks-smater" approach.
2336 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2337 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 08:00:00.000000000 +0800
2338 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2019-07-11 21:21:54.375717654 +0800
2341 +# Copyright (C) 2014-2019 Junjiro R. Okajima
2343 +# This program is free software; you can redistribute it and/or modify
2344 +# it under the terms of the GNU General Public License as published by
2345 +# the Free Software Foundation; either version 2 of the License, or
2346 +# (at your option) any later version.
2348 +# This program is distributed in the hope that it will be useful,
2349 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2350 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2351 +# GNU General Public License for more details.
2353 +# You should have received a copy of the GNU General Public License
2354 +# along with this program; if not, write to the Free Software
2355 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2358 +Listing XATTR/EA and getting the value
2359 +----------------------------------------------------------------------
2360 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2361 +shows the values from the topmost existing file. This behaviour is good
2362 +for the non-dir entries since the bahaviour exactly matches the shown
2363 +information. But for the directories, aufs considers all the same named
2364 +entries on the lower branches. Which means, if one of the lower entry
2365 +rejects readdir call, then aufs returns an error even if the topmost
2366 +entry allows it. This behaviour is necessary to respect the branch fs's
2367 +security, but can make users confused since the user-visible standard
2368 +attributes don't match the behaviour.
2369 +To address this issue, aufs has a mount option called dirperm1 which
2370 +checks the permission for the topmost entry only, and ignores the lower
2371 +entry's permission.
2373 +A similar issue can happen around XATTR.
2374 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2375 +always set. Otherwise these very unpleasant situation would happen.
2376 +- listxattr(2) may return the duplicated entries.
2377 +- users may not be able to remove or reset the XATTR forever,
2380 +XATTR/EA support in the internal (copy,move)-(up,down)
2381 +----------------------------------------------------------------------
2382 +Generally the extended attributes of inode are categorized as these.
2383 +- "security" for LSM and capability.
2384 +- "system" for posix ACL, 'acl' mount option is required for the branch
2386 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2387 +- "user" for userspace, 'user_xattr' mount option is required for the
2388 + branch fs generally.
2390 +Moreover there are some other categories. Aufs handles these rather
2391 +unpopular categories as the ordinary ones, ie. there is no special
2392 +condition nor exception.
2394 +In copy-up, the support for XATTR on the dst branch may differ from the
2395 +src branch. In this case, the copy-up operation will get an error and
2396 +the original user operation which triggered the copy-up will fail. It
2397 +can happen that even all copy-up will fail.
2398 +When both of src and dst branches support XATTR and if an error occurs
2399 +during copying XATTR, then the copy-up should fail obviously. That is a
2400 +good reason and aufs should return an error to userspace. But when only
2401 +the src branch support that XATTR, aufs should not return an error.
2402 +For example, the src branch supports ACL but the dst branch doesn't
2403 +because the dst branch may natively un-support it or temporary
2404 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2405 +may NOT return an error even if the XATTR is not supported. It is
2406 +totally up to the branch fs.
2408 +Anyway when the aufs internal copy-up gets an error from the dst branch
2409 +fs, then aufs tries removing the just copied entry and returns the error
2410 +to the userspace. The worst case of this situation will be all copy-up
2413 +For the copy-up operation, there two basic approaches.
2414 +- copy the specified XATTR only (by category above), and return the
2415 + error unconditionally if it happens.
2416 +- copy all XATTR, and ignore the error on the specified category only.
2418 +In order to support XATTR and to implement the correct behaviour, aufs
2419 +chooses the latter approach and introduces some new branch attributes,
2420 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2421 +They correspond to the XATTR namespaces (see above). Additionally, to be
2422 +convenient, "icex" is also provided which means all "icex*" attributes
2423 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2425 +The meaning of these attributes is to ignore the error from setting
2426 +XATTR on that branch.
2427 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2428 +error from the dst branch according to the specified attributes.
2430 +Some XATTR may have its default value. The default value may come from
2431 +the parent dir or the environment. If the default value is set at the
2432 +file creating-time, it will be overwritten by copy-up.
2433 +Some contradiction may happen I am afraid.
2434 +Do we need another attribute to stop copying XATTR? I am unsure. For
2435 +now, aufs implements the branch attributes to ignore the error.
2436 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2437 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 08:00:00.000000000 +0800
2438 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2019-07-11 21:21:54.375717654 +0800
2441 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2443 +# This program is free software; you can redistribute it and/or modify
2444 +# it under the terms of the GNU General Public License as published by
2445 +# the Free Software Foundation; either version 2 of the License, or
2446 +# (at your option) any later version.
2448 +# This program is distributed in the hope that it will be useful,
2449 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2450 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2451 +# GNU General Public License for more details.
2453 +# You should have received a copy of the GNU General Public License
2454 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2456 +Export Aufs via NFS
2457 +----------------------------------------------------------------------
2458 +Here is an approach.
2459 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2461 +- iget_locked(): initialize aufs inode generation for a new inode, and
2462 + store it in xigen file.
2463 +- destroy_inode(): increment aufs inode generation and store it in xigen
2464 + file. it is necessary even if it is not unlinked, because any data of
2465 + inode may be changed by UDBA.
2466 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2467 + build file handle by
2468 + + branch id (4 bytes)
2469 + + superblock generation (4 bytes)
2470 + + inode number (4 or 8 bytes)
2471 + + parent dir inode number (4 or 8 bytes)
2472 + + inode generation (4 bytes))
2473 + + return value of exportfs_encode_fh() for the parent on a branch (4
2475 + + file handle for a branch (by exportfs_encode_fh())
2477 + + find the index of a branch from its id in handle, and check it is
2478 + still exist in aufs.
2479 + + 1st level: get the inode number from handle and search it in cache.
2480 + + 2nd level: if not found in cache, get the parent inode number from
2481 + the handle and search it in cache. and then open the found parent
2482 + dir, find the matching inode number by vfs_readdir() and get its
2483 + name, and call lookup_one_len() for the target dentry.
2484 + + 3rd level: if the parent dir is not cached, call
2485 + exportfs_decode_fh() for a branch and get the parent on a branch,
2486 + build a pathname of it, convert it a pathname in aufs, call
2487 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2489 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2490 + for every branch, but not itself. to get this, (currently) aufs
2491 + searches in current->nsproxy->mnt_ns list. it may not be a good
2492 + idea, but I didn't get other approach.
2493 + + test the generation of the gotten inode.
2494 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2495 + convert it into ESTALE for NFSD.
2496 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2497 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2498 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2499 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 08:00:00.000000000 +0800
2500 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2019-07-11 21:21:54.375717654 +0800
2503 +# Copyright (C) 2005-2019 Junjiro R. Okajima
2505 +# This program is free software; you can redistribute it and/or modify
2506 +# it under the terms of the GNU General Public License as published by
2507 +# the Free Software Foundation; either version 2 of the License, or
2508 +# (at your option) any later version.
2510 +# This program is distributed in the hope that it will be useful,
2511 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2512 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2513 +# GNU General Public License for more details.
2515 +# You should have received a copy of the GNU General Public License
2516 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2518 +Show Whiteout Mode (shwh)
2519 +----------------------------------------------------------------------
2520 +Generally aufs hides the name of whiteouts. But in some cases, to show
2521 +them is very useful for users. For instance, creating a new middle layer
2522 +(branch) by merging existing layers.
2524 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2525 +When you have three branches,
2526 +- Bottom: 'system', squashfs (underlying base system), read-only
2527 +- Middle: 'mods', squashfs, read-only
2528 +- Top: 'overlay', ram (tmpfs), read-write
2530 +The top layer is loaded at boot time and saved at shutdown, to preserve
2531 +the changes made to the system during the session.
2532 +When larger changes have been made, or smaller changes have accumulated,
2533 +the size of the saved top layer data grows. At this point, it would be
2534 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2535 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2536 +restoring save and load speed.
2538 +This merging is simplified by the use of another aufs mount, of just the
2539 +two overlay branches using the 'shwh' option.
2540 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2541 + aufs /livesys/merge_union
2543 +A merged view of these two branches is then available at
2544 +/livesys/merge_union, and the new feature is that the whiteouts are
2546 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2547 +writing to all branches. Also the default mode for all branches is 'ro'.
2548 +It is now possible to save the combined contents of the two overlay
2549 +branches to a new squashfs, e.g.:
2550 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2552 +This new squashfs archive can be stored on the boot device and the
2553 +initramfs will use it to replace the old one at the next boot.
2554 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2555 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 08:00:00.000000000 +0800
2556 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2019-07-11 21:21:54.375717654 +0800
2559 +# Copyright (C) 2010-2019 Junjiro R. Okajima
2561 +# This program is free software; you can redistribute it and/or modify
2562 +# it under the terms of the GNU General Public License as published by
2563 +# the Free Software Foundation; either version 2 of the License, or
2564 +# (at your option) any later version.
2566 +# This program is distributed in the hope that it will be useful,
2567 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2568 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2569 +# GNU General Public License for more details.
2571 +# You should have received a copy of the GNU General Public License
2572 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2574 +Dynamically customizable FS operations
2575 +----------------------------------------------------------------------
2576 +Generally FS operations (struct inode_operations, struct
2577 +address_space_operations, struct file_operations, etc.) are defined as
2578 +"static const", but it never means that FS have only one set of
2579 +operation. Some FS have multiple sets of them. For instance, ext2 has
2580 +three sets, one for XIP, for NOBH, and for normal.
2581 +Since aufs overrides and redirects these operations, sometimes aufs has
2582 +to change its behaviour according to the branch FS type. More importantly
2583 +VFS acts differently if a function (member in the struct) is set or
2584 +not. It means aufs should have several sets of operations and select one
2585 +among them according to the branch FS definition.
2587 +In order to solve this problem and not to affect the behaviour of VFS,
2588 +aufs defines these operations dynamically. For instance, aufs defines
2589 +dummy direct_IO function for struct address_space_operations, but it may
2590 +not be set to the address_space_operations actually. When the branch FS
2591 +doesn't have it, aufs doesn't set it to its address_space_operations
2592 +while the function definition itself is still alive. So the behaviour
2593 +itself will not change, and it will return an error when direct_IO is
2596 +The lifetime of these dynamically generated operation object is
2597 +maintained by aufs branch object. When the branch is removed from aufs,
2598 +the reference counter of the object is decremented. When it reaches
2599 +zero, the dynamically generated operation object will be freed.
2601 +This approach is designed to support AIO (io_submit), Direct I/O and
2603 +Currently this approach is applied to address_space_operations for
2604 +regular files only.
2605 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2606 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 08:00:00.000000000 +0800
2607 +++ linux/Documentation/filesystems/aufs/README 2019-07-11 21:21:54.375717654 +0800
2610 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2616 +----------------------------------------
2617 +In the early days, aufs was entirely re-designed and re-implemented
2618 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2619 +improvements and implementations, it became totally different from
2620 +Unionfs while keeping the basic features.
2621 +Later, Unionfs Version 2.x series began taking some of the same
2622 +approaches to aufs1's.
2623 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2624 +University and his team.
2626 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2628 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2629 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2630 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2631 + or aufs1 from CVS on SourceForge.
2633 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2634 + According to Christoph Hellwig, linux rejects all union-type
2635 + filesystems but UnionMount.
2636 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2638 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2639 + UnionMount, and he pointed out an issue around a directory mutex
2640 + lock and aufs addressed it. But it is still unsure whether aufs will
2641 + be merged (or any other union solution).
2642 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2646 +----------------------------------------
2647 +- unite several directories into a single virtual filesystem. The member
2648 + directory is called as a branch.
2649 +- you can specify the permission flags to the branch, which are 'readonly',
2650 + 'readwrite' and 'whiteout-able.'
2651 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2652 + readonly branch are modifiable logically.
2653 +- dynamic branch manipulation, add, del.
2656 +Also there are many enhancements in aufs, such as:
2657 +- test only the highest one for the directory permission (dirperm1)
2658 +- copyup on open (coo=)
2659 +- 'move' policy for copy-up between two writable branches, after
2660 + checking free space.
2662 +- readdir(3) in userspace.
2663 +- keep inode number by external inode number table
2664 +- keep the timestamps of file/dir in internal copyup operation
2665 +- seekable directory, supporting NFS readdir.
2666 +- whiteout is hardlinked in order to reduce the consumption of inodes
2668 +- do not copyup, nor create a whiteout when it is unnecessary
2669 +- revert a single systemcall when an error occurs in aufs
2670 +- remount interface instead of ioctl
2671 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2672 +- loopback mounted filesystem as a branch
2673 +- kernel thread for removing the dir who has a plenty of whiteouts
2674 +- support copyup sparse file (a file which has a 'hole' in it)
2675 +- default permission flags for branches
2676 +- selectable permission flags for ro branch, whether whiteout can
2679 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2680 +- support multiple writable branches, some policies to select one
2681 + among multiple writable branches.
2682 +- a new semantics for link(2) and rename(2) to support multiple
2683 + writable branches.
2684 +- no glibc changes are required.
2685 +- pseudo hardlink (hardlink over branches)
2686 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2687 + including NFS or remote filesystem branch.
2688 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2691 +Currently these features are dropped temporary from aufs5.
2692 +See design/08plan.txt in detail.
2693 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2695 +- statistics of aufs thread (/sys/fs/aufs/stat)
2697 +Features or just an idea in the future (see also design/*.txt),
2698 +- reorder the branch index without del/re-add.
2699 +- permanent xino files for NFSD
2700 +- an option for refreshing the opened files after add/del branches
2701 +- light version, without branch manipulation. (unnecessary?)
2702 +- copyup in userspace
2703 +- inotify in userspace
2708 +----------------------------------------
2709 +There are three GIT trees for aufs5, aufs5-linux.git,
2710 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2712 +While the aufs-util is always necessary, you need either of aufs5-linux
2713 +or aufs5-standalone.
2715 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2716 +git://git.kernel.org/.../torvalds/linux.git.
2717 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2718 +build aufs5 as an external kernel module.
2719 +Several extra patches are not included in this tree. Only
2720 +aufs5-standalone tree contains them. They are described in the later
2721 +section "Configuration and Compilation."
2723 +On the other hand, the aufs5-standalone tree has only aufs source files
2724 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2725 +But you need to apply all aufs patches manually.
2727 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2728 +represents the linux kernel version, "linux-5.x". For instance,
2729 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2730 +"aufs5.x-rcN" branch.
2733 +$ git clone --reference /your/linux/git/tree \
2734 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2735 +- if you don't have linux GIT tree, then remove "--reference ..."
2736 +$ cd aufs5-linux.git
2737 +$ git checkout origin/aufs5.0
2739 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2740 +leave the patch-work to GIT.
2741 +$ cd /your/linux/git/tree
2742 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2744 +$ git checkout -b my5.0 v5.0
2745 +$ (add your local change...)
2746 +$ git pull aufs5 aufs5.0
2747 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2748 +- you may need to solve some conflicts between your_changes and
2749 + aufs5.0. in this case, git-rerere is recommended so that you can
2750 + solve the similar conflicts automatically when you upgrade to 5.1 or
2751 + later in the future.
2753 +o aufs5-standalone tree
2754 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2755 +$ cd aufs5-standalone.git
2756 +$ git checkout origin/aufs5.0
2759 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2760 +- note that the public aufs-util.git is on SourceForge instead of
2763 +$ git checkout origin/aufs5.0
2765 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2766 +The minor version number, 'x' in '5.x', of aufs may not always
2767 +follow the minor version number of the kernel.
2768 +Because changes in the kernel that cause the use of a new
2769 +minor version number do not always require changes to aufs-util.
2771 +Since aufs-util has its own minor version number, you may not be
2772 +able to find a GIT branch in aufs-util for your kernel's
2773 +exact minor version number.
2774 +In this case, you should git-checkout the branch for the
2775 +nearest lower number.
2777 +For (an unreleased) example:
2778 +If you are using "linux-5.10" and the "aufs5.10" branch
2779 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2780 +or something numerically smaller is the branch for your kernel.
2782 +Also you can view all branches by
2786 +3. Configuration and Compilation
2787 +----------------------------------------
2788 +Make sure you have git-checkout'ed the correct branch.
2790 +For aufs5-linux tree,
2791 +- enable CONFIG_AUFS_FS.
2792 +- set other aufs configurations if necessary.
2794 +For aufs5-standalone tree,
2795 +There are several ways to build.
2798 +- apply ./aufs5-kbuild.patch to your kernel source files.
2799 +- apply ./aufs5-base.patch too.
2800 +- apply ./aufs5-mmap.patch too.
2801 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2802 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2803 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2804 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2805 +- enable CONFIG_AUFS_FS, you can select either
2807 +- and build your kernel as usual.
2808 +- install the built kernel.
2809 +- install the header files too by "make headers_install" to the
2810 + directory where you specify. By default, it is $PWD/usr.
2811 + "make help" shows a brief note for headers_install.
2812 +- and reboot your system.
2815 +- module only (CONFIG_AUFS_FS=m).
2816 +- apply ./aufs5-base.patch to your kernel source files.
2817 +- apply ./aufs5-mmap.patch too.
2818 +- apply ./aufs5-standalone.patch too.
2819 +- build your kernel, don't forget "make headers_install", and reboot.
2820 +- edit ./config.mk and set other aufs configurations if necessary.
2821 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2822 + every aufs configurations.
2823 +- build the module by simple "make".
2824 +- you can specify ${KDIR} make variable which points to your kernel
2826 +- install the files
2827 + + run "make install" to install the aufs module, or copy the built
2828 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2829 + + run "make install_headers" (instead of headers_install) to install
2830 + the modified aufs header file (you can specify DESTDIR which is
2831 + available in aufs standalone version's Makefile only), or copy
2832 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2833 + you like manually. By default, the target directory is $PWD/usr.
2834 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2835 + kernel source tree.
2837 +Note: The header file aufs_type.h is necessary to build aufs-util
2838 + as well as "make headers_install" in the kernel source tree.
2839 + headers_install is subject to be forgotten, but it is essentially
2840 + necessary, not only for building aufs-util.
2841 + You may not meet problems without headers_install in some older
2845 +- read README in aufs-util, build and install it
2846 +- note that your distribution may contain an obsoleted version of
2847 + aufs_type.h in /usr/include/linux or something. When you build aufs
2848 + utilities, make sure that your compiler refers the correct aufs header
2849 + file which is built by "make headers_install."
2850 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2851 + then run "make install_ulib" too. And refer to the aufs manual in
2854 +There several other patches in aufs5-standalone.git. They are all
2855 +optional. When you meet some problems, they will help you.
2856 +- aufs5-loopback.patch
2857 + Supports a nested loopback mount in a branch-fs. This patch is
2858 + unnecessary until aufs produces a message like "you may want to try
2859 + another patch for loopback file".
2860 +- proc_mounts.patch
2861 + When there are many mountpoints and many mount(2)/umount(2) are
2862 + running, then /proc/mounts may not show the all mountpoints. This
2863 + patch makes /proc/mounts always show the full mountpoints list.
2864 + If you don't want to apply this patch and meet such problem, then you
2865 + need to increase the value of 'ProcMounts_Times' make-variable in
2866 + aufs-util.git as a second best solution.
2868 + Modifies a system global kernel internal function get_next_ino() in
2869 + order to stop assigning 0 for an inode-number. Not directly related to
2870 + aufs, but recommended generally.
2872 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2873 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2874 + duplication of inode number, which is important for backup tools and
2875 + other utilities. When you find aufs XINO files for tmpfs branch
2876 + growing too much, try this patch.
2877 +- lockdep-debug.patch
2878 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2879 + also a caller of VFS functions for branch filesystems, subclassing of
2880 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2881 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2882 + need to apply this debug patch to expand several constant values.
2883 + If don't know what LOCKDEP is, then you don't have apply this patch.
2887 +----------------------------------------
2888 +At first, make sure aufs-util are installed, and please read the aufs
2889 +manual, aufs.5 in aufs-util.git tree.
2893 +$ mkdir /tmp/rw /tmp/aufs
2894 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2896 +Here is another example. The result is equivalent.
2897 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2899 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2900 +# mount -o remount,append:${HOME} /tmp/aufs
2902 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2903 +you modify a file under /tmp/aufs, the one on your home directory is
2904 +not affected, instead the same named file will be newly created under
2905 +/tmp/rw. And all of your modification to a file will be applied to
2906 +the one under /tmp/rw. This is called the file based Copy on Write
2908 +Aufs mount options are described in aufs.5.
2909 +If you run chroot or something and make your aufs as a root directory,
2910 +then you need to customize the shutdown script. See the aufs manual in
2913 +Additionally, there are some sample usages of aufs which are a
2914 +diskless system with network booting, and LiveCD over NFS.
2915 +See sample dir in CVS tree on SourceForge.
2919 +----------------------------------------
2920 +When you have any problems or strange behaviour in aufs, please let me
2922 +- /proc/mounts (instead of the output of mount(8))
2923 +- /sys/module/aufs/*
2924 +- /sys/fs/aufs/* (if you have them)
2925 +- /debug/aufs/* (if you have them)
2926 +- linux kernel version
2927 + if your kernel is not plain, for example modified by distributor,
2928 + the url where i can download its source is necessary too.
2929 +- aufs version which was printed at loading the module or booting the
2930 + system, instead of the date you downloaded.
2931 +- configuration (define/undefine CONFIG_AUFS_xxx)
2932 +- kernel configuration or /proc/config.gz (if you have it)
2933 +- behaviour which you think to be incorrect
2934 +- actual operation, reproducible one is better
2935 +- mailto: aufs-users at lists.sourceforge.net
2937 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2938 +and Feature Requests) on SourceForge. Please join and write to
2942 +6. Acknowledgements
2943 +----------------------------------------
2944 +Thanks to everyone who have tried and are using aufs, whoever
2945 +have reported a bug or any feedback.
2947 +Especially donators:
2948 +Tomas Matejicek(slax.org) made a donation (much more than once).
2949 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2950 + scripts) is making "doubling" donations.
2951 + Unfortunately I cannot list all of the donators, but I really
2953 + It ends Aug 2010, but the ordinary donation URL is still available.
2954 + <http://sourceforge.net/donate/index.php?group_id=167503>
2955 +Dai Itasaka made a donation (2007/8).
2956 +Chuck Smith made a donation (2008/4, 10 and 12).
2957 +Henk Schoneveld made a donation (2008/9).
2958 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2959 +Francois Dupoux made a donation (2008/11).
2960 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2961 + aufs2 GIT tree (2009/2).
2962 +William Grant made a donation (2009/3).
2963 +Patrick Lane made a donation (2009/4).
2964 +The Mail Archive (mail-archive.com) made donations (2009/5).
2965 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2966 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2967 +Pavel Pronskiy made a donation (2011/2).
2968 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2969 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2970 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2972 +Sam Liddicott made a donation (2011/9).
2973 +Era Scarecrow made a donation (2013/4).
2974 +Bor Ratajc made a donation (2013/4).
2975 +Alessandro Gorreta made a donation (2013/4).
2976 +POIRETTE Marc made a donation (2013/4).
2977 +Alessandro Gorreta made a donation (2013/4).
2978 +lauri kasvandik made a donation (2013/5).
2979 +"pemasu from Finland" made a donation (2013/7).
2980 +The Parted Magic Project made a donation (2013/9 and 11).
2981 +Pavel Barta made a donation (2013/10).
2982 +Nikolay Pertsev made a donation (2014/5).
2983 +James B made a donation (2014/7 and 2015/7).
2984 +Stefano Di Biase made a donation (2014/8).
2985 +Daniel Epellei made a donation (2015/1).
2986 +OmegaPhil made a donation (2016/1, 2018/4).
2987 +Tomasz Szewczyk made a donation (2016/4).
2988 +James Burry made a donation (2016/12).
2989 +Carsten Rose made a donation (2018/9).
2990 +Porteus Kiosk made a donation (2018/10).
2992 +Thank you very much.
2993 +Donations are always, including future donations, very important and
2994 +helpful for me to keep on developing aufs.
2998 +----------------------------------------
2999 +If you are an experienced user, no explanation is needed. Aufs is
3000 +just a linux filesystem.
3005 +# Local variables: ;
3008 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3009 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 08:00:00.000000000 +0800
3010 +++ linux/fs/aufs/aufs.h 2019-07-11 21:21:54.379051070 +0800
3012 +/* SPDX-License-Identifier: GPL-2.0 */
3014 + * Copyright (C) 2005-2019 Junjiro R. Okajima
3016 + * This program, aufs is free software; you can redistribute it and/or modify
3017 + * it under the terms of the GNU General Public License as published by
3018 + * the Free Software Foundation; either version 2 of the License, or
3019 + * (at your option) any later version.
3021 + * This program is distributed in the hope that it will be useful,
3022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3024 + * GNU General Public License for more details.
3026 + * You should have received a copy of the GNU General Public License
3027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3031 + * all header files
3039 +#define AuStub(type, name, body, ...) \
3040 + static inline type name(__VA_ARGS__) { body; }
3042 +#define AuStubVoid(name, ...) \
3043 + AuStub(void, name, , __VA_ARGS__)
3044 +#define AuStubInt0(name, ...) \
3045 + AuStub(int, name, return 0, __VA_ARGS__)
3049 +#include "branch.h"
3052 +#include "dbgaufs.h"
3053 +#include "dentry.h"
3055 +#include "dirren.h"
3058 +#include "fstype.h"
3063 +#include "module.h"
3067 +#include "sysaufs.h"
3072 +#endif /* __KERNEL__ */
3073 +#endif /* __AUFS_H__ */
3074 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3075 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 08:00:00.000000000 +0800
3076 +++ linux/fs/aufs/branch.c 2019-07-11 21:21:54.379051070 +0800
3078 +// SPDX-License-Identifier: GPL-2.0
3080 + * Copyright (C) 2005-2019 Junjiro R. Okajima
3082 + * This program, aufs is free software; you can redistribute it and/or modify
3083 + * it under the terms of the GNU General Public License as published by
3084 + * the Free Software Foundation; either version 2 of the License, or
3085 + * (at your option) any later version.
3087 + * This program is distributed in the hope that it will be useful,
3088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3090 + * GNU General Public License for more details.
3092 + * You should have received a copy of the GNU General Public License
3093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3097 + * branch management
3100 +#include <linux/compat.h>
3101 +#include <linux/statfs.h>
3105 + * free a single branch
3107 +static void au_br_do_free(struct au_branch *br)
3110 + struct au_wbr *wbr;
3111 + struct au_dykey **key;
3113 + au_hnotify_fin_br(br);
3114 + /* always, regardless the mount option */
3115 + au_dr_hino_free(&br->br_dirren);
3118 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3119 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3120 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3121 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3125 + for (i = 0; i < AuBrWh_Last; i++)
3126 + dput(wbr->wbr_wh[i]);
3127 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3128 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3131 + if (br->br_fhsm) {
3132 + au_br_fhsm_fin(br->br_fhsm);
3133 + au_kfree_try_rcu(br->br_fhsm);
3136 + key = br->br_dykey;
3137 + for (i = 0; i < AuBrDynOp; i++, key++)
3143 + /* recursive lock, s_umount of branch's */
3144 + /* synchronize_rcu(); */ /* why? */
3146 + path_put(&br->br_path);
3148 + au_kfree_rcu(wbr);
3149 + au_lcnt_wait_for_fin(&br->br_nfiles);
3150 + au_lcnt_wait_for_fin(&br->br_count);
3151 + /* I don't know why, but percpu_refcount requires this */
3152 + /* synchronize_rcu(); */
3157 + * frees all branches
3159 +void au_br_free(struct au_sbinfo *sbinfo)
3161 + aufs_bindex_t bmax;
3162 + struct au_branch **br;
3164 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3166 + bmax = sbinfo->si_bbot + 1;
3167 + br = sbinfo->si_branch;
3169 + au_br_do_free(*br++);
3173 + * find the index of a branch which is specified by @br_id.
3175 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3177 + aufs_bindex_t bindex, bbot;
3179 + bbot = au_sbbot(sb);
3180 + for (bindex = 0; bindex <= bbot; bindex++)
3181 + if (au_sbr_id(sb, bindex) == br_id)
3186 +/* ---------------------------------------------------------------------- */
3192 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3193 + struct dentry *h_root)
3195 + if (unlikely(h_adding == h_root
3196 + || au_test_loopback_overlap(sb, h_adding)))
3198 + if (h_adding->d_sb != h_root->d_sb)
3200 + return au_test_subdir(h_adding, h_root)
3201 + || au_test_subdir(h_root, h_adding);
3205 + * returns a newly allocated branch. @new_nbranch is a number of branches
3206 + * after adding a branch.
3208 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3211 + struct au_branch *add_branch;
3212 + struct dentry *root;
3213 + struct inode *inode;
3217 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3218 + if (unlikely(!add_branch))
3220 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3221 + if (unlikely(!add_branch->br_xino))
3223 + err = au_hnotify_init_br(add_branch, perm);
3224 + if (unlikely(err))
3227 + if (au_br_writable(perm)) {
3228 + /* may be freed separately at changing the branch permission */
3229 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3231 + if (unlikely(!add_branch->br_wbr))
3235 + if (au_br_fhsm(perm)) {
3236 + err = au_fhsm_br_alloc(add_branch);
3237 + if (unlikely(err))
3241 + root = sb->s_root;
3242 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3244 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3246 + inode = d_inode(root);
3247 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3251 + return add_branch; /* success */
3254 + au_kfree_rcu(add_branch->br_wbr);
3256 + au_hnotify_fin_br(add_branch);
3258 + au_xino_put(add_branch);
3260 + au_kfree_rcu(add_branch);
3262 + return ERR_PTR(err);
3266 + * test if the branch permission is legal or not.
3268 +static int test_br(struct inode *inode, int brperm, char *path)
3272 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3277 + pr_err("write permission for readonly mount or inode, %s\n", path);
3285 + * 0: success, the caller will add it
3286 + * plus: success, it is already unified, the caller should ignore it
3289 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3292 + aufs_bindex_t bbot, bindex;
3293 + struct dentry *root, *h_dentry;
3294 + struct inode *inode, *h_inode;
3296 + root = sb->s_root;
3297 + bbot = au_sbbot(sb);
3298 + if (unlikely(bbot >= 0
3299 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3303 + pr_err("%s duplicated\n", add->pathname);
3308 + err = -ENOSPC; /* -E2BIG; */
3309 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3310 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3311 + pr_err("number of branches exceeded %s\n", add->pathname);
3316 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3317 + pr_err("bad index %d\n", add->bindex);
3321 + inode = d_inode(add->path.dentry);
3323 + if (unlikely(!inode->i_nlink)) {
3324 + pr_err("no existence %s\n", add->pathname);
3329 + if (unlikely(inode->i_sb == sb)) {
3330 + pr_err("%s must be outside\n", add->pathname);
3334 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3335 + pr_err("unsupported filesystem, %s (%s)\n",
3336 + add->pathname, au_sbtype(inode->i_sb));
3340 + if (unlikely(inode->i_sb->s_stack_depth)) {
3341 + pr_err("already stacked, %s (%s)\n",
3342 + add->pathname, au_sbtype(inode->i_sb));
3346 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3347 + if (unlikely(err))
3351 + return 0; /* success */
3354 + for (bindex = 0; bindex <= bbot; bindex++)
3355 + if (unlikely(test_overlap(sb, add->path.dentry,
3356 + au_h_dptr(root, bindex)))) {
3357 + pr_err("%s is overlapped\n", add->pathname);
3362 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3363 + h_dentry = au_h_dptr(root, 0);
3364 + h_inode = d_inode(h_dentry);
3365 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3366 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3367 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3368 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3370 + i_uid_read(inode), i_gid_read(inode),
3371 + (inode->i_mode & S_IALLUGO),
3372 + i_uid_read(h_inode), i_gid_read(h_inode),
3373 + (h_inode->i_mode & S_IALLUGO));
3381 + * initialize or clean the whiteouts for an adding branch
3383 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3386 + int err, old_perm;
3387 + aufs_bindex_t bindex;
3388 + struct inode *h_inode;
3389 + struct au_wbr *wbr;
3390 + struct au_hinode *hdir;
3391 + struct dentry *h_dentry;
3393 + err = vfsub_mnt_want_write(au_br_mnt(br));
3394 + if (unlikely(err))
3398 + old_perm = br->br_perm;
3399 + br->br_perm = new_perm;
3402 + bindex = au_br_index(sb, br->br_id);
3403 + if (0 <= bindex) {
3404 + hdir = au_hi(d_inode(sb->s_root), bindex);
3405 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3407 + h_dentry = au_br_dentry(br);
3408 + h_inode = d_inode(h_dentry);
3409 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3412 + err = au_wh_init(br, sb);
3414 + wbr_wh_write_lock(wbr);
3415 + err = au_wh_init(br, sb);
3416 + wbr_wh_write_unlock(wbr);
3419 + au_hn_inode_unlock(hdir);
3421 + inode_unlock(h_inode);
3422 + vfsub_mnt_drop_write(au_br_mnt(br));
3423 + br->br_perm = old_perm;
3425 + if (!err && wbr && !au_br_writable(new_perm)) {
3426 + au_kfree_rcu(wbr);
3427 + br->br_wbr = NULL;
3434 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3438 + struct kstatfs kst;
3439 + struct au_wbr *wbr;
3442 + au_rw_init(&wbr->wbr_wh_rwsem);
3443 + atomic_set(&wbr->wbr_wh_running, 0);
3446 + * a limit for rmdir/rename a dir
3447 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3449 + err = vfs_statfs(&br->br_path, &kst);
3450 + if (unlikely(err))
3453 + if (kst.f_namelen >= NAME_MAX)
3454 + err = au_br_init_wh(sb, br, perm);
3456 + pr_err("%pd(%s), unsupported namelen %ld\n",
3458 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3464 +/* initialize a new branch */
3465 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3466 + struct au_opt_add *add)
3469 + struct au_branch *brbase;
3471 + struct inode *h_inode;
3474 + br->br_perm = add->perm;
3475 + br->br_path = add->path; /* set first, path_get() later */
3476 + spin_lock_init(&br->br_dykey_lock);
3477 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3478 + au_lcnt_init(&br->br_count, /*release*/NULL);
3479 + br->br_id = au_new_br_id(sb);
3480 + AuDebugOn(br->br_id < 0);
3482 + /* always, regardless the given option */
3483 + err = au_dr_br_init(sb, br, &add->path);
3484 + if (unlikely(err))
3487 + if (au_br_writable(add->perm)) {
3488 + err = au_wbr_init(br, sb, add->perm);
3489 + if (unlikely(err))
3493 + if (au_opt_test(au_mntflags(sb), XINO)) {
3494 + brbase = au_sbr(sb, 0);
3495 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3497 + h_inode = d_inode(add->path.dentry);
3498 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3499 + if (unlikely(err)) {
3500 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3505 + sysaufs_br_init(br);
3506 + path_get(&br->br_path);
3507 + goto out; /* success */
3510 + memset(&br->br_path, 0, sizeof(br->br_path));
3515 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3516 + struct au_branch *br, aufs_bindex_t bbot,
3517 + aufs_bindex_t amount)
3519 + struct au_branch **brp;
3521 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3523 + brp = sbinfo->si_branch + bindex;
3524 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3526 + sbinfo->si_bbot++;
3527 + if (unlikely(bbot < 0))
3528 + sbinfo->si_bbot = 0;
3531 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3532 + aufs_bindex_t bbot, aufs_bindex_t amount)
3534 + struct au_hdentry *hdp;
3536 + AuRwMustWriteLock(&dinfo->di_rwsem);
3538 + hdp = au_hdentry(dinfo, bindex);
3539 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3540 + au_h_dentry_init(hdp);
3542 + if (unlikely(bbot < 0))
3543 + dinfo->di_btop = 0;
3546 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3547 + aufs_bindex_t bbot, aufs_bindex_t amount)
3549 + struct au_hinode *hip;
3551 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3553 + hip = au_hinode(iinfo, bindex);
3554 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3555 + au_hinode_init(hip);
3557 + if (unlikely(bbot < 0))
3558 + iinfo->ii_btop = 0;
3561 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3562 + aufs_bindex_t bindex)
3564 + struct dentry *root, *h_dentry;
3565 + struct inode *root_inode, *h_inode;
3566 + aufs_bindex_t bbot, amount;
3568 + root = sb->s_root;
3569 + root_inode = d_inode(root);
3570 + bbot = au_sbbot(sb);
3571 + amount = bbot + 1 - bindex;
3572 + h_dentry = au_br_dentry(br);
3573 + au_sbilist_lock();
3574 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3575 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3576 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3577 + au_set_h_dptr(root, bindex, dget(h_dentry));
3578 + h_inode = d_inode(h_dentry);
3579 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3580 + au_sbilist_unlock();
3583 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3586 + aufs_bindex_t bbot, add_bindex;
3587 + struct dentry *root, *h_dentry;
3588 + struct inode *root_inode;
3589 + struct au_branch *add_branch;
3591 + root = sb->s_root;
3592 + root_inode = d_inode(root);
3593 + IMustLock(root_inode);
3594 + IiMustWriteLock(root_inode);
3595 + err = test_add(sb, add, remount);
3596 + if (unlikely(err < 0))
3600 + goto out; /* success */
3603 + bbot = au_sbbot(sb);
3604 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3605 + err = PTR_ERR(add_branch);
3606 + if (IS_ERR(add_branch))
3609 + err = au_br_init(add_branch, sb, add);
3610 + if (unlikely(err)) {
3611 + au_br_do_free(add_branch);
3615 + add_bindex = add->bindex;
3616 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3617 + au_br_do_add(sb, add_branch, add_bindex);
3618 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3619 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3621 + h_dentry = add->path.dentry;
3622 + if (!add_bindex) {
3623 + au_cpup_attr_all(root_inode, /*force*/1);
3624 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3626 + au_add_nlink(root_inode, d_inode(h_dentry));
3632 +/* ---------------------------------------------------------------------- */
3634 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3635 + unsigned long long max __maybe_unused,
3638 + unsigned long long n;
3639 + struct file **p, *f;
3640 + struct hlist_bl_head *files;
3641 + struct hlist_bl_node *pos;
3642 + struct au_finfo *finfo;
3646 + files = &au_sbi(sb)->si_files;
3647 + hlist_bl_lock(files);
3648 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3649 + f = finfo->fi_file;
3651 + && !special_file(file_inode(f)->i_mode)) {
3655 + AuDebugOn(n > max);
3658 + hlist_bl_unlock(files);
3663 +static struct file **au_farray_alloc(struct super_block *sb,
3664 + unsigned long long *max)
3666 + struct au_sbinfo *sbi;
3669 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3670 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3673 +static void au_farray_free(struct file **a, unsigned long long max)
3675 + unsigned long long ull;
3677 + for (ull = 0; ull < max; ull++)
3683 +/* ---------------------------------------------------------------------- */
3689 +/* to show the line number, do not make it inlined function */
3690 +#define AuVerbose(do_info, fmt, ...) do { \
3692 + pr_info(fmt, ##__VA_ARGS__); \
3695 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3696 + aufs_bindex_t bbot)
3698 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3701 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3702 + aufs_bindex_t bbot)
3704 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3708 + * test if the branch is deletable or not.
3710 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3711 + unsigned int sigen, const unsigned int verbose)
3713 + int err, i, j, ndentry;
3714 + aufs_bindex_t btop, bbot;
3715 + struct au_dcsub_pages dpages;
3716 + struct au_dpage *dpage;
3719 + err = au_dpages_init(&dpages, GFP_NOFS);
3720 + if (unlikely(err))
3722 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3723 + if (unlikely(err))
3726 + for (i = 0; !err && i < dpages.ndpage; i++) {
3727 + dpage = dpages.dpages + i;
3728 + ndentry = dpage->ndentry;
3729 + for (j = 0; !err && j < ndentry; j++) {
3730 + d = dpage->dentries[j];
3731 + AuDebugOn(au_dcount(d) <= 0);
3732 + if (!au_digen_test(d, sigen)) {
3733 + di_read_lock_child(d, AuLock_IR);
3734 + if (unlikely(au_dbrange_test(d))) {
3735 + di_read_unlock(d, AuLock_IR);
3739 + di_write_lock_child(d);
3740 + if (unlikely(au_dbrange_test(d))) {
3741 + di_write_unlock(d);
3744 + err = au_reval_dpath(d, sigen);
3746 + di_downgrade_lock(d, AuLock_IR);
3748 + di_write_unlock(d);
3753 + /* AuDbgDentry(d); */
3754 + btop = au_dbtop(d);
3755 + bbot = au_dbbot(d);
3756 + if (btop <= bindex
3758 + && au_h_dptr(d, bindex)
3759 + && au_test_dbusy(d, btop, bbot)) {
3761 + AuVerbose(verbose, "busy %pd\n", d);
3764 + di_read_unlock(d, AuLock_IR);
3769 + au_dpages_free(&dpages);
3774 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3775 + unsigned int sigen, const unsigned int verbose)
3778 + unsigned long long max, ull;
3779 + struct inode *i, **array;
3780 + aufs_bindex_t btop, bbot;
3782 + array = au_iarray_alloc(sb, &max);
3783 + err = PTR_ERR(array);
3784 + if (IS_ERR(array))
3788 + AuDbg("b%d\n", bindex);
3789 + for (ull = 0; !err && ull < max; ull++) {
3793 + if (i->i_ino == AUFS_ROOT_INO)
3796 + /* AuDbgInode(i); */
3797 + if (au_iigen(i, NULL) == sigen)
3798 + ii_read_lock_child(i);
3800 + ii_write_lock_child(i);
3801 + err = au_refresh_hinode_self(i);
3804 + ii_downgrade_lock(i);
3806 + ii_write_unlock(i);
3811 + btop = au_ibtop(i);
3812 + bbot = au_ibbot(i);
3813 + if (btop <= bindex
3815 + && au_h_iptr(i, bindex)
3816 + && au_test_ibusy(i, btop, bbot)) {
3818 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3821 + ii_read_unlock(i);
3823 + au_iarray_free(array, max);
3829 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3830 + const unsigned int verbose)
3833 + unsigned int sigen;
3835 + sigen = au_sigen(root->d_sb);
3836 + DiMustNoWaiters(root);
3837 + IiMustNoWaiters(d_inode(root));
3838 + di_write_unlock(root);
3839 + err = test_dentry_busy(root, bindex, sigen, verbose);
3841 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3842 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3847 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3848 + struct file **to_free, int *idx)
3851 + unsigned char matched, root;
3852 + aufs_bindex_t bindex, bbot;
3853 + struct au_fidir *fidir;
3854 + struct au_hfile *hfile;
3857 + root = IS_ROOT(file->f_path.dentry);
3860 + to_free[*idx] = file;
3866 + fidir = au_fi(file)->fi_hdir;
3867 + AuDebugOn(!fidir);
3868 + bbot = au_fbbot_dir(file);
3869 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3870 + hfile = fidir->fd_hfile + bindex;
3871 + if (!hfile->hf_file)
3874 + if (hfile->hf_br->br_id == br_id) {
3886 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3887 + struct file **to_free, int opened)
3890 + unsigned long long ull, max;
3891 + aufs_bindex_t btop;
3892 + struct file *file, **array;
3893 + struct dentry *root;
3894 + struct au_hfile *hfile;
3896 + array = au_farray_alloc(sb, &max);
3897 + err = PTR_ERR(array);
3898 + if (IS_ERR(array))
3903 + root = sb->s_root;
3904 + di_write_unlock(root);
3905 + for (ull = 0; ull < max; ull++) {
3906 + file = array[ull];
3907 + if (unlikely(!file))
3910 + /* AuDbg("%pD\n", file); */
3911 + fi_read_lock(file);
3912 + btop = au_fbtop(file);
3913 + if (!d_is_dir(file->f_path.dentry)) {
3914 + hfile = &au_fi(file)->fi_htop;
3915 + if (hfile->hf_br->br_id == br_id)
3918 + err = test_dir_busy(file, br_id, to_free, &idx);
3919 + fi_read_unlock(file);
3920 + if (unlikely(err))
3923 + di_write_lock_child(root);
3924 + au_farray_free(array, max);
3925 + AuDebugOn(idx > opened);
3931 +static void br_del_file(struct file **to_free, unsigned long long opened,
3932 + aufs_bindex_t br_id)
3934 + unsigned long long ull;
3935 + aufs_bindex_t bindex, btop, bbot, bfound;
3936 + struct file *file;
3937 + struct au_fidir *fidir;
3938 + struct au_hfile *hfile;
3940 + for (ull = 0; ull < opened; ull++) {
3941 + file = to_free[ull];
3942 + if (unlikely(!file))
3945 + /* AuDbg("%pD\n", file); */
3946 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3948 + fidir = au_fi(file)->fi_hdir;
3949 + AuDebugOn(!fidir);
3950 + fi_write_lock(file);
3951 + btop = au_fbtop(file);
3952 + bbot = au_fbbot_dir(file);
3953 + for (bindex = btop; bindex <= bbot; bindex++) {
3954 + hfile = fidir->fd_hfile + bindex;
3955 + if (!hfile->hf_file)
3958 + if (hfile->hf_br->br_id == br_id) {
3963 + AuDebugOn(bfound < 0);
3964 + au_set_h_fptr(file, bfound, NULL);
3965 + if (bfound == btop) {
3966 + for (btop++; btop <= bbot; btop++)
3967 + if (au_hf_dir(file, btop)) {
3968 + au_set_fbtop(file, btop);
3972 + fi_write_unlock(file);
3976 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3977 + const aufs_bindex_t bindex,
3978 + const aufs_bindex_t bbot)
3980 + struct au_branch **brp, **p;
3982 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3984 + brp = sbinfo->si_branch + bindex;
3985 + if (bindex < bbot)
3986 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3987 + sbinfo->si_branch[0 + bbot] = NULL;
3988 + sbinfo->si_bbot--;
3990 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3993 + sbinfo->si_branch = p;
3994 + /* harmless error */
3997 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3998 + const aufs_bindex_t bbot)
4000 + struct au_hdentry *hdp, *p;
4002 + AuRwMustWriteLock(&dinfo->di_rwsem);
4004 + hdp = au_hdentry(dinfo, bindex);
4005 + if (bindex < bbot)
4006 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4007 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4010 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4013 + dinfo->di_hdentry = p;
4014 + /* harmless error */
4017 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4018 + const aufs_bindex_t bbot)
4020 + struct au_hinode *hip, *p;
4022 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4024 + hip = au_hinode(iinfo, bindex);
4025 + if (bindex < bbot)
4026 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4027 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4030 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4033 + iinfo->ii_hinode = p;
4034 + /* harmless error */
4037 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4038 + struct au_branch *br)
4040 + aufs_bindex_t bbot;
4041 + struct au_sbinfo *sbinfo;
4042 + struct dentry *root, *h_root;
4043 + struct inode *inode, *h_inode;
4044 + struct au_hinode *hinode;
4046 + SiMustWriteLock(sb);
4048 + root = sb->s_root;
4049 + inode = d_inode(root);
4050 + sbinfo = au_sbi(sb);
4051 + bbot = sbinfo->si_bbot;
4053 + h_root = au_h_dptr(root, bindex);
4054 + hinode = au_hi(inode, bindex);
4055 + h_inode = au_igrab(hinode->hi_inode);
4058 + au_sbilist_lock();
4059 + au_br_do_del_brp(sbinfo, bindex, bbot);
4060 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4061 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4062 + au_sbilist_unlock();
4064 + /* ignore an error */
4065 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4069 + au_br_do_free(br);
4072 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4073 + unsigned long long max, void *arg)
4078 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4081 + unsigned long long opened;
4082 + unsigned int mnt_flags;
4083 + aufs_bindex_t bindex, bbot, br_id;
4084 + unsigned char do_wh, verbose;
4085 + struct au_branch *br;
4086 + struct au_wbr *wbr;
4087 + struct dentry *root;
4088 + struct file **to_free;
4093 + root = sb->s_root;
4094 + bindex = au_find_dbindex(root, del->h_path.dentry);
4097 + goto out; /* success */
4099 + pr_err("%s no such branch\n", del->pathname);
4102 + AuDbg("bindex b%d\n", bindex);
4105 + mnt_flags = au_mntflags(sb);
4106 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4107 + bbot = au_sbbot(sb);
4108 + if (unlikely(!bbot)) {
4109 + AuVerbose(verbose, "no more branches left\n");
4113 + br = au_sbr(sb, bindex);
4114 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4115 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4116 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4120 + br_id = br->br_id;
4121 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4122 + if (unlikely(opened)) {
4123 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4124 + err = PTR_ERR(to_free);
4125 + if (IS_ERR(to_free))
4128 + err = test_file_busy(sb, br_id, to_free, opened);
4129 + if (unlikely(err)) {
4130 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4136 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4138 + /* instead of WbrWhMustWriteLock(wbr) */
4139 + SiMustWriteLock(sb);
4140 + for (i = 0; i < AuBrWh_Last; i++) {
4141 + dput(wbr->wbr_wh[i]);
4142 + wbr->wbr_wh[i] = NULL;
4146 + err = test_children_busy(root, bindex, verbose);
4147 + if (unlikely(err)) {
4156 + * now we confirmed the branch is deletable.
4157 + * let's free the remaining opened dirs on the branch.
4159 + di_write_unlock(root);
4160 + br_del_file(to_free, opened, br_id);
4161 + di_write_lock_child(root);
4164 + sysaufs_brs_del(sb, bindex); /* remove successors */
4165 + dbgaufs_xino_del(br); /* remove one */
4166 + au_br_do_del(sb, bindex, br);
4167 + sysaufs_brs_add(sb, bindex); /* append successors */
4168 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4171 + au_cpup_attr_all(d_inode(root), /*force*/1);
4172 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4174 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4175 + if (au_opt_test(mnt_flags, PLINK))
4176 + au_plink_half_refresh(sb, br_id);
4178 + goto out; /* success */
4182 + rerr = au_br_init_wh(sb, br, br->br_perm);
4184 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4185 + del->pathname, rerr);
4188 + au_farray_free(to_free, opened);
4192 +/* ---------------------------------------------------------------------- */
4194 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4197 + aufs_bindex_t btop, bbot;
4198 + struct aufs_ibusy ibusy;
4199 + struct inode *inode, *h_inode;
4202 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4205 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4207 + /* VERIFY_WRITE */
4208 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4209 + if (unlikely(err)) {
4216 + si_read_lock(sb, AuLock_FLUSH);
4217 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4221 + ibusy.h_ino = 0; /* invalid */
4222 + inode = ilookup(sb, ibusy.ino);
4224 + || inode->i_ino == AUFS_ROOT_INO
4225 + || au_is_bad_inode(inode))
4228 + ii_read_lock_child(inode);
4229 + btop = au_ibtop(inode);
4230 + bbot = au_ibbot(inode);
4231 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4232 + h_inode = au_h_iptr(inode, ibusy.bindex);
4233 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4234 + ibusy.h_ino = h_inode->i_ino;
4236 + ii_read_unlock(inode);
4240 + si_read_unlock(sb);
4242 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4243 + if (unlikely(err)) {
4252 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4254 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4257 +#ifdef CONFIG_COMPAT
4258 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4260 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4264 +/* ---------------------------------------------------------------------- */
4267 + * change a branch permission
4270 +static void au_warn_ima(void)
4273 + /* since it doesn't support mark_files_ro() */
4274 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4278 +static int do_need_sigen_inc(int a, int b)
4280 + return au_br_whable(a) && !au_br_whable(b);
4283 +static int need_sigen_inc(int old, int new)
4285 + return do_need_sigen_inc(old, new)
4286 + || do_need_sigen_inc(new, old);
4289 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4292 + unsigned int mnt_flags;
4293 + unsigned long long ull, max;
4294 + aufs_bindex_t br_id;
4295 + unsigned char verbose, writer;
4296 + struct file *file, *hf, **array;
4297 + struct au_hfile *hfile;
4299 + mnt_flags = au_mntflags(sb);
4300 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4302 + array = au_farray_alloc(sb, &max);
4303 + err = PTR_ERR(array);
4304 + if (IS_ERR(array))
4308 + br_id = au_sbr_id(sb, bindex);
4309 + for (ull = 0; ull < max; ull++) {
4310 + file = array[ull];
4311 + if (unlikely(!file))
4314 + /* AuDbg("%pD\n", file); */
4315 + fi_read_lock(file);
4316 + if (unlikely(au_test_mmapped(file))) {
4318 + AuVerbose(verbose, "mmapped %pD\n", file);
4320 + FiMustNoWaiters(file);
4321 + fi_read_unlock(file);
4325 + hfile = &au_fi(file)->fi_htop;
4326 + hf = hfile->hf_file;
4327 + if (!d_is_reg(file->f_path.dentry)
4328 + || !(file->f_mode & FMODE_WRITE)
4329 + || hfile->hf_br->br_id != br_id
4330 + || !(hf->f_mode & FMODE_WRITE))
4331 + array[ull] = NULL;
4337 + FiMustNoWaiters(file);
4338 + fi_read_unlock(file);
4346 + for (ull = 0; ull < max; ull++) {
4347 + file = array[ull];
4351 + /* todo: already flushed? */
4353 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4354 + * approach which resets f_mode and calls mnt_drop_write() and
4355 + * file_release_write() for each file, because the branch
4356 + * attribute in aufs world is totally different from the native
4359 + /* fi_read_lock(file); */
4360 + hfile = &au_fi(file)->fi_htop;
4361 + hf = hfile->hf_file;
4362 + /* fi_read_unlock(file); */
4363 + spin_lock(&hf->f_lock);
4364 + writer = !!(hf->f_mode & FMODE_WRITER);
4365 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4366 + spin_unlock(&hf->f_lock);
4368 + put_write_access(file_inode(hf));
4369 + __mnt_drop_write(hf->f_path.mnt);
4374 + au_farray_free(array, max);
4380 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4384 + aufs_bindex_t bindex;
4385 + struct dentry *root;
4386 + struct au_branch *br;
4387 + struct au_br_fhsm *bf;
4389 + root = sb->s_root;
4390 + bindex = au_find_dbindex(root, mod->h_root);
4393 + return 0; /* success */
4395 + pr_err("%s no such branch\n", mod->path);
4398 + AuDbg("bindex b%d\n", bindex);
4400 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4401 + if (unlikely(err))
4404 + br = au_sbr(sb, bindex);
4405 + AuDebugOn(mod->h_root != au_br_dentry(br));
4406 + if (br->br_perm == mod->perm)
4407 + return 0; /* success */
4409 + /* pre-allocate for non-fhsm --> fhsm */
4411 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4412 + err = au_fhsm_br_alloc(br);
4413 + if (unlikely(err))
4416 + br->br_fhsm = NULL;
4419 + if (au_br_writable(br->br_perm)) {
4420 + /* remove whiteout base */
4421 + err = au_br_init_wh(sb, br, mod->perm);
4422 + if (unlikely(err))
4425 + if (!au_br_writable(mod->perm)) {
4426 + /* rw --> ro, file might be mmapped */
4427 + DiMustNoWaiters(root);
4428 + IiMustNoWaiters(d_inode(root));
4429 + di_write_unlock(root);
4430 + err = au_br_mod_files_ro(sb, bindex);
4431 + /* aufs_write_lock() calls ..._child() */
4432 + di_write_lock_child(root);
4434 + if (unlikely(err)) {
4436 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4439 + rerr = au_wbr_init(br, sb, br->br_perm);
4440 + if (unlikely(rerr)) {
4441 + AuIOErr("nested error %d (%d)\n",
4443 + br->br_perm = mod->perm;
4447 + } else if (au_br_writable(mod->perm)) {
4450 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4452 + err = au_wbr_init(br, sb, mod->perm);
4453 + if (unlikely(err)) {
4454 + au_kfree_rcu(br->br_wbr);
4455 + br->br_wbr = NULL;
4459 + if (unlikely(err))
4462 + if (au_br_fhsm(br->br_perm)) {
4463 + if (!au_br_fhsm(mod->perm)) {
4464 + /* fhsm --> non-fhsm */
4465 + au_br_fhsm_fin(br->br_fhsm);
4466 + au_kfree_rcu(br->br_fhsm);
4467 + br->br_fhsm = NULL;
4469 + } else if (au_br_fhsm(mod->perm))
4470 + /* non-fhsm --> fhsm */
4473 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4474 + br->br_perm = mod->perm;
4475 + goto out; /* success */
4478 + au_kfree_try_rcu(bf);
4484 +/* ---------------------------------------------------------------------- */
4486 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4489 + struct kstatfs kstfs;
4491 + err = vfs_statfs(&br->br_path, &kstfs);
4493 + stfs->f_blocks = kstfs.f_blocks;
4494 + stfs->f_bavail = kstfs.f_bavail;
4495 + stfs->f_files = kstfs.f_files;
4496 + stfs->f_ffree = kstfs.f_ffree;
4501 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4502 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 08:00:00.000000000 +0800
4503 +++ linux/fs/aufs/branch.h 2019-07-11 21:21:54.379051070 +0800
4505 +/* SPDX-License-Identifier: GPL-2.0 */
4507 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4509 + * This program, aufs is free software; you can redistribute it and/or modify
4510 + * it under the terms of the GNU General Public License as published by
4511 + * the Free Software Foundation; either version 2 of the License, or
4512 + * (at your option) any later version.
4514 + * This program is distributed in the hope that it will be useful,
4515 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4516 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4517 + * GNU General Public License for more details.
4519 + * You should have received a copy of the GNU General Public License
4520 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4524 + * branch filesystems and xino for them
4527 +#ifndef __AUFS_BRANCH_H__
4528 +#define __AUFS_BRANCH_H__
4532 +#include <linux/mount.h>
4533 +#include "dirren.h"
4539 +/* ---------------------------------------------------------------------- */
4543 + struct file **xi_file;
4544 + unsigned int xi_nfile;
4550 + /* reserved for future use */
4551 + /* unsigned long *bitmap; */
4552 + wait_queue_head_t wqh;
4555 + struct mutex xi_mtx; /* protects xi_file array */
4556 + struct hlist_bl_head xi_writing;
4558 + atomic_t xi_truncating;
4560 + struct kref xi_kref;
4563 +/* File-based Hierarchical Storage Management */
4564 +struct au_br_fhsm {
4565 +#ifdef CONFIG_AUFS_FHSM
4566 + struct mutex bf_lock;
4567 + unsigned long bf_jiffy;
4568 + struct aufs_stfs bf_stfs;
4573 +/* members for writable branch only */
4574 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4576 + struct au_rwsem wbr_wh_rwsem;
4577 + struct dentry *wbr_wh[AuBrWh_Last];
4578 + atomic_t wbr_wh_running;
4579 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4580 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4581 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4584 + unsigned long long wbr_bytes;
4587 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4588 +#define AuBrDynOp (AuDyLast * 4)
4590 +#ifdef CONFIG_AUFS_HFSNOTIFY
4591 +/* support for asynchronous destruction */
4592 +struct au_br_hfsnotify {
4593 + struct fsnotify_group *hfsn_group;
4597 +/* sysfs entries */
4598 +struct au_brsysfs {
4600 + struct attribute attr;
4609 +/* protected by superblock rwsem */
4611 + struct au_xino *br_xino;
4613 + aufs_bindex_t br_id;
4616 + struct path br_path;
4617 + spinlock_t br_dykey_lock;
4618 + struct au_dykey *br_dykey[AuBrDynOp];
4619 + au_lcnt_t br_nfiles; /* opened files */
4620 + au_lcnt_t br_count; /* in-use for other */
4622 + struct au_wbr *br_wbr;
4623 + struct au_br_fhsm *br_fhsm;
4625 +#ifdef CONFIG_AUFS_HFSNOTIFY
4626 + struct au_br_hfsnotify *br_hfsn;
4629 +#ifdef CONFIG_SYSFS
4630 + /* entries under sysfs per mount-point */
4631 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4634 +#ifdef CONFIG_DEBUG_FS
4635 + struct dentry *br_dbgaufs; /* xino */
4638 + struct au_dr_br br_dirren;
4641 +/* ---------------------------------------------------------------------- */
4643 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4645 + return br->br_path.mnt;
4648 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4650 + return br->br_path.dentry;
4653 +static inline struct super_block *au_br_sb(struct au_branch *br)
4655 + return au_br_mnt(br)->mnt_sb;
4658 +static inline int au_br_rdonly(struct au_branch *br)
4660 + return (sb_rdonly(au_br_sb(br))
4661 + || !au_br_writable(br->br_perm))
4665 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4667 +#ifdef CONFIG_AUFS_HNOTIFY
4668 + return !(brperm & AuBrPerm_RR);
4674 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4676 + int err, exec_flag;
4679 + exec_flag = oflag & __FMODE_EXEC;
4680 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4686 +static inline void au_xino_get(struct au_branch *br)
4688 + struct au_xino *xi;
4692 + kref_get(&xi->xi_kref);
4695 +static inline int au_xino_count(struct au_branch *br)
4698 + struct au_xino *xi;
4703 + v = kref_read(&xi->xi_kref);
4708 +/* ---------------------------------------------------------------------- */
4712 +void au_br_free(struct au_sbinfo *sinfo);
4713 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4715 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4717 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4718 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4719 +#ifdef CONFIG_COMPAT
4720 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4723 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4726 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4729 +static const loff_t au_loff_max = LLONG_MAX;
4731 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4732 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4734 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4735 + struct file *copy_src);
4737 + struct au_xino *xi; /* switch between xino and xigen */
4739 + struct path *base;
4740 + struct file *copy_src;
4742 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4744 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4746 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4748 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4750 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4751 + size_t size, loff_t *pos);
4753 +int au_xib_trunc(struct super_block *sb);
4754 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4756 +struct au_xino *au_xino_alloc(unsigned int nfile);
4757 +int au_xino_put(struct au_branch *br);
4758 +struct file *au_xino_file1(struct au_xino *xi);
4760 +struct au_opt_xino;
4761 +void au_xino_clr(struct super_block *sb);
4762 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4763 +struct file *au_xino_def(struct super_block *sb);
4764 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4765 + struct path *base);
4767 +ino_t au_xino_new_ino(struct super_block *sb);
4768 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4770 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4771 + ino_t h_ino, int idx);
4772 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4775 +int au_xino_path(struct seq_file *seq, struct file *file);
4777 +/* ---------------------------------------------------------------------- */
4779 +/* @idx is signed to accept -1 meaning the first file */
4780 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4782 + struct file *file;
4789 + if (idx < xi->xi_nfile)
4790 + file = xi->xi_file[idx];
4792 + file = au_xino_file1(xi);
4798 +/* ---------------------------------------------------------------------- */
4800 +/* Superblock to branch */
4802 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4804 + return au_sbr(sb, bindex)->br_id;
4808 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4810 + return au_br_mnt(au_sbr(sb, bindex));
4814 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4816 + return au_br_sb(au_sbr(sb, bindex));
4819 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4821 + return au_sbr(sb, bindex)->br_perm;
4824 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4826 + return au_br_whable(au_sbr_perm(sb, bindex));
4829 +/* ---------------------------------------------------------------------- */
4831 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4832 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4833 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4834 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4836 +#define wbr_wh_read_trylock_nested(wbr) \
4837 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4838 +#define wbr_wh_write_trylock_nested(wbr) \
4839 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4842 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4843 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4844 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4846 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4847 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4848 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4850 +/* ---------------------------------------------------------------------- */
4852 +#ifdef CONFIG_AUFS_FHSM
4853 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4855 + mutex_init(&brfhsm->bf_lock);
4856 + brfhsm->bf_jiffy = 0;
4857 + brfhsm->bf_readable = 0;
4860 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4862 + mutex_destroy(&brfhsm->bf_lock);
4865 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4866 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4869 +#endif /* __KERNEL__ */
4870 +#endif /* __AUFS_BRANCH_H__ */
4871 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4872 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 08:00:00.000000000 +0800
4873 +++ linux/fs/aufs/conf.mk 2019-07-11 21:21:54.379051070 +0800
4875 +# SPDX-License-Identifier: GPL-2.0
4877 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4881 +AuConfStr += ${1}=${${1}}
4885 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4887 + HNOTIFY HFSNOTIFY \
4899 +$(foreach i, ${AuConfAll}, \
4900 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4902 +AuConfName = ${obj}/conf.str
4903 +${AuConfName}.tmp: FORCE
4904 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4905 +${AuConfName}: ${AuConfName}.tmp
4906 + @diff -q $< $@ > /dev/null 2>&1 || { \
4907 + echo ' GEN ' $@; \
4911 +clean-files += ${AuConfName} ${AuConfName}.tmp
4912 +${obj}/sysfs.o: ${AuConfName}
4914 +-include ${srctree}/${src}/conf_priv.mk
4915 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4916 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 08:00:00.000000000 +0800
4917 +++ linux/fs/aufs/cpup.c 2019-07-11 21:21:54.379051070 +0800
4919 +// SPDX-License-Identifier: GPL-2.0
4921 + * Copyright (C) 2005-2019 Junjiro R. Okajima
4923 + * This program, aufs is free software; you can redistribute it and/or modify
4924 + * it under the terms of the GNU General Public License as published by
4925 + * the Free Software Foundation; either version 2 of the License, or
4926 + * (at your option) any later version.
4928 + * This program is distributed in the hope that it will be useful,
4929 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4930 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4931 + * GNU General Public License for more details.
4933 + * You should have received a copy of the GNU General Public License
4934 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4938 + * copy-up functions, see wbr_policy.c for copy-down
4941 +#include <linux/fs_stack.h>
4942 +#include <linux/mm.h>
4943 +#include <linux/task_work.h>
4946 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4948 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4949 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4951 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4953 + dst->i_flags |= iflags & ~mask;
4954 + if (au_test_fs_notime(dst->i_sb))
4955 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4958 +void au_cpup_attr_timesizes(struct inode *inode)
4960 + struct inode *h_inode;
4962 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4963 + fsstack_copy_attr_times(inode, h_inode);
4964 + fsstack_copy_inode_size(inode, h_inode);
4967 +void au_cpup_attr_nlink(struct inode *inode, int force)
4969 + struct inode *h_inode;
4970 + struct super_block *sb;
4971 + aufs_bindex_t bindex, bbot;
4974 + bindex = au_ibtop(inode);
4975 + h_inode = au_h_iptr(inode, bindex);
4977 + && !S_ISDIR(h_inode->i_mode)
4978 + && au_opt_test(au_mntflags(sb), PLINK)
4979 + && au_plink_test(inode))
4983 + * 0 can happen in revalidating.
4984 + * h_inode->i_mutex may not be held here, but it is harmless since once
4985 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4987 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4988 + * the incorrect link count.
4990 + set_nlink(inode, h_inode->i_nlink);
4993 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4994 + * it may includes whplink directory.
4996 + if (S_ISDIR(h_inode->i_mode)) {
4997 + bbot = au_ibbot(inode);
4998 + for (bindex++; bindex <= bbot; bindex++) {
4999 + h_inode = au_h_iptr(inode, bindex);
5001 + au_add_nlink(inode, h_inode);
5006 +void au_cpup_attr_changeable(struct inode *inode)
5008 + struct inode *h_inode;
5010 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5011 + inode->i_mode = h_inode->i_mode;
5012 + inode->i_uid = h_inode->i_uid;
5013 + inode->i_gid = h_inode->i_gid;
5014 + au_cpup_attr_timesizes(inode);
5015 + au_cpup_attr_flags(inode, h_inode->i_flags);
5018 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5020 + struct au_iinfo *iinfo = au_ii(inode);
5022 + IiMustWriteLock(inode);
5024 + iinfo->ii_higen = h_inode->i_generation;
5025 + iinfo->ii_hsb1 = h_inode->i_sb;
5028 +void au_cpup_attr_all(struct inode *inode, int force)
5030 + struct inode *h_inode;
5032 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5033 + au_cpup_attr_changeable(inode);
5034 + if (inode->i_nlink > 0)
5035 + au_cpup_attr_nlink(inode, force);
5036 + inode->i_rdev = h_inode->i_rdev;
5037 + inode->i_blkbits = h_inode->i_blkbits;
5038 + au_cpup_igen(inode, h_inode);
5041 +/* ---------------------------------------------------------------------- */
5043 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5045 +/* keep the timestamps of the parent dir when cpup */
5046 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5047 + struct path *h_path)
5049 + struct inode *h_inode;
5051 + dt->dt_dentry = dentry;
5052 + dt->dt_h_path = *h_path;
5053 + h_inode = d_inode(h_path->dentry);
5054 + dt->dt_atime = h_inode->i_atime;
5055 + dt->dt_mtime = h_inode->i_mtime;
5059 +void au_dtime_revert(struct au_dtime *dt)
5061 + struct iattr attr;
5064 + attr.ia_atime = dt->dt_atime;
5065 + attr.ia_mtime = dt->dt_mtime;
5066 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5067 + | ATTR_ATIME | ATTR_ATIME_SET;
5069 + /* no delegation since this is a directory */
5070 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5071 + if (unlikely(err))
5072 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5075 +/* ---------------------------------------------------------------------- */
5077 +/* internal use only */
5078 +struct au_cpup_reg_attr {
5081 + unsigned int iflags; /* inode->i_flags */
5084 +static noinline_for_stack
5085 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5086 + struct au_cpup_reg_attr *h_src_attr)
5088 + int err, sbits, icex;
5089 + unsigned int mnt_flags;
5090 + unsigned char verbose;
5092 + struct path h_path;
5093 + struct inode *h_isrc, *h_idst;
5094 + struct kstat *h_st;
5095 + struct au_branch *br;
5097 + h_path.dentry = au_h_dptr(dst, bindex);
5098 + h_idst = d_inode(h_path.dentry);
5099 + br = au_sbr(dst->d_sb, bindex);
5100 + h_path.mnt = au_br_mnt(br);
5101 + h_isrc = d_inode(h_src);
5102 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5103 + | ATTR_ATIME | ATTR_MTIME
5104 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5105 + if (h_src_attr && h_src_attr->valid) {
5106 + h_st = &h_src_attr->st;
5107 + ia.ia_uid = h_st->uid;
5108 + ia.ia_gid = h_st->gid;
5109 + ia.ia_atime = h_st->atime;
5110 + ia.ia_mtime = h_st->mtime;
5111 + if (h_idst->i_mode != h_st->mode
5112 + && !S_ISLNK(h_idst->i_mode)) {
5113 + ia.ia_valid |= ATTR_MODE;
5114 + ia.ia_mode = h_st->mode;
5116 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5117 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5119 + ia.ia_uid = h_isrc->i_uid;
5120 + ia.ia_gid = h_isrc->i_gid;
5121 + ia.ia_atime = h_isrc->i_atime;
5122 + ia.ia_mtime = h_isrc->i_mtime;
5123 + if (h_idst->i_mode != h_isrc->i_mode
5124 + && !S_ISLNK(h_idst->i_mode)) {
5125 + ia.ia_valid |= ATTR_MODE;
5126 + ia.ia_mode = h_isrc->i_mode;
5128 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5129 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5131 + /* no delegation since it is just created */
5132 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5134 + /* is this nfs only? */
5135 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5136 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5137 + ia.ia_mode = h_isrc->i_mode;
5138 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5141 + icex = br->br_perm & AuBrAttr_ICEX;
5143 + mnt_flags = au_mntflags(dst->d_sb);
5144 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5145 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5151 +/* ---------------------------------------------------------------------- */
5153 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5154 + char *buf, unsigned long blksize)
5157 + size_t sz, rbytes, wbytes;
5158 + unsigned char all_zero;
5160 + struct inode *h_inode;
5161 + /* reduce stack usage */
5164 + zp = page_address(ZERO_PAGE(0));
5165 + if (unlikely(!zp))
5166 + return -ENOMEM; /* possible? */
5171 + AuDbg("len %lld\n", len);
5173 + if (len < blksize)
5177 + /* todo: signal_pending? */
5178 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5179 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5182 + if (unlikely(err < 0))
5186 + if (len >= rbytes && rbytes == blksize)
5187 + all_zero = !memcmp(buf, zp, rbytes);
5194 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5196 + /* todo: signal_pending? */
5197 + if (unlikely(err == -EAGAIN || err == -EINTR))
5199 + if (unlikely(err < 0))
5204 + if (unlikely(err < 0))
5210 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5212 + if (unlikely(res < 0))
5219 + /* the last block may be a hole */
5220 + if (!err && all_zero) {
5221 + AuLabel(last hole);
5224 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5225 + /* nfs requires this step to make last hole */
5226 + /* is this only nfs? */
5228 + /* todo: signal_pending? */
5229 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5230 + } while (err == -EAGAIN || err == -EINTR);
5237 + ia->ia_size = dst->f_pos;
5238 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5239 + ia->ia_file = dst;
5240 + h_inode = file_inode(dst);
5241 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5242 + /* no delegation since it is just created */
5243 + err = vfsub_notify_change(&dst->f_path, ia,
5244 + /*delegated*/NULL);
5245 + inode_unlock(h_inode);
5252 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5255 + unsigned long blksize;
5256 + unsigned char do_kfree;
5258 + struct super_block *h_sb;
5261 + h_sb = file_inode(dst)->i_sb;
5262 + blksize = h_sb->s_blocksize;
5263 + if (!blksize || PAGE_SIZE < blksize)
5264 + blksize = PAGE_SIZE;
5265 + AuDbg("blksize %lu\n", blksize);
5266 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5268 + buf = kmalloc(blksize, GFP_NOFS);
5270 + buf = (void *)__get_free_page(GFP_NOFS);
5271 + if (unlikely(!buf))
5274 + if (len > (1 << 22))
5275 + AuDbg("copying a large file %lld\n", (long long)len);
5279 + err = au_do_copy_file(dst, src, len, buf, blksize);
5281 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5282 + au_kfree_do_rcu(buf);
5284 + free_page((unsigned long)buf);
5290 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5293 + struct super_block *h_src_sb;
5294 + struct inode *h_src_inode;
5296 + h_src_inode = file_inode(src);
5297 + h_src_sb = h_src_inode->i_sb;
5299 + /* XFS acquires inode_lock */
5300 + if (!au_test_xfs(h_src_sb))
5301 + err = au_copy_file(dst, src, len);
5303 + inode_unlock_shared(h_src_inode);
5304 + err = au_copy_file(dst, src, len);
5305 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5311 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5315 + struct super_block *h_src_sb;
5316 + struct inode *h_src_inode;
5318 + h_src_inode = file_inode(src);
5319 + h_src_sb = h_src_inode->i_sb;
5320 + if (h_src_sb != file_inode(dst)->i_sb
5321 + || !dst->f_op->remap_file_range) {
5322 + err = au_do_copy(dst, src, len);
5326 + if (!au_test_nfs(h_src_sb)) {
5327 + inode_unlock_shared(h_src_inode);
5328 + lo = vfsub_clone_file_range(src, dst, len);
5329 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5331 + lo = vfsub_clone_file_range(src, dst, len);
5334 + goto out; /* success */
5335 + } else if (lo >= 0)
5336 + /* todo: possible? */
5337 + /* paritially succeeded */
5338 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5339 + else if (lo != -EOPNOTSUPP) {
5340 + /* older XFS has a condition in cloning */
5345 + /* the backend fs on NFS may not support cloning */
5346 + err = au_do_copy(dst, src, len);
5354 + * to support a sparse file which is opened with O_APPEND,
5355 + * we need to close the file.
5357 +static int au_cp_regular(struct au_cp_generic *cpg)
5360 + enum { SRC, DST };
5362 + aufs_bindex_t bindex;
5363 + unsigned int flags;
5364 + struct dentry *dentry;
5366 + struct file *file;
5369 + .bindex = cpg->bsrc,
5370 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5373 + .bindex = cpg->bdst,
5374 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5375 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5378 + struct au_branch *br;
5379 + struct super_block *sb, *h_src_sb;
5380 + struct inode *h_src_inode;
5381 + struct task_struct *tsk = current;
5383 + /* bsrc branch can be ro/rw. */
5384 + sb = cpg->dentry->d_sb;
5386 + for (i = 0; i < 2; i++, f++) {
5387 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5388 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5389 + /*file*/NULL, f->force_wr);
5390 + if (IS_ERR(f->file)) {
5391 + err = PTR_ERR(f->file);
5399 + /* try stopping to update while we copyup */
5400 + h_src_inode = d_inode(file[SRC].dentry);
5401 + h_src_sb = h_src_inode->i_sb;
5402 + if (!au_test_nfs(h_src_sb))
5403 + IMustLock(h_src_inode);
5404 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5406 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5407 + if (tsk->flags & PF_KTHREAD)
5408 + __fput_sync(file[DST].file);
5410 + /* it happened actually */
5411 + fput(file[DST].file);
5414 + * we have to call both since we don't know which place the file
5418 + flush_delayed_fput();
5420 + br = au_sbr(sb, file[DST].bindex);
5421 + au_lcnt_dec(&br->br_nfiles);
5424 + fput(file[SRC].file);
5425 + br = au_sbr(sb, file[SRC].bindex);
5426 + au_lcnt_dec(&br->br_nfiles);
5431 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5432 + struct au_cpup_reg_attr *h_src_attr)
5436 + struct path h_path;
5437 + struct inode *h_src_inode, *h_dst_inode;
5440 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5441 + l = i_size_read(h_src_inode);
5442 + if (cpg->len == -1 || l < cpg->len)
5445 + /* try stopping to update while we are referencing */
5446 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5447 + au_pin_hdir_unlock(cpg->pin);
5449 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5450 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5451 + h_src_attr->iflags = h_src_inode->i_flags;
5452 + if (!au_test_nfs(h_src_inode->i_sb))
5453 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5455 + inode_unlock_shared(h_src_inode);
5456 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5457 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5459 + if (unlikely(err)) {
5460 + inode_unlock_shared(h_src_inode);
5463 + h_src_attr->valid = 1;
5464 + if (!au_test_nfs(h_src_inode->i_sb)) {
5465 + err = au_cp_regular(cpg);
5466 + inode_unlock_shared(h_src_inode);
5468 + inode_unlock_shared(h_src_inode);
5469 + err = au_cp_regular(cpg);
5471 + rerr = au_pin_hdir_relock(cpg->pin);
5475 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5476 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5477 + h_dst_inode = d_inode(h_path.dentry);
5478 + spin_lock(&h_dst_inode->i_lock);
5479 + h_dst_inode->i_state |= I_LINKABLE;
5480 + spin_unlock(&h_dst_inode->i_lock);
5487 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5488 + struct inode *h_dir)
5491 + mm_segment_t old_fs;
5498 + sym.k = (void *)__get_free_page(GFP_NOFS);
5499 + if (unlikely(!sym.k))
5502 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5503 + old_fs = get_fs();
5504 + set_fs(KERNEL_DS);
5505 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5510 + sym.k[symlen] = 0;
5511 + err = vfsub_symlink(h_dir, h_path, sym.k);
5513 + free_page((unsigned long)sym.k);
5520 + * regardless 'acl' option, reset all ACL.
5521 + * All ACL will be copied up later from the original entry on the lower branch.
5523 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5526 + struct dentry *h_dentry;
5527 + struct inode *h_inode;
5529 + h_dentry = h_path->dentry;
5530 + h_inode = d_inode(h_dentry);
5531 + /* forget_all_cached_acls(h_inode)); */
5532 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5534 + if (err == -EOPNOTSUPP)
5537 + err = vfsub_acl_chmod(h_inode, mode);
5543 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5544 + struct inode *h_dir, struct path *h_path)
5547 + struct inode *dir, *inode;
5549 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5551 + if (err == -EOPNOTSUPP)
5553 + if (unlikely(err))
5557 + * strange behaviour from the users view,
5558 + * particularly setattr case
5560 + dir = d_inode(dst_parent);
5561 + if (au_ibtop(dir) == cpg->bdst)
5562 + au_cpup_attr_nlink(dir, /*force*/1);
5563 + inode = d_inode(cpg->dentry);
5564 + au_cpup_attr_nlink(inode, /*force*/1);
5570 +static noinline_for_stack
5571 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5572 + struct au_cpup_reg_attr *h_src_attr)
5576 + unsigned int mnt_flags;
5577 + unsigned char isdir, isreg, force;
5578 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5579 + struct au_dtime dt;
5580 + struct path h_path;
5581 + struct dentry *h_src, *h_dst, *h_parent;
5582 + struct inode *h_inode, *h_dir;
5583 + struct super_block *sb;
5585 + /* bsrc branch can be ro/rw. */
5586 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5587 + h_inode = d_inode(h_src);
5588 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5590 + /* try stopping to be referenced while we are creating */
5591 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5592 + if (au_ftest_cpup(cpg->flags, RENAME))
5593 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5594 + AUFS_WH_PFX_LEN));
5595 + h_parent = h_dst->d_parent; /* dir inode is locked */
5596 + h_dir = d_inode(h_parent);
5598 + AuDebugOn(h_parent != h_dst->d_parent);
5600 + sb = cpg->dentry->d_sb;
5601 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5603 + h_path.dentry = h_parent;
5604 + au_dtime_store(&dt, dst_parent, &h_path);
5606 + h_path.dentry = h_dst;
5610 + mode = h_inode->i_mode;
5611 + switch (mode & S_IFMT) {
5614 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5616 + err = au_do_cpup_regular(cpg, h_src_attr);
5620 + err = vfsub_mkdir(h_dir, &h_path, mode);
5622 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5625 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5629 + AuDebugOn(!capable(CAP_MKNOD));
5633 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5636 + AuIOErr("Unknown inode type 0%o\n", mode);
5640 + err = au_reset_acl(h_dir, &h_path, mode);
5642 + mnt_flags = au_mntflags(sb);
5643 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5645 + && au_opt_test(mnt_flags, XINO)
5646 + && (h_inode->i_nlink == 1
5647 + || (h_inode->i_state & I_LINKABLE))
5648 + /* todo: unnecessary? */
5649 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5650 + && cpg->bdst < cpg->bsrc
5651 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5652 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5653 + /* ignore this error */
5658 + force = !!cpg->len;
5659 + if (cpg->len == -1)
5660 + force = !!i_size_read(h_inode);
5662 + au_fhsm_wrote(sb, cpg->bdst, force);
5666 + au_dtime_revert(&dt);
5670 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5673 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5674 + struct inode *h_dir;
5675 + aufs_bindex_t bdst;
5677 + dentry = cpg->dentry;
5679 + h_dentry = au_h_dptr(dentry, bdst);
5680 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5682 + au_set_h_dptr(dentry, bdst, NULL);
5683 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5685 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5686 + au_set_h_dptr(dentry, bdst, h_dentry);
5689 + parent = dget_parent(dentry);
5690 + h_parent = au_h_dptr(parent, bdst);
5692 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5693 + if (IS_ERR(h_path->dentry))
5694 + err = PTR_ERR(h_path->dentry);
5696 + if (unlikely(err))
5699 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5700 + h_dir = d_inode(h_parent);
5702 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5703 + /* no delegation since it is just created */
5704 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5706 + dput(h_path->dentry);
5713 + * copyup the @dentry from @bsrc to @bdst.
5714 + * the caller must set the both of lower dentries.
5715 + * @len is for truncating when it is -1 copyup the entire file.
5716 + * in link/rename cases, @dst_parent may be different from the real one.
5717 + * basic->bsrc can be larger than basic->bdst.
5718 + * aufs doesn't touch the credential so
5719 + * security_inode_copy_up{,_xattr}() are unnecessary.
5721 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5724 + aufs_bindex_t old_ibtop;
5725 + unsigned char isdir, plink;
5726 + struct dentry *h_src, *h_dst, *h_parent;
5727 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5728 + struct super_block *sb;
5729 + struct au_branch *br;
5730 + /* to reduce stack size */
5732 + struct au_dtime dt;
5733 + struct path h_path;
5734 + struct au_cpup_reg_attr h_src_attr;
5738 + a = kmalloc(sizeof(*a), GFP_NOFS);
5741 + a->h_src_attr.valid = 0;
5743 + sb = cpg->dentry->d_sb;
5744 + br = au_sbr(sb, cpg->bdst);
5745 + a->h_path.mnt = au_br_mnt(br);
5746 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5747 + h_parent = h_dst->d_parent; /* dir inode is locked */
5748 + h_dir = d_inode(h_parent);
5751 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5752 + inode = d_inode(cpg->dentry);
5755 + dst_parent = dget_parent(cpg->dentry);
5759 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5760 + dst_inode = au_h_iptr(inode, cpg->bdst);
5762 + if (unlikely(!plink)) {
5764 + AuIOErr("hi%lu(i%lu) exists on b%d "
5765 + "but plink is disabled\n",
5766 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5770 + if (dst_inode->i_nlink) {
5771 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5773 + h_src = au_plink_lkup(inode, cpg->bdst);
5774 + err = PTR_ERR(h_src);
5775 + if (IS_ERR(h_src))
5777 + if (unlikely(d_is_negative(h_src))) {
5779 + AuIOErr("i%lu exists on b%d "
5780 + "but not pseudo-linked\n",
5781 + inode->i_ino, cpg->bdst);
5787 + a->h_path.dentry = h_parent;
5788 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5791 + a->h_path.dentry = h_dst;
5793 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5794 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5795 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5797 + au_dtime_revert(&a->dt);
5798 + if (unlikely(err == -EWOULDBLOCK)) {
5799 + pr_warn("cannot retry for NFSv4 delegation"
5800 + " for an internal link\n");
5806 + /* todo: cpup_wh_file? */
5808 + au_update_ibrange(inode, /*do_put_zero*/1);
5811 + isdir = S_ISDIR(inode->i_mode);
5812 + old_ibtop = au_ibtop(inode);
5813 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5814 + if (unlikely(err))
5816 + dst_inode = d_inode(h_dst);
5817 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5818 + /* todo: necessary? */
5819 + /* au_pin_hdir_unlock(cpg->pin); */
5821 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5822 + if (unlikely(err)) {
5823 + /* todo: necessary? */
5824 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5825 + inode_unlock(dst_inode);
5829 + if (cpg->bdst < old_ibtop) {
5830 + if (S_ISREG(inode->i_mode)) {
5831 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5832 + if (unlikely(err)) {
5833 + /* ignore an error */
5834 + /* au_pin_hdir_relock(cpg->pin); */
5835 + inode_unlock(dst_inode);
5839 + au_set_ibtop(inode, cpg->bdst);
5841 + au_set_ibbot(inode, cpg->bdst);
5842 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5843 + au_hi_flags(inode, isdir));
5845 + /* todo: necessary? */
5846 + /* err = au_pin_hdir_relock(cpg->pin); */
5847 + inode_unlock(dst_inode);
5848 + if (unlikely(err))
5851 + src_inode = d_inode(h_src);
5853 + && (src_inode->i_nlink > 1
5854 + || src_inode->i_state & I_LINKABLE)
5856 + au_plink_append(inode, cpg->bdst, h_dst);
5858 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5859 + a->h_path.dentry = h_dst;
5860 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5863 + goto out_parent; /* success */
5867 + a->h_path.dentry = h_parent;
5868 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5869 + a->h_path.dentry = h_dst;
5871 + if (d_is_positive(h_dst)) {
5873 + /* no delegation since it is just created */
5874 + rerr = vfsub_unlink(h_dir, &a->h_path,
5875 + /*delegated*/NULL, /*force*/0);
5877 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5879 + au_dtime_revert(&a->dt);
5881 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5891 +#if 0 /* reserved */
5892 +struct au_cpup_single_args {
5894 + struct au_cp_generic *cpg;
5895 + struct dentry *dst_parent;
5898 +static void au_call_cpup_single(void *args)
5900 + struct au_cpup_single_args *a = args;
5902 + au_pin_hdir_acquire_nest(a->cpg->pin);
5903 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5904 + au_pin_hdir_release(a->cpg->pin);
5909 + * prevent SIGXFSZ in copy-up.
5910 + * testing CAP_MKNOD is for generic fs,
5911 + * but CAP_FSETID is for xfs only, currently.
5913 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5916 + struct super_block *sb;
5917 + struct inode *h_dir;
5920 + sb = au_pinned_parent(pin)->d_sb;
5921 + if (!au_wkq_test()
5922 + && (!au_sbi(sb)->si_plink_maint_pid
5923 + || au_plink_maint(sb, AuLock_NOPLM))) {
5924 + switch (mode & S_IFMT) {
5926 + /* no condition about RLIMIT_FSIZE and the file size */
5931 + do_sio = !capable(CAP_MKNOD);
5935 + do_sio = ((mode & (S_ISUID | S_ISGID))
5936 + && !capable(CAP_FSETID));
5937 + /* this workaround may be removed in the future */
5939 + h_dir = au_pinned_h_dir(pin);
5940 + do_sio = h_dir->i_mode & S_ISVTX;
5947 +#if 0 /* reserved */
5948 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5951 + struct dentry *h_dentry;
5953 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5954 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5955 + err = au_cpup_single(cpg, dst_parent);
5957 + struct au_cpup_single_args args = {
5960 + .dst_parent = dst_parent
5962 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5963 + if (unlikely(wkq_err))
5972 + * copyup the @dentry from the first active lower branch to @bdst,
5973 + * using au_cpup_single().
5975 +static int au_cpup_simple(struct au_cp_generic *cpg)
5978 + unsigned int flags_orig;
5979 + struct dentry *dentry;
5981 + AuDebugOn(cpg->bsrc < 0);
5983 + dentry = cpg->dentry;
5984 + DiMustWriteLock(dentry);
5986 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5988 + flags_orig = cpg->flags;
5989 + au_fset_cpup(cpg->flags, RENAME);
5990 + err = au_cpup_single(cpg, NULL);
5991 + cpg->flags = flags_orig;
5993 + return 0; /* success */
5996 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5997 + au_set_dbtop(dentry, cpg->bsrc);
6003 +struct au_cpup_simple_args {
6005 + struct au_cp_generic *cpg;
6008 +static void au_call_cpup_simple(void *args)
6010 + struct au_cpup_simple_args *a = args;
6012 + au_pin_hdir_acquire_nest(a->cpg->pin);
6013 + *a->errp = au_cpup_simple(a->cpg);
6014 + au_pin_hdir_release(a->cpg->pin);
6017 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6020 + struct dentry *dentry, *parent;
6021 + struct file *h_file;
6022 + struct inode *h_dir;
6024 + dentry = cpg->dentry;
6026 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6027 + AuDebugOn(cpg->bsrc < 0);
6028 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6029 + err = PTR_ERR(h_file);
6030 + if (IS_ERR(h_file))
6034 + parent = dget_parent(dentry);
6035 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6036 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6037 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6038 + err = au_cpup_simple(cpg);
6040 + struct au_cpup_simple_args args = {
6044 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6045 + if (unlikely(wkq_err))
6051 + au_h_open_post(dentry, cpg->bsrc, h_file);
6057 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6059 + aufs_bindex_t bsrc, bbot;
6060 + struct dentry *dentry, *h_dentry;
6062 + if (cpg->bsrc < 0) {
6063 + dentry = cpg->dentry;
6064 + bbot = au_dbbot(dentry);
6065 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6066 + h_dentry = au_h_dptr(dentry, bsrc);
6068 + AuDebugOn(d_is_negative(h_dentry));
6072 + AuDebugOn(bsrc > bbot);
6075 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6076 + return au_do_sio_cpup_simple(cpg);
6079 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6081 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6082 + return au_do_sio_cpup_simple(cpg);
6085 +/* ---------------------------------------------------------------------- */
6088 + * copyup the deleted file for writing.
6090 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6091 + struct file *file)
6094 + unsigned int flags_orig;
6095 + aufs_bindex_t bsrc_orig;
6096 + struct au_dinfo *dinfo;
6098 + struct au_hdentry *hd;
6099 + struct dentry *h_dentry;
6102 + dinfo = au_di(cpg->dentry);
6103 + AuRwMustWriteLock(&dinfo->di_rwsem);
6105 + bsrc_orig = cpg->bsrc;
6106 + cpg->bsrc = dinfo->di_btop;
6107 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6108 + hdst.h_dentry = hdst.hd->hd_dentry;
6109 + hdst.hd->hd_dentry = wh_dentry;
6110 + dinfo->di_btop = cpg->bdst;
6112 + hsrc.h_dentry = NULL;
6114 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6115 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6116 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6118 + flags_orig = cpg->flags;
6119 + cpg->flags = !AuCpup_DTIME;
6120 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6121 + cpg->flags = flags_orig;
6124 + err = au_reopen_nondir(file);
6125 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6127 + hdst.hd->hd_dentry = hdst.h_dentry;
6128 + dinfo->di_btop = cpg->bsrc;
6129 + cpg->bsrc = bsrc_orig;
6134 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6137 + aufs_bindex_t bdst;
6138 + struct au_dtime dt;
6139 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6140 + struct au_branch *br;
6141 + struct path h_path;
6143 + dentry = cpg->dentry;
6145 + br = au_sbr(dentry->d_sb, bdst);
6146 + parent = dget_parent(dentry);
6147 + h_parent = au_h_dptr(parent, bdst);
6148 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6149 + err = PTR_ERR(wh_dentry);
6150 + if (IS_ERR(wh_dentry))
6153 + h_path.dentry = h_parent;
6154 + h_path.mnt = au_br_mnt(br);
6155 + au_dtime_store(&dt, parent, &h_path);
6156 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6157 + if (unlikely(err))
6161 + h_path.dentry = wh_dentry;
6162 + if (!d_is_dir(wh_dentry)) {
6163 + /* no delegation since it is just created */
6164 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6165 + /*delegated*/NULL, /*force*/0);
6167 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6168 + if (unlikely(err)) {
6169 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6173 + au_dtime_revert(&dt);
6174 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6183 +struct au_cpup_wh_args {
6185 + struct au_cp_generic *cpg;
6186 + struct file *file;
6189 +static void au_call_cpup_wh(void *args)
6191 + struct au_cpup_wh_args *a = args;
6193 + au_pin_hdir_acquire_nest(a->cpg->pin);
6194 + *a->errp = au_cpup_wh(a->cpg, a->file);
6195 + au_pin_hdir_release(a->cpg->pin);
6198 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6201 + aufs_bindex_t bdst;
6202 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6203 + struct inode *dir, *h_dir, *h_tmpdir;
6204 + struct au_wbr *wbr;
6205 + struct au_pin wh_pin, *pin_orig;
6207 + dentry = cpg->dentry;
6209 + parent = dget_parent(dentry);
6210 + dir = d_inode(parent);
6213 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6216 + if (!h_dir->i_nlink) {
6217 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6218 + h_orph = wbr->wbr_orph;
6220 + h_parent = dget(au_h_dptr(parent, bdst));
6221 + au_set_h_dptr(parent, bdst, dget(h_orph));
6222 + h_tmpdir = d_inode(h_orph);
6223 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6225 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6226 + /* todo: au_h_open_pre()? */
6228 + pin_orig = cpg->pin;
6229 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6230 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6231 + cpg->pin = &wh_pin;
6234 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6235 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6236 + err = au_cpup_wh(cpg, file);
6238 + struct au_cpup_wh_args args = {
6243 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6244 + if (unlikely(wkq_err))
6249 + inode_unlock(h_tmpdir);
6250 + /* todo: au_h_open_post()? */
6251 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6252 + au_set_h_dptr(parent, bdst, h_parent);
6253 + AuDebugOn(!pin_orig);
6254 + cpg->pin = pin_orig;
6262 +/* ---------------------------------------------------------------------- */
6265 + * generic routine for both of copy-up and copy-down.
6267 +/* cf. revalidate function in file.c */
6268 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6269 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6270 + struct au_pin *pin,
6271 + struct dentry *h_parent, void *arg),
6275 + struct au_pin pin;
6276 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6279 + parent = dget_parent(dentry);
6280 + if (IS_ROOT(parent))
6283 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6284 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6286 + /* do not use au_dpage */
6287 + real_parent = parent;
6290 + parent = dget_parent(dentry);
6291 + h_parent = au_h_dptr(parent, bdst);
6293 + goto out; /* success */
6295 + /* find top dir which is necessary to cpup */
6299 + parent = dget_parent(d);
6300 + di_read_lock_parent3(parent, !AuLock_IR);
6301 + h_parent = au_h_dptr(parent, bdst);
6302 + di_read_unlock(parent, !AuLock_IR);
6303 + } while (!h_parent);
6305 + if (d != real_parent)
6306 + di_write_lock_child3(d);
6308 + /* somebody else might create while we were sleeping */
6309 + h_dentry = au_h_dptr(d, bdst);
6310 + if (!h_dentry || d_is_negative(h_dentry)) {
6312 + au_update_dbtop(d);
6314 + au_pin_set_dentry(&pin, d);
6315 + err = au_do_pin(&pin);
6317 + err = cp(d, bdst, &pin, h_parent, arg);
6322 + if (d != real_parent)
6323 + di_write_unlock(d);
6324 + if (unlikely(err))
6333 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6334 + struct au_pin *pin,
6335 + struct dentry *h_parent __maybe_unused,
6336 + void *arg __maybe_unused)
6338 + struct au_cp_generic cpg = {
6344 + .flags = AuCpup_DTIME
6346 + return au_sio_cpup_simple(&cpg);
6349 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6351 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6354 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6357 + struct dentry *parent;
6358 + struct inode *dir;
6360 + parent = dget_parent(dentry);
6361 + dir = d_inode(parent);
6363 + if (au_h_iptr(dir, bdst))
6366 + di_read_unlock(parent, AuLock_IR);
6367 + di_write_lock_parent(parent);
6368 + /* someone else might change our inode while we were sleeping */
6369 + if (!au_h_iptr(dir, bdst))
6370 + err = au_cpup_dirs(dentry, bdst);
6371 + di_downgrade_lock(parent, AuLock_IR);
6377 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6378 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 08:00:00.000000000 +0800
6379 +++ linux/fs/aufs/cpup.h 2019-07-11 21:21:54.379051070 +0800
6381 +/* SPDX-License-Identifier: GPL-2.0 */
6383 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6385 + * This program, aufs is free software; you can redistribute it and/or modify
6386 + * it under the terms of the GNU General Public License as published by
6387 + * the Free Software Foundation; either version 2 of the License, or
6388 + * (at your option) any later version.
6390 + * This program is distributed in the hope that it will be useful,
6391 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6392 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6393 + * GNU General Public License for more details.
6395 + * You should have received a copy of the GNU General Public License
6396 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6400 + * copy-up/down functions
6403 +#ifndef __AUFS_CPUP_H__
6404 +#define __AUFS_CPUP_H__
6408 +#include <linux/path.h>
6414 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6415 +void au_cpup_attr_timesizes(struct inode *inode);
6416 +void au_cpup_attr_nlink(struct inode *inode, int force);
6417 +void au_cpup_attr_changeable(struct inode *inode);
6418 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6419 +void au_cpup_attr_all(struct inode *inode, int force);
6421 +/* ---------------------------------------------------------------------- */
6423 +struct au_cp_generic {
6424 + struct dentry *dentry;
6425 + aufs_bindex_t bdst, bsrc;
6427 + struct au_pin *pin;
6428 + unsigned int flags;
6432 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6433 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6435 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6436 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6438 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6440 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6441 + the branch is marked as RO */
6443 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6444 +#undef AuCpup_HOPEN
6445 +#define AuCpup_HOPEN 0
6448 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6449 +#define au_fset_cpup(flags, name) \
6450 + do { (flags) |= AuCpup_##name; } while (0)
6451 +#define au_fclr_cpup(flags, name) \
6452 + do { (flags) &= ~AuCpup_##name; } while (0)
6454 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6455 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6456 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6457 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6459 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6460 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6461 + struct au_pin *pin,
6462 + struct dentry *h_parent, void *arg),
6464 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6465 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6467 +/* ---------------------------------------------------------------------- */
6469 +/* keep timestamps when copyup */
6471 + struct dentry *dt_dentry;
6472 + struct path dt_h_path;
6473 + struct timespec64 dt_atime, dt_mtime;
6475 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6476 + struct path *h_path);
6477 +void au_dtime_revert(struct au_dtime *dt);
6479 +#endif /* __KERNEL__ */
6480 +#endif /* __AUFS_CPUP_H__ */
6481 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6482 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 08:00:00.000000000 +0800
6483 +++ linux/fs/aufs/dbgaufs.c 2019-07-11 21:21:54.379051070 +0800
6485 +// SPDX-License-Identifier: GPL-2.0
6487 + * Copyright (C) 2005-2019 Junjiro R. Okajima
6489 + * This program, aufs is free software; you can redistribute it and/or modify
6490 + * it under the terms of the GNU General Public License as published by
6491 + * the Free Software Foundation; either version 2 of the License, or
6492 + * (at your option) any later version.
6494 + * This program is distributed in the hope that it will be useful,
6495 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6496 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6497 + * GNU General Public License for more details.
6499 + * You should have received a copy of the GNU General Public License
6500 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6504 + * debugfs interface
6507 +#include <linux/debugfs.h>
6510 +#ifndef CONFIG_SYSFS
6511 +#error DEBUG_FS depends upon SYSFS
6514 +static struct dentry *dbgaufs;
6515 +static const mode_t dbgaufs_mode = 0444;
6517 +/* 20 is max digits length of ulong 64 */
6518 +struct dbgaufs_arg {
6524 + * common function for all XINO files
6526 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6527 + struct file *file)
6531 + p = file->private_data;
6533 + /* this is struct dbgaufs_arg */
6534 + AuDebugOn(!au_kfree_sz_test(p));
6535 + au_kfree_do_rcu(p);
6540 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6545 + struct dbgaufs_arg *p;
6548 + p = kmalloc(sizeof(*p), GFP_NOFS);
6554 + file->private_data = p;
6558 + err = vfsub_getattr(&xf->f_path, &st);
6562 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6563 + cnt, st.blocks, st.blksize,
6564 + (long long)st.size);
6566 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6567 + st.blocks, st.blksize,
6568 + (long long)st.size);
6569 + AuDebugOn(p->n >= sizeof(p->a));
6571 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6579 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6580 + size_t count, loff_t *ppos)
6582 + struct dbgaufs_arg *p;
6584 + p = file->private_data;
6585 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6588 +/* ---------------------------------------------------------------------- */
6590 +struct dbgaufs_plink_arg {
6595 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6596 + struct file *file)
6598 + free_page((unsigned long)file->private_data);
6602 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6604 + int err, i, limit;
6605 + unsigned long n, sum;
6606 + struct dbgaufs_plink_arg *p;
6607 + struct au_sbinfo *sbinfo;
6608 + struct super_block *sb;
6609 + struct hlist_bl_head *hbl;
6612 + p = (void *)get_zeroed_page(GFP_NOFS);
6617 + sbinfo = inode->i_private;
6618 + sb = sbinfo->si_sb;
6619 + si_noflush_read_lock(sb);
6620 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6621 + limit = PAGE_SIZE - sizeof(p->n);
6623 + /* the number of buckets */
6624 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6629 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6631 + n = au_hbl_count(hbl);
6634 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6637 + if (unlikely(limit <= 0))
6640 + p->a[p->n - 1] = '\n';
6642 + /* the sum of plinks */
6643 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6646 + if (unlikely(limit <= 0))
6649 +#define str "1\n0\n0\n"
6650 + p->n = sizeof(str) - 1;
6651 + strcpy(p->a, str);
6654 + si_read_unlock(sb);
6657 + file->private_data = p;
6658 + goto out; /* success */
6661 + free_page((unsigned long)p);
6666 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6667 + size_t count, loff_t *ppos)
6669 + struct dbgaufs_plink_arg *p;
6671 + p = file->private_data;
6672 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6675 +static const struct file_operations dbgaufs_plink_fop = {
6676 + .owner = THIS_MODULE,
6677 + .open = dbgaufs_plink_open,
6678 + .release = dbgaufs_plink_release,
6679 + .read = dbgaufs_plink_read
6682 +/* ---------------------------------------------------------------------- */
6684 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6687 + struct au_sbinfo *sbinfo;
6688 + struct super_block *sb;
6690 + sbinfo = inode->i_private;
6691 + sb = sbinfo->si_sb;
6692 + si_noflush_read_lock(sb);
6693 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6694 + si_read_unlock(sb);
6698 +static const struct file_operations dbgaufs_xib_fop = {
6699 + .owner = THIS_MODULE,
6700 + .open = dbgaufs_xib_open,
6701 + .release = dbgaufs_xi_release,
6702 + .read = dbgaufs_xi_read
6705 +/* ---------------------------------------------------------------------- */
6707 +#define DbgaufsXi_PREFIX "xi"
6709 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6713 + aufs_bindex_t bindex;
6714 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6715 + struct au_sbinfo *sbinfo;
6716 + struct super_block *sb;
6717 + struct au_xino *xi;
6719 + struct qstr *name;
6720 + struct au_branch *br;
6723 + name = &file->f_path.dentry->d_name;
6724 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6725 + || memcmp(name->name, DbgaufsXi_PREFIX,
6726 + sizeof(DbgaufsXi_PREFIX) - 1)))
6729 + AuDebugOn(name->len >= sizeof(a));
6730 + memcpy(a, name->name, name->len);
6731 + a[name->len] = '\0';
6732 + p = strchr(a, '-');
6735 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6736 + if (unlikely(err))
6741 + err = kstrtol(p + 1, 10, &l);
6742 + if (unlikely(err))
6748 + sbinfo = inode->i_private;
6749 + sb = sbinfo->si_sb;
6750 + si_noflush_read_lock(sb);
6751 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6753 + br = au_sbr(sb, bindex);
6755 + if (unlikely(idx >= xi->xi_nfile))
6757 + xf = au_xino_file(xi, idx);
6759 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6760 + au_xino_count(br));
6763 + si_read_unlock(sb);
6769 +static const struct file_operations dbgaufs_xino_fop = {
6770 + .owner = THIS_MODULE,
6771 + .open = dbgaufs_xino_open,
6772 + .release = dbgaufs_xi_release,
6773 + .read = dbgaufs_xi_read
6776 +void dbgaufs_xino_del(struct au_branch *br)
6778 + struct dentry *dbgaufs;
6780 + dbgaufs = br->br_dbgaufs;
6784 + br->br_dbgaufs = NULL;
6785 + /* debugfs acquires the parent i_mutex */
6787 + debugfs_remove(dbgaufs);
6791 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6793 + aufs_bindex_t bbot;
6794 + struct au_branch *br;
6796 + if (!au_sbi(sb)->si_dbgaufs)
6799 + bbot = au_sbbot(sb);
6800 + for (; bindex <= bbot; bindex++) {
6801 + br = au_sbr(sb, bindex);
6802 + dbgaufs_xino_del(br);
6806 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6807 + unsigned int idx, struct dentry *parent,
6808 + struct au_sbinfo *sbinfo)
6810 + struct au_branch *br;
6812 + /* "xi" bindex(5) "-" idx(2) NULL */
6813 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6816 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6818 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6820 + br = au_sbr(sb, bindex);
6821 + if (br->br_dbgaufs) {
6822 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6824 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6825 + /* debugfs acquires the parent i_mutex */
6827 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6831 + pr_warn("failed renaming %pd/%s, ignored.\n",
6836 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6837 + sbinfo, &dbgaufs_xino_fop);
6839 + if (unlikely(!br->br_dbgaufs))
6840 + pr_warn("failed creating %pd/%s, ignored.\n",
6845 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6846 + struct dentry *parent, struct au_sbinfo *sbinfo)
6848 + struct au_branch *br;
6849 + struct au_xino *xi;
6852 + br = au_sbr(sb, bindex);
6854 + for (u = 0; u < xi->xi_nfile; u++)
6855 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6858 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6860 + struct au_sbinfo *sbinfo;
6861 + struct dentry *parent;
6862 + aufs_bindex_t bbot;
6864 + if (!au_opt_test(au_mntflags(sb), XINO))
6867 + sbinfo = au_sbi(sb);
6868 + parent = sbinfo->si_dbgaufs;
6872 + bbot = au_sbbot(sb);
6874 + for (; bindex <= bbot; bindex++)
6875 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6877 + for (; bbot >= bindex; bbot--)
6878 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6881 +/* ---------------------------------------------------------------------- */
6883 +#ifdef CONFIG_AUFS_EXPORT
6884 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6887 + struct au_sbinfo *sbinfo;
6888 + struct super_block *sb;
6890 + sbinfo = inode->i_private;
6891 + sb = sbinfo->si_sb;
6892 + si_noflush_read_lock(sb);
6893 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6894 + si_read_unlock(sb);
6898 +static const struct file_operations dbgaufs_xigen_fop = {
6899 + .owner = THIS_MODULE,
6900 + .open = dbgaufs_xigen_open,
6901 + .release = dbgaufs_xi_release,
6902 + .read = dbgaufs_xi_read
6905 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6910 + * This function is a dynamic '__init' function actually,
6911 + * so the tiny check for si_rwsem is unnecessary.
6913 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6916 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6917 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6918 + &dbgaufs_xigen_fop);
6919 + if (sbinfo->si_dbgaufs_xigen)
6925 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6929 +#endif /* CONFIG_AUFS_EXPORT */
6931 +/* ---------------------------------------------------------------------- */
6933 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6936 + * This function is a dynamic '__fin' function actually,
6937 + * so the tiny check for si_rwsem is unnecessary.
6939 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6941 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6942 + sbinfo->si_dbgaufs = NULL;
6945 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6948 + char name[SysaufsSiNameLen];
6951 + * This function is a dynamic '__init' function actually,
6952 + * so the tiny check for si_rwsem is unnecessary.
6954 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6958 + AuErr1("/debug/aufs is uninitialized\n");
6963 + sysaufs_name(sbinfo, name);
6964 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6965 + if (unlikely(!sbinfo->si_dbgaufs))
6968 + /* regardless plink/noplink option */
6969 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6970 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6971 + &dbgaufs_plink_fop);
6972 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6975 + /* regardless xino/noxino option */
6976 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6977 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6978 + &dbgaufs_xib_fop);
6979 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6982 + err = dbgaufs_xigen_init(sbinfo);
6984 + goto out; /* success */
6987 + dbgaufs_si_fin(sbinfo);
6989 + if (unlikely(err))
6990 + pr_err("debugfs/aufs failed\n");
6994 +/* ---------------------------------------------------------------------- */
6996 +void dbgaufs_fin(void)
6998 + debugfs_remove(dbgaufs);
7001 +int __init dbgaufs_init(void)
7006 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7011 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7012 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 08:00:00.000000000 +0800
7013 +++ linux/fs/aufs/dbgaufs.h 2019-07-11 21:21:54.379051070 +0800
7015 +/* SPDX-License-Identifier: GPL-2.0 */
7017 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7019 + * This program, aufs is free software; you can redistribute it and/or modify
7020 + * it under the terms of the GNU General Public License as published by
7021 + * the Free Software Foundation; either version 2 of the License, or
7022 + * (at your option) any later version.
7024 + * This program is distributed in the hope that it will be useful,
7025 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7026 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7027 + * GNU General Public License for more details.
7029 + * You should have received a copy of the GNU General Public License
7030 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7034 + * debugfs interface
7037 +#ifndef __DBGAUFS_H__
7038 +#define __DBGAUFS_H__
7042 +struct super_block;
7046 +#ifdef CONFIG_DEBUG_FS
7048 +void dbgaufs_xino_del(struct au_branch *br);
7049 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7050 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7051 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7052 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7053 +void dbgaufs_fin(void);
7054 +int __init dbgaufs_init(void);
7056 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7057 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7058 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7060 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7061 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7062 +AuStubVoid(dbgaufs_fin, void)
7063 +AuStubInt0(__init dbgaufs_init, void)
7064 +#endif /* CONFIG_DEBUG_FS */
7066 +#endif /* __KERNEL__ */
7067 +#endif /* __DBGAUFS_H__ */
7068 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7069 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 08:00:00.000000000 +0800
7070 +++ linux/fs/aufs/dcsub.c 2019-07-11 21:21:54.379051070 +0800
7072 +// SPDX-License-Identifier: GPL-2.0
7074 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7076 + * This program, aufs is free software; you can redistribute it and/or modify
7077 + * it under the terms of the GNU General Public License as published by
7078 + * the Free Software Foundation; either version 2 of the License, or
7079 + * (at your option) any later version.
7081 + * This program is distributed in the hope that it will be useful,
7082 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7083 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7084 + * GNU General Public License for more details.
7086 + * You should have received a copy of the GNU General Public License
7087 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7091 + * sub-routines for dentry cache
7096 +static void au_dpage_free(struct au_dpage *dpage)
7099 + struct dentry **p;
7101 + p = dpage->dentries;
7102 + for (i = 0; i < dpage->ndentry; i++)
7104 + free_page((unsigned long)dpage->dentries);
7107 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7113 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7114 + if (unlikely(!dpages->dpages))
7117 + p = (void *)__get_free_page(gfp);
7121 + dpages->dpages[0].ndentry = 0;
7122 + dpages->dpages[0].dentries = p;
7123 + dpages->ndpage = 1;
7124 + return 0; /* success */
7127 + au_kfree_try_rcu(dpages->dpages);
7132 +void au_dpages_free(struct au_dcsub_pages *dpages)
7135 + struct au_dpage *p;
7137 + p = dpages->dpages;
7138 + for (i = 0; i < dpages->ndpage; i++)
7139 + au_dpage_free(p++);
7140 + au_kfree_try_rcu(dpages->dpages);
7143 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7144 + struct dentry *dentry, gfp_t gfp)
7147 + struct au_dpage *dpage;
7150 + dpage = dpages->dpages + dpages->ndpage - 1;
7151 + sz = PAGE_SIZE / sizeof(dentry);
7152 + if (unlikely(dpage->ndentry >= sz)) {
7153 + AuLabel(new dpage);
7155 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7156 + p = au_kzrealloc(dpages->dpages, sz,
7157 + sz + sizeof(*dpages->dpages), gfp,
7162 + dpages->dpages = p;
7163 + dpage = dpages->dpages + dpages->ndpage;
7164 + p = (void *)__get_free_page(gfp);
7168 + dpage->ndentry = 0;
7169 + dpage->dentries = p;
7173 + AuDebugOn(au_dcount(dentry) <= 0);
7174 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7175 + return 0; /* success */
7181 +/* todo: BAD approach */
7182 +/* copied from linux/fs/dcache.c */
7190 +extern void d_walk(struct dentry *parent, void *data,
7191 + enum d_walk_ret (*enter)(void *, struct dentry *));
7193 +struct ac_dpages_arg {
7195 + struct au_dcsub_pages *dpages;
7196 + struct super_block *sb;
7197 + au_dpages_test test;
7201 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7203 + enum d_walk_ret ret;
7204 + struct ac_dpages_arg *arg = _arg;
7206 + ret = D_WALK_CONTINUE;
7207 + if (dentry->d_sb == arg->sb
7208 + && !IS_ROOT(dentry)
7209 + && au_dcount(dentry) > 0
7211 + && (!arg->test || arg->test(dentry, arg->arg))) {
7212 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7213 + if (unlikely(arg->err))
7214 + ret = D_WALK_QUIT;
7220 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7221 + au_dpages_test test, void *arg)
7223 + struct ac_dpages_arg args = {
7231 + d_walk(root, &args, au_call_dpages_append);
7236 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7237 + int do_include, au_dpages_test test, void *arg)
7242 + write_seqlock(&rename_lock);
7243 + spin_lock(&dentry->d_lock);
7245 + && au_dcount(dentry) > 0
7246 + && (!test || test(dentry, arg)))
7247 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7248 + spin_unlock(&dentry->d_lock);
7249 + if (unlikely(err))
7253 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7256 + while (!IS_ROOT(dentry)) {
7257 + dentry = dentry->d_parent; /* rename_lock is locked */
7258 + spin_lock(&dentry->d_lock);
7259 + if (au_dcount(dentry) > 0
7260 + && (!test || test(dentry, arg)))
7261 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7262 + spin_unlock(&dentry->d_lock);
7263 + if (unlikely(err))
7268 + write_sequnlock(&rename_lock);
7272 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7274 + return au_di(dentry) && dentry->d_sb == arg;
7277 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7278 + struct dentry *dentry, int do_include)
7280 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7281 + au_dcsub_dpages_aufs, dentry->d_sb);
7284 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7286 + struct path path[2] = {
7295 + return path_is_under(path + 0, path + 1);
7297 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7298 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 08:00:00.000000000 +0800
7299 +++ linux/fs/aufs/dcsub.h 2019-07-11 21:21:54.379051070 +0800
7301 +/* SPDX-License-Identifier: GPL-2.0 */
7303 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7305 + * This program, aufs is free software; you can redistribute it and/or modify
7306 + * it under the terms of the GNU General Public License as published by
7307 + * the Free Software Foundation; either version 2 of the License, or
7308 + * (at your option) any later version.
7310 + * This program is distributed in the hope that it will be useful,
7311 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7312 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7313 + * GNU General Public License for more details.
7315 + * You should have received a copy of the GNU General Public License
7316 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7320 + * sub-routines for dentry cache
7323 +#ifndef __AUFS_DCSUB_H__
7324 +#define __AUFS_DCSUB_H__
7328 +#include <linux/dcache.h>
7329 +#include <linux/fs.h>
7333 + struct dentry **dentries;
7336 +struct au_dcsub_pages {
7338 + struct au_dpage *dpages;
7341 +/* ---------------------------------------------------------------------- */
7344 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7345 +void au_dpages_free(struct au_dcsub_pages *dpages);
7346 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7347 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7348 + au_dpages_test test, void *arg);
7349 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7350 + int do_include, au_dpages_test test, void *arg);
7351 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7352 + struct dentry *dentry, int do_include);
7353 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7355 +/* ---------------------------------------------------------------------- */
7358 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7359 + * include/linux/dcache.h. Try them (in the future).
7362 +static inline int au_d_hashed_positive(struct dentry *d)
7365 + struct inode *inode = d_inode(d);
7368 + if (unlikely(d_unhashed(d)
7369 + || d_is_negative(d)
7370 + || !inode->i_nlink))
7375 +static inline int au_d_linkable(struct dentry *d)
7378 + struct inode *inode = d_inode(d);
7380 + err = au_d_hashed_positive(d);
7382 + && d_is_positive(d)
7383 + && (inode->i_state & I_LINKABLE))
7388 +static inline int au_d_alive(struct dentry *d)
7391 + struct inode *inode;
7395 + err = au_d_hashed_positive(d);
7397 + inode = d_inode(d);
7398 + if (unlikely(d_unlinked(d)
7399 + || d_is_negative(d)
7400 + || !inode->i_nlink))
7406 +static inline int au_alive_dir(struct dentry *d)
7410 + err = au_d_alive(d);
7411 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7416 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7418 + return a->len == b->len
7419 + && !memcmp(a->name, b->name, a->len);
7424 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7426 + * the type of d_lockref.count became int, but the inlined function d_count()
7427 + * still returns unsigned int.
7428 + * I don't know why. Maybe it is for every d_count() users?
7429 + * Anyway au_dcount() lives on.
7431 +static inline int au_dcount(struct dentry *d)
7433 + return (int)d_count(d);
7436 +#endif /* __KERNEL__ */
7437 +#endif /* __AUFS_DCSUB_H__ */
7438 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7439 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 08:00:00.000000000 +0800
7440 +++ linux/fs/aufs/debug.c 2019-07-11 21:21:54.379051070 +0800
7442 +// SPDX-License-Identifier: GPL-2.0
7444 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7446 + * This program, aufs is free software; you can redistribute it and/or modify
7447 + * it under the terms of the GNU General Public License as published by
7448 + * the Free Software Foundation; either version 2 of the License, or
7449 + * (at your option) any later version.
7451 + * This program is distributed in the hope that it will be useful,
7452 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7453 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7454 + * GNU General Public License for more details.
7456 + * You should have received a copy of the GNU General Public License
7457 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7461 + * debug print functions
7464 +#include <linux/iversion.h>
7467 +/* Returns 0, or -errno. arg is in kp->arg. */
7468 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7472 + err = kstrtoint(val, 0, &n);
7482 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7483 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7488 + return sprintf(buffer, "%d", atomic_read(a));
7491 +static struct kernel_param_ops param_ops_atomic_t = {
7492 + .set = param_atomic_t_set,
7493 + .get = param_atomic_t_get
7494 + /* void (*free)(void *arg) */
7497 +atomic_t aufs_debug = ATOMIC_INIT(0);
7498 +MODULE_PARM_DESC(debug, "debug print");
7499 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7501 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7502 +char *au_plevel = KERN_DEBUG;
7503 +#define dpri(fmt, ...) do { \
7505 + && strcmp(au_plevel, KERN_DEBUG)) \
7506 + || au_debug_test()) \
7507 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7510 +/* ---------------------------------------------------------------------- */
7512 +void au_dpri_whlist(struct au_nhash *whlist)
7514 + unsigned long ul, n;
7515 + struct hlist_head *head;
7516 + struct au_vdir_wh *pos;
7518 + n = whlist->nh_num;
7519 + head = whlist->nh_head;
7520 + for (ul = 0; ul < n; ul++) {
7521 + hlist_for_each_entry(pos, head, wh_hash)
7522 + dpri("b%d, %.*s, %d\n",
7524 + pos->wh_str.len, pos->wh_str.name,
7530 +void au_dpri_vdir(struct au_vdir *vdir)
7533 + union au_vdir_deblk_p p;
7536 + if (!vdir || IS_ERR(vdir)) {
7537 + dpri("err %ld\n", PTR_ERR(vdir));
7541 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7542 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7543 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7544 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7545 + p.deblk = vdir->vd_deblk[ul];
7547 + dpri("[%lu]: %p\n", ul, o);
7551 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7552 + struct dentry *wh)
7557 + if (!inode || IS_ERR(inode)) {
7558 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7562 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7563 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7564 + && sizeof(inode->i_blocks) != sizeof(u64));
7566 + n = (void *)wh->d_name.name;
7567 + l = wh->d_name.len;
7570 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7571 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7573 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7574 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7575 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7576 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7577 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7578 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7579 + inode->i_generation,
7580 + l ? ", wh " : "", l, n);
7584 +void au_dpri_inode(struct inode *inode)
7586 + struct au_iinfo *iinfo;
7587 + struct au_hinode *hi;
7588 + aufs_bindex_t bindex;
7591 + err = do_pri_inode(-1, inode, -1, NULL);
7592 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7595 + iinfo = au_ii(inode);
7596 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7597 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7598 + if (iinfo->ii_btop < 0)
7601 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7602 + hi = au_hinode(iinfo, bindex);
7604 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7608 +void au_dpri_dalias(struct inode *inode)
7612 + spin_lock(&inode->i_lock);
7613 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7614 + au_dpri_dentry(d);
7615 + spin_unlock(&inode->i_lock);
7618 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7620 + struct dentry *wh = NULL;
7622 + struct inode *inode;
7623 + struct au_iinfo *iinfo;
7624 + struct au_hinode *hi;
7626 + if (!dentry || IS_ERR(dentry)) {
7627 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7630 + /* do not call dget_parent() here */
7631 + /* note: access d_xxx without d_lock */
7632 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7633 + bindex, dentry, dentry,
7634 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7635 + au_dcount(dentry), dentry->d_flags,
7636 + d_unhashed(dentry) ? "un" : "");
7639 + if (d_is_positive(dentry))
7640 + inode = d_inode(dentry);
7642 + && au_test_aufs(dentry->d_sb)
7644 + && !au_is_bad_inode(inode)) {
7645 + iinfo = au_ii(inode);
7646 + hi = au_hinode(iinfo, bindex);
7648 + wh = hi->hi_whdentry;
7650 + do_pri_inode(bindex, inode, hn, wh);
7654 +void au_dpri_dentry(struct dentry *dentry)
7656 + struct au_dinfo *dinfo;
7657 + aufs_bindex_t bindex;
7660 + err = do_pri_dentry(-1, dentry);
7661 + if (err || !au_test_aufs(dentry->d_sb))
7664 + dinfo = au_di(dentry);
7667 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7668 + dinfo->di_btop, dinfo->di_bbot,
7669 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7670 + dinfo->di_tmpfile);
7671 + if (dinfo->di_btop < 0)
7673 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7674 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7677 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7681 + if (!file || IS_ERR(file)) {
7682 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7687 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7688 + && au_test_aufs(file->f_path.dentry->d_sb)
7690 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7691 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7692 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7693 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7694 + file->f_version, file->f_pos, a);
7695 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7696 + do_pri_dentry(bindex, file->f_path.dentry);
7700 +void au_dpri_file(struct file *file)
7702 + struct au_finfo *finfo;
7703 + struct au_fidir *fidir;
7704 + struct au_hfile *hfile;
7705 + aufs_bindex_t bindex;
7708 + err = do_pri_file(-1, file);
7710 + || IS_ERR_OR_NULL(file->f_path.dentry)
7711 + || !au_test_aufs(file->f_path.dentry->d_sb))
7714 + finfo = au_fi(file);
7717 + if (finfo->fi_btop < 0)
7719 + fidir = finfo->fi_hdir;
7721 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7723 + for (bindex = finfo->fi_btop;
7724 + bindex >= 0 && bindex <= fidir->fd_bbot;
7726 + hfile = fidir->fd_hfile + bindex;
7727 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7731 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7733 + struct vfsmount *mnt;
7734 + struct super_block *sb;
7736 + if (!br || IS_ERR(br))
7738 + mnt = au_br_mnt(br);
7739 + if (!mnt || IS_ERR(mnt))
7742 + if (!sb || IS_ERR(sb))
7745 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7746 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7748 + bindex, br->br_perm, br->br_id, br->br_wbr,
7749 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7750 + sb->s_flags, sb->s_count,
7751 + atomic_read(&sb->s_active),
7752 + !!au_xino_file(br->br_xino, /*idx*/-1));
7756 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7760 +void au_dpri_sb(struct super_block *sb)
7762 + struct au_sbinfo *sbinfo;
7763 + aufs_bindex_t bindex;
7765 + /* to reduce stack size */
7767 + struct vfsmount mnt;
7768 + struct au_branch fake;
7771 + /* this function can be called from magic sysrq */
7772 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7773 + if (unlikely(!a)) {
7774 + dpri("no memory\n");
7778 + a->mnt.mnt_sb = sb;
7779 + a->fake.br_path.mnt = &a->mnt;
7780 + err = do_pri_br(-1, &a->fake);
7782 + dpri("dev 0x%x\n", sb->s_dev);
7783 + if (err || !au_test_aufs(sb))
7786 + sbinfo = au_sbi(sb);
7789 + dpri("nw %d, gen %u, kobj %d\n",
7790 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7791 + kref_read(&sbinfo->si_kobj.kref));
7792 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7793 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7796 +/* ---------------------------------------------------------------------- */
7798 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7800 + struct inode *h_inode, *inode = d_inode(dentry);
7801 + struct dentry *h_dentry;
7802 + aufs_bindex_t bindex, bbot, bi;
7804 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7807 + bbot = au_dbbot(dentry);
7808 + bi = au_ibbot(inode);
7811 + bindex = au_dbtop(dentry);
7812 + bi = au_ibtop(inode);
7816 + for (; bindex <= bbot; bindex++) {
7817 + h_dentry = au_h_dptr(dentry, bindex);
7820 + h_inode = au_h_iptr(inode, bindex);
7821 + if (unlikely(h_inode != d_inode(h_dentry))) {
7823 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7824 + AuDbgDentry(dentry);
7825 + AuDbgInode(inode);
7832 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7835 + struct au_dcsub_pages dpages;
7836 + struct au_dpage *dpage;
7837 + struct dentry **dentries;
7839 + err = au_dpages_init(&dpages, GFP_NOFS);
7841 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7843 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7844 + dpage = dpages.dpages + i;
7845 + dentries = dpage->dentries;
7846 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7847 + AuDebugOn(au_digen_test(dentries[j], sigen));
7849 + au_dpages_free(&dpages);
7852 +void au_dbg_verify_kthread(void)
7854 + if (au_wkq_test()) {
7857 + * It may be recursive, but udba=notify between two aufs mounts,
7858 + * where a single ro branch is shared, is not a problem.
7864 +/* ---------------------------------------------------------------------- */
7866 +int __init au_debug_init(void)
7868 + aufs_bindex_t bindex;
7869 + struct au_vdir_destr destr;
7872 + AuDebugOn(bindex >= 0);
7875 + AuDebugOn(destr.len < NAME_MAX);
7877 +#ifdef CONFIG_4KSTACKS
7878 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7883 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7884 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 08:00:00.000000000 +0800
7885 +++ linux/fs/aufs/debug.h 2019-07-11 21:21:54.379051070 +0800
7887 +/* SPDX-License-Identifier: GPL-2.0 */
7889 + * Copyright (C) 2005-2019 Junjiro R. Okajima
7891 + * This program, aufs is free software; you can redistribute it and/or modify
7892 + * it under the terms of the GNU General Public License as published by
7893 + * the Free Software Foundation; either version 2 of the License, or
7894 + * (at your option) any later version.
7896 + * This program is distributed in the hope that it will be useful,
7897 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7898 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7899 + * GNU General Public License for more details.
7901 + * You should have received a copy of the GNU General Public License
7902 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7906 + * debug print functions
7909 +#ifndef __AUFS_DEBUG_H__
7910 +#define __AUFS_DEBUG_H__
7914 +#include <linux/atomic.h>
7915 +#include <linux/module.h>
7916 +#include <linux/kallsyms.h>
7917 +#include <linux/sysrq.h>
7919 +#ifdef CONFIG_AUFS_DEBUG
7920 +#define AuDebugOn(a) BUG_ON(a)
7922 +/* module parameter */
7923 +extern atomic_t aufs_debug;
7924 +static inline void au_debug_on(void)
7926 + atomic_inc(&aufs_debug);
7928 +static inline void au_debug_off(void)
7930 + atomic_dec_if_positive(&aufs_debug);
7933 +static inline int au_debug_test(void)
7935 + return atomic_read(&aufs_debug) > 0;
7938 +#define AuDebugOn(a) do {} while (0)
7939 +AuStubVoid(au_debug_on, void)
7940 +AuStubVoid(au_debug_off, void)
7941 +AuStubInt0(au_debug_test, void)
7942 +#endif /* CONFIG_AUFS_DEBUG */
7944 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7946 +/* ---------------------------------------------------------------------- */
7950 +#define AuDbg(fmt, ...) do { \
7951 + if (au_debug_test()) \
7952 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7954 +#define AuLabel(l) AuDbg(#l "\n")
7955 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7956 +#define AuWarn1(fmt, ...) do { \
7957 + static unsigned char _c; \
7959 + pr_warn(fmt, ##__VA_ARGS__); \
7962 +#define AuErr1(fmt, ...) do { \
7963 + static unsigned char _c; \
7965 + pr_err(fmt, ##__VA_ARGS__); \
7968 +#define AuIOErr1(fmt, ...) do { \
7969 + static unsigned char _c; \
7971 + AuIOErr(fmt, ##__VA_ARGS__); \
7974 +#define AuUnsupportMsg "This operation is not supported." \
7975 + " Please report this application to aufs-users ML."
7976 +#define AuUnsupport(fmt, ...) do { \
7977 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7981 +#define AuTraceErr(e) do { \
7982 + if (unlikely((e) < 0)) \
7983 + AuDbg("err %d\n", (int)(e)); \
7986 +#define AuTraceErrPtr(p) do { \
7988 + AuDbg("err %ld\n", PTR_ERR(p)); \
7991 +/* dirty macros for debug print, use with "%.*s" and caution */
7992 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7994 +/* ---------------------------------------------------------------------- */
7997 +#ifdef CONFIG_AUFS_DEBUG
7998 +extern struct mutex au_dbg_mtx;
7999 +extern char *au_plevel;
8001 +void au_dpri_whlist(struct au_nhash *whlist);
8003 +void au_dpri_vdir(struct au_vdir *vdir);
8005 +void au_dpri_inode(struct inode *inode);
8006 +void au_dpri_dalias(struct inode *inode);
8007 +void au_dpri_dentry(struct dentry *dentry);
8009 +void au_dpri_file(struct file *filp);
8010 +struct super_block;
8011 +void au_dpri_sb(struct super_block *sb);
8013 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8014 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8015 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8016 +void au_dbg_verify_kthread(void);
8018 +int __init au_debug_init(void);
8020 +#define AuDbgWhlist(w) do { \
8021 + mutex_lock(&au_dbg_mtx); \
8023 + au_dpri_whlist(w); \
8024 + mutex_unlock(&au_dbg_mtx); \
8027 +#define AuDbgVdir(v) do { \
8028 + mutex_lock(&au_dbg_mtx); \
8030 + au_dpri_vdir(v); \
8031 + mutex_unlock(&au_dbg_mtx); \
8034 +#define AuDbgInode(i) do { \
8035 + mutex_lock(&au_dbg_mtx); \
8037 + au_dpri_inode(i); \
8038 + mutex_unlock(&au_dbg_mtx); \
8041 +#define AuDbgDAlias(i) do { \
8042 + mutex_lock(&au_dbg_mtx); \
8044 + au_dpri_dalias(i); \
8045 + mutex_unlock(&au_dbg_mtx); \
8048 +#define AuDbgDentry(d) do { \
8049 + mutex_lock(&au_dbg_mtx); \
8051 + au_dpri_dentry(d); \
8052 + mutex_unlock(&au_dbg_mtx); \
8055 +#define AuDbgFile(f) do { \
8056 + mutex_lock(&au_dbg_mtx); \
8058 + au_dpri_file(f); \
8059 + mutex_unlock(&au_dbg_mtx); \
8062 +#define AuDbgSb(sb) do { \
8063 + mutex_lock(&au_dbg_mtx); \
8064 + AuDbg(#sb "\n"); \
8066 + mutex_unlock(&au_dbg_mtx); \
8069 +#define AuDbgSym(addr) do { \
8070 + char sym[KSYM_SYMBOL_LEN]; \
8071 + sprint_symbol(sym, (unsigned long)addr); \
8072 + AuDbg("%s\n", sym); \
8075 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8076 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8077 +AuStubVoid(au_dbg_verify_kthread, void)
8078 +AuStubInt0(__init au_debug_init, void)
8080 +#define AuDbgWhlist(w) do {} while (0)
8081 +#define AuDbgVdir(v) do {} while (0)
8082 +#define AuDbgInode(i) do {} while (0)
8083 +#define AuDbgDAlias(i) do {} while (0)
8084 +#define AuDbgDentry(d) do {} while (0)
8085 +#define AuDbgFile(f) do {} while (0)
8086 +#define AuDbgSb(sb) do {} while (0)
8087 +#define AuDbgSym(addr) do {} while (0)
8088 +#endif /* CONFIG_AUFS_DEBUG */
8090 +/* ---------------------------------------------------------------------- */
8092 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8093 +int __init au_sysrq_init(void);
8094 +void au_sysrq_fin(void);
8096 +#ifdef CONFIG_HW_CONSOLE
8097 +#define au_dbg_blocked() do { \
8099 + handle_sysrq('w'); \
8102 +AuStubVoid(au_dbg_blocked, void)
8106 +AuStubInt0(__init au_sysrq_init, void)
8107 +AuStubVoid(au_sysrq_fin, void)
8108 +AuStubVoid(au_dbg_blocked, void)
8109 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8111 +#endif /* __KERNEL__ */
8112 +#endif /* __AUFS_DEBUG_H__ */
8113 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8114 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 08:00:00.000000000 +0800
8115 +++ linux/fs/aufs/dentry.c 2019-07-11 21:21:54.379051070 +0800
8117 +// SPDX-License-Identifier: GPL-2.0
8119 + * Copyright (C) 2005-2019 Junjiro R. Okajima
8121 + * This program, aufs is free software; you can redistribute it and/or modify
8122 + * it under the terms of the GNU General Public License as published by
8123 + * the Free Software Foundation; either version 2 of the License, or
8124 + * (at your option) any later version.
8126 + * This program is distributed in the hope that it will be useful,
8127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8129 + * GNU General Public License for more details.
8131 + * You should have received a copy of the GNU General Public License
8132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8136 + * lookup and dentry operations
8139 +#include <linux/iversion.h>
8140 +#include <linux/namei.h>
8144 + * returns positive/negative dentry, NULL or an error.
8145 + * NULL means whiteout-ed or not-found.
8147 +static struct dentry*
8148 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8149 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8151 + struct dentry *h_dentry;
8152 + struct inode *h_inode;
8153 + struct au_branch *br;
8154 + int wh_found, opq;
8155 + unsigned char wh_able;
8156 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8157 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8161 + br = au_sbr(dentry->d_sb, bindex);
8162 + wh_able = !!au_br_whable(br->br_perm);
8164 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8165 + h_dentry = ERR_PTR(wh_found);
8168 + if (unlikely(wh_found < 0))
8171 + /* We found a whiteout */
8172 + /* au_set_dbbot(dentry, bindex); */
8173 + au_set_dbwh(dentry, bindex);
8175 + return NULL; /* success */
8179 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8181 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8182 + if (IS_ERR(h_dentry)) {
8183 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8189 + h_inode = d_inode(h_dentry);
8190 + if (d_is_negative(h_dentry)) {
8193 + } else if (wh_found
8194 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8196 + else if (au_ftest_lkup(args->flags, DIRREN)
8198 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8199 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8200 + (unsigned long long)h_inode->i_ino);
8204 + if (au_dbbot(dentry) <= bindex)
8205 + au_set_dbbot(dentry, bindex);
8206 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8207 + au_set_dbtop(dentry, bindex);
8208 + au_set_h_dptr(dentry, bindex, h_dentry);
8210 + if (!d_is_dir(h_dentry)
8212 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8213 + goto out; /* success */
8215 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8216 + opq = au_diropq_test(h_dentry);
8217 + inode_unlock_shared(h_inode);
8219 + au_set_dbdiropq(dentry, bindex);
8220 + else if (unlikely(opq < 0)) {
8221 + au_set_h_dptr(dentry, bindex, NULL);
8222 + h_dentry = ERR_PTR(opq);
8233 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8235 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8236 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8242 + * returns the number of lower positive dentries,
8243 + * otherwise an error.
8244 + * can be called at unlinking with @type is zero.
8246 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8247 + unsigned int flags)
8249 + int npositive, err;
8250 + aufs_bindex_t bindex, btail, bdiropq;
8251 + unsigned char isdir, dirperm1, dirren;
8252 + struct au_do_lookup_args args = {
8254 + .name = &dentry->d_name
8256 + struct dentry *parent;
8257 + struct super_block *sb;
8259 + sb = dentry->d_sb;
8260 + err = au_test_shwh(sb, args.name);
8261 + if (unlikely(err))
8264 + err = au_wh_name_alloc(&args.whname, args.name);
8265 + if (unlikely(err))
8268 + isdir = !!d_is_dir(dentry);
8269 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8270 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8272 + au_fset_lkup(args.flags, DIRREN);
8275 + parent = dget_parent(dentry);
8276 + btail = au_dbtaildir(parent);
8277 + for (bindex = btop; bindex <= btail; bindex++) {
8278 + struct dentry *h_parent, *h_dentry;
8279 + struct inode *h_inode, *h_dir;
8280 + struct au_branch *br;
8282 + h_dentry = au_h_dptr(dentry, bindex);
8284 + if (d_is_positive(h_dentry))
8288 + h_parent = au_h_dptr(parent, bindex);
8289 + if (!h_parent || !d_is_dir(h_parent))
8293 + /* if the inum matches, then use the prepared name */
8294 + err = au_dr_lkup_name(&args, bindex);
8295 + if (unlikely(err))
8299 + h_dir = d_inode(h_parent);
8300 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8301 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8302 + inode_unlock_shared(h_dir);
8303 + err = PTR_ERR(h_dentry);
8304 + if (IS_ERR(h_dentry))
8307 + au_fclr_lkup(args.flags, ALLOW_NEG);
8309 + au_fset_lkup(args.flags, IGNORE_PERM);
8311 + if (au_dbwh(dentry) == bindex)
8315 + if (d_is_negative(h_dentry))
8317 + h_inode = d_inode(h_dentry);
8320 + args.type = h_inode->i_mode & S_IFMT;
8321 + if (args.type != S_IFDIR)
8324 + /* the type of lower may be different */
8325 + bdiropq = au_dbdiropq(dentry);
8326 + if (bdiropq >= 0 && bdiropq <= bindex)
8329 + br = au_sbr(sb, bindex);
8331 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8332 + /*add_ent*/NULL)) {
8333 + /* prepare next name to lookup */
8334 + err = au_dr_lkup(&args, dentry, bindex);
8335 + if (unlikely(err))
8341 + AuLabel(positive);
8342 + au_update_dbtop(dentry);
8345 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8346 + && au_dbtop(dentry) < 0)) {
8348 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8354 + au_kfree_try_rcu(args.whname.name);
8356 + au_dr_lkup_fin(&args);
8361 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8363 + struct dentry *dentry;
8366 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8367 + dentry = vfsub_lkup_one(name, parent);
8369 + struct vfsub_lkup_one_args args = {
8375 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8376 + if (unlikely(wkq_err))
8377 + dentry = ERR_PTR(wkq_err);
8384 + * lookup @dentry on @bindex which should be negative.
8386 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8389 + struct dentry *parent, *h_parent, *h_dentry;
8390 + struct au_branch *br;
8392 + parent = dget_parent(dentry);
8393 + h_parent = au_h_dptr(parent, bindex);
8394 + br = au_sbr(dentry->d_sb, bindex);
8396 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8398 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8399 + err = PTR_ERR(h_dentry);
8400 + if (IS_ERR(h_dentry))
8402 + if (unlikely(d_is_positive(h_dentry))) {
8404 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8410 + if (bindex < au_dbtop(dentry))
8411 + au_set_dbtop(dentry, bindex);
8412 + if (au_dbbot(dentry) < bindex)
8413 + au_set_dbbot(dentry, bindex);
8414 + au_set_h_dptr(dentry, bindex, h_dentry);
8421 +/* ---------------------------------------------------------------------- */
8423 +/* subset of struct inode */
8425 + unsigned long i_ino;
8426 + /* unsigned int i_nlink; */
8432 + blkcnt_t i_blocks;
8437 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8439 + ia->i_ino = h_inode->i_ino;
8440 + /* ia->i_nlink = h_inode->i_nlink; */
8441 + ia->i_uid = h_inode->i_uid;
8442 + ia->i_gid = h_inode->i_gid;
8443 + ia->i_version = inode_query_iversion(h_inode);
8445 + ia->i_size = h_inode->i_size;
8446 + ia->i_blocks = h_inode->i_blocks;
8448 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8451 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8453 + return ia->i_ino != h_inode->i_ino
8454 + /* || ia->i_nlink != h_inode->i_nlink */
8455 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8456 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8457 + || !inode_eq_iversion(h_inode, ia->i_version)
8459 + || ia->i_size != h_inode->i_size
8460 + || ia->i_blocks != h_inode->i_blocks
8462 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8465 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8466 + struct au_branch *br)
8469 + struct au_iattr ia;
8470 + struct inode *h_inode;
8471 + struct dentry *h_d;
8472 + struct super_block *h_sb;
8475 + memset(&ia, -1, sizeof(ia));
8476 + h_sb = h_dentry->d_sb;
8478 + if (d_is_positive(h_dentry)) {
8479 + h_inode = d_inode(h_dentry);
8480 + au_iattr_save(&ia, h_inode);
8481 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8482 + /* nfs d_revalidate may return 0 for negative dentry */
8483 + /* fuse d_revalidate always return 0 for negative dentry */
8486 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8487 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8488 + err = PTR_ERR(h_d);
8493 + if (unlikely(h_d != h_dentry
8494 + || d_inode(h_d) != h_inode
8495 + || (h_inode && au_iattr_test(&ia, h_inode))))
8496 + err = au_busy_or_stale();
8504 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8505 + struct dentry *h_parent, struct au_branch *br)
8510 + if (udba == AuOpt_UDBA_REVAL
8511 + && !au_test_fs_remote(h_dentry->d_sb)) {
8513 + err = (d_inode(h_dentry->d_parent) != h_dir);
8514 + } else if (udba != AuOpt_UDBA_NONE)
8515 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8520 +/* ---------------------------------------------------------------------- */
8522 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8525 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8526 + struct au_hdentry tmp, *p, *q;
8527 + struct au_dinfo *dinfo;
8528 + struct super_block *sb;
8530 + DiMustWriteLock(dentry);
8532 + sb = dentry->d_sb;
8533 + dinfo = au_di(dentry);
8534 + bbot = dinfo->di_bbot;
8535 + bwh = dinfo->di_bwh;
8536 + bdiropq = dinfo->di_bdiropq;
8537 + bindex = dinfo->di_btop;
8538 + p = au_hdentry(dinfo, bindex);
8539 + for (; bindex <= bbot; bindex++, p++) {
8540 + if (!p->hd_dentry)
8543 + new_bindex = au_br_index(sb, p->hd_id);
8544 + if (new_bindex == bindex)
8547 + if (dinfo->di_bwh == bindex)
8549 + if (dinfo->di_bdiropq == bindex)
8550 + bdiropq = new_bindex;
8551 + if (new_bindex < 0) {
8553 + p->hd_dentry = NULL;
8557 + /* swap two lower dentries, and loop again */
8558 + q = au_hdentry(dinfo, new_bindex);
8562 + if (tmp.hd_dentry) {
8568 + dinfo->di_bwh = -1;
8569 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8570 + dinfo->di_bwh = bwh;
8572 + dinfo->di_bdiropq = -1;
8574 + && bdiropq <= au_sbbot(sb)
8575 + && au_sbr_whable(sb, bdiropq))
8576 + dinfo->di_bdiropq = bdiropq;
8579 + dinfo->di_btop = -1;
8580 + dinfo->di_bbot = -1;
8581 + bbot = au_dbbot(parent);
8583 + p = au_hdentry(dinfo, bindex);
8584 + for (; bindex <= bbot; bindex++, p++)
8585 + if (p->hd_dentry) {
8586 + dinfo->di_btop = bindex;
8590 + if (dinfo->di_btop >= 0) {
8592 + p = au_hdentry(dinfo, bindex);
8593 + for (; bindex >= 0; bindex--, p--)
8594 + if (p->hd_dentry) {
8595 + dinfo->di_bbot = bindex;
8604 +static void au_do_hide(struct dentry *dentry)
8606 + struct inode *inode;
8608 + if (d_really_is_positive(dentry)) {
8609 + inode = d_inode(dentry);
8610 + if (!d_is_dir(dentry)) {
8611 + if (inode->i_nlink && !d_unhashed(dentry))
8612 + drop_nlink(inode);
8614 + clear_nlink(inode);
8615 + /* stop next lookup */
8616 + inode->i_flags |= S_DEAD;
8618 + smp_mb(); /* necessary? */
8623 +static int au_hide_children(struct dentry *parent)
8625 + int err, i, j, ndentry;
8626 + struct au_dcsub_pages dpages;
8627 + struct au_dpage *dpage;
8628 + struct dentry *dentry;
8630 + err = au_dpages_init(&dpages, GFP_NOFS);
8631 + if (unlikely(err))
8633 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8634 + if (unlikely(err))
8637 + /* in reverse order */
8638 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8639 + dpage = dpages.dpages + i;
8640 + ndentry = dpage->ndentry;
8641 + for (j = ndentry - 1; j >= 0; j--) {
8642 + dentry = dpage->dentries[j];
8643 + if (dentry != parent)
8644 + au_do_hide(dentry);
8649 + au_dpages_free(&dpages);
8654 +static void au_hide(struct dentry *dentry)
8658 + AuDbgDentry(dentry);
8659 + if (d_is_dir(dentry)) {
8660 + /* shrink_dcache_parent(dentry); */
8661 + err = au_hide_children(dentry);
8662 + if (unlikely(err))
8663 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8666 + au_do_hide(dentry);
8670 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8672 + * a dirty branch is added
8673 + * - on the top of layers
8674 + * - in the middle of layers
8675 + * - to the bottom of layers
8677 + * on the added branch there exists
8680 + * - a same named entry
8682 + * * negative --> positive
8683 + * * positive --> positive
8684 + * - type is unchanged
8685 + * - type is changed
8687 + * * negative --> negative
8688 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8691 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8692 + struct au_dinfo *tmp)
8695 + aufs_bindex_t bindex, bbot;
8697 + struct dentry *dentry;
8698 + struct inode *inode;
8700 + } orig_h, tmp_h = {
8703 + struct au_hdentry *hd;
8704 + struct inode *inode, *h_inode;
8705 + struct dentry *h_dentry;
8708 + AuDebugOn(dinfo->di_btop < 0);
8710 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8711 + orig_h.inode = NULL;
8712 + if (d_is_positive(orig_h.dentry)) {
8713 + orig_h.inode = d_inode(orig_h.dentry);
8714 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8716 + if (tmp->di_btop >= 0) {
8717 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8718 + if (d_is_positive(tmp_h.dentry)) {
8719 + tmp_h.inode = d_inode(tmp_h.dentry);
8720 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8725 + if (d_really_is_positive(dentry))
8726 + inode = d_inode(dentry);
8727 + if (!orig_h.inode) {
8728 + AuDbg("negative originally\n");
8734 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8735 + AuDebugOn(dinfo->di_bdiropq != -1);
8737 + if (!tmp_h.inode) {
8738 + AuDbg("negative --> negative\n");
8739 + /* should have only one negative lower */
8740 + if (tmp->di_btop >= 0
8741 + && tmp->di_btop < dinfo->di_btop) {
8742 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8743 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8744 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8745 + au_di_cp(dinfo, tmp);
8746 + hd = au_hdentry(tmp, tmp->di_btop);
8747 + au_set_h_dptr(dentry, tmp->di_btop,
8748 + dget(hd->hd_dentry));
8750 + au_dbg_verify_dinode(dentry);
8752 + AuDbg("negative --> positive\n");
8754 + * similar to the behaviour of creating with bypassing
8756 + * unhash it in order to force an error in the
8757 + * succeeding create operation.
8758 + * we should not set S_DEAD here.
8761 + /* au_di_swap(tmp, dinfo); */
8762 + au_dbg_verify_dinode(dentry);
8765 + AuDbg("positive originally\n");
8766 + /* inode may be NULL */
8767 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8768 + if (!tmp_h.inode) {
8769 + AuDbg("positive --> negative\n");
8770 + /* or bypassing aufs */
8772 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8773 + dinfo->di_bwh = tmp->di_bwh;
8775 + err = au_refresh_hinode_self(inode);
8776 + au_dbg_verify_dinode(dentry);
8777 + } else if (orig_h.mode == tmp_h.mode) {
8778 + AuDbg("positive --> positive, same type\n");
8779 + if (!S_ISDIR(orig_h.mode)
8780 + && dinfo->di_btop > tmp->di_btop) {
8782 + * similar to the behaviour of removing and
8787 + err = au_refresh_hinode_self(inode);
8788 + au_dbg_verify_dinode(dentry);
8790 + /* fill empty slots */
8791 + if (dinfo->di_btop > tmp->di_btop)
8792 + dinfo->di_btop = tmp->di_btop;
8793 + if (dinfo->di_bbot < tmp->di_bbot)
8794 + dinfo->di_bbot = tmp->di_bbot;
8795 + dinfo->di_bwh = tmp->di_bwh;
8796 + dinfo->di_bdiropq = tmp->di_bdiropq;
8797 + bbot = dinfo->di_bbot;
8798 + bindex = tmp->di_btop;
8799 + hd = au_hdentry(tmp, bindex);
8800 + for (; bindex <= bbot; bindex++, hd++) {
8801 + if (au_h_dptr(dentry, bindex))
8803 + h_dentry = hd->hd_dentry;
8806 + AuDebugOn(d_is_negative(h_dentry));
8807 + h_inode = d_inode(h_dentry);
8808 + AuDebugOn(orig_h.mode
8809 + != (h_inode->i_mode
8811 + au_set_h_dptr(dentry, bindex,
8815 + err = au_refresh_hinode(inode, dentry);
8816 + au_dbg_verify_dinode(dentry);
8819 + AuDbg("positive --> positive, different type\n");
8820 + /* similar to the behaviour of removing and creating */
8823 + err = au_refresh_hinode_self(inode);
8824 + au_dbg_verify_dinode(dentry);
8832 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8834 + const struct dentry_operations *dop
8835 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8836 + static const unsigned int mask
8837 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8839 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8841 + if (dentry->d_op == dop)
8844 + AuDbg("%pd\n", dentry);
8845 + spin_lock(&dentry->d_lock);
8846 + if (dop == &aufs_dop)
8847 + dentry->d_flags |= mask;
8849 + dentry->d_flags &= ~mask;
8850 + dentry->d_op = dop;
8851 + spin_unlock(&dentry->d_lock);
8854 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8856 + int err, ebrange, nbr;
8857 + unsigned int sigen;
8858 + struct au_dinfo *dinfo, *tmp;
8859 + struct super_block *sb;
8860 + struct inode *inode;
8862 + DiMustWriteLock(dentry);
8863 + AuDebugOn(IS_ROOT(dentry));
8864 + AuDebugOn(d_really_is_negative(parent));
8866 + sb = dentry->d_sb;
8867 + sigen = au_sigen(sb);
8868 + err = au_digen_test(parent, sigen);
8869 + if (unlikely(err))
8872 + nbr = au_sbbot(sb) + 1;
8873 + dinfo = au_di(dentry);
8874 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8875 + if (unlikely(err))
8877 + ebrange = au_dbrange_test(dentry);
8879 + ebrange = au_do_refresh_hdentry(dentry, parent);
8881 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8882 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8883 + if (d_really_is_positive(dentry)) {
8884 + inode = d_inode(dentry);
8885 + err = au_refresh_hinode_self(inode);
8887 + au_dbg_verify_dinode(dentry);
8889 + goto out_dgen; /* success */
8893 + /* temporary dinfo */
8894 + AuDbgDentry(dentry);
8896 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8897 + if (unlikely(!tmp))
8899 + au_di_swap(tmp, dinfo);
8900 + /* returns the number of positive dentries */
8902 + * if current working dir is removed, it returns an error.
8903 + * but the dentry is legal.
8905 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8906 + AuDbgDentry(dentry);
8907 + au_di_swap(tmp, dinfo);
8908 + if (err == -ENOENT)
8911 + /* compare/refresh by dinfo */
8912 + AuDbgDentry(dentry);
8913 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8914 + au_dbg_verify_dinode(dentry);
8917 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8918 + au_rw_write_unlock(&tmp->di_rwsem);
8920 + if (unlikely(err))
8924 + au_update_digen(dentry);
8926 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8927 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8928 + AuDbgDentry(dentry);
8934 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8935 + struct dentry *dentry, aufs_bindex_t bindex)
8940 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8943 + AuDbg("b%d\n", bindex);
8945 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8946 + * due to whiteout and branch permission.
8948 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8949 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8950 + /* it may return tri-state */
8951 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8953 + if (unlikely(valid < 0))
8963 +/* todo: remove this */
8964 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8965 + unsigned int flags, int do_udba, int dirren)
8968 + umode_t mode, h_mode;
8969 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8970 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8971 + struct inode *h_inode, *h_cached_inode;
8972 + struct dentry *h_dentry;
8973 + struct qstr *name, *h_name;
8980 + unhashed = !!d_unhashed(dentry);
8981 + is_root = !!IS_ROOT(dentry);
8982 + name = &dentry->d_name;
8983 + tmpfile = au_di(dentry)->di_tmpfile;
8986 + * Theoretically, REVAL test should be unnecessary in case of
8988 + * But {fs,i}notify doesn't fire some necessary events,
8989 + * IN_ATTRIB for atime/nlink/pageio
8990 + * Let's do REVAL test too.
8992 + if (do_udba && inode) {
8993 + mode = (inode->i_mode & S_IFMT);
8994 + plus = (inode->i_nlink > 0);
8995 + ibs = au_ibtop(inode);
8996 + ibe = au_ibbot(inode);
8999 + btop = au_dbtop(dentry);
9001 + if (inode && S_ISDIR(inode->i_mode))
9002 + btail = au_dbtaildir(dentry);
9003 + for (bindex = btop; bindex <= btail; bindex++) {
9004 + h_dentry = au_h_dptr(dentry, bindex);
9008 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9009 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9010 + spin_lock(&h_dentry->d_lock);
9011 + h_name = &h_dentry->d_name;
9012 + if (unlikely(do_udba
9015 + && (unhashed != !!d_unhashed(h_dentry)
9016 + || (!tmpfile && !dirren
9017 + && !au_qstreq(name, h_name))
9020 + && !(flags & LOOKUP_OPEN)
9021 + && (h_dentry->d_flags
9022 + & DCACHE_NFSFS_RENAMED)))
9026 + h_unhashed = d_unhashed(h_dentry);
9027 + spin_unlock(&h_dentry->d_lock);
9028 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9029 + unhashed, h_unhashed, dentry, h_dentry);
9032 + spin_unlock(&h_dentry->d_lock);
9034 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9035 + if (unlikely(err))
9036 + /* do not goto err, to keep the errno */
9039 + /* todo: plink too? */
9044 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9048 + if (d_is_positive(h_dentry))
9049 + h_inode = d_inode(h_dentry);
9052 + h_cached_inode = h_inode;
9054 + h_mode = (h_inode->i_mode & S_IFMT);
9055 + h_plus = (h_inode->i_nlink > 0);
9057 + if (inode && ibs <= bindex && bindex <= ibe)
9058 + h_cached_inode = au_h_iptr(inode, bindex);
9061 + if (unlikely(plus != h_plus && !tmpfile))
9064 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9066 + && !IS_ROOT(h_dentry)
9067 + && unhashed != d_unhashed(h_dentry)))
9070 + if (unlikely(mode != h_mode
9071 + || h_cached_inode != h_inode))
9084 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9085 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9088 + struct dentry *parent;
9090 + if (!au_digen_test(dentry, sigen))
9093 + parent = dget_parent(dentry);
9094 + di_read_lock_parent(parent, AuLock_IR);
9095 + AuDebugOn(au_digen_test(parent, sigen));
9096 + au_dbg_verify_gen(parent, sigen);
9097 + err = au_refresh_dentry(dentry, parent);
9098 + di_read_unlock(parent, AuLock_IR);
9104 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9107 + struct dentry *d, *parent;
9109 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9110 + return simple_reval_dpath(dentry, sigen);
9112 + /* slow loop, keep it simple and stupid */
9113 + /* cf: au_cpup_dirs() */
9116 + while (au_digen_test(dentry, sigen)) {
9120 + parent = dget_parent(d);
9121 + if (!au_digen_test(parent, sigen))
9127 + di_write_lock_child2(d);
9129 + /* someone might update our dentry while we were sleeping */
9130 + if (au_digen_test(d, sigen)) {
9132 + * todo: consolidate with simple_reval_dpath(),
9133 + * do_refresh() and au_reval_for_attr().
9135 + di_read_lock_parent(parent, AuLock_IR);
9136 + err = au_refresh_dentry(d, parent);
9137 + di_read_unlock(parent, AuLock_IR);
9141 + di_write_unlock(d);
9143 + if (unlikely(err))
9151 + * if valid returns 1, otherwise 0.
9153 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9156 + unsigned int sigen;
9157 + unsigned char do_udba, dirren;
9158 + struct super_block *sb;
9159 + struct inode *inode;
9161 + /* todo: support rcu-walk? */
9162 + if (flags & LOOKUP_RCU)
9166 + if (unlikely(!au_di(dentry)))
9170 + sb = dentry->d_sb;
9173 + * i_mutex of parent dir may be held,
9174 + * but we should not return 'invalid' due to busy.
9176 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9177 + if (unlikely(err)) {
9183 + if (d_really_is_positive(dentry))
9184 + inode = d_inode(dentry);
9185 + if (unlikely(inode && au_is_bad_inode(inode))) {
9190 + if (unlikely(au_dbrange_test(dentry))) {
9196 + sigen = au_sigen(sb);
9197 + if (au_digen_test(dentry, sigen)) {
9198 + AuDebugOn(IS_ROOT(dentry));
9199 + err = au_reval_dpath(dentry, sigen);
9200 + if (unlikely(err)) {
9205 + di_downgrade_lock(dentry, AuLock_IR);
9208 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9210 + && !(inode->i_state && I_LINKABLE)
9211 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9216 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9217 + if (do_udba && inode) {
9218 + aufs_bindex_t btop = au_ibtop(inode);
9219 + struct inode *h_inode;
9222 + h_inode = au_h_iptr(inode, btop);
9223 + if (h_inode && au_test_higen(inode, h_inode)) {
9230 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9231 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9232 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9234 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9240 + di_downgrade_lock(dentry, AuLock_IR);
9242 + aufs_read_unlock(dentry, AuLock_IR);
9247 + AuDbg("%pd invalid, %d\n", dentry, valid);
9253 +static void aufs_d_release(struct dentry *dentry)
9255 + if (au_di(dentry)) {
9256 + au_di_fin(dentry);
9257 + au_hn_di_reinit(dentry);
9261 +const struct dentry_operations aufs_dop = {
9262 + .d_revalidate = aufs_d_revalidate,
9263 + .d_weak_revalidate = aufs_d_revalidate,
9264 + .d_release = aufs_d_release
9267 +/* aufs_dop without d_revalidate */
9268 +const struct dentry_operations aufs_dop_noreval = {
9269 + .d_release = aufs_d_release
9271 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9272 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 08:00:00.000000000 +0800
9273 +++ linux/fs/aufs/dentry.h 2019-07-11 21:21:54.379051070 +0800
9275 +/* SPDX-License-Identifier: GPL-2.0 */
9277 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9279 + * This program, aufs is free software; you can redistribute it and/or modify
9280 + * it under the terms of the GNU General Public License as published by
9281 + * the Free Software Foundation; either version 2 of the License, or
9282 + * (at your option) any later version.
9284 + * This program is distributed in the hope that it will be useful,
9285 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9286 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9287 + * GNU General Public License for more details.
9289 + * You should have received a copy of the GNU General Public License
9290 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9294 + * lookup and dentry operations
9297 +#ifndef __AUFS_DENTRY_H__
9298 +#define __AUFS_DENTRY_H__
9302 +#include <linux/dcache.h>
9303 +#include "dirren.h"
9306 +struct au_hdentry {
9307 + struct dentry *hd_dentry;
9308 + aufs_bindex_t hd_id;
9312 + atomic_t di_generation;
9314 + struct au_rwsem di_rwsem;
9315 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9316 + unsigned char di_tmpfile; /* to allow the different name */
9317 + struct au_hdentry *di_hdentry;
9318 + struct rcu_head rcu;
9319 +} ____cacheline_aligned_in_smp;
9321 +/* ---------------------------------------------------------------------- */
9323 +/* flags for au_lkup_dentry() */
9324 +#define AuLkup_ALLOW_NEG 1
9325 +#define AuLkup_IGNORE_PERM (1 << 1)
9326 +#define AuLkup_DIRREN (1 << 2)
9327 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9328 +#define au_fset_lkup(flags, name) \
9329 + do { (flags) |= AuLkup_##name; } while (0)
9330 +#define au_fclr_lkup(flags, name) \
9331 + do { (flags) &= ~AuLkup_##name; } while (0)
9333 +#ifndef CONFIG_AUFS_DIRREN
9334 +#undef AuLkup_DIRREN
9335 +#define AuLkup_DIRREN 0
9338 +struct au_do_lookup_args {
9339 + unsigned int flags;
9341 + struct qstr whname, *name;
9342 + struct au_dr_lookup dirren;
9345 +/* ---------------------------------------------------------------------- */
9348 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9350 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9351 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9352 + struct dentry *h_parent, struct au_branch *br);
9354 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9355 + unsigned int flags);
9356 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9357 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9358 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9359 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9362 +void au_di_init_once(void *_di);
9363 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9364 +void au_di_free(struct au_dinfo *dinfo);
9365 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9366 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9367 +int au_di_init(struct dentry *dentry);
9368 +void au_di_fin(struct dentry *dentry);
9369 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9371 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9372 +void di_read_unlock(struct dentry *d, int flags);
9373 +void di_downgrade_lock(struct dentry *d, int flags);
9374 +void di_write_lock(struct dentry *d, unsigned int lsc);
9375 +void di_write_unlock(struct dentry *d);
9376 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9377 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9378 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9380 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9381 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9382 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9383 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9385 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9386 + struct dentry *h_dentry);
9387 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9388 +int au_dbrange_test(struct dentry *dentry);
9389 +void au_update_digen(struct dentry *dentry);
9390 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9391 +void au_update_dbtop(struct dentry *dentry);
9392 +void au_update_dbbot(struct dentry *dentry);
9393 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9395 +/* ---------------------------------------------------------------------- */
9397 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9399 + return dentry->d_fsdata;
9402 +/* ---------------------------------------------------------------------- */
9404 +/* lock subclass for dinfo */
9406 + AuLsc_DI_CHILD, /* child first */
9407 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9408 + AuLsc_DI_CHILD3, /* copyup dirs */
9412 + AuLsc_DI_TMP /* temp for replacing dinfo */
9416 + * di_read_lock_child, di_write_lock_child,
9417 + * di_read_lock_child2, di_write_lock_child2,
9418 + * di_read_lock_child3, di_write_lock_child3,
9419 + * di_read_lock_parent, di_write_lock_parent,
9420 + * di_read_lock_parent2, di_write_lock_parent2,
9421 + * di_read_lock_parent3, di_write_lock_parent3,
9423 +#define AuReadLockFunc(name, lsc) \
9424 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9425 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9427 +#define AuWriteLockFunc(name, lsc) \
9428 +static inline void di_write_lock_##name(struct dentry *d) \
9429 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9431 +#define AuRWLockFuncs(name, lsc) \
9432 + AuReadLockFunc(name, lsc) \
9433 + AuWriteLockFunc(name, lsc)
9435 +AuRWLockFuncs(child, CHILD);
9436 +AuRWLockFuncs(child2, CHILD2);
9437 +AuRWLockFuncs(child3, CHILD3);
9438 +AuRWLockFuncs(parent, PARENT);
9439 +AuRWLockFuncs(parent2, PARENT2);
9440 +AuRWLockFuncs(parent3, PARENT3);
9442 +#undef AuReadLockFunc
9443 +#undef AuWriteLockFunc
9444 +#undef AuRWLockFuncs
9446 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9447 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9448 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9450 +/* ---------------------------------------------------------------------- */
9452 +/* todo: memory barrier? */
9453 +static inline unsigned int au_digen(struct dentry *d)
9455 + return atomic_read(&au_di(d)->di_generation);
9458 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9460 + hdentry->hd_dentry = NULL;
9463 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9464 + aufs_bindex_t bindex)
9466 + return di->di_hdentry + bindex;
9469 +static inline void au_hdput(struct au_hdentry *hd)
9472 + dput(hd->hd_dentry);
9475 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9477 + DiMustAnyLock(dentry);
9478 + return au_di(dentry)->di_btop;
9481 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9483 + DiMustAnyLock(dentry);
9484 + return au_di(dentry)->di_bbot;
9487 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9489 + DiMustAnyLock(dentry);
9490 + return au_di(dentry)->di_bwh;
9493 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9495 + DiMustAnyLock(dentry);
9496 + return au_di(dentry)->di_bdiropq;
9499 +/* todo: hard/soft set? */
9500 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9502 + DiMustWriteLock(dentry);
9503 + au_di(dentry)->di_btop = bindex;
9506 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9508 + DiMustWriteLock(dentry);
9509 + au_di(dentry)->di_bbot = bindex;
9512 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9514 + DiMustWriteLock(dentry);
9515 + /* dbwh can be outside of btop - bbot range */
9516 + au_di(dentry)->di_bwh = bindex;
9519 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9521 + DiMustWriteLock(dentry);
9522 + au_di(dentry)->di_bdiropq = bindex;
9525 +/* ---------------------------------------------------------------------- */
9527 +#ifdef CONFIG_AUFS_HNOTIFY
9528 +static inline void au_digen_dec(struct dentry *d)
9530 + atomic_dec(&au_di(d)->di_generation);
9533 +static inline void au_hn_di_reinit(struct dentry *dentry)
9535 + dentry->d_fsdata = NULL;
9538 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9539 +#endif /* CONFIG_AUFS_HNOTIFY */
9541 +#endif /* __KERNEL__ */
9542 +#endif /* __AUFS_DENTRY_H__ */
9543 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9544 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 08:00:00.000000000 +0800
9545 +++ linux/fs/aufs/dinfo.c 2019-07-11 21:21:54.379051070 +0800
9547 +// SPDX-License-Identifier: GPL-2.0
9549 + * Copyright (C) 2005-2019 Junjiro R. Okajima
9551 + * This program, aufs is free software; you can redistribute it and/or modify
9552 + * it under the terms of the GNU General Public License as published by
9553 + * the Free Software Foundation; either version 2 of the License, or
9554 + * (at your option) any later version.
9556 + * This program is distributed in the hope that it will be useful,
9557 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9558 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9559 + * GNU General Public License for more details.
9561 + * You should have received a copy of the GNU General Public License
9562 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9566 + * dentry private data
9571 +void au_di_init_once(void *_dinfo)
9573 + struct au_dinfo *dinfo = _dinfo;
9575 + au_rw_init(&dinfo->di_rwsem);
9578 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9580 + struct au_dinfo *dinfo;
9583 + dinfo = au_cache_alloc_dinfo();
9584 + if (unlikely(!dinfo))
9587 + nbr = au_sbbot(sb) + 1;
9590 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9591 + if (dinfo->di_hdentry) {
9592 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9593 + dinfo->di_btop = -1;
9594 + dinfo->di_bbot = -1;
9595 + dinfo->di_bwh = -1;
9596 + dinfo->di_bdiropq = -1;
9597 + dinfo->di_tmpfile = 0;
9598 + for (i = 0; i < nbr; i++)
9599 + dinfo->di_hdentry[i].hd_id = -1;
9603 + au_cache_free_dinfo(dinfo);
9610 +void au_di_free(struct au_dinfo *dinfo)
9612 + struct au_hdentry *p;
9613 + aufs_bindex_t bbot, bindex;
9615 + /* dentry may not be revalidated */
9616 + bindex = dinfo->di_btop;
9617 + if (bindex >= 0) {
9618 + bbot = dinfo->di_bbot;
9619 + p = au_hdentry(dinfo, bindex);
9620 + while (bindex++ <= bbot)
9623 + au_kfree_try_rcu(dinfo->di_hdentry);
9624 + au_cache_free_dinfo(dinfo);
9627 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9629 + struct au_hdentry *p;
9632 + AuRwMustWriteLock(&a->di_rwsem);
9633 + AuRwMustWriteLock(&b->di_rwsem);
9635 +#define DiSwap(v, name) \
9637 + v = a->di_##name; \
9638 + a->di_##name = b->di_##name; \
9639 + b->di_##name = v; \
9642 + DiSwap(p, hdentry);
9646 + DiSwap(bi, bdiropq);
9652 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9654 + AuRwMustWriteLock(&dst->di_rwsem);
9655 + AuRwMustWriteLock(&src->di_rwsem);
9657 + dst->di_btop = src->di_btop;
9658 + dst->di_bbot = src->di_bbot;
9659 + dst->di_bwh = src->di_bwh;
9660 + dst->di_bdiropq = src->di_bdiropq;
9664 +int au_di_init(struct dentry *dentry)
9667 + struct super_block *sb;
9668 + struct au_dinfo *dinfo;
9671 + sb = dentry->d_sb;
9672 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9674 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9675 + /* smp_mb(); */ /* atomic_set */
9676 + dentry->d_fsdata = dinfo;
9683 +void au_di_fin(struct dentry *dentry)
9685 + struct au_dinfo *dinfo;
9687 + dinfo = au_di(dentry);
9688 + AuRwDestroy(&dinfo->di_rwsem);
9689 + au_di_free(dinfo);
9692 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9695 + struct au_hdentry *hdp;
9697 + AuRwMustWriteLock(&dinfo->di_rwsem);
9700 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9702 + sz = sizeof(*hdp);
9703 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9706 + dinfo->di_hdentry = hdp;
9713 +/* ---------------------------------------------------------------------- */
9715 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9718 + case AuLsc_DI_CHILD:
9719 + ii_write_lock_child(inode);
9721 + case AuLsc_DI_CHILD2:
9722 + ii_write_lock_child2(inode);
9724 + case AuLsc_DI_CHILD3:
9725 + ii_write_lock_child3(inode);
9727 + case AuLsc_DI_PARENT:
9728 + ii_write_lock_parent(inode);
9730 + case AuLsc_DI_PARENT2:
9731 + ii_write_lock_parent2(inode);
9733 + case AuLsc_DI_PARENT3:
9734 + ii_write_lock_parent3(inode);
9741 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9744 + case AuLsc_DI_CHILD:
9745 + ii_read_lock_child(inode);
9747 + case AuLsc_DI_CHILD2:
9748 + ii_read_lock_child2(inode);
9750 + case AuLsc_DI_CHILD3:
9751 + ii_read_lock_child3(inode);
9753 + case AuLsc_DI_PARENT:
9754 + ii_read_lock_parent(inode);
9756 + case AuLsc_DI_PARENT2:
9757 + ii_read_lock_parent2(inode);
9759 + case AuLsc_DI_PARENT3:
9760 + ii_read_lock_parent3(inode);
9767 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9769 + struct inode *inode;
9771 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9772 + if (d_really_is_positive(d)) {
9773 + inode = d_inode(d);
9774 + if (au_ftest_lock(flags, IW))
9775 + do_ii_write_lock(inode, lsc);
9776 + else if (au_ftest_lock(flags, IR))
9777 + do_ii_read_lock(inode, lsc);
9781 +void di_read_unlock(struct dentry *d, int flags)
9783 + struct inode *inode;
9785 + if (d_really_is_positive(d)) {
9786 + inode = d_inode(d);
9787 + if (au_ftest_lock(flags, IW)) {
9788 + au_dbg_verify_dinode(d);
9789 + ii_write_unlock(inode);
9790 + } else if (au_ftest_lock(flags, IR)) {
9791 + au_dbg_verify_dinode(d);
9792 + ii_read_unlock(inode);
9795 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9798 +void di_downgrade_lock(struct dentry *d, int flags)
9800 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9801 + ii_downgrade_lock(d_inode(d));
9802 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9805 +void di_write_lock(struct dentry *d, unsigned int lsc)
9807 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9808 + if (d_really_is_positive(d))
9809 + do_ii_write_lock(d_inode(d), lsc);
9812 +void di_write_unlock(struct dentry *d)
9814 + au_dbg_verify_dinode(d);
9815 + if (d_really_is_positive(d))
9816 + ii_write_unlock(d_inode(d));
9817 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9820 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9822 + AuDebugOn(d1 == d2
9823 + || d_inode(d1) == d_inode(d2)
9824 + || d1->d_sb != d2->d_sb);
9826 + if ((isdir && au_test_subdir(d1, d2))
9828 + di_write_lock_child(d1);
9829 + di_write_lock_child2(d2);
9831 + di_write_lock_child(d2);
9832 + di_write_lock_child2(d1);
9836 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9838 + AuDebugOn(d1 == d2
9839 + || d_inode(d1) == d_inode(d2)
9840 + || d1->d_sb != d2->d_sb);
9842 + if ((isdir && au_test_subdir(d1, d2))
9844 + di_write_lock_parent(d1);
9845 + di_write_lock_parent2(d2);
9847 + di_write_lock_parent(d2);
9848 + di_write_lock_parent2(d1);
9852 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9854 + di_write_unlock(d1);
9855 + if (d_inode(d1) == d_inode(d2))
9856 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9858 + di_write_unlock(d2);
9861 +/* ---------------------------------------------------------------------- */
9863 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9867 + DiMustAnyLock(dentry);
9869 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9871 + AuDebugOn(bindex < 0);
9872 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9873 + AuDebugOn(d && au_dcount(d) <= 0);
9878 + * extended version of au_h_dptr().
9879 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9882 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9884 + struct dentry *h_dentry;
9885 + struct inode *inode, *h_inode;
9887 + AuDebugOn(d_really_is_negative(dentry));
9890 + if (au_dbtop(dentry) <= bindex
9891 + && bindex <= au_dbbot(dentry))
9892 + h_dentry = au_h_dptr(dentry, bindex);
9893 + if (h_dentry && !au_d_linkable(h_dentry)) {
9895 + goto out; /* success */
9898 + inode = d_inode(dentry);
9899 + AuDebugOn(bindex < au_ibtop(inode));
9900 + AuDebugOn(au_ibbot(inode) < bindex);
9901 + h_inode = au_h_iptr(inode, bindex);
9902 + h_dentry = d_find_alias(h_inode);
9904 + if (!IS_ERR(h_dentry)) {
9905 + if (!au_d_linkable(h_dentry))
9906 + goto out; /* success */
9912 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9913 + h_dentry = au_plink_lkup(inode, bindex);
9914 + AuDebugOn(!h_dentry);
9915 + if (!IS_ERR(h_dentry)) {
9916 + if (!au_d_hashed_positive(h_dentry))
9917 + goto out; /* success */
9924 + AuDbgDentry(h_dentry);
9928 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9930 + aufs_bindex_t bbot, bwh;
9932 + bbot = au_dbbot(dentry);
9934 + bwh = au_dbwh(dentry);
9937 + if (0 < bwh && bwh < bbot)
9943 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9945 + aufs_bindex_t bbot, bopq;
9947 + bbot = au_dbtail(dentry);
9949 + bopq = au_dbdiropq(dentry);
9950 + if (0 <= bopq && bopq < bbot)
9956 +/* ---------------------------------------------------------------------- */
9958 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9959 + struct dentry *h_dentry)
9961 + struct au_dinfo *dinfo;
9962 + struct au_hdentry *hd;
9963 + struct au_branch *br;
9965 + DiMustWriteLock(dentry);
9967 + dinfo = au_di(dentry);
9968 + hd = au_hdentry(dinfo, bindex);
9970 + hd->hd_dentry = h_dentry;
9972 + br = au_sbr(dentry->d_sb, bindex);
9973 + hd->hd_id = br->br_id;
9977 +int au_dbrange_test(struct dentry *dentry)
9980 + aufs_bindex_t btop, bbot;
9983 + btop = au_dbtop(dentry);
9984 + bbot = au_dbbot(dentry);
9986 + AuDebugOn(bbot < 0 && btop > bbot);
9989 + AuDebugOn(bbot >= 0);
9995 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10000 + if (unlikely(au_digen(dentry) != sigen
10001 + || au_iigen_test(d_inode(dentry), sigen)))
10007 +void au_update_digen(struct dentry *dentry)
10009 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10010 + /* smp_mb(); */ /* atomic_set */
10013 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10015 + struct au_dinfo *dinfo;
10016 + struct dentry *h_d;
10017 + struct au_hdentry *hdp;
10018 + aufs_bindex_t bindex, bbot;
10020 + DiMustWriteLock(dentry);
10022 + dinfo = au_di(dentry);
10023 + if (!dinfo || dinfo->di_btop < 0)
10026 + if (do_put_zero) {
10027 + bbot = dinfo->di_bbot;
10028 + bindex = dinfo->di_btop;
10029 + hdp = au_hdentry(dinfo, bindex);
10030 + for (; bindex <= bbot; bindex++, hdp++) {
10031 + h_d = hdp->hd_dentry;
10032 + if (h_d && d_is_negative(h_d))
10033 + au_set_h_dptr(dentry, bindex, NULL);
10037 + dinfo->di_btop = 0;
10038 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10039 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10040 + if (hdp->hd_dentry)
10042 + if (dinfo->di_btop > dinfo->di_bbot) {
10043 + dinfo->di_btop = -1;
10044 + dinfo->di_bbot = -1;
10048 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10049 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10050 + if (hdp->hd_dentry)
10052 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10055 +void au_update_dbtop(struct dentry *dentry)
10057 + aufs_bindex_t bindex, bbot;
10058 + struct dentry *h_dentry;
10060 + bbot = au_dbbot(dentry);
10061 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10062 + h_dentry = au_h_dptr(dentry, bindex);
10065 + if (d_is_positive(h_dentry)) {
10066 + au_set_dbtop(dentry, bindex);
10069 + au_set_h_dptr(dentry, bindex, NULL);
10073 +void au_update_dbbot(struct dentry *dentry)
10075 + aufs_bindex_t bindex, btop;
10076 + struct dentry *h_dentry;
10078 + btop = au_dbtop(dentry);
10079 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10080 + h_dentry = au_h_dptr(dentry, bindex);
10083 + if (d_is_positive(h_dentry)) {
10084 + au_set_dbbot(dentry, bindex);
10087 + au_set_h_dptr(dentry, bindex, NULL);
10091 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10093 + aufs_bindex_t bindex, bbot;
10095 + bbot = au_dbbot(dentry);
10096 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10097 + if (au_h_dptr(dentry, bindex) == h_dentry)
10101 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10102 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 08:00:00.000000000 +0800
10103 +++ linux/fs/aufs/dir.c 2019-07-11 21:21:54.379051070 +0800
10105 +// SPDX-License-Identifier: GPL-2.0
10107 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10109 + * This program, aufs is free software; you can redistribute it and/or modify
10110 + * it under the terms of the GNU General Public License as published by
10111 + * the Free Software Foundation; either version 2 of the License, or
10112 + * (at your option) any later version.
10114 + * This program is distributed in the hope that it will be useful,
10115 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10117 + * GNU General Public License for more details.
10119 + * You should have received a copy of the GNU General Public License
10120 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10124 + * directory operations
10127 +#include <linux/fs_stack.h>
10128 +#include <linux/iversion.h>
10131 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10133 + unsigned int nlink;
10135 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10137 + nlink = dir->i_nlink;
10138 + nlink += h_dir->i_nlink - 2;
10139 + if (h_dir->i_nlink < 2)
10141 + smp_mb(); /* for i_nlink */
10142 + /* 0 can happen in revaliding */
10143 + set_nlink(dir, nlink);
10146 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10148 + unsigned int nlink;
10150 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10152 + nlink = dir->i_nlink;
10153 + nlink -= h_dir->i_nlink - 2;
10154 + if (h_dir->i_nlink < 2)
10156 + smp_mb(); /* for i_nlink */
10157 + /* nlink == 0 means the branch-fs is broken */
10158 + set_nlink(dir, nlink);
10161 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10164 + aufs_bindex_t bindex, bbot;
10165 + struct file *h_file;
10166 + struct dentry *h_dentry;
10170 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10172 + bbot = au_fbbot_dir(file);
10173 + for (bindex = au_fbtop(file);
10174 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10176 + h_file = au_hf_dir(file, bindex);
10177 + if (h_file && file_inode(h_file))
10178 + sz += vfsub_f_size_read(h_file);
10181 + AuDebugOn(!dentry);
10182 + AuDebugOn(!d_is_dir(dentry));
10184 + bbot = au_dbtaildir(dentry);
10185 + for (bindex = au_dbtop(dentry);
10186 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10188 + h_dentry = au_h_dptr(dentry, bindex);
10189 + if (h_dentry && d_is_positive(h_dentry))
10190 + sz += i_size_read(d_inode(h_dentry));
10193 + if (sz < KMALLOC_MAX_SIZE)
10194 + sz = roundup_pow_of_two(sz);
10195 + if (sz > KMALLOC_MAX_SIZE)
10196 + sz = KMALLOC_MAX_SIZE;
10197 + else if (sz < NAME_MAX) {
10198 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10199 + sz = AUFS_RDBLK_DEF;
10204 +struct au_dir_ts_arg {
10205 + struct dentry *dentry;
10206 + aufs_bindex_t brid;
10209 +static void au_do_dir_ts(void *arg)
10211 + struct au_dir_ts_arg *a = arg;
10212 + struct au_dtime dt;
10213 + struct path h_path;
10214 + struct inode *dir, *h_dir;
10215 + struct super_block *sb;
10216 + struct au_branch *br;
10217 + struct au_hinode *hdir;
10219 + aufs_bindex_t btop, bindex;
10221 + sb = a->dentry->d_sb;
10222 + if (d_really_is_negative(a->dentry))
10224 + /* no dir->i_mutex lock */
10225 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10227 + dir = d_inode(a->dentry);
10228 + btop = au_ibtop(dir);
10229 + bindex = au_br_index(sb, a->brid);
10230 + if (bindex < btop)
10233 + br = au_sbr(sb, bindex);
10234 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10235 + if (!h_path.dentry)
10237 + h_path.mnt = au_br_mnt(br);
10238 + au_dtime_store(&dt, a->dentry, &h_path);
10240 + br = au_sbr(sb, btop);
10241 + if (!au_br_writable(br->br_perm))
10243 + h_path.dentry = au_h_dptr(a->dentry, btop);
10244 + h_path.mnt = au_br_mnt(br);
10245 + err = vfsub_mnt_want_write(h_path.mnt);
10248 + hdir = au_hi(dir, btop);
10249 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10250 + h_dir = au_h_iptr(dir, btop);
10251 + if (h_dir->i_nlink
10252 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10253 + dt.dt_h_path = h_path;
10254 + au_dtime_revert(&dt);
10256 + au_hn_inode_unlock(hdir);
10257 + vfsub_mnt_drop_write(h_path.mnt);
10258 + au_cpup_attr_timesizes(dir);
10261 + aufs_read_unlock(a->dentry, AuLock_DW);
10264 + au_nwt_done(&au_sbi(sb)->si_nowait);
10265 + au_kfree_try_rcu(arg);
10268 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10270 + int perm, wkq_err;
10271 + aufs_bindex_t btop;
10272 + struct au_dir_ts_arg *arg;
10273 + struct dentry *dentry;
10274 + struct super_block *sb;
10278 + dentry = d_find_any_alias(dir);
10279 + AuDebugOn(!dentry);
10280 + sb = dentry->d_sb;
10281 + btop = au_ibtop(dir);
10282 + if (btop == bindex) {
10283 + au_cpup_attr_timesizes(dir);
10287 + perm = au_sbr_perm(sb, btop);
10288 + if (!au_br_writable(perm))
10291 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10295 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10296 + arg->brid = au_sbr_id(sb, bindex);
10297 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10298 + if (unlikely(wkq_err)) {
10299 + pr_err("wkq %d\n", wkq_err);
10301 + au_kfree_try_rcu(arg);
10308 +/* ---------------------------------------------------------------------- */
10310 +static int reopen_dir(struct file *file)
10313 + unsigned int flags;
10314 + aufs_bindex_t bindex, btail, btop;
10315 + struct dentry *dentry, *h_dentry;
10316 + struct file *h_file;
10318 + /* open all lower dirs */
10319 + dentry = file->f_path.dentry;
10320 + btop = au_dbtop(dentry);
10321 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10322 + au_set_h_fptr(file, bindex, NULL);
10323 + au_set_fbtop(file, btop);
10325 + btail = au_dbtaildir(dentry);
10326 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10327 + au_set_h_fptr(file, bindex, NULL);
10328 + au_set_fbbot_dir(file, btail);
10330 + flags = vfsub_file_flags(file);
10331 + for (bindex = btop; bindex <= btail; bindex++) {
10332 + h_dentry = au_h_dptr(dentry, bindex);
10335 + h_file = au_hf_dir(file, bindex);
10339 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10340 + err = PTR_ERR(h_file);
10341 + if (IS_ERR(h_file))
10342 + goto out; /* close all? */
10343 + au_set_h_fptr(file, bindex, h_file);
10345 + au_update_figen(file);
10346 + /* todo: necessary? */
10347 + /* file->f_ra = h_file->f_ra; */
10354 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10357 + aufs_bindex_t bindex, btail;
10358 + struct dentry *dentry, *h_dentry;
10359 + struct vfsmount *mnt;
10361 + FiMustWriteLock(file);
10362 + AuDebugOn(h_file);
10365 + mnt = file->f_path.mnt;
10366 + dentry = file->f_path.dentry;
10367 + file->f_version = inode_query_iversion(d_inode(dentry));
10368 + bindex = au_dbtop(dentry);
10369 + au_set_fbtop(file, bindex);
10370 + btail = au_dbtaildir(dentry);
10371 + au_set_fbbot_dir(file, btail);
10372 + for (; !err && bindex <= btail; bindex++) {
10373 + h_dentry = au_h_dptr(dentry, bindex);
10377 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10378 + if (unlikely(err))
10380 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10381 + if (IS_ERR(h_file)) {
10382 + err = PTR_ERR(h_file);
10385 + au_set_h_fptr(file, bindex, h_file);
10387 + au_update_figen(file);
10388 + /* todo: necessary? */
10389 + /* file->f_ra = h_file->f_ra; */
10391 + return 0; /* success */
10394 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10395 + au_set_h_fptr(file, bindex, NULL);
10396 + au_set_fbtop(file, -1);
10397 + au_set_fbbot_dir(file, -1);
10402 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10403 + struct file *file)
10406 + struct super_block *sb;
10407 + struct au_fidir *fidir;
10410 + sb = file->f_path.dentry->d_sb;
10411 + si_read_lock(sb, AuLock_FLUSH);
10412 + fidir = au_fidir_alloc(sb);
10414 + struct au_do_open_args args = {
10415 + .open = do_open_dir,
10418 + err = au_do_open(file, &args);
10419 + if (unlikely(err))
10420 + au_kfree_rcu(fidir);
10422 + si_read_unlock(sb);
10426 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10427 + struct file *file)
10429 + struct au_vdir *vdir_cache;
10430 + struct au_finfo *finfo;
10431 + struct au_fidir *fidir;
10432 + struct au_hfile *hf;
10433 + aufs_bindex_t bindex, bbot;
10435 + finfo = au_fi(file);
10436 + fidir = finfo->fi_hdir;
10438 + au_hbl_del(&finfo->fi_hlist,
10439 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10440 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10442 + au_vdir_free(vdir_cache);
10444 + bindex = finfo->fi_btop;
10445 + if (bindex >= 0) {
10446 + hf = fidir->fd_hfile + bindex;
10448 + * calls fput() instead of filp_close(),
10449 + * since no dnotify or lock for the lower file.
10451 + bbot = fidir->fd_bbot;
10452 + for (; bindex <= bbot; bindex++, hf++)
10454 + au_hfput(hf, /*execed*/0);
10456 + au_kfree_rcu(fidir);
10457 + finfo->fi_hdir = NULL;
10459 + au_finfo_fin(file);
10463 +/* ---------------------------------------------------------------------- */
10465 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10468 + aufs_bindex_t bindex, bbot;
10469 + struct file *h_file;
10472 + bbot = au_fbbot_dir(file);
10473 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10474 + h_file = au_hf_dir(file, bindex);
10476 + err = vfsub_flush(h_file, id);
10481 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10483 + return au_do_flush(file, id, au_do_flush_dir);
10486 +/* ---------------------------------------------------------------------- */
10488 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10491 + aufs_bindex_t bbot, bindex;
10492 + struct inode *inode;
10493 + struct super_block *sb;
10496 + sb = dentry->d_sb;
10497 + inode = d_inode(dentry);
10498 + IMustLock(inode);
10499 + bbot = au_dbbot(dentry);
10500 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10501 + struct path h_path;
10503 + if (au_test_ro(sb, bindex, inode))
10505 + h_path.dentry = au_h_dptr(dentry, bindex);
10506 + if (!h_path.dentry)
10509 + h_path.mnt = au_sbr_mnt(sb, bindex);
10510 + err = vfsub_fsync(NULL, &h_path, datasync);
10516 +static int au_do_fsync_dir(struct file *file, int datasync)
10519 + aufs_bindex_t bbot, bindex;
10520 + struct file *h_file;
10521 + struct super_block *sb;
10522 + struct inode *inode;
10524 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10525 + if (unlikely(err))
10528 + inode = file_inode(file);
10529 + sb = inode->i_sb;
10530 + bbot = au_fbbot_dir(file);
10531 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10532 + h_file = au_hf_dir(file, bindex);
10533 + if (!h_file || au_test_ro(sb, bindex, inode))
10536 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10544 + * @file may be NULL
10546 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10550 + struct dentry *dentry;
10551 + struct inode *inode;
10552 + struct super_block *sb;
10555 + dentry = file->f_path.dentry;
10556 + inode = d_inode(dentry);
10557 + inode_lock(inode);
10558 + sb = dentry->d_sb;
10559 + si_noflush_read_lock(sb);
10561 + err = au_do_fsync_dir(file, datasync);
10563 + di_write_lock_child(dentry);
10564 + err = au_do_fsync_dir_no_file(dentry, datasync);
10566 + au_cpup_attr_timesizes(inode);
10567 + di_write_unlock(dentry);
10569 + fi_write_unlock(file);
10571 + si_read_unlock(sb);
10572 + inode_unlock(inode);
10576 +/* ---------------------------------------------------------------------- */
10578 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10581 + struct dentry *dentry;
10582 + struct inode *inode, *h_inode;
10583 + struct super_block *sb;
10585 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10587 + dentry = file->f_path.dentry;
10588 + inode = d_inode(dentry);
10589 + IMustLock(inode);
10591 + sb = dentry->d_sb;
10592 + si_read_lock(sb, AuLock_FLUSH);
10593 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10594 + if (unlikely(err))
10596 + err = au_alive_dir(dentry);
10598 + err = au_vdir_init(file);
10599 + di_downgrade_lock(dentry, AuLock_IR);
10600 + if (unlikely(err))
10603 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10604 + if (!au_test_nfsd()) {
10605 + err = au_vdir_fill_de(file, ctx);
10606 + fsstack_copy_attr_atime(inode, h_inode);
10609 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10610 + * encode_fh() and others.
10612 + atomic_inc(&h_inode->i_count);
10613 + di_read_unlock(dentry, AuLock_IR);
10614 + si_read_unlock(sb);
10615 + err = au_vdir_fill_de(file, ctx);
10616 + fsstack_copy_attr_atime(inode, h_inode);
10617 + fi_write_unlock(file);
10625 + di_read_unlock(dentry, AuLock_IR);
10626 + fi_write_unlock(file);
10628 + si_read_unlock(sb);
10632 +/* ---------------------------------------------------------------------- */
10634 +#define AuTestEmpty_WHONLY 1
10635 +#define AuTestEmpty_CALLED (1 << 1)
10636 +#define AuTestEmpty_SHWH (1 << 2)
10637 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10638 +#define au_fset_testempty(flags, name) \
10639 + do { (flags) |= AuTestEmpty_##name; } while (0)
10640 +#define au_fclr_testempty(flags, name) \
10641 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10643 +#ifndef CONFIG_AUFS_SHWH
10644 +#undef AuTestEmpty_SHWH
10645 +#define AuTestEmpty_SHWH 0
10648 +struct test_empty_arg {
10649 + struct dir_context ctx;
10650 + struct au_nhash *whlist;
10651 + unsigned int flags;
10653 + aufs_bindex_t bindex;
10656 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10657 + int namelen, loff_t offset __maybe_unused, u64 ino,
10658 + unsigned int d_type)
10660 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10662 + char *name = (void *)__name;
10665 + au_fset_testempty(arg->flags, CALLED);
10667 + if (name[0] == '.'
10668 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10669 + goto out; /* success */
10671 + if (namelen <= AUFS_WH_PFX_LEN
10672 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10673 + if (au_ftest_testempty(arg->flags, WHONLY)
10674 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10675 + arg->err = -ENOTEMPTY;
10679 + name += AUFS_WH_PFX_LEN;
10680 + namelen -= AUFS_WH_PFX_LEN;
10681 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10682 + arg->err = au_nhash_append_wh
10683 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10684 + au_ftest_testempty(arg->flags, SHWH));
10688 + AuTraceErr(arg->err);
10692 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10695 + struct file *h_file;
10696 + struct au_branch *br;
10698 + h_file = au_h_open(dentry, arg->bindex,
10699 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10700 + /*file*/NULL, /*force_wr*/0);
10701 + err = PTR_ERR(h_file);
10702 + if (IS_ERR(h_file))
10706 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10707 + && !file_inode(h_file)->i_nlink)
10712 + au_fclr_testempty(arg->flags, CALLED);
10714 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10717 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10721 + br = au_sbr(dentry->d_sb, arg->bindex);
10722 + au_lcnt_dec(&br->br_nfiles);
10727 +struct do_test_empty_args {
10729 + struct dentry *dentry;
10730 + struct test_empty_arg *arg;
10733 +static void call_do_test_empty(void *args)
10735 + struct do_test_empty_args *a = args;
10736 + *a->errp = do_test_empty(a->dentry, a->arg);
10739 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10741 + int err, wkq_err;
10742 + struct dentry *h_dentry;
10743 + struct inode *h_inode;
10745 + h_dentry = au_h_dptr(dentry, arg->bindex);
10746 + h_inode = d_inode(h_dentry);
10747 + /* todo: i_mode changes anytime? */
10748 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10749 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10750 + inode_unlock_shared(h_inode);
10752 + err = do_test_empty(dentry, arg);
10754 + struct do_test_empty_args args = {
10756 + .dentry = dentry,
10759 + unsigned int flags = arg->flags;
10761 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10762 + if (unlikely(wkq_err))
10764 + arg->flags = flags;
10770 +int au_test_empty_lower(struct dentry *dentry)
10773 + unsigned int rdhash;
10774 + aufs_bindex_t bindex, btop, btail;
10775 + struct au_nhash whlist;
10776 + struct test_empty_arg arg = {
10778 + .actor = test_empty_cb
10781 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10783 + SiMustAnyLock(dentry->d_sb);
10785 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10787 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10788 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10789 + if (unlikely(err))
10793 + arg.whlist = &whlist;
10794 + btop = au_dbtop(dentry);
10795 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10796 + au_fset_testempty(arg.flags, SHWH);
10797 + test_empty = do_test_empty;
10798 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10799 + test_empty = sio_test_empty;
10800 + arg.bindex = btop;
10801 + err = test_empty(dentry, &arg);
10802 + if (unlikely(err))
10805 + au_fset_testempty(arg.flags, WHONLY);
10806 + btail = au_dbtaildir(dentry);
10807 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10808 + struct dentry *h_dentry;
10810 + h_dentry = au_h_dptr(dentry, bindex);
10811 + if (h_dentry && d_is_positive(h_dentry)) {
10812 + arg.bindex = bindex;
10813 + err = test_empty(dentry, &arg);
10818 + au_nhash_wh_free(&whlist);
10823 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10826 + struct test_empty_arg arg = {
10828 + .actor = test_empty_cb
10831 + aufs_bindex_t bindex, btail;
10834 + arg.whlist = whlist;
10835 + arg.flags = AuTestEmpty_WHONLY;
10836 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10837 + au_fset_testempty(arg.flags, SHWH);
10838 + btail = au_dbtaildir(dentry);
10839 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10840 + struct dentry *h_dentry;
10842 + h_dentry = au_h_dptr(dentry, bindex);
10843 + if (h_dentry && d_is_positive(h_dentry)) {
10844 + arg.bindex = bindex;
10845 + err = sio_test_empty(dentry, &arg);
10852 +/* ---------------------------------------------------------------------- */
10854 +const struct file_operations aufs_dir_fop = {
10855 + .owner = THIS_MODULE,
10856 + .llseek = default_llseek,
10857 + .read = generic_read_dir,
10858 + .iterate_shared = aufs_iterate_shared,
10859 + .unlocked_ioctl = aufs_ioctl_dir,
10860 +#ifdef CONFIG_COMPAT
10861 + .compat_ioctl = aufs_compat_ioctl_dir,
10863 + .open = aufs_open_dir,
10864 + .release = aufs_release_dir,
10865 + .flush = aufs_flush_dir,
10866 + .fsync = aufs_fsync_dir
10868 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10869 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 08:00:00.000000000 +0800
10870 +++ linux/fs/aufs/dir.h 2019-07-11 21:21:54.379051070 +0800
10872 +/* SPDX-License-Identifier: GPL-2.0 */
10874 + * Copyright (C) 2005-2019 Junjiro R. Okajima
10876 + * This program, aufs is free software; you can redistribute it and/or modify
10877 + * it under the terms of the GNU General Public License as published by
10878 + * the Free Software Foundation; either version 2 of the License, or
10879 + * (at your option) any later version.
10881 + * This program is distributed in the hope that it will be useful,
10882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10884 + * GNU General Public License for more details.
10886 + * You should have received a copy of the GNU General Public License
10887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10891 + * directory operations
10894 +#ifndef __AUFS_DIR_H__
10895 +#define __AUFS_DIR_H__
10899 +#include <linux/fs.h>
10901 +/* ---------------------------------------------------------------------- */
10903 +/* need to be faster and smaller */
10906 + unsigned int nh_num;
10907 + struct hlist_head *nh_head;
10910 +struct au_vdir_destr {
10911 + unsigned char len;
10912 + unsigned char name[0];
10915 +struct au_vdir_dehstr {
10916 + struct hlist_node hash;
10917 + struct au_vdir_destr *str;
10918 + struct rcu_head rcu;
10919 +} ____cacheline_aligned_in_smp;
10921 +struct au_vdir_de {
10923 + unsigned char de_type;
10924 + /* caution: packed */
10925 + struct au_vdir_destr de_str;
10928 +struct au_vdir_wh {
10929 + struct hlist_node wh_hash;
10930 +#ifdef CONFIG_AUFS_SHWH
10932 + aufs_bindex_t wh_bindex;
10933 + unsigned char wh_type;
10935 + aufs_bindex_t wh_bindex;
10937 + /* caution: packed */
10938 + struct au_vdir_destr wh_str;
10941 +union au_vdir_deblk_p {
10942 + unsigned char *deblk;
10943 + struct au_vdir_de *de;
10947 + unsigned char **vd_deblk;
10948 + unsigned long vd_nblk;
10950 + unsigned long ul;
10951 + union au_vdir_deblk_p p;
10955 + unsigned int vd_deblk_sz;
10956 + unsigned long vd_jiffy;
10957 + struct rcu_head rcu;
10958 +} ____cacheline_aligned_in_smp;
10960 +/* ---------------------------------------------------------------------- */
10963 +extern const struct file_operations aufs_dir_fop;
10964 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10965 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10966 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10967 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10968 +int au_test_empty_lower(struct dentry *dentry);
10969 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10972 +unsigned int au_rdhash_est(loff_t sz);
10973 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10974 +void au_nhash_wh_free(struct au_nhash *whlist);
10975 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10977 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10978 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10979 + unsigned int d_type, aufs_bindex_t bindex,
10980 + unsigned char shwh);
10981 +void au_vdir_free(struct au_vdir *vdir);
10982 +int au_vdir_init(struct file *file);
10983 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10986 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10988 +#ifdef CONFIG_AUFS_RDU
10990 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10991 +#ifdef CONFIG_COMPAT
10992 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10993 + unsigned long arg);
10996 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10997 + unsigned int cmd, unsigned long arg)
10998 +#ifdef CONFIG_COMPAT
10999 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11000 + unsigned int cmd, unsigned long arg)
11004 +#endif /* __KERNEL__ */
11005 +#endif /* __AUFS_DIR_H__ */
11006 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11007 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 08:00:00.000000000 +0800
11008 +++ linux/fs/aufs/dirren.c 2019-07-11 21:21:54.379051070 +0800
11010 +// SPDX-License-Identifier: GPL-2.0
11012 + * Copyright (C) 2017-2019 Junjiro R. Okajima
11014 + * This program, aufs is free software; you can redistribute it and/or modify
11015 + * it under the terms of the GNU General Public License as published by
11016 + * the Free Software Foundation; either version 2 of the License, or
11017 + * (at your option) any later version.
11019 + * This program is distributed in the hope that it will be useful,
11020 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11021 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11022 + * GNU General Public License for more details.
11024 + * You should have received a copy of the GNU General Public License
11025 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11029 + * special handling in renaming a directory
11030 + * in order to support looking-up the before-renamed name on the lower readonly
11034 +#include <linux/byteorder/generic.h>
11037 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11041 + idx = au_dr_ihash(ent->dr_h_ino);
11042 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11045 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11048 + struct hlist_bl_head *hbl;
11051 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11052 + hbl = dr->dr_h_ino + i;
11053 + hlist_bl_lock(hbl);
11054 + ret &= hlist_bl_empty(hbl);
11055 + hlist_bl_unlock(hbl);
11061 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11063 + struct au_dr_hino *found, *ent;
11064 + struct hlist_bl_head *hbl;
11065 + struct hlist_bl_node *pos;
11069 + idx = au_dr_ihash(ino);
11070 + hbl = dr->dr_h_ino + idx;
11071 + hlist_bl_lock(hbl);
11072 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11073 + if (ent->dr_h_ino == ino) {
11077 + hlist_bl_unlock(hbl);
11082 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11083 + struct au_dr_hino *add_ent)
11086 + struct hlist_bl_head *hbl;
11087 + struct hlist_bl_node *pos;
11088 + struct au_dr_hino *ent;
11091 + idx = au_dr_ihash(ino);
11092 + hbl = dr->dr_h_ino + idx;
11095 + struct hlist_bl_node *tmp;
11097 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11098 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11101 + hlist_bl_lock(hbl);
11102 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11103 + if (ent->dr_h_ino == ino) {
11107 + if (!found && add_ent)
11108 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11109 + hlist_bl_unlock(hbl);
11111 + if (!found && add_ent)
11112 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11117 +void au_dr_hino_free(struct au_dr_br *dr)
11120 + struct hlist_bl_head *hbl;
11121 + struct hlist_bl_node *pos, *tmp;
11122 + struct au_dr_hino *ent;
11124 + /* SiMustWriteLock(sb); */
11126 + for (i = 0; i < AuDirren_NHASH; i++) {
11127 + hbl = dr->dr_h_ino + i;
11128 + /* no spinlock since sbinfo must be write-locked */
11129 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11130 + au_kfree_rcu(ent);
11131 + INIT_HLIST_BL_HEAD(hbl);
11135 +/* returns the number of inodes or an error */
11136 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11137 + struct file *hinofile)
11141 + loff_t pos, oldsize;
11143 + struct inode *hinoinode;
11144 + struct hlist_bl_head *hbl;
11145 + struct hlist_bl_node *n1, *n2;
11146 + struct au_dr_hino *ent;
11148 + SiMustWriteLock(sb);
11149 + AuDebugOn(!au_br_writable(br->br_perm));
11151 + hinoinode = file_inode(hinofile);
11152 + oldsize = i_size_read(hinoinode);
11156 + hbl = br->br_dirren.dr_h_ino;
11157 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11158 + /* no bit-lock since sbinfo must be write-locked */
11159 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11160 + AuDbg("hi%llu, %pD2\n",
11161 + (unsigned long long)ent->dr_h_ino, hinofile);
11162 + u64 = cpu_to_be64(ent->dr_h_ino);
11163 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11164 + if (ssz == sizeof(u64))
11167 + /* write error */
11168 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11175 + /* regardless the error */
11176 + if (pos < oldsize) {
11177 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11185 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11192 + struct au_dr_hino *ent;
11193 + struct inode *hinoinode;
11194 + struct hlist_bl_head *hbl;
11198 + hbl = dr->dr_h_ino;
11199 + hinoinode = file_inode(hinofile);
11200 + sz = i_size_read(hinoinode);
11201 + AuDebugOn(sz % sizeof(u64));
11202 + n = sz / sizeof(u64);
11204 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11205 + if (unlikely(ssz != sizeof(u64))) {
11206 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11213 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11219 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11220 + AuDbg("hi%llu, %pD2\n",
11221 + (unsigned long long)ent->dr_h_ino, hinofile);
11222 + hidx = au_dr_ihash(ent->dr_h_ino);
11223 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11225 + goto out; /* success */
11228 + au_dr_hino_free(dr);
11235 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11236 + * @path is a switch to distinguish load and store.
11238 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11239 + struct au_branch *br, const struct path *path)
11242 + unsigned char load, suspend;
11243 + struct file *hinofile;
11244 + struct au_hinode *hdir;
11245 + struct inode *dir, *delegated;
11246 + struct path hinopath;
11247 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11248 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11250 + AuDebugOn(bindex < 0 && !br);
11251 + AuDebugOn(bindex >= 0 && br);
11256 + br = au_sbr(sb, bindex);
11259 + path = &br->br_path;
11260 + AuDebugOn(!au_br_writable(br->br_perm));
11261 + if (unlikely(!au_br_writable(br->br_perm)))
11267 + dir = d_inode(sb->s_root);
11268 + hdir = au_hinode(au_ii(dir), bindex);
11269 + dir = hdir->hi_inode;
11270 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11272 + dir = d_inode(path->dentry);
11273 + inode_lock_nested(dir, AuLsc_I_CHILD);
11275 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11276 + err = PTR_ERR(hinopath.dentry);
11277 + if (IS_ERR(hinopath.dentry))
11281 + flags = O_RDONLY;
11283 + if (d_is_negative(hinopath.dentry))
11284 + goto out_dput; /* success */
11286 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11287 + if (d_is_positive(hinopath.dentry)) {
11288 + delegated = NULL;
11289 + err = vfsub_unlink(dir, &hinopath, &delegated,
11292 + if (unlikely(err))
11293 + pr_err("ignored err %d, %pd2\n",
11294 + err, hinopath.dentry);
11295 + if (unlikely(err == -EWOULDBLOCK))
11300 + } else if (!d_is_positive(hinopath.dentry)) {
11301 + err = vfsub_create(dir, &hinopath, 0600,
11302 + /*want_excl*/false);
11304 + if (unlikely(err))
11307 + flags = O_WRONLY;
11309 + hinopath.mnt = path->mnt;
11310 + hinofile = vfsub_dentry_open(&hinopath, flags);
11312 + au_hn_inode_unlock(hdir);
11314 + inode_unlock(dir);
11315 + dput(hinopath.dentry);
11316 + AuTraceErrPtr(hinofile);
11317 + if (IS_ERR(hinofile)) {
11318 + err = PTR_ERR(hinofile);
11323 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11325 + err = au_dr_hino_store(sb, br, hinofile);
11330 + dput(hinopath.dentry);
11333 + au_hn_inode_unlock(hdir);
11335 + inode_unlock(dir);
11341 +/* ---------------------------------------------------------------------- */
11343 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11346 + struct kstatfs kstfs;
11348 + struct dentry *dentry;
11349 + struct super_block *sb;
11351 + err = vfs_statfs((void *)path, &kstfs);
11353 + if (unlikely(err))
11356 + /* todo: support for UUID */
11358 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11359 + brid->type = AuBrid_FSID;
11360 + brid->fsid = kstfs.f_fsid;
11362 + dentry = path->dentry;
11363 + sb = dentry->d_sb;
11366 + brid->type = AuBrid_DEV;
11375 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11376 + const struct path *path)
11379 + struct au_dr_br *dr;
11380 + struct hlist_bl_head *hbl;
11382 + dr = &br->br_dirren;
11383 + hbl = dr->dr_h_ino;
11384 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11385 + INIT_HLIST_BL_HEAD(hbl);
11387 + err = au_dr_brid_init(&dr->dr_brid, path);
11388 + if (unlikely(err))
11391 + if (au_opt_test(au_mntflags(sb), DIRREN))
11392 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11399 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11404 + if (au_br_writable(br->br_perm))
11405 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11407 + au_dr_hino_free(&br->br_dirren);
11412 +/* ---------------------------------------------------------------------- */
11414 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11415 + char *buf, size_t sz)
11418 + unsigned int major, minor;
11422 + err = snprintf(p, sz, "%d_", brid->type);
11423 + AuDebugOn(err > sz);
11426 + switch (brid->type) {
11427 + case AuBrid_Unset:
11429 + case AuBrid_UUID:
11430 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11432 + case AuBrid_FSID:
11433 + err = snprintf(p, sz, "%08x-%08x",
11434 + brid->fsid.val[0], brid->fsid.val[1]);
11437 + major = MAJOR(brid->dev);
11438 + minor = MINOR(brid->dev);
11439 + if (major <= 0xff && minor <= 0xff)
11440 + err = snprintf(p, sz, "%02x%02x", major, minor);
11442 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11445 + AuDebugOn(err > sz);
11448 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11449 + AuDebugOn(err > sz);
11456 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11459 + struct dentry *br_dentry;
11460 + struct inode *br_inode;
11462 + br_dentry = au_br_dentry(br);
11463 + br_inode = d_inode(br_dentry);
11464 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11465 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11466 + AuDebugOn(rlen > len);
11471 +/* ---------------------------------------------------------------------- */
11474 + * from the given @h_dentry, construct drinfo at @*fdata.
11475 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11478 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11479 + struct dentry *h_dentry,
11480 + unsigned char *allocated)
11483 + struct au_drinfo_fdata *f, *p;
11484 + struct au_drinfo *drinfo;
11485 + struct inode *h_inode;
11486 + struct qstr *qname;
11490 + h_inode = d_inode(h_dentry);
11491 + qname = &h_dentry->d_name;
11492 + drinfo = &f->drinfo;
11493 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11494 + drinfo->oldnamelen = qname->len;
11495 + if (*allocated < sizeof(*f) + qname->len) {
11496 + v = roundup_pow_of_two(*allocated + qname->len);
11497 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11498 + if (unlikely(!p)) {
11506 + drinfo = &f->drinfo;
11508 + memcpy(drinfo->oldname, qname->name, qname->len);
11509 + AuDbg("i%llu, %.*s\n",
11510 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11511 + drinfo->oldname);
11518 +/* callers have to free the return value */
11519 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11521 + struct au_drinfo *ret, *drinfo;
11522 + struct au_drinfo_fdata fdata;
11527 + ret = ERR_PTR(-EIO);
11529 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11530 + if (unlikely(ssz != sizeof(fdata))) {
11531 + AuIOErr("ssz %zd, %u, %pD2\n",
11532 + ssz, (unsigned int)sizeof(fdata), file);
11536 + fdata.magic = ntohl((__force __be32)fdata.magic);
11537 + switch (fdata.magic) {
11538 + case AUFS_DRINFO_MAGIC_V1:
11541 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11542 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11546 + drinfo = &fdata.drinfo;
11547 + len = drinfo->oldnamelen;
11549 + AuIOErr("broken drinfo %pD2\n", file);
11554 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11555 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11556 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11557 + (unsigned long long)drinfo->ino,
11558 + (unsigned long long)h_ino, file);
11559 + goto out; /* success */
11562 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11563 + if (unlikely(!ret)) {
11564 + ret = ERR_PTR(-ENOMEM);
11565 + AuTraceErrPtr(ret);
11570 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11571 + if (unlikely(ssz != len)) {
11572 + au_kfree_rcu(ret);
11573 + ret = ERR_PTR(-EIO);
11574 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11578 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11584 +/* ---------------------------------------------------------------------- */
11586 +/* in order to be revertible */
11587 +struct au_drinfo_rev_elm {
11589 + struct dentry *info_dentry;
11590 + struct au_drinfo *info_last;
11593 +struct au_drinfo_rev {
11594 + unsigned char already;
11595 + aufs_bindex_t nelm;
11596 + struct au_drinfo_rev_elm elm[0];
11599 +/* todo: isn't it too large? */
11600 +struct au_drinfo_store {
11601 + struct path h_ppath;
11602 + struct dentry *h_dentry;
11603 + struct au_drinfo_fdata *fdata;
11604 + char *infoname; /* inside of whname, just after PFX */
11605 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11606 + aufs_bindex_t btgt, btail;
11607 + unsigned char no_sio,
11608 + allocated, /* current size of *fdata */
11609 + infonamelen, /* room size for p */
11610 + whnamelen, /* length of the generated name */
11611 + renameback; /* renamed back */
11614 +/* on rename(2) error, the caller should revert it using @elm */
11615 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11616 + struct au_drinfo_rev_elm *elm)
11621 + struct path infopath = {
11622 + .mnt = w->h_ppath.mnt
11624 + struct inode *h_dir, *h_inode, *delegated;
11625 + struct file *infofile;
11626 + struct qstr *qname;
11629 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11631 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11633 + AuTraceErrPtr(infopath.dentry);
11634 + if (IS_ERR(infopath.dentry)) {
11635 + err = PTR_ERR(infopath.dentry);
11640 + h_dir = d_inode(w->h_ppath.dentry);
11641 + if (elm && d_is_negative(infopath.dentry)) {
11642 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11644 + if (unlikely(err))
11646 + elm->created = 1;
11647 + elm->info_dentry = dget(infopath.dentry);
11650 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11651 + AuTraceErrPtr(infofile);
11652 + if (IS_ERR(infofile)) {
11653 + err = PTR_ERR(infofile);
11657 + h_inode = d_inode(infopath.dentry);
11658 + if (elm && i_size_read(h_inode)) {
11659 + h_inode = d_inode(w->h_dentry);
11660 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11661 + AuTraceErrPtr(elm->info_last);
11662 + if (IS_ERR(elm->info_last)) {
11663 + err = PTR_ERR(elm->info_last);
11664 + elm->info_last = NULL;
11665 + AuDebugOn(elm->info_dentry);
11670 + if (elm && w->renameback) {
11671 + delegated = NULL;
11672 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11674 + if (unlikely(err == -EWOULDBLOCK))
11680 + qname = &w->h_dentry->d_name;
11681 + len = sizeof(*w->fdata) + qname->len;
11683 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11684 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11685 + if (ssz == len) {
11686 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11687 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11688 + goto out_fput; /* success */
11693 + /* the caller should revert it using @elm */
11699 + dput(infopath.dentry);
11705 +struct au_call_drinfo_do_store_args {
11707 + struct au_drinfo_store *w;
11708 + struct au_drinfo_rev_elm *elm;
11711 +static void au_call_drinfo_do_store(void *args)
11713 + struct au_call_drinfo_do_store_args *a = args;
11715 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11718 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11719 + struct au_drinfo_rev_elm *elm)
11721 + int err, wkq_err;
11724 + err = au_drinfo_do_store(w, elm);
11726 + struct au_call_drinfo_do_store_args a = {
11731 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11732 + if (unlikely(wkq_err))
11740 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11741 + aufs_bindex_t btgt)
11745 + memset(w, 0, sizeof(*w));
11746 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11747 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11748 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11749 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11751 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11754 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11755 + if (unlikely(!w->fdata)) {
11759 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11766 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11768 + au_kfree_rcu(w->fdata);
11771 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11772 + struct au_drinfo_store *w)
11774 + struct au_drinfo_rev_elm *elm;
11775 + struct inode *h_dir, *delegated;
11777 + struct path infopath = {
11778 + .mnt = w->h_ppath.mnt
11781 + h_dir = d_inode(w->h_ppath.dentry);
11782 + IMustLock(h_dir);
11786 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11787 + AuDebugOn(elm->created && elm->info_last);
11788 + if (elm->created) {
11790 + delegated = NULL;
11791 + infopath.dentry = elm->info_dentry;
11792 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11795 + if (unlikely(err == -EWOULDBLOCK))
11797 + dput(elm->info_dentry);
11798 + } else if (elm->info_last) {
11800 + w->fdata->drinfo = *elm->info_last;
11801 + memcpy(w->fdata->drinfo.oldname,
11802 + elm->info_last->oldname,
11803 + elm->info_last->oldnamelen);
11804 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11805 + au_kfree_rcu(elm->info_last);
11807 + if (unlikely(err))
11808 + AuIOErr("%d, %s\n", err, w->whname);
11809 + /* go on even if err */
11813 +/* caller has to call au_dr_rename_fin() later */
11814 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11815 + struct qstr *dst_name, void *_rev)
11817 + int err, sz, nelm;
11818 + aufs_bindex_t bindex, btail;
11819 + struct au_drinfo_store work;
11820 + struct au_drinfo_rev *rev, **p;
11821 + struct au_drinfo_rev_elm *elm;
11822 + struct super_block *sb;
11823 + struct au_branch *br;
11824 + struct au_hinode *hdir;
11826 + err = au_drinfo_store_work_init(&work, btgt);
11828 + if (unlikely(err))
11832 + btail = au_dbtaildir(dentry);
11833 + nelm = btail - btgt;
11834 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11835 + rev = kcalloc(1, sz, GFP_NOFS);
11836 + if (unlikely(!rev)) {
11840 + rev->nelm = nelm;
11846 + sb = dentry->d_sb;
11847 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11848 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11849 + hdir = au_hi(d_inode(dentry), btgt);
11850 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11851 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11852 + work.h_dentry = au_h_dptr(dentry, bindex);
11853 + if (!work.h_dentry)
11856 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11857 + &work.allocated);
11859 + if (unlikely(err))
11862 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11863 + br = au_sbr(sb, bindex);
11864 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11865 + work.whnamelen += au_drinfo_name(br, work.infoname,
11866 + work.infonamelen);
11867 + AuDbg("whname %.*s, i%llu, %.*s\n",
11868 + work.whnamelen, work.whname,
11869 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11870 + work.fdata->drinfo.oldnamelen,
11871 + work.fdata->drinfo.oldname);
11873 + err = au_drinfo_store_sio(&work, elm);
11875 + if (unlikely(err))
11878 + if (unlikely(err)) {
11879 + /* revert all drinfo */
11880 + au_drinfo_store_rev(rev, &work);
11881 + au_kfree_try_rcu(rev);
11884 + au_hn_inode_unlock(hdir);
11887 + au_drinfo_store_work_fin(&work);
11892 +/* ---------------------------------------------------------------------- */
11894 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11895 + struct qstr *dst_name, void *_rev)
11897 + int err, already;
11899 + struct super_block *sb;
11900 + struct au_branch *br;
11901 + struct au_dr_br *dr;
11902 + struct dentry *h_dentry;
11903 + struct inode *h_inode;
11904 + struct au_dr_hino *ent;
11905 + struct au_drinfo_rev *rev, **p;
11907 + AuDbg("bindex %d\n", bindex);
11910 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11911 + if (unlikely(!ent))
11915 + br = au_sbr(sb, bindex);
11916 + dr = &br->br_dirren;
11917 + h_dentry = au_h_dptr(src, bindex);
11918 + h_inode = d_inode(h_dentry);
11919 + ino = h_inode->i_ino;
11920 + ent->dr_h_ino = ino;
11921 + already = au_dr_hino_test_add(dr, ino, ent);
11922 + AuDbg("b%d, hi%llu, already %d\n",
11923 + bindex, (unsigned long long)ino, already);
11925 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11930 + rev->already = already;
11931 + goto out; /* success */
11936 + au_dr_hino_del(dr, ent);
11937 + au_kfree_rcu(ent);
11944 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11946 + struct au_drinfo_rev *rev;
11947 + struct au_drinfo_rev_elm *elm;
11952 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11953 + dput(elm->info_dentry);
11954 + au_kfree_rcu(elm->info_last);
11956 + au_kfree_try_rcu(rev);
11959 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11962 + struct au_drinfo_store work;
11963 + struct au_drinfo_rev *rev = _rev;
11964 + struct super_block *sb;
11965 + struct au_branch *br;
11966 + struct inode *h_inode;
11967 + struct au_dr_br *dr;
11968 + struct au_dr_hino *ent;
11970 + err = au_drinfo_store_work_init(&work, btgt);
11971 + if (unlikely(err))
11975 + br = au_sbr(sb, btgt);
11976 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11977 + work.h_ppath.mnt = au_br_mnt(br);
11978 + au_drinfo_store_rev(rev, &work);
11979 + au_drinfo_store_work_fin(&work);
11980 + if (rev->already)
11983 + dr = &br->br_dirren;
11984 + h_inode = d_inode(work.h_ppath.dentry);
11985 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11987 + au_dr_hino_del(dr, ent);
11988 + au_kfree_rcu(ent);
11991 + au_kfree_try_rcu(rev);
11992 + if (unlikely(err))
11993 + pr_err("failed to remove dirren info\n");
11996 +/* ---------------------------------------------------------------------- */
11998 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11999 + char *whname, int whnamelen,
12000 + struct dentry **info_dentry)
12002 + struct au_drinfo *drinfo;
12004 + struct inode *h_dir;
12005 + struct path infopath;
12008 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12010 + *info_dentry = NULL;
12013 + h_dir = d_inode(h_ppath->dentry);
12014 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12015 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12017 + if (IS_ERR(infopath.dentry)) {
12018 + drinfo = (void *)infopath.dentry;
12022 + if (d_is_negative(infopath.dentry))
12023 + goto out_dput; /* success */
12025 + infopath.mnt = h_ppath->mnt;
12026 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12027 + inode_unlock_shared(h_dir);
12030 + drinfo = (void *)f;
12034 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12035 + if (IS_ERR_OR_NULL(drinfo))
12038 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12039 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12044 + dput(infopath.dentry);
12047 + inode_unlock_shared(h_dir);
12048 + AuTraceErrPtr(drinfo);
12052 +struct au_drinfo_do_load_args {
12053 + struct au_drinfo **drinfop;
12054 + struct path *h_ppath;
12057 + struct dentry **info_dentry;
12060 +static void au_call_drinfo_do_load(void *args)
12062 + struct au_drinfo_do_load_args *a = args;
12064 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12068 +struct au_drinfo_load {
12069 + struct path h_ppath;
12070 + struct qstr *qname;
12071 + unsigned char no_sio;
12073 + aufs_bindex_t ninfo;
12074 + struct au_drinfo **drinfo;
12077 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12078 + struct au_branch *br)
12080 + int err, wkq_err, whnamelen, e;
12081 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12082 + = AUFS_WH_DR_INFO_PFX;
12083 + struct au_drinfo *drinfo;
12084 + struct qstr oldname;
12085 + struct inode *h_dir, *delegated;
12086 + struct dentry *info_dentry;
12087 + struct path infopath;
12089 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12090 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12091 + sizeof(whname) - whnamelen);
12093 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12096 + struct au_drinfo_do_load_args args = {
12097 + .drinfop = &drinfo,
12098 + .h_ppath = &w->h_ppath,
12099 + .whname = whname,
12100 + .whnamelen = whnamelen,
12101 + .info_dentry = &info_dentry
12103 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12104 + if (unlikely(wkq_err))
12105 + drinfo = ERR_PTR(wkq_err);
12107 + err = PTR_ERR(drinfo);
12108 + if (IS_ERR_OR_NULL(drinfo))
12112 + oldname.len = drinfo->oldnamelen;
12113 + oldname.name = drinfo->oldname;
12114 + if (au_qstreq(w->qname, &oldname)) {
12115 + /* the name is renamed back */
12116 + au_kfree_rcu(drinfo);
12119 + infopath.dentry = info_dentry;
12120 + infopath.mnt = w->h_ppath.mnt;
12121 + h_dir = d_inode(w->h_ppath.dentry);
12122 + delegated = NULL;
12123 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12124 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12125 + inode_unlock(h_dir);
12127 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12128 + if (unlikely(e == -EWOULDBLOCK))
12131 + au_kfree_rcu(w->drinfo[bindex]);
12132 + w->drinfo[bindex] = drinfo;
12133 + dput(info_dentry);
12140 +/* ---------------------------------------------------------------------- */
12142 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12144 + struct au_drinfo **p = drinfo;
12147 + au_kfree_rcu(*drinfo++);
12148 + au_kfree_try_rcu(p);
12151 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12152 + aufs_bindex_t btgt)
12155 + struct au_drinfo_load w;
12156 + aufs_bindex_t bindex, bbot;
12157 + struct au_branch *br;
12158 + struct inode *h_dir;
12159 + struct au_dr_hino *ent;
12160 + struct super_block *sb;
12162 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12163 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12164 + AuLNPair(&lkup->whname), btgt);
12166 + sb = dentry->d_sb;
12167 + bbot = au_sbbot(sb);
12168 + w.ninfo = bbot + 1;
12169 + if (!lkup->dirren.drinfo) {
12170 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12171 + sizeof(*lkup->dirren.drinfo),
12173 + if (unlikely(!lkup->dirren.drinfo)) {
12177 + lkup->dirren.ninfo = w.ninfo;
12179 + w.drinfo = lkup->dirren.drinfo;
12180 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12181 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12182 + AuDebugOn(!w.h_ppath.dentry);
12183 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12184 + w.qname = &dentry->d_name;
12187 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12188 + br = au_sbr(sb, bindex);
12189 + err = au_drinfo_load(&w, bindex, br);
12190 + if (unlikely(err))
12192 + if (w.drinfo[bindex])
12196 + br = au_sbr(sb, btgt);
12197 + h_dir = d_inode(w.h_ppath.dentry);
12198 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12200 + au_dr_hino_del(&br->br_dirren, ent);
12201 + au_kfree_rcu(ent);
12203 + goto out; /* success */
12206 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12207 + lkup->dirren.ninfo = 0;
12208 + lkup->dirren.drinfo = NULL;
12214 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12216 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12219 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12222 + struct au_drinfo *drinfo;
12225 + if (!lkup->dirren.drinfo)
12227 + AuDebugOn(lkup->dirren.ninfo < btgt + 1);
12228 + drinfo = lkup->dirren.drinfo[btgt + 1];
12232 + au_kfree_try_rcu(lkup->whname.name);
12233 + lkup->whname.name = NULL;
12234 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12235 + lkup->dirren.dr_name.name = drinfo->oldname;
12236 + lkup->name = &lkup->dirren.dr_name;
12237 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12239 + AuDbg("name %.*s, whname %.*s, b%d\n",
12240 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12248 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12252 + struct au_drinfo *drinfo;
12255 + if (!lkup->dirren.drinfo)
12257 + AuDebugOn(lkup->dirren.ninfo < bindex + 1);
12258 + drinfo = lkup->dirren.drinfo[bindex + 1];
12262 + match = (drinfo->ino == h_ino);
12263 + AuDbg("match %d\n", match);
12269 +/* ---------------------------------------------------------------------- */
12271 +int au_dr_opt_set(struct super_block *sb)
12274 + aufs_bindex_t bindex, bbot;
12275 + struct au_branch *br;
12278 + bbot = au_sbbot(sb);
12279 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12280 + br = au_sbr(sb, bindex);
12281 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12287 +int au_dr_opt_flush(struct super_block *sb)
12290 + aufs_bindex_t bindex, bbot;
12291 + struct au_branch *br;
12294 + bbot = au_sbbot(sb);
12295 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12296 + br = au_sbr(sb, bindex);
12297 + if (au_br_writable(br->br_perm))
12298 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12304 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12307 + aufs_bindex_t bindex, bbot;
12308 + struct au_branch *br;
12312 + err = au_dr_opt_flush(sb);
12313 + if (unlikely(err))
12317 + bbot = au_sbbot(sb);
12318 + for (bindex = 0; bindex <= bbot; bindex++) {
12319 + br = au_sbr(sb, bindex);
12320 + au_dr_hino_free(&br->br_dirren);
12326 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12327 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 08:00:00.000000000 +0800
12328 +++ linux/fs/aufs/dirren.h 2019-07-11 21:21:54.379051070 +0800
12330 +/* SPDX-License-Identifier: GPL-2.0 */
12332 + * Copyright (C) 2017-2019 Junjiro R. Okajima
12334 + * This program, aufs is free software; you can redistribute it and/or modify
12335 + * it under the terms of the GNU General Public License as published by
12336 + * the Free Software Foundation; either version 2 of the License, or
12337 + * (at your option) any later version.
12339 + * This program is distributed in the hope that it will be useful,
12340 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12341 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12342 + * GNU General Public License for more details.
12344 + * You should have received a copy of the GNU General Public License
12345 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12349 + * renamed dir info
12352 +#ifndef __AUFS_DIRREN_H__
12353 +#define __AUFS_DIRREN_H__
12357 +#include <linux/dcache.h>
12358 +#include <linux/statfs.h>
12359 +#include <linux/uuid.h>
12362 +#define AuDirren_NHASH 100
12364 +#ifdef CONFIG_AUFS_DIRREN
12365 +enum au_brid_type {
12372 +struct au_dr_brid {
12373 + enum au_brid_type type;
12375 + uuid_t uuid; /* unimplemented yet */
12381 +/* 20 is the max digits length of ulong 64 */
12382 +/* brid-type "_" uuid "_" inum */
12383 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12384 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12386 +struct au_dr_hino {
12387 + struct hlist_bl_node dr_hnode;
12392 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12393 + struct au_dr_brid dr_brid;
12396 +struct au_dr_lookup {
12397 + /* dr_name is pointed by struct au_do_lookup_args.name */
12398 + struct qstr dr_name; /* subset of dr_info */
12399 + aufs_bindex_t ninfo;
12400 + struct au_drinfo **drinfo;
12403 +struct au_dr_hino;
12405 +struct au_dr_br { };
12406 +struct au_dr_lookup { };
12409 +/* ---------------------------------------------------------------------- */
12412 +struct au_do_lookup_args;
12414 +#ifdef CONFIG_AUFS_DIRREN
12415 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12416 + struct au_dr_hino *add_ent);
12417 +void au_dr_hino_free(struct au_dr_br *dr);
12418 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12419 + const struct path *path);
12420 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12421 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12422 + struct qstr *dst_name, void *_rev);
12423 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12424 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12425 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12426 + aufs_bindex_t bindex);
12427 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12428 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12430 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12431 +int au_dr_opt_set(struct super_block *sb);
12432 +int au_dr_opt_flush(struct super_block *sb);
12433 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12435 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12436 + struct au_dr_hino *add_ent);
12437 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12438 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12439 + const struct path *path);
12440 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12441 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12442 + struct qstr *dst_name, void *_rev);
12443 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12444 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12446 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12447 + aufs_bindex_t bindex);
12448 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12449 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12450 + aufs_bindex_t bindex, ino_t h_ino);
12451 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12452 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12453 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12454 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12457 +/* ---------------------------------------------------------------------- */
12459 +#ifdef CONFIG_AUFS_DIRREN
12460 +static inline int au_dr_ihash(ino_t h_ino)
12462 + return h_ino % AuDirren_NHASH;
12465 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12468 +#endif /* __KERNEL__ */
12469 +#endif /* __AUFS_DIRREN_H__ */
12470 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12471 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 08:00:00.000000000 +0800
12472 +++ linux/fs/aufs/dynop.c 2019-07-11 21:21:54.379051070 +0800
12474 +// SPDX-License-Identifier: GPL-2.0
12476 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12478 + * This program, aufs is free software; you can redistribute it and/or modify
12479 + * it under the terms of the GNU General Public License as published by
12480 + * the Free Software Foundation; either version 2 of the License, or
12481 + * (at your option) any later version.
12483 + * This program is distributed in the hope that it will be useful,
12484 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12485 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12486 + * GNU General Public License for more details.
12488 + * You should have received a copy of the GNU General Public License
12489 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12493 + * dynamically customizable operations for regular files
12498 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12501 + * How large will these lists be?
12502 + * Usually just a few elements, 20-30 at most for each, I guess.
12504 +static struct hlist_bl_head dynop[AuDyLast];
12506 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12507 + const void *h_op)
12509 + struct au_dykey *key, *tmp;
12510 + struct hlist_bl_node *pos;
12513 + hlist_bl_lock(hbl);
12514 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12515 + if (tmp->dk_op.dy_hop == h_op) {
12516 + if (kref_get_unless_zero(&tmp->dk_kref))
12520 + hlist_bl_unlock(hbl);
12525 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12527 + struct au_dykey **k, *found;
12528 + const void *h_op = key->dk_op.dy_hop;
12532 + k = br->br_dykey;
12533 + for (i = 0; i < AuBrDynOp; i++)
12535 + if (k[i]->dk_op.dy_hop == h_op) {
12542 + spin_lock(&br->br_dykey_lock);
12543 + for (; i < AuBrDynOp; i++)
12545 + if (k[i]->dk_op.dy_hop == h_op) {
12553 + spin_unlock(&br->br_dykey_lock);
12554 + BUG_ON(i == AuBrDynOp); /* expand the array */
12560 +/* kref_get() if @key is already added */
12561 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12563 + struct au_dykey *tmp, *found;
12564 + struct hlist_bl_node *pos;
12565 + const void *h_op = key->dk_op.dy_hop;
12568 + hlist_bl_lock(hbl);
12569 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12570 + if (tmp->dk_op.dy_hop == h_op) {
12571 + if (kref_get_unless_zero(&tmp->dk_kref))
12576 + hlist_bl_add_head(&key->dk_hnode, hbl);
12577 + hlist_bl_unlock(hbl);
12584 +static void dy_free_rcu(struct rcu_head *rcu)
12586 + struct au_dykey *key;
12588 + key = container_of(rcu, struct au_dykey, dk_rcu);
12593 +static void dy_free(struct kref *kref)
12595 + struct au_dykey *key;
12596 + struct hlist_bl_head *hbl;
12598 + key = container_of(kref, struct au_dykey, dk_kref);
12599 + hbl = dynop + key->dk_op.dy_type;
12600 + au_hbl_del(&key->dk_hnode, hbl);
12601 + call_rcu(&key->dk_rcu, dy_free_rcu);
12604 +void au_dy_put(struct au_dykey *key)
12606 + kref_put(&key->dk_kref, dy_free);
12609 +/* ---------------------------------------------------------------------- */
12611 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12613 +#ifdef CONFIG_AUFS_DEBUG
12614 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12615 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12617 +#define DyDbgDeclare(cnt) do {} while (0)
12618 +#define DyDbgInc(cnt) do {} while (0)
12621 +#define DySet(func, dst, src, h_op, h_sb) do { \
12623 + if (h_op->func) { \
12625 + dst.func = src.func; \
12627 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12631 +#define DySetForce(func, dst, src) do { \
12632 + AuDebugOn(!src.func); \
12634 + dst.func = src.func; \
12637 +#define DySetAop(func) \
12638 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12639 +#define DySetAopForce(func) \
12640 + DySetForce(func, dyaop->da_op, aufs_aop)
12642 +static void dy_aop(struct au_dykey *key, const void *h_op,
12643 + struct super_block *h_sb __maybe_unused)
12645 + struct au_dyaop *dyaop = (void *)key;
12646 + const struct address_space_operations *h_aop = h_op;
12647 + DyDbgDeclare(cnt);
12649 + AuDbg("%s\n", au_sbtype(h_sb));
12651 + DySetAop(writepage);
12652 + DySetAopForce(readpage); /* force */
12653 + DySetAop(writepages);
12654 + DySetAop(set_page_dirty);
12655 + DySetAop(readpages);
12656 + DySetAop(write_begin);
12657 + DySetAop(write_end);
12659 + DySetAop(invalidatepage);
12660 + DySetAop(releasepage);
12661 + DySetAop(freepage);
12662 + /* this one will be changed according to an aufs mount option */
12663 + DySetAop(direct_IO);
12664 + DySetAop(migratepage);
12665 + DySetAop(isolate_page);
12666 + DySetAop(putback_page);
12667 + DySetAop(launder_page);
12668 + DySetAop(is_partially_uptodate);
12669 + DySetAop(is_dirty_writeback);
12670 + DySetAop(error_remove_page);
12671 + DySetAop(swap_activate);
12672 + DySetAop(swap_deactivate);
12674 + DyDbgSize(cnt, *h_aop);
12677 +/* ---------------------------------------------------------------------- */
12679 +static void dy_bug(struct kref *kref)
12684 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12686 + struct au_dykey *key, *old;
12687 + struct hlist_bl_head *hbl;
12690 + void (*set)(struct au_dykey *key, const void *h_op,
12691 + struct super_block *h_sb __maybe_unused);
12693 + static const struct op a[] = {
12695 + .sz = sizeof(struct au_dyaop),
12699 + const struct op *p;
12701 + hbl = dynop + op->dy_type;
12702 + key = dy_gfind_get(hbl, op->dy_hop);
12704 + goto out_add; /* success */
12706 + p = a + op->dy_type;
12707 + key = kzalloc(p->sz, GFP_NOFS);
12708 + if (unlikely(!key)) {
12709 + key = ERR_PTR(-ENOMEM);
12713 + key->dk_op.dy_hop = op->dy_hop;
12714 + kref_init(&key->dk_kref);
12715 + p->set(key, op->dy_hop, au_br_sb(br));
12716 + old = dy_gadd(hbl, key);
12718 + au_kfree_rcu(key);
12723 + old = dy_bradd(br, key);
12725 + /* its ref-count should never be zero here */
12726 + kref_put(&key->dk_kref, dy_bug);
12731 +/* ---------------------------------------------------------------------- */
12733 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12734 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12735 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12736 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12737 + * See the aufs manual in detail.
12739 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12742 + dyaop->da_op.direct_IO = NULL;
12744 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12747 +static struct au_dyaop *dy_aget(struct au_branch *br,
12748 + const struct address_space_operations *h_aop,
12751 + struct au_dyaop *dyaop;
12752 + struct au_dynop op;
12754 + op.dy_type = AuDy_AOP;
12755 + op.dy_haop = h_aop;
12756 + dyaop = (void *)dy_get(&op, br);
12757 + if (IS_ERR(dyaop))
12759 + dy_adx(dyaop, do_dx);
12765 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12766 + struct inode *h_inode)
12769 + struct super_block *sb;
12770 + struct au_branch *br;
12771 + struct au_dyaop *dyaop;
12773 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12774 + IiMustWriteLock(inode);
12776 + sb = inode->i_sb;
12777 + br = au_sbr(sb, bindex);
12778 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12779 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12780 + err = PTR_ERR(dyaop);
12781 + if (IS_ERR(dyaop))
12782 + /* unnecessary to call dy_fput() */
12786 + inode->i_mapping->a_ops = &dyaop->da_op;
12793 + * Is it safe to replace a_ops during the inode/file is in operation?
12794 + * Yes, I hope so.
12796 +int au_dy_irefresh(struct inode *inode)
12799 + aufs_bindex_t btop;
12800 + struct inode *h_inode;
12803 + if (S_ISREG(inode->i_mode)) {
12804 + btop = au_ibtop(inode);
12805 + h_inode = au_h_iptr(inode, btop);
12806 + err = au_dy_iaop(inode, btop, h_inode);
12811 +void au_dy_arefresh(int do_dx)
12813 + struct hlist_bl_head *hbl;
12814 + struct hlist_bl_node *pos;
12815 + struct au_dykey *key;
12817 + hbl = dynop + AuDy_AOP;
12818 + hlist_bl_lock(hbl);
12819 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12820 + dy_adx((void *)key, do_dx);
12821 + hlist_bl_unlock(hbl);
12824 +/* ---------------------------------------------------------------------- */
12826 +void __init au_dy_init(void)
12830 + for (i = 0; i < AuDyLast; i++)
12831 + INIT_HLIST_BL_HEAD(dynop + i);
12834 +void au_dy_fin(void)
12838 + for (i = 0; i < AuDyLast; i++)
12839 + WARN_ON(!hlist_bl_empty(dynop + i));
12841 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12842 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 08:00:00.000000000 +0800
12843 +++ linux/fs/aufs/dynop.h 2019-07-11 21:21:54.379051070 +0800
12845 +/* SPDX-License-Identifier: GPL-2.0 */
12847 + * Copyright (C) 2010-2019 Junjiro R. Okajima
12849 + * This program, aufs is free software; you can redistribute it and/or modify
12850 + * it under the terms of the GNU General Public License as published by
12851 + * the Free Software Foundation; either version 2 of the License, or
12852 + * (at your option) any later version.
12854 + * This program is distributed in the hope that it will be useful,
12855 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12856 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12857 + * GNU General Public License for more details.
12859 + * You should have received a copy of the GNU General Public License
12860 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12864 + * dynamically customizable operations (for regular files only)
12867 +#ifndef __AUFS_DYNOP_H__
12868 +#define __AUFS_DYNOP_H__
12872 +#include <linux/fs.h>
12873 +#include <linux/kref.h>
12875 +enum {AuDy_AOP, AuDyLast};
12880 + const void *dy_hop;
12881 + const struct address_space_operations *dy_haop;
12887 + struct hlist_bl_node dk_hnode;
12888 + struct rcu_head dk_rcu;
12890 + struct au_dynop dk_op;
12893 + * during I am in the branch local array, kref is gotten. when the
12894 + * branch is removed, kref is put.
12896 + struct kref dk_kref;
12899 +/* stop unioning since their sizes are very different from each other */
12901 + struct au_dykey da_key;
12902 + struct address_space_operations da_op; /* not const */
12904 +/* make sure that 'struct au_dykey *' can be any type */
12905 +static_assert(!offsetof(struct au_dyaop, da_key));
12907 +/* ---------------------------------------------------------------------- */
12911 +void au_dy_put(struct au_dykey *key);
12912 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12913 + struct inode *h_inode);
12914 +int au_dy_irefresh(struct inode *inode);
12915 +void au_dy_arefresh(int do_dio);
12917 +void __init au_dy_init(void);
12918 +void au_dy_fin(void);
12920 +#endif /* __KERNEL__ */
12921 +#endif /* __AUFS_DYNOP_H__ */
12922 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12923 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 08:00:00.000000000 +0800
12924 +++ linux/fs/aufs/export.c 2019-07-11 21:21:54.379051070 +0800
12926 +// SPDX-License-Identifier: GPL-2.0
12928 + * Copyright (C) 2005-2019 Junjiro R. Okajima
12930 + * This program, aufs is free software; you can redistribute it and/or modify
12931 + * it under the terms of the GNU General Public License as published by
12932 + * the Free Software Foundation; either version 2 of the License, or
12933 + * (at your option) any later version.
12935 + * This program is distributed in the hope that it will be useful,
12936 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12937 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12938 + * GNU General Public License for more details.
12940 + * You should have received a copy of the GNU General Public License
12941 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12948 +#include <linux/exportfs.h>
12949 +#include <linux/fs_struct.h>
12950 +#include <linux/namei.h>
12951 +#include <linux/nsproxy.h>
12952 +#include <linux/random.h>
12953 +#include <linux/writeback.h>
12957 +#ifdef CONFIG_AUFS_INO_T_64
12965 +static ino_t decode_ino(__u32 *a)
12969 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12971 +#ifdef CONFIG_AUFS_INO_T_64
12977 +static void encode_ino(__u32 *a, ino_t ino)
12983 +#ifdef CONFIG_AUFS_INO_T_64
12988 +/* NFS file handle */
12992 +#ifdef CONFIG_AUFS_INO_T_64
12993 + /* support 64bit inode number */
13006 + Fh_ino = Fh_ino1,
13007 + Fh_dir_ino = Fh_dir_ino1
13010 +static int au_test_anon(struct dentry *dentry)
13012 + /* note: read d_flags without d_lock */
13013 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13016 +int au_test_nfsd(void)
13019 + struct task_struct *tsk = current;
13020 + char comm[sizeof(tsk->comm)];
13023 + if (tsk->flags & PF_KTHREAD) {
13024 + get_task_comm(comm, tsk);
13025 + ret = !strcmp(comm, "nfsd");
13031 +/* ---------------------------------------------------------------------- */
13032 +/* inode generation external table */
13034 +void au_xigen_inc(struct inode *inode)
13039 + struct super_block *sb;
13040 + struct au_sbinfo *sbinfo;
13042 + sb = inode->i_sb;
13043 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13045 + sbinfo = au_sbi(sb);
13046 + pos = inode->i_ino;
13047 + pos *= sizeof(igen);
13048 + igen = inode->i_generation + 1;
13049 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13050 + sizeof(igen), &pos);
13051 + if (sz == sizeof(igen))
13052 + return; /* success */
13054 + if (unlikely(sz >= 0))
13055 + AuIOErr("xigen error (%zd)\n", sz);
13058 +int au_xigen_new(struct inode *inode)
13063 + struct super_block *sb;
13064 + struct au_sbinfo *sbinfo;
13065 + struct file *file;
13068 + /* todo: dirty, at mount time */
13069 + if (inode->i_ino == AUFS_ROOT_INO)
13071 + sb = inode->i_sb;
13072 + SiMustAnyLock(sb);
13073 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13077 + pos = inode->i_ino;
13078 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13079 + AuIOErr1("too large i%lld\n", pos);
13082 + pos *= sizeof(inode->i_generation);
13085 + sbinfo = au_sbi(sb);
13086 + file = sbinfo->si_xigen;
13089 + if (vfsub_f_size_read(file)
13090 + < pos + sizeof(inode->i_generation)) {
13091 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13092 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13093 + sizeof(inode->i_generation), &pos);
13095 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13096 + sizeof(inode->i_generation), &pos);
13097 + if (sz == sizeof(inode->i_generation))
13098 + goto out; /* success */
13101 + if (unlikely(sz >= 0)) {
13103 + AuIOErr("xigen error (%zd)\n", sz);
13110 +int au_xigen_set(struct super_block *sb, struct path *path)
13113 + struct au_sbinfo *sbinfo;
13114 + struct file *file;
13116 + SiMustWriteLock(sb);
13118 + sbinfo = au_sbi(sb);
13119 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13120 + err = PTR_ERR(file);
13121 + if (IS_ERR(file))
13124 + if (sbinfo->si_xigen)
13125 + fput(sbinfo->si_xigen);
13126 + sbinfo->si_xigen = file;
13133 +void au_xigen_clr(struct super_block *sb)
13135 + struct au_sbinfo *sbinfo;
13137 + SiMustWriteLock(sb);
13139 + sbinfo = au_sbi(sb);
13140 + if (sbinfo->si_xigen) {
13141 + fput(sbinfo->si_xigen);
13142 + sbinfo->si_xigen = NULL;
13146 +/* ---------------------------------------------------------------------- */
13148 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13151 + struct dentry *dentry, *d;
13152 + struct inode *inode;
13153 + unsigned int sigen;
13156 + inode = ilookup(sb, ino);
13160 + dentry = ERR_PTR(-ESTALE);
13161 + sigen = au_sigen(sb);
13162 + if (unlikely(au_is_bad_inode(inode)
13163 + || IS_DEADDIR(inode)
13164 + || sigen != au_iigen(inode, NULL)))
13168 + if (!dir_ino || S_ISDIR(inode->i_mode))
13169 + dentry = d_find_alias(inode);
13171 + spin_lock(&inode->i_lock);
13172 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13173 + spin_lock(&d->d_lock);
13174 + if (!au_test_anon(d)
13175 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13176 + dentry = dget_dlock(d);
13177 + spin_unlock(&d->d_lock);
13180 + spin_unlock(&d->d_lock);
13182 + spin_unlock(&inode->i_lock);
13184 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13185 + /* need to refresh */
13193 + AuTraceErrPtr(dentry);
13197 +/* ---------------------------------------------------------------------- */
13199 +/* todo: dirty? */
13200 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13202 +struct au_compare_mnt_args {
13204 + struct super_block *sb;
13207 + struct vfsmount *mnt;
13210 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13212 + struct au_compare_mnt_args *a = arg;
13214 + if (mnt->mnt_sb != a->sb)
13216 + a->mnt = mntget(mnt);
13220 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13223 + struct path root;
13224 + struct au_compare_mnt_args args = {
13228 + get_fs_root(current->fs, &root);
13230 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13231 + rcu_read_unlock();
13234 + AuDebugOn(!args.mnt);
13238 +struct au_nfsd_si_lock {
13239 + unsigned int sigen;
13240 + aufs_bindex_t bindex, br_id;
13241 + unsigned char force_lock;
13244 +static int si_nfsd_read_lock(struct super_block *sb,
13245 + struct au_nfsd_si_lock *nsi_lock)
13248 + aufs_bindex_t bindex;
13250 + si_read_lock(sb, AuLock_FLUSH);
13252 + /* branch id may be wrapped around */
13254 + bindex = au_br_index(sb, nsi_lock->br_id);
13255 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13256 + goto out; /* success */
13260 + if (!nsi_lock->force_lock)
13261 + si_read_unlock(sb);
13264 + nsi_lock->bindex = bindex;
13268 +struct find_name_by_ino {
13269 + struct dir_context ctx;
13270 + int called, found;
13277 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13278 + loff_t offset, u64 ino, unsigned int d_type)
13280 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13284 + if (a->ino != ino)
13287 + memcpy(a->name, name, namelen);
13288 + a->namelen = namelen;
13293 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13294 + struct au_nfsd_si_lock *nsi_lock)
13296 + struct dentry *dentry, *parent;
13297 + struct file *file;
13298 + struct inode *dir;
13299 + struct find_name_by_ino arg = {
13301 + .actor = find_name_by_ino
13306 + parent = path->dentry;
13308 + si_read_unlock(parent->d_sb);
13309 + file = vfsub_dentry_open(path, au_dir_roflags);
13310 + dentry = (void *)file;
13311 + if (IS_ERR(file))
13314 + dentry = ERR_PTR(-ENOMEM);
13315 + arg.name = (void *)__get_free_page(GFP_NOFS);
13316 + if (unlikely(!arg.name))
13323 + err = vfsub_iterate_dir(file, &arg.ctx);
13324 + } while (!err && !arg.found && arg.called);
13325 + dentry = ERR_PTR(err);
13326 + if (unlikely(err))
13328 + /* instead of ENOENT */
13329 + dentry = ERR_PTR(-ESTALE);
13333 + /* do not call vfsub_lkup_one() */
13334 + dir = d_inode(parent);
13335 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13336 + AuTraceErrPtr(dentry);
13337 + if (IS_ERR(dentry))
13339 + AuDebugOn(au_test_anon(dentry));
13340 + if (unlikely(d_really_is_negative(dentry))) {
13342 + dentry = ERR_PTR(-ENOENT);
13346 + free_page((unsigned long)arg.name);
13350 + if (unlikely(nsi_lock
13351 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13352 + if (!IS_ERR(dentry)) {
13354 + dentry = ERR_PTR(-ESTALE);
13356 + AuTraceErrPtr(dentry);
13360 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13362 + struct au_nfsd_si_lock *nsi_lock)
13364 + struct dentry *dentry;
13365 + struct path path;
13367 + if (dir_ino != AUFS_ROOT_INO) {
13368 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13369 + dentry = path.dentry;
13370 + if (!path.dentry || IS_ERR(path.dentry))
13372 + AuDebugOn(au_test_anon(path.dentry));
13374 + path.dentry = dget(sb->s_root);
13376 + path.mnt = au_mnt_get(sb);
13377 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13381 + AuTraceErrPtr(dentry);
13385 +/* ---------------------------------------------------------------------- */
13387 +static int h_acceptable(void *expv, struct dentry *dentry)
13392 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13393 + char *buf, int len, struct super_block *sb)
13397 + struct path path;
13399 + p = d_path(h_rootpath, buf, len);
13404 + path.mnt = h_rootpath->mnt;
13405 + path.dentry = h_parent;
13406 + p = d_path(&path, buf, len);
13412 + path.mnt = au_mnt_get(sb);
13413 + path.dentry = sb->s_root;
13414 + p = d_path(&path, buf, len - strlen(p));
13415 + mntput(path.mnt);
13419 + p[strlen(p)] = '/';
13422 + AuTraceErrPtr(p);
13427 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13428 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13430 + struct dentry *dentry, *h_parent, *root;
13431 + struct super_block *h_sb;
13432 + char *pathname, *p;
13433 + struct vfsmount *h_mnt;
13434 + struct au_branch *br;
13436 + struct path path;
13438 + br = au_sbr(sb, nsi_lock->bindex);
13439 + h_mnt = au_br_mnt(br);
13440 + h_sb = h_mnt->mnt_sb;
13441 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13443 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13444 + fh_len - Fh_tail, fh[Fh_h_type],
13445 + h_acceptable, /*context*/NULL);
13447 + dentry = h_parent;
13448 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13449 + AuWarn1("%s decode_fh failed, %ld\n",
13450 + au_sbtype(h_sb), PTR_ERR(h_parent));
13454 + if (unlikely(au_test_anon(h_parent))) {
13455 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13456 + au_sbtype(h_sb));
13457 + goto out_h_parent;
13460 + dentry = ERR_PTR(-ENOMEM);
13461 + pathname = (void *)__get_free_page(GFP_NOFS);
13462 + if (unlikely(!pathname))
13463 + goto out_h_parent;
13465 + root = sb->s_root;
13466 + path.mnt = h_mnt;
13467 + di_read_lock_parent(root, !AuLock_IR);
13468 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13469 + di_read_unlock(root, !AuLock_IR);
13470 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13471 + dentry = (void *)p;
13473 + goto out_pathname;
13475 + si_read_unlock(sb);
13476 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13477 + dentry = ERR_PTR(err);
13478 + if (unlikely(err))
13481 + dentry = ERR_PTR(-ENOENT);
13482 + AuDebugOn(au_test_anon(path.dentry));
13483 + if (unlikely(d_really_is_negative(path.dentry)))
13486 + if (ino != d_inode(path.dentry)->i_ino)
13487 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13489 + dentry = dget(path.dentry);
13494 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13495 + if (!IS_ERR(dentry)) {
13497 + dentry = ERR_PTR(-ESTALE);
13500 + free_page((unsigned long)pathname);
13504 + AuTraceErrPtr(dentry);
13508 +/* ---------------------------------------------------------------------- */
13510 +static struct dentry *
13511 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13514 + struct dentry *dentry;
13515 + __u32 *fh = fid->raw;
13516 + struct au_branch *br;
13517 + ino_t ino, dir_ino;
13518 + struct au_nfsd_si_lock nsi_lock = {
13522 + dentry = ERR_PTR(-ESTALE);
13523 + /* it should never happen, but the file handle is unreliable */
13524 + if (unlikely(fh_len < Fh_tail))
13526 + nsi_lock.sigen = fh[Fh_sigen];
13527 + nsi_lock.br_id = fh[Fh_br_id];
13529 + /* branch id may be wrapped around */
13531 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13533 + nsi_lock.force_lock = 1;
13535 + /* is this inode still cached? */
13536 + ino = decode_ino(fh + Fh_ino);
13537 + /* it should never happen */
13538 + if (unlikely(ino == AUFS_ROOT_INO))
13541 + dir_ino = decode_ino(fh + Fh_dir_ino);
13542 + dentry = decode_by_ino(sb, ino, dir_ino);
13543 + if (IS_ERR(dentry))
13548 + /* is the parent dir cached? */
13549 + br = au_sbr(sb, nsi_lock.bindex);
13550 + au_lcnt_inc(&br->br_nfiles);
13551 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13552 + if (IS_ERR(dentry))
13557 + /* lookup path */
13558 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13559 + if (IS_ERR(dentry))
13561 + if (unlikely(!dentry))
13562 + /* todo?: make it ESTALE */
13566 + if (!au_digen_test(dentry, au_sigen(sb))
13567 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13568 + goto out_unlock; /* success */
13571 + dentry = ERR_PTR(-ESTALE);
13574 + au_lcnt_dec(&br->br_nfiles);
13575 + si_read_unlock(sb);
13577 + AuTraceErrPtr(dentry);
13581 +#if 0 /* reserved for future use */
13582 +/* support subtreecheck option */
13583 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13584 + int fh_len, int fh_type)
13586 + struct dentry *parent;
13587 + __u32 *fh = fid->raw;
13590 + dir_ino = decode_ino(fh + Fh_dir_ino);
13591 + parent = decode_by_ino(sb, dir_ino, 0);
13592 + if (IS_ERR(parent))
13595 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13596 + dir_ino, fh, fh_len);
13599 + AuTraceErrPtr(parent);
13604 +/* ---------------------------------------------------------------------- */
13606 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13607 + struct inode *dir)
13610 + aufs_bindex_t bindex;
13611 + struct super_block *sb, *h_sb;
13612 + struct dentry *dentry, *parent, *h_parent;
13613 + struct inode *h_dir;
13614 + struct au_branch *br;
13617 + if (unlikely(*max_len <= Fh_tail)) {
13618 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13622 + err = FILEID_ROOT;
13623 + if (inode->i_ino == AUFS_ROOT_INO) {
13624 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13629 + sb = inode->i_sb;
13630 + err = si_read_lock(sb, AuLock_FLUSH);
13631 + if (unlikely(err))
13634 +#ifdef CONFIG_AUFS_DEBUG
13635 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13636 + AuWarn1("NFS-exporting requires xino\n");
13640 + ii_read_lock_child(inode);
13641 + bindex = au_ibtop(inode);
13643 + dentry = d_find_any_alias(inode);
13644 + if (unlikely(!dentry))
13646 + AuDebugOn(au_test_anon(dentry));
13647 + parent = dget_parent(dentry);
13649 + if (unlikely(!parent))
13651 + if (d_really_is_positive(parent))
13652 + dir = d_inode(parent);
13655 + ii_read_lock_parent(dir);
13656 + h_dir = au_h_iptr(dir, bindex);
13657 + ii_read_unlock(dir);
13658 + if (unlikely(!h_dir))
13660 + h_parent = d_find_any_alias(h_dir);
13661 + if (unlikely(!h_parent))
13662 + goto out_hparent;
13665 + br = au_sbr(sb, bindex);
13666 + h_sb = au_br_sb(br);
13667 + if (unlikely(!h_sb->s_export_op)) {
13668 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13669 + goto out_hparent;
13672 + fh[Fh_br_id] = br->br_id;
13673 + fh[Fh_sigen] = au_sigen(sb);
13674 + encode_ino(fh + Fh_ino, inode->i_ino);
13675 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13676 + fh[Fh_igen] = inode->i_generation;
13678 + *max_len -= Fh_tail;
13679 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13681 + /*connectable or subtreecheck*/0);
13682 + err = fh[Fh_h_type];
13683 + *max_len += Fh_tail;
13684 + /* todo: macros? */
13685 + if (err != FILEID_INVALID)
13688 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13695 + ii_read_unlock(inode);
13696 + si_read_unlock(sb);
13698 + if (unlikely(err < 0))
13699 + err = FILEID_INVALID;
13703 +/* ---------------------------------------------------------------------- */
13705 +static int aufs_commit_metadata(struct inode *inode)
13708 + aufs_bindex_t bindex;
13709 + struct super_block *sb;
13710 + struct inode *h_inode;
13711 + int (*f)(struct inode *inode);
13713 + sb = inode->i_sb;
13714 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13715 + ii_write_lock_child(inode);
13716 + bindex = au_ibtop(inode);
13717 + AuDebugOn(bindex < 0);
13718 + h_inode = au_h_iptr(inode, bindex);
13720 + f = h_inode->i_sb->s_export_op->commit_metadata;
13722 + err = f(h_inode);
13724 + struct writeback_control wbc = {
13725 + .sync_mode = WB_SYNC_ALL,
13726 + .nr_to_write = 0 /* metadata only */
13729 + err = sync_inode(h_inode, &wbc);
13732 + au_cpup_attr_timesizes(inode);
13733 + ii_write_unlock(inode);
13734 + si_read_unlock(sb);
13738 +/* ---------------------------------------------------------------------- */
13740 +static struct export_operations aufs_export_op = {
13741 + .fh_to_dentry = aufs_fh_to_dentry,
13742 + /* .fh_to_parent = aufs_fh_to_parent, */
13743 + .encode_fh = aufs_encode_fh,
13744 + .commit_metadata = aufs_commit_metadata
13747 +void au_export_init(struct super_block *sb)
13749 + struct au_sbinfo *sbinfo;
13752 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13753 + && IS_MODULE(CONFIG_EXPORTFS),
13754 + AUFS_NAME ": unsupported configuration "
13755 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13757 + sb->s_export_op = &aufs_export_op;
13758 + sbinfo = au_sbi(sb);
13759 + sbinfo->si_xigen = NULL;
13760 + get_random_bytes(&u, sizeof(u));
13761 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13762 + atomic_set(&sbinfo->si_xigen_next, u);
13764 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13765 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 08:00:00.000000000 +0800
13766 +++ linux/fs/aufs/fhsm.c 2019-07-11 21:21:54.379051070 +0800
13768 +// SPDX-License-Identifier: GPL-2.0
13770 + * Copyright (C) 2011-2019 Junjiro R. Okajima
13772 + * This program, aufs is free software; you can redistribute it and/or modify
13773 + * it under the terms of the GNU General Public License as published by
13774 + * the Free Software Foundation; either version 2 of the License, or
13775 + * (at your option) any later version.
13777 + * This program is distributed in the hope that it will be useful,
13778 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13779 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13780 + * GNU General Public License for more details.
13782 + * You should have received a copy of the GNU General Public License
13783 + * along with this program; if not, write to the Free Software
13784 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13788 + * File-based Hierarchy Storage Management
13791 +#include <linux/anon_inodes.h>
13792 +#include <linux/poll.h>
13793 +#include <linux/seq_file.h>
13794 +#include <linux/statfs.h>
13797 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13799 + struct au_sbinfo *sbinfo;
13800 + struct au_fhsm *fhsm;
13802 + SiMustAnyLock(sb);
13804 + sbinfo = au_sbi(sb);
13805 + fhsm = &sbinfo->si_fhsm;
13806 + AuDebugOn(!fhsm);
13807 + return fhsm->fhsm_bottom;
13810 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13812 + struct au_sbinfo *sbinfo;
13813 + struct au_fhsm *fhsm;
13815 + SiMustWriteLock(sb);
13817 + sbinfo = au_sbi(sb);
13818 + fhsm = &sbinfo->si_fhsm;
13819 + AuDebugOn(!fhsm);
13820 + fhsm->fhsm_bottom = bindex;
13823 +/* ---------------------------------------------------------------------- */
13825 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13827 + struct au_br_fhsm *bf;
13829 + bf = br->br_fhsm;
13830 + MtxMustLock(&bf->bf_lock);
13832 + return !bf->bf_readable
13833 + || time_after(jiffies,
13834 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13837 +/* ---------------------------------------------------------------------- */
13839 +static void au_fhsm_notify(struct super_block *sb, int val)
13841 + struct au_sbinfo *sbinfo;
13842 + struct au_fhsm *fhsm;
13844 + SiMustAnyLock(sb);
13846 + sbinfo = au_sbi(sb);
13847 + fhsm = &sbinfo->si_fhsm;
13848 + if (au_fhsm_pid(fhsm)
13849 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13850 + atomic_set(&fhsm->fhsm_readable, val);
13852 + wake_up(&fhsm->fhsm_wqh);
13856 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13857 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13860 + struct au_branch *br;
13861 + struct au_br_fhsm *bf;
13863 + br = au_sbr(sb, bindex);
13864 + AuDebugOn(au_br_rdonly(br));
13865 + bf = br->br_fhsm;
13869 + mutex_lock(&bf->bf_lock);
13871 + MtxMustLock(&bf->bf_lock);
13873 + /* sb->s_root for NFS is unreliable */
13874 + err = au_br_stfs(br, &bf->bf_stfs);
13875 + if (unlikely(err)) {
13876 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13880 + bf->bf_jiffy = jiffies;
13881 + bf->bf_readable = 1;
13883 + au_fhsm_notify(sb, /*val*/1);
13885 + *rstfs = bf->bf_stfs;
13889 + mutex_unlock(&bf->bf_lock);
13890 + au_fhsm_notify(sb, /*val*/1);
13895 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13898 + struct au_sbinfo *sbinfo;
13899 + struct au_fhsm *fhsm;
13900 + struct au_branch *br;
13901 + struct au_br_fhsm *bf;
13903 + AuDbg("b%d, force %d\n", bindex, force);
13904 + SiMustAnyLock(sb);
13906 + sbinfo = au_sbi(sb);
13907 + fhsm = &sbinfo->si_fhsm;
13908 + if (!au_ftest_si(sbinfo, FHSM)
13909 + || fhsm->fhsm_bottom == bindex)
13912 + br = au_sbr(sb, bindex);
13913 + bf = br->br_fhsm;
13915 + mutex_lock(&bf->bf_lock);
13917 + || au_fhsm_pid(fhsm)
13918 + || au_fhsm_test_jiffy(sbinfo, br))
13919 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13921 + mutex_unlock(&bf->bf_lock);
13924 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13926 + aufs_bindex_t bindex, bbot;
13927 + struct au_branch *br;
13929 + /* exclude the bottom */
13930 + bbot = au_fhsm_bottom(sb);
13931 + for (bindex = 0; bindex < bbot; bindex++) {
13932 + br = au_sbr(sb, bindex);
13933 + if (au_br_fhsm(br->br_perm))
13934 + au_fhsm_wrote(sb, bindex, force);
13938 +/* ---------------------------------------------------------------------- */
13940 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13943 + struct au_sbinfo *sbinfo;
13944 + struct au_fhsm *fhsm;
13947 + sbinfo = file->private_data;
13948 + fhsm = &sbinfo->si_fhsm;
13949 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13950 + if (atomic_read(&fhsm->fhsm_readable))
13951 + mask = EPOLLIN /* | EPOLLRDNORM */;
13954 + AuDbg("mask 0x%x\n", mask);
13958 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13959 + struct aufs_stfs *stfs, __s16 brid)
13963 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13965 + err = __put_user(brid, &stbr->brid);
13966 + if (unlikely(err))
13972 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13973 + struct aufs_stbr __user *stbr, size_t count)
13977 + aufs_bindex_t bindex, bbot;
13978 + struct au_branch *br;
13979 + struct au_br_fhsm *bf;
13981 + /* except the bottom branch */
13984 + bbot = au_fhsm_bottom(sb);
13985 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13986 + br = au_sbr(sb, bindex);
13987 + if (!au_br_fhsm(br->br_perm))
13990 + bf = br->br_fhsm;
13991 + mutex_lock(&bf->bf_lock);
13992 + if (bf->bf_readable) {
13994 + if (count >= sizeof(*stbr))
13995 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13998 + bf->bf_readable = 0;
13999 + count -= sizeof(*stbr);
14003 + mutex_unlock(&bf->bf_lock);
14006 + err = sizeof(*stbr) * nstbr;
14011 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14016 + aufs_bindex_t nfhsm, bindex, bbot;
14017 + struct au_sbinfo *sbinfo;
14018 + struct au_fhsm *fhsm;
14019 + struct au_branch *br;
14020 + struct super_block *sb;
14023 + sbinfo = file->private_data;
14024 + fhsm = &sbinfo->si_fhsm;
14026 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14027 + if (!atomic_read(&fhsm->fhsm_readable)) {
14028 + if (vfsub_file_flags(file) & O_NONBLOCK)
14031 + err = wait_event_interruptible_locked_irq
14033 + atomic_read(&fhsm->fhsm_readable));
14035 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14036 + if (unlikely(err))
14039 + /* sb may already be dead */
14040 + au_rw_read_lock(&sbinfo->si_rwsem);
14041 + readable = atomic_read(&fhsm->fhsm_readable);
14042 + if (readable > 0) {
14043 + sb = sbinfo->si_sb;
14045 + /* exclude the bottom branch */
14047 + bbot = au_fhsm_bottom(sb);
14048 + for (bindex = 0; bindex < bbot; bindex++) {
14049 + br = au_sbr(sb, bindex);
14050 + if (au_br_fhsm(br->br_perm))
14054 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14055 + atomic_set(&fhsm->fhsm_readable, 0);
14056 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14060 + au_rw_read_unlock(&sbinfo->si_rwsem);
14068 +static int au_fhsm_release(struct inode *inode, struct file *file)
14070 + struct au_sbinfo *sbinfo;
14071 + struct au_fhsm *fhsm;
14073 + /* sb may already be dead */
14074 + sbinfo = file->private_data;
14075 + fhsm = &sbinfo->si_fhsm;
14076 + spin_lock(&fhsm->fhsm_spin);
14077 + fhsm->fhsm_pid = 0;
14078 + spin_unlock(&fhsm->fhsm_spin);
14079 + kobject_put(&sbinfo->si_kobj);
14084 +static const struct file_operations au_fhsm_fops = {
14085 + .owner = THIS_MODULE,
14086 + .llseek = noop_llseek,
14087 + .read = au_fhsm_read,
14088 + .poll = au_fhsm_poll,
14089 + .release = au_fhsm_release
14092 +int au_fhsm_fd(struct super_block *sb, int oflags)
14095 + struct au_sbinfo *sbinfo;
14096 + struct au_fhsm *fhsm;
14099 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14103 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14107 + sbinfo = au_sbi(sb);
14108 + fhsm = &sbinfo->si_fhsm;
14109 + spin_lock(&fhsm->fhsm_spin);
14110 + if (!fhsm->fhsm_pid)
14111 + fhsm->fhsm_pid = current->pid;
14114 + spin_unlock(&fhsm->fhsm_spin);
14115 + if (unlikely(err))
14118 + oflags |= O_RDONLY;
14119 + /* oflags |= FMODE_NONOTIFY; */
14120 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14122 + if (unlikely(fd < 0))
14125 + /* succeed regardless 'fhsm' status */
14126 + kobject_get(&sbinfo->si_kobj);
14127 + si_noflush_read_lock(sb);
14128 + if (au_ftest_si(sbinfo, FHSM))
14129 + au_fhsm_wrote_all(sb, /*force*/0);
14130 + si_read_unlock(sb);
14131 + goto out; /* success */
14134 + spin_lock(&fhsm->fhsm_spin);
14135 + fhsm->fhsm_pid = 0;
14136 + spin_unlock(&fhsm->fhsm_spin);
14142 +/* ---------------------------------------------------------------------- */
14144 +int au_fhsm_br_alloc(struct au_branch *br)
14149 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14151 + au_br_fhsm_init(br->br_fhsm);
14158 +/* ---------------------------------------------------------------------- */
14160 +void au_fhsm_fin(struct super_block *sb)
14162 + au_fhsm_notify(sb, /*val*/-1);
14165 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14167 + struct au_fhsm *fhsm;
14169 + fhsm = &sbinfo->si_fhsm;
14170 + spin_lock_init(&fhsm->fhsm_spin);
14171 + init_waitqueue_head(&fhsm->fhsm_wqh);
14172 + atomic_set(&fhsm->fhsm_readable, 0);
14173 + fhsm->fhsm_expire
14174 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14175 + fhsm->fhsm_bottom = -1;
14178 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14180 + sbinfo->si_fhsm.fhsm_expire
14181 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14184 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14188 + if (!au_ftest_si(sbinfo, FHSM))
14191 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14192 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14193 + seq_printf(seq, ",fhsm_sec=%u", u);
14195 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14196 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 08:00:00.000000000 +0800
14197 +++ linux/fs/aufs/file.c 2019-07-11 21:21:54.379051070 +0800
14199 +// SPDX-License-Identifier: GPL-2.0
14201 + * Copyright (C) 2005-2019 Junjiro R. Okajima
14203 + * This program, aufs is free software; you can redistribute it and/or modify
14204 + * it under the terms of the GNU General Public License as published by
14205 + * the Free Software Foundation; either version 2 of the License, or
14206 + * (at your option) any later version.
14208 + * This program is distributed in the hope that it will be useful,
14209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14211 + * GNU General Public License for more details.
14213 + * You should have received a copy of the GNU General Public License
14214 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14218 + * handling file/dir, and address_space operation
14221 +#ifdef CONFIG_AUFS_DEBUG
14222 +#include <linux/migrate.h>
14224 +#include <linux/pagemap.h>
14227 +/* drop flags for writing */
14228 +unsigned int au_file_roflags(unsigned int flags)
14230 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14231 + flags |= O_RDONLY | O_NOATIME;
14235 +/* common functions to regular file and dir */
14236 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14237 + struct file *file, int force_wr)
14239 + struct file *h_file;
14240 + struct dentry *h_dentry;
14241 + struct inode *h_inode;
14242 + struct super_block *sb;
14243 + struct au_branch *br;
14244 + struct path h_path;
14247 + /* a race condition can happen between open and unlink/rmdir */
14248 + h_file = ERR_PTR(-ENOENT);
14249 + h_dentry = au_h_dptr(dentry, bindex);
14250 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14252 + h_inode = d_inode(h_dentry);
14253 + spin_lock(&h_dentry->d_lock);
14254 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14255 + /* || !d_inode(dentry)->i_nlink */
14257 + spin_unlock(&h_dentry->d_lock);
14258 + if (unlikely(err))
14261 + sb = dentry->d_sb;
14262 + br = au_sbr(sb, bindex);
14263 + err = au_br_test_oflag(flags, br);
14264 + h_file = ERR_PTR(err);
14265 + if (unlikely(err))
14268 + /* drop flags for writing */
14269 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14270 + if (force_wr && !(flags & O_WRONLY))
14272 + flags = au_file_roflags(flags);
14274 + h_file = ERR_PTR(-EROFS);
14275 + flags = au_file_roflags(flags);
14276 + if (unlikely(vfsub_native_ro(h_inode)
14277 + || IS_APPEND(h_inode)))
14279 + flags &= ~O_ACCMODE;
14280 + flags |= O_WRONLY;
14283 + flags &= ~O_CREAT;
14284 + au_lcnt_inc(&br->br_nfiles);
14285 + h_path.dentry = h_dentry;
14286 + h_path.mnt = au_br_mnt(br);
14287 + h_file = vfsub_dentry_open(&h_path, flags);
14288 + if (IS_ERR(h_file))
14291 + if (flags & __FMODE_EXEC) {
14292 + err = deny_write_access(h_file);
14293 + if (unlikely(err)) {
14295 + h_file = ERR_PTR(err);
14299 + fsnotify_open(h_file);
14300 + goto out; /* success */
14303 + au_lcnt_dec(&br->br_nfiles);
14308 +static int au_cmoo(struct dentry *dentry)
14310 + int err, cmoo, matched;
14311 + unsigned int udba;
14312 + struct path h_path;
14313 + struct au_pin pin;
14314 + struct au_cp_generic cpg = {
14315 + .dentry = dentry,
14320 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14322 + struct inode *delegated;
14323 + struct super_block *sb;
14324 + struct au_sbinfo *sbinfo;
14325 + struct au_fhsm *fhsm;
14327 + struct au_branch *br;
14328 + struct dentry *parent;
14329 + struct au_hinode *hdir;
14331 + DiMustWriteLock(dentry);
14332 + IiMustWriteLock(d_inode(dentry));
14335 + if (IS_ROOT(dentry))
14337 + cpg.bsrc = au_dbtop(dentry);
14341 + sb = dentry->d_sb;
14342 + sbinfo = au_sbi(sb);
14343 + fhsm = &sbinfo->si_fhsm;
14344 + pid = au_fhsm_pid(fhsm);
14347 + && (current->pid == pid
14348 + || rcu_dereference(current->real_parent)->pid == pid));
14349 + rcu_read_unlock();
14353 + br = au_sbr(sb, cpg.bsrc);
14354 + cmoo = au_br_cmoo(br->br_perm);
14357 + if (!d_is_reg(dentry))
14358 + cmoo &= AuBrAttr_COO_ALL;
14362 + parent = dget_parent(dentry);
14363 + di_write_lock_parent(parent);
14364 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14366 + if (unlikely(err < 0)) {
14367 + err = 0; /* there is no upper writable branch */
14370 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14372 + /* do not respect the coo attrib for the target branch */
14373 + err = au_cpup_dirs(dentry, cpg.bdst);
14374 + if (unlikely(err))
14377 + di_downgrade_lock(parent, AuLock_IR);
14378 + udba = au_opt_udba(sb);
14379 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14380 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14381 + if (unlikely(err))
14384 + err = au_sio_cpup_simple(&cpg);
14386 + if (unlikely(err))
14388 + if (!(cmoo & AuBrWAttr_MOO))
14389 + goto out_parent; /* success */
14391 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14392 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14393 + if (unlikely(err))
14396 + h_path.mnt = au_br_mnt(br);
14397 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14398 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14399 + delegated = NULL;
14400 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14402 + /* todo: keep h_dentry or not? */
14403 + if (unlikely(err == -EWOULDBLOCK)) {
14404 + pr_warn("cannot retry for NFSv4 delegation"
14405 + " for an internal unlink\n");
14408 + if (unlikely(err)) {
14409 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14413 + goto out_parent; /* success */
14416 + di_downgrade_lock(parent, AuLock_IR);
14418 + di_read_unlock(parent, AuLock_IR);
14425 +int au_do_open(struct file *file, struct au_do_open_args *args)
14427 + int err, aopen = args->aopen;
14428 + struct dentry *dentry;
14429 + struct au_finfo *finfo;
14432 + err = au_finfo_init(file, args->fidir);
14435 + err = au_finfo_init(file, args->fidir);
14438 + if (unlikely(err))
14441 + dentry = file->f_path.dentry;
14442 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14443 + di_write_lock_child(dentry);
14444 + err = au_cmoo(dentry);
14445 + di_downgrade_lock(dentry, AuLock_IR);
14448 + err = args->open(file, vfsub_file_flags(file), NULL);
14451 + err = args->open(file, vfsub_file_flags(file),
14456 + di_read_unlock(dentry, AuLock_IR);
14458 + finfo = au_fi(file);
14460 + finfo->fi_file = file;
14461 + au_hbl_add(&finfo->fi_hlist,
14462 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14465 + fi_write_unlock(file);
14468 + fi_write_unlock(file);
14471 + if (unlikely(err)) {
14472 + finfo->fi_hdir = NULL;
14473 + au_finfo_fin(file);
14481 +int au_reopen_nondir(struct file *file)
14484 + aufs_bindex_t btop;
14485 + struct dentry *dentry;
14486 + struct au_branch *br;
14487 + struct file *h_file, *h_file_tmp;
14489 + dentry = file->f_path.dentry;
14490 + btop = au_dbtop(dentry);
14491 + br = au_sbr(dentry->d_sb, btop);
14492 + h_file_tmp = NULL;
14493 + if (au_fbtop(file) == btop) {
14494 + h_file = au_hf_top(file);
14495 + if (file->f_mode == h_file->f_mode)
14496 + return 0; /* success */
14497 + h_file_tmp = h_file;
14498 + get_file(h_file_tmp);
14499 + au_lcnt_inc(&br->br_nfiles);
14500 + au_set_h_fptr(file, btop, NULL);
14502 + AuDebugOn(au_fi(file)->fi_hdir);
14505 + * file exists on both of rw and ro
14506 + * open --> dbtop and fbtop are both 0
14507 + * prepend a branch as rw, "rw" become ro
14509 + * delete the top branch, "rw" becomes rw again
14510 + * --> dbtop is 1, fbtop is still 0
14511 + * write --> fbtop is 0 but dbtop is 1
14513 + /* AuDebugOn(au_fbtop(file) < btop); */
14515 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14516 + file, /*force_wr*/0);
14517 + err = PTR_ERR(h_file);
14518 + if (IS_ERR(h_file)) {
14519 + if (h_file_tmp) {
14521 + au_set_h_fptr(file, btop, h_file_tmp);
14522 + h_file_tmp = NULL;
14524 + goto out; /* todo: close all? */
14528 + au_set_fbtop(file, btop);
14529 + au_set_h_fptr(file, btop, h_file);
14530 + au_update_figen(file);
14531 + /* todo: necessary? */
14532 + /* file->f_ra = h_file->f_ra; */
14535 + if (h_file_tmp) {
14536 + fput(h_file_tmp);
14537 + au_lcnt_dec(&br->br_nfiles);
14542 +/* ---------------------------------------------------------------------- */
14544 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14545 + struct dentry *hi_wh)
14548 + aufs_bindex_t btop;
14549 + struct au_dinfo *dinfo;
14550 + struct dentry *h_dentry;
14551 + struct au_hdentry *hdp;
14553 + dinfo = au_di(file->f_path.dentry);
14554 + AuRwMustWriteLock(&dinfo->di_rwsem);
14556 + btop = dinfo->di_btop;
14557 + dinfo->di_btop = btgt;
14558 + hdp = au_hdentry(dinfo, btgt);
14559 + h_dentry = hdp->hd_dentry;
14560 + hdp->hd_dentry = hi_wh;
14561 + err = au_reopen_nondir(file);
14562 + hdp->hd_dentry = h_dentry;
14563 + dinfo->di_btop = btop;
14568 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14569 + aufs_bindex_t bcpup, struct au_pin *pin)
14572 + struct inode *inode, *h_inode;
14573 + struct dentry *h_dentry, *hi_wh;
14574 + struct au_cp_generic cpg = {
14575 + .dentry = file->f_path.dentry,
14582 + au_update_dbtop(cpg.dentry);
14583 + inode = d_inode(cpg.dentry);
14585 + if (au_dbtop(cpg.dentry) <= bcpup
14586 + && au_dbbot(cpg.dentry) >= bcpup) {
14587 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14588 + if (h_dentry && d_is_positive(h_dentry))
14589 + h_inode = d_inode(h_dentry);
14591 + hi_wh = au_hi_wh(inode, bcpup);
14592 + if (!hi_wh && !h_inode)
14593 + err = au_sio_cpup_wh(&cpg, file);
14595 + /* already copied-up after unlink */
14596 + err = au_reopen_wh(file, bcpup, hi_wh);
14599 + && (inode->i_nlink > 1
14600 + || (inode->i_state & I_LINKABLE))
14601 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14602 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14608 + * prepare the @file for writing.
14610 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14613 + aufs_bindex_t dbtop;
14614 + struct dentry *parent;
14615 + struct inode *inode;
14616 + struct super_block *sb;
14617 + struct file *h_file;
14618 + struct au_cp_generic cpg = {
14619 + .dentry = file->f_path.dentry,
14624 + .flags = AuCpup_DTIME
14627 + sb = cpg.dentry->d_sb;
14628 + inode = d_inode(cpg.dentry);
14629 + cpg.bsrc = au_fbtop(file);
14630 + err = au_test_ro(sb, cpg.bsrc, inode);
14631 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14632 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14637 + /* need to cpup or reopen */
14638 + parent = dget_parent(cpg.dentry);
14639 + di_write_lock_parent(parent);
14640 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14642 + if (unlikely(err < 0))
14646 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14647 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14648 + if (unlikely(err))
14652 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14653 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14654 + if (unlikely(err))
14657 + dbtop = au_dbtop(cpg.dentry);
14658 + if (dbtop <= cpg.bdst)
14659 + cpg.bsrc = cpg.bdst;
14661 + if (dbtop <= cpg.bdst /* just reopen */
14662 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14664 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14665 + if (IS_ERR(h_file))
14666 + err = PTR_ERR(h_file);
14668 + di_downgrade_lock(parent, AuLock_IR);
14669 + if (dbtop > cpg.bdst)
14670 + err = au_sio_cpup_simple(&cpg);
14672 + err = au_reopen_nondir(file);
14673 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14675 + } else { /* copyup as wh and reopen */
14677 + * since writable hfsplus branch is not supported,
14678 + * h_open_pre/post() are unnecessary.
14680 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14681 + di_downgrade_lock(parent, AuLock_IR);
14685 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14686 + goto out_dput; /* success */
14692 + di_downgrade_lock(parent, AuLock_IR);
14694 + di_read_unlock(parent, AuLock_IR);
14701 +/* ---------------------------------------------------------------------- */
14703 +int au_do_flush(struct file *file, fl_owner_t id,
14704 + int (*flush)(struct file *file, fl_owner_t id))
14707 + struct super_block *sb;
14708 + struct inode *inode;
14710 + inode = file_inode(file);
14711 + sb = inode->i_sb;
14712 + si_noflush_read_lock(sb);
14713 + fi_read_lock(file);
14714 + ii_read_lock_child(inode);
14716 + err = flush(file, id);
14717 + au_cpup_attr_timesizes(inode);
14719 + ii_read_unlock(inode);
14720 + fi_read_unlock(file);
14721 + si_read_unlock(sb);
14725 +/* ---------------------------------------------------------------------- */
14727 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14730 + struct au_pin pin;
14731 + struct au_finfo *finfo;
14732 + struct dentry *parent, *hi_wh;
14733 + struct inode *inode;
14734 + struct super_block *sb;
14735 + struct au_cp_generic cpg = {
14736 + .dentry = file->f_path.dentry,
14741 + .flags = AuCpup_DTIME
14744 + FiMustWriteLock(file);
14747 + finfo = au_fi(file);
14748 + sb = cpg.dentry->d_sb;
14749 + inode = d_inode(cpg.dentry);
14750 + cpg.bdst = au_ibtop(inode);
14751 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14754 + parent = dget_parent(cpg.dentry);
14755 + if (au_test_ro(sb, cpg.bdst, inode)) {
14756 + di_read_lock_parent(parent, !AuLock_IR);
14757 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14759 + di_read_unlock(parent, !AuLock_IR);
14760 + if (unlikely(err < 0))
14765 + di_read_lock_parent(parent, AuLock_IR);
14766 + hi_wh = au_hi_wh(inode, cpg.bdst);
14767 + if (!S_ISDIR(inode->i_mode)
14768 + && au_opt_test(au_mntflags(sb), PLINK)
14769 + && au_plink_test(inode)
14770 + && !d_unhashed(cpg.dentry)
14771 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14772 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14773 + if (unlikely(err))
14776 + /* always superio. */
14777 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14778 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14780 + err = au_sio_cpup_simple(&cpg);
14783 + } else if (hi_wh) {
14784 + /* already copied-up after unlink */
14785 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14786 + *need_reopen = 0;
14790 + di_read_unlock(parent, AuLock_IR);
14797 +static void au_do_refresh_dir(struct file *file)
14799 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14800 + struct au_hfile *p, tmp, *q;
14801 + struct au_finfo *finfo;
14802 + struct super_block *sb;
14803 + struct au_fidir *fidir;
14805 + FiMustWriteLock(file);
14807 + sb = file->f_path.dentry->d_sb;
14808 + finfo = au_fi(file);
14809 + fidir = finfo->fi_hdir;
14810 + AuDebugOn(!fidir);
14811 + p = fidir->fd_hfile + finfo->fi_btop;
14812 + brid = p->hf_br->br_id;
14813 + bbot = fidir->fd_bbot;
14814 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14818 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14819 + if (new_bindex == bindex)
14821 + if (new_bindex < 0) {
14822 + au_set_h_fptr(file, bindex, NULL);
14826 + /* swap two lower inode, and loop again */
14827 + q = fidir->fd_hfile + new_bindex;
14831 + if (tmp.hf_file) {
14837 + p = fidir->fd_hfile;
14838 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14839 + bbot = au_sbbot(sb);
14840 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14841 + finfo->fi_btop++, p++)
14842 + if (p->hf_file) {
14843 + if (file_inode(p->hf_file))
14845 + au_hfput(p, /*execed*/0);
14848 + bbot = au_br_index(sb, brid);
14849 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14850 + finfo->fi_btop++, p++)
14852 + au_hfput(p, /*execed*/0);
14853 + bbot = au_sbbot(sb);
14856 + p = fidir->fd_hfile + bbot;
14857 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14858 + fidir->fd_bbot--, p--)
14859 + if (p->hf_file) {
14860 + if (file_inode(p->hf_file))
14862 + au_hfput(p, /*execed*/0);
14864 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14868 + * after branch manipulating, refresh the file.
14870 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14872 + int err, need_reopen, nbr;
14873 + aufs_bindex_t bbot, bindex;
14874 + struct dentry *dentry;
14875 + struct super_block *sb;
14876 + struct au_finfo *finfo;
14877 + struct au_hfile *hfile;
14879 + dentry = file->f_path.dentry;
14880 + sb = dentry->d_sb;
14881 + nbr = au_sbbot(sb) + 1;
14882 + finfo = au_fi(file);
14883 + if (!finfo->fi_hdir) {
14884 + hfile = &finfo->fi_htop;
14885 + AuDebugOn(!hfile->hf_file);
14886 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14887 + AuDebugOn(bindex < 0);
14888 + if (bindex != finfo->fi_btop)
14889 + au_set_fbtop(file, bindex);
14891 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14892 + if (unlikely(err))
14894 + au_do_refresh_dir(file);
14899 + if (!au_test_mmapped(file))
14900 + err = au_file_refresh_by_inode(file, &need_reopen);
14901 + if (finfo->fi_hdir)
14902 + /* harmless if err */
14903 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14904 + if (!err && need_reopen && !d_unlinked(dentry))
14905 + err = reopen(file);
14907 + au_update_figen(file);
14908 + goto out; /* success */
14911 + /* error, close all lower files */
14912 + if (finfo->fi_hdir) {
14913 + bbot = au_fbbot_dir(file);
14914 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14915 + au_set_h_fptr(file, bindex, NULL);
14922 +/* common function to regular file and dir */
14923 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14924 + int wlock, unsigned int fi_lsc)
14927 + unsigned int sigen, figen;
14928 + aufs_bindex_t btop;
14929 + unsigned char pseudo_link;
14930 + struct dentry *dentry;
14931 + struct inode *inode;
14934 + dentry = file->f_path.dentry;
14935 + inode = d_inode(dentry);
14936 + sigen = au_sigen(dentry->d_sb);
14937 + fi_write_lock_nested(file, fi_lsc);
14938 + figen = au_figen(file);
14940 + di_write_lock_child(dentry);
14942 + di_write_lock_child2(dentry);
14943 + btop = au_dbtop(dentry);
14944 + pseudo_link = (btop != au_ibtop(inode));
14945 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14947 + di_downgrade_lock(dentry, AuLock_IR);
14948 + fi_downgrade_lock(file);
14950 + goto out; /* success */
14953 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14954 + if (au_digen_test(dentry, sigen)) {
14955 + err = au_reval_dpath(dentry, sigen);
14956 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14960 + err = refresh_file(file, reopen);
14963 + di_downgrade_lock(dentry, AuLock_IR);
14964 + fi_downgrade_lock(file);
14967 + di_write_unlock(dentry);
14968 + fi_write_unlock(file);
14975 +/* ---------------------------------------------------------------------- */
14977 +/* cf. aufs_nopage() */
14978 +/* for madvise(2) */
14979 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14981 + unlock_page(page);
14985 +/* it will never be called, but necessary to support O_DIRECT */
14986 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14987 +{ BUG(); return 0; }
14989 +/* they will never be called. */
14990 +#ifdef CONFIG_AUFS_DEBUG
14991 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14992 + loff_t pos, unsigned len, unsigned flags,
14993 + struct page **pagep, void **fsdata)
14994 +{ AuUnsupport(); return 0; }
14995 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14996 + loff_t pos, unsigned len, unsigned copied,
14997 + struct page *page, void *fsdata)
14998 +{ AuUnsupport(); return 0; }
14999 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15000 +{ AuUnsupport(); return 0; }
15002 +static int aufs_set_page_dirty(struct page *page)
15003 +{ AuUnsupport(); return 0; }
15004 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15005 + unsigned int length)
15006 +{ AuUnsupport(); }
15007 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15008 +{ AuUnsupport(); return 0; }
15009 +#if 0 /* called by memory compaction regardless file */
15010 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15011 + struct page *page, enum migrate_mode mode)
15012 +{ AuUnsupport(); return 0; }
15014 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15015 +{ AuUnsupport(); return true; }
15016 +static void aufs_putback_page(struct page *page)
15017 +{ AuUnsupport(); }
15018 +static int aufs_launder_page(struct page *page)
15019 +{ AuUnsupport(); return 0; }
15020 +static int aufs_is_partially_uptodate(struct page *page,
15021 + unsigned long from,
15022 + unsigned long count)
15023 +{ AuUnsupport(); return 0; }
15024 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15026 +{ AuUnsupport(); }
15027 +static int aufs_error_remove_page(struct address_space *mapping,
15028 + struct page *page)
15029 +{ AuUnsupport(); return 0; }
15030 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15032 +{ AuUnsupport(); return 0; }
15033 +static void aufs_swap_deactivate(struct file *file)
15034 +{ AuUnsupport(); }
15035 +#endif /* CONFIG_AUFS_DEBUG */
15037 +const struct address_space_operations aufs_aop = {
15038 + .readpage = aufs_readpage,
15039 + .direct_IO = aufs_direct_IO,
15040 +#ifdef CONFIG_AUFS_DEBUG
15041 + .writepage = aufs_writepage,
15042 + /* no writepages, because of writepage */
15043 + .set_page_dirty = aufs_set_page_dirty,
15044 + /* no readpages, because of readpage */
15045 + .write_begin = aufs_write_begin,
15046 + .write_end = aufs_write_end,
15047 + /* no bmap, no block device */
15048 + .invalidatepage = aufs_invalidatepage,
15049 + .releasepage = aufs_releasepage,
15050 + /* is fallback_migrate_page ok? */
15051 + /* .migratepage = aufs_migratepage, */
15052 + .isolate_page = aufs_isolate_page,
15053 + .putback_page = aufs_putback_page,
15054 + .launder_page = aufs_launder_page,
15055 + .is_partially_uptodate = aufs_is_partially_uptodate,
15056 + .is_dirty_writeback = aufs_is_dirty_writeback,
15057 + .error_remove_page = aufs_error_remove_page,
15058 + .swap_activate = aufs_swap_activate,
15059 + .swap_deactivate = aufs_swap_deactivate
15060 +#endif /* CONFIG_AUFS_DEBUG */
15062 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15063 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 08:00:00.000000000 +0800
15064 +++ linux/fs/aufs/file.h 2019-07-11 21:21:54.379051070 +0800
15066 +/* SPDX-License-Identifier: GPL-2.0 */
15068 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15070 + * This program, aufs is free software; you can redistribute it and/or modify
15071 + * it under the terms of the GNU General Public License as published by
15072 + * the Free Software Foundation; either version 2 of the License, or
15073 + * (at your option) any later version.
15075 + * This program is distributed in the hope that it will be useful,
15076 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15077 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15078 + * GNU General Public License for more details.
15080 + * You should have received a copy of the GNU General Public License
15081 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15085 + * file operations
15088 +#ifndef __AUFS_FILE_H__
15089 +#define __AUFS_FILE_H__
15093 +#include <linux/file.h>
15094 +#include <linux/fs.h>
15095 +#include <linux/mm_types.h>
15096 +#include <linux/poll.h>
15097 +#include "rwsem.h"
15101 + struct file *hf_file;
15102 + struct au_branch *hf_br;
15107 + aufs_bindex_t fd_bbot;
15108 + aufs_bindex_t fd_nent;
15109 + struct au_vdir *fd_vdir_cache;
15110 + struct au_hfile fd_hfile[];
15113 +static inline int au_fidir_sz(int nent)
15115 + AuDebugOn(nent < 0);
15116 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15120 + atomic_t fi_generation;
15122 + struct au_rwsem fi_rwsem;
15123 + aufs_bindex_t fi_btop;
15125 + /* do not union them */
15126 + struct { /* for non-dir */
15127 + struct au_hfile fi_htop;
15128 + atomic_t fi_mmapped;
15130 + struct au_fidir *fi_hdir; /* for dir only */
15132 + struct hlist_bl_node fi_hlist;
15133 + struct file *fi_file; /* very ugly */
15134 + struct rcu_head rcu;
15135 +} ____cacheline_aligned_in_smp;
15137 +/* ---------------------------------------------------------------------- */
15140 +extern const struct address_space_operations aufs_aop;
15141 +unsigned int au_file_roflags(unsigned int flags);
15142 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15143 + struct file *file, int force_wr);
15144 +struct au_do_open_args {
15146 + int (*open)(struct file *file, int flags,
15147 + struct file *h_file);
15148 + struct au_fidir *fidir;
15149 + struct file *h_file;
15151 +int au_do_open(struct file *file, struct au_do_open_args *args);
15152 +int au_reopen_nondir(struct file *file);
15154 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15155 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15156 + int wlock, unsigned int fi_lsc);
15157 +int au_do_flush(struct file *file, fl_owner_t id,
15158 + int (*flush)(struct file *file, fl_owner_t id));
15161 +#ifdef CONFIG_AUFS_POLL
15162 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15165 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15167 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15169 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15170 + struct file *h_file);
15172 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15173 + aufs_bindex_t bindex, int force_wr)
15174 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15175 + struct file *h_file);
15179 +extern const struct file_operations aufs_file_fop;
15180 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15181 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15182 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15185 +void au_hfput(struct au_hfile *hf, int execed);
15186 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15187 + struct file *h_file);
15189 +void au_update_figen(struct file *file);
15190 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15191 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15193 +void au_fi_init_once(void *_fi);
15194 +void au_finfo_fin(struct file *file);
15195 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15198 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15199 +#ifdef CONFIG_COMPAT
15200 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15201 + unsigned long arg);
15202 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15203 + unsigned long arg);
15206 +/* ---------------------------------------------------------------------- */
15208 +static inline struct au_finfo *au_fi(struct file *file)
15210 + return file->private_data;
15213 +/* ---------------------------------------------------------------------- */
15215 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15216 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15217 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15218 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15220 +#define fi_read_trylock_nested(f) \
15221 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15222 +#define fi_write_trylock_nested(f) \
15223 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15226 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15227 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15228 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15230 +/* lock subclass for finfo */
15236 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15238 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15241 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15243 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15247 + * fi_read_lock_1, fi_write_lock_1,
15248 + * fi_read_lock_2, fi_write_lock_2
15250 +#define AuReadLockFunc(name) \
15251 +static inline void fi_read_lock_##name(struct file *f) \
15252 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15254 +#define AuWriteLockFunc(name) \
15255 +static inline void fi_write_lock_##name(struct file *f) \
15256 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15258 +#define AuRWLockFuncs(name) \
15259 + AuReadLockFunc(name) \
15260 + AuWriteLockFunc(name)
15265 +#undef AuReadLockFunc
15266 +#undef AuWriteLockFunc
15267 +#undef AuRWLockFuncs
15269 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15270 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15271 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15273 +/* ---------------------------------------------------------------------- */
15275 +/* todo: hard/soft set? */
15276 +static inline aufs_bindex_t au_fbtop(struct file *file)
15278 + FiMustAnyLock(file);
15279 + return au_fi(file)->fi_btop;
15282 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15284 + FiMustAnyLock(file);
15285 + AuDebugOn(!au_fi(file)->fi_hdir);
15286 + return au_fi(file)->fi_hdir->fd_bbot;
15289 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15291 + FiMustAnyLock(file);
15292 + AuDebugOn(!au_fi(file)->fi_hdir);
15293 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15296 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15298 + FiMustWriteLock(file);
15299 + au_fi(file)->fi_btop = bindex;
15302 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15304 + FiMustWriteLock(file);
15305 + AuDebugOn(!au_fi(file)->fi_hdir);
15306 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15309 +static inline void au_set_fvdir_cache(struct file *file,
15310 + struct au_vdir *vdir_cache)
15312 + FiMustWriteLock(file);
15313 + AuDebugOn(!au_fi(file)->fi_hdir);
15314 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15317 +static inline struct file *au_hf_top(struct file *file)
15319 + FiMustAnyLock(file);
15320 + AuDebugOn(au_fi(file)->fi_hdir);
15321 + return au_fi(file)->fi_htop.hf_file;
15324 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15326 + FiMustAnyLock(file);
15327 + AuDebugOn(!au_fi(file)->fi_hdir);
15328 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15331 +/* todo: memory barrier? */
15332 +static inline unsigned int au_figen(struct file *f)
15334 + return atomic_read(&au_fi(f)->fi_generation);
15337 +static inline void au_set_mmapped(struct file *f)
15339 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15341 + pr_warn("fi_mmapped wrapped around\n");
15342 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15346 +static inline void au_unset_mmapped(struct file *f)
15348 + atomic_dec(&au_fi(f)->fi_mmapped);
15351 +static inline int au_test_mmapped(struct file *f)
15353 + return atomic_read(&au_fi(f)->fi_mmapped);
15356 +/* customize vma->vm_file */
15358 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15359 + struct file *file)
15363 + f = vma->vm_file;
15365 + vma->vm_file = file;
15370 +#define AuDbgVmRegion(file, vma) do {} while (0)
15372 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15373 + struct file *file)
15375 + au_do_vm_file_reset(vma, file);
15378 +#define AuDbgVmRegion(file, vma) \
15379 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15381 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15382 + struct file *file)
15386 + au_do_vm_file_reset(vma, file);
15387 + f = vma->vm_region->vm_file;
15389 + vma->vm_region->vm_file = file;
15392 +#endif /* CONFIG_MMU */
15394 +/* handle vma->vm_prfile */
15395 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15396 + struct file *file)
15399 + vma->vm_prfile = file;
15400 +#ifndef CONFIG_MMU
15402 + vma->vm_region->vm_prfile = file;
15406 +#endif /* __KERNEL__ */
15407 +#endif /* __AUFS_FILE_H__ */
15408 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15409 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 08:00:00.000000000 +0800
15410 +++ linux/fs/aufs/finfo.c 2019-07-11 21:21:54.379051070 +0800
15412 +// SPDX-License-Identifier: GPL-2.0
15414 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15416 + * This program, aufs is free software; you can redistribute it and/or modify
15417 + * it under the terms of the GNU General Public License as published by
15418 + * the Free Software Foundation; either version 2 of the License, or
15419 + * (at your option) any later version.
15421 + * This program is distributed in the hope that it will be useful,
15422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15424 + * GNU General Public License for more details.
15426 + * You should have received a copy of the GNU General Public License
15427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15431 + * file private data
15436 +void au_hfput(struct au_hfile *hf, int execed)
15439 + allow_write_access(hf->hf_file);
15440 + fput(hf->hf_file);
15441 + hf->hf_file = NULL;
15442 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15443 + hf->hf_br = NULL;
15446 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15448 + struct au_finfo *finfo = au_fi(file);
15449 + struct au_hfile *hf;
15450 + struct au_fidir *fidir;
15452 + fidir = finfo->fi_hdir;
15454 + AuDebugOn(finfo->fi_btop != bindex);
15455 + hf = &finfo->fi_htop;
15457 + hf = fidir->fd_hfile + bindex;
15459 + if (hf && hf->hf_file)
15460 + au_hfput(hf, vfsub_file_execed(file));
15462 + FiMustWriteLock(file);
15463 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15464 + hf->hf_file = val;
15465 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15469 +void au_update_figen(struct file *file)
15471 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15472 + /* smp_mb(); */ /* atomic_set */
15475 +/* ---------------------------------------------------------------------- */
15477 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15479 + struct au_fidir *fidir;
15482 + nbr = au_sbbot(sb) + 1;
15484 + nbr = 2; /* initial allocate for 2 branches */
15485 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15487 + fidir->fd_bbot = -1;
15488 + fidir->fd_nent = nbr;
15494 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15497 + struct au_fidir *fidir, *p;
15499 + AuRwMustWriteLock(&finfo->fi_rwsem);
15500 + fidir = finfo->fi_hdir;
15501 + AuDebugOn(!fidir);
15504 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15505 + GFP_NOFS, may_shrink);
15507 + p->fd_nent = nbr;
15508 + finfo->fi_hdir = p;
15515 +/* ---------------------------------------------------------------------- */
15517 +void au_finfo_fin(struct file *file)
15519 + struct au_finfo *finfo;
15521 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15523 + finfo = au_fi(file);
15524 + AuDebugOn(finfo->fi_hdir);
15525 + AuRwDestroy(&finfo->fi_rwsem);
15526 + au_cache_free_finfo(finfo);
15529 +void au_fi_init_once(void *_finfo)
15531 + struct au_finfo *finfo = _finfo;
15533 + au_rw_init(&finfo->fi_rwsem);
15536 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15539 + struct au_finfo *finfo;
15540 + struct dentry *dentry;
15543 + dentry = file->f_path.dentry;
15544 + finfo = au_cache_alloc_finfo();
15545 + if (unlikely(!finfo))
15549 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15550 + au_rw_write_lock(&finfo->fi_rwsem);
15551 + finfo->fi_btop = -1;
15552 + finfo->fi_hdir = fidir;
15553 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15554 + /* smp_mb(); */ /* atomic_set */
15556 + file->private_data = finfo;
15561 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15562 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 08:00:00.000000000 +0800
15563 +++ linux/fs/aufs/f_op.c 2019-07-11 21:21:54.379051070 +0800
15565 +// SPDX-License-Identifier: GPL-2.0
15567 + * Copyright (C) 2005-2019 Junjiro R. Okajima
15569 + * This program, aufs is free software; you can redistribute it and/or modify
15570 + * it under the terms of the GNU General Public License as published by
15571 + * the Free Software Foundation; either version 2 of the License, or
15572 + * (at your option) any later version.
15574 + * This program is distributed in the hope that it will be useful,
15575 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15576 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15577 + * GNU General Public License for more details.
15579 + * You should have received a copy of the GNU General Public License
15580 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15584 + * file and vm operations
15587 +#include <linux/aio.h>
15588 +#include <linux/fs_stack.h>
15589 +#include <linux/mman.h>
15590 +#include <linux/security.h>
15593 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15596 + aufs_bindex_t bindex;
15597 + struct dentry *dentry, *h_dentry;
15598 + struct au_finfo *finfo;
15599 + struct inode *h_inode;
15601 + FiMustWriteLock(file);
15604 + dentry = file->f_path.dentry;
15605 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15606 + finfo = au_fi(file);
15607 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15608 + atomic_set(&finfo->fi_mmapped, 0);
15609 + bindex = au_dbtop(dentry);
15611 + h_dentry = au_h_dptr(dentry, bindex);
15612 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15613 + if (unlikely(err))
15615 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15616 + if (IS_ERR(h_file)) {
15617 + err = PTR_ERR(h_file);
15621 + h_dentry = h_file->f_path.dentry;
15622 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15623 + if (unlikely(err))
15625 + /* br ref is already inc-ed */
15628 + if ((flags & __O_TMPFILE)
15629 + && !(flags & O_EXCL)) {
15630 + h_inode = file_inode(h_file);
15631 + spin_lock(&h_inode->i_lock);
15632 + h_inode->i_state |= I_LINKABLE;
15633 + spin_unlock(&h_inode->i_lock);
15635 + au_set_fbtop(file, bindex);
15636 + au_set_h_fptr(file, bindex, h_file);
15637 + au_update_figen(file);
15638 + /* todo: necessary? */
15639 + /* file->f_ra = h_file->f_ra; */
15645 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15646 + struct file *file)
15649 + struct super_block *sb;
15650 + struct au_do_open_args args = {
15651 + .open = au_do_open_nondir
15654 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15655 + file, vfsub_file_flags(file), file->f_mode);
15657 + sb = file->f_path.dentry->d_sb;
15658 + si_read_lock(sb, AuLock_FLUSH);
15659 + err = au_do_open(file, &args);
15660 + si_read_unlock(sb);
15664 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15666 + struct au_finfo *finfo;
15667 + aufs_bindex_t bindex;
15669 + finfo = au_fi(file);
15670 + au_hbl_del(&finfo->fi_hlist,
15671 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15672 + bindex = finfo->fi_btop;
15674 + au_set_h_fptr(file, bindex, NULL);
15676 + au_finfo_fin(file);
15680 +/* ---------------------------------------------------------------------- */
15682 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15685 + struct file *h_file;
15688 + h_file = au_hf_top(file);
15690 + err = vfsub_flush(h_file, id);
15694 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15696 + return au_do_flush(file, id, au_do_flush_nondir);
15699 +/* ---------------------------------------------------------------------- */
15701 + * read and write functions acquire [fdi]_rwsem once, but release before
15702 + * mmap_sem. This is because to stop a race condition between mmap(2).
15703 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15704 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15705 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15708 +/* Callers should call au_read_post() or fput() in the end */
15709 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15711 + struct file *h_file;
15714 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15716 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15717 + h_file = au_hf_top(file);
15718 + get_file(h_file);
15720 + fi_read_unlock(file);
15722 + h_file = ERR_PTR(err);
15727 +static void au_read_post(struct inode *inode, struct file *h_file)
15729 + /* update without lock, I don't think it a problem */
15730 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15734 +struct au_write_pre {
15736 + unsigned int lsc;
15740 + aufs_bindex_t btop;
15744 + * return with iinfo is write-locked
15745 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15748 +static struct file *au_write_pre(struct file *file, int do_ready,
15749 + struct au_write_pre *wpre)
15751 + struct file *h_file;
15752 + struct dentry *dentry;
15754 + unsigned int lsc;
15755 + struct au_pin pin;
15760 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15761 + h_file = ERR_PTR(err);
15762 + if (unlikely(err))
15765 + dentry = file->f_path.dentry;
15767 + err = au_ready_to_write(file, -1, &pin);
15768 + if (unlikely(err)) {
15769 + h_file = ERR_PTR(err);
15770 + di_write_unlock(dentry);
15775 + di_downgrade_lock(dentry, /*flags*/0);
15777 + wpre->btop = au_fbtop(file);
15778 + h_file = au_hf_top(file);
15779 + get_file(h_file);
15781 + wpre->blks = file_inode(h_file)->i_blocks;
15784 + di_read_unlock(dentry, /*flags*/0);
15787 + fi_write_unlock(file);
15792 +static void au_write_post(struct inode *inode, struct file *h_file,
15793 + struct au_write_pre *wpre, ssize_t written)
15795 + struct inode *h_inode;
15797 + au_cpup_attr_timesizes(inode);
15798 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15799 + h_inode = file_inode(h_file);
15800 + inode->i_mode = h_inode->i_mode;
15801 + ii_write_unlock(inode);
15802 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15804 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15805 + /*force*/h_inode->i_blocks > wpre->blks);
15809 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15813 + struct inode *inode;
15814 + struct file *h_file;
15815 + struct super_block *sb;
15817 + inode = file_inode(file);
15818 + sb = inode->i_sb;
15819 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15821 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15822 + err = PTR_ERR(h_file);
15823 + if (IS_ERR(h_file))
15826 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15827 + err = vfsub_read_u(h_file, buf, count, ppos);
15828 + /* todo: necessary? */
15829 + /* file->f_ra = h_file->f_ra; */
15830 + au_read_post(inode, h_file);
15833 + si_read_unlock(sb);
15838 + * todo: very ugly
15839 + * it locks both of i_mutex and si_rwsem for read in safe.
15840 + * if the plink maintenance mode continues forever (that is the problem),
15841 + * may loop forever.
15843 +static void au_mtx_and_read_lock(struct inode *inode)
15846 + struct super_block *sb = inode->i_sb;
15849 + inode_lock(inode);
15850 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15853 + inode_unlock(inode);
15854 + si_read_lock(sb, AuLock_NOPLMW);
15855 + si_read_unlock(sb);
15859 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15860 + size_t count, loff_t *ppos)
15863 + struct au_write_pre wpre;
15864 + struct inode *inode;
15865 + struct file *h_file;
15866 + char __user *buf = (char __user *)ubuf;
15868 + inode = file_inode(file);
15869 + au_mtx_and_read_lock(inode);
15872 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15873 + err = PTR_ERR(h_file);
15874 + if (IS_ERR(h_file))
15877 + err = vfsub_write_u(h_file, buf, count, ppos);
15878 + au_write_post(inode, h_file, &wpre, err);
15881 + si_read_unlock(inode->i_sb);
15882 + inode_unlock(inode);
15886 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15887 + struct iov_iter *iov_iter)
15890 + struct file *file;
15891 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15893 + err = security_file_permission(h_file, rw);
15894 + if (unlikely(err))
15899 + if (rw == MAY_READ)
15900 + iter = h_file->f_op->read_iter;
15901 + else if (rw == MAY_WRITE)
15902 + iter = h_file->f_op->write_iter;
15904 + file = kio->ki_filp;
15905 + kio->ki_filp = h_file;
15908 + err = iter(kio, iov_iter);
15911 + /* currently there is no such fs */
15913 + kio->ki_filp = file;
15919 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15922 + struct file *file, *h_file;
15923 + struct inode *inode;
15924 + struct super_block *sb;
15926 + file = kio->ki_filp;
15927 + inode = file_inode(file);
15928 + sb = inode->i_sb;
15929 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15931 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15932 + err = PTR_ERR(h_file);
15933 + if (IS_ERR(h_file))
15936 + if (au_test_loopback_kthread()) {
15937 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15938 + if (file->f_mapping != h_file->f_mapping) {
15939 + file->f_mapping = h_file->f_mapping;
15940 + smp_mb(); /* unnecessary? */
15943 + fi_read_unlock(file);
15945 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15946 + /* todo: necessary? */
15947 + /* file->f_ra = h_file->f_ra; */
15948 + au_read_post(inode, h_file);
15951 + si_read_unlock(sb);
15955 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15958 + struct au_write_pre wpre;
15959 + struct inode *inode;
15960 + struct file *file, *h_file;
15962 + file = kio->ki_filp;
15963 + inode = file_inode(file);
15964 + au_mtx_and_read_lock(inode);
15967 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15968 + err = PTR_ERR(h_file);
15969 + if (IS_ERR(h_file))
15972 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15973 + au_write_post(inode, h_file, &wpre, err);
15976 + si_read_unlock(inode->i_sb);
15977 + inode_unlock(inode);
15981 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15982 + struct pipe_inode_info *pipe, size_t len,
15983 + unsigned int flags)
15986 + struct file *h_file;
15987 + struct inode *inode;
15988 + struct super_block *sb;
15990 + inode = file_inode(file);
15991 + sb = inode->i_sb;
15992 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15994 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15995 + err = PTR_ERR(h_file);
15996 + if (IS_ERR(h_file))
15999 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16000 + /* todo: necessary? */
16001 + /* file->f_ra = h_file->f_ra; */
16002 + au_read_post(inode, h_file);
16005 + si_read_unlock(sb);
16010 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16011 + size_t len, unsigned int flags)
16014 + struct au_write_pre wpre;
16015 + struct inode *inode;
16016 + struct file *h_file;
16018 + inode = file_inode(file);
16019 + au_mtx_and_read_lock(inode);
16022 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16023 + err = PTR_ERR(h_file);
16024 + if (IS_ERR(h_file))
16027 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16028 + au_write_post(inode, h_file, &wpre, err);
16031 + si_read_unlock(inode->i_sb);
16032 + inode_unlock(inode);
16036 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16040 + struct au_write_pre wpre;
16041 + struct inode *inode;
16042 + struct file *h_file;
16044 + inode = file_inode(file);
16045 + au_mtx_and_read_lock(inode);
16048 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16049 + err = PTR_ERR(h_file);
16050 + if (IS_ERR(h_file))
16054 + err = vfs_fallocate(h_file, mode, offset, len);
16056 + au_write_post(inode, h_file, &wpre, /*written*/1);
16059 + si_read_unlock(inode->i_sb);
16060 + inode_unlock(inode);
16064 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16065 + struct file *dst, loff_t dst_pos,
16066 + size_t len, unsigned int flags)
16069 + struct au_write_pre wpre;
16070 + enum { SRC, DST };
16072 + struct inode *inode;
16073 + struct file *h_file;
16074 + struct super_block *h_sb;
16076 +#define a_src a[SRC]
16077 +#define a_dst a[DST]
16080 + a_src.inode = file_inode(src);
16081 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16083 + a_dst.inode = file_inode(dst);
16084 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16087 + au_mtx_and_read_lock(a_dst.inode);
16089 + * in order to match the order in di_write_lock2_{child,parent}(),
16090 + * use f_path.dentry for this comparison.
16092 + if (src->f_path.dentry < dst->f_path.dentry) {
16093 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16094 + err = PTR_ERR(a_src.h_file);
16095 + if (IS_ERR(a_src.h_file))
16098 + wpre.lsc = AuLsc_FI_2;
16099 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16100 + err = PTR_ERR(a_dst.h_file);
16101 + if (IS_ERR(a_dst.h_file)) {
16102 + au_read_post(a_src.inode, a_src.h_file);
16106 + wpre.lsc = AuLsc_FI_1;
16107 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16108 + err = PTR_ERR(a_dst.h_file);
16109 + if (IS_ERR(a_dst.h_file))
16112 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16113 + err = PTR_ERR(a_src.h_file);
16114 + if (IS_ERR(a_src.h_file)) {
16115 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16122 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16123 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16124 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16130 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16131 + dst_pos, len, flags);
16134 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16135 + fi_read_unlock(src);
16136 + au_read_post(a_src.inode, a_src.h_file);
16138 + si_read_unlock(a_dst.inode->i_sb);
16139 + inode_unlock(a_dst.inode);
16146 +/* ---------------------------------------------------------------------- */
16149 + * The locking order around current->mmap_sem.
16150 + * - in most and regular cases
16151 + * file I/O syscall -- aufs_read() or something
16152 + * -- si_rwsem for read -- mmap_sem
16153 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16155 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16156 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16157 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16158 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16159 + * It means that when aufs acquires si_rwsem for write, the process should never
16160 + * acquire mmap_sem.
16162 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16163 + * problem either since any directory is not able to be mmap-ed.
16164 + * The similar scenario is applied to aufs_readlink() too.
16167 +#if 0 /* stop calling security_file_mmap() */
16168 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16169 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16171 +static unsigned long au_arch_prot_conv(unsigned long flags)
16173 + /* currently ppc64 only */
16174 +#ifdef CONFIG_PPC64
16175 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16176 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16177 + return AuConv_VM_PROT(flags, SAO);
16179 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16184 +static unsigned long au_prot_conv(unsigned long flags)
16186 + return AuConv_VM_PROT(flags, READ)
16187 + | AuConv_VM_PROT(flags, WRITE)
16188 + | AuConv_VM_PROT(flags, EXEC)
16189 + | au_arch_prot_conv(flags);
16192 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16193 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16195 +static unsigned long au_flag_conv(unsigned long flags)
16197 + return AuConv_VM_MAP(flags, GROWSDOWN)
16198 + | AuConv_VM_MAP(flags, DENYWRITE)
16199 + | AuConv_VM_MAP(flags, LOCKED);
16203 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16206 + const unsigned char wlock
16207 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16208 + struct super_block *sb;
16209 + struct file *h_file;
16210 + struct inode *inode;
16212 + AuDbgVmRegion(file, vma);
16214 + inode = file_inode(file);
16215 + sb = inode->i_sb;
16217 + si_read_lock(sb, AuLock_NOPLMW);
16219 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16221 + err = PTR_ERR(h_file);
16222 + if (IS_ERR(h_file))
16226 + au_set_mmapped(file);
16227 + au_vm_file_reset(vma, h_file);
16229 + * we cannot call security_mmap_file() here since it may acquire
16230 + * mmap_sem or i_mutex.
16232 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16233 + * au_flag_conv(vma->vm_flags));
16236 + err = call_mmap(h_file, vma);
16238 + au_vm_prfile_set(vma, file);
16239 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16240 + goto out_fput; /* success */
16242 + au_unset_mmapped(file);
16243 + au_vm_file_reset(vma, file);
16247 + ii_write_unlock(inode);
16252 + si_read_unlock(sb);
16258 +/* ---------------------------------------------------------------------- */
16260 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16264 + struct au_write_pre wpre;
16265 + struct inode *inode;
16266 + struct file *h_file;
16268 + err = 0; /* -EBADF; */ /* posix? */
16269 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16272 + inode = file_inode(file);
16273 + au_mtx_and_read_lock(inode);
16276 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16277 + err = PTR_ERR(h_file);
16278 + if (IS_ERR(h_file))
16281 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16282 + au_write_post(inode, h_file, &wpre, /*written*/0);
16285 + si_read_unlock(inode->i_sb);
16286 + inode_unlock(inode);
16291 +static int aufs_fasync(int fd, struct file *file, int flag)
16294 + struct file *h_file;
16295 + struct super_block *sb;
16297 + sb = file->f_path.dentry->d_sb;
16298 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16300 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16301 + err = PTR_ERR(h_file);
16302 + if (IS_ERR(h_file))
16305 + if (h_file->f_op->fasync)
16306 + err = h_file->f_op->fasync(fd, h_file, flag);
16307 + fput(h_file); /* instead of au_read_post() */
16310 + si_read_unlock(sb);
16314 +static int aufs_setfl(struct file *file, unsigned long arg)
16317 + struct file *h_file;
16318 + struct super_block *sb;
16320 + sb = file->f_path.dentry->d_sb;
16321 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16323 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16324 + err = PTR_ERR(h_file);
16325 + if (IS_ERR(h_file))
16328 + /* stop calling h_file->fasync */
16329 + arg |= vfsub_file_flags(file) & FASYNC;
16330 + err = setfl(/*unused fd*/-1, h_file, arg);
16331 + fput(h_file); /* instead of au_read_post() */
16334 + si_read_unlock(sb);
16338 +/* ---------------------------------------------------------------------- */
16340 +/* no one supports this operation, currently */
16342 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16343 + size_t len, loff_t *pos, int more)
16348 +/* ---------------------------------------------------------------------- */
16350 +const struct file_operations aufs_file_fop = {
16351 + .owner = THIS_MODULE,
16353 + .llseek = default_llseek,
16355 + .read = aufs_read,
16356 + .write = aufs_write,
16357 + .read_iter = aufs_read_iter,
16358 + .write_iter = aufs_write_iter,
16360 +#ifdef CONFIG_AUFS_POLL
16361 + .poll = aufs_poll,
16363 + .unlocked_ioctl = aufs_ioctl_nondir,
16364 +#ifdef CONFIG_COMPAT
16365 + .compat_ioctl = aufs_compat_ioctl_nondir,
16367 + .mmap = aufs_mmap,
16368 + .open = aufs_open_nondir,
16369 + .flush = aufs_flush_nondir,
16370 + .release = aufs_release_nondir,
16371 + .fsync = aufs_fsync_nondir,
16372 + .fasync = aufs_fasync,
16373 + /* .sendpage = aufs_sendpage, */
16374 + .setfl = aufs_setfl,
16375 + .splice_write = aufs_splice_write,
16376 + .splice_read = aufs_splice_read,
16378 + .aio_splice_write = aufs_aio_splice_write,
16379 + .aio_splice_read = aufs_aio_splice_read,
16381 + .fallocate = aufs_fallocate,
16382 + .copy_file_range = aufs_copy_file_range
16384 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16385 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 08:00:00.000000000 +0800
16386 +++ linux/fs/aufs/fstype.h 2019-07-11 21:21:54.379051070 +0800
16388 +/* SPDX-License-Identifier: GPL-2.0 */
16390 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16392 + * This program, aufs is free software; you can redistribute it and/or modify
16393 + * it under the terms of the GNU General Public License as published by
16394 + * the Free Software Foundation; either version 2 of the License, or
16395 + * (at your option) any later version.
16397 + * This program is distributed in the hope that it will be useful,
16398 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16399 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16400 + * GNU General Public License for more details.
16402 + * You should have received a copy of the GNU General Public License
16403 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16407 + * judging filesystem type
16410 +#ifndef __AUFS_FSTYPE_H__
16411 +#define __AUFS_FSTYPE_H__
16415 +#include <linux/fs.h>
16416 +#include <linux/magic.h>
16417 +#include <linux/nfs_fs.h>
16418 +#include <linux/romfs_fs.h>
16420 +static inline int au_test_aufs(struct super_block *sb)
16422 + return sb->s_magic == AUFS_SUPER_MAGIC;
16425 +static inline const char *au_sbtype(struct super_block *sb)
16427 + return sb->s_type->name;
16430 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16432 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16433 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16439 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16441 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16442 + return sb->s_magic == ROMFS_MAGIC;
16448 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16450 +#if IS_ENABLED(CONFIG_CRAMFS)
16451 + return sb->s_magic == CRAMFS_MAGIC;
16456 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16458 +#if IS_ENABLED(CONFIG_NFS_FS)
16459 + return sb->s_magic == NFS_SUPER_MAGIC;
16465 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16467 +#if IS_ENABLED(CONFIG_FUSE_FS)
16468 + return sb->s_magic == FUSE_SUPER_MAGIC;
16474 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16476 +#if IS_ENABLED(CONFIG_XFS_FS)
16477 + return sb->s_magic == XFS_SB_MAGIC;
16483 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16485 +#ifdef CONFIG_TMPFS
16486 + return sb->s_magic == TMPFS_MAGIC;
16492 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16494 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16495 + return !strcmp(au_sbtype(sb), "ecryptfs");
16501 +static inline int au_test_ramfs(struct super_block *sb)
16503 + return sb->s_magic == RAMFS_MAGIC;
16506 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16508 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16509 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16515 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16517 +#ifdef CONFIG_PROC_FS
16518 + return sb->s_magic == PROC_SUPER_MAGIC;
16524 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16526 +#ifdef CONFIG_SYSFS
16527 + return sb->s_magic == SYSFS_MAGIC;
16533 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16535 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16536 + return sb->s_magic == CONFIGFS_MAGIC;
16542 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16544 +#if IS_ENABLED(CONFIG_MINIX_FS)
16545 + return sb->s_magic == MINIX3_SUPER_MAGIC
16546 + || sb->s_magic == MINIX2_SUPER_MAGIC
16547 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16548 + || sb->s_magic == MINIX_SUPER_MAGIC
16549 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16555 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16557 +#if IS_ENABLED(CONFIG_FAT_FS)
16558 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16564 +static inline int au_test_msdos(struct super_block *sb)
16566 + return au_test_fat(sb);
16569 +static inline int au_test_vfat(struct super_block *sb)
16571 + return au_test_fat(sb);
16574 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16576 +#ifdef CONFIG_SECURITYFS
16577 + return sb->s_magic == SECURITYFS_MAGIC;
16583 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16585 +#if IS_ENABLED(CONFIG_SQUASHFS)
16586 + return sb->s_magic == SQUASHFS_MAGIC;
16592 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16594 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16595 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16601 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16603 +#if IS_ENABLED(CONFIG_XENFS)
16604 + return sb->s_magic == XENFS_SUPER_MAGIC;
16610 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16612 +#ifdef CONFIG_DEBUG_FS
16613 + return sb->s_magic == DEBUGFS_MAGIC;
16619 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16621 +#if IS_ENABLED(CONFIG_NILFS)
16622 + return sb->s_magic == NILFS_SUPER_MAGIC;
16628 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16630 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16631 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16637 +/* ---------------------------------------------------------------------- */
16639 + * they can't be an aufs branch.
16641 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16644 +#ifndef CONFIG_AUFS_BR_RAMFS
16645 + au_test_ramfs(sb) ||
16647 + au_test_procfs(sb)
16648 + || au_test_sysfs(sb)
16649 + || au_test_configfs(sb)
16650 + || au_test_debugfs(sb)
16651 + || au_test_securityfs(sb)
16652 + || au_test_xenfs(sb)
16653 + || au_test_ecryptfs(sb)
16654 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16655 + || au_test_aufs(sb); /* will be supported in next version */
16658 +static inline int au_test_fs_remote(struct super_block *sb)
16660 + return !au_test_tmpfs(sb)
16661 +#ifdef CONFIG_AUFS_BR_RAMFS
16662 + && !au_test_ramfs(sb)
16664 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16667 +/* ---------------------------------------------------------------------- */
16670 + * Note: these functions (below) are created after reading ->getattr() in all
16671 + * filesystems under linux/fs. it means we have to do so in every update...
16675 + * some filesystems require getattr to refresh the inode attributes before
16677 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16678 + * and leave the work for d_revalidate()
16680 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16682 + return au_test_nfs(sb)
16683 + || au_test_fuse(sb)
16684 + /* || au_test_btrfs(sb) */ /* untested */
16689 + * filesystems which don't maintain i_size or i_blocks.
16691 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16693 + return au_test_xfs(sb)
16694 + || au_test_btrfs(sb)
16695 + || au_test_ubifs(sb)
16696 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16697 + /* || au_test_minix(sb) */ /* untested */
16702 + * filesystems which don't store the correct value in some of their inode
16705 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16707 + return au_test_fs_bad_iattr_size(sb)
16708 + || au_test_fat(sb)
16709 + || au_test_msdos(sb)
16710 + || au_test_vfat(sb);
16713 +/* they don't check i_nlink in link(2) */
16714 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16716 + return au_test_tmpfs(sb)
16717 +#ifdef CONFIG_AUFS_BR_RAMFS
16718 + || au_test_ramfs(sb)
16720 + || au_test_ubifs(sb)
16721 + || au_test_hfsplus(sb);
16725 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16727 +static inline int au_test_fs_notime(struct super_block *sb)
16729 + return au_test_nfs(sb)
16730 + || au_test_fuse(sb)
16731 + || au_test_ubifs(sb)
16735 +/* temporary support for i#1 in cramfs */
16736 +static inline int au_test_fs_unique_ino(struct inode *inode)
16738 + if (au_test_cramfs(inode->i_sb))
16739 + return inode->i_ino != 1;
16743 +/* ---------------------------------------------------------------------- */
16746 + * the filesystem where the xino files placed must support i/o after unlink and
16747 + * maintain i_size and i_blocks.
16749 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16751 + return au_test_fs_remote(sb)
16752 + || au_test_fs_bad_iattr_size(sb)
16753 + /* don't want unnecessary work for xino */
16754 + || au_test_aufs(sb)
16755 + || au_test_ecryptfs(sb)
16756 + || au_test_nilfs(sb);
16759 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16761 + return au_test_tmpfs(sb)
16762 + || au_test_ramfs(sb);
16766 + * test if the @sb is real-readonly.
16768 +static inline int au_test_fs_rr(struct super_block *sb)
16770 + return au_test_squashfs(sb)
16771 + || au_test_iso9660(sb)
16772 + || au_test_cramfs(sb)
16773 + || au_test_romfs(sb);
16777 + * test if the @inode is nfs with 'noacl' option
16778 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16780 +static inline int au_test_nfs_noacl(struct inode *inode)
16782 + return au_test_nfs(inode->i_sb)
16783 + /* && IS_POSIXACL(inode) */
16784 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16787 +#endif /* __KERNEL__ */
16788 +#endif /* __AUFS_FSTYPE_H__ */
16789 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16790 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 08:00:00.000000000 +0800
16791 +++ linux/fs/aufs/hbl.h 2019-07-11 21:21:54.379051070 +0800
16793 +/* SPDX-License-Identifier: GPL-2.0 */
16795 + * Copyright (C) 2017-2019 Junjiro R. Okajima
16797 + * This program, aufs is free software; you can redistribute it and/or modify
16798 + * it under the terms of the GNU General Public License as published by
16799 + * the Free Software Foundation; either version 2 of the License, or
16800 + * (at your option) any later version.
16802 + * This program is distributed in the hope that it will be useful,
16803 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16804 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16805 + * GNU General Public License for more details.
16807 + * You should have received a copy of the GNU General Public License
16808 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16812 + * helpers for hlist_bl.h
16815 +#ifndef __AUFS_HBL_H__
16816 +#define __AUFS_HBL_H__
16820 +#include <linux/list_bl.h>
16822 +static inline void au_hbl_add(struct hlist_bl_node *node,
16823 + struct hlist_bl_head *hbl)
16825 + hlist_bl_lock(hbl);
16826 + hlist_bl_add_head(node, hbl);
16827 + hlist_bl_unlock(hbl);
16830 +static inline void au_hbl_del(struct hlist_bl_node *node,
16831 + struct hlist_bl_head *hbl)
16833 + hlist_bl_lock(hbl);
16834 + hlist_bl_del(node);
16835 + hlist_bl_unlock(hbl);
16838 +#define au_hbl_for_each(pos, head) \
16839 + for (pos = hlist_bl_first(head); \
16843 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16845 + unsigned long cnt;
16846 + struct hlist_bl_node *pos;
16849 + hlist_bl_lock(hbl);
16850 + au_hbl_for_each(pos, hbl)
16852 + hlist_bl_unlock(hbl);
16856 +#endif /* __KERNEL__ */
16857 +#endif /* __AUFS_HBL_H__ */
16858 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16859 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 08:00:00.000000000 +0800
16860 +++ linux/fs/aufs/hfsnotify.c 2019-07-11 21:21:54.379051070 +0800
16862 +// SPDX-License-Identifier: GPL-2.0
16864 + * Copyright (C) 2005-2019 Junjiro R. Okajima
16866 + * This program, aufs is free software; you can redistribute it and/or modify
16867 + * it under the terms of the GNU General Public License as published by
16868 + * the Free Software Foundation; either version 2 of the License, or
16869 + * (at your option) any later version.
16871 + * This program is distributed in the hope that it will be useful,
16872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16874 + * GNU General Public License for more details.
16876 + * You should have received a copy of the GNU General Public License
16877 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16881 + * fsnotify for the lower directories
16886 +/* FS_IN_IGNORED is unnecessary */
16887 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16888 + | FS_CREATE | FS_EVENT_ON_CHILD);
16889 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16890 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16892 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16894 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16896 + /* AuDbg("here\n"); */
16897 + au_cache_free_hnotify(hn);
16898 + smp_mb__before_atomic(); /* for atomic64_dec */
16899 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16900 + wake_up(&au_hfsn_wq);
16903 +static int au_hfsn_alloc(struct au_hinode *hinode)
16906 + struct au_hnotify *hn;
16907 + struct super_block *sb;
16908 + struct au_branch *br;
16909 + struct fsnotify_mark *mark;
16910 + aufs_bindex_t bindex;
16912 + hn = hinode->hi_notify;
16913 + sb = hn->hn_aufs_inode->i_sb;
16914 + bindex = au_br_index(sb, hinode->hi_id);
16915 + br = au_sbr(sb, bindex);
16916 + AuDebugOn(!br->br_hfsn);
16918 + mark = &hn->hn_mark;
16919 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16920 + mark->mask = AuHfsnMask;
16922 + * by udba rename or rmdir, aufs assign a new inode to the known
16923 + * h_inode, so specify 1 to allow dups.
16926 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16932 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16934 + struct fsnotify_mark *mark;
16935 + unsigned long long ull;
16936 + struct fsnotify_group *group;
16938 + ull = atomic64_inc_return(&au_hfsn_ifree);
16941 + mark = &hn->hn_mark;
16942 + spin_lock(&mark->lock);
16943 + group = mark->group;
16944 + fsnotify_get_group(group);
16945 + spin_unlock(&mark->lock);
16947 + fsnotify_destroy_mark(mark, group);
16948 + fsnotify_put_mark(mark);
16949 + fsnotify_put_group(group);
16952 + /* free hn by myself */
16956 +/* ---------------------------------------------------------------------- */
16958 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16960 + struct fsnotify_mark *mark;
16962 + mark = &hinode->hi_notify->hn_mark;
16963 + spin_lock(&mark->lock);
16965 + AuDebugOn(mark->mask & AuHfsnMask);
16966 + mark->mask |= AuHfsnMask;
16968 + AuDebugOn(!(mark->mask & AuHfsnMask));
16969 + mark->mask &= ~AuHfsnMask;
16971 + spin_unlock(&mark->lock);
16972 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16975 +/* ---------------------------------------------------------------------- */
16977 +/* #define AuDbgHnotify */
16978 +#ifdef AuDbgHnotify
16979 +static char *au_hfsn_name(u32 mask)
16981 +#ifdef CONFIG_AUFS_DEBUG
16982 +#define test_ret(flag) \
16984 + if (mask & flag) \
16987 + test_ret(FS_ACCESS);
16988 + test_ret(FS_MODIFY);
16989 + test_ret(FS_ATTRIB);
16990 + test_ret(FS_CLOSE_WRITE);
16991 + test_ret(FS_CLOSE_NOWRITE);
16992 + test_ret(FS_OPEN);
16993 + test_ret(FS_MOVED_FROM);
16994 + test_ret(FS_MOVED_TO);
16995 + test_ret(FS_CREATE);
16996 + test_ret(FS_DELETE);
16997 + test_ret(FS_DELETE_SELF);
16998 + test_ret(FS_MOVE_SELF);
16999 + test_ret(FS_UNMOUNT);
17000 + test_ret(FS_Q_OVERFLOW);
17001 + test_ret(FS_IN_IGNORED);
17002 + test_ret(FS_ISDIR);
17003 + test_ret(FS_IN_ONESHOT);
17004 + test_ret(FS_EVENT_ON_CHILD);
17013 +/* ---------------------------------------------------------------------- */
17015 +static void au_hfsn_free_group(struct fsnotify_group *group)
17017 + struct au_br_hfsnotify *hfsn = group->private;
17019 + /* AuDbg("here\n"); */
17020 + au_kfree_try_rcu(hfsn);
17023 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17024 + struct inode *inode,
17025 + u32 mask, const void *data, int data_type,
17026 + const struct qstr *file_name, u32 cookie,
17027 + struct fsnotify_iter_info *iter_info)
17030 + struct au_hnotify *hnotify;
17031 + struct inode *h_dir, *h_inode;
17032 + struct fsnotify_mark *inode_mark;
17034 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17037 + /* if FS_UNMOUNT happens, there must be another bug */
17038 + AuDebugOn(mask & FS_UNMOUNT);
17039 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17044 +#ifdef AuDbgHnotify
17046 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17047 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17048 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17049 + h_dir->i_ino, mask, au_hfsn_name(mask),
17050 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17051 + /* WARN_ON(1); */
17056 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17057 + AuDebugOn(!inode_mark);
17058 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17059 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
17065 +static struct fsnotify_ops au_hfsn_ops = {
17066 + .handle_event = au_hfsn_handle_event,
17067 + .free_group_priv = au_hfsn_free_group,
17068 + .free_mark = au_hfsn_free_mark
17071 +/* ---------------------------------------------------------------------- */
17073 +static void au_hfsn_fin_br(struct au_branch *br)
17075 + struct au_br_hfsnotify *hfsn;
17077 + hfsn = br->br_hfsn;
17080 + fsnotify_put_group(hfsn->hfsn_group);
17085 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17088 + struct fsnotify_group *group;
17089 + struct au_br_hfsnotify *hfsn;
17092 + br->br_hfsn = NULL;
17093 + if (!au_br_hnotifyable(perm))
17097 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17098 + if (unlikely(!hfsn))
17102 + group = fsnotify_alloc_group(&au_hfsn_ops);
17103 + if (IS_ERR(group)) {
17104 + err = PTR_ERR(group);
17105 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17109 + group->private = hfsn;
17110 + hfsn->hfsn_group = group;
17111 + br->br_hfsn = hfsn;
17112 + goto out; /* success */
17115 + au_kfree_try_rcu(hfsn);
17120 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17125 + if (!br->br_hfsn)
17126 + err = au_hfsn_init_br(br, perm);
17131 +/* ---------------------------------------------------------------------- */
17133 +static void au_hfsn_fin(void)
17135 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17136 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17139 +const struct au_hnotify_op au_hnotify_op = {
17140 + .ctl = au_hfsn_ctl,
17141 + .alloc = au_hfsn_alloc,
17142 + .free = au_hfsn_free,
17144 + .fin = au_hfsn_fin,
17146 + .reset_br = au_hfsn_reset_br,
17147 + .fin_br = au_hfsn_fin_br,
17148 + .init_br = au_hfsn_init_br
17150 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17151 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 08:00:00.000000000 +0800
17152 +++ linux/fs/aufs/hfsplus.c 2019-07-11 21:21:54.379051070 +0800
17154 +// SPDX-License-Identifier: GPL-2.0
17156 + * Copyright (C) 2010-2019 Junjiro R. Okajima
17158 + * This program, aufs is free software; you can redistribute it and/or modify
17159 + * it under the terms of the GNU General Public License as published by
17160 + * the Free Software Foundation; either version 2 of the License, or
17161 + * (at your option) any later version.
17163 + * This program is distributed in the hope that it will be useful,
17164 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17165 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17166 + * GNU General Public License for more details.
17168 + * You should have received a copy of the GNU General Public License
17169 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17173 + * special support for filesystems which acquires an inode mutex
17174 + * at final closing a file, eg, hfsplus.
17176 + * This trick is very simple and stupid, just to open the file before really
17177 + * necessary open to tell hfsplus that this is not the final closing.
17178 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17179 + * and au_h_open_post() after releasing it.
17184 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17187 + struct file *h_file;
17188 + struct dentry *h_dentry;
17190 + h_dentry = au_h_dptr(dentry, bindex);
17191 + AuDebugOn(!h_dentry);
17192 + AuDebugOn(d_is_negative(h_dentry));
17195 + if (au_test_hfsplus(h_dentry->d_sb)
17196 + && d_is_reg(h_dentry))
17197 + h_file = au_h_open(dentry, bindex,
17198 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17199 + /*file*/NULL, force_wr);
17203 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17204 + struct file *h_file)
17206 + struct au_branch *br;
17210 + br = au_sbr(dentry->d_sb, bindex);
17211 + au_lcnt_dec(&br->br_nfiles);
17214 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17215 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 08:00:00.000000000 +0800
17216 +++ linux/fs/aufs/hnotify.c 2019-07-11 21:21:54.379051070 +0800
17218 +// SPDX-License-Identifier: GPL-2.0
17220 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17222 + * This program, aufs is free software; you can redistribute it and/or modify
17223 + * it under the terms of the GNU General Public License as published by
17224 + * the Free Software Foundation; either version 2 of the License, or
17225 + * (at your option) any later version.
17227 + * This program is distributed in the hope that it will be useful,
17228 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17229 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17230 + * GNU General Public License for more details.
17232 + * You should have received a copy of the GNU General Public License
17233 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17237 + * abstraction to notify the direct changes on lower directories
17240 +/* #include <linux/iversion.h> */
17243 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17246 + struct au_hnotify *hn;
17249 + hn = au_cache_alloc_hnotify();
17251 + hn->hn_aufs_inode = inode;
17252 + hinode->hi_notify = hn;
17253 + err = au_hnotify_op.alloc(hinode);
17255 + if (unlikely(err)) {
17256 + hinode->hi_notify = NULL;
17257 + au_cache_free_hnotify(hn);
17259 + * The upper dir was removed by udba, but the same named
17260 + * dir left. In this case, aufs assigns a new inode
17261 + * number and set the monitor again.
17262 + * For the lower dir, the old monitor is still left.
17264 + if (err == -EEXIST)
17273 +void au_hn_free(struct au_hinode *hinode)
17275 + struct au_hnotify *hn;
17277 + hn = hinode->hi_notify;
17279 + hinode->hi_notify = NULL;
17280 + if (au_hnotify_op.free(hinode, hn))
17281 + au_cache_free_hnotify(hn);
17285 +/* ---------------------------------------------------------------------- */
17287 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17289 + if (hinode->hi_notify)
17290 + au_hnotify_op.ctl(hinode, do_set);
17293 +void au_hn_reset(struct inode *inode, unsigned int flags)
17295 + aufs_bindex_t bindex, bbot;
17296 + struct inode *hi;
17297 + struct dentry *iwhdentry;
17299 + bbot = au_ibbot(inode);
17300 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17301 + hi = au_h_iptr(inode, bindex);
17305 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17306 + iwhdentry = au_hi_wh(inode, bindex);
17310 + au_set_h_iptr(inode, bindex, NULL, 0);
17311 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17312 + flags & ~AuHi_XINO);
17315 + /* inode_unlock(hi); */
17319 +/* ---------------------------------------------------------------------- */
17321 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17324 + aufs_bindex_t bindex, bbot, bfound, btop;
17325 + struct inode *h_i;
17328 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17329 + pr_warn("branch root dir was changed\n");
17334 + bbot = au_ibbot(inode);
17335 + btop = au_ibtop(inode);
17336 +#if 0 /* reserved for future use */
17337 + if (bindex == bbot) {
17338 + /* keep this ino in rename case */
17342 + for (bindex = btop; bindex <= bbot; bindex++)
17343 + if (au_h_iptr(inode, bindex) == h_inode) {
17350 + for (bindex = btop; bindex <= bbot; bindex++) {
17351 + h_i = au_h_iptr(inode, bindex);
17355 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17356 + /* ignore this error */
17357 + /* bad action? */
17360 + /* children inode number will be broken */
17367 +static int hn_gen_tree(struct dentry *dentry)
17369 + int err, i, j, ndentry;
17370 + struct au_dcsub_pages dpages;
17371 + struct au_dpage *dpage;
17372 + struct dentry **dentries;
17374 + err = au_dpages_init(&dpages, GFP_NOFS);
17375 + if (unlikely(err))
17377 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17378 + if (unlikely(err))
17381 + for (i = 0; i < dpages.ndpage; i++) {
17382 + dpage = dpages.dpages + i;
17383 + dentries = dpage->dentries;
17384 + ndentry = dpage->ndentry;
17385 + for (j = 0; j < ndentry; j++) {
17386 + struct dentry *d;
17393 + if (d_really_is_positive(d))
17394 + /* todo: reset children xino?
17395 + cached children only? */
17396 + au_iigen_dec(d_inode(d));
17401 + au_dpages_free(&dpages);
17404 + /* discard children */
17405 + dentry_unhash(dentry);
17413 + * return 0 if processed.
17415 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17416 + const unsigned int isdir)
17419 + struct dentry *d;
17420 + struct qstr *dname;
17423 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17424 + pr_warn("branch root dir was changed\n");
17430 + AuDebugOn(!name);
17431 + au_iigen_dec(inode);
17432 + spin_lock(&inode->i_lock);
17433 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17434 + spin_lock(&d->d_lock);
17435 + dname = &d->d_name;
17436 + if (dname->len != nlen
17437 + && memcmp(dname->name, name, nlen)) {
17438 + spin_unlock(&d->d_lock);
17443 + spin_unlock(&d->d_lock);
17446 + spin_unlock(&inode->i_lock);
17448 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17449 + d = d_find_any_alias(inode);
17451 + au_iigen_dec(inode);
17455 + spin_lock(&d->d_lock);
17456 + dname = &d->d_name;
17457 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17458 + spin_unlock(&d->d_lock);
17459 + err = hn_gen_tree(d);
17460 + spin_lock(&d->d_lock);
17462 + spin_unlock(&d->d_lock);
17471 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17475 + if (IS_ROOT(dentry)) {
17476 + pr_warn("branch root dir was changed\n");
17482 + au_digen_dec(dentry);
17483 + if (d_really_is_positive(dentry))
17484 + au_iigen_dec(d_inode(dentry));
17486 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17487 + if (d_really_is_positive(dentry))
17488 + err = hn_gen_tree(dentry);
17495 +/* ---------------------------------------------------------------------- */
17497 +/* hnotify job flags */
17498 +#define AuHnJob_XINO0 1
17499 +#define AuHnJob_GEN (1 << 1)
17500 +#define AuHnJob_DIRENT (1 << 2)
17501 +#define AuHnJob_ISDIR (1 << 3)
17502 +#define AuHnJob_TRYXINO0 (1 << 4)
17503 +#define AuHnJob_MNTPNT (1 << 5)
17504 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17505 +#define au_fset_hnjob(flags, name) \
17506 + do { (flags) |= AuHnJob_##name; } while (0)
17507 +#define au_fclr_hnjob(flags, name) \
17508 + do { (flags) &= ~AuHnJob_##name; } while (0)
17516 +struct au_hnotify_args {
17517 + struct inode *h_dir, *dir, *h_child_inode;
17519 + unsigned int flags[AuHnLast];
17520 + unsigned int h_child_nlen;
17521 + char h_child_name[];
17524 +struct hn_job_args {
17525 + unsigned int flags;
17526 + struct inode *inode, *h_inode, *dir, *h_dir;
17527 + struct dentry *dentry;
17532 +static int hn_job(struct hn_job_args *a)
17534 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17538 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17539 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17541 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17544 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17545 + if (!a->h_inode->i_nlink
17546 + && !(a->h_inode->i_state & I_LINKABLE))
17547 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17548 + inode_unlock_shared(a->h_inode);
17551 + /* make the generation obsolete */
17552 + if (au_ftest_hnjob(a->flags, GEN)) {
17555 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17557 + if (e && a->dentry)
17558 + hn_gen_by_name(a->dentry, isdir);
17559 + /* ignore this error */
17562 + /* make dir entries obsolete */
17563 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17564 + struct au_vdir *vdir;
17566 + vdir = au_ivdir(a->inode);
17568 + vdir->vd_jiffy = 0;
17569 + /* IMustLock(a->inode); */
17570 + /* inode_inc_iversion(a->inode); */
17573 + /* can do nothing but warn */
17574 + if (au_ftest_hnjob(a->flags, MNTPNT)
17576 + && d_mountpoint(a->dentry))
17577 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17582 +/* ---------------------------------------------------------------------- */
17584 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17585 + struct inode *dir)
17587 + struct dentry *dentry, *d, *parent;
17588 + struct qstr *dname;
17590 + parent = d_find_any_alias(dir);
17595 + spin_lock(&parent->d_lock);
17596 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17597 + /* AuDbg("%pd\n", d); */
17598 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17599 + dname = &d->d_name;
17600 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17601 + goto cont_unlock;
17605 + goto cont_unlock;
17606 + if (au_dcount(d) > 0) {
17607 + dentry = dget_dlock(d);
17608 + spin_unlock(&d->d_lock);
17613 + spin_unlock(&d->d_lock);
17615 + spin_unlock(&parent->d_lock);
17619 + di_write_lock_child(dentry);
17624 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17625 + aufs_bindex_t bindex, ino_t h_ino)
17627 + struct inode *inode;
17632 + err = au_xino_read(sb, bindex, h_ino, &ino);
17634 + inode = ilookup(sb, ino);
17638 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17639 + pr_warn("wrong root branch\n");
17645 + ii_write_lock_child(inode);
17651 +static void au_hn_bh(void *_args)
17653 + struct au_hnotify_args *a = _args;
17654 + struct super_block *sb;
17655 + aufs_bindex_t bindex, bbot, bfound;
17656 + unsigned char xino, try_iput;
17658 + struct inode *inode;
17660 + struct hn_job_args args;
17661 + struct dentry *dentry;
17662 + struct au_sbinfo *sbinfo;
17664 + AuDebugOn(!_args);
17665 + AuDebugOn(!a->h_dir);
17666 + AuDebugOn(!a->dir);
17667 + AuDebugOn(!a->mask);
17668 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17669 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17670 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17675 + * do not lock a->dir->i_mutex here
17676 + * because of d_revalidate() may cause a deadlock.
17678 + sb = a->dir->i_sb;
17680 + sbinfo = au_sbi(sb);
17681 + AuDebugOn(!sbinfo);
17682 + si_write_lock(sb, AuLock_NOPLMW);
17684 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17685 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17686 + case FS_MOVED_FROM:
17687 + case FS_MOVED_TO:
17688 + AuWarn1("DIRREN with UDBA may not work correctly "
17689 + "for the direct rename(2)\n");
17692 + ii_read_lock_parent(a->dir);
17694 + bbot = au_ibbot(a->dir);
17695 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17696 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17700 + ii_read_unlock(a->dir);
17701 + if (unlikely(bfound < 0))
17704 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17706 + if (a->h_child_inode)
17707 + h_ino = a->h_child_inode->i_ino;
17709 + if (a->h_child_nlen
17710 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17711 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17712 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17715 + if (dentry && d_really_is_positive(dentry))
17716 + inode = d_inode(dentry);
17717 + if (xino && !inode && h_ino
17718 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17719 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17720 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17721 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17725 + args.flags = a->flags[AuHn_CHILD];
17726 + args.dentry = dentry;
17727 + args.inode = inode;
17728 + args.h_inode = a->h_child_inode;
17729 + args.dir = a->dir;
17730 + args.h_dir = a->h_dir;
17731 + args.h_name = a->h_child_name;
17732 + args.h_nlen = a->h_child_nlen;
17733 + err = hn_job(&args);
17735 + if (au_di(dentry))
17736 + di_write_unlock(dentry);
17739 + if (inode && try_iput) {
17740 + ii_write_unlock(inode);
17744 + ii_write_lock_parent(a->dir);
17745 + args.flags = a->flags[AuHn_PARENT];
17746 + args.dentry = NULL;
17747 + args.inode = a->dir;
17748 + args.h_inode = a->h_dir;
17750 + args.h_dir = NULL;
17751 + args.h_name = NULL;
17753 + err = hn_job(&args);
17754 + ii_write_unlock(a->dir);
17757 + iput(a->h_child_inode);
17760 + si_write_unlock(sb);
17761 + au_nwt_done(&sbinfo->si_nowait);
17765 +/* ---------------------------------------------------------------------- */
17767 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17768 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17771 + unsigned int flags[AuHnLast], f;
17772 + unsigned char isdir, isroot, wh;
17773 + struct inode *dir;
17774 + struct au_hnotify_args *args;
17775 + char *p, *h_child_name;
17778 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17779 + dir = igrab(hnotify->hn_aufs_inode);
17783 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17785 + h_child_name = (void *)h_child_qstr->name;
17786 + len = h_child_qstr->len;
17787 + if (h_child_name) {
17788 + if (len > AUFS_WH_PFX_LEN
17789 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17790 + h_child_name += AUFS_WH_PFX_LEN;
17791 + len -= AUFS_WH_PFX_LEN;
17797 + if (h_child_inode)
17798 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17799 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17800 + flags[AuHn_CHILD] = 0;
17802 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17803 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17804 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17805 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17806 + case FS_MOVED_FROM:
17807 + case FS_MOVED_TO:
17808 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17809 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17812 + AuDebugOn(!h_child_name);
17817 + * aufs never be able to get this child inode.
17818 + * revalidation should be in d_revalidate()
17819 + * by checking i_nlink, i_generation or d_unhashed().
17821 + AuDebugOn(!h_child_name);
17822 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17823 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17831 + h_child_inode = NULL;
17834 + /* iput() and kfree() will be called in au_hnotify() */
17835 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17836 + if (unlikely(!args)) {
17837 + AuErr1("no memory\n");
17841 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17842 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17843 + args->mask = mask;
17845 + args->h_dir = igrab(h_dir);
17846 + if (h_child_inode)
17847 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17848 + args->h_child_inode = h_child_inode;
17849 + args->h_child_nlen = len;
17851 + p = (void *)args;
17852 + p += sizeof(*args);
17853 + memcpy(p, h_child_name, len);
17857 + /* NFS fires the event for silly-renamed one from kworker */
17859 + if (!dir->i_nlink
17860 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17862 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17863 + if (unlikely(err)) {
17864 + pr_err("wkq %d\n", err);
17865 + iput(args->h_child_inode);
17866 + iput(args->h_dir);
17868 + au_kfree_rcu(args);
17875 +/* ---------------------------------------------------------------------- */
17877 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17881 + AuDebugOn(!(udba & AuOptMask_UDBA));
17884 + if (au_hnotify_op.reset_br)
17885 + err = au_hnotify_op.reset_br(udba, br, perm);
17890 +int au_hnotify_init_br(struct au_branch *br, int perm)
17895 + if (au_hnotify_op.init_br)
17896 + err = au_hnotify_op.init_br(br, perm);
17901 +void au_hnotify_fin_br(struct au_branch *br)
17903 + if (au_hnotify_op.fin_br)
17904 + au_hnotify_op.fin_br(br);
17907 +static void au_hn_destroy_cache(void)
17909 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17910 + au_cache[AuCache_HNOTIFY] = NULL;
17913 +int __init au_hnotify_init(void)
17918 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17919 + if (au_cache[AuCache_HNOTIFY]) {
17921 + if (au_hnotify_op.init)
17922 + err = au_hnotify_op.init();
17923 + if (unlikely(err))
17924 + au_hn_destroy_cache();
17930 +void au_hnotify_fin(void)
17932 + if (au_hnotify_op.fin)
17933 + au_hnotify_op.fin();
17935 + /* cf. au_cache_fin() */
17936 + if (au_cache[AuCache_HNOTIFY])
17937 + au_hn_destroy_cache();
17939 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17940 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 08:00:00.000000000 +0800
17941 +++ linux/fs/aufs/iinfo.c 2019-07-11 21:21:54.382384486 +0800
17943 +// SPDX-License-Identifier: GPL-2.0
17945 + * Copyright (C) 2005-2019 Junjiro R. Okajima
17947 + * This program, aufs is free software; you can redistribute it and/or modify
17948 + * it under the terms of the GNU General Public License as published by
17949 + * the Free Software Foundation; either version 2 of the License, or
17950 + * (at your option) any later version.
17952 + * This program is distributed in the hope that it will be useful,
17953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17955 + * GNU General Public License for more details.
17957 + * You should have received a copy of the GNU General Public License
17958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17962 + * inode private data
17967 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17969 + struct inode *h_inode;
17970 + struct au_hinode *hinode;
17972 + IiMustAnyLock(inode);
17974 + hinode = au_hinode(au_ii(inode), bindex);
17975 + h_inode = hinode->hi_inode;
17976 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17980 +/* todo: hard/soft set? */
17981 +void au_hiput(struct au_hinode *hinode)
17983 + au_hn_free(hinode);
17984 + dput(hinode->hi_whdentry);
17985 + iput(hinode->hi_inode);
17988 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17990 + unsigned int flags;
17991 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17994 + if (au_opt_test(mnt_flags, XINO))
17995 + au_fset_hi(flags, XINO);
17996 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17997 + au_fset_hi(flags, HNOTIFY);
18001 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18002 + struct inode *h_inode, unsigned int flags)
18004 + struct au_hinode *hinode;
18005 + struct inode *hi;
18006 + struct au_iinfo *iinfo = au_ii(inode);
18008 + IiMustWriteLock(inode);
18010 + hinode = au_hinode(iinfo, bindex);
18011 + hi = hinode->hi_inode;
18012 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18015 + au_hiput(hinode);
18016 + hinode->hi_inode = h_inode;
18019 + struct super_block *sb = inode->i_sb;
18020 + struct au_branch *br;
18022 + AuDebugOn(inode->i_mode
18023 + && (h_inode->i_mode & S_IFMT)
18024 + != (inode->i_mode & S_IFMT));
18025 + if (bindex == iinfo->ii_btop)
18026 + au_cpup_igen(inode, h_inode);
18027 + br = au_sbr(sb, bindex);
18028 + hinode->hi_id = br->br_id;
18029 + if (au_ftest_hi(flags, XINO)) {
18030 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18032 + if (unlikely(err))
18033 + AuIOErr1("failed au_xino_write() %d\n", err);
18036 + if (au_ftest_hi(flags, HNOTIFY)
18037 + && au_br_hnotifyable(br->br_perm)) {
18038 + err = au_hn_alloc(hinode, inode);
18039 + if (unlikely(err))
18040 + AuIOErr1("au_hn_alloc() %d\n", err);
18045 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18046 + struct dentry *h_wh)
18048 + struct au_hinode *hinode;
18050 + IiMustWriteLock(inode);
18052 + hinode = au_hinode(au_ii(inode), bindex);
18053 + AuDebugOn(hinode->hi_whdentry);
18054 + hinode->hi_whdentry = h_wh;
18057 +void au_update_iigen(struct inode *inode, int half)
18059 + struct au_iinfo *iinfo;
18060 + struct au_iigen *iigen;
18061 + unsigned int sigen;
18063 + sigen = au_sigen(inode->i_sb);
18064 + iinfo = au_ii(inode);
18065 + iigen = &iinfo->ii_generation;
18066 + spin_lock(&iigen->ig_spin);
18067 + iigen->ig_generation = sigen;
18069 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18071 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18072 + spin_unlock(&iigen->ig_spin);
18075 +/* it may be called at remount time, too */
18076 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18078 + struct au_iinfo *iinfo;
18079 + aufs_bindex_t bindex, bbot;
18081 + AuDebugOn(au_is_bad_inode(inode));
18082 + IiMustWriteLock(inode);
18084 + iinfo = au_ii(inode);
18085 + if (do_put_zero && iinfo->ii_btop >= 0) {
18086 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18088 + struct inode *h_i;
18090 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18093 + && !(h_i->i_state & I_LINKABLE))
18094 + au_set_h_iptr(inode, bindex, NULL, 0);
18098 + iinfo->ii_btop = -1;
18099 + iinfo->ii_bbot = -1;
18100 + bbot = au_sbbot(inode->i_sb);
18101 + for (bindex = 0; bindex <= bbot; bindex++)
18102 + if (au_hinode(iinfo, bindex)->hi_inode) {
18103 + iinfo->ii_btop = bindex;
18106 + if (iinfo->ii_btop >= 0)
18107 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18108 + if (au_hinode(iinfo, bindex)->hi_inode) {
18109 + iinfo->ii_bbot = bindex;
18112 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18115 +/* ---------------------------------------------------------------------- */
18117 +void au_icntnr_init_once(void *_c)
18119 + struct au_icntnr *c = _c;
18120 + struct au_iinfo *iinfo = &c->iinfo;
18122 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18123 + au_rw_init(&iinfo->ii_rwsem);
18124 + inode_init_once(&c->vfs_inode);
18127 +void au_hinode_init(struct au_hinode *hinode)
18129 + hinode->hi_inode = NULL;
18130 + hinode->hi_id = -1;
18131 + au_hn_init(hinode);
18132 + hinode->hi_whdentry = NULL;
18135 +int au_iinfo_init(struct inode *inode)
18137 + struct au_iinfo *iinfo;
18138 + struct super_block *sb;
18139 + struct au_hinode *hi;
18142 + sb = inode->i_sb;
18143 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18144 + nbr = au_sbbot(sb) + 1;
18145 + if (unlikely(nbr <= 0))
18147 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18149 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18151 + iinfo->ii_hinode = hi;
18152 + for (i = 0; i < nbr; i++, hi++)
18153 + au_hinode_init(hi);
18155 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18156 + iinfo->ii_btop = -1;
18157 + iinfo->ii_bbot = -1;
18158 + iinfo->ii_vdir = NULL;
18164 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18167 + struct au_hinode *hip;
18169 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18172 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18175 + iinfo->ii_hinode = hip;
18176 + i = iinfo->ii_bbot + 1;
18178 + for (; i < nbr; i++, hip++)
18179 + au_hinode_init(hip);
18186 +void au_iinfo_fin(struct inode *inode)
18188 + struct au_iinfo *iinfo;
18189 + struct au_hinode *hi;
18190 + struct super_block *sb;
18191 + aufs_bindex_t bindex, bbot;
18192 + const unsigned char unlinked = !inode->i_nlink;
18194 + AuDebugOn(au_is_bad_inode(inode));
18196 + sb = inode->i_sb;
18197 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18198 + if (si_pid_test(sb))
18199 + au_xino_delete_inode(inode, unlinked);
18202 + * it is safe to hide the dependency between sbinfo and
18206 + si_noflush_read_lock(sb);
18207 + au_xino_delete_inode(inode, unlinked);
18208 + si_read_unlock(sb);
18212 + iinfo = au_ii(inode);
18213 + if (iinfo->ii_vdir)
18214 + au_vdir_free(iinfo->ii_vdir);
18216 + bindex = iinfo->ii_btop;
18217 + if (bindex >= 0) {
18218 + hi = au_hinode(iinfo, bindex);
18219 + bbot = iinfo->ii_bbot;
18220 + while (bindex++ <= bbot) {
18221 + if (hi->hi_inode)
18226 + au_kfree_rcu(iinfo->ii_hinode);
18227 + AuRwDestroy(&iinfo->ii_rwsem);
18229 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18230 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 08:00:00.000000000 +0800
18231 +++ linux/fs/aufs/inode.c 2019-07-11 21:21:54.382384486 +0800
18233 +// SPDX-License-Identifier: GPL-2.0
18235 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18237 + * This program, aufs is free software; you can redistribute it and/or modify
18238 + * it under the terms of the GNU General Public License as published by
18239 + * the Free Software Foundation; either version 2 of the License, or
18240 + * (at your option) any later version.
18242 + * This program is distributed in the hope that it will be useful,
18243 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18244 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18245 + * GNU General Public License for more details.
18247 + * You should have received a copy of the GNU General Public License
18248 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18252 + * inode functions
18255 +#include <linux/iversion.h>
18258 +struct inode *au_igrab(struct inode *inode)
18261 + AuDebugOn(!atomic_read(&inode->i_count));
18267 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18269 + au_cpup_attr_all(inode, /*force*/0);
18270 + au_update_iigen(inode, /*half*/1);
18272 + inode_inc_iversion(inode);
18275 +static int au_ii_refresh(struct inode *inode, int *update)
18279 + aufs_bindex_t bindex, new_bindex;
18280 + struct super_block *sb;
18281 + struct au_iinfo *iinfo;
18282 + struct au_hinode *p, *q, tmp;
18284 + AuDebugOn(au_is_bad_inode(inode));
18285 + IiMustWriteLock(inode);
18288 + sb = inode->i_sb;
18289 + nbr = au_sbbot(sb) + 1;
18290 + type = inode->i_mode & S_IFMT;
18291 + iinfo = au_ii(inode);
18292 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18293 + if (unlikely(err))
18296 + AuDebugOn(iinfo->ii_btop < 0);
18297 + p = au_hinode(iinfo, iinfo->ii_btop);
18298 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18300 + if (!p->hi_inode)
18303 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18304 + new_bindex = au_br_index(sb, p->hi_id);
18305 + if (new_bindex == bindex)
18308 + if (new_bindex < 0) {
18311 + p->hi_inode = NULL;
18315 + if (new_bindex < iinfo->ii_btop)
18316 + iinfo->ii_btop = new_bindex;
18317 + if (iinfo->ii_bbot < new_bindex)
18318 + iinfo->ii_bbot = new_bindex;
18319 + /* swap two lower inode, and loop again */
18320 + q = au_hinode(iinfo, new_bindex);
18324 + if (tmp.hi_inode) {
18329 + au_update_ibrange(inode, /*do_put_zero*/0);
18330 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18331 + e = au_dy_irefresh(inode);
18332 + if (unlikely(e && !err))
18340 +void au_refresh_iop(struct inode *inode, int force_getattr)
18343 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18344 + const struct inode_operations *iop
18345 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18347 + if (inode->i_op == iop)
18350 + switch (inode->i_mode & S_IFMT) {
18352 + type = AuIop_DIR;
18355 + type = AuIop_SYMLINK;
18358 + type = AuIop_OTHER;
18362 + inode->i_op = iop + type;
18363 + /* unnecessary smp_wmb() */
18366 +int au_refresh_hinode_self(struct inode *inode)
18370 + err = au_ii_refresh(inode, &update);
18372 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18378 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18380 + int err, e, update;
18381 + unsigned int flags;
18383 + aufs_bindex_t bindex, bbot;
18384 + unsigned char isdir;
18385 + struct au_hinode *p;
18386 + struct au_iinfo *iinfo;
18388 + err = au_ii_refresh(inode, &update);
18389 + if (unlikely(err))
18393 + iinfo = au_ii(inode);
18394 + p = au_hinode(iinfo, iinfo->ii_btop);
18395 + mode = (inode->i_mode & S_IFMT);
18396 + isdir = S_ISDIR(mode);
18397 + flags = au_hi_flags(inode, isdir);
18398 + bbot = au_dbbot(dentry);
18399 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18400 + struct inode *h_i, *h_inode;
18401 + struct dentry *h_d;
18403 + h_d = au_h_dptr(dentry, bindex);
18404 + if (!h_d || d_is_negative(h_d))
18407 + h_inode = d_inode(h_d);
18408 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18409 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18410 + h_i = au_h_iptr(inode, bindex);
18412 + if (h_i == h_inode)
18418 + if (bindex < iinfo->ii_btop)
18419 + iinfo->ii_btop = bindex;
18420 + if (iinfo->ii_bbot < bindex)
18421 + iinfo->ii_bbot = bindex;
18422 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18425 + au_update_ibrange(inode, /*do_put_zero*/0);
18426 + e = au_dy_irefresh(inode);
18427 + if (unlikely(e && !err))
18430 + au_refresh_hinode_attr(inode, update && isdir);
18437 +static int set_inode(struct inode *inode, struct dentry *dentry)
18440 + unsigned int flags;
18442 + aufs_bindex_t bindex, btop, btail;
18443 + unsigned char isdir;
18444 + struct dentry *h_dentry;
18445 + struct inode *h_inode;
18446 + struct au_iinfo *iinfo;
18447 + struct inode_operations *iop;
18449 + IiMustWriteLock(inode);
18453 + iop = au_sbi(inode->i_sb)->si_iop_array;
18454 + btop = au_dbtop(dentry);
18455 + h_dentry = au_h_dptr(dentry, btop);
18456 + h_inode = d_inode(h_dentry);
18457 + mode = h_inode->i_mode;
18458 + switch (mode & S_IFMT) {
18460 + btail = au_dbtail(dentry);
18461 + inode->i_op = iop + AuIop_OTHER;
18462 + inode->i_fop = &aufs_file_fop;
18463 + err = au_dy_iaop(inode, btop, h_inode);
18464 + if (unlikely(err))
18469 + btail = au_dbtaildir(dentry);
18470 + inode->i_op = iop + AuIop_DIR;
18471 + inode->i_fop = &aufs_dir_fop;
18474 + btail = au_dbtail(dentry);
18475 + inode->i_op = iop + AuIop_SYMLINK;
18481 + btail = au_dbtail(dentry);
18482 + inode->i_op = iop + AuIop_OTHER;
18483 + init_special_inode(inode, mode, h_inode->i_rdev);
18486 + AuIOErr("Unknown file type 0%o\n", mode);
18491 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18492 + flags = au_hi_flags(inode, isdir);
18493 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18494 + && au_ftest_hi(flags, HNOTIFY)
18495 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18496 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18497 + au_fclr_hi(flags, HNOTIFY);
18498 + iinfo = au_ii(inode);
18499 + iinfo->ii_btop = btop;
18500 + iinfo->ii_bbot = btail;
18501 + for (bindex = btop; bindex <= btail; bindex++) {
18502 + h_dentry = au_h_dptr(dentry, bindex);
18504 + au_set_h_iptr(inode, bindex,
18505 + au_igrab(d_inode(h_dentry)), flags);
18507 + au_cpup_attr_all(inode, /*force*/1);
18509 + * to force calling aufs_get_acl() every time,
18510 + * do not call cache_no_acl() for aufs inode.
18518 + * successful returns with iinfo write_locked
18520 + * zero: success, matched
18521 + * plus: no error, but unmatched
18523 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18526 + unsigned int gen, igflags;
18527 + aufs_bindex_t bindex, bbot;
18528 + struct inode *h_inode, *h_dinode;
18529 + struct dentry *h_dentry;
18532 + * before this function, if aufs got any iinfo lock, it must be only
18533 + * one, the parent dir.
18534 + * it can happen by UDBA and the obsoleted inode number.
18537 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18541 + ii_write_lock_new_child(inode);
18542 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18543 + h_dinode = d_inode(h_dentry);
18544 + bbot = au_ibbot(inode);
18545 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18546 + h_inode = au_h_iptr(inode, bindex);
18547 + if (!h_inode || h_inode != h_dinode)
18551 + gen = au_iigen(inode, &igflags);
18552 + if (gen == au_digen(dentry)
18553 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18556 + /* fully refresh inode using dentry */
18557 + err = au_refresh_hinode(inode, dentry);
18559 + au_update_iigen(inode, /*half*/0);
18563 + if (unlikely(err))
18564 + ii_write_unlock(inode);
18569 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18570 + unsigned int d_type, ino_t *ino)
18573 + const int isnondir = d_type != DT_DIR;
18575 + /* prevent hardlinked inode number from race condition */
18577 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18578 + if (unlikely(err))
18582 + err = au_xino_read(sb, bindex, h_ino, ino);
18583 + if (unlikely(err))
18584 + goto out_xinondir;
18588 + *ino = au_xino_new_ino(sb);
18589 + if (unlikely(!*ino))
18590 + goto out_xinondir;
18591 + err = au_xino_write(sb, bindex, h_ino, *ino);
18592 + if (unlikely(err))
18593 + goto out_xinondir;
18597 + if (isnondir && idx >= 0)
18598 + au_xinondir_leave(sb, bindex, h_ino, idx);
18603 +/* successful returns with iinfo write_locked */
18604 +/* todo: return with unlocked? */
18605 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18607 + struct inode *inode, *h_inode;
18608 + struct dentry *h_dentry;
18609 + struct super_block *sb;
18610 + ino_t h_ino, ino;
18611 + int err, idx, hlinked;
18612 + aufs_bindex_t btop;
18614 + sb = dentry->d_sb;
18615 + btop = au_dbtop(dentry);
18616 + h_dentry = au_h_dptr(dentry, btop);
18617 + h_inode = d_inode(h_dentry);
18618 + h_ino = h_inode->i_ino;
18619 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18623 + * stop 'race'-ing between hardlinks under different
18627 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18628 + inode = ERR_PTR(err);
18629 + if (unlikely(err))
18633 + err = au_xino_read(sb, btop, h_ino, &ino);
18634 + inode = ERR_PTR(err);
18635 + if (unlikely(err))
18636 + goto out_xinondir;
18639 + ino = au_xino_new_ino(sb);
18640 + if (unlikely(!ino)) {
18641 + inode = ERR_PTR(-EIO);
18642 + goto out_xinondir;
18646 + AuDbg("i%lu\n", (unsigned long)ino);
18647 + inode = au_iget_locked(sb, ino);
18648 + err = PTR_ERR(inode);
18649 + if (IS_ERR(inode))
18650 + goto out_xinondir;
18652 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18653 + if (inode->i_state & I_NEW) {
18654 + ii_write_lock_new_child(inode);
18655 + err = set_inode(inode, dentry);
18657 + unlock_new_inode(inode);
18658 + goto out_xinondir; /* success */
18662 + * iget_failed() calls iput(), but we need to call
18663 + * ii_write_unlock() after iget_failed(). so dirty hack for
18666 + atomic_inc(&inode->i_count);
18667 + iget_failed(inode);
18668 + ii_write_unlock(inode);
18669 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18670 + /* ignore this error */
18672 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18674 + * horrible race condition between lookup, readdir and copyup
18675 + * (or something).
18677 + if (hlinked && idx >= 0)
18678 + au_xinondir_leave(sb, btop, h_ino, idx);
18679 + err = reval_inode(inode, dentry);
18680 + if (unlikely(err < 0)) {
18685 + goto out; /* success */
18686 + else if (hlinked && idx >= 0) {
18687 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18688 + if (unlikely(err)) {
18690 + inode = ERR_PTR(err);
18696 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18697 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18698 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18699 + btop, au_sbtype(h_dentry->d_sb), dentry,
18700 + (unsigned long)h_ino, (unsigned long)ino);
18702 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18705 + if (hlinked && idx >= 0)
18706 + au_xinondir_leave(sb, btop, h_ino, idx);
18712 + inode = ERR_PTR(err);
18714 + if (hlinked && idx >= 0)
18715 + au_xinondir_leave(sb, btop, h_ino, idx);
18720 +/* ---------------------------------------------------------------------- */
18722 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18723 + struct inode *inode)
18726 + struct inode *hi;
18728 + err = au_br_rdonly(au_sbr(sb, bindex));
18730 + /* pseudo-link after flushed may happen out of bounds */
18733 + && au_ibtop(inode) <= bindex
18734 + && bindex <= au_ibbot(inode)) {
18736 + * permission check is unnecessary since vfsub routine
18737 + * will be called later
18739 + hi = au_h_iptr(inode, bindex);
18741 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18747 +int au_test_h_perm(struct inode *h_inode, int mask)
18749 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18751 + return inode_permission(h_inode, mask);
18754 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18756 + if (au_test_nfs(h_inode->i_sb)
18757 + && (mask & MAY_WRITE)
18758 + && S_ISDIR(h_inode->i_mode))
18759 + mask |= MAY_READ; /* force permission check */
18760 + return au_test_h_perm(h_inode, mask);
18762 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18763 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 08:00:00.000000000 +0800
18764 +++ linux/fs/aufs/inode.h 2019-07-11 21:21:54.382384486 +0800
18766 +/* SPDX-License-Identifier: GPL-2.0 */
18768 + * Copyright (C) 2005-2019 Junjiro R. Okajima
18770 + * This program, aufs is free software; you can redistribute it and/or modify
18771 + * it under the terms of the GNU General Public License as published by
18772 + * the Free Software Foundation; either version 2 of the License, or
18773 + * (at your option) any later version.
18775 + * This program is distributed in the hope that it will be useful,
18776 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18777 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18778 + * GNU General Public License for more details.
18780 + * You should have received a copy of the GNU General Public License
18781 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18785 + * inode operations
18788 +#ifndef __AUFS_INODE_H__
18789 +#define __AUFS_INODE_H__
18793 +#include <linux/fsnotify.h>
18794 +#include "rwsem.h"
18798 +struct au_hnotify {
18799 +#ifdef CONFIG_AUFS_HNOTIFY
18800 +#ifdef CONFIG_AUFS_HFSNOTIFY
18801 + /* never use fsnotify_add_vfsmount_mark() */
18802 + struct fsnotify_mark hn_mark;
18804 + struct inode *hn_aufs_inode; /* no get/put */
18805 + struct rcu_head rcu;
18807 +} ____cacheline_aligned_in_smp;
18809 +struct au_hinode {
18810 + struct inode *hi_inode;
18811 + aufs_bindex_t hi_id;
18812 +#ifdef CONFIG_AUFS_HNOTIFY
18813 + struct au_hnotify *hi_notify;
18816 + /* reference to the copied-up whiteout with get/put */
18817 + struct dentry *hi_whdentry;
18821 +#define AuIG_HALF_REFRESHED 1
18822 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18823 +#define au_ig_fset(flags, name) \
18824 + do { (flags) |= AuIG_##name; } while (0)
18825 +#define au_ig_fclr(flags, name) \
18826 + do { (flags) &= ~AuIG_##name; } while (0)
18829 + spinlock_t ig_spin;
18830 + __u32 ig_generation, ig_flags;
18835 + struct au_iigen ii_generation;
18836 + struct super_block *ii_hsb1; /* no get/put */
18838 + struct au_rwsem ii_rwsem;
18839 + aufs_bindex_t ii_btop, ii_bbot;
18841 + struct au_hinode *ii_hinode;
18842 + struct au_vdir *ii_vdir;
18845 +struct au_icntnr {
18846 + struct au_iinfo iinfo;
18847 + struct inode vfs_inode;
18848 + struct hlist_bl_node plink;
18849 + struct rcu_head rcu;
18850 +} ____cacheline_aligned_in_smp;
18852 +/* au_pin flags */
18853 +#define AuPin_DI_LOCKED 1
18854 +#define AuPin_MNT_WRITE (1 << 1)
18855 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18856 +#define au_fset_pin(flags, name) \
18857 + do { (flags) |= AuPin_##name; } while (0)
18858 +#define au_fclr_pin(flags, name) \
18859 + do { (flags) &= ~AuPin_##name; } while (0)
18863 + struct dentry *dentry;
18864 + unsigned int udba;
18865 + unsigned char lsc_di, lsc_hi, flags;
18866 + aufs_bindex_t bindex;
18869 + struct dentry *parent;
18870 + struct au_hinode *hdir;
18871 + struct vfsmount *h_mnt;
18873 + /* temporary unlock/relock for copyup */
18874 + struct dentry *h_dentry, *h_parent;
18875 + struct au_branch *br;
18876 + struct task_struct *task;
18879 +void au_pin_hdir_unlock(struct au_pin *p);
18880 +int au_pin_hdir_lock(struct au_pin *p);
18881 +int au_pin_hdir_relock(struct au_pin *p);
18882 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18883 +void au_pin_hdir_release(struct au_pin *p);
18885 +/* ---------------------------------------------------------------------- */
18887 +static inline struct au_iinfo *au_ii(struct inode *inode)
18889 + BUG_ON(is_bad_inode(inode));
18890 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18893 +/* ---------------------------------------------------------------------- */
18896 +struct inode *au_igrab(struct inode *inode);
18897 +void au_refresh_iop(struct inode *inode, int force_getattr);
18898 +int au_refresh_hinode_self(struct inode *inode);
18899 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18900 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18901 + unsigned int d_type, ino_t *ino);
18902 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18903 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18904 + struct inode *inode);
18905 +int au_test_h_perm(struct inode *h_inode, int mask);
18906 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18908 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18909 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18911 +#ifdef CONFIG_AUFS_SHWH
18912 + return au_ino(sb, bindex, h_ino, d_type, ino);
18925 +extern struct inode_operations aufs_iop[AuIop_Last],
18926 + aufs_iop_nogetattr[AuIop_Last];
18928 +/* au_wr_dir flags */
18929 +#define AuWrDir_ADD_ENTRY 1
18930 +#define AuWrDir_ISDIR (1 << 1)
18931 +#define AuWrDir_TMPFILE (1 << 2)
18932 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18933 +#define au_fset_wrdir(flags, name) \
18934 + do { (flags) |= AuWrDir_##name; } while (0)
18935 +#define au_fclr_wrdir(flags, name) \
18936 + do { (flags) &= ~AuWrDir_##name; } while (0)
18938 +struct au_wr_dir_args {
18939 + aufs_bindex_t force_btgt;
18940 + unsigned char flags;
18942 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18943 + struct au_wr_dir_args *args);
18945 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18946 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18947 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18948 + unsigned int udba, unsigned char flags);
18949 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18950 + unsigned int udba, unsigned char flags) __must_check;
18951 +int au_do_pin(struct au_pin *pin) __must_check;
18952 +void au_unpin(struct au_pin *pin);
18953 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18955 +#define AuIcpup_DID_CPUP 1
18956 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18957 +#define au_fset_icpup(flags, name) \
18958 + do { (flags) |= AuIcpup_##name; } while (0)
18959 +#define au_fclr_icpup(flags, name) \
18960 + do { (flags) &= ~AuIcpup_##name; } while (0)
18962 +struct au_icpup_args {
18963 + unsigned char flags;
18964 + unsigned char pin_flags;
18965 + aufs_bindex_t btgt;
18966 + unsigned int udba;
18967 + struct au_pin pin;
18968 + struct path h_path;
18969 + struct inode *h_inode;
18972 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18973 + struct au_icpup_args *a);
18975 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
18979 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18980 + struct dentry *h_parent, int isdir);
18981 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18983 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18984 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18986 +struct vfsub_aopen_args;
18987 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18988 + struct vfsub_aopen_args *args);
18989 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18990 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18991 + struct dentry *dentry);
18992 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18995 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18996 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18997 + struct dentry *h_parent, int isdir);
18998 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18999 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19002 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19003 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19004 + struct inode *dir, struct dentry *dentry,
19005 + unsigned int flags);
19008 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19009 +void au_hiput(struct au_hinode *hinode);
19010 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19011 + struct dentry *h_wh);
19012 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19014 +/* hinode flags */
19015 +#define AuHi_XINO 1
19016 +#define AuHi_HNOTIFY (1 << 1)
19017 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19018 +#define au_fset_hi(flags, name) \
19019 + do { (flags) |= AuHi_##name; } while (0)
19020 +#define au_fclr_hi(flags, name) \
19021 + do { (flags) &= ~AuHi_##name; } while (0)
19023 +#ifndef CONFIG_AUFS_HNOTIFY
19024 +#undef AuHi_HNOTIFY
19025 +#define AuHi_HNOTIFY 0
19028 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19029 + struct inode *h_inode, unsigned int flags);
19031 +void au_update_iigen(struct inode *inode, int half);
19032 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19034 +void au_icntnr_init_once(void *_c);
19035 +void au_hinode_init(struct au_hinode *hinode);
19036 +int au_iinfo_init(struct inode *inode);
19037 +void au_iinfo_fin(struct inode *inode);
19038 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19040 +#ifdef CONFIG_PROC_FS
19042 +int au_plink_maint(struct super_block *sb, int flags);
19044 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19045 +int au_plink_maint_enter(struct super_block *sb);
19046 +#ifdef CONFIG_AUFS_DEBUG
19047 +void au_plink_list(struct super_block *sb);
19049 +AuStubVoid(au_plink_list, struct super_block *sb)
19051 +int au_plink_test(struct inode *inode);
19052 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19053 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19054 + struct dentry *h_dentry);
19055 +void au_plink_put(struct super_block *sb, int verbose);
19056 +void au_plink_clean(struct super_block *sb, int verbose);
19057 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19059 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19060 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19061 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19062 +AuStubVoid(au_plink_list, struct super_block *sb);
19063 +AuStubInt0(au_plink_test, struct inode *inode);
19064 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19065 + struct inode *inode, aufs_bindex_t bindex);
19066 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19067 + struct dentry *h_dentry);
19068 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19069 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19070 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19071 +#endif /* CONFIG_PROC_FS */
19073 +#ifdef CONFIG_AUFS_XATTR
19075 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19076 + unsigned int verbose);
19077 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19078 +void au_xattr_init(struct super_block *sb);
19080 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19081 + int ignore_flags, unsigned int verbose);
19082 +AuStubVoid(au_xattr_init, struct super_block *sb);
19085 +#ifdef CONFIG_FS_POSIX_ACL
19086 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19087 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19090 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19096 +struct au_sxattr {
19100 + const char *name;
19101 + const void *value;
19106 + struct posix_acl *acl;
19111 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19112 + struct au_sxattr *arg);
19115 +/* ---------------------------------------------------------------------- */
19117 +/* lock subclass for iinfo */
19119 + AuLsc_II_CHILD, /* child first */
19120 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19121 + AuLsc_II_CHILD3, /* copyup dirs */
19122 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19123 + AuLsc_II_PARENT2,
19124 + AuLsc_II_PARENT3, /* copyup dirs */
19125 + AuLsc_II_NEW_CHILD
19129 + * ii_read_lock_child, ii_write_lock_child,
19130 + * ii_read_lock_child2, ii_write_lock_child2,
19131 + * ii_read_lock_child3, ii_write_lock_child3,
19132 + * ii_read_lock_parent, ii_write_lock_parent,
19133 + * ii_read_lock_parent2, ii_write_lock_parent2,
19134 + * ii_read_lock_parent3, ii_write_lock_parent3,
19135 + * ii_read_lock_new_child, ii_write_lock_new_child,
19137 +#define AuReadLockFunc(name, lsc) \
19138 +static inline void ii_read_lock_##name(struct inode *i) \
19140 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19143 +#define AuWriteLockFunc(name, lsc) \
19144 +static inline void ii_write_lock_##name(struct inode *i) \
19146 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19149 +#define AuRWLockFuncs(name, lsc) \
19150 + AuReadLockFunc(name, lsc) \
19151 + AuWriteLockFunc(name, lsc)
19153 +AuRWLockFuncs(child, CHILD);
19154 +AuRWLockFuncs(child2, CHILD2);
19155 +AuRWLockFuncs(child3, CHILD3);
19156 +AuRWLockFuncs(parent, PARENT);
19157 +AuRWLockFuncs(parent2, PARENT2);
19158 +AuRWLockFuncs(parent3, PARENT3);
19159 +AuRWLockFuncs(new_child, NEW_CHILD);
19161 +#undef AuReadLockFunc
19162 +#undef AuWriteLockFunc
19163 +#undef AuRWLockFuncs
19165 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19166 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19167 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19169 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19170 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19171 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19173 +/* ---------------------------------------------------------------------- */
19175 +static inline void au_icntnr_init(struct au_icntnr *c)
19177 +#ifdef CONFIG_AUFS_DEBUG
19178 + c->vfs_inode.i_mode = 0;
19182 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19184 + unsigned int gen;
19185 + struct au_iinfo *iinfo;
19186 + struct au_iigen *iigen;
19188 + iinfo = au_ii(inode);
19189 + iigen = &iinfo->ii_generation;
19190 + spin_lock(&iigen->ig_spin);
19192 + *igflags = iigen->ig_flags;
19193 + gen = iigen->ig_generation;
19194 + spin_unlock(&iigen->ig_spin);
19199 +/* tiny test for inode number */
19200 +/* tmpfs generation is too rough */
19201 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19203 + struct au_iinfo *iinfo;
19205 + iinfo = au_ii(inode);
19206 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19207 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19208 + && iinfo->ii_higen == h_inode->i_generation);
19211 +static inline void au_iigen_dec(struct inode *inode)
19213 + struct au_iinfo *iinfo;
19214 + struct au_iigen *iigen;
19216 + iinfo = au_ii(inode);
19217 + iigen = &iinfo->ii_generation;
19218 + spin_lock(&iigen->ig_spin);
19219 + iigen->ig_generation--;
19220 + spin_unlock(&iigen->ig_spin);
19223 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19228 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19234 +/* ---------------------------------------------------------------------- */
19236 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19237 + aufs_bindex_t bindex)
19239 + return iinfo->ii_hinode + bindex;
19242 +static inline int au_is_bad_inode(struct inode *inode)
19244 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19247 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19248 + aufs_bindex_t bindex)
19250 + IiMustAnyLock(inode);
19251 + return au_hinode(au_ii(inode), bindex)->hi_id;
19254 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19256 + IiMustAnyLock(inode);
19257 + return au_ii(inode)->ii_btop;
19260 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19262 + IiMustAnyLock(inode);
19263 + return au_ii(inode)->ii_bbot;
19266 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19268 + IiMustAnyLock(inode);
19269 + return au_ii(inode)->ii_vdir;
19272 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19274 + IiMustAnyLock(inode);
19275 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19278 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19280 + IiMustWriteLock(inode);
19281 + au_ii(inode)->ii_btop = bindex;
19284 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19286 + IiMustWriteLock(inode);
19287 + au_ii(inode)->ii_bbot = bindex;
19290 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19292 + IiMustWriteLock(inode);
19293 + au_ii(inode)->ii_vdir = vdir;
19296 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19298 + IiMustAnyLock(inode);
19299 + return au_hinode(au_ii(inode), bindex);
19302 +/* ---------------------------------------------------------------------- */
19304 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19307 + return pin->parent;
19311 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19313 + if (pin && pin->hdir)
19314 + return pin->hdir->hi_inode;
19318 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19321 + return pin->hdir;
19325 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19328 + pin->dentry = dentry;
19331 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19332 + unsigned char lflag)
19336 + au_fset_pin(pin->flags, DI_LOCKED);
19338 + au_fclr_pin(pin->flags, DI_LOCKED);
19342 +#if 0 /* reserved */
19343 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19346 + dput(pin->parent);
19347 + pin->parent = dget(parent);
19352 +/* ---------------------------------------------------------------------- */
19355 +#ifdef CONFIG_AUFS_HNOTIFY
19356 +struct au_hnotify_op {
19357 + void (*ctl)(struct au_hinode *hinode, int do_set);
19358 + int (*alloc)(struct au_hinode *hinode);
19361 + * if it returns true, the the caller should free hinode->hi_notify,
19362 + * otherwise ->free() frees it.
19364 + int (*free)(struct au_hinode *hinode,
19365 + struct au_hnotify *hn) __must_check;
19367 + void (*fin)(void);
19368 + int (*init)(void);
19370 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19371 + void (*fin_br)(struct au_branch *br);
19372 + int (*init_br)(struct au_branch *br, int perm);
19376 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19377 +void au_hn_free(struct au_hinode *hinode);
19378 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19379 +void au_hn_reset(struct inode *inode, unsigned int flags);
19380 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19381 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19382 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19383 +int au_hnotify_init_br(struct au_branch *br, int perm);
19384 +void au_hnotify_fin_br(struct au_branch *br);
19385 +int __init au_hnotify_init(void);
19386 +void au_hnotify_fin(void);
19389 +extern const struct au_hnotify_op au_hnotify_op;
19392 +void au_hn_init(struct au_hinode *hinode)
19394 + hinode->hi_notify = NULL;
19397 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19399 + return hinode->hi_notify;
19403 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19404 + struct au_hinode *hinode __maybe_unused,
19405 + struct inode *inode __maybe_unused)
19406 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19407 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19408 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19409 + int do_set __maybe_unused)
19410 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19411 + unsigned int flags __maybe_unused)
19412 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19413 + struct au_branch *br __maybe_unused,
19414 + int perm __maybe_unused)
19415 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19416 + int perm __maybe_unused)
19417 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19418 +AuStubInt0(__init au_hnotify_init, void)
19419 +AuStubVoid(au_hnotify_fin, void)
19420 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19421 +#endif /* CONFIG_AUFS_HNOTIFY */
19423 +static inline void au_hn_suspend(struct au_hinode *hdir)
19425 + au_hn_ctl(hdir, /*do_set*/0);
19428 +static inline void au_hn_resume(struct au_hinode *hdir)
19430 + au_hn_ctl(hdir, /*do_set*/1);
19433 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19435 + inode_lock(hdir->hi_inode);
19436 + au_hn_suspend(hdir);
19439 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19440 + unsigned int sc __maybe_unused)
19442 + inode_lock_nested(hdir->hi_inode, sc);
19443 + au_hn_suspend(hdir);
19446 +#if 0 /* unused */
19447 +#include "vfsub.h"
19448 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19451 + inode_lock_shared_nested(hdir->hi_inode, sc);
19452 + au_hn_suspend(hdir);
19456 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19458 + au_hn_resume(hdir);
19459 + inode_unlock(hdir->hi_inode);
19462 +#endif /* __KERNEL__ */
19463 +#endif /* __AUFS_INODE_H__ */
19464 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19465 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 08:00:00.000000000 +0800
19466 +++ linux/fs/aufs/ioctl.c 2019-07-11 21:21:54.382384486 +0800
19468 +// SPDX-License-Identifier: GPL-2.0
19470 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19472 + * This program, aufs is free software; you can redistribute it and/or modify
19473 + * it under the terms of the GNU General Public License as published by
19474 + * the Free Software Foundation; either version 2 of the License, or
19475 + * (at your option) any later version.
19477 + * This program is distributed in the hope that it will be useful,
19478 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19479 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19480 + * GNU General Public License for more details.
19482 + * You should have received a copy of the GNU General Public License
19483 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19488 + * plink-management and readdir in userspace.
19489 + * assist the pathconf(3) wrapper library.
19491 + * File-based Hierarchical Storage Management.
19494 +#include <linux/compat.h>
19495 +#include <linux/file.h>
19498 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19501 + aufs_bindex_t wbi, bindex, bbot;
19502 + struct file *h_file;
19503 + struct super_block *sb;
19504 + struct dentry *root;
19505 + struct au_branch *br;
19506 + struct aufs_wbr_fd wbrfd = {
19507 + .oflags = au_dir_roflags,
19510 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19511 + | O_NOATIME | O_CLOEXEC;
19513 + AuDebugOn(wbrfd.oflags & ~valid);
19516 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19517 + if (unlikely(err)) {
19523 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19524 + wbrfd.oflags |= au_dir_roflags;
19525 + AuDbg("0%o\n", wbrfd.oflags);
19526 + if (unlikely(wbrfd.oflags & ~valid))
19530 + fd = get_unused_fd_flags(0);
19532 + if (unlikely(fd < 0))
19535 + h_file = ERR_PTR(-EINVAL);
19538 + sb = path->dentry->d_sb;
19539 + root = sb->s_root;
19540 + aufs_read_lock(root, AuLock_IR);
19541 + bbot = au_sbbot(sb);
19542 + if (wbrfd.brid >= 0) {
19543 + wbi = au_br_index(sb, wbrfd.brid);
19544 + if (unlikely(wbi < 0 || wbi > bbot))
19548 + h_file = ERR_PTR(-ENOENT);
19549 + br = au_sbr(sb, wbi);
19550 + if (!au_br_writable(br->br_perm)) {
19554 + bindex = wbi + 1;
19556 + for (; bindex <= bbot; bindex++) {
19557 + br = au_sbr(sb, bindex);
19558 + if (au_br_writable(br->br_perm)) {
19560 + br = au_sbr(sb, wbi);
19565 + AuDbg("wbi %d\n", wbi);
19567 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19571 + aufs_read_unlock(root, AuLock_IR);
19572 + err = PTR_ERR(h_file);
19573 + if (IS_ERR(h_file))
19576 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19577 + fd_install(fd, h_file);
19579 + goto out; /* success */
19582 + put_unused_fd(fd);
19588 +/* ---------------------------------------------------------------------- */
19590 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19593 + struct dentry *dentry;
19596 + case AUFS_CTL_RDU:
19597 + case AUFS_CTL_RDU_INO:
19598 + err = au_rdu_ioctl(file, cmd, arg);
19601 + case AUFS_CTL_WBR_FD:
19602 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19605 + case AUFS_CTL_IBUSY:
19606 + err = au_ibusy_ioctl(file, arg);
19609 + case AUFS_CTL_BRINFO:
19610 + err = au_brinfo_ioctl(file, arg);
19613 + case AUFS_CTL_FHSM_FD:
19614 + dentry = file->f_path.dentry;
19615 + if (IS_ROOT(dentry))
19616 + err = au_fhsm_fd(dentry->d_sb, arg);
19622 + /* do not call the lower */
19623 + AuDbg("0x%x\n", cmd);
19631 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19636 + case AUFS_CTL_MVDOWN:
19637 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19640 + case AUFS_CTL_WBR_FD:
19641 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19645 + /* do not call the lower */
19646 + AuDbg("0x%x\n", cmd);
19654 +#ifdef CONFIG_COMPAT
19655 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19656 + unsigned long arg)
19661 + case AUFS_CTL_RDU:
19662 + case AUFS_CTL_RDU_INO:
19663 + err = au_rdu_compat_ioctl(file, cmd, arg);
19666 + case AUFS_CTL_IBUSY:
19667 + err = au_ibusy_compat_ioctl(file, arg);
19670 + case AUFS_CTL_BRINFO:
19671 + err = au_brinfo_compat_ioctl(file, arg);
19675 + err = aufs_ioctl_dir(file, cmd, arg);
19682 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19683 + unsigned long arg)
19685 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19688 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19689 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 08:00:00.000000000 +0800
19690 +++ linux/fs/aufs/i_op_add.c 2019-07-11 21:21:54.382384486 +0800
19692 +// SPDX-License-Identifier: GPL-2.0
19694 + * Copyright (C) 2005-2019 Junjiro R. Okajima
19696 + * This program, aufs is free software; you can redistribute it and/or modify
19697 + * it under the terms of the GNU General Public License as published by
19698 + * the Free Software Foundation; either version 2 of the License, or
19699 + * (at your option) any later version.
19701 + * This program is distributed in the hope that it will be useful,
19702 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19703 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19704 + * GNU General Public License for more details.
19706 + * You should have received a copy of the GNU General Public License
19707 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19711 + * inode operations (add entry)
19714 +#include <linux/iversion.h>
19718 + * final procedure of adding a new entry, except link(2).
19719 + * remove whiteout, instantiate, copyup the parent dir's times and size
19720 + * and update version.
19721 + * if it failed, re-create the removed whiteout.
19723 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19724 + struct dentry *wh_dentry, struct dentry *dentry)
19727 + aufs_bindex_t bwh;
19728 + struct path h_path;
19729 + struct super_block *sb;
19730 + struct inode *inode, *h_dir;
19731 + struct dentry *wh;
19736 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19737 + IMustLock(h_dir);
19738 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19739 + bwh = au_dbwh(dentry);
19740 + h_path.dentry = wh_dentry;
19741 + h_path.mnt = au_sbr_mnt(sb, bindex);
19742 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19744 + if (unlikely(err))
19748 + inode = au_new_inode(dentry, /*must_new*/1);
19749 + if (!IS_ERR(inode)) {
19750 + d_instantiate(dentry, inode);
19751 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19753 + au_dir_ts(dir, bindex);
19754 + inode_inc_iversion(dir);
19755 + au_fhsm_wrote(sb, bindex, /*force*/0);
19756 + return 0; /* success */
19759 + err = PTR_ERR(inode);
19764 + /* dir inode is locked */
19765 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19766 + rerr = PTR_ERR(wh);
19767 + if (IS_ERR(wh)) {
19768 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19769 + dentry, err, rerr);
19778 +static int au_d_may_add(struct dentry *dentry)
19783 + if (unlikely(d_unhashed(dentry)))
19785 + if (unlikely(d_really_is_positive(dentry)))
19791 + * simple tests for the adding inode operations.
19792 + * following the checks in vfs, plus the parent-child relationship.
19794 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19795 + struct dentry *h_parent, int isdir)
19799 + struct dentry *h_dentry;
19800 + struct inode *h_inode;
19802 + err = -ENAMETOOLONG;
19803 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19806 + h_dentry = au_h_dptr(dentry, bindex);
19807 + if (d_really_is_negative(dentry)) {
19809 + if (unlikely(d_is_positive(h_dentry)))
19812 + /* rename(2) case */
19814 + if (unlikely(d_is_negative(h_dentry)))
19816 + h_inode = d_inode(h_dentry);
19817 + if (unlikely(!h_inode->i_nlink))
19820 + h_mode = h_inode->i_mode;
19823 + if (unlikely(S_ISDIR(h_mode)))
19825 + } else if (unlikely(!S_ISDIR(h_mode))) {
19832 + /* expected parent dir is locked */
19833 + if (unlikely(h_parent != h_dentry->d_parent))
19842 + * initial procedure of adding a new entry.
19843 + * prepare writable branch and the parent dir, lock it,
19844 + * and lookup whiteout for the new entry.
19846 +static struct dentry*
19847 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19848 + struct dentry *src_dentry, struct au_pin *pin,
19849 + struct au_wr_dir_args *wr_dir_args)
19851 + struct dentry *wh_dentry, *h_parent;
19852 + struct super_block *sb;
19853 + struct au_branch *br;
19855 + unsigned int udba;
19856 + aufs_bindex_t bcpup;
19858 + AuDbg("%pd\n", dentry);
19860 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19862 + wh_dentry = ERR_PTR(err);
19863 + if (unlikely(err < 0))
19866 + sb = dentry->d_sb;
19867 + udba = au_opt_udba(sb);
19868 + err = au_pin(pin, dentry, bcpup, udba,
19869 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19870 + wh_dentry = ERR_PTR(err);
19871 + if (unlikely(err))
19874 + h_parent = au_pinned_h_parent(pin);
19875 + if (udba != AuOpt_UDBA_NONE
19876 + && au_dbtop(dentry) == bcpup)
19877 + err = au_may_add(dentry, bcpup, h_parent,
19878 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19879 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19880 + err = -ENAMETOOLONG;
19881 + wh_dentry = ERR_PTR(err);
19882 + if (unlikely(err))
19885 + br = au_sbr(sb, bcpup);
19887 + struct path tmp = {
19888 + .dentry = h_parent,
19889 + .mnt = au_br_mnt(br)
19891 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19894 + wh_dentry = NULL;
19895 + if (bcpup != au_dbwh(dentry))
19896 + goto out; /* success */
19899 + * ENAMETOOLONG here means that if we allowed create such name, then it
19900 + * would not be able to removed in the future. So we don't allow such
19901 + * name here and we don't handle ENAMETOOLONG differently here.
19903 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19906 + if (IS_ERR(wh_dentry))
19909 + return wh_dentry;
19912 +/* ---------------------------------------------------------------------- */
19914 +enum { Mknod, Symlink, Creat };
19915 +struct simple_arg {
19922 + struct vfsub_aopen_args *aopen;
19925 + const char *symname;
19934 +static int add_simple(struct inode *dir, struct dentry *dentry,
19935 + struct simple_arg *arg)
19938 + aufs_bindex_t btop;
19939 + unsigned char created;
19940 + const unsigned char try_aopen
19941 + = (arg->type == Creat && arg->u.c.try_aopen);
19942 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19943 + struct dentry *wh_dentry, *parent;
19944 + struct inode *h_dir;
19945 + struct super_block *sb;
19946 + struct au_branch *br;
19947 + /* to reduce stack size */
19949 + struct au_dtime dt;
19950 + struct au_pin pin;
19951 + struct path h_path;
19952 + struct au_wr_dir_args wr_dir_args;
19955 + AuDbg("%pd\n", dentry);
19959 + a = kmalloc(sizeof(*a), GFP_NOFS);
19960 + if (unlikely(!a))
19962 + a->wr_dir_args.force_btgt = -1;
19963 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19965 + parent = dentry->d_parent; /* dir inode is locked */
19966 + if (!try_aopen) {
19967 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19968 + if (unlikely(err))
19971 + err = au_d_may_add(dentry);
19972 + if (unlikely(err))
19975 + di_write_lock_parent(parent);
19976 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19977 + &a->pin, &a->wr_dir_args);
19978 + err = PTR_ERR(wh_dentry);
19979 + if (IS_ERR(wh_dentry))
19982 + btop = au_dbtop(dentry);
19983 + sb = dentry->d_sb;
19984 + br = au_sbr(sb, btop);
19985 + a->h_path.dentry = au_h_dptr(dentry, btop);
19986 + a->h_path.mnt = au_br_mnt(br);
19987 + h_dir = au_pinned_h_dir(&a->pin);
19988 + switch (arg->type) {
19990 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19991 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19992 + arg->u.c.want_excl);
19994 + if (!err && try_aopen)
19995 + aopen->file->f_mode |= FMODE_CREATED;
19998 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19999 + AuDbg("err %d\n", err);
20000 + AuDbgFile(aopen->file);
20001 + created = err >= 0
20002 + && !!(aopen->file->f_mode & FMODE_CREATED);
20006 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20010 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20017 + if (unlikely(err < 0))
20020 + err = epilog(dir, btop, wh_dentry, dentry);
20022 + goto out_unpin; /* success */
20025 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20026 + /* no delegation since it is just created */
20027 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20030 + AuIOErr("%pd revert failure(%d, %d)\n",
20031 + dentry, err, rerr);
20034 + au_dtime_revert(&a->dt);
20036 + if (try_aopen && h_dir->i_op->atomic_open
20037 + && (aopen->file->f_mode & FMODE_OPENED))
20038 + /* aopen->file is still opened */
20039 + au_lcnt_dec(&aopen->br->br_nfiles);
20042 + au_unpin(&a->pin);
20046 + di_write_unlock(parent);
20048 + if (unlikely(err)) {
20049 + au_update_dbtop(dentry);
20053 + aufs_read_unlock(dentry, AuLock_DW);
20060 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20063 + struct simple_arg arg = {
20070 + return add_simple(dir, dentry, &arg);
20073 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20075 + struct simple_arg arg = {
20077 + .u.s.symname = symname
20079 + return add_simple(dir, dentry, &arg);
20082 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20085 + struct simple_arg arg = {
20089 + .want_excl = want_excl
20092 + return add_simple(dir, dentry, &arg);
20095 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20096 + struct vfsub_aopen_args *aopen_args)
20098 + struct simple_arg arg = {
20101 + .mode = aopen_args->create_mode,
20102 + .want_excl = aopen_args->open_flag & O_EXCL,
20103 + .try_aopen = true,
20104 + .aopen = aopen_args
20107 + return add_simple(dir, dentry, &arg);
20110 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20113 + aufs_bindex_t bindex;
20114 + struct super_block *sb;
20115 + struct dentry *parent, *h_parent, *h_dentry;
20116 + struct inode *h_dir, *inode;
20117 + struct vfsmount *h_mnt;
20118 + struct au_wr_dir_args wr_dir_args = {
20119 + .force_btgt = -1,
20120 + .flags = AuWrDir_TMPFILE
20123 + /* copy-up may happen */
20127 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20128 + if (unlikely(err))
20131 + err = au_di_init(dentry);
20132 + if (unlikely(err))
20136 + parent = d_find_any_alias(dir);
20137 + AuDebugOn(!parent);
20138 + di_write_lock_parent(parent);
20139 + if (unlikely(d_inode(parent) != dir))
20142 + err = au_digen_test(parent, au_sigen(sb));
20143 + if (unlikely(err))
20146 + bindex = au_dbtop(parent);
20147 + au_set_dbtop(dentry, bindex);
20148 + au_set_dbbot(dentry, bindex);
20149 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20151 + if (unlikely(err < 0))
20154 + err = -EOPNOTSUPP;
20155 + h_dir = au_h_iptr(dir, bindex);
20156 + if (unlikely(!h_dir->i_op->tmpfile))
20159 + h_mnt = au_sbr_mnt(sb, bindex);
20160 + err = vfsub_mnt_want_write(h_mnt);
20161 + if (unlikely(err))
20164 + h_parent = au_h_dptr(parent, bindex);
20165 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20166 + if (IS_ERR(h_dentry)) {
20167 + err = PTR_ERR(h_dentry);
20171 + au_set_dbtop(dentry, bindex);
20172 + au_set_dbbot(dentry, bindex);
20173 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20174 + inode = au_new_inode(dentry, /*must_new*/1);
20175 + if (IS_ERR(inode)) {
20176 + err = PTR_ERR(inode);
20177 + au_set_h_dptr(dentry, bindex, NULL);
20178 + au_set_dbtop(dentry, -1);
20179 + au_set_dbbot(dentry, -1);
20181 + if (!inode->i_nlink)
20182 + set_nlink(inode, 1);
20183 + d_tmpfile(dentry, inode);
20184 + au_di(dentry)->di_tmpfile = 1;
20186 + /* update without i_mutex */
20187 + if (au_ibtop(dir) == au_dbtop(dentry))
20188 + au_cpup_attr_timesizes(dir);
20193 + vfsub_mnt_drop_write(h_mnt);
20195 + di_write_unlock(parent);
20197 + di_write_unlock(dentry);
20198 + if (unlikely(err)) {
20199 + au_di_fin(dentry);
20200 + dentry->d_fsdata = NULL;
20203 + si_read_unlock(sb);
20205 + inode_unlock(dir);
20209 +/* ---------------------------------------------------------------------- */
20211 +struct au_link_args {
20212 + aufs_bindex_t bdst, bsrc;
20213 + struct au_pin pin;
20214 + struct path h_path;
20215 + struct dentry *src_parent, *parent;
20218 +static int au_cpup_before_link(struct dentry *src_dentry,
20219 + struct au_link_args *a)
20222 + struct dentry *h_src_dentry;
20223 + struct au_cp_generic cpg = {
20224 + .dentry = src_dentry,
20229 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20232 + di_read_lock_parent(a->src_parent, AuLock_IR);
20233 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20234 + if (unlikely(err))
20237 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20238 + err = au_pin(&a->pin, src_dentry, a->bdst,
20239 + au_opt_udba(src_dentry->d_sb),
20240 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20241 + if (unlikely(err))
20244 + err = au_sio_cpup_simple(&cpg);
20245 + au_unpin(&a->pin);
20248 + di_read_unlock(a->src_parent, AuLock_IR);
20252 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20253 + struct au_link_args *a)
20256 + unsigned char plink;
20257 + aufs_bindex_t bbot;
20258 + struct dentry *h_src_dentry;
20259 + struct inode *h_inode, *inode, *delegated;
20260 + struct super_block *sb;
20261 + struct file *h_file;
20265 + sb = src_dentry->d_sb;
20266 + inode = d_inode(src_dentry);
20267 + if (au_ibtop(inode) <= a->bdst)
20268 + h_inode = au_h_iptr(inode, a->bdst);
20269 + if (!h_inode || !h_inode->i_nlink) {
20270 + /* copyup src_dentry as the name of dentry. */
20271 + bbot = au_dbbot(dentry);
20272 + if (bbot < a->bsrc)
20273 + au_set_dbbot(dentry, a->bsrc);
20274 + au_set_h_dptr(dentry, a->bsrc,
20275 + dget(au_h_dptr(src_dentry, a->bsrc)));
20276 + dget(a->h_path.dentry);
20277 + au_set_h_dptr(dentry, a->bdst, NULL);
20278 + AuDbg("temporary d_inode...\n");
20279 + spin_lock(&dentry->d_lock);
20280 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20281 + spin_unlock(&dentry->d_lock);
20282 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20283 + if (IS_ERR(h_file))
20284 + err = PTR_ERR(h_file);
20286 + struct au_cp_generic cpg = {
20287 + .dentry = dentry,
20292 + .flags = AuCpup_KEEPLINO
20294 + err = au_sio_cpup_simple(&cpg);
20295 + au_h_open_post(dentry, a->bsrc, h_file);
20297 + dput(a->h_path.dentry);
20298 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20300 + au_set_h_dptr(dentry, a->bdst,
20301 + a->h_path.dentry);
20303 + spin_lock(&dentry->d_lock);
20304 + dentry->d_inode = NULL; /* restore */
20305 + spin_unlock(&dentry->d_lock);
20306 + AuDbg("temporary d_inode...done\n");
20307 + au_set_h_dptr(dentry, a->bsrc, NULL);
20308 + au_set_dbbot(dentry, bbot);
20310 + /* the inode of src_dentry already exists on a.bdst branch */
20311 + h_src_dentry = d_find_alias(h_inode);
20312 + if (!h_src_dentry && au_plink_test(inode)) {
20314 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20315 + err = PTR_ERR(h_src_dentry);
20316 + if (IS_ERR(h_src_dentry))
20319 + if (unlikely(d_is_negative(h_src_dentry))) {
20320 + dput(h_src_dentry);
20321 + h_src_dentry = NULL;
20325 + if (h_src_dentry) {
20326 + delegated = NULL;
20327 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20328 + &a->h_path, &delegated);
20329 + if (unlikely(err == -EWOULDBLOCK)) {
20330 + pr_warn("cannot retry for NFSv4 delegation"
20331 + " for an internal link\n");
20334 + dput(h_src_dentry);
20336 + AuIOErr("no dentry found for hi%lu on b%d\n",
20337 + h_inode->i_ino, a->bdst);
20342 + if (!err && !plink)
20343 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20350 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20351 + struct dentry *dentry)
20354 + struct au_dtime dt;
20355 + struct au_link_args *a;
20356 + struct dentry *wh_dentry, *h_src_dentry;
20357 + struct inode *inode, *delegated;
20358 + struct super_block *sb;
20359 + struct au_wr_dir_args wr_dir_args = {
20360 + /* .force_btgt = -1, */
20361 + .flags = AuWrDir_ADD_ENTRY
20365 + inode = d_inode(src_dentry);
20366 + IMustLock(inode);
20369 + a = kzalloc(sizeof(*a), GFP_NOFS);
20370 + if (unlikely(!a))
20373 + a->parent = dentry->d_parent; /* dir inode is locked */
20374 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20375 + AuLock_NOPLM | AuLock_GEN);
20376 + if (unlikely(err))
20378 + err = au_d_linkable(src_dentry);
20379 + if (unlikely(err))
20381 + err = au_d_may_add(dentry);
20382 + if (unlikely(err))
20385 + a->src_parent = dget_parent(src_dentry);
20386 + wr_dir_args.force_btgt = au_ibtop(inode);
20388 + di_write_lock_parent(a->parent);
20389 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20390 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20392 + err = PTR_ERR(wh_dentry);
20393 + if (IS_ERR(wh_dentry))
20397 + sb = dentry->d_sb;
20398 + a->bdst = au_dbtop(dentry);
20399 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20400 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20401 + a->bsrc = au_ibtop(inode);
20402 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20403 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20404 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20405 + if (!h_src_dentry) {
20406 + a->bsrc = au_dbtop(src_dentry);
20407 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20408 + AuDebugOn(!h_src_dentry);
20409 + } else if (IS_ERR(h_src_dentry)) {
20410 + err = PTR_ERR(h_src_dentry);
20415 + * aufs doesn't touch the credential so
20416 + * security_dentry_create_files_as() is unnecessary.
20418 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20419 + if (a->bdst < a->bsrc
20420 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20421 + err = au_cpup_or_link(src_dentry, dentry, a);
20423 + delegated = NULL;
20424 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20425 + &a->h_path, &delegated);
20426 + if (unlikely(err == -EWOULDBLOCK)) {
20427 + pr_warn("cannot retry for NFSv4 delegation"
20428 + " for an internal link\n");
20432 + dput(h_src_dentry);
20435 + * copyup src_dentry to the branch we process,
20436 + * and then link(2) to it.
20438 + dput(h_src_dentry);
20439 + if (a->bdst < a->bsrc
20440 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20441 + au_unpin(&a->pin);
20442 + di_write_unlock(a->parent);
20443 + err = au_cpup_before_link(src_dentry, a);
20444 + di_write_lock_parent(a->parent);
20446 + err = au_pin(&a->pin, dentry, a->bdst,
20448 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20449 + if (unlikely(err))
20453 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20455 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20456 + delegated = NULL;
20457 + err = vfsub_link(h_src_dentry,
20458 + au_pinned_h_dir(&a->pin),
20459 + &a->h_path, &delegated);
20460 + if (unlikely(err == -EWOULDBLOCK)) {
20461 + pr_warn("cannot retry"
20462 + " for NFSv4 delegation"
20463 + " for an internal link\n");
20469 + if (unlikely(err))
20473 + a->h_path.dentry = wh_dentry;
20474 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20476 + if (unlikely(err))
20480 + au_dir_ts(dir, a->bdst);
20481 + inode_inc_iversion(dir);
20482 + inc_nlink(inode);
20483 + inode->i_ctime = dir->i_ctime;
20484 + d_instantiate(dentry, au_igrab(inode));
20485 + if (d_unhashed(a->h_path.dentry))
20486 + /* some filesystem calls d_drop() */
20488 + /* some filesystems consume an inode even hardlink */
20489 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20490 + goto out_unpin; /* success */
20493 + /* no delegation since it is just created */
20494 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20495 + /*delegated*/NULL, /*force*/0);
20496 + if (unlikely(rerr)) {
20497 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20500 + au_dtime_revert(&dt);
20502 + au_unpin(&a->pin);
20506 + di_write_unlock(a->parent);
20507 + dput(a->src_parent);
20509 + if (unlikely(err)) {
20510 + au_update_dbtop(dentry);
20513 + aufs_read_and_write_unlock2(dentry, src_dentry);
20521 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20524 + aufs_bindex_t bindex;
20525 + unsigned char diropq;
20526 + struct path h_path;
20527 + struct dentry *wh_dentry, *parent, *opq_dentry;
20528 + struct inode *h_inode;
20529 + struct super_block *sb;
20531 + struct au_pin pin;
20532 + struct au_dtime dt;
20533 + } *a; /* reduce the stack usage */
20534 + struct au_wr_dir_args wr_dir_args = {
20535 + .force_btgt = -1,
20536 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20542 + a = kmalloc(sizeof(*a), GFP_NOFS);
20543 + if (unlikely(!a))
20546 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20547 + if (unlikely(err))
20549 + err = au_d_may_add(dentry);
20550 + if (unlikely(err))
20553 + parent = dentry->d_parent; /* dir inode is locked */
20554 + di_write_lock_parent(parent);
20555 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20556 + &a->pin, &wr_dir_args);
20557 + err = PTR_ERR(wh_dentry);
20558 + if (IS_ERR(wh_dentry))
20561 + sb = dentry->d_sb;
20562 + bindex = au_dbtop(dentry);
20563 + h_path.dentry = au_h_dptr(dentry, bindex);
20564 + h_path.mnt = au_sbr_mnt(sb, bindex);
20565 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20566 + if (unlikely(err))
20569 + /* make the dir opaque */
20571 + h_inode = d_inode(h_path.dentry);
20573 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20574 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20575 + opq_dentry = au_diropq_create(dentry, bindex);
20576 + inode_unlock(h_inode);
20577 + err = PTR_ERR(opq_dentry);
20578 + if (IS_ERR(opq_dentry))
20580 + dput(opq_dentry);
20584 + err = epilog(dir, bindex, wh_dentry, dentry);
20587 + goto out_unpin; /* success */
20592 + AuLabel(revert opq);
20593 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20594 + rerr = au_diropq_remove(dentry, bindex);
20595 + inode_unlock(h_inode);
20597 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20598 + dentry, err, rerr);
20604 + AuLabel(revert dir);
20605 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20607 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20608 + dentry, err, rerr);
20611 + au_dtime_revert(&a->dt);
20613 + au_unpin(&a->pin);
20616 + di_write_unlock(parent);
20618 + if (unlikely(err)) {
20619 + au_update_dbtop(dentry);
20622 + aufs_read_unlock(dentry, AuLock_DW);
20628 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20629 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 08:00:00.000000000 +0800
20630 +++ linux/fs/aufs/i_op.c 2019-07-11 21:21:54.379051070 +0800
20632 +// SPDX-License-Identifier: GPL-2.0
20634 + * Copyright (C) 2005-2019 Junjiro R. Okajima
20636 + * This program, aufs is free software; you can redistribute it and/or modify
20637 + * it under the terms of the GNU General Public License as published by
20638 + * the Free Software Foundation; either version 2 of the License, or
20639 + * (at your option) any later version.
20641 + * This program is distributed in the hope that it will be useful,
20642 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20643 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20644 + * GNU General Public License for more details.
20646 + * You should have received a copy of the GNU General Public License
20647 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20651 + * inode operations (except add/del/rename)
20654 +#include <linux/device_cgroup.h>
20655 +#include <linux/fs_stack.h>
20656 +#include <linux/iversion.h>
20657 +#include <linux/namei.h>
20658 +#include <linux/security.h>
20661 +static int h_permission(struct inode *h_inode, int mask,
20662 + struct path *h_path, int brperm)
20665 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20668 + if (write_mask && IS_IMMUTABLE(h_inode))
20672 + if (((mask & MAY_EXEC)
20673 + && S_ISREG(h_inode->i_mode)
20674 + && (path_noexec(h_path)
20675 + || !(h_inode->i_mode & 0111))))
20679 + * - skip the lower fs test in the case of write to ro branch.
20680 + * - nfs dir permission write check is optimized, but a policy for
20681 + * link/rename requires a real check.
20682 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20683 + * in this case, generic_permission() returns -EOPNOTSUPP.
20685 + if ((write_mask && !au_br_writable(brperm))
20686 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20687 + && write_mask && !(mask & MAY_READ))
20688 + || !h_inode->i_op->permission) {
20689 + /* AuLabel(generic_permission); */
20690 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20691 + err = generic_permission(h_inode, mask);
20692 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20693 + err = h_inode->i_op->permission(h_inode, mask);
20696 + /* AuLabel(h_inode->permission); */
20697 + err = h_inode->i_op->permission(h_inode, mask);
20702 + err = devcgroup_inode_permission(h_inode, mask);
20704 + err = security_inode_permission(h_inode, mask);
20708 + /* todo: do we need to call ima_path_check()? */
20709 + struct path h_path = {
20713 + err = ima_path_check(&h_path,
20714 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
20715 + IMA_COUNT_LEAVE);
20723 +static int aufs_permission(struct inode *inode, int mask)
20726 + aufs_bindex_t bindex, bbot;
20727 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20728 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20729 + struct inode *h_inode;
20730 + struct super_block *sb;
20731 + struct au_branch *br;
20733 + /* todo: support rcu-walk? */
20734 + if (mask & MAY_NOT_BLOCK)
20737 + sb = inode->i_sb;
20738 + si_read_lock(sb, AuLock_FLUSH);
20739 + ii_read_lock_child(inode);
20741 + err = au_iigen_test(inode, au_sigen(sb));
20742 + if (unlikely(err))
20748 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20749 + err = au_busy_or_stale();
20750 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20751 + if (unlikely(!h_inode
20752 + || (h_inode->i_mode & S_IFMT)
20753 + != (inode->i_mode & S_IFMT)))
20757 + bindex = au_ibtop(inode);
20758 + br = au_sbr(sb, bindex);
20759 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20762 + && !special_file(h_inode->i_mode)) {
20763 + /* test whether the upper writable branch exists */
20765 + for (; bindex >= 0; bindex--)
20766 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20774 + /* non-write to dir */
20776 + bbot = au_ibbot(inode);
20777 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20778 + h_inode = au_h_iptr(inode, bindex);
20780 + err = au_busy_or_stale();
20781 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20784 + br = au_sbr(sb, bindex);
20785 + err = h_permission(h_inode, mask, &br->br_path,
20791 + ii_read_unlock(inode);
20792 + si_read_unlock(sb);
20796 +/* ---------------------------------------------------------------------- */
20798 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20799 + unsigned int flags)
20801 + struct dentry *ret, *parent;
20802 + struct inode *inode;
20803 + struct super_block *sb;
20804 + int err, npositive;
20808 + /* todo: support rcu-walk? */
20809 + ret = ERR_PTR(-ECHILD);
20810 + if (flags & LOOKUP_RCU)
20813 + ret = ERR_PTR(-ENAMETOOLONG);
20814 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20818 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20819 + ret = ERR_PTR(err);
20820 + if (unlikely(err))
20823 + err = au_di_init(dentry);
20824 + ret = ERR_PTR(err);
20825 + if (unlikely(err))
20829 + npositive = 0; /* suppress a warning */
20830 + parent = dentry->d_parent; /* dir inode is locked */
20831 + di_read_lock_parent(parent, AuLock_IR);
20832 + err = au_alive_dir(parent);
20834 + err = au_digen_test(parent, au_sigen(sb));
20836 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20837 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20838 + AuLkup_ALLOW_NEG);
20841 + di_read_unlock(parent, AuLock_IR);
20842 + ret = ERR_PTR(err);
20843 + if (unlikely(err < 0))
20847 + inode = au_new_inode(dentry, /*must_new*/0);
20848 + if (IS_ERR(inode)) {
20849 + ret = (void *)inode;
20856 + atomic_inc(&inode->i_count);
20857 + ret = d_splice_alias(inode, dentry);
20859 + if (unlikely(d_need_lookup(dentry))) {
20860 + spin_lock(&dentry->d_lock);
20861 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20862 + spin_unlock(&dentry->d_lock);
20866 + if (!IS_ERR(ret)) {
20868 + if (ret && ret != dentry)
20869 + ii_write_unlock(inode);
20871 + ii_write_unlock(inode);
20878 + di_write_unlock(dentry);
20880 + si_read_unlock(sb);
20885 +/* ---------------------------------------------------------------------- */
20888 + * very dirty and complicated aufs ->atomic_open().
20889 + * aufs_atomic_open()
20890 + * + au_aopen_or_create()
20892 + * + vfsub_atomic_open()
20893 + * + branch fs ->atomic_open()
20894 + * may call the actual 'open' for h_file
20895 + * + inc br_nfiles only if opened
20896 + * + au_aopen_no_open() or au_aopen_do_open()
20898 + * au_aopen_do_open()
20899 + * + finish_open()
20900 + * + au_do_aopen()
20901 + * + au_do_open() the body of all 'open'
20902 + * + au_do_open_nondir()
20903 + * set the passed h_file
20905 + * au_aopen_no_open()
20906 + * + finish_no_open()
20909 +struct aopen_node {
20910 + struct hlist_bl_node hblist;
20911 + struct file *file, *h_file;
20914 +static int au_do_aopen(struct inode *inode, struct file *file)
20916 + struct hlist_bl_head *aopen;
20917 + struct hlist_bl_node *pos;
20918 + struct aopen_node *node;
20919 + struct au_do_open_args args = {
20921 + .open = au_do_open_nondir
20924 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20925 + hlist_bl_lock(aopen);
20926 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20927 + if (node->file == file) {
20928 + args.h_file = node->h_file;
20931 + hlist_bl_unlock(aopen);
20932 + /* AuDebugOn(!args.h_file); */
20934 + return au_do_open(file, &args);
20937 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20938 + struct aopen_node *aopen_node)
20941 + struct hlist_bl_head *aopen;
20944 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20945 + au_hbl_add(&aopen_node->hblist, aopen);
20946 + err = finish_open(file, dentry, au_do_aopen);
20947 + au_hbl_del(&aopen_node->hblist, aopen);
20948 + /* AuDbgFile(file); */
20949 + AuDbg("%pd%s%s\n", dentry,
20950 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20951 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20957 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20963 + err = finish_no_open(file, dentry);
20969 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20970 + struct file *file, unsigned int open_flag,
20971 + umode_t create_mode)
20973 + int err, did_open;
20974 + unsigned int lkup_flags;
20975 + aufs_bindex_t bindex;
20976 + struct super_block *sb;
20977 + struct dentry *parent, *d;
20978 + struct vfsub_aopen_args args = {
20979 + .open_flag = open_flag,
20980 + .create_mode = create_mode
20982 + struct aopen_node aopen_node = {
20987 + AuDbg("open_flag 0%o\n", open_flag);
20988 + AuDbgDentry(dentry);
20991 + if (!au_di(dentry)) {
20992 + lkup_flags = LOOKUP_OPEN;
20993 + if (open_flag & O_CREAT)
20994 + lkup_flags |= LOOKUP_CREATE;
20995 + d = aufs_lookup(dir, dentry, lkup_flags);
20997 + err = PTR_ERR(d);
21002 + * obsoleted dentry found.
21003 + * another error will be returned later.
21009 + AuDbgDentry(dentry);
21012 + if (d_is_positive(dentry)
21013 + || d_unhashed(dentry)
21014 + || d_unlinked(dentry)
21015 + || !(open_flag & O_CREAT)) {
21016 + err = au_aopen_no_open(file, dentry);
21017 + goto out; /* success */
21020 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21021 + if (unlikely(err))
21024 + sb = dentry->d_sb;
21025 + parent = dentry->d_parent; /* dir is locked */
21026 + di_write_lock_parent(parent);
21027 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21028 + if (unlikely(err < 0))
21031 + AuDbgDentry(dentry);
21032 + if (d_is_positive(dentry)) {
21033 + err = au_aopen_no_open(file, dentry);
21034 + goto out_parent; /* success */
21037 + args.file = alloc_empty_file(file->f_flags, current_cred());
21038 + err = PTR_ERR(args.file);
21039 + if (IS_ERR(args.file))
21042 + bindex = au_dbtop(dentry);
21043 + err = au_aopen_or_create(dir, dentry, &args);
21045 + AuDbgFile(args.file);
21046 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21047 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21050 + args.file = NULL;
21052 + di_write_unlock(parent);
21053 + di_write_unlock(dentry);
21054 + if (unlikely(err < 0)) {
21061 + err = au_aopen_no_open(file, dentry);
21063 + aopen_node.h_file = args.file;
21064 + err = au_aopen_do_open(file, dentry, &aopen_node);
21066 + if (unlikely(err < 0)) {
21070 + au_lcnt_dec(&args.br->br_nfiles);
21072 + goto out_sb; /* success */
21075 + di_write_unlock(parent);
21076 + di_write_unlock(dentry);
21078 + si_read_unlock(sb);
21086 +/* ---------------------------------------------------------------------- */
21088 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21089 + const unsigned char add_entry, aufs_bindex_t bcpup,
21090 + aufs_bindex_t btop)
21093 + struct dentry *h_parent;
21094 + struct inode *h_dir;
21097 + IMustLock(d_inode(parent));
21099 + di_write_lock_parent(parent);
21102 + if (!au_h_dptr(parent, bcpup)) {
21103 + if (btop > bcpup)
21104 + err = au_cpup_dirs(dentry, bcpup);
21105 + else if (btop < bcpup)
21106 + err = au_cpdown_dirs(dentry, bcpup);
21110 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21111 + h_parent = au_h_dptr(parent, bcpup);
21112 + h_dir = d_inode(h_parent);
21113 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21114 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21115 + /* todo: no unlock here */
21116 + inode_unlock_shared(h_dir);
21118 + AuDbg("bcpup %d\n", bcpup);
21120 + if (d_really_is_negative(dentry))
21121 + au_set_h_dptr(dentry, btop, NULL);
21122 + au_update_dbrange(dentry, /*do_put_zero*/0);
21127 + di_write_unlock(parent);
21129 + err = bcpup; /* success */
21136 + * decide the branch and the parent dir where we will create a new entry.
21137 + * returns new bindex or an error.
21138 + * copyup the parent dir if needed.
21140 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21141 + struct au_wr_dir_args *args)
21144 + unsigned int flags;
21145 + aufs_bindex_t bcpup, btop, src_btop;
21146 + const unsigned char add_entry
21147 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21148 + | au_ftest_wrdir(args->flags, TMPFILE);
21149 + struct super_block *sb;
21150 + struct dentry *parent;
21151 + struct au_sbinfo *sbinfo;
21153 + sb = dentry->d_sb;
21154 + sbinfo = au_sbi(sb);
21155 + parent = dget_parent(dentry);
21156 + btop = au_dbtop(dentry);
21158 + if (args->force_btgt < 0) {
21159 + if (src_dentry) {
21160 + src_btop = au_dbtop(src_dentry);
21161 + if (src_btop < btop)
21162 + bcpup = src_btop;
21163 + } else if (add_entry) {
21165 + if (au_ftest_wrdir(args->flags, ISDIR))
21166 + au_fset_wbr(flags, DIR);
21167 + err = AuWbrCreate(sbinfo, dentry, flags);
21171 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21173 + err = AuWbrCopyup(sbinfo, dentry);
21175 + if (!IS_ROOT(dentry)) {
21176 + di_read_lock_parent(parent, !AuLock_IR);
21177 + err = AuWbrCopyup(sbinfo, dentry);
21178 + di_read_unlock(parent, !AuLock_IR);
21180 + err = AuWbrCopyup(sbinfo, dentry);
21183 + if (unlikely(err < 0))
21187 + bcpup = args->force_btgt;
21188 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21191 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21193 + if (bcpup == btop)
21194 + goto out; /* success */
21196 + /* copyup the new parent into the branch we process */
21197 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21199 + if (d_really_is_negative(dentry)) {
21200 + au_set_h_dptr(dentry, btop, NULL);
21201 + au_set_dbtop(dentry, bcpup);
21202 + au_set_dbbot(dentry, bcpup);
21204 + AuDebugOn(add_entry
21205 + && !au_ftest_wrdir(args->flags, TMPFILE)
21206 + && !au_h_dptr(dentry, bcpup));
21214 +/* ---------------------------------------------------------------------- */
21216 +void au_pin_hdir_unlock(struct au_pin *p)
21219 + au_hn_inode_unlock(p->hdir);
21222 +int au_pin_hdir_lock(struct au_pin *p)
21230 + /* even if an error happens later, keep this lock */
21231 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21234 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21239 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21240 + p->h_parent, p->br);
21246 +int au_pin_hdir_relock(struct au_pin *p)
21249 + struct inode *h_i;
21250 + struct dentry *h_d[] = {
21255 + err = au_pin_hdir_lock(p);
21256 + if (unlikely(err))
21259 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21262 + if (d_is_positive(h_d[i])) {
21263 + h_i = d_inode(h_d[i]);
21264 + err = !h_i->i_nlink;
21272 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21274 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21275 + p->hdir->hi_inode->i_rwsem.owner = task;
21279 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21282 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21283 + p->lsc_hi, 0, NULL, _RET_IP_);
21284 + au_pin_hdir_set_owner(p, current);
21288 +void au_pin_hdir_release(struct au_pin *p)
21291 + au_pin_hdir_set_owner(p, p->task);
21292 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21296 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21298 + if (pin && pin->parent)
21299 + return au_h_dptr(pin->parent, pin->bindex);
21303 +void au_unpin(struct au_pin *p)
21306 + au_pin_hdir_unlock(p);
21307 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21308 + vfsub_mnt_drop_write(p->h_mnt);
21312 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21313 + di_read_unlock(p->parent, AuLock_IR);
21314 + iput(p->hdir->hi_inode);
21316 + p->parent = NULL;
21319 + /* do not clear p->task */
21322 +int au_do_pin(struct au_pin *p)
21325 + struct super_block *sb;
21326 + struct inode *h_dir;
21329 + sb = p->dentry->d_sb;
21330 + p->br = au_sbr(sb, p->bindex);
21331 + if (IS_ROOT(p->dentry)) {
21332 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21333 + p->h_mnt = au_br_mnt(p->br);
21334 + err = vfsub_mnt_want_write(p->h_mnt);
21335 + if (unlikely(err)) {
21336 + au_fclr_pin(p->flags, MNT_WRITE);
21343 + p->h_dentry = NULL;
21344 + if (p->bindex <= au_dbbot(p->dentry))
21345 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21347 + p->parent = dget_parent(p->dentry);
21348 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21349 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21352 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21353 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21355 + h_dir = p->hdir->hi_inode;
21359 + * if DI_LOCKED is not set, then p->parent may be different
21360 + * and h_parent can be NULL.
21362 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21364 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21365 + di_read_unlock(p->parent, AuLock_IR);
21367 + p->parent = NULL;
21371 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21372 + p->h_mnt = au_br_mnt(p->br);
21373 + err = vfsub_mnt_want_write(p->h_mnt);
21374 + if (unlikely(err)) {
21375 + au_fclr_pin(p->flags, MNT_WRITE);
21376 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21377 + di_read_unlock(p->parent, AuLock_IR);
21379 + p->parent = NULL;
21385 + err = au_pin_hdir_lock(p);
21387 + goto out; /* success */
21392 + pr_err("err %d\n", err);
21393 + err = au_busy_or_stale();
21398 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21399 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21400 + unsigned int udba, unsigned char flags)
21402 + p->dentry = dentry;
21404 + p->lsc_di = lsc_di;
21405 + p->lsc_hi = lsc_hi;
21406 + p->flags = flags;
21407 + p->bindex = bindex;
21409 + p->parent = NULL;
21413 + p->h_dentry = NULL;
21414 + p->h_parent = NULL;
21416 + p->task = current;
21419 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21420 + unsigned int udba, unsigned char flags)
21422 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21424 + return au_do_pin(pin);
21427 +/* ---------------------------------------------------------------------- */
21430 + * ->setattr() and ->getattr() are called in various cases.
21431 + * chmod, stat: dentry is revalidated.
21432 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21434 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21436 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21437 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21440 + struct dentry *parent;
21443 + if (au_digen_test(dentry, sigen)) {
21444 + parent = dget_parent(dentry);
21445 + di_read_lock_parent(parent, AuLock_IR);
21446 + err = au_refresh_dentry(dentry, parent);
21447 + di_read_unlock(parent, AuLock_IR);
21455 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21456 + struct au_icpup_args *a)
21460 + aufs_bindex_t btop, ibtop;
21461 + struct dentry *hi_wh, *parent;
21462 + struct inode *inode;
21463 + struct au_wr_dir_args wr_dir_args = {
21464 + .force_btgt = -1,
21468 + if (d_is_dir(dentry))
21469 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21470 + /* plink or hi_wh() case */
21471 + btop = au_dbtop(dentry);
21472 + inode = d_inode(dentry);
21473 + ibtop = au_ibtop(inode);
21474 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21475 + wr_dir_args.force_btgt = ibtop;
21476 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21477 + if (unlikely(err < 0))
21481 + au_fset_icpup(a->flags, DID_CPUP);
21484 + a->pin_flags = AuPin_MNT_WRITE;
21486 + if (!IS_ROOT(dentry)) {
21487 + au_fset_pin(a->pin_flags, DI_LOCKED);
21488 + parent = dget_parent(dentry);
21489 + di_write_lock_parent(parent);
21492 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21493 + if (unlikely(err))
21497 + a->h_path.dentry = au_h_dptr(dentry, btop);
21498 + a->h_inode = d_inode(a->h_path.dentry);
21499 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21500 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21501 + if (ia->ia_size < i_size_read(a->h_inode))
21502 + sz = ia->ia_size;
21503 + inode_unlock_shared(a->h_inode);
21507 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21508 + hi_wh = au_hi_wh(inode, a->btgt);
21510 + struct au_cp_generic cpg = {
21511 + .dentry = dentry,
21517 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21518 + if (unlikely(err))
21520 + hi_wh = au_hi_wh(inode, a->btgt);
21521 + /* todo: revalidate hi_wh? */
21526 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21527 + di_downgrade_lock(parent, AuLock_IR);
21531 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21532 + goto out; /* success */
21534 + if (!d_unhashed(dentry)) {
21535 + struct au_cp_generic cpg = {
21536 + .dentry = dentry,
21541 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21543 + err = au_sio_cpup_simple(&cpg);
21545 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21546 + } else if (!hi_wh)
21547 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21549 + a->h_path.dentry = hi_wh; /* do not dget here */
21552 + a->h_inode = d_inode(a->h_path.dentry);
21554 + goto out; /* success */
21555 + au_unpin(&a->pin);
21558 + di_write_unlock(parent);
21563 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21567 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21570 + struct inode *inode, *delegated;
21571 + struct super_block *sb;
21572 + struct file *file;
21573 + struct au_icpup_args *a;
21575 + inode = d_inode(dentry);
21576 + IMustLock(inode);
21578 + err = setattr_prepare(dentry, ia);
21579 + if (unlikely(err))
21583 + a = kzalloc(sizeof(*a), GFP_NOFS);
21584 + if (unlikely(!a))
21587 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21588 + ia->ia_valid &= ~ATTR_MODE;
21591 + sb = dentry->d_sb;
21592 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21593 + if (unlikely(err))
21596 + if (ia->ia_valid & ATTR_FILE) {
21597 + /* currently ftruncate(2) only */
21598 + AuDebugOn(!d_is_reg(dentry));
21599 + file = ia->ia_file;
21600 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21602 + if (unlikely(err))
21604 + ia->ia_file = au_hf_top(file);
21605 + a->udba = AuOpt_UDBA_NONE;
21607 + /* fchmod() doesn't pass ia_file */
21608 + a->udba = au_opt_udba(sb);
21609 + di_write_lock_child(dentry);
21610 + /* no d_unlinked(), to set UDBA_NONE for root */
21611 + if (d_unhashed(dentry))
21612 + a->udba = AuOpt_UDBA_NONE;
21613 + if (a->udba != AuOpt_UDBA_NONE) {
21614 + AuDebugOn(IS_ROOT(dentry));
21615 + err = au_reval_for_attr(dentry, au_sigen(sb));
21616 + if (unlikely(err))
21621 + err = au_pin_and_icpup(dentry, ia, a);
21622 + if (unlikely(err < 0))
21624 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21625 + ia->ia_file = NULL;
21626 + ia->ia_valid &= ~ATTR_FILE;
21629 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21630 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21631 + == (ATTR_MODE | ATTR_CTIME)) {
21632 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21633 + if (unlikely(err))
21635 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21636 + && (ia->ia_valid & ATTR_CTIME)) {
21637 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21638 + if (unlikely(err))
21642 + if (ia->ia_valid & ATTR_SIZE) {
21645 + if (ia->ia_size < i_size_read(inode))
21647 + truncate_setsize(inode, ia->ia_size);
21650 + if (ia->ia_valid & ATTR_FILE)
21652 + inode_unlock(a->h_inode);
21653 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21654 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21656 + delegated = NULL;
21658 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21660 + err = break_deleg_wait(&delegated);
21668 + * regardless aufs 'acl' option setting.
21669 + * why don't all acl-aware fs call this func from their ->setattr()?
21671 + if (!err && (ia->ia_valid & ATTR_MODE))
21672 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21674 + au_cpup_attr_changeable(inode);
21677 + inode_unlock(a->h_inode);
21678 + au_unpin(&a->pin);
21679 + if (unlikely(err))
21680 + au_update_dbtop(dentry);
21682 + di_write_unlock(dentry);
21684 + fi_write_unlock(file);
21685 + ia->ia_file = file;
21686 + ia->ia_valid |= ATTR_FILE;
21689 + si_read_unlock(sb);
21697 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21698 +static int au_h_path_to_set_attr(struct dentry *dentry,
21699 + struct au_icpup_args *a, struct path *h_path)
21702 + struct super_block *sb;
21704 + sb = dentry->d_sb;
21705 + a->udba = au_opt_udba(sb);
21706 + /* no d_unlinked(), to set UDBA_NONE for root */
21707 + if (d_unhashed(dentry))
21708 + a->udba = AuOpt_UDBA_NONE;
21709 + if (a->udba != AuOpt_UDBA_NONE) {
21710 + AuDebugOn(IS_ROOT(dentry));
21711 + err = au_reval_for_attr(dentry, au_sigen(sb));
21712 + if (unlikely(err))
21715 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21716 + if (unlikely(err < 0))
21719 + h_path->dentry = a->h_path.dentry;
21720 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21726 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21727 + struct au_sxattr *arg)
21730 + struct path h_path;
21731 + struct super_block *sb;
21732 + struct au_icpup_args *a;
21733 + struct inode *h_inode;
21735 + IMustLock(inode);
21738 + a = kzalloc(sizeof(*a), GFP_NOFS);
21739 + if (unlikely(!a))
21742 + sb = dentry->d_sb;
21743 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21744 + if (unlikely(err))
21747 + h_path.dentry = NULL; /* silence gcc */
21748 + di_write_lock_child(dentry);
21749 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21750 + if (unlikely(err))
21753 + inode_unlock(a->h_inode);
21754 + switch (arg->type) {
21755 + case AU_XATTR_SET:
21756 + AuDebugOn(d_is_negative(h_path.dentry));
21757 + err = vfsub_setxattr(h_path.dentry,
21758 + arg->u.set.name, arg->u.set.value,
21759 + arg->u.set.size, arg->u.set.flags);
21762 + err = -EOPNOTSUPP;
21763 + h_inode = d_inode(h_path.dentry);
21764 + if (h_inode->i_op->set_acl)
21765 + /* this will call posix_acl_update_mode */
21766 + err = h_inode->i_op->set_acl(h_inode,
21767 + arg->u.acl_set.acl,
21768 + arg->u.acl_set.type);
21772 + au_cpup_attr_timesizes(inode);
21774 + au_unpin(&a->pin);
21775 + if (unlikely(err))
21776 + au_update_dbtop(dentry);
21779 + di_write_unlock(dentry);
21780 + si_read_unlock(sb);
21789 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21790 + unsigned int nlink)
21794 + inode->i_mode = st->mode;
21795 + /* don't i_[ug]id_write() here */
21796 + inode->i_uid = st->uid;
21797 + inode->i_gid = st->gid;
21798 + inode->i_atime = st->atime;
21799 + inode->i_mtime = st->mtime;
21800 + inode->i_ctime = st->ctime;
21802 + au_cpup_attr_nlink(inode, /*force*/0);
21803 + if (S_ISDIR(inode->i_mode)) {
21804 + n = inode->i_nlink;
21807 + smp_mb(); /* for i_nlink */
21808 + /* 0 can happen */
21809 + set_nlink(inode, n);
21812 + spin_lock(&inode->i_lock);
21813 + inode->i_blocks = st->blocks;
21814 + i_size_write(inode, st->size);
21815 + spin_unlock(&inode->i_lock);
21819 + * common routine for aufs_getattr() and au_getxattr().
21820 + * returns zero or negative (an error).
21821 + * @dentry will be read-locked in success.
21823 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path,
21827 + unsigned int mnt_flags, sigen;
21828 + unsigned char udba_none;
21829 + aufs_bindex_t bindex;
21830 + struct super_block *sb, *h_sb;
21831 + struct inode *inode;
21833 + h_path->mnt = NULL;
21834 + h_path->dentry = NULL;
21837 + sb = dentry->d_sb;
21838 + mnt_flags = au_mntflags(sb);
21839 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21841 + if (unlikely(locked))
21842 + goto body; /* skip locking dinfo */
21844 + /* support fstat(2) */
21845 + if (!d_unlinked(dentry) && !udba_none) {
21846 + sigen = au_sigen(sb);
21847 + err = au_digen_test(dentry, sigen);
21849 + di_read_lock_child(dentry, AuLock_IR);
21850 + err = au_dbrange_test(dentry);
21851 + if (unlikely(err)) {
21852 + di_read_unlock(dentry, AuLock_IR);
21856 + AuDebugOn(IS_ROOT(dentry));
21857 + di_write_lock_child(dentry);
21858 + err = au_dbrange_test(dentry);
21860 + err = au_reval_for_attr(dentry, sigen);
21862 + di_downgrade_lock(dentry, AuLock_IR);
21864 + di_write_unlock(dentry);
21869 + di_read_lock_child(dentry, AuLock_IR);
21872 + inode = d_inode(dentry);
21873 + bindex = au_ibtop(inode);
21874 + h_path->mnt = au_sbr_mnt(sb, bindex);
21875 + h_sb = h_path->mnt->mnt_sb;
21877 + && !au_test_fs_bad_iattr(h_sb)
21879 + goto out; /* success */
21881 + if (au_dbtop(dentry) == bindex)
21882 + h_path->dentry = au_h_dptr(dentry, bindex);
21883 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21884 + h_path->dentry = au_plink_lkup(inode, bindex);
21885 + if (IS_ERR(h_path->dentry))
21886 + /* pretending success */
21887 + h_path->dentry = NULL;
21889 + dput(h_path->dentry);
21896 +static int aufs_getattr(const struct path *path, struct kstat *st,
21897 + u32 request, unsigned int query)
21900 + unsigned char positive;
21901 + struct path h_path;
21902 + struct dentry *dentry;
21903 + struct inode *inode;
21904 + struct super_block *sb;
21906 + dentry = path->dentry;
21907 + inode = d_inode(dentry);
21908 + sb = dentry->d_sb;
21909 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21910 + if (unlikely(err))
21912 + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0);
21913 + if (unlikely(err))
21915 + if (unlikely(!h_path.dentry))
21916 + /* illegally overlapped or something */
21917 + goto out_fill; /* pretending success */
21919 + positive = d_is_positive(h_path.dentry);
21921 + /* no vfsub version */
21922 + err = vfs_getattr(&h_path, st, request, query);
21925 + au_refresh_iattr(inode, st,
21926 + d_inode(h_path.dentry)->i_nlink);
21927 + goto out_fill; /* success */
21933 + generic_fillattr(inode, st);
21935 + di_read_unlock(dentry, AuLock_IR);
21937 + si_read_unlock(sb);
21943 +/* ---------------------------------------------------------------------- */
21945 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21946 + struct delayed_call *done)
21949 + struct dentry *h_dentry;
21950 + struct inode *h_inode;
21952 + aufs_bindex_t bindex;
21954 + ret = NULL; /* suppress a warning */
21959 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21960 + if (unlikely(err))
21963 + err = au_d_hashed_positive(dentry);
21964 + if (unlikely(err))
21968 + inode = d_inode(dentry);
21969 + bindex = au_ibtop(inode);
21970 + h_inode = au_h_iptr(inode, bindex);
21971 + if (unlikely(!h_inode->i_op->get_link))
21976 + if (au_dbtop(dentry) <= bindex) {
21977 + h_dentry = au_h_dptr(dentry, bindex);
21982 + h_dentry = d_find_any_alias(h_inode);
21983 + if (IS_ERR(h_dentry)) {
21984 + err = PTR_ERR(h_dentry);
21988 + if (unlikely(!h_dentry))
21992 + AuDbg("%ps\n", h_inode->i_op->get_link);
21993 + AuDbgDentry(h_dentry);
21994 + ret = vfs_get_link(h_dentry, done);
21997 + err = PTR_ERR(ret);
22000 + aufs_read_unlock(dentry, AuLock_IR);
22002 + if (unlikely(err))
22003 + ret = ERR_PTR(err);
22004 + AuTraceErrPtr(ret);
22008 +/* ---------------------------------------------------------------------- */
22010 +static int au_is_special(struct inode *inode)
22012 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
22015 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
22019 + aufs_bindex_t bindex;
22020 + struct super_block *sb;
22021 + struct inode *h_inode;
22022 + struct vfsmount *h_mnt;
22024 + sb = inode->i_sb;
22025 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
22026 + "unexpected s_flags 0x%lx", sb->s_flags);
22028 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
22030 + si_read_lock(sb, AuLock_FLUSH);
22031 + ii_write_lock_child(inode);
22034 + bindex = au_ibtop(inode);
22035 + h_inode = au_h_iptr(inode, bindex);
22036 + if (!au_test_ro(sb, bindex, inode)) {
22037 + h_mnt = au_sbr_mnt(sb, bindex);
22038 + err = vfsub_mnt_want_write(h_mnt);
22040 + err = vfsub_update_time(h_inode, ts, flags);
22041 + vfsub_mnt_drop_write(h_mnt);
22043 + } else if (au_is_special(h_inode)) {
22045 + * Never copy-up here.
22046 + * These special files may already be opened and used for
22047 + * communicating. If we copied it up, then the communication
22048 + * would be corrupted.
22050 + AuWarn1("timestamps for i%lu are ignored "
22051 + "since it is on readonly branch (hi%lu).\n",
22052 + inode->i_ino, h_inode->i_ino);
22053 + } else if (flags & ~S_ATIME) {
22055 + AuIOErr1("unexpected flags 0x%x\n", flags);
22060 + au_cpup_attr_timesizes(inode);
22061 + ii_write_unlock(inode);
22062 + si_read_unlock(sb);
22065 + if (!err && (flags & S_VERSION))
22066 + inode_inc_iversion(inode);
22071 +/* ---------------------------------------------------------------------- */
22073 +/* no getattr version will be set by module.c:aufs_init() */
22074 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
22076 + [AuIop_SYMLINK] = {
22077 + .permission = aufs_permission,
22078 +#ifdef CONFIG_FS_POSIX_ACL
22079 + .get_acl = aufs_get_acl,
22080 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
22083 + .setattr = aufs_setattr,
22084 + .getattr = aufs_getattr,
22086 +#ifdef CONFIG_AUFS_XATTR
22087 + .listxattr = aufs_listxattr,
22090 + .get_link = aufs_get_link,
22092 + /* .update_time = aufs_update_time */
22095 + .create = aufs_create,
22096 + .lookup = aufs_lookup,
22097 + .link = aufs_link,
22098 + .unlink = aufs_unlink,
22099 + .symlink = aufs_symlink,
22100 + .mkdir = aufs_mkdir,
22101 + .rmdir = aufs_rmdir,
22102 + .mknod = aufs_mknod,
22103 + .rename = aufs_rename,
22105 + .permission = aufs_permission,
22106 +#ifdef CONFIG_FS_POSIX_ACL
22107 + .get_acl = aufs_get_acl,
22108 + .set_acl = aufs_set_acl,
22111 + .setattr = aufs_setattr,
22112 + .getattr = aufs_getattr,
22114 +#ifdef CONFIG_AUFS_XATTR
22115 + .listxattr = aufs_listxattr,
22118 + .update_time = aufs_update_time,
22119 + .atomic_open = aufs_atomic_open,
22120 + .tmpfile = aufs_tmpfile
22122 + [AuIop_OTHER] = {
22123 + .permission = aufs_permission,
22124 +#ifdef CONFIG_FS_POSIX_ACL
22125 + .get_acl = aufs_get_acl,
22126 + .set_acl = aufs_set_acl,
22129 + .setattr = aufs_setattr,
22130 + .getattr = aufs_getattr,
22132 +#ifdef CONFIG_AUFS_XATTR
22133 + .listxattr = aufs_listxattr,
22136 + .update_time = aufs_update_time
22139 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
22140 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 08:00:00.000000000 +0800
22141 +++ linux/fs/aufs/i_op_del.c 2019-07-11 21:21:54.382384486 +0800
22143 +// SPDX-License-Identifier: GPL-2.0
22145 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22147 + * This program, aufs is free software; you can redistribute it and/or modify
22148 + * it under the terms of the GNU General Public License as published by
22149 + * the Free Software Foundation; either version 2 of the License, or
22150 + * (at your option) any later version.
22152 + * This program is distributed in the hope that it will be useful,
22153 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22154 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22155 + * GNU General Public License for more details.
22157 + * You should have received a copy of the GNU General Public License
22158 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22162 + * inode operations (del entry)
22165 +#include <linux/iversion.h>
22169 + * decide if a new whiteout for @dentry is necessary or not.
22170 + * when it is necessary, prepare the parent dir for the upper branch whose
22171 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22172 + * be done by caller.
22174 + * 0: wh is unnecessary
22175 + * plus: wh is necessary
22178 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22180 + int need_wh, err;
22181 + aufs_bindex_t btop;
22182 + struct super_block *sb;
22184 + sb = dentry->d_sb;
22185 + btop = au_dbtop(dentry);
22186 + if (*bcpup < 0) {
22188 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22189 + err = AuWbrCopyup(au_sbi(sb), dentry);
22191 + if (unlikely(err < 0))
22195 + AuDebugOn(btop < *bcpup
22196 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22197 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22199 + if (*bcpup != btop) {
22200 + err = au_cpup_dirs(dentry, *bcpup);
22201 + if (unlikely(err))
22205 + struct au_dinfo *dinfo, *tmp;
22207 + need_wh = -ENOMEM;
22208 + dinfo = au_di(dentry);
22209 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22211 + au_di_cp(tmp, dinfo);
22212 + au_di_swap(tmp, dinfo);
22213 + /* returns the number of positive dentries */
22214 + need_wh = au_lkup_dentry(dentry, btop + 1,
22215 + /* AuLkup_IGNORE_PERM */ 0);
22216 + au_di_swap(tmp, dinfo);
22217 + au_rw_write_unlock(&tmp->di_rwsem);
22221 + AuDbg("need_wh %d\n", need_wh);
22229 + * simple tests for the del-entry operations.
22230 + * following the checks in vfs, plus the parent-child relationship.
22232 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22233 + struct dentry *h_parent, int isdir)
22237 + struct dentry *h_dentry, *h_latest;
22238 + struct inode *h_inode;
22240 + h_dentry = au_h_dptr(dentry, bindex);
22241 + if (d_really_is_positive(dentry)) {
22243 + if (unlikely(d_is_negative(h_dentry)))
22245 + h_inode = d_inode(h_dentry);
22246 + if (unlikely(!h_inode->i_nlink))
22249 + h_mode = h_inode->i_mode;
22252 + if (unlikely(S_ISDIR(h_mode)))
22254 + } else if (unlikely(!S_ISDIR(h_mode))) {
22259 + /* rename(2) case */
22261 + if (unlikely(d_is_positive(h_dentry)))
22266 + /* expected parent dir is locked */
22267 + if (unlikely(h_parent != h_dentry->d_parent))
22272 + * rmdir a dir may break the consistency on some filesystem.
22273 + * let's try heavy test.
22276 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22277 + && au_test_h_perm(d_inode(h_parent),
22278 + MAY_EXEC | MAY_WRITE)))
22281 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22283 + if (IS_ERR(h_latest))
22285 + if (h_latest == h_dentry)
22294 + * decide the branch where we operate for @dentry. the branch index will be set
22295 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22296 + * dir for reverting.
22297 + * when a new whiteout is necessary, create it.
22299 +static struct dentry*
22300 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22301 + struct au_dtime *dt, struct au_pin *pin)
22303 + struct dentry *wh_dentry;
22304 + struct super_block *sb;
22305 + struct path h_path;
22306 + int err, need_wh;
22307 + unsigned int udba;
22308 + aufs_bindex_t bcpup;
22310 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22311 + wh_dentry = ERR_PTR(need_wh);
22312 + if (unlikely(need_wh < 0))
22315 + sb = dentry->d_sb;
22316 + udba = au_opt_udba(sb);
22318 + err = au_pin(pin, dentry, bcpup, udba,
22319 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22320 + wh_dentry = ERR_PTR(err);
22321 + if (unlikely(err))
22324 + h_path.dentry = au_pinned_h_parent(pin);
22325 + if (udba != AuOpt_UDBA_NONE
22326 + && au_dbtop(dentry) == bcpup) {
22327 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22328 + wh_dentry = ERR_PTR(err);
22329 + if (unlikely(err))
22333 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22334 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22335 + wh_dentry = NULL;
22337 + goto out; /* success, no need to create whiteout */
22339 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22340 + if (IS_ERR(wh_dentry))
22343 + /* returns with the parent is locked and wh_dentry is dget-ed */
22344 + goto out; /* success */
22349 + return wh_dentry;
22353 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22354 + * in order to be revertible and save time for removing many child whiteouts
22356 + * returns 1 when there are too many child whiteout and caller should remove
22357 + * them asynchronously. returns 0 when the number of children is enough small to
22358 + * remove now or the branch fs is a remote fs.
22359 + * otherwise return an error.
22361 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22362 + struct au_nhash *whlist, struct inode *dir)
22364 + int rmdir_later, err, dirwh;
22365 + struct dentry *h_dentry;
22366 + struct super_block *sb;
22367 + struct inode *inode;
22369 + sb = dentry->d_sb;
22370 + SiMustAnyLock(sb);
22371 + h_dentry = au_h_dptr(dentry, bindex);
22372 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22373 + if (unlikely(err))
22376 + /* stop monitoring */
22377 + inode = d_inode(dentry);
22378 + au_hn_free(au_hi(inode, bindex));
22380 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22381 + dirwh = au_sbi(sb)->si_dirwh;
22382 + rmdir_later = (dirwh <= 1);
22383 + if (!rmdir_later)
22384 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22387 + return rmdir_later;
22390 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22391 + if (unlikely(err)) {
22392 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22393 + h_dentry, bindex, err);
22403 + * final procedure for deleting a entry.
22404 + * maintain dentry and iattr.
22406 +static void epilog(struct inode *dir, struct dentry *dentry,
22407 + aufs_bindex_t bindex)
22409 + struct inode *inode;
22411 + inode = d_inode(dentry);
22413 + inode->i_ctime = dir->i_ctime;
22415 + au_dir_ts(dir, bindex);
22416 + inode_inc_iversion(dir);
22420 + * when an error happened, remove the created whiteout and revert everything.
22422 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22423 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22424 + struct dentry *dentry, struct au_dtime *dt)
22427 + struct path h_path = {
22428 + .dentry = wh_dentry,
22429 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22432 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22434 + au_set_dbwh(dentry, bwh);
22435 + au_dtime_revert(dt);
22439 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22443 +/* ---------------------------------------------------------------------- */
22445 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22448 + aufs_bindex_t bwh, bindex, btop;
22449 + struct inode *inode, *h_dir, *delegated;
22450 + struct dentry *parent, *wh_dentry;
22451 + /* to reduce stack size */
22453 + struct au_dtime dt;
22454 + struct au_pin pin;
22455 + struct path h_path;
22461 + a = kmalloc(sizeof(*a), GFP_NOFS);
22462 + if (unlikely(!a))
22465 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22466 + if (unlikely(err))
22468 + err = au_d_hashed_positive(dentry);
22469 + if (unlikely(err))
22471 + inode = d_inode(dentry);
22472 + IMustLock(inode);
22474 + if (unlikely(d_is_dir(dentry)))
22475 + goto out_unlock; /* possible? */
22477 + btop = au_dbtop(dentry);
22478 + bwh = au_dbwh(dentry);
22480 + parent = dentry->d_parent; /* dir inode is locked */
22481 + di_write_lock_parent(parent);
22482 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22484 + err = PTR_ERR(wh_dentry);
22485 + if (IS_ERR(wh_dentry))
22488 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22489 + a->h_path.dentry = au_h_dptr(dentry, btop);
22490 + dget(a->h_path.dentry);
22491 + if (bindex == btop) {
22492 + h_dir = au_pinned_h_dir(&a->pin);
22493 + delegated = NULL;
22494 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22495 + if (unlikely(err == -EWOULDBLOCK)) {
22496 + pr_warn("cannot retry for NFSv4 delegation"
22497 + " for an internal unlink\n");
22501 + /* dir inode is locked */
22502 + h_dir = d_inode(wh_dentry->d_parent);
22503 + IMustLock(h_dir);
22508 + vfsub_drop_nlink(inode);
22509 + epilog(dir, dentry, bindex);
22511 + /* update target timestamps */
22512 + if (bindex == btop) {
22513 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22515 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22517 + /* todo: this timestamp may be reverted later */
22518 + inode->i_ctime = h_dir->i_ctime;
22519 + goto out_unpin; /* success */
22526 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22533 + au_unpin(&a->pin);
22535 + dput(a->h_path.dentry);
22537 + di_write_unlock(parent);
22539 + aufs_read_unlock(dentry, AuLock_DW);
22546 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22548 + int err, rmdir_later;
22549 + aufs_bindex_t bwh, bindex, btop;
22550 + struct inode *inode;
22551 + struct dentry *parent, *wh_dentry, *h_dentry;
22552 + struct au_whtmp_rmdir *args;
22553 + /* to reduce stack size */
22555 + struct au_dtime dt;
22556 + struct au_pin pin;
22562 + a = kmalloc(sizeof(*a), GFP_NOFS);
22563 + if (unlikely(!a))
22566 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22567 + if (unlikely(err))
22569 + err = au_alive_dir(dentry);
22570 + if (unlikely(err))
22572 + inode = d_inode(dentry);
22573 + IMustLock(inode);
22575 + if (unlikely(!d_is_dir(dentry)))
22576 + goto out_unlock; /* possible? */
22579 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22580 + if (unlikely(!args))
22583 + parent = dentry->d_parent; /* dir inode is locked */
22584 + di_write_lock_parent(parent);
22585 + err = au_test_empty(dentry, &args->whlist);
22586 + if (unlikely(err))
22589 + btop = au_dbtop(dentry);
22590 + bwh = au_dbwh(dentry);
22592 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22594 + err = PTR_ERR(wh_dentry);
22595 + if (IS_ERR(wh_dentry))
22598 + h_dentry = au_h_dptr(dentry, btop);
22601 + if (bindex == btop) {
22602 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22604 + rmdir_later = err;
22608 + /* stop monitoring */
22609 + au_hn_free(au_hi(inode, btop));
22611 + /* dir inode is locked */
22612 + IMustLock(d_inode(wh_dentry->d_parent));
22617 + vfsub_dead_dir(inode);
22618 + au_set_dbdiropq(dentry, -1);
22619 + epilog(dir, dentry, bindex);
22621 + if (rmdir_later) {
22622 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22626 + goto out_unpin; /* success */
22634 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22641 + au_unpin(&a->pin);
22645 + di_write_unlock(parent);
22647 + au_whtmp_rmdir_free(args);
22649 + aufs_read_unlock(dentry, AuLock_DW);
22656 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22657 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 08:00:00.000000000 +0800
22658 +++ linux/fs/aufs/i_op_ren.c 2019-07-11 21:21:54.382384486 +0800
22660 +// SPDX-License-Identifier: GPL-2.0
22662 + * Copyright (C) 2005-2019 Junjiro R. Okajima
22664 + * This program, aufs is free software; you can redistribute it and/or modify
22665 + * it under the terms of the GNU General Public License as published by
22666 + * the Free Software Foundation; either version 2 of the License, or
22667 + * (at your option) any later version.
22669 + * This program is distributed in the hope that it will be useful,
22670 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22671 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22672 + * GNU General Public License for more details.
22674 + * You should have received a copy of the GNU General Public License
22675 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22679 + * inode operation (rename entry)
22680 + * todo: this is crazy monster
22683 +#include <linux/iversion.h>
22686 +enum { AuSRC, AuDST, AuSrcDst };
22687 +enum { AuPARENT, AuCHILD, AuParentChild };
22689 +#define AuRen_ISDIR_SRC 1
22690 +#define AuRen_ISDIR_DST (1 << 1)
22691 +#define AuRen_ISSAMEDIR (1 << 2)
22692 +#define AuRen_WHSRC (1 << 3)
22693 +#define AuRen_WHDST (1 << 4)
22694 +#define AuRen_MNT_WRITE (1 << 5)
22695 +#define AuRen_DT_DSTDIR (1 << 6)
22696 +#define AuRen_DIROPQ_SRC (1 << 7)
22697 +#define AuRen_DIROPQ_DST (1 << 8)
22698 +#define AuRen_DIRREN (1 << 9)
22699 +#define AuRen_DROPPED_SRC (1 << 10)
22700 +#define AuRen_DROPPED_DST (1 << 11)
22701 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22702 +#define au_fset_ren(flags, name) \
22703 + do { (flags) |= AuRen_##name; } while (0)
22704 +#define au_fclr_ren(flags, name) \
22705 + do { (flags) &= ~AuRen_##name; } while (0)
22707 +#ifndef CONFIG_AUFS_DIRREN
22708 +#undef AuRen_DIRREN
22709 +#define AuRen_DIRREN 0
22712 +struct au_ren_args {
22714 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22716 + struct inode *dir, *inode;
22717 + struct au_hinode *hdir, *hinode;
22718 + struct au_dtime dt[AuParentChild];
22719 + aufs_bindex_t btop, bdiropq;
22722 +#define src_dentry sd[AuSRC].dentry
22723 +#define src_dir sd[AuSRC].dir
22724 +#define src_inode sd[AuSRC].inode
22725 +#define src_h_dentry sd[AuSRC].h_dentry
22726 +#define src_parent sd[AuSRC].parent
22727 +#define src_h_parent sd[AuSRC].h_parent
22728 +#define src_wh_dentry sd[AuSRC].wh_dentry
22729 +#define src_hdir sd[AuSRC].hdir
22730 +#define src_hinode sd[AuSRC].hinode
22731 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22732 +#define src_dt sd[AuSRC].dt
22733 +#define src_btop sd[AuSRC].btop
22734 +#define src_bdiropq sd[AuSRC].bdiropq
22736 +#define dst_dentry sd[AuDST].dentry
22737 +#define dst_dir sd[AuDST].dir
22738 +#define dst_inode sd[AuDST].inode
22739 +#define dst_h_dentry sd[AuDST].h_dentry
22740 +#define dst_parent sd[AuDST].parent
22741 +#define dst_h_parent sd[AuDST].h_parent
22742 +#define dst_wh_dentry sd[AuDST].wh_dentry
22743 +#define dst_hdir sd[AuDST].hdir
22744 +#define dst_hinode sd[AuDST].hinode
22745 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22746 +#define dst_dt sd[AuDST].dt
22747 +#define dst_btop sd[AuDST].btop
22748 +#define dst_bdiropq sd[AuDST].bdiropq
22750 + struct dentry *h_trap;
22751 + struct au_branch *br;
22752 + struct path h_path;
22753 + struct au_nhash whlist;
22754 + aufs_bindex_t btgt, src_bwh;
22757 + unsigned short auren_flags;
22758 + unsigned char flags; /* syscall parameter */
22759 + unsigned char exchange;
22762 + struct au_whtmp_rmdir *thargs;
22763 + struct dentry *h_dst;
22764 + struct au_hinode *h_root;
22767 +/* ---------------------------------------------------------------------- */
22770 + * functions for reverting.
22771 + * when an error happened in a single rename systemcall, we should revert
22772 + * everything as if nothing happened.
22773 + * we don't need to revert the copied-up/down the parent dir since they are
22777 +#define RevertFailure(fmt, ...) do { \
22778 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22779 + ##__VA_ARGS__, err, rerr); \
22783 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22786 + struct dentry *d;
22787 +#define src_or_dst(member) a->sd[idx].member
22789 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22790 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22791 + rerr = au_diropq_remove(d, a->btgt);
22792 + au_hn_inode_unlock(src_or_dst(hinode));
22793 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22795 + RevertFailure("remove diropq %pd", d);
22797 +#undef src_or_dst_
22800 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22802 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22803 + au_ren_do_rev_diropq(err, a, AuSRC);
22804 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22805 + au_ren_do_rev_diropq(err, a, AuDST);
22808 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22811 + struct inode *delegated;
22813 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22814 + a->src_h_parent);
22815 + rerr = PTR_ERR(a->h_path.dentry);
22816 + if (IS_ERR(a->h_path.dentry)) {
22817 + RevertFailure("lkup one %pd", a->src_dentry);
22821 + delegated = NULL;
22822 + rerr = vfsub_rename(a->dst_h_dir,
22823 + au_h_dptr(a->src_dentry, a->btgt),
22824 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22825 + if (unlikely(rerr == -EWOULDBLOCK)) {
22826 + pr_warn("cannot retry for NFSv4 delegation"
22827 + " for an internal rename\n");
22830 + d_drop(a->h_path.dentry);
22831 + dput(a->h_path.dentry);
22832 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22834 + RevertFailure("rename %pd", a->src_dentry);
22837 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22840 + struct inode *delegated;
22842 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22843 + a->dst_h_parent);
22844 + rerr = PTR_ERR(a->h_path.dentry);
22845 + if (IS_ERR(a->h_path.dentry)) {
22846 + RevertFailure("lkup one %pd", a->dst_dentry);
22849 + if (d_is_positive(a->h_path.dentry)) {
22850 + d_drop(a->h_path.dentry);
22851 + dput(a->h_path.dentry);
22855 + delegated = NULL;
22856 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22857 + &delegated, a->flags);
22858 + if (unlikely(rerr == -EWOULDBLOCK)) {
22859 + pr_warn("cannot retry for NFSv4 delegation"
22860 + " for an internal rename\n");
22863 + d_drop(a->h_path.dentry);
22864 + dput(a->h_path.dentry);
22866 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22868 + RevertFailure("rename %pd", a->h_dst);
22871 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22875 + a->h_path.dentry = a->src_wh_dentry;
22876 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22877 + au_set_dbwh(a->src_dentry, a->src_bwh);
22879 + RevertFailure("unlink %pd", a->src_wh_dentry);
22881 +#undef RevertFailure
22883 +/* ---------------------------------------------------------------------- */
22886 + * when we have to copyup the renaming entry, do it with the rename-target name
22887 + * in order to minimize the cost (the later actual rename is unnecessary).
22888 + * otherwise rename it on the target branch.
22890 +static int au_ren_or_cpup(struct au_ren_args *a)
22893 + struct dentry *d;
22894 + struct inode *delegated;
22896 + d = a->src_dentry;
22897 + if (au_dbtop(d) == a->btgt) {
22898 + a->h_path.dentry = a->dst_h_dentry;
22899 + AuDebugOn(au_dbtop(d) != a->btgt);
22900 + delegated = NULL;
22901 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22902 + a->dst_h_dir, &a->h_path, &delegated,
22904 + if (unlikely(err == -EWOULDBLOCK)) {
22905 + pr_warn("cannot retry for NFSv4 delegation"
22906 + " for an internal rename\n");
22912 + if (!err && a->h_dst)
22913 + /* it will be set to dinfo later */
22919 +/* cf. aufs_rmdir() */
22920 +static int au_ren_del_whtmp(struct au_ren_args *a)
22923 + struct inode *dir;
22925 + dir = a->dst_dir;
22926 + SiMustAnyLock(dir->i_sb);
22927 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22928 + au_sbi(dir->i_sb)->si_dirwh)
22929 + || au_test_fs_remote(a->h_dst->d_sb)) {
22930 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22931 + if (unlikely(err))
22932 + pr_warn("failed removing whtmp dir %pd (%d), "
22933 + "ignored.\n", a->h_dst, err);
22935 + au_nhash_wh_free(&a->thargs->whlist);
22936 + a->thargs->whlist = a->whlist;
22937 + a->whlist.nh_num = 0;
22938 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22940 + a->thargs = NULL;
22946 +/* make it 'opaque' dir. */
22947 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22950 + struct dentry *d, *diropq;
22951 +#define src_or_dst(member) a->sd[idx].member
22954 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22955 + src_or_dst(bdiropq) = au_dbdiropq(d);
22956 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22957 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22958 + diropq = au_diropq_create(d, a->btgt);
22959 + au_hn_inode_unlock(src_or_dst(hinode));
22960 + if (IS_ERR(diropq))
22961 + err = PTR_ERR(diropq);
22965 +#undef src_or_dst_
22969 +static int au_ren_diropq(struct au_ren_args *a)
22972 + unsigned char always;
22973 + struct dentry *d;
22976 + d = a->dst_dentry; /* already renamed on the branch */
22977 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22978 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22979 + && !au_ftest_ren(a->auren_flags, DIRREN)
22980 + && a->btgt != au_dbdiropq(a->src_dentry)
22981 + && (a->dst_wh_dentry
22982 + || a->btgt <= au_dbdiropq(d)
22983 + /* hide the lower to keep xino */
22984 + /* the lowers may not be a dir, but we hide them anyway */
22985 + || a->btgt < au_dbbot(d)
22988 + err = au_ren_do_diropq(a, AuSRC);
22989 + if (unlikely(err))
22991 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22993 + if (!a->exchange)
22994 + goto out; /* success */
22996 + d = a->src_dentry; /* already renamed on the branch */
22997 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22998 + && a->btgt != au_dbdiropq(a->dst_dentry)
22999 + && (a->btgt < au_dbdiropq(d)
23000 + || a->btgt < au_dbbot(d)
23002 + AuDbgDentry(a->src_dentry);
23003 + AuDbgDentry(a->dst_dentry);
23004 + err = au_ren_do_diropq(a, AuDST);
23005 + if (unlikely(err))
23006 + goto out_rev_src;
23007 + au_fset_ren(a->auren_flags, DIROPQ_DST);
23009 + goto out; /* success */
23012 + AuDbg("err %d, reverting src\n", err);
23013 + au_ren_rev_diropq(err, a);
23018 +static int do_rename(struct au_ren_args *a)
23021 + struct dentry *d, *h_d;
23023 + if (!a->exchange) {
23024 + /* prepare workqueue args for asynchronous rmdir */
23025 + h_d = a->dst_h_dentry;
23026 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
23027 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
23028 + && d_is_positive(h_d)) {
23030 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
23032 + if (unlikely(!a->thargs))
23034 + a->h_dst = dget(h_d);
23037 + /* create whiteout for src_dentry */
23038 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
23039 + a->src_bwh = au_dbwh(a->src_dentry);
23040 + AuDebugOn(a->src_bwh >= 0);
23041 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
23042 + a->src_h_parent);
23043 + err = PTR_ERR(a->src_wh_dentry);
23044 + if (IS_ERR(a->src_wh_dentry))
23048 + /* lookup whiteout for dentry */
23049 + if (au_ftest_ren(a->auren_flags, WHDST)) {
23050 + h_d = au_wh_lkup(a->dst_h_parent,
23051 + &a->dst_dentry->d_name, a->br);
23052 + err = PTR_ERR(h_d);
23055 + if (d_is_negative(h_d))
23058 + a->dst_wh_dentry = h_d;
23061 + /* rename dentry to tmpwh */
23063 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
23064 + if (unlikely(err))
23067 + d = a->dst_dentry;
23068 + au_set_h_dptr(d, a->btgt, NULL);
23069 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
23070 + if (unlikely(err))
23072 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
23076 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
23078 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
23079 + && d_is_positive(a->dst_h_dentry)
23080 + && a->src_btop != a->btgt);
23083 + /* rename by vfs_rename or cpup */
23084 + err = au_ren_or_cpup(a);
23085 + if (unlikely(err))
23086 + /* leave the copied-up one */
23089 + /* make dir opaque */
23090 + err = au_ren_diropq(a);
23091 + if (unlikely(err))
23094 + /* update target timestamps */
23095 + if (a->exchange) {
23096 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
23097 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
23098 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23099 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23101 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
23102 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
23103 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
23104 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23106 + if (!a->exchange) {
23107 + /* remove whiteout for dentry */
23108 + if (a->dst_wh_dentry) {
23109 + a->h_path.dentry = a->dst_wh_dentry;
23110 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
23112 + if (unlikely(err))
23116 + /* remove whtmp */
23118 + au_ren_del_whtmp(a); /* ignore this error */
23120 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
23123 + goto out_success;
23126 + au_ren_rev_diropq(err, a);
23128 + au_ren_rev_rename(err, a);
23132 + au_ren_rev_whtmp(err, a);
23134 + dput(a->dst_wh_dentry);
23135 + a->dst_wh_dentry = NULL;
23137 + if (a->src_wh_dentry)
23138 + au_ren_rev_whsrc(err, a);
23140 + dput(a->src_wh_dentry);
23141 + dput(a->dst_wh_dentry);
23145 + au_whtmp_rmdir_free(a->thargs);
23146 + a->thargs = NULL;
23152 +/* ---------------------------------------------------------------------- */
23155 + * test if @dentry dir can be rename destination or not.
23156 + * success means, it is a logically empty dir.
23158 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23160 + return au_test_empty(dentry, whlist);
23164 + * test if @a->src_dentry dir can be rename source or not.
23165 + * if it can, return 0.
23167 + * - it is a logically empty dir.
23168 + * - or, it exists on writable branch and has no children including whiteouts
23169 + * on the lower branch unless DIRREN is on.
23171 +static int may_rename_srcdir(struct au_ren_args *a)
23174 + unsigned int rdhash;
23175 + aufs_bindex_t btop, btgt;
23176 + struct dentry *dentry;
23177 + struct super_block *sb;
23178 + struct au_sbinfo *sbinfo;
23180 + dentry = a->src_dentry;
23181 + sb = dentry->d_sb;
23182 + sbinfo = au_sbi(sb);
23183 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23184 + au_fset_ren(a->auren_flags, DIRREN);
23187 + btop = au_dbtop(dentry);
23188 + if (btop != btgt) {
23189 + struct au_nhash whlist;
23191 + SiMustAnyLock(sb);
23192 + rdhash = sbinfo->si_rdhash;
23194 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23196 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23197 + if (unlikely(err))
23199 + err = au_test_empty(dentry, &whlist);
23200 + au_nhash_wh_free(&whlist);
23204 + if (btop == au_dbtaildir(dentry))
23205 + return 0; /* success */
23207 + err = au_test_empty_lower(dentry);
23210 + if (err == -ENOTEMPTY) {
23211 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23214 + AuWarn1("renaming dir who has child(ren) on multiple "
23215 + "branches, is not supported\n");
23222 +/* side effect: sets whlist and h_dentry */
23223 +static int au_ren_may_dir(struct au_ren_args *a)
23226 + unsigned int rdhash;
23227 + struct dentry *d;
23229 + d = a->dst_dentry;
23230 + SiMustAnyLock(d->d_sb);
23233 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23234 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23236 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23237 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23238 + if (unlikely(err))
23241 + if (!a->exchange) {
23242 + au_set_dbtop(d, a->dst_btop);
23243 + err = may_rename_dstdir(d, &a->whlist);
23244 + au_set_dbtop(d, a->btgt);
23246 + err = may_rename_srcdir(a);
23248 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23249 + if (unlikely(err))
23252 + d = a->src_dentry;
23253 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23254 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23255 + err = may_rename_srcdir(a);
23256 + if (unlikely(err)) {
23257 + au_nhash_wh_free(&a->whlist);
23258 + a->whlist.nh_num = 0;
23265 +/* ---------------------------------------------------------------------- */
23268 + * simple tests for rename.
23269 + * following the checks in vfs, plus the parent-child relationship.
23271 +static int au_may_ren(struct au_ren_args *a)
23274 + struct inode *h_inode;
23276 + if (a->src_btop == a->btgt) {
23277 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23278 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23279 + if (unlikely(err))
23282 + if (unlikely(a->src_h_dentry == a->h_trap))
23287 + if (a->dst_btop != a->btgt)
23290 + err = -ENOTEMPTY;
23291 + if (unlikely(a->dst_h_dentry == a->h_trap))
23295 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23296 + if (d_really_is_negative(a->dst_dentry)) {
23297 + if (d_is_negative(a->dst_h_dentry))
23298 + err = au_may_add(a->dst_dentry, a->btgt,
23299 + a->dst_h_parent, isdir);
23301 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23303 + h_inode = d_inode(a->dst_h_dentry);
23304 + if (h_inode->i_nlink)
23305 + err = au_may_del(a->dst_dentry, a->btgt,
23306 + a->dst_h_parent, isdir);
23310 + if (unlikely(err == -ENOENT || err == -EEXIST))
23316 +/* ---------------------------------------------------------------------- */
23321 + * - src_dir and dir by lock_rename()
23322 + * - inode if exists
23325 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23327 + * + di_write_lock2_child()
23328 + * + di_write_lock_child()
23329 + * + ii_write_lock_child()
23330 + * + di_write_lock_child2()
23331 + * + ii_write_lock_child2()
23332 + * + src_parent and parent
23333 + * + di_write_lock_parent()
23334 + * + ii_write_lock_parent()
23335 + * + di_write_lock_parent2()
23336 + * + ii_write_lock_parent2()
23337 + * + lower src_dir and dir by vfsub_lock_rename()
23338 + * + verify the every relationships between child and parent. if any
23339 + * of them failed, unlock all and return -EBUSY.
23341 +static void au_ren_unlock(struct au_ren_args *a)
23343 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23344 + a->dst_h_parent, a->dst_hdir);
23345 + if (au_ftest_ren(a->auren_flags, DIRREN)
23347 + au_hn_inode_unlock(a->h_root);
23348 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23349 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23352 +static int au_ren_lock(struct au_ren_args *a)
23355 + unsigned int udba;
23358 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23359 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23360 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23361 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23363 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23364 + if (unlikely(err))
23366 + au_fset_ren(a->auren_flags, MNT_WRITE);
23367 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23368 + struct dentry *root;
23369 + struct inode *dir;
23372 + * sbinfo is already locked, so this ii_read_lock is
23373 + * unnecessary. but our debugging feature checks it.
23375 + root = a->src_inode->i_sb->s_root;
23376 + if (root != a->src_parent && root != a->dst_parent) {
23377 + dir = d_inode(root);
23378 + ii_read_lock_parent3(dir);
23379 + a->h_root = au_hi(dir, a->btgt);
23380 + ii_read_unlock(dir);
23381 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23384 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23385 + a->dst_h_parent, a->dst_hdir);
23386 + udba = au_opt_udba(a->src_dentry->d_sb);
23387 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23388 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23389 + err = au_busy_or_stale();
23390 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23391 + err = au_h_verify(a->src_h_dentry, udba,
23392 + d_inode(a->src_h_parent), a->src_h_parent,
23394 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23395 + err = au_h_verify(a->dst_h_dentry, udba,
23396 + d_inode(a->dst_h_parent), a->dst_h_parent,
23399 + goto out; /* success */
23401 + err = au_busy_or_stale();
23402 + au_ren_unlock(a);
23408 +/* ---------------------------------------------------------------------- */
23410 +static void au_ren_refresh_dir(struct au_ren_args *a)
23412 + struct inode *dir;
23414 + dir = a->dst_dir;
23415 + inode_inc_iversion(dir);
23416 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23417 + /* is this updating defined in POSIX? */
23418 + au_cpup_attr_timesizes(a->src_inode);
23419 + au_cpup_attr_nlink(dir, /*force*/1);
23421 + au_dir_ts(dir, a->btgt);
23423 + if (a->exchange) {
23424 + dir = a->src_dir;
23425 + inode_inc_iversion(dir);
23426 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23427 + /* is this updating defined in POSIX? */
23428 + au_cpup_attr_timesizes(a->dst_inode);
23429 + au_cpup_attr_nlink(dir, /*force*/1);
23431 + au_dir_ts(dir, a->btgt);
23434 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23437 + dir = a->src_dir;
23438 + inode_inc_iversion(dir);
23439 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23440 + au_cpup_attr_nlink(dir, /*force*/1);
23441 + au_dir_ts(dir, a->btgt);
23444 +static void au_ren_refresh(struct au_ren_args *a)
23446 + aufs_bindex_t bbot, bindex;
23447 + struct dentry *d, *h_d;
23448 + struct inode *i, *h_i;
23449 + struct super_block *sb;
23451 + d = a->dst_dentry;
23454 + /* already dget-ed by au_ren_or_cpup() */
23455 + au_set_h_dptr(d, a->btgt, a->h_dst);
23457 + i = a->dst_inode;
23459 + if (!a->exchange) {
23460 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23461 + vfsub_drop_nlink(i);
23463 + vfsub_dead_dir(i);
23464 + au_cpup_attr_timesizes(i);
23466 + au_update_dbrange(d, /*do_put_zero*/1);
23468 + au_cpup_attr_nlink(i, /*force*/1);
23471 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23472 + au_set_h_dptr(d, bindex, NULL);
23473 + bbot = au_dbbot(d);
23474 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23475 + au_set_h_dptr(d, bindex, NULL);
23476 + au_update_dbrange(d, /*do_put_zero*/0);
23480 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23481 + d_drop(a->src_dentry);
23482 + if (au_ftest_ren(a->auren_flags, DIRREN))
23483 + au_set_dbwh(a->src_dentry, -1);
23487 + d = a->src_dentry;
23488 + au_set_dbwh(d, -1);
23489 + bbot = au_dbbot(d);
23490 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23491 + h_d = au_h_dptr(d, bindex);
23493 + au_set_h_dptr(d, bindex, NULL);
23495 + au_set_dbbot(d, a->btgt);
23498 + i = a->src_inode;
23499 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23500 + return; /* success */
23502 + bbot = au_ibbot(i);
23503 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23504 + h_i = au_h_iptr(i, bindex);
23506 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23507 + /* ignore this error */
23508 + au_set_h_iptr(i, bindex, NULL, 0);
23511 + au_set_ibbot(i, a->btgt);
23514 +/* ---------------------------------------------------------------------- */
23516 +/* mainly for link(2) and rename(2) */
23517 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23519 + aufs_bindex_t bdiropq, bwh;
23520 + struct dentry *parent;
23521 + struct au_branch *br;
23523 + parent = dentry->d_parent;
23524 + IMustLock(d_inode(parent)); /* dir is locked */
23526 + bdiropq = au_dbdiropq(parent);
23527 + bwh = au_dbwh(dentry);
23528 + br = au_sbr(dentry->d_sb, btgt);
23529 + if (au_br_rdonly(br)
23530 + || (0 <= bdiropq && bdiropq < btgt)
23531 + || (0 <= bwh && bwh < btgt))
23534 + AuDbg("btgt %d\n", btgt);
23538 +/* sets src_btop, dst_btop and btgt */
23539 +static int au_ren_wbr(struct au_ren_args *a)
23542 + struct au_wr_dir_args wr_dir_args = {
23543 + /* .force_btgt = -1, */
23544 + .flags = AuWrDir_ADD_ENTRY
23547 + a->src_btop = au_dbtop(a->src_dentry);
23548 + a->dst_btop = au_dbtop(a->dst_dentry);
23549 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23550 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23551 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23552 + wr_dir_args.force_btgt = a->src_btop;
23553 + if (a->dst_inode && a->dst_btop < a->src_btop)
23554 + wr_dir_args.force_btgt = a->dst_btop;
23555 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23556 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23559 + au_update_dbtop(a->dst_dentry);
23564 +static void au_ren_dt(struct au_ren_args *a)
23566 + a->h_path.dentry = a->src_h_parent;
23567 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23568 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23569 + a->h_path.dentry = a->dst_h_parent;
23570 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23573 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23574 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23578 + a->h_path.dentry = a->src_h_dentry;
23579 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23580 + if (d_is_positive(a->dst_h_dentry)) {
23581 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23582 + a->h_path.dentry = a->dst_h_dentry;
23583 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23587 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23589 + struct dentry *h_d;
23590 + struct inode *h_inode;
23592 + au_dtime_revert(a->src_dt + AuPARENT);
23593 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23594 + au_dtime_revert(a->dst_dt + AuPARENT);
23596 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23597 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23598 + h_inode = d_inode(h_d);
23599 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23600 + au_dtime_revert(a->src_dt + AuCHILD);
23601 + inode_unlock(h_inode);
23603 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23604 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23605 + h_inode = d_inode(h_d);
23606 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23607 + au_dtime_revert(a->dst_dt + AuCHILD);
23608 + inode_unlock(h_inode);
23613 +/* ---------------------------------------------------------------------- */
23615 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23616 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23617 + unsigned int _flags)
23619 + int err, lock_flags;
23621 + /* reduce stack space */
23622 + struct au_ren_args *a;
23623 + struct au_pin pin;
23625 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23626 + IMustLock(_src_dir);
23627 + IMustLock(_dst_dir);
23630 + if (unlikely(_flags & RENAME_WHITEOUT))
23634 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23635 + a = kzalloc(sizeof(*a), GFP_NOFS);
23636 + if (unlikely(!a))
23639 + a->flags = _flags;
23640 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23641 + && RENAME_EXCHANGE > U8_MAX);
23642 + a->exchange = _flags & RENAME_EXCHANGE;
23643 + a->src_dir = _src_dir;
23644 + a->src_dentry = _src_dentry;
23645 + a->src_inode = NULL;
23646 + if (d_really_is_positive(a->src_dentry))
23647 + a->src_inode = d_inode(a->src_dentry);
23648 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23649 + a->dst_dir = _dst_dir;
23650 + a->dst_dentry = _dst_dentry;
23651 + a->dst_inode = NULL;
23652 + if (d_really_is_positive(a->dst_dentry))
23653 + a->dst_inode = d_inode(a->dst_dentry);
23654 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23655 + if (a->dst_inode) {
23657 + * if EXCHANGE && src is non-dir && dst is dir,
23658 + * dst is not locked.
23660 + /* IMustLock(a->dst_inode); */
23661 + au_igrab(a->dst_inode);
23665 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23666 + if (d_is_dir(a->src_dentry)) {
23667 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23668 + if (unlikely(!a->exchange
23669 + && d_really_is_positive(a->dst_dentry)
23670 + && !d_is_dir(a->dst_dentry)))
23672 + lock_flags |= AuLock_DIRS;
23674 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23675 + au_fset_ren(a->auren_flags, ISDIR_DST);
23676 + if (unlikely(!a->exchange
23677 + && d_really_is_positive(a->src_dentry)
23678 + && !d_is_dir(a->src_dentry)))
23680 + lock_flags |= AuLock_DIRS;
23682 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23684 + if (unlikely(err))
23687 + err = au_d_hashed_positive(a->src_dentry);
23688 + if (unlikely(err))
23691 + if (a->dst_inode) {
23693 + * If it is a dir, VFS unhash it before this
23694 + * function. It means we cannot rely upon d_unhashed().
23696 + if (unlikely(!a->dst_inode->i_nlink))
23698 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23699 + err = au_d_hashed_positive(a->dst_dentry);
23700 + if (unlikely(err && !a->exchange))
23702 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23704 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23708 + * is it possible?
23709 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23710 + * there may exist a problem somewhere else.
23713 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23716 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23717 + di_write_lock_parent(a->dst_parent);
23719 + /* which branch we process */
23720 + err = au_ren_wbr(a);
23721 + if (unlikely(err < 0))
23723 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23724 + a->h_path.mnt = au_br_mnt(a->br);
23726 + /* are they available to be renamed */
23727 + err = au_ren_may_dir(a);
23728 + if (unlikely(err))
23729 + goto out_children;
23731 + /* prepare the writable parent dir on the same branch */
23732 + if (a->dst_btop == a->btgt) {
23733 + au_fset_ren(a->auren_flags, WHDST);
23735 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23736 + if (unlikely(err))
23737 + goto out_children;
23741 + if (!a->exchange) {
23742 + if (a->src_dir != a->dst_dir) {
23744 + * this temporary unlock is safe,
23745 + * because both dir->i_mutex are locked.
23747 + di_write_unlock(a->dst_parent);
23748 + di_write_lock_parent(a->src_parent);
23749 + err = au_wr_dir_need_wh(a->src_dentry,
23750 + au_ftest_ren(a->auren_flags,
23753 + di_write_unlock(a->src_parent);
23754 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23756 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23758 + err = au_wr_dir_need_wh(a->src_dentry,
23759 + au_ftest_ren(a->auren_flags,
23763 + if (unlikely(err < 0))
23764 + goto out_children;
23766 + au_fset_ren(a->auren_flags, WHSRC);
23769 + if (a->src_btop != a->btgt) {
23770 + err = au_pin(&pin, a->src_dentry, a->btgt,
23771 + au_opt_udba(a->src_dentry->d_sb),
23772 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23774 + struct au_cp_generic cpg = {
23775 + .dentry = a->src_dentry,
23777 + .bsrc = a->src_btop,
23780 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23782 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23783 + err = au_sio_cpup_simple(&cpg);
23786 + if (unlikely(err))
23787 + goto out_children;
23788 + a->src_btop = a->btgt;
23789 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23790 + if (!a->exchange)
23791 + au_fset_ren(a->auren_flags, WHSRC);
23795 + if (a->exchange && a->dst_inode
23796 + && a->dst_btop != a->btgt) {
23797 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23798 + au_opt_udba(a->dst_dentry->d_sb),
23799 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23801 + struct au_cp_generic cpg = {
23802 + .dentry = a->dst_dentry,
23804 + .bsrc = a->dst_btop,
23807 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23809 + err = au_sio_cpup_simple(&cpg);
23812 + if (unlikely(err))
23813 + goto out_children;
23814 + a->dst_btop = a->btgt;
23815 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23818 + /* lock them all */
23819 + err = au_ren_lock(a);
23820 + if (unlikely(err))
23821 + /* leave the copied-up one */
23822 + goto out_children;
23824 + if (!a->exchange) {
23825 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23826 + err = au_may_ren(a);
23827 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23828 + err = -ENAMETOOLONG;
23829 + if (unlikely(err))
23833 + /* store timestamps to be revertible */
23836 + /* store dirren info */
23837 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23838 + err = au_dr_rename(a->src_dentry, a->btgt,
23839 + &a->dst_dentry->d_name, &rev);
23841 + if (unlikely(err))
23846 + err = do_rename(a);
23847 + if (unlikely(err))
23850 + if (au_ftest_ren(a->auren_flags, DIRREN))
23851 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23853 + /* update dir attributes */
23854 + au_ren_refresh_dir(a);
23856 + /* dput/iput all lower dentries */
23857 + au_ren_refresh(a);
23859 + goto out_hdir; /* success */
23862 + if (au_ftest_ren(a->auren_flags, DIRREN))
23863 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23865 + au_ren_rev_dt(err, a);
23867 + au_ren_unlock(a);
23869 + au_nhash_wh_free(&a->whlist);
23870 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23871 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23872 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23873 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23877 + if (d_unhashed(a->src_dentry))
23878 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23879 + if (d_unhashed(a->dst_dentry))
23880 + au_fset_ren(a->auren_flags, DROPPED_DST);
23881 + if (!a->exchange)
23882 + d_move(a->src_dentry, a->dst_dentry);
23884 + d_exchange(a->src_dentry, a->dst_dentry);
23885 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23886 + d_drop(a->dst_dentry);
23888 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23889 + d_drop(a->src_dentry);
23891 + au_update_dbtop(a->dst_dentry);
23892 + if (!a->dst_inode)
23893 + d_drop(a->dst_dentry);
23895 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23896 + di_write_unlock(a->dst_parent);
23898 + di_write_unlock2(a->src_parent, a->dst_parent);
23900 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23902 + iput(a->dst_inode);
23904 + au_whtmp_rmdir_free(a->thargs);
23910 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23911 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 08:00:00.000000000 +0800
23912 +++ linux/fs/aufs/Kconfig 2019-07-11 21:21:54.379051070 +0800
23914 +# SPDX-License-Identifier: GPL-2.0
23916 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23918 + Aufs is a stackable unification filesystem such as Unionfs,
23919 + which unifies several directories and provides a merged single
23921 + In the early days, aufs was entirely re-designed and
23922 + re-implemented Unionfs Version 1.x series. Introducing many
23923 + original ideas, approaches and improvements, it becomes totally
23924 + different from Unionfs while keeping the basic features.
23928 + prompt "Maximum number of branches"
23929 + default AUFS_BRANCH_MAX_127
23931 + Specifies the maximum number of branches (or member directories)
23932 + in a single aufs. The larger value consumes more system
23933 + resources and has a minor impact to performance.
23934 +config AUFS_BRANCH_MAX_127
23937 + Specifies the maximum number of branches (or member directories)
23938 + in a single aufs. The larger value consumes more system
23939 + resources and has a minor impact to performance.
23940 +config AUFS_BRANCH_MAX_511
23943 + Specifies the maximum number of branches (or member directories)
23944 + in a single aufs. The larger value consumes more system
23945 + resources and has a minor impact to performance.
23946 +config AUFS_BRANCH_MAX_1023
23949 + Specifies the maximum number of branches (or member directories)
23950 + in a single aufs. The larger value consumes more system
23951 + resources and has a minor impact to performance.
23952 +config AUFS_BRANCH_MAX_32767
23955 + Specifies the maximum number of branches (or member directories)
23956 + in a single aufs. The larger value consumes more system
23957 + resources and has a minor impact to performance.
23960 +config AUFS_SBILIST
23962 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23965 + Automatic configuration for internal use.
23966 + When aufs supports Magic SysRq or /proc, enabled automatically.
23968 +config AUFS_HNOTIFY
23969 + bool "Detect direct branch access (bypassing aufs)"
23971 + If you want to modify files on branches directly, eg. bypassing aufs,
23972 + and want aufs to detect the changes of them fully, then enable this
23973 + option and use 'udba=notify' mount option.
23974 + Currently there is only one available configuration, "fsnotify".
23975 + It will have a negative impact to the performance.
23976 + See detail in aufs.5.
23979 + prompt "method" if AUFS_HNOTIFY
23980 + default AUFS_HFSNOTIFY
23981 +config AUFS_HFSNOTIFY
23986 +config AUFS_EXPORT
23987 + bool "NFS-exportable aufs"
23988 + depends on EXPORTFS
23990 + If you want to export your mounted aufs via NFS, then enable this
23991 + option. There are several requirements for this configuration.
23992 + See detail in aufs.5.
23994 +config AUFS_INO_T_64
23996 + depends on AUFS_EXPORT
23997 + depends on 64BIT && !(ALPHA || S390)
24000 + Automatic configuration for internal use.
24001 + /* typedef unsigned long/int __kernel_ino_t */
24002 + /* alpha and s390x are int */
24005 + bool "support for XATTR/EA (including Security Labels)"
24007 + If your branch fs supports XATTR/EA and you want to make them
24008 + available in aufs too, then enable this opsion and specify the
24009 + branch attributes for EA.
24010 + See detail in aufs.5.
24013 + bool "File-based Hierarchical Storage Management"
24015 + Hierarchical Storage Management (or HSM) is a well-known feature
24016 + in the storage world. Aufs provides this feature as file-based.
24017 + with multiple branches.
24018 + These multiple branches are prioritized, ie. the topmost one
24019 + should be the fastest drive and be used heavily.
24022 + bool "Readdir in userspace"
24024 + Aufs has two methods to provide a merged view for a directory,
24025 + by a user-space library and by kernel-space natively. The latter
24026 + is always enabled but sometimes large and slow.
24027 + If you enable this option, install the library in aufs2-util
24028 + package, and set some environment variables for your readdir(3),
24029 + then the work will be handled in user-space which generally
24030 + shows better performance in most cases.
24031 + See detail in aufs.5.
24033 +config AUFS_DIRREN
24034 + bool "Workaround for rename(2)-ing a directory"
24036 + By default, aufs returns EXDEV error in renameing a dir who has
24037 + his child on the lower branch, since it is a bad idea to issue
24038 + rename(2) internally for every lower branch. But user may not
24039 + accept this behaviour. So here is a workaround to allow such
24040 + rename(2) and store some extra infromation on the writable
24041 + branch. Obviously this costs high (and I don't like it).
24042 + To use this feature, you need to enable this configuration AND
24043 + to specify the mount option `dirren.'
24044 + See details in aufs.5 and the design documents.
24047 + bool "Show whiteouts"
24049 + If you want to make the whiteouts in aufs visible, then enable
24050 + this option and specify 'shwh' mount option. Although it may
24051 + sounds like philosophy or something, but in technically it
24052 + simply shows the name of whiteout with keeping its behaviour.
24054 +config AUFS_BR_RAMFS
24055 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
24057 + If you want to use ramfs as an aufs branch fs, then enable this
24058 + option. Generally tmpfs is recommended.
24059 + Aufs prohibited them to be a branch fs by default, because
24060 + initramfs becomes unusable after switch_root or something
24061 + generally. If you sets initramfs as an aufs branch and boot your
24062 + system by switch_root, you will meet a problem easily since the
24063 + files in initramfs may be inaccessible.
24064 + Unless you are going to use ramfs as an aufs branch fs without
24065 + switch_root or something, leave it N.
24067 +config AUFS_BR_FUSE
24068 + bool "Fuse fs as an aufs branch"
24069 + depends on FUSE_FS
24072 + If you want to use fuse-based userspace filesystem as an aufs
24073 + branch fs, then enable this option.
24074 + It implements the internal poll(2) operation which is
24075 + implemented by fuse only (curretnly).
24080 + Automatic configuration for internal use.
24082 +config AUFS_BR_HFSPLUS
24083 + bool "Hfsplus as an aufs branch"
24084 + depends on HFSPLUS_FS
24087 + If you want to use hfsplus fs as an aufs branch fs, then enable
24088 + this option. This option introduces a small overhead at
24089 + copying-up a file on hfsplus.
24091 +config AUFS_BDEV_LOOP
24093 + depends on BLK_DEV_LOOP
24096 + Automatic configuration for internal use.
24097 + Convert =[ym] into =y.
24100 + bool "Debug aufs"
24102 + Enable this to compile aufs internal debug code.
24103 + It will have a negative impact to the performance.
24105 +config AUFS_MAGIC_SYSRQ
24107 + depends on AUFS_DEBUG && MAGIC_SYSRQ
24110 + Automatic configuration for internal use.
24111 + When aufs supports Magic SysRq, enabled automatically.
24113 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
24114 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 08:00:00.000000000 +0800
24115 +++ linux/fs/aufs/lcnt.h 2019-07-11 21:21:54.382384486 +0800
24117 +/* SPDX-License-Identifier: GPL-2.0 */
24119 + * Copyright (C) 2018-2019 Junjiro R. Okajima
24121 + * This program, aufs is free software; you can redistribute it and/or modify
24122 + * it under the terms of the GNU General Public License as published by
24123 + * the Free Software Foundation; either version 2 of the License, or
24124 + * (at your option) any later version.
24126 + * This program is distributed in the hope that it will be useful,
24127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24129 + * GNU General Public License for more details.
24131 + * You should have received a copy of the GNU General Public License
24132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24136 + * simple long counter wrapper
24139 +#ifndef __AUFS_LCNT_H__
24140 +#define __AUFS_LCNT_H__
24144 +#include "debug.h"
24146 +#define AuLCntATOMIC 1
24147 +#define AuLCntPCPUCNT 2
24149 + * why does percpu_refcount require extra synchronize_rcu()s in
24150 + * au_br_do_free()
24152 +#define AuLCntPCPUREF 3
24154 +/* #define AuLCntChosen AuLCntATOMIC */
24155 +#define AuLCntChosen AuLCntPCPUCNT
24156 +/* #define AuLCntChosen AuLCntPCPUREF */
24158 +#if AuLCntChosen == AuLCntATOMIC
24159 +#include <linux/atomic.h>
24161 +typedef atomic_long_t au_lcnt_t;
24163 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24165 + atomic_long_set(cnt, 0);
24169 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24174 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24175 + int do_sync __maybe_unused)
24180 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24182 + atomic_long_inc(cnt);
24185 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24187 + atomic_long_dec(cnt);
24190 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24192 + return atomic_long_read(cnt);
24196 +#if AuLCntChosen == AuLCntPCPUCNT
24197 +#include <linux/percpu_counter.h>
24199 +typedef struct percpu_counter au_lcnt_t;
24201 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24203 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24206 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24211 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24213 + percpu_counter_destroy(cnt);
24216 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24218 + percpu_counter_inc(cnt);
24221 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24223 + percpu_counter_dec(cnt);
24226 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24230 + n = percpu_counter_sum(cnt);
24232 + if (LONG_MAX != LLONG_MAX
24234 + AuWarn1("%s\n", "wrap-around");
24240 +#if AuLCntChosen == AuLCntPCPUREF
24241 +#include <linux/percpu-refcount.h>
24243 +typedef struct percpu_ref au_lcnt_t;
24245 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24248 + release = percpu_ref_exit;
24249 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24252 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24254 + synchronize_rcu();
24257 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24259 + percpu_ref_kill(cnt);
24261 + au_lcnt_wait_for_fin(cnt);
24264 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24266 + percpu_ref_get(cnt);
24269 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24271 + percpu_ref_put(cnt);
24275 + * avoid calling this func as possible.
24277 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24281 + percpu_ref_switch_to_atomic_sync(cnt);
24282 + l = atomic_long_read(&cnt->count);
24284 + percpu_ref_switch_to_percpu(cnt);
24286 + /* percpu_ref is initialized by 1 instead of 0 */
24291 +#ifdef CONFIG_AUFS_DEBUG
24292 +#define AuLCntZero(val) do { \
24295 + AuDbg("%s = %ld\n", #val, l); \
24298 +#define AuLCntZero(val) do {} while (0)
24301 +#endif /* __KERNEL__ */
24302 +#endif /* __AUFS_LCNT_H__ */
24303 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24304 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 08:00:00.000000000 +0800
24305 +++ linux/fs/aufs/loop.c 2019-07-11 21:21:54.382384486 +0800
24307 +// SPDX-License-Identifier: GPL-2.0
24309 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24311 + * This program, aufs is free software; you can redistribute it and/or modify
24312 + * it under the terms of the GNU General Public License as published by
24313 + * the Free Software Foundation; either version 2 of the License, or
24314 + * (at your option) any later version.
24316 + * This program is distributed in the hope that it will be useful,
24317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24319 + * GNU General Public License for more details.
24321 + * You should have received a copy of the GNU General Public License
24322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24326 + * support for loopback block device as a branch
24331 +/* added into drivers/block/loop.c */
24332 +static struct file *(*backing_file_func)(struct super_block *sb);
24335 + * test if two lower dentries have overlapping branches.
24337 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24339 + struct super_block *h_sb;
24340 + struct file *backing_file;
24342 + if (unlikely(!backing_file_func)) {
24343 + /* don't load "loop" module here */
24344 + backing_file_func = symbol_get(loop_backing_file);
24345 + if (unlikely(!backing_file_func))
24346 + /* "loop" module is not loaded */
24350 + h_sb = h_adding->d_sb;
24351 + backing_file = backing_file_func(h_sb);
24352 + if (!backing_file)
24355 + h_adding = backing_file->f_path.dentry;
24357 + * h_adding can be local NFS.
24358 + * in this case aufs cannot detect the loop.
24360 + if (unlikely(h_adding->d_sb == sb))
24362 + return !!au_test_subdir(h_adding, sb->s_root);
24365 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24366 +int au_test_loopback_kthread(void)
24369 + struct task_struct *tsk = current;
24370 + char c, comm[sizeof(tsk->comm)];
24373 + if (tsk->flags & PF_KTHREAD) {
24374 + get_task_comm(comm, tsk);
24376 + ret = ('0' <= c && c <= '9'
24377 + && !strncmp(comm, "loop", 4));
24383 +/* ---------------------------------------------------------------------- */
24385 +#define au_warn_loopback_step 16
24386 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24387 +static unsigned long *au_warn_loopback_array;
24389 +void au_warn_loopback(struct super_block *h_sb)
24391 + int i, new_nelem;
24392 + unsigned long *a, magic;
24393 + static DEFINE_SPINLOCK(spin);
24395 + magic = h_sb->s_magic;
24396 + spin_lock(&spin);
24397 + a = au_warn_loopback_array;
24398 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24399 + if (a[i] == magic) {
24400 + spin_unlock(&spin);
24404 + /* h_sb is new to us, print it */
24405 + if (i < au_warn_loopback_nelem) {
24410 + /* expand the array */
24411 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24412 + a = au_kzrealloc(au_warn_loopback_array,
24413 + au_warn_loopback_nelem * sizeof(unsigned long),
24414 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24415 + /*may_shrink*/0);
24417 + au_warn_loopback_nelem = new_nelem;
24418 + au_warn_loopback_array = a;
24423 + spin_unlock(&spin);
24424 + AuWarn1("realloc failed, ignored\n");
24428 + spin_unlock(&spin);
24429 + pr_warn("you may want to try another patch for loopback file "
24430 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24433 +int au_loopback_init(void)
24436 + struct super_block *sb __maybe_unused;
24438 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24441 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24442 + sizeof(unsigned long), GFP_NOFS);
24443 + if (unlikely(!au_warn_loopback_array))
24449 +void au_loopback_fin(void)
24451 + if (backing_file_func)
24452 + symbol_put(loop_backing_file);
24453 + au_kfree_try_rcu(au_warn_loopback_array);
24455 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24456 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 08:00:00.000000000 +0800
24457 +++ linux/fs/aufs/loop.h 2019-07-11 21:21:54.382384486 +0800
24459 +/* SPDX-License-Identifier: GPL-2.0 */
24461 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24463 + * This program, aufs is free software; you can redistribute it and/or modify
24464 + * it under the terms of the GNU General Public License as published by
24465 + * the Free Software Foundation; either version 2 of the License, or
24466 + * (at your option) any later version.
24468 + * This program is distributed in the hope that it will be useful,
24469 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24470 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24471 + * GNU General Public License for more details.
24473 + * You should have received a copy of the GNU General Public License
24474 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24478 + * support for loopback mount as a branch
24481 +#ifndef __AUFS_LOOP_H__
24482 +#define __AUFS_LOOP_H__
24487 +struct super_block;
24489 +#ifdef CONFIG_AUFS_BDEV_LOOP
24490 +/* drivers/block/loop.c */
24491 +struct file *loop_backing_file(struct super_block *sb);
24494 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24495 +int au_test_loopback_kthread(void);
24496 +void au_warn_loopback(struct super_block *h_sb);
24498 +int au_loopback_init(void);
24499 +void au_loopback_fin(void);
24501 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24503 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24504 + struct dentry *h_adding)
24505 +AuStubInt0(au_test_loopback_kthread, void)
24506 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24508 +AuStubInt0(au_loopback_init, void)
24509 +AuStubVoid(au_loopback_fin, void)
24510 +#endif /* BLK_DEV_LOOP */
24512 +#endif /* __KERNEL__ */
24513 +#endif /* __AUFS_LOOP_H__ */
24514 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24515 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 08:00:00.000000000 +0800
24516 +++ linux/fs/aufs/magic.mk 2019-07-11 21:21:54.382384486 +0800
24518 +# SPDX-License-Identifier: GPL-2.0
24520 +# defined in ${srctree}/fs/fuse/inode.c
24522 +ifdef CONFIG_FUSE_FS
24523 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24526 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24528 +ifdef CONFIG_XFS_FS
24529 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24532 +# defined in ${srctree}/fs/configfs/mount.c
24534 +ifdef CONFIG_CONFIGFS_FS
24535 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24538 +# defined in ${srctree}/fs/ubifs/ubifs.h
24540 +ifdef CONFIG_UBIFS_FS
24541 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24544 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24546 +ifdef CONFIG_HFSPLUS_FS
24547 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24549 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24550 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 08:00:00.000000000 +0800
24551 +++ linux/fs/aufs/Makefile 2019-07-11 21:21:54.379051070 +0800
24553 +# SPDX-License-Identifier: GPL-2.0
24555 +include ${src}/magic.mk
24556 +ifeq (${CONFIG_AUFS_FS},m)
24557 +include ${src}/conf.mk
24559 +-include ${src}/priv_def.mk
24561 +# cf. include/linux/kernel.h
24563 +ccflags-y += -DDEBUG
24564 +# sparse requires the full pathname
24566 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24568 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24571 +obj-$(CONFIG_AUFS_FS) += aufs.o
24572 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24573 + wkq.o vfsub.o dcsub.o \
24574 + cpup.o whout.o wbr_policy.o \
24575 + dinfo.o dentry.o \
24577 + finfo.o file.o f_op.o \
24579 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24583 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24584 +aufs-$(CONFIG_SYSFS) += sysfs.o
24585 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24586 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24587 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24588 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24589 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24590 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24591 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24592 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24593 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24594 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24595 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24596 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24597 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24598 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24599 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24600 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 08:00:00.000000000 +0800
24601 +++ linux/fs/aufs/module.c 2019-07-11 21:21:54.382384486 +0800
24603 +// SPDX-License-Identifier: GPL-2.0
24605 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24607 + * This program, aufs is free software; you can redistribute it and/or modify
24608 + * it under the terms of the GNU General Public License as published by
24609 + * the Free Software Foundation; either version 2 of the License, or
24610 + * (at your option) any later version.
24612 + * This program is distributed in the hope that it will be useful,
24613 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24614 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24615 + * GNU General Public License for more details.
24617 + * You should have received a copy of the GNU General Public License
24618 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24622 + * module global variables and operations
24625 +#include <linux/module.h>
24626 +#include <linux/seq_file.h>
24629 +/* shrinkable realloc */
24630 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24638 +#if 0 /* unused */
24645 + AuDebugOn(!new_sz);
24648 + diff = au_kmidx_sub(sz, new_sz);
24654 + /* expand or SLOB */
24655 + p = krealloc(p, new_sz, gfp);
24656 + else if (new_sz < sz && may_shrink) {
24660 + q = kmalloc(new_sz, gfp);
24663 + memcpy(q, p, new_sz);
24664 + au_kfree_try_rcu(p);
24675 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24678 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24679 + if (p && new_sz > nused)
24680 + memset(p + nused, 0, new_sz - nused);
24684 +/* ---------------------------------------------------------------------- */
24688 +struct kmem_cache *au_cache[AuCache_Last];
24690 +static void au_cache_fin(void)
24695 + * Make sure all delayed rcu free inodes are flushed before we
24700 + /* excluding AuCache_HNOTIFY */
24701 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24702 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24703 + kmem_cache_destroy(au_cache[i]);
24704 + au_cache[i] = NULL;
24708 +static int __init au_cache_init(void)
24710 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24711 + if (au_cache[AuCache_DINFO])
24712 + /* SLAB_DESTROY_BY_RCU */
24713 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24714 + au_icntnr_init_once);
24715 + if (au_cache[AuCache_ICNTNR])
24716 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24717 + au_fi_init_once);
24718 + if (au_cache[AuCache_FINFO])
24719 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24720 + if (au_cache[AuCache_VDIR])
24721 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24722 + if (au_cache[AuCache_DEHSTR])
24729 +/* ---------------------------------------------------------------------- */
24731 +int au_dir_roflags;
24733 +#ifdef CONFIG_AUFS_SBILIST
24735 + * iterate_supers_type() doesn't protect us from
24736 + * remounting (branch management)
24738 +struct hlist_bl_head au_sbilist;
24742 + * functions for module interface.
24744 +MODULE_LICENSE("GPL");
24745 +/* MODULE_LICENSE("GPL v2"); */
24746 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24747 +MODULE_DESCRIPTION(AUFS_NAME
24748 + " -- Advanced multi layered unification filesystem");
24749 +MODULE_VERSION(AUFS_VERSION);
24750 +MODULE_ALIAS_FS(AUFS_NAME);
24752 +/* this module parameter has no meaning when SYSFS is disabled */
24753 +int sysaufs_brs = 1;
24754 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24755 +module_param_named(brs, sysaufs_brs, int, 0444);
24757 +/* this module parameter has no meaning when USER_NS is disabled */
24759 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24760 +module_param_named(allow_userns, au_userns, bool, 0444);
24762 +/* ---------------------------------------------------------------------- */
24764 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24766 +int au_seq_path(struct seq_file *seq, struct path *path)
24770 + err = seq_path(seq, path, au_esc_chars);
24779 +/* ---------------------------------------------------------------------- */
24781 +static int __init aufs_init(void)
24786 + p = au_esc_chars;
24787 + for (i = 1; i <= ' '; i++)
24793 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24795 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24796 + for (i = 0; i < AuIop_Last; i++)
24797 + aufs_iop_nogetattr[i].getattr = NULL;
24799 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24801 + au_sbilist_init();
24802 + sysaufs_brs_init();
24805 + err = sysaufs_init();
24806 + if (unlikely(err))
24808 + err = dbgaufs_init();
24809 + if (unlikely(err))
24810 + goto out_sysaufs;
24811 + err = au_procfs_init();
24812 + if (unlikely(err))
24813 + goto out_dbgaufs;
24814 + err = au_wkq_init();
24815 + if (unlikely(err))
24817 + err = au_loopback_init();
24818 + if (unlikely(err))
24820 + err = au_hnotify_init();
24821 + if (unlikely(err))
24822 + goto out_loopback;
24823 + err = au_sysrq_init();
24824 + if (unlikely(err))
24826 + err = au_cache_init();
24827 + if (unlikely(err))
24830 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24831 + err = register_filesystem(&aufs_fs_type);
24832 + if (unlikely(err))
24835 + /* since we define pr_fmt, call printk directly */
24836 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24837 + goto out; /* success */
24844 + au_hnotify_fin();
24846 + au_loopback_fin();
24860 +static void __exit aufs_exit(void)
24862 + unregister_filesystem(&aufs_fs_type);
24865 + au_hnotify_fin();
24866 + au_loopback_fin();
24874 +module_init(aufs_init);
24875 +module_exit(aufs_exit);
24876 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24877 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 08:00:00.000000000 +0800
24878 +++ linux/fs/aufs/module.h 2019-07-11 21:21:54.382384486 +0800
24880 +/* SPDX-License-Identifier: GPL-2.0 */
24882 + * Copyright (C) 2005-2019 Junjiro R. Okajima
24884 + * This program, aufs is free software; you can redistribute it and/or modify
24885 + * it under the terms of the GNU General Public License as published by
24886 + * the Free Software Foundation; either version 2 of the License, or
24887 + * (at your option) any later version.
24889 + * This program is distributed in the hope that it will be useful,
24890 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24891 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24892 + * GNU General Public License for more details.
24894 + * You should have received a copy of the GNU General Public License
24895 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24899 + * module initialization and module-global
24902 +#ifndef __AUFS_MODULE_H__
24903 +#define __AUFS_MODULE_H__
24907 +#include <linux/slab.h>
24908 +#include "debug.h"
24909 +#include "dentry.h"
24912 +#include "inode.h"
24917 +/* module parameters */
24918 +extern int sysaufs_brs;
24919 +extern bool au_userns;
24921 +/* ---------------------------------------------------------------------- */
24923 +extern int au_dir_roflags;
24925 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24926 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24930 + * Comparing the size of the object with sizeof(struct rcu_head)
24931 + * case 1: object is always larger
24932 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24933 + * case 2: object is always smaller
24934 + * --> au_kfree_small()
24935 + * case 3: object can be any size
24936 + * --> au_kfree_try_rcu()
24939 +static inline void au_kfree_do_rcu(const void *p)
24942 + struct rcu_head rcu;
24943 + } *a = (void *)p;
24945 + kfree_rcu(a, rcu);
24948 +#define au_kfree_rcu(_p) do { \
24949 + typeof(_p) p = (_p); \
24950 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24952 + au_kfree_do_rcu(p); \
24955 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24956 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24958 +static inline void au_kfree_try_rcu(const void *p)
24962 + if (au_kfree_sz_test(p))
24963 + au_kfree_do_rcu(p);
24968 +static inline void au_kfree_small(const void *p)
24972 + AuDebugOn(au_kfree_sz_test(p));
24976 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24978 +#ifndef CONFIG_SLOB
24979 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24981 + return -1; /* SLOB is untested */
24985 +int au_seq_path(struct seq_file *seq, struct path *path);
24987 +#ifdef CONFIG_PROC_FS
24989 +int __init au_procfs_init(void);
24990 +void au_procfs_fin(void);
24992 +AuStubInt0(au_procfs_init, void);
24993 +AuStubVoid(au_procfs_fin, void);
24996 +/* ---------------------------------------------------------------------- */
25005 + AuCache_HNOTIFY, /* must be last */
25009 +extern struct kmem_cache *au_cache[AuCache_Last];
25011 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
25012 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
25013 +#define AuCacheCtor(type, ctor) \
25014 + kmem_cache_create(#type, sizeof(struct type), \
25015 + __alignof__(struct type), AuCacheFlags, ctor)
25017 +#define AuCacheFuncs(name, index) \
25018 + static inline struct au_##name *au_cache_alloc_##name(void) \
25019 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
25020 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
25021 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
25023 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
25024 + { void *p = rcu; \
25025 + p -= offsetof(struct au_##name, rcu); \
25026 + kmem_cache_free(au_cache[AuCache_##index], p); } \
25027 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
25028 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
25029 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
25031 + static inline void au_cache_free_##name(struct au_##name *p) \
25032 + { /* au_cache_free_##name##_norcu(p); */ \
25033 + au_cache_free_##name##_rcu(p); }
25035 +AuCacheFuncs(dinfo, DINFO);
25036 +AuCacheFuncs(icntnr, ICNTNR);
25037 +AuCacheFuncs(finfo, FINFO);
25038 +AuCacheFuncs(vdir, VDIR);
25039 +AuCacheFuncs(vdir_dehstr, DEHSTR);
25040 +#ifdef CONFIG_AUFS_HNOTIFY
25041 +AuCacheFuncs(hnotify, HNOTIFY);
25044 +#endif /* __KERNEL__ */
25045 +#endif /* __AUFS_MODULE_H__ */
25046 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
25047 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 08:00:00.000000000 +0800
25048 +++ linux/fs/aufs/mvdown.c 2019-07-11 21:21:54.382384486 +0800
25050 +// SPDX-License-Identifier: GPL-2.0
25052 + * Copyright (C) 2011-2019 Junjiro R. Okajima
25054 + * This program, aufs is free software; you can redistribute it and/or modify
25055 + * it under the terms of the GNU General Public License as published by
25056 + * the Free Software Foundation; either version 2 of the License, or
25057 + * (at your option) any later version.
25059 + * This program is distributed in the hope that it will be useful,
25060 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25061 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25062 + * GNU General Public License for more details.
25064 + * You should have received a copy of the GNU General Public License
25065 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25069 + * move-down, opposite of copy-up
25074 +struct au_mvd_args {
25076 + struct super_block *h_sb;
25077 + struct dentry *h_parent;
25078 + struct au_hinode *hdir;
25079 + struct inode *h_dir, *h_inode;
25080 + struct au_pin pin;
25081 + } info[AUFS_MVDOWN_NARRAY];
25083 + struct aufs_mvdown mvdown;
25084 + struct dentry *dentry, *parent;
25085 + struct inode *inode, *dir;
25086 + struct super_block *sb;
25087 + aufs_bindex_t bopq, bwh, bfound;
25088 + unsigned char rename_lock;
25091 +#define mvd_errno mvdown.au_errno
25092 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
25093 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
25094 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
25095 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
25097 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
25098 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
25099 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
25100 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
25101 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
25102 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
25104 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
25105 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
25106 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
25107 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
25108 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
25109 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
25111 +#define AU_MVD_PR(flag, ...) do { \
25113 + pr_err(__VA_ARGS__); \
25116 +static int find_lower_writable(struct au_mvd_args *a)
25118 + struct super_block *sb;
25119 + aufs_bindex_t bindex, bbot;
25120 + struct au_branch *br;
25123 + bindex = a->mvd_bsrc;
25124 + bbot = au_sbbot(sb);
25125 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
25126 + for (bindex++; bindex <= bbot; bindex++) {
25127 + br = au_sbr(sb, bindex);
25128 + if (au_br_fhsm(br->br_perm)
25129 + && !sb_rdonly(au_br_sb(br)))
25132 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
25133 + for (bindex++; bindex <= bbot; bindex++) {
25134 + br = au_sbr(sb, bindex);
25135 + if (!au_br_rdonly(br))
25139 + for (bindex++; bindex <= bbot; bindex++) {
25140 + br = au_sbr(sb, bindex);
25141 + if (!sb_rdonly(au_br_sb(br))) {
25142 + if (au_br_rdonly(br))
25144 + |= AUFS_MVDOWN_ROLOWER_R;
25152 +/* make the parent dir on bdst */
25153 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25158 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25159 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25160 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25161 + a->mvd_h_dst_parent = NULL;
25162 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25163 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25164 + if (!a->mvd_h_dst_parent) {
25165 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25166 + if (unlikely(err)) {
25167 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25170 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25178 +/* lock them all */
25179 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25182 + struct dentry *h_trap;
25184 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25185 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25186 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25187 + au_opt_udba(a->sb),
25188 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25190 + if (unlikely(err)) {
25191 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25195 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25196 + a->rename_lock = 0;
25197 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25198 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25199 + au_opt_udba(a->sb),
25200 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25201 + err = au_do_pin(&a->mvd_pin_src);
25203 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25204 + if (unlikely(err)) {
25205 + AU_MVD_PR(dmsg, "pin_src failed\n");
25208 + goto out; /* success */
25211 + a->rename_lock = 1;
25212 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25213 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25214 + au_opt_udba(a->sb),
25215 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25217 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25218 + if (unlikely(err)) {
25219 + AU_MVD_PR(dmsg, "pin_src failed\n");
25220 + au_pin_hdir_lock(&a->mvd_pin_dst);
25223 + au_pin_hdir_unlock(&a->mvd_pin_src);
25224 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25225 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25227 + err = (h_trap != a->mvd_h_src_parent);
25229 + err = (h_trap != a->mvd_h_dst_parent);
25231 + BUG_ON(err); /* it should never happen */
25232 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25235 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25236 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25237 + au_pin_hdir_lock(&a->mvd_pin_src);
25238 + au_unpin(&a->mvd_pin_src);
25239 + au_pin_hdir_lock(&a->mvd_pin_dst);
25242 + goto out; /* success */
25245 + au_unpin(&a->mvd_pin_dst);
25251 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25253 + if (!a->rename_lock)
25254 + au_unpin(&a->mvd_pin_src);
25256 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25257 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25258 + au_pin_hdir_lock(&a->mvd_pin_src);
25259 + au_unpin(&a->mvd_pin_src);
25260 + au_pin_hdir_lock(&a->mvd_pin_dst);
25262 + au_unpin(&a->mvd_pin_dst);
25265 +/* copy-down the file */
25266 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25269 + struct au_cp_generic cpg = {
25270 + .dentry = a->dentry,
25271 + .bdst = a->mvd_bdst,
25272 + .bsrc = a->mvd_bsrc,
25274 + .pin = &a->mvd_pin_dst,
25275 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25278 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25279 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25280 + au_fset_cpup(cpg.flags, OVERWRITE);
25281 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25282 + au_fset_cpup(cpg.flags, RWDST);
25283 + err = au_sio_cpdown_simple(&cpg);
25284 + if (unlikely(err))
25285 + AU_MVD_PR(dmsg, "cpdown failed\n");
25292 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25295 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25298 + struct path h_path;
25299 + struct au_branch *br;
25300 + struct inode *delegated;
25302 + br = au_sbr(a->sb, a->mvd_bdst);
25303 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25304 + err = PTR_ERR(h_path.dentry);
25305 + if (IS_ERR(h_path.dentry)) {
25306 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25311 + if (d_is_positive(h_path.dentry)) {
25312 + h_path.mnt = au_br_mnt(br);
25313 + delegated = NULL;
25314 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25315 + &delegated, /*force*/0);
25316 + if (unlikely(err == -EWOULDBLOCK)) {
25317 + pr_warn("cannot retry for NFSv4 delegation"
25318 + " for an internal unlink\n");
25321 + if (unlikely(err))
25322 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25324 + dput(h_path.dentry);
25332 + * unlink the topmost h_dentry
25334 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25337 + struct path h_path;
25338 + struct inode *delegated;
25340 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25341 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25342 + delegated = NULL;
25343 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25344 + if (unlikely(err == -EWOULDBLOCK)) {
25345 + pr_warn("cannot retry for NFSv4 delegation"
25346 + " for an internal unlink\n");
25349 + if (unlikely(err))
25350 + AU_MVD_PR(dmsg, "unlink failed\n");
25356 +/* Since mvdown succeeded, we ignore an error of this function */
25357 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25360 + struct au_branch *br;
25362 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25363 + br = au_sbr(a->sb, a->mvd_bsrc);
25364 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25366 + br = au_sbr(a->sb, a->mvd_bdst);
25367 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25368 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25371 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25373 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25377 + * copy-down the file and unlink the bsrc file.
25378 + * - unlink the bdst whout if exist
25379 + * - copy-down the file (with whtmp name and rename)
25380 + * - unlink the bsrc file
25382 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25386 + err = au_do_mkdir(dmsg, a);
25388 + err = au_do_lock(dmsg, a);
25389 + if (unlikely(err))
25393 + * do not revert the activities we made on bdst since they should be
25394 + * harmless in aufs.
25397 + err = au_do_cpdown(dmsg, a);
25399 + err = au_do_unlink_wh(dmsg, a);
25400 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25401 + err = au_do_unlink(dmsg, a);
25402 + if (unlikely(err))
25405 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25406 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25407 + if (find_lower_writable(a) < 0)
25408 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25410 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25411 + au_do_stfs(dmsg, a);
25413 + /* maintain internal array */
25414 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25415 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25416 + au_set_dbtop(a->dentry, a->mvd_bdst);
25417 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25418 + au_set_ibtop(a->inode, a->mvd_bdst);
25420 + /* hide the lower */
25421 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25422 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25423 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25424 + au_set_ibbot(a->inode, a->mvd_bsrc);
25426 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25427 + au_set_dbbot(a->dentry, a->mvd_bdst);
25428 + if (au_ibbot(a->inode) < a->mvd_bdst)
25429 + au_set_ibbot(a->inode, a->mvd_bdst);
25432 + au_do_unlock(dmsg, a);
25438 +/* ---------------------------------------------------------------------- */
25440 +/* make sure the file is idle */
25441 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25443 + int err, plinked;
25446 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25447 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25448 + && au_dcount(a->dentry) == 1
25449 + && atomic_read(&a->inode->i_count) == 1
25450 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25451 + && (!plinked || !au_plink_test(a->inode))
25452 + && a->inode->i_nlink == 1)
25457 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25458 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25459 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25460 + a->mvd_h_src_inode->i_nlink,
25461 + plinked, plinked ? au_plink_test(a->inode) : 0);
25468 +/* make sure the parent dir is fine */
25469 +static int au_mvd_args_parent(const unsigned char dmsg,
25470 + struct au_mvd_args *a)
25473 + aufs_bindex_t bindex;
25476 + if (unlikely(au_alive_dir(a->parent))) {
25478 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25482 + a->bopq = au_dbdiropq(a->parent);
25483 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25484 + AuDbg("b%d\n", bindex);
25485 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25486 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25488 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25489 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25490 + a->bopq, a->mvd_bdst);
25498 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25499 + struct au_mvd_args *a)
25502 + struct au_dinfo *dinfo, *tmp;
25504 + /* lookup the next lower positive entry */
25506 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25507 + if (unlikely(!tmp))
25512 + dinfo = au_di(a->dentry);
25513 + au_di_cp(tmp, dinfo);
25514 + au_di_swap(tmp, dinfo);
25516 + /* returns the number of positive dentries */
25517 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25518 + /* AuLkup_IGNORE_PERM */ 0);
25520 + a->bwh = au_dbwh(a->dentry);
25521 + else if (err > 0)
25522 + a->bfound = au_dbtop(a->dentry);
25524 + au_di_swap(tmp, dinfo);
25525 + au_rw_write_unlock(&tmp->di_rwsem);
25527 + if (unlikely(err < 0))
25528 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25531 + * here, we have these cases.
25533 + * no positive dentry under bsrc. there are more sub-cases.
25535 + * there no whiteout, we can safely move-down.
25538 + * bsrc < bwh && bwh < bdst
25539 + * there is a whiteout on RO branch. cannot proceed.
25541 + * there is a whiteout on the RW target branch. it should
25544 + * there is a whiteout somewhere unrelated branch.
25545 + * -1 < bfound && bfound <= bsrc
25548 + * found, but it is on RO branch between bsrc and bdst. cannot
25551 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25554 + * found, after we create the file on bdst, it will be hidden.
25557 + AuDebugOn(a->bfound == -1
25559 + && a->bwh <= a->mvd_bsrc);
25560 + AuDebugOn(-1 < a->bfound
25561 + && a->bfound <= a->mvd_bsrc);
25564 + if (a->bfound == -1
25565 + && a->mvd_bsrc < a->bwh
25567 + && a->bwh < a->mvd_bdst) {
25568 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25569 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25570 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25572 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25573 + a->mvd_errno = EAU_MVDOWN_UPPER;
25574 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25575 + a->mvd_bdst, a->bfound);
25579 + err = 0; /* success */
25586 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25591 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25592 + && a->bfound == a->mvd_bdst)
25598 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25601 + struct au_branch *br;
25604 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25608 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25609 + a->mvd_bsrc = au_ibtop(a->inode);
25611 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25612 + if (unlikely(a->mvd_bsrc < 0
25613 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25614 + || au_dbbot(a->dentry) < a->mvd_bsrc
25615 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25616 + || (a->mvd_bsrc < au_ibtop(a->inode)
25617 + || au_ibbot(a->inode) < a->mvd_bsrc
25618 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25619 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25620 + AU_MVD_PR(dmsg, "no upper\n");
25624 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25625 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25626 + AU_MVD_PR(dmsg, "on the bottom\n");
25629 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25630 + br = au_sbr(a->sb, a->mvd_bsrc);
25631 + err = au_br_rdonly(br);
25632 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25633 + if (unlikely(err))
25635 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25636 + || IS_APPEND(a->mvd_h_src_inode))) {
25638 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25644 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25645 + a->mvd_bdst = find_lower_writable(a);
25646 + if (unlikely(a->mvd_bdst < 0)) {
25647 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25648 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25652 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25653 + if (unlikely(a->mvd_bdst < 0
25654 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25655 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25656 + AU_MVD_PR(dmsg, "no lower brid\n");
25661 + err = au_mvd_args_busy(dmsg, a);
25663 + err = au_mvd_args_parent(dmsg, a);
25665 + err = au_mvd_args_intermediate(dmsg, a);
25667 + err = au_mvd_args_exist(dmsg, a);
25669 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25676 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25679 + unsigned char dmsg;
25680 + struct au_mvd_args *args;
25681 + struct inode *inode;
25683 + inode = d_inode(dentry);
25685 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25689 + args = kmalloc(sizeof(*args), GFP_NOFS);
25690 + if (unlikely(!args))
25693 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25695 + /* VERIFY_WRITE */
25696 + err = !access_ok(uarg, sizeof(*uarg));
25697 + if (unlikely(err)) {
25702 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25703 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25704 + args->mvdown.au_errno = 0;
25705 + args->dentry = dentry;
25706 + args->inode = inode;
25707 + args->sb = dentry->d_sb;
25710 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25711 + args->parent = dget_parent(dentry);
25712 + args->dir = d_inode(args->parent);
25713 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25714 + dput(args->parent);
25715 + if (unlikely(args->parent != dentry->d_parent)) {
25716 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25720 + inode_lock_nested(inode, I_MUTEX_CHILD);
25721 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25722 + if (unlikely(err))
25725 + di_write_lock_parent(args->parent);
25726 + err = au_mvd_args(dmsg, args);
25727 + if (unlikely(err))
25730 + err = au_do_mvdown(dmsg, args);
25731 + if (unlikely(err))
25734 + au_cpup_attr_timesizes(args->dir);
25735 + au_cpup_attr_timesizes(inode);
25736 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25737 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25738 + /* au_digen_dec(dentry); */
25741 + di_write_unlock(args->parent);
25742 + aufs_read_unlock(dentry, AuLock_DW);
25744 + inode_unlock(inode);
25746 + inode_unlock(args->dir);
25748 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25751 + au_kfree_rcu(args);
25756 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25757 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 08:00:00.000000000 +0800
25758 +++ linux/fs/aufs/opts.c 2019-07-11 21:21:54.382384486 +0800
25760 +// SPDX-License-Identifier: GPL-2.0
25762 + * Copyright (C) 2005-2019 Junjiro R. Okajima
25764 + * This program, aufs is free software; you can redistribute it and/or modify
25765 + * it under the terms of the GNU General Public License as published by
25766 + * the Free Software Foundation; either version 2 of the License, or
25767 + * (at your option) any later version.
25769 + * This program is distributed in the hope that it will be useful,
25770 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25771 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25772 + * GNU General Public License for more details.
25774 + * You should have received a copy of the GNU General Public License
25775 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25779 + * mount options/flags
25782 +#include <linux/namei.h>
25783 +#include <linux/types.h> /* a distribution requires */
25784 +#include <linux/parser.h>
25787 +/* ---------------------------------------------------------------------- */
25791 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25792 + Opt_idel, Opt_imod,
25793 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25794 + Opt_rdblk_def, Opt_rdhash_def,
25795 + Opt_xino, Opt_noxino,
25796 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25797 + Opt_trunc_xino_path, Opt_itrunc_xino,
25798 + Opt_trunc_xib, Opt_notrunc_xib,
25799 + Opt_shwh, Opt_noshwh,
25800 + Opt_plink, Opt_noplink, Opt_list_plink,
25802 + Opt_dio, Opt_nodio,
25803 + Opt_diropq_a, Opt_diropq_w,
25804 + Opt_warn_perm, Opt_nowarn_perm,
25805 + Opt_wbr_copyup, Opt_wbr_create,
25807 + Opt_verbose, Opt_noverbose,
25808 + Opt_sum, Opt_nosum, Opt_wsum,
25809 + Opt_dirperm1, Opt_nodirperm1,
25810 + Opt_dirren, Opt_nodirren,
25811 + Opt_acl, Opt_noacl,
25812 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25815 +static match_table_t options = {
25816 + {Opt_br, "br=%s"},
25817 + {Opt_br, "br:%s"},
25819 + {Opt_add, "add=%d:%s"},
25820 + {Opt_add, "add:%d:%s"},
25821 + {Opt_add, "ins=%d:%s"},
25822 + {Opt_add, "ins:%d:%s"},
25823 + {Opt_append, "append=%s"},
25824 + {Opt_append, "append:%s"},
25825 + {Opt_prepend, "prepend=%s"},
25826 + {Opt_prepend, "prepend:%s"},
25828 + {Opt_del, "del=%s"},
25829 + {Opt_del, "del:%s"},
25830 + /* {Opt_idel, "idel:%d"}, */
25831 + {Opt_mod, "mod=%s"},
25832 + {Opt_mod, "mod:%s"},
25833 + /* {Opt_imod, "imod:%d:%s"}, */
25835 + {Opt_dirwh, "dirwh=%d"},
25837 + {Opt_xino, "xino=%s"},
25838 + {Opt_noxino, "noxino"},
25839 + {Opt_trunc_xino, "trunc_xino"},
25840 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25841 + {Opt_notrunc_xino, "notrunc_xino"},
25842 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25843 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25844 + /* {Opt_zxino, "zxino=%s"}, */
25845 + {Opt_trunc_xib, "trunc_xib"},
25846 + {Opt_notrunc_xib, "notrunc_xib"},
25848 +#ifdef CONFIG_PROC_FS
25849 + {Opt_plink, "plink"},
25851 + {Opt_ignore_silent, "plink"},
25854 + {Opt_noplink, "noplink"},
25856 +#ifdef CONFIG_AUFS_DEBUG
25857 + {Opt_list_plink, "list_plink"},
25860 + {Opt_udba, "udba=%s"},
25862 + {Opt_dio, "dio"},
25863 + {Opt_nodio, "nodio"},
25865 +#ifdef CONFIG_AUFS_DIRREN
25866 + {Opt_dirren, "dirren"},
25867 + {Opt_nodirren, "nodirren"},
25869 + {Opt_ignore, "dirren"},
25870 + {Opt_ignore_silent, "nodirren"},
25873 +#ifdef CONFIG_AUFS_FHSM
25874 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25876 + {Opt_ignore, "fhsm_sec=%d"},
25879 + {Opt_diropq_a, "diropq=always"},
25880 + {Opt_diropq_a, "diropq=a"},
25881 + {Opt_diropq_w, "diropq=whiteouted"},
25882 + {Opt_diropq_w, "diropq=w"},
25884 + {Opt_warn_perm, "warn_perm"},
25885 + {Opt_nowarn_perm, "nowarn_perm"},
25887 + /* keep them temporary */
25888 + {Opt_ignore_silent, "nodlgt"},
25889 + {Opt_ignore, "clean_plink"},
25891 +#ifdef CONFIG_AUFS_SHWH
25892 + {Opt_shwh, "shwh"},
25894 + {Opt_noshwh, "noshwh"},
25896 + {Opt_dirperm1, "dirperm1"},
25897 + {Opt_nodirperm1, "nodirperm1"},
25899 + {Opt_verbose, "verbose"},
25900 + {Opt_verbose, "v"},
25901 + {Opt_noverbose, "noverbose"},
25902 + {Opt_noverbose, "quiet"},
25903 + {Opt_noverbose, "q"},
25904 + {Opt_noverbose, "silent"},
25906 + {Opt_sum, "sum"},
25907 + {Opt_nosum, "nosum"},
25908 + {Opt_wsum, "wsum"},
25910 + {Opt_rdcache, "rdcache=%d"},
25911 + {Opt_rdblk, "rdblk=%d"},
25912 + {Opt_rdblk_def, "rdblk=def"},
25913 + {Opt_rdhash, "rdhash=%d"},
25914 + {Opt_rdhash_def, "rdhash=def"},
25916 + {Opt_wbr_create, "create=%s"},
25917 + {Opt_wbr_create, "create_policy=%s"},
25918 + {Opt_wbr_copyup, "cpup=%s"},
25919 + {Opt_wbr_copyup, "copyup=%s"},
25920 + {Opt_wbr_copyup, "copyup_policy=%s"},
25922 + /* generic VFS flag */
25923 +#ifdef CONFIG_FS_POSIX_ACL
25924 + {Opt_acl, "acl"},
25925 + {Opt_noacl, "noacl"},
25927 + {Opt_ignore, "acl"},
25928 + {Opt_ignore_silent, "noacl"},
25931 + /* internal use for the scripts */
25932 + {Opt_ignore_silent, "si=%s"},
25934 + {Opt_br, "dirs=%s"},
25935 + {Opt_ignore, "debug=%d"},
25936 + {Opt_ignore, "delete=whiteout"},
25937 + {Opt_ignore, "delete=all"},
25938 + {Opt_ignore, "imap=%s"},
25940 + /* temporary workaround, due to old mount(8)? */
25941 + {Opt_ignore_silent, "relatime"},
25946 +/* ---------------------------------------------------------------------- */
25948 +static const char *au_parser_pattern(int val, match_table_t tbl)
25950 + struct match_token *p;
25953 + while (p->pattern) {
25954 + if (p->token == val)
25955 + return p->pattern;
25962 +static const char *au_optstr(int *val, match_table_t tbl)
25964 + struct match_token *p;
25971 + while (p->pattern) {
25973 + && (v & p->token) == p->token) {
25974 + *val &= ~p->token;
25975 + return p->pattern;
25984 +/* ---------------------------------------------------------------------- */
25986 +static match_table_t brperm = {
25987 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25988 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25989 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25993 +static match_table_t brattr = {
25995 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25996 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25997 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25998 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25999 +#ifdef CONFIG_AUFS_FHSM
26000 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26002 +#ifdef CONFIG_AUFS_XATTR
26003 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26004 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26005 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26006 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26007 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26008 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26011 + /* ro/rr branch */
26012 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26015 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26016 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26021 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26028 + p = strchr(str, '+');
26031 + v = match_token(str, table, args);
26033 + if (v & AuBrAttr_CMOO_Mask)
26034 + attr &= ~AuBrAttr_CMOO_Mask;
26039 + pr_warn("ignored branch attribute %s\n", str);
26049 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26057 + p = au_optstr(&perm, brattr);
26060 + memcpy(q, p, sz + 1);
26066 + p = au_optstr(&perm, brattr);
26070 + memcpy(q, p, sz + 1);
26076 + return q - str->a;
26079 +static int noinline_for_stack br_perm_val(char *perm)
26081 + int val, bad, sz;
26083 + substring_t args[MAX_OPT_ARGS];
26084 + au_br_perm_str_t attr;
26086 + p = strchr(perm, '+');
26089 + val = match_token(perm, brperm, args);
26093 + pr_warn("ignored branch permission %s\n", perm);
26094 + val = AuBrPerm_RO;
26100 + val |= br_attr_val(p + 1, brattr, args);
26103 + switch (val & AuBrPerm_Mask) {
26104 + case AuBrPerm_RO:
26105 + case AuBrPerm_RR:
26106 + bad = val & AuBrWAttr_Mask;
26107 + val &= ~AuBrWAttr_Mask;
26109 + case AuBrPerm_RW:
26110 + bad = val & AuBrRAttr_Mask;
26111 + val &= ~AuBrRAttr_Mask;
26116 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26117 + * does not treat it as an error, just warning.
26118 + * this is a tiny guard for the user operation.
26120 + if (val & AuBrAttr_UNPIN) {
26121 + bad |= AuBrAttr_UNPIN;
26122 + val &= ~AuBrAttr_UNPIN;
26125 + if (unlikely(bad)) {
26126 + sz = au_do_optstr_br_attr(&attr, bad);
26128 + pr_warn("ignored branch attribute %s\n", attr.a);
26135 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26137 + au_br_perm_str_t attr;
26143 + p = au_optstr(&perm, brperm);
26144 + AuDebugOn(!p || !*p);
26146 + memcpy(q, p, sz + 1);
26149 + sz = au_do_optstr_br_attr(&attr, perm);
26152 + memcpy(q, attr.a, sz + 1);
26155 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26158 +/* ---------------------------------------------------------------------- */
26160 +static match_table_t udbalevel = {
26161 + {AuOpt_UDBA_REVAL, "reval"},
26162 + {AuOpt_UDBA_NONE, "none"},
26163 +#ifdef CONFIG_AUFS_HNOTIFY
26164 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26165 +#ifdef CONFIG_AUFS_HFSNOTIFY
26166 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26172 +static int noinline_for_stack udba_val(char *str)
26174 + substring_t args[MAX_OPT_ARGS];
26176 + return match_token(str, udbalevel, args);
26179 +const char *au_optstr_udba(int udba)
26181 + return au_parser_pattern(udba, udbalevel);
26184 +/* ---------------------------------------------------------------------- */
26186 +static match_table_t au_wbr_create_policy = {
26187 + {AuWbrCreate_TDP, "tdp"},
26188 + {AuWbrCreate_TDP, "top-down-parent"},
26189 + {AuWbrCreate_RR, "rr"},
26190 + {AuWbrCreate_RR, "round-robin"},
26191 + {AuWbrCreate_MFS, "mfs"},
26192 + {AuWbrCreate_MFS, "most-free-space"},
26193 + {AuWbrCreate_MFSV, "mfs:%d"},
26194 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26196 + /* top-down regardless the parent, and then mfs */
26197 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26198 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26200 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26201 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26202 + {AuWbrCreate_PMFS, "pmfs"},
26203 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26204 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26205 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26210 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26211 + struct au_opt_wbr_create *create)
26214 + unsigned long long ull;
26217 + if (!match_u64(arg, &ull))
26218 + create->mfsrr_watermark = ull;
26220 + pr_err("bad integer in %s\n", str);
26227 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26228 + struct au_opt_wbr_create *create)
26233 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26234 + create->mfs_second = n;
26236 + pr_err("bad integer in %s\n", str);
26243 +static int noinline_for_stack
26244 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26247 + substring_t args[MAX_OPT_ARGS];
26249 + err = match_token(str, au_wbr_create_policy, args);
26250 + create->wbr_create = err;
26252 + case AuWbrCreate_MFSRRV:
26253 + case AuWbrCreate_TDMFSV:
26254 + case AuWbrCreate_PMFSRRV:
26255 + e = au_wbr_mfs_wmark(&args[0], str, create);
26257 + e = au_wbr_mfs_sec(&args[1], str, create);
26261 + case AuWbrCreate_MFSRR:
26262 + case AuWbrCreate_TDMFS:
26263 + case AuWbrCreate_PMFSRR:
26264 + e = au_wbr_mfs_wmark(&args[0], str, create);
26265 + if (unlikely(e)) {
26270 + case AuWbrCreate_MFS:
26271 + case AuWbrCreate_PMFS:
26272 + create->mfs_second = AUFS_MFS_DEF_SEC;
26274 + case AuWbrCreate_MFSV:
26275 + case AuWbrCreate_PMFSV:
26276 + e = au_wbr_mfs_sec(&args[0], str, create);
26285 +const char *au_optstr_wbr_create(int wbr_create)
26287 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26290 +static match_table_t au_wbr_copyup_policy = {
26291 + {AuWbrCopyup_TDP, "tdp"},
26292 + {AuWbrCopyup_TDP, "top-down-parent"},
26293 + {AuWbrCopyup_BUP, "bup"},
26294 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26295 + {AuWbrCopyup_BU, "bu"},
26296 + {AuWbrCopyup_BU, "bottom-up"},
26300 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26302 + substring_t args[MAX_OPT_ARGS];
26304 + return match_token(str, au_wbr_copyup_policy, args);
26307 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26309 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26312 +/* ---------------------------------------------------------------------- */
26314 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26316 +static void dump_opts(struct au_opts *opts)
26318 +#ifdef CONFIG_AUFS_DEBUG
26319 + /* reduce stack space */
26321 + struct au_opt_add *add;
26322 + struct au_opt_del *del;
26323 + struct au_opt_mod *mod;
26324 + struct au_opt_xino *xino;
26325 + struct au_opt_xino_itrunc *xino_itrunc;
26326 + struct au_opt_wbr_create *create;
26328 + struct au_opt *opt;
26331 + while (opt->type != Opt_tail) {
26332 + switch (opt->type) {
26334 + u.add = &opt->add;
26335 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26336 + u.add->bindex, u.add->pathname, u.add->perm,
26337 + u.add->path.dentry);
26341 + u.del = &opt->del;
26342 + AuDbg("del {%s, %p}\n",
26343 + u.del->pathname, u.del->h_path.dentry);
26347 + u.mod = &opt->mod;
26348 + AuDbg("mod {%s, 0x%x, %p}\n",
26349 + u.mod->path, u.mod->perm, u.mod->h_root);
26352 + u.add = &opt->add;
26353 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26354 + u.add->bindex, u.add->pathname, u.add->perm,
26355 + u.add->path.dentry);
26357 + case Opt_prepend:
26358 + u.add = &opt->add;
26359 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26360 + u.add->bindex, u.add->pathname, u.add->perm,
26361 + u.add->path.dentry);
26364 + AuDbg("dirwh %d\n", opt->dirwh);
26366 + case Opt_rdcache:
26367 + AuDbg("rdcache %d\n", opt->rdcache);
26370 + AuDbg("rdblk %u\n", opt->rdblk);
26372 + case Opt_rdblk_def:
26373 + AuDbg("rdblk_def\n");
26376 + AuDbg("rdhash %u\n", opt->rdhash);
26378 + case Opt_rdhash_def:
26379 + AuDbg("rdhash_def\n");
26382 + u.xino = &opt->xino;
26383 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26385 + case Opt_trunc_xino:
26386 + AuLabel(trunc_xino);
26388 + case Opt_notrunc_xino:
26389 + AuLabel(notrunc_xino);
26391 + case Opt_trunc_xino_path:
26392 + case Opt_itrunc_xino:
26393 + u.xino_itrunc = &opt->xino_itrunc;
26394 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26399 + case Opt_trunc_xib:
26400 + AuLabel(trunc_xib);
26402 + case Opt_notrunc_xib:
26403 + AuLabel(notrunc_xib);
26411 + case Opt_dirperm1:
26412 + AuLabel(dirperm1);
26414 + case Opt_nodirperm1:
26415 + AuLabel(nodirperm1);
26420 + case Opt_noplink:
26421 + AuLabel(noplink);
26423 + case Opt_list_plink:
26424 + AuLabel(list_plink);
26427 + AuDbg("udba %d, %s\n",
26428 + opt->udba, au_optstr_udba(opt->udba));
26436 + case Opt_diropq_a:
26437 + AuLabel(diropq_a);
26439 + case Opt_diropq_w:
26440 + AuLabel(diropq_w);
26442 + case Opt_warn_perm:
26443 + AuLabel(warn_perm);
26445 + case Opt_nowarn_perm:
26446 + AuLabel(nowarn_perm);
26448 + case Opt_verbose:
26449 + AuLabel(verbose);
26451 + case Opt_noverbose:
26452 + AuLabel(noverbose);
26463 + case Opt_wbr_create:
26464 + u.create = &opt->wbr_create;
26465 + AuDbg("create %d, %s\n", u.create->wbr_create,
26466 + au_optstr_wbr_create(u.create->wbr_create));
26467 + switch (u.create->wbr_create) {
26468 + case AuWbrCreate_MFSV:
26469 + case AuWbrCreate_PMFSV:
26470 + AuDbg("%d sec\n", u.create->mfs_second);
26472 + case AuWbrCreate_MFSRR:
26473 + case AuWbrCreate_TDMFS:
26474 + AuDbg("%llu watermark\n",
26475 + u.create->mfsrr_watermark);
26477 + case AuWbrCreate_MFSRRV:
26478 + case AuWbrCreate_TDMFSV:
26479 + case AuWbrCreate_PMFSRRV:
26480 + AuDbg("%llu watermark, %d sec\n",
26481 + u.create->mfsrr_watermark,
26482 + u.create->mfs_second);
26486 + case Opt_wbr_copyup:
26487 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26488 + au_optstr_wbr_copyup(opt->wbr_copyup));
26490 + case Opt_fhsm_sec:
26491 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26496 + case Opt_nodirren:
26497 + AuLabel(nodirren);
26513 +void au_opts_free(struct au_opts *opts)
26515 + struct au_opt *opt;
26518 + while (opt->type != Opt_tail) {
26519 + switch (opt->type) {
26522 + case Opt_prepend:
26523 + path_put(&opt->add.path);
26527 + path_put(&opt->del.h_path);
26531 + dput(opt->mod.h_root);
26534 + fput(opt->xino.file);
26541 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26542 + aufs_bindex_t bindex)
26545 + struct au_opt_add *add = &opt->add;
26548 + add->bindex = bindex;
26549 + add->perm = AuBrPerm_RO;
26550 + add->pathname = opt_str;
26551 + p = strchr(opt_str, '=');
26555 + add->perm = br_perm_val(p);
26558 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26561 + add->perm = AuBrPerm_RO;
26562 + if (au_test_fs_rr(add->path.dentry->d_sb))
26563 + add->perm = AuBrPerm_RR;
26564 + else if (!bindex && !(sb_flags & SB_RDONLY))
26565 + add->perm = AuBrPerm_RW;
26567 + opt->type = Opt_add;
26570 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26577 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26581 + del->pathname = args[0].from;
26582 + AuDbg("del path %s\n", del->pathname);
26584 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26585 + if (unlikely(err))
26586 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26591 +#if 0 /* reserved for future use */
26592 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26593 + struct au_opt_del *del, substring_t args[])
26596 + struct dentry *root;
26599 + root = sb->s_root;
26600 + aufs_read_lock(root, AuLock_FLUSH);
26601 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26602 + pr_err("out of bounds, %d\n", bindex);
26607 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26608 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26611 + aufs_read_unlock(root, !AuLock_IR);
26616 +static int noinline_for_stack
26617 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26620 + struct path path;
26624 + mod->path = args[0].from;
26625 + p = strchr(mod->path, '=');
26626 + if (unlikely(!p)) {
26627 + pr_err("no permission %s\n", args[0].from);
26632 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26633 + if (unlikely(err)) {
26634 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26638 + mod->perm = br_perm_val(p);
26639 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26640 + mod->h_root = dget(path.dentry);
26647 +#if 0 /* reserved for future use */
26648 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26649 + struct au_opt_mod *mod, substring_t args[])
26652 + struct dentry *root;
26655 + root = sb->s_root;
26656 + aufs_read_lock(root, AuLock_FLUSH);
26657 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26658 + pr_err("out of bounds, %d\n", bindex);
26663 + mod->perm = br_perm_val(args[1].from);
26664 + AuDbg("mod path %s, perm 0x%x, %s\n",
26665 + mod->path, mod->perm, args[1].from);
26666 + mod->h_root = dget(au_h_dptr(root, bindex));
26669 + aufs_read_unlock(root, !AuLock_IR);
26674 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26675 + substring_t args[])
26678 + struct file *file;
26680 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26681 + err = PTR_ERR(file);
26682 + if (IS_ERR(file))
26686 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26688 + pr_err("%s must be outside\n", args[0].from);
26693 + xino->file = file;
26694 + xino->path = args[0].from;
26700 +static int noinline_for_stack
26701 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26702 + struct au_opt_xino_itrunc *xino_itrunc,
26703 + substring_t args[])
26706 + aufs_bindex_t bbot, bindex;
26707 + struct path path;
26708 + struct dentry *root;
26710 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26711 + if (unlikely(err)) {
26712 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26716 + xino_itrunc->bindex = -1;
26717 + root = sb->s_root;
26718 + aufs_read_lock(root, AuLock_FLUSH);
26719 + bbot = au_sbbot(sb);
26720 + for (bindex = 0; bindex <= bbot; bindex++) {
26721 + if (au_h_dptr(root, bindex) == path.dentry) {
26722 + xino_itrunc->bindex = bindex;
26726 + aufs_read_unlock(root, !AuLock_IR);
26729 + if (unlikely(xino_itrunc->bindex < 0)) {
26730 + pr_err("no such branch %s\n", args[0].from);
26738 +/* called without aufs lock */
26739 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26741 + int err, n, token;
26742 + aufs_bindex_t bindex;
26743 + unsigned char skipped;
26744 + struct dentry *root;
26745 + struct au_opt *opt, *opt_tail;
26747 + /* reduce the stack space */
26749 + struct au_opt_xino_itrunc *xino_itrunc;
26750 + struct au_opt_wbr_create *create;
26753 + substring_t args[MAX_OPT_ARGS];
26757 + a = kmalloc(sizeof(*a), GFP_NOFS);
26758 + if (unlikely(!a))
26761 + root = sb->s_root;
26765 + opt_tail = opt + opts->max_opt - 1;
26766 + opt->type = Opt_tail;
26767 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26770 + token = match_token(opt_str, options, a->args);
26774 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26776 + err = opt_add(opt, opt_str, opts->sb_flags,
26778 + if (unlikely(!err && ++opt > opt_tail)) {
26782 + opt->type = Opt_tail;
26787 + if (unlikely(match_int(&a->args[0], &n))) {
26788 + pr_err("bad integer in %s\n", opt_str);
26792 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26795 + opt->type = token;
26798 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26799 + /*dummy bindex*/1);
26801 + opt->type = token;
26803 + case Opt_prepend:
26804 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26807 + opt->type = token;
26810 + err = au_opts_parse_del(&opt->del, a->args);
26812 + opt->type = token;
26814 +#if 0 /* reserved for future use */
26816 + del->pathname = "(indexed)";
26817 + if (unlikely(match_int(&args[0], &n))) {
26818 + pr_err("bad integer in %s\n", opt_str);
26821 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26823 + opt->type = token;
26827 + err = au_opts_parse_mod(&opt->mod, a->args);
26829 + opt->type = token;
26831 +#ifdef IMOD /* reserved for future use */
26833 + u.mod->path = "(indexed)";
26834 + if (unlikely(match_int(&a->args[0], &n))) {
26835 + pr_err("bad integer in %s\n", opt_str);
26838 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26840 + opt->type = token;
26844 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26846 + opt->type = token;
26849 + case Opt_trunc_xino_path:
26850 + err = au_opts_parse_xino_itrunc_path
26851 + (sb, &opt->xino_itrunc, a->args);
26853 + opt->type = token;
26856 + case Opt_itrunc_xino:
26857 + u.xino_itrunc = &opt->xino_itrunc;
26858 + if (unlikely(match_int(&a->args[0], &n))) {
26859 + pr_err("bad integer in %s\n", opt_str);
26862 + u.xino_itrunc->bindex = n;
26863 + aufs_read_lock(root, AuLock_FLUSH);
26864 + if (n < 0 || au_sbbot(sb) < n) {
26865 + pr_err("out of bounds, %d\n", n);
26866 + aufs_read_unlock(root, !AuLock_IR);
26869 + aufs_read_unlock(root, !AuLock_IR);
26871 + opt->type = token;
26875 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26878 + opt->type = token;
26881 + case Opt_rdcache:
26882 + if (unlikely(match_int(&a->args[0], &n))) {
26883 + pr_err("bad integer in %s\n", opt_str);
26886 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26887 + pr_err("rdcache must be smaller than %d\n",
26888 + AUFS_RDCACHE_MAX);
26891 + opt->rdcache = n;
26893 + opt->type = token;
26896 + if (unlikely(match_int(&a->args[0], &n)
26898 + || n > KMALLOC_MAX_SIZE)) {
26899 + pr_err("bad integer in %s\n", opt_str);
26902 + if (unlikely(n && n < NAME_MAX)) {
26903 + pr_err("rdblk must be larger than %d\n",
26909 + opt->type = token;
26912 + if (unlikely(match_int(&a->args[0], &n)
26914 + || n * sizeof(struct hlist_head)
26915 + > KMALLOC_MAX_SIZE)) {
26916 + pr_err("bad integer in %s\n", opt_str);
26921 + opt->type = token;
26924 + case Opt_trunc_xino:
26925 + case Opt_notrunc_xino:
26927 + case Opt_trunc_xib:
26928 + case Opt_notrunc_xib:
26931 + case Opt_dirperm1:
26932 + case Opt_nodirperm1:
26934 + case Opt_noplink:
26935 + case Opt_list_plink:
26938 + case Opt_diropq_a:
26939 + case Opt_diropq_w:
26940 + case Opt_warn_perm:
26941 + case Opt_nowarn_perm:
26942 + case Opt_verbose:
26943 + case Opt_noverbose:
26947 + case Opt_rdblk_def:
26948 + case Opt_rdhash_def:
26950 + case Opt_nodirren:
26954 + opt->type = token;
26958 + opt->udba = udba_val(a->args[0].from);
26959 + if (opt->udba >= 0) {
26961 + opt->type = token;
26963 + pr_err("wrong value, %s\n", opt_str);
26966 + case Opt_wbr_create:
26967 + u.create = &opt->wbr_create;
26968 + u.create->wbr_create
26969 + = au_wbr_create_val(a->args[0].from, u.create);
26970 + if (u.create->wbr_create >= 0) {
26972 + opt->type = token;
26974 + pr_err("wrong value, %s\n", opt_str);
26976 + case Opt_wbr_copyup:
26977 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26978 + if (opt->wbr_copyup >= 0) {
26980 + opt->type = token;
26982 + pr_err("wrong value, %s\n", opt_str);
26985 + case Opt_fhsm_sec:
26986 + if (unlikely(match_int(&a->args[0], &n)
26988 + pr_err("bad integer in %s\n", opt_str);
26991 + if (sysaufs_brs) {
26992 + opt->fhsm_second = n;
26993 + opt->type = token;
26995 + pr_warn("ignored %s\n", opt_str);
27000 + pr_warn("ignored %s\n", opt_str);
27002 + case Opt_ignore_silent:
27007 + pr_err("unknown option %s\n", opt_str);
27011 + if (!err && !skipped) {
27012 + if (unlikely(++opt > opt_tail)) {
27015 + opt->type = Opt_tail;
27018 + opt->type = Opt_tail;
27024 + if (unlikely(err))
27025 + au_opts_free(opts);
27031 +static int au_opt_wbr_create(struct super_block *sb,
27032 + struct au_opt_wbr_create *create)
27035 + struct au_sbinfo *sbinfo;
27037 + SiMustWriteLock(sb);
27039 + err = 1; /* handled */
27040 + sbinfo = au_sbi(sb);
27041 + if (sbinfo->si_wbr_create_ops->fin) {
27042 + err = sbinfo->si_wbr_create_ops->fin(sb);
27047 + sbinfo->si_wbr_create = create->wbr_create;
27048 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27049 + switch (create->wbr_create) {
27050 + case AuWbrCreate_MFSRRV:
27051 + case AuWbrCreate_MFSRR:
27052 + case AuWbrCreate_TDMFS:
27053 + case AuWbrCreate_TDMFSV:
27054 + case AuWbrCreate_PMFSRR:
27055 + case AuWbrCreate_PMFSRRV:
27056 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27058 + case AuWbrCreate_MFS:
27059 + case AuWbrCreate_MFSV:
27060 + case AuWbrCreate_PMFS:
27061 + case AuWbrCreate_PMFSV:
27062 + sbinfo->si_wbr_mfs.mfs_expire
27063 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27067 + if (sbinfo->si_wbr_create_ops->init)
27068 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27075 + * plus: processed without an error
27076 + * zero: unprocessed
27078 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27079 + struct au_opts *opts)
27082 + struct au_sbinfo *sbinfo;
27084 + SiMustWriteLock(sb);
27086 + err = 1; /* handled */
27087 + sbinfo = au_sbi(sb);
27088 + switch (opt->type) {
27090 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27091 + sbinfo->si_mntflags |= opt->udba;
27092 + opts->given_udba |= opt->udba;
27096 + au_opt_set(sbinfo->si_mntflags, PLINK);
27098 + case Opt_noplink:
27099 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27100 + au_plink_put(sb, /*verbose*/1);
27101 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27103 + case Opt_list_plink:
27104 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27105 + au_plink_list(sb);
27109 + au_opt_set(sbinfo->si_mntflags, DIO);
27110 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27113 + au_opt_clr(sbinfo->si_mntflags, DIO);
27114 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27117 + case Opt_fhsm_sec:
27118 + au_fhsm_set(sbinfo, opt->fhsm_second);
27121 + case Opt_diropq_a:
27122 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27124 + case Opt_diropq_w:
27125 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27128 + case Opt_warn_perm:
27129 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27131 + case Opt_nowarn_perm:
27132 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27135 + case Opt_verbose:
27136 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27138 + case Opt_noverbose:
27139 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27143 + au_opt_set(sbinfo->si_mntflags, SUM);
27146 + au_opt_clr(sbinfo->si_mntflags, SUM);
27147 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27149 + au_opt_clr(sbinfo->si_mntflags, SUM);
27150 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27153 + case Opt_wbr_create:
27154 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27156 + case Opt_wbr_copyup:
27157 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27158 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27162 + sbinfo->si_dirwh = opt->dirwh;
27165 + case Opt_rdcache:
27166 + sbinfo->si_rdcache
27167 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27170 + sbinfo->si_rdblk = opt->rdblk;
27172 + case Opt_rdblk_def:
27173 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27176 + sbinfo->si_rdhash = opt->rdhash;
27178 + case Opt_rdhash_def:
27179 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27183 + au_opt_set(sbinfo->si_mntflags, SHWH);
27186 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27189 + case Opt_dirperm1:
27190 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27192 + case Opt_nodirperm1:
27193 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27196 + case Opt_trunc_xino:
27197 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27199 + case Opt_notrunc_xino:
27200 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27203 + case Opt_trunc_xino_path:
27204 + case Opt_itrunc_xino:
27205 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27211 + case Opt_trunc_xib:
27212 + au_fset_opts(opts->flags, TRUNC_XIB);
27214 + case Opt_notrunc_xib:
27215 + au_fclr_opts(opts->flags, TRUNC_XIB);
27220 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27221 + err = au_dr_opt_set(sb);
27226 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27228 + case Opt_nodirren:
27230 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27231 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27237 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27241 + sb->s_flags |= SB_POSIXACL;
27244 + sb->s_flags &= ~SB_POSIXACL;
27256 + * returns tri-state.
27257 + * plus: processed without an error
27258 + * zero: unprocessed
27261 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27262 + struct au_opts *opts)
27264 + int err, do_refresh;
27267 + switch (opt->type) {
27269 + opt->add.bindex = au_sbbot(sb) + 1;
27270 + if (opt->add.bindex < 0)
27271 + opt->add.bindex = 0;
27273 + case Opt_prepend:
27274 + opt->add.bindex = 0;
27275 + add: /* indented label */
27277 + err = au_br_add(sb, &opt->add,
27278 + au_ftest_opts(opts->flags, REMOUNT));
27281 + au_fset_opts(opts->flags, REFRESH);
27287 + err = au_br_del(sb, &opt->del,
27288 + au_ftest_opts(opts->flags, REMOUNT));
27291 + au_fset_opts(opts->flags, TRUNC_XIB);
27292 + au_fset_opts(opts->flags, REFRESH);
27298 + err = au_br_mod(sb, &opt->mod,
27299 + au_ftest_opts(opts->flags, REMOUNT),
27304 + au_fset_opts(opts->flags, REFRESH);
27311 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27312 + struct au_opt_xino **opt_xino,
27313 + struct au_opts *opts)
27318 + switch (opt->type) {
27320 + err = au_xino_set(sb, &opt->xino,
27321 + !!au_ftest_opts(opts->flags, REMOUNT));
27322 + if (unlikely(err))
27325 + *opt_xino = &opt->xino;
27330 + *opt_xino = (void *)-1;
27337 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27338 + unsigned int pending)
27341 + aufs_bindex_t bindex, bbot;
27342 + unsigned char do_plink, skip, do_free, can_no_dreval;
27343 + struct au_branch *br;
27344 + struct au_wbr *wbr;
27345 + struct dentry *root, *dentry;
27346 + struct inode *dir, *h_dir;
27347 + struct au_sbinfo *sbinfo;
27348 + struct au_hinode *hdir;
27350 + SiMustAnyLock(sb);
27352 + sbinfo = au_sbi(sb);
27353 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27355 + if (!(sb_flags & SB_RDONLY)) {
27356 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27357 + pr_warn("first branch should be rw\n");
27358 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27359 + pr_warn_once("shwh should be used with ro\n");
27362 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27363 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27364 + pr_warn_once("udba=*notify requires xino\n");
27366 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27367 + pr_warn_once("dirperm1 breaks the protection"
27368 + " by the permission bits on the lower branch\n");
27372 + root = sb->s_root;
27373 + dir = d_inode(root);
27374 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27375 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27377 + bbot = au_sbbot(sb);
27378 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27380 + h_dir = au_h_iptr(dir, bindex);
27381 + br = au_sbr(sb, bindex);
27383 + if ((br->br_perm & AuBrAttr_ICEX)
27384 + && !h_dir->i_op->listxattr)
27385 + br->br_perm &= ~AuBrAttr_ICEX;
27387 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27388 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27389 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27393 + wbr = br->br_wbr;
27395 + wbr_wh_read_lock(wbr);
27397 + if (!au_br_writable(br->br_perm)) {
27400 + || (!wbr->wbr_whbase
27401 + && !wbr->wbr_plink
27402 + && !wbr->wbr_orph));
27403 + } else if (!au_br_wh_linkable(br->br_perm)) {
27404 + /* skip = (!br->br_whbase && !br->br_orph); */
27405 + skip = (!wbr || !wbr->wbr_whbase);
27406 + if (skip && wbr) {
27408 + skip = !!wbr->wbr_plink;
27410 + skip = !wbr->wbr_plink;
27413 + /* skip = (br->br_whbase && br->br_ohph); */
27414 + skip = (wbr && wbr->wbr_whbase);
27417 + skip = !!wbr->wbr_plink;
27419 + skip = !wbr->wbr_plink;
27423 + wbr_wh_read_unlock(wbr);
27425 + if (can_no_dreval) {
27426 + dentry = br->br_path.dentry;
27427 + spin_lock(&dentry->d_lock);
27428 + if (dentry->d_flags &
27429 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27430 + can_no_dreval = 0;
27431 + spin_unlock(&dentry->d_lock);
27434 + if (au_br_fhsm(br->br_perm)) {
27436 + AuDebugOn(!br->br_fhsm);
27442 + hdir = au_hi(dir, bindex);
27443 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27445 + wbr_wh_write_lock(wbr);
27446 + err = au_wh_init(br, sb);
27448 + wbr_wh_write_unlock(wbr);
27449 + au_hn_inode_unlock(hdir);
27451 + if (!err && do_free) {
27452 + au_kfree_rcu(wbr);
27453 + br->br_wbr = NULL;
27457 + if (can_no_dreval)
27458 + au_fset_si(sbinfo, NO_DREVAL);
27460 + au_fclr_si(sbinfo, NO_DREVAL);
27463 + au_fset_si(sbinfo, FHSM);
27464 + for (bindex = bbot; bindex >= 0; bindex--) {
27465 + br = au_sbr(sb, bindex);
27466 + if (au_br_fhsm(br->br_perm)) {
27467 + au_fhsm_set_bottom(sb, bindex);
27472 + au_fclr_si(sbinfo, FHSM);
27473 + au_fhsm_set_bottom(sb, -1);
27479 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27482 + unsigned int tmp;
27483 + aufs_bindex_t bindex, bbot;
27484 + struct au_opt *opt;
27485 + struct au_opt_xino *opt_xino, xino;
27486 + struct au_sbinfo *sbinfo;
27487 + struct au_branch *br;
27488 + struct inode *dir;
27490 + SiMustWriteLock(sb);
27495 + while (err >= 0 && opt->type != Opt_tail)
27496 + err = au_opt_simple(sb, opt++, opts);
27499 + else if (unlikely(err < 0))
27502 + /* disable xino and udba temporary */
27503 + sbinfo = au_sbi(sb);
27504 + tmp = sbinfo->si_mntflags;
27505 + au_opt_clr(sbinfo->si_mntflags, XINO);
27506 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27509 + while (err >= 0 && opt->type != Opt_tail)
27510 + err = au_opt_br(sb, opt++, opts);
27513 + else if (unlikely(err < 0))
27516 + bbot = au_sbbot(sb);
27517 + if (unlikely(bbot < 0)) {
27519 + pr_err("no branches\n");
27523 + if (au_opt_test(tmp, XINO))
27524 + au_opt_set(sbinfo->si_mntflags, XINO);
27526 + while (!err && opt->type != Opt_tail)
27527 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27528 + if (unlikely(err))
27531 + err = au_opts_verify(sb, sb->s_flags, tmp);
27532 + if (unlikely(err))
27535 + /* restore xino */
27536 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27537 + xino.file = au_xino_def(sb);
27538 + err = PTR_ERR(xino.file);
27539 + if (IS_ERR(xino.file))
27542 + err = au_xino_set(sb, &xino, /*remount*/0);
27544 + if (unlikely(err))
27548 + /* restore udba */
27549 + tmp &= AuOptMask_UDBA;
27550 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27551 + sbinfo->si_mntflags |= tmp;
27552 + bbot = au_sbbot(sb);
27553 + for (bindex = 0; bindex <= bbot; bindex++) {
27554 + br = au_sbr(sb, bindex);
27555 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27556 + if (unlikely(err))
27557 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27559 + /* go on even if err */
27561 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27562 + dir = d_inode(sb->s_root);
27563 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27570 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27573 + unsigned char no_dreval;
27574 + struct inode *dir;
27575 + struct au_opt_xino *opt_xino;
27576 + struct au_opt *opt;
27577 + struct au_sbinfo *sbinfo;
27579 + SiMustWriteLock(sb);
27581 + err = au_dr_opt_flush(sb);
27582 + if (unlikely(err))
27584 + au_fset_opts(opts->flags, DR_FLUSHED);
27586 + dir = d_inode(sb->s_root);
27587 + sbinfo = au_sbi(sb);
27590 + while (err >= 0 && opt->type != Opt_tail) {
27591 + err = au_opt_simple(sb, opt, opts);
27593 + err = au_opt_br(sb, opt, opts);
27595 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27601 + /* go on even err */
27603 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27604 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27605 + if (unlikely(rerr && !err))
27608 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27609 + au_fset_opts(opts->flags, REFRESH_IDOP);
27611 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27612 + rerr = au_xib_trunc(sb);
27613 + if (unlikely(rerr && !err))
27617 + /* will be handled by the caller */
27618 + if (!au_ftest_opts(opts->flags, REFRESH)
27619 + && (opts->given_udba
27620 + || au_opt_test(sbinfo->si_mntflags, XINO)
27621 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27623 + au_fset_opts(opts->flags, REFRESH);
27625 + AuDbg("status 0x%x\n", opts->flags);
27631 +/* ---------------------------------------------------------------------- */
27633 +unsigned int au_opt_udba(struct super_block *sb)
27635 + return au_mntflags(sb) & AuOptMask_UDBA;
27637 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27638 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 08:00:00.000000000 +0800
27639 +++ linux/fs/aufs/opts.h 2019-07-11 21:21:54.382384486 +0800
27641 +/* SPDX-License-Identifier: GPL-2.0 */
27643 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27645 + * This program, aufs is free software; you can redistribute it and/or modify
27646 + * it under the terms of the GNU General Public License as published by
27647 + * the Free Software Foundation; either version 2 of the License, or
27648 + * (at your option) any later version.
27650 + * This program is distributed in the hope that it will be useful,
27651 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27652 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27653 + * GNU General Public License for more details.
27655 + * You should have received a copy of the GNU General Public License
27656 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27660 + * mount options/flags
27663 +#ifndef __AUFS_OPTS_H__
27664 +#define __AUFS_OPTS_H__
27668 +#include <linux/path.h>
27672 +/* ---------------------------------------------------------------------- */
27675 +#define AuOpt_XINO 1 /* external inode number bitmap
27676 + and translation table */
27677 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27678 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27679 +#define AuOpt_UDBA_REVAL (1 << 3)
27680 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27681 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27682 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27683 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27685 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27686 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27687 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27688 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27689 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27690 +#define AuOpt_DIO (1 << 14) /* direct io */
27691 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27693 +#ifndef CONFIG_AUFS_HNOTIFY
27694 +#undef AuOpt_UDBA_HNOTIFY
27695 +#define AuOpt_UDBA_HNOTIFY 0
27697 +#ifndef CONFIG_AUFS_DIRREN
27698 +#undef AuOpt_DIRREN
27699 +#define AuOpt_DIRREN 0
27701 +#ifndef CONFIG_AUFS_SHWH
27703 +#define AuOpt_SHWH 0
27706 +#define AuOpt_Def (AuOpt_XINO \
27707 + | AuOpt_UDBA_REVAL \
27709 + /* | AuOpt_DIRPERM1 */ \
27710 + | AuOpt_WARN_PERM)
27711 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27712 + | AuOpt_UDBA_REVAL \
27713 + | AuOpt_UDBA_HNOTIFY)
27715 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27716 +#define au_opt_set(flags, name) do { \
27717 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27718 + ((flags) |= AuOpt_##name); \
27720 +#define au_opt_set_udba(flags, name) do { \
27721 + (flags) &= ~AuOptMask_UDBA; \
27722 + ((flags) |= AuOpt_##name); \
27724 +#define au_opt_clr(flags, name) do { \
27725 + ((flags) &= ~AuOpt_##name); \
27728 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27730 +#ifdef CONFIG_PROC_FS
27733 + return mntflags & ~AuOpt_PLINK;
27737 +/* ---------------------------------------------------------------------- */
27739 +/* policies to select one among multiple writable branches */
27741 + AuWbrCreate_TDP, /* top down parent */
27742 + AuWbrCreate_RR, /* round robin */
27743 + AuWbrCreate_MFS, /* most free space */
27744 + AuWbrCreate_MFSV, /* mfs with seconds */
27745 + AuWbrCreate_MFSRR, /* mfs then rr */
27746 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27747 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27748 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27749 + AuWbrCreate_PMFS, /* parent and mfs */
27750 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27751 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27752 + AuWbrCreate_PMFSRRV, /* plus seconds */
27754 + AuWbrCreate_Def = AuWbrCreate_TDP
27758 + AuWbrCopyup_TDP, /* top down parent */
27759 + AuWbrCopyup_BUP, /* bottom up parent */
27760 + AuWbrCopyup_BU, /* bottom up */
27762 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27765 +/* ---------------------------------------------------------------------- */
27767 +struct au_opt_add {
27768 + aufs_bindex_t bindex;
27771 + struct path path;
27774 +struct au_opt_del {
27776 + struct path h_path;
27779 +struct au_opt_mod {
27782 + struct dentry *h_root;
27785 +struct au_opt_xino {
27787 + struct file *file;
27790 +struct au_opt_xino_itrunc {
27791 + aufs_bindex_t bindex;
27794 +struct au_opt_wbr_create {
27797 + unsigned long long mfsrr_watermark;
27803 + struct au_opt_xino xino;
27804 + struct au_opt_xino_itrunc xino_itrunc;
27805 + struct au_opt_add add;
27806 + struct au_opt_del del;
27807 + struct au_opt_mod mod;
27810 + unsigned int rdblk;
27811 + unsigned int rdhash;
27813 + struct au_opt_wbr_create wbr_create;
27815 + unsigned int fhsm_second;
27820 +#define AuOpts_REMOUNT 1
27821 +#define AuOpts_REFRESH (1 << 1)
27822 +#define AuOpts_TRUNC_XIB (1 << 2)
27823 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27824 +#define AuOpts_REFRESH_IDOP (1 << 4)
27825 +#define AuOpts_DR_FLUSHED (1 << 5)
27826 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27827 +#define au_fset_opts(flags, name) \
27828 + do { (flags) |= AuOpts_##name; } while (0)
27829 +#define au_fclr_opts(flags, name) \
27830 + do { (flags) &= ~AuOpts_##name; } while (0)
27832 +#ifndef CONFIG_AUFS_DIRREN
27833 +#undef AuOpts_DR_FLUSHED
27834 +#define AuOpts_DR_FLUSHED 0
27838 + struct au_opt *opt;
27841 + unsigned int given_udba;
27842 + unsigned int flags;
27843 + unsigned long sb_flags;
27846 +/* ---------------------------------------------------------------------- */
27849 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27850 +const char *au_optstr_udba(int udba);
27851 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27852 +const char *au_optstr_wbr_create(int wbr_create);
27854 +void au_opts_free(struct au_opts *opts);
27855 +struct super_block;
27856 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27857 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27858 + unsigned int pending);
27859 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27860 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27862 +unsigned int au_opt_udba(struct super_block *sb);
27864 +#endif /* __KERNEL__ */
27865 +#endif /* __AUFS_OPTS_H__ */
27866 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27867 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 08:00:00.000000000 +0800
27868 +++ linux/fs/aufs/plink.c 2019-07-11 21:21:54.382384486 +0800
27870 +// SPDX-License-Identifier: GPL-2.0
27872 + * Copyright (C) 2005-2019 Junjiro R. Okajima
27874 + * This program, aufs is free software; you can redistribute it and/or modify
27875 + * it under the terms of the GNU General Public License as published by
27876 + * the Free Software Foundation; either version 2 of the License, or
27877 + * (at your option) any later version.
27879 + * This program is distributed in the hope that it will be useful,
27880 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27881 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27882 + * GNU General Public License for more details.
27884 + * You should have received a copy of the GNU General Public License
27885 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27895 + * the pseudo-link maintenance mode.
27896 + * during a user process maintains the pseudo-links,
27897 + * prohibit adding a new plink and branch manipulation.
27901 + * For entry functions which will handle plink, and i_mutex is already held
27903 + * They cannot wait and should return an error at once.
27904 + * Callers has to check the error.
27906 + * For entry functions which will handle plink, but i_mutex is not held
27908 + * They can wait the plink maintenance mode to finish.
27910 + * They behave like F_SETLK and F_SETLKW.
27911 + * If the caller never handle plink, then both flags are unnecessary.
27914 +int au_plink_maint(struct super_block *sb, int flags)
27918 + struct task_struct *parent, *prev;
27919 + struct au_sbinfo *sbi;
27921 + SiMustAnyLock(sb);
27924 + if (!au_opt_test(au_mntflags(sb), PLINK))
27927 + sbi = au_sbi(sb);
27928 + pid = sbi->si_plink_maint_pid;
27929 + if (!pid || pid == current->pid)
27932 + /* todo: it highly depends upon /sbin/mount.aufs */
27934 + parent = current;
27938 + parent = rcu_dereference(parent->real_parent);
27939 + if (parent == prev)
27941 + ppid = task_pid_vnr(parent);
27942 + if (pid == ppid) {
27943 + rcu_read_unlock();
27948 + rcu_read_unlock();
27950 + if (au_ftest_lock(flags, NOPLMW)) {
27951 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27952 + /* AuDebugOn(!lockdep_depth(current)); */
27953 + while (sbi->si_plink_maint_pid) {
27954 + si_read_unlock(sb);
27955 + /* gave up wake_up_bit() */
27956 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27958 + if (au_ftest_lock(flags, FLUSH))
27959 + au_nwt_flush(&sbi->si_nowait);
27960 + si_noflush_read_lock(sb);
27962 + } else if (au_ftest_lock(flags, NOPLM)) {
27963 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27971 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27973 + spin_lock(&sbinfo->si_plink_maint_lock);
27974 + sbinfo->si_plink_maint_pid = 0;
27975 + spin_unlock(&sbinfo->si_plink_maint_lock);
27976 + wake_up_all(&sbinfo->si_plink_wq);
27979 +int au_plink_maint_enter(struct super_block *sb)
27982 + struct au_sbinfo *sbinfo;
27985 + sbinfo = au_sbi(sb);
27986 + /* make sure i am the only one in this fs */
27987 + si_write_lock(sb, AuLock_FLUSH);
27988 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27989 + spin_lock(&sbinfo->si_plink_maint_lock);
27990 + if (!sbinfo->si_plink_maint_pid)
27991 + sbinfo->si_plink_maint_pid = current->pid;
27994 + spin_unlock(&sbinfo->si_plink_maint_lock);
27996 + si_write_unlock(sb);
28001 +/* ---------------------------------------------------------------------- */
28003 +#ifdef CONFIG_AUFS_DEBUG
28004 +void au_plink_list(struct super_block *sb)
28007 + struct au_sbinfo *sbinfo;
28008 + struct hlist_bl_head *hbl;
28009 + struct hlist_bl_node *pos;
28010 + struct au_icntnr *icntnr;
28012 + SiMustAnyLock(sb);
28014 + sbinfo = au_sbi(sb);
28015 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28016 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28018 + for (i = 0; i < AuPlink_NHASH; i++) {
28019 + hbl = sbinfo->si_plink + i;
28020 + hlist_bl_lock(hbl);
28021 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28022 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28023 + hlist_bl_unlock(hbl);
28028 +/* is the inode pseudo-linked? */
28029 +int au_plink_test(struct inode *inode)
28032 + struct au_sbinfo *sbinfo;
28033 + struct hlist_bl_head *hbl;
28034 + struct hlist_bl_node *pos;
28035 + struct au_icntnr *icntnr;
28037 + sbinfo = au_sbi(inode->i_sb);
28038 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28039 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28040 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28043 + i = au_plink_hash(inode->i_ino);
28044 + hbl = sbinfo->si_plink + i;
28045 + hlist_bl_lock(hbl);
28046 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28047 + if (&icntnr->vfs_inode == inode) {
28051 + hlist_bl_unlock(hbl);
28055 +/* ---------------------------------------------------------------------- */
28058 + * generate a name for plink.
28059 + * the file will be stored under AUFS_WH_PLINKDIR.
28061 +/* 20 is max digits length of ulong 64 */
28062 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28064 +static int plink_name(char *name, int len, struct inode *inode,
28065 + aufs_bindex_t bindex)
28068 + struct inode *h_inode;
28070 + h_inode = au_h_iptr(inode, bindex);
28071 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28075 +struct au_do_plink_lkup_args {
28076 + struct dentry **errp;
28077 + struct qstr *tgtname;
28078 + struct dentry *h_parent;
28079 + struct au_branch *br;
28082 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28083 + struct dentry *h_parent,
28084 + struct au_branch *br)
28086 + struct dentry *h_dentry;
28087 + struct inode *h_inode;
28089 + h_inode = d_inode(h_parent);
28090 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28091 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28092 + inode_unlock_shared(h_inode);
28096 +static void au_call_do_plink_lkup(void *args)
28098 + struct au_do_plink_lkup_args *a = args;
28099 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28102 +/* lookup the plink-ed @inode under the branch at @bindex */
28103 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28105 + struct dentry *h_dentry, *h_parent;
28106 + struct au_branch *br;
28108 + char a[PLINK_NAME_LEN];
28109 + struct qstr tgtname = QSTR_INIT(a, 0);
28111 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28113 + br = au_sbr(inode->i_sb, bindex);
28114 + h_parent = br->br_wbr->wbr_plink;
28115 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28117 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28118 + struct au_do_plink_lkup_args args = {
28119 + .errp = &h_dentry,
28120 + .tgtname = &tgtname,
28121 + .h_parent = h_parent,
28125 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28126 + if (unlikely(wkq_err))
28127 + h_dentry = ERR_PTR(wkq_err);
28129 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28134 +/* create a pseudo-link */
28135 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28136 + struct dentry *h_dentry, struct au_branch *br)
28139 + struct path h_path = {
28140 + .mnt = au_br_mnt(br)
28142 + struct inode *h_dir, *delegated;
28144 + h_dir = d_inode(h_parent);
28145 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28147 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28148 + err = PTR_ERR(h_path.dentry);
28149 + if (IS_ERR(h_path.dentry))
28153 + /* wh.plink dir is not monitored */
28154 + /* todo: is it really safe? */
28155 + if (d_is_positive(h_path.dentry)
28156 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28157 + delegated = NULL;
28158 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28159 + if (unlikely(err == -EWOULDBLOCK)) {
28160 + pr_warn("cannot retry for NFSv4 delegation"
28161 + " for an internal unlink\n");
28164 + dput(h_path.dentry);
28165 + h_path.dentry = NULL;
28169 + if (!err && d_is_negative(h_path.dentry)) {
28170 + delegated = NULL;
28171 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28172 + if (unlikely(err == -EWOULDBLOCK)) {
28173 + pr_warn("cannot retry for NFSv4 delegation"
28174 + " for an internal link\n");
28178 + dput(h_path.dentry);
28181 + inode_unlock(h_dir);
28185 +struct do_whplink_args {
28187 + struct qstr *tgt;
28188 + struct dentry *h_parent;
28189 + struct dentry *h_dentry;
28190 + struct au_branch *br;
28193 +static void call_do_whplink(void *args)
28195 + struct do_whplink_args *a = args;
28196 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28199 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28200 + aufs_bindex_t bindex, struct au_branch *br)
28202 + int err, wkq_err;
28203 + struct au_wbr *wbr;
28204 + struct dentry *h_parent;
28205 + char a[PLINK_NAME_LEN];
28206 + struct qstr tgtname = QSTR_INIT(a, 0);
28208 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28209 + h_parent = wbr->wbr_plink;
28210 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28212 + /* always superio. */
28213 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28214 + struct do_whplink_args args = {
28217 + .h_parent = h_parent,
28218 + .h_dentry = h_dentry,
28221 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28222 + if (unlikely(wkq_err))
28225 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28231 + * create a new pseudo-link for @h_dentry on @bindex.
28232 + * the linked inode is held in aufs @inode.
28234 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28235 + struct dentry *h_dentry)
28237 + struct super_block *sb;
28238 + struct au_sbinfo *sbinfo;
28239 + struct hlist_bl_head *hbl;
28240 + struct hlist_bl_node *pos;
28241 + struct au_icntnr *icntnr;
28242 + int found, err, cnt, i;
28244 + sb = inode->i_sb;
28245 + sbinfo = au_sbi(sb);
28246 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28247 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28249 + found = au_plink_test(inode);
28253 + i = au_plink_hash(inode->i_ino);
28254 + hbl = sbinfo->si_plink + i;
28257 + hlist_bl_lock(hbl);
28258 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28259 + if (&icntnr->vfs_inode == inode) {
28265 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28266 + hlist_bl_add_head(&icntnr->plink, hbl);
28268 + hlist_bl_unlock(hbl);
28270 + cnt = au_hbl_count(hbl);
28271 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28272 + if (cnt > AUFS_PLINK_WARN)
28273 + AuWarn1(msg ", %d\n", cnt);
28275 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28276 + if (unlikely(err)) {
28277 + pr_warn("err %d, damaged pseudo link.\n", err);
28278 + au_hbl_del(&icntnr->plink, hbl);
28279 + iput(&icntnr->vfs_inode);
28282 + iput(&icntnr->vfs_inode);
28285 +/* free all plinks */
28286 +void au_plink_put(struct super_block *sb, int verbose)
28289 + struct au_sbinfo *sbinfo;
28290 + struct hlist_bl_head *hbl;
28291 + struct hlist_bl_node *pos, *tmp;
28292 + struct au_icntnr *icntnr;
28294 + SiMustWriteLock(sb);
28296 + sbinfo = au_sbi(sb);
28297 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28298 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28300 + /* no spin_lock since sbinfo is write-locked */
28302 + for (i = 0; i < AuPlink_NHASH; i++) {
28303 + hbl = sbinfo->si_plink + i;
28304 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28305 + pr_warn("pseudo-link is not flushed");
28308 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28309 + iput(&icntnr->vfs_inode);
28310 + INIT_HLIST_BL_HEAD(hbl);
28314 +void au_plink_clean(struct super_block *sb, int verbose)
28316 + struct dentry *root;
28318 + root = sb->s_root;
28319 + aufs_write_lock(root);
28320 + if (au_opt_test(au_mntflags(sb), PLINK))
28321 + au_plink_put(sb, verbose);
28322 + aufs_write_unlock(root);
28325 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28328 + aufs_bindex_t btop, bbot, bindex;
28331 + btop = au_ibtop(inode);
28332 + bbot = au_ibbot(inode);
28334 + for (bindex = btop; bindex <= bbot; bindex++) {
28335 + if (!au_h_iptr(inode, bindex)
28336 + || au_ii_br_id(inode, bindex) != br_id)
28338 + au_set_h_iptr(inode, bindex, NULL, 0);
28343 + for (bindex = btop; bindex <= bbot; bindex++)
28344 + if (au_h_iptr(inode, bindex)) {
28354 +/* free the plinks on a branch specified by @br_id */
28355 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28357 + struct au_sbinfo *sbinfo;
28358 + struct hlist_bl_head *hbl;
28359 + struct hlist_bl_node *pos, *tmp;
28360 + struct au_icntnr *icntnr;
28361 + struct inode *inode;
28364 + SiMustWriteLock(sb);
28366 + sbinfo = au_sbi(sb);
28367 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28368 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28370 + /* no bit_lock since sbinfo is write-locked */
28371 + for (i = 0; i < AuPlink_NHASH; i++) {
28372 + hbl = sbinfo->si_plink + i;
28373 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28374 + inode = au_igrab(&icntnr->vfs_inode);
28375 + ii_write_lock_child(inode);
28376 + do_put = au_plink_do_half_refresh(inode, br_id);
28378 + hlist_bl_del(&icntnr->plink);
28381 + ii_write_unlock(inode);
28386 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28387 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 08:00:00.000000000 +0800
28388 +++ linux/fs/aufs/poll.c 2019-07-11 21:21:54.382384486 +0800
28390 +// SPDX-License-Identifier: GPL-2.0
28392 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28394 + * This program, aufs is free software; you can redistribute it and/or modify
28395 + * it under the terms of the GNU General Public License as published by
28396 + * the Free Software Foundation; either version 2 of the License, or
28397 + * (at your option) any later version.
28399 + * This program is distributed in the hope that it will be useful,
28400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28402 + * GNU General Public License for more details.
28404 + * You should have received a copy of the GNU General Public License
28405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28410 + * There is only one filesystem which implements ->poll operation, currently.
28415 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28418 + struct file *h_file;
28419 + struct super_block *sb;
28421 + /* We should pretend an error happened. */
28422 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28423 + sb = file->f_path.dentry->d_sb;
28424 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28426 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28427 + if (IS_ERR(h_file)) {
28428 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28432 + mask = vfs_poll(h_file, pt);
28433 + fput(h_file); /* instead of au_read_post() */
28436 + si_read_unlock(sb);
28437 + if (mask & EPOLLERR)
28438 + AuDbg("mask 0x%x\n", mask);
28441 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28442 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 08:00:00.000000000 +0800
28443 +++ linux/fs/aufs/posix_acl.c 2019-07-11 21:21:54.382384486 +0800
28445 +// SPDX-License-Identifier: GPL-2.0
28447 + * Copyright (C) 2014-2019 Junjiro R. Okajima
28449 + * This program, aufs is free software; you can redistribute it and/or modify
28450 + * it under the terms of the GNU General Public License as published by
28451 + * the Free Software Foundation; either version 2 of the License, or
28452 + * (at your option) any later version.
28454 + * This program is distributed in the hope that it will be useful,
28455 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28456 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28457 + * GNU General Public License for more details.
28459 + * You should have received a copy of the GNU General Public License
28460 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28464 + * posix acl operations
28467 +#include <linux/fs.h>
28470 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28472 + struct posix_acl *acl;
28474 + aufs_bindex_t bindex;
28475 + struct inode *h_inode;
28476 + struct super_block *sb;
28479 + sb = inode->i_sb;
28480 + si_read_lock(sb, AuLock_FLUSH);
28481 + ii_read_lock_child(inode);
28482 + if (!(sb->s_flags & SB_POSIXACL))
28485 + bindex = au_ibtop(inode);
28486 + h_inode = au_h_iptr(inode, bindex);
28487 + if (unlikely(!h_inode
28488 + || ((h_inode->i_mode & S_IFMT)
28489 + != (inode->i_mode & S_IFMT)))) {
28490 + err = au_busy_or_stale();
28491 + acl = ERR_PTR(err);
28495 + /* always topmost only */
28496 + acl = get_acl(h_inode, type);
28497 + if (!IS_ERR_OR_NULL(acl))
28498 + set_cached_acl(inode, type, acl);
28501 + ii_read_unlock(inode);
28502 + si_read_unlock(sb);
28504 + AuTraceErrPtr(acl);
28508 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28512 + struct dentry *dentry;
28513 + struct au_sxattr arg = {
28514 + .type = AU_ACL_SET,
28521 + IMustLock(inode);
28523 + if (inode->i_ino == AUFS_ROOT_INO)
28524 + dentry = dget(inode->i_sb->s_root);
28526 + dentry = d_find_alias(inode);
28528 + dentry = d_find_any_alias(inode);
28530 + pr_warn("cannot handle this inode, "
28531 + "please report to aufs-users ML\n");
28537 + ssz = au_sxattr(dentry, inode, &arg);
28542 + set_cached_acl(inode, type, acl);
28548 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28549 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 08:00:00.000000000 +0800
28550 +++ linux/fs/aufs/procfs.c 2019-07-11 21:21:54.382384486 +0800
28552 +// SPDX-License-Identifier: GPL-2.0
28554 + * Copyright (C) 2010-2019 Junjiro R. Okajima
28556 + * This program, aufs is free software; you can redistribute it and/or modify
28557 + * it under the terms of the GNU General Public License as published by
28558 + * the Free Software Foundation; either version 2 of the License, or
28559 + * (at your option) any later version.
28561 + * This program is distributed in the hope that it will be useful,
28562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28564 + * GNU General Public License for more details.
28566 + * You should have received a copy of the GNU General Public License
28567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28571 + * procfs interfaces
28574 +#include <linux/proc_fs.h>
28577 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28579 + struct au_sbinfo *sbinfo;
28581 + sbinfo = file->private_data;
28583 + au_plink_maint_leave(sbinfo);
28584 + kobject_put(&sbinfo->si_kobj);
28590 +static void au_procfs_plm_write_clean(struct file *file)
28592 + struct au_sbinfo *sbinfo;
28594 + sbinfo = file->private_data;
28596 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28599 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28602 + struct super_block *sb;
28603 + struct au_sbinfo *sbinfo;
28604 + struct hlist_bl_node *pos;
28607 + if (unlikely(file->private_data))
28611 + /* don't use au_sbilist_lock() here */
28612 + hlist_bl_lock(&au_sbilist);
28613 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28614 + if (id == sysaufs_si_id(sbinfo)) {
28615 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28616 + sb = sbinfo->si_sb;
28619 + hlist_bl_unlock(&au_sbilist);
28622 + if (unlikely(!sb))
28625 + err = au_plink_maint_enter(sb);
28627 + /* keep kobject_get() */
28628 + file->private_data = sbinfo;
28630 + kobject_put(&sbinfo->si_kobj);
28636 + * Accept a valid "si=xxxx" only.
28637 + * Once it is accepted successfully, accept "clean" too.
28639 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28640 + size_t count, loff_t *ppos)
28643 + unsigned long id;
28644 + /* last newline is allowed */
28645 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28648 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28652 + if (unlikely(count > sizeof(buf)))
28655 + err = copy_from_user(buf, ubuf, count);
28656 + if (unlikely(err)) {
28663 + if (!strcmp("clean", buf)) {
28664 + au_procfs_plm_write_clean(file);
28665 + goto out_success;
28666 + } else if (unlikely(strncmp("si=", buf, 3)))
28669 + err = kstrtoul(buf + 3, 16, &id);
28670 + if (unlikely(err))
28673 + err = au_procfs_plm_write_si(file, id);
28674 + if (unlikely(err))
28678 + err = count; /* success */
28683 +static const struct file_operations au_procfs_plm_fop = {
28684 + .write = au_procfs_plm_write,
28685 + .release = au_procfs_plm_release,
28686 + .owner = THIS_MODULE
28689 +/* ---------------------------------------------------------------------- */
28691 +static struct proc_dir_entry *au_procfs_dir;
28693 +void au_procfs_fin(void)
28695 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28696 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28699 +int __init au_procfs_init(void)
28702 + struct proc_dir_entry *entry;
28705 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28706 + if (unlikely(!au_procfs_dir))
28709 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28710 + au_procfs_dir, &au_procfs_plm_fop);
28711 + if (unlikely(!entry))
28715 + goto out; /* success */
28719 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28723 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28724 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 08:00:00.000000000 +0800
28725 +++ linux/fs/aufs/rdu.c 2019-07-11 21:21:54.382384486 +0800
28727 +// SPDX-License-Identifier: GPL-2.0
28729 + * Copyright (C) 2005-2019 Junjiro R. Okajima
28731 + * This program, aufs is free software; you can redistribute it and/or modify
28732 + * it under the terms of the GNU General Public License as published by
28733 + * the Free Software Foundation; either version 2 of the License, or
28734 + * (at your option) any later version.
28736 + * This program is distributed in the hope that it will be useful,
28737 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28738 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28739 + * GNU General Public License for more details.
28741 + * You should have received a copy of the GNU General Public License
28742 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28746 + * readdir in userspace.
28749 +#include <linux/compat.h>
28750 +#include <linux/fs_stack.h>
28751 +#include <linux/security.h>
28754 +/* bits for struct aufs_rdu.flags */
28755 +#define AuRdu_CALLED 1
28756 +#define AuRdu_CONT (1 << 1)
28757 +#define AuRdu_FULL (1 << 2)
28758 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28759 +#define au_fset_rdu(flags, name) \
28760 + do { (flags) |= AuRdu_##name; } while (0)
28761 +#define au_fclr_rdu(flags, name) \
28762 + do { (flags) &= ~AuRdu_##name; } while (0)
28764 +struct au_rdu_arg {
28765 + struct dir_context ctx;
28766 + struct aufs_rdu *rdu;
28767 + union au_rdu_ent_ul ent;
28768 + unsigned long end;
28770 + struct super_block *sb;
28774 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28775 + loff_t offset, u64 h_ino, unsigned int d_type)
28778 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28779 + struct aufs_rdu *rdu = arg->rdu;
28780 + struct au_rdu_ent ent;
28784 + au_fset_rdu(rdu->cookie.flags, CALLED);
28785 + len = au_rdu_len(nlen);
28786 + if (arg->ent.ul + len < arg->end) {
28788 + ent.bindex = rdu->cookie.bindex;
28789 + ent.type = d_type;
28791 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28792 + ent.type = DT_UNKNOWN;
28794 + /* unnecessary to support mmap_sem since this is a dir */
28796 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28798 + if (copy_to_user(arg->ent.e->name, name, nlen))
28800 + /* the terminating NULL */
28801 + if (__put_user(0, arg->ent.e->name + nlen))
28804 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28805 + arg->ent.ul += len;
28809 + au_fset_rdu(rdu->cookie.flags, FULL);
28811 + rdu->tail = arg->ent;
28815 + /* AuTraceErr(err); */
28819 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28823 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28825 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28826 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28828 + if (unlikely(offset != cookie->h_pos))
28834 + au_fclr_rdu(cookie->flags, CALLED);
28836 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28840 + && au_ftest_rdu(cookie->flags, CALLED)
28841 + && !au_ftest_rdu(cookie->flags, FULL));
28842 + cookie->h_pos = h_file->f_pos;
28849 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28852 + aufs_bindex_t bbot;
28853 + struct au_rdu_arg arg = {
28855 + .actor = au_rdu_fill
28858 + struct dentry *dentry;
28859 + struct inode *inode;
28860 + struct file *h_file;
28861 + struct au_rdu_cookie *cookie = &rdu->cookie;
28863 + /* VERIFY_WRITE */
28864 + err = !access_ok(rdu->ent.e, rdu->sz);
28865 + if (unlikely(err)) {
28871 + rdu->tail = rdu->ent;
28874 + arg.ent = rdu->ent;
28875 + arg.end = arg.ent.ul;
28876 + arg.end += rdu->sz;
28879 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28882 + err = security_file_permission(file, MAY_READ);
28884 + if (unlikely(err))
28887 + dentry = file->f_path.dentry;
28888 + inode = d_inode(dentry);
28889 + inode_lock_shared(inode);
28891 + arg.sb = inode->i_sb;
28892 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28893 + if (unlikely(err))
28895 + err = au_alive_dir(dentry);
28896 + if (unlikely(err))
28898 + /* todo: reval? */
28899 + fi_read_lock(file);
28902 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28903 + && cookie->generation != au_figen(file)))
28908 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28910 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28912 + bbot = au_fbtop(file);
28913 + if (cookie->bindex < bbot)
28914 + cookie->bindex = bbot;
28915 + bbot = au_fbbot_dir(file);
28916 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28917 + for (; !err && cookie->bindex <= bbot;
28918 + cookie->bindex++, cookie->h_pos = 0) {
28919 + h_file = au_hf_dir(file, cookie->bindex);
28923 + au_fclr_rdu(cookie->flags, FULL);
28924 + err = au_rdu_do(h_file, &arg);
28926 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28929 + AuDbg("rent %llu\n", rdu->rent);
28931 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28932 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28933 + au_fset_rdu(cookie->flags, CONT);
28934 + cookie->generation = au_figen(file);
28937 + ii_read_lock_child(inode);
28938 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28939 + ii_read_unlock(inode);
28942 + fi_read_unlock(file);
28944 + si_read_unlock(arg.sb);
28946 + inode_unlock_shared(inode);
28952 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28956 + unsigned long long nent;
28957 + union au_rdu_ent_ul *u;
28958 + struct au_rdu_ent ent;
28959 + struct super_block *sb;
28962 + nent = rdu->nent;
28964 + sb = file->f_path.dentry->d_sb;
28965 + si_read_lock(sb, AuLock_FLUSH);
28966 + while (nent-- > 0) {
28967 + /* unnecessary to support mmap_sem since this is a dir */
28968 + err = copy_from_user(&ent, u->e, sizeof(ent));
28970 + /* VERIFY_WRITE */
28971 + err = !access_ok(&u->e->ino, sizeof(ino));
28972 + if (unlikely(err)) {
28978 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28980 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28982 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28984 + if (unlikely(err)) {
28989 + err = __put_user(ino, &u->e->ino);
28990 + if (unlikely(err)) {
28995 + u->ul += au_rdu_len(ent.nlen);
28997 + si_read_unlock(sb);
29002 +/* ---------------------------------------------------------------------- */
29004 +static int au_rdu_verify(struct aufs_rdu *rdu)
29006 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29007 + "%llu, b%d, 0x%x, g%u}\n",
29008 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29010 + rdu->rent, rdu->shwh, rdu->full,
29011 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29012 + rdu->cookie.generation);
29014 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29018 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29022 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29025 + struct aufs_rdu rdu;
29026 + void __user *p = (void __user *)arg;
29028 + err = copy_from_user(&rdu, p, sizeof(rdu));
29029 + if (unlikely(err)) {
29034 + err = au_rdu_verify(&rdu);
29035 + if (unlikely(err))
29039 + case AUFS_CTL_RDU:
29040 + err = au_rdu(file, &rdu);
29041 + if (unlikely(err))
29044 + e = copy_to_user(p, &rdu, sizeof(rdu));
29045 + if (unlikely(e)) {
29050 + case AUFS_CTL_RDU_INO:
29051 + err = au_rdu_ino(file, &rdu);
29055 + /* err = -ENOTTY; */
29064 +#ifdef CONFIG_COMPAT
29065 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29068 + struct aufs_rdu rdu;
29069 + void __user *p = compat_ptr(arg);
29071 + /* todo: get_user()? */
29072 + err = copy_from_user(&rdu, p, sizeof(rdu));
29073 + if (unlikely(err)) {
29078 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29079 + err = au_rdu_verify(&rdu);
29080 + if (unlikely(err))
29084 + case AUFS_CTL_RDU:
29085 + err = au_rdu(file, &rdu);
29086 + if (unlikely(err))
29089 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29090 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29091 + e = copy_to_user(p, &rdu, sizeof(rdu));
29092 + if (unlikely(e)) {
29097 + case AUFS_CTL_RDU_INO:
29098 + err = au_rdu_ino(file, &rdu);
29102 + /* err = -ENOTTY; */
29111 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29112 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 08:00:00.000000000 +0800
29113 +++ linux/fs/aufs/rwsem.h 2019-07-11 21:21:54.382384486 +0800
29115 +/* SPDX-License-Identifier: GPL-2.0 */
29117 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29119 + * This program, aufs is free software; you can redistribute it and/or modify
29120 + * it under the terms of the GNU General Public License as published by
29121 + * the Free Software Foundation; either version 2 of the License, or
29122 + * (at your option) any later version.
29124 + * This program is distributed in the hope that it will be useful,
29125 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29126 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29127 + * GNU General Public License for more details.
29129 + * You should have received a copy of the GNU General Public License
29130 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29134 + * simple read-write semaphore wrappers
29137 +#ifndef __AUFS_RWSEM_H__
29138 +#define __AUFS_RWSEM_H__
29142 +#include "debug.h"
29144 +/* in the future, the name 'au_rwsem' will be totally gone */
29145 +#define au_rwsem rw_semaphore
29147 +/* to debug easier, do not make them inlined functions */
29148 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29149 +/* rwsem_is_locked() is unusable */
29150 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29152 + && !lockdep_is_held_type(rw, 1))
29153 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29155 + && !lockdep_is_held_type(rw, 0))
29156 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29158 + && !lockdep_is_held(rw))
29159 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29161 + && lockdep_is_held(rw))
29163 +#define au_rw_init(rw) init_rwsem(rw)
29165 +#define au_rw_init_wlock(rw) do { \
29166 + au_rw_init(rw); \
29167 + down_write(rw); \
29170 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29171 + au_rw_init(rw); \
29172 + down_write_nested(rw, lsc); \
29175 +#define au_rw_read_lock(rw) down_read(rw)
29176 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29177 +#define au_rw_read_unlock(rw) up_read(rw)
29178 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29179 +#define au_rw_write_lock(rw) down_write(rw)
29180 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29181 +#define au_rw_write_unlock(rw) up_write(rw)
29182 +/* why is not _nested version defined? */
29183 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29184 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29186 +#endif /* __KERNEL__ */
29187 +#endif /* __AUFS_RWSEM_H__ */
29188 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29189 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 08:00:00.000000000 +0800
29190 +++ linux/fs/aufs/sbinfo.c 2019-07-11 21:21:54.382384486 +0800
29192 +// SPDX-License-Identifier: GPL-2.0
29194 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29196 + * This program, aufs is free software; you can redistribute it and/or modify
29197 + * it under the terms of the GNU General Public License as published by
29198 + * the Free Software Foundation; either version 2 of the License, or
29199 + * (at your option) any later version.
29201 + * This program is distributed in the hope that it will be useful,
29202 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29203 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29204 + * GNU General Public License for more details.
29206 + * You should have received a copy of the GNU General Public License
29207 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29211 + * superblock private data
29214 +#include <linux/iversion.h>
29218 + * they are necessary regardless sysfs is disabled.
29220 +void au_si_free(struct kobject *kobj)
29223 + struct au_sbinfo *sbinfo;
29224 + char *locked __maybe_unused; /* debug only */
29226 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29227 + for (i = 0; i < AuPlink_NHASH; i++)
29228 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29229 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29231 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29232 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29233 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29234 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29236 + dbgaufs_si_fin(sbinfo);
29237 + au_rw_write_lock(&sbinfo->si_rwsem);
29238 + au_br_free(sbinfo);
29239 + au_rw_write_unlock(&sbinfo->si_rwsem);
29241 + au_kfree_try_rcu(sbinfo->si_branch);
29242 + mutex_destroy(&sbinfo->si_xib_mtx);
29243 + AuRwDestroy(&sbinfo->si_rwsem);
29245 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29246 + /* si_nfiles is waited too */
29247 + au_kfree_rcu(sbinfo);
29250 +int au_si_alloc(struct super_block *sb)
29253 + struct au_sbinfo *sbinfo;
29256 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29257 + if (unlikely(!sbinfo))
29260 + /* will be reallocated separately */
29261 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29262 + if (unlikely(!sbinfo->si_branch))
29265 + err = sysaufs_si_init(sbinfo);
29267 + dbgaufs_si_null(sbinfo);
29268 + err = dbgaufs_si_init(sbinfo);
29269 + if (unlikely(err))
29270 + kobject_put(&sbinfo->si_kobj);
29272 + if (unlikely(err))
29275 + au_nwt_init(&sbinfo->si_nowait);
29276 + au_rw_init_wlock(&sbinfo->si_rwsem);
29278 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29279 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29281 + sbinfo->si_bbot = -1;
29282 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29284 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29285 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29286 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29287 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29289 + au_fhsm_init(sbinfo);
29291 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29293 + sbinfo->si_xino_jiffy = jiffies;
29294 + sbinfo->si_xino_expire
29295 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29296 + mutex_init(&sbinfo->si_xib_mtx);
29297 + /* leave si_xib_last_pindex and si_xib_next_bit */
29299 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29301 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29302 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29303 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29304 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29306 + for (i = 0; i < AuPlink_NHASH; i++)
29307 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29308 + init_waitqueue_head(&sbinfo->si_plink_wq);
29309 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29311 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29313 + /* with getattr by default */
29314 + sbinfo->si_iop_array = aufs_iop;
29316 + /* leave other members for sysaufs and si_mnt. */
29317 + sbinfo->si_sb = sb;
29318 + sb->s_fs_info = sbinfo;
29320 + return 0; /* success */
29323 + au_kfree_try_rcu(sbinfo->si_branch);
29325 + au_kfree_rcu(sbinfo);
29330 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29333 + struct au_branch **brp;
29335 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29338 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29339 + if (unlikely(!sz))
29340 + sz = sizeof(*brp);
29341 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29344 + sbinfo->si_branch = brp;
29351 +/* ---------------------------------------------------------------------- */
29353 +unsigned int au_sigen_inc(struct super_block *sb)
29355 + unsigned int gen;
29356 + struct inode *inode;
29358 + SiMustWriteLock(sb);
29360 + gen = ++au_sbi(sb)->si_generation;
29361 + au_update_digen(sb->s_root);
29362 + inode = d_inode(sb->s_root);
29363 + au_update_iigen(inode, /*half*/0);
29364 + inode_inc_iversion(inode);
29368 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29370 + aufs_bindex_t br_id;
29372 + struct au_sbinfo *sbinfo;
29374 + SiMustWriteLock(sb);
29376 + sbinfo = au_sbi(sb);
29377 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29378 + br_id = ++sbinfo->si_last_br_id;
29379 + AuDebugOn(br_id < 0);
29380 + if (br_id && au_br_index(sb, br_id) < 0)
29387 +/* ---------------------------------------------------------------------- */
29389 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29390 +int si_read_lock(struct super_block *sb, int flags)
29395 + if (au_ftest_lock(flags, FLUSH))
29396 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29398 + si_noflush_read_lock(sb);
29399 + err = au_plink_maint(sb, flags);
29400 + if (unlikely(err))
29401 + si_read_unlock(sb);
29406 +int si_write_lock(struct super_block *sb, int flags)
29410 + if (au_ftest_lock(flags, FLUSH))
29411 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29413 + si_noflush_write_lock(sb);
29414 + err = au_plink_maint(sb, flags);
29415 + if (unlikely(err))
29416 + si_write_unlock(sb);
29421 +/* dentry and super_block lock. call at entry point */
29422 +int aufs_read_lock(struct dentry *dentry, int flags)
29425 + struct super_block *sb;
29427 + sb = dentry->d_sb;
29428 + err = si_read_lock(sb, flags);
29429 + if (unlikely(err))
29432 + if (au_ftest_lock(flags, DW))
29433 + di_write_lock_child(dentry);
29435 + di_read_lock_child(dentry, flags);
29437 + if (au_ftest_lock(flags, GEN)) {
29438 + err = au_digen_test(dentry, au_sigen(sb));
29439 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29440 + AuDebugOn(!err && au_dbrange_test(dentry));
29442 + err = au_dbrange_test(dentry);
29443 + if (unlikely(err))
29444 + aufs_read_unlock(dentry, flags);
29451 +void aufs_read_unlock(struct dentry *dentry, int flags)
29453 + if (au_ftest_lock(flags, DW))
29454 + di_write_unlock(dentry);
29456 + di_read_unlock(dentry, flags);
29457 + si_read_unlock(dentry->d_sb);
29460 +void aufs_write_lock(struct dentry *dentry)
29462 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29463 + di_write_lock_child(dentry);
29466 +void aufs_write_unlock(struct dentry *dentry)
29468 + di_write_unlock(dentry);
29469 + si_write_unlock(dentry->d_sb);
29472 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29475 + unsigned int sigen;
29476 + struct super_block *sb;
29479 + err = si_read_lock(sb, flags);
29480 + if (unlikely(err))
29483 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29485 + if (au_ftest_lock(flags, GEN)) {
29486 + sigen = au_sigen(sb);
29487 + err = au_digen_test(d1, sigen);
29488 + AuDebugOn(!err && au_dbrange_test(d1));
29490 + err = au_digen_test(d2, sigen);
29491 + AuDebugOn(!err && au_dbrange_test(d2));
29493 + if (unlikely(err))
29494 + aufs_read_and_write_unlock2(d1, d2);
29501 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29503 + di_write_unlock2(d1, d2);
29504 + si_read_unlock(d1->d_sb);
29506 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29507 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 08:00:00.000000000 +0800
29508 +++ linux/fs/aufs/super.c 2019-07-11 21:21:54.382384486 +0800
29510 +// SPDX-License-Identifier: GPL-2.0
29512 + * Copyright (C) 2005-2019 Junjiro R. Okajima
29514 + * This program, aufs is free software; you can redistribute it and/or modify
29515 + * it under the terms of the GNU General Public License as published by
29516 + * the Free Software Foundation; either version 2 of the License, or
29517 + * (at your option) any later version.
29519 + * This program is distributed in the hope that it will be useful,
29520 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29521 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29522 + * GNU General Public License for more details.
29524 + * You should have received a copy of the GNU General Public License
29525 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29529 + * mount and super_block operations
29532 +#include <linux/iversion.h>
29533 +#include <linux/mm.h>
29534 +#include <linux/seq_file.h>
29535 +#include <linux/statfs.h>
29536 +#include <linux/vmalloc.h>
29540 + * super_operations
29542 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29544 + struct au_icntnr *c;
29546 + c = au_cache_alloc_icntnr();
29548 + au_icntnr_init(c);
29549 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29550 + c->iinfo.ii_hinode = NULL;
29551 + return &c->vfs_inode;
29556 +static void aufs_destroy_inode(struct inode *inode)
29558 + if (!au_is_bad_inode(inode))
29559 + au_iinfo_fin(inode);
29562 +static void aufs_free_inode(struct inode *inode)
29564 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29567 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29569 + struct inode *inode;
29572 + inode = iget_locked(sb, ino);
29573 + if (unlikely(!inode)) {
29574 + inode = ERR_PTR(-ENOMEM);
29577 + if (!(inode->i_state & I_NEW))
29580 + err = au_xigen_new(inode);
29582 + err = au_iinfo_init(inode);
29584 + inode_inc_iversion(inode);
29586 + iget_failed(inode);
29587 + inode = ERR_PTR(err);
29591 + /* never return NULL */
29592 + AuDebugOn(!inode);
29593 + AuTraceErrPtr(inode);
29597 +/* lock free root dinfo */
29598 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29601 + aufs_bindex_t bindex, bbot;
29602 + struct path path;
29603 + struct au_hdentry *hdp;
29604 + struct au_branch *br;
29605 + au_br_perm_str_t perm;
29608 + bbot = au_sbbot(sb);
29610 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29611 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29612 + br = au_sbr(sb, bindex);
29613 + path.mnt = au_br_mnt(br);
29614 + path.dentry = hdp->hd_dentry;
29615 + err = au_seq_path(seq, &path);
29617 + au_optstr_br_perm(&perm, br->br_perm);
29618 + seq_printf(seq, "=%s", perm.a);
29619 + if (bindex != bbot)
29620 + seq_putc(seq, ':');
29623 + if (unlikely(err || seq_has_overflowed(seq)))
29629 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29630 + const char *append)
29635 + while (*pat != ':')
29638 + strcpy(p, append);
29639 + AuDebugOn(strlen(fmt) >= len);
29642 +static void au_show_wbr_create(struct seq_file *m, int v,
29643 + struct au_sbinfo *sbinfo)
29647 + struct au_wbr_mfs *mfs;
29649 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29651 + seq_puts(m, ",create=");
29652 + pat = au_optstr_wbr_create(v);
29653 + mfs = &sbinfo->si_wbr_mfs;
29655 + case AuWbrCreate_TDP:
29656 + case AuWbrCreate_RR:
29657 + case AuWbrCreate_MFS:
29658 + case AuWbrCreate_PMFS:
29659 + seq_puts(m, pat);
29661 + case AuWbrCreate_MFSRR:
29662 + case AuWbrCreate_TDMFS:
29663 + case AuWbrCreate_PMFSRR:
29664 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29665 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29667 + case AuWbrCreate_MFSV:
29668 + case AuWbrCreate_PMFSV:
29669 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29670 + seq_printf(m, fmt,
29671 + jiffies_to_msecs(mfs->mfs_expire)
29674 + case AuWbrCreate_MFSRRV:
29675 + case AuWbrCreate_TDMFSV:
29676 + case AuWbrCreate_PMFSRRV:
29677 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29678 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29679 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29686 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29688 +#ifdef CONFIG_SYSFS
29692 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29693 + aufs_bindex_t bindex, brid;
29694 + struct qstr *name;
29696 + struct dentry *d, *h_root;
29697 + struct au_branch *br;
29699 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29702 + f = au_sbi(sb)->si_xib;
29706 + /* stop printing the default xino path on the first writable branch */
29708 + bindex = au_xi_root(sb, f->f_path.dentry);
29709 + if (bindex >= 0) {
29710 + br = au_sbr_sb(sb, bindex);
29711 + h_root = au_br_dentry(br);
29714 + d = f->f_path.dentry;
29715 + name = &d->d_name;
29716 + /* safe ->d_parent because the file is unlinked */
29717 + if (d->d_parent == h_root
29718 + && name->len == len
29719 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29722 + seq_puts(seq, ",xino=");
29723 + err = au_xino_path(seq, f);
29730 +/* seq_file will re-call me in case of too long string */
29731 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29734 + unsigned int mnt_flags, v;
29735 + struct super_block *sb;
29736 + struct au_sbinfo *sbinfo;
29738 +#define AuBool(name, str) do { \
29739 + v = au_opt_test(mnt_flags, name); \
29740 + if (v != au_opt_test(AuOpt_Def, name)) \
29741 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29744 +#define AuStr(name, str) do { \
29745 + v = mnt_flags & AuOptMask_##name; \
29746 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29747 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29750 +#define AuUInt(name, str, val) do { \
29751 + if (val != AUFS_##name##_DEF) \
29752 + seq_printf(m, "," #str "=%u", val); \
29755 + sb = dentry->d_sb;
29756 + if (sb->s_flags & SB_POSIXACL)
29757 + seq_puts(m, ",acl");
29759 + if (sb->s_flags & SB_I_VERSION)
29760 + seq_puts(m, ",i_version");
29763 + /* lock free root dinfo */
29764 + si_noflush_read_lock(sb);
29765 + sbinfo = au_sbi(sb);
29766 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29768 + mnt_flags = au_mntflags(sb);
29769 + if (au_opt_test(mnt_flags, XINO)) {
29770 + err = au_show_xino(m, sb);
29771 + if (unlikely(err))
29774 + seq_puts(m, ",noxino");
29776 + AuBool(TRUNC_XINO, trunc_xino);
29777 + AuStr(UDBA, udba);
29778 + AuBool(SHWH, shwh);
29779 + AuBool(PLINK, plink);
29780 + AuBool(DIO, dio);
29781 + AuBool(DIRPERM1, dirperm1);
29783 + v = sbinfo->si_wbr_create;
29784 + if (v != AuWbrCreate_Def)
29785 + au_show_wbr_create(m, v, sbinfo);
29787 + v = sbinfo->si_wbr_copyup;
29788 + if (v != AuWbrCopyup_Def)
29789 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29791 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29792 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29793 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29795 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29797 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29798 + AuUInt(RDCACHE, rdcache, v);
29800 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29801 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29803 + au_fhsm_show(m, sbinfo);
29805 + AuBool(DIRREN, dirren);
29806 + AuBool(SUM, sum);
29807 + /* AuBool(SUM_W, wsum); */
29808 + AuBool(WARN_PERM, warn_perm);
29809 + AuBool(VERBOSE, verbose);
29812 + /* be sure to print "br:" last */
29813 + if (!sysaufs_brs) {
29814 + seq_puts(m, ",br:");
29815 + au_show_brs(m, sb);
29817 + si_read_unlock(sb);
29825 +/* ---------------------------------------------------------------------- */
29827 +/* sum mode which returns the summation for statfs(2) */
29829 +static u64 au_add_till_max(u64 a, u64 b)
29837 + return ULLONG_MAX;
29840 +static u64 au_mul_till_max(u64 a, long mul)
29848 + return ULLONG_MAX;
29851 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29854 + long bsize, factor;
29855 + u64 blocks, bfree, bavail, files, ffree;
29856 + aufs_bindex_t bbot, bindex, i;
29857 + unsigned char shared;
29858 + struct path h_path;
29859 + struct super_block *h_sb;
29862 + bsize = LONG_MAX;
29868 + bbot = au_sbbot(sb);
29869 + for (bindex = 0; bindex <= bbot; bindex++) {
29870 + h_path.mnt = au_sbr_mnt(sb, bindex);
29871 + h_sb = h_path.mnt->mnt_sb;
29873 + for (i = 0; !shared && i < bindex; i++)
29874 + shared = (au_sbr_sb(sb, i) == h_sb);
29878 + /* sb->s_root for NFS is unreliable */
29879 + h_path.dentry = h_path.mnt->mnt_root;
29880 + err = vfs_statfs(&h_path, buf);
29881 + if (unlikely(err))
29884 + if (bsize > buf->f_bsize) {
29886 + * we will reduce bsize, so we have to expand blocks
29887 + * etc. to match them again
29889 + factor = (bsize / buf->f_bsize);
29890 + blocks = au_mul_till_max(blocks, factor);
29891 + bfree = au_mul_till_max(bfree, factor);
29892 + bavail = au_mul_till_max(bavail, factor);
29893 + bsize = buf->f_bsize;
29896 + factor = (buf->f_bsize / bsize);
29897 + blocks = au_add_till_max(blocks,
29898 + au_mul_till_max(buf->f_blocks, factor));
29899 + bfree = au_add_till_max(bfree,
29900 + au_mul_till_max(buf->f_bfree, factor));
29901 + bavail = au_add_till_max(bavail,
29902 + au_mul_till_max(buf->f_bavail, factor));
29903 + files = au_add_till_max(files, buf->f_files);
29904 + ffree = au_add_till_max(ffree, buf->f_ffree);
29907 + buf->f_bsize = bsize;
29908 + buf->f_blocks = blocks;
29909 + buf->f_bfree = bfree;
29910 + buf->f_bavail = bavail;
29911 + buf->f_files = files;
29912 + buf->f_ffree = ffree;
29913 + buf->f_frsize = 0;
29919 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29922 + struct path h_path;
29923 + struct super_block *sb;
29925 + /* lock free root dinfo */
29926 + sb = dentry->d_sb;
29927 + si_noflush_read_lock(sb);
29928 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29929 + /* sb->s_root for NFS is unreliable */
29930 + h_path.mnt = au_sbr_mnt(sb, 0);
29931 + h_path.dentry = h_path.mnt->mnt_root;
29932 + err = vfs_statfs(&h_path, buf);
29934 + err = au_statfs_sum(sb, buf);
29935 + si_read_unlock(sb);
29938 + buf->f_type = AUFS_SUPER_MAGIC;
29939 + buf->f_namelen = AUFS_MAX_NAMELEN;
29940 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29942 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29947 +/* ---------------------------------------------------------------------- */
29949 +static int aufs_sync_fs(struct super_block *sb, int wait)
29952 + aufs_bindex_t bbot, bindex;
29953 + struct au_branch *br;
29954 + struct super_block *h_sb;
29957 + si_noflush_read_lock(sb);
29958 + bbot = au_sbbot(sb);
29959 + for (bindex = 0; bindex <= bbot; bindex++) {
29960 + br = au_sbr(sb, bindex);
29961 + if (!au_br_writable(br->br_perm))
29964 + h_sb = au_sbr_sb(sb, bindex);
29965 + e = vfsub_sync_filesystem(h_sb, wait);
29966 + if (unlikely(e && !err))
29968 + /* go on even if an error happens */
29970 + si_read_unlock(sb);
29975 +/* ---------------------------------------------------------------------- */
29977 +/* final actions when unmounting a file system */
29978 +static void aufs_put_super(struct super_block *sb)
29980 + struct au_sbinfo *sbinfo;
29982 + sbinfo = au_sbi(sb);
29984 + kobject_put(&sbinfo->si_kobj);
29987 +/* ---------------------------------------------------------------------- */
29989 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29990 + struct super_block *sb, void *arg)
29993 + unsigned long long n, sz;
30000 + if (*hint > ULLONG_MAX / sizeof(array)) {
30001 + array = ERR_PTR(-EMFILE);
30002 + pr_err("hint %llu\n", *hint);
30006 + sz = sizeof(array) * *hint;
30007 + array = kzalloc(sz, GFP_NOFS);
30008 + if (unlikely(!array))
30009 + array = vzalloc(sz);
30010 + if (unlikely(!array)) {
30011 + array = ERR_PTR(-ENOMEM);
30015 + n = cb(sb, array, *hint, arg);
30016 + AuDebugOn(n > *hint);
30023 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30024 + unsigned long long max __maybe_unused,
30027 + unsigned long long n;
30028 + struct inode **p, *inode;
30029 + struct list_head *head;
30034 + spin_lock(&sb->s_inode_list_lock);
30035 + list_for_each_entry(inode, head, i_sb_list) {
30036 + if (!au_is_bad_inode(inode)
30037 + && au_ii(inode)->ii_btop >= 0) {
30038 + spin_lock(&inode->i_lock);
30039 + if (atomic_read(&inode->i_count)) {
30043 + AuDebugOn(n > max);
30045 + spin_unlock(&inode->i_lock);
30048 + spin_unlock(&sb->s_inode_list_lock);
30053 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30055 + struct au_sbinfo *sbi;
30057 + sbi = au_sbi(sb);
30058 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30059 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30062 +void au_iarray_free(struct inode **a, unsigned long long max)
30064 + unsigned long long ull;
30066 + for (ull = 0; ull < max; ull++)
30071 +/* ---------------------------------------------------------------------- */
30074 + * refresh dentry and inode at remount time.
30076 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30077 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30078 + struct dentry *parent)
30082 + di_write_lock_child(dentry);
30083 + di_read_lock_parent(parent, AuLock_IR);
30084 + err = au_refresh_dentry(dentry, parent);
30085 + if (!err && dir_flags)
30086 + au_hn_reset(d_inode(dentry), dir_flags);
30087 + di_read_unlock(parent, AuLock_IR);
30088 + di_write_unlock(dentry);
30093 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30094 + struct au_sbinfo *sbinfo,
30095 + const unsigned int dir_flags, unsigned int do_idop)
30098 + struct dentry *parent;
30101 + parent = dget_parent(dentry);
30102 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30103 + if (d_really_is_positive(dentry)) {
30104 + if (!d_is_dir(dentry))
30105 + err = au_do_refresh(dentry, /*dir_flags*/0,
30108 + err = au_do_refresh(dentry, dir_flags, parent);
30109 + if (unlikely(err))
30110 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30113 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30114 + AuDbgDentry(dentry);
30120 + au_refresh_dop(dentry, /*force_reval*/0);
30122 + au_refresh_dop(dentry, /*force_reval*/1);
30128 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30130 + int err, i, j, ndentry, e;
30131 + unsigned int sigen;
30132 + struct au_dcsub_pages dpages;
30133 + struct au_dpage *dpage;
30134 + struct dentry **dentries, *d;
30135 + struct au_sbinfo *sbinfo;
30136 + struct dentry *root = sb->s_root;
30137 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30140 + au_refresh_dop(root, /*force_reval*/0);
30142 + err = au_dpages_init(&dpages, GFP_NOFS);
30143 + if (unlikely(err))
30145 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30146 + if (unlikely(err))
30149 + sigen = au_sigen(sb);
30150 + sbinfo = au_sbi(sb);
30151 + for (i = 0; i < dpages.ndpage; i++) {
30152 + dpage = dpages.dpages + i;
30153 + dentries = dpage->dentries;
30154 + ndentry = dpage->ndentry;
30155 + for (j = 0; j < ndentry; j++) {
30157 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30159 + if (unlikely(e && !err))
30161 + /* go on even err */
30166 + au_dpages_free(&dpages);
30171 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30174 + unsigned int sigen;
30175 + unsigned long long max, ull;
30176 + struct inode *inode, **array;
30178 + array = au_iarray_alloc(sb, &max);
30179 + err = PTR_ERR(array);
30180 + if (IS_ERR(array))
30184 + sigen = au_sigen(sb);
30185 + for (ull = 0; ull < max; ull++) {
30186 + inode = array[ull];
30187 + if (unlikely(!inode))
30191 + ii_write_lock_child(inode);
30192 + if (au_iigen(inode, NULL) != sigen) {
30193 + e = au_refresh_hinode_self(inode);
30194 + if (unlikely(e)) {
30195 + au_refresh_iop(inode, /*force_getattr*/1);
30196 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30199 + /* go on even if err */
30202 + if (!e && do_idop)
30203 + au_refresh_iop(inode, /*force_getattr*/0);
30204 + ii_write_unlock(inode);
30207 + au_iarray_free(array, max);
30213 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30216 + unsigned int udba;
30217 + aufs_bindex_t bindex, bbot;
30218 + struct dentry *root;
30219 + struct inode *inode;
30220 + struct au_branch *br;
30221 + struct au_sbinfo *sbi;
30223 + au_sigen_inc(sb);
30224 + sbi = au_sbi(sb);
30225 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30227 + root = sb->s_root;
30228 + DiMustNoWaiters(root);
30229 + inode = d_inode(root);
30230 + IiMustNoWaiters(inode);
30232 + udba = au_opt_udba(sb);
30233 + bbot = au_sbbot(sb);
30234 + for (bindex = 0; bindex <= bbot; bindex++) {
30235 + br = au_sbr(sb, bindex);
30236 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30237 + if (unlikely(err))
30238 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30240 + /* go on even if err */
30242 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30245 + if (au_ftest_si(sbi, NO_DREVAL)) {
30246 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30247 + sb->s_d_op = &aufs_dop_noreval;
30248 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30249 + sbi->si_iop_array = aufs_iop_nogetattr;
30251 + AuDebugOn(sb->s_d_op == &aufs_dop);
30252 + sb->s_d_op = &aufs_dop;
30253 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30254 + sbi->si_iop_array = aufs_iop;
30256 + pr_info("reset to %ps and %ps\n",
30257 + sb->s_d_op, sbi->si_iop_array);
30260 + di_write_unlock(root);
30261 + err = au_refresh_d(sb, do_idop);
30262 + e = au_refresh_i(sb, do_idop);
30263 + if (unlikely(e && !err))
30265 + /* aufs_write_lock() calls ..._child() */
30266 + di_write_lock_child(root);
30268 + au_cpup_attr_all(inode, /*force*/1);
30270 + if (unlikely(err))
30271 + AuIOErr("refresh failed, ignored, %d\n", err);
30274 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30275 +static int cvt_err(int err)
30289 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30292 + unsigned int mntflags;
30293 + struct au_opts opts = {
30296 + struct dentry *root;
30297 + struct inode *inode;
30298 + struct au_sbinfo *sbinfo;
30301 + root = sb->s_root;
30302 + if (!data || !*data) {
30303 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30305 + di_write_lock_child(root);
30306 + err = au_opts_verify(sb, *flags, /*pending*/0);
30307 + aufs_write_unlock(root);
30313 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30314 + if (unlikely(!opts.opt))
30316 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30317 + opts.flags = AuOpts_REMOUNT;
30318 + opts.sb_flags = *flags;
30320 + /* parse it before aufs lock */
30321 + err = au_opts_parse(sb, data, &opts);
30322 + if (unlikely(err))
30325 + sbinfo = au_sbi(sb);
30326 + inode = d_inode(root);
30327 + inode_lock(inode);
30328 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30329 + if (unlikely(err))
30331 + di_write_lock_child(root);
30333 + /* au_opts_remount() may return an error */
30334 + err = au_opts_remount(sb, &opts);
30335 + au_opts_free(&opts);
30337 + if (au_ftest_opts(opts.flags, REFRESH))
30338 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30340 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30341 + mntflags = au_mntflags(sb);
30342 + do_dx = !!au_opt_test(mntflags, DIO);
30343 + au_dy_arefresh(do_dx);
30346 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30347 + aufs_write_unlock(root);
30350 + inode_unlock(inode);
30352 + free_page((unsigned long)opts.opt);
30354 + err = cvt_err(err);
30359 +static const struct super_operations aufs_sop = {
30360 + .alloc_inode = aufs_alloc_inode,
30361 + .destroy_inode = aufs_destroy_inode,
30362 + .free_inode = aufs_free_inode,
30363 + /* always deleting, no clearing */
30364 + .drop_inode = generic_delete_inode,
30365 + .show_options = aufs_show_options,
30366 + .statfs = aufs_statfs,
30367 + .put_super = aufs_put_super,
30368 + .sync_fs = aufs_sync_fs,
30369 + .remount_fs = aufs_remount_fs
30372 +/* ---------------------------------------------------------------------- */
30374 +static int alloc_root(struct super_block *sb)
30377 + struct inode *inode;
30378 + struct dentry *root;
30381 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30382 + err = PTR_ERR(inode);
30383 + if (IS_ERR(inode))
30386 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30387 + inode->i_fop = &aufs_dir_fop;
30388 + inode->i_mode = S_IFDIR;
30389 + set_nlink(inode, 2);
30390 + unlock_new_inode(inode);
30392 + root = d_make_root(inode);
30393 + if (unlikely(!root))
30395 + err = PTR_ERR(root);
30396 + if (IS_ERR(root))
30399 + err = au_di_init(root);
30401 + sb->s_root = root;
30402 + return 0; /* success */
30410 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30411 + int silent __maybe_unused)
30414 + struct au_opts opts = {
30417 + struct au_sbinfo *sbinfo;
30418 + struct dentry *root;
30419 + struct inode *inode;
30420 + char *arg = raw_data;
30422 + if (unlikely(!arg || !*arg)) {
30424 + pr_err("no arg\n");
30429 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30430 + if (unlikely(!opts.opt))
30432 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30433 + opts.sb_flags = sb->s_flags;
30435 + err = au_si_alloc(sb);
30436 + if (unlikely(err))
30438 + sbinfo = au_sbi(sb);
30440 + /* all timestamps always follow the ones on the branch */
30441 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30442 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30443 + sb->s_op = &aufs_sop;
30444 + sb->s_d_op = &aufs_dop;
30445 + sb->s_magic = AUFS_SUPER_MAGIC;
30446 + sb->s_maxbytes = 0;
30447 + sb->s_stack_depth = 1;
30448 + au_export_init(sb);
30449 + au_xattr_init(sb);
30451 + err = alloc_root(sb);
30452 + if (unlikely(err)) {
30453 + si_write_unlock(sb);
30456 + root = sb->s_root;
30457 + inode = d_inode(root);
30460 + * actually we can parse options regardless aufs lock here.
30461 + * but at remount time, parsing must be done before aufs lock.
30462 + * so we follow the same rule.
30464 + ii_write_lock_parent(inode);
30465 + aufs_write_unlock(root);
30466 + err = au_opts_parse(sb, arg, &opts);
30467 + if (unlikely(err))
30470 + /* lock vfs_inode first, then aufs. */
30471 + inode_lock(inode);
30472 + aufs_write_lock(root);
30473 + err = au_opts_mount(sb, &opts);
30474 + au_opts_free(&opts);
30475 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30476 + sb->s_d_op = &aufs_dop_noreval;
30477 + pr_info("%ps\n", sb->s_d_op);
30478 + au_refresh_dop(root, /*force_reval*/0);
30479 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30480 + au_refresh_iop(inode, /*force_getattr*/0);
30482 + aufs_write_unlock(root);
30483 + inode_unlock(inode);
30485 + goto out_opts; /* success */
30489 + sb->s_root = NULL;
30491 + kobject_put(&sbinfo->si_kobj);
30492 + sb->s_fs_info = NULL;
30494 + free_page((unsigned long)opts.opt);
30497 + err = cvt_err(err);
30502 +/* ---------------------------------------------------------------------- */
30504 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30505 + const char *dev_name __maybe_unused,
30508 + struct dentry *root;
30510 + /* all timestamps always follow the ones on the branch */
30511 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30512 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30513 + if (IS_ERR(root))
30516 + au_sbilist_add(root->d_sb);
30522 +static void aufs_kill_sb(struct super_block *sb)
30524 + struct au_sbinfo *sbinfo;
30526 + sbinfo = au_sbi(sb);
30528 + au_sbilist_del(sb);
30529 + aufs_write_lock(sb->s_root);
30531 + if (sbinfo->si_wbr_create_ops->fin)
30532 + sbinfo->si_wbr_create_ops->fin(sb);
30533 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30534 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30535 + au_remount_refresh(sb, /*do_idop*/0);
30537 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30538 + au_plink_put(sb, /*verbose*/1);
30540 + au_dr_opt_flush(sb);
30541 + sbinfo->si_sb = NULL;
30542 + aufs_write_unlock(sb->s_root);
30543 + au_nwt_flush(&sbinfo->si_nowait);
30545 + kill_anon_super(sb);
30548 +struct file_system_type aufs_fs_type = {
30549 + .name = AUFS_FSTYPE,
30550 + /* a race between rename and others */
30551 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30552 + .mount = aufs_mount,
30553 + .kill_sb = aufs_kill_sb,
30554 + /* no need to __module_get() and module_put(). */
30555 + .owner = THIS_MODULE,
30557 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30558 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 08:00:00.000000000 +0800
30559 +++ linux/fs/aufs/super.h 2019-07-11 21:21:54.382384486 +0800
30561 +/* SPDX-License-Identifier: GPL-2.0 */
30563 + * Copyright (C) 2005-2019 Junjiro R. Okajima
30565 + * This program, aufs is free software; you can redistribute it and/or modify
30566 + * it under the terms of the GNU General Public License as published by
30567 + * the Free Software Foundation; either version 2 of the License, or
30568 + * (at your option) any later version.
30570 + * This program is distributed in the hope that it will be useful,
30571 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30572 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30573 + * GNU General Public License for more details.
30575 + * You should have received a copy of the GNU General Public License
30576 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30580 + * super_block operations
30583 +#ifndef __AUFS_SUPER_H__
30584 +#define __AUFS_SUPER_H__
30588 +#include <linux/fs.h>
30589 +#include <linux/kobject.h>
30592 +#include "rwsem.h"
30595 +/* policies to select one among multiple writable branches */
30596 +struct au_wbr_copyup_operations {
30597 + int (*copyup)(struct dentry *dentry);
30600 +#define AuWbr_DIR 1 /* target is a dir */
30601 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30603 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30604 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30605 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30607 +struct au_wbr_create_operations {
30608 + int (*create)(struct dentry *dentry, unsigned int flags);
30609 + int (*init)(struct super_block *sb);
30610 + int (*fin)(struct super_block *sb);
30613 +struct au_wbr_mfs {
30614 + struct mutex mfs_lock; /* protect this structure */
30615 + unsigned long mfs_jiffy;
30616 + unsigned long mfs_expire;
30617 + aufs_bindex_t mfs_bindex;
30619 + unsigned long long mfsrr_bytes;
30620 + unsigned long long mfsrr_watermark;
30623 +#define AuPlink_NHASH 100
30624 +static inline int au_plink_hash(ino_t ino)
30626 + return ino % AuPlink_NHASH;
30629 +/* File-based Hierarchical Storage Management */
30631 +#ifdef CONFIG_AUFS_FHSM
30632 + /* allow only one process who can receive the notification */
30633 + spinlock_t fhsm_spin;
30635 + wait_queue_head_t fhsm_wqh;
30636 + atomic_t fhsm_readable;
30638 + /* these are protected by si_rwsem */
30639 + unsigned long fhsm_expire;
30640 + aufs_bindex_t fhsm_bottom;
30645 +struct au_sbinfo {
30646 + /* nowait tasks in the system-wide workqueue */
30647 + struct au_nowait_tasks si_nowait;
30650 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30651 + * rwsem for au_sbinfo is necessary.
30653 + struct au_rwsem si_rwsem;
30656 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30659 + au_lcnt_t si_ninodes, si_nfiles;
30661 + /* branch management */
30662 + unsigned int si_generation;
30664 + /* see AuSi_ flags */
30665 + unsigned char au_si_status;
30667 + aufs_bindex_t si_bbot;
30669 + /* dirty trick to keep br_id plus */
30670 + unsigned int si_last_br_id :
30671 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30672 + struct au_branch **si_branch;
30674 + /* policy to select a writable branch */
30675 + unsigned char si_wbr_copyup;
30676 + unsigned char si_wbr_create;
30677 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30678 + struct au_wbr_create_operations *si_wbr_create_ops;
30680 + /* round robin */
30681 + atomic_t si_wbr_rr_next;
30683 + /* most free space */
30684 + struct au_wbr_mfs si_wbr_mfs;
30686 + /* File-based Hierarchical Storage Management */
30687 + struct au_fhsm si_fhsm;
30689 + /* mount flags */
30690 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30691 + unsigned int si_mntflags;
30693 + /* external inode number (bitmap and translation table) */
30694 + vfs_readf_t si_xread;
30695 + vfs_writef_t si_xwrite;
30696 + loff_t si_ximaxent; /* max entries in a xino */
30698 + struct file *si_xib;
30699 + struct mutex si_xib_mtx; /* protect xib members */
30700 + unsigned long *si_xib_buf;
30701 + unsigned long si_xib_last_pindex;
30702 + int si_xib_next_bit;
30704 + unsigned long si_xino_jiffy;
30705 + unsigned long si_xino_expire;
30706 + /* reserved for future use */
30707 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30709 +#ifdef CONFIG_AUFS_EXPORT
30710 + /* i_generation */
30711 + /* todo: make xigen file an array to support many inode numbers */
30712 + struct file *si_xigen;
30713 + atomic_t si_xigen_next;
30716 + /* dirty trick to support atomic_open */
30717 + struct hlist_bl_head si_aopen;
30719 + /* vdir parameters */
30720 + unsigned long si_rdcache; /* max cache time in jiffies */
30721 + unsigned int si_rdblk; /* deblk size */
30722 + unsigned int si_rdhash; /* hash size */
30725 + * If the number of whiteouts are larger than si_dirwh, leave all of
30726 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30727 + * future fsck.aufs or kernel thread will remove them later.
30728 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30730 + unsigned int si_dirwh;
30732 + /* pseudo_link list */
30733 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30734 + wait_queue_head_t si_plink_wq;
30735 + spinlock_t si_plink_maint_lock;
30736 + pid_t si_plink_maint_pid;
30739 + struct hlist_bl_head si_files;
30741 + /* with/without getattr, brother of sb->s_d_op */
30742 + struct inode_operations *si_iop_array;
30745 + * sysfs and lifetime management.
30746 + * this is not a small structure and it may be a waste of memory in case
30747 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30748 + * but using sysfs is majority.
30750 + struct kobject si_kobj;
30751 +#ifdef CONFIG_DEBUG_FS
30752 + struct dentry *si_dbgaufs;
30753 + struct dentry *si_dbgaufs_plink;
30754 + struct dentry *si_dbgaufs_xib;
30755 +#ifdef CONFIG_AUFS_EXPORT
30756 + struct dentry *si_dbgaufs_xigen;
30760 +#ifdef CONFIG_AUFS_SBILIST
30761 + struct hlist_bl_node si_list;
30764 + /* dirty, necessary for unmounting, sysfs and sysrq */
30765 + struct super_block *si_sb;
30768 +/* sbinfo status flags */
30770 + * set true when refresh_dirs() failed at remount time.
30771 + * then try refreshing dirs at access time again.
30772 + * if it is false, refreshing dirs at access time is unnecessary
30774 +#define AuSi_FAILED_REFRESH_DIR 1
30775 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30776 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30778 +#ifndef CONFIG_AUFS_FHSM
30780 +#define AuSi_FHSM 0
30783 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30784 + unsigned int flag)
30786 + AuRwMustAnyLock(&sbi->si_rwsem);
30787 + return sbi->au_si_status & flag;
30789 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30790 +#define au_fset_si(sbinfo, name) do { \
30791 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30792 + (sbinfo)->au_si_status |= AuSi_##name; \
30794 +#define au_fclr_si(sbinfo, name) do { \
30795 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30796 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30799 +/* ---------------------------------------------------------------------- */
30801 +/* policy to select one among writable branches */
30802 +#define AuWbrCopyup(sbinfo, ...) \
30803 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30804 +#define AuWbrCreate(sbinfo, ...) \
30805 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30807 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30808 +#define AuLock_DW 1 /* write-lock dentry */
30809 +#define AuLock_IR (1 << 1) /* read-lock inode */
30810 +#define AuLock_IW (1 << 2) /* write-lock inode */
30811 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30812 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30813 + /* except RENAME_EXCHANGE */
30814 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30815 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30816 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30817 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30818 +#define au_fset_lock(flags, name) \
30819 + do { (flags) |= AuLock_##name; } while (0)
30820 +#define au_fclr_lock(flags, name) \
30821 + do { (flags) &= ~AuLock_##name; } while (0)
30823 +/* ---------------------------------------------------------------------- */
30826 +extern struct file_system_type aufs_fs_type;
30827 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30828 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30829 + unsigned long long max, void *arg);
30830 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30831 + struct super_block *sb, void *arg);
30832 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30833 +void au_iarray_free(struct inode **a, unsigned long long max);
30836 +void au_si_free(struct kobject *kobj);
30837 +int au_si_alloc(struct super_block *sb);
30838 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30840 +unsigned int au_sigen_inc(struct super_block *sb);
30841 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30843 +int si_read_lock(struct super_block *sb, int flags);
30844 +int si_write_lock(struct super_block *sb, int flags);
30845 +int aufs_read_lock(struct dentry *dentry, int flags);
30846 +void aufs_read_unlock(struct dentry *dentry, int flags);
30847 +void aufs_write_lock(struct dentry *dentry);
30848 +void aufs_write_unlock(struct dentry *dentry);
30849 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30850 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30852 +/* wbr_policy.c */
30853 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30854 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30855 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30856 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30857 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30860 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30862 +#ifdef CONFIG_AUFS_FHSM
30865 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30869 + spin_lock(&fhsm->fhsm_spin);
30870 + pid = fhsm->fhsm_pid;
30871 + spin_unlock(&fhsm->fhsm_spin);
30876 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30877 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30878 +int au_fhsm_fd(struct super_block *sb, int oflags);
30879 +int au_fhsm_br_alloc(struct au_branch *br);
30880 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30881 +void au_fhsm_fin(struct super_block *sb);
30882 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30883 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30884 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30886 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30888 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30889 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30890 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30891 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30892 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30893 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30894 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30895 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30896 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30899 +/* ---------------------------------------------------------------------- */
30901 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30903 + return sb->s_fs_info;
30906 +/* ---------------------------------------------------------------------- */
30908 +#ifdef CONFIG_AUFS_EXPORT
30909 +int au_test_nfsd(void);
30910 +void au_export_init(struct super_block *sb);
30911 +void au_xigen_inc(struct inode *inode);
30912 +int au_xigen_new(struct inode *inode);
30913 +int au_xigen_set(struct super_block *sb, struct path *path);
30914 +void au_xigen_clr(struct super_block *sb);
30916 +static inline int au_busy_or_stale(void)
30918 + if (!au_test_nfsd())
30923 +AuStubInt0(au_test_nfsd, void)
30924 +AuStubVoid(au_export_init, struct super_block *sb)
30925 +AuStubVoid(au_xigen_inc, struct inode *inode)
30926 +AuStubInt0(au_xigen_new, struct inode *inode)
30927 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30928 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30929 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30930 +#endif /* CONFIG_AUFS_EXPORT */
30932 +/* ---------------------------------------------------------------------- */
30934 +#ifdef CONFIG_AUFS_SBILIST
30936 +extern struct hlist_bl_head au_sbilist;
30938 +static inline void au_sbilist_init(void)
30940 + INIT_HLIST_BL_HEAD(&au_sbilist);
30943 +static inline void au_sbilist_add(struct super_block *sb)
30945 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30948 +static inline void au_sbilist_del(struct super_block *sb)
30950 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30953 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30954 +static inline void au_sbilist_lock(void)
30956 + hlist_bl_lock(&au_sbilist);
30959 +static inline void au_sbilist_unlock(void)
30961 + hlist_bl_unlock(&au_sbilist);
30963 +#define AuGFP_SBILIST GFP_ATOMIC
30965 +AuStubVoid(au_sbilist_lock, void)
30966 +AuStubVoid(au_sbilist_unlock, void)
30967 +#define AuGFP_SBILIST GFP_NOFS
30968 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30970 +AuStubVoid(au_sbilist_init, void)
30971 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30972 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30973 +AuStubVoid(au_sbilist_lock, void)
30974 +AuStubVoid(au_sbilist_unlock, void)
30975 +#define AuGFP_SBILIST GFP_NOFS
30978 +/* ---------------------------------------------------------------------- */
30980 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30983 + * This function is a dynamic '__init' function actually,
30984 + * so the tiny check for si_rwsem is unnecessary.
30986 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30987 +#ifdef CONFIG_DEBUG_FS
30988 + sbinfo->si_dbgaufs = NULL;
30989 + sbinfo->si_dbgaufs_plink = NULL;
30990 + sbinfo->si_dbgaufs_xib = NULL;
30991 +#ifdef CONFIG_AUFS_EXPORT
30992 + sbinfo->si_dbgaufs_xigen = NULL;
30997 +/* ---------------------------------------------------------------------- */
30999 +/* current->atomic_flags */
31000 +/* this value should never corrupt the ones defined in linux/sched.h */
31001 +#define PFA_AUFS 0x10
31003 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31004 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31005 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31007 +static inline int si_pid_test(struct super_block *sb)
31009 + return !!task_test_aufs(current);
31012 +static inline void si_pid_clr(struct super_block *sb)
31014 + AuDebugOn(!task_test_aufs(current));
31015 + task_clear_aufs(current);
31018 +static inline void si_pid_set(struct super_block *sb)
31020 + AuDebugOn(task_test_aufs(current));
31021 + task_set_aufs(current);
31024 +/* ---------------------------------------------------------------------- */
31026 +/* lock superblock. mainly for entry point functions */
31027 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31028 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31029 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31030 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31032 +#define __si_read_trylock_nested(sb) \
31033 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31034 +#define __si_write_trylock_nested(sb) \
31035 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31038 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31039 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31040 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31042 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31043 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31044 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31046 +static inline void si_noflush_read_lock(struct super_block *sb)
31048 + __si_read_lock(sb);
31052 +static inline int si_noflush_read_trylock(struct super_block *sb)
31056 + locked = __si_read_trylock(sb);
31062 +static inline void si_noflush_write_lock(struct super_block *sb)
31064 + __si_write_lock(sb);
31068 +static inline int si_noflush_write_trylock(struct super_block *sb)
31072 + locked = __si_write_trylock(sb);
31078 +#if 0 /* reserved */
31079 +static inline int si_read_trylock(struct super_block *sb, int flags)
31081 + if (au_ftest_lock(flags, FLUSH))
31082 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31083 + return si_noflush_read_trylock(sb);
31087 +static inline void si_read_unlock(struct super_block *sb)
31090 + __si_read_unlock(sb);
31093 +#if 0 /* reserved */
31094 +static inline int si_write_trylock(struct super_block *sb, int flags)
31096 + if (au_ftest_lock(flags, FLUSH))
31097 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31098 + return si_noflush_write_trylock(sb);
31102 +static inline void si_write_unlock(struct super_block *sb)
31105 + __si_write_unlock(sb);
31108 +#if 0 /* reserved */
31109 +static inline void si_downgrade_lock(struct super_block *sb)
31111 + __si_downgrade_lock(sb);
31115 +/* ---------------------------------------------------------------------- */
31117 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31119 + SiMustAnyLock(sb);
31120 + return au_sbi(sb)->si_bbot;
31123 +static inline unsigned int au_mntflags(struct super_block *sb)
31125 + SiMustAnyLock(sb);
31126 + return au_sbi(sb)->si_mntflags;
31129 +static inline unsigned int au_sigen(struct super_block *sb)
31131 + SiMustAnyLock(sb);
31132 + return au_sbi(sb)->si_generation;
31135 +static inline struct au_branch *au_sbr(struct super_block *sb,
31136 + aufs_bindex_t bindex)
31138 + SiMustAnyLock(sb);
31139 + return au_sbi(sb)->si_branch[0 + bindex];
31142 +static inline loff_t au_xi_maxent(struct super_block *sb)
31144 + SiMustAnyLock(sb);
31145 + return au_sbi(sb)->si_ximaxent;
31148 +#endif /* __KERNEL__ */
31149 +#endif /* __AUFS_SUPER_H__ */
31150 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31151 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 08:00:00.000000000 +0800
31152 +++ linux/fs/aufs/sysaufs.c 2019-07-11 21:21:54.382384486 +0800
31154 +// SPDX-License-Identifier: GPL-2.0
31156 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31158 + * This program, aufs is free software; you can redistribute it and/or modify
31159 + * it under the terms of the GNU General Public License as published by
31160 + * the Free Software Foundation; either version 2 of the License, or
31161 + * (at your option) any later version.
31163 + * This program is distributed in the hope that it will be useful,
31164 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31165 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31166 + * GNU General Public License for more details.
31168 + * You should have received a copy of the GNU General Public License
31169 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31173 + * sysfs interface and lifetime management
31174 + * they are necessary regardless sysfs is disabled.
31177 +#include <linux/random.h>
31180 +unsigned long sysaufs_si_mask;
31181 +struct kset *sysaufs_kset;
31183 +#define AuSiAttr(_name) { \
31184 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31185 + .show = sysaufs_si_##_name, \
31188 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31189 +struct attribute *sysaufs_si_attrs[] = {
31190 + &sysaufs_si_attr_xi_path.attr,
31194 +static const struct sysfs_ops au_sbi_ops = {
31195 + .show = sysaufs_si_show
31198 +static struct kobj_type au_sbi_ktype = {
31199 + .release = au_si_free,
31200 + .sysfs_ops = &au_sbi_ops,
31201 + .default_attrs = sysaufs_si_attrs
31204 +/* ---------------------------------------------------------------------- */
31206 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31210 + sbinfo->si_kobj.kset = sysaufs_kset;
31211 + /* cf. sysaufs_name() */
31212 + err = kobject_init_and_add
31213 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31214 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31219 +void sysaufs_fin(void)
31221 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31222 + kset_unregister(sysaufs_kset);
31225 +int __init sysaufs_init(void)
31230 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31231 + } while (!sysaufs_si_mask);
31234 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31235 + if (unlikely(!sysaufs_kset))
31237 + err = PTR_ERR(sysaufs_kset);
31238 + if (IS_ERR(sysaufs_kset))
31240 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31241 + if (unlikely(err))
31242 + kset_unregister(sysaufs_kset);
31247 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31248 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 08:00:00.000000000 +0800
31249 +++ linux/fs/aufs/sysaufs.h 2019-07-11 21:21:54.382384486 +0800
31251 +/* SPDX-License-Identifier: GPL-2.0 */
31253 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31255 + * This program, aufs is free software; you can redistribute it and/or modify
31256 + * it under the terms of the GNU General Public License as published by
31257 + * the Free Software Foundation; either version 2 of the License, or
31258 + * (at your option) any later version.
31260 + * This program is distributed in the hope that it will be useful,
31261 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31262 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31263 + * GNU General Public License for more details.
31265 + * You should have received a copy of the GNU General Public License
31266 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31270 + * sysfs interface and mount lifetime management
31273 +#ifndef __SYSAUFS_H__
31274 +#define __SYSAUFS_H__
31278 +#include <linux/sysfs.h>
31279 +#include "module.h"
31281 +struct super_block;
31284 +struct sysaufs_si_attr {
31285 + struct attribute attr;
31286 + int (*show)(struct seq_file *seq, struct super_block *sb);
31289 +/* ---------------------------------------------------------------------- */
31292 +extern unsigned long sysaufs_si_mask;
31293 +extern struct kset *sysaufs_kset;
31294 +extern struct attribute *sysaufs_si_attrs[];
31295 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31296 +int __init sysaufs_init(void);
31297 +void sysaufs_fin(void);
31299 +/* ---------------------------------------------------------------------- */
31301 +/* some people doesn't like to show a pointer in kernel */
31302 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31304 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31307 +#define SysaufsSiNamePrefix "si_"
31308 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31309 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31311 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31312 + sysaufs_si_id(sbinfo));
31316 +#ifdef CONFIG_SYSFS
31318 +extern struct attribute_group *sysaufs_attr_group;
31320 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31321 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31323 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31324 +#ifdef CONFIG_COMPAT
31325 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31328 +void sysaufs_br_init(struct au_branch *br);
31329 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31330 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31332 +#define sysaufs_brs_init() do {} while (0)
31335 +#define sysaufs_attr_group NULL
31337 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31338 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31339 + struct attribute *attr, char *buf)
31340 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31341 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31342 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31344 +static inline void sysaufs_brs_init(void)
31349 +#endif /* CONFIG_SYSFS */
31351 +#endif /* __KERNEL__ */
31352 +#endif /* __SYSAUFS_H__ */
31353 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31354 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 08:00:00.000000000 +0800
31355 +++ linux/fs/aufs/sysfs.c 2019-07-11 21:21:54.382384486 +0800
31357 +// SPDX-License-Identifier: GPL-2.0
31359 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31361 + * This program, aufs is free software; you can redistribute it and/or modify
31362 + * it under the terms of the GNU General Public License as published by
31363 + * the Free Software Foundation; either version 2 of the License, or
31364 + * (at your option) any later version.
31366 + * This program is distributed in the hope that it will be useful,
31367 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31368 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31369 + * GNU General Public License for more details.
31371 + * You should have received a copy of the GNU General Public License
31372 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31376 + * sysfs interface
31379 +#include <linux/compat.h>
31380 +#include <linux/seq_file.h>
31383 +#ifdef CONFIG_AUFS_FS_MODULE
31384 +/* this entry violates the "one line per file" policy of sysfs */
31385 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31389 + static char *conf =
31390 +/* this file is generated at compiling */
31391 +#include "conf.str"
31394 + err = snprintf(buf, PAGE_SIZE, conf);
31395 + if (unlikely(err >= PAGE_SIZE))
31400 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31403 +static struct attribute *au_attr[] = {
31404 +#ifdef CONFIG_AUFS_FS_MODULE
31405 + &au_config_attr.attr,
31407 + NULL, /* need to NULL terminate the list of attributes */
31410 +static struct attribute_group sysaufs_attr_group_body = {
31414 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31416 +/* ---------------------------------------------------------------------- */
31418 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31422 + SiMustAnyLock(sb);
31425 + if (au_opt_test(au_mntflags(sb), XINO)) {
31426 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31427 + seq_putc(seq, '\n');
31433 + * the lifetime of branch is independent from the entry under sysfs.
31434 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31437 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31438 + aufs_bindex_t bindex, int idx)
31441 + struct path path;
31442 + struct dentry *root;
31443 + struct au_branch *br;
31444 + au_br_perm_str_t perm;
31446 + AuDbg("b%d\n", bindex);
31449 + root = sb->s_root;
31450 + di_read_lock_parent(root, !AuLock_IR);
31451 + br = au_sbr(sb, bindex);
31454 + case AuBrSysfs_BR:
31455 + path.mnt = au_br_mnt(br);
31456 + path.dentry = au_h_dptr(root, bindex);
31457 + err = au_seq_path(seq, &path);
31459 + au_optstr_br_perm(&perm, br->br_perm);
31460 + seq_printf(seq, "=%s\n", perm.a);
31463 + case AuBrSysfs_BRID:
31464 + seq_printf(seq, "%d\n", br->br_id);
31467 + di_read_unlock(root, !AuLock_IR);
31468 + if (unlikely(err || seq_has_overflowed(seq)))
31474 +/* ---------------------------------------------------------------------- */
31476 +static struct seq_file *au_seq(char *p, ssize_t len)
31478 + struct seq_file *seq;
31480 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31482 + /* mutex_init(&seq.lock); */
31485 + return seq; /* success */
31488 + seq = ERR_PTR(-ENOMEM);
31492 +#define SysaufsBr_PREFIX "br"
31493 +#define SysaufsBrid_PREFIX "brid"
31495 +/* todo: file size may exceed PAGE_SIZE */
31496 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31502 + aufs_bindex_t bbot;
31503 + struct au_sbinfo *sbinfo;
31504 + struct super_block *sb;
31505 + struct seq_file *seq;
31507 + struct attribute **cattr;
31509 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31510 + sb = sbinfo->si_sb;
31513 + * prevent a race condition between sysfs and aufs.
31514 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31515 + * prohibits maintaining the sysfs entries.
31516 + * hew we acquire read lock after sysfs_get_active_two().
31517 + * on the other hand, the remount process may maintain the sysfs/aufs
31518 + * entries after acquiring write lock.
31519 + * it can cause a deadlock.
31520 + * simply we gave up processing read here.
31523 + if (unlikely(!si_noflush_read_trylock(sb)))
31526 + seq = au_seq(buf, PAGE_SIZE);
31527 + err = PTR_ERR(seq);
31531 + name = (void *)attr->name;
31532 + cattr = sysaufs_si_attrs;
31534 + if (!strcmp(name, (*cattr)->name)) {
31535 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31542 + if (!strncmp(name, SysaufsBrid_PREFIX,
31543 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31544 + idx = AuBrSysfs_BRID;
31545 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31546 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31547 + sizeof(SysaufsBr_PREFIX) - 1)) {
31548 + idx = AuBrSysfs_BR;
31549 + name += sizeof(SysaufsBr_PREFIX) - 1;
31553 + err = kstrtol(name, 10, &l);
31555 + bbot = au_sbbot(sb);
31557 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31564 + err = seq->count;
31565 + /* sysfs limit */
31566 + if (unlikely(err == PAGE_SIZE))
31569 + au_kfree_rcu(seq);
31571 + si_read_unlock(sb);
31576 +/* ---------------------------------------------------------------------- */
31578 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31582 + aufs_bindex_t bindex, bbot;
31585 + struct seq_file *seq;
31586 + struct au_branch *br;
31588 + si_read_lock(sb, AuLock_FLUSH);
31589 + bbot = au_sbbot(sb);
31595 + buf = (void *)__get_free_page(GFP_NOFS);
31596 + if (unlikely(!buf))
31599 + seq = au_seq(buf, PAGE_SIZE);
31600 + err = PTR_ERR(seq);
31604 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31605 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31606 + /* VERIFY_WRITE */
31607 + err = !access_ok(arg, sizeof(*arg));
31608 + if (unlikely(err))
31611 + br = au_sbr(sb, bindex);
31612 + brid = br->br_id;
31613 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31614 + err = __put_user(brid, &arg->id);
31615 + if (unlikely(err))
31618 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31619 + err = __put_user(br->br_perm, &arg->perm);
31620 + if (unlikely(err))
31623 + err = au_seq_path(seq, &br->br_path);
31624 + if (unlikely(err))
31626 + seq_putc(seq, '\0');
31627 + if (!seq_has_overflowed(seq)) {
31628 + err = copy_to_user(arg->path, seq->buf, seq->count);
31630 + if (unlikely(err))
31637 + if (unlikely(err))
31641 + au_kfree_rcu(seq);
31643 + free_page((unsigned long)buf);
31645 + si_read_unlock(sb);
31649 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31651 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31654 +#ifdef CONFIG_COMPAT
31655 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31657 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31661 +/* ---------------------------------------------------------------------- */
31663 +void sysaufs_br_init(struct au_branch *br)
31666 + struct au_brsysfs *br_sysfs;
31667 + struct attribute *attr;
31669 + br_sysfs = br->br_sysfs;
31670 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31671 + attr = &br_sysfs->attr;
31672 + sysfs_attr_init(attr);
31673 + attr->name = br_sysfs->name;
31674 + attr->mode = 0444;
31679 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31681 + struct au_branch *br;
31682 + struct kobject *kobj;
31683 + struct au_brsysfs *br_sysfs;
31685 + aufs_bindex_t bbot;
31687 + if (!sysaufs_brs)
31690 + kobj = &au_sbi(sb)->si_kobj;
31691 + bbot = au_sbbot(sb);
31692 + for (; bindex <= bbot; bindex++) {
31693 + br = au_sbr(sb, bindex);
31694 + br_sysfs = br->br_sysfs;
31695 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31696 + sysfs_remove_file(kobj, &br_sysfs->attr);
31702 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31705 + aufs_bindex_t bbot;
31706 + struct kobject *kobj;
31707 + struct au_branch *br;
31708 + struct au_brsysfs *br_sysfs;
31710 + if (!sysaufs_brs)
31713 + kobj = &au_sbi(sb)->si_kobj;
31714 + bbot = au_sbbot(sb);
31715 + for (; bindex <= bbot; bindex++) {
31716 + br = au_sbr(sb, bindex);
31717 + br_sysfs = br->br_sysfs;
31718 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31719 + SysaufsBr_PREFIX "%d", bindex);
31720 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31721 + SysaufsBrid_PREFIX "%d", bindex);
31722 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31723 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31724 + if (unlikely(err))
31725 + pr_warn("failed %s under sysfs(%d)\n",
31726 + br_sysfs->name, err);
31731 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31732 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 08:00:00.000000000 +0800
31733 +++ linux/fs/aufs/sysrq.c 2019-07-11 21:21:54.382384486 +0800
31735 +// SPDX-License-Identifier: GPL-2.0
31737 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31739 + * This program, aufs is free software; you can redistribute it and/or modify
31740 + * it under the terms of the GNU General Public License as published by
31741 + * the Free Software Foundation; either version 2 of the License, or
31742 + * (at your option) any later version.
31744 + * This program is distributed in the hope that it will be useful,
31745 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31746 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31747 + * GNU General Public License for more details.
31749 + * You should have received a copy of the GNU General Public License
31750 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31754 + * magic sysrq handler
31757 +/* #include <linux/sysrq.h> */
31758 +#include <linux/writeback.h>
31761 +/* ---------------------------------------------------------------------- */
31763 +static void sysrq_sb(struct super_block *sb)
31766 + struct au_sbinfo *sbinfo;
31767 + struct file *file;
31768 + struct hlist_bl_head *files;
31769 + struct hlist_bl_node *pos;
31770 + struct au_finfo *finfo;
31772 + plevel = au_plevel;
31773 + au_plevel = KERN_WARNING;
31775 + /* since we define pr_fmt, call printk directly */
31776 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31778 + sbinfo = au_sbi(sb);
31779 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31780 + pr("superblock\n");
31784 + pr("root dentry\n");
31785 + au_dpri_dentry(sb->s_root);
31786 + pr("root inode\n");
31787 + au_dpri_inode(d_inode(sb->s_root));
31792 + int err, i, j, ndentry;
31793 + struct au_dcsub_pages dpages;
31794 + struct au_dpage *dpage;
31796 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31797 + if (unlikely(err))
31799 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31801 + for (i = 0; i < dpages.ndpage; i++) {
31802 + dpage = dpages.dpages + i;
31803 + ndentry = dpage->ndentry;
31804 + for (j = 0; j < ndentry; j++)
31805 + au_dpri_dentry(dpage->dentries[j]);
31807 + au_dpages_free(&dpages);
31815 + pr("isolated inode\n");
31816 + spin_lock(&sb->s_inode_list_lock);
31817 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31818 + spin_lock(&i->i_lock);
31819 + if (1 || hlist_empty(&i->i_dentry))
31820 + au_dpri_inode(i);
31821 + spin_unlock(&i->i_lock);
31823 + spin_unlock(&sb->s_inode_list_lock);
31827 + files = &au_sbi(sb)->si_files;
31828 + hlist_bl_lock(files);
31829 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31832 + file = finfo->fi_file;
31833 + mode = file_inode(file)->i_mode;
31834 + if (!special_file(mode))
31835 + au_dpri_file(file);
31837 + hlist_bl_unlock(files);
31841 + au_plevel = plevel;
31844 +/* ---------------------------------------------------------------------- */
31846 +/* module parameter */
31847 +static char *aufs_sysrq_key = "a";
31848 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31849 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31851 +static void au_sysrq(int key __maybe_unused)
31853 + struct au_sbinfo *sbinfo;
31854 + struct hlist_bl_node *pos;
31857 + au_sbilist_lock();
31858 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31859 + sysrq_sb(sbinfo->si_sb);
31860 + au_sbilist_unlock();
31864 +static struct sysrq_key_op au_sysrq_op = {
31865 + .handler = au_sysrq,
31866 + .help_msg = "Aufs",
31867 + .action_msg = "Aufs",
31868 + .enable_mask = SYSRQ_ENABLE_DUMP
31871 +/* ---------------------------------------------------------------------- */
31873 +int __init au_sysrq_init(void)
31879 + key = *aufs_sysrq_key;
31880 + if ('a' <= key && key <= 'z')
31881 + err = register_sysrq_key(key, &au_sysrq_op);
31882 + if (unlikely(err))
31883 + pr_err("err %d, sysrq=%c\n", err, key);
31887 +void au_sysrq_fin(void)
31891 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31892 + if (unlikely(err))
31893 + pr_err("err %d (ignored)\n", err);
31895 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31896 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 08:00:00.000000000 +0800
31897 +++ linux/fs/aufs/vdir.c 2019-07-11 21:21:54.382384486 +0800
31899 +// SPDX-License-Identifier: GPL-2.0
31901 + * Copyright (C) 2005-2019 Junjiro R. Okajima
31903 + * This program, aufs is free software; you can redistribute it and/or modify
31904 + * it under the terms of the GNU General Public License as published by
31905 + * the Free Software Foundation; either version 2 of the License, or
31906 + * (at your option) any later version.
31908 + * This program is distributed in the hope that it will be useful,
31909 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31910 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31911 + * GNU General Public License for more details.
31913 + * You should have received a copy of the GNU General Public License
31914 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31918 + * virtual or vertical directory
31921 +#include <linux/iversion.h>
31924 +static unsigned int calc_size(int nlen)
31926 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31929 +static int set_deblk_end(union au_vdir_deblk_p *p,
31930 + union au_vdir_deblk_p *deblk_end)
31932 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31933 + p->de->de_str.len = 0;
31937 + return -1; /* error */
31940 +/* returns true or false */
31941 +static int is_deblk_end(union au_vdir_deblk_p *p,
31942 + union au_vdir_deblk_p *deblk_end)
31944 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31945 + return !p->de->de_str.len;
31949 +static unsigned char *last_deblk(struct au_vdir *vdir)
31951 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31954 +/* ---------------------------------------------------------------------- */
31956 +/* estimate the appropriate size for name hash table */
31957 +unsigned int au_rdhash_est(loff_t sz)
31965 + if (sz < AUFS_RDHASH_DEF)
31966 + n = AUFS_RDHASH_DEF;
31967 + /* pr_info("n %u\n", n); */
31972 + * the allocated memory has to be freed by
31973 + * au_nhash_wh_free() or au_nhash_de_free().
31975 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31977 + struct hlist_head *head;
31981 + sz = sizeof(*nhash->nh_head) * num_hash;
31982 + head = kmalloc(sz, gfp);
31984 + nhash->nh_num = num_hash;
31985 + nhash->nh_head = head;
31986 + for (u = 0; u < num_hash; u++)
31987 + INIT_HLIST_HEAD(head++);
31988 + return 0; /* success */
31994 +static void nhash_count(struct hlist_head *head)
31998 + struct hlist_node *pos;
32001 + hlist_for_each(pos, head)
32003 + pr_info("%lu\n", n);
32007 +static void au_nhash_wh_do_free(struct hlist_head *head)
32009 + struct au_vdir_wh *pos;
32010 + struct hlist_node *node;
32012 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32013 + au_kfree_rcu(pos);
32016 +static void au_nhash_de_do_free(struct hlist_head *head)
32018 + struct au_vdir_dehstr *pos;
32019 + struct hlist_node *node;
32021 + hlist_for_each_entry_safe(pos, node, head, hash)
32022 + au_cache_free_vdir_dehstr(pos);
32025 +static void au_nhash_do_free(struct au_nhash *nhash,
32026 + void (*free)(struct hlist_head *head))
32029 + struct hlist_head *head;
32031 + n = nhash->nh_num;
32035 + head = nhash->nh_head;
32036 + while (n-- > 0) {
32037 + nhash_count(head);
32040 + au_kfree_try_rcu(nhash->nh_head);
32043 +void au_nhash_wh_free(struct au_nhash *whlist)
32045 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32048 +static void au_nhash_de_free(struct au_nhash *delist)
32050 + au_nhash_do_free(delist, au_nhash_de_do_free);
32053 +/* ---------------------------------------------------------------------- */
32055 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32059 + unsigned int u, n;
32060 + struct hlist_head *head;
32061 + struct au_vdir_wh *pos;
32064 + n = whlist->nh_num;
32065 + head = whlist->nh_head;
32066 + for (u = 0; u < n; u++, head++)
32067 + hlist_for_each_entry(pos, head, wh_hash)
32068 + if (pos->wh_bindex == btgt && ++num > limit)
32073 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32074 + unsigned char *name,
32075 + unsigned int len)
32078 + /* const unsigned int magic_bit = 12; */
32080 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32087 + /* v = hash_long(v, magic_bit); */
32088 + v %= nhash->nh_num;
32089 + return nhash->nh_head + v;
32092 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32095 + return str->len == nlen && !memcmp(str->name, name, nlen);
32098 +/* returns found or not */
32099 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32101 + struct hlist_head *head;
32102 + struct au_vdir_wh *pos;
32103 + struct au_vdir_destr *str;
32105 + head = au_name_hash(whlist, name, nlen);
32106 + hlist_for_each_entry(pos, head, wh_hash) {
32107 + str = &pos->wh_str;
32108 + AuDbg("%.*s\n", str->len, str->name);
32109 + if (au_nhash_test_name(str, name, nlen))
32115 +/* returns found(true) or not */
32116 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32118 + struct hlist_head *head;
32119 + struct au_vdir_dehstr *pos;
32120 + struct au_vdir_destr *str;
32122 + head = au_name_hash(delist, name, nlen);
32123 + hlist_for_each_entry(pos, head, hash) {
32125 + AuDbg("%.*s\n", str->len, str->name);
32126 + if (au_nhash_test_name(str, name, nlen))
32132 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32133 + unsigned char d_type)
32135 +#ifdef CONFIG_AUFS_SHWH
32136 + wh->wh_ino = ino;
32137 + wh->wh_type = d_type;
32141 +/* ---------------------------------------------------------------------- */
32143 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32144 + unsigned int d_type, aufs_bindex_t bindex,
32145 + unsigned char shwh)
32148 + struct au_vdir_destr *str;
32149 + struct au_vdir_wh *wh;
32151 + AuDbg("%.*s\n", nlen, name);
32152 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32155 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32156 + if (unlikely(!wh))
32160 + wh->wh_bindex = bindex;
32162 + au_shwh_init_wh(wh, ino, d_type);
32163 + str = &wh->wh_str;
32165 + memcpy(str->name, name, nlen);
32166 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32173 +static int append_deblk(struct au_vdir *vdir)
32176 + unsigned long ul;
32177 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32178 + union au_vdir_deblk_p p, deblk_end;
32179 + unsigned char **o;
32182 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32183 + GFP_NOFS, /*may_shrink*/0);
32184 + if (unlikely(!o))
32187 + vdir->vd_deblk = o;
32188 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32190 + ul = vdir->vd_nblk++;
32191 + vdir->vd_deblk[ul] = p.deblk;
32192 + vdir->vd_last.ul = ul;
32193 + vdir->vd_last.p.deblk = p.deblk;
32194 + deblk_end.deblk = p.deblk + deblk_sz;
32195 + err = set_deblk_end(&p, &deblk_end);
32202 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32203 + unsigned int d_type, struct au_nhash *delist)
32207 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32208 + union au_vdir_deblk_p p, *room, deblk_end;
32209 + struct au_vdir_dehstr *dehstr;
32211 + p.deblk = last_deblk(vdir);
32212 + deblk_end.deblk = p.deblk + deblk_sz;
32213 + room = &vdir->vd_last.p;
32214 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32215 + || !is_deblk_end(room, &deblk_end));
32217 + sz = calc_size(nlen);
32218 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32219 + err = append_deblk(vdir);
32220 + if (unlikely(err))
32223 + p.deblk = last_deblk(vdir);
32224 + deblk_end.deblk = p.deblk + deblk_sz;
32226 + AuDebugOn(room->deblk != p.deblk);
32230 + dehstr = au_cache_alloc_vdir_dehstr();
32231 + if (unlikely(!dehstr))
32234 + dehstr->str = &room->de->de_str;
32235 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32236 + room->de->de_ino = ino;
32237 + room->de->de_type = d_type;
32238 + room->de->de_str.len = nlen;
32239 + memcpy(room->de->de_str.name, name, nlen);
32242 + room->deblk += sz;
32243 + if (unlikely(set_deblk_end(room, &deblk_end)))
32244 + err = append_deblk(vdir);
32251 +/* ---------------------------------------------------------------------- */
32253 +void au_vdir_free(struct au_vdir *vdir)
32255 + unsigned char **deblk;
32257 + deblk = vdir->vd_deblk;
32258 + while (vdir->vd_nblk--)
32259 + au_kfree_try_rcu(*deblk++);
32260 + au_kfree_try_rcu(vdir->vd_deblk);
32261 + au_cache_free_vdir(vdir);
32264 +static struct au_vdir *alloc_vdir(struct file *file)
32266 + struct au_vdir *vdir;
32267 + struct super_block *sb;
32270 + sb = file->f_path.dentry->d_sb;
32271 + SiMustAnyLock(sb);
32274 + vdir = au_cache_alloc_vdir();
32275 + if (unlikely(!vdir))
32278 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32279 + if (unlikely(!vdir->vd_deblk))
32282 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32283 + if (!vdir->vd_deblk_sz) {
32284 + /* estimate the appropriate size for deblk */
32285 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32286 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32288 + vdir->vd_nblk = 0;
32289 + vdir->vd_version = 0;
32290 + vdir->vd_jiffy = 0;
32291 + err = append_deblk(vdir);
32293 + return vdir; /* success */
32295 + au_kfree_try_rcu(vdir->vd_deblk);
32298 + au_cache_free_vdir(vdir);
32300 + vdir = ERR_PTR(err);
32304 +static int reinit_vdir(struct au_vdir *vdir)
32307 + union au_vdir_deblk_p p, deblk_end;
32309 + while (vdir->vd_nblk > 1) {
32310 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32311 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32314 + p.deblk = vdir->vd_deblk[0];
32315 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32316 + err = set_deblk_end(&p, &deblk_end);
32317 + /* keep vd_dblk_sz */
32318 + vdir->vd_last.ul = 0;
32319 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32320 + vdir->vd_version = 0;
32321 + vdir->vd_jiffy = 0;
32326 +/* ---------------------------------------------------------------------- */
32328 +#define AuFillVdir_CALLED 1
32329 +#define AuFillVdir_WHABLE (1 << 1)
32330 +#define AuFillVdir_SHWH (1 << 2)
32331 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32332 +#define au_fset_fillvdir(flags, name) \
32333 + do { (flags) |= AuFillVdir_##name; } while (0)
32334 +#define au_fclr_fillvdir(flags, name) \
32335 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32337 +#ifndef CONFIG_AUFS_SHWH
32338 +#undef AuFillVdir_SHWH
32339 +#define AuFillVdir_SHWH 0
32342 +struct fillvdir_arg {
32343 + struct dir_context ctx;
32344 + struct file *file;
32345 + struct au_vdir *vdir;
32346 + struct au_nhash delist;
32347 + struct au_nhash whlist;
32348 + aufs_bindex_t bindex;
32349 + unsigned int flags;
32353 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32354 + loff_t offset __maybe_unused, u64 h_ino,
32355 + unsigned int d_type)
32357 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32358 + char *name = (void *)__name;
32359 + struct super_block *sb;
32361 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32364 + sb = arg->file->f_path.dentry->d_sb;
32365 + au_fset_fillvdir(arg->flags, CALLED);
32367 + if (nlen <= AUFS_WH_PFX_LEN
32368 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32369 + if (test_known(&arg->delist, name, nlen)
32370 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32371 + goto out; /* already exists or whiteouted */
32373 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32375 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32376 + d_type = DT_UNKNOWN;
32377 + arg->err = append_de(arg->vdir, name, nlen, ino,
32378 + d_type, &arg->delist);
32380 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32381 + name += AUFS_WH_PFX_LEN;
32382 + nlen -= AUFS_WH_PFX_LEN;
32383 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32384 + goto out; /* already whiteouted */
32386 + ino = 0; /* just to suppress a warning */
32388 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32391 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32392 + d_type = DT_UNKNOWN;
32393 + arg->err = au_nhash_append_wh
32394 + (&arg->whlist, name, nlen, ino, d_type,
32395 + arg->bindex, shwh);
32401 + arg->vdir->vd_jiffy = jiffies;
32403 + AuTraceErr(arg->err);
32407 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32408 + struct au_nhash *whlist, struct au_nhash *delist)
32410 +#ifdef CONFIG_AUFS_SHWH
32412 + unsigned int nh, u;
32413 + struct hlist_head *head;
32414 + struct au_vdir_wh *pos;
32415 + struct hlist_node *n;
32417 + struct au_vdir_destr *destr;
32419 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32422 + o = p = (void *)__get_free_page(GFP_NOFS);
32423 + if (unlikely(!p))
32427 + nh = whlist->nh_num;
32428 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32429 + p += AUFS_WH_PFX_LEN;
32430 + for (u = 0; u < nh; u++) {
32431 + head = whlist->nh_head + u;
32432 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32433 + destr = &pos->wh_str;
32434 + memcpy(p, destr->name, destr->len);
32435 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32436 + pos->wh_ino, pos->wh_type, delist);
32437 + if (unlikely(err))
32442 + free_page((unsigned long)o);
32452 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32455 + unsigned int rdhash;
32457 + aufs_bindex_t bbot, bindex, btop;
32458 + unsigned char shwh;
32459 + struct file *hf, *file;
32460 + struct super_block *sb;
32462 + file = arg->file;
32463 + sb = file->f_path.dentry->d_sb;
32464 + SiMustAnyLock(sb);
32466 + rdhash = au_sbi(sb)->si_rdhash;
32468 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32469 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32470 + if (unlikely(err))
32472 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32473 + if (unlikely(err))
32479 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32481 + au_fset_fillvdir(arg->flags, SHWH);
32483 + btop = au_fbtop(file);
32484 + bbot = au_fbbot_dir(file);
32485 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32486 + hf = au_hf_dir(file, bindex);
32490 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32492 + if (unlikely(offset))
32495 + arg->bindex = bindex;
32496 + au_fclr_fillvdir(arg->flags, WHABLE);
32498 + || (bindex != bbot
32499 + && au_br_whable(au_sbr_perm(sb, bindex))))
32500 + au_fset_fillvdir(arg->flags, WHABLE);
32503 + au_fclr_fillvdir(arg->flags, CALLED);
32505 + err = vfsub_iterate_dir(hf, &arg->ctx);
32508 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32511 + * dir_relax() may be good for concurrency, but aufs should not
32512 + * use it since it will cause a lockdep problem.
32516 + if (!err && shwh)
32517 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32519 + au_nhash_wh_free(&arg->whlist);
32522 + au_nhash_de_free(&arg->delist);
32527 +static int read_vdir(struct file *file, int may_read)
32530 + unsigned long expire;
32531 + unsigned char do_read;
32532 + struct fillvdir_arg arg = {
32534 + .actor = fillvdir
32537 + struct inode *inode;
32538 + struct au_vdir *vdir, *allocated;
32541 + inode = file_inode(file);
32542 + IMustLock(inode);
32543 + IiMustWriteLock(inode);
32544 + SiMustAnyLock(inode->i_sb);
32546 + allocated = NULL;
32548 + expire = au_sbi(inode->i_sb)->si_rdcache;
32549 + vdir = au_ivdir(inode);
32552 + vdir = alloc_vdir(file);
32553 + err = PTR_ERR(vdir);
32554 + if (IS_ERR(vdir))
32557 + allocated = vdir;
32558 + } else if (may_read
32559 + && (!inode_eq_iversion(inode, vdir->vd_version)
32560 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32562 + err = reinit_vdir(vdir);
32563 + if (unlikely(err))
32568 + return 0; /* success */
32572 + err = au_do_read_vdir(&arg);
32574 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32575 + vdir->vd_version = inode_query_iversion(inode);
32576 + vdir->vd_last.ul = 0;
32577 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32579 + au_set_ivdir(inode, allocated);
32580 + } else if (allocated)
32581 + au_vdir_free(allocated);
32587 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32590 + unsigned long ul, n;
32591 + const unsigned int deblk_sz = src->vd_deblk_sz;
32593 + AuDebugOn(tgt->vd_nblk != 1);
32596 + if (tgt->vd_nblk < src->vd_nblk) {
32597 + unsigned char **p;
32599 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32600 + GFP_NOFS, /*may_shrink*/0);
32601 + if (unlikely(!p))
32603 + tgt->vd_deblk = p;
32606 + if (tgt->vd_deblk_sz != deblk_sz) {
32607 + unsigned char *p;
32609 + tgt->vd_deblk_sz = deblk_sz;
32610 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32611 + /*may_shrink*/1);
32612 + if (unlikely(!p))
32614 + tgt->vd_deblk[0] = p;
32616 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32617 + tgt->vd_version = src->vd_version;
32618 + tgt->vd_jiffy = src->vd_jiffy;
32620 + n = src->vd_nblk;
32621 + for (ul = 1; ul < n; ul++) {
32622 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32624 + if (unlikely(!tgt->vd_deblk[ul]))
32628 + tgt->vd_nblk = n;
32629 + tgt->vd_last.ul = tgt->vd_last.ul;
32630 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32631 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32632 + - src->vd_deblk[src->vd_last.ul];
32634 + return 0; /* success */
32637 + rerr = reinit_vdir(tgt);
32642 +int au_vdir_init(struct file *file)
32645 + struct inode *inode;
32646 + struct au_vdir *vdir_cache, *allocated;
32648 + /* test file->f_pos here instead of ctx->pos */
32649 + err = read_vdir(file, !file->f_pos);
32650 + if (unlikely(err))
32653 + allocated = NULL;
32654 + vdir_cache = au_fvdir_cache(file);
32655 + if (!vdir_cache) {
32656 + vdir_cache = alloc_vdir(file);
32657 + err = PTR_ERR(vdir_cache);
32658 + if (IS_ERR(vdir_cache))
32660 + allocated = vdir_cache;
32661 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32662 + /* test file->f_pos here instead of ctx->pos */
32663 + err = reinit_vdir(vdir_cache);
32664 + if (unlikely(err))
32667 + return 0; /* success */
32669 + inode = file_inode(file);
32670 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32672 + file->f_version = inode_query_iversion(inode);
32674 + au_set_fvdir_cache(file, allocated);
32675 + } else if (allocated)
32676 + au_vdir_free(allocated);
32682 +static loff_t calc_offset(struct au_vdir *vdir)
32685 + union au_vdir_deblk_p p;
32687 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32688 + offset = vdir->vd_last.p.deblk - p.deblk;
32689 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32693 +/* returns true or false */
32694 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32697 + unsigned int deblk_sz;
32698 + unsigned long ul, n;
32700 + union au_vdir_deblk_p p, deblk_end;
32701 + struct au_vdir *vdir_cache;
32704 + vdir_cache = au_fvdir_cache(file);
32705 + offset = calc_offset(vdir_cache);
32706 + AuDbg("offset %lld\n", offset);
32707 + if (ctx->pos == offset)
32710 + vdir_cache->vd_last.ul = 0;
32711 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32716 + deblk_sz = vdir_cache->vd_deblk_sz;
32717 + ul = div64_u64(ctx->pos, deblk_sz);
32718 + AuDbg("ul %lu\n", ul);
32719 + if (ul >= vdir_cache->vd_nblk)
32722 + n = vdir_cache->vd_nblk;
32723 + for (; ul < n; ul++) {
32724 + p.deblk = vdir_cache->vd_deblk[ul];
32725 + deblk_end.deblk = p.deblk + deblk_sz;
32727 + offset *= deblk_sz;
32728 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32731 + l = calc_size(p.de->de_str.len);
32735 + if (!is_deblk_end(&p, &deblk_end)) {
32737 + vdir_cache->vd_last.ul = ul;
32738 + vdir_cache->vd_last.p = p;
32746 + AuDbg("valid %d\n", !valid);
32750 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32752 + unsigned int l, deblk_sz;
32753 + union au_vdir_deblk_p deblk_end;
32754 + struct au_vdir *vdir_cache;
32755 + struct au_vdir_de *de;
32757 + if (!seek_vdir(file, ctx))
32760 + vdir_cache = au_fvdir_cache(file);
32761 + deblk_sz = vdir_cache->vd_deblk_sz;
32763 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32764 + deblk_end.deblk += deblk_sz;
32765 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32766 + de = vdir_cache->vd_last.p.de;
32767 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32768 + de->de_str.len, de->de_str.name, ctx->pos,
32769 + (unsigned long)de->de_ino, de->de_type);
32770 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32771 + de->de_str.len, de->de_ino,
32773 + /* todo: ignore the error caused by udba? */
32774 + /* return err; */
32778 + l = calc_size(de->de_str.len);
32779 + vdir_cache->vd_last.p.deblk += l;
32782 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32783 + vdir_cache->vd_last.ul++;
32784 + vdir_cache->vd_last.p.deblk
32785 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32786 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32795 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32796 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 08:00:00.000000000 +0800
32797 +++ linux/fs/aufs/vfsub.c 2019-07-11 21:21:54.382384486 +0800
32799 +// SPDX-License-Identifier: GPL-2.0
32801 + * Copyright (C) 2005-2019 Junjiro R. Okajima
32803 + * This program, aufs is free software; you can redistribute it and/or modify
32804 + * it under the terms of the GNU General Public License as published by
32805 + * the Free Software Foundation; either version 2 of the License, or
32806 + * (at your option) any later version.
32808 + * This program is distributed in the hope that it will be useful,
32809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32811 + * GNU General Public License for more details.
32813 + * You should have received a copy of the GNU General Public License
32814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32818 + * sub-routines for VFS
32821 +#include <linux/mnt_namespace.h>
32822 +#include <linux/namei.h>
32823 +#include <linux/nsproxy.h>
32824 +#include <linux/security.h>
32825 +#include <linux/splice.h>
32828 +#ifdef CONFIG_AUFS_BR_FUSE
32829 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32831 + if (!au_test_fuse(h_sb) || !au_userns)
32834 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32838 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32843 + down_read(&h_sb->s_umount);
32844 + err = __sync_filesystem(h_sb, wait);
32845 + up_read(&h_sb->s_umount);
32851 +/* ---------------------------------------------------------------------- */
32853 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32857 + struct super_block *h_sb;
32859 + /* for remote fs, leave work for its getattr or d_revalidate */
32860 + /* for bad i_attr fs, handle them in aufs_getattr() */
32861 + /* still some fs may acquire i_mutex. we need to skip them */
32865 + h_sb = h_path->dentry->d_sb;
32866 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32868 + err = vfsub_getattr(h_path, &st);
32873 +/* ---------------------------------------------------------------------- */
32875 +struct file *vfsub_dentry_open(struct path *path, int flags)
32877 + struct file *file;
32879 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32881 + if (!IS_ERR_OR_NULL(file)
32882 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
32883 + i_readcount_inc(d_inode(path->dentry));
32888 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32890 + struct file *file;
32893 + file = filp_open(path,
32894 + oflags /* | __FMODE_NONOTIFY */,
32897 + if (IS_ERR(file))
32899 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32906 + * Ideally this function should call VFS:do_last() in order to keep all its
32907 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32908 + * structure such as nameidata. This is a second (or third) best approach.
32909 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32911 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32912 + struct vfsub_aopen_args *args)
32915 + struct au_branch *br = args->br;
32916 + struct file *file = args->file;
32917 + /* copied from linux/fs/namei.c:atomic_open() */
32918 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32921 + AuDebugOn(!dir->i_op->atomic_open);
32923 + err = au_br_test_oflag(args->open_flag, br);
32924 + if (unlikely(err))
32927 + au_lcnt_inc(&br->br_nfiles);
32928 + file->f_path.dentry = DENTRY_NOT_SET;
32929 + file->f_path.mnt = au_br_mnt(br);
32930 + AuDbg("%ps\n", dir->i_op->atomic_open);
32931 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32932 + args->create_mode);
32933 + if (unlikely(err < 0)) {
32934 + au_lcnt_dec(&br->br_nfiles);
32938 + /* temporary workaround for nfsv4 branch */
32939 + if (au_test_nfs(dir->i_sb))
32940 + nfs_mark_for_revalidate(dir);
32942 + if (file->f_mode & FMODE_CREATED)
32943 + fsnotify_create(dir, dentry);
32944 + if (!(file->f_mode & FMODE_OPENED)) {
32945 + au_lcnt_dec(&br->br_nfiles);
32949 + /* todo: call VFS:may_open() here */
32950 + /* todo: ima_file_check() too? */
32951 + if (!err && (args->open_flag & __FMODE_EXEC))
32952 + err = deny_write_access(file);
32954 + fsnotify_open(file);
32956 + au_lcnt_dec(&br->br_nfiles);
32957 + /* note that the file is created and still opened */
32963 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32967 + err = kern_path(name, flags, path);
32968 + if (!err && d_is_positive(path->dentry))
32969 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32973 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32974 + struct dentry *parent, int len)
32976 + struct path path = {
32980 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32981 + if (IS_ERR(path.dentry))
32983 + if (d_is_positive(path.dentry))
32984 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32987 + AuTraceErrPtr(path.dentry);
32988 + return path.dentry;
32991 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32994 + struct path path = {
32998 + /* VFS checks it too, but by WARN_ON_ONCE() */
32999 + IMustLock(d_inode(parent));
33001 + path.dentry = lookup_one_len(name, parent, len);
33002 + if (IS_ERR(path.dentry))
33004 + if (d_is_positive(path.dentry))
33005 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33008 + AuTraceErrPtr(path.dentry);
33009 + return path.dentry;
33012 +void vfsub_call_lkup_one(void *args)
33014 + struct vfsub_lkup_one_args *a = args;
33015 + *a->errp = vfsub_lkup_one(a->name, a->parent);
33018 +/* ---------------------------------------------------------------------- */
33020 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33021 + struct dentry *d2, struct au_hinode *hdir2)
33023 + struct dentry *d;
33026 + d = lock_rename(d1, d2);
33028 + au_hn_suspend(hdir1);
33029 + if (hdir1 != hdir2)
33030 + au_hn_suspend(hdir2);
33035 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33036 + struct dentry *d2, struct au_hinode *hdir2)
33038 + au_hn_resume(hdir1);
33039 + if (hdir1 != hdir2)
33040 + au_hn_resume(hdir2);
33042 + unlock_rename(d1, d2);
33046 +/* ---------------------------------------------------------------------- */
33048 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33051 + struct dentry *d;
33055 + d = path->dentry;
33056 + path->dentry = d->d_parent;
33057 + err = security_path_mknod(path, d, mode, 0);
33058 + path->dentry = d;
33059 + if (unlikely(err))
33063 + err = vfs_create(dir, path->dentry, mode, want_excl);
33066 + struct path tmp = *path;
33069 + vfsub_update_h_iattr(&tmp, &did);
33071 + tmp.dentry = path->dentry->d_parent;
33072 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33081 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33084 + struct dentry *d;
33088 + d = path->dentry;
33089 + path->dentry = d->d_parent;
33090 + err = security_path_symlink(path, d, symname);
33091 + path->dentry = d;
33092 + if (unlikely(err))
33096 + err = vfs_symlink(dir, path->dentry, symname);
33099 + struct path tmp = *path;
33102 + vfsub_update_h_iattr(&tmp, &did);
33104 + tmp.dentry = path->dentry->d_parent;
33105 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33114 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33117 + struct dentry *d;
33121 + d = path->dentry;
33122 + path->dentry = d->d_parent;
33123 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33124 + path->dentry = d;
33125 + if (unlikely(err))
33129 + err = vfs_mknod(dir, path->dentry, mode, dev);
33132 + struct path tmp = *path;
33135 + vfsub_update_h_iattr(&tmp, &did);
33137 + tmp.dentry = path->dentry->d_parent;
33138 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33147 +static int au_test_nlink(struct inode *inode)
33149 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33151 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33152 + || inode->i_nlink < link_max)
33157 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33158 + struct inode **delegated_inode)
33161 + struct dentry *d;
33165 + err = au_test_nlink(d_inode(src_dentry));
33166 + if (unlikely(err))
33169 + /* we don't call may_linkat() */
33170 + d = path->dentry;
33171 + path->dentry = d->d_parent;
33172 + err = security_path_link(src_dentry, path, d);
33173 + path->dentry = d;
33174 + if (unlikely(err))
33178 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33181 + struct path tmp = *path;
33184 + /* fuse has different memory inode for the same inumber */
33185 + vfsub_update_h_iattr(&tmp, &did);
33187 + tmp.dentry = path->dentry->d_parent;
33188 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33189 + tmp.dentry = src_dentry;
33190 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33199 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33200 + struct inode *dir, struct path *path,
33201 + struct inode **delegated_inode, unsigned int flags)
33204 + struct path tmp = {
33207 + struct dentry *d;
33210 + IMustLock(src_dir);
33212 + d = path->dentry;
33213 + path->dentry = d->d_parent;
33214 + tmp.dentry = src_dentry->d_parent;
33215 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33216 + path->dentry = d;
33217 + if (unlikely(err))
33221 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33222 + delegated_inode, flags);
33227 + tmp.dentry = d->d_parent;
33228 + vfsub_update_h_iattr(&tmp, &did);
33230 + tmp.dentry = src_dentry;
33231 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33232 + tmp.dentry = src_dentry->d_parent;
33233 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33242 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33245 + struct dentry *d;
33249 + d = path->dentry;
33250 + path->dentry = d->d_parent;
33251 + err = security_path_mkdir(path, d, mode);
33252 + path->dentry = d;
33253 + if (unlikely(err))
33257 + err = vfs_mkdir(dir, path->dentry, mode);
33260 + struct path tmp = *path;
33263 + vfsub_update_h_iattr(&tmp, &did);
33265 + tmp.dentry = path->dentry->d_parent;
33266 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33275 +int vfsub_rmdir(struct inode *dir, struct path *path)
33278 + struct dentry *d;
33282 + d = path->dentry;
33283 + path->dentry = d->d_parent;
33284 + err = security_path_rmdir(path, d);
33285 + path->dentry = d;
33286 + if (unlikely(err))
33290 + err = vfs_rmdir(dir, path->dentry);
33293 + struct path tmp = {
33294 + .dentry = path->dentry->d_parent,
33298 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33305 +/* ---------------------------------------------------------------------- */
33307 +/* todo: support mmap_sem? */
33308 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33314 + err = vfs_read(file, ubuf, count, ppos);
33317 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33321 +/* todo: kernel_read()? */
33322 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33326 + mm_segment_t oldfs;
33333 + oldfs = get_fs();
33334 + set_fs(KERNEL_DS);
33335 + err = vfsub_read_u(file, buf.u, count, ppos);
33340 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33346 + err = vfs_write(file, ubuf, count, ppos);
33349 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33353 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33356 + mm_segment_t oldfs;
33359 + const char __user *u;
33363 + oldfs = get_fs();
33364 + set_fs(KERNEL_DS);
33365 + err = vfsub_write_u(file, buf.u, count, ppos);
33370 +int vfsub_flush(struct file *file, fl_owner_t id)
33375 + if (file->f_op->flush) {
33376 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33377 + err = file->f_op->flush(file, id);
33380 + err = file->f_op->flush(file, id);
33384 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33390 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33394 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33397 + err = iterate_dir(file, ctx);
33400 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33405 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33406 + struct pipe_inode_info *pipe, size_t len,
33407 + unsigned int flags)
33412 + err = do_splice_to(in, ppos, pipe, len, flags);
33414 + file_accessed(in);
33416 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33420 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33421 + loff_t *ppos, size_t len, unsigned int flags)
33426 + err = do_splice_from(pipe, out, ppos, len, flags);
33429 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33433 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33437 + /* file can be NULL */
33439 + err = vfs_fsync(file, datasync);
33443 + AuDebugOn(!file);
33444 + path = &file->f_path;
33446 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33451 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33452 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33453 + struct file *h_file)
33456 + struct inode *h_inode;
33457 + struct super_block *h_sb;
33460 + err = vfsub_truncate(h_path, length);
33464 + h_inode = d_inode(h_path->dentry);
33465 + h_sb = h_inode->i_sb;
33467 + sb_start_write(h_sb);
33469 + err = locks_verify_truncate(h_inode, h_file, length);
33471 + err = security_path_truncate(h_path);
33474 + err = do_truncate(h_path->dentry, length, attr, h_file);
33478 + sb_end_write(h_sb);
33485 +/* ---------------------------------------------------------------------- */
33487 +struct au_vfsub_mkdir_args {
33489 + struct inode *dir;
33490 + struct path *path;
33494 +static void au_call_vfsub_mkdir(void *args)
33496 + struct au_vfsub_mkdir_args *a = args;
33497 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33500 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33502 + int err, do_sio, wkq_err;
33504 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33507 + err = vfsub_mkdir(dir, path, mode);
33510 + struct au_vfsub_mkdir_args args = {
33516 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33517 + if (unlikely(wkq_err))
33524 +struct au_vfsub_rmdir_args {
33526 + struct inode *dir;
33527 + struct path *path;
33530 +static void au_call_vfsub_rmdir(void *args)
33532 + struct au_vfsub_rmdir_args *a = args;
33533 + *a->errp = vfsub_rmdir(a->dir, a->path);
33536 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33538 + int err, do_sio, wkq_err;
33540 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33543 + err = vfsub_rmdir(dir, path);
33546 + struct au_vfsub_rmdir_args args = {
33551 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33552 + if (unlikely(wkq_err))
33559 +/* ---------------------------------------------------------------------- */
33561 +struct notify_change_args {
33563 + struct path *path;
33564 + struct iattr *ia;
33565 + struct inode **delegated_inode;
33568 +static void call_notify_change(void *args)
33570 + struct notify_change_args *a = args;
33571 + struct inode *h_inode;
33573 + h_inode = d_inode(a->path->dentry);
33574 + IMustLock(h_inode);
33576 + *a->errp = -EPERM;
33577 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33579 + *a->errp = notify_change(a->path->dentry, a->ia,
33580 + a->delegated_inode);
33583 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33585 + AuTraceErr(*a->errp);
33588 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33589 + struct inode **delegated_inode)
33592 + struct notify_change_args args = {
33596 + .delegated_inode = delegated_inode
33599 + call_notify_change(&args);
33604 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33605 + struct inode **delegated_inode)
33607 + int err, wkq_err;
33608 + struct notify_change_args args = {
33612 + .delegated_inode = delegated_inode
33615 + wkq_err = au_wkq_wait(call_notify_change, &args);
33616 + if (unlikely(wkq_err))
33622 +/* ---------------------------------------------------------------------- */
33624 +struct unlink_args {
33626 + struct inode *dir;
33627 + struct path *path;
33628 + struct inode **delegated_inode;
33631 +static void call_unlink(void *args)
33633 + struct unlink_args *a = args;
33634 + struct dentry *d = a->path->dentry;
33635 + struct inode *h_inode;
33636 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33637 + && au_dcount(d) == 1);
33639 + IMustLock(a->dir);
33641 + a->path->dentry = d->d_parent;
33642 + *a->errp = security_path_unlink(a->path, d);
33643 + a->path->dentry = d;
33644 + if (unlikely(*a->errp))
33647 + if (!stop_sillyrename)
33650 + if (d_is_positive(d)) {
33651 + h_inode = d_inode(d);
33656 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33659 + struct path tmp = {
33660 + .dentry = d->d_parent,
33661 + .mnt = a->path->mnt
33663 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33666 + if (!stop_sillyrename)
33671 + AuTraceErr(*a->errp);
33675 + * @dir: must be locked.
33676 + * @dentry: target dentry.
33678 +int vfsub_unlink(struct inode *dir, struct path *path,
33679 + struct inode **delegated_inode, int force)
33682 + struct unlink_args args = {
33686 + .delegated_inode = delegated_inode
33690 + call_unlink(&args);
33694 + wkq_err = au_wkq_wait(call_unlink, &args);
33695 + if (unlikely(wkq_err))
33701 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33702 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 08:00:00.000000000 +0800
33703 +++ linux/fs/aufs/vfsub.h 2019-07-11 21:21:54.382384486 +0800
33705 +/* SPDX-License-Identifier: GPL-2.0 */
33707 + * Copyright (C) 2005-2019 Junjiro R. Okajima
33709 + * This program, aufs is free software; you can redistribute it and/or modify
33710 + * it under the terms of the GNU General Public License as published by
33711 + * the Free Software Foundation; either version 2 of the License, or
33712 + * (at your option) any later version.
33714 + * This program is distributed in the hope that it will be useful,
33715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33717 + * GNU General Public License for more details.
33719 + * You should have received a copy of the GNU General Public License
33720 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33724 + * sub-routines for VFS
33727 +#ifndef __AUFS_VFSUB_H__
33728 +#define __AUFS_VFSUB_H__
33732 +#include <linux/fs.h>
33733 +#include <linux/mount.h>
33734 +#include <linux/posix_acl.h>
33735 +#include <linux/xattr.h>
33736 +#include "debug.h"
33738 +/* copied from linux/fs/internal.h */
33739 +/* todo: BAD approach!! */
33740 +extern void __mnt_drop_write(struct vfsmount *);
33741 +extern struct file *alloc_empty_file(int, const struct cred *);
33743 +/* ---------------------------------------------------------------------- */
33745 +/* lock subclass for lower inode */
33746 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33747 +/* reduce? gave up. */
33749 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33750 + AuLsc_I_PARENT, /* lower inode, parent first */
33751 + AuLsc_I_PARENT2, /* copyup dirs */
33752 + AuLsc_I_PARENT3, /* copyup wh */
33758 +/* to debug easier, do not make them inlined functions */
33759 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33760 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33762 +/* ---------------------------------------------------------------------- */
33764 +static inline void vfsub_drop_nlink(struct inode *inode)
33766 + AuDebugOn(!inode->i_nlink);
33767 + drop_nlink(inode);
33770 +static inline void vfsub_dead_dir(struct inode *inode)
33772 + AuDebugOn(!S_ISDIR(inode->i_mode));
33773 + inode->i_flags |= S_DEAD;
33774 + clear_nlink(inode);
33777 +static inline int vfsub_native_ro(struct inode *inode)
33779 + return sb_rdonly(inode->i_sb)
33780 + || IS_RDONLY(inode)
33781 + /* || IS_APPEND(inode) */
33782 + || IS_IMMUTABLE(inode);
33785 +#ifdef CONFIG_AUFS_BR_FUSE
33786 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33788 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33791 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33793 +/* ---------------------------------------------------------------------- */
33795 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33796 +struct file *vfsub_dentry_open(struct path *path, int flags);
33797 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33799 +struct vfsub_aopen_args {
33800 + struct file *file;
33801 + unsigned int open_flag;
33802 + umode_t create_mode;
33803 + struct au_branch *br;
33805 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33806 + struct vfsub_aopen_args *args);
33807 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33809 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33810 + struct dentry *parent, int len);
33811 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33814 +struct vfsub_lkup_one_args {
33815 + struct dentry **errp;
33816 + struct qstr *name;
33817 + struct dentry *parent;
33820 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33821 + struct dentry *parent)
33823 + return vfsub_lookup_one_len(name->name, parent, name->len);
33826 +void vfsub_call_lkup_one(void *args);
33828 +/* ---------------------------------------------------------------------- */
33830 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33835 + err = mnt_want_write(mnt);
33840 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33843 + mnt_drop_write(mnt);
33847 +#if 0 /* reserved */
33848 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33851 + mnt_drop_write_file(file);
33856 +/* ---------------------------------------------------------------------- */
33859 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33860 + struct dentry *d2, struct au_hinode *hdir2);
33861 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33862 + struct dentry *d2, struct au_hinode *hdir2);
33864 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33866 +int vfsub_symlink(struct inode *dir, struct path *path,
33867 + const char *symname);
33868 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33869 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33870 + struct path *path, struct inode **delegated_inode);
33871 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33872 + struct inode *hdir, struct path *path,
33873 + struct inode **delegated_inode, unsigned int flags);
33874 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33875 +int vfsub_rmdir(struct inode *dir, struct path *path);
33877 +/* ---------------------------------------------------------------------- */
33879 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33881 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33883 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33885 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33887 +int vfsub_flush(struct file *file, fl_owner_t id);
33888 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33890 +static inline loff_t vfsub_f_size_read(struct file *file)
33892 + return i_size_read(file_inode(file));
33895 +static inline unsigned int vfsub_file_flags(struct file *file)
33897 + unsigned int flags;
33899 + spin_lock(&file->f_lock);
33900 + flags = file->f_flags;
33901 + spin_unlock(&file->f_lock);
33906 +static inline int vfsub_file_execed(struct file *file)
33908 + /* todo: direct access f_flags */
33909 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33912 +#if 0 /* reserved */
33913 +static inline void vfsub_file_accessed(struct file *h_file)
33915 + file_accessed(h_file);
33916 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33920 +#if 0 /* reserved */
33921 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33922 + struct dentry *h_dentry)
33924 + struct path h_path = {
33925 + .dentry = h_dentry,
33928 + touch_atime(&h_path);
33929 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33933 +static inline int vfsub_update_time(struct inode *h_inode,
33934 + struct timespec64 *ts, int flags)
33936 + return update_time(h_inode, ts, flags);
33937 + /* no vfsub_update_h_iattr() since we don't have struct path */
33940 +#ifdef CONFIG_FS_POSIX_ACL
33941 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33945 + err = posix_acl_chmod(h_inode, h_mode);
33946 + if (err == -EOPNOTSUPP)
33951 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33954 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33955 + struct pipe_inode_info *pipe, size_t len,
33956 + unsigned int flags);
33957 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33958 + loff_t *ppos, size_t len, unsigned int flags);
33960 +static inline long vfsub_truncate(struct path *path, loff_t length)
33965 + err = vfs_truncate(path, length);
33970 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33971 + struct file *h_file);
33972 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33975 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33978 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33984 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33990 +/* copy_file_range(2) is a systemcall */
33991 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33992 + struct file *dst, loff_t dst_pos,
33993 + size_t len, unsigned int flags)
33998 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34004 +/* ---------------------------------------------------------------------- */
34006 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34011 + err = vfs_llseek(file, offset, origin);
34016 +/* ---------------------------------------------------------------------- */
34018 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34019 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34020 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34021 + struct inode **delegated_inode);
34022 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34023 + struct inode **delegated_inode);
34024 +int vfsub_unlink(struct inode *dir, struct path *path,
34025 + struct inode **delegated_inode, int force);
34027 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34029 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34032 +/* ---------------------------------------------------------------------- */
34034 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
34035 + const void *value, size_t size, int flags)
34040 + err = vfs_setxattr(dentry, name, value, size, flags);
34046 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
34051 + err = vfs_removexattr(dentry, name);
34057 +#endif /* __KERNEL__ */
34058 +#endif /* __AUFS_VFSUB_H__ */
34059 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34060 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 08:00:00.000000000 +0800
34061 +++ linux/fs/aufs/wbr_policy.c 2019-07-11 21:21:54.382384486 +0800
34063 +// SPDX-License-Identifier: GPL-2.0
34065 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34067 + * This program, aufs is free software; you can redistribute it and/or modify
34068 + * it under the terms of the GNU General Public License as published by
34069 + * the Free Software Foundation; either version 2 of the License, or
34070 + * (at your option) any later version.
34072 + * This program is distributed in the hope that it will be useful,
34073 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34074 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34075 + * GNU General Public License for more details.
34077 + * You should have received a copy of the GNU General Public License
34078 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34082 + * policies for selecting one among multiple writable branches
34085 +#include <linux/statfs.h>
34088 +/* subset of cpup_attr() */
34089 +static noinline_for_stack
34090 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34094 + struct inode *h_isrc;
34096 + h_isrc = d_inode(h_src);
34097 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34098 + ia.ia_mode = h_isrc->i_mode;
34099 + ia.ia_uid = h_isrc->i_uid;
34100 + ia.ia_gid = h_isrc->i_gid;
34101 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34102 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34103 + /* no delegation since it is just created */
34104 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34106 + /* is this nfs only? */
34107 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34108 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34109 + ia.ia_mode = h_isrc->i_mode;
34110 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34116 +#define AuCpdown_PARENT_OPQ 1
34117 +#define AuCpdown_WHED (1 << 1)
34118 +#define AuCpdown_MADE_DIR (1 << 2)
34119 +#define AuCpdown_DIROPQ (1 << 3)
34120 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34121 +#define au_fset_cpdown(flags, name) \
34122 + do { (flags) |= AuCpdown_##name; } while (0)
34123 +#define au_fclr_cpdown(flags, name) \
34124 + do { (flags) &= ~AuCpdown_##name; } while (0)
34126 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34127 + unsigned int *flags)
34130 + struct dentry *opq_dentry;
34132 + opq_dentry = au_diropq_create(dentry, bdst);
34133 + err = PTR_ERR(opq_dentry);
34134 + if (IS_ERR(opq_dentry))
34136 + dput(opq_dentry);
34137 + au_fset_cpdown(*flags, DIROPQ);
34143 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34144 + struct inode *dir, aufs_bindex_t bdst)
34147 + struct path h_path;
34148 + struct au_branch *br;
34150 + br = au_sbr(dentry->d_sb, bdst);
34151 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34152 + err = PTR_ERR(h_path.dentry);
34153 + if (IS_ERR(h_path.dentry))
34157 + if (d_is_positive(h_path.dentry)) {
34158 + h_path.mnt = au_br_mnt(br);
34159 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34162 + dput(h_path.dentry);
34168 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34169 + struct au_pin *pin,
34170 + struct dentry *h_parent, void *arg)
34173 + aufs_bindex_t bopq, btop;
34174 + struct path h_path;
34175 + struct dentry *parent;
34176 + struct inode *h_dir, *h_inode, *inode, *dir;
34177 + unsigned int *flags = arg;
34179 + btop = au_dbtop(dentry);
34180 + /* dentry is di-locked */
34181 + parent = dget_parent(dentry);
34182 + dir = d_inode(parent);
34183 + h_dir = d_inode(h_parent);
34184 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34185 + IMustLock(h_dir);
34187 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34188 + if (unlikely(err < 0))
34190 + h_path.dentry = au_h_dptr(dentry, bdst);
34191 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34192 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34193 + if (unlikely(err))
34195 + au_fset_cpdown(*flags, MADE_DIR);
34197 + bopq = au_dbdiropq(dentry);
34198 + au_fclr_cpdown(*flags, WHED);
34199 + au_fclr_cpdown(*flags, DIROPQ);
34200 + if (au_dbwh(dentry) == bdst)
34201 + au_fset_cpdown(*flags, WHED);
34202 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34203 + au_fset_cpdown(*flags, PARENT_OPQ);
34204 + h_inode = d_inode(h_path.dentry);
34205 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34206 + if (au_ftest_cpdown(*flags, WHED)) {
34207 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34208 + if (unlikely(err)) {
34209 + inode_unlock(h_inode);
34214 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34215 + inode_unlock(h_inode);
34216 + if (unlikely(err))
34219 + if (au_ftest_cpdown(*flags, WHED)) {
34220 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34221 + if (unlikely(err))
34225 + inode = d_inode(dentry);
34226 + if (au_ibbot(inode) < bdst)
34227 + au_set_ibbot(inode, bdst);
34228 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34229 + au_hi_flags(inode, /*isdir*/1));
34230 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34231 + goto out; /* success */
34235 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34236 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34237 + rerr = au_diropq_remove(dentry, bdst);
34238 + inode_unlock(h_inode);
34239 + if (unlikely(rerr)) {
34240 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34241 + dentry, bdst, rerr);
34247 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34248 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34249 + if (unlikely(rerr)) {
34250 + AuIOErr("failed removing %pd b%d (%d)\n",
34251 + dentry, bdst, rerr);
34256 + au_set_h_dptr(dentry, bdst, NULL);
34257 + if (au_dbbot(dentry) == bdst)
34258 + au_update_dbbot(dentry);
34264 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34267 + unsigned int flags;
34270 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34275 +/* ---------------------------------------------------------------------- */
34277 +/* policies for create */
34279 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34281 + int err, i, j, ndentry;
34282 + aufs_bindex_t bopq;
34283 + struct au_dcsub_pages dpages;
34284 + struct au_dpage *dpage;
34285 + struct dentry **dentries, *parent, *d;
34287 + err = au_dpages_init(&dpages, GFP_NOFS);
34288 + if (unlikely(err))
34290 + parent = dget_parent(dentry);
34291 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34292 + if (unlikely(err))
34296 + for (i = 0; i < dpages.ndpage; i++) {
34297 + dpage = dpages.dpages + i;
34298 + dentries = dpage->dentries;
34299 + ndentry = dpage->ndentry;
34300 + for (j = 0; j < ndentry; j++) {
34302 + di_read_lock_parent2(d, !AuLock_IR);
34303 + bopq = au_dbdiropq(d);
34304 + di_read_unlock(d, !AuLock_IR);
34305 + if (bopq >= 0 && bopq < err)
34312 + au_dpages_free(&dpages);
34317 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34319 + for (; bindex >= 0; bindex--)
34320 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34325 +/* top down parent */
34326 +static int au_wbr_create_tdp(struct dentry *dentry,
34327 + unsigned int flags __maybe_unused)
34330 + aufs_bindex_t btop, bindex;
34331 + struct super_block *sb;
34332 + struct dentry *parent, *h_parent;
34334 + sb = dentry->d_sb;
34335 + btop = au_dbtop(dentry);
34337 + if (!au_br_rdonly(au_sbr(sb, btop)))
34341 + parent = dget_parent(dentry);
34342 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34343 + h_parent = au_h_dptr(parent, bindex);
34344 + if (!h_parent || d_is_negative(h_parent))
34347 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34354 + /* bottom up here */
34355 + if (unlikely(err < 0)) {
34356 + err = au_wbr_bu(sb, btop - 1);
34358 + err = au_wbr_nonopq(dentry, err);
34362 + AuDbg("b%d\n", err);
34366 +/* ---------------------------------------------------------------------- */
34368 +/* an exception for the policy other than tdp */
34369 +static int au_wbr_create_exp(struct dentry *dentry)
34372 + aufs_bindex_t bwh, bdiropq;
34373 + struct dentry *parent;
34376 + bwh = au_dbwh(dentry);
34377 + parent = dget_parent(dentry);
34378 + bdiropq = au_dbdiropq(parent);
34380 + if (bdiropq >= 0)
34381 + err = min(bdiropq, bwh);
34384 + AuDbg("%d\n", err);
34385 + } else if (bdiropq >= 0) {
34387 + AuDbg("%d\n", err);
34392 + err = au_wbr_nonopq(dentry, err);
34394 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34397 + AuDbg("%d\n", err);
34401 +/* ---------------------------------------------------------------------- */
34404 +static int au_wbr_create_init_rr(struct super_block *sb)
34408 + err = au_wbr_bu(sb, au_sbbot(sb));
34409 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34412 + AuDbg("b%d\n", err);
34416 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34420 + aufs_bindex_t bindex, bbot;
34421 + struct super_block *sb;
34424 + err = au_wbr_create_exp(dentry);
34428 + sb = dentry->d_sb;
34429 + next = &au_sbi(sb)->si_wbr_rr_next;
34430 + bbot = au_sbbot(sb);
34432 + for (bindex = 0; bindex <= bbot; bindex++) {
34433 + if (!au_ftest_wbr(flags, DIR)) {
34434 + err = atomic_dec_return(next) + 1;
34435 + /* modulo for 0 is meaningless */
34436 + if (unlikely(!err))
34437 + err = atomic_dec_return(next) + 1;
34439 + err = atomic_read(next);
34440 + AuDbg("%d\n", err);
34443 + AuDbg("%d\n", err);
34444 + if (!au_br_rdonly(au_sbr(sb, err)))
34450 + err = au_wbr_nonopq(dentry, err);
34453 + AuDbg("%d\n", err);
34457 +/* ---------------------------------------------------------------------- */
34459 +/* most free space */
34460 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34462 + struct super_block *sb;
34463 + struct au_branch *br;
34464 + struct au_wbr_mfs *mfs;
34465 + struct dentry *h_parent;
34466 + aufs_bindex_t bindex, bbot;
34468 + unsigned long long b, bavail;
34469 + struct path h_path;
34470 + /* reduce the stack usage */
34471 + struct kstatfs *st;
34473 + st = kmalloc(sizeof(*st), GFP_NOFS);
34474 + if (unlikely(!st)) {
34475 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34480 + sb = dentry->d_sb;
34481 + mfs = &au_sbi(sb)->si_wbr_mfs;
34482 + MtxMustLock(&mfs->mfs_lock);
34483 + mfs->mfs_bindex = -EROFS;
34484 + mfs->mfsrr_bytes = 0;
34487 + bbot = au_sbbot(sb);
34489 + bindex = au_dbtop(parent);
34490 + bbot = au_dbtaildir(parent);
34493 + for (; bindex <= bbot; bindex++) {
34495 + h_parent = au_h_dptr(parent, bindex);
34496 + if (!h_parent || d_is_negative(h_parent))
34499 + br = au_sbr(sb, bindex);
34500 + if (au_br_rdonly(br))
34503 + /* sb->s_root for NFS is unreliable */
34504 + h_path.mnt = au_br_mnt(br);
34505 + h_path.dentry = h_path.mnt->mnt_root;
34506 + err = vfs_statfs(&h_path, st);
34507 + if (unlikely(err)) {
34508 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34512 + /* when the available size is equal, select the lower one */
34513 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34514 + || sizeof(b) < sizeof(st->f_bsize));
34515 + b = st->f_bavail * st->f_bsize;
34516 + br->br_wbr->wbr_bytes = b;
34517 + if (b >= bavail) {
34519 + mfs->mfs_bindex = bindex;
34520 + mfs->mfs_jiffy = jiffies;
34524 + mfs->mfsrr_bytes = bavail;
34525 + AuDbg("b%d\n", mfs->mfs_bindex);
34526 + au_kfree_rcu(st);
34529 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34532 + struct dentry *parent;
34533 + struct super_block *sb;
34534 + struct au_wbr_mfs *mfs;
34536 + err = au_wbr_create_exp(dentry);
34540 + sb = dentry->d_sb;
34542 + if (au_ftest_wbr(flags, PARENT))
34543 + parent = dget_parent(dentry);
34544 + mfs = &au_sbi(sb)->si_wbr_mfs;
34545 + mutex_lock(&mfs->mfs_lock);
34546 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34547 + || mfs->mfs_bindex < 0
34548 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34549 + au_mfs(dentry, parent);
34550 + mutex_unlock(&mfs->mfs_lock);
34551 + err = mfs->mfs_bindex;
34555 + err = au_wbr_nonopq(dentry, err);
34558 + AuDbg("b%d\n", err);
34562 +static int au_wbr_create_init_mfs(struct super_block *sb)
34564 + struct au_wbr_mfs *mfs;
34566 + mfs = &au_sbi(sb)->si_wbr_mfs;
34567 + mutex_init(&mfs->mfs_lock);
34568 + mfs->mfs_jiffy = 0;
34569 + mfs->mfs_bindex = -EROFS;
34574 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34576 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34580 +/* ---------------------------------------------------------------------- */
34582 +/* top down regardless parent, and then mfs */
34583 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34584 + unsigned int flags __maybe_unused)
34587 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34588 + unsigned long long watermark;
34589 + struct super_block *sb;
34590 + struct au_wbr_mfs *mfs;
34591 + struct au_branch *br;
34592 + struct dentry *parent;
34594 + sb = dentry->d_sb;
34595 + mfs = &au_sbi(sb)->si_wbr_mfs;
34596 + mutex_lock(&mfs->mfs_lock);
34597 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34598 + || mfs->mfs_bindex < 0)
34599 + au_mfs(dentry, /*parent*/NULL);
34600 + watermark = mfs->mfsrr_watermark;
34601 + bmfs = mfs->mfs_bindex;
34602 + mutex_unlock(&mfs->mfs_lock);
34604 + /* another style of au_wbr_create_exp() */
34605 + bwh = au_dbwh(dentry);
34606 + parent = dget_parent(dentry);
34607 + btail = au_dbtaildir(parent);
34608 + if (bwh >= 0 && bwh < btail)
34611 + err = au_wbr_nonopq(dentry, btail);
34612 + if (unlikely(err < 0))
34616 + for (bindex = 0; bindex <= btail; bindex++) {
34617 + br = au_sbr(sb, bindex);
34618 + if (au_br_rdonly(br))
34620 + if (br->br_wbr->wbr_bytes > watermark) {
34631 + AuDbg("b%d\n", err);
34635 +/* ---------------------------------------------------------------------- */
34637 +/* most free space and then round robin */
34638 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34641 + struct au_wbr_mfs *mfs;
34643 + err = au_wbr_create_mfs(dentry, flags);
34645 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34646 + mutex_lock(&mfs->mfs_lock);
34647 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34648 + err = au_wbr_create_rr(dentry, flags);
34649 + mutex_unlock(&mfs->mfs_lock);
34652 + AuDbg("b%d\n", err);
34656 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34660 + au_wbr_create_init_mfs(sb); /* ignore */
34661 + err = au_wbr_create_init_rr(sb);
34666 +/* ---------------------------------------------------------------------- */
34668 +/* top down parent and most free space */
34669 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34672 + unsigned long long b;
34673 + aufs_bindex_t bindex, btop, bbot;
34674 + struct super_block *sb;
34675 + struct dentry *parent, *h_parent;
34676 + struct au_branch *br;
34678 + err = au_wbr_create_tdp(dentry, flags);
34679 + if (unlikely(err < 0))
34681 + parent = dget_parent(dentry);
34682 + btop = au_dbtop(parent);
34683 + bbot = au_dbtaildir(parent);
34684 + if (btop == bbot)
34685 + goto out_parent; /* success */
34687 + e2 = au_wbr_create_mfs(dentry, flags);
34689 + goto out_parent; /* success */
34691 + /* when the available size is equal, select upper one */
34692 + sb = dentry->d_sb;
34693 + br = au_sbr(sb, err);
34694 + b = br->br_wbr->wbr_bytes;
34695 + AuDbg("b%d, %llu\n", err, b);
34697 + for (bindex = btop; bindex <= bbot; bindex++) {
34698 + h_parent = au_h_dptr(parent, bindex);
34699 + if (!h_parent || d_is_negative(h_parent))
34702 + br = au_sbr(sb, bindex);
34703 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34704 + b = br->br_wbr->wbr_bytes;
34706 + AuDbg("b%d, %llu\n", err, b);
34711 + err = au_wbr_nonopq(dentry, err);
34716 + AuDbg("b%d\n", err);
34720 +/* ---------------------------------------------------------------------- */
34723 + * - top down parent
34724 + * - most free space with parent
34725 + * - most free space round-robin regardless parent
34727 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34730 + unsigned long long watermark;
34731 + struct super_block *sb;
34732 + struct au_branch *br;
34733 + struct au_wbr_mfs *mfs;
34735 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34736 + if (unlikely(err < 0))
34739 + sb = dentry->d_sb;
34740 + br = au_sbr(sb, err);
34741 + mfs = &au_sbi(sb)->si_wbr_mfs;
34742 + mutex_lock(&mfs->mfs_lock);
34743 + watermark = mfs->mfsrr_watermark;
34744 + mutex_unlock(&mfs->mfs_lock);
34745 + if (br->br_wbr->wbr_bytes < watermark)
34746 + /* regardless the parent dir */
34747 + err = au_wbr_create_mfsrr(dentry, flags);
34750 + AuDbg("b%d\n", err);
34754 +/* ---------------------------------------------------------------------- */
34756 +/* policies for copyup */
34758 +/* top down parent */
34759 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34761 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34764 +/* bottom up parent */
34765 +static int au_wbr_copyup_bup(struct dentry *dentry)
34768 + aufs_bindex_t bindex, btop;
34769 + struct dentry *parent, *h_parent;
34770 + struct super_block *sb;
34773 + sb = dentry->d_sb;
34774 + parent = dget_parent(dentry);
34775 + btop = au_dbtop(parent);
34776 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34777 + h_parent = au_h_dptr(parent, bindex);
34778 + if (!h_parent || d_is_negative(h_parent))
34781 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34788 + /* bottom up here */
34789 + if (unlikely(err < 0))
34790 + err = au_wbr_bu(sb, btop - 1);
34792 + AuDbg("b%d\n", err);
34797 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34801 + err = au_wbr_bu(dentry->d_sb, btop);
34802 + AuDbg("b%d\n", err);
34804 + err = au_wbr_nonopq(dentry, err);
34806 + AuDbg("b%d\n", err);
34810 +static int au_wbr_copyup_bu(struct dentry *dentry)
34813 + aufs_bindex_t btop;
34815 + btop = au_dbtop(dentry);
34816 + err = au_wbr_do_copyup_bu(dentry, btop);
34820 +/* ---------------------------------------------------------------------- */
34822 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34823 + [AuWbrCopyup_TDP] = {
34824 + .copyup = au_wbr_copyup_tdp
34826 + [AuWbrCopyup_BUP] = {
34827 + .copyup = au_wbr_copyup_bup
34829 + [AuWbrCopyup_BU] = {
34830 + .copyup = au_wbr_copyup_bu
34834 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34835 + [AuWbrCreate_TDP] = {
34836 + .create = au_wbr_create_tdp
34838 + [AuWbrCreate_RR] = {
34839 + .create = au_wbr_create_rr,
34840 + .init = au_wbr_create_init_rr
34842 + [AuWbrCreate_MFS] = {
34843 + .create = au_wbr_create_mfs,
34844 + .init = au_wbr_create_init_mfs,
34845 + .fin = au_wbr_create_fin_mfs
34847 + [AuWbrCreate_MFSV] = {
34848 + .create = au_wbr_create_mfs,
34849 + .init = au_wbr_create_init_mfs,
34850 + .fin = au_wbr_create_fin_mfs
34852 + [AuWbrCreate_MFSRR] = {
34853 + .create = au_wbr_create_mfsrr,
34854 + .init = au_wbr_create_init_mfsrr,
34855 + .fin = au_wbr_create_fin_mfs
34857 + [AuWbrCreate_MFSRRV] = {
34858 + .create = au_wbr_create_mfsrr,
34859 + .init = au_wbr_create_init_mfsrr,
34860 + .fin = au_wbr_create_fin_mfs
34862 + [AuWbrCreate_TDMFS] = {
34863 + .create = au_wbr_create_tdmfs,
34864 + .init = au_wbr_create_init_mfs,
34865 + .fin = au_wbr_create_fin_mfs
34867 + [AuWbrCreate_TDMFSV] = {
34868 + .create = au_wbr_create_tdmfs,
34869 + .init = au_wbr_create_init_mfs,
34870 + .fin = au_wbr_create_fin_mfs
34872 + [AuWbrCreate_PMFS] = {
34873 + .create = au_wbr_create_pmfs,
34874 + .init = au_wbr_create_init_mfs,
34875 + .fin = au_wbr_create_fin_mfs
34877 + [AuWbrCreate_PMFSV] = {
34878 + .create = au_wbr_create_pmfs,
34879 + .init = au_wbr_create_init_mfs,
34880 + .fin = au_wbr_create_fin_mfs
34882 + [AuWbrCreate_PMFSRR] = {
34883 + .create = au_wbr_create_pmfsrr,
34884 + .init = au_wbr_create_init_mfsrr,
34885 + .fin = au_wbr_create_fin_mfs
34887 + [AuWbrCreate_PMFSRRV] = {
34888 + .create = au_wbr_create_pmfsrr,
34889 + .init = au_wbr_create_init_mfsrr,
34890 + .fin = au_wbr_create_fin_mfs
34893 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34894 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 08:00:00.000000000 +0800
34895 +++ linux/fs/aufs/whout.c 2019-07-11 21:21:54.382384486 +0800
34897 +// SPDX-License-Identifier: GPL-2.0
34899 + * Copyright (C) 2005-2019 Junjiro R. Okajima
34901 + * This program, aufs is free software; you can redistribute it and/or modify
34902 + * it under the terms of the GNU General Public License as published by
34903 + * the Free Software Foundation; either version 2 of the License, or
34904 + * (at your option) any later version.
34906 + * This program is distributed in the hope that it will be useful,
34907 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34908 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34909 + * GNU General Public License for more details.
34911 + * You should have received a copy of the GNU General Public License
34912 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34916 + * whiteout for logical deletion and opaque directory
34921 +#define WH_MASK 0444
34924 + * If a directory contains this file, then it is opaque. We start with the
34925 + * .wh. flag so that it is blocked by lookup.
34927 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34928 + sizeof(AUFS_WH_DIROPQ) - 1);
34931 + * generate whiteout name, which is NOT terminated by NULL.
34932 + * @name: original d_name.name
34933 + * @len: original d_name.len
34934 + * @wh: whiteout qstr
34935 + * returns zero when succeeds, otherwise error.
34936 + * succeeded value as wh->name should be freed by kfree().
34938 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34942 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34943 + return -ENAMETOOLONG;
34945 + wh->len = name->len + AUFS_WH_PFX_LEN;
34946 + p = kmalloc(wh->len, GFP_NOFS);
34949 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34950 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34957 +/* ---------------------------------------------------------------------- */
34960 + * test if the @wh_name exists under @h_parent.
34961 + * @try_sio specifies the necessary of super-io.
34963 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34966 + struct dentry *wh_dentry;
34969 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34971 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34972 + err = PTR_ERR(wh_dentry);
34973 + if (IS_ERR(wh_dentry)) {
34974 + if (err == -ENAMETOOLONG)
34980 + if (d_is_negative(wh_dentry))
34981 + goto out_wh; /* success */
34984 + if (d_is_reg(wh_dentry))
34985 + goto out_wh; /* success */
34988 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34989 + wh_dentry, d_inode(wh_dentry)->i_mode);
34998 + * test if the @h_dentry sets opaque or not.
35000 +int au_diropq_test(struct dentry *h_dentry)
35003 + struct inode *h_dir;
35005 + h_dir = d_inode(h_dentry);
35006 + err = au_wh_test(h_dentry, &diropq_name,
35007 + au_test_h_perm_sio(h_dir, MAY_EXEC));
35012 + * returns a negative dentry whose name is unique and temporary.
35014 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35015 + struct qstr *prefix)
35017 + struct dentry *dentry;
35019 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35021 + /* strict atomic_t is unnecessary here */
35022 + static unsigned short cnt;
35025 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35028 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35029 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35030 + dentry = ERR_PTR(-ENAMETOOLONG);
35031 + if (unlikely(qs.len > NAME_MAX))
35033 + dentry = ERR_PTR(-ENOMEM);
35034 + name = kmalloc(qs.len + 1, GFP_NOFS);
35035 + if (unlikely(!name))
35039 + /* doubly whiteout-ed */
35040 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35041 + p = name + AUFS_WH_PFX_LEN * 2;
35042 + memcpy(p, prefix->name, prefix->len);
35043 + p += prefix->len;
35045 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35048 + for (i = 0; i < 3; i++) {
35049 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35050 + dentry = au_sio_lkup_one(&qs, h_parent);
35051 + if (IS_ERR(dentry) || d_is_negative(dentry))
35055 + /* pr_warn("could not get random name\n"); */
35056 + dentry = ERR_PTR(-EEXIST);
35057 + AuDbg("%.*s\n", AuLNPair(&qs));
35061 + if (name != defname)
35062 + au_kfree_try_rcu(name);
35064 + AuTraceErrPtr(dentry);
35069 + * rename the @h_dentry on @br to the whiteouted temporary name.
35071 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35074 + struct path h_path = {
35075 + .mnt = au_br_mnt(br)
35077 + struct inode *h_dir, *delegated;
35078 + struct dentry *h_parent;
35080 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35081 + h_dir = d_inode(h_parent);
35082 + IMustLock(h_dir);
35084 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35085 + err = PTR_ERR(h_path.dentry);
35086 + if (IS_ERR(h_path.dentry))
35089 + /* under the same dir, no need to lock_rename() */
35090 + delegated = NULL;
35091 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35094 + if (unlikely(err == -EWOULDBLOCK)) {
35095 + pr_warn("cannot retry for NFSv4 delegation"
35096 + " for an internal rename\n");
35099 + dput(h_path.dentry);
35106 +/* ---------------------------------------------------------------------- */
35108 + * functions for removing a whiteout
35111 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35114 + struct inode *delegated;
35117 + * forces superio when the dir has a sticky bit.
35118 + * this may be a violation of unix fs semantics.
35120 + force = (h_dir->i_mode & S_ISVTX)
35121 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35122 + delegated = NULL;
35123 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35124 + if (unlikely(err == -EWOULDBLOCK)) {
35125 + pr_warn("cannot retry for NFSv4 delegation"
35126 + " for an internal unlink\n");
35132 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35133 + struct dentry *dentry)
35137 + err = do_unlink_wh(h_dir, h_path);
35138 + if (!err && dentry)
35139 + au_set_dbwh(dentry, -1);
35144 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35145 + struct au_branch *br)
35148 + struct path h_path = {
35149 + .mnt = au_br_mnt(br)
35153 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35154 + if (IS_ERR(h_path.dentry))
35155 + err = PTR_ERR(h_path.dentry);
35157 + if (d_is_reg(h_path.dentry))
35158 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35159 + dput(h_path.dentry);
35165 +/* ---------------------------------------------------------------------- */
35167 + * initialize/clean whiteout for a branch
35170 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35174 + struct inode *delegated;
35176 + if (d_is_negative(whpath->dentry))
35180 + err = vfsub_rmdir(h_dir, whpath);
35182 + delegated = NULL;
35183 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35184 + if (unlikely(err == -EWOULDBLOCK)) {
35185 + pr_warn("cannot retry for NFSv4 delegation"
35186 + " for an internal unlink\n");
35190 + if (unlikely(err))
35191 + pr_warn("failed removing %pd (%d), ignored.\n",
35192 + whpath->dentry, err);
35195 +static int test_linkable(struct dentry *h_root)
35197 + struct inode *h_dir = d_inode(h_root);
35199 + if (h_dir->i_op->link)
35202 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35203 + h_root, au_sbtype(h_root->d_sb));
35207 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35208 +static int au_whdir(struct inode *h_dir, struct path *path)
35213 + if (d_is_negative(path->dentry)) {
35216 + if (au_test_nfs(path->dentry->d_sb))
35218 + err = vfsub_mkdir(h_dir, path, mode);
35219 + } else if (d_is_dir(path->dentry))
35222 + pr_err("unknown %pd exists\n", path->dentry);
35227 +struct au_wh_base {
35228 + const struct qstr *name;
35229 + struct dentry *dentry;
35232 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35233 + struct path *h_path)
35235 + h_path->dentry = base[AuBrWh_BASE].dentry;
35236 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35237 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35238 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35239 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35240 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35244 + * returns tri-state,
35245 + * minus: error, caller should print the message
35247 + * plus: error, caller should NOT print the message
35249 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35250 + int do_plink, struct au_wh_base base[],
35251 + struct path *h_path)
35254 + struct inode *h_dir;
35256 + h_dir = d_inode(h_root);
35257 + h_path->dentry = base[AuBrWh_BASE].dentry;
35258 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35259 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35261 + err = test_linkable(h_root);
35262 + if (unlikely(err)) {
35267 + err = au_whdir(h_dir, h_path);
35268 + if (unlikely(err))
35270 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35272 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35273 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35274 + err = au_whdir(h_dir, h_path);
35275 + if (unlikely(err))
35277 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35284 + * for the moment, aufs supports the branch filesystem which does not support
35285 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35286 + * copyup failed. finally, such filesystem will not be used as the writable
35289 + * returns tri-state, see above.
35291 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35292 + int do_plink, struct au_wh_base base[],
35293 + struct path *h_path)
35296 + struct inode *h_dir;
35298 + WbrWhMustWriteLock(wbr);
35300 + err = test_linkable(h_root);
35301 + if (unlikely(err)) {
35307 + * todo: should this create be done in /sbin/mount.aufs helper?
35310 + h_dir = d_inode(h_root);
35311 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35312 + h_path->dentry = base[AuBrWh_BASE].dentry;
35313 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35314 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35317 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35318 + if (unlikely(err))
35321 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35323 + err = au_whdir(h_dir, h_path);
35324 + if (unlikely(err))
35326 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35328 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35329 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35331 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35332 + err = au_whdir(h_dir, h_path);
35333 + if (unlikely(err))
35335 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35342 + * initialize the whiteout base file/dir for @br.
35344 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35347 + const unsigned char do_plink
35348 + = !!au_opt_test(au_mntflags(sb), PLINK);
35349 + struct inode *h_dir;
35350 + struct path path = br->br_path;
35351 + struct dentry *h_root = path.dentry;
35352 + struct au_wbr *wbr = br->br_wbr;
35353 + static const struct qstr base_name[] = {
35354 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35355 + sizeof(AUFS_BASE_NAME) - 1),
35356 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35357 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35358 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35359 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35361 + struct au_wh_base base[] = {
35362 + [AuBrWh_BASE] = {
35363 + .name = base_name + AuBrWh_BASE,
35366 + [AuBrWh_PLINK] = {
35367 + .name = base_name + AuBrWh_PLINK,
35370 + [AuBrWh_ORPH] = {
35371 + .name = base_name + AuBrWh_ORPH,
35377 + WbrWhMustWriteLock(wbr);
35379 + for (i = 0; i < AuBrWh_Last; i++) {
35380 + /* doubly whiteouted */
35381 + struct dentry *d;
35383 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35384 + err = PTR_ERR(d);
35388 + base[i].dentry = d;
35390 + && wbr->wbr_wh[i]
35391 + && wbr->wbr_wh[i] != base[i].dentry);
35395 + for (i = 0; i < AuBrWh_Last; i++) {
35396 + dput(wbr->wbr_wh[i]);
35397 + wbr->wbr_wh[i] = NULL;
35401 + if (!au_br_writable(br->br_perm)) {
35402 + h_dir = d_inode(h_root);
35403 + au_wh_init_ro(h_dir, base, &path);
35404 + } else if (!au_br_wh_linkable(br->br_perm)) {
35405 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35411 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35417 + goto out; /* success */
35420 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35421 + err, h_root, au_sbtype(h_root->d_sb));
35423 + for (i = 0; i < AuBrWh_Last; i++)
35424 + dput(base[i].dentry);
35428 +/* ---------------------------------------------------------------------- */
35430 + * whiteouts are all hard-linked usually.
35431 + * when its link count reaches a ceiling, we create a new whiteout base
35432 + * asynchronously.
35435 +struct reinit_br_wh {
35436 + struct super_block *sb;
35437 + struct au_branch *br;
35440 +static void reinit_br_wh(void *arg)
35443 + aufs_bindex_t bindex;
35444 + struct path h_path;
35445 + struct reinit_br_wh *a = arg;
35446 + struct au_wbr *wbr;
35447 + struct inode *dir, *delegated;
35448 + struct dentry *h_root;
35449 + struct au_hinode *hdir;
35452 + wbr = a->br->br_wbr;
35453 + /* big aufs lock */
35454 + si_noflush_write_lock(a->sb);
35455 + if (!au_br_writable(a->br->br_perm))
35457 + bindex = au_br_index(a->sb, a->br->br_id);
35458 + if (unlikely(bindex < 0))
35461 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35462 + dir = d_inode(a->sb->s_root);
35463 + hdir = au_hi(dir, bindex);
35464 + h_root = au_h_dptr(a->sb->s_root, bindex);
35465 + AuDebugOn(h_root != au_br_dentry(a->br));
35467 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35468 + wbr_wh_write_lock(wbr);
35469 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35472 + h_path.dentry = wbr->wbr_whbase;
35473 + h_path.mnt = au_br_mnt(a->br);
35474 + delegated = NULL;
35475 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35477 + if (unlikely(err == -EWOULDBLOCK)) {
35478 + pr_warn("cannot retry for NFSv4 delegation"
35479 + " for an internal unlink\n");
35483 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35486 + dput(wbr->wbr_whbase);
35487 + wbr->wbr_whbase = NULL;
35489 + err = au_wh_init(a->br, a->sb);
35490 + wbr_wh_write_unlock(wbr);
35491 + au_hn_inode_unlock(hdir);
35492 + di_read_unlock(a->sb->s_root, AuLock_IR);
35494 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35498 + atomic_dec(&wbr->wbr_wh_running);
35499 + au_lcnt_dec(&a->br->br_count);
35500 + si_write_unlock(a->sb);
35501 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35503 + if (unlikely(err))
35504 + AuIOErr("err %d\n", err);
35507 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35509 + int do_dec, wkq_err;
35510 + struct reinit_br_wh *arg;
35513 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35516 + /* ignore ENOMEM */
35517 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35520 + * dec(wh_running), kfree(arg) and dec(br_count)
35521 + * in reinit function
35525 + au_lcnt_inc(&br->br_count);
35526 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35527 + if (unlikely(wkq_err)) {
35528 + atomic_dec(&br->br_wbr->wbr_wh_running);
35529 + au_lcnt_dec(&br->br_count);
35530 + au_kfree_rcu(arg);
35537 + atomic_dec(&br->br_wbr->wbr_wh_running);
35540 +/* ---------------------------------------------------------------------- */
35543 + * create the whiteout @wh.
35545 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35546 + struct dentry *wh)
35549 + struct path h_path = {
35552 + struct au_branch *br;
35553 + struct au_wbr *wbr;
35554 + struct dentry *h_parent;
35555 + struct inode *h_dir, *delegated;
35557 + h_parent = wh->d_parent; /* dir inode is locked */
35558 + h_dir = d_inode(h_parent);
35559 + IMustLock(h_dir);
35561 + br = au_sbr(sb, bindex);
35562 + h_path.mnt = au_br_mnt(br);
35563 + wbr = br->br_wbr;
35564 + wbr_wh_read_lock(wbr);
35565 + if (wbr->wbr_whbase) {
35566 + delegated = NULL;
35567 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35568 + if (unlikely(err == -EWOULDBLOCK)) {
35569 + pr_warn("cannot retry for NFSv4 delegation"
35570 + " for an internal link\n");
35573 + if (!err || err != -EMLINK)
35576 + /* link count full. re-initialize br_whbase. */
35577 + kick_reinit_br_wh(sb, br);
35580 + /* return this error in this context */
35581 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35583 + au_fhsm_wrote(sb, bindex, /*force*/0);
35586 + wbr_wh_read_unlock(wbr);
35590 +/* ---------------------------------------------------------------------- */
35593 + * create or remove the diropq.
35595 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35596 + unsigned int flags)
35598 + struct dentry *opq_dentry, *h_dentry;
35599 + struct super_block *sb;
35600 + struct au_branch *br;
35603 + sb = dentry->d_sb;
35604 + br = au_sbr(sb, bindex);
35605 + h_dentry = au_h_dptr(dentry, bindex);
35606 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35607 + if (IS_ERR(opq_dentry))
35610 + if (au_ftest_diropq(flags, CREATE)) {
35611 + err = link_or_create_wh(sb, bindex, opq_dentry);
35613 + au_set_dbdiropq(dentry, bindex);
35614 + goto out; /* success */
35617 + struct path tmp = {
35618 + .dentry = opq_dentry,
35619 + .mnt = au_br_mnt(br)
35621 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35623 + au_set_dbdiropq(dentry, -1);
35625 + dput(opq_dentry);
35626 + opq_dentry = ERR_PTR(err);
35629 + return opq_dentry;
35632 +struct do_diropq_args {
35633 + struct dentry **errp;
35634 + struct dentry *dentry;
35635 + aufs_bindex_t bindex;
35636 + unsigned int flags;
35639 +static void call_do_diropq(void *args)
35641 + struct do_diropq_args *a = args;
35642 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35645 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35646 + unsigned int flags)
35648 + struct dentry *diropq, *h_dentry;
35650 + h_dentry = au_h_dptr(dentry, bindex);
35651 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35652 + diropq = do_diropq(dentry, bindex, flags);
35655 + struct do_diropq_args args = {
35657 + .dentry = dentry,
35658 + .bindex = bindex,
35662 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35663 + if (unlikely(wkq_err))
35664 + diropq = ERR_PTR(wkq_err);
35670 +/* ---------------------------------------------------------------------- */
35673 + * lookup whiteout dentry.
35674 + * @h_parent: lower parent dentry which must exist and be locked
35675 + * @base_name: name of dentry which will be whiteouted
35676 + * returns dentry for whiteout.
35678 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35679 + struct au_branch *br)
35682 + struct qstr wh_name;
35683 + struct dentry *wh_dentry;
35685 + err = au_wh_name_alloc(&wh_name, base_name);
35686 + wh_dentry = ERR_PTR(err);
35688 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35689 + au_kfree_try_rcu(wh_name.name);
35691 + return wh_dentry;
35695 + * link/create a whiteout for @dentry on @bindex.
35697 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35698 + struct dentry *h_parent)
35700 + struct dentry *wh_dentry;
35701 + struct super_block *sb;
35704 + sb = dentry->d_sb;
35705 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35706 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35707 + err = link_or_create_wh(sb, bindex, wh_dentry);
35709 + au_set_dbwh(dentry, bindex);
35710 + au_fhsm_wrote(sb, bindex, /*force*/0);
35713 + wh_dentry = ERR_PTR(err);
35717 + return wh_dentry;
35720 +/* ---------------------------------------------------------------------- */
35722 +/* Delete all whiteouts in this directory on branch bindex. */
35723 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35724 + aufs_bindex_t bindex, struct au_branch *br)
35727 + unsigned long ul, n;
35728 + struct qstr wh_name;
35730 + struct hlist_head *head;
35731 + struct au_vdir_wh *pos;
35732 + struct au_vdir_destr *str;
35735 + p = (void *)__get_free_page(GFP_NOFS);
35736 + wh_name.name = p;
35737 + if (unlikely(!wh_name.name))
35741 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35742 + p += AUFS_WH_PFX_LEN;
35743 + n = whlist->nh_num;
35744 + head = whlist->nh_head;
35745 + for (ul = 0; !err && ul < n; ul++, head++) {
35746 + hlist_for_each_entry(pos, head, wh_hash) {
35747 + if (pos->wh_bindex != bindex)
35750 + str = &pos->wh_str;
35751 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35752 + memcpy(p, str->name, str->len);
35753 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35754 + err = unlink_wh_name(h_dentry, &wh_name, br);
35759 + AuIOErr("whiteout name too long %.*s\n",
35760 + str->len, str->name);
35765 + free_page((unsigned long)wh_name.name);
35771 +struct del_wh_children_args {
35773 + struct dentry *h_dentry;
35774 + struct au_nhash *whlist;
35775 + aufs_bindex_t bindex;
35776 + struct au_branch *br;
35779 +static void call_del_wh_children(void *args)
35781 + struct del_wh_children_args *a = args;
35782 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35785 +/* ---------------------------------------------------------------------- */
35787 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35789 + struct au_whtmp_rmdir *whtmp;
35791 + unsigned int rdhash;
35793 + SiMustAnyLock(sb);
35795 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35796 + if (unlikely(!whtmp)) {
35797 + whtmp = ERR_PTR(-ENOMEM);
35801 + /* no estimation for dir size */
35802 + rdhash = au_sbi(sb)->si_rdhash;
35804 + rdhash = AUFS_RDHASH_DEF;
35805 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35806 + if (unlikely(err)) {
35807 + au_kfree_rcu(whtmp);
35808 + whtmp = ERR_PTR(err);
35815 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35818 + au_lcnt_dec(&whtmp->br->br_count);
35819 + dput(whtmp->wh_dentry);
35820 + iput(whtmp->dir);
35821 + au_nhash_wh_free(&whtmp->whlist);
35822 + au_kfree_rcu(whtmp);
35826 + * rmdir the whiteouted temporary named dir @h_dentry.
35827 + * @whlist: whiteouted children.
35829 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35830 + struct dentry *wh_dentry, struct au_nhash *whlist)
35833 + unsigned int h_nlink;
35834 + struct path h_tmp;
35835 + struct inode *wh_inode, *h_dir;
35836 + struct au_branch *br;
35838 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35839 + IMustLock(h_dir);
35841 + br = au_sbr(dir->i_sb, bindex);
35842 + wh_inode = d_inode(wh_dentry);
35843 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35846 + * someone else might change some whiteouts while we were sleeping.
35847 + * it means this whlist may have an obsoleted entry.
35849 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35850 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35853 + struct del_wh_children_args args = {
35855 + .h_dentry = wh_dentry,
35856 + .whlist = whlist,
35857 + .bindex = bindex,
35861 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35862 + if (unlikely(wkq_err))
35865 + inode_unlock(wh_inode);
35868 + h_tmp.dentry = wh_dentry;
35869 + h_tmp.mnt = au_br_mnt(br);
35870 + h_nlink = h_dir->i_nlink;
35871 + err = vfsub_rmdir(h_dir, &h_tmp);
35872 + /* some fs doesn't change the parent nlink in some cases */
35873 + h_nlink -= h_dir->i_nlink;
35877 + if (au_ibtop(dir) == bindex) {
35878 + /* todo: dir->i_mutex is necessary */
35879 + au_cpup_attr_timesizes(dir);
35881 + vfsub_drop_nlink(dir);
35883 + return 0; /* success */
35886 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35890 +static void call_rmdir_whtmp(void *args)
35893 + aufs_bindex_t bindex;
35894 + struct au_whtmp_rmdir *a = args;
35895 + struct super_block *sb;
35896 + struct dentry *h_parent;
35897 + struct inode *h_dir;
35898 + struct au_hinode *hdir;
35900 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35901 + /* inode_lock(a->dir); */
35903 + sb = a->dir->i_sb;
35904 + si_read_lock(sb, !AuLock_FLUSH);
35905 + if (!au_br_writable(a->br->br_perm))
35907 + bindex = au_br_index(sb, a->br->br_id);
35908 + if (unlikely(bindex < 0))
35912 + ii_write_lock_parent(a->dir);
35913 + h_parent = dget_parent(a->wh_dentry);
35914 + h_dir = d_inode(h_parent);
35915 + hdir = au_hi(a->dir, bindex);
35916 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35917 + if (unlikely(err))
35919 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35920 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35923 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35924 + au_hn_inode_unlock(hdir);
35925 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35929 + ii_write_unlock(a->dir);
35931 + /* inode_unlock(a->dir); */
35932 + au_whtmp_rmdir_free(a);
35933 + si_read_unlock(sb);
35934 + au_nwt_done(&au_sbi(sb)->si_nowait);
35935 + if (unlikely(err))
35936 + AuIOErr("err %d\n", err);
35939 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35940 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35943 + struct super_block *sb;
35947 + /* all post-process will be done in do_rmdir_whtmp(). */
35949 + args->dir = au_igrab(dir);
35950 + args->br = au_sbr(sb, bindex);
35951 + au_lcnt_inc(&args->br->br_count);
35952 + args->wh_dentry = dget(wh_dentry);
35953 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35954 + if (unlikely(wkq_err)) {
35955 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35956 + au_whtmp_rmdir_free(args);
35959 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35960 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 08:00:00.000000000 +0800
35961 +++ linux/fs/aufs/whout.h 2019-07-11 21:21:54.382384486 +0800
35963 +/* SPDX-License-Identifier: GPL-2.0 */
35965 + * Copyright (C) 2005-2019 Junjiro R. Okajima
35967 + * This program, aufs is free software; you can redistribute it and/or modify
35968 + * it under the terms of the GNU General Public License as published by
35969 + * the Free Software Foundation; either version 2 of the License, or
35970 + * (at your option) any later version.
35972 + * This program is distributed in the hope that it will be useful,
35973 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35975 + * GNU General Public License for more details.
35977 + * You should have received a copy of the GNU General Public License
35978 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35982 + * whiteout for logical deletion and opaque directory
35985 +#ifndef __AUFS_WHOUT_H__
35986 +#define __AUFS_WHOUT_H__
35993 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35994 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35995 +int au_diropq_test(struct dentry *h_dentry);
35997 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35998 + struct qstr *prefix);
35999 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36000 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36001 + struct dentry *dentry);
36002 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36004 +/* diropq flags */
36005 +#define AuDiropq_CREATE 1
36006 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36007 +#define au_fset_diropq(flags, name) \
36008 + do { (flags) |= AuDiropq_##name; } while (0)
36009 +#define au_fclr_diropq(flags, name) \
36010 + do { (flags) &= ~AuDiropq_##name; } while (0)
36012 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36013 + unsigned int flags);
36014 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36015 + struct au_branch *br);
36016 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36017 + struct dentry *h_parent);
36019 +/* real rmdir for the whiteout-ed dir */
36020 +struct au_whtmp_rmdir {
36021 + struct inode *dir;
36022 + struct au_branch *br;
36023 + struct dentry *wh_dentry;
36024 + struct au_nhash whlist;
36027 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36028 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36029 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36030 + struct dentry *wh_dentry, struct au_nhash *whlist);
36031 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36032 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36034 +/* ---------------------------------------------------------------------- */
36036 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36037 + aufs_bindex_t bindex)
36039 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36042 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36044 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36047 +#endif /* __KERNEL__ */
36048 +#endif /* __AUFS_WHOUT_H__ */
36049 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36050 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 08:00:00.000000000 +0800
36051 +++ linux/fs/aufs/wkq.c 2019-07-11 21:21:54.382384486 +0800
36053 +// SPDX-License-Identifier: GPL-2.0
36055 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36057 + * This program, aufs is free software; you can redistribute it and/or modify
36058 + * it under the terms of the GNU General Public License as published by
36059 + * the Free Software Foundation; either version 2 of the License, or
36060 + * (at your option) any later version.
36062 + * This program is distributed in the hope that it will be useful,
36063 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36064 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36065 + * GNU General Public License for more details.
36067 + * You should have received a copy of the GNU General Public License
36068 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36072 + * workqueue for asynchronous/super-io operations
36073 + * todo: try new credential scheme
36076 +#include <linux/module.h>
36079 +/* internal workqueue named AUFS_WKQ_NAME */
36081 +static struct workqueue_struct *au_wkq;
36083 +struct au_wkinfo {
36084 + struct work_struct wk;
36085 + struct kobject *kobj;
36087 + unsigned int flags; /* see wkq.h */
36089 + au_wkq_func_t func;
36092 +#ifdef CONFIG_LOCKDEP
36094 + struct held_lock **hlock;
36097 + struct completion *comp;
36100 +/* ---------------------------------------------------------------------- */
36102 + * Aufs passes some operations to the workqueue such as the internal copyup.
36103 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36104 + * job run by workqueue depends upon the locks acquired in the other task.
36105 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36106 + * information too. And the job in the workqueue restores the info in order to
36107 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36108 + * correctly and expectedly.
36111 +#ifndef CONFIG_LOCKDEP
36112 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36113 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36114 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36115 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36116 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36118 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36120 + wkinfo->hlock = NULL;
36121 + wkinfo->dont_check = 0;
36128 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36130 + static DEFINE_SPINLOCK(spin);
36133 + struct lock_class_key *key;
36135 + { .name = "&sbinfo->si_rwsem" },
36136 + { .name = "&finfo->fi_rwsem" },
36137 + { .name = "&dinfo->di_rwsem" },
36138 + { .name = "&iinfo->ii_rwsem" }
36143 + /* lockless read from 'set.' see below */
36144 + if (set == ARRAY_SIZE(a)) {
36145 + for (i = 0; i < ARRAY_SIZE(a); i++)
36146 + if (a[i].key == key)
36151 + spin_lock(&spin);
36153 + for (i = 0; i < ARRAY_SIZE(a); i++)
36154 + if (a[i].key == key) {
36155 + spin_unlock(&spin);
36158 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36160 + if (unlikely(a[i].key == key)) { /* rare but possible */
36161 + spin_unlock(&spin);
36166 + if (strstr(a[i].name, name)) {
36168 + * the order of these three lines is important for the
36169 + * lockless read above.
36172 + spin_unlock(&spin);
36174 + /* AuDbg("%d, %s\n", set, name); */
36178 + spin_unlock(&spin);
36187 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36190 + struct task_struct *curr;
36191 + struct held_lock **hl, *held_locks, *p;
36195 + wkinfo->dont_check = lockdep_recursing(curr);
36196 + if (wkinfo->dont_check)
36198 + n = curr->lockdep_depth;
36203 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36204 + if (unlikely(!wkinfo->hlock))
36209 + if (0 && au_debug_test()) /* left for debugging */
36210 + lockdep_print_held_locks(curr);
36212 + held_locks = curr->held_locks;
36213 + hl = wkinfo->hlock;
36215 + p = held_locks++;
36216 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36225 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36227 + au_kfree_try_rcu(wkinfo->hlock);
36230 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36232 + struct held_lock *p, **hl = wkinfo->hlock;
36235 + if (wkinfo->dont_check)
36239 + while ((p = *hl++)) { /* assignment */
36240 + subclass = lockdep_hlock_class(p)->subclass;
36241 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36243 + rwsem_acquire_read(p->instance, subclass, 0,
36244 + /*p->acquire_ip*/_RET_IP_);
36246 + rwsem_acquire(p->instance, subclass, 0,
36247 + /*p->acquire_ip*/_RET_IP_);
36251 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36253 + struct held_lock *p, **hl = wkinfo->hlock;
36255 + if (wkinfo->dont_check)
36259 + while ((p = *hl++)) /* assignment */
36260 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36264 +static void wkq_func(struct work_struct *wk)
36266 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36268 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36269 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36271 + au_wkq_lockdep_pre(wkinfo);
36272 + wkinfo->func(wkinfo->args);
36273 + au_wkq_lockdep_post(wkinfo);
36274 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36275 + complete(wkinfo->comp);
36277 + kobject_put(wkinfo->kobj);
36278 + module_put(THIS_MODULE); /* todo: ?? */
36279 + au_kfree_rcu(wkinfo);
36284 + * Since struct completion is large, try allocating it dynamically.
36286 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
36287 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36289 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36291 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36293 + init_completion(*comp);
36294 + wkinfo->comp = *comp;
36300 +static void au_wkq_comp_free(struct completion *comp)
36302 + au_kfree_rcu(comp);
36308 +#define AuWkqCompDeclare(name) \
36309 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
36310 + struct completion *comp = &_ ## name
36312 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36314 + wkinfo->comp = *comp;
36318 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
36322 +#endif /* 4KSTACKS */
36324 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36326 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36327 + if (au_wkq_test()) {
36328 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36329 + " due to a dead dir by UDBA,"
36330 + " or async xino write?\n");
36331 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36334 + au_dbg_verify_kthread();
36336 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36337 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36338 + queue_work(au_wkq, &wkinfo->wk);
36340 + INIT_WORK(&wkinfo->wk, wkq_func);
36341 + schedule_work(&wkinfo->wk);
36346 + * Be careful. It is easy to make deadlock happen.
36347 + * processA: lock, wkq and wait
36348 + * processB: wkq and wait, lock in wkq
36351 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36354 + AuWkqCompDeclare(comp);
36355 + struct au_wkinfo wkinfo = {
36361 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36362 + if (unlikely(err))
36364 + err = au_wkq_lockdep_alloc(&wkinfo);
36365 + if (unlikely(err))
36368 + au_wkq_run(&wkinfo);
36369 + /* no timeout, no interrupt */
36370 + wait_for_completion(wkinfo.comp);
36372 + au_wkq_lockdep_free(&wkinfo);
36375 + au_wkq_comp_free(comp);
36377 + destroy_work_on_stack(&wkinfo.wk);
36382 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36383 + * problem in a concurrent umounting.
36385 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36386 + unsigned int flags)
36389 + struct au_wkinfo *wkinfo;
36391 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36394 + * wkq_func() must free this wkinfo.
36395 + * it highly depends upon the implementation of workqueue.
36398 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36400 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36401 + wkinfo->flags = flags & ~AuWkq_WAIT;
36402 + wkinfo->func = func;
36403 + wkinfo->args = args;
36404 + wkinfo->comp = NULL;
36405 + au_wkq_lockdep_init(wkinfo);
36406 + kobject_get(wkinfo->kobj);
36407 + __module_get(THIS_MODULE); /* todo: ?? */
36409 + au_wkq_run(wkinfo);
36412 + au_nwt_done(&au_sbi(sb)->si_nowait);
36418 +/* ---------------------------------------------------------------------- */
36420 +void au_nwt_init(struct au_nowait_tasks *nwt)
36422 + atomic_set(&nwt->nw_len, 0);
36423 + /* smp_mb(); */ /* atomic_set */
36424 + init_waitqueue_head(&nwt->nw_wq);
36427 +void au_wkq_fin(void)
36429 + destroy_workqueue(au_wkq);
36432 +int __init au_wkq_init(void)
36437 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36438 + if (IS_ERR(au_wkq))
36439 + err = PTR_ERR(au_wkq);
36440 + else if (!au_wkq)
36445 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36446 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 08:00:00.000000000 +0800
36447 +++ linux/fs/aufs/wkq.h 2019-07-11 21:21:54.382384486 +0800
36449 +/* SPDX-License-Identifier: GPL-2.0 */
36451 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36453 + * This program, aufs is free software; you can redistribute it and/or modify
36454 + * it under the terms of the GNU General Public License as published by
36455 + * the Free Software Foundation; either version 2 of the License, or
36456 + * (at your option) any later version.
36458 + * This program is distributed in the hope that it will be useful,
36459 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36460 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36461 + * GNU General Public License for more details.
36463 + * You should have received a copy of the GNU General Public License
36464 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36468 + * workqueue for asynchronous/super-io operations
36469 + * todo: try new credentials management scheme
36472 +#ifndef __AUFS_WKQ_H__
36473 +#define __AUFS_WKQ_H__
36477 +#include <linux/wait.h>
36479 +struct super_block;
36481 +/* ---------------------------------------------------------------------- */
36484 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36486 +struct au_nowait_tasks {
36488 + wait_queue_head_t nw_wq;
36491 +/* ---------------------------------------------------------------------- */
36493 +typedef void (*au_wkq_func_t)(void *args);
36496 +#define AuWkq_WAIT 1
36497 +#define AuWkq_NEST (1 << 1)
36498 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36499 +#define au_fset_wkq(flags, name) \
36500 + do { (flags) |= AuWkq_##name; } while (0)
36501 +#define au_fclr_wkq(flags, name) \
36502 + do { (flags) &= ~AuWkq_##name; } while (0)
36505 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36506 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36507 + unsigned int flags);
36508 +void au_nwt_init(struct au_nowait_tasks *nwt);
36509 +int __init au_wkq_init(void);
36510 +void au_wkq_fin(void);
36512 +/* ---------------------------------------------------------------------- */
36514 +static inline int au_wkq_test(void)
36516 + return current->flags & PF_WQ_WORKER;
36519 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36521 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36524 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36526 + if (atomic_dec_and_test(&nwt->nw_len))
36527 + wake_up_all(&nwt->nw_wq);
36530 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36532 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36536 +#endif /* __KERNEL__ */
36537 +#endif /* __AUFS_WKQ_H__ */
36538 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36539 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 08:00:00.000000000 +0800
36540 +++ linux/fs/aufs/xattr.c 2019-07-11 21:21:54.382384486 +0800
36542 +// SPDX-License-Identifier: GPL-2.0
36544 + * Copyright (C) 2014-2019 Junjiro R. Okajima
36546 + * This program, aufs is free software; you can redistribute it and/or modify
36547 + * it under the terms of the GNU General Public License as published by
36548 + * the Free Software Foundation; either version 2 of the License, or
36549 + * (at your option) any later version.
36551 + * This program is distributed in the hope that it will be useful,
36552 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36553 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36554 + * GNU General Public License for more details.
36556 + * You should have received a copy of the GNU General Public License
36557 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36561 + * handling xattr functions
36564 +#include <linux/fs.h>
36565 +#include <linux/posix_acl_xattr.h>
36566 +#include <linux/xattr.h>
36569 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36571 + if (!ignore_flags)
36579 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36584 +#define cmp(brattr, prefix) do { \
36585 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36586 + XATTR_##prefix##_PREFIX_LEN)) { \
36587 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36593 + cmp(SEC, SECURITY);
36594 + cmp(SYS, SYSTEM);
36595 + cmp(TR, TRUSTED);
36599 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36606 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36608 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36609 + char *name, char **buf, unsigned int ignore_flags,
36610 + unsigned int verbose)
36614 + struct inode *h_idst;
36616 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36618 + if (unlikely(err <= 0)) {
36619 + if (err == -ENODATA
36620 + || (err == -EOPNOTSUPP
36621 + && ((ignore_flags & au_xattr_out_of_list)
36622 + || (au_test_nfs_noacl(d_inode(h_src))
36623 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36625 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36628 + if (err && (verbose || au_debug_test()))
36629 + pr_err("%s, err %d\n", name, err);
36633 + /* unlock it temporary */
36634 + h_idst = d_inode(h_dst);
36635 + inode_unlock(h_idst);
36636 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36637 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36638 + if (unlikely(err)) {
36639 + if (verbose || au_debug_test())
36640 + pr_err("%s, err %d\n", name, err);
36641 + err = au_xattr_ignore(err, name, ignore_flags);
36648 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36649 + unsigned int verbose)
36651 + int err, unlocked, acl_access, acl_default;
36653 + struct inode *h_isrc, *h_idst;
36654 + char *value, *p, *o, *e;
36656 + /* try stopping to update the source inode while we are referencing */
36657 + /* there should not be the parent-child relationship between them */
36658 + h_isrc = d_inode(h_src);
36659 + h_idst = d_inode(h_dst);
36660 + inode_unlock(h_idst);
36661 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36662 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36665 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36666 + ssz = vfs_listxattr(h_src, NULL, 0);
36668 + if (unlikely(err < 0)) {
36670 + if (err == -ENODATA
36671 + || err == -EOPNOTSUPP)
36672 + err = 0; /* ignore */
36681 + p = kmalloc(ssz, GFP_NOFS);
36683 + if (unlikely(!p))
36685 + err = vfs_listxattr(h_src, p, ssz);
36687 + inode_unlock_shared(h_isrc);
36689 + AuDbg("err %d, ssz %zd\n", err, ssz);
36690 + if (unlikely(err < 0))
36698 + while (!err && p < e) {
36699 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36700 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36701 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36702 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36704 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36706 + p += strlen(p) + 1;
36709 + ignore_flags |= au_xattr_out_of_list;
36710 + if (!err && !acl_access) {
36711 + err = au_do_cpup_xattr(h_dst, h_src,
36712 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36713 + ignore_flags, verbose);
36716 + if (!err && !acl_default) {
36717 + err = au_do_cpup_xattr(h_dst, h_src,
36718 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36719 + ignore_flags, verbose);
36723 + au_kfree_try_rcu(value);
36726 + au_kfree_try_rcu(o);
36729 + inode_unlock_shared(h_isrc);
36734 +/* ---------------------------------------------------------------------- */
36736 +static int au_smack_reentering(struct super_block *sb)
36738 +#if IS_ENABLED(CONFIG_SECURITY_SMACK)
36740 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36741 + * i_op->getxattr(). ouch.
36743 + return si_pid_test(sb);
36754 +struct au_lgxattr {
36762 + const char *name;
36769 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
36773 + struct path h_path;
36774 + struct super_block *sb;
36776 + sb = dentry->d_sb;
36777 + reenter = au_smack_reentering(sb);
36779 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36780 + if (unlikely(err))
36783 + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter);
36784 + if (unlikely(err))
36786 + if (unlikely(!h_path.dentry))
36787 + /* illegally overlapped or something */
36788 + goto out_di; /* pretending success */
36790 + /* always topmost entry only */
36791 + switch (arg->type) {
36792 + case AU_XATTR_LIST:
36793 + err = vfs_listxattr(h_path.dentry,
36794 + arg->u.list.list, arg->u.list.size);
36796 + case AU_XATTR_GET:
36797 + AuDebugOn(d_is_negative(h_path.dentry));
36798 + err = vfs_getxattr(h_path.dentry,
36799 + arg->u.get.name, arg->u.get.value,
36800 + arg->u.get.size);
36806 + di_read_unlock(dentry, AuLock_IR);
36809 + si_read_unlock(sb);
36815 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36817 + struct au_lgxattr arg = {
36818 + .type = AU_XATTR_LIST,
36825 + return au_lgxattr(dentry, &arg);
36828 +static ssize_t au_getxattr(struct dentry *dentry,
36829 + struct inode *inode __maybe_unused,
36830 + const char *name, void *value, size_t size)
36832 + struct au_lgxattr arg = {
36833 + .type = AU_XATTR_GET,
36841 + return au_lgxattr(dentry, &arg);
36844 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36845 + const char *name, const void *value, size_t size,
36848 + struct au_sxattr arg = {
36849 + .type = AU_XATTR_SET,
36858 + return au_sxattr(dentry, inode, &arg);
36861 +/* ---------------------------------------------------------------------- */
36863 +static int au_xattr_get(const struct xattr_handler *handler,
36864 + struct dentry *dentry, struct inode *inode,
36865 + const char *name, void *buffer, size_t size)
36867 + return au_getxattr(dentry, inode, name, buffer, size);
36870 +static int au_xattr_set(const struct xattr_handler *handler,
36871 + struct dentry *dentry, struct inode *inode,
36872 + const char *name, const void *value, size_t size,
36875 + return au_setxattr(dentry, inode, name, value, size, flags);
36878 +static const struct xattr_handler au_xattr_handler = {
36881 + .get = au_xattr_get,
36882 + .set = au_xattr_set
36885 +static const struct xattr_handler *au_xattr_handlers[] = {
36886 +#ifdef CONFIG_FS_POSIX_ACL
36887 + &posix_acl_access_xattr_handler,
36888 + &posix_acl_default_xattr_handler,
36890 + &au_xattr_handler, /* must be last */
36894 +void au_xattr_init(struct super_block *sb)
36896 + sb->s_xattr = au_xattr_handlers;
36898 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36899 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 08:00:00.000000000 +0800
36900 +++ linux/fs/aufs/xino.c 2019-07-11 21:21:54.382384486 +0800
36902 +// SPDX-License-Identifier: GPL-2.0
36904 + * Copyright (C) 2005-2019 Junjiro R. Okajima
36906 + * This program, aufs is free software; you can redistribute it and/or modify
36907 + * it under the terms of the GNU General Public License as published by
36908 + * the Free Software Foundation; either version 2 of the License, or
36909 + * (at your option) any later version.
36911 + * This program is distributed in the hope that it will be useful,
36912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36914 + * GNU General Public License for more details.
36916 + * You should have received a copy of the GNU General Public License
36917 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36921 + * external inode number translation table and bitmap
36923 + * things to consider
36925 + * + au_xino object
36926 + * + XINO files (xino, xib, xigen)
36927 + * + dynamic debugfs entries (xiN)
36928 + * + static debugfs entries (xib, xigen)
36929 + * + static sysfs entry (xi_path)
36930 + * - several entry points to handle them.
36931 + * + mount(2) without xino option (default)
36932 + * + mount(2) with xino option
36933 + * + mount(2) with noxino option
36935 + * + remount with add/del branches
36936 + * + remount with xino/noxino options
36939 +#include <linux/seq_file.h>
36940 +#include <linux/statfs.h>
36943 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36944 + aufs_bindex_t bbot,
36945 + struct super_block *h_sb)
36947 + /* todo: try binary-search if the branches are many */
36948 + for (; btop <= bbot; btop++)
36949 + if (h_sb == au_sbr_sb(sb, btop))
36955 + * find another branch who is on the same filesystem of the specified
36956 + * branch{@btgt}. search until @bbot.
36958 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36959 + aufs_bindex_t bbot)
36961 + aufs_bindex_t bindex;
36962 + struct super_block *tgt_sb;
36964 + tgt_sb = au_sbr_sb(sb, btgt);
36965 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36967 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36972 +/* ---------------------------------------------------------------------- */
36975 + * stop unnecessary notify events at creating xino files
36978 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36980 + aufs_bindex_t bfound, bindex, bbot;
36981 + struct dentry *parent;
36982 + struct au_branch *br;
36985 + parent = dentry->d_parent; /* safe d_parent access */
36986 + bbot = au_sbbot(sb);
36987 + for (bindex = 0; bindex <= bbot; bindex++) {
36988 + br = au_sbr(sb, bindex);
36989 + if (au_br_dentry(br) == parent) {
36995 + AuDbg("bfound b%d\n", bfound);
36999 +struct au_xino_lock_dir {
37000 + struct au_hinode *hdir;
37001 + struct dentry *parent;
37002 + struct inode *dir;
37005 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37006 + unsigned int lsc)
37008 + struct dentry *parent;
37009 + struct inode *dir;
37011 + parent = dget_parent(dentry);
37012 + dir = d_inode(parent);
37013 + inode_lock_nested(dir, lsc);
37014 +#if 0 /* it should not happen */
37015 + spin_lock(&dentry->d_lock);
37016 + if (unlikely(dentry->d_parent != parent)) {
37017 + spin_unlock(&dentry->d_lock);
37018 + inode_unlock(dir);
37023 + spin_unlock(&dentry->d_lock);
37030 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37031 + struct au_xino_lock_dir *ldir)
37033 + aufs_bindex_t bindex;
37035 + ldir->hdir = NULL;
37036 + bindex = au_xi_root(sb, xipath->dentry);
37037 + if (bindex >= 0) {
37038 + /* rw branch root */
37039 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37040 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37043 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37045 + ldir->dir = d_inode(ldir->parent);
37049 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37052 + au_hn_inode_unlock(ldir->hdir);
37054 + inode_unlock(ldir->dir);
37055 + dput(ldir->parent);
37059 +/* ---------------------------------------------------------------------- */
37062 + * create and set a new xino file
37064 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37067 + struct file *file;
37068 + struct dentry *h_parent, *d;
37069 + struct inode *h_dir, *inode;
37071 + static DEFINE_MUTEX(mtx);
37074 + * at mount-time, and the xino file is the default path,
37075 + * hnotify is disabled so we have no notify events to ignore.
37076 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37079 + mutex_lock(&mtx);
37080 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37081 + /* | __FMODE_NONOTIFY */,
37083 + if (IS_ERR(file)) {
37085 + mutex_unlock(&mtx);
37087 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37091 + /* keep file count */
37093 + d = file->f_path.dentry;
37094 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37096 + mutex_unlock(&mtx);
37097 + /* mnt_want_write() is unnecessary here */
37098 + h_dir = d_inode(h_parent);
37099 + inode = file_inode(file);
37100 + /* no delegation since it is just created */
37101 + if (inode->i_nlink)
37102 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37104 + inode_unlock(h_dir);
37106 + if (unlikely(err)) {
37108 + pr_err("unlink %s(%d)\n", fpath, err);
37113 + if (unlikely(sb == d->d_sb)) {
37115 + pr_err("%s must be outside\n", fpath);
37118 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37120 + pr_err("xino doesn't support %s(%s)\n",
37121 + fpath, au_sbtype(d->d_sb));
37124 + return file; /* success */
37128 + file = ERR_PTR(err);
37133 + * create a new xinofile at the same place/path as @base.
37135 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37136 + struct file *copy_src)
37138 + struct file *file;
37139 + struct dentry *dentry, *parent;
37140 + struct inode *dir, *delegated;
37141 + struct qstr *name;
37142 + struct path path;
37143 + int err, do_unlock;
37144 + struct au_xino_lock_dir ldir;
37147 + au_xino_lock_dir(sb, base, &ldir);
37148 + dentry = base->dentry;
37149 + parent = dentry->d_parent; /* dir inode is locked */
37150 + dir = d_inode(parent);
37153 + name = &dentry->d_name;
37154 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37155 + if (IS_ERR(path.dentry)) {
37156 + file = (void *)path.dentry;
37157 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37161 + /* no need to mnt_want_write() since we call dentry_open() later */
37162 + err = vfs_create(dir, path.dentry, 0666, NULL);
37163 + if (unlikely(err)) {
37164 + file = ERR_PTR(err);
37165 + pr_err("%pd create err %d\n", dentry, err);
37169 + path.mnt = base->mnt;
37170 + file = vfsub_dentry_open(&path,
37171 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37172 + /* | __FMODE_NONOTIFY */);
37173 + if (IS_ERR(file)) {
37174 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37178 + delegated = NULL;
37179 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37180 + au_xino_unlock_dir(&ldir);
37182 + if (unlikely(err == -EWOULDBLOCK)) {
37183 + pr_warn("cannot retry for NFSv4 delegation"
37184 + " for an internal unlink\n");
37187 + if (unlikely(err)) {
37188 + pr_err("%pd unlink err %d\n", dentry, err);
37193 + /* no one can touch copy_src xino */
37194 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37195 + if (unlikely(err)) {
37196 + pr_err("%pd copy err %d\n", dentry, err);
37200 + goto out_dput; /* success */
37204 + file = ERR_PTR(err);
37206 + dput(path.dentry);
37209 + au_xino_unlock_dir(&ldir);
37213 +struct file *au_xino_file1(struct au_xino *xi)
37215 + struct file *file;
37216 + unsigned int u, nfile;
37219 + nfile = xi->xi_nfile;
37220 + for (u = 0; u < nfile; u++) {
37221 + file = xi->xi_file[u];
37229 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37240 + if (idx < xi->xi_nfile) {
37241 + f = xi->xi_file[idx];
37245 + p = au_kzrealloc(xi->xi_file,
37246 + sizeof(*xi->xi_file) * xi->xi_nfile,
37247 + sizeof(*xi->xi_file) * (idx + 1),
37248 + GFP_NOFS, /*may_shrink*/0);
37250 + MtxMustLock(&xi->xi_mtx);
37252 + xi->xi_nfile = idx + 1;
37260 + xi->xi_file[idx] = file;
37267 + * if @xinew->xi is not set, then create new xigen file.
37269 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37271 + struct file *file;
37274 + SiMustAnyLock(sb);
37276 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37277 + if (IS_ERR(file)) {
37278 + err = PTR_ERR(file);
37279 + pr_err("%s[%d], err %d\n",
37280 + xinew->xi ? "xino" : "xigen",
37281 + xinew->idx, err);
37286 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37289 + /* todo: make xigen file an array */
37290 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37293 + if (unlikely(err))
37294 + file = ERR_PTR(err);
37300 +/* ---------------------------------------------------------------------- */
37303 + * truncate xino files
37305 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37306 + int idx, struct kstatfs *st)
37310 + struct file *file, *new_xino;
37311 + struct au_xi_new xinew = {
37316 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37317 + file = au_xino_file(xinew.xi, idx);
37321 + xinew.base = &file->f_path;
37322 + err = vfs_statfs(xinew.base, st);
37323 + if (unlikely(err)) {
37324 + AuErr1("statfs err %d, ignored\n", err);
37329 + blocks = file_inode(file)->i_blocks;
37330 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37331 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37333 + xinew.copy_src = file;
37334 + new_xino = au_xi_new(sb, &xinew);
37335 + if (IS_ERR(new_xino)) {
37336 + err = PTR_ERR(new_xino);
37337 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37341 + err = vfs_statfs(&new_xino->f_path, st);
37343 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37344 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37345 + st->f_bfree, st->f_blocks);
37347 + AuErr1("statfs err %d, ignored\n", err);
37355 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37358 + unsigned long jiffy;
37359 + aufs_bindex_t bbot;
37360 + struct kstatfs *st;
37361 + struct au_branch *br;
37362 + struct au_xino *xi;
37365 + st = kmalloc(sizeof(*st), GFP_NOFS);
37366 + if (unlikely(!st))
37370 + bbot = au_sbbot(sb);
37371 + if (unlikely(bindex < 0 || bbot < bindex))
37376 + br = au_sbr(sb, bindex);
37377 + xi = br->br_xino;
37378 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37379 + err = au_xino_do_trunc(sb, bindex, i, st);
37381 + au_sbi(sb)->si_xino_jiffy = jiffy;
37384 + au_kfree_rcu(st);
37389 +struct xino_do_trunc_args {
37390 + struct super_block *sb;
37391 + struct au_branch *br;
37395 +static void xino_do_trunc(void *_args)
37397 + struct xino_do_trunc_args *args = _args;
37398 + struct super_block *sb;
37399 + struct au_branch *br;
37400 + struct inode *dir;
37402 + aufs_bindex_t bindex;
37406 + dir = d_inode(sb->s_root);
37410 + si_noflush_write_lock(sb);
37411 + ii_read_lock_parent(dir);
37412 + bindex = au_br_index(sb, br->br_id);
37413 + err = au_xino_trunc(sb, bindex, idx);
37414 + ii_read_unlock(dir);
37415 + if (unlikely(err))
37416 + pr_warn("err b%d, (%d)\n", bindex, err);
37417 + atomic_dec(&br->br_xino->xi_truncating);
37418 + au_lcnt_dec(&br->br_count);
37419 + si_write_unlock(sb);
37420 + au_nwt_done(&au_sbi(sb)->si_nowait);
37421 + au_kfree_rcu(args);
37425 + * returns the index in the xi_file array whose corresponding file is necessary
37426 + * to truncate, or -1 which means no need to truncate.
37428 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37432 + struct kstatfs st;
37433 + struct au_sbinfo *sbinfo;
37434 + struct au_xino *xi;
37435 + struct file *file;
37437 + /* todo: si_xino_expire and the ratio should be customizable */
37438 + sbinfo = au_sbi(sb);
37439 + if (time_before(jiffies,
37440 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37443 + /* truncation border */
37444 + xi = br->br_xino;
37445 + for (u = 0; u < xi->xi_nfile; u++) {
37446 + file = au_xino_file(xi, u);
37450 + err = vfs_statfs(&file->f_path, &st);
37451 + if (unlikely(err)) {
37452 + AuErr1("statfs err %d, ignored\n", err);
37455 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37456 + >= AUFS_XINO_DEF_TRUNC)
37463 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37466 + struct xino_do_trunc_args *args;
37469 + idx = xino_trunc_test(sb, br);
37473 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37476 + /* lock and kfree() will be called in trunc_xino() */
37477 + args = kmalloc(sizeof(*args), GFP_NOFS);
37478 + if (unlikely(!args)) {
37479 + AuErr1("no memory\n");
37483 + au_lcnt_inc(&br->br_count);
37487 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37489 + return; /* success */
37491 + pr_err("wkq %d\n", wkq_err);
37492 + au_lcnt_dec(&br->br_count);
37493 + au_kfree_rcu(args);
37496 + atomic_dec(&br->br_xino->xi_truncating);
37499 +/* ---------------------------------------------------------------------- */
37501 +struct au_xi_calc {
37506 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37507 + struct au_xi_calc *calc)
37511 + maxent = au_xi_maxent(sb);
37512 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37513 + calc->pos *= sizeof(ino_t);
37516 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37517 + struct au_xi_calc *calc)
37520 + struct file *file;
37521 + struct au_xino *xi = br->br_xino;
37522 + struct au_xi_new xinew = {
37526 + SiMustAnyLock(sb);
37532 + mutex_lock(&xi->xi_mtx);
37533 + file = au_xino_file(xi, calc->idx);
37537 + file = au_xino_file(xi, /*idx*/-1);
37538 + AuDebugOn(!file);
37539 + xinew.idx = calc->idx;
37540 + xinew.base = &file->f_path;
37541 + /* xinew.copy_src = NULL; */
37542 + file = au_xi_new(sb, &xinew);
37543 + if (IS_ERR(file))
37544 + err = PTR_ERR(file);
37547 + mutex_unlock(&xi->xi_mtx);
37552 +struct au_xino_do_new_async_args {
37553 + struct super_block *sb;
37554 + struct au_branch *br;
37555 + struct au_xi_calc calc;
37559 +struct au_xi_writing {
37560 + struct hlist_bl_node node;
37561 + ino_t h_ino, ino;
37564 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37565 + struct au_xi_calc *calc, ino_t ino);
37567 +static void au_xino_call_do_new_async(void *args)
37569 + struct au_xino_do_new_async_args *a = args;
37570 + struct au_branch *br;
37571 + struct super_block *sb;
37572 + struct au_sbinfo *sbi;
37573 + struct inode *root;
37574 + struct file *file;
37575 + struct au_xi_writing *del, *p;
37576 + struct hlist_bl_head *hbl;
37577 + struct hlist_bl_node *pos;
37582 + sbi = au_sbi(sb);
37583 + si_noflush_read_lock(sb);
37584 + root = d_inode(sb->s_root);
37585 + ii_read_lock_child(root);
37586 + err = au_xino_do_new_async(sb, br, &a->calc);
37587 + if (unlikely(err)) {
37588 + AuIOErr("err %d\n", err);
37592 + file = au_xino_file(br->br_xino, a->calc.idx);
37593 + AuDebugOn(!file);
37594 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37595 + if (unlikely(err)) {
37596 + AuIOErr("err %d\n", err);
37601 + hbl = &br->br_xino->xi_writing;
37602 + hlist_bl_lock(hbl);
37603 + au_hbl_for_each(pos, hbl) {
37604 + p = container_of(pos, struct au_xi_writing, node);
37605 + if (p->ino == a->ino) {
37607 + hlist_bl_del(&p->node);
37611 + hlist_bl_unlock(hbl);
37612 + au_kfree_rcu(del);
37615 + au_lcnt_dec(&br->br_count);
37616 + ii_read_unlock(root);
37617 + si_read_unlock(sb);
37618 + au_nwt_done(&sbi->si_nowait);
37623 + * create a new xino file asynchronously
37625 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37626 + struct au_xi_calc *calc, ino_t ino)
37629 + struct au_xino_do_new_async_args *arg;
37632 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37633 + if (unlikely(!arg))
37638 + arg->calc = *calc;
37640 + au_lcnt_inc(&br->br_count);
37641 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37642 + if (unlikely(err)) {
37643 + pr_err("wkq %d\n", err);
37644 + au_lcnt_dec(&br->br_count);
37645 + au_kfree_rcu(arg);
37653 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37654 + * at the position of @h_ino.
37656 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37661 + struct au_xi_calc calc;
37662 + struct au_sbinfo *sbinfo;
37663 + struct file *file;
37664 + struct au_xino *xi;
37665 + struct hlist_bl_head *hbl;
37666 + struct hlist_bl_node *pos;
37667 + struct au_xi_writing *p;
37670 + if (!au_opt_test(au_mntflags(sb), XINO))
37671 + return 0; /* no xino */
37674 + au_xi_calc(sb, h_ino, &calc);
37675 + xi = au_sbr(sb, bindex)->br_xino;
37676 + file = au_xino_file(xi, calc.idx);
37678 + hbl = &xi->xi_writing;
37679 + hlist_bl_lock(hbl);
37680 + au_hbl_for_each(pos, hbl) {
37681 + p = container_of(pos, struct au_xi_writing, node);
37682 + if (p->h_ino == h_ino) {
37683 + AuDbg("hi%llu, i%llu, found\n",
37684 + (u64)p->h_ino, (u64)p->ino);
37689 + hlist_bl_unlock(hbl);
37691 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37692 + return 0; /* no xino */
37694 + sbinfo = au_sbi(sb);
37695 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37696 + if (sz == sizeof(*ino))
37697 + return 0; /* success */
37700 + if (unlikely(sz >= 0)) {
37702 + AuIOErr("xino read error (%zd)\n", sz);
37707 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37708 + struct au_xi_calc *calc, ino_t ino)
37712 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37713 + if (sz == sizeof(ino))
37714 + return 0; /* success */
37716 + AuIOErr("write failed (%zd)\n", sz);
37721 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37722 + * at the position of @h_ino.
37723 + * even if @ino is zero, it is written to the xinofile and means no entry.
37724 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37725 + * try truncating it.
37727 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37731 + unsigned int mnt_flags;
37732 + struct au_xi_calc calc;
37733 + struct file *file;
37734 + struct au_branch *br;
37735 + struct au_xino *xi;
37736 + struct au_xi_writing *p;
37738 + SiMustAnyLock(sb);
37740 + mnt_flags = au_mntflags(sb);
37741 + if (!au_opt_test(mnt_flags, XINO))
37744 + au_xi_calc(sb, h_ino, &calc);
37745 + br = au_sbr(sb, bindex);
37746 + xi = br->br_xino;
37747 + file = au_xino_file(xi, calc.idx);
37749 + /* store the inum pair into the list */
37750 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37751 + p->h_ino = h_ino;
37753 + au_hbl_add(&p->node, &xi->xi_writing);
37755 + /* create and write a new xino file asynchronously */
37756 + err = au_xino_new_async(sb, br, &calc, ino);
37758 + return 0; /* success */
37762 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37764 + br = au_sbr(sb, bindex);
37765 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37766 + && au_test_fs_trunc_xino(au_br_sb(br)))
37767 + xino_try_trunc(sb, br);
37768 + return 0; /* success */
37772 + AuIOErr("write failed (%d)\n", err);
37776 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37777 + size_t size, loff_t *pos);
37779 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37780 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37784 + mm_segment_t oldfs;
37790 + const int prevent_endless = 10;
37794 + oldfs = get_fs();
37795 + set_fs(KERNEL_DS);
37797 + err = func(file, buf.u, size, pos);
37798 + if (err == -EINTR
37799 + && !au_wkq_test()
37800 + && fatal_signal_pending(current)) {
37802 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37803 + BUG_ON(err == -EINTR);
37804 + oldfs = get_fs();
37805 + set_fs(KERNEL_DS);
37807 + } while (i++ < prevent_endless
37808 + && (err == -EAGAIN || err == -EINTR));
37811 +#if 0 /* reserved for future use */
37813 + fsnotify_access(file->f_path.dentry);
37819 +struct xino_fread_args {
37821 + vfs_readf_t func;
37822 + struct file *file;
37828 +static void call_xino_fread(void *args)
37830 + struct xino_fread_args *a = args;
37831 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37834 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37835 + size_t size, loff_t *pos)
37839 + struct xino_fread_args args = {
37848 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37849 + if (unlikely(wkq_err))
37855 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37856 + size_t size, loff_t *pos);
37858 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37859 + size_t size, loff_t *pos)
37862 + mm_segment_t oldfs;
37865 + const char __user *u;
37868 + const int prevent_endless = 10;
37872 + oldfs = get_fs();
37873 + set_fs(KERNEL_DS);
37875 + err = func(file, buf.u, size, pos);
37876 + if (err == -EINTR
37877 + && !au_wkq_test()
37878 + && fatal_signal_pending(current)) {
37880 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37881 + BUG_ON(err == -EINTR);
37882 + oldfs = get_fs();
37883 + set_fs(KERNEL_DS);
37885 + } while (i++ < prevent_endless
37886 + && (err == -EAGAIN || err == -EINTR));
37889 +#if 0 /* reserved for future use */
37891 + fsnotify_modify(file->f_path.dentry);
37897 +struct do_xino_fwrite_args {
37899 + vfs_writef_t func;
37900 + struct file *file;
37906 +static void call_do_xino_fwrite(void *args)
37908 + struct do_xino_fwrite_args *a = args;
37909 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37912 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37913 + size_t size, loff_t *pos)
37917 + struct do_xino_fwrite_args args = {
37927 + * it breaks RLIMIT_FSIZE and normal user's limit,
37928 + * users should care about quota and real 'filesystem full.'
37930 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37931 + if (unlikely(wkq_err))
37937 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37938 + size_t size, loff_t *pos)
37942 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37944 + err = do_xino_fwrite(func, file, buf, size, pos);
37948 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37955 +/* ---------------------------------------------------------------------- */
37958 + * inode number bitmap
37960 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37961 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37965 + AuDebugOn(bit < 0 || page_bits <= bit);
37966 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37970 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37972 + AuDebugOn(ino < AUFS_FIRST_INO);
37973 + ino -= AUFS_FIRST_INO;
37974 + *pindex = ino / page_bits;
37975 + *bit = ino % page_bits;
37978 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37983 + struct au_sbinfo *sbinfo;
37984 + struct file *xib;
37985 + unsigned long *p;
37987 + sbinfo = au_sbi(sb);
37988 + MtxMustLock(&sbinfo->si_xib_mtx);
37989 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37990 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37992 + if (pindex == sbinfo->si_xib_last_pindex)
37995 + xib = sbinfo->si_xib;
37996 + p = sbinfo->si_xib_buf;
37997 + pos = sbinfo->si_xib_last_pindex;
37998 + pos *= PAGE_SIZE;
37999 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38000 + if (unlikely(sz != PAGE_SIZE))
38004 + pos *= PAGE_SIZE;
38005 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38006 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
38008 + memset(p, 0, PAGE_SIZE);
38009 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
38011 + if (sz == PAGE_SIZE) {
38012 + sbinfo->si_xib_last_pindex = pindex;
38013 + return 0; /* success */
38017 + AuIOErr1("write failed (%zd)\n", sz);
38024 +static void au_xib_clear_bit(struct inode *inode)
38027 + unsigned long pindex;
38028 + struct super_block *sb;
38029 + struct au_sbinfo *sbinfo;
38031 + AuDebugOn(inode->i_nlink);
38033 + sb = inode->i_sb;
38034 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38035 + AuDebugOn(page_bits <= bit);
38036 + sbinfo = au_sbi(sb);
38037 + mutex_lock(&sbinfo->si_xib_mtx);
38038 + err = xib_pindex(sb, pindex);
38040 + clear_bit(bit, sbinfo->si_xib_buf);
38041 + sbinfo->si_xib_next_bit = bit;
38043 + mutex_unlock(&sbinfo->si_xib_mtx);
38046 +/* ---------------------------------------------------------------------- */
38049 + * truncate a xino bitmap file
38053 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38057 + unsigned long pindex;
38058 + loff_t pos, pend;
38059 + struct au_sbinfo *sbinfo;
38060 + vfs_readf_t func;
38062 + unsigned long *p;
38065 + sbinfo = au_sbi(sb);
38066 + MtxMustLock(&sbinfo->si_xib_mtx);
38067 + p = sbinfo->si_xib_buf;
38068 + func = sbinfo->si_xread;
38069 + pend = vfsub_f_size_read(file);
38071 + while (pos < pend) {
38072 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38074 + if (unlikely(sz <= 0))
38078 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38079 + if (unlikely(*ino < AUFS_FIRST_INO))
38082 + xib_calc_bit(*ino, &pindex, &bit);
38083 + AuDebugOn(page_bits <= bit);
38084 + err = xib_pindex(sb, pindex);
38096 +static int xib_restore(struct super_block *sb)
38099 + unsigned int nfile;
38100 + aufs_bindex_t bindex, bbot;
38102 + struct au_branch *br;
38103 + struct au_xino *xi;
38104 + struct file *file;
38107 + page = (void *)__get_free_page(GFP_NOFS);
38108 + if (unlikely(!page))
38112 + bbot = au_sbbot(sb);
38113 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38114 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38115 + br = au_sbr(sb, bindex);
38116 + xi = br->br_xino;
38117 + nfile = xi->xi_nfile;
38118 + for (i = 0; i < nfile; i++) {
38119 + file = au_xino_file(xi, i);
38121 + err = do_xib_restore(sb, file, page);
38124 + AuDbg("skip shared b%d\n", bindex);
38125 + free_page((unsigned long)page);
38131 +int au_xib_trunc(struct super_block *sb)
38136 + struct au_sbinfo *sbinfo;
38137 + unsigned long *p;
38138 + struct file *file;
38140 + SiMustWriteLock(sb);
38143 + sbinfo = au_sbi(sb);
38144 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38147 + file = sbinfo->si_xib;
38148 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38151 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38152 + err = PTR_ERR(file);
38153 + if (IS_ERR(file))
38155 + fput(sbinfo->si_xib);
38156 + sbinfo->si_xib = file;
38158 + p = sbinfo->si_xib_buf;
38159 + memset(p, 0, PAGE_SIZE);
38161 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38162 + if (unlikely(sz != PAGE_SIZE)) {
38164 + AuIOErr("err %d\n", err);
38170 + mutex_lock(&sbinfo->si_xib_mtx);
38171 + /* mnt_want_write() is unnecessary here */
38172 + err = xib_restore(sb);
38173 + mutex_unlock(&sbinfo->si_xib_mtx);
38179 +/* ---------------------------------------------------------------------- */
38181 +struct au_xino *au_xino_alloc(unsigned int nfile)
38183 + struct au_xino *xi;
38185 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38186 + if (unlikely(!xi))
38188 + xi->xi_nfile = nfile;
38189 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38190 + if (unlikely(!xi->xi_file))
38193 + xi->xi_nondir.total = 8; /* initial size */
38194 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38196 + if (unlikely(!xi->xi_nondir.array))
38199 + spin_lock_init(&xi->xi_nondir.spin);
38200 + init_waitqueue_head(&xi->xi_nondir.wqh);
38201 + mutex_init(&xi->xi_mtx);
38202 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38203 + atomic_set(&xi->xi_truncating, 0);
38204 + kref_init(&xi->xi_kref);
38205 + goto out; /* success */
38208 + au_kfree_try_rcu(xi->xi_file);
38210 + au_kfree_rcu(xi);
38216 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38219 + struct au_xino *xi;
38222 + xi = au_xino_alloc(idx + 1);
38223 + if (unlikely(!xi)) {
38230 + xi->xi_file[idx] = file;
38231 + AuDebugOn(br->br_xino);
38232 + br->br_xino = xi;
38238 +static void au_xino_release(struct kref *kref)
38240 + struct au_xino *xi;
38242 + unsigned long ul;
38243 + struct hlist_bl_head *hbl;
38244 + struct hlist_bl_node *pos, *n;
38245 + struct au_xi_writing *p;
38247 + xi = container_of(kref, struct au_xino, xi_kref);
38248 + for (i = 0; i < xi->xi_nfile; i++)
38249 + if (xi->xi_file[i])
38250 + fput(xi->xi_file[i]);
38251 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38252 + AuDebugOn(xi->xi_nondir.array[i]);
38253 + mutex_destroy(&xi->xi_mtx);
38254 + hbl = &xi->xi_writing;
38255 + ul = au_hbl_count(hbl);
38256 + if (unlikely(ul)) {
38257 + pr_warn("xi_writing %lu\n", ul);
38258 + hlist_bl_lock(hbl);
38259 + hlist_bl_for_each_entry_safe (p, pos, n, hbl, node) {
38260 + hlist_bl_del(&p->node);
38263 + hlist_bl_unlock(hbl);
38265 + au_kfree_try_rcu(xi->xi_file);
38266 + au_kfree_try_rcu(xi->xi_nondir.array);
38267 + au_kfree_rcu(xi);
38270 +int au_xino_put(struct au_branch *br)
38273 + struct au_xino *xi;
38276 + xi = br->br_xino;
38278 + br->br_xino = NULL;
38279 + ret = kref_put(&xi->xi_kref, au_xino_release);
38285 +/* ---------------------------------------------------------------------- */
38288 + * xino mount option handlers
38292 +static void xino_clear_xib(struct super_block *sb)
38294 + struct au_sbinfo *sbinfo;
38296 + SiMustWriteLock(sb);
38298 + sbinfo = au_sbi(sb);
38299 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38300 + if (sbinfo->si_xib)
38301 + fput(sbinfo->si_xib);
38302 + sbinfo->si_xib = NULL;
38303 + if (sbinfo->si_xib_buf)
38304 + free_page((unsigned long)sbinfo->si_xib_buf);
38305 + sbinfo->si_xib_buf = NULL;
38308 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38312 + struct au_sbinfo *sbinfo;
38313 + struct file *file;
38314 + struct super_block *xi_sb;
38316 + SiMustWriteLock(sb);
38318 + sbinfo = au_sbi(sb);
38319 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38320 + err = PTR_ERR(file);
38321 + if (IS_ERR(file))
38323 + if (sbinfo->si_xib)
38324 + fput(sbinfo->si_xib);
38325 + sbinfo->si_xib = file;
38326 + sbinfo->si_xread = vfs_readf(file);
38327 + sbinfo->si_xwrite = vfs_writef(file);
38328 + xi_sb = file_inode(file)->i_sb;
38329 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38330 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38332 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38333 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38336 + sbinfo->si_ximaxent /= sizeof(ino_t);
38339 + if (!sbinfo->si_xib_buf)
38340 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38341 + if (unlikely(!sbinfo->si_xib_buf))
38344 + sbinfo->si_xib_last_pindex = 0;
38345 + sbinfo->si_xib_next_bit = 0;
38346 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38348 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38349 + PAGE_SIZE, &pos);
38350 + if (unlikely(err != PAGE_SIZE))
38354 + goto out; /* success */
38357 + if (sbinfo->si_xib_buf)
38358 + free_page((unsigned long)sbinfo->si_xib_buf);
38359 + sbinfo->si_xib_buf = NULL;
38363 + fput(sbinfo->si_xib);
38364 + sbinfo->si_xib = NULL;
38370 +/* xino for each branch */
38371 +static void xino_clear_br(struct super_block *sb)
38373 + aufs_bindex_t bindex, bbot;
38374 + struct au_branch *br;
38376 + bbot = au_sbbot(sb);
38377 + for (bindex = 0; bindex <= bbot; bindex++) {
38378 + br = au_sbr(sb, bindex);
38384 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38385 + aufs_bindex_t bshared)
38387 + struct au_branch *brshared;
38389 + brshared = au_sbr(sb, bshared);
38390 + AuDebugOn(!brshared->br_xino);
38391 + AuDebugOn(!brshared->br_xino->xi_file);
38392 + if (br->br_xino != brshared->br_xino) {
38393 + au_xino_get(brshared);
38395 + br->br_xino = brshared->br_xino;
38399 +struct au_xino_do_set_br {
38400 + vfs_writef_t writef;
38401 + struct au_branch *br;
38403 + aufs_bindex_t bshared;
38406 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38407 + struct au_xino_do_set_br *args)
38410 + struct au_xi_calc calc;
38411 + struct file *file;
38412 + struct au_branch *br;
38413 + struct au_xi_new xinew = {
38418 + xinew.xi = br->br_xino;
38419 + au_xi_calc(sb, args->h_ino, &calc);
38420 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38421 + if (args->bshared >= 0)
38422 + /* shared xino */
38423 + au_xino_set_br_shared(sb, br, args->bshared);
38424 + else if (!xinew.xi) {
38426 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38427 + if (unlikely(err))
38431 + /* force re-creating */
38432 + xinew.xi = br->br_xino;
38433 + xinew.idx = calc.idx;
38434 + mutex_lock(&xinew.xi->xi_mtx);
38435 + file = au_xi_new(sb, &xinew);
38436 + mutex_unlock(&xinew.xi->xi_mtx);
38437 + err = PTR_ERR(file);
38438 + if (IS_ERR(file))
38440 + AuDebugOn(!file);
38442 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38443 + if (unlikely(err))
38451 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38454 + aufs_bindex_t bindex, bbot;
38455 + struct au_xino_do_set_br args;
38456 + struct inode *inode;
38458 + SiMustWriteLock(sb);
38460 + bbot = au_sbbot(sb);
38461 + inode = d_inode(sb->s_root);
38462 + args.writef = au_sbi(sb)->si_xwrite;
38463 + for (bindex = 0; bindex <= bbot; bindex++) {
38464 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38465 + args.br = au_sbr(sb, bindex);
38466 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38467 + err = au_xino_do_set_br(sb, path, &args);
38468 + if (unlikely(err))
38476 +void au_xino_clr(struct super_block *sb)
38478 + struct au_sbinfo *sbinfo;
38480 + au_xigen_clr(sb);
38481 + xino_clear_xib(sb);
38482 + xino_clear_br(sb);
38483 + dbgaufs_brs_del(sb, 0);
38484 + sbinfo = au_sbi(sb);
38485 + /* lvalue, do not call au_mntflags() */
38486 + au_opt_clr(sbinfo->si_mntflags, XINO);
38489 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38492 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38493 + struct qstr *dname, *cur_name;
38494 + struct file *cur_xino;
38495 + struct au_sbinfo *sbinfo;
38496 + struct path *path, *cur_path;
38498 + SiMustWriteLock(sb);
38501 + sbinfo = au_sbi(sb);
38502 + path = &xiopt->file->f_path;
38503 + dentry = path->dentry;
38504 + parent = dget_parent(dentry);
38507 + cur_xino = sbinfo->si_xib;
38509 + cur_path = &cur_xino->f_path;
38510 + cur_dentry = cur_path->dentry;
38511 + cur_parent = dget_parent(cur_dentry);
38512 + cur_name = &cur_dentry->d_name;
38513 + dname = &dentry->d_name;
38514 + skip = (cur_parent == parent
38515 + && au_qstreq(dname, cur_name));
38516 + dput(cur_parent);
38522 + au_opt_set(sbinfo->si_mntflags, XINO);
38523 + err = au_xino_set_xib(sb, path);
38524 + /* si_x{read,write} are set */
38526 + err = au_xigen_set(sb, path);
38528 + err = au_xino_set_br(sb, path);
38530 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38531 + goto out; /* success */
38535 + AuIOErr("failed setting xino(%d).\n", err);
38544 + * create a xinofile at the default place/path.
38546 +struct file *au_xino_def(struct super_block *sb)
38548 + struct file *file;
38550 + struct au_branch *br;
38551 + struct super_block *h_sb;
38552 + struct path path;
38553 + aufs_bindex_t bbot, bindex, bwr;
38556 + bbot = au_sbbot(sb);
38558 + for (bindex = 0; bindex <= bbot; bindex++) {
38559 + br = au_sbr(sb, bindex);
38560 + if (au_br_writable(br->br_perm)
38561 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38568 + file = ERR_PTR(-ENOMEM);
38569 + page = (void *)__get_free_page(GFP_NOFS);
38570 + if (unlikely(!page))
38572 + path.mnt = au_br_mnt(br);
38573 + path.dentry = au_h_dptr(sb->s_root, bwr);
38574 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38575 + file = (void *)p;
38576 + if (!IS_ERR(p)) {
38577 + strcat(p, "/" AUFS_XINO_FNAME);
38578 + AuDbg("%s\n", p);
38579 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38581 + free_page((unsigned long)page);
38583 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38585 + if (IS_ERR(file))
38587 + h_sb = file->f_path.dentry->d_sb;
38588 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38589 + pr_err("xino doesn't support %s(%s)\n",
38590 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38592 + file = ERR_PTR(-EINVAL);
38600 +/* ---------------------------------------------------------------------- */
38603 + * initialize the xinofile for the specified branch @br
38604 + * at the place/path where @base_file indicates.
38605 + * test whether another branch is on the same filesystem or not,
38606 + * if found then share the xinofile with another branch.
38608 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38609 + struct path *base)
38612 + struct au_xino_do_set_br args = {
38617 + args.writef = au_sbi(sb)->si_xwrite;
38618 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38620 + err = au_xino_do_set_br(sb, base, &args);
38621 + if (unlikely(err))
38627 +/* ---------------------------------------------------------------------- */
38630 + * get an unused inode number from bitmap
38632 +ino_t au_xino_new_ino(struct super_block *sb)
38635 + unsigned long *p, pindex, ul, pend;
38636 + struct au_sbinfo *sbinfo;
38637 + struct file *file;
38638 + int free_bit, err;
38640 + if (!au_opt_test(au_mntflags(sb), XINO))
38641 + return iunique(sb, AUFS_FIRST_INO);
38643 + sbinfo = au_sbi(sb);
38644 + mutex_lock(&sbinfo->si_xib_mtx);
38645 + p = sbinfo->si_xib_buf;
38646 + free_bit = sbinfo->si_xib_next_bit;
38647 + if (free_bit < page_bits && !test_bit(free_bit, p))
38648 + goto out; /* success */
38649 + free_bit = find_first_zero_bit(p, page_bits);
38650 + if (free_bit < page_bits)
38651 + goto out; /* success */
38653 + pindex = sbinfo->si_xib_last_pindex;
38654 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38655 + err = xib_pindex(sb, ul);
38656 + if (unlikely(err))
38658 + free_bit = find_first_zero_bit(p, page_bits);
38659 + if (free_bit < page_bits)
38660 + goto out; /* success */
38663 + file = sbinfo->si_xib;
38664 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38665 + for (ul = pindex + 1; ul <= pend; ul++) {
38666 + err = xib_pindex(sb, ul);
38667 + if (unlikely(err))
38669 + free_bit = find_first_zero_bit(p, page_bits);
38670 + if (free_bit < page_bits)
38671 + goto out; /* success */
38676 + set_bit(free_bit, p);
38677 + sbinfo->si_xib_next_bit = free_bit + 1;
38678 + pindex = sbinfo->si_xib_last_pindex;
38679 + mutex_unlock(&sbinfo->si_xib_mtx);
38680 + ino = xib_calc_ino(pindex, free_bit);
38681 + AuDbg("i%lu\n", (unsigned long)ino);
38684 + mutex_unlock(&sbinfo->si_xib_mtx);
38689 +/* for s_op->delete_inode() */
38690 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38693 + unsigned int mnt_flags;
38694 + aufs_bindex_t bindex, bbot, bi;
38695 + unsigned char try_trunc;
38696 + struct au_iinfo *iinfo;
38697 + struct super_block *sb;
38698 + struct au_hinode *hi;
38699 + struct inode *h_inode;
38700 + struct au_branch *br;
38701 + vfs_writef_t xwrite;
38702 + struct au_xi_calc calc;
38703 + struct file *file;
38705 + AuDebugOn(au_is_bad_inode(inode));
38707 + sb = inode->i_sb;
38708 + mnt_flags = au_mntflags(sb);
38709 + if (!au_opt_test(mnt_flags, XINO)
38710 + || inode->i_ino == AUFS_ROOT_INO)
38714 + au_xigen_inc(inode);
38715 + au_xib_clear_bit(inode);
38718 + iinfo = au_ii(inode);
38719 + bindex = iinfo->ii_btop;
38723 + xwrite = au_sbi(sb)->si_xwrite;
38724 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38725 + hi = au_hinode(iinfo, bindex);
38726 + bbot = iinfo->ii_bbot;
38727 + for (; bindex <= bbot; bindex++, hi++) {
38728 + h_inode = hi->hi_inode;
38730 + || (!unlinked && h_inode->i_nlink))
38733 + /* inode may not be revalidated */
38734 + bi = au_br_index(sb, hi->hi_id);
38738 + br = au_sbr(sb, bi);
38739 + au_xi_calc(sb, h_inode->i_ino, &calc);
38740 + file = au_xino_file(br->br_xino, calc.idx);
38741 + if (IS_ERR_OR_NULL(file))
38744 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38745 + if (!err && try_trunc
38746 + && au_test_fs_trunc_xino(au_br_sb(br)))
38747 + xino_try_trunc(sb, br);
38751 +/* ---------------------------------------------------------------------- */
38753 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38755 + int found, total, i;
38758 + total = xi->xi_nondir.total;
38759 + for (i = 0; i < total; i++) {
38760 + if (xi->xi_nondir.array[i] != h_ino)
38769 +static int au_xinondir_expand(struct au_xino *xi)
38774 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38777 + sz = xi->xi_nondir.total * sizeof(ino_t);
38778 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38780 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38781 + /*may_shrink*/0);
38783 + xi->xi_nondir.array = p;
38784 + xi->xi_nondir.total <<= 1;
38785 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38793 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38794 + ino_t h_ino, int idx)
38796 + struct au_xino *xi;
38798 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38799 + xi = au_sbr(sb, bindex)->br_xino;
38800 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38802 + spin_lock(&xi->xi_nondir.spin);
38803 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38804 + xi->xi_nondir.array[idx] = 0;
38805 + spin_unlock(&xi->xi_nondir.spin);
38806 + wake_up_all(&xi->xi_nondir.wqh);
38809 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38812 + int err, found, empty;
38813 + struct au_xino *xi;
38817 + if (!au_opt_test(au_mntflags(sb), XINO))
38818 + goto out; /* no xino */
38820 + xi = au_sbr(sb, bindex)->br_xino;
38823 + spin_lock(&xi->xi_nondir.spin);
38824 + found = au_xinondir_find(xi, h_ino);
38825 + if (found == -1) {
38826 + empty = au_xinondir_find(xi, /*h_ino*/0);
38827 + if (empty == -1) {
38828 + empty = xi->xi_nondir.total;
38829 + err = au_xinondir_expand(xi);
38830 + if (unlikely(err))
38833 + xi->xi_nondir.array[empty] = h_ino;
38836 + spin_unlock(&xi->xi_nondir.spin);
38837 + wait_event(xi->xi_nondir.wqh,
38838 + xi->xi_nondir.array[found] != h_ino);
38843 + spin_unlock(&xi->xi_nondir.spin);
38848 +/* ---------------------------------------------------------------------- */
38850 +int au_xino_path(struct seq_file *seq, struct file *file)
38854 + err = au_seq_path(seq, &file->f_path);
38855 + if (unlikely(err))
38858 +#define Deleted "\\040(deleted)"
38859 + seq->count -= sizeof(Deleted) - 1;
38860 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38861 + sizeof(Deleted) - 1));
38867 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38868 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 08:00:00.000000000 +0800
38869 +++ linux/include/uapi/linux/aufs_type.h 2019-07-11 21:21:54.382384486 +0800
38871 +/* SPDX-License-Identifier: GPL-2.0 */
38873 + * Copyright (C) 2005-2019 Junjiro R. Okajima
38875 + * This program, aufs is free software; you can redistribute it and/or modify
38876 + * it under the terms of the GNU General Public License as published by
38877 + * the Free Software Foundation; either version 2 of the License, or
38878 + * (at your option) any later version.
38880 + * This program is distributed in the hope that it will be useful,
38881 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38882 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38883 + * GNU General Public License for more details.
38885 + * You should have received a copy of the GNU General Public License
38886 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38889 +#ifndef __AUFS_TYPE_H__
38890 +#define __AUFS_TYPE_H__
38892 +#define AUFS_NAME "aufs"
38896 + * define it before including all other headers.
38897 + * sched.h may use pr_* macros before defining "current", so define the
38898 + * no-current version first, and re-define later.
38900 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38901 +#include <linux/sched.h>
38903 +#define pr_fmt(fmt) \
38904 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38905 + (int)sizeof(current->comm), current->comm, current->pid
38907 +#include <stdint.h>
38908 +#include <sys/types.h>
38909 +#endif /* __KERNEL__ */
38911 +#include <linux/limits.h>
38913 +#define AUFS_VERSION "5.x-rcN-20190610"
38915 +/* todo? move this to linux-2.6.19/include/magic.h */
38916 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38918 +/* ---------------------------------------------------------------------- */
38920 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38921 +typedef int8_t aufs_bindex_t;
38922 +#define AUFS_BRANCH_MAX 127
38924 +typedef int16_t aufs_bindex_t;
38925 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38926 +#define AUFS_BRANCH_MAX 511
38927 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38928 +#define AUFS_BRANCH_MAX 1023
38929 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38930 +#define AUFS_BRANCH_MAX 32767
38935 +#ifndef AUFS_BRANCH_MAX
38936 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38938 +#endif /* __KERNEL__ */
38940 +/* ---------------------------------------------------------------------- */
38942 +#define AUFS_FSTYPE AUFS_NAME
38944 +#define AUFS_ROOT_INO 2
38945 +#define AUFS_FIRST_INO 11
38947 +#define AUFS_WH_PFX ".wh."
38948 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38949 +#define AUFS_WH_TMP_LEN 4
38950 +/* a limit for rmdir/rename a dir and copyup */
38951 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38952 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38954 + - AUFS_WH_TMP_LEN) /* hex */
38955 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38956 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38957 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38958 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38959 +#define AUFS_DIRWH_DEF 3
38960 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38961 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38962 +#define AUFS_RDBLK_DEF 512 /* bytes */
38963 +#define AUFS_RDHASH_DEF 32
38964 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38965 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38966 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38967 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38968 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38970 +/* pseudo-link maintenace under /proc */
38971 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38972 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38973 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38975 +/* dirren, renamed dir */
38976 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38977 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38978 +/* whiteouted doubly */
38979 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38980 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38982 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38983 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38985 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38986 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38987 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38989 +/* doubly whiteouted */
38990 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38991 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38992 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38994 +/* branch permissions and attributes */
38995 +#define AUFS_BRPERM_RW "rw"
38996 +#define AUFS_BRPERM_RO "ro"
38997 +#define AUFS_BRPERM_RR "rr"
38998 +#define AUFS_BRATTR_COO_REG "coo_reg"
38999 +#define AUFS_BRATTR_COO_ALL "coo_all"
39000 +#define AUFS_BRATTR_FHSM "fhsm"
39001 +#define AUFS_BRATTR_UNPIN "unpin"
39002 +#define AUFS_BRATTR_ICEX "icex"
39003 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39004 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39005 +#define AUFS_BRATTR_ICEX_TR "icextr"
39006 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39007 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39008 +#define AUFS_BRRATTR_WH "wh"
39009 +#define AUFS_BRWATTR_NLWH "nolwh"
39010 +#define AUFS_BRWATTR_MOO "moo"
39012 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39013 +#define AuBrPerm_RO (1 << 1) /* readonly */
39014 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39015 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39017 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39018 +#define AuBrAttr_COO_ALL (1 << 4)
39019 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39021 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39022 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39023 + branch. meaningless since
39024 + linux-3.18-rc1 */
39026 +/* ignore error in copying XATTR */
39027 +#define AuBrAttr_ICEX_SEC (1 << 7)
39028 +#define AuBrAttr_ICEX_SYS (1 << 8)
39029 +#define AuBrAttr_ICEX_TR (1 << 9)
39030 +#define AuBrAttr_ICEX_USR (1 << 10)
39031 +#define AuBrAttr_ICEX_OTH (1 << 11)
39032 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39033 + | AuBrAttr_ICEX_SYS \
39034 + | AuBrAttr_ICEX_TR \
39035 + | AuBrAttr_ICEX_USR \
39036 + | AuBrAttr_ICEX_OTH)
39038 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39039 +#define AuBrRAttr_Mask AuBrRAttr_WH
39041 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39042 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39043 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39045 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39047 +/* #warning test userspace */
39049 +#ifndef CONFIG_AUFS_FHSM
39050 +#undef AuBrAttr_FHSM
39051 +#define AuBrAttr_FHSM 0
39053 +#ifndef CONFIG_AUFS_XATTR
39054 +#undef AuBrAttr_ICEX
39055 +#define AuBrAttr_ICEX 0
39056 +#undef AuBrAttr_ICEX_SEC
39057 +#define AuBrAttr_ICEX_SEC 0
39058 +#undef AuBrAttr_ICEX_SYS
39059 +#define AuBrAttr_ICEX_SYS 0
39060 +#undef AuBrAttr_ICEX_TR
39061 +#define AuBrAttr_ICEX_TR 0
39062 +#undef AuBrAttr_ICEX_USR
39063 +#define AuBrAttr_ICEX_USR 0
39064 +#undef AuBrAttr_ICEX_OTH
39065 +#define AuBrAttr_ICEX_OTH 0
39069 +/* the longest combination */
39070 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39071 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39072 + "+" AUFS_BRATTR_COO_REG \
39073 + "+" AUFS_BRATTR_FHSM \
39074 + "+" AUFS_BRATTR_UNPIN \
39075 + "+" AUFS_BRATTR_ICEX_SEC \
39076 + "+" AUFS_BRATTR_ICEX_SYS \
39077 + "+" AUFS_BRATTR_ICEX_USR \
39078 + "+" AUFS_BRATTR_ICEX_OTH \
39079 + "+" AUFS_BRWATTR_NLWH)
39082 + char a[AuBrPermStrSz];
39083 +} au_br_perm_str_t;
39085 +static inline int au_br_writable(int brperm)
39087 + return brperm & AuBrPerm_RW;
39090 +static inline int au_br_whable(int brperm)
39092 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39095 +static inline int au_br_wh_linkable(int brperm)
39097 + return !(brperm & AuBrWAttr_NoLinkWH);
39100 +static inline int au_br_cmoo(int brperm)
39102 + return brperm & AuBrAttr_CMOO_Mask;
39105 +static inline int au_br_fhsm(int brperm)
39107 + return brperm & AuBrAttr_FHSM;
39110 +/* ---------------------------------------------------------------------- */
39114 + /* readdir in userspace */
39118 + AuCtl_WBR_FD, /* pathconf wrapper */
39119 + AuCtl_IBUSY, /* busy inode */
39120 + AuCtl_MVDOWN, /* move-down */
39121 + AuCtl_BR, /* info about branches */
39122 + AuCtl_FHSM_FD /* connection for fhsm */
39125 +/* borrowed from linux/include/linux/kernel.h */
39127 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39128 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39131 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39133 +#define __aligned(x) __attribute__((aligned(x)))
39138 +#define __packed __attribute__((packed))
39142 +struct au_rdu_cookie {
39147 + uint32_t generation;
39150 +struct au_rdu_ent {
39159 +static inline int au_rdu_len(int nlen)
39161 + /* include the terminating NULL */
39162 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39163 + sizeof(uint64_t));
39166 +union au_rdu_ent_ul {
39167 + struct au_rdu_ent __user *e;
39179 + uint64_t sz; /* AuCtl_RDU */
39180 + uint64_t nent; /* AuCtl_RDU_INO */
39182 + union au_rdu_ent_ul ent;
39183 + uint16_t verify[AufsCtlRduV_End];
39185 + /* input/output */
39189 + union au_rdu_ent_ul tail;
39190 + /* number of entries which were added in a single call */
39195 + struct au_rdu_cookie cookie;
39198 +/* ---------------------------------------------------------------------- */
39200 +/* dirren. the branch is identified by the filename who contains this */
39201 +struct au_drinfo {
39204 + uint8_t oldnamelen;
39205 + uint64_t _padding;
39207 + uint8_t oldname[0];
39210 +struct au_drinfo_fdata {
39212 + struct au_drinfo drinfo;
39215 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39217 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39219 +/* ---------------------------------------------------------------------- */
39221 +struct aufs_wbr_fd {
39226 +/* ---------------------------------------------------------------------- */
39228 +struct aufs_ibusy {
39229 + uint64_t ino, h_ino;
39233 +/* ---------------------------------------------------------------------- */
39235 +/* error code for move-down */
39236 +/* the actual message strings are implemented in aufs-util.git */
39238 + EAU_MVDOWN_OPAQUE = 1,
39239 + EAU_MVDOWN_WHITEOUT,
39240 + EAU_MVDOWN_UPPER,
39241 + EAU_MVDOWN_BOTTOM,
39242 + EAU_MVDOWN_NOUPPER,
39243 + EAU_MVDOWN_NOLOWERBR,
39247 +/* flags for move-down */
39248 +#define AUFS_MVDOWN_DMSG 1
39249 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39250 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39251 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39252 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39253 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39254 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39255 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39256 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39257 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39258 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39259 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39260 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39262 +/* index for move-down */
39264 + AUFS_MVDOWN_UPPER,
39265 + AUFS_MVDOWN_LOWER,
39266 + AUFS_MVDOWN_NARRAY
39270 + * additional info of move-down
39271 + * number of free blocks and inodes.
39272 + * subset of struct kstatfs, but smaller and always 64bit.
39274 +struct aufs_stfs {
39275 + uint64_t f_blocks;
39276 + uint64_t f_bavail;
39277 + uint64_t f_files;
39278 + uint64_t f_ffree;
39281 +struct aufs_stbr {
39282 + int16_t brid; /* optional input */
39283 + int16_t bindex; /* output */
39284 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39287 +struct aufs_mvdown {
39288 + uint32_t flags; /* input/output */
39289 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39290 + int8_t au_errno; /* output */
39293 +/* ---------------------------------------------------------------------- */
39295 +union aufs_brinfo {
39296 + /* PATH_MAX may differ between kernel-space and user-space */
39297 + char _spacer[4096];
39305 +/* ---------------------------------------------------------------------- */
39307 +#define AuCtlType 'A'
39308 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39309 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39310 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39311 + struct aufs_wbr_fd)
39312 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39313 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39314 + struct aufs_mvdown)
39315 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39316 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39318 +#endif /* __AUFS_TYPE_H__ */
39319 SPDX-License-Identifier: GPL-2.0
39320 aufs5.x-rcN loopback patch
39322 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39323 index 1b723737592b..16561a96019c 100644
39324 --- a/drivers/block/loop.c
39325 +++ b/drivers/block/loop.c
39326 @@ -633,6 +633,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39330 +static struct file *loop_real_file(struct file *file)
39332 + struct file *f = NULL;
39334 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39335 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39339 static void loop_reread_partitions(struct loop_device *lo,
39340 struct block_device *bdev)
39342 @@ -686,6 +695,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39345 struct file *file = NULL, *old_file;
39346 + struct file *f, *virt_file = NULL, *old_virt_file;
39350 @@ -705,12 +715,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39354 + f = loop_real_file(file);
39356 + virt_file = file;
39361 error = loop_validate_file(file, bdev);
39365 old_file = lo->lo_backing_file;
39366 + old_virt_file = lo->lo_backing_virt_file;
39370 @@ -722,6 +739,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39371 blk_mq_freeze_queue(lo->lo_queue);
39372 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39373 lo->lo_backing_file = file;
39374 + lo->lo_backing_virt_file = virt_file;
39375 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39376 mapping_set_gfp_mask(file->f_mapping,
39377 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39378 @@ -735,6 +753,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39382 + if (old_virt_file)
39383 + fput(old_virt_file);
39385 loop_reread_partitions(lo, bdev);
39387 @@ -743,6 +763,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39388 mutex_unlock(&loop_ctl_mutex);
39396 @@ -947,7 +969,7 @@ static void loop_update_rotational(struct loop_device *lo)
39397 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39398 struct block_device *bdev, unsigned int arg)
39400 - struct file *file;
39401 + struct file *file, *f, *virt_file = NULL;
39402 struct inode *inode;
39403 struct address_space *mapping;
39405 @@ -962,6 +984,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39409 + f = loop_real_file(file);
39411 + virt_file = file;
39417 * If we don't hold exclusive handle for the device, upgrade to it
39418 @@ -1009,6 +1037,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39419 lo->lo_device = bdev;
39420 lo->lo_flags = lo_flags;
39421 lo->lo_backing_file = file;
39422 + lo->lo_backing_virt_file = virt_file;
39423 lo->transfer = NULL;
39425 lo->lo_sizelimit = 0;
39426 @@ -1052,6 +1081,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39427 blkdev_put(bdev, mode | FMODE_EXCL);
39433 /* This is safe: open() is still holding a reference. */
39434 module_put(THIS_MODULE);
39435 @@ -1098,6 +1129,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39436 static int __loop_clr_fd(struct loop_device *lo, bool release)
39438 struct file *filp = NULL;
39439 + struct file *virt_filp = lo->lo_backing_virt_file;
39440 gfp_t gfp = lo->old_gfp_mask;
39441 struct block_device *bdev = lo->lo_device;
39443 @@ -1121,6 +1153,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39445 spin_lock_irq(&lo->lo_lock);
39446 lo->lo_backing_file = NULL;
39447 + lo->lo_backing_virt_file = NULL;
39448 spin_unlock_irq(&lo->lo_lock);
39450 loop_release_xfer(lo);
39451 @@ -1203,6 +1236,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39460 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39461 index af75a5ee4094..1e6ee5a4f623 100644
39462 --- a/drivers/block/loop.h
39463 +++ b/drivers/block/loop.h
39464 @@ -46,7 +46,7 @@ struct loop_device {
39465 int (*ioctl)(struct loop_device *, int cmd,
39466 unsigned long arg);
39468 - struct file * lo_backing_file;
39469 + struct file * lo_backing_file, *lo_backing_virt_file;
39470 struct block_device *lo_device;
39473 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39474 index 0309f0d502ff..19feb4f3cb5f 100644
39475 --- a/fs/aufs/f_op.c
39476 +++ b/fs/aufs/f_op.c
39477 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39478 if (IS_ERR(h_file))
39481 - if (au_test_loopback_kthread()) {
39482 + if (0 && au_test_loopback_kthread()) {
39483 au_warn_loopback(h_file->f_path.dentry->d_sb);
39484 if (file->f_mapping != h_file->f_mapping) {
39485 file->f_mapping = h_file->f_mapping;
39486 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39487 index 9ba35a878ecd..4ed0ff03d5ab 100644
39488 --- a/fs/aufs/loop.c
39489 +++ b/fs/aufs/loop.c
39490 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39491 symbol_put(loop_backing_file);
39492 au_kfree_try_rcu(au_warn_loopback_array);
39495 +/* ---------------------------------------------------------------------- */
39497 +/* support the loopback block device insude aufs */
39499 +struct file *aufs_real_loop(struct file *file)
39503 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39504 + fi_read_lock(file);
39505 + f = au_hf_top(file);
39506 + fi_read_unlock(file);
39510 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39511 index f31e40aff267..e13fb1a0717a 100644
39512 --- a/fs/aufs/loop.h
39513 +++ b/fs/aufs/loop.h
39514 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39516 int au_loopback_init(void);
39517 void au_loopback_fin(void);
39519 +struct file *aufs_real_loop(struct file *file);
39521 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39523 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39525 AuStubInt0(au_loopback_init, void)
39526 AuStubVoid(au_loopback_fin, void)
39528 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39529 #endif /* BLK_DEV_LOOP */
39531 #endif /* __KERNEL__ */
39532 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39533 index a97e2921cb09..f74eb6962684 100644
39534 --- a/fs/aufs/super.c
39535 +++ b/fs/aufs/super.c
39536 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39537 .statfs = aufs_statfs,
39538 .put_super = aufs_put_super,
39539 .sync_fs = aufs_sync_fs,
39540 - .remount_fs = aufs_remount_fs
39541 + .remount_fs = aufs_remount_fs,
39542 +#ifdef CONFIG_AUFS_BDEV_LOOP
39543 + .real_loop = aufs_real_loop
39547 /* ---------------------------------------------------------------------- */
39548 diff --git a/include/linux/fs.h b/include/linux/fs.h
39549 index 28593b894e7b..bdc2611787df 100644
39550 --- a/include/linux/fs.h
39551 +++ b/include/linux/fs.h
39552 @@ -1947,6 +1947,10 @@ struct super_operations {
39553 struct shrink_control *);
39554 long (*free_cached_objects)(struct super_block *,
39555 struct shrink_control *);
39556 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
39558 + struct file *(*real_loop)(struct file *);