1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index ac474a61be379..284cee954591e 100644
8 @@ -255,6 +255,7 @@ source "fs/pstore/Kconfig"
9 source "fs/sysv/Kconfig"
10 source "fs/ufs/Kconfig"
11 source "fs/exofs/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 293733f61594b..12d19d0de07a6 100644
20 @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules
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
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index b2f710eee67a7..8449c695ba0b1 100644
32 @@ -2605,6 +2605,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 ea9debf59b225..9e534a36c5941 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -739,6 +739,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 2e7e8d85e9b40..9f57bd87bce5a 100644
85 @@ -1238,7 +1238,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 4137d96534a6c..d4da10be555c9 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 42f6d25f32a52..fa6ae6a217fbd 100644
120 @@ -1657,7 +1657,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 99186556f8d34..72c93f3e86478 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 8a2737f0d61d3..45e3e7a0d4e64 100644
148 --- a/fs/read_write.c
149 +++ b/fs/read_write.c
150 @@ -489,6 +489,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
154 +vfs_readf_t vfs_readf(struct file *file)
156 + const struct file_operations *fop = file->f_op;
160 + if (fop->read_iter)
161 + return new_sync_read;
162 + return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
165 +vfs_writef_t vfs_writef(struct file *file)
167 + const struct file_operations *fop = file->f_op;
171 + if (fop->write_iter)
172 + return new_sync_write;
173 + return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
176 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
179 diff --git a/fs/splice.c b/fs/splice.c
180 index b3daa971f5977..1dd7f96b22dc4 100644
183 @@ -838,8 +838,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 @@ -855,9 +855,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 b54e0541ad899..28607828e96f2 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 897eae8faee1b..41da4219febfe 100644
222 --- a/include/linux/fs.h
223 +++ b/include/linux/fs.h
224 @@ -1286,6 +1286,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 @@ -1747,6 +1748,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 @@ -1818,6 +1820,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 @@ -2243,6 +2251,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 @@ -2530,6 +2539,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 b0d0b51c4d850..f73ffaa0199ee 100644
271 --- a/include/linux/lockdep.h
272 +++ b/include/linux/lockdep.h
273 @@ -313,6 +313,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 @@ -439,6 +441,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 35942084cd40d..24f5fd1a789de 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 74b4911ac16dd..19789fbea5675 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 dd13f865ad40e..fa6f5599a2a5e 100644
326 --- a/kernel/locking/lockdep.c
327 +++ b/kernel/locking/lockdep.c
328 @@ -140,7 +140,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES];
329 unsigned long nr_lock_classes;
330 static 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 @@ -151,6 +151,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
348 diff --git a/fs/proc/base.c b/fs/proc/base.c
349 index 7e9f07bf260d2..3ab59011067ee 100644
352 @@ -2016,7 +2016,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
354 vma = find_exact_vma(mm, vm_start, vm_end);
355 if (vma && vma->vm_file) {
356 - *path = vma->vm_file->f_path;
357 + *path = vma_pr_or_file(vma)->f_path;
361 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
362 index 3b63be64e4364..fb9913bf3d10d 100644
363 --- a/fs/proc/nommu.c
364 +++ b/fs/proc/nommu.c
365 @@ -45,7 +45,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 5ea1d64cb0b4c..7865a4707d233 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 @@ -1727,7 +1730,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 0b63d68dedb2a..400d1c594ceb3 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 0416a7204be37..4a298a92681bb 100644
420 --- a/include/linux/mm.h
421 +++ b/include/linux/mm.h
422 @@ -1440,6 +1440,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 5ed8f6292a533..01229754077f6 100644
453 --- a/include/linux/mm_types.h
454 +++ b/include/linux/mm_types.h
455 @@ -239,6 +239,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 @@ -313,6 +314,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 f0b58479534f0..fa562c364d020 100644
475 @@ -505,7 +505,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 26ef77a3883b5..b2869af1ef08e 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)
497 diff --git a/mm/filemap.c b/mm/filemap.c
498 index 52517f28e6f4a..250f675dcfb28 100644
501 @@ -2700,7 +2700,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 f7cd9cb966c0f..515e88a194bd0 100644
514 @@ -180,7 +180,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 @@ -905,7 +905,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 @@ -1821,8 +1821,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 @@ -2641,7 +2641,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 @@ -2660,7 +2660,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 @@ -2822,7 +2822,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 @@ -2897,10 +2897,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 @@ -3206,7 +3223,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 e4aac33216aec..83bfcd1528a00 100644
611 @@ -625,7 +625,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 @@ -763,7 +763,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 @@ -1286,7 +1286,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 @@ -1361,10 +1361,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 0000000000000..00d51187c3250
657 +// SPDX-License-Identifier: GPL-2.0
659 + * Mainly for aufs which mmap(2) different file and wants to print different
660 + * path in /proc/PID/maps.
661 + * Call these functions via macros defined in linux/mm.h.
663 + * See Documentation/filesystems/aufs/design/06mmap.txt
665 + * Copyright (c) 2014-2020 Junjro R. Okajima
666 + * Copyright (c) 2014 Ian Campbell
669 +#include <linux/mm.h>
670 +#include <linux/file.h>
671 +#include <linux/fs.h>
673 +/* #define PRFILE_TRACE */
674 +static inline void prfile_trace(struct file *f, struct file *pr,
675 + const char func[], int line, const char func2[])
679 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
683 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
686 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
688 + prfile_trace(f, pr, func, line, __func__);
689 + file_update_time(f);
691 + file_update_time(pr);
694 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
697 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
699 + prfile_trace(f, pr, func, line, __func__);
700 + return (f && pr) ? pr : f;
703 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
705 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
707 + prfile_trace(f, pr, func, line, __func__);
713 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
715 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
717 + prfile_trace(f, pr, func, line, __func__);
724 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
727 + struct file *f = region->vm_file, *pr = region->vm_prfile;
729 + prfile_trace(f, pr, func, line, __func__);
730 + return (f && pr) ? pr : f;
733 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
735 + struct file *f = region->vm_file, *pr = region->vm_prfile;
737 + prfile_trace(f, pr, func, line, __func__);
742 +#endif /* !CONFIG_MMU */
743 SPDX-License-Identifier: GPL-2.0
744 aufs4.19 standalone patch
746 diff --git a/fs/dcache.c b/fs/dcache.c
747 index 9f57bd87bce5a..328a13662ca2e 100644
750 @@ -1343,6 +1343,7 @@ void d_walk(struct dentry *parent, void *data,
754 +EXPORT_SYMBOL_GPL(d_walk);
757 struct vfsmount *mnt;
758 @@ -2837,6 +2838,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 1ebf6e5a521d9..a72c294657eae 100644
770 @@ -109,6 +109,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 d4da10be555c9..fbc70ac63462f 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 e49af4caf15d9..569020fd1fb38 100644
792 --- a/fs/file_table.c
793 +++ b/fs/file_table.c
794 @@ -161,6 +161,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 @@ -323,6 +324,7 @@ void flush_delayed_fput(void)
806 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
808 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
810 @@ -365,6 +367,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 fa6ae6a217fbd..69d4a6cded14b 100644
822 @@ -1666,6 +1666,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 72c93f3e86478..c49803ce04b8b 100644
834 @@ -437,6 +437,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 @@ -1832,6 +1834,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
854 +EXPORT_SYMBOL_GPL(iterate_mounts);
856 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
858 diff --git a/fs/notify/group.c b/fs/notify/group.c
859 index c03b836628769..94d210ca384a6 100644
860 --- a/fs/notify/group.c
861 +++ b/fs/notify/group.c
862 @@ -112,6 +112,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 @@ -121,6 +122,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 @@ -150,6 +152,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 59cdb27826def..ce365c73f4fea 100644
888 --- a/fs/notify/mark.c
889 +++ b/fs/notify/mark.c
890 @@ -263,6 +263,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 @@ -417,6 +418,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 @@ -632,6 +634,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 @@ -754,6 +757,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
915 fsnotify_get_group(group);
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 0285ce7dbd515..cb81623a8b09e 100644
926 @@ -64,6 +64,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 45e3e7a0d4e64..f802a3865acf4 100644
936 --- a/fs/read_write.c
937 +++ b/fs/read_write.c
938 @@ -459,6 +459,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 @@ -499,6 +500,7 @@ vfs_readf_t vfs_readf(struct file *file)
947 return new_sync_read;
948 return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */
950 +EXPORT_SYMBOL_GPL(vfs_readf);
952 vfs_writef_t vfs_writef(struct file *file)
954 @@ -510,6 +512,7 @@ vfs_writef_t vfs_writef(struct file *file)
955 return new_sync_write;
956 return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */
958 +EXPORT_SYMBOL_GPL(vfs_writef);
960 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
962 @@ -579,6 +582,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
966 +EXPORT_SYMBOL_GPL(vfs_write);
968 static inline loff_t file_pos_read(struct file *file)
970 diff --git a/fs/splice.c b/fs/splice.c
971 index 1dd7f96b22dc4..a5e3bcba0ea26 100644
974 @@ -851,6 +851,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 @@ -880,6 +881,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 28607828e96f2..ffd7ea43831ea 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 0d6a6a4af8616..7ce4701b7289d 100644
1006 @@ -295,6 +295,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 fa6f5599a2a5e..7ac19efdac047 100644
1016 --- a/kernel/locking/lockdep.c
1017 +++ b/kernel/locking/lockdep.c
1018 @@ -151,6 +151,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 0fef395662a6e..83fb1ecfc33de 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 cd97929fac663..20c59b2e3b261 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 736e78da1ab9d..c67016362c13e 100644
1046 --- a/security/security.c
1047 +++ b/security/security.c
1048 @@ -542,6 +542,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 @@ -558,6 +559,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 @@ -566,6 +568,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 @@ -593,6 +596,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 @@ -600,6 +604,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 @@ -607,6 +612,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 @@ -707,6 +713,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 @@ -878,6 +885,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 @@ -937,6 +945,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1114 return ima_file_mmap(file, prot);
1116 +EXPORT_SYMBOL_GPL(security_mmap_file);
1118 int security_mmap_addr(unsigned long addr)
1120 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1121 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1122 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-02-22 23:30:37.699347580 +0100
1124 +What: /debug/aufs/si_<id>/
1126 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1128 + Under /debug/aufs, a directory named si_<id> is created
1129 + per aufs mount, where <id> is a unique id generated
1132 +What: /debug/aufs/si_<id>/plink
1134 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1136 + It has three lines and shows the information about the
1137 + pseudo-link. The first line is a single number
1138 + representing a number of buckets. The second line is a
1139 + number of pseudo-links per buckets (separated by a
1140 + blank). The last line is a single number representing a
1141 + total number of psedo-links.
1142 + When the aufs mount option 'noplink' is specified, it
1143 + will show "1\n0\n0\n".
1145 +What: /debug/aufs/si_<id>/xib
1147 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1149 + It shows the consumed blocks by xib (External Inode Number
1150 + Bitmap), its block size and file size.
1151 + When the aufs mount option 'noxino' is specified, it
1152 + will be empty. About XINO files, see the aufs manual.
1154 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1156 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1158 + It shows the consumed blocks by xino (External Inode Number
1159 + Translation Table), its link count, block size and file
1161 + Due to the file size limit, there may exist multiple
1162 + xino files per branch. In this case, "-N" is added to
1163 + the filename and it corresponds to the index of the
1164 + internal xino array. "-0" is omitted.
1165 + When the aufs mount option 'noxino' is specified, Those
1166 + entries won't exist. About XINO files, see the aufs
1169 +What: /debug/aufs/si_<id>/xigen
1171 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1173 + It shows the consumed blocks by xigen (External Inode
1174 + Generation Table), its block size and file size.
1175 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1177 + When the aufs mount option 'noxino' is specified, it
1178 + will be empty. About XINO files, see the aufs manual.
1179 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1180 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1181 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-02-22 23:30:37.699347580 +0100
1183 +What: /sys/fs/aufs/si_<id>/
1185 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1187 + Under /sys/fs/aufs, a directory named si_<id> is created
1188 + per aufs mount, where <id> is a unique id generated
1191 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1193 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1195 + It shows the abolute path of a member directory (which
1196 + is called branch) in aufs, and its permission.
1198 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1200 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1202 + It shows the id of a member directory (which is called
1205 +What: /sys/fs/aufs/si_<id>/xi_path
1207 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1209 + It shows the abolute path of XINO (External Inode Number
1210 + Bitmap, Translation Table and Generation Table) file
1211 + even if it is the default path.
1212 + When the aufs mount option 'noxino' is specified, it
1213 + will be empty. About XINO files, see the aufs manual.
1214 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1215 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1216 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-02-22 23:30:37.699347580 +0100
1219 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1221 +# This program is free software; you can redistribute it and/or modify
1222 +# it under the terms of the GNU General Public License as published by
1223 +# the Free Software Foundation; either version 2 of the License, or
1224 +# (at your option) any later version.
1226 +# This program is distributed in the hope that it will be useful,
1227 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1228 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1229 +# GNU General Public License for more details.
1231 +# You should have received a copy of the GNU General Public License
1232 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1235 +----------------------------------------
1237 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1238 +1. abbrev. for "advanced multi-layered unification filesystem".
1239 +2. abbrev. for "another unionfs".
1240 +3. abbrev. for "auf das" in German which means "on the" in English.
1241 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1242 + But "Filesystem aufs Filesystem" is hard to understand.
1243 +4. abbrev. for "African Urban Fashion Show".
1245 +AUFS is a filesystem with features:
1246 +- multi layered stackable unification filesystem, the member directory
1247 + is called as a branch.
1248 +- branch permission and attribute, 'readonly', 'real-readonly',
1249 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1251 +- internal "file copy-on-write".
1252 +- logical deletion, whiteout.
1253 +- dynamic branch manipulation, adding, deleting and changing permission.
1254 +- allow bypassing aufs, user's direct branch access.
1255 +- external inode number translation table and bitmap which maintains the
1256 + persistent aufs inode number.
1257 +- seekable directory, including NFS readdir.
1258 +- file mapping, mmap and sharing pages.
1259 +- pseudo-link, hardlink over branches.
1260 +- loopback mounted filesystem as a branch.
1261 +- several policies to select one among multiple writable branches.
1262 +- revert a single systemcall when an error occurs in aufs.
1266 +Multi Layered Stackable Unification Filesystem
1267 +----------------------------------------------------------------------
1268 +Most people already knows what it is.
1269 +It is a filesystem which unifies several directories and provides a
1270 +merged single directory. When users access a file, the access will be
1271 +passed/re-directed/converted (sorry, I am not sure which English word is
1272 +correct) to the real file on the member filesystem. The member
1273 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1274 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1275 +readonly branch is handled by creating 'whiteout' on the upper writable
1278 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1279 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1280 +different approaches to implement the merged-view.
1281 +The former tries putting it into VFS, and the latter implements as a
1282 +separate filesystem.
1283 +(If I misunderstand about these implementations, please let me know and
1284 +I shall correct it. Because it is a long time ago when I read their
1285 +source files last time).
1287 +UnionMount's approach will be able to small, but may be hard to share
1288 +branches between several UnionMount since the whiteout in it is
1289 +implemented in the inode on branch filesystem and always
1290 +shared. According to Bharata's post, readdir does not seems to be
1292 +There are several missing features known in this implementations such as
1293 +- for users, the inode number may change silently. eg. copy-up.
1294 +- link(2) may break by copy-up.
1295 +- read(2) may get an obsoleted filedata (fstat(2) too).
1296 +- fcntl(F_SETLK) may be broken by copy-up.
1297 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1300 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1301 +merged into mainline. This is another implementation of UnionMount as a
1302 +separated filesystem. All the limitations and known problems which
1303 +UnionMount are equally inherited to "overlay" filesystem.
1305 +Unionfs has a longer history. When I started implementing a stackable
1306 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1307 +inode, dentry and file objects and they have an array pointing lower
1308 +same kind objects. After contributing many patches for Unionfs, I
1309 +re-started my project AUFS (Jun 2006).
1311 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1312 +implemented my own ideas, approaches and enhancements and it became
1313 +totally different one.
1315 +Comparing DM snapshot and fs based implementation
1316 +- the number of bytes to be copied between devices is much smaller.
1317 +- the type of filesystem must be one and only.
1318 +- the fs must be writable, no readonly fs, even for the lower original
1319 + device. so the compression fs will not be usable. but if we use
1320 + loopback mount, we may address this issue.
1322 + mount /cdrom/squashfs.img /sq
1323 + losetup /sq/ext2.img
1324 + losetup /somewhere/cow
1325 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1326 +- it will be difficult (or needs more operations) to extract the
1327 + difference between the original device and COW.
1328 +- DM snapshot-merge may help a lot when users try merging. in the
1329 + fs-layer union, users will use rsync(1).
1331 +You may want to read my old paper "Filesystems in LiveCD"
1332 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1335 +Several characters/aspects/persona of aufs
1336 +----------------------------------------------------------------------
1338 +Aufs has several characters, aspects or persona.
1339 +1. a filesystem, callee of VFS helper
1340 +2. sub-VFS, caller of VFS helper for branches
1341 +3. a virtual filesystem which maintains persistent inode number
1342 +4. reader/writer of files on branches such like an application
1344 +1. Callee of VFS Helper
1345 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1346 +unlink(2) from an application reaches sys_unlink() kernel function and
1347 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1348 +calls filesystem specific unlink operation. Actually aufs implements the
1349 +unlink operation but it behaves like a redirector.
1351 +2. Caller of VFS Helper for Branches
1352 +aufs_unlink() passes the unlink request to the branch filesystem as if
1353 +it were called from VFS. So the called unlink operation of the branch
1354 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1355 +every necessary pre/post operation for the branch filesystem.
1356 +- acquire the lock for the parent dir on a branch
1357 +- lookup in a branch
1358 +- revalidate dentry on a branch
1359 +- mnt_want_write() for a branch
1360 +- vfs_unlink() for a branch
1361 +- mnt_drop_write() for a branch
1362 +- release the lock on a branch
1364 +3. Persistent Inode Number
1365 +One of the most important issue for a filesystem is to maintain inode
1366 +numbers. This is particularly important to support exporting a
1367 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1368 +backend block device for its own. But some storage is necessary to
1369 +keep and maintain the inode numbers. It may be a large space and may not
1370 +suit to keep in memory. Aufs rents some space from its first writable
1371 +branch filesystem (by default) and creates file(s) on it. These files
1372 +are created by aufs internally and removed soon (currently) keeping
1374 +Note: Because these files are removed, they are totally gone after
1375 + unmounting aufs. It means the inode numbers are not persistent
1376 + across unmount or reboot. I have a plan to make them really
1377 + persistent which will be important for aufs on NFS server.
1379 +4. Read/Write Files Internally (copy-on-write)
1380 +Because a branch can be readonly, when you write a file on it, aufs will
1381 +"copy-up" it to the upper writable branch internally. And then write the
1382 +originally requested thing to the file. Generally kernel doesn't
1383 +open/read/write file actively. In aufs, even a single write may cause a
1384 +internal "file copy". This behaviour is very similar to cp(1) command.
1386 +Some people may think it is better to pass such work to user space
1387 +helper, instead of doing in kernel space. Actually I am still thinking
1388 +about it. But currently I have implemented it in kernel space.
1389 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1390 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1391 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-02-22 23:30:37.699347580 +0100
1394 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1396 +# This program is free software; you can redistribute it and/or modify
1397 +# it under the terms of the GNU General Public License as published by
1398 +# the Free Software Foundation; either version 2 of the License, or
1399 +# (at your option) any later version.
1401 +# This program is distributed in the hope that it will be useful,
1402 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1403 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1404 +# GNU General Public License for more details.
1406 +# You should have received a copy of the GNU General Public License
1407 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1409 +Basic Aufs Internal Structure
1411 +Superblock/Inode/Dentry/File Objects
1412 +----------------------------------------------------------------------
1413 +As like an ordinary filesystem, aufs has its own
1414 +superblock/inode/dentry/file objects. All these objects have a
1415 +dynamically allocated array and store the same kind of pointers to the
1416 +lower filesystem, branch.
1417 +For example, when you build a union with one readwrite branch and one
1418 +readonly, mounted /au, /rw and /ro respectively.
1420 +- /ro/fileA exists but /rw/fileA
1422 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1423 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1424 +- [0] = NULL (because /rw/fileA doesn't exist)
1427 +This style of an array is essentially same to the aufs
1428 +superblock/inode/dentry/file objects.
1430 +Because aufs supports manipulating branches, ie. add/delete/change
1431 +branches dynamically, these objects has its own generation. When
1432 +branches are changed, the generation in aufs superblock is
1433 +incremented. And a generation in other object are compared when it is
1434 +accessed. When a generation in other objects are obsoleted, aufs
1435 +refreshes the internal array.
1439 +----------------------------------------------------------------------
1440 +Additionally aufs superblock has some data for policies to select one
1441 +among multiple writable branches, XIB files, pseudo-links and kobject.
1442 +See below in detail.
1443 +About the policies which supports copy-down a directory, see
1444 +wbr_policy.txt too.
1447 +Branch and XINO(External Inode Number Translation Table)
1448 +----------------------------------------------------------------------
1449 +Every branch has its own xino (external inode number translation table)
1450 +file. The xino file is created and unlinked by aufs internally. When two
1451 +members of a union exist on the same filesystem, they share the single
1453 +The struct of a xino file is simple, just a sequence of aufs inode
1454 +numbers which is indexed by the lower inode number.
1455 +In the above sample, assume the inode number of /ro/fileA is i111 and
1456 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1457 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1459 +When the inode numbers are not contiguous, the xino file will be sparse
1460 +which has a hole in it and doesn't consume as much disk space as it
1461 +might appear. If your branch filesystem consumes disk space for such
1462 +holes, then you should specify 'xino=' option at mounting aufs.
1464 +Aufs has a mount option to free the disk blocks for such holes in XINO
1465 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1466 +meet a problem of disk shortage due to XINO files, then you should try
1467 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1468 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1469 +the holes in XINO files.
1471 +Also a writable branch has three kinds of "whiteout bases". All these
1472 +are existed when the branch is joined to aufs, and their names are
1473 +whiteout-ed doubly, so that users will never see their names in aufs
1475 +1. a regular file which will be hardlinked to all whiteouts.
1476 +2. a directory to store a pseudo-link.
1477 +3. a directory to store an "orphan"-ed file temporary.
1480 + When you remove a file on a readonly branch, aufs handles it as a
1481 + logical deletion and creates a whiteout on the upper writable branch
1482 + as a hardlink of this file in order not to consume inode on the
1485 + See below, Pseudo-link.
1487 + When "fileC" exists on the lower readonly branch only and it is
1488 + opened and removed with its parent dir, and then user writes
1489 + something into it, then aufs copies-up fileC to this
1490 + directory. Because there is no other dir to store fileC. After
1491 + creating a file under this dir, the file is unlinked.
1493 +Because aufs supports manipulating branches, ie. add/delete/change
1494 +dynamically, a branch has its own id. When the branch order changes,
1495 +aufs finds the new index by searching the branch id.
1499 +----------------------------------------------------------------------
1500 +Assume "fileA" exists on the lower readonly branch only and it is
1501 +hardlinked to "fileB" on the branch. When you write something to fileA,
1502 +aufs copies-up it to the upper writable branch. Additionally aufs
1503 +creates a hardlink under the Pseudo-link Directory of the writable
1504 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1505 +simple list. If fileB is read after unlinking fileA, aufs returns
1506 +filedata from the pseudo-link instead of the lower readonly
1507 +branch. Because the pseudo-link is based upon the inode, to keep the
1508 +inode number by xino (see above) is essentially necessary.
1510 +All the hardlinks under the Pseudo-link Directory of the writable branch
1511 +should be restored in a proper location later. Aufs provides a utility
1512 +to do this. The userspace helpers executed at remounting and unmounting
1514 +During this utility is running, it puts aufs into the pseudo-link
1515 +maintenance mode. In this mode, only the process which began the
1516 +maintenance mode (and its child processes) is allowed to operate in
1517 +aufs. Some other processes which are not related to the pseudo-link will
1518 +be allowed to run too, but the rest have to return an error or wait
1519 +until the maintenance mode ends. If a process already acquires an inode
1520 +mutex (in VFS), it has to return an error.
1523 +XIB(external inode number bitmap)
1524 +----------------------------------------------------------------------
1525 +Addition to the xino file per a branch, aufs has an external inode number
1526 +bitmap in a superblock object. It is also an internal file such like a
1528 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1530 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1532 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1533 +reduce the number of consumed disk blocks for these files.
1536 +Virtual or Vertical Dir, and Readdir in Userspace
1537 +----------------------------------------------------------------------
1538 +In order to support multiple layers (branches), aufs readdir operation
1539 +constructs a virtual dir block on memory. For readdir, aufs calls
1540 +vfs_readdir() internally for each dir on branches, merges their entries
1541 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1542 +object. So the file object has its entry list until it is closed. The
1543 +entry list will be updated when the file position is zero and becomes
1544 +obsoleted. This decision is made in aufs automatically.
1546 +The dynamically allocated memory block for the name of entries has a
1547 +unit of 512 bytes (by default) and stores the names contiguously (no
1548 +padding). Another block for each entry is handled by kmem_cache too.
1549 +During building dir blocks, aufs creates hash list and judging whether
1550 +the entry is whiteouted by its upper branch or already listed.
1551 +The merged result is cached in the corresponding inode object and
1552 +maintained by a customizable life-time option.
1554 +Some people may call it can be a security hole or invite DoS attack
1555 +since the opened and once readdir-ed dir (file object) holds its entry
1556 +list and becomes a pressure for system memory. But I'd say it is similar
1557 +to files under /proc or /sys. The virtual files in them also holds a
1558 +memory page (generally) while they are opened. When an idea to reduce
1559 +memory for them is introduced, it will be applied to aufs too.
1560 +For those who really hate this situation, I've developed readdir(3)
1561 +library which operates this merging in userspace. You just need to set
1562 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1563 +kernel space for readdir(3).
1567 +----------------------------------------------------------------------
1568 +Aufs sometimes requires privilege access to a branch. For instance,
1569 +in copy-up/down operation. When a user process is going to make changes
1570 +to a file which exists in the lower readonly branch only, and the mode
1571 +of one of ancestor directories may not be writable by a user
1572 +process. Here aufs copy-up the file with its ancestors and they may
1573 +require privilege to set its owner/group/mode/etc.
1574 +This is a typical case of a application character of aufs (see
1577 +Aufs uses workqueue synchronously for this case. It creates its own
1578 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1579 +passes the request to call mkdir or write (for example), and wait for
1580 +its completion. This approach solves a problem of a signal handler
1582 +If aufs didn't adopt the workqueue and changed the privilege of the
1583 +process, then the process may receive the unexpected SIGXFSZ or other
1586 +Also aufs uses the system global workqueue ("events" kernel thread) too
1587 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1588 +whiteout base and etc. This is unrelated to a privilege.
1589 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1590 +superblock at the beginning, at the same time waits for the completion
1591 +of all queued asynchronous tasks.
1595 +----------------------------------------------------------------------
1596 +The whiteout in aufs is very similar to Unionfs's. That is represented
1597 +by its filename. UnionMount takes an approach of a file mode, but I am
1598 +afraid several utilities (find(1) or something) will have to support it.
1600 +Basically the whiteout represents "logical deletion" which stops aufs to
1601 +lookup further, but also it represents "dir is opaque" which also stop
1604 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1605 +In order to make several functions in a single systemcall to be
1606 +revertible, aufs adopts an approach to rename a directory to a temporary
1607 +unique whiteouted name.
1608 +For example, in rename(2) dir where the target dir already existed, aufs
1609 +renames the target dir to a temporary unique whiteouted name before the
1610 +actual rename on a branch, and then handles other actions (make it opaque,
1611 +update the attributes, etc). If an error happens in these actions, aufs
1612 +simply renames the whiteouted name back and returns an error. If all are
1613 +succeeded, aufs registers a function to remove the whiteouted unique
1614 +temporary name completely and asynchronously to the system global
1619 +----------------------------------------------------------------------
1620 +It is a well-known feature or concept.
1621 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1622 +internally and makes change to the new file on the upper writable branch.
1623 +When the trigger systemcall does not update the timestamps of the parent
1624 +dir, aufs reverts it after copy-up.
1627 +Move-down (aufs3.9 and later)
1628 +----------------------------------------------------------------------
1629 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1630 +the lower readonly branch to the upper writable branch when a user
1631 +changes something about the file.
1632 +"Move-down" is an opposite action of copy-up. Basically this action is
1633 +ran manually instead of automatically and internally.
1634 +For desgin and implementation, aufs has to consider these issues.
1635 +- whiteout for the file may exist on the lower branch.
1636 +- ancestor directories may not exist on the lower branch.
1637 +- diropq for the ancestor directories may exist on the upper branch.
1638 +- free space on the lower branch will reduce.
1639 +- another access to the file may happen during moving-down, including
1640 + UDBA (see "Revalidate Dentry and UDBA").
1641 +- the file should not be hard-linked nor pseudo-linked. they should be
1642 + handled by auplink utility later.
1644 +Sometimes users want to move-down a file from the upper writable branch
1645 +to the lower readonly or writable branch. For instance,
1646 +- the free space of the upper writable branch is going to run out.
1647 +- create a new intermediate branch between the upper and lower branch.
1650 +For this purpose, use "aumvdown" command in aufs-util.git.
1651 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1652 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1653 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-02-22 23:30:37.699347580 +0100
1656 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1658 +# This program is free software; you can redistribute it and/or modify
1659 +# it under the terms of the GNU General Public License as published by
1660 +# the Free Software Foundation; either version 2 of the License, or
1661 +# (at your option) any later version.
1663 +# This program is distributed in the hope that it will be useful,
1664 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1665 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1666 +# GNU General Public License for more details.
1668 +# You should have received a copy of the GNU General Public License
1669 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1671 +Support for a branch who has its ->atomic_open()
1672 +----------------------------------------------------------------------
1673 +The filesystems who implement its ->atomic_open() are not majority. For
1674 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1675 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1676 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1677 +sure whether all filesystems who have ->atomic_open() behave like this,
1678 +but NFSv4 surely returns the error.
1680 +In order to support ->atomic_open() for aufs, there are a few
1683 +A. Introduce aufs_atomic_open()
1684 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1686 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1687 + an aufs user Pip Cet's approach
1688 + - calls aufs_create(), VFS finish_open() and notify_change().
1689 + - pass fake-mode to finish_open(), and then correct the mode by
1691 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1692 + - no aufs_atomic_open().
1693 + - aufs_lookup() registers the TID to an aufs internal object.
1694 + - aufs_create() does nothing when the matching TID is registered, but
1695 + registers the mode.
1696 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1697 + TID is registered.
1698 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1700 + - no aufs_atomic_open().
1701 + - aufs_create() registers the TID to an internal object. this info
1702 + represents "this process created this file just now."
1703 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1704 + registered TID and re-try open() with superuser's credential.
1706 +Pros and cons for each approach.
1709 + - straightforward but highly depends upon VFS internal.
1710 + - the atomic behavaiour is kept.
1711 + - some of parameters such as nameidata are hard to reproduce for
1715 + - easy to implement.
1716 + - the atomic behavaiour is lost.
1718 + - the atomic behavaiour is kept.
1719 + - dirty and tricky.
1720 + - VFS checks whether the file is created correctly after calling
1721 + ->create(), which means this approach doesn't work.
1723 + - easy to implement.
1724 + - the atomic behavaiour is lost.
1725 + - to open a file with superuser's credential and give it to a user
1726 + process is a bad idea, since the file object keeps the credential
1727 + in it. It may affect LSM or something. This approach doesn't work
1730 +The approach A is ideal, but it hard to implement. So here is a
1731 +variation of A, which is to be implemented.
1733 +A-1. Introduce aufs_atomic_open()
1734 + - calls branch fs ->atomic_open() if exists. otherwise calls
1735 + vfs_create() and finish_open().
1736 + - the demerit is that the several checks after branch fs
1737 + ->atomic_open() are lost. in the ordinary case, the checks are
1738 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1739 + be implemented in aufs, but not all I am afraid.
1740 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1741 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1742 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-02-22 23:30:37.699347580 +0100
1745 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1747 +# This program is free software; you can redistribute it and/or modify
1748 +# it under the terms of the GNU General Public License as published by
1749 +# the Free Software Foundation; either version 2 of the License, or
1750 +# (at your option) any later version.
1752 +# This program is distributed in the hope that it will be useful,
1753 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1754 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1755 +# GNU General Public License for more details.
1757 +# You should have received a copy of the GNU General Public License
1758 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1761 +----------------------------------------------------------------------
1762 +Since aufs has a character of sub-VFS (see Introduction), it operates
1763 +lookup for branches as VFS does. It may be a heavy work. But almost all
1764 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1765 +directly connected to its parent. Digging down the directory hierarchy
1766 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1769 +When a branch is a remote filesystem, aufs basically relies upon its
1770 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1772 +For d_revalidate, aufs implements three levels of revalidate tests. See
1773 +"Revalidate Dentry and UDBA" in detail.
1776 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1777 +----------------------------------------------------------------------
1778 +Let's try case study.
1779 +- aufs has two branches, upper readwrite and lower readonly.
1781 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1782 +- user invoked "chmod a+rx /au/dirA"
1783 +- the internal copy-up is activated and "/rw/dirA" is created and its
1784 + permission bits are set to world readable.
1785 +- then "/au/dirA" becomes world readable?
1787 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1788 +or it may be a natively readonly filesystem. If aufs respects the lower
1789 +branch, it should not respond readdir request from other users. But user
1790 +allowed it by chmod. Should really aufs rejects showing the entries
1793 +To be honest, I don't have a good solution for this case. So aufs
1794 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1796 +When dirperm1 is specified, aufs checks only the highest one for the
1797 +directory permission, and shows the entries. Otherwise, as usual, checks
1798 +every dir existing on all branches and rejects the request.
1800 +As a side effect, dirperm1 option improves the performance of aufs
1801 +because the number of permission check is reduced when the number of
1805 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1806 +----------------------------------------------------------------------
1807 +Generally VFS helpers re-validate a dentry as a part of lookup.
1808 +0. digging down the directory hierarchy.
1809 +1. lock the parent dir by its i_mutex.
1810 +2. lookup the final (child) entry.
1812 +4. call the actual operation (create, unlink, etc.)
1813 +5. unlock the parent dir
1815 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1816 +called. Actually aufs implements it and checks the dentry on a branch is
1818 +But it is not enough. Because aufs has to release the lock for the
1819 +parent dir on a branch at the end of ->lookup() (step 2) and
1820 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1822 +If the file on a branch is changed directly, eg. bypassing aufs, after
1823 +aufs released the lock, then the subsequent operation may cause
1824 +something unpleasant result.
1826 +This situation is a result of VFS architecture, ->lookup() and
1827 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1828 +design from VFS's point of view. It is just not suitable for sub-VFS
1831 +Aufs supports such case by three level of revalidation which is
1832 +selectable by user.
1833 +1. Simple Revalidate
1834 + Addition to the native flow in VFS's, confirm the child-parent
1835 + relationship on the branch just after locking the parent dir on the
1836 + branch in the "actual operation" (step 4). When this validation
1837 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1838 + checks the validation of the dentry on branches.
1839 +2. Monitor Changes Internally by Inotify/Fsnotify
1840 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1841 + the dentry on the branch, and returns EBUSY if it finds different
1843 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1844 + during it is in cache. When the event is notified, aufs registers a
1845 + function to kernel 'events' thread by schedule_work(). And the
1846 + function sets some special status to the cached aufs dentry and inode
1847 + private data. If they are not cached, then aufs has nothing to
1848 + do. When the same file is accessed through aufs (step 0-3) later,
1849 + aufs will detect the status and refresh all necessary data.
1850 + In this mode, aufs has to ignore the event which is fired by aufs
1852 +3. No Extra Validation
1853 + This is the simplest test and doesn't add any additional revalidation
1854 + test, and skip the revalidation in step 4. It is useful and improves
1855 + aufs performance when system surely hide the aufs branches from user,
1856 + by over-mounting something (or another method).
1857 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1858 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1859 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-02-22 23:30:37.699347580 +0100
1862 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1864 +# This program is free software; you can redistribute it and/or modify
1865 +# it under the terms of the GNU General Public License as published by
1866 +# the Free Software Foundation; either version 2 of the License, or
1867 +# (at your option) any later version.
1869 +# This program is distributed in the hope that it will be useful,
1870 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1871 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1872 +# GNU General Public License for more details.
1874 +# You should have received a copy of the GNU General Public License
1875 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1877 +Branch Manipulation
1879 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1880 +and changing its permission/attribute, there are a lot of works to do.
1884 +----------------------------------------------------------------------
1885 +o Confirm the adding dir exists outside of aufs, including loopback
1886 + mount, and its various attributes.
1887 +o Initialize the xino file and whiteout bases if necessary.
1890 +o Check the owner/group/mode of the directory
1891 + When the owner/group/mode of the adding directory differs from the
1892 + existing branch, aufs issues a warning because it may impose a
1894 + For example, when a upper writable branch has a world writable empty
1895 + top directory, a malicious user can create any files on the writable
1896 + branch directly, like copy-up and modify manually. If something like
1897 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1898 + writable branch, and the writable branch is world-writable, then a
1899 + malicious guy may create /etc/passwd on the writable branch directly
1900 + and the infected file will be valid in aufs.
1901 + I am afraid it can be a security issue, but aufs can do nothing except
1902 + producing a warning.
1906 +----------------------------------------------------------------------
1907 +o Confirm the deleting branch is not busy
1908 + To be general, there is one merit to adopt "remount" interface to
1909 + manipulate branches. It is to discard caches. At deleting a branch,
1910 + aufs checks the still cached (and connected) dentries and inodes. If
1911 + there are any, then they are all in-use. An inode without its
1912 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1914 + For the cached one, aufs checks whether the same named entry exists on
1916 + If the cached one is a directory, because aufs provides a merged view
1917 + to users, as long as one dir is left on any branch aufs can show the
1918 + dir to users. In this case, the branch can be removed from aufs.
1919 + Otherwise aufs rejects deleting the branch.
1921 + If any file on the deleting branch is opened by aufs, then aufs
1925 +Modify the Permission of a Branch
1926 +----------------------------------------------------------------------
1927 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1930 +o rw --> ro: Confirm the modifying branch is not busy
1931 + Aufs rejects the request if any of these conditions are true.
1932 + - a file on the branch is mmap-ed.
1933 + - a regular file on the branch is opened for write and there is no
1934 + same named entry on the upper branch.
1935 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1936 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1937 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-02-22 23:30:37.699347580 +0100
1940 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1942 +# This program is free software; you can redistribute it and/or modify
1943 +# it under the terms of the GNU General Public License as published by
1944 +# the Free Software Foundation; either version 2 of the License, or
1945 +# (at your option) any later version.
1947 +# This program is distributed in the hope that it will be useful,
1948 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1949 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1950 +# GNU General Public License for more details.
1952 +# You should have received a copy of the GNU General Public License
1953 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1955 +Policies to Select One among Multiple Writable Branches
1956 +----------------------------------------------------------------------
1957 +When the number of writable branch is more than one, aufs has to decide
1958 +the target branch for file creation or copy-up. By default, the highest
1959 +writable branch which has the parent (or ancestor) dir of the target
1960 +file is chosen (top-down-parent policy).
1961 +By user's request, aufs implements some other policies to select the
1962 +writable branch, for file creation several policies, round-robin,
1963 +most-free-space, and other policies. For copy-up, top-down-parent,
1964 +bottom-up-parent, bottom-up and others.
1966 +As expected, the round-robin policy selects the branch in circular. When
1967 +you have two writable branches and creates 10 new files, 5 files will be
1968 +created for each branch. mkdir(2) systemcall is an exception. When you
1969 +create 10 new directories, all will be created on the same branch.
1970 +And the most-free-space policy selects the one which has most free
1971 +space among the writable branches. The amount of free space will be
1972 +checked by aufs internally, and users can specify its time interval.
1974 +The policies for copy-up is more simple,
1975 +top-down-parent is equivalent to the same named on in create policy,
1976 +bottom-up-parent selects the writable branch where the parent dir
1977 +exists and the nearest upper one from the copyup-source,
1978 +bottom-up selects the nearest upper writable branch from the
1979 +copyup-source, regardless the existence of the parent dir.
1981 +There are some rules or exceptions to apply these policies.
1982 +- If there is a readonly branch above the policy-selected branch and
1983 + the parent dir is marked as opaque (a variation of whiteout), or the
1984 + target (creating) file is whiteout-ed on the upper readonly branch,
1985 + then the result of the policy is ignored and the target file will be
1986 + created on the nearest upper writable branch than the readonly branch.
1987 +- If there is a writable branch above the policy-selected branch and
1988 + the parent dir is marked as opaque or the target file is whiteouted
1989 + on the branch, then the result of the policy is ignored and the target
1990 + file will be created on the highest one among the upper writable
1991 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1993 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1994 + They try selecting the branch where the source exists as possible
1995 + since copyup a large file will take long time. If it can't be,
1996 + ie. the branch where the source exists is readonly, then they will
1997 + follow the copyup policy.
1998 +- There is an exception for rename(2) when the target exists.
1999 + If the rename target exists, aufs compares the index of the branches
2000 + where the source and the target exists and selects the higher
2001 + one. If the selected branch is readonly, then aufs follows the
2003 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
2004 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
2005 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-02-22 23:30:37.699347580 +0100
2008 +// to view this graph, run dot(1) command in GRAPHVIZ.
2012 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
2016 +aufs_rename -> whinfo [label="store/remove"];
2019 +inode_list [label="h_inum list in branch\ncache"];
2022 +whinode [label="h_inum list file"];
2025 +brmgmt [label="br_add/del/mod/umount"];
2027 +brmgmt -> inode_list [label="create/remove"];
2028 +brmgmt -> whinode [label="load/store"];
2030 +inode_list -> whinode [style=dashed,dir=both];
2032 +aufs_rename -> inode_list [label="add/del"];
2034 +aufs_lookup -> inode_list [label="search"];
2036 +aufs_lookup -> whinfo [label="load/remove"];
2038 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
2039 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
2040 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-02-22 23:30:37.699347580 +0100
2043 +# Copyright (C) 2017-2020 Junjiro R. Okajima
2045 +# This program is free software; you can redistribute it and/or modify
2046 +# it under the terms of the GNU General Public License as published by
2047 +# the Free Software Foundation; either version 2 of the License, or
2048 +# (at your option) any later version.
2050 +# This program is distributed in the hope that it will be useful,
2051 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2052 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2053 +# GNU General Public License for more details.
2055 +# You should have received a copy of the GNU General Public License
2056 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2058 +Special handling for renaming a directory (DIRREN)
2059 +----------------------------------------------------------------------
2060 +First, let's assume we have a simple usecase.
2064 +- /ro/dirA and /ro/dirA/file exist too
2065 +- there is no dirB on both branches
2066 +- a user issues rename("dirA", "dirB")
2068 +Now, what should aufs behave against this rename(2)?
2069 +There are a few possible cases.
2072 + since dirA exists on a readonly branch which cannot be renamed.
2074 + it is possible to copy-up dirA (only the dir itself), but the child
2075 + entries ("file" in this case) should not be. it must be a bad
2076 + approach to copy-up recursively.
2077 +C. returns a success.
2078 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
2079 + is a violation of aufs' policy.
2080 +D. construct an extra information which indicates that /ro/dirA should
2081 + be handled as the name of dirB.
2082 + overlayfs has a similar feature called REDIRECT.
2084 +Until now, aufs implements the case B only which returns EXDEV, and
2085 +expects the userspace application behaves like mv(1) which tries
2086 +issueing rename(2) recursively.
2088 +A new aufs feature called DIRREN is introduced which implements the case
2089 +D. There are several "extra information" added.
2091 +1. detailed info per renamed directory
2092 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
2093 +2. the inode-number list of directories on a branch
2094 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
2096 +The filename of "detailed info per directory" represents the lower
2097 +branch, and its format is
2098 +- a type of the branch id
2100 + + uuid (not implemented yet)
2103 +- the inode-number of the branch root dir
2105 +And it contains these info in a single regular file.
2107 +- branch's inode-number of the logically renamed dir
2108 +- the name of the before-renamed dir
2110 +The "detailed info per directory" file is created in aufs rename(2), and
2111 +loaded in any lookup.
2112 +The info is considered in lookup for the matching case only. Here
2113 +"matching" means that the root of branch (in the info filename) is same
2114 +to the current looking-up branch. After looking-up the before-renamed
2115 +name, the inode-number is compared. And the matched dentry is used.
2117 +The "inode-number list of directories" is a regular file which contains
2118 +simply the inode-numbers on the branch. The file is created or updated
2119 +in removing the branch, and loaded in adding the branch. Its lifetime is
2120 +equal to the branch.
2121 +The list is refered in lookup, and when the current target inode is
2122 +found in the list, the aufs tries loading the "detailed info per
2123 +directory" and get the changed and valid name of the dir.
2125 +Theoretically these "extra informaiton" may be able to be put into XATTR
2126 +in the dir inode. But aufs doesn't choose this way because
2127 +1. XATTR may not be supported by the branch (or its configuration)
2128 +2. XATTR may have its size limit.
2129 +3. XATTR may be less easy to convert than a regular file, when the
2130 + format of the info is changed in the future.
2131 +At the same time, I agree that the regular file approach is much slower
2132 +than XATTR approach. So, in the future, aufs may take the XATTR or other
2135 +This DIRREN feature is enabled by aufs configuration, and is activated
2136 +by a new mount option.
2138 +For the more complicated case, there is a work with UDBA option, which
2139 +is to dected the direct access to the branches (by-passing aufs) and to
2140 +maintain the cashes in aufs. Since a single cached aufs dentry may
2141 +contains two names, before- and after-rename, the name comparision in
2142 +UDBA handler may not work correctly. In this case, the behaviour will be
2143 +equivalen to udba=reval case.
2144 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2145 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2146 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-02-22 23:30:37.699347580 +0100
2149 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2151 +# This program is free software; you can redistribute it and/or modify
2152 +# it under the terms of the GNU General Public License as published by
2153 +# the Free Software Foundation; either version 2 of the License, or
2154 +# (at your option) any later version.
2156 +# This program is distributed in the hope that it will be useful,
2157 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2158 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2159 +# GNU General Public License for more details.
2161 +# You should have received a copy of the GNU General Public License
2162 +# along with this program; if not, write to the Free Software
2163 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2166 +File-based Hierarchical Storage Management (FHSM)
2167 +----------------------------------------------------------------------
2168 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2169 +storage world. Aufs provides this feature as file-based with multiple
2170 +writable branches, based upon the principle of "Colder, the Lower".
2171 +Here the word "colder" means that the less used files, and "lower" means
2172 +that the position in the order of the stacked branches vertically.
2173 +These multiple writable branches are prioritized, ie. the topmost one
2174 +should be the fastest drive and be used heavily.
2176 +o Characters in aufs FHSM story
2177 +- aufs itself and a new branch attribute.
2178 +- a new ioctl interface to move-down and to establish a connection with
2179 + the daemon ("move-down" is a converse of "copy-up").
2180 +- userspace tool and daemon.
2182 +The userspace daemon establishes a connection with aufs and waits for
2183 +the notification. The notified information is very similar to struct
2184 +statfs containing the number of consumed blocks and inodes.
2185 +When the consumed blocks/inodes of a branch exceeds the user-specified
2186 +upper watermark, the daemon activates its move-down process until the
2187 +consumed blocks/inodes reaches the user-specified lower watermark.
2189 +The actual move-down is done by aufs based upon the request from
2190 +user-space since we need to maintain the inode number and the internal
2191 +pointer arrays in aufs.
2193 +Currently aufs FHSM handles the regular files only. Additionally they
2194 +must not be hard-linked nor pseudo-linked.
2197 +o Cowork of aufs and the user-space daemon
2198 + During the userspace daemon established the connection, aufs sends a
2199 + small notification to it whenever aufs writes something into the
2200 + writable branch. But it may cost high since aufs issues statfs(2)
2201 + internally. So user can specify a new option to cache the
2202 + info. Actually the notification is controlled by these factors.
2203 + + the specified cache time.
2204 + + classified as "force" by aufs internally.
2205 + Until the specified time expires, aufs doesn't send the info
2206 + except the forced cases. When aufs decide forcing, the info is always
2207 + notified to userspace.
2208 + For example, the number of free inodes is generally large enough and
2209 + the shortage of it happens rarely. So aufs doesn't force the
2210 + notification when creating a new file, directory and others. This is
2211 + the typical case which aufs doesn't force.
2212 + When aufs writes the actual filedata and the files consumes any of new
2213 + blocks, the aufs forces notifying.
2216 +o Interfaces in aufs
2217 +- New branch attribute.
2219 + Specifies that the branch is managed by FHSM feature. In other word,
2220 + participant in the FHSM.
2221 + When nofhsm is set to the branch, it will not be the source/target
2222 + branch of the move-down operation. This attribute is set
2223 + independently from coo and moo attributes, and if you want full
2224 + FHSM, you should specify them as well.
2225 +- New mount option.
2227 + Specifies a second to suppress many less important info to be
2230 + + AUFS_CTL_FHSM_FD
2231 + create a new file descriptor which userspace can read the notification
2232 + (a subset of struct statfs) from aufs.
2233 +- Module parameter 'brs'
2234 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2236 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2237 + When there are two or more branches with fhsm attributes,
2238 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2239 + terminates it. As a result of remounting and branch-manipulation, the
2240 + number of branches with fhsm attribute can be one. In this case,
2241 + /sbin/mount.aufs will terminate the user-space daemon.
2244 +Finally the operation is done as these steps in kernel-space.
2246 + + no one else is using the file.
2247 + + the file is not hard-linked.
2248 + + the file is not pseudo-linked.
2249 + + the file is a regular file.
2250 + + the parent dir is not opaqued.
2251 +- find the target writable branch.
2252 +- make sure the file is not whiteout-ed by the upper (than the target)
2254 +- make the parent dir on the target branch.
2255 +- mutex lock the inode on the branch.
2256 +- unlink the whiteout on the target branch (if exists).
2257 +- lookup and create the whiteout-ed temporary name on the target branch.
2258 +- copy the file as the whiteout-ed temporary name on the target branch.
2259 +- rename the whiteout-ed temporary name to the original name.
2260 +- unlink the file on the source branch.
2261 +- maintain the internal pointer array and the external inode number
2263 +- maintain the timestamps and other attributes of the parent dir and the
2266 +And of course, in every step, an error may happen. So the operation
2267 +should restore the original file state after an error happens.
2268 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2269 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2270 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-02-22 23:30:37.699347580 +0100
2273 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2275 +# This program is free software; you can redistribute it and/or modify
2276 +# it under the terms of the GNU General Public License as published by
2277 +# the Free Software Foundation; either version 2 of the License, or
2278 +# (at your option) any later version.
2280 +# This program is distributed in the hope that it will be useful,
2281 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2282 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2283 +# GNU General Public License for more details.
2285 +# You should have received a copy of the GNU General Public License
2286 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2288 +mmap(2) -- File Memory Mapping
2289 +----------------------------------------------------------------------
2290 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2291 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2293 +This approach is simple and good, but there is one problem.
2294 +Under /proc, several entries show the mmapped files by its path (with
2295 +device and inode number), and the printed path will be the path on the
2296 +branch fs's instead of virtual aufs's.
2297 +This is not a problem in most cases, but some utilities lsof(1) (and its
2298 +user) may expect the path on aufs.
2300 +To address this issue, aufs adds a new member called vm_prfile in struct
2301 +vm_area_struct (and struct vm_region). The original vm_file points to
2302 +the file on the branch fs in order to handle everything correctly as
2303 +usual. The new vm_prfile points to a virtual file in aufs, and the
2304 +show-functions in procfs refers to vm_prfile if it is set.
2305 +Also we need to maintain several other places where touching vm_file
2307 +- fork()/clone() copies vma and the reference count of vm_file is
2309 +- merging vma maintains the ref count too.
2311 +This is not a good approach. It just fakes the printed path. But it
2312 +leaves all behaviour around f_mapping unchanged. This is surely an
2314 +Actually aufs had adopted another complicated approach which calls
2315 +generic_file_mmap() and handles struct vm_operations_struct. In this
2316 +approach, aufs met a hard problem and I could not solve it without
2317 +switching the approach.
2319 +There may be one more another approach which is
2320 +- bind-mount the branch-root onto the aufs-root internally
2321 +- grab the new vfsmount (ie. struct mount)
2322 +- lazy-umount the branch-root internally
2323 +- in open(2) the aufs-file, open the branch-file with the hidden
2324 + vfsmount (instead of the original branch's vfsmount)
2325 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2326 + but it may be possible from userspace by the mount helper.
2328 +Adding the internal hidden vfsmount and using it in opening a file, the
2329 +file path under /proc will be printed correctly. This approach looks
2330 +smarter, but is not possible I am afraid.
2331 +- aufs-root may be bind-mount later. when it happens, another hidden
2332 + vfsmount will be required.
2333 +- it is hard to get the chance to bind-mount and lazy-umount
2334 + + in kernel-space, FS can have vfsmount in open(2) via
2335 + file->f_path, and aufs can know its vfsmount. But several locks are
2336 + already acquired, and if aufs tries to bind-mount and lazy-umount
2337 + here, then it may cause a deadlock.
2338 + + in user-space, bind-mount doesn't invoke the mount helper.
2339 +- since /proc shows dev and ino, aufs has to give vma these info. it
2340 + means a new member vm_prinode will be necessary. this is essentially
2341 + equivalent to vm_prfile described above.
2343 +I have to give up this "looks-smater" approach.
2344 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2345 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2346 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-02-22 23:30:37.699347580 +0100
2349 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2351 +# This program is free software; you can redistribute it and/or modify
2352 +# it under the terms of the GNU General Public License as published by
2353 +# the Free Software Foundation; either version 2 of the License, or
2354 +# (at your option) any later version.
2356 +# This program is distributed in the hope that it will be useful,
2357 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2358 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2359 +# GNU General Public License for more details.
2361 +# You should have received a copy of the GNU General Public License
2362 +# along with this program; if not, write to the Free Software
2363 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2366 +Listing XATTR/EA and getting the value
2367 +----------------------------------------------------------------------
2368 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2369 +shows the values from the topmost existing file. This behaviour is good
2370 +for the non-dir entries since the bahaviour exactly matches the shown
2371 +information. But for the directories, aufs considers all the same named
2372 +entries on the lower branches. Which means, if one of the lower entry
2373 +rejects readdir call, then aufs returns an error even if the topmost
2374 +entry allows it. This behaviour is necessary to respect the branch fs's
2375 +security, but can make users confused since the user-visible standard
2376 +attributes don't match the behaviour.
2377 +To address this issue, aufs has a mount option called dirperm1 which
2378 +checks the permission for the topmost entry only, and ignores the lower
2379 +entry's permission.
2381 +A similar issue can happen around XATTR.
2382 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2383 +always set. Otherwise these very unpleasant situation would happen.
2384 +- listxattr(2) may return the duplicated entries.
2385 +- users may not be able to remove or reset the XATTR forever,
2388 +XATTR/EA support in the internal (copy,move)-(up,down)
2389 +----------------------------------------------------------------------
2390 +Generally the extended attributes of inode are categorized as these.
2391 +- "security" for LSM and capability.
2392 +- "system" for posix ACL, 'acl' mount option is required for the branch
2394 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2395 +- "user" for userspace, 'user_xattr' mount option is required for the
2396 + branch fs generally.
2398 +Moreover there are some other categories. Aufs handles these rather
2399 +unpopular categories as the ordinary ones, ie. there is no special
2400 +condition nor exception.
2402 +In copy-up, the support for XATTR on the dst branch may differ from the
2403 +src branch. In this case, the copy-up operation will get an error and
2404 +the original user operation which triggered the copy-up will fail. It
2405 +can happen that even all copy-up will fail.
2406 +When both of src and dst branches support XATTR and if an error occurs
2407 +during copying XATTR, then the copy-up should fail obviously. That is a
2408 +good reason and aufs should return an error to userspace. But when only
2409 +the src branch support that XATTR, aufs should not return an error.
2410 +For example, the src branch supports ACL but the dst branch doesn't
2411 +because the dst branch may natively un-support it or temporary
2412 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2413 +may NOT return an error even if the XATTR is not supported. It is
2414 +totally up to the branch fs.
2416 +Anyway when the aufs internal copy-up gets an error from the dst branch
2417 +fs, then aufs tries removing the just copied entry and returns the error
2418 +to the userspace. The worst case of this situation will be all copy-up
2421 +For the copy-up operation, there two basic approaches.
2422 +- copy the specified XATTR only (by category above), and return the
2423 + error unconditionally if it happens.
2424 +- copy all XATTR, and ignore the error on the specified category only.
2426 +In order to support XATTR and to implement the correct behaviour, aufs
2427 +chooses the latter approach and introduces some new branch attributes,
2428 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2429 +They correspond to the XATTR namespaces (see above). Additionally, to be
2430 +convenient, "icex" is also provided which means all "icex*" attributes
2431 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2433 +The meaning of these attributes is to ignore the error from setting
2434 +XATTR on that branch.
2435 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2436 +error from the dst branch according to the specified attributes.
2438 +Some XATTR may have its default value. The default value may come from
2439 +the parent dir or the environment. If the default value is set at the
2440 +file creating-time, it will be overwritten by copy-up.
2441 +Some contradiction may happen I am afraid.
2442 +Do we need another attribute to stop copying XATTR? I am unsure. For
2443 +now, aufs implements the branch attributes to ignore the error.
2444 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2445 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2446 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-02-22 23:30:37.699347580 +0100
2449 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2451 +# This program is free software; you can redistribute it and/or modify
2452 +# it under the terms of the GNU General Public License as published by
2453 +# the Free Software Foundation; either version 2 of the License, or
2454 +# (at your option) any later version.
2456 +# This program is distributed in the hope that it will be useful,
2457 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2458 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2459 +# GNU General Public License for more details.
2461 +# You should have received a copy of the GNU General Public License
2462 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2464 +Export Aufs via NFS
2465 +----------------------------------------------------------------------
2466 +Here is an approach.
2467 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2469 +- iget_locked(): initialize aufs inode generation for a new inode, and
2470 + store it in xigen file.
2471 +- destroy_inode(): increment aufs inode generation and store it in xigen
2472 + file. it is necessary even if it is not unlinked, because any data of
2473 + inode may be changed by UDBA.
2474 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2475 + build file handle by
2476 + + branch id (4 bytes)
2477 + + superblock generation (4 bytes)
2478 + + inode number (4 or 8 bytes)
2479 + + parent dir inode number (4 or 8 bytes)
2480 + + inode generation (4 bytes))
2481 + + return value of exportfs_encode_fh() for the parent on a branch (4
2483 + + file handle for a branch (by exportfs_encode_fh())
2485 + + find the index of a branch from its id in handle, and check it is
2486 + still exist in aufs.
2487 + + 1st level: get the inode number from handle and search it in cache.
2488 + + 2nd level: if not found in cache, get the parent inode number from
2489 + the handle and search it in cache. and then open the found parent
2490 + dir, find the matching inode number by vfs_readdir() and get its
2491 + name, and call lookup_one_len() for the target dentry.
2492 + + 3rd level: if the parent dir is not cached, call
2493 + exportfs_decode_fh() for a branch and get the parent on a branch,
2494 + build a pathname of it, convert it a pathname in aufs, call
2495 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2497 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2498 + for every branch, but not itself. to get this, (currently) aufs
2499 + searches in current->nsproxy->mnt_ns list. it may not be a good
2500 + idea, but I didn't get other approach.
2501 + + test the generation of the gotten inode.
2502 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2503 + convert it into ESTALE for NFSD.
2504 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2505 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2506 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2507 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2508 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-02-22 23:30:37.699347580 +0100
2511 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2513 +# This program is free software; you can redistribute it and/or modify
2514 +# it under the terms of the GNU General Public License as published by
2515 +# the Free Software Foundation; either version 2 of the License, or
2516 +# (at your option) any later version.
2518 +# This program is distributed in the hope that it will be useful,
2519 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2520 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2521 +# GNU General Public License for more details.
2523 +# You should have received a copy of the GNU General Public License
2524 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2526 +Show Whiteout Mode (shwh)
2527 +----------------------------------------------------------------------
2528 +Generally aufs hides the name of whiteouts. But in some cases, to show
2529 +them is very useful for users. For instance, creating a new middle layer
2530 +(branch) by merging existing layers.
2532 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2533 +When you have three branches,
2534 +- Bottom: 'system', squashfs (underlying base system), read-only
2535 +- Middle: 'mods', squashfs, read-only
2536 +- Top: 'overlay', ram (tmpfs), read-write
2538 +The top layer is loaded at boot time and saved at shutdown, to preserve
2539 +the changes made to the system during the session.
2540 +When larger changes have been made, or smaller changes have accumulated,
2541 +the size of the saved top layer data grows. At this point, it would be
2542 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2543 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2544 +restoring save and load speed.
2546 +This merging is simplified by the use of another aufs mount, of just the
2547 +two overlay branches using the 'shwh' option.
2548 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2549 + aufs /livesys/merge_union
2551 +A merged view of these two branches is then available at
2552 +/livesys/merge_union, and the new feature is that the whiteouts are
2554 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2555 +writing to all branches. Also the default mode for all branches is 'ro'.
2556 +It is now possible to save the combined contents of the two overlay
2557 +branches to a new squashfs, e.g.:
2558 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2560 +This new squashfs archive can be stored on the boot device and the
2561 +initramfs will use it to replace the old one at the next boot.
2562 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2563 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2564 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-02-22 23:30:37.699347580 +0100
2567 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2569 +# This program is free software; you can redistribute it and/or modify
2570 +# it under the terms of the GNU General Public License as published by
2571 +# the Free Software Foundation; either version 2 of the License, or
2572 +# (at your option) any later version.
2574 +# This program is distributed in the hope that it will be useful,
2575 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2576 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2577 +# GNU General Public License for more details.
2579 +# You should have received a copy of the GNU General Public License
2580 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2582 +Dynamically customizable FS operations
2583 +----------------------------------------------------------------------
2584 +Generally FS operations (struct inode_operations, struct
2585 +address_space_operations, struct file_operations, etc.) are defined as
2586 +"static const", but it never means that FS have only one set of
2587 +operation. Some FS have multiple sets of them. For instance, ext2 has
2588 +three sets, one for XIP, for NOBH, and for normal.
2589 +Since aufs overrides and redirects these operations, sometimes aufs has
2590 +to change its behaviour according to the branch FS type. More importantly
2591 +VFS acts differently if a function (member in the struct) is set or
2592 +not. It means aufs should have several sets of operations and select one
2593 +among them according to the branch FS definition.
2595 +In order to solve this problem and not to affect the behaviour of VFS,
2596 +aufs defines these operations dynamically. For instance, aufs defines
2597 +dummy direct_IO function for struct address_space_operations, but it may
2598 +not be set to the address_space_operations actually. When the branch FS
2599 +doesn't have it, aufs doesn't set it to its address_space_operations
2600 +while the function definition itself is still alive. So the behaviour
2601 +itself will not change, and it will return an error when direct_IO is
2604 +The lifetime of these dynamically generated operation object is
2605 +maintained by aufs branch object. When the branch is removed from aufs,
2606 +the reference counter of the object is decremented. When it reaches
2607 +zero, the dynamically generated operation object will be freed.
2609 +This approach is designed to support AIO (io_submit), Direct I/O and
2611 +Currently this approach is applied to address_space_operations for
2612 +regular files only.
2613 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2614 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2615 +++ linux/Documentation/filesystems/aufs/README 2021-02-22 23:30:37.699347580 +0100
2618 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2624 +----------------------------------------
2625 +In the early days, aufs was entirely re-designed and re-implemented
2626 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2627 +improvements and implementations, it becomes totally different from
2628 +Unionfs while keeping the basic features.
2629 +Recently, Unionfs Version 2.x series begin taking some of the same
2630 +approaches to aufs1's.
2631 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2632 +University and his team.
2634 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2635 +If you want older kernel version support, try aufs2-2.6.git or
2636 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2638 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2639 + According to Christoph Hellwig, linux rejects all union-type
2640 + filesystems but UnionMount.
2641 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2643 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2644 + UnionMount, and he pointed out an issue around a directory mutex
2645 + lock and aufs addressed it. But it is still unsure whether aufs will
2646 + be merged (or any other union solution).
2647 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2651 +----------------------------------------
2652 +- unite several directories into a single virtual filesystem. The member
2653 + directory is called as a branch.
2654 +- you can specify the permission flags to the branch, which are 'readonly',
2655 + 'readwrite' and 'whiteout-able.'
2656 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2657 + readonly branch are modifiable logically.
2658 +- dynamic branch manipulation, add, del.
2661 +Also there are many enhancements in aufs, such as:
2662 +- test only the highest one for the directory permission (dirperm1)
2663 +- copyup on open (coo=)
2664 +- 'move' policy for copy-up between two writable branches, after
2665 + checking free space.
2667 +- readdir(3) in userspace.
2668 +- keep inode number by external inode number table
2669 +- keep the timestamps of file/dir in internal copyup operation
2670 +- seekable directory, supporting NFS readdir.
2671 +- whiteout is hardlinked in order to reduce the consumption of inodes
2673 +- do not copyup, nor create a whiteout when it is unnecessary
2674 +- revert a single systemcall when an error occurs in aufs
2675 +- remount interface instead of ioctl
2676 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2677 +- loopback mounted filesystem as a branch
2678 +- kernel thread for removing the dir who has a plenty of whiteouts
2679 +- support copyup sparse file (a file which has a 'hole' in it)
2680 +- default permission flags for branches
2681 +- selectable permission flags for ro branch, whether whiteout can
2684 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2685 +- support multiple writable branches, some policies to select one
2686 + among multiple writable branches.
2687 +- a new semantics for link(2) and rename(2) to support multiple
2688 + writable branches.
2689 +- no glibc changes are required.
2690 +- pseudo hardlink (hardlink over branches)
2691 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2692 + including NFS or remote filesystem branch.
2693 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2696 +Currently these features are dropped temporary from aufs4.
2697 +See design/08plan.txt in detail.
2698 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2700 +- statistics of aufs thread (/sys/fs/aufs/stat)
2702 +Features or just an idea in the future (see also design/*.txt),
2703 +- reorder the branch index without del/re-add.
2704 +- permanent xino files for NFSD
2705 +- an option for refreshing the opened files after add/del branches
2706 +- light version, without branch manipulation. (unnecessary?)
2707 +- copyup in userspace
2708 +- inotify in userspace
2713 +----------------------------------------
2714 +There are three GIT trees for aufs4, aufs4-linux.git,
2715 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2717 +While the aufs-util is always necessary, you need either of aufs4-linux
2718 +or aufs4-standalone.
2720 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2721 +git://git.kernel.org/.../torvalds/linux.git.
2722 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2723 +build aufs4 as an external kernel module.
2724 +Several extra patches are not included in this tree. Only
2725 +aufs4-standalone tree contains them. They are described in the later
2726 +section "Configuration and Compilation."
2728 +On the other hand, the aufs4-standalone tree has only aufs source files
2729 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2730 +But you need to apply all aufs patches manually.
2732 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2733 +represents the linux kernel version, "linux-4.x". For instance,
2734 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2735 +"aufs4.x-rcN" branch.
2738 +$ git clone --reference /your/linux/git/tree \
2739 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2740 +- if you don't have linux GIT tree, then remove "--reference ..."
2741 +$ cd aufs4-linux.git
2742 +$ git checkout origin/aufs4.0
2744 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2745 +leave the patch-work to GIT.
2746 +$ cd /your/linux/git/tree
2747 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2749 +$ git checkout -b my4.0 v4.0
2750 +$ (add your local change...)
2751 +$ git pull aufs4 aufs4.0
2752 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2753 +- you may need to solve some conflicts between your_changes and
2754 + aufs4.0. in this case, git-rerere is recommended so that you can
2755 + solve the similar conflicts automatically when you upgrade to 4.1 or
2756 + later in the future.
2758 +o aufs4-standalone tree
2759 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2760 +$ cd aufs4-standalone.git
2761 +$ git checkout origin/aufs4.0
2764 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2765 +- note that the public aufs-util.git is on SourceForge instead of
2768 +$ git checkout origin/aufs4.0
2770 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2771 +The minor version number, 'x' in '4.x', of aufs may not always
2772 +follow the minor version number of the kernel.
2773 +Because changes in the kernel that cause the use of a new
2774 +minor version number do not always require changes to aufs-util.
2776 +Since aufs-util has its own minor version number, you may not be
2777 +able to find a GIT branch in aufs-util for your kernel's
2778 +exact minor version number.
2779 +In this case, you should git-checkout the branch for the
2780 +nearest lower number.
2782 +For (an unreleased) example:
2783 +If you are using "linux-4.10" and the "aufs4.10" branch
2784 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2785 +or something numerically smaller is the branch for your kernel.
2787 +Also you can view all branches by
2791 +3. Configuration and Compilation
2792 +----------------------------------------
2793 +Make sure you have git-checkout'ed the correct branch.
2795 +For aufs4-linux tree,
2796 +- enable CONFIG_AUFS_FS.
2797 +- set other aufs configurations if necessary.
2799 +For aufs4-standalone tree,
2800 +There are several ways to build.
2803 +- apply ./aufs4-kbuild.patch to your kernel source files.
2804 +- apply ./aufs4-base.patch too.
2805 +- apply ./aufs4-mmap.patch too.
2806 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2807 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2808 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2809 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2810 +- enable CONFIG_AUFS_FS, you can select either
2812 +- and build your kernel as usual.
2813 +- install the built kernel.
2814 + Note: Since linux-3.9, every filesystem module requires an alias
2815 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2816 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2817 +- install the header files too by "make headers_install" to the
2818 + directory where you specify. By default, it is $PWD/usr.
2819 + "make help" shows a brief note for headers_install.
2820 +- and reboot your system.
2823 +- module only (CONFIG_AUFS_FS=m).
2824 +- apply ./aufs4-base.patch to your kernel source files.
2825 +- apply ./aufs4-mmap.patch too.
2826 +- apply ./aufs4-standalone.patch too.
2827 +- build your kernel, don't forget "make headers_install", and reboot.
2828 +- edit ./config.mk and set other aufs configurations if necessary.
2829 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2830 + every aufs configurations.
2831 +- build the module by simple "make".
2832 + Note: Since linux-3.9, every filesystem module requires an alias
2833 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2834 + modules.aliases file.
2835 +- you can specify ${KDIR} make variable which points to your kernel
2837 +- install the files
2838 + + run "make install" to install the aufs module, or copy the built
2839 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2840 + + run "make install_headers" (instead of headers_install) to install
2841 + the modified aufs header file (you can specify DESTDIR which is
2842 + available in aufs standalone version's Makefile only), or copy
2843 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2844 + you like manually. By default, the target directory is $PWD/usr.
2845 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2846 + kernel source tree.
2848 +Note: The header file aufs_type.h is necessary to build aufs-util
2849 + as well as "make headers_install" in the kernel source tree.
2850 + headers_install is subject to be forgotten, but it is essentially
2851 + necessary, not only for building aufs-util.
2852 + You may not meet problems without headers_install in some older
2856 +- read README in aufs-util, build and install it
2857 +- note that your distribution may contain an obsoleted version of
2858 + aufs_type.h in /usr/include/linux or something. When you build aufs
2859 + utilities, make sure that your compiler refers the correct aufs header
2860 + file which is built by "make headers_install."
2861 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2862 + then run "make install_ulib" too. And refer to the aufs manual in
2865 +There several other patches in aufs4-standalone.git. They are all
2866 +optional. When you meet some problems, they will help you.
2867 +- aufs4-loopback.patch
2868 + Supports a nested loopback mount in a branch-fs. This patch is
2869 + unnecessary until aufs produces a message like "you may want to try
2870 + another patch for loopback file".
2871 +- proc_mounts.patch
2872 + When there are many mountpoints and many mount(2)/umount(2) are
2873 + running, then /proc/mounts may not show the all mountpoints. This
2874 + patch makes /proc/mounts always show the full mountpoints list.
2875 + If you don't want to apply this patch and meet such problem, then you
2876 + need to increase the value of 'ProcMounts_Times' make-variable in
2877 + aufs-util.git as a second best solution.
2879 + Modifies a system global kernel internal function get_next_ino() in
2880 + order to stop assigning 0 for an inode-number. Not directly related to
2881 + aufs, but recommended generally.
2883 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2884 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2885 + duplication of inode number, which is important for backup tools and
2886 + other utilities. When you find aufs XINO files for tmpfs branch
2887 + growing too much, try this patch.
2888 +- lockdep-debug.patch
2889 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2890 + also a caller of VFS functions for branch filesystems, subclassing of
2891 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2892 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2893 + need to apply this debug patch to expand several constant values.
2894 + If you don't know what LOCKDEP is, then you don't have apply this
2899 +----------------------------------------
2900 +At first, make sure aufs-util are installed, and please read the aufs
2901 +manual, aufs.5 in aufs-util.git tree.
2905 +$ mkdir /tmp/rw /tmp/aufs
2906 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2908 +Here is another example. The result is equivalent.
2909 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2911 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2912 +# mount -o remount,append:${HOME} /tmp/aufs
2914 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2915 +you modify a file under /tmp/aufs, the one on your home directory is
2916 +not affected, instead the same named file will be newly created under
2917 +/tmp/rw. And all of your modification to a file will be applied to
2918 +the one under /tmp/rw. This is called the file based Copy on Write
2920 +Aufs mount options are described in aufs.5.
2921 +If you run chroot or something and make your aufs as a root directory,
2922 +then you need to customize the shutdown script. See the aufs manual in
2925 +Additionally, there are some sample usages of aufs which are a
2926 +diskless system with network booting, and LiveCD over NFS.
2927 +See sample dir in CVS tree on SourceForge.
2931 +----------------------------------------
2932 +When you have any problems or strange behaviour in aufs, please let me
2934 +- /proc/mounts (instead of the output of mount(8))
2935 +- /sys/module/aufs/*
2936 +- /sys/fs/aufs/* (if you have them)
2937 +- /debug/aufs/* (if you have them)
2938 +- linux kernel version
2939 + if your kernel is not plain, for example modified by distributor,
2940 + the url where i can download its source is necessary too.
2941 +- aufs version which was printed at loading the module or booting the
2942 + system, instead of the date you downloaded.
2943 +- configuration (define/undefine CONFIG_AUFS_xxx)
2944 +- kernel configuration or /proc/config.gz (if you have it)
2945 +- LSM (linux security module, if you are using)
2946 +- behaviour which you think to be incorrect
2947 +- actual operation, reproducible one is better
2948 +- mailto: aufs-users at lists.sourceforge.net
2950 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2951 +and Feature Requests) on SourceForge. Please join and write to
2955 +6. Acknowledgements
2956 +----------------------------------------
2957 +Thanks to everyone who have tried and are using aufs, whoever
2958 +have reported a bug or any feedback.
2960 +Especially donators:
2961 +Tomas Matejicek(slax.org) made a donation (much more than once).
2962 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2963 + scripts) is making "doubling" donations.
2964 + Unfortunately I cannot list all of the donators, but I really
2966 + It ends Aug 2010, but the ordinary donation URL is still available.
2967 + <http://sourceforge.net/donate/index.php?group_id=167503>
2968 +Dai Itasaka made a donation (2007/8).
2969 +Chuck Smith made a donation (2008/4, 10 and 12).
2970 +Henk Schoneveld made a donation (2008/9).
2971 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2972 +Francois Dupoux made a donation (2008/11).
2973 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2974 + aufs2 GIT tree (2009/2).
2975 +William Grant made a donation (2009/3).
2976 +Patrick Lane made a donation (2009/4).
2977 +The Mail Archive (mail-archive.com) made donations (2009/5).
2978 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2979 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2980 +Pavel Pronskiy made a donation (2011/2).
2981 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2982 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2983 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2985 +Sam Liddicott made a donation (2011/9).
2986 +Era Scarecrow made a donation (2013/4).
2987 +Bor Ratajc made a donation (2013/4).
2988 +Alessandro Gorreta made a donation (2013/4).
2989 +POIRETTE Marc made a donation (2013/4).
2990 +Alessandro Gorreta made a donation (2013/4).
2991 +lauri kasvandik made a donation (2013/5).
2992 +"pemasu from Finland" made a donation (2013/7).
2993 +The Parted Magic Project made a donation (2013/9 and 11).
2994 +Pavel Barta made a donation (2013/10).
2995 +Nikolay Pertsev made a donation (2014/5).
2996 +James B made a donation (2014/7 and 2015/7).
2997 +Stefano Di Biase made a donation (2014/8).
2998 +Daniel Epellei made a donation (2015/1).
2999 +OmegaPhil made a donation (2016/1, 2018/4).
3000 +Tomasz Szewczyk made a donation (2016/4).
3001 +James Burry made a donation (2016/12).
3002 +Carsten Rose made a donation (2018/9).
3003 +Porteus Kiosk made a donation (2018/10).
3005 +Thank you very much.
3006 +Donations are always, including future donations, very important and
3007 +helpful for me to keep on developing aufs.
3011 +----------------------------------------
3012 +If you are an experienced user, no explanation is needed. Aufs is
3013 +just a linux filesystem.
3018 +# Local variables: ;
3021 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
3022 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3023 +++ linux/fs/aufs/aufs.h 2021-02-22 23:30:37.699347580 +0100
3025 +/* SPDX-License-Identifier: GPL-2.0 */
3027 + * Copyright (C) 2005-2020 Junjiro R. Okajima
3029 + * This program, aufs is free software; you can redistribute it and/or modify
3030 + * it under the terms of the GNU General Public License as published by
3031 + * the Free Software Foundation; either version 2 of the License, or
3032 + * (at your option) any later version.
3034 + * This program is distributed in the hope that it will be useful,
3035 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3036 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3037 + * GNU General Public License for more details.
3039 + * You should have received a copy of the GNU General Public License
3040 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3044 + * all header files
3052 +#define AuStub(type, name, body, ...) \
3053 + static inline type name(__VA_ARGS__) { body; }
3055 +#define AuStubVoid(name, ...) \
3056 + AuStub(void, name, , __VA_ARGS__)
3057 +#define AuStubInt0(name, ...) \
3058 + AuStub(int, name, return 0, __VA_ARGS__)
3062 +#include "branch.h"
3065 +#include "dbgaufs.h"
3066 +#include "dentry.h"
3068 +#include "dirren.h"
3071 +#include "fstype.h"
3076 +#include "module.h"
3080 +#include "sysaufs.h"
3085 +#endif /* __KERNEL__ */
3086 +#endif /* __AUFS_H__ */
3087 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
3088 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
3089 +++ linux/fs/aufs/branch.c 2021-02-22 23:30:37.699347580 +0100
3091 +// SPDX-License-Identifier: GPL-2.0
3093 + * Copyright (C) 2005-2020 Junjiro R. Okajima
3095 + * This program, aufs is free software; you can redistribute it and/or modify
3096 + * it under the terms of the GNU General Public License as published by
3097 + * the Free Software Foundation; either version 2 of the License, or
3098 + * (at your option) any later version.
3100 + * This program is distributed in the hope that it will be useful,
3101 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3102 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3103 + * GNU General Public License for more details.
3105 + * You should have received a copy of the GNU General Public License
3106 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3110 + * branch management
3113 +#include <linux/compat.h>
3114 +#include <linux/statfs.h>
3118 + * free a single branch
3120 +static void au_br_do_free(struct au_branch *br)
3123 + struct au_wbr *wbr;
3124 + struct au_dykey **key;
3126 + au_hnotify_fin_br(br);
3127 + /* always, regardless the mount option */
3128 + au_dr_hino_free(&br->br_dirren);
3131 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
3132 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
3133 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
3134 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
3138 + for (i = 0; i < AuBrWh_Last; i++)
3139 + dput(wbr->wbr_wh[i]);
3140 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3141 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3144 + if (br->br_fhsm) {
3145 + au_br_fhsm_fin(br->br_fhsm);
3146 + au_kfree_try_rcu(br->br_fhsm);
3149 + key = br->br_dykey;
3150 + for (i = 0; i < AuBrDynOp; i++, key++)
3156 + /* recursive lock, s_umount of branch's */
3157 + /* synchronize_rcu(); */ /* why? */
3159 + path_put(&br->br_path);
3161 + au_kfree_rcu(wbr);
3162 + au_lcnt_wait_for_fin(&br->br_nfiles);
3163 + au_lcnt_wait_for_fin(&br->br_count);
3164 + /* I don't know why, but percpu_refcount requires this */
3165 + /* synchronize_rcu(); */
3170 + * frees all branches
3172 +void au_br_free(struct au_sbinfo *sbinfo)
3174 + aufs_bindex_t bmax;
3175 + struct au_branch **br;
3177 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3179 + bmax = sbinfo->si_bbot + 1;
3180 + br = sbinfo->si_branch;
3182 + au_br_do_free(*br++);
3186 + * find the index of a branch which is specified by @br_id.
3188 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3190 + aufs_bindex_t bindex, bbot;
3192 + bbot = au_sbbot(sb);
3193 + for (bindex = 0; bindex <= bbot; bindex++)
3194 + if (au_sbr_id(sb, bindex) == br_id)
3199 +/* ---------------------------------------------------------------------- */
3205 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3206 + struct dentry *h_root)
3208 + if (unlikely(h_adding == h_root
3209 + || au_test_loopback_overlap(sb, h_adding)))
3211 + if (h_adding->d_sb != h_root->d_sb)
3213 + return au_test_subdir(h_adding, h_root)
3214 + || au_test_subdir(h_root, h_adding);
3218 + * returns a newly allocated branch. @new_nbranch is a number of branches
3219 + * after adding a branch.
3221 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3224 + struct au_branch *add_branch;
3225 + struct dentry *root;
3226 + struct inode *inode;
3230 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3231 + if (unlikely(!add_branch))
3233 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3234 + if (unlikely(!add_branch->br_xino))
3236 + err = au_hnotify_init_br(add_branch, perm);
3237 + if (unlikely(err))
3240 + if (au_br_writable(perm)) {
3241 + /* may be freed separately at changing the branch permission */
3242 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3244 + if (unlikely(!add_branch->br_wbr))
3248 + if (au_br_fhsm(perm)) {
3249 + err = au_fhsm_br_alloc(add_branch);
3250 + if (unlikely(err))
3254 + root = sb->s_root;
3255 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3257 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3259 + inode = d_inode(root);
3260 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3264 + return add_branch; /* success */
3267 + au_kfree_rcu(add_branch->br_wbr);
3269 + au_hnotify_fin_br(add_branch);
3271 + au_xino_put(add_branch);
3273 + au_kfree_rcu(add_branch);
3275 + return ERR_PTR(err);
3279 + * test if the branch permission is legal or not.
3281 +static int test_br(struct inode *inode, int brperm, char *path)
3285 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3290 + pr_err("write permission for readonly mount or inode, %s\n", path);
3298 + * 0: success, the caller will add it
3299 + * plus: success, it is already unified, the caller should ignore it
3302 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3305 + aufs_bindex_t bbot, bindex;
3306 + struct dentry *root, *h_dentry;
3307 + struct inode *inode, *h_inode;
3309 + root = sb->s_root;
3310 + bbot = au_sbbot(sb);
3311 + if (unlikely(bbot >= 0
3312 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3316 + pr_err("%s duplicated\n", add->pathname);
3321 + err = -ENOSPC; /* -E2BIG; */
3322 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3323 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3324 + pr_err("number of branches exceeded %s\n", add->pathname);
3329 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3330 + pr_err("bad index %d\n", add->bindex);
3334 + inode = d_inode(add->path.dentry);
3336 + if (unlikely(!inode->i_nlink)) {
3337 + pr_err("no existence %s\n", add->pathname);
3342 + if (unlikely(inode->i_sb == sb)) {
3343 + pr_err("%s must be outside\n", add->pathname);
3347 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3348 + pr_err("unsupported filesystem, %s (%s)\n",
3349 + add->pathname, au_sbtype(inode->i_sb));
3353 + if (unlikely(inode->i_sb->s_stack_depth)) {
3354 + pr_err("already stacked, %s (%s)\n",
3355 + add->pathname, au_sbtype(inode->i_sb));
3359 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3360 + if (unlikely(err))
3364 + return 0; /* success */
3367 + for (bindex = 0; bindex <= bbot; bindex++)
3368 + if (unlikely(test_overlap(sb, add->path.dentry,
3369 + au_h_dptr(root, bindex)))) {
3370 + pr_err("%s is overlapped\n", add->pathname);
3375 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3376 + h_dentry = au_h_dptr(root, 0);
3377 + h_inode = d_inode(h_dentry);
3378 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3379 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3380 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3381 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3383 + i_uid_read(inode), i_gid_read(inode),
3384 + (inode->i_mode & S_IALLUGO),
3385 + i_uid_read(h_inode), i_gid_read(h_inode),
3386 + (h_inode->i_mode & S_IALLUGO));
3394 + * initialize or clean the whiteouts for an adding branch
3396 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3399 + int err, old_perm;
3400 + aufs_bindex_t bindex;
3401 + struct inode *h_inode;
3402 + struct au_wbr *wbr;
3403 + struct au_hinode *hdir;
3404 + struct dentry *h_dentry;
3406 + err = vfsub_mnt_want_write(au_br_mnt(br));
3407 + if (unlikely(err))
3411 + old_perm = br->br_perm;
3412 + br->br_perm = new_perm;
3415 + bindex = au_br_index(sb, br->br_id);
3416 + if (0 <= bindex) {
3417 + hdir = au_hi(d_inode(sb->s_root), bindex);
3418 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3420 + h_dentry = au_br_dentry(br);
3421 + h_inode = d_inode(h_dentry);
3422 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3425 + err = au_wh_init(br, sb);
3427 + wbr_wh_write_lock(wbr);
3428 + err = au_wh_init(br, sb);
3429 + wbr_wh_write_unlock(wbr);
3432 + au_hn_inode_unlock(hdir);
3434 + inode_unlock(h_inode);
3435 + vfsub_mnt_drop_write(au_br_mnt(br));
3436 + br->br_perm = old_perm;
3438 + if (!err && wbr && !au_br_writable(new_perm)) {
3439 + au_kfree_rcu(wbr);
3440 + br->br_wbr = NULL;
3447 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3451 + struct kstatfs kst;
3452 + struct au_wbr *wbr;
3455 + au_rw_init(&wbr->wbr_wh_rwsem);
3456 + atomic_set(&wbr->wbr_wh_running, 0);
3459 + * a limit for rmdir/rename a dir
3460 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3462 + err = vfs_statfs(&br->br_path, &kst);
3463 + if (unlikely(err))
3466 + if (kst.f_namelen >= NAME_MAX)
3467 + err = au_br_init_wh(sb, br, perm);
3469 + pr_err("%pd(%s), unsupported namelen %ld\n",
3471 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3477 +/* initialize a new branch */
3478 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3479 + struct au_opt_add *add)
3482 + struct au_branch *brbase;
3484 + struct inode *h_inode;
3487 + br->br_perm = add->perm;
3488 + br->br_path = add->path; /* set first, path_get() later */
3489 + spin_lock_init(&br->br_dykey_lock);
3490 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3491 + au_lcnt_init(&br->br_count, /*release*/NULL);
3492 + br->br_id = au_new_br_id(sb);
3493 + AuDebugOn(br->br_id < 0);
3495 + /* always, regardless the given option */
3496 + err = au_dr_br_init(sb, br, &add->path);
3497 + if (unlikely(err))
3500 + if (au_br_writable(add->perm)) {
3501 + err = au_wbr_init(br, sb, add->perm);
3502 + if (unlikely(err))
3506 + if (au_opt_test(au_mntflags(sb), XINO)) {
3507 + brbase = au_sbr(sb, 0);
3508 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3510 + h_inode = d_inode(add->path.dentry);
3511 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3512 + if (unlikely(err)) {
3513 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3518 + sysaufs_br_init(br);
3519 + path_get(&br->br_path);
3520 + goto out; /* success */
3523 + memset(&br->br_path, 0, sizeof(br->br_path));
3528 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3529 + struct au_branch *br, aufs_bindex_t bbot,
3530 + aufs_bindex_t amount)
3532 + struct au_branch **brp;
3534 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3536 + brp = sbinfo->si_branch + bindex;
3537 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3539 + sbinfo->si_bbot++;
3540 + if (unlikely(bbot < 0))
3541 + sbinfo->si_bbot = 0;
3544 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3545 + aufs_bindex_t bbot, aufs_bindex_t amount)
3547 + struct au_hdentry *hdp;
3549 + AuRwMustWriteLock(&dinfo->di_rwsem);
3551 + hdp = au_hdentry(dinfo, bindex);
3552 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3553 + au_h_dentry_init(hdp);
3555 + if (unlikely(bbot < 0))
3556 + dinfo->di_btop = 0;
3559 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3560 + aufs_bindex_t bbot, aufs_bindex_t amount)
3562 + struct au_hinode *hip;
3564 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3566 + hip = au_hinode(iinfo, bindex);
3567 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3568 + au_hinode_init(hip);
3570 + if (unlikely(bbot < 0))
3571 + iinfo->ii_btop = 0;
3574 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3575 + aufs_bindex_t bindex)
3577 + struct dentry *root, *h_dentry;
3578 + struct inode *root_inode, *h_inode;
3579 + aufs_bindex_t bbot, amount;
3581 + root = sb->s_root;
3582 + root_inode = d_inode(root);
3583 + bbot = au_sbbot(sb);
3584 + amount = bbot + 1 - bindex;
3585 + h_dentry = au_br_dentry(br);
3586 + au_sbilist_lock();
3587 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3588 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3589 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3590 + au_set_h_dptr(root, bindex, dget(h_dentry));
3591 + h_inode = d_inode(h_dentry);
3592 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3593 + au_sbilist_unlock();
3596 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3599 + aufs_bindex_t bbot, add_bindex;
3600 + struct dentry *root, *h_dentry;
3601 + struct inode *root_inode;
3602 + struct au_branch *add_branch;
3604 + root = sb->s_root;
3605 + root_inode = d_inode(root);
3606 + IMustLock(root_inode);
3607 + IiMustWriteLock(root_inode);
3608 + err = test_add(sb, add, remount);
3609 + if (unlikely(err < 0))
3613 + goto out; /* success */
3616 + bbot = au_sbbot(sb);
3617 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3618 + err = PTR_ERR(add_branch);
3619 + if (IS_ERR(add_branch))
3622 + err = au_br_init(add_branch, sb, add);
3623 + if (unlikely(err)) {
3624 + au_br_do_free(add_branch);
3628 + add_bindex = add->bindex;
3629 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3630 + au_br_do_add(sb, add_branch, add_bindex);
3631 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3632 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3634 + h_dentry = add->path.dentry;
3635 + if (!add_bindex) {
3636 + au_cpup_attr_all(root_inode, /*force*/1);
3637 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3639 + au_add_nlink(root_inode, d_inode(h_dentry));
3645 +/* ---------------------------------------------------------------------- */
3647 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3648 + unsigned long long max __maybe_unused,
3651 + unsigned long long n;
3652 + struct file **p, *f;
3653 + struct hlist_bl_head *files;
3654 + struct hlist_bl_node *pos;
3655 + struct au_finfo *finfo;
3659 + files = &au_sbi(sb)->si_files;
3660 + hlist_bl_lock(files);
3661 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3662 + f = finfo->fi_file;
3664 + && !special_file(file_inode(f)->i_mode)) {
3668 + AuDebugOn(n > max);
3671 + hlist_bl_unlock(files);
3676 +static struct file **au_farray_alloc(struct super_block *sb,
3677 + unsigned long long *max)
3679 + struct au_sbinfo *sbi;
3682 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3683 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3686 +static void au_farray_free(struct file **a, unsigned long long max)
3688 + unsigned long long ull;
3690 + for (ull = 0; ull < max; ull++)
3696 +/* ---------------------------------------------------------------------- */
3702 +/* to show the line number, do not make it inlined function */
3703 +#define AuVerbose(do_info, fmt, ...) do { \
3705 + pr_info(fmt, ##__VA_ARGS__); \
3708 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3709 + aufs_bindex_t bbot)
3711 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3714 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3715 + aufs_bindex_t bbot)
3717 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3721 + * test if the branch is deletable or not.
3723 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3724 + unsigned int sigen, const unsigned int verbose)
3726 + int err, i, j, ndentry;
3727 + aufs_bindex_t btop, bbot;
3728 + struct au_dcsub_pages dpages;
3729 + struct au_dpage *dpage;
3732 + err = au_dpages_init(&dpages, GFP_NOFS);
3733 + if (unlikely(err))
3735 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3736 + if (unlikely(err))
3739 + for (i = 0; !err && i < dpages.ndpage; i++) {
3740 + dpage = dpages.dpages + i;
3741 + ndentry = dpage->ndentry;
3742 + for (j = 0; !err && j < ndentry; j++) {
3743 + d = dpage->dentries[j];
3744 + AuDebugOn(au_dcount(d) <= 0);
3745 + if (!au_digen_test(d, sigen)) {
3746 + di_read_lock_child(d, AuLock_IR);
3747 + if (unlikely(au_dbrange_test(d))) {
3748 + di_read_unlock(d, AuLock_IR);
3752 + di_write_lock_child(d);
3753 + if (unlikely(au_dbrange_test(d))) {
3754 + di_write_unlock(d);
3757 + err = au_reval_dpath(d, sigen);
3759 + di_downgrade_lock(d, AuLock_IR);
3761 + di_write_unlock(d);
3766 + /* AuDbgDentry(d); */
3767 + btop = au_dbtop(d);
3768 + bbot = au_dbbot(d);
3769 + if (btop <= bindex
3771 + && au_h_dptr(d, bindex)
3772 + && au_test_dbusy(d, btop, bbot)) {
3774 + AuVerbose(verbose, "busy %pd\n", d);
3777 + di_read_unlock(d, AuLock_IR);
3782 + au_dpages_free(&dpages);
3787 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3788 + unsigned int sigen, const unsigned int verbose)
3791 + unsigned long long max, ull;
3792 + struct inode *i, **array;
3793 + aufs_bindex_t btop, bbot;
3795 + array = au_iarray_alloc(sb, &max);
3796 + err = PTR_ERR(array);
3797 + if (IS_ERR(array))
3801 + AuDbg("b%d\n", bindex);
3802 + for (ull = 0; !err && ull < max; ull++) {
3806 + if (i->i_ino == AUFS_ROOT_INO)
3809 + /* AuDbgInode(i); */
3810 + if (au_iigen(i, NULL) == sigen)
3811 + ii_read_lock_child(i);
3813 + ii_write_lock_child(i);
3814 + err = au_refresh_hinode_self(i);
3817 + ii_downgrade_lock(i);
3819 + ii_write_unlock(i);
3824 + btop = au_ibtop(i);
3825 + bbot = au_ibbot(i);
3826 + if (btop <= bindex
3828 + && au_h_iptr(i, bindex)
3829 + && au_test_ibusy(i, btop, bbot)) {
3831 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3834 + ii_read_unlock(i);
3836 + au_iarray_free(array, max);
3842 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3843 + const unsigned int verbose)
3846 + unsigned int sigen;
3848 + sigen = au_sigen(root->d_sb);
3849 + DiMustNoWaiters(root);
3850 + IiMustNoWaiters(d_inode(root));
3851 + di_write_unlock(root);
3852 + err = test_dentry_busy(root, bindex, sigen, verbose);
3854 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3855 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3860 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3861 + struct file **to_free, int *idx)
3864 + unsigned char matched, root;
3865 + aufs_bindex_t bindex, bbot;
3866 + struct au_fidir *fidir;
3867 + struct au_hfile *hfile;
3870 + root = IS_ROOT(file->f_path.dentry);
3873 + to_free[*idx] = file;
3879 + fidir = au_fi(file)->fi_hdir;
3880 + AuDebugOn(!fidir);
3881 + bbot = au_fbbot_dir(file);
3882 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3883 + hfile = fidir->fd_hfile + bindex;
3884 + if (!hfile->hf_file)
3887 + if (hfile->hf_br->br_id == br_id) {
3899 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3900 + struct file **to_free, int opened)
3903 + unsigned long long ull, max;
3904 + aufs_bindex_t btop;
3905 + struct file *file, **array;
3906 + struct dentry *root;
3907 + struct au_hfile *hfile;
3909 + array = au_farray_alloc(sb, &max);
3910 + err = PTR_ERR(array);
3911 + if (IS_ERR(array))
3916 + root = sb->s_root;
3917 + di_write_unlock(root);
3918 + for (ull = 0; ull < max; ull++) {
3919 + file = array[ull];
3920 + if (unlikely(!file))
3923 + /* AuDbg("%pD\n", file); */
3924 + fi_read_lock(file);
3925 + btop = au_fbtop(file);
3926 + if (!d_is_dir(file->f_path.dentry)) {
3927 + hfile = &au_fi(file)->fi_htop;
3928 + if (hfile->hf_br->br_id == br_id)
3931 + err = test_dir_busy(file, br_id, to_free, &idx);
3932 + fi_read_unlock(file);
3933 + if (unlikely(err))
3936 + di_write_lock_child(root);
3937 + au_farray_free(array, max);
3938 + AuDebugOn(idx > opened);
3944 +static void br_del_file(struct file **to_free, unsigned long long opened,
3945 + aufs_bindex_t br_id)
3947 + unsigned long long ull;
3948 + aufs_bindex_t bindex, btop, bbot, bfound;
3949 + struct file *file;
3950 + struct au_fidir *fidir;
3951 + struct au_hfile *hfile;
3953 + for (ull = 0; ull < opened; ull++) {
3954 + file = to_free[ull];
3955 + if (unlikely(!file))
3958 + /* AuDbg("%pD\n", file); */
3959 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3961 + fidir = au_fi(file)->fi_hdir;
3962 + AuDebugOn(!fidir);
3963 + fi_write_lock(file);
3964 + btop = au_fbtop(file);
3965 + bbot = au_fbbot_dir(file);
3966 + for (bindex = btop; bindex <= bbot; bindex++) {
3967 + hfile = fidir->fd_hfile + bindex;
3968 + if (!hfile->hf_file)
3971 + if (hfile->hf_br->br_id == br_id) {
3976 + AuDebugOn(bfound < 0);
3977 + au_set_h_fptr(file, bfound, NULL);
3978 + if (bfound == btop) {
3979 + for (btop++; btop <= bbot; btop++)
3980 + if (au_hf_dir(file, btop)) {
3981 + au_set_fbtop(file, btop);
3985 + fi_write_unlock(file);
3989 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3990 + const aufs_bindex_t bindex,
3991 + const aufs_bindex_t bbot)
3993 + struct au_branch **brp, **p;
3995 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3997 + brp = sbinfo->si_branch + bindex;
3998 + if (bindex < bbot)
3999 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
4000 + sbinfo->si_branch[0 + bbot] = NULL;
4001 + sbinfo->si_bbot--;
4003 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
4006 + sbinfo->si_branch = p;
4007 + /* harmless error */
4010 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
4011 + const aufs_bindex_t bbot)
4013 + struct au_hdentry *hdp, *p;
4015 + AuRwMustWriteLock(&dinfo->di_rwsem);
4017 + hdp = au_hdentry(dinfo, bindex);
4018 + if (bindex < bbot)
4019 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
4020 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
4023 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
4026 + dinfo->di_hdentry = p;
4027 + /* harmless error */
4030 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
4031 + const aufs_bindex_t bbot)
4033 + struct au_hinode *hip, *p;
4035 + AuRwMustWriteLock(&iinfo->ii_rwsem);
4037 + hip = au_hinode(iinfo, bindex);
4038 + if (bindex < bbot)
4039 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
4040 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
4043 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
4046 + iinfo->ii_hinode = p;
4047 + /* harmless error */
4050 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
4051 + struct au_branch *br)
4053 + aufs_bindex_t bbot;
4054 + struct au_sbinfo *sbinfo;
4055 + struct dentry *root, *h_root;
4056 + struct inode *inode, *h_inode;
4057 + struct au_hinode *hinode;
4059 + SiMustWriteLock(sb);
4061 + root = sb->s_root;
4062 + inode = d_inode(root);
4063 + sbinfo = au_sbi(sb);
4064 + bbot = sbinfo->si_bbot;
4066 + h_root = au_h_dptr(root, bindex);
4067 + hinode = au_hi(inode, bindex);
4068 + h_inode = au_igrab(hinode->hi_inode);
4071 + au_sbilist_lock();
4072 + au_br_do_del_brp(sbinfo, bindex, bbot);
4073 + au_br_do_del_hdp(au_di(root), bindex, bbot);
4074 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
4075 + au_sbilist_unlock();
4077 + /* ignore an error */
4078 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
4082 + au_br_do_free(br);
4085 +static unsigned long long empty_cb(struct super_block *sb, void *array,
4086 + unsigned long long max, void *arg)
4091 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
4094 + unsigned long long opened;
4095 + unsigned int mnt_flags;
4096 + aufs_bindex_t bindex, bbot, br_id;
4097 + unsigned char do_wh, verbose;
4098 + struct au_branch *br;
4099 + struct au_wbr *wbr;
4100 + struct dentry *root;
4101 + struct file **to_free;
4106 + root = sb->s_root;
4107 + bindex = au_find_dbindex(root, del->h_path.dentry);
4110 + goto out; /* success */
4112 + pr_err("%s no such branch\n", del->pathname);
4115 + AuDbg("bindex b%d\n", bindex);
4118 + mnt_flags = au_mntflags(sb);
4119 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4120 + bbot = au_sbbot(sb);
4121 + if (unlikely(!bbot)) {
4122 + AuVerbose(verbose, "no more branches left\n");
4126 + br = au_sbr(sb, bindex);
4127 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
4128 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
4129 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
4133 + br_id = br->br_id;
4134 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
4135 + if (unlikely(opened)) {
4136 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
4137 + err = PTR_ERR(to_free);
4138 + if (IS_ERR(to_free))
4141 + err = test_file_busy(sb, br_id, to_free, opened);
4142 + if (unlikely(err)) {
4143 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4149 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4151 + /* instead of WbrWhMustWriteLock(wbr) */
4152 + SiMustWriteLock(sb);
4153 + for (i = 0; i < AuBrWh_Last; i++) {
4154 + dput(wbr->wbr_wh[i]);
4155 + wbr->wbr_wh[i] = NULL;
4159 + err = test_children_busy(root, bindex, verbose);
4160 + if (unlikely(err)) {
4169 + * now we confirmed the branch is deletable.
4170 + * let's free the remaining opened dirs on the branch.
4172 + di_write_unlock(root);
4173 + br_del_file(to_free, opened, br_id);
4174 + di_write_lock_child(root);
4177 + sysaufs_brs_del(sb, bindex); /* remove successors */
4178 + dbgaufs_xino_del(br); /* remove one */
4179 + au_br_do_del(sb, bindex, br);
4180 + sysaufs_brs_add(sb, bindex); /* append successors */
4181 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4184 + au_cpup_attr_all(d_inode(root), /*force*/1);
4185 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4187 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4188 + if (au_opt_test(mnt_flags, PLINK))
4189 + au_plink_half_refresh(sb, br_id);
4191 + goto out; /* success */
4195 + rerr = au_br_init_wh(sb, br, br->br_perm);
4197 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4198 + del->pathname, rerr);
4201 + au_farray_free(to_free, opened);
4205 +/* ---------------------------------------------------------------------- */
4207 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4210 + aufs_bindex_t btop, bbot;
4211 + struct aufs_ibusy ibusy;
4212 + struct inode *inode, *h_inode;
4215 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4218 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4220 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
4221 + if (unlikely(err)) {
4228 + si_read_lock(sb, AuLock_FLUSH);
4229 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4233 + ibusy.h_ino = 0; /* invalid */
4234 + inode = ilookup(sb, ibusy.ino);
4236 + || inode->i_ino == AUFS_ROOT_INO
4237 + || au_is_bad_inode(inode))
4240 + ii_read_lock_child(inode);
4241 + btop = au_ibtop(inode);
4242 + bbot = au_ibbot(inode);
4243 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4244 + h_inode = au_h_iptr(inode, ibusy.bindex);
4245 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4246 + ibusy.h_ino = h_inode->i_ino;
4248 + ii_read_unlock(inode);
4252 + si_read_unlock(sb);
4254 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4255 + if (unlikely(err)) {
4264 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4266 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4269 +#ifdef CONFIG_COMPAT
4270 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4272 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4276 +/* ---------------------------------------------------------------------- */
4279 + * change a branch permission
4282 +static void au_warn_ima(void)
4285 + /* since it doesn't support mark_files_ro() */
4286 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4290 +static int do_need_sigen_inc(int a, int b)
4292 + return au_br_whable(a) && !au_br_whable(b);
4295 +static int need_sigen_inc(int old, int new)
4297 + return do_need_sigen_inc(old, new)
4298 + || do_need_sigen_inc(new, old);
4301 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4304 + unsigned int mnt_flags;
4305 + unsigned long long ull, max;
4306 + aufs_bindex_t br_id;
4307 + unsigned char verbose, writer;
4308 + struct file *file, *hf, **array;
4309 + struct au_hfile *hfile;
4310 + struct inode *h_inode;
4312 + mnt_flags = au_mntflags(sb);
4313 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4315 + array = au_farray_alloc(sb, &max);
4316 + err = PTR_ERR(array);
4317 + if (IS_ERR(array))
4321 + br_id = au_sbr_id(sb, bindex);
4322 + for (ull = 0; ull < max; ull++) {
4323 + file = array[ull];
4324 + if (unlikely(!file))
4327 + /* AuDbg("%pD\n", file); */
4328 + fi_read_lock(file);
4329 + if (unlikely(au_test_mmapped(file))) {
4331 + AuVerbose(verbose, "mmapped %pD\n", file);
4333 + FiMustNoWaiters(file);
4334 + fi_read_unlock(file);
4338 + hfile = &au_fi(file)->fi_htop;
4339 + hf = hfile->hf_file;
4340 + if (!d_is_reg(file->f_path.dentry)
4341 + || !(file->f_mode & FMODE_WRITE)
4342 + || hfile->hf_br->br_id != br_id
4343 + || !(hf->f_mode & FMODE_WRITE))
4344 + array[ull] = NULL;
4350 + FiMustNoWaiters(file);
4351 + fi_read_unlock(file);
4359 + for (ull = 0; ull < max; ull++) {
4360 + file = array[ull];
4364 + /* todo: already flushed? */
4366 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4367 + * approach which resets f_mode and calls mnt_drop_write() and
4368 + * file_release_write() for each file, because the branch
4369 + * attribute in aufs world is totally different from the native
4372 + /* fi_read_lock(file); */
4373 + hfile = &au_fi(file)->fi_htop;
4374 + hf = hfile->hf_file;
4375 + /* fi_read_unlock(file); */
4376 + spin_lock(&hf->f_lock);
4377 + writer = !!(hf->f_mode & FMODE_WRITER);
4378 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4379 + spin_unlock(&hf->f_lock);
4381 + h_inode = file_inode(hf);
4382 + if (hf->f_mode & FMODE_READ)
4383 + i_readcount_inc(h_inode);
4384 + put_write_access(h_inode);
4385 + __mnt_drop_write(hf->f_path.mnt);
4390 + au_farray_free(array, max);
4396 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4400 + aufs_bindex_t bindex;
4401 + struct dentry *root;
4402 + struct au_branch *br;
4403 + struct au_br_fhsm *bf;
4405 + root = sb->s_root;
4406 + bindex = au_find_dbindex(root, mod->h_root);
4409 + return 0; /* success */
4411 + pr_err("%s no such branch\n", mod->path);
4414 + AuDbg("bindex b%d\n", bindex);
4416 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4417 + if (unlikely(err))
4420 + br = au_sbr(sb, bindex);
4421 + AuDebugOn(mod->h_root != au_br_dentry(br));
4422 + if (br->br_perm == mod->perm)
4423 + return 0; /* success */
4425 + /* pre-allocate for non-fhsm --> fhsm */
4427 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4428 + err = au_fhsm_br_alloc(br);
4429 + if (unlikely(err))
4432 + br->br_fhsm = NULL;
4435 + if (au_br_writable(br->br_perm)) {
4436 + /* remove whiteout base */
4437 + err = au_br_init_wh(sb, br, mod->perm);
4438 + if (unlikely(err))
4441 + if (!au_br_writable(mod->perm)) {
4442 + /* rw --> ro, file might be mmapped */
4443 + DiMustNoWaiters(root);
4444 + IiMustNoWaiters(d_inode(root));
4445 + di_write_unlock(root);
4446 + err = au_br_mod_files_ro(sb, bindex);
4447 + /* aufs_write_lock() calls ..._child() */
4448 + di_write_lock_child(root);
4450 + if (unlikely(err)) {
4452 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4455 + rerr = au_wbr_init(br, sb, br->br_perm);
4456 + if (unlikely(rerr)) {
4457 + AuIOErr("nested error %d (%d)\n",
4459 + br->br_perm = mod->perm;
4463 + } else if (au_br_writable(mod->perm)) {
4466 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4468 + err = au_wbr_init(br, sb, mod->perm);
4469 + if (unlikely(err)) {
4470 + au_kfree_rcu(br->br_wbr);
4471 + br->br_wbr = NULL;
4475 + if (unlikely(err))
4478 + if (au_br_fhsm(br->br_perm)) {
4479 + if (!au_br_fhsm(mod->perm)) {
4480 + /* fhsm --> non-fhsm */
4481 + au_br_fhsm_fin(br->br_fhsm);
4482 + au_kfree_rcu(br->br_fhsm);
4483 + br->br_fhsm = NULL;
4485 + } else if (au_br_fhsm(mod->perm))
4486 + /* non-fhsm --> fhsm */
4489 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4490 + br->br_perm = mod->perm;
4491 + goto out; /* success */
4494 + au_kfree_try_rcu(bf);
4500 +/* ---------------------------------------------------------------------- */
4502 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4505 + struct kstatfs kstfs;
4507 + err = vfs_statfs(&br->br_path, &kstfs);
4509 + stfs->f_blocks = kstfs.f_blocks;
4510 + stfs->f_bavail = kstfs.f_bavail;
4511 + stfs->f_files = kstfs.f_files;
4512 + stfs->f_ffree = kstfs.f_ffree;
4517 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4518 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4519 +++ linux/fs/aufs/branch.h 2021-02-22 23:30:37.699347580 +0100
4521 +/* SPDX-License-Identifier: GPL-2.0 */
4523 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4525 + * This program, aufs is free software; you can redistribute it and/or modify
4526 + * it under the terms of the GNU General Public License as published by
4527 + * the Free Software Foundation; either version 2 of the License, or
4528 + * (at your option) any later version.
4530 + * This program is distributed in the hope that it will be useful,
4531 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4532 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4533 + * GNU General Public License for more details.
4535 + * You should have received a copy of the GNU General Public License
4536 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4540 + * branch filesystems and xino for them
4543 +#ifndef __AUFS_BRANCH_H__
4544 +#define __AUFS_BRANCH_H__
4548 +#include <linux/mount.h>
4549 +#include "dirren.h"
4555 +/* ---------------------------------------------------------------------- */
4559 + struct file **xi_file;
4560 + unsigned int xi_nfile;
4566 + /* reserved for future use */
4567 + /* unsigned long *bitmap; */
4568 + wait_queue_head_t wqh;
4571 + struct mutex xi_mtx; /* protects xi_file array */
4572 + struct hlist_bl_head xi_writing;
4574 + atomic_t xi_truncating;
4576 + struct kref xi_kref;
4579 +/* File-based Hierarchical Storage Management */
4580 +struct au_br_fhsm {
4581 +#ifdef CONFIG_AUFS_FHSM
4582 + struct mutex bf_lock;
4583 + unsigned long bf_jiffy;
4584 + struct aufs_stfs bf_stfs;
4589 +/* members for writable branch only */
4590 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4592 + struct au_rwsem wbr_wh_rwsem;
4593 + struct dentry *wbr_wh[AuBrWh_Last];
4594 + atomic_t wbr_wh_running;
4595 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4596 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4597 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4600 + unsigned long long wbr_bytes;
4603 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4604 +#define AuBrDynOp (AuDyLast * 4)
4606 +#ifdef CONFIG_AUFS_HFSNOTIFY
4607 +/* support for asynchronous destruction */
4608 +struct au_br_hfsnotify {
4609 + struct fsnotify_group *hfsn_group;
4613 +/* sysfs entries */
4614 +struct au_brsysfs {
4616 + struct attribute attr;
4625 +/* protected by superblock rwsem */
4627 + struct au_xino *br_xino;
4629 + aufs_bindex_t br_id;
4632 + struct path br_path;
4633 + spinlock_t br_dykey_lock;
4634 + struct au_dykey *br_dykey[AuBrDynOp];
4635 + au_lcnt_t br_nfiles; /* opened files */
4636 + au_lcnt_t br_count; /* in-use for other */
4638 + struct au_wbr *br_wbr;
4639 + struct au_br_fhsm *br_fhsm;
4641 +#ifdef CONFIG_AUFS_HFSNOTIFY
4642 + struct au_br_hfsnotify *br_hfsn;
4645 +#ifdef CONFIG_SYSFS
4646 + /* entries under sysfs per mount-point */
4647 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4650 +#ifdef CONFIG_DEBUG_FS
4651 + struct dentry *br_dbgaufs; /* xino */
4654 + struct au_dr_br br_dirren;
4657 +/* ---------------------------------------------------------------------- */
4659 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4661 + return br->br_path.mnt;
4664 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4666 + return br->br_path.dentry;
4669 +static inline struct super_block *au_br_sb(struct au_branch *br)
4671 + return au_br_mnt(br)->mnt_sb;
4674 +static inline int au_br_rdonly(struct au_branch *br)
4676 + return (sb_rdonly(au_br_sb(br))
4677 + || !au_br_writable(br->br_perm))
4681 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4683 +#ifdef CONFIG_AUFS_HNOTIFY
4684 + return !(brperm & AuBrPerm_RR);
4690 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4692 + int err, exec_flag;
4695 + exec_flag = oflag & __FMODE_EXEC;
4696 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4702 +static inline void au_xino_get(struct au_branch *br)
4704 + struct au_xino *xi;
4708 + kref_get(&xi->xi_kref);
4711 +static inline int au_xino_count(struct au_branch *br)
4714 + struct au_xino *xi;
4719 + v = kref_read(&xi->xi_kref);
4724 +/* ---------------------------------------------------------------------- */
4728 +void au_br_free(struct au_sbinfo *sinfo);
4729 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4731 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4733 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4734 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4735 +#ifdef CONFIG_COMPAT
4736 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4739 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4742 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4745 +static const loff_t au_loff_max = LLONG_MAX;
4747 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4748 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4750 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4751 + struct file *copy_src);
4753 + struct au_xino *xi; /* switch between xino and xigen */
4755 + struct path *base;
4756 + struct file *copy_src;
4758 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4760 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4762 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4764 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4766 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4767 + size_t size, loff_t *pos);
4769 +int au_xib_trunc(struct super_block *sb);
4770 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4772 +struct au_xino *au_xino_alloc(unsigned int nfile);
4773 +int au_xino_put(struct au_branch *br);
4774 +struct file *au_xino_file1(struct au_xino *xi);
4776 +struct au_opt_xino;
4777 +void au_xino_clr(struct super_block *sb);
4778 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4779 +struct file *au_xino_def(struct super_block *sb);
4780 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4781 + struct path *base);
4783 +ino_t au_xino_new_ino(struct super_block *sb);
4784 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4786 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4787 + ino_t h_ino, int idx);
4788 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4791 +int au_xino_path(struct seq_file *seq, struct file *file);
4793 +/* ---------------------------------------------------------------------- */
4795 +/* @idx is signed to accept -1 meaning the first file */
4796 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4798 + struct file *file;
4805 + if (idx < xi->xi_nfile)
4806 + file = xi->xi_file[idx];
4808 + file = au_xino_file1(xi);
4814 +/* ---------------------------------------------------------------------- */
4816 +/* Superblock to branch */
4818 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4820 + return au_sbr(sb, bindex)->br_id;
4824 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4826 + return au_br_mnt(au_sbr(sb, bindex));
4830 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4832 + return au_br_sb(au_sbr(sb, bindex));
4835 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4837 + return au_sbr(sb, bindex)->br_perm;
4840 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4842 + return au_br_whable(au_sbr_perm(sb, bindex));
4845 +/* ---------------------------------------------------------------------- */
4847 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4848 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4849 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4850 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4852 +#define wbr_wh_read_trylock_nested(wbr) \
4853 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4854 +#define wbr_wh_write_trylock_nested(wbr) \
4855 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4858 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4859 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4860 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4862 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4863 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4864 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4866 +/* ---------------------------------------------------------------------- */
4868 +#ifdef CONFIG_AUFS_FHSM
4869 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4871 + mutex_init(&brfhsm->bf_lock);
4872 + brfhsm->bf_jiffy = 0;
4873 + brfhsm->bf_readable = 0;
4876 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4878 + mutex_destroy(&brfhsm->bf_lock);
4881 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4882 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4885 +#endif /* __KERNEL__ */
4886 +#endif /* __AUFS_BRANCH_H__ */
4887 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4888 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4889 +++ linux/fs/aufs/conf.mk 2021-02-22 23:30:37.699347580 +0100
4891 +# SPDX-License-Identifier: GPL-2.0
4893 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4897 +AuConfStr += ${1}=${${1}}
4901 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4903 + HNOTIFY HFSNOTIFY \
4915 +$(foreach i, ${AuConfAll}, \
4916 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4918 +AuConfName = ${obj}/conf.str
4919 +${AuConfName}.tmp: FORCE
4920 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4921 +${AuConfName}: ${AuConfName}.tmp
4922 + @diff -q $< $@ > /dev/null 2>&1 || { \
4923 + echo ' GEN ' $@; \
4927 +clean-files += ${AuConfName} ${AuConfName}.tmp
4928 +${obj}/sysfs.o: ${AuConfName}
4930 +-include ${srctree}/${src}/conf_priv.mk
4931 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4932 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4933 +++ linux/fs/aufs/cpup.c 2021-02-22 23:30:37.699347580 +0100
4935 +// SPDX-License-Identifier: GPL-2.0
4937 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4939 + * This program, aufs is free software; you can redistribute it and/or modify
4940 + * it under the terms of the GNU General Public License as published by
4941 + * the Free Software Foundation; either version 2 of the License, or
4942 + * (at your option) any later version.
4944 + * This program is distributed in the hope that it will be useful,
4945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4947 + * GNU General Public License for more details.
4949 + * You should have received a copy of the GNU General Public License
4950 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4954 + * copy-up functions, see wbr_policy.c for copy-down
4957 +#include <linux/fs_stack.h>
4958 +#include <linux/mm.h>
4959 +#include <linux/task_work.h>
4962 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4964 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4965 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4967 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4969 + dst->i_flags |= iflags & ~mask;
4970 + if (au_test_fs_notime(dst->i_sb))
4971 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4974 +void au_cpup_attr_timesizes(struct inode *inode)
4976 + struct inode *h_inode;
4978 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4979 + fsstack_copy_attr_times(inode, h_inode);
4980 + fsstack_copy_inode_size(inode, h_inode);
4983 +void au_cpup_attr_nlink(struct inode *inode, int force)
4985 + struct inode *h_inode;
4986 + struct super_block *sb;
4987 + aufs_bindex_t bindex, bbot;
4990 + bindex = au_ibtop(inode);
4991 + h_inode = au_h_iptr(inode, bindex);
4993 + && !S_ISDIR(h_inode->i_mode)
4994 + && au_opt_test(au_mntflags(sb), PLINK)
4995 + && au_plink_test(inode))
4999 + * 0 can happen in revalidating.
5000 + * h_inode->i_mutex may not be held here, but it is harmless since once
5001 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
5003 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
5004 + * the incorrect link count.
5006 + set_nlink(inode, h_inode->i_nlink);
5009 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
5010 + * it may includes whplink directory.
5012 + if (S_ISDIR(h_inode->i_mode)) {
5013 + bbot = au_ibbot(inode);
5014 + for (bindex++; bindex <= bbot; bindex++) {
5015 + h_inode = au_h_iptr(inode, bindex);
5017 + au_add_nlink(inode, h_inode);
5022 +void au_cpup_attr_changeable(struct inode *inode)
5024 + struct inode *h_inode;
5026 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5027 + inode->i_mode = h_inode->i_mode;
5028 + inode->i_uid = h_inode->i_uid;
5029 + inode->i_gid = h_inode->i_gid;
5030 + au_cpup_attr_timesizes(inode);
5031 + au_cpup_attr_flags(inode, h_inode->i_flags);
5034 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
5036 + struct au_iinfo *iinfo = au_ii(inode);
5038 + IiMustWriteLock(inode);
5040 + iinfo->ii_higen = h_inode->i_generation;
5041 + iinfo->ii_hsb1 = h_inode->i_sb;
5044 +void au_cpup_attr_all(struct inode *inode, int force)
5046 + struct inode *h_inode;
5048 + h_inode = au_h_iptr(inode, au_ibtop(inode));
5049 + au_cpup_attr_changeable(inode);
5050 + if (inode->i_nlink > 0)
5051 + au_cpup_attr_nlink(inode, force);
5052 + inode->i_rdev = h_inode->i_rdev;
5053 + inode->i_blkbits = h_inode->i_blkbits;
5054 + au_cpup_igen(inode, h_inode);
5057 +/* ---------------------------------------------------------------------- */
5059 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
5061 +/* keep the timestamps of the parent dir when cpup */
5062 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5063 + struct path *h_path)
5065 + struct inode *h_inode;
5067 + dt->dt_dentry = dentry;
5068 + dt->dt_h_path = *h_path;
5069 + h_inode = d_inode(h_path->dentry);
5070 + dt->dt_atime = h_inode->i_atime;
5071 + dt->dt_mtime = h_inode->i_mtime;
5075 +void au_dtime_revert(struct au_dtime *dt)
5077 + struct iattr attr;
5080 + attr.ia_atime = dt->dt_atime;
5081 + attr.ia_mtime = dt->dt_mtime;
5082 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
5083 + | ATTR_ATIME | ATTR_ATIME_SET;
5085 + /* no delegation since this is a directory */
5086 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
5087 + if (unlikely(err))
5088 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
5091 +/* ---------------------------------------------------------------------- */
5093 +/* internal use only */
5094 +struct au_cpup_reg_attr {
5097 + unsigned int iflags; /* inode->i_flags */
5100 +static noinline_for_stack
5101 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
5102 + struct au_cpup_reg_attr *h_src_attr)
5104 + int err, sbits, icex;
5105 + unsigned int mnt_flags;
5106 + unsigned char verbose;
5108 + struct path h_path;
5109 + struct inode *h_isrc, *h_idst;
5110 + struct kstat *h_st;
5111 + struct au_branch *br;
5113 + h_path.dentry = au_h_dptr(dst, bindex);
5114 + h_idst = d_inode(h_path.dentry);
5115 + br = au_sbr(dst->d_sb, bindex);
5116 + h_path.mnt = au_br_mnt(br);
5117 + h_isrc = d_inode(h_src);
5118 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
5119 + | ATTR_ATIME | ATTR_MTIME
5120 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
5121 + if (h_src_attr && h_src_attr->valid) {
5122 + h_st = &h_src_attr->st;
5123 + ia.ia_uid = h_st->uid;
5124 + ia.ia_gid = h_st->gid;
5125 + ia.ia_atime = h_st->atime;
5126 + ia.ia_mtime = h_st->mtime;
5127 + if (h_idst->i_mode != h_st->mode
5128 + && !S_ISLNK(h_idst->i_mode)) {
5129 + ia.ia_valid |= ATTR_MODE;
5130 + ia.ia_mode = h_st->mode;
5132 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
5133 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
5135 + ia.ia_uid = h_isrc->i_uid;
5136 + ia.ia_gid = h_isrc->i_gid;
5137 + ia.ia_atime = h_isrc->i_atime;
5138 + ia.ia_mtime = h_isrc->i_mtime;
5139 + if (h_idst->i_mode != h_isrc->i_mode
5140 + && !S_ISLNK(h_idst->i_mode)) {
5141 + ia.ia_valid |= ATTR_MODE;
5142 + ia.ia_mode = h_isrc->i_mode;
5144 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5145 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5147 + /* no delegation since it is just created */
5148 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5150 + /* is this nfs only? */
5151 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5152 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5153 + ia.ia_mode = h_isrc->i_mode;
5154 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5157 + icex = br->br_perm & AuBrAttr_ICEX;
5159 + mnt_flags = au_mntflags(dst->d_sb);
5160 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5161 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5167 +/* ---------------------------------------------------------------------- */
5169 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5170 + char *buf, unsigned long blksize)
5173 + size_t sz, rbytes, wbytes;
5174 + unsigned char all_zero;
5176 + struct inode *h_inode;
5177 + /* reduce stack usage */
5180 + zp = page_address(ZERO_PAGE(0));
5181 + if (unlikely(!zp))
5182 + return -ENOMEM; /* possible? */
5187 + AuDbg("len %lld\n", len);
5189 + if (len < blksize)
5193 + /* todo: signal_pending? */
5194 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5195 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5198 + if (unlikely(err < 0))
5202 + if (len >= rbytes && rbytes == blksize)
5203 + all_zero = !memcmp(buf, zp, rbytes);
5210 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5212 + /* todo: signal_pending? */
5213 + if (unlikely(err == -EAGAIN || err == -EINTR))
5215 + if (unlikely(err < 0))
5220 + if (unlikely(err < 0))
5226 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5228 + if (unlikely(res < 0))
5235 + /* the last block may be a hole */
5236 + if (!err && all_zero) {
5237 + AuLabel(last hole);
5240 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5241 + /* nfs requires this step to make last hole */
5242 + /* is this only nfs? */
5244 + /* todo: signal_pending? */
5245 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5246 + } while (err == -EAGAIN || err == -EINTR);
5253 + ia->ia_size = dst->f_pos;
5254 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5255 + ia->ia_file = dst;
5256 + h_inode = file_inode(dst);
5257 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5258 + /* no delegation since it is just created */
5259 + err = vfsub_notify_change(&dst->f_path, ia,
5260 + /*delegated*/NULL);
5261 + inode_unlock(h_inode);
5268 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5271 + unsigned long blksize;
5272 + unsigned char do_kfree;
5274 + struct super_block *h_sb;
5277 + h_sb = file_inode(dst)->i_sb;
5278 + blksize = h_sb->s_blocksize;
5279 + if (!blksize || PAGE_SIZE < blksize)
5280 + blksize = PAGE_SIZE;
5281 + AuDbg("blksize %lu\n", blksize);
5282 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5284 + buf = kmalloc(blksize, GFP_NOFS);
5286 + buf = (void *)__get_free_page(GFP_NOFS);
5287 + if (unlikely(!buf))
5290 + if (len > (1 << 22))
5291 + AuDbg("copying a large file %lld\n", (long long)len);
5295 + err = au_do_copy_file(dst, src, len, buf, blksize);
5297 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5298 + au_kfree_do_rcu(buf);
5300 + free_page((unsigned long)buf);
5306 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5309 + struct super_block *h_src_sb;
5310 + struct inode *h_src_inode;
5312 + h_src_inode = file_inode(src);
5313 + h_src_sb = h_src_inode->i_sb;
5315 + /* XFS acquires inode_lock */
5316 + if (!au_test_xfs(h_src_sb))
5317 + err = au_copy_file(dst, src, len);
5319 + inode_unlock_shared(h_src_inode);
5320 + err = au_copy_file(dst, src, len);
5321 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5327 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5330 + struct super_block *h_src_sb;
5331 + struct inode *h_src_inode;
5333 + h_src_inode = file_inode(src);
5334 + h_src_sb = h_src_inode->i_sb;
5335 + if (h_src_sb != file_inode(dst)->i_sb
5336 + || !dst->f_op->clone_file_range) {
5337 + err = au_do_copy(dst, src, len);
5341 + if (!au_test_nfs(h_src_sb)) {
5342 + inode_unlock_shared(h_src_inode);
5343 + err = vfsub_clone_file_range(src, dst, len);
5344 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5346 + err = vfsub_clone_file_range(src, dst, len);
5347 + /* older XFS has a condition in cloning */
5348 + if (unlikely(err != -EOPNOTSUPP))
5351 + /* the backend fs on NFS may not support cloning */
5352 + err = au_do_copy(dst, src, len);
5360 + * to support a sparse file which is opened with O_APPEND,
5361 + * we need to close the file.
5363 +static int au_cp_regular(struct au_cp_generic *cpg)
5366 + enum { SRC, DST };
5368 + aufs_bindex_t bindex;
5369 + unsigned int flags;
5370 + struct dentry *dentry;
5372 + struct file *file;
5375 + .bindex = cpg->bsrc,
5376 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5379 + .bindex = cpg->bdst,
5380 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5381 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5384 + struct au_branch *br;
5385 + struct super_block *sb, *h_src_sb;
5386 + struct inode *h_src_inode;
5387 + struct task_struct *tsk = current;
5389 + /* bsrc branch can be ro/rw. */
5390 + sb = cpg->dentry->d_sb;
5392 + for (i = 0; i < 2; i++, f++) {
5393 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5394 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5395 + /*file*/NULL, f->force_wr);
5396 + if (IS_ERR(f->file)) {
5397 + err = PTR_ERR(f->file);
5405 + /* try stopping to update while we copyup */
5406 + h_src_inode = d_inode(file[SRC].dentry);
5407 + h_src_sb = h_src_inode->i_sb;
5408 + if (!au_test_nfs(h_src_sb))
5409 + IMustLock(h_src_inode);
5410 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5412 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5413 + if (tsk->flags & PF_KTHREAD)
5414 + __fput_sync(file[DST].file);
5416 + /* it happened actually */
5417 + fput(file[DST].file);
5420 + * we have to call both since we don't know which place the file
5424 + flush_delayed_fput();
5426 + br = au_sbr(sb, file[DST].bindex);
5427 + au_lcnt_dec(&br->br_nfiles);
5430 + fput(file[SRC].file);
5431 + br = au_sbr(sb, file[SRC].bindex);
5432 + au_lcnt_dec(&br->br_nfiles);
5437 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5438 + struct au_cpup_reg_attr *h_src_attr)
5442 + struct path h_path;
5443 + struct inode *h_src_inode, *h_dst_inode;
5446 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5447 + l = i_size_read(h_src_inode);
5448 + if (cpg->len == -1 || l < cpg->len)
5451 + /* try stopping to update while we are referencing */
5452 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5453 + au_pin_hdir_unlock(cpg->pin);
5455 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5456 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5457 + h_src_attr->iflags = h_src_inode->i_flags;
5458 + if (!au_test_nfs(h_src_inode->i_sb))
5459 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5461 + inode_unlock_shared(h_src_inode);
5462 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5463 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5465 + if (unlikely(err)) {
5466 + inode_unlock_shared(h_src_inode);
5469 + h_src_attr->valid = 1;
5470 + if (!au_test_nfs(h_src_inode->i_sb)) {
5471 + err = au_cp_regular(cpg);
5472 + inode_unlock_shared(h_src_inode);
5474 + inode_unlock_shared(h_src_inode);
5475 + err = au_cp_regular(cpg);
5477 + rerr = au_pin_hdir_relock(cpg->pin);
5481 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5482 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5483 + h_dst_inode = d_inode(h_path.dentry);
5484 + spin_lock(&h_dst_inode->i_lock);
5485 + h_dst_inode->i_state |= I_LINKABLE;
5486 + spin_unlock(&h_dst_inode->i_lock);
5493 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5494 + struct inode *h_dir)
5497 + mm_segment_t old_fs;
5504 + sym.k = (void *)__get_free_page(GFP_NOFS);
5505 + if (unlikely(!sym.k))
5508 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5509 + old_fs = get_fs();
5510 + set_fs(KERNEL_DS);
5511 + symlen = vfs_readlink(h_src, sym.u, PATH_MAX);
5516 + sym.k[symlen] = 0;
5517 + err = vfsub_symlink(h_dir, h_path, sym.k);
5519 + free_page((unsigned long)sym.k);
5526 + * regardless 'acl' option, reset all ACL.
5527 + * All ACL will be copied up later from the original entry on the lower branch.
5529 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5532 + struct dentry *h_dentry;
5533 + struct inode *h_inode;
5535 + h_dentry = h_path->dentry;
5536 + h_inode = d_inode(h_dentry);
5537 + /* forget_all_cached_acls(h_inode)); */
5538 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5540 + if (err == -EOPNOTSUPP)
5543 + err = vfsub_acl_chmod(h_inode, mode);
5549 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5550 + struct inode *h_dir, struct path *h_path)
5553 + struct inode *dir, *inode;
5555 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5557 + if (err == -EOPNOTSUPP)
5559 + if (unlikely(err))
5563 + * strange behaviour from the users view,
5564 + * particularly setattr case
5566 + dir = d_inode(dst_parent);
5567 + if (au_ibtop(dir) == cpg->bdst)
5568 + au_cpup_attr_nlink(dir, /*force*/1);
5569 + inode = d_inode(cpg->dentry);
5570 + au_cpup_attr_nlink(inode, /*force*/1);
5576 +static noinline_for_stack
5577 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5578 + struct au_cpup_reg_attr *h_src_attr)
5582 + unsigned int mnt_flags;
5583 + unsigned char isdir, isreg, force;
5584 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5585 + struct au_dtime dt;
5586 + struct path h_path;
5587 + struct dentry *h_src, *h_dst, *h_parent;
5588 + struct inode *h_inode, *h_dir;
5589 + struct super_block *sb;
5591 + /* bsrc branch can be ro/rw. */
5592 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5593 + h_inode = d_inode(h_src);
5594 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5596 + /* try stopping to be referenced while we are creating */
5597 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5598 + if (au_ftest_cpup(cpg->flags, RENAME))
5599 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5600 + AUFS_WH_PFX_LEN));
5601 + h_parent = h_dst->d_parent; /* dir inode is locked */
5602 + h_dir = d_inode(h_parent);
5604 + AuDebugOn(h_parent != h_dst->d_parent);
5606 + sb = cpg->dentry->d_sb;
5607 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5609 + h_path.dentry = h_parent;
5610 + au_dtime_store(&dt, dst_parent, &h_path);
5612 + h_path.dentry = h_dst;
5616 + mode = h_inode->i_mode;
5617 + switch (mode & S_IFMT) {
5620 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5622 + err = au_do_cpup_regular(cpg, h_src_attr);
5626 + err = vfsub_mkdir(h_dir, &h_path, mode);
5628 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5631 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5635 + AuDebugOn(!capable(CAP_MKNOD));
5639 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5642 + AuIOErr("Unknown inode type 0%o\n", mode);
5646 + err = au_reset_acl(h_dir, &h_path, mode);
5648 + mnt_flags = au_mntflags(sb);
5649 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5651 + && au_opt_test(mnt_flags, XINO)
5652 + && (h_inode->i_nlink == 1
5653 + || (h_inode->i_state & I_LINKABLE))
5654 + /* todo: unnecessary? */
5655 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5656 + && cpg->bdst < cpg->bsrc
5657 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5658 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5659 + /* ignore this error */
5664 + force = !!cpg->len;
5665 + if (cpg->len == -1)
5666 + force = !!i_size_read(h_inode);
5668 + au_fhsm_wrote(sb, cpg->bdst, force);
5672 + au_dtime_revert(&dt);
5676 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5679 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5680 + struct inode *h_dir;
5681 + aufs_bindex_t bdst;
5683 + dentry = cpg->dentry;
5685 + h_dentry = au_h_dptr(dentry, bdst);
5686 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5688 + au_set_h_dptr(dentry, bdst, NULL);
5689 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5691 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5692 + au_set_h_dptr(dentry, bdst, h_dentry);
5695 + parent = dget_parent(dentry);
5696 + h_parent = au_h_dptr(parent, bdst);
5698 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5699 + if (IS_ERR(h_path->dentry))
5700 + err = PTR_ERR(h_path->dentry);
5702 + if (unlikely(err))
5705 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5706 + h_dir = d_inode(h_parent);
5708 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5709 + /* no delegation since it is just created */
5710 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5712 + dput(h_path->dentry);
5719 + * copyup the @dentry from @bsrc to @bdst.
5720 + * the caller must set the both of lower dentries.
5721 + * @len is for truncating when it is -1 copyup the entire file.
5722 + * in link/rename cases, @dst_parent may be different from the real one.
5723 + * basic->bsrc can be larger than basic->bdst.
5724 + * aufs doesn't touch the credential so
5725 + * security_inode_copy_up{,_xattr}() are unnecessary.
5727 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5730 + aufs_bindex_t old_ibtop;
5731 + unsigned char isdir, plink;
5732 + struct dentry *h_src, *h_dst, *h_parent;
5733 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5734 + struct super_block *sb;
5735 + struct au_branch *br;
5736 + /* to reduce stack size */
5738 + struct au_dtime dt;
5739 + struct path h_path;
5740 + struct au_cpup_reg_attr h_src_attr;
5744 + a = kmalloc(sizeof(*a), GFP_NOFS);
5747 + a->h_src_attr.valid = 0;
5749 + sb = cpg->dentry->d_sb;
5750 + br = au_sbr(sb, cpg->bdst);
5751 + a->h_path.mnt = au_br_mnt(br);
5752 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5753 + h_parent = h_dst->d_parent; /* dir inode is locked */
5754 + h_dir = d_inode(h_parent);
5757 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5758 + inode = d_inode(cpg->dentry);
5761 + dst_parent = dget_parent(cpg->dentry);
5765 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5766 + dst_inode = au_h_iptr(inode, cpg->bdst);
5768 + if (unlikely(!plink)) {
5770 + AuIOErr("hi%lu(i%lu) exists on b%d "
5771 + "but plink is disabled\n",
5772 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5776 + if (dst_inode->i_nlink) {
5777 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5779 + h_src = au_plink_lkup(inode, cpg->bdst);
5780 + err = PTR_ERR(h_src);
5781 + if (IS_ERR(h_src))
5783 + if (unlikely(d_is_negative(h_src))) {
5785 + AuIOErr("i%lu exists on b%d "
5786 + "but not pseudo-linked\n",
5787 + inode->i_ino, cpg->bdst);
5793 + a->h_path.dentry = h_parent;
5794 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5797 + a->h_path.dentry = h_dst;
5799 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5800 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5801 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5803 + au_dtime_revert(&a->dt);
5804 + if (unlikely(err == -EWOULDBLOCK)) {
5805 + pr_warn("cannot retry for NFSv4 delegation"
5806 + " for an internal link\n");
5812 + /* todo: cpup_wh_file? */
5814 + au_update_ibrange(inode, /*do_put_zero*/1);
5817 + isdir = S_ISDIR(inode->i_mode);
5818 + old_ibtop = au_ibtop(inode);
5819 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5820 + if (unlikely(err))
5822 + dst_inode = d_inode(h_dst);
5823 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5824 + /* todo: necessary? */
5825 + /* au_pin_hdir_unlock(cpg->pin); */
5827 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5828 + if (unlikely(err)) {
5829 + /* todo: necessary? */
5830 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5831 + inode_unlock(dst_inode);
5835 + if (cpg->bdst < old_ibtop) {
5836 + if (S_ISREG(inode->i_mode)) {
5837 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5838 + if (unlikely(err)) {
5839 + /* ignore an error */
5840 + /* au_pin_hdir_relock(cpg->pin); */
5841 + inode_unlock(dst_inode);
5845 + au_set_ibtop(inode, cpg->bdst);
5847 + au_set_ibbot(inode, cpg->bdst);
5848 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5849 + au_hi_flags(inode, isdir));
5851 + /* todo: necessary? */
5852 + /* err = au_pin_hdir_relock(cpg->pin); */
5853 + inode_unlock(dst_inode);
5854 + if (unlikely(err))
5857 + src_inode = d_inode(h_src);
5859 + && (src_inode->i_nlink > 1
5860 + || src_inode->i_state & I_LINKABLE)
5862 + au_plink_append(inode, cpg->bdst, h_dst);
5864 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5865 + a->h_path.dentry = h_dst;
5866 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5869 + goto out_parent; /* success */
5873 + a->h_path.dentry = h_parent;
5874 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5875 + a->h_path.dentry = h_dst;
5877 + if (d_is_positive(h_dst)) {
5879 + /* no delegation since it is just created */
5880 + rerr = vfsub_unlink(h_dir, &a->h_path,
5881 + /*delegated*/NULL, /*force*/0);
5883 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5885 + au_dtime_revert(&a->dt);
5887 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5897 +#if 0 /* reserved */
5898 +struct au_cpup_single_args {
5900 + struct au_cp_generic *cpg;
5901 + struct dentry *dst_parent;
5904 +static void au_call_cpup_single(void *args)
5906 + struct au_cpup_single_args *a = args;
5908 + au_pin_hdir_acquire_nest(a->cpg->pin);
5909 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5910 + au_pin_hdir_release(a->cpg->pin);
5915 + * prevent SIGXFSZ in copy-up.
5916 + * testing CAP_MKNOD is for generic fs,
5917 + * but CAP_FSETID is for xfs only, currently.
5919 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5922 + struct super_block *sb;
5923 + struct inode *h_dir;
5926 + sb = au_pinned_parent(pin)->d_sb;
5927 + if (!au_wkq_test()
5928 + && (!au_sbi(sb)->si_plink_maint_pid
5929 + || au_plink_maint(sb, AuLock_NOPLM))) {
5930 + switch (mode & S_IFMT) {
5932 + /* no condition about RLIMIT_FSIZE and the file size */
5937 + do_sio = !capable(CAP_MKNOD);
5941 + do_sio = ((mode & (S_ISUID | S_ISGID))
5942 + && !capable(CAP_FSETID));
5943 + /* this workaround may be removed in the future */
5945 + h_dir = au_pinned_h_dir(pin);
5946 + do_sio = h_dir->i_mode & S_ISVTX;
5953 +#if 0 /* reserved */
5954 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5957 + struct dentry *h_dentry;
5959 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5960 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5961 + err = au_cpup_single(cpg, dst_parent);
5963 + struct au_cpup_single_args args = {
5966 + .dst_parent = dst_parent
5968 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5969 + if (unlikely(wkq_err))
5978 + * copyup the @dentry from the first active lower branch to @bdst,
5979 + * using au_cpup_single().
5981 +static int au_cpup_simple(struct au_cp_generic *cpg)
5984 + unsigned int flags_orig;
5985 + struct dentry *dentry;
5987 + AuDebugOn(cpg->bsrc < 0);
5989 + dentry = cpg->dentry;
5990 + DiMustWriteLock(dentry);
5992 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5994 + flags_orig = cpg->flags;
5995 + au_fset_cpup(cpg->flags, RENAME);
5996 + err = au_cpup_single(cpg, NULL);
5997 + cpg->flags = flags_orig;
5999 + return 0; /* success */
6002 + au_set_h_dptr(dentry, cpg->bdst, NULL);
6003 + au_set_dbtop(dentry, cpg->bsrc);
6009 +struct au_cpup_simple_args {
6011 + struct au_cp_generic *cpg;
6014 +static void au_call_cpup_simple(void *args)
6016 + struct au_cpup_simple_args *a = args;
6018 + au_pin_hdir_acquire_nest(a->cpg->pin);
6019 + *a->errp = au_cpup_simple(a->cpg);
6020 + au_pin_hdir_release(a->cpg->pin);
6023 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
6026 + struct dentry *dentry, *parent;
6027 + struct file *h_file;
6028 + struct inode *h_dir;
6030 + dentry = cpg->dentry;
6032 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
6033 + AuDebugOn(cpg->bsrc < 0);
6034 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
6035 + err = PTR_ERR(h_file);
6036 + if (IS_ERR(h_file))
6040 + parent = dget_parent(dentry);
6041 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
6042 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
6043 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6044 + err = au_cpup_simple(cpg);
6046 + struct au_cpup_simple_args args = {
6050 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
6051 + if (unlikely(wkq_err))
6057 + au_h_open_post(dentry, cpg->bsrc, h_file);
6063 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
6065 + aufs_bindex_t bsrc, bbot;
6066 + struct dentry *dentry, *h_dentry;
6068 + if (cpg->bsrc < 0) {
6069 + dentry = cpg->dentry;
6070 + bbot = au_dbbot(dentry);
6071 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
6072 + h_dentry = au_h_dptr(dentry, bsrc);
6074 + AuDebugOn(d_is_negative(h_dentry));
6078 + AuDebugOn(bsrc > bbot);
6081 + AuDebugOn(cpg->bsrc <= cpg->bdst);
6082 + return au_do_sio_cpup_simple(cpg);
6085 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
6087 + AuDebugOn(cpg->bdst <= cpg->bsrc);
6088 + return au_do_sio_cpup_simple(cpg);
6091 +/* ---------------------------------------------------------------------- */
6094 + * copyup the deleted file for writing.
6096 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
6097 + struct file *file)
6100 + unsigned int flags_orig;
6101 + aufs_bindex_t bsrc_orig;
6102 + struct au_dinfo *dinfo;
6104 + struct au_hdentry *hd;
6105 + struct dentry *h_dentry;
6108 + dinfo = au_di(cpg->dentry);
6109 + AuRwMustWriteLock(&dinfo->di_rwsem);
6111 + bsrc_orig = cpg->bsrc;
6112 + cpg->bsrc = dinfo->di_btop;
6113 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
6114 + hdst.h_dentry = hdst.hd->hd_dentry;
6115 + hdst.hd->hd_dentry = wh_dentry;
6116 + dinfo->di_btop = cpg->bdst;
6118 + hsrc.h_dentry = NULL;
6120 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
6121 + hsrc.h_dentry = hsrc.hd->hd_dentry;
6122 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
6124 + flags_orig = cpg->flags;
6125 + cpg->flags = !AuCpup_DTIME;
6126 + err = au_cpup_single(cpg, /*h_parent*/NULL);
6127 + cpg->flags = flags_orig;
6130 + err = au_reopen_nondir(file);
6131 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6133 + hdst.hd->hd_dentry = hdst.h_dentry;
6134 + dinfo->di_btop = cpg->bsrc;
6135 + cpg->bsrc = bsrc_orig;
6140 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6143 + aufs_bindex_t bdst;
6144 + struct au_dtime dt;
6145 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6146 + struct au_branch *br;
6147 + struct path h_path;
6149 + dentry = cpg->dentry;
6151 + br = au_sbr(dentry->d_sb, bdst);
6152 + parent = dget_parent(dentry);
6153 + h_parent = au_h_dptr(parent, bdst);
6154 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6155 + err = PTR_ERR(wh_dentry);
6156 + if (IS_ERR(wh_dentry))
6159 + h_path.dentry = h_parent;
6160 + h_path.mnt = au_br_mnt(br);
6161 + au_dtime_store(&dt, parent, &h_path);
6162 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6163 + if (unlikely(err))
6167 + h_path.dentry = wh_dentry;
6168 + if (!d_is_dir(wh_dentry)) {
6169 + /* no delegation since it is just created */
6170 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6171 + /*delegated*/NULL, /*force*/0);
6173 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6174 + if (unlikely(err)) {
6175 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6179 + au_dtime_revert(&dt);
6180 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6189 +struct au_cpup_wh_args {
6191 + struct au_cp_generic *cpg;
6192 + struct file *file;
6195 +static void au_call_cpup_wh(void *args)
6197 + struct au_cpup_wh_args *a = args;
6199 + au_pin_hdir_acquire_nest(a->cpg->pin);
6200 + *a->errp = au_cpup_wh(a->cpg, a->file);
6201 + au_pin_hdir_release(a->cpg->pin);
6204 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6207 + aufs_bindex_t bdst;
6208 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6209 + struct inode *dir, *h_dir, *h_tmpdir;
6210 + struct au_wbr *wbr;
6211 + struct au_pin wh_pin, *pin_orig;
6213 + dentry = cpg->dentry;
6215 + parent = dget_parent(dentry);
6216 + dir = d_inode(parent);
6219 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6222 + if (!h_dir->i_nlink) {
6223 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6224 + h_orph = wbr->wbr_orph;
6226 + h_parent = dget(au_h_dptr(parent, bdst));
6227 + au_set_h_dptr(parent, bdst, dget(h_orph));
6228 + h_tmpdir = d_inode(h_orph);
6229 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6231 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6232 + /* todo: au_h_open_pre()? */
6234 + pin_orig = cpg->pin;
6235 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6236 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6237 + cpg->pin = &wh_pin;
6240 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6241 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6242 + err = au_cpup_wh(cpg, file);
6244 + struct au_cpup_wh_args args = {
6249 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6250 + if (unlikely(wkq_err))
6255 + inode_unlock(h_tmpdir);
6256 + /* todo: au_h_open_post()? */
6257 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6258 + au_set_h_dptr(parent, bdst, h_parent);
6259 + AuDebugOn(!pin_orig);
6260 + cpg->pin = pin_orig;
6268 +/* ---------------------------------------------------------------------- */
6271 + * generic routine for both of copy-up and copy-down.
6273 +/* cf. revalidate function in file.c */
6274 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6275 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6276 + struct au_pin *pin,
6277 + struct dentry *h_parent, void *arg),
6281 + struct au_pin pin;
6282 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6285 + parent = dget_parent(dentry);
6286 + if (IS_ROOT(parent))
6289 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6290 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6292 + /* do not use au_dpage */
6293 + real_parent = parent;
6296 + parent = dget_parent(dentry);
6297 + h_parent = au_h_dptr(parent, bdst);
6299 + goto out; /* success */
6301 + /* find top dir which is necessary to cpup */
6305 + parent = dget_parent(d);
6306 + di_read_lock_parent3(parent, !AuLock_IR);
6307 + h_parent = au_h_dptr(parent, bdst);
6308 + di_read_unlock(parent, !AuLock_IR);
6309 + } while (!h_parent);
6311 + if (d != real_parent)
6312 + di_write_lock_child3(d);
6314 + /* somebody else might create while we were sleeping */
6315 + h_dentry = au_h_dptr(d, bdst);
6316 + if (!h_dentry || d_is_negative(h_dentry)) {
6318 + au_update_dbtop(d);
6320 + au_pin_set_dentry(&pin, d);
6321 + err = au_do_pin(&pin);
6323 + err = cp(d, bdst, &pin, h_parent, arg);
6328 + if (d != real_parent)
6329 + di_write_unlock(d);
6330 + if (unlikely(err))
6339 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6340 + struct au_pin *pin,
6341 + struct dentry *h_parent __maybe_unused,
6342 + void *arg __maybe_unused)
6344 + struct au_cp_generic cpg = {
6350 + .flags = AuCpup_DTIME
6352 + return au_sio_cpup_simple(&cpg);
6355 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6357 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6360 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6363 + struct dentry *parent;
6364 + struct inode *dir;
6366 + parent = dget_parent(dentry);
6367 + dir = d_inode(parent);
6369 + if (au_h_iptr(dir, bdst))
6372 + di_read_unlock(parent, AuLock_IR);
6373 + di_write_lock_parent(parent);
6374 + /* someone else might change our inode while we were sleeping */
6375 + if (!au_h_iptr(dir, bdst))
6376 + err = au_cpup_dirs(dentry, bdst);
6377 + di_downgrade_lock(parent, AuLock_IR);
6383 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6384 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6385 +++ linux/fs/aufs/cpup.h 2021-02-22 23:30:37.699347580 +0100
6387 +/* SPDX-License-Identifier: GPL-2.0 */
6389 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6391 + * This program, aufs is free software; you can redistribute it and/or modify
6392 + * it under the terms of the GNU General Public License as published by
6393 + * the Free Software Foundation; either version 2 of the License, or
6394 + * (at your option) any later version.
6396 + * This program is distributed in the hope that it will be useful,
6397 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6398 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6399 + * GNU General Public License for more details.
6401 + * You should have received a copy of the GNU General Public License
6402 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6406 + * copy-up/down functions
6409 +#ifndef __AUFS_CPUP_H__
6410 +#define __AUFS_CPUP_H__
6414 +#include <linux/path.h>
6420 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6421 +void au_cpup_attr_timesizes(struct inode *inode);
6422 +void au_cpup_attr_nlink(struct inode *inode, int force);
6423 +void au_cpup_attr_changeable(struct inode *inode);
6424 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6425 +void au_cpup_attr_all(struct inode *inode, int force);
6427 +/* ---------------------------------------------------------------------- */
6429 +struct au_cp_generic {
6430 + struct dentry *dentry;
6431 + aufs_bindex_t bdst, bsrc;
6433 + struct au_pin *pin;
6434 + unsigned int flags;
6438 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6439 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6441 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6442 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6444 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6446 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6447 + the branch is marked as RO */
6449 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6450 +#undef AuCpup_HOPEN
6451 +#define AuCpup_HOPEN 0
6454 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6455 +#define au_fset_cpup(flags, name) \
6456 + do { (flags) |= AuCpup_##name; } while (0)
6457 +#define au_fclr_cpup(flags, name) \
6458 + do { (flags) &= ~AuCpup_##name; } while (0)
6460 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6461 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6462 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6463 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6465 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6466 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6467 + struct au_pin *pin,
6468 + struct dentry *h_parent, void *arg),
6470 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6471 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6473 +/* ---------------------------------------------------------------------- */
6475 +/* keep timestamps when copyup */
6477 + struct dentry *dt_dentry;
6478 + struct path dt_h_path;
6479 + struct timespec64 dt_atime, dt_mtime;
6481 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6482 + struct path *h_path);
6483 +void au_dtime_revert(struct au_dtime *dt);
6485 +#endif /* __KERNEL__ */
6486 +#endif /* __AUFS_CPUP_H__ */
6487 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6488 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6489 +++ linux/fs/aufs/dbgaufs.c 2021-02-22 23:30:37.699347580 +0100
6491 +// SPDX-License-Identifier: GPL-2.0
6493 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6495 + * This program, aufs is free software; you can redistribute it and/or modify
6496 + * it under the terms of the GNU General Public License as published by
6497 + * the Free Software Foundation; either version 2 of the License, or
6498 + * (at your option) any later version.
6500 + * This program is distributed in the hope that it will be useful,
6501 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6502 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6503 + * GNU General Public License for more details.
6505 + * You should have received a copy of the GNU General Public License
6506 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6510 + * debugfs interface
6513 +#include <linux/debugfs.h>
6516 +#ifndef CONFIG_SYSFS
6517 +#error DEBUG_FS depends upon SYSFS
6520 +static struct dentry *dbgaufs;
6521 +static const mode_t dbgaufs_mode = 0444;
6523 +/* 20 is max digits length of ulong 64 */
6524 +struct dbgaufs_arg {
6530 + * common function for all XINO files
6532 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6533 + struct file *file)
6537 + p = file->private_data;
6539 + /* this is struct dbgaufs_arg */
6540 + AuDebugOn(!au_kfree_sz_test(p));
6541 + au_kfree_do_rcu(p);
6546 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6551 + struct dbgaufs_arg *p;
6554 + p = kmalloc(sizeof(*p), GFP_NOFS);
6560 + file->private_data = p;
6564 + err = vfsub_getattr(&xf->f_path, &st);
6568 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6569 + cnt, st.blocks, st.blksize,
6570 + (long long)st.size);
6572 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6573 + st.blocks, st.blksize,
6574 + (long long)st.size);
6575 + AuDebugOn(p->n >= sizeof(p->a));
6577 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6585 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6586 + size_t count, loff_t *ppos)
6588 + struct dbgaufs_arg *p;
6590 + p = file->private_data;
6591 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6594 +/* ---------------------------------------------------------------------- */
6596 +struct dbgaufs_plink_arg {
6601 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6602 + struct file *file)
6604 + free_page((unsigned long)file->private_data);
6608 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6610 + int err, i, limit;
6611 + unsigned long n, sum;
6612 + struct dbgaufs_plink_arg *p;
6613 + struct au_sbinfo *sbinfo;
6614 + struct super_block *sb;
6615 + struct hlist_bl_head *hbl;
6618 + p = (void *)get_zeroed_page(GFP_NOFS);
6623 + sbinfo = inode->i_private;
6624 + sb = sbinfo->si_sb;
6625 + si_noflush_read_lock(sb);
6626 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6627 + limit = PAGE_SIZE - sizeof(p->n);
6629 + /* the number of buckets */
6630 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6635 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6637 + n = au_hbl_count(hbl);
6640 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6643 + if (unlikely(limit <= 0))
6646 + p->a[p->n - 1] = '\n';
6648 + /* the sum of plinks */
6649 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6652 + if (unlikely(limit <= 0))
6655 +#define str "1\n0\n0\n"
6656 + p->n = sizeof(str) - 1;
6657 + strcpy(p->a, str);
6660 + si_read_unlock(sb);
6663 + file->private_data = p;
6664 + goto out; /* success */
6667 + free_page((unsigned long)p);
6672 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6673 + size_t count, loff_t *ppos)
6675 + struct dbgaufs_plink_arg *p;
6677 + p = file->private_data;
6678 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6681 +static const struct file_operations dbgaufs_plink_fop = {
6682 + .owner = THIS_MODULE,
6683 + .open = dbgaufs_plink_open,
6684 + .release = dbgaufs_plink_release,
6685 + .read = dbgaufs_plink_read
6688 +/* ---------------------------------------------------------------------- */
6690 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6693 + struct au_sbinfo *sbinfo;
6694 + struct super_block *sb;
6696 + sbinfo = inode->i_private;
6697 + sb = sbinfo->si_sb;
6698 + si_noflush_read_lock(sb);
6699 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6700 + si_read_unlock(sb);
6704 +static const struct file_operations dbgaufs_xib_fop = {
6705 + .owner = THIS_MODULE,
6706 + .open = dbgaufs_xib_open,
6707 + .release = dbgaufs_xi_release,
6708 + .read = dbgaufs_xi_read
6711 +/* ---------------------------------------------------------------------- */
6713 +#define DbgaufsXi_PREFIX "xi"
6715 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6719 + aufs_bindex_t bindex;
6720 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6721 + struct au_sbinfo *sbinfo;
6722 + struct super_block *sb;
6723 + struct au_xino *xi;
6725 + struct qstr *name;
6726 + struct au_branch *br;
6729 + name = &file->f_path.dentry->d_name;
6730 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6731 + || memcmp(name->name, DbgaufsXi_PREFIX,
6732 + sizeof(DbgaufsXi_PREFIX) - 1)))
6735 + AuDebugOn(name->len >= sizeof(a));
6736 + memcpy(a, name->name, name->len);
6737 + a[name->len] = '\0';
6738 + p = strchr(a, '-');
6741 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6742 + if (unlikely(err))
6747 + err = kstrtol(p + 1, 10, &l);
6748 + if (unlikely(err))
6754 + sbinfo = inode->i_private;
6755 + sb = sbinfo->si_sb;
6756 + si_noflush_read_lock(sb);
6757 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6759 + br = au_sbr(sb, bindex);
6761 + if (unlikely(idx >= xi->xi_nfile))
6763 + xf = au_xino_file(xi, idx);
6765 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6766 + au_xino_count(br));
6769 + si_read_unlock(sb);
6775 +static const struct file_operations dbgaufs_xino_fop = {
6776 + .owner = THIS_MODULE,
6777 + .open = dbgaufs_xino_open,
6778 + .release = dbgaufs_xi_release,
6779 + .read = dbgaufs_xi_read
6782 +void dbgaufs_xino_del(struct au_branch *br)
6784 + struct dentry *dbgaufs;
6786 + dbgaufs = br->br_dbgaufs;
6790 + br->br_dbgaufs = NULL;
6791 + /* debugfs acquires the parent i_mutex */
6793 + debugfs_remove(dbgaufs);
6797 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6799 + aufs_bindex_t bbot;
6800 + struct au_branch *br;
6802 + if (!au_sbi(sb)->si_dbgaufs)
6805 + bbot = au_sbbot(sb);
6806 + for (; bindex <= bbot; bindex++) {
6807 + br = au_sbr(sb, bindex);
6808 + dbgaufs_xino_del(br);
6812 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6813 + unsigned int idx, struct dentry *parent,
6814 + struct au_sbinfo *sbinfo)
6816 + struct au_branch *br;
6818 + /* "xi" bindex(5) "-" idx(2) NULL */
6819 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6822 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6824 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6826 + br = au_sbr(sb, bindex);
6827 + if (br->br_dbgaufs) {
6828 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6830 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6831 + /* debugfs acquires the parent i_mutex */
6833 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6837 + pr_warn("failed renaming %pd/%s, ignored.\n",
6842 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6843 + sbinfo, &dbgaufs_xino_fop);
6845 + if (unlikely(!br->br_dbgaufs))
6846 + pr_warn("failed creating %pd/%s, ignored.\n",
6851 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6852 + struct dentry *parent, struct au_sbinfo *sbinfo)
6854 + struct au_branch *br;
6855 + struct au_xino *xi;
6858 + br = au_sbr(sb, bindex);
6860 + for (u = 0; u < xi->xi_nfile; u++)
6861 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6864 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6866 + struct au_sbinfo *sbinfo;
6867 + struct dentry *parent;
6868 + aufs_bindex_t bbot;
6870 + if (!au_opt_test(au_mntflags(sb), XINO))
6873 + sbinfo = au_sbi(sb);
6874 + parent = sbinfo->si_dbgaufs;
6878 + bbot = au_sbbot(sb);
6880 + for (; bindex <= bbot; bindex++)
6881 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6883 + for (; bbot >= bindex; bbot--)
6884 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6887 +/* ---------------------------------------------------------------------- */
6889 +#ifdef CONFIG_AUFS_EXPORT
6890 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6893 + struct au_sbinfo *sbinfo;
6894 + struct super_block *sb;
6896 + sbinfo = inode->i_private;
6897 + sb = sbinfo->si_sb;
6898 + si_noflush_read_lock(sb);
6899 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6900 + si_read_unlock(sb);
6904 +static const struct file_operations dbgaufs_xigen_fop = {
6905 + .owner = THIS_MODULE,
6906 + .open = dbgaufs_xigen_open,
6907 + .release = dbgaufs_xi_release,
6908 + .read = dbgaufs_xi_read
6911 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6916 + * This function is a dynamic '__init' function actually,
6917 + * so the tiny check for si_rwsem is unnecessary.
6919 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6922 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6923 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6924 + &dbgaufs_xigen_fop);
6925 + if (sbinfo->si_dbgaufs_xigen)
6931 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6935 +#endif /* CONFIG_AUFS_EXPORT */
6937 +/* ---------------------------------------------------------------------- */
6939 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6942 + * This function is a dynamic '__fin' function actually,
6943 + * so the tiny check for si_rwsem is unnecessary.
6945 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6947 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6948 + sbinfo->si_dbgaufs = NULL;
6951 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6954 + char name[SysaufsSiNameLen];
6957 + * This function is a dynamic '__init' function actually,
6958 + * so the tiny check for si_rwsem is unnecessary.
6960 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6964 + AuErr1("/debug/aufs is uninitialized\n");
6969 + sysaufs_name(sbinfo, name);
6970 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6971 + if (unlikely(!sbinfo->si_dbgaufs))
6974 + /* regardless plink/noplink option */
6975 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6976 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6977 + &dbgaufs_plink_fop);
6978 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6981 + /* regardless xino/noxino option */
6982 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6983 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6984 + &dbgaufs_xib_fop);
6985 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6988 + err = dbgaufs_xigen_init(sbinfo);
6990 + goto out; /* success */
6993 + dbgaufs_si_fin(sbinfo);
6995 + if (unlikely(err))
6996 + pr_err("debugfs/aufs failed\n");
7000 +/* ---------------------------------------------------------------------- */
7002 +void dbgaufs_fin(void)
7004 + debugfs_remove(dbgaufs);
7007 +int __init dbgaufs_init(void)
7012 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
7017 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
7018 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
7019 +++ linux/fs/aufs/dbgaufs.h 2021-02-22 23:30:37.699347580 +0100
7021 +/* SPDX-License-Identifier: GPL-2.0 */
7023 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7025 + * This program, aufs is free software; you can redistribute it and/or modify
7026 + * it under the terms of the GNU General Public License as published by
7027 + * the Free Software Foundation; either version 2 of the License, or
7028 + * (at your option) any later version.
7030 + * This program is distributed in the hope that it will be useful,
7031 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7032 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7033 + * GNU General Public License for more details.
7035 + * You should have received a copy of the GNU General Public License
7036 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7040 + * debugfs interface
7043 +#ifndef __DBGAUFS_H__
7044 +#define __DBGAUFS_H__
7048 +struct super_block;
7052 +#ifdef CONFIG_DEBUG_FS
7054 +void dbgaufs_xino_del(struct au_branch *br);
7055 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
7056 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
7057 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
7058 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
7059 +void dbgaufs_fin(void);
7060 +int __init dbgaufs_init(void);
7062 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
7063 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
7064 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
7066 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
7067 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
7068 +AuStubVoid(dbgaufs_fin, void)
7069 +AuStubInt0(__init dbgaufs_init, void)
7070 +#endif /* CONFIG_DEBUG_FS */
7072 +#endif /* __KERNEL__ */
7073 +#endif /* __DBGAUFS_H__ */
7074 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
7075 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
7076 +++ linux/fs/aufs/dcsub.c 2021-02-22 23:30:37.699347580 +0100
7078 +// SPDX-License-Identifier: GPL-2.0
7080 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7082 + * This program, aufs is free software; you can redistribute it and/or modify
7083 + * it under the terms of the GNU General Public License as published by
7084 + * the Free Software Foundation; either version 2 of the License, or
7085 + * (at your option) any later version.
7087 + * This program is distributed in the hope that it will be useful,
7088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7090 + * GNU General Public License for more details.
7092 + * You should have received a copy of the GNU General Public License
7093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7097 + * sub-routines for dentry cache
7102 +static void au_dpage_free(struct au_dpage *dpage)
7105 + struct dentry **p;
7107 + p = dpage->dentries;
7108 + for (i = 0; i < dpage->ndentry; i++)
7110 + free_page((unsigned long)dpage->dentries);
7113 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
7119 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
7120 + if (unlikely(!dpages->dpages))
7123 + p = (void *)__get_free_page(gfp);
7127 + dpages->dpages[0].ndentry = 0;
7128 + dpages->dpages[0].dentries = p;
7129 + dpages->ndpage = 1;
7130 + return 0; /* success */
7133 + au_kfree_try_rcu(dpages->dpages);
7138 +void au_dpages_free(struct au_dcsub_pages *dpages)
7141 + struct au_dpage *p;
7143 + p = dpages->dpages;
7144 + for (i = 0; i < dpages->ndpage; i++)
7145 + au_dpage_free(p++);
7146 + au_kfree_try_rcu(dpages->dpages);
7149 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7150 + struct dentry *dentry, gfp_t gfp)
7153 + struct au_dpage *dpage;
7156 + dpage = dpages->dpages + dpages->ndpage - 1;
7157 + sz = PAGE_SIZE / sizeof(dentry);
7158 + if (unlikely(dpage->ndentry >= sz)) {
7159 + AuLabel(new dpage);
7161 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7162 + p = au_kzrealloc(dpages->dpages, sz,
7163 + sz + sizeof(*dpages->dpages), gfp,
7168 + dpages->dpages = p;
7169 + dpage = dpages->dpages + dpages->ndpage;
7170 + p = (void *)__get_free_page(gfp);
7174 + dpage->ndentry = 0;
7175 + dpage->dentries = p;
7179 + AuDebugOn(au_dcount(dentry) <= 0);
7180 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7181 + return 0; /* success */
7187 +/* todo: BAD approach */
7188 +/* copied from linux/fs/dcache.c */
7196 +extern void d_walk(struct dentry *parent, void *data,
7197 + enum d_walk_ret (*enter)(void *, struct dentry *));
7199 +struct ac_dpages_arg {
7201 + struct au_dcsub_pages *dpages;
7202 + struct super_block *sb;
7203 + au_dpages_test test;
7207 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7209 + enum d_walk_ret ret;
7210 + struct ac_dpages_arg *arg = _arg;
7212 + ret = D_WALK_CONTINUE;
7213 + if (dentry->d_sb == arg->sb
7214 + && !IS_ROOT(dentry)
7215 + && au_dcount(dentry) > 0
7217 + && (!arg->test || arg->test(dentry, arg->arg))) {
7218 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7219 + if (unlikely(arg->err))
7220 + ret = D_WALK_QUIT;
7226 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7227 + au_dpages_test test, void *arg)
7229 + struct ac_dpages_arg args = {
7237 + d_walk(root, &args, au_call_dpages_append);
7242 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7243 + int do_include, au_dpages_test test, void *arg)
7248 + write_seqlock(&rename_lock);
7249 + spin_lock(&dentry->d_lock);
7251 + && au_dcount(dentry) > 0
7252 + && (!test || test(dentry, arg)))
7253 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7254 + spin_unlock(&dentry->d_lock);
7255 + if (unlikely(err))
7259 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7262 + while (!IS_ROOT(dentry)) {
7263 + dentry = dentry->d_parent; /* rename_lock is locked */
7264 + spin_lock(&dentry->d_lock);
7265 + if (au_dcount(dentry) > 0
7266 + && (!test || test(dentry, arg)))
7267 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7268 + spin_unlock(&dentry->d_lock);
7269 + if (unlikely(err))
7274 + write_sequnlock(&rename_lock);
7278 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7280 + return au_di(dentry) && dentry->d_sb == arg;
7283 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7284 + struct dentry *dentry, int do_include)
7286 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7287 + au_dcsub_dpages_aufs, dentry->d_sb);
7290 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7292 + struct path path[2] = {
7301 + return path_is_under(path + 0, path + 1);
7303 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7304 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7305 +++ linux/fs/aufs/dcsub.h 2021-02-22 23:30:37.699347580 +0100
7307 +/* SPDX-License-Identifier: GPL-2.0 */
7309 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7311 + * This program, aufs is free software; you can redistribute it and/or modify
7312 + * it under the terms of the GNU General Public License as published by
7313 + * the Free Software Foundation; either version 2 of the License, or
7314 + * (at your option) any later version.
7316 + * This program is distributed in the hope that it will be useful,
7317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7319 + * GNU General Public License for more details.
7321 + * You should have received a copy of the GNU General Public License
7322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7326 + * sub-routines for dentry cache
7329 +#ifndef __AUFS_DCSUB_H__
7330 +#define __AUFS_DCSUB_H__
7334 +#include <linux/dcache.h>
7335 +#include <linux/fs.h>
7339 + struct dentry **dentries;
7342 +struct au_dcsub_pages {
7344 + struct au_dpage *dpages;
7347 +/* ---------------------------------------------------------------------- */
7350 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7351 +void au_dpages_free(struct au_dcsub_pages *dpages);
7352 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7353 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7354 + au_dpages_test test, void *arg);
7355 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7356 + int do_include, au_dpages_test test, void *arg);
7357 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7358 + struct dentry *dentry, int do_include);
7359 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7361 +/* ---------------------------------------------------------------------- */
7364 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7365 + * include/linux/dcache.h. Try them (in the future).
7368 +static inline int au_d_hashed_positive(struct dentry *d)
7371 + struct inode *inode = d_inode(d);
7374 + if (unlikely(d_unhashed(d)
7375 + || d_is_negative(d)
7376 + || !inode->i_nlink))
7381 +static inline int au_d_linkable(struct dentry *d)
7384 + struct inode *inode = d_inode(d);
7386 + err = au_d_hashed_positive(d);
7388 + && d_is_positive(d)
7389 + && (inode->i_state & I_LINKABLE))
7394 +static inline int au_d_alive(struct dentry *d)
7397 + struct inode *inode;
7401 + err = au_d_hashed_positive(d);
7403 + inode = d_inode(d);
7404 + if (unlikely(d_unlinked(d)
7405 + || d_is_negative(d)
7406 + || !inode->i_nlink))
7412 +static inline int au_alive_dir(struct dentry *d)
7416 + err = au_d_alive(d);
7417 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7422 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7424 + return a->len == b->len
7425 + && !memcmp(a->name, b->name, a->len);
7430 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7432 + * the type of d_lockref.count became int, but the inlined function d_count()
7433 + * still returns unsigned int.
7434 + * I don't know why. Maybe it is for every d_count() users?
7435 + * Anyway au_dcount() lives on.
7437 +static inline int au_dcount(struct dentry *d)
7439 + return (int)d_count(d);
7442 +#endif /* __KERNEL__ */
7443 +#endif /* __AUFS_DCSUB_H__ */
7444 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7445 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7446 +++ linux/fs/aufs/debug.c 2021-02-22 23:30:37.699347580 +0100
7448 +// SPDX-License-Identifier: GPL-2.0
7450 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7452 + * This program, aufs is free software; you can redistribute it and/or modify
7453 + * it under the terms of the GNU General Public License as published by
7454 + * the Free Software Foundation; either version 2 of the License, or
7455 + * (at your option) any later version.
7457 + * This program is distributed in the hope that it will be useful,
7458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7460 + * GNU General Public License for more details.
7462 + * You should have received a copy of the GNU General Public License
7463 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7467 + * debug print functions
7470 +#include <linux/iversion.h>
7473 +/* Returns 0, or -errno. arg is in kp->arg. */
7474 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7478 + err = kstrtoint(val, 0, &n);
7488 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7489 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7494 + return sprintf(buffer, "%d", atomic_read(a));
7497 +static struct kernel_param_ops param_ops_atomic_t = {
7498 + .set = param_atomic_t_set,
7499 + .get = param_atomic_t_get
7500 + /* void (*free)(void *arg) */
7503 +atomic_t aufs_debug = ATOMIC_INIT(0);
7504 +MODULE_PARM_DESC(debug, "debug print");
7505 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7507 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7508 +char *au_plevel = KERN_DEBUG;
7509 +#define dpri(fmt, ...) do { \
7511 + && strcmp(au_plevel, KERN_DEBUG)) \
7512 + || au_debug_test()) \
7513 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7516 +/* ---------------------------------------------------------------------- */
7518 +void au_dpri_whlist(struct au_nhash *whlist)
7520 + unsigned long ul, n;
7521 + struct hlist_head *head;
7522 + struct au_vdir_wh *pos;
7524 + n = whlist->nh_num;
7525 + head = whlist->nh_head;
7526 + for (ul = 0; ul < n; ul++) {
7527 + hlist_for_each_entry(pos, head, wh_hash)
7528 + dpri("b%d, %.*s, %d\n",
7530 + pos->wh_str.len, pos->wh_str.name,
7536 +void au_dpri_vdir(struct au_vdir *vdir)
7539 + union au_vdir_deblk_p p;
7542 + if (!vdir || IS_ERR(vdir)) {
7543 + dpri("err %ld\n", PTR_ERR(vdir));
7547 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7548 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7549 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7550 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7551 + p.deblk = vdir->vd_deblk[ul];
7553 + dpri("[%lu]: %p\n", ul, o);
7557 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7558 + struct dentry *wh)
7563 + if (!inode || IS_ERR(inode)) {
7564 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7568 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7569 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7570 + && sizeof(inode->i_blocks) != sizeof(u64));
7572 + n = (void *)wh->d_name.name;
7573 + l = wh->d_name.len;
7576 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7577 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7579 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7580 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7581 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7582 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7583 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7584 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7585 + inode->i_generation,
7586 + l ? ", wh " : "", l, n);
7590 +void au_dpri_inode(struct inode *inode)
7592 + struct au_iinfo *iinfo;
7593 + struct au_hinode *hi;
7594 + aufs_bindex_t bindex;
7597 + err = do_pri_inode(-1, inode, -1, NULL);
7598 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7601 + iinfo = au_ii(inode);
7602 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7603 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7604 + if (iinfo->ii_btop < 0)
7607 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7608 + hi = au_hinode(iinfo, bindex);
7610 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7614 +void au_dpri_dalias(struct inode *inode)
7618 + spin_lock(&inode->i_lock);
7619 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7620 + au_dpri_dentry(d);
7621 + spin_unlock(&inode->i_lock);
7624 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7626 + struct dentry *wh = NULL;
7628 + struct inode *inode;
7629 + struct au_iinfo *iinfo;
7630 + struct au_hinode *hi;
7632 + if (!dentry || IS_ERR(dentry)) {
7633 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7636 + /* do not call dget_parent() here */
7637 + /* note: access d_xxx without d_lock */
7638 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7639 + bindex, dentry, dentry,
7640 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7641 + au_dcount(dentry), dentry->d_flags,
7642 + d_unhashed(dentry) ? "un" : "");
7645 + if (d_is_positive(dentry))
7646 + inode = d_inode(dentry);
7648 + && au_test_aufs(dentry->d_sb)
7650 + && !au_is_bad_inode(inode)) {
7651 + iinfo = au_ii(inode);
7652 + hi = au_hinode(iinfo, bindex);
7654 + wh = hi->hi_whdentry;
7656 + do_pri_inode(bindex, inode, hn, wh);
7660 +void au_dpri_dentry(struct dentry *dentry)
7662 + struct au_dinfo *dinfo;
7663 + aufs_bindex_t bindex;
7666 + err = do_pri_dentry(-1, dentry);
7667 + if (err || !au_test_aufs(dentry->d_sb))
7670 + dinfo = au_di(dentry);
7673 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7674 + dinfo->di_btop, dinfo->di_bbot,
7675 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7676 + dinfo->di_tmpfile);
7677 + if (dinfo->di_btop < 0)
7679 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7680 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7683 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7687 + if (!file || IS_ERR(file)) {
7688 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7693 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7694 + && au_test_aufs(file->f_path.dentry->d_sb)
7696 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7697 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7698 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7699 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7700 + file->f_version, file->f_pos, a);
7701 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7702 + do_pri_dentry(bindex, file->f_path.dentry);
7706 +void au_dpri_file(struct file *file)
7708 + struct au_finfo *finfo;
7709 + struct au_fidir *fidir;
7710 + struct au_hfile *hfile;
7711 + aufs_bindex_t bindex;
7714 + err = do_pri_file(-1, file);
7716 + || IS_ERR_OR_NULL(file->f_path.dentry)
7717 + || !au_test_aufs(file->f_path.dentry->d_sb))
7720 + finfo = au_fi(file);
7723 + if (finfo->fi_btop < 0)
7725 + fidir = finfo->fi_hdir;
7727 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7729 + for (bindex = finfo->fi_btop;
7730 + bindex >= 0 && bindex <= fidir->fd_bbot;
7732 + hfile = fidir->fd_hfile + bindex;
7733 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7737 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7739 + struct vfsmount *mnt;
7740 + struct super_block *sb;
7742 + if (!br || IS_ERR(br))
7744 + mnt = au_br_mnt(br);
7745 + if (!mnt || IS_ERR(mnt))
7748 + if (!sb || IS_ERR(sb))
7751 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7752 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7754 + bindex, br->br_perm, br->br_id, br->br_wbr,
7755 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7756 + sb->s_flags, sb->s_count,
7757 + atomic_read(&sb->s_active),
7758 + !!au_xino_file(br->br_xino, /*idx*/-1));
7762 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7766 +void au_dpri_sb(struct super_block *sb)
7768 + struct au_sbinfo *sbinfo;
7769 + aufs_bindex_t bindex;
7771 + /* to reduce stack size */
7773 + struct vfsmount mnt;
7774 + struct au_branch fake;
7777 + /* this function can be called from magic sysrq */
7778 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7779 + if (unlikely(!a)) {
7780 + dpri("no memory\n");
7784 + a->mnt.mnt_sb = sb;
7785 + a->fake.br_path.mnt = &a->mnt;
7786 + err = do_pri_br(-1, &a->fake);
7788 + dpri("dev 0x%x\n", sb->s_dev);
7789 + if (err || !au_test_aufs(sb))
7792 + sbinfo = au_sbi(sb);
7795 + dpri("nw %d, gen %u, kobj %d\n",
7796 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7797 + kref_read(&sbinfo->si_kobj.kref));
7798 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7799 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7802 +/* ---------------------------------------------------------------------- */
7804 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7806 + struct inode *h_inode, *inode = d_inode(dentry);
7807 + struct dentry *h_dentry;
7808 + aufs_bindex_t bindex, bbot, bi;
7810 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7813 + bbot = au_dbbot(dentry);
7814 + bi = au_ibbot(inode);
7817 + bindex = au_dbtop(dentry);
7818 + bi = au_ibtop(inode);
7822 + for (; bindex <= bbot; bindex++) {
7823 + h_dentry = au_h_dptr(dentry, bindex);
7826 + h_inode = au_h_iptr(inode, bindex);
7827 + if (unlikely(h_inode != d_inode(h_dentry))) {
7829 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7830 + AuDbgDentry(dentry);
7831 + AuDbgInode(inode);
7838 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7841 + struct au_dcsub_pages dpages;
7842 + struct au_dpage *dpage;
7843 + struct dentry **dentries;
7845 + err = au_dpages_init(&dpages, GFP_NOFS);
7847 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7849 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7850 + dpage = dpages.dpages + i;
7851 + dentries = dpage->dentries;
7852 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7853 + AuDebugOn(au_digen_test(dentries[j], sigen));
7855 + au_dpages_free(&dpages);
7858 +void au_dbg_verify_kthread(void)
7860 + if (au_wkq_test()) {
7863 + * It may be recursive, but udba=notify between two aufs mounts,
7864 + * where a single ro branch is shared, is not a problem.
7870 +/* ---------------------------------------------------------------------- */
7872 +int __init au_debug_init(void)
7874 + aufs_bindex_t bindex;
7875 + struct au_vdir_destr destr;
7878 + AuDebugOn(bindex >= 0);
7881 + AuDebugOn(destr.len < NAME_MAX);
7883 +#ifdef CONFIG_4KSTACKS
7884 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7889 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7890 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7891 +++ linux/fs/aufs/debug.h 2021-02-22 23:30:37.699347580 +0100
7893 +/* SPDX-License-Identifier: GPL-2.0 */
7895 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7897 + * This program, aufs is free software; you can redistribute it and/or modify
7898 + * it under the terms of the GNU General Public License as published by
7899 + * the Free Software Foundation; either version 2 of the License, or
7900 + * (at your option) any later version.
7902 + * This program is distributed in the hope that it will be useful,
7903 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7904 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7905 + * GNU General Public License for more details.
7907 + * You should have received a copy of the GNU General Public License
7908 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7912 + * debug print functions
7915 +#ifndef __AUFS_DEBUG_H__
7916 +#define __AUFS_DEBUG_H__
7920 +#include <linux/atomic.h>
7921 +#include <linux/module.h>
7922 +#include <linux/kallsyms.h>
7923 +#include <linux/sysrq.h>
7925 +#ifdef CONFIG_AUFS_DEBUG
7926 +#define AuDebugOn(a) BUG_ON(a)
7928 +/* module parameter */
7929 +extern atomic_t aufs_debug;
7930 +static inline void au_debug_on(void)
7932 + atomic_inc(&aufs_debug);
7934 +static inline void au_debug_off(void)
7936 + atomic_dec_if_positive(&aufs_debug);
7939 +static inline int au_debug_test(void)
7941 + return atomic_read(&aufs_debug) > 0;
7944 +#define AuDebugOn(a) do {} while (0)
7945 +AuStubVoid(au_debug_on, void)
7946 +AuStubVoid(au_debug_off, void)
7947 +AuStubInt0(au_debug_test, void)
7948 +#endif /* CONFIG_AUFS_DEBUG */
7950 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7952 +/* ---------------------------------------------------------------------- */
7956 +#define AuDbg(fmt, ...) do { \
7957 + if (au_debug_test()) \
7958 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7960 +#define AuLabel(l) AuDbg(#l "\n")
7961 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7962 +#define AuWarn1(fmt, ...) do { \
7963 + static unsigned char _c; \
7965 + pr_warn(fmt, ##__VA_ARGS__); \
7968 +#define AuErr1(fmt, ...) do { \
7969 + static unsigned char _c; \
7971 + pr_err(fmt, ##__VA_ARGS__); \
7974 +#define AuIOErr1(fmt, ...) do { \
7975 + static unsigned char _c; \
7977 + AuIOErr(fmt, ##__VA_ARGS__); \
7980 +#define AuUnsupportMsg "This operation is not supported." \
7981 + " Please report this application to aufs-users ML."
7982 +#define AuUnsupport(fmt, ...) do { \
7983 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7987 +#define AuTraceErr(e) do { \
7988 + if (unlikely((e) < 0)) \
7989 + AuDbg("err %d\n", (int)(e)); \
7992 +#define AuTraceErrPtr(p) do { \
7994 + AuDbg("err %ld\n", PTR_ERR(p)); \
7997 +/* dirty macros for debug print, use with "%.*s" and caution */
7998 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
8000 +/* ---------------------------------------------------------------------- */
8003 +#ifdef CONFIG_AUFS_DEBUG
8004 +extern struct mutex au_dbg_mtx;
8005 +extern char *au_plevel;
8007 +void au_dpri_whlist(struct au_nhash *whlist);
8009 +void au_dpri_vdir(struct au_vdir *vdir);
8011 +void au_dpri_inode(struct inode *inode);
8012 +void au_dpri_dalias(struct inode *inode);
8013 +void au_dpri_dentry(struct dentry *dentry);
8015 +void au_dpri_file(struct file *filp);
8016 +struct super_block;
8017 +void au_dpri_sb(struct super_block *sb);
8019 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
8020 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
8021 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
8022 +void au_dbg_verify_kthread(void);
8024 +int __init au_debug_init(void);
8026 +#define AuDbgWhlist(w) do { \
8027 + mutex_lock(&au_dbg_mtx); \
8029 + au_dpri_whlist(w); \
8030 + mutex_unlock(&au_dbg_mtx); \
8033 +#define AuDbgVdir(v) do { \
8034 + mutex_lock(&au_dbg_mtx); \
8036 + au_dpri_vdir(v); \
8037 + mutex_unlock(&au_dbg_mtx); \
8040 +#define AuDbgInode(i) do { \
8041 + mutex_lock(&au_dbg_mtx); \
8043 + au_dpri_inode(i); \
8044 + mutex_unlock(&au_dbg_mtx); \
8047 +#define AuDbgDAlias(i) do { \
8048 + mutex_lock(&au_dbg_mtx); \
8050 + au_dpri_dalias(i); \
8051 + mutex_unlock(&au_dbg_mtx); \
8054 +#define AuDbgDentry(d) do { \
8055 + mutex_lock(&au_dbg_mtx); \
8057 + au_dpri_dentry(d); \
8058 + mutex_unlock(&au_dbg_mtx); \
8061 +#define AuDbgFile(f) do { \
8062 + mutex_lock(&au_dbg_mtx); \
8064 + au_dpri_file(f); \
8065 + mutex_unlock(&au_dbg_mtx); \
8068 +#define AuDbgSb(sb) do { \
8069 + mutex_lock(&au_dbg_mtx); \
8070 + AuDbg(#sb "\n"); \
8072 + mutex_unlock(&au_dbg_mtx); \
8075 +#define AuDbgSym(addr) do { \
8076 + char sym[KSYM_SYMBOL_LEN]; \
8077 + sprint_symbol(sym, (unsigned long)addr); \
8078 + AuDbg("%s\n", sym); \
8081 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
8082 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
8083 +AuStubVoid(au_dbg_verify_kthread, void)
8084 +AuStubInt0(__init au_debug_init, void)
8086 +#define AuDbgWhlist(w) do {} while (0)
8087 +#define AuDbgVdir(v) do {} while (0)
8088 +#define AuDbgInode(i) do {} while (0)
8089 +#define AuDbgDAlias(i) do {} while (0)
8090 +#define AuDbgDentry(d) do {} while (0)
8091 +#define AuDbgFile(f) do {} while (0)
8092 +#define AuDbgSb(sb) do {} while (0)
8093 +#define AuDbgSym(addr) do {} while (0)
8094 +#endif /* CONFIG_AUFS_DEBUG */
8096 +/* ---------------------------------------------------------------------- */
8098 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
8099 +int __init au_sysrq_init(void);
8100 +void au_sysrq_fin(void);
8102 +#ifdef CONFIG_HW_CONSOLE
8103 +#define au_dbg_blocked() do { \
8105 + handle_sysrq('w'); \
8108 +AuStubVoid(au_dbg_blocked, void)
8112 +AuStubInt0(__init au_sysrq_init, void)
8113 +AuStubVoid(au_sysrq_fin, void)
8114 +AuStubVoid(au_dbg_blocked, void)
8115 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
8117 +#endif /* __KERNEL__ */
8118 +#endif /* __AUFS_DEBUG_H__ */
8119 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
8120 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
8121 +++ linux/fs/aufs/dentry.c 2021-02-22 23:30:37.699347580 +0100
8123 +// SPDX-License-Identifier: GPL-2.0
8125 + * Copyright (C) 2005-2020 Junjiro R. Okajima
8127 + * This program, aufs is free software; you can redistribute it and/or modify
8128 + * it under the terms of the GNU General Public License as published by
8129 + * the Free Software Foundation; either version 2 of the License, or
8130 + * (at your option) any later version.
8132 + * This program is distributed in the hope that it will be useful,
8133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8135 + * GNU General Public License for more details.
8137 + * You should have received a copy of the GNU General Public License
8138 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8142 + * lookup and dentry operations
8145 +#include <linux/iversion.h>
8146 +#include <linux/namei.h>
8150 + * returns positive/negative dentry, NULL or an error.
8151 + * NULL means whiteout-ed or not-found.
8153 +static struct dentry*
8154 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8155 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8157 + struct dentry *h_dentry;
8158 + struct inode *h_inode;
8159 + struct au_branch *br;
8160 + int wh_found, opq;
8161 + unsigned char wh_able;
8162 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8163 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8167 + br = au_sbr(dentry->d_sb, bindex);
8168 + wh_able = !!au_br_whable(br->br_perm);
8170 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8171 + h_dentry = ERR_PTR(wh_found);
8174 + if (unlikely(wh_found < 0))
8177 + /* We found a whiteout */
8178 + /* au_set_dbbot(dentry, bindex); */
8179 + au_set_dbwh(dentry, bindex);
8181 + return NULL; /* success */
8185 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8187 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8188 + if (IS_ERR(h_dentry)) {
8189 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8195 + h_inode = d_inode(h_dentry);
8196 + if (d_is_negative(h_dentry)) {
8199 + } else if (wh_found
8200 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8202 + else if (au_ftest_lkup(args->flags, DIRREN)
8204 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8205 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8206 + (unsigned long long)h_inode->i_ino);
8210 + if (au_dbbot(dentry) <= bindex)
8211 + au_set_dbbot(dentry, bindex);
8212 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8213 + au_set_dbtop(dentry, bindex);
8214 + au_set_h_dptr(dentry, bindex, h_dentry);
8216 + if (!d_is_dir(h_dentry)
8218 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8219 + goto out; /* success */
8221 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8222 + opq = au_diropq_test(h_dentry);
8223 + inode_unlock_shared(h_inode);
8225 + au_set_dbdiropq(dentry, bindex);
8226 + else if (unlikely(opq < 0)) {
8227 + au_set_h_dptr(dentry, bindex, NULL);
8228 + h_dentry = ERR_PTR(opq);
8239 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8241 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8242 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8248 + * returns the number of lower positive dentries,
8249 + * otherwise an error.
8250 + * can be called at unlinking with @type is zero.
8252 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8253 + unsigned int flags)
8255 + int npositive, err;
8256 + aufs_bindex_t bindex, btail, bdiropq;
8257 + unsigned char isdir, dirperm1, dirren;
8258 + struct au_do_lookup_args args = {
8260 + .name = &dentry->d_name
8262 + struct dentry *parent;
8263 + struct super_block *sb;
8265 + sb = dentry->d_sb;
8266 + err = au_test_shwh(sb, args.name);
8267 + if (unlikely(err))
8270 + err = au_wh_name_alloc(&args.whname, args.name);
8271 + if (unlikely(err))
8274 + isdir = !!d_is_dir(dentry);
8275 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8276 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8278 + au_fset_lkup(args.flags, DIRREN);
8281 + parent = dget_parent(dentry);
8282 + btail = au_dbtaildir(parent);
8283 + for (bindex = btop; bindex <= btail; bindex++) {
8284 + struct dentry *h_parent, *h_dentry;
8285 + struct inode *h_inode, *h_dir;
8286 + struct au_branch *br;
8288 + h_dentry = au_h_dptr(dentry, bindex);
8290 + if (d_is_positive(h_dentry))
8294 + h_parent = au_h_dptr(parent, bindex);
8295 + if (!h_parent || !d_is_dir(h_parent))
8299 + /* if the inum matches, then use the prepared name */
8300 + err = au_dr_lkup_name(&args, bindex);
8301 + if (unlikely(err))
8305 + h_dir = d_inode(h_parent);
8306 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8307 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8308 + inode_unlock_shared(h_dir);
8309 + err = PTR_ERR(h_dentry);
8310 + if (IS_ERR(h_dentry))
8313 + au_fclr_lkup(args.flags, ALLOW_NEG);
8315 + au_fset_lkup(args.flags, IGNORE_PERM);
8317 + if (au_dbwh(dentry) == bindex)
8321 + if (d_is_negative(h_dentry))
8323 + h_inode = d_inode(h_dentry);
8326 + args.type = h_inode->i_mode & S_IFMT;
8327 + if (args.type != S_IFDIR)
8330 + /* the type of lower may be different */
8331 + bdiropq = au_dbdiropq(dentry);
8332 + if (bdiropq >= 0 && bdiropq <= bindex)
8335 + br = au_sbr(sb, bindex);
8337 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8338 + /*add_ent*/NULL)) {
8339 + /* prepare next name to lookup */
8340 + err = au_dr_lkup(&args, dentry, bindex);
8341 + if (unlikely(err))
8347 + AuLabel(positive);
8348 + au_update_dbtop(dentry);
8351 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8352 + && au_dbtop(dentry) < 0)) {
8354 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8360 + au_kfree_try_rcu(args.whname.name);
8362 + au_dr_lkup_fin(&args);
8367 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8369 + struct dentry *dentry;
8372 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8373 + dentry = vfsub_lkup_one(name, parent);
8375 + struct vfsub_lkup_one_args args = {
8381 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8382 + if (unlikely(wkq_err))
8383 + dentry = ERR_PTR(wkq_err);
8390 + * lookup @dentry on @bindex which should be negative.
8392 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8395 + struct dentry *parent, *h_parent, *h_dentry;
8396 + struct au_branch *br;
8398 + parent = dget_parent(dentry);
8399 + h_parent = au_h_dptr(parent, bindex);
8400 + br = au_sbr(dentry->d_sb, bindex);
8402 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8404 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8405 + err = PTR_ERR(h_dentry);
8406 + if (IS_ERR(h_dentry))
8408 + if (unlikely(d_is_positive(h_dentry))) {
8410 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8416 + if (bindex < au_dbtop(dentry))
8417 + au_set_dbtop(dentry, bindex);
8418 + if (au_dbbot(dentry) < bindex)
8419 + au_set_dbbot(dentry, bindex);
8420 + au_set_h_dptr(dentry, bindex, h_dentry);
8427 +/* ---------------------------------------------------------------------- */
8429 +/* subset of struct inode */
8431 + unsigned long i_ino;
8432 + /* unsigned int i_nlink; */
8438 + blkcnt_t i_blocks;
8443 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8445 + ia->i_ino = h_inode->i_ino;
8446 + /* ia->i_nlink = h_inode->i_nlink; */
8447 + ia->i_uid = h_inode->i_uid;
8448 + ia->i_gid = h_inode->i_gid;
8449 + ia->i_version = inode_query_iversion(h_inode);
8451 + ia->i_size = h_inode->i_size;
8452 + ia->i_blocks = h_inode->i_blocks;
8454 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8457 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8459 + return ia->i_ino != h_inode->i_ino
8460 + /* || ia->i_nlink != h_inode->i_nlink */
8461 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8462 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8463 + || !inode_eq_iversion(h_inode, ia->i_version)
8465 + || ia->i_size != h_inode->i_size
8466 + || ia->i_blocks != h_inode->i_blocks
8468 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8471 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8472 + struct au_branch *br)
8475 + struct au_iattr ia;
8476 + struct inode *h_inode;
8477 + struct dentry *h_d;
8478 + struct super_block *h_sb;
8481 + memset(&ia, -1, sizeof(ia));
8482 + h_sb = h_dentry->d_sb;
8484 + if (d_is_positive(h_dentry)) {
8485 + h_inode = d_inode(h_dentry);
8486 + au_iattr_save(&ia, h_inode);
8487 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8488 + /* nfs d_revalidate may return 0 for negative dentry */
8489 + /* fuse d_revalidate always return 0 for negative dentry */
8492 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8493 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8494 + err = PTR_ERR(h_d);
8499 + if (unlikely(h_d != h_dentry
8500 + || d_inode(h_d) != h_inode
8501 + || (h_inode && au_iattr_test(&ia, h_inode))))
8502 + err = au_busy_or_stale();
8510 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8511 + struct dentry *h_parent, struct au_branch *br)
8516 + if (udba == AuOpt_UDBA_REVAL
8517 + && !au_test_fs_remote(h_dentry->d_sb)) {
8519 + err = (d_inode(h_dentry->d_parent) != h_dir);
8520 + } else if (udba != AuOpt_UDBA_NONE)
8521 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8526 +/* ---------------------------------------------------------------------- */
8528 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8531 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8532 + struct au_hdentry tmp, *p, *q;
8533 + struct au_dinfo *dinfo;
8534 + struct super_block *sb;
8536 + DiMustWriteLock(dentry);
8538 + sb = dentry->d_sb;
8539 + dinfo = au_di(dentry);
8540 + bbot = dinfo->di_bbot;
8541 + bwh = dinfo->di_bwh;
8542 + bdiropq = dinfo->di_bdiropq;
8543 + bindex = dinfo->di_btop;
8544 + p = au_hdentry(dinfo, bindex);
8545 + for (; bindex <= bbot; bindex++, p++) {
8546 + if (!p->hd_dentry)
8549 + new_bindex = au_br_index(sb, p->hd_id);
8550 + if (new_bindex == bindex)
8553 + if (dinfo->di_bwh == bindex)
8555 + if (dinfo->di_bdiropq == bindex)
8556 + bdiropq = new_bindex;
8557 + if (new_bindex < 0) {
8559 + p->hd_dentry = NULL;
8563 + /* swap two lower dentries, and loop again */
8564 + q = au_hdentry(dinfo, new_bindex);
8568 + if (tmp.hd_dentry) {
8574 + dinfo->di_bwh = -1;
8575 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8576 + dinfo->di_bwh = bwh;
8578 + dinfo->di_bdiropq = -1;
8580 + && bdiropq <= au_sbbot(sb)
8581 + && au_sbr_whable(sb, bdiropq))
8582 + dinfo->di_bdiropq = bdiropq;
8585 + dinfo->di_btop = -1;
8586 + dinfo->di_bbot = -1;
8587 + bbot = au_dbbot(parent);
8589 + p = au_hdentry(dinfo, bindex);
8590 + for (; bindex <= bbot; bindex++, p++)
8591 + if (p->hd_dentry) {
8592 + dinfo->di_btop = bindex;
8596 + if (dinfo->di_btop >= 0) {
8598 + p = au_hdentry(dinfo, bindex);
8599 + for (; bindex >= 0; bindex--, p--)
8600 + if (p->hd_dentry) {
8601 + dinfo->di_bbot = bindex;
8610 +static void au_do_hide(struct dentry *dentry)
8612 + struct inode *inode;
8614 + if (d_really_is_positive(dentry)) {
8615 + inode = d_inode(dentry);
8616 + if (!d_is_dir(dentry)) {
8617 + if (inode->i_nlink && !d_unhashed(dentry))
8618 + drop_nlink(inode);
8620 + clear_nlink(inode);
8621 + /* stop next lookup */
8622 + inode->i_flags |= S_DEAD;
8624 + smp_mb(); /* necessary? */
8629 +static int au_hide_children(struct dentry *parent)
8631 + int err, i, j, ndentry;
8632 + struct au_dcsub_pages dpages;
8633 + struct au_dpage *dpage;
8634 + struct dentry *dentry;
8636 + err = au_dpages_init(&dpages, GFP_NOFS);
8637 + if (unlikely(err))
8639 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8640 + if (unlikely(err))
8643 + /* in reverse order */
8644 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8645 + dpage = dpages.dpages + i;
8646 + ndentry = dpage->ndentry;
8647 + for (j = ndentry - 1; j >= 0; j--) {
8648 + dentry = dpage->dentries[j];
8649 + if (dentry != parent)
8650 + au_do_hide(dentry);
8655 + au_dpages_free(&dpages);
8660 +static void au_hide(struct dentry *dentry)
8664 + AuDbgDentry(dentry);
8665 + if (d_is_dir(dentry)) {
8666 + /* shrink_dcache_parent(dentry); */
8667 + err = au_hide_children(dentry);
8668 + if (unlikely(err))
8669 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8672 + au_do_hide(dentry);
8676 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8678 + * a dirty branch is added
8679 + * - on the top of layers
8680 + * - in the middle of layers
8681 + * - to the bottom of layers
8683 + * on the added branch there exists
8686 + * - a same named entry
8688 + * * negative --> positive
8689 + * * positive --> positive
8690 + * - type is unchanged
8691 + * - type is changed
8693 + * * negative --> negative
8694 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8697 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8698 + struct au_dinfo *tmp)
8701 + aufs_bindex_t bindex, bbot;
8703 + struct dentry *dentry;
8704 + struct inode *inode;
8706 + } orig_h, tmp_h = {
8709 + struct au_hdentry *hd;
8710 + struct inode *inode, *h_inode;
8711 + struct dentry *h_dentry;
8714 + AuDebugOn(dinfo->di_btop < 0);
8716 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8717 + orig_h.inode = NULL;
8718 + if (d_is_positive(orig_h.dentry)) {
8719 + orig_h.inode = d_inode(orig_h.dentry);
8720 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8722 + if (tmp->di_btop >= 0) {
8723 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8724 + if (d_is_positive(tmp_h.dentry)) {
8725 + tmp_h.inode = d_inode(tmp_h.dentry);
8726 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8731 + if (d_really_is_positive(dentry))
8732 + inode = d_inode(dentry);
8733 + if (!orig_h.inode) {
8734 + AuDbg("negative originally\n");
8740 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8741 + AuDebugOn(dinfo->di_bdiropq != -1);
8743 + if (!tmp_h.inode) {
8744 + AuDbg("negative --> negative\n");
8745 + /* should have only one negative lower */
8746 + if (tmp->di_btop >= 0
8747 + && tmp->di_btop < dinfo->di_btop) {
8748 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8749 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8750 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8751 + au_di_cp(dinfo, tmp);
8752 + hd = au_hdentry(tmp, tmp->di_btop);
8753 + au_set_h_dptr(dentry, tmp->di_btop,
8754 + dget(hd->hd_dentry));
8756 + au_dbg_verify_dinode(dentry);
8758 + AuDbg("negative --> positive\n");
8760 + * similar to the behaviour of creating with bypassing
8762 + * unhash it in order to force an error in the
8763 + * succeeding create operation.
8764 + * we should not set S_DEAD here.
8767 + /* au_di_swap(tmp, dinfo); */
8768 + au_dbg_verify_dinode(dentry);
8771 + AuDbg("positive originally\n");
8772 + /* inode may be NULL */
8773 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8774 + if (!tmp_h.inode) {
8775 + AuDbg("positive --> negative\n");
8776 + /* or bypassing aufs */
8778 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8779 + dinfo->di_bwh = tmp->di_bwh;
8781 + err = au_refresh_hinode_self(inode);
8782 + au_dbg_verify_dinode(dentry);
8783 + } else if (orig_h.mode == tmp_h.mode) {
8784 + AuDbg("positive --> positive, same type\n");
8785 + if (!S_ISDIR(orig_h.mode)
8786 + && dinfo->di_btop > tmp->di_btop) {
8788 + * similar to the behaviour of removing and
8793 + err = au_refresh_hinode_self(inode);
8794 + au_dbg_verify_dinode(dentry);
8796 + /* fill empty slots */
8797 + if (dinfo->di_btop > tmp->di_btop)
8798 + dinfo->di_btop = tmp->di_btop;
8799 + if (dinfo->di_bbot < tmp->di_bbot)
8800 + dinfo->di_bbot = tmp->di_bbot;
8801 + dinfo->di_bwh = tmp->di_bwh;
8802 + dinfo->di_bdiropq = tmp->di_bdiropq;
8803 + bbot = dinfo->di_bbot;
8804 + bindex = tmp->di_btop;
8805 + hd = au_hdentry(tmp, bindex);
8806 + for (; bindex <= bbot; bindex++, hd++) {
8807 + if (au_h_dptr(dentry, bindex))
8809 + h_dentry = hd->hd_dentry;
8812 + AuDebugOn(d_is_negative(h_dentry));
8813 + h_inode = d_inode(h_dentry);
8814 + AuDebugOn(orig_h.mode
8815 + != (h_inode->i_mode
8817 + au_set_h_dptr(dentry, bindex,
8821 + err = au_refresh_hinode(inode, dentry);
8822 + au_dbg_verify_dinode(dentry);
8825 + AuDbg("positive --> positive, different type\n");
8826 + /* similar to the behaviour of removing and creating */
8829 + err = au_refresh_hinode_self(inode);
8830 + au_dbg_verify_dinode(dentry);
8838 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8840 + const struct dentry_operations *dop
8841 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8842 + static const unsigned int mask
8843 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8845 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8847 + if (dentry->d_op == dop)
8850 + AuDbg("%pd\n", dentry);
8851 + spin_lock(&dentry->d_lock);
8852 + if (dop == &aufs_dop)
8853 + dentry->d_flags |= mask;
8855 + dentry->d_flags &= ~mask;
8856 + dentry->d_op = dop;
8857 + spin_unlock(&dentry->d_lock);
8860 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8862 + int err, ebrange, nbr;
8863 + unsigned int sigen;
8864 + struct au_dinfo *dinfo, *tmp;
8865 + struct super_block *sb;
8866 + struct inode *inode;
8868 + DiMustWriteLock(dentry);
8869 + AuDebugOn(IS_ROOT(dentry));
8870 + AuDebugOn(d_really_is_negative(parent));
8872 + sb = dentry->d_sb;
8873 + sigen = au_sigen(sb);
8874 + err = au_digen_test(parent, sigen);
8875 + if (unlikely(err))
8878 + nbr = au_sbbot(sb) + 1;
8879 + dinfo = au_di(dentry);
8880 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8881 + if (unlikely(err))
8883 + ebrange = au_dbrange_test(dentry);
8885 + ebrange = au_do_refresh_hdentry(dentry, parent);
8887 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8888 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8889 + if (d_really_is_positive(dentry)) {
8890 + inode = d_inode(dentry);
8891 + err = au_refresh_hinode_self(inode);
8893 + au_dbg_verify_dinode(dentry);
8895 + goto out_dgen; /* success */
8899 + /* temporary dinfo */
8900 + AuDbgDentry(dentry);
8902 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8903 + if (unlikely(!tmp))
8905 + au_di_swap(tmp, dinfo);
8906 + /* returns the number of positive dentries */
8908 + * if current working dir is removed, it returns an error.
8909 + * but the dentry is legal.
8911 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8912 + AuDbgDentry(dentry);
8913 + au_di_swap(tmp, dinfo);
8914 + if (err == -ENOENT)
8917 + /* compare/refresh by dinfo */
8918 + AuDbgDentry(dentry);
8919 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8920 + au_dbg_verify_dinode(dentry);
8923 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8924 + au_rw_write_unlock(&tmp->di_rwsem);
8926 + if (unlikely(err))
8930 + au_update_digen(dentry);
8932 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8933 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8934 + AuDbgDentry(dentry);
8940 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8941 + struct dentry *dentry, aufs_bindex_t bindex)
8946 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8949 + AuDbg("b%d\n", bindex);
8951 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8952 + * due to whiteout and branch permission.
8954 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8955 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8956 + /* it may return tri-state */
8957 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8959 + if (unlikely(valid < 0))
8969 +/* todo: remove this */
8970 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8971 + unsigned int flags, int do_udba, int dirren)
8974 + umode_t mode, h_mode;
8975 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8976 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8977 + struct inode *h_inode, *h_cached_inode;
8978 + struct dentry *h_dentry;
8979 + struct qstr *name, *h_name;
8986 + unhashed = !!d_unhashed(dentry);
8987 + is_root = !!IS_ROOT(dentry);
8988 + name = &dentry->d_name;
8989 + tmpfile = au_di(dentry)->di_tmpfile;
8992 + * Theoretically, REVAL test should be unnecessary in case of
8994 + * But {fs,i}notify doesn't fire some necessary events,
8995 + * IN_ATTRIB for atime/nlink/pageio
8996 + * Let's do REVAL test too.
8998 + if (do_udba && inode) {
8999 + mode = (inode->i_mode & S_IFMT);
9000 + plus = (inode->i_nlink > 0);
9001 + ibs = au_ibtop(inode);
9002 + ibe = au_ibbot(inode);
9005 + btop = au_dbtop(dentry);
9007 + if (inode && S_ISDIR(inode->i_mode))
9008 + btail = au_dbtaildir(dentry);
9009 + for (bindex = btop; bindex <= btail; bindex++) {
9010 + h_dentry = au_h_dptr(dentry, bindex);
9014 + AuDbg("b%d, %pd\n", bindex, h_dentry);
9015 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
9016 + spin_lock(&h_dentry->d_lock);
9017 + h_name = &h_dentry->d_name;
9018 + if (unlikely(do_udba
9021 + && (unhashed != !!d_unhashed(h_dentry)
9022 + || (!tmpfile && !dirren
9023 + && !au_qstreq(name, h_name))
9026 + && !(flags & LOOKUP_OPEN)
9027 + && (h_dentry->d_flags
9028 + & DCACHE_NFSFS_RENAMED)))
9032 + h_unhashed = d_unhashed(h_dentry);
9033 + spin_unlock(&h_dentry->d_lock);
9034 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
9035 + unhashed, h_unhashed, dentry, h_dentry);
9038 + spin_unlock(&h_dentry->d_lock);
9040 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
9041 + if (unlikely(err))
9042 + /* do not goto err, to keep the errno */
9045 + /* todo: plink too? */
9050 + if (unlikely(!!inode != d_is_positive(h_dentry)))
9054 + if (d_is_positive(h_dentry))
9055 + h_inode = d_inode(h_dentry);
9058 + h_cached_inode = h_inode;
9060 + h_mode = (h_inode->i_mode & S_IFMT);
9061 + h_plus = (h_inode->i_nlink > 0);
9063 + if (inode && ibs <= bindex && bindex <= ibe)
9064 + h_cached_inode = au_h_iptr(inode, bindex);
9067 + if (unlikely(plus != h_plus && !tmpfile))
9070 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
9072 + && !IS_ROOT(h_dentry)
9073 + && unhashed != d_unhashed(h_dentry)))
9076 + if (unlikely(mode != h_mode
9077 + || h_cached_inode != h_inode))
9090 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
9091 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
9094 + struct dentry *parent;
9096 + if (!au_digen_test(dentry, sigen))
9099 + parent = dget_parent(dentry);
9100 + di_read_lock_parent(parent, AuLock_IR);
9101 + AuDebugOn(au_digen_test(parent, sigen));
9102 + au_dbg_verify_gen(parent, sigen);
9103 + err = au_refresh_dentry(dentry, parent);
9104 + di_read_unlock(parent, AuLock_IR);
9110 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
9113 + struct dentry *d, *parent;
9115 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
9116 + return simple_reval_dpath(dentry, sigen);
9118 + /* slow loop, keep it simple and stupid */
9119 + /* cf: au_cpup_dirs() */
9122 + while (au_digen_test(dentry, sigen)) {
9126 + parent = dget_parent(d);
9127 + if (!au_digen_test(parent, sigen))
9133 + di_write_lock_child2(d);
9135 + /* someone might update our dentry while we were sleeping */
9136 + if (au_digen_test(d, sigen)) {
9138 + * todo: consolidate with simple_reval_dpath(),
9139 + * do_refresh() and au_reval_for_attr().
9141 + di_read_lock_parent(parent, AuLock_IR);
9142 + err = au_refresh_dentry(d, parent);
9143 + di_read_unlock(parent, AuLock_IR);
9147 + di_write_unlock(d);
9149 + if (unlikely(err))
9157 + * if valid returns 1, otherwise 0.
9159 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9162 + unsigned int sigen;
9163 + unsigned char do_udba, dirren;
9164 + struct super_block *sb;
9165 + struct inode *inode;
9167 + /* todo: support rcu-walk? */
9168 + if (flags & LOOKUP_RCU)
9172 + if (unlikely(!au_di(dentry)))
9176 + sb = dentry->d_sb;
9179 + * i_mutex of parent dir may be held,
9180 + * but we should not return 'invalid' due to busy.
9182 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9183 + if (unlikely(err)) {
9189 + if (d_really_is_positive(dentry))
9190 + inode = d_inode(dentry);
9191 + if (unlikely(inode && au_is_bad_inode(inode))) {
9196 + if (unlikely(au_dbrange_test(dentry))) {
9202 + sigen = au_sigen(sb);
9203 + if (au_digen_test(dentry, sigen)) {
9204 + AuDebugOn(IS_ROOT(dentry));
9205 + err = au_reval_dpath(dentry, sigen);
9206 + if (unlikely(err)) {
9211 + di_downgrade_lock(dentry, AuLock_IR);
9214 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9216 + && !(inode->i_state && I_LINKABLE)
9217 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9222 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9223 + if (do_udba && inode) {
9224 + aufs_bindex_t btop = au_ibtop(inode);
9225 + struct inode *h_inode;
9228 + h_inode = au_h_iptr(inode, btop);
9229 + if (h_inode && au_test_higen(inode, h_inode)) {
9236 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9237 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9238 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9240 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9246 + di_downgrade_lock(dentry, AuLock_IR);
9248 + aufs_read_unlock(dentry, AuLock_IR);
9253 + AuDbg("%pd invalid, %d\n", dentry, valid);
9259 +static void aufs_d_release(struct dentry *dentry)
9261 + if (au_di(dentry)) {
9262 + au_di_fin(dentry);
9263 + au_hn_di_reinit(dentry);
9267 +const struct dentry_operations aufs_dop = {
9268 + .d_revalidate = aufs_d_revalidate,
9269 + .d_weak_revalidate = aufs_d_revalidate,
9270 + .d_release = aufs_d_release
9273 +/* aufs_dop without d_revalidate */
9274 +const struct dentry_operations aufs_dop_noreval = {
9275 + .d_release = aufs_d_release
9277 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9278 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9279 +++ linux/fs/aufs/dentry.h 2021-02-22 23:30:37.699347580 +0100
9281 +/* SPDX-License-Identifier: GPL-2.0 */
9283 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9285 + * This program, aufs is free software; you can redistribute it and/or modify
9286 + * it under the terms of the GNU General Public License as published by
9287 + * the Free Software Foundation; either version 2 of the License, or
9288 + * (at your option) any later version.
9290 + * This program is distributed in the hope that it will be useful,
9291 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9292 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9293 + * GNU General Public License for more details.
9295 + * You should have received a copy of the GNU General Public License
9296 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9300 + * lookup and dentry operations
9303 +#ifndef __AUFS_DENTRY_H__
9304 +#define __AUFS_DENTRY_H__
9308 +#include <linux/dcache.h>
9309 +#include "dirren.h"
9312 +struct au_hdentry {
9313 + struct dentry *hd_dentry;
9314 + aufs_bindex_t hd_id;
9318 + atomic_t di_generation;
9320 + struct au_rwsem di_rwsem;
9321 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9322 + unsigned char di_tmpfile; /* to allow the different name */
9323 + struct au_hdentry *di_hdentry;
9324 + struct rcu_head rcu;
9325 +} ____cacheline_aligned_in_smp;
9327 +/* ---------------------------------------------------------------------- */
9329 +/* flags for au_lkup_dentry() */
9330 +#define AuLkup_ALLOW_NEG 1
9331 +#define AuLkup_IGNORE_PERM (1 << 1)
9332 +#define AuLkup_DIRREN (1 << 2)
9333 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9334 +#define au_fset_lkup(flags, name) \
9335 + do { (flags) |= AuLkup_##name; } while (0)
9336 +#define au_fclr_lkup(flags, name) \
9337 + do { (flags) &= ~AuLkup_##name; } while (0)
9339 +#ifndef CONFIG_AUFS_DIRREN
9340 +#undef AuLkup_DIRREN
9341 +#define AuLkup_DIRREN 0
9344 +struct au_do_lookup_args {
9345 + unsigned int flags;
9347 + struct qstr whname, *name;
9348 + struct au_dr_lookup dirren;
9351 +/* ---------------------------------------------------------------------- */
9354 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9356 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9357 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9358 + struct dentry *h_parent, struct au_branch *br);
9360 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9361 + unsigned int flags);
9362 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9363 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9364 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9365 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9368 +void au_di_init_once(void *_di);
9369 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9370 +void au_di_free(struct au_dinfo *dinfo);
9371 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9372 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9373 +int au_di_init(struct dentry *dentry);
9374 +void au_di_fin(struct dentry *dentry);
9375 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9377 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9378 +void di_read_unlock(struct dentry *d, int flags);
9379 +void di_downgrade_lock(struct dentry *d, int flags);
9380 +void di_write_lock(struct dentry *d, unsigned int lsc);
9381 +void di_write_unlock(struct dentry *d);
9382 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9383 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9384 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9386 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9387 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9388 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9389 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9391 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9392 + struct dentry *h_dentry);
9393 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9394 +int au_dbrange_test(struct dentry *dentry);
9395 +void au_update_digen(struct dentry *dentry);
9396 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9397 +void au_update_dbtop(struct dentry *dentry);
9398 +void au_update_dbbot(struct dentry *dentry);
9399 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9401 +/* ---------------------------------------------------------------------- */
9403 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9405 + return dentry->d_fsdata;
9408 +/* ---------------------------------------------------------------------- */
9410 +/* lock subclass for dinfo */
9412 + AuLsc_DI_CHILD, /* child first */
9413 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9414 + AuLsc_DI_CHILD3, /* copyup dirs */
9418 + AuLsc_DI_TMP /* temp for replacing dinfo */
9422 + * di_read_lock_child, di_write_lock_child,
9423 + * di_read_lock_child2, di_write_lock_child2,
9424 + * di_read_lock_child3, di_write_lock_child3,
9425 + * di_read_lock_parent, di_write_lock_parent,
9426 + * di_read_lock_parent2, di_write_lock_parent2,
9427 + * di_read_lock_parent3, di_write_lock_parent3,
9429 +#define AuReadLockFunc(name, lsc) \
9430 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9431 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9433 +#define AuWriteLockFunc(name, lsc) \
9434 +static inline void di_write_lock_##name(struct dentry *d) \
9435 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9437 +#define AuRWLockFuncs(name, lsc) \
9438 + AuReadLockFunc(name, lsc) \
9439 + AuWriteLockFunc(name, lsc)
9441 +AuRWLockFuncs(child, CHILD);
9442 +AuRWLockFuncs(child2, CHILD2);
9443 +AuRWLockFuncs(child3, CHILD3);
9444 +AuRWLockFuncs(parent, PARENT);
9445 +AuRWLockFuncs(parent2, PARENT2);
9446 +AuRWLockFuncs(parent3, PARENT3);
9448 +#undef AuReadLockFunc
9449 +#undef AuWriteLockFunc
9450 +#undef AuRWLockFuncs
9452 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9453 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9454 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9456 +/* ---------------------------------------------------------------------- */
9458 +/* todo: memory barrier? */
9459 +static inline unsigned int au_digen(struct dentry *d)
9461 + return atomic_read(&au_di(d)->di_generation);
9464 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9466 + hdentry->hd_dentry = NULL;
9469 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9470 + aufs_bindex_t bindex)
9472 + return di->di_hdentry + bindex;
9475 +static inline void au_hdput(struct au_hdentry *hd)
9478 + dput(hd->hd_dentry);
9481 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9483 + DiMustAnyLock(dentry);
9484 + return au_di(dentry)->di_btop;
9487 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9489 + DiMustAnyLock(dentry);
9490 + return au_di(dentry)->di_bbot;
9493 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9495 + DiMustAnyLock(dentry);
9496 + return au_di(dentry)->di_bwh;
9499 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9501 + DiMustAnyLock(dentry);
9502 + return au_di(dentry)->di_bdiropq;
9505 +/* todo: hard/soft set? */
9506 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9508 + DiMustWriteLock(dentry);
9509 + au_di(dentry)->di_btop = bindex;
9512 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9514 + DiMustWriteLock(dentry);
9515 + au_di(dentry)->di_bbot = bindex;
9518 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9520 + DiMustWriteLock(dentry);
9521 + /* dbwh can be outside of btop - bbot range */
9522 + au_di(dentry)->di_bwh = bindex;
9525 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9527 + DiMustWriteLock(dentry);
9528 + au_di(dentry)->di_bdiropq = bindex;
9531 +/* ---------------------------------------------------------------------- */
9533 +#ifdef CONFIG_AUFS_HNOTIFY
9534 +static inline void au_digen_dec(struct dentry *d)
9536 + atomic_dec(&au_di(d)->di_generation);
9539 +static inline void au_hn_di_reinit(struct dentry *dentry)
9541 + dentry->d_fsdata = NULL;
9544 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9545 +#endif /* CONFIG_AUFS_HNOTIFY */
9547 +#endif /* __KERNEL__ */
9548 +#endif /* __AUFS_DENTRY_H__ */
9549 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9550 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9551 +++ linux/fs/aufs/dinfo.c 2021-02-22 23:30:37.699347580 +0100
9553 +// SPDX-License-Identifier: GPL-2.0
9555 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9557 + * This program, aufs is free software; you can redistribute it and/or modify
9558 + * it under the terms of the GNU General Public License as published by
9559 + * the Free Software Foundation; either version 2 of the License, or
9560 + * (at your option) any later version.
9562 + * This program is distributed in the hope that it will be useful,
9563 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9564 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9565 + * GNU General Public License for more details.
9567 + * You should have received a copy of the GNU General Public License
9568 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9572 + * dentry private data
9577 +void au_di_init_once(void *_dinfo)
9579 + struct au_dinfo *dinfo = _dinfo;
9581 + au_rw_init(&dinfo->di_rwsem);
9584 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9586 + struct au_dinfo *dinfo;
9589 + dinfo = au_cache_alloc_dinfo();
9590 + if (unlikely(!dinfo))
9593 + nbr = au_sbbot(sb) + 1;
9596 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9597 + if (dinfo->di_hdentry) {
9598 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9599 + dinfo->di_btop = -1;
9600 + dinfo->di_bbot = -1;
9601 + dinfo->di_bwh = -1;
9602 + dinfo->di_bdiropq = -1;
9603 + dinfo->di_tmpfile = 0;
9604 + for (i = 0; i < nbr; i++)
9605 + dinfo->di_hdentry[i].hd_id = -1;
9609 + au_cache_free_dinfo(dinfo);
9616 +void au_di_free(struct au_dinfo *dinfo)
9618 + struct au_hdentry *p;
9619 + aufs_bindex_t bbot, bindex;
9621 + /* dentry may not be revalidated */
9622 + bindex = dinfo->di_btop;
9623 + if (bindex >= 0) {
9624 + bbot = dinfo->di_bbot;
9625 + p = au_hdentry(dinfo, bindex);
9626 + while (bindex++ <= bbot)
9629 + au_kfree_try_rcu(dinfo->di_hdentry);
9630 + au_cache_free_dinfo(dinfo);
9633 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9635 + struct au_hdentry *p;
9638 + AuRwMustWriteLock(&a->di_rwsem);
9639 + AuRwMustWriteLock(&b->di_rwsem);
9641 +#define DiSwap(v, name) \
9643 + v = a->di_##name; \
9644 + a->di_##name = b->di_##name; \
9645 + b->di_##name = v; \
9648 + DiSwap(p, hdentry);
9652 + DiSwap(bi, bdiropq);
9658 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9660 + AuRwMustWriteLock(&dst->di_rwsem);
9661 + AuRwMustWriteLock(&src->di_rwsem);
9663 + dst->di_btop = src->di_btop;
9664 + dst->di_bbot = src->di_bbot;
9665 + dst->di_bwh = src->di_bwh;
9666 + dst->di_bdiropq = src->di_bdiropq;
9670 +int au_di_init(struct dentry *dentry)
9673 + struct super_block *sb;
9674 + struct au_dinfo *dinfo;
9677 + sb = dentry->d_sb;
9678 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9680 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9681 + /* smp_mb(); */ /* atomic_set */
9682 + dentry->d_fsdata = dinfo;
9689 +void au_di_fin(struct dentry *dentry)
9691 + struct au_dinfo *dinfo;
9693 + dinfo = au_di(dentry);
9694 + AuRwDestroy(&dinfo->di_rwsem);
9695 + au_di_free(dinfo);
9698 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9701 + struct au_hdentry *hdp;
9703 + AuRwMustWriteLock(&dinfo->di_rwsem);
9706 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9708 + sz = sizeof(*hdp);
9709 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9712 + dinfo->di_hdentry = hdp;
9719 +/* ---------------------------------------------------------------------- */
9721 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9724 + case AuLsc_DI_CHILD:
9725 + ii_write_lock_child(inode);
9727 + case AuLsc_DI_CHILD2:
9728 + ii_write_lock_child2(inode);
9730 + case AuLsc_DI_CHILD3:
9731 + ii_write_lock_child3(inode);
9733 + case AuLsc_DI_PARENT:
9734 + ii_write_lock_parent(inode);
9736 + case AuLsc_DI_PARENT2:
9737 + ii_write_lock_parent2(inode);
9739 + case AuLsc_DI_PARENT3:
9740 + ii_write_lock_parent3(inode);
9747 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9750 + case AuLsc_DI_CHILD:
9751 + ii_read_lock_child(inode);
9753 + case AuLsc_DI_CHILD2:
9754 + ii_read_lock_child2(inode);
9756 + case AuLsc_DI_CHILD3:
9757 + ii_read_lock_child3(inode);
9759 + case AuLsc_DI_PARENT:
9760 + ii_read_lock_parent(inode);
9762 + case AuLsc_DI_PARENT2:
9763 + ii_read_lock_parent2(inode);
9765 + case AuLsc_DI_PARENT3:
9766 + ii_read_lock_parent3(inode);
9773 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9775 + struct inode *inode;
9777 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9778 + if (d_really_is_positive(d)) {
9779 + inode = d_inode(d);
9780 + if (au_ftest_lock(flags, IW))
9781 + do_ii_write_lock(inode, lsc);
9782 + else if (au_ftest_lock(flags, IR))
9783 + do_ii_read_lock(inode, lsc);
9787 +void di_read_unlock(struct dentry *d, int flags)
9789 + struct inode *inode;
9791 + if (d_really_is_positive(d)) {
9792 + inode = d_inode(d);
9793 + if (au_ftest_lock(flags, IW)) {
9794 + au_dbg_verify_dinode(d);
9795 + ii_write_unlock(inode);
9796 + } else if (au_ftest_lock(flags, IR)) {
9797 + au_dbg_verify_dinode(d);
9798 + ii_read_unlock(inode);
9801 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9804 +void di_downgrade_lock(struct dentry *d, int flags)
9806 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9807 + ii_downgrade_lock(d_inode(d));
9808 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9811 +void di_write_lock(struct dentry *d, unsigned int lsc)
9813 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9814 + if (d_really_is_positive(d))
9815 + do_ii_write_lock(d_inode(d), lsc);
9818 +void di_write_unlock(struct dentry *d)
9820 + au_dbg_verify_dinode(d);
9821 + if (d_really_is_positive(d))
9822 + ii_write_unlock(d_inode(d));
9823 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9826 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9828 + AuDebugOn(d1 == d2
9829 + || d_inode(d1) == d_inode(d2)
9830 + || d1->d_sb != d2->d_sb);
9832 + if ((isdir && au_test_subdir(d1, d2))
9834 + di_write_lock_child(d1);
9835 + di_write_lock_child2(d2);
9837 + di_write_lock_child(d2);
9838 + di_write_lock_child2(d1);
9842 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9844 + AuDebugOn(d1 == d2
9845 + || d_inode(d1) == d_inode(d2)
9846 + || d1->d_sb != d2->d_sb);
9848 + if ((isdir && au_test_subdir(d1, d2))
9850 + di_write_lock_parent(d1);
9851 + di_write_lock_parent2(d2);
9853 + di_write_lock_parent(d2);
9854 + di_write_lock_parent2(d1);
9858 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9860 + di_write_unlock(d1);
9861 + if (d_inode(d1) == d_inode(d2))
9862 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9864 + di_write_unlock(d2);
9867 +/* ---------------------------------------------------------------------- */
9869 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9873 + DiMustAnyLock(dentry);
9875 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9877 + AuDebugOn(bindex < 0);
9878 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9879 + AuDebugOn(d && au_dcount(d) <= 0);
9884 + * extended version of au_h_dptr().
9885 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9888 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9890 + struct dentry *h_dentry;
9891 + struct inode *inode, *h_inode;
9893 + AuDebugOn(d_really_is_negative(dentry));
9896 + if (au_dbtop(dentry) <= bindex
9897 + && bindex <= au_dbbot(dentry))
9898 + h_dentry = au_h_dptr(dentry, bindex);
9899 + if (h_dentry && !au_d_linkable(h_dentry)) {
9901 + goto out; /* success */
9904 + inode = d_inode(dentry);
9905 + AuDebugOn(bindex < au_ibtop(inode));
9906 + AuDebugOn(au_ibbot(inode) < bindex);
9907 + h_inode = au_h_iptr(inode, bindex);
9908 + h_dentry = d_find_alias(h_inode);
9910 + if (!IS_ERR(h_dentry)) {
9911 + if (!au_d_linkable(h_dentry))
9912 + goto out; /* success */
9918 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9919 + h_dentry = au_plink_lkup(inode, bindex);
9920 + AuDebugOn(!h_dentry);
9921 + if (!IS_ERR(h_dentry)) {
9922 + if (!au_d_hashed_positive(h_dentry))
9923 + goto out; /* success */
9930 + AuDbgDentry(h_dentry);
9934 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9936 + aufs_bindex_t bbot, bwh;
9938 + bbot = au_dbbot(dentry);
9940 + bwh = au_dbwh(dentry);
9943 + if (0 < bwh && bwh < bbot)
9949 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9951 + aufs_bindex_t bbot, bopq;
9953 + bbot = au_dbtail(dentry);
9955 + bopq = au_dbdiropq(dentry);
9956 + if (0 <= bopq && bopq < bbot)
9962 +/* ---------------------------------------------------------------------- */
9964 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9965 + struct dentry *h_dentry)
9967 + struct au_dinfo *dinfo;
9968 + struct au_hdentry *hd;
9969 + struct au_branch *br;
9971 + DiMustWriteLock(dentry);
9973 + dinfo = au_di(dentry);
9974 + hd = au_hdentry(dinfo, bindex);
9976 + hd->hd_dentry = h_dentry;
9978 + br = au_sbr(dentry->d_sb, bindex);
9979 + hd->hd_id = br->br_id;
9983 +int au_dbrange_test(struct dentry *dentry)
9986 + aufs_bindex_t btop, bbot;
9989 + btop = au_dbtop(dentry);
9990 + bbot = au_dbbot(dentry);
9992 + AuDebugOn(bbot < 0 && btop > bbot);
9995 + AuDebugOn(bbot >= 0);
10001 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
10006 + if (unlikely(au_digen(dentry) != sigen
10007 + || au_iigen_test(d_inode(dentry), sigen)))
10013 +void au_update_digen(struct dentry *dentry)
10015 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
10016 + /* smp_mb(); */ /* atomic_set */
10019 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
10021 + struct au_dinfo *dinfo;
10022 + struct dentry *h_d;
10023 + struct au_hdentry *hdp;
10024 + aufs_bindex_t bindex, bbot;
10026 + DiMustWriteLock(dentry);
10028 + dinfo = au_di(dentry);
10029 + if (!dinfo || dinfo->di_btop < 0)
10032 + if (do_put_zero) {
10033 + bbot = dinfo->di_bbot;
10034 + bindex = dinfo->di_btop;
10035 + hdp = au_hdentry(dinfo, bindex);
10036 + for (; bindex <= bbot; bindex++, hdp++) {
10037 + h_d = hdp->hd_dentry;
10038 + if (h_d && d_is_negative(h_d))
10039 + au_set_h_dptr(dentry, bindex, NULL);
10043 + dinfo->di_btop = 0;
10044 + hdp = au_hdentry(dinfo, dinfo->di_btop);
10045 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
10046 + if (hdp->hd_dentry)
10048 + if (dinfo->di_btop > dinfo->di_bbot) {
10049 + dinfo->di_btop = -1;
10050 + dinfo->di_bbot = -1;
10054 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
10055 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
10056 + if (hdp->hd_dentry)
10058 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
10061 +void au_update_dbtop(struct dentry *dentry)
10063 + aufs_bindex_t bindex, bbot;
10064 + struct dentry *h_dentry;
10066 + bbot = au_dbbot(dentry);
10067 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
10068 + h_dentry = au_h_dptr(dentry, bindex);
10071 + if (d_is_positive(h_dentry)) {
10072 + au_set_dbtop(dentry, bindex);
10075 + au_set_h_dptr(dentry, bindex, NULL);
10079 +void au_update_dbbot(struct dentry *dentry)
10081 + aufs_bindex_t bindex, btop;
10082 + struct dentry *h_dentry;
10084 + btop = au_dbtop(dentry);
10085 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
10086 + h_dentry = au_h_dptr(dentry, bindex);
10089 + if (d_is_positive(h_dentry)) {
10090 + au_set_dbbot(dentry, bindex);
10093 + au_set_h_dptr(dentry, bindex, NULL);
10097 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
10099 + aufs_bindex_t bindex, bbot;
10101 + bbot = au_dbbot(dentry);
10102 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
10103 + if (au_h_dptr(dentry, bindex) == h_dentry)
10107 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
10108 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
10109 +++ linux/fs/aufs/dir.c 2021-02-22 23:30:37.699347580 +0100
10111 +// SPDX-License-Identifier: GPL-2.0
10113 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10115 + * This program, aufs is free software; you can redistribute it and/or modify
10116 + * it under the terms of the GNU General Public License as published by
10117 + * the Free Software Foundation; either version 2 of the License, or
10118 + * (at your option) any later version.
10120 + * This program is distributed in the hope that it will be useful,
10121 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10122 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10123 + * GNU General Public License for more details.
10125 + * You should have received a copy of the GNU General Public License
10126 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10130 + * directory operations
10133 +#include <linux/fs_stack.h>
10134 +#include <linux/iversion.h>
10137 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10139 + unsigned int nlink;
10141 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10143 + nlink = dir->i_nlink;
10144 + nlink += h_dir->i_nlink - 2;
10145 + if (h_dir->i_nlink < 2)
10147 + smp_mb(); /* for i_nlink */
10148 + /* 0 can happen in revaliding */
10149 + set_nlink(dir, nlink);
10152 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10154 + unsigned int nlink;
10156 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10158 + nlink = dir->i_nlink;
10159 + nlink -= h_dir->i_nlink - 2;
10160 + if (h_dir->i_nlink < 2)
10162 + smp_mb(); /* for i_nlink */
10163 + /* nlink == 0 means the branch-fs is broken */
10164 + set_nlink(dir, nlink);
10167 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10170 + aufs_bindex_t bindex, bbot;
10171 + struct file *h_file;
10172 + struct dentry *h_dentry;
10176 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10178 + bbot = au_fbbot_dir(file);
10179 + for (bindex = au_fbtop(file);
10180 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10182 + h_file = au_hf_dir(file, bindex);
10183 + if (h_file && file_inode(h_file))
10184 + sz += vfsub_f_size_read(h_file);
10187 + AuDebugOn(!dentry);
10188 + AuDebugOn(!d_is_dir(dentry));
10190 + bbot = au_dbtaildir(dentry);
10191 + for (bindex = au_dbtop(dentry);
10192 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10194 + h_dentry = au_h_dptr(dentry, bindex);
10195 + if (h_dentry && d_is_positive(h_dentry))
10196 + sz += i_size_read(d_inode(h_dentry));
10199 + if (sz < KMALLOC_MAX_SIZE)
10200 + sz = roundup_pow_of_two(sz);
10201 + if (sz > KMALLOC_MAX_SIZE)
10202 + sz = KMALLOC_MAX_SIZE;
10203 + else if (sz < NAME_MAX) {
10204 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10205 + sz = AUFS_RDBLK_DEF;
10210 +struct au_dir_ts_arg {
10211 + struct dentry *dentry;
10212 + aufs_bindex_t brid;
10215 +static void au_do_dir_ts(void *arg)
10217 + struct au_dir_ts_arg *a = arg;
10218 + struct au_dtime dt;
10219 + struct path h_path;
10220 + struct inode *dir, *h_dir;
10221 + struct super_block *sb;
10222 + struct au_branch *br;
10223 + struct au_hinode *hdir;
10225 + aufs_bindex_t btop, bindex;
10227 + sb = a->dentry->d_sb;
10228 + if (d_really_is_negative(a->dentry))
10230 + /* no dir->i_mutex lock */
10231 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10233 + dir = d_inode(a->dentry);
10234 + btop = au_ibtop(dir);
10235 + bindex = au_br_index(sb, a->brid);
10236 + if (bindex < btop)
10239 + br = au_sbr(sb, bindex);
10240 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10241 + if (!h_path.dentry)
10243 + h_path.mnt = au_br_mnt(br);
10244 + au_dtime_store(&dt, a->dentry, &h_path);
10246 + br = au_sbr(sb, btop);
10247 + if (!au_br_writable(br->br_perm))
10249 + h_path.dentry = au_h_dptr(a->dentry, btop);
10250 + h_path.mnt = au_br_mnt(br);
10251 + err = vfsub_mnt_want_write(h_path.mnt);
10254 + hdir = au_hi(dir, btop);
10255 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10256 + h_dir = au_h_iptr(dir, btop);
10257 + if (h_dir->i_nlink
10258 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10259 + dt.dt_h_path = h_path;
10260 + au_dtime_revert(&dt);
10262 + au_hn_inode_unlock(hdir);
10263 + vfsub_mnt_drop_write(h_path.mnt);
10264 + au_cpup_attr_timesizes(dir);
10267 + aufs_read_unlock(a->dentry, AuLock_DW);
10270 + au_nwt_done(&au_sbi(sb)->si_nowait);
10271 + au_kfree_try_rcu(arg);
10274 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10276 + int perm, wkq_err;
10277 + aufs_bindex_t btop;
10278 + struct au_dir_ts_arg *arg;
10279 + struct dentry *dentry;
10280 + struct super_block *sb;
10284 + dentry = d_find_any_alias(dir);
10285 + AuDebugOn(!dentry);
10286 + sb = dentry->d_sb;
10287 + btop = au_ibtop(dir);
10288 + if (btop == bindex) {
10289 + au_cpup_attr_timesizes(dir);
10293 + perm = au_sbr_perm(sb, btop);
10294 + if (!au_br_writable(perm))
10297 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10301 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10302 + arg->brid = au_sbr_id(sb, bindex);
10303 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10304 + if (unlikely(wkq_err)) {
10305 + pr_err("wkq %d\n", wkq_err);
10307 + au_kfree_try_rcu(arg);
10314 +/* ---------------------------------------------------------------------- */
10316 +static int reopen_dir(struct file *file)
10319 + unsigned int flags;
10320 + aufs_bindex_t bindex, btail, btop;
10321 + struct dentry *dentry, *h_dentry;
10322 + struct file *h_file;
10324 + /* open all lower dirs */
10325 + dentry = file->f_path.dentry;
10326 + btop = au_dbtop(dentry);
10327 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10328 + au_set_h_fptr(file, bindex, NULL);
10329 + au_set_fbtop(file, btop);
10331 + btail = au_dbtaildir(dentry);
10332 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10333 + au_set_h_fptr(file, bindex, NULL);
10334 + au_set_fbbot_dir(file, btail);
10336 + flags = vfsub_file_flags(file);
10337 + for (bindex = btop; bindex <= btail; bindex++) {
10338 + h_dentry = au_h_dptr(dentry, bindex);
10341 + h_file = au_hf_dir(file, bindex);
10345 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10346 + err = PTR_ERR(h_file);
10347 + if (IS_ERR(h_file))
10348 + goto out; /* close all? */
10349 + au_set_h_fptr(file, bindex, h_file);
10351 + au_update_figen(file);
10352 + /* todo: necessary? */
10353 + /* file->f_ra = h_file->f_ra; */
10360 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10363 + aufs_bindex_t bindex, btail;
10364 + struct dentry *dentry, *h_dentry;
10365 + struct vfsmount *mnt;
10367 + FiMustWriteLock(file);
10368 + AuDebugOn(h_file);
10371 + mnt = file->f_path.mnt;
10372 + dentry = file->f_path.dentry;
10373 + file->f_version = inode_query_iversion(d_inode(dentry));
10374 + bindex = au_dbtop(dentry);
10375 + au_set_fbtop(file, bindex);
10376 + btail = au_dbtaildir(dentry);
10377 + au_set_fbbot_dir(file, btail);
10378 + for (; !err && bindex <= btail; bindex++) {
10379 + h_dentry = au_h_dptr(dentry, bindex);
10383 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10384 + if (unlikely(err))
10386 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10387 + if (IS_ERR(h_file)) {
10388 + err = PTR_ERR(h_file);
10391 + au_set_h_fptr(file, bindex, h_file);
10393 + au_update_figen(file);
10394 + /* todo: necessary? */
10395 + /* file->f_ra = h_file->f_ra; */
10397 + return 0; /* success */
10400 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10401 + au_set_h_fptr(file, bindex, NULL);
10402 + au_set_fbtop(file, -1);
10403 + au_set_fbbot_dir(file, -1);
10408 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10409 + struct file *file)
10412 + struct super_block *sb;
10413 + struct au_fidir *fidir;
10416 + sb = file->f_path.dentry->d_sb;
10417 + si_read_lock(sb, AuLock_FLUSH);
10418 + fidir = au_fidir_alloc(sb);
10420 + struct au_do_open_args args = {
10421 + .open = do_open_dir,
10424 + err = au_do_open(file, &args);
10425 + if (unlikely(err))
10426 + au_kfree_rcu(fidir);
10428 + si_read_unlock(sb);
10432 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10433 + struct file *file)
10435 + struct au_vdir *vdir_cache;
10436 + struct au_finfo *finfo;
10437 + struct au_fidir *fidir;
10438 + struct au_hfile *hf;
10439 + aufs_bindex_t bindex, bbot;
10441 + finfo = au_fi(file);
10442 + fidir = finfo->fi_hdir;
10444 + au_hbl_del(&finfo->fi_hlist,
10445 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10446 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10448 + au_vdir_free(vdir_cache);
10450 + bindex = finfo->fi_btop;
10451 + if (bindex >= 0) {
10452 + hf = fidir->fd_hfile + bindex;
10454 + * calls fput() instead of filp_close(),
10455 + * since no dnotify or lock for the lower file.
10457 + bbot = fidir->fd_bbot;
10458 + for (; bindex <= bbot; bindex++, hf++)
10460 + au_hfput(hf, /*execed*/0);
10462 + au_kfree_rcu(fidir);
10463 + finfo->fi_hdir = NULL;
10465 + au_finfo_fin(file);
10469 +/* ---------------------------------------------------------------------- */
10471 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10474 + aufs_bindex_t bindex, bbot;
10475 + struct file *h_file;
10478 + bbot = au_fbbot_dir(file);
10479 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10480 + h_file = au_hf_dir(file, bindex);
10482 + err = vfsub_flush(h_file, id);
10487 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10489 + return au_do_flush(file, id, au_do_flush_dir);
10492 +/* ---------------------------------------------------------------------- */
10494 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10497 + aufs_bindex_t bbot, bindex;
10498 + struct inode *inode;
10499 + struct super_block *sb;
10502 + sb = dentry->d_sb;
10503 + inode = d_inode(dentry);
10504 + IMustLock(inode);
10505 + bbot = au_dbbot(dentry);
10506 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10507 + struct path h_path;
10509 + if (au_test_ro(sb, bindex, inode))
10511 + h_path.dentry = au_h_dptr(dentry, bindex);
10512 + if (!h_path.dentry)
10515 + h_path.mnt = au_sbr_mnt(sb, bindex);
10516 + err = vfsub_fsync(NULL, &h_path, datasync);
10522 +static int au_do_fsync_dir(struct file *file, int datasync)
10525 + aufs_bindex_t bbot, bindex;
10526 + struct file *h_file;
10527 + struct super_block *sb;
10528 + struct inode *inode;
10530 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10531 + if (unlikely(err))
10534 + inode = file_inode(file);
10535 + sb = inode->i_sb;
10536 + bbot = au_fbbot_dir(file);
10537 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10538 + h_file = au_hf_dir(file, bindex);
10539 + if (!h_file || au_test_ro(sb, bindex, inode))
10542 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10550 + * @file may be NULL
10552 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10556 + struct dentry *dentry;
10557 + struct inode *inode;
10558 + struct super_block *sb;
10561 + dentry = file->f_path.dentry;
10562 + inode = d_inode(dentry);
10563 + inode_lock(inode);
10564 + sb = dentry->d_sb;
10565 + si_noflush_read_lock(sb);
10567 + err = au_do_fsync_dir(file, datasync);
10569 + di_write_lock_child(dentry);
10570 + err = au_do_fsync_dir_no_file(dentry, datasync);
10572 + au_cpup_attr_timesizes(inode);
10573 + di_write_unlock(dentry);
10575 + fi_write_unlock(file);
10577 + si_read_unlock(sb);
10578 + inode_unlock(inode);
10582 +/* ---------------------------------------------------------------------- */
10584 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10587 + struct dentry *dentry;
10588 + struct inode *inode, *h_inode;
10589 + struct super_block *sb;
10591 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10593 + dentry = file->f_path.dentry;
10594 + inode = d_inode(dentry);
10595 + IMustLock(inode);
10597 + sb = dentry->d_sb;
10598 + si_read_lock(sb, AuLock_FLUSH);
10599 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10600 + if (unlikely(err))
10602 + err = au_alive_dir(dentry);
10604 + err = au_vdir_init(file);
10605 + di_downgrade_lock(dentry, AuLock_IR);
10606 + if (unlikely(err))
10609 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10610 + if (!au_test_nfsd()) {
10611 + err = au_vdir_fill_de(file, ctx);
10612 + fsstack_copy_attr_atime(inode, h_inode);
10615 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10616 + * encode_fh() and others.
10618 + atomic_inc(&h_inode->i_count);
10619 + di_read_unlock(dentry, AuLock_IR);
10620 + si_read_unlock(sb);
10621 + err = au_vdir_fill_de(file, ctx);
10622 + fsstack_copy_attr_atime(inode, h_inode);
10623 + fi_write_unlock(file);
10631 + di_read_unlock(dentry, AuLock_IR);
10632 + fi_write_unlock(file);
10634 + si_read_unlock(sb);
10638 +/* ---------------------------------------------------------------------- */
10640 +#define AuTestEmpty_WHONLY 1
10641 +#define AuTestEmpty_CALLED (1 << 1)
10642 +#define AuTestEmpty_SHWH (1 << 2)
10643 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10644 +#define au_fset_testempty(flags, name) \
10645 + do { (flags) |= AuTestEmpty_##name; } while (0)
10646 +#define au_fclr_testempty(flags, name) \
10647 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10649 +#ifndef CONFIG_AUFS_SHWH
10650 +#undef AuTestEmpty_SHWH
10651 +#define AuTestEmpty_SHWH 0
10654 +struct test_empty_arg {
10655 + struct dir_context ctx;
10656 + struct au_nhash *whlist;
10657 + unsigned int flags;
10659 + aufs_bindex_t bindex;
10662 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10663 + int namelen, loff_t offset __maybe_unused, u64 ino,
10664 + unsigned int d_type)
10666 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10668 + char *name = (void *)__name;
10671 + au_fset_testempty(arg->flags, CALLED);
10673 + if (name[0] == '.'
10674 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10675 + goto out; /* success */
10677 + if (namelen <= AUFS_WH_PFX_LEN
10678 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10679 + if (au_ftest_testempty(arg->flags, WHONLY)
10680 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10681 + arg->err = -ENOTEMPTY;
10685 + name += AUFS_WH_PFX_LEN;
10686 + namelen -= AUFS_WH_PFX_LEN;
10687 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10688 + arg->err = au_nhash_append_wh
10689 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10690 + au_ftest_testempty(arg->flags, SHWH));
10694 + AuTraceErr(arg->err);
10698 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10701 + struct file *h_file;
10702 + struct au_branch *br;
10704 + h_file = au_h_open(dentry, arg->bindex,
10705 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10706 + /*file*/NULL, /*force_wr*/0);
10707 + err = PTR_ERR(h_file);
10708 + if (IS_ERR(h_file))
10712 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10713 + && !file_inode(h_file)->i_nlink)
10718 + au_fclr_testempty(arg->flags, CALLED);
10720 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10723 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10727 + br = au_sbr(dentry->d_sb, arg->bindex);
10728 + au_lcnt_dec(&br->br_nfiles);
10733 +struct do_test_empty_args {
10735 + struct dentry *dentry;
10736 + struct test_empty_arg *arg;
10739 +static void call_do_test_empty(void *args)
10741 + struct do_test_empty_args *a = args;
10742 + *a->errp = do_test_empty(a->dentry, a->arg);
10745 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10747 + int err, wkq_err;
10748 + struct dentry *h_dentry;
10749 + struct inode *h_inode;
10751 + h_dentry = au_h_dptr(dentry, arg->bindex);
10752 + h_inode = d_inode(h_dentry);
10753 + /* todo: i_mode changes anytime? */
10754 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10755 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10756 + inode_unlock_shared(h_inode);
10758 + err = do_test_empty(dentry, arg);
10760 + struct do_test_empty_args args = {
10762 + .dentry = dentry,
10765 + unsigned int flags = arg->flags;
10767 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10768 + if (unlikely(wkq_err))
10770 + arg->flags = flags;
10776 +int au_test_empty_lower(struct dentry *dentry)
10779 + unsigned int rdhash;
10780 + aufs_bindex_t bindex, btop, btail;
10781 + struct au_nhash whlist;
10782 + struct test_empty_arg arg = {
10784 + .actor = test_empty_cb
10787 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10789 + SiMustAnyLock(dentry->d_sb);
10791 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10793 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10794 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10795 + if (unlikely(err))
10799 + arg.whlist = &whlist;
10800 + btop = au_dbtop(dentry);
10801 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10802 + au_fset_testempty(arg.flags, SHWH);
10803 + test_empty = do_test_empty;
10804 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10805 + test_empty = sio_test_empty;
10806 + arg.bindex = btop;
10807 + err = test_empty(dentry, &arg);
10808 + if (unlikely(err))
10811 + au_fset_testempty(arg.flags, WHONLY);
10812 + btail = au_dbtaildir(dentry);
10813 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10814 + struct dentry *h_dentry;
10816 + h_dentry = au_h_dptr(dentry, bindex);
10817 + if (h_dentry && d_is_positive(h_dentry)) {
10818 + arg.bindex = bindex;
10819 + err = test_empty(dentry, &arg);
10824 + au_nhash_wh_free(&whlist);
10829 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10832 + struct test_empty_arg arg = {
10834 + .actor = test_empty_cb
10837 + aufs_bindex_t bindex, btail;
10840 + arg.whlist = whlist;
10841 + arg.flags = AuTestEmpty_WHONLY;
10842 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10843 + au_fset_testempty(arg.flags, SHWH);
10844 + btail = au_dbtaildir(dentry);
10845 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10846 + struct dentry *h_dentry;
10848 + h_dentry = au_h_dptr(dentry, bindex);
10849 + if (h_dentry && d_is_positive(h_dentry)) {
10850 + arg.bindex = bindex;
10851 + err = sio_test_empty(dentry, &arg);
10858 +/* ---------------------------------------------------------------------- */
10860 +const struct file_operations aufs_dir_fop = {
10861 + .owner = THIS_MODULE,
10862 + .llseek = default_llseek,
10863 + .read = generic_read_dir,
10864 + .iterate_shared = aufs_iterate_shared,
10865 + .unlocked_ioctl = aufs_ioctl_dir,
10866 +#ifdef CONFIG_COMPAT
10867 + .compat_ioctl = aufs_compat_ioctl_dir,
10869 + .open = aufs_open_dir,
10870 + .release = aufs_release_dir,
10871 + .flush = aufs_flush_dir,
10872 + .fsync = aufs_fsync_dir
10874 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10875 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10876 +++ linux/fs/aufs/dir.h 2021-02-22 23:30:37.699347580 +0100
10878 +/* SPDX-License-Identifier: GPL-2.0 */
10880 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10882 + * This program, aufs is free software; you can redistribute it and/or modify
10883 + * it under the terms of the GNU General Public License as published by
10884 + * the Free Software Foundation; either version 2 of the License, or
10885 + * (at your option) any later version.
10887 + * This program is distributed in the hope that it will be useful,
10888 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10889 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10890 + * GNU General Public License for more details.
10892 + * You should have received a copy of the GNU General Public License
10893 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10897 + * directory operations
10900 +#ifndef __AUFS_DIR_H__
10901 +#define __AUFS_DIR_H__
10905 +#include <linux/fs.h>
10907 +/* ---------------------------------------------------------------------- */
10909 +/* need to be faster and smaller */
10912 + unsigned int nh_num;
10913 + struct hlist_head *nh_head;
10916 +struct au_vdir_destr {
10917 + unsigned char len;
10918 + unsigned char name[];
10921 +struct au_vdir_dehstr {
10922 + struct hlist_node hash;
10923 + struct au_vdir_destr *str;
10924 + struct rcu_head rcu;
10925 +} ____cacheline_aligned_in_smp;
10927 +struct au_vdir_de {
10929 + unsigned char de_type;
10930 + /* caution: packed */
10931 + struct au_vdir_destr de_str;
10934 +struct au_vdir_wh {
10935 + struct hlist_node wh_hash;
10936 +#ifdef CONFIG_AUFS_SHWH
10938 + aufs_bindex_t wh_bindex;
10939 + unsigned char wh_type;
10941 + aufs_bindex_t wh_bindex;
10943 + /* caution: packed */
10944 + struct au_vdir_destr wh_str;
10947 +union au_vdir_deblk_p {
10948 + unsigned char *deblk;
10949 + struct au_vdir_de *de;
10953 + unsigned char **vd_deblk;
10954 + unsigned long vd_nblk;
10956 + unsigned long ul;
10957 + union au_vdir_deblk_p p;
10961 + unsigned int vd_deblk_sz;
10962 + unsigned long vd_jiffy;
10963 + struct rcu_head rcu;
10964 +} ____cacheline_aligned_in_smp;
10966 +/* ---------------------------------------------------------------------- */
10969 +extern const struct file_operations aufs_dir_fop;
10970 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10971 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10972 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10973 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10974 +int au_test_empty_lower(struct dentry *dentry);
10975 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10978 +unsigned int au_rdhash_est(loff_t sz);
10979 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10980 +void au_nhash_wh_free(struct au_nhash *whlist);
10981 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10983 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10984 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10985 + unsigned int d_type, aufs_bindex_t bindex,
10986 + unsigned char shwh);
10987 +void au_vdir_free(struct au_vdir *vdir);
10988 +int au_vdir_init(struct file *file);
10989 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10992 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10994 +#ifdef CONFIG_AUFS_RDU
10996 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10997 +#ifdef CONFIG_COMPAT
10998 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10999 + unsigned long arg);
11002 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
11003 + unsigned int cmd, unsigned long arg)
11004 +#ifdef CONFIG_COMPAT
11005 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
11006 + unsigned int cmd, unsigned long arg)
11010 +#endif /* __KERNEL__ */
11011 +#endif /* __AUFS_DIR_H__ */
11012 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
11013 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
11014 +++ linux/fs/aufs/dirren.c 2021-02-22 23:30:37.699347580 +0100
11016 +// SPDX-License-Identifier: GPL-2.0
11018 + * Copyright (C) 2017-2020 Junjiro R. Okajima
11020 + * This program, aufs is free software; you can redistribute it and/or modify
11021 + * it under the terms of the GNU General Public License as published by
11022 + * the Free Software Foundation; either version 2 of the License, or
11023 + * (at your option) any later version.
11025 + * This program is distributed in the hope that it will be useful,
11026 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11027 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11028 + * GNU General Public License for more details.
11030 + * You should have received a copy of the GNU General Public License
11031 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11035 + * special handling in renaming a directory
11036 + * in order to support looking-up the before-renamed name on the lower readonly
11040 +#include <linux/byteorder/generic.h>
11043 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
11047 + idx = au_dr_ihash(ent->dr_h_ino);
11048 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
11051 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
11054 + struct hlist_bl_head *hbl;
11057 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
11058 + hbl = dr->dr_h_ino + i;
11059 + hlist_bl_lock(hbl);
11060 + ret &= hlist_bl_empty(hbl);
11061 + hlist_bl_unlock(hbl);
11067 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
11069 + struct au_dr_hino *found, *ent;
11070 + struct hlist_bl_head *hbl;
11071 + struct hlist_bl_node *pos;
11075 + idx = au_dr_ihash(ino);
11076 + hbl = dr->dr_h_ino + idx;
11077 + hlist_bl_lock(hbl);
11078 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11079 + if (ent->dr_h_ino == ino) {
11083 + hlist_bl_unlock(hbl);
11088 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
11089 + struct au_dr_hino *add_ent)
11092 + struct hlist_bl_head *hbl;
11093 + struct hlist_bl_node *pos;
11094 + struct au_dr_hino *ent;
11097 + idx = au_dr_ihash(ino);
11098 + hbl = dr->dr_h_ino + idx;
11099 +#if 0 /* debug print */
11101 + struct hlist_bl_node *tmp;
11103 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11104 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
11107 + hlist_bl_lock(hbl);
11108 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
11109 + if (ent->dr_h_ino == ino) {
11113 + if (!found && add_ent)
11114 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
11115 + hlist_bl_unlock(hbl);
11117 + if (!found && add_ent)
11118 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11123 +void au_dr_hino_free(struct au_dr_br *dr)
11126 + struct hlist_bl_head *hbl;
11127 + struct hlist_bl_node *pos, *tmp;
11128 + struct au_dr_hino *ent;
11130 + /* SiMustWriteLock(sb); */
11132 + for (i = 0; i < AuDirren_NHASH; i++) {
11133 + hbl = dr->dr_h_ino + i;
11134 + /* no spinlock since sbinfo must be write-locked */
11135 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11136 + au_kfree_rcu(ent);
11137 + INIT_HLIST_BL_HEAD(hbl);
11141 +/* returns the number of inodes or an error */
11142 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11143 + struct file *hinofile)
11147 + loff_t pos, oldsize;
11149 + struct inode *hinoinode;
11150 + struct hlist_bl_head *hbl;
11151 + struct hlist_bl_node *n1, *n2;
11152 + struct au_dr_hino *ent;
11154 + SiMustWriteLock(sb);
11155 + AuDebugOn(!au_br_writable(br->br_perm));
11157 + hinoinode = file_inode(hinofile);
11158 + oldsize = i_size_read(hinoinode);
11162 + hbl = br->br_dirren.dr_h_ino;
11163 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11164 + /* no bit-lock since sbinfo must be write-locked */
11165 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11166 + AuDbg("hi%llu, %pD2\n",
11167 + (unsigned long long)ent->dr_h_ino, hinofile);
11168 + u64 = cpu_to_be64(ent->dr_h_ino);
11169 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11170 + if (ssz == sizeof(u64))
11173 + /* write error */
11174 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11181 + /* regardless the error */
11182 + if (pos < oldsize) {
11183 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11191 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11198 + struct au_dr_hino *ent;
11199 + struct inode *hinoinode;
11200 + struct hlist_bl_head *hbl;
11204 + hbl = dr->dr_h_ino;
11205 + hinoinode = file_inode(hinofile);
11206 + sz = i_size_read(hinoinode);
11207 + AuDebugOn(sz % sizeof(u64));
11208 + n = sz / sizeof(u64);
11210 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11211 + if (unlikely(ssz != sizeof(u64))) {
11212 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11219 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11225 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11226 + AuDbg("hi%llu, %pD2\n",
11227 + (unsigned long long)ent->dr_h_ino, hinofile);
11228 + hidx = au_dr_ihash(ent->dr_h_ino);
11229 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11231 + goto out; /* success */
11234 + au_dr_hino_free(dr);
11241 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11242 + * @path is a switch to distinguish load and store.
11244 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11245 + struct au_branch *br, const struct path *path)
11248 + unsigned char load, suspend;
11249 + struct file *hinofile;
11250 + struct au_hinode *hdir;
11251 + struct inode *dir, *delegated;
11252 + struct path hinopath;
11253 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11254 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11256 + AuDebugOn(bindex < 0 && !br);
11257 + AuDebugOn(bindex >= 0 && br);
11262 + br = au_sbr(sb, bindex);
11265 + path = &br->br_path;
11266 + AuDebugOn(!au_br_writable(br->br_perm));
11267 + if (unlikely(!au_br_writable(br->br_perm)))
11273 + dir = d_inode(sb->s_root);
11274 + hdir = au_hinode(au_ii(dir), bindex);
11275 + dir = hdir->hi_inode;
11276 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11278 + dir = d_inode(path->dentry);
11279 + inode_lock_nested(dir, AuLsc_I_CHILD);
11281 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11282 + err = PTR_ERR(hinopath.dentry);
11283 + if (IS_ERR(hinopath.dentry))
11287 + flags = O_RDONLY;
11289 + if (d_is_negative(hinopath.dentry))
11290 + goto out_dput; /* success */
11292 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11293 + if (d_is_positive(hinopath.dentry)) {
11294 + delegated = NULL;
11295 + err = vfsub_unlink(dir, &hinopath, &delegated,
11298 + if (unlikely(err))
11299 + pr_err("ignored err %d, %pd2\n",
11300 + err, hinopath.dentry);
11301 + if (unlikely(err == -EWOULDBLOCK))
11306 + } else if (!d_is_positive(hinopath.dentry)) {
11307 + err = vfsub_create(dir, &hinopath, 0600,
11308 + /*want_excl*/false);
11310 + if (unlikely(err))
11313 + flags = O_WRONLY;
11315 + hinopath.mnt = path->mnt;
11316 + hinofile = vfsub_dentry_open(&hinopath, flags);
11318 + au_hn_inode_unlock(hdir);
11320 + inode_unlock(dir);
11321 + dput(hinopath.dentry);
11322 + AuTraceErrPtr(hinofile);
11323 + if (IS_ERR(hinofile)) {
11324 + err = PTR_ERR(hinofile);
11329 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11331 + err = au_dr_hino_store(sb, br, hinofile);
11336 + dput(hinopath.dentry);
11339 + au_hn_inode_unlock(hdir);
11341 + inode_unlock(dir);
11347 +/* ---------------------------------------------------------------------- */
11349 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11352 + struct kstatfs kstfs;
11354 + struct dentry *dentry;
11355 + struct super_block *sb;
11357 + err = vfs_statfs((void *)path, &kstfs);
11359 + if (unlikely(err))
11362 + /* todo: support for UUID */
11364 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11365 + brid->type = AuBrid_FSID;
11366 + brid->fsid = kstfs.f_fsid;
11368 + dentry = path->dentry;
11369 + sb = dentry->d_sb;
11372 + brid->type = AuBrid_DEV;
11381 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11382 + const struct path *path)
11385 + struct au_dr_br *dr;
11386 + struct hlist_bl_head *hbl;
11388 + dr = &br->br_dirren;
11389 + hbl = dr->dr_h_ino;
11390 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11391 + INIT_HLIST_BL_HEAD(hbl);
11393 + err = au_dr_brid_init(&dr->dr_brid, path);
11394 + if (unlikely(err))
11397 + if (au_opt_test(au_mntflags(sb), DIRREN))
11398 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11405 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11410 + if (au_br_writable(br->br_perm))
11411 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11413 + au_dr_hino_free(&br->br_dirren);
11418 +/* ---------------------------------------------------------------------- */
11420 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11421 + char *buf, size_t sz)
11424 + unsigned int major, minor;
11428 + err = snprintf(p, sz, "%d_", brid->type);
11429 + AuDebugOn(err > sz);
11432 + switch (brid->type) {
11433 + case AuBrid_Unset:
11435 + case AuBrid_UUID:
11436 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11438 + case AuBrid_FSID:
11439 + err = snprintf(p, sz, "%08x-%08x",
11440 + brid->fsid.val[0], brid->fsid.val[1]);
11443 + major = MAJOR(brid->dev);
11444 + minor = MINOR(brid->dev);
11445 + if (major <= 0xff && minor <= 0xff)
11446 + err = snprintf(p, sz, "%02x%02x", major, minor);
11448 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11451 + AuDebugOn(err > sz);
11454 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11455 + AuDebugOn(err > sz);
11462 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11465 + struct dentry *br_dentry;
11466 + struct inode *br_inode;
11468 + br_dentry = au_br_dentry(br);
11469 + br_inode = d_inode(br_dentry);
11470 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11471 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11472 + AuDebugOn(rlen > len);
11477 +/* ---------------------------------------------------------------------- */
11480 + * from the given @h_dentry, construct drinfo at @*fdata.
11481 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11484 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11485 + struct dentry *h_dentry,
11486 + unsigned char *allocated)
11489 + struct au_drinfo_fdata *f, *p;
11490 + struct au_drinfo *drinfo;
11491 + struct inode *h_inode;
11492 + struct qstr *qname;
11496 + h_inode = d_inode(h_dentry);
11497 + qname = &h_dentry->d_name;
11498 + drinfo = &f->drinfo;
11499 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11500 + drinfo->oldnamelen = qname->len;
11501 + if (*allocated < sizeof(*f) + qname->len) {
11502 + v = roundup_pow_of_two(*allocated + qname->len);
11503 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11504 + if (unlikely(!p)) {
11512 + drinfo = &f->drinfo;
11514 + memcpy(drinfo->oldname, qname->name, qname->len);
11515 + AuDbg("i%llu, %.*s\n",
11516 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11517 + drinfo->oldname);
11524 +/* callers have to free the return value */
11525 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11527 + struct au_drinfo *ret, *drinfo;
11528 + struct au_drinfo_fdata fdata;
11533 + ret = ERR_PTR(-EIO);
11535 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11536 + if (unlikely(ssz != sizeof(fdata))) {
11537 + AuIOErr("ssz %zd, %u, %pD2\n",
11538 + ssz, (unsigned int)sizeof(fdata), file);
11542 + fdata.magic = ntohl((__force __be32)fdata.magic);
11543 + switch (fdata.magic) {
11544 + case AUFS_DRINFO_MAGIC_V1:
11547 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11548 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11552 + drinfo = &fdata.drinfo;
11553 + len = drinfo->oldnamelen;
11555 + AuIOErr("broken drinfo %pD2\n", file);
11560 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11561 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11562 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11563 + (unsigned long long)drinfo->ino,
11564 + (unsigned long long)h_ino, file);
11565 + goto out; /* success */
11568 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11569 + if (unlikely(!ret)) {
11570 + ret = ERR_PTR(-ENOMEM);
11571 + AuTraceErrPtr(ret);
11576 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11577 + if (unlikely(ssz != len)) {
11578 + au_kfree_rcu(ret);
11579 + ret = ERR_PTR(-EIO);
11580 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11584 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11590 +/* ---------------------------------------------------------------------- */
11592 +/* in order to be revertible */
11593 +struct au_drinfo_rev_elm {
11595 + struct dentry *info_dentry;
11596 + struct au_drinfo *info_last;
11599 +struct au_drinfo_rev {
11600 + unsigned char already;
11601 + aufs_bindex_t nelm;
11602 + struct au_drinfo_rev_elm elm[];
11605 +/* todo: isn't it too large? */
11606 +struct au_drinfo_store {
11607 + struct path h_ppath;
11608 + struct dentry *h_dentry;
11609 + struct au_drinfo_fdata *fdata;
11610 + char *infoname; /* inside of whname, just after PFX */
11611 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11612 + aufs_bindex_t btgt, btail;
11613 + unsigned char no_sio,
11614 + allocated, /* current size of *fdata */
11615 + infonamelen, /* room size for p */
11616 + whnamelen, /* length of the generated name */
11617 + renameback; /* renamed back */
11620 +/* on rename(2) error, the caller should revert it using @elm */
11621 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11622 + struct au_drinfo_rev_elm *elm)
11627 + struct path infopath = {
11628 + .mnt = w->h_ppath.mnt
11630 + struct inode *h_dir, *h_inode, *delegated;
11631 + struct file *infofile;
11632 + struct qstr *qname;
11635 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11637 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11639 + AuTraceErrPtr(infopath.dentry);
11640 + if (IS_ERR(infopath.dentry)) {
11641 + err = PTR_ERR(infopath.dentry);
11646 + h_dir = d_inode(w->h_ppath.dentry);
11647 + if (elm && d_is_negative(infopath.dentry)) {
11648 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11650 + if (unlikely(err))
11652 + elm->created = 1;
11653 + elm->info_dentry = dget(infopath.dentry);
11656 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11657 + AuTraceErrPtr(infofile);
11658 + if (IS_ERR(infofile)) {
11659 + err = PTR_ERR(infofile);
11663 + h_inode = d_inode(infopath.dentry);
11664 + if (elm && i_size_read(h_inode)) {
11665 + h_inode = d_inode(w->h_dentry);
11666 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11667 + AuTraceErrPtr(elm->info_last);
11668 + if (IS_ERR(elm->info_last)) {
11669 + err = PTR_ERR(elm->info_last);
11670 + elm->info_last = NULL;
11671 + AuDebugOn(elm->info_dentry);
11676 + if (elm && w->renameback) {
11677 + delegated = NULL;
11678 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11680 + if (unlikely(err == -EWOULDBLOCK))
11686 + qname = &w->h_dentry->d_name;
11687 + len = sizeof(*w->fdata) + qname->len;
11689 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11690 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11691 + if (ssz == len) {
11692 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11693 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11694 + goto out_fput; /* success */
11699 + /* the caller should revert it using @elm */
11705 + dput(infopath.dentry);
11711 +struct au_call_drinfo_do_store_args {
11713 + struct au_drinfo_store *w;
11714 + struct au_drinfo_rev_elm *elm;
11717 +static void au_call_drinfo_do_store(void *args)
11719 + struct au_call_drinfo_do_store_args *a = args;
11721 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11724 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11725 + struct au_drinfo_rev_elm *elm)
11727 + int err, wkq_err;
11730 + err = au_drinfo_do_store(w, elm);
11732 + struct au_call_drinfo_do_store_args a = {
11737 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11738 + if (unlikely(wkq_err))
11746 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11747 + aufs_bindex_t btgt)
11751 + memset(w, 0, sizeof(*w));
11752 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11753 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11754 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11755 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11757 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11760 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11761 + if (unlikely(!w->fdata)) {
11765 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11772 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11774 + au_kfree_rcu(w->fdata);
11777 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11778 + struct au_drinfo_store *w)
11780 + struct au_drinfo_rev_elm *elm;
11781 + struct inode *h_dir, *delegated;
11783 + struct path infopath = {
11784 + .mnt = w->h_ppath.mnt
11787 + h_dir = d_inode(w->h_ppath.dentry);
11788 + IMustLock(h_dir);
11792 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11793 + AuDebugOn(elm->created && elm->info_last);
11794 + if (elm->created) {
11796 + delegated = NULL;
11797 + infopath.dentry = elm->info_dentry;
11798 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11801 + if (unlikely(err == -EWOULDBLOCK))
11803 + dput(elm->info_dentry);
11804 + } else if (elm->info_last) {
11806 + w->fdata->drinfo = *elm->info_last;
11807 + memcpy(w->fdata->drinfo.oldname,
11808 + elm->info_last->oldname,
11809 + elm->info_last->oldnamelen);
11810 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11811 + au_kfree_rcu(elm->info_last);
11813 + if (unlikely(err))
11814 + AuIOErr("%d, %s\n", err, w->whname);
11815 + /* go on even if err */
11819 +/* caller has to call au_dr_rename_fin() later */
11820 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11821 + struct qstr *dst_name, void *_rev)
11823 + int err, sz, nelm;
11824 + aufs_bindex_t bindex, btail;
11825 + struct au_drinfo_store work;
11826 + struct au_drinfo_rev *rev, **p;
11827 + struct au_drinfo_rev_elm *elm;
11828 + struct super_block *sb;
11829 + struct au_branch *br;
11830 + struct au_hinode *hdir;
11832 + err = au_drinfo_store_work_init(&work, btgt);
11834 + if (unlikely(err))
11838 + btail = au_dbtaildir(dentry);
11839 + nelm = btail - btgt;
11840 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11841 + rev = kcalloc(1, sz, GFP_NOFS);
11842 + if (unlikely(!rev)) {
11846 + rev->nelm = nelm;
11852 + sb = dentry->d_sb;
11853 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11854 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11855 + hdir = au_hi(d_inode(dentry), btgt);
11856 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11857 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11858 + work.h_dentry = au_h_dptr(dentry, bindex);
11859 + if (!work.h_dentry)
11862 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11863 + &work.allocated);
11865 + if (unlikely(err))
11868 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11869 + br = au_sbr(sb, bindex);
11870 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11871 + work.whnamelen += au_drinfo_name(br, work.infoname,
11872 + work.infonamelen);
11873 + AuDbg("whname %.*s, i%llu, %.*s\n",
11874 + work.whnamelen, work.whname,
11875 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11876 + work.fdata->drinfo.oldnamelen,
11877 + work.fdata->drinfo.oldname);
11879 + err = au_drinfo_store_sio(&work, elm);
11881 + if (unlikely(err))
11884 + if (unlikely(err)) {
11885 + /* revert all drinfo */
11886 + au_drinfo_store_rev(rev, &work);
11887 + au_kfree_try_rcu(rev);
11890 + au_hn_inode_unlock(hdir);
11893 + au_drinfo_store_work_fin(&work);
11898 +/* ---------------------------------------------------------------------- */
11900 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11901 + struct qstr *dst_name, void *_rev)
11903 + int err, already;
11905 + struct super_block *sb;
11906 + struct au_branch *br;
11907 + struct au_dr_br *dr;
11908 + struct dentry *h_dentry;
11909 + struct inode *h_inode;
11910 + struct au_dr_hino *ent;
11911 + struct au_drinfo_rev *rev, **p;
11913 + AuDbg("bindex %d\n", bindex);
11916 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11917 + if (unlikely(!ent))
11921 + br = au_sbr(sb, bindex);
11922 + dr = &br->br_dirren;
11923 + h_dentry = au_h_dptr(src, bindex);
11924 + h_inode = d_inode(h_dentry);
11925 + ino = h_inode->i_ino;
11926 + ent->dr_h_ino = ino;
11927 + already = au_dr_hino_test_add(dr, ino, ent);
11928 + AuDbg("b%d, hi%llu, already %d\n",
11929 + bindex, (unsigned long long)ino, already);
11931 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11936 + rev->already = already;
11937 + goto out; /* success */
11942 + au_dr_hino_del(dr, ent);
11943 + au_kfree_rcu(ent);
11950 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11952 + struct au_drinfo_rev *rev;
11953 + struct au_drinfo_rev_elm *elm;
11958 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11959 + dput(elm->info_dentry);
11960 + au_kfree_rcu(elm->info_last);
11962 + au_kfree_try_rcu(rev);
11965 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11968 + struct au_drinfo_store work;
11969 + struct au_drinfo_rev *rev = _rev;
11970 + struct super_block *sb;
11971 + struct au_branch *br;
11972 + struct inode *h_inode;
11973 + struct au_dr_br *dr;
11974 + struct au_dr_hino *ent;
11976 + err = au_drinfo_store_work_init(&work, btgt);
11977 + if (unlikely(err))
11981 + br = au_sbr(sb, btgt);
11982 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11983 + work.h_ppath.mnt = au_br_mnt(br);
11984 + au_drinfo_store_rev(rev, &work);
11985 + au_drinfo_store_work_fin(&work);
11986 + if (rev->already)
11989 + dr = &br->br_dirren;
11990 + h_inode = d_inode(work.h_ppath.dentry);
11991 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11993 + au_dr_hino_del(dr, ent);
11994 + au_kfree_rcu(ent);
11997 + au_kfree_try_rcu(rev);
11998 + if (unlikely(err))
11999 + pr_err("failed to remove dirren info\n");
12002 +/* ---------------------------------------------------------------------- */
12004 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
12005 + char *whname, int whnamelen,
12006 + struct dentry **info_dentry)
12008 + struct au_drinfo *drinfo;
12010 + struct inode *h_dir;
12011 + struct path infopath;
12014 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
12016 + *info_dentry = NULL;
12019 + h_dir = d_inode(h_ppath->dentry);
12020 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
12021 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
12023 + if (IS_ERR(infopath.dentry)) {
12024 + drinfo = (void *)infopath.dentry;
12028 + if (d_is_negative(infopath.dentry))
12029 + goto out_dput; /* success */
12031 + infopath.mnt = h_ppath->mnt;
12032 + f = vfsub_dentry_open(&infopath, O_RDONLY);
12033 + inode_unlock_shared(h_dir);
12036 + drinfo = (void *)f;
12040 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
12041 + if (IS_ERR_OR_NULL(drinfo))
12044 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
12045 + *info_dentry = dget(infopath.dentry); /* keep it alive */
12050 + dput(infopath.dentry);
12053 + inode_unlock_shared(h_dir);
12054 + AuTraceErrPtr(drinfo);
12058 +struct au_drinfo_do_load_args {
12059 + struct au_drinfo **drinfop;
12060 + struct path *h_ppath;
12063 + struct dentry **info_dentry;
12066 +static void au_call_drinfo_do_load(void *args)
12068 + struct au_drinfo_do_load_args *a = args;
12070 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
12074 +struct au_drinfo_load {
12075 + struct path h_ppath;
12076 + struct qstr *qname;
12077 + unsigned char no_sio;
12079 + aufs_bindex_t ninfo;
12080 + struct au_drinfo **drinfo;
12083 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
12084 + struct au_branch *br)
12086 + int err, wkq_err, whnamelen, e;
12087 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
12088 + = AUFS_WH_DR_INFO_PFX;
12089 + struct au_drinfo *drinfo;
12090 + struct qstr oldname;
12091 + struct inode *h_dir, *delegated;
12092 + struct dentry *info_dentry;
12093 + struct path infopath;
12095 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
12096 + whnamelen += au_drinfo_name(br, whname + whnamelen,
12097 + sizeof(whname) - whnamelen);
12099 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
12102 + struct au_drinfo_do_load_args args = {
12103 + .drinfop = &drinfo,
12104 + .h_ppath = &w->h_ppath,
12105 + .whname = whname,
12106 + .whnamelen = whnamelen,
12107 + .info_dentry = &info_dentry
12109 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
12110 + if (unlikely(wkq_err))
12111 + drinfo = ERR_PTR(wkq_err);
12113 + err = PTR_ERR(drinfo);
12114 + if (IS_ERR_OR_NULL(drinfo))
12118 + oldname.len = drinfo->oldnamelen;
12119 + oldname.name = drinfo->oldname;
12120 + if (au_qstreq(w->qname, &oldname)) {
12121 + /* the name is renamed back */
12122 + au_kfree_rcu(drinfo);
12125 + infopath.dentry = info_dentry;
12126 + infopath.mnt = w->h_ppath.mnt;
12127 + h_dir = d_inode(w->h_ppath.dentry);
12128 + delegated = NULL;
12129 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12130 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12131 + inode_unlock(h_dir);
12133 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12134 + if (unlikely(e == -EWOULDBLOCK))
12137 + au_kfree_rcu(w->drinfo[bindex]);
12138 + w->drinfo[bindex] = drinfo;
12139 + dput(info_dentry);
12146 +/* ---------------------------------------------------------------------- */
12148 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12150 + struct au_drinfo **p = drinfo;
12153 + au_kfree_rcu(*drinfo++);
12154 + au_kfree_try_rcu(p);
12157 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12158 + aufs_bindex_t btgt)
12161 + struct au_drinfo_load w;
12162 + aufs_bindex_t bindex, bbot;
12163 + struct au_branch *br;
12164 + struct inode *h_dir;
12165 + struct au_dr_hino *ent;
12166 + struct super_block *sb;
12168 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12169 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12170 + AuLNPair(&lkup->whname), btgt);
12172 + sb = dentry->d_sb;
12173 + bbot = au_sbbot(sb);
12174 + w.ninfo = bbot + 1;
12175 + if (!lkup->dirren.drinfo) {
12176 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12177 + sizeof(*lkup->dirren.drinfo),
12179 + if (unlikely(!lkup->dirren.drinfo)) {
12183 + lkup->dirren.ninfo = w.ninfo;
12185 + w.drinfo = lkup->dirren.drinfo;
12186 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12187 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12188 + AuDebugOn(!w.h_ppath.dentry);
12189 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12190 + w.qname = &dentry->d_name;
12193 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12194 + br = au_sbr(sb, bindex);
12195 + err = au_drinfo_load(&w, bindex, br);
12196 + if (unlikely(err))
12198 + if (w.drinfo[bindex])
12202 + br = au_sbr(sb, btgt);
12203 + h_dir = d_inode(w.h_ppath.dentry);
12204 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12206 + au_dr_hino_del(&br->br_dirren, ent);
12207 + au_kfree_rcu(ent);
12209 + goto out; /* success */
12212 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12213 + lkup->dirren.ninfo = 0;
12214 + lkup->dirren.drinfo = NULL;
12220 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12222 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12225 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12228 + struct au_drinfo *drinfo;
12231 + if (!lkup->dirren.drinfo)
12233 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12234 + drinfo = lkup->dirren.drinfo[btgt];
12238 + au_kfree_try_rcu(lkup->whname.name);
12239 + lkup->whname.name = NULL;
12240 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12241 + lkup->dirren.dr_name.name = drinfo->oldname;
12242 + lkup->name = &lkup->dirren.dr_name;
12243 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12245 + AuDbg("name %.*s, whname %.*s, b%d\n",
12246 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12254 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12258 + struct au_drinfo *drinfo;
12261 + if (!lkup->dirren.drinfo)
12263 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12264 + drinfo = lkup->dirren.drinfo[bindex];
12268 + match = (drinfo->ino == h_ino);
12269 + AuDbg("match %d\n", match);
12275 +/* ---------------------------------------------------------------------- */
12277 +int au_dr_opt_set(struct super_block *sb)
12280 + aufs_bindex_t bindex, bbot;
12281 + struct au_branch *br;
12284 + bbot = au_sbbot(sb);
12285 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12286 + br = au_sbr(sb, bindex);
12287 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12293 +int au_dr_opt_flush(struct super_block *sb)
12296 + aufs_bindex_t bindex, bbot;
12297 + struct au_branch *br;
12300 + bbot = au_sbbot(sb);
12301 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12302 + br = au_sbr(sb, bindex);
12303 + if (au_br_writable(br->br_perm))
12304 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12310 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12313 + aufs_bindex_t bindex, bbot;
12314 + struct au_branch *br;
12318 + err = au_dr_opt_flush(sb);
12319 + if (unlikely(err))
12323 + bbot = au_sbbot(sb);
12324 + for (bindex = 0; bindex <= bbot; bindex++) {
12325 + br = au_sbr(sb, bindex);
12326 + au_dr_hino_free(&br->br_dirren);
12332 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12333 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12334 +++ linux/fs/aufs/dirren.h 2021-02-22 23:30:37.699347580 +0100
12336 +/* SPDX-License-Identifier: GPL-2.0 */
12338 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12340 + * This program, aufs is free software; you can redistribute it and/or modify
12341 + * it under the terms of the GNU General Public License as published by
12342 + * the Free Software Foundation; either version 2 of the License, or
12343 + * (at your option) any later version.
12345 + * This program is distributed in the hope that it will be useful,
12346 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12347 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12348 + * GNU General Public License for more details.
12350 + * You should have received a copy of the GNU General Public License
12351 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12355 + * renamed dir info
12358 +#ifndef __AUFS_DIRREN_H__
12359 +#define __AUFS_DIRREN_H__
12363 +#include <linux/dcache.h>
12364 +#include <linux/statfs.h>
12365 +#include <linux/uuid.h>
12368 +#define AuDirren_NHASH 100
12370 +#ifdef CONFIG_AUFS_DIRREN
12371 +enum au_brid_type {
12378 +struct au_dr_brid {
12379 + enum au_brid_type type;
12381 + uuid_t uuid; /* unimplemented yet */
12387 +/* 20 is the max digits length of ulong 64 */
12388 +/* brid-type "_" uuid "_" inum */
12389 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12390 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12392 +struct au_dr_hino {
12393 + struct hlist_bl_node dr_hnode;
12398 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12399 + struct au_dr_brid dr_brid;
12402 +struct au_dr_lookup {
12403 + /* dr_name is pointed by struct au_do_lookup_args.name */
12404 + struct qstr dr_name; /* subset of dr_info */
12405 + aufs_bindex_t ninfo;
12406 + struct au_drinfo **drinfo;
12409 +struct au_dr_hino;
12411 +struct au_dr_br { };
12412 +struct au_dr_lookup { };
12415 +/* ---------------------------------------------------------------------- */
12418 +struct au_do_lookup_args;
12420 +#ifdef CONFIG_AUFS_DIRREN
12421 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12422 + struct au_dr_hino *add_ent);
12423 +void au_dr_hino_free(struct au_dr_br *dr);
12424 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12425 + const struct path *path);
12426 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12427 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12428 + struct qstr *dst_name, void *_rev);
12429 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12430 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12431 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12432 + aufs_bindex_t bindex);
12433 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12434 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12436 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12437 +int au_dr_opt_set(struct super_block *sb);
12438 +int au_dr_opt_flush(struct super_block *sb);
12439 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12441 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12442 + struct au_dr_hino *add_ent);
12443 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12444 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12445 + const struct path *path);
12446 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12447 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12448 + struct qstr *dst_name, void *_rev);
12449 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12450 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12452 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12453 + aufs_bindex_t bindex);
12454 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12455 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12456 + aufs_bindex_t bindex, ino_t h_ino);
12457 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12458 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12459 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12460 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12463 +/* ---------------------------------------------------------------------- */
12465 +#ifdef CONFIG_AUFS_DIRREN
12466 +static inline int au_dr_ihash(ino_t h_ino)
12468 + return h_ino % AuDirren_NHASH;
12471 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12474 +#endif /* __KERNEL__ */
12475 +#endif /* __AUFS_DIRREN_H__ */
12476 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12477 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12478 +++ linux/fs/aufs/dynop.c 2021-02-22 23:30:37.699347580 +0100
12480 +// SPDX-License-Identifier: GPL-2.0
12482 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12484 + * This program, aufs is free software; you can redistribute it and/or modify
12485 + * it under the terms of the GNU General Public License as published by
12486 + * the Free Software Foundation; either version 2 of the License, or
12487 + * (at your option) any later version.
12489 + * This program is distributed in the hope that it will be useful,
12490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12492 + * GNU General Public License for more details.
12494 + * You should have received a copy of the GNU General Public License
12495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12499 + * dynamically customizable operations for regular files
12504 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12507 + * How large will these lists be?
12508 + * Usually just a few elements, 20-30 at most for each, I guess.
12510 +static struct hlist_bl_head dynop[AuDyLast];
12512 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12513 + const void *h_op)
12515 + struct au_dykey *key, *tmp;
12516 + struct hlist_bl_node *pos;
12519 + hlist_bl_lock(hbl);
12520 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12521 + if (tmp->dk_op.dy_hop == h_op) {
12522 + if (kref_get_unless_zero(&tmp->dk_kref))
12526 + hlist_bl_unlock(hbl);
12531 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12533 + struct au_dykey **k, *found;
12534 + const void *h_op = key->dk_op.dy_hop;
12538 + k = br->br_dykey;
12539 + for (i = 0; i < AuBrDynOp; i++)
12541 + if (k[i]->dk_op.dy_hop == h_op) {
12548 + spin_lock(&br->br_dykey_lock);
12549 + for (; i < AuBrDynOp; i++)
12551 + if (k[i]->dk_op.dy_hop == h_op) {
12559 + spin_unlock(&br->br_dykey_lock);
12560 + BUG_ON(i == AuBrDynOp); /* expand the array */
12566 +/* kref_get() if @key is already added */
12567 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12569 + struct au_dykey *tmp, *found;
12570 + struct hlist_bl_node *pos;
12571 + const void *h_op = key->dk_op.dy_hop;
12574 + hlist_bl_lock(hbl);
12575 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12576 + if (tmp->dk_op.dy_hop == h_op) {
12577 + if (kref_get_unless_zero(&tmp->dk_kref))
12582 + hlist_bl_add_head(&key->dk_hnode, hbl);
12583 + hlist_bl_unlock(hbl);
12590 +static void dy_free_rcu(struct rcu_head *rcu)
12592 + struct au_dykey *key;
12594 + key = container_of(rcu, struct au_dykey, dk_rcu);
12599 +static void dy_free(struct kref *kref)
12601 + struct au_dykey *key;
12602 + struct hlist_bl_head *hbl;
12604 + key = container_of(kref, struct au_dykey, dk_kref);
12605 + hbl = dynop + key->dk_op.dy_type;
12606 + au_hbl_del(&key->dk_hnode, hbl);
12607 + call_rcu(&key->dk_rcu, dy_free_rcu);
12610 +void au_dy_put(struct au_dykey *key)
12612 + kref_put(&key->dk_kref, dy_free);
12615 +/* ---------------------------------------------------------------------- */
12617 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12619 +#ifdef CONFIG_AUFS_DEBUG
12620 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12621 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12623 +#define DyDbgDeclare(cnt) do {} while (0)
12624 +#define DyDbgInc(cnt) do {} while (0)
12627 +#define DySet(func, dst, src, h_op, h_sb) do { \
12629 + if (h_op->func) { \
12631 + dst.func = src.func; \
12633 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12637 +#define DySetForce(func, dst, src) do { \
12638 + AuDebugOn(!src.func); \
12640 + dst.func = src.func; \
12643 +#define DySetAop(func) \
12644 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12645 +#define DySetAopForce(func) \
12646 + DySetForce(func, dyaop->da_op, aufs_aop)
12648 +static void dy_aop(struct au_dykey *key, const void *h_op,
12649 + struct super_block *h_sb __maybe_unused)
12651 + struct au_dyaop *dyaop = (void *)key;
12652 + const struct address_space_operations *h_aop = h_op;
12653 + DyDbgDeclare(cnt);
12655 + AuDbg("%s\n", au_sbtype(h_sb));
12657 + DySetAop(writepage);
12658 + DySetAopForce(readpage); /* force */
12659 + DySetAop(writepages);
12660 + DySetAop(set_page_dirty);
12661 + DySetAop(readpages);
12662 + DySetAop(write_begin);
12663 + DySetAop(write_end);
12665 + DySetAop(invalidatepage);
12666 + DySetAop(releasepage);
12667 + DySetAop(freepage);
12668 + /* this one will be changed according to an aufs mount option */
12669 + DySetAop(direct_IO);
12670 + DySetAop(migratepage);
12671 + DySetAop(isolate_page);
12672 + DySetAop(putback_page);
12673 + DySetAop(launder_page);
12674 + DySetAop(is_partially_uptodate);
12675 + DySetAop(is_dirty_writeback);
12676 + DySetAop(error_remove_page);
12677 + DySetAop(swap_activate);
12678 + DySetAop(swap_deactivate);
12680 + DyDbgSize(cnt, *h_aop);
12683 +/* ---------------------------------------------------------------------- */
12685 +static void dy_bug(struct kref *kref)
12690 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12692 + struct au_dykey *key, *old;
12693 + struct hlist_bl_head *hbl;
12696 + void (*set)(struct au_dykey *key, const void *h_op,
12697 + struct super_block *h_sb __maybe_unused);
12699 + static const struct op a[] = {
12701 + .sz = sizeof(struct au_dyaop),
12705 + const struct op *p;
12707 + hbl = dynop + op->dy_type;
12708 + key = dy_gfind_get(hbl, op->dy_hop);
12710 + goto out_add; /* success */
12712 + p = a + op->dy_type;
12713 + key = kzalloc(p->sz, GFP_NOFS);
12714 + if (unlikely(!key)) {
12715 + key = ERR_PTR(-ENOMEM);
12719 + key->dk_op.dy_hop = op->dy_hop;
12720 + kref_init(&key->dk_kref);
12721 + p->set(key, op->dy_hop, au_br_sb(br));
12722 + old = dy_gadd(hbl, key);
12724 + au_kfree_rcu(key);
12729 + old = dy_bradd(br, key);
12731 + /* its ref-count should never be zero here */
12732 + kref_put(&key->dk_kref, dy_bug);
12737 +/* ---------------------------------------------------------------------- */
12739 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12740 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12741 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12742 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12743 + * See the aufs manual in detail.
12745 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12748 + dyaop->da_op.direct_IO = NULL;
12750 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12753 +static struct au_dyaop *dy_aget(struct au_branch *br,
12754 + const struct address_space_operations *h_aop,
12757 + struct au_dyaop *dyaop;
12758 + struct au_dynop op;
12760 + op.dy_type = AuDy_AOP;
12761 + op.dy_haop = h_aop;
12762 + dyaop = (void *)dy_get(&op, br);
12763 + if (IS_ERR(dyaop))
12765 + dy_adx(dyaop, do_dx);
12771 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12772 + struct inode *h_inode)
12775 + struct super_block *sb;
12776 + struct au_branch *br;
12777 + struct au_dyaop *dyaop;
12779 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12780 + IiMustWriteLock(inode);
12782 + sb = inode->i_sb;
12783 + br = au_sbr(sb, bindex);
12784 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12785 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12786 + err = PTR_ERR(dyaop);
12787 + if (IS_ERR(dyaop))
12788 + /* unnecessary to call dy_fput() */
12792 + inode->i_mapping->a_ops = &dyaop->da_op;
12799 + * Is it safe to replace a_ops during the inode/file is in operation?
12800 + * Yes, I hope so.
12802 +int au_dy_irefresh(struct inode *inode)
12805 + aufs_bindex_t btop;
12806 + struct inode *h_inode;
12809 + if (S_ISREG(inode->i_mode)) {
12810 + btop = au_ibtop(inode);
12811 + h_inode = au_h_iptr(inode, btop);
12812 + err = au_dy_iaop(inode, btop, h_inode);
12817 +void au_dy_arefresh(int do_dx)
12819 + struct hlist_bl_head *hbl;
12820 + struct hlist_bl_node *pos;
12821 + struct au_dykey *key;
12823 + hbl = dynop + AuDy_AOP;
12824 + hlist_bl_lock(hbl);
12825 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12826 + dy_adx((void *)key, do_dx);
12827 + hlist_bl_unlock(hbl);
12830 +/* ---------------------------------------------------------------------- */
12832 +void __init au_dy_init(void)
12836 + /* make sure that 'struct au_dykey *' can be any type */
12837 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
12839 + for (i = 0; i < AuDyLast; i++)
12840 + INIT_HLIST_BL_HEAD(dynop + i);
12843 +void au_dy_fin(void)
12847 + for (i = 0; i < AuDyLast; i++)
12848 + WARN_ON(!hlist_bl_empty(dynop + i));
12850 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12851 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12852 +++ linux/fs/aufs/dynop.h 2021-02-22 23:30:37.699347580 +0100
12854 +/* SPDX-License-Identifier: GPL-2.0 */
12856 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12858 + * This program, aufs is free software; you can redistribute it and/or modify
12859 + * it under the terms of the GNU General Public License as published by
12860 + * the Free Software Foundation; either version 2 of the License, or
12861 + * (at your option) any later version.
12863 + * This program is distributed in the hope that it will be useful,
12864 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12865 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12866 + * GNU General Public License for more details.
12868 + * You should have received a copy of the GNU General Public License
12869 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12873 + * dynamically customizable operations (for regular files only)
12876 +#ifndef __AUFS_DYNOP_H__
12877 +#define __AUFS_DYNOP_H__
12881 +#include <linux/fs.h>
12882 +#include <linux/kref.h>
12884 +enum {AuDy_AOP, AuDyLast};
12889 + const void *dy_hop;
12890 + const struct address_space_operations *dy_haop;
12896 + struct hlist_bl_node dk_hnode;
12897 + struct rcu_head dk_rcu;
12899 + struct au_dynop dk_op;
12902 + * during I am in the branch local array, kref is gotten. when the
12903 + * branch is removed, kref is put.
12905 + struct kref dk_kref;
12908 +/* stop unioning since their sizes are very different from each other */
12910 + struct au_dykey da_key;
12911 + struct address_space_operations da_op; /* not const */
12914 +/* ---------------------------------------------------------------------- */
12918 +void au_dy_put(struct au_dykey *key);
12919 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12920 + struct inode *h_inode);
12921 +int au_dy_irefresh(struct inode *inode);
12922 +void au_dy_arefresh(int do_dio);
12924 +void __init au_dy_init(void);
12925 +void au_dy_fin(void);
12927 +#endif /* __KERNEL__ */
12928 +#endif /* __AUFS_DYNOP_H__ */
12929 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12930 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12931 +++ linux/fs/aufs/export.c 2021-02-22 23:30:37.699347580 +0100
12933 +// SPDX-License-Identifier: GPL-2.0
12935 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12937 + * This program, aufs is free software; you can redistribute it and/or modify
12938 + * it under the terms of the GNU General Public License as published by
12939 + * the Free Software Foundation; either version 2 of the License, or
12940 + * (at your option) any later version.
12942 + * This program is distributed in the hope that it will be useful,
12943 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12944 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12945 + * GNU General Public License for more details.
12947 + * You should have received a copy of the GNU General Public License
12948 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12955 +#include <linux/exportfs.h>
12956 +#include <linux/fs_struct.h>
12957 +#include <linux/namei.h>
12958 +#include <linux/nsproxy.h>
12959 +#include <linux/random.h>
12960 +#include <linux/writeback.h>
12964 +#ifdef CONFIG_AUFS_INO_T_64
12972 +static ino_t decode_ino(__u32 *a)
12976 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12978 +#ifdef CONFIG_AUFS_INO_T_64
12984 +static void encode_ino(__u32 *a, ino_t ino)
12990 +#ifdef CONFIG_AUFS_INO_T_64
12995 +/* NFS file handle */
12999 +#ifdef CONFIG_AUFS_INO_T_64
13000 + /* support 64bit inode number */
13013 + Fh_ino = Fh_ino1,
13014 + Fh_dir_ino = Fh_dir_ino1
13017 +static int au_test_anon(struct dentry *dentry)
13019 + /* note: read d_flags without d_lock */
13020 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
13023 +int au_test_nfsd(void)
13026 + struct task_struct *tsk = current;
13027 + char comm[sizeof(tsk->comm)];
13030 + if (tsk->flags & PF_KTHREAD) {
13031 + get_task_comm(comm, tsk);
13032 + ret = !strcmp(comm, "nfsd");
13038 +/* ---------------------------------------------------------------------- */
13039 +/* inode generation external table */
13041 +void au_xigen_inc(struct inode *inode)
13046 + struct super_block *sb;
13047 + struct au_sbinfo *sbinfo;
13049 + sb = inode->i_sb;
13050 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
13052 + sbinfo = au_sbi(sb);
13053 + pos = inode->i_ino;
13054 + pos *= sizeof(igen);
13055 + igen = inode->i_generation + 1;
13056 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
13057 + sizeof(igen), &pos);
13058 + if (sz == sizeof(igen))
13059 + return; /* success */
13061 + if (unlikely(sz >= 0))
13062 + AuIOErr("xigen error (%zd)\n", sz);
13065 +int au_xigen_new(struct inode *inode)
13070 + struct super_block *sb;
13071 + struct au_sbinfo *sbinfo;
13072 + struct file *file;
13075 + /* todo: dirty, at mount time */
13076 + if (inode->i_ino == AUFS_ROOT_INO)
13078 + sb = inode->i_sb;
13079 + SiMustAnyLock(sb);
13080 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13084 + pos = inode->i_ino;
13085 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
13086 + AuIOErr1("too large i%lld\n", pos);
13089 + pos *= sizeof(inode->i_generation);
13092 + sbinfo = au_sbi(sb);
13093 + file = sbinfo->si_xigen;
13096 + if (vfsub_f_size_read(file)
13097 + < pos + sizeof(inode->i_generation)) {
13098 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
13099 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
13100 + sizeof(inode->i_generation), &pos);
13102 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
13103 + sizeof(inode->i_generation), &pos);
13104 + if (sz == sizeof(inode->i_generation))
13105 + goto out; /* success */
13108 + if (unlikely(sz >= 0)) {
13110 + AuIOErr("xigen error (%zd)\n", sz);
13117 +int au_xigen_set(struct super_block *sb, struct path *path)
13120 + struct au_sbinfo *sbinfo;
13121 + struct file *file;
13123 + SiMustWriteLock(sb);
13125 + sbinfo = au_sbi(sb);
13126 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13127 + err = PTR_ERR(file);
13128 + if (IS_ERR(file))
13131 + if (sbinfo->si_xigen)
13132 + fput(sbinfo->si_xigen);
13133 + sbinfo->si_xigen = file;
13140 +void au_xigen_clr(struct super_block *sb)
13142 + struct au_sbinfo *sbinfo;
13144 + SiMustWriteLock(sb);
13146 + sbinfo = au_sbi(sb);
13147 + if (sbinfo->si_xigen) {
13148 + fput(sbinfo->si_xigen);
13149 + sbinfo->si_xigen = NULL;
13153 +/* ---------------------------------------------------------------------- */
13155 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13158 + struct dentry *dentry, *d;
13159 + struct inode *inode;
13160 + unsigned int sigen;
13163 + inode = ilookup(sb, ino);
13167 + dentry = ERR_PTR(-ESTALE);
13168 + sigen = au_sigen(sb);
13169 + if (unlikely(au_is_bad_inode(inode)
13170 + || IS_DEADDIR(inode)
13171 + || sigen != au_iigen(inode, NULL)))
13175 + if (!dir_ino || S_ISDIR(inode->i_mode))
13176 + dentry = d_find_alias(inode);
13178 + spin_lock(&inode->i_lock);
13179 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13180 + spin_lock(&d->d_lock);
13181 + if (!au_test_anon(d)
13182 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13183 + dentry = dget_dlock(d);
13184 + spin_unlock(&d->d_lock);
13187 + spin_unlock(&d->d_lock);
13189 + spin_unlock(&inode->i_lock);
13191 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13192 + /* need to refresh */
13200 + AuTraceErrPtr(dentry);
13204 +/* ---------------------------------------------------------------------- */
13206 +/* todo: dirty? */
13207 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13209 +struct au_compare_mnt_args {
13211 + struct super_block *sb;
13214 + struct vfsmount *mnt;
13217 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13219 + struct au_compare_mnt_args *a = arg;
13221 + if (mnt->mnt_sb != a->sb)
13223 + a->mnt = mntget(mnt);
13227 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13230 + struct path root;
13231 + struct au_compare_mnt_args args = {
13235 + get_fs_root(current->fs, &root);
13237 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13238 + rcu_read_unlock();
13241 + AuDebugOn(!args.mnt);
13245 +struct au_nfsd_si_lock {
13246 + unsigned int sigen;
13247 + aufs_bindex_t bindex, br_id;
13248 + unsigned char force_lock;
13251 +static int si_nfsd_read_lock(struct super_block *sb,
13252 + struct au_nfsd_si_lock *nsi_lock)
13255 + aufs_bindex_t bindex;
13257 + si_read_lock(sb, AuLock_FLUSH);
13259 + /* branch id may be wrapped around */
13261 + bindex = au_br_index(sb, nsi_lock->br_id);
13262 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13263 + goto out; /* success */
13267 + if (!nsi_lock->force_lock)
13268 + si_read_unlock(sb);
13271 + nsi_lock->bindex = bindex;
13275 +struct find_name_by_ino {
13276 + struct dir_context ctx;
13277 + int called, found;
13284 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13285 + loff_t offset, u64 ino, unsigned int d_type)
13287 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13291 + if (a->ino != ino)
13294 + memcpy(a->name, name, namelen);
13295 + a->namelen = namelen;
13300 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13301 + struct au_nfsd_si_lock *nsi_lock)
13303 + struct dentry *dentry, *parent;
13304 + struct file *file;
13305 + struct inode *dir;
13306 + struct find_name_by_ino arg = {
13308 + .actor = find_name_by_ino
13313 + parent = path->dentry;
13315 + si_read_unlock(parent->d_sb);
13316 + file = vfsub_dentry_open(path, au_dir_roflags);
13317 + dentry = (void *)file;
13318 + if (IS_ERR(file))
13321 + dentry = ERR_PTR(-ENOMEM);
13322 + arg.name = (void *)__get_free_page(GFP_NOFS);
13323 + if (unlikely(!arg.name))
13330 + err = vfsub_iterate_dir(file, &arg.ctx);
13331 + } while (!err && !arg.found && arg.called);
13332 + dentry = ERR_PTR(err);
13333 + if (unlikely(err))
13335 + /* instead of ENOENT */
13336 + dentry = ERR_PTR(-ESTALE);
13340 + /* do not call vfsub_lkup_one() */
13341 + dir = d_inode(parent);
13342 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13343 + AuTraceErrPtr(dentry);
13344 + if (IS_ERR(dentry))
13346 + AuDebugOn(au_test_anon(dentry));
13347 + if (unlikely(d_really_is_negative(dentry))) {
13349 + dentry = ERR_PTR(-ENOENT);
13353 + free_page((unsigned long)arg.name);
13357 + if (unlikely(nsi_lock
13358 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13359 + if (!IS_ERR(dentry)) {
13361 + dentry = ERR_PTR(-ESTALE);
13363 + AuTraceErrPtr(dentry);
13367 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13369 + struct au_nfsd_si_lock *nsi_lock)
13371 + struct dentry *dentry;
13372 + struct path path;
13374 + if (dir_ino != AUFS_ROOT_INO) {
13375 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13376 + dentry = path.dentry;
13377 + if (!path.dentry || IS_ERR(path.dentry))
13379 + AuDebugOn(au_test_anon(path.dentry));
13381 + path.dentry = dget(sb->s_root);
13383 + path.mnt = au_mnt_get(sb);
13384 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13388 + AuTraceErrPtr(dentry);
13392 +/* ---------------------------------------------------------------------- */
13394 +static int h_acceptable(void *expv, struct dentry *dentry)
13399 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13400 + char *buf, int len, struct super_block *sb)
13404 + struct path path;
13406 + p = d_path(h_rootpath, buf, len);
13411 + path.mnt = h_rootpath->mnt;
13412 + path.dentry = h_parent;
13413 + p = d_path(&path, buf, len);
13419 + path.mnt = au_mnt_get(sb);
13420 + path.dentry = sb->s_root;
13421 + p = d_path(&path, buf, len - strlen(p));
13422 + mntput(path.mnt);
13426 + p[strlen(p)] = '/';
13429 + AuTraceErrPtr(p);
13434 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13435 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13437 + struct dentry *dentry, *h_parent, *root;
13438 + struct super_block *h_sb;
13439 + char *pathname, *p;
13440 + struct vfsmount *h_mnt;
13441 + struct au_branch *br;
13443 + struct path path;
13445 + br = au_sbr(sb, nsi_lock->bindex);
13446 + h_mnt = au_br_mnt(br);
13447 + h_sb = h_mnt->mnt_sb;
13448 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13450 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13451 + fh_len - Fh_tail, fh[Fh_h_type],
13452 + h_acceptable, /*context*/NULL);
13454 + dentry = h_parent;
13455 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13456 + AuWarn1("%s decode_fh failed, %ld\n",
13457 + au_sbtype(h_sb), PTR_ERR(h_parent));
13461 + if (unlikely(au_test_anon(h_parent))) {
13462 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13463 + au_sbtype(h_sb));
13464 + goto out_h_parent;
13467 + dentry = ERR_PTR(-ENOMEM);
13468 + pathname = (void *)__get_free_page(GFP_NOFS);
13469 + if (unlikely(!pathname))
13470 + goto out_h_parent;
13472 + root = sb->s_root;
13473 + path.mnt = h_mnt;
13474 + di_read_lock_parent(root, !AuLock_IR);
13475 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13476 + di_read_unlock(root, !AuLock_IR);
13477 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13478 + dentry = (void *)p;
13480 + goto out_pathname;
13482 + si_read_unlock(sb);
13483 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13484 + dentry = ERR_PTR(err);
13485 + if (unlikely(err))
13488 + dentry = ERR_PTR(-ENOENT);
13489 + AuDebugOn(au_test_anon(path.dentry));
13490 + if (unlikely(d_really_is_negative(path.dentry)))
13493 + if (ino != d_inode(path.dentry)->i_ino)
13494 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13496 + dentry = dget(path.dentry);
13501 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13502 + if (!IS_ERR(dentry)) {
13504 + dentry = ERR_PTR(-ESTALE);
13507 + free_page((unsigned long)pathname);
13511 + AuTraceErrPtr(dentry);
13515 +/* ---------------------------------------------------------------------- */
13517 +static struct dentry *
13518 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13521 + struct dentry *dentry;
13522 + __u32 *fh = fid->raw;
13523 + struct au_branch *br;
13524 + ino_t ino, dir_ino;
13525 + struct au_nfsd_si_lock nsi_lock = {
13529 + dentry = ERR_PTR(-ESTALE);
13530 + /* it should never happen, but the file handle is unreliable */
13531 + if (unlikely(fh_len < Fh_tail))
13533 + nsi_lock.sigen = fh[Fh_sigen];
13534 + nsi_lock.br_id = fh[Fh_br_id];
13536 + /* branch id may be wrapped around */
13538 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13540 + nsi_lock.force_lock = 1;
13542 + /* is this inode still cached? */
13543 + ino = decode_ino(fh + Fh_ino);
13544 + /* it should never happen */
13545 + if (unlikely(ino == AUFS_ROOT_INO))
13548 + dir_ino = decode_ino(fh + Fh_dir_ino);
13549 + dentry = decode_by_ino(sb, ino, dir_ino);
13550 + if (IS_ERR(dentry))
13555 + /* is the parent dir cached? */
13556 + br = au_sbr(sb, nsi_lock.bindex);
13557 + au_lcnt_inc(&br->br_nfiles);
13558 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13559 + if (IS_ERR(dentry))
13564 + /* lookup path */
13565 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13566 + if (IS_ERR(dentry))
13568 + if (unlikely(!dentry))
13569 + /* todo?: make it ESTALE */
13573 + if (!au_digen_test(dentry, au_sigen(sb))
13574 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13575 + goto out_unlock; /* success */
13578 + dentry = ERR_PTR(-ESTALE);
13581 + au_lcnt_dec(&br->br_nfiles);
13582 + si_read_unlock(sb);
13584 + AuTraceErrPtr(dentry);
13588 +#if 0 /* reserved for future use */
13589 +/* support subtreecheck option */
13590 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13591 + int fh_len, int fh_type)
13593 + struct dentry *parent;
13594 + __u32 *fh = fid->raw;
13597 + dir_ino = decode_ino(fh + Fh_dir_ino);
13598 + parent = decode_by_ino(sb, dir_ino, 0);
13599 + if (IS_ERR(parent))
13602 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13603 + dir_ino, fh, fh_len);
13606 + AuTraceErrPtr(parent);
13611 +/* ---------------------------------------------------------------------- */
13613 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13614 + struct inode *dir)
13617 + aufs_bindex_t bindex;
13618 + struct super_block *sb, *h_sb;
13619 + struct dentry *dentry, *parent, *h_parent;
13620 + struct inode *h_dir;
13621 + struct au_branch *br;
13624 + if (unlikely(*max_len <= Fh_tail)) {
13625 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13629 + err = FILEID_ROOT;
13630 + if (inode->i_ino == AUFS_ROOT_INO) {
13631 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13636 + sb = inode->i_sb;
13637 + err = si_read_lock(sb, AuLock_FLUSH);
13638 + if (unlikely(err))
13641 +#ifdef CONFIG_AUFS_DEBUG
13642 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13643 + AuWarn1("NFS-exporting requires xino\n");
13647 + ii_read_lock_child(inode);
13648 + bindex = au_ibtop(inode);
13650 + dentry = d_find_any_alias(inode);
13651 + if (unlikely(!dentry))
13653 + AuDebugOn(au_test_anon(dentry));
13654 + parent = dget_parent(dentry);
13656 + if (unlikely(!parent))
13658 + if (d_really_is_positive(parent))
13659 + dir = d_inode(parent);
13662 + ii_read_lock_parent(dir);
13663 + h_dir = au_h_iptr(dir, bindex);
13664 + ii_read_unlock(dir);
13665 + if (unlikely(!h_dir))
13667 + h_parent = d_find_any_alias(h_dir);
13668 + if (unlikely(!h_parent))
13669 + goto out_hparent;
13672 + br = au_sbr(sb, bindex);
13673 + h_sb = au_br_sb(br);
13674 + if (unlikely(!h_sb->s_export_op)) {
13675 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13676 + goto out_hparent;
13679 + fh[Fh_br_id] = br->br_id;
13680 + fh[Fh_sigen] = au_sigen(sb);
13681 + encode_ino(fh + Fh_ino, inode->i_ino);
13682 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13683 + fh[Fh_igen] = inode->i_generation;
13685 + *max_len -= Fh_tail;
13686 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13688 + /*connectable or subtreecheck*/0);
13689 + err = fh[Fh_h_type];
13690 + *max_len += Fh_tail;
13691 + /* todo: macros? */
13692 + if (err != FILEID_INVALID)
13695 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13702 + ii_read_unlock(inode);
13703 + si_read_unlock(sb);
13705 + if (unlikely(err < 0))
13706 + err = FILEID_INVALID;
13710 +/* ---------------------------------------------------------------------- */
13712 +static int aufs_commit_metadata(struct inode *inode)
13715 + aufs_bindex_t bindex;
13716 + struct super_block *sb;
13717 + struct inode *h_inode;
13718 + int (*f)(struct inode *inode);
13720 + sb = inode->i_sb;
13721 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13722 + ii_write_lock_child(inode);
13723 + bindex = au_ibtop(inode);
13724 + AuDebugOn(bindex < 0);
13725 + h_inode = au_h_iptr(inode, bindex);
13727 + f = h_inode->i_sb->s_export_op->commit_metadata;
13729 + err = f(h_inode);
13731 + struct writeback_control wbc = {
13732 + .sync_mode = WB_SYNC_ALL,
13733 + .nr_to_write = 0 /* metadata only */
13736 + err = sync_inode(h_inode, &wbc);
13739 + au_cpup_attr_timesizes(inode);
13740 + ii_write_unlock(inode);
13741 + si_read_unlock(sb);
13745 +/* ---------------------------------------------------------------------- */
13747 +static struct export_operations aufs_export_op = {
13748 + .fh_to_dentry = aufs_fh_to_dentry,
13749 + /* .fh_to_parent = aufs_fh_to_parent, */
13750 + .encode_fh = aufs_encode_fh,
13751 + .commit_metadata = aufs_commit_metadata
13754 +void au_export_init(struct super_block *sb)
13756 + struct au_sbinfo *sbinfo;
13759 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13760 + && IS_MODULE(CONFIG_EXPORTFS),
13761 + AUFS_NAME ": unsupported configuration "
13762 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13764 + sb->s_export_op = &aufs_export_op;
13765 + sbinfo = au_sbi(sb);
13766 + sbinfo->si_xigen = NULL;
13767 + get_random_bytes(&u, sizeof(u));
13768 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13769 + atomic_set(&sbinfo->si_xigen_next, u);
13771 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13772 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13773 +++ linux/fs/aufs/fhsm.c 2021-02-22 23:30:37.699347580 +0100
13775 +// SPDX-License-Identifier: GPL-2.0
13777 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13779 + * This program, aufs is free software; you can redistribute it and/or modify
13780 + * it under the terms of the GNU General Public License as published by
13781 + * the Free Software Foundation; either version 2 of the License, or
13782 + * (at your option) any later version.
13784 + * This program is distributed in the hope that it will be useful,
13785 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13786 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13787 + * GNU General Public License for more details.
13789 + * You should have received a copy of the GNU General Public License
13790 + * along with this program; if not, write to the Free Software
13791 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13795 + * File-based Hierarchy Storage Management
13798 +#include <linux/anon_inodes.h>
13799 +#include <linux/poll.h>
13800 +#include <linux/seq_file.h>
13801 +#include <linux/statfs.h>
13804 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13806 + struct au_sbinfo *sbinfo;
13807 + struct au_fhsm *fhsm;
13809 + SiMustAnyLock(sb);
13811 + sbinfo = au_sbi(sb);
13812 + fhsm = &sbinfo->si_fhsm;
13813 + AuDebugOn(!fhsm);
13814 + return fhsm->fhsm_bottom;
13817 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13819 + struct au_sbinfo *sbinfo;
13820 + struct au_fhsm *fhsm;
13822 + SiMustWriteLock(sb);
13824 + sbinfo = au_sbi(sb);
13825 + fhsm = &sbinfo->si_fhsm;
13826 + AuDebugOn(!fhsm);
13827 + fhsm->fhsm_bottom = bindex;
13830 +/* ---------------------------------------------------------------------- */
13832 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13834 + struct au_br_fhsm *bf;
13836 + bf = br->br_fhsm;
13837 + MtxMustLock(&bf->bf_lock);
13839 + return !bf->bf_readable
13840 + || time_after(jiffies,
13841 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13844 +/* ---------------------------------------------------------------------- */
13846 +static void au_fhsm_notify(struct super_block *sb, int val)
13848 + struct au_sbinfo *sbinfo;
13849 + struct au_fhsm *fhsm;
13851 + SiMustAnyLock(sb);
13853 + sbinfo = au_sbi(sb);
13854 + fhsm = &sbinfo->si_fhsm;
13855 + if (au_fhsm_pid(fhsm)
13856 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13857 + atomic_set(&fhsm->fhsm_readable, val);
13859 + wake_up(&fhsm->fhsm_wqh);
13863 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13864 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13867 + struct au_branch *br;
13868 + struct au_br_fhsm *bf;
13870 + br = au_sbr(sb, bindex);
13871 + AuDebugOn(au_br_rdonly(br));
13872 + bf = br->br_fhsm;
13876 + mutex_lock(&bf->bf_lock);
13878 + MtxMustLock(&bf->bf_lock);
13880 + /* sb->s_root for NFS is unreliable */
13881 + err = au_br_stfs(br, &bf->bf_stfs);
13882 + if (unlikely(err)) {
13883 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13887 + bf->bf_jiffy = jiffies;
13888 + bf->bf_readable = 1;
13890 + au_fhsm_notify(sb, /*val*/1);
13892 + *rstfs = bf->bf_stfs;
13896 + mutex_unlock(&bf->bf_lock);
13897 + au_fhsm_notify(sb, /*val*/1);
13902 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13905 + struct au_sbinfo *sbinfo;
13906 + struct au_fhsm *fhsm;
13907 + struct au_branch *br;
13908 + struct au_br_fhsm *bf;
13910 + AuDbg("b%d, force %d\n", bindex, force);
13911 + SiMustAnyLock(sb);
13913 + sbinfo = au_sbi(sb);
13914 + fhsm = &sbinfo->si_fhsm;
13915 + if (!au_ftest_si(sbinfo, FHSM)
13916 + || fhsm->fhsm_bottom == bindex)
13919 + br = au_sbr(sb, bindex);
13920 + bf = br->br_fhsm;
13922 + mutex_lock(&bf->bf_lock);
13924 + || au_fhsm_pid(fhsm)
13925 + || au_fhsm_test_jiffy(sbinfo, br))
13926 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13928 + mutex_unlock(&bf->bf_lock);
13931 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13933 + aufs_bindex_t bindex, bbot;
13934 + struct au_branch *br;
13936 + /* exclude the bottom */
13937 + bbot = au_fhsm_bottom(sb);
13938 + for (bindex = 0; bindex < bbot; bindex++) {
13939 + br = au_sbr(sb, bindex);
13940 + if (au_br_fhsm(br->br_perm))
13941 + au_fhsm_wrote(sb, bindex, force);
13945 +/* ---------------------------------------------------------------------- */
13947 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13950 + struct au_sbinfo *sbinfo;
13951 + struct au_fhsm *fhsm;
13954 + sbinfo = file->private_data;
13955 + fhsm = &sbinfo->si_fhsm;
13956 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13957 + if (atomic_read(&fhsm->fhsm_readable))
13958 + mask = EPOLLIN /* | EPOLLRDNORM */;
13961 + AuDbg("mask 0x%x\n", mask);
13965 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13966 + struct aufs_stfs *stfs, __s16 brid)
13970 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13972 + err = __put_user(brid, &stbr->brid);
13973 + if (unlikely(err))
13979 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13980 + struct aufs_stbr __user *stbr, size_t count)
13984 + aufs_bindex_t bindex, bbot;
13985 + struct au_branch *br;
13986 + struct au_br_fhsm *bf;
13988 + /* except the bottom branch */
13991 + bbot = au_fhsm_bottom(sb);
13992 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13993 + br = au_sbr(sb, bindex);
13994 + if (!au_br_fhsm(br->br_perm))
13997 + bf = br->br_fhsm;
13998 + mutex_lock(&bf->bf_lock);
13999 + if (bf->bf_readable) {
14001 + if (count >= sizeof(*stbr))
14002 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
14005 + bf->bf_readable = 0;
14006 + count -= sizeof(*stbr);
14010 + mutex_unlock(&bf->bf_lock);
14013 + err = sizeof(*stbr) * nstbr;
14018 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
14023 + aufs_bindex_t nfhsm, bindex, bbot;
14024 + struct au_sbinfo *sbinfo;
14025 + struct au_fhsm *fhsm;
14026 + struct au_branch *br;
14027 + struct super_block *sb;
14030 + sbinfo = file->private_data;
14031 + fhsm = &sbinfo->si_fhsm;
14033 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
14034 + if (!atomic_read(&fhsm->fhsm_readable)) {
14035 + if (vfsub_file_flags(file) & O_NONBLOCK)
14038 + err = wait_event_interruptible_locked_irq
14040 + atomic_read(&fhsm->fhsm_readable));
14042 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
14043 + if (unlikely(err))
14046 + /* sb may already be dead */
14047 + au_rw_read_lock(&sbinfo->si_rwsem);
14048 + readable = atomic_read(&fhsm->fhsm_readable);
14049 + if (readable > 0) {
14050 + sb = sbinfo->si_sb;
14052 + /* exclude the bottom branch */
14054 + bbot = au_fhsm_bottom(sb);
14055 + for (bindex = 0; bindex < bbot; bindex++) {
14056 + br = au_sbr(sb, bindex);
14057 + if (au_br_fhsm(br->br_perm))
14061 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
14062 + atomic_set(&fhsm->fhsm_readable, 0);
14063 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
14067 + au_rw_read_unlock(&sbinfo->si_rwsem);
14075 +static int au_fhsm_release(struct inode *inode, struct file *file)
14077 + struct au_sbinfo *sbinfo;
14078 + struct au_fhsm *fhsm;
14080 + /* sb may already be dead */
14081 + sbinfo = file->private_data;
14082 + fhsm = &sbinfo->si_fhsm;
14083 + spin_lock(&fhsm->fhsm_spin);
14084 + fhsm->fhsm_pid = 0;
14085 + spin_unlock(&fhsm->fhsm_spin);
14086 + kobject_put(&sbinfo->si_kobj);
14091 +static const struct file_operations au_fhsm_fops = {
14092 + .owner = THIS_MODULE,
14093 + .llseek = noop_llseek,
14094 + .read = au_fhsm_read,
14095 + .poll = au_fhsm_poll,
14096 + .release = au_fhsm_release
14099 +int au_fhsm_fd(struct super_block *sb, int oflags)
14102 + struct au_sbinfo *sbinfo;
14103 + struct au_fhsm *fhsm;
14106 + if (unlikely(!capable(CAP_SYS_ADMIN)))
14110 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
14114 + sbinfo = au_sbi(sb);
14115 + fhsm = &sbinfo->si_fhsm;
14116 + spin_lock(&fhsm->fhsm_spin);
14117 + if (!fhsm->fhsm_pid)
14118 + fhsm->fhsm_pid = current->pid;
14121 + spin_unlock(&fhsm->fhsm_spin);
14122 + if (unlikely(err))
14125 + oflags |= O_RDONLY;
14126 + /* oflags |= FMODE_NONOTIFY; */
14127 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14129 + if (unlikely(fd < 0))
14132 + /* succeed regardless 'fhsm' status */
14133 + kobject_get(&sbinfo->si_kobj);
14134 + si_noflush_read_lock(sb);
14135 + if (au_ftest_si(sbinfo, FHSM))
14136 + au_fhsm_wrote_all(sb, /*force*/0);
14137 + si_read_unlock(sb);
14138 + goto out; /* success */
14141 + spin_lock(&fhsm->fhsm_spin);
14142 + fhsm->fhsm_pid = 0;
14143 + spin_unlock(&fhsm->fhsm_spin);
14149 +/* ---------------------------------------------------------------------- */
14151 +int au_fhsm_br_alloc(struct au_branch *br)
14156 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14158 + au_br_fhsm_init(br->br_fhsm);
14165 +/* ---------------------------------------------------------------------- */
14167 +void au_fhsm_fin(struct super_block *sb)
14169 + au_fhsm_notify(sb, /*val*/-1);
14172 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14174 + struct au_fhsm *fhsm;
14176 + fhsm = &sbinfo->si_fhsm;
14177 + spin_lock_init(&fhsm->fhsm_spin);
14178 + init_waitqueue_head(&fhsm->fhsm_wqh);
14179 + atomic_set(&fhsm->fhsm_readable, 0);
14180 + fhsm->fhsm_expire
14181 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14182 + fhsm->fhsm_bottom = -1;
14185 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14187 + sbinfo->si_fhsm.fhsm_expire
14188 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14191 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14195 + if (!au_ftest_si(sbinfo, FHSM))
14198 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14199 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14200 + seq_printf(seq, ",fhsm_sec=%u", u);
14202 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14203 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14204 +++ linux/fs/aufs/file.c 2021-02-22 23:30:37.702680911 +0100
14206 +// SPDX-License-Identifier: GPL-2.0
14208 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14210 + * This program, aufs is free software; you can redistribute it and/or modify
14211 + * it under the terms of the GNU General Public License as published by
14212 + * the Free Software Foundation; either version 2 of the License, or
14213 + * (at your option) any later version.
14215 + * This program is distributed in the hope that it will be useful,
14216 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14217 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14218 + * GNU General Public License for more details.
14220 + * You should have received a copy of the GNU General Public License
14221 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14225 + * handling file/dir, and address_space operation
14228 +#ifdef CONFIG_AUFS_DEBUG
14229 +#include <linux/migrate.h>
14231 +#include <linux/pagemap.h>
14234 +/* drop flags for writing */
14235 +unsigned int au_file_roflags(unsigned int flags)
14237 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14238 + flags |= O_RDONLY | O_NOATIME;
14242 +/* common functions to regular file and dir */
14243 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14244 + struct file *file, int force_wr)
14246 + struct file *h_file;
14247 + struct dentry *h_dentry;
14248 + struct inode *h_inode;
14249 + struct super_block *sb;
14250 + struct au_branch *br;
14251 + struct path h_path;
14254 + /* a race condition can happen between open and unlink/rmdir */
14255 + h_file = ERR_PTR(-ENOENT);
14256 + h_dentry = au_h_dptr(dentry, bindex);
14257 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14259 + h_inode = d_inode(h_dentry);
14260 + spin_lock(&h_dentry->d_lock);
14261 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14262 + /* || !d_inode(dentry)->i_nlink */
14264 + spin_unlock(&h_dentry->d_lock);
14265 + if (unlikely(err))
14268 + sb = dentry->d_sb;
14269 + br = au_sbr(sb, bindex);
14270 + err = au_br_test_oflag(flags, br);
14271 + h_file = ERR_PTR(err);
14272 + if (unlikely(err))
14275 + /* drop flags for writing */
14276 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14277 + if (force_wr && !(flags & O_WRONLY))
14279 + flags = au_file_roflags(flags);
14281 + h_file = ERR_PTR(-EROFS);
14282 + flags = au_file_roflags(flags);
14283 + if (unlikely(vfsub_native_ro(h_inode)
14284 + || IS_APPEND(h_inode)))
14286 + flags &= ~O_ACCMODE;
14287 + flags |= O_WRONLY;
14290 + flags &= ~O_CREAT;
14291 + au_lcnt_inc(&br->br_nfiles);
14292 + h_path.dentry = h_dentry;
14293 + h_path.mnt = au_br_mnt(br);
14294 + h_file = vfsub_dentry_open(&h_path, flags);
14295 + if (IS_ERR(h_file))
14298 + if (flags & __FMODE_EXEC) {
14299 + err = deny_write_access(h_file);
14300 + if (unlikely(err)) {
14302 + h_file = ERR_PTR(err);
14306 + fsnotify_open(h_file);
14307 + goto out; /* success */
14310 + au_lcnt_dec(&br->br_nfiles);
14315 +static int au_cmoo(struct dentry *dentry)
14317 + int err, cmoo, matched;
14318 + unsigned int udba;
14319 + struct path h_path;
14320 + struct au_pin pin;
14321 + struct au_cp_generic cpg = {
14322 + .dentry = dentry,
14327 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14329 + struct inode *delegated;
14330 + struct super_block *sb;
14331 + struct au_sbinfo *sbinfo;
14332 + struct au_fhsm *fhsm;
14334 + struct au_branch *br;
14335 + struct dentry *parent;
14336 + struct au_hinode *hdir;
14338 + DiMustWriteLock(dentry);
14339 + IiMustWriteLock(d_inode(dentry));
14342 + if (IS_ROOT(dentry))
14344 + cpg.bsrc = au_dbtop(dentry);
14348 + sb = dentry->d_sb;
14349 + sbinfo = au_sbi(sb);
14350 + fhsm = &sbinfo->si_fhsm;
14351 + pid = au_fhsm_pid(fhsm);
14354 + && (current->pid == pid
14355 + || rcu_dereference(current->real_parent)->pid == pid));
14356 + rcu_read_unlock();
14360 + br = au_sbr(sb, cpg.bsrc);
14361 + cmoo = au_br_cmoo(br->br_perm);
14364 + if (!d_is_reg(dentry))
14365 + cmoo &= AuBrAttr_COO_ALL;
14369 + parent = dget_parent(dentry);
14370 + di_write_lock_parent(parent);
14371 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14373 + if (unlikely(err < 0)) {
14374 + err = 0; /* there is no upper writable branch */
14377 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14379 + /* do not respect the coo attrib for the target branch */
14380 + err = au_cpup_dirs(dentry, cpg.bdst);
14381 + if (unlikely(err))
14384 + di_downgrade_lock(parent, AuLock_IR);
14385 + udba = au_opt_udba(sb);
14386 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14387 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14388 + if (unlikely(err))
14391 + err = au_sio_cpup_simple(&cpg);
14393 + if (unlikely(err))
14395 + if (!(cmoo & AuBrWAttr_MOO))
14396 + goto out_parent; /* success */
14398 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14399 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14400 + if (unlikely(err))
14403 + h_path.mnt = au_br_mnt(br);
14404 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14405 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14406 + delegated = NULL;
14407 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14409 + /* todo: keep h_dentry or not? */
14410 + if (unlikely(err == -EWOULDBLOCK)) {
14411 + pr_warn("cannot retry for NFSv4 delegation"
14412 + " for an internal unlink\n");
14415 + if (unlikely(err)) {
14416 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14420 + goto out_parent; /* success */
14423 + di_downgrade_lock(parent, AuLock_IR);
14425 + di_read_unlock(parent, AuLock_IR);
14432 +int au_do_open(struct file *file, struct au_do_open_args *args)
14434 + int err, aopen = args->aopen;
14435 + struct dentry *dentry;
14436 + struct au_finfo *finfo;
14439 + err = au_finfo_init(file, args->fidir);
14442 + err = au_finfo_init(file, args->fidir);
14445 + if (unlikely(err))
14448 + dentry = file->f_path.dentry;
14449 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14450 + di_write_lock_child(dentry);
14451 + err = au_cmoo(dentry);
14452 + di_downgrade_lock(dentry, AuLock_IR);
14455 + err = args->open(file, vfsub_file_flags(file), NULL);
14458 + err = args->open(file, vfsub_file_flags(file),
14463 + di_read_unlock(dentry, AuLock_IR);
14465 + finfo = au_fi(file);
14467 + finfo->fi_file = file;
14468 + au_hbl_add(&finfo->fi_hlist,
14469 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14472 + fi_write_unlock(file);
14475 + fi_write_unlock(file);
14478 + if (unlikely(err)) {
14479 + finfo->fi_hdir = NULL;
14480 + au_finfo_fin(file);
14488 +int au_reopen_nondir(struct file *file)
14491 + aufs_bindex_t btop;
14492 + struct dentry *dentry;
14493 + struct au_branch *br;
14494 + struct file *h_file, *h_file_tmp;
14496 + dentry = file->f_path.dentry;
14497 + btop = au_dbtop(dentry);
14498 + br = au_sbr(dentry->d_sb, btop);
14499 + h_file_tmp = NULL;
14500 + if (au_fbtop(file) == btop) {
14501 + h_file = au_hf_top(file);
14502 + if (file->f_mode == h_file->f_mode)
14503 + return 0; /* success */
14504 + h_file_tmp = h_file;
14505 + get_file(h_file_tmp);
14506 + au_lcnt_inc(&br->br_nfiles);
14507 + au_set_h_fptr(file, btop, NULL);
14509 + AuDebugOn(au_fi(file)->fi_hdir);
14512 + * file exists on both of rw and ro
14513 + * open --> dbtop and fbtop are both 0
14514 + * prepend a branch as rw, "rw" become ro
14516 + * delete the top branch, "rw" becomes rw again
14517 + * --> dbtop is 1, fbtop is still 0
14518 + * write --> fbtop is 0 but dbtop is 1
14520 + /* AuDebugOn(au_fbtop(file) < btop); */
14522 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14523 + file, /*force_wr*/0);
14524 + err = PTR_ERR(h_file);
14525 + if (IS_ERR(h_file)) {
14526 + if (h_file_tmp) {
14528 + au_set_h_fptr(file, btop, h_file_tmp);
14529 + h_file_tmp = NULL;
14531 + goto out; /* todo: close all? */
14535 + au_set_fbtop(file, btop);
14536 + au_set_h_fptr(file, btop, h_file);
14537 + au_update_figen(file);
14538 + /* todo: necessary? */
14539 + /* file->f_ra = h_file->f_ra; */
14542 + if (h_file_tmp) {
14543 + fput(h_file_tmp);
14544 + au_lcnt_dec(&br->br_nfiles);
14549 +/* ---------------------------------------------------------------------- */
14551 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14552 + struct dentry *hi_wh)
14555 + aufs_bindex_t btop;
14556 + struct au_dinfo *dinfo;
14557 + struct dentry *h_dentry;
14558 + struct au_hdentry *hdp;
14560 + dinfo = au_di(file->f_path.dentry);
14561 + AuRwMustWriteLock(&dinfo->di_rwsem);
14563 + btop = dinfo->di_btop;
14564 + dinfo->di_btop = btgt;
14565 + hdp = au_hdentry(dinfo, btgt);
14566 + h_dentry = hdp->hd_dentry;
14567 + hdp->hd_dentry = hi_wh;
14568 + err = au_reopen_nondir(file);
14569 + hdp->hd_dentry = h_dentry;
14570 + dinfo->di_btop = btop;
14575 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14576 + aufs_bindex_t bcpup, struct au_pin *pin)
14579 + struct inode *inode, *h_inode;
14580 + struct dentry *h_dentry, *hi_wh;
14581 + struct au_cp_generic cpg = {
14582 + .dentry = file->f_path.dentry,
14589 + au_update_dbtop(cpg.dentry);
14590 + inode = d_inode(cpg.dentry);
14592 + if (au_dbtop(cpg.dentry) <= bcpup
14593 + && au_dbbot(cpg.dentry) >= bcpup) {
14594 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14595 + if (h_dentry && d_is_positive(h_dentry))
14596 + h_inode = d_inode(h_dentry);
14598 + hi_wh = au_hi_wh(inode, bcpup);
14599 + if (!hi_wh && !h_inode)
14600 + err = au_sio_cpup_wh(&cpg, file);
14602 + /* already copied-up after unlink */
14603 + err = au_reopen_wh(file, bcpup, hi_wh);
14606 + && (inode->i_nlink > 1
14607 + || (inode->i_state & I_LINKABLE))
14608 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14609 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14615 + * prepare the @file for writing.
14617 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14620 + aufs_bindex_t dbtop;
14621 + struct dentry *parent;
14622 + struct inode *inode;
14623 + struct super_block *sb;
14624 + struct file *h_file;
14625 + struct au_cp_generic cpg = {
14626 + .dentry = file->f_path.dentry,
14631 + .flags = AuCpup_DTIME
14634 + sb = cpg.dentry->d_sb;
14635 + inode = d_inode(cpg.dentry);
14636 + cpg.bsrc = au_fbtop(file);
14637 + err = au_test_ro(sb, cpg.bsrc, inode);
14638 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14639 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14644 + /* need to cpup or reopen */
14645 + parent = dget_parent(cpg.dentry);
14646 + di_write_lock_parent(parent);
14647 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14649 + if (unlikely(err < 0))
14653 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14654 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14655 + if (unlikely(err))
14659 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14660 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14661 + if (unlikely(err))
14664 + dbtop = au_dbtop(cpg.dentry);
14665 + if (dbtop <= cpg.bdst)
14666 + cpg.bsrc = cpg.bdst;
14668 + if (dbtop <= cpg.bdst /* just reopen */
14669 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14671 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14672 + if (IS_ERR(h_file))
14673 + err = PTR_ERR(h_file);
14675 + di_downgrade_lock(parent, AuLock_IR);
14676 + if (dbtop > cpg.bdst)
14677 + err = au_sio_cpup_simple(&cpg);
14679 + err = au_reopen_nondir(file);
14680 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14682 + } else { /* copyup as wh and reopen */
14684 + * since writable hfsplus branch is not supported,
14685 + * h_open_pre/post() are unnecessary.
14687 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14688 + di_downgrade_lock(parent, AuLock_IR);
14692 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14693 + goto out_dput; /* success */
14699 + di_downgrade_lock(parent, AuLock_IR);
14701 + di_read_unlock(parent, AuLock_IR);
14708 +/* ---------------------------------------------------------------------- */
14710 +int au_do_flush(struct file *file, fl_owner_t id,
14711 + int (*flush)(struct file *file, fl_owner_t id))
14714 + struct super_block *sb;
14715 + struct inode *inode;
14717 + inode = file_inode(file);
14718 + sb = inode->i_sb;
14719 + si_noflush_read_lock(sb);
14720 + fi_read_lock(file);
14721 + ii_read_lock_child(inode);
14723 + err = flush(file, id);
14724 + au_cpup_attr_timesizes(inode);
14726 + ii_read_unlock(inode);
14727 + fi_read_unlock(file);
14728 + si_read_unlock(sb);
14732 +/* ---------------------------------------------------------------------- */
14734 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14737 + struct au_pin pin;
14738 + struct au_finfo *finfo;
14739 + struct dentry *parent, *hi_wh;
14740 + struct inode *inode;
14741 + struct super_block *sb;
14742 + struct au_cp_generic cpg = {
14743 + .dentry = file->f_path.dentry,
14748 + .flags = AuCpup_DTIME
14751 + FiMustWriteLock(file);
14754 + finfo = au_fi(file);
14755 + sb = cpg.dentry->d_sb;
14756 + inode = d_inode(cpg.dentry);
14757 + cpg.bdst = au_ibtop(inode);
14758 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14761 + parent = dget_parent(cpg.dentry);
14762 + if (au_test_ro(sb, cpg.bdst, inode)) {
14763 + di_read_lock_parent(parent, !AuLock_IR);
14764 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14766 + di_read_unlock(parent, !AuLock_IR);
14767 + if (unlikely(err < 0))
14772 + di_read_lock_parent(parent, AuLock_IR);
14773 + hi_wh = au_hi_wh(inode, cpg.bdst);
14774 + if (!S_ISDIR(inode->i_mode)
14775 + && au_opt_test(au_mntflags(sb), PLINK)
14776 + && au_plink_test(inode)
14777 + && !d_unhashed(cpg.dentry)
14778 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14779 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14780 + if (unlikely(err))
14783 + /* always superio. */
14784 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14785 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14787 + err = au_sio_cpup_simple(&cpg);
14790 + } else if (hi_wh) {
14791 + /* already copied-up after unlink */
14792 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14793 + *need_reopen = 0;
14797 + di_read_unlock(parent, AuLock_IR);
14804 +static void au_do_refresh_dir(struct file *file)
14806 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14807 + struct au_hfile *p, tmp, *q;
14808 + struct au_finfo *finfo;
14809 + struct super_block *sb;
14810 + struct au_fidir *fidir;
14812 + FiMustWriteLock(file);
14814 + sb = file->f_path.dentry->d_sb;
14815 + finfo = au_fi(file);
14816 + fidir = finfo->fi_hdir;
14817 + AuDebugOn(!fidir);
14818 + p = fidir->fd_hfile + finfo->fi_btop;
14819 + brid = p->hf_br->br_id;
14820 + bbot = fidir->fd_bbot;
14821 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14825 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14826 + if (new_bindex == bindex)
14828 + if (new_bindex < 0) {
14829 + au_set_h_fptr(file, bindex, NULL);
14833 + /* swap two lower inode, and loop again */
14834 + q = fidir->fd_hfile + new_bindex;
14838 + if (tmp.hf_file) {
14844 + p = fidir->fd_hfile;
14845 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14846 + bbot = au_sbbot(sb);
14847 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14848 + finfo->fi_btop++, p++)
14849 + if (p->hf_file) {
14850 + if (file_inode(p->hf_file))
14852 + au_hfput(p, /*execed*/0);
14855 + bbot = au_br_index(sb, brid);
14856 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14857 + finfo->fi_btop++, p++)
14859 + au_hfput(p, /*execed*/0);
14860 + bbot = au_sbbot(sb);
14863 + p = fidir->fd_hfile + bbot;
14864 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14865 + fidir->fd_bbot--, p--)
14866 + if (p->hf_file) {
14867 + if (file_inode(p->hf_file))
14869 + au_hfput(p, /*execed*/0);
14871 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14875 + * after branch manipulating, refresh the file.
14877 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14879 + int err, need_reopen, nbr;
14880 + aufs_bindex_t bbot, bindex;
14881 + struct dentry *dentry;
14882 + struct super_block *sb;
14883 + struct au_finfo *finfo;
14884 + struct au_hfile *hfile;
14886 + dentry = file->f_path.dentry;
14887 + sb = dentry->d_sb;
14888 + nbr = au_sbbot(sb) + 1;
14889 + finfo = au_fi(file);
14890 + if (!finfo->fi_hdir) {
14891 + hfile = &finfo->fi_htop;
14892 + AuDebugOn(!hfile->hf_file);
14893 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14894 + AuDebugOn(bindex < 0);
14895 + if (bindex != finfo->fi_btop)
14896 + au_set_fbtop(file, bindex);
14898 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14899 + if (unlikely(err))
14901 + au_do_refresh_dir(file);
14906 + if (!au_test_mmapped(file))
14907 + err = au_file_refresh_by_inode(file, &need_reopen);
14908 + if (finfo->fi_hdir)
14909 + /* harmless if err */
14910 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14911 + if (!err && need_reopen && !d_unlinked(dentry))
14912 + err = reopen(file);
14914 + au_update_figen(file);
14915 + goto out; /* success */
14918 + /* error, close all lower files */
14919 + if (finfo->fi_hdir) {
14920 + bbot = au_fbbot_dir(file);
14921 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14922 + au_set_h_fptr(file, bindex, NULL);
14929 +/* common function to regular file and dir */
14930 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14931 + int wlock, unsigned int fi_lsc)
14934 + unsigned int sigen, figen;
14935 + aufs_bindex_t btop;
14936 + unsigned char pseudo_link;
14937 + struct dentry *dentry;
14938 + struct inode *inode;
14941 + dentry = file->f_path.dentry;
14942 + inode = d_inode(dentry);
14943 + sigen = au_sigen(dentry->d_sb);
14944 + fi_write_lock_nested(file, fi_lsc);
14945 + figen = au_figen(file);
14947 + di_write_lock_child(dentry);
14949 + di_write_lock_child2(dentry);
14950 + btop = au_dbtop(dentry);
14951 + pseudo_link = (btop != au_ibtop(inode));
14952 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14954 + di_downgrade_lock(dentry, AuLock_IR);
14955 + fi_downgrade_lock(file);
14957 + goto out; /* success */
14960 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14961 + if (au_digen_test(dentry, sigen)) {
14962 + err = au_reval_dpath(dentry, sigen);
14963 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14967 + err = refresh_file(file, reopen);
14970 + di_downgrade_lock(dentry, AuLock_IR);
14971 + fi_downgrade_lock(file);
14974 + di_write_unlock(dentry);
14975 + fi_write_unlock(file);
14982 +/* ---------------------------------------------------------------------- */
14984 +/* cf. aufs_nopage() */
14985 +/* for madvise(2) */
14986 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14988 + unlock_page(page);
14992 +/* it will never be called, but necessary to support O_DIRECT */
14993 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14994 +{ BUG(); return 0; }
14996 +/* they will never be called. */
14997 +#ifdef CONFIG_AUFS_DEBUG
14998 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14999 + loff_t pos, unsigned len, unsigned flags,
15000 + struct page **pagep, void **fsdata)
15001 +{ AuUnsupport(); return 0; }
15002 +static int aufs_write_end(struct file *file, struct address_space *mapping,
15003 + loff_t pos, unsigned len, unsigned copied,
15004 + struct page *page, void *fsdata)
15005 +{ AuUnsupport(); return 0; }
15006 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
15007 +{ AuUnsupport(); return 0; }
15009 +static int aufs_set_page_dirty(struct page *page)
15010 +{ AuUnsupport(); return 0; }
15011 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
15012 + unsigned int length)
15013 +{ AuUnsupport(); }
15014 +static int aufs_releasepage(struct page *page, gfp_t gfp)
15015 +{ AuUnsupport(); return 0; }
15016 +#if 0 /* called by memory compaction regardless file */
15017 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
15018 + struct page *page, enum migrate_mode mode)
15019 +{ AuUnsupport(); return 0; }
15021 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
15022 +{ AuUnsupport(); return true; }
15023 +static void aufs_putback_page(struct page *page)
15024 +{ AuUnsupport(); }
15025 +static int aufs_launder_page(struct page *page)
15026 +{ AuUnsupport(); return 0; }
15027 +static int aufs_is_partially_uptodate(struct page *page,
15028 + unsigned long from,
15029 + unsigned long count)
15030 +{ AuUnsupport(); return 0; }
15031 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
15033 +{ AuUnsupport(); }
15034 +static int aufs_error_remove_page(struct address_space *mapping,
15035 + struct page *page)
15036 +{ AuUnsupport(); return 0; }
15037 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
15039 +{ AuUnsupport(); return 0; }
15040 +static void aufs_swap_deactivate(struct file *file)
15041 +{ AuUnsupport(); }
15042 +#endif /* CONFIG_AUFS_DEBUG */
15044 +const struct address_space_operations aufs_aop = {
15045 + .readpage = aufs_readpage,
15046 + .direct_IO = aufs_direct_IO,
15047 +#ifdef CONFIG_AUFS_DEBUG
15048 + .writepage = aufs_writepage,
15049 + /* no writepages, because of writepage */
15050 + .set_page_dirty = aufs_set_page_dirty,
15051 + /* no readpages, because of readpage */
15052 + .write_begin = aufs_write_begin,
15053 + .write_end = aufs_write_end,
15054 + /* no bmap, no block device */
15055 + .invalidatepage = aufs_invalidatepage,
15056 + .releasepage = aufs_releasepage,
15057 + /* is fallback_migrate_page ok? */
15058 + /* .migratepage = aufs_migratepage, */
15059 + .isolate_page = aufs_isolate_page,
15060 + .putback_page = aufs_putback_page,
15061 + .launder_page = aufs_launder_page,
15062 + .is_partially_uptodate = aufs_is_partially_uptodate,
15063 + .is_dirty_writeback = aufs_is_dirty_writeback,
15064 + .error_remove_page = aufs_error_remove_page,
15065 + .swap_activate = aufs_swap_activate,
15066 + .swap_deactivate = aufs_swap_deactivate
15067 +#endif /* CONFIG_AUFS_DEBUG */
15069 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
15070 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
15071 +++ linux/fs/aufs/file.h 2021-02-22 23:30:37.702680911 +0100
15073 +/* SPDX-License-Identifier: GPL-2.0 */
15075 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15077 + * This program, aufs is free software; you can redistribute it and/or modify
15078 + * it under the terms of the GNU General Public License as published by
15079 + * the Free Software Foundation; either version 2 of the License, or
15080 + * (at your option) any later version.
15082 + * This program is distributed in the hope that it will be useful,
15083 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15084 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15085 + * GNU General Public License for more details.
15087 + * You should have received a copy of the GNU General Public License
15088 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15092 + * file operations
15095 +#ifndef __AUFS_FILE_H__
15096 +#define __AUFS_FILE_H__
15100 +#include <linux/file.h>
15101 +#include <linux/fs.h>
15102 +#include <linux/mm_types.h>
15103 +#include <linux/poll.h>
15104 +#include "rwsem.h"
15108 + struct file *hf_file;
15109 + struct au_branch *hf_br;
15114 + aufs_bindex_t fd_bbot;
15115 + aufs_bindex_t fd_nent;
15116 + struct au_vdir *fd_vdir_cache;
15117 + struct au_hfile fd_hfile[];
15120 +static inline int au_fidir_sz(int nent)
15122 + AuDebugOn(nent < 0);
15123 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15127 + atomic_t fi_generation;
15129 + struct au_rwsem fi_rwsem;
15130 + aufs_bindex_t fi_btop;
15132 + /* do not union them */
15133 + struct { /* for non-dir */
15134 + struct au_hfile fi_htop;
15135 + atomic_t fi_mmapped;
15137 + struct au_fidir *fi_hdir; /* for dir only */
15139 + struct hlist_bl_node fi_hlist;
15140 + struct file *fi_file; /* very ugly */
15141 + struct rcu_head rcu;
15142 +} ____cacheline_aligned_in_smp;
15144 +/* ---------------------------------------------------------------------- */
15147 +extern const struct address_space_operations aufs_aop;
15148 +unsigned int au_file_roflags(unsigned int flags);
15149 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15150 + struct file *file, int force_wr);
15151 +struct au_do_open_args {
15153 + int (*open)(struct file *file, int flags,
15154 + struct file *h_file);
15155 + struct au_fidir *fidir;
15156 + struct file *h_file;
15158 +int au_do_open(struct file *file, struct au_do_open_args *args);
15159 +int au_reopen_nondir(struct file *file);
15161 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15162 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15163 + int wlock, unsigned int fi_lsc);
15164 +int au_do_flush(struct file *file, fl_owner_t id,
15165 + int (*flush)(struct file *file, fl_owner_t id));
15168 +#ifdef CONFIG_AUFS_POLL
15169 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15172 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15174 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15176 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15177 + struct file *h_file);
15179 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15180 + aufs_bindex_t bindex, int force_wr)
15181 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15182 + struct file *h_file);
15186 +extern const struct file_operations aufs_file_fop;
15187 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15188 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15189 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15192 +void au_hfput(struct au_hfile *hf, int execed);
15193 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15194 + struct file *h_file);
15196 +void au_update_figen(struct file *file);
15197 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15198 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15200 +void au_fi_init_once(void *_fi);
15201 +void au_finfo_fin(struct file *file);
15202 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15205 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15206 +#ifdef CONFIG_COMPAT
15207 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15208 + unsigned long arg);
15209 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15210 + unsigned long arg);
15213 +/* ---------------------------------------------------------------------- */
15215 +static inline struct au_finfo *au_fi(struct file *file)
15217 + return file->private_data;
15220 +/* ---------------------------------------------------------------------- */
15222 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15223 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15224 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15225 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15227 +#define fi_read_trylock_nested(f) \
15228 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15229 +#define fi_write_trylock_nested(f) \
15230 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15233 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15234 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15235 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15237 +/* lock subclass for finfo */
15243 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15245 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15248 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15250 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15254 + * fi_read_lock_1, fi_write_lock_1,
15255 + * fi_read_lock_2, fi_write_lock_2
15257 +#define AuReadLockFunc(name) \
15258 +static inline void fi_read_lock_##name(struct file *f) \
15259 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15261 +#define AuWriteLockFunc(name) \
15262 +static inline void fi_write_lock_##name(struct file *f) \
15263 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15265 +#define AuRWLockFuncs(name) \
15266 + AuReadLockFunc(name) \
15267 + AuWriteLockFunc(name)
15272 +#undef AuReadLockFunc
15273 +#undef AuWriteLockFunc
15274 +#undef AuRWLockFuncs
15276 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15277 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15278 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15280 +/* ---------------------------------------------------------------------- */
15282 +/* todo: hard/soft set? */
15283 +static inline aufs_bindex_t au_fbtop(struct file *file)
15285 + FiMustAnyLock(file);
15286 + return au_fi(file)->fi_btop;
15289 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15291 + FiMustAnyLock(file);
15292 + AuDebugOn(!au_fi(file)->fi_hdir);
15293 + return au_fi(file)->fi_hdir->fd_bbot;
15296 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15298 + FiMustAnyLock(file);
15299 + AuDebugOn(!au_fi(file)->fi_hdir);
15300 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15303 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15305 + FiMustWriteLock(file);
15306 + au_fi(file)->fi_btop = bindex;
15309 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15311 + FiMustWriteLock(file);
15312 + AuDebugOn(!au_fi(file)->fi_hdir);
15313 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15316 +static inline void au_set_fvdir_cache(struct file *file,
15317 + struct au_vdir *vdir_cache)
15319 + FiMustWriteLock(file);
15320 + AuDebugOn(!au_fi(file)->fi_hdir);
15321 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15324 +static inline struct file *au_hf_top(struct file *file)
15326 + FiMustAnyLock(file);
15327 + AuDebugOn(au_fi(file)->fi_hdir);
15328 + return au_fi(file)->fi_htop.hf_file;
15331 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15333 + FiMustAnyLock(file);
15334 + AuDebugOn(!au_fi(file)->fi_hdir);
15335 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15338 +/* todo: memory barrier? */
15339 +static inline unsigned int au_figen(struct file *f)
15341 + return atomic_read(&au_fi(f)->fi_generation);
15344 +static inline void au_set_mmapped(struct file *f)
15346 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15348 + pr_warn("fi_mmapped wrapped around\n");
15349 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15353 +static inline void au_unset_mmapped(struct file *f)
15355 + atomic_dec(&au_fi(f)->fi_mmapped);
15358 +static inline int au_test_mmapped(struct file *f)
15360 + return atomic_read(&au_fi(f)->fi_mmapped);
15363 +/* customize vma->vm_file */
15365 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15366 + struct file *file)
15370 + f = vma->vm_file;
15372 + vma->vm_file = file;
15377 +#define AuDbgVmRegion(file, vma) do {} while (0)
15379 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15380 + struct file *file)
15382 + au_do_vm_file_reset(vma, file);
15385 +#define AuDbgVmRegion(file, vma) \
15386 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15388 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15389 + struct file *file)
15393 + au_do_vm_file_reset(vma, file);
15394 + f = vma->vm_region->vm_file;
15396 + vma->vm_region->vm_file = file;
15399 +#endif /* CONFIG_MMU */
15401 +/* handle vma->vm_prfile */
15402 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15403 + struct file *file)
15406 + vma->vm_prfile = file;
15407 +#ifndef CONFIG_MMU
15409 + vma->vm_region->vm_prfile = file;
15413 +#endif /* __KERNEL__ */
15414 +#endif /* __AUFS_FILE_H__ */
15415 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15416 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15417 +++ linux/fs/aufs/finfo.c 2021-02-22 23:30:37.702680911 +0100
15419 +// SPDX-License-Identifier: GPL-2.0
15421 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15423 + * This program, aufs is free software; you can redistribute it and/or modify
15424 + * it under the terms of the GNU General Public License as published by
15425 + * the Free Software Foundation; either version 2 of the License, or
15426 + * (at your option) any later version.
15428 + * This program is distributed in the hope that it will be useful,
15429 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15430 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15431 + * GNU General Public License for more details.
15433 + * You should have received a copy of the GNU General Public License
15434 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15438 + * file private data
15443 +void au_hfput(struct au_hfile *hf, int execed)
15446 + allow_write_access(hf->hf_file);
15447 + fput(hf->hf_file);
15448 + hf->hf_file = NULL;
15449 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15450 + hf->hf_br = NULL;
15453 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15455 + struct au_finfo *finfo = au_fi(file);
15456 + struct au_hfile *hf;
15457 + struct au_fidir *fidir;
15459 + fidir = finfo->fi_hdir;
15461 + AuDebugOn(finfo->fi_btop != bindex);
15462 + hf = &finfo->fi_htop;
15464 + hf = fidir->fd_hfile + bindex;
15466 + if (hf && hf->hf_file)
15467 + au_hfput(hf, vfsub_file_execed(file));
15469 + FiMustWriteLock(file);
15470 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15471 + hf->hf_file = val;
15472 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15476 +void au_update_figen(struct file *file)
15478 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15479 + /* smp_mb(); */ /* atomic_set */
15482 +/* ---------------------------------------------------------------------- */
15484 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15486 + struct au_fidir *fidir;
15489 + nbr = au_sbbot(sb) + 1;
15491 + nbr = 2; /* initial allocate for 2 branches */
15492 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15494 + fidir->fd_bbot = -1;
15495 + fidir->fd_nent = nbr;
15501 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15504 + struct au_fidir *fidir, *p;
15506 + AuRwMustWriteLock(&finfo->fi_rwsem);
15507 + fidir = finfo->fi_hdir;
15508 + AuDebugOn(!fidir);
15511 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15512 + GFP_NOFS, may_shrink);
15514 + p->fd_nent = nbr;
15515 + finfo->fi_hdir = p;
15522 +/* ---------------------------------------------------------------------- */
15524 +void au_finfo_fin(struct file *file)
15526 + struct au_finfo *finfo;
15528 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15530 + finfo = au_fi(file);
15531 + AuDebugOn(finfo->fi_hdir);
15532 + AuRwDestroy(&finfo->fi_rwsem);
15533 + au_cache_free_finfo(finfo);
15536 +void au_fi_init_once(void *_finfo)
15538 + struct au_finfo *finfo = _finfo;
15540 + au_rw_init(&finfo->fi_rwsem);
15543 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15546 + struct au_finfo *finfo;
15547 + struct dentry *dentry;
15550 + dentry = file->f_path.dentry;
15551 + finfo = au_cache_alloc_finfo();
15552 + if (unlikely(!finfo))
15556 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15557 + au_rw_write_lock(&finfo->fi_rwsem);
15558 + finfo->fi_btop = -1;
15559 + finfo->fi_hdir = fidir;
15560 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15561 + /* smp_mb(); */ /* atomic_set */
15563 + file->private_data = finfo;
15568 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15569 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15570 +++ linux/fs/aufs/f_op.c 2021-02-22 23:30:37.699347580 +0100
15572 +// SPDX-License-Identifier: GPL-2.0
15574 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15576 + * This program, aufs is free software; you can redistribute it and/or modify
15577 + * it under the terms of the GNU General Public License as published by
15578 + * the Free Software Foundation; either version 2 of the License, or
15579 + * (at your option) any later version.
15581 + * This program is distributed in the hope that it will be useful,
15582 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15583 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15584 + * GNU General Public License for more details.
15586 + * You should have received a copy of the GNU General Public License
15587 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15591 + * file and vm operations
15594 +#include <linux/aio.h>
15595 +#include <linux/fs_stack.h>
15596 +#include <linux/mman.h>
15597 +#include <linux/security.h>
15600 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15603 + aufs_bindex_t bindex;
15604 + struct dentry *dentry, *h_dentry;
15605 + struct au_finfo *finfo;
15606 + struct inode *h_inode;
15608 + FiMustWriteLock(file);
15611 + dentry = file->f_path.dentry;
15612 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15613 + finfo = au_fi(file);
15614 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15615 + atomic_set(&finfo->fi_mmapped, 0);
15616 + bindex = au_dbtop(dentry);
15618 + h_dentry = au_h_dptr(dentry, bindex);
15619 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15620 + if (unlikely(err))
15622 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15623 + if (IS_ERR(h_file)) {
15624 + err = PTR_ERR(h_file);
15628 + h_dentry = h_file->f_path.dentry;
15629 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15630 + if (unlikely(err))
15632 + /* br ref is already inc-ed */
15635 + if ((flags & __O_TMPFILE)
15636 + && !(flags & O_EXCL)) {
15637 + h_inode = file_inode(h_file);
15638 + spin_lock(&h_inode->i_lock);
15639 + h_inode->i_state |= I_LINKABLE;
15640 + spin_unlock(&h_inode->i_lock);
15642 + au_set_fbtop(file, bindex);
15643 + au_set_h_fptr(file, bindex, h_file);
15644 + au_update_figen(file);
15645 + /* todo: necessary? */
15646 + /* file->f_ra = h_file->f_ra; */
15652 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15653 + struct file *file)
15656 + struct super_block *sb;
15657 + struct au_do_open_args args = {
15658 + .open = au_do_open_nondir
15661 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15662 + file, vfsub_file_flags(file), file->f_mode);
15664 + sb = file->f_path.dentry->d_sb;
15665 + si_read_lock(sb, AuLock_FLUSH);
15666 + err = au_do_open(file, &args);
15667 + si_read_unlock(sb);
15671 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15673 + struct au_finfo *finfo;
15674 + aufs_bindex_t bindex;
15676 + finfo = au_fi(file);
15677 + au_hbl_del(&finfo->fi_hlist,
15678 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15679 + bindex = finfo->fi_btop;
15681 + au_set_h_fptr(file, bindex, NULL);
15683 + au_finfo_fin(file);
15687 +/* ---------------------------------------------------------------------- */
15689 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15692 + struct file *h_file;
15695 + h_file = au_hf_top(file);
15697 + err = vfsub_flush(h_file, id);
15701 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15703 + return au_do_flush(file, id, au_do_flush_nondir);
15706 +/* ---------------------------------------------------------------------- */
15708 + * read and write functions acquire [fdi]_rwsem once, but release before
15709 + * mmap_sem. This is because to stop a race condition between mmap(2).
15710 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15711 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15712 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15715 +/* Callers should call au_read_post() or fput() in the end */
15716 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15718 + struct file *h_file;
15721 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15723 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15724 + h_file = au_hf_top(file);
15725 + get_file(h_file);
15727 + fi_read_unlock(file);
15729 + h_file = ERR_PTR(err);
15734 +static void au_read_post(struct inode *inode, struct file *h_file)
15736 + /* update without lock, I don't think it a problem */
15737 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15741 +struct au_write_pre {
15743 + unsigned int lsc;
15747 + aufs_bindex_t btop;
15751 + * return with iinfo is write-locked
15752 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15755 +static struct file *au_write_pre(struct file *file, int do_ready,
15756 + struct au_write_pre *wpre)
15758 + struct file *h_file;
15759 + struct dentry *dentry;
15761 + unsigned int lsc;
15762 + struct au_pin pin;
15767 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15768 + h_file = ERR_PTR(err);
15769 + if (unlikely(err))
15772 + dentry = file->f_path.dentry;
15774 + err = au_ready_to_write(file, -1, &pin);
15775 + if (unlikely(err)) {
15776 + h_file = ERR_PTR(err);
15777 + di_write_unlock(dentry);
15782 + di_downgrade_lock(dentry, /*flags*/0);
15784 + wpre->btop = au_fbtop(file);
15785 + h_file = au_hf_top(file);
15786 + get_file(h_file);
15788 + wpre->blks = file_inode(h_file)->i_blocks;
15791 + di_read_unlock(dentry, /*flags*/0);
15794 + fi_write_unlock(file);
15799 +static void au_write_post(struct inode *inode, struct file *h_file,
15800 + struct au_write_pre *wpre, ssize_t written)
15802 + struct inode *h_inode;
15804 + au_cpup_attr_timesizes(inode);
15805 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15806 + h_inode = file_inode(h_file);
15807 + inode->i_mode = h_inode->i_mode;
15808 + ii_write_unlock(inode);
15809 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15811 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15812 + /*force*/h_inode->i_blocks > wpre->blks);
15816 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
15820 + struct inode *inode;
15821 + struct file *h_file;
15822 + struct super_block *sb;
15824 + inode = file_inode(file);
15825 + sb = inode->i_sb;
15826 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15828 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15829 + err = PTR_ERR(h_file);
15830 + if (IS_ERR(h_file))
15833 + /* filedata may be obsoleted by concurrent copyup, but no problem */
15834 + err = vfsub_read_u(h_file, buf, count, ppos);
15835 + /* todo: necessary? */
15836 + /* file->f_ra = h_file->f_ra; */
15837 + au_read_post(inode, h_file);
15840 + si_read_unlock(sb);
15845 + * todo: very ugly
15846 + * it locks both of i_mutex and si_rwsem for read in safe.
15847 + * if the plink maintenance mode continues forever (that is the problem),
15848 + * may loop forever.
15850 +static void au_mtx_and_read_lock(struct inode *inode)
15853 + struct super_block *sb = inode->i_sb;
15856 + inode_lock(inode);
15857 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15860 + inode_unlock(inode);
15861 + si_read_lock(sb, AuLock_NOPLMW);
15862 + si_read_unlock(sb);
15866 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
15867 + size_t count, loff_t *ppos)
15870 + struct au_write_pre wpre;
15871 + struct inode *inode;
15872 + struct file *h_file;
15873 + char __user *buf = (char __user *)ubuf;
15875 + inode = file_inode(file);
15876 + au_mtx_and_read_lock(inode);
15879 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15880 + err = PTR_ERR(h_file);
15881 + if (IS_ERR(h_file))
15884 + err = vfsub_write_u(h_file, buf, count, ppos);
15885 + au_write_post(inode, h_file, &wpre, err);
15888 + si_read_unlock(inode->i_sb);
15889 + inode_unlock(inode);
15893 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15894 + struct iov_iter *iov_iter)
15897 + struct file *file;
15898 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15900 + err = security_file_permission(h_file, rw);
15901 + if (unlikely(err))
15904 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15906 + if (rw == MAY_READ)
15907 + iter = h_file->f_op->read_iter;
15908 + else if (rw == MAY_WRITE)
15909 + iter = h_file->f_op->write_iter;
15911 + file = kio->ki_filp;
15912 + kio->ki_filp = h_file;
15915 + err = iter(kio, iov_iter);
15918 + /* currently there is no such fs */
15920 + kio->ki_filp = file;
15926 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15929 + struct file *file, *h_file;
15930 + struct inode *inode;
15931 + struct super_block *sb;
15933 + file = kio->ki_filp;
15934 + inode = file_inode(file);
15935 + sb = inode->i_sb;
15936 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15938 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15939 + err = PTR_ERR(h_file);
15940 + if (IS_ERR(h_file))
15943 + if (au_test_loopback_kthread()) {
15944 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15945 + if (file->f_mapping != h_file->f_mapping) {
15946 + file->f_mapping = h_file->f_mapping;
15947 + smp_mb(); /* unnecessary? */
15950 + fi_read_unlock(file);
15952 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15953 + /* todo: necessary? */
15954 + /* file->f_ra = h_file->f_ra; */
15955 + au_read_post(inode, h_file);
15958 + si_read_unlock(sb);
15962 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15965 + struct au_write_pre wpre;
15966 + struct inode *inode;
15967 + struct file *file, *h_file;
15969 + file = kio->ki_filp;
15970 + inode = file_inode(file);
15971 + au_mtx_and_read_lock(inode);
15974 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15975 + err = PTR_ERR(h_file);
15976 + if (IS_ERR(h_file))
15979 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15980 + au_write_post(inode, h_file, &wpre, err);
15983 + si_read_unlock(inode->i_sb);
15984 + inode_unlock(inode);
15988 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15989 + struct pipe_inode_info *pipe, size_t len,
15990 + unsigned int flags)
15993 + struct file *h_file;
15994 + struct inode *inode;
15995 + struct super_block *sb;
15997 + inode = file_inode(file);
15998 + sb = inode->i_sb;
15999 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16001 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16002 + err = PTR_ERR(h_file);
16003 + if (IS_ERR(h_file))
16006 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
16007 + /* todo: necessary? */
16008 + /* file->f_ra = h_file->f_ra; */
16009 + au_read_post(inode, h_file);
16012 + si_read_unlock(sb);
16017 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
16018 + size_t len, unsigned int flags)
16021 + struct au_write_pre wpre;
16022 + struct inode *inode;
16023 + struct file *h_file;
16025 + inode = file_inode(file);
16026 + au_mtx_and_read_lock(inode);
16029 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16030 + err = PTR_ERR(h_file);
16031 + if (IS_ERR(h_file))
16034 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
16035 + au_write_post(inode, h_file, &wpre, err);
16038 + si_read_unlock(inode->i_sb);
16039 + inode_unlock(inode);
16043 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
16047 + struct au_write_pre wpre;
16048 + struct inode *inode;
16049 + struct file *h_file;
16051 + inode = file_inode(file);
16052 + au_mtx_and_read_lock(inode);
16055 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16056 + err = PTR_ERR(h_file);
16057 + if (IS_ERR(h_file))
16061 + err = vfs_fallocate(h_file, mode, offset, len);
16063 + au_write_post(inode, h_file, &wpre, /*written*/1);
16066 + si_read_unlock(inode->i_sb);
16067 + inode_unlock(inode);
16071 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
16072 + struct file *dst, loff_t dst_pos,
16073 + size_t len, unsigned int flags)
16076 + struct au_write_pre wpre;
16077 + enum { SRC, DST };
16079 + struct inode *inode;
16080 + struct file *h_file;
16081 + struct super_block *h_sb;
16083 +#define a_src a[SRC]
16084 +#define a_dst a[DST]
16087 + a_src.inode = file_inode(src);
16088 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
16090 + a_dst.inode = file_inode(dst);
16091 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
16094 + au_mtx_and_read_lock(a_dst.inode);
16096 + * in order to match the order in di_write_lock2_{child,parent}(),
16097 + * use f_path.dentry for this comparison.
16099 + if (src->f_path.dentry < dst->f_path.dentry) {
16100 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
16101 + err = PTR_ERR(a_src.h_file);
16102 + if (IS_ERR(a_src.h_file))
16105 + wpre.lsc = AuLsc_FI_2;
16106 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16107 + err = PTR_ERR(a_dst.h_file);
16108 + if (IS_ERR(a_dst.h_file)) {
16109 + au_read_post(a_src.inode, a_src.h_file);
16113 + wpre.lsc = AuLsc_FI_1;
16114 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
16115 + err = PTR_ERR(a_dst.h_file);
16116 + if (IS_ERR(a_dst.h_file))
16119 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
16120 + err = PTR_ERR(a_src.h_file);
16121 + if (IS_ERR(a_src.h_file)) {
16122 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
16129 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
16130 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
16131 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
16137 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
16138 + dst_pos, len, flags);
16141 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
16142 + fi_read_unlock(src);
16143 + au_read_post(a_src.inode, a_src.h_file);
16145 + si_read_unlock(a_dst.inode->i_sb);
16146 + inode_unlock(a_dst.inode);
16153 +/* ---------------------------------------------------------------------- */
16156 + * The locking order around current->mmap_sem.
16157 + * - in most and regular cases
16158 + * file I/O syscall -- aufs_read() or something
16159 + * -- si_rwsem for read -- mmap_sem
16160 + * (Note that [fdi]i_rwsem are released before mmap_sem).
16162 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
16163 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
16164 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16165 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16166 + * It means that when aufs acquires si_rwsem for write, the process should never
16167 + * acquire mmap_sem.
16169 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16170 + * problem either since any directory is not able to be mmap-ed.
16171 + * The similar scenario is applied to aufs_readlink() too.
16174 +#if 0 /* stop calling security_file_mmap() */
16175 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16176 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16178 +static unsigned long au_arch_prot_conv(unsigned long flags)
16180 + /* currently ppc64 only */
16181 +#ifdef CONFIG_PPC64
16182 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16183 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16184 + return AuConv_VM_PROT(flags, SAO);
16186 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16191 +static unsigned long au_prot_conv(unsigned long flags)
16193 + return AuConv_VM_PROT(flags, READ)
16194 + | AuConv_VM_PROT(flags, WRITE)
16195 + | AuConv_VM_PROT(flags, EXEC)
16196 + | au_arch_prot_conv(flags);
16199 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16200 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16202 +static unsigned long au_flag_conv(unsigned long flags)
16204 + return AuConv_VM_MAP(flags, GROWSDOWN)
16205 + | AuConv_VM_MAP(flags, DENYWRITE)
16206 + | AuConv_VM_MAP(flags, LOCKED);
16210 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16213 + const unsigned char wlock
16214 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16215 + struct super_block *sb;
16216 + struct file *h_file;
16217 + struct inode *inode;
16219 + AuDbgVmRegion(file, vma);
16221 + inode = file_inode(file);
16222 + sb = inode->i_sb;
16224 + si_read_lock(sb, AuLock_NOPLMW);
16226 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16228 + err = PTR_ERR(h_file);
16229 + if (IS_ERR(h_file))
16233 + au_set_mmapped(file);
16234 + au_vm_file_reset(vma, h_file);
16236 + * we cannot call security_mmap_file() here since it may acquire
16237 + * mmap_sem or i_mutex.
16239 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16240 + * au_flag_conv(vma->vm_flags));
16243 + err = call_mmap(h_file, vma);
16245 + au_vm_prfile_set(vma, file);
16246 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16247 + goto out_fput; /* success */
16249 + au_unset_mmapped(file);
16250 + au_vm_file_reset(vma, file);
16254 + ii_write_unlock(inode);
16259 + si_read_unlock(sb);
16265 +/* ---------------------------------------------------------------------- */
16267 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16271 + struct au_write_pre wpre;
16272 + struct inode *inode;
16273 + struct file *h_file;
16275 + err = 0; /* -EBADF; */ /* posix? */
16276 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16279 + inode = file_inode(file);
16280 + au_mtx_and_read_lock(inode);
16283 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16284 + err = PTR_ERR(h_file);
16285 + if (IS_ERR(h_file))
16288 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16289 + au_write_post(inode, h_file, &wpre, /*written*/0);
16292 + si_read_unlock(inode->i_sb);
16293 + inode_unlock(inode);
16298 +static int aufs_fasync(int fd, struct file *file, int flag)
16301 + struct file *h_file;
16302 + struct super_block *sb;
16304 + sb = file->f_path.dentry->d_sb;
16305 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16307 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16308 + err = PTR_ERR(h_file);
16309 + if (IS_ERR(h_file))
16312 + if (h_file->f_op->fasync)
16313 + err = h_file->f_op->fasync(fd, h_file, flag);
16314 + fput(h_file); /* instead of au_read_post() */
16317 + si_read_unlock(sb);
16321 +static int aufs_setfl(struct file *file, unsigned long arg)
16324 + struct file *h_file;
16325 + struct super_block *sb;
16327 + sb = file->f_path.dentry->d_sb;
16328 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16330 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16331 + err = PTR_ERR(h_file);
16332 + if (IS_ERR(h_file))
16335 + /* stop calling h_file->fasync */
16336 + arg |= vfsub_file_flags(file) & FASYNC;
16337 + err = setfl(/*unused fd*/-1, h_file, arg);
16338 + fput(h_file); /* instead of au_read_post() */
16341 + si_read_unlock(sb);
16345 +/* ---------------------------------------------------------------------- */
16347 +/* no one supports this operation, currently */
16348 +#if 0 /* reserved for future use */
16349 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16350 + size_t len, loff_t *pos, int more)
16355 +/* ---------------------------------------------------------------------- */
16357 +const struct file_operations aufs_file_fop = {
16358 + .owner = THIS_MODULE,
16360 + .llseek = default_llseek,
16362 + .read = aufs_read,
16363 + .write = aufs_write,
16364 + .read_iter = aufs_read_iter,
16365 + .write_iter = aufs_write_iter,
16367 +#ifdef CONFIG_AUFS_POLL
16368 + .poll = aufs_poll,
16370 + .unlocked_ioctl = aufs_ioctl_nondir,
16371 +#ifdef CONFIG_COMPAT
16372 + .compat_ioctl = aufs_compat_ioctl_nondir,
16374 + .mmap = aufs_mmap,
16375 + .open = aufs_open_nondir,
16376 + .flush = aufs_flush_nondir,
16377 + .release = aufs_release_nondir,
16378 + .fsync = aufs_fsync_nondir,
16379 + .fasync = aufs_fasync,
16380 + /* .sendpage = aufs_sendpage, */
16381 + .setfl = aufs_setfl,
16382 + .splice_write = aufs_splice_write,
16383 + .splice_read = aufs_splice_read,
16384 +#if 0 /* reserved for future use */
16385 + .aio_splice_write = aufs_aio_splice_write,
16386 + .aio_splice_read = aufs_aio_splice_read,
16388 + .fallocate = aufs_fallocate,
16389 + .copy_file_range = aufs_copy_file_range
16391 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16392 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16393 +++ linux/fs/aufs/fstype.h 2021-02-22 23:30:37.702680911 +0100
16395 +/* SPDX-License-Identifier: GPL-2.0 */
16397 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16399 + * This program, aufs is free software; you can redistribute it and/or modify
16400 + * it under the terms of the GNU General Public License as published by
16401 + * the Free Software Foundation; either version 2 of the License, or
16402 + * (at your option) any later version.
16404 + * This program is distributed in the hope that it will be useful,
16405 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16407 + * GNU General Public License for more details.
16409 + * You should have received a copy of the GNU General Public License
16410 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16414 + * judging filesystem type
16417 +#ifndef __AUFS_FSTYPE_H__
16418 +#define __AUFS_FSTYPE_H__
16422 +#include <linux/fs.h>
16423 +#include <linux/magic.h>
16424 +#include <linux/nfs_fs.h>
16425 +#include <linux/romfs_fs.h>
16427 +static inline int au_test_aufs(struct super_block *sb)
16429 + return sb->s_magic == AUFS_SUPER_MAGIC;
16432 +static inline const char *au_sbtype(struct super_block *sb)
16434 + return sb->s_type->name;
16437 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16439 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16440 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16446 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16448 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16449 + return sb->s_magic == ROMFS_MAGIC;
16455 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16457 +#if IS_ENABLED(CONFIG_CRAMFS)
16458 + return sb->s_magic == CRAMFS_MAGIC;
16463 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16465 +#if IS_ENABLED(CONFIG_NFS_FS)
16466 + return sb->s_magic == NFS_SUPER_MAGIC;
16472 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16474 +#if IS_ENABLED(CONFIG_FUSE_FS)
16475 + return sb->s_magic == FUSE_SUPER_MAGIC;
16481 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16483 +#if IS_ENABLED(CONFIG_XFS_FS)
16484 + return sb->s_magic == XFS_SB_MAGIC;
16490 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16492 +#ifdef CONFIG_TMPFS
16493 + return sb->s_magic == TMPFS_MAGIC;
16499 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16501 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16502 + return !strcmp(au_sbtype(sb), "ecryptfs");
16508 +static inline int au_test_ramfs(struct super_block *sb)
16510 + return sb->s_magic == RAMFS_MAGIC;
16513 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16515 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16516 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16522 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16524 +#ifdef CONFIG_PROC_FS
16525 + return sb->s_magic == PROC_SUPER_MAGIC;
16531 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16533 +#ifdef CONFIG_SYSFS
16534 + return sb->s_magic == SYSFS_MAGIC;
16540 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16542 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16543 + return sb->s_magic == CONFIGFS_MAGIC;
16549 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16551 +#if IS_ENABLED(CONFIG_MINIX_FS)
16552 + return sb->s_magic == MINIX3_SUPER_MAGIC
16553 + || sb->s_magic == MINIX2_SUPER_MAGIC
16554 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16555 + || sb->s_magic == MINIX_SUPER_MAGIC
16556 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16562 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16564 +#if IS_ENABLED(CONFIG_FAT_FS)
16565 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16571 +static inline int au_test_msdos(struct super_block *sb)
16573 + return au_test_fat(sb);
16576 +static inline int au_test_vfat(struct super_block *sb)
16578 + return au_test_fat(sb);
16581 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16583 +#ifdef CONFIG_SECURITYFS
16584 + return sb->s_magic == SECURITYFS_MAGIC;
16590 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16592 +#if IS_ENABLED(CONFIG_SQUASHFS)
16593 + return sb->s_magic == SQUASHFS_MAGIC;
16599 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16601 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16602 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16608 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16610 +#if IS_ENABLED(CONFIG_XENFS)
16611 + return sb->s_magic == XENFS_SUPER_MAGIC;
16617 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16619 +#ifdef CONFIG_DEBUG_FS
16620 + return sb->s_magic == DEBUGFS_MAGIC;
16626 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16628 +#if IS_ENABLED(CONFIG_NILFS)
16629 + return sb->s_magic == NILFS_SUPER_MAGIC;
16635 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16637 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16638 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16644 +/* ---------------------------------------------------------------------- */
16646 + * they can't be an aufs branch.
16648 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16651 +#ifndef CONFIG_AUFS_BR_RAMFS
16652 + au_test_ramfs(sb) ||
16654 + au_test_procfs(sb)
16655 + || au_test_sysfs(sb)
16656 + || au_test_configfs(sb)
16657 + || au_test_debugfs(sb)
16658 + || au_test_securityfs(sb)
16659 + || au_test_xenfs(sb)
16660 + || au_test_ecryptfs(sb)
16661 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16662 + || au_test_aufs(sb); /* will be supported in next version */
16665 +static inline int au_test_fs_remote(struct super_block *sb)
16667 + return !au_test_tmpfs(sb)
16668 +#ifdef CONFIG_AUFS_BR_RAMFS
16669 + && !au_test_ramfs(sb)
16671 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16674 +/* ---------------------------------------------------------------------- */
16677 + * Note: these functions (below) are created after reading ->getattr() in all
16678 + * filesystems under linux/fs. it means we have to do so in every update...
16682 + * some filesystems require getattr to refresh the inode attributes before
16684 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16685 + * and leave the work for d_revalidate()
16687 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16689 + return au_test_nfs(sb)
16690 + || au_test_fuse(sb)
16691 + /* || au_test_btrfs(sb) */ /* untested */
16696 + * filesystems which don't maintain i_size or i_blocks.
16698 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16700 + return au_test_xfs(sb)
16701 + || au_test_btrfs(sb)
16702 + || au_test_ubifs(sb)
16703 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16704 + /* || au_test_minix(sb) */ /* untested */
16709 + * filesystems which don't store the correct value in some of their inode
16712 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16714 + return au_test_fs_bad_iattr_size(sb)
16715 + || au_test_fat(sb)
16716 + || au_test_msdos(sb)
16717 + || au_test_vfat(sb);
16720 +/* they don't check i_nlink in link(2) */
16721 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16723 + return au_test_tmpfs(sb)
16724 +#ifdef CONFIG_AUFS_BR_RAMFS
16725 + || au_test_ramfs(sb)
16727 + || au_test_ubifs(sb)
16728 + || au_test_hfsplus(sb);
16732 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16734 +static inline int au_test_fs_notime(struct super_block *sb)
16736 + return au_test_nfs(sb)
16737 + || au_test_fuse(sb)
16738 + || au_test_ubifs(sb)
16742 +/* temporary support for i#1 in cramfs */
16743 +static inline int au_test_fs_unique_ino(struct inode *inode)
16745 + if (au_test_cramfs(inode->i_sb))
16746 + return inode->i_ino != 1;
16750 +/* ---------------------------------------------------------------------- */
16753 + * the filesystem where the xino files placed must support i/o after unlink and
16754 + * maintain i_size and i_blocks.
16756 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16758 + return au_test_fs_remote(sb)
16759 + || au_test_fs_bad_iattr_size(sb)
16760 + /* don't want unnecessary work for xino */
16761 + || au_test_aufs(sb)
16762 + || au_test_ecryptfs(sb)
16763 + || au_test_nilfs(sb);
16766 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16768 + return au_test_tmpfs(sb)
16769 + || au_test_ramfs(sb);
16773 + * test if the @sb is real-readonly.
16775 +static inline int au_test_fs_rr(struct super_block *sb)
16777 + return au_test_squashfs(sb)
16778 + || au_test_iso9660(sb)
16779 + || au_test_cramfs(sb)
16780 + || au_test_romfs(sb);
16784 + * test if the @inode is nfs with 'noacl' option
16785 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16787 +static inline int au_test_nfs_noacl(struct inode *inode)
16789 + return au_test_nfs(inode->i_sb)
16790 + /* && IS_POSIXACL(inode) */
16791 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16794 +#endif /* __KERNEL__ */
16795 +#endif /* __AUFS_FSTYPE_H__ */
16796 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16797 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16798 +++ linux/fs/aufs/hbl.h 2021-02-22 23:30:37.702680911 +0100
16800 +/* SPDX-License-Identifier: GPL-2.0 */
16802 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16804 + * This program, aufs is free software; you can redistribute it and/or modify
16805 + * it under the terms of the GNU General Public License as published by
16806 + * the Free Software Foundation; either version 2 of the License, or
16807 + * (at your option) any later version.
16809 + * This program is distributed in the hope that it will be useful,
16810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16812 + * GNU General Public License for more details.
16814 + * You should have received a copy of the GNU General Public License
16815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16819 + * helpers for hlist_bl.h
16822 +#ifndef __AUFS_HBL_H__
16823 +#define __AUFS_HBL_H__
16827 +#include <linux/list_bl.h>
16829 +static inline void au_hbl_add(struct hlist_bl_node *node,
16830 + struct hlist_bl_head *hbl)
16832 + hlist_bl_lock(hbl);
16833 + hlist_bl_add_head(node, hbl);
16834 + hlist_bl_unlock(hbl);
16837 +static inline void au_hbl_del(struct hlist_bl_node *node,
16838 + struct hlist_bl_head *hbl)
16840 + hlist_bl_lock(hbl);
16841 + hlist_bl_del(node);
16842 + hlist_bl_unlock(hbl);
16845 +#define au_hbl_for_each(pos, head) \
16846 + for (pos = hlist_bl_first(head); \
16850 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16852 + unsigned long cnt;
16853 + struct hlist_bl_node *pos;
16856 + hlist_bl_lock(hbl);
16857 + au_hbl_for_each(pos, hbl)
16859 + hlist_bl_unlock(hbl);
16863 +#endif /* __KERNEL__ */
16864 +#endif /* __AUFS_HBL_H__ */
16865 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16866 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16867 +++ linux/fs/aufs/hfsnotify.c 2021-02-22 23:30:37.702680911 +0100
16869 +// SPDX-License-Identifier: GPL-2.0
16871 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16873 + * This program, aufs is free software; you can redistribute it and/or modify
16874 + * it under the terms of the GNU General Public License as published by
16875 + * the Free Software Foundation; either version 2 of the License, or
16876 + * (at your option) any later version.
16878 + * This program is distributed in the hope that it will be useful,
16879 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16880 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16881 + * GNU General Public License for more details.
16883 + * You should have received a copy of the GNU General Public License
16884 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16888 + * fsnotify for the lower directories
16893 +/* FS_IN_IGNORED is unnecessary */
16894 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16895 + | FS_CREATE | FS_EVENT_ON_CHILD);
16896 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16897 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16899 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16901 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16903 + /* AuDbg("here\n"); */
16904 + au_cache_free_hnotify(hn);
16905 + smp_mb__before_atomic(); /* for atomic64_dec */
16906 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16907 + wake_up(&au_hfsn_wq);
16910 +static int au_hfsn_alloc(struct au_hinode *hinode)
16913 + struct au_hnotify *hn;
16914 + struct super_block *sb;
16915 + struct au_branch *br;
16916 + struct fsnotify_mark *mark;
16917 + aufs_bindex_t bindex;
16919 + hn = hinode->hi_notify;
16920 + sb = hn->hn_aufs_inode->i_sb;
16921 + bindex = au_br_index(sb, hinode->hi_id);
16922 + br = au_sbr(sb, bindex);
16923 + AuDebugOn(!br->br_hfsn);
16925 + mark = &hn->hn_mark;
16926 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16927 + mark->mask = AuHfsnMask;
16929 + * by udba rename or rmdir, aufs assign a new inode to the known
16930 + * h_inode, so specify 1 to allow dups.
16933 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16939 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16941 + struct fsnotify_mark *mark;
16942 + unsigned long long ull;
16943 + struct fsnotify_group *group;
16945 + ull = atomic64_inc_return(&au_hfsn_ifree);
16948 + mark = &hn->hn_mark;
16949 + spin_lock(&mark->lock);
16950 + group = mark->group;
16951 + fsnotify_get_group(group);
16952 + spin_unlock(&mark->lock);
16954 + fsnotify_destroy_mark(mark, group);
16955 + fsnotify_put_mark(mark);
16956 + fsnotify_put_group(group);
16959 + /* free hn by myself */
16963 +/* ---------------------------------------------------------------------- */
16965 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16967 + struct fsnotify_mark *mark;
16969 + mark = &hinode->hi_notify->hn_mark;
16970 + spin_lock(&mark->lock);
16972 + AuDebugOn(mark->mask & AuHfsnMask);
16973 + mark->mask |= AuHfsnMask;
16975 + AuDebugOn(!(mark->mask & AuHfsnMask));
16976 + mark->mask &= ~AuHfsnMask;
16978 + spin_unlock(&mark->lock);
16979 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16982 +/* ---------------------------------------------------------------------- */
16984 +/* #define AuDbgHnotify */
16985 +#ifdef AuDbgHnotify
16986 +static char *au_hfsn_name(u32 mask)
16988 +#ifdef CONFIG_AUFS_DEBUG
16989 +#define test_ret(flag) \
16991 + if (mask & flag) \
16994 + test_ret(FS_ACCESS);
16995 + test_ret(FS_MODIFY);
16996 + test_ret(FS_ATTRIB);
16997 + test_ret(FS_CLOSE_WRITE);
16998 + test_ret(FS_CLOSE_NOWRITE);
16999 + test_ret(FS_OPEN);
17000 + test_ret(FS_MOVED_FROM);
17001 + test_ret(FS_MOVED_TO);
17002 + test_ret(FS_CREATE);
17003 + test_ret(FS_DELETE);
17004 + test_ret(FS_DELETE_SELF);
17005 + test_ret(FS_MOVE_SELF);
17006 + test_ret(FS_UNMOUNT);
17007 + test_ret(FS_Q_OVERFLOW);
17008 + test_ret(FS_IN_IGNORED);
17009 + test_ret(FS_ISDIR);
17010 + test_ret(FS_IN_ONESHOT);
17011 + test_ret(FS_EVENT_ON_CHILD);
17020 +/* ---------------------------------------------------------------------- */
17022 +static void au_hfsn_free_group(struct fsnotify_group *group)
17024 + struct au_br_hfsnotify *hfsn = group->private;
17026 + /* AuDbg("here\n"); */
17027 + au_kfree_try_rcu(hfsn);
17030 +static int au_hfsn_handle_event(struct fsnotify_group *group,
17031 + struct inode *inode,
17032 + u32 mask, const void *data, int data_type,
17033 + const unsigned char *file_name, u32 cookie,
17034 + struct fsnotify_iter_info *iter_info)
17037 + struct au_hnotify *hnotify;
17038 + struct inode *h_dir, *h_inode;
17039 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
17040 + struct fsnotify_mark *inode_mark;
17042 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
17045 + /* if FS_UNMOUNT happens, there must be another bug */
17046 + AuDebugOn(mask & FS_UNMOUNT);
17047 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
17052 +#ifdef AuDbgHnotify
17054 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
17055 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
17056 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
17057 + h_dir->i_ino, mask, au_hfsn_name(mask),
17058 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
17059 + /* WARN_ON(1); */
17064 + inode_mark = fsnotify_iter_inode_mark(iter_info);
17065 + AuDebugOn(!inode_mark);
17066 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
17067 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
17073 +static struct fsnotify_ops au_hfsn_ops = {
17074 + .handle_event = au_hfsn_handle_event,
17075 + .free_group_priv = au_hfsn_free_group,
17076 + .free_mark = au_hfsn_free_mark
17079 +/* ---------------------------------------------------------------------- */
17081 +static void au_hfsn_fin_br(struct au_branch *br)
17083 + struct au_br_hfsnotify *hfsn;
17085 + hfsn = br->br_hfsn;
17088 + fsnotify_put_group(hfsn->hfsn_group);
17093 +static int au_hfsn_init_br(struct au_branch *br, int perm)
17096 + struct fsnotify_group *group;
17097 + struct au_br_hfsnotify *hfsn;
17100 + br->br_hfsn = NULL;
17101 + if (!au_br_hnotifyable(perm))
17105 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
17106 + if (unlikely(!hfsn))
17110 + group = fsnotify_alloc_group(&au_hfsn_ops);
17111 + if (IS_ERR(group)) {
17112 + err = PTR_ERR(group);
17113 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
17117 + group->private = hfsn;
17118 + hfsn->hfsn_group = group;
17119 + br->br_hfsn = hfsn;
17120 + goto out; /* success */
17123 + au_kfree_try_rcu(hfsn);
17128 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
17133 + if (!br->br_hfsn)
17134 + err = au_hfsn_init_br(br, perm);
17139 +/* ---------------------------------------------------------------------- */
17141 +static void au_hfsn_fin(void)
17143 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
17144 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
17147 +const struct au_hnotify_op au_hnotify_op = {
17148 + .ctl = au_hfsn_ctl,
17149 + .alloc = au_hfsn_alloc,
17150 + .free = au_hfsn_free,
17152 + .fin = au_hfsn_fin,
17154 + .reset_br = au_hfsn_reset_br,
17155 + .fin_br = au_hfsn_fin_br,
17156 + .init_br = au_hfsn_init_br
17158 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
17159 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
17160 +++ linux/fs/aufs/hfsplus.c 2021-02-22 23:30:37.702680911 +0100
17162 +// SPDX-License-Identifier: GPL-2.0
17164 + * Copyright (C) 2010-2020 Junjiro R. Okajima
17166 + * This program, aufs is free software; you can redistribute it and/or modify
17167 + * it under the terms of the GNU General Public License as published by
17168 + * the Free Software Foundation; either version 2 of the License, or
17169 + * (at your option) any later version.
17171 + * This program is distributed in the hope that it will be useful,
17172 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17173 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17174 + * GNU General Public License for more details.
17176 + * You should have received a copy of the GNU General Public License
17177 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17181 + * special support for filesystems which acquires an inode mutex
17182 + * at final closing a file, eg, hfsplus.
17184 + * This trick is very simple and stupid, just to open the file before really
17185 + * necessary open to tell hfsplus that this is not the final closing.
17186 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17187 + * and au_h_open_post() after releasing it.
17192 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17195 + struct file *h_file;
17196 + struct dentry *h_dentry;
17198 + h_dentry = au_h_dptr(dentry, bindex);
17199 + AuDebugOn(!h_dentry);
17200 + AuDebugOn(d_is_negative(h_dentry));
17203 + if (au_test_hfsplus(h_dentry->d_sb)
17204 + && d_is_reg(h_dentry))
17205 + h_file = au_h_open(dentry, bindex,
17206 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17207 + /*file*/NULL, force_wr);
17211 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17212 + struct file *h_file)
17214 + struct au_branch *br;
17218 + br = au_sbr(dentry->d_sb, bindex);
17219 + au_lcnt_dec(&br->br_nfiles);
17222 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17223 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17224 +++ linux/fs/aufs/hnotify.c 2021-02-22 23:30:37.702680911 +0100
17226 +// SPDX-License-Identifier: GPL-2.0
17228 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17230 + * This program, aufs is free software; you can redistribute it and/or modify
17231 + * it under the terms of the GNU General Public License as published by
17232 + * the Free Software Foundation; either version 2 of the License, or
17233 + * (at your option) any later version.
17235 + * This program is distributed in the hope that it will be useful,
17236 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17237 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17238 + * GNU General Public License for more details.
17240 + * You should have received a copy of the GNU General Public License
17241 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17245 + * abstraction to notify the direct changes on lower directories
17248 +/* #include <linux/iversion.h> */
17251 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17254 + struct au_hnotify *hn;
17257 + hn = au_cache_alloc_hnotify();
17259 + hn->hn_aufs_inode = inode;
17260 + hinode->hi_notify = hn;
17261 + err = au_hnotify_op.alloc(hinode);
17263 + if (unlikely(err)) {
17264 + hinode->hi_notify = NULL;
17265 + au_cache_free_hnotify(hn);
17267 + * The upper dir was removed by udba, but the same named
17268 + * dir left. In this case, aufs assigns a new inode
17269 + * number and set the monitor again.
17270 + * For the lower dir, the old monitor is still left.
17272 + if (err == -EEXIST)
17281 +void au_hn_free(struct au_hinode *hinode)
17283 + struct au_hnotify *hn;
17285 + hn = hinode->hi_notify;
17287 + hinode->hi_notify = NULL;
17288 + if (au_hnotify_op.free(hinode, hn))
17289 + au_cache_free_hnotify(hn);
17293 +/* ---------------------------------------------------------------------- */
17295 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17297 + if (hinode->hi_notify)
17298 + au_hnotify_op.ctl(hinode, do_set);
17301 +void au_hn_reset(struct inode *inode, unsigned int flags)
17303 + aufs_bindex_t bindex, bbot;
17304 + struct inode *hi;
17305 + struct dentry *iwhdentry;
17307 + bbot = au_ibbot(inode);
17308 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17309 + hi = au_h_iptr(inode, bindex);
17313 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17314 + iwhdentry = au_hi_wh(inode, bindex);
17318 + au_set_h_iptr(inode, bindex, NULL, 0);
17319 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17320 + flags & ~AuHi_XINO);
17323 + /* inode_unlock(hi); */
17327 +/* ---------------------------------------------------------------------- */
17329 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17332 + aufs_bindex_t bindex, bbot, bfound, btop;
17333 + struct inode *h_i;
17336 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17337 + pr_warn("branch root dir was changed\n");
17342 + bbot = au_ibbot(inode);
17343 + btop = au_ibtop(inode);
17344 +#if 0 /* reserved for future use */
17345 + if (bindex == bbot) {
17346 + /* keep this ino in rename case */
17350 + for (bindex = btop; bindex <= bbot; bindex++)
17351 + if (au_h_iptr(inode, bindex) == h_inode) {
17358 + for (bindex = btop; bindex <= bbot; bindex++) {
17359 + h_i = au_h_iptr(inode, bindex);
17363 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17364 + /* ignore this error */
17365 + /* bad action? */
17368 + /* children inode number will be broken */
17375 +static int hn_gen_tree(struct dentry *dentry)
17377 + int err, i, j, ndentry;
17378 + struct au_dcsub_pages dpages;
17379 + struct au_dpage *dpage;
17380 + struct dentry **dentries;
17382 + err = au_dpages_init(&dpages, GFP_NOFS);
17383 + if (unlikely(err))
17385 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17386 + if (unlikely(err))
17389 + for (i = 0; i < dpages.ndpage; i++) {
17390 + dpage = dpages.dpages + i;
17391 + dentries = dpage->dentries;
17392 + ndentry = dpage->ndentry;
17393 + for (j = 0; j < ndentry; j++) {
17394 + struct dentry *d;
17401 + if (d_really_is_positive(d))
17402 + /* todo: reset children xino?
17403 + cached children only? */
17404 + au_iigen_dec(d_inode(d));
17409 + au_dpages_free(&dpages);
17415 + * return 0 if processed.
17417 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17418 + const unsigned int isdir)
17421 + struct dentry *d;
17422 + struct qstr *dname;
17425 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17426 + pr_warn("branch root dir was changed\n");
17432 + AuDebugOn(!name);
17433 + au_iigen_dec(inode);
17434 + spin_lock(&inode->i_lock);
17435 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17436 + spin_lock(&d->d_lock);
17437 + dname = &d->d_name;
17438 + if (dname->len != nlen
17439 + && memcmp(dname->name, name, nlen)) {
17440 + spin_unlock(&d->d_lock);
17445 + spin_unlock(&d->d_lock);
17448 + spin_unlock(&inode->i_lock);
17450 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17451 + d = d_find_any_alias(inode);
17453 + au_iigen_dec(inode);
17457 + spin_lock(&d->d_lock);
17458 + dname = &d->d_name;
17459 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17460 + spin_unlock(&d->d_lock);
17461 + err = hn_gen_tree(d);
17462 + spin_lock(&d->d_lock);
17464 + spin_unlock(&d->d_lock);
17473 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17477 + if (IS_ROOT(dentry)) {
17478 + pr_warn("branch root dir was changed\n");
17484 + au_digen_dec(dentry);
17485 + if (d_really_is_positive(dentry))
17486 + au_iigen_dec(d_inode(dentry));
17488 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17489 + if (d_really_is_positive(dentry))
17490 + err = hn_gen_tree(dentry);
17497 +/* ---------------------------------------------------------------------- */
17499 +/* hnotify job flags */
17500 +#define AuHnJob_XINO0 1
17501 +#define AuHnJob_GEN (1 << 1)
17502 +#define AuHnJob_DIRENT (1 << 2)
17503 +#define AuHnJob_ISDIR (1 << 3)
17504 +#define AuHnJob_TRYXINO0 (1 << 4)
17505 +#define AuHnJob_MNTPNT (1 << 5)
17506 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17507 +#define au_fset_hnjob(flags, name) \
17508 + do { (flags) |= AuHnJob_##name; } while (0)
17509 +#define au_fclr_hnjob(flags, name) \
17510 + do { (flags) &= ~AuHnJob_##name; } while (0)
17518 +struct au_hnotify_args {
17519 + struct inode *h_dir, *dir, *h_child_inode;
17521 + unsigned int flags[AuHnLast];
17522 + unsigned int h_child_nlen;
17523 + char h_child_name[];
17526 +struct hn_job_args {
17527 + unsigned int flags;
17528 + struct inode *inode, *h_inode, *dir, *h_dir;
17529 + struct dentry *dentry;
17534 +static int hn_job(struct hn_job_args *a)
17536 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17540 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17541 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17543 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17546 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17547 + if (!a->h_inode->i_nlink
17548 + && !(a->h_inode->i_state & I_LINKABLE))
17549 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17550 + inode_unlock_shared(a->h_inode);
17553 + /* make the generation obsolete */
17554 + if (au_ftest_hnjob(a->flags, GEN)) {
17557 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17559 + if (e && a->dentry)
17560 + hn_gen_by_name(a->dentry, isdir);
17561 + /* ignore this error */
17564 + /* make dir entries obsolete */
17565 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17566 + struct au_vdir *vdir;
17568 + vdir = au_ivdir(a->inode);
17570 + vdir->vd_jiffy = 0;
17571 + /* IMustLock(a->inode); */
17572 + /* inode_inc_iversion(a->inode); */
17575 + /* can do nothing but warn */
17576 + if (au_ftest_hnjob(a->flags, MNTPNT)
17578 + && d_mountpoint(a->dentry))
17579 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17584 +/* ---------------------------------------------------------------------- */
17586 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17587 + struct inode *dir)
17589 + struct dentry *dentry, *d, *parent;
17590 + struct qstr *dname;
17592 + parent = d_find_any_alias(dir);
17597 + spin_lock(&parent->d_lock);
17598 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17599 + /* AuDbg("%pd\n", d); */
17600 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17601 + dname = &d->d_name;
17602 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17603 + goto cont_unlock;
17607 + goto cont_unlock;
17608 + if (au_dcount(d) > 0) {
17609 + dentry = dget_dlock(d);
17610 + spin_unlock(&d->d_lock);
17615 + spin_unlock(&d->d_lock);
17617 + spin_unlock(&parent->d_lock);
17621 + di_write_lock_child(dentry);
17626 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17627 + aufs_bindex_t bindex, ino_t h_ino)
17629 + struct inode *inode;
17634 + err = au_xino_read(sb, bindex, h_ino, &ino);
17636 + inode = ilookup(sb, ino);
17640 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17641 + pr_warn("wrong root branch\n");
17647 + ii_write_lock_child(inode);
17653 +static void au_hn_bh(void *_args)
17655 + struct au_hnotify_args *a = _args;
17656 + struct super_block *sb;
17657 + aufs_bindex_t bindex, bbot, bfound;
17658 + unsigned char xino, try_iput;
17660 + struct inode *inode;
17662 + struct hn_job_args args;
17663 + struct dentry *dentry;
17664 + struct au_sbinfo *sbinfo;
17666 + AuDebugOn(!_args);
17667 + AuDebugOn(!a->h_dir);
17668 + AuDebugOn(!a->dir);
17669 + AuDebugOn(!a->mask);
17670 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17671 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17672 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17677 + * do not lock a->dir->i_mutex here
17678 + * because of d_revalidate() may cause a deadlock.
17680 + sb = a->dir->i_sb;
17682 + sbinfo = au_sbi(sb);
17683 + AuDebugOn(!sbinfo);
17684 + si_write_lock(sb, AuLock_NOPLMW);
17686 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17687 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17688 + case FS_MOVED_FROM:
17689 + case FS_MOVED_TO:
17690 + AuWarn1("DIRREN with UDBA may not work correctly "
17691 + "for the direct rename(2)\n");
17694 + ii_read_lock_parent(a->dir);
17696 + bbot = au_ibbot(a->dir);
17697 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17698 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17702 + ii_read_unlock(a->dir);
17703 + if (unlikely(bfound < 0))
17706 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17708 + if (a->h_child_inode)
17709 + h_ino = a->h_child_inode->i_ino;
17711 + if (a->h_child_nlen
17712 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17713 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17714 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17717 + if (dentry && d_really_is_positive(dentry))
17718 + inode = d_inode(dentry);
17719 + if (xino && !inode && h_ino
17720 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17721 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17722 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17723 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17727 + args.flags = a->flags[AuHn_CHILD];
17728 + args.dentry = dentry;
17729 + args.inode = inode;
17730 + args.h_inode = a->h_child_inode;
17731 + args.dir = a->dir;
17732 + args.h_dir = a->h_dir;
17733 + args.h_name = a->h_child_name;
17734 + args.h_nlen = a->h_child_nlen;
17735 + err = hn_job(&args);
17737 + if (au_di(dentry))
17738 + di_write_unlock(dentry);
17741 + if (inode && try_iput) {
17742 + ii_write_unlock(inode);
17746 + ii_write_lock_parent(a->dir);
17747 + args.flags = a->flags[AuHn_PARENT];
17748 + args.dentry = NULL;
17749 + args.inode = a->dir;
17750 + args.h_inode = a->h_dir;
17752 + args.h_dir = NULL;
17753 + args.h_name = NULL;
17755 + err = hn_job(&args);
17756 + ii_write_unlock(a->dir);
17759 + iput(a->h_child_inode);
17762 + si_write_unlock(sb);
17763 + au_nwt_done(&sbinfo->si_nowait);
17767 +/* ---------------------------------------------------------------------- */
17769 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17770 + struct qstr *h_child_qstr, struct inode *h_child_inode)
17773 + unsigned int flags[AuHnLast], f;
17774 + unsigned char isdir, isroot, wh;
17775 + struct inode *dir;
17776 + struct au_hnotify_args *args;
17777 + char *p, *h_child_name;
17780 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17781 + dir = igrab(hnotify->hn_aufs_inode);
17785 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17787 + h_child_name = (void *)h_child_qstr->name;
17788 + len = h_child_qstr->len;
17789 + if (h_child_name) {
17790 + if (len > AUFS_WH_PFX_LEN
17791 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17792 + h_child_name += AUFS_WH_PFX_LEN;
17793 + len -= AUFS_WH_PFX_LEN;
17799 + if (h_child_inode)
17800 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17801 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17802 + flags[AuHn_CHILD] = 0;
17804 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17805 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17806 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17807 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
17808 + case FS_MOVED_FROM:
17809 + case FS_MOVED_TO:
17810 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17811 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17814 + AuDebugOn(!h_child_name);
17819 + * aufs never be able to get this child inode.
17820 + * revalidation should be in d_revalidate()
17821 + * by checking i_nlink, i_generation or d_unhashed().
17823 + AuDebugOn(!h_child_name);
17824 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17825 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17833 + h_child_inode = NULL;
17836 + /* iput() and kfree() will be called in au_hnotify() */
17837 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17838 + if (unlikely(!args)) {
17839 + AuErr1("no memory\n");
17843 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17844 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17845 + args->mask = mask;
17847 + args->h_dir = igrab(h_dir);
17848 + if (h_child_inode)
17849 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17850 + args->h_child_inode = h_child_inode;
17851 + args->h_child_nlen = len;
17853 + p = (void *)args;
17854 + p += sizeof(*args);
17855 + memcpy(p, h_child_name, len);
17859 + /* NFS fires the event for silly-renamed one from kworker */
17861 + if (!dir->i_nlink
17862 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17864 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17865 + if (unlikely(err)) {
17866 + pr_err("wkq %d\n", err);
17867 + iput(args->h_child_inode);
17868 + iput(args->h_dir);
17870 + au_kfree_rcu(args);
17877 +/* ---------------------------------------------------------------------- */
17879 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17883 + AuDebugOn(!(udba & AuOptMask_UDBA));
17886 + if (au_hnotify_op.reset_br)
17887 + err = au_hnotify_op.reset_br(udba, br, perm);
17892 +int au_hnotify_init_br(struct au_branch *br, int perm)
17897 + if (au_hnotify_op.init_br)
17898 + err = au_hnotify_op.init_br(br, perm);
17903 +void au_hnotify_fin_br(struct au_branch *br)
17905 + if (au_hnotify_op.fin_br)
17906 + au_hnotify_op.fin_br(br);
17909 +static void au_hn_destroy_cache(void)
17911 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17912 + au_cache[AuCache_HNOTIFY] = NULL;
17915 +int __init au_hnotify_init(void)
17920 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17921 + if (au_cache[AuCache_HNOTIFY]) {
17923 + if (au_hnotify_op.init)
17924 + err = au_hnotify_op.init();
17925 + if (unlikely(err))
17926 + au_hn_destroy_cache();
17932 +void au_hnotify_fin(void)
17934 + if (au_hnotify_op.fin)
17935 + au_hnotify_op.fin();
17937 + /* cf. au_cache_fin() */
17938 + if (au_cache[AuCache_HNOTIFY])
17939 + au_hn_destroy_cache();
17941 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17942 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17943 +++ linux/fs/aufs/iinfo.c 2021-02-22 23:30:37.702680911 +0100
17945 +// SPDX-License-Identifier: GPL-2.0
17947 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17949 + * This program, aufs is free software; you can redistribute it and/or modify
17950 + * it under the terms of the GNU General Public License as published by
17951 + * the Free Software Foundation; either version 2 of the License, or
17952 + * (at your option) any later version.
17954 + * This program is distributed in the hope that it will be useful,
17955 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17956 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17957 + * GNU General Public License for more details.
17959 + * You should have received a copy of the GNU General Public License
17960 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17964 + * inode private data
17969 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17971 + struct inode *h_inode;
17972 + struct au_hinode *hinode;
17974 + IiMustAnyLock(inode);
17976 + hinode = au_hinode(au_ii(inode), bindex);
17977 + h_inode = hinode->hi_inode;
17978 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17982 +/* todo: hard/soft set? */
17983 +void au_hiput(struct au_hinode *hinode)
17985 + au_hn_free(hinode);
17986 + dput(hinode->hi_whdentry);
17987 + iput(hinode->hi_inode);
17990 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17992 + unsigned int flags;
17993 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17996 + if (au_opt_test(mnt_flags, XINO))
17997 + au_fset_hi(flags, XINO);
17998 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17999 + au_fset_hi(flags, HNOTIFY);
18003 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18004 + struct inode *h_inode, unsigned int flags)
18006 + struct au_hinode *hinode;
18007 + struct inode *hi;
18008 + struct au_iinfo *iinfo = au_ii(inode);
18010 + IiMustWriteLock(inode);
18012 + hinode = au_hinode(iinfo, bindex);
18013 + hi = hinode->hi_inode;
18014 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18017 + au_hiput(hinode);
18018 + hinode->hi_inode = h_inode;
18021 + struct super_block *sb = inode->i_sb;
18022 + struct au_branch *br;
18024 + AuDebugOn(inode->i_mode
18025 + && (h_inode->i_mode & S_IFMT)
18026 + != (inode->i_mode & S_IFMT));
18027 + if (bindex == iinfo->ii_btop)
18028 + au_cpup_igen(inode, h_inode);
18029 + br = au_sbr(sb, bindex);
18030 + hinode->hi_id = br->br_id;
18031 + if (au_ftest_hi(flags, XINO)) {
18032 + err = au_xino_write(sb, bindex, h_inode->i_ino,
18034 + if (unlikely(err))
18035 + AuIOErr1("failed au_xino_write() %d\n", err);
18038 + if (au_ftest_hi(flags, HNOTIFY)
18039 + && au_br_hnotifyable(br->br_perm)) {
18040 + err = au_hn_alloc(hinode, inode);
18041 + if (unlikely(err))
18042 + AuIOErr1("au_hn_alloc() %d\n", err);
18047 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18048 + struct dentry *h_wh)
18050 + struct au_hinode *hinode;
18052 + IiMustWriteLock(inode);
18054 + hinode = au_hinode(au_ii(inode), bindex);
18055 + AuDebugOn(hinode->hi_whdentry);
18056 + hinode->hi_whdentry = h_wh;
18059 +void au_update_iigen(struct inode *inode, int half)
18061 + struct au_iinfo *iinfo;
18062 + struct au_iigen *iigen;
18063 + unsigned int sigen;
18065 + sigen = au_sigen(inode->i_sb);
18066 + iinfo = au_ii(inode);
18067 + iigen = &iinfo->ii_generation;
18068 + spin_lock(&iigen->ig_spin);
18069 + iigen->ig_generation = sigen;
18071 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
18073 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
18074 + spin_unlock(&iigen->ig_spin);
18077 +/* it may be called at remount time, too */
18078 +void au_update_ibrange(struct inode *inode, int do_put_zero)
18080 + struct au_iinfo *iinfo;
18081 + aufs_bindex_t bindex, bbot;
18083 + AuDebugOn(au_is_bad_inode(inode));
18084 + IiMustWriteLock(inode);
18086 + iinfo = au_ii(inode);
18087 + if (do_put_zero && iinfo->ii_btop >= 0) {
18088 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18090 + struct inode *h_i;
18092 + h_i = au_hinode(iinfo, bindex)->hi_inode;
18095 + && !(h_i->i_state & I_LINKABLE))
18096 + au_set_h_iptr(inode, bindex, NULL, 0);
18100 + iinfo->ii_btop = -1;
18101 + iinfo->ii_bbot = -1;
18102 + bbot = au_sbbot(inode->i_sb);
18103 + for (bindex = 0; bindex <= bbot; bindex++)
18104 + if (au_hinode(iinfo, bindex)->hi_inode) {
18105 + iinfo->ii_btop = bindex;
18108 + if (iinfo->ii_btop >= 0)
18109 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
18110 + if (au_hinode(iinfo, bindex)->hi_inode) {
18111 + iinfo->ii_bbot = bindex;
18114 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
18117 +/* ---------------------------------------------------------------------- */
18119 +void au_icntnr_init_once(void *_c)
18121 + struct au_icntnr *c = _c;
18122 + struct au_iinfo *iinfo = &c->iinfo;
18124 + spin_lock_init(&iinfo->ii_generation.ig_spin);
18125 + au_rw_init(&iinfo->ii_rwsem);
18126 + inode_init_once(&c->vfs_inode);
18129 +void au_hinode_init(struct au_hinode *hinode)
18131 + hinode->hi_inode = NULL;
18132 + hinode->hi_id = -1;
18133 + au_hn_init(hinode);
18134 + hinode->hi_whdentry = NULL;
18137 +int au_iinfo_init(struct inode *inode)
18139 + struct au_iinfo *iinfo;
18140 + struct super_block *sb;
18141 + struct au_hinode *hi;
18144 + sb = inode->i_sb;
18145 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18146 + nbr = au_sbbot(sb) + 1;
18147 + if (unlikely(nbr <= 0))
18149 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
18151 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
18153 + iinfo->ii_hinode = hi;
18154 + for (i = 0; i < nbr; i++, hi++)
18155 + au_hinode_init(hi);
18157 + iinfo->ii_generation.ig_generation = au_sigen(sb);
18158 + iinfo->ii_btop = -1;
18159 + iinfo->ii_bbot = -1;
18160 + iinfo->ii_vdir = NULL;
18166 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
18169 + struct au_hinode *hip;
18171 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18174 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18177 + iinfo->ii_hinode = hip;
18178 + i = iinfo->ii_bbot + 1;
18180 + for (; i < nbr; i++, hip++)
18181 + au_hinode_init(hip);
18188 +void au_iinfo_fin(struct inode *inode)
18190 + struct au_iinfo *iinfo;
18191 + struct au_hinode *hi;
18192 + struct super_block *sb;
18193 + aufs_bindex_t bindex, bbot;
18194 + const unsigned char unlinked = !inode->i_nlink;
18196 + AuDebugOn(au_is_bad_inode(inode));
18198 + sb = inode->i_sb;
18199 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18200 + if (si_pid_test(sb))
18201 + au_xino_delete_inode(inode, unlinked);
18204 + * it is safe to hide the dependency between sbinfo and
18208 + si_noflush_read_lock(sb);
18209 + au_xino_delete_inode(inode, unlinked);
18210 + si_read_unlock(sb);
18214 + iinfo = au_ii(inode);
18215 + if (iinfo->ii_vdir)
18216 + au_vdir_free(iinfo->ii_vdir);
18218 + bindex = iinfo->ii_btop;
18219 + if (bindex >= 0) {
18220 + hi = au_hinode(iinfo, bindex);
18221 + bbot = iinfo->ii_bbot;
18222 + while (bindex++ <= bbot) {
18223 + if (hi->hi_inode)
18228 + au_kfree_rcu(iinfo->ii_hinode);
18229 + AuRwDestroy(&iinfo->ii_rwsem);
18231 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18232 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18233 +++ linux/fs/aufs/inode.c 2021-02-22 23:30:37.702680911 +0100
18235 +// SPDX-License-Identifier: GPL-2.0
18237 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18239 + * This program, aufs is free software; you can redistribute it and/or modify
18240 + * it under the terms of the GNU General Public License as published by
18241 + * the Free Software Foundation; either version 2 of the License, or
18242 + * (at your option) any later version.
18244 + * This program is distributed in the hope that it will be useful,
18245 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18247 + * GNU General Public License for more details.
18249 + * You should have received a copy of the GNU General Public License
18250 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18254 + * inode functions
18257 +#include <linux/iversion.h>
18260 +struct inode *au_igrab(struct inode *inode)
18263 + AuDebugOn(!atomic_read(&inode->i_count));
18269 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18271 + au_cpup_attr_all(inode, /*force*/0);
18272 + au_update_iigen(inode, /*half*/1);
18274 + inode_inc_iversion(inode);
18277 +static int au_ii_refresh(struct inode *inode, int *update)
18281 + aufs_bindex_t bindex, new_bindex;
18282 + struct super_block *sb;
18283 + struct au_iinfo *iinfo;
18284 + struct au_hinode *p, *q, tmp;
18286 + AuDebugOn(au_is_bad_inode(inode));
18287 + IiMustWriteLock(inode);
18290 + sb = inode->i_sb;
18291 + nbr = au_sbbot(sb) + 1;
18292 + type = inode->i_mode & S_IFMT;
18293 + iinfo = au_ii(inode);
18294 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18295 + if (unlikely(err))
18298 + AuDebugOn(iinfo->ii_btop < 0);
18299 + p = au_hinode(iinfo, iinfo->ii_btop);
18300 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18302 + if (!p->hi_inode)
18305 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18306 + new_bindex = au_br_index(sb, p->hi_id);
18307 + if (new_bindex == bindex)
18310 + if (new_bindex < 0) {
18313 + p->hi_inode = NULL;
18317 + if (new_bindex < iinfo->ii_btop)
18318 + iinfo->ii_btop = new_bindex;
18319 + if (iinfo->ii_bbot < new_bindex)
18320 + iinfo->ii_bbot = new_bindex;
18321 + /* swap two lower inode, and loop again */
18322 + q = au_hinode(iinfo, new_bindex);
18326 + if (tmp.hi_inode) {
18331 + au_update_ibrange(inode, /*do_put_zero*/0);
18332 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18333 + e = au_dy_irefresh(inode);
18334 + if (unlikely(e && !err))
18342 +void au_refresh_iop(struct inode *inode, int force_getattr)
18345 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18346 + const struct inode_operations *iop
18347 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18349 + if (inode->i_op == iop)
18352 + switch (inode->i_mode & S_IFMT) {
18354 + type = AuIop_DIR;
18357 + type = AuIop_SYMLINK;
18360 + type = AuIop_OTHER;
18364 + inode->i_op = iop + type;
18365 + /* unnecessary smp_wmb() */
18368 +int au_refresh_hinode_self(struct inode *inode)
18372 + err = au_ii_refresh(inode, &update);
18374 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18380 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18382 + int err, e, update;
18383 + unsigned int flags;
18385 + aufs_bindex_t bindex, bbot;
18386 + unsigned char isdir;
18387 + struct au_hinode *p;
18388 + struct au_iinfo *iinfo;
18390 + err = au_ii_refresh(inode, &update);
18391 + if (unlikely(err))
18395 + iinfo = au_ii(inode);
18396 + p = au_hinode(iinfo, iinfo->ii_btop);
18397 + mode = (inode->i_mode & S_IFMT);
18398 + isdir = S_ISDIR(mode);
18399 + flags = au_hi_flags(inode, isdir);
18400 + bbot = au_dbbot(dentry);
18401 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18402 + struct inode *h_i, *h_inode;
18403 + struct dentry *h_d;
18405 + h_d = au_h_dptr(dentry, bindex);
18406 + if (!h_d || d_is_negative(h_d))
18409 + h_inode = d_inode(h_d);
18410 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18411 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18412 + h_i = au_h_iptr(inode, bindex);
18414 + if (h_i == h_inode)
18420 + if (bindex < iinfo->ii_btop)
18421 + iinfo->ii_btop = bindex;
18422 + if (iinfo->ii_bbot < bindex)
18423 + iinfo->ii_bbot = bindex;
18424 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18427 + au_update_ibrange(inode, /*do_put_zero*/0);
18428 + e = au_dy_irefresh(inode);
18429 + if (unlikely(e && !err))
18432 + au_refresh_hinode_attr(inode, update && isdir);
18439 +static int set_inode(struct inode *inode, struct dentry *dentry)
18442 + unsigned int flags;
18444 + aufs_bindex_t bindex, btop, btail;
18445 + unsigned char isdir;
18446 + struct dentry *h_dentry;
18447 + struct inode *h_inode;
18448 + struct au_iinfo *iinfo;
18449 + const struct inode_operations *iop;
18451 + IiMustWriteLock(inode);
18455 + iop = au_sbi(inode->i_sb)->si_iop_array;
18456 + btop = au_dbtop(dentry);
18457 + h_dentry = au_h_dptr(dentry, btop);
18458 + h_inode = d_inode(h_dentry);
18459 + mode = h_inode->i_mode;
18460 + switch (mode & S_IFMT) {
18462 + btail = au_dbtail(dentry);
18463 + inode->i_op = iop + AuIop_OTHER;
18464 + inode->i_fop = &aufs_file_fop;
18465 + err = au_dy_iaop(inode, btop, h_inode);
18466 + if (unlikely(err))
18471 + btail = au_dbtaildir(dentry);
18472 + inode->i_op = iop + AuIop_DIR;
18473 + inode->i_fop = &aufs_dir_fop;
18476 + btail = au_dbtail(dentry);
18477 + inode->i_op = iop + AuIop_SYMLINK;
18483 + btail = au_dbtail(dentry);
18484 + inode->i_op = iop + AuIop_OTHER;
18485 + init_special_inode(inode, mode, h_inode->i_rdev);
18488 + AuIOErr("Unknown file type 0%o\n", mode);
18493 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18494 + flags = au_hi_flags(inode, isdir);
18495 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18496 + && au_ftest_hi(flags, HNOTIFY)
18497 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18498 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18499 + au_fclr_hi(flags, HNOTIFY);
18500 + iinfo = au_ii(inode);
18501 + iinfo->ii_btop = btop;
18502 + iinfo->ii_bbot = btail;
18503 + for (bindex = btop; bindex <= btail; bindex++) {
18504 + h_dentry = au_h_dptr(dentry, bindex);
18506 + au_set_h_iptr(inode, bindex,
18507 + au_igrab(d_inode(h_dentry)), flags);
18509 + au_cpup_attr_all(inode, /*force*/1);
18511 + * to force calling aufs_get_acl() every time,
18512 + * do not call cache_no_acl() for aufs inode.
18520 + * successful returns with iinfo write_locked
18522 + * zero: success, matched
18523 + * plus: no error, but unmatched
18525 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18528 + unsigned int gen, igflags;
18529 + aufs_bindex_t bindex, bbot;
18530 + struct inode *h_inode, *h_dinode;
18531 + struct dentry *h_dentry;
18534 + * before this function, if aufs got any iinfo lock, it must be only
18535 + * one, the parent dir.
18536 + * it can happen by UDBA and the obsoleted inode number.
18539 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18543 + ii_write_lock_new_child(inode);
18544 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18545 + h_dinode = d_inode(h_dentry);
18546 + bbot = au_ibbot(inode);
18547 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18548 + h_inode = au_h_iptr(inode, bindex);
18549 + if (!h_inode || h_inode != h_dinode)
18553 + gen = au_iigen(inode, &igflags);
18554 + if (gen == au_digen(dentry)
18555 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18558 + /* fully refresh inode using dentry */
18559 + err = au_refresh_hinode(inode, dentry);
18561 + au_update_iigen(inode, /*half*/0);
18565 + if (unlikely(err))
18566 + ii_write_unlock(inode);
18571 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18572 + unsigned int d_type, ino_t *ino)
18575 + const int isnondir = d_type != DT_DIR;
18577 + /* prevent hardlinked inode number from race condition */
18579 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18580 + if (unlikely(err))
18584 + err = au_xino_read(sb, bindex, h_ino, ino);
18585 + if (unlikely(err))
18586 + goto out_xinondir;
18590 + *ino = au_xino_new_ino(sb);
18591 + if (unlikely(!*ino))
18592 + goto out_xinondir;
18593 + err = au_xino_write(sb, bindex, h_ino, *ino);
18594 + if (unlikely(err))
18595 + goto out_xinondir;
18599 + if (isnondir && idx >= 0)
18600 + au_xinondir_leave(sb, bindex, h_ino, idx);
18605 +/* successful returns with iinfo write_locked */
18606 +/* todo: return with unlocked? */
18607 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18609 + struct inode *inode, *h_inode;
18610 + struct dentry *h_dentry;
18611 + struct super_block *sb;
18612 + ino_t h_ino, ino;
18613 + int err, idx, hlinked;
18614 + aufs_bindex_t btop;
18616 + sb = dentry->d_sb;
18617 + btop = au_dbtop(dentry);
18618 + h_dentry = au_h_dptr(dentry, btop);
18619 + h_inode = d_inode(h_dentry);
18620 + h_ino = h_inode->i_ino;
18621 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18625 + * stop 'race'-ing between hardlinks under different
18629 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18630 + inode = ERR_PTR(err);
18631 + if (unlikely(err))
18635 + err = au_xino_read(sb, btop, h_ino, &ino);
18636 + inode = ERR_PTR(err);
18637 + if (unlikely(err))
18638 + goto out_xinondir;
18641 + ino = au_xino_new_ino(sb);
18642 + if (unlikely(!ino)) {
18643 + inode = ERR_PTR(-EIO);
18644 + goto out_xinondir;
18648 + AuDbg("i%lu\n", (unsigned long)ino);
18649 + inode = au_iget_locked(sb, ino);
18650 + err = PTR_ERR(inode);
18651 + if (IS_ERR(inode))
18652 + goto out_xinondir;
18654 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18655 + if (inode->i_state & I_NEW) {
18656 + ii_write_lock_new_child(inode);
18657 + err = set_inode(inode, dentry);
18659 + unlock_new_inode(inode);
18660 + goto out_xinondir; /* success */
18664 + * iget_failed() calls iput(), but we need to call
18665 + * ii_write_unlock() after iget_failed(). so dirty hack for
18668 + atomic_inc(&inode->i_count);
18669 + iget_failed(inode);
18670 + ii_write_unlock(inode);
18671 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18672 + /* ignore this error */
18674 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18676 + * horrible race condition between lookup, readdir and copyup
18677 + * (or something).
18679 + if (hlinked && idx >= 0)
18680 + au_xinondir_leave(sb, btop, h_ino, idx);
18681 + err = reval_inode(inode, dentry);
18682 + if (unlikely(err < 0)) {
18687 + goto out; /* success */
18688 + else if (hlinked && idx >= 0) {
18689 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18690 + if (unlikely(err)) {
18692 + inode = ERR_PTR(err);
18698 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18699 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18700 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18701 + btop, au_sbtype(h_dentry->d_sb), dentry,
18702 + (unsigned long)h_ino, (unsigned long)ino);
18704 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18707 + if (hlinked && idx >= 0)
18708 + au_xinondir_leave(sb, btop, h_ino, idx);
18714 + inode = ERR_PTR(err);
18716 + if (hlinked && idx >= 0)
18717 + au_xinondir_leave(sb, btop, h_ino, idx);
18722 +/* ---------------------------------------------------------------------- */
18724 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18725 + struct inode *inode)
18728 + struct inode *hi;
18730 + err = au_br_rdonly(au_sbr(sb, bindex));
18732 + /* pseudo-link after flushed may happen out of bounds */
18735 + && au_ibtop(inode) <= bindex
18736 + && bindex <= au_ibbot(inode)) {
18738 + * permission check is unnecessary since vfsub routine
18739 + * will be called later
18741 + hi = au_h_iptr(inode, bindex);
18743 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18749 +int au_test_h_perm(struct inode *h_inode, int mask)
18751 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18753 + return inode_permission(h_inode, mask);
18756 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18758 + if (au_test_nfs(h_inode->i_sb)
18759 + && (mask & MAY_WRITE)
18760 + && S_ISDIR(h_inode->i_mode))
18761 + mask |= MAY_READ; /* force permission check */
18762 + return au_test_h_perm(h_inode, mask);
18764 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18765 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18766 +++ linux/fs/aufs/inode.h 2021-02-22 23:30:37.702680911 +0100
18768 +/* SPDX-License-Identifier: GPL-2.0 */
18770 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18772 + * This program, aufs is free software; you can redistribute it and/or modify
18773 + * it under the terms of the GNU General Public License as published by
18774 + * the Free Software Foundation; either version 2 of the License, or
18775 + * (at your option) any later version.
18777 + * This program is distributed in the hope that it will be useful,
18778 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18779 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18780 + * GNU General Public License for more details.
18782 + * You should have received a copy of the GNU General Public License
18783 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18787 + * inode operations
18790 +#ifndef __AUFS_INODE_H__
18791 +#define __AUFS_INODE_H__
18795 +#include <linux/fsnotify.h>
18796 +#include "rwsem.h"
18800 +struct au_hnotify {
18801 +#ifdef CONFIG_AUFS_HNOTIFY
18802 +#ifdef CONFIG_AUFS_HFSNOTIFY
18803 + /* never use fsnotify_add_vfsmount_mark() */
18804 + struct fsnotify_mark hn_mark;
18806 + struct inode *hn_aufs_inode; /* no get/put */
18807 + struct rcu_head rcu;
18809 +} ____cacheline_aligned_in_smp;
18811 +struct au_hinode {
18812 + struct inode *hi_inode;
18813 + aufs_bindex_t hi_id;
18814 +#ifdef CONFIG_AUFS_HNOTIFY
18815 + struct au_hnotify *hi_notify;
18818 + /* reference to the copied-up whiteout with get/put */
18819 + struct dentry *hi_whdentry;
18823 +#define AuIG_HALF_REFRESHED 1
18824 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18825 +#define au_ig_fset(flags, name) \
18826 + do { (flags) |= AuIG_##name; } while (0)
18827 +#define au_ig_fclr(flags, name) \
18828 + do { (flags) &= ~AuIG_##name; } while (0)
18831 + spinlock_t ig_spin;
18832 + __u32 ig_generation, ig_flags;
18837 + struct au_iigen ii_generation;
18838 + struct super_block *ii_hsb1; /* no get/put */
18840 + struct au_rwsem ii_rwsem;
18841 + aufs_bindex_t ii_btop, ii_bbot;
18843 + struct au_hinode *ii_hinode;
18844 + struct au_vdir *ii_vdir;
18847 +struct au_icntnr {
18848 + struct au_iinfo iinfo;
18849 + struct inode vfs_inode;
18850 + struct hlist_bl_node plink;
18851 + struct rcu_head rcu;
18852 +} ____cacheline_aligned_in_smp;
18854 +/* au_pin flags */
18855 +#define AuPin_DI_LOCKED 1
18856 +#define AuPin_MNT_WRITE (1 << 1)
18857 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18858 +#define au_fset_pin(flags, name) \
18859 + do { (flags) |= AuPin_##name; } while (0)
18860 +#define au_fclr_pin(flags, name) \
18861 + do { (flags) &= ~AuPin_##name; } while (0)
18865 + struct dentry *dentry;
18866 + unsigned int udba;
18867 + unsigned char lsc_di, lsc_hi, flags;
18868 + aufs_bindex_t bindex;
18871 + struct dentry *parent;
18872 + struct au_hinode *hdir;
18873 + struct vfsmount *h_mnt;
18875 + /* temporary unlock/relock for copyup */
18876 + struct dentry *h_dentry, *h_parent;
18877 + struct au_branch *br;
18878 + struct task_struct *task;
18881 +void au_pin_hdir_unlock(struct au_pin *p);
18882 +int au_pin_hdir_lock(struct au_pin *p);
18883 +int au_pin_hdir_relock(struct au_pin *p);
18884 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18885 +void au_pin_hdir_release(struct au_pin *p);
18887 +/* ---------------------------------------------------------------------- */
18889 +static inline struct au_iinfo *au_ii(struct inode *inode)
18891 + BUG_ON(is_bad_inode(inode));
18892 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18895 +/* ---------------------------------------------------------------------- */
18898 +struct inode *au_igrab(struct inode *inode);
18899 +void au_refresh_iop(struct inode *inode, int force_getattr);
18900 +int au_refresh_hinode_self(struct inode *inode);
18901 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18902 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18903 + unsigned int d_type, ino_t *ino);
18904 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18905 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18906 + struct inode *inode);
18907 +int au_test_h_perm(struct inode *h_inode, int mask);
18908 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18910 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18911 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18913 +#ifdef CONFIG_AUFS_SHWH
18914 + return au_ino(sb, bindex, h_ino, d_type, ino);
18927 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18928 + aufs_iop_nogetattr[AuIop_Last];
18930 +/* au_wr_dir flags */
18931 +#define AuWrDir_ADD_ENTRY 1
18932 +#define AuWrDir_ISDIR (1 << 1)
18933 +#define AuWrDir_TMPFILE (1 << 2)
18934 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18935 +#define au_fset_wrdir(flags, name) \
18936 + do { (flags) |= AuWrDir_##name; } while (0)
18937 +#define au_fclr_wrdir(flags, name) \
18938 + do { (flags) &= ~AuWrDir_##name; } while (0)
18940 +struct au_wr_dir_args {
18941 + aufs_bindex_t force_btgt;
18942 + unsigned char flags;
18944 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18945 + struct au_wr_dir_args *args);
18947 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18948 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18949 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18950 + unsigned int udba, unsigned char flags);
18951 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18952 + unsigned int udba, unsigned char flags) __must_check;
18953 +int au_do_pin(struct au_pin *pin) __must_check;
18954 +void au_unpin(struct au_pin *pin);
18955 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18957 +#define AuIcpup_DID_CPUP 1
18958 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18959 +#define au_fset_icpup(flags, name) \
18960 + do { (flags) |= AuIcpup_##name; } while (0)
18961 +#define au_fclr_icpup(flags, name) \
18962 + do { (flags) &= ~AuIcpup_##name; } while (0)
18964 +struct au_icpup_args {
18965 + unsigned char flags;
18966 + unsigned char pin_flags;
18967 + aufs_bindex_t btgt;
18968 + unsigned int udba;
18969 + struct au_pin pin;
18970 + struct path h_path;
18971 + struct inode *h_inode;
18974 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18975 + struct au_icpup_args *a);
18977 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18978 + struct path *h_path, int locked);
18981 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18982 + struct dentry *h_parent, int isdir);
18983 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18985 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18986 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18988 +struct vfsub_aopen_args;
18989 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18990 + struct vfsub_aopen_args *args);
18991 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18992 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18993 + struct dentry *dentry);
18994 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18997 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18998 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18999 + struct dentry *h_parent, int isdir);
19000 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
19001 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
19004 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
19005 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
19006 + struct inode *dir, struct dentry *dentry,
19007 + unsigned int flags);
19010 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
19011 +void au_hiput(struct au_hinode *hinode);
19012 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19013 + struct dentry *h_wh);
19014 +unsigned int au_hi_flags(struct inode *inode, int isdir);
19016 +/* hinode flags */
19017 +#define AuHi_XINO 1
19018 +#define AuHi_HNOTIFY (1 << 1)
19019 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
19020 +#define au_fset_hi(flags, name) \
19021 + do { (flags) |= AuHi_##name; } while (0)
19022 +#define au_fclr_hi(flags, name) \
19023 + do { (flags) &= ~AuHi_##name; } while (0)
19025 +#ifndef CONFIG_AUFS_HNOTIFY
19026 +#undef AuHi_HNOTIFY
19027 +#define AuHi_HNOTIFY 0
19030 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19031 + struct inode *h_inode, unsigned int flags);
19033 +void au_update_iigen(struct inode *inode, int half);
19034 +void au_update_ibrange(struct inode *inode, int do_put_zero);
19036 +void au_icntnr_init_once(void *_c);
19037 +void au_hinode_init(struct au_hinode *hinode);
19038 +int au_iinfo_init(struct inode *inode);
19039 +void au_iinfo_fin(struct inode *inode);
19040 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
19042 +#ifdef CONFIG_PROC_FS
19044 +int au_plink_maint(struct super_block *sb, int flags);
19046 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
19047 +int au_plink_maint_enter(struct super_block *sb);
19048 +#ifdef CONFIG_AUFS_DEBUG
19049 +void au_plink_list(struct super_block *sb);
19051 +AuStubVoid(au_plink_list, struct super_block *sb)
19053 +int au_plink_test(struct inode *inode);
19054 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
19055 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
19056 + struct dentry *h_dentry);
19057 +void au_plink_put(struct super_block *sb, int verbose);
19058 +void au_plink_clean(struct super_block *sb, int verbose);
19059 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
19061 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
19062 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
19063 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
19064 +AuStubVoid(au_plink_list, struct super_block *sb);
19065 +AuStubInt0(au_plink_test, struct inode *inode);
19066 +AuStub(struct dentry *, au_plink_lkup, return NULL,
19067 + struct inode *inode, aufs_bindex_t bindex);
19068 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
19069 + struct dentry *h_dentry);
19070 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
19071 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
19072 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
19073 +#endif /* CONFIG_PROC_FS */
19075 +#ifdef CONFIG_AUFS_XATTR
19077 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
19078 + unsigned int verbose);
19079 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
19080 +void au_xattr_init(struct super_block *sb);
19082 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
19083 + int ignore_flags, unsigned int verbose);
19084 +AuStubVoid(au_xattr_init, struct super_block *sb);
19087 +#ifdef CONFIG_FS_POSIX_ACL
19088 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
19089 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
19092 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19098 +struct au_sxattr {
19102 + const char *name;
19103 + const void *value;
19108 + struct posix_acl *acl;
19113 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19114 + struct au_sxattr *arg);
19117 +/* ---------------------------------------------------------------------- */
19119 +/* lock subclass for iinfo */
19121 + AuLsc_II_CHILD, /* child first */
19122 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
19123 + AuLsc_II_CHILD3, /* copyup dirs */
19124 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
19125 + AuLsc_II_PARENT2,
19126 + AuLsc_II_PARENT3, /* copyup dirs */
19127 + AuLsc_II_NEW_CHILD
19131 + * ii_read_lock_child, ii_write_lock_child,
19132 + * ii_read_lock_child2, ii_write_lock_child2,
19133 + * ii_read_lock_child3, ii_write_lock_child3,
19134 + * ii_read_lock_parent, ii_write_lock_parent,
19135 + * ii_read_lock_parent2, ii_write_lock_parent2,
19136 + * ii_read_lock_parent3, ii_write_lock_parent3,
19137 + * ii_read_lock_new_child, ii_write_lock_new_child,
19139 +#define AuReadLockFunc(name, lsc) \
19140 +static inline void ii_read_lock_##name(struct inode *i) \
19142 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19145 +#define AuWriteLockFunc(name, lsc) \
19146 +static inline void ii_write_lock_##name(struct inode *i) \
19148 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
19151 +#define AuRWLockFuncs(name, lsc) \
19152 + AuReadLockFunc(name, lsc) \
19153 + AuWriteLockFunc(name, lsc)
19155 +AuRWLockFuncs(child, CHILD);
19156 +AuRWLockFuncs(child2, CHILD2);
19157 +AuRWLockFuncs(child3, CHILD3);
19158 +AuRWLockFuncs(parent, PARENT);
19159 +AuRWLockFuncs(parent2, PARENT2);
19160 +AuRWLockFuncs(parent3, PARENT3);
19161 +AuRWLockFuncs(new_child, NEW_CHILD);
19163 +#undef AuReadLockFunc
19164 +#undef AuWriteLockFunc
19165 +#undef AuRWLockFuncs
19167 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19168 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19169 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19171 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19172 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19173 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19175 +/* ---------------------------------------------------------------------- */
19177 +static inline void au_icntnr_init(struct au_icntnr *c)
19179 +#ifdef CONFIG_AUFS_DEBUG
19180 + c->vfs_inode.i_mode = 0;
19184 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19186 + unsigned int gen;
19187 + struct au_iinfo *iinfo;
19188 + struct au_iigen *iigen;
19190 + iinfo = au_ii(inode);
19191 + iigen = &iinfo->ii_generation;
19192 + spin_lock(&iigen->ig_spin);
19194 + *igflags = iigen->ig_flags;
19195 + gen = iigen->ig_generation;
19196 + spin_unlock(&iigen->ig_spin);
19201 +/* tiny test for inode number */
19202 +/* tmpfs generation is too rough */
19203 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19205 + struct au_iinfo *iinfo;
19207 + iinfo = au_ii(inode);
19208 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19209 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19210 + && iinfo->ii_higen == h_inode->i_generation);
19213 +static inline void au_iigen_dec(struct inode *inode)
19215 + struct au_iinfo *iinfo;
19216 + struct au_iigen *iigen;
19218 + iinfo = au_ii(inode);
19219 + iigen = &iinfo->ii_generation;
19220 + spin_lock(&iigen->ig_spin);
19221 + iigen->ig_generation--;
19222 + spin_unlock(&iigen->ig_spin);
19225 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19230 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19236 +/* ---------------------------------------------------------------------- */
19238 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19239 + aufs_bindex_t bindex)
19241 + return iinfo->ii_hinode + bindex;
19244 +static inline int au_is_bad_inode(struct inode *inode)
19246 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19249 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19250 + aufs_bindex_t bindex)
19252 + IiMustAnyLock(inode);
19253 + return au_hinode(au_ii(inode), bindex)->hi_id;
19256 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19258 + IiMustAnyLock(inode);
19259 + return au_ii(inode)->ii_btop;
19262 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19264 + IiMustAnyLock(inode);
19265 + return au_ii(inode)->ii_bbot;
19268 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19270 + IiMustAnyLock(inode);
19271 + return au_ii(inode)->ii_vdir;
19274 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19276 + IiMustAnyLock(inode);
19277 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19280 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19282 + IiMustWriteLock(inode);
19283 + au_ii(inode)->ii_btop = bindex;
19286 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19288 + IiMustWriteLock(inode);
19289 + au_ii(inode)->ii_bbot = bindex;
19292 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19294 + IiMustWriteLock(inode);
19295 + au_ii(inode)->ii_vdir = vdir;
19298 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19300 + IiMustAnyLock(inode);
19301 + return au_hinode(au_ii(inode), bindex);
19304 +/* ---------------------------------------------------------------------- */
19306 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19309 + return pin->parent;
19313 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19315 + if (pin && pin->hdir)
19316 + return pin->hdir->hi_inode;
19320 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19323 + return pin->hdir;
19327 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19330 + pin->dentry = dentry;
19333 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19334 + unsigned char lflag)
19338 + au_fset_pin(pin->flags, DI_LOCKED);
19340 + au_fclr_pin(pin->flags, DI_LOCKED);
19344 +#if 0 /* reserved */
19345 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19348 + dput(pin->parent);
19349 + pin->parent = dget(parent);
19354 +/* ---------------------------------------------------------------------- */
19357 +#ifdef CONFIG_AUFS_HNOTIFY
19358 +struct au_hnotify_op {
19359 + void (*ctl)(struct au_hinode *hinode, int do_set);
19360 + int (*alloc)(struct au_hinode *hinode);
19363 + * if it returns true, the the caller should free hinode->hi_notify,
19364 + * otherwise ->free() frees it.
19366 + int (*free)(struct au_hinode *hinode,
19367 + struct au_hnotify *hn) __must_check;
19369 + void (*fin)(void);
19370 + int (*init)(void);
19372 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19373 + void (*fin_br)(struct au_branch *br);
19374 + int (*init_br)(struct au_branch *br, int perm);
19378 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19379 +void au_hn_free(struct au_hinode *hinode);
19380 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19381 +void au_hn_reset(struct inode *inode, unsigned int flags);
19382 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19383 + struct qstr *h_child_qstr, struct inode *h_child_inode);
19384 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19385 +int au_hnotify_init_br(struct au_branch *br, int perm);
19386 +void au_hnotify_fin_br(struct au_branch *br);
19387 +int __init au_hnotify_init(void);
19388 +void au_hnotify_fin(void);
19391 +extern const struct au_hnotify_op au_hnotify_op;
19394 +void au_hn_init(struct au_hinode *hinode)
19396 + hinode->hi_notify = NULL;
19399 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19401 + return hinode->hi_notify;
19405 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19406 + struct au_hinode *hinode __maybe_unused,
19407 + struct inode *inode __maybe_unused)
19408 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19409 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19410 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19411 + int do_set __maybe_unused)
19412 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19413 + unsigned int flags __maybe_unused)
19414 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19415 + struct au_branch *br __maybe_unused,
19416 + int perm __maybe_unused)
19417 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19418 + int perm __maybe_unused)
19419 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19420 +AuStubInt0(__init au_hnotify_init, void)
19421 +AuStubVoid(au_hnotify_fin, void)
19422 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19423 +#endif /* CONFIG_AUFS_HNOTIFY */
19425 +static inline void au_hn_suspend(struct au_hinode *hdir)
19427 + au_hn_ctl(hdir, /*do_set*/0);
19430 +static inline void au_hn_resume(struct au_hinode *hdir)
19432 + au_hn_ctl(hdir, /*do_set*/1);
19435 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19437 + inode_lock(hdir->hi_inode);
19438 + au_hn_suspend(hdir);
19441 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19442 + unsigned int sc __maybe_unused)
19444 + inode_lock_nested(hdir->hi_inode, sc);
19445 + au_hn_suspend(hdir);
19448 +#if 0 /* unused */
19449 +#include "vfsub.h"
19450 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19453 + inode_lock_shared_nested(hdir->hi_inode, sc);
19454 + au_hn_suspend(hdir);
19458 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19460 + au_hn_resume(hdir);
19461 + inode_unlock(hdir->hi_inode);
19464 +#endif /* __KERNEL__ */
19465 +#endif /* __AUFS_INODE_H__ */
19466 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19467 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19468 +++ linux/fs/aufs/ioctl.c 2021-02-22 23:30:37.702680911 +0100
19470 +// SPDX-License-Identifier: GPL-2.0
19472 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19474 + * This program, aufs is free software; you can redistribute it and/or modify
19475 + * it under the terms of the GNU General Public License as published by
19476 + * the Free Software Foundation; either version 2 of the License, or
19477 + * (at your option) any later version.
19479 + * This program is distributed in the hope that it will be useful,
19480 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19481 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19482 + * GNU General Public License for more details.
19484 + * You should have received a copy of the GNU General Public License
19485 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19490 + * plink-management and readdir in userspace.
19491 + * assist the pathconf(3) wrapper library.
19493 + * File-based Hierarchical Storage Management.
19496 +#include <linux/compat.h>
19497 +#include <linux/file.h>
19500 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19503 + aufs_bindex_t wbi, bindex, bbot;
19504 + struct file *h_file;
19505 + struct super_block *sb;
19506 + struct dentry *root;
19507 + struct au_branch *br;
19508 + struct aufs_wbr_fd wbrfd = {
19509 + .oflags = au_dir_roflags,
19512 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19513 + | O_NOATIME | O_CLOEXEC;
19515 + AuDebugOn(wbrfd.oflags & ~valid);
19518 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19519 + if (unlikely(err)) {
19525 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19526 + wbrfd.oflags |= au_dir_roflags;
19527 + AuDbg("0%o\n", wbrfd.oflags);
19528 + if (unlikely(wbrfd.oflags & ~valid))
19532 + fd = get_unused_fd_flags(0);
19534 + if (unlikely(fd < 0))
19537 + h_file = ERR_PTR(-EINVAL);
19540 + sb = path->dentry->d_sb;
19541 + root = sb->s_root;
19542 + aufs_read_lock(root, AuLock_IR);
19543 + bbot = au_sbbot(sb);
19544 + if (wbrfd.brid >= 0) {
19545 + wbi = au_br_index(sb, wbrfd.brid);
19546 + if (unlikely(wbi < 0 || wbi > bbot))
19550 + h_file = ERR_PTR(-ENOENT);
19551 + br = au_sbr(sb, wbi);
19552 + if (!au_br_writable(br->br_perm)) {
19556 + bindex = wbi + 1;
19558 + for (; bindex <= bbot; bindex++) {
19559 + br = au_sbr(sb, bindex);
19560 + if (au_br_writable(br->br_perm)) {
19562 + br = au_sbr(sb, wbi);
19567 + AuDbg("wbi %d\n", wbi);
19569 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19573 + aufs_read_unlock(root, AuLock_IR);
19574 + err = PTR_ERR(h_file);
19575 + if (IS_ERR(h_file))
19578 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19579 + fd_install(fd, h_file);
19581 + goto out; /* success */
19584 + put_unused_fd(fd);
19590 +/* ---------------------------------------------------------------------- */
19592 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19595 + struct dentry *dentry;
19598 + case AUFS_CTL_RDU:
19599 + case AUFS_CTL_RDU_INO:
19600 + err = au_rdu_ioctl(file, cmd, arg);
19603 + case AUFS_CTL_WBR_FD:
19604 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19607 + case AUFS_CTL_IBUSY:
19608 + err = au_ibusy_ioctl(file, arg);
19611 + case AUFS_CTL_BRINFO:
19612 + err = au_brinfo_ioctl(file, arg);
19615 + case AUFS_CTL_FHSM_FD:
19616 + dentry = file->f_path.dentry;
19617 + if (IS_ROOT(dentry))
19618 + err = au_fhsm_fd(dentry->d_sb, arg);
19624 + /* do not call the lower */
19625 + AuDbg("0x%x\n", cmd);
19633 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19638 + case AUFS_CTL_MVDOWN:
19639 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19642 + case AUFS_CTL_WBR_FD:
19643 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19647 + /* do not call the lower */
19648 + AuDbg("0x%x\n", cmd);
19656 +#ifdef CONFIG_COMPAT
19657 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19658 + unsigned long arg)
19663 + case AUFS_CTL_RDU:
19664 + case AUFS_CTL_RDU_INO:
19665 + err = au_rdu_compat_ioctl(file, cmd, arg);
19668 + case AUFS_CTL_IBUSY:
19669 + err = au_ibusy_compat_ioctl(file, arg);
19672 + case AUFS_CTL_BRINFO:
19673 + err = au_brinfo_compat_ioctl(file, arg);
19677 + err = aufs_ioctl_dir(file, cmd, arg);
19684 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19685 + unsigned long arg)
19687 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19690 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19691 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19692 +++ linux/fs/aufs/i_op_add.c 2021-02-22 23:30:37.702680911 +0100
19694 +// SPDX-License-Identifier: GPL-2.0
19696 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19698 + * This program, aufs is free software; you can redistribute it and/or modify
19699 + * it under the terms of the GNU General Public License as published by
19700 + * the Free Software Foundation; either version 2 of the License, or
19701 + * (at your option) any later version.
19703 + * This program is distributed in the hope that it will be useful,
19704 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19705 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19706 + * GNU General Public License for more details.
19708 + * You should have received a copy of the GNU General Public License
19709 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19713 + * inode operations (add entry)
19716 +#include <linux/iversion.h>
19720 + * final procedure of adding a new entry, except link(2).
19721 + * remove whiteout, instantiate, copyup the parent dir's times and size
19722 + * and update version.
19723 + * if it failed, re-create the removed whiteout.
19725 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19726 + struct dentry *wh_dentry, struct dentry *dentry)
19729 + aufs_bindex_t bwh;
19730 + struct path h_path;
19731 + struct super_block *sb;
19732 + struct inode *inode, *h_dir;
19733 + struct dentry *wh;
19738 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19739 + IMustLock(h_dir);
19740 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19741 + bwh = au_dbwh(dentry);
19742 + h_path.dentry = wh_dentry;
19743 + h_path.mnt = au_sbr_mnt(sb, bindex);
19744 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19746 + if (unlikely(err))
19750 + inode = au_new_inode(dentry, /*must_new*/1);
19751 + if (!IS_ERR(inode)) {
19752 + d_instantiate(dentry, inode);
19753 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19755 + au_dir_ts(dir, bindex);
19756 + inode_inc_iversion(dir);
19757 + au_fhsm_wrote(sb, bindex, /*force*/0);
19758 + return 0; /* success */
19761 + err = PTR_ERR(inode);
19766 + /* dir inode is locked */
19767 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19768 + rerr = PTR_ERR(wh);
19769 + if (IS_ERR(wh)) {
19770 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19771 + dentry, err, rerr);
19780 +static int au_d_may_add(struct dentry *dentry)
19785 + if (unlikely(d_unhashed(dentry)))
19787 + if (unlikely(d_really_is_positive(dentry)))
19793 + * simple tests for the adding inode operations.
19794 + * following the checks in vfs, plus the parent-child relationship.
19796 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19797 + struct dentry *h_parent, int isdir)
19801 + struct dentry *h_dentry;
19802 + struct inode *h_inode;
19804 + err = -ENAMETOOLONG;
19805 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19808 + h_dentry = au_h_dptr(dentry, bindex);
19809 + if (d_really_is_negative(dentry)) {
19811 + if (unlikely(d_is_positive(h_dentry)))
19814 + /* rename(2) case */
19816 + if (unlikely(d_is_negative(h_dentry)))
19818 + h_inode = d_inode(h_dentry);
19819 + if (unlikely(!h_inode->i_nlink))
19822 + h_mode = h_inode->i_mode;
19825 + if (unlikely(S_ISDIR(h_mode)))
19827 + } else if (unlikely(!S_ISDIR(h_mode))) {
19834 + /* expected parent dir is locked */
19835 + if (unlikely(h_parent != h_dentry->d_parent))
19844 + * initial procedure of adding a new entry.
19845 + * prepare writable branch and the parent dir, lock it,
19846 + * and lookup whiteout for the new entry.
19848 +static struct dentry*
19849 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19850 + struct dentry *src_dentry, struct au_pin *pin,
19851 + struct au_wr_dir_args *wr_dir_args)
19853 + struct dentry *wh_dentry, *h_parent;
19854 + struct super_block *sb;
19855 + struct au_branch *br;
19857 + unsigned int udba;
19858 + aufs_bindex_t bcpup;
19860 + AuDbg("%pd\n", dentry);
19862 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19864 + wh_dentry = ERR_PTR(err);
19865 + if (unlikely(err < 0))
19868 + sb = dentry->d_sb;
19869 + udba = au_opt_udba(sb);
19870 + err = au_pin(pin, dentry, bcpup, udba,
19871 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19872 + wh_dentry = ERR_PTR(err);
19873 + if (unlikely(err))
19876 + h_parent = au_pinned_h_parent(pin);
19877 + if (udba != AuOpt_UDBA_NONE
19878 + && au_dbtop(dentry) == bcpup)
19879 + err = au_may_add(dentry, bcpup, h_parent,
19880 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19881 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19882 + err = -ENAMETOOLONG;
19883 + wh_dentry = ERR_PTR(err);
19884 + if (unlikely(err))
19887 + br = au_sbr(sb, bcpup);
19889 + struct path tmp = {
19890 + .dentry = h_parent,
19891 + .mnt = au_br_mnt(br)
19893 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19896 + wh_dentry = NULL;
19897 + if (bcpup != au_dbwh(dentry))
19898 + goto out; /* success */
19901 + * ENAMETOOLONG here means that if we allowed create such name, then it
19902 + * would not be able to removed in the future. So we don't allow such
19903 + * name here and we don't handle ENAMETOOLONG differently here.
19905 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19908 + if (IS_ERR(wh_dentry))
19911 + return wh_dentry;
19914 +/* ---------------------------------------------------------------------- */
19916 +enum { Mknod, Symlink, Creat };
19917 +struct simple_arg {
19924 + struct vfsub_aopen_args *aopen;
19927 + const char *symname;
19936 +static int add_simple(struct inode *dir, struct dentry *dentry,
19937 + struct simple_arg *arg)
19940 + aufs_bindex_t btop;
19941 + unsigned char created;
19942 + const unsigned char try_aopen
19943 + = (arg->type == Creat && arg->u.c.try_aopen);
19944 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19945 + struct dentry *wh_dentry, *parent;
19946 + struct inode *h_dir;
19947 + struct super_block *sb;
19948 + struct au_branch *br;
19949 + /* to reduce stack size */
19951 + struct au_dtime dt;
19952 + struct au_pin pin;
19953 + struct path h_path;
19954 + struct au_wr_dir_args wr_dir_args;
19957 + AuDbg("%pd\n", dentry);
19961 + a = kmalloc(sizeof(*a), GFP_NOFS);
19962 + if (unlikely(!a))
19964 + a->wr_dir_args.force_btgt = -1;
19965 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19967 + parent = dentry->d_parent; /* dir inode is locked */
19968 + if (!try_aopen) {
19969 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19970 + if (unlikely(err))
19973 + err = au_d_may_add(dentry);
19974 + if (unlikely(err))
19977 + di_write_lock_parent(parent);
19978 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19979 + &a->pin, &a->wr_dir_args);
19980 + err = PTR_ERR(wh_dentry);
19981 + if (IS_ERR(wh_dentry))
19984 + btop = au_dbtop(dentry);
19985 + sb = dentry->d_sb;
19986 + br = au_sbr(sb, btop);
19987 + a->h_path.dentry = au_h_dptr(dentry, btop);
19988 + a->h_path.mnt = au_br_mnt(br);
19989 + h_dir = au_pinned_h_dir(&a->pin);
19990 + switch (arg->type) {
19992 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19993 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19994 + arg->u.c.want_excl);
19996 + if (!err && try_aopen)
19997 + aopen->file->f_mode |= FMODE_CREATED;
20000 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
20001 + AuDbg("err %d\n", err);
20002 + AuDbgFile(aopen->file);
20003 + created = err >= 0
20004 + && !!(aopen->file->f_mode & FMODE_CREATED);
20008 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
20012 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
20019 + if (unlikely(err < 0))
20022 + err = epilog(dir, btop, wh_dentry, dentry);
20024 + goto out_unpin; /* success */
20027 + if (created /* && d_is_positive(a->h_path.dentry) */) {
20028 + /* no delegation since it is just created */
20029 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
20032 + AuIOErr("%pd revert failure(%d, %d)\n",
20033 + dentry, err, rerr);
20036 + au_dtime_revert(&a->dt);
20038 + if (try_aopen && h_dir->i_op->atomic_open
20039 + && (aopen->file->f_mode & FMODE_OPENED))
20040 + /* aopen->file is still opened */
20041 + au_lcnt_dec(&aopen->br->br_nfiles);
20044 + au_unpin(&a->pin);
20048 + di_write_unlock(parent);
20050 + if (unlikely(err)) {
20051 + au_update_dbtop(dentry);
20055 + aufs_read_unlock(dentry, AuLock_DW);
20062 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20065 + struct simple_arg arg = {
20072 + return add_simple(dir, dentry, &arg);
20075 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
20077 + struct simple_arg arg = {
20079 + .u.s.symname = symname
20081 + return add_simple(dir, dentry, &arg);
20084 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20087 + struct simple_arg arg = {
20091 + .want_excl = want_excl
20094 + return add_simple(dir, dentry, &arg);
20097 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20098 + struct vfsub_aopen_args *aopen_args)
20100 + struct simple_arg arg = {
20103 + .mode = aopen_args->create_mode,
20104 + .want_excl = aopen_args->open_flag & O_EXCL,
20105 + .try_aopen = true,
20106 + .aopen = aopen_args
20109 + return add_simple(dir, dentry, &arg);
20112 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
20115 + aufs_bindex_t bindex;
20116 + struct super_block *sb;
20117 + struct dentry *parent, *h_parent, *h_dentry;
20118 + struct inode *h_dir, *inode;
20119 + struct vfsmount *h_mnt;
20120 + struct au_wr_dir_args wr_dir_args = {
20121 + .force_btgt = -1,
20122 + .flags = AuWrDir_TMPFILE
20125 + /* copy-up may happen */
20129 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20130 + if (unlikely(err))
20133 + err = au_di_init(dentry);
20134 + if (unlikely(err))
20138 + parent = d_find_any_alias(dir);
20139 + AuDebugOn(!parent);
20140 + di_write_lock_parent(parent);
20141 + if (unlikely(d_inode(parent) != dir))
20144 + err = au_digen_test(parent, au_sigen(sb));
20145 + if (unlikely(err))
20148 + bindex = au_dbtop(parent);
20149 + au_set_dbtop(dentry, bindex);
20150 + au_set_dbbot(dentry, bindex);
20151 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
20153 + if (unlikely(err < 0))
20156 + err = -EOPNOTSUPP;
20157 + h_dir = au_h_iptr(dir, bindex);
20158 + if (unlikely(!h_dir->i_op->tmpfile))
20161 + h_mnt = au_sbr_mnt(sb, bindex);
20162 + err = vfsub_mnt_want_write(h_mnt);
20163 + if (unlikely(err))
20166 + h_parent = au_h_dptr(parent, bindex);
20167 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
20168 + if (IS_ERR(h_dentry)) {
20169 + err = PTR_ERR(h_dentry);
20173 + au_set_dbtop(dentry, bindex);
20174 + au_set_dbbot(dentry, bindex);
20175 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20176 + inode = au_new_inode(dentry, /*must_new*/1);
20177 + if (IS_ERR(inode)) {
20178 + err = PTR_ERR(inode);
20179 + au_set_h_dptr(dentry, bindex, NULL);
20180 + au_set_dbtop(dentry, -1);
20181 + au_set_dbbot(dentry, -1);
20183 + if (!inode->i_nlink)
20184 + set_nlink(inode, 1);
20185 + d_tmpfile(dentry, inode);
20186 + au_di(dentry)->di_tmpfile = 1;
20188 + /* update without i_mutex */
20189 + if (au_ibtop(dir) == au_dbtop(dentry))
20190 + au_cpup_attr_timesizes(dir);
20195 + vfsub_mnt_drop_write(h_mnt);
20197 + di_write_unlock(parent);
20199 + di_write_unlock(dentry);
20200 + if (unlikely(err)) {
20201 + au_di_fin(dentry);
20202 + dentry->d_fsdata = NULL;
20205 + si_read_unlock(sb);
20207 + inode_unlock(dir);
20211 +/* ---------------------------------------------------------------------- */
20213 +struct au_link_args {
20214 + aufs_bindex_t bdst, bsrc;
20215 + struct au_pin pin;
20216 + struct path h_path;
20217 + struct dentry *src_parent, *parent;
20220 +static int au_cpup_before_link(struct dentry *src_dentry,
20221 + struct au_link_args *a)
20224 + struct dentry *h_src_dentry;
20225 + struct au_cp_generic cpg = {
20226 + .dentry = src_dentry,
20231 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20234 + di_read_lock_parent(a->src_parent, AuLock_IR);
20235 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20236 + if (unlikely(err))
20239 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20240 + err = au_pin(&a->pin, src_dentry, a->bdst,
20241 + au_opt_udba(src_dentry->d_sb),
20242 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20243 + if (unlikely(err))
20246 + err = au_sio_cpup_simple(&cpg);
20247 + au_unpin(&a->pin);
20250 + di_read_unlock(a->src_parent, AuLock_IR);
20254 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20255 + struct au_link_args *a)
20258 + unsigned char plink;
20259 + aufs_bindex_t bbot;
20260 + struct dentry *h_src_dentry;
20261 + struct inode *h_inode, *inode, *delegated;
20262 + struct super_block *sb;
20263 + struct file *h_file;
20267 + sb = src_dentry->d_sb;
20268 + inode = d_inode(src_dentry);
20269 + if (au_ibtop(inode) <= a->bdst)
20270 + h_inode = au_h_iptr(inode, a->bdst);
20271 + if (!h_inode || !h_inode->i_nlink) {
20272 + /* copyup src_dentry as the name of dentry. */
20273 + bbot = au_dbbot(dentry);
20274 + if (bbot < a->bsrc)
20275 + au_set_dbbot(dentry, a->bsrc);
20276 + au_set_h_dptr(dentry, a->bsrc,
20277 + dget(au_h_dptr(src_dentry, a->bsrc)));
20278 + dget(a->h_path.dentry);
20279 + au_set_h_dptr(dentry, a->bdst, NULL);
20280 + AuDbg("temporary d_inode...\n");
20281 + spin_lock(&dentry->d_lock);
20282 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20283 + spin_unlock(&dentry->d_lock);
20284 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20285 + if (IS_ERR(h_file))
20286 + err = PTR_ERR(h_file);
20288 + struct au_cp_generic cpg = {
20289 + .dentry = dentry,
20294 + .flags = AuCpup_KEEPLINO
20296 + err = au_sio_cpup_simple(&cpg);
20297 + au_h_open_post(dentry, a->bsrc, h_file);
20299 + dput(a->h_path.dentry);
20300 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20302 + au_set_h_dptr(dentry, a->bdst,
20303 + a->h_path.dentry);
20305 + spin_lock(&dentry->d_lock);
20306 + dentry->d_inode = NULL; /* restore */
20307 + spin_unlock(&dentry->d_lock);
20308 + AuDbg("temporary d_inode...done\n");
20309 + au_set_h_dptr(dentry, a->bsrc, NULL);
20310 + au_set_dbbot(dentry, bbot);
20312 + /* the inode of src_dentry already exists on a.bdst branch */
20313 + h_src_dentry = d_find_alias(h_inode);
20314 + if (!h_src_dentry && au_plink_test(inode)) {
20316 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20317 + err = PTR_ERR(h_src_dentry);
20318 + if (IS_ERR(h_src_dentry))
20321 + if (unlikely(d_is_negative(h_src_dentry))) {
20322 + dput(h_src_dentry);
20323 + h_src_dentry = NULL;
20327 + if (h_src_dentry) {
20328 + delegated = NULL;
20329 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20330 + &a->h_path, &delegated);
20331 + if (unlikely(err == -EWOULDBLOCK)) {
20332 + pr_warn("cannot retry for NFSv4 delegation"
20333 + " for an internal link\n");
20336 + dput(h_src_dentry);
20338 + AuIOErr("no dentry found for hi%lu on b%d\n",
20339 + h_inode->i_ino, a->bdst);
20344 + if (!err && !plink)
20345 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20352 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20353 + struct dentry *dentry)
20356 + struct au_dtime dt;
20357 + struct au_link_args *a;
20358 + struct dentry *wh_dentry, *h_src_dentry;
20359 + struct inode *inode, *delegated;
20360 + struct super_block *sb;
20361 + struct au_wr_dir_args wr_dir_args = {
20362 + /* .force_btgt = -1, */
20363 + .flags = AuWrDir_ADD_ENTRY
20367 + inode = d_inode(src_dentry);
20368 + IMustLock(inode);
20371 + a = kzalloc(sizeof(*a), GFP_NOFS);
20372 + if (unlikely(!a))
20375 + a->parent = dentry->d_parent; /* dir inode is locked */
20376 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20377 + AuLock_NOPLM | AuLock_GEN);
20378 + if (unlikely(err))
20380 + err = au_d_linkable(src_dentry);
20381 + if (unlikely(err))
20383 + err = au_d_may_add(dentry);
20384 + if (unlikely(err))
20387 + a->src_parent = dget_parent(src_dentry);
20388 + wr_dir_args.force_btgt = au_ibtop(inode);
20390 + di_write_lock_parent(a->parent);
20391 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20392 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20394 + err = PTR_ERR(wh_dentry);
20395 + if (IS_ERR(wh_dentry))
20399 + sb = dentry->d_sb;
20400 + a->bdst = au_dbtop(dentry);
20401 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20402 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20403 + a->bsrc = au_ibtop(inode);
20404 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20405 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20406 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20407 + if (!h_src_dentry) {
20408 + a->bsrc = au_dbtop(src_dentry);
20409 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20410 + AuDebugOn(!h_src_dentry);
20411 + } else if (IS_ERR(h_src_dentry)) {
20412 + err = PTR_ERR(h_src_dentry);
20417 + * aufs doesn't touch the credential so
20418 + * security_dentry_create_files_as() is unnecessary.
20420 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20421 + if (a->bdst < a->bsrc
20422 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20423 + err = au_cpup_or_link(src_dentry, dentry, a);
20425 + delegated = NULL;
20426 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20427 + &a->h_path, &delegated);
20428 + if (unlikely(err == -EWOULDBLOCK)) {
20429 + pr_warn("cannot retry for NFSv4 delegation"
20430 + " for an internal link\n");
20434 + dput(h_src_dentry);
20437 + * copyup src_dentry to the branch we process,
20438 + * and then link(2) to it.
20440 + dput(h_src_dentry);
20441 + if (a->bdst < a->bsrc
20442 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20443 + au_unpin(&a->pin);
20444 + di_write_unlock(a->parent);
20445 + err = au_cpup_before_link(src_dentry, a);
20446 + di_write_lock_parent(a->parent);
20448 + err = au_pin(&a->pin, dentry, a->bdst,
20450 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20451 + if (unlikely(err))
20455 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20457 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20458 + delegated = NULL;
20459 + err = vfsub_link(h_src_dentry,
20460 + au_pinned_h_dir(&a->pin),
20461 + &a->h_path, &delegated);
20462 + if (unlikely(err == -EWOULDBLOCK)) {
20463 + pr_warn("cannot retry"
20464 + " for NFSv4 delegation"
20465 + " for an internal link\n");
20471 + if (unlikely(err))
20475 + a->h_path.dentry = wh_dentry;
20476 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20478 + if (unlikely(err))
20482 + au_dir_ts(dir, a->bdst);
20483 + inode_inc_iversion(dir);
20484 + inc_nlink(inode);
20485 + inode->i_ctime = dir->i_ctime;
20486 + d_instantiate(dentry, au_igrab(inode));
20487 + if (d_unhashed(a->h_path.dentry))
20488 + /* some filesystem calls d_drop() */
20490 + /* some filesystems consume an inode even hardlink */
20491 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20492 + goto out_unpin; /* success */
20495 + /* no delegation since it is just created */
20496 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20497 + /*delegated*/NULL, /*force*/0);
20498 + if (unlikely(rerr)) {
20499 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20502 + au_dtime_revert(&dt);
20504 + au_unpin(&a->pin);
20508 + di_write_unlock(a->parent);
20509 + dput(a->src_parent);
20511 + if (unlikely(err)) {
20512 + au_update_dbtop(dentry);
20515 + aufs_read_and_write_unlock2(dentry, src_dentry);
20523 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20526 + aufs_bindex_t bindex;
20527 + unsigned char diropq;
20528 + struct path h_path;
20529 + struct dentry *wh_dentry, *parent, *opq_dentry;
20530 + struct inode *h_inode;
20531 + struct super_block *sb;
20533 + struct au_pin pin;
20534 + struct au_dtime dt;
20535 + } *a; /* reduce the stack usage */
20536 + struct au_wr_dir_args wr_dir_args = {
20537 + .force_btgt = -1,
20538 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20544 + a = kmalloc(sizeof(*a), GFP_NOFS);
20545 + if (unlikely(!a))
20548 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20549 + if (unlikely(err))
20551 + err = au_d_may_add(dentry);
20552 + if (unlikely(err))
20555 + parent = dentry->d_parent; /* dir inode is locked */
20556 + di_write_lock_parent(parent);
20557 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20558 + &a->pin, &wr_dir_args);
20559 + err = PTR_ERR(wh_dentry);
20560 + if (IS_ERR(wh_dentry))
20563 + sb = dentry->d_sb;
20564 + bindex = au_dbtop(dentry);
20565 + h_path.dentry = au_h_dptr(dentry, bindex);
20566 + h_path.mnt = au_sbr_mnt(sb, bindex);
20567 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20568 + if (unlikely(err))
20571 + /* make the dir opaque */
20573 + h_inode = d_inode(h_path.dentry);
20575 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20576 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20577 + opq_dentry = au_diropq_create(dentry, bindex);
20578 + inode_unlock(h_inode);
20579 + err = PTR_ERR(opq_dentry);
20580 + if (IS_ERR(opq_dentry))
20582 + dput(opq_dentry);
20586 + err = epilog(dir, bindex, wh_dentry, dentry);
20589 + goto out_unpin; /* success */
20594 + AuLabel(revert opq);
20595 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20596 + rerr = au_diropq_remove(dentry, bindex);
20597 + inode_unlock(h_inode);
20599 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20600 + dentry, err, rerr);
20606 + AuLabel(revert dir);
20607 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20609 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20610 + dentry, err, rerr);
20613 + au_dtime_revert(&a->dt);
20615 + au_unpin(&a->pin);
20618 + di_write_unlock(parent);
20620 + if (unlikely(err)) {
20621 + au_update_dbtop(dentry);
20624 + aufs_read_unlock(dentry, AuLock_DW);
20630 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20631 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20632 +++ linux/fs/aufs/i_op.c 2021-02-22 23:30:37.702680911 +0100
20634 +// SPDX-License-Identifier: GPL-2.0
20636 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20638 + * This program, aufs is free software; you can redistribute it and/or modify
20639 + * it under the terms of the GNU General Public License as published by
20640 + * the Free Software Foundation; either version 2 of the License, or
20641 + * (at your option) any later version.
20643 + * This program is distributed in the hope that it will be useful,
20644 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20645 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20646 + * GNU General Public License for more details.
20648 + * You should have received a copy of the GNU General Public License
20649 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20653 + * inode operations (except add/del/rename)
20656 +#include <linux/device_cgroup.h>
20657 +#include <linux/fs_stack.h>
20658 +#include <linux/iversion.h>
20659 +#include <linux/namei.h>
20660 +#include <linux/security.h>
20663 +static int h_permission(struct inode *h_inode, int mask,
20664 + struct path *h_path, int brperm)
20667 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20670 + if (write_mask && IS_IMMUTABLE(h_inode))
20674 + if (((mask & MAY_EXEC)
20675 + && S_ISREG(h_inode->i_mode)
20676 + && (path_noexec(h_path)
20677 + || !(h_inode->i_mode & 0111))))
20681 + * - skip the lower fs test in the case of write to ro branch.
20682 + * - nfs dir permission write check is optimized, but a policy for
20683 + * link/rename requires a real check.
20684 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20685 + * in this case, generic_permission() returns -EOPNOTSUPP.
20687 + if ((write_mask && !au_br_writable(brperm))
20688 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20689 + && write_mask && !(mask & MAY_READ))
20690 + || !h_inode->i_op->permission) {
20691 + /* AuLabel(generic_permission); */
20692 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20693 + err = generic_permission(h_inode, mask);
20694 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20695 + err = h_inode->i_op->permission(h_inode, mask);
20698 + /* AuLabel(h_inode->permission); */
20699 + err = h_inode->i_op->permission(h_inode, mask);
20704 + err = devcgroup_inode_permission(h_inode, mask);
20706 + err = security_inode_permission(h_inode, mask);
20712 +static int aufs_permission(struct inode *inode, int mask)
20715 + aufs_bindex_t bindex, bbot;
20716 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20717 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20718 + struct inode *h_inode;
20719 + struct super_block *sb;
20720 + struct au_branch *br;
20722 + /* todo: support rcu-walk? */
20723 + if (mask & MAY_NOT_BLOCK)
20726 + sb = inode->i_sb;
20727 + si_read_lock(sb, AuLock_FLUSH);
20728 + ii_read_lock_child(inode);
20729 +#if 0 /* reserved for future use */
20731 + * This test may be rather 'too much' since the test is essentially done
20732 + * in the aufs_lookup(). Theoretically it is possible that the inode
20733 + * generation doesn't match to the superblock's here. But it isn't a
20734 + * big deal I suppose.
20736 + err = au_iigen_test(inode, au_sigen(sb));
20737 + if (unlikely(err))
20743 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20744 + err = au_busy_or_stale();
20745 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20746 + if (unlikely(!h_inode
20747 + || (h_inode->i_mode & S_IFMT)
20748 + != (inode->i_mode & S_IFMT)))
20752 + bindex = au_ibtop(inode);
20753 + br = au_sbr(sb, bindex);
20754 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20757 + && !special_file(h_inode->i_mode)) {
20758 + /* test whether the upper writable branch exists */
20760 + for (; bindex >= 0; bindex--)
20761 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20769 + /* non-write to dir */
20771 + bbot = au_ibbot(inode);
20772 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20773 + h_inode = au_h_iptr(inode, bindex);
20775 + err = au_busy_or_stale();
20776 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20779 + br = au_sbr(sb, bindex);
20780 + err = h_permission(h_inode, mask, &br->br_path,
20786 + ii_read_unlock(inode);
20787 + si_read_unlock(sb);
20791 +/* ---------------------------------------------------------------------- */
20793 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20794 + unsigned int flags)
20796 + struct dentry *ret, *parent;
20797 + struct inode *inode;
20798 + struct super_block *sb;
20799 + int err, npositive;
20803 + /* todo: support rcu-walk? */
20804 + ret = ERR_PTR(-ECHILD);
20805 + if (flags & LOOKUP_RCU)
20808 + ret = ERR_PTR(-ENAMETOOLONG);
20809 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20813 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20814 + ret = ERR_PTR(err);
20815 + if (unlikely(err))
20818 + err = au_di_init(dentry);
20819 + ret = ERR_PTR(err);
20820 + if (unlikely(err))
20824 + npositive = 0; /* suppress a warning */
20825 + parent = dentry->d_parent; /* dir inode is locked */
20826 + di_read_lock_parent(parent, AuLock_IR);
20827 + err = au_alive_dir(parent);
20829 + err = au_digen_test(parent, au_sigen(sb));
20831 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20832 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20833 + AuLkup_ALLOW_NEG);
20836 + di_read_unlock(parent, AuLock_IR);
20837 + ret = ERR_PTR(err);
20838 + if (unlikely(err < 0))
20842 + inode = au_new_inode(dentry, /*must_new*/0);
20843 + if (IS_ERR(inode)) {
20844 + ret = (void *)inode;
20851 + atomic_inc(&inode->i_count);
20852 + ret = d_splice_alias(inode, dentry);
20853 +#if 0 /* reserved for future use */
20854 + if (unlikely(d_need_lookup(dentry))) {
20855 + spin_lock(&dentry->d_lock);
20856 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20857 + spin_unlock(&dentry->d_lock);
20861 + if (!IS_ERR(ret)) {
20863 + if (ret && ret != dentry)
20864 + ii_write_unlock(inode);
20866 + ii_write_unlock(inode);
20873 + di_write_unlock(dentry);
20875 + si_read_unlock(sb);
20880 +/* ---------------------------------------------------------------------- */
20883 + * very dirty and complicated aufs ->atomic_open().
20884 + * aufs_atomic_open()
20885 + * + au_aopen_or_create()
20887 + * + vfsub_atomic_open()
20888 + * + branch fs ->atomic_open()
20889 + * may call the actual 'open' for h_file
20890 + * + inc br_nfiles only if opened
20891 + * + au_aopen_no_open() or au_aopen_do_open()
20893 + * au_aopen_do_open()
20894 + * + finish_open()
20895 + * + au_do_aopen()
20896 + * + au_do_open() the body of all 'open'
20897 + * + au_do_open_nondir()
20898 + * set the passed h_file
20900 + * au_aopen_no_open()
20901 + * + finish_no_open()
20904 +struct aopen_node {
20905 + struct hlist_bl_node hblist;
20906 + struct file *file, *h_file;
20909 +static int au_do_aopen(struct inode *inode, struct file *file)
20911 + struct hlist_bl_head *aopen;
20912 + struct hlist_bl_node *pos;
20913 + struct aopen_node *node;
20914 + struct au_do_open_args args = {
20916 + .open = au_do_open_nondir
20919 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20920 + hlist_bl_lock(aopen);
20921 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20922 + if (node->file == file) {
20923 + args.h_file = node->h_file;
20926 + hlist_bl_unlock(aopen);
20927 + /* AuDebugOn(!args.h_file); */
20929 + return au_do_open(file, &args);
20932 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20933 + struct aopen_node *aopen_node)
20936 + struct hlist_bl_head *aopen;
20939 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20940 + au_hbl_add(&aopen_node->hblist, aopen);
20941 + err = finish_open(file, dentry, au_do_aopen);
20942 + au_hbl_del(&aopen_node->hblist, aopen);
20943 + /* AuDbgFile(file); */
20944 + AuDbg("%pd%s%s\n", dentry,
20945 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20946 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20952 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20958 + err = finish_no_open(file, dentry);
20964 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20965 + struct file *file, unsigned int open_flag,
20966 + umode_t create_mode)
20968 + int err, did_open;
20969 + unsigned int lkup_flags;
20970 + aufs_bindex_t bindex;
20971 + struct super_block *sb;
20972 + struct dentry *parent, *d;
20973 + struct vfsub_aopen_args args = {
20974 + .open_flag = open_flag,
20975 + .create_mode = create_mode
20977 + struct aopen_node aopen_node = {
20982 + AuDbg("open_flag 0%o\n", open_flag);
20983 + AuDbgDentry(dentry);
20986 + if (!au_di(dentry)) {
20987 + lkup_flags = LOOKUP_OPEN;
20988 + if (open_flag & O_CREAT)
20989 + lkup_flags |= LOOKUP_CREATE;
20990 + d = aufs_lookup(dir, dentry, lkup_flags);
20992 + err = PTR_ERR(d);
20997 + * obsoleted dentry found.
20998 + * another error will be returned later.
21004 + AuDbgDentry(dentry);
21007 + if (d_is_positive(dentry)
21008 + || d_unhashed(dentry)
21009 + || d_unlinked(dentry)
21010 + || !(open_flag & O_CREAT)) {
21011 + err = au_aopen_no_open(file, dentry);
21012 + goto out; /* success */
21015 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
21016 + if (unlikely(err))
21019 + sb = dentry->d_sb;
21020 + parent = dentry->d_parent; /* dir is locked */
21021 + di_write_lock_parent(parent);
21022 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
21023 + if (unlikely(err < 0))
21026 + AuDbgDentry(dentry);
21027 + if (d_is_positive(dentry)) {
21028 + err = au_aopen_no_open(file, dentry);
21029 + goto out_parent; /* success */
21032 + args.file = alloc_empty_file(file->f_flags, current_cred());
21033 + err = PTR_ERR(args.file);
21034 + if (IS_ERR(args.file))
21037 + bindex = au_dbtop(dentry);
21038 + err = au_aopen_or_create(dir, dentry, &args);
21040 + AuDbgFile(args.file);
21041 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
21042 + did_open = !!(args.file->f_mode & FMODE_OPENED);
21045 + args.file = NULL;
21047 + di_write_unlock(parent);
21048 + di_write_unlock(dentry);
21049 + if (unlikely(err < 0)) {
21056 + err = au_aopen_no_open(file, dentry);
21058 + aopen_node.h_file = args.file;
21059 + err = au_aopen_do_open(file, dentry, &aopen_node);
21061 + if (unlikely(err < 0)) {
21065 + au_lcnt_dec(&args.br->br_nfiles);
21067 + goto out_sb; /* success */
21070 + di_write_unlock(parent);
21071 + di_write_unlock(dentry);
21073 + si_read_unlock(sb);
21081 +/* ---------------------------------------------------------------------- */
21083 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
21084 + const unsigned char add_entry, aufs_bindex_t bcpup,
21085 + aufs_bindex_t btop)
21088 + struct dentry *h_parent;
21089 + struct inode *h_dir;
21092 + IMustLock(d_inode(parent));
21094 + di_write_lock_parent(parent);
21097 + if (!au_h_dptr(parent, bcpup)) {
21098 + if (btop > bcpup)
21099 + err = au_cpup_dirs(dentry, bcpup);
21100 + else if (btop < bcpup)
21101 + err = au_cpdown_dirs(dentry, bcpup);
21105 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
21106 + h_parent = au_h_dptr(parent, bcpup);
21107 + h_dir = d_inode(h_parent);
21108 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
21109 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
21110 + /* todo: no unlock here */
21111 + inode_unlock_shared(h_dir);
21113 + AuDbg("bcpup %d\n", bcpup);
21115 + if (d_really_is_negative(dentry))
21116 + au_set_h_dptr(dentry, btop, NULL);
21117 + au_update_dbrange(dentry, /*do_put_zero*/0);
21122 + di_write_unlock(parent);
21124 + err = bcpup; /* success */
21131 + * decide the branch and the parent dir where we will create a new entry.
21132 + * returns new bindex or an error.
21133 + * copyup the parent dir if needed.
21135 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
21136 + struct au_wr_dir_args *args)
21139 + unsigned int flags;
21140 + aufs_bindex_t bcpup, btop, src_btop;
21141 + const unsigned char add_entry
21142 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
21143 + | au_ftest_wrdir(args->flags, TMPFILE);
21144 + struct super_block *sb;
21145 + struct dentry *parent;
21146 + struct au_sbinfo *sbinfo;
21148 + sb = dentry->d_sb;
21149 + sbinfo = au_sbi(sb);
21150 + parent = dget_parent(dentry);
21151 + btop = au_dbtop(dentry);
21153 + if (args->force_btgt < 0) {
21154 + if (src_dentry) {
21155 + src_btop = au_dbtop(src_dentry);
21156 + if (src_btop < btop)
21157 + bcpup = src_btop;
21158 + } else if (add_entry) {
21160 + if (au_ftest_wrdir(args->flags, ISDIR))
21161 + au_fset_wbr(flags, DIR);
21162 + err = AuWbrCreate(sbinfo, dentry, flags);
21166 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21168 + err = AuWbrCopyup(sbinfo, dentry);
21170 + if (!IS_ROOT(dentry)) {
21171 + di_read_lock_parent(parent, !AuLock_IR);
21172 + err = AuWbrCopyup(sbinfo, dentry);
21173 + di_read_unlock(parent, !AuLock_IR);
21175 + err = AuWbrCopyup(sbinfo, dentry);
21178 + if (unlikely(err < 0))
21182 + bcpup = args->force_btgt;
21183 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21186 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21188 + if (bcpup == btop)
21189 + goto out; /* success */
21191 + /* copyup the new parent into the branch we process */
21192 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21194 + if (d_really_is_negative(dentry)) {
21195 + au_set_h_dptr(dentry, btop, NULL);
21196 + au_set_dbtop(dentry, bcpup);
21197 + au_set_dbbot(dentry, bcpup);
21199 + AuDebugOn(add_entry
21200 + && !au_ftest_wrdir(args->flags, TMPFILE)
21201 + && !au_h_dptr(dentry, bcpup));
21209 +/* ---------------------------------------------------------------------- */
21211 +void au_pin_hdir_unlock(struct au_pin *p)
21214 + au_hn_inode_unlock(p->hdir);
21217 +int au_pin_hdir_lock(struct au_pin *p)
21225 + /* even if an error happens later, keep this lock */
21226 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21229 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21234 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21235 + p->h_parent, p->br);
21241 +int au_pin_hdir_relock(struct au_pin *p)
21244 + struct inode *h_i;
21245 + struct dentry *h_d[] = {
21250 + err = au_pin_hdir_lock(p);
21251 + if (unlikely(err))
21254 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21257 + if (d_is_positive(h_d[i])) {
21258 + h_i = d_inode(h_d[i]);
21259 + err = !h_i->i_nlink;
21267 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21269 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) \
21270 + && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
21271 + p->hdir->hi_inode->i_rwsem.owner = task;
21275 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21278 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21279 + p->lsc_hi, 0, NULL, _RET_IP_);
21280 + au_pin_hdir_set_owner(p, current);
21284 +void au_pin_hdir_release(struct au_pin *p)
21287 + au_pin_hdir_set_owner(p, p->task);
21288 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
21292 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21294 + if (pin && pin->parent)
21295 + return au_h_dptr(pin->parent, pin->bindex);
21299 +void au_unpin(struct au_pin *p)
21302 + au_pin_hdir_unlock(p);
21303 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21304 + vfsub_mnt_drop_write(p->h_mnt);
21308 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21309 + di_read_unlock(p->parent, AuLock_IR);
21310 + iput(p->hdir->hi_inode);
21312 + p->parent = NULL;
21315 + /* do not clear p->task */
21318 +int au_do_pin(struct au_pin *p)
21321 + struct super_block *sb;
21322 + struct inode *h_dir;
21325 + sb = p->dentry->d_sb;
21326 + p->br = au_sbr(sb, p->bindex);
21327 + if (IS_ROOT(p->dentry)) {
21328 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21329 + p->h_mnt = au_br_mnt(p->br);
21330 + err = vfsub_mnt_want_write(p->h_mnt);
21331 + if (unlikely(err)) {
21332 + au_fclr_pin(p->flags, MNT_WRITE);
21339 + p->h_dentry = NULL;
21340 + if (p->bindex <= au_dbbot(p->dentry))
21341 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21343 + p->parent = dget_parent(p->dentry);
21344 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21345 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21348 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21349 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21351 + h_dir = p->hdir->hi_inode;
21355 + * if DI_LOCKED is not set, then p->parent may be different
21356 + * and h_parent can be NULL.
21358 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21360 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21361 + di_read_unlock(p->parent, AuLock_IR);
21363 + p->parent = NULL;
21367 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21368 + p->h_mnt = au_br_mnt(p->br);
21369 + err = vfsub_mnt_want_write(p->h_mnt);
21370 + if (unlikely(err)) {
21371 + au_fclr_pin(p->flags, MNT_WRITE);
21372 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21373 + di_read_unlock(p->parent, AuLock_IR);
21375 + p->parent = NULL;
21381 + err = au_pin_hdir_lock(p);
21383 + goto out; /* success */
21388 + pr_err("err %d\n", err);
21389 + err = au_busy_or_stale();
21394 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21395 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21396 + unsigned int udba, unsigned char flags)
21398 + p->dentry = dentry;
21400 + p->lsc_di = lsc_di;
21401 + p->lsc_hi = lsc_hi;
21402 + p->flags = flags;
21403 + p->bindex = bindex;
21405 + p->parent = NULL;
21409 + p->h_dentry = NULL;
21410 + p->h_parent = NULL;
21412 + p->task = current;
21415 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21416 + unsigned int udba, unsigned char flags)
21418 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21420 + return au_do_pin(pin);
21423 +/* ---------------------------------------------------------------------- */
21426 + * ->setattr() and ->getattr() are called in various cases.
21427 + * chmod, stat: dentry is revalidated.
21428 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21430 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21432 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21433 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21436 + struct dentry *parent;
21439 + if (au_digen_test(dentry, sigen)) {
21440 + parent = dget_parent(dentry);
21441 + di_read_lock_parent(parent, AuLock_IR);
21442 + err = au_refresh_dentry(dentry, parent);
21443 + di_read_unlock(parent, AuLock_IR);
21451 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21452 + struct au_icpup_args *a)
21456 + aufs_bindex_t btop, ibtop;
21457 + struct dentry *hi_wh, *parent;
21458 + struct inode *inode;
21459 + struct au_wr_dir_args wr_dir_args = {
21460 + .force_btgt = -1,
21464 + if (d_is_dir(dentry))
21465 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21466 + /* plink or hi_wh() case */
21467 + btop = au_dbtop(dentry);
21468 + inode = d_inode(dentry);
21469 + ibtop = au_ibtop(inode);
21470 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21471 + wr_dir_args.force_btgt = ibtop;
21472 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21473 + if (unlikely(err < 0))
21477 + au_fset_icpup(a->flags, DID_CPUP);
21480 + a->pin_flags = AuPin_MNT_WRITE;
21482 + if (!IS_ROOT(dentry)) {
21483 + au_fset_pin(a->pin_flags, DI_LOCKED);
21484 + parent = dget_parent(dentry);
21485 + di_write_lock_parent(parent);
21488 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21489 + if (unlikely(err))
21493 + a->h_path.dentry = au_h_dptr(dentry, btop);
21494 + a->h_inode = d_inode(a->h_path.dentry);
21495 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21496 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21497 + if (ia->ia_size < i_size_read(a->h_inode))
21498 + sz = ia->ia_size;
21499 + inode_unlock_shared(a->h_inode);
21503 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21504 + hi_wh = au_hi_wh(inode, a->btgt);
21506 + struct au_cp_generic cpg = {
21507 + .dentry = dentry,
21513 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21514 + if (unlikely(err))
21516 + hi_wh = au_hi_wh(inode, a->btgt);
21517 + /* todo: revalidate hi_wh? */
21522 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21523 + di_downgrade_lock(parent, AuLock_IR);
21527 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21528 + goto out; /* success */
21530 + if (!d_unhashed(dentry)) {
21531 + struct au_cp_generic cpg = {
21532 + .dentry = dentry,
21537 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21539 + err = au_sio_cpup_simple(&cpg);
21541 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21542 + } else if (!hi_wh)
21543 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21545 + a->h_path.dentry = hi_wh; /* do not dget here */
21548 + a->h_inode = d_inode(a->h_path.dentry);
21550 + goto out; /* success */
21551 + au_unpin(&a->pin);
21554 + di_write_unlock(parent);
21559 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21563 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21566 + struct inode *inode, *delegated;
21567 + struct super_block *sb;
21568 + struct file *file;
21569 + struct au_icpup_args *a;
21571 + inode = d_inode(dentry);
21572 + IMustLock(inode);
21574 + err = setattr_prepare(dentry, ia);
21575 + if (unlikely(err))
21579 + a = kzalloc(sizeof(*a), GFP_NOFS);
21580 + if (unlikely(!a))
21583 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21584 + ia->ia_valid &= ~ATTR_MODE;
21587 + sb = dentry->d_sb;
21588 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21589 + if (unlikely(err))
21592 + if (ia->ia_valid & ATTR_FILE) {
21593 + /* currently ftruncate(2) only */
21594 + AuDebugOn(!d_is_reg(dentry));
21595 + file = ia->ia_file;
21596 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21598 + if (unlikely(err))
21600 + ia->ia_file = au_hf_top(file);
21601 + a->udba = AuOpt_UDBA_NONE;
21603 + /* fchmod() doesn't pass ia_file */
21604 + a->udba = au_opt_udba(sb);
21605 + di_write_lock_child(dentry);
21606 + /* no d_unlinked(), to set UDBA_NONE for root */
21607 + if (d_unhashed(dentry))
21608 + a->udba = AuOpt_UDBA_NONE;
21609 + if (a->udba != AuOpt_UDBA_NONE) {
21610 + AuDebugOn(IS_ROOT(dentry));
21611 + err = au_reval_for_attr(dentry, au_sigen(sb));
21612 + if (unlikely(err))
21617 + err = au_pin_and_icpup(dentry, ia, a);
21618 + if (unlikely(err < 0))
21620 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21621 + ia->ia_file = NULL;
21622 + ia->ia_valid &= ~ATTR_FILE;
21625 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21626 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21627 + == (ATTR_MODE | ATTR_CTIME)) {
21628 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21629 + if (unlikely(err))
21631 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21632 + && (ia->ia_valid & ATTR_CTIME)) {
21633 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21634 + if (unlikely(err))
21638 + if (ia->ia_valid & ATTR_SIZE) {
21641 + if (ia->ia_size < i_size_read(inode))
21643 + truncate_setsize(inode, ia->ia_size);
21646 + if (ia->ia_valid & ATTR_FILE)
21648 + inode_unlock(a->h_inode);
21649 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21650 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21652 + delegated = NULL;
21654 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21656 + err = break_deleg_wait(&delegated);
21664 + * regardless aufs 'acl' option setting.
21665 + * why don't all acl-aware fs call this func from their ->setattr()?
21667 + if (!err && (ia->ia_valid & ATTR_MODE))
21668 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21670 + au_cpup_attr_changeable(inode);
21673 + inode_unlock(a->h_inode);
21674 + au_unpin(&a->pin);
21675 + if (unlikely(err))
21676 + au_update_dbtop(dentry);
21678 + di_write_unlock(dentry);
21680 + fi_write_unlock(file);
21681 + ia->ia_file = file;
21682 + ia->ia_valid |= ATTR_FILE;
21685 + si_read_unlock(sb);
21693 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21694 +static int au_h_path_to_set_attr(struct dentry *dentry,
21695 + struct au_icpup_args *a, struct path *h_path)
21698 + struct super_block *sb;
21700 + sb = dentry->d_sb;
21701 + a->udba = au_opt_udba(sb);
21702 + /* no d_unlinked(), to set UDBA_NONE for root */
21703 + if (d_unhashed(dentry))
21704 + a->udba = AuOpt_UDBA_NONE;
21705 + if (a->udba != AuOpt_UDBA_NONE) {
21706 + AuDebugOn(IS_ROOT(dentry));
21707 + err = au_reval_for_attr(dentry, au_sigen(sb));
21708 + if (unlikely(err))
21711 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21712 + if (unlikely(err < 0))
21715 + h_path->dentry = a->h_path.dentry;
21716 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21722 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21723 + struct au_sxattr *arg)
21726 + struct path h_path;
21727 + struct super_block *sb;
21728 + struct au_icpup_args *a;
21729 + struct inode *h_inode;
21731 + IMustLock(inode);
21734 + a = kzalloc(sizeof(*a), GFP_NOFS);
21735 + if (unlikely(!a))
21738 + sb = dentry->d_sb;
21739 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21740 + if (unlikely(err))
21743 + h_path.dentry = NULL; /* silence gcc */
21744 + di_write_lock_child(dentry);
21745 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21746 + if (unlikely(err))
21749 + inode_unlock(a->h_inode);
21750 + switch (arg->type) {
21751 + case AU_XATTR_SET:
21752 + AuDebugOn(d_is_negative(h_path.dentry));
21753 + err = vfsub_setxattr(h_path.dentry,
21754 + arg->u.set.name, arg->u.set.value,
21755 + arg->u.set.size, arg->u.set.flags);
21758 + err = -EOPNOTSUPP;
21759 + h_inode = d_inode(h_path.dentry);
21760 + if (h_inode->i_op->set_acl)
21761 + /* this will call posix_acl_update_mode */
21762 + err = h_inode->i_op->set_acl(h_inode,
21763 + arg->u.acl_set.acl,
21764 + arg->u.acl_set.type);
21768 + au_cpup_attr_timesizes(inode);
21770 + au_unpin(&a->pin);
21771 + if (unlikely(err))
21772 + au_update_dbtop(dentry);
21775 + di_write_unlock(dentry);
21776 + si_read_unlock(sb);
21785 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21786 + unsigned int nlink)
21790 + inode->i_mode = st->mode;
21791 + /* don't i_[ug]id_write() here */
21792 + inode->i_uid = st->uid;
21793 + inode->i_gid = st->gid;
21794 + inode->i_atime = st->atime;
21795 + inode->i_mtime = st->mtime;
21796 + inode->i_ctime = st->ctime;
21798 + au_cpup_attr_nlink(inode, /*force*/0);
21799 + if (S_ISDIR(inode->i_mode)) {
21800 + n = inode->i_nlink;
21803 + smp_mb(); /* for i_nlink */
21804 + /* 0 can happen */
21805 + set_nlink(inode, n);
21808 + spin_lock(&inode->i_lock);
21809 + inode->i_blocks = st->blocks;
21810 + i_size_write(inode, st->size);
21811 + spin_unlock(&inode->i_lock);
21815 + * common routine for aufs_getattr() and au_getxattr().
21816 + * returns zero or negative (an error).
21817 + * @dentry will be read-locked in success.
21819 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21820 + struct path *h_path, int locked)
21823 + unsigned int mnt_flags, sigen;
21824 + unsigned char udba_none;
21825 + aufs_bindex_t bindex;
21826 + struct super_block *sb, *h_sb;
21828 + h_path->mnt = NULL;
21829 + h_path->dentry = NULL;
21832 + sb = dentry->d_sb;
21833 + mnt_flags = au_mntflags(sb);
21834 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21836 + if (unlikely(locked))
21837 + goto body; /* skip locking dinfo */
21839 + /* support fstat(2) */
21840 + if (!d_unlinked(dentry) && !udba_none) {
21841 + sigen = au_sigen(sb);
21842 + err = au_digen_test(dentry, sigen);
21844 + di_read_lock_child(dentry, AuLock_IR);
21845 + err = au_dbrange_test(dentry);
21846 + if (unlikely(err)) {
21847 + di_read_unlock(dentry, AuLock_IR);
21851 + AuDebugOn(IS_ROOT(dentry));
21852 + di_write_lock_child(dentry);
21853 + err = au_dbrange_test(dentry);
21855 + err = au_reval_for_attr(dentry, sigen);
21857 + di_downgrade_lock(dentry, AuLock_IR);
21859 + di_write_unlock(dentry);
21864 + di_read_lock_child(dentry, AuLock_IR);
21868 + inode = d_inode(dentry);
21869 + if (unlikely(!inode))
21872 + bindex = au_ibtop(inode);
21873 + h_path->mnt = au_sbr_mnt(sb, bindex);
21874 + h_sb = h_path->mnt->mnt_sb;
21876 + && !au_test_fs_bad_iattr(h_sb)
21878 + goto out; /* success */
21880 + if (au_dbtop(dentry) == bindex)
21881 + h_path->dentry = au_h_dptr(dentry, bindex);
21882 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21883 + h_path->dentry = au_plink_lkup(inode, bindex);
21884 + if (IS_ERR(h_path->dentry))
21885 + /* pretending success */
21886 + h_path->dentry = NULL;
21888 + dput(h_path->dentry);
21895 +static int aufs_getattr(const struct path *path, struct kstat *st,
21896 + u32 request, unsigned int query)
21899 + unsigned char positive;
21900 + struct path h_path;
21901 + struct dentry *dentry;
21902 + struct inode *inode;
21903 + struct super_block *sb;
21905 + dentry = path->dentry;
21906 + inode = d_inode(dentry);
21907 + sb = dentry->d_sb;
21908 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21909 + if (unlikely(err))
21911 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
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 01:00:00.000000000 +0100
22141 +++ linux/fs/aufs/i_op_del.c 2021-02-22 23:30:37.702680911 +0100
22143 +// SPDX-License-Identifier: GPL-2.0
22145 + * Copyright (C) 2005-2020 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 01:00:00.000000000 +0100
22658 +++ linux/fs/aufs/i_op_ren.c 2021-02-22 23:30:37.702680911 +0100
22660 +// SPDX-License-Identifier: GPL-2.0
22662 + * Copyright (C) 2005-2020 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);
23077 +#if 0 /* debugging */
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 01:00:00.000000000 +0100
23912 +++ linux/fs/aufs/Kconfig 2021-02-22 23:30:37.699347580 +0100
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 01:00:00.000000000 +0100
24115 +++ linux/fs/aufs/lcnt.h 2021-02-22 23:30:37.702680911 +0100
24117 +/* SPDX-License-Identifier: GPL-2.0 */
24119 + * Copyright (C) 2018-2020 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 01:00:00.000000000 +0100
24305 +++ linux/fs/aufs/loop.c 2021-02-22 23:30:37.702680911 +0100
24307 +// SPDX-License-Identifier: GPL-2.0
24309 + * Copyright (C) 2005-2020 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(unsigned long));
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 01:00:00.000000000 +0100
24457 +++ linux/fs/aufs/loop.h 2021-02-22 23:30:37.702680911 +0100
24459 +/* SPDX-License-Identifier: GPL-2.0 */
24461 + * Copyright (C) 2005-2020 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 01:00:00.000000000 +0100
24516 +++ linux/fs/aufs/magic.mk 2021-02-22 23:30:37.702680911 +0100
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 01:00:00.000000000 +0100
24551 +++ linux/fs/aufs/Makefile 2021-02-22 23:30:37.699347580 +0100
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 01:00:00.000000000 +0100
24601 +++ linux/fs/aufs/module.c 2021-02-22 23:30:37.702680911 +0100
24603 +// SPDX-License-Identifier: GPL-2.0
24605 + * Copyright (C) 2005-2020 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 01:00:00.000000000 +0100
24878 +++ linux/fs/aufs/module.h 2021-02-22 23:30:37.702680911 +0100
24880 +/* SPDX-License-Identifier: GPL-2.0 */
24882 + * Copyright (C) 2005-2020 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 01:00:00.000000000 +0100
25048 +++ linux/fs/aufs/mvdown.c 2021-02-22 23:30:37.702680911 +0100
25050 +// SPDX-License-Identifier: GPL-2.0
25052 + * Copyright (C) 2011-2020 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 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
25696 + if (unlikely(err)) {
25701 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25702 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25703 + args->mvdown.au_errno = 0;
25704 + args->dentry = dentry;
25705 + args->inode = inode;
25706 + args->sb = dentry->d_sb;
25709 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25710 + args->parent = dget_parent(dentry);
25711 + args->dir = d_inode(args->parent);
25712 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25713 + dput(args->parent);
25714 + if (unlikely(args->parent != dentry->d_parent)) {
25715 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25719 + inode_lock_nested(inode, I_MUTEX_CHILD);
25720 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25721 + if (unlikely(err))
25724 + di_write_lock_parent(args->parent);
25725 + err = au_mvd_args(dmsg, args);
25726 + if (unlikely(err))
25729 + err = au_do_mvdown(dmsg, args);
25730 + if (unlikely(err))
25733 + au_cpup_attr_timesizes(args->dir);
25734 + au_cpup_attr_timesizes(inode);
25735 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25736 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25737 + /* au_digen_dec(dentry); */
25740 + di_write_unlock(args->parent);
25741 + aufs_read_unlock(dentry, AuLock_DW);
25743 + inode_unlock(inode);
25745 + inode_unlock(args->dir);
25747 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25750 + au_kfree_rcu(args);
25755 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25756 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25757 +++ linux/fs/aufs/opts.c 2021-02-22 23:30:37.702680911 +0100
25759 +// SPDX-License-Identifier: GPL-2.0
25761 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25763 + * This program, aufs is free software; you can redistribute it and/or modify
25764 + * it under the terms of the GNU General Public License as published by
25765 + * the Free Software Foundation; either version 2 of the License, or
25766 + * (at your option) any later version.
25768 + * This program is distributed in the hope that it will be useful,
25769 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25770 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25771 + * GNU General Public License for more details.
25773 + * You should have received a copy of the GNU General Public License
25774 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25778 + * mount options/flags
25781 +#include <linux/namei.h>
25782 +#include <linux/types.h> /* a distribution requires */
25783 +#include <linux/parser.h>
25786 +/* ---------------------------------------------------------------------- */
25790 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25791 + Opt_idel, Opt_imod,
25792 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25793 + Opt_rdblk_def, Opt_rdhash_def,
25794 + Opt_xino, Opt_noxino,
25795 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25796 + Opt_trunc_xino_path, Opt_itrunc_xino,
25797 + Opt_trunc_xib, Opt_notrunc_xib,
25798 + Opt_shwh, Opt_noshwh,
25799 + Opt_plink, Opt_noplink, Opt_list_plink,
25801 + Opt_dio, Opt_nodio,
25802 + Opt_diropq_a, Opt_diropq_w,
25803 + Opt_warn_perm, Opt_nowarn_perm,
25804 + Opt_wbr_copyup, Opt_wbr_create,
25806 + Opt_verbose, Opt_noverbose,
25807 + Opt_sum, Opt_nosum, Opt_wsum,
25808 + Opt_dirperm1, Opt_nodirperm1,
25809 + Opt_dirren, Opt_nodirren,
25810 + Opt_acl, Opt_noacl,
25811 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25814 +static match_table_t options = {
25815 + {Opt_br, "br=%s"},
25816 + {Opt_br, "br:%s"},
25818 + {Opt_add, "add=%d:%s"},
25819 + {Opt_add, "add:%d:%s"},
25820 + {Opt_add, "ins=%d:%s"},
25821 + {Opt_add, "ins:%d:%s"},
25822 + {Opt_append, "append=%s"},
25823 + {Opt_append, "append:%s"},
25824 + {Opt_prepend, "prepend=%s"},
25825 + {Opt_prepend, "prepend:%s"},
25827 + {Opt_del, "del=%s"},
25828 + {Opt_del, "del:%s"},
25829 + /* {Opt_idel, "idel:%d"}, */
25830 + {Opt_mod, "mod=%s"},
25831 + {Opt_mod, "mod:%s"},
25832 + /* {Opt_imod, "imod:%d:%s"}, */
25834 + {Opt_dirwh, "dirwh=%d"},
25836 + {Opt_xino, "xino=%s"},
25837 + {Opt_noxino, "noxino"},
25838 + {Opt_trunc_xino, "trunc_xino"},
25839 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25840 + {Opt_notrunc_xino, "notrunc_xino"},
25841 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25842 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25843 + /* {Opt_zxino, "zxino=%s"}, */
25844 + {Opt_trunc_xib, "trunc_xib"},
25845 + {Opt_notrunc_xib, "notrunc_xib"},
25847 +#ifdef CONFIG_PROC_FS
25848 + {Opt_plink, "plink"},
25850 + {Opt_ignore_silent, "plink"},
25853 + {Opt_noplink, "noplink"},
25855 +#ifdef CONFIG_AUFS_DEBUG
25856 + {Opt_list_plink, "list_plink"},
25859 + {Opt_udba, "udba=%s"},
25861 + {Opt_dio, "dio"},
25862 + {Opt_nodio, "nodio"},
25864 +#ifdef CONFIG_AUFS_DIRREN
25865 + {Opt_dirren, "dirren"},
25866 + {Opt_nodirren, "nodirren"},
25868 + {Opt_ignore, "dirren"},
25869 + {Opt_ignore_silent, "nodirren"},
25872 +#ifdef CONFIG_AUFS_FHSM
25873 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25875 + {Opt_ignore, "fhsm_sec=%d"},
25878 + {Opt_diropq_a, "diropq=always"},
25879 + {Opt_diropq_a, "diropq=a"},
25880 + {Opt_diropq_w, "diropq=whiteouted"},
25881 + {Opt_diropq_w, "diropq=w"},
25883 + {Opt_warn_perm, "warn_perm"},
25884 + {Opt_nowarn_perm, "nowarn_perm"},
25886 + /* keep them temporary */
25887 + {Opt_ignore_silent, "nodlgt"},
25888 + {Opt_ignore, "clean_plink"},
25890 +#ifdef CONFIG_AUFS_SHWH
25891 + {Opt_shwh, "shwh"},
25893 + {Opt_noshwh, "noshwh"},
25895 + {Opt_dirperm1, "dirperm1"},
25896 + {Opt_nodirperm1, "nodirperm1"},
25898 + {Opt_verbose, "verbose"},
25899 + {Opt_verbose, "v"},
25900 + {Opt_noverbose, "noverbose"},
25901 + {Opt_noverbose, "quiet"},
25902 + {Opt_noverbose, "q"},
25903 + {Opt_noverbose, "silent"},
25905 + {Opt_sum, "sum"},
25906 + {Opt_nosum, "nosum"},
25907 + {Opt_wsum, "wsum"},
25909 + {Opt_rdcache, "rdcache=%d"},
25910 + {Opt_rdblk, "rdblk=%d"},
25911 + {Opt_rdblk_def, "rdblk=def"},
25912 + {Opt_rdhash, "rdhash=%d"},
25913 + {Opt_rdhash_def, "rdhash=def"},
25915 + {Opt_wbr_create, "create=%s"},
25916 + {Opt_wbr_create, "create_policy=%s"},
25917 + {Opt_wbr_copyup, "cpup=%s"},
25918 + {Opt_wbr_copyup, "copyup=%s"},
25919 + {Opt_wbr_copyup, "copyup_policy=%s"},
25921 + /* generic VFS flag */
25922 +#ifdef CONFIG_FS_POSIX_ACL
25923 + {Opt_acl, "acl"},
25924 + {Opt_noacl, "noacl"},
25926 + {Opt_ignore, "acl"},
25927 + {Opt_ignore_silent, "noacl"},
25930 + /* internal use for the scripts */
25931 + {Opt_ignore_silent, "si=%s"},
25933 + {Opt_br, "dirs=%s"},
25934 + {Opt_ignore, "debug=%d"},
25935 + {Opt_ignore, "delete=whiteout"},
25936 + {Opt_ignore, "delete=all"},
25937 + {Opt_ignore, "imap=%s"},
25939 + /* temporary workaround, due to old mount(8)? */
25940 + {Opt_ignore_silent, "relatime"},
25945 +/* ---------------------------------------------------------------------- */
25947 +static const char *au_parser_pattern(int val, match_table_t tbl)
25949 + struct match_token *p;
25952 + while (p->pattern) {
25953 + if (p->token == val)
25954 + return p->pattern;
25961 +static const char *au_optstr(int *val, match_table_t tbl)
25963 + struct match_token *p;
25970 + while (p->pattern) {
25972 + && (v & p->token) == p->token) {
25973 + *val &= ~p->token;
25974 + return p->pattern;
25983 +/* ---------------------------------------------------------------------- */
25985 +static match_table_t brperm = {
25986 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25987 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25988 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25992 +static match_table_t brattr = {
25994 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25995 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25996 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25997 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25998 +#ifdef CONFIG_AUFS_FHSM
25999 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26001 +#ifdef CONFIG_AUFS_XATTR
26002 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26003 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26004 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26005 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26006 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26007 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26010 + /* ro/rr branch */
26011 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26014 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26015 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26020 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26027 + p = strchr(str, '+');
26030 + v = match_token(str, table, args);
26032 + if (v & AuBrAttr_CMOO_Mask)
26033 + attr &= ~AuBrAttr_CMOO_Mask;
26038 + pr_warn("ignored branch attribute %s\n", str);
26048 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26056 + p = au_optstr(&perm, brattr);
26059 + memcpy(q, p, sz + 1);
26065 + p = au_optstr(&perm, brattr);
26069 + memcpy(q, p, sz + 1);
26075 + return q - str->a;
26078 +static int noinline_for_stack br_perm_val(char *perm)
26080 + int val, bad, sz;
26082 + substring_t args[MAX_OPT_ARGS];
26083 + au_br_perm_str_t attr;
26085 + p = strchr(perm, '+');
26088 + val = match_token(perm, brperm, args);
26092 + pr_warn("ignored branch permission %s\n", perm);
26093 + val = AuBrPerm_RO;
26099 + val |= br_attr_val(p + 1, brattr, args);
26102 + switch (val & AuBrPerm_Mask) {
26103 + case AuBrPerm_RO:
26104 + case AuBrPerm_RR:
26105 + bad = val & AuBrWAttr_Mask;
26106 + val &= ~AuBrWAttr_Mask;
26108 + case AuBrPerm_RW:
26109 + bad = val & AuBrRAttr_Mask;
26110 + val &= ~AuBrRAttr_Mask;
26115 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
26116 + * does not treat it as an error, just warning.
26117 + * this is a tiny guard for the user operation.
26119 + if (val & AuBrAttr_UNPIN) {
26120 + bad |= AuBrAttr_UNPIN;
26121 + val &= ~AuBrAttr_UNPIN;
26124 + if (unlikely(bad)) {
26125 + sz = au_do_optstr_br_attr(&attr, bad);
26127 + pr_warn("ignored branch attribute %s\n", attr.a);
26134 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
26136 + au_br_perm_str_t attr;
26142 + p = au_optstr(&perm, brperm);
26143 + AuDebugOn(!p || !*p);
26145 + memcpy(q, p, sz + 1);
26148 + sz = au_do_optstr_br_attr(&attr, perm);
26151 + memcpy(q, attr.a, sz + 1);
26154 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26157 +/* ---------------------------------------------------------------------- */
26159 +static match_table_t udbalevel = {
26160 + {AuOpt_UDBA_REVAL, "reval"},
26161 + {AuOpt_UDBA_NONE, "none"},
26162 +#ifdef CONFIG_AUFS_HNOTIFY
26163 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26164 +#ifdef CONFIG_AUFS_HFSNOTIFY
26165 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26171 +static int noinline_for_stack udba_val(char *str)
26173 + substring_t args[MAX_OPT_ARGS];
26175 + return match_token(str, udbalevel, args);
26178 +const char *au_optstr_udba(int udba)
26180 + return au_parser_pattern(udba, udbalevel);
26183 +/* ---------------------------------------------------------------------- */
26185 +static match_table_t au_wbr_create_policy = {
26186 + {AuWbrCreate_TDP, "tdp"},
26187 + {AuWbrCreate_TDP, "top-down-parent"},
26188 + {AuWbrCreate_RR, "rr"},
26189 + {AuWbrCreate_RR, "round-robin"},
26190 + {AuWbrCreate_MFS, "mfs"},
26191 + {AuWbrCreate_MFS, "most-free-space"},
26192 + {AuWbrCreate_MFSV, "mfs:%d"},
26193 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26195 + /* top-down regardless the parent, and then mfs */
26196 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26197 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26199 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26200 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26201 + {AuWbrCreate_PMFS, "pmfs"},
26202 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26203 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26204 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26209 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26210 + struct au_opt_wbr_create *create)
26213 + unsigned long long ull;
26216 + if (!match_u64(arg, &ull))
26217 + create->mfsrr_watermark = ull;
26219 + pr_err("bad integer in %s\n", str);
26226 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26227 + struct au_opt_wbr_create *create)
26232 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26233 + create->mfs_second = n;
26235 + pr_err("bad integer in %s\n", str);
26242 +static int noinline_for_stack
26243 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26246 + substring_t args[MAX_OPT_ARGS];
26248 + err = match_token(str, au_wbr_create_policy, args);
26249 + create->wbr_create = err;
26251 + case AuWbrCreate_MFSRRV:
26252 + case AuWbrCreate_TDMFSV:
26253 + case AuWbrCreate_PMFSRRV:
26254 + e = au_wbr_mfs_wmark(&args[0], str, create);
26256 + e = au_wbr_mfs_sec(&args[1], str, create);
26260 + case AuWbrCreate_MFSRR:
26261 + case AuWbrCreate_TDMFS:
26262 + case AuWbrCreate_PMFSRR:
26263 + e = au_wbr_mfs_wmark(&args[0], str, create);
26264 + if (unlikely(e)) {
26269 + case AuWbrCreate_MFS:
26270 + case AuWbrCreate_PMFS:
26271 + create->mfs_second = AUFS_MFS_DEF_SEC;
26273 + case AuWbrCreate_MFSV:
26274 + case AuWbrCreate_PMFSV:
26275 + e = au_wbr_mfs_sec(&args[0], str, create);
26284 +const char *au_optstr_wbr_create(int wbr_create)
26286 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26289 +static match_table_t au_wbr_copyup_policy = {
26290 + {AuWbrCopyup_TDP, "tdp"},
26291 + {AuWbrCopyup_TDP, "top-down-parent"},
26292 + {AuWbrCopyup_BUP, "bup"},
26293 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26294 + {AuWbrCopyup_BU, "bu"},
26295 + {AuWbrCopyup_BU, "bottom-up"},
26299 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26301 + substring_t args[MAX_OPT_ARGS];
26303 + return match_token(str, au_wbr_copyup_policy, args);
26306 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26308 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26311 +/* ---------------------------------------------------------------------- */
26313 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26315 +static void dump_opts(struct au_opts *opts)
26317 +#ifdef CONFIG_AUFS_DEBUG
26318 + /* reduce stack space */
26320 + struct au_opt_add *add;
26321 + struct au_opt_del *del;
26322 + struct au_opt_mod *mod;
26323 + struct au_opt_xino *xino;
26324 + struct au_opt_xino_itrunc *xino_itrunc;
26325 + struct au_opt_wbr_create *create;
26327 + struct au_opt *opt;
26330 + while (opt->type != Opt_tail) {
26331 + switch (opt->type) {
26333 + u.add = &opt->add;
26334 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26335 + u.add->bindex, u.add->pathname, u.add->perm,
26336 + u.add->path.dentry);
26340 + u.del = &opt->del;
26341 + AuDbg("del {%s, %p}\n",
26342 + u.del->pathname, u.del->h_path.dentry);
26346 + u.mod = &opt->mod;
26347 + AuDbg("mod {%s, 0x%x, %p}\n",
26348 + u.mod->path, u.mod->perm, u.mod->h_root);
26351 + u.add = &opt->add;
26352 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26353 + u.add->bindex, u.add->pathname, u.add->perm,
26354 + u.add->path.dentry);
26356 + case Opt_prepend:
26357 + u.add = &opt->add;
26358 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26359 + u.add->bindex, u.add->pathname, u.add->perm,
26360 + u.add->path.dentry);
26363 + AuDbg("dirwh %d\n", opt->dirwh);
26365 + case Opt_rdcache:
26366 + AuDbg("rdcache %d\n", opt->rdcache);
26369 + AuDbg("rdblk %u\n", opt->rdblk);
26371 + case Opt_rdblk_def:
26372 + AuDbg("rdblk_def\n");
26375 + AuDbg("rdhash %u\n", opt->rdhash);
26377 + case Opt_rdhash_def:
26378 + AuDbg("rdhash_def\n");
26381 + u.xino = &opt->xino;
26382 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26384 + case Opt_trunc_xino:
26385 + AuLabel(trunc_xino);
26387 + case Opt_notrunc_xino:
26388 + AuLabel(notrunc_xino);
26390 + case Opt_trunc_xino_path:
26391 + case Opt_itrunc_xino:
26392 + u.xino_itrunc = &opt->xino_itrunc;
26393 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26398 + case Opt_trunc_xib:
26399 + AuLabel(trunc_xib);
26401 + case Opt_notrunc_xib:
26402 + AuLabel(notrunc_xib);
26410 + case Opt_dirperm1:
26411 + AuLabel(dirperm1);
26413 + case Opt_nodirperm1:
26414 + AuLabel(nodirperm1);
26419 + case Opt_noplink:
26420 + AuLabel(noplink);
26422 + case Opt_list_plink:
26423 + AuLabel(list_plink);
26426 + AuDbg("udba %d, %s\n",
26427 + opt->udba, au_optstr_udba(opt->udba));
26435 + case Opt_diropq_a:
26436 + AuLabel(diropq_a);
26438 + case Opt_diropq_w:
26439 + AuLabel(diropq_w);
26441 + case Opt_warn_perm:
26442 + AuLabel(warn_perm);
26444 + case Opt_nowarn_perm:
26445 + AuLabel(nowarn_perm);
26447 + case Opt_verbose:
26448 + AuLabel(verbose);
26450 + case Opt_noverbose:
26451 + AuLabel(noverbose);
26462 + case Opt_wbr_create:
26463 + u.create = &opt->wbr_create;
26464 + AuDbg("create %d, %s\n", u.create->wbr_create,
26465 + au_optstr_wbr_create(u.create->wbr_create));
26466 + switch (u.create->wbr_create) {
26467 + case AuWbrCreate_MFSV:
26468 + case AuWbrCreate_PMFSV:
26469 + AuDbg("%d sec\n", u.create->mfs_second);
26471 + case AuWbrCreate_MFSRR:
26472 + case AuWbrCreate_TDMFS:
26473 + AuDbg("%llu watermark\n",
26474 + u.create->mfsrr_watermark);
26476 + case AuWbrCreate_MFSRRV:
26477 + case AuWbrCreate_TDMFSV:
26478 + case AuWbrCreate_PMFSRRV:
26479 + AuDbg("%llu watermark, %d sec\n",
26480 + u.create->mfsrr_watermark,
26481 + u.create->mfs_second);
26485 + case Opt_wbr_copyup:
26486 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26487 + au_optstr_wbr_copyup(opt->wbr_copyup));
26489 + case Opt_fhsm_sec:
26490 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26495 + case Opt_nodirren:
26496 + AuLabel(nodirren);
26512 +void au_opts_free(struct au_opts *opts)
26514 + struct au_opt *opt;
26517 + while (opt->type != Opt_tail) {
26518 + switch (opt->type) {
26521 + case Opt_prepend:
26522 + path_put(&opt->add.path);
26526 + path_put(&opt->del.h_path);
26530 + dput(opt->mod.h_root);
26533 + fput(opt->xino.file);
26540 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26541 + aufs_bindex_t bindex)
26544 + struct au_opt_add *add = &opt->add;
26547 + add->bindex = bindex;
26548 + add->perm = AuBrPerm_RO;
26549 + add->pathname = opt_str;
26550 + p = strchr(opt_str, '=');
26554 + add->perm = br_perm_val(p);
26557 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26560 + add->perm = AuBrPerm_RO;
26561 + if (au_test_fs_rr(add->path.dentry->d_sb))
26562 + add->perm = AuBrPerm_RR;
26563 + else if (!bindex && !(sb_flags & SB_RDONLY))
26564 + add->perm = AuBrPerm_RW;
26566 + opt->type = Opt_add;
26569 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26576 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26580 + del->pathname = args[0].from;
26581 + AuDbg("del path %s\n", del->pathname);
26583 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26584 + if (unlikely(err))
26585 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26590 +#if 0 /* reserved for future use */
26591 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26592 + struct au_opt_del *del, substring_t args[])
26595 + struct dentry *root;
26598 + root = sb->s_root;
26599 + aufs_read_lock(root, AuLock_FLUSH);
26600 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26601 + pr_err("out of bounds, %d\n", bindex);
26606 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26607 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26610 + aufs_read_unlock(root, !AuLock_IR);
26615 +static int noinline_for_stack
26616 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26619 + struct path path;
26623 + mod->path = args[0].from;
26624 + p = strchr(mod->path, '=');
26625 + if (unlikely(!p)) {
26626 + pr_err("no permission %s\n", args[0].from);
26631 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26632 + if (unlikely(err)) {
26633 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26637 + mod->perm = br_perm_val(p);
26638 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26639 + mod->h_root = dget(path.dentry);
26646 +#if 0 /* reserved for future use */
26647 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26648 + struct au_opt_mod *mod, substring_t args[])
26651 + struct dentry *root;
26654 + root = sb->s_root;
26655 + aufs_read_lock(root, AuLock_FLUSH);
26656 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26657 + pr_err("out of bounds, %d\n", bindex);
26662 + mod->perm = br_perm_val(args[1].from);
26663 + AuDbg("mod path %s, perm 0x%x, %s\n",
26664 + mod->path, mod->perm, args[1].from);
26665 + mod->h_root = dget(au_h_dptr(root, bindex));
26668 + aufs_read_unlock(root, !AuLock_IR);
26673 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26674 + substring_t args[])
26677 + struct file *file;
26679 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26680 + err = PTR_ERR(file);
26681 + if (IS_ERR(file))
26685 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26687 + pr_err("%s must be outside\n", args[0].from);
26692 + xino->file = file;
26693 + xino->path = args[0].from;
26699 +static int noinline_for_stack
26700 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26701 + struct au_opt_xino_itrunc *xino_itrunc,
26702 + substring_t args[])
26705 + aufs_bindex_t bbot, bindex;
26706 + struct path path;
26707 + struct dentry *root;
26709 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26710 + if (unlikely(err)) {
26711 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26715 + xino_itrunc->bindex = -1;
26716 + root = sb->s_root;
26717 + aufs_read_lock(root, AuLock_FLUSH);
26718 + bbot = au_sbbot(sb);
26719 + for (bindex = 0; bindex <= bbot; bindex++) {
26720 + if (au_h_dptr(root, bindex) == path.dentry) {
26721 + xino_itrunc->bindex = bindex;
26725 + aufs_read_unlock(root, !AuLock_IR);
26728 + if (unlikely(xino_itrunc->bindex < 0)) {
26729 + pr_err("no such branch %s\n", args[0].from);
26737 +/* called without aufs lock */
26738 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26740 + int err, n, token;
26741 + aufs_bindex_t bindex;
26742 + unsigned char skipped;
26743 + struct dentry *root;
26744 + struct au_opt *opt, *opt_tail;
26746 + /* reduce the stack space */
26748 + struct au_opt_xino_itrunc *xino_itrunc;
26749 + struct au_opt_wbr_create *create;
26752 + substring_t args[MAX_OPT_ARGS];
26756 + a = kmalloc(sizeof(*a), GFP_NOFS);
26757 + if (unlikely(!a))
26760 + root = sb->s_root;
26764 + opt_tail = opt + opts->max_opt - 1;
26765 + opt->type = Opt_tail;
26766 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26769 + token = match_token(opt_str, options, a->args);
26773 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26775 + err = opt_add(opt, opt_str, opts->sb_flags,
26777 + if (unlikely(!err && ++opt > opt_tail)) {
26781 + opt->type = Opt_tail;
26786 + if (unlikely(match_int(&a->args[0], &n))) {
26787 + pr_err("bad integer in %s\n", opt_str);
26791 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26794 + opt->type = token;
26797 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26798 + /*dummy bindex*/1);
26800 + opt->type = token;
26802 + case Opt_prepend:
26803 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26806 + opt->type = token;
26809 + err = au_opts_parse_del(&opt->del, a->args);
26811 + opt->type = token;
26813 +#if 0 /* reserved for future use */
26815 + del->pathname = "(indexed)";
26816 + if (unlikely(match_int(&args[0], &n))) {
26817 + pr_err("bad integer in %s\n", opt_str);
26820 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26822 + opt->type = token;
26826 + err = au_opts_parse_mod(&opt->mod, a->args);
26828 + opt->type = token;
26830 +#ifdef IMOD /* reserved for future use */
26832 + u.mod->path = "(indexed)";
26833 + if (unlikely(match_int(&a->args[0], &n))) {
26834 + pr_err("bad integer in %s\n", opt_str);
26837 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26839 + opt->type = token;
26843 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26845 + opt->type = token;
26848 + case Opt_trunc_xino_path:
26849 + err = au_opts_parse_xino_itrunc_path
26850 + (sb, &opt->xino_itrunc, a->args);
26852 + opt->type = token;
26855 + case Opt_itrunc_xino:
26856 + u.xino_itrunc = &opt->xino_itrunc;
26857 + if (unlikely(match_int(&a->args[0], &n))) {
26858 + pr_err("bad integer in %s\n", opt_str);
26861 + u.xino_itrunc->bindex = n;
26862 + aufs_read_lock(root, AuLock_FLUSH);
26863 + if (n < 0 || au_sbbot(sb) < n) {
26864 + pr_err("out of bounds, %d\n", n);
26865 + aufs_read_unlock(root, !AuLock_IR);
26868 + aufs_read_unlock(root, !AuLock_IR);
26870 + opt->type = token;
26874 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26877 + opt->type = token;
26880 + case Opt_rdcache:
26881 + if (unlikely(match_int(&a->args[0], &n))) {
26882 + pr_err("bad integer in %s\n", opt_str);
26885 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26886 + pr_err("rdcache must be smaller than %d\n",
26887 + AUFS_RDCACHE_MAX);
26890 + opt->rdcache = n;
26892 + opt->type = token;
26895 + if (unlikely(match_int(&a->args[0], &n)
26897 + || n > KMALLOC_MAX_SIZE)) {
26898 + pr_err("bad integer in %s\n", opt_str);
26901 + if (unlikely(n && n < NAME_MAX)) {
26902 + pr_err("rdblk must be larger than %d\n",
26908 + opt->type = token;
26911 + if (unlikely(match_int(&a->args[0], &n)
26913 + || n * sizeof(struct hlist_head)
26914 + > KMALLOC_MAX_SIZE)) {
26915 + pr_err("bad integer in %s\n", opt_str);
26920 + opt->type = token;
26923 + case Opt_trunc_xino:
26924 + case Opt_notrunc_xino:
26926 + case Opt_trunc_xib:
26927 + case Opt_notrunc_xib:
26930 + case Opt_dirperm1:
26931 + case Opt_nodirperm1:
26933 + case Opt_noplink:
26934 + case Opt_list_plink:
26937 + case Opt_diropq_a:
26938 + case Opt_diropq_w:
26939 + case Opt_warn_perm:
26940 + case Opt_nowarn_perm:
26941 + case Opt_verbose:
26942 + case Opt_noverbose:
26946 + case Opt_rdblk_def:
26947 + case Opt_rdhash_def:
26949 + case Opt_nodirren:
26953 + opt->type = token;
26957 + opt->udba = udba_val(a->args[0].from);
26958 + if (opt->udba >= 0) {
26960 + opt->type = token;
26962 + pr_err("wrong value, %s\n", opt_str);
26965 + case Opt_wbr_create:
26966 + u.create = &opt->wbr_create;
26967 + u.create->wbr_create
26968 + = au_wbr_create_val(a->args[0].from, u.create);
26969 + if (u.create->wbr_create >= 0) {
26971 + opt->type = token;
26973 + pr_err("wrong value, %s\n", opt_str);
26975 + case Opt_wbr_copyup:
26976 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26977 + if (opt->wbr_copyup >= 0) {
26979 + opt->type = token;
26981 + pr_err("wrong value, %s\n", opt_str);
26984 + case Opt_fhsm_sec:
26985 + if (unlikely(match_int(&a->args[0], &n)
26987 + pr_err("bad integer in %s\n", opt_str);
26990 + if (sysaufs_brs) {
26991 + opt->fhsm_second = n;
26992 + opt->type = token;
26994 + pr_warn("ignored %s\n", opt_str);
26999 + pr_warn("ignored %s\n", opt_str);
27001 + case Opt_ignore_silent:
27006 + pr_err("unknown option %s\n", opt_str);
27010 + if (!err && !skipped) {
27011 + if (unlikely(++opt > opt_tail)) {
27014 + opt->type = Opt_tail;
27017 + opt->type = Opt_tail;
27023 + if (unlikely(err))
27024 + au_opts_free(opts);
27030 +static int au_opt_wbr_create(struct super_block *sb,
27031 + struct au_opt_wbr_create *create)
27034 + struct au_sbinfo *sbinfo;
27036 + SiMustWriteLock(sb);
27038 + err = 1; /* handled */
27039 + sbinfo = au_sbi(sb);
27040 + if (sbinfo->si_wbr_create_ops->fin) {
27041 + err = sbinfo->si_wbr_create_ops->fin(sb);
27046 + sbinfo->si_wbr_create = create->wbr_create;
27047 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27048 + switch (create->wbr_create) {
27049 + case AuWbrCreate_MFSRRV:
27050 + case AuWbrCreate_MFSRR:
27051 + case AuWbrCreate_TDMFS:
27052 + case AuWbrCreate_TDMFSV:
27053 + case AuWbrCreate_PMFSRR:
27054 + case AuWbrCreate_PMFSRRV:
27055 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27057 + case AuWbrCreate_MFS:
27058 + case AuWbrCreate_MFSV:
27059 + case AuWbrCreate_PMFS:
27060 + case AuWbrCreate_PMFSV:
27061 + sbinfo->si_wbr_mfs.mfs_expire
27062 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27066 + if (sbinfo->si_wbr_create_ops->init)
27067 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27074 + * plus: processed without an error
27075 + * zero: unprocessed
27077 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27078 + struct au_opts *opts)
27081 + struct au_sbinfo *sbinfo;
27083 + SiMustWriteLock(sb);
27085 + err = 1; /* handled */
27086 + sbinfo = au_sbi(sb);
27087 + switch (opt->type) {
27089 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27090 + sbinfo->si_mntflags |= opt->udba;
27091 + opts->given_udba |= opt->udba;
27095 + au_opt_set(sbinfo->si_mntflags, PLINK);
27097 + case Opt_noplink:
27098 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27099 + au_plink_put(sb, /*verbose*/1);
27100 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27102 + case Opt_list_plink:
27103 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27104 + au_plink_list(sb);
27108 + au_opt_set(sbinfo->si_mntflags, DIO);
27109 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27112 + au_opt_clr(sbinfo->si_mntflags, DIO);
27113 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27116 + case Opt_fhsm_sec:
27117 + au_fhsm_set(sbinfo, opt->fhsm_second);
27120 + case Opt_diropq_a:
27121 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27123 + case Opt_diropq_w:
27124 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27127 + case Opt_warn_perm:
27128 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27130 + case Opt_nowarn_perm:
27131 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27134 + case Opt_verbose:
27135 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27137 + case Opt_noverbose:
27138 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27142 + au_opt_set(sbinfo->si_mntflags, SUM);
27145 + au_opt_clr(sbinfo->si_mntflags, SUM);
27146 + 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 + /* Always goto add, not fallthrough */
27274 + case Opt_prepend:
27275 + opt->add.bindex = 0;
27276 + /* fallthrough */
27277 + add: /* indented label */
27279 + err = au_br_add(sb, &opt->add,
27280 + au_ftest_opts(opts->flags, REMOUNT));
27283 + au_fset_opts(opts->flags, REFRESH);
27289 + err = au_br_del(sb, &opt->del,
27290 + au_ftest_opts(opts->flags, REMOUNT));
27293 + au_fset_opts(opts->flags, TRUNC_XIB);
27294 + au_fset_opts(opts->flags, REFRESH);
27300 + err = au_br_mod(sb, &opt->mod,
27301 + au_ftest_opts(opts->flags, REMOUNT),
27306 + au_fset_opts(opts->flags, REFRESH);
27313 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27314 + struct au_opt_xino **opt_xino,
27315 + struct au_opts *opts)
27320 + switch (opt->type) {
27322 + err = au_xino_set(sb, &opt->xino,
27323 + !!au_ftest_opts(opts->flags, REMOUNT));
27324 + if (unlikely(err))
27327 + *opt_xino = &opt->xino;
27332 + *opt_xino = (void *)-1;
27339 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27340 + unsigned int pending)
27343 + aufs_bindex_t bindex, bbot;
27344 + unsigned char do_plink, skip, do_free, can_no_dreval;
27345 + struct au_branch *br;
27346 + struct au_wbr *wbr;
27347 + struct dentry *root, *dentry;
27348 + struct inode *dir, *h_dir;
27349 + struct au_sbinfo *sbinfo;
27350 + struct au_hinode *hdir;
27352 + SiMustAnyLock(sb);
27354 + sbinfo = au_sbi(sb);
27355 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27357 + if (!(sb_flags & SB_RDONLY)) {
27358 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27359 + pr_warn("first branch should be rw\n");
27360 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27361 + pr_warn_once("shwh should be used with ro\n");
27364 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27365 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27366 + pr_warn_once("udba=*notify requires xino\n");
27368 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27369 + pr_warn_once("dirperm1 breaks the protection"
27370 + " by the permission bits on the lower branch\n");
27374 + root = sb->s_root;
27375 + dir = d_inode(root);
27376 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27377 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27379 + bbot = au_sbbot(sb);
27380 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27382 + h_dir = au_h_iptr(dir, bindex);
27383 + br = au_sbr(sb, bindex);
27385 + if ((br->br_perm & AuBrAttr_ICEX)
27386 + && !h_dir->i_op->listxattr)
27387 + br->br_perm &= ~AuBrAttr_ICEX;
27388 +#if 0 /* untested */
27389 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27390 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27391 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27395 + wbr = br->br_wbr;
27397 + wbr_wh_read_lock(wbr);
27399 + if (!au_br_writable(br->br_perm)) {
27402 + || (!wbr->wbr_whbase
27403 + && !wbr->wbr_plink
27404 + && !wbr->wbr_orph));
27405 + } else if (!au_br_wh_linkable(br->br_perm)) {
27406 + /* skip = (!br->br_whbase && !br->br_orph); */
27407 + skip = (!wbr || !wbr->wbr_whbase);
27408 + if (skip && wbr) {
27410 + skip = !!wbr->wbr_plink;
27412 + skip = !wbr->wbr_plink;
27415 + /* skip = (br->br_whbase && br->br_ohph); */
27416 + skip = (wbr && wbr->wbr_whbase);
27419 + skip = !!wbr->wbr_plink;
27421 + skip = !wbr->wbr_plink;
27425 + wbr_wh_read_unlock(wbr);
27427 + if (can_no_dreval) {
27428 + dentry = br->br_path.dentry;
27429 + spin_lock(&dentry->d_lock);
27430 + if (dentry->d_flags &
27431 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27432 + can_no_dreval = 0;
27433 + spin_unlock(&dentry->d_lock);
27436 + if (au_br_fhsm(br->br_perm)) {
27438 + AuDebugOn(!br->br_fhsm);
27444 + hdir = au_hi(dir, bindex);
27445 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27447 + wbr_wh_write_lock(wbr);
27448 + err = au_wh_init(br, sb);
27450 + wbr_wh_write_unlock(wbr);
27451 + au_hn_inode_unlock(hdir);
27453 + if (!err && do_free) {
27454 + au_kfree_rcu(wbr);
27455 + br->br_wbr = NULL;
27459 + if (can_no_dreval)
27460 + au_fset_si(sbinfo, NO_DREVAL);
27462 + au_fclr_si(sbinfo, NO_DREVAL);
27465 + au_fset_si(sbinfo, FHSM);
27466 + for (bindex = bbot; bindex >= 0; bindex--) {
27467 + br = au_sbr(sb, bindex);
27468 + if (au_br_fhsm(br->br_perm)) {
27469 + au_fhsm_set_bottom(sb, bindex);
27474 + au_fclr_si(sbinfo, FHSM);
27475 + au_fhsm_set_bottom(sb, -1);
27481 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27484 + unsigned int tmp;
27485 + aufs_bindex_t bindex, bbot;
27486 + struct au_opt *opt;
27487 + struct au_opt_xino *opt_xino, xino;
27488 + struct au_sbinfo *sbinfo;
27489 + struct au_branch *br;
27490 + struct inode *dir;
27492 + SiMustWriteLock(sb);
27497 + while (err >= 0 && opt->type != Opt_tail)
27498 + err = au_opt_simple(sb, opt++, opts);
27501 + else if (unlikely(err < 0))
27504 + /* disable xino and udba temporary */
27505 + sbinfo = au_sbi(sb);
27506 + tmp = sbinfo->si_mntflags;
27507 + au_opt_clr(sbinfo->si_mntflags, XINO);
27508 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27511 + while (err >= 0 && opt->type != Opt_tail)
27512 + err = au_opt_br(sb, opt++, opts);
27515 + else if (unlikely(err < 0))
27518 + bbot = au_sbbot(sb);
27519 + if (unlikely(bbot < 0)) {
27521 + pr_err("no branches\n");
27525 + if (au_opt_test(tmp, XINO))
27526 + au_opt_set(sbinfo->si_mntflags, XINO);
27528 + while (!err && opt->type != Opt_tail)
27529 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27530 + if (unlikely(err))
27533 + err = au_opts_verify(sb, sb->s_flags, tmp);
27534 + if (unlikely(err))
27537 + /* restore xino */
27538 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27539 + xino.file = au_xino_def(sb);
27540 + err = PTR_ERR(xino.file);
27541 + if (IS_ERR(xino.file))
27544 + err = au_xino_set(sb, &xino, /*remount*/0);
27546 + if (unlikely(err))
27550 + /* restore udba */
27551 + tmp &= AuOptMask_UDBA;
27552 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27553 + sbinfo->si_mntflags |= tmp;
27554 + bbot = au_sbbot(sb);
27555 + for (bindex = 0; bindex <= bbot; bindex++) {
27556 + br = au_sbr(sb, bindex);
27557 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27558 + if (unlikely(err))
27559 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27561 + /* go on even if err */
27563 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27564 + dir = d_inode(sb->s_root);
27565 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27572 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27575 + unsigned char no_dreval;
27576 + struct inode *dir;
27577 + struct au_opt_xino *opt_xino;
27578 + struct au_opt *opt;
27579 + struct au_sbinfo *sbinfo;
27581 + SiMustWriteLock(sb);
27583 + err = au_dr_opt_flush(sb);
27584 + if (unlikely(err))
27586 + au_fset_opts(opts->flags, DR_FLUSHED);
27588 + dir = d_inode(sb->s_root);
27589 + sbinfo = au_sbi(sb);
27592 + while (err >= 0 && opt->type != Opt_tail) {
27593 + err = au_opt_simple(sb, opt, opts);
27595 + err = au_opt_br(sb, opt, opts);
27597 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27603 + /* go on even err */
27605 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27606 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27607 + if (unlikely(rerr && !err))
27610 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27611 + au_fset_opts(opts->flags, REFRESH_IDOP);
27613 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27614 + rerr = au_xib_trunc(sb);
27615 + if (unlikely(rerr && !err))
27619 + /* will be handled by the caller */
27620 + if (!au_ftest_opts(opts->flags, REFRESH)
27621 + && (opts->given_udba
27622 + || au_opt_test(sbinfo->si_mntflags, XINO)
27623 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27625 + au_fset_opts(opts->flags, REFRESH);
27627 + AuDbg("status 0x%x\n", opts->flags);
27633 +/* ---------------------------------------------------------------------- */
27635 +unsigned int au_opt_udba(struct super_block *sb)
27637 + return au_mntflags(sb) & AuOptMask_UDBA;
27639 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27640 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27641 +++ linux/fs/aufs/opts.h 2021-02-22 23:30:37.702680911 +0100
27643 +/* SPDX-License-Identifier: GPL-2.0 */
27645 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27647 + * This program, aufs is free software; you can redistribute it and/or modify
27648 + * it under the terms of the GNU General Public License as published by
27649 + * the Free Software Foundation; either version 2 of the License, or
27650 + * (at your option) any later version.
27652 + * This program is distributed in the hope that it will be useful,
27653 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27654 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27655 + * GNU General Public License for more details.
27657 + * You should have received a copy of the GNU General Public License
27658 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27662 + * mount options/flags
27665 +#ifndef __AUFS_OPTS_H__
27666 +#define __AUFS_OPTS_H__
27670 +#include <linux/path.h>
27674 +/* ---------------------------------------------------------------------- */
27677 +#define AuOpt_XINO 1 /* external inode number bitmap
27678 + and translation table */
27679 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27680 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27681 +#define AuOpt_UDBA_REVAL (1 << 3)
27682 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27683 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27684 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27685 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27687 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27688 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27689 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27690 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27691 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27692 +#define AuOpt_DIO (1 << 14) /* direct io */
27693 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27695 +#ifndef CONFIG_AUFS_HNOTIFY
27696 +#undef AuOpt_UDBA_HNOTIFY
27697 +#define AuOpt_UDBA_HNOTIFY 0
27699 +#ifndef CONFIG_AUFS_DIRREN
27700 +#undef AuOpt_DIRREN
27701 +#define AuOpt_DIRREN 0
27703 +#ifndef CONFIG_AUFS_SHWH
27705 +#define AuOpt_SHWH 0
27708 +#define AuOpt_Def (AuOpt_XINO \
27709 + | AuOpt_UDBA_REVAL \
27711 + /* | AuOpt_DIRPERM1 */ \
27712 + | AuOpt_WARN_PERM)
27713 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27714 + | AuOpt_UDBA_REVAL \
27715 + | AuOpt_UDBA_HNOTIFY)
27717 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27718 +#define au_opt_set(flags, name) do { \
27719 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27720 + ((flags) |= AuOpt_##name); \
27722 +#define au_opt_set_udba(flags, name) do { \
27723 + (flags) &= ~AuOptMask_UDBA; \
27724 + ((flags) |= AuOpt_##name); \
27726 +#define au_opt_clr(flags, name) do { \
27727 + ((flags) &= ~AuOpt_##name); \
27730 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27732 +#ifdef CONFIG_PROC_FS
27735 + return mntflags & ~AuOpt_PLINK;
27739 +/* ---------------------------------------------------------------------- */
27741 +/* policies to select one among multiple writable branches */
27743 + AuWbrCreate_TDP, /* top down parent */
27744 + AuWbrCreate_RR, /* round robin */
27745 + AuWbrCreate_MFS, /* most free space */
27746 + AuWbrCreate_MFSV, /* mfs with seconds */
27747 + AuWbrCreate_MFSRR, /* mfs then rr */
27748 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27749 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27750 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27751 + AuWbrCreate_PMFS, /* parent and mfs */
27752 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27753 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27754 + AuWbrCreate_PMFSRRV, /* plus seconds */
27756 + AuWbrCreate_Def = AuWbrCreate_TDP
27760 + AuWbrCopyup_TDP, /* top down parent */
27761 + AuWbrCopyup_BUP, /* bottom up parent */
27762 + AuWbrCopyup_BU, /* bottom up */
27764 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27767 +/* ---------------------------------------------------------------------- */
27769 +struct au_opt_add {
27770 + aufs_bindex_t bindex;
27773 + struct path path;
27776 +struct au_opt_del {
27778 + struct path h_path;
27781 +struct au_opt_mod {
27784 + struct dentry *h_root;
27787 +struct au_opt_xino {
27789 + struct file *file;
27792 +struct au_opt_xino_itrunc {
27793 + aufs_bindex_t bindex;
27796 +struct au_opt_wbr_create {
27799 + unsigned long long mfsrr_watermark;
27805 + struct au_opt_xino xino;
27806 + struct au_opt_xino_itrunc xino_itrunc;
27807 + struct au_opt_add add;
27808 + struct au_opt_del del;
27809 + struct au_opt_mod mod;
27812 + unsigned int rdblk;
27813 + unsigned int rdhash;
27815 + struct au_opt_wbr_create wbr_create;
27817 + unsigned int fhsm_second;
27822 +#define AuOpts_REMOUNT 1
27823 +#define AuOpts_REFRESH (1 << 1)
27824 +#define AuOpts_TRUNC_XIB (1 << 2)
27825 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27826 +#define AuOpts_REFRESH_IDOP (1 << 4)
27827 +#define AuOpts_DR_FLUSHED (1 << 5)
27828 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27829 +#define au_fset_opts(flags, name) \
27830 + do { (flags) |= AuOpts_##name; } while (0)
27831 +#define au_fclr_opts(flags, name) \
27832 + do { (flags) &= ~AuOpts_##name; } while (0)
27834 +#ifndef CONFIG_AUFS_DIRREN
27835 +#undef AuOpts_DR_FLUSHED
27836 +#define AuOpts_DR_FLUSHED 0
27840 + struct au_opt *opt;
27843 + unsigned int given_udba;
27844 + unsigned int flags;
27845 + unsigned long sb_flags;
27848 +/* ---------------------------------------------------------------------- */
27851 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27852 +const char *au_optstr_udba(int udba);
27853 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27854 +const char *au_optstr_wbr_create(int wbr_create);
27856 +void au_opts_free(struct au_opts *opts);
27857 +struct super_block;
27858 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27859 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27860 + unsigned int pending);
27861 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27862 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27864 +unsigned int au_opt_udba(struct super_block *sb);
27866 +#endif /* __KERNEL__ */
27867 +#endif /* __AUFS_OPTS_H__ */
27868 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27869 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27870 +++ linux/fs/aufs/plink.c 2021-02-22 23:30:37.702680911 +0100
27872 +// SPDX-License-Identifier: GPL-2.0
27874 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27876 + * This program, aufs is free software; you can redistribute it and/or modify
27877 + * it under the terms of the GNU General Public License as published by
27878 + * the Free Software Foundation; either version 2 of the License, or
27879 + * (at your option) any later version.
27881 + * This program is distributed in the hope that it will be useful,
27882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27884 + * GNU General Public License for more details.
27886 + * You should have received a copy of the GNU General Public License
27887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27897 + * the pseudo-link maintenance mode.
27898 + * during a user process maintains the pseudo-links,
27899 + * prohibit adding a new plink and branch manipulation.
27903 + * For entry functions which will handle plink, and i_mutex is already held
27905 + * They cannot wait and should return an error at once.
27906 + * Callers has to check the error.
27908 + * For entry functions which will handle plink, but i_mutex is not held
27910 + * They can wait the plink maintenance mode to finish.
27912 + * They behave like F_SETLK and F_SETLKW.
27913 + * If the caller never handle plink, then both flags are unnecessary.
27916 +int au_plink_maint(struct super_block *sb, int flags)
27920 + struct task_struct *parent, *prev;
27921 + struct au_sbinfo *sbi;
27923 + SiMustAnyLock(sb);
27926 + if (!au_opt_test(au_mntflags(sb), PLINK))
27929 + sbi = au_sbi(sb);
27930 + pid = sbi->si_plink_maint_pid;
27931 + if (!pid || pid == current->pid)
27934 + /* todo: it highly depends upon /sbin/mount.aufs */
27936 + parent = current;
27940 + parent = rcu_dereference(parent->real_parent);
27941 + if (parent == prev)
27943 + ppid = task_pid_vnr(parent);
27944 + if (pid == ppid) {
27945 + rcu_read_unlock();
27950 + rcu_read_unlock();
27952 + if (au_ftest_lock(flags, NOPLMW)) {
27953 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27954 + /* AuDebugOn(!lockdep_depth(current)); */
27955 + while (sbi->si_plink_maint_pid) {
27956 + si_read_unlock(sb);
27957 + /* gave up wake_up_bit() */
27958 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27960 + if (au_ftest_lock(flags, FLUSH))
27961 + au_nwt_flush(&sbi->si_nowait);
27962 + si_noflush_read_lock(sb);
27964 + } else if (au_ftest_lock(flags, NOPLM)) {
27965 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27973 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27975 + spin_lock(&sbinfo->si_plink_maint_lock);
27976 + sbinfo->si_plink_maint_pid = 0;
27977 + spin_unlock(&sbinfo->si_plink_maint_lock);
27978 + wake_up_all(&sbinfo->si_plink_wq);
27981 +int au_plink_maint_enter(struct super_block *sb)
27984 + struct au_sbinfo *sbinfo;
27987 + sbinfo = au_sbi(sb);
27988 + /* make sure i am the only one in this fs */
27989 + si_write_lock(sb, AuLock_FLUSH);
27990 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27991 + spin_lock(&sbinfo->si_plink_maint_lock);
27992 + if (!sbinfo->si_plink_maint_pid)
27993 + sbinfo->si_plink_maint_pid = current->pid;
27996 + spin_unlock(&sbinfo->si_plink_maint_lock);
27998 + si_write_unlock(sb);
28003 +/* ---------------------------------------------------------------------- */
28005 +#ifdef CONFIG_AUFS_DEBUG
28006 +void au_plink_list(struct super_block *sb)
28009 + struct au_sbinfo *sbinfo;
28010 + struct hlist_bl_head *hbl;
28011 + struct hlist_bl_node *pos;
28012 + struct au_icntnr *icntnr;
28014 + SiMustAnyLock(sb);
28016 + sbinfo = au_sbi(sb);
28017 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28018 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28020 + for (i = 0; i < AuPlink_NHASH; i++) {
28021 + hbl = sbinfo->si_plink + i;
28022 + hlist_bl_lock(hbl);
28023 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28024 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28025 + hlist_bl_unlock(hbl);
28030 +/* is the inode pseudo-linked? */
28031 +int au_plink_test(struct inode *inode)
28034 + struct au_sbinfo *sbinfo;
28035 + struct hlist_bl_head *hbl;
28036 + struct hlist_bl_node *pos;
28037 + struct au_icntnr *icntnr;
28039 + sbinfo = au_sbi(inode->i_sb);
28040 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28041 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28042 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28045 + i = au_plink_hash(inode->i_ino);
28046 + hbl = sbinfo->si_plink + i;
28047 + hlist_bl_lock(hbl);
28048 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28049 + if (&icntnr->vfs_inode == inode) {
28053 + hlist_bl_unlock(hbl);
28057 +/* ---------------------------------------------------------------------- */
28060 + * generate a name for plink.
28061 + * the file will be stored under AUFS_WH_PLINKDIR.
28063 +/* 20 is max digits length of ulong 64 */
28064 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28066 +static int plink_name(char *name, int len, struct inode *inode,
28067 + aufs_bindex_t bindex)
28070 + struct inode *h_inode;
28072 + h_inode = au_h_iptr(inode, bindex);
28073 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28077 +struct au_do_plink_lkup_args {
28078 + struct dentry **errp;
28079 + struct qstr *tgtname;
28080 + struct dentry *h_parent;
28081 + struct au_branch *br;
28084 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28085 + struct dentry *h_parent,
28086 + struct au_branch *br)
28088 + struct dentry *h_dentry;
28089 + struct inode *h_inode;
28091 + h_inode = d_inode(h_parent);
28092 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28093 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
28094 + inode_unlock_shared(h_inode);
28098 +static void au_call_do_plink_lkup(void *args)
28100 + struct au_do_plink_lkup_args *a = args;
28101 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
28104 +/* lookup the plink-ed @inode under the branch at @bindex */
28105 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28107 + struct dentry *h_dentry, *h_parent;
28108 + struct au_branch *br;
28110 + char a[PLINK_NAME_LEN];
28111 + struct qstr tgtname = QSTR_INIT(a, 0);
28113 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28115 + br = au_sbr(inode->i_sb, bindex);
28116 + h_parent = br->br_wbr->wbr_plink;
28117 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28119 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28120 + struct au_do_plink_lkup_args args = {
28121 + .errp = &h_dentry,
28122 + .tgtname = &tgtname,
28123 + .h_parent = h_parent,
28127 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28128 + if (unlikely(wkq_err))
28129 + h_dentry = ERR_PTR(wkq_err);
28131 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
28136 +/* create a pseudo-link */
28137 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
28138 + struct dentry *h_dentry, struct au_branch *br)
28141 + struct path h_path = {
28142 + .mnt = au_br_mnt(br)
28144 + struct inode *h_dir, *delegated;
28146 + h_dir = d_inode(h_parent);
28147 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28149 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28150 + err = PTR_ERR(h_path.dentry);
28151 + if (IS_ERR(h_path.dentry))
28155 + /* wh.plink dir is not monitored */
28156 + /* todo: is it really safe? */
28157 + if (d_is_positive(h_path.dentry)
28158 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28159 + delegated = NULL;
28160 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28161 + if (unlikely(err == -EWOULDBLOCK)) {
28162 + pr_warn("cannot retry for NFSv4 delegation"
28163 + " for an internal unlink\n");
28166 + dput(h_path.dentry);
28167 + h_path.dentry = NULL;
28171 + if (!err && d_is_negative(h_path.dentry)) {
28172 + delegated = NULL;
28173 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28174 + if (unlikely(err == -EWOULDBLOCK)) {
28175 + pr_warn("cannot retry for NFSv4 delegation"
28176 + " for an internal link\n");
28180 + dput(h_path.dentry);
28183 + inode_unlock(h_dir);
28187 +struct do_whplink_args {
28189 + struct qstr *tgt;
28190 + struct dentry *h_parent;
28191 + struct dentry *h_dentry;
28192 + struct au_branch *br;
28195 +static void call_do_whplink(void *args)
28197 + struct do_whplink_args *a = args;
28198 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28201 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28202 + aufs_bindex_t bindex, struct au_branch *br)
28204 + int err, wkq_err;
28205 + struct au_wbr *wbr;
28206 + struct dentry *h_parent;
28207 + char a[PLINK_NAME_LEN];
28208 + struct qstr tgtname = QSTR_INIT(a, 0);
28210 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28211 + h_parent = wbr->wbr_plink;
28212 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28214 + /* always superio. */
28215 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28216 + struct do_whplink_args args = {
28219 + .h_parent = h_parent,
28220 + .h_dentry = h_dentry,
28223 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28224 + if (unlikely(wkq_err))
28227 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28233 + * create a new pseudo-link for @h_dentry on @bindex.
28234 + * the linked inode is held in aufs @inode.
28236 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28237 + struct dentry *h_dentry)
28239 + struct super_block *sb;
28240 + struct au_sbinfo *sbinfo;
28241 + struct hlist_bl_head *hbl;
28242 + struct hlist_bl_node *pos;
28243 + struct au_icntnr *icntnr;
28244 + int found, err, cnt, i;
28246 + sb = inode->i_sb;
28247 + sbinfo = au_sbi(sb);
28248 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28249 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28251 + found = au_plink_test(inode);
28255 + i = au_plink_hash(inode->i_ino);
28256 + hbl = sbinfo->si_plink + i;
28259 + hlist_bl_lock(hbl);
28260 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28261 + if (&icntnr->vfs_inode == inode) {
28267 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28268 + hlist_bl_add_head(&icntnr->plink, hbl);
28270 + hlist_bl_unlock(hbl);
28272 + cnt = au_hbl_count(hbl);
28273 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28274 + if (cnt > AUFS_PLINK_WARN)
28275 + AuWarn1(msg ", %d\n", cnt);
28277 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28278 + if (unlikely(err)) {
28279 + pr_warn("err %d, damaged pseudo link.\n", err);
28280 + au_hbl_del(&icntnr->plink, hbl);
28281 + iput(&icntnr->vfs_inode);
28284 + iput(&icntnr->vfs_inode);
28287 +/* free all plinks */
28288 +void au_plink_put(struct super_block *sb, int verbose)
28291 + struct au_sbinfo *sbinfo;
28292 + struct hlist_bl_head *hbl;
28293 + struct hlist_bl_node *pos, *tmp;
28294 + struct au_icntnr *icntnr;
28296 + SiMustWriteLock(sb);
28298 + sbinfo = au_sbi(sb);
28299 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28300 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28302 + /* no spin_lock since sbinfo is write-locked */
28304 + for (i = 0; i < AuPlink_NHASH; i++) {
28305 + hbl = sbinfo->si_plink + i;
28306 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28307 + pr_warn("pseudo-link is not flushed");
28310 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28311 + iput(&icntnr->vfs_inode);
28312 + INIT_HLIST_BL_HEAD(hbl);
28316 +void au_plink_clean(struct super_block *sb, int verbose)
28318 + struct dentry *root;
28320 + root = sb->s_root;
28321 + aufs_write_lock(root);
28322 + if (au_opt_test(au_mntflags(sb), PLINK))
28323 + au_plink_put(sb, verbose);
28324 + aufs_write_unlock(root);
28327 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28330 + aufs_bindex_t btop, bbot, bindex;
28333 + btop = au_ibtop(inode);
28334 + bbot = au_ibbot(inode);
28336 + for (bindex = btop; bindex <= bbot; bindex++) {
28337 + if (!au_h_iptr(inode, bindex)
28338 + || au_ii_br_id(inode, bindex) != br_id)
28340 + au_set_h_iptr(inode, bindex, NULL, 0);
28345 + for (bindex = btop; bindex <= bbot; bindex++)
28346 + if (au_h_iptr(inode, bindex)) {
28356 +/* free the plinks on a branch specified by @br_id */
28357 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28359 + struct au_sbinfo *sbinfo;
28360 + struct hlist_bl_head *hbl;
28361 + struct hlist_bl_node *pos, *tmp;
28362 + struct au_icntnr *icntnr;
28363 + struct inode *inode;
28366 + SiMustWriteLock(sb);
28368 + sbinfo = au_sbi(sb);
28369 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28370 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28372 + /* no bit_lock since sbinfo is write-locked */
28373 + for (i = 0; i < AuPlink_NHASH; i++) {
28374 + hbl = sbinfo->si_plink + i;
28375 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28376 + inode = au_igrab(&icntnr->vfs_inode);
28377 + ii_write_lock_child(inode);
28378 + do_put = au_plink_do_half_refresh(inode, br_id);
28380 + hlist_bl_del(&icntnr->plink);
28383 + ii_write_unlock(inode);
28388 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28389 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28390 +++ linux/fs/aufs/poll.c 2021-02-22 23:30:37.702680911 +0100
28392 +// SPDX-License-Identifier: GPL-2.0
28394 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28396 + * This program, aufs is free software; you can redistribute it and/or modify
28397 + * it under the terms of the GNU General Public License as published by
28398 + * the Free Software Foundation; either version 2 of the License, or
28399 + * (at your option) any later version.
28401 + * This program is distributed in the hope that it will be useful,
28402 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28403 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28404 + * GNU General Public License for more details.
28406 + * You should have received a copy of the GNU General Public License
28407 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28412 + * There is only one filesystem which implements ->poll operation, currently.
28417 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28420 + struct file *h_file;
28421 + struct super_block *sb;
28423 + /* We should pretend an error happened. */
28424 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28425 + sb = file->f_path.dentry->d_sb;
28426 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28428 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28429 + if (IS_ERR(h_file)) {
28430 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28434 + mask = vfs_poll(h_file, pt);
28435 + fput(h_file); /* instead of au_read_post() */
28438 + si_read_unlock(sb);
28439 + if (mask & EPOLLERR)
28440 + AuDbg("mask 0x%x\n", mask);
28443 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28444 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28445 +++ linux/fs/aufs/posix_acl.c 2021-02-22 23:30:37.702680911 +0100
28447 +// SPDX-License-Identifier: GPL-2.0
28449 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28451 + * This program, aufs is free software; you can redistribute it and/or modify
28452 + * it under the terms of the GNU General Public License as published by
28453 + * the Free Software Foundation; either version 2 of the License, or
28454 + * (at your option) any later version.
28456 + * This program is distributed in the hope that it will be useful,
28457 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28458 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28459 + * GNU General Public License for more details.
28461 + * You should have received a copy of the GNU General Public License
28462 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28466 + * posix acl operations
28469 +#include <linux/fs.h>
28472 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28474 + struct posix_acl *acl;
28476 + aufs_bindex_t bindex;
28477 + struct inode *h_inode;
28478 + struct super_block *sb;
28481 + sb = inode->i_sb;
28482 + si_read_lock(sb, AuLock_FLUSH);
28483 + ii_read_lock_child(inode);
28484 + if (!(sb->s_flags & SB_POSIXACL))
28487 + bindex = au_ibtop(inode);
28488 + h_inode = au_h_iptr(inode, bindex);
28489 + if (unlikely(!h_inode
28490 + || ((h_inode->i_mode & S_IFMT)
28491 + != (inode->i_mode & S_IFMT)))) {
28492 + err = au_busy_or_stale();
28493 + acl = ERR_PTR(err);
28497 + /* always topmost only */
28498 + acl = get_acl(h_inode, type);
28500 + forget_cached_acl(inode, type);
28502 + set_cached_acl(inode, type, acl);
28505 + ii_read_unlock(inode);
28506 + si_read_unlock(sb);
28508 + AuTraceErrPtr(acl);
28512 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28516 + struct dentry *dentry;
28517 + struct au_sxattr arg = {
28518 + .type = AU_ACL_SET,
28525 + IMustLock(inode);
28527 + if (inode->i_ino == AUFS_ROOT_INO)
28528 + dentry = dget(inode->i_sb->s_root);
28530 + dentry = d_find_alias(inode);
28532 + dentry = d_find_any_alias(inode);
28534 + pr_warn("cannot handle this inode, "
28535 + "please report to aufs-users ML\n");
28541 + ssz = au_sxattr(dentry, inode, &arg);
28542 + /* forget even it if succeeds since the branch might set differently */
28543 + forget_cached_acl(inode, type);
28552 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28553 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28554 +++ linux/fs/aufs/procfs.c 2021-02-22 23:30:37.702680911 +0100
28556 +// SPDX-License-Identifier: GPL-2.0
28558 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28560 + * This program, aufs is free software; you can redistribute it and/or modify
28561 + * it under the terms of the GNU General Public License as published by
28562 + * the Free Software Foundation; either version 2 of the License, or
28563 + * (at your option) any later version.
28565 + * This program is distributed in the hope that it will be useful,
28566 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28567 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28568 + * GNU General Public License for more details.
28570 + * You should have received a copy of the GNU General Public License
28571 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28575 + * procfs interfaces
28578 +#include <linux/proc_fs.h>
28581 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28583 + struct au_sbinfo *sbinfo;
28585 + sbinfo = file->private_data;
28587 + au_plink_maint_leave(sbinfo);
28588 + kobject_put(&sbinfo->si_kobj);
28594 +static void au_procfs_plm_write_clean(struct file *file)
28596 + struct au_sbinfo *sbinfo;
28598 + sbinfo = file->private_data;
28600 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28603 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28606 + struct super_block *sb;
28607 + struct au_sbinfo *sbinfo;
28608 + struct hlist_bl_node *pos;
28611 + if (unlikely(file->private_data))
28615 + /* don't use au_sbilist_lock() here */
28616 + hlist_bl_lock(&au_sbilist);
28617 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28618 + if (id == sysaufs_si_id(sbinfo)) {
28619 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28620 + sb = sbinfo->si_sb;
28623 + hlist_bl_unlock(&au_sbilist);
28626 + if (unlikely(!sb))
28629 + err = au_plink_maint_enter(sb);
28631 + /* keep kobject_get() */
28632 + file->private_data = sbinfo;
28634 + kobject_put(&sbinfo->si_kobj);
28640 + * Accept a valid "si=xxxx" only.
28641 + * Once it is accepted successfully, accept "clean" too.
28643 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28644 + size_t count, loff_t *ppos)
28647 + unsigned long id;
28648 + /* last newline is allowed */
28649 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28652 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28656 + if (unlikely(count > sizeof(buf)))
28659 + err = copy_from_user(buf, ubuf, count);
28660 + if (unlikely(err)) {
28667 + if (!strcmp("clean", buf)) {
28668 + au_procfs_plm_write_clean(file);
28669 + goto out_success;
28670 + } else if (unlikely(strncmp("si=", buf, 3)))
28673 + err = kstrtoul(buf + 3, 16, &id);
28674 + if (unlikely(err))
28677 + err = au_procfs_plm_write_si(file, id);
28678 + if (unlikely(err))
28682 + err = count; /* success */
28687 +static const struct file_operations au_procfs_plm_fop = {
28688 + .write = au_procfs_plm_write,
28689 + .release = au_procfs_plm_release,
28690 + .owner = THIS_MODULE
28693 +/* ---------------------------------------------------------------------- */
28695 +static struct proc_dir_entry *au_procfs_dir;
28697 +void au_procfs_fin(void)
28699 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28700 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28703 +int __init au_procfs_init(void)
28706 + struct proc_dir_entry *entry;
28709 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28710 + if (unlikely(!au_procfs_dir))
28713 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28714 + au_procfs_dir, &au_procfs_plm_fop);
28715 + if (unlikely(!entry))
28719 + goto out; /* success */
28723 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28727 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28728 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28729 +++ linux/fs/aufs/rdu.c 2021-02-22 23:30:37.702680911 +0100
28731 +// SPDX-License-Identifier: GPL-2.0
28733 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28735 + * This program, aufs is free software; you can redistribute it and/or modify
28736 + * it under the terms of the GNU General Public License as published by
28737 + * the Free Software Foundation; either version 2 of the License, or
28738 + * (at your option) any later version.
28740 + * This program is distributed in the hope that it will be useful,
28741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28743 + * GNU General Public License for more details.
28745 + * You should have received a copy of the GNU General Public License
28746 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28750 + * readdir in userspace.
28753 +#include <linux/compat.h>
28754 +#include <linux/fs_stack.h>
28755 +#include <linux/security.h>
28758 +/* bits for struct aufs_rdu.flags */
28759 +#define AuRdu_CALLED 1
28760 +#define AuRdu_CONT (1 << 1)
28761 +#define AuRdu_FULL (1 << 2)
28762 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28763 +#define au_fset_rdu(flags, name) \
28764 + do { (flags) |= AuRdu_##name; } while (0)
28765 +#define au_fclr_rdu(flags, name) \
28766 + do { (flags) &= ~AuRdu_##name; } while (0)
28768 +struct au_rdu_arg {
28769 + struct dir_context ctx;
28770 + struct aufs_rdu *rdu;
28771 + union au_rdu_ent_ul ent;
28772 + unsigned long end;
28774 + struct super_block *sb;
28778 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28779 + loff_t offset, u64 h_ino, unsigned int d_type)
28782 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28783 + struct aufs_rdu *rdu = arg->rdu;
28784 + struct au_rdu_ent ent;
28788 + au_fset_rdu(rdu->cookie.flags, CALLED);
28789 + len = au_rdu_len(nlen);
28790 + if (arg->ent.ul + len < arg->end) {
28792 + ent.bindex = rdu->cookie.bindex;
28793 + ent.type = d_type;
28795 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28796 + ent.type = DT_UNKNOWN;
28798 + /* unnecessary to support mmap_sem since this is a dir */
28800 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28802 + if (copy_to_user(arg->ent.e->name, name, nlen))
28804 + /* the terminating NULL */
28805 + if (__put_user(0, arg->ent.e->name + nlen))
28808 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28809 + arg->ent.ul += len;
28813 + au_fset_rdu(rdu->cookie.flags, FULL);
28815 + rdu->tail = arg->ent;
28819 + /* AuTraceErr(err); */
28823 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28827 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28829 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28830 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28832 + if (unlikely(offset != cookie->h_pos))
28838 + au_fclr_rdu(cookie->flags, CALLED);
28840 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28844 + && au_ftest_rdu(cookie->flags, CALLED)
28845 + && !au_ftest_rdu(cookie->flags, FULL));
28846 + cookie->h_pos = h_file->f_pos;
28853 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28856 + aufs_bindex_t bbot;
28857 + struct au_rdu_arg arg = {
28859 + .actor = au_rdu_fill
28862 + struct dentry *dentry;
28863 + struct inode *inode;
28864 + struct file *h_file;
28865 + struct au_rdu_cookie *cookie = &rdu->cookie;
28867 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
28868 + if (unlikely(err)) {
28874 + rdu->tail = rdu->ent;
28877 + arg.ent = rdu->ent;
28878 + arg.end = arg.ent.ul;
28879 + arg.end += rdu->sz;
28882 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28885 + err = security_file_permission(file, MAY_READ);
28887 + if (unlikely(err))
28890 + dentry = file->f_path.dentry;
28891 + inode = d_inode(dentry);
28892 + inode_lock_shared(inode);
28894 + arg.sb = inode->i_sb;
28895 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28896 + if (unlikely(err))
28898 + err = au_alive_dir(dentry);
28899 + if (unlikely(err))
28901 + /* todo: reval? */
28902 + fi_read_lock(file);
28905 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28906 + && cookie->generation != au_figen(file)))
28911 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28913 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28915 + bbot = au_fbtop(file);
28916 + if (cookie->bindex < bbot)
28917 + cookie->bindex = bbot;
28918 + bbot = au_fbbot_dir(file);
28919 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28920 + for (; !err && cookie->bindex <= bbot;
28921 + cookie->bindex++, cookie->h_pos = 0) {
28922 + h_file = au_hf_dir(file, cookie->bindex);
28926 + au_fclr_rdu(cookie->flags, FULL);
28927 + err = au_rdu_do(h_file, &arg);
28929 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28932 + AuDbg("rent %llu\n", rdu->rent);
28934 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28935 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28936 + au_fset_rdu(cookie->flags, CONT);
28937 + cookie->generation = au_figen(file);
28940 + ii_read_lock_child(inode);
28941 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28942 + ii_read_unlock(inode);
28945 + fi_read_unlock(file);
28947 + si_read_unlock(arg.sb);
28949 + inode_unlock_shared(inode);
28955 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28959 + unsigned long long nent;
28960 + union au_rdu_ent_ul *u;
28961 + struct au_rdu_ent ent;
28962 + struct super_block *sb;
28965 + nent = rdu->nent;
28967 + sb = file->f_path.dentry->d_sb;
28968 + si_read_lock(sb, AuLock_FLUSH);
28969 + while (nent-- > 0) {
28970 + /* unnecessary to support mmap_sem since this is a dir */
28971 + err = copy_from_user(&ent, u->e, sizeof(ent));
28973 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
28974 + if (unlikely(err)) {
28980 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28982 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28984 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28986 + if (unlikely(err)) {
28991 + err = __put_user(ino, &u->e->ino);
28992 + if (unlikely(err)) {
28997 + u->ul += au_rdu_len(ent.nlen);
28999 + si_read_unlock(sb);
29004 +/* ---------------------------------------------------------------------- */
29006 +static int au_rdu_verify(struct aufs_rdu *rdu)
29008 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29009 + "%llu, b%d, 0x%x, g%u}\n",
29010 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29012 + rdu->rent, rdu->shwh, rdu->full,
29013 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29014 + rdu->cookie.generation);
29016 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29020 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29024 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29027 + struct aufs_rdu rdu;
29028 + void __user *p = (void __user *)arg;
29030 + err = copy_from_user(&rdu, p, sizeof(rdu));
29031 + if (unlikely(err)) {
29036 + err = au_rdu_verify(&rdu);
29037 + if (unlikely(err))
29041 + case AUFS_CTL_RDU:
29042 + err = au_rdu(file, &rdu);
29043 + if (unlikely(err))
29046 + e = copy_to_user(p, &rdu, sizeof(rdu));
29047 + if (unlikely(e)) {
29052 + case AUFS_CTL_RDU_INO:
29053 + err = au_rdu_ino(file, &rdu);
29057 + /* err = -ENOTTY; */
29066 +#ifdef CONFIG_COMPAT
29067 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29070 + struct aufs_rdu rdu;
29071 + void __user *p = compat_ptr(arg);
29073 + /* todo: get_user()? */
29074 + err = copy_from_user(&rdu, p, sizeof(rdu));
29075 + if (unlikely(err)) {
29080 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29081 + err = au_rdu_verify(&rdu);
29082 + if (unlikely(err))
29086 + case AUFS_CTL_RDU:
29087 + err = au_rdu(file, &rdu);
29088 + if (unlikely(err))
29091 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29092 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29093 + e = copy_to_user(p, &rdu, sizeof(rdu));
29094 + if (unlikely(e)) {
29099 + case AUFS_CTL_RDU_INO:
29100 + err = au_rdu_ino(file, &rdu);
29104 + /* err = -ENOTTY; */
29113 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29114 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29115 +++ linux/fs/aufs/rwsem.h 2021-02-22 23:30:37.702680911 +0100
29117 +/* SPDX-License-Identifier: GPL-2.0 */
29119 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29121 + * This program, aufs is free software; you can redistribute it and/or modify
29122 + * it under the terms of the GNU General Public License as published by
29123 + * the Free Software Foundation; either version 2 of the License, or
29124 + * (at your option) any later version.
29126 + * This program is distributed in the hope that it will be useful,
29127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29129 + * GNU General Public License for more details.
29131 + * You should have received a copy of the GNU General Public License
29132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29136 + * simple read-write semaphore wrappers
29139 +#ifndef __AUFS_RWSEM_H__
29140 +#define __AUFS_RWSEM_H__
29144 +#include "debug.h"
29146 +/* in the future, the name 'au_rwsem' will be totally gone */
29147 +#define au_rwsem rw_semaphore
29149 +/* to debug easier, do not make them inlined functions */
29150 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29151 +/* rwsem_is_locked() is unusable */
29152 +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \
29154 + && !lockdep_is_held_type(rw, 1))
29155 +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \
29157 + && !lockdep_is_held_type(rw, 0))
29158 +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \
29160 + && !lockdep_is_held(rw))
29161 +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \
29163 + && lockdep_is_held(rw))
29165 +#define au_rw_init(rw) init_rwsem(rw)
29167 +#define au_rw_init_wlock(rw) do { \
29168 + au_rw_init(rw); \
29169 + down_write(rw); \
29172 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29173 + au_rw_init(rw); \
29174 + down_write_nested(rw, lsc); \
29177 +#define au_rw_read_lock(rw) down_read(rw)
29178 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29179 +#define au_rw_read_unlock(rw) up_read(rw)
29180 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29181 +#define au_rw_write_lock(rw) down_write(rw)
29182 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29183 +#define au_rw_write_unlock(rw) up_write(rw)
29184 +/* why is not _nested version defined? */
29185 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29186 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29188 +#endif /* __KERNEL__ */
29189 +#endif /* __AUFS_RWSEM_H__ */
29190 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29191 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29192 +++ linux/fs/aufs/sbinfo.c 2021-02-22 23:30:37.702680911 +0100
29194 +// SPDX-License-Identifier: GPL-2.0
29196 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29198 + * This program, aufs is free software; you can redistribute it and/or modify
29199 + * it under the terms of the GNU General Public License as published by
29200 + * the Free Software Foundation; either version 2 of the License, or
29201 + * (at your option) any later version.
29203 + * This program is distributed in the hope that it will be useful,
29204 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29205 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29206 + * GNU General Public License for more details.
29208 + * You should have received a copy of the GNU General Public License
29209 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29213 + * superblock private data
29216 +#include <linux/iversion.h>
29220 + * they are necessary regardless sysfs is disabled.
29222 +void au_si_free(struct kobject *kobj)
29225 + struct au_sbinfo *sbinfo;
29226 + char *locked __maybe_unused; /* debug only */
29228 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29229 + for (i = 0; i < AuPlink_NHASH; i++)
29230 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29231 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29233 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29234 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29235 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29236 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29238 + dbgaufs_si_fin(sbinfo);
29239 + au_rw_write_lock(&sbinfo->si_rwsem);
29240 + au_br_free(sbinfo);
29241 + au_rw_write_unlock(&sbinfo->si_rwsem);
29243 + au_kfree_try_rcu(sbinfo->si_branch);
29244 + mutex_destroy(&sbinfo->si_xib_mtx);
29245 + AuRwDestroy(&sbinfo->si_rwsem);
29247 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29248 + /* si_nfiles is waited too */
29249 + au_kfree_rcu(sbinfo);
29252 +int au_si_alloc(struct super_block *sb)
29255 + struct au_sbinfo *sbinfo;
29258 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29259 + if (unlikely(!sbinfo))
29262 + /* will be reallocated separately */
29263 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29264 + if (unlikely(!sbinfo->si_branch))
29267 + err = sysaufs_si_init(sbinfo);
29269 + dbgaufs_si_null(sbinfo);
29270 + err = dbgaufs_si_init(sbinfo);
29271 + if (unlikely(err))
29272 + kobject_put(&sbinfo->si_kobj);
29274 + if (unlikely(err))
29277 + au_nwt_init(&sbinfo->si_nowait);
29278 + au_rw_init_wlock(&sbinfo->si_rwsem);
29280 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29281 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29283 + sbinfo->si_bbot = -1;
29284 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29286 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29287 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29288 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29289 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29291 + au_fhsm_init(sbinfo);
29293 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29295 + sbinfo->si_xino_jiffy = jiffies;
29296 + sbinfo->si_xino_expire
29297 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29298 + mutex_init(&sbinfo->si_xib_mtx);
29299 + /* leave si_xib_last_pindex and si_xib_next_bit */
29301 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29303 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29304 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29305 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29306 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29308 + for (i = 0; i < AuPlink_NHASH; i++)
29309 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29310 + init_waitqueue_head(&sbinfo->si_plink_wq);
29311 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29313 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29315 + /* with getattr by default */
29316 + sbinfo->si_iop_array = aufs_iop;
29318 + /* leave other members for sysaufs and si_mnt. */
29319 + sbinfo->si_sb = sb;
29320 + sb->s_fs_info = sbinfo;
29322 + return 0; /* success */
29325 + au_kfree_try_rcu(sbinfo->si_branch);
29327 + au_kfree_rcu(sbinfo);
29332 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29335 + struct au_branch **brp;
29337 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29340 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29341 + if (unlikely(!sz))
29342 + sz = sizeof(*brp);
29343 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29346 + sbinfo->si_branch = brp;
29353 +/* ---------------------------------------------------------------------- */
29355 +unsigned int au_sigen_inc(struct super_block *sb)
29357 + unsigned int gen;
29358 + struct inode *inode;
29360 + SiMustWriteLock(sb);
29362 + gen = ++au_sbi(sb)->si_generation;
29363 + au_update_digen(sb->s_root);
29364 + inode = d_inode(sb->s_root);
29365 + au_update_iigen(inode, /*half*/0);
29366 + inode_inc_iversion(inode);
29370 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29372 + aufs_bindex_t br_id;
29374 + struct au_sbinfo *sbinfo;
29376 + SiMustWriteLock(sb);
29378 + sbinfo = au_sbi(sb);
29379 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29380 + br_id = ++sbinfo->si_last_br_id;
29381 + AuDebugOn(br_id < 0);
29382 + if (br_id && au_br_index(sb, br_id) < 0)
29389 +/* ---------------------------------------------------------------------- */
29391 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29392 +int si_read_lock(struct super_block *sb, int flags)
29397 + if (au_ftest_lock(flags, FLUSH))
29398 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29400 + si_noflush_read_lock(sb);
29401 + err = au_plink_maint(sb, flags);
29402 + if (unlikely(err))
29403 + si_read_unlock(sb);
29408 +int si_write_lock(struct super_block *sb, int flags)
29412 + if (au_ftest_lock(flags, FLUSH))
29413 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29415 + si_noflush_write_lock(sb);
29416 + err = au_plink_maint(sb, flags);
29417 + if (unlikely(err))
29418 + si_write_unlock(sb);
29423 +/* dentry and super_block lock. call at entry point */
29424 +int aufs_read_lock(struct dentry *dentry, int flags)
29427 + struct super_block *sb;
29429 + sb = dentry->d_sb;
29430 + err = si_read_lock(sb, flags);
29431 + if (unlikely(err))
29434 + if (au_ftest_lock(flags, DW))
29435 + di_write_lock_child(dentry);
29437 + di_read_lock_child(dentry, flags);
29439 + if (au_ftest_lock(flags, GEN)) {
29440 + err = au_digen_test(dentry, au_sigen(sb));
29441 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29442 + AuDebugOn(!err && au_dbrange_test(dentry));
29444 + err = au_dbrange_test(dentry);
29445 + if (unlikely(err))
29446 + aufs_read_unlock(dentry, flags);
29453 +void aufs_read_unlock(struct dentry *dentry, int flags)
29455 + if (au_ftest_lock(flags, DW))
29456 + di_write_unlock(dentry);
29458 + di_read_unlock(dentry, flags);
29459 + si_read_unlock(dentry->d_sb);
29462 +void aufs_write_lock(struct dentry *dentry)
29464 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29465 + di_write_lock_child(dentry);
29468 +void aufs_write_unlock(struct dentry *dentry)
29470 + di_write_unlock(dentry);
29471 + si_write_unlock(dentry->d_sb);
29474 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29477 + unsigned int sigen;
29478 + struct super_block *sb;
29481 + err = si_read_lock(sb, flags);
29482 + if (unlikely(err))
29485 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29487 + if (au_ftest_lock(flags, GEN)) {
29488 + sigen = au_sigen(sb);
29489 + err = au_digen_test(d1, sigen);
29490 + AuDebugOn(!err && au_dbrange_test(d1));
29492 + err = au_digen_test(d2, sigen);
29493 + AuDebugOn(!err && au_dbrange_test(d2));
29495 + if (unlikely(err))
29496 + aufs_read_and_write_unlock2(d1, d2);
29503 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29505 + di_write_unlock2(d1, d2);
29506 + si_read_unlock(d1->d_sb);
29508 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29509 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29510 +++ linux/fs/aufs/super.c 2021-02-22 23:30:37.702680911 +0100
29512 +// SPDX-License-Identifier: GPL-2.0
29514 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29516 + * This program, aufs is free software; you can redistribute it and/or modify
29517 + * it under the terms of the GNU General Public License as published by
29518 + * the Free Software Foundation; either version 2 of the License, or
29519 + * (at your option) any later version.
29521 + * This program is distributed in the hope that it will be useful,
29522 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29523 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29524 + * GNU General Public License for more details.
29526 + * You should have received a copy of the GNU General Public License
29527 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29531 + * mount and super_block operations
29534 +#include <linux/iversion.h>
29535 +#include <linux/mm.h>
29536 +#include <linux/seq_file.h>
29537 +#include <linux/statfs.h>
29538 +#include <linux/vmalloc.h>
29542 + * super_operations
29544 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29546 + struct au_icntnr *c;
29548 + c = au_cache_alloc_icntnr();
29550 + au_icntnr_init(c);
29551 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29552 + c->iinfo.ii_hinode = NULL;
29553 + return &c->vfs_inode;
29558 +static void aufs_destroy_inode_cb(struct rcu_head *head)
29560 + struct inode *inode = container_of(head, struct inode, i_rcu);
29562 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29565 +static void aufs_destroy_inode(struct inode *inode)
29567 + if (!au_is_bad_inode(inode))
29568 + au_iinfo_fin(inode);
29569 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
29572 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29574 + struct inode *inode;
29577 + inode = iget_locked(sb, ino);
29578 + if (unlikely(!inode)) {
29579 + inode = ERR_PTR(-ENOMEM);
29582 + if (!(inode->i_state & I_NEW))
29585 + err = au_xigen_new(inode);
29587 + err = au_iinfo_init(inode);
29589 + inode_inc_iversion(inode);
29591 + iget_failed(inode);
29592 + inode = ERR_PTR(err);
29596 + /* never return NULL */
29597 + AuDebugOn(!inode);
29598 + AuTraceErrPtr(inode);
29602 +/* lock free root dinfo */
29603 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29606 + aufs_bindex_t bindex, bbot;
29607 + struct path path;
29608 + struct au_hdentry *hdp;
29609 + struct au_branch *br;
29610 + au_br_perm_str_t perm;
29613 + bbot = au_sbbot(sb);
29615 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29616 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29617 + br = au_sbr(sb, bindex);
29618 + path.mnt = au_br_mnt(br);
29619 + path.dentry = hdp->hd_dentry;
29620 + err = au_seq_path(seq, &path);
29622 + au_optstr_br_perm(&perm, br->br_perm);
29623 + seq_printf(seq, "=%s", perm.a);
29624 + if (bindex != bbot)
29625 + seq_putc(seq, ':');
29628 + if (unlikely(err || seq_has_overflowed(seq)))
29634 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29635 + const char *append)
29640 + while (*pat != ':')
29643 + strcpy(p, append);
29644 + AuDebugOn(strlen(fmt) >= len);
29647 +static void au_show_wbr_create(struct seq_file *m, int v,
29648 + struct au_sbinfo *sbinfo)
29652 + struct au_wbr_mfs *mfs;
29654 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29656 + seq_puts(m, ",create=");
29657 + pat = au_optstr_wbr_create(v);
29658 + mfs = &sbinfo->si_wbr_mfs;
29660 + case AuWbrCreate_TDP:
29661 + case AuWbrCreate_RR:
29662 + case AuWbrCreate_MFS:
29663 + case AuWbrCreate_PMFS:
29664 + seq_puts(m, pat);
29666 + case AuWbrCreate_MFSRR:
29667 + case AuWbrCreate_TDMFS:
29668 + case AuWbrCreate_PMFSRR:
29669 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29670 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29672 + case AuWbrCreate_MFSV:
29673 + case AuWbrCreate_PMFSV:
29674 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29675 + seq_printf(m, fmt,
29676 + jiffies_to_msecs(mfs->mfs_expire)
29679 + case AuWbrCreate_MFSRRV:
29680 + case AuWbrCreate_TDMFSV:
29681 + case AuWbrCreate_PMFSRRV:
29682 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29683 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29684 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29691 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29693 +#ifdef CONFIG_SYSFS
29697 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29698 + aufs_bindex_t bindex, brid;
29699 + struct qstr *name;
29701 + struct dentry *d, *h_root;
29702 + struct au_branch *br;
29704 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29707 + f = au_sbi(sb)->si_xib;
29711 + /* stop printing the default xino path on the first writable branch */
29713 + bindex = au_xi_root(sb, f->f_path.dentry);
29714 + if (bindex >= 0) {
29715 + br = au_sbr_sb(sb, bindex);
29716 + h_root = au_br_dentry(br);
29719 + d = f->f_path.dentry;
29720 + name = &d->d_name;
29721 + /* safe ->d_parent because the file is unlinked */
29722 + if (d->d_parent == h_root
29723 + && name->len == len
29724 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29727 + seq_puts(seq, ",xino=");
29728 + err = au_xino_path(seq, f);
29735 +/* seq_file will re-call me in case of too long string */
29736 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29739 + unsigned int mnt_flags, v;
29740 + struct super_block *sb;
29741 + struct au_sbinfo *sbinfo;
29743 +#define AuBool(name, str) do { \
29744 + v = au_opt_test(mnt_flags, name); \
29745 + if (v != au_opt_test(AuOpt_Def, name)) \
29746 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29749 +#define AuStr(name, str) do { \
29750 + v = mnt_flags & AuOptMask_##name; \
29751 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29752 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29755 +#define AuUInt(name, str, val) do { \
29756 + if (val != AUFS_##name##_DEF) \
29757 + seq_printf(m, "," #str "=%u", val); \
29760 + sb = dentry->d_sb;
29761 + if (sb->s_flags & SB_POSIXACL)
29762 + seq_puts(m, ",acl");
29763 +#if 0 /* reserved for future use */
29764 + if (sb->s_flags & SB_I_VERSION)
29765 + seq_puts(m, ",i_version");
29768 + /* lock free root dinfo */
29769 + si_noflush_read_lock(sb);
29770 + sbinfo = au_sbi(sb);
29771 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29773 + mnt_flags = au_mntflags(sb);
29774 + if (au_opt_test(mnt_flags, XINO)) {
29775 + err = au_show_xino(m, sb);
29776 + if (unlikely(err))
29779 + seq_puts(m, ",noxino");
29781 + AuBool(TRUNC_XINO, trunc_xino);
29782 + AuStr(UDBA, udba);
29783 + AuBool(SHWH, shwh);
29784 + AuBool(PLINK, plink);
29785 + AuBool(DIO, dio);
29786 + AuBool(DIRPERM1, dirperm1);
29788 + v = sbinfo->si_wbr_create;
29789 + if (v != AuWbrCreate_Def)
29790 + au_show_wbr_create(m, v, sbinfo);
29792 + v = sbinfo->si_wbr_copyup;
29793 + if (v != AuWbrCopyup_Def)
29794 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29796 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29797 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29798 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29800 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29802 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29803 + AuUInt(RDCACHE, rdcache, v);
29805 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29806 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29808 + au_fhsm_show(m, sbinfo);
29810 + AuBool(DIRREN, dirren);
29811 + AuBool(SUM, sum);
29812 + /* AuBool(SUM_W, wsum); */
29813 + AuBool(WARN_PERM, warn_perm);
29814 + AuBool(VERBOSE, verbose);
29817 + /* be sure to print "br:" last */
29818 + if (!sysaufs_brs) {
29819 + seq_puts(m, ",br:");
29820 + au_show_brs(m, sb);
29822 + si_read_unlock(sb);
29830 +/* ---------------------------------------------------------------------- */
29832 +/* sum mode which returns the summation for statfs(2) */
29834 +static u64 au_add_till_max(u64 a, u64 b)
29842 + return ULLONG_MAX;
29845 +static u64 au_mul_till_max(u64 a, long mul)
29853 + return ULLONG_MAX;
29856 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29859 + long bsize, factor;
29860 + u64 blocks, bfree, bavail, files, ffree;
29861 + aufs_bindex_t bbot, bindex, i;
29862 + unsigned char shared;
29863 + struct path h_path;
29864 + struct super_block *h_sb;
29867 + bsize = LONG_MAX;
29873 + bbot = au_sbbot(sb);
29874 + for (bindex = 0; bindex <= bbot; bindex++) {
29875 + h_path.mnt = au_sbr_mnt(sb, bindex);
29876 + h_sb = h_path.mnt->mnt_sb;
29878 + for (i = 0; !shared && i < bindex; i++)
29879 + shared = (au_sbr_sb(sb, i) == h_sb);
29883 + /* sb->s_root for NFS is unreliable */
29884 + h_path.dentry = h_path.mnt->mnt_root;
29885 + err = vfs_statfs(&h_path, buf);
29886 + if (unlikely(err))
29889 + if (bsize > buf->f_bsize) {
29891 + * we will reduce bsize, so we have to expand blocks
29892 + * etc. to match them again
29894 + factor = (bsize / buf->f_bsize);
29895 + blocks = au_mul_till_max(blocks, factor);
29896 + bfree = au_mul_till_max(bfree, factor);
29897 + bavail = au_mul_till_max(bavail, factor);
29898 + bsize = buf->f_bsize;
29901 + factor = (buf->f_bsize / bsize);
29902 + blocks = au_add_till_max(blocks,
29903 + au_mul_till_max(buf->f_blocks, factor));
29904 + bfree = au_add_till_max(bfree,
29905 + au_mul_till_max(buf->f_bfree, factor));
29906 + bavail = au_add_till_max(bavail,
29907 + au_mul_till_max(buf->f_bavail, factor));
29908 + files = au_add_till_max(files, buf->f_files);
29909 + ffree = au_add_till_max(ffree, buf->f_ffree);
29912 + buf->f_bsize = bsize;
29913 + buf->f_blocks = blocks;
29914 + buf->f_bfree = bfree;
29915 + buf->f_bavail = bavail;
29916 + buf->f_files = files;
29917 + buf->f_ffree = ffree;
29918 + buf->f_frsize = 0;
29924 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29927 + struct path h_path;
29928 + struct super_block *sb;
29930 + /* lock free root dinfo */
29931 + sb = dentry->d_sb;
29932 + si_noflush_read_lock(sb);
29933 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29934 + /* sb->s_root for NFS is unreliable */
29935 + h_path.mnt = au_sbr_mnt(sb, 0);
29936 + h_path.dentry = h_path.mnt->mnt_root;
29937 + err = vfs_statfs(&h_path, buf);
29939 + err = au_statfs_sum(sb, buf);
29940 + si_read_unlock(sb);
29943 + buf->f_type = AUFS_SUPER_MAGIC;
29944 + buf->f_namelen = AUFS_MAX_NAMELEN;
29945 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29947 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29952 +/* ---------------------------------------------------------------------- */
29954 +static int aufs_sync_fs(struct super_block *sb, int wait)
29957 + aufs_bindex_t bbot, bindex;
29958 + struct au_branch *br;
29959 + struct super_block *h_sb;
29962 + si_noflush_read_lock(sb);
29963 + bbot = au_sbbot(sb);
29964 + for (bindex = 0; bindex <= bbot; bindex++) {
29965 + br = au_sbr(sb, bindex);
29966 + if (!au_br_writable(br->br_perm))
29969 + h_sb = au_sbr_sb(sb, bindex);
29970 + e = vfsub_sync_filesystem(h_sb, wait);
29971 + if (unlikely(e && !err))
29973 + /* go on even if an error happens */
29975 + si_read_unlock(sb);
29980 +/* ---------------------------------------------------------------------- */
29982 +/* final actions when unmounting a file system */
29983 +static void aufs_put_super(struct super_block *sb)
29985 + struct au_sbinfo *sbinfo;
29987 + sbinfo = au_sbi(sb);
29989 + kobject_put(&sbinfo->si_kobj);
29992 +/* ---------------------------------------------------------------------- */
29994 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29995 + struct super_block *sb, void *arg)
29998 + unsigned long long n, sz;
30005 + if (*hint > ULLONG_MAX / sizeof(array)) {
30006 + array = ERR_PTR(-EMFILE);
30007 + pr_err("hint %llu\n", *hint);
30011 + sz = sizeof(array) * *hint;
30012 + array = kzalloc(sz, GFP_NOFS);
30013 + if (unlikely(!array))
30014 + array = vzalloc(sz);
30015 + if (unlikely(!array)) {
30016 + array = ERR_PTR(-ENOMEM);
30020 + n = cb(sb, array, *hint, arg);
30021 + AuDebugOn(n > *hint);
30028 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30029 + unsigned long long max __maybe_unused,
30032 + unsigned long long n;
30033 + struct inode **p, *inode;
30034 + struct list_head *head;
30039 + spin_lock(&sb->s_inode_list_lock);
30040 + list_for_each_entry(inode, head, i_sb_list) {
30041 + if (!au_is_bad_inode(inode)
30042 + && au_ii(inode)->ii_btop >= 0) {
30043 + spin_lock(&inode->i_lock);
30044 + if (atomic_read(&inode->i_count)) {
30048 + AuDebugOn(n > max);
30050 + spin_unlock(&inode->i_lock);
30053 + spin_unlock(&sb->s_inode_list_lock);
30058 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30060 + struct au_sbinfo *sbi;
30062 + sbi = au_sbi(sb);
30063 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30064 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30067 +void au_iarray_free(struct inode **a, unsigned long long max)
30069 + unsigned long long ull;
30071 + for (ull = 0; ull < max; ull++)
30076 +/* ---------------------------------------------------------------------- */
30079 + * refresh dentry and inode at remount time.
30081 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30082 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30083 + struct dentry *parent)
30087 + di_write_lock_child(dentry);
30088 + di_read_lock_parent(parent, AuLock_IR);
30089 + err = au_refresh_dentry(dentry, parent);
30090 + if (!err && dir_flags)
30091 + au_hn_reset(d_inode(dentry), dir_flags);
30092 + di_read_unlock(parent, AuLock_IR);
30093 + di_write_unlock(dentry);
30098 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30099 + struct au_sbinfo *sbinfo,
30100 + const unsigned int dir_flags, unsigned int do_idop)
30103 + struct dentry *parent;
30106 + parent = dget_parent(dentry);
30107 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30108 + if (d_really_is_positive(dentry)) {
30109 + if (!d_is_dir(dentry))
30110 + err = au_do_refresh(dentry, /*dir_flags*/0,
30113 + err = au_do_refresh(dentry, dir_flags, parent);
30114 + if (unlikely(err))
30115 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30118 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30119 + AuDbgDentry(dentry);
30125 + au_refresh_dop(dentry, /*force_reval*/0);
30127 + au_refresh_dop(dentry, /*force_reval*/1);
30133 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30135 + int err, i, j, ndentry, e;
30136 + unsigned int sigen;
30137 + struct au_dcsub_pages dpages;
30138 + struct au_dpage *dpage;
30139 + struct dentry **dentries, *d;
30140 + struct au_sbinfo *sbinfo;
30141 + struct dentry *root = sb->s_root;
30142 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30145 + au_refresh_dop(root, /*force_reval*/0);
30147 + err = au_dpages_init(&dpages, GFP_NOFS);
30148 + if (unlikely(err))
30150 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30151 + if (unlikely(err))
30154 + sigen = au_sigen(sb);
30155 + sbinfo = au_sbi(sb);
30156 + for (i = 0; i < dpages.ndpage; i++) {
30157 + dpage = dpages.dpages + i;
30158 + dentries = dpage->dentries;
30159 + ndentry = dpage->ndentry;
30160 + for (j = 0; j < ndentry; j++) {
30162 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30164 + if (unlikely(e && !err))
30166 + /* go on even err */
30171 + au_dpages_free(&dpages);
30176 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30179 + unsigned int sigen;
30180 + unsigned long long max, ull;
30181 + struct inode *inode, **array;
30183 + array = au_iarray_alloc(sb, &max);
30184 + err = PTR_ERR(array);
30185 + if (IS_ERR(array))
30189 + sigen = au_sigen(sb);
30190 + for (ull = 0; ull < max; ull++) {
30191 + inode = array[ull];
30192 + if (unlikely(!inode))
30196 + ii_write_lock_child(inode);
30197 + if (au_iigen(inode, NULL) != sigen) {
30198 + e = au_refresh_hinode_self(inode);
30199 + if (unlikely(e)) {
30200 + au_refresh_iop(inode, /*force_getattr*/1);
30201 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30204 + /* go on even if err */
30207 + if (!e && do_idop)
30208 + au_refresh_iop(inode, /*force_getattr*/0);
30209 + ii_write_unlock(inode);
30212 + au_iarray_free(array, max);
30218 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30221 + unsigned int udba;
30222 + aufs_bindex_t bindex, bbot;
30223 + struct dentry *root;
30224 + struct inode *inode;
30225 + struct au_branch *br;
30226 + struct au_sbinfo *sbi;
30228 + au_sigen_inc(sb);
30229 + sbi = au_sbi(sb);
30230 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30232 + root = sb->s_root;
30233 + DiMustNoWaiters(root);
30234 + inode = d_inode(root);
30235 + IiMustNoWaiters(inode);
30237 + udba = au_opt_udba(sb);
30238 + bbot = au_sbbot(sb);
30239 + for (bindex = 0; bindex <= bbot; bindex++) {
30240 + br = au_sbr(sb, bindex);
30241 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30242 + if (unlikely(err))
30243 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30245 + /* go on even if err */
30247 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30250 + if (au_ftest_si(sbi, NO_DREVAL)) {
30251 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30252 + sb->s_d_op = &aufs_dop_noreval;
30253 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30254 + sbi->si_iop_array = aufs_iop_nogetattr;
30256 + AuDebugOn(sb->s_d_op == &aufs_dop);
30257 + sb->s_d_op = &aufs_dop;
30258 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30259 + sbi->si_iop_array = aufs_iop;
30261 + pr_info("reset to %ps and %ps\n",
30262 + sb->s_d_op, sbi->si_iop_array);
30265 + di_write_unlock(root);
30266 + err = au_refresh_d(sb, do_idop);
30267 + e = au_refresh_i(sb, do_idop);
30268 + if (unlikely(e && !err))
30270 + /* aufs_write_lock() calls ..._child() */
30271 + di_write_lock_child(root);
30273 + au_cpup_attr_all(inode, /*force*/1);
30275 + if (unlikely(err))
30276 + AuIOErr("refresh failed, ignored, %d\n", err);
30279 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30280 +static int cvt_err(int err)
30294 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30297 + unsigned int mntflags;
30298 + struct au_opts opts = {
30301 + struct dentry *root;
30302 + struct inode *inode;
30303 + struct au_sbinfo *sbinfo;
30306 + root = sb->s_root;
30307 + if (!data || !*data) {
30308 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30310 + di_write_lock_child(root);
30311 + err = au_opts_verify(sb, *flags, /*pending*/0);
30312 + aufs_write_unlock(root);
30318 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30319 + if (unlikely(!opts.opt))
30321 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30322 + opts.flags = AuOpts_REMOUNT;
30323 + opts.sb_flags = *flags;
30325 + /* parse it before aufs lock */
30326 + err = au_opts_parse(sb, data, &opts);
30327 + if (unlikely(err))
30330 + sbinfo = au_sbi(sb);
30331 + inode = d_inode(root);
30332 + inode_lock(inode);
30333 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30334 + if (unlikely(err))
30336 + di_write_lock_child(root);
30338 + /* au_opts_remount() may return an error */
30339 + err = au_opts_remount(sb, &opts);
30340 + au_opts_free(&opts);
30342 + if (au_ftest_opts(opts.flags, REFRESH))
30343 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30345 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30346 + mntflags = au_mntflags(sb);
30347 + do_dx = !!au_opt_test(mntflags, DIO);
30348 + au_dy_arefresh(do_dx);
30351 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30352 + aufs_write_unlock(root);
30355 + inode_unlock(inode);
30357 + free_page((unsigned long)opts.opt);
30359 + err = cvt_err(err);
30364 +static const struct super_operations aufs_sop = {
30365 + .alloc_inode = aufs_alloc_inode,
30366 + .destroy_inode = aufs_destroy_inode,
30367 + /* always deleting, no clearing */
30368 + .drop_inode = generic_delete_inode,
30369 + .show_options = aufs_show_options,
30370 + .statfs = aufs_statfs,
30371 + .put_super = aufs_put_super,
30372 + .sync_fs = aufs_sync_fs,
30373 + .remount_fs = aufs_remount_fs
30376 +/* ---------------------------------------------------------------------- */
30378 +static int alloc_root(struct super_block *sb)
30381 + struct inode *inode;
30382 + struct dentry *root;
30385 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30386 + err = PTR_ERR(inode);
30387 + if (IS_ERR(inode))
30390 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30391 + inode->i_fop = &aufs_dir_fop;
30392 + inode->i_mode = S_IFDIR;
30393 + set_nlink(inode, 2);
30394 + unlock_new_inode(inode);
30396 + root = d_make_root(inode);
30397 + if (unlikely(!root))
30399 + err = PTR_ERR(root);
30400 + if (IS_ERR(root))
30403 + err = au_di_init(root);
30405 + sb->s_root = root;
30406 + return 0; /* success */
30414 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30415 + int silent __maybe_unused)
30418 + struct au_opts opts = {
30421 + struct au_sbinfo *sbinfo;
30422 + struct dentry *root;
30423 + struct inode *inode;
30424 + char *arg = raw_data;
30426 + if (unlikely(!arg || !*arg)) {
30428 + pr_err("no arg\n");
30433 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30434 + if (unlikely(!opts.opt))
30436 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30437 + opts.sb_flags = sb->s_flags;
30439 + err = au_si_alloc(sb);
30440 + if (unlikely(err))
30442 + sbinfo = au_sbi(sb);
30444 + /* all timestamps always follow the ones on the branch */
30445 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30446 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30447 + sb->s_op = &aufs_sop;
30448 + sb->s_d_op = &aufs_dop;
30449 + sb->s_magic = AUFS_SUPER_MAGIC;
30450 + sb->s_maxbytes = 0;
30451 + sb->s_stack_depth = 1;
30452 + au_export_init(sb);
30453 + au_xattr_init(sb);
30455 + err = alloc_root(sb);
30456 + if (unlikely(err)) {
30457 + si_write_unlock(sb);
30460 + root = sb->s_root;
30461 + inode = d_inode(root);
30464 + * actually we can parse options regardless aufs lock here.
30465 + * but at remount time, parsing must be done before aufs lock.
30466 + * so we follow the same rule.
30468 + ii_write_lock_parent(inode);
30469 + aufs_write_unlock(root);
30470 + err = au_opts_parse(sb, arg, &opts);
30471 + if (unlikely(err))
30474 + /* lock vfs_inode first, then aufs. */
30475 + inode_lock(inode);
30476 + aufs_write_lock(root);
30477 + err = au_opts_mount(sb, &opts);
30478 + au_opts_free(&opts);
30479 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30480 + sb->s_d_op = &aufs_dop_noreval;
30481 + pr_info("%ps\n", sb->s_d_op);
30482 + au_refresh_dop(root, /*force_reval*/0);
30483 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30484 + au_refresh_iop(inode, /*force_getattr*/0);
30486 + aufs_write_unlock(root);
30487 + inode_unlock(inode);
30489 + goto out_opts; /* success */
30493 + sb->s_root = NULL;
30495 + kobject_put(&sbinfo->si_kobj);
30496 + sb->s_fs_info = NULL;
30498 + free_page((unsigned long)opts.opt);
30501 + err = cvt_err(err);
30506 +/* ---------------------------------------------------------------------- */
30508 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30509 + const char *dev_name __maybe_unused,
30512 + struct dentry *root;
30514 + /* all timestamps always follow the ones on the branch */
30515 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30516 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30517 + if (IS_ERR(root))
30520 + au_sbilist_add(root->d_sb);
30526 +static void aufs_kill_sb(struct super_block *sb)
30528 + struct au_sbinfo *sbinfo;
30530 + sbinfo = au_sbi(sb);
30532 + au_sbilist_del(sb);
30533 + aufs_write_lock(sb->s_root);
30535 + if (sbinfo->si_wbr_create_ops->fin)
30536 + sbinfo->si_wbr_create_ops->fin(sb);
30537 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30538 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30539 + au_remount_refresh(sb, /*do_idop*/0);
30541 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30542 + au_plink_put(sb, /*verbose*/1);
30544 + au_dr_opt_flush(sb);
30545 + sbinfo->si_sb = NULL;
30546 + aufs_write_unlock(sb->s_root);
30547 + au_nwt_flush(&sbinfo->si_nowait);
30549 + kill_anon_super(sb);
30552 +struct file_system_type aufs_fs_type = {
30553 + .name = AUFS_FSTYPE,
30554 + /* a race between rename and others */
30555 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30556 + .mount = aufs_mount,
30557 + .kill_sb = aufs_kill_sb,
30558 + /* no need to __module_get() and module_put(). */
30559 + .owner = THIS_MODULE,
30561 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30562 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30563 +++ linux/fs/aufs/super.h 2021-02-22 23:30:37.702680911 +0100
30565 +/* SPDX-License-Identifier: GPL-2.0 */
30567 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30569 + * This program, aufs is free software; you can redistribute it and/or modify
30570 + * it under the terms of the GNU General Public License as published by
30571 + * the Free Software Foundation; either version 2 of the License, or
30572 + * (at your option) any later version.
30574 + * This program is distributed in the hope that it will be useful,
30575 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30576 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30577 + * GNU General Public License for more details.
30579 + * You should have received a copy of the GNU General Public License
30580 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30584 + * super_block operations
30587 +#ifndef __AUFS_SUPER_H__
30588 +#define __AUFS_SUPER_H__
30592 +#include <linux/fs.h>
30593 +#include <linux/kobject.h>
30596 +#include "rwsem.h"
30599 +/* policies to select one among multiple writable branches */
30600 +struct au_wbr_copyup_operations {
30601 + int (*copyup)(struct dentry *dentry);
30604 +#define AuWbr_DIR 1 /* target is a dir */
30605 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30607 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30608 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30609 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30611 +struct au_wbr_create_operations {
30612 + int (*create)(struct dentry *dentry, unsigned int flags);
30613 + int (*init)(struct super_block *sb);
30614 + int (*fin)(struct super_block *sb);
30617 +struct au_wbr_mfs {
30618 + struct mutex mfs_lock; /* protect this structure */
30619 + unsigned long mfs_jiffy;
30620 + unsigned long mfs_expire;
30621 + aufs_bindex_t mfs_bindex;
30623 + unsigned long long mfsrr_bytes;
30624 + unsigned long long mfsrr_watermark;
30627 +#define AuPlink_NHASH 100
30628 +static inline int au_plink_hash(ino_t ino)
30630 + return ino % AuPlink_NHASH;
30633 +/* File-based Hierarchical Storage Management */
30635 +#ifdef CONFIG_AUFS_FHSM
30636 + /* allow only one process who can receive the notification */
30637 + spinlock_t fhsm_spin;
30639 + wait_queue_head_t fhsm_wqh;
30640 + atomic_t fhsm_readable;
30642 + /* these are protected by si_rwsem */
30643 + unsigned long fhsm_expire;
30644 + aufs_bindex_t fhsm_bottom;
30649 +struct au_sbinfo {
30650 + /* nowait tasks in the system-wide workqueue */
30651 + struct au_nowait_tasks si_nowait;
30654 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30655 + * rwsem for au_sbinfo is necessary.
30657 + struct au_rwsem si_rwsem;
30660 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30663 + au_lcnt_t si_ninodes, si_nfiles;
30665 + /* branch management */
30666 + unsigned int si_generation;
30668 + /* see AuSi_ flags */
30669 + unsigned char au_si_status;
30671 + aufs_bindex_t si_bbot;
30673 + /* dirty trick to keep br_id plus */
30674 + unsigned int si_last_br_id :
30675 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30676 + struct au_branch **si_branch;
30678 + /* policy to select a writable branch */
30679 + unsigned char si_wbr_copyup;
30680 + unsigned char si_wbr_create;
30681 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30682 + struct au_wbr_create_operations *si_wbr_create_ops;
30684 + /* round robin */
30685 + atomic_t si_wbr_rr_next;
30687 + /* most free space */
30688 + struct au_wbr_mfs si_wbr_mfs;
30690 + /* File-based Hierarchical Storage Management */
30691 + struct au_fhsm si_fhsm;
30693 + /* mount flags */
30694 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30695 + unsigned int si_mntflags;
30697 + /* external inode number (bitmap and translation table) */
30698 + vfs_readf_t si_xread;
30699 + vfs_writef_t si_xwrite;
30700 + loff_t si_ximaxent; /* max entries in a xino */
30702 + struct file *si_xib;
30703 + struct mutex si_xib_mtx; /* protect xib members */
30704 + unsigned long *si_xib_buf;
30705 + unsigned long si_xib_last_pindex;
30706 + int si_xib_next_bit;
30708 + unsigned long si_xino_jiffy;
30709 + unsigned long si_xino_expire;
30710 + /* reserved for future use */
30711 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30713 +#ifdef CONFIG_AUFS_EXPORT
30714 + /* i_generation */
30715 + /* todo: make xigen file an array to support many inode numbers */
30716 + struct file *si_xigen;
30717 + atomic_t si_xigen_next;
30720 + /* dirty trick to support atomic_open */
30721 + struct hlist_bl_head si_aopen;
30723 + /* vdir parameters */
30724 + unsigned long si_rdcache; /* max cache time in jiffies */
30725 + unsigned int si_rdblk; /* deblk size */
30726 + unsigned int si_rdhash; /* hash size */
30729 + * If the number of whiteouts are larger than si_dirwh, leave all of
30730 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30731 + * future fsck.aufs or kernel thread will remove them later.
30732 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30734 + unsigned int si_dirwh;
30736 + /* pseudo_link list */
30737 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30738 + wait_queue_head_t si_plink_wq;
30739 + spinlock_t si_plink_maint_lock;
30740 + pid_t si_plink_maint_pid;
30743 + struct hlist_bl_head si_files;
30745 + /* with/without getattr, brother of sb->s_d_op */
30746 + const struct inode_operations *si_iop_array;
30749 + * sysfs and lifetime management.
30750 + * this is not a small structure and it may be a waste of memory in case
30751 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30752 + * but using sysfs is majority.
30754 + struct kobject si_kobj;
30755 +#ifdef CONFIG_DEBUG_FS
30756 + struct dentry *si_dbgaufs;
30757 + struct dentry *si_dbgaufs_plink;
30758 + struct dentry *si_dbgaufs_xib;
30759 +#ifdef CONFIG_AUFS_EXPORT
30760 + struct dentry *si_dbgaufs_xigen;
30764 +#ifdef CONFIG_AUFS_SBILIST
30765 + struct hlist_bl_node si_list;
30768 + /* dirty, necessary for unmounting, sysfs and sysrq */
30769 + struct super_block *si_sb;
30772 +/* sbinfo status flags */
30774 + * set true when refresh_dirs() failed at remount time.
30775 + * then try refreshing dirs at access time again.
30776 + * if it is false, refreshing dirs at access time is unnecessary
30778 +#define AuSi_FAILED_REFRESH_DIR 1
30779 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30780 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30782 +#ifndef CONFIG_AUFS_FHSM
30784 +#define AuSi_FHSM 0
30787 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30788 + unsigned int flag)
30790 + AuRwMustAnyLock(&sbi->si_rwsem);
30791 + return sbi->au_si_status & flag;
30793 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30794 +#define au_fset_si(sbinfo, name) do { \
30795 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30796 + (sbinfo)->au_si_status |= AuSi_##name; \
30798 +#define au_fclr_si(sbinfo, name) do { \
30799 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30800 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30803 +/* ---------------------------------------------------------------------- */
30805 +/* policy to select one among writable branches */
30806 +#define AuWbrCopyup(sbinfo, ...) \
30807 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30808 +#define AuWbrCreate(sbinfo, ...) \
30809 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30811 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30812 +#define AuLock_DW 1 /* write-lock dentry */
30813 +#define AuLock_IR (1 << 1) /* read-lock inode */
30814 +#define AuLock_IW (1 << 2) /* write-lock inode */
30815 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30816 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30817 + /* except RENAME_EXCHANGE */
30818 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30819 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30820 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30821 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30822 +#define au_fset_lock(flags, name) \
30823 + do { (flags) |= AuLock_##name; } while (0)
30824 +#define au_fclr_lock(flags, name) \
30825 + do { (flags) &= ~AuLock_##name; } while (0)
30827 +/* ---------------------------------------------------------------------- */
30830 +extern struct file_system_type aufs_fs_type;
30831 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30832 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30833 + unsigned long long max, void *arg);
30834 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30835 + struct super_block *sb, void *arg);
30836 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30837 +void au_iarray_free(struct inode **a, unsigned long long max);
30840 +void au_si_free(struct kobject *kobj);
30841 +int au_si_alloc(struct super_block *sb);
30842 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30844 +unsigned int au_sigen_inc(struct super_block *sb);
30845 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30847 +int si_read_lock(struct super_block *sb, int flags);
30848 +int si_write_lock(struct super_block *sb, int flags);
30849 +int aufs_read_lock(struct dentry *dentry, int flags);
30850 +void aufs_read_unlock(struct dentry *dentry, int flags);
30851 +void aufs_write_lock(struct dentry *dentry);
30852 +void aufs_write_unlock(struct dentry *dentry);
30853 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30854 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30856 +/* wbr_policy.c */
30857 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30858 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30859 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30860 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30861 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30864 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30866 +#ifdef CONFIG_AUFS_FHSM
30869 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30873 + spin_lock(&fhsm->fhsm_spin);
30874 + pid = fhsm->fhsm_pid;
30875 + spin_unlock(&fhsm->fhsm_spin);
30880 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30881 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30882 +int au_fhsm_fd(struct super_block *sb, int oflags);
30883 +int au_fhsm_br_alloc(struct au_branch *br);
30884 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30885 +void au_fhsm_fin(struct super_block *sb);
30886 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30887 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30888 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30890 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30892 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30893 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30894 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30895 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30896 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30897 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30898 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30899 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30900 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30903 +/* ---------------------------------------------------------------------- */
30905 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30907 + return sb->s_fs_info;
30910 +/* ---------------------------------------------------------------------- */
30912 +#ifdef CONFIG_AUFS_EXPORT
30913 +int au_test_nfsd(void);
30914 +void au_export_init(struct super_block *sb);
30915 +void au_xigen_inc(struct inode *inode);
30916 +int au_xigen_new(struct inode *inode);
30917 +int au_xigen_set(struct super_block *sb, struct path *path);
30918 +void au_xigen_clr(struct super_block *sb);
30920 +static inline int au_busy_or_stale(void)
30922 + if (!au_test_nfsd())
30927 +AuStubInt0(au_test_nfsd, void)
30928 +AuStubVoid(au_export_init, struct super_block *sb)
30929 +AuStubVoid(au_xigen_inc, struct inode *inode)
30930 +AuStubInt0(au_xigen_new, struct inode *inode)
30931 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30932 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30933 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30934 +#endif /* CONFIG_AUFS_EXPORT */
30936 +/* ---------------------------------------------------------------------- */
30938 +#ifdef CONFIG_AUFS_SBILIST
30940 +extern struct hlist_bl_head au_sbilist;
30942 +static inline void au_sbilist_init(void)
30944 + INIT_HLIST_BL_HEAD(&au_sbilist);
30947 +static inline void au_sbilist_add(struct super_block *sb)
30949 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30952 +static inline void au_sbilist_del(struct super_block *sb)
30954 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30957 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30958 +static inline void au_sbilist_lock(void)
30960 + hlist_bl_lock(&au_sbilist);
30963 +static inline void au_sbilist_unlock(void)
30965 + hlist_bl_unlock(&au_sbilist);
30967 +#define AuGFP_SBILIST GFP_ATOMIC
30969 +AuStubVoid(au_sbilist_lock, void)
30970 +AuStubVoid(au_sbilist_unlock, void)
30971 +#define AuGFP_SBILIST GFP_NOFS
30972 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30974 +AuStubVoid(au_sbilist_init, void)
30975 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30976 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30977 +AuStubVoid(au_sbilist_lock, void)
30978 +AuStubVoid(au_sbilist_unlock, void)
30979 +#define AuGFP_SBILIST GFP_NOFS
30982 +/* ---------------------------------------------------------------------- */
30984 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30987 + * This function is a dynamic '__init' function actually,
30988 + * so the tiny check for si_rwsem is unnecessary.
30990 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30991 +#ifdef CONFIG_DEBUG_FS
30992 + sbinfo->si_dbgaufs = NULL;
30993 + sbinfo->si_dbgaufs_plink = NULL;
30994 + sbinfo->si_dbgaufs_xib = NULL;
30995 +#ifdef CONFIG_AUFS_EXPORT
30996 + sbinfo->si_dbgaufs_xigen = NULL;
31001 +/* ---------------------------------------------------------------------- */
31003 +/* current->atomic_flags */
31004 +/* this value should never corrupt the ones defined in linux/sched.h */
31005 +#define PFA_AUFS 7
31007 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31008 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31009 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31011 +static inline int si_pid_test(struct super_block *sb)
31013 + return !!task_test_aufs(current);
31016 +static inline void si_pid_clr(struct super_block *sb)
31018 + AuDebugOn(!task_test_aufs(current));
31019 + task_clear_aufs(current);
31022 +static inline void si_pid_set(struct super_block *sb)
31024 + AuDebugOn(task_test_aufs(current));
31025 + task_set_aufs(current);
31028 +/* ---------------------------------------------------------------------- */
31030 +/* lock superblock. mainly for entry point functions */
31031 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31032 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31033 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31034 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31036 +#define __si_read_trylock_nested(sb) \
31037 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31038 +#define __si_write_trylock_nested(sb) \
31039 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31042 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31043 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31044 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31046 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31047 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31048 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31050 +static inline void si_noflush_read_lock(struct super_block *sb)
31052 + __si_read_lock(sb);
31056 +static inline int si_noflush_read_trylock(struct super_block *sb)
31060 + locked = __si_read_trylock(sb);
31066 +static inline void si_noflush_write_lock(struct super_block *sb)
31068 + __si_write_lock(sb);
31072 +static inline int si_noflush_write_trylock(struct super_block *sb)
31076 + locked = __si_write_trylock(sb);
31082 +#if 0 /* reserved */
31083 +static inline int si_read_trylock(struct super_block *sb, int flags)
31085 + if (au_ftest_lock(flags, FLUSH))
31086 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31087 + return si_noflush_read_trylock(sb);
31091 +static inline void si_read_unlock(struct super_block *sb)
31094 + __si_read_unlock(sb);
31097 +#if 0 /* reserved */
31098 +static inline int si_write_trylock(struct super_block *sb, int flags)
31100 + if (au_ftest_lock(flags, FLUSH))
31101 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31102 + return si_noflush_write_trylock(sb);
31106 +static inline void si_write_unlock(struct super_block *sb)
31109 + __si_write_unlock(sb);
31112 +#if 0 /* reserved */
31113 +static inline void si_downgrade_lock(struct super_block *sb)
31115 + __si_downgrade_lock(sb);
31119 +/* ---------------------------------------------------------------------- */
31121 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31123 + SiMustAnyLock(sb);
31124 + return au_sbi(sb)->si_bbot;
31127 +static inline unsigned int au_mntflags(struct super_block *sb)
31129 + SiMustAnyLock(sb);
31130 + return au_sbi(sb)->si_mntflags;
31133 +static inline unsigned int au_sigen(struct super_block *sb)
31135 + SiMustAnyLock(sb);
31136 + return au_sbi(sb)->si_generation;
31139 +static inline struct au_branch *au_sbr(struct super_block *sb,
31140 + aufs_bindex_t bindex)
31142 + SiMustAnyLock(sb);
31143 + return au_sbi(sb)->si_branch[0 + bindex];
31146 +static inline loff_t au_xi_maxent(struct super_block *sb)
31148 + SiMustAnyLock(sb);
31149 + return au_sbi(sb)->si_ximaxent;
31152 +#endif /* __KERNEL__ */
31153 +#endif /* __AUFS_SUPER_H__ */
31154 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31155 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31156 +++ linux/fs/aufs/sysaufs.c 2021-02-22 23:30:37.702680911 +0100
31158 +// SPDX-License-Identifier: GPL-2.0
31160 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31162 + * This program, aufs is free software; you can redistribute it and/or modify
31163 + * it under the terms of the GNU General Public License as published by
31164 + * the Free Software Foundation; either version 2 of the License, or
31165 + * (at your option) any later version.
31167 + * This program is distributed in the hope that it will be useful,
31168 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31169 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31170 + * GNU General Public License for more details.
31172 + * You should have received a copy of the GNU General Public License
31173 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31177 + * sysfs interface and lifetime management
31178 + * they are necessary regardless sysfs is disabled.
31181 +#include <linux/random.h>
31184 +unsigned long sysaufs_si_mask;
31185 +struct kset *sysaufs_kset;
31187 +#define AuSiAttr(_name) { \
31188 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31189 + .show = sysaufs_si_##_name, \
31192 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31193 +struct attribute *sysaufs_si_attrs[] = {
31194 + &sysaufs_si_attr_xi_path.attr,
31198 +static const struct sysfs_ops au_sbi_ops = {
31199 + .show = sysaufs_si_show
31202 +static struct kobj_type au_sbi_ktype = {
31203 + .release = au_si_free,
31204 + .sysfs_ops = &au_sbi_ops,
31205 + .default_attrs = sysaufs_si_attrs
31208 +/* ---------------------------------------------------------------------- */
31210 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31214 + sbinfo->si_kobj.kset = sysaufs_kset;
31215 + /* cf. sysaufs_name() */
31216 + err = kobject_init_and_add
31217 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31218 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31223 +void sysaufs_fin(void)
31225 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31226 + kset_unregister(sysaufs_kset);
31229 +int __init sysaufs_init(void)
31234 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31235 + } while (!sysaufs_si_mask);
31238 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31239 + if (unlikely(!sysaufs_kset))
31241 + err = PTR_ERR(sysaufs_kset);
31242 + if (IS_ERR(sysaufs_kset))
31244 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31245 + if (unlikely(err))
31246 + kset_unregister(sysaufs_kset);
31251 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31252 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31253 +++ linux/fs/aufs/sysaufs.h 2021-02-22 23:30:37.702680911 +0100
31255 +/* SPDX-License-Identifier: GPL-2.0 */
31257 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31259 + * This program, aufs is free software; you can redistribute it and/or modify
31260 + * it under the terms of the GNU General Public License as published by
31261 + * the Free Software Foundation; either version 2 of the License, or
31262 + * (at your option) any later version.
31264 + * This program is distributed in the hope that it will be useful,
31265 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31266 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31267 + * GNU General Public License for more details.
31269 + * You should have received a copy of the GNU General Public License
31270 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31274 + * sysfs interface and mount lifetime management
31277 +#ifndef __SYSAUFS_H__
31278 +#define __SYSAUFS_H__
31282 +#include <linux/sysfs.h>
31283 +#include "module.h"
31285 +struct super_block;
31288 +struct sysaufs_si_attr {
31289 + struct attribute attr;
31290 + int (*show)(struct seq_file *seq, struct super_block *sb);
31293 +/* ---------------------------------------------------------------------- */
31296 +extern unsigned long sysaufs_si_mask;
31297 +extern struct kset *sysaufs_kset;
31298 +extern struct attribute *sysaufs_si_attrs[];
31299 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31300 +int __init sysaufs_init(void);
31301 +void sysaufs_fin(void);
31303 +/* ---------------------------------------------------------------------- */
31305 +/* some people doesn't like to show a pointer in kernel */
31306 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31308 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31311 +#define SysaufsSiNamePrefix "si_"
31312 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31313 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31315 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31316 + sysaufs_si_id(sbinfo));
31320 +#ifdef CONFIG_SYSFS
31322 +extern struct attribute_group *sysaufs_attr_group;
31324 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31325 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31327 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31328 +#ifdef CONFIG_COMPAT
31329 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31332 +void sysaufs_br_init(struct au_branch *br);
31333 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31334 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31336 +#define sysaufs_brs_init() do {} while (0)
31339 +#define sysaufs_attr_group NULL
31341 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31342 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31343 + struct attribute *attr, char *buf)
31344 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31345 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31346 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31348 +static inline void sysaufs_brs_init(void)
31353 +#endif /* CONFIG_SYSFS */
31355 +#endif /* __KERNEL__ */
31356 +#endif /* __SYSAUFS_H__ */
31357 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31358 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31359 +++ linux/fs/aufs/sysfs.c 2021-02-22 23:30:37.702680911 +0100
31361 +// SPDX-License-Identifier: GPL-2.0
31363 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31365 + * This program, aufs is free software; you can redistribute it and/or modify
31366 + * it under the terms of the GNU General Public License as published by
31367 + * the Free Software Foundation; either version 2 of the License, or
31368 + * (at your option) any later version.
31370 + * This program is distributed in the hope that it will be useful,
31371 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31372 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31373 + * GNU General Public License for more details.
31375 + * You should have received a copy of the GNU General Public License
31376 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31380 + * sysfs interface
31383 +#include <linux/compat.h>
31384 +#include <linux/seq_file.h>
31387 +#ifdef CONFIG_AUFS_FS_MODULE
31388 +/* this entry violates the "one line per file" policy of sysfs */
31389 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31393 + static char *conf =
31394 +/* this file is generated at compiling */
31395 +#include "conf.str"
31398 + err = snprintf(buf, PAGE_SIZE, conf);
31399 + if (unlikely(err >= PAGE_SIZE))
31404 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31407 +static struct attribute *au_attr[] = {
31408 +#ifdef CONFIG_AUFS_FS_MODULE
31409 + &au_config_attr.attr,
31411 + NULL, /* need to NULL terminate the list of attributes */
31414 +static struct attribute_group sysaufs_attr_group_body = {
31418 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31420 +/* ---------------------------------------------------------------------- */
31422 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31426 + SiMustAnyLock(sb);
31429 + if (au_opt_test(au_mntflags(sb), XINO)) {
31430 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31431 + seq_putc(seq, '\n');
31437 + * the lifetime of branch is independent from the entry under sysfs.
31438 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31441 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31442 + aufs_bindex_t bindex, int idx)
31445 + struct path path;
31446 + struct dentry *root;
31447 + struct au_branch *br;
31448 + au_br_perm_str_t perm;
31450 + AuDbg("b%d\n", bindex);
31453 + root = sb->s_root;
31454 + di_read_lock_parent(root, !AuLock_IR);
31455 + br = au_sbr(sb, bindex);
31458 + case AuBrSysfs_BR:
31459 + path.mnt = au_br_mnt(br);
31460 + path.dentry = au_h_dptr(root, bindex);
31461 + err = au_seq_path(seq, &path);
31463 + au_optstr_br_perm(&perm, br->br_perm);
31464 + seq_printf(seq, "=%s\n", perm.a);
31467 + case AuBrSysfs_BRID:
31468 + seq_printf(seq, "%d\n", br->br_id);
31471 + di_read_unlock(root, !AuLock_IR);
31472 + if (unlikely(err || seq_has_overflowed(seq)))
31478 +/* ---------------------------------------------------------------------- */
31480 +static struct seq_file *au_seq(char *p, ssize_t len)
31482 + struct seq_file *seq;
31484 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31486 + /* mutex_init(&seq.lock); */
31489 + return seq; /* success */
31492 + seq = ERR_PTR(-ENOMEM);
31496 +#define SysaufsBr_PREFIX "br"
31497 +#define SysaufsBrid_PREFIX "brid"
31499 +/* todo: file size may exceed PAGE_SIZE */
31500 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31506 + aufs_bindex_t bbot;
31507 + struct au_sbinfo *sbinfo;
31508 + struct super_block *sb;
31509 + struct seq_file *seq;
31511 + struct attribute **cattr;
31513 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31514 + sb = sbinfo->si_sb;
31517 + * prevent a race condition between sysfs and aufs.
31518 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31519 + * prohibits maintaining the sysfs entries.
31520 + * hew we acquire read lock after sysfs_get_active_two().
31521 + * on the other hand, the remount process may maintain the sysfs/aufs
31522 + * entries after acquiring write lock.
31523 + * it can cause a deadlock.
31524 + * simply we gave up processing read here.
31527 + if (unlikely(!si_noflush_read_trylock(sb)))
31530 + seq = au_seq(buf, PAGE_SIZE);
31531 + err = PTR_ERR(seq);
31535 + name = (void *)attr->name;
31536 + cattr = sysaufs_si_attrs;
31538 + if (!strcmp(name, (*cattr)->name)) {
31539 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31546 + if (!strncmp(name, SysaufsBrid_PREFIX,
31547 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31548 + idx = AuBrSysfs_BRID;
31549 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31550 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31551 + sizeof(SysaufsBr_PREFIX) - 1)) {
31552 + idx = AuBrSysfs_BR;
31553 + name += sizeof(SysaufsBr_PREFIX) - 1;
31557 + err = kstrtol(name, 10, &l);
31559 + bbot = au_sbbot(sb);
31561 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31568 + err = seq->count;
31569 + /* sysfs limit */
31570 + if (unlikely(err == PAGE_SIZE))
31573 + au_kfree_rcu(seq);
31575 + si_read_unlock(sb);
31580 +/* ---------------------------------------------------------------------- */
31582 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31586 + aufs_bindex_t bindex, bbot;
31589 + struct seq_file *seq;
31590 + struct au_branch *br;
31592 + si_read_lock(sb, AuLock_FLUSH);
31593 + bbot = au_sbbot(sb);
31599 + buf = (void *)__get_free_page(GFP_NOFS);
31600 + if (unlikely(!buf))
31603 + seq = au_seq(buf, PAGE_SIZE);
31604 + err = PTR_ERR(seq);
31608 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31609 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31610 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
31611 + if (unlikely(err))
31614 + br = au_sbr(sb, bindex);
31615 + brid = br->br_id;
31616 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31617 + err = __put_user(brid, &arg->id);
31618 + if (unlikely(err))
31621 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31622 + err = __put_user(br->br_perm, &arg->perm);
31623 + if (unlikely(err))
31626 + err = au_seq_path(seq, &br->br_path);
31627 + if (unlikely(err))
31629 + seq_putc(seq, '\0');
31630 + if (!seq_has_overflowed(seq)) {
31631 + err = copy_to_user(arg->path, seq->buf, seq->count);
31633 + if (unlikely(err))
31640 + if (unlikely(err))
31644 + au_kfree_rcu(seq);
31646 + free_page((unsigned long)buf);
31648 + si_read_unlock(sb);
31652 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31654 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31657 +#ifdef CONFIG_COMPAT
31658 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31660 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31664 +/* ---------------------------------------------------------------------- */
31666 +void sysaufs_br_init(struct au_branch *br)
31669 + struct au_brsysfs *br_sysfs;
31670 + struct attribute *attr;
31672 + br_sysfs = br->br_sysfs;
31673 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31674 + attr = &br_sysfs->attr;
31675 + sysfs_attr_init(attr);
31676 + attr->name = br_sysfs->name;
31677 + attr->mode = 0444;
31682 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31684 + struct au_branch *br;
31685 + struct kobject *kobj;
31686 + struct au_brsysfs *br_sysfs;
31688 + aufs_bindex_t bbot;
31690 + if (!sysaufs_brs)
31693 + kobj = &au_sbi(sb)->si_kobj;
31694 + bbot = au_sbbot(sb);
31695 + for (; bindex <= bbot; bindex++) {
31696 + br = au_sbr(sb, bindex);
31697 + br_sysfs = br->br_sysfs;
31698 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31699 + sysfs_remove_file(kobj, &br_sysfs->attr);
31705 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31708 + aufs_bindex_t bbot;
31709 + struct kobject *kobj;
31710 + struct au_branch *br;
31711 + struct au_brsysfs *br_sysfs;
31713 + if (!sysaufs_brs)
31716 + kobj = &au_sbi(sb)->si_kobj;
31717 + bbot = au_sbbot(sb);
31718 + for (; bindex <= bbot; bindex++) {
31719 + br = au_sbr(sb, bindex);
31720 + br_sysfs = br->br_sysfs;
31721 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31722 + SysaufsBr_PREFIX "%d", bindex);
31723 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31724 + SysaufsBrid_PREFIX "%d", bindex);
31725 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31726 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31727 + if (unlikely(err))
31728 + pr_warn("failed %s under sysfs(%d)\n",
31729 + br_sysfs->name, err);
31734 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31735 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31736 +++ linux/fs/aufs/sysrq.c 2021-02-22 23:30:37.702680911 +0100
31738 +// SPDX-License-Identifier: GPL-2.0
31740 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31742 + * This program, aufs is free software; you can redistribute it and/or modify
31743 + * it under the terms of the GNU General Public License as published by
31744 + * the Free Software Foundation; either version 2 of the License, or
31745 + * (at your option) any later version.
31747 + * This program is distributed in the hope that it will be useful,
31748 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31749 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31750 + * GNU General Public License for more details.
31752 + * You should have received a copy of the GNU General Public License
31753 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31757 + * magic sysrq handler
31760 +/* #include <linux/sysrq.h> */
31761 +#include <linux/writeback.h>
31764 +/* ---------------------------------------------------------------------- */
31766 +static void sysrq_sb(struct super_block *sb)
31769 + struct au_sbinfo *sbinfo;
31770 + struct file *file;
31771 + struct hlist_bl_head *files;
31772 + struct hlist_bl_node *pos;
31773 + struct au_finfo *finfo;
31776 + plevel = au_plevel;
31777 + au_plevel = KERN_WARNING;
31779 + /* since we define pr_fmt, call printk directly */
31780 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31782 + sbinfo = au_sbi(sb);
31783 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31784 + pr("superblock\n");
31787 +#if 0 /* reserved */
31789 + int err, i, j, ndentry;
31790 + struct au_dcsub_pages dpages;
31791 + struct au_dpage *dpage;
31793 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31794 + if (unlikely(err))
31796 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31798 + for (i = 0; i < dpages.ndpage; i++) {
31799 + dpage = dpages.dpages + i;
31800 + ndentry = dpage->ndentry;
31801 + for (j = 0; j < ndentry; j++)
31802 + au_dpri_dentry(dpage->dentries[j]);
31804 + au_dpages_free(&dpages);
31808 + pr("isolated inode\n");
31809 + spin_lock(&sb->s_inode_list_lock);
31810 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31811 + spin_lock(&i->i_lock);
31812 + if (hlist_empty(&i->i_dentry))
31813 + au_dpri_inode(i);
31814 + spin_unlock(&i->i_lock);
31816 + spin_unlock(&sb->s_inode_list_lock);
31819 + files = &au_sbi(sb)->si_files;
31820 + hlist_bl_lock(files);
31821 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31824 + file = finfo->fi_file;
31825 + mode = file_inode(file)->i_mode;
31826 + if (!special_file(mode))
31827 + au_dpri_file(file);
31829 + hlist_bl_unlock(files);
31833 + au_plevel = plevel;
31836 +/* ---------------------------------------------------------------------- */
31838 +/* module parameter */
31839 +static char *aufs_sysrq_key = "a";
31840 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31841 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31843 +static void au_sysrq(int key __maybe_unused)
31845 + struct au_sbinfo *sbinfo;
31846 + struct hlist_bl_node *pos;
31849 + au_sbilist_lock();
31850 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31851 + sysrq_sb(sbinfo->si_sb);
31852 + au_sbilist_unlock();
31856 +static struct sysrq_key_op au_sysrq_op = {
31857 + .handler = au_sysrq,
31858 + .help_msg = "Aufs",
31859 + .action_msg = "Aufs",
31860 + .enable_mask = SYSRQ_ENABLE_DUMP
31863 +/* ---------------------------------------------------------------------- */
31865 +int __init au_sysrq_init(void)
31871 + key = *aufs_sysrq_key;
31872 + if ('a' <= key && key <= 'z')
31873 + err = register_sysrq_key(key, &au_sysrq_op);
31874 + if (unlikely(err))
31875 + pr_err("err %d, sysrq=%c\n", err, key);
31879 +void au_sysrq_fin(void)
31883 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31884 + if (unlikely(err))
31885 + pr_err("err %d (ignored)\n", err);
31887 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31888 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31889 +++ linux/fs/aufs/vdir.c 2021-02-22 23:30:37.702680911 +0100
31891 +// SPDX-License-Identifier: GPL-2.0
31893 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31895 + * This program, aufs is free software; you can redistribute it and/or modify
31896 + * it under the terms of the GNU General Public License as published by
31897 + * the Free Software Foundation; either version 2 of the License, or
31898 + * (at your option) any later version.
31900 + * This program is distributed in the hope that it will be useful,
31901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31903 + * GNU General Public License for more details.
31905 + * You should have received a copy of the GNU General Public License
31906 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31910 + * virtual or vertical directory
31913 +#include <linux/iversion.h>
31916 +static unsigned int calc_size(int nlen)
31918 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31921 +static int set_deblk_end(union au_vdir_deblk_p *p,
31922 + union au_vdir_deblk_p *deblk_end)
31924 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31925 + p->de->de_str.len = 0;
31929 + return -1; /* error */
31932 +/* returns true or false */
31933 +static int is_deblk_end(union au_vdir_deblk_p *p,
31934 + union au_vdir_deblk_p *deblk_end)
31936 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31937 + return !p->de->de_str.len;
31941 +static unsigned char *last_deblk(struct au_vdir *vdir)
31943 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31946 +/* ---------------------------------------------------------------------- */
31948 +/* estimate the appropriate size for name hash table */
31949 +unsigned int au_rdhash_est(loff_t sz)
31957 + if (sz < AUFS_RDHASH_DEF)
31958 + n = AUFS_RDHASH_DEF;
31959 + /* pr_info("n %u\n", n); */
31964 + * the allocated memory has to be freed by
31965 + * au_nhash_wh_free() or au_nhash_de_free().
31967 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31969 + struct hlist_head *head;
31973 + sz = sizeof(*nhash->nh_head) * num_hash;
31974 + head = kmalloc(sz, gfp);
31976 + nhash->nh_num = num_hash;
31977 + nhash->nh_head = head;
31978 + for (u = 0; u < num_hash; u++)
31979 + INIT_HLIST_HEAD(head++);
31980 + return 0; /* success */
31986 +static void nhash_count(struct hlist_head *head)
31988 +#if 0 /* debugging */
31990 + struct hlist_node *pos;
31993 + hlist_for_each(pos, head)
31995 + pr_info("%lu\n", n);
31999 +static void au_nhash_wh_do_free(struct hlist_head *head)
32001 + struct au_vdir_wh *pos;
32002 + struct hlist_node *node;
32004 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32005 + au_kfree_rcu(pos);
32008 +static void au_nhash_de_do_free(struct hlist_head *head)
32010 + struct au_vdir_dehstr *pos;
32011 + struct hlist_node *node;
32013 + hlist_for_each_entry_safe(pos, node, head, hash)
32014 + au_cache_free_vdir_dehstr(pos);
32017 +static void au_nhash_do_free(struct au_nhash *nhash,
32018 + void (*free)(struct hlist_head *head))
32021 + struct hlist_head *head;
32023 + n = nhash->nh_num;
32027 + head = nhash->nh_head;
32028 + while (n-- > 0) {
32029 + nhash_count(head);
32032 + au_kfree_try_rcu(nhash->nh_head);
32035 +void au_nhash_wh_free(struct au_nhash *whlist)
32037 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32040 +static void au_nhash_de_free(struct au_nhash *delist)
32042 + au_nhash_do_free(delist, au_nhash_de_do_free);
32045 +/* ---------------------------------------------------------------------- */
32047 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32051 + unsigned int u, n;
32052 + struct hlist_head *head;
32053 + struct au_vdir_wh *pos;
32056 + n = whlist->nh_num;
32057 + head = whlist->nh_head;
32058 + for (u = 0; u < n; u++, head++)
32059 + hlist_for_each_entry(pos, head, wh_hash)
32060 + if (pos->wh_bindex == btgt && ++num > limit)
32065 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32066 + unsigned char *name,
32067 + unsigned int len)
32070 + /* const unsigned int magic_bit = 12; */
32072 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32079 + /* v = hash_long(v, magic_bit); */
32080 + v %= nhash->nh_num;
32081 + return nhash->nh_head + v;
32084 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32087 + return str->len == nlen && !memcmp(str->name, name, nlen);
32090 +/* returns found or not */
32091 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32093 + struct hlist_head *head;
32094 + struct au_vdir_wh *pos;
32095 + struct au_vdir_destr *str;
32097 + head = au_name_hash(whlist, name, nlen);
32098 + hlist_for_each_entry(pos, head, wh_hash) {
32099 + str = &pos->wh_str;
32100 + AuDbg("%.*s\n", str->len, str->name);
32101 + if (au_nhash_test_name(str, name, nlen))
32107 +/* returns found(true) or not */
32108 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32110 + struct hlist_head *head;
32111 + struct au_vdir_dehstr *pos;
32112 + struct au_vdir_destr *str;
32114 + head = au_name_hash(delist, name, nlen);
32115 + hlist_for_each_entry(pos, head, hash) {
32117 + AuDbg("%.*s\n", str->len, str->name);
32118 + if (au_nhash_test_name(str, name, nlen))
32124 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32125 + unsigned char d_type)
32127 +#ifdef CONFIG_AUFS_SHWH
32128 + wh->wh_ino = ino;
32129 + wh->wh_type = d_type;
32133 +/* ---------------------------------------------------------------------- */
32135 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32136 + unsigned int d_type, aufs_bindex_t bindex,
32137 + unsigned char shwh)
32140 + struct au_vdir_destr *str;
32141 + struct au_vdir_wh *wh;
32143 + AuDbg("%.*s\n", nlen, name);
32144 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32147 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32148 + if (unlikely(!wh))
32152 + wh->wh_bindex = bindex;
32154 + au_shwh_init_wh(wh, ino, d_type);
32155 + str = &wh->wh_str;
32157 + memcpy(str->name, name, nlen);
32158 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32165 +static int append_deblk(struct au_vdir *vdir)
32168 + unsigned long ul;
32169 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32170 + union au_vdir_deblk_p p, deblk_end;
32171 + unsigned char **o;
32174 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32175 + GFP_NOFS, /*may_shrink*/0);
32176 + if (unlikely(!o))
32179 + vdir->vd_deblk = o;
32180 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32182 + ul = vdir->vd_nblk++;
32183 + vdir->vd_deblk[ul] = p.deblk;
32184 + vdir->vd_last.ul = ul;
32185 + vdir->vd_last.p.deblk = p.deblk;
32186 + deblk_end.deblk = p.deblk + deblk_sz;
32187 + err = set_deblk_end(&p, &deblk_end);
32194 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32195 + unsigned int d_type, struct au_nhash *delist)
32199 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32200 + union au_vdir_deblk_p p, *room, deblk_end;
32201 + struct au_vdir_dehstr *dehstr;
32203 + p.deblk = last_deblk(vdir);
32204 + deblk_end.deblk = p.deblk + deblk_sz;
32205 + room = &vdir->vd_last.p;
32206 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32207 + || !is_deblk_end(room, &deblk_end));
32209 + sz = calc_size(nlen);
32210 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32211 + err = append_deblk(vdir);
32212 + if (unlikely(err))
32215 + p.deblk = last_deblk(vdir);
32216 + deblk_end.deblk = p.deblk + deblk_sz;
32218 + AuDebugOn(room->deblk != p.deblk);
32222 + dehstr = au_cache_alloc_vdir_dehstr();
32223 + if (unlikely(!dehstr))
32226 + dehstr->str = &room->de->de_str;
32227 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32228 + room->de->de_ino = ino;
32229 + room->de->de_type = d_type;
32230 + room->de->de_str.len = nlen;
32231 + memcpy(room->de->de_str.name, name, nlen);
32234 + room->deblk += sz;
32235 + if (unlikely(set_deblk_end(room, &deblk_end)))
32236 + err = append_deblk(vdir);
32243 +/* ---------------------------------------------------------------------- */
32245 +void au_vdir_free(struct au_vdir *vdir)
32247 + unsigned char **deblk;
32249 + deblk = vdir->vd_deblk;
32250 + while (vdir->vd_nblk--)
32251 + au_kfree_try_rcu(*deblk++);
32252 + au_kfree_try_rcu(vdir->vd_deblk);
32253 + au_cache_free_vdir(vdir);
32256 +static struct au_vdir *alloc_vdir(struct file *file)
32258 + struct au_vdir *vdir;
32259 + struct super_block *sb;
32262 + sb = file->f_path.dentry->d_sb;
32263 + SiMustAnyLock(sb);
32266 + vdir = au_cache_alloc_vdir();
32267 + if (unlikely(!vdir))
32270 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32271 + if (unlikely(!vdir->vd_deblk))
32274 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32275 + if (!vdir->vd_deblk_sz) {
32276 + /* estimate the appropriate size for deblk */
32277 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32278 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32280 + vdir->vd_nblk = 0;
32281 + vdir->vd_version = 0;
32282 + vdir->vd_jiffy = 0;
32283 + err = append_deblk(vdir);
32285 + return vdir; /* success */
32287 + au_kfree_try_rcu(vdir->vd_deblk);
32290 + au_cache_free_vdir(vdir);
32292 + vdir = ERR_PTR(err);
32296 +static int reinit_vdir(struct au_vdir *vdir)
32299 + union au_vdir_deblk_p p, deblk_end;
32301 + while (vdir->vd_nblk > 1) {
32302 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32303 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32306 + p.deblk = vdir->vd_deblk[0];
32307 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32308 + err = set_deblk_end(&p, &deblk_end);
32309 + /* keep vd_dblk_sz */
32310 + vdir->vd_last.ul = 0;
32311 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32312 + vdir->vd_version = 0;
32313 + vdir->vd_jiffy = 0;
32318 +/* ---------------------------------------------------------------------- */
32320 +#define AuFillVdir_CALLED 1
32321 +#define AuFillVdir_WHABLE (1 << 1)
32322 +#define AuFillVdir_SHWH (1 << 2)
32323 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32324 +#define au_fset_fillvdir(flags, name) \
32325 + do { (flags) |= AuFillVdir_##name; } while (0)
32326 +#define au_fclr_fillvdir(flags, name) \
32327 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32329 +#ifndef CONFIG_AUFS_SHWH
32330 +#undef AuFillVdir_SHWH
32331 +#define AuFillVdir_SHWH 0
32334 +struct fillvdir_arg {
32335 + struct dir_context ctx;
32336 + struct file *file;
32337 + struct au_vdir *vdir;
32338 + struct au_nhash delist;
32339 + struct au_nhash whlist;
32340 + aufs_bindex_t bindex;
32341 + unsigned int flags;
32345 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32346 + loff_t offset __maybe_unused, u64 h_ino,
32347 + unsigned int d_type)
32349 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32350 + char *name = (void *)__name;
32351 + struct super_block *sb;
32353 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32356 + sb = arg->file->f_path.dentry->d_sb;
32357 + au_fset_fillvdir(arg->flags, CALLED);
32359 + if (nlen <= AUFS_WH_PFX_LEN
32360 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32361 + if (test_known(&arg->delist, name, nlen)
32362 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32363 + goto out; /* already exists or whiteouted */
32365 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32367 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32368 + d_type = DT_UNKNOWN;
32369 + arg->err = append_de(arg->vdir, name, nlen, ino,
32370 + d_type, &arg->delist);
32372 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32373 + name += AUFS_WH_PFX_LEN;
32374 + nlen -= AUFS_WH_PFX_LEN;
32375 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32376 + goto out; /* already whiteouted */
32378 + ino = 0; /* just to suppress a warning */
32380 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32383 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32384 + d_type = DT_UNKNOWN;
32385 + arg->err = au_nhash_append_wh
32386 + (&arg->whlist, name, nlen, ino, d_type,
32387 + arg->bindex, shwh);
32393 + arg->vdir->vd_jiffy = jiffies;
32395 + AuTraceErr(arg->err);
32399 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32400 + struct au_nhash *whlist, struct au_nhash *delist)
32402 +#ifdef CONFIG_AUFS_SHWH
32404 + unsigned int nh, u;
32405 + struct hlist_head *head;
32406 + struct au_vdir_wh *pos;
32407 + struct hlist_node *n;
32409 + struct au_vdir_destr *destr;
32411 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32414 + o = p = (void *)__get_free_page(GFP_NOFS);
32415 + if (unlikely(!p))
32419 + nh = whlist->nh_num;
32420 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32421 + p += AUFS_WH_PFX_LEN;
32422 + for (u = 0; u < nh; u++) {
32423 + head = whlist->nh_head + u;
32424 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32425 + destr = &pos->wh_str;
32426 + memcpy(p, destr->name, destr->len);
32427 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32428 + pos->wh_ino, pos->wh_type, delist);
32429 + if (unlikely(err))
32434 + free_page((unsigned long)o);
32444 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32447 + unsigned int rdhash;
32449 + aufs_bindex_t bbot, bindex, btop;
32450 + unsigned char shwh;
32451 + struct file *hf, *file;
32452 + struct super_block *sb;
32454 + file = arg->file;
32455 + sb = file->f_path.dentry->d_sb;
32456 + SiMustAnyLock(sb);
32458 + rdhash = au_sbi(sb)->si_rdhash;
32460 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32461 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32462 + if (unlikely(err))
32464 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32465 + if (unlikely(err))
32471 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32473 + au_fset_fillvdir(arg->flags, SHWH);
32475 + btop = au_fbtop(file);
32476 + bbot = au_fbbot_dir(file);
32477 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32478 + hf = au_hf_dir(file, bindex);
32482 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32484 + if (unlikely(offset))
32487 + arg->bindex = bindex;
32488 + au_fclr_fillvdir(arg->flags, WHABLE);
32490 + || (bindex != bbot
32491 + && au_br_whable(au_sbr_perm(sb, bindex))))
32492 + au_fset_fillvdir(arg->flags, WHABLE);
32495 + au_fclr_fillvdir(arg->flags, CALLED);
32497 + err = vfsub_iterate_dir(hf, &arg->ctx);
32500 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32503 + * dir_relax() may be good for concurrency, but aufs should not
32504 + * use it since it will cause a lockdep problem.
32508 + if (!err && shwh)
32509 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32511 + au_nhash_wh_free(&arg->whlist);
32514 + au_nhash_de_free(&arg->delist);
32519 +static int read_vdir(struct file *file, int may_read)
32522 + unsigned long expire;
32523 + unsigned char do_read;
32524 + struct fillvdir_arg arg = {
32526 + .actor = fillvdir
32529 + struct inode *inode;
32530 + struct au_vdir *vdir, *allocated;
32533 + inode = file_inode(file);
32534 + IMustLock(inode);
32535 + IiMustWriteLock(inode);
32536 + SiMustAnyLock(inode->i_sb);
32538 + allocated = NULL;
32540 + expire = au_sbi(inode->i_sb)->si_rdcache;
32541 + vdir = au_ivdir(inode);
32544 + vdir = alloc_vdir(file);
32545 + err = PTR_ERR(vdir);
32546 + if (IS_ERR(vdir))
32549 + allocated = vdir;
32550 + } else if (may_read
32551 + && (!inode_eq_iversion(inode, vdir->vd_version)
32552 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32554 + err = reinit_vdir(vdir);
32555 + if (unlikely(err))
32560 + return 0; /* success */
32564 + err = au_do_read_vdir(&arg);
32566 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32567 + vdir->vd_version = inode_query_iversion(inode);
32568 + vdir->vd_last.ul = 0;
32569 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32571 + au_set_ivdir(inode, allocated);
32572 + } else if (allocated)
32573 + au_vdir_free(allocated);
32579 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32582 + unsigned long ul, n;
32583 + const unsigned int deblk_sz = src->vd_deblk_sz;
32585 + AuDebugOn(tgt->vd_nblk != 1);
32588 + if (tgt->vd_nblk < src->vd_nblk) {
32589 + unsigned char **p;
32591 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32592 + GFP_NOFS, /*may_shrink*/0);
32593 + if (unlikely(!p))
32595 + tgt->vd_deblk = p;
32598 + if (tgt->vd_deblk_sz != deblk_sz) {
32599 + unsigned char *p;
32601 + tgt->vd_deblk_sz = deblk_sz;
32602 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32603 + /*may_shrink*/1);
32604 + if (unlikely(!p))
32606 + tgt->vd_deblk[0] = p;
32608 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32609 + tgt->vd_version = src->vd_version;
32610 + tgt->vd_jiffy = src->vd_jiffy;
32612 + n = src->vd_nblk;
32613 + for (ul = 1; ul < n; ul++) {
32614 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32616 + if (unlikely(!tgt->vd_deblk[ul]))
32620 + tgt->vd_nblk = n;
32621 + tgt->vd_last.ul = tgt->vd_last.ul;
32622 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32623 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32624 + - src->vd_deblk[src->vd_last.ul];
32626 + return 0; /* success */
32629 + rerr = reinit_vdir(tgt);
32634 +int au_vdir_init(struct file *file)
32637 + struct inode *inode;
32638 + struct au_vdir *vdir_cache, *allocated;
32640 + /* test file->f_pos here instead of ctx->pos */
32641 + err = read_vdir(file, !file->f_pos);
32642 + if (unlikely(err))
32645 + allocated = NULL;
32646 + vdir_cache = au_fvdir_cache(file);
32647 + if (!vdir_cache) {
32648 + vdir_cache = alloc_vdir(file);
32649 + err = PTR_ERR(vdir_cache);
32650 + if (IS_ERR(vdir_cache))
32652 + allocated = vdir_cache;
32653 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32654 + /* test file->f_pos here instead of ctx->pos */
32655 + err = reinit_vdir(vdir_cache);
32656 + if (unlikely(err))
32659 + return 0; /* success */
32661 + inode = file_inode(file);
32662 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32664 + file->f_version = inode_query_iversion(inode);
32666 + au_set_fvdir_cache(file, allocated);
32667 + } else if (allocated)
32668 + au_vdir_free(allocated);
32674 +static loff_t calc_offset(struct au_vdir *vdir)
32677 + union au_vdir_deblk_p p;
32679 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32680 + offset = vdir->vd_last.p.deblk - p.deblk;
32681 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32685 +/* returns true or false */
32686 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32689 + unsigned int deblk_sz;
32690 + unsigned long ul, n;
32692 + union au_vdir_deblk_p p, deblk_end;
32693 + struct au_vdir *vdir_cache;
32696 + vdir_cache = au_fvdir_cache(file);
32697 + offset = calc_offset(vdir_cache);
32698 + AuDbg("offset %lld\n", offset);
32699 + if (ctx->pos == offset)
32702 + vdir_cache->vd_last.ul = 0;
32703 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32708 + deblk_sz = vdir_cache->vd_deblk_sz;
32709 + ul = div64_u64(ctx->pos, deblk_sz);
32710 + AuDbg("ul %lu\n", ul);
32711 + if (ul >= vdir_cache->vd_nblk)
32714 + n = vdir_cache->vd_nblk;
32715 + for (; ul < n; ul++) {
32716 + p.deblk = vdir_cache->vd_deblk[ul];
32717 + deblk_end.deblk = p.deblk + deblk_sz;
32719 + offset *= deblk_sz;
32720 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32723 + l = calc_size(p.de->de_str.len);
32727 + if (!is_deblk_end(&p, &deblk_end)) {
32729 + vdir_cache->vd_last.ul = ul;
32730 + vdir_cache->vd_last.p = p;
32738 + AuDbg("valid %d\n", !valid);
32742 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32744 + unsigned int l, deblk_sz;
32745 + union au_vdir_deblk_p deblk_end;
32746 + struct au_vdir *vdir_cache;
32747 + struct au_vdir_de *de;
32749 + if (!seek_vdir(file, ctx))
32752 + vdir_cache = au_fvdir_cache(file);
32753 + deblk_sz = vdir_cache->vd_deblk_sz;
32755 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32756 + deblk_end.deblk += deblk_sz;
32757 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32758 + de = vdir_cache->vd_last.p.de;
32759 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32760 + de->de_str.len, de->de_str.name, ctx->pos,
32761 + (unsigned long)de->de_ino, de->de_type);
32762 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32763 + de->de_str.len, de->de_ino,
32765 + /* todo: ignore the error caused by udba? */
32766 + /* return err; */
32770 + l = calc_size(de->de_str.len);
32771 + vdir_cache->vd_last.p.deblk += l;
32774 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32775 + vdir_cache->vd_last.ul++;
32776 + vdir_cache->vd_last.p.deblk
32777 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32778 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32787 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32788 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32789 +++ linux/fs/aufs/vfsub.c 2021-02-22 23:30:37.702680911 +0100
32791 +// SPDX-License-Identifier: GPL-2.0
32793 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32795 + * This program, aufs is free software; you can redistribute it and/or modify
32796 + * it under the terms of the GNU General Public License as published by
32797 + * the Free Software Foundation; either version 2 of the License, or
32798 + * (at your option) any later version.
32800 + * This program is distributed in the hope that it will be useful,
32801 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32802 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32803 + * GNU General Public License for more details.
32805 + * You should have received a copy of the GNU General Public License
32806 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32810 + * sub-routines for VFS
32813 +#include <linux/mnt_namespace.h>
32814 +#include <linux/namei.h>
32815 +#include <linux/nsproxy.h>
32816 +#include <linux/security.h>
32817 +#include <linux/splice.h>
32820 +#ifdef CONFIG_AUFS_BR_FUSE
32821 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32823 + if (!au_test_fuse(h_sb) || !au_userns)
32826 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32830 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32835 + down_read(&h_sb->s_umount);
32836 + err = __sync_filesystem(h_sb, wait);
32837 + up_read(&h_sb->s_umount);
32843 +/* ---------------------------------------------------------------------- */
32845 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32849 + struct super_block *h_sb;
32851 + /* for remote fs, leave work for its getattr or d_revalidate */
32852 + /* for bad i_attr fs, handle them in aufs_getattr() */
32853 + /* still some fs may acquire i_mutex. we need to skip them */
32857 + h_sb = h_path->dentry->d_sb;
32858 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32860 + err = vfsub_getattr(h_path, &st);
32865 +/* ---------------------------------------------------------------------- */
32867 +struct file *vfsub_dentry_open(struct path *path, int flags)
32869 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32873 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32875 + struct file *file;
32878 + file = filp_open(path,
32879 + oflags /* | __FMODE_NONOTIFY */,
32882 + if (IS_ERR(file))
32884 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32891 + * Ideally this function should call VFS:do_last() in order to keep all its
32892 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32893 + * structure such as nameidata. This is a second (or third) best approach.
32894 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32896 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32897 + struct vfsub_aopen_args *args)
32900 + struct au_branch *br = args->br;
32901 + struct file *file = args->file;
32902 + /* copied from linux/fs/namei.c:atomic_open() */
32903 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32906 + AuDebugOn(!dir->i_op->atomic_open);
32908 + err = au_br_test_oflag(args->open_flag, br);
32909 + if (unlikely(err))
32912 + au_lcnt_inc(&br->br_nfiles);
32913 + file->f_path.dentry = DENTRY_NOT_SET;
32914 + file->f_path.mnt = au_br_mnt(br);
32915 + AuDbg("%ps\n", dir->i_op->atomic_open);
32916 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32917 + args->create_mode);
32918 + if (unlikely(err < 0)) {
32919 + au_lcnt_dec(&br->br_nfiles);
32923 + /* temporary workaround for nfsv4 branch */
32924 + if (au_test_nfs(dir->i_sb))
32925 + nfs_mark_for_revalidate(dir);
32927 + if (file->f_mode & FMODE_CREATED)
32928 + fsnotify_create(dir, dentry);
32929 + if (!(file->f_mode & FMODE_OPENED)) {
32930 + au_lcnt_dec(&br->br_nfiles);
32934 + /* todo: call VFS:may_open() here */
32935 + /* todo: ima_file_check() too? */
32936 + if (!err && (args->open_flag & __FMODE_EXEC))
32937 + err = deny_write_access(file);
32939 + fsnotify_open(file);
32941 + au_lcnt_dec(&br->br_nfiles);
32942 + /* note that the file is created and still opened */
32948 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32952 + err = kern_path(name, flags, path);
32953 + if (!err && d_is_positive(path->dentry))
32954 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32958 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32959 + struct dentry *parent, int len)
32961 + struct path path = {
32965 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32966 + if (IS_ERR(path.dentry))
32968 + if (d_is_positive(path.dentry))
32969 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32972 + AuTraceErrPtr(path.dentry);
32973 + return path.dentry;
32976 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32979 + struct path path = {
32983 + /* VFS checks it too, but by WARN_ON_ONCE() */
32984 + IMustLock(d_inode(parent));
32986 + path.dentry = lookup_one_len(name, parent, len);
32987 + if (IS_ERR(path.dentry))
32989 + if (d_is_positive(path.dentry))
32990 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32993 + AuTraceErrPtr(path.dentry);
32994 + return path.dentry;
32997 +void vfsub_call_lkup_one(void *args)
32999 + struct vfsub_lkup_one_args *a = args;
33000 + *a->errp = vfsub_lkup_one(a->name, a->parent);
33003 +/* ---------------------------------------------------------------------- */
33005 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33006 + struct dentry *d2, struct au_hinode *hdir2)
33008 + struct dentry *d;
33011 + d = lock_rename(d1, d2);
33013 + au_hn_suspend(hdir1);
33014 + if (hdir1 != hdir2)
33015 + au_hn_suspend(hdir2);
33020 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33021 + struct dentry *d2, struct au_hinode *hdir2)
33023 + au_hn_resume(hdir1);
33024 + if (hdir1 != hdir2)
33025 + au_hn_resume(hdir2);
33027 + unlock_rename(d1, d2);
33031 +/* ---------------------------------------------------------------------- */
33033 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33036 + struct dentry *d;
33040 + d = path->dentry;
33041 + path->dentry = d->d_parent;
33042 + err = security_path_mknod(path, d, mode, 0);
33043 + path->dentry = d;
33044 + if (unlikely(err))
33048 + err = vfs_create(dir, path->dentry, mode, want_excl);
33051 + struct path tmp = *path;
33054 + vfsub_update_h_iattr(&tmp, &did);
33056 + tmp.dentry = path->dentry->d_parent;
33057 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33066 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33069 + struct dentry *d;
33073 + d = path->dentry;
33074 + path->dentry = d->d_parent;
33075 + err = security_path_symlink(path, d, symname);
33076 + path->dentry = d;
33077 + if (unlikely(err))
33081 + err = vfs_symlink(dir, path->dentry, symname);
33084 + struct path tmp = *path;
33087 + vfsub_update_h_iattr(&tmp, &did);
33089 + tmp.dentry = path->dentry->d_parent;
33090 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33099 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33102 + struct dentry *d;
33106 + d = path->dentry;
33107 + path->dentry = d->d_parent;
33108 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33109 + path->dentry = d;
33110 + if (unlikely(err))
33114 + err = vfs_mknod(dir, path->dentry, mode, dev);
33117 + struct path tmp = *path;
33120 + vfsub_update_h_iattr(&tmp, &did);
33122 + tmp.dentry = path->dentry->d_parent;
33123 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33132 +static int au_test_nlink(struct inode *inode)
33134 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33136 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33137 + || inode->i_nlink < link_max)
33142 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33143 + struct inode **delegated_inode)
33146 + struct dentry *d;
33150 + err = au_test_nlink(d_inode(src_dentry));
33151 + if (unlikely(err))
33154 + /* we don't call may_linkat() */
33155 + d = path->dentry;
33156 + path->dentry = d->d_parent;
33157 + err = security_path_link(src_dentry, path, d);
33158 + path->dentry = d;
33159 + if (unlikely(err))
33163 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
33166 + struct path tmp = *path;
33169 + /* fuse has different memory inode for the same inumber */
33170 + vfsub_update_h_iattr(&tmp, &did);
33172 + tmp.dentry = path->dentry->d_parent;
33173 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33174 + tmp.dentry = src_dentry;
33175 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33184 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33185 + struct inode *dir, struct path *path,
33186 + struct inode **delegated_inode, unsigned int flags)
33189 + struct path tmp = {
33192 + struct dentry *d;
33195 + IMustLock(src_dir);
33197 + d = path->dentry;
33198 + path->dentry = d->d_parent;
33199 + tmp.dentry = src_dentry->d_parent;
33200 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33201 + path->dentry = d;
33202 + if (unlikely(err))
33206 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33207 + delegated_inode, flags);
33212 + tmp.dentry = d->d_parent;
33213 + vfsub_update_h_iattr(&tmp, &did);
33215 + tmp.dentry = src_dentry;
33216 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33217 + tmp.dentry = src_dentry->d_parent;
33218 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33227 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33230 + struct dentry *d;
33234 + d = path->dentry;
33235 + path->dentry = d->d_parent;
33236 + err = security_path_mkdir(path, d, mode);
33237 + path->dentry = d;
33238 + if (unlikely(err))
33242 + err = vfs_mkdir(dir, path->dentry, mode);
33245 + struct path tmp = *path;
33248 + vfsub_update_h_iattr(&tmp, &did);
33250 + tmp.dentry = path->dentry->d_parent;
33251 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33260 +int vfsub_rmdir(struct inode *dir, struct path *path)
33263 + struct dentry *d;
33267 + d = path->dentry;
33268 + path->dentry = d->d_parent;
33269 + err = security_path_rmdir(path, d);
33270 + path->dentry = d;
33271 + if (unlikely(err))
33275 + err = vfs_rmdir(dir, path->dentry);
33278 + struct path tmp = {
33279 + .dentry = path->dentry->d_parent,
33283 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33290 +/* ---------------------------------------------------------------------- */
33292 +/* todo: support mmap_sem? */
33293 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33299 + err = vfs_read(file, ubuf, count, ppos);
33302 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33306 +/* todo: kernel_read()? */
33307 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33311 + mm_segment_t oldfs;
33318 + oldfs = get_fs();
33319 + set_fs(KERNEL_DS);
33320 + err = vfsub_read_u(file, buf.u, count, ppos);
33325 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33331 + err = vfs_write(file, ubuf, count, ppos);
33334 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33338 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33341 + mm_segment_t oldfs;
33344 + const char __user *u;
33348 + oldfs = get_fs();
33349 + set_fs(KERNEL_DS);
33350 + err = vfsub_write_u(file, buf.u, count, ppos);
33355 +int vfsub_flush(struct file *file, fl_owner_t id)
33360 + if (file->f_op->flush) {
33361 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33362 + err = file->f_op->flush(file, id);
33365 + err = file->f_op->flush(file, id);
33369 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33375 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33379 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33382 + err = iterate_dir(file, ctx);
33385 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33390 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33391 + struct pipe_inode_info *pipe, size_t len,
33392 + unsigned int flags)
33397 + err = do_splice_to(in, ppos, pipe, len, flags);
33399 + file_accessed(in);
33401 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33405 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33406 + loff_t *ppos, size_t len, unsigned int flags)
33411 + err = do_splice_from(pipe, out, ppos, len, flags);
33414 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33418 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33422 + /* file can be NULL */
33424 + err = vfs_fsync(file, datasync);
33428 + AuDebugOn(!file);
33429 + path = &file->f_path;
33431 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33436 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33437 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33438 + struct file *h_file)
33441 + struct inode *h_inode;
33442 + struct super_block *h_sb;
33445 + err = vfsub_truncate(h_path, length);
33449 + h_inode = d_inode(h_path->dentry);
33450 + h_sb = h_inode->i_sb;
33452 + sb_start_write(h_sb);
33454 + err = locks_verify_truncate(h_inode, h_file, length);
33456 + err = security_path_truncate(h_path);
33459 + err = do_truncate(h_path->dentry, length, attr, h_file);
33463 + sb_end_write(h_sb);
33470 +/* ---------------------------------------------------------------------- */
33472 +struct au_vfsub_mkdir_args {
33474 + struct inode *dir;
33475 + struct path *path;
33479 +static void au_call_vfsub_mkdir(void *args)
33481 + struct au_vfsub_mkdir_args *a = args;
33482 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33485 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33487 + int err, do_sio, wkq_err;
33489 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33492 + err = vfsub_mkdir(dir, path, mode);
33495 + struct au_vfsub_mkdir_args args = {
33501 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33502 + if (unlikely(wkq_err))
33509 +struct au_vfsub_rmdir_args {
33511 + struct inode *dir;
33512 + struct path *path;
33515 +static void au_call_vfsub_rmdir(void *args)
33517 + struct au_vfsub_rmdir_args *a = args;
33518 + *a->errp = vfsub_rmdir(a->dir, a->path);
33521 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33523 + int err, do_sio, wkq_err;
33525 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33528 + err = vfsub_rmdir(dir, path);
33531 + struct au_vfsub_rmdir_args args = {
33536 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33537 + if (unlikely(wkq_err))
33544 +/* ---------------------------------------------------------------------- */
33546 +struct notify_change_args {
33548 + struct path *path;
33549 + struct iattr *ia;
33550 + struct inode **delegated_inode;
33553 +static void call_notify_change(void *args)
33555 + struct notify_change_args *a = args;
33556 + struct inode *h_inode;
33558 + h_inode = d_inode(a->path->dentry);
33559 + IMustLock(h_inode);
33561 + *a->errp = -EPERM;
33562 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33564 + *a->errp = notify_change(a->path->dentry, a->ia,
33565 + a->delegated_inode);
33568 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33570 + AuTraceErr(*a->errp);
33573 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33574 + struct inode **delegated_inode)
33577 + struct notify_change_args args = {
33581 + .delegated_inode = delegated_inode
33584 + call_notify_change(&args);
33589 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33590 + struct inode **delegated_inode)
33592 + int err, wkq_err;
33593 + struct notify_change_args args = {
33597 + .delegated_inode = delegated_inode
33600 + wkq_err = au_wkq_wait(call_notify_change, &args);
33601 + if (unlikely(wkq_err))
33607 +/* ---------------------------------------------------------------------- */
33609 +struct unlink_args {
33611 + struct inode *dir;
33612 + struct path *path;
33613 + struct inode **delegated_inode;
33616 +static void call_unlink(void *args)
33618 + struct unlink_args *a = args;
33619 + struct dentry *d = a->path->dentry;
33620 + struct inode *h_inode;
33621 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33622 + && au_dcount(d) == 1);
33624 + IMustLock(a->dir);
33626 + a->path->dentry = d->d_parent;
33627 + *a->errp = security_path_unlink(a->path, d);
33628 + a->path->dentry = d;
33629 + if (unlikely(*a->errp))
33632 + if (!stop_sillyrename)
33635 + if (d_is_positive(d)) {
33636 + h_inode = d_inode(d);
33641 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33644 + struct path tmp = {
33645 + .dentry = d->d_parent,
33646 + .mnt = a->path->mnt
33648 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33651 + if (!stop_sillyrename)
33656 + AuTraceErr(*a->errp);
33660 + * @dir: must be locked.
33661 + * @dentry: target dentry.
33663 +int vfsub_unlink(struct inode *dir, struct path *path,
33664 + struct inode **delegated_inode, int force)
33667 + struct unlink_args args = {
33671 + .delegated_inode = delegated_inode
33675 + call_unlink(&args);
33679 + wkq_err = au_wkq_wait(call_unlink, &args);
33680 + if (unlikely(wkq_err))
33686 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33687 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33688 +++ linux/fs/aufs/vfsub.h 2021-02-22 23:30:37.702680911 +0100
33690 +/* SPDX-License-Identifier: GPL-2.0 */
33692 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33694 + * This program, aufs is free software; you can redistribute it and/or modify
33695 + * it under the terms of the GNU General Public License as published by
33696 + * the Free Software Foundation; either version 2 of the License, or
33697 + * (at your option) any later version.
33699 + * This program is distributed in the hope that it will be useful,
33700 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33701 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33702 + * GNU General Public License for more details.
33704 + * You should have received a copy of the GNU General Public License
33705 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33709 + * sub-routines for VFS
33712 +#ifndef __AUFS_VFSUB_H__
33713 +#define __AUFS_VFSUB_H__
33717 +#include <linux/fs.h>
33718 +#include <linux/mount.h>
33719 +#include <linux/posix_acl.h>
33720 +#include <linux/xattr.h>
33721 +#include "debug.h"
33723 +/* copied from linux/fs/internal.h */
33724 +/* todo: BAD approach!! */
33725 +extern void __mnt_drop_write(struct vfsmount *);
33726 +extern struct file *alloc_empty_file(int, const struct cred *);
33728 +/* ---------------------------------------------------------------------- */
33730 +/* lock subclass for lower inode */
33731 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33732 +/* reduce? gave up. */
33734 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33735 + AuLsc_I_PARENT, /* lower inode, parent first */
33736 + AuLsc_I_PARENT2, /* copyup dirs */
33737 + AuLsc_I_PARENT3, /* copyup wh */
33743 +/* to debug easier, do not make them inlined functions */
33744 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33745 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33747 +/* ---------------------------------------------------------------------- */
33749 +static inline void vfsub_drop_nlink(struct inode *inode)
33751 + AuDebugOn(!inode->i_nlink);
33752 + drop_nlink(inode);
33755 +static inline void vfsub_dead_dir(struct inode *inode)
33757 + AuDebugOn(!S_ISDIR(inode->i_mode));
33758 + inode->i_flags |= S_DEAD;
33759 + clear_nlink(inode);
33762 +static inline int vfsub_native_ro(struct inode *inode)
33764 + return sb_rdonly(inode->i_sb)
33765 + || IS_RDONLY(inode)
33766 + /* || IS_APPEND(inode) */
33767 + || IS_IMMUTABLE(inode);
33770 +#ifdef CONFIG_AUFS_BR_FUSE
33771 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33773 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33776 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33778 +/* ---------------------------------------------------------------------- */
33780 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33781 +struct file *vfsub_dentry_open(struct path *path, int flags);
33782 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33784 +struct vfsub_aopen_args {
33785 + struct file *file;
33786 + unsigned int open_flag;
33787 + umode_t create_mode;
33788 + struct au_branch *br;
33790 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33791 + struct vfsub_aopen_args *args);
33792 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33794 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33795 + struct dentry *parent, int len);
33796 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33799 +struct vfsub_lkup_one_args {
33800 + struct dentry **errp;
33801 + struct qstr *name;
33802 + struct dentry *parent;
33805 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33806 + struct dentry *parent)
33808 + return vfsub_lookup_one_len(name->name, parent, name->len);
33811 +void vfsub_call_lkup_one(void *args);
33813 +/* ---------------------------------------------------------------------- */
33815 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33820 + err = mnt_want_write(mnt);
33825 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33828 + mnt_drop_write(mnt);
33832 +#if 0 /* reserved */
33833 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33836 + mnt_drop_write_file(file);
33841 +/* ---------------------------------------------------------------------- */
33844 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33845 + struct dentry *d2, struct au_hinode *hdir2);
33846 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33847 + struct dentry *d2, struct au_hinode *hdir2);
33849 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33851 +int vfsub_symlink(struct inode *dir, struct path *path,
33852 + const char *symname);
33853 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33854 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33855 + struct path *path, struct inode **delegated_inode);
33856 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33857 + struct inode *hdir, struct path *path,
33858 + struct inode **delegated_inode, unsigned int flags);
33859 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33860 +int vfsub_rmdir(struct inode *dir, struct path *path);
33862 +/* ---------------------------------------------------------------------- */
33864 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33866 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33868 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33870 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33872 +int vfsub_flush(struct file *file, fl_owner_t id);
33873 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33875 +static inline loff_t vfsub_f_size_read(struct file *file)
33877 + return i_size_read(file_inode(file));
33880 +static inline unsigned int vfsub_file_flags(struct file *file)
33882 + unsigned int flags;
33884 + spin_lock(&file->f_lock);
33885 + flags = file->f_flags;
33886 + spin_unlock(&file->f_lock);
33891 +static inline int vfsub_file_execed(struct file *file)
33893 + /* todo: direct access f_flags */
33894 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33897 +#if 0 /* reserved */
33898 +static inline void vfsub_file_accessed(struct file *h_file)
33900 + file_accessed(h_file);
33901 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33905 +#if 0 /* reserved */
33906 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33907 + struct dentry *h_dentry)
33909 + struct path h_path = {
33910 + .dentry = h_dentry,
33913 + touch_atime(&h_path);
33914 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33918 +static inline int vfsub_update_time(struct inode *h_inode,
33919 + struct timespec64 *ts, int flags)
33921 + return update_time(h_inode, ts, flags);
33922 + /* no vfsub_update_h_iattr() since we don't have struct path */
33925 +#ifdef CONFIG_FS_POSIX_ACL
33926 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33930 + err = posix_acl_chmod(h_inode, h_mode);
33931 + if (err == -EOPNOTSUPP)
33936 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33939 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33940 + struct pipe_inode_info *pipe, size_t len,
33941 + unsigned int flags);
33942 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33943 + loff_t *ppos, size_t len, unsigned int flags);
33945 +static inline long vfsub_truncate(struct path *path, loff_t length)
33950 + err = vfs_truncate(path, length);
33955 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33956 + struct file *h_file);
33957 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33960 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33963 +static inline int vfsub_clone_file_range(struct file *src, struct file *dst,
33969 + err = vfs_clone_file_range(src, 0, dst, 0, len);
33975 +/* copy_file_range(2) is a systemcall */
33976 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33977 + struct file *dst, loff_t dst_pos,
33978 + size_t len, unsigned int flags)
33983 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33989 +/* ---------------------------------------------------------------------- */
33991 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33996 + err = vfs_llseek(file, offset, origin);
34001 +/* ---------------------------------------------------------------------- */
34003 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34004 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34005 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34006 + struct inode **delegated_inode);
34007 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34008 + struct inode **delegated_inode);
34009 +int vfsub_unlink(struct inode *dir, struct path *path,
34010 + struct inode **delegated_inode, int force);
34012 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34014 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34017 +/* ---------------------------------------------------------------------- */
34019 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
34020 + const void *value, size_t size, int flags)
34025 + err = vfs_setxattr(dentry, name, value, size, flags);
34031 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
34036 + err = vfs_removexattr(dentry, name);
34042 +#endif /* __KERNEL__ */
34043 +#endif /* __AUFS_VFSUB_H__ */
34044 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34045 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34046 +++ linux/fs/aufs/wbr_policy.c 2021-02-22 23:30:37.702680911 +0100
34048 +// SPDX-License-Identifier: GPL-2.0
34050 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34052 + * This program, aufs is free software; you can redistribute it and/or modify
34053 + * it under the terms of the GNU General Public License as published by
34054 + * the Free Software Foundation; either version 2 of the License, or
34055 + * (at your option) any later version.
34057 + * This program is distributed in the hope that it will be useful,
34058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34060 + * GNU General Public License for more details.
34062 + * You should have received a copy of the GNU General Public License
34063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34067 + * policies for selecting one among multiple writable branches
34070 +#include <linux/statfs.h>
34073 +/* subset of cpup_attr() */
34074 +static noinline_for_stack
34075 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34079 + struct inode *h_isrc;
34081 + h_isrc = d_inode(h_src);
34082 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34083 + ia.ia_mode = h_isrc->i_mode;
34084 + ia.ia_uid = h_isrc->i_uid;
34085 + ia.ia_gid = h_isrc->i_gid;
34086 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34087 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34088 + /* no delegation since it is just created */
34089 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34091 + /* is this nfs only? */
34092 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34093 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34094 + ia.ia_mode = h_isrc->i_mode;
34095 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34101 +#define AuCpdown_PARENT_OPQ 1
34102 +#define AuCpdown_WHED (1 << 1)
34103 +#define AuCpdown_MADE_DIR (1 << 2)
34104 +#define AuCpdown_DIROPQ (1 << 3)
34105 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34106 +#define au_fset_cpdown(flags, name) \
34107 + do { (flags) |= AuCpdown_##name; } while (0)
34108 +#define au_fclr_cpdown(flags, name) \
34109 + do { (flags) &= ~AuCpdown_##name; } while (0)
34111 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34112 + unsigned int *flags)
34115 + struct dentry *opq_dentry;
34117 + opq_dentry = au_diropq_create(dentry, bdst);
34118 + err = PTR_ERR(opq_dentry);
34119 + if (IS_ERR(opq_dentry))
34121 + dput(opq_dentry);
34122 + au_fset_cpdown(*flags, DIROPQ);
34128 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34129 + struct inode *dir, aufs_bindex_t bdst)
34132 + struct path h_path;
34133 + struct au_branch *br;
34135 + br = au_sbr(dentry->d_sb, bdst);
34136 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34137 + err = PTR_ERR(h_path.dentry);
34138 + if (IS_ERR(h_path.dentry))
34142 + if (d_is_positive(h_path.dentry)) {
34143 + h_path.mnt = au_br_mnt(br);
34144 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34147 + dput(h_path.dentry);
34153 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34154 + struct au_pin *pin,
34155 + struct dentry *h_parent, void *arg)
34158 + aufs_bindex_t bopq, btop;
34159 + struct path h_path;
34160 + struct dentry *parent;
34161 + struct inode *h_dir, *h_inode, *inode, *dir;
34162 + unsigned int *flags = arg;
34164 + btop = au_dbtop(dentry);
34165 + /* dentry is di-locked */
34166 + parent = dget_parent(dentry);
34167 + dir = d_inode(parent);
34168 + h_dir = d_inode(h_parent);
34169 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34170 + IMustLock(h_dir);
34172 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34173 + if (unlikely(err < 0))
34175 + h_path.dentry = au_h_dptr(dentry, bdst);
34176 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34177 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34178 + if (unlikely(err))
34180 + au_fset_cpdown(*flags, MADE_DIR);
34182 + bopq = au_dbdiropq(dentry);
34183 + au_fclr_cpdown(*flags, WHED);
34184 + au_fclr_cpdown(*flags, DIROPQ);
34185 + if (au_dbwh(dentry) == bdst)
34186 + au_fset_cpdown(*flags, WHED);
34187 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34188 + au_fset_cpdown(*flags, PARENT_OPQ);
34189 + h_inode = d_inode(h_path.dentry);
34190 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34191 + if (au_ftest_cpdown(*flags, WHED)) {
34192 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34193 + if (unlikely(err)) {
34194 + inode_unlock(h_inode);
34199 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34200 + inode_unlock(h_inode);
34201 + if (unlikely(err))
34204 + if (au_ftest_cpdown(*flags, WHED)) {
34205 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34206 + if (unlikely(err))
34210 + inode = d_inode(dentry);
34211 + if (au_ibbot(inode) < bdst)
34212 + au_set_ibbot(inode, bdst);
34213 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34214 + au_hi_flags(inode, /*isdir*/1));
34215 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34216 + goto out; /* success */
34220 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34221 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34222 + rerr = au_diropq_remove(dentry, bdst);
34223 + inode_unlock(h_inode);
34224 + if (unlikely(rerr)) {
34225 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34226 + dentry, bdst, rerr);
34232 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34233 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34234 + if (unlikely(rerr)) {
34235 + AuIOErr("failed removing %pd b%d (%d)\n",
34236 + dentry, bdst, rerr);
34241 + au_set_h_dptr(dentry, bdst, NULL);
34242 + if (au_dbbot(dentry) == bdst)
34243 + au_update_dbbot(dentry);
34249 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34252 + unsigned int flags;
34255 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34260 +/* ---------------------------------------------------------------------- */
34262 +/* policies for create */
34264 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34266 + int err, i, j, ndentry;
34267 + aufs_bindex_t bopq;
34268 + struct au_dcsub_pages dpages;
34269 + struct au_dpage *dpage;
34270 + struct dentry **dentries, *parent, *d;
34272 + err = au_dpages_init(&dpages, GFP_NOFS);
34273 + if (unlikely(err))
34275 + parent = dget_parent(dentry);
34276 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34277 + if (unlikely(err))
34281 + for (i = 0; i < dpages.ndpage; i++) {
34282 + dpage = dpages.dpages + i;
34283 + dentries = dpage->dentries;
34284 + ndentry = dpage->ndentry;
34285 + for (j = 0; j < ndentry; j++) {
34287 + di_read_lock_parent2(d, !AuLock_IR);
34288 + bopq = au_dbdiropq(d);
34289 + di_read_unlock(d, !AuLock_IR);
34290 + if (bopq >= 0 && bopq < err)
34297 + au_dpages_free(&dpages);
34302 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34304 + for (; bindex >= 0; bindex--)
34305 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34310 +/* top down parent */
34311 +static int au_wbr_create_tdp(struct dentry *dentry,
34312 + unsigned int flags __maybe_unused)
34315 + aufs_bindex_t btop, bindex;
34316 + struct super_block *sb;
34317 + struct dentry *parent, *h_parent;
34319 + sb = dentry->d_sb;
34320 + btop = au_dbtop(dentry);
34322 + if (!au_br_rdonly(au_sbr(sb, btop)))
34326 + parent = dget_parent(dentry);
34327 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34328 + h_parent = au_h_dptr(parent, bindex);
34329 + if (!h_parent || d_is_negative(h_parent))
34332 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34339 + /* bottom up here */
34340 + if (unlikely(err < 0)) {
34341 + err = au_wbr_bu(sb, btop - 1);
34343 + err = au_wbr_nonopq(dentry, err);
34347 + AuDbg("b%d\n", err);
34351 +/* ---------------------------------------------------------------------- */
34353 +/* an exception for the policy other than tdp */
34354 +static int au_wbr_create_exp(struct dentry *dentry)
34357 + aufs_bindex_t bwh, bdiropq;
34358 + struct dentry *parent;
34361 + bwh = au_dbwh(dentry);
34362 + parent = dget_parent(dentry);
34363 + bdiropq = au_dbdiropq(parent);
34365 + if (bdiropq >= 0)
34366 + err = min(bdiropq, bwh);
34369 + AuDbg("%d\n", err);
34370 + } else if (bdiropq >= 0) {
34372 + AuDbg("%d\n", err);
34377 + err = au_wbr_nonopq(dentry, err);
34379 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34382 + AuDbg("%d\n", err);
34386 +/* ---------------------------------------------------------------------- */
34389 +static int au_wbr_create_init_rr(struct super_block *sb)
34393 + err = au_wbr_bu(sb, au_sbbot(sb));
34394 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34397 + AuDbg("b%d\n", err);
34401 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34405 + aufs_bindex_t bindex, bbot;
34406 + struct super_block *sb;
34409 + err = au_wbr_create_exp(dentry);
34413 + sb = dentry->d_sb;
34414 + next = &au_sbi(sb)->si_wbr_rr_next;
34415 + bbot = au_sbbot(sb);
34417 + for (bindex = 0; bindex <= bbot; bindex++) {
34418 + if (!au_ftest_wbr(flags, DIR)) {
34419 + err = atomic_dec_return(next) + 1;
34420 + /* modulo for 0 is meaningless */
34421 + if (unlikely(!err))
34422 + err = atomic_dec_return(next) + 1;
34424 + err = atomic_read(next);
34425 + AuDbg("%d\n", err);
34428 + AuDbg("%d\n", err);
34429 + if (!au_br_rdonly(au_sbr(sb, err)))
34435 + err = au_wbr_nonopq(dentry, err);
34438 + AuDbg("%d\n", err);
34442 +/* ---------------------------------------------------------------------- */
34444 +/* most free space */
34445 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34447 + struct super_block *sb;
34448 + struct au_branch *br;
34449 + struct au_wbr_mfs *mfs;
34450 + struct dentry *h_parent;
34451 + aufs_bindex_t bindex, bbot;
34453 + unsigned long long b, bavail;
34454 + struct path h_path;
34455 + /* reduce the stack usage */
34456 + struct kstatfs *st;
34458 + st = kmalloc(sizeof(*st), GFP_NOFS);
34459 + if (unlikely(!st)) {
34460 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34465 + sb = dentry->d_sb;
34466 + mfs = &au_sbi(sb)->si_wbr_mfs;
34467 + MtxMustLock(&mfs->mfs_lock);
34468 + mfs->mfs_bindex = -EROFS;
34469 + mfs->mfsrr_bytes = 0;
34472 + bbot = au_sbbot(sb);
34474 + bindex = au_dbtop(parent);
34475 + bbot = au_dbtaildir(parent);
34478 + for (; bindex <= bbot; bindex++) {
34480 + h_parent = au_h_dptr(parent, bindex);
34481 + if (!h_parent || d_is_negative(h_parent))
34484 + br = au_sbr(sb, bindex);
34485 + if (au_br_rdonly(br))
34488 + /* sb->s_root for NFS is unreliable */
34489 + h_path.mnt = au_br_mnt(br);
34490 + h_path.dentry = h_path.mnt->mnt_root;
34491 + err = vfs_statfs(&h_path, st);
34492 + if (unlikely(err)) {
34493 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34497 + /* when the available size is equal, select the lower one */
34498 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34499 + || sizeof(b) < sizeof(st->f_bsize));
34500 + b = st->f_bavail * st->f_bsize;
34501 + br->br_wbr->wbr_bytes = b;
34502 + if (b >= bavail) {
34504 + mfs->mfs_bindex = bindex;
34505 + mfs->mfs_jiffy = jiffies;
34509 + mfs->mfsrr_bytes = bavail;
34510 + AuDbg("b%d\n", mfs->mfs_bindex);
34511 + au_kfree_rcu(st);
34514 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34517 + struct dentry *parent;
34518 + struct super_block *sb;
34519 + struct au_wbr_mfs *mfs;
34521 + err = au_wbr_create_exp(dentry);
34525 + sb = dentry->d_sb;
34527 + if (au_ftest_wbr(flags, PARENT))
34528 + parent = dget_parent(dentry);
34529 + mfs = &au_sbi(sb)->si_wbr_mfs;
34530 + mutex_lock(&mfs->mfs_lock);
34531 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34532 + || mfs->mfs_bindex < 0
34533 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34534 + au_mfs(dentry, parent);
34535 + mutex_unlock(&mfs->mfs_lock);
34536 + err = mfs->mfs_bindex;
34540 + err = au_wbr_nonopq(dentry, err);
34543 + AuDbg("b%d\n", err);
34547 +static int au_wbr_create_init_mfs(struct super_block *sb)
34549 + struct au_wbr_mfs *mfs;
34551 + mfs = &au_sbi(sb)->si_wbr_mfs;
34552 + mutex_init(&mfs->mfs_lock);
34553 + mfs->mfs_jiffy = 0;
34554 + mfs->mfs_bindex = -EROFS;
34559 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34561 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34565 +/* ---------------------------------------------------------------------- */
34567 +/* top down regardless parent, and then mfs */
34568 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34569 + unsigned int flags __maybe_unused)
34572 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34573 + unsigned long long watermark;
34574 + struct super_block *sb;
34575 + struct au_wbr_mfs *mfs;
34576 + struct au_branch *br;
34577 + struct dentry *parent;
34579 + sb = dentry->d_sb;
34580 + mfs = &au_sbi(sb)->si_wbr_mfs;
34581 + mutex_lock(&mfs->mfs_lock);
34582 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34583 + || mfs->mfs_bindex < 0)
34584 + au_mfs(dentry, /*parent*/NULL);
34585 + watermark = mfs->mfsrr_watermark;
34586 + bmfs = mfs->mfs_bindex;
34587 + mutex_unlock(&mfs->mfs_lock);
34589 + /* another style of au_wbr_create_exp() */
34590 + bwh = au_dbwh(dentry);
34591 + parent = dget_parent(dentry);
34592 + btail = au_dbtaildir(parent);
34593 + if (bwh >= 0 && bwh < btail)
34596 + err = au_wbr_nonopq(dentry, btail);
34597 + if (unlikely(err < 0))
34601 + for (bindex = 0; bindex <= btail; bindex++) {
34602 + br = au_sbr(sb, bindex);
34603 + if (au_br_rdonly(br))
34605 + if (br->br_wbr->wbr_bytes > watermark) {
34616 + AuDbg("b%d\n", err);
34620 +/* ---------------------------------------------------------------------- */
34622 +/* most free space and then round robin */
34623 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34626 + struct au_wbr_mfs *mfs;
34628 + err = au_wbr_create_mfs(dentry, flags);
34630 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34631 + mutex_lock(&mfs->mfs_lock);
34632 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34633 + err = au_wbr_create_rr(dentry, flags);
34634 + mutex_unlock(&mfs->mfs_lock);
34637 + AuDbg("b%d\n", err);
34641 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34645 + au_wbr_create_init_mfs(sb); /* ignore */
34646 + err = au_wbr_create_init_rr(sb);
34651 +/* ---------------------------------------------------------------------- */
34653 +/* top down parent and most free space */
34654 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34657 + unsigned long long b;
34658 + aufs_bindex_t bindex, btop, bbot;
34659 + struct super_block *sb;
34660 + struct dentry *parent, *h_parent;
34661 + struct au_branch *br;
34663 + err = au_wbr_create_tdp(dentry, flags);
34664 + if (unlikely(err < 0))
34666 + parent = dget_parent(dentry);
34667 + btop = au_dbtop(parent);
34668 + bbot = au_dbtaildir(parent);
34669 + if (btop == bbot)
34670 + goto out_parent; /* success */
34672 + e2 = au_wbr_create_mfs(dentry, flags);
34674 + goto out_parent; /* success */
34676 + /* when the available size is equal, select upper one */
34677 + sb = dentry->d_sb;
34678 + br = au_sbr(sb, err);
34679 + b = br->br_wbr->wbr_bytes;
34680 + AuDbg("b%d, %llu\n", err, b);
34682 + for (bindex = btop; bindex <= bbot; bindex++) {
34683 + h_parent = au_h_dptr(parent, bindex);
34684 + if (!h_parent || d_is_negative(h_parent))
34687 + br = au_sbr(sb, bindex);
34688 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34689 + b = br->br_wbr->wbr_bytes;
34691 + AuDbg("b%d, %llu\n", err, b);
34696 + err = au_wbr_nonopq(dentry, err);
34701 + AuDbg("b%d\n", err);
34705 +/* ---------------------------------------------------------------------- */
34708 + * - top down parent
34709 + * - most free space with parent
34710 + * - most free space round-robin regardless parent
34712 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34715 + unsigned long long watermark;
34716 + struct super_block *sb;
34717 + struct au_branch *br;
34718 + struct au_wbr_mfs *mfs;
34720 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34721 + if (unlikely(err < 0))
34724 + sb = dentry->d_sb;
34725 + br = au_sbr(sb, err);
34726 + mfs = &au_sbi(sb)->si_wbr_mfs;
34727 + mutex_lock(&mfs->mfs_lock);
34728 + watermark = mfs->mfsrr_watermark;
34729 + mutex_unlock(&mfs->mfs_lock);
34730 + if (br->br_wbr->wbr_bytes < watermark)
34731 + /* regardless the parent dir */
34732 + err = au_wbr_create_mfsrr(dentry, flags);
34735 + AuDbg("b%d\n", err);
34739 +/* ---------------------------------------------------------------------- */
34741 +/* policies for copyup */
34743 +/* top down parent */
34744 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34746 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34749 +/* bottom up parent */
34750 +static int au_wbr_copyup_bup(struct dentry *dentry)
34753 + aufs_bindex_t bindex, btop;
34754 + struct dentry *parent, *h_parent;
34755 + struct super_block *sb;
34758 + sb = dentry->d_sb;
34759 + parent = dget_parent(dentry);
34760 + btop = au_dbtop(parent);
34761 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34762 + h_parent = au_h_dptr(parent, bindex);
34763 + if (!h_parent || d_is_negative(h_parent))
34766 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34773 + /* bottom up here */
34774 + if (unlikely(err < 0))
34775 + err = au_wbr_bu(sb, btop - 1);
34777 + AuDbg("b%d\n", err);
34782 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34786 + err = au_wbr_bu(dentry->d_sb, btop);
34787 + AuDbg("b%d\n", err);
34789 + err = au_wbr_nonopq(dentry, err);
34791 + AuDbg("b%d\n", err);
34795 +static int au_wbr_copyup_bu(struct dentry *dentry)
34798 + aufs_bindex_t btop;
34800 + btop = au_dbtop(dentry);
34801 + err = au_wbr_do_copyup_bu(dentry, btop);
34805 +/* ---------------------------------------------------------------------- */
34807 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34808 + [AuWbrCopyup_TDP] = {
34809 + .copyup = au_wbr_copyup_tdp
34811 + [AuWbrCopyup_BUP] = {
34812 + .copyup = au_wbr_copyup_bup
34814 + [AuWbrCopyup_BU] = {
34815 + .copyup = au_wbr_copyup_bu
34819 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34820 + [AuWbrCreate_TDP] = {
34821 + .create = au_wbr_create_tdp
34823 + [AuWbrCreate_RR] = {
34824 + .create = au_wbr_create_rr,
34825 + .init = au_wbr_create_init_rr
34827 + [AuWbrCreate_MFS] = {
34828 + .create = au_wbr_create_mfs,
34829 + .init = au_wbr_create_init_mfs,
34830 + .fin = au_wbr_create_fin_mfs
34832 + [AuWbrCreate_MFSV] = {
34833 + .create = au_wbr_create_mfs,
34834 + .init = au_wbr_create_init_mfs,
34835 + .fin = au_wbr_create_fin_mfs
34837 + [AuWbrCreate_MFSRR] = {
34838 + .create = au_wbr_create_mfsrr,
34839 + .init = au_wbr_create_init_mfsrr,
34840 + .fin = au_wbr_create_fin_mfs
34842 + [AuWbrCreate_MFSRRV] = {
34843 + .create = au_wbr_create_mfsrr,
34844 + .init = au_wbr_create_init_mfsrr,
34845 + .fin = au_wbr_create_fin_mfs
34847 + [AuWbrCreate_TDMFS] = {
34848 + .create = au_wbr_create_tdmfs,
34849 + .init = au_wbr_create_init_mfs,
34850 + .fin = au_wbr_create_fin_mfs
34852 + [AuWbrCreate_TDMFSV] = {
34853 + .create = au_wbr_create_tdmfs,
34854 + .init = au_wbr_create_init_mfs,
34855 + .fin = au_wbr_create_fin_mfs
34857 + [AuWbrCreate_PMFS] = {
34858 + .create = au_wbr_create_pmfs,
34859 + .init = au_wbr_create_init_mfs,
34860 + .fin = au_wbr_create_fin_mfs
34862 + [AuWbrCreate_PMFSV] = {
34863 + .create = au_wbr_create_pmfs,
34864 + .init = au_wbr_create_init_mfs,
34865 + .fin = au_wbr_create_fin_mfs
34867 + [AuWbrCreate_PMFSRR] = {
34868 + .create = au_wbr_create_pmfsrr,
34869 + .init = au_wbr_create_init_mfsrr,
34870 + .fin = au_wbr_create_fin_mfs
34872 + [AuWbrCreate_PMFSRRV] = {
34873 + .create = au_wbr_create_pmfsrr,
34874 + .init = au_wbr_create_init_mfsrr,
34875 + .fin = au_wbr_create_fin_mfs
34878 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34879 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34880 +++ linux/fs/aufs/whout.c 2021-02-22 23:30:37.702680911 +0100
34882 +// SPDX-License-Identifier: GPL-2.0
34884 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34886 + * This program, aufs is free software; you can redistribute it and/or modify
34887 + * it under the terms of the GNU General Public License as published by
34888 + * the Free Software Foundation; either version 2 of the License, or
34889 + * (at your option) any later version.
34891 + * This program is distributed in the hope that it will be useful,
34892 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34893 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34894 + * GNU General Public License for more details.
34896 + * You should have received a copy of the GNU General Public License
34897 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34901 + * whiteout for logical deletion and opaque directory
34906 +#define WH_MASK 0444
34909 + * If a directory contains this file, then it is opaque. We start with the
34910 + * .wh. flag so that it is blocked by lookup.
34912 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34913 + sizeof(AUFS_WH_DIROPQ) - 1);
34916 + * generate whiteout name, which is NOT terminated by NULL.
34917 + * @name: original d_name.name
34918 + * @len: original d_name.len
34919 + * @wh: whiteout qstr
34920 + * returns zero when succeeds, otherwise error.
34921 + * succeeded value as wh->name should be freed by kfree().
34923 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34927 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34928 + return -ENAMETOOLONG;
34930 + wh->len = name->len + AUFS_WH_PFX_LEN;
34931 + p = kmalloc(wh->len, GFP_NOFS);
34934 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34935 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34942 +/* ---------------------------------------------------------------------- */
34945 + * test if the @wh_name exists under @h_parent.
34946 + * @try_sio specifies the necessary of super-io.
34948 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34951 + struct dentry *wh_dentry;
34954 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34956 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34957 + err = PTR_ERR(wh_dentry);
34958 + if (IS_ERR(wh_dentry)) {
34959 + if (err == -ENAMETOOLONG)
34965 + if (d_is_negative(wh_dentry))
34966 + goto out_wh; /* success */
34969 + if (d_is_reg(wh_dentry))
34970 + goto out_wh; /* success */
34973 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34974 + wh_dentry, d_inode(wh_dentry)->i_mode);
34983 + * test if the @h_dentry sets opaque or not.
34985 +int au_diropq_test(struct dentry *h_dentry)
34988 + struct inode *h_dir;
34990 + h_dir = d_inode(h_dentry);
34991 + err = au_wh_test(h_dentry, &diropq_name,
34992 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34997 + * returns a negative dentry whose name is unique and temporary.
34999 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35000 + struct qstr *prefix)
35002 + struct dentry *dentry;
35004 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35006 + /* strict atomic_t is unnecessary here */
35007 + static unsigned short cnt;
35010 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35013 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35014 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35015 + dentry = ERR_PTR(-ENAMETOOLONG);
35016 + if (unlikely(qs.len > NAME_MAX))
35018 + dentry = ERR_PTR(-ENOMEM);
35019 + name = kmalloc(qs.len + 1, GFP_NOFS);
35020 + if (unlikely(!name))
35024 + /* doubly whiteout-ed */
35025 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35026 + p = name + AUFS_WH_PFX_LEN * 2;
35027 + memcpy(p, prefix->name, prefix->len);
35028 + p += prefix->len;
35030 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35033 + for (i = 0; i < 3; i++) {
35034 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35035 + dentry = au_sio_lkup_one(&qs, h_parent);
35036 + if (IS_ERR(dentry) || d_is_negative(dentry))
35040 + /* pr_warn("could not get random name\n"); */
35041 + dentry = ERR_PTR(-EEXIST);
35042 + AuDbg("%.*s\n", AuLNPair(&qs));
35046 + if (name != defname)
35047 + au_kfree_try_rcu(name);
35049 + AuTraceErrPtr(dentry);
35054 + * rename the @h_dentry on @br to the whiteouted temporary name.
35056 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35059 + struct path h_path = {
35060 + .mnt = au_br_mnt(br)
35062 + struct inode *h_dir, *delegated;
35063 + struct dentry *h_parent;
35065 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35066 + h_dir = d_inode(h_parent);
35067 + IMustLock(h_dir);
35069 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35070 + err = PTR_ERR(h_path.dentry);
35071 + if (IS_ERR(h_path.dentry))
35074 + /* under the same dir, no need to lock_rename() */
35075 + delegated = NULL;
35076 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35079 + if (unlikely(err == -EWOULDBLOCK)) {
35080 + pr_warn("cannot retry for NFSv4 delegation"
35081 + " for an internal rename\n");
35084 + dput(h_path.dentry);
35091 +/* ---------------------------------------------------------------------- */
35093 + * functions for removing a whiteout
35096 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35099 + struct inode *delegated;
35102 + * forces superio when the dir has a sticky bit.
35103 + * this may be a violation of unix fs semantics.
35105 + force = (h_dir->i_mode & S_ISVTX)
35106 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35107 + delegated = NULL;
35108 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35109 + if (unlikely(err == -EWOULDBLOCK)) {
35110 + pr_warn("cannot retry for NFSv4 delegation"
35111 + " for an internal unlink\n");
35117 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35118 + struct dentry *dentry)
35122 + err = do_unlink_wh(h_dir, h_path);
35123 + if (!err && dentry)
35124 + au_set_dbwh(dentry, -1);
35129 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35130 + struct au_branch *br)
35133 + struct path h_path = {
35134 + .mnt = au_br_mnt(br)
35138 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35139 + if (IS_ERR(h_path.dentry))
35140 + err = PTR_ERR(h_path.dentry);
35142 + if (d_is_reg(h_path.dentry))
35143 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35144 + dput(h_path.dentry);
35150 +/* ---------------------------------------------------------------------- */
35152 + * initialize/clean whiteout for a branch
35155 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35159 + struct inode *delegated;
35161 + if (d_is_negative(whpath->dentry))
35165 + err = vfsub_rmdir(h_dir, whpath);
35167 + delegated = NULL;
35168 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35169 + if (unlikely(err == -EWOULDBLOCK)) {
35170 + pr_warn("cannot retry for NFSv4 delegation"
35171 + " for an internal unlink\n");
35175 + if (unlikely(err))
35176 + pr_warn("failed removing %pd (%d), ignored.\n",
35177 + whpath->dentry, err);
35180 +static int test_linkable(struct dentry *h_root)
35182 + struct inode *h_dir = d_inode(h_root);
35184 + if (h_dir->i_op->link)
35187 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35188 + h_root, au_sbtype(h_root->d_sb));
35189 + return -ENOSYS; /* the branch doesn't have its ->link() */
35192 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35193 +static int au_whdir(struct inode *h_dir, struct path *path)
35198 + if (d_is_negative(path->dentry)) {
35201 + if (au_test_nfs(path->dentry->d_sb))
35203 + err = vfsub_mkdir(h_dir, path, mode);
35204 + } else if (d_is_dir(path->dentry))
35207 + pr_err("unknown %pd exists\n", path->dentry);
35212 +struct au_wh_base {
35213 + const struct qstr *name;
35214 + struct dentry *dentry;
35217 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35218 + struct path *h_path)
35220 + h_path->dentry = base[AuBrWh_BASE].dentry;
35221 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35222 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35223 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35224 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35225 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35229 + * returns tri-state,
35230 + * minus: error, caller should print the message
35232 + * plus: error, caller should NOT print the message
35234 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35235 + int do_plink, struct au_wh_base base[],
35236 + struct path *h_path)
35239 + struct inode *h_dir;
35241 + h_dir = d_inode(h_root);
35242 + h_path->dentry = base[AuBrWh_BASE].dentry;
35243 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35244 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35246 + err = test_linkable(h_root);
35247 + if (unlikely(err)) {
35252 + err = au_whdir(h_dir, h_path);
35253 + if (unlikely(err))
35255 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35257 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35258 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35259 + err = au_whdir(h_dir, h_path);
35260 + if (unlikely(err))
35262 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35269 + * for the moment, aufs supports the branch filesystem which does not support
35270 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35271 + * copyup failed. finally, such filesystem will not be used as the writable
35274 + * returns tri-state, see above.
35276 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35277 + int do_plink, struct au_wh_base base[],
35278 + struct path *h_path)
35281 + struct inode *h_dir;
35283 + WbrWhMustWriteLock(wbr);
35285 + err = test_linkable(h_root);
35286 + if (unlikely(err)) {
35292 + * todo: should this create be done in /sbin/mount.aufs helper?
35295 + h_dir = d_inode(h_root);
35296 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35297 + h_path->dentry = base[AuBrWh_BASE].dentry;
35298 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35299 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35302 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35303 + if (unlikely(err))
35306 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35308 + err = au_whdir(h_dir, h_path);
35309 + if (unlikely(err))
35311 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35313 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35314 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35316 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35317 + err = au_whdir(h_dir, h_path);
35318 + if (unlikely(err))
35320 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35327 + * initialize the whiteout base file/dir for @br.
35329 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35332 + const unsigned char do_plink
35333 + = !!au_opt_test(au_mntflags(sb), PLINK);
35334 + struct inode *h_dir;
35335 + struct path path = br->br_path;
35336 + struct dentry *h_root = path.dentry;
35337 + struct au_wbr *wbr = br->br_wbr;
35338 + static const struct qstr base_name[] = {
35339 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35340 + sizeof(AUFS_BASE_NAME) - 1),
35341 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35342 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35343 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35344 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35346 + struct au_wh_base base[] = {
35347 + [AuBrWh_BASE] = {
35348 + .name = base_name + AuBrWh_BASE,
35351 + [AuBrWh_PLINK] = {
35352 + .name = base_name + AuBrWh_PLINK,
35355 + [AuBrWh_ORPH] = {
35356 + .name = base_name + AuBrWh_ORPH,
35362 + WbrWhMustWriteLock(wbr);
35364 + for (i = 0; i < AuBrWh_Last; i++) {
35365 + /* doubly whiteouted */
35366 + struct dentry *d;
35368 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35369 + err = PTR_ERR(d);
35373 + base[i].dentry = d;
35375 + && wbr->wbr_wh[i]
35376 + && wbr->wbr_wh[i] != base[i].dentry);
35380 + for (i = 0; i < AuBrWh_Last; i++) {
35381 + dput(wbr->wbr_wh[i]);
35382 + wbr->wbr_wh[i] = NULL;
35386 + if (!au_br_writable(br->br_perm)) {
35387 + h_dir = d_inode(h_root);
35388 + au_wh_init_ro(h_dir, base, &path);
35389 + } else if (!au_br_wh_linkable(br->br_perm)) {
35390 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35396 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35402 + goto out; /* success */
35405 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35406 + err, h_root, au_sbtype(h_root->d_sb));
35408 + for (i = 0; i < AuBrWh_Last; i++)
35409 + dput(base[i].dentry);
35413 +/* ---------------------------------------------------------------------- */
35415 + * whiteouts are all hard-linked usually.
35416 + * when its link count reaches a ceiling, we create a new whiteout base
35417 + * asynchronously.
35420 +struct reinit_br_wh {
35421 + struct super_block *sb;
35422 + struct au_branch *br;
35425 +static void reinit_br_wh(void *arg)
35428 + aufs_bindex_t bindex;
35429 + struct path h_path;
35430 + struct reinit_br_wh *a = arg;
35431 + struct au_wbr *wbr;
35432 + struct inode *dir, *delegated;
35433 + struct dentry *h_root;
35434 + struct au_hinode *hdir;
35437 + wbr = a->br->br_wbr;
35438 + /* big aufs lock */
35439 + si_noflush_write_lock(a->sb);
35440 + if (!au_br_writable(a->br->br_perm))
35442 + bindex = au_br_index(a->sb, a->br->br_id);
35443 + if (unlikely(bindex < 0))
35446 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35447 + dir = d_inode(a->sb->s_root);
35448 + hdir = au_hi(dir, bindex);
35449 + h_root = au_h_dptr(a->sb->s_root, bindex);
35450 + AuDebugOn(h_root != au_br_dentry(a->br));
35452 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35453 + wbr_wh_write_lock(wbr);
35454 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35457 + h_path.dentry = wbr->wbr_whbase;
35458 + h_path.mnt = au_br_mnt(a->br);
35459 + delegated = NULL;
35460 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35462 + if (unlikely(err == -EWOULDBLOCK)) {
35463 + pr_warn("cannot retry for NFSv4 delegation"
35464 + " for an internal unlink\n");
35468 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35471 + dput(wbr->wbr_whbase);
35472 + wbr->wbr_whbase = NULL;
35474 + err = au_wh_init(a->br, a->sb);
35475 + wbr_wh_write_unlock(wbr);
35476 + au_hn_inode_unlock(hdir);
35477 + di_read_unlock(a->sb->s_root, AuLock_IR);
35479 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35483 + atomic_dec(&wbr->wbr_wh_running);
35484 + au_lcnt_dec(&a->br->br_count);
35485 + si_write_unlock(a->sb);
35486 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35488 + if (unlikely(err))
35489 + AuIOErr("err %d\n", err);
35492 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35494 + int do_dec, wkq_err;
35495 + struct reinit_br_wh *arg;
35498 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35501 + /* ignore ENOMEM */
35502 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35505 + * dec(wh_running), kfree(arg) and dec(br_count)
35506 + * in reinit function
35510 + au_lcnt_inc(&br->br_count);
35511 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35512 + if (unlikely(wkq_err)) {
35513 + atomic_dec(&br->br_wbr->wbr_wh_running);
35514 + au_lcnt_dec(&br->br_count);
35515 + au_kfree_rcu(arg);
35522 + atomic_dec(&br->br_wbr->wbr_wh_running);
35525 +/* ---------------------------------------------------------------------- */
35528 + * create the whiteout @wh.
35530 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35531 + struct dentry *wh)
35534 + struct path h_path = {
35537 + struct au_branch *br;
35538 + struct au_wbr *wbr;
35539 + struct dentry *h_parent;
35540 + struct inode *h_dir, *delegated;
35542 + h_parent = wh->d_parent; /* dir inode is locked */
35543 + h_dir = d_inode(h_parent);
35544 + IMustLock(h_dir);
35546 + br = au_sbr(sb, bindex);
35547 + h_path.mnt = au_br_mnt(br);
35548 + wbr = br->br_wbr;
35549 + wbr_wh_read_lock(wbr);
35550 + if (wbr->wbr_whbase) {
35551 + delegated = NULL;
35552 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35553 + if (unlikely(err == -EWOULDBLOCK)) {
35554 + pr_warn("cannot retry for NFSv4 delegation"
35555 + " for an internal link\n");
35558 + if (!err || err != -EMLINK)
35561 + /* link count full. re-initialize br_whbase. */
35562 + kick_reinit_br_wh(sb, br);
35565 + /* return this error in this context */
35566 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35568 + au_fhsm_wrote(sb, bindex, /*force*/0);
35571 + wbr_wh_read_unlock(wbr);
35575 +/* ---------------------------------------------------------------------- */
35578 + * create or remove the diropq.
35580 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35581 + unsigned int flags)
35583 + struct dentry *opq_dentry, *h_dentry;
35584 + struct super_block *sb;
35585 + struct au_branch *br;
35588 + sb = dentry->d_sb;
35589 + br = au_sbr(sb, bindex);
35590 + h_dentry = au_h_dptr(dentry, bindex);
35591 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35592 + if (IS_ERR(opq_dentry))
35595 + if (au_ftest_diropq(flags, CREATE)) {
35596 + err = link_or_create_wh(sb, bindex, opq_dentry);
35598 + au_set_dbdiropq(dentry, bindex);
35599 + goto out; /* success */
35602 + struct path tmp = {
35603 + .dentry = opq_dentry,
35604 + .mnt = au_br_mnt(br)
35606 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35608 + au_set_dbdiropq(dentry, -1);
35610 + dput(opq_dentry);
35611 + opq_dentry = ERR_PTR(err);
35614 + return opq_dentry;
35617 +struct do_diropq_args {
35618 + struct dentry **errp;
35619 + struct dentry *dentry;
35620 + aufs_bindex_t bindex;
35621 + unsigned int flags;
35624 +static void call_do_diropq(void *args)
35626 + struct do_diropq_args *a = args;
35627 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35630 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35631 + unsigned int flags)
35633 + struct dentry *diropq, *h_dentry;
35635 + h_dentry = au_h_dptr(dentry, bindex);
35636 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35637 + diropq = do_diropq(dentry, bindex, flags);
35640 + struct do_diropq_args args = {
35642 + .dentry = dentry,
35643 + .bindex = bindex,
35647 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35648 + if (unlikely(wkq_err))
35649 + diropq = ERR_PTR(wkq_err);
35655 +/* ---------------------------------------------------------------------- */
35658 + * lookup whiteout dentry.
35659 + * @h_parent: lower parent dentry which must exist and be locked
35660 + * @base_name: name of dentry which will be whiteouted
35661 + * returns dentry for whiteout.
35663 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35664 + struct au_branch *br)
35667 + struct qstr wh_name;
35668 + struct dentry *wh_dentry;
35670 + err = au_wh_name_alloc(&wh_name, base_name);
35671 + wh_dentry = ERR_PTR(err);
35673 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35674 + au_kfree_try_rcu(wh_name.name);
35676 + return wh_dentry;
35680 + * link/create a whiteout for @dentry on @bindex.
35682 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35683 + struct dentry *h_parent)
35685 + struct dentry *wh_dentry;
35686 + struct super_block *sb;
35689 + sb = dentry->d_sb;
35690 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35691 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35692 + err = link_or_create_wh(sb, bindex, wh_dentry);
35694 + au_set_dbwh(dentry, bindex);
35695 + au_fhsm_wrote(sb, bindex, /*force*/0);
35698 + wh_dentry = ERR_PTR(err);
35702 + return wh_dentry;
35705 +/* ---------------------------------------------------------------------- */
35707 +/* Delete all whiteouts in this directory on branch bindex. */
35708 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35709 + aufs_bindex_t bindex, struct au_branch *br)
35712 + unsigned long ul, n;
35713 + struct qstr wh_name;
35715 + struct hlist_head *head;
35716 + struct au_vdir_wh *pos;
35717 + struct au_vdir_destr *str;
35720 + p = (void *)__get_free_page(GFP_NOFS);
35721 + wh_name.name = p;
35722 + if (unlikely(!wh_name.name))
35726 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35727 + p += AUFS_WH_PFX_LEN;
35728 + n = whlist->nh_num;
35729 + head = whlist->nh_head;
35730 + for (ul = 0; !err && ul < n; ul++, head++) {
35731 + hlist_for_each_entry(pos, head, wh_hash) {
35732 + if (pos->wh_bindex != bindex)
35735 + str = &pos->wh_str;
35736 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35737 + memcpy(p, str->name, str->len);
35738 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35739 + err = unlink_wh_name(h_dentry, &wh_name, br);
35744 + AuIOErr("whiteout name too long %.*s\n",
35745 + str->len, str->name);
35750 + free_page((unsigned long)wh_name.name);
35756 +struct del_wh_children_args {
35758 + struct dentry *h_dentry;
35759 + struct au_nhash *whlist;
35760 + aufs_bindex_t bindex;
35761 + struct au_branch *br;
35764 +static void call_del_wh_children(void *args)
35766 + struct del_wh_children_args *a = args;
35767 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35770 +/* ---------------------------------------------------------------------- */
35772 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35774 + struct au_whtmp_rmdir *whtmp;
35776 + unsigned int rdhash;
35778 + SiMustAnyLock(sb);
35780 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35781 + if (unlikely(!whtmp)) {
35782 + whtmp = ERR_PTR(-ENOMEM);
35786 + /* no estimation for dir size */
35787 + rdhash = au_sbi(sb)->si_rdhash;
35789 + rdhash = AUFS_RDHASH_DEF;
35790 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35791 + if (unlikely(err)) {
35792 + au_kfree_rcu(whtmp);
35793 + whtmp = ERR_PTR(err);
35800 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35803 + au_lcnt_dec(&whtmp->br->br_count);
35804 + dput(whtmp->wh_dentry);
35805 + iput(whtmp->dir);
35806 + au_nhash_wh_free(&whtmp->whlist);
35807 + au_kfree_rcu(whtmp);
35811 + * rmdir the whiteouted temporary named dir @h_dentry.
35812 + * @whlist: whiteouted children.
35814 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35815 + struct dentry *wh_dentry, struct au_nhash *whlist)
35818 + unsigned int h_nlink;
35819 + struct path h_tmp;
35820 + struct inode *wh_inode, *h_dir;
35821 + struct au_branch *br;
35823 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35824 + IMustLock(h_dir);
35826 + br = au_sbr(dir->i_sb, bindex);
35827 + wh_inode = d_inode(wh_dentry);
35828 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35831 + * someone else might change some whiteouts while we were sleeping.
35832 + * it means this whlist may have an obsoleted entry.
35834 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35835 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35838 + struct del_wh_children_args args = {
35840 + .h_dentry = wh_dentry,
35841 + .whlist = whlist,
35842 + .bindex = bindex,
35846 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35847 + if (unlikely(wkq_err))
35850 + inode_unlock(wh_inode);
35853 + h_tmp.dentry = wh_dentry;
35854 + h_tmp.mnt = au_br_mnt(br);
35855 + h_nlink = h_dir->i_nlink;
35856 + err = vfsub_rmdir(h_dir, &h_tmp);
35857 + /* some fs doesn't change the parent nlink in some cases */
35858 + h_nlink -= h_dir->i_nlink;
35862 + if (au_ibtop(dir) == bindex) {
35863 + /* todo: dir->i_mutex is necessary */
35864 + au_cpup_attr_timesizes(dir);
35866 + vfsub_drop_nlink(dir);
35868 + return 0; /* success */
35871 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35875 +static void call_rmdir_whtmp(void *args)
35878 + aufs_bindex_t bindex;
35879 + struct au_whtmp_rmdir *a = args;
35880 + struct super_block *sb;
35881 + struct dentry *h_parent;
35882 + struct inode *h_dir;
35883 + struct au_hinode *hdir;
35885 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35886 + /* inode_lock(a->dir); */
35888 + sb = a->dir->i_sb;
35889 + si_read_lock(sb, !AuLock_FLUSH);
35890 + if (!au_br_writable(a->br->br_perm))
35892 + bindex = au_br_index(sb, a->br->br_id);
35893 + if (unlikely(bindex < 0))
35897 + ii_write_lock_parent(a->dir);
35898 + h_parent = dget_parent(a->wh_dentry);
35899 + h_dir = d_inode(h_parent);
35900 + hdir = au_hi(a->dir, bindex);
35901 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35902 + if (unlikely(err))
35904 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35905 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35908 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35909 + au_hn_inode_unlock(hdir);
35910 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35914 + ii_write_unlock(a->dir);
35916 + /* inode_unlock(a->dir); */
35917 + au_whtmp_rmdir_free(a);
35918 + si_read_unlock(sb);
35919 + au_nwt_done(&au_sbi(sb)->si_nowait);
35920 + if (unlikely(err))
35921 + AuIOErr("err %d\n", err);
35924 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35925 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35928 + struct super_block *sb;
35932 + /* all post-process will be done in do_rmdir_whtmp(). */
35934 + args->dir = au_igrab(dir);
35935 + args->br = au_sbr(sb, bindex);
35936 + au_lcnt_inc(&args->br->br_count);
35937 + args->wh_dentry = dget(wh_dentry);
35938 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35939 + if (unlikely(wkq_err)) {
35940 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35941 + au_whtmp_rmdir_free(args);
35944 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35945 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35946 +++ linux/fs/aufs/whout.h 2021-02-22 23:30:37.702680911 +0100
35948 +/* SPDX-License-Identifier: GPL-2.0 */
35950 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35952 + * This program, aufs is free software; you can redistribute it and/or modify
35953 + * it under the terms of the GNU General Public License as published by
35954 + * the Free Software Foundation; either version 2 of the License, or
35955 + * (at your option) any later version.
35957 + * This program is distributed in the hope that it will be useful,
35958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35960 + * GNU General Public License for more details.
35962 + * You should have received a copy of the GNU General Public License
35963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35967 + * whiteout for logical deletion and opaque directory
35970 +#ifndef __AUFS_WHOUT_H__
35971 +#define __AUFS_WHOUT_H__
35978 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35979 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35980 +int au_diropq_test(struct dentry *h_dentry);
35982 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35983 + struct qstr *prefix);
35984 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35985 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35986 + struct dentry *dentry);
35987 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35989 +/* diropq flags */
35990 +#define AuDiropq_CREATE 1
35991 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35992 +#define au_fset_diropq(flags, name) \
35993 + do { (flags) |= AuDiropq_##name; } while (0)
35994 +#define au_fclr_diropq(flags, name) \
35995 + do { (flags) &= ~AuDiropq_##name; } while (0)
35997 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35998 + unsigned int flags);
35999 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36000 + struct au_branch *br);
36001 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36002 + struct dentry *h_parent);
36004 +/* real rmdir for the whiteout-ed dir */
36005 +struct au_whtmp_rmdir {
36006 + struct inode *dir;
36007 + struct au_branch *br;
36008 + struct dentry *wh_dentry;
36009 + struct au_nhash whlist;
36012 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36013 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36014 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36015 + struct dentry *wh_dentry, struct au_nhash *whlist);
36016 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36017 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36019 +/* ---------------------------------------------------------------------- */
36021 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36022 + aufs_bindex_t bindex)
36024 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36027 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36029 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36032 +#endif /* __KERNEL__ */
36033 +#endif /* __AUFS_WHOUT_H__ */
36034 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36035 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36036 +++ linux/fs/aufs/wkq.c 2021-02-22 23:30:37.702680911 +0100
36038 +// SPDX-License-Identifier: GPL-2.0
36040 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36042 + * This program, aufs is free software; you can redistribute it and/or modify
36043 + * it under the terms of the GNU General Public License as published by
36044 + * the Free Software Foundation; either version 2 of the License, or
36045 + * (at your option) any later version.
36047 + * This program is distributed in the hope that it will be useful,
36048 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36049 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36050 + * GNU General Public License for more details.
36052 + * You should have received a copy of the GNU General Public License
36053 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36057 + * workqueue for asynchronous/super-io operations
36058 + * todo: try new credential scheme
36061 +#include <linux/module.h>
36064 +/* internal workqueue named AUFS_WKQ_NAME */
36066 +static struct workqueue_struct *au_wkq;
36068 +struct au_wkinfo {
36069 + struct work_struct wk;
36070 + struct kobject *kobj;
36072 + unsigned int flags; /* see wkq.h */
36074 + au_wkq_func_t func;
36077 +#ifdef CONFIG_LOCKDEP
36079 + struct held_lock **hlock;
36082 + struct completion *comp;
36085 +/* ---------------------------------------------------------------------- */
36087 + * Aufs passes some operations to the workqueue such as the internal copyup.
36088 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36089 + * job run by workqueue depends upon the locks acquired in the other task.
36090 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36091 + * information too. And the job in the workqueue restores the info in order to
36092 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36093 + * correctly and expectedly.
36096 +#ifndef CONFIG_LOCKDEP
36097 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36098 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36099 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36100 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36101 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36103 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36105 + wkinfo->hlock = NULL;
36106 + wkinfo->dont_check = 0;
36113 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36115 + static DEFINE_SPINLOCK(spin);
36118 + struct lock_class_key *key;
36120 + { .name = "&sbinfo->si_rwsem" },
36121 + { .name = "&finfo->fi_rwsem" },
36122 + { .name = "&dinfo->di_rwsem" },
36123 + { .name = "&iinfo->ii_rwsem" }
36128 + /* lockless read from 'set.' see below */
36129 + if (set == ARRAY_SIZE(a)) {
36130 + for (i = 0; i < ARRAY_SIZE(a); i++)
36131 + if (a[i].key == key)
36136 + spin_lock(&spin);
36138 + for (i = 0; i < ARRAY_SIZE(a); i++)
36139 + if (a[i].key == key) {
36140 + spin_unlock(&spin);
36143 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36145 + if (unlikely(a[i].key == key)) { /* rare but possible */
36146 + spin_unlock(&spin);
36151 + if (strstr(a[i].name, name)) {
36153 + * the order of these three lines is important for the
36154 + * lockless read above.
36157 + spin_unlock(&spin);
36159 + /* AuDbg("%d, %s\n", set, name); */
36163 + spin_unlock(&spin);
36172 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36175 + struct task_struct *curr;
36176 + struct held_lock **hl, *held_locks, *p;
36180 + wkinfo->dont_check = lockdep_recursing(curr);
36181 + if (wkinfo->dont_check)
36183 + n = curr->lockdep_depth;
36188 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36189 + if (unlikely(!wkinfo->hlock))
36193 +#if 0 /* left for debugging */
36194 + if (0 && au_debug_test())
36195 + lockdep_print_held_locks(curr);
36197 + held_locks = curr->held_locks;
36198 + hl = wkinfo->hlock;
36200 + p = held_locks++;
36201 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36210 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36212 + au_kfree_try_rcu(wkinfo->hlock);
36215 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36217 + struct held_lock *p, **hl = wkinfo->hlock;
36220 + if (wkinfo->dont_check)
36224 + while ((p = *hl++)) { /* assignment */
36225 + subclass = lockdep_hlock_class(p)->subclass;
36226 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36228 + rwsem_acquire_read(p->instance, subclass, 0,
36229 + /*p->acquire_ip*/_RET_IP_);
36231 + rwsem_acquire(p->instance, subclass, 0,
36232 + /*p->acquire_ip*/_RET_IP_);
36236 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36238 + struct held_lock *p, **hl = wkinfo->hlock;
36240 + if (wkinfo->dont_check)
36244 + while ((p = *hl++)) /* assignment */
36245 + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_);
36249 +static void wkq_func(struct work_struct *wk)
36251 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36253 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36254 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36256 + au_wkq_lockdep_pre(wkinfo);
36257 + wkinfo->func(wkinfo->args);
36258 + au_wkq_lockdep_post(wkinfo);
36259 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36260 + complete(wkinfo->comp);
36262 + kobject_put(wkinfo->kobj);
36263 + module_put(THIS_MODULE); /* todo: ?? */
36264 + au_kfree_rcu(wkinfo);
36269 + * Since struct completion is large, try allocating it dynamically.
36271 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36273 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36275 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36277 + init_completion(*comp);
36278 + wkinfo->comp = *comp;
36284 +static void au_wkq_comp_free(struct completion *comp)
36286 + au_kfree_rcu(comp);
36289 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36291 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36292 + if (au_wkq_test()) {
36293 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36294 + " due to a dead dir by UDBA,"
36295 + " or async xino write?\n");
36296 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36299 + au_dbg_verify_kthread();
36301 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36302 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36303 + queue_work(au_wkq, &wkinfo->wk);
36305 + INIT_WORK(&wkinfo->wk, wkq_func);
36306 + schedule_work(&wkinfo->wk);
36311 + * Be careful. It is easy to make deadlock happen.
36312 + * processA: lock, wkq and wait
36313 + * processB: wkq and wait, lock in wkq
36316 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36319 + AuWkqCompDeclare(comp);
36320 + struct au_wkinfo wkinfo = {
36326 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36327 + if (unlikely(err))
36329 + err = au_wkq_lockdep_alloc(&wkinfo);
36330 + if (unlikely(err))
36333 + au_wkq_run(&wkinfo);
36334 + /* no timeout, no interrupt */
36335 + wait_for_completion(wkinfo.comp);
36337 + au_wkq_lockdep_free(&wkinfo);
36340 + au_wkq_comp_free(comp);
36342 + destroy_work_on_stack(&wkinfo.wk);
36347 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36348 + * problem in a concurrent umounting.
36350 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36351 + unsigned int flags)
36354 + struct au_wkinfo *wkinfo;
36356 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36359 + * wkq_func() must free this wkinfo.
36360 + * it highly depends upon the implementation of workqueue.
36363 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36365 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36366 + wkinfo->flags = flags & ~AuWkq_WAIT;
36367 + wkinfo->func = func;
36368 + wkinfo->args = args;
36369 + wkinfo->comp = NULL;
36370 + au_wkq_lockdep_init(wkinfo);
36371 + kobject_get(wkinfo->kobj);
36372 + __module_get(THIS_MODULE); /* todo: ?? */
36374 + au_wkq_run(wkinfo);
36377 + au_nwt_done(&au_sbi(sb)->si_nowait);
36383 +/* ---------------------------------------------------------------------- */
36385 +void au_nwt_init(struct au_nowait_tasks *nwt)
36387 + atomic_set(&nwt->nw_len, 0);
36388 + /* smp_mb(); */ /* atomic_set */
36389 + init_waitqueue_head(&nwt->nw_wq);
36392 +void au_wkq_fin(void)
36394 + destroy_workqueue(au_wkq);
36397 +int __init au_wkq_init(void)
36402 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36403 + if (IS_ERR(au_wkq))
36404 + err = PTR_ERR(au_wkq);
36405 + else if (!au_wkq)
36410 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36411 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36412 +++ linux/fs/aufs/wkq.h 2021-02-22 23:30:37.702680911 +0100
36414 +/* SPDX-License-Identifier: GPL-2.0 */
36416 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36418 + * This program, aufs is free software; you can redistribute it and/or modify
36419 + * it under the terms of the GNU General Public License as published by
36420 + * the Free Software Foundation; either version 2 of the License, or
36421 + * (at your option) any later version.
36423 + * This program is distributed in the hope that it will be useful,
36424 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36425 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36426 + * GNU General Public License for more details.
36428 + * You should have received a copy of the GNU General Public License
36429 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36433 + * workqueue for asynchronous/super-io operations
36434 + * todo: try new credentials management scheme
36437 +#ifndef __AUFS_WKQ_H__
36438 +#define __AUFS_WKQ_H__
36442 +#include <linux/wait.h>
36444 +struct super_block;
36446 +/* ---------------------------------------------------------------------- */
36449 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36451 +struct au_nowait_tasks {
36453 + wait_queue_head_t nw_wq;
36456 +/* ---------------------------------------------------------------------- */
36458 +typedef void (*au_wkq_func_t)(void *args);
36461 +#define AuWkq_WAIT 1
36462 +#define AuWkq_NEST (1 << 1)
36463 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36464 +#define au_fset_wkq(flags, name) \
36465 + do { (flags) |= AuWkq_##name; } while (0)
36466 +#define au_fclr_wkq(flags, name) \
36467 + do { (flags) &= ~AuWkq_##name; } while (0)
36470 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36471 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36472 + unsigned int flags);
36473 +void au_nwt_init(struct au_nowait_tasks *nwt);
36474 +int __init au_wkq_init(void);
36475 +void au_wkq_fin(void);
36477 +/* ---------------------------------------------------------------------- */
36479 +static inline int au_wkq_test(void)
36481 + return current->flags & PF_WQ_WORKER;
36484 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36486 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36489 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36491 + if (atomic_dec_and_test(&nwt->nw_len))
36492 + wake_up_all(&nwt->nw_wq);
36495 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36497 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36501 +#endif /* __KERNEL__ */
36502 +#endif /* __AUFS_WKQ_H__ */
36503 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36504 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36505 +++ linux/fs/aufs/xattr.c 2021-02-22 23:30:37.702680911 +0100
36507 +// SPDX-License-Identifier: GPL-2.0
36509 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36511 + * This program, aufs is free software; you can redistribute it and/or modify
36512 + * it under the terms of the GNU General Public License as published by
36513 + * the Free Software Foundation; either version 2 of the License, or
36514 + * (at your option) any later version.
36516 + * This program is distributed in the hope that it will be useful,
36517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36519 + * GNU General Public License for more details.
36521 + * You should have received a copy of the GNU General Public License
36522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36526 + * handling xattr functions
36529 +#include <linux/fs.h>
36530 +#include <linux/posix_acl_xattr.h>
36531 +#include <linux/xattr.h>
36534 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36536 + if (!ignore_flags)
36544 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36549 +#define cmp(brattr, prefix) do { \
36550 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36551 + XATTR_##prefix##_PREFIX_LEN)) { \
36552 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36558 + cmp(SEC, SECURITY);
36559 + cmp(SYS, SYSTEM);
36560 + cmp(TR, TRUSTED);
36564 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36571 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36573 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36574 + char *name, char **buf, unsigned int ignore_flags,
36575 + unsigned int verbose)
36579 + struct inode *h_idst;
36581 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36583 + if (unlikely(err <= 0)) {
36584 + if (err == -ENODATA
36585 + || (err == -EOPNOTSUPP
36586 + && ((ignore_flags & au_xattr_out_of_list)
36587 + || (au_test_nfs_noacl(d_inode(h_src))
36588 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36590 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36593 + if (err && (verbose || au_debug_test()))
36594 + pr_err("%s, err %d\n", name, err);
36598 + /* unlock it temporary */
36599 + h_idst = d_inode(h_dst);
36600 + inode_unlock(h_idst);
36601 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36602 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36603 + if (unlikely(err)) {
36604 + if (verbose || au_debug_test())
36605 + pr_err("%s, err %d\n", name, err);
36606 + err = au_xattr_ignore(err, name, ignore_flags);
36613 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36614 + unsigned int verbose)
36616 + int err, unlocked, acl_access, acl_default;
36618 + struct inode *h_isrc, *h_idst;
36619 + char *value, *p, *o, *e;
36621 + /* try stopping to update the source inode while we are referencing */
36622 + /* there should not be the parent-child relationship between them */
36623 + h_isrc = d_inode(h_src);
36624 + h_idst = d_inode(h_dst);
36625 + inode_unlock(h_idst);
36626 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36627 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36630 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36631 + ssz = vfs_listxattr(h_src, NULL, 0);
36633 + if (unlikely(err < 0)) {
36635 + if (err == -ENODATA
36636 + || err == -EOPNOTSUPP)
36637 + err = 0; /* ignore */
36646 + p = kmalloc(ssz, GFP_NOFS);
36648 + if (unlikely(!p))
36650 + err = vfs_listxattr(h_src, p, ssz);
36652 + inode_unlock_shared(h_isrc);
36654 + AuDbg("err %d, ssz %zd\n", err, ssz);
36655 + if (unlikely(err < 0))
36663 + while (!err && p < e) {
36664 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36665 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36666 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36667 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36669 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36671 + p += strlen(p) + 1;
36674 + ignore_flags |= au_xattr_out_of_list;
36675 + if (!err && !acl_access) {
36676 + err = au_do_cpup_xattr(h_dst, h_src,
36677 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36678 + ignore_flags, verbose);
36681 + if (!err && !acl_default) {
36682 + err = au_do_cpup_xattr(h_dst, h_src,
36683 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36684 + ignore_flags, verbose);
36688 + au_kfree_try_rcu(value);
36691 + au_kfree_try_rcu(o);
36694 + inode_unlock_shared(h_isrc);
36699 +/* ---------------------------------------------------------------------- */
36701 +static int au_smack_reentering(struct super_block *sb)
36703 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36705 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36706 + * i_op->getxattr(). ouch.
36708 + return si_pid_test(sb);
36719 +struct au_lgxattr {
36727 + const char *name;
36734 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36735 + struct au_lgxattr *arg)
36739 + struct path h_path;
36740 + struct super_block *sb;
36742 + sb = dentry->d_sb;
36743 + reenter = au_smack_reentering(sb);
36745 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36746 + if (unlikely(err))
36749 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36750 + if (unlikely(err))
36752 + if (unlikely(!h_path.dentry))
36753 + /* illegally overlapped or something */
36754 + goto out_di; /* pretending success */
36756 + /* always topmost entry only */
36757 + switch (arg->type) {
36758 + case AU_XATTR_LIST:
36759 + err = vfs_listxattr(h_path.dentry,
36760 + arg->u.list.list, arg->u.list.size);
36762 + case AU_XATTR_GET:
36763 + AuDebugOn(d_is_negative(h_path.dentry));
36764 + err = vfs_getxattr(h_path.dentry,
36765 + arg->u.get.name, arg->u.get.value,
36766 + arg->u.get.size);
36772 + di_read_unlock(dentry, AuLock_IR);
36775 + si_read_unlock(sb);
36781 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36783 + struct au_lgxattr arg = {
36784 + .type = AU_XATTR_LIST,
36791 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36794 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36795 + const char *name, void *value, size_t size)
36797 + struct au_lgxattr arg = {
36798 + .type = AU_XATTR_GET,
36806 + return au_lgxattr(dentry, inode, &arg);
36809 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36810 + const char *name, const void *value, size_t size,
36813 + struct au_sxattr arg = {
36814 + .type = AU_XATTR_SET,
36823 + return au_sxattr(dentry, inode, &arg);
36826 +/* ---------------------------------------------------------------------- */
36828 +static int au_xattr_get(const struct xattr_handler *handler,
36829 + struct dentry *dentry, struct inode *inode,
36830 + const char *name, void *buffer, size_t size)
36832 + return au_getxattr(dentry, inode, name, buffer, size);
36835 +static int au_xattr_set(const struct xattr_handler *handler,
36836 + struct dentry *dentry, struct inode *inode,
36837 + const char *name, const void *value, size_t size,
36840 + return au_setxattr(dentry, inode, name, value, size, flags);
36843 +static const struct xattr_handler au_xattr_handler = {
36846 + .get = au_xattr_get,
36847 + .set = au_xattr_set
36850 +static const struct xattr_handler *au_xattr_handlers[] = {
36851 +#ifdef CONFIG_FS_POSIX_ACL
36852 + &posix_acl_access_xattr_handler,
36853 + &posix_acl_default_xattr_handler,
36855 + &au_xattr_handler, /* must be last */
36859 +void au_xattr_init(struct super_block *sb)
36861 + sb->s_xattr = au_xattr_handlers;
36863 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36864 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36865 +++ linux/fs/aufs/xino.c 2021-02-22 23:30:37.706014241 +0100
36867 +// SPDX-License-Identifier: GPL-2.0
36869 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36871 + * This program, aufs is free software; you can redistribute it and/or modify
36872 + * it under the terms of the GNU General Public License as published by
36873 + * the Free Software Foundation; either version 2 of the License, or
36874 + * (at your option) any later version.
36876 + * This program is distributed in the hope that it will be useful,
36877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36879 + * GNU General Public License for more details.
36881 + * You should have received a copy of the GNU General Public License
36882 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36886 + * external inode number translation table and bitmap
36888 + * things to consider
36890 + * + au_xino object
36891 + * + XINO files (xino, xib, xigen)
36892 + * + dynamic debugfs entries (xiN)
36893 + * + static debugfs entries (xib, xigen)
36894 + * + static sysfs entry (xi_path)
36895 + * - several entry points to handle them.
36896 + * + mount(2) without xino option (default)
36897 + * + mount(2) with xino option
36898 + * + mount(2) with noxino option
36900 + * + remount with add/del branches
36901 + * + remount with xino/noxino options
36904 +#include <linux/seq_file.h>
36905 +#include <linux/statfs.h>
36908 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36909 + aufs_bindex_t bbot,
36910 + struct super_block *h_sb)
36912 + /* todo: try binary-search if the branches are many */
36913 + for (; btop <= bbot; btop++)
36914 + if (h_sb == au_sbr_sb(sb, btop))
36920 + * find another branch who is on the same filesystem of the specified
36921 + * branch{@btgt}. search until @bbot.
36923 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36924 + aufs_bindex_t bbot)
36926 + aufs_bindex_t bindex;
36927 + struct super_block *tgt_sb;
36929 + tgt_sb = au_sbr_sb(sb, btgt);
36930 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36932 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36937 +/* ---------------------------------------------------------------------- */
36940 + * stop unnecessary notify events at creating xino files
36943 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36945 + aufs_bindex_t bfound, bindex, bbot;
36946 + struct dentry *parent;
36947 + struct au_branch *br;
36950 + parent = dentry->d_parent; /* safe d_parent access */
36951 + bbot = au_sbbot(sb);
36952 + for (bindex = 0; bindex <= bbot; bindex++) {
36953 + br = au_sbr(sb, bindex);
36954 + if (au_br_dentry(br) == parent) {
36960 + AuDbg("bfound b%d\n", bfound);
36964 +struct au_xino_lock_dir {
36965 + struct au_hinode *hdir;
36966 + struct dentry *parent;
36967 + struct inode *dir;
36970 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36971 + unsigned int lsc)
36973 + struct dentry *parent;
36974 + struct inode *dir;
36976 + parent = dget_parent(dentry);
36977 + dir = d_inode(parent);
36978 + inode_lock_nested(dir, lsc);
36979 +#if 0 /* it should not happen */
36980 + spin_lock(&dentry->d_lock);
36981 + if (unlikely(dentry->d_parent != parent)) {
36982 + spin_unlock(&dentry->d_lock);
36983 + inode_unlock(dir);
36988 + spin_unlock(&dentry->d_lock);
36995 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36996 + struct au_xino_lock_dir *ldir)
36998 + aufs_bindex_t bindex;
37000 + ldir->hdir = NULL;
37001 + bindex = au_xi_root(sb, xipath->dentry);
37002 + if (bindex >= 0) {
37003 + /* rw branch root */
37004 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37005 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37008 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37010 + ldir->dir = d_inode(ldir->parent);
37014 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37017 + au_hn_inode_unlock(ldir->hdir);
37019 + inode_unlock(ldir->dir);
37020 + dput(ldir->parent);
37024 +/* ---------------------------------------------------------------------- */
37027 + * create and set a new xino file
37029 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37032 + struct file *file;
37033 + struct dentry *h_parent, *d;
37034 + struct inode *h_dir, *inode;
37036 + static DEFINE_MUTEX(mtx);
37039 + * at mount-time, and the xino file is the default path,
37040 + * hnotify is disabled so we have no notify events to ignore.
37041 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37044 + mutex_lock(&mtx);
37045 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37046 + /* | __FMODE_NONOTIFY */,
37048 + if (IS_ERR(file)) {
37050 + mutex_unlock(&mtx);
37052 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37056 + /* keep file count */
37058 + d = file->f_path.dentry;
37059 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37061 + mutex_unlock(&mtx);
37062 + /* mnt_want_write() is unnecessary here */
37063 + h_dir = d_inode(h_parent);
37064 + inode = file_inode(file);
37065 + /* no delegation since it is just created */
37066 + if (inode->i_nlink)
37067 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37069 + inode_unlock(h_dir);
37071 + if (unlikely(err)) {
37073 + pr_err("unlink %s(%d)\n", fpath, err);
37078 + if (unlikely(sb == d->d_sb)) {
37080 + pr_err("%s must be outside\n", fpath);
37083 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37085 + pr_err("xino doesn't support %s(%s)\n",
37086 + fpath, au_sbtype(d->d_sb));
37089 + return file; /* success */
37093 + file = ERR_PTR(err);
37098 + * create a new xinofile at the same place/path as @base.
37100 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37101 + struct file *copy_src)
37103 + struct file *file;
37104 + struct dentry *dentry, *parent;
37105 + struct inode *dir, *delegated;
37106 + struct qstr *name;
37107 + struct path path;
37108 + int err, do_unlock;
37109 + struct au_xino_lock_dir ldir;
37112 + au_xino_lock_dir(sb, base, &ldir);
37113 + dentry = base->dentry;
37114 + parent = dentry->d_parent; /* dir inode is locked */
37115 + dir = d_inode(parent);
37118 + name = &dentry->d_name;
37119 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37120 + if (IS_ERR(path.dentry)) {
37121 + file = (void *)path.dentry;
37122 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37126 + /* no need to mnt_want_write() since we call dentry_open() later */
37127 + err = vfs_create(dir, path.dentry, 0666, NULL);
37128 + if (unlikely(err)) {
37129 + file = ERR_PTR(err);
37130 + pr_err("%pd create err %d\n", dentry, err);
37134 + path.mnt = base->mnt;
37135 + file = vfsub_dentry_open(&path,
37136 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37137 + /* | __FMODE_NONOTIFY */);
37138 + if (IS_ERR(file)) {
37139 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37143 + delegated = NULL;
37144 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37145 + au_xino_unlock_dir(&ldir);
37147 + if (unlikely(err == -EWOULDBLOCK)) {
37148 + pr_warn("cannot retry for NFSv4 delegation"
37149 + " for an internal unlink\n");
37152 + if (unlikely(err)) {
37153 + pr_err("%pd unlink err %d\n", dentry, err);
37158 + /* no one can touch copy_src xino */
37159 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37160 + if (unlikely(err)) {
37161 + pr_err("%pd copy err %d\n", dentry, err);
37165 + goto out_dput; /* success */
37169 + file = ERR_PTR(err);
37171 + dput(path.dentry);
37174 + au_xino_unlock_dir(&ldir);
37178 +struct file *au_xino_file1(struct au_xino *xi)
37180 + struct file *file;
37181 + unsigned int u, nfile;
37184 + nfile = xi->xi_nfile;
37185 + for (u = 0; u < nfile; u++) {
37186 + file = xi->xi_file[u];
37194 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37205 + if (idx < xi->xi_nfile) {
37206 + f = xi->xi_file[idx];
37210 + p = au_kzrealloc(xi->xi_file,
37211 + sizeof(*xi->xi_file) * xi->xi_nfile,
37212 + sizeof(*xi->xi_file) * (idx + 1),
37213 + GFP_NOFS, /*may_shrink*/0);
37215 + MtxMustLock(&xi->xi_mtx);
37217 + xi->xi_nfile = idx + 1;
37225 + xi->xi_file[idx] = file;
37232 + * if @xinew->xi is not set, then create new xigen file.
37234 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37236 + struct file *file;
37239 + SiMustAnyLock(sb);
37241 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37242 + if (IS_ERR(file)) {
37243 + err = PTR_ERR(file);
37244 + pr_err("%s[%d], err %d\n",
37245 + xinew->xi ? "xino" : "xigen",
37246 + xinew->idx, err);
37251 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37254 + /* todo: make xigen file an array */
37255 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37258 + if (unlikely(err))
37259 + file = ERR_PTR(err);
37265 +/* ---------------------------------------------------------------------- */
37268 + * truncate xino files
37270 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37271 + int idx, struct kstatfs *st)
37275 + struct file *file, *new_xino;
37276 + struct au_xi_new xinew = {
37281 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37282 + file = au_xino_file(xinew.xi, idx);
37286 + xinew.base = &file->f_path;
37287 + err = vfs_statfs(xinew.base, st);
37288 + if (unlikely(err)) {
37289 + AuErr1("statfs err %d, ignored\n", err);
37294 + blocks = file_inode(file)->i_blocks;
37295 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37296 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37298 + xinew.copy_src = file;
37299 + new_xino = au_xi_new(sb, &xinew);
37300 + if (IS_ERR(new_xino)) {
37301 + err = PTR_ERR(new_xino);
37302 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37306 + err = vfs_statfs(&new_xino->f_path, st);
37308 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37309 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37310 + st->f_bfree, st->f_blocks);
37312 + AuErr1("statfs err %d, ignored\n", err);
37320 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37323 + unsigned long jiffy;
37324 + aufs_bindex_t bbot;
37325 + struct kstatfs *st;
37326 + struct au_branch *br;
37327 + struct au_xino *xi;
37330 + st = kmalloc(sizeof(*st), GFP_NOFS);
37331 + if (unlikely(!st))
37335 + bbot = au_sbbot(sb);
37336 + if (unlikely(bindex < 0 || bbot < bindex))
37341 + br = au_sbr(sb, bindex);
37342 + xi = br->br_xino;
37343 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37344 + err = au_xino_do_trunc(sb, bindex, i, st);
37346 + au_sbi(sb)->si_xino_jiffy = jiffy;
37349 + au_kfree_rcu(st);
37354 +struct xino_do_trunc_args {
37355 + struct super_block *sb;
37356 + struct au_branch *br;
37360 +static void xino_do_trunc(void *_args)
37362 + struct xino_do_trunc_args *args = _args;
37363 + struct super_block *sb;
37364 + struct au_branch *br;
37365 + struct inode *dir;
37367 + aufs_bindex_t bindex;
37371 + dir = d_inode(sb->s_root);
37375 + si_noflush_write_lock(sb);
37376 + ii_read_lock_parent(dir);
37377 + bindex = au_br_index(sb, br->br_id);
37378 + err = au_xino_trunc(sb, bindex, idx);
37379 + ii_read_unlock(dir);
37380 + if (unlikely(err))
37381 + pr_warn("err b%d, (%d)\n", bindex, err);
37382 + atomic_dec(&br->br_xino->xi_truncating);
37383 + au_lcnt_dec(&br->br_count);
37384 + si_write_unlock(sb);
37385 + au_nwt_done(&au_sbi(sb)->si_nowait);
37386 + au_kfree_rcu(args);
37390 + * returns the index in the xi_file array whose corresponding file is necessary
37391 + * to truncate, or -1 which means no need to truncate.
37393 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37397 + struct kstatfs st;
37398 + struct au_sbinfo *sbinfo;
37399 + struct au_xino *xi;
37400 + struct file *file;
37402 + /* todo: si_xino_expire and the ratio should be customizable */
37403 + sbinfo = au_sbi(sb);
37404 + if (time_before(jiffies,
37405 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37408 + /* truncation border */
37409 + xi = br->br_xino;
37410 + for (u = 0; u < xi->xi_nfile; u++) {
37411 + file = au_xino_file(xi, u);
37415 + err = vfs_statfs(&file->f_path, &st);
37416 + if (unlikely(err)) {
37417 + AuErr1("statfs err %d, ignored\n", err);
37420 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37421 + >= AUFS_XINO_DEF_TRUNC)
37428 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37431 + struct xino_do_trunc_args *args;
37434 + idx = xino_trunc_test(sb, br);
37438 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37441 + /* lock and kfree() will be called in trunc_xino() */
37442 + args = kmalloc(sizeof(*args), GFP_NOFS);
37443 + if (unlikely(!args)) {
37444 + AuErr1("no memory\n");
37448 + au_lcnt_inc(&br->br_count);
37452 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37454 + return; /* success */
37456 + pr_err("wkq %d\n", wkq_err);
37457 + au_lcnt_dec(&br->br_count);
37458 + au_kfree_rcu(args);
37461 + atomic_dec(&br->br_xino->xi_truncating);
37464 +/* ---------------------------------------------------------------------- */
37466 +struct au_xi_calc {
37471 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37472 + struct au_xi_calc *calc)
37476 + maxent = au_xi_maxent(sb);
37477 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37478 + calc->pos *= sizeof(ino_t);
37481 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37482 + struct au_xi_calc *calc)
37485 + struct file *file;
37486 + struct au_xino *xi = br->br_xino;
37487 + struct au_xi_new xinew = {
37491 + SiMustAnyLock(sb);
37497 + mutex_lock(&xi->xi_mtx);
37498 + file = au_xino_file(xi, calc->idx);
37502 + file = au_xino_file(xi, /*idx*/-1);
37503 + AuDebugOn(!file);
37504 + xinew.idx = calc->idx;
37505 + xinew.base = &file->f_path;
37506 + /* xinew.copy_src = NULL; */
37507 + file = au_xi_new(sb, &xinew);
37508 + if (IS_ERR(file))
37509 + err = PTR_ERR(file);
37512 + mutex_unlock(&xi->xi_mtx);
37517 +struct au_xino_do_new_async_args {
37518 + struct super_block *sb;
37519 + struct au_branch *br;
37520 + struct au_xi_calc calc;
37524 +struct au_xi_writing {
37525 + struct hlist_bl_node node;
37526 + ino_t h_ino, ino;
37529 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37530 + struct au_xi_calc *calc, ino_t ino);
37532 +static void au_xino_call_do_new_async(void *args)
37534 + struct au_xino_do_new_async_args *a = args;
37535 + struct au_branch *br;
37536 + struct super_block *sb;
37537 + struct au_sbinfo *sbi;
37538 + struct inode *root;
37539 + struct file *file;
37540 + struct au_xi_writing *del, *p;
37541 + struct hlist_bl_head *hbl;
37542 + struct hlist_bl_node *pos;
37547 + sbi = au_sbi(sb);
37548 + si_noflush_read_lock(sb);
37549 + root = d_inode(sb->s_root);
37550 + ii_read_lock_child(root);
37551 + err = au_xino_do_new_async(sb, br, &a->calc);
37552 + if (unlikely(err)) {
37553 + AuIOErr("err %d\n", err);
37557 + file = au_xino_file(br->br_xino, a->calc.idx);
37558 + AuDebugOn(!file);
37559 + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino);
37560 + if (unlikely(err)) {
37561 + AuIOErr("err %d\n", err);
37566 + hbl = &br->br_xino->xi_writing;
37567 + hlist_bl_lock(hbl);
37568 + au_hbl_for_each(pos, hbl) {
37569 + p = container_of(pos, struct au_xi_writing, node);
37570 + if (p->ino == a->ino) {
37572 + hlist_bl_del(&p->node);
37576 + hlist_bl_unlock(hbl);
37577 + au_kfree_rcu(del);
37580 + au_lcnt_dec(&br->br_count);
37581 + ii_read_unlock(root);
37582 + si_read_unlock(sb);
37583 + au_nwt_done(&sbi->si_nowait);
37588 + * create a new xino file asynchronously
37590 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37591 + struct au_xi_calc *calc, ino_t ino)
37594 + struct au_xino_do_new_async_args *arg;
37597 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37598 + if (unlikely(!arg))
37603 + arg->calc = *calc;
37605 + au_lcnt_inc(&br->br_count);
37606 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37607 + if (unlikely(err)) {
37608 + pr_err("wkq %d\n", err);
37609 + au_lcnt_dec(&br->br_count);
37610 + au_kfree_rcu(arg);
37618 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37619 + * at the position of @h_ino.
37621 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37626 + struct au_xi_calc calc;
37627 + struct au_sbinfo *sbinfo;
37628 + struct file *file;
37629 + struct au_xino *xi;
37630 + struct hlist_bl_head *hbl;
37631 + struct hlist_bl_node *pos;
37632 + struct au_xi_writing *p;
37635 + if (!au_opt_test(au_mntflags(sb), XINO))
37636 + return 0; /* no xino */
37639 + au_xi_calc(sb, h_ino, &calc);
37640 + xi = au_sbr(sb, bindex)->br_xino;
37641 + file = au_xino_file(xi, calc.idx);
37643 + hbl = &xi->xi_writing;
37644 + hlist_bl_lock(hbl);
37645 + au_hbl_for_each(pos, hbl) {
37646 + p = container_of(pos, struct au_xi_writing, node);
37647 + if (p->h_ino == h_ino) {
37648 + AuDbg("hi%llu, i%llu, found\n",
37649 + (u64)p->h_ino, (u64)p->ino);
37654 + hlist_bl_unlock(hbl);
37656 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37657 + return 0; /* no xino */
37659 + sbinfo = au_sbi(sb);
37660 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos);
37661 + if (sz == sizeof(*ino))
37662 + return 0; /* success */
37665 + if (unlikely(sz >= 0)) {
37667 + AuIOErr("xino read error (%zd)\n", sz);
37672 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
37673 + struct au_xi_calc *calc, ino_t ino)
37677 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos);
37678 + if (sz == sizeof(ino))
37679 + return 0; /* success */
37681 + AuIOErr("write failed (%zd)\n", sz);
37686 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37687 + * at the position of @h_ino.
37688 + * even if @ino is zero, it is written to the xinofile and means no entry.
37689 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37690 + * try truncating it.
37692 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37696 + unsigned int mnt_flags;
37697 + struct au_xi_calc calc;
37698 + struct file *file;
37699 + struct au_branch *br;
37700 + struct au_xino *xi;
37701 + struct au_xi_writing *p;
37703 + SiMustAnyLock(sb);
37705 + mnt_flags = au_mntflags(sb);
37706 + if (!au_opt_test(mnt_flags, XINO))
37709 + au_xi_calc(sb, h_ino, &calc);
37710 + br = au_sbr(sb, bindex);
37711 + xi = br->br_xino;
37712 + file = au_xino_file(xi, calc.idx);
37714 + /* store the inum pair into the list */
37715 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37716 + p->h_ino = h_ino;
37718 + au_hbl_add(&p->node, &xi->xi_writing);
37720 + /* create and write a new xino file asynchronously */
37721 + err = au_xino_new_async(sb, br, &calc, ino);
37723 + return 0; /* success */
37727 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino);
37729 + br = au_sbr(sb, bindex);
37730 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37731 + && au_test_fs_trunc_xino(au_br_sb(br)))
37732 + xino_try_trunc(sb, br);
37733 + return 0; /* success */
37737 + AuIOErr("write failed (%d)\n", err);
37741 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37742 + size_t size, loff_t *pos);
37744 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37745 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
37749 + mm_segment_t oldfs;
37755 + const int prevent_endless = 10;
37759 + oldfs = get_fs();
37760 + set_fs(KERNEL_DS);
37762 + err = func(file, buf.u, size, pos);
37763 + if (err == -EINTR
37764 + && !au_wkq_test()
37765 + && fatal_signal_pending(current)) {
37767 + err = xino_fread_wkq(func, file, kbuf, size, pos);
37768 + BUG_ON(err == -EINTR);
37769 + oldfs = get_fs();
37770 + set_fs(KERNEL_DS);
37772 + } while (i++ < prevent_endless
37773 + && (err == -EAGAIN || err == -EINTR));
37776 +#if 0 /* reserved for future use */
37778 + fsnotify_access(file->f_path.dentry);
37784 +struct xino_fread_args {
37786 + vfs_readf_t func;
37787 + struct file *file;
37793 +static void call_xino_fread(void *args)
37795 + struct xino_fread_args *a = args;
37796 + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos);
37799 +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf,
37800 + size_t size, loff_t *pos)
37804 + struct xino_fread_args args = {
37813 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37814 + if (unlikely(wkq_err))
37820 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37821 + size_t size, loff_t *pos);
37823 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
37824 + size_t size, loff_t *pos)
37827 + mm_segment_t oldfs;
37830 + const char __user *u;
37833 + const int prevent_endless = 10;
37837 + oldfs = get_fs();
37838 + set_fs(KERNEL_DS);
37840 + err = func(file, buf.u, size, pos);
37841 + if (err == -EINTR
37842 + && !au_wkq_test()
37843 + && fatal_signal_pending(current)) {
37845 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
37846 + BUG_ON(err == -EINTR);
37847 + oldfs = get_fs();
37848 + set_fs(KERNEL_DS);
37850 + } while (i++ < prevent_endless
37851 + && (err == -EAGAIN || err == -EINTR));
37854 +#if 0 /* reserved for future use */
37856 + fsnotify_modify(file->f_path.dentry);
37862 +struct do_xino_fwrite_args {
37864 + vfs_writef_t func;
37865 + struct file *file;
37871 +static void call_do_xino_fwrite(void *args)
37873 + struct do_xino_fwrite_args *a = args;
37874 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
37877 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
37878 + size_t size, loff_t *pos)
37882 + struct do_xino_fwrite_args args = {
37892 + * it breaks RLIMIT_FSIZE and normal user's limit,
37893 + * users should care about quota and real 'filesystem full.'
37895 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37896 + if (unlikely(wkq_err))
37902 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
37903 + size_t size, loff_t *pos)
37907 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37909 + err = do_xino_fwrite(func, file, buf, size, pos);
37913 + err = xino_fwrite_wkq(func, file, buf, size, pos);
37920 +/* ---------------------------------------------------------------------- */
37923 + * inode number bitmap
37925 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37926 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37930 + AuDebugOn(bit < 0 || page_bits <= bit);
37931 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37935 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37937 + AuDebugOn(ino < AUFS_FIRST_INO);
37938 + ino -= AUFS_FIRST_INO;
37939 + *pindex = ino / page_bits;
37940 + *bit = ino % page_bits;
37943 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37948 + struct au_sbinfo *sbinfo;
37949 + struct file *xib;
37950 + unsigned long *p;
37952 + sbinfo = au_sbi(sb);
37953 + MtxMustLock(&sbinfo->si_xib_mtx);
37954 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37955 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37957 + if (pindex == sbinfo->si_xib_last_pindex)
37960 + xib = sbinfo->si_xib;
37961 + p = sbinfo->si_xib_buf;
37962 + pos = sbinfo->si_xib_last_pindex;
37963 + pos *= PAGE_SIZE;
37964 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37965 + if (unlikely(sz != PAGE_SIZE))
37969 + pos *= PAGE_SIZE;
37970 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37971 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
37973 + memset(p, 0, PAGE_SIZE);
37974 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
37976 + if (sz == PAGE_SIZE) {
37977 + sbinfo->si_xib_last_pindex = pindex;
37978 + return 0; /* success */
37982 + AuIOErr1("write failed (%zd)\n", sz);
37989 +static void au_xib_clear_bit(struct inode *inode)
37992 + unsigned long pindex;
37993 + struct super_block *sb;
37994 + struct au_sbinfo *sbinfo;
37996 + AuDebugOn(inode->i_nlink);
37998 + sb = inode->i_sb;
37999 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38000 + AuDebugOn(page_bits <= bit);
38001 + sbinfo = au_sbi(sb);
38002 + mutex_lock(&sbinfo->si_xib_mtx);
38003 + err = xib_pindex(sb, pindex);
38005 + clear_bit(bit, sbinfo->si_xib_buf);
38006 + sbinfo->si_xib_next_bit = bit;
38008 + mutex_unlock(&sbinfo->si_xib_mtx);
38011 +/* ---------------------------------------------------------------------- */
38014 + * truncate a xino bitmap file
38018 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38022 + unsigned long pindex;
38023 + loff_t pos, pend;
38024 + struct au_sbinfo *sbinfo;
38025 + vfs_readf_t func;
38027 + unsigned long *p;
38030 + sbinfo = au_sbi(sb);
38031 + MtxMustLock(&sbinfo->si_xib_mtx);
38032 + p = sbinfo->si_xib_buf;
38033 + func = sbinfo->si_xread;
38034 + pend = vfsub_f_size_read(file);
38036 + while (pos < pend) {
38037 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
38039 + if (unlikely(sz <= 0))
38043 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38044 + if (unlikely(*ino < AUFS_FIRST_INO))
38047 + xib_calc_bit(*ino, &pindex, &bit);
38048 + AuDebugOn(page_bits <= bit);
38049 + err = xib_pindex(sb, pindex);
38061 +static int xib_restore(struct super_block *sb)
38064 + unsigned int nfile;
38065 + aufs_bindex_t bindex, bbot;
38067 + struct au_branch *br;
38068 + struct au_xino *xi;
38069 + struct file *file;
38072 + page = (void *)__get_free_page(GFP_NOFS);
38073 + if (unlikely(!page))
38077 + bbot = au_sbbot(sb);
38078 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38079 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38080 + br = au_sbr(sb, bindex);
38081 + xi = br->br_xino;
38082 + nfile = xi->xi_nfile;
38083 + for (i = 0; i < nfile; i++) {
38084 + file = au_xino_file(xi, i);
38086 + err = do_xib_restore(sb, file, page);
38089 + AuDbg("skip shared b%d\n", bindex);
38090 + free_page((unsigned long)page);
38096 +int au_xib_trunc(struct super_block *sb)
38101 + struct au_sbinfo *sbinfo;
38102 + unsigned long *p;
38103 + struct file *file;
38105 + SiMustWriteLock(sb);
38108 + sbinfo = au_sbi(sb);
38109 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38112 + file = sbinfo->si_xib;
38113 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38116 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38117 + err = PTR_ERR(file);
38118 + if (IS_ERR(file))
38120 + fput(sbinfo->si_xib);
38121 + sbinfo->si_xib = file;
38123 + p = sbinfo->si_xib_buf;
38124 + memset(p, 0, PAGE_SIZE);
38126 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
38127 + if (unlikely(sz != PAGE_SIZE)) {
38129 + AuIOErr("err %d\n", err);
38135 + mutex_lock(&sbinfo->si_xib_mtx);
38136 + /* mnt_want_write() is unnecessary here */
38137 + err = xib_restore(sb);
38138 + mutex_unlock(&sbinfo->si_xib_mtx);
38144 +/* ---------------------------------------------------------------------- */
38146 +struct au_xino *au_xino_alloc(unsigned int nfile)
38148 + struct au_xino *xi;
38150 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38151 + if (unlikely(!xi))
38153 + xi->xi_nfile = nfile;
38154 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38155 + if (unlikely(!xi->xi_file))
38158 + xi->xi_nondir.total = 8; /* initial size */
38159 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38161 + if (unlikely(!xi->xi_nondir.array))
38164 + spin_lock_init(&xi->xi_nondir.spin);
38165 + init_waitqueue_head(&xi->xi_nondir.wqh);
38166 + mutex_init(&xi->xi_mtx);
38167 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38168 + atomic_set(&xi->xi_truncating, 0);
38169 + kref_init(&xi->xi_kref);
38170 + goto out; /* success */
38173 + au_kfree_try_rcu(xi->xi_file);
38175 + au_kfree_rcu(xi);
38181 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38184 + struct au_xino *xi;
38187 + xi = au_xino_alloc(idx + 1);
38188 + if (unlikely(!xi)) {
38195 + xi->xi_file[idx] = file;
38196 + AuDebugOn(br->br_xino);
38197 + br->br_xino = xi;
38203 +static void au_xino_release(struct kref *kref)
38205 + struct au_xino *xi;
38207 + unsigned long ul;
38208 + struct hlist_bl_head *hbl;
38209 + struct hlist_bl_node *pos, *n;
38210 + struct au_xi_writing *p;
38212 + xi = container_of(kref, struct au_xino, xi_kref);
38213 + for (i = 0; i < xi->xi_nfile; i++)
38214 + if (xi->xi_file[i])
38215 + fput(xi->xi_file[i]);
38216 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38217 + AuDebugOn(xi->xi_nondir.array[i]);
38218 + mutex_destroy(&xi->xi_mtx);
38219 + hbl = &xi->xi_writing;
38220 + ul = au_hbl_count(hbl);
38221 + if (unlikely(ul)) {
38222 + pr_warn("xi_writing %lu\n", ul);
38223 + hlist_bl_lock(hbl);
38224 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38225 + hlist_bl_del(&p->node);
38226 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38229 + hlist_bl_unlock(hbl);
38231 + au_kfree_try_rcu(xi->xi_file);
38232 + au_kfree_try_rcu(xi->xi_nondir.array);
38233 + au_kfree_rcu(xi);
38236 +int au_xino_put(struct au_branch *br)
38239 + struct au_xino *xi;
38242 + xi = br->br_xino;
38244 + br->br_xino = NULL;
38245 + ret = kref_put(&xi->xi_kref, au_xino_release);
38251 +/* ---------------------------------------------------------------------- */
38254 + * xino mount option handlers
38258 +static void xino_clear_xib(struct super_block *sb)
38260 + struct au_sbinfo *sbinfo;
38262 + SiMustWriteLock(sb);
38264 + sbinfo = au_sbi(sb);
38265 + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */
38266 + if (sbinfo->si_xib)
38267 + fput(sbinfo->si_xib);
38268 + sbinfo->si_xib = NULL;
38269 + if (sbinfo->si_xib_buf)
38270 + free_page((unsigned long)sbinfo->si_xib_buf);
38271 + sbinfo->si_xib_buf = NULL;
38274 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38278 + struct au_sbinfo *sbinfo;
38279 + struct file *file;
38280 + struct super_block *xi_sb;
38282 + SiMustWriteLock(sb);
38284 + sbinfo = au_sbi(sb);
38285 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38286 + err = PTR_ERR(file);
38287 + if (IS_ERR(file))
38289 + if (sbinfo->si_xib)
38290 + fput(sbinfo->si_xib);
38291 + sbinfo->si_xib = file;
38292 + sbinfo->si_xread = vfs_readf(file);
38293 + sbinfo->si_xwrite = vfs_writef(file);
38294 + xi_sb = file_inode(file)->i_sb;
38295 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38296 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38298 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38299 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38302 + sbinfo->si_ximaxent /= sizeof(ino_t);
38305 + if (!sbinfo->si_xib_buf)
38306 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38307 + if (unlikely(!sbinfo->si_xib_buf))
38310 + sbinfo->si_xib_last_pindex = 0;
38311 + sbinfo->si_xib_next_bit = 0;
38312 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38314 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
38315 + PAGE_SIZE, &pos);
38316 + if (unlikely(err != PAGE_SIZE))
38320 + goto out; /* success */
38323 + if (sbinfo->si_xib_buf)
38324 + free_page((unsigned long)sbinfo->si_xib_buf);
38325 + sbinfo->si_xib_buf = NULL;
38329 + fput(sbinfo->si_xib);
38330 + sbinfo->si_xib = NULL;
38336 +/* xino for each branch */
38337 +static void xino_clear_br(struct super_block *sb)
38339 + aufs_bindex_t bindex, bbot;
38340 + struct au_branch *br;
38342 + bbot = au_sbbot(sb);
38343 + for (bindex = 0; bindex <= bbot; bindex++) {
38344 + br = au_sbr(sb, bindex);
38350 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38351 + aufs_bindex_t bshared)
38353 + struct au_branch *brshared;
38355 + brshared = au_sbr(sb, bshared);
38356 + AuDebugOn(!brshared->br_xino);
38357 + AuDebugOn(!brshared->br_xino->xi_file);
38358 + if (br->br_xino != brshared->br_xino) {
38359 + au_xino_get(brshared);
38361 + br->br_xino = brshared->br_xino;
38365 +struct au_xino_do_set_br {
38366 + vfs_writef_t writef;
38367 + struct au_branch *br;
38369 + aufs_bindex_t bshared;
38372 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38373 + struct au_xino_do_set_br *args)
38376 + struct au_xi_calc calc;
38377 + struct file *file;
38378 + struct au_branch *br;
38379 + struct au_xi_new xinew = {
38384 + xinew.xi = br->br_xino;
38385 + au_xi_calc(sb, args->h_ino, &calc);
38386 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38387 + if (args->bshared >= 0)
38388 + /* shared xino */
38389 + au_xino_set_br_shared(sb, br, args->bshared);
38390 + else if (!xinew.xi) {
38392 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38393 + if (unlikely(err))
38397 + /* force re-creating */
38398 + xinew.xi = br->br_xino;
38399 + xinew.idx = calc.idx;
38400 + mutex_lock(&xinew.xi->xi_mtx);
38401 + file = au_xi_new(sb, &xinew);
38402 + mutex_unlock(&xinew.xi->xi_mtx);
38403 + err = PTR_ERR(file);
38404 + if (IS_ERR(file))
38406 + AuDebugOn(!file);
38408 + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO);
38409 + if (unlikely(err))
38417 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38420 + aufs_bindex_t bindex, bbot;
38421 + struct au_xino_do_set_br args;
38422 + struct inode *inode;
38424 + SiMustWriteLock(sb);
38426 + bbot = au_sbbot(sb);
38427 + inode = d_inode(sb->s_root);
38428 + args.writef = au_sbi(sb)->si_xwrite;
38429 + for (bindex = 0; bindex <= bbot; bindex++) {
38430 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38431 + args.br = au_sbr(sb, bindex);
38432 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38433 + err = au_xino_do_set_br(sb, path, &args);
38434 + if (unlikely(err))
38442 +void au_xino_clr(struct super_block *sb)
38444 + struct au_sbinfo *sbinfo;
38446 + au_xigen_clr(sb);
38447 + xino_clear_xib(sb);
38448 + xino_clear_br(sb);
38449 + dbgaufs_brs_del(sb, 0);
38450 + sbinfo = au_sbi(sb);
38451 + /* lvalue, do not call au_mntflags() */
38452 + au_opt_clr(sbinfo->si_mntflags, XINO);
38455 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38458 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38459 + struct qstr *dname, *cur_name;
38460 + struct file *cur_xino;
38461 + struct au_sbinfo *sbinfo;
38462 + struct path *path, *cur_path;
38464 + SiMustWriteLock(sb);
38467 + sbinfo = au_sbi(sb);
38468 + path = &xiopt->file->f_path;
38469 + dentry = path->dentry;
38470 + parent = dget_parent(dentry);
38473 + cur_xino = sbinfo->si_xib;
38475 + cur_path = &cur_xino->f_path;
38476 + cur_dentry = cur_path->dentry;
38477 + cur_parent = dget_parent(cur_dentry);
38478 + cur_name = &cur_dentry->d_name;
38479 + dname = &dentry->d_name;
38480 + skip = (cur_parent == parent
38481 + && au_qstreq(dname, cur_name));
38482 + dput(cur_parent);
38488 + au_opt_set(sbinfo->si_mntflags, XINO);
38489 + err = au_xino_set_xib(sb, path);
38490 + /* si_x{read,write} are set */
38492 + err = au_xigen_set(sb, path);
38494 + err = au_xino_set_br(sb, path);
38496 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38497 + goto out; /* success */
38501 + AuIOErr("failed setting xino(%d).\n", err);
38510 + * create a xinofile at the default place/path.
38512 +struct file *au_xino_def(struct super_block *sb)
38514 + struct file *file;
38516 + struct au_branch *br;
38517 + struct super_block *h_sb;
38518 + struct path path;
38519 + aufs_bindex_t bbot, bindex, bwr;
38522 + bbot = au_sbbot(sb);
38524 + for (bindex = 0; bindex <= bbot; bindex++) {
38525 + br = au_sbr(sb, bindex);
38526 + if (au_br_writable(br->br_perm)
38527 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38534 + file = ERR_PTR(-ENOMEM);
38535 + page = (void *)__get_free_page(GFP_NOFS);
38536 + if (unlikely(!page))
38538 + path.mnt = au_br_mnt(br);
38539 + path.dentry = au_h_dptr(sb->s_root, bwr);
38540 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38541 + file = (void *)p;
38542 + if (!IS_ERR(p)) {
38543 + strcat(p, "/" AUFS_XINO_FNAME);
38544 + AuDbg("%s\n", p);
38545 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38547 + free_page((unsigned long)page);
38549 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38551 + if (IS_ERR(file))
38553 + h_sb = file->f_path.dentry->d_sb;
38554 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38555 + pr_err("xino doesn't support %s(%s)\n",
38556 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38558 + file = ERR_PTR(-EINVAL);
38566 +/* ---------------------------------------------------------------------- */
38569 + * initialize the xinofile for the specified branch @br
38570 + * at the place/path where @base_file indicates.
38571 + * test whether another branch is on the same filesystem or not,
38572 + * if found then share the xinofile with another branch.
38574 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38575 + struct path *base)
38578 + struct au_xino_do_set_br args = {
38583 + args.writef = au_sbi(sb)->si_xwrite;
38584 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38586 + err = au_xino_do_set_br(sb, base, &args);
38587 + if (unlikely(err))
38593 +/* ---------------------------------------------------------------------- */
38596 + * get an unused inode number from bitmap
38598 +ino_t au_xino_new_ino(struct super_block *sb)
38601 + unsigned long *p, pindex, ul, pend;
38602 + struct au_sbinfo *sbinfo;
38603 + struct file *file;
38604 + int free_bit, err;
38606 + if (!au_opt_test(au_mntflags(sb), XINO))
38607 + return iunique(sb, AUFS_FIRST_INO);
38609 + sbinfo = au_sbi(sb);
38610 + mutex_lock(&sbinfo->si_xib_mtx);
38611 + p = sbinfo->si_xib_buf;
38612 + free_bit = sbinfo->si_xib_next_bit;
38613 + if (free_bit < page_bits && !test_bit(free_bit, p))
38614 + goto out; /* success */
38615 + free_bit = find_first_zero_bit(p, page_bits);
38616 + if (free_bit < page_bits)
38617 + goto out; /* success */
38619 + pindex = sbinfo->si_xib_last_pindex;
38620 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38621 + err = xib_pindex(sb, ul);
38622 + if (unlikely(err))
38624 + free_bit = find_first_zero_bit(p, page_bits);
38625 + if (free_bit < page_bits)
38626 + goto out; /* success */
38629 + file = sbinfo->si_xib;
38630 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38631 + for (ul = pindex + 1; ul <= pend; ul++) {
38632 + err = xib_pindex(sb, ul);
38633 + if (unlikely(err))
38635 + free_bit = find_first_zero_bit(p, page_bits);
38636 + if (free_bit < page_bits)
38637 + goto out; /* success */
38642 + set_bit(free_bit, p);
38643 + sbinfo->si_xib_next_bit = free_bit + 1;
38644 + pindex = sbinfo->si_xib_last_pindex;
38645 + mutex_unlock(&sbinfo->si_xib_mtx);
38646 + ino = xib_calc_ino(pindex, free_bit);
38647 + AuDbg("i%lu\n", (unsigned long)ino);
38650 + mutex_unlock(&sbinfo->si_xib_mtx);
38655 +/* for s_op->delete_inode() */
38656 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38659 + unsigned int mnt_flags;
38660 + aufs_bindex_t bindex, bbot, bi;
38661 + unsigned char try_trunc;
38662 + struct au_iinfo *iinfo;
38663 + struct super_block *sb;
38664 + struct au_hinode *hi;
38665 + struct inode *h_inode;
38666 + struct au_branch *br;
38667 + vfs_writef_t xwrite;
38668 + struct au_xi_calc calc;
38669 + struct file *file;
38671 + AuDebugOn(au_is_bad_inode(inode));
38673 + sb = inode->i_sb;
38674 + mnt_flags = au_mntflags(sb);
38675 + if (!au_opt_test(mnt_flags, XINO)
38676 + || inode->i_ino == AUFS_ROOT_INO)
38680 + au_xigen_inc(inode);
38681 + au_xib_clear_bit(inode);
38684 + iinfo = au_ii(inode);
38685 + bindex = iinfo->ii_btop;
38689 + xwrite = au_sbi(sb)->si_xwrite;
38690 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38691 + hi = au_hinode(iinfo, bindex);
38692 + bbot = iinfo->ii_bbot;
38693 + for (; bindex <= bbot; bindex++, hi++) {
38694 + h_inode = hi->hi_inode;
38696 + || (!unlinked && h_inode->i_nlink))
38699 + /* inode may not be revalidated */
38700 + bi = au_br_index(sb, hi->hi_id);
38704 + br = au_sbr(sb, bi);
38705 + au_xi_calc(sb, h_inode->i_ino, &calc);
38706 + file = au_xino_file(br->br_xino, calc.idx);
38707 + if (IS_ERR_OR_NULL(file))
38710 + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0);
38711 + if (!err && try_trunc
38712 + && au_test_fs_trunc_xino(au_br_sb(br)))
38713 + xino_try_trunc(sb, br);
38717 +/* ---------------------------------------------------------------------- */
38719 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38721 + int found, total, i;
38724 + total = xi->xi_nondir.total;
38725 + for (i = 0; i < total; i++) {
38726 + if (xi->xi_nondir.array[i] != h_ino)
38735 +static int au_xinondir_expand(struct au_xino *xi)
38740 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38743 + sz = xi->xi_nondir.total * sizeof(ino_t);
38744 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38746 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38747 + /*may_shrink*/0);
38749 + xi->xi_nondir.array = p;
38750 + xi->xi_nondir.total <<= 1;
38751 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38759 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38760 + ino_t h_ino, int idx)
38762 + struct au_xino *xi;
38764 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38765 + xi = au_sbr(sb, bindex)->br_xino;
38766 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38768 + spin_lock(&xi->xi_nondir.spin);
38769 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38770 + xi->xi_nondir.array[idx] = 0;
38771 + spin_unlock(&xi->xi_nondir.spin);
38772 + wake_up_all(&xi->xi_nondir.wqh);
38775 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38778 + int err, found, empty;
38779 + struct au_xino *xi;
38783 + if (!au_opt_test(au_mntflags(sb), XINO))
38784 + goto out; /* no xino */
38786 + xi = au_sbr(sb, bindex)->br_xino;
38789 + spin_lock(&xi->xi_nondir.spin);
38790 + found = au_xinondir_find(xi, h_ino);
38791 + if (found == -1) {
38792 + empty = au_xinondir_find(xi, /*h_ino*/0);
38793 + if (empty == -1) {
38794 + empty = xi->xi_nondir.total;
38795 + err = au_xinondir_expand(xi);
38796 + if (unlikely(err))
38799 + xi->xi_nondir.array[empty] = h_ino;
38802 + spin_unlock(&xi->xi_nondir.spin);
38803 + wait_event(xi->xi_nondir.wqh,
38804 + xi->xi_nondir.array[found] != h_ino);
38809 + spin_unlock(&xi->xi_nondir.spin);
38814 +/* ---------------------------------------------------------------------- */
38816 +int au_xino_path(struct seq_file *seq, struct file *file)
38820 + err = au_seq_path(seq, &file->f_path);
38821 + if (unlikely(err))
38824 +#define Deleted "\\040(deleted)"
38825 + seq->count -= sizeof(Deleted) - 1;
38826 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38827 + sizeof(Deleted) - 1));
38833 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38834 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38835 +++ linux/include/uapi/linux/aufs_type.h 2021-02-22 23:30:37.706014241 +0100
38837 +/* SPDX-License-Identifier: GPL-2.0 */
38839 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38841 + * This program, aufs is free software; you can redistribute it and/or modify
38842 + * it under the terms of the GNU General Public License as published by
38843 + * the Free Software Foundation; either version 2 of the License, or
38844 + * (at your option) any later version.
38846 + * This program is distributed in the hope that it will be useful,
38847 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38848 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38849 + * GNU General Public License for more details.
38851 + * You should have received a copy of the GNU General Public License
38852 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38855 +#ifndef __AUFS_TYPE_H__
38856 +#define __AUFS_TYPE_H__
38858 +#define AUFS_NAME "aufs"
38862 + * define it before including all other headers.
38863 + * sched.h may use pr_* macros before defining "current", so define the
38864 + * no-current version first, and re-define later.
38866 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38867 +#include <linux/sched.h>
38869 +#define pr_fmt(fmt) \
38870 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38871 + (int)sizeof(current->comm), current->comm, current->pid
38872 +#include <linux/limits.h>
38874 +#include <stdint.h>
38875 +#include <sys/types.h>
38876 +#include <limits.h>
38877 +#endif /* __KERNEL__ */
38879 +#define AUFS_VERSION "4.19-20200622"
38881 +/* todo? move this to linux-2.6.19/include/magic.h */
38882 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38884 +/* ---------------------------------------------------------------------- */
38887 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38888 +typedef int8_t aufs_bindex_t;
38889 +#define AUFS_BRANCH_MAX 127
38891 +typedef int16_t aufs_bindex_t;
38892 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38893 +#define AUFS_BRANCH_MAX 511
38894 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38895 +#define AUFS_BRANCH_MAX 1023
38896 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38897 +#define AUFS_BRANCH_MAX 32767
38901 +#ifndef AUFS_BRANCH_MAX
38902 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38904 +#endif /* __KERNEL__ */
38906 +/* ---------------------------------------------------------------------- */
38908 +#define AUFS_FSTYPE AUFS_NAME
38910 +#define AUFS_ROOT_INO 2
38911 +#define AUFS_FIRST_INO 11
38913 +#define AUFS_WH_PFX ".wh."
38914 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38915 +#define AUFS_WH_TMP_LEN 4
38916 +/* a limit for rmdir/rename a dir and copyup */
38917 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38918 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38920 + - AUFS_WH_TMP_LEN) /* hex */
38921 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38922 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38923 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38924 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38925 +#define AUFS_DIRWH_DEF 3
38926 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38927 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38928 +#define AUFS_RDBLK_DEF 512 /* bytes */
38929 +#define AUFS_RDHASH_DEF 32
38930 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38931 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38932 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38933 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38934 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38936 +/* pseudo-link maintenace under /proc */
38937 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38938 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38939 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38941 +/* dirren, renamed dir */
38942 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38943 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38944 +/* whiteouted doubly */
38945 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38946 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38948 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38949 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38951 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38952 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38953 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38955 +/* doubly whiteouted */
38956 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38957 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38958 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38960 +/* branch permissions and attributes */
38961 +#define AUFS_BRPERM_RW "rw"
38962 +#define AUFS_BRPERM_RO "ro"
38963 +#define AUFS_BRPERM_RR "rr"
38964 +#define AUFS_BRATTR_COO_REG "coo_reg"
38965 +#define AUFS_BRATTR_COO_ALL "coo_all"
38966 +#define AUFS_BRATTR_FHSM "fhsm"
38967 +#define AUFS_BRATTR_UNPIN "unpin"
38968 +#define AUFS_BRATTR_ICEX "icex"
38969 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38970 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38971 +#define AUFS_BRATTR_ICEX_TR "icextr"
38972 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38973 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38974 +#define AUFS_BRRATTR_WH "wh"
38975 +#define AUFS_BRWATTR_NLWH "nolwh"
38976 +#define AUFS_BRWATTR_MOO "moo"
38978 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38979 +#define AuBrPerm_RO (1 << 1) /* readonly */
38980 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38981 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38983 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38984 +#define AuBrAttr_COO_ALL (1 << 4)
38985 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38987 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38988 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38989 + branch. meaningless since
38990 + linux-3.18-rc1 */
38992 +/* ignore error in copying XATTR */
38993 +#define AuBrAttr_ICEX_SEC (1 << 7)
38994 +#define AuBrAttr_ICEX_SYS (1 << 8)
38995 +#define AuBrAttr_ICEX_TR (1 << 9)
38996 +#define AuBrAttr_ICEX_USR (1 << 10)
38997 +#define AuBrAttr_ICEX_OTH (1 << 11)
38998 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38999 + | AuBrAttr_ICEX_SYS \
39000 + | AuBrAttr_ICEX_TR \
39001 + | AuBrAttr_ICEX_USR \
39002 + | AuBrAttr_ICEX_OTH)
39004 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39005 +#define AuBrRAttr_Mask AuBrRAttr_WH
39007 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39008 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39009 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39011 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39013 +/* #warning test userspace */
39015 +#ifndef CONFIG_AUFS_FHSM
39016 +#undef AuBrAttr_FHSM
39017 +#define AuBrAttr_FHSM 0
39019 +#ifndef CONFIG_AUFS_XATTR
39020 +#undef AuBrAttr_ICEX
39021 +#define AuBrAttr_ICEX 0
39022 +#undef AuBrAttr_ICEX_SEC
39023 +#define AuBrAttr_ICEX_SEC 0
39024 +#undef AuBrAttr_ICEX_SYS
39025 +#define AuBrAttr_ICEX_SYS 0
39026 +#undef AuBrAttr_ICEX_TR
39027 +#define AuBrAttr_ICEX_TR 0
39028 +#undef AuBrAttr_ICEX_USR
39029 +#define AuBrAttr_ICEX_USR 0
39030 +#undef AuBrAttr_ICEX_OTH
39031 +#define AuBrAttr_ICEX_OTH 0
39035 +/* the longest combination */
39036 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39037 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39038 + "+" AUFS_BRATTR_COO_REG \
39039 + "+" AUFS_BRATTR_FHSM \
39040 + "+" AUFS_BRATTR_UNPIN \
39041 + "+" AUFS_BRATTR_ICEX_SEC \
39042 + "+" AUFS_BRATTR_ICEX_SYS \
39043 + "+" AUFS_BRATTR_ICEX_USR \
39044 + "+" AUFS_BRATTR_ICEX_OTH \
39045 + "+" AUFS_BRWATTR_NLWH)
39048 + char a[AuBrPermStrSz];
39049 +} au_br_perm_str_t;
39051 +static inline int au_br_writable(int brperm)
39053 + return brperm & AuBrPerm_RW;
39056 +static inline int au_br_whable(int brperm)
39058 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39061 +static inline int au_br_wh_linkable(int brperm)
39063 + return !(brperm & AuBrWAttr_NoLinkWH);
39066 +static inline int au_br_cmoo(int brperm)
39068 + return brperm & AuBrAttr_CMOO_Mask;
39071 +static inline int au_br_fhsm(int brperm)
39073 + return brperm & AuBrAttr_FHSM;
39076 +/* ---------------------------------------------------------------------- */
39080 + /* readdir in userspace */
39084 + AuCtl_WBR_FD, /* pathconf wrapper */
39085 + AuCtl_IBUSY, /* busy inode */
39086 + AuCtl_MVDOWN, /* move-down */
39087 + AuCtl_BR, /* info about branches */
39088 + AuCtl_FHSM_FD /* connection for fhsm */
39091 +/* borrowed from linux/include/linux/kernel.h */
39093 +#ifdef _GNU_SOURCE
39094 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39096 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39098 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39101 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39103 +#define __aligned(x) __attribute__((aligned(x)))
39108 +#define __packed __attribute__((packed))
39112 +struct au_rdu_cookie {
39117 + uint32_t generation;
39120 +struct au_rdu_ent {
39129 +static inline int au_rdu_len(int nlen)
39131 + /* include the terminating NULL */
39132 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39133 + sizeof(uint64_t));
39136 +union au_rdu_ent_ul {
39137 + struct au_rdu_ent __user *e;
39149 + uint64_t sz; /* AuCtl_RDU */
39150 + uint64_t nent; /* AuCtl_RDU_INO */
39152 + union au_rdu_ent_ul ent;
39153 + uint16_t verify[AufsCtlRduV_End];
39155 + /* input/output */
39159 + union au_rdu_ent_ul tail;
39160 + /* number of entries which were added in a single call */
39165 + struct au_rdu_cookie cookie;
39168 +/* ---------------------------------------------------------------------- */
39170 +/* dirren. the branch is identified by the filename who contains this */
39171 +struct au_drinfo {
39174 + uint8_t oldnamelen;
39175 + uint64_t _padding;
39177 + uint8_t oldname[];
39180 +struct au_drinfo_fdata {
39182 + struct au_drinfo drinfo;
39185 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39187 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39189 +/* ---------------------------------------------------------------------- */
39191 +struct aufs_wbr_fd {
39196 +/* ---------------------------------------------------------------------- */
39198 +struct aufs_ibusy {
39199 + uint64_t ino, h_ino;
39203 +/* ---------------------------------------------------------------------- */
39205 +/* error code for move-down */
39206 +/* the actual message strings are implemented in aufs-util.git */
39208 + EAU_MVDOWN_OPAQUE = 1,
39209 + EAU_MVDOWN_WHITEOUT,
39210 + EAU_MVDOWN_UPPER,
39211 + EAU_MVDOWN_BOTTOM,
39212 + EAU_MVDOWN_NOUPPER,
39213 + EAU_MVDOWN_NOLOWERBR,
39217 +/* flags for move-down */
39218 +#define AUFS_MVDOWN_DMSG 1
39219 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39220 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39221 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39222 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39223 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39224 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39225 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39226 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39227 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39228 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39229 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39230 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39232 +/* index for move-down */
39234 + AUFS_MVDOWN_UPPER,
39235 + AUFS_MVDOWN_LOWER,
39236 + AUFS_MVDOWN_NARRAY
39240 + * additional info of move-down
39241 + * number of free blocks and inodes.
39242 + * subset of struct kstatfs, but smaller and always 64bit.
39244 +struct aufs_stfs {
39245 + uint64_t f_blocks;
39246 + uint64_t f_bavail;
39247 + uint64_t f_files;
39248 + uint64_t f_ffree;
39251 +struct aufs_stbr {
39252 + int16_t brid; /* optional input */
39253 + int16_t bindex; /* output */
39254 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39257 +struct aufs_mvdown {
39258 + uint32_t flags; /* input/output */
39259 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39260 + int8_t au_errno; /* output */
39263 +/* ---------------------------------------------------------------------- */
39265 +union aufs_brinfo {
39266 + /* PATH_MAX may differ between kernel-space and user-space */
39267 + char _spacer[4096];
39275 +/* ---------------------------------------------------------------------- */
39277 +#define AuCtlType 'A'
39278 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39279 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39280 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39281 + struct aufs_wbr_fd)
39282 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39283 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39284 + struct aufs_mvdown)
39285 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39286 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39288 +#endif /* __AUFS_TYPE_H__ */
39289 SPDX-License-Identifier: GPL-2.0
39290 aufs4.19 loopback patch
39292 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39293 index 9e534a36c5941..74cd74e6374b0 100644
39294 --- a/drivers/block/loop.c
39295 +++ b/drivers/block/loop.c
39296 @@ -626,6 +626,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39300 +static struct file *loop_real_file(struct file *file)
39302 + struct file *f = NULL;
39304 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39305 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39309 static void loop_reread_partitions(struct loop_device *lo,
39310 struct block_device *bdev)
39312 @@ -690,6 +699,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39315 struct file *file = NULL, *old_file;
39316 + struct file *f, *virt_file = NULL, *old_virt_file;
39320 @@ -705,12 +715,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39324 + f = loop_real_file(file);
39326 + virt_file = file;
39331 error = loop_validate_file(file, bdev);
39335 old_file = lo->lo_backing_file;
39336 + old_virt_file = lo->lo_backing_virt_file;
39340 @@ -722,6 +739,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39341 blk_mq_freeze_queue(lo->lo_queue);
39342 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39343 lo->lo_backing_file = file;
39344 + lo->lo_backing_virt_file = virt_file;
39345 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39346 mapping_set_gfp_mask(file->f_mapping,
39347 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39348 @@ -729,14 +747,18 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39352 + if (old_virt_file)
39353 + fput(old_virt_file);
39355 loop_reread_partitions(lo, bdev);
39359 mutex_unlock(&loop_ctl_mutex);
39367 @@ -922,7 +944,7 @@ static int loop_prepare_queue(struct loop_device *lo)
39368 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39369 struct block_device *bdev, unsigned int arg)
39371 - struct file *file;
39372 + struct file *file, *f, *virt_file = NULL;
39373 struct inode *inode;
39374 struct address_space *mapping;
39376 @@ -936,6 +958,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39380 + f = loop_real_file(file);
39382 + virt_file = file;
39387 error = mutex_lock_killable(&loop_ctl_mutex);
39389 @@ -968,6 +996,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39390 lo->lo_device = bdev;
39391 lo->lo_flags = lo_flags;
39392 lo->lo_backing_file = file;
39393 + lo->lo_backing_virt_file = virt_file;
39394 lo->transfer = NULL;
39396 lo->lo_sizelimit = 0;
39397 @@ -1001,6 +1030,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
39398 mutex_unlock(&loop_ctl_mutex);
39404 /* This is safe: open() is still holding a reference. */
39405 module_put(THIS_MODULE);
39406 @@ -1047,6 +1078,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
39407 static int __loop_clr_fd(struct loop_device *lo, bool release)
39409 struct file *filp = NULL;
39410 + struct file *virt_filp = lo->lo_backing_virt_file;
39411 gfp_t gfp = lo->old_gfp_mask;
39412 struct block_device *bdev = lo->lo_device;
39414 @@ -1078,6 +1110,7 @@ static int loop_clr_fd(struct loop_device *lo)
39416 spin_lock_irq(&lo->lo_lock);
39417 lo->lo_backing_file = NULL;
39418 + lo->lo_backing_virt_file = NULL;
39419 spin_unlock_irq(&lo->lo_lock);
39421 loop_release_xfer(lo);
39422 @@ -1126,6 +1159,8 @@ static int loop_clr_fd(struct loop_device *lo)
39431 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39432 index 4d42c7af7de75..a15dd5bff5eae 100644
39433 --- a/drivers/block/loop.h
39434 +++ b/drivers/block/loop.h
39435 @@ -46,7 +46,7 @@ struct loop_device {
39436 int (*ioctl)(struct loop_device *, int cmd,
39437 unsigned long arg);
39439 - struct file * lo_backing_file;
39440 + struct file *lo_backing_file, *lo_backing_virt_file;
39441 struct block_device *lo_device;
39444 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39445 index 6fb4a4ed8cc7f..ba9a959f2db27 100644
39446 --- a/fs/aufs/f_op.c
39447 +++ b/fs/aufs/f_op.c
39448 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39449 if (IS_ERR(h_file))
39452 - if (au_test_loopback_kthread()) {
39453 + if (0 && au_test_loopback_kthread()) {
39454 au_warn_loopback(h_file->f_path.dentry->d_sb);
39455 if (file->f_mapping != h_file->f_mapping) {
39456 file->f_mapping = h_file->f_mapping;
39457 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39458 index 50e80bd1d589d..d0f9777267f99 100644
39459 --- a/fs/aufs/loop.c
39460 +++ b/fs/aufs/loop.c
39461 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39462 symbol_put(loop_backing_file);
39463 au_kfree_try_rcu(au_warn_loopback_array);
39466 +/* ---------------------------------------------------------------------- */
39468 +/* support the loopback block device insude aufs */
39470 +struct file *aufs_real_loop(struct file *file)
39474 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39475 + fi_read_lock(file);
39476 + f = au_hf_top(file);
39477 + fi_read_unlock(file);
39481 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39482 index 94f4f80ae33bf..ca1194354aff4 100644
39483 --- a/fs/aufs/loop.h
39484 +++ b/fs/aufs/loop.h
39485 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39487 int au_loopback_init(void);
39488 void au_loopback_fin(void);
39490 +struct file *aufs_real_loop(struct file *file);
39492 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39494 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39496 AuStubInt0(au_loopback_init, void)
39497 AuStubVoid(au_loopback_fin, void)
39499 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39500 #endif /* BLK_DEV_LOOP */
39502 #endif /* __KERNEL__ */
39503 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39504 index e3b81808a78a7..eff4f475de060 100644
39505 --- a/fs/aufs/super.c
39506 +++ b/fs/aufs/super.c
39507 @@ -846,7 +846,10 @@ static const struct super_operations aufs_sop = {
39508 .statfs = aufs_statfs,
39509 .put_super = aufs_put_super,
39510 .sync_fs = aufs_sync_fs,
39511 - .remount_fs = aufs_remount_fs
39512 + .remount_fs = aufs_remount_fs,
39513 +#ifdef CONFIG_AUFS_BDEV_LOOP
39514 + .real_loop = aufs_real_loop
39518 /* ---------------------------------------------------------------------- */
39519 diff --git a/include/linux/fs.h b/include/linux/fs.h
39520 index 41da4219febfe..72fe934fd55b0 100644
39521 --- a/include/linux/fs.h
39522 +++ b/include/linux/fs.h
39523 @@ -1882,6 +1882,10 @@ struct super_operations {
39524 struct shrink_control *);
39525 long (*free_cached_objects)(struct super_block *,
39526 struct shrink_control *);
39527 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39529 + struct file *(*real_loop)(struct file *);