1 SPDX-License-Identifier: GPL-2.0
2 aufs5.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index 6c7dc1387beb0..4af0a823e5f24 100644
8 @@ -312,6 +312,7 @@ source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/erofs/Kconfig"
11 source "fs/vboxsf/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 208a74e0b00e1..57d47a0762e0a 100644
20 @@ -140,3 +140,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
21 obj-$(CONFIG_EROFS_FS) += erofs/
22 obj-$(CONFIG_VBOXSF_FS) += vboxsf/
23 obj-$(CONFIG_ZONEFS_FS) += zonefs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs5.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 05fd080b82f3a..9554f31190578 100644
32 @@ -3235,6 +3235,19 @@ 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
41 +W: http://aufs.sourceforge.net
42 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: Documentation/filesystems/aufs/
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda <ojeda@kernel.org>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index 19fe19eaa50e9..9009a0efc4b28 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -636,6 +636,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 c84269c6e8bf6..6f4f48c828351 100644
85 @@ -1345,7 +1345,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 9c6c6a3e2de51..02382fa9bd341 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 @@ -64,6 +64,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/namespace.c b/fs/namespace.c
117 index de6fae84f1a1a..e189393b34b14 100644
120 @@ -839,6 +839,12 @@ static inline int check_mnt(struct mount *mnt)
121 return mnt->mnt_ns == current->nsproxy->mnt_ns;
124 +/* for aufs, CONFIG_AUFS_BR_FUSE */
125 +int is_current_mnt_ns(struct vfsmount *mnt)
127 + return check_mnt(real_mount(mnt));
131 * vfsmount lock must be held for write
133 diff --git a/fs/splice.c b/fs/splice.c
134 index 5dbce4dcc1a7d..3e6ba363b7775 100644
137 @@ -759,8 +759,8 @@ static int warn_unsupported(struct file *file, const char *op)
139 * Attempt to initiate a splice from pipe to file.
141 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
142 - loff_t *ppos, size_t len, unsigned int flags)
143 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
144 + loff_t *ppos, size_t len, unsigned int flags)
146 if (unlikely(!out->f_op->splice_write))
147 return warn_unsupported(out, "write");
148 @@ -770,9 +770,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
150 * Attempt to initiate a splice from a file to a pipe.
152 -static long do_splice_to(struct file *in, loff_t *ppos,
153 - struct pipe_inode_info *pipe, size_t len,
154 - unsigned int flags)
155 +long do_splice_to(struct file *in, loff_t *ppos,
156 + struct pipe_inode_info *pipe, size_t len,
157 + unsigned int flags)
159 unsigned int p_space;
161 diff --git a/include/linux/fs.h b/include/linux/fs.h
162 index e2d892b201b07..5479e6dc18a23 100644
163 --- a/include/linux/fs.h
164 +++ b/include/linux/fs.h
165 @@ -1372,6 +1372,7 @@ extern void fasync_free(struct fasync_struct *);
166 /* can be called from interrupts */
167 extern void kill_fasync(struct fasync_struct **, int, int);
169 +extern int setfl(int fd, struct file *filp, unsigned long arg);
170 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
171 extern int f_setown(struct file *filp, unsigned long arg, int force);
172 extern void f_delown(struct file *filp);
173 @@ -2003,6 +2004,7 @@ struct file_operations {
174 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
175 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
176 int (*check_flags)(int);
177 + int (*setfl)(struct file *, unsigned long);
178 int (*flock) (struct file *, int, struct file_lock *);
179 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
180 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
181 @@ -2529,6 +2531,7 @@ extern int current_umask(void);
182 extern void ihold(struct inode * inode);
183 extern void iput(struct inode *);
184 extern int generic_update_time(struct inode *, struct timespec64 *, int);
185 +extern int update_time(struct inode *, struct timespec64 *, int);
188 extern struct kobject *fs_kobj;
189 @@ -2707,6 +2710,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
192 void emergency_thaw_all(void);
193 +extern int __sync_filesystem(struct super_block *, int);
194 extern int sync_filesystem(struct super_block *);
195 extern const struct file_operations def_blk_fops;
196 extern const struct file_operations def_chr_fops;
197 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
198 index 467b94257105e..dab20282c82e2 100644
199 --- a/include/linux/lockdep.h
200 +++ b/include/linux/lockdep.h
201 @@ -248,6 +248,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
202 return lock->key == key;
205 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
210 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
211 index 8f882f5881e87..6b9808f098435 100644
212 --- a/include/linux/mnt_namespace.h
213 +++ b/include/linux/mnt_namespace.h
214 @@ -7,12 +7,15 @@ struct mnt_namespace;
216 struct user_namespace;
220 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
221 struct user_namespace *, struct fs_struct *);
222 extern void put_mnt_ns(struct mnt_namespace *ns);
223 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
225 +extern int is_current_mnt_ns(struct vfsmount *mnt);
227 extern const struct file_operations proc_mounts_operations;
228 extern const struct file_operations proc_mountinfo_operations;
229 extern const struct file_operations proc_mountstats_operations;
230 diff --git a/include/linux/splice.h b/include/linux/splice.h
231 index a55179fd60fc3..8e21c53cf8831 100644
232 --- a/include/linux/splice.h
233 +++ b/include/linux/splice.h
234 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
236 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
237 extern const struct pipe_buf_operations default_pipe_buf_ops;
239 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
240 + loff_t *ppos, size_t len, unsigned int flags);
241 +extern long do_splice_to(struct file *in, loff_t *ppos,
242 + struct pipe_inode_info *pipe, size_t len,
243 + unsigned int flags);
245 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
246 index f8a0212189cad..43e3d1fdd570b 100644
247 --- a/kernel/locking/lockdep.c
248 +++ b/kernel/locking/lockdep.c
249 @@ -189,7 +189,7 @@ static
250 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
251 DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
253 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
254 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
256 unsigned int class_idx = hlock->class_idx;
258 @@ -210,6 +210,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
260 return lock_classes + class_idx;
262 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
264 #ifdef CONFIG_LOCK_STAT
265 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
266 SPDX-License-Identifier: GPL-2.0
267 aufs5.x-rcN mmap patch
269 diff --git a/fs/proc/base.c b/fs/proc/base.c
270 index d654ce7150fdd..422713de90f60 100644
273 @@ -2191,7 +2191,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
275 vma = find_exact_vma(mm, vm_start, vm_end);
276 if (vma && vma->vm_file) {
277 - *path = vma->vm_file->f_path;
278 + *path = vma_pr_or_file(vma)->f_path;
282 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
283 index 13452b32e2bd5..38acccfef9d49 100644
284 --- a/fs/proc/nommu.c
285 +++ b/fs/proc/nommu.c
286 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
287 file = region->vm_file;
290 - struct inode *inode = file_inode(region->vm_file);
291 + struct inode *inode;
293 + file = vmr_pr_or_file(region);
294 + inode = file_inode(file);
295 dev = inode->i_sb->s_dev;
298 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
299 index f46060eb91b5c..2a7c8709acadd 100644
300 --- a/fs/proc/task_mmu.c
301 +++ b/fs/proc/task_mmu.c
302 @@ -281,7 +281,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
303 const char *name = NULL;
306 - struct inode *inode = file_inode(vma->vm_file);
307 + struct inode *inode;
309 + file = vma_pr_or_file(vma);
310 + inode = file_inode(file);
311 dev = inode->i_sb->s_dev;
313 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
314 @@ -1903,7 +1906,7 @@ static int show_numa_map(struct seq_file *m, void *v)
315 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
316 struct vm_area_struct *vma = v;
317 struct numa_maps *md = &numa_priv->md;
318 - struct file *file = vma->vm_file;
319 + struct file *file = vma_pr_or_file(vma);
320 struct mm_struct *mm = vma->vm_mm;
321 struct mempolicy *pol;
323 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
324 index a6d21fc0033c6..02c2de31196e0 100644
325 --- a/fs/proc/task_nommu.c
326 +++ b/fs/proc/task_nommu.c
327 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
331 - struct inode *inode = file_inode(vma->vm_file);
332 + struct inode *inode;
334 + file = vma_pr_or_file(vma);
335 + inode = file_inode(file);
336 dev = inode->i_sb->s_dev;
338 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
339 diff --git a/include/linux/mm.h b/include/linux/mm.h
340 index 5744a3fc47169..f2f4c5ec69530 100644
341 --- a/include/linux/mm.h
342 +++ b/include/linux/mm.h
343 @@ -1895,6 +1895,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
344 unmap_mapping_range(mapping, holebegin, holelen, 0);
347 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
348 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
350 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
351 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
353 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
355 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
357 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
358 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
361 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
362 +extern void vmr_do_fput(struct vm_region *, const char[], int);
364 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
366 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
367 +#endif /* !CONFIG_MMU */
369 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
370 void *buf, int len, unsigned int gup_flags);
371 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
372 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
373 index 0f549870da6a0..67d02ae46b8fa 100644
374 --- a/include/linux/mm_types.h
375 +++ b/include/linux/mm_types.h
376 @@ -344,6 +344,7 @@ struct vm_region {
377 unsigned long vm_top; /* region allocated to here */
378 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
379 struct file *vm_file; /* the backing file or NULL */
380 + struct file *vm_prfile; /* the virtual backing file or NULL */
382 int vm_usage; /* region usage count (access under nommu_region_sem) */
383 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
384 @@ -440,6 +441,7 @@ struct vm_area_struct {
385 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
387 struct file * vm_file; /* File we map to (can be NULL). */
388 + struct file *vm_prfile; /* shadow of vm_file */
389 void * vm_private_data; /* was vm_pte (shared mem) */
392 diff --git a/kernel/fork.c b/kernel/fork.c
393 index f1e89007f2288..f085ecd96a7db 100644
396 @@ -575,7 +575,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
398 struct address_space *mapping = file->f_mapping;
402 i_mmap_lock_write(mapping);
403 if (tmp->vm_flags & VM_SHARED)
404 mapping_allow_writable(mapping);
405 diff --git a/mm/Makefile b/mm/Makefile
406 index 70d4309c9ce33..9acff75987dfa 100644
409 @@ -54,7 +54,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
410 mm_init.o percpu.o slab_common.o \
411 compaction.o vmacache.o \
412 interval_tree.o list_lru.o workingset.o \
413 - debug.o gup.o mmap_lock.o $(mmu-y)
414 + prfile.o debug.o gup.o mmap_lock.o $(mmu-y)
416 # Give 'page_alloc' its own module-parameter namespace
417 page-alloc-y := page_alloc.o
418 diff --git a/mm/filemap.c b/mm/filemap.c
419 index ad8c39d90bf94..f95b595a49b7b 100644
422 @@ -3395,7 +3395,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
423 vm_fault_t ret = VM_FAULT_LOCKED;
425 sb_start_pagefault(mapping->host->i_sb);
426 - file_update_time(vmf->vma->vm_file);
427 + vma_file_update_time(vmf->vma);
429 if (folio->mapping != mapping) {
431 diff --git a/mm/mmap.c b/mm/mmap.c
432 index f61a15474dd6d..071c0cd6ef623 100644
435 @@ -184,7 +184,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
436 if (vma->vm_ops && vma->vm_ops->close)
437 vma->vm_ops->close(vma);
439 - fput(vma->vm_file);
441 mpol_put(vma_policy(vma));
444 @@ -953,7 +953,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
447 uprobe_munmap(next, next->vm_start, next->vm_end);
452 anon_vma_merge(vma, next);
453 @@ -1879,7 +1879,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
457 - fput(vma->vm_file);
461 /* Undo any partial mapping done by a device driver. */
462 @@ -2737,7 +2737,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
466 - get_file(new->vm_file);
469 if (new->vm_ops && new->vm_ops->open)
470 new->vm_ops->open(new);
471 @@ -2756,7 +2756,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
472 if (new->vm_ops && new->vm_ops->close)
473 new->vm_ops->close(new);
475 - fput(new->vm_file);
477 unlink_anon_vmas(new);
479 mpol_put(vma_policy(new));
480 @@ -2950,7 +2950,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
481 struct vm_area_struct *vma;
482 unsigned long populate = 0;
483 unsigned long ret = -EINVAL;
485 + struct file *file, *prfile;
487 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
488 current->comm, current->pid);
489 @@ -3006,10 +3006,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
490 if (vma->vm_flags & VM_LOCKED)
493 - file = get_file(vma->vm_file);
495 + file = vma->vm_file;
496 + prfile = vma->vm_prfile;
497 ret = do_mmap(vma->vm_file, start, size,
498 prot, flags, pgoff, &populate, NULL);
499 + if (!IS_ERR_VALUE(ret) && file && prfile) {
500 + struct vm_area_struct *new_vma;
502 + new_vma = find_vma(mm, ret);
503 + if (!new_vma->vm_prfile)
504 + new_vma->vm_prfile = prfile;
505 + if (new_vma != vma)
509 + * two fput()s instead of vma_fput(vma),
510 + * coz vma may not be available anymore.
516 mmap_write_unlock(mm);
518 @@ -3291,7 +3308,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
519 if (anon_vma_clone(new_vma, vma))
520 goto out_free_mempol;
521 if (new_vma->vm_file)
522 - get_file(new_vma->vm_file);
523 + vma_get_file(new_vma);
524 if (new_vma->vm_ops && new_vma->vm_ops->open)
525 new_vma->vm_ops->open(new_vma);
526 vma_link(mm, new_vma, prev, rb_link, rb_parent);
527 diff --git a/mm/nommu.c b/mm/nommu.c
528 index 55a9e48a7a026..8dc77ce96335a 100644
531 @@ -522,7 +522,7 @@ static void __put_nommu_region(struct vm_region *region)
532 up_write(&nommu_region_sem);
535 - fput(region->vm_file);
538 /* IO memory and memory shared directly out of the pagecache
539 * from ramfs/tmpfs mustn't be released here */
540 @@ -654,7 +654,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
541 if (vma->vm_ops && vma->vm_ops->close)
542 vma->vm_ops->close(vma);
544 - fput(vma->vm_file);
546 put_nommu_region(vma->vm_region);
549 @@ -1174,7 +1174,7 @@ unsigned long do_mmap(struct file *file,
550 goto error_just_free;
553 - fput(region->vm_file);
555 kmem_cache_free(vm_region_jar, region);
558 @@ -1251,10 +1251,10 @@ unsigned long do_mmap(struct file *file,
559 up_write(&nommu_region_sem);
562 - fput(region->vm_file);
564 kmem_cache_free(vm_region_jar, region);
566 - fput(vma->vm_file);
571 diff --git a/mm/prfile.c b/mm/prfile.c
573 index 0000000000000..511543ab1b418
577 +// SPDX-License-Identifier: GPL-2.0
579 + * Mainly for aufs which mmap(2) different file and wants to print different
580 + * path in /proc/PID/maps.
581 + * Call these functions via macros defined in linux/mm.h.
583 + * See Documentation/filesystems/aufs/design/06mmap.txt
585 + * Copyright (c) 2014-2021 Junjro R. Okajima
586 + * Copyright (c) 2014 Ian Campbell
589 +#include <linux/mm.h>
590 +#include <linux/file.h>
591 +#include <linux/fs.h>
593 +/* #define PRFILE_TRACE */
594 +static inline void prfile_trace(struct file *f, struct file *pr,
595 + const char func[], int line, const char func2[])
599 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
603 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
606 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
608 + prfile_trace(f, pr, func, line, __func__);
609 + file_update_time(f);
611 + file_update_time(pr);
614 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
617 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
619 + prfile_trace(f, pr, func, line, __func__);
620 + return (f && pr) ? pr : f;
623 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
625 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
627 + prfile_trace(f, pr, func, line, __func__);
633 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
635 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
637 + prfile_trace(f, pr, func, line, __func__);
644 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
647 + struct file *f = region->vm_file, *pr = region->vm_prfile;
649 + prfile_trace(f, pr, func, line, __func__);
650 + return (f && pr) ? pr : f;
653 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
655 + struct file *f = region->vm_file, *pr = region->vm_prfile;
657 + prfile_trace(f, pr, func, line, __func__);
662 +#endif /* !CONFIG_MMU */
663 SPDX-License-Identifier: GPL-2.0
664 aufs5.x-rcN standalone patch
666 diff --git a/fs/dcache.c b/fs/dcache.c
667 index 6f4f48c828351..7ce9e4401f08a 100644
670 @@ -1450,6 +1450,7 @@ void d_walk(struct dentry *parent, void *data,
674 +EXPORT_SYMBOL_GPL(d_walk);
677 struct vfsmount *mnt;
678 @@ -2995,6 +2996,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
680 write_sequnlock(&rename_lock);
682 +EXPORT_SYMBOL_GPL(d_exchange);
685 * d_ancestor - search for an ancestor
686 diff --git a/fs/exec.c b/fs/exec.c
687 index 79f2c9483302d..d9bc22409be6a 100644
690 @@ -112,6 +112,7 @@ bool path_noexec(const struct path *path)
691 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
692 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
694 +EXPORT_SYMBOL_GPL(path_noexec);
698 diff --git a/fs/fcntl.c b/fs/fcntl.c
699 index 02382fa9bd341..3418c60b90146 100644
702 @@ -86,6 +86,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
706 +EXPORT_SYMBOL_GPL(setfl);
708 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
710 diff --git a/fs/file_table.c b/fs/file_table.c
711 index 7d2e692b66a94..91942789c49aa 100644
712 --- a/fs/file_table.c
713 +++ b/fs/file_table.c
714 @@ -198,6 +198,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
716 return ERR_PTR(-ENFILE);
718 +EXPORT_SYMBOL_GPL(alloc_empty_file);
721 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
722 @@ -412,6 +413,7 @@ void __fput_sync(struct file *file)
726 +EXPORT_SYMBOL_GPL(__fput_sync);
728 void __init files_init(void)
730 diff --git a/fs/namespace.c b/fs/namespace.c
731 index e189393b34b14..5d7d122d1067a 100644
734 @@ -440,6 +440,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
735 mnt_dec_writers(real_mount(mnt));
738 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
741 * mnt_drop_write - give up write access to a mount
742 @@ -844,6 +845,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
744 return check_mnt(real_mount(mnt));
746 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
749 * vfsmount lock must be held for write
750 @@ -2047,6 +2049,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
754 +EXPORT_SYMBOL_GPL(iterate_mounts);
756 static void lock_mnt_tree(struct mount *mnt)
758 diff --git a/fs/notify/group.c b/fs/notify/group.c
759 index b7d4d64f87c29..2d2d2c6d33e41 100644
760 --- a/fs/notify/group.c
761 +++ b/fs/notify/group.c
762 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
764 refcount_inc(&group->refcnt);
766 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
769 * Drop a reference to a group. Free it if it's through.
770 diff --git a/fs/open.c b/fs/open.c
771 index 9ff2f621b760b..3b8deceee506f 100644
774 @@ -66,6 +66,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
775 inode_unlock(dentry->d_inode);
778 +EXPORT_SYMBOL_GPL(do_truncate);
780 long vfs_truncate(const struct path *path, loff_t length)
782 diff --git a/fs/read_write.c b/fs/read_write.c
783 index 0074afa7ecb3e..612cf04d9f6b9 100644
784 --- a/fs/read_write.c
785 +++ b/fs/read_write.c
786 @@ -488,6 +488,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
790 +EXPORT_SYMBOL_GPL(vfs_read);
792 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
794 @@ -598,6 +599,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
795 file_end_write(file);
798 +EXPORT_SYMBOL_GPL(vfs_write);
800 /* file_ppos returns &file->f_pos or NULL if file is stream */
801 static inline loff_t *file_ppos(struct file *file)
802 diff --git a/fs/splice.c b/fs/splice.c
803 index 3e6ba363b7775..7c1be373eb7cd 100644
806 @@ -766,6 +766,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
807 return warn_unsupported(out, "write");
808 return out->f_op->splice_write(pipe, out, ppos, len, flags);
810 +EXPORT_SYMBOL_GPL(do_splice_from);
813 * Attempt to initiate a splice from a file to a pipe.
814 @@ -795,6 +796,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
815 return warn_unsupported(in, "read");
816 return in->f_op->splice_read(in, ppos, pipe, len, flags);
818 +EXPORT_SYMBOL_GPL(do_splice_to);
821 * splice_direct_to_actor - splices data directly between two non-pipes
822 diff --git a/fs/xattr.c b/fs/xattr.c
823 index 5c8c5175b385c..ff7e9ff774b73 100644
826 @@ -384,6 +384,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
827 *xattr_value = value;
830 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
833 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
834 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
835 index 43e3d1fdd570b..5d6f33f1f2f28 100644
836 --- a/kernel/locking/lockdep.c
837 +++ b/kernel/locking/lockdep.c
838 @@ -210,6 +210,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
840 return lock_classes + class_idx;
842 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
843 #define hlock_class(hlock) lockdep_hlock_class(hlock)
845 #ifdef CONFIG_LOCK_STAT
846 diff --git a/kernel/task_work.c b/kernel/task_work.c
847 index 1698fbe6f0e13..081b05acadf82 100644
848 --- a/kernel/task_work.c
849 +++ b/kernel/task_work.c
850 @@ -167,3 +167,4 @@ void task_work_run(void)
854 +EXPORT_SYMBOL_GPL(task_work_run);
855 diff --git a/security/security.c b/security/security.c
856 index 22261d79f3333..732e4c219ea29 100644
857 --- a/security/security.c
858 +++ b/security/security.c
859 @@ -1151,6 +1151,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
861 return call_int_hook(path_rmdir, 0, dir, dentry);
863 +EXPORT_SYMBOL_GPL(security_path_rmdir);
865 int security_path_unlink(const struct path *dir, struct dentry *dentry)
867 @@ -1167,6 +1168,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
869 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
871 +EXPORT_SYMBOL_GPL(security_path_symlink);
873 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
874 struct dentry *new_dentry)
875 @@ -1175,6 +1177,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
877 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
879 +EXPORT_SYMBOL_GPL(security_path_link);
881 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
882 const struct path *new_dir, struct dentry *new_dentry,
883 @@ -1202,6 +1205,7 @@ int security_path_truncate(const struct path *path)
885 return call_int_hook(path_truncate, 0, path);
887 +EXPORT_SYMBOL_GPL(security_path_truncate);
889 int security_path_chmod(const struct path *path, umode_t mode)
891 @@ -1209,6 +1213,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
893 return call_int_hook(path_chmod, 0, path, mode);
895 +EXPORT_SYMBOL_GPL(security_path_chmod);
897 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
899 @@ -1216,6 +1221,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
901 return call_int_hook(path_chown, 0, path, uid, gid);
903 +EXPORT_SYMBOL_GPL(security_path_chown);
905 int security_path_chroot(const struct path *path)
907 @@ -1316,6 +1322,7 @@ int security_inode_permission(struct inode *inode, int mask)
909 return call_int_hook(inode_permission, 0, inode, mask);
911 +EXPORT_SYMBOL_GPL(security_inode_permission);
913 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
915 @@ -1513,6 +1520,7 @@ int security_file_permission(struct file *file, int mask)
917 return fsnotify_perm(file, mask);
919 +EXPORT_SYMBOL_GPL(security_file_permission);
921 int security_file_alloc(struct file *file)
923 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
924 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
925 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-03-21 14:49:05.713299677 +0100
927 +What: /debug/aufs/si_<id>/
929 +Contact: J. R. Okajima <hooanon05g@gmail.com>
931 + Under /debug/aufs, a directory named si_<id> is created
932 + per aufs mount, where <id> is a unique id generated
935 +What: /debug/aufs/si_<id>/plink
937 +Contact: J. R. Okajima <hooanon05g@gmail.com>
939 + It has three lines and shows the information about the
940 + pseudo-link. The first line is a single number
941 + representing a number of buckets. The second line is a
942 + number of pseudo-links per buckets (separated by a
943 + blank). The last line is a single number representing a
944 + total number of psedo-links.
945 + When the aufs mount option 'noplink' is specified, it
946 + will show "1\n0\n0\n".
948 +What: /debug/aufs/si_<id>/xib
950 +Contact: J. R. Okajima <hooanon05g@gmail.com>
952 + It shows the consumed blocks by xib (External Inode Number
953 + Bitmap), its block size and file size.
954 + When the aufs mount option 'noxino' is specified, it
955 + will be empty. About XINO files, see the aufs manual.
957 +What: /debug/aufs/si_<id>/xi<branch-index>
959 +Contact: J. R. Okajima <hooanon05g@gmail.com>
961 + It shows the consumed blocks by xino (External Inode Number
962 + Translation Table), its link count, block size and file
964 + Due to the file size limit, there may exist multiple
965 + xino files per branch. In this case, "-N" is added to
966 + the filename and it corresponds to the index of the
967 + internal xino array. "-0" is omitted.
968 + When the aufs mount option 'noxino' is specified, Those
969 + entries won't exist. About XINO files, see the aufs
972 +What: /debug/aufs/si_<id>/xigen
974 +Contact: J. R. Okajima <hooanon05g@gmail.com>
976 + It shows the consumed blocks by xigen (External Inode
977 + Generation Table), its block size and file size.
978 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
980 + When the aufs mount option 'noxino' is specified, it
981 + will be empty. About XINO files, see the aufs manual.
982 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
983 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
984 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-03-21 14:49:05.713299677 +0100
986 +What: /sys/fs/aufs/si_<id>/
988 +Contact: J. R. Okajima <hooanon05g@gmail.com>
990 + Under /sys/fs/aufs, a directory named si_<id> is created
991 + per aufs mount, where <id> is a unique id generated
994 +What: /sys/fs/aufs/si_<id>/br<idx>
996 +Contact: J. R. Okajima <hooanon05g@gmail.com>
998 + It shows the abolute path of a member directory (which
999 + is called branch) in aufs, and its permission.
1001 +What: /sys/fs/aufs/si_<id>/brid<idx>
1003 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1005 + It shows the id of a member directory (which is called
1008 +What: /sys/fs/aufs/si_<id>/xi_path
1010 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1012 + It shows the abolute path of XINO (External Inode Number
1013 + Bitmap, Translation Table and Generation Table) file
1014 + even if it is the default path.
1015 + When the aufs mount option 'noxino' is specified, it
1016 + will be empty. About XINO files, see the aufs manual.
1017 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1018 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1019 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-03-21 14:49:05.713299677 +0100
1022 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1024 +# This program is free software; you can redistribute it and/or modify
1025 +# it under the terms of the GNU General Public License as published by
1026 +# the Free Software Foundation; either version 2 of the License, or
1027 +# (at your option) any later version.
1029 +# This program is distributed in the hope that it will be useful,
1030 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1031 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1032 +# GNU General Public License for more details.
1034 +# You should have received a copy of the GNU General Public License
1035 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1038 +----------------------------------------
1040 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1041 +1. abbrev. for "advanced multi-layered unification filesystem".
1042 +2. abbrev. for "another unionfs".
1043 +3. abbrev. for "auf das" in German which means "on the" in English.
1044 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1045 + But "Filesystem aufs Filesystem" is hard to understand.
1046 +4. abbrev. for "African Urban Fashion Show".
1048 +AUFS is a filesystem with features:
1049 +- multi layered stackable unification filesystem, the member directory
1050 + is called as a branch.
1051 +- branch permission and attribute, 'readonly', 'real-readonly',
1052 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1054 +- internal "file copy-on-write".
1055 +- logical deletion, whiteout.
1056 +- dynamic branch manipulation, adding, deleting and changing permission.
1057 +- allow bypassing aufs, user's direct branch access.
1058 +- external inode number translation table and bitmap which maintains the
1059 + persistent aufs inode number.
1060 +- seekable directory, including NFS readdir.
1061 +- file mapping, mmap and sharing pages.
1062 +- pseudo-link, hardlink over branches.
1063 +- loopback mounted filesystem as a branch.
1064 +- several policies to select one among multiple writable branches.
1065 +- revert a single systemcall when an error occurs in aufs.
1069 +Multi Layered Stackable Unification Filesystem
1070 +----------------------------------------------------------------------
1071 +Most people already knows what it is.
1072 +It is a filesystem which unifies several directories and provides a
1073 +merged single directory. When users access a file, the access will be
1074 +passed/re-directed/converted (sorry, I am not sure which English word is
1075 +correct) to the real file on the member filesystem. The member
1076 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1077 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1078 +readonly branch is handled by creating 'whiteout' on the upper writable
1081 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1082 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1083 +different approaches to implement the merged-view.
1084 +The former tries putting it into VFS, and the latter implements as a
1085 +separate filesystem.
1086 +(If I misunderstand about these implementations, please let me know and
1087 +I shall correct it. Because it is a long time ago when I read their
1088 +source files last time).
1090 +UnionMount's approach will be able to small, but may be hard to share
1091 +branches between several UnionMount since the whiteout in it is
1092 +implemented in the inode on branch filesystem and always
1093 +shared. According to Bharata's post, readdir does not seems to be
1095 +There are several missing features known in this implementations such as
1096 +- for users, the inode number may change silently. eg. copy-up.
1097 +- link(2) may break by copy-up.
1098 +- read(2) may get an obsoleted filedata (fstat(2) too).
1099 +- fcntl(F_SETLK) may be broken by copy-up.
1100 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1103 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1104 +merged into mainline. This is another implementation of UnionMount as a
1105 +separated filesystem. All the limitations and known problems which
1106 +UnionMount are equally inherited to "overlay" filesystem.
1108 +Unionfs has a longer history. When I started implementing a stackable
1109 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1110 +inode, dentry and file objects and they have an array pointing lower
1111 +same kind objects. After contributing many patches for Unionfs, I
1112 +re-started my project AUFS (Jun 2006).
1114 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1115 +implemented my own ideas, approaches and enhancements and it became
1116 +totally different one.
1118 +Comparing DM snapshot and fs based implementation
1119 +- the number of bytes to be copied between devices is much smaller.
1120 +- the type of filesystem must be one and only.
1121 +- the fs must be writable, no readonly fs, even for the lower original
1122 + device. so the compression fs will not be usable. but if we use
1123 + loopback mount, we may address this issue.
1125 + mount /cdrom/squashfs.img /sq
1126 + losetup /sq/ext2.img
1127 + losetup /somewhere/cow
1128 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1129 +- it will be difficult (or needs more operations) to extract the
1130 + difference between the original device and COW.
1131 +- DM snapshot-merge may help a lot when users try merging. in the
1132 + fs-layer union, users will use rsync(1).
1134 +You may want to read my old paper "Filesystems in LiveCD"
1135 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1138 +Several characters/aspects/persona of aufs
1139 +----------------------------------------------------------------------
1141 +Aufs has several characters, aspects or persona.
1142 +1. a filesystem, callee of VFS helper
1143 +2. sub-VFS, caller of VFS helper for branches
1144 +3. a virtual filesystem which maintains persistent inode number
1145 +4. reader/writer of files on branches such like an application
1147 +1. Callee of VFS Helper
1148 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1149 +unlink(2) from an application reaches sys_unlink() kernel function and
1150 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1151 +calls filesystem specific unlink operation. Actually aufs implements the
1152 +unlink operation but it behaves like a redirector.
1154 +2. Caller of VFS Helper for Branches
1155 +aufs_unlink() passes the unlink request to the branch filesystem as if
1156 +it were called from VFS. So the called unlink operation of the branch
1157 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1158 +every necessary pre/post operation for the branch filesystem.
1159 +- acquire the lock for the parent dir on a branch
1160 +- lookup in a branch
1161 +- revalidate dentry on a branch
1162 +- mnt_want_write() for a branch
1163 +- vfs_unlink() for a branch
1164 +- mnt_drop_write() for a branch
1165 +- release the lock on a branch
1167 +3. Persistent Inode Number
1168 +One of the most important issue for a filesystem is to maintain inode
1169 +numbers. This is particularly important to support exporting a
1170 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1171 +backend block device for its own. But some storage is necessary to
1172 +keep and maintain the inode numbers. It may be a large space and may not
1173 +suit to keep in memory. Aufs rents some space from its first writable
1174 +branch filesystem (by default) and creates file(s) on it. These files
1175 +are created by aufs internally and removed soon (currently) keeping
1177 +Note: Because these files are removed, they are totally gone after
1178 + unmounting aufs. It means the inode numbers are not persistent
1179 + across unmount or reboot. I have a plan to make them really
1180 + persistent which will be important for aufs on NFS server.
1182 +4. Read/Write Files Internally (copy-on-write)
1183 +Because a branch can be readonly, when you write a file on it, aufs will
1184 +"copy-up" it to the upper writable branch internally. And then write the
1185 +originally requested thing to the file. Generally kernel doesn't
1186 +open/read/write file actively. In aufs, even a single write may cause a
1187 +internal "file copy". This behaviour is very similar to cp(1) command.
1189 +Some people may think it is better to pass such work to user space
1190 +helper, instead of doing in kernel space. Actually I am still thinking
1191 +about it. But currently I have implemented it in kernel space.
1192 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1193 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1194 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-03-21 14:49:05.713299677 +0100
1197 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1199 +# This program is free software; you can redistribute it and/or modify
1200 +# it under the terms of the GNU General Public License as published by
1201 +# the Free Software Foundation; either version 2 of the License, or
1202 +# (at your option) any later version.
1204 +# This program is distributed in the hope that it will be useful,
1205 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1206 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1207 +# GNU General Public License for more details.
1209 +# You should have received a copy of the GNU General Public License
1210 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1212 +Basic Aufs Internal Structure
1214 +Superblock/Inode/Dentry/File Objects
1215 +----------------------------------------------------------------------
1216 +As like an ordinary filesystem, aufs has its own
1217 +superblock/inode/dentry/file objects. All these objects have a
1218 +dynamically allocated array and store the same kind of pointers to the
1219 +lower filesystem, branch.
1220 +For example, when you build a union with one readwrite branch and one
1221 +readonly, mounted /au, /rw and /ro respectively.
1223 +- /ro/fileA exists but /rw/fileA
1225 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1226 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1227 +- [0] = NULL (because /rw/fileA doesn't exist)
1230 +This style of an array is essentially same to the aufs
1231 +superblock/inode/dentry/file objects.
1233 +Because aufs supports manipulating branches, ie. add/delete/change
1234 +branches dynamically, these objects has its own generation. When
1235 +branches are changed, the generation in aufs superblock is
1236 +incremented. And a generation in other object are compared when it is
1237 +accessed. When a generation in other objects are obsoleted, aufs
1238 +refreshes the internal array.
1242 +----------------------------------------------------------------------
1243 +Additionally aufs superblock has some data for policies to select one
1244 +among multiple writable branches, XIB files, pseudo-links and kobject.
1245 +See below in detail.
1246 +About the policies which supports copy-down a directory, see
1247 +wbr_policy.txt too.
1250 +Branch and XINO(External Inode Number Translation Table)
1251 +----------------------------------------------------------------------
1252 +Every branch has its own xino (external inode number translation table)
1253 +file. The xino file is created and unlinked by aufs internally. When two
1254 +members of a union exist on the same filesystem, they share the single
1256 +The struct of a xino file is simple, just a sequence of aufs inode
1257 +numbers which is indexed by the lower inode number.
1258 +In the above sample, assume the inode number of /ro/fileA is i111 and
1259 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1260 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1262 +When the inode numbers are not contiguous, the xino file will be sparse
1263 +which has a hole in it and doesn't consume as much disk space as it
1264 +might appear. If your branch filesystem consumes disk space for such
1265 +holes, then you should specify 'xino=' option at mounting aufs.
1267 +Aufs has a mount option to free the disk blocks for such holes in XINO
1268 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1269 +meet a problem of disk shortage due to XINO files, then you should try
1270 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1271 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1272 +the holes in XINO files.
1274 +Also a writable branch has three kinds of "whiteout bases". All these
1275 +are existed when the branch is joined to aufs, and their names are
1276 +whiteout-ed doubly, so that users will never see their names in aufs
1278 +1. a regular file which will be hardlinked to all whiteouts.
1279 +2. a directory to store a pseudo-link.
1280 +3. a directory to store an "orphan"-ed file temporary.
1283 + When you remove a file on a readonly branch, aufs handles it as a
1284 + logical deletion and creates a whiteout on the upper writable branch
1285 + as a hardlink of this file in order not to consume inode on the
1288 + See below, Pseudo-link.
1290 + When "fileC" exists on the lower readonly branch only and it is
1291 + opened and removed with its parent dir, and then user writes
1292 + something into it, then aufs copies-up fileC to this
1293 + directory. Because there is no other dir to store fileC. After
1294 + creating a file under this dir, the file is unlinked.
1296 +Because aufs supports manipulating branches, ie. add/delete/change
1297 +dynamically, a branch has its own id. When the branch order changes,
1298 +aufs finds the new index by searching the branch id.
1302 +----------------------------------------------------------------------
1303 +Assume "fileA" exists on the lower readonly branch only and it is
1304 +hardlinked to "fileB" on the branch. When you write something to fileA,
1305 +aufs copies-up it to the upper writable branch. Additionally aufs
1306 +creates a hardlink under the Pseudo-link Directory of the writable
1307 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1308 +simple list. If fileB is read after unlinking fileA, aufs returns
1309 +filedata from the pseudo-link instead of the lower readonly
1310 +branch. Because the pseudo-link is based upon the inode, to keep the
1311 +inode number by xino (see above) is essentially necessary.
1313 +All the hardlinks under the Pseudo-link Directory of the writable branch
1314 +should be restored in a proper location later. Aufs provides a utility
1315 +to do this. The userspace helpers executed at remounting and unmounting
1317 +During this utility is running, it puts aufs into the pseudo-link
1318 +maintenance mode. In this mode, only the process which began the
1319 +maintenance mode (and its child processes) is allowed to operate in
1320 +aufs. Some other processes which are not related to the pseudo-link will
1321 +be allowed to run too, but the rest have to return an error or wait
1322 +until the maintenance mode ends. If a process already acquires an inode
1323 +mutex (in VFS), it has to return an error.
1326 +XIB(external inode number bitmap)
1327 +----------------------------------------------------------------------
1328 +Addition to the xino file per a branch, aufs has an external inode number
1329 +bitmap in a superblock object. It is also an internal file such like a
1331 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1333 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1335 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1336 +reduce the number of consumed disk blocks for these files.
1339 +Virtual or Vertical Dir, and Readdir in Userspace
1340 +----------------------------------------------------------------------
1341 +In order to support multiple layers (branches), aufs readdir operation
1342 +constructs a virtual dir block on memory. For readdir, aufs calls
1343 +vfs_readdir() internally for each dir on branches, merges their entries
1344 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1345 +object. So the file object has its entry list until it is closed. The
1346 +entry list will be updated when the file position is zero and becomes
1347 +obsoleted. This decision is made in aufs automatically.
1349 +The dynamically allocated memory block for the name of entries has a
1350 +unit of 512 bytes (by default) and stores the names contiguously (no
1351 +padding). Another block for each entry is handled by kmem_cache too.
1352 +During building dir blocks, aufs creates hash list and judging whether
1353 +the entry is whiteouted by its upper branch or already listed.
1354 +The merged result is cached in the corresponding inode object and
1355 +maintained by a customizable life-time option.
1357 +Some people may call it can be a security hole or invite DoS attack
1358 +since the opened and once readdir-ed dir (file object) holds its entry
1359 +list and becomes a pressure for system memory. But I'd say it is similar
1360 +to files under /proc or /sys. The virtual files in them also holds a
1361 +memory page (generally) while they are opened. When an idea to reduce
1362 +memory for them is introduced, it will be applied to aufs too.
1363 +For those who really hate this situation, I've developed readdir(3)
1364 +library which operates this merging in userspace. You just need to set
1365 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1366 +kernel space for readdir(3).
1370 +----------------------------------------------------------------------
1371 +Aufs sometimes requires privilege access to a branch. For instance,
1372 +in copy-up/down operation. When a user process is going to make changes
1373 +to a file which exists in the lower readonly branch only, and the mode
1374 +of one of ancestor directories may not be writable by a user
1375 +process. Here aufs copy-up the file with its ancestors and they may
1376 +require privilege to set its owner/group/mode/etc.
1377 +This is a typical case of a application character of aufs (see
1380 +Aufs uses workqueue synchronously for this case. It creates its own
1381 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1382 +passes the request to call mkdir or write (for example), and wait for
1383 +its completion. This approach solves a problem of a signal handler
1385 +If aufs didn't adopt the workqueue and changed the privilege of the
1386 +process, then the process may receive the unexpected SIGXFSZ or other
1389 +Also aufs uses the system global workqueue ("events" kernel thread) too
1390 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1391 +whiteout base and etc. This is unrelated to a privilege.
1392 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1393 +superblock at the beginning, at the same time waits for the completion
1394 +of all queued asynchronous tasks.
1398 +----------------------------------------------------------------------
1399 +The whiteout in aufs is very similar to Unionfs's. That is represented
1400 +by its filename. UnionMount takes an approach of a file mode, but I am
1401 +afraid several utilities (find(1) or something) will have to support it.
1403 +Basically the whiteout represents "logical deletion" which stops aufs to
1404 +lookup further, but also it represents "dir is opaque" which also stop
1407 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1408 +In order to make several functions in a single systemcall to be
1409 +revertible, aufs adopts an approach to rename a directory to a temporary
1410 +unique whiteouted name.
1411 +For example, in rename(2) dir where the target dir already existed, aufs
1412 +renames the target dir to a temporary unique whiteouted name before the
1413 +actual rename on a branch, and then handles other actions (make it opaque,
1414 +update the attributes, etc). If an error happens in these actions, aufs
1415 +simply renames the whiteouted name back and returns an error. If all are
1416 +succeeded, aufs registers a function to remove the whiteouted unique
1417 +temporary name completely and asynchronously to the system global
1422 +----------------------------------------------------------------------
1423 +It is a well-known feature or concept.
1424 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1425 +internally and makes change to the new file on the upper writable branch.
1426 +When the trigger systemcall does not update the timestamps of the parent
1427 +dir, aufs reverts it after copy-up.
1430 +Move-down (aufs3.9 and later)
1431 +----------------------------------------------------------------------
1432 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1433 +the lower readonly branch to the upper writable branch when a user
1434 +changes something about the file.
1435 +"Move-down" is an opposite action of copy-up. Basically this action is
1436 +ran manually instead of automatically and internally.
1437 +For desgin and implementation, aufs has to consider these issues.
1438 +- whiteout for the file may exist on the lower branch.
1439 +- ancestor directories may not exist on the lower branch.
1440 +- diropq for the ancestor directories may exist on the upper branch.
1441 +- free space on the lower branch will reduce.
1442 +- another access to the file may happen during moving-down, including
1443 + UDBA (see "Revalidate Dentry and UDBA").
1444 +- the file should not be hard-linked nor pseudo-linked. they should be
1445 + handled by auplink utility later.
1447 +Sometimes users want to move-down a file from the upper writable branch
1448 +to the lower readonly or writable branch. For instance,
1449 +- the free space of the upper writable branch is going to run out.
1450 +- create a new intermediate branch between the upper and lower branch.
1453 +For this purpose, use "aumvdown" command in aufs-util.git.
1454 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1455 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1456 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-03-21 14:49:05.713299677 +0100
1459 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1461 +# This program is free software; you can redistribute it and/or modify
1462 +# it under the terms of the GNU General Public License as published by
1463 +# the Free Software Foundation; either version 2 of the License, or
1464 +# (at your option) any later version.
1466 +# This program is distributed in the hope that it will be useful,
1467 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1468 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1469 +# GNU General Public License for more details.
1471 +# You should have received a copy of the GNU General Public License
1472 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1474 +Support for a branch who has its ->atomic_open()
1475 +----------------------------------------------------------------------
1476 +The filesystems who implement its ->atomic_open() are not majority. For
1477 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1478 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1479 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1480 +sure whether all filesystems who have ->atomic_open() behave like this,
1481 +but NFSv4 surely returns the error.
1483 +In order to support ->atomic_open() for aufs, there are a few
1486 +A. Introduce aufs_atomic_open()
1487 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1489 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1490 + an aufs user Pip Cet's approach
1491 + - calls aufs_create(), VFS finish_open() and notify_change().
1492 + - pass fake-mode to finish_open(), and then correct the mode by
1494 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1495 + - no aufs_atomic_open().
1496 + - aufs_lookup() registers the TID to an aufs internal object.
1497 + - aufs_create() does nothing when the matching TID is registered, but
1498 + registers the mode.
1499 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1500 + TID is registered.
1501 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1503 + - no aufs_atomic_open().
1504 + - aufs_create() registers the TID to an internal object. this info
1505 + represents "this process created this file just now."
1506 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1507 + registered TID and re-try open() with superuser's credential.
1509 +Pros and cons for each approach.
1512 + - straightforward but highly depends upon VFS internal.
1513 + - the atomic behavaiour is kept.
1514 + - some of parameters such as nameidata are hard to reproduce for
1518 + - easy to implement.
1519 + - the atomic behavaiour is lost.
1521 + - the atomic behavaiour is kept.
1522 + - dirty and tricky.
1523 + - VFS checks whether the file is created correctly after calling
1524 + ->create(), which means this approach doesn't work.
1526 + - easy to implement.
1527 + - the atomic behavaiour is lost.
1528 + - to open a file with superuser's credential and give it to a user
1529 + process is a bad idea, since the file object keeps the credential
1530 + in it. It may affect LSM or something. This approach doesn't work
1533 +The approach A is ideal, but it hard to implement. So here is a
1534 +variation of A, which is to be implemented.
1536 +A-1. Introduce aufs_atomic_open()
1537 + - calls branch fs ->atomic_open() if exists. otherwise calls
1538 + vfs_create() and finish_open().
1539 + - the demerit is that the several checks after branch fs
1540 + ->atomic_open() are lost. in the ordinary case, the checks are
1541 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1542 + be implemented in aufs, but not all I am afraid.
1543 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1544 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1545 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-03-21 14:49:05.713299677 +0100
1548 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1550 +# This program is free software; you can redistribute it and/or modify
1551 +# it under the terms of the GNU General Public License as published by
1552 +# the Free Software Foundation; either version 2 of the License, or
1553 +# (at your option) any later version.
1555 +# This program is distributed in the hope that it will be useful,
1556 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1557 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1558 +# GNU General Public License for more details.
1560 +# You should have received a copy of the GNU General Public License
1561 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1564 +----------------------------------------------------------------------
1565 +Since aufs has a character of sub-VFS (see Introduction), it operates
1566 +lookup for branches as VFS does. It may be a heavy work. But almost all
1567 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1568 +directly connected to its parent. Digging down the directory hierarchy
1569 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1572 +When a branch is a remote filesystem, aufs basically relies upon its
1573 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1575 +For d_revalidate, aufs implements three levels of revalidate tests. See
1576 +"Revalidate Dentry and UDBA" in detail.
1579 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1580 +----------------------------------------------------------------------
1581 +Let's try case study.
1582 +- aufs has two branches, upper readwrite and lower readonly.
1584 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1585 +- user invoked "chmod a+rx /au/dirA"
1586 +- the internal copy-up is activated and "/rw/dirA" is created and its
1587 + permission bits are set to world readable.
1588 +- then "/au/dirA" becomes world readable?
1590 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1591 +or it may be a natively readonly filesystem. If aufs respects the lower
1592 +branch, it should not respond readdir request from other users. But user
1593 +allowed it by chmod. Should really aufs rejects showing the entries
1596 +To be honest, I don't have a good solution for this case. So aufs
1597 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1599 +When dirperm1 is specified, aufs checks only the highest one for the
1600 +directory permission, and shows the entries. Otherwise, as usual, checks
1601 +every dir existing on all branches and rejects the request.
1603 +As a side effect, dirperm1 option improves the performance of aufs
1604 +because the number of permission check is reduced when the number of
1608 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1609 +----------------------------------------------------------------------
1610 +Generally VFS helpers re-validate a dentry as a part of lookup.
1611 +0. digging down the directory hierarchy.
1612 +1. lock the parent dir by its i_mutex.
1613 +2. lookup the final (child) entry.
1615 +4. call the actual operation (create, unlink, etc.)
1616 +5. unlock the parent dir
1618 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1619 +called. Actually aufs implements it and checks the dentry on a branch is
1621 +But it is not enough. Because aufs has to release the lock for the
1622 +parent dir on a branch at the end of ->lookup() (step 2) and
1623 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1625 +If the file on a branch is changed directly, eg. bypassing aufs, after
1626 +aufs released the lock, then the subsequent operation may cause
1627 +something unpleasant result.
1629 +This situation is a result of VFS architecture, ->lookup() and
1630 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1631 +design from VFS's point of view. It is just not suitable for sub-VFS
1634 +Aufs supports such case by three level of revalidation which is
1635 +selectable by user.
1636 +1. Simple Revalidate
1637 + Addition to the native flow in VFS's, confirm the child-parent
1638 + relationship on the branch just after locking the parent dir on the
1639 + branch in the "actual operation" (step 4). When this validation
1640 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1641 + checks the validation of the dentry on branches.
1642 +2. Monitor Changes Internally by Inotify/Fsnotify
1643 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1644 + the dentry on the branch, and returns EBUSY if it finds different
1646 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1647 + during it is in cache. When the event is notified, aufs registers a
1648 + function to kernel 'events' thread by schedule_work(). And the
1649 + function sets some special status to the cached aufs dentry and inode
1650 + private data. If they are not cached, then aufs has nothing to
1651 + do. When the same file is accessed through aufs (step 0-3) later,
1652 + aufs will detect the status and refresh all necessary data.
1653 + In this mode, aufs has to ignore the event which is fired by aufs
1655 +3. No Extra Validation
1656 + This is the simplest test and doesn't add any additional revalidation
1657 + test, and skip the revalidation in step 4. It is useful and improves
1658 + aufs performance when system surely hide the aufs branches from user,
1659 + by over-mounting something (or another method).
1660 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1661 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1662 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-03-21 14:49:05.713299677 +0100
1665 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1667 +# This program is free software; you can redistribute it and/or modify
1668 +# it under the terms of the GNU General Public License as published by
1669 +# the Free Software Foundation; either version 2 of the License, or
1670 +# (at your option) any later version.
1672 +# This program is distributed in the hope that it will be useful,
1673 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1674 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1675 +# GNU General Public License for more details.
1677 +# You should have received a copy of the GNU General Public License
1678 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1680 +Branch Manipulation
1682 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1683 +and changing its permission/attribute, there are a lot of works to do.
1687 +----------------------------------------------------------------------
1688 +o Confirm the adding dir exists outside of aufs, including loopback
1689 + mount, and its various attributes.
1690 +o Initialize the xino file and whiteout bases if necessary.
1693 +o Check the owner/group/mode of the directory
1694 + When the owner/group/mode of the adding directory differs from the
1695 + existing branch, aufs issues a warning because it may impose a
1697 + For example, when a upper writable branch has a world writable empty
1698 + top directory, a malicious user can create any files on the writable
1699 + branch directly, like copy-up and modify manually. If something like
1700 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1701 + writable branch, and the writable branch is world-writable, then a
1702 + malicious guy may create /etc/passwd on the writable branch directly
1703 + and the infected file will be valid in aufs.
1704 + I am afraid it can be a security issue, but aufs can do nothing except
1705 + producing a warning.
1709 +----------------------------------------------------------------------
1710 +o Confirm the deleting branch is not busy
1711 + To be general, there is one merit to adopt "remount" interface to
1712 + manipulate branches. It is to discard caches. At deleting a branch,
1713 + aufs checks the still cached (and connected) dentries and inodes. If
1714 + there are any, then they are all in-use. An inode without its
1715 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1717 + For the cached one, aufs checks whether the same named entry exists on
1719 + If the cached one is a directory, because aufs provides a merged view
1720 + to users, as long as one dir is left on any branch aufs can show the
1721 + dir to users. In this case, the branch can be removed from aufs.
1722 + Otherwise aufs rejects deleting the branch.
1724 + If any file on the deleting branch is opened by aufs, then aufs
1728 +Modify the Permission of a Branch
1729 +----------------------------------------------------------------------
1730 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1733 +o rw --> ro: Confirm the modifying branch is not busy
1734 + Aufs rejects the request if any of these conditions are true.
1735 + - a file on the branch is mmap-ed.
1736 + - a regular file on the branch is opened for write and there is no
1737 + same named entry on the upper branch.
1738 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1739 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1740 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-03-21 14:49:05.713299677 +0100
1743 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1745 +# This program is free software; you can redistribute it and/or modify
1746 +# it under the terms of the GNU General Public License as published by
1747 +# the Free Software Foundation; either version 2 of the License, or
1748 +# (at your option) any later version.
1750 +# This program is distributed in the hope that it will be useful,
1751 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1752 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1753 +# GNU General Public License for more details.
1755 +# You should have received a copy of the GNU General Public License
1756 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1758 +Policies to Select One among Multiple Writable Branches
1759 +----------------------------------------------------------------------
1760 +When the number of writable branch is more than one, aufs has to decide
1761 +the target branch for file creation or copy-up. By default, the highest
1762 +writable branch which has the parent (or ancestor) dir of the target
1763 +file is chosen (top-down-parent policy).
1764 +By user's request, aufs implements some other policies to select the
1765 +writable branch, for file creation several policies, round-robin,
1766 +most-free-space, and other policies. For copy-up, top-down-parent,
1767 +bottom-up-parent, bottom-up and others.
1769 +As expected, the round-robin policy selects the branch in circular. When
1770 +you have two writable branches and creates 10 new files, 5 files will be
1771 +created for each branch. mkdir(2) systemcall is an exception. When you
1772 +create 10 new directories, all will be created on the same branch.
1773 +And the most-free-space policy selects the one which has most free
1774 +space among the writable branches. The amount of free space will be
1775 +checked by aufs internally, and users can specify its time interval.
1777 +The policies for copy-up is more simple,
1778 +top-down-parent is equivalent to the same named on in create policy,
1779 +bottom-up-parent selects the writable branch where the parent dir
1780 +exists and the nearest upper one from the copyup-source,
1781 +bottom-up selects the nearest upper writable branch from the
1782 +copyup-source, regardless the existence of the parent dir.
1784 +There are some rules or exceptions to apply these policies.
1785 +- If there is a readonly branch above the policy-selected branch and
1786 + the parent dir is marked as opaque (a variation of whiteout), or the
1787 + target (creating) file is whiteout-ed on the upper readonly branch,
1788 + then the result of the policy is ignored and the target file will be
1789 + created on the nearest upper writable branch than the readonly branch.
1790 +- If there is a writable branch above the policy-selected branch and
1791 + the parent dir is marked as opaque or the target file is whiteouted
1792 + on the branch, then the result of the policy is ignored and the target
1793 + file will be created on the highest one among the upper writable
1794 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1796 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1797 + They try selecting the branch where the source exists as possible
1798 + since copyup a large file will take long time. If it can't be,
1799 + ie. the branch where the source exists is readonly, then they will
1800 + follow the copyup policy.
1801 +- There is an exception for rename(2) when the target exists.
1802 + If the rename target exists, aufs compares the index of the branches
1803 + where the source and the target exists and selects the higher
1804 + one. If the selected branch is readonly, then aufs follows the
1806 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1807 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1808 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-03-21 14:49:05.713299677 +0100
1811 +// to view this graph, run dot(1) command in GRAPHVIZ.
1815 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1819 +aufs_rename -> whinfo [label="store/remove"];
1822 +inode_list [label="h_inum list in branch\ncache"];
1825 +whinode [label="h_inum list file"];
1828 +brmgmt [label="br_add/del/mod/umount"];
1830 +brmgmt -> inode_list [label="create/remove"];
1831 +brmgmt -> whinode [label="load/store"];
1833 +inode_list -> whinode [style=dashed,dir=both];
1835 +aufs_rename -> inode_list [label="add/del"];
1837 +aufs_lookup -> inode_list [label="search"];
1839 +aufs_lookup -> whinfo [label="load/remove"];
1841 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1842 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1843 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-03-21 14:49:05.713299677 +0100
1846 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1848 +# This program is free software; you can redistribute it and/or modify
1849 +# it under the terms of the GNU General Public License as published by
1850 +# the Free Software Foundation; either version 2 of the License, or
1851 +# (at your option) any later version.
1853 +# This program is distributed in the hope that it will be useful,
1854 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1855 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1856 +# GNU General Public License for more details.
1858 +# You should have received a copy of the GNU General Public License
1859 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1861 +Special handling for renaming a directory (DIRREN)
1862 +----------------------------------------------------------------------
1863 +First, let's assume we have a simple usecase.
1867 +- /ro/dirA and /ro/dirA/file exist too
1868 +- there is no dirB on both branches
1869 +- a user issues rename("dirA", "dirB")
1871 +Now, what should aufs behave against this rename(2)?
1872 +There are a few possible cases.
1875 + since dirA exists on a readonly branch which cannot be renamed.
1877 + it is possible to copy-up dirA (only the dir itself), but the child
1878 + entries ("file" in this case) should not be. it must be a bad
1879 + approach to copy-up recursively.
1880 +C. returns a success.
1881 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1882 + is a violation of aufs' policy.
1883 +D. construct an extra information which indicates that /ro/dirA should
1884 + be handled as the name of dirB.
1885 + overlayfs has a similar feature called REDIRECT.
1887 +Until now, aufs implements the case B only which returns EXDEV, and
1888 +expects the userspace application behaves like mv(1) which tries
1889 +issueing rename(2) recursively.
1891 +A new aufs feature called DIRREN is introduced which implements the case
1892 +D. There are several "extra information" added.
1894 +1. detailed info per renamed directory
1895 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1896 +2. the inode-number list of directories on a branch
1897 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1899 +The filename of "detailed info per directory" represents the lower
1900 +branch, and its format is
1901 +- a type of the branch id
1903 + + uuid (not implemented yet)
1906 +- the inode-number of the branch root dir
1908 +And it contains these info in a single regular file.
1910 +- branch's inode-number of the logically renamed dir
1911 +- the name of the before-renamed dir
1913 +The "detailed info per directory" file is created in aufs rename(2), and
1914 +loaded in any lookup.
1915 +The info is considered in lookup for the matching case only. Here
1916 +"matching" means that the root of branch (in the info filename) is same
1917 +to the current looking-up branch. After looking-up the before-renamed
1918 +name, the inode-number is compared. And the matched dentry is used.
1920 +The "inode-number list of directories" is a regular file which contains
1921 +simply the inode-numbers on the branch. The file is created or updated
1922 +in removing the branch, and loaded in adding the branch. Its lifetime is
1923 +equal to the branch.
1924 +The list is refered in lookup, and when the current target inode is
1925 +found in the list, the aufs tries loading the "detailed info per
1926 +directory" and get the changed and valid name of the dir.
1928 +Theoretically these "extra informaiton" may be able to be put into XATTR
1929 +in the dir inode. But aufs doesn't choose this way because
1930 +1. XATTR may not be supported by the branch (or its configuration)
1931 +2. XATTR may have its size limit.
1932 +3. XATTR may be less easy to convert than a regular file, when the
1933 + format of the info is changed in the future.
1934 +At the same time, I agree that the regular file approach is much slower
1935 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1938 +This DIRREN feature is enabled by aufs configuration, and is activated
1939 +by a new mount option.
1941 +For the more complicated case, there is a work with UDBA option, which
1942 +is to dected the direct access to the branches (by-passing aufs) and to
1943 +maintain the cashes in aufs. Since a single cached aufs dentry may
1944 +contains two names, before- and after-rename, the name comparision in
1945 +UDBA handler may not work correctly. In this case, the behaviour will be
1946 +equivalen to udba=reval case.
1947 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1948 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1949 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-03-21 14:49:05.716633010 +0100
1952 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1954 +# This program is free software; you can redistribute it and/or modify
1955 +# it under the terms of the GNU General Public License as published by
1956 +# the Free Software Foundation; either version 2 of the License, or
1957 +# (at your option) any later version.
1959 +# This program is distributed in the hope that it will be useful,
1960 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1961 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1962 +# GNU General Public License for more details.
1964 +# You should have received a copy of the GNU General Public License
1965 +# along with this program; if not, write to the Free Software
1966 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1969 +File-based Hierarchical Storage Management (FHSM)
1970 +----------------------------------------------------------------------
1971 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1972 +storage world. Aufs provides this feature as file-based with multiple
1973 +writable branches, based upon the principle of "Colder, the Lower".
1974 +Here the word "colder" means that the less used files, and "lower" means
1975 +that the position in the order of the stacked branches vertically.
1976 +These multiple writable branches are prioritized, ie. the topmost one
1977 +should be the fastest drive and be used heavily.
1979 +o Characters in aufs FHSM story
1980 +- aufs itself and a new branch attribute.
1981 +- a new ioctl interface to move-down and to establish a connection with
1982 + the daemon ("move-down" is a converse of "copy-up").
1983 +- userspace tool and daemon.
1985 +The userspace daemon establishes a connection with aufs and waits for
1986 +the notification. The notified information is very similar to struct
1987 +statfs containing the number of consumed blocks and inodes.
1988 +When the consumed blocks/inodes of a branch exceeds the user-specified
1989 +upper watermark, the daemon activates its move-down process until the
1990 +consumed blocks/inodes reaches the user-specified lower watermark.
1992 +The actual move-down is done by aufs based upon the request from
1993 +user-space since we need to maintain the inode number and the internal
1994 +pointer arrays in aufs.
1996 +Currently aufs FHSM handles the regular files only. Additionally they
1997 +must not be hard-linked nor pseudo-linked.
2000 +o Cowork of aufs and the user-space daemon
2001 + During the userspace daemon established the connection, aufs sends a
2002 + small notification to it whenever aufs writes something into the
2003 + writable branch. But it may cost high since aufs issues statfs(2)
2004 + internally. So user can specify a new option to cache the
2005 + info. Actually the notification is controlled by these factors.
2006 + + the specified cache time.
2007 + + classified as "force" by aufs internally.
2008 + Until the specified time expires, aufs doesn't send the info
2009 + except the forced cases. When aufs decide forcing, the info is always
2010 + notified to userspace.
2011 + For example, the number of free inodes is generally large enough and
2012 + the shortage of it happens rarely. So aufs doesn't force the
2013 + notification when creating a new file, directory and others. This is
2014 + the typical case which aufs doesn't force.
2015 + When aufs writes the actual filedata and the files consumes any of new
2016 + blocks, the aufs forces notifying.
2019 +o Interfaces in aufs
2020 +- New branch attribute.
2022 + Specifies that the branch is managed by FHSM feature. In other word,
2023 + participant in the FHSM.
2024 + When nofhsm is set to the branch, it will not be the source/target
2025 + branch of the move-down operation. This attribute is set
2026 + independently from coo and moo attributes, and if you want full
2027 + FHSM, you should specify them as well.
2028 +- New mount option.
2030 + Specifies a second to suppress many less important info to be
2033 + + AUFS_CTL_FHSM_FD
2034 + create a new file descriptor which userspace can read the notification
2035 + (a subset of struct statfs) from aufs.
2036 +- Module parameter 'brs'
2037 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2039 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2040 + When there are two or more branches with fhsm attributes,
2041 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2042 + terminates it. As a result of remounting and branch-manipulation, the
2043 + number of branches with fhsm attribute can be one. In this case,
2044 + /sbin/mount.aufs will terminate the user-space daemon.
2047 +Finally the operation is done as these steps in kernel-space.
2049 + + no one else is using the file.
2050 + + the file is not hard-linked.
2051 + + the file is not pseudo-linked.
2052 + + the file is a regular file.
2053 + + the parent dir is not opaqued.
2054 +- find the target writable branch.
2055 +- make sure the file is not whiteout-ed by the upper (than the target)
2057 +- make the parent dir on the target branch.
2058 +- mutex lock the inode on the branch.
2059 +- unlink the whiteout on the target branch (if exists).
2060 +- lookup and create the whiteout-ed temporary name on the target branch.
2061 +- copy the file as the whiteout-ed temporary name on the target branch.
2062 +- rename the whiteout-ed temporary name to the original name.
2063 +- unlink the file on the source branch.
2064 +- maintain the internal pointer array and the external inode number
2066 +- maintain the timestamps and other attributes of the parent dir and the
2069 +And of course, in every step, an error may happen. So the operation
2070 +should restore the original file state after an error happens.
2071 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2072 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2073 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-03-21 14:49:05.716633010 +0100
2076 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2078 +# This program is free software; you can redistribute it and/or modify
2079 +# it under the terms of the GNU General Public License as published by
2080 +# the Free Software Foundation; either version 2 of the License, or
2081 +# (at your option) any later version.
2083 +# This program is distributed in the hope that it will be useful,
2084 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2085 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2086 +# GNU General Public License for more details.
2088 +# You should have received a copy of the GNU General Public License
2089 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2091 +mmap(2) -- File Memory Mapping
2092 +----------------------------------------------------------------------
2093 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2094 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2096 +This approach is simple and good, but there is one problem.
2097 +Under /proc, several entries show the mmapped files by its path (with
2098 +device and inode number), and the printed path will be the path on the
2099 +branch fs's instead of virtual aufs's.
2100 +This is not a problem in most cases, but some utilities lsof(1) (and its
2101 +user) may expect the path on aufs.
2103 +To address this issue, aufs adds a new member called vm_prfile in struct
2104 +vm_area_struct (and struct vm_region). The original vm_file points to
2105 +the file on the branch fs in order to handle everything correctly as
2106 +usual. The new vm_prfile points to a virtual file in aufs, and the
2107 +show-functions in procfs refers to vm_prfile if it is set.
2108 +Also we need to maintain several other places where touching vm_file
2110 +- fork()/clone() copies vma and the reference count of vm_file is
2112 +- merging vma maintains the ref count too.
2114 +This is not a good approach. It just fakes the printed path. But it
2115 +leaves all behaviour around f_mapping unchanged. This is surely an
2117 +Actually aufs had adopted another complicated approach which calls
2118 +generic_file_mmap() and handles struct vm_operations_struct. In this
2119 +approach, aufs met a hard problem and I could not solve it without
2120 +switching the approach.
2122 +There may be one more another approach which is
2123 +- bind-mount the branch-root onto the aufs-root internally
2124 +- grab the new vfsmount (ie. struct mount)
2125 +- lazy-umount the branch-root internally
2126 +- in open(2) the aufs-file, open the branch-file with the hidden
2127 + vfsmount (instead of the original branch's vfsmount)
2128 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2129 + but it may be possible from userspace by the mount helper.
2131 +Adding the internal hidden vfsmount and using it in opening a file, the
2132 +file path under /proc will be printed correctly. This approach looks
2133 +smarter, but is not possible I am afraid.
2134 +- aufs-root may be bind-mount later. when it happens, another hidden
2135 + vfsmount will be required.
2136 +- it is hard to get the chance to bind-mount and lazy-umount
2137 + + in kernel-space, FS can have vfsmount in open(2) via
2138 + file->f_path, and aufs can know its vfsmount. But several locks are
2139 + already acquired, and if aufs tries to bind-mount and lazy-umount
2140 + here, then it may cause a deadlock.
2141 + + in user-space, bind-mount doesn't invoke the mount helper.
2142 +- since /proc shows dev and ino, aufs has to give vma these info. it
2143 + means a new member vm_prinode will be necessary. this is essentially
2144 + equivalent to vm_prfile described above.
2146 +I have to give up this "looks-smater" approach.
2147 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2148 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2149 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-03-21 14:49:05.716633010 +0100
2152 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2154 +# This program is free software; you can redistribute it and/or modify
2155 +# it under the terms of the GNU General Public License as published by
2156 +# the Free Software Foundation; either version 2 of the License, or
2157 +# (at your option) any later version.
2159 +# This program is distributed in the hope that it will be useful,
2160 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2161 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2162 +# GNU General Public License for more details.
2164 +# You should have received a copy of the GNU General Public License
2165 +# along with this program; if not, write to the Free Software
2166 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2169 +Listing XATTR/EA and getting the value
2170 +----------------------------------------------------------------------
2171 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2172 +shows the values from the topmost existing file. This behaviour is good
2173 +for the non-dir entries since the bahaviour exactly matches the shown
2174 +information. But for the directories, aufs considers all the same named
2175 +entries on the lower branches. Which means, if one of the lower entry
2176 +rejects readdir call, then aufs returns an error even if the topmost
2177 +entry allows it. This behaviour is necessary to respect the branch fs's
2178 +security, but can make users confused since the user-visible standard
2179 +attributes don't match the behaviour.
2180 +To address this issue, aufs has a mount option called dirperm1 which
2181 +checks the permission for the topmost entry only, and ignores the lower
2182 +entry's permission.
2184 +A similar issue can happen around XATTR.
2185 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2186 +always set. Otherwise these very unpleasant situation would happen.
2187 +- listxattr(2) may return the duplicated entries.
2188 +- users may not be able to remove or reset the XATTR forever,
2191 +XATTR/EA support in the internal (copy,move)-(up,down)
2192 +----------------------------------------------------------------------
2193 +Generally the extended attributes of inode are categorized as these.
2194 +- "security" for LSM and capability.
2195 +- "system" for posix ACL, 'acl' mount option is required for the branch
2197 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2198 +- "user" for userspace, 'user_xattr' mount option is required for the
2199 + branch fs generally.
2201 +Moreover there are some other categories. Aufs handles these rather
2202 +unpopular categories as the ordinary ones, ie. there is no special
2203 +condition nor exception.
2205 +In copy-up, the support for XATTR on the dst branch may differ from the
2206 +src branch. In this case, the copy-up operation will get an error and
2207 +the original user operation which triggered the copy-up will fail. It
2208 +can happen that even all copy-up will fail.
2209 +When both of src and dst branches support XATTR and if an error occurs
2210 +during copying XATTR, then the copy-up should fail obviously. That is a
2211 +good reason and aufs should return an error to userspace. But when only
2212 +the src branch support that XATTR, aufs should not return an error.
2213 +For example, the src branch supports ACL but the dst branch doesn't
2214 +because the dst branch may natively un-support it or temporary
2215 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2216 +may NOT return an error even if the XATTR is not supported. It is
2217 +totally up to the branch fs.
2219 +Anyway when the aufs internal copy-up gets an error from the dst branch
2220 +fs, then aufs tries removing the just copied entry and returns the error
2221 +to the userspace. The worst case of this situation will be all copy-up
2224 +For the copy-up operation, there two basic approaches.
2225 +- copy the specified XATTR only (by category above), and return the
2226 + error unconditionally if it happens.
2227 +- copy all XATTR, and ignore the error on the specified category only.
2229 +In order to support XATTR and to implement the correct behaviour, aufs
2230 +chooses the latter approach and introduces some new branch attributes,
2231 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2232 +They correspond to the XATTR namespaces (see above). Additionally, to be
2233 +convenient, "icex" is also provided which means all "icex*" attributes
2234 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2236 +The meaning of these attributes is to ignore the error from setting
2237 +XATTR on that branch.
2238 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2239 +error from the dst branch according to the specified attributes.
2241 +Some XATTR may have its default value. The default value may come from
2242 +the parent dir or the environment. If the default value is set at the
2243 +file creating-time, it will be overwritten by copy-up.
2244 +Some contradiction may happen I am afraid.
2245 +Do we need another attribute to stop copying XATTR? I am unsure. For
2246 +now, aufs implements the branch attributes to ignore the error.
2247 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2248 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2249 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-03-21 14:49:05.716633010 +0100
2252 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2254 +# This program is free software; you can redistribute it and/or modify
2255 +# it under the terms of the GNU General Public License as published by
2256 +# the Free Software Foundation; either version 2 of the License, or
2257 +# (at your option) any later version.
2259 +# This program is distributed in the hope that it will be useful,
2260 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2261 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2262 +# GNU General Public License for more details.
2264 +# You should have received a copy of the GNU General Public License
2265 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2267 +Export Aufs via NFS
2268 +----------------------------------------------------------------------
2269 +Here is an approach.
2270 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2272 +- iget_locked(): initialize aufs inode generation for a new inode, and
2273 + store it in xigen file.
2274 +- destroy_inode(): increment aufs inode generation and store it in xigen
2275 + file. it is necessary even if it is not unlinked, because any data of
2276 + inode may be changed by UDBA.
2277 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2278 + build file handle by
2279 + + branch id (4 bytes)
2280 + + superblock generation (4 bytes)
2281 + + inode number (4 or 8 bytes)
2282 + + parent dir inode number (4 or 8 bytes)
2283 + + inode generation (4 bytes))
2284 + + return value of exportfs_encode_fh() for the parent on a branch (4
2286 + + file handle for a branch (by exportfs_encode_fh())
2288 + + find the index of a branch from its id in handle, and check it is
2289 + still exist in aufs.
2290 + + 1st level: get the inode number from handle and search it in cache.
2291 + + 2nd level: if not found in cache, get the parent inode number from
2292 + the handle and search it in cache. and then open the found parent
2293 + dir, find the matching inode number by vfs_readdir() and get its
2294 + name, and call lookup_one_len() for the target dentry.
2295 + + 3rd level: if the parent dir is not cached, call
2296 + exportfs_decode_fh() for a branch and get the parent on a branch,
2297 + build a pathname of it, convert it a pathname in aufs, call
2298 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2300 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2301 + for every branch, but not itself. to get this, (currently) aufs
2302 + searches in current->nsproxy->mnt_ns list. it may not be a good
2303 + idea, but I didn't get other approach.
2304 + + test the generation of the gotten inode.
2305 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2306 + convert it into ESTALE for NFSD.
2307 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2308 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2309 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2310 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2311 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-03-21 14:49:05.716633010 +0100
2314 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2316 +# This program is free software; you can redistribute it and/or modify
2317 +# it under the terms of the GNU General Public License as published by
2318 +# the Free Software Foundation; either version 2 of the License, or
2319 +# (at your option) any later version.
2321 +# This program is distributed in the hope that it will be useful,
2322 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2323 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2324 +# GNU General Public License for more details.
2326 +# You should have received a copy of the GNU General Public License
2327 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2329 +Show Whiteout Mode (shwh)
2330 +----------------------------------------------------------------------
2331 +Generally aufs hides the name of whiteouts. But in some cases, to show
2332 +them is very useful for users. For instance, creating a new middle layer
2333 +(branch) by merging existing layers.
2335 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2336 +When you have three branches,
2337 +- Bottom: 'system', squashfs (underlying base system), read-only
2338 +- Middle: 'mods', squashfs, read-only
2339 +- Top: 'overlay', ram (tmpfs), read-write
2341 +The top layer is loaded at boot time and saved at shutdown, to preserve
2342 +the changes made to the system during the session.
2343 +When larger changes have been made, or smaller changes have accumulated,
2344 +the size of the saved top layer data grows. At this point, it would be
2345 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2346 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2347 +restoring save and load speed.
2349 +This merging is simplified by the use of another aufs mount, of just the
2350 +two overlay branches using the 'shwh' option.
2351 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2352 + aufs /livesys/merge_union
2354 +A merged view of these two branches is then available at
2355 +/livesys/merge_union, and the new feature is that the whiteouts are
2357 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2358 +writing to all branches. Also the default mode for all branches is 'ro'.
2359 +It is now possible to save the combined contents of the two overlay
2360 +branches to a new squashfs, e.g.:
2361 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2363 +This new squashfs archive can be stored on the boot device and the
2364 +initramfs will use it to replace the old one at the next boot.
2365 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2366 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2367 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-03-21 14:49:05.716633010 +0100
2370 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2372 +# This program is free software; you can redistribute it and/or modify
2373 +# it under the terms of the GNU General Public License as published by
2374 +# the Free Software Foundation; either version 2 of the License, or
2375 +# (at your option) any later version.
2377 +# This program is distributed in the hope that it will be useful,
2378 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2379 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2380 +# GNU General Public License for more details.
2382 +# You should have received a copy of the GNU General Public License
2383 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2385 +Dynamically customizable FS operations
2386 +----------------------------------------------------------------------
2387 +Generally FS operations (struct inode_operations, struct
2388 +address_space_operations, struct file_operations, etc.) are defined as
2389 +"static const", but it never means that FS have only one set of
2390 +operation. Some FS have multiple sets of them. For instance, ext2 has
2391 +three sets, one for XIP, for NOBH, and for normal.
2392 +Since aufs overrides and redirects these operations, sometimes aufs has
2393 +to change its behaviour according to the branch FS type. More importantly
2394 +VFS acts differently if a function (member in the struct) is set or
2395 +not. It means aufs should have several sets of operations and select one
2396 +among them according to the branch FS definition.
2398 +In order to solve this problem and not to affect the behaviour of VFS,
2399 +aufs defines these operations dynamically. For instance, aufs defines
2400 +dummy direct_IO function for struct address_space_operations, but it may
2401 +not be set to the address_space_operations actually. When the branch FS
2402 +doesn't have it, aufs doesn't set it to its address_space_operations
2403 +while the function definition itself is still alive. So the behaviour
2404 +itself will not change, and it will return an error when direct_IO is
2407 +The lifetime of these dynamically generated operation object is
2408 +maintained by aufs branch object. When the branch is removed from aufs,
2409 +the reference counter of the object is decremented. When it reaches
2410 +zero, the dynamically generated operation object will be freed.
2412 +This approach is designed to support AIO (io_submit), Direct I/O and
2414 +Currently this approach is applied to address_space_operations for
2415 +regular files only.
2416 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2417 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2418 +++ linux/Documentation/filesystems/aufs/README 2022-03-21 14:49:05.713299677 +0100
2421 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2427 +----------------------------------------
2428 +In the early days, aufs was entirely re-designed and re-implemented
2429 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2430 +improvements and implementations, it became totally different from
2431 +Unionfs while keeping the basic features.
2432 +Later, Unionfs Version 2.x series began taking some of the same
2433 +approaches to aufs1's.
2434 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2435 +University and his team.
2437 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2439 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2440 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2441 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2442 + or aufs1 from CVS on SourceForge.
2444 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2445 + According to Christoph Hellwig, linux rejects all union-type
2446 + filesystems but UnionMount.
2447 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2449 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2450 + UnionMount, and he pointed out an issue around a directory mutex
2451 + lock and aufs addressed it. But it is still unsure whether aufs will
2452 + be merged (or any other union solution).
2453 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2457 +----------------------------------------
2458 +- unite several directories into a single virtual filesystem. The member
2459 + directory is called as a branch.
2460 +- you can specify the permission flags to the branch, which are 'readonly',
2461 + 'readwrite' and 'whiteout-able.'
2462 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2463 + readonly branch are modifiable logically.
2464 +- dynamic branch manipulation, add, del.
2467 +Also there are many enhancements in aufs, such as:
2468 +- test only the highest one for the directory permission (dirperm1)
2469 +- copyup on open (coo=)
2470 +- 'move' policy for copy-up between two writable branches, after
2471 + checking free space.
2473 +- readdir(3) in userspace.
2474 +- keep inode number by external inode number table
2475 +- keep the timestamps of file/dir in internal copyup operation
2476 +- seekable directory, supporting NFS readdir.
2477 +- whiteout is hardlinked in order to reduce the consumption of inodes
2479 +- do not copyup, nor create a whiteout when it is unnecessary
2480 +- revert a single systemcall when an error occurs in aufs
2481 +- remount interface instead of ioctl
2482 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2483 +- loopback mounted filesystem as a branch
2484 +- kernel thread for removing the dir who has a plenty of whiteouts
2485 +- support copyup sparse file (a file which has a 'hole' in it)
2486 +- default permission flags for branches
2487 +- selectable permission flags for ro branch, whether whiteout can
2490 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2491 +- support multiple writable branches, some policies to select one
2492 + among multiple writable branches.
2493 +- a new semantics for link(2) and rename(2) to support multiple
2494 + writable branches.
2495 +- no glibc changes are required.
2496 +- pseudo hardlink (hardlink over branches)
2497 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2498 + including NFS or remote filesystem branch.
2499 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2502 +Currently these features are dropped temporary from aufs5.
2503 +See design/08plan.txt in detail.
2504 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2506 +- statistics of aufs thread (/sys/fs/aufs/stat)
2508 +Features or just an idea in the future (see also design/*.txt),
2509 +- reorder the branch index without del/re-add.
2510 +- permanent xino files for NFSD
2511 +- an option for refreshing the opened files after add/del branches
2512 +- light version, without branch manipulation. (unnecessary?)
2513 +- copyup in userspace
2514 +- inotify in userspace
2519 +----------------------------------------
2520 +There are three GIT trees for aufs5, aufs5-linux.git,
2521 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2523 +While the aufs-util is always necessary, you need either of aufs5-linux
2524 +or aufs5-standalone.
2526 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2527 +git://git.kernel.org/.../torvalds/linux.git.
2528 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2529 +build aufs5 as an external kernel module.
2530 +Several extra patches are not included in this tree. Only
2531 +aufs5-standalone tree contains them. They are described in the later
2532 +section "Configuration and Compilation."
2534 +On the other hand, the aufs5-standalone tree has only aufs source files
2535 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2536 +But you need to apply all aufs patches manually.
2538 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2539 +represents the linux kernel version, "linux-5.x". For instance,
2540 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2541 +"aufs5.x-rcN" branch.
2544 +$ git clone --reference /your/linux/git/tree \
2545 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2546 +- if you don't have linux GIT tree, then remove "--reference ..."
2547 +$ cd aufs5-linux.git
2548 +$ git checkout origin/aufs5.0
2550 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2551 +leave the patch-work to GIT.
2552 +$ cd /your/linux/git/tree
2553 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2555 +$ git checkout -b my5.0 v5.0
2556 +$ (add your local change...)
2557 +$ git pull aufs5 aufs5.0
2558 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2559 +- you may need to solve some conflicts between your_changes and
2560 + aufs5.0. in this case, git-rerere is recommended so that you can
2561 + solve the similar conflicts automatically when you upgrade to 5.1 or
2562 + later in the future.
2564 +o aufs5-standalone tree
2565 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2566 +$ cd aufs5-standalone.git
2567 +$ git checkout origin/aufs5.0
2570 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2571 +- note that the public aufs-util.git is on SourceForge instead of
2574 +$ git checkout origin/aufs5.0
2576 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2577 +The minor version number, 'x' in '5.x', of aufs may not always
2578 +follow the minor version number of the kernel.
2579 +Because changes in the kernel that cause the use of a new
2580 +minor version number do not always require changes to aufs-util.
2582 +Since aufs-util has its own minor version number, you may not be
2583 +able to find a GIT branch in aufs-util for your kernel's
2584 +exact minor version number.
2585 +In this case, you should git-checkout the branch for the
2586 +nearest lower number.
2588 +For (an unreleased) example:
2589 +If you are using "linux-5.10" and the "aufs5.10" branch
2590 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2591 +or something numerically smaller is the branch for your kernel.
2593 +Also you can view all branches by
2597 +3. Configuration and Compilation
2598 +----------------------------------------
2599 +Make sure you have git-checkout'ed the correct branch.
2601 +For aufs5-linux tree,
2602 +- enable CONFIG_AUFS_FS.
2603 +- set other aufs configurations if necessary.
2604 +- for aufs5.13 and later
2605 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2606 + also a caller of VFS functions for branch filesystems, subclassing of
2607 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2608 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2609 + need to customize some LOCKDEP numbers. Here are what I use on my
2611 + CONFIG_LOCKDEP_BITS=21
2612 + CONFIG_LOCKDEP_CHAINS_BITS=21
2613 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2615 +For aufs5-standalone tree,
2616 +There are several ways to build.
2619 +- apply ./aufs5-kbuild.patch to your kernel source files.
2620 +- apply ./aufs5-base.patch too.
2621 +- apply ./aufs5-mmap.patch too.
2622 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2623 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2624 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2625 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2626 +- enable CONFIG_AUFS_FS, you can select either
2628 +- and build your kernel as usual.
2629 +- install the built kernel.
2630 +- install the header files too by "make headers_install" to the
2631 + directory where you specify. By default, it is $PWD/usr.
2632 + "make help" shows a brief note for headers_install.
2633 +- and reboot your system.
2636 +- module only (CONFIG_AUFS_FS=m).
2637 +- apply ./aufs5-base.patch to your kernel source files.
2638 +- apply ./aufs5-mmap.patch too.
2639 +- apply ./aufs5-standalone.patch too.
2640 +- build your kernel, don't forget "make headers_install", and reboot.
2641 +- edit ./config.mk and set other aufs configurations if necessary.
2642 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2643 + every aufs configurations.
2644 +- build the module by simple "make".
2645 +- you can specify ${KDIR} make variable which points to your kernel
2647 +- install the files
2648 + + run "make install" to install the aufs module, or copy the built
2649 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2650 + + run "make install_headers" (instead of headers_install) to install
2651 + the modified aufs header file (you can specify DESTDIR which is
2652 + available in aufs standalone version's Makefile only), or copy
2653 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2654 + you like manually. By default, the target directory is $PWD/usr.
2655 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2656 + kernel source tree.
2658 +Note: The header file aufs_type.h is necessary to build aufs-util
2659 + as well as "make headers_install" in the kernel source tree.
2660 + headers_install is subject to be forgotten, but it is essentially
2661 + necessary, not only for building aufs-util.
2662 + You may not meet problems without headers_install in some older
2666 +- read README in aufs-util, build and install it
2667 +- note that your distribution may contain an obsoleted version of
2668 + aufs_type.h in /usr/include/linux or something. When you build aufs
2669 + utilities, make sure that your compiler refers the correct aufs header
2670 + file which is built by "make headers_install."
2671 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2672 + then run "make install_ulib" too. And refer to the aufs manual in
2675 +There several other patches in aufs5-standalone.git. They are all
2676 +optional. When you meet some problems, they will help you.
2677 +- aufs5-loopback.patch
2678 + Supports a nested loopback mount in a branch-fs. This patch is
2679 + unnecessary until aufs produces a message like "you may want to try
2680 + another patch for loopback file".
2682 + Modifies a system global kernel internal function get_next_ino() in
2683 + order to stop assigning 0 for an inode-number. Not directly related to
2684 + aufs, but recommended generally.
2686 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2687 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2688 + duplication of inode number, which is important for backup tools and
2689 + other utilities. When you find aufs XINO files for tmpfs branch
2690 + growing too much, try this patch.
2694 +----------------------------------------
2695 +At first, make sure aufs-util are installed, and please read the aufs
2696 +manual, aufs.5 in aufs-util.git tree.
2700 +$ mkdir /tmp/rw /tmp/aufs
2701 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2703 +Here is another example. The result is equivalent.
2704 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2706 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2707 +# mount -o remount,append:${HOME} /tmp/aufs
2709 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2710 +you modify a file under /tmp/aufs, the one on your home directory is
2711 +not affected, instead the same named file will be newly created under
2712 +/tmp/rw. And all of your modification to a file will be applied to
2713 +the one under /tmp/rw. This is called the file based Copy on Write
2715 +Aufs mount options are described in aufs.5.
2716 +If you run chroot or something and make your aufs as a root directory,
2717 +then you need to customize the shutdown script. See the aufs manual in
2720 +Additionally, there are some sample usages of aufs which are a
2721 +diskless system with network booting, and LiveCD over NFS.
2722 +See sample dir in CVS tree on SourceForge.
2726 +----------------------------------------
2727 +When you have any problems or strange behaviour in aufs, please let me
2729 +- /proc/mounts (instead of the output of mount(8))
2730 +- /sys/module/aufs/*
2731 +- /sys/fs/aufs/* (if you have them)
2732 +- /debug/aufs/* (if you have them)
2733 +- linux kernel version
2734 + if your kernel is not plain, for example modified by distributor,
2735 + the url where i can download its source is necessary too.
2736 +- aufs version which was printed at loading the module or booting the
2737 + system, instead of the date you downloaded.
2738 +- configuration (define/undefine CONFIG_AUFS_xxx)
2739 +- kernel configuration or /proc/config.gz (if you have it)
2740 +- LSM (linux security module, if you are using)
2741 +- behaviour which you think to be incorrect
2742 +- actual operation, reproducible one is better
2743 +- mailto: aufs-users at lists.sourceforge.net
2745 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2746 +and Feature Requests) on SourceForge. Please join and write to
2750 +6. Acknowledgements
2751 +----------------------------------------
2752 +Thanks to everyone who have tried and are using aufs, whoever
2753 +have reported a bug or any feedback.
2755 +Especially donators:
2756 +Tomas Matejicek(slax.org) made a donation (much more than once).
2757 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2758 + scripts) is making "doubling" donations.
2759 + Unfortunately I cannot list all of the donators, but I really
2761 + It ends Aug 2010, but the ordinary donation URL is still available.
2762 + <http://sourceforge.net/donate/index.php?group_id=167503>
2763 +Dai Itasaka made a donation (2007/8).
2764 +Chuck Smith made a donation (2008/4, 10 and 12).
2765 +Henk Schoneveld made a donation (2008/9).
2766 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2767 +Francois Dupoux made a donation (2008/11).
2768 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2769 + aufs2 GIT tree (2009/2).
2770 +William Grant made a donation (2009/3).
2771 +Patrick Lane made a donation (2009/4).
2772 +The Mail Archive (mail-archive.com) made donations (2009/5).
2773 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2774 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2775 +Pavel Pronskiy made a donation (2011/2).
2776 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2777 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2778 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2780 +Sam Liddicott made a donation (2011/9).
2781 +Era Scarecrow made a donation (2013/4).
2782 +Bor Ratajc made a donation (2013/4).
2783 +Alessandro Gorreta made a donation (2013/4).
2784 +POIRETTE Marc made a donation (2013/4).
2785 +Alessandro Gorreta made a donation (2013/4).
2786 +lauri kasvandik made a donation (2013/5).
2787 +"pemasu from Finland" made a donation (2013/7).
2788 +The Parted Magic Project made a donation (2013/9 and 11).
2789 +Pavel Barta made a donation (2013/10).
2790 +Nikolay Pertsev made a donation (2014/5).
2791 +James B made a donation (2014/7, 2015/7, and 2021/12).
2792 +Stefano Di Biase made a donation (2014/8).
2793 +Daniel Epellei made a donation (2015/1).
2794 +OmegaPhil made a donation (2016/1, 2018/4).
2795 +Tomasz Szewczyk made a donation (2016/4).
2796 +James Burry made a donation (2016/12).
2797 +Carsten Rose made a donation (2018/9).
2798 +Porteus Kiosk made a donation (2018/10).
2800 +Thank you very much.
2801 +Donations are always, including future donations, very important and
2802 +helpful for me to keep on developing aufs.
2806 +----------------------------------------
2807 +If you are an experienced user, no explanation is needed. Aufs is
2808 +just a linux filesystem.
2813 +# Local variables: ;
2816 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2817 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2818 +++ linux/fs/aufs/aufs.h 2022-03-21 14:49:05.716633010 +0100
2820 +/* SPDX-License-Identifier: GPL-2.0 */
2822 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2824 + * This program, aufs is free software; you can redistribute it and/or modify
2825 + * it under the terms of the GNU General Public License as published by
2826 + * the Free Software Foundation; either version 2 of the License, or
2827 + * (at your option) any later version.
2829 + * This program is distributed in the hope that it will be useful,
2830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2832 + * GNU General Public License for more details.
2834 + * You should have received a copy of the GNU General Public License
2835 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2839 + * all header files
2847 +#define AuStub(type, name, body, ...) \
2848 + static inline type name(__VA_ARGS__) { body; }
2850 +#define AuStubVoid(name, ...) \
2851 + AuStub(void, name, , __VA_ARGS__)
2852 +#define AuStubInt0(name, ...) \
2853 + AuStub(int, name, return 0, __VA_ARGS__)
2857 +#include "branch.h"
2860 +#include "dbgaufs.h"
2861 +#include "dentry.h"
2863 +#include "dirren.h"
2866 +#include "fstype.h"
2871 +#include "module.h"
2875 +#include "sysaufs.h"
2880 +#endif /* __KERNEL__ */
2881 +#endif /* __AUFS_H__ */
2882 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2883 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2884 +++ linux/fs/aufs/branch.c 2022-03-21 14:49:05.719966344 +0100
2886 +// SPDX-License-Identifier: GPL-2.0
2888 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2890 + * This program, aufs is free software; you can redistribute it and/or modify
2891 + * it under the terms of the GNU General Public License as published by
2892 + * the Free Software Foundation; either version 2 of the License, or
2893 + * (at your option) any later version.
2895 + * This program is distributed in the hope that it will be useful,
2896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2898 + * GNU General Public License for more details.
2900 + * You should have received a copy of the GNU General Public License
2901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2905 + * branch management
2908 +#include <linux/compat.h>
2909 +#include <linux/statfs.h>
2913 + * free a single branch
2915 +static void au_br_do_free(struct au_branch *br)
2918 + struct au_wbr *wbr;
2919 + struct au_dykey **key;
2921 + au_hnotify_fin_br(br);
2922 + /* always, regardless the mount option */
2923 + au_dr_hino_free(&br->br_dirren);
2926 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2927 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2928 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2929 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2933 + for (i = 0; i < AuBrWh_Last; i++)
2934 + dput(wbr->wbr_wh[i]);
2935 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2936 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2939 + if (br->br_fhsm) {
2940 + au_br_fhsm_fin(br->br_fhsm);
2941 + au_kfree_try_rcu(br->br_fhsm);
2944 + key = br->br_dykey;
2945 + for (i = 0; i < AuBrDynOp; i++, key++)
2951 + /* recursive lock, s_umount of branch's */
2952 + /* synchronize_rcu(); */ /* why? */
2954 + path_put(&br->br_path);
2956 + au_kfree_rcu(wbr);
2957 + au_lcnt_wait_for_fin(&br->br_nfiles);
2958 + au_lcnt_wait_for_fin(&br->br_count);
2959 + /* I don't know why, but percpu_refcount requires this */
2960 + /* synchronize_rcu(); */
2965 + * frees all branches
2967 +void au_br_free(struct au_sbinfo *sbinfo)
2969 + aufs_bindex_t bmax;
2970 + struct au_branch **br;
2972 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2974 + bmax = sbinfo->si_bbot + 1;
2975 + br = sbinfo->si_branch;
2977 + au_br_do_free(*br++);
2981 + * find the index of a branch which is specified by @br_id.
2983 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2985 + aufs_bindex_t bindex, bbot;
2987 + bbot = au_sbbot(sb);
2988 + for (bindex = 0; bindex <= bbot; bindex++)
2989 + if (au_sbr_id(sb, bindex) == br_id)
2994 +/* ---------------------------------------------------------------------- */
3000 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3001 + struct dentry *h_root)
3003 + if (unlikely(h_adding == h_root
3004 + || au_test_loopback_overlap(sb, h_adding)))
3006 + if (h_adding->d_sb != h_root->d_sb)
3008 + return au_test_subdir(h_adding, h_root)
3009 + || au_test_subdir(h_root, h_adding);
3013 + * returns a newly allocated branch. @new_nbranch is a number of branches
3014 + * after adding a branch.
3016 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3019 + struct au_branch *add_branch;
3020 + struct dentry *root;
3021 + struct inode *inode;
3025 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3026 + if (unlikely(!add_branch))
3028 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3029 + if (unlikely(!add_branch->br_xino))
3031 + err = au_hnotify_init_br(add_branch, perm);
3032 + if (unlikely(err))
3035 + if (au_br_writable(perm)) {
3036 + /* may be freed separately at changing the branch permission */
3037 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3039 + if (unlikely(!add_branch->br_wbr))
3043 + if (au_br_fhsm(perm)) {
3044 + err = au_fhsm_br_alloc(add_branch);
3045 + if (unlikely(err))
3049 + root = sb->s_root;
3050 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3052 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3054 + inode = d_inode(root);
3055 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3059 + return add_branch; /* success */
3062 + au_kfree_rcu(add_branch->br_wbr);
3064 + au_hnotify_fin_br(add_branch);
3066 + au_xino_put(add_branch);
3068 + au_kfree_rcu(add_branch);
3070 + return ERR_PTR(err);
3074 + * test if the branch permission is legal or not.
3076 +static int test_br(struct inode *inode, int brperm, char *path)
3080 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3085 + pr_err("write permission for readonly mount or inode, %s\n", path);
3093 + * 0: success, the caller will add it
3094 + * plus: success, it is already unified, the caller should ignore it
3097 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3100 + aufs_bindex_t bbot, bindex;
3101 + struct dentry *root, *h_dentry;
3102 + struct inode *inode, *h_inode;
3104 + root = sb->s_root;
3105 + bbot = au_sbbot(sb);
3106 + if (unlikely(bbot >= 0
3107 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3111 + pr_err("%s duplicated\n", add->pathname);
3116 + err = -ENOSPC; /* -E2BIG; */
3117 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3118 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3119 + pr_err("number of branches exceeded %s\n", add->pathname);
3124 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3125 + pr_err("bad index %d\n", add->bindex);
3129 + inode = d_inode(add->path.dentry);
3131 + if (unlikely(!inode->i_nlink)) {
3132 + pr_err("no existence %s\n", add->pathname);
3137 + if (unlikely(inode->i_sb == sb)) {
3138 + pr_err("%s must be outside\n", add->pathname);
3142 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3143 + pr_err("unsupported filesystem, %s (%s)\n",
3144 + add->pathname, au_sbtype(inode->i_sb));
3148 + if (unlikely(inode->i_sb->s_stack_depth)) {
3149 + pr_err("already stacked, %s (%s)\n",
3150 + add->pathname, au_sbtype(inode->i_sb));
3154 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3155 + if (unlikely(err))
3159 + return 0; /* success */
3162 + for (bindex = 0; bindex <= bbot; bindex++)
3163 + if (unlikely(test_overlap(sb, add->path.dentry,
3164 + au_h_dptr(root, bindex)))) {
3165 + pr_err("%s is overlapped\n", add->pathname);
3170 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3171 + h_dentry = au_h_dptr(root, 0);
3172 + h_inode = d_inode(h_dentry);
3173 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3174 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3175 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3176 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3178 + i_uid_read(inode), i_gid_read(inode),
3179 + (inode->i_mode & S_IALLUGO),
3180 + i_uid_read(h_inode), i_gid_read(h_inode),
3181 + (h_inode->i_mode & S_IALLUGO));
3189 + * initialize or clean the whiteouts for an adding branch
3191 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3194 + int err, old_perm;
3195 + aufs_bindex_t bindex;
3196 + struct inode *h_inode;
3197 + struct au_wbr *wbr;
3198 + struct au_hinode *hdir;
3199 + struct dentry *h_dentry;
3201 + err = vfsub_mnt_want_write(au_br_mnt(br));
3202 + if (unlikely(err))
3206 + old_perm = br->br_perm;
3207 + br->br_perm = new_perm;
3210 + bindex = au_br_index(sb, br->br_id);
3211 + if (0 <= bindex) {
3212 + hdir = au_hi(d_inode(sb->s_root), bindex);
3213 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3215 + h_dentry = au_br_dentry(br);
3216 + h_inode = d_inode(h_dentry);
3217 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3220 + err = au_wh_init(br, sb);
3222 + wbr_wh_write_lock(wbr);
3223 + err = au_wh_init(br, sb);
3224 + wbr_wh_write_unlock(wbr);
3227 + au_hn_inode_unlock(hdir);
3229 + inode_unlock(h_inode);
3230 + vfsub_mnt_drop_write(au_br_mnt(br));
3231 + br->br_perm = old_perm;
3233 + if (!err && wbr && !au_br_writable(new_perm)) {
3234 + au_kfree_rcu(wbr);
3235 + br->br_wbr = NULL;
3242 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3246 + struct kstatfs kst;
3247 + struct au_wbr *wbr;
3250 + au_rw_init(&wbr->wbr_wh_rwsem);
3251 + atomic_set(&wbr->wbr_wh_running, 0);
3254 + * a limit for rmdir/rename a dir
3255 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3257 + err = vfs_statfs(&br->br_path, &kst);
3258 + if (unlikely(err))
3261 + if (kst.f_namelen >= NAME_MAX)
3262 + err = au_br_init_wh(sb, br, perm);
3264 + pr_err("%pd(%s), unsupported namelen %ld\n",
3266 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3272 +/* initialize a new branch */
3273 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3274 + struct au_opt_add *add)
3277 + struct au_branch *brbase;
3279 + struct inode *h_inode;
3282 + br->br_perm = add->perm;
3283 + br->br_path = add->path; /* set first, path_get() later */
3284 + spin_lock_init(&br->br_dykey_lock);
3285 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3286 + au_lcnt_init(&br->br_count, /*release*/NULL);
3287 + br->br_id = au_new_br_id(sb);
3288 + AuDebugOn(br->br_id < 0);
3290 + /* always, regardless the given option */
3291 + err = au_dr_br_init(sb, br, &add->path);
3292 + if (unlikely(err))
3295 + if (au_br_writable(add->perm)) {
3296 + err = au_wbr_init(br, sb, add->perm);
3297 + if (unlikely(err))
3301 + if (au_opt_test(au_mntflags(sb), XINO)) {
3302 + brbase = au_sbr(sb, 0);
3303 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3305 + h_inode = d_inode(add->path.dentry);
3306 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3307 + if (unlikely(err)) {
3308 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3313 + sysaufs_br_init(br);
3314 + path_get(&br->br_path);
3315 + goto out; /* success */
3318 + memset(&br->br_path, 0, sizeof(br->br_path));
3323 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3324 + struct au_branch *br, aufs_bindex_t bbot,
3325 + aufs_bindex_t amount)
3327 + struct au_branch **brp;
3329 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3331 + brp = sbinfo->si_branch + bindex;
3332 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3334 + sbinfo->si_bbot++;
3335 + if (unlikely(bbot < 0))
3336 + sbinfo->si_bbot = 0;
3339 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3340 + aufs_bindex_t bbot, aufs_bindex_t amount)
3342 + struct au_hdentry *hdp;
3344 + AuRwMustWriteLock(&dinfo->di_rwsem);
3346 + hdp = au_hdentry(dinfo, bindex);
3347 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3348 + au_h_dentry_init(hdp);
3350 + if (unlikely(bbot < 0))
3351 + dinfo->di_btop = 0;
3354 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3355 + aufs_bindex_t bbot, aufs_bindex_t amount)
3357 + struct au_hinode *hip;
3359 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3361 + hip = au_hinode(iinfo, bindex);
3362 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3363 + au_hinode_init(hip);
3365 + if (unlikely(bbot < 0))
3366 + iinfo->ii_btop = 0;
3369 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3370 + aufs_bindex_t bindex)
3372 + struct dentry *root, *h_dentry;
3373 + struct inode *root_inode, *h_inode;
3374 + aufs_bindex_t bbot, amount;
3376 + root = sb->s_root;
3377 + root_inode = d_inode(root);
3378 + bbot = au_sbbot(sb);
3379 + amount = bbot + 1 - bindex;
3380 + h_dentry = au_br_dentry(br);
3381 + au_sbilist_lock();
3382 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3383 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3384 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3385 + au_set_h_dptr(root, bindex, dget(h_dentry));
3386 + h_inode = d_inode(h_dentry);
3387 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3388 + au_sbilist_unlock();
3391 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3394 + aufs_bindex_t bbot, add_bindex;
3395 + struct dentry *root, *h_dentry;
3396 + struct inode *root_inode;
3397 + struct au_branch *add_branch;
3399 + root = sb->s_root;
3400 + root_inode = d_inode(root);
3401 + IMustLock(root_inode);
3402 + IiMustWriteLock(root_inode);
3403 + err = test_add(sb, add, remount);
3404 + if (unlikely(err < 0))
3408 + goto out; /* success */
3411 + bbot = au_sbbot(sb);
3412 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3413 + err = PTR_ERR(add_branch);
3414 + if (IS_ERR(add_branch))
3417 + err = au_br_init(add_branch, sb, add);
3418 + if (unlikely(err)) {
3419 + au_br_do_free(add_branch);
3423 + add_bindex = add->bindex;
3424 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3425 + au_br_do_add(sb, add_branch, add_bindex);
3426 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3427 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3429 + h_dentry = add->path.dentry;
3430 + if (!add_bindex) {
3431 + au_cpup_attr_all(root_inode, /*force*/1);
3432 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3434 + au_add_nlink(root_inode, d_inode(h_dentry));
3440 +/* ---------------------------------------------------------------------- */
3442 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3443 + unsigned long long max __maybe_unused,
3446 + unsigned long long n;
3447 + struct file **p, *f;
3448 + struct hlist_bl_head *files;
3449 + struct hlist_bl_node *pos;
3450 + struct au_finfo *finfo;
3454 + files = &au_sbi(sb)->si_files;
3455 + hlist_bl_lock(files);
3456 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3457 + f = finfo->fi_file;
3459 + && !special_file(file_inode(f)->i_mode)) {
3463 + AuDebugOn(n > max);
3466 + hlist_bl_unlock(files);
3471 +static struct file **au_farray_alloc(struct super_block *sb,
3472 + unsigned long long *max)
3474 + struct au_sbinfo *sbi;
3477 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3478 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3481 +static void au_farray_free(struct file **a, unsigned long long max)
3483 + unsigned long long ull;
3485 + for (ull = 0; ull < max; ull++)
3491 +/* ---------------------------------------------------------------------- */
3497 +/* to show the line number, do not make it inlined function */
3498 +#define AuVerbose(do_info, fmt, ...) do { \
3500 + pr_info(fmt, ##__VA_ARGS__); \
3503 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3504 + aufs_bindex_t bbot)
3506 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3509 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3510 + aufs_bindex_t bbot)
3512 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3516 + * test if the branch is deletable or not.
3518 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3519 + unsigned int sigen, const unsigned int verbose)
3521 + int err, i, j, ndentry;
3522 + aufs_bindex_t btop, bbot;
3523 + struct au_dcsub_pages dpages;
3524 + struct au_dpage *dpage;
3527 + err = au_dpages_init(&dpages, GFP_NOFS);
3528 + if (unlikely(err))
3530 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3531 + if (unlikely(err))
3534 + for (i = 0; !err && i < dpages.ndpage; i++) {
3535 + dpage = dpages.dpages + i;
3536 + ndentry = dpage->ndentry;
3537 + for (j = 0; !err && j < ndentry; j++) {
3538 + d = dpage->dentries[j];
3539 + AuDebugOn(au_dcount(d) <= 0);
3540 + if (!au_digen_test(d, sigen)) {
3541 + di_read_lock_child(d, AuLock_IR);
3542 + if (unlikely(au_dbrange_test(d))) {
3543 + di_read_unlock(d, AuLock_IR);
3547 + di_write_lock_child(d);
3548 + if (unlikely(au_dbrange_test(d))) {
3549 + di_write_unlock(d);
3552 + err = au_reval_dpath(d, sigen);
3554 + di_downgrade_lock(d, AuLock_IR);
3556 + di_write_unlock(d);
3561 + /* AuDbgDentry(d); */
3562 + btop = au_dbtop(d);
3563 + bbot = au_dbbot(d);
3564 + if (btop <= bindex
3566 + && au_h_dptr(d, bindex)
3567 + && au_test_dbusy(d, btop, bbot)) {
3569 + AuVerbose(verbose, "busy %pd\n", d);
3572 + di_read_unlock(d, AuLock_IR);
3577 + au_dpages_free(&dpages);
3582 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3583 + unsigned int sigen, const unsigned int verbose)
3586 + unsigned long long max, ull;
3587 + struct inode *i, **array;
3588 + aufs_bindex_t btop, bbot;
3590 + array = au_iarray_alloc(sb, &max);
3591 + err = PTR_ERR(array);
3592 + if (IS_ERR(array))
3596 + AuDbg("b%d\n", bindex);
3597 + for (ull = 0; !err && ull < max; ull++) {
3601 + if (i->i_ino == AUFS_ROOT_INO)
3604 + /* AuDbgInode(i); */
3605 + if (au_iigen(i, NULL) == sigen)
3606 + ii_read_lock_child(i);
3608 + ii_write_lock_child(i);
3609 + err = au_refresh_hinode_self(i);
3612 + ii_downgrade_lock(i);
3614 + ii_write_unlock(i);
3619 + btop = au_ibtop(i);
3620 + bbot = au_ibbot(i);
3621 + if (btop <= bindex
3623 + && au_h_iptr(i, bindex)
3624 + && au_test_ibusy(i, btop, bbot)) {
3626 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3629 + ii_read_unlock(i);
3631 + au_iarray_free(array, max);
3637 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3638 + const unsigned int verbose)
3641 + unsigned int sigen;
3643 + sigen = au_sigen(root->d_sb);
3644 + DiMustNoWaiters(root);
3645 + IiMustNoWaiters(d_inode(root));
3646 + di_write_unlock(root);
3647 + err = test_dentry_busy(root, bindex, sigen, verbose);
3649 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3650 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3655 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3656 + struct file **to_free, int *idx)
3659 + unsigned char matched, root;
3660 + aufs_bindex_t bindex, bbot;
3661 + struct au_fidir *fidir;
3662 + struct au_hfile *hfile;
3665 + root = IS_ROOT(file->f_path.dentry);
3668 + to_free[*idx] = file;
3674 + fidir = au_fi(file)->fi_hdir;
3675 + AuDebugOn(!fidir);
3676 + bbot = au_fbbot_dir(file);
3677 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3678 + hfile = fidir->fd_hfile + bindex;
3679 + if (!hfile->hf_file)
3682 + if (hfile->hf_br->br_id == br_id) {
3694 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3695 + struct file **to_free, int opened)
3698 + unsigned long long ull, max;
3699 + aufs_bindex_t btop;
3700 + struct file *file, **array;
3701 + struct dentry *root;
3702 + struct au_hfile *hfile;
3704 + array = au_farray_alloc(sb, &max);
3705 + err = PTR_ERR(array);
3706 + if (IS_ERR(array))
3711 + root = sb->s_root;
3712 + di_write_unlock(root);
3713 + for (ull = 0; ull < max; ull++) {
3714 + file = array[ull];
3715 + if (unlikely(!file))
3718 + /* AuDbg("%pD\n", file); */
3719 + fi_read_lock(file);
3720 + btop = au_fbtop(file);
3721 + if (!d_is_dir(file->f_path.dentry)) {
3722 + hfile = &au_fi(file)->fi_htop;
3723 + if (hfile->hf_br->br_id == br_id)
3726 + err = test_dir_busy(file, br_id, to_free, &idx);
3727 + fi_read_unlock(file);
3728 + if (unlikely(err))
3731 + di_write_lock_child(root);
3732 + au_farray_free(array, max);
3733 + AuDebugOn(idx > opened);
3739 +static void br_del_file(struct file **to_free, unsigned long long opened,
3740 + aufs_bindex_t br_id)
3742 + unsigned long long ull;
3743 + aufs_bindex_t bindex, btop, bbot, bfound;
3744 + struct file *file;
3745 + struct au_fidir *fidir;
3746 + struct au_hfile *hfile;
3748 + for (ull = 0; ull < opened; ull++) {
3749 + file = to_free[ull];
3750 + if (unlikely(!file))
3753 + /* AuDbg("%pD\n", file); */
3754 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3756 + fidir = au_fi(file)->fi_hdir;
3757 + AuDebugOn(!fidir);
3758 + fi_write_lock(file);
3759 + btop = au_fbtop(file);
3760 + bbot = au_fbbot_dir(file);
3761 + for (bindex = btop; bindex <= bbot; bindex++) {
3762 + hfile = fidir->fd_hfile + bindex;
3763 + if (!hfile->hf_file)
3766 + if (hfile->hf_br->br_id == br_id) {
3771 + AuDebugOn(bfound < 0);
3772 + au_set_h_fptr(file, bfound, NULL);
3773 + if (bfound == btop) {
3774 + for (btop++; btop <= bbot; btop++)
3775 + if (au_hf_dir(file, btop)) {
3776 + au_set_fbtop(file, btop);
3780 + fi_write_unlock(file);
3784 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3785 + const aufs_bindex_t bindex,
3786 + const aufs_bindex_t bbot)
3788 + struct au_branch **brp, **p;
3790 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3792 + brp = sbinfo->si_branch + bindex;
3793 + if (bindex < bbot)
3794 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3795 + sbinfo->si_branch[0 + bbot] = NULL;
3796 + sbinfo->si_bbot--;
3798 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3801 + sbinfo->si_branch = p;
3802 + /* harmless error */
3805 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3806 + const aufs_bindex_t bbot)
3808 + struct au_hdentry *hdp, *p;
3810 + AuRwMustWriteLock(&dinfo->di_rwsem);
3812 + hdp = au_hdentry(dinfo, bindex);
3813 + if (bindex < bbot)
3814 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3815 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3818 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3821 + dinfo->di_hdentry = p;
3822 + /* harmless error */
3825 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3826 + const aufs_bindex_t bbot)
3828 + struct au_hinode *hip, *p;
3830 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3832 + hip = au_hinode(iinfo, bindex);
3833 + if (bindex < bbot)
3834 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3835 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3838 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3841 + iinfo->ii_hinode = p;
3842 + /* harmless error */
3845 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3846 + struct au_branch *br)
3848 + aufs_bindex_t bbot;
3849 + struct au_sbinfo *sbinfo;
3850 + struct dentry *root, *h_root;
3851 + struct inode *inode, *h_inode;
3852 + struct au_hinode *hinode;
3854 + SiMustWriteLock(sb);
3856 + root = sb->s_root;
3857 + inode = d_inode(root);
3858 + sbinfo = au_sbi(sb);
3859 + bbot = sbinfo->si_bbot;
3861 + h_root = au_h_dptr(root, bindex);
3862 + hinode = au_hi(inode, bindex);
3863 + h_inode = au_igrab(hinode->hi_inode);
3866 + au_sbilist_lock();
3867 + au_br_do_del_brp(sbinfo, bindex, bbot);
3868 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3869 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3870 + au_sbilist_unlock();
3872 + /* ignore an error */
3873 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3877 + au_br_do_free(br);
3880 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3881 + unsigned long long max, void *arg)
3886 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3889 + unsigned long long opened;
3890 + unsigned int mnt_flags;
3891 + aufs_bindex_t bindex, bbot, br_id;
3892 + unsigned char do_wh, verbose;
3893 + struct au_branch *br;
3894 + struct au_wbr *wbr;
3895 + struct dentry *root;
3896 + struct file **to_free;
3901 + root = sb->s_root;
3902 + bindex = au_find_dbindex(root, del->h_path.dentry);
3905 + goto out; /* success */
3907 + pr_err("%s no such branch\n", del->pathname);
3910 + AuDbg("bindex b%d\n", bindex);
3913 + mnt_flags = au_mntflags(sb);
3914 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3915 + bbot = au_sbbot(sb);
3916 + if (unlikely(!bbot)) {
3917 + AuVerbose(verbose, "no more branches left\n");
3921 + br = au_sbr(sb, bindex);
3922 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3923 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3924 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3928 + br_id = br->br_id;
3929 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3930 + if (unlikely(opened)) {
3931 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3932 + err = PTR_ERR(to_free);
3933 + if (IS_ERR(to_free))
3936 + err = test_file_busy(sb, br_id, to_free, opened);
3937 + if (unlikely(err)) {
3938 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3944 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3946 + /* instead of WbrWhMustWriteLock(wbr) */
3947 + SiMustWriteLock(sb);
3948 + for (i = 0; i < AuBrWh_Last; i++) {
3949 + dput(wbr->wbr_wh[i]);
3950 + wbr->wbr_wh[i] = NULL;
3954 + err = test_children_busy(root, bindex, verbose);
3955 + if (unlikely(err)) {
3964 + * now we confirmed the branch is deletable.
3965 + * let's free the remaining opened dirs on the branch.
3967 + di_write_unlock(root);
3968 + br_del_file(to_free, opened, br_id);
3969 + di_write_lock_child(root);
3972 + sysaufs_brs_del(sb, bindex); /* remove successors */
3973 + dbgaufs_xino_del(br); /* remove one */
3974 + au_br_do_del(sb, bindex, br);
3975 + sysaufs_brs_add(sb, bindex); /* append successors */
3976 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3979 + au_cpup_attr_all(d_inode(root), /*force*/1);
3980 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3982 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3983 + if (au_opt_test(mnt_flags, PLINK))
3984 + au_plink_half_refresh(sb, br_id);
3986 + goto out; /* success */
3990 + rerr = au_br_init_wh(sb, br, br->br_perm);
3992 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3993 + del->pathname, rerr);
3996 + au_farray_free(to_free, opened);
4000 +/* ---------------------------------------------------------------------- */
4002 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4005 + aufs_bindex_t btop, bbot;
4006 + struct aufs_ibusy ibusy;
4007 + struct inode *inode, *h_inode;
4010 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4013 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4015 + /* VERIFY_WRITE */
4016 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4017 + if (unlikely(err)) {
4024 + si_read_lock(sb, AuLock_FLUSH);
4025 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4029 + ibusy.h_ino = 0; /* invalid */
4030 + inode = ilookup(sb, ibusy.ino);
4032 + || inode->i_ino == AUFS_ROOT_INO
4033 + || au_is_bad_inode(inode))
4036 + ii_read_lock_child(inode);
4037 + btop = au_ibtop(inode);
4038 + bbot = au_ibbot(inode);
4039 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4040 + h_inode = au_h_iptr(inode, ibusy.bindex);
4041 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4042 + ibusy.h_ino = h_inode->i_ino;
4044 + ii_read_unlock(inode);
4048 + si_read_unlock(sb);
4050 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4051 + if (unlikely(err)) {
4060 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4062 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4065 +#ifdef CONFIG_COMPAT
4066 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4068 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4072 +/* ---------------------------------------------------------------------- */
4075 + * change a branch permission
4078 +static void au_warn_ima(void)
4081 + /* since it doesn't support mark_files_ro() */
4082 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4086 +static int do_need_sigen_inc(int a, int b)
4088 + return au_br_whable(a) && !au_br_whable(b);
4091 +static int need_sigen_inc(int old, int new)
4093 + return do_need_sigen_inc(old, new)
4094 + || do_need_sigen_inc(new, old);
4097 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4100 + unsigned int mnt_flags;
4101 + unsigned long long ull, max;
4102 + aufs_bindex_t br_id;
4103 + unsigned char verbose, writer;
4104 + struct file *file, *hf, **array;
4105 + struct au_hfile *hfile;
4106 + struct inode *h_inode;
4108 + mnt_flags = au_mntflags(sb);
4109 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4111 + array = au_farray_alloc(sb, &max);
4112 + err = PTR_ERR(array);
4113 + if (IS_ERR(array))
4117 + br_id = au_sbr_id(sb, bindex);
4118 + for (ull = 0; ull < max; ull++) {
4119 + file = array[ull];
4120 + if (unlikely(!file))
4123 + /* AuDbg("%pD\n", file); */
4124 + fi_read_lock(file);
4125 + if (unlikely(au_test_mmapped(file))) {
4127 + AuVerbose(verbose, "mmapped %pD\n", file);
4129 + FiMustNoWaiters(file);
4130 + fi_read_unlock(file);
4134 + hfile = &au_fi(file)->fi_htop;
4135 + hf = hfile->hf_file;
4136 + if (!d_is_reg(file->f_path.dentry)
4137 + || !(file->f_mode & FMODE_WRITE)
4138 + || hfile->hf_br->br_id != br_id
4139 + || !(hf->f_mode & FMODE_WRITE))
4140 + array[ull] = NULL;
4146 + FiMustNoWaiters(file);
4147 + fi_read_unlock(file);
4155 + for (ull = 0; ull < max; ull++) {
4156 + file = array[ull];
4160 + /* todo: already flushed? */
4162 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4163 + * approach which resets f_mode and calls mnt_drop_write() and
4164 + * file_release_write() for each file, because the branch
4165 + * attribute in aufs world is totally different from the native
4168 + /* fi_read_lock(file); */
4169 + hfile = &au_fi(file)->fi_htop;
4170 + hf = hfile->hf_file;
4171 + /* fi_read_unlock(file); */
4172 + spin_lock(&hf->f_lock);
4173 + writer = !!(hf->f_mode & FMODE_WRITER);
4174 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4175 + spin_unlock(&hf->f_lock);
4177 + h_inode = file_inode(hf);
4178 + if (hf->f_mode & FMODE_READ)
4179 + i_readcount_inc(h_inode);
4180 + put_write_access(h_inode);
4181 + __mnt_drop_write(hf->f_path.mnt);
4186 + au_farray_free(array, max);
4192 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4196 + aufs_bindex_t bindex;
4197 + struct dentry *root;
4198 + struct au_branch *br;
4199 + struct au_br_fhsm *bf;
4201 + root = sb->s_root;
4202 + bindex = au_find_dbindex(root, mod->h_root);
4205 + return 0; /* success */
4207 + pr_err("%s no such branch\n", mod->path);
4210 + AuDbg("bindex b%d\n", bindex);
4212 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4213 + if (unlikely(err))
4216 + br = au_sbr(sb, bindex);
4217 + AuDebugOn(mod->h_root != au_br_dentry(br));
4218 + if (br->br_perm == mod->perm)
4219 + return 0; /* success */
4221 + /* pre-allocate for non-fhsm --> fhsm */
4223 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4224 + err = au_fhsm_br_alloc(br);
4225 + if (unlikely(err))
4228 + br->br_fhsm = NULL;
4231 + if (au_br_writable(br->br_perm)) {
4232 + /* remove whiteout base */
4233 + err = au_br_init_wh(sb, br, mod->perm);
4234 + if (unlikely(err))
4237 + if (!au_br_writable(mod->perm)) {
4238 + /* rw --> ro, file might be mmapped */
4239 + DiMustNoWaiters(root);
4240 + IiMustNoWaiters(d_inode(root));
4241 + di_write_unlock(root);
4242 + err = au_br_mod_files_ro(sb, bindex);
4243 + /* aufs_write_lock() calls ..._child() */
4244 + di_write_lock_child(root);
4246 + if (unlikely(err)) {
4248 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4251 + rerr = au_wbr_init(br, sb, br->br_perm);
4252 + if (unlikely(rerr)) {
4253 + AuIOErr("nested error %d (%d)\n",
4255 + br->br_perm = mod->perm;
4259 + } else if (au_br_writable(mod->perm)) {
4262 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4264 + err = au_wbr_init(br, sb, mod->perm);
4265 + if (unlikely(err)) {
4266 + au_kfree_rcu(br->br_wbr);
4267 + br->br_wbr = NULL;
4271 + if (unlikely(err))
4274 + if (au_br_fhsm(br->br_perm)) {
4275 + if (!au_br_fhsm(mod->perm)) {
4276 + /* fhsm --> non-fhsm */
4277 + au_br_fhsm_fin(br->br_fhsm);
4278 + au_kfree_rcu(br->br_fhsm);
4279 + br->br_fhsm = NULL;
4281 + } else if (au_br_fhsm(mod->perm))
4282 + /* non-fhsm --> fhsm */
4285 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4286 + br->br_perm = mod->perm;
4287 + goto out; /* success */
4290 + au_kfree_try_rcu(bf);
4296 +/* ---------------------------------------------------------------------- */
4298 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4301 + struct kstatfs kstfs;
4303 + err = vfs_statfs(&br->br_path, &kstfs);
4305 + stfs->f_blocks = kstfs.f_blocks;
4306 + stfs->f_bavail = kstfs.f_bavail;
4307 + stfs->f_files = kstfs.f_files;
4308 + stfs->f_ffree = kstfs.f_ffree;
4313 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4314 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4315 +++ linux/fs/aufs/branch.h 2022-03-21 14:49:05.719966344 +0100
4317 +/* SPDX-License-Identifier: GPL-2.0 */
4319 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4321 + * This program, aufs is free software; you can redistribute it and/or modify
4322 + * it under the terms of the GNU General Public License as published by
4323 + * the Free Software Foundation; either version 2 of the License, or
4324 + * (at your option) any later version.
4326 + * This program is distributed in the hope that it will be useful,
4327 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4329 + * GNU General Public License for more details.
4331 + * You should have received a copy of the GNU General Public License
4332 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4336 + * branch filesystems and xino for them
4339 +#ifndef __AUFS_BRANCH_H__
4340 +#define __AUFS_BRANCH_H__
4344 +#include <linux/mount.h>
4345 +#include "dirren.h"
4351 +/* ---------------------------------------------------------------------- */
4355 + struct file **xi_file;
4356 + unsigned int xi_nfile;
4362 + /* reserved for future use */
4363 + /* unsigned long *bitmap; */
4364 + wait_queue_head_t wqh;
4367 + struct mutex xi_mtx; /* protects xi_file array */
4368 + struct hlist_bl_head xi_writing;
4370 + atomic_t xi_truncating;
4372 + struct kref xi_kref;
4375 +/* File-based Hierarchical Storage Management */
4376 +struct au_br_fhsm {
4377 +#ifdef CONFIG_AUFS_FHSM
4378 + struct mutex bf_lock;
4379 + unsigned long bf_jiffy;
4380 + struct aufs_stfs bf_stfs;
4385 +/* members for writable branch only */
4386 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4388 + struct au_rwsem wbr_wh_rwsem;
4389 + struct dentry *wbr_wh[AuBrWh_Last];
4390 + atomic_t wbr_wh_running;
4391 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4392 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4393 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4396 + unsigned long long wbr_bytes;
4399 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4400 +#define AuBrDynOp (AuDyLast * 4)
4402 +#ifdef CONFIG_AUFS_HFSNOTIFY
4403 +/* support for asynchronous destruction */
4404 +struct au_br_hfsnotify {
4405 + struct fsnotify_group *hfsn_group;
4409 +/* sysfs entries */
4410 +struct au_brsysfs {
4412 + struct attribute attr;
4421 +/* protected by superblock rwsem */
4423 + struct au_xino *br_xino;
4425 + aufs_bindex_t br_id;
4428 + struct path br_path;
4429 + spinlock_t br_dykey_lock;
4430 + struct au_dykey *br_dykey[AuBrDynOp];
4431 + au_lcnt_t br_nfiles; /* opened files */
4432 + au_lcnt_t br_count; /* in-use for other */
4434 + struct au_wbr *br_wbr;
4435 + struct au_br_fhsm *br_fhsm;
4437 +#ifdef CONFIG_AUFS_HFSNOTIFY
4438 + struct au_br_hfsnotify *br_hfsn;
4441 +#ifdef CONFIG_SYSFS
4442 + /* entries under sysfs per mount-point */
4443 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4446 +#ifdef CONFIG_DEBUG_FS
4447 + struct dentry *br_dbgaufs; /* xino */
4450 + struct au_dr_br br_dirren;
4453 +/* ---------------------------------------------------------------------- */
4455 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4457 + return br->br_path.mnt;
4460 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4462 + return br->br_path.dentry;
4465 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4467 + return mnt_user_ns(br->br_path.mnt);
4470 +static inline struct super_block *au_br_sb(struct au_branch *br)
4472 + return au_br_mnt(br)->mnt_sb;
4475 +static inline int au_br_rdonly(struct au_branch *br)
4477 + return (sb_rdonly(au_br_sb(br))
4478 + || !au_br_writable(br->br_perm))
4482 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4484 +#ifdef CONFIG_AUFS_HNOTIFY
4485 + return !(brperm & AuBrPerm_RR);
4491 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4493 + int err, exec_flag;
4496 + exec_flag = oflag & __FMODE_EXEC;
4497 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4503 +static inline void au_xino_get(struct au_branch *br)
4505 + struct au_xino *xi;
4509 + kref_get(&xi->xi_kref);
4512 +static inline int au_xino_count(struct au_branch *br)
4515 + struct au_xino *xi;
4520 + v = kref_read(&xi->xi_kref);
4525 +/* ---------------------------------------------------------------------- */
4529 +void au_br_free(struct au_sbinfo *sinfo);
4530 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4532 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4534 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4535 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4536 +#ifdef CONFIG_COMPAT
4537 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4540 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4543 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4546 +static const loff_t au_loff_max = LLONG_MAX;
4548 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4549 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4551 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4552 + struct file *copy_src);
4554 + struct au_xino *xi; /* switch between xino and xigen */
4556 + struct path *base;
4557 + struct file *copy_src;
4559 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4561 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4563 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4565 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4566 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4568 +int au_xib_trunc(struct super_block *sb);
4569 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4571 +struct au_xino *au_xino_alloc(unsigned int nfile);
4572 +int au_xino_put(struct au_branch *br);
4573 +struct file *au_xino_file1(struct au_xino *xi);
4575 +struct au_opt_xino;
4576 +void au_xino_clr(struct super_block *sb);
4577 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4578 +struct file *au_xino_def(struct super_block *sb);
4579 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4580 + struct path *base);
4582 +ino_t au_xino_new_ino(struct super_block *sb);
4583 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4585 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4586 + ino_t h_ino, int idx);
4587 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4590 +int au_xino_path(struct seq_file *seq, struct file *file);
4592 +/* ---------------------------------------------------------------------- */
4594 +/* @idx is signed to accept -1 meaning the first file */
4595 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4597 + struct file *file;
4604 + if (idx < xi->xi_nfile)
4605 + file = xi->xi_file[idx];
4607 + file = au_xino_file1(xi);
4613 +/* ---------------------------------------------------------------------- */
4615 +/* Superblock to branch */
4617 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4619 + return au_sbr(sb, bindex)->br_id;
4623 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4625 + return au_br_mnt(au_sbr(sb, bindex));
4629 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4631 + return au_br_userns(au_sbr(sb, bindex));
4635 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4637 + return au_br_sb(au_sbr(sb, bindex));
4640 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4642 + return au_sbr(sb, bindex)->br_perm;
4645 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4647 + return au_br_whable(au_sbr_perm(sb, bindex));
4650 +/* ---------------------------------------------------------------------- */
4652 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4653 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4654 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4655 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4657 +#define wbr_wh_read_trylock_nested(wbr) \
4658 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4659 +#define wbr_wh_write_trylock_nested(wbr) \
4660 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4663 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4664 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4665 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4667 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4668 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4669 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4671 +/* ---------------------------------------------------------------------- */
4673 +#ifdef CONFIG_AUFS_FHSM
4674 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4676 + mutex_init(&brfhsm->bf_lock);
4677 + brfhsm->bf_jiffy = 0;
4678 + brfhsm->bf_readable = 0;
4681 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4683 + mutex_destroy(&brfhsm->bf_lock);
4686 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4687 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4690 +#endif /* __KERNEL__ */
4691 +#endif /* __AUFS_BRANCH_H__ */
4692 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4693 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4694 +++ linux/fs/aufs/conf.mk 2022-03-21 14:49:05.719966344 +0100
4696 +# SPDX-License-Identifier: GPL-2.0
4698 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4702 +AuConfStr += ${1}=${${1}}
4706 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4708 + HNOTIFY HFSNOTIFY \
4720 +$(foreach i, ${AuConfAll}, \
4721 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4723 +AuConfName = ${obj}/conf.str
4724 +${AuConfName}.tmp: FORCE
4725 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4726 +${AuConfName}: ${AuConfName}.tmp
4727 + @diff -q $< $@ > /dev/null 2>&1 || { \
4728 + echo ' GEN ' $@; \
4732 +clean-files += ${AuConfName} ${AuConfName}.tmp
4733 +${obj}/sysfs.o: ${AuConfName}
4735 +-include ${srctree}/${src}/conf_priv.mk
4736 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4737 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4738 +++ linux/fs/aufs/cpup.c 2022-03-21 14:49:05.719966344 +0100
4740 +// SPDX-License-Identifier: GPL-2.0
4742 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4744 + * This program, aufs is free software; you can redistribute it and/or modify
4745 + * it under the terms of the GNU General Public License as published by
4746 + * the Free Software Foundation; either version 2 of the License, or
4747 + * (at your option) any later version.
4749 + * This program is distributed in the hope that it will be useful,
4750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4752 + * GNU General Public License for more details.
4754 + * You should have received a copy of the GNU General Public License
4755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4759 + * copy-up functions, see wbr_policy.c for copy-down
4762 +#include <linux/fs_stack.h>
4763 +#include <linux/mm.h>
4764 +#include <linux/task_work.h>
4767 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4769 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4770 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4772 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4774 + dst->i_flags |= iflags & ~mask;
4775 + if (au_test_fs_notime(dst->i_sb))
4776 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4779 +void au_cpup_attr_timesizes(struct inode *inode)
4781 + struct inode *h_inode;
4783 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4784 + fsstack_copy_attr_times(inode, h_inode);
4785 + fsstack_copy_inode_size(inode, h_inode);
4788 +void au_cpup_attr_nlink(struct inode *inode, int force)
4790 + struct inode *h_inode;
4791 + struct super_block *sb;
4792 + aufs_bindex_t bindex, bbot;
4795 + bindex = au_ibtop(inode);
4796 + h_inode = au_h_iptr(inode, bindex);
4798 + && !S_ISDIR(h_inode->i_mode)
4799 + && au_opt_test(au_mntflags(sb), PLINK)
4800 + && au_plink_test(inode))
4804 + * 0 can happen in revalidating.
4805 + * h_inode->i_mutex may not be held here, but it is harmless since once
4806 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4808 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4809 + * the incorrect link count.
4811 + set_nlink(inode, h_inode->i_nlink);
4814 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4815 + * it may includes whplink directory.
4817 + if (S_ISDIR(h_inode->i_mode)) {
4818 + bbot = au_ibbot(inode);
4819 + for (bindex++; bindex <= bbot; bindex++) {
4820 + h_inode = au_h_iptr(inode, bindex);
4822 + au_add_nlink(inode, h_inode);
4827 +void au_cpup_attr_changeable(struct inode *inode)
4829 + struct inode *h_inode;
4831 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4832 + inode->i_mode = h_inode->i_mode;
4833 + inode->i_uid = h_inode->i_uid;
4834 + inode->i_gid = h_inode->i_gid;
4835 + au_cpup_attr_timesizes(inode);
4836 + au_cpup_attr_flags(inode, h_inode->i_flags);
4839 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4841 + struct au_iinfo *iinfo = au_ii(inode);
4843 + IiMustWriteLock(inode);
4845 + iinfo->ii_higen = h_inode->i_generation;
4846 + iinfo->ii_hsb1 = h_inode->i_sb;
4849 +void au_cpup_attr_all(struct inode *inode, int force)
4851 + struct inode *h_inode;
4853 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4854 + au_cpup_attr_changeable(inode);
4855 + if (inode->i_nlink > 0)
4856 + au_cpup_attr_nlink(inode, force);
4857 + inode->i_rdev = h_inode->i_rdev;
4858 + inode->i_blkbits = h_inode->i_blkbits;
4859 + au_cpup_igen(inode, h_inode);
4862 +/* ---------------------------------------------------------------------- */
4864 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4866 +/* keep the timestamps of the parent dir when cpup */
4867 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4868 + struct path *h_path)
4870 + struct inode *h_inode;
4872 + dt->dt_dentry = dentry;
4873 + dt->dt_h_path = *h_path;
4874 + h_inode = d_inode(h_path->dentry);
4875 + dt->dt_atime = h_inode->i_atime;
4876 + dt->dt_mtime = h_inode->i_mtime;
4880 +void au_dtime_revert(struct au_dtime *dt)
4882 + struct iattr attr;
4885 + attr.ia_atime = dt->dt_atime;
4886 + attr.ia_mtime = dt->dt_mtime;
4887 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4888 + | ATTR_ATIME | ATTR_ATIME_SET;
4890 + /* no delegation since this is a directory */
4891 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4892 + if (unlikely(err))
4893 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4896 +/* ---------------------------------------------------------------------- */
4898 +/* internal use only */
4899 +struct au_cpup_reg_attr {
4902 + unsigned int iflags; /* inode->i_flags */
4905 +static noinline_for_stack
4906 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4907 + struct au_cpup_reg_attr *h_src_attr)
4909 + int err, sbits, icex;
4910 + unsigned int mnt_flags;
4911 + unsigned char verbose;
4913 + struct path h_path;
4914 + struct inode *h_isrc, *h_idst;
4915 + struct kstat *h_st;
4916 + struct au_branch *br;
4918 + br = au_sbr(dst->d_sb, bindex);
4919 + h_path.mnt = au_br_mnt(br);
4920 + h_path.dentry = au_h_dptr(dst, bindex);
4921 + h_idst = d_inode(h_path.dentry);
4922 + h_isrc = d_inode(h_src->dentry);
4923 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4924 + | ATTR_ATIME | ATTR_MTIME
4925 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4926 + if (h_src_attr && h_src_attr->valid) {
4927 + h_st = &h_src_attr->st;
4928 + ia.ia_uid = h_st->uid;
4929 + ia.ia_gid = h_st->gid;
4930 + ia.ia_atime = h_st->atime;
4931 + ia.ia_mtime = h_st->mtime;
4932 + if (h_idst->i_mode != h_st->mode
4933 + && !S_ISLNK(h_idst->i_mode)) {
4934 + ia.ia_valid |= ATTR_MODE;
4935 + ia.ia_mode = h_st->mode;
4937 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4938 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4940 + ia.ia_uid = h_isrc->i_uid;
4941 + ia.ia_gid = h_isrc->i_gid;
4942 + ia.ia_atime = h_isrc->i_atime;
4943 + ia.ia_mtime = h_isrc->i_mtime;
4944 + if (h_idst->i_mode != h_isrc->i_mode
4945 + && !S_ISLNK(h_idst->i_mode)) {
4946 + ia.ia_valid |= ATTR_MODE;
4947 + ia.ia_mode = h_isrc->i_mode;
4949 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4950 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4952 + /* no delegation since it is just created */
4953 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4955 + /* is this nfs only? */
4956 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4957 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4958 + ia.ia_mode = h_isrc->i_mode;
4959 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4962 + icex = br->br_perm & AuBrAttr_ICEX;
4964 + mnt_flags = au_mntflags(dst->d_sb);
4965 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4966 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4972 +/* ---------------------------------------------------------------------- */
4974 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4975 + char *buf, unsigned long blksize)
4978 + size_t sz, rbytes, wbytes;
4979 + unsigned char all_zero;
4981 + struct inode *h_inode;
4982 + /* reduce stack usage */
4985 + zp = page_address(ZERO_PAGE(0));
4986 + if (unlikely(!zp))
4987 + return -ENOMEM; /* possible? */
4992 + AuDbg("len %lld\n", len);
4994 + if (len < blksize)
4998 + /* todo: signal_pending? */
4999 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5000 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5003 + if (unlikely(err < 0))
5007 + if (len >= rbytes && rbytes == blksize)
5008 + all_zero = !memcmp(buf, zp, rbytes);
5015 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5017 + /* todo: signal_pending? */
5018 + if (unlikely(err == -EAGAIN || err == -EINTR))
5020 + if (unlikely(err < 0))
5025 + if (unlikely(err < 0))
5031 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5033 + if (unlikely(res < 0))
5040 + /* the last block may be a hole */
5041 + if (!err && all_zero) {
5042 + AuLabel(last hole);
5045 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5046 + /* nfs requires this step to make last hole */
5047 + /* is this only nfs? */
5049 + /* todo: signal_pending? */
5050 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5051 + } while (err == -EAGAIN || err == -EINTR);
5058 + ia->ia_size = dst->f_pos;
5059 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5060 + ia->ia_file = dst;
5061 + h_inode = file_inode(dst);
5062 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5063 + /* no delegation since it is just created */
5064 + err = vfsub_notify_change(&dst->f_path, ia,
5065 + /*delegated*/NULL);
5066 + inode_unlock(h_inode);
5073 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5076 + unsigned long blksize;
5077 + unsigned char do_kfree;
5079 + struct super_block *h_sb;
5082 + h_sb = file_inode(dst)->i_sb;
5083 + blksize = h_sb->s_blocksize;
5084 + if (!blksize || PAGE_SIZE < blksize)
5085 + blksize = PAGE_SIZE;
5086 + AuDbg("blksize %lu\n", blksize);
5087 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5089 + buf = kmalloc(blksize, GFP_NOFS);
5091 + buf = (void *)__get_free_page(GFP_NOFS);
5092 + if (unlikely(!buf))
5095 + if (len > (1 << 22))
5096 + AuDbg("copying a large file %lld\n", (long long)len);
5100 + err = au_do_copy_file(dst, src, len, buf, blksize);
5102 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5103 + au_kfree_do_rcu(buf);
5105 + free_page((unsigned long)buf);
5111 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5114 + struct super_block *h_src_sb;
5115 + struct inode *h_src_inode;
5117 + h_src_inode = file_inode(src);
5118 + h_src_sb = h_src_inode->i_sb;
5120 + /* XFS acquires inode_lock */
5121 + if (!au_test_xfs(h_src_sb))
5122 + err = au_copy_file(dst, src, len);
5124 + inode_unlock_shared(h_src_inode);
5125 + err = au_copy_file(dst, src, len);
5126 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5132 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5136 + struct super_block *h_src_sb;
5137 + struct inode *h_src_inode;
5139 + h_src_inode = file_inode(src);
5140 + h_src_sb = h_src_inode->i_sb;
5141 + if (h_src_sb != file_inode(dst)->i_sb
5142 + || !dst->f_op->remap_file_range) {
5143 + err = au_do_copy(dst, src, len);
5147 + if (!au_test_nfs(h_src_sb)) {
5148 + inode_unlock_shared(h_src_inode);
5149 + lo = vfsub_clone_file_range(src, dst, len);
5150 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5152 + lo = vfsub_clone_file_range(src, dst, len);
5155 + goto out; /* success */
5156 + } else if (lo >= 0)
5157 + /* todo: possible? */
5158 + /* paritially succeeded */
5159 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5160 + else if (lo != -EOPNOTSUPP) {
5161 + /* older XFS has a condition in cloning */
5166 + /* the backend fs on NFS may not support cloning */
5167 + err = au_do_copy(dst, src, len);
5175 + * to support a sparse file which is opened with O_APPEND,
5176 + * we need to close the file.
5178 +static int au_cp_regular(struct au_cp_generic *cpg)
5181 + enum { SRC, DST };
5183 + aufs_bindex_t bindex;
5184 + unsigned int flags;
5185 + struct dentry *dentry;
5187 + struct file *file;
5190 + .bindex = cpg->bsrc,
5191 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5194 + .bindex = cpg->bdst,
5195 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5196 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5199 + struct au_branch *br;
5200 + struct super_block *sb, *h_src_sb;
5201 + struct inode *h_src_inode;
5202 + struct task_struct *tsk = current;
5204 + /* bsrc branch can be ro/rw. */
5205 + sb = cpg->dentry->d_sb;
5207 + for (i = 0; i < 2; i++, f++) {
5208 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5209 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5210 + /*file*/NULL, f->force_wr);
5211 + if (IS_ERR(f->file)) {
5212 + err = PTR_ERR(f->file);
5220 + /* try stopping to update while we copyup */
5221 + h_src_inode = d_inode(file[SRC].dentry);
5222 + h_src_sb = h_src_inode->i_sb;
5223 + if (!au_test_nfs(h_src_sb))
5224 + IMustLock(h_src_inode);
5225 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5227 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5228 + if (tsk->flags & PF_KTHREAD)
5229 + __fput_sync(file[DST].file);
5231 + /* it happened actually */
5232 + fput(file[DST].file);
5235 + * we have to call both since we don't know which place the file
5239 + flush_delayed_fput();
5241 + br = au_sbr(sb, file[DST].bindex);
5242 + au_lcnt_dec(&br->br_nfiles);
5245 + fput(file[SRC].file);
5246 + br = au_sbr(sb, file[SRC].bindex);
5247 + au_lcnt_dec(&br->br_nfiles);
5252 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5253 + struct au_cpup_reg_attr *h_src_attr)
5257 + struct path h_path;
5258 + struct inode *h_src_inode, *h_dst_inode;
5261 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5262 + l = i_size_read(h_src_inode);
5263 + if (cpg->len == -1 || l < cpg->len)
5266 + /* try stopping to update while we are referencing */
5267 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5268 + au_pin_hdir_unlock(cpg->pin);
5270 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5271 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5272 + h_src_attr->iflags = h_src_inode->i_flags;
5273 + if (!au_test_nfs(h_src_inode->i_sb))
5274 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5276 + inode_unlock_shared(h_src_inode);
5277 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5278 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5280 + if (unlikely(err)) {
5281 + inode_unlock_shared(h_src_inode);
5284 + h_src_attr->valid = 1;
5285 + if (!au_test_nfs(h_src_inode->i_sb)) {
5286 + err = au_cp_regular(cpg);
5287 + inode_unlock_shared(h_src_inode);
5289 + inode_unlock_shared(h_src_inode);
5290 + err = au_cp_regular(cpg);
5292 + rerr = au_pin_hdir_relock(cpg->pin);
5296 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5297 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5298 + h_dst_inode = d_inode(h_path.dentry);
5299 + spin_lock(&h_dst_inode->i_lock);
5300 + h_dst_inode->i_state |= I_LINKABLE;
5301 + spin_unlock(&h_dst_inode->i_lock);
5308 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5309 + struct inode *h_dir)
5312 + DEFINE_DELAYED_CALL(done);
5315 + sym = vfs_get_link(h_src, &done);
5316 + err = PTR_ERR(sym);
5320 + err = vfsub_symlink(h_dir, h_path, sym);
5323 + do_delayed_call(&done);
5328 + * regardless 'acl' option, reset all ACL.
5329 + * All ACL will be copied up later from the original entry on the lower branch.
5331 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5334 + struct dentry *h_dentry;
5335 + struct inode *h_inode;
5336 + struct user_namespace *h_userns;
5338 + h_userns = mnt_user_ns(h_path->mnt);
5339 + h_dentry = h_path->dentry;
5340 + h_inode = d_inode(h_dentry);
5341 + /* forget_all_cached_acls(h_inode)); */
5342 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5344 + if (err == -EOPNOTSUPP)
5347 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5353 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5354 + struct inode *h_dir, struct path *h_path)
5357 + struct inode *dir, *inode;
5358 + struct user_namespace *h_userns;
5360 + h_userns = mnt_user_ns(h_path->mnt);
5361 + err = vfsub_removexattr(h_userns, h_path->dentry,
5362 + XATTR_NAME_POSIX_ACL_DEFAULT);
5364 + if (err == -EOPNOTSUPP)
5366 + if (unlikely(err))
5370 + * strange behaviour from the users view,
5371 + * particularly setattr case
5373 + dir = d_inode(dst_parent);
5374 + if (au_ibtop(dir) == cpg->bdst)
5375 + au_cpup_attr_nlink(dir, /*force*/1);
5376 + inode = d_inode(cpg->dentry);
5377 + au_cpup_attr_nlink(inode, /*force*/1);
5383 +static noinline_for_stack
5384 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5385 + struct au_cpup_reg_attr *h_src_attr)
5389 + unsigned int mnt_flags;
5390 + unsigned char isdir, isreg, force;
5391 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5392 + struct au_dtime dt;
5393 + struct path h_path;
5394 + struct dentry *h_src, *h_dst, *h_parent;
5395 + struct inode *h_inode, *h_dir;
5396 + struct super_block *sb;
5398 + /* bsrc branch can be ro/rw. */
5399 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5400 + h_inode = d_inode(h_src);
5401 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5403 + /* try stopping to be referenced while we are creating */
5404 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5405 + if (au_ftest_cpup(cpg->flags, RENAME))
5406 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5407 + AUFS_WH_PFX_LEN));
5408 + h_parent = h_dst->d_parent; /* dir inode is locked */
5409 + h_dir = d_inode(h_parent);
5411 + AuDebugOn(h_parent != h_dst->d_parent);
5413 + sb = cpg->dentry->d_sb;
5414 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5416 + h_path.dentry = h_parent;
5417 + au_dtime_store(&dt, dst_parent, &h_path);
5419 + h_path.dentry = h_dst;
5423 + mode = h_inode->i_mode;
5424 + switch (mode & S_IFMT) {
5427 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5429 + err = au_do_cpup_regular(cpg, h_src_attr);
5433 + err = vfsub_mkdir(h_dir, &h_path, mode);
5435 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5438 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5442 + AuDebugOn(!capable(CAP_MKNOD));
5446 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5449 + AuIOErr("Unknown inode type 0%o\n", mode);
5453 + err = au_reset_acl(h_dir, &h_path, mode);
5455 + mnt_flags = au_mntflags(sb);
5456 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5458 + && au_opt_test(mnt_flags, XINO)
5459 + && (h_inode->i_nlink == 1
5460 + || (h_inode->i_state & I_LINKABLE))
5461 + /* todo: unnecessary? */
5462 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5463 + && cpg->bdst < cpg->bsrc
5464 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5465 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5466 + /* ignore this error */
5471 + force = !!cpg->len;
5472 + if (cpg->len == -1)
5473 + force = !!i_size_read(h_inode);
5475 + au_fhsm_wrote(sb, cpg->bdst, force);
5479 + au_dtime_revert(&dt);
5483 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5486 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5487 + struct path h_ppath;
5488 + struct inode *h_dir;
5489 + aufs_bindex_t bdst;
5491 + dentry = cpg->dentry;
5493 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5494 + h_dentry = au_h_dptr(dentry, bdst);
5495 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5497 + au_set_h_dptr(dentry, bdst, NULL);
5498 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5500 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5501 + au_set_h_dptr(dentry, bdst, h_dentry);
5504 + parent = dget_parent(dentry);
5505 + h_ppath.dentry = au_h_dptr(parent, bdst);
5507 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5508 + if (IS_ERR(h_path->dentry))
5509 + err = PTR_ERR(h_path->dentry);
5511 + if (unlikely(err))
5514 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5515 + h_dir = d_inode(h_parent);
5517 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5518 + /* no delegation since it is just created */
5519 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5521 + dput(h_path->dentry);
5528 + * copyup the @dentry from @bsrc to @bdst.
5529 + * the caller must set the both of lower dentries.
5530 + * @len is for truncating when it is -1 copyup the entire file.
5531 + * in link/rename cases, @dst_parent may be different from the real one.
5532 + * basic->bsrc can be larger than basic->bdst.
5533 + * aufs doesn't touch the credential so
5534 + * security_inode_copy_up{,_xattr}() are unnecessary.
5536 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5539 + aufs_bindex_t old_ibtop;
5540 + unsigned char isdir, plink;
5541 + struct dentry *h_src, *h_dst, *h_parent;
5542 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5543 + struct super_block *sb;
5544 + struct au_branch *br;
5545 + struct path h_src_path;
5546 + /* to reduce stack size */
5548 + struct au_dtime dt;
5549 + struct path h_path;
5550 + struct au_cpup_reg_attr h_src_attr;
5554 + a = kmalloc(sizeof(*a), GFP_NOFS);
5557 + a->h_src_attr.valid = 0;
5559 + sb = cpg->dentry->d_sb;
5560 + br = au_sbr(sb, cpg->bdst);
5561 + a->h_path.mnt = au_br_mnt(br);
5562 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5563 + h_parent = h_dst->d_parent; /* dir inode is locked */
5564 + h_dir = d_inode(h_parent);
5567 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5568 + inode = d_inode(cpg->dentry);
5571 + dst_parent = dget_parent(cpg->dentry);
5575 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5576 + dst_inode = au_h_iptr(inode, cpg->bdst);
5578 + if (unlikely(!plink)) {
5580 + AuIOErr("hi%lu(i%lu) exists on b%d "
5581 + "but plink is disabled\n",
5582 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5586 + if (dst_inode->i_nlink) {
5587 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5589 + h_src = au_plink_lkup(inode, cpg->bdst);
5590 + err = PTR_ERR(h_src);
5591 + if (IS_ERR(h_src))
5593 + if (unlikely(d_is_negative(h_src))) {
5595 + AuIOErr("i%lu exists on b%d "
5596 + "but not pseudo-linked\n",
5597 + inode->i_ino, cpg->bdst);
5603 + a->h_path.dentry = h_parent;
5604 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5607 + a->h_path.dentry = h_dst;
5609 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5610 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5611 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5613 + au_dtime_revert(&a->dt);
5614 + if (unlikely(err == -EWOULDBLOCK)) {
5615 + pr_warn("cannot retry for NFSv4 delegation"
5616 + " for an internal link\n");
5622 + /* todo: cpup_wh_file? */
5624 + au_update_ibrange(inode, /*do_put_zero*/1);
5627 + isdir = S_ISDIR(inode->i_mode);
5628 + old_ibtop = au_ibtop(inode);
5629 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5630 + if (unlikely(err))
5632 + dst_inode = d_inode(h_dst);
5633 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5634 + /* todo: necessary? */
5635 + /* au_pin_hdir_unlock(cpg->pin); */
5637 + h_src_path.dentry = h_src;
5638 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5639 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5640 + if (unlikely(err)) {
5641 + /* todo: necessary? */
5642 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5643 + inode_unlock(dst_inode);
5647 + if (cpg->bdst < old_ibtop) {
5648 + if (S_ISREG(inode->i_mode)) {
5649 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5650 + if (unlikely(err)) {
5651 + /* ignore an error */
5652 + /* au_pin_hdir_relock(cpg->pin); */
5653 + inode_unlock(dst_inode);
5657 + au_set_ibtop(inode, cpg->bdst);
5659 + au_set_ibbot(inode, cpg->bdst);
5660 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5661 + au_hi_flags(inode, isdir));
5663 + /* todo: necessary? */
5664 + /* err = au_pin_hdir_relock(cpg->pin); */
5665 + inode_unlock(dst_inode);
5666 + if (unlikely(err))
5669 + src_inode = d_inode(h_src);
5671 + && (src_inode->i_nlink > 1
5672 + || src_inode->i_state & I_LINKABLE)
5674 + au_plink_append(inode, cpg->bdst, h_dst);
5676 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5677 + a->h_path.dentry = h_dst;
5678 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5681 + goto out_parent; /* success */
5685 + a->h_path.dentry = h_parent;
5686 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5687 + a->h_path.dentry = h_dst;
5689 + if (d_is_positive(h_dst)) {
5691 + /* no delegation since it is just created */
5692 + rerr = vfsub_unlink(h_dir, &a->h_path,
5693 + /*delegated*/NULL, /*force*/0);
5695 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5697 + au_dtime_revert(&a->dt);
5699 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5709 +#if 0 /* reserved */
5710 +struct au_cpup_single_args {
5712 + struct au_cp_generic *cpg;
5713 + struct dentry *dst_parent;
5716 +static void au_call_cpup_single(void *args)
5718 + struct au_cpup_single_args *a = args;
5720 + au_pin_hdir_acquire_nest(a->cpg->pin);
5721 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5722 + au_pin_hdir_release(a->cpg->pin);
5727 + * prevent SIGXFSZ in copy-up.
5728 + * testing CAP_MKNOD is for generic fs,
5729 + * but CAP_FSETID is for xfs only, currently.
5731 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5734 + struct super_block *sb;
5735 + struct inode *h_dir;
5738 + sb = au_pinned_parent(pin)->d_sb;
5739 + if (!au_wkq_test()
5740 + && (!au_sbi(sb)->si_plink_maint_pid
5741 + || au_plink_maint(sb, AuLock_NOPLM))) {
5742 + switch (mode & S_IFMT) {
5744 + /* no condition about RLIMIT_FSIZE and the file size */
5749 + do_sio = !capable(CAP_MKNOD);
5753 + do_sio = ((mode & (S_ISUID | S_ISGID))
5754 + && !capable(CAP_FSETID));
5755 + /* this workaround may be removed in the future */
5757 + h_dir = au_pinned_h_dir(pin);
5758 + do_sio = h_dir->i_mode & S_ISVTX;
5765 +#if 0 /* reserved */
5766 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5769 + struct dentry *h_dentry;
5771 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5772 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5773 + err = au_cpup_single(cpg, dst_parent);
5775 + struct au_cpup_single_args args = {
5778 + .dst_parent = dst_parent
5780 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5781 + if (unlikely(wkq_err))
5790 + * copyup the @dentry from the first active lower branch to @bdst,
5791 + * using au_cpup_single().
5793 +static int au_cpup_simple(struct au_cp_generic *cpg)
5796 + unsigned int flags_orig;
5797 + struct dentry *dentry;
5799 + AuDebugOn(cpg->bsrc < 0);
5801 + dentry = cpg->dentry;
5802 + DiMustWriteLock(dentry);
5804 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5806 + flags_orig = cpg->flags;
5807 + au_fset_cpup(cpg->flags, RENAME);
5808 + err = au_cpup_single(cpg, NULL);
5809 + cpg->flags = flags_orig;
5811 + return 0; /* success */
5814 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5815 + au_set_dbtop(dentry, cpg->bsrc);
5821 +struct au_cpup_simple_args {
5823 + struct au_cp_generic *cpg;
5826 +static void au_call_cpup_simple(void *args)
5828 + struct au_cpup_simple_args *a = args;
5830 + au_pin_hdir_acquire_nest(a->cpg->pin);
5831 + *a->errp = au_cpup_simple(a->cpg);
5832 + au_pin_hdir_release(a->cpg->pin);
5835 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5838 + struct dentry *dentry, *parent;
5839 + struct file *h_file;
5840 + struct inode *h_dir;
5841 + struct user_namespace *h_userns;
5843 + dentry = cpg->dentry;
5845 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5846 + AuDebugOn(cpg->bsrc < 0);
5847 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5848 + err = PTR_ERR(h_file);
5849 + if (IS_ERR(h_file))
5853 + parent = dget_parent(dentry);
5854 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5855 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5856 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5857 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5858 + err = au_cpup_simple(cpg);
5860 + struct au_cpup_simple_args args = {
5864 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5865 + if (unlikely(wkq_err))
5871 + au_h_open_post(dentry, cpg->bsrc, h_file);
5877 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5879 + aufs_bindex_t bsrc, bbot;
5880 + struct dentry *dentry, *h_dentry;
5882 + if (cpg->bsrc < 0) {
5883 + dentry = cpg->dentry;
5884 + bbot = au_dbbot(dentry);
5885 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5886 + h_dentry = au_h_dptr(dentry, bsrc);
5888 + AuDebugOn(d_is_negative(h_dentry));
5892 + AuDebugOn(bsrc > bbot);
5895 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5896 + return au_do_sio_cpup_simple(cpg);
5899 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5901 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5902 + return au_do_sio_cpup_simple(cpg);
5905 +/* ---------------------------------------------------------------------- */
5908 + * copyup the deleted file for writing.
5910 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5911 + struct file *file)
5914 + unsigned int flags_orig;
5915 + aufs_bindex_t bsrc_orig;
5916 + struct au_dinfo *dinfo;
5918 + struct au_hdentry *hd;
5919 + struct dentry *h_dentry;
5922 + dinfo = au_di(cpg->dentry);
5923 + AuRwMustWriteLock(&dinfo->di_rwsem);
5925 + bsrc_orig = cpg->bsrc;
5926 + cpg->bsrc = dinfo->di_btop;
5927 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5928 + hdst.h_dentry = hdst.hd->hd_dentry;
5929 + hdst.hd->hd_dentry = wh_dentry;
5930 + dinfo->di_btop = cpg->bdst;
5932 + hsrc.h_dentry = NULL;
5934 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5935 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5936 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5938 + flags_orig = cpg->flags;
5939 + cpg->flags = !AuCpup_DTIME;
5940 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5941 + cpg->flags = flags_orig;
5944 + err = au_reopen_nondir(file);
5945 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5947 + hdst.hd->hd_dentry = hdst.h_dentry;
5948 + dinfo->di_btop = cpg->bsrc;
5949 + cpg->bsrc = bsrc_orig;
5954 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5957 + aufs_bindex_t bdst;
5958 + struct au_dtime dt;
5959 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5960 + struct au_branch *br;
5961 + struct path h_path;
5963 + dentry = cpg->dentry;
5965 + br = au_sbr(dentry->d_sb, bdst);
5966 + parent = dget_parent(dentry);
5967 + h_parent = au_h_dptr(parent, bdst);
5968 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5969 + err = PTR_ERR(wh_dentry);
5970 + if (IS_ERR(wh_dentry))
5973 + h_path.dentry = h_parent;
5974 + h_path.mnt = au_br_mnt(br);
5975 + au_dtime_store(&dt, parent, &h_path);
5976 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5977 + if (unlikely(err))
5981 + h_path.dentry = wh_dentry;
5982 + if (!d_is_dir(wh_dentry)) {
5983 + /* no delegation since it is just created */
5984 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5985 + /*delegated*/NULL, /*force*/0);
5987 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5988 + if (unlikely(err)) {
5989 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5993 + au_dtime_revert(&dt);
5994 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6003 +struct au_cpup_wh_args {
6005 + struct au_cp_generic *cpg;
6006 + struct file *file;
6009 +static void au_call_cpup_wh(void *args)
6011 + struct au_cpup_wh_args *a = args;
6013 + au_pin_hdir_acquire_nest(a->cpg->pin);
6014 + *a->errp = au_cpup_wh(a->cpg, a->file);
6015 + au_pin_hdir_release(a->cpg->pin);
6018 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6021 + aufs_bindex_t bdst;
6022 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6023 + struct inode *dir, *h_dir, *h_tmpdir;
6024 + struct au_wbr *wbr;
6025 + struct au_pin wh_pin, *pin_orig;
6026 + struct user_namespace *h_userns;
6028 + dentry = cpg->dentry;
6030 + parent = dget_parent(dentry);
6031 + dir = d_inode(parent);
6034 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6037 + if (!h_dir->i_nlink) {
6038 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6039 + h_orph = wbr->wbr_orph;
6041 + h_parent = dget(au_h_dptr(parent, bdst));
6042 + au_set_h_dptr(parent, bdst, dget(h_orph));
6043 + h_tmpdir = d_inode(h_orph);
6044 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6046 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6047 + /* todo: au_h_open_pre()? */
6049 + pin_orig = cpg->pin;
6050 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6051 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6052 + cpg->pin = &wh_pin;
6055 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6056 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6057 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6058 + err = au_cpup_wh(cpg, file);
6060 + struct au_cpup_wh_args args = {
6065 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6066 + if (unlikely(wkq_err))
6071 + inode_unlock(h_tmpdir);
6072 + /* todo: au_h_open_post()? */
6073 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6074 + au_set_h_dptr(parent, bdst, h_parent);
6075 + AuDebugOn(!pin_orig);
6076 + cpg->pin = pin_orig;
6084 +/* ---------------------------------------------------------------------- */
6087 + * generic routine for both of copy-up and copy-down.
6089 +/* cf. revalidate function in file.c */
6090 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6091 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6092 + struct au_pin *pin,
6093 + struct dentry *h_parent, void *arg),
6097 + struct au_pin pin;
6098 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6101 + parent = dget_parent(dentry);
6102 + if (IS_ROOT(parent))
6105 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6106 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6108 + /* do not use au_dpage */
6109 + real_parent = parent;
6112 + parent = dget_parent(dentry);
6113 + h_parent = au_h_dptr(parent, bdst);
6115 + goto out; /* success */
6117 + /* find top dir which is necessary to cpup */
6121 + parent = dget_parent(d);
6122 + di_read_lock_parent3(parent, !AuLock_IR);
6123 + h_parent = au_h_dptr(parent, bdst);
6124 + di_read_unlock(parent, !AuLock_IR);
6125 + } while (!h_parent);
6127 + if (d != real_parent)
6128 + di_write_lock_child3(d);
6130 + /* somebody else might create while we were sleeping */
6131 + h_dentry = au_h_dptr(d, bdst);
6132 + if (!h_dentry || d_is_negative(h_dentry)) {
6134 + au_update_dbtop(d);
6136 + au_pin_set_dentry(&pin, d);
6137 + err = au_do_pin(&pin);
6139 + err = cp(d, bdst, &pin, h_parent, arg);
6144 + if (d != real_parent)
6145 + di_write_unlock(d);
6146 + if (unlikely(err))
6155 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6156 + struct au_pin *pin,
6157 + struct dentry *h_parent __maybe_unused,
6158 + void *arg __maybe_unused)
6160 + struct au_cp_generic cpg = {
6166 + .flags = AuCpup_DTIME
6168 + return au_sio_cpup_simple(&cpg);
6171 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6173 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6176 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6179 + struct dentry *parent;
6180 + struct inode *dir;
6182 + parent = dget_parent(dentry);
6183 + dir = d_inode(parent);
6185 + if (au_h_iptr(dir, bdst))
6188 + di_read_unlock(parent, AuLock_IR);
6189 + di_write_lock_parent(parent);
6190 + /* someone else might change our inode while we were sleeping */
6191 + if (!au_h_iptr(dir, bdst))
6192 + err = au_cpup_dirs(dentry, bdst);
6193 + di_downgrade_lock(parent, AuLock_IR);
6199 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6200 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6201 +++ linux/fs/aufs/cpup.h 2022-03-21 14:49:05.719966344 +0100
6203 +/* SPDX-License-Identifier: GPL-2.0 */
6205 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6207 + * This program, aufs is free software; you can redistribute it and/or modify
6208 + * it under the terms of the GNU General Public License as published by
6209 + * the Free Software Foundation; either version 2 of the License, or
6210 + * (at your option) any later version.
6212 + * This program is distributed in the hope that it will be useful,
6213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6215 + * GNU General Public License for more details.
6217 + * You should have received a copy of the GNU General Public License
6218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6222 + * copy-up/down functions
6225 +#ifndef __AUFS_CPUP_H__
6226 +#define __AUFS_CPUP_H__
6230 +#include <linux/path.h>
6236 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6237 +void au_cpup_attr_timesizes(struct inode *inode);
6238 +void au_cpup_attr_nlink(struct inode *inode, int force);
6239 +void au_cpup_attr_changeable(struct inode *inode);
6240 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6241 +void au_cpup_attr_all(struct inode *inode, int force);
6243 +/* ---------------------------------------------------------------------- */
6245 +struct au_cp_generic {
6246 + struct dentry *dentry;
6247 + aufs_bindex_t bdst, bsrc;
6249 + struct au_pin *pin;
6250 + unsigned int flags;
6254 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6255 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6257 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6258 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6260 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6262 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6263 + the branch is marked as RO */
6265 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6266 +#undef AuCpup_HOPEN
6267 +#define AuCpup_HOPEN 0
6270 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6271 +#define au_fset_cpup(flags, name) \
6272 + do { (flags) |= AuCpup_##name; } while (0)
6273 +#define au_fclr_cpup(flags, name) \
6274 + do { (flags) &= ~AuCpup_##name; } while (0)
6276 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6277 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6278 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6279 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6281 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6282 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6283 + struct au_pin *pin,
6284 + struct dentry *h_parent, void *arg),
6286 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6287 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6289 +/* ---------------------------------------------------------------------- */
6291 +/* keep timestamps when copyup */
6293 + struct dentry *dt_dentry;
6294 + struct path dt_h_path;
6295 + struct timespec64 dt_atime, dt_mtime;
6297 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6298 + struct path *h_path);
6299 +void au_dtime_revert(struct au_dtime *dt);
6301 +#endif /* __KERNEL__ */
6302 +#endif /* __AUFS_CPUP_H__ */
6303 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6304 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6305 +++ linux/fs/aufs/dbgaufs.c 2022-03-21 14:49:05.719966344 +0100
6307 +// SPDX-License-Identifier: GPL-2.0
6309 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6311 + * This program, aufs is free software; you can redistribute it and/or modify
6312 + * it under the terms of the GNU General Public License as published by
6313 + * the Free Software Foundation; either version 2 of the License, or
6314 + * (at your option) any later version.
6316 + * This program is distributed in the hope that it will be useful,
6317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6319 + * GNU General Public License for more details.
6321 + * You should have received a copy of the GNU General Public License
6322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6326 + * debugfs interface
6329 +#include <linux/debugfs.h>
6332 +#ifndef CONFIG_SYSFS
6333 +#error DEBUG_FS depends upon SYSFS
6336 +static struct dentry *dbgaufs;
6337 +static const mode_t dbgaufs_mode = 0444;
6339 +/* 20 is max digits length of ulong 64 */
6340 +struct dbgaufs_arg {
6346 + * common function for all XINO files
6348 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6349 + struct file *file)
6353 + p = file->private_data;
6355 + /* this is struct dbgaufs_arg */
6356 + AuDebugOn(!au_kfree_sz_test(p));
6357 + au_kfree_do_rcu(p);
6362 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6367 + struct dbgaufs_arg *p;
6370 + p = kmalloc(sizeof(*p), GFP_NOFS);
6376 + file->private_data = p;
6380 + err = vfsub_getattr(&xf->f_path, &st);
6384 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6385 + cnt, st.blocks, st.blksize,
6386 + (long long)st.size);
6388 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6389 + st.blocks, st.blksize,
6390 + (long long)st.size);
6391 + AuDebugOn(p->n >= sizeof(p->a));
6393 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6401 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6402 + size_t count, loff_t *ppos)
6404 + struct dbgaufs_arg *p;
6406 + p = file->private_data;
6407 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6410 +/* ---------------------------------------------------------------------- */
6412 +struct dbgaufs_plink_arg {
6417 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6418 + struct file *file)
6420 + free_page((unsigned long)file->private_data);
6424 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6426 + int err, i, limit;
6427 + unsigned long n, sum;
6428 + struct dbgaufs_plink_arg *p;
6429 + struct au_sbinfo *sbinfo;
6430 + struct super_block *sb;
6431 + struct hlist_bl_head *hbl;
6434 + p = (void *)get_zeroed_page(GFP_NOFS);
6439 + sbinfo = inode->i_private;
6440 + sb = sbinfo->si_sb;
6441 + si_noflush_read_lock(sb);
6442 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6443 + limit = PAGE_SIZE - sizeof(p->n);
6445 + /* the number of buckets */
6446 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6451 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6453 + n = au_hbl_count(hbl);
6456 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6459 + if (unlikely(limit <= 0))
6462 + p->a[p->n - 1] = '\n';
6464 + /* the sum of plinks */
6465 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6468 + if (unlikely(limit <= 0))
6471 +#define str "1\n0\n0\n"
6472 + p->n = sizeof(str) - 1;
6473 + strcpy(p->a, str);
6476 + si_read_unlock(sb);
6479 + file->private_data = p;
6480 + goto out; /* success */
6483 + free_page((unsigned long)p);
6488 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6489 + size_t count, loff_t *ppos)
6491 + struct dbgaufs_plink_arg *p;
6493 + p = file->private_data;
6494 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6497 +static const struct file_operations dbgaufs_plink_fop = {
6498 + .owner = THIS_MODULE,
6499 + .open = dbgaufs_plink_open,
6500 + .release = dbgaufs_plink_release,
6501 + .read = dbgaufs_plink_read
6504 +/* ---------------------------------------------------------------------- */
6506 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6509 + struct au_sbinfo *sbinfo;
6510 + struct super_block *sb;
6512 + sbinfo = inode->i_private;
6513 + sb = sbinfo->si_sb;
6514 + si_noflush_read_lock(sb);
6515 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6516 + si_read_unlock(sb);
6520 +static const struct file_operations dbgaufs_xib_fop = {
6521 + .owner = THIS_MODULE,
6522 + .open = dbgaufs_xib_open,
6523 + .release = dbgaufs_xi_release,
6524 + .read = dbgaufs_xi_read
6527 +/* ---------------------------------------------------------------------- */
6529 +#define DbgaufsXi_PREFIX "xi"
6531 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6535 + aufs_bindex_t bindex;
6536 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6537 + struct au_sbinfo *sbinfo;
6538 + struct super_block *sb;
6539 + struct au_xino *xi;
6541 + struct qstr *name;
6542 + struct au_branch *br;
6545 + name = &file->f_path.dentry->d_name;
6546 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6547 + || memcmp(name->name, DbgaufsXi_PREFIX,
6548 + sizeof(DbgaufsXi_PREFIX) - 1)))
6551 + AuDebugOn(name->len >= sizeof(a));
6552 + memcpy(a, name->name, name->len);
6553 + a[name->len] = '\0';
6554 + p = strchr(a, '-');
6557 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6558 + if (unlikely(err))
6563 + err = kstrtol(p + 1, 10, &l);
6564 + if (unlikely(err))
6570 + sbinfo = inode->i_private;
6571 + sb = sbinfo->si_sb;
6572 + si_noflush_read_lock(sb);
6573 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6575 + br = au_sbr(sb, bindex);
6577 + if (unlikely(idx >= xi->xi_nfile))
6579 + xf = au_xino_file(xi, idx);
6581 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6582 + au_xino_count(br));
6585 + si_read_unlock(sb);
6591 +static const struct file_operations dbgaufs_xino_fop = {
6592 + .owner = THIS_MODULE,
6593 + .open = dbgaufs_xino_open,
6594 + .release = dbgaufs_xi_release,
6595 + .read = dbgaufs_xi_read
6598 +void dbgaufs_xino_del(struct au_branch *br)
6600 + struct dentry *dbgaufs;
6602 + dbgaufs = br->br_dbgaufs;
6606 + br->br_dbgaufs = NULL;
6607 + /* debugfs acquires the parent i_mutex */
6609 + debugfs_remove(dbgaufs);
6613 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6615 + aufs_bindex_t bbot;
6616 + struct au_branch *br;
6618 + if (!au_sbi(sb)->si_dbgaufs)
6621 + bbot = au_sbbot(sb);
6622 + for (; bindex <= bbot; bindex++) {
6623 + br = au_sbr(sb, bindex);
6624 + dbgaufs_xino_del(br);
6628 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6629 + unsigned int idx, struct dentry *parent,
6630 + struct au_sbinfo *sbinfo)
6632 + struct au_branch *br;
6634 + /* "xi" bindex(5) "-" idx(2) NULL */
6635 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6638 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6640 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6642 + br = au_sbr(sb, bindex);
6643 + if (br->br_dbgaufs) {
6644 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6646 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6647 + /* debugfs acquires the parent i_mutex */
6649 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6653 + pr_warn("failed renaming %pd/%s, ignored.\n",
6658 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6659 + sbinfo, &dbgaufs_xino_fop);
6661 + if (unlikely(!br->br_dbgaufs))
6662 + pr_warn("failed creating %pd/%s, ignored.\n",
6667 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6668 + struct dentry *parent, struct au_sbinfo *sbinfo)
6670 + struct au_branch *br;
6671 + struct au_xino *xi;
6674 + br = au_sbr(sb, bindex);
6676 + for (u = 0; u < xi->xi_nfile; u++)
6677 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6680 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6682 + struct au_sbinfo *sbinfo;
6683 + struct dentry *parent;
6684 + aufs_bindex_t bbot;
6686 + if (!au_opt_test(au_mntflags(sb), XINO))
6689 + sbinfo = au_sbi(sb);
6690 + parent = sbinfo->si_dbgaufs;
6694 + bbot = au_sbbot(sb);
6696 + for (; bindex <= bbot; bindex++)
6697 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6699 + for (; bbot >= bindex; bbot--)
6700 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6703 +/* ---------------------------------------------------------------------- */
6705 +#ifdef CONFIG_AUFS_EXPORT
6706 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6709 + struct au_sbinfo *sbinfo;
6710 + struct super_block *sb;
6712 + sbinfo = inode->i_private;
6713 + sb = sbinfo->si_sb;
6714 + si_noflush_read_lock(sb);
6715 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6716 + si_read_unlock(sb);
6720 +static const struct file_operations dbgaufs_xigen_fop = {
6721 + .owner = THIS_MODULE,
6722 + .open = dbgaufs_xigen_open,
6723 + .release = dbgaufs_xi_release,
6724 + .read = dbgaufs_xi_read
6727 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6732 + * This function is a dynamic '__init' function actually,
6733 + * so the tiny check for si_rwsem is unnecessary.
6735 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6738 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6739 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6740 + &dbgaufs_xigen_fop);
6741 + if (sbinfo->si_dbgaufs_xigen)
6747 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6751 +#endif /* CONFIG_AUFS_EXPORT */
6753 +/* ---------------------------------------------------------------------- */
6755 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6758 + * This function is a dynamic '__fin' function actually,
6759 + * so the tiny check for si_rwsem is unnecessary.
6761 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6763 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6764 + sbinfo->si_dbgaufs = NULL;
6767 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6770 + char name[SysaufsSiNameLen];
6773 + * This function is a dynamic '__init' function actually,
6774 + * so the tiny check for si_rwsem is unnecessary.
6776 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6780 + AuErr1("/debug/aufs is uninitialized\n");
6785 + sysaufs_name(sbinfo, name);
6786 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6787 + if (unlikely(!sbinfo->si_dbgaufs))
6790 + /* regardless plink/noplink option */
6791 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6792 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6793 + &dbgaufs_plink_fop);
6794 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6797 + /* regardless xino/noxino option */
6798 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6799 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6800 + &dbgaufs_xib_fop);
6801 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6804 + err = dbgaufs_xigen_init(sbinfo);
6806 + goto out; /* success */
6809 + dbgaufs_si_fin(sbinfo);
6811 + if (unlikely(err))
6812 + pr_err("debugfs/aufs failed\n");
6816 +/* ---------------------------------------------------------------------- */
6818 +void dbgaufs_fin(void)
6820 + debugfs_remove(dbgaufs);
6823 +int __init dbgaufs_init(void)
6828 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6833 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6834 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6835 +++ linux/fs/aufs/dbgaufs.h 2022-03-21 14:49:05.719966344 +0100
6837 +/* SPDX-License-Identifier: GPL-2.0 */
6839 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6841 + * This program, aufs is free software; you can redistribute it and/or modify
6842 + * it under the terms of the GNU General Public License as published by
6843 + * the Free Software Foundation; either version 2 of the License, or
6844 + * (at your option) any later version.
6846 + * This program is distributed in the hope that it will be useful,
6847 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6848 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6849 + * GNU General Public License for more details.
6851 + * You should have received a copy of the GNU General Public License
6852 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6856 + * debugfs interface
6859 +#ifndef __DBGAUFS_H__
6860 +#define __DBGAUFS_H__
6864 +struct super_block;
6868 +#ifdef CONFIG_DEBUG_FS
6870 +void dbgaufs_xino_del(struct au_branch *br);
6871 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6872 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6873 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6874 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6875 +void dbgaufs_fin(void);
6876 +int __init dbgaufs_init(void);
6878 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6879 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6880 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6882 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6883 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6884 +AuStubVoid(dbgaufs_fin, void)
6885 +AuStubInt0(__init dbgaufs_init, void)
6886 +#endif /* CONFIG_DEBUG_FS */
6888 +#endif /* __KERNEL__ */
6889 +#endif /* __DBGAUFS_H__ */
6890 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6891 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6892 +++ linux/fs/aufs/dcsub.c 2022-03-21 14:49:05.719966344 +0100
6894 +// SPDX-License-Identifier: GPL-2.0
6896 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6898 + * This program, aufs is free software; you can redistribute it and/or modify
6899 + * it under the terms of the GNU General Public License as published by
6900 + * the Free Software Foundation; either version 2 of the License, or
6901 + * (at your option) any later version.
6903 + * This program is distributed in the hope that it will be useful,
6904 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6905 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6906 + * GNU General Public License for more details.
6908 + * You should have received a copy of the GNU General Public License
6909 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6913 + * sub-routines for dentry cache
6918 +static void au_dpage_free(struct au_dpage *dpage)
6921 + struct dentry **p;
6923 + p = dpage->dentries;
6924 + for (i = 0; i < dpage->ndentry; i++)
6926 + free_page((unsigned long)dpage->dentries);
6929 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6935 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6936 + if (unlikely(!dpages->dpages))
6939 + p = (void *)__get_free_page(gfp);
6943 + dpages->dpages[0].ndentry = 0;
6944 + dpages->dpages[0].dentries = p;
6945 + dpages->ndpage = 1;
6946 + return 0; /* success */
6949 + au_kfree_try_rcu(dpages->dpages);
6954 +void au_dpages_free(struct au_dcsub_pages *dpages)
6957 + struct au_dpage *p;
6959 + p = dpages->dpages;
6960 + for (i = 0; i < dpages->ndpage; i++)
6961 + au_dpage_free(p++);
6962 + au_kfree_try_rcu(dpages->dpages);
6965 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6966 + struct dentry *dentry, gfp_t gfp)
6969 + struct au_dpage *dpage;
6972 + dpage = dpages->dpages + dpages->ndpage - 1;
6973 + sz = PAGE_SIZE / sizeof(dentry);
6974 + if (unlikely(dpage->ndentry >= sz)) {
6975 + AuLabel(new dpage);
6977 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6978 + p = au_kzrealloc(dpages->dpages, sz,
6979 + sz + sizeof(*dpages->dpages), gfp,
6984 + dpages->dpages = p;
6985 + dpage = dpages->dpages + dpages->ndpage;
6986 + p = (void *)__get_free_page(gfp);
6990 + dpage->ndentry = 0;
6991 + dpage->dentries = p;
6995 + AuDebugOn(au_dcount(dentry) <= 0);
6996 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6997 + return 0; /* success */
7003 +/* todo: BAD approach */
7004 +/* copied from linux/fs/dcache.c */
7012 +extern void d_walk(struct dentry *parent, void *data,
7013 + enum d_walk_ret (*enter)(void *, struct dentry *));
7015 +struct ac_dpages_arg {
7017 + struct au_dcsub_pages *dpages;
7018 + struct super_block *sb;
7019 + au_dpages_test test;
7023 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7025 + enum d_walk_ret ret;
7026 + struct ac_dpages_arg *arg = _arg;
7028 + ret = D_WALK_CONTINUE;
7029 + if (dentry->d_sb == arg->sb
7030 + && !IS_ROOT(dentry)
7031 + && au_dcount(dentry) > 0
7033 + && (!arg->test || arg->test(dentry, arg->arg))) {
7034 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7035 + if (unlikely(arg->err))
7036 + ret = D_WALK_QUIT;
7042 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7043 + au_dpages_test test, void *arg)
7045 + struct ac_dpages_arg args = {
7053 + d_walk(root, &args, au_call_dpages_append);
7058 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7059 + int do_include, au_dpages_test test, void *arg)
7064 + write_seqlock(&rename_lock);
7065 + spin_lock(&dentry->d_lock);
7067 + && au_dcount(dentry) > 0
7068 + && (!test || test(dentry, arg)))
7069 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7070 + spin_unlock(&dentry->d_lock);
7071 + if (unlikely(err))
7075 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7078 + while (!IS_ROOT(dentry)) {
7079 + dentry = dentry->d_parent; /* rename_lock is locked */
7080 + spin_lock(&dentry->d_lock);
7081 + if (au_dcount(dentry) > 0
7082 + && (!test || test(dentry, arg)))
7083 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7084 + spin_unlock(&dentry->d_lock);
7085 + if (unlikely(err))
7090 + write_sequnlock(&rename_lock);
7094 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7096 + return au_di(dentry) && dentry->d_sb == arg;
7099 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7100 + struct dentry *dentry, int do_include)
7102 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7103 + au_dcsub_dpages_aufs, dentry->d_sb);
7106 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7108 + struct path path[2] = {
7117 + return path_is_under(path + 0, path + 1);
7119 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7120 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7121 +++ linux/fs/aufs/dcsub.h 2022-03-21 14:49:05.719966344 +0100
7123 +/* SPDX-License-Identifier: GPL-2.0 */
7125 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7127 + * This program, aufs is free software; you can redistribute it and/or modify
7128 + * it under the terms of the GNU General Public License as published by
7129 + * the Free Software Foundation; either version 2 of the License, or
7130 + * (at your option) any later version.
7132 + * This program is distributed in the hope that it will be useful,
7133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7135 + * GNU General Public License for more details.
7137 + * You should have received a copy of the GNU General Public License
7138 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7142 + * sub-routines for dentry cache
7145 +#ifndef __AUFS_DCSUB_H__
7146 +#define __AUFS_DCSUB_H__
7150 +#include <linux/dcache.h>
7151 +#include <linux/fs.h>
7155 + struct dentry **dentries;
7158 +struct au_dcsub_pages {
7160 + struct au_dpage *dpages;
7163 +/* ---------------------------------------------------------------------- */
7166 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7167 +void au_dpages_free(struct au_dcsub_pages *dpages);
7168 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7169 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7170 + au_dpages_test test, void *arg);
7171 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7172 + int do_include, au_dpages_test test, void *arg);
7173 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7174 + struct dentry *dentry, int do_include);
7175 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7177 +/* ---------------------------------------------------------------------- */
7180 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7181 + * include/linux/dcache.h. Try them (in the future).
7184 +static inline int au_d_hashed_positive(struct dentry *d)
7187 + struct inode *inode = d_inode(d);
7190 + if (unlikely(d_unhashed(d)
7191 + || d_is_negative(d)
7192 + || !inode->i_nlink))
7197 +static inline int au_d_linkable(struct dentry *d)
7200 + struct inode *inode = d_inode(d);
7202 + err = au_d_hashed_positive(d);
7204 + && d_is_positive(d)
7205 + && (inode->i_state & I_LINKABLE))
7210 +static inline int au_d_alive(struct dentry *d)
7213 + struct inode *inode;
7217 + err = au_d_hashed_positive(d);
7219 + inode = d_inode(d);
7220 + if (unlikely(d_unlinked(d)
7221 + || d_is_negative(d)
7222 + || !inode->i_nlink))
7228 +static inline int au_alive_dir(struct dentry *d)
7232 + err = au_d_alive(d);
7233 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7238 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7240 + return a->len == b->len
7241 + && !memcmp(a->name, b->name, a->len);
7246 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7248 + * the type of d_lockref.count became int, but the inlined function d_count()
7249 + * still returns unsigned int.
7250 + * I don't know why. Maybe it is for every d_count() users?
7251 + * Anyway au_dcount() lives on.
7253 +static inline int au_dcount(struct dentry *d)
7255 + return (int)d_count(d);
7258 +#endif /* __KERNEL__ */
7259 +#endif /* __AUFS_DCSUB_H__ */
7260 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7261 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7262 +++ linux/fs/aufs/debug.c 2022-03-21 14:49:05.719966344 +0100
7264 +// SPDX-License-Identifier: GPL-2.0
7266 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7268 + * This program, aufs is free software; you can redistribute it and/or modify
7269 + * it under the terms of the GNU General Public License as published by
7270 + * the Free Software Foundation; either version 2 of the License, or
7271 + * (at your option) any later version.
7273 + * This program is distributed in the hope that it will be useful,
7274 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7275 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7276 + * GNU General Public License for more details.
7278 + * You should have received a copy of the GNU General Public License
7279 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7283 + * debug print functions
7286 +#include <linux/iversion.h>
7289 +/* Returns 0, or -errno. arg is in kp->arg. */
7290 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7294 + err = kstrtoint(val, 0, &n);
7304 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7305 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7310 + return sprintf(buffer, "%d", atomic_read(a));
7313 +static struct kernel_param_ops param_ops_atomic_t = {
7314 + .set = param_atomic_t_set,
7315 + .get = param_atomic_t_get
7316 + /* void (*free)(void *arg) */
7319 +atomic_t aufs_debug = ATOMIC_INIT(0);
7320 +MODULE_PARM_DESC(debug, "debug print");
7321 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7323 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7324 +char *au_plevel = KERN_DEBUG;
7325 +#define dpri(fmt, ...) do { \
7327 + && strcmp(au_plevel, KERN_DEBUG)) \
7328 + || au_debug_test()) \
7329 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7332 +/* ---------------------------------------------------------------------- */
7334 +void au_dpri_whlist(struct au_nhash *whlist)
7336 + unsigned long ul, n;
7337 + struct hlist_head *head;
7338 + struct au_vdir_wh *pos;
7340 + n = whlist->nh_num;
7341 + head = whlist->nh_head;
7342 + for (ul = 0; ul < n; ul++) {
7343 + hlist_for_each_entry(pos, head, wh_hash)
7344 + dpri("b%d, %.*s, %d\n",
7346 + pos->wh_str.len, pos->wh_str.name,
7352 +void au_dpri_vdir(struct au_vdir *vdir)
7355 + union au_vdir_deblk_p p;
7358 + if (!vdir || IS_ERR(vdir)) {
7359 + dpri("err %ld\n", PTR_ERR(vdir));
7363 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7364 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7365 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7366 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7367 + p.deblk = vdir->vd_deblk[ul];
7369 + dpri("[%lu]: %p\n", ul, o);
7373 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7374 + struct dentry *wh)
7379 + if (!inode || IS_ERR(inode)) {
7380 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7384 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7385 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7386 + && sizeof(inode->i_blocks) != sizeof(u64));
7388 + n = (void *)wh->d_name.name;
7389 + l = wh->d_name.len;
7392 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7393 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7395 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7396 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7397 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7398 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7399 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7400 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7401 + inode->i_generation,
7402 + l ? ", wh " : "", l, n);
7406 +void au_dpri_inode(struct inode *inode)
7408 + struct au_iinfo *iinfo;
7409 + struct au_hinode *hi;
7410 + aufs_bindex_t bindex;
7413 + err = do_pri_inode(-1, inode, -1, NULL);
7414 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7417 + iinfo = au_ii(inode);
7418 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7419 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7420 + if (iinfo->ii_btop < 0)
7423 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7424 + hi = au_hinode(iinfo, bindex);
7426 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7430 +void au_dpri_dalias(struct inode *inode)
7434 + spin_lock(&inode->i_lock);
7435 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7436 + au_dpri_dentry(d);
7437 + spin_unlock(&inode->i_lock);
7440 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7442 + struct dentry *wh = NULL;
7444 + struct inode *inode;
7445 + struct au_iinfo *iinfo;
7446 + struct au_hinode *hi;
7448 + if (!dentry || IS_ERR(dentry)) {
7449 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7452 + /* do not call dget_parent() here */
7453 + /* note: access d_xxx without d_lock */
7454 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7455 + bindex, dentry, dentry,
7456 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7457 + au_dcount(dentry), dentry->d_flags,
7458 + d_unhashed(dentry) ? "un" : "");
7461 + if (d_is_positive(dentry))
7462 + inode = d_inode(dentry);
7464 + && au_test_aufs(dentry->d_sb)
7466 + && !au_is_bad_inode(inode)) {
7467 + iinfo = au_ii(inode);
7468 + hi = au_hinode(iinfo, bindex);
7470 + wh = hi->hi_whdentry;
7472 + do_pri_inode(bindex, inode, hn, wh);
7476 +void au_dpri_dentry(struct dentry *dentry)
7478 + struct au_dinfo *dinfo;
7479 + aufs_bindex_t bindex;
7482 + err = do_pri_dentry(-1, dentry);
7483 + if (err || !au_test_aufs(dentry->d_sb))
7486 + dinfo = au_di(dentry);
7489 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7490 + dinfo->di_btop, dinfo->di_bbot,
7491 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7492 + dinfo->di_tmpfile);
7493 + if (dinfo->di_btop < 0)
7495 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7496 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7499 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7503 + if (!file || IS_ERR(file)) {
7504 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7509 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7510 + && au_test_aufs(file->f_path.dentry->d_sb)
7512 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7513 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7514 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7515 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7516 + file->f_version, file->f_pos, a);
7517 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7518 + do_pri_dentry(bindex, file->f_path.dentry);
7522 +void au_dpri_file(struct file *file)
7524 + struct au_finfo *finfo;
7525 + struct au_fidir *fidir;
7526 + struct au_hfile *hfile;
7527 + aufs_bindex_t bindex;
7530 + err = do_pri_file(-1, file);
7532 + || IS_ERR_OR_NULL(file->f_path.dentry)
7533 + || !au_test_aufs(file->f_path.dentry->d_sb))
7536 + finfo = au_fi(file);
7539 + if (finfo->fi_btop < 0)
7541 + fidir = finfo->fi_hdir;
7543 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7545 + for (bindex = finfo->fi_btop;
7546 + bindex >= 0 && bindex <= fidir->fd_bbot;
7548 + hfile = fidir->fd_hfile + bindex;
7549 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7553 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7555 + struct vfsmount *mnt;
7556 + struct super_block *sb;
7558 + if (!br || IS_ERR(br))
7560 + mnt = au_br_mnt(br);
7561 + if (!mnt || IS_ERR(mnt))
7564 + if (!sb || IS_ERR(sb))
7567 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7568 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7570 + bindex, br->br_perm, br->br_id, br->br_wbr,
7571 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7572 + sb->s_flags, sb->s_count,
7573 + atomic_read(&sb->s_active),
7574 + !!au_xino_file(br->br_xino, /*idx*/-1));
7578 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7582 +void au_dpri_sb(struct super_block *sb)
7584 + struct au_sbinfo *sbinfo;
7585 + aufs_bindex_t bindex;
7587 + /* to reduce stack size */
7589 + struct vfsmount mnt;
7590 + struct au_branch fake;
7593 + /* this function can be called from magic sysrq */
7594 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7595 + if (unlikely(!a)) {
7596 + dpri("no memory\n");
7600 + a->mnt.mnt_sb = sb;
7601 + a->fake.br_path.mnt = &a->mnt;
7602 + err = do_pri_br(-1, &a->fake);
7604 + dpri("dev 0x%x\n", sb->s_dev);
7605 + if (err || !au_test_aufs(sb))
7608 + sbinfo = au_sbi(sb);
7611 + dpri("nw %d, gen %u, kobj %d\n",
7612 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7613 + kref_read(&sbinfo->si_kobj.kref));
7614 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7615 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7618 +/* ---------------------------------------------------------------------- */
7620 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7622 + struct inode *h_inode, *inode = d_inode(dentry);
7623 + struct dentry *h_dentry;
7624 + aufs_bindex_t bindex, bbot, bi;
7626 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7629 + bbot = au_dbbot(dentry);
7630 + bi = au_ibbot(inode);
7633 + bindex = au_dbtop(dentry);
7634 + bi = au_ibtop(inode);
7638 + for (; bindex <= bbot; bindex++) {
7639 + h_dentry = au_h_dptr(dentry, bindex);
7642 + h_inode = au_h_iptr(inode, bindex);
7643 + if (unlikely(h_inode != d_inode(h_dentry))) {
7645 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7646 + AuDbgDentry(dentry);
7647 + AuDbgInode(inode);
7649 + if (au_test_fuse(h_inode->i_sb))
7657 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7660 + struct au_dcsub_pages dpages;
7661 + struct au_dpage *dpage;
7662 + struct dentry **dentries;
7664 + err = au_dpages_init(&dpages, GFP_NOFS);
7666 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7668 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7669 + dpage = dpages.dpages + i;
7670 + dentries = dpage->dentries;
7671 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7672 + AuDebugOn(au_digen_test(dentries[j], sigen));
7674 + au_dpages_free(&dpages);
7677 +void au_dbg_verify_kthread(void)
7679 + if (au_wkq_test()) {
7682 + * It may be recursive, but udba=notify between two aufs mounts,
7683 + * where a single ro branch is shared, is not a problem.
7689 +/* ---------------------------------------------------------------------- */
7691 +int __init au_debug_init(void)
7693 + aufs_bindex_t bindex;
7694 + struct au_vdir_destr destr;
7697 + AuDebugOn(bindex >= 0);
7700 + AuDebugOn(destr.len < NAME_MAX);
7702 +#ifdef CONFIG_4KSTACKS
7703 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7708 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7709 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7710 +++ linux/fs/aufs/debug.h 2022-03-21 14:49:05.719966344 +0100
7712 +/* SPDX-License-Identifier: GPL-2.0 */
7714 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7716 + * This program, aufs is free software; you can redistribute it and/or modify
7717 + * it under the terms of the GNU General Public License as published by
7718 + * the Free Software Foundation; either version 2 of the License, or
7719 + * (at your option) any later version.
7721 + * This program is distributed in the hope that it will be useful,
7722 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7723 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7724 + * GNU General Public License for more details.
7726 + * You should have received a copy of the GNU General Public License
7727 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7731 + * debug print functions
7734 +#ifndef __AUFS_DEBUG_H__
7735 +#define __AUFS_DEBUG_H__
7739 +#include <linux/atomic.h>
7740 +#include <linux/module.h>
7741 +#include <linux/kallsyms.h>
7742 +#include <linux/sysrq.h>
7744 +#ifdef CONFIG_AUFS_DEBUG
7745 +#define AuDebugOn(a) BUG_ON(a)
7747 +/* module parameter */
7748 +extern atomic_t aufs_debug;
7749 +static inline void au_debug_on(void)
7751 + atomic_inc(&aufs_debug);
7753 +static inline void au_debug_off(void)
7755 + atomic_dec_if_positive(&aufs_debug);
7758 +static inline int au_debug_test(void)
7760 + return atomic_read(&aufs_debug) > 0;
7763 +#define AuDebugOn(a) do {} while (0)
7764 +AuStubVoid(au_debug_on, void)
7765 +AuStubVoid(au_debug_off, void)
7766 +AuStubInt0(au_debug_test, void)
7767 +#endif /* CONFIG_AUFS_DEBUG */
7769 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7771 +/* ---------------------------------------------------------------------- */
7775 +#define AuDbg(fmt, ...) do { \
7776 + if (au_debug_test()) \
7777 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7779 +#define AuLabel(l) AuDbg(#l "\n")
7780 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7781 +#define AuWarn1(fmt, ...) do { \
7782 + static unsigned char _c; \
7784 + pr_warn(fmt, ##__VA_ARGS__); \
7787 +#define AuErr1(fmt, ...) do { \
7788 + static unsigned char _c; \
7790 + pr_err(fmt, ##__VA_ARGS__); \
7793 +#define AuIOErr1(fmt, ...) do { \
7794 + static unsigned char _c; \
7796 + AuIOErr(fmt, ##__VA_ARGS__); \
7799 +#define AuUnsupportMsg "This operation is not supported." \
7800 + " Please report this application to aufs-users ML."
7801 +#define AuUnsupport(fmt, ...) do { \
7802 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7806 +#define AuTraceErr(e) do { \
7807 + if (unlikely((e) < 0)) \
7808 + AuDbg("err %d\n", (int)(e)); \
7811 +#define AuTraceErrPtr(p) do { \
7813 + AuDbg("err %ld\n", PTR_ERR(p)); \
7816 +/* dirty macros for debug print, use with "%.*s" and caution */
7817 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7819 +/* ---------------------------------------------------------------------- */
7822 +#ifdef CONFIG_AUFS_DEBUG
7823 +extern struct mutex au_dbg_mtx;
7824 +extern char *au_plevel;
7826 +void au_dpri_whlist(struct au_nhash *whlist);
7828 +void au_dpri_vdir(struct au_vdir *vdir);
7830 +void au_dpri_inode(struct inode *inode);
7831 +void au_dpri_dalias(struct inode *inode);
7832 +void au_dpri_dentry(struct dentry *dentry);
7834 +void au_dpri_file(struct file *filp);
7835 +struct super_block;
7836 +void au_dpri_sb(struct super_block *sb);
7838 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7839 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7840 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7841 +void au_dbg_verify_kthread(void);
7843 +int __init au_debug_init(void);
7845 +#define AuDbgWhlist(w) do { \
7846 + mutex_lock(&au_dbg_mtx); \
7848 + au_dpri_whlist(w); \
7849 + mutex_unlock(&au_dbg_mtx); \
7852 +#define AuDbgVdir(v) do { \
7853 + mutex_lock(&au_dbg_mtx); \
7855 + au_dpri_vdir(v); \
7856 + mutex_unlock(&au_dbg_mtx); \
7859 +#define AuDbgInode(i) do { \
7860 + mutex_lock(&au_dbg_mtx); \
7862 + au_dpri_inode(i); \
7863 + mutex_unlock(&au_dbg_mtx); \
7866 +#define AuDbgDAlias(i) do { \
7867 + mutex_lock(&au_dbg_mtx); \
7869 + au_dpri_dalias(i); \
7870 + mutex_unlock(&au_dbg_mtx); \
7873 +#define AuDbgDentry(d) do { \
7874 + mutex_lock(&au_dbg_mtx); \
7876 + au_dpri_dentry(d); \
7877 + mutex_unlock(&au_dbg_mtx); \
7880 +#define AuDbgFile(f) do { \
7881 + mutex_lock(&au_dbg_mtx); \
7883 + au_dpri_file(f); \
7884 + mutex_unlock(&au_dbg_mtx); \
7887 +#define AuDbgSb(sb) do { \
7888 + mutex_lock(&au_dbg_mtx); \
7889 + AuDbg(#sb "\n"); \
7891 + mutex_unlock(&au_dbg_mtx); \
7894 +#define AuDbgSym(addr) do { \
7895 + char sym[KSYM_SYMBOL_LEN]; \
7896 + sprint_symbol(sym, (unsigned long)addr); \
7897 + AuDbg("%s\n", sym); \
7900 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7901 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7902 +AuStubVoid(au_dbg_verify_kthread, void)
7903 +AuStubInt0(__init au_debug_init, void)
7905 +#define AuDbgWhlist(w) do {} while (0)
7906 +#define AuDbgVdir(v) do {} while (0)
7907 +#define AuDbgInode(i) do {} while (0)
7908 +#define AuDbgDAlias(i) do {} while (0)
7909 +#define AuDbgDentry(d) do {} while (0)
7910 +#define AuDbgFile(f) do {} while (0)
7911 +#define AuDbgSb(sb) do {} while (0)
7912 +#define AuDbgSym(addr) do {} while (0)
7913 +#endif /* CONFIG_AUFS_DEBUG */
7915 +/* ---------------------------------------------------------------------- */
7917 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7918 +int __init au_sysrq_init(void);
7919 +void au_sysrq_fin(void);
7921 +#ifdef CONFIG_HW_CONSOLE
7922 +#define au_dbg_blocked() do { \
7924 + handle_sysrq('w'); \
7927 +AuStubVoid(au_dbg_blocked, void)
7931 +AuStubInt0(__init au_sysrq_init, void)
7932 +AuStubVoid(au_sysrq_fin, void)
7933 +AuStubVoid(au_dbg_blocked, void)
7934 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7936 +#endif /* __KERNEL__ */
7937 +#endif /* __AUFS_DEBUG_H__ */
7938 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7939 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7940 +++ linux/fs/aufs/dentry.c 2022-03-21 14:49:05.719966344 +0100
7942 +// SPDX-License-Identifier: GPL-2.0
7944 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7946 + * This program, aufs is free software; you can redistribute it and/or modify
7947 + * it under the terms of the GNU General Public License as published by
7948 + * the Free Software Foundation; either version 2 of the License, or
7949 + * (at your option) any later version.
7951 + * This program is distributed in the hope that it will be useful,
7952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7954 + * GNU General Public License for more details.
7956 + * You should have received a copy of the GNU General Public License
7957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7961 + * lookup and dentry operations
7964 +#include <linux/iversion.h>
7968 + * returns positive/negative dentry, NULL or an error.
7969 + * NULL means whiteout-ed or not-found.
7971 +static struct dentry*
7972 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7973 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7975 + struct dentry *h_dentry;
7976 + struct inode *h_inode;
7977 + struct au_branch *br;
7978 + struct user_namespace *h_userns;
7979 + struct path h_path;
7980 + int wh_found, opq;
7981 + unsigned char wh_able;
7982 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7983 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7987 + br = au_sbr(dentry->d_sb, bindex);
7988 + h_path.dentry = h_parent;
7989 + h_path.mnt = au_br_mnt(br);
7990 + h_userns = au_br_userns(br);
7991 + wh_able = !!au_br_whable(br->br_perm);
7993 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
7995 + h_dentry = ERR_PTR(wh_found);
7998 + if (unlikely(wh_found < 0))
8001 + /* We found a whiteout */
8002 + /* au_set_dbbot(dentry, bindex); */
8003 + au_set_dbwh(dentry, bindex);
8005 + return NULL; /* success */
8009 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8011 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8012 + if (IS_ERR(h_dentry)) {
8013 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8019 + h_inode = d_inode(h_dentry);
8020 + if (d_is_negative(h_dentry)) {
8023 + } else if (wh_found
8024 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8026 + else if (au_ftest_lkup(args->flags, DIRREN)
8028 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8029 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8030 + (unsigned long long)h_inode->i_ino);
8034 + if (au_dbbot(dentry) <= bindex)
8035 + au_set_dbbot(dentry, bindex);
8036 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8037 + au_set_dbtop(dentry, bindex);
8038 + au_set_h_dptr(dentry, bindex, h_dentry);
8040 + if (!d_is_dir(h_dentry)
8042 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8043 + goto out; /* success */
8045 + h_path.dentry = h_dentry;
8046 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8047 + opq = au_diropq_test(h_userns, &h_path);
8048 + inode_unlock_shared(h_inode);
8050 + au_set_dbdiropq(dentry, bindex);
8051 + else if (unlikely(opq < 0)) {
8052 + au_set_h_dptr(dentry, bindex, NULL);
8053 + h_dentry = ERR_PTR(opq);
8064 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8066 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8067 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8073 + * returns the number of lower positive dentries,
8074 + * otherwise an error.
8075 + * can be called at unlinking with @type is zero.
8077 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8078 + unsigned int flags)
8080 + int npositive, err;
8081 + aufs_bindex_t bindex, btail, bdiropq;
8082 + unsigned char isdir, dirperm1, dirren;
8083 + struct au_do_lookup_args args = {
8085 + .name = &dentry->d_name
8087 + struct dentry *parent;
8088 + struct super_block *sb;
8090 + sb = dentry->d_sb;
8091 + err = au_test_shwh(sb, args.name);
8092 + if (unlikely(err))
8095 + err = au_wh_name_alloc(&args.whname, args.name);
8096 + if (unlikely(err))
8099 + isdir = !!d_is_dir(dentry);
8100 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8101 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8103 + au_fset_lkup(args.flags, DIRREN);
8106 + parent = dget_parent(dentry);
8107 + btail = au_dbtaildir(parent);
8108 + for (bindex = btop; bindex <= btail; bindex++) {
8109 + struct dentry *h_parent, *h_dentry;
8110 + struct inode *h_inode, *h_dir;
8111 + struct au_branch *br;
8113 + h_dentry = au_h_dptr(dentry, bindex);
8115 + if (d_is_positive(h_dentry))
8119 + h_parent = au_h_dptr(parent, bindex);
8120 + if (!h_parent || !d_is_dir(h_parent))
8124 + /* if the inum matches, then use the prepared name */
8125 + err = au_dr_lkup_name(&args, bindex);
8126 + if (unlikely(err))
8130 + h_dir = d_inode(h_parent);
8131 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8132 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8133 + inode_unlock_shared(h_dir);
8134 + err = PTR_ERR(h_dentry);
8135 + if (IS_ERR(h_dentry))
8138 + au_fclr_lkup(args.flags, ALLOW_NEG);
8140 + au_fset_lkup(args.flags, IGNORE_PERM);
8142 + if (au_dbwh(dentry) == bindex)
8146 + if (d_is_negative(h_dentry))
8148 + h_inode = d_inode(h_dentry);
8151 + args.type = h_inode->i_mode & S_IFMT;
8152 + if (args.type != S_IFDIR)
8155 + /* the type of lower may be different */
8156 + bdiropq = au_dbdiropq(dentry);
8157 + if (bdiropq >= 0 && bdiropq <= bindex)
8160 + br = au_sbr(sb, bindex);
8162 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8163 + /*add_ent*/NULL)) {
8164 + /* prepare next name to lookup */
8165 + err = au_dr_lkup(&args, dentry, bindex);
8166 + if (unlikely(err))
8172 + AuLabel(positive);
8173 + au_update_dbtop(dentry);
8176 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8177 + && au_dbtop(dentry) < 0)) {
8179 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8185 + au_kfree_try_rcu(args.whname.name);
8187 + au_dr_lkup_fin(&args);
8192 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8193 + struct path *ppath)
8195 + struct dentry *dentry;
8198 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8199 + dentry = vfsub_lkup_one(name, ppath);
8201 + struct vfsub_lkup_one_args args = {
8207 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8208 + if (unlikely(wkq_err))
8209 + dentry = ERR_PTR(wkq_err);
8216 + * lookup @dentry on @bindex which should be negative.
8218 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8221 + struct dentry *parent, *h_dentry;
8222 + struct au_branch *br;
8223 + struct user_namespace *h_userns;
8224 + struct path h_ppath;
8226 + parent = dget_parent(dentry);
8227 + br = au_sbr(dentry->d_sb, bindex);
8228 + h_ppath.dentry = au_h_dptr(parent, bindex);
8229 + h_ppath.mnt = au_br_mnt(br);
8230 + h_userns = au_br_userns(br);
8232 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8234 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8235 + err = PTR_ERR(h_dentry);
8236 + if (IS_ERR(h_dentry))
8238 + if (unlikely(d_is_positive(h_dentry))) {
8240 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8246 + if (bindex < au_dbtop(dentry))
8247 + au_set_dbtop(dentry, bindex);
8248 + if (au_dbbot(dentry) < bindex)
8249 + au_set_dbbot(dentry, bindex);
8250 + au_set_h_dptr(dentry, bindex, h_dentry);
8257 +/* ---------------------------------------------------------------------- */
8259 +/* subset of struct inode */
8261 + unsigned long i_ino;
8262 + /* unsigned int i_nlink; */
8268 + blkcnt_t i_blocks;
8273 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8275 + ia->i_ino = h_inode->i_ino;
8276 + /* ia->i_nlink = h_inode->i_nlink; */
8277 + ia->i_uid = h_inode->i_uid;
8278 + ia->i_gid = h_inode->i_gid;
8279 + ia->i_version = inode_query_iversion(h_inode);
8281 + ia->i_size = h_inode->i_size;
8282 + ia->i_blocks = h_inode->i_blocks;
8284 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8287 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8289 + return ia->i_ino != h_inode->i_ino
8290 + /* || ia->i_nlink != h_inode->i_nlink */
8291 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8292 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8293 + || !inode_eq_iversion(h_inode, ia->i_version)
8295 + || ia->i_size != h_inode->i_size
8296 + || ia->i_blocks != h_inode->i_blocks
8298 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8301 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8302 + struct au_branch *br)
8305 + struct au_iattr ia;
8306 + struct inode *h_inode;
8307 + struct dentry *h_d;
8308 + struct super_block *h_sb;
8309 + struct path h_ppath;
8312 + memset(&ia, -1, sizeof(ia));
8313 + h_sb = h_dentry->d_sb;
8315 + if (d_is_positive(h_dentry)) {
8316 + h_inode = d_inode(h_dentry);
8317 + au_iattr_save(&ia, h_inode);
8318 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8319 + /* nfs d_revalidate may return 0 for negative dentry */
8320 + /* fuse d_revalidate always return 0 for negative dentry */
8323 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8324 + h_ppath.dentry = h_parent;
8325 + h_ppath.mnt = au_br_mnt(br);
8326 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8327 + err = PTR_ERR(h_d);
8332 + if (unlikely(h_d != h_dentry
8333 + || d_inode(h_d) != h_inode
8334 + || (h_inode && au_iattr_test(&ia, h_inode))))
8335 + err = au_busy_or_stale();
8343 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8344 + struct dentry *h_parent, struct au_branch *br)
8349 + if (udba == AuOpt_UDBA_REVAL
8350 + && !au_test_fs_remote(h_dentry->d_sb)) {
8352 + err = (d_inode(h_dentry->d_parent) != h_dir);
8353 + } else if (udba != AuOpt_UDBA_NONE)
8354 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8359 +/* ---------------------------------------------------------------------- */
8361 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8364 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8365 + struct au_hdentry tmp, *p, *q;
8366 + struct au_dinfo *dinfo;
8367 + struct super_block *sb;
8369 + DiMustWriteLock(dentry);
8371 + sb = dentry->d_sb;
8372 + dinfo = au_di(dentry);
8373 + bbot = dinfo->di_bbot;
8374 + bwh = dinfo->di_bwh;
8375 + bdiropq = dinfo->di_bdiropq;
8376 + bindex = dinfo->di_btop;
8377 + p = au_hdentry(dinfo, bindex);
8378 + for (; bindex <= bbot; bindex++, p++) {
8379 + if (!p->hd_dentry)
8382 + new_bindex = au_br_index(sb, p->hd_id);
8383 + if (new_bindex == bindex)
8386 + if (dinfo->di_bwh == bindex)
8388 + if (dinfo->di_bdiropq == bindex)
8389 + bdiropq = new_bindex;
8390 + if (new_bindex < 0) {
8392 + p->hd_dentry = NULL;
8396 + /* swap two lower dentries, and loop again */
8397 + q = au_hdentry(dinfo, new_bindex);
8401 + if (tmp.hd_dentry) {
8407 + dinfo->di_bwh = -1;
8408 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8409 + dinfo->di_bwh = bwh;
8411 + dinfo->di_bdiropq = -1;
8413 + && bdiropq <= au_sbbot(sb)
8414 + && au_sbr_whable(sb, bdiropq))
8415 + dinfo->di_bdiropq = bdiropq;
8418 + dinfo->di_btop = -1;
8419 + dinfo->di_bbot = -1;
8420 + bbot = au_dbbot(parent);
8422 + p = au_hdentry(dinfo, bindex);
8423 + for (; bindex <= bbot; bindex++, p++)
8424 + if (p->hd_dentry) {
8425 + dinfo->di_btop = bindex;
8429 + if (dinfo->di_btop >= 0) {
8431 + p = au_hdentry(dinfo, bindex);
8432 + for (; bindex >= 0; bindex--, p--)
8433 + if (p->hd_dentry) {
8434 + dinfo->di_bbot = bindex;
8443 +static void au_do_hide(struct dentry *dentry)
8445 + struct inode *inode;
8447 + if (d_really_is_positive(dentry)) {
8448 + inode = d_inode(dentry);
8449 + if (!d_is_dir(dentry)) {
8450 + if (inode->i_nlink && !d_unhashed(dentry))
8451 + drop_nlink(inode);
8453 + clear_nlink(inode);
8454 + /* stop next lookup */
8455 + inode->i_flags |= S_DEAD;
8457 + smp_mb(); /* necessary? */
8462 +static int au_hide_children(struct dentry *parent)
8464 + int err, i, j, ndentry;
8465 + struct au_dcsub_pages dpages;
8466 + struct au_dpage *dpage;
8467 + struct dentry *dentry;
8469 + err = au_dpages_init(&dpages, GFP_NOFS);
8470 + if (unlikely(err))
8472 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8473 + if (unlikely(err))
8476 + /* in reverse order */
8477 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8478 + dpage = dpages.dpages + i;
8479 + ndentry = dpage->ndentry;
8480 + for (j = ndentry - 1; j >= 0; j--) {
8481 + dentry = dpage->dentries[j];
8482 + if (dentry != parent)
8483 + au_do_hide(dentry);
8488 + au_dpages_free(&dpages);
8493 +static void au_hide(struct dentry *dentry)
8497 + AuDbgDentry(dentry);
8498 + if (d_is_dir(dentry)) {
8499 + /* shrink_dcache_parent(dentry); */
8500 + err = au_hide_children(dentry);
8501 + if (unlikely(err))
8502 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8505 + au_do_hide(dentry);
8509 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8511 + * a dirty branch is added
8512 + * - on the top of layers
8513 + * - in the middle of layers
8514 + * - to the bottom of layers
8516 + * on the added branch there exists
8519 + * - a same named entry
8521 + * * negative --> positive
8522 + * * positive --> positive
8523 + * - type is unchanged
8524 + * - type is changed
8526 + * * negative --> negative
8527 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8530 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8531 + struct au_dinfo *tmp)
8534 + aufs_bindex_t bindex, bbot;
8536 + struct dentry *dentry;
8537 + struct inode *inode;
8539 + } orig_h, tmp_h = {
8542 + struct au_hdentry *hd;
8543 + struct inode *inode, *h_inode;
8544 + struct dentry *h_dentry;
8547 + AuDebugOn(dinfo->di_btop < 0);
8549 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8550 + orig_h.inode = NULL;
8551 + if (d_is_positive(orig_h.dentry)) {
8552 + orig_h.inode = d_inode(orig_h.dentry);
8553 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8555 + if (tmp->di_btop >= 0) {
8556 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8557 + if (d_is_positive(tmp_h.dentry)) {
8558 + tmp_h.inode = d_inode(tmp_h.dentry);
8559 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8564 + if (d_really_is_positive(dentry))
8565 + inode = d_inode(dentry);
8566 + if (!orig_h.inode) {
8567 + AuDbg("negative originally\n");
8573 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8574 + AuDebugOn(dinfo->di_bdiropq != -1);
8576 + if (!tmp_h.inode) {
8577 + AuDbg("negative --> negative\n");
8578 + /* should have only one negative lower */
8579 + if (tmp->di_btop >= 0
8580 + && tmp->di_btop < dinfo->di_btop) {
8581 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8582 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8583 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8584 + au_di_cp(dinfo, tmp);
8585 + hd = au_hdentry(tmp, tmp->di_btop);
8586 + au_set_h_dptr(dentry, tmp->di_btop,
8587 + dget(hd->hd_dentry));
8589 + au_dbg_verify_dinode(dentry);
8591 + AuDbg("negative --> positive\n");
8593 + * similar to the behaviour of creating with bypassing
8595 + * unhash it in order to force an error in the
8596 + * succeeding create operation.
8597 + * we should not set S_DEAD here.
8600 + /* au_di_swap(tmp, dinfo); */
8601 + au_dbg_verify_dinode(dentry);
8604 + AuDbg("positive originally\n");
8605 + /* inode may be NULL */
8606 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8607 + if (!tmp_h.inode) {
8608 + AuDbg("positive --> negative\n");
8609 + /* or bypassing aufs */
8611 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8612 + dinfo->di_bwh = tmp->di_bwh;
8614 + err = au_refresh_hinode_self(inode);
8615 + au_dbg_verify_dinode(dentry);
8616 + } else if (orig_h.mode == tmp_h.mode) {
8617 + AuDbg("positive --> positive, same type\n");
8618 + if (!S_ISDIR(orig_h.mode)
8619 + && dinfo->di_btop > tmp->di_btop) {
8621 + * similar to the behaviour of removing and
8626 + err = au_refresh_hinode_self(inode);
8627 + au_dbg_verify_dinode(dentry);
8629 + /* fill empty slots */
8630 + if (dinfo->di_btop > tmp->di_btop)
8631 + dinfo->di_btop = tmp->di_btop;
8632 + if (dinfo->di_bbot < tmp->di_bbot)
8633 + dinfo->di_bbot = tmp->di_bbot;
8634 + dinfo->di_bwh = tmp->di_bwh;
8635 + dinfo->di_bdiropq = tmp->di_bdiropq;
8636 + bbot = dinfo->di_bbot;
8637 + bindex = tmp->di_btop;
8638 + hd = au_hdentry(tmp, bindex);
8639 + for (; bindex <= bbot; bindex++, hd++) {
8640 + if (au_h_dptr(dentry, bindex))
8642 + h_dentry = hd->hd_dentry;
8645 + AuDebugOn(d_is_negative(h_dentry));
8646 + h_inode = d_inode(h_dentry);
8647 + AuDebugOn(orig_h.mode
8648 + != (h_inode->i_mode
8650 + au_set_h_dptr(dentry, bindex,
8654 + err = au_refresh_hinode(inode, dentry);
8655 + au_dbg_verify_dinode(dentry);
8658 + AuDbg("positive --> positive, different type\n");
8659 + /* similar to the behaviour of removing and creating */
8662 + err = au_refresh_hinode_self(inode);
8663 + au_dbg_verify_dinode(dentry);
8671 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8673 + const struct dentry_operations *dop
8674 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8675 + static const unsigned int mask
8676 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8678 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8680 + if (dentry->d_op == dop)
8683 + AuDbg("%pd\n", dentry);
8684 + spin_lock(&dentry->d_lock);
8685 + if (dop == &aufs_dop)
8686 + dentry->d_flags |= mask;
8688 + dentry->d_flags &= ~mask;
8689 + dentry->d_op = dop;
8690 + spin_unlock(&dentry->d_lock);
8693 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8695 + int err, ebrange, nbr;
8696 + unsigned int sigen;
8697 + struct au_dinfo *dinfo, *tmp;
8698 + struct super_block *sb;
8699 + struct inode *inode;
8701 + DiMustWriteLock(dentry);
8702 + AuDebugOn(IS_ROOT(dentry));
8703 + AuDebugOn(d_really_is_negative(parent));
8705 + sb = dentry->d_sb;
8706 + sigen = au_sigen(sb);
8707 + err = au_digen_test(parent, sigen);
8708 + if (unlikely(err))
8711 + nbr = au_sbbot(sb) + 1;
8712 + dinfo = au_di(dentry);
8713 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8714 + if (unlikely(err))
8716 + ebrange = au_dbrange_test(dentry);
8718 + ebrange = au_do_refresh_hdentry(dentry, parent);
8720 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8721 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8722 + if (d_really_is_positive(dentry)) {
8723 + inode = d_inode(dentry);
8724 + err = au_refresh_hinode_self(inode);
8726 + au_dbg_verify_dinode(dentry);
8728 + goto out_dgen; /* success */
8732 + /* temporary dinfo */
8733 + AuDbgDentry(dentry);
8735 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8736 + if (unlikely(!tmp))
8738 + au_di_swap(tmp, dinfo);
8739 + /* returns the number of positive dentries */
8741 + * if current working dir is removed, it returns an error.
8742 + * but the dentry is legal.
8744 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8745 + AuDbgDentry(dentry);
8746 + au_di_swap(tmp, dinfo);
8747 + if (err == -ENOENT)
8750 + /* compare/refresh by dinfo */
8751 + AuDbgDentry(dentry);
8752 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8753 + au_dbg_verify_dinode(dentry);
8756 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8757 + au_rw_write_unlock(&tmp->di_rwsem);
8759 + if (unlikely(err))
8763 + au_update_digen(dentry);
8765 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8766 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8767 + AuDbgDentry(dentry);
8773 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8774 + struct dentry *dentry, aufs_bindex_t bindex)
8779 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8782 + AuDbg("b%d\n", bindex);
8784 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8785 + * due to whiteout and branch permission.
8787 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8788 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8789 + /* it may return tri-state */
8790 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8792 + if (unlikely(valid < 0))
8802 +/* todo: remove this */
8803 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8804 + unsigned int flags, int do_udba, int dirren)
8807 + umode_t mode, h_mode;
8808 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8809 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8810 + struct inode *h_inode, *h_cached_inode;
8811 + struct dentry *h_dentry;
8812 + struct qstr *name, *h_name;
8819 + unhashed = !!d_unhashed(dentry);
8820 + is_root = !!IS_ROOT(dentry);
8821 + name = &dentry->d_name;
8822 + tmpfile = au_di(dentry)->di_tmpfile;
8825 + * Theoretically, REVAL test should be unnecessary in case of
8827 + * But {fs,i}notify doesn't fire some necessary events,
8828 + * IN_ATTRIB for atime/nlink/pageio
8829 + * Let's do REVAL test too.
8831 + if (do_udba && inode) {
8832 + mode = (inode->i_mode & S_IFMT);
8833 + plus = (inode->i_nlink > 0);
8834 + ibs = au_ibtop(inode);
8835 + ibe = au_ibbot(inode);
8838 + btop = au_dbtop(dentry);
8840 + if (inode && S_ISDIR(inode->i_mode))
8841 + btail = au_dbtaildir(dentry);
8842 + for (bindex = btop; bindex <= btail; bindex++) {
8843 + h_dentry = au_h_dptr(dentry, bindex);
8847 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8848 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8849 + spin_lock(&h_dentry->d_lock);
8850 + h_name = &h_dentry->d_name;
8851 + if (unlikely(do_udba
8854 + && (unhashed != !!d_unhashed(h_dentry)
8855 + || (!tmpfile && !dirren
8856 + && !au_qstreq(name, h_name))
8859 + && !(flags & LOOKUP_OPEN)
8860 + && (h_dentry->d_flags
8861 + & DCACHE_NFSFS_RENAMED)))
8865 + h_unhashed = d_unhashed(h_dentry);
8866 + spin_unlock(&h_dentry->d_lock);
8867 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8868 + unhashed, h_unhashed, dentry, h_dentry);
8871 + spin_unlock(&h_dentry->d_lock);
8873 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8874 + if (unlikely(err))
8875 + /* do not goto err, to keep the errno */
8878 + /* todo: plink too? */
8883 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8887 + if (d_is_positive(h_dentry))
8888 + h_inode = d_inode(h_dentry);
8891 + h_cached_inode = h_inode;
8893 + h_mode = (h_inode->i_mode & S_IFMT);
8894 + h_plus = (h_inode->i_nlink > 0);
8896 + if (inode && ibs <= bindex && bindex <= ibe)
8897 + h_cached_inode = au_h_iptr(inode, bindex);
8900 + if (unlikely(plus != h_plus && !tmpfile))
8903 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8905 + && !IS_ROOT(h_dentry)
8906 + && unhashed != d_unhashed(h_dentry)))
8909 + if (unlikely(mode != h_mode
8910 + || h_cached_inode != h_inode))
8923 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8924 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8927 + struct dentry *parent;
8929 + if (!au_digen_test(dentry, sigen))
8932 + parent = dget_parent(dentry);
8933 + di_read_lock_parent(parent, AuLock_IR);
8934 + AuDebugOn(au_digen_test(parent, sigen));
8935 + au_dbg_verify_gen(parent, sigen);
8936 + err = au_refresh_dentry(dentry, parent);
8937 + di_read_unlock(parent, AuLock_IR);
8943 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8946 + struct dentry *d, *parent;
8948 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8949 + return simple_reval_dpath(dentry, sigen);
8951 + /* slow loop, keep it simple and stupid */
8952 + /* cf: au_cpup_dirs() */
8955 + while (au_digen_test(dentry, sigen)) {
8959 + parent = dget_parent(d);
8960 + if (!au_digen_test(parent, sigen))
8966 + di_write_lock_child2(d);
8968 + /* someone might update our dentry while we were sleeping */
8969 + if (au_digen_test(d, sigen)) {
8971 + * todo: consolidate with simple_reval_dpath(),
8972 + * do_refresh() and au_reval_for_attr().
8974 + di_read_lock_parent(parent, AuLock_IR);
8975 + err = au_refresh_dentry(d, parent);
8976 + di_read_unlock(parent, AuLock_IR);
8980 + di_write_unlock(d);
8982 + if (unlikely(err))
8990 + * if valid returns 1, otherwise 0.
8992 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8995 + unsigned int sigen;
8996 + unsigned char do_udba, dirren;
8997 + struct super_block *sb;
8998 + struct inode *inode;
9000 + /* todo: support rcu-walk? */
9001 + if (flags & LOOKUP_RCU)
9005 + if (unlikely(!au_di(dentry)))
9009 + sb = dentry->d_sb;
9012 + * i_mutex of parent dir may be held,
9013 + * but we should not return 'invalid' due to busy.
9015 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9016 + if (unlikely(err)) {
9022 + if (d_really_is_positive(dentry))
9023 + inode = d_inode(dentry);
9024 + if (unlikely(inode && au_is_bad_inode(inode))) {
9029 + if (unlikely(au_dbrange_test(dentry))) {
9035 + sigen = au_sigen(sb);
9036 + if (au_digen_test(dentry, sigen)) {
9037 + AuDebugOn(IS_ROOT(dentry));
9038 + err = au_reval_dpath(dentry, sigen);
9039 + if (unlikely(err)) {
9044 + di_downgrade_lock(dentry, AuLock_IR);
9047 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9049 + && !(inode->i_state && I_LINKABLE)
9050 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9055 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9056 + if (do_udba && inode) {
9057 + aufs_bindex_t btop = au_ibtop(inode);
9058 + struct inode *h_inode;
9061 + h_inode = au_h_iptr(inode, btop);
9062 + if (h_inode && au_test_higen(inode, h_inode)) {
9069 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9070 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9071 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9073 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9079 + di_downgrade_lock(dentry, AuLock_IR);
9081 + aufs_read_unlock(dentry, AuLock_IR);
9086 + AuDbg("%pd invalid, %d\n", dentry, valid);
9092 +static void aufs_d_release(struct dentry *dentry)
9094 + if (au_di(dentry)) {
9095 + au_di_fin(dentry);
9096 + au_hn_di_reinit(dentry);
9100 +const struct dentry_operations aufs_dop = {
9101 + .d_revalidate = aufs_d_revalidate,
9102 + .d_weak_revalidate = aufs_d_revalidate,
9103 + .d_release = aufs_d_release
9106 +/* aufs_dop without d_revalidate */
9107 +const struct dentry_operations aufs_dop_noreval = {
9108 + .d_release = aufs_d_release
9110 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9111 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9112 +++ linux/fs/aufs/dentry.h 2022-03-21 14:49:05.719966344 +0100
9114 +/* SPDX-License-Identifier: GPL-2.0 */
9116 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9118 + * This program, aufs is free software; you can redistribute it and/or modify
9119 + * it under the terms of the GNU General Public License as published by
9120 + * the Free Software Foundation; either version 2 of the License, or
9121 + * (at your option) any later version.
9123 + * This program is distributed in the hope that it will be useful,
9124 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9125 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9126 + * GNU General Public License for more details.
9128 + * You should have received a copy of the GNU General Public License
9129 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9133 + * lookup and dentry operations
9136 +#ifndef __AUFS_DENTRY_H__
9137 +#define __AUFS_DENTRY_H__
9141 +#include <linux/dcache.h>
9142 +#include "dirren.h"
9145 +struct au_hdentry {
9146 + struct dentry *hd_dentry;
9147 + aufs_bindex_t hd_id;
9151 + atomic_t di_generation;
9153 + struct au_rwsem di_rwsem;
9154 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9155 + unsigned char di_tmpfile; /* to allow the different name */
9156 + struct au_hdentry *di_hdentry;
9157 + struct rcu_head rcu;
9158 +} ____cacheline_aligned_in_smp;
9160 +/* ---------------------------------------------------------------------- */
9162 +/* flags for au_lkup_dentry() */
9163 +#define AuLkup_ALLOW_NEG 1
9164 +#define AuLkup_IGNORE_PERM (1 << 1)
9165 +#define AuLkup_DIRREN (1 << 2)
9166 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9167 +#define au_fset_lkup(flags, name) \
9168 + do { (flags) |= AuLkup_##name; } while (0)
9169 +#define au_fclr_lkup(flags, name) \
9170 + do { (flags) &= ~AuLkup_##name; } while (0)
9172 +#ifndef CONFIG_AUFS_DIRREN
9173 +#undef AuLkup_DIRREN
9174 +#define AuLkup_DIRREN 0
9177 +struct au_do_lookup_args {
9178 + unsigned int flags;
9180 + struct qstr whname, *name;
9181 + struct au_dr_lookup dirren;
9184 +/* ---------------------------------------------------------------------- */
9187 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9189 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9190 + struct path *ppath);
9191 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9192 + struct dentry *h_parent, struct au_branch *br);
9194 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9195 + unsigned int flags);
9196 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9197 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9198 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9199 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9202 +void au_di_init_once(void *_di);
9203 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9204 +void au_di_free(struct au_dinfo *dinfo);
9205 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9206 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9207 +int au_di_init(struct dentry *dentry);
9208 +void au_di_fin(struct dentry *dentry);
9209 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9211 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9212 +void di_read_unlock(struct dentry *d, int flags);
9213 +void di_downgrade_lock(struct dentry *d, int flags);
9214 +void di_write_lock(struct dentry *d, unsigned int lsc);
9215 +void di_write_unlock(struct dentry *d);
9216 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9217 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9218 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9220 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9221 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9222 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9223 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9225 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9226 + struct dentry *h_dentry);
9227 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9228 +int au_dbrange_test(struct dentry *dentry);
9229 +void au_update_digen(struct dentry *dentry);
9230 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9231 +void au_update_dbtop(struct dentry *dentry);
9232 +void au_update_dbbot(struct dentry *dentry);
9233 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9235 +/* ---------------------------------------------------------------------- */
9237 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9239 + return dentry->d_fsdata;
9242 +/* ---------------------------------------------------------------------- */
9244 +/* lock subclass for dinfo */
9246 + AuLsc_DI_CHILD, /* child first */
9247 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9248 + AuLsc_DI_CHILD3, /* copyup dirs */
9252 + AuLsc_DI_TMP /* temp for replacing dinfo */
9256 + * di_read_lock_child, di_write_lock_child,
9257 + * di_read_lock_child2, di_write_lock_child2,
9258 + * di_read_lock_child3, di_write_lock_child3,
9259 + * di_read_lock_parent, di_write_lock_parent,
9260 + * di_read_lock_parent2, di_write_lock_parent2,
9261 + * di_read_lock_parent3, di_write_lock_parent3,
9263 +#define AuReadLockFunc(name, lsc) \
9264 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9265 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9267 +#define AuWriteLockFunc(name, lsc) \
9268 +static inline void di_write_lock_##name(struct dentry *d) \
9269 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9271 +#define AuRWLockFuncs(name, lsc) \
9272 + AuReadLockFunc(name, lsc) \
9273 + AuWriteLockFunc(name, lsc)
9275 +AuRWLockFuncs(child, CHILD);
9276 +AuRWLockFuncs(child2, CHILD2);
9277 +AuRWLockFuncs(child3, CHILD3);
9278 +AuRWLockFuncs(parent, PARENT);
9279 +AuRWLockFuncs(parent2, PARENT2);
9280 +AuRWLockFuncs(parent3, PARENT3);
9282 +#undef AuReadLockFunc
9283 +#undef AuWriteLockFunc
9284 +#undef AuRWLockFuncs
9286 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9287 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9288 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9290 +/* ---------------------------------------------------------------------- */
9292 +/* todo: memory barrier? */
9293 +static inline unsigned int au_digen(struct dentry *d)
9295 + return atomic_read(&au_di(d)->di_generation);
9298 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9300 + hdentry->hd_dentry = NULL;
9303 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9304 + aufs_bindex_t bindex)
9306 + return di->di_hdentry + bindex;
9309 +static inline void au_hdput(struct au_hdentry *hd)
9312 + dput(hd->hd_dentry);
9315 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9317 + DiMustAnyLock(dentry);
9318 + return au_di(dentry)->di_btop;
9321 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9323 + DiMustAnyLock(dentry);
9324 + return au_di(dentry)->di_bbot;
9327 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9329 + DiMustAnyLock(dentry);
9330 + return au_di(dentry)->di_bwh;
9333 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9335 + DiMustAnyLock(dentry);
9336 + return au_di(dentry)->di_bdiropq;
9339 +/* todo: hard/soft set? */
9340 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9342 + DiMustWriteLock(dentry);
9343 + au_di(dentry)->di_btop = bindex;
9346 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9348 + DiMustWriteLock(dentry);
9349 + au_di(dentry)->di_bbot = bindex;
9352 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9354 + DiMustWriteLock(dentry);
9355 + /* dbwh can be outside of btop - bbot range */
9356 + au_di(dentry)->di_bwh = bindex;
9359 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9361 + DiMustWriteLock(dentry);
9362 + au_di(dentry)->di_bdiropq = bindex;
9365 +/* ---------------------------------------------------------------------- */
9367 +#ifdef CONFIG_AUFS_HNOTIFY
9368 +static inline void au_digen_dec(struct dentry *d)
9370 + atomic_dec(&au_di(d)->di_generation);
9373 +static inline void au_hn_di_reinit(struct dentry *dentry)
9375 + dentry->d_fsdata = NULL;
9378 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9379 +#endif /* CONFIG_AUFS_HNOTIFY */
9381 +#endif /* __KERNEL__ */
9382 +#endif /* __AUFS_DENTRY_H__ */
9383 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9384 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9385 +++ linux/fs/aufs/dinfo.c 2022-03-21 14:49:05.719966344 +0100
9387 +// SPDX-License-Identifier: GPL-2.0
9389 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9391 + * This program, aufs is free software; you can redistribute it and/or modify
9392 + * it under the terms of the GNU General Public License as published by
9393 + * the Free Software Foundation; either version 2 of the License, or
9394 + * (at your option) any later version.
9396 + * This program is distributed in the hope that it will be useful,
9397 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9398 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9399 + * GNU General Public License for more details.
9401 + * You should have received a copy of the GNU General Public License
9402 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9406 + * dentry private data
9411 +void au_di_init_once(void *_dinfo)
9413 + struct au_dinfo *dinfo = _dinfo;
9415 + au_rw_init(&dinfo->di_rwsem);
9418 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9420 + struct au_dinfo *dinfo;
9423 + dinfo = au_cache_alloc_dinfo();
9424 + if (unlikely(!dinfo))
9427 + nbr = au_sbbot(sb) + 1;
9430 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9431 + if (dinfo->di_hdentry) {
9432 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9433 + dinfo->di_btop = -1;
9434 + dinfo->di_bbot = -1;
9435 + dinfo->di_bwh = -1;
9436 + dinfo->di_bdiropq = -1;
9437 + dinfo->di_tmpfile = 0;
9438 + for (i = 0; i < nbr; i++)
9439 + dinfo->di_hdentry[i].hd_id = -1;
9443 + au_cache_free_dinfo(dinfo);
9450 +void au_di_free(struct au_dinfo *dinfo)
9452 + struct au_hdentry *p;
9453 + aufs_bindex_t bbot, bindex;
9455 + /* dentry may not be revalidated */
9456 + bindex = dinfo->di_btop;
9457 + if (bindex >= 0) {
9458 + bbot = dinfo->di_bbot;
9459 + p = au_hdentry(dinfo, bindex);
9460 + while (bindex++ <= bbot)
9463 + au_kfree_try_rcu(dinfo->di_hdentry);
9464 + au_cache_free_dinfo(dinfo);
9467 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9469 + struct au_hdentry *p;
9472 + AuRwMustWriteLock(&a->di_rwsem);
9473 + AuRwMustWriteLock(&b->di_rwsem);
9475 +#define DiSwap(v, name) \
9477 + v = a->di_##name; \
9478 + a->di_##name = b->di_##name; \
9479 + b->di_##name = v; \
9482 + DiSwap(p, hdentry);
9486 + DiSwap(bi, bdiropq);
9492 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9494 + AuRwMustWriteLock(&dst->di_rwsem);
9495 + AuRwMustWriteLock(&src->di_rwsem);
9497 + dst->di_btop = src->di_btop;
9498 + dst->di_bbot = src->di_bbot;
9499 + dst->di_bwh = src->di_bwh;
9500 + dst->di_bdiropq = src->di_bdiropq;
9504 +int au_di_init(struct dentry *dentry)
9507 + struct super_block *sb;
9508 + struct au_dinfo *dinfo;
9511 + sb = dentry->d_sb;
9512 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9514 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9515 + /* smp_mb(); */ /* atomic_set */
9516 + dentry->d_fsdata = dinfo;
9523 +void au_di_fin(struct dentry *dentry)
9525 + struct au_dinfo *dinfo;
9527 + dinfo = au_di(dentry);
9528 + AuRwDestroy(&dinfo->di_rwsem);
9529 + au_di_free(dinfo);
9532 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9535 + struct au_hdentry *hdp;
9537 + AuRwMustWriteLock(&dinfo->di_rwsem);
9540 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9542 + sz = sizeof(*hdp);
9543 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9546 + dinfo->di_hdentry = hdp;
9553 +/* ---------------------------------------------------------------------- */
9555 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9558 + case AuLsc_DI_CHILD:
9559 + ii_write_lock_child(inode);
9561 + case AuLsc_DI_CHILD2:
9562 + ii_write_lock_child2(inode);
9564 + case AuLsc_DI_CHILD3:
9565 + ii_write_lock_child3(inode);
9567 + case AuLsc_DI_PARENT:
9568 + ii_write_lock_parent(inode);
9570 + case AuLsc_DI_PARENT2:
9571 + ii_write_lock_parent2(inode);
9573 + case AuLsc_DI_PARENT3:
9574 + ii_write_lock_parent3(inode);
9581 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9584 + case AuLsc_DI_CHILD:
9585 + ii_read_lock_child(inode);
9587 + case AuLsc_DI_CHILD2:
9588 + ii_read_lock_child2(inode);
9590 + case AuLsc_DI_CHILD3:
9591 + ii_read_lock_child3(inode);
9593 + case AuLsc_DI_PARENT:
9594 + ii_read_lock_parent(inode);
9596 + case AuLsc_DI_PARENT2:
9597 + ii_read_lock_parent2(inode);
9599 + case AuLsc_DI_PARENT3:
9600 + ii_read_lock_parent3(inode);
9607 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9609 + struct inode *inode;
9611 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9612 + if (d_really_is_positive(d)) {
9613 + inode = d_inode(d);
9614 + if (au_ftest_lock(flags, IW))
9615 + do_ii_write_lock(inode, lsc);
9616 + else if (au_ftest_lock(flags, IR))
9617 + do_ii_read_lock(inode, lsc);
9621 +void di_read_unlock(struct dentry *d, int flags)
9623 + struct inode *inode;
9625 + if (d_really_is_positive(d)) {
9626 + inode = d_inode(d);
9627 + if (au_ftest_lock(flags, IW)) {
9628 + au_dbg_verify_dinode(d);
9629 + ii_write_unlock(inode);
9630 + } else if (au_ftest_lock(flags, IR)) {
9631 + au_dbg_verify_dinode(d);
9632 + ii_read_unlock(inode);
9635 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9638 +void di_downgrade_lock(struct dentry *d, int flags)
9640 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9641 + ii_downgrade_lock(d_inode(d));
9642 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9645 +void di_write_lock(struct dentry *d, unsigned int lsc)
9647 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9648 + if (d_really_is_positive(d))
9649 + do_ii_write_lock(d_inode(d), lsc);
9652 +void di_write_unlock(struct dentry *d)
9654 + au_dbg_verify_dinode(d);
9655 + if (d_really_is_positive(d))
9656 + ii_write_unlock(d_inode(d));
9657 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9660 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9662 + AuDebugOn(d1 == d2
9663 + || d_inode(d1) == d_inode(d2)
9664 + || d1->d_sb != d2->d_sb);
9666 + if ((isdir && au_test_subdir(d1, d2))
9668 + di_write_lock_child(d1);
9669 + di_write_lock_child2(d2);
9671 + di_write_lock_child(d2);
9672 + di_write_lock_child2(d1);
9676 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9678 + AuDebugOn(d1 == d2
9679 + || d_inode(d1) == d_inode(d2)
9680 + || d1->d_sb != d2->d_sb);
9682 + if ((isdir && au_test_subdir(d1, d2))
9684 + di_write_lock_parent(d1);
9685 + di_write_lock_parent2(d2);
9687 + di_write_lock_parent(d2);
9688 + di_write_lock_parent2(d1);
9692 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9694 + di_write_unlock(d1);
9695 + if (d_inode(d1) == d_inode(d2))
9696 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9698 + di_write_unlock(d2);
9701 +/* ---------------------------------------------------------------------- */
9703 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9707 + DiMustAnyLock(dentry);
9709 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9711 + AuDebugOn(bindex < 0);
9712 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9713 + AuDebugOn(d && au_dcount(d) <= 0);
9718 + * extended version of au_h_dptr().
9719 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9722 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9724 + struct dentry *h_dentry;
9725 + struct inode *inode, *h_inode;
9727 + AuDebugOn(d_really_is_negative(dentry));
9730 + if (au_dbtop(dentry) <= bindex
9731 + && bindex <= au_dbbot(dentry))
9732 + h_dentry = au_h_dptr(dentry, bindex);
9733 + if (h_dentry && !au_d_linkable(h_dentry)) {
9735 + goto out; /* success */
9738 + inode = d_inode(dentry);
9739 + AuDebugOn(bindex < au_ibtop(inode));
9740 + AuDebugOn(au_ibbot(inode) < bindex);
9741 + h_inode = au_h_iptr(inode, bindex);
9742 + h_dentry = d_find_alias(h_inode);
9744 + if (!IS_ERR(h_dentry)) {
9745 + if (!au_d_linkable(h_dentry))
9746 + goto out; /* success */
9752 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9753 + h_dentry = au_plink_lkup(inode, bindex);
9754 + AuDebugOn(!h_dentry);
9755 + if (!IS_ERR(h_dentry)) {
9756 + if (!au_d_hashed_positive(h_dentry))
9757 + goto out; /* success */
9764 + AuDbgDentry(h_dentry);
9768 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9770 + aufs_bindex_t bbot, bwh;
9772 + bbot = au_dbbot(dentry);
9774 + bwh = au_dbwh(dentry);
9777 + if (0 < bwh && bwh < bbot)
9783 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9785 + aufs_bindex_t bbot, bopq;
9787 + bbot = au_dbtail(dentry);
9789 + bopq = au_dbdiropq(dentry);
9790 + if (0 <= bopq && bopq < bbot)
9796 +/* ---------------------------------------------------------------------- */
9798 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9799 + struct dentry *h_dentry)
9801 + struct au_dinfo *dinfo;
9802 + struct au_hdentry *hd;
9803 + struct au_branch *br;
9805 + DiMustWriteLock(dentry);
9807 + dinfo = au_di(dentry);
9808 + hd = au_hdentry(dinfo, bindex);
9810 + hd->hd_dentry = h_dentry;
9812 + br = au_sbr(dentry->d_sb, bindex);
9813 + hd->hd_id = br->br_id;
9817 +int au_dbrange_test(struct dentry *dentry)
9820 + aufs_bindex_t btop, bbot;
9823 + btop = au_dbtop(dentry);
9824 + bbot = au_dbbot(dentry);
9826 + AuDebugOn(bbot < 0 && btop > bbot);
9829 + AuDebugOn(bbot >= 0);
9835 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9840 + if (unlikely(au_digen(dentry) != sigen
9841 + || au_iigen_test(d_inode(dentry), sigen)))
9847 +void au_update_digen(struct dentry *dentry)
9849 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9850 + /* smp_mb(); */ /* atomic_set */
9853 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9855 + struct au_dinfo *dinfo;
9856 + struct dentry *h_d;
9857 + struct au_hdentry *hdp;
9858 + aufs_bindex_t bindex, bbot;
9860 + DiMustWriteLock(dentry);
9862 + dinfo = au_di(dentry);
9863 + if (!dinfo || dinfo->di_btop < 0)
9866 + if (do_put_zero) {
9867 + bbot = dinfo->di_bbot;
9868 + bindex = dinfo->di_btop;
9869 + hdp = au_hdentry(dinfo, bindex);
9870 + for (; bindex <= bbot; bindex++, hdp++) {
9871 + h_d = hdp->hd_dentry;
9872 + if (h_d && d_is_negative(h_d))
9873 + au_set_h_dptr(dentry, bindex, NULL);
9877 + dinfo->di_btop = 0;
9878 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9879 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9880 + if (hdp->hd_dentry)
9882 + if (dinfo->di_btop > dinfo->di_bbot) {
9883 + dinfo->di_btop = -1;
9884 + dinfo->di_bbot = -1;
9888 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9889 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9890 + if (hdp->hd_dentry)
9892 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9895 +void au_update_dbtop(struct dentry *dentry)
9897 + aufs_bindex_t bindex, bbot;
9898 + struct dentry *h_dentry;
9900 + bbot = au_dbbot(dentry);
9901 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9902 + h_dentry = au_h_dptr(dentry, bindex);
9905 + if (d_is_positive(h_dentry)) {
9906 + au_set_dbtop(dentry, bindex);
9909 + au_set_h_dptr(dentry, bindex, NULL);
9913 +void au_update_dbbot(struct dentry *dentry)
9915 + aufs_bindex_t bindex, btop;
9916 + struct dentry *h_dentry;
9918 + btop = au_dbtop(dentry);
9919 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9920 + h_dentry = au_h_dptr(dentry, bindex);
9923 + if (d_is_positive(h_dentry)) {
9924 + au_set_dbbot(dentry, bindex);
9927 + au_set_h_dptr(dentry, bindex, NULL);
9931 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9933 + aufs_bindex_t bindex, bbot;
9935 + bbot = au_dbbot(dentry);
9936 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9937 + if (au_h_dptr(dentry, bindex) == h_dentry)
9941 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9942 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9943 +++ linux/fs/aufs/dir.c 2022-03-21 14:49:05.719966344 +0100
9945 +// SPDX-License-Identifier: GPL-2.0
9947 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9949 + * This program, aufs is free software; you can redistribute it and/or modify
9950 + * it under the terms of the GNU General Public License as published by
9951 + * the Free Software Foundation; either version 2 of the License, or
9952 + * (at your option) any later version.
9954 + * This program is distributed in the hope that it will be useful,
9955 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9956 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9957 + * GNU General Public License for more details.
9959 + * You should have received a copy of the GNU General Public License
9960 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9964 + * directory operations
9967 +#include <linux/fs_stack.h>
9968 +#include <linux/iversion.h>
9971 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9973 + unsigned int nlink;
9975 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9977 + nlink = dir->i_nlink;
9978 + nlink += h_dir->i_nlink - 2;
9979 + if (h_dir->i_nlink < 2)
9981 + smp_mb(); /* for i_nlink */
9982 + /* 0 can happen in revaliding */
9983 + set_nlink(dir, nlink);
9986 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9988 + unsigned int nlink;
9990 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9992 + nlink = dir->i_nlink;
9993 + nlink -= h_dir->i_nlink - 2;
9994 + if (h_dir->i_nlink < 2)
9996 + smp_mb(); /* for i_nlink */
9997 + /* nlink == 0 means the branch-fs is broken */
9998 + set_nlink(dir, nlink);
10001 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10004 + aufs_bindex_t bindex, bbot;
10005 + struct file *h_file;
10006 + struct dentry *h_dentry;
10010 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10012 + bbot = au_fbbot_dir(file);
10013 + for (bindex = au_fbtop(file);
10014 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10016 + h_file = au_hf_dir(file, bindex);
10017 + if (h_file && file_inode(h_file))
10018 + sz += vfsub_f_size_read(h_file);
10021 + AuDebugOn(!dentry);
10022 + AuDebugOn(!d_is_dir(dentry));
10024 + bbot = au_dbtaildir(dentry);
10025 + for (bindex = au_dbtop(dentry);
10026 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10028 + h_dentry = au_h_dptr(dentry, bindex);
10029 + if (h_dentry && d_is_positive(h_dentry))
10030 + sz += i_size_read(d_inode(h_dentry));
10033 + if (sz < KMALLOC_MAX_SIZE)
10034 + sz = roundup_pow_of_two(sz);
10035 + if (sz > KMALLOC_MAX_SIZE)
10036 + sz = KMALLOC_MAX_SIZE;
10037 + else if (sz < NAME_MAX) {
10038 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10039 + sz = AUFS_RDBLK_DEF;
10044 +struct au_dir_ts_arg {
10045 + struct dentry *dentry;
10046 + aufs_bindex_t brid;
10049 +static void au_do_dir_ts(void *arg)
10051 + struct au_dir_ts_arg *a = arg;
10052 + struct au_dtime dt;
10053 + struct path h_path;
10054 + struct inode *dir, *h_dir;
10055 + struct super_block *sb;
10056 + struct au_branch *br;
10057 + struct au_hinode *hdir;
10059 + aufs_bindex_t btop, bindex;
10061 + sb = a->dentry->d_sb;
10062 + if (d_really_is_negative(a->dentry))
10064 + /* no dir->i_mutex lock */
10065 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10067 + dir = d_inode(a->dentry);
10068 + btop = au_ibtop(dir);
10069 + bindex = au_br_index(sb, a->brid);
10070 + if (bindex < btop)
10073 + br = au_sbr(sb, bindex);
10074 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10075 + if (!h_path.dentry)
10077 + h_path.mnt = au_br_mnt(br);
10078 + au_dtime_store(&dt, a->dentry, &h_path);
10080 + br = au_sbr(sb, btop);
10081 + if (!au_br_writable(br->br_perm))
10083 + h_path.dentry = au_h_dptr(a->dentry, btop);
10084 + h_path.mnt = au_br_mnt(br);
10085 + err = vfsub_mnt_want_write(h_path.mnt);
10088 + hdir = au_hi(dir, btop);
10089 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10090 + h_dir = au_h_iptr(dir, btop);
10091 + if (h_dir->i_nlink
10092 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10093 + dt.dt_h_path = h_path;
10094 + au_dtime_revert(&dt);
10096 + au_hn_inode_unlock(hdir);
10097 + vfsub_mnt_drop_write(h_path.mnt);
10098 + au_cpup_attr_timesizes(dir);
10101 + aufs_read_unlock(a->dentry, AuLock_DW);
10104 + au_nwt_done(&au_sbi(sb)->si_nowait);
10105 + au_kfree_try_rcu(arg);
10108 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10110 + int perm, wkq_err;
10111 + aufs_bindex_t btop;
10112 + struct au_dir_ts_arg *arg;
10113 + struct dentry *dentry;
10114 + struct super_block *sb;
10118 + dentry = d_find_any_alias(dir);
10119 + AuDebugOn(!dentry);
10120 + sb = dentry->d_sb;
10121 + btop = au_ibtop(dir);
10122 + if (btop == bindex) {
10123 + au_cpup_attr_timesizes(dir);
10127 + perm = au_sbr_perm(sb, btop);
10128 + if (!au_br_writable(perm))
10131 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10135 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10136 + arg->brid = au_sbr_id(sb, bindex);
10137 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10138 + if (unlikely(wkq_err)) {
10139 + pr_err("wkq %d\n", wkq_err);
10141 + au_kfree_try_rcu(arg);
10148 +/* ---------------------------------------------------------------------- */
10150 +static int reopen_dir(struct file *file)
10153 + unsigned int flags;
10154 + aufs_bindex_t bindex, btail, btop;
10155 + struct dentry *dentry, *h_dentry;
10156 + struct file *h_file;
10158 + /* open all lower dirs */
10159 + dentry = file->f_path.dentry;
10160 + btop = au_dbtop(dentry);
10161 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10162 + au_set_h_fptr(file, bindex, NULL);
10163 + au_set_fbtop(file, btop);
10165 + btail = au_dbtaildir(dentry);
10166 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10167 + au_set_h_fptr(file, bindex, NULL);
10168 + au_set_fbbot_dir(file, btail);
10170 + flags = vfsub_file_flags(file);
10171 + for (bindex = btop; bindex <= btail; bindex++) {
10172 + h_dentry = au_h_dptr(dentry, bindex);
10175 + h_file = au_hf_dir(file, bindex);
10179 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10180 + err = PTR_ERR(h_file);
10181 + if (IS_ERR(h_file))
10182 + goto out; /* close all? */
10183 + au_set_h_fptr(file, bindex, h_file);
10185 + au_update_figen(file);
10186 + /* todo: necessary? */
10187 + /* file->f_ra = h_file->f_ra; */
10194 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10197 + aufs_bindex_t bindex, btail;
10198 + struct dentry *dentry, *h_dentry;
10199 + struct vfsmount *mnt;
10201 + FiMustWriteLock(file);
10202 + AuDebugOn(h_file);
10205 + mnt = file->f_path.mnt;
10206 + dentry = file->f_path.dentry;
10207 + file->f_version = inode_query_iversion(d_inode(dentry));
10208 + bindex = au_dbtop(dentry);
10209 + au_set_fbtop(file, bindex);
10210 + btail = au_dbtaildir(dentry);
10211 + au_set_fbbot_dir(file, btail);
10212 + for (; !err && bindex <= btail; bindex++) {
10213 + h_dentry = au_h_dptr(dentry, bindex);
10217 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10218 + if (unlikely(err))
10220 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10221 + if (IS_ERR(h_file)) {
10222 + err = PTR_ERR(h_file);
10225 + au_set_h_fptr(file, bindex, h_file);
10227 + au_update_figen(file);
10228 + /* todo: necessary? */
10229 + /* file->f_ra = h_file->f_ra; */
10231 + return 0; /* success */
10234 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10235 + au_set_h_fptr(file, bindex, NULL);
10236 + au_set_fbtop(file, -1);
10237 + au_set_fbbot_dir(file, -1);
10242 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10243 + struct file *file)
10246 + struct super_block *sb;
10247 + struct au_fidir *fidir;
10250 + sb = file->f_path.dentry->d_sb;
10251 + si_read_lock(sb, AuLock_FLUSH);
10252 + fidir = au_fidir_alloc(sb);
10254 + struct au_do_open_args args = {
10255 + .open = do_open_dir,
10258 + err = au_do_open(file, &args);
10259 + if (unlikely(err))
10260 + au_kfree_rcu(fidir);
10262 + si_read_unlock(sb);
10266 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10267 + struct file *file)
10269 + struct au_vdir *vdir_cache;
10270 + struct au_finfo *finfo;
10271 + struct au_fidir *fidir;
10272 + struct au_hfile *hf;
10273 + aufs_bindex_t bindex, bbot;
10275 + finfo = au_fi(file);
10276 + fidir = finfo->fi_hdir;
10278 + au_hbl_del(&finfo->fi_hlist,
10279 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10280 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10282 + au_vdir_free(vdir_cache);
10284 + bindex = finfo->fi_btop;
10285 + if (bindex >= 0) {
10286 + hf = fidir->fd_hfile + bindex;
10288 + * calls fput() instead of filp_close(),
10289 + * since no dnotify or lock for the lower file.
10291 + bbot = fidir->fd_bbot;
10292 + for (; bindex <= bbot; bindex++, hf++)
10294 + au_hfput(hf, /*execed*/0);
10296 + au_kfree_rcu(fidir);
10297 + finfo->fi_hdir = NULL;
10299 + au_finfo_fin(file);
10303 +/* ---------------------------------------------------------------------- */
10305 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10308 + aufs_bindex_t bindex, bbot;
10309 + struct file *h_file;
10312 + bbot = au_fbbot_dir(file);
10313 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10314 + h_file = au_hf_dir(file, bindex);
10316 + err = vfsub_flush(h_file, id);
10321 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10323 + return au_do_flush(file, id, au_do_flush_dir);
10326 +/* ---------------------------------------------------------------------- */
10328 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10331 + aufs_bindex_t bbot, bindex;
10332 + struct inode *inode;
10333 + struct super_block *sb;
10336 + sb = dentry->d_sb;
10337 + inode = d_inode(dentry);
10338 + IMustLock(inode);
10339 + bbot = au_dbbot(dentry);
10340 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10341 + struct path h_path;
10343 + if (au_test_ro(sb, bindex, inode))
10345 + h_path.dentry = au_h_dptr(dentry, bindex);
10346 + if (!h_path.dentry)
10349 + h_path.mnt = au_sbr_mnt(sb, bindex);
10350 + err = vfsub_fsync(NULL, &h_path, datasync);
10356 +static int au_do_fsync_dir(struct file *file, int datasync)
10359 + aufs_bindex_t bbot, bindex;
10360 + struct file *h_file;
10361 + struct super_block *sb;
10362 + struct inode *inode;
10364 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10365 + if (unlikely(err))
10368 + inode = file_inode(file);
10369 + sb = inode->i_sb;
10370 + bbot = au_fbbot_dir(file);
10371 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10372 + h_file = au_hf_dir(file, bindex);
10373 + if (!h_file || au_test_ro(sb, bindex, inode))
10376 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10384 + * @file may be NULL
10386 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10390 + struct dentry *dentry;
10391 + struct inode *inode;
10392 + struct super_block *sb;
10395 + dentry = file->f_path.dentry;
10396 + inode = d_inode(dentry);
10397 + inode_lock(inode);
10398 + sb = dentry->d_sb;
10399 + si_noflush_read_lock(sb);
10401 + err = au_do_fsync_dir(file, datasync);
10403 + di_write_lock_child(dentry);
10404 + err = au_do_fsync_dir_no_file(dentry, datasync);
10406 + au_cpup_attr_timesizes(inode);
10407 + di_write_unlock(dentry);
10409 + fi_write_unlock(file);
10411 + si_read_unlock(sb);
10412 + inode_unlock(inode);
10416 +/* ---------------------------------------------------------------------- */
10418 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10421 + struct dentry *dentry;
10422 + struct inode *inode, *h_inode;
10423 + struct super_block *sb;
10425 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10427 + dentry = file->f_path.dentry;
10428 + inode = d_inode(dentry);
10429 + IMustLock(inode);
10431 + sb = dentry->d_sb;
10432 + si_read_lock(sb, AuLock_FLUSH);
10433 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10434 + if (unlikely(err))
10436 + err = au_alive_dir(dentry);
10438 + err = au_vdir_init(file);
10439 + di_downgrade_lock(dentry, AuLock_IR);
10440 + if (unlikely(err))
10443 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10444 + if (!au_test_nfsd()) {
10445 + err = au_vdir_fill_de(file, ctx);
10446 + fsstack_copy_attr_atime(inode, h_inode);
10449 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10450 + * encode_fh() and others.
10452 + atomic_inc(&h_inode->i_count);
10453 + di_read_unlock(dentry, AuLock_IR);
10454 + si_read_unlock(sb);
10455 + err = au_vdir_fill_de(file, ctx);
10456 + fsstack_copy_attr_atime(inode, h_inode);
10457 + fi_write_unlock(file);
10465 + di_read_unlock(dentry, AuLock_IR);
10466 + fi_write_unlock(file);
10468 + si_read_unlock(sb);
10472 +/* ---------------------------------------------------------------------- */
10474 +#define AuTestEmpty_WHONLY 1
10475 +#define AuTestEmpty_CALLED (1 << 1)
10476 +#define AuTestEmpty_SHWH (1 << 2)
10477 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10478 +#define au_fset_testempty(flags, name) \
10479 + do { (flags) |= AuTestEmpty_##name; } while (0)
10480 +#define au_fclr_testempty(flags, name) \
10481 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10483 +#ifndef CONFIG_AUFS_SHWH
10484 +#undef AuTestEmpty_SHWH
10485 +#define AuTestEmpty_SHWH 0
10488 +struct test_empty_arg {
10489 + struct dir_context ctx;
10490 + struct au_nhash *whlist;
10491 + unsigned int flags;
10493 + aufs_bindex_t bindex;
10496 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10497 + int namelen, loff_t offset __maybe_unused, u64 ino,
10498 + unsigned int d_type)
10500 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10502 + char *name = (void *)__name;
10505 + au_fset_testempty(arg->flags, CALLED);
10507 + if (name[0] == '.'
10508 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10509 + goto out; /* success */
10511 + if (namelen <= AUFS_WH_PFX_LEN
10512 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10513 + if (au_ftest_testempty(arg->flags, WHONLY)
10514 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10515 + arg->err = -ENOTEMPTY;
10519 + name += AUFS_WH_PFX_LEN;
10520 + namelen -= AUFS_WH_PFX_LEN;
10521 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10522 + arg->err = au_nhash_append_wh
10523 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10524 + au_ftest_testempty(arg->flags, SHWH));
10528 + AuTraceErr(arg->err);
10532 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10535 + struct file *h_file;
10536 + struct au_branch *br;
10538 + h_file = au_h_open(dentry, arg->bindex,
10539 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10540 + /*file*/NULL, /*force_wr*/0);
10541 + err = PTR_ERR(h_file);
10542 + if (IS_ERR(h_file))
10546 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10547 + && !file_inode(h_file)->i_nlink)
10552 + au_fclr_testempty(arg->flags, CALLED);
10554 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10557 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10561 + br = au_sbr(dentry->d_sb, arg->bindex);
10562 + au_lcnt_dec(&br->br_nfiles);
10567 +struct do_test_empty_args {
10569 + struct dentry *dentry;
10570 + struct test_empty_arg *arg;
10573 +static void call_do_test_empty(void *args)
10575 + struct do_test_empty_args *a = args;
10576 + *a->errp = do_test_empty(a->dentry, a->arg);
10579 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10581 + int err, wkq_err;
10582 + struct dentry *h_dentry;
10583 + struct inode *h_inode;
10584 + struct user_namespace *h_userns;
10586 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10587 + h_dentry = au_h_dptr(dentry, arg->bindex);
10588 + h_inode = d_inode(h_dentry);
10589 + /* todo: i_mode changes anytime? */
10590 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10591 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10592 + inode_unlock_shared(h_inode);
10594 + err = do_test_empty(dentry, arg);
10596 + struct do_test_empty_args args = {
10598 + .dentry = dentry,
10601 + unsigned int flags = arg->flags;
10603 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10604 + if (unlikely(wkq_err))
10606 + arg->flags = flags;
10612 +int au_test_empty_lower(struct dentry *dentry)
10615 + unsigned int rdhash;
10616 + aufs_bindex_t bindex, btop, btail;
10617 + struct au_nhash whlist;
10618 + struct test_empty_arg arg = {
10620 + .actor = test_empty_cb
10623 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10625 + SiMustAnyLock(dentry->d_sb);
10627 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10629 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10630 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10631 + if (unlikely(err))
10635 + arg.whlist = &whlist;
10636 + btop = au_dbtop(dentry);
10637 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10638 + au_fset_testempty(arg.flags, SHWH);
10639 + test_empty = do_test_empty;
10640 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10641 + test_empty = sio_test_empty;
10642 + arg.bindex = btop;
10643 + err = test_empty(dentry, &arg);
10644 + if (unlikely(err))
10647 + au_fset_testempty(arg.flags, WHONLY);
10648 + btail = au_dbtaildir(dentry);
10649 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10650 + struct dentry *h_dentry;
10652 + h_dentry = au_h_dptr(dentry, bindex);
10653 + if (h_dentry && d_is_positive(h_dentry)) {
10654 + arg.bindex = bindex;
10655 + err = test_empty(dentry, &arg);
10660 + au_nhash_wh_free(&whlist);
10665 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10668 + struct test_empty_arg arg = {
10670 + .actor = test_empty_cb
10673 + aufs_bindex_t bindex, btail;
10676 + arg.whlist = whlist;
10677 + arg.flags = AuTestEmpty_WHONLY;
10678 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10679 + au_fset_testempty(arg.flags, SHWH);
10680 + btail = au_dbtaildir(dentry);
10681 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10682 + struct dentry *h_dentry;
10684 + h_dentry = au_h_dptr(dentry, bindex);
10685 + if (h_dentry && d_is_positive(h_dentry)) {
10686 + arg.bindex = bindex;
10687 + err = sio_test_empty(dentry, &arg);
10694 +/* ---------------------------------------------------------------------- */
10696 +const struct file_operations aufs_dir_fop = {
10697 + .owner = THIS_MODULE,
10698 + .llseek = default_llseek,
10699 + .read = generic_read_dir,
10700 + .iterate_shared = aufs_iterate_shared,
10701 + .unlocked_ioctl = aufs_ioctl_dir,
10702 +#ifdef CONFIG_COMPAT
10703 + .compat_ioctl = aufs_compat_ioctl_dir,
10705 + .open = aufs_open_dir,
10706 + .release = aufs_release_dir,
10707 + .flush = aufs_flush_dir,
10708 + .fsync = aufs_fsync_dir
10710 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10711 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10712 +++ linux/fs/aufs/dir.h 2022-03-21 14:49:05.719966344 +0100
10714 +/* SPDX-License-Identifier: GPL-2.0 */
10716 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10718 + * This program, aufs is free software; you can redistribute it and/or modify
10719 + * it under the terms of the GNU General Public License as published by
10720 + * the Free Software Foundation; either version 2 of the License, or
10721 + * (at your option) any later version.
10723 + * This program is distributed in the hope that it will be useful,
10724 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10725 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10726 + * GNU General Public License for more details.
10728 + * You should have received a copy of the GNU General Public License
10729 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10733 + * directory operations
10736 +#ifndef __AUFS_DIR_H__
10737 +#define __AUFS_DIR_H__
10741 +#include <linux/fs.h>
10743 +/* ---------------------------------------------------------------------- */
10745 +/* need to be faster and smaller */
10748 + unsigned int nh_num;
10749 + struct hlist_head *nh_head;
10752 +struct au_vdir_destr {
10753 + unsigned char len;
10754 + unsigned char name[];
10757 +struct au_vdir_dehstr {
10758 + struct hlist_node hash;
10759 + struct au_vdir_destr *str;
10760 + struct rcu_head rcu;
10761 +} ____cacheline_aligned_in_smp;
10763 +struct au_vdir_de {
10765 + unsigned char de_type;
10766 + /* caution: packed */
10767 + struct au_vdir_destr de_str;
10770 +struct au_vdir_wh {
10771 + struct hlist_node wh_hash;
10772 +#ifdef CONFIG_AUFS_SHWH
10774 + aufs_bindex_t wh_bindex;
10775 + unsigned char wh_type;
10777 + aufs_bindex_t wh_bindex;
10779 + /* caution: packed */
10780 + struct au_vdir_destr wh_str;
10783 +union au_vdir_deblk_p {
10784 + unsigned char *deblk;
10785 + struct au_vdir_de *de;
10789 + unsigned char **vd_deblk;
10790 + unsigned long vd_nblk;
10792 + unsigned long ul;
10793 + union au_vdir_deblk_p p;
10797 + unsigned int vd_deblk_sz;
10798 + unsigned long vd_jiffy;
10799 + struct rcu_head rcu;
10800 +} ____cacheline_aligned_in_smp;
10802 +/* ---------------------------------------------------------------------- */
10805 +extern const struct file_operations aufs_dir_fop;
10806 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10807 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10808 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10809 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10810 +int au_test_empty_lower(struct dentry *dentry);
10811 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10814 +unsigned int au_rdhash_est(loff_t sz);
10815 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10816 +void au_nhash_wh_free(struct au_nhash *whlist);
10817 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10819 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10820 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10821 + unsigned int d_type, aufs_bindex_t bindex,
10822 + unsigned char shwh);
10823 +void au_vdir_free(struct au_vdir *vdir);
10824 +int au_vdir_init(struct file *file);
10825 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10828 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10830 +#ifdef CONFIG_AUFS_RDU
10832 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10833 +#ifdef CONFIG_COMPAT
10834 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10835 + unsigned long arg);
10838 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10839 + unsigned int cmd, unsigned long arg)
10840 +#ifdef CONFIG_COMPAT
10841 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10842 + unsigned int cmd, unsigned long arg)
10846 +#endif /* __KERNEL__ */
10847 +#endif /* __AUFS_DIR_H__ */
10848 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10849 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10850 +++ linux/fs/aufs/dirren.c 2022-03-21 14:49:05.723299677 +0100
10852 +// SPDX-License-Identifier: GPL-2.0
10854 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10856 + * This program, aufs is free software; you can redistribute it and/or modify
10857 + * it under the terms of the GNU General Public License as published by
10858 + * the Free Software Foundation; either version 2 of the License, or
10859 + * (at your option) any later version.
10861 + * This program is distributed in the hope that it will be useful,
10862 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10863 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10864 + * GNU General Public License for more details.
10866 + * You should have received a copy of the GNU General Public License
10867 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10871 + * special handling in renaming a directory
10872 + * in order to support looking-up the before-renamed name on the lower readonly
10876 +#include <linux/byteorder/generic.h>
10879 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10883 + idx = au_dr_ihash(ent->dr_h_ino);
10884 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10887 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10890 + struct hlist_bl_head *hbl;
10893 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10894 + hbl = dr->dr_h_ino + i;
10895 + hlist_bl_lock(hbl);
10896 + ret &= hlist_bl_empty(hbl);
10897 + hlist_bl_unlock(hbl);
10903 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10905 + struct au_dr_hino *found, *ent;
10906 + struct hlist_bl_head *hbl;
10907 + struct hlist_bl_node *pos;
10911 + idx = au_dr_ihash(ino);
10912 + hbl = dr->dr_h_ino + idx;
10913 + hlist_bl_lock(hbl);
10914 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10915 + if (ent->dr_h_ino == ino) {
10919 + hlist_bl_unlock(hbl);
10924 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10925 + struct au_dr_hino *add_ent)
10928 + struct hlist_bl_head *hbl;
10929 + struct hlist_bl_node *pos;
10930 + struct au_dr_hino *ent;
10933 + idx = au_dr_ihash(ino);
10934 + hbl = dr->dr_h_ino + idx;
10935 +#if 0 /* debug print */
10937 + struct hlist_bl_node *tmp;
10939 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10940 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10943 + hlist_bl_lock(hbl);
10944 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10945 + if (ent->dr_h_ino == ino) {
10949 + if (!found && add_ent)
10950 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10951 + hlist_bl_unlock(hbl);
10953 + if (!found && add_ent)
10954 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10959 +void au_dr_hino_free(struct au_dr_br *dr)
10962 + struct hlist_bl_head *hbl;
10963 + struct hlist_bl_node *pos, *tmp;
10964 + struct au_dr_hino *ent;
10966 + /* SiMustWriteLock(sb); */
10968 + for (i = 0; i < AuDirren_NHASH; i++) {
10969 + hbl = dr->dr_h_ino + i;
10970 + /* no spinlock since sbinfo must be write-locked */
10971 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10972 + au_kfree_rcu(ent);
10973 + INIT_HLIST_BL_HEAD(hbl);
10977 +/* returns the number of inodes or an error */
10978 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10979 + struct file *hinofile)
10983 + loff_t pos, oldsize;
10985 + struct inode *hinoinode;
10986 + struct hlist_bl_head *hbl;
10987 + struct hlist_bl_node *n1, *n2;
10988 + struct au_dr_hino *ent;
10990 + SiMustWriteLock(sb);
10991 + AuDebugOn(!au_br_writable(br->br_perm));
10993 + hinoinode = file_inode(hinofile);
10994 + oldsize = i_size_read(hinoinode);
10998 + hbl = br->br_dirren.dr_h_ino;
10999 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11000 + /* no bit-lock since sbinfo must be write-locked */
11001 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11002 + AuDbg("hi%llu, %pD2\n",
11003 + (unsigned long long)ent->dr_h_ino, hinofile);
11004 + u64 = cpu_to_be64(ent->dr_h_ino);
11005 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11006 + if (ssz == sizeof(u64))
11009 + /* write error */
11010 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11017 + /* regardless the error */
11018 + if (pos < oldsize) {
11019 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11027 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11034 + struct au_dr_hino *ent;
11035 + struct inode *hinoinode;
11036 + struct hlist_bl_head *hbl;
11040 + hbl = dr->dr_h_ino;
11041 + hinoinode = file_inode(hinofile);
11042 + sz = i_size_read(hinoinode);
11043 + AuDebugOn(sz % sizeof(u64));
11044 + n = sz / sizeof(u64);
11046 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11047 + if (unlikely(ssz != sizeof(u64))) {
11048 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11055 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11061 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11062 + AuDbg("hi%llu, %pD2\n",
11063 + (unsigned long long)ent->dr_h_ino, hinofile);
11064 + hidx = au_dr_ihash(ent->dr_h_ino);
11065 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11067 + goto out; /* success */
11070 + au_dr_hino_free(dr);
11077 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11078 + * @path is a switch to distinguish load and store.
11080 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11081 + struct au_branch *br, const struct path *path)
11084 + unsigned char load, suspend;
11085 + struct file *hinofile;
11086 + struct au_hinode *hdir;
11087 + struct inode *dir, *delegated;
11088 + struct path hinopath;
11089 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11090 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11092 + AuDebugOn(bindex < 0 && !br);
11093 + AuDebugOn(bindex >= 0 && br);
11098 + br = au_sbr(sb, bindex);
11101 + path = &br->br_path;
11102 + AuDebugOn(!au_br_writable(br->br_perm));
11103 + if (unlikely(!au_br_writable(br->br_perm)))
11109 + dir = d_inode(sb->s_root);
11110 + hdir = au_hinode(au_ii(dir), bindex);
11111 + dir = hdir->hi_inode;
11112 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11114 + dir = d_inode(path->dentry);
11115 + inode_lock_nested(dir, AuLsc_I_CHILD);
11117 + hinopath.mnt = path->mnt;
11118 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11119 + err = PTR_ERR(hinopath.dentry);
11120 + if (IS_ERR(hinopath.dentry))
11124 + flags = O_RDONLY;
11126 + if (d_is_negative(hinopath.dentry))
11127 + goto out_dput; /* success */
11129 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11130 + if (d_is_positive(hinopath.dentry)) {
11131 + delegated = NULL;
11132 + err = vfsub_unlink(dir, &hinopath, &delegated,
11135 + if (unlikely(err))
11136 + pr_err("ignored err %d, %pd2\n",
11137 + err, hinopath.dentry);
11138 + if (unlikely(err == -EWOULDBLOCK))
11143 + } else if (!d_is_positive(hinopath.dentry)) {
11144 + err = vfsub_create(dir, &hinopath, 0600,
11145 + /*want_excl*/false);
11147 + if (unlikely(err))
11150 + flags = O_WRONLY;
11152 + hinofile = vfsub_dentry_open(&hinopath, flags);
11154 + au_hn_inode_unlock(hdir);
11156 + inode_unlock(dir);
11157 + dput(hinopath.dentry);
11158 + AuTraceErrPtr(hinofile);
11159 + if (IS_ERR(hinofile)) {
11160 + err = PTR_ERR(hinofile);
11165 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11167 + err = au_dr_hino_store(sb, br, hinofile);
11172 + dput(hinopath.dentry);
11175 + au_hn_inode_unlock(hdir);
11177 + inode_unlock(dir);
11183 +/* ---------------------------------------------------------------------- */
11185 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11188 + struct kstatfs kstfs;
11190 + struct dentry *dentry;
11191 + struct super_block *sb;
11193 + err = vfs_statfs((void *)path, &kstfs);
11195 + if (unlikely(err))
11198 + /* todo: support for UUID */
11200 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11201 + brid->type = AuBrid_FSID;
11202 + brid->fsid = kstfs.f_fsid;
11204 + dentry = path->dentry;
11205 + sb = dentry->d_sb;
11208 + brid->type = AuBrid_DEV;
11217 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11218 + const struct path *path)
11221 + struct au_dr_br *dr;
11222 + struct hlist_bl_head *hbl;
11224 + dr = &br->br_dirren;
11225 + hbl = dr->dr_h_ino;
11226 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11227 + INIT_HLIST_BL_HEAD(hbl);
11229 + err = au_dr_brid_init(&dr->dr_brid, path);
11230 + if (unlikely(err))
11233 + if (au_opt_test(au_mntflags(sb), DIRREN))
11234 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11241 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11246 + if (au_br_writable(br->br_perm))
11247 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11249 + au_dr_hino_free(&br->br_dirren);
11254 +/* ---------------------------------------------------------------------- */
11256 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11257 + char *buf, size_t sz)
11260 + unsigned int major, minor;
11264 + err = snprintf(p, sz, "%d_", brid->type);
11265 + AuDebugOn(err > sz);
11268 + switch (brid->type) {
11269 + case AuBrid_Unset:
11271 + case AuBrid_UUID:
11272 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11274 + case AuBrid_FSID:
11275 + err = snprintf(p, sz, "%08x-%08x",
11276 + brid->fsid.val[0], brid->fsid.val[1]);
11279 + major = MAJOR(brid->dev);
11280 + minor = MINOR(brid->dev);
11281 + if (major <= 0xff && minor <= 0xff)
11282 + err = snprintf(p, sz, "%02x%02x", major, minor);
11284 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11287 + AuDebugOn(err > sz);
11290 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11291 + AuDebugOn(err > sz);
11298 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11301 + struct dentry *br_dentry;
11302 + struct inode *br_inode;
11304 + br_dentry = au_br_dentry(br);
11305 + br_inode = d_inode(br_dentry);
11306 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11307 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11308 + AuDebugOn(rlen > len);
11313 +/* ---------------------------------------------------------------------- */
11316 + * from the given @h_dentry, construct drinfo at @*fdata.
11317 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11320 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11321 + struct dentry *h_dentry,
11322 + unsigned char *allocated)
11325 + struct au_drinfo_fdata *f, *p;
11326 + struct au_drinfo *drinfo;
11327 + struct inode *h_inode;
11328 + struct qstr *qname;
11332 + h_inode = d_inode(h_dentry);
11333 + qname = &h_dentry->d_name;
11334 + drinfo = &f->drinfo;
11335 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11336 + drinfo->oldnamelen = qname->len;
11337 + if (*allocated < sizeof(*f) + qname->len) {
11338 + v = roundup_pow_of_two(*allocated + qname->len);
11339 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11340 + if (unlikely(!p)) {
11348 + drinfo = &f->drinfo;
11350 + memcpy(drinfo->oldname, qname->name, qname->len);
11351 + AuDbg("i%llu, %.*s\n",
11352 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11353 + drinfo->oldname);
11360 +/* callers have to free the return value */
11361 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11363 + struct au_drinfo *ret, *drinfo;
11364 + struct au_drinfo_fdata fdata;
11369 + ret = ERR_PTR(-EIO);
11371 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11372 + if (unlikely(ssz != sizeof(fdata))) {
11373 + AuIOErr("ssz %zd, %u, %pD2\n",
11374 + ssz, (unsigned int)sizeof(fdata), file);
11378 + fdata.magic = ntohl((__force __be32)fdata.magic);
11379 + switch (fdata.magic) {
11380 + case AUFS_DRINFO_MAGIC_V1:
11383 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11384 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11388 + drinfo = &fdata.drinfo;
11389 + len = drinfo->oldnamelen;
11391 + AuIOErr("broken drinfo %pD2\n", file);
11396 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11397 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11398 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11399 + (unsigned long long)drinfo->ino,
11400 + (unsigned long long)h_ino, file);
11401 + goto out; /* success */
11404 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11405 + if (unlikely(!ret)) {
11406 + ret = ERR_PTR(-ENOMEM);
11407 + AuTraceErrPtr(ret);
11412 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11413 + if (unlikely(ssz != len)) {
11414 + au_kfree_rcu(ret);
11415 + ret = ERR_PTR(-EIO);
11416 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11420 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11426 +/* ---------------------------------------------------------------------- */
11428 +/* in order to be revertible */
11429 +struct au_drinfo_rev_elm {
11431 + struct dentry *info_dentry;
11432 + struct au_drinfo *info_last;
11435 +struct au_drinfo_rev {
11436 + unsigned char already;
11437 + aufs_bindex_t nelm;
11438 + struct au_drinfo_rev_elm elm[];
11441 +/* todo: isn't it too large? */
11442 +struct au_drinfo_store {
11443 + struct path h_ppath;
11444 + struct dentry *h_dentry;
11445 + struct au_drinfo_fdata *fdata;
11446 + char *infoname; /* inside of whname, just after PFX */
11447 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11448 + aufs_bindex_t btgt, btail;
11449 + unsigned char no_sio,
11450 + allocated, /* current size of *fdata */
11451 + infonamelen, /* room size for p */
11452 + whnamelen, /* length of the generated name */
11453 + renameback; /* renamed back */
11456 +/* on rename(2) error, the caller should revert it using @elm */
11457 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11458 + struct au_drinfo_rev_elm *elm)
11463 + struct path infopath = {
11464 + .mnt = w->h_ppath.mnt
11466 + struct inode *h_dir, *h_inode, *delegated;
11467 + struct file *infofile;
11468 + struct qstr *qname;
11471 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11473 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11475 + AuTraceErrPtr(infopath.dentry);
11476 + if (IS_ERR(infopath.dentry)) {
11477 + err = PTR_ERR(infopath.dentry);
11482 + h_dir = d_inode(w->h_ppath.dentry);
11483 + if (elm && d_is_negative(infopath.dentry)) {
11484 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11486 + if (unlikely(err))
11488 + elm->created = 1;
11489 + elm->info_dentry = dget(infopath.dentry);
11492 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11493 + AuTraceErrPtr(infofile);
11494 + if (IS_ERR(infofile)) {
11495 + err = PTR_ERR(infofile);
11499 + h_inode = d_inode(infopath.dentry);
11500 + if (elm && i_size_read(h_inode)) {
11501 + h_inode = d_inode(w->h_dentry);
11502 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11503 + AuTraceErrPtr(elm->info_last);
11504 + if (IS_ERR(elm->info_last)) {
11505 + err = PTR_ERR(elm->info_last);
11506 + elm->info_last = NULL;
11507 + AuDebugOn(elm->info_dentry);
11512 + if (elm && w->renameback) {
11513 + delegated = NULL;
11514 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11516 + if (unlikely(err == -EWOULDBLOCK))
11522 + qname = &w->h_dentry->d_name;
11523 + len = sizeof(*w->fdata) + qname->len;
11525 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11526 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11527 + if (ssz == len) {
11528 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11529 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11530 + goto out_fput; /* success */
11535 + /* the caller should revert it using @elm */
11541 + dput(infopath.dentry);
11547 +struct au_call_drinfo_do_store_args {
11549 + struct au_drinfo_store *w;
11550 + struct au_drinfo_rev_elm *elm;
11553 +static void au_call_drinfo_do_store(void *args)
11555 + struct au_call_drinfo_do_store_args *a = args;
11557 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11560 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11561 + struct au_drinfo_rev_elm *elm)
11563 + int err, wkq_err;
11566 + err = au_drinfo_do_store(w, elm);
11568 + struct au_call_drinfo_do_store_args a = {
11573 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11574 + if (unlikely(wkq_err))
11582 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11583 + aufs_bindex_t btgt)
11587 + memset(w, 0, sizeof(*w));
11588 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11589 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11590 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11591 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11593 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11596 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11597 + if (unlikely(!w->fdata)) {
11601 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11608 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11610 + au_kfree_rcu(w->fdata);
11613 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11614 + struct au_drinfo_store *w)
11616 + struct au_drinfo_rev_elm *elm;
11617 + struct inode *h_dir, *delegated;
11619 + struct path infopath = {
11620 + .mnt = w->h_ppath.mnt
11623 + h_dir = d_inode(w->h_ppath.dentry);
11624 + IMustLock(h_dir);
11628 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11629 + AuDebugOn(elm->created && elm->info_last);
11630 + if (elm->created) {
11632 + delegated = NULL;
11633 + infopath.dentry = elm->info_dentry;
11634 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11637 + if (unlikely(err == -EWOULDBLOCK))
11639 + dput(elm->info_dentry);
11640 + } else if (elm->info_last) {
11642 + w->fdata->drinfo = *elm->info_last;
11643 + memcpy(w->fdata->drinfo.oldname,
11644 + elm->info_last->oldname,
11645 + elm->info_last->oldnamelen);
11646 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11647 + au_kfree_rcu(elm->info_last);
11649 + if (unlikely(err))
11650 + AuIOErr("%d, %s\n", err, w->whname);
11651 + /* go on even if err */
11655 +/* caller has to call au_dr_rename_fin() later */
11656 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11657 + struct qstr *dst_name, void *_rev)
11659 + int err, sz, nelm;
11660 + aufs_bindex_t bindex, btail;
11661 + struct au_drinfo_store work;
11662 + struct au_drinfo_rev *rev, **p;
11663 + struct au_drinfo_rev_elm *elm;
11664 + struct super_block *sb;
11665 + struct au_branch *br;
11666 + struct au_hinode *hdir;
11668 + err = au_drinfo_store_work_init(&work, btgt);
11670 + if (unlikely(err))
11674 + btail = au_dbtaildir(dentry);
11675 + nelm = btail - btgt;
11676 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11677 + rev = kcalloc(1, sz, GFP_NOFS);
11678 + if (unlikely(!rev)) {
11682 + rev->nelm = nelm;
11688 + sb = dentry->d_sb;
11689 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11690 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11691 + hdir = au_hi(d_inode(dentry), btgt);
11692 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11693 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11694 + work.h_dentry = au_h_dptr(dentry, bindex);
11695 + if (!work.h_dentry)
11698 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11699 + &work.allocated);
11701 + if (unlikely(err))
11704 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11705 + br = au_sbr(sb, bindex);
11706 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11707 + work.whnamelen += au_drinfo_name(br, work.infoname,
11708 + work.infonamelen);
11709 + AuDbg("whname %.*s, i%llu, %.*s\n",
11710 + work.whnamelen, work.whname,
11711 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11712 + work.fdata->drinfo.oldnamelen,
11713 + work.fdata->drinfo.oldname);
11715 + err = au_drinfo_store_sio(&work, elm);
11717 + if (unlikely(err))
11720 + if (unlikely(err)) {
11721 + /* revert all drinfo */
11722 + au_drinfo_store_rev(rev, &work);
11723 + au_kfree_try_rcu(rev);
11726 + au_hn_inode_unlock(hdir);
11729 + au_drinfo_store_work_fin(&work);
11734 +/* ---------------------------------------------------------------------- */
11736 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11737 + struct qstr *dst_name, void *_rev)
11739 + int err, already;
11741 + struct super_block *sb;
11742 + struct au_branch *br;
11743 + struct au_dr_br *dr;
11744 + struct dentry *h_dentry;
11745 + struct inode *h_inode;
11746 + struct au_dr_hino *ent;
11747 + struct au_drinfo_rev *rev, **p;
11749 + AuDbg("bindex %d\n", bindex);
11752 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11753 + if (unlikely(!ent))
11757 + br = au_sbr(sb, bindex);
11758 + dr = &br->br_dirren;
11759 + h_dentry = au_h_dptr(src, bindex);
11760 + h_inode = d_inode(h_dentry);
11761 + ino = h_inode->i_ino;
11762 + ent->dr_h_ino = ino;
11763 + already = au_dr_hino_test_add(dr, ino, ent);
11764 + AuDbg("b%d, hi%llu, already %d\n",
11765 + bindex, (unsigned long long)ino, already);
11767 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11772 + rev->already = already;
11773 + goto out; /* success */
11778 + au_dr_hino_del(dr, ent);
11779 + au_kfree_rcu(ent);
11786 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11788 + struct au_drinfo_rev *rev;
11789 + struct au_drinfo_rev_elm *elm;
11794 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11795 + dput(elm->info_dentry);
11796 + au_kfree_rcu(elm->info_last);
11798 + au_kfree_try_rcu(rev);
11801 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11804 + struct au_drinfo_store work;
11805 + struct au_drinfo_rev *rev = _rev;
11806 + struct super_block *sb;
11807 + struct au_branch *br;
11808 + struct inode *h_inode;
11809 + struct au_dr_br *dr;
11810 + struct au_dr_hino *ent;
11812 + err = au_drinfo_store_work_init(&work, btgt);
11813 + if (unlikely(err))
11817 + br = au_sbr(sb, btgt);
11818 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11819 + work.h_ppath.mnt = au_br_mnt(br);
11820 + au_drinfo_store_rev(rev, &work);
11821 + au_drinfo_store_work_fin(&work);
11822 + if (rev->already)
11825 + dr = &br->br_dirren;
11826 + h_inode = d_inode(work.h_ppath.dentry);
11827 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11829 + au_dr_hino_del(dr, ent);
11830 + au_kfree_rcu(ent);
11833 + au_kfree_try_rcu(rev);
11834 + if (unlikely(err))
11835 + pr_err("failed to remove dirren info\n");
11838 +/* ---------------------------------------------------------------------- */
11840 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11841 + char *whname, int whnamelen,
11842 + struct dentry **info_dentry)
11844 + struct au_drinfo *drinfo;
11846 + struct inode *h_dir;
11847 + struct path infopath;
11850 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11852 + *info_dentry = NULL;
11855 + h_dir = d_inode(h_ppath->dentry);
11856 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11857 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11858 + if (IS_ERR(infopath.dentry)) {
11859 + drinfo = (void *)infopath.dentry;
11863 + if (d_is_negative(infopath.dentry))
11864 + goto out_dput; /* success */
11866 + infopath.mnt = h_ppath->mnt;
11867 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11868 + inode_unlock_shared(h_dir);
11871 + drinfo = (void *)f;
11875 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11876 + if (IS_ERR_OR_NULL(drinfo))
11879 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11880 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11885 + dput(infopath.dentry);
11888 + inode_unlock_shared(h_dir);
11889 + AuTraceErrPtr(drinfo);
11893 +struct au_drinfo_do_load_args {
11894 + struct au_drinfo **drinfop;
11895 + struct path *h_ppath;
11898 + struct dentry **info_dentry;
11901 +static void au_call_drinfo_do_load(void *args)
11903 + struct au_drinfo_do_load_args *a = args;
11905 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11909 +struct au_drinfo_load {
11910 + struct path h_ppath;
11911 + struct qstr *qname;
11912 + unsigned char no_sio;
11914 + aufs_bindex_t ninfo;
11915 + struct au_drinfo **drinfo;
11918 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11919 + struct au_branch *br)
11921 + int err, wkq_err, whnamelen, e;
11922 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11923 + = AUFS_WH_DR_INFO_PFX;
11924 + struct au_drinfo *drinfo;
11925 + struct qstr oldname;
11926 + struct inode *h_dir, *delegated;
11927 + struct dentry *info_dentry;
11928 + struct path infopath;
11930 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11931 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11932 + sizeof(whname) - whnamelen);
11934 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11937 + struct au_drinfo_do_load_args args = {
11938 + .drinfop = &drinfo,
11939 + .h_ppath = &w->h_ppath,
11940 + .whname = whname,
11941 + .whnamelen = whnamelen,
11942 + .info_dentry = &info_dentry
11944 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11945 + if (unlikely(wkq_err))
11946 + drinfo = ERR_PTR(wkq_err);
11948 + err = PTR_ERR(drinfo);
11949 + if (IS_ERR_OR_NULL(drinfo))
11953 + oldname.len = drinfo->oldnamelen;
11954 + oldname.name = drinfo->oldname;
11955 + if (au_qstreq(w->qname, &oldname)) {
11956 + /* the name is renamed back */
11957 + au_kfree_rcu(drinfo);
11960 + infopath.dentry = info_dentry;
11961 + infopath.mnt = w->h_ppath.mnt;
11962 + h_dir = d_inode(w->h_ppath.dentry);
11963 + delegated = NULL;
11964 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11965 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11966 + inode_unlock(h_dir);
11968 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11969 + if (unlikely(e == -EWOULDBLOCK))
11972 + au_kfree_rcu(w->drinfo[bindex]);
11973 + w->drinfo[bindex] = drinfo;
11974 + dput(info_dentry);
11981 +/* ---------------------------------------------------------------------- */
11983 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11985 + struct au_drinfo **p = drinfo;
11988 + au_kfree_rcu(*drinfo++);
11989 + au_kfree_try_rcu(p);
11992 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
11993 + aufs_bindex_t btgt)
11996 + struct au_drinfo_load w;
11997 + aufs_bindex_t bindex, bbot;
11998 + struct au_branch *br;
11999 + struct inode *h_dir;
12000 + struct au_dr_hino *ent;
12001 + struct super_block *sb;
12003 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12004 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12005 + AuLNPair(&lkup->whname), btgt);
12007 + sb = dentry->d_sb;
12008 + bbot = au_sbbot(sb);
12009 + w.ninfo = bbot + 1;
12010 + if (!lkup->dirren.drinfo) {
12011 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12012 + sizeof(*lkup->dirren.drinfo),
12014 + if (unlikely(!lkup->dirren.drinfo)) {
12018 + lkup->dirren.ninfo = w.ninfo;
12020 + w.drinfo = lkup->dirren.drinfo;
12021 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12022 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12023 + AuDebugOn(!w.h_ppath.dentry);
12024 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12025 + w.qname = &dentry->d_name;
12028 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12029 + br = au_sbr(sb, bindex);
12030 + err = au_drinfo_load(&w, bindex, br);
12031 + if (unlikely(err))
12033 + if (w.drinfo[bindex])
12037 + br = au_sbr(sb, btgt);
12038 + h_dir = d_inode(w.h_ppath.dentry);
12039 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12041 + au_dr_hino_del(&br->br_dirren, ent);
12042 + au_kfree_rcu(ent);
12044 + goto out; /* success */
12047 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12048 + lkup->dirren.ninfo = 0;
12049 + lkup->dirren.drinfo = NULL;
12055 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12057 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12060 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12063 + struct au_drinfo *drinfo;
12066 + if (!lkup->dirren.drinfo)
12068 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12069 + drinfo = lkup->dirren.drinfo[btgt];
12073 + au_kfree_try_rcu(lkup->whname.name);
12074 + lkup->whname.name = NULL;
12075 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12076 + lkup->dirren.dr_name.name = drinfo->oldname;
12077 + lkup->name = &lkup->dirren.dr_name;
12078 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12080 + AuDbg("name %.*s, whname %.*s, b%d\n",
12081 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12089 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12093 + struct au_drinfo *drinfo;
12096 + if (!lkup->dirren.drinfo)
12098 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12099 + drinfo = lkup->dirren.drinfo[bindex];
12103 + match = (drinfo->ino == h_ino);
12104 + AuDbg("match %d\n", match);
12110 +/* ---------------------------------------------------------------------- */
12112 +int au_dr_opt_set(struct super_block *sb)
12115 + aufs_bindex_t bindex, bbot;
12116 + struct au_branch *br;
12119 + bbot = au_sbbot(sb);
12120 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12121 + br = au_sbr(sb, bindex);
12122 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12128 +int au_dr_opt_flush(struct super_block *sb)
12131 + aufs_bindex_t bindex, bbot;
12132 + struct au_branch *br;
12135 + bbot = au_sbbot(sb);
12136 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12137 + br = au_sbr(sb, bindex);
12138 + if (au_br_writable(br->br_perm))
12139 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12145 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12148 + aufs_bindex_t bindex, bbot;
12149 + struct au_branch *br;
12153 + err = au_dr_opt_flush(sb);
12154 + if (unlikely(err))
12158 + bbot = au_sbbot(sb);
12159 + for (bindex = 0; bindex <= bbot; bindex++) {
12160 + br = au_sbr(sb, bindex);
12161 + au_dr_hino_free(&br->br_dirren);
12167 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12168 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12169 +++ linux/fs/aufs/dirren.h 2022-03-21 14:49:05.723299677 +0100
12171 +/* SPDX-License-Identifier: GPL-2.0 */
12173 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12175 + * This program, aufs is free software; you can redistribute it and/or modify
12176 + * it under the terms of the GNU General Public License as published by
12177 + * the Free Software Foundation; either version 2 of the License, or
12178 + * (at your option) any later version.
12180 + * This program is distributed in the hope that it will be useful,
12181 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12182 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12183 + * GNU General Public License for more details.
12185 + * You should have received a copy of the GNU General Public License
12186 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12190 + * renamed dir info
12193 +#ifndef __AUFS_DIRREN_H__
12194 +#define __AUFS_DIRREN_H__
12198 +#include <linux/dcache.h>
12199 +#include <linux/statfs.h>
12200 +#include <linux/uuid.h>
12203 +#define AuDirren_NHASH 100
12205 +#ifdef CONFIG_AUFS_DIRREN
12206 +enum au_brid_type {
12213 +struct au_dr_brid {
12214 + enum au_brid_type type;
12216 + uuid_t uuid; /* unimplemented yet */
12222 +/* 20 is the max digits length of ulong 64 */
12223 +/* brid-type "_" uuid "_" inum */
12224 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12225 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12227 +struct au_dr_hino {
12228 + struct hlist_bl_node dr_hnode;
12233 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12234 + struct au_dr_brid dr_brid;
12237 +struct au_dr_lookup {
12238 + /* dr_name is pointed by struct au_do_lookup_args.name */
12239 + struct qstr dr_name; /* subset of dr_info */
12240 + aufs_bindex_t ninfo;
12241 + struct au_drinfo **drinfo;
12244 +struct au_dr_hino;
12246 +struct au_dr_br { };
12247 +struct au_dr_lookup { };
12250 +/* ---------------------------------------------------------------------- */
12253 +struct au_do_lookup_args;
12255 +#ifdef CONFIG_AUFS_DIRREN
12256 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12257 + struct au_dr_hino *add_ent);
12258 +void au_dr_hino_free(struct au_dr_br *dr);
12259 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12260 + const struct path *path);
12261 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12262 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12263 + struct qstr *dst_name, void *_rev);
12264 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12265 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12266 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12267 + aufs_bindex_t bindex);
12268 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12269 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12271 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12272 +int au_dr_opt_set(struct super_block *sb);
12273 +int au_dr_opt_flush(struct super_block *sb);
12274 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12276 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12277 + struct au_dr_hino *add_ent);
12278 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12279 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12280 + const struct path *path);
12281 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12282 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12283 + struct qstr *dst_name, void *_rev);
12284 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12285 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12287 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12288 + aufs_bindex_t bindex);
12289 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12290 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12291 + aufs_bindex_t bindex, ino_t h_ino);
12292 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12293 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12294 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12295 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12298 +/* ---------------------------------------------------------------------- */
12300 +#ifdef CONFIG_AUFS_DIRREN
12301 +static inline int au_dr_ihash(ino_t h_ino)
12303 + return h_ino % AuDirren_NHASH;
12306 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12309 +#endif /* __KERNEL__ */
12310 +#endif /* __AUFS_DIRREN_H__ */
12311 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12312 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12313 +++ linux/fs/aufs/dynop.c 2022-03-21 14:49:05.723299677 +0100
12315 +// SPDX-License-Identifier: GPL-2.0
12317 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12319 + * This program, aufs is free software; you can redistribute it and/or modify
12320 + * it under the terms of the GNU General Public License as published by
12321 + * the Free Software Foundation; either version 2 of the License, or
12322 + * (at your option) any later version.
12324 + * This program is distributed in the hope that it will be useful,
12325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12327 + * GNU General Public License for more details.
12329 + * You should have received a copy of the GNU General Public License
12330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12334 + * dynamically customizable operations for regular files
12339 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12342 + * How large will these lists be?
12343 + * Usually just a few elements, 20-30 at most for each, I guess.
12345 +static struct hlist_bl_head dynop[AuDyLast];
12347 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12348 + const void *h_op)
12350 + struct au_dykey *key, *tmp;
12351 + struct hlist_bl_node *pos;
12354 + hlist_bl_lock(hbl);
12355 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12356 + if (tmp->dk_op.dy_hop == h_op) {
12357 + if (kref_get_unless_zero(&tmp->dk_kref))
12361 + hlist_bl_unlock(hbl);
12366 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12368 + struct au_dykey **k, *found;
12369 + const void *h_op = key->dk_op.dy_hop;
12373 + k = br->br_dykey;
12374 + for (i = 0; i < AuBrDynOp; i++)
12376 + if (k[i]->dk_op.dy_hop == h_op) {
12383 + spin_lock(&br->br_dykey_lock);
12384 + for (; i < AuBrDynOp; i++)
12386 + if (k[i]->dk_op.dy_hop == h_op) {
12394 + spin_unlock(&br->br_dykey_lock);
12395 + BUG_ON(i == AuBrDynOp); /* expand the array */
12401 +/* kref_get() if @key is already added */
12402 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12404 + struct au_dykey *tmp, *found;
12405 + struct hlist_bl_node *pos;
12406 + const void *h_op = key->dk_op.dy_hop;
12409 + hlist_bl_lock(hbl);
12410 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12411 + if (tmp->dk_op.dy_hop == h_op) {
12412 + if (kref_get_unless_zero(&tmp->dk_kref))
12417 + hlist_bl_add_head(&key->dk_hnode, hbl);
12418 + hlist_bl_unlock(hbl);
12425 +static void dy_free_rcu(struct rcu_head *rcu)
12427 + struct au_dykey *key;
12429 + key = container_of(rcu, struct au_dykey, dk_rcu);
12434 +static void dy_free(struct kref *kref)
12436 + struct au_dykey *key;
12437 + struct hlist_bl_head *hbl;
12439 + key = container_of(kref, struct au_dykey, dk_kref);
12440 + hbl = dynop + key->dk_op.dy_type;
12441 + au_hbl_del(&key->dk_hnode, hbl);
12442 + call_rcu(&key->dk_rcu, dy_free_rcu);
12445 +void au_dy_put(struct au_dykey *key)
12447 + kref_put(&key->dk_kref, dy_free);
12450 +/* ---------------------------------------------------------------------- */
12452 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12454 +#ifdef CONFIG_AUFS_DEBUG
12455 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12456 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12458 +#define DyDbgDeclare(cnt) do {} while (0)
12459 +#define DyDbgInc(cnt) do {} while (0)
12462 +#define DySet(func, dst, src, h_op, h_sb) do { \
12464 + if (h_op->func) { \
12466 + dst.func = src.func; \
12468 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12472 +#define DySetForce(func, dst, src) do { \
12473 + AuDebugOn(!src.func); \
12475 + dst.func = src.func; \
12478 +#define DySetAop(func) \
12479 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12480 +#define DySetAopForce(func) \
12481 + DySetForce(func, dyaop->da_op, aufs_aop)
12483 +static void dy_aop(struct au_dykey *key, const void *h_op,
12484 + struct super_block *h_sb __maybe_unused)
12486 + struct au_dyaop *dyaop = (void *)key;
12487 + const struct address_space_operations *h_aop = h_op;
12488 + DyDbgDeclare(cnt);
12490 + AuDbg("%s\n", au_sbtype(h_sb));
12492 + DySetAop(writepage);
12493 + DySetAopForce(readpage); /* force */
12494 + DySetAop(writepages);
12495 + DySetAop(set_page_dirty);
12496 + DySetAop(readpages);
12497 + DySetAop(readahead);
12498 + DySetAop(write_begin);
12499 + DySetAop(write_end);
12501 + DySetAop(invalidatepage);
12502 + DySetAop(releasepage);
12503 + DySetAop(freepage);
12504 + /* this one will be changed according to an aufs mount option */
12505 + DySetAop(direct_IO);
12506 + DySetAop(migratepage);
12507 + DySetAop(isolate_page);
12508 + DySetAop(putback_page);
12509 + DySetAop(launder_page);
12510 + DySetAop(is_partially_uptodate);
12511 + DySetAop(is_dirty_writeback);
12512 + DySetAop(error_remove_page);
12513 + DySetAop(swap_activate);
12514 + DySetAop(swap_deactivate);
12516 + DyDbgSize(cnt, *h_aop);
12519 +/* ---------------------------------------------------------------------- */
12521 +static void dy_bug(struct kref *kref)
12526 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12528 + struct au_dykey *key, *old;
12529 + struct hlist_bl_head *hbl;
12532 + void (*set)(struct au_dykey *key, const void *h_op,
12533 + struct super_block *h_sb __maybe_unused);
12535 + static const struct op a[] = {
12537 + .sz = sizeof(struct au_dyaop),
12541 + const struct op *p;
12543 + hbl = dynop + op->dy_type;
12544 + key = dy_gfind_get(hbl, op->dy_hop);
12546 + goto out_add; /* success */
12548 + p = a + op->dy_type;
12549 + key = kzalloc(p->sz, GFP_NOFS);
12550 + if (unlikely(!key)) {
12551 + key = ERR_PTR(-ENOMEM);
12555 + key->dk_op.dy_hop = op->dy_hop;
12556 + kref_init(&key->dk_kref);
12557 + p->set(key, op->dy_hop, au_br_sb(br));
12558 + old = dy_gadd(hbl, key);
12560 + au_kfree_rcu(key);
12565 + old = dy_bradd(br, key);
12567 + /* its ref-count should never be zero here */
12568 + kref_put(&key->dk_kref, dy_bug);
12573 +/* ---------------------------------------------------------------------- */
12575 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12576 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12577 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12578 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12579 + * See the aufs manual in detail.
12581 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12584 + dyaop->da_op.direct_IO = NULL;
12586 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12589 +static struct au_dyaop *dy_aget(struct au_branch *br,
12590 + const struct address_space_operations *h_aop,
12593 + struct au_dyaop *dyaop;
12594 + struct au_dynop op;
12596 + op.dy_type = AuDy_AOP;
12597 + op.dy_haop = h_aop;
12598 + dyaop = (void *)dy_get(&op, br);
12599 + if (IS_ERR(dyaop))
12601 + dy_adx(dyaop, do_dx);
12607 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12608 + struct inode *h_inode)
12611 + struct super_block *sb;
12612 + struct au_branch *br;
12613 + struct au_dyaop *dyaop;
12615 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12616 + IiMustWriteLock(inode);
12618 + sb = inode->i_sb;
12619 + br = au_sbr(sb, bindex);
12620 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12621 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12622 + err = PTR_ERR(dyaop);
12623 + if (IS_ERR(dyaop))
12624 + /* unnecessary to call dy_fput() */
12628 + inode->i_mapping->a_ops = &dyaop->da_op;
12635 + * Is it safe to replace a_ops during the inode/file is in operation?
12636 + * Yes, I hope so.
12638 +int au_dy_irefresh(struct inode *inode)
12641 + aufs_bindex_t btop;
12642 + struct inode *h_inode;
12645 + if (S_ISREG(inode->i_mode)) {
12646 + btop = au_ibtop(inode);
12647 + h_inode = au_h_iptr(inode, btop);
12648 + err = au_dy_iaop(inode, btop, h_inode);
12653 +void au_dy_arefresh(int do_dx)
12655 + struct hlist_bl_head *hbl;
12656 + struct hlist_bl_node *pos;
12657 + struct au_dykey *key;
12659 + hbl = dynop + AuDy_AOP;
12660 + hlist_bl_lock(hbl);
12661 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12662 + dy_adx((void *)key, do_dx);
12663 + hlist_bl_unlock(hbl);
12666 +/* ---------------------------------------------------------------------- */
12668 +void __init au_dy_init(void)
12672 + for (i = 0; i < AuDyLast; i++)
12673 + INIT_HLIST_BL_HEAD(dynop + i);
12676 +void au_dy_fin(void)
12680 + for (i = 0; i < AuDyLast; i++)
12681 + WARN_ON(!hlist_bl_empty(dynop + i));
12683 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12684 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12685 +++ linux/fs/aufs/dynop.h 2022-03-21 14:49:05.723299677 +0100
12687 +/* SPDX-License-Identifier: GPL-2.0 */
12689 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12691 + * This program, aufs is free software; you can redistribute it and/or modify
12692 + * it under the terms of the GNU General Public License as published by
12693 + * the Free Software Foundation; either version 2 of the License, or
12694 + * (at your option) any later version.
12696 + * This program is distributed in the hope that it will be useful,
12697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12699 + * GNU General Public License for more details.
12701 + * You should have received a copy of the GNU General Public License
12702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12706 + * dynamically customizable operations (for regular files only)
12709 +#ifndef __AUFS_DYNOP_H__
12710 +#define __AUFS_DYNOP_H__
12714 +#include <linux/fs.h>
12715 +#include <linux/kref.h>
12717 +enum {AuDy_AOP, AuDyLast};
12722 + const void *dy_hop;
12723 + const struct address_space_operations *dy_haop;
12729 + struct hlist_bl_node dk_hnode;
12730 + struct rcu_head dk_rcu;
12732 + struct au_dynop dk_op;
12735 + * during I am in the branch local array, kref is gotten. when the
12736 + * branch is removed, kref is put.
12738 + struct kref dk_kref;
12741 +/* stop unioning since their sizes are very different from each other */
12743 + struct au_dykey da_key;
12744 + struct address_space_operations da_op; /* not const */
12746 +/* make sure that 'struct au_dykey *' can be any type */
12747 +static_assert(!offsetof(struct au_dyaop, da_key));
12749 +/* ---------------------------------------------------------------------- */
12753 +void au_dy_put(struct au_dykey *key);
12754 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12755 + struct inode *h_inode);
12756 +int au_dy_irefresh(struct inode *inode);
12757 +void au_dy_arefresh(int do_dio);
12759 +void __init au_dy_init(void);
12760 +void au_dy_fin(void);
12762 +#endif /* __KERNEL__ */
12763 +#endif /* __AUFS_DYNOP_H__ */
12764 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12765 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12766 +++ linux/fs/aufs/export.c 2022-03-21 14:49:05.723299677 +0100
12768 +// SPDX-License-Identifier: GPL-2.0
12770 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12772 + * This program, aufs is free software; you can redistribute it and/or modify
12773 + * it under the terms of the GNU General Public License as published by
12774 + * the Free Software Foundation; either version 2 of the License, or
12775 + * (at your option) any later version.
12777 + * This program is distributed in the hope that it will be useful,
12778 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12779 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12780 + * GNU General Public License for more details.
12782 + * You should have received a copy of the GNU General Public License
12783 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12790 +#include <linux/exportfs.h>
12791 +#include <linux/fs_struct.h>
12792 +#include <linux/nsproxy.h>
12793 +#include <linux/random.h>
12794 +#include <linux/writeback.h>
12798 +#ifdef CONFIG_AUFS_INO_T_64
12806 +static ino_t decode_ino(__u32 *a)
12810 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12812 +#ifdef CONFIG_AUFS_INO_T_64
12818 +static void encode_ino(__u32 *a, ino_t ino)
12824 +#ifdef CONFIG_AUFS_INO_T_64
12829 +/* NFS file handle */
12833 +#ifdef CONFIG_AUFS_INO_T_64
12834 + /* support 64bit inode number */
12847 + Fh_ino = Fh_ino1,
12848 + Fh_dir_ino = Fh_dir_ino1
12851 +static int au_test_anon(struct dentry *dentry)
12853 + /* note: read d_flags without d_lock */
12854 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12857 +int au_test_nfsd(void)
12860 + struct task_struct *tsk = current;
12861 + char comm[sizeof(tsk->comm)];
12864 + if (tsk->flags & PF_KTHREAD) {
12865 + get_task_comm(comm, tsk);
12866 + ret = !strcmp(comm, "nfsd");
12872 +/* ---------------------------------------------------------------------- */
12873 +/* inode generation external table */
12875 +void au_xigen_inc(struct inode *inode)
12880 + struct super_block *sb;
12881 + struct au_sbinfo *sbinfo;
12883 + sb = inode->i_sb;
12884 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12886 + sbinfo = au_sbi(sb);
12887 + pos = inode->i_ino;
12888 + pos *= sizeof(igen);
12889 + igen = inode->i_generation + 1;
12890 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12891 + if (sz == sizeof(igen))
12892 + return; /* success */
12894 + if (unlikely(sz >= 0))
12895 + AuIOErr("xigen error (%zd)\n", sz);
12898 +int au_xigen_new(struct inode *inode)
12903 + struct super_block *sb;
12904 + struct au_sbinfo *sbinfo;
12905 + struct file *file;
12908 + /* todo: dirty, at mount time */
12909 + if (inode->i_ino == AUFS_ROOT_INO)
12911 + sb = inode->i_sb;
12912 + SiMustAnyLock(sb);
12913 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12917 + pos = inode->i_ino;
12918 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12919 + AuIOErr1("too large i%lld\n", pos);
12922 + pos *= sizeof(inode->i_generation);
12925 + sbinfo = au_sbi(sb);
12926 + file = sbinfo->si_xigen;
12929 + if (vfsub_f_size_read(file)
12930 + < pos + sizeof(inode->i_generation)) {
12931 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12932 + sz = xino_fwrite(file, &inode->i_generation,
12933 + sizeof(inode->i_generation), &pos);
12935 + sz = xino_fread(file, &inode->i_generation,
12936 + sizeof(inode->i_generation), &pos);
12937 + if (sz == sizeof(inode->i_generation))
12938 + goto out; /* success */
12941 + if (unlikely(sz >= 0)) {
12943 + AuIOErr("xigen error (%zd)\n", sz);
12950 +int au_xigen_set(struct super_block *sb, struct path *path)
12953 + struct au_sbinfo *sbinfo;
12954 + struct file *file;
12956 + SiMustWriteLock(sb);
12958 + sbinfo = au_sbi(sb);
12959 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12960 + err = PTR_ERR(file);
12961 + if (IS_ERR(file))
12964 + if (sbinfo->si_xigen)
12965 + fput(sbinfo->si_xigen);
12966 + sbinfo->si_xigen = file;
12973 +void au_xigen_clr(struct super_block *sb)
12975 + struct au_sbinfo *sbinfo;
12977 + SiMustWriteLock(sb);
12979 + sbinfo = au_sbi(sb);
12980 + if (sbinfo->si_xigen) {
12981 + fput(sbinfo->si_xigen);
12982 + sbinfo->si_xigen = NULL;
12986 +/* ---------------------------------------------------------------------- */
12988 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
12991 + struct dentry *dentry, *d;
12992 + struct inode *inode;
12993 + unsigned int sigen;
12996 + inode = ilookup(sb, ino);
13000 + dentry = ERR_PTR(-ESTALE);
13001 + sigen = au_sigen(sb);
13002 + if (unlikely(au_is_bad_inode(inode)
13003 + || IS_DEADDIR(inode)
13004 + || sigen != au_iigen(inode, NULL)))
13008 + if (!dir_ino || S_ISDIR(inode->i_mode))
13009 + dentry = d_find_alias(inode);
13011 + spin_lock(&inode->i_lock);
13012 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13013 + spin_lock(&d->d_lock);
13014 + if (!au_test_anon(d)
13015 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13016 + dentry = dget_dlock(d);
13017 + spin_unlock(&d->d_lock);
13020 + spin_unlock(&d->d_lock);
13022 + spin_unlock(&inode->i_lock);
13024 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13025 + /* need to refresh */
13033 + AuTraceErrPtr(dentry);
13037 +/* ---------------------------------------------------------------------- */
13039 +/* todo: dirty? */
13040 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13042 +struct au_compare_mnt_args {
13044 + struct super_block *sb;
13047 + struct vfsmount *mnt;
13050 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13052 + struct au_compare_mnt_args *a = arg;
13054 + if (mnt->mnt_sb != a->sb)
13056 + a->mnt = mntget(mnt);
13060 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13063 + struct path root;
13064 + struct au_compare_mnt_args args = {
13068 + get_fs_root(current->fs, &root);
13070 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13071 + rcu_read_unlock();
13074 + AuDebugOn(!args.mnt);
13078 +struct au_nfsd_si_lock {
13079 + unsigned int sigen;
13080 + aufs_bindex_t bindex, br_id;
13081 + unsigned char force_lock;
13084 +static int si_nfsd_read_lock(struct super_block *sb,
13085 + struct au_nfsd_si_lock *nsi_lock)
13088 + aufs_bindex_t bindex;
13090 + si_read_lock(sb, AuLock_FLUSH);
13092 + /* branch id may be wrapped around */
13094 + bindex = au_br_index(sb, nsi_lock->br_id);
13095 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13096 + goto out; /* success */
13100 + if (!nsi_lock->force_lock)
13101 + si_read_unlock(sb);
13104 + nsi_lock->bindex = bindex;
13108 +struct find_name_by_ino {
13109 + struct dir_context ctx;
13110 + int called, found;
13117 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13118 + loff_t offset, u64 ino, unsigned int d_type)
13120 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13124 + if (a->ino != ino)
13127 + memcpy(a->name, name, namelen);
13128 + a->namelen = namelen;
13133 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13134 + struct au_nfsd_si_lock *nsi_lock)
13136 + struct dentry *dentry, *parent;
13137 + struct file *file;
13138 + struct inode *dir;
13139 + struct find_name_by_ino arg = {
13141 + .actor = find_name_by_ino
13146 + parent = path->dentry;
13148 + si_read_unlock(parent->d_sb);
13149 + file = vfsub_dentry_open(path, au_dir_roflags);
13150 + dentry = (void *)file;
13151 + if (IS_ERR(file))
13154 + dentry = ERR_PTR(-ENOMEM);
13155 + arg.name = (void *)__get_free_page(GFP_NOFS);
13156 + if (unlikely(!arg.name))
13163 + err = vfsub_iterate_dir(file, &arg.ctx);
13164 + } while (!err && !arg.found && arg.called);
13165 + dentry = ERR_PTR(err);
13166 + if (unlikely(err))
13168 + /* instead of ENOENT */
13169 + dentry = ERR_PTR(-ESTALE);
13173 + /* do not call vfsub_lkup_one() */
13174 + dir = d_inode(parent);
13175 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13176 + AuTraceErrPtr(dentry);
13177 + if (IS_ERR(dentry))
13179 + AuDebugOn(au_test_anon(dentry));
13180 + if (unlikely(d_really_is_negative(dentry))) {
13182 + dentry = ERR_PTR(-ENOENT);
13186 + free_page((unsigned long)arg.name);
13190 + if (unlikely(nsi_lock
13191 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13192 + if (!IS_ERR(dentry)) {
13194 + dentry = ERR_PTR(-ESTALE);
13196 + AuTraceErrPtr(dentry);
13200 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13202 + struct au_nfsd_si_lock *nsi_lock)
13204 + struct dentry *dentry;
13205 + struct path path;
13207 + if (dir_ino != AUFS_ROOT_INO) {
13208 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13209 + dentry = path.dentry;
13210 + if (!path.dentry || IS_ERR(path.dentry))
13212 + AuDebugOn(au_test_anon(path.dentry));
13214 + path.dentry = dget(sb->s_root);
13216 + path.mnt = au_mnt_get(sb);
13217 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13221 + AuTraceErrPtr(dentry);
13225 +/* ---------------------------------------------------------------------- */
13227 +static int h_acceptable(void *expv, struct dentry *dentry)
13232 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13233 + char *buf, int len, struct super_block *sb)
13237 + struct path path;
13239 + p = d_path(h_rootpath, buf, len);
13244 + path.mnt = h_rootpath->mnt;
13245 + path.dentry = h_parent;
13246 + p = d_path(&path, buf, len);
13252 + path.mnt = au_mnt_get(sb);
13253 + path.dentry = sb->s_root;
13254 + p = d_path(&path, buf, len - strlen(p));
13255 + mntput(path.mnt);
13259 + p[strlen(p)] = '/';
13262 + AuTraceErrPtr(p);
13267 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13268 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13270 + struct dentry *dentry, *h_parent, *root;
13271 + struct super_block *h_sb;
13272 + char *pathname, *p;
13273 + struct vfsmount *h_mnt;
13274 + struct au_branch *br;
13276 + struct path path;
13278 + br = au_sbr(sb, nsi_lock->bindex);
13279 + h_mnt = au_br_mnt(br);
13280 + h_sb = h_mnt->mnt_sb;
13281 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13283 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13284 + fh_len - Fh_tail, fh[Fh_h_type],
13285 + h_acceptable, /*context*/NULL);
13287 + dentry = h_parent;
13288 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13289 + AuWarn1("%s decode_fh failed, %ld\n",
13290 + au_sbtype(h_sb), PTR_ERR(h_parent));
13294 + if (unlikely(au_test_anon(h_parent))) {
13295 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13296 + au_sbtype(h_sb));
13297 + goto out_h_parent;
13300 + dentry = ERR_PTR(-ENOMEM);
13301 + pathname = (void *)__get_free_page(GFP_NOFS);
13302 + if (unlikely(!pathname))
13303 + goto out_h_parent;
13305 + root = sb->s_root;
13306 + path.mnt = h_mnt;
13307 + di_read_lock_parent(root, !AuLock_IR);
13308 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13309 + di_read_unlock(root, !AuLock_IR);
13310 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13311 + dentry = (void *)p;
13313 + goto out_pathname;
13315 + si_read_unlock(sb);
13316 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13317 + dentry = ERR_PTR(err);
13318 + if (unlikely(err))
13321 + dentry = ERR_PTR(-ENOENT);
13322 + AuDebugOn(au_test_anon(path.dentry));
13323 + if (unlikely(d_really_is_negative(path.dentry)))
13326 + if (ino != d_inode(path.dentry)->i_ino)
13327 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13329 + dentry = dget(path.dentry);
13334 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13335 + if (!IS_ERR(dentry)) {
13337 + dentry = ERR_PTR(-ESTALE);
13340 + free_page((unsigned long)pathname);
13344 + AuTraceErrPtr(dentry);
13348 +/* ---------------------------------------------------------------------- */
13350 +static struct dentry *
13351 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13354 + struct dentry *dentry;
13355 + __u32 *fh = fid->raw;
13356 + struct au_branch *br;
13357 + ino_t ino, dir_ino;
13358 + struct au_nfsd_si_lock nsi_lock = {
13362 + dentry = ERR_PTR(-ESTALE);
13363 + /* it should never happen, but the file handle is unreliable */
13364 + if (unlikely(fh_len < Fh_tail))
13366 + nsi_lock.sigen = fh[Fh_sigen];
13367 + nsi_lock.br_id = fh[Fh_br_id];
13369 + /* branch id may be wrapped around */
13371 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13373 + nsi_lock.force_lock = 1;
13375 + /* is this inode still cached? */
13376 + ino = decode_ino(fh + Fh_ino);
13377 + /* it should never happen */
13378 + if (unlikely(ino == AUFS_ROOT_INO))
13381 + dir_ino = decode_ino(fh + Fh_dir_ino);
13382 + dentry = decode_by_ino(sb, ino, dir_ino);
13383 + if (IS_ERR(dentry))
13388 + /* is the parent dir cached? */
13389 + br = au_sbr(sb, nsi_lock.bindex);
13390 + au_lcnt_inc(&br->br_nfiles);
13391 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13392 + if (IS_ERR(dentry))
13397 + /* lookup path */
13398 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13399 + if (IS_ERR(dentry))
13401 + if (unlikely(!dentry))
13402 + /* todo?: make it ESTALE */
13406 + if (!au_digen_test(dentry, au_sigen(sb))
13407 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13408 + goto out_unlock; /* success */
13411 + dentry = ERR_PTR(-ESTALE);
13414 + au_lcnt_dec(&br->br_nfiles);
13415 + si_read_unlock(sb);
13417 + AuTraceErrPtr(dentry);
13421 +#if 0 /* reserved for future use */
13422 +/* support subtreecheck option */
13423 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13424 + int fh_len, int fh_type)
13426 + struct dentry *parent;
13427 + __u32 *fh = fid->raw;
13430 + dir_ino = decode_ino(fh + Fh_dir_ino);
13431 + parent = decode_by_ino(sb, dir_ino, 0);
13432 + if (IS_ERR(parent))
13435 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13436 + dir_ino, fh, fh_len);
13439 + AuTraceErrPtr(parent);
13444 +/* ---------------------------------------------------------------------- */
13446 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13447 + struct inode *dir)
13450 + aufs_bindex_t bindex;
13451 + struct super_block *sb, *h_sb;
13452 + struct dentry *dentry, *parent, *h_parent;
13453 + struct inode *h_dir;
13454 + struct au_branch *br;
13457 + if (unlikely(*max_len <= Fh_tail)) {
13458 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13462 + err = FILEID_ROOT;
13463 + if (inode->i_ino == AUFS_ROOT_INO) {
13464 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13469 + sb = inode->i_sb;
13470 + err = si_read_lock(sb, AuLock_FLUSH);
13471 + if (unlikely(err))
13474 +#ifdef CONFIG_AUFS_DEBUG
13475 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13476 + AuWarn1("NFS-exporting requires xino\n");
13480 + ii_read_lock_child(inode);
13481 + bindex = au_ibtop(inode);
13483 + dentry = d_find_any_alias(inode);
13484 + if (unlikely(!dentry))
13486 + AuDebugOn(au_test_anon(dentry));
13487 + parent = dget_parent(dentry);
13489 + if (unlikely(!parent))
13491 + if (d_really_is_positive(parent))
13492 + dir = d_inode(parent);
13495 + ii_read_lock_parent(dir);
13496 + h_dir = au_h_iptr(dir, bindex);
13497 + ii_read_unlock(dir);
13498 + if (unlikely(!h_dir))
13500 + h_parent = d_find_any_alias(h_dir);
13501 + if (unlikely(!h_parent))
13502 + goto out_hparent;
13505 + br = au_sbr(sb, bindex);
13506 + h_sb = au_br_sb(br);
13507 + if (unlikely(!h_sb->s_export_op)) {
13508 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13509 + goto out_hparent;
13512 + fh[Fh_br_id] = br->br_id;
13513 + fh[Fh_sigen] = au_sigen(sb);
13514 + encode_ino(fh + Fh_ino, inode->i_ino);
13515 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13516 + fh[Fh_igen] = inode->i_generation;
13518 + *max_len -= Fh_tail;
13519 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13521 + /*connectable or subtreecheck*/0);
13522 + err = fh[Fh_h_type];
13523 + *max_len += Fh_tail;
13524 + /* todo: macros? */
13525 + if (err != FILEID_INVALID)
13528 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13535 + ii_read_unlock(inode);
13536 + si_read_unlock(sb);
13538 + if (unlikely(err < 0))
13539 + err = FILEID_INVALID;
13543 +/* ---------------------------------------------------------------------- */
13545 +static int aufs_commit_metadata(struct inode *inode)
13548 + aufs_bindex_t bindex;
13549 + struct super_block *sb;
13550 + struct inode *h_inode;
13551 + int (*f)(struct inode *inode);
13553 + sb = inode->i_sb;
13554 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13555 + ii_write_lock_child(inode);
13556 + bindex = au_ibtop(inode);
13557 + AuDebugOn(bindex < 0);
13558 + h_inode = au_h_iptr(inode, bindex);
13560 + f = h_inode->i_sb->s_export_op->commit_metadata;
13562 + err = f(h_inode);
13564 + err = sync_inode_metadata(h_inode, /*wait*/1);
13566 + au_cpup_attr_timesizes(inode);
13567 + ii_write_unlock(inode);
13568 + si_read_unlock(sb);
13572 +/* ---------------------------------------------------------------------- */
13574 +static struct export_operations aufs_export_op = {
13575 + .fh_to_dentry = aufs_fh_to_dentry,
13576 + /* .fh_to_parent = aufs_fh_to_parent, */
13577 + .encode_fh = aufs_encode_fh,
13578 + .commit_metadata = aufs_commit_metadata
13581 +void au_export_init(struct super_block *sb)
13583 + struct au_sbinfo *sbinfo;
13586 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13587 + && IS_MODULE(CONFIG_EXPORTFS),
13588 + AUFS_NAME ": unsupported configuration "
13589 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13591 + sb->s_export_op = &aufs_export_op;
13592 + sbinfo = au_sbi(sb);
13593 + sbinfo->si_xigen = NULL;
13594 + get_random_bytes(&u, sizeof(u));
13595 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13596 + atomic_set(&sbinfo->si_xigen_next, u);
13598 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13599 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13600 +++ linux/fs/aufs/fhsm.c 2022-03-21 14:49:05.723299677 +0100
13602 +// SPDX-License-Identifier: GPL-2.0
13604 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13606 + * This program, aufs is free software; you can redistribute it and/or modify
13607 + * it under the terms of the GNU General Public License as published by
13608 + * the Free Software Foundation; either version 2 of the License, or
13609 + * (at your option) any later version.
13611 + * This program is distributed in the hope that it will be useful,
13612 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13613 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13614 + * GNU General Public License for more details.
13616 + * You should have received a copy of the GNU General Public License
13617 + * along with this program; if not, write to the Free Software
13618 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13622 + * File-based Hierarchy Storage Management
13625 +#include <linux/anon_inodes.h>
13626 +#include <linux/poll.h>
13627 +#include <linux/seq_file.h>
13628 +#include <linux/statfs.h>
13631 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13633 + struct au_sbinfo *sbinfo;
13634 + struct au_fhsm *fhsm;
13636 + SiMustAnyLock(sb);
13638 + sbinfo = au_sbi(sb);
13639 + fhsm = &sbinfo->si_fhsm;
13640 + AuDebugOn(!fhsm);
13641 + return fhsm->fhsm_bottom;
13644 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13646 + struct au_sbinfo *sbinfo;
13647 + struct au_fhsm *fhsm;
13649 + SiMustWriteLock(sb);
13651 + sbinfo = au_sbi(sb);
13652 + fhsm = &sbinfo->si_fhsm;
13653 + AuDebugOn(!fhsm);
13654 + fhsm->fhsm_bottom = bindex;
13657 +/* ---------------------------------------------------------------------- */
13659 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13661 + struct au_br_fhsm *bf;
13663 + bf = br->br_fhsm;
13664 + MtxMustLock(&bf->bf_lock);
13666 + return !bf->bf_readable
13667 + || time_after(jiffies,
13668 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13671 +/* ---------------------------------------------------------------------- */
13673 +static void au_fhsm_notify(struct super_block *sb, int val)
13675 + struct au_sbinfo *sbinfo;
13676 + struct au_fhsm *fhsm;
13678 + SiMustAnyLock(sb);
13680 + sbinfo = au_sbi(sb);
13681 + fhsm = &sbinfo->si_fhsm;
13682 + if (au_fhsm_pid(fhsm)
13683 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13684 + atomic_set(&fhsm->fhsm_readable, val);
13686 + wake_up(&fhsm->fhsm_wqh);
13690 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13691 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13694 + struct au_branch *br;
13695 + struct au_br_fhsm *bf;
13697 + br = au_sbr(sb, bindex);
13698 + AuDebugOn(au_br_rdonly(br));
13699 + bf = br->br_fhsm;
13703 + mutex_lock(&bf->bf_lock);
13705 + MtxMustLock(&bf->bf_lock);
13707 + /* sb->s_root for NFS is unreliable */
13708 + err = au_br_stfs(br, &bf->bf_stfs);
13709 + if (unlikely(err)) {
13710 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13714 + bf->bf_jiffy = jiffies;
13715 + bf->bf_readable = 1;
13717 + au_fhsm_notify(sb, /*val*/1);
13719 + *rstfs = bf->bf_stfs;
13723 + mutex_unlock(&bf->bf_lock);
13724 + au_fhsm_notify(sb, /*val*/1);
13729 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13732 + struct au_sbinfo *sbinfo;
13733 + struct au_fhsm *fhsm;
13734 + struct au_branch *br;
13735 + struct au_br_fhsm *bf;
13737 + AuDbg("b%d, force %d\n", bindex, force);
13738 + SiMustAnyLock(sb);
13740 + sbinfo = au_sbi(sb);
13741 + fhsm = &sbinfo->si_fhsm;
13742 + if (!au_ftest_si(sbinfo, FHSM)
13743 + || fhsm->fhsm_bottom == bindex)
13746 + br = au_sbr(sb, bindex);
13747 + bf = br->br_fhsm;
13749 + mutex_lock(&bf->bf_lock);
13751 + || au_fhsm_pid(fhsm)
13752 + || au_fhsm_test_jiffy(sbinfo, br))
13753 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13755 + mutex_unlock(&bf->bf_lock);
13758 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13760 + aufs_bindex_t bindex, bbot;
13761 + struct au_branch *br;
13763 + /* exclude the bottom */
13764 + bbot = au_fhsm_bottom(sb);
13765 + for (bindex = 0; bindex < bbot; bindex++) {
13766 + br = au_sbr(sb, bindex);
13767 + if (au_br_fhsm(br->br_perm))
13768 + au_fhsm_wrote(sb, bindex, force);
13772 +/* ---------------------------------------------------------------------- */
13774 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13777 + struct au_sbinfo *sbinfo;
13778 + struct au_fhsm *fhsm;
13781 + sbinfo = file->private_data;
13782 + fhsm = &sbinfo->si_fhsm;
13783 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13784 + if (atomic_read(&fhsm->fhsm_readable))
13785 + mask = EPOLLIN /* | EPOLLRDNORM */;
13788 + AuDbg("mask 0x%x\n", mask);
13792 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13793 + struct aufs_stfs *stfs, __s16 brid)
13797 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13799 + err = __put_user(brid, &stbr->brid);
13800 + if (unlikely(err))
13806 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13807 + struct aufs_stbr __user *stbr, size_t count)
13811 + aufs_bindex_t bindex, bbot;
13812 + struct au_branch *br;
13813 + struct au_br_fhsm *bf;
13815 + /* except the bottom branch */
13818 + bbot = au_fhsm_bottom(sb);
13819 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13820 + br = au_sbr(sb, bindex);
13821 + if (!au_br_fhsm(br->br_perm))
13824 + bf = br->br_fhsm;
13825 + mutex_lock(&bf->bf_lock);
13826 + if (bf->bf_readable) {
13828 + if (count >= sizeof(*stbr))
13829 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13832 + bf->bf_readable = 0;
13833 + count -= sizeof(*stbr);
13837 + mutex_unlock(&bf->bf_lock);
13840 + err = sizeof(*stbr) * nstbr;
13845 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13850 + aufs_bindex_t nfhsm, bindex, bbot;
13851 + struct au_sbinfo *sbinfo;
13852 + struct au_fhsm *fhsm;
13853 + struct au_branch *br;
13854 + struct super_block *sb;
13857 + sbinfo = file->private_data;
13858 + fhsm = &sbinfo->si_fhsm;
13860 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13861 + if (!atomic_read(&fhsm->fhsm_readable)) {
13862 + if (vfsub_file_flags(file) & O_NONBLOCK)
13865 + err = wait_event_interruptible_locked_irq
13867 + atomic_read(&fhsm->fhsm_readable));
13869 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13870 + if (unlikely(err))
13873 + /* sb may already be dead */
13874 + au_rw_read_lock(&sbinfo->si_rwsem);
13875 + readable = atomic_read(&fhsm->fhsm_readable);
13876 + if (readable > 0) {
13877 + sb = sbinfo->si_sb;
13879 + /* exclude the bottom branch */
13881 + bbot = au_fhsm_bottom(sb);
13882 + for (bindex = 0; bindex < bbot; bindex++) {
13883 + br = au_sbr(sb, bindex);
13884 + if (au_br_fhsm(br->br_perm))
13888 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13889 + atomic_set(&fhsm->fhsm_readable, 0);
13890 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13894 + au_rw_read_unlock(&sbinfo->si_rwsem);
13902 +static int au_fhsm_release(struct inode *inode, struct file *file)
13904 + struct au_sbinfo *sbinfo;
13905 + struct au_fhsm *fhsm;
13907 + /* sb may already be dead */
13908 + sbinfo = file->private_data;
13909 + fhsm = &sbinfo->si_fhsm;
13910 + spin_lock(&fhsm->fhsm_spin);
13911 + fhsm->fhsm_pid = 0;
13912 + spin_unlock(&fhsm->fhsm_spin);
13913 + kobject_put(&sbinfo->si_kobj);
13918 +static const struct file_operations au_fhsm_fops = {
13919 + .owner = THIS_MODULE,
13920 + .llseek = noop_llseek,
13921 + .read = au_fhsm_read,
13922 + .poll = au_fhsm_poll,
13923 + .release = au_fhsm_release
13926 +int au_fhsm_fd(struct super_block *sb, int oflags)
13929 + struct au_sbinfo *sbinfo;
13930 + struct au_fhsm *fhsm;
13933 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13937 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13941 + sbinfo = au_sbi(sb);
13942 + fhsm = &sbinfo->si_fhsm;
13943 + spin_lock(&fhsm->fhsm_spin);
13944 + if (!fhsm->fhsm_pid)
13945 + fhsm->fhsm_pid = current->pid;
13948 + spin_unlock(&fhsm->fhsm_spin);
13949 + if (unlikely(err))
13952 + oflags |= O_RDONLY;
13953 + /* oflags |= FMODE_NONOTIFY; */
13954 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13956 + if (unlikely(fd < 0))
13959 + /* succeed regardless 'fhsm' status */
13960 + kobject_get(&sbinfo->si_kobj);
13961 + si_noflush_read_lock(sb);
13962 + if (au_ftest_si(sbinfo, FHSM))
13963 + au_fhsm_wrote_all(sb, /*force*/0);
13964 + si_read_unlock(sb);
13965 + goto out; /* success */
13968 + spin_lock(&fhsm->fhsm_spin);
13969 + fhsm->fhsm_pid = 0;
13970 + spin_unlock(&fhsm->fhsm_spin);
13976 +/* ---------------------------------------------------------------------- */
13978 +int au_fhsm_br_alloc(struct au_branch *br)
13983 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13985 + au_br_fhsm_init(br->br_fhsm);
13992 +/* ---------------------------------------------------------------------- */
13994 +void au_fhsm_fin(struct super_block *sb)
13996 + au_fhsm_notify(sb, /*val*/-1);
13999 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14001 + struct au_fhsm *fhsm;
14003 + fhsm = &sbinfo->si_fhsm;
14004 + spin_lock_init(&fhsm->fhsm_spin);
14005 + init_waitqueue_head(&fhsm->fhsm_wqh);
14006 + atomic_set(&fhsm->fhsm_readable, 0);
14007 + fhsm->fhsm_expire
14008 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14009 + fhsm->fhsm_bottom = -1;
14012 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14014 + sbinfo->si_fhsm.fhsm_expire
14015 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14018 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14022 + if (!au_ftest_si(sbinfo, FHSM))
14025 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14026 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14027 + seq_printf(seq, ",fhsm_sec=%u", u);
14029 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14030 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14031 +++ linux/fs/aufs/file.c 2022-03-21 14:49:05.723299677 +0100
14033 +// SPDX-License-Identifier: GPL-2.0
14035 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14037 + * This program, aufs is free software; you can redistribute it and/or modify
14038 + * it under the terms of the GNU General Public License as published by
14039 + * the Free Software Foundation; either version 2 of the License, or
14040 + * (at your option) any later version.
14042 + * This program is distributed in the hope that it will be useful,
14043 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14044 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14045 + * GNU General Public License for more details.
14047 + * You should have received a copy of the GNU General Public License
14048 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14052 + * handling file/dir, and address_space operation
14055 +#ifdef CONFIG_AUFS_DEBUG
14056 +#include <linux/migrate.h>
14058 +#include <linux/pagemap.h>
14061 +/* drop flags for writing */
14062 +unsigned int au_file_roflags(unsigned int flags)
14064 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14065 + flags |= O_RDONLY | O_NOATIME;
14069 +/* common functions to regular file and dir */
14070 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14071 + struct file *file, int force_wr)
14073 + struct file *h_file;
14074 + struct dentry *h_dentry;
14075 + struct inode *h_inode;
14076 + struct super_block *sb;
14077 + struct au_branch *br;
14078 + struct path h_path;
14081 + /* a race condition can happen between open and unlink/rmdir */
14082 + h_file = ERR_PTR(-ENOENT);
14083 + h_dentry = au_h_dptr(dentry, bindex);
14084 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14086 + h_inode = d_inode(h_dentry);
14087 + spin_lock(&h_dentry->d_lock);
14088 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14089 + /* || !d_inode(dentry)->i_nlink */
14091 + spin_unlock(&h_dentry->d_lock);
14092 + if (unlikely(err))
14095 + sb = dentry->d_sb;
14096 + br = au_sbr(sb, bindex);
14097 + err = au_br_test_oflag(flags, br);
14098 + h_file = ERR_PTR(err);
14099 + if (unlikely(err))
14102 + /* drop flags for writing */
14103 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14104 + if (force_wr && !(flags & O_WRONLY))
14106 + flags = au_file_roflags(flags);
14108 + h_file = ERR_PTR(-EROFS);
14109 + flags = au_file_roflags(flags);
14110 + if (unlikely(vfsub_native_ro(h_inode)
14111 + || IS_APPEND(h_inode)))
14113 + flags &= ~O_ACCMODE;
14114 + flags |= O_WRONLY;
14117 + flags &= ~O_CREAT;
14118 + au_lcnt_inc(&br->br_nfiles);
14119 + h_path.dentry = h_dentry;
14120 + h_path.mnt = au_br_mnt(br);
14121 + h_file = vfsub_dentry_open(&h_path, flags);
14122 + if (IS_ERR(h_file))
14125 + if (flags & __FMODE_EXEC) {
14126 + err = deny_write_access(h_file);
14127 + if (unlikely(err)) {
14129 + h_file = ERR_PTR(err);
14133 + fsnotify_open(h_file);
14134 + goto out; /* success */
14137 + au_lcnt_dec(&br->br_nfiles);
14142 +static int au_cmoo(struct dentry *dentry)
14144 + int err, cmoo, matched;
14145 + unsigned int udba;
14146 + struct path h_path;
14147 + struct au_pin pin;
14148 + struct au_cp_generic cpg = {
14149 + .dentry = dentry,
14154 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14156 + struct inode *delegated;
14157 + struct super_block *sb;
14158 + struct au_sbinfo *sbinfo;
14159 + struct au_fhsm *fhsm;
14161 + struct au_branch *br;
14162 + struct dentry *parent;
14163 + struct au_hinode *hdir;
14165 + DiMustWriteLock(dentry);
14166 + IiMustWriteLock(d_inode(dentry));
14169 + if (IS_ROOT(dentry))
14171 + cpg.bsrc = au_dbtop(dentry);
14175 + sb = dentry->d_sb;
14176 + sbinfo = au_sbi(sb);
14177 + fhsm = &sbinfo->si_fhsm;
14178 + pid = au_fhsm_pid(fhsm);
14181 + && (current->pid == pid
14182 + || rcu_dereference(current->real_parent)->pid == pid));
14183 + rcu_read_unlock();
14187 + br = au_sbr(sb, cpg.bsrc);
14188 + cmoo = au_br_cmoo(br->br_perm);
14191 + if (!d_is_reg(dentry))
14192 + cmoo &= AuBrAttr_COO_ALL;
14196 + parent = dget_parent(dentry);
14197 + di_write_lock_parent(parent);
14198 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14200 + if (unlikely(err < 0)) {
14201 + err = 0; /* there is no upper writable branch */
14204 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14206 + /* do not respect the coo attrib for the target branch */
14207 + err = au_cpup_dirs(dentry, cpg.bdst);
14208 + if (unlikely(err))
14211 + di_downgrade_lock(parent, AuLock_IR);
14212 + udba = au_opt_udba(sb);
14213 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14214 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14215 + if (unlikely(err))
14218 + err = au_sio_cpup_simple(&cpg);
14220 + if (unlikely(err))
14222 + if (!(cmoo & AuBrWAttr_MOO))
14223 + goto out_parent; /* success */
14225 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14226 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14227 + if (unlikely(err))
14230 + h_path.mnt = au_br_mnt(br);
14231 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14232 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14233 + delegated = NULL;
14234 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14236 + /* todo: keep h_dentry or not? */
14237 + if (unlikely(err == -EWOULDBLOCK)) {
14238 + pr_warn("cannot retry for NFSv4 delegation"
14239 + " for an internal unlink\n");
14242 + if (unlikely(err)) {
14243 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14247 + goto out_parent; /* success */
14250 + di_downgrade_lock(parent, AuLock_IR);
14252 + di_read_unlock(parent, AuLock_IR);
14259 +int au_do_open(struct file *file, struct au_do_open_args *args)
14261 + int err, aopen = args->aopen;
14262 + struct dentry *dentry;
14263 + struct au_finfo *finfo;
14266 + err = au_finfo_init(file, args->fidir);
14269 + err = au_finfo_init(file, args->fidir);
14272 + if (unlikely(err))
14275 + dentry = file->f_path.dentry;
14276 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14277 + di_write_lock_child(dentry);
14278 + err = au_cmoo(dentry);
14279 + di_downgrade_lock(dentry, AuLock_IR);
14282 + err = args->open(file, vfsub_file_flags(file), NULL);
14285 + err = args->open(file, vfsub_file_flags(file),
14290 + di_read_unlock(dentry, AuLock_IR);
14292 + finfo = au_fi(file);
14294 + finfo->fi_file = file;
14295 + au_hbl_add(&finfo->fi_hlist,
14296 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14299 + fi_write_unlock(file);
14302 + fi_write_unlock(file);
14305 + if (unlikely(err)) {
14306 + finfo->fi_hdir = NULL;
14307 + au_finfo_fin(file);
14315 +int au_reopen_nondir(struct file *file)
14318 + aufs_bindex_t btop;
14319 + struct dentry *dentry;
14320 + struct au_branch *br;
14321 + struct file *h_file, *h_file_tmp;
14323 + dentry = file->f_path.dentry;
14324 + btop = au_dbtop(dentry);
14325 + br = au_sbr(dentry->d_sb, btop);
14326 + h_file_tmp = NULL;
14327 + if (au_fbtop(file) == btop) {
14328 + h_file = au_hf_top(file);
14329 + if (file->f_mode == h_file->f_mode)
14330 + return 0; /* success */
14331 + h_file_tmp = h_file;
14332 + get_file(h_file_tmp);
14333 + au_lcnt_inc(&br->br_nfiles);
14334 + au_set_h_fptr(file, btop, NULL);
14336 + AuDebugOn(au_fi(file)->fi_hdir);
14339 + * file exists on both of rw and ro
14340 + * open --> dbtop and fbtop are both 0
14341 + * prepend a branch as rw, "rw" become ro
14343 + * delete the top branch, "rw" becomes rw again
14344 + * --> dbtop is 1, fbtop is still 0
14345 + * write --> fbtop is 0 but dbtop is 1
14347 + /* AuDebugOn(au_fbtop(file) < btop); */
14349 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14350 + file, /*force_wr*/0);
14351 + err = PTR_ERR(h_file);
14352 + if (IS_ERR(h_file)) {
14353 + if (h_file_tmp) {
14355 + au_set_h_fptr(file, btop, h_file_tmp);
14356 + h_file_tmp = NULL;
14358 + goto out; /* todo: close all? */
14362 + au_set_fbtop(file, btop);
14363 + au_set_h_fptr(file, btop, h_file);
14364 + au_update_figen(file);
14365 + /* todo: necessary? */
14366 + /* file->f_ra = h_file->f_ra; */
14369 + if (h_file_tmp) {
14370 + fput(h_file_tmp);
14371 + au_lcnt_dec(&br->br_nfiles);
14376 +/* ---------------------------------------------------------------------- */
14378 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14379 + struct dentry *hi_wh)
14382 + aufs_bindex_t btop;
14383 + struct au_dinfo *dinfo;
14384 + struct dentry *h_dentry;
14385 + struct au_hdentry *hdp;
14387 + dinfo = au_di(file->f_path.dentry);
14388 + AuRwMustWriteLock(&dinfo->di_rwsem);
14390 + btop = dinfo->di_btop;
14391 + dinfo->di_btop = btgt;
14392 + hdp = au_hdentry(dinfo, btgt);
14393 + h_dentry = hdp->hd_dentry;
14394 + hdp->hd_dentry = hi_wh;
14395 + err = au_reopen_nondir(file);
14396 + hdp->hd_dentry = h_dentry;
14397 + dinfo->di_btop = btop;
14402 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14403 + aufs_bindex_t bcpup, struct au_pin *pin)
14406 + struct inode *inode, *h_inode;
14407 + struct dentry *h_dentry, *hi_wh;
14408 + struct au_cp_generic cpg = {
14409 + .dentry = file->f_path.dentry,
14416 + au_update_dbtop(cpg.dentry);
14417 + inode = d_inode(cpg.dentry);
14419 + if (au_dbtop(cpg.dentry) <= bcpup
14420 + && au_dbbot(cpg.dentry) >= bcpup) {
14421 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14422 + if (h_dentry && d_is_positive(h_dentry))
14423 + h_inode = d_inode(h_dentry);
14425 + hi_wh = au_hi_wh(inode, bcpup);
14426 + if (!hi_wh && !h_inode)
14427 + err = au_sio_cpup_wh(&cpg, file);
14429 + /* already copied-up after unlink */
14430 + err = au_reopen_wh(file, bcpup, hi_wh);
14433 + && (inode->i_nlink > 1
14434 + || (inode->i_state & I_LINKABLE))
14435 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14436 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14442 + * prepare the @file for writing.
14444 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14447 + aufs_bindex_t dbtop;
14448 + struct dentry *parent;
14449 + struct inode *inode;
14450 + struct super_block *sb;
14451 + struct file *h_file;
14452 + struct au_cp_generic cpg = {
14453 + .dentry = file->f_path.dentry,
14458 + .flags = AuCpup_DTIME
14461 + sb = cpg.dentry->d_sb;
14462 + inode = d_inode(cpg.dentry);
14463 + cpg.bsrc = au_fbtop(file);
14464 + err = au_test_ro(sb, cpg.bsrc, inode);
14465 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14466 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14471 + /* need to cpup or reopen */
14472 + parent = dget_parent(cpg.dentry);
14473 + di_write_lock_parent(parent);
14474 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14476 + if (unlikely(err < 0))
14480 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14481 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14482 + if (unlikely(err))
14486 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14487 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14488 + if (unlikely(err))
14491 + dbtop = au_dbtop(cpg.dentry);
14492 + if (dbtop <= cpg.bdst)
14493 + cpg.bsrc = cpg.bdst;
14495 + if (dbtop <= cpg.bdst /* just reopen */
14496 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14498 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14499 + if (IS_ERR(h_file))
14500 + err = PTR_ERR(h_file);
14502 + di_downgrade_lock(parent, AuLock_IR);
14503 + if (dbtop > cpg.bdst)
14504 + err = au_sio_cpup_simple(&cpg);
14506 + err = au_reopen_nondir(file);
14507 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14509 + } else { /* copyup as wh and reopen */
14511 + * since writable hfsplus branch is not supported,
14512 + * h_open_pre/post() are unnecessary.
14514 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14515 + di_downgrade_lock(parent, AuLock_IR);
14519 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14520 + goto out_dput; /* success */
14526 + di_downgrade_lock(parent, AuLock_IR);
14528 + di_read_unlock(parent, AuLock_IR);
14535 +/* ---------------------------------------------------------------------- */
14537 +int au_do_flush(struct file *file, fl_owner_t id,
14538 + int (*flush)(struct file *file, fl_owner_t id))
14541 + struct super_block *sb;
14542 + struct inode *inode;
14544 + inode = file_inode(file);
14545 + sb = inode->i_sb;
14546 + si_noflush_read_lock(sb);
14547 + fi_read_lock(file);
14548 + ii_read_lock_child(inode);
14550 + err = flush(file, id);
14551 + au_cpup_attr_timesizes(inode);
14553 + ii_read_unlock(inode);
14554 + fi_read_unlock(file);
14555 + si_read_unlock(sb);
14559 +/* ---------------------------------------------------------------------- */
14561 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14564 + struct au_pin pin;
14565 + struct au_finfo *finfo;
14566 + struct dentry *parent, *hi_wh;
14567 + struct inode *inode;
14568 + struct super_block *sb;
14569 + struct au_cp_generic cpg = {
14570 + .dentry = file->f_path.dentry,
14575 + .flags = AuCpup_DTIME
14578 + FiMustWriteLock(file);
14581 + finfo = au_fi(file);
14582 + sb = cpg.dentry->d_sb;
14583 + inode = d_inode(cpg.dentry);
14584 + cpg.bdst = au_ibtop(inode);
14585 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14588 + parent = dget_parent(cpg.dentry);
14589 + if (au_test_ro(sb, cpg.bdst, inode)) {
14590 + di_read_lock_parent(parent, !AuLock_IR);
14591 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14593 + di_read_unlock(parent, !AuLock_IR);
14594 + if (unlikely(err < 0))
14599 + di_read_lock_parent(parent, AuLock_IR);
14600 + hi_wh = au_hi_wh(inode, cpg.bdst);
14601 + if (!S_ISDIR(inode->i_mode)
14602 + && au_opt_test(au_mntflags(sb), PLINK)
14603 + && au_plink_test(inode)
14604 + && !d_unhashed(cpg.dentry)
14605 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14606 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14607 + if (unlikely(err))
14610 + /* always superio. */
14611 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14612 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14614 + err = au_sio_cpup_simple(&cpg);
14617 + } else if (hi_wh) {
14618 + /* already copied-up after unlink */
14619 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14620 + *need_reopen = 0;
14624 + di_read_unlock(parent, AuLock_IR);
14631 +static void au_do_refresh_dir(struct file *file)
14633 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14634 + struct au_hfile *p, tmp, *q;
14635 + struct au_finfo *finfo;
14636 + struct super_block *sb;
14637 + struct au_fidir *fidir;
14639 + FiMustWriteLock(file);
14641 + sb = file->f_path.dentry->d_sb;
14642 + finfo = au_fi(file);
14643 + fidir = finfo->fi_hdir;
14644 + AuDebugOn(!fidir);
14645 + p = fidir->fd_hfile + finfo->fi_btop;
14646 + brid = p->hf_br->br_id;
14647 + bbot = fidir->fd_bbot;
14648 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14652 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14653 + if (new_bindex == bindex)
14655 + if (new_bindex < 0) {
14656 + au_set_h_fptr(file, bindex, NULL);
14660 + /* swap two lower inode, and loop again */
14661 + q = fidir->fd_hfile + new_bindex;
14665 + if (tmp.hf_file) {
14671 + p = fidir->fd_hfile;
14672 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14673 + bbot = au_sbbot(sb);
14674 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14675 + finfo->fi_btop++, p++)
14676 + if (p->hf_file) {
14677 + if (file_inode(p->hf_file))
14679 + au_hfput(p, /*execed*/0);
14682 + bbot = au_br_index(sb, brid);
14683 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14684 + finfo->fi_btop++, p++)
14686 + au_hfput(p, /*execed*/0);
14687 + bbot = au_sbbot(sb);
14690 + p = fidir->fd_hfile + bbot;
14691 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14692 + fidir->fd_bbot--, p--)
14693 + if (p->hf_file) {
14694 + if (file_inode(p->hf_file))
14696 + au_hfput(p, /*execed*/0);
14698 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14702 + * after branch manipulating, refresh the file.
14704 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14706 + int err, need_reopen, nbr;
14707 + aufs_bindex_t bbot, bindex;
14708 + struct dentry *dentry;
14709 + struct super_block *sb;
14710 + struct au_finfo *finfo;
14711 + struct au_hfile *hfile;
14713 + dentry = file->f_path.dentry;
14714 + sb = dentry->d_sb;
14715 + nbr = au_sbbot(sb) + 1;
14716 + finfo = au_fi(file);
14717 + if (!finfo->fi_hdir) {
14718 + hfile = &finfo->fi_htop;
14719 + AuDebugOn(!hfile->hf_file);
14720 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14721 + AuDebugOn(bindex < 0);
14722 + if (bindex != finfo->fi_btop)
14723 + au_set_fbtop(file, bindex);
14725 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14726 + if (unlikely(err))
14728 + au_do_refresh_dir(file);
14733 + if (!au_test_mmapped(file))
14734 + err = au_file_refresh_by_inode(file, &need_reopen);
14735 + if (finfo->fi_hdir)
14736 + /* harmless if err */
14737 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14738 + if (!err && need_reopen && !d_unlinked(dentry))
14739 + err = reopen(file);
14741 + au_update_figen(file);
14742 + goto out; /* success */
14745 + /* error, close all lower files */
14746 + if (finfo->fi_hdir) {
14747 + bbot = au_fbbot_dir(file);
14748 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14749 + au_set_h_fptr(file, bindex, NULL);
14756 +/* common function to regular file and dir */
14757 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14758 + int wlock, unsigned int fi_lsc)
14761 + unsigned int sigen, figen;
14762 + aufs_bindex_t btop;
14763 + unsigned char pseudo_link;
14764 + struct dentry *dentry;
14765 + struct inode *inode;
14768 + dentry = file->f_path.dentry;
14769 + inode = d_inode(dentry);
14770 + sigen = au_sigen(dentry->d_sb);
14771 + fi_write_lock_nested(file, fi_lsc);
14772 + figen = au_figen(file);
14774 + di_write_lock_child(dentry);
14776 + di_write_lock_child2(dentry);
14777 + btop = au_dbtop(dentry);
14778 + pseudo_link = (btop != au_ibtop(inode));
14779 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14781 + di_downgrade_lock(dentry, AuLock_IR);
14782 + fi_downgrade_lock(file);
14784 + goto out; /* success */
14787 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14788 + if (au_digen_test(dentry, sigen)) {
14789 + err = au_reval_dpath(dentry, sigen);
14790 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14794 + err = refresh_file(file, reopen);
14797 + di_downgrade_lock(dentry, AuLock_IR);
14798 + fi_downgrade_lock(file);
14801 + di_write_unlock(dentry);
14802 + fi_write_unlock(file);
14809 +/* ---------------------------------------------------------------------- */
14811 +/* cf. aufs_nopage() */
14812 +/* for madvise(2) */
14813 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14815 + unlock_page(page);
14819 +/* it will never be called, but necessary to support O_DIRECT */
14820 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14821 +{ BUG(); return 0; }
14823 +/* they will never be called. */
14824 +#ifdef CONFIG_AUFS_DEBUG
14825 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14826 + loff_t pos, unsigned len, unsigned flags,
14827 + struct page **pagep, void **fsdata)
14828 +{ AuUnsupport(); return 0; }
14829 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14830 + loff_t pos, unsigned len, unsigned copied,
14831 + struct page *page, void *fsdata)
14832 +{ AuUnsupport(); return 0; }
14833 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14834 +{ AuUnsupport(); return 0; }
14836 +static int aufs_set_page_dirty(struct page *page)
14837 +{ AuUnsupport(); return 0; }
14838 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14839 + unsigned int length)
14840 +{ AuUnsupport(); }
14841 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14842 +{ AuUnsupport(); return 0; }
14843 +#if 0 /* called by memory compaction regardless file */
14844 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14845 + struct page *page, enum migrate_mode mode)
14846 +{ AuUnsupport(); return 0; }
14848 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14849 +{ AuUnsupport(); return true; }
14850 +static void aufs_putback_page(struct page *page)
14851 +{ AuUnsupport(); }
14852 +static int aufs_launder_page(struct page *page)
14853 +{ AuUnsupport(); return 0; }
14854 +static int aufs_is_partially_uptodate(struct page *page,
14855 + unsigned long from,
14856 + unsigned long count)
14857 +{ AuUnsupport(); return 0; }
14858 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14860 +{ AuUnsupport(); }
14861 +static int aufs_error_remove_page(struct address_space *mapping,
14862 + struct page *page)
14863 +{ AuUnsupport(); return 0; }
14864 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14866 +{ AuUnsupport(); return 0; }
14867 +static void aufs_swap_deactivate(struct file *file)
14868 +{ AuUnsupport(); }
14869 +#endif /* CONFIG_AUFS_DEBUG */
14871 +const struct address_space_operations aufs_aop = {
14872 + .readpage = aufs_readpage,
14873 + .direct_IO = aufs_direct_IO,
14874 +#ifdef CONFIG_AUFS_DEBUG
14875 + .writepage = aufs_writepage,
14876 + /* no writepages, because of writepage */
14877 + .set_page_dirty = aufs_set_page_dirty,
14878 + /* no readpages, because of readpage */
14879 + .write_begin = aufs_write_begin,
14880 + .write_end = aufs_write_end,
14881 + /* no bmap, no block device */
14882 + .invalidatepage = aufs_invalidatepage,
14883 + .releasepage = aufs_releasepage,
14884 + /* is fallback_migrate_page ok? */
14885 + /* .migratepage = aufs_migratepage, */
14886 + .isolate_page = aufs_isolate_page,
14887 + .putback_page = aufs_putback_page,
14888 + .launder_page = aufs_launder_page,
14889 + .is_partially_uptodate = aufs_is_partially_uptodate,
14890 + .is_dirty_writeback = aufs_is_dirty_writeback,
14891 + .error_remove_page = aufs_error_remove_page,
14892 + .swap_activate = aufs_swap_activate,
14893 + .swap_deactivate = aufs_swap_deactivate
14894 +#endif /* CONFIG_AUFS_DEBUG */
14896 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14897 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14898 +++ linux/fs/aufs/file.h 2022-03-21 14:49:05.723299677 +0100
14900 +/* SPDX-License-Identifier: GPL-2.0 */
14902 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14904 + * This program, aufs is free software; you can redistribute it and/or modify
14905 + * it under the terms of the GNU General Public License as published by
14906 + * the Free Software Foundation; either version 2 of the License, or
14907 + * (at your option) any later version.
14909 + * This program is distributed in the hope that it will be useful,
14910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14912 + * GNU General Public License for more details.
14914 + * You should have received a copy of the GNU General Public License
14915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14919 + * file operations
14922 +#ifndef __AUFS_FILE_H__
14923 +#define __AUFS_FILE_H__
14927 +#include <linux/file.h>
14928 +#include <linux/fs.h>
14929 +#include <linux/mm_types.h>
14930 +#include <linux/poll.h>
14931 +#include "rwsem.h"
14935 + struct file *hf_file;
14936 + struct au_branch *hf_br;
14941 + aufs_bindex_t fd_bbot;
14942 + aufs_bindex_t fd_nent;
14943 + struct au_vdir *fd_vdir_cache;
14944 + struct au_hfile fd_hfile[];
14947 +static inline int au_fidir_sz(int nent)
14949 + AuDebugOn(nent < 0);
14950 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14954 + atomic_t fi_generation;
14956 + struct au_rwsem fi_rwsem;
14957 + aufs_bindex_t fi_btop;
14959 + /* do not union them */
14960 + struct { /* for non-dir */
14961 + struct au_hfile fi_htop;
14962 + atomic_t fi_mmapped;
14964 + struct au_fidir *fi_hdir; /* for dir only */
14966 + struct hlist_bl_node fi_hlist;
14967 + struct file *fi_file; /* very ugly */
14968 + struct rcu_head rcu;
14969 +} ____cacheline_aligned_in_smp;
14971 +/* ---------------------------------------------------------------------- */
14974 +extern const struct address_space_operations aufs_aop;
14975 +unsigned int au_file_roflags(unsigned int flags);
14976 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14977 + struct file *file, int force_wr);
14978 +struct au_do_open_args {
14980 + int (*open)(struct file *file, int flags,
14981 + struct file *h_file);
14982 + struct au_fidir *fidir;
14983 + struct file *h_file;
14985 +int au_do_open(struct file *file, struct au_do_open_args *args);
14986 +int au_reopen_nondir(struct file *file);
14988 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14989 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14990 + int wlock, unsigned int fi_lsc);
14991 +int au_do_flush(struct file *file, fl_owner_t id,
14992 + int (*flush)(struct file *file, fl_owner_t id));
14995 +#ifdef CONFIG_AUFS_POLL
14996 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
14999 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15001 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15003 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15004 + struct file *h_file);
15006 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15007 + aufs_bindex_t bindex, int force_wr)
15008 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15009 + struct file *h_file);
15013 +extern const struct file_operations aufs_file_fop;
15014 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15015 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15016 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15019 +void au_hfput(struct au_hfile *hf, int execed);
15020 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15021 + struct file *h_file);
15023 +void au_update_figen(struct file *file);
15024 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15025 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15027 +void au_fi_init_once(void *_fi);
15028 +void au_finfo_fin(struct file *file);
15029 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15032 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15033 +#ifdef CONFIG_COMPAT
15034 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15035 + unsigned long arg);
15036 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15037 + unsigned long arg);
15040 +/* ---------------------------------------------------------------------- */
15042 +static inline struct au_finfo *au_fi(struct file *file)
15044 + return file->private_data;
15047 +/* ---------------------------------------------------------------------- */
15049 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15050 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15051 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15052 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15054 +#define fi_read_trylock_nested(f) \
15055 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15056 +#define fi_write_trylock_nested(f) \
15057 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15060 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15061 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15062 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15064 +/* lock subclass for finfo */
15070 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15072 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15075 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15077 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15081 + * fi_read_lock_1, fi_write_lock_1,
15082 + * fi_read_lock_2, fi_write_lock_2
15084 +#define AuReadLockFunc(name) \
15085 +static inline void fi_read_lock_##name(struct file *f) \
15086 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15088 +#define AuWriteLockFunc(name) \
15089 +static inline void fi_write_lock_##name(struct file *f) \
15090 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15092 +#define AuRWLockFuncs(name) \
15093 + AuReadLockFunc(name) \
15094 + AuWriteLockFunc(name)
15099 +#undef AuReadLockFunc
15100 +#undef AuWriteLockFunc
15101 +#undef AuRWLockFuncs
15103 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15104 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15105 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15107 +/* ---------------------------------------------------------------------- */
15109 +/* todo: hard/soft set? */
15110 +static inline aufs_bindex_t au_fbtop(struct file *file)
15112 + FiMustAnyLock(file);
15113 + return au_fi(file)->fi_btop;
15116 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15118 + FiMustAnyLock(file);
15119 + AuDebugOn(!au_fi(file)->fi_hdir);
15120 + return au_fi(file)->fi_hdir->fd_bbot;
15123 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15125 + FiMustAnyLock(file);
15126 + AuDebugOn(!au_fi(file)->fi_hdir);
15127 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15130 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15132 + FiMustWriteLock(file);
15133 + au_fi(file)->fi_btop = bindex;
15136 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15138 + FiMustWriteLock(file);
15139 + AuDebugOn(!au_fi(file)->fi_hdir);
15140 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15143 +static inline void au_set_fvdir_cache(struct file *file,
15144 + struct au_vdir *vdir_cache)
15146 + FiMustWriteLock(file);
15147 + AuDebugOn(!au_fi(file)->fi_hdir);
15148 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15151 +static inline struct file *au_hf_top(struct file *file)
15153 + FiMustAnyLock(file);
15154 + AuDebugOn(au_fi(file)->fi_hdir);
15155 + return au_fi(file)->fi_htop.hf_file;
15158 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15160 + FiMustAnyLock(file);
15161 + AuDebugOn(!au_fi(file)->fi_hdir);
15162 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15165 +/* todo: memory barrier? */
15166 +static inline unsigned int au_figen(struct file *f)
15168 + return atomic_read(&au_fi(f)->fi_generation);
15171 +static inline void au_set_mmapped(struct file *f)
15173 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15175 + pr_warn("fi_mmapped wrapped around\n");
15176 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15180 +static inline void au_unset_mmapped(struct file *f)
15182 + atomic_dec(&au_fi(f)->fi_mmapped);
15185 +static inline int au_test_mmapped(struct file *f)
15187 + return atomic_read(&au_fi(f)->fi_mmapped);
15190 +/* customize vma->vm_file */
15192 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15193 + struct file *file)
15197 + f = vma->vm_file;
15199 + vma->vm_file = file;
15204 +#define AuDbgVmRegion(file, vma) do {} while (0)
15206 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15207 + struct file *file)
15209 + au_do_vm_file_reset(vma, file);
15212 +#define AuDbgVmRegion(file, vma) \
15213 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15215 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15216 + struct file *file)
15220 + au_do_vm_file_reset(vma, file);
15221 + f = vma->vm_region->vm_file;
15223 + vma->vm_region->vm_file = file;
15226 +#endif /* CONFIG_MMU */
15228 +/* handle vma->vm_prfile */
15229 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15230 + struct file *file)
15233 + vma->vm_prfile = file;
15234 +#ifndef CONFIG_MMU
15236 + vma->vm_region->vm_prfile = file;
15240 +#endif /* __KERNEL__ */
15241 +#endif /* __AUFS_FILE_H__ */
15242 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15243 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15244 +++ linux/fs/aufs/finfo.c 2022-03-21 14:49:05.723299677 +0100
15246 +// SPDX-License-Identifier: GPL-2.0
15248 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15250 + * This program, aufs is free software; you can redistribute it and/or modify
15251 + * it under the terms of the GNU General Public License as published by
15252 + * the Free Software Foundation; either version 2 of the License, or
15253 + * (at your option) any later version.
15255 + * This program is distributed in the hope that it will be useful,
15256 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15257 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15258 + * GNU General Public License for more details.
15260 + * You should have received a copy of the GNU General Public License
15261 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15265 + * file private data
15270 +void au_hfput(struct au_hfile *hf, int execed)
15273 + allow_write_access(hf->hf_file);
15274 + fput(hf->hf_file);
15275 + hf->hf_file = NULL;
15276 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15277 + hf->hf_br = NULL;
15280 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15282 + struct au_finfo *finfo = au_fi(file);
15283 + struct au_hfile *hf;
15284 + struct au_fidir *fidir;
15286 + fidir = finfo->fi_hdir;
15288 + AuDebugOn(finfo->fi_btop != bindex);
15289 + hf = &finfo->fi_htop;
15291 + hf = fidir->fd_hfile + bindex;
15293 + if (hf && hf->hf_file)
15294 + au_hfput(hf, vfsub_file_execed(file));
15296 + FiMustWriteLock(file);
15297 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15298 + hf->hf_file = val;
15299 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15303 +void au_update_figen(struct file *file)
15305 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15306 + /* smp_mb(); */ /* atomic_set */
15309 +/* ---------------------------------------------------------------------- */
15311 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15313 + struct au_fidir *fidir;
15316 + nbr = au_sbbot(sb) + 1;
15318 + nbr = 2; /* initial allocate for 2 branches */
15319 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15321 + fidir->fd_bbot = -1;
15322 + fidir->fd_nent = nbr;
15328 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15331 + struct au_fidir *fidir, *p;
15333 + AuRwMustWriteLock(&finfo->fi_rwsem);
15334 + fidir = finfo->fi_hdir;
15335 + AuDebugOn(!fidir);
15338 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15339 + GFP_NOFS, may_shrink);
15341 + p->fd_nent = nbr;
15342 + finfo->fi_hdir = p;
15349 +/* ---------------------------------------------------------------------- */
15351 +void au_finfo_fin(struct file *file)
15353 + struct au_finfo *finfo;
15355 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15357 + finfo = au_fi(file);
15358 + AuDebugOn(finfo->fi_hdir);
15359 + AuRwDestroy(&finfo->fi_rwsem);
15360 + au_cache_free_finfo(finfo);
15363 +void au_fi_init_once(void *_finfo)
15365 + struct au_finfo *finfo = _finfo;
15367 + au_rw_init(&finfo->fi_rwsem);
15370 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15373 + struct au_finfo *finfo;
15374 + struct dentry *dentry;
15377 + dentry = file->f_path.dentry;
15378 + finfo = au_cache_alloc_finfo();
15379 + if (unlikely(!finfo))
15383 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15384 + au_rw_write_lock(&finfo->fi_rwsem);
15385 + finfo->fi_btop = -1;
15386 + finfo->fi_hdir = fidir;
15387 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15388 + /* smp_mb(); */ /* atomic_set */
15390 + file->private_data = finfo;
15395 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15396 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15397 +++ linux/fs/aufs/f_op.c 2022-03-21 14:49:05.723299677 +0100
15399 +// SPDX-License-Identifier: GPL-2.0
15401 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15403 + * This program, aufs is free software; you can redistribute it and/or modify
15404 + * it under the terms of the GNU General Public License as published by
15405 + * the Free Software Foundation; either version 2 of the License, or
15406 + * (at your option) any later version.
15408 + * This program is distributed in the hope that it will be useful,
15409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15411 + * GNU General Public License for more details.
15413 + * You should have received a copy of the GNU General Public License
15414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15418 + * file and vm operations
15421 +#include <linux/aio.h>
15422 +#include <linux/fs_stack.h>
15423 +#include <linux/mman.h>
15424 +#include <linux/security.h>
15427 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15430 + aufs_bindex_t bindex;
15431 + struct dentry *dentry, *h_dentry;
15432 + struct au_finfo *finfo;
15433 + struct inode *h_inode;
15435 + FiMustWriteLock(file);
15438 + dentry = file->f_path.dentry;
15439 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15440 + finfo = au_fi(file);
15441 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15442 + atomic_set(&finfo->fi_mmapped, 0);
15443 + bindex = au_dbtop(dentry);
15445 + h_dentry = au_h_dptr(dentry, bindex);
15446 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15447 + if (unlikely(err))
15449 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15450 + if (IS_ERR(h_file)) {
15451 + err = PTR_ERR(h_file);
15455 + h_dentry = h_file->f_path.dentry;
15456 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15457 + if (unlikely(err))
15459 + /* br ref is already inc-ed */
15462 + if ((flags & __O_TMPFILE)
15463 + && !(flags & O_EXCL)) {
15464 + h_inode = file_inode(h_file);
15465 + spin_lock(&h_inode->i_lock);
15466 + h_inode->i_state |= I_LINKABLE;
15467 + spin_unlock(&h_inode->i_lock);
15469 + au_set_fbtop(file, bindex);
15470 + au_set_h_fptr(file, bindex, h_file);
15471 + au_update_figen(file);
15472 + /* todo: necessary? */
15473 + /* file->f_ra = h_file->f_ra; */
15479 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15480 + struct file *file)
15483 + struct super_block *sb;
15484 + struct au_do_open_args args = {
15485 + .open = au_do_open_nondir
15488 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15489 + file, vfsub_file_flags(file), file->f_mode);
15491 + sb = file->f_path.dentry->d_sb;
15492 + si_read_lock(sb, AuLock_FLUSH);
15493 + err = au_do_open(file, &args);
15494 + si_read_unlock(sb);
15498 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15500 + struct au_finfo *finfo;
15501 + aufs_bindex_t bindex;
15503 + finfo = au_fi(file);
15504 + au_hbl_del(&finfo->fi_hlist,
15505 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15506 + bindex = finfo->fi_btop;
15508 + au_set_h_fptr(file, bindex, NULL);
15510 + au_finfo_fin(file);
15514 +/* ---------------------------------------------------------------------- */
15516 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15519 + struct file *h_file;
15522 + h_file = au_hf_top(file);
15524 + err = vfsub_flush(h_file, id);
15528 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15530 + return au_do_flush(file, id, au_do_flush_nondir);
15533 +/* ---------------------------------------------------------------------- */
15535 + * read and write functions acquire [fdi]_rwsem once, but release before
15536 + * mmap_sem. This is because to stop a race condition between mmap(2).
15537 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15538 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15539 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15542 +/* Callers should call au_read_post() or fput() in the end */
15543 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15545 + struct file *h_file;
15548 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15550 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15551 + h_file = au_hf_top(file);
15552 + get_file(h_file);
15554 + fi_read_unlock(file);
15556 + h_file = ERR_PTR(err);
15561 +static void au_read_post(struct inode *inode, struct file *h_file)
15563 + /* update without lock, I don't think it a problem */
15564 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15568 +struct au_write_pre {
15570 + unsigned int lsc;
15574 + aufs_bindex_t btop;
15578 + * return with iinfo is write-locked
15579 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15582 +static struct file *au_write_pre(struct file *file, int do_ready,
15583 + struct au_write_pre *wpre)
15585 + struct file *h_file;
15586 + struct dentry *dentry;
15588 + unsigned int lsc;
15589 + struct au_pin pin;
15594 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15595 + h_file = ERR_PTR(err);
15596 + if (unlikely(err))
15599 + dentry = file->f_path.dentry;
15601 + err = au_ready_to_write(file, -1, &pin);
15602 + if (unlikely(err)) {
15603 + h_file = ERR_PTR(err);
15604 + di_write_unlock(dentry);
15609 + di_downgrade_lock(dentry, /*flags*/0);
15611 + wpre->btop = au_fbtop(file);
15612 + h_file = au_hf_top(file);
15613 + get_file(h_file);
15615 + wpre->blks = file_inode(h_file)->i_blocks;
15618 + di_read_unlock(dentry, /*flags*/0);
15621 + fi_write_unlock(file);
15626 +static void au_write_post(struct inode *inode, struct file *h_file,
15627 + struct au_write_pre *wpre, ssize_t written)
15629 + struct inode *h_inode;
15631 + au_cpup_attr_timesizes(inode);
15632 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15633 + h_inode = file_inode(h_file);
15634 + inode->i_mode = h_inode->i_mode;
15635 + ii_write_unlock(inode);
15636 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15638 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15639 + /*force*/h_inode->i_blocks > wpre->blks);
15644 + * todo: very ugly
15645 + * it locks both of i_mutex and si_rwsem for read in safe.
15646 + * if the plink maintenance mode continues forever (that is the problem),
15647 + * may loop forever.
15649 +static void au_mtx_and_read_lock(struct inode *inode)
15652 + struct super_block *sb = inode->i_sb;
15655 + inode_lock(inode);
15656 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15659 + inode_unlock(inode);
15660 + si_read_lock(sb, AuLock_NOPLMW);
15661 + si_read_unlock(sb);
15665 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15666 + struct iov_iter *iov_iter)
15669 + struct file *file;
15670 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15672 + err = security_file_permission(h_file, rw);
15673 + if (unlikely(err))
15676 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15678 + if (rw == MAY_READ)
15679 + iter = h_file->f_op->read_iter;
15680 + else if (rw == MAY_WRITE)
15681 + iter = h_file->f_op->write_iter;
15683 + file = kio->ki_filp;
15684 + kio->ki_filp = h_file;
15687 + err = iter(kio, iov_iter);
15690 + /* currently there is no such fs */
15692 + kio->ki_filp = file;
15698 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15701 + struct file *file, *h_file;
15702 + struct inode *inode;
15703 + struct super_block *sb;
15705 + file = kio->ki_filp;
15706 + inode = file_inode(file);
15707 + sb = inode->i_sb;
15708 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15710 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15711 + err = PTR_ERR(h_file);
15712 + if (IS_ERR(h_file))
15715 + if (au_test_loopback_kthread()) {
15716 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15717 + if (file->f_mapping != h_file->f_mapping) {
15718 + file->f_mapping = h_file->f_mapping;
15719 + smp_mb(); /* unnecessary? */
15722 + fi_read_unlock(file);
15724 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15725 + /* todo: necessary? */
15726 + /* file->f_ra = h_file->f_ra; */
15727 + au_read_post(inode, h_file);
15730 + si_read_unlock(sb);
15734 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15737 + struct au_write_pre wpre;
15738 + struct inode *inode;
15739 + struct file *file, *h_file;
15741 + file = kio->ki_filp;
15742 + inode = file_inode(file);
15743 + au_mtx_and_read_lock(inode);
15746 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15747 + err = PTR_ERR(h_file);
15748 + if (IS_ERR(h_file))
15751 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15752 + au_write_post(inode, h_file, &wpre, err);
15755 + si_read_unlock(inode->i_sb);
15756 + inode_unlock(inode);
15761 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15762 + * don't have their own .splice_{read,write} implimentations, and they use
15763 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15764 + * simple converters to f_op->iter_read() and ->iter_write().
15765 + * But we keep our own implementations because some non-mainlined FSes may have
15766 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15767 + * away an opportunity to co-work with aufs from them.
15769 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15770 + struct pipe_inode_info *pipe, size_t len,
15771 + unsigned int flags)
15774 + struct file *h_file;
15775 + struct inode *inode;
15776 + struct super_block *sb;
15778 + inode = file_inode(file);
15779 + sb = inode->i_sb;
15780 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15782 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15783 + err = PTR_ERR(h_file);
15784 + if (IS_ERR(h_file))
15787 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15788 + /* todo: necessary? */
15789 + /* file->f_ra = h_file->f_ra; */
15790 + au_read_post(inode, h_file);
15793 + si_read_unlock(sb);
15798 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15799 + size_t len, unsigned int flags)
15802 + struct au_write_pre wpre;
15803 + struct inode *inode;
15804 + struct file *h_file;
15806 + inode = file_inode(file);
15807 + au_mtx_and_read_lock(inode);
15810 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15811 + err = PTR_ERR(h_file);
15812 + if (IS_ERR(h_file))
15815 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15816 + au_write_post(inode, h_file, &wpre, err);
15819 + si_read_unlock(inode->i_sb);
15820 + inode_unlock(inode);
15824 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15828 + struct au_write_pre wpre;
15829 + struct inode *inode;
15830 + struct file *h_file;
15832 + inode = file_inode(file);
15833 + au_mtx_and_read_lock(inode);
15836 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15837 + err = PTR_ERR(h_file);
15838 + if (IS_ERR(h_file))
15842 + err = vfs_fallocate(h_file, mode, offset, len);
15844 + au_write_post(inode, h_file, &wpre, /*written*/1);
15847 + si_read_unlock(inode->i_sb);
15848 + inode_unlock(inode);
15852 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15853 + struct file *dst, loff_t dst_pos,
15854 + size_t len, unsigned int flags)
15857 + struct au_write_pre wpre;
15858 + enum { SRC, DST };
15860 + struct inode *inode;
15861 + struct file *h_file;
15862 + struct super_block *h_sb;
15864 +#define a_src a[SRC]
15865 +#define a_dst a[DST]
15868 + a_src.inode = file_inode(src);
15869 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15871 + a_dst.inode = file_inode(dst);
15872 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15875 + au_mtx_and_read_lock(a_dst.inode);
15877 + * in order to match the order in di_write_lock2_{child,parent}(),
15878 + * use f_path.dentry for this comparison.
15880 + if (src->f_path.dentry < dst->f_path.dentry) {
15881 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15882 + err = PTR_ERR(a_src.h_file);
15883 + if (IS_ERR(a_src.h_file))
15886 + wpre.lsc = AuLsc_FI_2;
15887 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15888 + err = PTR_ERR(a_dst.h_file);
15889 + if (IS_ERR(a_dst.h_file)) {
15890 + au_read_post(a_src.inode, a_src.h_file);
15894 + wpre.lsc = AuLsc_FI_1;
15895 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15896 + err = PTR_ERR(a_dst.h_file);
15897 + if (IS_ERR(a_dst.h_file))
15900 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15901 + err = PTR_ERR(a_src.h_file);
15902 + if (IS_ERR(a_src.h_file)) {
15903 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15910 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15911 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15912 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15918 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15919 + dst_pos, len, flags);
15922 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15923 + fi_read_unlock(src);
15924 + au_read_post(a_src.inode, a_src.h_file);
15926 + si_read_unlock(a_dst.inode->i_sb);
15927 + inode_unlock(a_dst.inode);
15934 +/* ---------------------------------------------------------------------- */
15937 + * The locking order around current->mmap_sem.
15938 + * - in most and regular cases
15939 + * file I/O syscall -- aufs_read() or something
15940 + * -- si_rwsem for read -- mmap_sem
15941 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15943 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15944 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15945 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15946 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15947 + * It means that when aufs acquires si_rwsem for write, the process should never
15948 + * acquire mmap_sem.
15950 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15951 + * problem either since any directory is not able to be mmap-ed.
15952 + * The similar scenario is applied to aufs_readlink() too.
15955 +#if 0 /* stop calling security_file_mmap() */
15956 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15957 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15959 +static unsigned long au_arch_prot_conv(unsigned long flags)
15961 + /* currently ppc64 only */
15962 +#ifdef CONFIG_PPC64
15963 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15964 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15965 + return AuConv_VM_PROT(flags, SAO);
15967 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15972 +static unsigned long au_prot_conv(unsigned long flags)
15974 + return AuConv_VM_PROT(flags, READ)
15975 + | AuConv_VM_PROT(flags, WRITE)
15976 + | AuConv_VM_PROT(flags, EXEC)
15977 + | au_arch_prot_conv(flags);
15980 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15981 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15983 +static unsigned long au_flag_conv(unsigned long flags)
15985 + return AuConv_VM_MAP(flags, GROWSDOWN)
15986 + | AuConv_VM_MAP(flags, DENYWRITE)
15987 + | AuConv_VM_MAP(flags, LOCKED);
15991 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
15994 + const unsigned char wlock
15995 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
15996 + struct super_block *sb;
15997 + struct file *h_file;
15998 + struct inode *inode;
16000 + AuDbgVmRegion(file, vma);
16002 + inode = file_inode(file);
16003 + sb = inode->i_sb;
16005 + si_read_lock(sb, AuLock_NOPLMW);
16007 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16009 + err = PTR_ERR(h_file);
16010 + if (IS_ERR(h_file))
16014 + au_set_mmapped(file);
16015 + au_vm_file_reset(vma, h_file);
16017 + * we cannot call security_mmap_file() here since it may acquire
16018 + * mmap_sem or i_mutex.
16020 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16021 + * au_flag_conv(vma->vm_flags));
16024 + err = call_mmap(h_file, vma);
16026 + au_vm_prfile_set(vma, file);
16027 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16028 + goto out_fput; /* success */
16030 + au_unset_mmapped(file);
16031 + au_vm_file_reset(vma, file);
16035 + ii_write_unlock(inode);
16040 + si_read_unlock(sb);
16046 +/* ---------------------------------------------------------------------- */
16048 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16052 + struct au_write_pre wpre;
16053 + struct inode *inode;
16054 + struct file *h_file;
16056 + err = 0; /* -EBADF; */ /* posix? */
16057 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16060 + inode = file_inode(file);
16061 + au_mtx_and_read_lock(inode);
16064 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16065 + err = PTR_ERR(h_file);
16066 + if (IS_ERR(h_file))
16069 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16070 + au_write_post(inode, h_file, &wpre, /*written*/0);
16073 + si_read_unlock(inode->i_sb);
16074 + inode_unlock(inode);
16079 +static int aufs_fasync(int fd, struct file *file, int flag)
16082 + struct file *h_file;
16083 + struct super_block *sb;
16085 + sb = file->f_path.dentry->d_sb;
16086 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16088 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16089 + err = PTR_ERR(h_file);
16090 + if (IS_ERR(h_file))
16093 + if (h_file->f_op->fasync)
16094 + err = h_file->f_op->fasync(fd, h_file, flag);
16095 + fput(h_file); /* instead of au_read_post() */
16098 + si_read_unlock(sb);
16102 +static int aufs_setfl(struct file *file, unsigned long arg)
16105 + struct file *h_file;
16106 + struct super_block *sb;
16108 + sb = file->f_path.dentry->d_sb;
16109 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16111 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16112 + err = PTR_ERR(h_file);
16113 + if (IS_ERR(h_file))
16116 + /* stop calling h_file->fasync */
16117 + arg |= vfsub_file_flags(file) & FASYNC;
16118 + err = setfl(/*unused fd*/-1, h_file, arg);
16119 + fput(h_file); /* instead of au_read_post() */
16122 + si_read_unlock(sb);
16126 +/* ---------------------------------------------------------------------- */
16128 +/* no one supports this operation, currently */
16129 +#if 0 /* reserved for future use */
16130 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16131 + size_t len, loff_t *pos, int more)
16136 +/* ---------------------------------------------------------------------- */
16138 +const struct file_operations aufs_file_fop = {
16139 + .owner = THIS_MODULE,
16141 + .llseek = default_llseek,
16143 + .read_iter = aufs_read_iter,
16144 + .write_iter = aufs_write_iter,
16146 +#ifdef CONFIG_AUFS_POLL
16147 + .poll = aufs_poll,
16149 + .unlocked_ioctl = aufs_ioctl_nondir,
16150 +#ifdef CONFIG_COMPAT
16151 + .compat_ioctl = aufs_compat_ioctl_nondir,
16153 + .mmap = aufs_mmap,
16154 + .open = aufs_open_nondir,
16155 + .flush = aufs_flush_nondir,
16156 + .release = aufs_release_nondir,
16157 + .fsync = aufs_fsync_nondir,
16158 + .fasync = aufs_fasync,
16159 + /* .sendpage = aufs_sendpage, */
16160 + .setfl = aufs_setfl,
16161 + .splice_write = aufs_splice_write,
16162 + .splice_read = aufs_splice_read,
16163 +#if 0 /* reserved for future use */
16164 + .aio_splice_write = aufs_aio_splice_write,
16165 + .aio_splice_read = aufs_aio_splice_read,
16167 + .fallocate = aufs_fallocate,
16168 + .copy_file_range = aufs_copy_file_range
16170 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16171 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16172 +++ linux/fs/aufs/fsctx.c 2022-03-21 14:49:05.723299677 +0100
16174 +// SPDX-License-Identifier: GPL-2.0
16176 + * Copyright (C) 2022 Junjiro R. Okajima
16178 + * This program, aufs is free software; you can redistribute it and/or modify
16179 + * it under the terms of the GNU General Public License as published by
16180 + * the Free Software Foundation; either version 2 of the License, or
16181 + * (at your option) any later version.
16183 + * This program is distributed in the hope that it will be useful,
16184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16186 + * GNU General Public License for more details.
16188 + * You should have received a copy of the GNU General Public License
16189 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16193 + * fs context, aka new mount api
16196 +#include <linux/fs_context.h>
16199 +struct au_fsctx_opts {
16200 + aufs_bindex_t bindex;
16201 + unsigned char skipped;
16202 + struct au_opt *opt, *opt_tail;
16203 + struct super_block *sb;
16204 + struct au_sbinfo *sbinfo;
16205 + struct au_opts opts;
16208 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16209 +static int cvt_err(int err)
16223 +static int au_fsctx_reconfigure(struct fs_context *fc)
16226 + unsigned int mntflags;
16227 + struct dentry *root;
16228 + struct super_block *sb;
16229 + struct inode *inode;
16230 + struct au_fsctx_opts *a = fc->fs_private;
16232 + AuDbg("fc %p\n", fc);
16236 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16238 + di_write_lock_child(root);
16239 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16240 + aufs_write_unlock(root);
16243 + inode = d_inode(root);
16244 + inode_lock(inode);
16245 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16246 + if (unlikely(err))
16248 + di_write_lock_child(root);
16250 + /* au_opts_remount() may return an error */
16251 + err = au_opts_remount(sb, &a->opts);
16253 + if (au_ftest_opts(a->opts.flags, REFRESH))
16254 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16257 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16258 + mntflags = au_mntflags(sb);
16259 + do_dx = !!au_opt_test(mntflags, DIO);
16260 + au_dy_arefresh(do_dx);
16263 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16264 + aufs_write_unlock(root);
16267 + inode_unlock(inode);
16268 + err = cvt_err(err);
16274 +/* ---------------------------------------------------------------------- */
16276 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16279 + struct au_fsctx_opts *a = fc->fs_private;
16280 + struct au_sbinfo *sbinfo = a->sbinfo;
16281 + struct dentry *root;
16282 + struct inode *inode;
16284 + sbinfo->si_sb = sb;
16285 + sb->s_fs_info = sbinfo;
16286 + kobject_get(&sbinfo->si_kobj);
16288 + __si_write_lock(sb);
16290 + au_sbilist_add(sb);
16292 + /* all timestamps always follow the ones on the branch */
16293 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16294 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16295 + sb->s_op = &aufs_sop;
16296 + sb->s_d_op = &aufs_dop;
16297 + sb->s_magic = AUFS_SUPER_MAGIC;
16298 + sb->s_maxbytes = 0;
16299 + sb->s_stack_depth = 1;
16300 + au_export_init(sb);
16301 + au_xattr_init(sb);
16303 + err = au_alloc_root(sb);
16304 + if (unlikely(err)) {
16305 + si_write_unlock(sb);
16308 + root = sb->s_root;
16309 + inode = d_inode(root);
16310 + ii_write_lock_parent(inode);
16311 + aufs_write_unlock(root);
16313 + /* lock vfs_inode first, then aufs. */
16314 + inode_lock(inode);
16315 + aufs_write_lock(root);
16316 + err = au_opts_mount(sb, &a->opts);
16318 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16319 + sb->s_d_op = &aufs_dop_noreval;
16320 + /* infofc(fc, "%ps", sb->s_d_op); */
16321 + pr_info("%ps\n", sb->s_d_op);
16322 + au_refresh_dop(root, /*force_reval*/0);
16323 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16324 + au_refresh_iop(inode, /*force_getattr*/0);
16326 + aufs_write_unlock(root);
16327 + inode_unlock(inode);
16329 + goto out; /* success */
16332 + sb->s_root = NULL;
16335 + if (unlikely(err))
16336 + kobject_put(&sbinfo->si_kobj);
16338 + err = cvt_err(err);
16343 +static int au_fsctx_get_tree(struct fs_context *fc)
16347 + AuDbg("fc %p\n", fc);
16348 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16354 +/* ---------------------------------------------------------------------- */
16356 +static void au_fsctx_dump(struct au_opts *opts)
16358 +#ifdef CONFIG_AUFS_DEBUG
16359 + /* reduce stack space */
16361 + struct au_opt_add *add;
16362 + struct au_opt_del *del;
16363 + struct au_opt_mod *mod;
16364 + struct au_opt_xino *xino;
16365 + struct au_opt_xino_itrunc *xino_itrunc;
16366 + struct au_opt_wbr_create *create;
16368 + struct au_opt *opt;
16371 + while (opt->type != Opt_tail) {
16372 + switch (opt->type) {
16374 + u.add = &opt->add;
16375 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16376 + u.add->bindex, u.add->pathname, u.add->perm,
16377 + u.add->path.dentry);
16382 + u.del = &opt->del;
16383 + AuDbg("del {%s, %p}\n",
16384 + u.del->pathname, u.del->h_path.dentry);
16389 + u.mod = &opt->mod;
16390 + AuDbg("mod {%s, 0x%x, %p}\n",
16391 + u.mod->path, u.mod->perm, u.mod->h_root);
16394 + u.add = &opt->add;
16395 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16396 + u.add->bindex, u.add->pathname, u.add->perm,
16397 + u.add->path.dentry);
16399 + case Opt_prepend:
16400 + u.add = &opt->add;
16401 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16402 + u.add->bindex, u.add->pathname, u.add->perm,
16403 + u.add->path.dentry);
16407 + AuDbg("dirwh %d\n", opt->dirwh);
16409 + case Opt_rdcache:
16410 + AuDbg("rdcache %d\n", opt->rdcache);
16413 + AuDbg("rdblk %d\n", opt->rdblk);
16416 + AuDbg("rdhash %u\n", opt->rdhash);
16420 + u.xino = &opt->xino;
16421 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16424 +#define au_fsctx_TF(name) \
16425 + case Opt_##name: \
16429 + AuLabel(no##name); \
16432 + /* simple true/false flag */
16433 + au_fsctx_TF(trunc_xino);
16434 + au_fsctx_TF(trunc_xib);
16435 + au_fsctx_TF(dirperm1);
16436 + au_fsctx_TF(plink);
16437 + au_fsctx_TF(shwh);
16438 + au_fsctx_TF(dio);
16439 + au_fsctx_TF(warn_perm);
16440 + au_fsctx_TF(verbose);
16441 + au_fsctx_TF(sum);
16442 + au_fsctx_TF(dirren);
16443 + au_fsctx_TF(acl);
16444 +#undef au_fsctx_TF
16446 + case Opt_trunc_xino_path:
16448 + case Opt_itrunc_xino:
16449 + u.xino_itrunc = &opt->xino_itrunc;
16450 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16456 + case Opt_list_plink:
16457 + AuLabel(list_plink);
16460 + AuDbg("udba %d, %s\n",
16461 + opt->udba, au_optstr_udba(opt->udba));
16463 + case Opt_diropq_a:
16464 + AuLabel(diropq_a);
16466 + case Opt_diropq_w:
16467 + AuLabel(diropq_w);
16472 + case Opt_wbr_create:
16473 + u.create = &opt->wbr_create;
16474 + AuDbg("create %d, %s\n", u.create->wbr_create,
16475 + au_optstr_wbr_create(u.create->wbr_create));
16476 + switch (u.create->wbr_create) {
16477 + case AuWbrCreate_MFSV:
16479 + case AuWbrCreate_PMFSV:
16480 + AuDbg("%d sec\n", u.create->mfs_second);
16482 + case AuWbrCreate_MFSRR:
16484 + case AuWbrCreate_TDMFS:
16485 + AuDbg("%llu watermark\n",
16486 + u.create->mfsrr_watermark);
16488 + case AuWbrCreate_MFSRRV:
16490 + case AuWbrCreate_TDMFSV:
16492 + case AuWbrCreate_PMFSRRV:
16493 + AuDbg("%llu watermark, %d sec\n",
16494 + u.create->mfsrr_watermark,
16495 + u.create->mfs_second);
16499 + case Opt_wbr_copyup:
16500 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16501 + au_optstr_wbr_copyup(opt->wbr_copyup));
16503 + case Opt_fhsm_sec:
16504 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16508 + AuDbg("type %d\n", opt->type);
16516 +/* ---------------------------------------------------------------------- */
16519 + * For conditionally compiled mount options.
16520 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16522 +#define au_ignore_flag(name, action) \
16523 + fsparam_flag(name, action), \
16524 + fsparam_flag("no" name, Opt_ignore_silent)
16526 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16527 + fsparam_string("br", Opt_br),
16529 + /* "add=%d:%s" or "ins=%d:%s" */
16530 + fsparam_string("add", Opt_add),
16531 + fsparam_string("ins", Opt_add),
16532 + fsparam_path("append", Opt_append),
16533 + fsparam_path("prepend", Opt_prepend),
16535 + fsparam_path("del", Opt_del),
16536 + /* fsparam_s32("idel", Opt_idel), */
16537 + fsparam_path("mod", Opt_mod),
16538 + /* fsparam_string("imod", Opt_imod), */
16540 + fsparam_s32("dirwh", Opt_dirwh),
16542 + fsparam_path("xino", Opt_xino),
16543 + fsparam_flag("noxino", Opt_noxino),
16544 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16545 + /* "trunc_xino_v=%d:%d" */
16546 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16547 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16548 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16549 + /* fsparam_path("zxino", Opt_zxino), */
16550 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16552 +#ifdef CONFIG_PROC_FS
16553 + fsparam_flag_no("plink", Opt_plink),
16555 + au_ignore_flag("plink", Opt_ignore),
16558 +#ifdef CONFIG_AUFS_DEBUG
16559 + fsparam_flag("list_plink", Opt_list_plink),
16562 + fsparam_string("udba", Opt_udba),
16564 + fsparam_flag_no("dio", Opt_dio),
16566 +#ifdef CONFIG_AUFS_DIRREN
16567 + fsparam_flag_no("dirren", Opt_dirren),
16569 + au_ignore_flag("dirren", Opt_ignore),
16572 +#ifdef CONFIG_AUFS_FHSM
16573 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16575 + fsparam_s32("fhsm_sec", Opt_ignore),
16578 + /* always | a | whiteouted | w */
16579 + fsparam_string("diropq", Opt_diropq),
16581 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16583 +#ifdef CONFIG_AUFS_SHWH
16584 + fsparam_flag_no("shwh", Opt_shwh),
16586 + au_ignore_flag("shwh", Opt_err),
16589 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16591 + fsparam_flag_no("verbose", Opt_verbose),
16592 + fsparam_flag("v", Opt_verbose),
16593 + fsparam_flag("quiet", Opt_noverbose),
16594 + fsparam_flag("q", Opt_noverbose),
16595 + /* user-space may handle this */
16596 + fsparam_flag("silent", Opt_noverbose),
16598 + fsparam_flag_no("sum", Opt_sum),
16599 + fsparam_flag("wsum", Opt_wsum),
16601 + fsparam_s32("rdcache", Opt_rdcache),
16602 + /* "def" or s32 */
16603 + fsparam_string("rdblk", Opt_rdblk),
16604 + /* "def" or s32 */
16605 + fsparam_string("rdhash", Opt_rdhash),
16607 + fsparam_string("create", Opt_wbr_create),
16608 + fsparam_string("create_policy", Opt_wbr_create),
16609 + fsparam_string("cpup", Opt_wbr_copyup),
16610 + fsparam_string("copyup", Opt_wbr_copyup),
16611 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16613 + /* generic VFS flag */
16614 +#ifdef CONFIG_FS_POSIX_ACL
16615 + fsparam_flag_no("acl", Opt_acl),
16617 + au_ignore_flag("acl"),
16620 + /* internal use for the scripts */
16621 + fsparam_string("si", Opt_ignore_silent),
16623 + /* obsoleted, keep them temporary */
16624 + fsparam_flag("nodlgt", Opt_ignore_silent),
16625 + fsparam_flag("clean_plink", Opt_ignore),
16626 + fsparam_string("dirs", Opt_br),
16627 + fsparam_u32("debug", Opt_ignore),
16628 + /* "whiteout" or "all" */
16629 + fsparam_string("delete", Opt_ignore),
16630 + fsparam_string("imap", Opt_ignore),
16632 + /* temporary workaround, due to old mount(8)? */
16633 + fsparam_flag("relatime", Opt_ignore_silent),
16638 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16639 + char *brspec, size_t speclen,
16640 + aufs_bindex_t bindex)
16645 + AuDbg("brspec %s\n", brspec);
16649 + speclen = strlen(brspec);
16650 + /* will be freed by au_fsctx_free() */
16651 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16652 + if (unlikely(!p)) {
16653 + errorfc(fc, "failed in %s", brspec);
16656 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16663 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16667 + struct au_fsctx_opts *a = fc->fs_private;
16668 + struct au_opt *opt = a->opt;
16669 + aufs_bindex_t bindex = a->bindex;
16671 + AuDbg("brspec %s\n", brspec);
16674 + while ((p = strsep(&brspec, ":")) && *p) {
16675 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16677 + if (unlikely(err))
16681 + if (unlikely(opt > a->opt_tail)) {
16687 + opt->type = Opt_tail;
16690 + a->bindex = bindex;
16697 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16701 + struct au_fsctx_opts *a = fc->fs_private;
16702 + struct au_opt *opt = a->opt;
16705 + p = strchr(addspec, ':');
16706 + if (unlikely(!p)) {
16707 + errorfc(fc, "bad arg in %s", addspec);
16711 + err = kstrtoint(addspec, 0, &n);
16712 + if (unlikely(err)) {
16713 + errorfc(fc, "bad integer in %s", addspec);
16716 + AuDbg("n %d\n", n);
16717 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16724 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16725 + struct fs_parameter *param)
16730 + /* will be freed by au_fsctx_free() */
16731 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16732 + if (unlikely(!del->pathname))
16734 + AuDbg("del %s\n", del->pathname);
16735 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16736 + if (unlikely(err))
16737 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16744 +#if 0 /* reserved for future use */
16745 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16746 + aufs_bindex_t bindex)
16749 + struct super_block *sb;
16750 + struct dentry *root;
16751 + struct au_fsctx_opts *a = fc->fs_private;
16757 + root = sb->s_root;
16758 + aufs_read_lock(root, AuLock_FLUSH);
16759 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16760 + errorfc(fc, "out of bounds, %d", bindex);
16765 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16766 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16769 + aufs_read_unlock(root, !AuLock_IR);
16775 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16776 + struct fs_parameter *param)
16779 + struct path path;
16783 + /* will be freed by au_fsctx_free() */
16784 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16785 + if (unlikely(!mod->path))
16789 + p = strchr(mod->path, '=');
16790 + if (unlikely(!p)) {
16791 + errorfc(fc, "no permission %s", mod->path);
16796 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16797 + if (unlikely(err)) {
16798 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16802 + mod->perm = au_br_perm_val(p);
16803 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16804 + mod->h_root = dget(path.dentry);
16812 +#if 0 /* reserved for future use */
16813 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16818 + struct super_block *sb;
16819 + struct dentry *root;
16820 + struct au_fsctx_opts *a = fc->fs_private;
16826 + p = strchr(ibrspec, ':');
16827 + if (unlikely(!p)) {
16828 + errorfc(fc, "no index, %s", ibrspec);
16832 + err = kstrtoint(ibrspec, 0, &n);
16833 + if (unlikely(err)) {
16834 + errorfc(fc, "bad integer in %s", ibrspec);
16837 + AuDbg("n %d\n", n);
16839 + root = sb->s_root;
16840 + aufs_read_lock(root, AuLock_FLUSH);
16841 + if (n < 0 || au_sbbot(sb) < n) {
16842 + errorfc(fc, "out of bounds, %d", bindex);
16847 + mod->perm = au_br_perm_val(p);
16848 + AuDbg("mod path %s, perm 0x%x, %s\n",
16849 + mod->path, mod->perm, p);
16850 + mod->h_root = dget(au_h_dptr(root, bindex));
16853 + aufs_read_unlock(root, !AuLock_IR);
16860 +static int au_fsctx_parse_xino(struct fs_context *fc,
16861 + struct au_opt_xino *xino,
16862 + struct fs_parameter *param)
16865 + struct au_fsctx_opts *a = fc->fs_private;
16868 + /* will be freed by au_opts_free() */
16869 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16870 + if (unlikely(!xino->path))
16872 + AuDbg("path %s\n", xino->path);
16874 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16876 + err = PTR_ERR(xino->file);
16877 + if (IS_ERR(xino->file)) {
16878 + xino->file = NULL;
16883 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16885 + errorfc(fc, "%s must be outside", xino->path);
16894 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16895 + struct au_opt_xino_itrunc *xino_itrunc,
16899 + aufs_bindex_t bbot, bindex;
16900 + struct path path;
16901 + struct dentry *root;
16902 + struct au_fsctx_opts *a = fc->fs_private;
16904 + AuDebugOn(!a->sb);
16906 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16907 + if (unlikely(err)) {
16908 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16912 + xino_itrunc->bindex = -1;
16913 + root = a->sb->s_root;
16914 + aufs_read_lock(root, AuLock_FLUSH);
16915 + bbot = au_sbbot(a->sb);
16916 + for (bindex = 0; bindex <= bbot; bindex++) {
16917 + if (au_h_dptr(root, bindex) == path.dentry) {
16918 + xino_itrunc->bindex = bindex;
16922 + aufs_read_unlock(root, !AuLock_IR);
16925 + if (unlikely(xino_itrunc->bindex < 0)) {
16927 + errorfc(fc, "no such branch %s", pathname);
16935 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16936 + struct au_opt_xino_itrunc *xino_itrunc,
16937 + unsigned int bindex)
16940 + aufs_bindex_t bbot;
16941 + struct super_block *sb;
16942 + struct au_fsctx_opts *a = fc->fs_private;
16948 + si_noflush_read_lock(sb);
16949 + bbot = au_sbbot(sb);
16950 + si_read_unlock(sb);
16951 + if (bindex <= bbot)
16952 + xino_itrunc->bindex = bindex;
16955 + errorfc(fc, "out of bounds, %u", bindex);
16962 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16965 + struct fs_parse_result result;
16966 + struct au_fsctx_opts *a = fc->fs_private;
16967 + struct au_opt *opt = a->opt;
16969 + AuDbg("fc %p, param {key %s, string %s}\n",
16970 + fc, param->key, param->string);
16971 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16972 + if (unlikely(err < 0))
16975 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
16976 + token, result.negated, result.uint_64);
16982 + err = au_fsctx_parse_br(fc, param->string);
16985 + err = au_fsctx_parse_add(fc, param->string);
16988 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
16989 + /*dummy bindex*/1);
16991 + case Opt_prepend:
16992 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
16997 + err = au_fsctx_parse_del(fc, &opt->del, param);
16999 +#if 0 /* reserved for future use */
17006 + del->pathname = "(indexed)";
17007 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17012 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17014 +#ifdef IMOD /* reserved for future use */
17021 + u.mod->path = "(indexed)";
17022 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17027 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17029 + case Opt_trunc_xino_path:
17031 + errorfc(fc, "no such branch %s", param->string);
17034 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17038 + case Opt_trunc_xino_v:
17044 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17048 + case Opt_itrunc_xino:
17050 + errorfc(fc, "out of bounds %s", param->string);
17053 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17059 + opt->dirwh = result.int_32;
17062 + case Opt_rdcache:
17063 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17064 + errorfc(fc, "rdcache must be smaller than %d",
17065 + AUFS_RDCACHE_MAX);
17069 + opt->rdcache = result.int_32;
17074 + opt->rdblk = AUFS_RDBLK_DEF;
17075 + if (!strcmp(param->string, "def"))
17078 + err = kstrtoint(param->string, 0, &result.int_32);
17079 + if (unlikely(err)) {
17080 + errorfc(fc, "bad value in %s", param->key);
17084 + if (unlikely(result.int_32 < 0
17085 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17086 + errorfc(fc, "bad value in %s", param->key);
17089 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17090 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17094 + opt->rdblk = result.int_32;
17099 + opt->rdhash = AUFS_RDHASH_DEF;
17100 + if (!strcmp(param->string, "def"))
17103 + err = kstrtoint(param->string, 0, &result.int_32);
17104 + if (unlikely(err)) {
17105 + errorfc(fc, "bad value in %s", param->key);
17108 + /* how about zero? */
17109 + if (result.int_32 < 0
17110 + || result.int_32 * sizeof(struct hlist_head)
17111 + > KMALLOC_MAX_SIZE) {
17113 + errorfc(fc, "bad integer in %s", param->key);
17116 + opt->rdhash = result.int_32;
17121 + * As other options, fs/aufs/opts.c can handle these strings by
17122 + * match_token(). But "diropq=" is deprecated now and will
17123 + * never have other value. So simple strcmp() is enough here.
17125 + if (!strcmp(param->string, "a") ||
17126 + !strcmp(param->string, "always")) {
17128 + opt->type = Opt_diropq_a;
17129 + } else if (!strcmp(param->string, "w") ||
17130 + !strcmp(param->string, "whiteouted")) {
17132 + opt->type = Opt_diropq_w;
17134 + errorfc(fc, "unknown value %s", param->string);
17138 + opt->udba = au_udba_val(param->string);
17139 + if (opt->udba >= 0)
17142 + errorf(fc, "wrong value, %s", param->string);
17145 + case Opt_wbr_create:
17146 + opt->wbr_create.wbr_create
17147 + = au_wbr_create_val(param->string, &opt->wbr_create);
17148 + if (opt->wbr_create.wbr_create >= 0)
17151 + errorf(fc, "wrong value, %s", param->key);
17154 + case Opt_wbr_copyup:
17155 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17156 + if (opt->wbr_copyup >= 0)
17159 + errorfc(fc, "wrong value, %s", param->key);
17162 + case Opt_fhsm_sec:
17163 + if (unlikely(result.int_32 < 0)) {
17164 + errorfc(fc, "bad integer in %s\n", param->key);
17169 + opt->fhsm_second = result.int_32;
17171 + warnfc(fc, "ignored %s %s", param->key, param->string);
17174 + /* simple true/false flag */
17175 +#define au_fsctx_TF(name) \
17176 + case Opt_##name: \
17178 + opt->tf = !result.negated; \
17180 + au_fsctx_TF(trunc_xino);
17181 + au_fsctx_TF(trunc_xib);
17182 + au_fsctx_TF(dirperm1);
17183 + au_fsctx_TF(plink);
17184 + au_fsctx_TF(shwh);
17185 + au_fsctx_TF(dio);
17186 + au_fsctx_TF(warn_perm);
17187 + au_fsctx_TF(verbose);
17188 + au_fsctx_TF(sum);
17189 + au_fsctx_TF(dirren);
17190 + au_fsctx_TF(acl);
17191 +#undef au_fsctx_TF
17193 + case Opt_noverbose:
17195 + opt->type = Opt_verbose;
17201 + case Opt_list_plink:
17208 + warnfc(fc, "ignored %s", param->key);
17210 + case Opt_ignore_silent:
17219 + if (unlikely(err))
17227 + case Opt_noverbose:
17232 + opt->type = token;
17236 + if (unlikely(opt > a->opt_tail)) {
17240 + opt->type = Opt_tail;
17248 + * these options accept both 'name=val' and 'name:val' form.
17249 + * some accept optional '=' in its value.
17250 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17252 +static inline unsigned int is_colonopt(char *str)
17254 +#define do_test(name) \
17255 + if (!strncmp(str, name ":", sizeof(name))) \
17256 + return sizeof(name) - 1;
17260 + do_test("append");
17261 + do_test("prepend");
17263 + /* do_test("idel"); */
17265 + /* do_test("imod"); */
17271 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17276 + struct au_fsctx_opts *a = fc->fs_private;
17279 + AuDbg("str %s\n", str);
17281 + u = is_colonopt(str);
17284 + str = strchr(str, ',');
17290 + AuDbg("str %s\n", str);
17292 + err = generic_parse_monolithic(fc, str);
17294 + au_fsctx_dump(&a->opts);
17299 +/* ---------------------------------------------------------------------- */
17301 +static void au_fsctx_opts_free(struct au_opts *opts)
17303 + struct au_opt *opt;
17306 + while (opt->type != Opt_tail) {
17307 + switch (opt->type) {
17312 + case Opt_prepend:
17313 + kfree(opt->add.pathname);
17314 + path_put(&opt->add.path);
17317 + kfree(opt->del.pathname);
17320 + path_put(&opt->del.h_path);
17323 + kfree(opt->mod.path);
17326 + dput(opt->mod.h_root);
17329 + kfree(opt->xino.path);
17330 + fput(opt->xino.file);
17337 +static void au_fsctx_free(struct fs_context *fc)
17339 + struct au_fsctx_opts *a = fc->fs_private;
17341 + /* fs_type=%p, root=%pD */
17342 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17343 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17345 + kobject_put(&a->sbinfo->si_kobj);
17346 + au_fsctx_opts_free(&a->opts);
17347 + free_page((unsigned long)a->opts.opt);
17351 +static const struct fs_context_operations au_fsctx_ops = {
17352 + .free = au_fsctx_free,
17353 + .parse_param = au_fsctx_parse_param,
17354 + .parse_monolithic = au_fsctx_parse_monolithic,
17355 + .get_tree = au_fsctx_get_tree,
17356 + .reconfigure = au_fsctx_reconfigure
17358 + * nfs4 requires ->dup()? No.
17359 + * I don't know what is this ->dup() for.
17363 +int aufs_fsctx_init(struct fs_context *fc)
17366 + struct au_fsctx_opts *a;
17368 + /* fs_type=%p, root=%pD */
17369 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17370 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17372 + /* they will be freed by au_fsctx_free() */
17374 + a = kzalloc(sizeof(*a), GFP_NOFS);
17375 + if (unlikely(!a))
17378 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17379 + if (unlikely(!a->opts.opt))
17381 + a->opt = a->opts.opt;
17382 + a->opt->type = Opt_tail;
17383 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17384 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17385 + a->opts.sb_flags = fc->sb_flags;
17389 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17390 + a->opts.flags = AuOpts_REMOUNT;
17391 + a->sb = fc->root->d_sb;
17392 + a->sbinfo = au_sbi(a->sb);
17393 + kobject_get(&a->sbinfo->si_kobj);
17395 + a->sbinfo = au_si_alloc(a->sb);
17396 + AuDebugOn(!a->sbinfo);
17397 + err = PTR_ERR(a->sbinfo);
17398 + if (IS_ERR(a->sbinfo))
17400 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17404 + fc->fs_private = a;
17405 + fc->ops = &au_fsctx_ops;
17406 + goto out; /* success */
17409 + free_page((unsigned long)a->opts.opt);
17416 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17417 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17418 +++ linux/fs/aufs/fstype.h 2022-03-21 14:49:05.723299677 +0100
17420 +/* SPDX-License-Identifier: GPL-2.0 */
17422 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17424 + * This program, aufs is free software; you can redistribute it and/or modify
17425 + * it under the terms of the GNU General Public License as published by
17426 + * the Free Software Foundation; either version 2 of the License, or
17427 + * (at your option) any later version.
17429 + * This program is distributed in the hope that it will be useful,
17430 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17431 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17432 + * GNU General Public License for more details.
17434 + * You should have received a copy of the GNU General Public License
17435 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17439 + * judging filesystem type
17442 +#ifndef __AUFS_FSTYPE_H__
17443 +#define __AUFS_FSTYPE_H__
17447 +#include <linux/fs.h>
17448 +#include <linux/magic.h>
17449 +#include <linux/nfs_fs.h>
17450 +#include <linux/romfs_fs.h>
17452 +static inline int au_test_aufs(struct super_block *sb)
17454 + return sb->s_magic == AUFS_SUPER_MAGIC;
17457 +static inline const char *au_sbtype(struct super_block *sb)
17459 + return sb->s_type->name;
17462 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17464 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17465 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17471 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17473 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17474 + return sb->s_magic == ROMFS_MAGIC;
17480 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17482 +#if IS_ENABLED(CONFIG_CRAMFS)
17483 + return sb->s_magic == CRAMFS_MAGIC;
17488 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17490 +#if IS_ENABLED(CONFIG_NFS_FS)
17491 + return sb->s_magic == NFS_SUPER_MAGIC;
17497 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17499 +#if IS_ENABLED(CONFIG_FUSE_FS)
17500 + return sb->s_magic == FUSE_SUPER_MAGIC;
17506 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17508 +#if IS_ENABLED(CONFIG_XFS_FS)
17509 + return sb->s_magic == XFS_SB_MAGIC;
17515 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17517 +#ifdef CONFIG_TMPFS
17518 + return sb->s_magic == TMPFS_MAGIC;
17524 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17526 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17527 + return !strcmp(au_sbtype(sb), "ecryptfs");
17533 +static inline int au_test_ramfs(struct super_block *sb)
17535 + return sb->s_magic == RAMFS_MAGIC;
17538 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17540 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17541 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17547 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17549 +#ifdef CONFIG_PROC_FS
17550 + return sb->s_magic == PROC_SUPER_MAGIC;
17556 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17558 +#ifdef CONFIG_SYSFS
17559 + return sb->s_magic == SYSFS_MAGIC;
17565 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17567 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17568 + return sb->s_magic == CONFIGFS_MAGIC;
17574 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17576 +#if IS_ENABLED(CONFIG_MINIX_FS)
17577 + return sb->s_magic == MINIX3_SUPER_MAGIC
17578 + || sb->s_magic == MINIX2_SUPER_MAGIC
17579 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17580 + || sb->s_magic == MINIX_SUPER_MAGIC
17581 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17587 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17589 +#if IS_ENABLED(CONFIG_FAT_FS)
17590 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17596 +static inline int au_test_msdos(struct super_block *sb)
17598 + return au_test_fat(sb);
17601 +static inline int au_test_vfat(struct super_block *sb)
17603 + return au_test_fat(sb);
17606 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17608 +#ifdef CONFIG_SECURITYFS
17609 + return sb->s_magic == SECURITYFS_MAGIC;
17615 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17617 +#if IS_ENABLED(CONFIG_SQUASHFS)
17618 + return sb->s_magic == SQUASHFS_MAGIC;
17624 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17626 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17627 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17633 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17635 +#if IS_ENABLED(CONFIG_XENFS)
17636 + return sb->s_magic == XENFS_SUPER_MAGIC;
17642 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17644 +#ifdef CONFIG_DEBUG_FS
17645 + return sb->s_magic == DEBUGFS_MAGIC;
17651 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17653 +#if IS_ENABLED(CONFIG_NILFS)
17654 + return sb->s_magic == NILFS_SUPER_MAGIC;
17660 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17662 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17663 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17669 +/* ---------------------------------------------------------------------- */
17671 + * they can't be an aufs branch.
17673 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17676 +#ifndef CONFIG_AUFS_BR_RAMFS
17677 + au_test_ramfs(sb) ||
17679 + au_test_procfs(sb)
17680 + || au_test_sysfs(sb)
17681 + || au_test_configfs(sb)
17682 + || au_test_debugfs(sb)
17683 + || au_test_securityfs(sb)
17684 + || au_test_xenfs(sb)
17685 + || au_test_ecryptfs(sb)
17686 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17687 + || au_test_aufs(sb); /* will be supported in next version */
17690 +static inline int au_test_fs_remote(struct super_block *sb)
17692 + return !au_test_tmpfs(sb)
17693 +#ifdef CONFIG_AUFS_BR_RAMFS
17694 + && !au_test_ramfs(sb)
17696 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17699 +/* ---------------------------------------------------------------------- */
17702 + * Note: these functions (below) are created after reading ->getattr() in all
17703 + * filesystems under linux/fs. it means we have to do so in every update...
17707 + * some filesystems require getattr to refresh the inode attributes before
17709 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17710 + * and leave the work for d_revalidate()
17712 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17714 + return au_test_nfs(sb)
17715 + || au_test_fuse(sb)
17716 + /* || au_test_btrfs(sb) */ /* untested */
17721 + * filesystems which don't maintain i_size or i_blocks.
17723 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17725 + return au_test_xfs(sb)
17726 + || au_test_btrfs(sb)
17727 + || au_test_ubifs(sb)
17728 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17729 + /* || au_test_minix(sb) */ /* untested */
17734 + * filesystems which don't store the correct value in some of their inode
17737 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17739 + return au_test_fs_bad_iattr_size(sb)
17740 + || au_test_fat(sb)
17741 + || au_test_msdos(sb)
17742 + || au_test_vfat(sb);
17745 +/* they don't check i_nlink in link(2) */
17746 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17748 + return au_test_tmpfs(sb)
17749 +#ifdef CONFIG_AUFS_BR_RAMFS
17750 + || au_test_ramfs(sb)
17752 + || au_test_ubifs(sb)
17753 + || au_test_hfsplus(sb);
17757 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17759 +static inline int au_test_fs_notime(struct super_block *sb)
17761 + return au_test_nfs(sb)
17762 + || au_test_fuse(sb)
17763 + || au_test_ubifs(sb)
17767 +/* temporary support for i#1 in cramfs */
17768 +static inline int au_test_fs_unique_ino(struct inode *inode)
17770 + if (au_test_cramfs(inode->i_sb))
17771 + return inode->i_ino != 1;
17775 +/* ---------------------------------------------------------------------- */
17778 + * the filesystem where the xino files placed must support i/o after unlink and
17779 + * maintain i_size and i_blocks.
17781 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17783 + return au_test_fs_remote(sb)
17784 + || au_test_fs_bad_iattr_size(sb)
17785 + /* don't want unnecessary work for xino */
17786 + || au_test_aufs(sb)
17787 + || au_test_ecryptfs(sb)
17788 + || au_test_nilfs(sb);
17791 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17793 + return au_test_tmpfs(sb)
17794 + || au_test_ramfs(sb);
17798 + * test if the @sb is real-readonly.
17800 +static inline int au_test_fs_rr(struct super_block *sb)
17802 + return au_test_squashfs(sb)
17803 + || au_test_iso9660(sb)
17804 + || au_test_cramfs(sb)
17805 + || au_test_romfs(sb);
17809 + * test if the @inode is nfs with 'noacl' option
17810 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17812 +static inline int au_test_nfs_noacl(struct inode *inode)
17814 + return au_test_nfs(inode->i_sb)
17815 + /* && IS_POSIXACL(inode) */
17816 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17819 +#endif /* __KERNEL__ */
17820 +#endif /* __AUFS_FSTYPE_H__ */
17821 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17822 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17823 +++ linux/fs/aufs/hbl.h 2022-03-21 14:49:05.723299677 +0100
17825 +/* SPDX-License-Identifier: GPL-2.0 */
17827 + * Copyright (C) 2017-2021 Junjiro R. Okajima
17829 + * This program, aufs is free software; you can redistribute it and/or modify
17830 + * it under the terms of the GNU General Public License as published by
17831 + * the Free Software Foundation; either version 2 of the License, or
17832 + * (at your option) any later version.
17834 + * This program is distributed in the hope that it will be useful,
17835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17837 + * GNU General Public License for more details.
17839 + * You should have received a copy of the GNU General Public License
17840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17844 + * helpers for hlist_bl.h
17847 +#ifndef __AUFS_HBL_H__
17848 +#define __AUFS_HBL_H__
17852 +#include <linux/list_bl.h>
17854 +static inline void au_hbl_add(struct hlist_bl_node *node,
17855 + struct hlist_bl_head *hbl)
17857 + hlist_bl_lock(hbl);
17858 + hlist_bl_add_head(node, hbl);
17859 + hlist_bl_unlock(hbl);
17862 +static inline void au_hbl_del(struct hlist_bl_node *node,
17863 + struct hlist_bl_head *hbl)
17865 + hlist_bl_lock(hbl);
17866 + hlist_bl_del(node);
17867 + hlist_bl_unlock(hbl);
17870 +#define au_hbl_for_each(pos, head) \
17871 + for (pos = hlist_bl_first(head); \
17875 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17877 + unsigned long cnt;
17878 + struct hlist_bl_node *pos;
17881 + hlist_bl_lock(hbl);
17882 + au_hbl_for_each(pos, hbl)
17884 + hlist_bl_unlock(hbl);
17888 +#endif /* __KERNEL__ */
17889 +#endif /* __AUFS_HBL_H__ */
17890 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17891 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17892 +++ linux/fs/aufs/hfsnotify.c 2022-03-21 14:49:05.723299677 +0100
17894 +// SPDX-License-Identifier: GPL-2.0
17896 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17898 + * This program, aufs is free software; you can redistribute it and/or modify
17899 + * it under the terms of the GNU General Public License as published by
17900 + * the Free Software Foundation; either version 2 of the License, or
17901 + * (at your option) any later version.
17903 + * This program is distributed in the hope that it will be useful,
17904 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17905 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17906 + * GNU General Public License for more details.
17908 + * You should have received a copy of the GNU General Public License
17909 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17913 + * fsnotify for the lower directories
17918 +/* FS_IN_IGNORED is unnecessary */
17919 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17920 + | FS_CREATE | FS_EVENT_ON_CHILD);
17921 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17922 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17924 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17926 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17928 + /* AuDbg("here\n"); */
17929 + au_cache_free_hnotify(hn);
17930 + smp_mb__before_atomic(); /* for atomic64_dec */
17931 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17932 + wake_up(&au_hfsn_wq);
17935 +static int au_hfsn_alloc(struct au_hinode *hinode)
17938 + struct au_hnotify *hn;
17939 + struct super_block *sb;
17940 + struct au_branch *br;
17941 + struct fsnotify_mark *mark;
17942 + aufs_bindex_t bindex;
17944 + hn = hinode->hi_notify;
17945 + sb = hn->hn_aufs_inode->i_sb;
17946 + bindex = au_br_index(sb, hinode->hi_id);
17947 + br = au_sbr(sb, bindex);
17948 + AuDebugOn(!br->br_hfsn);
17950 + mark = &hn->hn_mark;
17951 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17952 + mark->mask = AuHfsnMask;
17954 + * by udba rename or rmdir, aufs assign a new inode to the known
17955 + * h_inode, so specify 1 to allow dups.
17958 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17964 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17966 + struct fsnotify_mark *mark;
17967 + unsigned long long ull;
17968 + struct fsnotify_group *group;
17970 + ull = atomic64_inc_return(&au_hfsn_ifree);
17973 + mark = &hn->hn_mark;
17974 + spin_lock(&mark->lock);
17975 + group = mark->group;
17976 + fsnotify_get_group(group);
17977 + spin_unlock(&mark->lock);
17979 + fsnotify_destroy_mark(mark, group);
17980 + fsnotify_put_mark(mark);
17981 + fsnotify_put_group(group);
17984 + /* free hn by myself */
17988 +/* ---------------------------------------------------------------------- */
17990 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
17992 + struct fsnotify_mark *mark;
17994 + mark = &hinode->hi_notify->hn_mark;
17995 + spin_lock(&mark->lock);
17997 + AuDebugOn(mark->mask & AuHfsnMask);
17998 + mark->mask |= AuHfsnMask;
18000 + AuDebugOn(!(mark->mask & AuHfsnMask));
18001 + mark->mask &= ~AuHfsnMask;
18003 + spin_unlock(&mark->lock);
18004 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18007 +/* ---------------------------------------------------------------------- */
18009 +/* #define AuDbgHnotify */
18010 +#ifdef AuDbgHnotify
18011 +static char *au_hfsn_name(u32 mask)
18013 +#ifdef CONFIG_AUFS_DEBUG
18014 +#define test_ret(flag) \
18016 + if (mask & flag) \
18019 + test_ret(FS_ACCESS);
18020 + test_ret(FS_MODIFY);
18021 + test_ret(FS_ATTRIB);
18022 + test_ret(FS_CLOSE_WRITE);
18023 + test_ret(FS_CLOSE_NOWRITE);
18024 + test_ret(FS_OPEN);
18025 + test_ret(FS_MOVED_FROM);
18026 + test_ret(FS_MOVED_TO);
18027 + test_ret(FS_CREATE);
18028 + test_ret(FS_DELETE);
18029 + test_ret(FS_DELETE_SELF);
18030 + test_ret(FS_MOVE_SELF);
18031 + test_ret(FS_UNMOUNT);
18032 + test_ret(FS_Q_OVERFLOW);
18033 + test_ret(FS_IN_IGNORED);
18034 + test_ret(FS_ISDIR);
18035 + test_ret(FS_IN_ONESHOT);
18036 + test_ret(FS_EVENT_ON_CHILD);
18045 +/* ---------------------------------------------------------------------- */
18047 +static void au_hfsn_free_group(struct fsnotify_group *group)
18049 + struct au_br_hfsnotify *hfsn = group->private;
18051 + /* AuDbg("here\n"); */
18052 + au_kfree_try_rcu(hfsn);
18055 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18056 + u32 mask, const void *data, int data_type,
18057 + struct inode *dir,
18058 + const struct qstr *file_name, u32 cookie,
18059 + struct fsnotify_iter_info *iter_info)
18062 + struct au_hnotify *hnotify;
18063 + struct inode *h_dir, *h_inode;
18064 + struct fsnotify_mark *inode_mark;
18066 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18067 + || data_type == FSNOTIFY_EVENT_DENTRY));
18070 + /* if FS_UNMOUNT happens, there must be another bug */
18071 + AuDebugOn(mask & FS_UNMOUNT);
18072 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18077 +#ifdef AuDbgHnotify
18079 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
18080 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
18081 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18082 + h_dir->i_ino, mask, au_hfsn_name(mask),
18083 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
18084 + /* WARN_ON(1); */
18089 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18090 + AuDebugOn(!inode_mark);
18091 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18092 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18098 +static struct fsnotify_ops au_hfsn_ops = {
18099 + .handle_event = au_hfsn_handle_event,
18100 + .free_group_priv = au_hfsn_free_group,
18101 + .free_mark = au_hfsn_free_mark
18104 +/* ---------------------------------------------------------------------- */
18106 +static void au_hfsn_fin_br(struct au_branch *br)
18108 + struct au_br_hfsnotify *hfsn;
18110 + hfsn = br->br_hfsn;
18113 + fsnotify_put_group(hfsn->hfsn_group);
18118 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18121 + struct fsnotify_group *group;
18122 + struct au_br_hfsnotify *hfsn;
18125 + br->br_hfsn = NULL;
18126 + if (!au_br_hnotifyable(perm))
18130 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18131 + if (unlikely(!hfsn))
18135 + group = fsnotify_alloc_group(&au_hfsn_ops);
18136 + if (IS_ERR(group)) {
18137 + err = PTR_ERR(group);
18138 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18142 + group->private = hfsn;
18143 + hfsn->hfsn_group = group;
18144 + br->br_hfsn = hfsn;
18145 + goto out; /* success */
18148 + au_kfree_try_rcu(hfsn);
18153 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18158 + if (!br->br_hfsn)
18159 + err = au_hfsn_init_br(br, perm);
18164 +/* ---------------------------------------------------------------------- */
18166 +static void au_hfsn_fin(void)
18168 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18169 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18172 +const struct au_hnotify_op au_hnotify_op = {
18173 + .ctl = au_hfsn_ctl,
18174 + .alloc = au_hfsn_alloc,
18175 + .free = au_hfsn_free,
18177 + .fin = au_hfsn_fin,
18179 + .reset_br = au_hfsn_reset_br,
18180 + .fin_br = au_hfsn_fin_br,
18181 + .init_br = au_hfsn_init_br
18183 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18184 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18185 +++ linux/fs/aufs/hfsplus.c 2022-03-21 14:49:05.723299677 +0100
18187 +// SPDX-License-Identifier: GPL-2.0
18189 + * Copyright (C) 2010-2021 Junjiro R. Okajima
18191 + * This program, aufs is free software; you can redistribute it and/or modify
18192 + * it under the terms of the GNU General Public License as published by
18193 + * the Free Software Foundation; either version 2 of the License, or
18194 + * (at your option) any later version.
18196 + * This program is distributed in the hope that it will be useful,
18197 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18198 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18199 + * GNU General Public License for more details.
18201 + * You should have received a copy of the GNU General Public License
18202 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18206 + * special support for filesystems which acquires an inode mutex
18207 + * at final closing a file, eg, hfsplus.
18209 + * This trick is very simple and stupid, just to open the file before really
18210 + * necessary open to tell hfsplus that this is not the final closing.
18211 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18212 + * and au_h_open_post() after releasing it.
18217 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18220 + struct file *h_file;
18221 + struct dentry *h_dentry;
18223 + h_dentry = au_h_dptr(dentry, bindex);
18224 + AuDebugOn(!h_dentry);
18225 + AuDebugOn(d_is_negative(h_dentry));
18228 + if (au_test_hfsplus(h_dentry->d_sb)
18229 + && d_is_reg(h_dentry))
18230 + h_file = au_h_open(dentry, bindex,
18231 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18232 + /*file*/NULL, force_wr);
18236 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18237 + struct file *h_file)
18239 + struct au_branch *br;
18243 + br = au_sbr(dentry->d_sb, bindex);
18244 + au_lcnt_dec(&br->br_nfiles);
18247 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18248 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18249 +++ linux/fs/aufs/hnotify.c 2022-03-21 14:49:05.723299677 +0100
18251 +// SPDX-License-Identifier: GPL-2.0
18253 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18255 + * This program, aufs is free software; you can redistribute it and/or modify
18256 + * it under the terms of the GNU General Public License as published by
18257 + * the Free Software Foundation; either version 2 of the License, or
18258 + * (at your option) any later version.
18260 + * This program is distributed in the hope that it will be useful,
18261 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18262 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18263 + * GNU General Public License for more details.
18265 + * You should have received a copy of the GNU General Public License
18266 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18270 + * abstraction to notify the direct changes on lower directories
18273 +/* #include <linux/iversion.h> */
18276 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18279 + struct au_hnotify *hn;
18282 + hn = au_cache_alloc_hnotify();
18284 + hn->hn_aufs_inode = inode;
18285 + hinode->hi_notify = hn;
18286 + err = au_hnotify_op.alloc(hinode);
18288 + if (unlikely(err)) {
18289 + hinode->hi_notify = NULL;
18290 + au_cache_free_hnotify(hn);
18292 + * The upper dir was removed by udba, but the same named
18293 + * dir left. In this case, aufs assigns a new inode
18294 + * number and set the monitor again.
18295 + * For the lower dir, the old monitor is still left.
18297 + if (err == -EEXIST)
18306 +void au_hn_free(struct au_hinode *hinode)
18308 + struct au_hnotify *hn;
18310 + hn = hinode->hi_notify;
18312 + hinode->hi_notify = NULL;
18313 + if (au_hnotify_op.free(hinode, hn))
18314 + au_cache_free_hnotify(hn);
18318 +/* ---------------------------------------------------------------------- */
18320 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18322 + if (hinode->hi_notify)
18323 + au_hnotify_op.ctl(hinode, do_set);
18326 +void au_hn_reset(struct inode *inode, unsigned int flags)
18328 + aufs_bindex_t bindex, bbot;
18329 + struct inode *hi;
18330 + struct dentry *iwhdentry;
18332 + bbot = au_ibbot(inode);
18333 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18334 + hi = au_h_iptr(inode, bindex);
18338 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18339 + iwhdentry = au_hi_wh(inode, bindex);
18343 + au_set_h_iptr(inode, bindex, NULL, 0);
18344 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18345 + flags & ~AuHi_XINO);
18348 + /* inode_unlock(hi); */
18352 +/* ---------------------------------------------------------------------- */
18354 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18357 + aufs_bindex_t bindex, bbot, bfound, btop;
18358 + struct inode *h_i;
18361 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18362 + pr_warn("branch root dir was changed\n");
18367 + bbot = au_ibbot(inode);
18368 + btop = au_ibtop(inode);
18369 +#if 0 /* reserved for future use */
18370 + if (bindex == bbot) {
18371 + /* keep this ino in rename case */
18375 + for (bindex = btop; bindex <= bbot; bindex++)
18376 + if (au_h_iptr(inode, bindex) == h_inode) {
18383 + for (bindex = btop; bindex <= bbot; bindex++) {
18384 + h_i = au_h_iptr(inode, bindex);
18388 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18389 + /* ignore this error */
18390 + /* bad action? */
18393 + /* children inode number will be broken */
18400 +static int hn_gen_tree(struct dentry *dentry)
18402 + int err, i, j, ndentry;
18403 + struct au_dcsub_pages dpages;
18404 + struct au_dpage *dpage;
18405 + struct dentry **dentries;
18407 + err = au_dpages_init(&dpages, GFP_NOFS);
18408 + if (unlikely(err))
18410 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18411 + if (unlikely(err))
18414 + for (i = 0; i < dpages.ndpage; i++) {
18415 + dpage = dpages.dpages + i;
18416 + dentries = dpage->dentries;
18417 + ndentry = dpage->ndentry;
18418 + for (j = 0; j < ndentry; j++) {
18419 + struct dentry *d;
18426 + if (d_really_is_positive(d))
18427 + /* todo: reset children xino?
18428 + cached children only? */
18429 + au_iigen_dec(d_inode(d));
18434 + au_dpages_free(&dpages);
18440 + * return 0 if processed.
18442 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18443 + const unsigned int isdir)
18446 + struct dentry *d;
18447 + struct qstr *dname;
18450 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18451 + pr_warn("branch root dir was changed\n");
18457 + AuDebugOn(!name);
18458 + au_iigen_dec(inode);
18459 + spin_lock(&inode->i_lock);
18460 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18461 + spin_lock(&d->d_lock);
18462 + dname = &d->d_name;
18463 + if (dname->len != nlen
18464 + && memcmp(dname->name, name, nlen)) {
18465 + spin_unlock(&d->d_lock);
18470 + spin_unlock(&d->d_lock);
18473 + spin_unlock(&inode->i_lock);
18475 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18476 + d = d_find_any_alias(inode);
18478 + au_iigen_dec(inode);
18482 + spin_lock(&d->d_lock);
18483 + dname = &d->d_name;
18484 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18485 + spin_unlock(&d->d_lock);
18486 + err = hn_gen_tree(d);
18487 + spin_lock(&d->d_lock);
18489 + spin_unlock(&d->d_lock);
18498 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18502 + if (IS_ROOT(dentry)) {
18503 + pr_warn("branch root dir was changed\n");
18509 + au_digen_dec(dentry);
18510 + if (d_really_is_positive(dentry))
18511 + au_iigen_dec(d_inode(dentry));
18513 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18514 + if (d_really_is_positive(dentry))
18515 + err = hn_gen_tree(dentry);
18522 +/* ---------------------------------------------------------------------- */
18524 +/* hnotify job flags */
18525 +#define AuHnJob_XINO0 1
18526 +#define AuHnJob_GEN (1 << 1)
18527 +#define AuHnJob_DIRENT (1 << 2)
18528 +#define AuHnJob_ISDIR (1 << 3)
18529 +#define AuHnJob_TRYXINO0 (1 << 4)
18530 +#define AuHnJob_MNTPNT (1 << 5)
18531 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18532 +#define au_fset_hnjob(flags, name) \
18533 + do { (flags) |= AuHnJob_##name; } while (0)
18534 +#define au_fclr_hnjob(flags, name) \
18535 + do { (flags) &= ~AuHnJob_##name; } while (0)
18543 +struct au_hnotify_args {
18544 + struct inode *h_dir, *dir, *h_child_inode;
18546 + unsigned int flags[AuHnLast];
18547 + unsigned int h_child_nlen;
18548 + char h_child_name[];
18551 +struct hn_job_args {
18552 + unsigned int flags;
18553 + struct inode *inode, *h_inode, *dir, *h_dir;
18554 + struct dentry *dentry;
18559 +static int hn_job(struct hn_job_args *a)
18561 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18565 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18566 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18568 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18571 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18572 + if (!a->h_inode->i_nlink
18573 + && !(a->h_inode->i_state & I_LINKABLE))
18574 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18575 + inode_unlock_shared(a->h_inode);
18578 + /* make the generation obsolete */
18579 + if (au_ftest_hnjob(a->flags, GEN)) {
18582 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18584 + if (e && a->dentry)
18585 + hn_gen_by_name(a->dentry, isdir);
18586 + /* ignore this error */
18589 + /* make dir entries obsolete */
18590 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18591 + struct au_vdir *vdir;
18593 + vdir = au_ivdir(a->inode);
18595 + vdir->vd_jiffy = 0;
18596 + /* IMustLock(a->inode); */
18597 + /* inode_inc_iversion(a->inode); */
18600 + /* can do nothing but warn */
18601 + if (au_ftest_hnjob(a->flags, MNTPNT)
18603 + && d_mountpoint(a->dentry))
18604 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18609 +/* ---------------------------------------------------------------------- */
18611 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18612 + struct inode *dir)
18614 + struct dentry *dentry, *d, *parent;
18615 + struct qstr *dname;
18617 + parent = d_find_any_alias(dir);
18622 + spin_lock(&parent->d_lock);
18623 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18624 + /* AuDbg("%pd\n", d); */
18625 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18626 + dname = &d->d_name;
18627 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18628 + goto cont_unlock;
18632 + goto cont_unlock;
18633 + if (au_dcount(d) > 0) {
18634 + dentry = dget_dlock(d);
18635 + spin_unlock(&d->d_lock);
18640 + spin_unlock(&d->d_lock);
18642 + spin_unlock(&parent->d_lock);
18646 + di_write_lock_child(dentry);
18651 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18652 + aufs_bindex_t bindex, ino_t h_ino)
18654 + struct inode *inode;
18659 + err = au_xino_read(sb, bindex, h_ino, &ino);
18661 + inode = ilookup(sb, ino);
18665 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18666 + pr_warn("wrong root branch\n");
18672 + ii_write_lock_child(inode);
18678 +static void au_hn_bh(void *_args)
18680 + struct au_hnotify_args *a = _args;
18681 + struct super_block *sb;
18682 + aufs_bindex_t bindex, bbot, bfound;
18683 + unsigned char xino, try_iput;
18685 + struct inode *inode;
18687 + struct hn_job_args args;
18688 + struct dentry *dentry;
18689 + struct au_sbinfo *sbinfo;
18691 + AuDebugOn(!_args);
18692 + AuDebugOn(!a->h_dir);
18693 + AuDebugOn(!a->dir);
18694 + AuDebugOn(!a->mask);
18695 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18696 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18697 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18702 + * do not lock a->dir->i_mutex here
18703 + * because of d_revalidate() may cause a deadlock.
18705 + sb = a->dir->i_sb;
18707 + sbinfo = au_sbi(sb);
18708 + AuDebugOn(!sbinfo);
18709 + si_write_lock(sb, AuLock_NOPLMW);
18711 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18712 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18713 + case FS_MOVED_FROM:
18714 + case FS_MOVED_TO:
18715 + AuWarn1("DIRREN with UDBA may not work correctly "
18716 + "for the direct rename(2)\n");
18719 + ii_read_lock_parent(a->dir);
18721 + bbot = au_ibbot(a->dir);
18722 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18723 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18727 + ii_read_unlock(a->dir);
18728 + if (unlikely(bfound < 0))
18731 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18733 + if (a->h_child_inode)
18734 + h_ino = a->h_child_inode->i_ino;
18736 + if (a->h_child_nlen
18737 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18738 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18739 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18742 + if (dentry && d_really_is_positive(dentry))
18743 + inode = d_inode(dentry);
18744 + if (xino && !inode && h_ino
18745 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18746 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18747 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18748 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18752 + args.flags = a->flags[AuHn_CHILD];
18753 + args.dentry = dentry;
18754 + args.inode = inode;
18755 + args.h_inode = a->h_child_inode;
18756 + args.dir = a->dir;
18757 + args.h_dir = a->h_dir;
18758 + args.h_name = a->h_child_name;
18759 + args.h_nlen = a->h_child_nlen;
18760 + err = hn_job(&args);
18762 + if (au_di(dentry))
18763 + di_write_unlock(dentry);
18766 + if (inode && try_iput) {
18767 + ii_write_unlock(inode);
18771 + ii_write_lock_parent(a->dir);
18772 + args.flags = a->flags[AuHn_PARENT];
18773 + args.dentry = NULL;
18774 + args.inode = a->dir;
18775 + args.h_inode = a->h_dir;
18777 + args.h_dir = NULL;
18778 + args.h_name = NULL;
18780 + err = hn_job(&args);
18781 + ii_write_unlock(a->dir);
18784 + iput(a->h_child_inode);
18787 + si_write_unlock(sb);
18788 + au_nwt_done(&sbinfo->si_nowait);
18792 +/* ---------------------------------------------------------------------- */
18794 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18795 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18798 + unsigned int flags[AuHnLast], f;
18799 + unsigned char isdir, isroot, wh;
18800 + struct inode *dir;
18801 + struct au_hnotify_args *args;
18802 + char *p, *h_child_name;
18805 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18806 + dir = igrab(hnotify->hn_aufs_inode);
18810 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18812 + h_child_name = (void *)h_child_qstr->name;
18813 + len = h_child_qstr->len;
18814 + if (h_child_name) {
18815 + if (len > AUFS_WH_PFX_LEN
18816 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18817 + h_child_name += AUFS_WH_PFX_LEN;
18818 + len -= AUFS_WH_PFX_LEN;
18824 + if (h_child_inode)
18825 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18826 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18827 + flags[AuHn_CHILD] = 0;
18829 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18830 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18831 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18832 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18833 + case FS_MOVED_FROM:
18834 + case FS_MOVED_TO:
18835 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18836 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18839 + AuDebugOn(!h_child_name);
18844 + * aufs never be able to get this child inode.
18845 + * revalidation should be in d_revalidate()
18846 + * by checking i_nlink, i_generation or d_unhashed().
18848 + AuDebugOn(!h_child_name);
18849 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18850 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18858 + h_child_inode = NULL;
18861 + /* iput() and kfree() will be called in au_hnotify() */
18862 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18863 + if (unlikely(!args)) {
18864 + AuErr1("no memory\n");
18868 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18869 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18870 + args->mask = mask;
18872 + args->h_dir = igrab(h_dir);
18873 + if (h_child_inode)
18874 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18875 + args->h_child_inode = h_child_inode;
18876 + args->h_child_nlen = len;
18878 + p = (void *)args;
18879 + p += sizeof(*args);
18880 + memcpy(p, h_child_name, len);
18884 + /* NFS fires the event for silly-renamed one from kworker */
18886 + if (!dir->i_nlink
18887 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18889 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18890 + if (unlikely(err)) {
18891 + pr_err("wkq %d\n", err);
18892 + iput(args->h_child_inode);
18893 + iput(args->h_dir);
18895 + au_kfree_rcu(args);
18902 +/* ---------------------------------------------------------------------- */
18904 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18908 + AuDebugOn(!(udba & AuOptMask_UDBA));
18911 + if (au_hnotify_op.reset_br)
18912 + err = au_hnotify_op.reset_br(udba, br, perm);
18917 +int au_hnotify_init_br(struct au_branch *br, int perm)
18922 + if (au_hnotify_op.init_br)
18923 + err = au_hnotify_op.init_br(br, perm);
18928 +void au_hnotify_fin_br(struct au_branch *br)
18930 + if (au_hnotify_op.fin_br)
18931 + au_hnotify_op.fin_br(br);
18934 +static void au_hn_destroy_cache(void)
18936 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18937 + au_cache[AuCache_HNOTIFY] = NULL;
18940 +int __init au_hnotify_init(void)
18945 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18946 + if (au_cache[AuCache_HNOTIFY]) {
18948 + if (au_hnotify_op.init)
18949 + err = au_hnotify_op.init();
18950 + if (unlikely(err))
18951 + au_hn_destroy_cache();
18957 +void au_hnotify_fin(void)
18959 + if (au_hnotify_op.fin)
18960 + au_hnotify_op.fin();
18962 + /* cf. au_cache_fin() */
18963 + if (au_cache[AuCache_HNOTIFY])
18964 + au_hn_destroy_cache();
18966 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18967 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18968 +++ linux/fs/aufs/iinfo.c 2022-03-21 14:49:05.726633010 +0100
18970 +// SPDX-License-Identifier: GPL-2.0
18972 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18974 + * This program, aufs is free software; you can redistribute it and/or modify
18975 + * it under the terms of the GNU General Public License as published by
18976 + * the Free Software Foundation; either version 2 of the License, or
18977 + * (at your option) any later version.
18979 + * This program is distributed in the hope that it will be useful,
18980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18982 + * GNU General Public License for more details.
18984 + * You should have received a copy of the GNU General Public License
18985 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18989 + * inode private data
18994 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
18996 + struct inode *h_inode;
18997 + struct au_hinode *hinode;
18999 + IiMustAnyLock(inode);
19001 + hinode = au_hinode(au_ii(inode), bindex);
19002 + h_inode = hinode->hi_inode;
19003 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19007 +/* todo: hard/soft set? */
19008 +void au_hiput(struct au_hinode *hinode)
19010 + au_hn_free(hinode);
19011 + dput(hinode->hi_whdentry);
19012 + iput(hinode->hi_inode);
19015 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19017 + unsigned int flags;
19018 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19021 + if (au_opt_test(mnt_flags, XINO))
19022 + au_fset_hi(flags, XINO);
19023 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19024 + au_fset_hi(flags, HNOTIFY);
19028 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19029 + struct inode *h_inode, unsigned int flags)
19031 + struct au_hinode *hinode;
19032 + struct inode *hi;
19033 + struct au_iinfo *iinfo = au_ii(inode);
19035 + IiMustWriteLock(inode);
19037 + hinode = au_hinode(iinfo, bindex);
19038 + hi = hinode->hi_inode;
19039 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19042 + au_hiput(hinode);
19043 + hinode->hi_inode = h_inode;
19046 + struct super_block *sb = inode->i_sb;
19047 + struct au_branch *br;
19049 + AuDebugOn(inode->i_mode
19050 + && (h_inode->i_mode & S_IFMT)
19051 + != (inode->i_mode & S_IFMT));
19052 + if (bindex == iinfo->ii_btop)
19053 + au_cpup_igen(inode, h_inode);
19054 + br = au_sbr(sb, bindex);
19055 + hinode->hi_id = br->br_id;
19056 + if (au_ftest_hi(flags, XINO)) {
19057 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19059 + if (unlikely(err))
19060 + AuIOErr1("failed au_xino_write() %d\n", err);
19063 + if (au_ftest_hi(flags, HNOTIFY)
19064 + && au_br_hnotifyable(br->br_perm)) {
19065 + err = au_hn_alloc(hinode, inode);
19066 + if (unlikely(err))
19067 + AuIOErr1("au_hn_alloc() %d\n", err);
19072 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19073 + struct dentry *h_wh)
19075 + struct au_hinode *hinode;
19077 + IiMustWriteLock(inode);
19079 + hinode = au_hinode(au_ii(inode), bindex);
19080 + AuDebugOn(hinode->hi_whdentry);
19081 + hinode->hi_whdentry = h_wh;
19084 +void au_update_iigen(struct inode *inode, int half)
19086 + struct au_iinfo *iinfo;
19087 + struct au_iigen *iigen;
19088 + unsigned int sigen;
19090 + sigen = au_sigen(inode->i_sb);
19091 + iinfo = au_ii(inode);
19092 + iigen = &iinfo->ii_generation;
19093 + spin_lock(&iigen->ig_spin);
19094 + iigen->ig_generation = sigen;
19096 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19098 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19099 + spin_unlock(&iigen->ig_spin);
19102 +/* it may be called at remount time, too */
19103 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19105 + struct au_iinfo *iinfo;
19106 + aufs_bindex_t bindex, bbot;
19108 + AuDebugOn(au_is_bad_inode(inode));
19109 + IiMustWriteLock(inode);
19111 + iinfo = au_ii(inode);
19112 + if (do_put_zero && iinfo->ii_btop >= 0) {
19113 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19115 + struct inode *h_i;
19117 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19120 + && !(h_i->i_state & I_LINKABLE))
19121 + au_set_h_iptr(inode, bindex, NULL, 0);
19125 + iinfo->ii_btop = -1;
19126 + iinfo->ii_bbot = -1;
19127 + bbot = au_sbbot(inode->i_sb);
19128 + for (bindex = 0; bindex <= bbot; bindex++)
19129 + if (au_hinode(iinfo, bindex)->hi_inode) {
19130 + iinfo->ii_btop = bindex;
19133 + if (iinfo->ii_btop >= 0)
19134 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19135 + if (au_hinode(iinfo, bindex)->hi_inode) {
19136 + iinfo->ii_bbot = bindex;
19139 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19142 +/* ---------------------------------------------------------------------- */
19144 +void au_icntnr_init_once(void *_c)
19146 + struct au_icntnr *c = _c;
19147 + struct au_iinfo *iinfo = &c->iinfo;
19149 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19150 + au_rw_init(&iinfo->ii_rwsem);
19151 + inode_init_once(&c->vfs_inode);
19154 +void au_hinode_init(struct au_hinode *hinode)
19156 + hinode->hi_inode = NULL;
19157 + hinode->hi_id = -1;
19158 + au_hn_init(hinode);
19159 + hinode->hi_whdentry = NULL;
19162 +int au_iinfo_init(struct inode *inode)
19164 + struct au_iinfo *iinfo;
19165 + struct super_block *sb;
19166 + struct au_hinode *hi;
19169 + sb = inode->i_sb;
19170 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19171 + nbr = au_sbbot(sb) + 1;
19172 + if (unlikely(nbr <= 0))
19174 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19176 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19178 + iinfo->ii_hinode = hi;
19179 + for (i = 0; i < nbr; i++, hi++)
19180 + au_hinode_init(hi);
19182 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19183 + iinfo->ii_btop = -1;
19184 + iinfo->ii_bbot = -1;
19185 + iinfo->ii_vdir = NULL;
19191 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19194 + struct au_hinode *hip;
19196 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19199 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19202 + iinfo->ii_hinode = hip;
19203 + i = iinfo->ii_bbot + 1;
19205 + for (; i < nbr; i++, hip++)
19206 + au_hinode_init(hip);
19213 +void au_iinfo_fin(struct inode *inode)
19215 + struct au_iinfo *iinfo;
19216 + struct au_hinode *hi;
19217 + struct super_block *sb;
19218 + aufs_bindex_t bindex, bbot;
19219 + const unsigned char unlinked = !inode->i_nlink;
19221 + AuDebugOn(au_is_bad_inode(inode));
19223 + sb = inode->i_sb;
19224 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19225 + if (si_pid_test(sb))
19226 + au_xino_delete_inode(inode, unlinked);
19229 + * it is safe to hide the dependency between sbinfo and
19233 + si_noflush_read_lock(sb);
19234 + au_xino_delete_inode(inode, unlinked);
19235 + si_read_unlock(sb);
19239 + iinfo = au_ii(inode);
19240 + if (iinfo->ii_vdir)
19241 + au_vdir_free(iinfo->ii_vdir);
19243 + bindex = iinfo->ii_btop;
19244 + if (bindex >= 0) {
19245 + hi = au_hinode(iinfo, bindex);
19246 + bbot = iinfo->ii_bbot;
19247 + while (bindex++ <= bbot) {
19248 + if (hi->hi_inode)
19253 + au_kfree_rcu(iinfo->ii_hinode);
19254 + AuRwDestroy(&iinfo->ii_rwsem);
19256 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19257 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19258 +++ linux/fs/aufs/inode.c 2022-03-21 14:49:05.726633010 +0100
19260 +// SPDX-License-Identifier: GPL-2.0
19262 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19264 + * This program, aufs is free software; you can redistribute it and/or modify
19265 + * it under the terms of the GNU General Public License as published by
19266 + * the Free Software Foundation; either version 2 of the License, or
19267 + * (at your option) any later version.
19269 + * This program is distributed in the hope that it will be useful,
19270 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19271 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19272 + * GNU General Public License for more details.
19274 + * You should have received a copy of the GNU General Public License
19275 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19279 + * inode functions
19282 +#include <linux/iversion.h>
19285 +struct inode *au_igrab(struct inode *inode)
19288 + AuDebugOn(!atomic_read(&inode->i_count));
19294 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19296 + au_cpup_attr_all(inode, /*force*/0);
19297 + au_update_iigen(inode, /*half*/1);
19299 + inode_inc_iversion(inode);
19302 +static int au_ii_refresh(struct inode *inode, int *update)
19306 + aufs_bindex_t bindex, new_bindex;
19307 + struct super_block *sb;
19308 + struct au_iinfo *iinfo;
19309 + struct au_hinode *p, *q, tmp;
19311 + AuDebugOn(au_is_bad_inode(inode));
19312 + IiMustWriteLock(inode);
19315 + sb = inode->i_sb;
19316 + nbr = au_sbbot(sb) + 1;
19317 + type = inode->i_mode & S_IFMT;
19318 + iinfo = au_ii(inode);
19319 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19320 + if (unlikely(err))
19323 + AuDebugOn(iinfo->ii_btop < 0);
19324 + p = au_hinode(iinfo, iinfo->ii_btop);
19325 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19327 + if (!p->hi_inode)
19330 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19331 + new_bindex = au_br_index(sb, p->hi_id);
19332 + if (new_bindex == bindex)
19335 + if (new_bindex < 0) {
19338 + p->hi_inode = NULL;
19342 + if (new_bindex < iinfo->ii_btop)
19343 + iinfo->ii_btop = new_bindex;
19344 + if (iinfo->ii_bbot < new_bindex)
19345 + iinfo->ii_bbot = new_bindex;
19346 + /* swap two lower inode, and loop again */
19347 + q = au_hinode(iinfo, new_bindex);
19351 + if (tmp.hi_inode) {
19356 + au_update_ibrange(inode, /*do_put_zero*/0);
19357 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19358 + e = au_dy_irefresh(inode);
19359 + if (unlikely(e && !err))
19367 +void au_refresh_iop(struct inode *inode, int force_getattr)
19370 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19371 + const struct inode_operations *iop
19372 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19374 + if (inode->i_op == iop)
19377 + switch (inode->i_mode & S_IFMT) {
19379 + type = AuIop_DIR;
19382 + type = AuIop_SYMLINK;
19385 + type = AuIop_OTHER;
19389 + inode->i_op = iop + type;
19390 + /* unnecessary smp_wmb() */
19393 +int au_refresh_hinode_self(struct inode *inode)
19397 + err = au_ii_refresh(inode, &update);
19399 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19405 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19407 + int err, e, update;
19408 + unsigned int flags;
19410 + aufs_bindex_t bindex, bbot;
19411 + unsigned char isdir;
19412 + struct au_hinode *p;
19413 + struct au_iinfo *iinfo;
19415 + err = au_ii_refresh(inode, &update);
19416 + if (unlikely(err))
19420 + iinfo = au_ii(inode);
19421 + p = au_hinode(iinfo, iinfo->ii_btop);
19422 + mode = (inode->i_mode & S_IFMT);
19423 + isdir = S_ISDIR(mode);
19424 + flags = au_hi_flags(inode, isdir);
19425 + bbot = au_dbbot(dentry);
19426 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19427 + struct inode *h_i, *h_inode;
19428 + struct dentry *h_d;
19430 + h_d = au_h_dptr(dentry, bindex);
19431 + if (!h_d || d_is_negative(h_d))
19434 + h_inode = d_inode(h_d);
19435 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19436 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19437 + h_i = au_h_iptr(inode, bindex);
19439 + if (h_i == h_inode)
19445 + if (bindex < iinfo->ii_btop)
19446 + iinfo->ii_btop = bindex;
19447 + if (iinfo->ii_bbot < bindex)
19448 + iinfo->ii_bbot = bindex;
19449 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19452 + au_update_ibrange(inode, /*do_put_zero*/0);
19453 + e = au_dy_irefresh(inode);
19454 + if (unlikely(e && !err))
19457 + au_refresh_hinode_attr(inode, update && isdir);
19464 +static int set_inode(struct inode *inode, struct dentry *dentry)
19467 + unsigned int flags;
19469 + aufs_bindex_t bindex, btop, btail;
19470 + unsigned char isdir;
19471 + struct dentry *h_dentry;
19472 + struct inode *h_inode;
19473 + struct au_iinfo *iinfo;
19474 + const struct inode_operations *iop;
19476 + IiMustWriteLock(inode);
19480 + iop = au_sbi(inode->i_sb)->si_iop_array;
19481 + btop = au_dbtop(dentry);
19482 + h_dentry = au_h_dptr(dentry, btop);
19483 + h_inode = d_inode(h_dentry);
19484 + mode = h_inode->i_mode;
19485 + switch (mode & S_IFMT) {
19487 + btail = au_dbtail(dentry);
19488 + inode->i_op = iop + AuIop_OTHER;
19489 + inode->i_fop = &aufs_file_fop;
19490 + err = au_dy_iaop(inode, btop, h_inode);
19491 + if (unlikely(err))
19496 + btail = au_dbtaildir(dentry);
19497 + inode->i_op = iop + AuIop_DIR;
19498 + inode->i_fop = &aufs_dir_fop;
19501 + btail = au_dbtail(dentry);
19502 + inode->i_op = iop + AuIop_SYMLINK;
19508 + btail = au_dbtail(dentry);
19509 + inode->i_op = iop + AuIop_OTHER;
19510 + init_special_inode(inode, mode, h_inode->i_rdev);
19513 + AuIOErr("Unknown file type 0%o\n", mode);
19518 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19519 + flags = au_hi_flags(inode, isdir);
19520 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19521 + && au_ftest_hi(flags, HNOTIFY)
19522 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19523 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19524 + au_fclr_hi(flags, HNOTIFY);
19525 + iinfo = au_ii(inode);
19526 + iinfo->ii_btop = btop;
19527 + iinfo->ii_bbot = btail;
19528 + for (bindex = btop; bindex <= btail; bindex++) {
19529 + h_dentry = au_h_dptr(dentry, bindex);
19531 + au_set_h_iptr(inode, bindex,
19532 + au_igrab(d_inode(h_dentry)), flags);
19534 + au_cpup_attr_all(inode, /*force*/1);
19536 + * to force calling aufs_get_acl() every time,
19537 + * do not call cache_no_acl() for aufs inode.
19545 + * successful returns with iinfo write_locked
19547 + * zero: success, matched
19548 + * plus: no error, but unmatched
19550 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19553 + unsigned int gen, igflags;
19554 + aufs_bindex_t bindex, bbot;
19555 + struct inode *h_inode, *h_dinode;
19556 + struct dentry *h_dentry;
19559 + * before this function, if aufs got any iinfo lock, it must be only
19560 + * one, the parent dir.
19561 + * it can happen by UDBA and the obsoleted inode number.
19564 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19568 + ii_write_lock_new_child(inode);
19569 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19570 + h_dinode = d_inode(h_dentry);
19571 + bbot = au_ibbot(inode);
19572 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19573 + h_inode = au_h_iptr(inode, bindex);
19574 + if (!h_inode || h_inode != h_dinode)
19578 + gen = au_iigen(inode, &igflags);
19579 + if (gen == au_digen(dentry)
19580 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19583 + /* fully refresh inode using dentry */
19584 + err = au_refresh_hinode(inode, dentry);
19586 + au_update_iigen(inode, /*half*/0);
19590 + if (unlikely(err))
19591 + ii_write_unlock(inode);
19596 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19597 + unsigned int d_type, ino_t *ino)
19600 + const int isnondir = d_type != DT_DIR;
19602 + /* prevent hardlinked inode number from race condition */
19604 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19605 + if (unlikely(err))
19609 + err = au_xino_read(sb, bindex, h_ino, ino);
19610 + if (unlikely(err))
19611 + goto out_xinondir;
19615 + *ino = au_xino_new_ino(sb);
19616 + if (unlikely(!*ino))
19617 + goto out_xinondir;
19618 + err = au_xino_write(sb, bindex, h_ino, *ino);
19619 + if (unlikely(err))
19620 + goto out_xinondir;
19624 + if (isnondir && idx >= 0)
19625 + au_xinondir_leave(sb, bindex, h_ino, idx);
19630 +/* successful returns with iinfo write_locked */
19631 +/* todo: return with unlocked? */
19632 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19634 + struct inode *inode, *h_inode;
19635 + struct dentry *h_dentry;
19636 + struct super_block *sb;
19637 + ino_t h_ino, ino;
19638 + int err, idx, hlinked;
19639 + aufs_bindex_t btop;
19641 + sb = dentry->d_sb;
19642 + btop = au_dbtop(dentry);
19643 + h_dentry = au_h_dptr(dentry, btop);
19644 + h_inode = d_inode(h_dentry);
19645 + h_ino = h_inode->i_ino;
19646 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19650 + * stop 'race'-ing between hardlinks under different
19654 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19655 + inode = ERR_PTR(err);
19656 + if (unlikely(err))
19660 + err = au_xino_read(sb, btop, h_ino, &ino);
19661 + inode = ERR_PTR(err);
19662 + if (unlikely(err))
19663 + goto out_xinondir;
19666 + ino = au_xino_new_ino(sb);
19667 + if (unlikely(!ino)) {
19668 + inode = ERR_PTR(-EIO);
19669 + goto out_xinondir;
19673 + AuDbg("i%lu\n", (unsigned long)ino);
19674 + inode = au_iget_locked(sb, ino);
19675 + err = PTR_ERR(inode);
19676 + if (IS_ERR(inode))
19677 + goto out_xinondir;
19679 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19680 + if (inode->i_state & I_NEW) {
19681 + ii_write_lock_new_child(inode);
19682 + err = set_inode(inode, dentry);
19684 + unlock_new_inode(inode);
19685 + goto out_xinondir; /* success */
19689 + * iget_failed() calls iput(), but we need to call
19690 + * ii_write_unlock() after iget_failed(). so dirty hack for
19693 + atomic_inc(&inode->i_count);
19694 + iget_failed(inode);
19695 + ii_write_unlock(inode);
19696 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19697 + /* ignore this error */
19699 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19701 + * horrible race condition between lookup, readdir and copyup
19702 + * (or something).
19704 + if (hlinked && idx >= 0)
19705 + au_xinondir_leave(sb, btop, h_ino, idx);
19706 + err = reval_inode(inode, dentry);
19707 + if (unlikely(err < 0)) {
19712 + goto out; /* success */
19713 + else if (hlinked && idx >= 0) {
19714 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19715 + if (unlikely(err)) {
19717 + inode = ERR_PTR(err);
19723 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19724 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19725 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19726 + btop, au_sbtype(h_dentry->d_sb), dentry,
19727 + (unsigned long)h_ino, (unsigned long)ino);
19729 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19732 + if (hlinked && idx >= 0)
19733 + au_xinondir_leave(sb, btop, h_ino, idx);
19739 + inode = ERR_PTR(err);
19741 + if (hlinked && idx >= 0)
19742 + au_xinondir_leave(sb, btop, h_ino, idx);
19747 +/* ---------------------------------------------------------------------- */
19749 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19750 + struct inode *inode)
19753 + struct inode *hi;
19755 + err = au_br_rdonly(au_sbr(sb, bindex));
19757 + /* pseudo-link after flushed may happen out of bounds */
19760 + && au_ibtop(inode) <= bindex
19761 + && bindex <= au_ibbot(inode)) {
19763 + * permission check is unnecessary since vfsub routine
19764 + * will be called later
19766 + hi = au_h_iptr(inode, bindex);
19768 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19774 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19777 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19779 + return inode_permission(h_userns, h_inode, mask);
19782 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19785 + if (au_test_nfs(h_inode->i_sb)
19786 + && (mask & MAY_WRITE)
19787 + && S_ISDIR(h_inode->i_mode))
19788 + mask |= MAY_READ; /* force permission check */
19789 + return au_test_h_perm(h_userns, h_inode, mask);
19791 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19792 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19793 +++ linux/fs/aufs/inode.h 2022-03-21 14:49:05.726633010 +0100
19795 +/* SPDX-License-Identifier: GPL-2.0 */
19797 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19799 + * This program, aufs is free software; you can redistribute it and/or modify
19800 + * it under the terms of the GNU General Public License as published by
19801 + * the Free Software Foundation; either version 2 of the License, or
19802 + * (at your option) any later version.
19804 + * This program is distributed in the hope that it will be useful,
19805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19807 + * GNU General Public License for more details.
19809 + * You should have received a copy of the GNU General Public License
19810 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19814 + * inode operations
19817 +#ifndef __AUFS_INODE_H__
19818 +#define __AUFS_INODE_H__
19822 +#include <linux/fsnotify.h>
19823 +#include "rwsem.h"
19827 +struct au_hnotify {
19828 +#ifdef CONFIG_AUFS_HNOTIFY
19829 +#ifdef CONFIG_AUFS_HFSNOTIFY
19830 + /* never use fsnotify_add_vfsmount_mark() */
19831 + struct fsnotify_mark hn_mark;
19833 + struct inode *hn_aufs_inode; /* no get/put */
19834 + struct rcu_head rcu;
19836 +} ____cacheline_aligned_in_smp;
19838 +struct au_hinode {
19839 + struct inode *hi_inode;
19840 + aufs_bindex_t hi_id;
19841 +#ifdef CONFIG_AUFS_HNOTIFY
19842 + struct au_hnotify *hi_notify;
19845 + /* reference to the copied-up whiteout with get/put */
19846 + struct dentry *hi_whdentry;
19850 +#define AuIG_HALF_REFRESHED 1
19851 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19852 +#define au_ig_fset(flags, name) \
19853 + do { (flags) |= AuIG_##name; } while (0)
19854 +#define au_ig_fclr(flags, name) \
19855 + do { (flags) &= ~AuIG_##name; } while (0)
19858 + spinlock_t ig_spin;
19859 + __u32 ig_generation, ig_flags;
19864 + struct au_iigen ii_generation;
19865 + struct super_block *ii_hsb1; /* no get/put */
19867 + struct au_rwsem ii_rwsem;
19868 + aufs_bindex_t ii_btop, ii_bbot;
19870 + struct au_hinode *ii_hinode;
19871 + struct au_vdir *ii_vdir;
19874 +struct au_icntnr {
19875 + struct au_iinfo iinfo;
19876 + struct inode vfs_inode;
19877 + struct hlist_bl_node plink;
19878 + struct rcu_head rcu;
19879 +} ____cacheline_aligned_in_smp;
19881 +/* au_pin flags */
19882 +#define AuPin_DI_LOCKED 1
19883 +#define AuPin_MNT_WRITE (1 << 1)
19884 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19885 +#define au_fset_pin(flags, name) \
19886 + do { (flags) |= AuPin_##name; } while (0)
19887 +#define au_fclr_pin(flags, name) \
19888 + do { (flags) &= ~AuPin_##name; } while (0)
19892 + struct dentry *dentry;
19893 + unsigned int udba;
19894 + unsigned char lsc_di, lsc_hi, flags;
19895 + aufs_bindex_t bindex;
19898 + struct dentry *parent;
19899 + struct au_hinode *hdir;
19900 + struct vfsmount *h_mnt;
19902 + /* temporary unlock/relock for copyup */
19903 + struct dentry *h_dentry, *h_parent;
19904 + struct au_branch *br;
19905 + struct task_struct *task;
19908 +void au_pin_hdir_unlock(struct au_pin *p);
19909 +int au_pin_hdir_lock(struct au_pin *p);
19910 +int au_pin_hdir_relock(struct au_pin *p);
19911 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19912 +void au_pin_hdir_release(struct au_pin *p);
19914 +/* ---------------------------------------------------------------------- */
19916 +static inline struct au_iinfo *au_ii(struct inode *inode)
19918 + BUG_ON(is_bad_inode(inode));
19919 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19922 +/* ---------------------------------------------------------------------- */
19925 +struct inode *au_igrab(struct inode *inode);
19926 +void au_refresh_iop(struct inode *inode, int force_getattr);
19927 +int au_refresh_hinode_self(struct inode *inode);
19928 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19929 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19930 + unsigned int d_type, ino_t *ino);
19931 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19932 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19933 + struct inode *inode);
19934 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19936 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19939 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19940 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19942 +#ifdef CONFIG_AUFS_SHWH
19943 + return au_ino(sb, bindex, h_ino, d_type, ino);
19956 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19957 + aufs_iop_nogetattr[AuIop_Last];
19959 +/* au_wr_dir flags */
19960 +#define AuWrDir_ADD_ENTRY 1
19961 +#define AuWrDir_ISDIR (1 << 1)
19962 +#define AuWrDir_TMPFILE (1 << 2)
19963 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19964 +#define au_fset_wrdir(flags, name) \
19965 + do { (flags) |= AuWrDir_##name; } while (0)
19966 +#define au_fclr_wrdir(flags, name) \
19967 + do { (flags) &= ~AuWrDir_##name; } while (0)
19969 +struct au_wr_dir_args {
19970 + aufs_bindex_t force_btgt;
19971 + unsigned char flags;
19973 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19974 + struct au_wr_dir_args *args);
19976 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
19977 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
19978 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19979 + unsigned int udba, unsigned char flags);
19980 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19981 + unsigned int udba, unsigned char flags) __must_check;
19982 +int au_do_pin(struct au_pin *pin) __must_check;
19983 +void au_unpin(struct au_pin *pin);
19984 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
19986 +#define AuIcpup_DID_CPUP 1
19987 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
19988 +#define au_fset_icpup(flags, name) \
19989 + do { (flags) |= AuIcpup_##name; } while (0)
19990 +#define au_fclr_icpup(flags, name) \
19991 + do { (flags) &= ~AuIcpup_##name; } while (0)
19993 +struct au_icpup_args {
19994 + unsigned char flags;
19995 + unsigned char pin_flags;
19996 + aufs_bindex_t btgt;
19997 + unsigned int udba;
19998 + struct au_pin pin;
19999 + struct path h_path;
20000 + struct inode *h_inode;
20003 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20004 + struct au_icpup_args *a);
20006 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20007 + struct path *h_path, int locked);
20010 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20011 + struct dentry *h_parent, int isdir);
20012 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
20013 + struct dentry *dentry, umode_t mode, dev_t dev);
20014 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
20015 + struct dentry *dentry, const char *symname);
20016 +int aufs_create(struct user_namespace *userns, struct inode *dir,
20017 + struct dentry *dentry, umode_t mode, bool want_excl);
20018 +struct vfsub_aopen_args;
20019 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20020 + struct vfsub_aopen_args *args);
20021 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
20022 + struct dentry *dentry, umode_t mode);
20023 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20024 + struct dentry *dentry);
20025 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20026 + struct dentry *dentry, umode_t mode);
20029 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20030 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20031 + struct dentry *h_parent, int isdir);
20032 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20033 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20036 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20037 +int aufs_rename(struct user_namespace *userns,
20038 + struct inode *_src_dir, struct dentry *_src_dentry,
20039 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20040 + unsigned int _flags);
20043 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20044 +void au_hiput(struct au_hinode *hinode);
20045 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20046 + struct dentry *h_wh);
20047 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20049 +/* hinode flags */
20050 +#define AuHi_XINO 1
20051 +#define AuHi_HNOTIFY (1 << 1)
20052 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20053 +#define au_fset_hi(flags, name) \
20054 + do { (flags) |= AuHi_##name; } while (0)
20055 +#define au_fclr_hi(flags, name) \
20056 + do { (flags) &= ~AuHi_##name; } while (0)
20058 +#ifndef CONFIG_AUFS_HNOTIFY
20059 +#undef AuHi_HNOTIFY
20060 +#define AuHi_HNOTIFY 0
20063 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20064 + struct inode *h_inode, unsigned int flags);
20066 +void au_update_iigen(struct inode *inode, int half);
20067 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20069 +void au_icntnr_init_once(void *_c);
20070 +void au_hinode_init(struct au_hinode *hinode);
20071 +int au_iinfo_init(struct inode *inode);
20072 +void au_iinfo_fin(struct inode *inode);
20073 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20075 +#ifdef CONFIG_PROC_FS
20077 +int au_plink_maint(struct super_block *sb, int flags);
20079 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20080 +int au_plink_maint_enter(struct super_block *sb);
20081 +#ifdef CONFIG_AUFS_DEBUG
20082 +void au_plink_list(struct super_block *sb);
20084 +AuStubVoid(au_plink_list, struct super_block *sb)
20086 +int au_plink_test(struct inode *inode);
20087 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20088 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20089 + struct dentry *h_dentry);
20090 +void au_plink_put(struct super_block *sb, int verbose);
20091 +void au_plink_clean(struct super_block *sb, int verbose);
20092 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20094 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20095 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20096 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20097 +AuStubVoid(au_plink_list, struct super_block *sb);
20098 +AuStubInt0(au_plink_test, struct inode *inode);
20099 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20100 + struct inode *inode, aufs_bindex_t bindex);
20101 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20102 + struct dentry *h_dentry);
20103 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20104 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20105 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20106 +#endif /* CONFIG_PROC_FS */
20108 +#ifdef CONFIG_AUFS_XATTR
20110 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20111 + unsigned int verbose);
20112 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20113 +void au_xattr_init(struct super_block *sb);
20115 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20116 + int ignore_flags, unsigned int verbose);
20117 +AuStubVoid(au_xattr_init, struct super_block *sb);
20120 +#ifdef CONFIG_FS_POSIX_ACL
20121 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
20122 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
20123 + struct posix_acl *acl, int type);
20126 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20132 +struct au_sxattr {
20136 + const char *name;
20137 + const void *value;
20142 + struct posix_acl *acl;
20147 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20148 + struct au_sxattr *arg);
20151 +/* ---------------------------------------------------------------------- */
20153 +/* lock subclass for iinfo */
20155 + AuLsc_II_CHILD, /* child first */
20156 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20157 + AuLsc_II_CHILD3, /* copyup dirs */
20158 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20159 + AuLsc_II_PARENT2,
20160 + AuLsc_II_PARENT3, /* copyup dirs */
20161 + AuLsc_II_NEW_CHILD
20165 + * ii_read_lock_child, ii_write_lock_child,
20166 + * ii_read_lock_child2, ii_write_lock_child2,
20167 + * ii_read_lock_child3, ii_write_lock_child3,
20168 + * ii_read_lock_parent, ii_write_lock_parent,
20169 + * ii_read_lock_parent2, ii_write_lock_parent2,
20170 + * ii_read_lock_parent3, ii_write_lock_parent3,
20171 + * ii_read_lock_new_child, ii_write_lock_new_child,
20173 +#define AuReadLockFunc(name, lsc) \
20174 +static inline void ii_read_lock_##name(struct inode *i) \
20176 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20179 +#define AuWriteLockFunc(name, lsc) \
20180 +static inline void ii_write_lock_##name(struct inode *i) \
20182 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20185 +#define AuRWLockFuncs(name, lsc) \
20186 + AuReadLockFunc(name, lsc) \
20187 + AuWriteLockFunc(name, lsc)
20189 +AuRWLockFuncs(child, CHILD);
20190 +AuRWLockFuncs(child2, CHILD2);
20191 +AuRWLockFuncs(child3, CHILD3);
20192 +AuRWLockFuncs(parent, PARENT);
20193 +AuRWLockFuncs(parent2, PARENT2);
20194 +AuRWLockFuncs(parent3, PARENT3);
20195 +AuRWLockFuncs(new_child, NEW_CHILD);
20197 +#undef AuReadLockFunc
20198 +#undef AuWriteLockFunc
20199 +#undef AuRWLockFuncs
20201 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20202 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20203 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20205 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20206 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20207 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20209 +/* ---------------------------------------------------------------------- */
20211 +static inline void au_icntnr_init(struct au_icntnr *c)
20213 +#ifdef CONFIG_AUFS_DEBUG
20214 + c->vfs_inode.i_mode = 0;
20218 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20220 + unsigned int gen;
20221 + struct au_iinfo *iinfo;
20222 + struct au_iigen *iigen;
20224 + iinfo = au_ii(inode);
20225 + iigen = &iinfo->ii_generation;
20226 + spin_lock(&iigen->ig_spin);
20228 + *igflags = iigen->ig_flags;
20229 + gen = iigen->ig_generation;
20230 + spin_unlock(&iigen->ig_spin);
20235 +/* tiny test for inode number */
20236 +/* tmpfs generation is too rough */
20237 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20239 + struct au_iinfo *iinfo;
20241 + iinfo = au_ii(inode);
20242 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20243 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20244 + && iinfo->ii_higen == h_inode->i_generation);
20247 +static inline void au_iigen_dec(struct inode *inode)
20249 + struct au_iinfo *iinfo;
20250 + struct au_iigen *iigen;
20252 + iinfo = au_ii(inode);
20253 + iigen = &iinfo->ii_generation;
20254 + spin_lock(&iigen->ig_spin);
20255 + iigen->ig_generation--;
20256 + spin_unlock(&iigen->ig_spin);
20259 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20264 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20270 +/* ---------------------------------------------------------------------- */
20272 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20273 + aufs_bindex_t bindex)
20275 + return iinfo->ii_hinode + bindex;
20278 +static inline int au_is_bad_inode(struct inode *inode)
20280 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20283 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20284 + aufs_bindex_t bindex)
20286 + IiMustAnyLock(inode);
20287 + return au_hinode(au_ii(inode), bindex)->hi_id;
20290 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20292 + IiMustAnyLock(inode);
20293 + return au_ii(inode)->ii_btop;
20296 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20298 + IiMustAnyLock(inode);
20299 + return au_ii(inode)->ii_bbot;
20302 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20304 + IiMustAnyLock(inode);
20305 + return au_ii(inode)->ii_vdir;
20308 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20310 + IiMustAnyLock(inode);
20311 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20314 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20316 + IiMustWriteLock(inode);
20317 + au_ii(inode)->ii_btop = bindex;
20320 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20322 + IiMustWriteLock(inode);
20323 + au_ii(inode)->ii_bbot = bindex;
20326 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20328 + IiMustWriteLock(inode);
20329 + au_ii(inode)->ii_vdir = vdir;
20332 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20334 + IiMustAnyLock(inode);
20335 + return au_hinode(au_ii(inode), bindex);
20338 +/* ---------------------------------------------------------------------- */
20340 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20343 + return pin->parent;
20347 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20349 + if (pin && pin->hdir)
20350 + return pin->hdir->hi_inode;
20354 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20357 + return pin->hdir;
20361 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20364 + pin->dentry = dentry;
20367 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20368 + unsigned char lflag)
20372 + au_fset_pin(pin->flags, DI_LOCKED);
20374 + au_fclr_pin(pin->flags, DI_LOCKED);
20378 +#if 0 /* reserved */
20379 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20382 + dput(pin->parent);
20383 + pin->parent = dget(parent);
20388 +/* ---------------------------------------------------------------------- */
20391 +#ifdef CONFIG_AUFS_HNOTIFY
20392 +struct au_hnotify_op {
20393 + void (*ctl)(struct au_hinode *hinode, int do_set);
20394 + int (*alloc)(struct au_hinode *hinode);
20397 + * if it returns true, the caller should free hinode->hi_notify,
20398 + * otherwise ->free() frees it.
20400 + int (*free)(struct au_hinode *hinode,
20401 + struct au_hnotify *hn) __must_check;
20403 + void (*fin)(void);
20404 + int (*init)(void);
20406 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20407 + void (*fin_br)(struct au_branch *br);
20408 + int (*init_br)(struct au_branch *br, int perm);
20412 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20413 +void au_hn_free(struct au_hinode *hinode);
20414 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20415 +void au_hn_reset(struct inode *inode, unsigned int flags);
20416 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20417 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20418 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20419 +int au_hnotify_init_br(struct au_branch *br, int perm);
20420 +void au_hnotify_fin_br(struct au_branch *br);
20421 +int __init au_hnotify_init(void);
20422 +void au_hnotify_fin(void);
20425 +extern const struct au_hnotify_op au_hnotify_op;
20428 +void au_hn_init(struct au_hinode *hinode)
20430 + hinode->hi_notify = NULL;
20433 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20435 + return hinode->hi_notify;
20439 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20440 + struct au_hinode *hinode __maybe_unused,
20441 + struct inode *inode __maybe_unused)
20442 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20443 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20444 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20445 + int do_set __maybe_unused)
20446 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20447 + unsigned int flags __maybe_unused)
20448 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20449 + struct au_branch *br __maybe_unused,
20450 + int perm __maybe_unused)
20451 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20452 + int perm __maybe_unused)
20453 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20454 +AuStubInt0(__init au_hnotify_init, void)
20455 +AuStubVoid(au_hnotify_fin, void)
20456 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20457 +#endif /* CONFIG_AUFS_HNOTIFY */
20459 +static inline void au_hn_suspend(struct au_hinode *hdir)
20461 + au_hn_ctl(hdir, /*do_set*/0);
20464 +static inline void au_hn_resume(struct au_hinode *hdir)
20466 + au_hn_ctl(hdir, /*do_set*/1);
20469 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20471 + inode_lock(hdir->hi_inode);
20472 + au_hn_suspend(hdir);
20475 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20476 + unsigned int sc __maybe_unused)
20478 + inode_lock_nested(hdir->hi_inode, sc);
20479 + au_hn_suspend(hdir);
20482 +#if 0 /* unused */
20483 +#include "vfsub.h"
20484 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20487 + inode_lock_shared_nested(hdir->hi_inode, sc);
20488 + au_hn_suspend(hdir);
20492 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20494 + au_hn_resume(hdir);
20495 + inode_unlock(hdir->hi_inode);
20498 +#endif /* __KERNEL__ */
20499 +#endif /* __AUFS_INODE_H__ */
20500 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20501 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20502 +++ linux/fs/aufs/ioctl.c 2022-03-21 14:49:05.726633010 +0100
20504 +// SPDX-License-Identifier: GPL-2.0
20506 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20508 + * This program, aufs is free software; you can redistribute it and/or modify
20509 + * it under the terms of the GNU General Public License as published by
20510 + * the Free Software Foundation; either version 2 of the License, or
20511 + * (at your option) any later version.
20513 + * This program is distributed in the hope that it will be useful,
20514 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20515 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20516 + * GNU General Public License for more details.
20518 + * You should have received a copy of the GNU General Public License
20519 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20524 + * plink-management and readdir in userspace.
20525 + * assist the pathconf(3) wrapper library.
20527 + * File-based Hierarchical Storage Management.
20530 +#include <linux/compat.h>
20531 +#include <linux/file.h>
20534 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20537 + aufs_bindex_t wbi, bindex, bbot;
20538 + struct file *h_file;
20539 + struct super_block *sb;
20540 + struct dentry *root;
20541 + struct au_branch *br;
20542 + struct aufs_wbr_fd wbrfd = {
20543 + .oflags = au_dir_roflags,
20546 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20547 + | O_NOATIME | O_CLOEXEC;
20549 + AuDebugOn(wbrfd.oflags & ~valid);
20552 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20553 + if (unlikely(err)) {
20559 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20560 + wbrfd.oflags |= au_dir_roflags;
20561 + AuDbg("0%o\n", wbrfd.oflags);
20562 + if (unlikely(wbrfd.oflags & ~valid))
20566 + fd = get_unused_fd_flags(0);
20568 + if (unlikely(fd < 0))
20571 + h_file = ERR_PTR(-EINVAL);
20574 + sb = path->dentry->d_sb;
20575 + root = sb->s_root;
20576 + aufs_read_lock(root, AuLock_IR);
20577 + bbot = au_sbbot(sb);
20578 + if (wbrfd.brid >= 0) {
20579 + wbi = au_br_index(sb, wbrfd.brid);
20580 + if (unlikely(wbi < 0 || wbi > bbot))
20584 + h_file = ERR_PTR(-ENOENT);
20585 + br = au_sbr(sb, wbi);
20586 + if (!au_br_writable(br->br_perm)) {
20590 + bindex = wbi + 1;
20592 + for (; bindex <= bbot; bindex++) {
20593 + br = au_sbr(sb, bindex);
20594 + if (au_br_writable(br->br_perm)) {
20596 + br = au_sbr(sb, wbi);
20601 + AuDbg("wbi %d\n", wbi);
20603 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20607 + aufs_read_unlock(root, AuLock_IR);
20608 + err = PTR_ERR(h_file);
20609 + if (IS_ERR(h_file))
20612 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20613 + fd_install(fd, h_file);
20615 + goto out; /* success */
20618 + put_unused_fd(fd);
20624 +/* ---------------------------------------------------------------------- */
20626 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20629 + struct dentry *dentry;
20632 + case AUFS_CTL_RDU:
20633 + case AUFS_CTL_RDU_INO:
20634 + err = au_rdu_ioctl(file, cmd, arg);
20637 + case AUFS_CTL_WBR_FD:
20638 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20641 + case AUFS_CTL_IBUSY:
20642 + err = au_ibusy_ioctl(file, arg);
20645 + case AUFS_CTL_BRINFO:
20646 + err = au_brinfo_ioctl(file, arg);
20649 + case AUFS_CTL_FHSM_FD:
20650 + dentry = file->f_path.dentry;
20651 + if (IS_ROOT(dentry))
20652 + err = au_fhsm_fd(dentry->d_sb, arg);
20658 + /* do not call the lower */
20659 + AuDbg("0x%x\n", cmd);
20667 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20672 + case AUFS_CTL_MVDOWN:
20673 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20676 + case AUFS_CTL_WBR_FD:
20677 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20681 + /* do not call the lower */
20682 + AuDbg("0x%x\n", cmd);
20690 +#ifdef CONFIG_COMPAT
20691 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20692 + unsigned long arg)
20697 + case AUFS_CTL_RDU:
20698 + case AUFS_CTL_RDU_INO:
20699 + err = au_rdu_compat_ioctl(file, cmd, arg);
20702 + case AUFS_CTL_IBUSY:
20703 + err = au_ibusy_compat_ioctl(file, arg);
20706 + case AUFS_CTL_BRINFO:
20707 + err = au_brinfo_compat_ioctl(file, arg);
20711 + err = aufs_ioctl_dir(file, cmd, arg);
20718 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20719 + unsigned long arg)
20721 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20724 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20725 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20726 +++ linux/fs/aufs/i_op_add.c 2022-03-21 14:49:05.726633010 +0100
20728 +// SPDX-License-Identifier: GPL-2.0
20730 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20732 + * This program, aufs is free software; you can redistribute it and/or modify
20733 + * it under the terms of the GNU General Public License as published by
20734 + * the Free Software Foundation; either version 2 of the License, or
20735 + * (at your option) any later version.
20737 + * This program is distributed in the hope that it will be useful,
20738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20740 + * GNU General Public License for more details.
20742 + * You should have received a copy of the GNU General Public License
20743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20747 + * inode operations (add entry)
20750 +#include <linux/iversion.h>
20754 + * final procedure of adding a new entry, except link(2).
20755 + * remove whiteout, instantiate, copyup the parent dir's times and size
20756 + * and update version.
20757 + * if it failed, re-create the removed whiteout.
20759 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20760 + struct dentry *wh_dentry, struct dentry *dentry)
20763 + aufs_bindex_t bwh;
20764 + struct path h_path;
20765 + struct super_block *sb;
20766 + struct inode *inode, *h_dir;
20767 + struct dentry *wh;
20772 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20773 + IMustLock(h_dir);
20774 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20775 + bwh = au_dbwh(dentry);
20776 + h_path.dentry = wh_dentry;
20777 + h_path.mnt = au_sbr_mnt(sb, bindex);
20778 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20780 + if (unlikely(err))
20784 + inode = au_new_inode(dentry, /*must_new*/1);
20785 + if (!IS_ERR(inode)) {
20786 + d_instantiate(dentry, inode);
20787 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20789 + au_dir_ts(dir, bindex);
20790 + inode_inc_iversion(dir);
20791 + au_fhsm_wrote(sb, bindex, /*force*/0);
20792 + return 0; /* success */
20795 + err = PTR_ERR(inode);
20800 + /* dir inode is locked */
20801 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20802 + rerr = PTR_ERR(wh);
20803 + if (IS_ERR(wh)) {
20804 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20805 + dentry, err, rerr);
20814 +static int au_d_may_add(struct dentry *dentry)
20819 + if (unlikely(d_unhashed(dentry)))
20821 + if (unlikely(d_really_is_positive(dentry)))
20827 + * simple tests for the adding inode operations.
20828 + * following the checks in vfs, plus the parent-child relationship.
20830 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20831 + struct dentry *h_parent, int isdir)
20835 + struct dentry *h_dentry;
20836 + struct inode *h_inode;
20838 + err = -ENAMETOOLONG;
20839 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20842 + h_dentry = au_h_dptr(dentry, bindex);
20843 + if (d_really_is_negative(dentry)) {
20845 + if (unlikely(d_is_positive(h_dentry)))
20848 + /* rename(2) case */
20850 + if (unlikely(d_is_negative(h_dentry)))
20852 + h_inode = d_inode(h_dentry);
20853 + if (unlikely(!h_inode->i_nlink))
20856 + h_mode = h_inode->i_mode;
20859 + if (unlikely(S_ISDIR(h_mode)))
20861 + } else if (unlikely(!S_ISDIR(h_mode))) {
20868 + /* expected parent dir is locked */
20869 + if (unlikely(h_parent != h_dentry->d_parent))
20878 + * initial procedure of adding a new entry.
20879 + * prepare writable branch and the parent dir, lock it,
20880 + * and lookup whiteout for the new entry.
20882 +static struct dentry*
20883 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20884 + struct dentry *src_dentry, struct au_pin *pin,
20885 + struct au_wr_dir_args *wr_dir_args)
20887 + struct dentry *wh_dentry, *h_parent;
20888 + struct super_block *sb;
20889 + struct au_branch *br;
20891 + unsigned int udba;
20892 + aufs_bindex_t bcpup;
20894 + AuDbg("%pd\n", dentry);
20896 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20898 + wh_dentry = ERR_PTR(err);
20899 + if (unlikely(err < 0))
20902 + sb = dentry->d_sb;
20903 + udba = au_opt_udba(sb);
20904 + err = au_pin(pin, dentry, bcpup, udba,
20905 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20906 + wh_dentry = ERR_PTR(err);
20907 + if (unlikely(err))
20910 + h_parent = au_pinned_h_parent(pin);
20911 + if (udba != AuOpt_UDBA_NONE
20912 + && au_dbtop(dentry) == bcpup)
20913 + err = au_may_add(dentry, bcpup, h_parent,
20914 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20915 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20916 + err = -ENAMETOOLONG;
20917 + wh_dentry = ERR_PTR(err);
20918 + if (unlikely(err))
20921 + br = au_sbr(sb, bcpup);
20923 + struct path tmp = {
20924 + .dentry = h_parent,
20925 + .mnt = au_br_mnt(br)
20927 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20930 + wh_dentry = NULL;
20931 + if (bcpup != au_dbwh(dentry))
20932 + goto out; /* success */
20935 + * ENAMETOOLONG here means that if we allowed create such name, then it
20936 + * would not be able to removed in the future. So we don't allow such
20937 + * name here and we don't handle ENAMETOOLONG differently here.
20939 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20942 + if (IS_ERR(wh_dentry))
20945 + return wh_dentry;
20948 +/* ---------------------------------------------------------------------- */
20950 +enum { Mknod, Symlink, Creat };
20951 +struct simple_arg {
20958 + struct vfsub_aopen_args *aopen;
20961 + const char *symname;
20970 +static int add_simple(struct inode *dir, struct dentry *dentry,
20971 + struct simple_arg *arg)
20974 + aufs_bindex_t btop;
20975 + unsigned char created;
20976 + const unsigned char try_aopen
20977 + = (arg->type == Creat && arg->u.c.try_aopen);
20978 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
20979 + struct dentry *wh_dentry, *parent;
20980 + struct inode *h_dir;
20981 + struct super_block *sb;
20982 + struct au_branch *br;
20983 + /* to reduce stack size */
20985 + struct au_dtime dt;
20986 + struct au_pin pin;
20987 + struct path h_path;
20988 + struct au_wr_dir_args wr_dir_args;
20991 + AuDbg("%pd\n", dentry);
20995 + a = kmalloc(sizeof(*a), GFP_NOFS);
20996 + if (unlikely(!a))
20998 + a->wr_dir_args.force_btgt = -1;
20999 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21001 + parent = dentry->d_parent; /* dir inode is locked */
21002 + if (!try_aopen) {
21003 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21004 + if (unlikely(err))
21007 + err = au_d_may_add(dentry);
21008 + if (unlikely(err))
21011 + di_write_lock_parent(parent);
21012 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21013 + &a->pin, &a->wr_dir_args);
21014 + err = PTR_ERR(wh_dentry);
21015 + if (IS_ERR(wh_dentry))
21018 + btop = au_dbtop(dentry);
21019 + sb = dentry->d_sb;
21020 + br = au_sbr(sb, btop);
21021 + a->h_path.dentry = au_h_dptr(dentry, btop);
21022 + a->h_path.mnt = au_br_mnt(br);
21023 + h_dir = au_pinned_h_dir(&a->pin);
21024 + switch (arg->type) {
21026 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21027 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21028 + arg->u.c.want_excl);
21030 + if (!err && try_aopen)
21031 + aopen->file->f_mode |= FMODE_CREATED;
21034 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21035 + AuDbg("err %d\n", err);
21036 + AuDbgFile(aopen->file);
21037 + created = err >= 0
21038 + && !!(aopen->file->f_mode & FMODE_CREATED);
21042 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21046 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21053 + if (unlikely(err < 0))
21056 + err = epilog(dir, btop, wh_dentry, dentry);
21058 + goto out_unpin; /* success */
21061 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21062 + /* no delegation since it is just created */
21063 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21066 + AuIOErr("%pd revert failure(%d, %d)\n",
21067 + dentry, err, rerr);
21070 + au_dtime_revert(&a->dt);
21072 + if (try_aopen && h_dir->i_op->atomic_open
21073 + && (aopen->file->f_mode & FMODE_OPENED))
21074 + /* aopen->file is still opened */
21075 + au_lcnt_dec(&aopen->br->br_nfiles);
21078 + au_unpin(&a->pin);
21082 + di_write_unlock(parent);
21084 + if (unlikely(err)) {
21085 + au_update_dbtop(dentry);
21089 + aufs_read_unlock(dentry, AuLock_DW);
21096 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
21097 + struct dentry *dentry, umode_t mode, dev_t dev)
21099 + struct simple_arg arg = {
21106 + return add_simple(dir, dentry, &arg);
21109 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
21110 + struct dentry *dentry, const char *symname)
21112 + struct simple_arg arg = {
21114 + .u.s.symname = symname
21116 + return add_simple(dir, dentry, &arg);
21119 +int aufs_create(struct user_namespace *userns, struct inode *dir,
21120 + struct dentry *dentry, umode_t mode, bool want_excl)
21122 + struct simple_arg arg = {
21126 + .want_excl = want_excl
21129 + return add_simple(dir, dentry, &arg);
21132 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21133 + struct vfsub_aopen_args *aopen_args)
21135 + struct simple_arg arg = {
21138 + .mode = aopen_args->create_mode,
21139 + .want_excl = aopen_args->open_flag & O_EXCL,
21140 + .try_aopen = true,
21141 + .aopen = aopen_args
21144 + return add_simple(dir, dentry, &arg);
21147 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
21148 + struct dentry *dentry, umode_t mode)
21151 + aufs_bindex_t bindex;
21152 + struct super_block *sb;
21153 + struct dentry *parent, *h_parent, *h_dentry;
21154 + struct inode *h_dir, *inode;
21155 + struct vfsmount *h_mnt;
21156 + struct user_namespace *h_userns;
21157 + struct au_wr_dir_args wr_dir_args = {
21158 + .force_btgt = -1,
21159 + .flags = AuWrDir_TMPFILE
21162 + /* copy-up may happen */
21166 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21167 + if (unlikely(err))
21170 + err = au_di_init(dentry);
21171 + if (unlikely(err))
21175 + parent = d_find_any_alias(dir);
21176 + AuDebugOn(!parent);
21177 + di_write_lock_parent(parent);
21178 + if (unlikely(d_inode(parent) != dir))
21181 + err = au_digen_test(parent, au_sigen(sb));
21182 + if (unlikely(err))
21185 + bindex = au_dbtop(parent);
21186 + au_set_dbtop(dentry, bindex);
21187 + au_set_dbbot(dentry, bindex);
21188 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21190 + if (unlikely(err < 0))
21193 + err = -EOPNOTSUPP;
21194 + h_dir = au_h_iptr(dir, bindex);
21195 + if (unlikely(!h_dir->i_op->tmpfile))
21198 + h_mnt = au_sbr_mnt(sb, bindex);
21199 + err = vfsub_mnt_want_write(h_mnt);
21200 + if (unlikely(err))
21203 + h_userns = mnt_user_ns(h_mnt);
21204 + h_parent = au_h_dptr(parent, bindex);
21205 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
21206 + if (IS_ERR(h_dentry)) {
21207 + err = PTR_ERR(h_dentry);
21211 + au_set_dbtop(dentry, bindex);
21212 + au_set_dbbot(dentry, bindex);
21213 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21214 + inode = au_new_inode(dentry, /*must_new*/1);
21215 + if (IS_ERR(inode)) {
21216 + err = PTR_ERR(inode);
21217 + au_set_h_dptr(dentry, bindex, NULL);
21218 + au_set_dbtop(dentry, -1);
21219 + au_set_dbbot(dentry, -1);
21221 + if (!inode->i_nlink)
21222 + set_nlink(inode, 1);
21223 + d_tmpfile(dentry, inode);
21224 + au_di(dentry)->di_tmpfile = 1;
21226 + /* update without i_mutex */
21227 + if (au_ibtop(dir) == au_dbtop(dentry))
21228 + au_cpup_attr_timesizes(dir);
21233 + vfsub_mnt_drop_write(h_mnt);
21235 + di_write_unlock(parent);
21237 + di_write_unlock(dentry);
21238 + if (unlikely(err)) {
21239 + au_di_fin(dentry);
21240 + dentry->d_fsdata = NULL;
21243 + si_read_unlock(sb);
21245 + inode_unlock(dir);
21249 +/* ---------------------------------------------------------------------- */
21251 +struct au_link_args {
21252 + aufs_bindex_t bdst, bsrc;
21253 + struct au_pin pin;
21254 + struct path h_path;
21255 + struct dentry *src_parent, *parent;
21258 +static int au_cpup_before_link(struct dentry *src_dentry,
21259 + struct au_link_args *a)
21262 + struct dentry *h_src_dentry;
21263 + struct au_cp_generic cpg = {
21264 + .dentry = src_dentry,
21269 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21272 + di_read_lock_parent(a->src_parent, AuLock_IR);
21273 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21274 + if (unlikely(err))
21277 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21278 + err = au_pin(&a->pin, src_dentry, a->bdst,
21279 + au_opt_udba(src_dentry->d_sb),
21280 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21281 + if (unlikely(err))
21284 + err = au_sio_cpup_simple(&cpg);
21285 + au_unpin(&a->pin);
21288 + di_read_unlock(a->src_parent, AuLock_IR);
21292 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21293 + struct au_link_args *a)
21296 + unsigned char plink;
21297 + aufs_bindex_t bbot;
21298 + struct dentry *h_src_dentry;
21299 + struct inode *h_inode, *inode, *delegated;
21300 + struct super_block *sb;
21301 + struct file *h_file;
21305 + sb = src_dentry->d_sb;
21306 + inode = d_inode(src_dentry);
21307 + if (au_ibtop(inode) <= a->bdst)
21308 + h_inode = au_h_iptr(inode, a->bdst);
21309 + if (!h_inode || !h_inode->i_nlink) {
21310 + /* copyup src_dentry as the name of dentry. */
21311 + bbot = au_dbbot(dentry);
21312 + if (bbot < a->bsrc)
21313 + au_set_dbbot(dentry, a->bsrc);
21314 + au_set_h_dptr(dentry, a->bsrc,
21315 + dget(au_h_dptr(src_dentry, a->bsrc)));
21316 + dget(a->h_path.dentry);
21317 + au_set_h_dptr(dentry, a->bdst, NULL);
21318 + AuDbg("temporary d_inode...\n");
21319 + spin_lock(&dentry->d_lock);
21320 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21321 + spin_unlock(&dentry->d_lock);
21322 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21323 + if (IS_ERR(h_file))
21324 + err = PTR_ERR(h_file);
21326 + struct au_cp_generic cpg = {
21327 + .dentry = dentry,
21332 + .flags = AuCpup_KEEPLINO
21334 + err = au_sio_cpup_simple(&cpg);
21335 + au_h_open_post(dentry, a->bsrc, h_file);
21337 + dput(a->h_path.dentry);
21338 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21340 + au_set_h_dptr(dentry, a->bdst,
21341 + a->h_path.dentry);
21343 + spin_lock(&dentry->d_lock);
21344 + dentry->d_inode = NULL; /* restore */
21345 + spin_unlock(&dentry->d_lock);
21346 + AuDbg("temporary d_inode...done\n");
21347 + au_set_h_dptr(dentry, a->bsrc, NULL);
21348 + au_set_dbbot(dentry, bbot);
21350 + /* the inode of src_dentry already exists on a.bdst branch */
21351 + h_src_dentry = d_find_alias(h_inode);
21352 + if (!h_src_dentry && au_plink_test(inode)) {
21354 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21355 + err = PTR_ERR(h_src_dentry);
21356 + if (IS_ERR(h_src_dentry))
21359 + if (unlikely(d_is_negative(h_src_dentry))) {
21360 + dput(h_src_dentry);
21361 + h_src_dentry = NULL;
21365 + if (h_src_dentry) {
21366 + delegated = NULL;
21367 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21368 + &a->h_path, &delegated);
21369 + if (unlikely(err == -EWOULDBLOCK)) {
21370 + pr_warn("cannot retry for NFSv4 delegation"
21371 + " for an internal link\n");
21374 + dput(h_src_dentry);
21376 + AuIOErr("no dentry found for hi%lu on b%d\n",
21377 + h_inode->i_ino, a->bdst);
21382 + if (!err && !plink)
21383 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21390 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21391 + struct dentry *dentry)
21394 + struct au_dtime dt;
21395 + struct au_link_args *a;
21396 + struct dentry *wh_dentry, *h_src_dentry;
21397 + struct inode *inode, *delegated;
21398 + struct super_block *sb;
21399 + struct au_wr_dir_args wr_dir_args = {
21400 + /* .force_btgt = -1, */
21401 + .flags = AuWrDir_ADD_ENTRY
21405 + inode = d_inode(src_dentry);
21406 + IMustLock(inode);
21409 + a = kzalloc(sizeof(*a), GFP_NOFS);
21410 + if (unlikely(!a))
21413 + a->parent = dentry->d_parent; /* dir inode is locked */
21414 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21415 + AuLock_NOPLM | AuLock_GEN);
21416 + if (unlikely(err))
21418 + err = au_d_linkable(src_dentry);
21419 + if (unlikely(err))
21421 + err = au_d_may_add(dentry);
21422 + if (unlikely(err))
21425 + a->src_parent = dget_parent(src_dentry);
21426 + wr_dir_args.force_btgt = au_ibtop(inode);
21428 + di_write_lock_parent(a->parent);
21429 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21430 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21432 + err = PTR_ERR(wh_dentry);
21433 + if (IS_ERR(wh_dentry))
21437 + sb = dentry->d_sb;
21438 + a->bdst = au_dbtop(dentry);
21439 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21440 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21441 + a->bsrc = au_ibtop(inode);
21442 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21443 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21444 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21445 + if (!h_src_dentry) {
21446 + a->bsrc = au_dbtop(src_dentry);
21447 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21448 + AuDebugOn(!h_src_dentry);
21449 + } else if (IS_ERR(h_src_dentry)) {
21450 + err = PTR_ERR(h_src_dentry);
21455 + * aufs doesn't touch the credential so
21456 + * security_dentry_create_files_as() is unnecessary.
21458 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21459 + if (a->bdst < a->bsrc
21460 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21461 + err = au_cpup_or_link(src_dentry, dentry, a);
21463 + delegated = NULL;
21464 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21465 + &a->h_path, &delegated);
21466 + if (unlikely(err == -EWOULDBLOCK)) {
21467 + pr_warn("cannot retry for NFSv4 delegation"
21468 + " for an internal link\n");
21472 + dput(h_src_dentry);
21475 + * copyup src_dentry to the branch we process,
21476 + * and then link(2) to it.
21478 + dput(h_src_dentry);
21479 + if (a->bdst < a->bsrc
21480 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21481 + au_unpin(&a->pin);
21482 + di_write_unlock(a->parent);
21483 + err = au_cpup_before_link(src_dentry, a);
21484 + di_write_lock_parent(a->parent);
21486 + err = au_pin(&a->pin, dentry, a->bdst,
21488 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21489 + if (unlikely(err))
21493 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21495 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21496 + delegated = NULL;
21497 + err = vfsub_link(h_src_dentry,
21498 + au_pinned_h_dir(&a->pin),
21499 + &a->h_path, &delegated);
21500 + if (unlikely(err == -EWOULDBLOCK)) {
21501 + pr_warn("cannot retry"
21502 + " for NFSv4 delegation"
21503 + " for an internal link\n");
21509 + if (unlikely(err))
21513 + a->h_path.dentry = wh_dentry;
21514 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21516 + if (unlikely(err))
21520 + au_dir_ts(dir, a->bdst);
21521 + inode_inc_iversion(dir);
21522 + inc_nlink(inode);
21523 + inode->i_ctime = dir->i_ctime;
21524 + d_instantiate(dentry, au_igrab(inode));
21525 + if (d_unhashed(a->h_path.dentry))
21526 + /* some filesystem calls d_drop() */
21528 + /* some filesystems consume an inode even hardlink */
21529 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21530 + goto out_unpin; /* success */
21533 + /* no delegation since it is just created */
21534 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21535 + /*delegated*/NULL, /*force*/0);
21536 + if (unlikely(rerr)) {
21537 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21540 + au_dtime_revert(&dt);
21542 + au_unpin(&a->pin);
21546 + di_write_unlock(a->parent);
21547 + dput(a->src_parent);
21549 + if (unlikely(err)) {
21550 + au_update_dbtop(dentry);
21553 + aufs_read_and_write_unlock2(dentry, src_dentry);
21561 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
21562 + struct dentry *dentry, umode_t mode)
21565 + aufs_bindex_t bindex;
21566 + unsigned char diropq;
21567 + struct path h_path;
21568 + struct dentry *wh_dentry, *parent, *opq_dentry;
21569 + struct inode *h_inode;
21570 + struct super_block *sb;
21572 + struct au_pin pin;
21573 + struct au_dtime dt;
21574 + } *a; /* reduce the stack usage */
21575 + struct au_wr_dir_args wr_dir_args = {
21576 + .force_btgt = -1,
21577 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21583 + a = kmalloc(sizeof(*a), GFP_NOFS);
21584 + if (unlikely(!a))
21587 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21588 + if (unlikely(err))
21590 + err = au_d_may_add(dentry);
21591 + if (unlikely(err))
21594 + parent = dentry->d_parent; /* dir inode is locked */
21595 + di_write_lock_parent(parent);
21596 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21597 + &a->pin, &wr_dir_args);
21598 + err = PTR_ERR(wh_dentry);
21599 + if (IS_ERR(wh_dentry))
21602 + sb = dentry->d_sb;
21603 + bindex = au_dbtop(dentry);
21604 + h_path.dentry = au_h_dptr(dentry, bindex);
21605 + h_path.mnt = au_sbr_mnt(sb, bindex);
21606 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21607 + if (unlikely(err))
21610 + /* make the dir opaque */
21612 + h_inode = d_inode(h_path.dentry);
21614 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21615 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21616 + opq_dentry = au_diropq_create(dentry, bindex);
21617 + inode_unlock(h_inode);
21618 + err = PTR_ERR(opq_dentry);
21619 + if (IS_ERR(opq_dentry))
21621 + dput(opq_dentry);
21625 + err = epilog(dir, bindex, wh_dentry, dentry);
21628 + goto out_unpin; /* success */
21633 + AuLabel(revert opq);
21634 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21635 + rerr = au_diropq_remove(dentry, bindex);
21636 + inode_unlock(h_inode);
21638 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21639 + dentry, err, rerr);
21645 + AuLabel(revert dir);
21646 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21648 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21649 + dentry, err, rerr);
21652 + au_dtime_revert(&a->dt);
21654 + au_unpin(&a->pin);
21657 + di_write_unlock(parent);
21659 + if (unlikely(err)) {
21660 + au_update_dbtop(dentry);
21663 + aufs_read_unlock(dentry, AuLock_DW);
21669 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21670 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21671 +++ linux/fs/aufs/i_op.c 2022-03-21 14:49:05.726633010 +0100
21673 +// SPDX-License-Identifier: GPL-2.0
21675 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21677 + * This program, aufs is free software; you can redistribute it and/or modify
21678 + * it under the terms of the GNU General Public License as published by
21679 + * the Free Software Foundation; either version 2 of the License, or
21680 + * (at your option) any later version.
21682 + * This program is distributed in the hope that it will be useful,
21683 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21684 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21685 + * GNU General Public License for more details.
21687 + * You should have received a copy of the GNU General Public License
21688 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21692 + * inode operations (except add/del/rename)
21695 +#include <linux/device_cgroup.h>
21696 +#include <linux/fs_stack.h>
21697 +#include <linux/iversion.h>
21698 +#include <linux/security.h>
21701 +static int h_permission(struct inode *h_inode, int mask,
21702 + struct path *h_path, int brperm)
21705 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21706 + struct user_namespace *h_userns;
21709 + if (write_mask && IS_IMMUTABLE(h_inode))
21713 + if (((mask & MAY_EXEC)
21714 + && S_ISREG(h_inode->i_mode)
21715 + && (path_noexec(h_path)
21716 + || !(h_inode->i_mode & 0111))))
21720 + * - skip the lower fs test in the case of write to ro branch.
21721 + * - nfs dir permission write check is optimized, but a policy for
21722 + * link/rename requires a real check.
21723 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21724 + * in this case, generic_permission() returns -EOPNOTSUPP.
21726 + h_userns = mnt_user_ns(h_path->mnt);
21727 + if ((write_mask && !au_br_writable(brperm))
21728 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21729 + && write_mask && !(mask & MAY_READ))
21730 + || !h_inode->i_op->permission) {
21731 + /* AuLabel(generic_permission); */
21732 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
21733 + err = generic_permission(h_userns, h_inode, mask);
21734 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21735 + err = h_inode->i_op->permission(h_userns, h_inode,
21739 + /* AuLabel(h_inode->permission); */
21740 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
21745 + err = devcgroup_inode_permission(h_inode, mask);
21747 + err = security_inode_permission(h_inode, mask);
21753 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
21757 + aufs_bindex_t bindex, bbot;
21758 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21759 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21760 + struct inode *h_inode;
21761 + struct super_block *sb;
21762 + struct au_branch *br;
21764 + /* todo: support rcu-walk? */
21765 + if (mask & MAY_NOT_BLOCK)
21768 + sb = inode->i_sb;
21769 + si_read_lock(sb, AuLock_FLUSH);
21770 + ii_read_lock_child(inode);
21771 +#if 0 /* reserved for future use */
21773 + * This test may be rather 'too much' since the test is essentially done
21774 + * in the aufs_lookup(). Theoretically it is possible that the inode
21775 + * generation doesn't match to the superblock's here. But it isn't a
21776 + * big deal I suppose.
21778 + err = au_iigen_test(inode, au_sigen(sb));
21779 + if (unlikely(err))
21785 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21786 + err = au_busy_or_stale();
21787 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21788 + if (unlikely(!h_inode
21789 + || (h_inode->i_mode & S_IFMT)
21790 + != (inode->i_mode & S_IFMT)))
21794 + bindex = au_ibtop(inode);
21795 + br = au_sbr(sb, bindex);
21796 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21799 + && !special_file(h_inode->i_mode)) {
21800 + /* test whether the upper writable branch exists */
21802 + for (; bindex >= 0; bindex--)
21803 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21811 + /* non-write to dir */
21813 + bbot = au_ibbot(inode);
21814 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21815 + h_inode = au_h_iptr(inode, bindex);
21817 + err = au_busy_or_stale();
21818 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21821 + br = au_sbr(sb, bindex);
21822 + err = h_permission(h_inode, mask, &br->br_path,
21828 + ii_read_unlock(inode);
21829 + si_read_unlock(sb);
21833 +/* ---------------------------------------------------------------------- */
21835 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21836 + unsigned int flags)
21838 + struct dentry *ret, *parent;
21839 + struct inode *inode;
21840 + struct super_block *sb;
21841 + int err, npositive;
21845 + /* todo: support rcu-walk? */
21846 + ret = ERR_PTR(-ECHILD);
21847 + if (flags & LOOKUP_RCU)
21850 + ret = ERR_PTR(-ENAMETOOLONG);
21851 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21855 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21856 + ret = ERR_PTR(err);
21857 + if (unlikely(err))
21860 + err = au_di_init(dentry);
21861 + ret = ERR_PTR(err);
21862 + if (unlikely(err))
21866 + npositive = 0; /* suppress a warning */
21867 + parent = dentry->d_parent; /* dir inode is locked */
21868 + di_read_lock_parent(parent, AuLock_IR);
21869 + err = au_alive_dir(parent);
21871 + err = au_digen_test(parent, au_sigen(sb));
21873 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21874 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21875 + AuLkup_ALLOW_NEG);
21878 + di_read_unlock(parent, AuLock_IR);
21879 + ret = ERR_PTR(err);
21880 + if (unlikely(err < 0))
21884 + inode = au_new_inode(dentry, /*must_new*/0);
21885 + if (IS_ERR(inode)) {
21886 + ret = (void *)inode;
21893 + atomic_inc(&inode->i_count);
21894 + ret = d_splice_alias(inode, dentry);
21895 +#if 0 /* reserved for future use */
21896 + if (unlikely(d_need_lookup(dentry))) {
21897 + spin_lock(&dentry->d_lock);
21898 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21899 + spin_unlock(&dentry->d_lock);
21903 + if (!IS_ERR(ret)) {
21905 + if (ret && ret != dentry)
21906 + ii_write_unlock(inode);
21908 + ii_write_unlock(inode);
21915 + di_write_unlock(dentry);
21917 + si_read_unlock(sb);
21922 +/* ---------------------------------------------------------------------- */
21925 + * very dirty and complicated aufs ->atomic_open().
21926 + * aufs_atomic_open()
21927 + * + au_aopen_or_create()
21929 + * + vfsub_atomic_open()
21930 + * + branch fs ->atomic_open()
21931 + * may call the actual 'open' for h_file
21932 + * + inc br_nfiles only if opened
21933 + * + au_aopen_no_open() or au_aopen_do_open()
21935 + * au_aopen_do_open()
21936 + * + finish_open()
21937 + * + au_do_aopen()
21938 + * + au_do_open() the body of all 'open'
21939 + * + au_do_open_nondir()
21940 + * set the passed h_file
21942 + * au_aopen_no_open()
21943 + * + finish_no_open()
21946 +struct aopen_node {
21947 + struct hlist_bl_node hblist;
21948 + struct file *file, *h_file;
21951 +static int au_do_aopen(struct inode *inode, struct file *file)
21953 + struct hlist_bl_head *aopen;
21954 + struct hlist_bl_node *pos;
21955 + struct aopen_node *node;
21956 + struct au_do_open_args args = {
21958 + .open = au_do_open_nondir
21961 + aopen = &au_sbi(inode->i_sb)->si_aopen;
21962 + hlist_bl_lock(aopen);
21963 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
21964 + if (node->file == file) {
21965 + args.h_file = node->h_file;
21968 + hlist_bl_unlock(aopen);
21969 + /* AuDebugOn(!args.h_file); */
21971 + return au_do_open(file, &args);
21974 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
21975 + struct aopen_node *aopen_node)
21978 + struct hlist_bl_head *aopen;
21981 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
21982 + au_hbl_add(&aopen_node->hblist, aopen);
21983 + err = finish_open(file, dentry, au_do_aopen);
21984 + au_hbl_del(&aopen_node->hblist, aopen);
21985 + /* AuDbgFile(file); */
21986 + AuDbg("%pd%s%s\n", dentry,
21987 + (file->f_mode & FMODE_CREATED) ? " created" : "",
21988 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
21994 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22000 + err = finish_no_open(file, dentry);
22006 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22007 + struct file *file, unsigned int open_flag,
22008 + umode_t create_mode)
22010 + int err, did_open;
22011 + unsigned int lkup_flags;
22012 + aufs_bindex_t bindex;
22013 + struct super_block *sb;
22014 + struct dentry *parent, *d;
22015 + struct vfsub_aopen_args args = {
22016 + .open_flag = open_flag,
22017 + .create_mode = create_mode
22019 + struct aopen_node aopen_node = {
22024 + AuDbg("open_flag 0%o\n", open_flag);
22025 + AuDbgDentry(dentry);
22028 + if (!au_di(dentry)) {
22029 + lkup_flags = LOOKUP_OPEN;
22030 + if (open_flag & O_CREAT)
22031 + lkup_flags |= LOOKUP_CREATE;
22032 + d = aufs_lookup(dir, dentry, lkup_flags);
22034 + err = PTR_ERR(d);
22039 + * obsoleted dentry found.
22040 + * another error will be returned later.
22046 + AuDbgDentry(dentry);
22049 + if (d_is_positive(dentry)
22050 + || d_unhashed(dentry)
22051 + || d_unlinked(dentry)
22052 + || !(open_flag & O_CREAT)) {
22053 + err = au_aopen_no_open(file, dentry);
22054 + goto out; /* success */
22057 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22058 + if (unlikely(err))
22061 + sb = dentry->d_sb;
22062 + parent = dentry->d_parent; /* dir is locked */
22063 + di_write_lock_parent(parent);
22064 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22065 + if (unlikely(err < 0))
22068 + AuDbgDentry(dentry);
22069 + if (d_is_positive(dentry)) {
22070 + err = au_aopen_no_open(file, dentry);
22071 + goto out_parent; /* success */
22074 + args.file = alloc_empty_file(file->f_flags, current_cred());
22075 + err = PTR_ERR(args.file);
22076 + if (IS_ERR(args.file))
22079 + bindex = au_dbtop(dentry);
22080 + err = au_aopen_or_create(dir, dentry, &args);
22082 + AuDbgFile(args.file);
22083 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22084 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22087 + args.file = NULL;
22089 + di_write_unlock(parent);
22090 + di_write_unlock(dentry);
22091 + if (unlikely(err < 0)) {
22098 + err = au_aopen_no_open(file, dentry);
22100 + aopen_node.h_file = args.file;
22101 + err = au_aopen_do_open(file, dentry, &aopen_node);
22103 + if (unlikely(err < 0)) {
22107 + au_lcnt_dec(&args.br->br_nfiles);
22109 + goto out_sb; /* success */
22112 + di_write_unlock(parent);
22113 + di_write_unlock(dentry);
22115 + si_read_unlock(sb);
22123 +/* ---------------------------------------------------------------------- */
22125 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22126 + const unsigned char add_entry, aufs_bindex_t bcpup,
22127 + aufs_bindex_t btop)
22130 + struct dentry *h_parent;
22131 + struct inode *h_dir;
22134 + IMustLock(d_inode(parent));
22136 + di_write_lock_parent(parent);
22139 + if (!au_h_dptr(parent, bcpup)) {
22140 + if (btop > bcpup)
22141 + err = au_cpup_dirs(dentry, bcpup);
22142 + else if (btop < bcpup)
22143 + err = au_cpdown_dirs(dentry, bcpup);
22147 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22148 + h_parent = au_h_dptr(parent, bcpup);
22149 + h_dir = d_inode(h_parent);
22150 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22151 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22152 + /* todo: no unlock here */
22153 + inode_unlock_shared(h_dir);
22155 + AuDbg("bcpup %d\n", bcpup);
22157 + if (d_really_is_negative(dentry))
22158 + au_set_h_dptr(dentry, btop, NULL);
22159 + au_update_dbrange(dentry, /*do_put_zero*/0);
22164 + di_write_unlock(parent);
22166 + err = bcpup; /* success */
22173 + * decide the branch and the parent dir where we will create a new entry.
22174 + * returns new bindex or an error.
22175 + * copyup the parent dir if needed.
22177 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22178 + struct au_wr_dir_args *args)
22181 + unsigned int flags;
22182 + aufs_bindex_t bcpup, btop, src_btop;
22183 + const unsigned char add_entry
22184 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22185 + | au_ftest_wrdir(args->flags, TMPFILE);
22186 + struct super_block *sb;
22187 + struct dentry *parent;
22188 + struct au_sbinfo *sbinfo;
22190 + sb = dentry->d_sb;
22191 + sbinfo = au_sbi(sb);
22192 + parent = dget_parent(dentry);
22193 + btop = au_dbtop(dentry);
22195 + if (args->force_btgt < 0) {
22196 + if (src_dentry) {
22197 + src_btop = au_dbtop(src_dentry);
22198 + if (src_btop < btop)
22199 + bcpup = src_btop;
22200 + } else if (add_entry) {
22202 + if (au_ftest_wrdir(args->flags, ISDIR))
22203 + au_fset_wbr(flags, DIR);
22204 + err = AuWbrCreate(sbinfo, dentry, flags);
22208 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22210 + err = AuWbrCopyup(sbinfo, dentry);
22212 + if (!IS_ROOT(dentry)) {
22213 + di_read_lock_parent(parent, !AuLock_IR);
22214 + err = AuWbrCopyup(sbinfo, dentry);
22215 + di_read_unlock(parent, !AuLock_IR);
22217 + err = AuWbrCopyup(sbinfo, dentry);
22220 + if (unlikely(err < 0))
22224 + bcpup = args->force_btgt;
22225 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22228 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22230 + if (bcpup == btop)
22231 + goto out; /* success */
22233 + /* copyup the new parent into the branch we process */
22234 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22236 + if (d_really_is_negative(dentry)) {
22237 + au_set_h_dptr(dentry, btop, NULL);
22238 + au_set_dbtop(dentry, bcpup);
22239 + au_set_dbbot(dentry, bcpup);
22241 + AuDebugOn(add_entry
22242 + && !au_ftest_wrdir(args->flags, TMPFILE)
22243 + && !au_h_dptr(dentry, bcpup));
22251 +/* ---------------------------------------------------------------------- */
22253 +void au_pin_hdir_unlock(struct au_pin *p)
22256 + au_hn_inode_unlock(p->hdir);
22259 +int au_pin_hdir_lock(struct au_pin *p)
22267 + /* even if an error happens later, keep this lock */
22268 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22271 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22276 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22277 + p->h_parent, p->br);
22283 +int au_pin_hdir_relock(struct au_pin *p)
22286 + struct inode *h_i;
22287 + struct dentry *h_d[] = {
22292 + err = au_pin_hdir_lock(p);
22293 + if (unlikely(err))
22296 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22299 + if (d_is_positive(h_d[i])) {
22300 + h_i = d_inode(h_d[i]);
22301 + err = !h_i->i_nlink;
22309 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22311 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22314 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22317 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22318 + p->lsc_hi, 0, NULL, _RET_IP_);
22319 + au_pin_hdir_set_owner(p, current);
22323 +void au_pin_hdir_release(struct au_pin *p)
22326 + au_pin_hdir_set_owner(p, p->task);
22327 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22331 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22333 + if (pin && pin->parent)
22334 + return au_h_dptr(pin->parent, pin->bindex);
22338 +void au_unpin(struct au_pin *p)
22341 + au_pin_hdir_unlock(p);
22342 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22343 + vfsub_mnt_drop_write(p->h_mnt);
22347 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22348 + di_read_unlock(p->parent, AuLock_IR);
22349 + iput(p->hdir->hi_inode);
22351 + p->parent = NULL;
22354 + /* do not clear p->task */
22357 +int au_do_pin(struct au_pin *p)
22360 + struct super_block *sb;
22361 + struct inode *h_dir;
22364 + sb = p->dentry->d_sb;
22365 + p->br = au_sbr(sb, p->bindex);
22366 + if (IS_ROOT(p->dentry)) {
22367 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22368 + p->h_mnt = au_br_mnt(p->br);
22369 + err = vfsub_mnt_want_write(p->h_mnt);
22370 + if (unlikely(err)) {
22371 + au_fclr_pin(p->flags, MNT_WRITE);
22378 + p->h_dentry = NULL;
22379 + if (p->bindex <= au_dbbot(p->dentry))
22380 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22382 + p->parent = dget_parent(p->dentry);
22383 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22384 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22387 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22388 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22390 + h_dir = p->hdir->hi_inode;
22394 + * if DI_LOCKED is not set, then p->parent may be different
22395 + * and h_parent can be NULL.
22397 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22399 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22400 + di_read_unlock(p->parent, AuLock_IR);
22402 + p->parent = NULL;
22406 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22407 + p->h_mnt = au_br_mnt(p->br);
22408 + err = vfsub_mnt_want_write(p->h_mnt);
22409 + if (unlikely(err)) {
22410 + au_fclr_pin(p->flags, MNT_WRITE);
22411 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22412 + di_read_unlock(p->parent, AuLock_IR);
22414 + p->parent = NULL;
22420 + err = au_pin_hdir_lock(p);
22422 + goto out; /* success */
22427 + pr_err("err %d\n", err);
22428 + err = au_busy_or_stale();
22433 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22434 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22435 + unsigned int udba, unsigned char flags)
22437 + p->dentry = dentry;
22439 + p->lsc_di = lsc_di;
22440 + p->lsc_hi = lsc_hi;
22441 + p->flags = flags;
22442 + p->bindex = bindex;
22444 + p->parent = NULL;
22448 + p->h_dentry = NULL;
22449 + p->h_parent = NULL;
22451 + p->task = current;
22454 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22455 + unsigned int udba, unsigned char flags)
22457 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22459 + return au_do_pin(pin);
22462 +/* ---------------------------------------------------------------------- */
22465 + * ->setattr() and ->getattr() are called in various cases.
22466 + * chmod, stat: dentry is revalidated.
22467 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22469 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22471 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22472 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22475 + struct dentry *parent;
22478 + if (au_digen_test(dentry, sigen)) {
22479 + parent = dget_parent(dentry);
22480 + di_read_lock_parent(parent, AuLock_IR);
22481 + err = au_refresh_dentry(dentry, parent);
22482 + di_read_unlock(parent, AuLock_IR);
22490 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22491 + struct au_icpup_args *a)
22495 + aufs_bindex_t btop, ibtop;
22496 + struct dentry *hi_wh, *parent;
22497 + struct inode *inode;
22498 + struct au_wr_dir_args wr_dir_args = {
22499 + .force_btgt = -1,
22503 + if (d_is_dir(dentry))
22504 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22505 + /* plink or hi_wh() case */
22506 + btop = au_dbtop(dentry);
22507 + inode = d_inode(dentry);
22508 + ibtop = au_ibtop(inode);
22509 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22510 + wr_dir_args.force_btgt = ibtop;
22511 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22512 + if (unlikely(err < 0))
22516 + au_fset_icpup(a->flags, DID_CPUP);
22519 + a->pin_flags = AuPin_MNT_WRITE;
22521 + if (!IS_ROOT(dentry)) {
22522 + au_fset_pin(a->pin_flags, DI_LOCKED);
22523 + parent = dget_parent(dentry);
22524 + di_write_lock_parent(parent);
22527 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22528 + if (unlikely(err))
22532 + a->h_path.dentry = au_h_dptr(dentry, btop);
22533 + a->h_inode = d_inode(a->h_path.dentry);
22534 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22535 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22536 + if (ia->ia_size < i_size_read(a->h_inode))
22537 + sz = ia->ia_size;
22538 + inode_unlock_shared(a->h_inode);
22542 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22543 + hi_wh = au_hi_wh(inode, a->btgt);
22545 + struct au_cp_generic cpg = {
22546 + .dentry = dentry,
22552 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22553 + if (unlikely(err))
22555 + hi_wh = au_hi_wh(inode, a->btgt);
22556 + /* todo: revalidate hi_wh? */
22561 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22562 + di_downgrade_lock(parent, AuLock_IR);
22566 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22567 + goto out; /* success */
22569 + if (!d_unhashed(dentry)) {
22570 + struct au_cp_generic cpg = {
22571 + .dentry = dentry,
22576 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22578 + err = au_sio_cpup_simple(&cpg);
22580 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22581 + } else if (!hi_wh)
22582 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22584 + a->h_path.dentry = hi_wh; /* do not dget here */
22587 + a->h_inode = d_inode(a->h_path.dentry);
22589 + goto out; /* success */
22590 + au_unpin(&a->pin);
22593 + di_write_unlock(parent);
22598 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22602 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
22603 + struct iattr *ia)
22606 + struct inode *inode, *delegated;
22607 + struct super_block *sb;
22608 + struct file *file;
22609 + struct au_icpup_args *a;
22610 + struct user_namespace *h_userns;
22612 + inode = d_inode(dentry);
22613 + IMustLock(inode);
22615 + err = setattr_prepare(userns, dentry, ia);
22616 + if (unlikely(err))
22620 + a = kzalloc(sizeof(*a), GFP_NOFS);
22621 + if (unlikely(!a))
22624 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22625 + ia->ia_valid &= ~ATTR_MODE;
22628 + sb = dentry->d_sb;
22629 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22630 + if (unlikely(err))
22633 + if (ia->ia_valid & ATTR_FILE) {
22634 + /* currently ftruncate(2) only */
22635 + AuDebugOn(!d_is_reg(dentry));
22636 + file = ia->ia_file;
22637 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22639 + if (unlikely(err))
22641 + ia->ia_file = au_hf_top(file);
22642 + a->udba = AuOpt_UDBA_NONE;
22644 + /* fchmod() doesn't pass ia_file */
22645 + a->udba = au_opt_udba(sb);
22646 + di_write_lock_child(dentry);
22647 + /* no d_unlinked(), to set UDBA_NONE for root */
22648 + if (d_unhashed(dentry))
22649 + a->udba = AuOpt_UDBA_NONE;
22650 + if (a->udba != AuOpt_UDBA_NONE) {
22651 + AuDebugOn(IS_ROOT(dentry));
22652 + err = au_reval_for_attr(dentry, au_sigen(sb));
22653 + if (unlikely(err))
22658 + err = au_pin_and_icpup(dentry, ia, a);
22659 + if (unlikely(err < 0))
22661 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22662 + ia->ia_file = NULL;
22663 + ia->ia_valid &= ~ATTR_FILE;
22666 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22667 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22668 + == (ATTR_MODE | ATTR_CTIME)) {
22669 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22670 + if (unlikely(err))
22672 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22673 + && (ia->ia_valid & ATTR_CTIME)) {
22674 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22675 + if (unlikely(err))
22679 + if (ia->ia_valid & ATTR_SIZE) {
22682 + if (ia->ia_size < i_size_read(inode))
22684 + truncate_setsize(inode, ia->ia_size);
22687 + if (ia->ia_valid & ATTR_FILE)
22689 + inode_unlock(a->h_inode);
22690 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22691 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22693 + delegated = NULL;
22695 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22697 + err = break_deleg_wait(&delegated);
22705 + * regardless aufs 'acl' option setting.
22706 + * why don't all acl-aware fs call this func from their ->setattr()?
22708 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22709 + h_userns = mnt_user_ns(a->h_path.mnt);
22710 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
22713 + au_cpup_attr_changeable(inode);
22716 + inode_unlock(a->h_inode);
22717 + au_unpin(&a->pin);
22718 + if (unlikely(err))
22719 + au_update_dbtop(dentry);
22721 + di_write_unlock(dentry);
22723 + fi_write_unlock(file);
22724 + ia->ia_file = file;
22725 + ia->ia_valid |= ATTR_FILE;
22728 + si_read_unlock(sb);
22736 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22737 +static int au_h_path_to_set_attr(struct dentry *dentry,
22738 + struct au_icpup_args *a, struct path *h_path)
22741 + struct super_block *sb;
22743 + sb = dentry->d_sb;
22744 + a->udba = au_opt_udba(sb);
22745 + /* no d_unlinked(), to set UDBA_NONE for root */
22746 + if (d_unhashed(dentry))
22747 + a->udba = AuOpt_UDBA_NONE;
22748 + if (a->udba != AuOpt_UDBA_NONE) {
22749 + AuDebugOn(IS_ROOT(dentry));
22750 + err = au_reval_for_attr(dentry, au_sigen(sb));
22751 + if (unlikely(err))
22754 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22755 + if (unlikely(err < 0))
22758 + h_path->dentry = a->h_path.dentry;
22759 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22765 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22766 + struct au_sxattr *arg)
22769 + struct path h_path;
22770 + struct super_block *sb;
22771 + struct au_icpup_args *a;
22772 + struct inode *h_inode;
22773 + struct user_namespace *h_userns;
22775 + IMustLock(inode);
22778 + a = kzalloc(sizeof(*a), GFP_NOFS);
22779 + if (unlikely(!a))
22782 + sb = dentry->d_sb;
22783 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22784 + if (unlikely(err))
22787 + h_path.dentry = NULL; /* silence gcc */
22788 + di_write_lock_child(dentry);
22789 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22790 + if (unlikely(err))
22792 + h_userns = mnt_user_ns(h_path.mnt);
22794 + inode_unlock(a->h_inode);
22795 + switch (arg->type) {
22796 + case AU_XATTR_SET:
22797 + AuDebugOn(d_is_negative(h_path.dentry));
22798 + err = vfsub_setxattr(h_userns, h_path.dentry,
22799 + arg->u.set.name, arg->u.set.value,
22800 + arg->u.set.size, arg->u.set.flags);
22803 + err = -EOPNOTSUPP;
22804 + h_inode = d_inode(h_path.dentry);
22805 + if (h_inode->i_op->set_acl) {
22806 + /* this will call posix_acl_update_mode */
22807 + err = h_inode->i_op->set_acl(h_userns, h_inode,
22808 + arg->u.acl_set.acl,
22809 + arg->u.acl_set.type);
22814 + au_cpup_attr_timesizes(inode);
22816 + au_unpin(&a->pin);
22817 + if (unlikely(err))
22818 + au_update_dbtop(dentry);
22821 + di_write_unlock(dentry);
22822 + si_read_unlock(sb);
22831 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22832 + unsigned int nlink)
22836 + inode->i_mode = st->mode;
22837 + /* don't i_[ug]id_write() here */
22838 + inode->i_uid = st->uid;
22839 + inode->i_gid = st->gid;
22840 + inode->i_atime = st->atime;
22841 + inode->i_mtime = st->mtime;
22842 + inode->i_ctime = st->ctime;
22844 + au_cpup_attr_nlink(inode, /*force*/0);
22845 + if (S_ISDIR(inode->i_mode)) {
22846 + n = inode->i_nlink;
22849 + smp_mb(); /* for i_nlink */
22850 + /* 0 can happen */
22851 + set_nlink(inode, n);
22854 + spin_lock(&inode->i_lock);
22855 + inode->i_blocks = st->blocks;
22856 + i_size_write(inode, st->size);
22857 + spin_unlock(&inode->i_lock);
22861 + * common routine for aufs_getattr() and au_getxattr().
22862 + * returns zero or negative (an error).
22863 + * @dentry will be read-locked in success.
22865 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22866 + struct path *h_path, int locked)
22869 + unsigned int mnt_flags, sigen;
22870 + unsigned char udba_none;
22871 + aufs_bindex_t bindex;
22872 + struct super_block *sb, *h_sb;
22874 + h_path->mnt = NULL;
22875 + h_path->dentry = NULL;
22878 + sb = dentry->d_sb;
22879 + mnt_flags = au_mntflags(sb);
22880 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22882 + if (unlikely(locked))
22883 + goto body; /* skip locking dinfo */
22885 + /* support fstat(2) */
22886 + if (!d_unlinked(dentry) && !udba_none) {
22887 + sigen = au_sigen(sb);
22888 + err = au_digen_test(dentry, sigen);
22890 + di_read_lock_child(dentry, AuLock_IR);
22891 + err = au_dbrange_test(dentry);
22892 + if (unlikely(err)) {
22893 + di_read_unlock(dentry, AuLock_IR);
22897 + AuDebugOn(IS_ROOT(dentry));
22898 + di_write_lock_child(dentry);
22899 + err = au_dbrange_test(dentry);
22901 + err = au_reval_for_attr(dentry, sigen);
22903 + di_downgrade_lock(dentry, AuLock_IR);
22905 + di_write_unlock(dentry);
22910 + di_read_lock_child(dentry, AuLock_IR);
22914 + inode = d_inode(dentry);
22915 + if (unlikely(!inode))
22918 + bindex = au_ibtop(inode);
22919 + h_path->mnt = au_sbr_mnt(sb, bindex);
22920 + h_sb = h_path->mnt->mnt_sb;
22922 + && !au_test_fs_bad_iattr(h_sb)
22924 + goto out; /* success */
22926 + if (au_dbtop(dentry) == bindex)
22927 + h_path->dentry = au_h_dptr(dentry, bindex);
22928 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22929 + h_path->dentry = au_plink_lkup(inode, bindex);
22930 + if (IS_ERR(h_path->dentry))
22931 + /* pretending success */
22932 + h_path->dentry = NULL;
22934 + dput(h_path->dentry);
22941 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
22942 + struct kstat *st, u32 request, unsigned int query)
22945 + unsigned char positive;
22946 + struct path h_path;
22947 + struct dentry *dentry;
22948 + struct inode *inode;
22949 + struct super_block *sb;
22951 + dentry = path->dentry;
22952 + inode = d_inode(dentry);
22953 + sb = dentry->d_sb;
22954 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22955 + if (unlikely(err))
22957 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
22959 + if (unlikely(err))
22961 + if (unlikely(!h_path.dentry))
22962 + /* illegally overlapped or something */
22963 + goto out_fill; /* pretending success */
22965 + positive = d_is_positive(h_path.dentry);
22967 + /* no vfsub version */
22968 + err = vfs_getattr(&h_path, st, request, query);
22971 + au_refresh_iattr(inode, st,
22972 + d_inode(h_path.dentry)->i_nlink);
22973 + goto out_fill; /* success */
22979 + generic_fillattr(userns, inode, st);
22981 + di_read_unlock(dentry, AuLock_IR);
22983 + si_read_unlock(sb);
22989 +/* ---------------------------------------------------------------------- */
22991 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
22992 + struct delayed_call *done)
22995 + struct dentry *h_dentry;
22996 + struct inode *h_inode;
22998 + aufs_bindex_t bindex;
23000 + ret = NULL; /* suppress a warning */
23005 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23006 + if (unlikely(err))
23009 + err = au_d_hashed_positive(dentry);
23010 + if (unlikely(err))
23014 + inode = d_inode(dentry);
23015 + bindex = au_ibtop(inode);
23016 + h_inode = au_h_iptr(inode, bindex);
23017 + if (unlikely(!h_inode->i_op->get_link))
23022 + if (au_dbtop(dentry) <= bindex) {
23023 + h_dentry = au_h_dptr(dentry, bindex);
23028 + h_dentry = d_find_any_alias(h_inode);
23029 + if (IS_ERR(h_dentry)) {
23030 + err = PTR_ERR(h_dentry);
23034 + if (unlikely(!h_dentry))
23038 + AuDbg("%ps\n", h_inode->i_op->get_link);
23039 + AuDbgDentry(h_dentry);
23040 + ret = vfs_get_link(h_dentry, done);
23043 + err = PTR_ERR(ret);
23046 + aufs_read_unlock(dentry, AuLock_IR);
23048 + if (unlikely(err))
23049 + ret = ERR_PTR(err);
23050 + AuTraceErrPtr(ret);
23054 +/* ---------------------------------------------------------------------- */
23056 +static int au_is_special(struct inode *inode)
23058 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23061 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
23065 + aufs_bindex_t bindex;
23066 + struct super_block *sb;
23067 + struct inode *h_inode;
23068 + struct vfsmount *h_mnt;
23070 + sb = inode->i_sb;
23071 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23072 + "unexpected s_flags 0x%lx", sb->s_flags);
23074 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23076 + si_read_lock(sb, AuLock_FLUSH);
23077 + ii_write_lock_child(inode);
23080 + bindex = au_ibtop(inode);
23081 + h_inode = au_h_iptr(inode, bindex);
23082 + if (!au_test_ro(sb, bindex, inode)) {
23083 + h_mnt = au_sbr_mnt(sb, bindex);
23084 + err = vfsub_mnt_want_write(h_mnt);
23086 + err = vfsub_update_time(h_inode, ts, flags);
23087 + vfsub_mnt_drop_write(h_mnt);
23089 + } else if (au_is_special(h_inode)) {
23091 + * Never copy-up here.
23092 + * These special files may already be opened and used for
23093 + * communicating. If we copied it up, then the communication
23094 + * would be corrupted.
23096 + AuWarn1("timestamps for i%lu are ignored "
23097 + "since it is on readonly branch (hi%lu).\n",
23098 + inode->i_ino, h_inode->i_ino);
23099 + } else if (flags & ~S_ATIME) {
23101 + AuIOErr1("unexpected flags 0x%x\n", flags);
23106 + au_cpup_attr_timesizes(inode);
23107 + ii_write_unlock(inode);
23108 + si_read_unlock(sb);
23111 + if (!err && (flags & S_VERSION))
23112 + inode_inc_iversion(inode);
23117 +/* ---------------------------------------------------------------------- */
23119 +/* no getattr version will be set by module.c:aufs_init() */
23120 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23122 + [AuIop_SYMLINK] = {
23123 + .permission = aufs_permission,
23124 +#ifdef CONFIG_FS_POSIX_ACL
23125 + .get_acl = aufs_get_acl,
23126 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23129 + .setattr = aufs_setattr,
23130 + .getattr = aufs_getattr,
23132 +#ifdef CONFIG_AUFS_XATTR
23133 + .listxattr = aufs_listxattr,
23136 + .get_link = aufs_get_link,
23138 + /* .update_time = aufs_update_time */
23141 + .create = aufs_create,
23142 + .lookup = aufs_lookup,
23143 + .link = aufs_link,
23144 + .unlink = aufs_unlink,
23145 + .symlink = aufs_symlink,
23146 + .mkdir = aufs_mkdir,
23147 + .rmdir = aufs_rmdir,
23148 + .mknod = aufs_mknod,
23149 + .rename = aufs_rename,
23151 + .permission = aufs_permission,
23152 +#ifdef CONFIG_FS_POSIX_ACL
23153 + .get_acl = aufs_get_acl,
23154 + .set_acl = aufs_set_acl,
23157 + .setattr = aufs_setattr,
23158 + .getattr = aufs_getattr,
23160 +#ifdef CONFIG_AUFS_XATTR
23161 + .listxattr = aufs_listxattr,
23164 + .update_time = aufs_update_time,
23165 + .atomic_open = aufs_atomic_open,
23166 + .tmpfile = aufs_tmpfile
23168 + [AuIop_OTHER] = {
23169 + .permission = aufs_permission,
23170 +#ifdef CONFIG_FS_POSIX_ACL
23171 + .get_acl = aufs_get_acl,
23172 + .set_acl = aufs_set_acl,
23175 + .setattr = aufs_setattr,
23176 + .getattr = aufs_getattr,
23178 +#ifdef CONFIG_AUFS_XATTR
23179 + .listxattr = aufs_listxattr,
23182 + .update_time = aufs_update_time
23185 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23186 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23187 +++ linux/fs/aufs/i_op_del.c 2022-03-21 14:49:05.726633010 +0100
23189 +// SPDX-License-Identifier: GPL-2.0
23191 + * Copyright (C) 2005-2021 Junjiro R. Okajima
23193 + * This program, aufs is free software; you can redistribute it and/or modify
23194 + * it under the terms of the GNU General Public License as published by
23195 + * the Free Software Foundation; either version 2 of the License, or
23196 + * (at your option) any later version.
23198 + * This program is distributed in the hope that it will be useful,
23199 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23201 + * GNU General Public License for more details.
23203 + * You should have received a copy of the GNU General Public License
23204 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23208 + * inode operations (del entry)
23211 +#include <linux/iversion.h>
23215 + * decide if a new whiteout for @dentry is necessary or not.
23216 + * when it is necessary, prepare the parent dir for the upper branch whose
23217 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23218 + * be done by caller.
23220 + * 0: wh is unnecessary
23221 + * plus: wh is necessary
23224 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23226 + int need_wh, err;
23227 + aufs_bindex_t btop;
23228 + struct super_block *sb;
23230 + sb = dentry->d_sb;
23231 + btop = au_dbtop(dentry);
23232 + if (*bcpup < 0) {
23234 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23235 + err = AuWbrCopyup(au_sbi(sb), dentry);
23237 + if (unlikely(err < 0))
23241 + AuDebugOn(btop < *bcpup
23242 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23243 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23245 + if (*bcpup != btop) {
23246 + err = au_cpup_dirs(dentry, *bcpup);
23247 + if (unlikely(err))
23251 + struct au_dinfo *dinfo, *tmp;
23253 + need_wh = -ENOMEM;
23254 + dinfo = au_di(dentry);
23255 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23257 + au_di_cp(tmp, dinfo);
23258 + au_di_swap(tmp, dinfo);
23259 + /* returns the number of positive dentries */
23260 + need_wh = au_lkup_dentry(dentry, btop + 1,
23261 + /* AuLkup_IGNORE_PERM */ 0);
23262 + au_di_swap(tmp, dinfo);
23263 + au_rw_write_unlock(&tmp->di_rwsem);
23267 + AuDbg("need_wh %d\n", need_wh);
23275 + * simple tests for the del-entry operations.
23276 + * following the checks in vfs, plus the parent-child relationship.
23278 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23279 + struct dentry *h_parent, int isdir)
23283 + struct dentry *h_dentry, *h_latest;
23284 + struct inode *h_inode;
23285 + struct path h_ppath;
23286 + struct super_block *sb;
23287 + struct au_branch *br;
23288 + struct user_namespace *h_userns;
23290 + h_dentry = au_h_dptr(dentry, bindex);
23291 + if (d_really_is_positive(dentry)) {
23293 + if (unlikely(d_is_negative(h_dentry)))
23295 + h_inode = d_inode(h_dentry);
23296 + if (unlikely(!h_inode->i_nlink))
23299 + h_mode = h_inode->i_mode;
23302 + if (unlikely(S_ISDIR(h_mode)))
23304 + } else if (unlikely(!S_ISDIR(h_mode))) {
23309 + /* rename(2) case */
23311 + if (unlikely(d_is_positive(h_dentry)))
23316 + /* expected parent dir is locked */
23317 + if (unlikely(h_parent != h_dentry->d_parent))
23322 + * rmdir a dir may break the consistency on some filesystem.
23323 + * let's try heavy test.
23326 + sb = dentry->d_sb;
23327 + br = au_sbr(sb, bindex);
23328 + h_userns = au_br_userns(br);
23329 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23330 + && au_test_h_perm(h_userns, d_inode(h_parent),
23331 + MAY_EXEC | MAY_WRITE)))
23334 + h_ppath.dentry = h_parent;
23335 + h_ppath.mnt = au_br_mnt(br);
23336 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
23338 + if (IS_ERR(h_latest))
23340 + if (h_latest == h_dentry)
23349 + * decide the branch where we operate for @dentry. the branch index will be set
23350 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23351 + * dir for reverting.
23352 + * when a new whiteout is necessary, create it.
23354 +static struct dentry*
23355 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23356 + struct au_dtime *dt, struct au_pin *pin)
23358 + struct dentry *wh_dentry;
23359 + struct super_block *sb;
23360 + struct path h_path;
23361 + int err, need_wh;
23362 + unsigned int udba;
23363 + aufs_bindex_t bcpup;
23365 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23366 + wh_dentry = ERR_PTR(need_wh);
23367 + if (unlikely(need_wh < 0))
23370 + sb = dentry->d_sb;
23371 + udba = au_opt_udba(sb);
23373 + err = au_pin(pin, dentry, bcpup, udba,
23374 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23375 + wh_dentry = ERR_PTR(err);
23376 + if (unlikely(err))
23379 + h_path.dentry = au_pinned_h_parent(pin);
23380 + if (udba != AuOpt_UDBA_NONE
23381 + && au_dbtop(dentry) == bcpup) {
23382 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23383 + wh_dentry = ERR_PTR(err);
23384 + if (unlikely(err))
23388 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23389 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23390 + wh_dentry = NULL;
23392 + goto out; /* success, no need to create whiteout */
23394 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23395 + if (IS_ERR(wh_dentry))
23398 + /* returns with the parent is locked and wh_dentry is dget-ed */
23399 + goto out; /* success */
23404 + return wh_dentry;
23408 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23409 + * in order to be revertible and save time for removing many child whiteouts
23411 + * returns 1 when there are too many child whiteout and caller should remove
23412 + * them asynchronously. returns 0 when the number of children is enough small to
23413 + * remove now or the branch fs is a remote fs.
23414 + * otherwise return an error.
23416 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23417 + struct au_nhash *whlist, struct inode *dir)
23419 + int rmdir_later, err, dirwh;
23420 + struct dentry *h_dentry;
23421 + struct super_block *sb;
23422 + struct inode *inode;
23424 + sb = dentry->d_sb;
23425 + SiMustAnyLock(sb);
23426 + h_dentry = au_h_dptr(dentry, bindex);
23427 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23428 + if (unlikely(err))
23431 + /* stop monitoring */
23432 + inode = d_inode(dentry);
23433 + au_hn_free(au_hi(inode, bindex));
23435 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23436 + dirwh = au_sbi(sb)->si_dirwh;
23437 + rmdir_later = (dirwh <= 1);
23438 + if (!rmdir_later)
23439 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23442 + return rmdir_later;
23445 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23446 + if (unlikely(err)) {
23447 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23448 + h_dentry, bindex, err);
23458 + * final procedure for deleting a entry.
23459 + * maintain dentry and iattr.
23461 +static void epilog(struct inode *dir, struct dentry *dentry,
23462 + aufs_bindex_t bindex)
23464 + struct inode *inode;
23466 + inode = d_inode(dentry);
23468 + inode->i_ctime = dir->i_ctime;
23470 + au_dir_ts(dir, bindex);
23471 + inode_inc_iversion(dir);
23475 + * when an error happened, remove the created whiteout and revert everything.
23477 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23478 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23479 + struct dentry *dentry, struct au_dtime *dt)
23482 + struct path h_path = {
23483 + .dentry = wh_dentry,
23484 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23487 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23489 + au_set_dbwh(dentry, bwh);
23490 + au_dtime_revert(dt);
23494 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23498 +/* ---------------------------------------------------------------------- */
23500 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23503 + aufs_bindex_t bwh, bindex, btop;
23504 + struct inode *inode, *h_dir, *delegated;
23505 + struct dentry *parent, *wh_dentry;
23506 + /* to reduce stack size */
23508 + struct au_dtime dt;
23509 + struct au_pin pin;
23510 + struct path h_path;
23516 + a = kmalloc(sizeof(*a), GFP_NOFS);
23517 + if (unlikely(!a))
23520 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23521 + if (unlikely(err))
23523 + err = au_d_hashed_positive(dentry);
23524 + if (unlikely(err))
23526 + inode = d_inode(dentry);
23527 + IMustLock(inode);
23529 + if (unlikely(d_is_dir(dentry)))
23530 + goto out_unlock; /* possible? */
23532 + btop = au_dbtop(dentry);
23533 + bwh = au_dbwh(dentry);
23535 + parent = dentry->d_parent; /* dir inode is locked */
23536 + di_write_lock_parent(parent);
23537 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23539 + err = PTR_ERR(wh_dentry);
23540 + if (IS_ERR(wh_dentry))
23543 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23544 + a->h_path.dentry = au_h_dptr(dentry, btop);
23545 + dget(a->h_path.dentry);
23546 + if (bindex == btop) {
23547 + h_dir = au_pinned_h_dir(&a->pin);
23548 + delegated = NULL;
23549 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23550 + if (unlikely(err == -EWOULDBLOCK)) {
23551 + pr_warn("cannot retry for NFSv4 delegation"
23552 + " for an internal unlink\n");
23556 + /* dir inode is locked */
23557 + h_dir = d_inode(wh_dentry->d_parent);
23558 + IMustLock(h_dir);
23563 + vfsub_drop_nlink(inode);
23564 + epilog(dir, dentry, bindex);
23566 + /* update target timestamps */
23567 + if (bindex == btop) {
23568 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23570 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23572 + /* todo: this timestamp may be reverted later */
23573 + inode->i_ctime = h_dir->i_ctime;
23574 + goto out_unpin; /* success */
23581 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23588 + au_unpin(&a->pin);
23590 + dput(a->h_path.dentry);
23592 + di_write_unlock(parent);
23594 + aufs_read_unlock(dentry, AuLock_DW);
23601 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23603 + int err, rmdir_later;
23604 + aufs_bindex_t bwh, bindex, btop;
23605 + struct inode *inode;
23606 + struct dentry *parent, *wh_dentry, *h_dentry;
23607 + struct au_whtmp_rmdir *args;
23608 + /* to reduce stack size */
23610 + struct au_dtime dt;
23611 + struct au_pin pin;
23617 + a = kmalloc(sizeof(*a), GFP_NOFS);
23618 + if (unlikely(!a))
23621 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23622 + if (unlikely(err))
23624 + err = au_alive_dir(dentry);
23625 + if (unlikely(err))
23627 + inode = d_inode(dentry);
23628 + IMustLock(inode);
23630 + if (unlikely(!d_is_dir(dentry)))
23631 + goto out_unlock; /* possible? */
23634 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23635 + if (unlikely(!args))
23638 + parent = dentry->d_parent; /* dir inode is locked */
23639 + di_write_lock_parent(parent);
23640 + err = au_test_empty(dentry, &args->whlist);
23641 + if (unlikely(err))
23644 + btop = au_dbtop(dentry);
23645 + bwh = au_dbwh(dentry);
23647 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23649 + err = PTR_ERR(wh_dentry);
23650 + if (IS_ERR(wh_dentry))
23653 + h_dentry = au_h_dptr(dentry, btop);
23656 + if (bindex == btop) {
23657 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23659 + rmdir_later = err;
23663 + /* stop monitoring */
23664 + au_hn_free(au_hi(inode, btop));
23666 + /* dir inode is locked */
23667 + IMustLock(d_inode(wh_dentry->d_parent));
23672 + vfsub_dead_dir(inode);
23673 + au_set_dbdiropq(dentry, -1);
23674 + epilog(dir, dentry, bindex);
23676 + if (rmdir_later) {
23677 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23681 + goto out_unpin; /* success */
23689 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23696 + au_unpin(&a->pin);
23700 + di_write_unlock(parent);
23702 + au_whtmp_rmdir_free(args);
23704 + aufs_read_unlock(dentry, AuLock_DW);
23711 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23712 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23713 +++ linux/fs/aufs/i_op_ren.c 2022-03-21 14:49:05.726633010 +0100
23715 +// SPDX-License-Identifier: GPL-2.0
23717 + * Copyright (C) 2005-2021 Junjiro R. Okajima
23719 + * This program, aufs is free software; you can redistribute it and/or modify
23720 + * it under the terms of the GNU General Public License as published by
23721 + * the Free Software Foundation; either version 2 of the License, or
23722 + * (at your option) any later version.
23724 + * This program is distributed in the hope that it will be useful,
23725 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23726 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23727 + * GNU General Public License for more details.
23729 + * You should have received a copy of the GNU General Public License
23730 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23734 + * inode operation (rename entry)
23735 + * todo: this is crazy monster
23738 +#include <linux/iversion.h>
23741 +enum { AuSRC, AuDST, AuSrcDst };
23742 +enum { AuPARENT, AuCHILD, AuParentChild };
23744 +#define AuRen_ISDIR_SRC 1
23745 +#define AuRen_ISDIR_DST (1 << 1)
23746 +#define AuRen_ISSAMEDIR (1 << 2)
23747 +#define AuRen_WHSRC (1 << 3)
23748 +#define AuRen_WHDST (1 << 4)
23749 +#define AuRen_MNT_WRITE (1 << 5)
23750 +#define AuRen_DT_DSTDIR (1 << 6)
23751 +#define AuRen_DIROPQ_SRC (1 << 7)
23752 +#define AuRen_DIROPQ_DST (1 << 8)
23753 +#define AuRen_DIRREN (1 << 9)
23754 +#define AuRen_DROPPED_SRC (1 << 10)
23755 +#define AuRen_DROPPED_DST (1 << 11)
23756 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23757 +#define au_fset_ren(flags, name) \
23758 + do { (flags) |= AuRen_##name; } while (0)
23759 +#define au_fclr_ren(flags, name) \
23760 + do { (flags) &= ~AuRen_##name; } while (0)
23762 +#ifndef CONFIG_AUFS_DIRREN
23763 +#undef AuRen_DIRREN
23764 +#define AuRen_DIRREN 0
23767 +struct au_ren_args {
23769 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23771 + struct inode *dir, *inode;
23772 + struct au_hinode *hdir, *hinode;
23773 + struct au_dtime dt[AuParentChild];
23774 + aufs_bindex_t btop, bdiropq;
23777 +#define src_dentry sd[AuSRC].dentry
23778 +#define src_dir sd[AuSRC].dir
23779 +#define src_inode sd[AuSRC].inode
23780 +#define src_h_dentry sd[AuSRC].h_dentry
23781 +#define src_parent sd[AuSRC].parent
23782 +#define src_h_parent sd[AuSRC].h_parent
23783 +#define src_wh_dentry sd[AuSRC].wh_dentry
23784 +#define src_hdir sd[AuSRC].hdir
23785 +#define src_hinode sd[AuSRC].hinode
23786 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23787 +#define src_dt sd[AuSRC].dt
23788 +#define src_btop sd[AuSRC].btop
23789 +#define src_bdiropq sd[AuSRC].bdiropq
23791 +#define dst_dentry sd[AuDST].dentry
23792 +#define dst_dir sd[AuDST].dir
23793 +#define dst_inode sd[AuDST].inode
23794 +#define dst_h_dentry sd[AuDST].h_dentry
23795 +#define dst_parent sd[AuDST].parent
23796 +#define dst_h_parent sd[AuDST].h_parent
23797 +#define dst_wh_dentry sd[AuDST].wh_dentry
23798 +#define dst_hdir sd[AuDST].hdir
23799 +#define dst_hinode sd[AuDST].hinode
23800 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23801 +#define dst_dt sd[AuDST].dt
23802 +#define dst_btop sd[AuDST].btop
23803 +#define dst_bdiropq sd[AuDST].bdiropq
23805 + struct dentry *h_trap;
23806 + struct au_branch *br;
23807 + struct path h_path;
23808 + struct au_nhash whlist;
23809 + aufs_bindex_t btgt, src_bwh;
23812 + unsigned short auren_flags;
23813 + unsigned char flags; /* syscall parameter */
23814 + unsigned char exchange;
23817 + struct au_whtmp_rmdir *thargs;
23818 + struct dentry *h_dst;
23819 + struct au_hinode *h_root;
23822 +/* ---------------------------------------------------------------------- */
23825 + * functions for reverting.
23826 + * when an error happened in a single rename systemcall, we should revert
23827 + * everything as if nothing happened.
23828 + * we don't need to revert the copied-up/down the parent dir since they are
23832 +#define RevertFailure(fmt, ...) do { \
23833 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23834 + ##__VA_ARGS__, err, rerr); \
23838 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23841 + struct dentry *d;
23842 +#define src_or_dst(member) a->sd[idx].member
23844 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23845 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23846 + rerr = au_diropq_remove(d, a->btgt);
23847 + au_hn_inode_unlock(src_or_dst(hinode));
23848 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23850 + RevertFailure("remove diropq %pd", d);
23852 +#undef src_or_dst_
23855 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23857 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23858 + au_ren_do_rev_diropq(err, a, AuSRC);
23859 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23860 + au_ren_do_rev_diropq(err, a, AuDST);
23863 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23866 + struct inode *delegated;
23867 + struct path h_ppath = {
23868 + .dentry = a->src_h_parent,
23869 + .mnt = a->h_path.mnt
23872 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23873 + rerr = PTR_ERR(a->h_path.dentry);
23874 + if (IS_ERR(a->h_path.dentry)) {
23875 + RevertFailure("lkup one %pd", a->src_dentry);
23879 + delegated = NULL;
23880 + rerr = vfsub_rename(a->dst_h_dir,
23881 + au_h_dptr(a->src_dentry, a->btgt),
23882 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23883 + if (unlikely(rerr == -EWOULDBLOCK)) {
23884 + pr_warn("cannot retry for NFSv4 delegation"
23885 + " for an internal rename\n");
23888 + d_drop(a->h_path.dentry);
23889 + dput(a->h_path.dentry);
23890 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23892 + RevertFailure("rename %pd", a->src_dentry);
23895 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23898 + struct inode *delegated;
23899 + struct path h_ppath = {
23900 + .dentry = a->dst_h_parent,
23901 + .mnt = a->h_path.mnt
23904 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23905 + rerr = PTR_ERR(a->h_path.dentry);
23906 + if (IS_ERR(a->h_path.dentry)) {
23907 + RevertFailure("lkup one %pd", a->dst_dentry);
23910 + if (d_is_positive(a->h_path.dentry)) {
23911 + d_drop(a->h_path.dentry);
23912 + dput(a->h_path.dentry);
23916 + delegated = NULL;
23917 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23918 + &delegated, a->flags);
23919 + if (unlikely(rerr == -EWOULDBLOCK)) {
23920 + pr_warn("cannot retry for NFSv4 delegation"
23921 + " for an internal rename\n");
23924 + d_drop(a->h_path.dentry);
23925 + dput(a->h_path.dentry);
23927 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23929 + RevertFailure("rename %pd", a->h_dst);
23932 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23936 + a->h_path.dentry = a->src_wh_dentry;
23937 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23938 + au_set_dbwh(a->src_dentry, a->src_bwh);
23940 + RevertFailure("unlink %pd", a->src_wh_dentry);
23942 +#undef RevertFailure
23944 +/* ---------------------------------------------------------------------- */
23947 + * when we have to copyup the renaming entry, do it with the rename-target name
23948 + * in order to minimize the cost (the later actual rename is unnecessary).
23949 + * otherwise rename it on the target branch.
23951 +static int au_ren_or_cpup(struct au_ren_args *a)
23954 + struct dentry *d;
23955 + struct inode *delegated;
23957 + d = a->src_dentry;
23958 + if (au_dbtop(d) == a->btgt) {
23959 + a->h_path.dentry = a->dst_h_dentry;
23960 + AuDebugOn(au_dbtop(d) != a->btgt);
23961 + delegated = NULL;
23962 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
23963 + a->dst_h_dir, &a->h_path, &delegated,
23965 + if (unlikely(err == -EWOULDBLOCK)) {
23966 + pr_warn("cannot retry for NFSv4 delegation"
23967 + " for an internal rename\n");
23973 + if (!err && a->h_dst)
23974 + /* it will be set to dinfo later */
23980 +/* cf. aufs_rmdir() */
23981 +static int au_ren_del_whtmp(struct au_ren_args *a)
23984 + struct inode *dir;
23986 + dir = a->dst_dir;
23987 + SiMustAnyLock(dir->i_sb);
23988 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
23989 + au_sbi(dir->i_sb)->si_dirwh)
23990 + || au_test_fs_remote(a->h_dst->d_sb)) {
23991 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
23992 + if (unlikely(err))
23993 + pr_warn("failed removing whtmp dir %pd (%d), "
23994 + "ignored.\n", a->h_dst, err);
23996 + au_nhash_wh_free(&a->thargs->whlist);
23997 + a->thargs->whlist = a->whlist;
23998 + a->whlist.nh_num = 0;
23999 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24001 + a->thargs = NULL;
24007 +/* make it 'opaque' dir. */
24008 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24011 + struct dentry *d, *diropq;
24012 +#define src_or_dst(member) a->sd[idx].member
24015 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24016 + src_or_dst(bdiropq) = au_dbdiropq(d);
24017 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24018 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24019 + diropq = au_diropq_create(d, a->btgt);
24020 + au_hn_inode_unlock(src_or_dst(hinode));
24021 + if (IS_ERR(diropq))
24022 + err = PTR_ERR(diropq);
24026 +#undef src_or_dst_
24030 +static int au_ren_diropq(struct au_ren_args *a)
24033 + unsigned char always;
24034 + struct dentry *d;
24037 + d = a->dst_dentry; /* already renamed on the branch */
24038 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24039 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24040 + && !au_ftest_ren(a->auren_flags, DIRREN)
24041 + && a->btgt != au_dbdiropq(a->src_dentry)
24042 + && (a->dst_wh_dentry
24043 + || a->btgt <= au_dbdiropq(d)
24044 + /* hide the lower to keep xino */
24045 + /* the lowers may not be a dir, but we hide them anyway */
24046 + || a->btgt < au_dbbot(d)
24049 + err = au_ren_do_diropq(a, AuSRC);
24050 + if (unlikely(err))
24052 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24054 + if (!a->exchange)
24055 + goto out; /* success */
24057 + d = a->src_dentry; /* already renamed on the branch */
24058 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24059 + && a->btgt != au_dbdiropq(a->dst_dentry)
24060 + && (a->btgt < au_dbdiropq(d)
24061 + || a->btgt < au_dbbot(d)
24063 + AuDbgDentry(a->src_dentry);
24064 + AuDbgDentry(a->dst_dentry);
24065 + err = au_ren_do_diropq(a, AuDST);
24066 + if (unlikely(err))
24067 + goto out_rev_src;
24068 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24070 + goto out; /* success */
24073 + AuDbg("err %d, reverting src\n", err);
24074 + au_ren_rev_diropq(err, a);
24079 +static int do_rename(struct au_ren_args *a)
24082 + struct dentry *d, *h_d;
24084 + if (!a->exchange) {
24085 + /* prepare workqueue args for asynchronous rmdir */
24086 + h_d = a->dst_h_dentry;
24087 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24088 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24089 + && d_is_positive(h_d)) {
24091 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24093 + if (unlikely(!a->thargs))
24095 + a->h_dst = dget(h_d);
24098 + /* create whiteout for src_dentry */
24099 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24100 + a->src_bwh = au_dbwh(a->src_dentry);
24101 + AuDebugOn(a->src_bwh >= 0);
24102 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24103 + a->src_h_parent);
24104 + err = PTR_ERR(a->src_wh_dentry);
24105 + if (IS_ERR(a->src_wh_dentry))
24109 + /* lookup whiteout for dentry */
24110 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24111 + h_d = au_wh_lkup(a->dst_h_parent,
24112 + &a->dst_dentry->d_name, a->br);
24113 + err = PTR_ERR(h_d);
24116 + if (d_is_negative(h_d))
24119 + a->dst_wh_dentry = h_d;
24122 + /* rename dentry to tmpwh */
24124 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24125 + if (unlikely(err))
24128 + d = a->dst_dentry;
24129 + au_set_h_dptr(d, a->btgt, NULL);
24130 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24131 + if (unlikely(err))
24133 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24137 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24138 +#if 0 /* debugging */
24139 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24140 + && d_is_positive(a->dst_h_dentry)
24141 + && a->src_btop != a->btgt);
24144 + /* rename by vfs_rename or cpup */
24145 + err = au_ren_or_cpup(a);
24146 + if (unlikely(err))
24147 + /* leave the copied-up one */
24150 + /* make dir opaque */
24151 + err = au_ren_diropq(a);
24152 + if (unlikely(err))
24155 + /* update target timestamps */
24156 + if (a->exchange) {
24157 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24158 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24159 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24160 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24162 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24163 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24164 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24165 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24167 + if (!a->exchange) {
24168 + /* remove whiteout for dentry */
24169 + if (a->dst_wh_dentry) {
24170 + a->h_path.dentry = a->dst_wh_dentry;
24171 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24173 + if (unlikely(err))
24177 + /* remove whtmp */
24179 + au_ren_del_whtmp(a); /* ignore this error */
24181 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24184 + goto out_success;
24187 + au_ren_rev_diropq(err, a);
24189 + au_ren_rev_rename(err, a);
24193 + au_ren_rev_whtmp(err, a);
24195 + dput(a->dst_wh_dentry);
24196 + a->dst_wh_dentry = NULL;
24198 + if (a->src_wh_dentry)
24199 + au_ren_rev_whsrc(err, a);
24201 + dput(a->src_wh_dentry);
24202 + dput(a->dst_wh_dentry);
24206 + au_whtmp_rmdir_free(a->thargs);
24207 + a->thargs = NULL;
24213 +/* ---------------------------------------------------------------------- */
24216 + * test if @dentry dir can be rename destination or not.
24217 + * success means, it is a logically empty dir.
24219 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24221 + return au_test_empty(dentry, whlist);
24225 + * test if @a->src_dentry dir can be rename source or not.
24226 + * if it can, return 0.
24228 + * - it is a logically empty dir.
24229 + * - or, it exists on writable branch and has no children including whiteouts
24230 + * on the lower branch unless DIRREN is on.
24232 +static int may_rename_srcdir(struct au_ren_args *a)
24235 + unsigned int rdhash;
24236 + aufs_bindex_t btop, btgt;
24237 + struct dentry *dentry;
24238 + struct super_block *sb;
24239 + struct au_sbinfo *sbinfo;
24241 + dentry = a->src_dentry;
24242 + sb = dentry->d_sb;
24243 + sbinfo = au_sbi(sb);
24244 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24245 + au_fset_ren(a->auren_flags, DIRREN);
24248 + btop = au_dbtop(dentry);
24249 + if (btop != btgt) {
24250 + struct au_nhash whlist;
24252 + SiMustAnyLock(sb);
24253 + rdhash = sbinfo->si_rdhash;
24255 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24257 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24258 + if (unlikely(err))
24260 + err = au_test_empty(dentry, &whlist);
24261 + au_nhash_wh_free(&whlist);
24265 + if (btop == au_dbtaildir(dentry))
24266 + return 0; /* success */
24268 + err = au_test_empty_lower(dentry);
24271 + if (err == -ENOTEMPTY) {
24272 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24275 + AuWarn1("renaming dir who has child(ren) on multiple "
24276 + "branches, is not supported\n");
24283 +/* side effect: sets whlist and h_dentry */
24284 +static int au_ren_may_dir(struct au_ren_args *a)
24287 + unsigned int rdhash;
24288 + struct dentry *d;
24290 + d = a->dst_dentry;
24291 + SiMustAnyLock(d->d_sb);
24294 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24295 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24297 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24298 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24299 + if (unlikely(err))
24302 + if (!a->exchange) {
24303 + au_set_dbtop(d, a->dst_btop);
24304 + err = may_rename_dstdir(d, &a->whlist);
24305 + au_set_dbtop(d, a->btgt);
24307 + err = may_rename_srcdir(a);
24309 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24310 + if (unlikely(err))
24313 + d = a->src_dentry;
24314 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24315 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24316 + err = may_rename_srcdir(a);
24317 + if (unlikely(err)) {
24318 + au_nhash_wh_free(&a->whlist);
24319 + a->whlist.nh_num = 0;
24326 +/* ---------------------------------------------------------------------- */
24329 + * simple tests for rename.
24330 + * following the checks in vfs, plus the parent-child relationship.
24332 +static int au_may_ren(struct au_ren_args *a)
24335 + struct inode *h_inode;
24337 + if (a->src_btop == a->btgt) {
24338 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24339 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24340 + if (unlikely(err))
24343 + if (unlikely(a->src_h_dentry == a->h_trap))
24348 + if (a->dst_btop != a->btgt)
24351 + err = -ENOTEMPTY;
24352 + if (unlikely(a->dst_h_dentry == a->h_trap))
24356 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24357 + if (d_really_is_negative(a->dst_dentry)) {
24358 + if (d_is_negative(a->dst_h_dentry))
24359 + err = au_may_add(a->dst_dentry, a->btgt,
24360 + a->dst_h_parent, isdir);
24362 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24364 + h_inode = d_inode(a->dst_h_dentry);
24365 + if (h_inode->i_nlink)
24366 + err = au_may_del(a->dst_dentry, a->btgt,
24367 + a->dst_h_parent, isdir);
24371 + if (unlikely(err == -ENOENT || err == -EEXIST))
24377 +/* ---------------------------------------------------------------------- */
24382 + * - src_dir and dir by lock_rename()
24383 + * - inode if exists
24386 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24388 + * + di_write_lock2_child()
24389 + * + di_write_lock_child()
24390 + * + ii_write_lock_child()
24391 + * + di_write_lock_child2()
24392 + * + ii_write_lock_child2()
24393 + * + src_parent and parent
24394 + * + di_write_lock_parent()
24395 + * + ii_write_lock_parent()
24396 + * + di_write_lock_parent2()
24397 + * + ii_write_lock_parent2()
24398 + * + lower src_dir and dir by vfsub_lock_rename()
24399 + * + verify the every relationships between child and parent. if any
24400 + * of them failed, unlock all and return -EBUSY.
24402 +static void au_ren_unlock(struct au_ren_args *a)
24404 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24405 + a->dst_h_parent, a->dst_hdir);
24406 + if (au_ftest_ren(a->auren_flags, DIRREN)
24408 + au_hn_inode_unlock(a->h_root);
24409 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24410 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24413 +static int au_ren_lock(struct au_ren_args *a)
24416 + unsigned int udba;
24419 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24420 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24421 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24422 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24424 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24425 + if (unlikely(err))
24427 + au_fset_ren(a->auren_flags, MNT_WRITE);
24428 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24429 + struct dentry *root;
24430 + struct inode *dir;
24433 + * sbinfo is already locked, so this ii_read_lock is
24434 + * unnecessary. but our debugging feature checks it.
24436 + root = a->src_inode->i_sb->s_root;
24437 + if (root != a->src_parent && root != a->dst_parent) {
24438 + dir = d_inode(root);
24439 + ii_read_lock_parent3(dir);
24440 + a->h_root = au_hi(dir, a->btgt);
24441 + ii_read_unlock(dir);
24442 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24445 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24446 + a->dst_h_parent, a->dst_hdir);
24447 + udba = au_opt_udba(a->src_dentry->d_sb);
24448 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24449 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24450 + err = au_busy_or_stale();
24451 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24452 + err = au_h_verify(a->src_h_dentry, udba,
24453 + d_inode(a->src_h_parent), a->src_h_parent,
24455 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24456 + err = au_h_verify(a->dst_h_dentry, udba,
24457 + d_inode(a->dst_h_parent), a->dst_h_parent,
24460 + goto out; /* success */
24462 + err = au_busy_or_stale();
24463 + au_ren_unlock(a);
24469 +/* ---------------------------------------------------------------------- */
24471 +static void au_ren_refresh_dir(struct au_ren_args *a)
24473 + struct inode *dir;
24475 + dir = a->dst_dir;
24476 + inode_inc_iversion(dir);
24477 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24478 + /* is this updating defined in POSIX? */
24479 + au_cpup_attr_timesizes(a->src_inode);
24480 + au_cpup_attr_nlink(dir, /*force*/1);
24482 + au_dir_ts(dir, a->btgt);
24484 + if (a->exchange) {
24485 + dir = a->src_dir;
24486 + inode_inc_iversion(dir);
24487 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24488 + /* is this updating defined in POSIX? */
24489 + au_cpup_attr_timesizes(a->dst_inode);
24490 + au_cpup_attr_nlink(dir, /*force*/1);
24492 + au_dir_ts(dir, a->btgt);
24495 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24498 + dir = a->src_dir;
24499 + inode_inc_iversion(dir);
24500 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24501 + au_cpup_attr_nlink(dir, /*force*/1);
24502 + au_dir_ts(dir, a->btgt);
24505 +static void au_ren_refresh(struct au_ren_args *a)
24507 + aufs_bindex_t bbot, bindex;
24508 + struct dentry *d, *h_d;
24509 + struct inode *i, *h_i;
24510 + struct super_block *sb;
24512 + d = a->dst_dentry;
24515 + /* already dget-ed by au_ren_or_cpup() */
24516 + au_set_h_dptr(d, a->btgt, a->h_dst);
24518 + i = a->dst_inode;
24520 + if (!a->exchange) {
24521 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24522 + vfsub_drop_nlink(i);
24524 + vfsub_dead_dir(i);
24525 + au_cpup_attr_timesizes(i);
24527 + au_update_dbrange(d, /*do_put_zero*/1);
24529 + au_cpup_attr_nlink(i, /*force*/1);
24532 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24533 + au_set_h_dptr(d, bindex, NULL);
24534 + bbot = au_dbbot(d);
24535 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24536 + au_set_h_dptr(d, bindex, NULL);
24537 + au_update_dbrange(d, /*do_put_zero*/0);
24541 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24542 + d_drop(a->src_dentry);
24543 + if (au_ftest_ren(a->auren_flags, DIRREN))
24544 + au_set_dbwh(a->src_dentry, -1);
24548 + d = a->src_dentry;
24549 + au_set_dbwh(d, -1);
24550 + bbot = au_dbbot(d);
24551 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24552 + h_d = au_h_dptr(d, bindex);
24554 + au_set_h_dptr(d, bindex, NULL);
24556 + au_set_dbbot(d, a->btgt);
24559 + i = a->src_inode;
24560 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24561 + return; /* success */
24563 + bbot = au_ibbot(i);
24564 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24565 + h_i = au_h_iptr(i, bindex);
24567 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24568 + /* ignore this error */
24569 + au_set_h_iptr(i, bindex, NULL, 0);
24572 + au_set_ibbot(i, a->btgt);
24575 +/* ---------------------------------------------------------------------- */
24577 +/* mainly for link(2) and rename(2) */
24578 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24580 + aufs_bindex_t bdiropq, bwh;
24581 + struct dentry *parent;
24582 + struct au_branch *br;
24584 + parent = dentry->d_parent;
24585 + IMustLock(d_inode(parent)); /* dir is locked */
24587 + bdiropq = au_dbdiropq(parent);
24588 + bwh = au_dbwh(dentry);
24589 + br = au_sbr(dentry->d_sb, btgt);
24590 + if (au_br_rdonly(br)
24591 + || (0 <= bdiropq && bdiropq < btgt)
24592 + || (0 <= bwh && bwh < btgt))
24595 + AuDbg("btgt %d\n", btgt);
24599 +/* sets src_btop, dst_btop and btgt */
24600 +static int au_ren_wbr(struct au_ren_args *a)
24603 + struct au_wr_dir_args wr_dir_args = {
24604 + /* .force_btgt = -1, */
24605 + .flags = AuWrDir_ADD_ENTRY
24608 + a->src_btop = au_dbtop(a->src_dentry);
24609 + a->dst_btop = au_dbtop(a->dst_dentry);
24610 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24611 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24612 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24613 + wr_dir_args.force_btgt = a->src_btop;
24614 + if (a->dst_inode && a->dst_btop < a->src_btop)
24615 + wr_dir_args.force_btgt = a->dst_btop;
24616 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24617 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24620 + au_update_dbtop(a->dst_dentry);
24625 +static void au_ren_dt(struct au_ren_args *a)
24627 + a->h_path.dentry = a->src_h_parent;
24628 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24629 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24630 + a->h_path.dentry = a->dst_h_parent;
24631 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24634 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24635 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24639 + a->h_path.dentry = a->src_h_dentry;
24640 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24641 + if (d_is_positive(a->dst_h_dentry)) {
24642 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24643 + a->h_path.dentry = a->dst_h_dentry;
24644 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24648 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24650 + struct dentry *h_d;
24651 + struct inode *h_inode;
24653 + au_dtime_revert(a->src_dt + AuPARENT);
24654 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24655 + au_dtime_revert(a->dst_dt + AuPARENT);
24657 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24658 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24659 + h_inode = d_inode(h_d);
24660 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24661 + au_dtime_revert(a->src_dt + AuCHILD);
24662 + inode_unlock(h_inode);
24664 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24665 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24666 + h_inode = d_inode(h_d);
24667 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24668 + au_dtime_revert(a->dst_dt + AuCHILD);
24669 + inode_unlock(h_inode);
24674 +/* ---------------------------------------------------------------------- */
24676 +int aufs_rename(struct user_namespace *userns,
24677 + struct inode *_src_dir, struct dentry *_src_dentry,
24678 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24679 + unsigned int _flags)
24681 + int err, lock_flags;
24683 + /* reduce stack space */
24684 + struct au_ren_args *a;
24685 + struct au_pin pin;
24687 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24688 + IMustLock(_src_dir);
24689 + IMustLock(_dst_dir);
24692 + if (unlikely(_flags & RENAME_WHITEOUT))
24696 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24697 + a = kzalloc(sizeof(*a), GFP_NOFS);
24698 + if (unlikely(!a))
24701 + a->flags = _flags;
24702 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24703 + && RENAME_EXCHANGE > U8_MAX);
24704 + a->exchange = _flags & RENAME_EXCHANGE;
24705 + a->src_dir = _src_dir;
24706 + a->src_dentry = _src_dentry;
24707 + a->src_inode = NULL;
24708 + if (d_really_is_positive(a->src_dentry))
24709 + a->src_inode = d_inode(a->src_dentry);
24710 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24711 + a->dst_dir = _dst_dir;
24712 + a->dst_dentry = _dst_dentry;
24713 + a->dst_inode = NULL;
24714 + if (d_really_is_positive(a->dst_dentry))
24715 + a->dst_inode = d_inode(a->dst_dentry);
24716 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24717 + if (a->dst_inode) {
24719 + * if EXCHANGE && src is non-dir && dst is dir,
24720 + * dst is not locked.
24722 + /* IMustLock(a->dst_inode); */
24723 + au_igrab(a->dst_inode);
24727 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24728 + if (d_is_dir(a->src_dentry)) {
24729 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24730 + if (unlikely(!a->exchange
24731 + && d_really_is_positive(a->dst_dentry)
24732 + && !d_is_dir(a->dst_dentry)))
24734 + lock_flags |= AuLock_DIRS;
24736 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24737 + au_fset_ren(a->auren_flags, ISDIR_DST);
24738 + if (unlikely(!a->exchange
24739 + && d_really_is_positive(a->src_dentry)
24740 + && !d_is_dir(a->src_dentry)))
24742 + lock_flags |= AuLock_DIRS;
24744 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24746 + if (unlikely(err))
24749 + err = au_d_hashed_positive(a->src_dentry);
24750 + if (unlikely(err))
24753 + if (a->dst_inode) {
24755 + * If it is a dir, VFS unhash it before this
24756 + * function. It means we cannot rely upon d_unhashed().
24758 + if (unlikely(!a->dst_inode->i_nlink))
24760 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24761 + err = au_d_hashed_positive(a->dst_dentry);
24762 + if (unlikely(err && !a->exchange))
24764 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24766 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24770 + * is it possible?
24771 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24772 + * there may exist a problem somewhere else.
24775 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24778 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24779 + di_write_lock_parent(a->dst_parent);
24781 + /* which branch we process */
24782 + err = au_ren_wbr(a);
24783 + if (unlikely(err < 0))
24785 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24786 + a->h_path.mnt = au_br_mnt(a->br);
24788 + /* are they available to be renamed */
24789 + err = au_ren_may_dir(a);
24790 + if (unlikely(err))
24791 + goto out_children;
24793 + /* prepare the writable parent dir on the same branch */
24794 + if (a->dst_btop == a->btgt) {
24795 + au_fset_ren(a->auren_flags, WHDST);
24797 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24798 + if (unlikely(err))
24799 + goto out_children;
24803 + if (!a->exchange) {
24804 + if (a->src_dir != a->dst_dir) {
24806 + * this temporary unlock is safe,
24807 + * because both dir->i_mutex are locked.
24809 + di_write_unlock(a->dst_parent);
24810 + di_write_lock_parent(a->src_parent);
24811 + err = au_wr_dir_need_wh(a->src_dentry,
24812 + au_ftest_ren(a->auren_flags,
24815 + di_write_unlock(a->src_parent);
24816 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24818 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24820 + err = au_wr_dir_need_wh(a->src_dentry,
24821 + au_ftest_ren(a->auren_flags,
24825 + if (unlikely(err < 0))
24826 + goto out_children;
24828 + au_fset_ren(a->auren_flags, WHSRC);
24831 + if (a->src_btop != a->btgt) {
24832 + err = au_pin(&pin, a->src_dentry, a->btgt,
24833 + au_opt_udba(a->src_dentry->d_sb),
24834 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24836 + struct au_cp_generic cpg = {
24837 + .dentry = a->src_dentry,
24839 + .bsrc = a->src_btop,
24842 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24844 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24845 + err = au_sio_cpup_simple(&cpg);
24848 + if (unlikely(err))
24849 + goto out_children;
24850 + a->src_btop = a->btgt;
24851 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24852 + if (!a->exchange)
24853 + au_fset_ren(a->auren_flags, WHSRC);
24857 + if (a->exchange && a->dst_inode
24858 + && a->dst_btop != a->btgt) {
24859 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24860 + au_opt_udba(a->dst_dentry->d_sb),
24861 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24863 + struct au_cp_generic cpg = {
24864 + .dentry = a->dst_dentry,
24866 + .bsrc = a->dst_btop,
24869 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24871 + err = au_sio_cpup_simple(&cpg);
24874 + if (unlikely(err))
24875 + goto out_children;
24876 + a->dst_btop = a->btgt;
24877 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24880 + /* lock them all */
24881 + err = au_ren_lock(a);
24882 + if (unlikely(err))
24883 + /* leave the copied-up one */
24884 + goto out_children;
24886 + if (!a->exchange) {
24887 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24888 + err = au_may_ren(a);
24889 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24890 + err = -ENAMETOOLONG;
24891 + if (unlikely(err))
24895 + /* store timestamps to be revertible */
24898 + /* store dirren info */
24899 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24900 + err = au_dr_rename(a->src_dentry, a->btgt,
24901 + &a->dst_dentry->d_name, &rev);
24903 + if (unlikely(err))
24908 + err = do_rename(a);
24909 + if (unlikely(err))
24912 + if (au_ftest_ren(a->auren_flags, DIRREN))
24913 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24915 + /* update dir attributes */
24916 + au_ren_refresh_dir(a);
24918 + /* dput/iput all lower dentries */
24919 + au_ren_refresh(a);
24921 + goto out_hdir; /* success */
24924 + if (au_ftest_ren(a->auren_flags, DIRREN))
24925 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24927 + au_ren_rev_dt(err, a);
24929 + au_ren_unlock(a);
24931 + au_nhash_wh_free(&a->whlist);
24932 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24933 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24934 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24935 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24939 + if (d_unhashed(a->src_dentry))
24940 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24941 + if (d_unhashed(a->dst_dentry))
24942 + au_fset_ren(a->auren_flags, DROPPED_DST);
24943 + if (!a->exchange)
24944 + d_move(a->src_dentry, a->dst_dentry);
24946 + d_exchange(a->src_dentry, a->dst_dentry);
24947 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
24948 + d_drop(a->dst_dentry);
24950 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
24951 + d_drop(a->src_dentry);
24953 + au_update_dbtop(a->dst_dentry);
24954 + if (!a->dst_inode)
24955 + d_drop(a->dst_dentry);
24957 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24958 + di_write_unlock(a->dst_parent);
24960 + di_write_unlock2(a->src_parent, a->dst_parent);
24962 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
24964 + iput(a->dst_inode);
24966 + au_whtmp_rmdir_free(a->thargs);
24972 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
24973 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
24974 +++ linux/fs/aufs/Kconfig 2022-03-21 14:49:05.716633010 +0100
24976 +# SPDX-License-Identifier: GPL-2.0
24978 + tristate "Aufs (Advanced multi layered unification filesystem) support"
24980 + Aufs is a stackable unification filesystem such as Unionfs,
24981 + which unifies several directories and provides a merged single
24983 + In the early days, aufs was entirely re-designed and
24984 + re-implemented Unionfs Version 1.x series. Introducing many
24985 + original ideas, approaches and improvements, it becomes totally
24986 + different from Unionfs while keeping the basic features.
24990 + prompt "Maximum number of branches"
24991 + default AUFS_BRANCH_MAX_127
24993 + Specifies the maximum number of branches (or member directories)
24994 + in a single aufs. The larger value consumes more system
24995 + resources and has a minor impact to performance.
24996 +config AUFS_BRANCH_MAX_127
24999 + Specifies the maximum number of branches (or member directories)
25000 + in a single aufs. The larger value consumes more system
25001 + resources and has a minor impact to performance.
25002 +config AUFS_BRANCH_MAX_511
25005 + Specifies the maximum number of branches (or member directories)
25006 + in a single aufs. The larger value consumes more system
25007 + resources and has a minor impact to performance.
25008 +config AUFS_BRANCH_MAX_1023
25011 + Specifies the maximum number of branches (or member directories)
25012 + in a single aufs. The larger value consumes more system
25013 + resources and has a minor impact to performance.
25014 +config AUFS_BRANCH_MAX_32767
25017 + Specifies the maximum number of branches (or member directories)
25018 + in a single aufs. The larger value consumes more system
25019 + resources and has a minor impact to performance.
25022 +config AUFS_SBILIST
25024 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25027 + Automatic configuration for internal use.
25028 + When aufs supports Magic SysRq or /proc, enabled automatically.
25030 +config AUFS_HNOTIFY
25031 + bool "Detect direct branch access (bypassing aufs)"
25033 + If you want to modify files on branches directly, eg. bypassing aufs,
25034 + and want aufs to detect the changes of them fully, then enable this
25035 + option and use 'udba=notify' mount option.
25036 + Currently there is only one available configuration, "fsnotify".
25037 + It will have a negative impact to the performance.
25038 + See detail in aufs.5.
25041 + prompt "method" if AUFS_HNOTIFY
25042 + default AUFS_HFSNOTIFY
25043 +config AUFS_HFSNOTIFY
25048 +config AUFS_EXPORT
25049 + bool "NFS-exportable aufs"
25050 + depends on EXPORTFS
25052 + If you want to export your mounted aufs via NFS, then enable this
25053 + option. There are several requirements for this configuration.
25054 + See detail in aufs.5.
25056 +config AUFS_INO_T_64
25058 + depends on AUFS_EXPORT
25059 + depends on 64BIT && !(ALPHA || S390)
25062 + Automatic configuration for internal use.
25063 + /* typedef unsigned long/int __kernel_ino_t */
25064 + /* alpha and s390x are int */
25067 + bool "support for XATTR/EA (including Security Labels)"
25069 + If your branch fs supports XATTR/EA and you want to make them
25070 + available in aufs too, then enable this opsion and specify the
25071 + branch attributes for EA.
25072 + See detail in aufs.5.
25075 + bool "File-based Hierarchical Storage Management"
25077 + Hierarchical Storage Management (or HSM) is a well-known feature
25078 + in the storage world. Aufs provides this feature as file-based.
25079 + with multiple branches.
25080 + These multiple branches are prioritized, ie. the topmost one
25081 + should be the fastest drive and be used heavily.
25084 + bool "Readdir in userspace"
25086 + Aufs has two methods to provide a merged view for a directory,
25087 + by a user-space library and by kernel-space natively. The latter
25088 + is always enabled but sometimes large and slow.
25089 + If you enable this option, install the library in aufs2-util
25090 + package, and set some environment variables for your readdir(3),
25091 + then the work will be handled in user-space which generally
25092 + shows better performance in most cases.
25093 + See detail in aufs.5.
25095 +config AUFS_DIRREN
25096 + bool "Workaround for rename(2)-ing a directory"
25098 + By default, aufs returns EXDEV error in renameing a dir who has
25099 + his child on the lower branch, since it is a bad idea to issue
25100 + rename(2) internally for every lower branch. But user may not
25101 + accept this behaviour. So here is a workaround to allow such
25102 + rename(2) and store some extra infromation on the writable
25103 + branch. Obviously this costs high (and I don't like it).
25104 + To use this feature, you need to enable this configuration AND
25105 + to specify the mount option `dirren.'
25106 + See details in aufs.5 and the design documents.
25109 + bool "Show whiteouts"
25111 + If you want to make the whiteouts in aufs visible, then enable
25112 + this option and specify 'shwh' mount option. Although it may
25113 + sounds like philosophy or something, but in technically it
25114 + simply shows the name of whiteout with keeping its behaviour.
25116 +config AUFS_BR_RAMFS
25117 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25119 + If you want to use ramfs as an aufs branch fs, then enable this
25120 + option. Generally tmpfs is recommended.
25121 + Aufs prohibited them to be a branch fs by default, because
25122 + initramfs becomes unusable after switch_root or something
25123 + generally. If you sets initramfs as an aufs branch and boot your
25124 + system by switch_root, you will meet a problem easily since the
25125 + files in initramfs may be inaccessible.
25126 + Unless you are going to use ramfs as an aufs branch fs without
25127 + switch_root or something, leave it N.
25129 +config AUFS_BR_FUSE
25130 + bool "Fuse fs as an aufs branch"
25131 + depends on FUSE_FS
25134 + If you want to use fuse-based userspace filesystem as an aufs
25135 + branch fs, then enable this option.
25136 + It implements the internal poll(2) operation which is
25137 + implemented by fuse only (curretnly).
25142 + Automatic configuration for internal use.
25144 +config AUFS_BR_HFSPLUS
25145 + bool "Hfsplus as an aufs branch"
25146 + depends on HFSPLUS_FS
25149 + If you want to use hfsplus fs as an aufs branch fs, then enable
25150 + this option. This option introduces a small overhead at
25151 + copying-up a file on hfsplus.
25153 +config AUFS_BDEV_LOOP
25155 + depends on BLK_DEV_LOOP
25158 + Automatic configuration for internal use.
25159 + Convert =[ym] into =y.
25162 + bool "Debug aufs"
25164 + Enable this to compile aufs internal debug code.
25165 + It will have a negative impact to the performance.
25167 +config AUFS_MAGIC_SYSRQ
25169 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25172 + Automatic configuration for internal use.
25173 + When aufs supports Magic SysRq, enabled automatically.
25175 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25176 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25177 +++ linux/fs/aufs/lcnt.h 2022-03-21 14:49:05.726633010 +0100
25179 +/* SPDX-License-Identifier: GPL-2.0 */
25181 + * Copyright (C) 2018-2021 Junjiro R. Okajima
25183 + * This program, aufs is free software; you can redistribute it and/or modify
25184 + * it under the terms of the GNU General Public License as published by
25185 + * the Free Software Foundation; either version 2 of the License, or
25186 + * (at your option) any later version.
25188 + * This program is distributed in the hope that it will be useful,
25189 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25190 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25191 + * GNU General Public License for more details.
25193 + * You should have received a copy of the GNU General Public License
25194 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25198 + * simple long counter wrapper
25201 +#ifndef __AUFS_LCNT_H__
25202 +#define __AUFS_LCNT_H__
25206 +#include "debug.h"
25208 +#define AuLCntATOMIC 1
25209 +#define AuLCntPCPUCNT 2
25211 + * why does percpu_refcount require extra synchronize_rcu()s in
25212 + * au_br_do_free()
25214 +#define AuLCntPCPUREF 3
25216 +/* #define AuLCntChosen AuLCntATOMIC */
25217 +#define AuLCntChosen AuLCntPCPUCNT
25218 +/* #define AuLCntChosen AuLCntPCPUREF */
25220 +#if AuLCntChosen == AuLCntATOMIC
25221 +#include <linux/atomic.h>
25223 +typedef atomic_long_t au_lcnt_t;
25225 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25227 + atomic_long_set(cnt, 0);
25231 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25236 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25237 + int do_sync __maybe_unused)
25242 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25244 + atomic_long_inc(cnt);
25247 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25249 + atomic_long_dec(cnt);
25252 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25254 + return atomic_long_read(cnt);
25258 +#if AuLCntChosen == AuLCntPCPUCNT
25259 +#include <linux/percpu_counter.h>
25261 +typedef struct percpu_counter au_lcnt_t;
25263 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25265 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25268 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25273 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25275 + percpu_counter_destroy(cnt);
25278 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25280 + percpu_counter_inc(cnt);
25283 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25285 + percpu_counter_dec(cnt);
25288 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25292 + n = percpu_counter_sum(cnt);
25294 + if (LONG_MAX != LLONG_MAX
25296 + AuWarn1("%s\n", "wrap-around");
25302 +#if AuLCntChosen == AuLCntPCPUREF
25303 +#include <linux/percpu-refcount.h>
25305 +typedef struct percpu_ref au_lcnt_t;
25307 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25310 + release = percpu_ref_exit;
25311 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25314 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25316 + synchronize_rcu();
25319 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25321 + percpu_ref_kill(cnt);
25323 + au_lcnt_wait_for_fin(cnt);
25326 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25328 + percpu_ref_get(cnt);
25331 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25333 + percpu_ref_put(cnt);
25337 + * avoid calling this func as possible.
25339 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25343 + percpu_ref_switch_to_atomic_sync(cnt);
25344 + l = atomic_long_read(&cnt->count);
25346 + percpu_ref_switch_to_percpu(cnt);
25348 + /* percpu_ref is initialized by 1 instead of 0 */
25353 +#ifdef CONFIG_AUFS_DEBUG
25354 +#define AuLCntZero(val) do { \
25357 + AuDbg("%s = %ld\n", #val, l); \
25360 +#define AuLCntZero(val) do {} while (0)
25363 +#endif /* __KERNEL__ */
25364 +#endif /* __AUFS_LCNT_H__ */
25365 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25366 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25367 +++ linux/fs/aufs/loop.c 2022-03-21 14:49:05.726633010 +0100
25369 +// SPDX-License-Identifier: GPL-2.0
25371 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25373 + * This program, aufs is free software; you can redistribute it and/or modify
25374 + * it under the terms of the GNU General Public License as published by
25375 + * the Free Software Foundation; either version 2 of the License, or
25376 + * (at your option) any later version.
25378 + * This program is distributed in the hope that it will be useful,
25379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25381 + * GNU General Public License for more details.
25383 + * You should have received a copy of the GNU General Public License
25384 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25388 + * support for loopback block device as a branch
25393 +/* added into drivers/block/loop.c */
25394 +static struct file *(*backing_file_func)(struct super_block *sb);
25397 + * test if two lower dentries have overlapping branches.
25399 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25401 + struct super_block *h_sb;
25402 + struct file *backing_file;
25404 + if (unlikely(!backing_file_func)) {
25405 + /* don't load "loop" module here */
25406 + backing_file_func = symbol_get(loop_backing_file);
25407 + if (unlikely(!backing_file_func))
25408 + /* "loop" module is not loaded */
25412 + h_sb = h_adding->d_sb;
25413 + backing_file = backing_file_func(h_sb);
25414 + if (!backing_file)
25417 + h_adding = backing_file->f_path.dentry;
25419 + * h_adding can be local NFS.
25420 + * in this case aufs cannot detect the loop.
25422 + if (unlikely(h_adding->d_sb == sb))
25424 + return !!au_test_subdir(h_adding, sb->s_root);
25427 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25428 +int au_test_loopback_kthread(void)
25431 + struct task_struct *tsk = current;
25432 + char c, comm[sizeof(tsk->comm)];
25435 + if (tsk->flags & PF_KTHREAD) {
25436 + get_task_comm(comm, tsk);
25438 + ret = ('0' <= c && c <= '9'
25439 + && !strncmp(comm, "loop", 4));
25445 +/* ---------------------------------------------------------------------- */
25447 +#define au_warn_loopback_step 16
25448 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25449 +static unsigned long *au_warn_loopback_array;
25451 +void au_warn_loopback(struct super_block *h_sb)
25453 + int i, new_nelem;
25454 + unsigned long *a, magic;
25455 + static DEFINE_SPINLOCK(spin);
25457 + magic = h_sb->s_magic;
25458 + spin_lock(&spin);
25459 + a = au_warn_loopback_array;
25460 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25461 + if (a[i] == magic) {
25462 + spin_unlock(&spin);
25466 + /* h_sb is new to us, print it */
25467 + if (i < au_warn_loopback_nelem) {
25472 + /* expand the array */
25473 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25474 + a = au_kzrealloc(au_warn_loopback_array,
25475 + au_warn_loopback_nelem * sizeof(unsigned long),
25476 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25477 + /*may_shrink*/0);
25479 + au_warn_loopback_nelem = new_nelem;
25480 + au_warn_loopback_array = a;
25485 + spin_unlock(&spin);
25486 + AuWarn1("realloc failed, ignored\n");
25490 + spin_unlock(&spin);
25491 + pr_warn("you may want to try another patch for loopback file "
25492 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25495 +int au_loopback_init(void)
25498 + struct super_block *sb __maybe_unused;
25500 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25503 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25504 + sizeof(unsigned long), GFP_NOFS);
25505 + if (unlikely(!au_warn_loopback_array))
25511 +void au_loopback_fin(void)
25513 + if (backing_file_func)
25514 + symbol_put(loop_backing_file);
25515 + au_kfree_try_rcu(au_warn_loopback_array);
25517 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25518 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25519 +++ linux/fs/aufs/loop.h 2022-03-21 14:49:05.726633010 +0100
25521 +/* SPDX-License-Identifier: GPL-2.0 */
25523 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25525 + * This program, aufs is free software; you can redistribute it and/or modify
25526 + * it under the terms of the GNU General Public License as published by
25527 + * the Free Software Foundation; either version 2 of the License, or
25528 + * (at your option) any later version.
25530 + * This program is distributed in the hope that it will be useful,
25531 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25532 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25533 + * GNU General Public License for more details.
25535 + * You should have received a copy of the GNU General Public License
25536 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25540 + * support for loopback mount as a branch
25543 +#ifndef __AUFS_LOOP_H__
25544 +#define __AUFS_LOOP_H__
25549 +struct super_block;
25551 +#ifdef CONFIG_AUFS_BDEV_LOOP
25552 +/* drivers/block/loop.c */
25553 +struct file *loop_backing_file(struct super_block *sb);
25556 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25557 +int au_test_loopback_kthread(void);
25558 +void au_warn_loopback(struct super_block *h_sb);
25560 +int au_loopback_init(void);
25561 +void au_loopback_fin(void);
25563 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25565 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25566 + struct dentry *h_adding)
25567 +AuStubInt0(au_test_loopback_kthread, void)
25568 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25570 +AuStubInt0(au_loopback_init, void)
25571 +AuStubVoid(au_loopback_fin, void)
25572 +#endif /* BLK_DEV_LOOP */
25574 +#endif /* __KERNEL__ */
25575 +#endif /* __AUFS_LOOP_H__ */
25576 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25577 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25578 +++ linux/fs/aufs/magic.mk 2022-03-21 14:49:05.726633010 +0100
25580 +# SPDX-License-Identifier: GPL-2.0
25582 +# defined in ${srctree}/fs/fuse/inode.c
25584 +ifdef CONFIG_FUSE_FS
25585 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25588 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25590 +ifdef CONFIG_XFS_FS
25591 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25594 +# defined in ${srctree}/fs/configfs/mount.c
25596 +ifdef CONFIG_CONFIGFS_FS
25597 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25600 +# defined in ${srctree}/fs/ubifs/ubifs.h
25602 +ifdef CONFIG_UBIFS_FS
25603 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25606 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25608 +ifdef CONFIG_HFSPLUS_FS
25609 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25611 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25612 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25613 +++ linux/fs/aufs/Makefile 2022-03-21 14:49:05.716633010 +0100
25615 +# SPDX-License-Identifier: GPL-2.0
25617 +include ${src}/magic.mk
25618 +ifeq (${CONFIG_AUFS_FS},m)
25619 +include ${src}/conf.mk
25621 +-include ${src}/priv_def.mk
25623 +# cf. include/linux/kernel.h
25625 +ccflags-y += -DDEBUG
25626 +# sparse requires the full pathname
25628 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25630 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25633 +obj-$(CONFIG_AUFS_FS) += aufs.o
25634 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25635 + wkq.o vfsub.o dcsub.o \
25636 + cpup.o whout.o wbr_policy.o \
25637 + dinfo.o dentry.o \
25639 + finfo.o file.o f_op.o \
25641 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25645 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25646 +aufs-$(CONFIG_SYSFS) += sysfs.o
25647 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25648 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25649 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25650 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25651 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25652 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25653 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25654 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25655 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25656 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25657 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25658 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25659 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25660 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25661 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25662 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25663 +++ linux/fs/aufs/module.c 2022-03-21 14:49:05.726633010 +0100
25665 +// SPDX-License-Identifier: GPL-2.0
25667 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25669 + * This program, aufs is free software; you can redistribute it and/or modify
25670 + * it under the terms of the GNU General Public License as published by
25671 + * the Free Software Foundation; either version 2 of the License, or
25672 + * (at your option) any later version.
25674 + * This program is distributed in the hope that it will be useful,
25675 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25676 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25677 + * GNU General Public License for more details.
25679 + * You should have received a copy of the GNU General Public License
25680 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25684 + * module global variables and operations
25687 +#include <linux/module.h>
25688 +#include <linux/seq_file.h>
25691 +/* shrinkable realloc */
25692 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25700 +#if 0 /* unused */
25707 + AuDebugOn(!new_sz);
25710 + diff = au_kmidx_sub(sz, new_sz);
25716 + /* expand or SLOB */
25717 + p = krealloc(p, new_sz, gfp);
25718 + else if (new_sz < sz && may_shrink) {
25722 + q = kmalloc(new_sz, gfp);
25725 + memcpy(q, p, new_sz);
25726 + au_kfree_try_rcu(p);
25737 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25740 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25741 + if (p && new_sz > nused)
25742 + memset(p + nused, 0, new_sz - nused);
25746 +/* ---------------------------------------------------------------------- */
25750 +struct kmem_cache *au_cache[AuCache_Last];
25752 +static void au_cache_fin(void)
25757 + * Make sure all delayed rcu free inodes are flushed before we
25762 + /* excluding AuCache_HNOTIFY */
25763 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25764 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25765 + kmem_cache_destroy(au_cache[i]);
25766 + au_cache[i] = NULL;
25770 +static int __init au_cache_init(void)
25772 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25773 + if (au_cache[AuCache_DINFO])
25774 + /* SLAB_DESTROY_BY_RCU */
25775 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25776 + au_icntnr_init_once);
25777 + if (au_cache[AuCache_ICNTNR])
25778 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25779 + au_fi_init_once);
25780 + if (au_cache[AuCache_FINFO])
25781 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25782 + if (au_cache[AuCache_VDIR])
25783 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25784 + if (au_cache[AuCache_DEHSTR])
25791 +/* ---------------------------------------------------------------------- */
25793 +int au_dir_roflags;
25795 +#ifdef CONFIG_AUFS_SBILIST
25797 + * iterate_supers_type() doesn't protect us from
25798 + * remounting (branch management)
25800 +struct hlist_bl_head au_sbilist;
25804 + * functions for module interface.
25806 +MODULE_LICENSE("GPL");
25807 +/* MODULE_LICENSE("GPL v2"); */
25808 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25809 +MODULE_DESCRIPTION(AUFS_NAME
25810 + " -- Advanced multi layered unification filesystem");
25811 +MODULE_VERSION(AUFS_VERSION);
25812 +MODULE_ALIAS_FS(AUFS_NAME);
25814 +/* this module parameter has no meaning when SYSFS is disabled */
25815 +int sysaufs_brs = 1;
25816 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25817 +module_param_named(brs, sysaufs_brs, int, 0444);
25819 +/* this module parameter has no meaning when USER_NS is disabled */
25821 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25822 +module_param_named(allow_userns, au_userns, bool, 0444);
25824 +/* ---------------------------------------------------------------------- */
25826 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25828 +int au_seq_path(struct seq_file *seq, struct path *path)
25832 + err = seq_path(seq, path, au_esc_chars);
25841 +/* ---------------------------------------------------------------------- */
25843 +static int __init aufs_init(void)
25848 + p = au_esc_chars;
25849 + for (i = 1; i <= ' '; i++)
25855 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25857 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25858 + for (i = 0; i < AuIop_Last; i++)
25859 + aufs_iop_nogetattr[i].getattr = NULL;
25861 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25863 + au_sbilist_init();
25864 + sysaufs_brs_init();
25867 + err = sysaufs_init();
25868 + if (unlikely(err))
25870 + err = dbgaufs_init();
25871 + if (unlikely(err))
25872 + goto out_sysaufs;
25873 + err = au_procfs_init();
25874 + if (unlikely(err))
25875 + goto out_dbgaufs;
25876 + err = au_wkq_init();
25877 + if (unlikely(err))
25879 + err = au_loopback_init();
25880 + if (unlikely(err))
25882 + err = au_hnotify_init();
25883 + if (unlikely(err))
25884 + goto out_loopback;
25885 + err = au_sysrq_init();
25886 + if (unlikely(err))
25888 + err = au_cache_init();
25889 + if (unlikely(err))
25892 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25893 + err = register_filesystem(&aufs_fs_type);
25894 + if (unlikely(err))
25897 + /* since we define pr_fmt, call printk directly */
25898 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25899 + goto out; /* success */
25906 + au_hnotify_fin();
25908 + au_loopback_fin();
25922 +static void __exit aufs_exit(void)
25924 + unregister_filesystem(&aufs_fs_type);
25927 + au_hnotify_fin();
25928 + au_loopback_fin();
25936 +module_init(aufs_init);
25937 +module_exit(aufs_exit);
25938 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25939 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25940 +++ linux/fs/aufs/module.h 2022-03-21 14:49:05.726633010 +0100
25942 +/* SPDX-License-Identifier: GPL-2.0 */
25944 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25946 + * This program, aufs is free software; you can redistribute it and/or modify
25947 + * it under the terms of the GNU General Public License as published by
25948 + * the Free Software Foundation; either version 2 of the License, or
25949 + * (at your option) any later version.
25951 + * This program is distributed in the hope that it will be useful,
25952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25954 + * GNU General Public License for more details.
25956 + * You should have received a copy of the GNU General Public License
25957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25961 + * module initialization and module-global
25964 +#ifndef __AUFS_MODULE_H__
25965 +#define __AUFS_MODULE_H__
25969 +#include <linux/slab.h>
25970 +#include "debug.h"
25971 +#include "dentry.h"
25974 +#include "inode.h"
25979 +/* module parameters */
25980 +extern int sysaufs_brs;
25981 +extern bool au_userns;
25983 +/* ---------------------------------------------------------------------- */
25985 +extern int au_dir_roflags;
25987 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
25988 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25992 + * Comparing the size of the object with sizeof(struct rcu_head)
25993 + * case 1: object is always larger
25994 + * --> au_kfree_rcu() or au_kfree_do_rcu()
25995 + * case 2: object is always smaller
25996 + * --> au_kfree_small()
25997 + * case 3: object can be any size
25998 + * --> au_kfree_try_rcu()
26001 +static inline void au_kfree_do_rcu(const void *p)
26004 + struct rcu_head rcu;
26005 + } *a = (void *)p;
26007 + kfree_rcu(a, rcu);
26010 +#define au_kfree_rcu(_p) do { \
26011 + typeof(_p) p = (_p); \
26012 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26014 + au_kfree_do_rcu(p); \
26017 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26018 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26020 +static inline void au_kfree_try_rcu(const void *p)
26024 + if (au_kfree_sz_test(p))
26025 + au_kfree_do_rcu(p);
26030 +static inline void au_kfree_small(const void *p)
26034 + AuDebugOn(au_kfree_sz_test(p));
26038 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26040 +#ifndef CONFIG_SLOB
26041 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26043 + return -1; /* SLOB is untested */
26047 +int au_seq_path(struct seq_file *seq, struct path *path);
26049 +#ifdef CONFIG_PROC_FS
26051 +int __init au_procfs_init(void);
26052 +void au_procfs_fin(void);
26054 +AuStubInt0(au_procfs_init, void);
26055 +AuStubVoid(au_procfs_fin, void);
26058 +/* ---------------------------------------------------------------------- */
26067 + AuCache_HNOTIFY, /* must be last */
26071 +extern struct kmem_cache *au_cache[AuCache_Last];
26073 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26074 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26075 +#define AuCacheCtor(type, ctor) \
26076 + kmem_cache_create(#type, sizeof(struct type), \
26077 + __alignof__(struct type), AuCacheFlags, ctor)
26079 +#define AuCacheFuncs(name, index) \
26080 + static inline struct au_##name *au_cache_alloc_##name(void) \
26081 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
26082 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26083 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26085 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26086 + { void *p = rcu; \
26087 + p -= offsetof(struct au_##name, rcu); \
26088 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26089 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26090 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26091 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26093 + static inline void au_cache_free_##name(struct au_##name *p) \
26094 + { /* au_cache_free_##name##_norcu(p); */ \
26095 + au_cache_free_##name##_rcu(p); }
26097 +AuCacheFuncs(dinfo, DINFO);
26098 +AuCacheFuncs(icntnr, ICNTNR);
26099 +AuCacheFuncs(finfo, FINFO);
26100 +AuCacheFuncs(vdir, VDIR);
26101 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26102 +#ifdef CONFIG_AUFS_HNOTIFY
26103 +AuCacheFuncs(hnotify, HNOTIFY);
26106 +#endif /* __KERNEL__ */
26107 +#endif /* __AUFS_MODULE_H__ */
26108 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26109 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26110 +++ linux/fs/aufs/mvdown.c 2022-03-21 14:49:05.729966343 +0100
26112 +// SPDX-License-Identifier: GPL-2.0
26114 + * Copyright (C) 2011-2021 Junjiro R. Okajima
26116 + * This program, aufs is free software; you can redistribute it and/or modify
26117 + * it under the terms of the GNU General Public License as published by
26118 + * the Free Software Foundation; either version 2 of the License, or
26119 + * (at your option) any later version.
26121 + * This program is distributed in the hope that it will be useful,
26122 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26124 + * GNU General Public License for more details.
26126 + * You should have received a copy of the GNU General Public License
26127 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26131 + * move-down, opposite of copy-up
26136 +struct au_mvd_args {
26138 + struct super_block *h_sb;
26139 + struct dentry *h_parent;
26140 + struct au_hinode *hdir;
26141 + struct inode *h_dir, *h_inode;
26142 + struct au_pin pin;
26143 + } info[AUFS_MVDOWN_NARRAY];
26145 + struct aufs_mvdown mvdown;
26146 + struct dentry *dentry, *parent;
26147 + struct inode *inode, *dir;
26148 + struct super_block *sb;
26149 + aufs_bindex_t bopq, bwh, bfound;
26150 + unsigned char rename_lock;
26153 +#define mvd_errno mvdown.au_errno
26154 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26155 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26156 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26157 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26159 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26160 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26161 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26162 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26163 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26164 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26166 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26167 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26168 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26169 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26170 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26171 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26173 +#define AU_MVD_PR(flag, ...) do { \
26175 + pr_err(__VA_ARGS__); \
26178 +static int find_lower_writable(struct au_mvd_args *a)
26180 + struct super_block *sb;
26181 + aufs_bindex_t bindex, bbot;
26182 + struct au_branch *br;
26185 + bindex = a->mvd_bsrc;
26186 + bbot = au_sbbot(sb);
26187 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26188 + for (bindex++; bindex <= bbot; bindex++) {
26189 + br = au_sbr(sb, bindex);
26190 + if (au_br_fhsm(br->br_perm)
26191 + && !sb_rdonly(au_br_sb(br)))
26194 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26195 + for (bindex++; bindex <= bbot; bindex++) {
26196 + br = au_sbr(sb, bindex);
26197 + if (!au_br_rdonly(br))
26201 + for (bindex++; bindex <= bbot; bindex++) {
26202 + br = au_sbr(sb, bindex);
26203 + if (!sb_rdonly(au_br_sb(br))) {
26204 + if (au_br_rdonly(br))
26206 + |= AUFS_MVDOWN_ROLOWER_R;
26214 +/* make the parent dir on bdst */
26215 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26220 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26221 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26222 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26223 + a->mvd_h_dst_parent = NULL;
26224 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26225 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26226 + if (!a->mvd_h_dst_parent) {
26227 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26228 + if (unlikely(err)) {
26229 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26232 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26240 +/* lock them all */
26241 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26244 + struct dentry *h_trap;
26246 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26247 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26248 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26249 + au_opt_udba(a->sb),
26250 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26252 + if (unlikely(err)) {
26253 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26257 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26258 + a->rename_lock = 0;
26259 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26260 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26261 + au_opt_udba(a->sb),
26262 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26263 + err = au_do_pin(&a->mvd_pin_src);
26265 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26266 + if (unlikely(err)) {
26267 + AU_MVD_PR(dmsg, "pin_src failed\n");
26270 + goto out; /* success */
26273 + a->rename_lock = 1;
26274 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26275 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26276 + au_opt_udba(a->sb),
26277 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26279 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26280 + if (unlikely(err)) {
26281 + AU_MVD_PR(dmsg, "pin_src failed\n");
26282 + au_pin_hdir_lock(&a->mvd_pin_dst);
26285 + au_pin_hdir_unlock(&a->mvd_pin_src);
26286 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26287 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26289 + err = (h_trap != a->mvd_h_src_parent);
26291 + err = (h_trap != a->mvd_h_dst_parent);
26293 + BUG_ON(err); /* it should never happen */
26294 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26297 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26298 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26299 + au_pin_hdir_lock(&a->mvd_pin_src);
26300 + au_unpin(&a->mvd_pin_src);
26301 + au_pin_hdir_lock(&a->mvd_pin_dst);
26304 + goto out; /* success */
26307 + au_unpin(&a->mvd_pin_dst);
26313 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26315 + if (!a->rename_lock)
26316 + au_unpin(&a->mvd_pin_src);
26318 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26319 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26320 + au_pin_hdir_lock(&a->mvd_pin_src);
26321 + au_unpin(&a->mvd_pin_src);
26322 + au_pin_hdir_lock(&a->mvd_pin_dst);
26324 + au_unpin(&a->mvd_pin_dst);
26327 +/* copy-down the file */
26328 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26331 + struct au_cp_generic cpg = {
26332 + .dentry = a->dentry,
26333 + .bdst = a->mvd_bdst,
26334 + .bsrc = a->mvd_bsrc,
26336 + .pin = &a->mvd_pin_dst,
26337 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26340 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26341 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26342 + au_fset_cpup(cpg.flags, OVERWRITE);
26343 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26344 + au_fset_cpup(cpg.flags, RWDST);
26345 + err = au_sio_cpdown_simple(&cpg);
26346 + if (unlikely(err))
26347 + AU_MVD_PR(dmsg, "cpdown failed\n");
26354 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26357 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26360 + struct path h_path;
26361 + struct au_branch *br;
26362 + struct inode *delegated;
26364 + br = au_sbr(a->sb, a->mvd_bdst);
26365 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26366 + err = PTR_ERR(h_path.dentry);
26367 + if (IS_ERR(h_path.dentry)) {
26368 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26373 + if (d_is_positive(h_path.dentry)) {
26374 + h_path.mnt = au_br_mnt(br);
26375 + delegated = NULL;
26376 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26377 + &delegated, /*force*/0);
26378 + if (unlikely(err == -EWOULDBLOCK)) {
26379 + pr_warn("cannot retry for NFSv4 delegation"
26380 + " for an internal unlink\n");
26383 + if (unlikely(err))
26384 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26386 + dput(h_path.dentry);
26394 + * unlink the topmost h_dentry
26396 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26399 + struct path h_path;
26400 + struct inode *delegated;
26402 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26403 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26404 + delegated = NULL;
26405 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26406 + if (unlikely(err == -EWOULDBLOCK)) {
26407 + pr_warn("cannot retry for NFSv4 delegation"
26408 + " for an internal unlink\n");
26411 + if (unlikely(err))
26412 + AU_MVD_PR(dmsg, "unlink failed\n");
26418 +/* Since mvdown succeeded, we ignore an error of this function */
26419 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26422 + struct au_branch *br;
26424 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26425 + br = au_sbr(a->sb, a->mvd_bsrc);
26426 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26428 + br = au_sbr(a->sb, a->mvd_bdst);
26429 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26430 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26433 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26435 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26439 + * copy-down the file and unlink the bsrc file.
26440 + * - unlink the bdst whout if exist
26441 + * - copy-down the file (with whtmp name and rename)
26442 + * - unlink the bsrc file
26444 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26448 + err = au_do_mkdir(dmsg, a);
26450 + err = au_do_lock(dmsg, a);
26451 + if (unlikely(err))
26455 + * do not revert the activities we made on bdst since they should be
26456 + * harmless in aufs.
26459 + err = au_do_cpdown(dmsg, a);
26461 + err = au_do_unlink_wh(dmsg, a);
26462 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26463 + err = au_do_unlink(dmsg, a);
26464 + if (unlikely(err))
26467 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26468 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26469 + if (find_lower_writable(a) < 0)
26470 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26472 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26473 + au_do_stfs(dmsg, a);
26475 + /* maintain internal array */
26476 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26477 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26478 + au_set_dbtop(a->dentry, a->mvd_bdst);
26479 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26480 + au_set_ibtop(a->inode, a->mvd_bdst);
26482 + /* hide the lower */
26483 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26484 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26485 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26486 + au_set_ibbot(a->inode, a->mvd_bsrc);
26488 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26489 + au_set_dbbot(a->dentry, a->mvd_bdst);
26490 + if (au_ibbot(a->inode) < a->mvd_bdst)
26491 + au_set_ibbot(a->inode, a->mvd_bdst);
26494 + au_do_unlock(dmsg, a);
26500 +/* ---------------------------------------------------------------------- */
26502 +/* make sure the file is idle */
26503 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26505 + int err, plinked;
26508 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26509 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26510 + && au_dcount(a->dentry) == 1
26511 + && atomic_read(&a->inode->i_count) == 1
26512 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26513 + && (!plinked || !au_plink_test(a->inode))
26514 + && a->inode->i_nlink == 1)
26519 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26520 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26521 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26522 + a->mvd_h_src_inode->i_nlink,
26523 + plinked, plinked ? au_plink_test(a->inode) : 0);
26530 +/* make sure the parent dir is fine */
26531 +static int au_mvd_args_parent(const unsigned char dmsg,
26532 + struct au_mvd_args *a)
26535 + aufs_bindex_t bindex;
26538 + if (unlikely(au_alive_dir(a->parent))) {
26540 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26544 + a->bopq = au_dbdiropq(a->parent);
26545 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26546 + AuDbg("b%d\n", bindex);
26547 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26548 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26550 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26551 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26552 + a->bopq, a->mvd_bdst);
26560 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26561 + struct au_mvd_args *a)
26564 + struct au_dinfo *dinfo, *tmp;
26566 + /* lookup the next lower positive entry */
26568 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26569 + if (unlikely(!tmp))
26574 + dinfo = au_di(a->dentry);
26575 + au_di_cp(tmp, dinfo);
26576 + au_di_swap(tmp, dinfo);
26578 + /* returns the number of positive dentries */
26579 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26580 + /* AuLkup_IGNORE_PERM */ 0);
26582 + a->bwh = au_dbwh(a->dentry);
26583 + else if (err > 0)
26584 + a->bfound = au_dbtop(a->dentry);
26586 + au_di_swap(tmp, dinfo);
26587 + au_rw_write_unlock(&tmp->di_rwsem);
26589 + if (unlikely(err < 0))
26590 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26593 + * here, we have these cases.
26595 + * no positive dentry under bsrc. there are more sub-cases.
26597 + * there no whiteout, we can safely move-down.
26600 + * bsrc < bwh && bwh < bdst
26601 + * there is a whiteout on RO branch. cannot proceed.
26603 + * there is a whiteout on the RW target branch. it should
26606 + * there is a whiteout somewhere unrelated branch.
26607 + * -1 < bfound && bfound <= bsrc
26610 + * found, but it is on RO branch between bsrc and bdst. cannot
26613 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26616 + * found, after we create the file on bdst, it will be hidden.
26619 + AuDebugOn(a->bfound == -1
26621 + && a->bwh <= a->mvd_bsrc);
26622 + AuDebugOn(-1 < a->bfound
26623 + && a->bfound <= a->mvd_bsrc);
26626 + if (a->bfound == -1
26627 + && a->mvd_bsrc < a->bwh
26629 + && a->bwh < a->mvd_bdst) {
26630 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26631 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26632 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26634 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26635 + a->mvd_errno = EAU_MVDOWN_UPPER;
26636 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26637 + a->mvd_bdst, a->bfound);
26641 + err = 0; /* success */
26648 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26653 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26654 + && a->bfound == a->mvd_bdst)
26660 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26663 + struct au_branch *br;
26666 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26670 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26671 + a->mvd_bsrc = au_ibtop(a->inode);
26673 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26674 + if (unlikely(a->mvd_bsrc < 0
26675 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26676 + || au_dbbot(a->dentry) < a->mvd_bsrc
26677 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26678 + || (a->mvd_bsrc < au_ibtop(a->inode)
26679 + || au_ibbot(a->inode) < a->mvd_bsrc
26680 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26681 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26682 + AU_MVD_PR(dmsg, "no upper\n");
26686 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26687 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26688 + AU_MVD_PR(dmsg, "on the bottom\n");
26691 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26692 + br = au_sbr(a->sb, a->mvd_bsrc);
26693 + err = au_br_rdonly(br);
26694 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26695 + if (unlikely(err))
26697 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26698 + || IS_APPEND(a->mvd_h_src_inode))) {
26700 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26706 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26707 + a->mvd_bdst = find_lower_writable(a);
26708 + if (unlikely(a->mvd_bdst < 0)) {
26709 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26710 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26714 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26715 + if (unlikely(a->mvd_bdst < 0
26716 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26717 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26718 + AU_MVD_PR(dmsg, "no lower brid\n");
26723 + err = au_mvd_args_busy(dmsg, a);
26725 + err = au_mvd_args_parent(dmsg, a);
26727 + err = au_mvd_args_intermediate(dmsg, a);
26729 + err = au_mvd_args_exist(dmsg, a);
26731 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26738 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26741 + unsigned char dmsg;
26742 + struct au_mvd_args *args;
26743 + struct inode *inode;
26745 + inode = d_inode(dentry);
26747 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26751 + args = kmalloc(sizeof(*args), GFP_NOFS);
26752 + if (unlikely(!args))
26755 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26757 + /* VERIFY_WRITE */
26758 + err = !access_ok(uarg, sizeof(*uarg));
26759 + if (unlikely(err)) {
26764 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26765 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26766 + args->mvdown.au_errno = 0;
26767 + args->dentry = dentry;
26768 + args->inode = inode;
26769 + args->sb = dentry->d_sb;
26772 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26773 + args->parent = dget_parent(dentry);
26774 + args->dir = d_inode(args->parent);
26775 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26776 + dput(args->parent);
26777 + if (unlikely(args->parent != dentry->d_parent)) {
26778 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26782 + inode_lock_nested(inode, I_MUTEX_CHILD);
26783 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26784 + if (unlikely(err))
26787 + di_write_lock_parent(args->parent);
26788 + err = au_mvd_args(dmsg, args);
26789 + if (unlikely(err))
26792 + err = au_do_mvdown(dmsg, args);
26793 + if (unlikely(err))
26796 + au_cpup_attr_timesizes(args->dir);
26797 + au_cpup_attr_timesizes(inode);
26798 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26799 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26800 + /* au_digen_dec(dentry); */
26803 + di_write_unlock(args->parent);
26804 + aufs_read_unlock(dentry, AuLock_DW);
26806 + inode_unlock(inode);
26808 + inode_unlock(args->dir);
26810 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26813 + au_kfree_rcu(args);
26818 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26819 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26820 +++ linux/fs/aufs/opts.c 2022-03-21 14:49:05.729966343 +0100
26822 +// SPDX-License-Identifier: GPL-2.0
26824 + * Copyright (C) 2005-2021 Junjiro R. Okajima
26826 + * This program, aufs is free software; you can redistribute it and/or modify
26827 + * it under the terms of the GNU General Public License as published by
26828 + * the Free Software Foundation; either version 2 of the License, or
26829 + * (at your option) any later version.
26831 + * This program is distributed in the hope that it will be useful,
26832 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26833 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26834 + * GNU General Public License for more details.
26836 + * You should have received a copy of the GNU General Public License
26837 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26841 + * mount options/flags
26844 +#include <linux/types.h> /* a distribution requires */
26845 +#include <linux/parser.h>
26848 +/* ---------------------------------------------------------------------- */
26850 +static const char *au_parser_pattern(int val, match_table_t tbl)
26852 + struct match_token *p;
26855 + while (p->pattern) {
26856 + if (p->token == val)
26857 + return p->pattern;
26864 +static const char *au_optstr(int *val, match_table_t tbl)
26866 + struct match_token *p;
26873 + while (p->pattern) {
26875 + && (v & p->token) == p->token) {
26876 + *val &= ~p->token;
26877 + return p->pattern;
26886 +/* ---------------------------------------------------------------------- */
26888 +static match_table_t brperm = {
26889 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26890 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26891 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26895 +static match_table_t brattr = {
26897 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26898 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26899 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26900 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26901 +#ifdef CONFIG_AUFS_FHSM
26902 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26904 +#ifdef CONFIG_AUFS_XATTR
26905 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26906 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26907 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26908 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26909 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26910 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26913 + /* ro/rr branch */
26914 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26917 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26918 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26923 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26930 + p = strchr(str, '+');
26933 + v = match_token(str, table, args);
26935 + if (v & AuBrAttr_CMOO_Mask)
26936 + attr &= ~AuBrAttr_CMOO_Mask;
26941 + pr_warn("ignored branch attribute %s\n", str);
26951 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26959 + p = au_optstr(&perm, brattr);
26962 + memcpy(q, p, sz + 1);
26968 + p = au_optstr(&perm, brattr);
26972 + memcpy(q, p, sz + 1);
26978 + return q - str->a;
26981 +int au_br_perm_val(char *perm)
26983 + int val, bad, sz;
26985 + substring_t args[MAX_OPT_ARGS];
26986 + au_br_perm_str_t attr;
26988 + p = strchr(perm, '+');
26991 + val = match_token(perm, brperm, args);
26995 + pr_warn("ignored branch permission %s\n", perm);
26996 + val = AuBrPerm_RO;
27002 + val |= br_attr_val(p + 1, brattr, args);
27005 + switch (val & AuBrPerm_Mask) {
27006 + case AuBrPerm_RO:
27007 + case AuBrPerm_RR:
27008 + bad = val & AuBrWAttr_Mask;
27009 + val &= ~AuBrWAttr_Mask;
27011 + case AuBrPerm_RW:
27012 + bad = val & AuBrRAttr_Mask;
27013 + val &= ~AuBrRAttr_Mask;
27018 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27019 + * does not treat it as an error, just warning.
27020 + * this is a tiny guard for the user operation.
27022 + if (val & AuBrAttr_UNPIN) {
27023 + bad |= AuBrAttr_UNPIN;
27024 + val &= ~AuBrAttr_UNPIN;
27027 + if (unlikely(bad)) {
27028 + sz = au_do_optstr_br_attr(&attr, bad);
27030 + pr_warn("ignored branch attribute %s\n", attr.a);
27037 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27039 + au_br_perm_str_t attr;
27045 + p = au_optstr(&perm, brperm);
27046 + AuDebugOn(!p || !*p);
27048 + memcpy(q, p, sz + 1);
27051 + sz = au_do_optstr_br_attr(&attr, perm);
27054 + memcpy(q, attr.a, sz + 1);
27057 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27060 +/* ---------------------------------------------------------------------- */
27062 +static match_table_t udbalevel = {
27063 + {AuOpt_UDBA_REVAL, "reval"},
27064 + {AuOpt_UDBA_NONE, "none"},
27065 +#ifdef CONFIG_AUFS_HNOTIFY
27066 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27067 +#ifdef CONFIG_AUFS_HFSNOTIFY
27068 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27074 +int au_udba_val(char *str)
27076 + substring_t args[MAX_OPT_ARGS];
27078 + return match_token(str, udbalevel, args);
27081 +const char *au_optstr_udba(int udba)
27083 + return au_parser_pattern(udba, udbalevel);
27086 +/* ---------------------------------------------------------------------- */
27088 +static match_table_t au_wbr_create_policy = {
27089 + {AuWbrCreate_TDP, "tdp"},
27090 + {AuWbrCreate_TDP, "top-down-parent"},
27091 + {AuWbrCreate_RR, "rr"},
27092 + {AuWbrCreate_RR, "round-robin"},
27093 + {AuWbrCreate_MFS, "mfs"},
27094 + {AuWbrCreate_MFS, "most-free-space"},
27095 + {AuWbrCreate_MFSV, "mfs:%d"},
27096 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27098 + /* top-down regardless the parent, and then mfs */
27099 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27100 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27102 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27103 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27104 + {AuWbrCreate_PMFS, "pmfs"},
27105 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27106 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27107 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27112 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27113 + struct au_opt_wbr_create *create)
27116 + unsigned long long ull;
27119 + if (!match_u64(arg, &ull))
27120 + create->mfsrr_watermark = ull;
27122 + pr_err("bad integer in %s\n", str);
27129 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27130 + struct au_opt_wbr_create *create)
27135 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27136 + create->mfs_second = n;
27138 + pr_err("bad integer in %s\n", str);
27145 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27148 + substring_t args[MAX_OPT_ARGS];
27150 + err = match_token(str, au_wbr_create_policy, args);
27151 + create->wbr_create = err;
27153 + case AuWbrCreate_MFSRRV:
27154 + case AuWbrCreate_TDMFSV:
27155 + case AuWbrCreate_PMFSRRV:
27156 + e = au_wbr_mfs_wmark(&args[0], str, create);
27158 + e = au_wbr_mfs_sec(&args[1], str, create);
27162 + case AuWbrCreate_MFSRR:
27163 + case AuWbrCreate_TDMFS:
27164 + case AuWbrCreate_PMFSRR:
27165 + e = au_wbr_mfs_wmark(&args[0], str, create);
27166 + if (unlikely(e)) {
27171 + case AuWbrCreate_MFS:
27172 + case AuWbrCreate_PMFS:
27173 + create->mfs_second = AUFS_MFS_DEF_SEC;
27175 + case AuWbrCreate_MFSV:
27176 + case AuWbrCreate_PMFSV:
27177 + e = au_wbr_mfs_sec(&args[0], str, create);
27186 +const char *au_optstr_wbr_create(int wbr_create)
27188 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27191 +static match_table_t au_wbr_copyup_policy = {
27192 + {AuWbrCopyup_TDP, "tdp"},
27193 + {AuWbrCopyup_TDP, "top-down-parent"},
27194 + {AuWbrCopyup_BUP, "bup"},
27195 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27196 + {AuWbrCopyup_BU, "bu"},
27197 + {AuWbrCopyup_BU, "bottom-up"},
27201 +int au_wbr_copyup_val(char *str)
27203 + substring_t args[MAX_OPT_ARGS];
27205 + return match_token(str, au_wbr_copyup_policy, args);
27208 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27210 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27213 +/* ---------------------------------------------------------------------- */
27215 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27216 + aufs_bindex_t bindex)
27219 + struct au_opt_add *add = &opt->add;
27222 + add->bindex = bindex;
27223 + add->perm = AuBrPerm_RO;
27224 + add->pathname = opt_str;
27225 + p = strchr(opt_str, '=');
27229 + add->perm = au_br_perm_val(p);
27232 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27235 + add->perm = AuBrPerm_RO;
27236 + if (au_test_fs_rr(add->path.dentry->d_sb))
27237 + add->perm = AuBrPerm_RR;
27238 + else if (!bindex && !(sb_flags & SB_RDONLY))
27239 + add->perm = AuBrPerm_RW;
27241 + opt->type = Opt_add;
27244 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27251 +static int au_opt_wbr_create(struct super_block *sb,
27252 + struct au_opt_wbr_create *create)
27255 + struct au_sbinfo *sbinfo;
27257 + SiMustWriteLock(sb);
27259 + err = 1; /* handled */
27260 + sbinfo = au_sbi(sb);
27261 + if (sbinfo->si_wbr_create_ops->fin) {
27262 + err = sbinfo->si_wbr_create_ops->fin(sb);
27267 + sbinfo->si_wbr_create = create->wbr_create;
27268 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27269 + switch (create->wbr_create) {
27270 + case AuWbrCreate_MFSRRV:
27271 + case AuWbrCreate_MFSRR:
27272 + case AuWbrCreate_TDMFS:
27273 + case AuWbrCreate_TDMFSV:
27274 + case AuWbrCreate_PMFSRR:
27275 + case AuWbrCreate_PMFSRRV:
27276 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27278 + case AuWbrCreate_MFS:
27279 + case AuWbrCreate_MFSV:
27280 + case AuWbrCreate_PMFS:
27281 + case AuWbrCreate_PMFSV:
27282 + sbinfo->si_wbr_mfs.mfs_expire
27283 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27287 + if (sbinfo->si_wbr_create_ops->init)
27288 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27295 + * plus: processed without an error
27296 + * zero: unprocessed
27298 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27299 + struct au_opts *opts)
27302 + struct au_sbinfo *sbinfo;
27304 + SiMustWriteLock(sb);
27306 + err = 1; /* handled */
27307 + sbinfo = au_sbi(sb);
27308 + switch (opt->type) {
27310 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27311 + sbinfo->si_mntflags |= opt->udba;
27312 + opts->given_udba |= opt->udba;
27317 + au_opt_set(sbinfo->si_mntflags, PLINK);
27319 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27320 + au_plink_put(sb, /*verbose*/1);
27321 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27324 + case Opt_list_plink:
27325 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27326 + au_plink_list(sb);
27331 + au_opt_set(sbinfo->si_mntflags, DIO);
27332 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27334 + au_opt_clr(sbinfo->si_mntflags, DIO);
27335 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27339 + case Opt_fhsm_sec:
27340 + au_fhsm_set(sbinfo, opt->fhsm_second);
27343 + case Opt_diropq_a:
27344 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27346 + case Opt_diropq_w:
27347 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27350 + case Opt_warn_perm:
27352 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27354 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27357 + case Opt_verbose:
27359 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27361 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27366 + au_opt_set(sbinfo->si_mntflags, SUM);
27368 + au_opt_clr(sbinfo->si_mntflags, SUM);
27369 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27373 + au_opt_clr(sbinfo->si_mntflags, SUM);
27374 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27377 + case Opt_wbr_create:
27378 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27380 + case Opt_wbr_copyup:
27381 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27382 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27386 + sbinfo->si_dirwh = opt->dirwh;
27389 + case Opt_rdcache:
27390 + sbinfo->si_rdcache
27391 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27394 + sbinfo->si_rdblk = opt->rdblk;
27397 + sbinfo->si_rdhash = opt->rdhash;
27402 + au_opt_set(sbinfo->si_mntflags, SHWH);
27404 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27407 + case Opt_dirperm1:
27409 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27411 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27414 + case Opt_trunc_xino:
27416 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27418 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27421 + case Opt_trunc_xino_path:
27422 + case Opt_itrunc_xino:
27423 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27429 + case Opt_trunc_xib:
27431 + au_fset_opts(opts->flags, TRUNC_XIB);
27433 + au_fclr_opts(opts->flags, TRUNC_XIB);
27439 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27440 + err = au_dr_opt_set(sb);
27445 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27447 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27448 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27454 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27460 + sb->s_flags |= SB_POSIXACL;
27462 + sb->s_flags &= ~SB_POSIXACL;
27474 + * returns tri-state.
27475 + * plus: processed without an error
27476 + * zero: unprocessed
27479 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27480 + struct au_opts *opts)
27482 + int err, do_refresh;
27485 + switch (opt->type) {
27487 + opt->add.bindex = au_sbbot(sb) + 1;
27488 + if (opt->add.bindex < 0)
27489 + opt->add.bindex = 0;
27491 + /* Always goto add, not fallthrough */
27492 + case Opt_prepend:
27493 + opt->add.bindex = 0;
27495 + add: /* indented label */
27497 + err = au_br_add(sb, &opt->add,
27498 + au_ftest_opts(opts->flags, REMOUNT));
27501 + au_fset_opts(opts->flags, REFRESH);
27507 + err = au_br_del(sb, &opt->del,
27508 + au_ftest_opts(opts->flags, REMOUNT));
27511 + au_fset_opts(opts->flags, TRUNC_XIB);
27512 + au_fset_opts(opts->flags, REFRESH);
27518 + err = au_br_mod(sb, &opt->mod,
27519 + au_ftest_opts(opts->flags, REMOUNT),
27524 + au_fset_opts(opts->flags, REFRESH);
27531 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27532 + struct au_opt_xino **opt_xino,
27533 + struct au_opts *opts)
27538 + switch (opt->type) {
27540 + err = au_xino_set(sb, &opt->xino,
27541 + !!au_ftest_opts(opts->flags, REMOUNT));
27543 + *opt_xino = &opt->xino;
27547 + *opt_xino = (void *)-1;
27554 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27555 + unsigned int pending)
27558 + aufs_bindex_t bindex, bbot;
27559 + unsigned char do_plink, skip, do_free, can_no_dreval;
27560 + struct au_branch *br;
27561 + struct au_wbr *wbr;
27562 + struct dentry *root, *dentry;
27563 + struct inode *dir, *h_dir;
27564 + struct au_sbinfo *sbinfo;
27565 + struct au_hinode *hdir;
27567 + SiMustAnyLock(sb);
27569 + sbinfo = au_sbi(sb);
27570 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27572 + if (!(sb_flags & SB_RDONLY)) {
27573 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27574 + pr_warn("first branch should be rw\n");
27575 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27576 + pr_warn_once("shwh should be used with ro\n");
27579 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27580 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27581 + pr_warn_once("udba=*notify requires xino\n");
27583 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27584 + pr_warn_once("dirperm1 breaks the protection"
27585 + " by the permission bits on the lower branch\n");
27589 + root = sb->s_root;
27590 + dir = d_inode(root);
27591 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27592 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27594 + bbot = au_sbbot(sb);
27595 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27597 + h_dir = au_h_iptr(dir, bindex);
27598 + br = au_sbr(sb, bindex);
27600 + if ((br->br_perm & AuBrAttr_ICEX)
27601 + && !h_dir->i_op->listxattr)
27602 + br->br_perm &= ~AuBrAttr_ICEX;
27603 +#if 0 /* untested */
27604 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27605 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27606 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27610 + wbr = br->br_wbr;
27612 + wbr_wh_read_lock(wbr);
27614 + if (!au_br_writable(br->br_perm)) {
27617 + || (!wbr->wbr_whbase
27618 + && !wbr->wbr_plink
27619 + && !wbr->wbr_orph));
27620 + } else if (!au_br_wh_linkable(br->br_perm)) {
27621 + /* skip = (!br->br_whbase && !br->br_orph); */
27622 + skip = (!wbr || !wbr->wbr_whbase);
27623 + if (skip && wbr) {
27625 + skip = !!wbr->wbr_plink;
27627 + skip = !wbr->wbr_plink;
27630 + /* skip = (br->br_whbase && br->br_ohph); */
27631 + skip = (wbr && wbr->wbr_whbase);
27634 + skip = !!wbr->wbr_plink;
27636 + skip = !wbr->wbr_plink;
27640 + wbr_wh_read_unlock(wbr);
27642 + if (can_no_dreval) {
27643 + dentry = br->br_path.dentry;
27644 + spin_lock(&dentry->d_lock);
27645 + if (dentry->d_flags &
27646 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27647 + can_no_dreval = 0;
27648 + spin_unlock(&dentry->d_lock);
27651 + if (au_br_fhsm(br->br_perm)) {
27653 + AuDebugOn(!br->br_fhsm);
27659 + hdir = au_hi(dir, bindex);
27660 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27662 + wbr_wh_write_lock(wbr);
27663 + err = au_wh_init(br, sb);
27665 + wbr_wh_write_unlock(wbr);
27666 + au_hn_inode_unlock(hdir);
27668 + if (!err && do_free) {
27669 + au_kfree_rcu(wbr);
27670 + br->br_wbr = NULL;
27674 + if (can_no_dreval)
27675 + au_fset_si(sbinfo, NO_DREVAL);
27677 + au_fclr_si(sbinfo, NO_DREVAL);
27680 + au_fset_si(sbinfo, FHSM);
27681 + for (bindex = bbot; bindex >= 0; bindex--) {
27682 + br = au_sbr(sb, bindex);
27683 + if (au_br_fhsm(br->br_perm)) {
27684 + au_fhsm_set_bottom(sb, bindex);
27689 + au_fclr_si(sbinfo, FHSM);
27690 + au_fhsm_set_bottom(sb, -1);
27696 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27699 + unsigned int tmp;
27700 + aufs_bindex_t bindex, bbot;
27701 + struct au_opt *opt;
27702 + struct au_opt_xino *opt_xino, xino;
27703 + struct au_sbinfo *sbinfo;
27704 + struct au_branch *br;
27705 + struct inode *dir;
27707 + SiMustWriteLock(sb);
27712 + while (err >= 0 && opt->type != Opt_tail)
27713 + err = au_opt_simple(sb, opt++, opts);
27716 + else if (unlikely(err < 0))
27719 + /* disable xino and udba temporary */
27720 + sbinfo = au_sbi(sb);
27721 + tmp = sbinfo->si_mntflags;
27722 + au_opt_clr(sbinfo->si_mntflags, XINO);
27723 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27726 + while (err >= 0 && opt->type != Opt_tail)
27727 + err = au_opt_br(sb, opt++, opts);
27730 + else if (unlikely(err < 0))
27733 + bbot = au_sbbot(sb);
27734 + if (unlikely(bbot < 0)) {
27736 + pr_err("no branches\n");
27740 + if (au_opt_test(tmp, XINO))
27741 + au_opt_set(sbinfo->si_mntflags, XINO);
27743 + while (!err && opt->type != Opt_tail)
27744 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27745 + if (unlikely(err))
27748 + err = au_opts_verify(sb, sb->s_flags, tmp);
27749 + if (unlikely(err))
27752 + /* restore xino */
27753 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27754 + xino.file = au_xino_def(sb);
27755 + err = PTR_ERR(xino.file);
27756 + if (IS_ERR(xino.file))
27759 + err = au_xino_set(sb, &xino, /*remount*/0);
27761 + if (unlikely(err))
27765 + /* restore udba */
27766 + tmp &= AuOptMask_UDBA;
27767 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27768 + sbinfo->si_mntflags |= tmp;
27769 + bbot = au_sbbot(sb);
27770 + for (bindex = 0; bindex <= bbot; bindex++) {
27771 + br = au_sbr(sb, bindex);
27772 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27773 + if (unlikely(err))
27774 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27776 + /* go on even if err */
27778 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27779 + dir = d_inode(sb->s_root);
27780 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27787 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27790 + unsigned char no_dreval;
27791 + struct inode *dir;
27792 + struct au_opt_xino *opt_xino;
27793 + struct au_opt *opt;
27794 + struct au_sbinfo *sbinfo;
27796 + SiMustWriteLock(sb);
27798 + err = au_dr_opt_flush(sb);
27799 + if (unlikely(err))
27801 + au_fset_opts(opts->flags, DR_FLUSHED);
27803 + dir = d_inode(sb->s_root);
27804 + sbinfo = au_sbi(sb);
27807 + while (err >= 0 && opt->type != Opt_tail) {
27808 + err = au_opt_simple(sb, opt, opts);
27810 + err = au_opt_br(sb, opt, opts);
27812 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27818 + /* go on even err */
27820 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27821 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27822 + if (unlikely(rerr && !err))
27825 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27826 + au_fset_opts(opts->flags, REFRESH_IDOP);
27828 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27829 + rerr = au_xib_trunc(sb);
27830 + if (unlikely(rerr && !err))
27834 + /* will be handled by the caller */
27835 + if (!au_ftest_opts(opts->flags, REFRESH)
27836 + && (opts->given_udba
27837 + || au_opt_test(sbinfo->si_mntflags, XINO)
27838 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27840 + au_fset_opts(opts->flags, REFRESH);
27842 + AuDbg("status 0x%x\n", opts->flags);
27848 +/* ---------------------------------------------------------------------- */
27850 +unsigned int au_opt_udba(struct super_block *sb)
27852 + return au_mntflags(sb) & AuOptMask_UDBA;
27854 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27855 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27856 +++ linux/fs/aufs/opts.h 2022-03-21 14:49:05.729966343 +0100
27858 +/* SPDX-License-Identifier: GPL-2.0 */
27860 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27862 + * This program, aufs is free software; you can redistribute it and/or modify
27863 + * it under the terms of the GNU General Public License as published by
27864 + * the Free Software Foundation; either version 2 of the License, or
27865 + * (at your option) any later version.
27867 + * This program is distributed in the hope that it will be useful,
27868 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27869 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27870 + * GNU General Public License for more details.
27872 + * You should have received a copy of the GNU General Public License
27873 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27877 + * mount options/flags
27880 +#ifndef __AUFS_OPTS_H__
27881 +#define __AUFS_OPTS_H__
27885 +#include <linux/fs_parser.h>
27886 +#include <linux/namei.h>
27887 +#include <linux/path.h>
27891 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27892 + Opt_idel, Opt_imod,
27893 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27894 + Opt_xino, Opt_noxino,
27895 + Opt_trunc_xino, Opt_trunc_xino_v,
27896 + Opt_trunc_xino_path, Opt_itrunc_xino,
27899 + Opt_plink, Opt_list_plink,
27902 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27904 + Opt_wbr_copyup, Opt_wbr_create,
27906 + Opt_verbose, Opt_noverbose,
27907 + Opt_sum, Opt_wsum,
27911 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27914 +/* ---------------------------------------------------------------------- */
27917 +#define AuOpt_XINO 1 /* external inode number bitmap
27918 + and translation table */
27919 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27920 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27921 +#define AuOpt_UDBA_REVAL (1 << 3)
27922 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27923 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27924 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27925 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27927 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27928 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27929 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27930 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27931 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27932 +#define AuOpt_DIO (1 << 14) /* direct io */
27933 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27935 +#ifndef CONFIG_AUFS_HNOTIFY
27936 +#undef AuOpt_UDBA_HNOTIFY
27937 +#define AuOpt_UDBA_HNOTIFY 0
27939 +#ifndef CONFIG_AUFS_DIRREN
27940 +#undef AuOpt_DIRREN
27941 +#define AuOpt_DIRREN 0
27943 +#ifndef CONFIG_AUFS_SHWH
27945 +#define AuOpt_SHWH 0
27948 +#define AuOpt_Def (AuOpt_XINO \
27949 + | AuOpt_UDBA_REVAL \
27951 + /* | AuOpt_DIRPERM1 */ \
27952 + | AuOpt_WARN_PERM)
27953 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27954 + | AuOpt_UDBA_REVAL \
27955 + | AuOpt_UDBA_HNOTIFY)
27957 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
27959 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27960 +#define au_opt_set(flags, name) do { \
27961 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27962 + ((flags) |= AuOpt_##name); \
27964 +#define au_opt_set_udba(flags, name) do { \
27965 + (flags) &= ~AuOptMask_UDBA; \
27966 + ((flags) |= AuOpt_##name); \
27968 +#define au_opt_clr(flags, name) do { \
27969 + ((flags) &= ~AuOpt_##name); \
27972 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27974 +#ifdef CONFIG_PROC_FS
27977 + return mntflags & ~AuOpt_PLINK;
27981 +/* ---------------------------------------------------------------------- */
27983 +/* policies to select one among multiple writable branches */
27985 + AuWbrCreate_TDP, /* top down parent */
27986 + AuWbrCreate_RR, /* round robin */
27987 + AuWbrCreate_MFS, /* most free space */
27988 + AuWbrCreate_MFSV, /* mfs with seconds */
27989 + AuWbrCreate_MFSRR, /* mfs then rr */
27990 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27991 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27992 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27993 + AuWbrCreate_PMFS, /* parent and mfs */
27994 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27995 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27996 + AuWbrCreate_PMFSRRV, /* plus seconds */
27998 + AuWbrCreate_Def = AuWbrCreate_TDP
28002 + AuWbrCopyup_TDP, /* top down parent */
28003 + AuWbrCopyup_BUP, /* bottom up parent */
28004 + AuWbrCopyup_BU, /* bottom up */
28006 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28009 +/* ---------------------------------------------------------------------- */
28013 +struct au_opt_add {
28014 + aufs_bindex_t bindex;
28017 + struct path path;
28020 +struct au_opt_del {
28022 + struct path h_path;
28025 +struct au_opt_mod {
28028 + struct dentry *h_root;
28031 +struct au_opt_xino {
28033 + struct file *file;
28036 +struct au_opt_xino_itrunc {
28037 + aufs_bindex_t bindex;
28040 +struct au_opt_wbr_create {
28043 + unsigned long long mfsrr_watermark;
28049 + struct au_opt_xino xino;
28050 + struct au_opt_xino_itrunc xino_itrunc;
28051 + struct au_opt_add add;
28052 + struct au_opt_del del;
28053 + struct au_opt_mod mod;
28056 + unsigned int rdblk;
28057 + unsigned int rdhash;
28059 + struct au_opt_wbr_create wbr_create;
28061 + unsigned int fhsm_second;
28062 + bool tf; /* generic flag, true or false */
28067 +#define AuOpts_REMOUNT 1
28068 +#define AuOpts_REFRESH (1 << 1)
28069 +#define AuOpts_TRUNC_XIB (1 << 2)
28070 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28071 +#define AuOpts_REFRESH_IDOP (1 << 4)
28072 +#define AuOpts_DR_FLUSHED (1 << 5)
28073 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28074 +#define au_fset_opts(flags, name) \
28075 + do { (flags) |= AuOpts_##name; } while (0)
28076 +#define au_fclr_opts(flags, name) \
28077 + do { (flags) &= ~AuOpts_##name; } while (0)
28079 +#ifndef CONFIG_AUFS_DIRREN
28080 +#undef AuOpts_DR_FLUSHED
28081 +#define AuOpts_DR_FLUSHED 0
28085 + struct au_opt *opt;
28088 + unsigned int given_udba;
28089 + unsigned int flags;
28090 + unsigned long sb_flags;
28093 +/* ---------------------------------------------------------------------- */
28096 +int au_br_perm_val(char *perm);
28097 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28098 +int au_udba_val(char *str);
28099 +const char *au_optstr_udba(int udba);
28100 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28101 +const char *au_optstr_wbr_create(int wbr_create);
28102 +int au_wbr_copyup_val(char *str);
28103 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28105 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28106 + aufs_bindex_t bindex);
28107 +struct super_block;
28108 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28109 + unsigned int pending);
28110 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28111 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28113 +unsigned int au_opt_udba(struct super_block *sb);
28116 +int aufs_fsctx_init(struct fs_context *fc);
28117 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28119 +#endif /* __KERNEL__ */
28120 +#endif /* __AUFS_OPTS_H__ */
28121 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28122 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28123 +++ linux/fs/aufs/plink.c 2022-03-21 14:49:05.729966343 +0100
28125 +// SPDX-License-Identifier: GPL-2.0
28127 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28129 + * This program, aufs is free software; you can redistribute it and/or modify
28130 + * it under the terms of the GNU General Public License as published by
28131 + * the Free Software Foundation; either version 2 of the License, or
28132 + * (at your option) any later version.
28134 + * This program is distributed in the hope that it will be useful,
28135 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28136 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28137 + * GNU General Public License for more details.
28139 + * You should have received a copy of the GNU General Public License
28140 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28150 + * the pseudo-link maintenance mode.
28151 + * during a user process maintains the pseudo-links,
28152 + * prohibit adding a new plink and branch manipulation.
28156 + * For entry functions which will handle plink, and i_mutex is already held
28158 + * They cannot wait and should return an error at once.
28159 + * Callers has to check the error.
28161 + * For entry functions which will handle plink, but i_mutex is not held
28163 + * They can wait the plink maintenance mode to finish.
28165 + * They behave like F_SETLK and F_SETLKW.
28166 + * If the caller never handle plink, then both flags are unnecessary.
28169 +int au_plink_maint(struct super_block *sb, int flags)
28173 + struct task_struct *parent, *prev;
28174 + struct au_sbinfo *sbi;
28176 + SiMustAnyLock(sb);
28179 + if (!au_opt_test(au_mntflags(sb), PLINK))
28182 + sbi = au_sbi(sb);
28183 + pid = sbi->si_plink_maint_pid;
28184 + if (!pid || pid == current->pid)
28187 + /* todo: it highly depends upon /sbin/mount.aufs */
28189 + parent = current;
28193 + parent = rcu_dereference(parent->real_parent);
28194 + if (parent == prev)
28196 + ppid = task_pid_vnr(parent);
28197 + if (pid == ppid) {
28198 + rcu_read_unlock();
28203 + rcu_read_unlock();
28205 + if (au_ftest_lock(flags, NOPLMW)) {
28206 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28207 + /* AuDebugOn(!lockdep_depth(current)); */
28208 + while (sbi->si_plink_maint_pid) {
28209 + si_read_unlock(sb);
28210 + /* gave up wake_up_bit() */
28211 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28213 + if (au_ftest_lock(flags, FLUSH))
28214 + au_nwt_flush(&sbi->si_nowait);
28215 + si_noflush_read_lock(sb);
28217 + } else if (au_ftest_lock(flags, NOPLM)) {
28218 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28226 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28228 + spin_lock(&sbinfo->si_plink_maint_lock);
28229 + sbinfo->si_plink_maint_pid = 0;
28230 + spin_unlock(&sbinfo->si_plink_maint_lock);
28231 + wake_up_all(&sbinfo->si_plink_wq);
28234 +int au_plink_maint_enter(struct super_block *sb)
28237 + struct au_sbinfo *sbinfo;
28240 + sbinfo = au_sbi(sb);
28241 + /* make sure i am the only one in this fs */
28242 + si_write_lock(sb, AuLock_FLUSH);
28243 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28244 + spin_lock(&sbinfo->si_plink_maint_lock);
28245 + if (!sbinfo->si_plink_maint_pid)
28246 + sbinfo->si_plink_maint_pid = current->pid;
28249 + spin_unlock(&sbinfo->si_plink_maint_lock);
28251 + si_write_unlock(sb);
28256 +/* ---------------------------------------------------------------------- */
28258 +#ifdef CONFIG_AUFS_DEBUG
28259 +void au_plink_list(struct super_block *sb)
28262 + struct au_sbinfo *sbinfo;
28263 + struct hlist_bl_head *hbl;
28264 + struct hlist_bl_node *pos;
28265 + struct au_icntnr *icntnr;
28267 + SiMustAnyLock(sb);
28269 + sbinfo = au_sbi(sb);
28270 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28271 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28273 + for (i = 0; i < AuPlink_NHASH; i++) {
28274 + hbl = sbinfo->si_plink + i;
28275 + hlist_bl_lock(hbl);
28276 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28277 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28278 + hlist_bl_unlock(hbl);
28283 +/* is the inode pseudo-linked? */
28284 +int au_plink_test(struct inode *inode)
28287 + struct au_sbinfo *sbinfo;
28288 + struct hlist_bl_head *hbl;
28289 + struct hlist_bl_node *pos;
28290 + struct au_icntnr *icntnr;
28292 + sbinfo = au_sbi(inode->i_sb);
28293 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28294 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28295 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28298 + i = au_plink_hash(inode->i_ino);
28299 + hbl = sbinfo->si_plink + i;
28300 + hlist_bl_lock(hbl);
28301 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28302 + if (&icntnr->vfs_inode == inode) {
28306 + hlist_bl_unlock(hbl);
28310 +/* ---------------------------------------------------------------------- */
28313 + * generate a name for plink.
28314 + * the file will be stored under AUFS_WH_PLINKDIR.
28316 +/* 20 is max digits length of ulong 64 */
28317 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28319 +static int plink_name(char *name, int len, struct inode *inode,
28320 + aufs_bindex_t bindex)
28323 + struct inode *h_inode;
28325 + h_inode = au_h_iptr(inode, bindex);
28326 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28330 +struct au_do_plink_lkup_args {
28331 + struct dentry **errp;
28332 + struct qstr *tgtname;
28333 + struct path *h_ppath;
28336 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28337 + struct path *h_ppath)
28339 + struct dentry *h_dentry;
28340 + struct inode *h_inode;
28342 + h_inode = d_inode(h_ppath->dentry);
28343 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28344 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28345 + inode_unlock_shared(h_inode);
28350 +static void au_call_do_plink_lkup(void *args)
28352 + struct au_do_plink_lkup_args *a = args;
28353 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28356 +/* lookup the plink-ed @inode under the branch at @bindex */
28357 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28359 + struct dentry *h_dentry;
28360 + struct au_branch *br;
28361 + struct path h_ppath;
28363 + char a[PLINK_NAME_LEN];
28364 + struct qstr tgtname = QSTR_INIT(a, 0);
28366 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28368 + br = au_sbr(inode->i_sb, bindex);
28369 + h_ppath.dentry = br->br_wbr->wbr_plink;
28370 + h_ppath.mnt = au_br_mnt(br);
28371 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28373 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28374 + struct au_do_plink_lkup_args args = {
28375 + .errp = &h_dentry,
28376 + .tgtname = &tgtname,
28377 + .h_ppath = &h_ppath
28380 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28381 + if (unlikely(wkq_err))
28382 + h_dentry = ERR_PTR(wkq_err);
28384 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28389 +/* create a pseudo-link */
28390 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28391 + struct dentry *h_dentry)
28394 + struct path h_path;
28395 + struct inode *h_dir, *delegated;
28397 + h_dir = d_inode(h_ppath->dentry);
28398 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28399 + h_path.mnt = h_ppath->mnt;
28401 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28402 + err = PTR_ERR(h_path.dentry);
28403 + if (IS_ERR(h_path.dentry))
28407 + /* wh.plink dir is not monitored */
28408 + /* todo: is it really safe? */
28409 + if (d_is_positive(h_path.dentry)
28410 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28411 + delegated = NULL;
28412 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28413 + if (unlikely(err == -EWOULDBLOCK)) {
28414 + pr_warn("cannot retry for NFSv4 delegation"
28415 + " for an internal unlink\n");
28418 + dput(h_path.dentry);
28419 + h_path.dentry = NULL;
28423 + if (!err && d_is_negative(h_path.dentry)) {
28424 + delegated = NULL;
28425 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28426 + if (unlikely(err == -EWOULDBLOCK)) {
28427 + pr_warn("cannot retry for NFSv4 delegation"
28428 + " for an internal link\n");
28432 + dput(h_path.dentry);
28435 + inode_unlock(h_dir);
28439 +struct do_whplink_args {
28441 + struct qstr *tgt;
28442 + struct path *h_ppath;
28443 + struct dentry *h_dentry;
28446 +static void call_do_whplink(void *args)
28448 + struct do_whplink_args *a = args;
28449 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28452 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28453 + aufs_bindex_t bindex)
28455 + int err, wkq_err;
28456 + struct au_branch *br;
28457 + struct au_wbr *wbr;
28458 + struct path h_ppath;
28459 + char a[PLINK_NAME_LEN];
28460 + struct qstr tgtname = QSTR_INIT(a, 0);
28462 + br = au_sbr(inode->i_sb, bindex);
28463 + wbr = br->br_wbr;
28464 + h_ppath.dentry = wbr->wbr_plink;
28465 + h_ppath.mnt = au_br_mnt(br);
28466 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28468 + /* always superio. */
28469 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28470 + struct do_whplink_args args = {
28473 + .h_ppath = &h_ppath,
28474 + .h_dentry = h_dentry
28476 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28477 + if (unlikely(wkq_err))
28480 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28486 + * create a new pseudo-link for @h_dentry on @bindex.
28487 + * the linked inode is held in aufs @inode.
28489 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28490 + struct dentry *h_dentry)
28492 + struct super_block *sb;
28493 + struct au_sbinfo *sbinfo;
28494 + struct hlist_bl_head *hbl;
28495 + struct hlist_bl_node *pos;
28496 + struct au_icntnr *icntnr;
28497 + int found, err, cnt, i;
28499 + sb = inode->i_sb;
28500 + sbinfo = au_sbi(sb);
28501 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28502 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28504 + found = au_plink_test(inode);
28508 + i = au_plink_hash(inode->i_ino);
28509 + hbl = sbinfo->si_plink + i;
28512 + hlist_bl_lock(hbl);
28513 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28514 + if (&icntnr->vfs_inode == inode) {
28520 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28521 + hlist_bl_add_head(&icntnr->plink, hbl);
28523 + hlist_bl_unlock(hbl);
28525 + cnt = au_hbl_count(hbl);
28526 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28527 + if (cnt > AUFS_PLINK_WARN)
28528 + AuWarn1(msg ", %d\n", cnt);
28530 + err = whplink(h_dentry, inode, bindex);
28531 + if (unlikely(err)) {
28532 + pr_warn("err %d, damaged pseudo link.\n", err);
28533 + au_hbl_del(&icntnr->plink, hbl);
28534 + iput(&icntnr->vfs_inode);
28537 + iput(&icntnr->vfs_inode);
28540 +/* free all plinks */
28541 +void au_plink_put(struct super_block *sb, int verbose)
28544 + struct au_sbinfo *sbinfo;
28545 + struct hlist_bl_head *hbl;
28546 + struct hlist_bl_node *pos, *tmp;
28547 + struct au_icntnr *icntnr;
28549 + SiMustWriteLock(sb);
28551 + sbinfo = au_sbi(sb);
28552 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28553 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28555 + /* no spin_lock since sbinfo is write-locked */
28557 + for (i = 0; i < AuPlink_NHASH; i++) {
28558 + hbl = sbinfo->si_plink + i;
28559 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28560 + pr_warn("pseudo-link is not flushed");
28563 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28564 + iput(&icntnr->vfs_inode);
28565 + INIT_HLIST_BL_HEAD(hbl);
28569 +void au_plink_clean(struct super_block *sb, int verbose)
28571 + struct dentry *root;
28573 + root = sb->s_root;
28574 + aufs_write_lock(root);
28575 + if (au_opt_test(au_mntflags(sb), PLINK))
28576 + au_plink_put(sb, verbose);
28577 + aufs_write_unlock(root);
28580 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28583 + aufs_bindex_t btop, bbot, bindex;
28586 + btop = au_ibtop(inode);
28587 + bbot = au_ibbot(inode);
28589 + for (bindex = btop; bindex <= bbot; bindex++) {
28590 + if (!au_h_iptr(inode, bindex)
28591 + || au_ii_br_id(inode, bindex) != br_id)
28593 + au_set_h_iptr(inode, bindex, NULL, 0);
28598 + for (bindex = btop; bindex <= bbot; bindex++)
28599 + if (au_h_iptr(inode, bindex)) {
28609 +/* free the plinks on a branch specified by @br_id */
28610 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28612 + struct au_sbinfo *sbinfo;
28613 + struct hlist_bl_head *hbl;
28614 + struct hlist_bl_node *pos, *tmp;
28615 + struct au_icntnr *icntnr;
28616 + struct inode *inode;
28619 + SiMustWriteLock(sb);
28621 + sbinfo = au_sbi(sb);
28622 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28623 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28625 + /* no bit_lock since sbinfo is write-locked */
28626 + for (i = 0; i < AuPlink_NHASH; i++) {
28627 + hbl = sbinfo->si_plink + i;
28628 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28629 + inode = au_igrab(&icntnr->vfs_inode);
28630 + ii_write_lock_child(inode);
28631 + do_put = au_plink_do_half_refresh(inode, br_id);
28633 + hlist_bl_del(&icntnr->plink);
28636 + ii_write_unlock(inode);
28641 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28642 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28643 +++ linux/fs/aufs/poll.c 2022-03-21 14:49:05.729966343 +0100
28645 +// SPDX-License-Identifier: GPL-2.0
28647 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28649 + * This program, aufs is free software; you can redistribute it and/or modify
28650 + * it under the terms of the GNU General Public License as published by
28651 + * the Free Software Foundation; either version 2 of the License, or
28652 + * (at your option) any later version.
28654 + * This program is distributed in the hope that it will be useful,
28655 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28656 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28657 + * GNU General Public License for more details.
28659 + * You should have received a copy of the GNU General Public License
28660 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28665 + * There is only one filesystem which implements ->poll operation, currently.
28670 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28673 + struct file *h_file;
28674 + struct super_block *sb;
28676 + /* We should pretend an error happened. */
28677 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28678 + sb = file->f_path.dentry->d_sb;
28679 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28681 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28682 + if (IS_ERR(h_file)) {
28683 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28687 + mask = vfs_poll(h_file, pt);
28688 + fput(h_file); /* instead of au_read_post() */
28691 + si_read_unlock(sb);
28692 + if (mask & EPOLLERR)
28693 + AuDbg("mask 0x%x\n", mask);
28696 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28697 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28698 +++ linux/fs/aufs/posix_acl.c 2022-03-21 14:49:05.729966343 +0100
28700 +// SPDX-License-Identifier: GPL-2.0
28702 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28704 + * This program, aufs is free software; you can redistribute it and/or modify
28705 + * it under the terms of the GNU General Public License as published by
28706 + * the Free Software Foundation; either version 2 of the License, or
28707 + * (at your option) any later version.
28709 + * This program is distributed in the hope that it will be useful,
28710 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28711 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28712 + * GNU General Public License for more details.
28714 + * You should have received a copy of the GNU General Public License
28715 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28719 + * posix acl operations
28722 +#include <linux/fs.h>
28725 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28727 + struct posix_acl *acl;
28729 + aufs_bindex_t bindex;
28730 + struct inode *h_inode;
28731 + struct super_block *sb;
28733 + acl = ERR_PTR(-ECHILD);
28738 + sb = inode->i_sb;
28739 + si_read_lock(sb, AuLock_FLUSH);
28740 + ii_read_lock_child(inode);
28741 + if (!(sb->s_flags & SB_POSIXACL))
28744 + bindex = au_ibtop(inode);
28745 + h_inode = au_h_iptr(inode, bindex);
28746 + if (unlikely(!h_inode
28747 + || ((h_inode->i_mode & S_IFMT)
28748 + != (inode->i_mode & S_IFMT)))) {
28749 + err = au_busy_or_stale();
28750 + acl = ERR_PTR(err);
28754 + /* always topmost only */
28755 + acl = get_acl(h_inode, type);
28757 + forget_cached_acl(inode, type);
28759 + set_cached_acl(inode, type, acl);
28762 + ii_read_unlock(inode);
28763 + si_read_unlock(sb);
28766 + AuTraceErrPtr(acl);
28770 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28771 + struct posix_acl *acl, int type)
28775 + struct dentry *dentry;
28776 + struct au_sxattr arg = {
28777 + .type = AU_ACL_SET,
28784 + IMustLock(inode);
28786 + if (inode->i_ino == AUFS_ROOT_INO)
28787 + dentry = dget(inode->i_sb->s_root);
28789 + dentry = d_find_alias(inode);
28791 + dentry = d_find_any_alias(inode);
28793 + pr_warn("cannot handle this inode, "
28794 + "please report to aufs-users ML\n");
28800 + ssz = au_sxattr(dentry, inode, &arg);
28801 + /* forget even it if succeeds since the branch might set differently */
28802 + forget_cached_acl(inode, type);
28811 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28812 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28813 +++ linux/fs/aufs/procfs.c 2022-03-21 14:49:05.729966343 +0100
28815 +// SPDX-License-Identifier: GPL-2.0
28817 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28819 + * This program, aufs is free software; you can redistribute it and/or modify
28820 + * it under the terms of the GNU General Public License as published by
28821 + * the Free Software Foundation; either version 2 of the License, or
28822 + * (at your option) any later version.
28824 + * This program is distributed in the hope that it will be useful,
28825 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28826 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28827 + * GNU General Public License for more details.
28829 + * You should have received a copy of the GNU General Public License
28830 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28834 + * procfs interfaces
28837 +#include <linux/proc_fs.h>
28840 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28842 + struct au_sbinfo *sbinfo;
28844 + sbinfo = file->private_data;
28846 + au_plink_maint_leave(sbinfo);
28847 + kobject_put(&sbinfo->si_kobj);
28853 +static void au_procfs_plm_write_clean(struct file *file)
28855 + struct au_sbinfo *sbinfo;
28857 + sbinfo = file->private_data;
28859 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28862 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28865 + struct super_block *sb;
28866 + struct au_sbinfo *sbinfo;
28867 + struct hlist_bl_node *pos;
28870 + if (unlikely(file->private_data))
28874 + /* don't use au_sbilist_lock() here */
28875 + hlist_bl_lock(&au_sbilist);
28876 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28877 + if (id == sysaufs_si_id(sbinfo)) {
28878 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28879 + sb = sbinfo->si_sb;
28882 + hlist_bl_unlock(&au_sbilist);
28885 + if (unlikely(!sb))
28888 + err = au_plink_maint_enter(sb);
28890 + /* keep kobject_get() */
28891 + file->private_data = sbinfo;
28893 + kobject_put(&sbinfo->si_kobj);
28899 + * Accept a valid "si=xxxx" only.
28900 + * Once it is accepted successfully, accept "clean" too.
28902 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28903 + size_t count, loff_t *ppos)
28906 + unsigned long id;
28907 + /* last newline is allowed */
28908 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28911 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28915 + if (unlikely(count > sizeof(buf)))
28918 + err = copy_from_user(buf, ubuf, count);
28919 + if (unlikely(err)) {
28926 + if (!strcmp("clean", buf)) {
28927 + au_procfs_plm_write_clean(file);
28928 + goto out_success;
28929 + } else if (unlikely(strncmp("si=", buf, 3)))
28932 + err = kstrtoul(buf + 3, 16, &id);
28933 + if (unlikely(err))
28936 + err = au_procfs_plm_write_si(file, id);
28937 + if (unlikely(err))
28941 + err = count; /* success */
28946 +static const struct proc_ops au_procfs_plm_op = {
28947 + .proc_write = au_procfs_plm_write,
28948 + .proc_release = au_procfs_plm_release
28951 +/* ---------------------------------------------------------------------- */
28953 +static struct proc_dir_entry *au_procfs_dir;
28955 +void au_procfs_fin(void)
28957 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28958 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28961 +int __init au_procfs_init(void)
28964 + struct proc_dir_entry *entry;
28967 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28968 + if (unlikely(!au_procfs_dir))
28971 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28972 + au_procfs_dir, &au_procfs_plm_op);
28973 + if (unlikely(!entry))
28977 + goto out; /* success */
28981 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28985 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28986 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28987 +++ linux/fs/aufs/rdu.c 2022-03-21 14:49:05.729966343 +0100
28989 +// SPDX-License-Identifier: GPL-2.0
28991 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28993 + * This program, aufs is free software; you can redistribute it and/or modify
28994 + * it under the terms of the GNU General Public License as published by
28995 + * the Free Software Foundation; either version 2 of the License, or
28996 + * (at your option) any later version.
28998 + * This program is distributed in the hope that it will be useful,
28999 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29000 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29001 + * GNU General Public License for more details.
29003 + * You should have received a copy of the GNU General Public License
29004 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29008 + * readdir in userspace.
29011 +#include <linux/compat.h>
29012 +#include <linux/fs_stack.h>
29013 +#include <linux/security.h>
29016 +/* bits for struct aufs_rdu.flags */
29017 +#define AuRdu_CALLED 1
29018 +#define AuRdu_CONT (1 << 1)
29019 +#define AuRdu_FULL (1 << 2)
29020 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29021 +#define au_fset_rdu(flags, name) \
29022 + do { (flags) |= AuRdu_##name; } while (0)
29023 +#define au_fclr_rdu(flags, name) \
29024 + do { (flags) &= ~AuRdu_##name; } while (0)
29026 +struct au_rdu_arg {
29027 + struct dir_context ctx;
29028 + struct aufs_rdu *rdu;
29029 + union au_rdu_ent_ul ent;
29030 + unsigned long end;
29032 + struct super_block *sb;
29036 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29037 + loff_t offset, u64 h_ino, unsigned int d_type)
29040 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29041 + struct aufs_rdu *rdu = arg->rdu;
29042 + struct au_rdu_ent ent;
29046 + au_fset_rdu(rdu->cookie.flags, CALLED);
29047 + len = au_rdu_len(nlen);
29048 + if (arg->ent.ul + len < arg->end) {
29050 + ent.bindex = rdu->cookie.bindex;
29051 + ent.type = d_type;
29053 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29054 + ent.type = DT_UNKNOWN;
29056 + /* unnecessary to support mmap_sem since this is a dir */
29058 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29060 + if (copy_to_user(arg->ent.e->name, name, nlen))
29062 + /* the terminating NULL */
29063 + if (__put_user(0, arg->ent.e->name + nlen))
29066 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29067 + arg->ent.ul += len;
29071 + au_fset_rdu(rdu->cookie.flags, FULL);
29073 + rdu->tail = arg->ent;
29077 + /* AuTraceErr(err); */
29081 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29085 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29087 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29088 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29090 + if (unlikely(offset != cookie->h_pos))
29096 + au_fclr_rdu(cookie->flags, CALLED);
29098 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29102 + && au_ftest_rdu(cookie->flags, CALLED)
29103 + && !au_ftest_rdu(cookie->flags, FULL));
29104 + cookie->h_pos = h_file->f_pos;
29111 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29114 + aufs_bindex_t bbot;
29115 + struct au_rdu_arg arg = {
29117 + .actor = au_rdu_fill
29120 + struct dentry *dentry;
29121 + struct inode *inode;
29122 + struct file *h_file;
29123 + struct au_rdu_cookie *cookie = &rdu->cookie;
29125 + /* VERIFY_WRITE */
29126 + err = !access_ok(rdu->ent.e, rdu->sz);
29127 + if (unlikely(err)) {
29133 + rdu->tail = rdu->ent;
29136 + arg.ent = rdu->ent;
29137 + arg.end = arg.ent.ul;
29138 + arg.end += rdu->sz;
29141 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
29144 + err = security_file_permission(file, MAY_READ);
29146 + if (unlikely(err))
29149 + dentry = file->f_path.dentry;
29150 + inode = d_inode(dentry);
29151 + inode_lock_shared(inode);
29153 + arg.sb = inode->i_sb;
29154 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29155 + if (unlikely(err))
29157 + err = au_alive_dir(dentry);
29158 + if (unlikely(err))
29160 + /* todo: reval? */
29161 + fi_read_lock(file);
29164 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29165 + && cookie->generation != au_figen(file)))
29170 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29172 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29174 + bbot = au_fbtop(file);
29175 + if (cookie->bindex < bbot)
29176 + cookie->bindex = bbot;
29177 + bbot = au_fbbot_dir(file);
29178 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29179 + for (; !err && cookie->bindex <= bbot;
29180 + cookie->bindex++, cookie->h_pos = 0) {
29181 + h_file = au_hf_dir(file, cookie->bindex);
29185 + au_fclr_rdu(cookie->flags, FULL);
29186 + err = au_rdu_do(h_file, &arg);
29188 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29191 + AuDbg("rent %llu\n", rdu->rent);
29193 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29194 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29195 + au_fset_rdu(cookie->flags, CONT);
29196 + cookie->generation = au_figen(file);
29199 + ii_read_lock_child(inode);
29200 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29201 + ii_read_unlock(inode);
29204 + fi_read_unlock(file);
29206 + si_read_unlock(arg.sb);
29208 + inode_unlock_shared(inode);
29214 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29218 + unsigned long long nent;
29219 + union au_rdu_ent_ul *u;
29220 + struct au_rdu_ent ent;
29221 + struct super_block *sb;
29224 + nent = rdu->nent;
29226 + sb = file->f_path.dentry->d_sb;
29227 + si_read_lock(sb, AuLock_FLUSH);
29228 + while (nent-- > 0) {
29229 + /* unnecessary to support mmap_sem since this is a dir */
29230 + err = copy_from_user(&ent, u->e, sizeof(ent));
29232 + /* VERIFY_WRITE */
29233 + err = !access_ok(&u->e->ino, sizeof(ino));
29234 + if (unlikely(err)) {
29240 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29242 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29244 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29246 + if (unlikely(err)) {
29251 + err = __put_user(ino, &u->e->ino);
29252 + if (unlikely(err)) {
29257 + u->ul += au_rdu_len(ent.nlen);
29259 + si_read_unlock(sb);
29264 +/* ---------------------------------------------------------------------- */
29266 +static int au_rdu_verify(struct aufs_rdu *rdu)
29268 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29269 + "%llu, b%d, 0x%x, g%u}\n",
29270 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29272 + rdu->rent, rdu->shwh, rdu->full,
29273 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29274 + rdu->cookie.generation);
29276 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29280 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29284 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29287 + struct aufs_rdu rdu;
29288 + void __user *p = (void __user *)arg;
29290 + err = copy_from_user(&rdu, p, sizeof(rdu));
29291 + if (unlikely(err)) {
29296 + err = au_rdu_verify(&rdu);
29297 + if (unlikely(err))
29301 + case AUFS_CTL_RDU:
29302 + err = au_rdu(file, &rdu);
29303 + if (unlikely(err))
29306 + e = copy_to_user(p, &rdu, sizeof(rdu));
29307 + if (unlikely(e)) {
29312 + case AUFS_CTL_RDU_INO:
29313 + err = au_rdu_ino(file, &rdu);
29317 + /* err = -ENOTTY; */
29326 +#ifdef CONFIG_COMPAT
29327 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29330 + struct aufs_rdu rdu;
29331 + void __user *p = compat_ptr(arg);
29333 + /* todo: get_user()? */
29334 + err = copy_from_user(&rdu, p, sizeof(rdu));
29335 + if (unlikely(err)) {
29340 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29341 + err = au_rdu_verify(&rdu);
29342 + if (unlikely(err))
29346 + case AUFS_CTL_RDU:
29347 + err = au_rdu(file, &rdu);
29348 + if (unlikely(err))
29351 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29352 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29353 + e = copy_to_user(p, &rdu, sizeof(rdu));
29354 + if (unlikely(e)) {
29359 + case AUFS_CTL_RDU_INO:
29360 + err = au_rdu_ino(file, &rdu);
29364 + /* err = -ENOTTY; */
29373 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29374 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29375 +++ linux/fs/aufs/rwsem.h 2022-03-21 14:49:05.729966343 +0100
29377 +/* SPDX-License-Identifier: GPL-2.0 */
29379 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29381 + * This program, aufs is free software; you can redistribute it and/or modify
29382 + * it under the terms of the GNU General Public License as published by
29383 + * the Free Software Foundation; either version 2 of the License, or
29384 + * (at your option) any later version.
29386 + * This program is distributed in the hope that it will be useful,
29387 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29388 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29389 + * GNU General Public License for more details.
29391 + * You should have received a copy of the GNU General Public License
29392 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29396 + * simple read-write semaphore wrappers
29399 +#ifndef __AUFS_RWSEM_H__
29400 +#define __AUFS_RWSEM_H__
29404 +#include "debug.h"
29406 +/* in the future, the name 'au_rwsem' will be totally gone */
29407 +#define au_rwsem rw_semaphore
29409 +/* to debug easier, do not make them inlined functions */
29410 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29412 +#ifdef CONFIG_LOCKDEP
29413 +/* rwsem_is_locked() is unusable */
29414 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29415 + && !lockdep_recursing(current) \
29417 + && !lockdep_is_held_type(rw, 1))
29418 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29419 + && !lockdep_recursing(current) \
29421 + && !lockdep_is_held_type(rw, 0))
29422 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29423 + && !lockdep_recursing(current) \
29425 + && !lockdep_is_held(rw))
29426 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29427 + && !lockdep_recursing(current) \
29429 + && lockdep_is_held(rw))
29431 +#define AuRwMustReadLock(rw) do {} while (0)
29432 +#define AuRwMustWriteLock(rw) do {} while (0)
29433 +#define AuRwMustAnyLock(rw) do {} while (0)
29434 +#define AuRwDestroy(rw) do {} while (0)
29437 +#define au_rw_init(rw) init_rwsem(rw)
29439 +#define au_rw_init_wlock(rw) do { \
29440 + au_rw_init(rw); \
29441 + down_write(rw); \
29444 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29445 + au_rw_init(rw); \
29446 + down_write_nested(rw, lsc); \
29449 +#define au_rw_read_lock(rw) down_read(rw)
29450 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29451 +#define au_rw_read_unlock(rw) up_read(rw)
29452 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29453 +#define au_rw_write_lock(rw) down_write(rw)
29454 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29455 +#define au_rw_write_unlock(rw) up_write(rw)
29456 +/* why is not _nested version defined? */
29457 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29458 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29460 +#endif /* __KERNEL__ */
29461 +#endif /* __AUFS_RWSEM_H__ */
29462 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29463 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29464 +++ linux/fs/aufs/sbinfo.c 2022-03-21 14:49:05.729966343 +0100
29466 +// SPDX-License-Identifier: GPL-2.0
29468 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29470 + * This program, aufs is free software; you can redistribute it and/or modify
29471 + * it under the terms of the GNU General Public License as published by
29472 + * the Free Software Foundation; either version 2 of the License, or
29473 + * (at your option) any later version.
29475 + * This program is distributed in the hope that it will be useful,
29476 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29477 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29478 + * GNU General Public License for more details.
29480 + * You should have received a copy of the GNU General Public License
29481 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29485 + * superblock private data
29488 +#include <linux/iversion.h>
29492 + * they are necessary regardless sysfs is disabled.
29494 +void au_si_free(struct kobject *kobj)
29497 + struct au_sbinfo *sbinfo;
29498 + char *locked __maybe_unused; /* debug only */
29500 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29501 + for (i = 0; i < AuPlink_NHASH; i++)
29502 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29503 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29505 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29506 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29507 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29508 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29510 + dbgaufs_si_fin(sbinfo);
29511 + au_rw_write_lock(&sbinfo->si_rwsem);
29512 + au_br_free(sbinfo);
29513 + au_rw_write_unlock(&sbinfo->si_rwsem);
29515 + au_kfree_try_rcu(sbinfo->si_branch);
29516 + mutex_destroy(&sbinfo->si_xib_mtx);
29517 + AuRwDestroy(&sbinfo->si_rwsem);
29519 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29520 + /* si_nfiles is waited too */
29521 + au_kfree_rcu(sbinfo);
29524 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29526 + struct au_sbinfo *sbinfo;
29530 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29531 + if (unlikely(!sbinfo))
29534 + /* will be reallocated separately */
29535 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29536 + if (unlikely(!sbinfo->si_branch))
29539 + err = sysaufs_si_init(sbinfo);
29541 + dbgaufs_si_null(sbinfo);
29542 + err = dbgaufs_si_init(sbinfo);
29543 + if (unlikely(err))
29544 + kobject_put(&sbinfo->si_kobj);
29546 + if (unlikely(err))
29549 + au_nwt_init(&sbinfo->si_nowait);
29550 + au_rw_init_wlock(&sbinfo->si_rwsem);
29552 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29553 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29555 + sbinfo->si_bbot = -1;
29556 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29558 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29559 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29560 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29561 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29563 + au_fhsm_init(sbinfo);
29565 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29567 + sbinfo->si_xino_jiffy = jiffies;
29568 + sbinfo->si_xino_expire
29569 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29570 + mutex_init(&sbinfo->si_xib_mtx);
29571 + /* leave si_xib_last_pindex and si_xib_next_bit */
29573 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29575 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29576 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29577 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29578 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29580 + for (i = 0; i < AuPlink_NHASH; i++)
29581 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29582 + init_waitqueue_head(&sbinfo->si_plink_wq);
29583 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29585 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29587 + /* with getattr by default */
29588 + sbinfo->si_iop_array = aufs_iop;
29590 + /* leave other members for sysaufs and si_mnt. */
29591 + sbinfo->si_sb = sb;
29593 + sb->s_fs_info = sbinfo;
29596 + return sbinfo; /* success */
29599 + au_kfree_try_rcu(sbinfo->si_branch);
29601 + au_kfree_rcu(sbinfo);
29603 + return ERR_PTR(err);
29606 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29609 + struct au_branch **brp;
29611 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29614 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29615 + if (unlikely(!sz))
29616 + sz = sizeof(*brp);
29617 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29620 + sbinfo->si_branch = brp;
29627 +/* ---------------------------------------------------------------------- */
29629 +unsigned int au_sigen_inc(struct super_block *sb)
29631 + unsigned int gen;
29632 + struct inode *inode;
29634 + SiMustWriteLock(sb);
29636 + gen = ++au_sbi(sb)->si_generation;
29637 + au_update_digen(sb->s_root);
29638 + inode = d_inode(sb->s_root);
29639 + au_update_iigen(inode, /*half*/0);
29640 + inode_inc_iversion(inode);
29644 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29646 + aufs_bindex_t br_id;
29648 + struct au_sbinfo *sbinfo;
29650 + SiMustWriteLock(sb);
29652 + sbinfo = au_sbi(sb);
29653 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29654 + br_id = ++sbinfo->si_last_br_id;
29655 + AuDebugOn(br_id < 0);
29656 + if (br_id && au_br_index(sb, br_id) < 0)
29663 +/* ---------------------------------------------------------------------- */
29665 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29666 +int si_read_lock(struct super_block *sb, int flags)
29671 + if (au_ftest_lock(flags, FLUSH))
29672 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29674 + si_noflush_read_lock(sb);
29675 + err = au_plink_maint(sb, flags);
29676 + if (unlikely(err))
29677 + si_read_unlock(sb);
29682 +int si_write_lock(struct super_block *sb, int flags)
29686 + if (au_ftest_lock(flags, FLUSH))
29687 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29689 + si_noflush_write_lock(sb);
29690 + err = au_plink_maint(sb, flags);
29691 + if (unlikely(err))
29692 + si_write_unlock(sb);
29697 +/* dentry and super_block lock. call at entry point */
29698 +int aufs_read_lock(struct dentry *dentry, int flags)
29701 + struct super_block *sb;
29703 + sb = dentry->d_sb;
29704 + err = si_read_lock(sb, flags);
29705 + if (unlikely(err))
29708 + if (au_ftest_lock(flags, DW))
29709 + di_write_lock_child(dentry);
29711 + di_read_lock_child(dentry, flags);
29713 + if (au_ftest_lock(flags, GEN)) {
29714 + err = au_digen_test(dentry, au_sigen(sb));
29715 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29716 + AuDebugOn(!err && au_dbrange_test(dentry));
29718 + err = au_dbrange_test(dentry);
29719 + if (unlikely(err))
29720 + aufs_read_unlock(dentry, flags);
29727 +void aufs_read_unlock(struct dentry *dentry, int flags)
29729 + if (au_ftest_lock(flags, DW))
29730 + di_write_unlock(dentry);
29732 + di_read_unlock(dentry, flags);
29733 + si_read_unlock(dentry->d_sb);
29736 +void aufs_write_lock(struct dentry *dentry)
29738 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29739 + di_write_lock_child(dentry);
29742 +void aufs_write_unlock(struct dentry *dentry)
29744 + di_write_unlock(dentry);
29745 + si_write_unlock(dentry->d_sb);
29748 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29751 + unsigned int sigen;
29752 + struct super_block *sb;
29755 + err = si_read_lock(sb, flags);
29756 + if (unlikely(err))
29759 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29761 + if (au_ftest_lock(flags, GEN)) {
29762 + sigen = au_sigen(sb);
29763 + err = au_digen_test(d1, sigen);
29764 + AuDebugOn(!err && au_dbrange_test(d1));
29766 + err = au_digen_test(d2, sigen);
29767 + AuDebugOn(!err && au_dbrange_test(d2));
29769 + if (unlikely(err))
29770 + aufs_read_and_write_unlock2(d1, d2);
29777 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29779 + di_write_unlock2(d1, d2);
29780 + si_read_unlock(d1->d_sb);
29782 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29783 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29784 +++ linux/fs/aufs/super.c 2022-03-21 14:49:05.729966343 +0100
29786 +// SPDX-License-Identifier: GPL-2.0
29788 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29790 + * This program, aufs is free software; you can redistribute it and/or modify
29791 + * it under the terms of the GNU General Public License as published by
29792 + * the Free Software Foundation; either version 2 of the License, or
29793 + * (at your option) any later version.
29795 + * This program is distributed in the hope that it will be useful,
29796 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29797 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29798 + * GNU General Public License for more details.
29800 + * You should have received a copy of the GNU General Public License
29801 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29805 + * mount and super_block operations
29808 +#include <linux/iversion.h>
29809 +#include <linux/mm.h>
29810 +#include <linux/seq_file.h>
29811 +#include <linux/statfs.h>
29812 +#include <linux/vmalloc.h>
29816 + * super_operations
29818 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29820 + struct au_icntnr *c;
29822 + c = au_cache_alloc_icntnr();
29824 + au_icntnr_init(c);
29825 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29826 + c->iinfo.ii_hinode = NULL;
29827 + return &c->vfs_inode;
29832 +static void aufs_destroy_inode(struct inode *inode)
29834 + if (!au_is_bad_inode(inode))
29835 + au_iinfo_fin(inode);
29838 +static void aufs_free_inode(struct inode *inode)
29840 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29843 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29845 + struct inode *inode;
29848 + inode = iget_locked(sb, ino);
29849 + if (unlikely(!inode)) {
29850 + inode = ERR_PTR(-ENOMEM);
29853 + if (!(inode->i_state & I_NEW))
29856 + err = au_xigen_new(inode);
29858 + err = au_iinfo_init(inode);
29860 + inode_inc_iversion(inode);
29862 + iget_failed(inode);
29863 + inode = ERR_PTR(err);
29867 + /* never return NULL */
29868 + AuDebugOn(!inode);
29869 + AuTraceErrPtr(inode);
29873 +/* lock free root dinfo */
29874 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29877 + aufs_bindex_t bindex, bbot;
29878 + struct path path;
29879 + struct au_hdentry *hdp;
29880 + struct au_branch *br;
29881 + au_br_perm_str_t perm;
29884 + bbot = au_sbbot(sb);
29886 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29887 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29888 + br = au_sbr(sb, bindex);
29889 + path.mnt = au_br_mnt(br);
29890 + path.dentry = hdp->hd_dentry;
29891 + err = au_seq_path(seq, &path);
29893 + au_optstr_br_perm(&perm, br->br_perm);
29894 + seq_printf(seq, "=%s", perm.a);
29895 + if (bindex != bbot)
29896 + seq_putc(seq, ':');
29899 + if (unlikely(err || seq_has_overflowed(seq)))
29905 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29906 + const char *append)
29911 + while (*pat != ':')
29914 + strcpy(p, append);
29915 + AuDebugOn(strlen(fmt) >= len);
29918 +static void au_show_wbr_create(struct seq_file *m, int v,
29919 + struct au_sbinfo *sbinfo)
29923 + struct au_wbr_mfs *mfs;
29925 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29927 + seq_puts(m, ",create=");
29928 + pat = au_optstr_wbr_create(v);
29929 + mfs = &sbinfo->si_wbr_mfs;
29931 + case AuWbrCreate_TDP:
29932 + case AuWbrCreate_RR:
29933 + case AuWbrCreate_MFS:
29934 + case AuWbrCreate_PMFS:
29935 + seq_puts(m, pat);
29937 + case AuWbrCreate_MFSRR:
29938 + case AuWbrCreate_TDMFS:
29939 + case AuWbrCreate_PMFSRR:
29940 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29941 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29943 + case AuWbrCreate_MFSV:
29944 + case AuWbrCreate_PMFSV:
29945 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29946 + seq_printf(m, fmt,
29947 + jiffies_to_msecs(mfs->mfs_expire)
29950 + case AuWbrCreate_MFSRRV:
29951 + case AuWbrCreate_TDMFSV:
29952 + case AuWbrCreate_PMFSRRV:
29953 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29954 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29955 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29962 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29964 +#ifdef CONFIG_SYSFS
29968 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29969 + aufs_bindex_t bindex, brid;
29970 + struct qstr *name;
29972 + struct dentry *d, *h_root;
29973 + struct au_branch *br;
29975 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29978 + f = au_sbi(sb)->si_xib;
29982 + /* stop printing the default xino path on the first writable branch */
29984 + bindex = au_xi_root(sb, f->f_path.dentry);
29985 + if (bindex >= 0) {
29986 + br = au_sbr_sb(sb, bindex);
29987 + h_root = au_br_dentry(br);
29990 + d = f->f_path.dentry;
29991 + name = &d->d_name;
29992 + /* safe ->d_parent because the file is unlinked */
29993 + if (d->d_parent == h_root
29994 + && name->len == len
29995 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29998 + seq_puts(seq, ",xino=");
29999 + err = au_xino_path(seq, f);
30006 +/* seq_file will re-call me in case of too long string */
30007 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30010 + unsigned int mnt_flags, v;
30011 + struct super_block *sb;
30012 + struct au_sbinfo *sbinfo;
30014 +#define AuBool(name, str) do { \
30015 + v = au_opt_test(mnt_flags, name); \
30016 + if (v != au_opt_test(AuOpt_Def, name)) \
30017 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30020 +#define AuStr(name, str) do { \
30021 + v = mnt_flags & AuOptMask_##name; \
30022 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30023 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30026 +#define AuUInt(name, str, val) do { \
30027 + if (val != AUFS_##name##_DEF) \
30028 + seq_printf(m, "," #str "=%u", val); \
30031 + sb = dentry->d_sb;
30032 + if (sb->s_flags & SB_POSIXACL)
30033 + seq_puts(m, ",acl");
30034 +#if 0 /* reserved for future use */
30035 + if (sb->s_flags & SB_I_VERSION)
30036 + seq_puts(m, ",i_version");
30039 + /* lock free root dinfo */
30040 + si_noflush_read_lock(sb);
30041 + sbinfo = au_sbi(sb);
30042 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30044 + mnt_flags = au_mntflags(sb);
30045 + if (au_opt_test(mnt_flags, XINO)) {
30046 + err = au_show_xino(m, sb);
30047 + if (unlikely(err))
30050 + seq_puts(m, ",noxino");
30052 + AuBool(TRUNC_XINO, trunc_xino);
30053 + AuStr(UDBA, udba);
30054 + AuBool(SHWH, shwh);
30055 + AuBool(PLINK, plink);
30056 + AuBool(DIO, dio);
30057 + AuBool(DIRPERM1, dirperm1);
30059 + v = sbinfo->si_wbr_create;
30060 + if (v != AuWbrCreate_Def)
30061 + au_show_wbr_create(m, v, sbinfo);
30063 + v = sbinfo->si_wbr_copyup;
30064 + if (v != AuWbrCopyup_Def)
30065 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30067 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30068 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30069 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30071 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30073 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30074 + AuUInt(RDCACHE, rdcache, v);
30076 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30077 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30079 + au_fhsm_show(m, sbinfo);
30081 + AuBool(DIRREN, dirren);
30082 + AuBool(SUM, sum);
30083 + /* AuBool(SUM_W, wsum); */
30084 + AuBool(WARN_PERM, warn_perm);
30085 + AuBool(VERBOSE, verbose);
30088 + /* be sure to print "br:" last */
30089 + if (!sysaufs_brs) {
30090 + seq_puts(m, ",br:");
30091 + au_show_brs(m, sb);
30093 + si_read_unlock(sb);
30101 +/* ---------------------------------------------------------------------- */
30103 +/* sum mode which returns the summation for statfs(2) */
30105 +static u64 au_add_till_max(u64 a, u64 b)
30113 + return ULLONG_MAX;
30116 +static u64 au_mul_till_max(u64 a, long mul)
30124 + return ULLONG_MAX;
30127 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30130 + long bsize, factor;
30131 + u64 blocks, bfree, bavail, files, ffree;
30132 + aufs_bindex_t bbot, bindex, i;
30133 + unsigned char shared;
30134 + struct path h_path;
30135 + struct super_block *h_sb;
30138 + bsize = LONG_MAX;
30144 + bbot = au_sbbot(sb);
30145 + for (bindex = 0; bindex <= bbot; bindex++) {
30146 + h_path.mnt = au_sbr_mnt(sb, bindex);
30147 + h_sb = h_path.mnt->mnt_sb;
30149 + for (i = 0; !shared && i < bindex; i++)
30150 + shared = (au_sbr_sb(sb, i) == h_sb);
30154 + /* sb->s_root for NFS is unreliable */
30155 + h_path.dentry = h_path.mnt->mnt_root;
30156 + err = vfs_statfs(&h_path, buf);
30157 + if (unlikely(err))
30160 + if (bsize > buf->f_bsize) {
30162 + * we will reduce bsize, so we have to expand blocks
30163 + * etc. to match them again
30165 + factor = (bsize / buf->f_bsize);
30166 + blocks = au_mul_till_max(blocks, factor);
30167 + bfree = au_mul_till_max(bfree, factor);
30168 + bavail = au_mul_till_max(bavail, factor);
30169 + bsize = buf->f_bsize;
30172 + factor = (buf->f_bsize / bsize);
30173 + blocks = au_add_till_max(blocks,
30174 + au_mul_till_max(buf->f_blocks, factor));
30175 + bfree = au_add_till_max(bfree,
30176 + au_mul_till_max(buf->f_bfree, factor));
30177 + bavail = au_add_till_max(bavail,
30178 + au_mul_till_max(buf->f_bavail, factor));
30179 + files = au_add_till_max(files, buf->f_files);
30180 + ffree = au_add_till_max(ffree, buf->f_ffree);
30183 + buf->f_bsize = bsize;
30184 + buf->f_blocks = blocks;
30185 + buf->f_bfree = bfree;
30186 + buf->f_bavail = bavail;
30187 + buf->f_files = files;
30188 + buf->f_ffree = ffree;
30189 + buf->f_frsize = 0;
30195 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30198 + struct path h_path;
30199 + struct super_block *sb;
30201 + /* lock free root dinfo */
30202 + sb = dentry->d_sb;
30203 + si_noflush_read_lock(sb);
30204 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30205 + /* sb->s_root for NFS is unreliable */
30206 + h_path.mnt = au_sbr_mnt(sb, 0);
30207 + h_path.dentry = h_path.mnt->mnt_root;
30208 + err = vfs_statfs(&h_path, buf);
30210 + err = au_statfs_sum(sb, buf);
30211 + si_read_unlock(sb);
30214 + buf->f_type = AUFS_SUPER_MAGIC;
30215 + buf->f_namelen = AUFS_MAX_NAMELEN;
30216 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30218 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30223 +/* ---------------------------------------------------------------------- */
30225 +static int aufs_sync_fs(struct super_block *sb, int wait)
30228 + aufs_bindex_t bbot, bindex;
30229 + struct au_branch *br;
30230 + struct super_block *h_sb;
30233 + si_noflush_read_lock(sb);
30234 + bbot = au_sbbot(sb);
30235 + for (bindex = 0; bindex <= bbot; bindex++) {
30236 + br = au_sbr(sb, bindex);
30237 + if (!au_br_writable(br->br_perm))
30240 + h_sb = au_sbr_sb(sb, bindex);
30241 + e = vfsub_sync_filesystem(h_sb);
30242 + if (unlikely(e && !err))
30244 + /* go on even if an error happens */
30246 + si_read_unlock(sb);
30251 +/* ---------------------------------------------------------------------- */
30253 +/* final actions when unmounting a file system */
30254 +static void aufs_put_super(struct super_block *sb)
30256 + struct au_sbinfo *sbinfo;
30258 + sbinfo = au_sbi(sb);
30260 + kobject_put(&sbinfo->si_kobj);
30263 +/* ---------------------------------------------------------------------- */
30265 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30266 + struct super_block *sb, void *arg)
30269 + unsigned long long n, sz;
30276 + if (*hint > ULLONG_MAX / sizeof(array)) {
30277 + array = ERR_PTR(-EMFILE);
30278 + pr_err("hint %llu\n", *hint);
30282 + sz = sizeof(array) * *hint;
30283 + array = kzalloc(sz, GFP_NOFS);
30284 + if (unlikely(!array))
30285 + array = vzalloc(sz);
30286 + if (unlikely(!array)) {
30287 + array = ERR_PTR(-ENOMEM);
30291 + n = cb(sb, array, *hint, arg);
30292 + AuDebugOn(n > *hint);
30299 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30300 + unsigned long long max __maybe_unused,
30303 + unsigned long long n;
30304 + struct inode **p, *inode;
30305 + struct list_head *head;
30310 + spin_lock(&sb->s_inode_list_lock);
30311 + list_for_each_entry(inode, head, i_sb_list) {
30312 + if (!au_is_bad_inode(inode)
30313 + && au_ii(inode)->ii_btop >= 0) {
30314 + spin_lock(&inode->i_lock);
30315 + if (atomic_read(&inode->i_count)) {
30319 + AuDebugOn(n > max);
30321 + spin_unlock(&inode->i_lock);
30324 + spin_unlock(&sb->s_inode_list_lock);
30329 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30331 + struct au_sbinfo *sbi;
30333 + sbi = au_sbi(sb);
30334 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30335 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30338 +void au_iarray_free(struct inode **a, unsigned long long max)
30340 + unsigned long long ull;
30342 + for (ull = 0; ull < max; ull++)
30347 +/* ---------------------------------------------------------------------- */
30350 + * refresh dentry and inode at remount time.
30352 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30353 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30354 + struct dentry *parent)
30358 + di_write_lock_child(dentry);
30359 + di_read_lock_parent(parent, AuLock_IR);
30360 + err = au_refresh_dentry(dentry, parent);
30361 + if (!err && dir_flags)
30362 + au_hn_reset(d_inode(dentry), dir_flags);
30363 + di_read_unlock(parent, AuLock_IR);
30364 + di_write_unlock(dentry);
30369 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30370 + struct au_sbinfo *sbinfo,
30371 + const unsigned int dir_flags, unsigned int do_idop)
30374 + struct dentry *parent;
30377 + parent = dget_parent(dentry);
30378 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30379 + if (d_really_is_positive(dentry)) {
30380 + if (!d_is_dir(dentry))
30381 + err = au_do_refresh(dentry, /*dir_flags*/0,
30384 + err = au_do_refresh(dentry, dir_flags, parent);
30385 + if (unlikely(err))
30386 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30389 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30390 + AuDbgDentry(dentry);
30396 + au_refresh_dop(dentry, /*force_reval*/0);
30398 + au_refresh_dop(dentry, /*force_reval*/1);
30404 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30406 + int err, i, j, ndentry, e;
30407 + unsigned int sigen;
30408 + struct au_dcsub_pages dpages;
30409 + struct au_dpage *dpage;
30410 + struct dentry **dentries, *d;
30411 + struct au_sbinfo *sbinfo;
30412 + struct dentry *root = sb->s_root;
30413 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30416 + au_refresh_dop(root, /*force_reval*/0);
30418 + err = au_dpages_init(&dpages, GFP_NOFS);
30419 + if (unlikely(err))
30421 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30422 + if (unlikely(err))
30425 + sigen = au_sigen(sb);
30426 + sbinfo = au_sbi(sb);
30427 + for (i = 0; i < dpages.ndpage; i++) {
30428 + dpage = dpages.dpages + i;
30429 + dentries = dpage->dentries;
30430 + ndentry = dpage->ndentry;
30431 + for (j = 0; j < ndentry; j++) {
30433 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30435 + if (unlikely(e && !err))
30437 + /* go on even err */
30442 + au_dpages_free(&dpages);
30447 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30450 + unsigned int sigen;
30451 + unsigned long long max, ull;
30452 + struct inode *inode, **array;
30454 + array = au_iarray_alloc(sb, &max);
30455 + err = PTR_ERR(array);
30456 + if (IS_ERR(array))
30460 + sigen = au_sigen(sb);
30461 + for (ull = 0; ull < max; ull++) {
30462 + inode = array[ull];
30463 + if (unlikely(!inode))
30467 + ii_write_lock_child(inode);
30468 + if (au_iigen(inode, NULL) != sigen) {
30469 + e = au_refresh_hinode_self(inode);
30470 + if (unlikely(e)) {
30471 + au_refresh_iop(inode, /*force_getattr*/1);
30472 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30475 + /* go on even if err */
30478 + if (!e && do_idop)
30479 + au_refresh_iop(inode, /*force_getattr*/0);
30480 + ii_write_unlock(inode);
30483 + au_iarray_free(array, max);
30489 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30492 + unsigned int udba;
30493 + aufs_bindex_t bindex, bbot;
30494 + struct dentry *root;
30495 + struct inode *inode;
30496 + struct au_branch *br;
30497 + struct au_sbinfo *sbi;
30499 + au_sigen_inc(sb);
30500 + sbi = au_sbi(sb);
30501 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30503 + root = sb->s_root;
30504 + DiMustNoWaiters(root);
30505 + inode = d_inode(root);
30506 + IiMustNoWaiters(inode);
30508 + udba = au_opt_udba(sb);
30509 + bbot = au_sbbot(sb);
30510 + for (bindex = 0; bindex <= bbot; bindex++) {
30511 + br = au_sbr(sb, bindex);
30512 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30513 + if (unlikely(err))
30514 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30516 + /* go on even if err */
30518 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30521 + if (au_ftest_si(sbi, NO_DREVAL)) {
30522 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30523 + sb->s_d_op = &aufs_dop_noreval;
30524 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30525 + sbi->si_iop_array = aufs_iop_nogetattr;
30527 + AuDebugOn(sb->s_d_op == &aufs_dop);
30528 + sb->s_d_op = &aufs_dop;
30529 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30530 + sbi->si_iop_array = aufs_iop;
30532 + pr_info("reset to %ps and %ps\n",
30533 + sb->s_d_op, sbi->si_iop_array);
30536 + di_write_unlock(root);
30537 + err = au_refresh_d(sb, do_idop);
30538 + e = au_refresh_i(sb, do_idop);
30539 + if (unlikely(e && !err))
30541 + /* aufs_write_lock() calls ..._child() */
30542 + di_write_lock_child(root);
30544 + au_cpup_attr_all(inode, /*force*/1);
30546 + if (unlikely(err))
30547 + AuIOErr("refresh failed, ignored, %d\n", err);
30550 +const struct super_operations aufs_sop = {
30551 + .alloc_inode = aufs_alloc_inode,
30552 + .destroy_inode = aufs_destroy_inode,
30553 + .free_inode = aufs_free_inode,
30554 + /* always deleting, no clearing */
30555 + .drop_inode = generic_delete_inode,
30556 + .show_options = aufs_show_options,
30557 + .statfs = aufs_statfs,
30558 + .put_super = aufs_put_super,
30559 + .sync_fs = aufs_sync_fs
30562 +/* ---------------------------------------------------------------------- */
30564 +int au_alloc_root(struct super_block *sb)
30567 + struct inode *inode;
30568 + struct dentry *root;
30571 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30572 + err = PTR_ERR(inode);
30573 + if (IS_ERR(inode))
30576 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30577 + inode->i_fop = &aufs_dir_fop;
30578 + inode->i_mode = S_IFDIR;
30579 + set_nlink(inode, 2);
30580 + unlock_new_inode(inode);
30582 + root = d_make_root(inode);
30583 + if (unlikely(!root))
30585 + err = PTR_ERR(root);
30586 + if (IS_ERR(root))
30589 + err = au_di_init(root);
30591 + sb->s_root = root;
30592 + return 0; /* success */
30600 +/* ---------------------------------------------------------------------- */
30602 +static void aufs_kill_sb(struct super_block *sb)
30604 + struct au_sbinfo *sbinfo;
30605 + struct dentry *root;
30607 + sbinfo = au_sbi(sb);
30611 + au_sbilist_del(sb);
30613 + root = sb->s_root;
30615 + aufs_write_lock(root);
30617 + __si_write_lock(sb);
30620 + if (sbinfo->si_wbr_create_ops->fin)
30621 + sbinfo->si_wbr_create_ops->fin(sb);
30622 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30623 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30624 + au_remount_refresh(sb, /*do_idop*/0);
30626 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30627 + au_plink_put(sb, /*verbose*/1);
30630 + au_dr_opt_flush(sb);
30633 + aufs_write_unlock(root);
30635 + __si_write_unlock(sb);
30637 + sbinfo->si_sb = NULL;
30638 + au_nwt_flush(&sbinfo->si_nowait);
30641 + kill_anon_super(sb);
30644 +struct file_system_type aufs_fs_type = {
30645 + .name = AUFS_FSTYPE,
30646 + /* a race between rename and others */
30647 + .fs_flags = FS_RENAME_DOES_D_MOVE
30649 + /*| FS_ALLOW_IDMAP*/
30651 + .init_fs_context = aufs_fsctx_init,
30652 + .parameters = aufs_fsctx_paramspec,
30653 + .kill_sb = aufs_kill_sb,
30654 + /* no need to __module_get() and module_put(). */
30655 + .owner = THIS_MODULE,
30657 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30658 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30659 +++ linux/fs/aufs/super.h 2022-03-21 14:49:05.729966343 +0100
30661 +/* SPDX-License-Identifier: GPL-2.0 */
30663 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30665 + * This program, aufs is free software; you can redistribute it and/or modify
30666 + * it under the terms of the GNU General Public License as published by
30667 + * the Free Software Foundation; either version 2 of the License, or
30668 + * (at your option) any later version.
30670 + * This program is distributed in the hope that it will be useful,
30671 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30672 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30673 + * GNU General Public License for more details.
30675 + * You should have received a copy of the GNU General Public License
30676 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30680 + * super_block operations
30683 +#ifndef __AUFS_SUPER_H__
30684 +#define __AUFS_SUPER_H__
30688 +#include <linux/fs.h>
30689 +#include <linux/kobject.h>
30692 +#include "rwsem.h"
30695 +/* policies to select one among multiple writable branches */
30696 +struct au_wbr_copyup_operations {
30697 + int (*copyup)(struct dentry *dentry);
30700 +#define AuWbr_DIR 1 /* target is a dir */
30701 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30703 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30704 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30705 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30707 +struct au_wbr_create_operations {
30708 + int (*create)(struct dentry *dentry, unsigned int flags);
30709 + int (*init)(struct super_block *sb);
30710 + int (*fin)(struct super_block *sb);
30713 +struct au_wbr_mfs {
30714 + struct mutex mfs_lock; /* protect this structure */
30715 + unsigned long mfs_jiffy;
30716 + unsigned long mfs_expire;
30717 + aufs_bindex_t mfs_bindex;
30719 + unsigned long long mfsrr_bytes;
30720 + unsigned long long mfsrr_watermark;
30723 +#define AuPlink_NHASH 100
30724 +static inline int au_plink_hash(ino_t ino)
30726 + return ino % AuPlink_NHASH;
30729 +/* File-based Hierarchical Storage Management */
30731 +#ifdef CONFIG_AUFS_FHSM
30732 + /* allow only one process who can receive the notification */
30733 + spinlock_t fhsm_spin;
30735 + wait_queue_head_t fhsm_wqh;
30736 + atomic_t fhsm_readable;
30738 + /* these are protected by si_rwsem */
30739 + unsigned long fhsm_expire;
30740 + aufs_bindex_t fhsm_bottom;
30745 +struct au_sbinfo {
30746 + /* nowait tasks in the system-wide workqueue */
30747 + struct au_nowait_tasks si_nowait;
30750 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30751 + * rwsem for au_sbinfo is necessary.
30753 + struct au_rwsem si_rwsem;
30756 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30759 + au_lcnt_t si_ninodes, si_nfiles;
30761 + /* branch management */
30762 + unsigned int si_generation;
30764 + /* see AuSi_ flags */
30765 + unsigned char au_si_status;
30767 + aufs_bindex_t si_bbot;
30769 + /* dirty trick to keep br_id plus */
30770 + unsigned int si_last_br_id :
30771 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30772 + struct au_branch **si_branch;
30774 + /* policy to select a writable branch */
30775 + unsigned char si_wbr_copyup;
30776 + unsigned char si_wbr_create;
30777 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30778 + struct au_wbr_create_operations *si_wbr_create_ops;
30780 + /* round robin */
30781 + atomic_t si_wbr_rr_next;
30783 + /* most free space */
30784 + struct au_wbr_mfs si_wbr_mfs;
30786 + /* File-based Hierarchical Storage Management */
30787 + struct au_fhsm si_fhsm;
30789 + /* mount flags */
30790 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30791 + unsigned int si_mntflags;
30793 + /* external inode number (bitmap and translation table) */
30794 + loff_t si_ximaxent; /* max entries in a xino */
30796 + struct file *si_xib;
30797 + struct mutex si_xib_mtx; /* protect xib members */
30798 + unsigned long *si_xib_buf;
30799 + unsigned long si_xib_last_pindex;
30800 + int si_xib_next_bit;
30802 + unsigned long si_xino_jiffy;
30803 + unsigned long si_xino_expire;
30804 + /* reserved for future use */
30805 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30807 +#ifdef CONFIG_AUFS_EXPORT
30808 + /* i_generation */
30809 + /* todo: make xigen file an array to support many inode numbers */
30810 + struct file *si_xigen;
30811 + atomic_t si_xigen_next;
30814 + /* dirty trick to support atomic_open */
30815 + struct hlist_bl_head si_aopen;
30817 + /* vdir parameters */
30818 + unsigned long si_rdcache; /* max cache time in jiffies */
30819 + unsigned int si_rdblk; /* deblk size */
30820 + unsigned int si_rdhash; /* hash size */
30823 + * If the number of whiteouts are larger than si_dirwh, leave all of
30824 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30825 + * future fsck.aufs or kernel thread will remove them later.
30826 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30828 + unsigned int si_dirwh;
30830 + /* pseudo_link list */
30831 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30832 + wait_queue_head_t si_plink_wq;
30833 + spinlock_t si_plink_maint_lock;
30834 + pid_t si_plink_maint_pid;
30837 + struct hlist_bl_head si_files;
30839 + /* with/without getattr, brother of sb->s_d_op */
30840 + const struct inode_operations *si_iop_array;
30843 + * sysfs and lifetime management.
30844 + * this is not a small structure and it may be a waste of memory in case
30845 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30846 + * but using sysfs is majority.
30848 + struct kobject si_kobj;
30849 +#ifdef CONFIG_DEBUG_FS
30850 + struct dentry *si_dbgaufs;
30851 + struct dentry *si_dbgaufs_plink;
30852 + struct dentry *si_dbgaufs_xib;
30853 +#ifdef CONFIG_AUFS_EXPORT
30854 + struct dentry *si_dbgaufs_xigen;
30858 +#ifdef CONFIG_AUFS_SBILIST
30859 + struct hlist_bl_node si_list;
30862 + /* dirty, necessary for unmounting, sysfs and sysrq */
30863 + struct super_block *si_sb;
30866 +/* sbinfo status flags */
30868 + * set true when refresh_dirs() failed at remount time.
30869 + * then try refreshing dirs at access time again.
30870 + * if it is false, refreshing dirs at access time is unnecessary
30872 +#define AuSi_FAILED_REFRESH_DIR 1
30873 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30874 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30876 +#ifndef CONFIG_AUFS_FHSM
30878 +#define AuSi_FHSM 0
30881 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30882 + unsigned int flag)
30884 + AuRwMustAnyLock(&sbi->si_rwsem);
30885 + return sbi->au_si_status & flag;
30887 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30888 +#define au_fset_si(sbinfo, name) do { \
30889 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30890 + (sbinfo)->au_si_status |= AuSi_##name; \
30892 +#define au_fclr_si(sbinfo, name) do { \
30893 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30894 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30897 +/* ---------------------------------------------------------------------- */
30899 +/* policy to select one among writable branches */
30900 +#define AuWbrCopyup(sbinfo, ...) \
30901 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30902 +#define AuWbrCreate(sbinfo, ...) \
30903 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30905 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30906 +#define AuLock_DW 1 /* write-lock dentry */
30907 +#define AuLock_IR (1 << 1) /* read-lock inode */
30908 +#define AuLock_IW (1 << 2) /* write-lock inode */
30909 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30910 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30911 + /* except RENAME_EXCHANGE */
30912 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30913 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30914 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30915 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30916 +#define au_fset_lock(flags, name) \
30917 + do { (flags) |= AuLock_##name; } while (0)
30918 +#define au_fclr_lock(flags, name) \
30919 + do { (flags) &= ~AuLock_##name; } while (0)
30921 +/* ---------------------------------------------------------------------- */
30924 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30926 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30927 + unsigned long long max, void *arg);
30928 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30929 + struct super_block *sb, void *arg);
30930 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30931 +void au_iarray_free(struct inode **a, unsigned long long max);
30933 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
30934 +extern const struct super_operations aufs_sop;
30935 +int au_alloc_root(struct super_block *sb);
30936 +extern struct file_system_type aufs_fs_type;
30939 +void au_si_free(struct kobject *kobj);
30940 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
30941 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30943 +unsigned int au_sigen_inc(struct super_block *sb);
30944 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30946 +int si_read_lock(struct super_block *sb, int flags);
30947 +int si_write_lock(struct super_block *sb, int flags);
30948 +int aufs_read_lock(struct dentry *dentry, int flags);
30949 +void aufs_read_unlock(struct dentry *dentry, int flags);
30950 +void aufs_write_lock(struct dentry *dentry);
30951 +void aufs_write_unlock(struct dentry *dentry);
30952 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30953 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30955 +/* wbr_policy.c */
30956 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30957 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30958 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30959 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30960 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30963 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30965 +#ifdef CONFIG_AUFS_FHSM
30968 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30972 + spin_lock(&fhsm->fhsm_spin);
30973 + pid = fhsm->fhsm_pid;
30974 + spin_unlock(&fhsm->fhsm_spin);
30979 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30980 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30981 +int au_fhsm_fd(struct super_block *sb, int oflags);
30982 +int au_fhsm_br_alloc(struct au_branch *br);
30983 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30984 +void au_fhsm_fin(struct super_block *sb);
30985 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30986 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30987 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30989 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30991 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30992 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30993 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30994 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30995 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30996 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30997 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30998 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30999 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31002 +/* ---------------------------------------------------------------------- */
31004 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31006 + return sb->s_fs_info;
31009 +/* ---------------------------------------------------------------------- */
31011 +#ifdef CONFIG_AUFS_EXPORT
31012 +int au_test_nfsd(void);
31013 +void au_export_init(struct super_block *sb);
31014 +void au_xigen_inc(struct inode *inode);
31015 +int au_xigen_new(struct inode *inode);
31016 +int au_xigen_set(struct super_block *sb, struct path *path);
31017 +void au_xigen_clr(struct super_block *sb);
31019 +static inline int au_busy_or_stale(void)
31021 + if (!au_test_nfsd())
31026 +AuStubInt0(au_test_nfsd, void)
31027 +AuStubVoid(au_export_init, struct super_block *sb)
31028 +AuStubVoid(au_xigen_inc, struct inode *inode)
31029 +AuStubInt0(au_xigen_new, struct inode *inode)
31030 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31031 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31032 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31033 +#endif /* CONFIG_AUFS_EXPORT */
31035 +/* ---------------------------------------------------------------------- */
31037 +#ifdef CONFIG_AUFS_SBILIST
31039 +extern struct hlist_bl_head au_sbilist;
31041 +static inline void au_sbilist_init(void)
31043 + INIT_HLIST_BL_HEAD(&au_sbilist);
31046 +static inline void au_sbilist_add(struct super_block *sb)
31048 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31051 +static inline void au_sbilist_del(struct super_block *sb)
31053 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31056 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31057 +static inline void au_sbilist_lock(void)
31059 + hlist_bl_lock(&au_sbilist);
31062 +static inline void au_sbilist_unlock(void)
31064 + hlist_bl_unlock(&au_sbilist);
31066 +#define AuGFP_SBILIST GFP_ATOMIC
31068 +AuStubVoid(au_sbilist_lock, void)
31069 +AuStubVoid(au_sbilist_unlock, void)
31070 +#define AuGFP_SBILIST GFP_NOFS
31071 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31073 +AuStubVoid(au_sbilist_init, void)
31074 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31075 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31076 +AuStubVoid(au_sbilist_lock, void)
31077 +AuStubVoid(au_sbilist_unlock, void)
31078 +#define AuGFP_SBILIST GFP_NOFS
31081 +/* ---------------------------------------------------------------------- */
31083 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31086 + * This function is a dynamic '__init' function actually,
31087 + * so the tiny check for si_rwsem is unnecessary.
31089 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31090 +#ifdef CONFIG_DEBUG_FS
31091 + sbinfo->si_dbgaufs = NULL;
31092 + sbinfo->si_dbgaufs_plink = NULL;
31093 + sbinfo->si_dbgaufs_xib = NULL;
31094 +#ifdef CONFIG_AUFS_EXPORT
31095 + sbinfo->si_dbgaufs_xigen = NULL;
31100 +/* ---------------------------------------------------------------------- */
31102 +/* current->atomic_flags */
31103 +/* this value should never corrupt the ones defined in linux/sched.h */
31104 +#define PFA_AUFS 0x10
31106 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31107 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31108 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31110 +static inline int si_pid_test(struct super_block *sb)
31112 + return !!task_test_aufs(current);
31115 +static inline void si_pid_clr(struct super_block *sb)
31117 + AuDebugOn(!task_test_aufs(current));
31118 + task_clear_aufs(current);
31121 +static inline void si_pid_set(struct super_block *sb)
31123 + AuDebugOn(task_test_aufs(current));
31124 + task_set_aufs(current);
31127 +/* ---------------------------------------------------------------------- */
31129 +/* lock superblock. mainly for entry point functions */
31130 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31131 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31132 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31133 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31135 +#define __si_read_trylock_nested(sb) \
31136 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31137 +#define __si_write_trylock_nested(sb) \
31138 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31141 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31142 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31143 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31145 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31146 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31147 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31149 +static inline void si_noflush_read_lock(struct super_block *sb)
31151 + __si_read_lock(sb);
31155 +static inline int si_noflush_read_trylock(struct super_block *sb)
31159 + locked = __si_read_trylock(sb);
31165 +static inline void si_noflush_write_lock(struct super_block *sb)
31167 + __si_write_lock(sb);
31171 +static inline int si_noflush_write_trylock(struct super_block *sb)
31175 + locked = __si_write_trylock(sb);
31181 +#if 0 /* reserved */
31182 +static inline int si_read_trylock(struct super_block *sb, int flags)
31184 + if (au_ftest_lock(flags, FLUSH))
31185 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31186 + return si_noflush_read_trylock(sb);
31190 +static inline void si_read_unlock(struct super_block *sb)
31193 + __si_read_unlock(sb);
31196 +#if 0 /* reserved */
31197 +static inline int si_write_trylock(struct super_block *sb, int flags)
31199 + if (au_ftest_lock(flags, FLUSH))
31200 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31201 + return si_noflush_write_trylock(sb);
31205 +static inline void si_write_unlock(struct super_block *sb)
31208 + __si_write_unlock(sb);
31211 +#if 0 /* reserved */
31212 +static inline void si_downgrade_lock(struct super_block *sb)
31214 + __si_downgrade_lock(sb);
31218 +/* ---------------------------------------------------------------------- */
31220 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31222 + SiMustAnyLock(sb);
31223 + return au_sbi(sb)->si_bbot;
31226 +static inline unsigned int au_mntflags(struct super_block *sb)
31228 + SiMustAnyLock(sb);
31229 + return au_sbi(sb)->si_mntflags;
31232 +static inline unsigned int au_sigen(struct super_block *sb)
31234 + SiMustAnyLock(sb);
31235 + return au_sbi(sb)->si_generation;
31238 +static inline struct au_branch *au_sbr(struct super_block *sb,
31239 + aufs_bindex_t bindex)
31241 + SiMustAnyLock(sb);
31242 + return au_sbi(sb)->si_branch[0 + bindex];
31245 +static inline loff_t au_xi_maxent(struct super_block *sb)
31247 + SiMustAnyLock(sb);
31248 + return au_sbi(sb)->si_ximaxent;
31251 +#endif /* __KERNEL__ */
31252 +#endif /* __AUFS_SUPER_H__ */
31253 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31254 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31255 +++ linux/fs/aufs/sysaufs.c 2022-03-21 14:49:05.729966343 +0100
31257 +// SPDX-License-Identifier: GPL-2.0
31259 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31261 + * This program, aufs is free software; you can redistribute it and/or modify
31262 + * it under the terms of the GNU General Public License as published by
31263 + * the Free Software Foundation; either version 2 of the License, or
31264 + * (at your option) any later version.
31266 + * This program is distributed in the hope that it will be useful,
31267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31269 + * GNU General Public License for more details.
31271 + * You should have received a copy of the GNU General Public License
31272 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31276 + * sysfs interface and lifetime management
31277 + * they are necessary regardless sysfs is disabled.
31280 +#include <linux/random.h>
31283 +unsigned long sysaufs_si_mask;
31284 +struct kset *sysaufs_kset;
31286 +#define AuSiAttr(_name) { \
31287 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31288 + .show = sysaufs_si_##_name, \
31291 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31292 +struct attribute *sysaufs_si_attrs[] = {
31293 + &sysaufs_si_attr_xi_path.attr,
31297 +static const struct sysfs_ops au_sbi_ops = {
31298 + .show = sysaufs_si_show
31301 +static struct kobj_type au_sbi_ktype = {
31302 + .release = au_si_free,
31303 + .sysfs_ops = &au_sbi_ops,
31304 + .default_attrs = sysaufs_si_attrs
31307 +/* ---------------------------------------------------------------------- */
31309 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31313 + sbinfo->si_kobj.kset = sysaufs_kset;
31314 + /* cf. sysaufs_name() */
31315 + err = kobject_init_and_add
31316 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31317 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31322 +void sysaufs_fin(void)
31324 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31325 + kset_unregister(sysaufs_kset);
31328 +int __init sysaufs_init(void)
31333 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31334 + } while (!sysaufs_si_mask);
31337 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31338 + if (unlikely(!sysaufs_kset))
31340 + err = PTR_ERR(sysaufs_kset);
31341 + if (IS_ERR(sysaufs_kset))
31343 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31344 + if (unlikely(err))
31345 + kset_unregister(sysaufs_kset);
31350 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31351 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31352 +++ linux/fs/aufs/sysaufs.h 2022-03-21 14:49:05.729966343 +0100
31354 +/* SPDX-License-Identifier: GPL-2.0 */
31356 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31358 + * This program, aufs is free software; you can redistribute it and/or modify
31359 + * it under the terms of the GNU General Public License as published by
31360 + * the Free Software Foundation; either version 2 of the License, or
31361 + * (at your option) any later version.
31363 + * This program is distributed in the hope that it will be useful,
31364 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31365 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31366 + * GNU General Public License for more details.
31368 + * You should have received a copy of the GNU General Public License
31369 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31373 + * sysfs interface and mount lifetime management
31376 +#ifndef __SYSAUFS_H__
31377 +#define __SYSAUFS_H__
31381 +#include <linux/sysfs.h>
31382 +#include "module.h"
31384 +struct super_block;
31387 +struct sysaufs_si_attr {
31388 + struct attribute attr;
31389 + int (*show)(struct seq_file *seq, struct super_block *sb);
31392 +/* ---------------------------------------------------------------------- */
31395 +extern unsigned long sysaufs_si_mask;
31396 +extern struct kset *sysaufs_kset;
31397 +extern struct attribute *sysaufs_si_attrs[];
31398 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31399 +int __init sysaufs_init(void);
31400 +void sysaufs_fin(void);
31402 +/* ---------------------------------------------------------------------- */
31404 +/* some people doesn't like to show a pointer in kernel */
31405 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31407 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31410 +#define SysaufsSiNamePrefix "si_"
31411 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31412 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31414 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31415 + sysaufs_si_id(sbinfo));
31419 +#ifdef CONFIG_SYSFS
31421 +extern struct attribute_group *sysaufs_attr_group;
31423 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31424 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31426 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31427 +#ifdef CONFIG_COMPAT
31428 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31431 +void sysaufs_br_init(struct au_branch *br);
31432 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31433 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31435 +#define sysaufs_brs_init() do {} while (0)
31438 +#define sysaufs_attr_group NULL
31440 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31441 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31442 + struct attribute *attr, char *buf)
31443 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31444 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31445 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31447 +static inline void sysaufs_brs_init(void)
31452 +#endif /* CONFIG_SYSFS */
31454 +#endif /* __KERNEL__ */
31455 +#endif /* __SYSAUFS_H__ */
31456 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31457 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31458 +++ linux/fs/aufs/sysfs.c 2022-03-21 14:49:05.729966343 +0100
31460 +// SPDX-License-Identifier: GPL-2.0
31462 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31464 + * This program, aufs is free software; you can redistribute it and/or modify
31465 + * it under the terms of the GNU General Public License as published by
31466 + * the Free Software Foundation; either version 2 of the License, or
31467 + * (at your option) any later version.
31469 + * This program is distributed in the hope that it will be useful,
31470 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31471 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31472 + * GNU General Public License for more details.
31474 + * You should have received a copy of the GNU General Public License
31475 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31479 + * sysfs interface
31482 +#include <linux/compat.h>
31483 +#include <linux/seq_file.h>
31486 +#ifdef CONFIG_AUFS_FS_MODULE
31487 +/* this entry violates the "one line per file" policy of sysfs */
31488 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31492 + static char *conf =
31493 +/* this file is generated at compiling */
31494 +#include "conf.str"
31497 + err = snprintf(buf, PAGE_SIZE, conf);
31498 + if (unlikely(err >= PAGE_SIZE))
31503 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31506 +static struct attribute *au_attr[] = {
31507 +#ifdef CONFIG_AUFS_FS_MODULE
31508 + &au_config_attr.attr,
31510 + NULL, /* need to NULL terminate the list of attributes */
31513 +static struct attribute_group sysaufs_attr_group_body = {
31517 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31519 +/* ---------------------------------------------------------------------- */
31521 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31525 + SiMustAnyLock(sb);
31528 + if (au_opt_test(au_mntflags(sb), XINO)) {
31529 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31530 + seq_putc(seq, '\n');
31536 + * the lifetime of branch is independent from the entry under sysfs.
31537 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31540 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31541 + aufs_bindex_t bindex, int idx)
31544 + struct path path;
31545 + struct dentry *root;
31546 + struct au_branch *br;
31547 + au_br_perm_str_t perm;
31549 + AuDbg("b%d\n", bindex);
31552 + root = sb->s_root;
31553 + di_read_lock_parent(root, !AuLock_IR);
31554 + br = au_sbr(sb, bindex);
31557 + case AuBrSysfs_BR:
31558 + path.mnt = au_br_mnt(br);
31559 + path.dentry = au_h_dptr(root, bindex);
31560 + err = au_seq_path(seq, &path);
31562 + au_optstr_br_perm(&perm, br->br_perm);
31563 + seq_printf(seq, "=%s\n", perm.a);
31566 + case AuBrSysfs_BRID:
31567 + seq_printf(seq, "%d\n", br->br_id);
31570 + di_read_unlock(root, !AuLock_IR);
31571 + if (unlikely(err || seq_has_overflowed(seq)))
31577 +/* ---------------------------------------------------------------------- */
31579 +static struct seq_file *au_seq(char *p, ssize_t len)
31581 + struct seq_file *seq;
31583 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31585 + /* mutex_init(&seq.lock); */
31588 + return seq; /* success */
31591 + seq = ERR_PTR(-ENOMEM);
31595 +#define SysaufsBr_PREFIX "br"
31596 +#define SysaufsBrid_PREFIX "brid"
31598 +/* todo: file size may exceed PAGE_SIZE */
31599 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31605 + aufs_bindex_t bbot;
31606 + struct au_sbinfo *sbinfo;
31607 + struct super_block *sb;
31608 + struct seq_file *seq;
31610 + struct attribute **cattr;
31612 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31613 + sb = sbinfo->si_sb;
31616 + * prevent a race condition between sysfs and aufs.
31617 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31618 + * prohibits maintaining the sysfs entries.
31619 + * hew we acquire read lock after sysfs_get_active_two().
31620 + * on the other hand, the remount process may maintain the sysfs/aufs
31621 + * entries after acquiring write lock.
31622 + * it can cause a deadlock.
31623 + * simply we gave up processing read here.
31626 + if (unlikely(!si_noflush_read_trylock(sb)))
31629 + seq = au_seq(buf, PAGE_SIZE);
31630 + err = PTR_ERR(seq);
31634 + name = (void *)attr->name;
31635 + cattr = sysaufs_si_attrs;
31637 + if (!strcmp(name, (*cattr)->name)) {
31638 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31645 + if (!strncmp(name, SysaufsBrid_PREFIX,
31646 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31647 + idx = AuBrSysfs_BRID;
31648 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31649 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31650 + sizeof(SysaufsBr_PREFIX) - 1)) {
31651 + idx = AuBrSysfs_BR;
31652 + name += sizeof(SysaufsBr_PREFIX) - 1;
31656 + err = kstrtol(name, 10, &l);
31658 + bbot = au_sbbot(sb);
31660 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31667 + err = seq->count;
31668 + /* sysfs limit */
31669 + if (unlikely(err == PAGE_SIZE))
31672 + au_kfree_rcu(seq);
31674 + si_read_unlock(sb);
31679 +/* ---------------------------------------------------------------------- */
31681 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31685 + aufs_bindex_t bindex, bbot;
31688 + struct seq_file *seq;
31689 + struct au_branch *br;
31691 + si_read_lock(sb, AuLock_FLUSH);
31692 + bbot = au_sbbot(sb);
31698 + buf = (void *)__get_free_page(GFP_NOFS);
31699 + if (unlikely(!buf))
31702 + seq = au_seq(buf, PAGE_SIZE);
31703 + err = PTR_ERR(seq);
31707 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31708 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31709 + /* VERIFY_WRITE */
31710 + err = !access_ok(arg, sizeof(*arg));
31711 + if (unlikely(err))
31714 + br = au_sbr(sb, bindex);
31715 + brid = br->br_id;
31716 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31717 + err = __put_user(brid, &arg->id);
31718 + if (unlikely(err))
31721 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31722 + err = __put_user(br->br_perm, &arg->perm);
31723 + if (unlikely(err))
31726 + err = au_seq_path(seq, &br->br_path);
31727 + if (unlikely(err))
31729 + seq_putc(seq, '\0');
31730 + if (!seq_has_overflowed(seq)) {
31731 + err = copy_to_user(arg->path, seq->buf, seq->count);
31733 + if (unlikely(err))
31740 + if (unlikely(err))
31744 + au_kfree_rcu(seq);
31746 + free_page((unsigned long)buf);
31748 + si_read_unlock(sb);
31752 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31754 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31757 +#ifdef CONFIG_COMPAT
31758 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31760 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31764 +/* ---------------------------------------------------------------------- */
31766 +void sysaufs_br_init(struct au_branch *br)
31769 + struct au_brsysfs *br_sysfs;
31770 + struct attribute *attr;
31772 + br_sysfs = br->br_sysfs;
31773 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31774 + attr = &br_sysfs->attr;
31775 + sysfs_attr_init(attr);
31776 + attr->name = br_sysfs->name;
31777 + attr->mode = 0444;
31782 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31784 + struct au_branch *br;
31785 + struct kobject *kobj;
31786 + struct au_brsysfs *br_sysfs;
31788 + aufs_bindex_t bbot;
31790 + if (!sysaufs_brs)
31793 + kobj = &au_sbi(sb)->si_kobj;
31794 + bbot = au_sbbot(sb);
31795 + for (; bindex <= bbot; bindex++) {
31796 + br = au_sbr(sb, bindex);
31797 + br_sysfs = br->br_sysfs;
31798 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31799 + sysfs_remove_file(kobj, &br_sysfs->attr);
31805 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31808 + aufs_bindex_t bbot;
31809 + struct kobject *kobj;
31810 + struct au_branch *br;
31811 + struct au_brsysfs *br_sysfs;
31813 + if (!sysaufs_brs)
31816 + kobj = &au_sbi(sb)->si_kobj;
31817 + bbot = au_sbbot(sb);
31818 + for (; bindex <= bbot; bindex++) {
31819 + br = au_sbr(sb, bindex);
31820 + br_sysfs = br->br_sysfs;
31821 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31822 + SysaufsBr_PREFIX "%d", bindex);
31823 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31824 + SysaufsBrid_PREFIX "%d", bindex);
31825 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31826 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31827 + if (unlikely(err))
31828 + pr_warn("failed %s under sysfs(%d)\n",
31829 + br_sysfs->name, err);
31834 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31835 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31836 +++ linux/fs/aufs/sysrq.c 2022-03-21 14:49:05.729966343 +0100
31838 +// SPDX-License-Identifier: GPL-2.0
31840 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31842 + * This program, aufs is free software; you can redistribute it and/or modify
31843 + * it under the terms of the GNU General Public License as published by
31844 + * the Free Software Foundation; either version 2 of the License, or
31845 + * (at your option) any later version.
31847 + * This program is distributed in the hope that it will be useful,
31848 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31849 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31850 + * GNU General Public License for more details.
31852 + * You should have received a copy of the GNU General Public License
31853 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31857 + * magic sysrq handler
31860 +/* #include <linux/sysrq.h> */
31861 +#include <linux/writeback.h>
31864 +/* ---------------------------------------------------------------------- */
31866 +static void sysrq_sb(struct super_block *sb)
31869 + struct au_sbinfo *sbinfo;
31870 + struct file *file;
31871 + struct hlist_bl_head *files;
31872 + struct hlist_bl_node *pos;
31873 + struct au_finfo *finfo;
31876 + plevel = au_plevel;
31877 + au_plevel = KERN_WARNING;
31879 + /* since we define pr_fmt, call printk directly */
31880 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31882 + sbinfo = au_sbi(sb);
31883 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31884 + pr("superblock\n");
31887 +#if 0 /* reserved */
31889 + int err, i, j, ndentry;
31890 + struct au_dcsub_pages dpages;
31891 + struct au_dpage *dpage;
31893 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31894 + if (unlikely(err))
31896 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31898 + for (i = 0; i < dpages.ndpage; i++) {
31899 + dpage = dpages.dpages + i;
31900 + ndentry = dpage->ndentry;
31901 + for (j = 0; j < ndentry; j++)
31902 + au_dpri_dentry(dpage->dentries[j]);
31904 + au_dpages_free(&dpages);
31908 + pr("isolated inode\n");
31909 + spin_lock(&sb->s_inode_list_lock);
31910 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31911 + spin_lock(&i->i_lock);
31912 + if (hlist_empty(&i->i_dentry))
31913 + au_dpri_inode(i);
31914 + spin_unlock(&i->i_lock);
31916 + spin_unlock(&sb->s_inode_list_lock);
31919 + files = &au_sbi(sb)->si_files;
31920 + hlist_bl_lock(files);
31921 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31924 + file = finfo->fi_file;
31925 + mode = file_inode(file)->i_mode;
31926 + if (!special_file(mode))
31927 + au_dpri_file(file);
31929 + hlist_bl_unlock(files);
31933 + au_plevel = plevel;
31936 +/* ---------------------------------------------------------------------- */
31938 +/* module parameter */
31939 +static char *aufs_sysrq_key = "a";
31940 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31941 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31943 +static void au_sysrq(int key __maybe_unused)
31945 + struct au_sbinfo *sbinfo;
31946 + struct hlist_bl_node *pos;
31949 + au_sbilist_lock();
31950 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31951 + sysrq_sb(sbinfo->si_sb);
31952 + au_sbilist_unlock();
31956 +static struct sysrq_key_op au_sysrq_op = {
31957 + .handler = au_sysrq,
31958 + .help_msg = "Aufs",
31959 + .action_msg = "Aufs",
31960 + .enable_mask = SYSRQ_ENABLE_DUMP
31963 +/* ---------------------------------------------------------------------- */
31965 +int __init au_sysrq_init(void)
31971 + key = *aufs_sysrq_key;
31972 + if ('a' <= key && key <= 'z')
31973 + err = register_sysrq_key(key, &au_sysrq_op);
31974 + if (unlikely(err))
31975 + pr_err("err %d, sysrq=%c\n", err, key);
31979 +void au_sysrq_fin(void)
31983 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31984 + if (unlikely(err))
31985 + pr_err("err %d (ignored)\n", err);
31987 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31988 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31989 +++ linux/fs/aufs/vdir.c 2022-03-21 14:49:05.733299677 +0100
31991 +// SPDX-License-Identifier: GPL-2.0
31993 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31995 + * This program, aufs is free software; you can redistribute it and/or modify
31996 + * it under the terms of the GNU General Public License as published by
31997 + * the Free Software Foundation; either version 2 of the License, or
31998 + * (at your option) any later version.
32000 + * This program is distributed in the hope that it will be useful,
32001 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32002 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32003 + * GNU General Public License for more details.
32005 + * You should have received a copy of the GNU General Public License
32006 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32010 + * virtual or vertical directory
32013 +#include <linux/iversion.h>
32016 +static unsigned int calc_size(int nlen)
32018 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32021 +static int set_deblk_end(union au_vdir_deblk_p *p,
32022 + union au_vdir_deblk_p *deblk_end)
32024 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32025 + p->de->de_str.len = 0;
32029 + return -1; /* error */
32032 +/* returns true or false */
32033 +static int is_deblk_end(union au_vdir_deblk_p *p,
32034 + union au_vdir_deblk_p *deblk_end)
32036 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32037 + return !p->de->de_str.len;
32041 +static unsigned char *last_deblk(struct au_vdir *vdir)
32043 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32046 +/* ---------------------------------------------------------------------- */
32048 +/* estimate the appropriate size for name hash table */
32049 +unsigned int au_rdhash_est(loff_t sz)
32057 + if (sz < AUFS_RDHASH_DEF)
32058 + n = AUFS_RDHASH_DEF;
32059 + /* pr_info("n %u\n", n); */
32064 + * the allocated memory has to be freed by
32065 + * au_nhash_wh_free() or au_nhash_de_free().
32067 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32069 + struct hlist_head *head;
32073 + sz = sizeof(*nhash->nh_head) * num_hash;
32074 + head = kmalloc(sz, gfp);
32076 + nhash->nh_num = num_hash;
32077 + nhash->nh_head = head;
32078 + for (u = 0; u < num_hash; u++)
32079 + INIT_HLIST_HEAD(head++);
32080 + return 0; /* success */
32086 +static void nhash_count(struct hlist_head *head)
32088 +#if 0 /* debugging */
32090 + struct hlist_node *pos;
32093 + hlist_for_each(pos, head)
32095 + pr_info("%lu\n", n);
32099 +static void au_nhash_wh_do_free(struct hlist_head *head)
32101 + struct au_vdir_wh *pos;
32102 + struct hlist_node *node;
32104 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32105 + au_kfree_rcu(pos);
32108 +static void au_nhash_de_do_free(struct hlist_head *head)
32110 + struct au_vdir_dehstr *pos;
32111 + struct hlist_node *node;
32113 + hlist_for_each_entry_safe(pos, node, head, hash)
32114 + au_cache_free_vdir_dehstr(pos);
32117 +static void au_nhash_do_free(struct au_nhash *nhash,
32118 + void (*free)(struct hlist_head *head))
32121 + struct hlist_head *head;
32123 + n = nhash->nh_num;
32127 + head = nhash->nh_head;
32128 + while (n-- > 0) {
32129 + nhash_count(head);
32132 + au_kfree_try_rcu(nhash->nh_head);
32135 +void au_nhash_wh_free(struct au_nhash *whlist)
32137 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32140 +static void au_nhash_de_free(struct au_nhash *delist)
32142 + au_nhash_do_free(delist, au_nhash_de_do_free);
32145 +/* ---------------------------------------------------------------------- */
32147 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32151 + unsigned int u, n;
32152 + struct hlist_head *head;
32153 + struct au_vdir_wh *pos;
32156 + n = whlist->nh_num;
32157 + head = whlist->nh_head;
32158 + for (u = 0; u < n; u++, head++)
32159 + hlist_for_each_entry(pos, head, wh_hash)
32160 + if (pos->wh_bindex == btgt && ++num > limit)
32165 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32166 + unsigned char *name,
32167 + unsigned int len)
32170 + /* const unsigned int magic_bit = 12; */
32172 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32179 + /* v = hash_long(v, magic_bit); */
32180 + v %= nhash->nh_num;
32181 + return nhash->nh_head + v;
32184 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32187 + return str->len == nlen && !memcmp(str->name, name, nlen);
32190 +/* returns found or not */
32191 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32193 + struct hlist_head *head;
32194 + struct au_vdir_wh *pos;
32195 + struct au_vdir_destr *str;
32197 + head = au_name_hash(whlist, name, nlen);
32198 + hlist_for_each_entry(pos, head, wh_hash) {
32199 + str = &pos->wh_str;
32200 + AuDbg("%.*s\n", str->len, str->name);
32201 + if (au_nhash_test_name(str, name, nlen))
32207 +/* returns found(true) or not */
32208 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32210 + struct hlist_head *head;
32211 + struct au_vdir_dehstr *pos;
32212 + struct au_vdir_destr *str;
32214 + head = au_name_hash(delist, name, nlen);
32215 + hlist_for_each_entry(pos, head, hash) {
32217 + AuDbg("%.*s\n", str->len, str->name);
32218 + if (au_nhash_test_name(str, name, nlen))
32224 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32225 + unsigned char d_type)
32227 +#ifdef CONFIG_AUFS_SHWH
32228 + wh->wh_ino = ino;
32229 + wh->wh_type = d_type;
32233 +/* ---------------------------------------------------------------------- */
32235 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32236 + unsigned int d_type, aufs_bindex_t bindex,
32237 + unsigned char shwh)
32240 + struct au_vdir_destr *str;
32241 + struct au_vdir_wh *wh;
32243 + AuDbg("%.*s\n", nlen, name);
32244 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32247 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32248 + if (unlikely(!wh))
32252 + wh->wh_bindex = bindex;
32254 + au_shwh_init_wh(wh, ino, d_type);
32255 + str = &wh->wh_str;
32257 + memcpy(str->name, name, nlen);
32258 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32265 +static int append_deblk(struct au_vdir *vdir)
32268 + unsigned long ul;
32269 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32270 + union au_vdir_deblk_p p, deblk_end;
32271 + unsigned char **o;
32274 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32275 + GFP_NOFS, /*may_shrink*/0);
32276 + if (unlikely(!o))
32279 + vdir->vd_deblk = o;
32280 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32282 + ul = vdir->vd_nblk++;
32283 + vdir->vd_deblk[ul] = p.deblk;
32284 + vdir->vd_last.ul = ul;
32285 + vdir->vd_last.p.deblk = p.deblk;
32286 + deblk_end.deblk = p.deblk + deblk_sz;
32287 + err = set_deblk_end(&p, &deblk_end);
32294 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32295 + unsigned int d_type, struct au_nhash *delist)
32299 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32300 + union au_vdir_deblk_p p, *room, deblk_end;
32301 + struct au_vdir_dehstr *dehstr;
32303 + p.deblk = last_deblk(vdir);
32304 + deblk_end.deblk = p.deblk + deblk_sz;
32305 + room = &vdir->vd_last.p;
32306 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32307 + || !is_deblk_end(room, &deblk_end));
32309 + sz = calc_size(nlen);
32310 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32311 + err = append_deblk(vdir);
32312 + if (unlikely(err))
32315 + p.deblk = last_deblk(vdir);
32316 + deblk_end.deblk = p.deblk + deblk_sz;
32318 + AuDebugOn(room->deblk != p.deblk);
32322 + dehstr = au_cache_alloc_vdir_dehstr();
32323 + if (unlikely(!dehstr))
32326 + dehstr->str = &room->de->de_str;
32327 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32328 + room->de->de_ino = ino;
32329 + room->de->de_type = d_type;
32330 + room->de->de_str.len = nlen;
32331 + memcpy(room->de->de_str.name, name, nlen);
32334 + room->deblk += sz;
32335 + if (unlikely(set_deblk_end(room, &deblk_end)))
32336 + err = append_deblk(vdir);
32343 +/* ---------------------------------------------------------------------- */
32345 +void au_vdir_free(struct au_vdir *vdir)
32347 + unsigned char **deblk;
32349 + deblk = vdir->vd_deblk;
32350 + while (vdir->vd_nblk--)
32351 + au_kfree_try_rcu(*deblk++);
32352 + au_kfree_try_rcu(vdir->vd_deblk);
32353 + au_cache_free_vdir(vdir);
32356 +static struct au_vdir *alloc_vdir(struct file *file)
32358 + struct au_vdir *vdir;
32359 + struct super_block *sb;
32362 + sb = file->f_path.dentry->d_sb;
32363 + SiMustAnyLock(sb);
32366 + vdir = au_cache_alloc_vdir();
32367 + if (unlikely(!vdir))
32370 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32371 + if (unlikely(!vdir->vd_deblk))
32374 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32375 + if (!vdir->vd_deblk_sz) {
32376 + /* estimate the appropriate size for deblk */
32377 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32378 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32380 + vdir->vd_nblk = 0;
32381 + vdir->vd_version = 0;
32382 + vdir->vd_jiffy = 0;
32383 + err = append_deblk(vdir);
32385 + return vdir; /* success */
32387 + au_kfree_try_rcu(vdir->vd_deblk);
32390 + au_cache_free_vdir(vdir);
32392 + vdir = ERR_PTR(err);
32396 +static int reinit_vdir(struct au_vdir *vdir)
32399 + union au_vdir_deblk_p p, deblk_end;
32401 + while (vdir->vd_nblk > 1) {
32402 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32403 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32406 + p.deblk = vdir->vd_deblk[0];
32407 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32408 + err = set_deblk_end(&p, &deblk_end);
32409 + /* keep vd_dblk_sz */
32410 + vdir->vd_last.ul = 0;
32411 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32412 + vdir->vd_version = 0;
32413 + vdir->vd_jiffy = 0;
32418 +/* ---------------------------------------------------------------------- */
32420 +#define AuFillVdir_CALLED 1
32421 +#define AuFillVdir_WHABLE (1 << 1)
32422 +#define AuFillVdir_SHWH (1 << 2)
32423 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32424 +#define au_fset_fillvdir(flags, name) \
32425 + do { (flags) |= AuFillVdir_##name; } while (0)
32426 +#define au_fclr_fillvdir(flags, name) \
32427 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32429 +#ifndef CONFIG_AUFS_SHWH
32430 +#undef AuFillVdir_SHWH
32431 +#define AuFillVdir_SHWH 0
32434 +struct fillvdir_arg {
32435 + struct dir_context ctx;
32436 + struct file *file;
32437 + struct au_vdir *vdir;
32438 + struct au_nhash delist;
32439 + struct au_nhash whlist;
32440 + aufs_bindex_t bindex;
32441 + unsigned int flags;
32445 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32446 + loff_t offset __maybe_unused, u64 h_ino,
32447 + unsigned int d_type)
32449 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32450 + char *name = (void *)__name;
32451 + struct super_block *sb;
32453 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32456 + sb = arg->file->f_path.dentry->d_sb;
32457 + au_fset_fillvdir(arg->flags, CALLED);
32459 + if (nlen <= AUFS_WH_PFX_LEN
32460 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32461 + if (test_known(&arg->delist, name, nlen)
32462 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32463 + goto out; /* already exists or whiteouted */
32465 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32467 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32468 + d_type = DT_UNKNOWN;
32469 + arg->err = append_de(arg->vdir, name, nlen, ino,
32470 + d_type, &arg->delist);
32472 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32473 + name += AUFS_WH_PFX_LEN;
32474 + nlen -= AUFS_WH_PFX_LEN;
32475 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32476 + goto out; /* already whiteouted */
32478 + ino = 0; /* just to suppress a warning */
32480 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32483 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32484 + d_type = DT_UNKNOWN;
32485 + arg->err = au_nhash_append_wh
32486 + (&arg->whlist, name, nlen, ino, d_type,
32487 + arg->bindex, shwh);
32493 + arg->vdir->vd_jiffy = jiffies;
32495 + AuTraceErr(arg->err);
32499 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32500 + struct au_nhash *whlist, struct au_nhash *delist)
32502 +#ifdef CONFIG_AUFS_SHWH
32504 + unsigned int nh, u;
32505 + struct hlist_head *head;
32506 + struct au_vdir_wh *pos;
32507 + struct hlist_node *n;
32509 + struct au_vdir_destr *destr;
32511 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32514 + o = p = (void *)__get_free_page(GFP_NOFS);
32515 + if (unlikely(!p))
32519 + nh = whlist->nh_num;
32520 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32521 + p += AUFS_WH_PFX_LEN;
32522 + for (u = 0; u < nh; u++) {
32523 + head = whlist->nh_head + u;
32524 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32525 + destr = &pos->wh_str;
32526 + memcpy(p, destr->name, destr->len);
32527 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32528 + pos->wh_ino, pos->wh_type, delist);
32529 + if (unlikely(err))
32534 + free_page((unsigned long)o);
32544 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32547 + unsigned int rdhash;
32549 + aufs_bindex_t bbot, bindex, btop;
32550 + unsigned char shwh;
32551 + struct file *hf, *file;
32552 + struct super_block *sb;
32554 + file = arg->file;
32555 + sb = file->f_path.dentry->d_sb;
32556 + SiMustAnyLock(sb);
32558 + rdhash = au_sbi(sb)->si_rdhash;
32560 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32561 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32562 + if (unlikely(err))
32564 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32565 + if (unlikely(err))
32571 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32573 + au_fset_fillvdir(arg->flags, SHWH);
32575 + btop = au_fbtop(file);
32576 + bbot = au_fbbot_dir(file);
32577 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32578 + hf = au_hf_dir(file, bindex);
32582 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32584 + if (unlikely(offset))
32587 + arg->bindex = bindex;
32588 + au_fclr_fillvdir(arg->flags, WHABLE);
32590 + || (bindex != bbot
32591 + && au_br_whable(au_sbr_perm(sb, bindex))))
32592 + au_fset_fillvdir(arg->flags, WHABLE);
32595 + au_fclr_fillvdir(arg->flags, CALLED);
32597 + err = vfsub_iterate_dir(hf, &arg->ctx);
32600 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32603 + * dir_relax() may be good for concurrency, but aufs should not
32604 + * use it since it will cause a lockdep problem.
32608 + if (!err && shwh)
32609 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32611 + au_nhash_wh_free(&arg->whlist);
32614 + au_nhash_de_free(&arg->delist);
32619 +static int read_vdir(struct file *file, int may_read)
32622 + unsigned long expire;
32623 + unsigned char do_read;
32624 + struct fillvdir_arg arg = {
32626 + .actor = fillvdir
32629 + struct inode *inode;
32630 + struct au_vdir *vdir, *allocated;
32633 + inode = file_inode(file);
32634 + IMustLock(inode);
32635 + IiMustWriteLock(inode);
32636 + SiMustAnyLock(inode->i_sb);
32638 + allocated = NULL;
32640 + expire = au_sbi(inode->i_sb)->si_rdcache;
32641 + vdir = au_ivdir(inode);
32644 + vdir = alloc_vdir(file);
32645 + err = PTR_ERR(vdir);
32646 + if (IS_ERR(vdir))
32649 + allocated = vdir;
32650 + } else if (may_read
32651 + && (!inode_eq_iversion(inode, vdir->vd_version)
32652 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32654 + err = reinit_vdir(vdir);
32655 + if (unlikely(err))
32660 + return 0; /* success */
32664 + err = au_do_read_vdir(&arg);
32666 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32667 + vdir->vd_version = inode_query_iversion(inode);
32668 + vdir->vd_last.ul = 0;
32669 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32671 + au_set_ivdir(inode, allocated);
32672 + } else if (allocated)
32673 + au_vdir_free(allocated);
32679 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32682 + unsigned long ul, n;
32683 + const unsigned int deblk_sz = src->vd_deblk_sz;
32685 + AuDebugOn(tgt->vd_nblk != 1);
32688 + if (tgt->vd_nblk < src->vd_nblk) {
32689 + unsigned char **p;
32691 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32692 + GFP_NOFS, /*may_shrink*/0);
32693 + if (unlikely(!p))
32695 + tgt->vd_deblk = p;
32698 + if (tgt->vd_deblk_sz != deblk_sz) {
32699 + unsigned char *p;
32701 + tgt->vd_deblk_sz = deblk_sz;
32702 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32703 + /*may_shrink*/1);
32704 + if (unlikely(!p))
32706 + tgt->vd_deblk[0] = p;
32708 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32709 + tgt->vd_version = src->vd_version;
32710 + tgt->vd_jiffy = src->vd_jiffy;
32712 + n = src->vd_nblk;
32713 + for (ul = 1; ul < n; ul++) {
32714 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32716 + if (unlikely(!tgt->vd_deblk[ul]))
32720 + tgt->vd_nblk = n;
32721 + tgt->vd_last.ul = tgt->vd_last.ul;
32722 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32723 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32724 + - src->vd_deblk[src->vd_last.ul];
32726 + return 0; /* success */
32729 + rerr = reinit_vdir(tgt);
32734 +int au_vdir_init(struct file *file)
32737 + struct inode *inode;
32738 + struct au_vdir *vdir_cache, *allocated;
32740 + /* test file->f_pos here instead of ctx->pos */
32741 + err = read_vdir(file, !file->f_pos);
32742 + if (unlikely(err))
32745 + allocated = NULL;
32746 + vdir_cache = au_fvdir_cache(file);
32747 + if (!vdir_cache) {
32748 + vdir_cache = alloc_vdir(file);
32749 + err = PTR_ERR(vdir_cache);
32750 + if (IS_ERR(vdir_cache))
32752 + allocated = vdir_cache;
32753 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32754 + /* test file->f_pos here instead of ctx->pos */
32755 + err = reinit_vdir(vdir_cache);
32756 + if (unlikely(err))
32759 + return 0; /* success */
32761 + inode = file_inode(file);
32762 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32764 + file->f_version = inode_query_iversion(inode);
32766 + au_set_fvdir_cache(file, allocated);
32767 + } else if (allocated)
32768 + au_vdir_free(allocated);
32774 +static loff_t calc_offset(struct au_vdir *vdir)
32777 + union au_vdir_deblk_p p;
32779 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32780 + offset = vdir->vd_last.p.deblk - p.deblk;
32781 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32785 +/* returns true or false */
32786 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32789 + unsigned int deblk_sz;
32790 + unsigned long ul, n;
32792 + union au_vdir_deblk_p p, deblk_end;
32793 + struct au_vdir *vdir_cache;
32796 + vdir_cache = au_fvdir_cache(file);
32797 + offset = calc_offset(vdir_cache);
32798 + AuDbg("offset %lld\n", offset);
32799 + if (ctx->pos == offset)
32802 + vdir_cache->vd_last.ul = 0;
32803 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32808 + deblk_sz = vdir_cache->vd_deblk_sz;
32809 + ul = div64_u64(ctx->pos, deblk_sz);
32810 + AuDbg("ul %lu\n", ul);
32811 + if (ul >= vdir_cache->vd_nblk)
32814 + n = vdir_cache->vd_nblk;
32815 + for (; ul < n; ul++) {
32816 + p.deblk = vdir_cache->vd_deblk[ul];
32817 + deblk_end.deblk = p.deblk + deblk_sz;
32819 + offset *= deblk_sz;
32820 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32823 + l = calc_size(p.de->de_str.len);
32827 + if (!is_deblk_end(&p, &deblk_end)) {
32829 + vdir_cache->vd_last.ul = ul;
32830 + vdir_cache->vd_last.p = p;
32838 + AuDbg("valid %d\n", !valid);
32842 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32844 + unsigned int l, deblk_sz;
32845 + union au_vdir_deblk_p deblk_end;
32846 + struct au_vdir *vdir_cache;
32847 + struct au_vdir_de *de;
32849 + if (!seek_vdir(file, ctx))
32852 + vdir_cache = au_fvdir_cache(file);
32853 + deblk_sz = vdir_cache->vd_deblk_sz;
32855 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32856 + deblk_end.deblk += deblk_sz;
32857 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32858 + de = vdir_cache->vd_last.p.de;
32859 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32860 + de->de_str.len, de->de_str.name, ctx->pos,
32861 + (unsigned long)de->de_ino, de->de_type);
32862 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32863 + de->de_str.len, de->de_ino,
32865 + /* todo: ignore the error caused by udba? */
32866 + /* return err; */
32870 + l = calc_size(de->de_str.len);
32871 + vdir_cache->vd_last.p.deblk += l;
32874 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32875 + vdir_cache->vd_last.ul++;
32876 + vdir_cache->vd_last.p.deblk
32877 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32878 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32887 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32888 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32889 +++ linux/fs/aufs/vfsub.c 2022-03-21 14:49:05.733299677 +0100
32891 +// SPDX-License-Identifier: GPL-2.0
32893 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32895 + * This program, aufs is free software; you can redistribute it and/or modify
32896 + * it under the terms of the GNU General Public License as published by
32897 + * the Free Software Foundation; either version 2 of the License, or
32898 + * (at your option) any later version.
32900 + * This program is distributed in the hope that it will be useful,
32901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32903 + * GNU General Public License for more details.
32905 + * You should have received a copy of the GNU General Public License
32906 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32910 + * sub-routines for VFS
32913 +#include <linux/mnt_namespace.h>
32914 +#include <linux/nsproxy.h>
32915 +#include <linux/security.h>
32916 +#include <linux/splice.h>
32919 +#ifdef CONFIG_AUFS_BR_FUSE
32920 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32922 + if (!au_test_fuse(h_sb) || !au_userns)
32925 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32929 +int vfsub_sync_filesystem(struct super_block *h_sb)
32934 + down_read(&h_sb->s_umount);
32935 + err = sync_filesystem(h_sb);
32936 + up_read(&h_sb->s_umount);
32942 +/* ---------------------------------------------------------------------- */
32944 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32948 + struct super_block *h_sb;
32951 + * Always needs h_path->mnt for LSM or FUSE branch.
32953 + AuDebugOn(!h_path->mnt);
32955 + /* for remote fs, leave work for its getattr or d_revalidate */
32956 + /* for bad i_attr fs, handle them in aufs_getattr() */
32957 + /* still some fs may acquire i_mutex. we need to skip them */
32961 + h_sb = h_path->dentry->d_sb;
32962 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32964 + err = vfsub_getattr(h_path, &st);
32969 +/* ---------------------------------------------------------------------- */
32971 +struct file *vfsub_dentry_open(struct path *path, int flags)
32973 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32977 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32979 + struct file *file;
32982 + file = filp_open(path,
32983 + oflags /* | __FMODE_NONOTIFY */,
32986 + if (IS_ERR(file))
32988 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32995 + * Ideally this function should call VFS:do_last() in order to keep all its
32996 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32997 + * structure such as nameidata. This is a second (or third) best approach.
32998 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33000 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33001 + struct vfsub_aopen_args *args)
33004 + struct au_branch *br = args->br;
33005 + struct file *file = args->file;
33006 + /* copied from linux/fs/namei.c:atomic_open() */
33007 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33010 + AuDebugOn(!dir->i_op->atomic_open);
33012 + err = au_br_test_oflag(args->open_flag, br);
33013 + if (unlikely(err))
33016 + au_lcnt_inc(&br->br_nfiles);
33017 + file->f_path.dentry = DENTRY_NOT_SET;
33018 + file->f_path.mnt = au_br_mnt(br);
33019 + AuDbg("%ps\n", dir->i_op->atomic_open);
33020 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33021 + args->create_mode);
33022 + if (unlikely(err < 0)) {
33023 + au_lcnt_dec(&br->br_nfiles);
33027 + /* temporary workaround for nfsv4 branch */
33028 + if (au_test_nfs(dir->i_sb))
33029 + nfs_mark_for_revalidate(dir);
33031 + if (file->f_mode & FMODE_CREATED)
33032 + fsnotify_create(dir, dentry);
33033 + if (!(file->f_mode & FMODE_OPENED)) {
33034 + au_lcnt_dec(&br->br_nfiles);
33038 + /* todo: call VFS:may_open() here */
33039 + /* todo: ima_file_check() too? */
33040 + if (!err && (args->open_flag & __FMODE_EXEC))
33041 + err = deny_write_access(file);
33043 + fsnotify_open(file);
33045 + au_lcnt_dec(&br->br_nfiles);
33046 + /* note that the file is created and still opened */
33052 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33056 + err = kern_path(name, flags, path);
33057 + if (!err && d_is_positive(path->dentry))
33058 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33062 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33063 + struct path *ppath, int len)
33065 + struct path path;
33067 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33068 + if (IS_ERR(path.dentry))
33070 + if (d_is_positive(path.dentry)) {
33071 + path.mnt = ppath->mnt;
33072 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33076 + AuTraceErrPtr(path.dentry);
33077 + return path.dentry;
33080 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33083 + struct path path;
33085 + /* VFS checks it too, but by WARN_ON_ONCE() */
33086 + IMustLock(d_inode(ppath->dentry));
33088 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33089 + if (IS_ERR(path.dentry))
33091 + if (d_is_positive(path.dentry)) {
33092 + path.mnt = ppath->mnt;
33093 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33097 + AuTraceErrPtr(path.dentry);
33098 + return path.dentry;
33101 +void vfsub_call_lkup_one(void *args)
33103 + struct vfsub_lkup_one_args *a = args;
33104 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33107 +/* ---------------------------------------------------------------------- */
33109 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33110 + struct dentry *d2, struct au_hinode *hdir2)
33112 + struct dentry *d;
33115 + d = lock_rename(d1, d2);
33117 + au_hn_suspend(hdir1);
33118 + if (hdir1 != hdir2)
33119 + au_hn_suspend(hdir2);
33124 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33125 + struct dentry *d2, struct au_hinode *hdir2)
33127 + au_hn_resume(hdir1);
33128 + if (hdir1 != hdir2)
33129 + au_hn_resume(hdir2);
33131 + unlock_rename(d1, d2);
33135 +/* ---------------------------------------------------------------------- */
33137 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33140 + struct dentry *d;
33141 + struct user_namespace *userns;
33145 + d = path->dentry;
33146 + path->dentry = d->d_parent;
33147 + err = security_path_mknod(path, d, mode, 0);
33148 + path->dentry = d;
33149 + if (unlikely(err))
33151 + userns = mnt_user_ns(path->mnt);
33154 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
33157 + struct path tmp = *path;
33160 + vfsub_update_h_iattr(&tmp, &did);
33162 + tmp.dentry = path->dentry->d_parent;
33163 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33172 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33175 + struct dentry *d;
33176 + struct user_namespace *userns;
33180 + d = path->dentry;
33181 + path->dentry = d->d_parent;
33182 + err = security_path_symlink(path, d, symname);
33183 + path->dentry = d;
33184 + if (unlikely(err))
33186 + userns = mnt_user_ns(path->mnt);
33189 + err = vfs_symlink(userns, dir, path->dentry, symname);
33192 + struct path tmp = *path;
33195 + vfsub_update_h_iattr(&tmp, &did);
33197 + tmp.dentry = path->dentry->d_parent;
33198 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33207 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33210 + struct dentry *d;
33211 + struct user_namespace *userns;
33215 + d = path->dentry;
33216 + path->dentry = d->d_parent;
33217 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33218 + path->dentry = d;
33219 + if (unlikely(err))
33221 + userns = mnt_user_ns(path->mnt);
33224 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
33227 + struct path tmp = *path;
33230 + vfsub_update_h_iattr(&tmp, &did);
33232 + tmp.dentry = path->dentry->d_parent;
33233 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33242 +static int au_test_nlink(struct inode *inode)
33244 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33246 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33247 + || inode->i_nlink < link_max)
33252 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33253 + struct inode **delegated_inode)
33256 + struct dentry *d;
33257 + struct user_namespace *userns;
33261 + err = au_test_nlink(d_inode(src_dentry));
33262 + if (unlikely(err))
33265 + /* we don't call may_linkat() */
33266 + d = path->dentry;
33267 + path->dentry = d->d_parent;
33268 + err = security_path_link(src_dentry, path, d);
33269 + path->dentry = d;
33270 + if (unlikely(err))
33272 + userns = mnt_user_ns(path->mnt);
33275 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33278 + struct path tmp = *path;
33281 + /* fuse has different memory inode for the same inumber */
33282 + vfsub_update_h_iattr(&tmp, &did);
33284 + tmp.dentry = path->dentry->d_parent;
33285 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33286 + tmp.dentry = src_dentry;
33287 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33296 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33297 + struct inode *dir, struct path *path,
33298 + struct inode **delegated_inode, unsigned int flags)
33301 + struct renamedata rd;
33302 + struct path tmp = {
33305 + struct dentry *d;
33308 + IMustLock(src_dir);
33310 + d = path->dentry;
33311 + path->dentry = d->d_parent;
33312 + tmp.dentry = src_dentry->d_parent;
33313 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33314 + path->dentry = d;
33315 + if (unlikely(err))
33318 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33319 + rd.old_dir = src_dir;
33320 + rd.old_dentry = src_dentry;
33321 + rd.new_mnt_userns = rd.old_mnt_userns;
33322 + rd.new_dir = dir;
33323 + rd.new_dentry = path->dentry;
33324 + rd.delegated_inode = delegated_inode;
33325 + rd.flags = flags;
33327 + err = vfs_rename(&rd);
33332 + tmp.dentry = d->d_parent;
33333 + vfsub_update_h_iattr(&tmp, &did);
33335 + tmp.dentry = src_dentry;
33336 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33337 + tmp.dentry = src_dentry->d_parent;
33338 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33347 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33350 + struct dentry *d;
33351 + struct user_namespace *userns;
33355 + d = path->dentry;
33356 + path->dentry = d->d_parent;
33357 + err = security_path_mkdir(path, d, mode);
33358 + path->dentry = d;
33359 + if (unlikely(err))
33361 + userns = mnt_user_ns(path->mnt);
33364 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33367 + struct path tmp = *path;
33370 + vfsub_update_h_iattr(&tmp, &did);
33372 + tmp.dentry = path->dentry->d_parent;
33373 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33382 +int vfsub_rmdir(struct inode *dir, struct path *path)
33385 + struct dentry *d;
33386 + struct user_namespace *userns;
33390 + d = path->dentry;
33391 + path->dentry = d->d_parent;
33392 + err = security_path_rmdir(path, d);
33393 + path->dentry = d;
33394 + if (unlikely(err))
33396 + userns = mnt_user_ns(path->mnt);
33399 + err = vfs_rmdir(userns, dir, path->dentry);
33402 + struct path tmp = {
33403 + .dentry = path->dentry->d_parent,
33407 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33414 +/* ---------------------------------------------------------------------- */
33416 +/* todo: support mmap_sem? */
33417 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33423 + err = vfs_read(file, ubuf, count, ppos);
33426 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33430 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33436 + err = kernel_read(file, kbuf, count, ppos);
33440 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33444 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33450 + err = vfs_write(file, ubuf, count, ppos);
33453 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33457 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33462 + err = kernel_write(file, kbuf, count, ppos);
33465 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33469 +int vfsub_flush(struct file *file, fl_owner_t id)
33474 + if (file->f_op->flush) {
33475 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33476 + err = file->f_op->flush(file, id);
33479 + err = file->f_op->flush(file, id);
33483 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33489 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33493 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33496 + err = iterate_dir(file, ctx);
33499 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33504 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33505 + struct pipe_inode_info *pipe, size_t len,
33506 + unsigned int flags)
33511 + err = do_splice_to(in, ppos, pipe, len, flags);
33513 + file_accessed(in);
33515 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33519 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33520 + loff_t *ppos, size_t len, unsigned int flags)
33525 + err = do_splice_from(pipe, out, ppos, len, flags);
33528 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33532 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33536 + /* file can be NULL */
33538 + err = vfs_fsync(file, datasync);
33542 + AuDebugOn(!file);
33543 + path = &file->f_path;
33545 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33550 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33551 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33552 + struct file *h_file)
33555 + struct inode *h_inode;
33556 + struct super_block *h_sb;
33557 + struct user_namespace *h_userns;
33560 + err = vfsub_truncate(h_path, length);
33564 + h_inode = d_inode(h_path->dentry);
33565 + h_sb = h_inode->i_sb;
33567 + sb_start_write(h_sb);
33569 + err = security_path_truncate(h_path);
33571 + h_userns = mnt_user_ns(h_path->mnt);
33573 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33578 + sb_end_write(h_sb);
33585 +/* ---------------------------------------------------------------------- */
33587 +struct au_vfsub_mkdir_args {
33589 + struct inode *dir;
33590 + struct path *path;
33594 +static void au_call_vfsub_mkdir(void *args)
33596 + struct au_vfsub_mkdir_args *a = args;
33597 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33600 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33602 + int err, do_sio, wkq_err;
33603 + struct user_namespace *userns;
33605 + userns = mnt_user_ns(path->mnt);
33606 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33609 + err = vfsub_mkdir(dir, path, mode);
33612 + struct au_vfsub_mkdir_args args = {
33618 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33619 + if (unlikely(wkq_err))
33626 +struct au_vfsub_rmdir_args {
33628 + struct inode *dir;
33629 + struct path *path;
33632 +static void au_call_vfsub_rmdir(void *args)
33634 + struct au_vfsub_rmdir_args *a = args;
33635 + *a->errp = vfsub_rmdir(a->dir, a->path);
33638 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33640 + int err, do_sio, wkq_err;
33641 + struct user_namespace *userns;
33643 + userns = mnt_user_ns(path->mnt);
33644 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33647 + err = vfsub_rmdir(dir, path);
33650 + struct au_vfsub_rmdir_args args = {
33655 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33656 + if (unlikely(wkq_err))
33663 +/* ---------------------------------------------------------------------- */
33665 +struct notify_change_args {
33667 + struct path *path;
33668 + struct iattr *ia;
33669 + struct inode **delegated_inode;
33672 +static void call_notify_change(void *args)
33674 + struct notify_change_args *a = args;
33675 + struct inode *h_inode;
33676 + struct user_namespace *userns;
33678 + h_inode = d_inode(a->path->dentry);
33679 + IMustLock(h_inode);
33681 + *a->errp = -EPERM;
33682 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33683 + userns = mnt_user_ns(a->path->mnt);
33685 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33686 + a->delegated_inode);
33689 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33691 + AuTraceErr(*a->errp);
33694 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33695 + struct inode **delegated_inode)
33698 + struct notify_change_args args = {
33702 + .delegated_inode = delegated_inode
33705 + call_notify_change(&args);
33710 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33711 + struct inode **delegated_inode)
33713 + int err, wkq_err;
33714 + struct notify_change_args args = {
33718 + .delegated_inode = delegated_inode
33721 + wkq_err = au_wkq_wait(call_notify_change, &args);
33722 + if (unlikely(wkq_err))
33728 +/* ---------------------------------------------------------------------- */
33730 +struct unlink_args {
33732 + struct inode *dir;
33733 + struct path *path;
33734 + struct inode **delegated_inode;
33737 +static void call_unlink(void *args)
33739 + struct unlink_args *a = args;
33740 + struct dentry *d = a->path->dentry;
33741 + struct inode *h_inode;
33742 + struct user_namespace *userns;
33743 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33744 + && au_dcount(d) == 1);
33746 + IMustLock(a->dir);
33748 + a->path->dentry = d->d_parent;
33749 + *a->errp = security_path_unlink(a->path, d);
33750 + a->path->dentry = d;
33751 + if (unlikely(*a->errp))
33754 + if (!stop_sillyrename)
33757 + if (d_is_positive(d)) {
33758 + h_inode = d_inode(d);
33762 + userns = mnt_user_ns(a->path->mnt);
33764 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33767 + struct path tmp = {
33768 + .dentry = d->d_parent,
33769 + .mnt = a->path->mnt
33771 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33774 + if (!stop_sillyrename)
33779 + AuTraceErr(*a->errp);
33783 + * @dir: must be locked.
33784 + * @dentry: target dentry.
33786 +int vfsub_unlink(struct inode *dir, struct path *path,
33787 + struct inode **delegated_inode, int force)
33790 + struct unlink_args args = {
33794 + .delegated_inode = delegated_inode
33798 + call_unlink(&args);
33802 + wkq_err = au_wkq_wait(call_unlink, &args);
33803 + if (unlikely(wkq_err))
33809 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33810 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33811 +++ linux/fs/aufs/vfsub.h 2022-03-21 14:49:05.733299677 +0100
33813 +/* SPDX-License-Identifier: GPL-2.0 */
33815 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33817 + * This program, aufs is free software; you can redistribute it and/or modify
33818 + * it under the terms of the GNU General Public License as published by
33819 + * the Free Software Foundation; either version 2 of the License, or
33820 + * (at your option) any later version.
33822 + * This program is distributed in the hope that it will be useful,
33823 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33824 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33825 + * GNU General Public License for more details.
33827 + * You should have received a copy of the GNU General Public License
33828 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33832 + * sub-routines for VFS
33835 +#ifndef __AUFS_VFSUB_H__
33836 +#define __AUFS_VFSUB_H__
33840 +#include <linux/fs.h>
33841 +#include <linux/mount.h>
33842 +#include <linux/posix_acl.h>
33843 +#include <linux/xattr.h>
33844 +#include "debug.h"
33846 +/* copied from linux/fs/internal.h */
33847 +/* todo: BAD approach!! */
33848 +extern void __mnt_drop_write(struct vfsmount *);
33849 +extern struct file *alloc_empty_file(int, const struct cred *);
33851 +/* ---------------------------------------------------------------------- */
33853 +/* lock subclass for lower inode */
33854 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33855 +/* reduce? gave up. */
33857 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33858 + AuLsc_I_PARENT, /* lower inode, parent first */
33859 + AuLsc_I_PARENT2, /* copyup dirs */
33860 + AuLsc_I_PARENT3, /* copyup wh */
33866 +/* to debug easier, do not make them inlined functions */
33867 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33868 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33870 +/* ---------------------------------------------------------------------- */
33872 +static inline void vfsub_drop_nlink(struct inode *inode)
33874 + AuDebugOn(!inode->i_nlink);
33875 + drop_nlink(inode);
33878 +static inline void vfsub_dead_dir(struct inode *inode)
33880 + AuDebugOn(!S_ISDIR(inode->i_mode));
33881 + inode->i_flags |= S_DEAD;
33882 + clear_nlink(inode);
33885 +static inline int vfsub_native_ro(struct inode *inode)
33887 + return sb_rdonly(inode->i_sb)
33888 + || IS_RDONLY(inode)
33889 + /* || IS_APPEND(inode) */
33890 + || IS_IMMUTABLE(inode);
33893 +#ifdef CONFIG_AUFS_BR_FUSE
33894 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33896 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33899 +int vfsub_sync_filesystem(struct super_block *h_sb);
33901 +/* ---------------------------------------------------------------------- */
33903 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33904 +struct file *vfsub_dentry_open(struct path *path, int flags);
33905 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33907 +struct vfsub_aopen_args {
33908 + struct file *file;
33909 + unsigned int open_flag;
33910 + umode_t create_mode;
33911 + struct au_branch *br;
33913 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33914 + struct vfsub_aopen_args *args);
33915 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33917 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33918 + struct path *ppath, int len);
33919 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33922 +struct vfsub_lkup_one_args {
33923 + struct dentry **errp;
33924 + struct qstr *name;
33925 + struct path *ppath;
33928 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33929 + struct path *ppath)
33931 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33934 +void vfsub_call_lkup_one(void *args);
33936 +/* ---------------------------------------------------------------------- */
33938 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33943 + err = mnt_want_write(mnt);
33948 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33951 + mnt_drop_write(mnt);
33955 +#if 0 /* reserved */
33956 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33959 + mnt_drop_write_file(file);
33964 +/* ---------------------------------------------------------------------- */
33967 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33968 + struct dentry *d2, struct au_hinode *hdir2);
33969 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33970 + struct dentry *d2, struct au_hinode *hdir2);
33972 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33974 +int vfsub_symlink(struct inode *dir, struct path *path,
33975 + const char *symname);
33976 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33977 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33978 + struct path *path, struct inode **delegated_inode);
33979 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33980 + struct inode *hdir, struct path *path,
33981 + struct inode **delegated_inode, unsigned int flags);
33982 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33983 +int vfsub_rmdir(struct inode *dir, struct path *path);
33985 +/* ---------------------------------------------------------------------- */
33987 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33989 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33991 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33993 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33995 +int vfsub_flush(struct file *file, fl_owner_t id);
33996 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33998 +static inline loff_t vfsub_f_size_read(struct file *file)
34000 + return i_size_read(file_inode(file));
34003 +static inline unsigned int vfsub_file_flags(struct file *file)
34005 + unsigned int flags;
34007 + spin_lock(&file->f_lock);
34008 + flags = file->f_flags;
34009 + spin_unlock(&file->f_lock);
34014 +static inline int vfsub_file_execed(struct file *file)
34016 + /* todo: direct access f_flags */
34017 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34020 +#if 0 /* reserved */
34021 +static inline void vfsub_file_accessed(struct file *h_file)
34023 + file_accessed(h_file);
34024 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34028 +#if 0 /* reserved */
34029 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34030 + struct dentry *h_dentry)
34032 + struct path h_path = {
34033 + .dentry = h_dentry,
34036 + touch_atime(&h_path);
34037 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34041 +static inline int vfsub_update_time(struct inode *h_inode,
34042 + struct timespec64 *ts, int flags)
34044 + return inode_update_time(h_inode, ts, flags);
34045 + /* no vfsub_update_h_iattr() since we don't have struct path */
34048 +#ifdef CONFIG_FS_POSIX_ACL
34049 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
34050 + struct inode *h_inode, umode_t h_mode)
34054 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
34055 + if (err == -EOPNOTSUPP)
34060 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
34061 + struct inode *h_inode, umode_t h_mode);
34064 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34065 + struct pipe_inode_info *pipe, size_t len,
34066 + unsigned int flags);
34067 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34068 + loff_t *ppos, size_t len, unsigned int flags);
34070 +static inline long vfsub_truncate(struct path *path, loff_t length)
34075 + err = vfs_truncate(path, length);
34080 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34081 + struct file *h_file);
34082 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34085 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34088 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34094 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34100 +/* copy_file_range(2) is a systemcall */
34101 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34102 + struct file *dst, loff_t dst_pos,
34103 + size_t len, unsigned int flags)
34108 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34114 +/* ---------------------------------------------------------------------- */
34116 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34121 + err = vfs_llseek(file, offset, origin);
34126 +/* ---------------------------------------------------------------------- */
34128 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34129 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34130 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34131 + struct inode **delegated_inode);
34132 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34133 + struct inode **delegated_inode);
34134 +int vfsub_unlink(struct inode *dir, struct path *path,
34135 + struct inode **delegated_inode, int force);
34137 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34139 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34142 +/* ---------------------------------------------------------------------- */
34144 +static inline int vfsub_setxattr(struct user_namespace *userns,
34145 + struct dentry *dentry, const char *name,
34146 + const void *value, size_t size, int flags)
34151 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
34157 +static inline int vfsub_removexattr(struct user_namespace *userns,
34158 + struct dentry *dentry, const char *name)
34163 + err = vfs_removexattr(userns, dentry, name);
34169 +#endif /* __KERNEL__ */
34170 +#endif /* __AUFS_VFSUB_H__ */
34171 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34172 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34173 +++ linux/fs/aufs/wbr_policy.c 2022-03-21 14:49:05.733299677 +0100
34175 +// SPDX-License-Identifier: GPL-2.0
34177 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34179 + * This program, aufs is free software; you can redistribute it and/or modify
34180 + * it under the terms of the GNU General Public License as published by
34181 + * the Free Software Foundation; either version 2 of the License, or
34182 + * (at your option) any later version.
34184 + * This program is distributed in the hope that it will be useful,
34185 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34186 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34187 + * GNU General Public License for more details.
34189 + * You should have received a copy of the GNU General Public License
34190 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34194 + * policies for selecting one among multiple writable branches
34197 +#include <linux/statfs.h>
34200 +/* subset of cpup_attr() */
34201 +static noinline_for_stack
34202 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34206 + struct inode *h_isrc;
34208 + h_isrc = d_inode(h_src);
34209 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34210 + ia.ia_mode = h_isrc->i_mode;
34211 + ia.ia_uid = h_isrc->i_uid;
34212 + ia.ia_gid = h_isrc->i_gid;
34213 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34214 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34215 + /* no delegation since it is just created */
34216 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34218 + /* is this nfs only? */
34219 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34220 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34221 + ia.ia_mode = h_isrc->i_mode;
34222 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34228 +#define AuCpdown_PARENT_OPQ 1
34229 +#define AuCpdown_WHED (1 << 1)
34230 +#define AuCpdown_MADE_DIR (1 << 2)
34231 +#define AuCpdown_DIROPQ (1 << 3)
34232 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34233 +#define au_fset_cpdown(flags, name) \
34234 + do { (flags) |= AuCpdown_##name; } while (0)
34235 +#define au_fclr_cpdown(flags, name) \
34236 + do { (flags) &= ~AuCpdown_##name; } while (0)
34238 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34239 + unsigned int *flags)
34242 + struct dentry *opq_dentry;
34244 + opq_dentry = au_diropq_create(dentry, bdst);
34245 + err = PTR_ERR(opq_dentry);
34246 + if (IS_ERR(opq_dentry))
34248 + dput(opq_dentry);
34249 + au_fset_cpdown(*flags, DIROPQ);
34255 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34256 + struct inode *dir, aufs_bindex_t bdst)
34259 + struct path h_path;
34260 + struct au_branch *br;
34262 + br = au_sbr(dentry->d_sb, bdst);
34263 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34264 + err = PTR_ERR(h_path.dentry);
34265 + if (IS_ERR(h_path.dentry))
34269 + if (d_is_positive(h_path.dentry)) {
34270 + h_path.mnt = au_br_mnt(br);
34271 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34274 + dput(h_path.dentry);
34280 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34281 + struct au_pin *pin,
34282 + struct dentry *h_parent, void *arg)
34285 + aufs_bindex_t bopq, btop;
34286 + struct path h_path;
34287 + struct dentry *parent;
34288 + struct inode *h_dir, *h_inode, *inode, *dir;
34289 + unsigned int *flags = arg;
34291 + btop = au_dbtop(dentry);
34292 + /* dentry is di-locked */
34293 + parent = dget_parent(dentry);
34294 + dir = d_inode(parent);
34295 + h_dir = d_inode(h_parent);
34296 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34297 + IMustLock(h_dir);
34299 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34300 + if (unlikely(err < 0))
34302 + h_path.dentry = au_h_dptr(dentry, bdst);
34303 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34304 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34305 + if (unlikely(err))
34307 + au_fset_cpdown(*flags, MADE_DIR);
34309 + bopq = au_dbdiropq(dentry);
34310 + au_fclr_cpdown(*flags, WHED);
34311 + au_fclr_cpdown(*flags, DIROPQ);
34312 + if (au_dbwh(dentry) == bdst)
34313 + au_fset_cpdown(*flags, WHED);
34314 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34315 + au_fset_cpdown(*flags, PARENT_OPQ);
34316 + h_inode = d_inode(h_path.dentry);
34317 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34318 + if (au_ftest_cpdown(*flags, WHED)) {
34319 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34320 + if (unlikely(err)) {
34321 + inode_unlock(h_inode);
34326 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34327 + inode_unlock(h_inode);
34328 + if (unlikely(err))
34331 + if (au_ftest_cpdown(*flags, WHED)) {
34332 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34333 + if (unlikely(err))
34337 + inode = d_inode(dentry);
34338 + if (au_ibbot(inode) < bdst)
34339 + au_set_ibbot(inode, bdst);
34340 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34341 + au_hi_flags(inode, /*isdir*/1));
34342 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34343 + goto out; /* success */
34347 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34348 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34349 + rerr = au_diropq_remove(dentry, bdst);
34350 + inode_unlock(h_inode);
34351 + if (unlikely(rerr)) {
34352 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34353 + dentry, bdst, rerr);
34359 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34360 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34361 + if (unlikely(rerr)) {
34362 + AuIOErr("failed removing %pd b%d (%d)\n",
34363 + dentry, bdst, rerr);
34368 + au_set_h_dptr(dentry, bdst, NULL);
34369 + if (au_dbbot(dentry) == bdst)
34370 + au_update_dbbot(dentry);
34376 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34379 + unsigned int flags;
34382 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34387 +/* ---------------------------------------------------------------------- */
34389 +/* policies for create */
34391 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34393 + int err, i, j, ndentry;
34394 + aufs_bindex_t bopq;
34395 + struct au_dcsub_pages dpages;
34396 + struct au_dpage *dpage;
34397 + struct dentry **dentries, *parent, *d;
34399 + err = au_dpages_init(&dpages, GFP_NOFS);
34400 + if (unlikely(err))
34402 + parent = dget_parent(dentry);
34403 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34404 + if (unlikely(err))
34408 + for (i = 0; i < dpages.ndpage; i++) {
34409 + dpage = dpages.dpages + i;
34410 + dentries = dpage->dentries;
34411 + ndentry = dpage->ndentry;
34412 + for (j = 0; j < ndentry; j++) {
34414 + di_read_lock_parent2(d, !AuLock_IR);
34415 + bopq = au_dbdiropq(d);
34416 + di_read_unlock(d, !AuLock_IR);
34417 + if (bopq >= 0 && bopq < err)
34424 + au_dpages_free(&dpages);
34429 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34431 + for (; bindex >= 0; bindex--)
34432 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34437 +/* top down parent */
34438 +static int au_wbr_create_tdp(struct dentry *dentry,
34439 + unsigned int flags __maybe_unused)
34442 + aufs_bindex_t btop, bindex;
34443 + struct super_block *sb;
34444 + struct dentry *parent, *h_parent;
34446 + sb = dentry->d_sb;
34447 + btop = au_dbtop(dentry);
34449 + if (!au_br_rdonly(au_sbr(sb, btop)))
34453 + parent = dget_parent(dentry);
34454 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34455 + h_parent = au_h_dptr(parent, bindex);
34456 + if (!h_parent || d_is_negative(h_parent))
34459 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34466 + /* bottom up here */
34467 + if (unlikely(err < 0)) {
34468 + err = au_wbr_bu(sb, btop - 1);
34470 + err = au_wbr_nonopq(dentry, err);
34474 + AuDbg("b%d\n", err);
34478 +/* ---------------------------------------------------------------------- */
34480 +/* an exception for the policy other than tdp */
34481 +static int au_wbr_create_exp(struct dentry *dentry)
34484 + aufs_bindex_t bwh, bdiropq;
34485 + struct dentry *parent;
34488 + bwh = au_dbwh(dentry);
34489 + parent = dget_parent(dentry);
34490 + bdiropq = au_dbdiropq(parent);
34492 + if (bdiropq >= 0)
34493 + err = min(bdiropq, bwh);
34496 + AuDbg("%d\n", err);
34497 + } else if (bdiropq >= 0) {
34499 + AuDbg("%d\n", err);
34504 + err = au_wbr_nonopq(dentry, err);
34506 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34509 + AuDbg("%d\n", err);
34513 +/* ---------------------------------------------------------------------- */
34516 +static int au_wbr_create_init_rr(struct super_block *sb)
34520 + err = au_wbr_bu(sb, au_sbbot(sb));
34521 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34524 + AuDbg("b%d\n", err);
34528 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34532 + aufs_bindex_t bindex, bbot;
34533 + struct super_block *sb;
34536 + err = au_wbr_create_exp(dentry);
34540 + sb = dentry->d_sb;
34541 + next = &au_sbi(sb)->si_wbr_rr_next;
34542 + bbot = au_sbbot(sb);
34544 + for (bindex = 0; bindex <= bbot; bindex++) {
34545 + if (!au_ftest_wbr(flags, DIR)) {
34546 + err = atomic_dec_return(next) + 1;
34547 + /* modulo for 0 is meaningless */
34548 + if (unlikely(!err))
34549 + err = atomic_dec_return(next) + 1;
34551 + err = atomic_read(next);
34552 + AuDbg("%d\n", err);
34555 + AuDbg("%d\n", err);
34556 + if (!au_br_rdonly(au_sbr(sb, err)))
34562 + err = au_wbr_nonopq(dentry, err);
34565 + AuDbg("%d\n", err);
34569 +/* ---------------------------------------------------------------------- */
34571 +/* most free space */
34572 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34574 + struct super_block *sb;
34575 + struct au_branch *br;
34576 + struct au_wbr_mfs *mfs;
34577 + struct dentry *h_parent;
34578 + aufs_bindex_t bindex, bbot;
34580 + unsigned long long b, bavail;
34581 + struct path h_path;
34582 + /* reduce the stack usage */
34583 + struct kstatfs *st;
34585 + st = kmalloc(sizeof(*st), GFP_NOFS);
34586 + if (unlikely(!st)) {
34587 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34592 + sb = dentry->d_sb;
34593 + mfs = &au_sbi(sb)->si_wbr_mfs;
34594 + MtxMustLock(&mfs->mfs_lock);
34595 + mfs->mfs_bindex = -EROFS;
34596 + mfs->mfsrr_bytes = 0;
34599 + bbot = au_sbbot(sb);
34601 + bindex = au_dbtop(parent);
34602 + bbot = au_dbtaildir(parent);
34605 + for (; bindex <= bbot; bindex++) {
34607 + h_parent = au_h_dptr(parent, bindex);
34608 + if (!h_parent || d_is_negative(h_parent))
34611 + br = au_sbr(sb, bindex);
34612 + if (au_br_rdonly(br))
34615 + /* sb->s_root for NFS is unreliable */
34616 + h_path.mnt = au_br_mnt(br);
34617 + h_path.dentry = h_path.mnt->mnt_root;
34618 + err = vfs_statfs(&h_path, st);
34619 + if (unlikely(err)) {
34620 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34624 + /* when the available size is equal, select the lower one */
34625 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34626 + || sizeof(b) < sizeof(st->f_bsize));
34627 + b = st->f_bavail * st->f_bsize;
34628 + br->br_wbr->wbr_bytes = b;
34629 + if (b >= bavail) {
34631 + mfs->mfs_bindex = bindex;
34632 + mfs->mfs_jiffy = jiffies;
34636 + mfs->mfsrr_bytes = bavail;
34637 + AuDbg("b%d\n", mfs->mfs_bindex);
34638 + au_kfree_rcu(st);
34641 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34644 + struct dentry *parent;
34645 + struct super_block *sb;
34646 + struct au_wbr_mfs *mfs;
34648 + err = au_wbr_create_exp(dentry);
34652 + sb = dentry->d_sb;
34654 + if (au_ftest_wbr(flags, PARENT))
34655 + parent = dget_parent(dentry);
34656 + mfs = &au_sbi(sb)->si_wbr_mfs;
34657 + mutex_lock(&mfs->mfs_lock);
34658 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34659 + || mfs->mfs_bindex < 0
34660 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34661 + au_mfs(dentry, parent);
34662 + mutex_unlock(&mfs->mfs_lock);
34663 + err = mfs->mfs_bindex;
34667 + err = au_wbr_nonopq(dentry, err);
34670 + AuDbg("b%d\n", err);
34674 +static int au_wbr_create_init_mfs(struct super_block *sb)
34676 + struct au_wbr_mfs *mfs;
34678 + mfs = &au_sbi(sb)->si_wbr_mfs;
34679 + mutex_init(&mfs->mfs_lock);
34680 + mfs->mfs_jiffy = 0;
34681 + mfs->mfs_bindex = -EROFS;
34686 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34688 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34692 +/* ---------------------------------------------------------------------- */
34694 +/* top down regardless parent, and then mfs */
34695 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34696 + unsigned int flags __maybe_unused)
34699 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34700 + unsigned long long watermark;
34701 + struct super_block *sb;
34702 + struct au_wbr_mfs *mfs;
34703 + struct au_branch *br;
34704 + struct dentry *parent;
34706 + sb = dentry->d_sb;
34707 + mfs = &au_sbi(sb)->si_wbr_mfs;
34708 + mutex_lock(&mfs->mfs_lock);
34709 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34710 + || mfs->mfs_bindex < 0)
34711 + au_mfs(dentry, /*parent*/NULL);
34712 + watermark = mfs->mfsrr_watermark;
34713 + bmfs = mfs->mfs_bindex;
34714 + mutex_unlock(&mfs->mfs_lock);
34716 + /* another style of au_wbr_create_exp() */
34717 + bwh = au_dbwh(dentry);
34718 + parent = dget_parent(dentry);
34719 + btail = au_dbtaildir(parent);
34720 + if (bwh >= 0 && bwh < btail)
34723 + err = au_wbr_nonopq(dentry, btail);
34724 + if (unlikely(err < 0))
34728 + for (bindex = 0; bindex <= btail; bindex++) {
34729 + br = au_sbr(sb, bindex);
34730 + if (au_br_rdonly(br))
34732 + if (br->br_wbr->wbr_bytes > watermark) {
34743 + AuDbg("b%d\n", err);
34747 +/* ---------------------------------------------------------------------- */
34749 +/* most free space and then round robin */
34750 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34753 + struct au_wbr_mfs *mfs;
34755 + err = au_wbr_create_mfs(dentry, flags);
34757 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34758 + mutex_lock(&mfs->mfs_lock);
34759 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34760 + err = au_wbr_create_rr(dentry, flags);
34761 + mutex_unlock(&mfs->mfs_lock);
34764 + AuDbg("b%d\n", err);
34768 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34772 + au_wbr_create_init_mfs(sb); /* ignore */
34773 + err = au_wbr_create_init_rr(sb);
34778 +/* ---------------------------------------------------------------------- */
34780 +/* top down parent and most free space */
34781 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34784 + unsigned long long b;
34785 + aufs_bindex_t bindex, btop, bbot;
34786 + struct super_block *sb;
34787 + struct dentry *parent, *h_parent;
34788 + struct au_branch *br;
34790 + err = au_wbr_create_tdp(dentry, flags);
34791 + if (unlikely(err < 0))
34793 + parent = dget_parent(dentry);
34794 + btop = au_dbtop(parent);
34795 + bbot = au_dbtaildir(parent);
34796 + if (btop == bbot)
34797 + goto out_parent; /* success */
34799 + e2 = au_wbr_create_mfs(dentry, flags);
34801 + goto out_parent; /* success */
34803 + /* when the available size is equal, select upper one */
34804 + sb = dentry->d_sb;
34805 + br = au_sbr(sb, err);
34806 + b = br->br_wbr->wbr_bytes;
34807 + AuDbg("b%d, %llu\n", err, b);
34809 + for (bindex = btop; bindex <= bbot; bindex++) {
34810 + h_parent = au_h_dptr(parent, bindex);
34811 + if (!h_parent || d_is_negative(h_parent))
34814 + br = au_sbr(sb, bindex);
34815 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34816 + b = br->br_wbr->wbr_bytes;
34818 + AuDbg("b%d, %llu\n", err, b);
34823 + err = au_wbr_nonopq(dentry, err);
34828 + AuDbg("b%d\n", err);
34832 +/* ---------------------------------------------------------------------- */
34835 + * - top down parent
34836 + * - most free space with parent
34837 + * - most free space round-robin regardless parent
34839 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34842 + unsigned long long watermark;
34843 + struct super_block *sb;
34844 + struct au_branch *br;
34845 + struct au_wbr_mfs *mfs;
34847 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34848 + if (unlikely(err < 0))
34851 + sb = dentry->d_sb;
34852 + br = au_sbr(sb, err);
34853 + mfs = &au_sbi(sb)->si_wbr_mfs;
34854 + mutex_lock(&mfs->mfs_lock);
34855 + watermark = mfs->mfsrr_watermark;
34856 + mutex_unlock(&mfs->mfs_lock);
34857 + if (br->br_wbr->wbr_bytes < watermark)
34858 + /* regardless the parent dir */
34859 + err = au_wbr_create_mfsrr(dentry, flags);
34862 + AuDbg("b%d\n", err);
34866 +/* ---------------------------------------------------------------------- */
34868 +/* policies for copyup */
34870 +/* top down parent */
34871 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34873 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34876 +/* bottom up parent */
34877 +static int au_wbr_copyup_bup(struct dentry *dentry)
34880 + aufs_bindex_t bindex, btop;
34881 + struct dentry *parent, *h_parent;
34882 + struct super_block *sb;
34885 + sb = dentry->d_sb;
34886 + parent = dget_parent(dentry);
34887 + btop = au_dbtop(parent);
34888 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34889 + h_parent = au_h_dptr(parent, bindex);
34890 + if (!h_parent || d_is_negative(h_parent))
34893 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34900 + /* bottom up here */
34901 + if (unlikely(err < 0))
34902 + err = au_wbr_bu(sb, btop - 1);
34904 + AuDbg("b%d\n", err);
34909 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34913 + err = au_wbr_bu(dentry->d_sb, btop);
34914 + AuDbg("b%d\n", err);
34916 + err = au_wbr_nonopq(dentry, err);
34918 + AuDbg("b%d\n", err);
34922 +static int au_wbr_copyup_bu(struct dentry *dentry)
34925 + aufs_bindex_t btop;
34927 + btop = au_dbtop(dentry);
34928 + err = au_wbr_do_copyup_bu(dentry, btop);
34932 +/* ---------------------------------------------------------------------- */
34934 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34935 + [AuWbrCopyup_TDP] = {
34936 + .copyup = au_wbr_copyup_tdp
34938 + [AuWbrCopyup_BUP] = {
34939 + .copyup = au_wbr_copyup_bup
34941 + [AuWbrCopyup_BU] = {
34942 + .copyup = au_wbr_copyup_bu
34946 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34947 + [AuWbrCreate_TDP] = {
34948 + .create = au_wbr_create_tdp
34950 + [AuWbrCreate_RR] = {
34951 + .create = au_wbr_create_rr,
34952 + .init = au_wbr_create_init_rr
34954 + [AuWbrCreate_MFS] = {
34955 + .create = au_wbr_create_mfs,
34956 + .init = au_wbr_create_init_mfs,
34957 + .fin = au_wbr_create_fin_mfs
34959 + [AuWbrCreate_MFSV] = {
34960 + .create = au_wbr_create_mfs,
34961 + .init = au_wbr_create_init_mfs,
34962 + .fin = au_wbr_create_fin_mfs
34964 + [AuWbrCreate_MFSRR] = {
34965 + .create = au_wbr_create_mfsrr,
34966 + .init = au_wbr_create_init_mfsrr,
34967 + .fin = au_wbr_create_fin_mfs
34969 + [AuWbrCreate_MFSRRV] = {
34970 + .create = au_wbr_create_mfsrr,
34971 + .init = au_wbr_create_init_mfsrr,
34972 + .fin = au_wbr_create_fin_mfs
34974 + [AuWbrCreate_TDMFS] = {
34975 + .create = au_wbr_create_tdmfs,
34976 + .init = au_wbr_create_init_mfs,
34977 + .fin = au_wbr_create_fin_mfs
34979 + [AuWbrCreate_TDMFSV] = {
34980 + .create = au_wbr_create_tdmfs,
34981 + .init = au_wbr_create_init_mfs,
34982 + .fin = au_wbr_create_fin_mfs
34984 + [AuWbrCreate_PMFS] = {
34985 + .create = au_wbr_create_pmfs,
34986 + .init = au_wbr_create_init_mfs,
34987 + .fin = au_wbr_create_fin_mfs
34989 + [AuWbrCreate_PMFSV] = {
34990 + .create = au_wbr_create_pmfs,
34991 + .init = au_wbr_create_init_mfs,
34992 + .fin = au_wbr_create_fin_mfs
34994 + [AuWbrCreate_PMFSRR] = {
34995 + .create = au_wbr_create_pmfsrr,
34996 + .init = au_wbr_create_init_mfsrr,
34997 + .fin = au_wbr_create_fin_mfs
34999 + [AuWbrCreate_PMFSRRV] = {
35000 + .create = au_wbr_create_pmfsrr,
35001 + .init = au_wbr_create_init_mfsrr,
35002 + .fin = au_wbr_create_fin_mfs
35005 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35006 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35007 +++ linux/fs/aufs/whout.c 2022-03-21 14:49:05.733299677 +0100
35009 +// SPDX-License-Identifier: GPL-2.0
35011 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35013 + * This program, aufs is free software; you can redistribute it and/or modify
35014 + * it under the terms of the GNU General Public License as published by
35015 + * the Free Software Foundation; either version 2 of the License, or
35016 + * (at your option) any later version.
35018 + * This program is distributed in the hope that it will be useful,
35019 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35020 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35021 + * GNU General Public License for more details.
35023 + * You should have received a copy of the GNU General Public License
35024 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35028 + * whiteout for logical deletion and opaque directory
35033 +#define WH_MASK 0444
35036 + * If a directory contains this file, then it is opaque. We start with the
35037 + * .wh. flag so that it is blocked by lookup.
35039 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35040 + sizeof(AUFS_WH_DIROPQ) - 1);
35043 + * generate whiteout name, which is NOT terminated by NULL.
35044 + * @name: original d_name.name
35045 + * @len: original d_name.len
35046 + * @wh: whiteout qstr
35047 + * returns zero when succeeds, otherwise error.
35048 + * succeeded value as wh->name should be freed by kfree().
35050 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35054 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35055 + return -ENAMETOOLONG;
35057 + wh->len = name->len + AUFS_WH_PFX_LEN;
35058 + p = kmalloc(wh->len, GFP_NOFS);
35061 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35062 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35069 +/* ---------------------------------------------------------------------- */
35072 + * test if the @wh_name exists under @h_ppath.
35073 + * @try_sio specifies the necessary of super-io.
35075 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35076 + struct qstr *wh_name, int try_sio)
35079 + struct dentry *wh_dentry;
35082 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35084 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
35085 + err = PTR_ERR(wh_dentry);
35086 + if (IS_ERR(wh_dentry)) {
35087 + if (err == -ENAMETOOLONG)
35093 + if (d_is_negative(wh_dentry))
35094 + goto out_wh; /* success */
35097 + if (d_is_reg(wh_dentry))
35098 + goto out_wh; /* success */
35101 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35102 + wh_dentry, d_inode(wh_dentry)->i_mode);
35111 + * test if the @h_path->dentry sets opaque or not.
35113 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
35116 + struct inode *h_dir;
35118 + h_dir = d_inode(h_path->dentry);
35119 + err = au_wh_test(h_userns, h_path, &diropq_name,
35120 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
35125 + * returns a negative dentry whose name is unique and temporary.
35127 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35128 + struct qstr *prefix)
35130 + struct dentry *dentry;
35132 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35134 + /* strict atomic_t is unnecessary here */
35135 + static unsigned short cnt;
35137 + struct path h_ppath;
35138 + struct user_namespace *h_userns;
35140 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35143 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35144 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35145 + dentry = ERR_PTR(-ENAMETOOLONG);
35146 + if (unlikely(qs.len > NAME_MAX))
35148 + dentry = ERR_PTR(-ENOMEM);
35149 + name = kmalloc(qs.len + 1, GFP_NOFS);
35150 + if (unlikely(!name))
35154 + /* doubly whiteout-ed */
35155 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35156 + p = name + AUFS_WH_PFX_LEN * 2;
35157 + memcpy(p, prefix->name, prefix->len);
35158 + p += prefix->len;
35160 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35162 + h_ppath.dentry = h_parent;
35163 + h_ppath.mnt = au_br_mnt(br);
35164 + h_userns = au_br_userns(br);
35166 + for (i = 0; i < 3; i++) {
35167 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35168 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
35169 + if (IS_ERR(dentry) || d_is_negative(dentry))
35173 + /* pr_warn("could not get random name\n"); */
35174 + dentry = ERR_PTR(-EEXIST);
35175 + AuDbg("%.*s\n", AuLNPair(&qs));
35179 + if (name != defname)
35180 + au_kfree_try_rcu(name);
35182 + AuTraceErrPtr(dentry);
35187 + * rename the @h_dentry on @br to the whiteouted temporary name.
35189 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35192 + struct path h_path = {
35193 + .mnt = au_br_mnt(br)
35195 + struct inode *h_dir, *delegated;
35196 + struct dentry *h_parent;
35198 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35199 + h_dir = d_inode(h_parent);
35200 + IMustLock(h_dir);
35202 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35203 + err = PTR_ERR(h_path.dentry);
35204 + if (IS_ERR(h_path.dentry))
35207 + /* under the same dir, no need to lock_rename() */
35208 + delegated = NULL;
35209 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35212 + if (unlikely(err == -EWOULDBLOCK)) {
35213 + pr_warn("cannot retry for NFSv4 delegation"
35214 + " for an internal rename\n");
35217 + dput(h_path.dentry);
35224 +/* ---------------------------------------------------------------------- */
35226 + * functions for removing a whiteout
35229 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35232 + struct inode *delegated;
35235 + * forces superio when the dir has a sticky bit.
35236 + * this may be a violation of unix fs semantics.
35238 + force = (h_dir->i_mode & S_ISVTX)
35239 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35240 + delegated = NULL;
35241 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35242 + if (unlikely(err == -EWOULDBLOCK)) {
35243 + pr_warn("cannot retry for NFSv4 delegation"
35244 + " for an internal unlink\n");
35250 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35251 + struct dentry *dentry)
35255 + err = do_unlink_wh(h_dir, h_path);
35256 + if (!err && dentry)
35257 + au_set_dbwh(dentry, -1);
35262 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35265 + struct path h_path;
35268 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35269 + if (IS_ERR(h_path.dentry))
35270 + err = PTR_ERR(h_path.dentry);
35272 + if (d_is_reg(h_path.dentry)) {
35273 + h_path.mnt = h_ppath->mnt;
35274 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35276 + dput(h_path.dentry);
35282 +/* ---------------------------------------------------------------------- */
35284 + * initialize/clean whiteout for a branch
35287 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35291 + struct inode *delegated;
35293 + if (d_is_negative(whpath->dentry))
35297 + err = vfsub_rmdir(h_dir, whpath);
35299 + delegated = NULL;
35300 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35301 + if (unlikely(err == -EWOULDBLOCK)) {
35302 + pr_warn("cannot retry for NFSv4 delegation"
35303 + " for an internal unlink\n");
35307 + if (unlikely(err))
35308 + pr_warn("failed removing %pd (%d), ignored.\n",
35309 + whpath->dentry, err);
35312 +static int test_linkable(struct dentry *h_root)
35314 + struct inode *h_dir = d_inode(h_root);
35316 + if (h_dir->i_op->link)
35319 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35320 + h_root, au_sbtype(h_root->d_sb));
35321 + return -ENOSYS; /* the branch doesn't have its ->link() */
35324 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35325 +static int au_whdir(struct inode *h_dir, struct path *path)
35330 + if (d_is_negative(path->dentry)) {
35333 + if (au_test_nfs(path->dentry->d_sb))
35335 + err = vfsub_mkdir(h_dir, path, mode);
35336 + } else if (d_is_dir(path->dentry))
35339 + pr_err("unknown %pd exists\n", path->dentry);
35344 +struct au_wh_base {
35345 + const struct qstr *name;
35346 + struct dentry *dentry;
35349 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35350 + struct path *h_path)
35352 + h_path->dentry = base[AuBrWh_BASE].dentry;
35353 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35354 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35355 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35356 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35357 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35361 + * returns tri-state,
35362 + * minus: error, caller should print the message
35364 + * plus: error, caller should NOT print the message
35366 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35367 + int do_plink, struct au_wh_base base[],
35368 + struct path *h_path)
35371 + struct inode *h_dir;
35373 + h_dir = d_inode(h_root);
35374 + h_path->dentry = base[AuBrWh_BASE].dentry;
35375 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35376 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35378 + err = test_linkable(h_root);
35379 + if (unlikely(err)) {
35384 + err = au_whdir(h_dir, h_path);
35385 + if (unlikely(err))
35387 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35389 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35390 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35391 + err = au_whdir(h_dir, h_path);
35392 + if (unlikely(err))
35394 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35401 + * for the moment, aufs supports the branch filesystem which does not support
35402 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35403 + * copyup failed. finally, such filesystem will not be used as the writable
35406 + * returns tri-state, see above.
35408 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35409 + int do_plink, struct au_wh_base base[],
35410 + struct path *h_path)
35413 + struct inode *h_dir;
35415 + WbrWhMustWriteLock(wbr);
35417 + err = test_linkable(h_root);
35418 + if (unlikely(err)) {
35424 + * todo: should this create be done in /sbin/mount.aufs helper?
35427 + h_dir = d_inode(h_root);
35428 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35429 + h_path->dentry = base[AuBrWh_BASE].dentry;
35430 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35431 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35434 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35435 + if (unlikely(err))
35438 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35440 + err = au_whdir(h_dir, h_path);
35441 + if (unlikely(err))
35443 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35445 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35446 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35448 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35449 + err = au_whdir(h_dir, h_path);
35450 + if (unlikely(err))
35452 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35459 + * initialize the whiteout base file/dir for @br.
35461 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35464 + const unsigned char do_plink
35465 + = !!au_opt_test(au_mntflags(sb), PLINK);
35466 + struct inode *h_dir;
35467 + struct path path = br->br_path;
35468 + struct dentry *h_root = path.dentry;
35469 + struct au_wbr *wbr = br->br_wbr;
35470 + static const struct qstr base_name[] = {
35471 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35472 + sizeof(AUFS_BASE_NAME) - 1),
35473 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35474 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35475 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35476 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35478 + struct au_wh_base base[] = {
35479 + [AuBrWh_BASE] = {
35480 + .name = base_name + AuBrWh_BASE,
35483 + [AuBrWh_PLINK] = {
35484 + .name = base_name + AuBrWh_PLINK,
35487 + [AuBrWh_ORPH] = {
35488 + .name = base_name + AuBrWh_ORPH,
35494 + WbrWhMustWriteLock(wbr);
35496 + for (i = 0; i < AuBrWh_Last; i++) {
35497 + /* doubly whiteouted */
35498 + struct dentry *d;
35500 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35501 + err = PTR_ERR(d);
35505 + base[i].dentry = d;
35507 + && wbr->wbr_wh[i]
35508 + && wbr->wbr_wh[i] != base[i].dentry);
35512 + for (i = 0; i < AuBrWh_Last; i++) {
35513 + dput(wbr->wbr_wh[i]);
35514 + wbr->wbr_wh[i] = NULL;
35518 + if (!au_br_writable(br->br_perm)) {
35519 + h_dir = d_inode(h_root);
35520 + au_wh_init_ro(h_dir, base, &path);
35521 + } else if (!au_br_wh_linkable(br->br_perm)) {
35522 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35528 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35534 + goto out; /* success */
35537 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35538 + err, h_root, au_sbtype(h_root->d_sb));
35540 + for (i = 0; i < AuBrWh_Last; i++)
35541 + dput(base[i].dentry);
35545 +/* ---------------------------------------------------------------------- */
35547 + * whiteouts are all hard-linked usually.
35548 + * when its link count reaches a ceiling, we create a new whiteout base
35549 + * asynchronously.
35552 +struct reinit_br_wh {
35553 + struct super_block *sb;
35554 + struct au_branch *br;
35557 +static void reinit_br_wh(void *arg)
35560 + aufs_bindex_t bindex;
35561 + struct path h_path;
35562 + struct reinit_br_wh *a = arg;
35563 + struct au_wbr *wbr;
35564 + struct inode *dir, *delegated;
35565 + struct dentry *h_root;
35566 + struct au_hinode *hdir;
35569 + wbr = a->br->br_wbr;
35570 + /* big aufs lock */
35571 + si_noflush_write_lock(a->sb);
35572 + if (!au_br_writable(a->br->br_perm))
35574 + bindex = au_br_index(a->sb, a->br->br_id);
35575 + if (unlikely(bindex < 0))
35578 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35579 + dir = d_inode(a->sb->s_root);
35580 + hdir = au_hi(dir, bindex);
35581 + h_root = au_h_dptr(a->sb->s_root, bindex);
35582 + AuDebugOn(h_root != au_br_dentry(a->br));
35584 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35585 + wbr_wh_write_lock(wbr);
35586 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35589 + h_path.dentry = wbr->wbr_whbase;
35590 + h_path.mnt = au_br_mnt(a->br);
35591 + delegated = NULL;
35592 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35594 + if (unlikely(err == -EWOULDBLOCK)) {
35595 + pr_warn("cannot retry for NFSv4 delegation"
35596 + " for an internal unlink\n");
35600 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35603 + dput(wbr->wbr_whbase);
35604 + wbr->wbr_whbase = NULL;
35606 + err = au_wh_init(a->br, a->sb);
35607 + wbr_wh_write_unlock(wbr);
35608 + au_hn_inode_unlock(hdir);
35609 + di_read_unlock(a->sb->s_root, AuLock_IR);
35611 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35615 + atomic_dec(&wbr->wbr_wh_running);
35616 + au_lcnt_dec(&a->br->br_count);
35617 + si_write_unlock(a->sb);
35618 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35620 + if (unlikely(err))
35621 + AuIOErr("err %d\n", err);
35624 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35626 + int do_dec, wkq_err;
35627 + struct reinit_br_wh *arg;
35630 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35633 + /* ignore ENOMEM */
35634 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35637 + * dec(wh_running), kfree(arg) and dec(br_count)
35638 + * in reinit function
35642 + au_lcnt_inc(&br->br_count);
35643 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35644 + if (unlikely(wkq_err)) {
35645 + atomic_dec(&br->br_wbr->wbr_wh_running);
35646 + au_lcnt_dec(&br->br_count);
35647 + au_kfree_rcu(arg);
35654 + atomic_dec(&br->br_wbr->wbr_wh_running);
35657 +/* ---------------------------------------------------------------------- */
35660 + * create the whiteout @wh.
35662 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35663 + struct dentry *wh)
35666 + struct path h_path = {
35669 + struct au_branch *br;
35670 + struct au_wbr *wbr;
35671 + struct dentry *h_parent;
35672 + struct inode *h_dir, *delegated;
35674 + h_parent = wh->d_parent; /* dir inode is locked */
35675 + h_dir = d_inode(h_parent);
35676 + IMustLock(h_dir);
35678 + br = au_sbr(sb, bindex);
35679 + h_path.mnt = au_br_mnt(br);
35680 + wbr = br->br_wbr;
35681 + wbr_wh_read_lock(wbr);
35682 + if (wbr->wbr_whbase) {
35683 + delegated = NULL;
35684 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35685 + if (unlikely(err == -EWOULDBLOCK)) {
35686 + pr_warn("cannot retry for NFSv4 delegation"
35687 + " for an internal link\n");
35690 + if (!err || err != -EMLINK)
35693 + /* link count full. re-initialize br_whbase. */
35694 + kick_reinit_br_wh(sb, br);
35697 + /* return this error in this context */
35698 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35700 + au_fhsm_wrote(sb, bindex, /*force*/0);
35703 + wbr_wh_read_unlock(wbr);
35707 +/* ---------------------------------------------------------------------- */
35710 + * create or remove the diropq.
35712 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35713 + unsigned int flags)
35715 + struct dentry *opq_dentry;
35716 + struct super_block *sb;
35717 + struct au_branch *br;
35718 + struct path h_path;
35721 + sb = dentry->d_sb;
35722 + br = au_sbr(sb, bindex);
35723 + h_path.dentry = au_h_dptr(dentry, bindex);
35724 + h_path.mnt = au_br_mnt(br);
35725 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35726 + if (IS_ERR(opq_dentry))
35729 + if (au_ftest_diropq(flags, CREATE)) {
35730 + err = link_or_create_wh(sb, bindex, opq_dentry);
35732 + au_set_dbdiropq(dentry, bindex);
35733 + goto out; /* success */
35736 + h_path.dentry = opq_dentry;
35737 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35739 + au_set_dbdiropq(dentry, -1);
35741 + dput(opq_dentry);
35742 + opq_dentry = ERR_PTR(err);
35745 + return opq_dentry;
35748 +struct do_diropq_args {
35749 + struct dentry **errp;
35750 + struct dentry *dentry;
35751 + aufs_bindex_t bindex;
35752 + unsigned int flags;
35755 +static void call_do_diropq(void *args)
35757 + struct do_diropq_args *a = args;
35758 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35761 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35762 + unsigned int flags)
35764 + struct dentry *diropq, *h_dentry;
35765 + struct user_namespace *h_userns;
35767 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35768 + h_dentry = au_h_dptr(dentry, bindex);
35769 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35770 + MAY_EXEC | MAY_WRITE))
35771 + diropq = do_diropq(dentry, bindex, flags);
35774 + struct do_diropq_args args = {
35776 + .dentry = dentry,
35777 + .bindex = bindex,
35781 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35782 + if (unlikely(wkq_err))
35783 + diropq = ERR_PTR(wkq_err);
35789 +/* ---------------------------------------------------------------------- */
35792 + * lookup whiteout dentry.
35793 + * @h_parent: lower parent dentry which must exist and be locked
35794 + * @base_name: name of dentry which will be whiteouted
35795 + * returns dentry for whiteout.
35797 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35798 + struct au_branch *br)
35801 + struct qstr wh_name;
35802 + struct dentry *wh_dentry;
35803 + struct path h_path;
35805 + err = au_wh_name_alloc(&wh_name, base_name);
35806 + wh_dentry = ERR_PTR(err);
35808 + h_path.dentry = h_parent;
35809 + h_path.mnt = au_br_mnt(br);
35810 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35811 + au_kfree_try_rcu(wh_name.name);
35813 + return wh_dentry;
35817 + * link/create a whiteout for @dentry on @bindex.
35819 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35820 + struct dentry *h_parent)
35822 + struct dentry *wh_dentry;
35823 + struct super_block *sb;
35826 + sb = dentry->d_sb;
35827 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35828 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35829 + err = link_or_create_wh(sb, bindex, wh_dentry);
35831 + au_set_dbwh(dentry, bindex);
35832 + au_fhsm_wrote(sb, bindex, /*force*/0);
35835 + wh_dentry = ERR_PTR(err);
35839 + return wh_dentry;
35842 +/* ---------------------------------------------------------------------- */
35844 +/* Delete all whiteouts in this directory on branch bindex. */
35845 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35846 + aufs_bindex_t bindex)
35849 + unsigned long ul, n;
35850 + struct qstr wh_name;
35852 + struct hlist_head *head;
35853 + struct au_vdir_wh *pos;
35854 + struct au_vdir_destr *str;
35857 + p = (void *)__get_free_page(GFP_NOFS);
35858 + wh_name.name = p;
35859 + if (unlikely(!wh_name.name))
35863 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35864 + p += AUFS_WH_PFX_LEN;
35865 + n = whlist->nh_num;
35866 + head = whlist->nh_head;
35867 + for (ul = 0; !err && ul < n; ul++, head++) {
35868 + hlist_for_each_entry(pos, head, wh_hash) {
35869 + if (pos->wh_bindex != bindex)
35872 + str = &pos->wh_str;
35873 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35874 + memcpy(p, str->name, str->len);
35875 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35876 + err = unlink_wh_name(h_path, &wh_name);
35881 + AuIOErr("whiteout name too long %.*s\n",
35882 + str->len, str->name);
35887 + free_page((unsigned long)wh_name.name);
35893 +struct del_wh_children_args {
35895 + struct path *h_path;
35896 + struct au_nhash *whlist;
35897 + aufs_bindex_t bindex;
35900 +static void call_del_wh_children(void *args)
35902 + struct del_wh_children_args *a = args;
35903 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35906 +/* ---------------------------------------------------------------------- */
35908 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35910 + struct au_whtmp_rmdir *whtmp;
35912 + unsigned int rdhash;
35914 + SiMustAnyLock(sb);
35916 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35917 + if (unlikely(!whtmp)) {
35918 + whtmp = ERR_PTR(-ENOMEM);
35922 + /* no estimation for dir size */
35923 + rdhash = au_sbi(sb)->si_rdhash;
35925 + rdhash = AUFS_RDHASH_DEF;
35926 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35927 + if (unlikely(err)) {
35928 + au_kfree_rcu(whtmp);
35929 + whtmp = ERR_PTR(err);
35936 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35939 + au_lcnt_dec(&whtmp->br->br_count);
35940 + dput(whtmp->wh_dentry);
35941 + iput(whtmp->dir);
35942 + au_nhash_wh_free(&whtmp->whlist);
35943 + au_kfree_rcu(whtmp);
35947 + * rmdir the whiteouted temporary named dir @h_dentry.
35948 + * @whlist: whiteouted children.
35950 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35951 + struct dentry *wh_dentry, struct au_nhash *whlist)
35954 + unsigned int h_nlink;
35955 + struct path wh_path;
35956 + struct inode *wh_inode, *h_dir;
35957 + struct au_branch *br;
35958 + struct user_namespace *h_userns;
35960 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35961 + IMustLock(h_dir);
35963 + br = au_sbr(dir->i_sb, bindex);
35964 + wh_path.dentry = wh_dentry;
35965 + wh_path.mnt = au_br_mnt(br);
35966 + h_userns = au_br_userns(br);
35967 + wh_inode = d_inode(wh_dentry);
35968 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35971 + * someone else might change some whiteouts while we were sleeping.
35972 + * it means this whlist may have an obsoleted entry.
35974 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
35975 + err = del_wh_children(&wh_path, whlist, bindex);
35978 + struct del_wh_children_args args = {
35980 + .h_path = &wh_path,
35981 + .whlist = whlist,
35985 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35986 + if (unlikely(wkq_err))
35989 + inode_unlock(wh_inode);
35992 + h_nlink = h_dir->i_nlink;
35993 + err = vfsub_rmdir(h_dir, &wh_path);
35994 + /* some fs doesn't change the parent nlink in some cases */
35995 + h_nlink -= h_dir->i_nlink;
35999 + if (au_ibtop(dir) == bindex) {
36000 + /* todo: dir->i_mutex is necessary */
36001 + au_cpup_attr_timesizes(dir);
36003 + vfsub_drop_nlink(dir);
36005 + return 0; /* success */
36008 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36012 +static void call_rmdir_whtmp(void *args)
36015 + aufs_bindex_t bindex;
36016 + struct au_whtmp_rmdir *a = args;
36017 + struct super_block *sb;
36018 + struct dentry *h_parent;
36019 + struct inode *h_dir;
36020 + struct au_hinode *hdir;
36022 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36023 + /* inode_lock(a->dir); */
36025 + sb = a->dir->i_sb;
36026 + si_read_lock(sb, !AuLock_FLUSH);
36027 + if (!au_br_writable(a->br->br_perm))
36029 + bindex = au_br_index(sb, a->br->br_id);
36030 + if (unlikely(bindex < 0))
36034 + ii_write_lock_parent(a->dir);
36035 + h_parent = dget_parent(a->wh_dentry);
36036 + h_dir = d_inode(h_parent);
36037 + hdir = au_hi(a->dir, bindex);
36038 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36039 + if (unlikely(err))
36041 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36042 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36045 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36046 + au_hn_inode_unlock(hdir);
36047 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36051 + ii_write_unlock(a->dir);
36053 + /* inode_unlock(a->dir); */
36054 + au_whtmp_rmdir_free(a);
36055 + si_read_unlock(sb);
36056 + au_nwt_done(&au_sbi(sb)->si_nowait);
36057 + if (unlikely(err))
36058 + AuIOErr("err %d\n", err);
36061 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36062 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36065 + struct super_block *sb;
36069 + /* all post-process will be done in do_rmdir_whtmp(). */
36071 + args->dir = au_igrab(dir);
36072 + args->br = au_sbr(sb, bindex);
36073 + au_lcnt_inc(&args->br->br_count);
36074 + args->wh_dentry = dget(wh_dentry);
36075 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36076 + if (unlikely(wkq_err)) {
36077 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36078 + au_whtmp_rmdir_free(args);
36081 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36082 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36083 +++ linux/fs/aufs/whout.h 2022-03-21 14:49:05.733299677 +0100
36085 +/* SPDX-License-Identifier: GPL-2.0 */
36087 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36089 + * This program, aufs is free software; you can redistribute it and/or modify
36090 + * it under the terms of the GNU General Public License as published by
36091 + * the Free Software Foundation; either version 2 of the License, or
36092 + * (at your option) any later version.
36094 + * This program is distributed in the hope that it will be useful,
36095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36097 + * GNU General Public License for more details.
36099 + * You should have received a copy of the GNU General Public License
36100 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36104 + * whiteout for logical deletion and opaque directory
36107 +#ifndef __AUFS_WHOUT_H__
36108 +#define __AUFS_WHOUT_H__
36115 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36116 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
36117 + struct qstr *wh_name, int try_sio);
36118 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
36120 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36121 + struct qstr *prefix);
36122 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36123 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36124 + struct dentry *dentry);
36125 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36127 +/* diropq flags */
36128 +#define AuDiropq_CREATE 1
36129 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36130 +#define au_fset_diropq(flags, name) \
36131 + do { (flags) |= AuDiropq_##name; } while (0)
36132 +#define au_fclr_diropq(flags, name) \
36133 + do { (flags) &= ~AuDiropq_##name; } while (0)
36135 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36136 + unsigned int flags);
36137 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36138 + struct au_branch *br);
36139 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36140 + struct dentry *h_parent);
36142 +/* real rmdir for the whiteout-ed dir */
36143 +struct au_whtmp_rmdir {
36144 + struct inode *dir;
36145 + struct au_branch *br;
36146 + struct dentry *wh_dentry;
36147 + struct au_nhash whlist;
36150 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36151 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36152 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36153 + struct dentry *wh_dentry, struct au_nhash *whlist);
36154 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36155 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36157 +/* ---------------------------------------------------------------------- */
36159 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36160 + aufs_bindex_t bindex)
36162 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36165 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36167 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36170 +#endif /* __KERNEL__ */
36171 +#endif /* __AUFS_WHOUT_H__ */
36172 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36173 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36174 +++ linux/fs/aufs/wkq.c 2022-03-21 14:49:05.733299677 +0100
36176 +// SPDX-License-Identifier: GPL-2.0
36178 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36180 + * This program, aufs is free software; you can redistribute it and/or modify
36181 + * it under the terms of the GNU General Public License as published by
36182 + * the Free Software Foundation; either version 2 of the License, or
36183 + * (at your option) any later version.
36185 + * This program is distributed in the hope that it will be useful,
36186 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36187 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36188 + * GNU General Public License for more details.
36190 + * You should have received a copy of the GNU General Public License
36191 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36195 + * workqueue for asynchronous/super-io operations
36196 + * todo: try new credential scheme
36199 +#include <linux/module.h>
36202 +/* internal workqueue named AUFS_WKQ_NAME */
36204 +static struct workqueue_struct *au_wkq;
36206 +struct au_wkinfo {
36207 + struct work_struct wk;
36208 + struct kobject *kobj;
36210 + unsigned int flags; /* see wkq.h */
36212 + au_wkq_func_t func;
36215 +#ifdef CONFIG_LOCKDEP
36217 + struct held_lock **hlock;
36220 + struct completion *comp;
36223 +/* ---------------------------------------------------------------------- */
36225 + * Aufs passes some operations to the workqueue such as the internal copyup.
36226 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36227 + * job run by workqueue depends upon the locks acquired in the other task.
36228 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36229 + * information too. And the job in the workqueue restores the info in order to
36230 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36231 + * correctly and expectedly.
36234 +#ifndef CONFIG_LOCKDEP
36235 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36236 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36237 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36238 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36239 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36241 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36243 + wkinfo->hlock = NULL;
36244 + wkinfo->dont_check = 0;
36251 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36253 + static DEFINE_SPINLOCK(spin);
36256 + struct lock_class_key *key;
36258 + { .name = "&sbinfo->si_rwsem" },
36259 + { .name = "&finfo->fi_rwsem" },
36260 + { .name = "&dinfo->di_rwsem" },
36261 + { .name = "&iinfo->ii_rwsem" }
36266 + /* lockless read from 'set.' see below */
36267 + if (set == ARRAY_SIZE(a)) {
36268 + for (i = 0; i < ARRAY_SIZE(a); i++)
36269 + if (a[i].key == key)
36274 + spin_lock(&spin);
36276 + for (i = 0; i < ARRAY_SIZE(a); i++)
36277 + if (a[i].key == key) {
36278 + spin_unlock(&spin);
36281 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36283 + if (unlikely(a[i].key == key)) { /* rare but possible */
36284 + spin_unlock(&spin);
36289 + if (strstr(a[i].name, name)) {
36291 + * the order of these three lines is important for the
36292 + * lockless read above.
36295 + spin_unlock(&spin);
36297 + /* AuDbg("%d, %s\n", set, name); */
36301 + spin_unlock(&spin);
36310 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36313 + struct task_struct *curr;
36314 + struct held_lock **hl, *held_locks, *p;
36318 + wkinfo->dont_check = lockdep_recursing(curr);
36319 + if (wkinfo->dont_check)
36321 + n = curr->lockdep_depth;
36326 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36327 + if (unlikely(!wkinfo->hlock))
36331 +#if 0 /* left for debugging */
36332 + if (0 && au_debug_test())
36333 + lockdep_print_held_locks(curr);
36335 + held_locks = curr->held_locks;
36336 + hl = wkinfo->hlock;
36338 + p = held_locks++;
36339 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36348 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36350 + au_kfree_try_rcu(wkinfo->hlock);
36353 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36355 + struct held_lock *p, **hl = wkinfo->hlock;
36358 + if (wkinfo->dont_check)
36362 + while ((p = *hl++)) { /* assignment */
36363 + subclass = lockdep_hlock_class(p)->subclass;
36364 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36366 + rwsem_acquire_read(p->instance, subclass, 0,
36367 + /*p->acquire_ip*/_RET_IP_);
36369 + rwsem_acquire(p->instance, subclass, 0,
36370 + /*p->acquire_ip*/_RET_IP_);
36374 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36376 + struct held_lock *p, **hl = wkinfo->hlock;
36378 + if (wkinfo->dont_check)
36382 + while ((p = *hl++)) /* assignment */
36383 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36387 +static void wkq_func(struct work_struct *wk)
36389 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36391 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36392 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36394 + au_wkq_lockdep_pre(wkinfo);
36395 + wkinfo->func(wkinfo->args);
36396 + au_wkq_lockdep_post(wkinfo);
36397 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36398 + complete(wkinfo->comp);
36400 + kobject_put(wkinfo->kobj);
36401 + module_put(THIS_MODULE); /* todo: ?? */
36402 + au_kfree_rcu(wkinfo);
36407 + * Since struct completion is large, try allocating it dynamically.
36409 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36411 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36413 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36415 + init_completion(*comp);
36416 + wkinfo->comp = *comp;
36422 +static void au_wkq_comp_free(struct completion *comp)
36424 + au_kfree_rcu(comp);
36427 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36429 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36430 + if (au_wkq_test()) {
36431 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36432 + " due to a dead dir by UDBA,"
36433 + " or async xino write?\n");
36434 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36437 + au_dbg_verify_kthread();
36439 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36440 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36441 + queue_work(au_wkq, &wkinfo->wk);
36443 + INIT_WORK(&wkinfo->wk, wkq_func);
36444 + schedule_work(&wkinfo->wk);
36449 + * Be careful. It is easy to make deadlock happen.
36450 + * processA: lock, wkq and wait
36451 + * processB: wkq and wait, lock in wkq
36454 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36457 + AuWkqCompDeclare(comp);
36458 + struct au_wkinfo wkinfo = {
36464 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36465 + if (unlikely(err))
36467 + err = au_wkq_lockdep_alloc(&wkinfo);
36468 + if (unlikely(err))
36471 + au_wkq_run(&wkinfo);
36472 + /* no timeout, no interrupt */
36473 + wait_for_completion(wkinfo.comp);
36475 + au_wkq_lockdep_free(&wkinfo);
36478 + au_wkq_comp_free(comp);
36480 + destroy_work_on_stack(&wkinfo.wk);
36485 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36486 + * problem in a concurrent umounting.
36488 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36489 + unsigned int flags)
36492 + struct au_wkinfo *wkinfo;
36494 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36497 + * wkq_func() must free this wkinfo.
36498 + * it highly depends upon the implementation of workqueue.
36501 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36503 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36504 + wkinfo->flags = flags & ~AuWkq_WAIT;
36505 + wkinfo->func = func;
36506 + wkinfo->args = args;
36507 + wkinfo->comp = NULL;
36508 + au_wkq_lockdep_init(wkinfo);
36509 + kobject_get(wkinfo->kobj);
36510 + __module_get(THIS_MODULE); /* todo: ?? */
36512 + au_wkq_run(wkinfo);
36515 + au_nwt_done(&au_sbi(sb)->si_nowait);
36521 +/* ---------------------------------------------------------------------- */
36523 +void au_nwt_init(struct au_nowait_tasks *nwt)
36525 + atomic_set(&nwt->nw_len, 0);
36526 + /* smp_mb(); */ /* atomic_set */
36527 + init_waitqueue_head(&nwt->nw_wq);
36530 +void au_wkq_fin(void)
36532 + destroy_workqueue(au_wkq);
36535 +int __init au_wkq_init(void)
36540 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36541 + if (IS_ERR(au_wkq))
36542 + err = PTR_ERR(au_wkq);
36543 + else if (!au_wkq)
36548 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36549 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36550 +++ linux/fs/aufs/wkq.h 2022-03-21 14:49:05.733299677 +0100
36552 +/* SPDX-License-Identifier: GPL-2.0 */
36554 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36556 + * This program, aufs is free software; you can redistribute it and/or modify
36557 + * it under the terms of the GNU General Public License as published by
36558 + * the Free Software Foundation; either version 2 of the License, or
36559 + * (at your option) any later version.
36561 + * This program is distributed in the hope that it will be useful,
36562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36564 + * GNU General Public License for more details.
36566 + * You should have received a copy of the GNU General Public License
36567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36571 + * workqueue for asynchronous/super-io operations
36572 + * todo: try new credentials management scheme
36575 +#ifndef __AUFS_WKQ_H__
36576 +#define __AUFS_WKQ_H__
36580 +#include <linux/wait.h>
36582 +struct super_block;
36584 +/* ---------------------------------------------------------------------- */
36587 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36589 +struct au_nowait_tasks {
36591 + wait_queue_head_t nw_wq;
36594 +/* ---------------------------------------------------------------------- */
36596 +typedef void (*au_wkq_func_t)(void *args);
36599 +#define AuWkq_WAIT 1
36600 +#define AuWkq_NEST (1 << 1)
36601 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36602 +#define au_fset_wkq(flags, name) \
36603 + do { (flags) |= AuWkq_##name; } while (0)
36604 +#define au_fclr_wkq(flags, name) \
36605 + do { (flags) &= ~AuWkq_##name; } while (0)
36608 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36609 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36610 + unsigned int flags);
36611 +void au_nwt_init(struct au_nowait_tasks *nwt);
36612 +int __init au_wkq_init(void);
36613 +void au_wkq_fin(void);
36615 +/* ---------------------------------------------------------------------- */
36617 +static inline int au_wkq_test(void)
36619 + return current->flags & PF_WQ_WORKER;
36622 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36624 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36627 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36629 + if (atomic_dec_and_test(&nwt->nw_len))
36630 + wake_up_all(&nwt->nw_wq);
36633 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36635 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36639 +#endif /* __KERNEL__ */
36640 +#endif /* __AUFS_WKQ_H__ */
36641 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36642 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36643 +++ linux/fs/aufs/xattr.c 2022-03-21 14:49:05.733299677 +0100
36645 +// SPDX-License-Identifier: GPL-2.0
36647 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36649 + * This program, aufs is free software; you can redistribute it and/or modify
36650 + * it under the terms of the GNU General Public License as published by
36651 + * the Free Software Foundation; either version 2 of the License, or
36652 + * (at your option) any later version.
36654 + * This program is distributed in the hope that it will be useful,
36655 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36656 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36657 + * GNU General Public License for more details.
36659 + * You should have received a copy of the GNU General Public License
36660 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36664 + * handling xattr functions
36667 +#include <linux/fs.h>
36668 +#include <linux/posix_acl_xattr.h>
36669 +#include <linux/xattr.h>
36672 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36674 + if (!ignore_flags)
36682 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36687 +#define cmp(brattr, prefix) do { \
36688 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36689 + XATTR_##prefix##_PREFIX_LEN)) { \
36690 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36696 + cmp(SEC, SECURITY);
36697 + cmp(SYS, SYSTEM);
36698 + cmp(TR, TRUSTED);
36702 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36709 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36711 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36712 + char *name, char **buf, unsigned int ignore_flags,
36713 + unsigned int verbose)
36717 + struct inode *h_idst;
36718 + struct dentry *h_dst_dentry, *h_src_dentry;
36719 + struct user_namespace *h_dst_userns, *h_src_userns;
36721 + h_src_userns = mnt_user_ns(h_src->mnt);
36722 + h_src_dentry = h_src->dentry;
36723 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36726 + if (unlikely(err <= 0)) {
36727 + if (err == -ENODATA
36728 + || (err == -EOPNOTSUPP
36729 + && ((ignore_flags & au_xattr_out_of_list)
36730 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36731 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36733 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36736 + if (err && (verbose || au_debug_test()))
36737 + pr_err("%s, err %d\n", name, err);
36741 + /* unlock it temporary */
36742 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36743 + h_dst_dentry = h_dst->dentry;
36744 + h_idst = d_inode(h_dst_dentry);
36745 + inode_unlock(h_idst);
36746 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36748 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36749 + if (unlikely(err)) {
36750 + if (verbose || au_debug_test())
36751 + pr_err("%s, err %d\n", name, err);
36752 + err = au_xattr_ignore(err, name, ignore_flags);
36759 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36760 + unsigned int verbose)
36762 + int err, unlocked, acl_access, acl_default;
36764 + struct dentry *h_dst_dentry, *h_src_dentry;
36765 + struct inode *h_isrc, *h_idst;
36766 + char *value, *p, *o, *e;
36768 + /* try stopping to update the source inode while we are referencing */
36769 + /* there should not be the parent-child relationship between them */
36770 + h_dst_dentry = h_dst->dentry;
36771 + h_idst = d_inode(h_dst_dentry);
36772 + h_src_dentry = h_src->dentry;
36773 + h_isrc = d_inode(h_src_dentry);
36774 + inode_unlock(h_idst);
36775 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36776 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36779 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36780 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36782 + if (unlikely(err < 0)) {
36784 + if (err == -ENODATA
36785 + || err == -EOPNOTSUPP)
36786 + err = 0; /* ignore */
36795 + p = kmalloc(ssz, GFP_NOFS);
36797 + if (unlikely(!p))
36799 + err = vfs_listxattr(h_src_dentry, p, ssz);
36801 + inode_unlock_shared(h_isrc);
36803 + AuDbg("err %d, ssz %zd\n", err, ssz);
36804 + if (unlikely(err < 0))
36812 + while (!err && p < e) {
36813 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36814 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36815 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36816 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36818 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36820 + p += strlen(p) + 1;
36823 + ignore_flags |= au_xattr_out_of_list;
36824 + if (!err && !acl_access) {
36825 + err = au_do_cpup_xattr(h_dst, h_src,
36826 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36827 + ignore_flags, verbose);
36830 + if (!err && !acl_default) {
36831 + err = au_do_cpup_xattr(h_dst, h_src,
36832 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36833 + ignore_flags, verbose);
36837 + au_kfree_try_rcu(value);
36840 + au_kfree_try_rcu(o);
36843 + inode_unlock_shared(h_isrc);
36848 +/* ---------------------------------------------------------------------- */
36850 +static int au_smack_reentering(struct super_block *sb)
36852 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36854 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36855 + * i_op->getxattr(). ouch.
36857 + return si_pid_test(sb);
36868 +struct au_lgxattr {
36876 + const char *name;
36883 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36884 + struct au_lgxattr *arg)
36888 + struct path h_path;
36889 + struct super_block *sb;
36891 + sb = dentry->d_sb;
36892 + reenter = au_smack_reentering(sb);
36894 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36895 + if (unlikely(err))
36898 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36899 + if (unlikely(err))
36901 + if (unlikely(!h_path.dentry))
36902 + /* illegally overlapped or something */
36903 + goto out_di; /* pretending success */
36905 + /* always topmost entry only */
36906 + switch (arg->type) {
36907 + case AU_XATTR_LIST:
36908 + err = vfs_listxattr(h_path.dentry,
36909 + arg->u.list.list, arg->u.list.size);
36911 + case AU_XATTR_GET:
36912 + AuDebugOn(d_is_negative(h_path.dentry));
36913 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36914 + arg->u.get.name, arg->u.get.value,
36915 + arg->u.get.size);
36921 + di_read_unlock(dentry, AuLock_IR);
36924 + si_read_unlock(sb);
36930 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36932 + struct au_lgxattr arg = {
36933 + .type = AU_XATTR_LIST,
36940 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36943 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36944 + const char *name, void *value, size_t size)
36946 + struct au_lgxattr arg = {
36947 + .type = AU_XATTR_GET,
36955 + return au_lgxattr(dentry, inode, &arg);
36958 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36959 + const char *name, const void *value, size_t size,
36962 + struct au_sxattr arg = {
36963 + .type = AU_XATTR_SET,
36972 + return au_sxattr(dentry, inode, &arg);
36975 +/* ---------------------------------------------------------------------- */
36977 +static int au_xattr_get(const struct xattr_handler *handler,
36978 + struct dentry *dentry, struct inode *inode,
36979 + const char *name, void *buffer, size_t size)
36981 + return au_getxattr(dentry, inode, name, buffer, size);
36984 +static int au_xattr_set(const struct xattr_handler *handler,
36985 + struct user_namespace *userns,
36986 + struct dentry *dentry, struct inode *inode,
36987 + const char *name, const void *value, size_t size,
36990 + return au_setxattr(dentry, inode, name, value, size, flags);
36993 +static const struct xattr_handler au_xattr_handler = {
36996 + .get = au_xattr_get,
36997 + .set = au_xattr_set
37000 +static const struct xattr_handler *au_xattr_handlers[] = {
37001 +#ifdef CONFIG_FS_POSIX_ACL
37002 + &posix_acl_access_xattr_handler,
37003 + &posix_acl_default_xattr_handler,
37005 + &au_xattr_handler, /* must be last */
37009 +void au_xattr_init(struct super_block *sb)
37011 + sb->s_xattr = au_xattr_handlers;
37013 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37014 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37015 +++ linux/fs/aufs/xino.c 2022-03-21 14:49:05.733299677 +0100
37017 +// SPDX-License-Identifier: GPL-2.0
37019 + * Copyright (C) 2005-2021 Junjiro R. Okajima
37021 + * This program, aufs is free software; you can redistribute it and/or modify
37022 + * it under the terms of the GNU General Public License as published by
37023 + * the Free Software Foundation; either version 2 of the License, or
37024 + * (at your option) any later version.
37026 + * This program is distributed in the hope that it will be useful,
37027 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37028 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37029 + * GNU General Public License for more details.
37031 + * You should have received a copy of the GNU General Public License
37032 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37036 + * external inode number translation table and bitmap
37038 + * things to consider
37040 + * + au_xino object
37041 + * + XINO files (xino, xib, xigen)
37042 + * + dynamic debugfs entries (xiN)
37043 + * + static debugfs entries (xib, xigen)
37044 + * + static sysfs entry (xi_path)
37045 + * - several entry points to handle them.
37046 + * + mount(2) without xino option (default)
37047 + * + mount(2) with xino option
37048 + * + mount(2) with noxino option
37050 + * + remount with add/del branches
37051 + * + remount with xino/noxino options
37054 +#include <linux/seq_file.h>
37055 +#include <linux/statfs.h>
37058 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37059 + aufs_bindex_t bbot,
37060 + struct super_block *h_sb)
37062 + /* todo: try binary-search if the branches are many */
37063 + for (; btop <= bbot; btop++)
37064 + if (h_sb == au_sbr_sb(sb, btop))
37070 + * find another branch who is on the same filesystem of the specified
37071 + * branch{@btgt}. search until @bbot.
37073 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37074 + aufs_bindex_t bbot)
37076 + aufs_bindex_t bindex;
37077 + struct super_block *tgt_sb;
37079 + tgt_sb = au_sbr_sb(sb, btgt);
37080 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37082 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37087 +/* ---------------------------------------------------------------------- */
37090 + * stop unnecessary notify events at creating xino files
37093 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37095 + aufs_bindex_t bfound, bindex, bbot;
37096 + struct dentry *parent;
37097 + struct au_branch *br;
37100 + parent = dentry->d_parent; /* safe d_parent access */
37101 + bbot = au_sbbot(sb);
37102 + for (bindex = 0; bindex <= bbot; bindex++) {
37103 + br = au_sbr(sb, bindex);
37104 + if (au_br_dentry(br) == parent) {
37110 + AuDbg("bfound b%d\n", bfound);
37114 +struct au_xino_lock_dir {
37115 + struct au_hinode *hdir;
37116 + struct dentry *parent;
37117 + struct inode *dir;
37120 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37121 + unsigned int lsc)
37123 + struct dentry *parent;
37124 + struct inode *dir;
37126 + parent = dget_parent(dentry);
37127 + dir = d_inode(parent);
37128 + inode_lock_nested(dir, lsc);
37129 +#if 0 /* it should not happen */
37130 + spin_lock(&dentry->d_lock);
37131 + if (unlikely(dentry->d_parent != parent)) {
37132 + spin_unlock(&dentry->d_lock);
37133 + inode_unlock(dir);
37138 + spin_unlock(&dentry->d_lock);
37145 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37146 + struct au_xino_lock_dir *ldir)
37148 + aufs_bindex_t bindex;
37150 + ldir->hdir = NULL;
37151 + bindex = au_xi_root(sb, xipath->dentry);
37152 + if (bindex >= 0) {
37153 + /* rw branch root */
37154 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37155 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37158 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37160 + ldir->dir = d_inode(ldir->parent);
37164 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37167 + au_hn_inode_unlock(ldir->hdir);
37169 + inode_unlock(ldir->dir);
37170 + dput(ldir->parent);
37174 +/* ---------------------------------------------------------------------- */
37177 + * create and set a new xino file
37179 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37182 + struct file *file;
37183 + struct dentry *h_parent, *d;
37184 + struct inode *h_dir, *inode;
37186 + static DEFINE_MUTEX(mtx);
37189 + * at mount-time, and the xino file is the default path,
37190 + * hnotify is disabled so we have no notify events to ignore.
37191 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37194 + mutex_lock(&mtx);
37195 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37196 + /* | __FMODE_NONOTIFY */,
37198 + if (IS_ERR(file)) {
37200 + mutex_unlock(&mtx);
37202 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37206 + /* keep file count */
37208 + d = file->f_path.dentry;
37209 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37211 + mutex_unlock(&mtx);
37212 + /* mnt_want_write() is unnecessary here */
37213 + h_dir = d_inode(h_parent);
37214 + inode = file_inode(file);
37215 + /* no delegation since it is just created */
37216 + if (inode->i_nlink)
37217 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37219 + inode_unlock(h_dir);
37221 + if (unlikely(err)) {
37223 + pr_err("unlink %s(%d)\n", fpath, err);
37228 + if (unlikely(sb && sb == d->d_sb)) {
37230 + pr_err("%s must be outside\n", fpath);
37233 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37235 + pr_err("xino doesn't support %s(%s)\n",
37236 + fpath, au_sbtype(d->d_sb));
37239 + return file; /* success */
37243 + file = ERR_PTR(err);
37248 + * create a new xinofile at the same place/path as @base.
37250 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37251 + struct file *copy_src)
37253 + struct file *file;
37254 + struct dentry *dentry;
37255 + struct inode *dir, *delegated;
37256 + struct qstr *name;
37257 + struct path ppath, path;
37258 + int err, do_unlock;
37259 + struct au_xino_lock_dir ldir;
37262 + au_xino_lock_dir(sb, base, &ldir);
37263 + dentry = base->dentry;
37264 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37265 + ppath.mnt = base->mnt;
37266 + dir = d_inode(ppath.dentry);
37269 + name = &dentry->d_name;
37270 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37271 + if (IS_ERR(path.dentry)) {
37272 + file = (void *)path.dentry;
37273 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37277 + /* no need to mnt_want_write() since we call dentry_open() later */
37278 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37279 + if (unlikely(err)) {
37280 + file = ERR_PTR(err);
37281 + pr_err("%pd create err %d\n", dentry, err);
37285 + path.mnt = base->mnt;
37286 + file = vfsub_dentry_open(&path,
37287 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37288 + /* | __FMODE_NONOTIFY */);
37289 + if (IS_ERR(file)) {
37290 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37294 + delegated = NULL;
37295 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37296 + au_xino_unlock_dir(&ldir);
37298 + if (unlikely(err == -EWOULDBLOCK)) {
37299 + pr_warn("cannot retry for NFSv4 delegation"
37300 + " for an internal unlink\n");
37303 + if (unlikely(err)) {
37304 + pr_err("%pd unlink err %d\n", dentry, err);
37309 + /* no one can touch copy_src xino */
37310 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37311 + if (unlikely(err)) {
37312 + pr_err("%pd copy err %d\n", dentry, err);
37316 + goto out_dput; /* success */
37320 + file = ERR_PTR(err);
37322 + dput(path.dentry);
37325 + au_xino_unlock_dir(&ldir);
37329 +struct file *au_xino_file1(struct au_xino *xi)
37331 + struct file *file;
37332 + unsigned int u, nfile;
37335 + nfile = xi->xi_nfile;
37336 + for (u = 0; u < nfile; u++) {
37337 + file = xi->xi_file[u];
37345 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37356 + if (idx < xi->xi_nfile) {
37357 + f = xi->xi_file[idx];
37361 + p = au_kzrealloc(xi->xi_file,
37362 + sizeof(*xi->xi_file) * xi->xi_nfile,
37363 + sizeof(*xi->xi_file) * (idx + 1),
37364 + GFP_NOFS, /*may_shrink*/0);
37366 + MtxMustLock(&xi->xi_mtx);
37368 + xi->xi_nfile = idx + 1;
37376 + xi->xi_file[idx] = file;
37383 + * if @xinew->xi is not set, then create new xigen file.
37385 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37387 + struct file *file;
37390 + SiMustAnyLock(sb);
37392 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37393 + if (IS_ERR(file)) {
37394 + err = PTR_ERR(file);
37395 + pr_err("%s[%d], err %d\n",
37396 + xinew->xi ? "xino" : "xigen",
37397 + xinew->idx, err);
37402 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37405 + /* todo: make xigen file an array */
37406 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37409 + if (unlikely(err))
37410 + file = ERR_PTR(err);
37416 +/* ---------------------------------------------------------------------- */
37419 + * truncate xino files
37421 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37422 + int idx, struct kstatfs *st)
37426 + struct file *file, *new_xino;
37427 + struct au_xi_new xinew = {
37432 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37433 + file = au_xino_file(xinew.xi, idx);
37437 + xinew.base = &file->f_path;
37438 + err = vfs_statfs(xinew.base, st);
37439 + if (unlikely(err)) {
37440 + AuErr1("statfs err %d, ignored\n", err);
37445 + blocks = file_inode(file)->i_blocks;
37446 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37447 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37449 + xinew.copy_src = file;
37450 + new_xino = au_xi_new(sb, &xinew);
37451 + if (IS_ERR(new_xino)) {
37452 + err = PTR_ERR(new_xino);
37453 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37457 + err = vfs_statfs(&new_xino->f_path, st);
37459 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37460 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37461 + st->f_bfree, st->f_blocks);
37463 + AuErr1("statfs err %d, ignored\n", err);
37471 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37474 + unsigned long jiffy;
37475 + aufs_bindex_t bbot;
37476 + struct kstatfs *st;
37477 + struct au_branch *br;
37478 + struct au_xino *xi;
37481 + st = kmalloc(sizeof(*st), GFP_NOFS);
37482 + if (unlikely(!st))
37486 + bbot = au_sbbot(sb);
37487 + if (unlikely(bindex < 0 || bbot < bindex))
37492 + br = au_sbr(sb, bindex);
37493 + xi = br->br_xino;
37494 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37495 + err = au_xino_do_trunc(sb, bindex, i, st);
37497 + au_sbi(sb)->si_xino_jiffy = jiffy;
37500 + au_kfree_rcu(st);
37505 +struct xino_do_trunc_args {
37506 + struct super_block *sb;
37507 + struct au_branch *br;
37511 +static void xino_do_trunc(void *_args)
37513 + struct xino_do_trunc_args *args = _args;
37514 + struct super_block *sb;
37515 + struct au_branch *br;
37516 + struct inode *dir;
37518 + aufs_bindex_t bindex;
37522 + dir = d_inode(sb->s_root);
37526 + si_noflush_write_lock(sb);
37527 + ii_read_lock_parent(dir);
37528 + bindex = au_br_index(sb, br->br_id);
37529 + err = au_xino_trunc(sb, bindex, idx);
37530 + ii_read_unlock(dir);
37531 + if (unlikely(err))
37532 + pr_warn("err b%d, (%d)\n", bindex, err);
37533 + atomic_dec(&br->br_xino->xi_truncating);
37534 + au_lcnt_dec(&br->br_count);
37535 + si_write_unlock(sb);
37536 + au_nwt_done(&au_sbi(sb)->si_nowait);
37537 + au_kfree_rcu(args);
37541 + * returns the index in the xi_file array whose corresponding file is necessary
37542 + * to truncate, or -1 which means no need to truncate.
37544 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37548 + struct kstatfs st;
37549 + struct au_sbinfo *sbinfo;
37550 + struct au_xino *xi;
37551 + struct file *file;
37553 + /* todo: si_xino_expire and the ratio should be customizable */
37554 + sbinfo = au_sbi(sb);
37555 + if (time_before(jiffies,
37556 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37559 + /* truncation border */
37560 + xi = br->br_xino;
37561 + for (u = 0; u < xi->xi_nfile; u++) {
37562 + file = au_xino_file(xi, u);
37566 + err = vfs_statfs(&file->f_path, &st);
37567 + if (unlikely(err)) {
37568 + AuErr1("statfs err %d, ignored\n", err);
37571 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37572 + >= AUFS_XINO_DEF_TRUNC)
37579 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37582 + struct xino_do_trunc_args *args;
37585 + idx = xino_trunc_test(sb, br);
37589 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37592 + /* lock and kfree() will be called in trunc_xino() */
37593 + args = kmalloc(sizeof(*args), GFP_NOFS);
37594 + if (unlikely(!args)) {
37595 + AuErr1("no memory\n");
37599 + au_lcnt_inc(&br->br_count);
37603 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37605 + return; /* success */
37607 + pr_err("wkq %d\n", wkq_err);
37608 + au_lcnt_dec(&br->br_count);
37609 + au_kfree_rcu(args);
37612 + atomic_dec(&br->br_xino->xi_truncating);
37615 +/* ---------------------------------------------------------------------- */
37617 +struct au_xi_calc {
37622 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37623 + struct au_xi_calc *calc)
37627 + maxent = au_xi_maxent(sb);
37628 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37629 + calc->pos *= sizeof(ino_t);
37632 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37633 + struct au_xi_calc *calc)
37636 + struct file *file;
37637 + struct au_xino *xi = br->br_xino;
37638 + struct au_xi_new xinew = {
37642 + SiMustAnyLock(sb);
37648 + mutex_lock(&xi->xi_mtx);
37649 + file = au_xino_file(xi, calc->idx);
37653 + file = au_xino_file(xi, /*idx*/-1);
37654 + AuDebugOn(!file);
37655 + xinew.idx = calc->idx;
37656 + xinew.base = &file->f_path;
37657 + /* xinew.copy_src = NULL; */
37658 + file = au_xi_new(sb, &xinew);
37659 + if (IS_ERR(file))
37660 + err = PTR_ERR(file);
37663 + mutex_unlock(&xi->xi_mtx);
37668 +struct au_xino_do_new_async_args {
37669 + struct super_block *sb;
37670 + struct au_branch *br;
37671 + struct au_xi_calc calc;
37675 +struct au_xi_writing {
37676 + struct hlist_bl_node node;
37677 + ino_t h_ino, ino;
37680 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37683 +static void au_xino_call_do_new_async(void *args)
37685 + struct au_xino_do_new_async_args *a = args;
37686 + struct au_branch *br;
37687 + struct super_block *sb;
37688 + struct au_sbinfo *sbi;
37689 + struct inode *root;
37690 + struct file *file;
37691 + struct au_xi_writing *del, *p;
37692 + struct hlist_bl_head *hbl;
37693 + struct hlist_bl_node *pos;
37698 + sbi = au_sbi(sb);
37699 + si_noflush_read_lock(sb);
37700 + root = d_inode(sb->s_root);
37701 + ii_read_lock_child(root);
37702 + err = au_xino_do_new_async(sb, br, &a->calc);
37703 + if (unlikely(err)) {
37704 + AuIOErr("err %d\n", err);
37708 + file = au_xino_file(br->br_xino, a->calc.idx);
37709 + AuDebugOn(!file);
37710 + err = au_xino_do_write(file, &a->calc, a->ino);
37711 + if (unlikely(err)) {
37712 + AuIOErr("err %d\n", err);
37717 + hbl = &br->br_xino->xi_writing;
37718 + hlist_bl_lock(hbl);
37719 + au_hbl_for_each(pos, hbl) {
37720 + p = container_of(pos, struct au_xi_writing, node);
37721 + if (p->ino == a->ino) {
37723 + hlist_bl_del(&p->node);
37727 + hlist_bl_unlock(hbl);
37728 + au_kfree_rcu(del);
37731 + au_lcnt_dec(&br->br_count);
37732 + ii_read_unlock(root);
37733 + si_read_unlock(sb);
37734 + au_nwt_done(&sbi->si_nowait);
37739 + * create a new xino file asynchronously
37741 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37742 + struct au_xi_calc *calc, ino_t ino)
37745 + struct au_xino_do_new_async_args *arg;
37748 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37749 + if (unlikely(!arg))
37754 + arg->calc = *calc;
37756 + au_lcnt_inc(&br->br_count);
37757 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37758 + if (unlikely(err)) {
37759 + pr_err("wkq %d\n", err);
37760 + au_lcnt_dec(&br->br_count);
37761 + au_kfree_rcu(arg);
37769 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37770 + * at the position of @h_ino.
37772 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37777 + struct au_xi_calc calc;
37778 + struct au_sbinfo *sbinfo;
37779 + struct file *file;
37780 + struct au_xino *xi;
37781 + struct hlist_bl_head *hbl;
37782 + struct hlist_bl_node *pos;
37783 + struct au_xi_writing *p;
37786 + if (!au_opt_test(au_mntflags(sb), XINO))
37787 + return 0; /* no xino */
37790 + au_xi_calc(sb, h_ino, &calc);
37791 + xi = au_sbr(sb, bindex)->br_xino;
37792 + file = au_xino_file(xi, calc.idx);
37794 + hbl = &xi->xi_writing;
37795 + hlist_bl_lock(hbl);
37796 + au_hbl_for_each(pos, hbl) {
37797 + p = container_of(pos, struct au_xi_writing, node);
37798 + if (p->h_ino == h_ino) {
37799 + AuDbg("hi%llu, i%llu, found\n",
37800 + (u64)p->h_ino, (u64)p->ino);
37805 + hlist_bl_unlock(hbl);
37807 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37808 + return 0; /* no xino */
37810 + sbinfo = au_sbi(sb);
37811 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37812 + if (sz == sizeof(*ino))
37813 + return 0; /* success */
37816 + if (unlikely(sz >= 0)) {
37818 + AuIOErr("xino read error (%zd)\n", sz);
37823 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37828 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37829 + if (sz == sizeof(ino))
37830 + return 0; /* success */
37832 + AuIOErr("write failed (%zd)\n", sz);
37837 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37838 + * at the position of @h_ino.
37839 + * even if @ino is zero, it is written to the xinofile and means no entry.
37840 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37841 + * try truncating it.
37843 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37847 + unsigned int mnt_flags;
37848 + struct au_xi_calc calc;
37849 + struct file *file;
37850 + struct au_branch *br;
37851 + struct au_xino *xi;
37852 + struct au_xi_writing *p;
37854 + SiMustAnyLock(sb);
37856 + mnt_flags = au_mntflags(sb);
37857 + if (!au_opt_test(mnt_flags, XINO))
37860 + au_xi_calc(sb, h_ino, &calc);
37861 + br = au_sbr(sb, bindex);
37862 + xi = br->br_xino;
37863 + file = au_xino_file(xi, calc.idx);
37865 + /* store the inum pair into the list */
37866 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37867 + p->h_ino = h_ino;
37869 + au_hbl_add(&p->node, &xi->xi_writing);
37871 + /* create and write a new xino file asynchronously */
37872 + err = au_xino_new_async(sb, br, &calc, ino);
37874 + return 0; /* success */
37878 + err = au_xino_do_write(file, &calc, ino);
37880 + br = au_sbr(sb, bindex);
37881 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37882 + && au_test_fs_trunc_xino(au_br_sb(br)))
37883 + xino_try_trunc(sb, br);
37884 + return 0; /* success */
37888 + AuIOErr("write failed (%d)\n", err);
37892 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37895 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37896 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37900 + const int prevent_endless = 10;
37904 + err = vfsub_read_k(file, kbuf, size, pos);
37905 + if (err == -EINTR
37906 + && !au_wkq_test()
37907 + && fatal_signal_pending(current)) {
37908 + err = xino_fread_wkq(file, kbuf, size, pos);
37909 + BUG_ON(err == -EINTR);
37911 + } while (i++ < prevent_endless
37912 + && (err == -EAGAIN || err == -EINTR));
37914 +#if 0 /* reserved for future use */
37916 + fsnotify_access(file->f_path.dentry);
37922 +struct xino_fread_args {
37924 + struct file *file;
37930 +static void call_xino_fread(void *args)
37932 + struct xino_fread_args *a = args;
37933 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37936 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37941 + struct xino_fread_args args = {
37949 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37950 + if (unlikely(wkq_err))
37956 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37959 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37964 + const int prevent_endless = 10;
37968 + err = vfsub_write_k(file, kbuf, size, pos);
37969 + if (err == -EINTR
37970 + && !au_wkq_test()
37971 + && fatal_signal_pending(current)) {
37972 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37973 + BUG_ON(err == -EINTR);
37975 + } while (i++ < prevent_endless
37976 + && (err == -EAGAIN || err == -EINTR));
37978 +#if 0 /* reserved for future use */
37980 + fsnotify_modify(file->f_path.dentry);
37986 +struct do_xino_fwrite_args {
37988 + struct file *file;
37994 +static void call_do_xino_fwrite(void *args)
37996 + struct do_xino_fwrite_args *a = args;
37997 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38000 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38005 + struct do_xino_fwrite_args args = {
38014 + * it breaks RLIMIT_FSIZE and normal user's limit,
38015 + * users should care about quota and real 'filesystem full.'
38017 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38018 + if (unlikely(wkq_err))
38024 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38028 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38030 + err = do_xino_fwrite(file, buf, size, pos);
38034 + err = xino_fwrite_wkq(file, buf, size, pos);
38041 +/* ---------------------------------------------------------------------- */
38044 + * inode number bitmap
38046 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38047 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38051 + AuDebugOn(bit < 0 || page_bits <= bit);
38052 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38056 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38058 + AuDebugOn(ino < AUFS_FIRST_INO);
38059 + ino -= AUFS_FIRST_INO;
38060 + *pindex = ino / page_bits;
38061 + *bit = ino % page_bits;
38064 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38069 + struct au_sbinfo *sbinfo;
38070 + struct file *xib;
38071 + unsigned long *p;
38073 + sbinfo = au_sbi(sb);
38074 + MtxMustLock(&sbinfo->si_xib_mtx);
38075 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38076 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38078 + if (pindex == sbinfo->si_xib_last_pindex)
38081 + xib = sbinfo->si_xib;
38082 + p = sbinfo->si_xib_buf;
38083 + pos = sbinfo->si_xib_last_pindex;
38084 + pos *= PAGE_SIZE;
38085 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38086 + if (unlikely(sz != PAGE_SIZE))
38090 + pos *= PAGE_SIZE;
38091 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38092 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38094 + memset(p, 0, PAGE_SIZE);
38095 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38097 + if (sz == PAGE_SIZE) {
38098 + sbinfo->si_xib_last_pindex = pindex;
38099 + return 0; /* success */
38103 + AuIOErr1("write failed (%zd)\n", sz);
38110 +static void au_xib_clear_bit(struct inode *inode)
38113 + unsigned long pindex;
38114 + struct super_block *sb;
38115 + struct au_sbinfo *sbinfo;
38117 + AuDebugOn(inode->i_nlink);
38119 + sb = inode->i_sb;
38120 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38121 + AuDebugOn(page_bits <= bit);
38122 + sbinfo = au_sbi(sb);
38123 + mutex_lock(&sbinfo->si_xib_mtx);
38124 + err = xib_pindex(sb, pindex);
38126 + clear_bit(bit, sbinfo->si_xib_buf);
38127 + sbinfo->si_xib_next_bit = bit;
38129 + mutex_unlock(&sbinfo->si_xib_mtx);
38132 +/* ---------------------------------------------------------------------- */
38135 + * truncate a xino bitmap file
38139 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38143 + unsigned long pindex;
38144 + loff_t pos, pend;
38145 + struct au_sbinfo *sbinfo;
38147 + unsigned long *p;
38150 + sbinfo = au_sbi(sb);
38151 + MtxMustLock(&sbinfo->si_xib_mtx);
38152 + p = sbinfo->si_xib_buf;
38153 + pend = vfsub_f_size_read(file);
38155 + while (pos < pend) {
38156 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38158 + if (unlikely(sz <= 0))
38162 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38163 + if (unlikely(*ino < AUFS_FIRST_INO))
38166 + xib_calc_bit(*ino, &pindex, &bit);
38167 + AuDebugOn(page_bits <= bit);
38168 + err = xib_pindex(sb, pindex);
38180 +static int xib_restore(struct super_block *sb)
38183 + unsigned int nfile;
38184 + aufs_bindex_t bindex, bbot;
38186 + struct au_branch *br;
38187 + struct au_xino *xi;
38188 + struct file *file;
38191 + page = (void *)__get_free_page(GFP_NOFS);
38192 + if (unlikely(!page))
38196 + bbot = au_sbbot(sb);
38197 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38198 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38199 + br = au_sbr(sb, bindex);
38200 + xi = br->br_xino;
38201 + nfile = xi->xi_nfile;
38202 + for (i = 0; i < nfile; i++) {
38203 + file = au_xino_file(xi, i);
38205 + err = do_xib_restore(sb, file, page);
38208 + AuDbg("skip shared b%d\n", bindex);
38209 + free_page((unsigned long)page);
38215 +int au_xib_trunc(struct super_block *sb)
38220 + struct au_sbinfo *sbinfo;
38221 + unsigned long *p;
38222 + struct file *file;
38224 + SiMustWriteLock(sb);
38227 + sbinfo = au_sbi(sb);
38228 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38231 + file = sbinfo->si_xib;
38232 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38235 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38236 + err = PTR_ERR(file);
38237 + if (IS_ERR(file))
38239 + fput(sbinfo->si_xib);
38240 + sbinfo->si_xib = file;
38242 + p = sbinfo->si_xib_buf;
38243 + memset(p, 0, PAGE_SIZE);
38245 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38246 + if (unlikely(sz != PAGE_SIZE)) {
38248 + AuIOErr("err %d\n", err);
38254 + mutex_lock(&sbinfo->si_xib_mtx);
38255 + /* mnt_want_write() is unnecessary here */
38256 + err = xib_restore(sb);
38257 + mutex_unlock(&sbinfo->si_xib_mtx);
38263 +/* ---------------------------------------------------------------------- */
38265 +struct au_xino *au_xino_alloc(unsigned int nfile)
38267 + struct au_xino *xi;
38269 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38270 + if (unlikely(!xi))
38272 + xi->xi_nfile = nfile;
38273 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38274 + if (unlikely(!xi->xi_file))
38277 + xi->xi_nondir.total = 8; /* initial size */
38278 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38280 + if (unlikely(!xi->xi_nondir.array))
38283 + spin_lock_init(&xi->xi_nondir.spin);
38284 + init_waitqueue_head(&xi->xi_nondir.wqh);
38285 + mutex_init(&xi->xi_mtx);
38286 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38287 + atomic_set(&xi->xi_truncating, 0);
38288 + kref_init(&xi->xi_kref);
38289 + goto out; /* success */
38292 + au_kfree_try_rcu(xi->xi_file);
38294 + au_kfree_rcu(xi);
38300 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38303 + struct au_xino *xi;
38306 + xi = au_xino_alloc(idx + 1);
38307 + if (unlikely(!xi)) {
38314 + xi->xi_file[idx] = file;
38315 + AuDebugOn(br->br_xino);
38316 + br->br_xino = xi;
38322 +static void au_xino_release(struct kref *kref)
38324 + struct au_xino *xi;
38326 + unsigned long ul;
38327 + struct hlist_bl_head *hbl;
38328 + struct hlist_bl_node *pos, *n;
38329 + struct au_xi_writing *p;
38331 + xi = container_of(kref, struct au_xino, xi_kref);
38332 + for (i = 0; i < xi->xi_nfile; i++)
38333 + if (xi->xi_file[i])
38334 + fput(xi->xi_file[i]);
38335 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38336 + AuDebugOn(xi->xi_nondir.array[i]);
38337 + mutex_destroy(&xi->xi_mtx);
38338 + hbl = &xi->xi_writing;
38339 + ul = au_hbl_count(hbl);
38340 + if (unlikely(ul)) {
38341 + pr_warn("xi_writing %lu\n", ul);
38342 + hlist_bl_lock(hbl);
38343 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38344 + hlist_bl_del(&p->node);
38345 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38348 + hlist_bl_unlock(hbl);
38350 + au_kfree_try_rcu(xi->xi_file);
38351 + au_kfree_try_rcu(xi->xi_nondir.array);
38352 + au_kfree_rcu(xi);
38355 +int au_xino_put(struct au_branch *br)
38358 + struct au_xino *xi;
38361 + xi = br->br_xino;
38363 + br->br_xino = NULL;
38364 + ret = kref_put(&xi->xi_kref, au_xino_release);
38370 +/* ---------------------------------------------------------------------- */
38373 + * xino mount option handlers
38377 +static void xino_clear_xib(struct super_block *sb)
38379 + struct au_sbinfo *sbinfo;
38381 + SiMustWriteLock(sb);
38383 + sbinfo = au_sbi(sb);
38384 + if (sbinfo->si_xib)
38385 + fput(sbinfo->si_xib);
38386 + sbinfo->si_xib = NULL;
38387 + if (sbinfo->si_xib_buf)
38388 + free_page((unsigned long)sbinfo->si_xib_buf);
38389 + sbinfo->si_xib_buf = NULL;
38392 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38396 + struct au_sbinfo *sbinfo;
38397 + struct file *file;
38398 + struct super_block *xi_sb;
38400 + SiMustWriteLock(sb);
38402 + sbinfo = au_sbi(sb);
38403 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38404 + err = PTR_ERR(file);
38405 + if (IS_ERR(file))
38407 + if (sbinfo->si_xib)
38408 + fput(sbinfo->si_xib);
38409 + sbinfo->si_xib = file;
38410 + xi_sb = file_inode(file)->i_sb;
38411 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38412 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38414 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38415 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38418 + sbinfo->si_ximaxent /= sizeof(ino_t);
38421 + if (!sbinfo->si_xib_buf)
38422 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38423 + if (unlikely(!sbinfo->si_xib_buf))
38426 + sbinfo->si_xib_last_pindex = 0;
38427 + sbinfo->si_xib_next_bit = 0;
38428 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38430 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38431 + if (unlikely(err != PAGE_SIZE))
38435 + goto out; /* success */
38438 + if (sbinfo->si_xib_buf)
38439 + free_page((unsigned long)sbinfo->si_xib_buf);
38440 + sbinfo->si_xib_buf = NULL;
38444 + fput(sbinfo->si_xib);
38445 + sbinfo->si_xib = NULL;
38451 +/* xino for each branch */
38452 +static void xino_clear_br(struct super_block *sb)
38454 + aufs_bindex_t bindex, bbot;
38455 + struct au_branch *br;
38457 + bbot = au_sbbot(sb);
38458 + for (bindex = 0; bindex <= bbot; bindex++) {
38459 + br = au_sbr(sb, bindex);
38465 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38466 + aufs_bindex_t bshared)
38468 + struct au_branch *brshared;
38470 + brshared = au_sbr(sb, bshared);
38471 + AuDebugOn(!brshared->br_xino);
38472 + AuDebugOn(!brshared->br_xino->xi_file);
38473 + if (br->br_xino != brshared->br_xino) {
38474 + au_xino_get(brshared);
38476 + br->br_xino = brshared->br_xino;
38480 +struct au_xino_do_set_br {
38481 + struct au_branch *br;
38483 + aufs_bindex_t bshared;
38486 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38487 + struct au_xino_do_set_br *args)
38490 + struct au_xi_calc calc;
38491 + struct file *file;
38492 + struct au_branch *br;
38493 + struct au_xi_new xinew = {
38498 + xinew.xi = br->br_xino;
38499 + au_xi_calc(sb, args->h_ino, &calc);
38500 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38501 + if (args->bshared >= 0)
38502 + /* shared xino */
38503 + au_xino_set_br_shared(sb, br, args->bshared);
38504 + else if (!xinew.xi) {
38506 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38507 + if (unlikely(err))
38511 + /* force re-creating */
38512 + xinew.xi = br->br_xino;
38513 + xinew.idx = calc.idx;
38514 + mutex_lock(&xinew.xi->xi_mtx);
38515 + file = au_xi_new(sb, &xinew);
38516 + mutex_unlock(&xinew.xi->xi_mtx);
38517 + err = PTR_ERR(file);
38518 + if (IS_ERR(file))
38520 + AuDebugOn(!file);
38522 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38523 + if (unlikely(err))
38531 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38534 + aufs_bindex_t bindex, bbot;
38535 + struct au_xino_do_set_br args;
38536 + struct inode *inode;
38538 + SiMustWriteLock(sb);
38540 + bbot = au_sbbot(sb);
38541 + inode = d_inode(sb->s_root);
38542 + for (bindex = 0; bindex <= bbot; bindex++) {
38543 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38544 + args.br = au_sbr(sb, bindex);
38545 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38546 + err = au_xino_do_set_br(sb, path, &args);
38547 + if (unlikely(err))
38555 +void au_xino_clr(struct super_block *sb)
38557 + struct au_sbinfo *sbinfo;
38559 + au_xigen_clr(sb);
38560 + xino_clear_xib(sb);
38561 + xino_clear_br(sb);
38562 + dbgaufs_brs_del(sb, 0);
38563 + sbinfo = au_sbi(sb);
38564 + /* lvalue, do not call au_mntflags() */
38565 + au_opt_clr(sbinfo->si_mntflags, XINO);
38568 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38571 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38572 + struct qstr *dname, *cur_name;
38573 + struct file *cur_xino;
38574 + struct au_sbinfo *sbinfo;
38575 + struct path *path, *cur_path;
38577 + SiMustWriteLock(sb);
38580 + sbinfo = au_sbi(sb);
38581 + path = &xiopt->file->f_path;
38582 + dentry = path->dentry;
38583 + parent = dget_parent(dentry);
38586 + cur_xino = sbinfo->si_xib;
38588 + cur_path = &cur_xino->f_path;
38589 + cur_dentry = cur_path->dentry;
38590 + cur_parent = dget_parent(cur_dentry);
38591 + cur_name = &cur_dentry->d_name;
38592 + dname = &dentry->d_name;
38593 + skip = (cur_parent == parent
38594 + && au_qstreq(dname, cur_name));
38595 + dput(cur_parent);
38601 + au_opt_set(sbinfo->si_mntflags, XINO);
38602 + err = au_xino_set_xib(sb, path);
38603 + /* si_x{read,write} are set */
38605 + err = au_xigen_set(sb, path);
38607 + err = au_xino_set_br(sb, path);
38609 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38610 + goto out; /* success */
38614 + AuIOErr("failed setting xino(%d).\n", err);
38623 + * create a xinofile at the default place/path.
38625 +struct file *au_xino_def(struct super_block *sb)
38627 + struct file *file;
38629 + struct au_branch *br;
38630 + struct super_block *h_sb;
38631 + struct path path;
38632 + aufs_bindex_t bbot, bindex, bwr;
38635 + bbot = au_sbbot(sb);
38637 + for (bindex = 0; bindex <= bbot; bindex++) {
38638 + br = au_sbr(sb, bindex);
38639 + if (au_br_writable(br->br_perm)
38640 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38647 + file = ERR_PTR(-ENOMEM);
38648 + page = (void *)__get_free_page(GFP_NOFS);
38649 + if (unlikely(!page))
38651 + path.mnt = au_br_mnt(br);
38652 + path.dentry = au_h_dptr(sb->s_root, bwr);
38653 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38654 + file = (void *)p;
38655 + if (!IS_ERR(p)) {
38656 + strcat(p, "/" AUFS_XINO_FNAME);
38657 + AuDbg("%s\n", p);
38658 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38660 + free_page((unsigned long)page);
38662 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38664 + if (IS_ERR(file))
38666 + h_sb = file->f_path.dentry->d_sb;
38667 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38668 + pr_err("xino doesn't support %s(%s)\n",
38669 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38671 + file = ERR_PTR(-EINVAL);
38679 +/* ---------------------------------------------------------------------- */
38682 + * initialize the xinofile for the specified branch @br
38683 + * at the place/path where @base_file indicates.
38684 + * test whether another branch is on the same filesystem or not,
38685 + * if found then share the xinofile with another branch.
38687 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38688 + struct path *base)
38691 + struct au_xino_do_set_br args = {
38696 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38698 + err = au_xino_do_set_br(sb, base, &args);
38699 + if (unlikely(err))
38705 +/* ---------------------------------------------------------------------- */
38708 + * get an unused inode number from bitmap
38710 +ino_t au_xino_new_ino(struct super_block *sb)
38713 + unsigned long *p, pindex, ul, pend;
38714 + struct au_sbinfo *sbinfo;
38715 + struct file *file;
38716 + int free_bit, err;
38718 + if (!au_opt_test(au_mntflags(sb), XINO))
38719 + return iunique(sb, AUFS_FIRST_INO);
38721 + sbinfo = au_sbi(sb);
38722 + mutex_lock(&sbinfo->si_xib_mtx);
38723 + p = sbinfo->si_xib_buf;
38724 + free_bit = sbinfo->si_xib_next_bit;
38725 + if (free_bit < page_bits && !test_bit(free_bit, p))
38726 + goto out; /* success */
38727 + free_bit = find_first_zero_bit(p, page_bits);
38728 + if (free_bit < page_bits)
38729 + goto out; /* success */
38731 + pindex = sbinfo->si_xib_last_pindex;
38732 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38733 + err = xib_pindex(sb, ul);
38734 + if (unlikely(err))
38736 + free_bit = find_first_zero_bit(p, page_bits);
38737 + if (free_bit < page_bits)
38738 + goto out; /* success */
38741 + file = sbinfo->si_xib;
38742 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38743 + for (ul = pindex + 1; ul <= pend; ul++) {
38744 + err = xib_pindex(sb, ul);
38745 + if (unlikely(err))
38747 + free_bit = find_first_zero_bit(p, page_bits);
38748 + if (free_bit < page_bits)
38749 + goto out; /* success */
38754 + set_bit(free_bit, p);
38755 + sbinfo->si_xib_next_bit = free_bit + 1;
38756 + pindex = sbinfo->si_xib_last_pindex;
38757 + mutex_unlock(&sbinfo->si_xib_mtx);
38758 + ino = xib_calc_ino(pindex, free_bit);
38759 + AuDbg("i%lu\n", (unsigned long)ino);
38762 + mutex_unlock(&sbinfo->si_xib_mtx);
38767 +/* for s_op->delete_inode() */
38768 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38771 + unsigned int mnt_flags;
38772 + aufs_bindex_t bindex, bbot, bi;
38773 + unsigned char try_trunc;
38774 + struct au_iinfo *iinfo;
38775 + struct super_block *sb;
38776 + struct au_hinode *hi;
38777 + struct inode *h_inode;
38778 + struct au_branch *br;
38779 + struct au_xi_calc calc;
38780 + struct file *file;
38782 + AuDebugOn(au_is_bad_inode(inode));
38784 + sb = inode->i_sb;
38785 + mnt_flags = au_mntflags(sb);
38786 + if (!au_opt_test(mnt_flags, XINO)
38787 + || inode->i_ino == AUFS_ROOT_INO)
38791 + au_xigen_inc(inode);
38792 + au_xib_clear_bit(inode);
38795 + iinfo = au_ii(inode);
38796 + bindex = iinfo->ii_btop;
38800 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38801 + hi = au_hinode(iinfo, bindex);
38802 + bbot = iinfo->ii_bbot;
38803 + for (; bindex <= bbot; bindex++, hi++) {
38804 + h_inode = hi->hi_inode;
38806 + || (!unlinked && h_inode->i_nlink))
38809 + /* inode may not be revalidated */
38810 + bi = au_br_index(sb, hi->hi_id);
38814 + br = au_sbr(sb, bi);
38815 + au_xi_calc(sb, h_inode->i_ino, &calc);
38816 + file = au_xino_file(br->br_xino, calc.idx);
38817 + if (IS_ERR_OR_NULL(file))
38820 + err = au_xino_do_write(file, &calc, /*ino*/0);
38821 + if (!err && try_trunc
38822 + && au_test_fs_trunc_xino(au_br_sb(br)))
38823 + xino_try_trunc(sb, br);
38827 +/* ---------------------------------------------------------------------- */
38829 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38831 + int found, total, i;
38834 + total = xi->xi_nondir.total;
38835 + for (i = 0; i < total; i++) {
38836 + if (xi->xi_nondir.array[i] != h_ino)
38845 +static int au_xinondir_expand(struct au_xino *xi)
38850 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38853 + sz = xi->xi_nondir.total * sizeof(ino_t);
38854 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38856 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38857 + /*may_shrink*/0);
38859 + xi->xi_nondir.array = p;
38860 + xi->xi_nondir.total <<= 1;
38861 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38869 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38870 + ino_t h_ino, int idx)
38872 + struct au_xino *xi;
38874 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38875 + xi = au_sbr(sb, bindex)->br_xino;
38876 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38878 + spin_lock(&xi->xi_nondir.spin);
38879 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38880 + xi->xi_nondir.array[idx] = 0;
38881 + spin_unlock(&xi->xi_nondir.spin);
38882 + wake_up_all(&xi->xi_nondir.wqh);
38885 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38888 + int err, found, empty;
38889 + struct au_xino *xi;
38893 + if (!au_opt_test(au_mntflags(sb), XINO))
38894 + goto out; /* no xino */
38896 + xi = au_sbr(sb, bindex)->br_xino;
38899 + spin_lock(&xi->xi_nondir.spin);
38900 + found = au_xinondir_find(xi, h_ino);
38901 + if (found == -1) {
38902 + empty = au_xinondir_find(xi, /*h_ino*/0);
38903 + if (empty == -1) {
38904 + empty = xi->xi_nondir.total;
38905 + err = au_xinondir_expand(xi);
38906 + if (unlikely(err))
38909 + xi->xi_nondir.array[empty] = h_ino;
38912 + spin_unlock(&xi->xi_nondir.spin);
38913 + wait_event(xi->xi_nondir.wqh,
38914 + xi->xi_nondir.array[found] != h_ino);
38919 + spin_unlock(&xi->xi_nondir.spin);
38924 +/* ---------------------------------------------------------------------- */
38926 +int au_xino_path(struct seq_file *seq, struct file *file)
38930 + err = au_seq_path(seq, &file->f_path);
38931 + if (unlikely(err))
38934 +#define Deleted "\\040(deleted)"
38935 + seq->count -= sizeof(Deleted) - 1;
38936 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38937 + sizeof(Deleted) - 1));
38943 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38944 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38945 +++ linux/include/uapi/linux/aufs_type.h 2022-03-21 14:49:05.733299677 +0100
38947 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38949 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38951 + * This program, aufs is free software; you can redistribute it and/or modify
38952 + * it under the terms of the GNU General Public License as published by
38953 + * the Free Software Foundation; either version 2 of the License, or
38954 + * (at your option) any later version.
38956 + * This program is distributed in the hope that it will be useful,
38957 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38958 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38959 + * GNU General Public License for more details.
38961 + * You should have received a copy of the GNU General Public License
38962 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38965 +#ifndef __AUFS_TYPE_H__
38966 +#define __AUFS_TYPE_H__
38968 +#define AUFS_NAME "aufs"
38972 + * define it before including all other headers.
38973 + * sched.h may use pr_* macros before defining "current", so define the
38974 + * no-current version first, and re-define later.
38976 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38977 +#include <linux/sched.h>
38979 +#define pr_fmt(fmt) \
38980 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38981 + (int)sizeof(current->comm), current->comm, current->pid
38982 +#include <linux/limits.h>
38984 +#include <stdint.h>
38985 +#include <sys/types.h>
38986 +#include <limits.h>
38987 +#endif /* __KERNEL__ */
38989 +#define AUFS_VERSION "5.x-rcN-20220314"
38991 +/* todo? move this to linux-2.6.19/include/magic.h */
38992 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38994 +/* ---------------------------------------------------------------------- */
38997 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38998 +typedef int8_t aufs_bindex_t;
38999 +#define AUFS_BRANCH_MAX 127
39001 +typedef int16_t aufs_bindex_t;
39002 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39003 +#define AUFS_BRANCH_MAX 511
39004 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39005 +#define AUFS_BRANCH_MAX 1023
39006 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39007 +#define AUFS_BRANCH_MAX 32767
39011 +#ifndef AUFS_BRANCH_MAX
39012 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39014 +#endif /* __KERNEL__ */
39016 +/* ---------------------------------------------------------------------- */
39018 +#define AUFS_FSTYPE AUFS_NAME
39020 +#define AUFS_ROOT_INO 2
39021 +#define AUFS_FIRST_INO 11
39023 +#define AUFS_WH_PFX ".wh."
39024 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39025 +#define AUFS_WH_TMP_LEN 4
39026 +/* a limit for rmdir/rename a dir and copyup */
39027 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39028 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39030 + - AUFS_WH_TMP_LEN) /* hex */
39031 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39032 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39033 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39034 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39035 +#define AUFS_DIRWH_DEF 3
39036 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39037 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39038 +#define AUFS_RDBLK_DEF 512 /* bytes */
39039 +#define AUFS_RDHASH_DEF 32
39040 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39041 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39042 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39043 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39044 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39046 +/* pseudo-link maintenace under /proc */
39047 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39048 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39049 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39051 +/* dirren, renamed dir */
39052 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39053 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39054 +/* whiteouted doubly */
39055 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39056 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39058 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39059 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39061 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39062 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39063 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39065 +/* doubly whiteouted */
39066 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39067 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39068 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39070 +/* branch permissions and attributes */
39071 +#define AUFS_BRPERM_RW "rw"
39072 +#define AUFS_BRPERM_RO "ro"
39073 +#define AUFS_BRPERM_RR "rr"
39074 +#define AUFS_BRATTR_COO_REG "coo_reg"
39075 +#define AUFS_BRATTR_COO_ALL "coo_all"
39076 +#define AUFS_BRATTR_FHSM "fhsm"
39077 +#define AUFS_BRATTR_UNPIN "unpin"
39078 +#define AUFS_BRATTR_ICEX "icex"
39079 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39080 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39081 +#define AUFS_BRATTR_ICEX_TR "icextr"
39082 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39083 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39084 +#define AUFS_BRRATTR_WH "wh"
39085 +#define AUFS_BRWATTR_NLWH "nolwh"
39086 +#define AUFS_BRWATTR_MOO "moo"
39088 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39089 +#define AuBrPerm_RO (1 << 1) /* readonly */
39090 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39091 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39093 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39094 +#define AuBrAttr_COO_ALL (1 << 4)
39095 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39097 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39098 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39099 + branch. meaningless since
39100 + linux-3.18-rc1 */
39102 +/* ignore error in copying XATTR */
39103 +#define AuBrAttr_ICEX_SEC (1 << 7)
39104 +#define AuBrAttr_ICEX_SYS (1 << 8)
39105 +#define AuBrAttr_ICEX_TR (1 << 9)
39106 +#define AuBrAttr_ICEX_USR (1 << 10)
39107 +#define AuBrAttr_ICEX_OTH (1 << 11)
39108 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39109 + | AuBrAttr_ICEX_SYS \
39110 + | AuBrAttr_ICEX_TR \
39111 + | AuBrAttr_ICEX_USR \
39112 + | AuBrAttr_ICEX_OTH)
39114 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39115 +#define AuBrRAttr_Mask AuBrRAttr_WH
39117 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39118 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39119 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39121 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39123 +/* #warning test userspace */
39125 +#ifndef CONFIG_AUFS_FHSM
39126 +#undef AuBrAttr_FHSM
39127 +#define AuBrAttr_FHSM 0
39129 +#ifndef CONFIG_AUFS_XATTR
39130 +#undef AuBrAttr_ICEX
39131 +#define AuBrAttr_ICEX 0
39132 +#undef AuBrAttr_ICEX_SEC
39133 +#define AuBrAttr_ICEX_SEC 0
39134 +#undef AuBrAttr_ICEX_SYS
39135 +#define AuBrAttr_ICEX_SYS 0
39136 +#undef AuBrAttr_ICEX_TR
39137 +#define AuBrAttr_ICEX_TR 0
39138 +#undef AuBrAttr_ICEX_USR
39139 +#define AuBrAttr_ICEX_USR 0
39140 +#undef AuBrAttr_ICEX_OTH
39141 +#define AuBrAttr_ICEX_OTH 0
39145 +/* the longest combination */
39146 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39147 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39148 + "+" AUFS_BRATTR_COO_REG \
39149 + "+" AUFS_BRATTR_FHSM \
39150 + "+" AUFS_BRATTR_UNPIN \
39151 + "+" AUFS_BRATTR_ICEX_SEC \
39152 + "+" AUFS_BRATTR_ICEX_SYS \
39153 + "+" AUFS_BRATTR_ICEX_USR \
39154 + "+" AUFS_BRATTR_ICEX_OTH \
39155 + "+" AUFS_BRWATTR_NLWH)
39158 + char a[AuBrPermStrSz];
39159 +} au_br_perm_str_t;
39161 +static inline int au_br_writable(int brperm)
39163 + return brperm & AuBrPerm_RW;
39166 +static inline int au_br_whable(int brperm)
39168 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39171 +static inline int au_br_wh_linkable(int brperm)
39173 + return !(brperm & AuBrWAttr_NoLinkWH);
39176 +static inline int au_br_cmoo(int brperm)
39178 + return brperm & AuBrAttr_CMOO_Mask;
39181 +static inline int au_br_fhsm(int brperm)
39183 + return brperm & AuBrAttr_FHSM;
39186 +/* ---------------------------------------------------------------------- */
39190 + /* readdir in userspace */
39194 + AuCtl_WBR_FD, /* pathconf wrapper */
39195 + AuCtl_IBUSY, /* busy inode */
39196 + AuCtl_MVDOWN, /* move-down */
39197 + AuCtl_BR, /* info about branches */
39198 + AuCtl_FHSM_FD /* connection for fhsm */
39201 +/* borrowed from linux/include/linux/kernel.h */
39203 +#ifdef _GNU_SOURCE
39204 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39206 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39208 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39211 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39213 +#define __aligned(x) __attribute__((aligned(x)))
39218 +#define __packed __attribute__((packed))
39222 +struct au_rdu_cookie {
39227 + uint32_t generation;
39230 +struct au_rdu_ent {
39239 +static inline int au_rdu_len(int nlen)
39241 + /* include the terminating NULL */
39242 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39243 + sizeof(uint64_t));
39246 +union au_rdu_ent_ul {
39247 + struct au_rdu_ent __user *e;
39259 + uint64_t sz; /* AuCtl_RDU */
39260 + uint64_t nent; /* AuCtl_RDU_INO */
39262 + union au_rdu_ent_ul ent;
39263 + uint16_t verify[AufsCtlRduV_End];
39265 + /* input/output */
39269 + union au_rdu_ent_ul tail;
39270 + /* number of entries which were added in a single call */
39275 + struct au_rdu_cookie cookie;
39278 +/* ---------------------------------------------------------------------- */
39280 +/* dirren. the branch is identified by the filename who contains this */
39281 +struct au_drinfo {
39284 + uint8_t oldnamelen;
39285 + uint64_t _padding;
39287 + uint8_t oldname[];
39290 +struct au_drinfo_fdata {
39292 + struct au_drinfo drinfo;
39295 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39297 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39299 +/* ---------------------------------------------------------------------- */
39301 +struct aufs_wbr_fd {
39306 +/* ---------------------------------------------------------------------- */
39308 +struct aufs_ibusy {
39309 + uint64_t ino, h_ino;
39313 +/* ---------------------------------------------------------------------- */
39315 +/* error code for move-down */
39316 +/* the actual message strings are implemented in aufs-util.git */
39318 + EAU_MVDOWN_OPAQUE = 1,
39319 + EAU_MVDOWN_WHITEOUT,
39320 + EAU_MVDOWN_UPPER,
39321 + EAU_MVDOWN_BOTTOM,
39322 + EAU_MVDOWN_NOUPPER,
39323 + EAU_MVDOWN_NOLOWERBR,
39327 +/* flags for move-down */
39328 +#define AUFS_MVDOWN_DMSG 1
39329 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39330 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39331 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39332 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39333 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39334 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39335 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39336 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39337 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39338 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39339 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39340 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39342 +/* index for move-down */
39344 + AUFS_MVDOWN_UPPER,
39345 + AUFS_MVDOWN_LOWER,
39346 + AUFS_MVDOWN_NARRAY
39350 + * additional info of move-down
39351 + * number of free blocks and inodes.
39352 + * subset of struct kstatfs, but smaller and always 64bit.
39354 +struct aufs_stfs {
39355 + uint64_t f_blocks;
39356 + uint64_t f_bavail;
39357 + uint64_t f_files;
39358 + uint64_t f_ffree;
39361 +struct aufs_stbr {
39362 + int16_t brid; /* optional input */
39363 + int16_t bindex; /* output */
39364 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39367 +struct aufs_mvdown {
39368 + uint32_t flags; /* input/output */
39369 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39370 + int8_t au_errno; /* output */
39373 +/* ---------------------------------------------------------------------- */
39375 +union aufs_brinfo {
39376 + /* PATH_MAX may differ between kernel-space and user-space */
39377 + char _spacer[4096];
39385 +/* ---------------------------------------------------------------------- */
39387 +#define AuCtlType 'A'
39388 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39389 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39390 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39391 + struct aufs_wbr_fd)
39392 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39393 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39394 + struct aufs_mvdown)
39395 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39396 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39398 +#endif /* __AUFS_TYPE_H__ */
39399 SPDX-License-Identifier: GPL-2.0
39400 aufs5.x-rcN loopback patch
39402 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39403 index 9009a0efc4b28..60307b90fbead 100644
39404 --- a/drivers/block/loop.c
39405 +++ b/drivers/block/loop.c
39406 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39410 +static struct file *loop_real_file(struct file *file)
39412 + struct file *f = NULL;
39414 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39415 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39419 static void loop_reread_partitions(struct loop_device *lo)
39422 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39424 struct file *file = fget(arg);
39425 struct file *old_file;
39426 + struct file *f, *virt_file = NULL, *old_virt_file;
39430 @@ -586,11 +596,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39431 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39434 + f = loop_real_file(file);
39436 + virt_file = file;
39441 error = loop_validate_file(file, bdev);
39445 old_file = lo->lo_backing_file;
39446 + old_virt_file = lo->lo_backing_virt_file;
39450 @@ -603,6 +621,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39451 blk_mq_freeze_queue(lo->lo_queue);
39452 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39453 lo->lo_backing_file = file;
39454 + lo->lo_backing_virt_file = virt_file;
39455 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39456 mapping_set_gfp_mask(file->f_mapping,
39457 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39458 @@ -625,6 +644,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39462 + if (old_virt_file)
39463 + fput(old_virt_file);
39465 loop_reread_partitions(lo);
39467 @@ -633,6 +654,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39468 loop_global_unlock(lo, is_loop);
39476 @@ -971,6 +994,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39477 const struct loop_config *config)
39479 struct file *file = fget(config->fd);
39480 + struct file *f, *virt_file = NULL;
39481 struct inode *inode;
39482 struct address_space *mapping;
39484 @@ -986,6 +1010,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39485 /* This is safe, since we have a reference from open(). */
39486 __module_get(THIS_MODULE);
39488 + f = loop_real_file(file);
39490 + virt_file = file;
39496 * If we don't hold exclusive handle for the device, upgrade to it
39497 * here to avoid changing device under exclusive owner.
39498 @@ -1051,6 +1082,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39499 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39500 lo->lo_device = bdev;
39501 lo->lo_backing_file = file;
39502 + lo->lo_backing_virt_file = virt_file;
39503 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39504 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39506 @@ -1101,6 +1133,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39507 bd_abort_claiming(bdev, loop_configure);
39512 /* This is safe: open() is still holding a reference. */
39513 module_put(THIS_MODULE);
39515 @@ -1109,6 +1143,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39516 static void __loop_clr_fd(struct loop_device *lo, bool release)
39519 + struct file *virt_filp = lo->lo_backing_virt_file;
39520 gfp_t gfp = lo->old_gfp_mask;
39521 struct loop_worker *pos, *worker;
39523 @@ -1154,6 +1189,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39524 spin_lock_irq(&lo->lo_lock);
39525 filp = lo->lo_backing_file;
39526 lo->lo_backing_file = NULL;
39527 + lo->lo_backing_virt_file = NULL;
39528 spin_unlock_irq(&lo->lo_lock);
39530 lo->lo_device = NULL;
39531 @@ -1215,6 +1251,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39532 * fput can take open_mutex which is usually taken before lo_mutex.
39539 static int loop_clr_fd(struct loop_device *lo)
39540 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39541 index 082d4b6bfc6a6..61feca64688df 100644
39542 --- a/drivers/block/loop.h
39543 +++ b/drivers/block/loop.h
39544 @@ -34,7 +34,7 @@ struct loop_device {
39546 char lo_file_name[LO_NAME_SIZE];
39548 - struct file * lo_backing_file;
39549 + struct file *lo_backing_file, *lo_backing_virt_file;
39550 struct block_device *lo_device;
39552 gfp_t old_gfp_mask;
39553 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39554 index 99ceca1440449..e49dfe8550329 100644
39555 --- a/fs/aufs/f_op.c
39556 +++ b/fs/aufs/f_op.c
39557 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39558 if (IS_ERR(h_file))
39561 - if (au_test_loopback_kthread()) {
39562 + if (0 && au_test_loopback_kthread()) {
39563 au_warn_loopback(h_file->f_path.dentry->d_sb);
39564 if (file->f_mapping != h_file->f_mapping) {
39565 file->f_mapping = h_file->f_mapping;
39566 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39567 index 74347bd75b380..5ef888a1d53f4 100644
39568 --- a/fs/aufs/loop.c
39569 +++ b/fs/aufs/loop.c
39570 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39571 symbol_put(loop_backing_file);
39572 au_kfree_try_rcu(au_warn_loopback_array);
39575 +/* ---------------------------------------------------------------------- */
39577 +/* support the loopback block device insude aufs */
39579 +struct file *aufs_real_loop(struct file *file)
39583 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39584 + fi_read_lock(file);
39585 + f = au_hf_top(file);
39586 + fi_read_unlock(file);
39590 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39591 index 7293bee427f96..3345c098d0d47 100644
39592 --- a/fs/aufs/loop.h
39593 +++ b/fs/aufs/loop.h
39594 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39596 int au_loopback_init(void);
39597 void au_loopback_fin(void);
39599 +struct file *aufs_real_loop(struct file *file);
39601 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39603 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39605 AuStubInt0(au_loopback_init, void)
39606 AuStubVoid(au_loopback_fin, void)
39608 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39609 #endif /* BLK_DEV_LOOP */
39611 #endif /* __KERNEL__ */
39612 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39613 index 90043afec51c1..0835f6da42d97 100644
39614 --- a/fs/aufs/super.c
39615 +++ b/fs/aufs/super.c
39616 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39617 .show_options = aufs_show_options,
39618 .statfs = aufs_statfs,
39619 .put_super = aufs_put_super,
39620 - .sync_fs = aufs_sync_fs
39621 + .sync_fs = aufs_sync_fs,
39622 +#ifdef CONFIG_AUFS_BDEV_LOOP
39623 + .real_loop = aufs_real_loop
39627 /* ---------------------------------------------------------------------- */
39628 diff --git a/include/linux/fs.h b/include/linux/fs.h
39629 index 5479e6dc18a23..05fe92d076c19 100644
39630 --- a/include/linux/fs.h
39631 +++ b/include/linux/fs.h
39632 @@ -2137,6 +2137,10 @@ struct super_operations {
39633 struct shrink_control *);
39634 long (*free_cached_objects)(struct super_block *,
39635 struct shrink_control *);
39636 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39638 + struct file *(*real_loop)(struct file *);