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 diff --git a/fs/namespace.c b/fs/namespace.c
723 index e189393b34b14..5d7d122d1067a 100644
726 @@ -440,6 +440,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
727 mnt_dec_writers(real_mount(mnt));
730 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
733 * mnt_drop_write - give up write access to a mount
734 @@ -844,6 +845,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
736 return check_mnt(real_mount(mnt));
738 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
741 * vfsmount lock must be held for write
742 @@ -2047,6 +2049,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
746 +EXPORT_SYMBOL_GPL(iterate_mounts);
748 static void lock_mnt_tree(struct mount *mnt)
750 diff --git a/fs/notify/group.c b/fs/notify/group.c
751 index b7d4d64f87c29..2d2d2c6d33e41 100644
752 --- a/fs/notify/group.c
753 +++ b/fs/notify/group.c
754 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
756 refcount_inc(&group->refcnt);
758 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
761 * Drop a reference to a group. Free it if it's through.
762 diff --git a/fs/open.c b/fs/open.c
763 index 9ff2f621b760b..3b8deceee506f 100644
766 @@ -66,6 +66,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
767 inode_unlock(dentry->d_inode);
770 +EXPORT_SYMBOL_GPL(do_truncate);
772 long vfs_truncate(const struct path *path, loff_t length)
774 diff --git a/fs/read_write.c b/fs/read_write.c
775 index 0074afa7ecb3e..612cf04d9f6b9 100644
776 --- a/fs/read_write.c
777 +++ b/fs/read_write.c
778 @@ -488,6 +488,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
782 +EXPORT_SYMBOL_GPL(vfs_read);
784 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
786 @@ -598,6 +599,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
787 file_end_write(file);
790 +EXPORT_SYMBOL_GPL(vfs_write);
792 /* file_ppos returns &file->f_pos or NULL if file is stream */
793 static inline loff_t *file_ppos(struct file *file)
794 diff --git a/fs/splice.c b/fs/splice.c
795 index 3e6ba363b7775..7c1be373eb7cd 100644
798 @@ -766,6 +766,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
799 return warn_unsupported(out, "write");
800 return out->f_op->splice_write(pipe, out, ppos, len, flags);
802 +EXPORT_SYMBOL_GPL(do_splice_from);
805 * Attempt to initiate a splice from a file to a pipe.
806 @@ -795,6 +796,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
807 return warn_unsupported(in, "read");
808 return in->f_op->splice_read(in, ppos, pipe, len, flags);
810 +EXPORT_SYMBOL_GPL(do_splice_to);
813 * splice_direct_to_actor - splices data directly between two non-pipes
814 diff --git a/fs/xattr.c b/fs/xattr.c
815 index 5c8c5175b385c..ff7e9ff774b73 100644
818 @@ -384,6 +384,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
819 *xattr_value = value;
822 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
825 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
826 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
827 index 43e3d1fdd570b..5d6f33f1f2f28 100644
828 --- a/kernel/locking/lockdep.c
829 +++ b/kernel/locking/lockdep.c
830 @@ -210,6 +210,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
832 return lock_classes + class_idx;
834 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
835 #define hlock_class(hlock) lockdep_hlock_class(hlock)
837 #ifdef CONFIG_LOCK_STAT
838 diff --git a/kernel/task_work.c b/kernel/task_work.c
839 index 1698fbe6f0e13..081b05acadf82 100644
840 --- a/kernel/task_work.c
841 +++ b/kernel/task_work.c
842 @@ -167,3 +167,4 @@ void task_work_run(void)
846 +EXPORT_SYMBOL_GPL(task_work_run);
847 diff --git a/security/security.c b/security/security.c
848 index 22261d79f3333..732e4c219ea29 100644
849 --- a/security/security.c
850 +++ b/security/security.c
851 @@ -1151,6 +1151,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
853 return call_int_hook(path_rmdir, 0, dir, dentry);
855 +EXPORT_SYMBOL_GPL(security_path_rmdir);
857 int security_path_unlink(const struct path *dir, struct dentry *dentry)
859 @@ -1167,6 +1168,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
861 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
863 +EXPORT_SYMBOL_GPL(security_path_symlink);
865 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
866 struct dentry *new_dentry)
867 @@ -1175,6 +1177,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
869 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
871 +EXPORT_SYMBOL_GPL(security_path_link);
873 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
874 const struct path *new_dir, struct dentry *new_dentry,
875 @@ -1202,6 +1205,7 @@ int security_path_truncate(const struct path *path)
877 return call_int_hook(path_truncate, 0, path);
879 +EXPORT_SYMBOL_GPL(security_path_truncate);
881 int security_path_chmod(const struct path *path, umode_t mode)
883 @@ -1209,6 +1213,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
885 return call_int_hook(path_chmod, 0, path, mode);
887 +EXPORT_SYMBOL_GPL(security_path_chmod);
889 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
891 @@ -1216,6 +1221,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
893 return call_int_hook(path_chown, 0, path, uid, gid);
895 +EXPORT_SYMBOL_GPL(security_path_chown);
897 int security_path_chroot(const struct path *path)
899 @@ -1316,6 +1322,7 @@ int security_inode_permission(struct inode *inode, int mask)
901 return call_int_hook(inode_permission, 0, inode, mask);
903 +EXPORT_SYMBOL_GPL(security_inode_permission);
905 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
907 @@ -1513,6 +1520,7 @@ int security_file_permission(struct file *file, int mask)
909 return fsnotify_perm(file, mask);
911 +EXPORT_SYMBOL_GPL(security_file_permission);
913 int security_file_alloc(struct file *file)
915 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
916 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
917 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-03-21 14:49:05.713299677 +0100
919 +What: /debug/aufs/si_<id>/
921 +Contact: J. R. Okajima <hooanon05g@gmail.com>
923 + Under /debug/aufs, a directory named si_<id> is created
924 + per aufs mount, where <id> is a unique id generated
927 +What: /debug/aufs/si_<id>/plink
929 +Contact: J. R. Okajima <hooanon05g@gmail.com>
931 + It has three lines and shows the information about the
932 + pseudo-link. The first line is a single number
933 + representing a number of buckets. The second line is a
934 + number of pseudo-links per buckets (separated by a
935 + blank). The last line is a single number representing a
936 + total number of psedo-links.
937 + When the aufs mount option 'noplink' is specified, it
938 + will show "1\n0\n0\n".
940 +What: /debug/aufs/si_<id>/xib
942 +Contact: J. R. Okajima <hooanon05g@gmail.com>
944 + It shows the consumed blocks by xib (External Inode Number
945 + Bitmap), its block size and file size.
946 + When the aufs mount option 'noxino' is specified, it
947 + will be empty. About XINO files, see the aufs manual.
949 +What: /debug/aufs/si_<id>/xi<branch-index>
951 +Contact: J. R. Okajima <hooanon05g@gmail.com>
953 + It shows the consumed blocks by xino (External Inode Number
954 + Translation Table), its link count, block size and file
956 + Due to the file size limit, there may exist multiple
957 + xino files per branch. In this case, "-N" is added to
958 + the filename and it corresponds to the index of the
959 + internal xino array. "-0" is omitted.
960 + When the aufs mount option 'noxino' is specified, Those
961 + entries won't exist. About XINO files, see the aufs
964 +What: /debug/aufs/si_<id>/xigen
966 +Contact: J. R. Okajima <hooanon05g@gmail.com>
968 + It shows the consumed blocks by xigen (External Inode
969 + Generation Table), its block size and file size.
970 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
972 + When the aufs mount option 'noxino' is specified, it
973 + will be empty. About XINO files, see the aufs manual.
974 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
975 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
976 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-03-21 14:49:05.713299677 +0100
978 +What: /sys/fs/aufs/si_<id>/
980 +Contact: J. R. Okajima <hooanon05g@gmail.com>
982 + Under /sys/fs/aufs, a directory named si_<id> is created
983 + per aufs mount, where <id> is a unique id generated
986 +What: /sys/fs/aufs/si_<id>/br<idx>
988 +Contact: J. R. Okajima <hooanon05g@gmail.com>
990 + It shows the abolute path of a member directory (which
991 + is called branch) in aufs, and its permission.
993 +What: /sys/fs/aufs/si_<id>/brid<idx>
995 +Contact: J. R. Okajima <hooanon05g@gmail.com>
997 + It shows the id of a member directory (which is called
1000 +What: /sys/fs/aufs/si_<id>/xi_path
1002 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1004 + It shows the abolute path of XINO (External Inode Number
1005 + Bitmap, Translation Table and Generation Table) file
1006 + even if it is the default path.
1007 + When the aufs mount option 'noxino' is specified, it
1008 + will be empty. About XINO files, see the aufs manual.
1009 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1010 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1011 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-03-21 14:49:05.713299677 +0100
1014 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1016 +# This program is free software; you can redistribute it and/or modify
1017 +# it under the terms of the GNU General Public License as published by
1018 +# the Free Software Foundation; either version 2 of the License, or
1019 +# (at your option) any later version.
1021 +# This program is distributed in the hope that it will be useful,
1022 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1023 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1024 +# GNU General Public License for more details.
1026 +# You should have received a copy of the GNU General Public License
1027 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1030 +----------------------------------------
1032 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1033 +1. abbrev. for "advanced multi-layered unification filesystem".
1034 +2. abbrev. for "another unionfs".
1035 +3. abbrev. for "auf das" in German which means "on the" in English.
1036 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1037 + But "Filesystem aufs Filesystem" is hard to understand.
1038 +4. abbrev. for "African Urban Fashion Show".
1040 +AUFS is a filesystem with features:
1041 +- multi layered stackable unification filesystem, the member directory
1042 + is called as a branch.
1043 +- branch permission and attribute, 'readonly', 'real-readonly',
1044 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1046 +- internal "file copy-on-write".
1047 +- logical deletion, whiteout.
1048 +- dynamic branch manipulation, adding, deleting and changing permission.
1049 +- allow bypassing aufs, user's direct branch access.
1050 +- external inode number translation table and bitmap which maintains the
1051 + persistent aufs inode number.
1052 +- seekable directory, including NFS readdir.
1053 +- file mapping, mmap and sharing pages.
1054 +- pseudo-link, hardlink over branches.
1055 +- loopback mounted filesystem as a branch.
1056 +- several policies to select one among multiple writable branches.
1057 +- revert a single systemcall when an error occurs in aufs.
1061 +Multi Layered Stackable Unification Filesystem
1062 +----------------------------------------------------------------------
1063 +Most people already knows what it is.
1064 +It is a filesystem which unifies several directories and provides a
1065 +merged single directory. When users access a file, the access will be
1066 +passed/re-directed/converted (sorry, I am not sure which English word is
1067 +correct) to the real file on the member filesystem. The member
1068 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1069 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1070 +readonly branch is handled by creating 'whiteout' on the upper writable
1073 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1074 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1075 +different approaches to implement the merged-view.
1076 +The former tries putting it into VFS, and the latter implements as a
1077 +separate filesystem.
1078 +(If I misunderstand about these implementations, please let me know and
1079 +I shall correct it. Because it is a long time ago when I read their
1080 +source files last time).
1082 +UnionMount's approach will be able to small, but may be hard to share
1083 +branches between several UnionMount since the whiteout in it is
1084 +implemented in the inode on branch filesystem and always
1085 +shared. According to Bharata's post, readdir does not seems to be
1087 +There are several missing features known in this implementations such as
1088 +- for users, the inode number may change silently. eg. copy-up.
1089 +- link(2) may break by copy-up.
1090 +- read(2) may get an obsoleted filedata (fstat(2) too).
1091 +- fcntl(F_SETLK) may be broken by copy-up.
1092 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1095 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1096 +merged into mainline. This is another implementation of UnionMount as a
1097 +separated filesystem. All the limitations and known problems which
1098 +UnionMount are equally inherited to "overlay" filesystem.
1100 +Unionfs has a longer history. When I started implementing a stackable
1101 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1102 +inode, dentry and file objects and they have an array pointing lower
1103 +same kind objects. After contributing many patches for Unionfs, I
1104 +re-started my project AUFS (Jun 2006).
1106 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1107 +implemented my own ideas, approaches and enhancements and it became
1108 +totally different one.
1110 +Comparing DM snapshot and fs based implementation
1111 +- the number of bytes to be copied between devices is much smaller.
1112 +- the type of filesystem must be one and only.
1113 +- the fs must be writable, no readonly fs, even for the lower original
1114 + device. so the compression fs will not be usable. but if we use
1115 + loopback mount, we may address this issue.
1117 + mount /cdrom/squashfs.img /sq
1118 + losetup /sq/ext2.img
1119 + losetup /somewhere/cow
1120 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1121 +- it will be difficult (or needs more operations) to extract the
1122 + difference between the original device and COW.
1123 +- DM snapshot-merge may help a lot when users try merging. in the
1124 + fs-layer union, users will use rsync(1).
1126 +You may want to read my old paper "Filesystems in LiveCD"
1127 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1130 +Several characters/aspects/persona of aufs
1131 +----------------------------------------------------------------------
1133 +Aufs has several characters, aspects or persona.
1134 +1. a filesystem, callee of VFS helper
1135 +2. sub-VFS, caller of VFS helper for branches
1136 +3. a virtual filesystem which maintains persistent inode number
1137 +4. reader/writer of files on branches such like an application
1139 +1. Callee of VFS Helper
1140 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1141 +unlink(2) from an application reaches sys_unlink() kernel function and
1142 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1143 +calls filesystem specific unlink operation. Actually aufs implements the
1144 +unlink operation but it behaves like a redirector.
1146 +2. Caller of VFS Helper for Branches
1147 +aufs_unlink() passes the unlink request to the branch filesystem as if
1148 +it were called from VFS. So the called unlink operation of the branch
1149 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1150 +every necessary pre/post operation for the branch filesystem.
1151 +- acquire the lock for the parent dir on a branch
1152 +- lookup in a branch
1153 +- revalidate dentry on a branch
1154 +- mnt_want_write() for a branch
1155 +- vfs_unlink() for a branch
1156 +- mnt_drop_write() for a branch
1157 +- release the lock on a branch
1159 +3. Persistent Inode Number
1160 +One of the most important issue for a filesystem is to maintain inode
1161 +numbers. This is particularly important to support exporting a
1162 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1163 +backend block device for its own. But some storage is necessary to
1164 +keep and maintain the inode numbers. It may be a large space and may not
1165 +suit to keep in memory. Aufs rents some space from its first writable
1166 +branch filesystem (by default) and creates file(s) on it. These files
1167 +are created by aufs internally and removed soon (currently) keeping
1169 +Note: Because these files are removed, they are totally gone after
1170 + unmounting aufs. It means the inode numbers are not persistent
1171 + across unmount or reboot. I have a plan to make them really
1172 + persistent which will be important for aufs on NFS server.
1174 +4. Read/Write Files Internally (copy-on-write)
1175 +Because a branch can be readonly, when you write a file on it, aufs will
1176 +"copy-up" it to the upper writable branch internally. And then write the
1177 +originally requested thing to the file. Generally kernel doesn't
1178 +open/read/write file actively. In aufs, even a single write may cause a
1179 +internal "file copy". This behaviour is very similar to cp(1) command.
1181 +Some people may think it is better to pass such work to user space
1182 +helper, instead of doing in kernel space. Actually I am still thinking
1183 +about it. But currently I have implemented it in kernel space.
1184 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1185 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1186 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-03-21 14:49:05.713299677 +0100
1189 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1191 +# This program is free software; you can redistribute it and/or modify
1192 +# it under the terms of the GNU General Public License as published by
1193 +# the Free Software Foundation; either version 2 of the License, or
1194 +# (at your option) any later version.
1196 +# This program is distributed in the hope that it will be useful,
1197 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1198 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1199 +# GNU General Public License for more details.
1201 +# You should have received a copy of the GNU General Public License
1202 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1204 +Basic Aufs Internal Structure
1206 +Superblock/Inode/Dentry/File Objects
1207 +----------------------------------------------------------------------
1208 +As like an ordinary filesystem, aufs has its own
1209 +superblock/inode/dentry/file objects. All these objects have a
1210 +dynamically allocated array and store the same kind of pointers to the
1211 +lower filesystem, branch.
1212 +For example, when you build a union with one readwrite branch and one
1213 +readonly, mounted /au, /rw and /ro respectively.
1215 +- /ro/fileA exists but /rw/fileA
1217 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1218 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1219 +- [0] = NULL (because /rw/fileA doesn't exist)
1222 +This style of an array is essentially same to the aufs
1223 +superblock/inode/dentry/file objects.
1225 +Because aufs supports manipulating branches, ie. add/delete/change
1226 +branches dynamically, these objects has its own generation. When
1227 +branches are changed, the generation in aufs superblock is
1228 +incremented. And a generation in other object are compared when it is
1229 +accessed. When a generation in other objects are obsoleted, aufs
1230 +refreshes the internal array.
1234 +----------------------------------------------------------------------
1235 +Additionally aufs superblock has some data for policies to select one
1236 +among multiple writable branches, XIB files, pseudo-links and kobject.
1237 +See below in detail.
1238 +About the policies which supports copy-down a directory, see
1239 +wbr_policy.txt too.
1242 +Branch and XINO(External Inode Number Translation Table)
1243 +----------------------------------------------------------------------
1244 +Every branch has its own xino (external inode number translation table)
1245 +file. The xino file is created and unlinked by aufs internally. When two
1246 +members of a union exist on the same filesystem, they share the single
1248 +The struct of a xino file is simple, just a sequence of aufs inode
1249 +numbers which is indexed by the lower inode number.
1250 +In the above sample, assume the inode number of /ro/fileA is i111 and
1251 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1252 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1254 +When the inode numbers are not contiguous, the xino file will be sparse
1255 +which has a hole in it and doesn't consume as much disk space as it
1256 +might appear. If your branch filesystem consumes disk space for such
1257 +holes, then you should specify 'xino=' option at mounting aufs.
1259 +Aufs has a mount option to free the disk blocks for such holes in XINO
1260 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1261 +meet a problem of disk shortage due to XINO files, then you should try
1262 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1263 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1264 +the holes in XINO files.
1266 +Also a writable branch has three kinds of "whiteout bases". All these
1267 +are existed when the branch is joined to aufs, and their names are
1268 +whiteout-ed doubly, so that users will never see their names in aufs
1270 +1. a regular file which will be hardlinked to all whiteouts.
1271 +2. a directory to store a pseudo-link.
1272 +3. a directory to store an "orphan"-ed file temporary.
1275 + When you remove a file on a readonly branch, aufs handles it as a
1276 + logical deletion and creates a whiteout on the upper writable branch
1277 + as a hardlink of this file in order not to consume inode on the
1280 + See below, Pseudo-link.
1282 + When "fileC" exists on the lower readonly branch only and it is
1283 + opened and removed with its parent dir, and then user writes
1284 + something into it, then aufs copies-up fileC to this
1285 + directory. Because there is no other dir to store fileC. After
1286 + creating a file under this dir, the file is unlinked.
1288 +Because aufs supports manipulating branches, ie. add/delete/change
1289 +dynamically, a branch has its own id. When the branch order changes,
1290 +aufs finds the new index by searching the branch id.
1294 +----------------------------------------------------------------------
1295 +Assume "fileA" exists on the lower readonly branch only and it is
1296 +hardlinked to "fileB" on the branch. When you write something to fileA,
1297 +aufs copies-up it to the upper writable branch. Additionally aufs
1298 +creates a hardlink under the Pseudo-link Directory of the writable
1299 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1300 +simple list. If fileB is read after unlinking fileA, aufs returns
1301 +filedata from the pseudo-link instead of the lower readonly
1302 +branch. Because the pseudo-link is based upon the inode, to keep the
1303 +inode number by xino (see above) is essentially necessary.
1305 +All the hardlinks under the Pseudo-link Directory of the writable branch
1306 +should be restored in a proper location later. Aufs provides a utility
1307 +to do this. The userspace helpers executed at remounting and unmounting
1309 +During this utility is running, it puts aufs into the pseudo-link
1310 +maintenance mode. In this mode, only the process which began the
1311 +maintenance mode (and its child processes) is allowed to operate in
1312 +aufs. Some other processes which are not related to the pseudo-link will
1313 +be allowed to run too, but the rest have to return an error or wait
1314 +until the maintenance mode ends. If a process already acquires an inode
1315 +mutex (in VFS), it has to return an error.
1318 +XIB(external inode number bitmap)
1319 +----------------------------------------------------------------------
1320 +Addition to the xino file per a branch, aufs has an external inode number
1321 +bitmap in a superblock object. It is also an internal file such like a
1323 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1325 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1327 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1328 +reduce the number of consumed disk blocks for these files.
1331 +Virtual or Vertical Dir, and Readdir in Userspace
1332 +----------------------------------------------------------------------
1333 +In order to support multiple layers (branches), aufs readdir operation
1334 +constructs a virtual dir block on memory. For readdir, aufs calls
1335 +vfs_readdir() internally for each dir on branches, merges their entries
1336 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1337 +object. So the file object has its entry list until it is closed. The
1338 +entry list will be updated when the file position is zero and becomes
1339 +obsoleted. This decision is made in aufs automatically.
1341 +The dynamically allocated memory block for the name of entries has a
1342 +unit of 512 bytes (by default) and stores the names contiguously (no
1343 +padding). Another block for each entry is handled by kmem_cache too.
1344 +During building dir blocks, aufs creates hash list and judging whether
1345 +the entry is whiteouted by its upper branch or already listed.
1346 +The merged result is cached in the corresponding inode object and
1347 +maintained by a customizable life-time option.
1349 +Some people may call it can be a security hole or invite DoS attack
1350 +since the opened and once readdir-ed dir (file object) holds its entry
1351 +list and becomes a pressure for system memory. But I'd say it is similar
1352 +to files under /proc or /sys. The virtual files in them also holds a
1353 +memory page (generally) while they are opened. When an idea to reduce
1354 +memory for them is introduced, it will be applied to aufs too.
1355 +For those who really hate this situation, I've developed readdir(3)
1356 +library which operates this merging in userspace. You just need to set
1357 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1358 +kernel space for readdir(3).
1362 +----------------------------------------------------------------------
1363 +Aufs sometimes requires privilege access to a branch. For instance,
1364 +in copy-up/down operation. When a user process is going to make changes
1365 +to a file which exists in the lower readonly branch only, and the mode
1366 +of one of ancestor directories may not be writable by a user
1367 +process. Here aufs copy-up the file with its ancestors and they may
1368 +require privilege to set its owner/group/mode/etc.
1369 +This is a typical case of a application character of aufs (see
1372 +Aufs uses workqueue synchronously for this case. It creates its own
1373 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1374 +passes the request to call mkdir or write (for example), and wait for
1375 +its completion. This approach solves a problem of a signal handler
1377 +If aufs didn't adopt the workqueue and changed the privilege of the
1378 +process, then the process may receive the unexpected SIGXFSZ or other
1381 +Also aufs uses the system global workqueue ("events" kernel thread) too
1382 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1383 +whiteout base and etc. This is unrelated to a privilege.
1384 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1385 +superblock at the beginning, at the same time waits for the completion
1386 +of all queued asynchronous tasks.
1390 +----------------------------------------------------------------------
1391 +The whiteout in aufs is very similar to Unionfs's. That is represented
1392 +by its filename. UnionMount takes an approach of a file mode, but I am
1393 +afraid several utilities (find(1) or something) will have to support it.
1395 +Basically the whiteout represents "logical deletion" which stops aufs to
1396 +lookup further, but also it represents "dir is opaque" which also stop
1399 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1400 +In order to make several functions in a single systemcall to be
1401 +revertible, aufs adopts an approach to rename a directory to a temporary
1402 +unique whiteouted name.
1403 +For example, in rename(2) dir where the target dir already existed, aufs
1404 +renames the target dir to a temporary unique whiteouted name before the
1405 +actual rename on a branch, and then handles other actions (make it opaque,
1406 +update the attributes, etc). If an error happens in these actions, aufs
1407 +simply renames the whiteouted name back and returns an error. If all are
1408 +succeeded, aufs registers a function to remove the whiteouted unique
1409 +temporary name completely and asynchronously to the system global
1414 +----------------------------------------------------------------------
1415 +It is a well-known feature or concept.
1416 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1417 +internally and makes change to the new file on the upper writable branch.
1418 +When the trigger systemcall does not update the timestamps of the parent
1419 +dir, aufs reverts it after copy-up.
1422 +Move-down (aufs3.9 and later)
1423 +----------------------------------------------------------------------
1424 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1425 +the lower readonly branch to the upper writable branch when a user
1426 +changes something about the file.
1427 +"Move-down" is an opposite action of copy-up. Basically this action is
1428 +ran manually instead of automatically and internally.
1429 +For desgin and implementation, aufs has to consider these issues.
1430 +- whiteout for the file may exist on the lower branch.
1431 +- ancestor directories may not exist on the lower branch.
1432 +- diropq for the ancestor directories may exist on the upper branch.
1433 +- free space on the lower branch will reduce.
1434 +- another access to the file may happen during moving-down, including
1435 + UDBA (see "Revalidate Dentry and UDBA").
1436 +- the file should not be hard-linked nor pseudo-linked. they should be
1437 + handled by auplink utility later.
1439 +Sometimes users want to move-down a file from the upper writable branch
1440 +to the lower readonly or writable branch. For instance,
1441 +- the free space of the upper writable branch is going to run out.
1442 +- create a new intermediate branch between the upper and lower branch.
1445 +For this purpose, use "aumvdown" command in aufs-util.git.
1446 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1447 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1448 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-03-21 14:49:05.713299677 +0100
1451 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1453 +# This program is free software; you can redistribute it and/or modify
1454 +# it under the terms of the GNU General Public License as published by
1455 +# the Free Software Foundation; either version 2 of the License, or
1456 +# (at your option) any later version.
1458 +# This program is distributed in the hope that it will be useful,
1459 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1460 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1461 +# GNU General Public License for more details.
1463 +# You should have received a copy of the GNU General Public License
1464 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1466 +Support for a branch who has its ->atomic_open()
1467 +----------------------------------------------------------------------
1468 +The filesystems who implement its ->atomic_open() are not majority. For
1469 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1470 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1471 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1472 +sure whether all filesystems who have ->atomic_open() behave like this,
1473 +but NFSv4 surely returns the error.
1475 +In order to support ->atomic_open() for aufs, there are a few
1478 +A. Introduce aufs_atomic_open()
1479 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1481 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1482 + an aufs user Pip Cet's approach
1483 + - calls aufs_create(), VFS finish_open() and notify_change().
1484 + - pass fake-mode to finish_open(), and then correct the mode by
1486 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1487 + - no aufs_atomic_open().
1488 + - aufs_lookup() registers the TID to an aufs internal object.
1489 + - aufs_create() does nothing when the matching TID is registered, but
1490 + registers the mode.
1491 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1492 + TID is registered.
1493 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1495 + - no aufs_atomic_open().
1496 + - aufs_create() registers the TID to an internal object. this info
1497 + represents "this process created this file just now."
1498 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1499 + registered TID and re-try open() with superuser's credential.
1501 +Pros and cons for each approach.
1504 + - straightforward but highly depends upon VFS internal.
1505 + - the atomic behavaiour is kept.
1506 + - some of parameters such as nameidata are hard to reproduce for
1510 + - easy to implement.
1511 + - the atomic behavaiour is lost.
1513 + - the atomic behavaiour is kept.
1514 + - dirty and tricky.
1515 + - VFS checks whether the file is created correctly after calling
1516 + ->create(), which means this approach doesn't work.
1518 + - easy to implement.
1519 + - the atomic behavaiour is lost.
1520 + - to open a file with superuser's credential and give it to a user
1521 + process is a bad idea, since the file object keeps the credential
1522 + in it. It may affect LSM or something. This approach doesn't work
1525 +The approach A is ideal, but it hard to implement. So here is a
1526 +variation of A, which is to be implemented.
1528 +A-1. Introduce aufs_atomic_open()
1529 + - calls branch fs ->atomic_open() if exists. otherwise calls
1530 + vfs_create() and finish_open().
1531 + - the demerit is that the several checks after branch fs
1532 + ->atomic_open() are lost. in the ordinary case, the checks are
1533 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1534 + be implemented in aufs, but not all I am afraid.
1535 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1536 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1537 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-03-21 14:49:05.713299677 +0100
1540 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1542 +# This program is free software; you can redistribute it and/or modify
1543 +# it under the terms of the GNU General Public License as published by
1544 +# the Free Software Foundation; either version 2 of the License, or
1545 +# (at your option) any later version.
1547 +# This program is distributed in the hope that it will be useful,
1548 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1549 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1550 +# GNU General Public License for more details.
1552 +# You should have received a copy of the GNU General Public License
1553 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1556 +----------------------------------------------------------------------
1557 +Since aufs has a character of sub-VFS (see Introduction), it operates
1558 +lookup for branches as VFS does. It may be a heavy work. But almost all
1559 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1560 +directly connected to its parent. Digging down the directory hierarchy
1561 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1564 +When a branch is a remote filesystem, aufs basically relies upon its
1565 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1567 +For d_revalidate, aufs implements three levels of revalidate tests. See
1568 +"Revalidate Dentry and UDBA" in detail.
1571 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1572 +----------------------------------------------------------------------
1573 +Let's try case study.
1574 +- aufs has two branches, upper readwrite and lower readonly.
1576 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1577 +- user invoked "chmod a+rx /au/dirA"
1578 +- the internal copy-up is activated and "/rw/dirA" is created and its
1579 + permission bits are set to world readable.
1580 +- then "/au/dirA" becomes world readable?
1582 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1583 +or it may be a natively readonly filesystem. If aufs respects the lower
1584 +branch, it should not respond readdir request from other users. But user
1585 +allowed it by chmod. Should really aufs rejects showing the entries
1588 +To be honest, I don't have a good solution for this case. So aufs
1589 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1591 +When dirperm1 is specified, aufs checks only the highest one for the
1592 +directory permission, and shows the entries. Otherwise, as usual, checks
1593 +every dir existing on all branches and rejects the request.
1595 +As a side effect, dirperm1 option improves the performance of aufs
1596 +because the number of permission check is reduced when the number of
1600 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1601 +----------------------------------------------------------------------
1602 +Generally VFS helpers re-validate a dentry as a part of lookup.
1603 +0. digging down the directory hierarchy.
1604 +1. lock the parent dir by its i_mutex.
1605 +2. lookup the final (child) entry.
1607 +4. call the actual operation (create, unlink, etc.)
1608 +5. unlock the parent dir
1610 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1611 +called. Actually aufs implements it and checks the dentry on a branch is
1613 +But it is not enough. Because aufs has to release the lock for the
1614 +parent dir on a branch at the end of ->lookup() (step 2) and
1615 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1617 +If the file on a branch is changed directly, eg. bypassing aufs, after
1618 +aufs released the lock, then the subsequent operation may cause
1619 +something unpleasant result.
1621 +This situation is a result of VFS architecture, ->lookup() and
1622 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1623 +design from VFS's point of view. It is just not suitable for sub-VFS
1626 +Aufs supports such case by three level of revalidation which is
1627 +selectable by user.
1628 +1. Simple Revalidate
1629 + Addition to the native flow in VFS's, confirm the child-parent
1630 + relationship on the branch just after locking the parent dir on the
1631 + branch in the "actual operation" (step 4). When this validation
1632 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1633 + checks the validation of the dentry on branches.
1634 +2. Monitor Changes Internally by Inotify/Fsnotify
1635 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1636 + the dentry on the branch, and returns EBUSY if it finds different
1638 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1639 + during it is in cache. When the event is notified, aufs registers a
1640 + function to kernel 'events' thread by schedule_work(). And the
1641 + function sets some special status to the cached aufs dentry and inode
1642 + private data. If they are not cached, then aufs has nothing to
1643 + do. When the same file is accessed through aufs (step 0-3) later,
1644 + aufs will detect the status and refresh all necessary data.
1645 + In this mode, aufs has to ignore the event which is fired by aufs
1647 +3. No Extra Validation
1648 + This is the simplest test and doesn't add any additional revalidation
1649 + test, and skip the revalidation in step 4. It is useful and improves
1650 + aufs performance when system surely hide the aufs branches from user,
1651 + by over-mounting something (or another method).
1652 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1653 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1654 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-03-21 14:49:05.713299677 +0100
1657 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1659 +# This program is free software; you can redistribute it and/or modify
1660 +# it under the terms of the GNU General Public License as published by
1661 +# the Free Software Foundation; either version 2 of the License, or
1662 +# (at your option) any later version.
1664 +# This program is distributed in the hope that it will be useful,
1665 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1666 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1667 +# GNU General Public License for more details.
1669 +# You should have received a copy of the GNU General Public License
1670 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1672 +Branch Manipulation
1674 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1675 +and changing its permission/attribute, there are a lot of works to do.
1679 +----------------------------------------------------------------------
1680 +o Confirm the adding dir exists outside of aufs, including loopback
1681 + mount, and its various attributes.
1682 +o Initialize the xino file and whiteout bases if necessary.
1685 +o Check the owner/group/mode of the directory
1686 + When the owner/group/mode of the adding directory differs from the
1687 + existing branch, aufs issues a warning because it may impose a
1689 + For example, when a upper writable branch has a world writable empty
1690 + top directory, a malicious user can create any files on the writable
1691 + branch directly, like copy-up and modify manually. If something like
1692 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1693 + writable branch, and the writable branch is world-writable, then a
1694 + malicious guy may create /etc/passwd on the writable branch directly
1695 + and the infected file will be valid in aufs.
1696 + I am afraid it can be a security issue, but aufs can do nothing except
1697 + producing a warning.
1701 +----------------------------------------------------------------------
1702 +o Confirm the deleting branch is not busy
1703 + To be general, there is one merit to adopt "remount" interface to
1704 + manipulate branches. It is to discard caches. At deleting a branch,
1705 + aufs checks the still cached (and connected) dentries and inodes. If
1706 + there are any, then they are all in-use. An inode without its
1707 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1709 + For the cached one, aufs checks whether the same named entry exists on
1711 + If the cached one is a directory, because aufs provides a merged view
1712 + to users, as long as one dir is left on any branch aufs can show the
1713 + dir to users. In this case, the branch can be removed from aufs.
1714 + Otherwise aufs rejects deleting the branch.
1716 + If any file on the deleting branch is opened by aufs, then aufs
1720 +Modify the Permission of a Branch
1721 +----------------------------------------------------------------------
1722 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1725 +o rw --> ro: Confirm the modifying branch is not busy
1726 + Aufs rejects the request if any of these conditions are true.
1727 + - a file on the branch is mmap-ed.
1728 + - a regular file on the branch is opened for write and there is no
1729 + same named entry on the upper branch.
1730 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1731 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1732 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-03-21 14:49:05.713299677 +0100
1735 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1737 +# This program is free software; you can redistribute it and/or modify
1738 +# it under the terms of the GNU General Public License as published by
1739 +# the Free Software Foundation; either version 2 of the License, or
1740 +# (at your option) any later version.
1742 +# This program is distributed in the hope that it will be useful,
1743 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1744 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1745 +# GNU General Public License for more details.
1747 +# You should have received a copy of the GNU General Public License
1748 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1750 +Policies to Select One among Multiple Writable Branches
1751 +----------------------------------------------------------------------
1752 +When the number of writable branch is more than one, aufs has to decide
1753 +the target branch for file creation or copy-up. By default, the highest
1754 +writable branch which has the parent (or ancestor) dir of the target
1755 +file is chosen (top-down-parent policy).
1756 +By user's request, aufs implements some other policies to select the
1757 +writable branch, for file creation several policies, round-robin,
1758 +most-free-space, and other policies. For copy-up, top-down-parent,
1759 +bottom-up-parent, bottom-up and others.
1761 +As expected, the round-robin policy selects the branch in circular. When
1762 +you have two writable branches and creates 10 new files, 5 files will be
1763 +created for each branch. mkdir(2) systemcall is an exception. When you
1764 +create 10 new directories, all will be created on the same branch.
1765 +And the most-free-space policy selects the one which has most free
1766 +space among the writable branches. The amount of free space will be
1767 +checked by aufs internally, and users can specify its time interval.
1769 +The policies for copy-up is more simple,
1770 +top-down-parent is equivalent to the same named on in create policy,
1771 +bottom-up-parent selects the writable branch where the parent dir
1772 +exists and the nearest upper one from the copyup-source,
1773 +bottom-up selects the nearest upper writable branch from the
1774 +copyup-source, regardless the existence of the parent dir.
1776 +There are some rules or exceptions to apply these policies.
1777 +- If there is a readonly branch above the policy-selected branch and
1778 + the parent dir is marked as opaque (a variation of whiteout), or the
1779 + target (creating) file is whiteout-ed on the upper readonly branch,
1780 + then the result of the policy is ignored and the target file will be
1781 + created on the nearest upper writable branch than the readonly branch.
1782 +- If there is a writable branch above the policy-selected branch and
1783 + the parent dir is marked as opaque or the target file is whiteouted
1784 + on the branch, then the result of the policy is ignored and the target
1785 + file will be created on the highest one among the upper writable
1786 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1788 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1789 + They try selecting the branch where the source exists as possible
1790 + since copyup a large file will take long time. If it can't be,
1791 + ie. the branch where the source exists is readonly, then they will
1792 + follow the copyup policy.
1793 +- There is an exception for rename(2) when the target exists.
1794 + If the rename target exists, aufs compares the index of the branches
1795 + where the source and the target exists and selects the higher
1796 + one. If the selected branch is readonly, then aufs follows the
1798 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1799 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1800 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-03-21 14:49:05.713299677 +0100
1803 +// to view this graph, run dot(1) command in GRAPHVIZ.
1807 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1811 +aufs_rename -> whinfo [label="store/remove"];
1814 +inode_list [label="h_inum list in branch\ncache"];
1817 +whinode [label="h_inum list file"];
1820 +brmgmt [label="br_add/del/mod/umount"];
1822 +brmgmt -> inode_list [label="create/remove"];
1823 +brmgmt -> whinode [label="load/store"];
1825 +inode_list -> whinode [style=dashed,dir=both];
1827 +aufs_rename -> inode_list [label="add/del"];
1829 +aufs_lookup -> inode_list [label="search"];
1831 +aufs_lookup -> whinfo [label="load/remove"];
1833 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1834 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1835 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-03-21 14:49:05.713299677 +0100
1838 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1840 +# This program is free software; you can redistribute it and/or modify
1841 +# it under the terms of the GNU General Public License as published by
1842 +# the Free Software Foundation; either version 2 of the License, or
1843 +# (at your option) any later version.
1845 +# This program is distributed in the hope that it will be useful,
1846 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1847 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1848 +# GNU General Public License for more details.
1850 +# You should have received a copy of the GNU General Public License
1851 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1853 +Special handling for renaming a directory (DIRREN)
1854 +----------------------------------------------------------------------
1855 +First, let's assume we have a simple usecase.
1859 +- /ro/dirA and /ro/dirA/file exist too
1860 +- there is no dirB on both branches
1861 +- a user issues rename("dirA", "dirB")
1863 +Now, what should aufs behave against this rename(2)?
1864 +There are a few possible cases.
1867 + since dirA exists on a readonly branch which cannot be renamed.
1869 + it is possible to copy-up dirA (only the dir itself), but the child
1870 + entries ("file" in this case) should not be. it must be a bad
1871 + approach to copy-up recursively.
1872 +C. returns a success.
1873 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1874 + is a violation of aufs' policy.
1875 +D. construct an extra information which indicates that /ro/dirA should
1876 + be handled as the name of dirB.
1877 + overlayfs has a similar feature called REDIRECT.
1879 +Until now, aufs implements the case B only which returns EXDEV, and
1880 +expects the userspace application behaves like mv(1) which tries
1881 +issueing rename(2) recursively.
1883 +A new aufs feature called DIRREN is introduced which implements the case
1884 +D. There are several "extra information" added.
1886 +1. detailed info per renamed directory
1887 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1888 +2. the inode-number list of directories on a branch
1889 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1891 +The filename of "detailed info per directory" represents the lower
1892 +branch, and its format is
1893 +- a type of the branch id
1895 + + uuid (not implemented yet)
1898 +- the inode-number of the branch root dir
1900 +And it contains these info in a single regular file.
1902 +- branch's inode-number of the logically renamed dir
1903 +- the name of the before-renamed dir
1905 +The "detailed info per directory" file is created in aufs rename(2), and
1906 +loaded in any lookup.
1907 +The info is considered in lookup for the matching case only. Here
1908 +"matching" means that the root of branch (in the info filename) is same
1909 +to the current looking-up branch. After looking-up the before-renamed
1910 +name, the inode-number is compared. And the matched dentry is used.
1912 +The "inode-number list of directories" is a regular file which contains
1913 +simply the inode-numbers on the branch. The file is created or updated
1914 +in removing the branch, and loaded in adding the branch. Its lifetime is
1915 +equal to the branch.
1916 +The list is refered in lookup, and when the current target inode is
1917 +found in the list, the aufs tries loading the "detailed info per
1918 +directory" and get the changed and valid name of the dir.
1920 +Theoretically these "extra informaiton" may be able to be put into XATTR
1921 +in the dir inode. But aufs doesn't choose this way because
1922 +1. XATTR may not be supported by the branch (or its configuration)
1923 +2. XATTR may have its size limit.
1924 +3. XATTR may be less easy to convert than a regular file, when the
1925 + format of the info is changed in the future.
1926 +At the same time, I agree that the regular file approach is much slower
1927 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1930 +This DIRREN feature is enabled by aufs configuration, and is activated
1931 +by a new mount option.
1933 +For the more complicated case, there is a work with UDBA option, which
1934 +is to dected the direct access to the branches (by-passing aufs) and to
1935 +maintain the cashes in aufs. Since a single cached aufs dentry may
1936 +contains two names, before- and after-rename, the name comparision in
1937 +UDBA handler may not work correctly. In this case, the behaviour will be
1938 +equivalen to udba=reval case.
1939 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1940 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1941 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-03-21 14:49:05.716633010 +0100
1944 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1946 +# This program is free software; you can redistribute it and/or modify
1947 +# it under the terms of the GNU General Public License as published by
1948 +# the Free Software Foundation; either version 2 of the License, or
1949 +# (at your option) any later version.
1951 +# This program is distributed in the hope that it will be useful,
1952 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1953 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1954 +# GNU General Public License for more details.
1956 +# You should have received a copy of the GNU General Public License
1957 +# along with this program; if not, write to the Free Software
1958 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1961 +File-based Hierarchical Storage Management (FHSM)
1962 +----------------------------------------------------------------------
1963 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1964 +storage world. Aufs provides this feature as file-based with multiple
1965 +writable branches, based upon the principle of "Colder, the Lower".
1966 +Here the word "colder" means that the less used files, and "lower" means
1967 +that the position in the order of the stacked branches vertically.
1968 +These multiple writable branches are prioritized, ie. the topmost one
1969 +should be the fastest drive and be used heavily.
1971 +o Characters in aufs FHSM story
1972 +- aufs itself and a new branch attribute.
1973 +- a new ioctl interface to move-down and to establish a connection with
1974 + the daemon ("move-down" is a converse of "copy-up").
1975 +- userspace tool and daemon.
1977 +The userspace daemon establishes a connection with aufs and waits for
1978 +the notification. The notified information is very similar to struct
1979 +statfs containing the number of consumed blocks and inodes.
1980 +When the consumed blocks/inodes of a branch exceeds the user-specified
1981 +upper watermark, the daemon activates its move-down process until the
1982 +consumed blocks/inodes reaches the user-specified lower watermark.
1984 +The actual move-down is done by aufs based upon the request from
1985 +user-space since we need to maintain the inode number and the internal
1986 +pointer arrays in aufs.
1988 +Currently aufs FHSM handles the regular files only. Additionally they
1989 +must not be hard-linked nor pseudo-linked.
1992 +o Cowork of aufs and the user-space daemon
1993 + During the userspace daemon established the connection, aufs sends a
1994 + small notification to it whenever aufs writes something into the
1995 + writable branch. But it may cost high since aufs issues statfs(2)
1996 + internally. So user can specify a new option to cache the
1997 + info. Actually the notification is controlled by these factors.
1998 + + the specified cache time.
1999 + + classified as "force" by aufs internally.
2000 + Until the specified time expires, aufs doesn't send the info
2001 + except the forced cases. When aufs decide forcing, the info is always
2002 + notified to userspace.
2003 + For example, the number of free inodes is generally large enough and
2004 + the shortage of it happens rarely. So aufs doesn't force the
2005 + notification when creating a new file, directory and others. This is
2006 + the typical case which aufs doesn't force.
2007 + When aufs writes the actual filedata and the files consumes any of new
2008 + blocks, the aufs forces notifying.
2011 +o Interfaces in aufs
2012 +- New branch attribute.
2014 + Specifies that the branch is managed by FHSM feature. In other word,
2015 + participant in the FHSM.
2016 + When nofhsm is set to the branch, it will not be the source/target
2017 + branch of the move-down operation. This attribute is set
2018 + independently from coo and moo attributes, and if you want full
2019 + FHSM, you should specify them as well.
2020 +- New mount option.
2022 + Specifies a second to suppress many less important info to be
2025 + + AUFS_CTL_FHSM_FD
2026 + create a new file descriptor which userspace can read the notification
2027 + (a subset of struct statfs) from aufs.
2028 +- Module parameter 'brs'
2029 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2031 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2032 + When there are two or more branches with fhsm attributes,
2033 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2034 + terminates it. As a result of remounting and branch-manipulation, the
2035 + number of branches with fhsm attribute can be one. In this case,
2036 + /sbin/mount.aufs will terminate the user-space daemon.
2039 +Finally the operation is done as these steps in kernel-space.
2041 + + no one else is using the file.
2042 + + the file is not hard-linked.
2043 + + the file is not pseudo-linked.
2044 + + the file is a regular file.
2045 + + the parent dir is not opaqued.
2046 +- find the target writable branch.
2047 +- make sure the file is not whiteout-ed by the upper (than the target)
2049 +- make the parent dir on the target branch.
2050 +- mutex lock the inode on the branch.
2051 +- unlink the whiteout on the target branch (if exists).
2052 +- lookup and create the whiteout-ed temporary name on the target branch.
2053 +- copy the file as the whiteout-ed temporary name on the target branch.
2054 +- rename the whiteout-ed temporary name to the original name.
2055 +- unlink the file on the source branch.
2056 +- maintain the internal pointer array and the external inode number
2058 +- maintain the timestamps and other attributes of the parent dir and the
2061 +And of course, in every step, an error may happen. So the operation
2062 +should restore the original file state after an error happens.
2063 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2064 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2065 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-03-21 14:49:05.716633010 +0100
2068 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2070 +# This program is free software; you can redistribute it and/or modify
2071 +# it under the terms of the GNU General Public License as published by
2072 +# the Free Software Foundation; either version 2 of the License, or
2073 +# (at your option) any later version.
2075 +# This program is distributed in the hope that it will be useful,
2076 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2077 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2078 +# GNU General Public License for more details.
2080 +# You should have received a copy of the GNU General Public License
2081 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2083 +mmap(2) -- File Memory Mapping
2084 +----------------------------------------------------------------------
2085 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2086 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2088 +This approach is simple and good, but there is one problem.
2089 +Under /proc, several entries show the mmapped files by its path (with
2090 +device and inode number), and the printed path will be the path on the
2091 +branch fs's instead of virtual aufs's.
2092 +This is not a problem in most cases, but some utilities lsof(1) (and its
2093 +user) may expect the path on aufs.
2095 +To address this issue, aufs adds a new member called vm_prfile in struct
2096 +vm_area_struct (and struct vm_region). The original vm_file points to
2097 +the file on the branch fs in order to handle everything correctly as
2098 +usual. The new vm_prfile points to a virtual file in aufs, and the
2099 +show-functions in procfs refers to vm_prfile if it is set.
2100 +Also we need to maintain several other places where touching vm_file
2102 +- fork()/clone() copies vma and the reference count of vm_file is
2104 +- merging vma maintains the ref count too.
2106 +This is not a good approach. It just fakes the printed path. But it
2107 +leaves all behaviour around f_mapping unchanged. This is surely an
2109 +Actually aufs had adopted another complicated approach which calls
2110 +generic_file_mmap() and handles struct vm_operations_struct. In this
2111 +approach, aufs met a hard problem and I could not solve it without
2112 +switching the approach.
2114 +There may be one more another approach which is
2115 +- bind-mount the branch-root onto the aufs-root internally
2116 +- grab the new vfsmount (ie. struct mount)
2117 +- lazy-umount the branch-root internally
2118 +- in open(2) the aufs-file, open the branch-file with the hidden
2119 + vfsmount (instead of the original branch's vfsmount)
2120 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2121 + but it may be possible from userspace by the mount helper.
2123 +Adding the internal hidden vfsmount and using it in opening a file, the
2124 +file path under /proc will be printed correctly. This approach looks
2125 +smarter, but is not possible I am afraid.
2126 +- aufs-root may be bind-mount later. when it happens, another hidden
2127 + vfsmount will be required.
2128 +- it is hard to get the chance to bind-mount and lazy-umount
2129 + + in kernel-space, FS can have vfsmount in open(2) via
2130 + file->f_path, and aufs can know its vfsmount. But several locks are
2131 + already acquired, and if aufs tries to bind-mount and lazy-umount
2132 + here, then it may cause a deadlock.
2133 + + in user-space, bind-mount doesn't invoke the mount helper.
2134 +- since /proc shows dev and ino, aufs has to give vma these info. it
2135 + means a new member vm_prinode will be necessary. this is essentially
2136 + equivalent to vm_prfile described above.
2138 +I have to give up this "looks-smater" approach.
2139 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2140 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2141 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-03-21 14:49:05.716633010 +0100
2144 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2146 +# This program is free software; you can redistribute it and/or modify
2147 +# it under the terms of the GNU General Public License as published by
2148 +# the Free Software Foundation; either version 2 of the License, or
2149 +# (at your option) any later version.
2151 +# This program is distributed in the hope that it will be useful,
2152 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2153 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2154 +# GNU General Public License for more details.
2156 +# You should have received a copy of the GNU General Public License
2157 +# along with this program; if not, write to the Free Software
2158 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2161 +Listing XATTR/EA and getting the value
2162 +----------------------------------------------------------------------
2163 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2164 +shows the values from the topmost existing file. This behaviour is good
2165 +for the non-dir entries since the bahaviour exactly matches the shown
2166 +information. But for the directories, aufs considers all the same named
2167 +entries on the lower branches. Which means, if one of the lower entry
2168 +rejects readdir call, then aufs returns an error even if the topmost
2169 +entry allows it. This behaviour is necessary to respect the branch fs's
2170 +security, but can make users confused since the user-visible standard
2171 +attributes don't match the behaviour.
2172 +To address this issue, aufs has a mount option called dirperm1 which
2173 +checks the permission for the topmost entry only, and ignores the lower
2174 +entry's permission.
2176 +A similar issue can happen around XATTR.
2177 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2178 +always set. Otherwise these very unpleasant situation would happen.
2179 +- listxattr(2) may return the duplicated entries.
2180 +- users may not be able to remove or reset the XATTR forever,
2183 +XATTR/EA support in the internal (copy,move)-(up,down)
2184 +----------------------------------------------------------------------
2185 +Generally the extended attributes of inode are categorized as these.
2186 +- "security" for LSM and capability.
2187 +- "system" for posix ACL, 'acl' mount option is required for the branch
2189 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2190 +- "user" for userspace, 'user_xattr' mount option is required for the
2191 + branch fs generally.
2193 +Moreover there are some other categories. Aufs handles these rather
2194 +unpopular categories as the ordinary ones, ie. there is no special
2195 +condition nor exception.
2197 +In copy-up, the support for XATTR on the dst branch may differ from the
2198 +src branch. In this case, the copy-up operation will get an error and
2199 +the original user operation which triggered the copy-up will fail. It
2200 +can happen that even all copy-up will fail.
2201 +When both of src and dst branches support XATTR and if an error occurs
2202 +during copying XATTR, then the copy-up should fail obviously. That is a
2203 +good reason and aufs should return an error to userspace. But when only
2204 +the src branch support that XATTR, aufs should not return an error.
2205 +For example, the src branch supports ACL but the dst branch doesn't
2206 +because the dst branch may natively un-support it or temporary
2207 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2208 +may NOT return an error even if the XATTR is not supported. It is
2209 +totally up to the branch fs.
2211 +Anyway when the aufs internal copy-up gets an error from the dst branch
2212 +fs, then aufs tries removing the just copied entry and returns the error
2213 +to the userspace. The worst case of this situation will be all copy-up
2216 +For the copy-up operation, there two basic approaches.
2217 +- copy the specified XATTR only (by category above), and return the
2218 + error unconditionally if it happens.
2219 +- copy all XATTR, and ignore the error on the specified category only.
2221 +In order to support XATTR and to implement the correct behaviour, aufs
2222 +chooses the latter approach and introduces some new branch attributes,
2223 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2224 +They correspond to the XATTR namespaces (see above). Additionally, to be
2225 +convenient, "icex" is also provided which means all "icex*" attributes
2226 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2228 +The meaning of these attributes is to ignore the error from setting
2229 +XATTR on that branch.
2230 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2231 +error from the dst branch according to the specified attributes.
2233 +Some XATTR may have its default value. The default value may come from
2234 +the parent dir or the environment. If the default value is set at the
2235 +file creating-time, it will be overwritten by copy-up.
2236 +Some contradiction may happen I am afraid.
2237 +Do we need another attribute to stop copying XATTR? I am unsure. For
2238 +now, aufs implements the branch attributes to ignore the error.
2239 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2240 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2241 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-03-21 14:49:05.716633010 +0100
2244 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2246 +# This program is free software; you can redistribute it and/or modify
2247 +# it under the terms of the GNU General Public License as published by
2248 +# the Free Software Foundation; either version 2 of the License, or
2249 +# (at your option) any later version.
2251 +# This program is distributed in the hope that it will be useful,
2252 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2253 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2254 +# GNU General Public License for more details.
2256 +# You should have received a copy of the GNU General Public License
2257 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2259 +Export Aufs via NFS
2260 +----------------------------------------------------------------------
2261 +Here is an approach.
2262 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2264 +- iget_locked(): initialize aufs inode generation for a new inode, and
2265 + store it in xigen file.
2266 +- destroy_inode(): increment aufs inode generation and store it in xigen
2267 + file. it is necessary even if it is not unlinked, because any data of
2268 + inode may be changed by UDBA.
2269 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2270 + build file handle by
2271 + + branch id (4 bytes)
2272 + + superblock generation (4 bytes)
2273 + + inode number (4 or 8 bytes)
2274 + + parent dir inode number (4 or 8 bytes)
2275 + + inode generation (4 bytes))
2276 + + return value of exportfs_encode_fh() for the parent on a branch (4
2278 + + file handle for a branch (by exportfs_encode_fh())
2280 + + find the index of a branch from its id in handle, and check it is
2281 + still exist in aufs.
2282 + + 1st level: get the inode number from handle and search it in cache.
2283 + + 2nd level: if not found in cache, get the parent inode number from
2284 + the handle and search it in cache. and then open the found parent
2285 + dir, find the matching inode number by vfs_readdir() and get its
2286 + name, and call lookup_one_len() for the target dentry.
2287 + + 3rd level: if the parent dir is not cached, call
2288 + exportfs_decode_fh() for a branch and get the parent on a branch,
2289 + build a pathname of it, convert it a pathname in aufs, call
2290 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2292 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2293 + for every branch, but not itself. to get this, (currently) aufs
2294 + searches in current->nsproxy->mnt_ns list. it may not be a good
2295 + idea, but I didn't get other approach.
2296 + + test the generation of the gotten inode.
2297 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2298 + convert it into ESTALE for NFSD.
2299 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2300 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2301 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2302 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2303 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-03-21 14:49:05.716633010 +0100
2306 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2308 +# This program is free software; you can redistribute it and/or modify
2309 +# it under the terms of the GNU General Public License as published by
2310 +# the Free Software Foundation; either version 2 of the License, or
2311 +# (at your option) any later version.
2313 +# This program is distributed in the hope that it will be useful,
2314 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2315 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2316 +# GNU General Public License for more details.
2318 +# You should have received a copy of the GNU General Public License
2319 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2321 +Show Whiteout Mode (shwh)
2322 +----------------------------------------------------------------------
2323 +Generally aufs hides the name of whiteouts. But in some cases, to show
2324 +them is very useful for users. For instance, creating a new middle layer
2325 +(branch) by merging existing layers.
2327 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2328 +When you have three branches,
2329 +- Bottom: 'system', squashfs (underlying base system), read-only
2330 +- Middle: 'mods', squashfs, read-only
2331 +- Top: 'overlay', ram (tmpfs), read-write
2333 +The top layer is loaded at boot time and saved at shutdown, to preserve
2334 +the changes made to the system during the session.
2335 +When larger changes have been made, or smaller changes have accumulated,
2336 +the size of the saved top layer data grows. At this point, it would be
2337 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2338 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2339 +restoring save and load speed.
2341 +This merging is simplified by the use of another aufs mount, of just the
2342 +two overlay branches using the 'shwh' option.
2343 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2344 + aufs /livesys/merge_union
2346 +A merged view of these two branches is then available at
2347 +/livesys/merge_union, and the new feature is that the whiteouts are
2349 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2350 +writing to all branches. Also the default mode for all branches is 'ro'.
2351 +It is now possible to save the combined contents of the two overlay
2352 +branches to a new squashfs, e.g.:
2353 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2355 +This new squashfs archive can be stored on the boot device and the
2356 +initramfs will use it to replace the old one at the next boot.
2357 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2358 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2359 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-03-21 14:49:05.716633010 +0100
2362 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2364 +# This program is free software; you can redistribute it and/or modify
2365 +# it under the terms of the GNU General Public License as published by
2366 +# the Free Software Foundation; either version 2 of the License, or
2367 +# (at your option) any later version.
2369 +# This program is distributed in the hope that it will be useful,
2370 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2371 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2372 +# GNU General Public License for more details.
2374 +# You should have received a copy of the GNU General Public License
2375 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2377 +Dynamically customizable FS operations
2378 +----------------------------------------------------------------------
2379 +Generally FS operations (struct inode_operations, struct
2380 +address_space_operations, struct file_operations, etc.) are defined as
2381 +"static const", but it never means that FS have only one set of
2382 +operation. Some FS have multiple sets of them. For instance, ext2 has
2383 +three sets, one for XIP, for NOBH, and for normal.
2384 +Since aufs overrides and redirects these operations, sometimes aufs has
2385 +to change its behaviour according to the branch FS type. More importantly
2386 +VFS acts differently if a function (member in the struct) is set or
2387 +not. It means aufs should have several sets of operations and select one
2388 +among them according to the branch FS definition.
2390 +In order to solve this problem and not to affect the behaviour of VFS,
2391 +aufs defines these operations dynamically. For instance, aufs defines
2392 +dummy direct_IO function for struct address_space_operations, but it may
2393 +not be set to the address_space_operations actually. When the branch FS
2394 +doesn't have it, aufs doesn't set it to its address_space_operations
2395 +while the function definition itself is still alive. So the behaviour
2396 +itself will not change, and it will return an error when direct_IO is
2399 +The lifetime of these dynamically generated operation object is
2400 +maintained by aufs branch object. When the branch is removed from aufs,
2401 +the reference counter of the object is decremented. When it reaches
2402 +zero, the dynamically generated operation object will be freed.
2404 +This approach is designed to support AIO (io_submit), Direct I/O and
2406 +Currently this approach is applied to address_space_operations for
2407 +regular files only.
2408 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2409 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2410 +++ linux/Documentation/filesystems/aufs/README 2022-03-21 14:49:05.713299677 +0100
2413 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2419 +----------------------------------------
2420 +In the early days, aufs was entirely re-designed and re-implemented
2421 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2422 +improvements and implementations, it became totally different from
2423 +Unionfs while keeping the basic features.
2424 +Later, Unionfs Version 2.x series began taking some of the same
2425 +approaches to aufs1's.
2426 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2427 +University and his team.
2429 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2431 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2432 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2433 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2434 + or aufs1 from CVS on SourceForge.
2436 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2437 + According to Christoph Hellwig, linux rejects all union-type
2438 + filesystems but UnionMount.
2439 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2441 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2442 + UnionMount, and he pointed out an issue around a directory mutex
2443 + lock and aufs addressed it. But it is still unsure whether aufs will
2444 + be merged (or any other union solution).
2445 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2449 +----------------------------------------
2450 +- unite several directories into a single virtual filesystem. The member
2451 + directory is called as a branch.
2452 +- you can specify the permission flags to the branch, which are 'readonly',
2453 + 'readwrite' and 'whiteout-able.'
2454 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2455 + readonly branch are modifiable logically.
2456 +- dynamic branch manipulation, add, del.
2459 +Also there are many enhancements in aufs, such as:
2460 +- test only the highest one for the directory permission (dirperm1)
2461 +- copyup on open (coo=)
2462 +- 'move' policy for copy-up between two writable branches, after
2463 + checking free space.
2465 +- readdir(3) in userspace.
2466 +- keep inode number by external inode number table
2467 +- keep the timestamps of file/dir in internal copyup operation
2468 +- seekable directory, supporting NFS readdir.
2469 +- whiteout is hardlinked in order to reduce the consumption of inodes
2471 +- do not copyup, nor create a whiteout when it is unnecessary
2472 +- revert a single systemcall when an error occurs in aufs
2473 +- remount interface instead of ioctl
2474 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2475 +- loopback mounted filesystem as a branch
2476 +- kernel thread for removing the dir who has a plenty of whiteouts
2477 +- support copyup sparse file (a file which has a 'hole' in it)
2478 +- default permission flags for branches
2479 +- selectable permission flags for ro branch, whether whiteout can
2482 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2483 +- support multiple writable branches, some policies to select one
2484 + among multiple writable branches.
2485 +- a new semantics for link(2) and rename(2) to support multiple
2486 + writable branches.
2487 +- no glibc changes are required.
2488 +- pseudo hardlink (hardlink over branches)
2489 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2490 + including NFS or remote filesystem branch.
2491 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2494 +Currently these features are dropped temporary from aufs5.
2495 +See design/08plan.txt in detail.
2496 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2498 +- statistics of aufs thread (/sys/fs/aufs/stat)
2500 +Features or just an idea in the future (see also design/*.txt),
2501 +- reorder the branch index without del/re-add.
2502 +- permanent xino files for NFSD
2503 +- an option for refreshing the opened files after add/del branches
2504 +- light version, without branch manipulation. (unnecessary?)
2505 +- copyup in userspace
2506 +- inotify in userspace
2511 +----------------------------------------
2512 +There are three GIT trees for aufs5, aufs5-linux.git,
2513 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2515 +While the aufs-util is always necessary, you need either of aufs5-linux
2516 +or aufs5-standalone.
2518 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2519 +git://git.kernel.org/.../torvalds/linux.git.
2520 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2521 +build aufs5 as an external kernel module.
2522 +Several extra patches are not included in this tree. Only
2523 +aufs5-standalone tree contains them. They are described in the later
2524 +section "Configuration and Compilation."
2526 +On the other hand, the aufs5-standalone tree has only aufs source files
2527 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2528 +But you need to apply all aufs patches manually.
2530 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2531 +represents the linux kernel version, "linux-5.x". For instance,
2532 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2533 +"aufs5.x-rcN" branch.
2536 +$ git clone --reference /your/linux/git/tree \
2537 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2538 +- if you don't have linux GIT tree, then remove "--reference ..."
2539 +$ cd aufs5-linux.git
2540 +$ git checkout origin/aufs5.0
2542 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2543 +leave the patch-work to GIT.
2544 +$ cd /your/linux/git/tree
2545 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2547 +$ git checkout -b my5.0 v5.0
2548 +$ (add your local change...)
2549 +$ git pull aufs5 aufs5.0
2550 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2551 +- you may need to solve some conflicts between your_changes and
2552 + aufs5.0. in this case, git-rerere is recommended so that you can
2553 + solve the similar conflicts automatically when you upgrade to 5.1 or
2554 + later in the future.
2556 +o aufs5-standalone tree
2557 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2558 +$ cd aufs5-standalone.git
2559 +$ git checkout origin/aufs5.0
2562 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2563 +- note that the public aufs-util.git is on SourceForge instead of
2566 +$ git checkout origin/aufs5.0
2568 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2569 +The minor version number, 'x' in '5.x', of aufs may not always
2570 +follow the minor version number of the kernel.
2571 +Because changes in the kernel that cause the use of a new
2572 +minor version number do not always require changes to aufs-util.
2574 +Since aufs-util has its own minor version number, you may not be
2575 +able to find a GIT branch in aufs-util for your kernel's
2576 +exact minor version number.
2577 +In this case, you should git-checkout the branch for the
2578 +nearest lower number.
2580 +For (an unreleased) example:
2581 +If you are using "linux-5.10" and the "aufs5.10" branch
2582 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2583 +or something numerically smaller is the branch for your kernel.
2585 +Also you can view all branches by
2589 +3. Configuration and Compilation
2590 +----------------------------------------
2591 +Make sure you have git-checkout'ed the correct branch.
2593 +For aufs5-linux tree,
2594 +- enable CONFIG_AUFS_FS.
2595 +- set other aufs configurations if necessary.
2596 +- for aufs5.13 and later
2597 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2598 + also a caller of VFS functions for branch filesystems, subclassing of
2599 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2600 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2601 + need to customize some LOCKDEP numbers. Here are what I use on my
2603 + CONFIG_LOCKDEP_BITS=21
2604 + CONFIG_LOCKDEP_CHAINS_BITS=21
2605 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2607 +For aufs5-standalone tree,
2608 +There are several ways to build.
2611 +- apply ./aufs5-kbuild.patch to your kernel source files.
2612 +- apply ./aufs5-base.patch too.
2613 +- apply ./aufs5-mmap.patch too.
2614 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2615 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2616 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2617 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2618 +- enable CONFIG_AUFS_FS, you can select either
2620 +- and build your kernel as usual.
2621 +- install the built kernel.
2622 +- install the header files too by "make headers_install" to the
2623 + directory where you specify. By default, it is $PWD/usr.
2624 + "make help" shows a brief note for headers_install.
2625 +- and reboot your system.
2628 +- module only (CONFIG_AUFS_FS=m).
2629 +- apply ./aufs5-base.patch to your kernel source files.
2630 +- apply ./aufs5-mmap.patch too.
2631 +- apply ./aufs5-standalone.patch too.
2632 +- build your kernel, don't forget "make headers_install", and reboot.
2633 +- edit ./config.mk and set other aufs configurations if necessary.
2634 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2635 + every aufs configurations.
2636 +- build the module by simple "make".
2637 +- you can specify ${KDIR} make variable which points to your kernel
2639 +- install the files
2640 + + run "make install" to install the aufs module, or copy the built
2641 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2642 + + run "make install_headers" (instead of headers_install) to install
2643 + the modified aufs header file (you can specify DESTDIR which is
2644 + available in aufs standalone version's Makefile only), or copy
2645 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2646 + you like manually. By default, the target directory is $PWD/usr.
2647 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2648 + kernel source tree.
2650 +Note: The header file aufs_type.h is necessary to build aufs-util
2651 + as well as "make headers_install" in the kernel source tree.
2652 + headers_install is subject to be forgotten, but it is essentially
2653 + necessary, not only for building aufs-util.
2654 + You may not meet problems without headers_install in some older
2658 +- read README in aufs-util, build and install it
2659 +- note that your distribution may contain an obsoleted version of
2660 + aufs_type.h in /usr/include/linux or something. When you build aufs
2661 + utilities, make sure that your compiler refers the correct aufs header
2662 + file which is built by "make headers_install."
2663 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2664 + then run "make install_ulib" too. And refer to the aufs manual in
2667 +There several other patches in aufs5-standalone.git. They are all
2668 +optional. When you meet some problems, they will help you.
2669 +- aufs5-loopback.patch
2670 + Supports a nested loopback mount in a branch-fs. This patch is
2671 + unnecessary until aufs produces a message like "you may want to try
2672 + another patch for loopback file".
2674 + Modifies a system global kernel internal function get_next_ino() in
2675 + order to stop assigning 0 for an inode-number. Not directly related to
2676 + aufs, but recommended generally.
2678 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2679 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2680 + duplication of inode number, which is important for backup tools and
2681 + other utilities. When you find aufs XINO files for tmpfs branch
2682 + growing too much, try this patch.
2686 +----------------------------------------
2687 +At first, make sure aufs-util are installed, and please read the aufs
2688 +manual, aufs.5 in aufs-util.git tree.
2692 +$ mkdir /tmp/rw /tmp/aufs
2693 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2695 +Here is another example. The result is equivalent.
2696 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2698 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2699 +# mount -o remount,append:${HOME} /tmp/aufs
2701 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2702 +you modify a file under /tmp/aufs, the one on your home directory is
2703 +not affected, instead the same named file will be newly created under
2704 +/tmp/rw. And all of your modification to a file will be applied to
2705 +the one under /tmp/rw. This is called the file based Copy on Write
2707 +Aufs mount options are described in aufs.5.
2708 +If you run chroot or something and make your aufs as a root directory,
2709 +then you need to customize the shutdown script. See the aufs manual in
2712 +Additionally, there are some sample usages of aufs which are a
2713 +diskless system with network booting, and LiveCD over NFS.
2714 +See sample dir in CVS tree on SourceForge.
2718 +----------------------------------------
2719 +When you have any problems or strange behaviour in aufs, please let me
2721 +- /proc/mounts (instead of the output of mount(8))
2722 +- /sys/module/aufs/*
2723 +- /sys/fs/aufs/* (if you have them)
2724 +- /debug/aufs/* (if you have them)
2725 +- linux kernel version
2726 + if your kernel is not plain, for example modified by distributor,
2727 + the url where i can download its source is necessary too.
2728 +- aufs version which was printed at loading the module or booting the
2729 + system, instead of the date you downloaded.
2730 +- configuration (define/undefine CONFIG_AUFS_xxx)
2731 +- kernel configuration or /proc/config.gz (if you have it)
2732 +- LSM (linux security module, if you are using)
2733 +- behaviour which you think to be incorrect
2734 +- actual operation, reproducible one is better
2735 +- mailto: aufs-users at lists.sourceforge.net
2737 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2738 +and Feature Requests) on SourceForge. Please join and write to
2742 +6. Acknowledgements
2743 +----------------------------------------
2744 +Thanks to everyone who have tried and are using aufs, whoever
2745 +have reported a bug or any feedback.
2747 +Especially donators:
2748 +Tomas Matejicek(slax.org) made a donation (much more than once).
2749 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2750 + scripts) is making "doubling" donations.
2751 + Unfortunately I cannot list all of the donators, but I really
2753 + It ends Aug 2010, but the ordinary donation URL is still available.
2754 + <http://sourceforge.net/donate/index.php?group_id=167503>
2755 +Dai Itasaka made a donation (2007/8).
2756 +Chuck Smith made a donation (2008/4, 10 and 12).
2757 +Henk Schoneveld made a donation (2008/9).
2758 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2759 +Francois Dupoux made a donation (2008/11).
2760 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2761 + aufs2 GIT tree (2009/2).
2762 +William Grant made a donation (2009/3).
2763 +Patrick Lane made a donation (2009/4).
2764 +The Mail Archive (mail-archive.com) made donations (2009/5).
2765 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2766 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2767 +Pavel Pronskiy made a donation (2011/2).
2768 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2769 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2770 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2772 +Sam Liddicott made a donation (2011/9).
2773 +Era Scarecrow made a donation (2013/4).
2774 +Bor Ratajc made a donation (2013/4).
2775 +Alessandro Gorreta made a donation (2013/4).
2776 +POIRETTE Marc made a donation (2013/4).
2777 +Alessandro Gorreta made a donation (2013/4).
2778 +lauri kasvandik made a donation (2013/5).
2779 +"pemasu from Finland" made a donation (2013/7).
2780 +The Parted Magic Project made a donation (2013/9 and 11).
2781 +Pavel Barta made a donation (2013/10).
2782 +Nikolay Pertsev made a donation (2014/5).
2783 +James B made a donation (2014/7, 2015/7, and 2021/12).
2784 +Stefano Di Biase made a donation (2014/8).
2785 +Daniel Epellei made a donation (2015/1).
2786 +OmegaPhil made a donation (2016/1, 2018/4).
2787 +Tomasz Szewczyk made a donation (2016/4).
2788 +James Burry made a donation (2016/12).
2789 +Carsten Rose made a donation (2018/9).
2790 +Porteus Kiosk made a donation (2018/10).
2792 +Thank you very much.
2793 +Donations are always, including future donations, very important and
2794 +helpful for me to keep on developing aufs.
2798 +----------------------------------------
2799 +If you are an experienced user, no explanation is needed. Aufs is
2800 +just a linux filesystem.
2805 +# Local variables: ;
2808 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2809 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2810 +++ linux/fs/aufs/aufs.h 2022-03-21 14:49:05.716633010 +0100
2812 +/* SPDX-License-Identifier: GPL-2.0 */
2814 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2816 + * This program, aufs is free software; you can redistribute it and/or modify
2817 + * it under the terms of the GNU General Public License as published by
2818 + * the Free Software Foundation; either version 2 of the License, or
2819 + * (at your option) any later version.
2821 + * This program is distributed in the hope that it will be useful,
2822 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2823 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2824 + * GNU General Public License for more details.
2826 + * You should have received a copy of the GNU General Public License
2827 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2831 + * all header files
2839 +#define AuStub(type, name, body, ...) \
2840 + static inline type name(__VA_ARGS__) { body; }
2842 +#define AuStubVoid(name, ...) \
2843 + AuStub(void, name, , __VA_ARGS__)
2844 +#define AuStubInt0(name, ...) \
2845 + AuStub(int, name, return 0, __VA_ARGS__)
2849 +#include "branch.h"
2852 +#include "dbgaufs.h"
2853 +#include "dentry.h"
2855 +#include "dirren.h"
2858 +#include "fstype.h"
2863 +#include "module.h"
2867 +#include "sysaufs.h"
2872 +#endif /* __KERNEL__ */
2873 +#endif /* __AUFS_H__ */
2874 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2875 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2876 +++ linux/fs/aufs/branch.c 2022-03-21 14:49:05.719966344 +0100
2878 +// SPDX-License-Identifier: GPL-2.0
2880 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2882 + * This program, aufs is free software; you can redistribute it and/or modify
2883 + * it under the terms of the GNU General Public License as published by
2884 + * the Free Software Foundation; either version 2 of the License, or
2885 + * (at your option) any later version.
2887 + * This program is distributed in the hope that it will be useful,
2888 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2889 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2890 + * GNU General Public License for more details.
2892 + * You should have received a copy of the GNU General Public License
2893 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2897 + * branch management
2900 +#include <linux/compat.h>
2901 +#include <linux/statfs.h>
2905 + * free a single branch
2907 +static void au_br_do_free(struct au_branch *br)
2910 + struct au_wbr *wbr;
2911 + struct au_dykey **key;
2913 + au_hnotify_fin_br(br);
2914 + /* always, regardless the mount option */
2915 + au_dr_hino_free(&br->br_dirren);
2918 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2919 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2920 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2921 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2925 + for (i = 0; i < AuBrWh_Last; i++)
2926 + dput(wbr->wbr_wh[i]);
2927 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2928 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2931 + if (br->br_fhsm) {
2932 + au_br_fhsm_fin(br->br_fhsm);
2933 + au_kfree_try_rcu(br->br_fhsm);
2936 + key = br->br_dykey;
2937 + for (i = 0; i < AuBrDynOp; i++, key++)
2943 + /* recursive lock, s_umount of branch's */
2944 + /* synchronize_rcu(); */ /* why? */
2946 + path_put(&br->br_path);
2948 + au_kfree_rcu(wbr);
2949 + au_lcnt_wait_for_fin(&br->br_nfiles);
2950 + au_lcnt_wait_for_fin(&br->br_count);
2951 + /* I don't know why, but percpu_refcount requires this */
2952 + /* synchronize_rcu(); */
2957 + * frees all branches
2959 +void au_br_free(struct au_sbinfo *sbinfo)
2961 + aufs_bindex_t bmax;
2962 + struct au_branch **br;
2964 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2966 + bmax = sbinfo->si_bbot + 1;
2967 + br = sbinfo->si_branch;
2969 + au_br_do_free(*br++);
2973 + * find the index of a branch which is specified by @br_id.
2975 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2977 + aufs_bindex_t bindex, bbot;
2979 + bbot = au_sbbot(sb);
2980 + for (bindex = 0; bindex <= bbot; bindex++)
2981 + if (au_sbr_id(sb, bindex) == br_id)
2986 +/* ---------------------------------------------------------------------- */
2992 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2993 + struct dentry *h_root)
2995 + if (unlikely(h_adding == h_root
2996 + || au_test_loopback_overlap(sb, h_adding)))
2998 + if (h_adding->d_sb != h_root->d_sb)
3000 + return au_test_subdir(h_adding, h_root)
3001 + || au_test_subdir(h_root, h_adding);
3005 + * returns a newly allocated branch. @new_nbranch is a number of branches
3006 + * after adding a branch.
3008 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3011 + struct au_branch *add_branch;
3012 + struct dentry *root;
3013 + struct inode *inode;
3017 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3018 + if (unlikely(!add_branch))
3020 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3021 + if (unlikely(!add_branch->br_xino))
3023 + err = au_hnotify_init_br(add_branch, perm);
3024 + if (unlikely(err))
3027 + if (au_br_writable(perm)) {
3028 + /* may be freed separately at changing the branch permission */
3029 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3031 + if (unlikely(!add_branch->br_wbr))
3035 + if (au_br_fhsm(perm)) {
3036 + err = au_fhsm_br_alloc(add_branch);
3037 + if (unlikely(err))
3041 + root = sb->s_root;
3042 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3044 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3046 + inode = d_inode(root);
3047 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3051 + return add_branch; /* success */
3054 + au_kfree_rcu(add_branch->br_wbr);
3056 + au_hnotify_fin_br(add_branch);
3058 + au_xino_put(add_branch);
3060 + au_kfree_rcu(add_branch);
3062 + return ERR_PTR(err);
3066 + * test if the branch permission is legal or not.
3068 +static int test_br(struct inode *inode, int brperm, char *path)
3072 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3077 + pr_err("write permission for readonly mount or inode, %s\n", path);
3085 + * 0: success, the caller will add it
3086 + * plus: success, it is already unified, the caller should ignore it
3089 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3092 + aufs_bindex_t bbot, bindex;
3093 + struct dentry *root, *h_dentry;
3094 + struct inode *inode, *h_inode;
3096 + root = sb->s_root;
3097 + bbot = au_sbbot(sb);
3098 + if (unlikely(bbot >= 0
3099 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3103 + pr_err("%s duplicated\n", add->pathname);
3108 + err = -ENOSPC; /* -E2BIG; */
3109 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3110 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3111 + pr_err("number of branches exceeded %s\n", add->pathname);
3116 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3117 + pr_err("bad index %d\n", add->bindex);
3121 + inode = d_inode(add->path.dentry);
3123 + if (unlikely(!inode->i_nlink)) {
3124 + pr_err("no existence %s\n", add->pathname);
3129 + if (unlikely(inode->i_sb == sb)) {
3130 + pr_err("%s must be outside\n", add->pathname);
3134 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3135 + pr_err("unsupported filesystem, %s (%s)\n",
3136 + add->pathname, au_sbtype(inode->i_sb));
3140 + if (unlikely(inode->i_sb->s_stack_depth)) {
3141 + pr_err("already stacked, %s (%s)\n",
3142 + add->pathname, au_sbtype(inode->i_sb));
3146 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3147 + if (unlikely(err))
3151 + return 0; /* success */
3154 + for (bindex = 0; bindex <= bbot; bindex++)
3155 + if (unlikely(test_overlap(sb, add->path.dentry,
3156 + au_h_dptr(root, bindex)))) {
3157 + pr_err("%s is overlapped\n", add->pathname);
3162 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3163 + h_dentry = au_h_dptr(root, 0);
3164 + h_inode = d_inode(h_dentry);
3165 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3166 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3167 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3168 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3170 + i_uid_read(inode), i_gid_read(inode),
3171 + (inode->i_mode & S_IALLUGO),
3172 + i_uid_read(h_inode), i_gid_read(h_inode),
3173 + (h_inode->i_mode & S_IALLUGO));
3181 + * initialize or clean the whiteouts for an adding branch
3183 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3186 + int err, old_perm;
3187 + aufs_bindex_t bindex;
3188 + struct inode *h_inode;
3189 + struct au_wbr *wbr;
3190 + struct au_hinode *hdir;
3191 + struct dentry *h_dentry;
3193 + err = vfsub_mnt_want_write(au_br_mnt(br));
3194 + if (unlikely(err))
3198 + old_perm = br->br_perm;
3199 + br->br_perm = new_perm;
3202 + bindex = au_br_index(sb, br->br_id);
3203 + if (0 <= bindex) {
3204 + hdir = au_hi(d_inode(sb->s_root), bindex);
3205 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3207 + h_dentry = au_br_dentry(br);
3208 + h_inode = d_inode(h_dentry);
3209 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3212 + err = au_wh_init(br, sb);
3214 + wbr_wh_write_lock(wbr);
3215 + err = au_wh_init(br, sb);
3216 + wbr_wh_write_unlock(wbr);
3219 + au_hn_inode_unlock(hdir);
3221 + inode_unlock(h_inode);
3222 + vfsub_mnt_drop_write(au_br_mnt(br));
3223 + br->br_perm = old_perm;
3225 + if (!err && wbr && !au_br_writable(new_perm)) {
3226 + au_kfree_rcu(wbr);
3227 + br->br_wbr = NULL;
3234 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3238 + struct kstatfs kst;
3239 + struct au_wbr *wbr;
3242 + au_rw_init(&wbr->wbr_wh_rwsem);
3243 + atomic_set(&wbr->wbr_wh_running, 0);
3246 + * a limit for rmdir/rename a dir
3247 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3249 + err = vfs_statfs(&br->br_path, &kst);
3250 + if (unlikely(err))
3253 + if (kst.f_namelen >= NAME_MAX)
3254 + err = au_br_init_wh(sb, br, perm);
3256 + pr_err("%pd(%s), unsupported namelen %ld\n",
3258 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3264 +/* initialize a new branch */
3265 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3266 + struct au_opt_add *add)
3269 + struct au_branch *brbase;
3271 + struct inode *h_inode;
3274 + br->br_perm = add->perm;
3275 + br->br_path = add->path; /* set first, path_get() later */
3276 + spin_lock_init(&br->br_dykey_lock);
3277 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3278 + au_lcnt_init(&br->br_count, /*release*/NULL);
3279 + br->br_id = au_new_br_id(sb);
3280 + AuDebugOn(br->br_id < 0);
3282 + /* always, regardless the given option */
3283 + err = au_dr_br_init(sb, br, &add->path);
3284 + if (unlikely(err))
3287 + if (au_br_writable(add->perm)) {
3288 + err = au_wbr_init(br, sb, add->perm);
3289 + if (unlikely(err))
3293 + if (au_opt_test(au_mntflags(sb), XINO)) {
3294 + brbase = au_sbr(sb, 0);
3295 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3297 + h_inode = d_inode(add->path.dentry);
3298 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3299 + if (unlikely(err)) {
3300 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3305 + sysaufs_br_init(br);
3306 + path_get(&br->br_path);
3307 + goto out; /* success */
3310 + memset(&br->br_path, 0, sizeof(br->br_path));
3315 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3316 + struct au_branch *br, aufs_bindex_t bbot,
3317 + aufs_bindex_t amount)
3319 + struct au_branch **brp;
3321 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3323 + brp = sbinfo->si_branch + bindex;
3324 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3326 + sbinfo->si_bbot++;
3327 + if (unlikely(bbot < 0))
3328 + sbinfo->si_bbot = 0;
3331 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3332 + aufs_bindex_t bbot, aufs_bindex_t amount)
3334 + struct au_hdentry *hdp;
3336 + AuRwMustWriteLock(&dinfo->di_rwsem);
3338 + hdp = au_hdentry(dinfo, bindex);
3339 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3340 + au_h_dentry_init(hdp);
3342 + if (unlikely(bbot < 0))
3343 + dinfo->di_btop = 0;
3346 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3347 + aufs_bindex_t bbot, aufs_bindex_t amount)
3349 + struct au_hinode *hip;
3351 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3353 + hip = au_hinode(iinfo, bindex);
3354 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3355 + au_hinode_init(hip);
3357 + if (unlikely(bbot < 0))
3358 + iinfo->ii_btop = 0;
3361 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3362 + aufs_bindex_t bindex)
3364 + struct dentry *root, *h_dentry;
3365 + struct inode *root_inode, *h_inode;
3366 + aufs_bindex_t bbot, amount;
3368 + root = sb->s_root;
3369 + root_inode = d_inode(root);
3370 + bbot = au_sbbot(sb);
3371 + amount = bbot + 1 - bindex;
3372 + h_dentry = au_br_dentry(br);
3373 + au_sbilist_lock();
3374 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3375 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3376 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3377 + au_set_h_dptr(root, bindex, dget(h_dentry));
3378 + h_inode = d_inode(h_dentry);
3379 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3380 + au_sbilist_unlock();
3383 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3386 + aufs_bindex_t bbot, add_bindex;
3387 + struct dentry *root, *h_dentry;
3388 + struct inode *root_inode;
3389 + struct au_branch *add_branch;
3391 + root = sb->s_root;
3392 + root_inode = d_inode(root);
3393 + IMustLock(root_inode);
3394 + IiMustWriteLock(root_inode);
3395 + err = test_add(sb, add, remount);
3396 + if (unlikely(err < 0))
3400 + goto out; /* success */
3403 + bbot = au_sbbot(sb);
3404 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3405 + err = PTR_ERR(add_branch);
3406 + if (IS_ERR(add_branch))
3409 + err = au_br_init(add_branch, sb, add);
3410 + if (unlikely(err)) {
3411 + au_br_do_free(add_branch);
3415 + add_bindex = add->bindex;
3416 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3417 + au_br_do_add(sb, add_branch, add_bindex);
3418 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3419 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3421 + h_dentry = add->path.dentry;
3422 + if (!add_bindex) {
3423 + au_cpup_attr_all(root_inode, /*force*/1);
3424 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3426 + au_add_nlink(root_inode, d_inode(h_dentry));
3432 +/* ---------------------------------------------------------------------- */
3434 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3435 + unsigned long long max __maybe_unused,
3438 + unsigned long long n;
3439 + struct file **p, *f;
3440 + struct hlist_bl_head *files;
3441 + struct hlist_bl_node *pos;
3442 + struct au_finfo *finfo;
3446 + files = &au_sbi(sb)->si_files;
3447 + hlist_bl_lock(files);
3448 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3449 + f = finfo->fi_file;
3451 + && !special_file(file_inode(f)->i_mode)) {
3455 + AuDebugOn(n > max);
3458 + hlist_bl_unlock(files);
3463 +static struct file **au_farray_alloc(struct super_block *sb,
3464 + unsigned long long *max)
3466 + struct au_sbinfo *sbi;
3469 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3470 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3473 +static void au_farray_free(struct file **a, unsigned long long max)
3475 + unsigned long long ull;
3477 + for (ull = 0; ull < max; ull++)
3483 +/* ---------------------------------------------------------------------- */
3489 +/* to show the line number, do not make it inlined function */
3490 +#define AuVerbose(do_info, fmt, ...) do { \
3492 + pr_info(fmt, ##__VA_ARGS__); \
3495 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3496 + aufs_bindex_t bbot)
3498 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3501 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3502 + aufs_bindex_t bbot)
3504 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3508 + * test if the branch is deletable or not.
3510 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3511 + unsigned int sigen, const unsigned int verbose)
3513 + int err, i, j, ndentry;
3514 + aufs_bindex_t btop, bbot;
3515 + struct au_dcsub_pages dpages;
3516 + struct au_dpage *dpage;
3519 + err = au_dpages_init(&dpages, GFP_NOFS);
3520 + if (unlikely(err))
3522 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3523 + if (unlikely(err))
3526 + for (i = 0; !err && i < dpages.ndpage; i++) {
3527 + dpage = dpages.dpages + i;
3528 + ndentry = dpage->ndentry;
3529 + for (j = 0; !err && j < ndentry; j++) {
3530 + d = dpage->dentries[j];
3531 + AuDebugOn(au_dcount(d) <= 0);
3532 + if (!au_digen_test(d, sigen)) {
3533 + di_read_lock_child(d, AuLock_IR);
3534 + if (unlikely(au_dbrange_test(d))) {
3535 + di_read_unlock(d, AuLock_IR);
3539 + di_write_lock_child(d);
3540 + if (unlikely(au_dbrange_test(d))) {
3541 + di_write_unlock(d);
3544 + err = au_reval_dpath(d, sigen);
3546 + di_downgrade_lock(d, AuLock_IR);
3548 + di_write_unlock(d);
3553 + /* AuDbgDentry(d); */
3554 + btop = au_dbtop(d);
3555 + bbot = au_dbbot(d);
3556 + if (btop <= bindex
3558 + && au_h_dptr(d, bindex)
3559 + && au_test_dbusy(d, btop, bbot)) {
3561 + AuVerbose(verbose, "busy %pd\n", d);
3564 + di_read_unlock(d, AuLock_IR);
3569 + au_dpages_free(&dpages);
3574 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3575 + unsigned int sigen, const unsigned int verbose)
3578 + unsigned long long max, ull;
3579 + struct inode *i, **array;
3580 + aufs_bindex_t btop, bbot;
3582 + array = au_iarray_alloc(sb, &max);
3583 + err = PTR_ERR(array);
3584 + if (IS_ERR(array))
3588 + AuDbg("b%d\n", bindex);
3589 + for (ull = 0; !err && ull < max; ull++) {
3593 + if (i->i_ino == AUFS_ROOT_INO)
3596 + /* AuDbgInode(i); */
3597 + if (au_iigen(i, NULL) == sigen)
3598 + ii_read_lock_child(i);
3600 + ii_write_lock_child(i);
3601 + err = au_refresh_hinode_self(i);
3604 + ii_downgrade_lock(i);
3606 + ii_write_unlock(i);
3611 + btop = au_ibtop(i);
3612 + bbot = au_ibbot(i);
3613 + if (btop <= bindex
3615 + && au_h_iptr(i, bindex)
3616 + && au_test_ibusy(i, btop, bbot)) {
3618 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3621 + ii_read_unlock(i);
3623 + au_iarray_free(array, max);
3629 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3630 + const unsigned int verbose)
3633 + unsigned int sigen;
3635 + sigen = au_sigen(root->d_sb);
3636 + DiMustNoWaiters(root);
3637 + IiMustNoWaiters(d_inode(root));
3638 + di_write_unlock(root);
3639 + err = test_dentry_busy(root, bindex, sigen, verbose);
3641 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3642 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3647 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3648 + struct file **to_free, int *idx)
3651 + unsigned char matched, root;
3652 + aufs_bindex_t bindex, bbot;
3653 + struct au_fidir *fidir;
3654 + struct au_hfile *hfile;
3657 + root = IS_ROOT(file->f_path.dentry);
3660 + to_free[*idx] = file;
3666 + fidir = au_fi(file)->fi_hdir;
3667 + AuDebugOn(!fidir);
3668 + bbot = au_fbbot_dir(file);
3669 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3670 + hfile = fidir->fd_hfile + bindex;
3671 + if (!hfile->hf_file)
3674 + if (hfile->hf_br->br_id == br_id) {
3686 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3687 + struct file **to_free, int opened)
3690 + unsigned long long ull, max;
3691 + aufs_bindex_t btop;
3692 + struct file *file, **array;
3693 + struct dentry *root;
3694 + struct au_hfile *hfile;
3696 + array = au_farray_alloc(sb, &max);
3697 + err = PTR_ERR(array);
3698 + if (IS_ERR(array))
3703 + root = sb->s_root;
3704 + di_write_unlock(root);
3705 + for (ull = 0; ull < max; ull++) {
3706 + file = array[ull];
3707 + if (unlikely(!file))
3710 + /* AuDbg("%pD\n", file); */
3711 + fi_read_lock(file);
3712 + btop = au_fbtop(file);
3713 + if (!d_is_dir(file->f_path.dentry)) {
3714 + hfile = &au_fi(file)->fi_htop;
3715 + if (hfile->hf_br->br_id == br_id)
3718 + err = test_dir_busy(file, br_id, to_free, &idx);
3719 + fi_read_unlock(file);
3720 + if (unlikely(err))
3723 + di_write_lock_child(root);
3724 + au_farray_free(array, max);
3725 + AuDebugOn(idx > opened);
3731 +static void br_del_file(struct file **to_free, unsigned long long opened,
3732 + aufs_bindex_t br_id)
3734 + unsigned long long ull;
3735 + aufs_bindex_t bindex, btop, bbot, bfound;
3736 + struct file *file;
3737 + struct au_fidir *fidir;
3738 + struct au_hfile *hfile;
3740 + for (ull = 0; ull < opened; ull++) {
3741 + file = to_free[ull];
3742 + if (unlikely(!file))
3745 + /* AuDbg("%pD\n", file); */
3746 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3748 + fidir = au_fi(file)->fi_hdir;
3749 + AuDebugOn(!fidir);
3750 + fi_write_lock(file);
3751 + btop = au_fbtop(file);
3752 + bbot = au_fbbot_dir(file);
3753 + for (bindex = btop; bindex <= bbot; bindex++) {
3754 + hfile = fidir->fd_hfile + bindex;
3755 + if (!hfile->hf_file)
3758 + if (hfile->hf_br->br_id == br_id) {
3763 + AuDebugOn(bfound < 0);
3764 + au_set_h_fptr(file, bfound, NULL);
3765 + if (bfound == btop) {
3766 + for (btop++; btop <= bbot; btop++)
3767 + if (au_hf_dir(file, btop)) {
3768 + au_set_fbtop(file, btop);
3772 + fi_write_unlock(file);
3776 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3777 + const aufs_bindex_t bindex,
3778 + const aufs_bindex_t bbot)
3780 + struct au_branch **brp, **p;
3782 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3784 + brp = sbinfo->si_branch + bindex;
3785 + if (bindex < bbot)
3786 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3787 + sbinfo->si_branch[0 + bbot] = NULL;
3788 + sbinfo->si_bbot--;
3790 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3793 + sbinfo->si_branch = p;
3794 + /* harmless error */
3797 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3798 + const aufs_bindex_t bbot)
3800 + struct au_hdentry *hdp, *p;
3802 + AuRwMustWriteLock(&dinfo->di_rwsem);
3804 + hdp = au_hdentry(dinfo, bindex);
3805 + if (bindex < bbot)
3806 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3807 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3810 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3813 + dinfo->di_hdentry = p;
3814 + /* harmless error */
3817 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3818 + const aufs_bindex_t bbot)
3820 + struct au_hinode *hip, *p;
3822 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3824 + hip = au_hinode(iinfo, bindex);
3825 + if (bindex < bbot)
3826 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3827 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3830 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3833 + iinfo->ii_hinode = p;
3834 + /* harmless error */
3837 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3838 + struct au_branch *br)
3840 + aufs_bindex_t bbot;
3841 + struct au_sbinfo *sbinfo;
3842 + struct dentry *root, *h_root;
3843 + struct inode *inode, *h_inode;
3844 + struct au_hinode *hinode;
3846 + SiMustWriteLock(sb);
3848 + root = sb->s_root;
3849 + inode = d_inode(root);
3850 + sbinfo = au_sbi(sb);
3851 + bbot = sbinfo->si_bbot;
3853 + h_root = au_h_dptr(root, bindex);
3854 + hinode = au_hi(inode, bindex);
3855 + h_inode = au_igrab(hinode->hi_inode);
3858 + au_sbilist_lock();
3859 + au_br_do_del_brp(sbinfo, bindex, bbot);
3860 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3861 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3862 + au_sbilist_unlock();
3864 + /* ignore an error */
3865 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3869 + au_br_do_free(br);
3872 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3873 + unsigned long long max, void *arg)
3878 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3881 + unsigned long long opened;
3882 + unsigned int mnt_flags;
3883 + aufs_bindex_t bindex, bbot, br_id;
3884 + unsigned char do_wh, verbose;
3885 + struct au_branch *br;
3886 + struct au_wbr *wbr;
3887 + struct dentry *root;
3888 + struct file **to_free;
3893 + root = sb->s_root;
3894 + bindex = au_find_dbindex(root, del->h_path.dentry);
3897 + goto out; /* success */
3899 + pr_err("%s no such branch\n", del->pathname);
3902 + AuDbg("bindex b%d\n", bindex);
3905 + mnt_flags = au_mntflags(sb);
3906 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3907 + bbot = au_sbbot(sb);
3908 + if (unlikely(!bbot)) {
3909 + AuVerbose(verbose, "no more branches left\n");
3913 + br = au_sbr(sb, bindex);
3914 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3915 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3916 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3920 + br_id = br->br_id;
3921 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3922 + if (unlikely(opened)) {
3923 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3924 + err = PTR_ERR(to_free);
3925 + if (IS_ERR(to_free))
3928 + err = test_file_busy(sb, br_id, to_free, opened);
3929 + if (unlikely(err)) {
3930 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3936 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3938 + /* instead of WbrWhMustWriteLock(wbr) */
3939 + SiMustWriteLock(sb);
3940 + for (i = 0; i < AuBrWh_Last; i++) {
3941 + dput(wbr->wbr_wh[i]);
3942 + wbr->wbr_wh[i] = NULL;
3946 + err = test_children_busy(root, bindex, verbose);
3947 + if (unlikely(err)) {
3956 + * now we confirmed the branch is deletable.
3957 + * let's free the remaining opened dirs on the branch.
3959 + di_write_unlock(root);
3960 + br_del_file(to_free, opened, br_id);
3961 + di_write_lock_child(root);
3964 + sysaufs_brs_del(sb, bindex); /* remove successors */
3965 + dbgaufs_xino_del(br); /* remove one */
3966 + au_br_do_del(sb, bindex, br);
3967 + sysaufs_brs_add(sb, bindex); /* append successors */
3968 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3971 + au_cpup_attr_all(d_inode(root), /*force*/1);
3972 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3974 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3975 + if (au_opt_test(mnt_flags, PLINK))
3976 + au_plink_half_refresh(sb, br_id);
3978 + goto out; /* success */
3982 + rerr = au_br_init_wh(sb, br, br->br_perm);
3984 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3985 + del->pathname, rerr);
3988 + au_farray_free(to_free, opened);
3992 +/* ---------------------------------------------------------------------- */
3994 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3997 + aufs_bindex_t btop, bbot;
3998 + struct aufs_ibusy ibusy;
3999 + struct inode *inode, *h_inode;
4002 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4005 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4007 + /* VERIFY_WRITE */
4008 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4009 + if (unlikely(err)) {
4016 + si_read_lock(sb, AuLock_FLUSH);
4017 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4021 + ibusy.h_ino = 0; /* invalid */
4022 + inode = ilookup(sb, ibusy.ino);
4024 + || inode->i_ino == AUFS_ROOT_INO
4025 + || au_is_bad_inode(inode))
4028 + ii_read_lock_child(inode);
4029 + btop = au_ibtop(inode);
4030 + bbot = au_ibbot(inode);
4031 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4032 + h_inode = au_h_iptr(inode, ibusy.bindex);
4033 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4034 + ibusy.h_ino = h_inode->i_ino;
4036 + ii_read_unlock(inode);
4040 + si_read_unlock(sb);
4042 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4043 + if (unlikely(err)) {
4052 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4054 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4057 +#ifdef CONFIG_COMPAT
4058 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4060 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4064 +/* ---------------------------------------------------------------------- */
4067 + * change a branch permission
4070 +static void au_warn_ima(void)
4073 + /* since it doesn't support mark_files_ro() */
4074 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4078 +static int do_need_sigen_inc(int a, int b)
4080 + return au_br_whable(a) && !au_br_whable(b);
4083 +static int need_sigen_inc(int old, int new)
4085 + return do_need_sigen_inc(old, new)
4086 + || do_need_sigen_inc(new, old);
4089 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4092 + unsigned int mnt_flags;
4093 + unsigned long long ull, max;
4094 + aufs_bindex_t br_id;
4095 + unsigned char verbose, writer;
4096 + struct file *file, *hf, **array;
4097 + struct au_hfile *hfile;
4098 + struct inode *h_inode;
4100 + mnt_flags = au_mntflags(sb);
4101 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4103 + array = au_farray_alloc(sb, &max);
4104 + err = PTR_ERR(array);
4105 + if (IS_ERR(array))
4109 + br_id = au_sbr_id(sb, bindex);
4110 + for (ull = 0; ull < max; ull++) {
4111 + file = array[ull];
4112 + if (unlikely(!file))
4115 + /* AuDbg("%pD\n", file); */
4116 + fi_read_lock(file);
4117 + if (unlikely(au_test_mmapped(file))) {
4119 + AuVerbose(verbose, "mmapped %pD\n", file);
4121 + FiMustNoWaiters(file);
4122 + fi_read_unlock(file);
4126 + hfile = &au_fi(file)->fi_htop;
4127 + hf = hfile->hf_file;
4128 + if (!d_is_reg(file->f_path.dentry)
4129 + || !(file->f_mode & FMODE_WRITE)
4130 + || hfile->hf_br->br_id != br_id
4131 + || !(hf->f_mode & FMODE_WRITE))
4132 + array[ull] = NULL;
4138 + FiMustNoWaiters(file);
4139 + fi_read_unlock(file);
4147 + for (ull = 0; ull < max; ull++) {
4148 + file = array[ull];
4152 + /* todo: already flushed? */
4154 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4155 + * approach which resets f_mode and calls mnt_drop_write() and
4156 + * file_release_write() for each file, because the branch
4157 + * attribute in aufs world is totally different from the native
4160 + /* fi_read_lock(file); */
4161 + hfile = &au_fi(file)->fi_htop;
4162 + hf = hfile->hf_file;
4163 + /* fi_read_unlock(file); */
4164 + spin_lock(&hf->f_lock);
4165 + writer = !!(hf->f_mode & FMODE_WRITER);
4166 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4167 + spin_unlock(&hf->f_lock);
4169 + h_inode = file_inode(hf);
4170 + if (hf->f_mode & FMODE_READ)
4171 + i_readcount_inc(h_inode);
4172 + put_write_access(h_inode);
4173 + __mnt_drop_write(hf->f_path.mnt);
4178 + au_farray_free(array, max);
4184 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4188 + aufs_bindex_t bindex;
4189 + struct dentry *root;
4190 + struct au_branch *br;
4191 + struct au_br_fhsm *bf;
4193 + root = sb->s_root;
4194 + bindex = au_find_dbindex(root, mod->h_root);
4197 + return 0; /* success */
4199 + pr_err("%s no such branch\n", mod->path);
4202 + AuDbg("bindex b%d\n", bindex);
4204 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4205 + if (unlikely(err))
4208 + br = au_sbr(sb, bindex);
4209 + AuDebugOn(mod->h_root != au_br_dentry(br));
4210 + if (br->br_perm == mod->perm)
4211 + return 0; /* success */
4213 + /* pre-allocate for non-fhsm --> fhsm */
4215 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4216 + err = au_fhsm_br_alloc(br);
4217 + if (unlikely(err))
4220 + br->br_fhsm = NULL;
4223 + if (au_br_writable(br->br_perm)) {
4224 + /* remove whiteout base */
4225 + err = au_br_init_wh(sb, br, mod->perm);
4226 + if (unlikely(err))
4229 + if (!au_br_writable(mod->perm)) {
4230 + /* rw --> ro, file might be mmapped */
4231 + DiMustNoWaiters(root);
4232 + IiMustNoWaiters(d_inode(root));
4233 + di_write_unlock(root);
4234 + err = au_br_mod_files_ro(sb, bindex);
4235 + /* aufs_write_lock() calls ..._child() */
4236 + di_write_lock_child(root);
4238 + if (unlikely(err)) {
4240 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4243 + rerr = au_wbr_init(br, sb, br->br_perm);
4244 + if (unlikely(rerr)) {
4245 + AuIOErr("nested error %d (%d)\n",
4247 + br->br_perm = mod->perm;
4251 + } else if (au_br_writable(mod->perm)) {
4254 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4256 + err = au_wbr_init(br, sb, mod->perm);
4257 + if (unlikely(err)) {
4258 + au_kfree_rcu(br->br_wbr);
4259 + br->br_wbr = NULL;
4263 + if (unlikely(err))
4266 + if (au_br_fhsm(br->br_perm)) {
4267 + if (!au_br_fhsm(mod->perm)) {
4268 + /* fhsm --> non-fhsm */
4269 + au_br_fhsm_fin(br->br_fhsm);
4270 + au_kfree_rcu(br->br_fhsm);
4271 + br->br_fhsm = NULL;
4273 + } else if (au_br_fhsm(mod->perm))
4274 + /* non-fhsm --> fhsm */
4277 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4278 + br->br_perm = mod->perm;
4279 + goto out; /* success */
4282 + au_kfree_try_rcu(bf);
4288 +/* ---------------------------------------------------------------------- */
4290 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4293 + struct kstatfs kstfs;
4295 + err = vfs_statfs(&br->br_path, &kstfs);
4297 + stfs->f_blocks = kstfs.f_blocks;
4298 + stfs->f_bavail = kstfs.f_bavail;
4299 + stfs->f_files = kstfs.f_files;
4300 + stfs->f_ffree = kstfs.f_ffree;
4305 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4306 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4307 +++ linux/fs/aufs/branch.h 2022-03-21 14:49:05.719966344 +0100
4309 +/* SPDX-License-Identifier: GPL-2.0 */
4311 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4313 + * This program, aufs is free software; you can redistribute it and/or modify
4314 + * it under the terms of the GNU General Public License as published by
4315 + * the Free Software Foundation; either version 2 of the License, or
4316 + * (at your option) any later version.
4318 + * This program is distributed in the hope that it will be useful,
4319 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4320 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4321 + * GNU General Public License for more details.
4323 + * You should have received a copy of the GNU General Public License
4324 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4328 + * branch filesystems and xino for them
4331 +#ifndef __AUFS_BRANCH_H__
4332 +#define __AUFS_BRANCH_H__
4336 +#include <linux/mount.h>
4337 +#include "dirren.h"
4343 +/* ---------------------------------------------------------------------- */
4347 + struct file **xi_file;
4348 + unsigned int xi_nfile;
4354 + /* reserved for future use */
4355 + /* unsigned long *bitmap; */
4356 + wait_queue_head_t wqh;
4359 + struct mutex xi_mtx; /* protects xi_file array */
4360 + struct hlist_bl_head xi_writing;
4362 + atomic_t xi_truncating;
4364 + struct kref xi_kref;
4367 +/* File-based Hierarchical Storage Management */
4368 +struct au_br_fhsm {
4369 +#ifdef CONFIG_AUFS_FHSM
4370 + struct mutex bf_lock;
4371 + unsigned long bf_jiffy;
4372 + struct aufs_stfs bf_stfs;
4377 +/* members for writable branch only */
4378 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4380 + struct au_rwsem wbr_wh_rwsem;
4381 + struct dentry *wbr_wh[AuBrWh_Last];
4382 + atomic_t wbr_wh_running;
4383 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4384 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4385 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4388 + unsigned long long wbr_bytes;
4391 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4392 +#define AuBrDynOp (AuDyLast * 4)
4394 +#ifdef CONFIG_AUFS_HFSNOTIFY
4395 +/* support for asynchronous destruction */
4396 +struct au_br_hfsnotify {
4397 + struct fsnotify_group *hfsn_group;
4401 +/* sysfs entries */
4402 +struct au_brsysfs {
4404 + struct attribute attr;
4413 +/* protected by superblock rwsem */
4415 + struct au_xino *br_xino;
4417 + aufs_bindex_t br_id;
4420 + struct path br_path;
4421 + spinlock_t br_dykey_lock;
4422 + struct au_dykey *br_dykey[AuBrDynOp];
4423 + au_lcnt_t br_nfiles; /* opened files */
4424 + au_lcnt_t br_count; /* in-use for other */
4426 + struct au_wbr *br_wbr;
4427 + struct au_br_fhsm *br_fhsm;
4429 +#ifdef CONFIG_AUFS_HFSNOTIFY
4430 + struct au_br_hfsnotify *br_hfsn;
4433 +#ifdef CONFIG_SYSFS
4434 + /* entries under sysfs per mount-point */
4435 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4438 +#ifdef CONFIG_DEBUG_FS
4439 + struct dentry *br_dbgaufs; /* xino */
4442 + struct au_dr_br br_dirren;
4445 +/* ---------------------------------------------------------------------- */
4447 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4449 + return br->br_path.mnt;
4452 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4454 + return br->br_path.dentry;
4457 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4459 + return mnt_user_ns(br->br_path.mnt);
4462 +static inline struct super_block *au_br_sb(struct au_branch *br)
4464 + return au_br_mnt(br)->mnt_sb;
4467 +static inline int au_br_rdonly(struct au_branch *br)
4469 + return (sb_rdonly(au_br_sb(br))
4470 + || !au_br_writable(br->br_perm))
4474 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4476 +#ifdef CONFIG_AUFS_HNOTIFY
4477 + return !(brperm & AuBrPerm_RR);
4483 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4485 + int err, exec_flag;
4488 + exec_flag = oflag & __FMODE_EXEC;
4489 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4495 +static inline void au_xino_get(struct au_branch *br)
4497 + struct au_xino *xi;
4501 + kref_get(&xi->xi_kref);
4504 +static inline int au_xino_count(struct au_branch *br)
4507 + struct au_xino *xi;
4512 + v = kref_read(&xi->xi_kref);
4517 +/* ---------------------------------------------------------------------- */
4521 +void au_br_free(struct au_sbinfo *sinfo);
4522 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4524 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4526 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4527 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4528 +#ifdef CONFIG_COMPAT
4529 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4532 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4535 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4538 +static const loff_t au_loff_max = LLONG_MAX;
4540 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4541 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4543 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4544 + struct file *copy_src);
4546 + struct au_xino *xi; /* switch between xino and xigen */
4548 + struct path *base;
4549 + struct file *copy_src;
4551 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4553 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4555 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4557 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4558 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4560 +int au_xib_trunc(struct super_block *sb);
4561 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4563 +struct au_xino *au_xino_alloc(unsigned int nfile);
4564 +int au_xino_put(struct au_branch *br);
4565 +struct file *au_xino_file1(struct au_xino *xi);
4567 +struct au_opt_xino;
4568 +void au_xino_clr(struct super_block *sb);
4569 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4570 +struct file *au_xino_def(struct super_block *sb);
4571 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4572 + struct path *base);
4574 +ino_t au_xino_new_ino(struct super_block *sb);
4575 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4577 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4578 + ino_t h_ino, int idx);
4579 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4582 +int au_xino_path(struct seq_file *seq, struct file *file);
4584 +/* ---------------------------------------------------------------------- */
4586 +/* @idx is signed to accept -1 meaning the first file */
4587 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4589 + struct file *file;
4596 + if (idx < xi->xi_nfile)
4597 + file = xi->xi_file[idx];
4599 + file = au_xino_file1(xi);
4605 +/* ---------------------------------------------------------------------- */
4607 +/* Superblock to branch */
4609 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4611 + return au_sbr(sb, bindex)->br_id;
4615 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4617 + return au_br_mnt(au_sbr(sb, bindex));
4621 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4623 + return au_br_userns(au_sbr(sb, bindex));
4627 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4629 + return au_br_sb(au_sbr(sb, bindex));
4632 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4634 + return au_sbr(sb, bindex)->br_perm;
4637 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4639 + return au_br_whable(au_sbr_perm(sb, bindex));
4642 +/* ---------------------------------------------------------------------- */
4644 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4645 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4646 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4647 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4649 +#define wbr_wh_read_trylock_nested(wbr) \
4650 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4651 +#define wbr_wh_write_trylock_nested(wbr) \
4652 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4655 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4656 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4657 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4659 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4660 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4661 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4663 +/* ---------------------------------------------------------------------- */
4665 +#ifdef CONFIG_AUFS_FHSM
4666 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4668 + mutex_init(&brfhsm->bf_lock);
4669 + brfhsm->bf_jiffy = 0;
4670 + brfhsm->bf_readable = 0;
4673 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4675 + mutex_destroy(&brfhsm->bf_lock);
4678 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4679 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4682 +#endif /* __KERNEL__ */
4683 +#endif /* __AUFS_BRANCH_H__ */
4684 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4685 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4686 +++ linux/fs/aufs/conf.mk 2022-03-21 14:49:05.719966344 +0100
4688 +# SPDX-License-Identifier: GPL-2.0
4690 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4694 +AuConfStr += ${1}=${${1}}
4698 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4700 + HNOTIFY HFSNOTIFY \
4712 +$(foreach i, ${AuConfAll}, \
4713 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4715 +AuConfName = ${obj}/conf.str
4716 +${AuConfName}.tmp: FORCE
4717 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4718 +${AuConfName}: ${AuConfName}.tmp
4719 + @diff -q $< $@ > /dev/null 2>&1 || { \
4720 + echo ' GEN ' $@; \
4724 +clean-files += ${AuConfName} ${AuConfName}.tmp
4725 +${obj}/sysfs.o: ${AuConfName}
4727 +-include ${srctree}/${src}/conf_priv.mk
4728 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4729 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4730 +++ linux/fs/aufs/cpup.c 2022-03-21 14:49:05.719966344 +0100
4732 +// SPDX-License-Identifier: GPL-2.0
4734 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4736 + * This program, aufs is free software; you can redistribute it and/or modify
4737 + * it under the terms of the GNU General Public License as published by
4738 + * the Free Software Foundation; either version 2 of the License, or
4739 + * (at your option) any later version.
4741 + * This program is distributed in the hope that it will be useful,
4742 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4743 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4744 + * GNU General Public License for more details.
4746 + * You should have received a copy of the GNU General Public License
4747 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4751 + * copy-up functions, see wbr_policy.c for copy-down
4754 +#include <linux/fs_stack.h>
4755 +#include <linux/mm.h>
4756 +#include <linux/task_work.h>
4759 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4761 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4762 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4764 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4766 + dst->i_flags |= iflags & ~mask;
4767 + if (au_test_fs_notime(dst->i_sb))
4768 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4771 +void au_cpup_attr_timesizes(struct inode *inode)
4773 + struct inode *h_inode;
4775 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4776 + fsstack_copy_attr_times(inode, h_inode);
4777 + fsstack_copy_inode_size(inode, h_inode);
4780 +void au_cpup_attr_nlink(struct inode *inode, int force)
4782 + struct inode *h_inode;
4783 + struct super_block *sb;
4784 + aufs_bindex_t bindex, bbot;
4787 + bindex = au_ibtop(inode);
4788 + h_inode = au_h_iptr(inode, bindex);
4790 + && !S_ISDIR(h_inode->i_mode)
4791 + && au_opt_test(au_mntflags(sb), PLINK)
4792 + && au_plink_test(inode))
4796 + * 0 can happen in revalidating.
4797 + * h_inode->i_mutex may not be held here, but it is harmless since once
4798 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4800 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4801 + * the incorrect link count.
4803 + set_nlink(inode, h_inode->i_nlink);
4806 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4807 + * it may includes whplink directory.
4809 + if (S_ISDIR(h_inode->i_mode)) {
4810 + bbot = au_ibbot(inode);
4811 + for (bindex++; bindex <= bbot; bindex++) {
4812 + h_inode = au_h_iptr(inode, bindex);
4814 + au_add_nlink(inode, h_inode);
4819 +void au_cpup_attr_changeable(struct inode *inode)
4821 + struct inode *h_inode;
4823 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4824 + inode->i_mode = h_inode->i_mode;
4825 + inode->i_uid = h_inode->i_uid;
4826 + inode->i_gid = h_inode->i_gid;
4827 + au_cpup_attr_timesizes(inode);
4828 + au_cpup_attr_flags(inode, h_inode->i_flags);
4831 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4833 + struct au_iinfo *iinfo = au_ii(inode);
4835 + IiMustWriteLock(inode);
4837 + iinfo->ii_higen = h_inode->i_generation;
4838 + iinfo->ii_hsb1 = h_inode->i_sb;
4841 +void au_cpup_attr_all(struct inode *inode, int force)
4843 + struct inode *h_inode;
4845 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4846 + au_cpup_attr_changeable(inode);
4847 + if (inode->i_nlink > 0)
4848 + au_cpup_attr_nlink(inode, force);
4849 + inode->i_rdev = h_inode->i_rdev;
4850 + inode->i_blkbits = h_inode->i_blkbits;
4851 + au_cpup_igen(inode, h_inode);
4854 +/* ---------------------------------------------------------------------- */
4856 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4858 +/* keep the timestamps of the parent dir when cpup */
4859 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4860 + struct path *h_path)
4862 + struct inode *h_inode;
4864 + dt->dt_dentry = dentry;
4865 + dt->dt_h_path = *h_path;
4866 + h_inode = d_inode(h_path->dentry);
4867 + dt->dt_atime = h_inode->i_atime;
4868 + dt->dt_mtime = h_inode->i_mtime;
4872 +void au_dtime_revert(struct au_dtime *dt)
4874 + struct iattr attr;
4877 + attr.ia_atime = dt->dt_atime;
4878 + attr.ia_mtime = dt->dt_mtime;
4879 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4880 + | ATTR_ATIME | ATTR_ATIME_SET;
4882 + /* no delegation since this is a directory */
4883 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4884 + if (unlikely(err))
4885 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4888 +/* ---------------------------------------------------------------------- */
4890 +/* internal use only */
4891 +struct au_cpup_reg_attr {
4894 + unsigned int iflags; /* inode->i_flags */
4897 +static noinline_for_stack
4898 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4899 + struct au_cpup_reg_attr *h_src_attr)
4901 + int err, sbits, icex;
4902 + unsigned int mnt_flags;
4903 + unsigned char verbose;
4905 + struct path h_path;
4906 + struct inode *h_isrc, *h_idst;
4907 + struct kstat *h_st;
4908 + struct au_branch *br;
4910 + br = au_sbr(dst->d_sb, bindex);
4911 + h_path.mnt = au_br_mnt(br);
4912 + h_path.dentry = au_h_dptr(dst, bindex);
4913 + h_idst = d_inode(h_path.dentry);
4914 + h_isrc = d_inode(h_src->dentry);
4915 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4916 + | ATTR_ATIME | ATTR_MTIME
4917 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4918 + if (h_src_attr && h_src_attr->valid) {
4919 + h_st = &h_src_attr->st;
4920 + ia.ia_uid = h_st->uid;
4921 + ia.ia_gid = h_st->gid;
4922 + ia.ia_atime = h_st->atime;
4923 + ia.ia_mtime = h_st->mtime;
4924 + if (h_idst->i_mode != h_st->mode
4925 + && !S_ISLNK(h_idst->i_mode)) {
4926 + ia.ia_valid |= ATTR_MODE;
4927 + ia.ia_mode = h_st->mode;
4929 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4930 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4932 + ia.ia_uid = h_isrc->i_uid;
4933 + ia.ia_gid = h_isrc->i_gid;
4934 + ia.ia_atime = h_isrc->i_atime;
4935 + ia.ia_mtime = h_isrc->i_mtime;
4936 + if (h_idst->i_mode != h_isrc->i_mode
4937 + && !S_ISLNK(h_idst->i_mode)) {
4938 + ia.ia_valid |= ATTR_MODE;
4939 + ia.ia_mode = h_isrc->i_mode;
4941 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4942 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4944 + /* no delegation since it is just created */
4945 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4947 + /* is this nfs only? */
4948 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4949 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4950 + ia.ia_mode = h_isrc->i_mode;
4951 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4954 + icex = br->br_perm & AuBrAttr_ICEX;
4956 + mnt_flags = au_mntflags(dst->d_sb);
4957 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4958 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4964 +/* ---------------------------------------------------------------------- */
4966 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4967 + char *buf, unsigned long blksize)
4970 + size_t sz, rbytes, wbytes;
4971 + unsigned char all_zero;
4973 + struct inode *h_inode;
4974 + /* reduce stack usage */
4977 + zp = page_address(ZERO_PAGE(0));
4978 + if (unlikely(!zp))
4979 + return -ENOMEM; /* possible? */
4984 + AuDbg("len %lld\n", len);
4986 + if (len < blksize)
4990 + /* todo: signal_pending? */
4991 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4992 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4995 + if (unlikely(err < 0))
4999 + if (len >= rbytes && rbytes == blksize)
5000 + all_zero = !memcmp(buf, zp, rbytes);
5007 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5009 + /* todo: signal_pending? */
5010 + if (unlikely(err == -EAGAIN || err == -EINTR))
5012 + if (unlikely(err < 0))
5017 + if (unlikely(err < 0))
5023 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5025 + if (unlikely(res < 0))
5032 + /* the last block may be a hole */
5033 + if (!err && all_zero) {
5034 + AuLabel(last hole);
5037 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5038 + /* nfs requires this step to make last hole */
5039 + /* is this only nfs? */
5041 + /* todo: signal_pending? */
5042 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5043 + } while (err == -EAGAIN || err == -EINTR);
5050 + ia->ia_size = dst->f_pos;
5051 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5052 + ia->ia_file = dst;
5053 + h_inode = file_inode(dst);
5054 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5055 + /* no delegation since it is just created */
5056 + err = vfsub_notify_change(&dst->f_path, ia,
5057 + /*delegated*/NULL);
5058 + inode_unlock(h_inode);
5065 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5068 + unsigned long blksize;
5069 + unsigned char do_kfree;
5071 + struct super_block *h_sb;
5074 + h_sb = file_inode(dst)->i_sb;
5075 + blksize = h_sb->s_blocksize;
5076 + if (!blksize || PAGE_SIZE < blksize)
5077 + blksize = PAGE_SIZE;
5078 + AuDbg("blksize %lu\n", blksize);
5079 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5081 + buf = kmalloc(blksize, GFP_NOFS);
5083 + buf = (void *)__get_free_page(GFP_NOFS);
5084 + if (unlikely(!buf))
5087 + if (len > (1 << 22))
5088 + AuDbg("copying a large file %lld\n", (long long)len);
5092 + err = au_do_copy_file(dst, src, len, buf, blksize);
5094 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5095 + au_kfree_do_rcu(buf);
5097 + free_page((unsigned long)buf);
5103 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5106 + struct super_block *h_src_sb;
5107 + struct inode *h_src_inode;
5109 + h_src_inode = file_inode(src);
5110 + h_src_sb = h_src_inode->i_sb;
5112 + /* XFS acquires inode_lock */
5113 + if (!au_test_xfs(h_src_sb))
5114 + err = au_copy_file(dst, src, len);
5116 + inode_unlock_shared(h_src_inode);
5117 + err = au_copy_file(dst, src, len);
5118 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5124 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5128 + struct super_block *h_src_sb;
5129 + struct inode *h_src_inode;
5131 + h_src_inode = file_inode(src);
5132 + h_src_sb = h_src_inode->i_sb;
5133 + if (h_src_sb != file_inode(dst)->i_sb
5134 + || !dst->f_op->remap_file_range) {
5135 + err = au_do_copy(dst, src, len);
5139 + if (!au_test_nfs(h_src_sb)) {
5140 + inode_unlock_shared(h_src_inode);
5141 + lo = vfsub_clone_file_range(src, dst, len);
5142 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5144 + lo = vfsub_clone_file_range(src, dst, len);
5147 + goto out; /* success */
5148 + } else if (lo >= 0)
5149 + /* todo: possible? */
5150 + /* paritially succeeded */
5151 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5152 + else if (lo != -EOPNOTSUPP) {
5153 + /* older XFS has a condition in cloning */
5158 + /* the backend fs on NFS may not support cloning */
5159 + err = au_do_copy(dst, src, len);
5167 + * to support a sparse file which is opened with O_APPEND,
5168 + * we need to close the file.
5170 +static int au_cp_regular(struct au_cp_generic *cpg)
5173 + enum { SRC, DST };
5175 + aufs_bindex_t bindex;
5176 + unsigned int flags;
5177 + struct dentry *dentry;
5179 + struct file *file;
5182 + .bindex = cpg->bsrc,
5183 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5186 + .bindex = cpg->bdst,
5187 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5188 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5191 + struct au_branch *br;
5192 + struct super_block *sb, *h_src_sb;
5193 + struct inode *h_src_inode;
5194 + struct task_struct *tsk = current;
5196 + /* bsrc branch can be ro/rw. */
5197 + sb = cpg->dentry->d_sb;
5199 + for (i = 0; i < 2; i++, f++) {
5200 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5201 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5202 + /*file*/NULL, f->force_wr);
5203 + if (IS_ERR(f->file)) {
5204 + err = PTR_ERR(f->file);
5212 + /* try stopping to update while we copyup */
5213 + h_src_inode = d_inode(file[SRC].dentry);
5214 + h_src_sb = h_src_inode->i_sb;
5215 + if (!au_test_nfs(h_src_sb))
5216 + IMustLock(h_src_inode);
5217 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5219 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5220 + if (tsk->flags & PF_KTHREAD)
5221 + __fput_sync(file[DST].file);
5223 + /* it happened actually */
5224 + fput(file[DST].file);
5227 + * we have to call both since we don't know which place the file
5231 + flush_delayed_fput();
5233 + br = au_sbr(sb, file[DST].bindex);
5234 + au_lcnt_dec(&br->br_nfiles);
5237 + fput(file[SRC].file);
5238 + br = au_sbr(sb, file[SRC].bindex);
5239 + au_lcnt_dec(&br->br_nfiles);
5244 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5245 + struct au_cpup_reg_attr *h_src_attr)
5249 + struct path h_path;
5250 + struct inode *h_src_inode, *h_dst_inode;
5253 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5254 + l = i_size_read(h_src_inode);
5255 + if (cpg->len == -1 || l < cpg->len)
5258 + /* try stopping to update while we are referencing */
5259 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5260 + au_pin_hdir_unlock(cpg->pin);
5262 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5263 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5264 + h_src_attr->iflags = h_src_inode->i_flags;
5265 + if (!au_test_nfs(h_src_inode->i_sb))
5266 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5268 + inode_unlock_shared(h_src_inode);
5269 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5270 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5272 + if (unlikely(err)) {
5273 + inode_unlock_shared(h_src_inode);
5276 + h_src_attr->valid = 1;
5277 + if (!au_test_nfs(h_src_inode->i_sb)) {
5278 + err = au_cp_regular(cpg);
5279 + inode_unlock_shared(h_src_inode);
5281 + inode_unlock_shared(h_src_inode);
5282 + err = au_cp_regular(cpg);
5284 + rerr = au_pin_hdir_relock(cpg->pin);
5288 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5289 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5290 + h_dst_inode = d_inode(h_path.dentry);
5291 + spin_lock(&h_dst_inode->i_lock);
5292 + h_dst_inode->i_state |= I_LINKABLE;
5293 + spin_unlock(&h_dst_inode->i_lock);
5300 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5301 + struct inode *h_dir)
5304 + DEFINE_DELAYED_CALL(done);
5307 + sym = vfs_get_link(h_src, &done);
5308 + err = PTR_ERR(sym);
5312 + err = vfsub_symlink(h_dir, h_path, sym);
5315 + do_delayed_call(&done);
5320 + * regardless 'acl' option, reset all ACL.
5321 + * All ACL will be copied up later from the original entry on the lower branch.
5323 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5326 + struct dentry *h_dentry;
5327 + struct inode *h_inode;
5328 + struct user_namespace *h_userns;
5330 + h_userns = mnt_user_ns(h_path->mnt);
5331 + h_dentry = h_path->dentry;
5332 + h_inode = d_inode(h_dentry);
5333 + /* forget_all_cached_acls(h_inode)); */
5334 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5336 + if (err == -EOPNOTSUPP)
5339 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5345 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5346 + struct inode *h_dir, struct path *h_path)
5349 + struct inode *dir, *inode;
5350 + struct user_namespace *h_userns;
5352 + h_userns = mnt_user_ns(h_path->mnt);
5353 + err = vfsub_removexattr(h_userns, h_path->dentry,
5354 + XATTR_NAME_POSIX_ACL_DEFAULT);
5356 + if (err == -EOPNOTSUPP)
5358 + if (unlikely(err))
5362 + * strange behaviour from the users view,
5363 + * particularly setattr case
5365 + dir = d_inode(dst_parent);
5366 + if (au_ibtop(dir) == cpg->bdst)
5367 + au_cpup_attr_nlink(dir, /*force*/1);
5368 + inode = d_inode(cpg->dentry);
5369 + au_cpup_attr_nlink(inode, /*force*/1);
5375 +static noinline_for_stack
5376 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5377 + struct au_cpup_reg_attr *h_src_attr)
5381 + unsigned int mnt_flags;
5382 + unsigned char isdir, isreg, force;
5383 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5384 + struct au_dtime dt;
5385 + struct path h_path;
5386 + struct dentry *h_src, *h_dst, *h_parent;
5387 + struct inode *h_inode, *h_dir;
5388 + struct super_block *sb;
5390 + /* bsrc branch can be ro/rw. */
5391 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5392 + h_inode = d_inode(h_src);
5393 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5395 + /* try stopping to be referenced while we are creating */
5396 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5397 + if (au_ftest_cpup(cpg->flags, RENAME))
5398 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5399 + AUFS_WH_PFX_LEN));
5400 + h_parent = h_dst->d_parent; /* dir inode is locked */
5401 + h_dir = d_inode(h_parent);
5403 + AuDebugOn(h_parent != h_dst->d_parent);
5405 + sb = cpg->dentry->d_sb;
5406 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5408 + h_path.dentry = h_parent;
5409 + au_dtime_store(&dt, dst_parent, &h_path);
5411 + h_path.dentry = h_dst;
5415 + mode = h_inode->i_mode;
5416 + switch (mode & S_IFMT) {
5419 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5421 + err = au_do_cpup_regular(cpg, h_src_attr);
5425 + err = vfsub_mkdir(h_dir, &h_path, mode);
5427 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5430 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5434 + AuDebugOn(!capable(CAP_MKNOD));
5438 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5441 + AuIOErr("Unknown inode type 0%o\n", mode);
5445 + err = au_reset_acl(h_dir, &h_path, mode);
5447 + mnt_flags = au_mntflags(sb);
5448 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5450 + && au_opt_test(mnt_flags, XINO)
5451 + && (h_inode->i_nlink == 1
5452 + || (h_inode->i_state & I_LINKABLE))
5453 + /* todo: unnecessary? */
5454 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5455 + && cpg->bdst < cpg->bsrc
5456 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5457 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5458 + /* ignore this error */
5463 + force = !!cpg->len;
5464 + if (cpg->len == -1)
5465 + force = !!i_size_read(h_inode);
5467 + au_fhsm_wrote(sb, cpg->bdst, force);
5471 + au_dtime_revert(&dt);
5475 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5478 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5479 + struct path h_ppath;
5480 + struct inode *h_dir;
5481 + aufs_bindex_t bdst;
5483 + dentry = cpg->dentry;
5485 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5486 + h_dentry = au_h_dptr(dentry, bdst);
5487 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5489 + au_set_h_dptr(dentry, bdst, NULL);
5490 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5492 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5493 + au_set_h_dptr(dentry, bdst, h_dentry);
5496 + parent = dget_parent(dentry);
5497 + h_ppath.dentry = au_h_dptr(parent, bdst);
5499 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5500 + if (IS_ERR(h_path->dentry))
5501 + err = PTR_ERR(h_path->dentry);
5503 + if (unlikely(err))
5506 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5507 + h_dir = d_inode(h_parent);
5509 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5510 + /* no delegation since it is just created */
5511 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5513 + dput(h_path->dentry);
5520 + * copyup the @dentry from @bsrc to @bdst.
5521 + * the caller must set the both of lower dentries.
5522 + * @len is for truncating when it is -1 copyup the entire file.
5523 + * in link/rename cases, @dst_parent may be different from the real one.
5524 + * basic->bsrc can be larger than basic->bdst.
5525 + * aufs doesn't touch the credential so
5526 + * security_inode_copy_up{,_xattr}() are unnecessary.
5528 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5531 + aufs_bindex_t old_ibtop;
5532 + unsigned char isdir, plink;
5533 + struct dentry *h_src, *h_dst, *h_parent;
5534 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5535 + struct super_block *sb;
5536 + struct au_branch *br;
5537 + struct path h_src_path;
5538 + /* to reduce stack size */
5540 + struct au_dtime dt;
5541 + struct path h_path;
5542 + struct au_cpup_reg_attr h_src_attr;
5546 + a = kmalloc(sizeof(*a), GFP_NOFS);
5549 + a->h_src_attr.valid = 0;
5551 + sb = cpg->dentry->d_sb;
5552 + br = au_sbr(sb, cpg->bdst);
5553 + a->h_path.mnt = au_br_mnt(br);
5554 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5555 + h_parent = h_dst->d_parent; /* dir inode is locked */
5556 + h_dir = d_inode(h_parent);
5559 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5560 + inode = d_inode(cpg->dentry);
5563 + dst_parent = dget_parent(cpg->dentry);
5567 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5568 + dst_inode = au_h_iptr(inode, cpg->bdst);
5570 + if (unlikely(!plink)) {
5572 + AuIOErr("hi%lu(i%lu) exists on b%d "
5573 + "but plink is disabled\n",
5574 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5578 + if (dst_inode->i_nlink) {
5579 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5581 + h_src = au_plink_lkup(inode, cpg->bdst);
5582 + err = PTR_ERR(h_src);
5583 + if (IS_ERR(h_src))
5585 + if (unlikely(d_is_negative(h_src))) {
5587 + AuIOErr("i%lu exists on b%d "
5588 + "but not pseudo-linked\n",
5589 + inode->i_ino, cpg->bdst);
5595 + a->h_path.dentry = h_parent;
5596 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5599 + a->h_path.dentry = h_dst;
5601 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5602 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5603 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5605 + au_dtime_revert(&a->dt);
5606 + if (unlikely(err == -EWOULDBLOCK)) {
5607 + pr_warn("cannot retry for NFSv4 delegation"
5608 + " for an internal link\n");
5614 + /* todo: cpup_wh_file? */
5616 + au_update_ibrange(inode, /*do_put_zero*/1);
5619 + isdir = S_ISDIR(inode->i_mode);
5620 + old_ibtop = au_ibtop(inode);
5621 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5622 + if (unlikely(err))
5624 + dst_inode = d_inode(h_dst);
5625 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5626 + /* todo: necessary? */
5627 + /* au_pin_hdir_unlock(cpg->pin); */
5629 + h_src_path.dentry = h_src;
5630 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5631 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5632 + if (unlikely(err)) {
5633 + /* todo: necessary? */
5634 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5635 + inode_unlock(dst_inode);
5639 + if (cpg->bdst < old_ibtop) {
5640 + if (S_ISREG(inode->i_mode)) {
5641 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5642 + if (unlikely(err)) {
5643 + /* ignore an error */
5644 + /* au_pin_hdir_relock(cpg->pin); */
5645 + inode_unlock(dst_inode);
5649 + au_set_ibtop(inode, cpg->bdst);
5651 + au_set_ibbot(inode, cpg->bdst);
5652 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5653 + au_hi_flags(inode, isdir));
5655 + /* todo: necessary? */
5656 + /* err = au_pin_hdir_relock(cpg->pin); */
5657 + inode_unlock(dst_inode);
5658 + if (unlikely(err))
5661 + src_inode = d_inode(h_src);
5663 + && (src_inode->i_nlink > 1
5664 + || src_inode->i_state & I_LINKABLE)
5666 + au_plink_append(inode, cpg->bdst, h_dst);
5668 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5669 + a->h_path.dentry = h_dst;
5670 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5673 + goto out_parent; /* success */
5677 + a->h_path.dentry = h_parent;
5678 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5679 + a->h_path.dentry = h_dst;
5681 + if (d_is_positive(h_dst)) {
5683 + /* no delegation since it is just created */
5684 + rerr = vfsub_unlink(h_dir, &a->h_path,
5685 + /*delegated*/NULL, /*force*/0);
5687 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5689 + au_dtime_revert(&a->dt);
5691 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5701 +#if 0 /* reserved */
5702 +struct au_cpup_single_args {
5704 + struct au_cp_generic *cpg;
5705 + struct dentry *dst_parent;
5708 +static void au_call_cpup_single(void *args)
5710 + struct au_cpup_single_args *a = args;
5712 + au_pin_hdir_acquire_nest(a->cpg->pin);
5713 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5714 + au_pin_hdir_release(a->cpg->pin);
5719 + * prevent SIGXFSZ in copy-up.
5720 + * testing CAP_MKNOD is for generic fs,
5721 + * but CAP_FSETID is for xfs only, currently.
5723 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5726 + struct super_block *sb;
5727 + struct inode *h_dir;
5730 + sb = au_pinned_parent(pin)->d_sb;
5731 + if (!au_wkq_test()
5732 + && (!au_sbi(sb)->si_plink_maint_pid
5733 + || au_plink_maint(sb, AuLock_NOPLM))) {
5734 + switch (mode & S_IFMT) {
5736 + /* no condition about RLIMIT_FSIZE and the file size */
5741 + do_sio = !capable(CAP_MKNOD);
5745 + do_sio = ((mode & (S_ISUID | S_ISGID))
5746 + && !capable(CAP_FSETID));
5747 + /* this workaround may be removed in the future */
5749 + h_dir = au_pinned_h_dir(pin);
5750 + do_sio = h_dir->i_mode & S_ISVTX;
5757 +#if 0 /* reserved */
5758 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5761 + struct dentry *h_dentry;
5763 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5764 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5765 + err = au_cpup_single(cpg, dst_parent);
5767 + struct au_cpup_single_args args = {
5770 + .dst_parent = dst_parent
5772 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5773 + if (unlikely(wkq_err))
5782 + * copyup the @dentry from the first active lower branch to @bdst,
5783 + * using au_cpup_single().
5785 +static int au_cpup_simple(struct au_cp_generic *cpg)
5788 + unsigned int flags_orig;
5789 + struct dentry *dentry;
5791 + AuDebugOn(cpg->bsrc < 0);
5793 + dentry = cpg->dentry;
5794 + DiMustWriteLock(dentry);
5796 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5798 + flags_orig = cpg->flags;
5799 + au_fset_cpup(cpg->flags, RENAME);
5800 + err = au_cpup_single(cpg, NULL);
5801 + cpg->flags = flags_orig;
5803 + return 0; /* success */
5806 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5807 + au_set_dbtop(dentry, cpg->bsrc);
5813 +struct au_cpup_simple_args {
5815 + struct au_cp_generic *cpg;
5818 +static void au_call_cpup_simple(void *args)
5820 + struct au_cpup_simple_args *a = args;
5822 + au_pin_hdir_acquire_nest(a->cpg->pin);
5823 + *a->errp = au_cpup_simple(a->cpg);
5824 + au_pin_hdir_release(a->cpg->pin);
5827 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5830 + struct dentry *dentry, *parent;
5831 + struct file *h_file;
5832 + struct inode *h_dir;
5833 + struct user_namespace *h_userns;
5835 + dentry = cpg->dentry;
5837 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5838 + AuDebugOn(cpg->bsrc < 0);
5839 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5840 + err = PTR_ERR(h_file);
5841 + if (IS_ERR(h_file))
5845 + parent = dget_parent(dentry);
5846 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5847 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5848 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5849 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5850 + err = au_cpup_simple(cpg);
5852 + struct au_cpup_simple_args args = {
5856 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5857 + if (unlikely(wkq_err))
5863 + au_h_open_post(dentry, cpg->bsrc, h_file);
5869 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5871 + aufs_bindex_t bsrc, bbot;
5872 + struct dentry *dentry, *h_dentry;
5874 + if (cpg->bsrc < 0) {
5875 + dentry = cpg->dentry;
5876 + bbot = au_dbbot(dentry);
5877 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5878 + h_dentry = au_h_dptr(dentry, bsrc);
5880 + AuDebugOn(d_is_negative(h_dentry));
5884 + AuDebugOn(bsrc > bbot);
5887 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5888 + return au_do_sio_cpup_simple(cpg);
5891 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5893 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5894 + return au_do_sio_cpup_simple(cpg);
5897 +/* ---------------------------------------------------------------------- */
5900 + * copyup the deleted file for writing.
5902 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5903 + struct file *file)
5906 + unsigned int flags_orig;
5907 + aufs_bindex_t bsrc_orig;
5908 + struct au_dinfo *dinfo;
5910 + struct au_hdentry *hd;
5911 + struct dentry *h_dentry;
5914 + dinfo = au_di(cpg->dentry);
5915 + AuRwMustWriteLock(&dinfo->di_rwsem);
5917 + bsrc_orig = cpg->bsrc;
5918 + cpg->bsrc = dinfo->di_btop;
5919 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5920 + hdst.h_dentry = hdst.hd->hd_dentry;
5921 + hdst.hd->hd_dentry = wh_dentry;
5922 + dinfo->di_btop = cpg->bdst;
5924 + hsrc.h_dentry = NULL;
5926 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5927 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5928 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5930 + flags_orig = cpg->flags;
5931 + cpg->flags = !AuCpup_DTIME;
5932 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5933 + cpg->flags = flags_orig;
5936 + err = au_reopen_nondir(file);
5937 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5939 + hdst.hd->hd_dentry = hdst.h_dentry;
5940 + dinfo->di_btop = cpg->bsrc;
5941 + cpg->bsrc = bsrc_orig;
5946 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5949 + aufs_bindex_t bdst;
5950 + struct au_dtime dt;
5951 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5952 + struct au_branch *br;
5953 + struct path h_path;
5955 + dentry = cpg->dentry;
5957 + br = au_sbr(dentry->d_sb, bdst);
5958 + parent = dget_parent(dentry);
5959 + h_parent = au_h_dptr(parent, bdst);
5960 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5961 + err = PTR_ERR(wh_dentry);
5962 + if (IS_ERR(wh_dentry))
5965 + h_path.dentry = h_parent;
5966 + h_path.mnt = au_br_mnt(br);
5967 + au_dtime_store(&dt, parent, &h_path);
5968 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5969 + if (unlikely(err))
5973 + h_path.dentry = wh_dentry;
5974 + if (!d_is_dir(wh_dentry)) {
5975 + /* no delegation since it is just created */
5976 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5977 + /*delegated*/NULL, /*force*/0);
5979 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5980 + if (unlikely(err)) {
5981 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5985 + au_dtime_revert(&dt);
5986 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5995 +struct au_cpup_wh_args {
5997 + struct au_cp_generic *cpg;
5998 + struct file *file;
6001 +static void au_call_cpup_wh(void *args)
6003 + struct au_cpup_wh_args *a = args;
6005 + au_pin_hdir_acquire_nest(a->cpg->pin);
6006 + *a->errp = au_cpup_wh(a->cpg, a->file);
6007 + au_pin_hdir_release(a->cpg->pin);
6010 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6013 + aufs_bindex_t bdst;
6014 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6015 + struct inode *dir, *h_dir, *h_tmpdir;
6016 + struct au_wbr *wbr;
6017 + struct au_pin wh_pin, *pin_orig;
6018 + struct user_namespace *h_userns;
6020 + dentry = cpg->dentry;
6022 + parent = dget_parent(dentry);
6023 + dir = d_inode(parent);
6026 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6029 + if (!h_dir->i_nlink) {
6030 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6031 + h_orph = wbr->wbr_orph;
6033 + h_parent = dget(au_h_dptr(parent, bdst));
6034 + au_set_h_dptr(parent, bdst, dget(h_orph));
6035 + h_tmpdir = d_inode(h_orph);
6036 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6038 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6039 + /* todo: au_h_open_pre()? */
6041 + pin_orig = cpg->pin;
6042 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6043 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6044 + cpg->pin = &wh_pin;
6047 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6048 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6049 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6050 + err = au_cpup_wh(cpg, file);
6052 + struct au_cpup_wh_args args = {
6057 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6058 + if (unlikely(wkq_err))
6063 + inode_unlock(h_tmpdir);
6064 + /* todo: au_h_open_post()? */
6065 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6066 + au_set_h_dptr(parent, bdst, h_parent);
6067 + AuDebugOn(!pin_orig);
6068 + cpg->pin = pin_orig;
6076 +/* ---------------------------------------------------------------------- */
6079 + * generic routine for both of copy-up and copy-down.
6081 +/* cf. revalidate function in file.c */
6082 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6083 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6084 + struct au_pin *pin,
6085 + struct dentry *h_parent, void *arg),
6089 + struct au_pin pin;
6090 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6093 + parent = dget_parent(dentry);
6094 + if (IS_ROOT(parent))
6097 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6098 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6100 + /* do not use au_dpage */
6101 + real_parent = parent;
6104 + parent = dget_parent(dentry);
6105 + h_parent = au_h_dptr(parent, bdst);
6107 + goto out; /* success */
6109 + /* find top dir which is necessary to cpup */
6113 + parent = dget_parent(d);
6114 + di_read_lock_parent3(parent, !AuLock_IR);
6115 + h_parent = au_h_dptr(parent, bdst);
6116 + di_read_unlock(parent, !AuLock_IR);
6117 + } while (!h_parent);
6119 + if (d != real_parent)
6120 + di_write_lock_child3(d);
6122 + /* somebody else might create while we were sleeping */
6123 + h_dentry = au_h_dptr(d, bdst);
6124 + if (!h_dentry || d_is_negative(h_dentry)) {
6126 + au_update_dbtop(d);
6128 + au_pin_set_dentry(&pin, d);
6129 + err = au_do_pin(&pin);
6131 + err = cp(d, bdst, &pin, h_parent, arg);
6136 + if (d != real_parent)
6137 + di_write_unlock(d);
6138 + if (unlikely(err))
6147 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6148 + struct au_pin *pin,
6149 + struct dentry *h_parent __maybe_unused,
6150 + void *arg __maybe_unused)
6152 + struct au_cp_generic cpg = {
6158 + .flags = AuCpup_DTIME
6160 + return au_sio_cpup_simple(&cpg);
6163 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6165 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6168 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6171 + struct dentry *parent;
6172 + struct inode *dir;
6174 + parent = dget_parent(dentry);
6175 + dir = d_inode(parent);
6177 + if (au_h_iptr(dir, bdst))
6180 + di_read_unlock(parent, AuLock_IR);
6181 + di_write_lock_parent(parent);
6182 + /* someone else might change our inode while we were sleeping */
6183 + if (!au_h_iptr(dir, bdst))
6184 + err = au_cpup_dirs(dentry, bdst);
6185 + di_downgrade_lock(parent, AuLock_IR);
6191 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6192 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6193 +++ linux/fs/aufs/cpup.h 2022-03-21 14:49:05.719966344 +0100
6195 +/* SPDX-License-Identifier: GPL-2.0 */
6197 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6199 + * This program, aufs is free software; you can redistribute it and/or modify
6200 + * it under the terms of the GNU General Public License as published by
6201 + * the Free Software Foundation; either version 2 of the License, or
6202 + * (at your option) any later version.
6204 + * This program is distributed in the hope that it will be useful,
6205 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6206 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6207 + * GNU General Public License for more details.
6209 + * You should have received a copy of the GNU General Public License
6210 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6214 + * copy-up/down functions
6217 +#ifndef __AUFS_CPUP_H__
6218 +#define __AUFS_CPUP_H__
6222 +#include <linux/path.h>
6228 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6229 +void au_cpup_attr_timesizes(struct inode *inode);
6230 +void au_cpup_attr_nlink(struct inode *inode, int force);
6231 +void au_cpup_attr_changeable(struct inode *inode);
6232 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6233 +void au_cpup_attr_all(struct inode *inode, int force);
6235 +/* ---------------------------------------------------------------------- */
6237 +struct au_cp_generic {
6238 + struct dentry *dentry;
6239 + aufs_bindex_t bdst, bsrc;
6241 + struct au_pin *pin;
6242 + unsigned int flags;
6246 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6247 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6249 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6250 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6252 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6254 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6255 + the branch is marked as RO */
6257 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6258 +#undef AuCpup_HOPEN
6259 +#define AuCpup_HOPEN 0
6262 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6263 +#define au_fset_cpup(flags, name) \
6264 + do { (flags) |= AuCpup_##name; } while (0)
6265 +#define au_fclr_cpup(flags, name) \
6266 + do { (flags) &= ~AuCpup_##name; } while (0)
6268 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6269 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6270 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6271 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6273 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6274 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6275 + struct au_pin *pin,
6276 + struct dentry *h_parent, void *arg),
6278 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6279 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6281 +/* ---------------------------------------------------------------------- */
6283 +/* keep timestamps when copyup */
6285 + struct dentry *dt_dentry;
6286 + struct path dt_h_path;
6287 + struct timespec64 dt_atime, dt_mtime;
6289 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6290 + struct path *h_path);
6291 +void au_dtime_revert(struct au_dtime *dt);
6293 +#endif /* __KERNEL__ */
6294 +#endif /* __AUFS_CPUP_H__ */
6295 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6296 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6297 +++ linux/fs/aufs/dbgaufs.c 2022-03-21 14:49:05.719966344 +0100
6299 +// SPDX-License-Identifier: GPL-2.0
6301 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6303 + * This program, aufs is free software; you can redistribute it and/or modify
6304 + * it under the terms of the GNU General Public License as published by
6305 + * the Free Software Foundation; either version 2 of the License, or
6306 + * (at your option) any later version.
6308 + * This program is distributed in the hope that it will be useful,
6309 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6310 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6311 + * GNU General Public License for more details.
6313 + * You should have received a copy of the GNU General Public License
6314 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6318 + * debugfs interface
6321 +#include <linux/debugfs.h>
6324 +#ifndef CONFIG_SYSFS
6325 +#error DEBUG_FS depends upon SYSFS
6328 +static struct dentry *dbgaufs;
6329 +static const mode_t dbgaufs_mode = 0444;
6331 +/* 20 is max digits length of ulong 64 */
6332 +struct dbgaufs_arg {
6338 + * common function for all XINO files
6340 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6341 + struct file *file)
6345 + p = file->private_data;
6347 + /* this is struct dbgaufs_arg */
6348 + AuDebugOn(!au_kfree_sz_test(p));
6349 + au_kfree_do_rcu(p);
6354 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6359 + struct dbgaufs_arg *p;
6362 + p = kmalloc(sizeof(*p), GFP_NOFS);
6368 + file->private_data = p;
6372 + err = vfsub_getattr(&xf->f_path, &st);
6376 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6377 + cnt, st.blocks, st.blksize,
6378 + (long long)st.size);
6380 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6381 + st.blocks, st.blksize,
6382 + (long long)st.size);
6383 + AuDebugOn(p->n >= sizeof(p->a));
6385 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6393 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6394 + size_t count, loff_t *ppos)
6396 + struct dbgaufs_arg *p;
6398 + p = file->private_data;
6399 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6402 +/* ---------------------------------------------------------------------- */
6404 +struct dbgaufs_plink_arg {
6409 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6410 + struct file *file)
6412 + free_page((unsigned long)file->private_data);
6416 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6418 + int err, i, limit;
6419 + unsigned long n, sum;
6420 + struct dbgaufs_plink_arg *p;
6421 + struct au_sbinfo *sbinfo;
6422 + struct super_block *sb;
6423 + struct hlist_bl_head *hbl;
6426 + p = (void *)get_zeroed_page(GFP_NOFS);
6431 + sbinfo = inode->i_private;
6432 + sb = sbinfo->si_sb;
6433 + si_noflush_read_lock(sb);
6434 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6435 + limit = PAGE_SIZE - sizeof(p->n);
6437 + /* the number of buckets */
6438 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6443 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6445 + n = au_hbl_count(hbl);
6448 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6451 + if (unlikely(limit <= 0))
6454 + p->a[p->n - 1] = '\n';
6456 + /* the sum of plinks */
6457 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6460 + if (unlikely(limit <= 0))
6463 +#define str "1\n0\n0\n"
6464 + p->n = sizeof(str) - 1;
6465 + strcpy(p->a, str);
6468 + si_read_unlock(sb);
6471 + file->private_data = p;
6472 + goto out; /* success */
6475 + free_page((unsigned long)p);
6480 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6481 + size_t count, loff_t *ppos)
6483 + struct dbgaufs_plink_arg *p;
6485 + p = file->private_data;
6486 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6489 +static const struct file_operations dbgaufs_plink_fop = {
6490 + .owner = THIS_MODULE,
6491 + .open = dbgaufs_plink_open,
6492 + .release = dbgaufs_plink_release,
6493 + .read = dbgaufs_plink_read
6496 +/* ---------------------------------------------------------------------- */
6498 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6501 + struct au_sbinfo *sbinfo;
6502 + struct super_block *sb;
6504 + sbinfo = inode->i_private;
6505 + sb = sbinfo->si_sb;
6506 + si_noflush_read_lock(sb);
6507 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6508 + si_read_unlock(sb);
6512 +static const struct file_operations dbgaufs_xib_fop = {
6513 + .owner = THIS_MODULE,
6514 + .open = dbgaufs_xib_open,
6515 + .release = dbgaufs_xi_release,
6516 + .read = dbgaufs_xi_read
6519 +/* ---------------------------------------------------------------------- */
6521 +#define DbgaufsXi_PREFIX "xi"
6523 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6527 + aufs_bindex_t bindex;
6528 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6529 + struct au_sbinfo *sbinfo;
6530 + struct super_block *sb;
6531 + struct au_xino *xi;
6533 + struct qstr *name;
6534 + struct au_branch *br;
6537 + name = &file->f_path.dentry->d_name;
6538 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6539 + || memcmp(name->name, DbgaufsXi_PREFIX,
6540 + sizeof(DbgaufsXi_PREFIX) - 1)))
6543 + AuDebugOn(name->len >= sizeof(a));
6544 + memcpy(a, name->name, name->len);
6545 + a[name->len] = '\0';
6546 + p = strchr(a, '-');
6549 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6550 + if (unlikely(err))
6555 + err = kstrtol(p + 1, 10, &l);
6556 + if (unlikely(err))
6562 + sbinfo = inode->i_private;
6563 + sb = sbinfo->si_sb;
6564 + si_noflush_read_lock(sb);
6565 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6567 + br = au_sbr(sb, bindex);
6569 + if (unlikely(idx >= xi->xi_nfile))
6571 + xf = au_xino_file(xi, idx);
6573 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6574 + au_xino_count(br));
6577 + si_read_unlock(sb);
6583 +static const struct file_operations dbgaufs_xino_fop = {
6584 + .owner = THIS_MODULE,
6585 + .open = dbgaufs_xino_open,
6586 + .release = dbgaufs_xi_release,
6587 + .read = dbgaufs_xi_read
6590 +void dbgaufs_xino_del(struct au_branch *br)
6592 + struct dentry *dbgaufs;
6594 + dbgaufs = br->br_dbgaufs;
6598 + br->br_dbgaufs = NULL;
6599 + /* debugfs acquires the parent i_mutex */
6601 + debugfs_remove(dbgaufs);
6605 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6607 + aufs_bindex_t bbot;
6608 + struct au_branch *br;
6610 + if (!au_sbi(sb)->si_dbgaufs)
6613 + bbot = au_sbbot(sb);
6614 + for (; bindex <= bbot; bindex++) {
6615 + br = au_sbr(sb, bindex);
6616 + dbgaufs_xino_del(br);
6620 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6621 + unsigned int idx, struct dentry *parent,
6622 + struct au_sbinfo *sbinfo)
6624 + struct au_branch *br;
6626 + /* "xi" bindex(5) "-" idx(2) NULL */
6627 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6630 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6632 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6634 + br = au_sbr(sb, bindex);
6635 + if (br->br_dbgaufs) {
6636 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6638 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6639 + /* debugfs acquires the parent i_mutex */
6641 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6645 + pr_warn("failed renaming %pd/%s, ignored.\n",
6650 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6651 + sbinfo, &dbgaufs_xino_fop);
6653 + if (unlikely(!br->br_dbgaufs))
6654 + pr_warn("failed creating %pd/%s, ignored.\n",
6659 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6660 + struct dentry *parent, struct au_sbinfo *sbinfo)
6662 + struct au_branch *br;
6663 + struct au_xino *xi;
6666 + br = au_sbr(sb, bindex);
6668 + for (u = 0; u < xi->xi_nfile; u++)
6669 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6672 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6674 + struct au_sbinfo *sbinfo;
6675 + struct dentry *parent;
6676 + aufs_bindex_t bbot;
6678 + if (!au_opt_test(au_mntflags(sb), XINO))
6681 + sbinfo = au_sbi(sb);
6682 + parent = sbinfo->si_dbgaufs;
6686 + bbot = au_sbbot(sb);
6688 + for (; bindex <= bbot; bindex++)
6689 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6691 + for (; bbot >= bindex; bbot--)
6692 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6695 +/* ---------------------------------------------------------------------- */
6697 +#ifdef CONFIG_AUFS_EXPORT
6698 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6701 + struct au_sbinfo *sbinfo;
6702 + struct super_block *sb;
6704 + sbinfo = inode->i_private;
6705 + sb = sbinfo->si_sb;
6706 + si_noflush_read_lock(sb);
6707 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6708 + si_read_unlock(sb);
6712 +static const struct file_operations dbgaufs_xigen_fop = {
6713 + .owner = THIS_MODULE,
6714 + .open = dbgaufs_xigen_open,
6715 + .release = dbgaufs_xi_release,
6716 + .read = dbgaufs_xi_read
6719 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6724 + * This function is a dynamic '__init' function actually,
6725 + * so the tiny check for si_rwsem is unnecessary.
6727 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6730 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6731 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6732 + &dbgaufs_xigen_fop);
6733 + if (sbinfo->si_dbgaufs_xigen)
6739 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6743 +#endif /* CONFIG_AUFS_EXPORT */
6745 +/* ---------------------------------------------------------------------- */
6747 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6750 + * This function is a dynamic '__fin' function actually,
6751 + * so the tiny check for si_rwsem is unnecessary.
6753 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6755 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6756 + sbinfo->si_dbgaufs = NULL;
6759 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6762 + char name[SysaufsSiNameLen];
6765 + * This function is a dynamic '__init' function actually,
6766 + * so the tiny check for si_rwsem is unnecessary.
6768 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6772 + AuErr1("/debug/aufs is uninitialized\n");
6777 + sysaufs_name(sbinfo, name);
6778 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6779 + if (unlikely(!sbinfo->si_dbgaufs))
6782 + /* regardless plink/noplink option */
6783 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6784 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6785 + &dbgaufs_plink_fop);
6786 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6789 + /* regardless xino/noxino option */
6790 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6791 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6792 + &dbgaufs_xib_fop);
6793 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6796 + err = dbgaufs_xigen_init(sbinfo);
6798 + goto out; /* success */
6801 + dbgaufs_si_fin(sbinfo);
6803 + if (unlikely(err))
6804 + pr_err("debugfs/aufs failed\n");
6808 +/* ---------------------------------------------------------------------- */
6810 +void dbgaufs_fin(void)
6812 + debugfs_remove(dbgaufs);
6815 +int __init dbgaufs_init(void)
6820 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6825 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6826 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6827 +++ linux/fs/aufs/dbgaufs.h 2022-03-21 14:49:05.719966344 +0100
6829 +/* SPDX-License-Identifier: GPL-2.0 */
6831 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6833 + * This program, aufs is free software; you can redistribute it and/or modify
6834 + * it under the terms of the GNU General Public License as published by
6835 + * the Free Software Foundation; either version 2 of the License, or
6836 + * (at your option) any later version.
6838 + * This program is distributed in the hope that it will be useful,
6839 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6840 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6841 + * GNU General Public License for more details.
6843 + * You should have received a copy of the GNU General Public License
6844 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6848 + * debugfs interface
6851 +#ifndef __DBGAUFS_H__
6852 +#define __DBGAUFS_H__
6856 +struct super_block;
6860 +#ifdef CONFIG_DEBUG_FS
6862 +void dbgaufs_xino_del(struct au_branch *br);
6863 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6864 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6865 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6866 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6867 +void dbgaufs_fin(void);
6868 +int __init dbgaufs_init(void);
6870 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6871 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6872 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6874 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6875 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6876 +AuStubVoid(dbgaufs_fin, void)
6877 +AuStubInt0(__init dbgaufs_init, void)
6878 +#endif /* CONFIG_DEBUG_FS */
6880 +#endif /* __KERNEL__ */
6881 +#endif /* __DBGAUFS_H__ */
6882 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6883 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6884 +++ linux/fs/aufs/dcsub.c 2022-03-21 14:49:05.719966344 +0100
6886 +// SPDX-License-Identifier: GPL-2.0
6888 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6890 + * This program, aufs is free software; you can redistribute it and/or modify
6891 + * it under the terms of the GNU General Public License as published by
6892 + * the Free Software Foundation; either version 2 of the License, or
6893 + * (at your option) any later version.
6895 + * This program is distributed in the hope that it will be useful,
6896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6898 + * GNU General Public License for more details.
6900 + * You should have received a copy of the GNU General Public License
6901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6905 + * sub-routines for dentry cache
6910 +static void au_dpage_free(struct au_dpage *dpage)
6913 + struct dentry **p;
6915 + p = dpage->dentries;
6916 + for (i = 0; i < dpage->ndentry; i++)
6918 + free_page((unsigned long)dpage->dentries);
6921 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6927 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6928 + if (unlikely(!dpages->dpages))
6931 + p = (void *)__get_free_page(gfp);
6935 + dpages->dpages[0].ndentry = 0;
6936 + dpages->dpages[0].dentries = p;
6937 + dpages->ndpage = 1;
6938 + return 0; /* success */
6941 + au_kfree_try_rcu(dpages->dpages);
6946 +void au_dpages_free(struct au_dcsub_pages *dpages)
6949 + struct au_dpage *p;
6951 + p = dpages->dpages;
6952 + for (i = 0; i < dpages->ndpage; i++)
6953 + au_dpage_free(p++);
6954 + au_kfree_try_rcu(dpages->dpages);
6957 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6958 + struct dentry *dentry, gfp_t gfp)
6961 + struct au_dpage *dpage;
6964 + dpage = dpages->dpages + dpages->ndpage - 1;
6965 + sz = PAGE_SIZE / sizeof(dentry);
6966 + if (unlikely(dpage->ndentry >= sz)) {
6967 + AuLabel(new dpage);
6969 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6970 + p = au_kzrealloc(dpages->dpages, sz,
6971 + sz + sizeof(*dpages->dpages), gfp,
6976 + dpages->dpages = p;
6977 + dpage = dpages->dpages + dpages->ndpage;
6978 + p = (void *)__get_free_page(gfp);
6982 + dpage->ndentry = 0;
6983 + dpage->dentries = p;
6987 + AuDebugOn(au_dcount(dentry) <= 0);
6988 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6989 + return 0; /* success */
6995 +/* todo: BAD approach */
6996 +/* copied from linux/fs/dcache.c */
7004 +extern void d_walk(struct dentry *parent, void *data,
7005 + enum d_walk_ret (*enter)(void *, struct dentry *));
7007 +struct ac_dpages_arg {
7009 + struct au_dcsub_pages *dpages;
7010 + struct super_block *sb;
7011 + au_dpages_test test;
7015 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7017 + enum d_walk_ret ret;
7018 + struct ac_dpages_arg *arg = _arg;
7020 + ret = D_WALK_CONTINUE;
7021 + if (dentry->d_sb == arg->sb
7022 + && !IS_ROOT(dentry)
7023 + && au_dcount(dentry) > 0
7025 + && (!arg->test || arg->test(dentry, arg->arg))) {
7026 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7027 + if (unlikely(arg->err))
7028 + ret = D_WALK_QUIT;
7034 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7035 + au_dpages_test test, void *arg)
7037 + struct ac_dpages_arg args = {
7045 + d_walk(root, &args, au_call_dpages_append);
7050 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7051 + int do_include, au_dpages_test test, void *arg)
7056 + write_seqlock(&rename_lock);
7057 + spin_lock(&dentry->d_lock);
7059 + && au_dcount(dentry) > 0
7060 + && (!test || test(dentry, arg)))
7061 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7062 + spin_unlock(&dentry->d_lock);
7063 + if (unlikely(err))
7067 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7070 + while (!IS_ROOT(dentry)) {
7071 + dentry = dentry->d_parent; /* rename_lock is locked */
7072 + spin_lock(&dentry->d_lock);
7073 + if (au_dcount(dentry) > 0
7074 + && (!test || test(dentry, arg)))
7075 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7076 + spin_unlock(&dentry->d_lock);
7077 + if (unlikely(err))
7082 + write_sequnlock(&rename_lock);
7086 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7088 + return au_di(dentry) && dentry->d_sb == arg;
7091 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7092 + struct dentry *dentry, int do_include)
7094 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7095 + au_dcsub_dpages_aufs, dentry->d_sb);
7098 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7100 + struct path path[2] = {
7109 + return path_is_under(path + 0, path + 1);
7111 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7112 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7113 +++ linux/fs/aufs/dcsub.h 2022-03-21 14:49:05.719966344 +0100
7115 +/* SPDX-License-Identifier: GPL-2.0 */
7117 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7119 + * This program, aufs is free software; you can redistribute it and/or modify
7120 + * it under the terms of the GNU General Public License as published by
7121 + * the Free Software Foundation; either version 2 of the License, or
7122 + * (at your option) any later version.
7124 + * This program is distributed in the hope that it will be useful,
7125 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7126 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7127 + * GNU General Public License for more details.
7129 + * You should have received a copy of the GNU General Public License
7130 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7134 + * sub-routines for dentry cache
7137 +#ifndef __AUFS_DCSUB_H__
7138 +#define __AUFS_DCSUB_H__
7142 +#include <linux/dcache.h>
7143 +#include <linux/fs.h>
7147 + struct dentry **dentries;
7150 +struct au_dcsub_pages {
7152 + struct au_dpage *dpages;
7155 +/* ---------------------------------------------------------------------- */
7158 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7159 +void au_dpages_free(struct au_dcsub_pages *dpages);
7160 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7161 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7162 + au_dpages_test test, void *arg);
7163 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7164 + int do_include, au_dpages_test test, void *arg);
7165 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7166 + struct dentry *dentry, int do_include);
7167 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7169 +/* ---------------------------------------------------------------------- */
7172 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7173 + * include/linux/dcache.h. Try them (in the future).
7176 +static inline int au_d_hashed_positive(struct dentry *d)
7179 + struct inode *inode = d_inode(d);
7182 + if (unlikely(d_unhashed(d)
7183 + || d_is_negative(d)
7184 + || !inode->i_nlink))
7189 +static inline int au_d_linkable(struct dentry *d)
7192 + struct inode *inode = d_inode(d);
7194 + err = au_d_hashed_positive(d);
7196 + && d_is_positive(d)
7197 + && (inode->i_state & I_LINKABLE))
7202 +static inline int au_d_alive(struct dentry *d)
7205 + struct inode *inode;
7209 + err = au_d_hashed_positive(d);
7211 + inode = d_inode(d);
7212 + if (unlikely(d_unlinked(d)
7213 + || d_is_negative(d)
7214 + || !inode->i_nlink))
7220 +static inline int au_alive_dir(struct dentry *d)
7224 + err = au_d_alive(d);
7225 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7230 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7232 + return a->len == b->len
7233 + && !memcmp(a->name, b->name, a->len);
7238 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7240 + * the type of d_lockref.count became int, but the inlined function d_count()
7241 + * still returns unsigned int.
7242 + * I don't know why. Maybe it is for every d_count() users?
7243 + * Anyway au_dcount() lives on.
7245 +static inline int au_dcount(struct dentry *d)
7247 + return (int)d_count(d);
7250 +#endif /* __KERNEL__ */
7251 +#endif /* __AUFS_DCSUB_H__ */
7252 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7253 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7254 +++ linux/fs/aufs/debug.c 2022-03-21 14:49:05.719966344 +0100
7256 +// SPDX-License-Identifier: GPL-2.0
7258 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7260 + * This program, aufs is free software; you can redistribute it and/or modify
7261 + * it under the terms of the GNU General Public License as published by
7262 + * the Free Software Foundation; either version 2 of the License, or
7263 + * (at your option) any later version.
7265 + * This program is distributed in the hope that it will be useful,
7266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7268 + * GNU General Public License for more details.
7270 + * You should have received a copy of the GNU General Public License
7271 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7275 + * debug print functions
7278 +#include <linux/iversion.h>
7281 +/* Returns 0, or -errno. arg is in kp->arg. */
7282 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7286 + err = kstrtoint(val, 0, &n);
7296 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7297 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7302 + return sprintf(buffer, "%d", atomic_read(a));
7305 +static struct kernel_param_ops param_ops_atomic_t = {
7306 + .set = param_atomic_t_set,
7307 + .get = param_atomic_t_get
7308 + /* void (*free)(void *arg) */
7311 +atomic_t aufs_debug = ATOMIC_INIT(0);
7312 +MODULE_PARM_DESC(debug, "debug print");
7313 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7315 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7316 +char *au_plevel = KERN_DEBUG;
7317 +#define dpri(fmt, ...) do { \
7319 + && strcmp(au_plevel, KERN_DEBUG)) \
7320 + || au_debug_test()) \
7321 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7324 +/* ---------------------------------------------------------------------- */
7326 +void au_dpri_whlist(struct au_nhash *whlist)
7328 + unsigned long ul, n;
7329 + struct hlist_head *head;
7330 + struct au_vdir_wh *pos;
7332 + n = whlist->nh_num;
7333 + head = whlist->nh_head;
7334 + for (ul = 0; ul < n; ul++) {
7335 + hlist_for_each_entry(pos, head, wh_hash)
7336 + dpri("b%d, %.*s, %d\n",
7338 + pos->wh_str.len, pos->wh_str.name,
7344 +void au_dpri_vdir(struct au_vdir *vdir)
7347 + union au_vdir_deblk_p p;
7350 + if (!vdir || IS_ERR(vdir)) {
7351 + dpri("err %ld\n", PTR_ERR(vdir));
7355 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7356 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7357 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7358 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7359 + p.deblk = vdir->vd_deblk[ul];
7361 + dpri("[%lu]: %p\n", ul, o);
7365 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7366 + struct dentry *wh)
7371 + if (!inode || IS_ERR(inode)) {
7372 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7376 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7377 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7378 + && sizeof(inode->i_blocks) != sizeof(u64));
7380 + n = (void *)wh->d_name.name;
7381 + l = wh->d_name.len;
7384 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7385 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7387 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7388 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7389 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7390 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7391 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7392 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7393 + inode->i_generation,
7394 + l ? ", wh " : "", l, n);
7398 +void au_dpri_inode(struct inode *inode)
7400 + struct au_iinfo *iinfo;
7401 + struct au_hinode *hi;
7402 + aufs_bindex_t bindex;
7405 + err = do_pri_inode(-1, inode, -1, NULL);
7406 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7409 + iinfo = au_ii(inode);
7410 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7411 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7412 + if (iinfo->ii_btop < 0)
7415 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7416 + hi = au_hinode(iinfo, bindex);
7418 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7422 +void au_dpri_dalias(struct inode *inode)
7426 + spin_lock(&inode->i_lock);
7427 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7428 + au_dpri_dentry(d);
7429 + spin_unlock(&inode->i_lock);
7432 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7434 + struct dentry *wh = NULL;
7436 + struct inode *inode;
7437 + struct au_iinfo *iinfo;
7438 + struct au_hinode *hi;
7440 + if (!dentry || IS_ERR(dentry)) {
7441 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7444 + /* do not call dget_parent() here */
7445 + /* note: access d_xxx without d_lock */
7446 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7447 + bindex, dentry, dentry,
7448 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7449 + au_dcount(dentry), dentry->d_flags,
7450 + d_unhashed(dentry) ? "un" : "");
7453 + if (d_is_positive(dentry))
7454 + inode = d_inode(dentry);
7456 + && au_test_aufs(dentry->d_sb)
7458 + && !au_is_bad_inode(inode)) {
7459 + iinfo = au_ii(inode);
7460 + hi = au_hinode(iinfo, bindex);
7462 + wh = hi->hi_whdentry;
7464 + do_pri_inode(bindex, inode, hn, wh);
7468 +void au_dpri_dentry(struct dentry *dentry)
7470 + struct au_dinfo *dinfo;
7471 + aufs_bindex_t bindex;
7474 + err = do_pri_dentry(-1, dentry);
7475 + if (err || !au_test_aufs(dentry->d_sb))
7478 + dinfo = au_di(dentry);
7481 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7482 + dinfo->di_btop, dinfo->di_bbot,
7483 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7484 + dinfo->di_tmpfile);
7485 + if (dinfo->di_btop < 0)
7487 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7488 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7491 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7495 + if (!file || IS_ERR(file)) {
7496 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7501 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7502 + && au_test_aufs(file->f_path.dentry->d_sb)
7504 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7505 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7506 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7507 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7508 + file->f_version, file->f_pos, a);
7509 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7510 + do_pri_dentry(bindex, file->f_path.dentry);
7514 +void au_dpri_file(struct file *file)
7516 + struct au_finfo *finfo;
7517 + struct au_fidir *fidir;
7518 + struct au_hfile *hfile;
7519 + aufs_bindex_t bindex;
7522 + err = do_pri_file(-1, file);
7524 + || IS_ERR_OR_NULL(file->f_path.dentry)
7525 + || !au_test_aufs(file->f_path.dentry->d_sb))
7528 + finfo = au_fi(file);
7531 + if (finfo->fi_btop < 0)
7533 + fidir = finfo->fi_hdir;
7535 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7537 + for (bindex = finfo->fi_btop;
7538 + bindex >= 0 && bindex <= fidir->fd_bbot;
7540 + hfile = fidir->fd_hfile + bindex;
7541 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7545 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7547 + struct vfsmount *mnt;
7548 + struct super_block *sb;
7550 + if (!br || IS_ERR(br))
7552 + mnt = au_br_mnt(br);
7553 + if (!mnt || IS_ERR(mnt))
7556 + if (!sb || IS_ERR(sb))
7559 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7560 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7562 + bindex, br->br_perm, br->br_id, br->br_wbr,
7563 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7564 + sb->s_flags, sb->s_count,
7565 + atomic_read(&sb->s_active),
7566 + !!au_xino_file(br->br_xino, /*idx*/-1));
7570 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7574 +void au_dpri_sb(struct super_block *sb)
7576 + struct au_sbinfo *sbinfo;
7577 + aufs_bindex_t bindex;
7579 + /* to reduce stack size */
7581 + struct vfsmount mnt;
7582 + struct au_branch fake;
7585 + /* this function can be called from magic sysrq */
7586 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7587 + if (unlikely(!a)) {
7588 + dpri("no memory\n");
7592 + a->mnt.mnt_sb = sb;
7593 + a->fake.br_path.mnt = &a->mnt;
7594 + err = do_pri_br(-1, &a->fake);
7596 + dpri("dev 0x%x\n", sb->s_dev);
7597 + if (err || !au_test_aufs(sb))
7600 + sbinfo = au_sbi(sb);
7603 + dpri("nw %d, gen %u, kobj %d\n",
7604 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7605 + kref_read(&sbinfo->si_kobj.kref));
7606 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7607 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7610 +/* ---------------------------------------------------------------------- */
7612 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7614 + struct inode *h_inode, *inode = d_inode(dentry);
7615 + struct dentry *h_dentry;
7616 + aufs_bindex_t bindex, bbot, bi;
7618 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7621 + bbot = au_dbbot(dentry);
7622 + bi = au_ibbot(inode);
7625 + bindex = au_dbtop(dentry);
7626 + bi = au_ibtop(inode);
7630 + for (; bindex <= bbot; bindex++) {
7631 + h_dentry = au_h_dptr(dentry, bindex);
7634 + h_inode = au_h_iptr(inode, bindex);
7635 + if (unlikely(h_inode != d_inode(h_dentry))) {
7637 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7638 + AuDbgDentry(dentry);
7639 + AuDbgInode(inode);
7641 + if (au_test_fuse(h_inode->i_sb))
7649 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7652 + struct au_dcsub_pages dpages;
7653 + struct au_dpage *dpage;
7654 + struct dentry **dentries;
7656 + err = au_dpages_init(&dpages, GFP_NOFS);
7658 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7660 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7661 + dpage = dpages.dpages + i;
7662 + dentries = dpage->dentries;
7663 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7664 + AuDebugOn(au_digen_test(dentries[j], sigen));
7666 + au_dpages_free(&dpages);
7669 +void au_dbg_verify_kthread(void)
7671 + if (au_wkq_test()) {
7674 + * It may be recursive, but udba=notify between two aufs mounts,
7675 + * where a single ro branch is shared, is not a problem.
7681 +/* ---------------------------------------------------------------------- */
7683 +int __init au_debug_init(void)
7685 + aufs_bindex_t bindex;
7686 + struct au_vdir_destr destr;
7689 + AuDebugOn(bindex >= 0);
7692 + AuDebugOn(destr.len < NAME_MAX);
7694 +#ifdef CONFIG_4KSTACKS
7695 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7700 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7701 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7702 +++ linux/fs/aufs/debug.h 2022-03-21 14:49:05.719966344 +0100
7704 +/* SPDX-License-Identifier: GPL-2.0 */
7706 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7708 + * This program, aufs is free software; you can redistribute it and/or modify
7709 + * it under the terms of the GNU General Public License as published by
7710 + * the Free Software Foundation; either version 2 of the License, or
7711 + * (at your option) any later version.
7713 + * This program is distributed in the hope that it will be useful,
7714 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7715 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7716 + * GNU General Public License for more details.
7718 + * You should have received a copy of the GNU General Public License
7719 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7723 + * debug print functions
7726 +#ifndef __AUFS_DEBUG_H__
7727 +#define __AUFS_DEBUG_H__
7731 +#include <linux/atomic.h>
7732 +#include <linux/module.h>
7733 +#include <linux/kallsyms.h>
7734 +#include <linux/sysrq.h>
7736 +#ifdef CONFIG_AUFS_DEBUG
7737 +#define AuDebugOn(a) BUG_ON(a)
7739 +/* module parameter */
7740 +extern atomic_t aufs_debug;
7741 +static inline void au_debug_on(void)
7743 + atomic_inc(&aufs_debug);
7745 +static inline void au_debug_off(void)
7747 + atomic_dec_if_positive(&aufs_debug);
7750 +static inline int au_debug_test(void)
7752 + return atomic_read(&aufs_debug) > 0;
7755 +#define AuDebugOn(a) do {} while (0)
7756 +AuStubVoid(au_debug_on, void)
7757 +AuStubVoid(au_debug_off, void)
7758 +AuStubInt0(au_debug_test, void)
7759 +#endif /* CONFIG_AUFS_DEBUG */
7761 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7763 +/* ---------------------------------------------------------------------- */
7767 +#define AuDbg(fmt, ...) do { \
7768 + if (au_debug_test()) \
7769 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7771 +#define AuLabel(l) AuDbg(#l "\n")
7772 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7773 +#define AuWarn1(fmt, ...) do { \
7774 + static unsigned char _c; \
7776 + pr_warn(fmt, ##__VA_ARGS__); \
7779 +#define AuErr1(fmt, ...) do { \
7780 + static unsigned char _c; \
7782 + pr_err(fmt, ##__VA_ARGS__); \
7785 +#define AuIOErr1(fmt, ...) do { \
7786 + static unsigned char _c; \
7788 + AuIOErr(fmt, ##__VA_ARGS__); \
7791 +#define AuUnsupportMsg "This operation is not supported." \
7792 + " Please report this application to aufs-users ML."
7793 +#define AuUnsupport(fmt, ...) do { \
7794 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7798 +#define AuTraceErr(e) do { \
7799 + if (unlikely((e) < 0)) \
7800 + AuDbg("err %d\n", (int)(e)); \
7803 +#define AuTraceErrPtr(p) do { \
7805 + AuDbg("err %ld\n", PTR_ERR(p)); \
7808 +/* dirty macros for debug print, use with "%.*s" and caution */
7809 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7811 +/* ---------------------------------------------------------------------- */
7814 +#ifdef CONFIG_AUFS_DEBUG
7815 +extern struct mutex au_dbg_mtx;
7816 +extern char *au_plevel;
7818 +void au_dpri_whlist(struct au_nhash *whlist);
7820 +void au_dpri_vdir(struct au_vdir *vdir);
7822 +void au_dpri_inode(struct inode *inode);
7823 +void au_dpri_dalias(struct inode *inode);
7824 +void au_dpri_dentry(struct dentry *dentry);
7826 +void au_dpri_file(struct file *filp);
7827 +struct super_block;
7828 +void au_dpri_sb(struct super_block *sb);
7830 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7831 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7832 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7833 +void au_dbg_verify_kthread(void);
7835 +int __init au_debug_init(void);
7837 +#define AuDbgWhlist(w) do { \
7838 + mutex_lock(&au_dbg_mtx); \
7840 + au_dpri_whlist(w); \
7841 + mutex_unlock(&au_dbg_mtx); \
7844 +#define AuDbgVdir(v) do { \
7845 + mutex_lock(&au_dbg_mtx); \
7847 + au_dpri_vdir(v); \
7848 + mutex_unlock(&au_dbg_mtx); \
7851 +#define AuDbgInode(i) do { \
7852 + mutex_lock(&au_dbg_mtx); \
7854 + au_dpri_inode(i); \
7855 + mutex_unlock(&au_dbg_mtx); \
7858 +#define AuDbgDAlias(i) do { \
7859 + mutex_lock(&au_dbg_mtx); \
7861 + au_dpri_dalias(i); \
7862 + mutex_unlock(&au_dbg_mtx); \
7865 +#define AuDbgDentry(d) do { \
7866 + mutex_lock(&au_dbg_mtx); \
7868 + au_dpri_dentry(d); \
7869 + mutex_unlock(&au_dbg_mtx); \
7872 +#define AuDbgFile(f) do { \
7873 + mutex_lock(&au_dbg_mtx); \
7875 + au_dpri_file(f); \
7876 + mutex_unlock(&au_dbg_mtx); \
7879 +#define AuDbgSb(sb) do { \
7880 + mutex_lock(&au_dbg_mtx); \
7881 + AuDbg(#sb "\n"); \
7883 + mutex_unlock(&au_dbg_mtx); \
7886 +#define AuDbgSym(addr) do { \
7887 + char sym[KSYM_SYMBOL_LEN]; \
7888 + sprint_symbol(sym, (unsigned long)addr); \
7889 + AuDbg("%s\n", sym); \
7892 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7893 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7894 +AuStubVoid(au_dbg_verify_kthread, void)
7895 +AuStubInt0(__init au_debug_init, void)
7897 +#define AuDbgWhlist(w) do {} while (0)
7898 +#define AuDbgVdir(v) do {} while (0)
7899 +#define AuDbgInode(i) do {} while (0)
7900 +#define AuDbgDAlias(i) do {} while (0)
7901 +#define AuDbgDentry(d) do {} while (0)
7902 +#define AuDbgFile(f) do {} while (0)
7903 +#define AuDbgSb(sb) do {} while (0)
7904 +#define AuDbgSym(addr) do {} while (0)
7905 +#endif /* CONFIG_AUFS_DEBUG */
7907 +/* ---------------------------------------------------------------------- */
7909 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7910 +int __init au_sysrq_init(void);
7911 +void au_sysrq_fin(void);
7913 +#ifdef CONFIG_HW_CONSOLE
7914 +#define au_dbg_blocked() do { \
7916 + handle_sysrq('w'); \
7919 +AuStubVoid(au_dbg_blocked, void)
7923 +AuStubInt0(__init au_sysrq_init, void)
7924 +AuStubVoid(au_sysrq_fin, void)
7925 +AuStubVoid(au_dbg_blocked, void)
7926 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7928 +#endif /* __KERNEL__ */
7929 +#endif /* __AUFS_DEBUG_H__ */
7930 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7931 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7932 +++ linux/fs/aufs/dentry.c 2022-03-21 14:49:05.719966344 +0100
7934 +// SPDX-License-Identifier: GPL-2.0
7936 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7938 + * This program, aufs is free software; you can redistribute it and/or modify
7939 + * it under the terms of the GNU General Public License as published by
7940 + * the Free Software Foundation; either version 2 of the License, or
7941 + * (at your option) any later version.
7943 + * This program is distributed in the hope that it will be useful,
7944 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7945 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7946 + * GNU General Public License for more details.
7948 + * You should have received a copy of the GNU General Public License
7949 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7953 + * lookup and dentry operations
7956 +#include <linux/iversion.h>
7960 + * returns positive/negative dentry, NULL or an error.
7961 + * NULL means whiteout-ed or not-found.
7963 +static struct dentry*
7964 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7965 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7967 + struct dentry *h_dentry;
7968 + struct inode *h_inode;
7969 + struct au_branch *br;
7970 + struct user_namespace *h_userns;
7971 + struct path h_path;
7972 + int wh_found, opq;
7973 + unsigned char wh_able;
7974 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7975 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7979 + br = au_sbr(dentry->d_sb, bindex);
7980 + h_path.dentry = h_parent;
7981 + h_path.mnt = au_br_mnt(br);
7982 + h_userns = au_br_userns(br);
7983 + wh_able = !!au_br_whable(br->br_perm);
7985 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
7987 + h_dentry = ERR_PTR(wh_found);
7990 + if (unlikely(wh_found < 0))
7993 + /* We found a whiteout */
7994 + /* au_set_dbbot(dentry, bindex); */
7995 + au_set_dbwh(dentry, bindex);
7997 + return NULL; /* success */
8001 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8003 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8004 + if (IS_ERR(h_dentry)) {
8005 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8011 + h_inode = d_inode(h_dentry);
8012 + if (d_is_negative(h_dentry)) {
8015 + } else if (wh_found
8016 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8018 + else if (au_ftest_lkup(args->flags, DIRREN)
8020 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8021 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8022 + (unsigned long long)h_inode->i_ino);
8026 + if (au_dbbot(dentry) <= bindex)
8027 + au_set_dbbot(dentry, bindex);
8028 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8029 + au_set_dbtop(dentry, bindex);
8030 + au_set_h_dptr(dentry, bindex, h_dentry);
8032 + if (!d_is_dir(h_dentry)
8034 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8035 + goto out; /* success */
8037 + h_path.dentry = h_dentry;
8038 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8039 + opq = au_diropq_test(h_userns, &h_path);
8040 + inode_unlock_shared(h_inode);
8042 + au_set_dbdiropq(dentry, bindex);
8043 + else if (unlikely(opq < 0)) {
8044 + au_set_h_dptr(dentry, bindex, NULL);
8045 + h_dentry = ERR_PTR(opq);
8056 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8058 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8059 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8065 + * returns the number of lower positive dentries,
8066 + * otherwise an error.
8067 + * can be called at unlinking with @type is zero.
8069 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8070 + unsigned int flags)
8072 + int npositive, err;
8073 + aufs_bindex_t bindex, btail, bdiropq;
8074 + unsigned char isdir, dirperm1, dirren;
8075 + struct au_do_lookup_args args = {
8077 + .name = &dentry->d_name
8079 + struct dentry *parent;
8080 + struct super_block *sb;
8082 + sb = dentry->d_sb;
8083 + err = au_test_shwh(sb, args.name);
8084 + if (unlikely(err))
8087 + err = au_wh_name_alloc(&args.whname, args.name);
8088 + if (unlikely(err))
8091 + isdir = !!d_is_dir(dentry);
8092 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8093 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8095 + au_fset_lkup(args.flags, DIRREN);
8098 + parent = dget_parent(dentry);
8099 + btail = au_dbtaildir(parent);
8100 + for (bindex = btop; bindex <= btail; bindex++) {
8101 + struct dentry *h_parent, *h_dentry;
8102 + struct inode *h_inode, *h_dir;
8103 + struct au_branch *br;
8105 + h_dentry = au_h_dptr(dentry, bindex);
8107 + if (d_is_positive(h_dentry))
8111 + h_parent = au_h_dptr(parent, bindex);
8112 + if (!h_parent || !d_is_dir(h_parent))
8116 + /* if the inum matches, then use the prepared name */
8117 + err = au_dr_lkup_name(&args, bindex);
8118 + if (unlikely(err))
8122 + h_dir = d_inode(h_parent);
8123 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8124 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8125 + inode_unlock_shared(h_dir);
8126 + err = PTR_ERR(h_dentry);
8127 + if (IS_ERR(h_dentry))
8130 + au_fclr_lkup(args.flags, ALLOW_NEG);
8132 + au_fset_lkup(args.flags, IGNORE_PERM);
8134 + if (au_dbwh(dentry) == bindex)
8138 + if (d_is_negative(h_dentry))
8140 + h_inode = d_inode(h_dentry);
8143 + args.type = h_inode->i_mode & S_IFMT;
8144 + if (args.type != S_IFDIR)
8147 + /* the type of lower may be different */
8148 + bdiropq = au_dbdiropq(dentry);
8149 + if (bdiropq >= 0 && bdiropq <= bindex)
8152 + br = au_sbr(sb, bindex);
8154 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8155 + /*add_ent*/NULL)) {
8156 + /* prepare next name to lookup */
8157 + err = au_dr_lkup(&args, dentry, bindex);
8158 + if (unlikely(err))
8164 + AuLabel(positive);
8165 + au_update_dbtop(dentry);
8168 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8169 + && au_dbtop(dentry) < 0)) {
8171 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8177 + au_kfree_try_rcu(args.whname.name);
8179 + au_dr_lkup_fin(&args);
8184 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8185 + struct path *ppath)
8187 + struct dentry *dentry;
8190 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8191 + dentry = vfsub_lkup_one(name, ppath);
8193 + struct vfsub_lkup_one_args args = {
8199 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8200 + if (unlikely(wkq_err))
8201 + dentry = ERR_PTR(wkq_err);
8208 + * lookup @dentry on @bindex which should be negative.
8210 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8213 + struct dentry *parent, *h_dentry;
8214 + struct au_branch *br;
8215 + struct user_namespace *h_userns;
8216 + struct path h_ppath;
8218 + parent = dget_parent(dentry);
8219 + br = au_sbr(dentry->d_sb, bindex);
8220 + h_ppath.dentry = au_h_dptr(parent, bindex);
8221 + h_ppath.mnt = au_br_mnt(br);
8222 + h_userns = au_br_userns(br);
8224 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8226 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8227 + err = PTR_ERR(h_dentry);
8228 + if (IS_ERR(h_dentry))
8230 + if (unlikely(d_is_positive(h_dentry))) {
8232 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8238 + if (bindex < au_dbtop(dentry))
8239 + au_set_dbtop(dentry, bindex);
8240 + if (au_dbbot(dentry) < bindex)
8241 + au_set_dbbot(dentry, bindex);
8242 + au_set_h_dptr(dentry, bindex, h_dentry);
8249 +/* ---------------------------------------------------------------------- */
8251 +/* subset of struct inode */
8253 + unsigned long i_ino;
8254 + /* unsigned int i_nlink; */
8260 + blkcnt_t i_blocks;
8265 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8267 + ia->i_ino = h_inode->i_ino;
8268 + /* ia->i_nlink = h_inode->i_nlink; */
8269 + ia->i_uid = h_inode->i_uid;
8270 + ia->i_gid = h_inode->i_gid;
8271 + ia->i_version = inode_query_iversion(h_inode);
8273 + ia->i_size = h_inode->i_size;
8274 + ia->i_blocks = h_inode->i_blocks;
8276 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8279 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8281 + return ia->i_ino != h_inode->i_ino
8282 + /* || ia->i_nlink != h_inode->i_nlink */
8283 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8284 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8285 + || !inode_eq_iversion(h_inode, ia->i_version)
8287 + || ia->i_size != h_inode->i_size
8288 + || ia->i_blocks != h_inode->i_blocks
8290 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8293 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8294 + struct au_branch *br)
8297 + struct au_iattr ia;
8298 + struct inode *h_inode;
8299 + struct dentry *h_d;
8300 + struct super_block *h_sb;
8301 + struct path h_ppath;
8304 + memset(&ia, -1, sizeof(ia));
8305 + h_sb = h_dentry->d_sb;
8307 + if (d_is_positive(h_dentry)) {
8308 + h_inode = d_inode(h_dentry);
8309 + au_iattr_save(&ia, h_inode);
8310 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8311 + /* nfs d_revalidate may return 0 for negative dentry */
8312 + /* fuse d_revalidate always return 0 for negative dentry */
8315 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8316 + h_ppath.dentry = h_parent;
8317 + h_ppath.mnt = au_br_mnt(br);
8318 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8319 + err = PTR_ERR(h_d);
8324 + if (unlikely(h_d != h_dentry
8325 + || d_inode(h_d) != h_inode
8326 + || (h_inode && au_iattr_test(&ia, h_inode))))
8327 + err = au_busy_or_stale();
8335 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8336 + struct dentry *h_parent, struct au_branch *br)
8341 + if (udba == AuOpt_UDBA_REVAL
8342 + && !au_test_fs_remote(h_dentry->d_sb)) {
8344 + err = (d_inode(h_dentry->d_parent) != h_dir);
8345 + } else if (udba != AuOpt_UDBA_NONE)
8346 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8351 +/* ---------------------------------------------------------------------- */
8353 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8356 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8357 + struct au_hdentry tmp, *p, *q;
8358 + struct au_dinfo *dinfo;
8359 + struct super_block *sb;
8361 + DiMustWriteLock(dentry);
8363 + sb = dentry->d_sb;
8364 + dinfo = au_di(dentry);
8365 + bbot = dinfo->di_bbot;
8366 + bwh = dinfo->di_bwh;
8367 + bdiropq = dinfo->di_bdiropq;
8368 + bindex = dinfo->di_btop;
8369 + p = au_hdentry(dinfo, bindex);
8370 + for (; bindex <= bbot; bindex++, p++) {
8371 + if (!p->hd_dentry)
8374 + new_bindex = au_br_index(sb, p->hd_id);
8375 + if (new_bindex == bindex)
8378 + if (dinfo->di_bwh == bindex)
8380 + if (dinfo->di_bdiropq == bindex)
8381 + bdiropq = new_bindex;
8382 + if (new_bindex < 0) {
8384 + p->hd_dentry = NULL;
8388 + /* swap two lower dentries, and loop again */
8389 + q = au_hdentry(dinfo, new_bindex);
8393 + if (tmp.hd_dentry) {
8399 + dinfo->di_bwh = -1;
8400 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8401 + dinfo->di_bwh = bwh;
8403 + dinfo->di_bdiropq = -1;
8405 + && bdiropq <= au_sbbot(sb)
8406 + && au_sbr_whable(sb, bdiropq))
8407 + dinfo->di_bdiropq = bdiropq;
8410 + dinfo->di_btop = -1;
8411 + dinfo->di_bbot = -1;
8412 + bbot = au_dbbot(parent);
8414 + p = au_hdentry(dinfo, bindex);
8415 + for (; bindex <= bbot; bindex++, p++)
8416 + if (p->hd_dentry) {
8417 + dinfo->di_btop = bindex;
8421 + if (dinfo->di_btop >= 0) {
8423 + p = au_hdentry(dinfo, bindex);
8424 + for (; bindex >= 0; bindex--, p--)
8425 + if (p->hd_dentry) {
8426 + dinfo->di_bbot = bindex;
8435 +static void au_do_hide(struct dentry *dentry)
8437 + struct inode *inode;
8439 + if (d_really_is_positive(dentry)) {
8440 + inode = d_inode(dentry);
8441 + if (!d_is_dir(dentry)) {
8442 + if (inode->i_nlink && !d_unhashed(dentry))
8443 + drop_nlink(inode);
8445 + clear_nlink(inode);
8446 + /* stop next lookup */
8447 + inode->i_flags |= S_DEAD;
8449 + smp_mb(); /* necessary? */
8454 +static int au_hide_children(struct dentry *parent)
8456 + int err, i, j, ndentry;
8457 + struct au_dcsub_pages dpages;
8458 + struct au_dpage *dpage;
8459 + struct dentry *dentry;
8461 + err = au_dpages_init(&dpages, GFP_NOFS);
8462 + if (unlikely(err))
8464 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8465 + if (unlikely(err))
8468 + /* in reverse order */
8469 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8470 + dpage = dpages.dpages + i;
8471 + ndentry = dpage->ndentry;
8472 + for (j = ndentry - 1; j >= 0; j--) {
8473 + dentry = dpage->dentries[j];
8474 + if (dentry != parent)
8475 + au_do_hide(dentry);
8480 + au_dpages_free(&dpages);
8485 +static void au_hide(struct dentry *dentry)
8489 + AuDbgDentry(dentry);
8490 + if (d_is_dir(dentry)) {
8491 + /* shrink_dcache_parent(dentry); */
8492 + err = au_hide_children(dentry);
8493 + if (unlikely(err))
8494 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8497 + au_do_hide(dentry);
8501 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8503 + * a dirty branch is added
8504 + * - on the top of layers
8505 + * - in the middle of layers
8506 + * - to the bottom of layers
8508 + * on the added branch there exists
8511 + * - a same named entry
8513 + * * negative --> positive
8514 + * * positive --> positive
8515 + * - type is unchanged
8516 + * - type is changed
8518 + * * negative --> negative
8519 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8522 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8523 + struct au_dinfo *tmp)
8526 + aufs_bindex_t bindex, bbot;
8528 + struct dentry *dentry;
8529 + struct inode *inode;
8531 + } orig_h, tmp_h = {
8534 + struct au_hdentry *hd;
8535 + struct inode *inode, *h_inode;
8536 + struct dentry *h_dentry;
8539 + AuDebugOn(dinfo->di_btop < 0);
8541 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8542 + orig_h.inode = NULL;
8543 + if (d_is_positive(orig_h.dentry)) {
8544 + orig_h.inode = d_inode(orig_h.dentry);
8545 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8547 + if (tmp->di_btop >= 0) {
8548 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8549 + if (d_is_positive(tmp_h.dentry)) {
8550 + tmp_h.inode = d_inode(tmp_h.dentry);
8551 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8556 + if (d_really_is_positive(dentry))
8557 + inode = d_inode(dentry);
8558 + if (!orig_h.inode) {
8559 + AuDbg("negative originally\n");
8565 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8566 + AuDebugOn(dinfo->di_bdiropq != -1);
8568 + if (!tmp_h.inode) {
8569 + AuDbg("negative --> negative\n");
8570 + /* should have only one negative lower */
8571 + if (tmp->di_btop >= 0
8572 + && tmp->di_btop < dinfo->di_btop) {
8573 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8574 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8575 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8576 + au_di_cp(dinfo, tmp);
8577 + hd = au_hdentry(tmp, tmp->di_btop);
8578 + au_set_h_dptr(dentry, tmp->di_btop,
8579 + dget(hd->hd_dentry));
8581 + au_dbg_verify_dinode(dentry);
8583 + AuDbg("negative --> positive\n");
8585 + * similar to the behaviour of creating with bypassing
8587 + * unhash it in order to force an error in the
8588 + * succeeding create operation.
8589 + * we should not set S_DEAD here.
8592 + /* au_di_swap(tmp, dinfo); */
8593 + au_dbg_verify_dinode(dentry);
8596 + AuDbg("positive originally\n");
8597 + /* inode may be NULL */
8598 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8599 + if (!tmp_h.inode) {
8600 + AuDbg("positive --> negative\n");
8601 + /* or bypassing aufs */
8603 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8604 + dinfo->di_bwh = tmp->di_bwh;
8606 + err = au_refresh_hinode_self(inode);
8607 + au_dbg_verify_dinode(dentry);
8608 + } else if (orig_h.mode == tmp_h.mode) {
8609 + AuDbg("positive --> positive, same type\n");
8610 + if (!S_ISDIR(orig_h.mode)
8611 + && dinfo->di_btop > tmp->di_btop) {
8613 + * similar to the behaviour of removing and
8618 + err = au_refresh_hinode_self(inode);
8619 + au_dbg_verify_dinode(dentry);
8621 + /* fill empty slots */
8622 + if (dinfo->di_btop > tmp->di_btop)
8623 + dinfo->di_btop = tmp->di_btop;
8624 + if (dinfo->di_bbot < tmp->di_bbot)
8625 + dinfo->di_bbot = tmp->di_bbot;
8626 + dinfo->di_bwh = tmp->di_bwh;
8627 + dinfo->di_bdiropq = tmp->di_bdiropq;
8628 + bbot = dinfo->di_bbot;
8629 + bindex = tmp->di_btop;
8630 + hd = au_hdentry(tmp, bindex);
8631 + for (; bindex <= bbot; bindex++, hd++) {
8632 + if (au_h_dptr(dentry, bindex))
8634 + h_dentry = hd->hd_dentry;
8637 + AuDebugOn(d_is_negative(h_dentry));
8638 + h_inode = d_inode(h_dentry);
8639 + AuDebugOn(orig_h.mode
8640 + != (h_inode->i_mode
8642 + au_set_h_dptr(dentry, bindex,
8646 + err = au_refresh_hinode(inode, dentry);
8647 + au_dbg_verify_dinode(dentry);
8650 + AuDbg("positive --> positive, different type\n");
8651 + /* similar to the behaviour of removing and creating */
8654 + err = au_refresh_hinode_self(inode);
8655 + au_dbg_verify_dinode(dentry);
8663 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8665 + const struct dentry_operations *dop
8666 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8667 + static const unsigned int mask
8668 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8670 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8672 + if (dentry->d_op == dop)
8675 + AuDbg("%pd\n", dentry);
8676 + spin_lock(&dentry->d_lock);
8677 + if (dop == &aufs_dop)
8678 + dentry->d_flags |= mask;
8680 + dentry->d_flags &= ~mask;
8681 + dentry->d_op = dop;
8682 + spin_unlock(&dentry->d_lock);
8685 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8687 + int err, ebrange, nbr;
8688 + unsigned int sigen;
8689 + struct au_dinfo *dinfo, *tmp;
8690 + struct super_block *sb;
8691 + struct inode *inode;
8693 + DiMustWriteLock(dentry);
8694 + AuDebugOn(IS_ROOT(dentry));
8695 + AuDebugOn(d_really_is_negative(parent));
8697 + sb = dentry->d_sb;
8698 + sigen = au_sigen(sb);
8699 + err = au_digen_test(parent, sigen);
8700 + if (unlikely(err))
8703 + nbr = au_sbbot(sb) + 1;
8704 + dinfo = au_di(dentry);
8705 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8706 + if (unlikely(err))
8708 + ebrange = au_dbrange_test(dentry);
8710 + ebrange = au_do_refresh_hdentry(dentry, parent);
8712 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8713 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8714 + if (d_really_is_positive(dentry)) {
8715 + inode = d_inode(dentry);
8716 + err = au_refresh_hinode_self(inode);
8718 + au_dbg_verify_dinode(dentry);
8720 + goto out_dgen; /* success */
8724 + /* temporary dinfo */
8725 + AuDbgDentry(dentry);
8727 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8728 + if (unlikely(!tmp))
8730 + au_di_swap(tmp, dinfo);
8731 + /* returns the number of positive dentries */
8733 + * if current working dir is removed, it returns an error.
8734 + * but the dentry is legal.
8736 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8737 + AuDbgDentry(dentry);
8738 + au_di_swap(tmp, dinfo);
8739 + if (err == -ENOENT)
8742 + /* compare/refresh by dinfo */
8743 + AuDbgDentry(dentry);
8744 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8745 + au_dbg_verify_dinode(dentry);
8748 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8749 + au_rw_write_unlock(&tmp->di_rwsem);
8751 + if (unlikely(err))
8755 + au_update_digen(dentry);
8757 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8758 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8759 + AuDbgDentry(dentry);
8765 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8766 + struct dentry *dentry, aufs_bindex_t bindex)
8771 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8774 + AuDbg("b%d\n", bindex);
8776 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8777 + * due to whiteout and branch permission.
8779 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8780 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8781 + /* it may return tri-state */
8782 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8784 + if (unlikely(valid < 0))
8794 +/* todo: remove this */
8795 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8796 + unsigned int flags, int do_udba, int dirren)
8799 + umode_t mode, h_mode;
8800 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8801 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8802 + struct inode *h_inode, *h_cached_inode;
8803 + struct dentry *h_dentry;
8804 + struct qstr *name, *h_name;
8811 + unhashed = !!d_unhashed(dentry);
8812 + is_root = !!IS_ROOT(dentry);
8813 + name = &dentry->d_name;
8814 + tmpfile = au_di(dentry)->di_tmpfile;
8817 + * Theoretically, REVAL test should be unnecessary in case of
8819 + * But {fs,i}notify doesn't fire some necessary events,
8820 + * IN_ATTRIB for atime/nlink/pageio
8821 + * Let's do REVAL test too.
8823 + if (do_udba && inode) {
8824 + mode = (inode->i_mode & S_IFMT);
8825 + plus = (inode->i_nlink > 0);
8826 + ibs = au_ibtop(inode);
8827 + ibe = au_ibbot(inode);
8830 + btop = au_dbtop(dentry);
8832 + if (inode && S_ISDIR(inode->i_mode))
8833 + btail = au_dbtaildir(dentry);
8834 + for (bindex = btop; bindex <= btail; bindex++) {
8835 + h_dentry = au_h_dptr(dentry, bindex);
8839 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8840 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8841 + spin_lock(&h_dentry->d_lock);
8842 + h_name = &h_dentry->d_name;
8843 + if (unlikely(do_udba
8846 + && (unhashed != !!d_unhashed(h_dentry)
8847 + || (!tmpfile && !dirren
8848 + && !au_qstreq(name, h_name))
8851 + && !(flags & LOOKUP_OPEN)
8852 + && (h_dentry->d_flags
8853 + & DCACHE_NFSFS_RENAMED)))
8857 + h_unhashed = d_unhashed(h_dentry);
8858 + spin_unlock(&h_dentry->d_lock);
8859 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8860 + unhashed, h_unhashed, dentry, h_dentry);
8863 + spin_unlock(&h_dentry->d_lock);
8865 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8866 + if (unlikely(err))
8867 + /* do not goto err, to keep the errno */
8870 + /* todo: plink too? */
8875 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8879 + if (d_is_positive(h_dentry))
8880 + h_inode = d_inode(h_dentry);
8883 + h_cached_inode = h_inode;
8885 + h_mode = (h_inode->i_mode & S_IFMT);
8886 + h_plus = (h_inode->i_nlink > 0);
8888 + if (inode && ibs <= bindex && bindex <= ibe)
8889 + h_cached_inode = au_h_iptr(inode, bindex);
8892 + if (unlikely(plus != h_plus && !tmpfile))
8895 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8897 + && !IS_ROOT(h_dentry)
8898 + && unhashed != d_unhashed(h_dentry)))
8901 + if (unlikely(mode != h_mode
8902 + || h_cached_inode != h_inode))
8915 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8916 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8919 + struct dentry *parent;
8921 + if (!au_digen_test(dentry, sigen))
8924 + parent = dget_parent(dentry);
8925 + di_read_lock_parent(parent, AuLock_IR);
8926 + AuDebugOn(au_digen_test(parent, sigen));
8927 + au_dbg_verify_gen(parent, sigen);
8928 + err = au_refresh_dentry(dentry, parent);
8929 + di_read_unlock(parent, AuLock_IR);
8935 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8938 + struct dentry *d, *parent;
8940 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8941 + return simple_reval_dpath(dentry, sigen);
8943 + /* slow loop, keep it simple and stupid */
8944 + /* cf: au_cpup_dirs() */
8947 + while (au_digen_test(dentry, sigen)) {
8951 + parent = dget_parent(d);
8952 + if (!au_digen_test(parent, sigen))
8958 + di_write_lock_child2(d);
8960 + /* someone might update our dentry while we were sleeping */
8961 + if (au_digen_test(d, sigen)) {
8963 + * todo: consolidate with simple_reval_dpath(),
8964 + * do_refresh() and au_reval_for_attr().
8966 + di_read_lock_parent(parent, AuLock_IR);
8967 + err = au_refresh_dentry(d, parent);
8968 + di_read_unlock(parent, AuLock_IR);
8972 + di_write_unlock(d);
8974 + if (unlikely(err))
8982 + * if valid returns 1, otherwise 0.
8984 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8987 + unsigned int sigen;
8988 + unsigned char do_udba, dirren;
8989 + struct super_block *sb;
8990 + struct inode *inode;
8992 + /* todo: support rcu-walk? */
8993 + if (flags & LOOKUP_RCU)
8997 + if (unlikely(!au_di(dentry)))
9001 + sb = dentry->d_sb;
9004 + * i_mutex of parent dir may be held,
9005 + * but we should not return 'invalid' due to busy.
9007 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9008 + if (unlikely(err)) {
9014 + if (d_really_is_positive(dentry))
9015 + inode = d_inode(dentry);
9016 + if (unlikely(inode && au_is_bad_inode(inode))) {
9021 + if (unlikely(au_dbrange_test(dentry))) {
9027 + sigen = au_sigen(sb);
9028 + if (au_digen_test(dentry, sigen)) {
9029 + AuDebugOn(IS_ROOT(dentry));
9030 + err = au_reval_dpath(dentry, sigen);
9031 + if (unlikely(err)) {
9036 + di_downgrade_lock(dentry, AuLock_IR);
9039 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9041 + && !(inode->i_state && I_LINKABLE)
9042 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9047 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9048 + if (do_udba && inode) {
9049 + aufs_bindex_t btop = au_ibtop(inode);
9050 + struct inode *h_inode;
9053 + h_inode = au_h_iptr(inode, btop);
9054 + if (h_inode && au_test_higen(inode, h_inode)) {
9061 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9062 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9063 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9065 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9071 + di_downgrade_lock(dentry, AuLock_IR);
9073 + aufs_read_unlock(dentry, AuLock_IR);
9078 + AuDbg("%pd invalid, %d\n", dentry, valid);
9084 +static void aufs_d_release(struct dentry *dentry)
9086 + if (au_di(dentry)) {
9087 + au_di_fin(dentry);
9088 + au_hn_di_reinit(dentry);
9092 +const struct dentry_operations aufs_dop = {
9093 + .d_revalidate = aufs_d_revalidate,
9094 + .d_weak_revalidate = aufs_d_revalidate,
9095 + .d_release = aufs_d_release
9098 +/* aufs_dop without d_revalidate */
9099 +const struct dentry_operations aufs_dop_noreval = {
9100 + .d_release = aufs_d_release
9102 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9103 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9104 +++ linux/fs/aufs/dentry.h 2022-03-21 14:49:05.719966344 +0100
9106 +/* SPDX-License-Identifier: GPL-2.0 */
9108 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9110 + * This program, aufs is free software; you can redistribute it and/or modify
9111 + * it under the terms of the GNU General Public License as published by
9112 + * the Free Software Foundation; either version 2 of the License, or
9113 + * (at your option) any later version.
9115 + * This program is distributed in the hope that it will be useful,
9116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9118 + * GNU General Public License for more details.
9120 + * You should have received a copy of the GNU General Public License
9121 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9125 + * lookup and dentry operations
9128 +#ifndef __AUFS_DENTRY_H__
9129 +#define __AUFS_DENTRY_H__
9133 +#include <linux/dcache.h>
9134 +#include "dirren.h"
9137 +struct au_hdentry {
9138 + struct dentry *hd_dentry;
9139 + aufs_bindex_t hd_id;
9143 + atomic_t di_generation;
9145 + struct au_rwsem di_rwsem;
9146 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9147 + unsigned char di_tmpfile; /* to allow the different name */
9148 + struct au_hdentry *di_hdentry;
9149 + struct rcu_head rcu;
9150 +} ____cacheline_aligned_in_smp;
9152 +/* ---------------------------------------------------------------------- */
9154 +/* flags for au_lkup_dentry() */
9155 +#define AuLkup_ALLOW_NEG 1
9156 +#define AuLkup_IGNORE_PERM (1 << 1)
9157 +#define AuLkup_DIRREN (1 << 2)
9158 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9159 +#define au_fset_lkup(flags, name) \
9160 + do { (flags) |= AuLkup_##name; } while (0)
9161 +#define au_fclr_lkup(flags, name) \
9162 + do { (flags) &= ~AuLkup_##name; } while (0)
9164 +#ifndef CONFIG_AUFS_DIRREN
9165 +#undef AuLkup_DIRREN
9166 +#define AuLkup_DIRREN 0
9169 +struct au_do_lookup_args {
9170 + unsigned int flags;
9172 + struct qstr whname, *name;
9173 + struct au_dr_lookup dirren;
9176 +/* ---------------------------------------------------------------------- */
9179 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9181 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9182 + struct path *ppath);
9183 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9184 + struct dentry *h_parent, struct au_branch *br);
9186 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9187 + unsigned int flags);
9188 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9189 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9190 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9191 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9194 +void au_di_init_once(void *_di);
9195 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9196 +void au_di_free(struct au_dinfo *dinfo);
9197 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9198 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9199 +int au_di_init(struct dentry *dentry);
9200 +void au_di_fin(struct dentry *dentry);
9201 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9203 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9204 +void di_read_unlock(struct dentry *d, int flags);
9205 +void di_downgrade_lock(struct dentry *d, int flags);
9206 +void di_write_lock(struct dentry *d, unsigned int lsc);
9207 +void di_write_unlock(struct dentry *d);
9208 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9209 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9210 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9212 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9213 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9214 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9215 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9217 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9218 + struct dentry *h_dentry);
9219 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9220 +int au_dbrange_test(struct dentry *dentry);
9221 +void au_update_digen(struct dentry *dentry);
9222 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9223 +void au_update_dbtop(struct dentry *dentry);
9224 +void au_update_dbbot(struct dentry *dentry);
9225 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9227 +/* ---------------------------------------------------------------------- */
9229 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9231 + return dentry->d_fsdata;
9234 +/* ---------------------------------------------------------------------- */
9236 +/* lock subclass for dinfo */
9238 + AuLsc_DI_CHILD, /* child first */
9239 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9240 + AuLsc_DI_CHILD3, /* copyup dirs */
9244 + AuLsc_DI_TMP /* temp for replacing dinfo */
9248 + * di_read_lock_child, di_write_lock_child,
9249 + * di_read_lock_child2, di_write_lock_child2,
9250 + * di_read_lock_child3, di_write_lock_child3,
9251 + * di_read_lock_parent, di_write_lock_parent,
9252 + * di_read_lock_parent2, di_write_lock_parent2,
9253 + * di_read_lock_parent3, di_write_lock_parent3,
9255 +#define AuReadLockFunc(name, lsc) \
9256 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9257 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9259 +#define AuWriteLockFunc(name, lsc) \
9260 +static inline void di_write_lock_##name(struct dentry *d) \
9261 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9263 +#define AuRWLockFuncs(name, lsc) \
9264 + AuReadLockFunc(name, lsc) \
9265 + AuWriteLockFunc(name, lsc)
9267 +AuRWLockFuncs(child, CHILD);
9268 +AuRWLockFuncs(child2, CHILD2);
9269 +AuRWLockFuncs(child3, CHILD3);
9270 +AuRWLockFuncs(parent, PARENT);
9271 +AuRWLockFuncs(parent2, PARENT2);
9272 +AuRWLockFuncs(parent3, PARENT3);
9274 +#undef AuReadLockFunc
9275 +#undef AuWriteLockFunc
9276 +#undef AuRWLockFuncs
9278 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9279 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9280 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9282 +/* ---------------------------------------------------------------------- */
9284 +/* todo: memory barrier? */
9285 +static inline unsigned int au_digen(struct dentry *d)
9287 + return atomic_read(&au_di(d)->di_generation);
9290 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9292 + hdentry->hd_dentry = NULL;
9295 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9296 + aufs_bindex_t bindex)
9298 + return di->di_hdentry + bindex;
9301 +static inline void au_hdput(struct au_hdentry *hd)
9304 + dput(hd->hd_dentry);
9307 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9309 + DiMustAnyLock(dentry);
9310 + return au_di(dentry)->di_btop;
9313 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9315 + DiMustAnyLock(dentry);
9316 + return au_di(dentry)->di_bbot;
9319 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9321 + DiMustAnyLock(dentry);
9322 + return au_di(dentry)->di_bwh;
9325 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9327 + DiMustAnyLock(dentry);
9328 + return au_di(dentry)->di_bdiropq;
9331 +/* todo: hard/soft set? */
9332 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9334 + DiMustWriteLock(dentry);
9335 + au_di(dentry)->di_btop = bindex;
9338 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9340 + DiMustWriteLock(dentry);
9341 + au_di(dentry)->di_bbot = bindex;
9344 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9346 + DiMustWriteLock(dentry);
9347 + /* dbwh can be outside of btop - bbot range */
9348 + au_di(dentry)->di_bwh = bindex;
9351 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9353 + DiMustWriteLock(dentry);
9354 + au_di(dentry)->di_bdiropq = bindex;
9357 +/* ---------------------------------------------------------------------- */
9359 +#ifdef CONFIG_AUFS_HNOTIFY
9360 +static inline void au_digen_dec(struct dentry *d)
9362 + atomic_dec(&au_di(d)->di_generation);
9365 +static inline void au_hn_di_reinit(struct dentry *dentry)
9367 + dentry->d_fsdata = NULL;
9370 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9371 +#endif /* CONFIG_AUFS_HNOTIFY */
9373 +#endif /* __KERNEL__ */
9374 +#endif /* __AUFS_DENTRY_H__ */
9375 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9376 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9377 +++ linux/fs/aufs/dinfo.c 2022-03-21 14:49:05.719966344 +0100
9379 +// SPDX-License-Identifier: GPL-2.0
9381 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9383 + * This program, aufs is free software; you can redistribute it and/or modify
9384 + * it under the terms of the GNU General Public License as published by
9385 + * the Free Software Foundation; either version 2 of the License, or
9386 + * (at your option) any later version.
9388 + * This program is distributed in the hope that it will be useful,
9389 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9390 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9391 + * GNU General Public License for more details.
9393 + * You should have received a copy of the GNU General Public License
9394 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9398 + * dentry private data
9403 +void au_di_init_once(void *_dinfo)
9405 + struct au_dinfo *dinfo = _dinfo;
9407 + au_rw_init(&dinfo->di_rwsem);
9410 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9412 + struct au_dinfo *dinfo;
9415 + dinfo = au_cache_alloc_dinfo();
9416 + if (unlikely(!dinfo))
9419 + nbr = au_sbbot(sb) + 1;
9422 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9423 + if (dinfo->di_hdentry) {
9424 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9425 + dinfo->di_btop = -1;
9426 + dinfo->di_bbot = -1;
9427 + dinfo->di_bwh = -1;
9428 + dinfo->di_bdiropq = -1;
9429 + dinfo->di_tmpfile = 0;
9430 + for (i = 0; i < nbr; i++)
9431 + dinfo->di_hdentry[i].hd_id = -1;
9435 + au_cache_free_dinfo(dinfo);
9442 +void au_di_free(struct au_dinfo *dinfo)
9444 + struct au_hdentry *p;
9445 + aufs_bindex_t bbot, bindex;
9447 + /* dentry may not be revalidated */
9448 + bindex = dinfo->di_btop;
9449 + if (bindex >= 0) {
9450 + bbot = dinfo->di_bbot;
9451 + p = au_hdentry(dinfo, bindex);
9452 + while (bindex++ <= bbot)
9455 + au_kfree_try_rcu(dinfo->di_hdentry);
9456 + au_cache_free_dinfo(dinfo);
9459 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9461 + struct au_hdentry *p;
9464 + AuRwMustWriteLock(&a->di_rwsem);
9465 + AuRwMustWriteLock(&b->di_rwsem);
9467 +#define DiSwap(v, name) \
9469 + v = a->di_##name; \
9470 + a->di_##name = b->di_##name; \
9471 + b->di_##name = v; \
9474 + DiSwap(p, hdentry);
9478 + DiSwap(bi, bdiropq);
9484 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9486 + AuRwMustWriteLock(&dst->di_rwsem);
9487 + AuRwMustWriteLock(&src->di_rwsem);
9489 + dst->di_btop = src->di_btop;
9490 + dst->di_bbot = src->di_bbot;
9491 + dst->di_bwh = src->di_bwh;
9492 + dst->di_bdiropq = src->di_bdiropq;
9496 +int au_di_init(struct dentry *dentry)
9499 + struct super_block *sb;
9500 + struct au_dinfo *dinfo;
9503 + sb = dentry->d_sb;
9504 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9506 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9507 + /* smp_mb(); */ /* atomic_set */
9508 + dentry->d_fsdata = dinfo;
9515 +void au_di_fin(struct dentry *dentry)
9517 + struct au_dinfo *dinfo;
9519 + dinfo = au_di(dentry);
9520 + AuRwDestroy(&dinfo->di_rwsem);
9521 + au_di_free(dinfo);
9524 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9527 + struct au_hdentry *hdp;
9529 + AuRwMustWriteLock(&dinfo->di_rwsem);
9532 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9534 + sz = sizeof(*hdp);
9535 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9538 + dinfo->di_hdentry = hdp;
9545 +/* ---------------------------------------------------------------------- */
9547 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9550 + case AuLsc_DI_CHILD:
9551 + ii_write_lock_child(inode);
9553 + case AuLsc_DI_CHILD2:
9554 + ii_write_lock_child2(inode);
9556 + case AuLsc_DI_CHILD3:
9557 + ii_write_lock_child3(inode);
9559 + case AuLsc_DI_PARENT:
9560 + ii_write_lock_parent(inode);
9562 + case AuLsc_DI_PARENT2:
9563 + ii_write_lock_parent2(inode);
9565 + case AuLsc_DI_PARENT3:
9566 + ii_write_lock_parent3(inode);
9573 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9576 + case AuLsc_DI_CHILD:
9577 + ii_read_lock_child(inode);
9579 + case AuLsc_DI_CHILD2:
9580 + ii_read_lock_child2(inode);
9582 + case AuLsc_DI_CHILD3:
9583 + ii_read_lock_child3(inode);
9585 + case AuLsc_DI_PARENT:
9586 + ii_read_lock_parent(inode);
9588 + case AuLsc_DI_PARENT2:
9589 + ii_read_lock_parent2(inode);
9591 + case AuLsc_DI_PARENT3:
9592 + ii_read_lock_parent3(inode);
9599 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9601 + struct inode *inode;
9603 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9604 + if (d_really_is_positive(d)) {
9605 + inode = d_inode(d);
9606 + if (au_ftest_lock(flags, IW))
9607 + do_ii_write_lock(inode, lsc);
9608 + else if (au_ftest_lock(flags, IR))
9609 + do_ii_read_lock(inode, lsc);
9613 +void di_read_unlock(struct dentry *d, int flags)
9615 + struct inode *inode;
9617 + if (d_really_is_positive(d)) {
9618 + inode = d_inode(d);
9619 + if (au_ftest_lock(flags, IW)) {
9620 + au_dbg_verify_dinode(d);
9621 + ii_write_unlock(inode);
9622 + } else if (au_ftest_lock(flags, IR)) {
9623 + au_dbg_verify_dinode(d);
9624 + ii_read_unlock(inode);
9627 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9630 +void di_downgrade_lock(struct dentry *d, int flags)
9632 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9633 + ii_downgrade_lock(d_inode(d));
9634 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9637 +void di_write_lock(struct dentry *d, unsigned int lsc)
9639 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9640 + if (d_really_is_positive(d))
9641 + do_ii_write_lock(d_inode(d), lsc);
9644 +void di_write_unlock(struct dentry *d)
9646 + au_dbg_verify_dinode(d);
9647 + if (d_really_is_positive(d))
9648 + ii_write_unlock(d_inode(d));
9649 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9652 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9654 + AuDebugOn(d1 == d2
9655 + || d_inode(d1) == d_inode(d2)
9656 + || d1->d_sb != d2->d_sb);
9658 + if ((isdir && au_test_subdir(d1, d2))
9660 + di_write_lock_child(d1);
9661 + di_write_lock_child2(d2);
9663 + di_write_lock_child(d2);
9664 + di_write_lock_child2(d1);
9668 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9670 + AuDebugOn(d1 == d2
9671 + || d_inode(d1) == d_inode(d2)
9672 + || d1->d_sb != d2->d_sb);
9674 + if ((isdir && au_test_subdir(d1, d2))
9676 + di_write_lock_parent(d1);
9677 + di_write_lock_parent2(d2);
9679 + di_write_lock_parent(d2);
9680 + di_write_lock_parent2(d1);
9684 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9686 + di_write_unlock(d1);
9687 + if (d_inode(d1) == d_inode(d2))
9688 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9690 + di_write_unlock(d2);
9693 +/* ---------------------------------------------------------------------- */
9695 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9699 + DiMustAnyLock(dentry);
9701 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9703 + AuDebugOn(bindex < 0);
9704 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9705 + AuDebugOn(d && au_dcount(d) <= 0);
9710 + * extended version of au_h_dptr().
9711 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9714 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9716 + struct dentry *h_dentry;
9717 + struct inode *inode, *h_inode;
9719 + AuDebugOn(d_really_is_negative(dentry));
9722 + if (au_dbtop(dentry) <= bindex
9723 + && bindex <= au_dbbot(dentry))
9724 + h_dentry = au_h_dptr(dentry, bindex);
9725 + if (h_dentry && !au_d_linkable(h_dentry)) {
9727 + goto out; /* success */
9730 + inode = d_inode(dentry);
9731 + AuDebugOn(bindex < au_ibtop(inode));
9732 + AuDebugOn(au_ibbot(inode) < bindex);
9733 + h_inode = au_h_iptr(inode, bindex);
9734 + h_dentry = d_find_alias(h_inode);
9736 + if (!IS_ERR(h_dentry)) {
9737 + if (!au_d_linkable(h_dentry))
9738 + goto out; /* success */
9744 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9745 + h_dentry = au_plink_lkup(inode, bindex);
9746 + AuDebugOn(!h_dentry);
9747 + if (!IS_ERR(h_dentry)) {
9748 + if (!au_d_hashed_positive(h_dentry))
9749 + goto out; /* success */
9756 + AuDbgDentry(h_dentry);
9760 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9762 + aufs_bindex_t bbot, bwh;
9764 + bbot = au_dbbot(dentry);
9766 + bwh = au_dbwh(dentry);
9769 + if (0 < bwh && bwh < bbot)
9775 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9777 + aufs_bindex_t bbot, bopq;
9779 + bbot = au_dbtail(dentry);
9781 + bopq = au_dbdiropq(dentry);
9782 + if (0 <= bopq && bopq < bbot)
9788 +/* ---------------------------------------------------------------------- */
9790 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9791 + struct dentry *h_dentry)
9793 + struct au_dinfo *dinfo;
9794 + struct au_hdentry *hd;
9795 + struct au_branch *br;
9797 + DiMustWriteLock(dentry);
9799 + dinfo = au_di(dentry);
9800 + hd = au_hdentry(dinfo, bindex);
9802 + hd->hd_dentry = h_dentry;
9804 + br = au_sbr(dentry->d_sb, bindex);
9805 + hd->hd_id = br->br_id;
9809 +int au_dbrange_test(struct dentry *dentry)
9812 + aufs_bindex_t btop, bbot;
9815 + btop = au_dbtop(dentry);
9816 + bbot = au_dbbot(dentry);
9818 + AuDebugOn(bbot < 0 && btop > bbot);
9821 + AuDebugOn(bbot >= 0);
9827 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9832 + if (unlikely(au_digen(dentry) != sigen
9833 + || au_iigen_test(d_inode(dentry), sigen)))
9839 +void au_update_digen(struct dentry *dentry)
9841 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9842 + /* smp_mb(); */ /* atomic_set */
9845 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9847 + struct au_dinfo *dinfo;
9848 + struct dentry *h_d;
9849 + struct au_hdentry *hdp;
9850 + aufs_bindex_t bindex, bbot;
9852 + DiMustWriteLock(dentry);
9854 + dinfo = au_di(dentry);
9855 + if (!dinfo || dinfo->di_btop < 0)
9858 + if (do_put_zero) {
9859 + bbot = dinfo->di_bbot;
9860 + bindex = dinfo->di_btop;
9861 + hdp = au_hdentry(dinfo, bindex);
9862 + for (; bindex <= bbot; bindex++, hdp++) {
9863 + h_d = hdp->hd_dentry;
9864 + if (h_d && d_is_negative(h_d))
9865 + au_set_h_dptr(dentry, bindex, NULL);
9869 + dinfo->di_btop = 0;
9870 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9871 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9872 + if (hdp->hd_dentry)
9874 + if (dinfo->di_btop > dinfo->di_bbot) {
9875 + dinfo->di_btop = -1;
9876 + dinfo->di_bbot = -1;
9880 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9881 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9882 + if (hdp->hd_dentry)
9884 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9887 +void au_update_dbtop(struct dentry *dentry)
9889 + aufs_bindex_t bindex, bbot;
9890 + struct dentry *h_dentry;
9892 + bbot = au_dbbot(dentry);
9893 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9894 + h_dentry = au_h_dptr(dentry, bindex);
9897 + if (d_is_positive(h_dentry)) {
9898 + au_set_dbtop(dentry, bindex);
9901 + au_set_h_dptr(dentry, bindex, NULL);
9905 +void au_update_dbbot(struct dentry *dentry)
9907 + aufs_bindex_t bindex, btop;
9908 + struct dentry *h_dentry;
9910 + btop = au_dbtop(dentry);
9911 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9912 + h_dentry = au_h_dptr(dentry, bindex);
9915 + if (d_is_positive(h_dentry)) {
9916 + au_set_dbbot(dentry, bindex);
9919 + au_set_h_dptr(dentry, bindex, NULL);
9923 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9925 + aufs_bindex_t bindex, bbot;
9927 + bbot = au_dbbot(dentry);
9928 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9929 + if (au_h_dptr(dentry, bindex) == h_dentry)
9933 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9934 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9935 +++ linux/fs/aufs/dir.c 2022-03-21 14:49:05.719966344 +0100
9937 +// SPDX-License-Identifier: GPL-2.0
9939 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9941 + * This program, aufs is free software; you can redistribute it and/or modify
9942 + * it under the terms of the GNU General Public License as published by
9943 + * the Free Software Foundation; either version 2 of the License, or
9944 + * (at your option) any later version.
9946 + * This program is distributed in the hope that it will be useful,
9947 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9948 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9949 + * GNU General Public License for more details.
9951 + * You should have received a copy of the GNU General Public License
9952 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9956 + * directory operations
9959 +#include <linux/fs_stack.h>
9960 +#include <linux/iversion.h>
9963 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9965 + unsigned int nlink;
9967 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9969 + nlink = dir->i_nlink;
9970 + nlink += h_dir->i_nlink - 2;
9971 + if (h_dir->i_nlink < 2)
9973 + smp_mb(); /* for i_nlink */
9974 + /* 0 can happen in revaliding */
9975 + set_nlink(dir, nlink);
9978 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9980 + unsigned int nlink;
9982 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9984 + nlink = dir->i_nlink;
9985 + nlink -= h_dir->i_nlink - 2;
9986 + if (h_dir->i_nlink < 2)
9988 + smp_mb(); /* for i_nlink */
9989 + /* nlink == 0 means the branch-fs is broken */
9990 + set_nlink(dir, nlink);
9993 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9996 + aufs_bindex_t bindex, bbot;
9997 + struct file *h_file;
9998 + struct dentry *h_dentry;
10002 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10004 + bbot = au_fbbot_dir(file);
10005 + for (bindex = au_fbtop(file);
10006 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10008 + h_file = au_hf_dir(file, bindex);
10009 + if (h_file && file_inode(h_file))
10010 + sz += vfsub_f_size_read(h_file);
10013 + AuDebugOn(!dentry);
10014 + AuDebugOn(!d_is_dir(dentry));
10016 + bbot = au_dbtaildir(dentry);
10017 + for (bindex = au_dbtop(dentry);
10018 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10020 + h_dentry = au_h_dptr(dentry, bindex);
10021 + if (h_dentry && d_is_positive(h_dentry))
10022 + sz += i_size_read(d_inode(h_dentry));
10025 + if (sz < KMALLOC_MAX_SIZE)
10026 + sz = roundup_pow_of_two(sz);
10027 + if (sz > KMALLOC_MAX_SIZE)
10028 + sz = KMALLOC_MAX_SIZE;
10029 + else if (sz < NAME_MAX) {
10030 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10031 + sz = AUFS_RDBLK_DEF;
10036 +struct au_dir_ts_arg {
10037 + struct dentry *dentry;
10038 + aufs_bindex_t brid;
10041 +static void au_do_dir_ts(void *arg)
10043 + struct au_dir_ts_arg *a = arg;
10044 + struct au_dtime dt;
10045 + struct path h_path;
10046 + struct inode *dir, *h_dir;
10047 + struct super_block *sb;
10048 + struct au_branch *br;
10049 + struct au_hinode *hdir;
10051 + aufs_bindex_t btop, bindex;
10053 + sb = a->dentry->d_sb;
10054 + if (d_really_is_negative(a->dentry))
10056 + /* no dir->i_mutex lock */
10057 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10059 + dir = d_inode(a->dentry);
10060 + btop = au_ibtop(dir);
10061 + bindex = au_br_index(sb, a->brid);
10062 + if (bindex < btop)
10065 + br = au_sbr(sb, bindex);
10066 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10067 + if (!h_path.dentry)
10069 + h_path.mnt = au_br_mnt(br);
10070 + au_dtime_store(&dt, a->dentry, &h_path);
10072 + br = au_sbr(sb, btop);
10073 + if (!au_br_writable(br->br_perm))
10075 + h_path.dentry = au_h_dptr(a->dentry, btop);
10076 + h_path.mnt = au_br_mnt(br);
10077 + err = vfsub_mnt_want_write(h_path.mnt);
10080 + hdir = au_hi(dir, btop);
10081 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10082 + h_dir = au_h_iptr(dir, btop);
10083 + if (h_dir->i_nlink
10084 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10085 + dt.dt_h_path = h_path;
10086 + au_dtime_revert(&dt);
10088 + au_hn_inode_unlock(hdir);
10089 + vfsub_mnt_drop_write(h_path.mnt);
10090 + au_cpup_attr_timesizes(dir);
10093 + aufs_read_unlock(a->dentry, AuLock_DW);
10096 + au_nwt_done(&au_sbi(sb)->si_nowait);
10097 + au_kfree_try_rcu(arg);
10100 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10102 + int perm, wkq_err;
10103 + aufs_bindex_t btop;
10104 + struct au_dir_ts_arg *arg;
10105 + struct dentry *dentry;
10106 + struct super_block *sb;
10110 + dentry = d_find_any_alias(dir);
10111 + AuDebugOn(!dentry);
10112 + sb = dentry->d_sb;
10113 + btop = au_ibtop(dir);
10114 + if (btop == bindex) {
10115 + au_cpup_attr_timesizes(dir);
10119 + perm = au_sbr_perm(sb, btop);
10120 + if (!au_br_writable(perm))
10123 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10127 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10128 + arg->brid = au_sbr_id(sb, bindex);
10129 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10130 + if (unlikely(wkq_err)) {
10131 + pr_err("wkq %d\n", wkq_err);
10133 + au_kfree_try_rcu(arg);
10140 +/* ---------------------------------------------------------------------- */
10142 +static int reopen_dir(struct file *file)
10145 + unsigned int flags;
10146 + aufs_bindex_t bindex, btail, btop;
10147 + struct dentry *dentry, *h_dentry;
10148 + struct file *h_file;
10150 + /* open all lower dirs */
10151 + dentry = file->f_path.dentry;
10152 + btop = au_dbtop(dentry);
10153 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10154 + au_set_h_fptr(file, bindex, NULL);
10155 + au_set_fbtop(file, btop);
10157 + btail = au_dbtaildir(dentry);
10158 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10159 + au_set_h_fptr(file, bindex, NULL);
10160 + au_set_fbbot_dir(file, btail);
10162 + flags = vfsub_file_flags(file);
10163 + for (bindex = btop; bindex <= btail; bindex++) {
10164 + h_dentry = au_h_dptr(dentry, bindex);
10167 + h_file = au_hf_dir(file, bindex);
10171 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10172 + err = PTR_ERR(h_file);
10173 + if (IS_ERR(h_file))
10174 + goto out; /* close all? */
10175 + au_set_h_fptr(file, bindex, h_file);
10177 + au_update_figen(file);
10178 + /* todo: necessary? */
10179 + /* file->f_ra = h_file->f_ra; */
10186 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10189 + aufs_bindex_t bindex, btail;
10190 + struct dentry *dentry, *h_dentry;
10191 + struct vfsmount *mnt;
10193 + FiMustWriteLock(file);
10194 + AuDebugOn(h_file);
10197 + mnt = file->f_path.mnt;
10198 + dentry = file->f_path.dentry;
10199 + file->f_version = inode_query_iversion(d_inode(dentry));
10200 + bindex = au_dbtop(dentry);
10201 + au_set_fbtop(file, bindex);
10202 + btail = au_dbtaildir(dentry);
10203 + au_set_fbbot_dir(file, btail);
10204 + for (; !err && bindex <= btail; bindex++) {
10205 + h_dentry = au_h_dptr(dentry, bindex);
10209 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10210 + if (unlikely(err))
10212 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10213 + if (IS_ERR(h_file)) {
10214 + err = PTR_ERR(h_file);
10217 + au_set_h_fptr(file, bindex, h_file);
10219 + au_update_figen(file);
10220 + /* todo: necessary? */
10221 + /* file->f_ra = h_file->f_ra; */
10223 + return 0; /* success */
10226 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10227 + au_set_h_fptr(file, bindex, NULL);
10228 + au_set_fbtop(file, -1);
10229 + au_set_fbbot_dir(file, -1);
10234 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10235 + struct file *file)
10238 + struct super_block *sb;
10239 + struct au_fidir *fidir;
10242 + sb = file->f_path.dentry->d_sb;
10243 + si_read_lock(sb, AuLock_FLUSH);
10244 + fidir = au_fidir_alloc(sb);
10246 + struct au_do_open_args args = {
10247 + .open = do_open_dir,
10250 + err = au_do_open(file, &args);
10251 + if (unlikely(err))
10252 + au_kfree_rcu(fidir);
10254 + si_read_unlock(sb);
10258 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10259 + struct file *file)
10261 + struct au_vdir *vdir_cache;
10262 + struct au_finfo *finfo;
10263 + struct au_fidir *fidir;
10264 + struct au_hfile *hf;
10265 + aufs_bindex_t bindex, bbot;
10267 + finfo = au_fi(file);
10268 + fidir = finfo->fi_hdir;
10270 + au_hbl_del(&finfo->fi_hlist,
10271 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10272 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10274 + au_vdir_free(vdir_cache);
10276 + bindex = finfo->fi_btop;
10277 + if (bindex >= 0) {
10278 + hf = fidir->fd_hfile + bindex;
10280 + * calls fput() instead of filp_close(),
10281 + * since no dnotify or lock for the lower file.
10283 + bbot = fidir->fd_bbot;
10284 + for (; bindex <= bbot; bindex++, hf++)
10286 + au_hfput(hf, /*execed*/0);
10288 + au_kfree_rcu(fidir);
10289 + finfo->fi_hdir = NULL;
10291 + au_finfo_fin(file);
10295 +/* ---------------------------------------------------------------------- */
10297 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10300 + aufs_bindex_t bindex, bbot;
10301 + struct file *h_file;
10304 + bbot = au_fbbot_dir(file);
10305 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10306 + h_file = au_hf_dir(file, bindex);
10308 + err = vfsub_flush(h_file, id);
10313 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10315 + return au_do_flush(file, id, au_do_flush_dir);
10318 +/* ---------------------------------------------------------------------- */
10320 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10323 + aufs_bindex_t bbot, bindex;
10324 + struct inode *inode;
10325 + struct super_block *sb;
10328 + sb = dentry->d_sb;
10329 + inode = d_inode(dentry);
10330 + IMustLock(inode);
10331 + bbot = au_dbbot(dentry);
10332 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10333 + struct path h_path;
10335 + if (au_test_ro(sb, bindex, inode))
10337 + h_path.dentry = au_h_dptr(dentry, bindex);
10338 + if (!h_path.dentry)
10341 + h_path.mnt = au_sbr_mnt(sb, bindex);
10342 + err = vfsub_fsync(NULL, &h_path, datasync);
10348 +static int au_do_fsync_dir(struct file *file, int datasync)
10351 + aufs_bindex_t bbot, bindex;
10352 + struct file *h_file;
10353 + struct super_block *sb;
10354 + struct inode *inode;
10356 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10357 + if (unlikely(err))
10360 + inode = file_inode(file);
10361 + sb = inode->i_sb;
10362 + bbot = au_fbbot_dir(file);
10363 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10364 + h_file = au_hf_dir(file, bindex);
10365 + if (!h_file || au_test_ro(sb, bindex, inode))
10368 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10376 + * @file may be NULL
10378 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10382 + struct dentry *dentry;
10383 + struct inode *inode;
10384 + struct super_block *sb;
10387 + dentry = file->f_path.dentry;
10388 + inode = d_inode(dentry);
10389 + inode_lock(inode);
10390 + sb = dentry->d_sb;
10391 + si_noflush_read_lock(sb);
10393 + err = au_do_fsync_dir(file, datasync);
10395 + di_write_lock_child(dentry);
10396 + err = au_do_fsync_dir_no_file(dentry, datasync);
10398 + au_cpup_attr_timesizes(inode);
10399 + di_write_unlock(dentry);
10401 + fi_write_unlock(file);
10403 + si_read_unlock(sb);
10404 + inode_unlock(inode);
10408 +/* ---------------------------------------------------------------------- */
10410 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10413 + struct dentry *dentry;
10414 + struct inode *inode, *h_inode;
10415 + struct super_block *sb;
10417 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10419 + dentry = file->f_path.dentry;
10420 + inode = d_inode(dentry);
10421 + IMustLock(inode);
10423 + sb = dentry->d_sb;
10424 + si_read_lock(sb, AuLock_FLUSH);
10425 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10426 + if (unlikely(err))
10428 + err = au_alive_dir(dentry);
10430 + err = au_vdir_init(file);
10431 + di_downgrade_lock(dentry, AuLock_IR);
10432 + if (unlikely(err))
10435 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10436 + if (!au_test_nfsd()) {
10437 + err = au_vdir_fill_de(file, ctx);
10438 + fsstack_copy_attr_atime(inode, h_inode);
10441 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10442 + * encode_fh() and others.
10444 + atomic_inc(&h_inode->i_count);
10445 + di_read_unlock(dentry, AuLock_IR);
10446 + si_read_unlock(sb);
10447 + err = au_vdir_fill_de(file, ctx);
10448 + fsstack_copy_attr_atime(inode, h_inode);
10449 + fi_write_unlock(file);
10457 + di_read_unlock(dentry, AuLock_IR);
10458 + fi_write_unlock(file);
10460 + si_read_unlock(sb);
10464 +/* ---------------------------------------------------------------------- */
10466 +#define AuTestEmpty_WHONLY 1
10467 +#define AuTestEmpty_CALLED (1 << 1)
10468 +#define AuTestEmpty_SHWH (1 << 2)
10469 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10470 +#define au_fset_testempty(flags, name) \
10471 + do { (flags) |= AuTestEmpty_##name; } while (0)
10472 +#define au_fclr_testempty(flags, name) \
10473 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10475 +#ifndef CONFIG_AUFS_SHWH
10476 +#undef AuTestEmpty_SHWH
10477 +#define AuTestEmpty_SHWH 0
10480 +struct test_empty_arg {
10481 + struct dir_context ctx;
10482 + struct au_nhash *whlist;
10483 + unsigned int flags;
10485 + aufs_bindex_t bindex;
10488 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10489 + int namelen, loff_t offset __maybe_unused, u64 ino,
10490 + unsigned int d_type)
10492 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10494 + char *name = (void *)__name;
10497 + au_fset_testempty(arg->flags, CALLED);
10499 + if (name[0] == '.'
10500 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10501 + goto out; /* success */
10503 + if (namelen <= AUFS_WH_PFX_LEN
10504 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10505 + if (au_ftest_testempty(arg->flags, WHONLY)
10506 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10507 + arg->err = -ENOTEMPTY;
10511 + name += AUFS_WH_PFX_LEN;
10512 + namelen -= AUFS_WH_PFX_LEN;
10513 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10514 + arg->err = au_nhash_append_wh
10515 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10516 + au_ftest_testempty(arg->flags, SHWH));
10520 + AuTraceErr(arg->err);
10524 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10527 + struct file *h_file;
10528 + struct au_branch *br;
10530 + h_file = au_h_open(dentry, arg->bindex,
10531 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10532 + /*file*/NULL, /*force_wr*/0);
10533 + err = PTR_ERR(h_file);
10534 + if (IS_ERR(h_file))
10538 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10539 + && !file_inode(h_file)->i_nlink)
10544 + au_fclr_testempty(arg->flags, CALLED);
10546 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10549 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10553 + br = au_sbr(dentry->d_sb, arg->bindex);
10554 + au_lcnt_dec(&br->br_nfiles);
10559 +struct do_test_empty_args {
10561 + struct dentry *dentry;
10562 + struct test_empty_arg *arg;
10565 +static void call_do_test_empty(void *args)
10567 + struct do_test_empty_args *a = args;
10568 + *a->errp = do_test_empty(a->dentry, a->arg);
10571 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10573 + int err, wkq_err;
10574 + struct dentry *h_dentry;
10575 + struct inode *h_inode;
10576 + struct user_namespace *h_userns;
10578 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10579 + h_dentry = au_h_dptr(dentry, arg->bindex);
10580 + h_inode = d_inode(h_dentry);
10581 + /* todo: i_mode changes anytime? */
10582 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10583 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10584 + inode_unlock_shared(h_inode);
10586 + err = do_test_empty(dentry, arg);
10588 + struct do_test_empty_args args = {
10590 + .dentry = dentry,
10593 + unsigned int flags = arg->flags;
10595 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10596 + if (unlikely(wkq_err))
10598 + arg->flags = flags;
10604 +int au_test_empty_lower(struct dentry *dentry)
10607 + unsigned int rdhash;
10608 + aufs_bindex_t bindex, btop, btail;
10609 + struct au_nhash whlist;
10610 + struct test_empty_arg arg = {
10612 + .actor = test_empty_cb
10615 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10617 + SiMustAnyLock(dentry->d_sb);
10619 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10621 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10622 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10623 + if (unlikely(err))
10627 + arg.whlist = &whlist;
10628 + btop = au_dbtop(dentry);
10629 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10630 + au_fset_testempty(arg.flags, SHWH);
10631 + test_empty = do_test_empty;
10632 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10633 + test_empty = sio_test_empty;
10634 + arg.bindex = btop;
10635 + err = test_empty(dentry, &arg);
10636 + if (unlikely(err))
10639 + au_fset_testempty(arg.flags, WHONLY);
10640 + btail = au_dbtaildir(dentry);
10641 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10642 + struct dentry *h_dentry;
10644 + h_dentry = au_h_dptr(dentry, bindex);
10645 + if (h_dentry && d_is_positive(h_dentry)) {
10646 + arg.bindex = bindex;
10647 + err = test_empty(dentry, &arg);
10652 + au_nhash_wh_free(&whlist);
10657 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10660 + struct test_empty_arg arg = {
10662 + .actor = test_empty_cb
10665 + aufs_bindex_t bindex, btail;
10668 + arg.whlist = whlist;
10669 + arg.flags = AuTestEmpty_WHONLY;
10670 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10671 + au_fset_testempty(arg.flags, SHWH);
10672 + btail = au_dbtaildir(dentry);
10673 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10674 + struct dentry *h_dentry;
10676 + h_dentry = au_h_dptr(dentry, bindex);
10677 + if (h_dentry && d_is_positive(h_dentry)) {
10678 + arg.bindex = bindex;
10679 + err = sio_test_empty(dentry, &arg);
10686 +/* ---------------------------------------------------------------------- */
10688 +const struct file_operations aufs_dir_fop = {
10689 + .owner = THIS_MODULE,
10690 + .llseek = default_llseek,
10691 + .read = generic_read_dir,
10692 + .iterate_shared = aufs_iterate_shared,
10693 + .unlocked_ioctl = aufs_ioctl_dir,
10694 +#ifdef CONFIG_COMPAT
10695 + .compat_ioctl = aufs_compat_ioctl_dir,
10697 + .open = aufs_open_dir,
10698 + .release = aufs_release_dir,
10699 + .flush = aufs_flush_dir,
10700 + .fsync = aufs_fsync_dir
10702 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10703 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10704 +++ linux/fs/aufs/dir.h 2022-03-21 14:49:05.719966344 +0100
10706 +/* SPDX-License-Identifier: GPL-2.0 */
10708 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10710 + * This program, aufs is free software; you can redistribute it and/or modify
10711 + * it under the terms of the GNU General Public License as published by
10712 + * the Free Software Foundation; either version 2 of the License, or
10713 + * (at your option) any later version.
10715 + * This program is distributed in the hope that it will be useful,
10716 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10717 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10718 + * GNU General Public License for more details.
10720 + * You should have received a copy of the GNU General Public License
10721 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10725 + * directory operations
10728 +#ifndef __AUFS_DIR_H__
10729 +#define __AUFS_DIR_H__
10733 +#include <linux/fs.h>
10735 +/* ---------------------------------------------------------------------- */
10737 +/* need to be faster and smaller */
10740 + unsigned int nh_num;
10741 + struct hlist_head *nh_head;
10744 +struct au_vdir_destr {
10745 + unsigned char len;
10746 + unsigned char name[];
10749 +struct au_vdir_dehstr {
10750 + struct hlist_node hash;
10751 + struct au_vdir_destr *str;
10752 + struct rcu_head rcu;
10753 +} ____cacheline_aligned_in_smp;
10755 +struct au_vdir_de {
10757 + unsigned char de_type;
10758 + /* caution: packed */
10759 + struct au_vdir_destr de_str;
10762 +struct au_vdir_wh {
10763 + struct hlist_node wh_hash;
10764 +#ifdef CONFIG_AUFS_SHWH
10766 + aufs_bindex_t wh_bindex;
10767 + unsigned char wh_type;
10769 + aufs_bindex_t wh_bindex;
10771 + /* caution: packed */
10772 + struct au_vdir_destr wh_str;
10775 +union au_vdir_deblk_p {
10776 + unsigned char *deblk;
10777 + struct au_vdir_de *de;
10781 + unsigned char **vd_deblk;
10782 + unsigned long vd_nblk;
10784 + unsigned long ul;
10785 + union au_vdir_deblk_p p;
10789 + unsigned int vd_deblk_sz;
10790 + unsigned long vd_jiffy;
10791 + struct rcu_head rcu;
10792 +} ____cacheline_aligned_in_smp;
10794 +/* ---------------------------------------------------------------------- */
10797 +extern const struct file_operations aufs_dir_fop;
10798 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10799 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10800 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10801 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10802 +int au_test_empty_lower(struct dentry *dentry);
10803 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10806 +unsigned int au_rdhash_est(loff_t sz);
10807 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10808 +void au_nhash_wh_free(struct au_nhash *whlist);
10809 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10811 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10812 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10813 + unsigned int d_type, aufs_bindex_t bindex,
10814 + unsigned char shwh);
10815 +void au_vdir_free(struct au_vdir *vdir);
10816 +int au_vdir_init(struct file *file);
10817 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10820 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10822 +#ifdef CONFIG_AUFS_RDU
10824 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10825 +#ifdef CONFIG_COMPAT
10826 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10827 + unsigned long arg);
10830 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10831 + unsigned int cmd, unsigned long arg)
10832 +#ifdef CONFIG_COMPAT
10833 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10834 + unsigned int cmd, unsigned long arg)
10838 +#endif /* __KERNEL__ */
10839 +#endif /* __AUFS_DIR_H__ */
10840 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10841 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10842 +++ linux/fs/aufs/dirren.c 2022-03-21 14:49:05.723299677 +0100
10844 +// SPDX-License-Identifier: GPL-2.0
10846 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10848 + * This program, aufs is free software; you can redistribute it and/or modify
10849 + * it under the terms of the GNU General Public License as published by
10850 + * the Free Software Foundation; either version 2 of the License, or
10851 + * (at your option) any later version.
10853 + * This program is distributed in the hope that it will be useful,
10854 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10855 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10856 + * GNU General Public License for more details.
10858 + * You should have received a copy of the GNU General Public License
10859 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10863 + * special handling in renaming a directory
10864 + * in order to support looking-up the before-renamed name on the lower readonly
10868 +#include <linux/byteorder/generic.h>
10871 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10875 + idx = au_dr_ihash(ent->dr_h_ino);
10876 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10879 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10882 + struct hlist_bl_head *hbl;
10885 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10886 + hbl = dr->dr_h_ino + i;
10887 + hlist_bl_lock(hbl);
10888 + ret &= hlist_bl_empty(hbl);
10889 + hlist_bl_unlock(hbl);
10895 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10897 + struct au_dr_hino *found, *ent;
10898 + struct hlist_bl_head *hbl;
10899 + struct hlist_bl_node *pos;
10903 + idx = au_dr_ihash(ino);
10904 + hbl = dr->dr_h_ino + idx;
10905 + hlist_bl_lock(hbl);
10906 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10907 + if (ent->dr_h_ino == ino) {
10911 + hlist_bl_unlock(hbl);
10916 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10917 + struct au_dr_hino *add_ent)
10920 + struct hlist_bl_head *hbl;
10921 + struct hlist_bl_node *pos;
10922 + struct au_dr_hino *ent;
10925 + idx = au_dr_ihash(ino);
10926 + hbl = dr->dr_h_ino + idx;
10927 +#if 0 /* debug print */
10929 + struct hlist_bl_node *tmp;
10931 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10932 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10935 + hlist_bl_lock(hbl);
10936 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10937 + if (ent->dr_h_ino == ino) {
10941 + if (!found && add_ent)
10942 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10943 + hlist_bl_unlock(hbl);
10945 + if (!found && add_ent)
10946 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10951 +void au_dr_hino_free(struct au_dr_br *dr)
10954 + struct hlist_bl_head *hbl;
10955 + struct hlist_bl_node *pos, *tmp;
10956 + struct au_dr_hino *ent;
10958 + /* SiMustWriteLock(sb); */
10960 + for (i = 0; i < AuDirren_NHASH; i++) {
10961 + hbl = dr->dr_h_ino + i;
10962 + /* no spinlock since sbinfo must be write-locked */
10963 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10964 + au_kfree_rcu(ent);
10965 + INIT_HLIST_BL_HEAD(hbl);
10969 +/* returns the number of inodes or an error */
10970 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10971 + struct file *hinofile)
10975 + loff_t pos, oldsize;
10977 + struct inode *hinoinode;
10978 + struct hlist_bl_head *hbl;
10979 + struct hlist_bl_node *n1, *n2;
10980 + struct au_dr_hino *ent;
10982 + SiMustWriteLock(sb);
10983 + AuDebugOn(!au_br_writable(br->br_perm));
10985 + hinoinode = file_inode(hinofile);
10986 + oldsize = i_size_read(hinoinode);
10990 + hbl = br->br_dirren.dr_h_ino;
10991 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
10992 + /* no bit-lock since sbinfo must be write-locked */
10993 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
10994 + AuDbg("hi%llu, %pD2\n",
10995 + (unsigned long long)ent->dr_h_ino, hinofile);
10996 + u64 = cpu_to_be64(ent->dr_h_ino);
10997 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
10998 + if (ssz == sizeof(u64))
11001 + /* write error */
11002 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11009 + /* regardless the error */
11010 + if (pos < oldsize) {
11011 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11019 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11026 + struct au_dr_hino *ent;
11027 + struct inode *hinoinode;
11028 + struct hlist_bl_head *hbl;
11032 + hbl = dr->dr_h_ino;
11033 + hinoinode = file_inode(hinofile);
11034 + sz = i_size_read(hinoinode);
11035 + AuDebugOn(sz % sizeof(u64));
11036 + n = sz / sizeof(u64);
11038 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11039 + if (unlikely(ssz != sizeof(u64))) {
11040 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11047 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11053 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11054 + AuDbg("hi%llu, %pD2\n",
11055 + (unsigned long long)ent->dr_h_ino, hinofile);
11056 + hidx = au_dr_ihash(ent->dr_h_ino);
11057 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11059 + goto out; /* success */
11062 + au_dr_hino_free(dr);
11069 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11070 + * @path is a switch to distinguish load and store.
11072 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11073 + struct au_branch *br, const struct path *path)
11076 + unsigned char load, suspend;
11077 + struct file *hinofile;
11078 + struct au_hinode *hdir;
11079 + struct inode *dir, *delegated;
11080 + struct path hinopath;
11081 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11082 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11084 + AuDebugOn(bindex < 0 && !br);
11085 + AuDebugOn(bindex >= 0 && br);
11090 + br = au_sbr(sb, bindex);
11093 + path = &br->br_path;
11094 + AuDebugOn(!au_br_writable(br->br_perm));
11095 + if (unlikely(!au_br_writable(br->br_perm)))
11101 + dir = d_inode(sb->s_root);
11102 + hdir = au_hinode(au_ii(dir), bindex);
11103 + dir = hdir->hi_inode;
11104 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11106 + dir = d_inode(path->dentry);
11107 + inode_lock_nested(dir, AuLsc_I_CHILD);
11109 + hinopath.mnt = path->mnt;
11110 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11111 + err = PTR_ERR(hinopath.dentry);
11112 + if (IS_ERR(hinopath.dentry))
11116 + flags = O_RDONLY;
11118 + if (d_is_negative(hinopath.dentry))
11119 + goto out_dput; /* success */
11121 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11122 + if (d_is_positive(hinopath.dentry)) {
11123 + delegated = NULL;
11124 + err = vfsub_unlink(dir, &hinopath, &delegated,
11127 + if (unlikely(err))
11128 + pr_err("ignored err %d, %pd2\n",
11129 + err, hinopath.dentry);
11130 + if (unlikely(err == -EWOULDBLOCK))
11135 + } else if (!d_is_positive(hinopath.dentry)) {
11136 + err = vfsub_create(dir, &hinopath, 0600,
11137 + /*want_excl*/false);
11139 + if (unlikely(err))
11142 + flags = O_WRONLY;
11144 + hinofile = vfsub_dentry_open(&hinopath, flags);
11146 + au_hn_inode_unlock(hdir);
11148 + inode_unlock(dir);
11149 + dput(hinopath.dentry);
11150 + AuTraceErrPtr(hinofile);
11151 + if (IS_ERR(hinofile)) {
11152 + err = PTR_ERR(hinofile);
11157 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11159 + err = au_dr_hino_store(sb, br, hinofile);
11164 + dput(hinopath.dentry);
11167 + au_hn_inode_unlock(hdir);
11169 + inode_unlock(dir);
11175 +/* ---------------------------------------------------------------------- */
11177 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11180 + struct kstatfs kstfs;
11182 + struct dentry *dentry;
11183 + struct super_block *sb;
11185 + err = vfs_statfs((void *)path, &kstfs);
11187 + if (unlikely(err))
11190 + /* todo: support for UUID */
11192 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11193 + brid->type = AuBrid_FSID;
11194 + brid->fsid = kstfs.f_fsid;
11196 + dentry = path->dentry;
11197 + sb = dentry->d_sb;
11200 + brid->type = AuBrid_DEV;
11209 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11210 + const struct path *path)
11213 + struct au_dr_br *dr;
11214 + struct hlist_bl_head *hbl;
11216 + dr = &br->br_dirren;
11217 + hbl = dr->dr_h_ino;
11218 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11219 + INIT_HLIST_BL_HEAD(hbl);
11221 + err = au_dr_brid_init(&dr->dr_brid, path);
11222 + if (unlikely(err))
11225 + if (au_opt_test(au_mntflags(sb), DIRREN))
11226 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11233 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11238 + if (au_br_writable(br->br_perm))
11239 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11241 + au_dr_hino_free(&br->br_dirren);
11246 +/* ---------------------------------------------------------------------- */
11248 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11249 + char *buf, size_t sz)
11252 + unsigned int major, minor;
11256 + err = snprintf(p, sz, "%d_", brid->type);
11257 + AuDebugOn(err > sz);
11260 + switch (brid->type) {
11261 + case AuBrid_Unset:
11263 + case AuBrid_UUID:
11264 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11266 + case AuBrid_FSID:
11267 + err = snprintf(p, sz, "%08x-%08x",
11268 + brid->fsid.val[0], brid->fsid.val[1]);
11271 + major = MAJOR(brid->dev);
11272 + minor = MINOR(brid->dev);
11273 + if (major <= 0xff && minor <= 0xff)
11274 + err = snprintf(p, sz, "%02x%02x", major, minor);
11276 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11279 + AuDebugOn(err > sz);
11282 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11283 + AuDebugOn(err > sz);
11290 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11293 + struct dentry *br_dentry;
11294 + struct inode *br_inode;
11296 + br_dentry = au_br_dentry(br);
11297 + br_inode = d_inode(br_dentry);
11298 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11299 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11300 + AuDebugOn(rlen > len);
11305 +/* ---------------------------------------------------------------------- */
11308 + * from the given @h_dentry, construct drinfo at @*fdata.
11309 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11312 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11313 + struct dentry *h_dentry,
11314 + unsigned char *allocated)
11317 + struct au_drinfo_fdata *f, *p;
11318 + struct au_drinfo *drinfo;
11319 + struct inode *h_inode;
11320 + struct qstr *qname;
11324 + h_inode = d_inode(h_dentry);
11325 + qname = &h_dentry->d_name;
11326 + drinfo = &f->drinfo;
11327 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11328 + drinfo->oldnamelen = qname->len;
11329 + if (*allocated < sizeof(*f) + qname->len) {
11330 + v = roundup_pow_of_two(*allocated + qname->len);
11331 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11332 + if (unlikely(!p)) {
11340 + drinfo = &f->drinfo;
11342 + memcpy(drinfo->oldname, qname->name, qname->len);
11343 + AuDbg("i%llu, %.*s\n",
11344 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11345 + drinfo->oldname);
11352 +/* callers have to free the return value */
11353 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11355 + struct au_drinfo *ret, *drinfo;
11356 + struct au_drinfo_fdata fdata;
11361 + ret = ERR_PTR(-EIO);
11363 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11364 + if (unlikely(ssz != sizeof(fdata))) {
11365 + AuIOErr("ssz %zd, %u, %pD2\n",
11366 + ssz, (unsigned int)sizeof(fdata), file);
11370 + fdata.magic = ntohl((__force __be32)fdata.magic);
11371 + switch (fdata.magic) {
11372 + case AUFS_DRINFO_MAGIC_V1:
11375 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11376 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11380 + drinfo = &fdata.drinfo;
11381 + len = drinfo->oldnamelen;
11383 + AuIOErr("broken drinfo %pD2\n", file);
11388 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11389 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11390 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11391 + (unsigned long long)drinfo->ino,
11392 + (unsigned long long)h_ino, file);
11393 + goto out; /* success */
11396 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11397 + if (unlikely(!ret)) {
11398 + ret = ERR_PTR(-ENOMEM);
11399 + AuTraceErrPtr(ret);
11404 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11405 + if (unlikely(ssz != len)) {
11406 + au_kfree_rcu(ret);
11407 + ret = ERR_PTR(-EIO);
11408 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11412 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11418 +/* ---------------------------------------------------------------------- */
11420 +/* in order to be revertible */
11421 +struct au_drinfo_rev_elm {
11423 + struct dentry *info_dentry;
11424 + struct au_drinfo *info_last;
11427 +struct au_drinfo_rev {
11428 + unsigned char already;
11429 + aufs_bindex_t nelm;
11430 + struct au_drinfo_rev_elm elm[];
11433 +/* todo: isn't it too large? */
11434 +struct au_drinfo_store {
11435 + struct path h_ppath;
11436 + struct dentry *h_dentry;
11437 + struct au_drinfo_fdata *fdata;
11438 + char *infoname; /* inside of whname, just after PFX */
11439 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11440 + aufs_bindex_t btgt, btail;
11441 + unsigned char no_sio,
11442 + allocated, /* current size of *fdata */
11443 + infonamelen, /* room size for p */
11444 + whnamelen, /* length of the generated name */
11445 + renameback; /* renamed back */
11448 +/* on rename(2) error, the caller should revert it using @elm */
11449 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11450 + struct au_drinfo_rev_elm *elm)
11455 + struct path infopath = {
11456 + .mnt = w->h_ppath.mnt
11458 + struct inode *h_dir, *h_inode, *delegated;
11459 + struct file *infofile;
11460 + struct qstr *qname;
11463 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11465 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11467 + AuTraceErrPtr(infopath.dentry);
11468 + if (IS_ERR(infopath.dentry)) {
11469 + err = PTR_ERR(infopath.dentry);
11474 + h_dir = d_inode(w->h_ppath.dentry);
11475 + if (elm && d_is_negative(infopath.dentry)) {
11476 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11478 + if (unlikely(err))
11480 + elm->created = 1;
11481 + elm->info_dentry = dget(infopath.dentry);
11484 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11485 + AuTraceErrPtr(infofile);
11486 + if (IS_ERR(infofile)) {
11487 + err = PTR_ERR(infofile);
11491 + h_inode = d_inode(infopath.dentry);
11492 + if (elm && i_size_read(h_inode)) {
11493 + h_inode = d_inode(w->h_dentry);
11494 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11495 + AuTraceErrPtr(elm->info_last);
11496 + if (IS_ERR(elm->info_last)) {
11497 + err = PTR_ERR(elm->info_last);
11498 + elm->info_last = NULL;
11499 + AuDebugOn(elm->info_dentry);
11504 + if (elm && w->renameback) {
11505 + delegated = NULL;
11506 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11508 + if (unlikely(err == -EWOULDBLOCK))
11514 + qname = &w->h_dentry->d_name;
11515 + len = sizeof(*w->fdata) + qname->len;
11517 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11518 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11519 + if (ssz == len) {
11520 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11521 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11522 + goto out_fput; /* success */
11527 + /* the caller should revert it using @elm */
11533 + dput(infopath.dentry);
11539 +struct au_call_drinfo_do_store_args {
11541 + struct au_drinfo_store *w;
11542 + struct au_drinfo_rev_elm *elm;
11545 +static void au_call_drinfo_do_store(void *args)
11547 + struct au_call_drinfo_do_store_args *a = args;
11549 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11552 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11553 + struct au_drinfo_rev_elm *elm)
11555 + int err, wkq_err;
11558 + err = au_drinfo_do_store(w, elm);
11560 + struct au_call_drinfo_do_store_args a = {
11565 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11566 + if (unlikely(wkq_err))
11574 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11575 + aufs_bindex_t btgt)
11579 + memset(w, 0, sizeof(*w));
11580 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11581 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11582 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11583 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11585 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11588 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11589 + if (unlikely(!w->fdata)) {
11593 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11600 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11602 + au_kfree_rcu(w->fdata);
11605 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11606 + struct au_drinfo_store *w)
11608 + struct au_drinfo_rev_elm *elm;
11609 + struct inode *h_dir, *delegated;
11611 + struct path infopath = {
11612 + .mnt = w->h_ppath.mnt
11615 + h_dir = d_inode(w->h_ppath.dentry);
11616 + IMustLock(h_dir);
11620 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11621 + AuDebugOn(elm->created && elm->info_last);
11622 + if (elm->created) {
11624 + delegated = NULL;
11625 + infopath.dentry = elm->info_dentry;
11626 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11629 + if (unlikely(err == -EWOULDBLOCK))
11631 + dput(elm->info_dentry);
11632 + } else if (elm->info_last) {
11634 + w->fdata->drinfo = *elm->info_last;
11635 + memcpy(w->fdata->drinfo.oldname,
11636 + elm->info_last->oldname,
11637 + elm->info_last->oldnamelen);
11638 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11639 + au_kfree_rcu(elm->info_last);
11641 + if (unlikely(err))
11642 + AuIOErr("%d, %s\n", err, w->whname);
11643 + /* go on even if err */
11647 +/* caller has to call au_dr_rename_fin() later */
11648 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11649 + struct qstr *dst_name, void *_rev)
11651 + int err, sz, nelm;
11652 + aufs_bindex_t bindex, btail;
11653 + struct au_drinfo_store work;
11654 + struct au_drinfo_rev *rev, **p;
11655 + struct au_drinfo_rev_elm *elm;
11656 + struct super_block *sb;
11657 + struct au_branch *br;
11658 + struct au_hinode *hdir;
11660 + err = au_drinfo_store_work_init(&work, btgt);
11662 + if (unlikely(err))
11666 + btail = au_dbtaildir(dentry);
11667 + nelm = btail - btgt;
11668 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11669 + rev = kcalloc(1, sz, GFP_NOFS);
11670 + if (unlikely(!rev)) {
11674 + rev->nelm = nelm;
11680 + sb = dentry->d_sb;
11681 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11682 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11683 + hdir = au_hi(d_inode(dentry), btgt);
11684 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11685 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11686 + work.h_dentry = au_h_dptr(dentry, bindex);
11687 + if (!work.h_dentry)
11690 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11691 + &work.allocated);
11693 + if (unlikely(err))
11696 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11697 + br = au_sbr(sb, bindex);
11698 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11699 + work.whnamelen += au_drinfo_name(br, work.infoname,
11700 + work.infonamelen);
11701 + AuDbg("whname %.*s, i%llu, %.*s\n",
11702 + work.whnamelen, work.whname,
11703 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11704 + work.fdata->drinfo.oldnamelen,
11705 + work.fdata->drinfo.oldname);
11707 + err = au_drinfo_store_sio(&work, elm);
11709 + if (unlikely(err))
11712 + if (unlikely(err)) {
11713 + /* revert all drinfo */
11714 + au_drinfo_store_rev(rev, &work);
11715 + au_kfree_try_rcu(rev);
11718 + au_hn_inode_unlock(hdir);
11721 + au_drinfo_store_work_fin(&work);
11726 +/* ---------------------------------------------------------------------- */
11728 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11729 + struct qstr *dst_name, void *_rev)
11731 + int err, already;
11733 + struct super_block *sb;
11734 + struct au_branch *br;
11735 + struct au_dr_br *dr;
11736 + struct dentry *h_dentry;
11737 + struct inode *h_inode;
11738 + struct au_dr_hino *ent;
11739 + struct au_drinfo_rev *rev, **p;
11741 + AuDbg("bindex %d\n", bindex);
11744 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11745 + if (unlikely(!ent))
11749 + br = au_sbr(sb, bindex);
11750 + dr = &br->br_dirren;
11751 + h_dentry = au_h_dptr(src, bindex);
11752 + h_inode = d_inode(h_dentry);
11753 + ino = h_inode->i_ino;
11754 + ent->dr_h_ino = ino;
11755 + already = au_dr_hino_test_add(dr, ino, ent);
11756 + AuDbg("b%d, hi%llu, already %d\n",
11757 + bindex, (unsigned long long)ino, already);
11759 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11764 + rev->already = already;
11765 + goto out; /* success */
11770 + au_dr_hino_del(dr, ent);
11771 + au_kfree_rcu(ent);
11778 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11780 + struct au_drinfo_rev *rev;
11781 + struct au_drinfo_rev_elm *elm;
11786 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11787 + dput(elm->info_dentry);
11788 + au_kfree_rcu(elm->info_last);
11790 + au_kfree_try_rcu(rev);
11793 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11796 + struct au_drinfo_store work;
11797 + struct au_drinfo_rev *rev = _rev;
11798 + struct super_block *sb;
11799 + struct au_branch *br;
11800 + struct inode *h_inode;
11801 + struct au_dr_br *dr;
11802 + struct au_dr_hino *ent;
11804 + err = au_drinfo_store_work_init(&work, btgt);
11805 + if (unlikely(err))
11809 + br = au_sbr(sb, btgt);
11810 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11811 + work.h_ppath.mnt = au_br_mnt(br);
11812 + au_drinfo_store_rev(rev, &work);
11813 + au_drinfo_store_work_fin(&work);
11814 + if (rev->already)
11817 + dr = &br->br_dirren;
11818 + h_inode = d_inode(work.h_ppath.dentry);
11819 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11821 + au_dr_hino_del(dr, ent);
11822 + au_kfree_rcu(ent);
11825 + au_kfree_try_rcu(rev);
11826 + if (unlikely(err))
11827 + pr_err("failed to remove dirren info\n");
11830 +/* ---------------------------------------------------------------------- */
11832 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11833 + char *whname, int whnamelen,
11834 + struct dentry **info_dentry)
11836 + struct au_drinfo *drinfo;
11838 + struct inode *h_dir;
11839 + struct path infopath;
11842 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11844 + *info_dentry = NULL;
11847 + h_dir = d_inode(h_ppath->dentry);
11848 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11849 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11850 + if (IS_ERR(infopath.dentry)) {
11851 + drinfo = (void *)infopath.dentry;
11855 + if (d_is_negative(infopath.dentry))
11856 + goto out_dput; /* success */
11858 + infopath.mnt = h_ppath->mnt;
11859 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11860 + inode_unlock_shared(h_dir);
11863 + drinfo = (void *)f;
11867 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11868 + if (IS_ERR_OR_NULL(drinfo))
11871 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11872 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11877 + dput(infopath.dentry);
11880 + inode_unlock_shared(h_dir);
11881 + AuTraceErrPtr(drinfo);
11885 +struct au_drinfo_do_load_args {
11886 + struct au_drinfo **drinfop;
11887 + struct path *h_ppath;
11890 + struct dentry **info_dentry;
11893 +static void au_call_drinfo_do_load(void *args)
11895 + struct au_drinfo_do_load_args *a = args;
11897 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11901 +struct au_drinfo_load {
11902 + struct path h_ppath;
11903 + struct qstr *qname;
11904 + unsigned char no_sio;
11906 + aufs_bindex_t ninfo;
11907 + struct au_drinfo **drinfo;
11910 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11911 + struct au_branch *br)
11913 + int err, wkq_err, whnamelen, e;
11914 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11915 + = AUFS_WH_DR_INFO_PFX;
11916 + struct au_drinfo *drinfo;
11917 + struct qstr oldname;
11918 + struct inode *h_dir, *delegated;
11919 + struct dentry *info_dentry;
11920 + struct path infopath;
11922 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11923 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11924 + sizeof(whname) - whnamelen);
11926 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11929 + struct au_drinfo_do_load_args args = {
11930 + .drinfop = &drinfo,
11931 + .h_ppath = &w->h_ppath,
11932 + .whname = whname,
11933 + .whnamelen = whnamelen,
11934 + .info_dentry = &info_dentry
11936 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11937 + if (unlikely(wkq_err))
11938 + drinfo = ERR_PTR(wkq_err);
11940 + err = PTR_ERR(drinfo);
11941 + if (IS_ERR_OR_NULL(drinfo))
11945 + oldname.len = drinfo->oldnamelen;
11946 + oldname.name = drinfo->oldname;
11947 + if (au_qstreq(w->qname, &oldname)) {
11948 + /* the name is renamed back */
11949 + au_kfree_rcu(drinfo);
11952 + infopath.dentry = info_dentry;
11953 + infopath.mnt = w->h_ppath.mnt;
11954 + h_dir = d_inode(w->h_ppath.dentry);
11955 + delegated = NULL;
11956 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11957 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11958 + inode_unlock(h_dir);
11960 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11961 + if (unlikely(e == -EWOULDBLOCK))
11964 + au_kfree_rcu(w->drinfo[bindex]);
11965 + w->drinfo[bindex] = drinfo;
11966 + dput(info_dentry);
11973 +/* ---------------------------------------------------------------------- */
11975 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11977 + struct au_drinfo **p = drinfo;
11980 + au_kfree_rcu(*drinfo++);
11981 + au_kfree_try_rcu(p);
11984 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
11985 + aufs_bindex_t btgt)
11988 + struct au_drinfo_load w;
11989 + aufs_bindex_t bindex, bbot;
11990 + struct au_branch *br;
11991 + struct inode *h_dir;
11992 + struct au_dr_hino *ent;
11993 + struct super_block *sb;
11995 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
11996 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
11997 + AuLNPair(&lkup->whname), btgt);
11999 + sb = dentry->d_sb;
12000 + bbot = au_sbbot(sb);
12001 + w.ninfo = bbot + 1;
12002 + if (!lkup->dirren.drinfo) {
12003 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12004 + sizeof(*lkup->dirren.drinfo),
12006 + if (unlikely(!lkup->dirren.drinfo)) {
12010 + lkup->dirren.ninfo = w.ninfo;
12012 + w.drinfo = lkup->dirren.drinfo;
12013 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12014 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12015 + AuDebugOn(!w.h_ppath.dentry);
12016 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12017 + w.qname = &dentry->d_name;
12020 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12021 + br = au_sbr(sb, bindex);
12022 + err = au_drinfo_load(&w, bindex, br);
12023 + if (unlikely(err))
12025 + if (w.drinfo[bindex])
12029 + br = au_sbr(sb, btgt);
12030 + h_dir = d_inode(w.h_ppath.dentry);
12031 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12033 + au_dr_hino_del(&br->br_dirren, ent);
12034 + au_kfree_rcu(ent);
12036 + goto out; /* success */
12039 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12040 + lkup->dirren.ninfo = 0;
12041 + lkup->dirren.drinfo = NULL;
12047 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12049 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12052 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12055 + struct au_drinfo *drinfo;
12058 + if (!lkup->dirren.drinfo)
12060 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12061 + drinfo = lkup->dirren.drinfo[btgt];
12065 + au_kfree_try_rcu(lkup->whname.name);
12066 + lkup->whname.name = NULL;
12067 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12068 + lkup->dirren.dr_name.name = drinfo->oldname;
12069 + lkup->name = &lkup->dirren.dr_name;
12070 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12072 + AuDbg("name %.*s, whname %.*s, b%d\n",
12073 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12081 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12085 + struct au_drinfo *drinfo;
12088 + if (!lkup->dirren.drinfo)
12090 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12091 + drinfo = lkup->dirren.drinfo[bindex];
12095 + match = (drinfo->ino == h_ino);
12096 + AuDbg("match %d\n", match);
12102 +/* ---------------------------------------------------------------------- */
12104 +int au_dr_opt_set(struct super_block *sb)
12107 + aufs_bindex_t bindex, bbot;
12108 + struct au_branch *br;
12111 + bbot = au_sbbot(sb);
12112 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12113 + br = au_sbr(sb, bindex);
12114 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12120 +int au_dr_opt_flush(struct super_block *sb)
12123 + aufs_bindex_t bindex, bbot;
12124 + struct au_branch *br;
12127 + bbot = au_sbbot(sb);
12128 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12129 + br = au_sbr(sb, bindex);
12130 + if (au_br_writable(br->br_perm))
12131 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12137 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12140 + aufs_bindex_t bindex, bbot;
12141 + struct au_branch *br;
12145 + err = au_dr_opt_flush(sb);
12146 + if (unlikely(err))
12150 + bbot = au_sbbot(sb);
12151 + for (bindex = 0; bindex <= bbot; bindex++) {
12152 + br = au_sbr(sb, bindex);
12153 + au_dr_hino_free(&br->br_dirren);
12159 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12160 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12161 +++ linux/fs/aufs/dirren.h 2022-03-21 14:49:05.723299677 +0100
12163 +/* SPDX-License-Identifier: GPL-2.0 */
12165 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12167 + * This program, aufs is free software; you can redistribute it and/or modify
12168 + * it under the terms of the GNU General Public License as published by
12169 + * the Free Software Foundation; either version 2 of the License, or
12170 + * (at your option) any later version.
12172 + * This program is distributed in the hope that it will be useful,
12173 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12174 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12175 + * GNU General Public License for more details.
12177 + * You should have received a copy of the GNU General Public License
12178 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12182 + * renamed dir info
12185 +#ifndef __AUFS_DIRREN_H__
12186 +#define __AUFS_DIRREN_H__
12190 +#include <linux/dcache.h>
12191 +#include <linux/statfs.h>
12192 +#include <linux/uuid.h>
12195 +#define AuDirren_NHASH 100
12197 +#ifdef CONFIG_AUFS_DIRREN
12198 +enum au_brid_type {
12205 +struct au_dr_brid {
12206 + enum au_brid_type type;
12208 + uuid_t uuid; /* unimplemented yet */
12214 +/* 20 is the max digits length of ulong 64 */
12215 +/* brid-type "_" uuid "_" inum */
12216 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12217 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12219 +struct au_dr_hino {
12220 + struct hlist_bl_node dr_hnode;
12225 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12226 + struct au_dr_brid dr_brid;
12229 +struct au_dr_lookup {
12230 + /* dr_name is pointed by struct au_do_lookup_args.name */
12231 + struct qstr dr_name; /* subset of dr_info */
12232 + aufs_bindex_t ninfo;
12233 + struct au_drinfo **drinfo;
12236 +struct au_dr_hino;
12238 +struct au_dr_br { };
12239 +struct au_dr_lookup { };
12242 +/* ---------------------------------------------------------------------- */
12245 +struct au_do_lookup_args;
12247 +#ifdef CONFIG_AUFS_DIRREN
12248 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12249 + struct au_dr_hino *add_ent);
12250 +void au_dr_hino_free(struct au_dr_br *dr);
12251 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12252 + const struct path *path);
12253 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12254 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12255 + struct qstr *dst_name, void *_rev);
12256 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12257 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12258 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12259 + aufs_bindex_t bindex);
12260 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12261 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12263 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12264 +int au_dr_opt_set(struct super_block *sb);
12265 +int au_dr_opt_flush(struct super_block *sb);
12266 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12268 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12269 + struct au_dr_hino *add_ent);
12270 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12271 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12272 + const struct path *path);
12273 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12274 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12275 + struct qstr *dst_name, void *_rev);
12276 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12277 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12279 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12280 + aufs_bindex_t bindex);
12281 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12282 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12283 + aufs_bindex_t bindex, ino_t h_ino);
12284 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12285 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12286 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12287 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12290 +/* ---------------------------------------------------------------------- */
12292 +#ifdef CONFIG_AUFS_DIRREN
12293 +static inline int au_dr_ihash(ino_t h_ino)
12295 + return h_ino % AuDirren_NHASH;
12298 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12301 +#endif /* __KERNEL__ */
12302 +#endif /* __AUFS_DIRREN_H__ */
12303 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12304 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12305 +++ linux/fs/aufs/dynop.c 2022-03-21 14:49:05.723299677 +0100
12307 +// SPDX-License-Identifier: GPL-2.0
12309 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12311 + * This program, aufs is free software; you can redistribute it and/or modify
12312 + * it under the terms of the GNU General Public License as published by
12313 + * the Free Software Foundation; either version 2 of the License, or
12314 + * (at your option) any later version.
12316 + * This program is distributed in the hope that it will be useful,
12317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12319 + * GNU General Public License for more details.
12321 + * You should have received a copy of the GNU General Public License
12322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12326 + * dynamically customizable operations for regular files
12331 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12334 + * How large will these lists be?
12335 + * Usually just a few elements, 20-30 at most for each, I guess.
12337 +static struct hlist_bl_head dynop[AuDyLast];
12339 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12340 + const void *h_op)
12342 + struct au_dykey *key, *tmp;
12343 + struct hlist_bl_node *pos;
12346 + hlist_bl_lock(hbl);
12347 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12348 + if (tmp->dk_op.dy_hop == h_op) {
12349 + if (kref_get_unless_zero(&tmp->dk_kref))
12353 + hlist_bl_unlock(hbl);
12358 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12360 + struct au_dykey **k, *found;
12361 + const void *h_op = key->dk_op.dy_hop;
12365 + k = br->br_dykey;
12366 + for (i = 0; i < AuBrDynOp; i++)
12368 + if (k[i]->dk_op.dy_hop == h_op) {
12375 + spin_lock(&br->br_dykey_lock);
12376 + for (; i < AuBrDynOp; i++)
12378 + if (k[i]->dk_op.dy_hop == h_op) {
12386 + spin_unlock(&br->br_dykey_lock);
12387 + BUG_ON(i == AuBrDynOp); /* expand the array */
12393 +/* kref_get() if @key is already added */
12394 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12396 + struct au_dykey *tmp, *found;
12397 + struct hlist_bl_node *pos;
12398 + const void *h_op = key->dk_op.dy_hop;
12401 + hlist_bl_lock(hbl);
12402 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12403 + if (tmp->dk_op.dy_hop == h_op) {
12404 + if (kref_get_unless_zero(&tmp->dk_kref))
12409 + hlist_bl_add_head(&key->dk_hnode, hbl);
12410 + hlist_bl_unlock(hbl);
12417 +static void dy_free_rcu(struct rcu_head *rcu)
12419 + struct au_dykey *key;
12421 + key = container_of(rcu, struct au_dykey, dk_rcu);
12426 +static void dy_free(struct kref *kref)
12428 + struct au_dykey *key;
12429 + struct hlist_bl_head *hbl;
12431 + key = container_of(kref, struct au_dykey, dk_kref);
12432 + hbl = dynop + key->dk_op.dy_type;
12433 + au_hbl_del(&key->dk_hnode, hbl);
12434 + call_rcu(&key->dk_rcu, dy_free_rcu);
12437 +void au_dy_put(struct au_dykey *key)
12439 + kref_put(&key->dk_kref, dy_free);
12442 +/* ---------------------------------------------------------------------- */
12444 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12446 +#ifdef CONFIG_AUFS_DEBUG
12447 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12448 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12450 +#define DyDbgDeclare(cnt) do {} while (0)
12451 +#define DyDbgInc(cnt) do {} while (0)
12454 +#define DySet(func, dst, src, h_op, h_sb) do { \
12456 + if (h_op->func) { \
12458 + dst.func = src.func; \
12460 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12464 +#define DySetForce(func, dst, src) do { \
12465 + AuDebugOn(!src.func); \
12467 + dst.func = src.func; \
12470 +#define DySetAop(func) \
12471 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12472 +#define DySetAopForce(func) \
12473 + DySetForce(func, dyaop->da_op, aufs_aop)
12475 +static void dy_aop(struct au_dykey *key, const void *h_op,
12476 + struct super_block *h_sb __maybe_unused)
12478 + struct au_dyaop *dyaop = (void *)key;
12479 + const struct address_space_operations *h_aop = h_op;
12480 + DyDbgDeclare(cnt);
12482 + AuDbg("%s\n", au_sbtype(h_sb));
12484 + DySetAop(writepage);
12485 + DySetAopForce(readpage); /* force */
12486 + DySetAop(writepages);
12487 + DySetAop(set_page_dirty);
12488 + DySetAop(readpages);
12489 + DySetAop(readahead);
12490 + DySetAop(write_begin);
12491 + DySetAop(write_end);
12493 + DySetAop(invalidatepage);
12494 + DySetAop(releasepage);
12495 + DySetAop(freepage);
12496 + /* this one will be changed according to an aufs mount option */
12497 + DySetAop(direct_IO);
12498 + DySetAop(migratepage);
12499 + DySetAop(isolate_page);
12500 + DySetAop(putback_page);
12501 + DySetAop(launder_page);
12502 + DySetAop(is_partially_uptodate);
12503 + DySetAop(is_dirty_writeback);
12504 + DySetAop(error_remove_page);
12505 + DySetAop(swap_activate);
12506 + DySetAop(swap_deactivate);
12508 + DyDbgSize(cnt, *h_aop);
12511 +/* ---------------------------------------------------------------------- */
12513 +static void dy_bug(struct kref *kref)
12518 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12520 + struct au_dykey *key, *old;
12521 + struct hlist_bl_head *hbl;
12524 + void (*set)(struct au_dykey *key, const void *h_op,
12525 + struct super_block *h_sb __maybe_unused);
12527 + static const struct op a[] = {
12529 + .sz = sizeof(struct au_dyaop),
12533 + const struct op *p;
12535 + hbl = dynop + op->dy_type;
12536 + key = dy_gfind_get(hbl, op->dy_hop);
12538 + goto out_add; /* success */
12540 + p = a + op->dy_type;
12541 + key = kzalloc(p->sz, GFP_NOFS);
12542 + if (unlikely(!key)) {
12543 + key = ERR_PTR(-ENOMEM);
12547 + key->dk_op.dy_hop = op->dy_hop;
12548 + kref_init(&key->dk_kref);
12549 + p->set(key, op->dy_hop, au_br_sb(br));
12550 + old = dy_gadd(hbl, key);
12552 + au_kfree_rcu(key);
12557 + old = dy_bradd(br, key);
12559 + /* its ref-count should never be zero here */
12560 + kref_put(&key->dk_kref, dy_bug);
12565 +/* ---------------------------------------------------------------------- */
12567 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12568 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12569 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12570 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12571 + * See the aufs manual in detail.
12573 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12576 + dyaop->da_op.direct_IO = NULL;
12578 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12581 +static struct au_dyaop *dy_aget(struct au_branch *br,
12582 + const struct address_space_operations *h_aop,
12585 + struct au_dyaop *dyaop;
12586 + struct au_dynop op;
12588 + op.dy_type = AuDy_AOP;
12589 + op.dy_haop = h_aop;
12590 + dyaop = (void *)dy_get(&op, br);
12591 + if (IS_ERR(dyaop))
12593 + dy_adx(dyaop, do_dx);
12599 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12600 + struct inode *h_inode)
12603 + struct super_block *sb;
12604 + struct au_branch *br;
12605 + struct au_dyaop *dyaop;
12607 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12608 + IiMustWriteLock(inode);
12610 + sb = inode->i_sb;
12611 + br = au_sbr(sb, bindex);
12612 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12613 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12614 + err = PTR_ERR(dyaop);
12615 + if (IS_ERR(dyaop))
12616 + /* unnecessary to call dy_fput() */
12620 + inode->i_mapping->a_ops = &dyaop->da_op;
12627 + * Is it safe to replace a_ops during the inode/file is in operation?
12628 + * Yes, I hope so.
12630 +int au_dy_irefresh(struct inode *inode)
12633 + aufs_bindex_t btop;
12634 + struct inode *h_inode;
12637 + if (S_ISREG(inode->i_mode)) {
12638 + btop = au_ibtop(inode);
12639 + h_inode = au_h_iptr(inode, btop);
12640 + err = au_dy_iaop(inode, btop, h_inode);
12645 +void au_dy_arefresh(int do_dx)
12647 + struct hlist_bl_head *hbl;
12648 + struct hlist_bl_node *pos;
12649 + struct au_dykey *key;
12651 + hbl = dynop + AuDy_AOP;
12652 + hlist_bl_lock(hbl);
12653 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12654 + dy_adx((void *)key, do_dx);
12655 + hlist_bl_unlock(hbl);
12658 +/* ---------------------------------------------------------------------- */
12660 +void __init au_dy_init(void)
12664 + for (i = 0; i < AuDyLast; i++)
12665 + INIT_HLIST_BL_HEAD(dynop + i);
12668 +void au_dy_fin(void)
12672 + for (i = 0; i < AuDyLast; i++)
12673 + WARN_ON(!hlist_bl_empty(dynop + i));
12675 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12676 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12677 +++ linux/fs/aufs/dynop.h 2022-03-21 14:49:05.723299677 +0100
12679 +/* SPDX-License-Identifier: GPL-2.0 */
12681 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12683 + * This program, aufs is free software; you can redistribute it and/or modify
12684 + * it under the terms of the GNU General Public License as published by
12685 + * the Free Software Foundation; either version 2 of the License, or
12686 + * (at your option) any later version.
12688 + * This program is distributed in the hope that it will be useful,
12689 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12690 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12691 + * GNU General Public License for more details.
12693 + * You should have received a copy of the GNU General Public License
12694 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12698 + * dynamically customizable operations (for regular files only)
12701 +#ifndef __AUFS_DYNOP_H__
12702 +#define __AUFS_DYNOP_H__
12706 +#include <linux/fs.h>
12707 +#include <linux/kref.h>
12709 +enum {AuDy_AOP, AuDyLast};
12714 + const void *dy_hop;
12715 + const struct address_space_operations *dy_haop;
12721 + struct hlist_bl_node dk_hnode;
12722 + struct rcu_head dk_rcu;
12724 + struct au_dynop dk_op;
12727 + * during I am in the branch local array, kref is gotten. when the
12728 + * branch is removed, kref is put.
12730 + struct kref dk_kref;
12733 +/* stop unioning since their sizes are very different from each other */
12735 + struct au_dykey da_key;
12736 + struct address_space_operations da_op; /* not const */
12738 +/* make sure that 'struct au_dykey *' can be any type */
12739 +static_assert(!offsetof(struct au_dyaop, da_key));
12741 +/* ---------------------------------------------------------------------- */
12745 +void au_dy_put(struct au_dykey *key);
12746 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12747 + struct inode *h_inode);
12748 +int au_dy_irefresh(struct inode *inode);
12749 +void au_dy_arefresh(int do_dio);
12751 +void __init au_dy_init(void);
12752 +void au_dy_fin(void);
12754 +#endif /* __KERNEL__ */
12755 +#endif /* __AUFS_DYNOP_H__ */
12756 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12757 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12758 +++ linux/fs/aufs/export.c 2022-03-21 14:49:05.723299677 +0100
12760 +// SPDX-License-Identifier: GPL-2.0
12762 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12764 + * This program, aufs is free software; you can redistribute it and/or modify
12765 + * it under the terms of the GNU General Public License as published by
12766 + * the Free Software Foundation; either version 2 of the License, or
12767 + * (at your option) any later version.
12769 + * This program is distributed in the hope that it will be useful,
12770 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12771 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12772 + * GNU General Public License for more details.
12774 + * You should have received a copy of the GNU General Public License
12775 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12782 +#include <linux/exportfs.h>
12783 +#include <linux/fs_struct.h>
12784 +#include <linux/nsproxy.h>
12785 +#include <linux/random.h>
12786 +#include <linux/writeback.h>
12790 +#ifdef CONFIG_AUFS_INO_T_64
12798 +static ino_t decode_ino(__u32 *a)
12802 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12804 +#ifdef CONFIG_AUFS_INO_T_64
12810 +static void encode_ino(__u32 *a, ino_t ino)
12816 +#ifdef CONFIG_AUFS_INO_T_64
12821 +/* NFS file handle */
12825 +#ifdef CONFIG_AUFS_INO_T_64
12826 + /* support 64bit inode number */
12839 + Fh_ino = Fh_ino1,
12840 + Fh_dir_ino = Fh_dir_ino1
12843 +static int au_test_anon(struct dentry *dentry)
12845 + /* note: read d_flags without d_lock */
12846 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12849 +int au_test_nfsd(void)
12852 + struct task_struct *tsk = current;
12853 + char comm[sizeof(tsk->comm)];
12856 + if (tsk->flags & PF_KTHREAD) {
12857 + get_task_comm(comm, tsk);
12858 + ret = !strcmp(comm, "nfsd");
12864 +/* ---------------------------------------------------------------------- */
12865 +/* inode generation external table */
12867 +void au_xigen_inc(struct inode *inode)
12872 + struct super_block *sb;
12873 + struct au_sbinfo *sbinfo;
12875 + sb = inode->i_sb;
12876 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12878 + sbinfo = au_sbi(sb);
12879 + pos = inode->i_ino;
12880 + pos *= sizeof(igen);
12881 + igen = inode->i_generation + 1;
12882 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12883 + if (sz == sizeof(igen))
12884 + return; /* success */
12886 + if (unlikely(sz >= 0))
12887 + AuIOErr("xigen error (%zd)\n", sz);
12890 +int au_xigen_new(struct inode *inode)
12895 + struct super_block *sb;
12896 + struct au_sbinfo *sbinfo;
12897 + struct file *file;
12900 + /* todo: dirty, at mount time */
12901 + if (inode->i_ino == AUFS_ROOT_INO)
12903 + sb = inode->i_sb;
12904 + SiMustAnyLock(sb);
12905 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12909 + pos = inode->i_ino;
12910 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12911 + AuIOErr1("too large i%lld\n", pos);
12914 + pos *= sizeof(inode->i_generation);
12917 + sbinfo = au_sbi(sb);
12918 + file = sbinfo->si_xigen;
12921 + if (vfsub_f_size_read(file)
12922 + < pos + sizeof(inode->i_generation)) {
12923 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12924 + sz = xino_fwrite(file, &inode->i_generation,
12925 + sizeof(inode->i_generation), &pos);
12927 + sz = xino_fread(file, &inode->i_generation,
12928 + sizeof(inode->i_generation), &pos);
12929 + if (sz == sizeof(inode->i_generation))
12930 + goto out; /* success */
12933 + if (unlikely(sz >= 0)) {
12935 + AuIOErr("xigen error (%zd)\n", sz);
12942 +int au_xigen_set(struct super_block *sb, struct path *path)
12945 + struct au_sbinfo *sbinfo;
12946 + struct file *file;
12948 + SiMustWriteLock(sb);
12950 + sbinfo = au_sbi(sb);
12951 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12952 + err = PTR_ERR(file);
12953 + if (IS_ERR(file))
12956 + if (sbinfo->si_xigen)
12957 + fput(sbinfo->si_xigen);
12958 + sbinfo->si_xigen = file;
12965 +void au_xigen_clr(struct super_block *sb)
12967 + struct au_sbinfo *sbinfo;
12969 + SiMustWriteLock(sb);
12971 + sbinfo = au_sbi(sb);
12972 + if (sbinfo->si_xigen) {
12973 + fput(sbinfo->si_xigen);
12974 + sbinfo->si_xigen = NULL;
12978 +/* ---------------------------------------------------------------------- */
12980 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
12983 + struct dentry *dentry, *d;
12984 + struct inode *inode;
12985 + unsigned int sigen;
12988 + inode = ilookup(sb, ino);
12992 + dentry = ERR_PTR(-ESTALE);
12993 + sigen = au_sigen(sb);
12994 + if (unlikely(au_is_bad_inode(inode)
12995 + || IS_DEADDIR(inode)
12996 + || sigen != au_iigen(inode, NULL)))
13000 + if (!dir_ino || S_ISDIR(inode->i_mode))
13001 + dentry = d_find_alias(inode);
13003 + spin_lock(&inode->i_lock);
13004 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13005 + spin_lock(&d->d_lock);
13006 + if (!au_test_anon(d)
13007 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13008 + dentry = dget_dlock(d);
13009 + spin_unlock(&d->d_lock);
13012 + spin_unlock(&d->d_lock);
13014 + spin_unlock(&inode->i_lock);
13016 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13017 + /* need to refresh */
13025 + AuTraceErrPtr(dentry);
13029 +/* ---------------------------------------------------------------------- */
13031 +/* todo: dirty? */
13032 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13034 +struct au_compare_mnt_args {
13036 + struct super_block *sb;
13039 + struct vfsmount *mnt;
13042 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13044 + struct au_compare_mnt_args *a = arg;
13046 + if (mnt->mnt_sb != a->sb)
13048 + a->mnt = mntget(mnt);
13052 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13055 + struct path root;
13056 + struct au_compare_mnt_args args = {
13060 + get_fs_root(current->fs, &root);
13062 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13063 + rcu_read_unlock();
13066 + AuDebugOn(!args.mnt);
13070 +struct au_nfsd_si_lock {
13071 + unsigned int sigen;
13072 + aufs_bindex_t bindex, br_id;
13073 + unsigned char force_lock;
13076 +static int si_nfsd_read_lock(struct super_block *sb,
13077 + struct au_nfsd_si_lock *nsi_lock)
13080 + aufs_bindex_t bindex;
13082 + si_read_lock(sb, AuLock_FLUSH);
13084 + /* branch id may be wrapped around */
13086 + bindex = au_br_index(sb, nsi_lock->br_id);
13087 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13088 + goto out; /* success */
13092 + if (!nsi_lock->force_lock)
13093 + si_read_unlock(sb);
13096 + nsi_lock->bindex = bindex;
13100 +struct find_name_by_ino {
13101 + struct dir_context ctx;
13102 + int called, found;
13109 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13110 + loff_t offset, u64 ino, unsigned int d_type)
13112 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13116 + if (a->ino != ino)
13119 + memcpy(a->name, name, namelen);
13120 + a->namelen = namelen;
13125 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13126 + struct au_nfsd_si_lock *nsi_lock)
13128 + struct dentry *dentry, *parent;
13129 + struct file *file;
13130 + struct inode *dir;
13131 + struct find_name_by_ino arg = {
13133 + .actor = find_name_by_ino
13138 + parent = path->dentry;
13140 + si_read_unlock(parent->d_sb);
13141 + file = vfsub_dentry_open(path, au_dir_roflags);
13142 + dentry = (void *)file;
13143 + if (IS_ERR(file))
13146 + dentry = ERR_PTR(-ENOMEM);
13147 + arg.name = (void *)__get_free_page(GFP_NOFS);
13148 + if (unlikely(!arg.name))
13155 + err = vfsub_iterate_dir(file, &arg.ctx);
13156 + } while (!err && !arg.found && arg.called);
13157 + dentry = ERR_PTR(err);
13158 + if (unlikely(err))
13160 + /* instead of ENOENT */
13161 + dentry = ERR_PTR(-ESTALE);
13165 + /* do not call vfsub_lkup_one() */
13166 + dir = d_inode(parent);
13167 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13168 + AuTraceErrPtr(dentry);
13169 + if (IS_ERR(dentry))
13171 + AuDebugOn(au_test_anon(dentry));
13172 + if (unlikely(d_really_is_negative(dentry))) {
13174 + dentry = ERR_PTR(-ENOENT);
13178 + free_page((unsigned long)arg.name);
13182 + if (unlikely(nsi_lock
13183 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13184 + if (!IS_ERR(dentry)) {
13186 + dentry = ERR_PTR(-ESTALE);
13188 + AuTraceErrPtr(dentry);
13192 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13194 + struct au_nfsd_si_lock *nsi_lock)
13196 + struct dentry *dentry;
13197 + struct path path;
13199 + if (dir_ino != AUFS_ROOT_INO) {
13200 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13201 + dentry = path.dentry;
13202 + if (!path.dentry || IS_ERR(path.dentry))
13204 + AuDebugOn(au_test_anon(path.dentry));
13206 + path.dentry = dget(sb->s_root);
13208 + path.mnt = au_mnt_get(sb);
13209 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13213 + AuTraceErrPtr(dentry);
13217 +/* ---------------------------------------------------------------------- */
13219 +static int h_acceptable(void *expv, struct dentry *dentry)
13224 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13225 + char *buf, int len, struct super_block *sb)
13229 + struct path path;
13231 + p = d_path(h_rootpath, buf, len);
13236 + path.mnt = h_rootpath->mnt;
13237 + path.dentry = h_parent;
13238 + p = d_path(&path, buf, len);
13244 + path.mnt = au_mnt_get(sb);
13245 + path.dentry = sb->s_root;
13246 + p = d_path(&path, buf, len - strlen(p));
13247 + mntput(path.mnt);
13251 + p[strlen(p)] = '/';
13254 + AuTraceErrPtr(p);
13259 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13260 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13262 + struct dentry *dentry, *h_parent, *root;
13263 + struct super_block *h_sb;
13264 + char *pathname, *p;
13265 + struct vfsmount *h_mnt;
13266 + struct au_branch *br;
13268 + struct path path;
13270 + br = au_sbr(sb, nsi_lock->bindex);
13271 + h_mnt = au_br_mnt(br);
13272 + h_sb = h_mnt->mnt_sb;
13273 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13275 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13276 + fh_len - Fh_tail, fh[Fh_h_type],
13277 + h_acceptable, /*context*/NULL);
13279 + dentry = h_parent;
13280 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13281 + AuWarn1("%s decode_fh failed, %ld\n",
13282 + au_sbtype(h_sb), PTR_ERR(h_parent));
13286 + if (unlikely(au_test_anon(h_parent))) {
13287 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13288 + au_sbtype(h_sb));
13289 + goto out_h_parent;
13292 + dentry = ERR_PTR(-ENOMEM);
13293 + pathname = (void *)__get_free_page(GFP_NOFS);
13294 + if (unlikely(!pathname))
13295 + goto out_h_parent;
13297 + root = sb->s_root;
13298 + path.mnt = h_mnt;
13299 + di_read_lock_parent(root, !AuLock_IR);
13300 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13301 + di_read_unlock(root, !AuLock_IR);
13302 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13303 + dentry = (void *)p;
13305 + goto out_pathname;
13307 + si_read_unlock(sb);
13308 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13309 + dentry = ERR_PTR(err);
13310 + if (unlikely(err))
13313 + dentry = ERR_PTR(-ENOENT);
13314 + AuDebugOn(au_test_anon(path.dentry));
13315 + if (unlikely(d_really_is_negative(path.dentry)))
13318 + if (ino != d_inode(path.dentry)->i_ino)
13319 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13321 + dentry = dget(path.dentry);
13326 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13327 + if (!IS_ERR(dentry)) {
13329 + dentry = ERR_PTR(-ESTALE);
13332 + free_page((unsigned long)pathname);
13336 + AuTraceErrPtr(dentry);
13340 +/* ---------------------------------------------------------------------- */
13342 +static struct dentry *
13343 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13346 + struct dentry *dentry;
13347 + __u32 *fh = fid->raw;
13348 + struct au_branch *br;
13349 + ino_t ino, dir_ino;
13350 + struct au_nfsd_si_lock nsi_lock = {
13354 + dentry = ERR_PTR(-ESTALE);
13355 + /* it should never happen, but the file handle is unreliable */
13356 + if (unlikely(fh_len < Fh_tail))
13358 + nsi_lock.sigen = fh[Fh_sigen];
13359 + nsi_lock.br_id = fh[Fh_br_id];
13361 + /* branch id may be wrapped around */
13363 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13365 + nsi_lock.force_lock = 1;
13367 + /* is this inode still cached? */
13368 + ino = decode_ino(fh + Fh_ino);
13369 + /* it should never happen */
13370 + if (unlikely(ino == AUFS_ROOT_INO))
13373 + dir_ino = decode_ino(fh + Fh_dir_ino);
13374 + dentry = decode_by_ino(sb, ino, dir_ino);
13375 + if (IS_ERR(dentry))
13380 + /* is the parent dir cached? */
13381 + br = au_sbr(sb, nsi_lock.bindex);
13382 + au_lcnt_inc(&br->br_nfiles);
13383 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13384 + if (IS_ERR(dentry))
13389 + /* lookup path */
13390 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13391 + if (IS_ERR(dentry))
13393 + if (unlikely(!dentry))
13394 + /* todo?: make it ESTALE */
13398 + if (!au_digen_test(dentry, au_sigen(sb))
13399 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13400 + goto out_unlock; /* success */
13403 + dentry = ERR_PTR(-ESTALE);
13406 + au_lcnt_dec(&br->br_nfiles);
13407 + si_read_unlock(sb);
13409 + AuTraceErrPtr(dentry);
13413 +#if 0 /* reserved for future use */
13414 +/* support subtreecheck option */
13415 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13416 + int fh_len, int fh_type)
13418 + struct dentry *parent;
13419 + __u32 *fh = fid->raw;
13422 + dir_ino = decode_ino(fh + Fh_dir_ino);
13423 + parent = decode_by_ino(sb, dir_ino, 0);
13424 + if (IS_ERR(parent))
13427 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13428 + dir_ino, fh, fh_len);
13431 + AuTraceErrPtr(parent);
13436 +/* ---------------------------------------------------------------------- */
13438 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13439 + struct inode *dir)
13442 + aufs_bindex_t bindex;
13443 + struct super_block *sb, *h_sb;
13444 + struct dentry *dentry, *parent, *h_parent;
13445 + struct inode *h_dir;
13446 + struct au_branch *br;
13449 + if (unlikely(*max_len <= Fh_tail)) {
13450 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13454 + err = FILEID_ROOT;
13455 + if (inode->i_ino == AUFS_ROOT_INO) {
13456 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13461 + sb = inode->i_sb;
13462 + err = si_read_lock(sb, AuLock_FLUSH);
13463 + if (unlikely(err))
13466 +#ifdef CONFIG_AUFS_DEBUG
13467 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13468 + AuWarn1("NFS-exporting requires xino\n");
13472 + ii_read_lock_child(inode);
13473 + bindex = au_ibtop(inode);
13475 + dentry = d_find_any_alias(inode);
13476 + if (unlikely(!dentry))
13478 + AuDebugOn(au_test_anon(dentry));
13479 + parent = dget_parent(dentry);
13481 + if (unlikely(!parent))
13483 + if (d_really_is_positive(parent))
13484 + dir = d_inode(parent);
13487 + ii_read_lock_parent(dir);
13488 + h_dir = au_h_iptr(dir, bindex);
13489 + ii_read_unlock(dir);
13490 + if (unlikely(!h_dir))
13492 + h_parent = d_find_any_alias(h_dir);
13493 + if (unlikely(!h_parent))
13494 + goto out_hparent;
13497 + br = au_sbr(sb, bindex);
13498 + h_sb = au_br_sb(br);
13499 + if (unlikely(!h_sb->s_export_op)) {
13500 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13501 + goto out_hparent;
13504 + fh[Fh_br_id] = br->br_id;
13505 + fh[Fh_sigen] = au_sigen(sb);
13506 + encode_ino(fh + Fh_ino, inode->i_ino);
13507 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13508 + fh[Fh_igen] = inode->i_generation;
13510 + *max_len -= Fh_tail;
13511 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13513 + /*connectable or subtreecheck*/0);
13514 + err = fh[Fh_h_type];
13515 + *max_len += Fh_tail;
13516 + /* todo: macros? */
13517 + if (err != FILEID_INVALID)
13520 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13527 + ii_read_unlock(inode);
13528 + si_read_unlock(sb);
13530 + if (unlikely(err < 0))
13531 + err = FILEID_INVALID;
13535 +/* ---------------------------------------------------------------------- */
13537 +static int aufs_commit_metadata(struct inode *inode)
13540 + aufs_bindex_t bindex;
13541 + struct super_block *sb;
13542 + struct inode *h_inode;
13543 + int (*f)(struct inode *inode);
13545 + sb = inode->i_sb;
13546 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13547 + ii_write_lock_child(inode);
13548 + bindex = au_ibtop(inode);
13549 + AuDebugOn(bindex < 0);
13550 + h_inode = au_h_iptr(inode, bindex);
13552 + f = h_inode->i_sb->s_export_op->commit_metadata;
13554 + err = f(h_inode);
13556 + err = sync_inode_metadata(h_inode, /*wait*/1);
13558 + au_cpup_attr_timesizes(inode);
13559 + ii_write_unlock(inode);
13560 + si_read_unlock(sb);
13564 +/* ---------------------------------------------------------------------- */
13566 +static struct export_operations aufs_export_op = {
13567 + .fh_to_dentry = aufs_fh_to_dentry,
13568 + /* .fh_to_parent = aufs_fh_to_parent, */
13569 + .encode_fh = aufs_encode_fh,
13570 + .commit_metadata = aufs_commit_metadata
13573 +void au_export_init(struct super_block *sb)
13575 + struct au_sbinfo *sbinfo;
13578 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13579 + && IS_MODULE(CONFIG_EXPORTFS),
13580 + AUFS_NAME ": unsupported configuration "
13581 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13583 + sb->s_export_op = &aufs_export_op;
13584 + sbinfo = au_sbi(sb);
13585 + sbinfo->si_xigen = NULL;
13586 + get_random_bytes(&u, sizeof(u));
13587 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13588 + atomic_set(&sbinfo->si_xigen_next, u);
13590 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13591 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13592 +++ linux/fs/aufs/fhsm.c 2022-03-21 14:49:05.723299677 +0100
13594 +// SPDX-License-Identifier: GPL-2.0
13596 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13598 + * This program, aufs is free software; you can redistribute it and/or modify
13599 + * it under the terms of the GNU General Public License as published by
13600 + * the Free Software Foundation; either version 2 of the License, or
13601 + * (at your option) any later version.
13603 + * This program is distributed in the hope that it will be useful,
13604 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13605 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13606 + * GNU General Public License for more details.
13608 + * You should have received a copy of the GNU General Public License
13609 + * along with this program; if not, write to the Free Software
13610 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13614 + * File-based Hierarchy Storage Management
13617 +#include <linux/anon_inodes.h>
13618 +#include <linux/poll.h>
13619 +#include <linux/seq_file.h>
13620 +#include <linux/statfs.h>
13623 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13625 + struct au_sbinfo *sbinfo;
13626 + struct au_fhsm *fhsm;
13628 + SiMustAnyLock(sb);
13630 + sbinfo = au_sbi(sb);
13631 + fhsm = &sbinfo->si_fhsm;
13632 + AuDebugOn(!fhsm);
13633 + return fhsm->fhsm_bottom;
13636 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13638 + struct au_sbinfo *sbinfo;
13639 + struct au_fhsm *fhsm;
13641 + SiMustWriteLock(sb);
13643 + sbinfo = au_sbi(sb);
13644 + fhsm = &sbinfo->si_fhsm;
13645 + AuDebugOn(!fhsm);
13646 + fhsm->fhsm_bottom = bindex;
13649 +/* ---------------------------------------------------------------------- */
13651 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13653 + struct au_br_fhsm *bf;
13655 + bf = br->br_fhsm;
13656 + MtxMustLock(&bf->bf_lock);
13658 + return !bf->bf_readable
13659 + || time_after(jiffies,
13660 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13663 +/* ---------------------------------------------------------------------- */
13665 +static void au_fhsm_notify(struct super_block *sb, int val)
13667 + struct au_sbinfo *sbinfo;
13668 + struct au_fhsm *fhsm;
13670 + SiMustAnyLock(sb);
13672 + sbinfo = au_sbi(sb);
13673 + fhsm = &sbinfo->si_fhsm;
13674 + if (au_fhsm_pid(fhsm)
13675 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13676 + atomic_set(&fhsm->fhsm_readable, val);
13678 + wake_up(&fhsm->fhsm_wqh);
13682 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13683 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13686 + struct au_branch *br;
13687 + struct au_br_fhsm *bf;
13689 + br = au_sbr(sb, bindex);
13690 + AuDebugOn(au_br_rdonly(br));
13691 + bf = br->br_fhsm;
13695 + mutex_lock(&bf->bf_lock);
13697 + MtxMustLock(&bf->bf_lock);
13699 + /* sb->s_root for NFS is unreliable */
13700 + err = au_br_stfs(br, &bf->bf_stfs);
13701 + if (unlikely(err)) {
13702 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13706 + bf->bf_jiffy = jiffies;
13707 + bf->bf_readable = 1;
13709 + au_fhsm_notify(sb, /*val*/1);
13711 + *rstfs = bf->bf_stfs;
13715 + mutex_unlock(&bf->bf_lock);
13716 + au_fhsm_notify(sb, /*val*/1);
13721 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13724 + struct au_sbinfo *sbinfo;
13725 + struct au_fhsm *fhsm;
13726 + struct au_branch *br;
13727 + struct au_br_fhsm *bf;
13729 + AuDbg("b%d, force %d\n", bindex, force);
13730 + SiMustAnyLock(sb);
13732 + sbinfo = au_sbi(sb);
13733 + fhsm = &sbinfo->si_fhsm;
13734 + if (!au_ftest_si(sbinfo, FHSM)
13735 + || fhsm->fhsm_bottom == bindex)
13738 + br = au_sbr(sb, bindex);
13739 + bf = br->br_fhsm;
13741 + mutex_lock(&bf->bf_lock);
13743 + || au_fhsm_pid(fhsm)
13744 + || au_fhsm_test_jiffy(sbinfo, br))
13745 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13747 + mutex_unlock(&bf->bf_lock);
13750 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13752 + aufs_bindex_t bindex, bbot;
13753 + struct au_branch *br;
13755 + /* exclude the bottom */
13756 + bbot = au_fhsm_bottom(sb);
13757 + for (bindex = 0; bindex < bbot; bindex++) {
13758 + br = au_sbr(sb, bindex);
13759 + if (au_br_fhsm(br->br_perm))
13760 + au_fhsm_wrote(sb, bindex, force);
13764 +/* ---------------------------------------------------------------------- */
13766 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13769 + struct au_sbinfo *sbinfo;
13770 + struct au_fhsm *fhsm;
13773 + sbinfo = file->private_data;
13774 + fhsm = &sbinfo->si_fhsm;
13775 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13776 + if (atomic_read(&fhsm->fhsm_readable))
13777 + mask = EPOLLIN /* | EPOLLRDNORM */;
13780 + AuDbg("mask 0x%x\n", mask);
13784 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13785 + struct aufs_stfs *stfs, __s16 brid)
13789 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13791 + err = __put_user(brid, &stbr->brid);
13792 + if (unlikely(err))
13798 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13799 + struct aufs_stbr __user *stbr, size_t count)
13803 + aufs_bindex_t bindex, bbot;
13804 + struct au_branch *br;
13805 + struct au_br_fhsm *bf;
13807 + /* except the bottom branch */
13810 + bbot = au_fhsm_bottom(sb);
13811 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13812 + br = au_sbr(sb, bindex);
13813 + if (!au_br_fhsm(br->br_perm))
13816 + bf = br->br_fhsm;
13817 + mutex_lock(&bf->bf_lock);
13818 + if (bf->bf_readable) {
13820 + if (count >= sizeof(*stbr))
13821 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13824 + bf->bf_readable = 0;
13825 + count -= sizeof(*stbr);
13829 + mutex_unlock(&bf->bf_lock);
13832 + err = sizeof(*stbr) * nstbr;
13837 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13842 + aufs_bindex_t nfhsm, bindex, bbot;
13843 + struct au_sbinfo *sbinfo;
13844 + struct au_fhsm *fhsm;
13845 + struct au_branch *br;
13846 + struct super_block *sb;
13849 + sbinfo = file->private_data;
13850 + fhsm = &sbinfo->si_fhsm;
13852 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13853 + if (!atomic_read(&fhsm->fhsm_readable)) {
13854 + if (vfsub_file_flags(file) & O_NONBLOCK)
13857 + err = wait_event_interruptible_locked_irq
13859 + atomic_read(&fhsm->fhsm_readable));
13861 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13862 + if (unlikely(err))
13865 + /* sb may already be dead */
13866 + au_rw_read_lock(&sbinfo->si_rwsem);
13867 + readable = atomic_read(&fhsm->fhsm_readable);
13868 + if (readable > 0) {
13869 + sb = sbinfo->si_sb;
13871 + /* exclude the bottom branch */
13873 + bbot = au_fhsm_bottom(sb);
13874 + for (bindex = 0; bindex < bbot; bindex++) {
13875 + br = au_sbr(sb, bindex);
13876 + if (au_br_fhsm(br->br_perm))
13880 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13881 + atomic_set(&fhsm->fhsm_readable, 0);
13882 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13886 + au_rw_read_unlock(&sbinfo->si_rwsem);
13894 +static int au_fhsm_release(struct inode *inode, struct file *file)
13896 + struct au_sbinfo *sbinfo;
13897 + struct au_fhsm *fhsm;
13899 + /* sb may already be dead */
13900 + sbinfo = file->private_data;
13901 + fhsm = &sbinfo->si_fhsm;
13902 + spin_lock(&fhsm->fhsm_spin);
13903 + fhsm->fhsm_pid = 0;
13904 + spin_unlock(&fhsm->fhsm_spin);
13905 + kobject_put(&sbinfo->si_kobj);
13910 +static const struct file_operations au_fhsm_fops = {
13911 + .owner = THIS_MODULE,
13912 + .llseek = noop_llseek,
13913 + .read = au_fhsm_read,
13914 + .poll = au_fhsm_poll,
13915 + .release = au_fhsm_release
13918 +int au_fhsm_fd(struct super_block *sb, int oflags)
13921 + struct au_sbinfo *sbinfo;
13922 + struct au_fhsm *fhsm;
13925 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13929 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13933 + sbinfo = au_sbi(sb);
13934 + fhsm = &sbinfo->si_fhsm;
13935 + spin_lock(&fhsm->fhsm_spin);
13936 + if (!fhsm->fhsm_pid)
13937 + fhsm->fhsm_pid = current->pid;
13940 + spin_unlock(&fhsm->fhsm_spin);
13941 + if (unlikely(err))
13944 + oflags |= O_RDONLY;
13945 + /* oflags |= FMODE_NONOTIFY; */
13946 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13948 + if (unlikely(fd < 0))
13951 + /* succeed regardless 'fhsm' status */
13952 + kobject_get(&sbinfo->si_kobj);
13953 + si_noflush_read_lock(sb);
13954 + if (au_ftest_si(sbinfo, FHSM))
13955 + au_fhsm_wrote_all(sb, /*force*/0);
13956 + si_read_unlock(sb);
13957 + goto out; /* success */
13960 + spin_lock(&fhsm->fhsm_spin);
13961 + fhsm->fhsm_pid = 0;
13962 + spin_unlock(&fhsm->fhsm_spin);
13968 +/* ---------------------------------------------------------------------- */
13970 +int au_fhsm_br_alloc(struct au_branch *br)
13975 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13977 + au_br_fhsm_init(br->br_fhsm);
13984 +/* ---------------------------------------------------------------------- */
13986 +void au_fhsm_fin(struct super_block *sb)
13988 + au_fhsm_notify(sb, /*val*/-1);
13991 +void au_fhsm_init(struct au_sbinfo *sbinfo)
13993 + struct au_fhsm *fhsm;
13995 + fhsm = &sbinfo->si_fhsm;
13996 + spin_lock_init(&fhsm->fhsm_spin);
13997 + init_waitqueue_head(&fhsm->fhsm_wqh);
13998 + atomic_set(&fhsm->fhsm_readable, 0);
13999 + fhsm->fhsm_expire
14000 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14001 + fhsm->fhsm_bottom = -1;
14004 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14006 + sbinfo->si_fhsm.fhsm_expire
14007 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14010 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14014 + if (!au_ftest_si(sbinfo, FHSM))
14017 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14018 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14019 + seq_printf(seq, ",fhsm_sec=%u", u);
14021 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14022 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14023 +++ linux/fs/aufs/file.c 2022-03-21 14:49:05.723299677 +0100
14025 +// SPDX-License-Identifier: GPL-2.0
14027 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14029 + * This program, aufs is free software; you can redistribute it and/or modify
14030 + * it under the terms of the GNU General Public License as published by
14031 + * the Free Software Foundation; either version 2 of the License, or
14032 + * (at your option) any later version.
14034 + * This program is distributed in the hope that it will be useful,
14035 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14036 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14037 + * GNU General Public License for more details.
14039 + * You should have received a copy of the GNU General Public License
14040 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14044 + * handling file/dir, and address_space operation
14047 +#ifdef CONFIG_AUFS_DEBUG
14048 +#include <linux/migrate.h>
14050 +#include <linux/pagemap.h>
14053 +/* drop flags for writing */
14054 +unsigned int au_file_roflags(unsigned int flags)
14056 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14057 + flags |= O_RDONLY | O_NOATIME;
14061 +/* common functions to regular file and dir */
14062 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14063 + struct file *file, int force_wr)
14065 + struct file *h_file;
14066 + struct dentry *h_dentry;
14067 + struct inode *h_inode;
14068 + struct super_block *sb;
14069 + struct au_branch *br;
14070 + struct path h_path;
14073 + /* a race condition can happen between open and unlink/rmdir */
14074 + h_file = ERR_PTR(-ENOENT);
14075 + h_dentry = au_h_dptr(dentry, bindex);
14076 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14078 + h_inode = d_inode(h_dentry);
14079 + spin_lock(&h_dentry->d_lock);
14080 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14081 + /* || !d_inode(dentry)->i_nlink */
14083 + spin_unlock(&h_dentry->d_lock);
14084 + if (unlikely(err))
14087 + sb = dentry->d_sb;
14088 + br = au_sbr(sb, bindex);
14089 + err = au_br_test_oflag(flags, br);
14090 + h_file = ERR_PTR(err);
14091 + if (unlikely(err))
14094 + /* drop flags for writing */
14095 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14096 + if (force_wr && !(flags & O_WRONLY))
14098 + flags = au_file_roflags(flags);
14100 + h_file = ERR_PTR(-EROFS);
14101 + flags = au_file_roflags(flags);
14102 + if (unlikely(vfsub_native_ro(h_inode)
14103 + || IS_APPEND(h_inode)))
14105 + flags &= ~O_ACCMODE;
14106 + flags |= O_WRONLY;
14109 + flags &= ~O_CREAT;
14110 + au_lcnt_inc(&br->br_nfiles);
14111 + h_path.dentry = h_dentry;
14112 + h_path.mnt = au_br_mnt(br);
14113 + h_file = vfsub_dentry_open(&h_path, flags);
14114 + if (IS_ERR(h_file))
14117 + if (flags & __FMODE_EXEC) {
14118 + err = deny_write_access(h_file);
14119 + if (unlikely(err)) {
14121 + h_file = ERR_PTR(err);
14125 + fsnotify_open(h_file);
14126 + goto out; /* success */
14129 + au_lcnt_dec(&br->br_nfiles);
14134 +static int au_cmoo(struct dentry *dentry)
14136 + int err, cmoo, matched;
14137 + unsigned int udba;
14138 + struct path h_path;
14139 + struct au_pin pin;
14140 + struct au_cp_generic cpg = {
14141 + .dentry = dentry,
14146 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14148 + struct inode *delegated;
14149 + struct super_block *sb;
14150 + struct au_sbinfo *sbinfo;
14151 + struct au_fhsm *fhsm;
14153 + struct au_branch *br;
14154 + struct dentry *parent;
14155 + struct au_hinode *hdir;
14157 + DiMustWriteLock(dentry);
14158 + IiMustWriteLock(d_inode(dentry));
14161 + if (IS_ROOT(dentry))
14163 + cpg.bsrc = au_dbtop(dentry);
14167 + sb = dentry->d_sb;
14168 + sbinfo = au_sbi(sb);
14169 + fhsm = &sbinfo->si_fhsm;
14170 + pid = au_fhsm_pid(fhsm);
14173 + && (current->pid == pid
14174 + || rcu_dereference(current->real_parent)->pid == pid));
14175 + rcu_read_unlock();
14179 + br = au_sbr(sb, cpg.bsrc);
14180 + cmoo = au_br_cmoo(br->br_perm);
14183 + if (!d_is_reg(dentry))
14184 + cmoo &= AuBrAttr_COO_ALL;
14188 + parent = dget_parent(dentry);
14189 + di_write_lock_parent(parent);
14190 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14192 + if (unlikely(err < 0)) {
14193 + err = 0; /* there is no upper writable branch */
14196 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14198 + /* do not respect the coo attrib for the target branch */
14199 + err = au_cpup_dirs(dentry, cpg.bdst);
14200 + if (unlikely(err))
14203 + di_downgrade_lock(parent, AuLock_IR);
14204 + udba = au_opt_udba(sb);
14205 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14206 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14207 + if (unlikely(err))
14210 + err = au_sio_cpup_simple(&cpg);
14212 + if (unlikely(err))
14214 + if (!(cmoo & AuBrWAttr_MOO))
14215 + goto out_parent; /* success */
14217 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14218 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14219 + if (unlikely(err))
14222 + h_path.mnt = au_br_mnt(br);
14223 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14224 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14225 + delegated = NULL;
14226 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14228 + /* todo: keep h_dentry or not? */
14229 + if (unlikely(err == -EWOULDBLOCK)) {
14230 + pr_warn("cannot retry for NFSv4 delegation"
14231 + " for an internal unlink\n");
14234 + if (unlikely(err)) {
14235 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14239 + goto out_parent; /* success */
14242 + di_downgrade_lock(parent, AuLock_IR);
14244 + di_read_unlock(parent, AuLock_IR);
14251 +int au_do_open(struct file *file, struct au_do_open_args *args)
14253 + int err, aopen = args->aopen;
14254 + struct dentry *dentry;
14255 + struct au_finfo *finfo;
14258 + err = au_finfo_init(file, args->fidir);
14261 + err = au_finfo_init(file, args->fidir);
14264 + if (unlikely(err))
14267 + dentry = file->f_path.dentry;
14268 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14269 + di_write_lock_child(dentry);
14270 + err = au_cmoo(dentry);
14271 + di_downgrade_lock(dentry, AuLock_IR);
14274 + err = args->open(file, vfsub_file_flags(file), NULL);
14277 + err = args->open(file, vfsub_file_flags(file),
14282 + di_read_unlock(dentry, AuLock_IR);
14284 + finfo = au_fi(file);
14286 + finfo->fi_file = file;
14287 + au_hbl_add(&finfo->fi_hlist,
14288 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14291 + fi_write_unlock(file);
14294 + fi_write_unlock(file);
14297 + if (unlikely(err)) {
14298 + finfo->fi_hdir = NULL;
14299 + au_finfo_fin(file);
14307 +int au_reopen_nondir(struct file *file)
14310 + aufs_bindex_t btop;
14311 + struct dentry *dentry;
14312 + struct au_branch *br;
14313 + struct file *h_file, *h_file_tmp;
14315 + dentry = file->f_path.dentry;
14316 + btop = au_dbtop(dentry);
14317 + br = au_sbr(dentry->d_sb, btop);
14318 + h_file_tmp = NULL;
14319 + if (au_fbtop(file) == btop) {
14320 + h_file = au_hf_top(file);
14321 + if (file->f_mode == h_file->f_mode)
14322 + return 0; /* success */
14323 + h_file_tmp = h_file;
14324 + get_file(h_file_tmp);
14325 + au_lcnt_inc(&br->br_nfiles);
14326 + au_set_h_fptr(file, btop, NULL);
14328 + AuDebugOn(au_fi(file)->fi_hdir);
14331 + * file exists on both of rw and ro
14332 + * open --> dbtop and fbtop are both 0
14333 + * prepend a branch as rw, "rw" become ro
14335 + * delete the top branch, "rw" becomes rw again
14336 + * --> dbtop is 1, fbtop is still 0
14337 + * write --> fbtop is 0 but dbtop is 1
14339 + /* AuDebugOn(au_fbtop(file) < btop); */
14341 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14342 + file, /*force_wr*/0);
14343 + err = PTR_ERR(h_file);
14344 + if (IS_ERR(h_file)) {
14345 + if (h_file_tmp) {
14347 + au_set_h_fptr(file, btop, h_file_tmp);
14348 + h_file_tmp = NULL;
14350 + goto out; /* todo: close all? */
14354 + au_set_fbtop(file, btop);
14355 + au_set_h_fptr(file, btop, h_file);
14356 + au_update_figen(file);
14357 + /* todo: necessary? */
14358 + /* file->f_ra = h_file->f_ra; */
14361 + if (h_file_tmp) {
14362 + fput(h_file_tmp);
14363 + au_lcnt_dec(&br->br_nfiles);
14368 +/* ---------------------------------------------------------------------- */
14370 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14371 + struct dentry *hi_wh)
14374 + aufs_bindex_t btop;
14375 + struct au_dinfo *dinfo;
14376 + struct dentry *h_dentry;
14377 + struct au_hdentry *hdp;
14379 + dinfo = au_di(file->f_path.dentry);
14380 + AuRwMustWriteLock(&dinfo->di_rwsem);
14382 + btop = dinfo->di_btop;
14383 + dinfo->di_btop = btgt;
14384 + hdp = au_hdentry(dinfo, btgt);
14385 + h_dentry = hdp->hd_dentry;
14386 + hdp->hd_dentry = hi_wh;
14387 + err = au_reopen_nondir(file);
14388 + hdp->hd_dentry = h_dentry;
14389 + dinfo->di_btop = btop;
14394 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14395 + aufs_bindex_t bcpup, struct au_pin *pin)
14398 + struct inode *inode, *h_inode;
14399 + struct dentry *h_dentry, *hi_wh;
14400 + struct au_cp_generic cpg = {
14401 + .dentry = file->f_path.dentry,
14408 + au_update_dbtop(cpg.dentry);
14409 + inode = d_inode(cpg.dentry);
14411 + if (au_dbtop(cpg.dentry) <= bcpup
14412 + && au_dbbot(cpg.dentry) >= bcpup) {
14413 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14414 + if (h_dentry && d_is_positive(h_dentry))
14415 + h_inode = d_inode(h_dentry);
14417 + hi_wh = au_hi_wh(inode, bcpup);
14418 + if (!hi_wh && !h_inode)
14419 + err = au_sio_cpup_wh(&cpg, file);
14421 + /* already copied-up after unlink */
14422 + err = au_reopen_wh(file, bcpup, hi_wh);
14425 + && (inode->i_nlink > 1
14426 + || (inode->i_state & I_LINKABLE))
14427 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14428 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14434 + * prepare the @file for writing.
14436 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14439 + aufs_bindex_t dbtop;
14440 + struct dentry *parent;
14441 + struct inode *inode;
14442 + struct super_block *sb;
14443 + struct file *h_file;
14444 + struct au_cp_generic cpg = {
14445 + .dentry = file->f_path.dentry,
14450 + .flags = AuCpup_DTIME
14453 + sb = cpg.dentry->d_sb;
14454 + inode = d_inode(cpg.dentry);
14455 + cpg.bsrc = au_fbtop(file);
14456 + err = au_test_ro(sb, cpg.bsrc, inode);
14457 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14458 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14463 + /* need to cpup or reopen */
14464 + parent = dget_parent(cpg.dentry);
14465 + di_write_lock_parent(parent);
14466 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14468 + if (unlikely(err < 0))
14472 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14473 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14474 + if (unlikely(err))
14478 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14479 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14480 + if (unlikely(err))
14483 + dbtop = au_dbtop(cpg.dentry);
14484 + if (dbtop <= cpg.bdst)
14485 + cpg.bsrc = cpg.bdst;
14487 + if (dbtop <= cpg.bdst /* just reopen */
14488 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14490 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14491 + if (IS_ERR(h_file))
14492 + err = PTR_ERR(h_file);
14494 + di_downgrade_lock(parent, AuLock_IR);
14495 + if (dbtop > cpg.bdst)
14496 + err = au_sio_cpup_simple(&cpg);
14498 + err = au_reopen_nondir(file);
14499 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14501 + } else { /* copyup as wh and reopen */
14503 + * since writable hfsplus branch is not supported,
14504 + * h_open_pre/post() are unnecessary.
14506 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14507 + di_downgrade_lock(parent, AuLock_IR);
14511 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14512 + goto out_dput; /* success */
14518 + di_downgrade_lock(parent, AuLock_IR);
14520 + di_read_unlock(parent, AuLock_IR);
14527 +/* ---------------------------------------------------------------------- */
14529 +int au_do_flush(struct file *file, fl_owner_t id,
14530 + int (*flush)(struct file *file, fl_owner_t id))
14533 + struct super_block *sb;
14534 + struct inode *inode;
14536 + inode = file_inode(file);
14537 + sb = inode->i_sb;
14538 + si_noflush_read_lock(sb);
14539 + fi_read_lock(file);
14540 + ii_read_lock_child(inode);
14542 + err = flush(file, id);
14543 + au_cpup_attr_timesizes(inode);
14545 + ii_read_unlock(inode);
14546 + fi_read_unlock(file);
14547 + si_read_unlock(sb);
14551 +/* ---------------------------------------------------------------------- */
14553 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14556 + struct au_pin pin;
14557 + struct au_finfo *finfo;
14558 + struct dentry *parent, *hi_wh;
14559 + struct inode *inode;
14560 + struct super_block *sb;
14561 + struct au_cp_generic cpg = {
14562 + .dentry = file->f_path.dentry,
14567 + .flags = AuCpup_DTIME
14570 + FiMustWriteLock(file);
14573 + finfo = au_fi(file);
14574 + sb = cpg.dentry->d_sb;
14575 + inode = d_inode(cpg.dentry);
14576 + cpg.bdst = au_ibtop(inode);
14577 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14580 + parent = dget_parent(cpg.dentry);
14581 + if (au_test_ro(sb, cpg.bdst, inode)) {
14582 + di_read_lock_parent(parent, !AuLock_IR);
14583 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14585 + di_read_unlock(parent, !AuLock_IR);
14586 + if (unlikely(err < 0))
14591 + di_read_lock_parent(parent, AuLock_IR);
14592 + hi_wh = au_hi_wh(inode, cpg.bdst);
14593 + if (!S_ISDIR(inode->i_mode)
14594 + && au_opt_test(au_mntflags(sb), PLINK)
14595 + && au_plink_test(inode)
14596 + && !d_unhashed(cpg.dentry)
14597 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14598 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14599 + if (unlikely(err))
14602 + /* always superio. */
14603 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14604 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14606 + err = au_sio_cpup_simple(&cpg);
14609 + } else if (hi_wh) {
14610 + /* already copied-up after unlink */
14611 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14612 + *need_reopen = 0;
14616 + di_read_unlock(parent, AuLock_IR);
14623 +static void au_do_refresh_dir(struct file *file)
14625 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14626 + struct au_hfile *p, tmp, *q;
14627 + struct au_finfo *finfo;
14628 + struct super_block *sb;
14629 + struct au_fidir *fidir;
14631 + FiMustWriteLock(file);
14633 + sb = file->f_path.dentry->d_sb;
14634 + finfo = au_fi(file);
14635 + fidir = finfo->fi_hdir;
14636 + AuDebugOn(!fidir);
14637 + p = fidir->fd_hfile + finfo->fi_btop;
14638 + brid = p->hf_br->br_id;
14639 + bbot = fidir->fd_bbot;
14640 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14644 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14645 + if (new_bindex == bindex)
14647 + if (new_bindex < 0) {
14648 + au_set_h_fptr(file, bindex, NULL);
14652 + /* swap two lower inode, and loop again */
14653 + q = fidir->fd_hfile + new_bindex;
14657 + if (tmp.hf_file) {
14663 + p = fidir->fd_hfile;
14664 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14665 + bbot = au_sbbot(sb);
14666 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14667 + finfo->fi_btop++, p++)
14668 + if (p->hf_file) {
14669 + if (file_inode(p->hf_file))
14671 + au_hfput(p, /*execed*/0);
14674 + bbot = au_br_index(sb, brid);
14675 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14676 + finfo->fi_btop++, p++)
14678 + au_hfput(p, /*execed*/0);
14679 + bbot = au_sbbot(sb);
14682 + p = fidir->fd_hfile + bbot;
14683 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14684 + fidir->fd_bbot--, p--)
14685 + if (p->hf_file) {
14686 + if (file_inode(p->hf_file))
14688 + au_hfput(p, /*execed*/0);
14690 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14694 + * after branch manipulating, refresh the file.
14696 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14698 + int err, need_reopen, nbr;
14699 + aufs_bindex_t bbot, bindex;
14700 + struct dentry *dentry;
14701 + struct super_block *sb;
14702 + struct au_finfo *finfo;
14703 + struct au_hfile *hfile;
14705 + dentry = file->f_path.dentry;
14706 + sb = dentry->d_sb;
14707 + nbr = au_sbbot(sb) + 1;
14708 + finfo = au_fi(file);
14709 + if (!finfo->fi_hdir) {
14710 + hfile = &finfo->fi_htop;
14711 + AuDebugOn(!hfile->hf_file);
14712 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14713 + AuDebugOn(bindex < 0);
14714 + if (bindex != finfo->fi_btop)
14715 + au_set_fbtop(file, bindex);
14717 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14718 + if (unlikely(err))
14720 + au_do_refresh_dir(file);
14725 + if (!au_test_mmapped(file))
14726 + err = au_file_refresh_by_inode(file, &need_reopen);
14727 + if (finfo->fi_hdir)
14728 + /* harmless if err */
14729 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14730 + if (!err && need_reopen && !d_unlinked(dentry))
14731 + err = reopen(file);
14733 + au_update_figen(file);
14734 + goto out; /* success */
14737 + /* error, close all lower files */
14738 + if (finfo->fi_hdir) {
14739 + bbot = au_fbbot_dir(file);
14740 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14741 + au_set_h_fptr(file, bindex, NULL);
14748 +/* common function to regular file and dir */
14749 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14750 + int wlock, unsigned int fi_lsc)
14753 + unsigned int sigen, figen;
14754 + aufs_bindex_t btop;
14755 + unsigned char pseudo_link;
14756 + struct dentry *dentry;
14757 + struct inode *inode;
14760 + dentry = file->f_path.dentry;
14761 + inode = d_inode(dentry);
14762 + sigen = au_sigen(dentry->d_sb);
14763 + fi_write_lock_nested(file, fi_lsc);
14764 + figen = au_figen(file);
14766 + di_write_lock_child(dentry);
14768 + di_write_lock_child2(dentry);
14769 + btop = au_dbtop(dentry);
14770 + pseudo_link = (btop != au_ibtop(inode));
14771 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14773 + di_downgrade_lock(dentry, AuLock_IR);
14774 + fi_downgrade_lock(file);
14776 + goto out; /* success */
14779 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14780 + if (au_digen_test(dentry, sigen)) {
14781 + err = au_reval_dpath(dentry, sigen);
14782 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14786 + err = refresh_file(file, reopen);
14789 + di_downgrade_lock(dentry, AuLock_IR);
14790 + fi_downgrade_lock(file);
14793 + di_write_unlock(dentry);
14794 + fi_write_unlock(file);
14801 +/* ---------------------------------------------------------------------- */
14803 +/* cf. aufs_nopage() */
14804 +/* for madvise(2) */
14805 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14807 + unlock_page(page);
14811 +/* it will never be called, but necessary to support O_DIRECT */
14812 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14813 +{ BUG(); return 0; }
14815 +/* they will never be called. */
14816 +#ifdef CONFIG_AUFS_DEBUG
14817 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14818 + loff_t pos, unsigned len, unsigned flags,
14819 + struct page **pagep, void **fsdata)
14820 +{ AuUnsupport(); return 0; }
14821 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14822 + loff_t pos, unsigned len, unsigned copied,
14823 + struct page *page, void *fsdata)
14824 +{ AuUnsupport(); return 0; }
14825 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14826 +{ AuUnsupport(); return 0; }
14828 +static int aufs_set_page_dirty(struct page *page)
14829 +{ AuUnsupport(); return 0; }
14830 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14831 + unsigned int length)
14832 +{ AuUnsupport(); }
14833 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14834 +{ AuUnsupport(); return 0; }
14835 +#if 0 /* called by memory compaction regardless file */
14836 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14837 + struct page *page, enum migrate_mode mode)
14838 +{ AuUnsupport(); return 0; }
14840 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14841 +{ AuUnsupport(); return true; }
14842 +static void aufs_putback_page(struct page *page)
14843 +{ AuUnsupport(); }
14844 +static int aufs_launder_page(struct page *page)
14845 +{ AuUnsupport(); return 0; }
14846 +static int aufs_is_partially_uptodate(struct page *page,
14847 + unsigned long from,
14848 + unsigned long count)
14849 +{ AuUnsupport(); return 0; }
14850 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14852 +{ AuUnsupport(); }
14853 +static int aufs_error_remove_page(struct address_space *mapping,
14854 + struct page *page)
14855 +{ AuUnsupport(); return 0; }
14856 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14858 +{ AuUnsupport(); return 0; }
14859 +static void aufs_swap_deactivate(struct file *file)
14860 +{ AuUnsupport(); }
14861 +#endif /* CONFIG_AUFS_DEBUG */
14863 +const struct address_space_operations aufs_aop = {
14864 + .readpage = aufs_readpage,
14865 + .direct_IO = aufs_direct_IO,
14866 +#ifdef CONFIG_AUFS_DEBUG
14867 + .writepage = aufs_writepage,
14868 + /* no writepages, because of writepage */
14869 + .set_page_dirty = aufs_set_page_dirty,
14870 + /* no readpages, because of readpage */
14871 + .write_begin = aufs_write_begin,
14872 + .write_end = aufs_write_end,
14873 + /* no bmap, no block device */
14874 + .invalidatepage = aufs_invalidatepage,
14875 + .releasepage = aufs_releasepage,
14876 + /* is fallback_migrate_page ok? */
14877 + /* .migratepage = aufs_migratepage, */
14878 + .isolate_page = aufs_isolate_page,
14879 + .putback_page = aufs_putback_page,
14880 + .launder_page = aufs_launder_page,
14881 + .is_partially_uptodate = aufs_is_partially_uptodate,
14882 + .is_dirty_writeback = aufs_is_dirty_writeback,
14883 + .error_remove_page = aufs_error_remove_page,
14884 + .swap_activate = aufs_swap_activate,
14885 + .swap_deactivate = aufs_swap_deactivate
14886 +#endif /* CONFIG_AUFS_DEBUG */
14888 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14889 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14890 +++ linux/fs/aufs/file.h 2022-03-21 14:49:05.723299677 +0100
14892 +/* SPDX-License-Identifier: GPL-2.0 */
14894 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14896 + * This program, aufs is free software; you can redistribute it and/or modify
14897 + * it under the terms of the GNU General Public License as published by
14898 + * the Free Software Foundation; either version 2 of the License, or
14899 + * (at your option) any later version.
14901 + * This program is distributed in the hope that it will be useful,
14902 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14904 + * GNU General Public License for more details.
14906 + * You should have received a copy of the GNU General Public License
14907 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14911 + * file operations
14914 +#ifndef __AUFS_FILE_H__
14915 +#define __AUFS_FILE_H__
14919 +#include <linux/file.h>
14920 +#include <linux/fs.h>
14921 +#include <linux/mm_types.h>
14922 +#include <linux/poll.h>
14923 +#include "rwsem.h"
14927 + struct file *hf_file;
14928 + struct au_branch *hf_br;
14933 + aufs_bindex_t fd_bbot;
14934 + aufs_bindex_t fd_nent;
14935 + struct au_vdir *fd_vdir_cache;
14936 + struct au_hfile fd_hfile[];
14939 +static inline int au_fidir_sz(int nent)
14941 + AuDebugOn(nent < 0);
14942 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14946 + atomic_t fi_generation;
14948 + struct au_rwsem fi_rwsem;
14949 + aufs_bindex_t fi_btop;
14951 + /* do not union them */
14952 + struct { /* for non-dir */
14953 + struct au_hfile fi_htop;
14954 + atomic_t fi_mmapped;
14956 + struct au_fidir *fi_hdir; /* for dir only */
14958 + struct hlist_bl_node fi_hlist;
14959 + struct file *fi_file; /* very ugly */
14960 + struct rcu_head rcu;
14961 +} ____cacheline_aligned_in_smp;
14963 +/* ---------------------------------------------------------------------- */
14966 +extern const struct address_space_operations aufs_aop;
14967 +unsigned int au_file_roflags(unsigned int flags);
14968 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14969 + struct file *file, int force_wr);
14970 +struct au_do_open_args {
14972 + int (*open)(struct file *file, int flags,
14973 + struct file *h_file);
14974 + struct au_fidir *fidir;
14975 + struct file *h_file;
14977 +int au_do_open(struct file *file, struct au_do_open_args *args);
14978 +int au_reopen_nondir(struct file *file);
14980 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14981 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14982 + int wlock, unsigned int fi_lsc);
14983 +int au_do_flush(struct file *file, fl_owner_t id,
14984 + int (*flush)(struct file *file, fl_owner_t id));
14987 +#ifdef CONFIG_AUFS_POLL
14988 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
14991 +#ifdef CONFIG_AUFS_BR_HFSPLUS
14993 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14995 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14996 + struct file *h_file);
14998 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
14999 + aufs_bindex_t bindex, int force_wr)
15000 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15001 + struct file *h_file);
15005 +extern const struct file_operations aufs_file_fop;
15006 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15007 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15008 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15011 +void au_hfput(struct au_hfile *hf, int execed);
15012 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15013 + struct file *h_file);
15015 +void au_update_figen(struct file *file);
15016 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15017 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15019 +void au_fi_init_once(void *_fi);
15020 +void au_finfo_fin(struct file *file);
15021 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15024 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15025 +#ifdef CONFIG_COMPAT
15026 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15027 + unsigned long arg);
15028 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15029 + unsigned long arg);
15032 +/* ---------------------------------------------------------------------- */
15034 +static inline struct au_finfo *au_fi(struct file *file)
15036 + return file->private_data;
15039 +/* ---------------------------------------------------------------------- */
15041 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15042 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15043 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15044 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15046 +#define fi_read_trylock_nested(f) \
15047 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15048 +#define fi_write_trylock_nested(f) \
15049 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15052 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15053 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15054 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15056 +/* lock subclass for finfo */
15062 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15064 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15067 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15069 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15073 + * fi_read_lock_1, fi_write_lock_1,
15074 + * fi_read_lock_2, fi_write_lock_2
15076 +#define AuReadLockFunc(name) \
15077 +static inline void fi_read_lock_##name(struct file *f) \
15078 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15080 +#define AuWriteLockFunc(name) \
15081 +static inline void fi_write_lock_##name(struct file *f) \
15082 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15084 +#define AuRWLockFuncs(name) \
15085 + AuReadLockFunc(name) \
15086 + AuWriteLockFunc(name)
15091 +#undef AuReadLockFunc
15092 +#undef AuWriteLockFunc
15093 +#undef AuRWLockFuncs
15095 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15096 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15097 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15099 +/* ---------------------------------------------------------------------- */
15101 +/* todo: hard/soft set? */
15102 +static inline aufs_bindex_t au_fbtop(struct file *file)
15104 + FiMustAnyLock(file);
15105 + return au_fi(file)->fi_btop;
15108 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15110 + FiMustAnyLock(file);
15111 + AuDebugOn(!au_fi(file)->fi_hdir);
15112 + return au_fi(file)->fi_hdir->fd_bbot;
15115 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15117 + FiMustAnyLock(file);
15118 + AuDebugOn(!au_fi(file)->fi_hdir);
15119 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15122 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15124 + FiMustWriteLock(file);
15125 + au_fi(file)->fi_btop = bindex;
15128 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15130 + FiMustWriteLock(file);
15131 + AuDebugOn(!au_fi(file)->fi_hdir);
15132 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15135 +static inline void au_set_fvdir_cache(struct file *file,
15136 + struct au_vdir *vdir_cache)
15138 + FiMustWriteLock(file);
15139 + AuDebugOn(!au_fi(file)->fi_hdir);
15140 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15143 +static inline struct file *au_hf_top(struct file *file)
15145 + FiMustAnyLock(file);
15146 + AuDebugOn(au_fi(file)->fi_hdir);
15147 + return au_fi(file)->fi_htop.hf_file;
15150 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15152 + FiMustAnyLock(file);
15153 + AuDebugOn(!au_fi(file)->fi_hdir);
15154 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15157 +/* todo: memory barrier? */
15158 +static inline unsigned int au_figen(struct file *f)
15160 + return atomic_read(&au_fi(f)->fi_generation);
15163 +static inline void au_set_mmapped(struct file *f)
15165 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15167 + pr_warn("fi_mmapped wrapped around\n");
15168 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15172 +static inline void au_unset_mmapped(struct file *f)
15174 + atomic_dec(&au_fi(f)->fi_mmapped);
15177 +static inline int au_test_mmapped(struct file *f)
15179 + return atomic_read(&au_fi(f)->fi_mmapped);
15182 +/* customize vma->vm_file */
15184 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15185 + struct file *file)
15189 + f = vma->vm_file;
15191 + vma->vm_file = file;
15196 +#define AuDbgVmRegion(file, vma) do {} while (0)
15198 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15199 + struct file *file)
15201 + au_do_vm_file_reset(vma, file);
15204 +#define AuDbgVmRegion(file, vma) \
15205 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15207 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15208 + struct file *file)
15212 + au_do_vm_file_reset(vma, file);
15213 + f = vma->vm_region->vm_file;
15215 + vma->vm_region->vm_file = file;
15218 +#endif /* CONFIG_MMU */
15220 +/* handle vma->vm_prfile */
15221 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15222 + struct file *file)
15225 + vma->vm_prfile = file;
15226 +#ifndef CONFIG_MMU
15228 + vma->vm_region->vm_prfile = file;
15232 +#endif /* __KERNEL__ */
15233 +#endif /* __AUFS_FILE_H__ */
15234 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15235 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15236 +++ linux/fs/aufs/finfo.c 2022-03-21 14:49:05.723299677 +0100
15238 +// SPDX-License-Identifier: GPL-2.0
15240 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15242 + * This program, aufs is free software; you can redistribute it and/or modify
15243 + * it under the terms of the GNU General Public License as published by
15244 + * the Free Software Foundation; either version 2 of the License, or
15245 + * (at your option) any later version.
15247 + * This program is distributed in the hope that it will be useful,
15248 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15249 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15250 + * GNU General Public License for more details.
15252 + * You should have received a copy of the GNU General Public License
15253 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15257 + * file private data
15262 +void au_hfput(struct au_hfile *hf, int execed)
15265 + allow_write_access(hf->hf_file);
15266 + fput(hf->hf_file);
15267 + hf->hf_file = NULL;
15268 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15269 + hf->hf_br = NULL;
15272 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15274 + struct au_finfo *finfo = au_fi(file);
15275 + struct au_hfile *hf;
15276 + struct au_fidir *fidir;
15278 + fidir = finfo->fi_hdir;
15280 + AuDebugOn(finfo->fi_btop != bindex);
15281 + hf = &finfo->fi_htop;
15283 + hf = fidir->fd_hfile + bindex;
15285 + if (hf && hf->hf_file)
15286 + au_hfput(hf, vfsub_file_execed(file));
15288 + FiMustWriteLock(file);
15289 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15290 + hf->hf_file = val;
15291 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15295 +void au_update_figen(struct file *file)
15297 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15298 + /* smp_mb(); */ /* atomic_set */
15301 +/* ---------------------------------------------------------------------- */
15303 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15305 + struct au_fidir *fidir;
15308 + nbr = au_sbbot(sb) + 1;
15310 + nbr = 2; /* initial allocate for 2 branches */
15311 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15313 + fidir->fd_bbot = -1;
15314 + fidir->fd_nent = nbr;
15320 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15323 + struct au_fidir *fidir, *p;
15325 + AuRwMustWriteLock(&finfo->fi_rwsem);
15326 + fidir = finfo->fi_hdir;
15327 + AuDebugOn(!fidir);
15330 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15331 + GFP_NOFS, may_shrink);
15333 + p->fd_nent = nbr;
15334 + finfo->fi_hdir = p;
15341 +/* ---------------------------------------------------------------------- */
15343 +void au_finfo_fin(struct file *file)
15345 + struct au_finfo *finfo;
15347 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15349 + finfo = au_fi(file);
15350 + AuDebugOn(finfo->fi_hdir);
15351 + AuRwDestroy(&finfo->fi_rwsem);
15352 + au_cache_free_finfo(finfo);
15355 +void au_fi_init_once(void *_finfo)
15357 + struct au_finfo *finfo = _finfo;
15359 + au_rw_init(&finfo->fi_rwsem);
15362 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15365 + struct au_finfo *finfo;
15366 + struct dentry *dentry;
15369 + dentry = file->f_path.dentry;
15370 + finfo = au_cache_alloc_finfo();
15371 + if (unlikely(!finfo))
15375 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15376 + au_rw_write_lock(&finfo->fi_rwsem);
15377 + finfo->fi_btop = -1;
15378 + finfo->fi_hdir = fidir;
15379 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15380 + /* smp_mb(); */ /* atomic_set */
15382 + file->private_data = finfo;
15387 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15388 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15389 +++ linux/fs/aufs/f_op.c 2022-03-21 14:49:05.723299677 +0100
15391 +// SPDX-License-Identifier: GPL-2.0
15393 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15395 + * This program, aufs is free software; you can redistribute it and/or modify
15396 + * it under the terms of the GNU General Public License as published by
15397 + * the Free Software Foundation; either version 2 of the License, or
15398 + * (at your option) any later version.
15400 + * This program is distributed in the hope that it will be useful,
15401 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15402 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15403 + * GNU General Public License for more details.
15405 + * You should have received a copy of the GNU General Public License
15406 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15410 + * file and vm operations
15413 +#include <linux/aio.h>
15414 +#include <linux/fs_stack.h>
15415 +#include <linux/mman.h>
15416 +#include <linux/security.h>
15419 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15422 + aufs_bindex_t bindex;
15423 + struct dentry *dentry, *h_dentry;
15424 + struct au_finfo *finfo;
15425 + struct inode *h_inode;
15427 + FiMustWriteLock(file);
15430 + dentry = file->f_path.dentry;
15431 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15432 + finfo = au_fi(file);
15433 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15434 + atomic_set(&finfo->fi_mmapped, 0);
15435 + bindex = au_dbtop(dentry);
15437 + h_dentry = au_h_dptr(dentry, bindex);
15438 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15439 + if (unlikely(err))
15441 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15442 + if (IS_ERR(h_file)) {
15443 + err = PTR_ERR(h_file);
15447 + h_dentry = h_file->f_path.dentry;
15448 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15449 + if (unlikely(err))
15451 + /* br ref is already inc-ed */
15454 + if ((flags & __O_TMPFILE)
15455 + && !(flags & O_EXCL)) {
15456 + h_inode = file_inode(h_file);
15457 + spin_lock(&h_inode->i_lock);
15458 + h_inode->i_state |= I_LINKABLE;
15459 + spin_unlock(&h_inode->i_lock);
15461 + au_set_fbtop(file, bindex);
15462 + au_set_h_fptr(file, bindex, h_file);
15463 + au_update_figen(file);
15464 + /* todo: necessary? */
15465 + /* file->f_ra = h_file->f_ra; */
15471 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15472 + struct file *file)
15475 + struct super_block *sb;
15476 + struct au_do_open_args args = {
15477 + .open = au_do_open_nondir
15480 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15481 + file, vfsub_file_flags(file), file->f_mode);
15483 + sb = file->f_path.dentry->d_sb;
15484 + si_read_lock(sb, AuLock_FLUSH);
15485 + err = au_do_open(file, &args);
15486 + si_read_unlock(sb);
15490 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15492 + struct au_finfo *finfo;
15493 + aufs_bindex_t bindex;
15495 + finfo = au_fi(file);
15496 + au_hbl_del(&finfo->fi_hlist,
15497 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15498 + bindex = finfo->fi_btop;
15500 + au_set_h_fptr(file, bindex, NULL);
15502 + au_finfo_fin(file);
15506 +/* ---------------------------------------------------------------------- */
15508 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15511 + struct file *h_file;
15514 + h_file = au_hf_top(file);
15516 + err = vfsub_flush(h_file, id);
15520 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15522 + return au_do_flush(file, id, au_do_flush_nondir);
15525 +/* ---------------------------------------------------------------------- */
15527 + * read and write functions acquire [fdi]_rwsem once, but release before
15528 + * mmap_sem. This is because to stop a race condition between mmap(2).
15529 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15530 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15531 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15534 +/* Callers should call au_read_post() or fput() in the end */
15535 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15537 + struct file *h_file;
15540 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15542 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15543 + h_file = au_hf_top(file);
15544 + get_file(h_file);
15546 + fi_read_unlock(file);
15548 + h_file = ERR_PTR(err);
15553 +static void au_read_post(struct inode *inode, struct file *h_file)
15555 + /* update without lock, I don't think it a problem */
15556 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15560 +struct au_write_pre {
15562 + unsigned int lsc;
15566 + aufs_bindex_t btop;
15570 + * return with iinfo is write-locked
15571 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15574 +static struct file *au_write_pre(struct file *file, int do_ready,
15575 + struct au_write_pre *wpre)
15577 + struct file *h_file;
15578 + struct dentry *dentry;
15580 + unsigned int lsc;
15581 + struct au_pin pin;
15586 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15587 + h_file = ERR_PTR(err);
15588 + if (unlikely(err))
15591 + dentry = file->f_path.dentry;
15593 + err = au_ready_to_write(file, -1, &pin);
15594 + if (unlikely(err)) {
15595 + h_file = ERR_PTR(err);
15596 + di_write_unlock(dentry);
15601 + di_downgrade_lock(dentry, /*flags*/0);
15603 + wpre->btop = au_fbtop(file);
15604 + h_file = au_hf_top(file);
15605 + get_file(h_file);
15607 + wpre->blks = file_inode(h_file)->i_blocks;
15610 + di_read_unlock(dentry, /*flags*/0);
15613 + fi_write_unlock(file);
15618 +static void au_write_post(struct inode *inode, struct file *h_file,
15619 + struct au_write_pre *wpre, ssize_t written)
15621 + struct inode *h_inode;
15623 + au_cpup_attr_timesizes(inode);
15624 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15625 + h_inode = file_inode(h_file);
15626 + inode->i_mode = h_inode->i_mode;
15627 + ii_write_unlock(inode);
15628 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15630 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15631 + /*force*/h_inode->i_blocks > wpre->blks);
15636 + * todo: very ugly
15637 + * it locks both of i_mutex and si_rwsem for read in safe.
15638 + * if the plink maintenance mode continues forever (that is the problem),
15639 + * may loop forever.
15641 +static void au_mtx_and_read_lock(struct inode *inode)
15644 + struct super_block *sb = inode->i_sb;
15647 + inode_lock(inode);
15648 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15651 + inode_unlock(inode);
15652 + si_read_lock(sb, AuLock_NOPLMW);
15653 + si_read_unlock(sb);
15657 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15658 + struct iov_iter *iov_iter)
15661 + struct file *file;
15662 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15664 + err = security_file_permission(h_file, rw);
15665 + if (unlikely(err))
15668 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15670 + if (rw == MAY_READ)
15671 + iter = h_file->f_op->read_iter;
15672 + else if (rw == MAY_WRITE)
15673 + iter = h_file->f_op->write_iter;
15675 + file = kio->ki_filp;
15676 + kio->ki_filp = h_file;
15679 + err = iter(kio, iov_iter);
15682 + /* currently there is no such fs */
15684 + kio->ki_filp = file;
15690 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15693 + struct file *file, *h_file;
15694 + struct inode *inode;
15695 + struct super_block *sb;
15697 + file = kio->ki_filp;
15698 + inode = file_inode(file);
15699 + sb = inode->i_sb;
15700 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15702 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15703 + err = PTR_ERR(h_file);
15704 + if (IS_ERR(h_file))
15707 + if (au_test_loopback_kthread()) {
15708 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15709 + if (file->f_mapping != h_file->f_mapping) {
15710 + file->f_mapping = h_file->f_mapping;
15711 + smp_mb(); /* unnecessary? */
15714 + fi_read_unlock(file);
15716 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15717 + /* todo: necessary? */
15718 + /* file->f_ra = h_file->f_ra; */
15719 + au_read_post(inode, h_file);
15722 + si_read_unlock(sb);
15726 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15729 + struct au_write_pre wpre;
15730 + struct inode *inode;
15731 + struct file *file, *h_file;
15733 + file = kio->ki_filp;
15734 + inode = file_inode(file);
15735 + au_mtx_and_read_lock(inode);
15738 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15739 + err = PTR_ERR(h_file);
15740 + if (IS_ERR(h_file))
15743 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15744 + au_write_post(inode, h_file, &wpre, err);
15747 + si_read_unlock(inode->i_sb);
15748 + inode_unlock(inode);
15753 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15754 + * don't have their own .splice_{read,write} implimentations, and they use
15755 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15756 + * simple converters to f_op->iter_read() and ->iter_write().
15757 + * But we keep our own implementations because some non-mainlined FSes may have
15758 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15759 + * away an opportunity to co-work with aufs from them.
15761 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15762 + struct pipe_inode_info *pipe, size_t len,
15763 + unsigned int flags)
15766 + struct file *h_file;
15767 + struct inode *inode;
15768 + struct super_block *sb;
15770 + inode = file_inode(file);
15771 + sb = inode->i_sb;
15772 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15774 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15775 + err = PTR_ERR(h_file);
15776 + if (IS_ERR(h_file))
15779 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15780 + /* todo: necessary? */
15781 + /* file->f_ra = h_file->f_ra; */
15782 + au_read_post(inode, h_file);
15785 + si_read_unlock(sb);
15790 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15791 + size_t len, unsigned int flags)
15794 + struct au_write_pre wpre;
15795 + struct inode *inode;
15796 + struct file *h_file;
15798 + inode = file_inode(file);
15799 + au_mtx_and_read_lock(inode);
15802 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15803 + err = PTR_ERR(h_file);
15804 + if (IS_ERR(h_file))
15807 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15808 + au_write_post(inode, h_file, &wpre, err);
15811 + si_read_unlock(inode->i_sb);
15812 + inode_unlock(inode);
15816 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15820 + struct au_write_pre wpre;
15821 + struct inode *inode;
15822 + struct file *h_file;
15824 + inode = file_inode(file);
15825 + au_mtx_and_read_lock(inode);
15828 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15829 + err = PTR_ERR(h_file);
15830 + if (IS_ERR(h_file))
15834 + err = vfs_fallocate(h_file, mode, offset, len);
15836 + au_write_post(inode, h_file, &wpre, /*written*/1);
15839 + si_read_unlock(inode->i_sb);
15840 + inode_unlock(inode);
15844 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15845 + struct file *dst, loff_t dst_pos,
15846 + size_t len, unsigned int flags)
15849 + struct au_write_pre wpre;
15850 + enum { SRC, DST };
15852 + struct inode *inode;
15853 + struct file *h_file;
15854 + struct super_block *h_sb;
15856 +#define a_src a[SRC]
15857 +#define a_dst a[DST]
15860 + a_src.inode = file_inode(src);
15861 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15863 + a_dst.inode = file_inode(dst);
15864 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15867 + au_mtx_and_read_lock(a_dst.inode);
15869 + * in order to match the order in di_write_lock2_{child,parent}(),
15870 + * use f_path.dentry for this comparison.
15872 + if (src->f_path.dentry < dst->f_path.dentry) {
15873 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15874 + err = PTR_ERR(a_src.h_file);
15875 + if (IS_ERR(a_src.h_file))
15878 + wpre.lsc = AuLsc_FI_2;
15879 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15880 + err = PTR_ERR(a_dst.h_file);
15881 + if (IS_ERR(a_dst.h_file)) {
15882 + au_read_post(a_src.inode, a_src.h_file);
15886 + wpre.lsc = AuLsc_FI_1;
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))
15892 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15893 + err = PTR_ERR(a_src.h_file);
15894 + if (IS_ERR(a_src.h_file)) {
15895 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15902 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15903 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15904 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15910 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15911 + dst_pos, len, flags);
15914 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15915 + fi_read_unlock(src);
15916 + au_read_post(a_src.inode, a_src.h_file);
15918 + si_read_unlock(a_dst.inode->i_sb);
15919 + inode_unlock(a_dst.inode);
15926 +/* ---------------------------------------------------------------------- */
15929 + * The locking order around current->mmap_sem.
15930 + * - in most and regular cases
15931 + * file I/O syscall -- aufs_read() or something
15932 + * -- si_rwsem for read -- mmap_sem
15933 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15935 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15936 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15937 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15938 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15939 + * It means that when aufs acquires si_rwsem for write, the process should never
15940 + * acquire mmap_sem.
15942 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15943 + * problem either since any directory is not able to be mmap-ed.
15944 + * The similar scenario is applied to aufs_readlink() too.
15947 +#if 0 /* stop calling security_file_mmap() */
15948 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15949 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15951 +static unsigned long au_arch_prot_conv(unsigned long flags)
15953 + /* currently ppc64 only */
15954 +#ifdef CONFIG_PPC64
15955 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15956 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15957 + return AuConv_VM_PROT(flags, SAO);
15959 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15964 +static unsigned long au_prot_conv(unsigned long flags)
15966 + return AuConv_VM_PROT(flags, READ)
15967 + | AuConv_VM_PROT(flags, WRITE)
15968 + | AuConv_VM_PROT(flags, EXEC)
15969 + | au_arch_prot_conv(flags);
15972 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15973 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15975 +static unsigned long au_flag_conv(unsigned long flags)
15977 + return AuConv_VM_MAP(flags, GROWSDOWN)
15978 + | AuConv_VM_MAP(flags, DENYWRITE)
15979 + | AuConv_VM_MAP(flags, LOCKED);
15983 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
15986 + const unsigned char wlock
15987 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
15988 + struct super_block *sb;
15989 + struct file *h_file;
15990 + struct inode *inode;
15992 + AuDbgVmRegion(file, vma);
15994 + inode = file_inode(file);
15995 + sb = inode->i_sb;
15997 + si_read_lock(sb, AuLock_NOPLMW);
15999 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16001 + err = PTR_ERR(h_file);
16002 + if (IS_ERR(h_file))
16006 + au_set_mmapped(file);
16007 + au_vm_file_reset(vma, h_file);
16009 + * we cannot call security_mmap_file() here since it may acquire
16010 + * mmap_sem or i_mutex.
16012 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16013 + * au_flag_conv(vma->vm_flags));
16016 + err = call_mmap(h_file, vma);
16018 + au_vm_prfile_set(vma, file);
16019 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16020 + goto out_fput; /* success */
16022 + au_unset_mmapped(file);
16023 + au_vm_file_reset(vma, file);
16027 + ii_write_unlock(inode);
16032 + si_read_unlock(sb);
16038 +/* ---------------------------------------------------------------------- */
16040 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16044 + struct au_write_pre wpre;
16045 + struct inode *inode;
16046 + struct file *h_file;
16048 + err = 0; /* -EBADF; */ /* posix? */
16049 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16052 + inode = file_inode(file);
16053 + au_mtx_and_read_lock(inode);
16056 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16057 + err = PTR_ERR(h_file);
16058 + if (IS_ERR(h_file))
16061 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16062 + au_write_post(inode, h_file, &wpre, /*written*/0);
16065 + si_read_unlock(inode->i_sb);
16066 + inode_unlock(inode);
16071 +static int aufs_fasync(int fd, struct file *file, int flag)
16074 + struct file *h_file;
16075 + struct super_block *sb;
16077 + sb = file->f_path.dentry->d_sb;
16078 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16080 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16081 + err = PTR_ERR(h_file);
16082 + if (IS_ERR(h_file))
16085 + if (h_file->f_op->fasync)
16086 + err = h_file->f_op->fasync(fd, h_file, flag);
16087 + fput(h_file); /* instead of au_read_post() */
16090 + si_read_unlock(sb);
16094 +static int aufs_setfl(struct file *file, unsigned long arg)
16097 + struct file *h_file;
16098 + struct super_block *sb;
16100 + sb = file->f_path.dentry->d_sb;
16101 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16103 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16104 + err = PTR_ERR(h_file);
16105 + if (IS_ERR(h_file))
16108 + /* stop calling h_file->fasync */
16109 + arg |= vfsub_file_flags(file) & FASYNC;
16110 + err = setfl(/*unused fd*/-1, h_file, arg);
16111 + fput(h_file); /* instead of au_read_post() */
16114 + si_read_unlock(sb);
16118 +/* ---------------------------------------------------------------------- */
16120 +/* no one supports this operation, currently */
16121 +#if 0 /* reserved for future use */
16122 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16123 + size_t len, loff_t *pos, int more)
16128 +/* ---------------------------------------------------------------------- */
16130 +const struct file_operations aufs_file_fop = {
16131 + .owner = THIS_MODULE,
16133 + .llseek = default_llseek,
16135 + .read_iter = aufs_read_iter,
16136 + .write_iter = aufs_write_iter,
16138 +#ifdef CONFIG_AUFS_POLL
16139 + .poll = aufs_poll,
16141 + .unlocked_ioctl = aufs_ioctl_nondir,
16142 +#ifdef CONFIG_COMPAT
16143 + .compat_ioctl = aufs_compat_ioctl_nondir,
16145 + .mmap = aufs_mmap,
16146 + .open = aufs_open_nondir,
16147 + .flush = aufs_flush_nondir,
16148 + .release = aufs_release_nondir,
16149 + .fsync = aufs_fsync_nondir,
16150 + .fasync = aufs_fasync,
16151 + /* .sendpage = aufs_sendpage, */
16152 + .setfl = aufs_setfl,
16153 + .splice_write = aufs_splice_write,
16154 + .splice_read = aufs_splice_read,
16155 +#if 0 /* reserved for future use */
16156 + .aio_splice_write = aufs_aio_splice_write,
16157 + .aio_splice_read = aufs_aio_splice_read,
16159 + .fallocate = aufs_fallocate,
16160 + .copy_file_range = aufs_copy_file_range
16162 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16163 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16164 +++ linux/fs/aufs/fsctx.c 2022-03-21 14:49:05.723299677 +0100
16166 +// SPDX-License-Identifier: GPL-2.0
16168 + * Copyright (C) 2022 Junjiro R. Okajima
16170 + * This program, aufs is free software; you can redistribute it and/or modify
16171 + * it under the terms of the GNU General Public License as published by
16172 + * the Free Software Foundation; either version 2 of the License, or
16173 + * (at your option) any later version.
16175 + * This program is distributed in the hope that it will be useful,
16176 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16177 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16178 + * GNU General Public License for more details.
16180 + * You should have received a copy of the GNU General Public License
16181 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16185 + * fs context, aka new mount api
16188 +#include <linux/fs_context.h>
16191 +struct au_fsctx_opts {
16192 + aufs_bindex_t bindex;
16193 + unsigned char skipped;
16194 + struct au_opt *opt, *opt_tail;
16195 + struct super_block *sb;
16196 + struct au_sbinfo *sbinfo;
16197 + struct au_opts opts;
16200 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16201 +static int cvt_err(int err)
16215 +static int au_fsctx_reconfigure(struct fs_context *fc)
16218 + unsigned int mntflags;
16219 + struct dentry *root;
16220 + struct super_block *sb;
16221 + struct inode *inode;
16222 + struct au_fsctx_opts *a = fc->fs_private;
16224 + AuDbg("fc %p\n", fc);
16228 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16230 + di_write_lock_child(root);
16231 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16232 + aufs_write_unlock(root);
16235 + inode = d_inode(root);
16236 + inode_lock(inode);
16237 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16238 + if (unlikely(err))
16240 + di_write_lock_child(root);
16242 + /* au_opts_remount() may return an error */
16243 + err = au_opts_remount(sb, &a->opts);
16245 + if (au_ftest_opts(a->opts.flags, REFRESH))
16246 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16249 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16250 + mntflags = au_mntflags(sb);
16251 + do_dx = !!au_opt_test(mntflags, DIO);
16252 + au_dy_arefresh(do_dx);
16255 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16256 + aufs_write_unlock(root);
16259 + inode_unlock(inode);
16260 + err = cvt_err(err);
16266 +/* ---------------------------------------------------------------------- */
16268 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16271 + struct au_fsctx_opts *a = fc->fs_private;
16272 + struct au_sbinfo *sbinfo = a->sbinfo;
16273 + struct dentry *root;
16274 + struct inode *inode;
16276 + sbinfo->si_sb = sb;
16277 + sb->s_fs_info = sbinfo;
16278 + kobject_get(&sbinfo->si_kobj);
16280 + __si_write_lock(sb);
16282 + au_sbilist_add(sb);
16284 + /* all timestamps always follow the ones on the branch */
16285 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16286 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16287 + sb->s_op = &aufs_sop;
16288 + sb->s_d_op = &aufs_dop;
16289 + sb->s_magic = AUFS_SUPER_MAGIC;
16290 + sb->s_maxbytes = 0;
16291 + sb->s_stack_depth = 1;
16292 + au_export_init(sb);
16293 + au_xattr_init(sb);
16295 + err = au_alloc_root(sb);
16296 + if (unlikely(err)) {
16297 + si_write_unlock(sb);
16300 + root = sb->s_root;
16301 + inode = d_inode(root);
16302 + ii_write_lock_parent(inode);
16303 + aufs_write_unlock(root);
16305 + /* lock vfs_inode first, then aufs. */
16306 + inode_lock(inode);
16307 + aufs_write_lock(root);
16308 + err = au_opts_mount(sb, &a->opts);
16310 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16311 + sb->s_d_op = &aufs_dop_noreval;
16312 + /* infofc(fc, "%ps", sb->s_d_op); */
16313 + pr_info("%ps\n", sb->s_d_op);
16314 + au_refresh_dop(root, /*force_reval*/0);
16315 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16316 + au_refresh_iop(inode, /*force_getattr*/0);
16318 + aufs_write_unlock(root);
16319 + inode_unlock(inode);
16321 + goto out; /* success */
16324 + sb->s_root = NULL;
16327 + if (unlikely(err))
16328 + kobject_put(&sbinfo->si_kobj);
16330 + err = cvt_err(err);
16335 +static int au_fsctx_get_tree(struct fs_context *fc)
16339 + AuDbg("fc %p\n", fc);
16340 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16346 +/* ---------------------------------------------------------------------- */
16348 +static void au_fsctx_dump(struct au_opts *opts)
16350 +#ifdef CONFIG_AUFS_DEBUG
16351 + /* reduce stack space */
16353 + struct au_opt_add *add;
16354 + struct au_opt_del *del;
16355 + struct au_opt_mod *mod;
16356 + struct au_opt_xino *xino;
16357 + struct au_opt_xino_itrunc *xino_itrunc;
16358 + struct au_opt_wbr_create *create;
16360 + struct au_opt *opt;
16363 + while (opt->type != Opt_tail) {
16364 + switch (opt->type) {
16366 + u.add = &opt->add;
16367 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16368 + u.add->bindex, u.add->pathname, u.add->perm,
16369 + u.add->path.dentry);
16374 + u.del = &opt->del;
16375 + AuDbg("del {%s, %p}\n",
16376 + u.del->pathname, u.del->h_path.dentry);
16381 + u.mod = &opt->mod;
16382 + AuDbg("mod {%s, 0x%x, %p}\n",
16383 + u.mod->path, u.mod->perm, u.mod->h_root);
16386 + u.add = &opt->add;
16387 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16388 + u.add->bindex, u.add->pathname, u.add->perm,
16389 + u.add->path.dentry);
16391 + case Opt_prepend:
16392 + u.add = &opt->add;
16393 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16394 + u.add->bindex, u.add->pathname, u.add->perm,
16395 + u.add->path.dentry);
16399 + AuDbg("dirwh %d\n", opt->dirwh);
16401 + case Opt_rdcache:
16402 + AuDbg("rdcache %d\n", opt->rdcache);
16405 + AuDbg("rdblk %d\n", opt->rdblk);
16408 + AuDbg("rdhash %u\n", opt->rdhash);
16412 + u.xino = &opt->xino;
16413 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16416 +#define au_fsctx_TF(name) \
16417 + case Opt_##name: \
16421 + AuLabel(no##name); \
16424 + /* simple true/false flag */
16425 + au_fsctx_TF(trunc_xino);
16426 + au_fsctx_TF(trunc_xib);
16427 + au_fsctx_TF(dirperm1);
16428 + au_fsctx_TF(plink);
16429 + au_fsctx_TF(shwh);
16430 + au_fsctx_TF(dio);
16431 + au_fsctx_TF(warn_perm);
16432 + au_fsctx_TF(verbose);
16433 + au_fsctx_TF(sum);
16434 + au_fsctx_TF(dirren);
16435 + au_fsctx_TF(acl);
16436 +#undef au_fsctx_TF
16438 + case Opt_trunc_xino_path:
16440 + case Opt_itrunc_xino:
16441 + u.xino_itrunc = &opt->xino_itrunc;
16442 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16448 + case Opt_list_plink:
16449 + AuLabel(list_plink);
16452 + AuDbg("udba %d, %s\n",
16453 + opt->udba, au_optstr_udba(opt->udba));
16455 + case Opt_diropq_a:
16456 + AuLabel(diropq_a);
16458 + case Opt_diropq_w:
16459 + AuLabel(diropq_w);
16464 + case Opt_wbr_create:
16465 + u.create = &opt->wbr_create;
16466 + AuDbg("create %d, %s\n", u.create->wbr_create,
16467 + au_optstr_wbr_create(u.create->wbr_create));
16468 + switch (u.create->wbr_create) {
16469 + case AuWbrCreate_MFSV:
16471 + case AuWbrCreate_PMFSV:
16472 + AuDbg("%d sec\n", u.create->mfs_second);
16474 + case AuWbrCreate_MFSRR:
16476 + case AuWbrCreate_TDMFS:
16477 + AuDbg("%llu watermark\n",
16478 + u.create->mfsrr_watermark);
16480 + case AuWbrCreate_MFSRRV:
16482 + case AuWbrCreate_TDMFSV:
16484 + case AuWbrCreate_PMFSRRV:
16485 + AuDbg("%llu watermark, %d sec\n",
16486 + u.create->mfsrr_watermark,
16487 + u.create->mfs_second);
16491 + case Opt_wbr_copyup:
16492 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16493 + au_optstr_wbr_copyup(opt->wbr_copyup));
16495 + case Opt_fhsm_sec:
16496 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16500 + AuDbg("type %d\n", opt->type);
16508 +/* ---------------------------------------------------------------------- */
16511 + * For conditionally compiled mount options.
16512 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16514 +#define au_ignore_flag(name, action) \
16515 + fsparam_flag(name, action), \
16516 + fsparam_flag("no" name, Opt_ignore_silent)
16518 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16519 + fsparam_string("br", Opt_br),
16521 + /* "add=%d:%s" or "ins=%d:%s" */
16522 + fsparam_string("add", Opt_add),
16523 + fsparam_string("ins", Opt_add),
16524 + fsparam_path("append", Opt_append),
16525 + fsparam_path("prepend", Opt_prepend),
16527 + fsparam_path("del", Opt_del),
16528 + /* fsparam_s32("idel", Opt_idel), */
16529 + fsparam_path("mod", Opt_mod),
16530 + /* fsparam_string("imod", Opt_imod), */
16532 + fsparam_s32("dirwh", Opt_dirwh),
16534 + fsparam_path("xino", Opt_xino),
16535 + fsparam_flag("noxino", Opt_noxino),
16536 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16537 + /* "trunc_xino_v=%d:%d" */
16538 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16539 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16540 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16541 + /* fsparam_path("zxino", Opt_zxino), */
16542 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16544 +#ifdef CONFIG_PROC_FS
16545 + fsparam_flag_no("plink", Opt_plink),
16547 + au_ignore_flag("plink", Opt_ignore),
16550 +#ifdef CONFIG_AUFS_DEBUG
16551 + fsparam_flag("list_plink", Opt_list_plink),
16554 + fsparam_string("udba", Opt_udba),
16556 + fsparam_flag_no("dio", Opt_dio),
16558 +#ifdef CONFIG_AUFS_DIRREN
16559 + fsparam_flag_no("dirren", Opt_dirren),
16561 + au_ignore_flag("dirren", Opt_ignore),
16564 +#ifdef CONFIG_AUFS_FHSM
16565 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16567 + fsparam_s32("fhsm_sec", Opt_ignore),
16570 + /* always | a | whiteouted | w */
16571 + fsparam_string("diropq", Opt_diropq),
16573 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16575 +#ifdef CONFIG_AUFS_SHWH
16576 + fsparam_flag_no("shwh", Opt_shwh),
16578 + au_ignore_flag("shwh", Opt_err),
16581 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16583 + fsparam_flag_no("verbose", Opt_verbose),
16584 + fsparam_flag("v", Opt_verbose),
16585 + fsparam_flag("quiet", Opt_noverbose),
16586 + fsparam_flag("q", Opt_noverbose),
16587 + /* user-space may handle this */
16588 + fsparam_flag("silent", Opt_noverbose),
16590 + fsparam_flag_no("sum", Opt_sum),
16591 + fsparam_flag("wsum", Opt_wsum),
16593 + fsparam_s32("rdcache", Opt_rdcache),
16594 + /* "def" or s32 */
16595 + fsparam_string("rdblk", Opt_rdblk),
16596 + /* "def" or s32 */
16597 + fsparam_string("rdhash", Opt_rdhash),
16599 + fsparam_string("create", Opt_wbr_create),
16600 + fsparam_string("create_policy", Opt_wbr_create),
16601 + fsparam_string("cpup", Opt_wbr_copyup),
16602 + fsparam_string("copyup", Opt_wbr_copyup),
16603 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16605 + /* generic VFS flag */
16606 +#ifdef CONFIG_FS_POSIX_ACL
16607 + fsparam_flag_no("acl", Opt_acl),
16609 + au_ignore_flag("acl"),
16612 + /* internal use for the scripts */
16613 + fsparam_string("si", Opt_ignore_silent),
16615 + /* obsoleted, keep them temporary */
16616 + fsparam_flag("nodlgt", Opt_ignore_silent),
16617 + fsparam_flag("clean_plink", Opt_ignore),
16618 + fsparam_string("dirs", Opt_br),
16619 + fsparam_u32("debug", Opt_ignore),
16620 + /* "whiteout" or "all" */
16621 + fsparam_string("delete", Opt_ignore),
16622 + fsparam_string("imap", Opt_ignore),
16624 + /* temporary workaround, due to old mount(8)? */
16625 + fsparam_flag("relatime", Opt_ignore_silent),
16630 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16631 + char *brspec, size_t speclen,
16632 + aufs_bindex_t bindex)
16637 + AuDbg("brspec %s\n", brspec);
16641 + speclen = strlen(brspec);
16642 + /* will be freed by au_fsctx_free() */
16643 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16644 + if (unlikely(!p)) {
16645 + errorfc(fc, "failed in %s", brspec);
16648 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16655 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16659 + struct au_fsctx_opts *a = fc->fs_private;
16660 + struct au_opt *opt = a->opt;
16661 + aufs_bindex_t bindex = a->bindex;
16663 + AuDbg("brspec %s\n", brspec);
16666 + while ((p = strsep(&brspec, ":")) && *p) {
16667 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16669 + if (unlikely(err))
16673 + if (unlikely(opt > a->opt_tail)) {
16679 + opt->type = Opt_tail;
16682 + a->bindex = bindex;
16689 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16693 + struct au_fsctx_opts *a = fc->fs_private;
16694 + struct au_opt *opt = a->opt;
16697 + p = strchr(addspec, ':');
16698 + if (unlikely(!p)) {
16699 + errorfc(fc, "bad arg in %s", addspec);
16703 + err = kstrtoint(addspec, 0, &n);
16704 + if (unlikely(err)) {
16705 + errorfc(fc, "bad integer in %s", addspec);
16708 + AuDbg("n %d\n", n);
16709 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16716 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16717 + struct fs_parameter *param)
16722 + /* will be freed by au_fsctx_free() */
16723 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16724 + if (unlikely(!del->pathname))
16726 + AuDbg("del %s\n", del->pathname);
16727 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16728 + if (unlikely(err))
16729 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16736 +#if 0 /* reserved for future use */
16737 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16738 + aufs_bindex_t bindex)
16741 + struct super_block *sb;
16742 + struct dentry *root;
16743 + struct au_fsctx_opts *a = fc->fs_private;
16749 + root = sb->s_root;
16750 + aufs_read_lock(root, AuLock_FLUSH);
16751 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16752 + errorfc(fc, "out of bounds, %d", bindex);
16757 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16758 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16761 + aufs_read_unlock(root, !AuLock_IR);
16767 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16768 + struct fs_parameter *param)
16771 + struct path path;
16775 + /* will be freed by au_fsctx_free() */
16776 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16777 + if (unlikely(!mod->path))
16781 + p = strchr(mod->path, '=');
16782 + if (unlikely(!p)) {
16783 + errorfc(fc, "no permission %s", mod->path);
16788 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16789 + if (unlikely(err)) {
16790 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16794 + mod->perm = au_br_perm_val(p);
16795 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16796 + mod->h_root = dget(path.dentry);
16804 +#if 0 /* reserved for future use */
16805 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16810 + struct super_block *sb;
16811 + struct dentry *root;
16812 + struct au_fsctx_opts *a = fc->fs_private;
16818 + p = strchr(ibrspec, ':');
16819 + if (unlikely(!p)) {
16820 + errorfc(fc, "no index, %s", ibrspec);
16824 + err = kstrtoint(ibrspec, 0, &n);
16825 + if (unlikely(err)) {
16826 + errorfc(fc, "bad integer in %s", ibrspec);
16829 + AuDbg("n %d\n", n);
16831 + root = sb->s_root;
16832 + aufs_read_lock(root, AuLock_FLUSH);
16833 + if (n < 0 || au_sbbot(sb) < n) {
16834 + errorfc(fc, "out of bounds, %d", bindex);
16839 + mod->perm = au_br_perm_val(p);
16840 + AuDbg("mod path %s, perm 0x%x, %s\n",
16841 + mod->path, mod->perm, p);
16842 + mod->h_root = dget(au_h_dptr(root, bindex));
16845 + aufs_read_unlock(root, !AuLock_IR);
16852 +static int au_fsctx_parse_xino(struct fs_context *fc,
16853 + struct au_opt_xino *xino,
16854 + struct fs_parameter *param)
16857 + struct au_fsctx_opts *a = fc->fs_private;
16860 + /* will be freed by au_opts_free() */
16861 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16862 + if (unlikely(!xino->path))
16864 + AuDbg("path %s\n", xino->path);
16866 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16868 + err = PTR_ERR(xino->file);
16869 + if (IS_ERR(xino->file)) {
16870 + xino->file = NULL;
16875 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16877 + errorfc(fc, "%s must be outside", xino->path);
16886 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16887 + struct au_opt_xino_itrunc *xino_itrunc,
16891 + aufs_bindex_t bbot, bindex;
16892 + struct path path;
16893 + struct dentry *root;
16894 + struct au_fsctx_opts *a = fc->fs_private;
16896 + AuDebugOn(!a->sb);
16898 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16899 + if (unlikely(err)) {
16900 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16904 + xino_itrunc->bindex = -1;
16905 + root = a->sb->s_root;
16906 + aufs_read_lock(root, AuLock_FLUSH);
16907 + bbot = au_sbbot(a->sb);
16908 + for (bindex = 0; bindex <= bbot; bindex++) {
16909 + if (au_h_dptr(root, bindex) == path.dentry) {
16910 + xino_itrunc->bindex = bindex;
16914 + aufs_read_unlock(root, !AuLock_IR);
16917 + if (unlikely(xino_itrunc->bindex < 0)) {
16919 + errorfc(fc, "no such branch %s", pathname);
16927 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16928 + struct au_opt_xino_itrunc *xino_itrunc,
16929 + unsigned int bindex)
16932 + aufs_bindex_t bbot;
16933 + struct super_block *sb;
16934 + struct au_fsctx_opts *a = fc->fs_private;
16940 + si_noflush_read_lock(sb);
16941 + bbot = au_sbbot(sb);
16942 + si_read_unlock(sb);
16943 + if (bindex <= bbot)
16944 + xino_itrunc->bindex = bindex;
16947 + errorfc(fc, "out of bounds, %u", bindex);
16954 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16957 + struct fs_parse_result result;
16958 + struct au_fsctx_opts *a = fc->fs_private;
16959 + struct au_opt *opt = a->opt;
16961 + AuDbg("fc %p, param {key %s, string %s}\n",
16962 + fc, param->key, param->string);
16963 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16964 + if (unlikely(err < 0))
16967 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
16968 + token, result.negated, result.uint_64);
16974 + err = au_fsctx_parse_br(fc, param->string);
16977 + err = au_fsctx_parse_add(fc, param->string);
16980 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
16981 + /*dummy bindex*/1);
16983 + case Opt_prepend:
16984 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
16989 + err = au_fsctx_parse_del(fc, &opt->del, param);
16991 +#if 0 /* reserved for future use */
16998 + del->pathname = "(indexed)";
16999 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17004 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17006 +#ifdef IMOD /* reserved for future use */
17013 + u.mod->path = "(indexed)";
17014 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17019 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17021 + case Opt_trunc_xino_path:
17023 + errorfc(fc, "no such branch %s", param->string);
17026 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17030 + case Opt_trunc_xino_v:
17036 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17040 + case Opt_itrunc_xino:
17042 + errorfc(fc, "out of bounds %s", param->string);
17045 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17051 + opt->dirwh = result.int_32;
17054 + case Opt_rdcache:
17055 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17056 + errorfc(fc, "rdcache must be smaller than %d",
17057 + AUFS_RDCACHE_MAX);
17061 + opt->rdcache = result.int_32;
17066 + opt->rdblk = AUFS_RDBLK_DEF;
17067 + if (!strcmp(param->string, "def"))
17070 + err = kstrtoint(param->string, 0, &result.int_32);
17071 + if (unlikely(err)) {
17072 + errorfc(fc, "bad value in %s", param->key);
17076 + if (unlikely(result.int_32 < 0
17077 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17078 + errorfc(fc, "bad value in %s", param->key);
17081 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17082 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17086 + opt->rdblk = result.int_32;
17091 + opt->rdhash = AUFS_RDHASH_DEF;
17092 + if (!strcmp(param->string, "def"))
17095 + err = kstrtoint(param->string, 0, &result.int_32);
17096 + if (unlikely(err)) {
17097 + errorfc(fc, "bad value in %s", param->key);
17100 + /* how about zero? */
17101 + if (result.int_32 < 0
17102 + || result.int_32 * sizeof(struct hlist_head)
17103 + > KMALLOC_MAX_SIZE) {
17105 + errorfc(fc, "bad integer in %s", param->key);
17108 + opt->rdhash = result.int_32;
17113 + * As other options, fs/aufs/opts.c can handle these strings by
17114 + * match_token(). But "diropq=" is deprecated now and will
17115 + * never have other value. So simple strcmp() is enough here.
17117 + if (!strcmp(param->string, "a") ||
17118 + !strcmp(param->string, "always")) {
17120 + opt->type = Opt_diropq_a;
17121 + } else if (!strcmp(param->string, "w") ||
17122 + !strcmp(param->string, "whiteouted")) {
17124 + opt->type = Opt_diropq_w;
17126 + errorfc(fc, "unknown value %s", param->string);
17130 + opt->udba = au_udba_val(param->string);
17131 + if (opt->udba >= 0)
17134 + errorf(fc, "wrong value, %s", param->string);
17137 + case Opt_wbr_create:
17138 + opt->wbr_create.wbr_create
17139 + = au_wbr_create_val(param->string, &opt->wbr_create);
17140 + if (opt->wbr_create.wbr_create >= 0)
17143 + errorf(fc, "wrong value, %s", param->key);
17146 + case Opt_wbr_copyup:
17147 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17148 + if (opt->wbr_copyup >= 0)
17151 + errorfc(fc, "wrong value, %s", param->key);
17154 + case Opt_fhsm_sec:
17155 + if (unlikely(result.int_32 < 0)) {
17156 + errorfc(fc, "bad integer in %s\n", param->key);
17161 + opt->fhsm_second = result.int_32;
17163 + warnfc(fc, "ignored %s %s", param->key, param->string);
17166 + /* simple true/false flag */
17167 +#define au_fsctx_TF(name) \
17168 + case Opt_##name: \
17170 + opt->tf = !result.negated; \
17172 + au_fsctx_TF(trunc_xino);
17173 + au_fsctx_TF(trunc_xib);
17174 + au_fsctx_TF(dirperm1);
17175 + au_fsctx_TF(plink);
17176 + au_fsctx_TF(shwh);
17177 + au_fsctx_TF(dio);
17178 + au_fsctx_TF(warn_perm);
17179 + au_fsctx_TF(verbose);
17180 + au_fsctx_TF(sum);
17181 + au_fsctx_TF(dirren);
17182 + au_fsctx_TF(acl);
17183 +#undef au_fsctx_TF
17185 + case Opt_noverbose:
17187 + opt->type = Opt_verbose;
17193 + case Opt_list_plink:
17200 + warnfc(fc, "ignored %s", param->key);
17202 + case Opt_ignore_silent:
17211 + if (unlikely(err))
17219 + case Opt_noverbose:
17224 + opt->type = token;
17228 + if (unlikely(opt > a->opt_tail)) {
17232 + opt->type = Opt_tail;
17240 + * these options accept both 'name=val' and 'name:val' form.
17241 + * some accept optional '=' in its value.
17242 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17244 +static inline unsigned int is_colonopt(char *str)
17246 +#define do_test(name) \
17247 + if (!strncmp(str, name ":", sizeof(name))) \
17248 + return sizeof(name) - 1;
17252 + do_test("append");
17253 + do_test("prepend");
17255 + /* do_test("idel"); */
17257 + /* do_test("imod"); */
17263 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17268 + struct au_fsctx_opts *a = fc->fs_private;
17271 + AuDbg("str %s\n", str);
17273 + u = is_colonopt(str);
17276 + str = strchr(str, ',');
17282 + AuDbg("str %s\n", str);
17284 + err = generic_parse_monolithic(fc, str);
17286 + au_fsctx_dump(&a->opts);
17291 +/* ---------------------------------------------------------------------- */
17293 +static void au_fsctx_opts_free(struct au_opts *opts)
17295 + struct au_opt *opt;
17298 + while (opt->type != Opt_tail) {
17299 + switch (opt->type) {
17304 + case Opt_prepend:
17305 + kfree(opt->add.pathname);
17306 + path_put(&opt->add.path);
17309 + kfree(opt->del.pathname);
17312 + path_put(&opt->del.h_path);
17315 + kfree(opt->mod.path);
17318 + dput(opt->mod.h_root);
17321 + kfree(opt->xino.path);
17322 + fput(opt->xino.file);
17329 +static void au_fsctx_free(struct fs_context *fc)
17331 + struct au_fsctx_opts *a = fc->fs_private;
17333 + /* fs_type=%p, root=%pD */
17334 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17335 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17337 + kobject_put(&a->sbinfo->si_kobj);
17338 + au_fsctx_opts_free(&a->opts);
17339 + free_page((unsigned long)a->opts.opt);
17343 +static const struct fs_context_operations au_fsctx_ops = {
17344 + .free = au_fsctx_free,
17345 + .parse_param = au_fsctx_parse_param,
17346 + .parse_monolithic = au_fsctx_parse_monolithic,
17347 + .get_tree = au_fsctx_get_tree,
17348 + .reconfigure = au_fsctx_reconfigure
17350 + * nfs4 requires ->dup()? No.
17351 + * I don't know what is this ->dup() for.
17355 +int aufs_fsctx_init(struct fs_context *fc)
17358 + struct au_fsctx_opts *a;
17360 + /* fs_type=%p, root=%pD */
17361 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17362 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17364 + /* they will be freed by au_fsctx_free() */
17366 + a = kzalloc(sizeof(*a), GFP_NOFS);
17367 + if (unlikely(!a))
17370 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17371 + if (unlikely(!a->opts.opt))
17373 + a->opt = a->opts.opt;
17374 + a->opt->type = Opt_tail;
17375 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17376 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17377 + a->opts.sb_flags = fc->sb_flags;
17381 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17382 + a->opts.flags = AuOpts_REMOUNT;
17383 + a->sb = fc->root->d_sb;
17384 + a->sbinfo = au_sbi(a->sb);
17385 + kobject_get(&a->sbinfo->si_kobj);
17387 + a->sbinfo = au_si_alloc(a->sb);
17388 + AuDebugOn(!a->sbinfo);
17389 + err = PTR_ERR(a->sbinfo);
17390 + if (IS_ERR(a->sbinfo))
17392 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17396 + fc->fs_private = a;
17397 + fc->ops = &au_fsctx_ops;
17398 + goto out; /* success */
17401 + free_page((unsigned long)a->opts.opt);
17408 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17409 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17410 +++ linux/fs/aufs/fstype.h 2022-03-21 14:49:05.723299677 +0100
17412 +/* SPDX-License-Identifier: GPL-2.0 */
17414 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17416 + * This program, aufs is free software; you can redistribute it and/or modify
17417 + * it under the terms of the GNU General Public License as published by
17418 + * the Free Software Foundation; either version 2 of the License, or
17419 + * (at your option) any later version.
17421 + * This program is distributed in the hope that it will be useful,
17422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17424 + * GNU General Public License for more details.
17426 + * You should have received a copy of the GNU General Public License
17427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17431 + * judging filesystem type
17434 +#ifndef __AUFS_FSTYPE_H__
17435 +#define __AUFS_FSTYPE_H__
17439 +#include <linux/fs.h>
17440 +#include <linux/magic.h>
17441 +#include <linux/nfs_fs.h>
17442 +#include <linux/romfs_fs.h>
17444 +static inline int au_test_aufs(struct super_block *sb)
17446 + return sb->s_magic == AUFS_SUPER_MAGIC;
17449 +static inline const char *au_sbtype(struct super_block *sb)
17451 + return sb->s_type->name;
17454 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17456 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17457 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17463 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17465 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17466 + return sb->s_magic == ROMFS_MAGIC;
17472 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17474 +#if IS_ENABLED(CONFIG_CRAMFS)
17475 + return sb->s_magic == CRAMFS_MAGIC;
17480 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17482 +#if IS_ENABLED(CONFIG_NFS_FS)
17483 + return sb->s_magic == NFS_SUPER_MAGIC;
17489 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17491 +#if IS_ENABLED(CONFIG_FUSE_FS)
17492 + return sb->s_magic == FUSE_SUPER_MAGIC;
17498 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17500 +#if IS_ENABLED(CONFIG_XFS_FS)
17501 + return sb->s_magic == XFS_SB_MAGIC;
17507 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17509 +#ifdef CONFIG_TMPFS
17510 + return sb->s_magic == TMPFS_MAGIC;
17516 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17518 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17519 + return !strcmp(au_sbtype(sb), "ecryptfs");
17525 +static inline int au_test_ramfs(struct super_block *sb)
17527 + return sb->s_magic == RAMFS_MAGIC;
17530 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17532 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17533 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17539 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17541 +#ifdef CONFIG_PROC_FS
17542 + return sb->s_magic == PROC_SUPER_MAGIC;
17548 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17550 +#ifdef CONFIG_SYSFS
17551 + return sb->s_magic == SYSFS_MAGIC;
17557 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17559 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17560 + return sb->s_magic == CONFIGFS_MAGIC;
17566 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17568 +#if IS_ENABLED(CONFIG_MINIX_FS)
17569 + return sb->s_magic == MINIX3_SUPER_MAGIC
17570 + || sb->s_magic == MINIX2_SUPER_MAGIC
17571 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17572 + || sb->s_magic == MINIX_SUPER_MAGIC
17573 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17579 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17581 +#if IS_ENABLED(CONFIG_FAT_FS)
17582 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17588 +static inline int au_test_msdos(struct super_block *sb)
17590 + return au_test_fat(sb);
17593 +static inline int au_test_vfat(struct super_block *sb)
17595 + return au_test_fat(sb);
17598 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17600 +#ifdef CONFIG_SECURITYFS
17601 + return sb->s_magic == SECURITYFS_MAGIC;
17607 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17609 +#if IS_ENABLED(CONFIG_SQUASHFS)
17610 + return sb->s_magic == SQUASHFS_MAGIC;
17616 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17618 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17619 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17625 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17627 +#if IS_ENABLED(CONFIG_XENFS)
17628 + return sb->s_magic == XENFS_SUPER_MAGIC;
17634 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17636 +#ifdef CONFIG_DEBUG_FS
17637 + return sb->s_magic == DEBUGFS_MAGIC;
17643 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17645 +#if IS_ENABLED(CONFIG_NILFS)
17646 + return sb->s_magic == NILFS_SUPER_MAGIC;
17652 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17654 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17655 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17661 +/* ---------------------------------------------------------------------- */
17663 + * they can't be an aufs branch.
17665 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17668 +#ifndef CONFIG_AUFS_BR_RAMFS
17669 + au_test_ramfs(sb) ||
17671 + au_test_procfs(sb)
17672 + || au_test_sysfs(sb)
17673 + || au_test_configfs(sb)
17674 + || au_test_debugfs(sb)
17675 + || au_test_securityfs(sb)
17676 + || au_test_xenfs(sb)
17677 + || au_test_ecryptfs(sb)
17678 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17679 + || au_test_aufs(sb); /* will be supported in next version */
17682 +static inline int au_test_fs_remote(struct super_block *sb)
17684 + return !au_test_tmpfs(sb)
17685 +#ifdef CONFIG_AUFS_BR_RAMFS
17686 + && !au_test_ramfs(sb)
17688 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17691 +/* ---------------------------------------------------------------------- */
17694 + * Note: these functions (below) are created after reading ->getattr() in all
17695 + * filesystems under linux/fs. it means we have to do so in every update...
17699 + * some filesystems require getattr to refresh the inode attributes before
17701 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17702 + * and leave the work for d_revalidate()
17704 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17706 + return au_test_nfs(sb)
17707 + || au_test_fuse(sb)
17708 + /* || au_test_btrfs(sb) */ /* untested */
17713 + * filesystems which don't maintain i_size or i_blocks.
17715 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17717 + return au_test_xfs(sb)
17718 + || au_test_btrfs(sb)
17719 + || au_test_ubifs(sb)
17720 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17721 + /* || au_test_minix(sb) */ /* untested */
17726 + * filesystems which don't store the correct value in some of their inode
17729 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17731 + return au_test_fs_bad_iattr_size(sb)
17732 + || au_test_fat(sb)
17733 + || au_test_msdos(sb)
17734 + || au_test_vfat(sb);
17737 +/* they don't check i_nlink in link(2) */
17738 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17740 + return au_test_tmpfs(sb)
17741 +#ifdef CONFIG_AUFS_BR_RAMFS
17742 + || au_test_ramfs(sb)
17744 + || au_test_ubifs(sb)
17745 + || au_test_hfsplus(sb);
17749 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17751 +static inline int au_test_fs_notime(struct super_block *sb)
17753 + return au_test_nfs(sb)
17754 + || au_test_fuse(sb)
17755 + || au_test_ubifs(sb)
17759 +/* temporary support for i#1 in cramfs */
17760 +static inline int au_test_fs_unique_ino(struct inode *inode)
17762 + if (au_test_cramfs(inode->i_sb))
17763 + return inode->i_ino != 1;
17767 +/* ---------------------------------------------------------------------- */
17770 + * the filesystem where the xino files placed must support i/o after unlink and
17771 + * maintain i_size and i_blocks.
17773 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17775 + return au_test_fs_remote(sb)
17776 + || au_test_fs_bad_iattr_size(sb)
17777 + /* don't want unnecessary work for xino */
17778 + || au_test_aufs(sb)
17779 + || au_test_ecryptfs(sb)
17780 + || au_test_nilfs(sb);
17783 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17785 + return au_test_tmpfs(sb)
17786 + || au_test_ramfs(sb);
17790 + * test if the @sb is real-readonly.
17792 +static inline int au_test_fs_rr(struct super_block *sb)
17794 + return au_test_squashfs(sb)
17795 + || au_test_iso9660(sb)
17796 + || au_test_cramfs(sb)
17797 + || au_test_romfs(sb);
17801 + * test if the @inode is nfs with 'noacl' option
17802 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17804 +static inline int au_test_nfs_noacl(struct inode *inode)
17806 + return au_test_nfs(inode->i_sb)
17807 + /* && IS_POSIXACL(inode) */
17808 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17811 +#endif /* __KERNEL__ */
17812 +#endif /* __AUFS_FSTYPE_H__ */
17813 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17814 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17815 +++ linux/fs/aufs/hbl.h 2022-03-21 14:49:05.723299677 +0100
17817 +/* SPDX-License-Identifier: GPL-2.0 */
17819 + * Copyright (C) 2017-2021 Junjiro R. Okajima
17821 + * This program, aufs is free software; you can redistribute it and/or modify
17822 + * it under the terms of the GNU General Public License as published by
17823 + * the Free Software Foundation; either version 2 of the License, or
17824 + * (at your option) any later version.
17826 + * This program is distributed in the hope that it will be useful,
17827 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17828 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17829 + * GNU General Public License for more details.
17831 + * You should have received a copy of the GNU General Public License
17832 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17836 + * helpers for hlist_bl.h
17839 +#ifndef __AUFS_HBL_H__
17840 +#define __AUFS_HBL_H__
17844 +#include <linux/list_bl.h>
17846 +static inline void au_hbl_add(struct hlist_bl_node *node,
17847 + struct hlist_bl_head *hbl)
17849 + hlist_bl_lock(hbl);
17850 + hlist_bl_add_head(node, hbl);
17851 + hlist_bl_unlock(hbl);
17854 +static inline void au_hbl_del(struct hlist_bl_node *node,
17855 + struct hlist_bl_head *hbl)
17857 + hlist_bl_lock(hbl);
17858 + hlist_bl_del(node);
17859 + hlist_bl_unlock(hbl);
17862 +#define au_hbl_for_each(pos, head) \
17863 + for (pos = hlist_bl_first(head); \
17867 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17869 + unsigned long cnt;
17870 + struct hlist_bl_node *pos;
17873 + hlist_bl_lock(hbl);
17874 + au_hbl_for_each(pos, hbl)
17876 + hlist_bl_unlock(hbl);
17880 +#endif /* __KERNEL__ */
17881 +#endif /* __AUFS_HBL_H__ */
17882 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17883 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17884 +++ linux/fs/aufs/hfsnotify.c 2022-03-21 14:49:05.723299677 +0100
17886 +// SPDX-License-Identifier: GPL-2.0
17888 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17890 + * This program, aufs is free software; you can redistribute it and/or modify
17891 + * it under the terms of the GNU General Public License as published by
17892 + * the Free Software Foundation; either version 2 of the License, or
17893 + * (at your option) any later version.
17895 + * This program is distributed in the hope that it will be useful,
17896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17898 + * GNU General Public License for more details.
17900 + * You should have received a copy of the GNU General Public License
17901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17905 + * fsnotify for the lower directories
17910 +/* FS_IN_IGNORED is unnecessary */
17911 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17912 + | FS_CREATE | FS_EVENT_ON_CHILD);
17913 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17914 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17916 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17918 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17920 + /* AuDbg("here\n"); */
17921 + au_cache_free_hnotify(hn);
17922 + smp_mb__before_atomic(); /* for atomic64_dec */
17923 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17924 + wake_up(&au_hfsn_wq);
17927 +static int au_hfsn_alloc(struct au_hinode *hinode)
17930 + struct au_hnotify *hn;
17931 + struct super_block *sb;
17932 + struct au_branch *br;
17933 + struct fsnotify_mark *mark;
17934 + aufs_bindex_t bindex;
17936 + hn = hinode->hi_notify;
17937 + sb = hn->hn_aufs_inode->i_sb;
17938 + bindex = au_br_index(sb, hinode->hi_id);
17939 + br = au_sbr(sb, bindex);
17940 + AuDebugOn(!br->br_hfsn);
17942 + mark = &hn->hn_mark;
17943 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17944 + mark->mask = AuHfsnMask;
17946 + * by udba rename or rmdir, aufs assign a new inode to the known
17947 + * h_inode, so specify 1 to allow dups.
17950 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17956 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17958 + struct fsnotify_mark *mark;
17959 + unsigned long long ull;
17960 + struct fsnotify_group *group;
17962 + ull = atomic64_inc_return(&au_hfsn_ifree);
17965 + mark = &hn->hn_mark;
17966 + spin_lock(&mark->lock);
17967 + group = mark->group;
17968 + fsnotify_get_group(group);
17969 + spin_unlock(&mark->lock);
17971 + fsnotify_destroy_mark(mark, group);
17972 + fsnotify_put_mark(mark);
17973 + fsnotify_put_group(group);
17976 + /* free hn by myself */
17980 +/* ---------------------------------------------------------------------- */
17982 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
17984 + struct fsnotify_mark *mark;
17986 + mark = &hinode->hi_notify->hn_mark;
17987 + spin_lock(&mark->lock);
17989 + AuDebugOn(mark->mask & AuHfsnMask);
17990 + mark->mask |= AuHfsnMask;
17992 + AuDebugOn(!(mark->mask & AuHfsnMask));
17993 + mark->mask &= ~AuHfsnMask;
17995 + spin_unlock(&mark->lock);
17996 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
17999 +/* ---------------------------------------------------------------------- */
18001 +/* #define AuDbgHnotify */
18002 +#ifdef AuDbgHnotify
18003 +static char *au_hfsn_name(u32 mask)
18005 +#ifdef CONFIG_AUFS_DEBUG
18006 +#define test_ret(flag) \
18008 + if (mask & flag) \
18011 + test_ret(FS_ACCESS);
18012 + test_ret(FS_MODIFY);
18013 + test_ret(FS_ATTRIB);
18014 + test_ret(FS_CLOSE_WRITE);
18015 + test_ret(FS_CLOSE_NOWRITE);
18016 + test_ret(FS_OPEN);
18017 + test_ret(FS_MOVED_FROM);
18018 + test_ret(FS_MOVED_TO);
18019 + test_ret(FS_CREATE);
18020 + test_ret(FS_DELETE);
18021 + test_ret(FS_DELETE_SELF);
18022 + test_ret(FS_MOVE_SELF);
18023 + test_ret(FS_UNMOUNT);
18024 + test_ret(FS_Q_OVERFLOW);
18025 + test_ret(FS_IN_IGNORED);
18026 + test_ret(FS_ISDIR);
18027 + test_ret(FS_IN_ONESHOT);
18028 + test_ret(FS_EVENT_ON_CHILD);
18037 +/* ---------------------------------------------------------------------- */
18039 +static void au_hfsn_free_group(struct fsnotify_group *group)
18041 + struct au_br_hfsnotify *hfsn = group->private;
18043 + /* AuDbg("here\n"); */
18044 + au_kfree_try_rcu(hfsn);
18047 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18048 + u32 mask, const void *data, int data_type,
18049 + struct inode *dir,
18050 + const struct qstr *file_name, u32 cookie,
18051 + struct fsnotify_iter_info *iter_info)
18054 + struct au_hnotify *hnotify;
18055 + struct inode *h_dir, *h_inode;
18056 + struct fsnotify_mark *inode_mark;
18058 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18059 + || data_type == FSNOTIFY_EVENT_DENTRY));
18062 + /* if FS_UNMOUNT happens, there must be another bug */
18063 + AuDebugOn(mask & FS_UNMOUNT);
18064 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18069 +#ifdef AuDbgHnotify
18071 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
18072 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
18073 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18074 + h_dir->i_ino, mask, au_hfsn_name(mask),
18075 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
18076 + /* WARN_ON(1); */
18081 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18082 + AuDebugOn(!inode_mark);
18083 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18084 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18090 +static struct fsnotify_ops au_hfsn_ops = {
18091 + .handle_event = au_hfsn_handle_event,
18092 + .free_group_priv = au_hfsn_free_group,
18093 + .free_mark = au_hfsn_free_mark
18096 +/* ---------------------------------------------------------------------- */
18098 +static void au_hfsn_fin_br(struct au_branch *br)
18100 + struct au_br_hfsnotify *hfsn;
18102 + hfsn = br->br_hfsn;
18105 + fsnotify_put_group(hfsn->hfsn_group);
18110 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18113 + struct fsnotify_group *group;
18114 + struct au_br_hfsnotify *hfsn;
18117 + br->br_hfsn = NULL;
18118 + if (!au_br_hnotifyable(perm))
18122 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18123 + if (unlikely(!hfsn))
18127 + group = fsnotify_alloc_group(&au_hfsn_ops);
18128 + if (IS_ERR(group)) {
18129 + err = PTR_ERR(group);
18130 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18134 + group->private = hfsn;
18135 + hfsn->hfsn_group = group;
18136 + br->br_hfsn = hfsn;
18137 + goto out; /* success */
18140 + au_kfree_try_rcu(hfsn);
18145 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18150 + if (!br->br_hfsn)
18151 + err = au_hfsn_init_br(br, perm);
18156 +/* ---------------------------------------------------------------------- */
18158 +static void au_hfsn_fin(void)
18160 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18161 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18164 +const struct au_hnotify_op au_hnotify_op = {
18165 + .ctl = au_hfsn_ctl,
18166 + .alloc = au_hfsn_alloc,
18167 + .free = au_hfsn_free,
18169 + .fin = au_hfsn_fin,
18171 + .reset_br = au_hfsn_reset_br,
18172 + .fin_br = au_hfsn_fin_br,
18173 + .init_br = au_hfsn_init_br
18175 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18176 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18177 +++ linux/fs/aufs/hfsplus.c 2022-03-21 14:49:05.723299677 +0100
18179 +// SPDX-License-Identifier: GPL-2.0
18181 + * Copyright (C) 2010-2021 Junjiro R. Okajima
18183 + * This program, aufs is free software; you can redistribute it and/or modify
18184 + * it under the terms of the GNU General Public License as published by
18185 + * the Free Software Foundation; either version 2 of the License, or
18186 + * (at your option) any later version.
18188 + * This program is distributed in the hope that it will be useful,
18189 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18190 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18191 + * GNU General Public License for more details.
18193 + * You should have received a copy of the GNU General Public License
18194 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18198 + * special support for filesystems which acquires an inode mutex
18199 + * at final closing a file, eg, hfsplus.
18201 + * This trick is very simple and stupid, just to open the file before really
18202 + * necessary open to tell hfsplus that this is not the final closing.
18203 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18204 + * and au_h_open_post() after releasing it.
18209 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18212 + struct file *h_file;
18213 + struct dentry *h_dentry;
18215 + h_dentry = au_h_dptr(dentry, bindex);
18216 + AuDebugOn(!h_dentry);
18217 + AuDebugOn(d_is_negative(h_dentry));
18220 + if (au_test_hfsplus(h_dentry->d_sb)
18221 + && d_is_reg(h_dentry))
18222 + h_file = au_h_open(dentry, bindex,
18223 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18224 + /*file*/NULL, force_wr);
18228 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18229 + struct file *h_file)
18231 + struct au_branch *br;
18235 + br = au_sbr(dentry->d_sb, bindex);
18236 + au_lcnt_dec(&br->br_nfiles);
18239 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18240 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18241 +++ linux/fs/aufs/hnotify.c 2022-03-21 14:49:05.723299677 +0100
18243 +// SPDX-License-Identifier: GPL-2.0
18245 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18247 + * This program, aufs is free software; you can redistribute it and/or modify
18248 + * it under the terms of the GNU General Public License as published by
18249 + * the Free Software Foundation; either version 2 of the License, or
18250 + * (at your option) any later version.
18252 + * This program is distributed in the hope that it will be useful,
18253 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18254 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18255 + * GNU General Public License for more details.
18257 + * You should have received a copy of the GNU General Public License
18258 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18262 + * abstraction to notify the direct changes on lower directories
18265 +/* #include <linux/iversion.h> */
18268 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18271 + struct au_hnotify *hn;
18274 + hn = au_cache_alloc_hnotify();
18276 + hn->hn_aufs_inode = inode;
18277 + hinode->hi_notify = hn;
18278 + err = au_hnotify_op.alloc(hinode);
18280 + if (unlikely(err)) {
18281 + hinode->hi_notify = NULL;
18282 + au_cache_free_hnotify(hn);
18284 + * The upper dir was removed by udba, but the same named
18285 + * dir left. In this case, aufs assigns a new inode
18286 + * number and set the monitor again.
18287 + * For the lower dir, the old monitor is still left.
18289 + if (err == -EEXIST)
18298 +void au_hn_free(struct au_hinode *hinode)
18300 + struct au_hnotify *hn;
18302 + hn = hinode->hi_notify;
18304 + hinode->hi_notify = NULL;
18305 + if (au_hnotify_op.free(hinode, hn))
18306 + au_cache_free_hnotify(hn);
18310 +/* ---------------------------------------------------------------------- */
18312 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18314 + if (hinode->hi_notify)
18315 + au_hnotify_op.ctl(hinode, do_set);
18318 +void au_hn_reset(struct inode *inode, unsigned int flags)
18320 + aufs_bindex_t bindex, bbot;
18321 + struct inode *hi;
18322 + struct dentry *iwhdentry;
18324 + bbot = au_ibbot(inode);
18325 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18326 + hi = au_h_iptr(inode, bindex);
18330 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18331 + iwhdentry = au_hi_wh(inode, bindex);
18335 + au_set_h_iptr(inode, bindex, NULL, 0);
18336 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18337 + flags & ~AuHi_XINO);
18340 + /* inode_unlock(hi); */
18344 +/* ---------------------------------------------------------------------- */
18346 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18349 + aufs_bindex_t bindex, bbot, bfound, btop;
18350 + struct inode *h_i;
18353 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18354 + pr_warn("branch root dir was changed\n");
18359 + bbot = au_ibbot(inode);
18360 + btop = au_ibtop(inode);
18361 +#if 0 /* reserved for future use */
18362 + if (bindex == bbot) {
18363 + /* keep this ino in rename case */
18367 + for (bindex = btop; bindex <= bbot; bindex++)
18368 + if (au_h_iptr(inode, bindex) == h_inode) {
18375 + for (bindex = btop; bindex <= bbot; bindex++) {
18376 + h_i = au_h_iptr(inode, bindex);
18380 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18381 + /* ignore this error */
18382 + /* bad action? */
18385 + /* children inode number will be broken */
18392 +static int hn_gen_tree(struct dentry *dentry)
18394 + int err, i, j, ndentry;
18395 + struct au_dcsub_pages dpages;
18396 + struct au_dpage *dpage;
18397 + struct dentry **dentries;
18399 + err = au_dpages_init(&dpages, GFP_NOFS);
18400 + if (unlikely(err))
18402 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18403 + if (unlikely(err))
18406 + for (i = 0; i < dpages.ndpage; i++) {
18407 + dpage = dpages.dpages + i;
18408 + dentries = dpage->dentries;
18409 + ndentry = dpage->ndentry;
18410 + for (j = 0; j < ndentry; j++) {
18411 + struct dentry *d;
18418 + if (d_really_is_positive(d))
18419 + /* todo: reset children xino?
18420 + cached children only? */
18421 + au_iigen_dec(d_inode(d));
18426 + au_dpages_free(&dpages);
18432 + * return 0 if processed.
18434 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18435 + const unsigned int isdir)
18438 + struct dentry *d;
18439 + struct qstr *dname;
18442 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18443 + pr_warn("branch root dir was changed\n");
18449 + AuDebugOn(!name);
18450 + au_iigen_dec(inode);
18451 + spin_lock(&inode->i_lock);
18452 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18453 + spin_lock(&d->d_lock);
18454 + dname = &d->d_name;
18455 + if (dname->len != nlen
18456 + && memcmp(dname->name, name, nlen)) {
18457 + spin_unlock(&d->d_lock);
18462 + spin_unlock(&d->d_lock);
18465 + spin_unlock(&inode->i_lock);
18467 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18468 + d = d_find_any_alias(inode);
18470 + au_iigen_dec(inode);
18474 + spin_lock(&d->d_lock);
18475 + dname = &d->d_name;
18476 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18477 + spin_unlock(&d->d_lock);
18478 + err = hn_gen_tree(d);
18479 + spin_lock(&d->d_lock);
18481 + spin_unlock(&d->d_lock);
18490 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18494 + if (IS_ROOT(dentry)) {
18495 + pr_warn("branch root dir was changed\n");
18501 + au_digen_dec(dentry);
18502 + if (d_really_is_positive(dentry))
18503 + au_iigen_dec(d_inode(dentry));
18505 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18506 + if (d_really_is_positive(dentry))
18507 + err = hn_gen_tree(dentry);
18514 +/* ---------------------------------------------------------------------- */
18516 +/* hnotify job flags */
18517 +#define AuHnJob_XINO0 1
18518 +#define AuHnJob_GEN (1 << 1)
18519 +#define AuHnJob_DIRENT (1 << 2)
18520 +#define AuHnJob_ISDIR (1 << 3)
18521 +#define AuHnJob_TRYXINO0 (1 << 4)
18522 +#define AuHnJob_MNTPNT (1 << 5)
18523 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18524 +#define au_fset_hnjob(flags, name) \
18525 + do { (flags) |= AuHnJob_##name; } while (0)
18526 +#define au_fclr_hnjob(flags, name) \
18527 + do { (flags) &= ~AuHnJob_##name; } while (0)
18535 +struct au_hnotify_args {
18536 + struct inode *h_dir, *dir, *h_child_inode;
18538 + unsigned int flags[AuHnLast];
18539 + unsigned int h_child_nlen;
18540 + char h_child_name[];
18543 +struct hn_job_args {
18544 + unsigned int flags;
18545 + struct inode *inode, *h_inode, *dir, *h_dir;
18546 + struct dentry *dentry;
18551 +static int hn_job(struct hn_job_args *a)
18553 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18557 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18558 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18560 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18563 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18564 + if (!a->h_inode->i_nlink
18565 + && !(a->h_inode->i_state & I_LINKABLE))
18566 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18567 + inode_unlock_shared(a->h_inode);
18570 + /* make the generation obsolete */
18571 + if (au_ftest_hnjob(a->flags, GEN)) {
18574 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18576 + if (e && a->dentry)
18577 + hn_gen_by_name(a->dentry, isdir);
18578 + /* ignore this error */
18581 + /* make dir entries obsolete */
18582 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18583 + struct au_vdir *vdir;
18585 + vdir = au_ivdir(a->inode);
18587 + vdir->vd_jiffy = 0;
18588 + /* IMustLock(a->inode); */
18589 + /* inode_inc_iversion(a->inode); */
18592 + /* can do nothing but warn */
18593 + if (au_ftest_hnjob(a->flags, MNTPNT)
18595 + && d_mountpoint(a->dentry))
18596 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18601 +/* ---------------------------------------------------------------------- */
18603 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18604 + struct inode *dir)
18606 + struct dentry *dentry, *d, *parent;
18607 + struct qstr *dname;
18609 + parent = d_find_any_alias(dir);
18614 + spin_lock(&parent->d_lock);
18615 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18616 + /* AuDbg("%pd\n", d); */
18617 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18618 + dname = &d->d_name;
18619 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18620 + goto cont_unlock;
18624 + goto cont_unlock;
18625 + if (au_dcount(d) > 0) {
18626 + dentry = dget_dlock(d);
18627 + spin_unlock(&d->d_lock);
18632 + spin_unlock(&d->d_lock);
18634 + spin_unlock(&parent->d_lock);
18638 + di_write_lock_child(dentry);
18643 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18644 + aufs_bindex_t bindex, ino_t h_ino)
18646 + struct inode *inode;
18651 + err = au_xino_read(sb, bindex, h_ino, &ino);
18653 + inode = ilookup(sb, ino);
18657 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18658 + pr_warn("wrong root branch\n");
18664 + ii_write_lock_child(inode);
18670 +static void au_hn_bh(void *_args)
18672 + struct au_hnotify_args *a = _args;
18673 + struct super_block *sb;
18674 + aufs_bindex_t bindex, bbot, bfound;
18675 + unsigned char xino, try_iput;
18677 + struct inode *inode;
18679 + struct hn_job_args args;
18680 + struct dentry *dentry;
18681 + struct au_sbinfo *sbinfo;
18683 + AuDebugOn(!_args);
18684 + AuDebugOn(!a->h_dir);
18685 + AuDebugOn(!a->dir);
18686 + AuDebugOn(!a->mask);
18687 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18688 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18689 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18694 + * do not lock a->dir->i_mutex here
18695 + * because of d_revalidate() may cause a deadlock.
18697 + sb = a->dir->i_sb;
18699 + sbinfo = au_sbi(sb);
18700 + AuDebugOn(!sbinfo);
18701 + si_write_lock(sb, AuLock_NOPLMW);
18703 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18704 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18705 + case FS_MOVED_FROM:
18706 + case FS_MOVED_TO:
18707 + AuWarn1("DIRREN with UDBA may not work correctly "
18708 + "for the direct rename(2)\n");
18711 + ii_read_lock_parent(a->dir);
18713 + bbot = au_ibbot(a->dir);
18714 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18715 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18719 + ii_read_unlock(a->dir);
18720 + if (unlikely(bfound < 0))
18723 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18725 + if (a->h_child_inode)
18726 + h_ino = a->h_child_inode->i_ino;
18728 + if (a->h_child_nlen
18729 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18730 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18731 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18734 + if (dentry && d_really_is_positive(dentry))
18735 + inode = d_inode(dentry);
18736 + if (xino && !inode && h_ino
18737 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18738 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18739 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18740 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18744 + args.flags = a->flags[AuHn_CHILD];
18745 + args.dentry = dentry;
18746 + args.inode = inode;
18747 + args.h_inode = a->h_child_inode;
18748 + args.dir = a->dir;
18749 + args.h_dir = a->h_dir;
18750 + args.h_name = a->h_child_name;
18751 + args.h_nlen = a->h_child_nlen;
18752 + err = hn_job(&args);
18754 + if (au_di(dentry))
18755 + di_write_unlock(dentry);
18758 + if (inode && try_iput) {
18759 + ii_write_unlock(inode);
18763 + ii_write_lock_parent(a->dir);
18764 + args.flags = a->flags[AuHn_PARENT];
18765 + args.dentry = NULL;
18766 + args.inode = a->dir;
18767 + args.h_inode = a->h_dir;
18769 + args.h_dir = NULL;
18770 + args.h_name = NULL;
18772 + err = hn_job(&args);
18773 + ii_write_unlock(a->dir);
18776 + iput(a->h_child_inode);
18779 + si_write_unlock(sb);
18780 + au_nwt_done(&sbinfo->si_nowait);
18784 +/* ---------------------------------------------------------------------- */
18786 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18787 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18790 + unsigned int flags[AuHnLast], f;
18791 + unsigned char isdir, isroot, wh;
18792 + struct inode *dir;
18793 + struct au_hnotify_args *args;
18794 + char *p, *h_child_name;
18797 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18798 + dir = igrab(hnotify->hn_aufs_inode);
18802 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18804 + h_child_name = (void *)h_child_qstr->name;
18805 + len = h_child_qstr->len;
18806 + if (h_child_name) {
18807 + if (len > AUFS_WH_PFX_LEN
18808 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18809 + h_child_name += AUFS_WH_PFX_LEN;
18810 + len -= AUFS_WH_PFX_LEN;
18816 + if (h_child_inode)
18817 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18818 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18819 + flags[AuHn_CHILD] = 0;
18821 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18822 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18823 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18824 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18825 + case FS_MOVED_FROM:
18826 + case FS_MOVED_TO:
18827 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18828 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18831 + AuDebugOn(!h_child_name);
18836 + * aufs never be able to get this child inode.
18837 + * revalidation should be in d_revalidate()
18838 + * by checking i_nlink, i_generation or d_unhashed().
18840 + AuDebugOn(!h_child_name);
18841 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18842 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18850 + h_child_inode = NULL;
18853 + /* iput() and kfree() will be called in au_hnotify() */
18854 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18855 + if (unlikely(!args)) {
18856 + AuErr1("no memory\n");
18860 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18861 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18862 + args->mask = mask;
18864 + args->h_dir = igrab(h_dir);
18865 + if (h_child_inode)
18866 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18867 + args->h_child_inode = h_child_inode;
18868 + args->h_child_nlen = len;
18870 + p = (void *)args;
18871 + p += sizeof(*args);
18872 + memcpy(p, h_child_name, len);
18876 + /* NFS fires the event for silly-renamed one from kworker */
18878 + if (!dir->i_nlink
18879 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18881 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18882 + if (unlikely(err)) {
18883 + pr_err("wkq %d\n", err);
18884 + iput(args->h_child_inode);
18885 + iput(args->h_dir);
18887 + au_kfree_rcu(args);
18894 +/* ---------------------------------------------------------------------- */
18896 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18900 + AuDebugOn(!(udba & AuOptMask_UDBA));
18903 + if (au_hnotify_op.reset_br)
18904 + err = au_hnotify_op.reset_br(udba, br, perm);
18909 +int au_hnotify_init_br(struct au_branch *br, int perm)
18914 + if (au_hnotify_op.init_br)
18915 + err = au_hnotify_op.init_br(br, perm);
18920 +void au_hnotify_fin_br(struct au_branch *br)
18922 + if (au_hnotify_op.fin_br)
18923 + au_hnotify_op.fin_br(br);
18926 +static void au_hn_destroy_cache(void)
18928 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18929 + au_cache[AuCache_HNOTIFY] = NULL;
18932 +int __init au_hnotify_init(void)
18937 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18938 + if (au_cache[AuCache_HNOTIFY]) {
18940 + if (au_hnotify_op.init)
18941 + err = au_hnotify_op.init();
18942 + if (unlikely(err))
18943 + au_hn_destroy_cache();
18949 +void au_hnotify_fin(void)
18951 + if (au_hnotify_op.fin)
18952 + au_hnotify_op.fin();
18954 + /* cf. au_cache_fin() */
18955 + if (au_cache[AuCache_HNOTIFY])
18956 + au_hn_destroy_cache();
18958 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18959 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18960 +++ linux/fs/aufs/iinfo.c 2022-03-21 14:49:05.726633010 +0100
18962 +// SPDX-License-Identifier: GPL-2.0
18964 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18966 + * This program, aufs is free software; you can redistribute it and/or modify
18967 + * it under the terms of the GNU General Public License as published by
18968 + * the Free Software Foundation; either version 2 of the License, or
18969 + * (at your option) any later version.
18971 + * This program is distributed in the hope that it will be useful,
18972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18974 + * GNU General Public License for more details.
18976 + * You should have received a copy of the GNU General Public License
18977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18981 + * inode private data
18986 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
18988 + struct inode *h_inode;
18989 + struct au_hinode *hinode;
18991 + IiMustAnyLock(inode);
18993 + hinode = au_hinode(au_ii(inode), bindex);
18994 + h_inode = hinode->hi_inode;
18995 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
18999 +/* todo: hard/soft set? */
19000 +void au_hiput(struct au_hinode *hinode)
19002 + au_hn_free(hinode);
19003 + dput(hinode->hi_whdentry);
19004 + iput(hinode->hi_inode);
19007 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19009 + unsigned int flags;
19010 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19013 + if (au_opt_test(mnt_flags, XINO))
19014 + au_fset_hi(flags, XINO);
19015 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19016 + au_fset_hi(flags, HNOTIFY);
19020 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19021 + struct inode *h_inode, unsigned int flags)
19023 + struct au_hinode *hinode;
19024 + struct inode *hi;
19025 + struct au_iinfo *iinfo = au_ii(inode);
19027 + IiMustWriteLock(inode);
19029 + hinode = au_hinode(iinfo, bindex);
19030 + hi = hinode->hi_inode;
19031 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19034 + au_hiput(hinode);
19035 + hinode->hi_inode = h_inode;
19038 + struct super_block *sb = inode->i_sb;
19039 + struct au_branch *br;
19041 + AuDebugOn(inode->i_mode
19042 + && (h_inode->i_mode & S_IFMT)
19043 + != (inode->i_mode & S_IFMT));
19044 + if (bindex == iinfo->ii_btop)
19045 + au_cpup_igen(inode, h_inode);
19046 + br = au_sbr(sb, bindex);
19047 + hinode->hi_id = br->br_id;
19048 + if (au_ftest_hi(flags, XINO)) {
19049 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19051 + if (unlikely(err))
19052 + AuIOErr1("failed au_xino_write() %d\n", err);
19055 + if (au_ftest_hi(flags, HNOTIFY)
19056 + && au_br_hnotifyable(br->br_perm)) {
19057 + err = au_hn_alloc(hinode, inode);
19058 + if (unlikely(err))
19059 + AuIOErr1("au_hn_alloc() %d\n", err);
19064 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19065 + struct dentry *h_wh)
19067 + struct au_hinode *hinode;
19069 + IiMustWriteLock(inode);
19071 + hinode = au_hinode(au_ii(inode), bindex);
19072 + AuDebugOn(hinode->hi_whdentry);
19073 + hinode->hi_whdentry = h_wh;
19076 +void au_update_iigen(struct inode *inode, int half)
19078 + struct au_iinfo *iinfo;
19079 + struct au_iigen *iigen;
19080 + unsigned int sigen;
19082 + sigen = au_sigen(inode->i_sb);
19083 + iinfo = au_ii(inode);
19084 + iigen = &iinfo->ii_generation;
19085 + spin_lock(&iigen->ig_spin);
19086 + iigen->ig_generation = sigen;
19088 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19090 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19091 + spin_unlock(&iigen->ig_spin);
19094 +/* it may be called at remount time, too */
19095 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19097 + struct au_iinfo *iinfo;
19098 + aufs_bindex_t bindex, bbot;
19100 + AuDebugOn(au_is_bad_inode(inode));
19101 + IiMustWriteLock(inode);
19103 + iinfo = au_ii(inode);
19104 + if (do_put_zero && iinfo->ii_btop >= 0) {
19105 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19107 + struct inode *h_i;
19109 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19112 + && !(h_i->i_state & I_LINKABLE))
19113 + au_set_h_iptr(inode, bindex, NULL, 0);
19117 + iinfo->ii_btop = -1;
19118 + iinfo->ii_bbot = -1;
19119 + bbot = au_sbbot(inode->i_sb);
19120 + for (bindex = 0; bindex <= bbot; bindex++)
19121 + if (au_hinode(iinfo, bindex)->hi_inode) {
19122 + iinfo->ii_btop = bindex;
19125 + if (iinfo->ii_btop >= 0)
19126 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19127 + if (au_hinode(iinfo, bindex)->hi_inode) {
19128 + iinfo->ii_bbot = bindex;
19131 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19134 +/* ---------------------------------------------------------------------- */
19136 +void au_icntnr_init_once(void *_c)
19138 + struct au_icntnr *c = _c;
19139 + struct au_iinfo *iinfo = &c->iinfo;
19141 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19142 + au_rw_init(&iinfo->ii_rwsem);
19143 + inode_init_once(&c->vfs_inode);
19146 +void au_hinode_init(struct au_hinode *hinode)
19148 + hinode->hi_inode = NULL;
19149 + hinode->hi_id = -1;
19150 + au_hn_init(hinode);
19151 + hinode->hi_whdentry = NULL;
19154 +int au_iinfo_init(struct inode *inode)
19156 + struct au_iinfo *iinfo;
19157 + struct super_block *sb;
19158 + struct au_hinode *hi;
19161 + sb = inode->i_sb;
19162 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19163 + nbr = au_sbbot(sb) + 1;
19164 + if (unlikely(nbr <= 0))
19166 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19168 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19170 + iinfo->ii_hinode = hi;
19171 + for (i = 0; i < nbr; i++, hi++)
19172 + au_hinode_init(hi);
19174 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19175 + iinfo->ii_btop = -1;
19176 + iinfo->ii_bbot = -1;
19177 + iinfo->ii_vdir = NULL;
19183 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19186 + struct au_hinode *hip;
19188 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19191 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19194 + iinfo->ii_hinode = hip;
19195 + i = iinfo->ii_bbot + 1;
19197 + for (; i < nbr; i++, hip++)
19198 + au_hinode_init(hip);
19205 +void au_iinfo_fin(struct inode *inode)
19207 + struct au_iinfo *iinfo;
19208 + struct au_hinode *hi;
19209 + struct super_block *sb;
19210 + aufs_bindex_t bindex, bbot;
19211 + const unsigned char unlinked = !inode->i_nlink;
19213 + AuDebugOn(au_is_bad_inode(inode));
19215 + sb = inode->i_sb;
19216 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19217 + if (si_pid_test(sb))
19218 + au_xino_delete_inode(inode, unlinked);
19221 + * it is safe to hide the dependency between sbinfo and
19225 + si_noflush_read_lock(sb);
19226 + au_xino_delete_inode(inode, unlinked);
19227 + si_read_unlock(sb);
19231 + iinfo = au_ii(inode);
19232 + if (iinfo->ii_vdir)
19233 + au_vdir_free(iinfo->ii_vdir);
19235 + bindex = iinfo->ii_btop;
19236 + if (bindex >= 0) {
19237 + hi = au_hinode(iinfo, bindex);
19238 + bbot = iinfo->ii_bbot;
19239 + while (bindex++ <= bbot) {
19240 + if (hi->hi_inode)
19245 + au_kfree_rcu(iinfo->ii_hinode);
19246 + AuRwDestroy(&iinfo->ii_rwsem);
19248 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19249 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19250 +++ linux/fs/aufs/inode.c 2022-03-21 14:49:05.726633010 +0100
19252 +// SPDX-License-Identifier: GPL-2.0
19254 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19256 + * This program, aufs is free software; you can redistribute it and/or modify
19257 + * it under the terms of the GNU General Public License as published by
19258 + * the Free Software Foundation; either version 2 of the License, or
19259 + * (at your option) any later version.
19261 + * This program is distributed in the hope that it will be useful,
19262 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19263 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19264 + * GNU General Public License for more details.
19266 + * You should have received a copy of the GNU General Public License
19267 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19271 + * inode functions
19274 +#include <linux/iversion.h>
19277 +struct inode *au_igrab(struct inode *inode)
19280 + AuDebugOn(!atomic_read(&inode->i_count));
19286 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19288 + au_cpup_attr_all(inode, /*force*/0);
19289 + au_update_iigen(inode, /*half*/1);
19291 + inode_inc_iversion(inode);
19294 +static int au_ii_refresh(struct inode *inode, int *update)
19298 + aufs_bindex_t bindex, new_bindex;
19299 + struct super_block *sb;
19300 + struct au_iinfo *iinfo;
19301 + struct au_hinode *p, *q, tmp;
19303 + AuDebugOn(au_is_bad_inode(inode));
19304 + IiMustWriteLock(inode);
19307 + sb = inode->i_sb;
19308 + nbr = au_sbbot(sb) + 1;
19309 + type = inode->i_mode & S_IFMT;
19310 + iinfo = au_ii(inode);
19311 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19312 + if (unlikely(err))
19315 + AuDebugOn(iinfo->ii_btop < 0);
19316 + p = au_hinode(iinfo, iinfo->ii_btop);
19317 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19319 + if (!p->hi_inode)
19322 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19323 + new_bindex = au_br_index(sb, p->hi_id);
19324 + if (new_bindex == bindex)
19327 + if (new_bindex < 0) {
19330 + p->hi_inode = NULL;
19334 + if (new_bindex < iinfo->ii_btop)
19335 + iinfo->ii_btop = new_bindex;
19336 + if (iinfo->ii_bbot < new_bindex)
19337 + iinfo->ii_bbot = new_bindex;
19338 + /* swap two lower inode, and loop again */
19339 + q = au_hinode(iinfo, new_bindex);
19343 + if (tmp.hi_inode) {
19348 + au_update_ibrange(inode, /*do_put_zero*/0);
19349 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19350 + e = au_dy_irefresh(inode);
19351 + if (unlikely(e && !err))
19359 +void au_refresh_iop(struct inode *inode, int force_getattr)
19362 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19363 + const struct inode_operations *iop
19364 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19366 + if (inode->i_op == iop)
19369 + switch (inode->i_mode & S_IFMT) {
19371 + type = AuIop_DIR;
19374 + type = AuIop_SYMLINK;
19377 + type = AuIop_OTHER;
19381 + inode->i_op = iop + type;
19382 + /* unnecessary smp_wmb() */
19385 +int au_refresh_hinode_self(struct inode *inode)
19389 + err = au_ii_refresh(inode, &update);
19391 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19397 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19399 + int err, e, update;
19400 + unsigned int flags;
19402 + aufs_bindex_t bindex, bbot;
19403 + unsigned char isdir;
19404 + struct au_hinode *p;
19405 + struct au_iinfo *iinfo;
19407 + err = au_ii_refresh(inode, &update);
19408 + if (unlikely(err))
19412 + iinfo = au_ii(inode);
19413 + p = au_hinode(iinfo, iinfo->ii_btop);
19414 + mode = (inode->i_mode & S_IFMT);
19415 + isdir = S_ISDIR(mode);
19416 + flags = au_hi_flags(inode, isdir);
19417 + bbot = au_dbbot(dentry);
19418 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19419 + struct inode *h_i, *h_inode;
19420 + struct dentry *h_d;
19422 + h_d = au_h_dptr(dentry, bindex);
19423 + if (!h_d || d_is_negative(h_d))
19426 + h_inode = d_inode(h_d);
19427 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19428 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19429 + h_i = au_h_iptr(inode, bindex);
19431 + if (h_i == h_inode)
19437 + if (bindex < iinfo->ii_btop)
19438 + iinfo->ii_btop = bindex;
19439 + if (iinfo->ii_bbot < bindex)
19440 + iinfo->ii_bbot = bindex;
19441 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19444 + au_update_ibrange(inode, /*do_put_zero*/0);
19445 + e = au_dy_irefresh(inode);
19446 + if (unlikely(e && !err))
19449 + au_refresh_hinode_attr(inode, update && isdir);
19456 +static int set_inode(struct inode *inode, struct dentry *dentry)
19459 + unsigned int flags;
19461 + aufs_bindex_t bindex, btop, btail;
19462 + unsigned char isdir;
19463 + struct dentry *h_dentry;
19464 + struct inode *h_inode;
19465 + struct au_iinfo *iinfo;
19466 + const struct inode_operations *iop;
19468 + IiMustWriteLock(inode);
19472 + iop = au_sbi(inode->i_sb)->si_iop_array;
19473 + btop = au_dbtop(dentry);
19474 + h_dentry = au_h_dptr(dentry, btop);
19475 + h_inode = d_inode(h_dentry);
19476 + mode = h_inode->i_mode;
19477 + switch (mode & S_IFMT) {
19479 + btail = au_dbtail(dentry);
19480 + inode->i_op = iop + AuIop_OTHER;
19481 + inode->i_fop = &aufs_file_fop;
19482 + err = au_dy_iaop(inode, btop, h_inode);
19483 + if (unlikely(err))
19488 + btail = au_dbtaildir(dentry);
19489 + inode->i_op = iop + AuIop_DIR;
19490 + inode->i_fop = &aufs_dir_fop;
19493 + btail = au_dbtail(dentry);
19494 + inode->i_op = iop + AuIop_SYMLINK;
19500 + btail = au_dbtail(dentry);
19501 + inode->i_op = iop + AuIop_OTHER;
19502 + init_special_inode(inode, mode, h_inode->i_rdev);
19505 + AuIOErr("Unknown file type 0%o\n", mode);
19510 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19511 + flags = au_hi_flags(inode, isdir);
19512 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19513 + && au_ftest_hi(flags, HNOTIFY)
19514 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19515 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19516 + au_fclr_hi(flags, HNOTIFY);
19517 + iinfo = au_ii(inode);
19518 + iinfo->ii_btop = btop;
19519 + iinfo->ii_bbot = btail;
19520 + for (bindex = btop; bindex <= btail; bindex++) {
19521 + h_dentry = au_h_dptr(dentry, bindex);
19523 + au_set_h_iptr(inode, bindex,
19524 + au_igrab(d_inode(h_dentry)), flags);
19526 + au_cpup_attr_all(inode, /*force*/1);
19528 + * to force calling aufs_get_acl() every time,
19529 + * do not call cache_no_acl() for aufs inode.
19537 + * successful returns with iinfo write_locked
19539 + * zero: success, matched
19540 + * plus: no error, but unmatched
19542 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19545 + unsigned int gen, igflags;
19546 + aufs_bindex_t bindex, bbot;
19547 + struct inode *h_inode, *h_dinode;
19548 + struct dentry *h_dentry;
19551 + * before this function, if aufs got any iinfo lock, it must be only
19552 + * one, the parent dir.
19553 + * it can happen by UDBA and the obsoleted inode number.
19556 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19560 + ii_write_lock_new_child(inode);
19561 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19562 + h_dinode = d_inode(h_dentry);
19563 + bbot = au_ibbot(inode);
19564 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19565 + h_inode = au_h_iptr(inode, bindex);
19566 + if (!h_inode || h_inode != h_dinode)
19570 + gen = au_iigen(inode, &igflags);
19571 + if (gen == au_digen(dentry)
19572 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19575 + /* fully refresh inode using dentry */
19576 + err = au_refresh_hinode(inode, dentry);
19578 + au_update_iigen(inode, /*half*/0);
19582 + if (unlikely(err))
19583 + ii_write_unlock(inode);
19588 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19589 + unsigned int d_type, ino_t *ino)
19592 + const int isnondir = d_type != DT_DIR;
19594 + /* prevent hardlinked inode number from race condition */
19596 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19597 + if (unlikely(err))
19601 + err = au_xino_read(sb, bindex, h_ino, ino);
19602 + if (unlikely(err))
19603 + goto out_xinondir;
19607 + *ino = au_xino_new_ino(sb);
19608 + if (unlikely(!*ino))
19609 + goto out_xinondir;
19610 + err = au_xino_write(sb, bindex, h_ino, *ino);
19611 + if (unlikely(err))
19612 + goto out_xinondir;
19616 + if (isnondir && idx >= 0)
19617 + au_xinondir_leave(sb, bindex, h_ino, idx);
19622 +/* successful returns with iinfo write_locked */
19623 +/* todo: return with unlocked? */
19624 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19626 + struct inode *inode, *h_inode;
19627 + struct dentry *h_dentry;
19628 + struct super_block *sb;
19629 + ino_t h_ino, ino;
19630 + int err, idx, hlinked;
19631 + aufs_bindex_t btop;
19633 + sb = dentry->d_sb;
19634 + btop = au_dbtop(dentry);
19635 + h_dentry = au_h_dptr(dentry, btop);
19636 + h_inode = d_inode(h_dentry);
19637 + h_ino = h_inode->i_ino;
19638 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19642 + * stop 'race'-ing between hardlinks under different
19646 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19647 + inode = ERR_PTR(err);
19648 + if (unlikely(err))
19652 + err = au_xino_read(sb, btop, h_ino, &ino);
19653 + inode = ERR_PTR(err);
19654 + if (unlikely(err))
19655 + goto out_xinondir;
19658 + ino = au_xino_new_ino(sb);
19659 + if (unlikely(!ino)) {
19660 + inode = ERR_PTR(-EIO);
19661 + goto out_xinondir;
19665 + AuDbg("i%lu\n", (unsigned long)ino);
19666 + inode = au_iget_locked(sb, ino);
19667 + err = PTR_ERR(inode);
19668 + if (IS_ERR(inode))
19669 + goto out_xinondir;
19671 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19672 + if (inode->i_state & I_NEW) {
19673 + ii_write_lock_new_child(inode);
19674 + err = set_inode(inode, dentry);
19676 + unlock_new_inode(inode);
19677 + goto out_xinondir; /* success */
19681 + * iget_failed() calls iput(), but we need to call
19682 + * ii_write_unlock() after iget_failed(). so dirty hack for
19685 + atomic_inc(&inode->i_count);
19686 + iget_failed(inode);
19687 + ii_write_unlock(inode);
19688 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19689 + /* ignore this error */
19691 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19693 + * horrible race condition between lookup, readdir and copyup
19694 + * (or something).
19696 + if (hlinked && idx >= 0)
19697 + au_xinondir_leave(sb, btop, h_ino, idx);
19698 + err = reval_inode(inode, dentry);
19699 + if (unlikely(err < 0)) {
19704 + goto out; /* success */
19705 + else if (hlinked && idx >= 0) {
19706 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19707 + if (unlikely(err)) {
19709 + inode = ERR_PTR(err);
19715 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19716 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19717 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19718 + btop, au_sbtype(h_dentry->d_sb), dentry,
19719 + (unsigned long)h_ino, (unsigned long)ino);
19721 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19724 + if (hlinked && idx >= 0)
19725 + au_xinondir_leave(sb, btop, h_ino, idx);
19731 + inode = ERR_PTR(err);
19733 + if (hlinked && idx >= 0)
19734 + au_xinondir_leave(sb, btop, h_ino, idx);
19739 +/* ---------------------------------------------------------------------- */
19741 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19742 + struct inode *inode)
19745 + struct inode *hi;
19747 + err = au_br_rdonly(au_sbr(sb, bindex));
19749 + /* pseudo-link after flushed may happen out of bounds */
19752 + && au_ibtop(inode) <= bindex
19753 + && bindex <= au_ibbot(inode)) {
19755 + * permission check is unnecessary since vfsub routine
19756 + * will be called later
19758 + hi = au_h_iptr(inode, bindex);
19760 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19766 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19769 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19771 + return inode_permission(h_userns, h_inode, mask);
19774 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19777 + if (au_test_nfs(h_inode->i_sb)
19778 + && (mask & MAY_WRITE)
19779 + && S_ISDIR(h_inode->i_mode))
19780 + mask |= MAY_READ; /* force permission check */
19781 + return au_test_h_perm(h_userns, h_inode, mask);
19783 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19784 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19785 +++ linux/fs/aufs/inode.h 2022-03-21 14:49:05.726633010 +0100
19787 +/* SPDX-License-Identifier: GPL-2.0 */
19789 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19791 + * This program, aufs is free software; you can redistribute it and/or modify
19792 + * it under the terms of the GNU General Public License as published by
19793 + * the Free Software Foundation; either version 2 of the License, or
19794 + * (at your option) any later version.
19796 + * This program is distributed in the hope that it will be useful,
19797 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19798 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19799 + * GNU General Public License for more details.
19801 + * You should have received a copy of the GNU General Public License
19802 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19806 + * inode operations
19809 +#ifndef __AUFS_INODE_H__
19810 +#define __AUFS_INODE_H__
19814 +#include <linux/fsnotify.h>
19815 +#include "rwsem.h"
19819 +struct au_hnotify {
19820 +#ifdef CONFIG_AUFS_HNOTIFY
19821 +#ifdef CONFIG_AUFS_HFSNOTIFY
19822 + /* never use fsnotify_add_vfsmount_mark() */
19823 + struct fsnotify_mark hn_mark;
19825 + struct inode *hn_aufs_inode; /* no get/put */
19826 + struct rcu_head rcu;
19828 +} ____cacheline_aligned_in_smp;
19830 +struct au_hinode {
19831 + struct inode *hi_inode;
19832 + aufs_bindex_t hi_id;
19833 +#ifdef CONFIG_AUFS_HNOTIFY
19834 + struct au_hnotify *hi_notify;
19837 + /* reference to the copied-up whiteout with get/put */
19838 + struct dentry *hi_whdentry;
19842 +#define AuIG_HALF_REFRESHED 1
19843 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19844 +#define au_ig_fset(flags, name) \
19845 + do { (flags) |= AuIG_##name; } while (0)
19846 +#define au_ig_fclr(flags, name) \
19847 + do { (flags) &= ~AuIG_##name; } while (0)
19850 + spinlock_t ig_spin;
19851 + __u32 ig_generation, ig_flags;
19856 + struct au_iigen ii_generation;
19857 + struct super_block *ii_hsb1; /* no get/put */
19859 + struct au_rwsem ii_rwsem;
19860 + aufs_bindex_t ii_btop, ii_bbot;
19862 + struct au_hinode *ii_hinode;
19863 + struct au_vdir *ii_vdir;
19866 +struct au_icntnr {
19867 + struct au_iinfo iinfo;
19868 + struct inode vfs_inode;
19869 + struct hlist_bl_node plink;
19870 + struct rcu_head rcu;
19871 +} ____cacheline_aligned_in_smp;
19873 +/* au_pin flags */
19874 +#define AuPin_DI_LOCKED 1
19875 +#define AuPin_MNT_WRITE (1 << 1)
19876 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19877 +#define au_fset_pin(flags, name) \
19878 + do { (flags) |= AuPin_##name; } while (0)
19879 +#define au_fclr_pin(flags, name) \
19880 + do { (flags) &= ~AuPin_##name; } while (0)
19884 + struct dentry *dentry;
19885 + unsigned int udba;
19886 + unsigned char lsc_di, lsc_hi, flags;
19887 + aufs_bindex_t bindex;
19890 + struct dentry *parent;
19891 + struct au_hinode *hdir;
19892 + struct vfsmount *h_mnt;
19894 + /* temporary unlock/relock for copyup */
19895 + struct dentry *h_dentry, *h_parent;
19896 + struct au_branch *br;
19897 + struct task_struct *task;
19900 +void au_pin_hdir_unlock(struct au_pin *p);
19901 +int au_pin_hdir_lock(struct au_pin *p);
19902 +int au_pin_hdir_relock(struct au_pin *p);
19903 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19904 +void au_pin_hdir_release(struct au_pin *p);
19906 +/* ---------------------------------------------------------------------- */
19908 +static inline struct au_iinfo *au_ii(struct inode *inode)
19910 + BUG_ON(is_bad_inode(inode));
19911 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19914 +/* ---------------------------------------------------------------------- */
19917 +struct inode *au_igrab(struct inode *inode);
19918 +void au_refresh_iop(struct inode *inode, int force_getattr);
19919 +int au_refresh_hinode_self(struct inode *inode);
19920 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19921 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19922 + unsigned int d_type, ino_t *ino);
19923 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19924 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19925 + struct inode *inode);
19926 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19928 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19931 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19932 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19934 +#ifdef CONFIG_AUFS_SHWH
19935 + return au_ino(sb, bindex, h_ino, d_type, ino);
19948 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19949 + aufs_iop_nogetattr[AuIop_Last];
19951 +/* au_wr_dir flags */
19952 +#define AuWrDir_ADD_ENTRY 1
19953 +#define AuWrDir_ISDIR (1 << 1)
19954 +#define AuWrDir_TMPFILE (1 << 2)
19955 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19956 +#define au_fset_wrdir(flags, name) \
19957 + do { (flags) |= AuWrDir_##name; } while (0)
19958 +#define au_fclr_wrdir(flags, name) \
19959 + do { (flags) &= ~AuWrDir_##name; } while (0)
19961 +struct au_wr_dir_args {
19962 + aufs_bindex_t force_btgt;
19963 + unsigned char flags;
19965 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19966 + struct au_wr_dir_args *args);
19968 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
19969 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
19970 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19971 + unsigned int udba, unsigned char flags);
19972 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19973 + unsigned int udba, unsigned char flags) __must_check;
19974 +int au_do_pin(struct au_pin *pin) __must_check;
19975 +void au_unpin(struct au_pin *pin);
19976 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
19978 +#define AuIcpup_DID_CPUP 1
19979 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
19980 +#define au_fset_icpup(flags, name) \
19981 + do { (flags) |= AuIcpup_##name; } while (0)
19982 +#define au_fclr_icpup(flags, name) \
19983 + do { (flags) &= ~AuIcpup_##name; } while (0)
19985 +struct au_icpup_args {
19986 + unsigned char flags;
19987 + unsigned char pin_flags;
19988 + aufs_bindex_t btgt;
19989 + unsigned int udba;
19990 + struct au_pin pin;
19991 + struct path h_path;
19992 + struct inode *h_inode;
19995 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19996 + struct au_icpup_args *a);
19998 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
19999 + struct path *h_path, int locked);
20002 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20003 + struct dentry *h_parent, int isdir);
20004 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
20005 + struct dentry *dentry, umode_t mode, dev_t dev);
20006 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
20007 + struct dentry *dentry, const char *symname);
20008 +int aufs_create(struct user_namespace *userns, struct inode *dir,
20009 + struct dentry *dentry, umode_t mode, bool want_excl);
20010 +struct vfsub_aopen_args;
20011 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20012 + struct vfsub_aopen_args *args);
20013 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
20014 + struct dentry *dentry, umode_t mode);
20015 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20016 + struct dentry *dentry);
20017 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20018 + struct dentry *dentry, umode_t mode);
20021 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20022 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20023 + struct dentry *h_parent, int isdir);
20024 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20025 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20028 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20029 +int aufs_rename(struct user_namespace *userns,
20030 + struct inode *_src_dir, struct dentry *_src_dentry,
20031 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20032 + unsigned int _flags);
20035 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20036 +void au_hiput(struct au_hinode *hinode);
20037 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20038 + struct dentry *h_wh);
20039 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20041 +/* hinode flags */
20042 +#define AuHi_XINO 1
20043 +#define AuHi_HNOTIFY (1 << 1)
20044 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20045 +#define au_fset_hi(flags, name) \
20046 + do { (flags) |= AuHi_##name; } while (0)
20047 +#define au_fclr_hi(flags, name) \
20048 + do { (flags) &= ~AuHi_##name; } while (0)
20050 +#ifndef CONFIG_AUFS_HNOTIFY
20051 +#undef AuHi_HNOTIFY
20052 +#define AuHi_HNOTIFY 0
20055 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20056 + struct inode *h_inode, unsigned int flags);
20058 +void au_update_iigen(struct inode *inode, int half);
20059 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20061 +void au_icntnr_init_once(void *_c);
20062 +void au_hinode_init(struct au_hinode *hinode);
20063 +int au_iinfo_init(struct inode *inode);
20064 +void au_iinfo_fin(struct inode *inode);
20065 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20067 +#ifdef CONFIG_PROC_FS
20069 +int au_plink_maint(struct super_block *sb, int flags);
20071 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20072 +int au_plink_maint_enter(struct super_block *sb);
20073 +#ifdef CONFIG_AUFS_DEBUG
20074 +void au_plink_list(struct super_block *sb);
20076 +AuStubVoid(au_plink_list, struct super_block *sb)
20078 +int au_plink_test(struct inode *inode);
20079 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20080 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20081 + struct dentry *h_dentry);
20082 +void au_plink_put(struct super_block *sb, int verbose);
20083 +void au_plink_clean(struct super_block *sb, int verbose);
20084 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20086 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20087 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20088 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20089 +AuStubVoid(au_plink_list, struct super_block *sb);
20090 +AuStubInt0(au_plink_test, struct inode *inode);
20091 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20092 + struct inode *inode, aufs_bindex_t bindex);
20093 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20094 + struct dentry *h_dentry);
20095 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20096 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20097 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20098 +#endif /* CONFIG_PROC_FS */
20100 +#ifdef CONFIG_AUFS_XATTR
20102 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20103 + unsigned int verbose);
20104 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20105 +void au_xattr_init(struct super_block *sb);
20107 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20108 + int ignore_flags, unsigned int verbose);
20109 +AuStubVoid(au_xattr_init, struct super_block *sb);
20112 +#ifdef CONFIG_FS_POSIX_ACL
20113 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
20114 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
20115 + struct posix_acl *acl, int type);
20118 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20124 +struct au_sxattr {
20128 + const char *name;
20129 + const void *value;
20134 + struct posix_acl *acl;
20139 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20140 + struct au_sxattr *arg);
20143 +/* ---------------------------------------------------------------------- */
20145 +/* lock subclass for iinfo */
20147 + AuLsc_II_CHILD, /* child first */
20148 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20149 + AuLsc_II_CHILD3, /* copyup dirs */
20150 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20151 + AuLsc_II_PARENT2,
20152 + AuLsc_II_PARENT3, /* copyup dirs */
20153 + AuLsc_II_NEW_CHILD
20157 + * ii_read_lock_child, ii_write_lock_child,
20158 + * ii_read_lock_child2, ii_write_lock_child2,
20159 + * ii_read_lock_child3, ii_write_lock_child3,
20160 + * ii_read_lock_parent, ii_write_lock_parent,
20161 + * ii_read_lock_parent2, ii_write_lock_parent2,
20162 + * ii_read_lock_parent3, ii_write_lock_parent3,
20163 + * ii_read_lock_new_child, ii_write_lock_new_child,
20165 +#define AuReadLockFunc(name, lsc) \
20166 +static inline void ii_read_lock_##name(struct inode *i) \
20168 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20171 +#define AuWriteLockFunc(name, lsc) \
20172 +static inline void ii_write_lock_##name(struct inode *i) \
20174 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20177 +#define AuRWLockFuncs(name, lsc) \
20178 + AuReadLockFunc(name, lsc) \
20179 + AuWriteLockFunc(name, lsc)
20181 +AuRWLockFuncs(child, CHILD);
20182 +AuRWLockFuncs(child2, CHILD2);
20183 +AuRWLockFuncs(child3, CHILD3);
20184 +AuRWLockFuncs(parent, PARENT);
20185 +AuRWLockFuncs(parent2, PARENT2);
20186 +AuRWLockFuncs(parent3, PARENT3);
20187 +AuRWLockFuncs(new_child, NEW_CHILD);
20189 +#undef AuReadLockFunc
20190 +#undef AuWriteLockFunc
20191 +#undef AuRWLockFuncs
20193 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20194 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20195 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20197 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20198 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20199 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20201 +/* ---------------------------------------------------------------------- */
20203 +static inline void au_icntnr_init(struct au_icntnr *c)
20205 +#ifdef CONFIG_AUFS_DEBUG
20206 + c->vfs_inode.i_mode = 0;
20210 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20212 + unsigned int gen;
20213 + struct au_iinfo *iinfo;
20214 + struct au_iigen *iigen;
20216 + iinfo = au_ii(inode);
20217 + iigen = &iinfo->ii_generation;
20218 + spin_lock(&iigen->ig_spin);
20220 + *igflags = iigen->ig_flags;
20221 + gen = iigen->ig_generation;
20222 + spin_unlock(&iigen->ig_spin);
20227 +/* tiny test for inode number */
20228 +/* tmpfs generation is too rough */
20229 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20231 + struct au_iinfo *iinfo;
20233 + iinfo = au_ii(inode);
20234 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20235 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20236 + && iinfo->ii_higen == h_inode->i_generation);
20239 +static inline void au_iigen_dec(struct inode *inode)
20241 + struct au_iinfo *iinfo;
20242 + struct au_iigen *iigen;
20244 + iinfo = au_ii(inode);
20245 + iigen = &iinfo->ii_generation;
20246 + spin_lock(&iigen->ig_spin);
20247 + iigen->ig_generation--;
20248 + spin_unlock(&iigen->ig_spin);
20251 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20256 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20262 +/* ---------------------------------------------------------------------- */
20264 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20265 + aufs_bindex_t bindex)
20267 + return iinfo->ii_hinode + bindex;
20270 +static inline int au_is_bad_inode(struct inode *inode)
20272 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20275 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20276 + aufs_bindex_t bindex)
20278 + IiMustAnyLock(inode);
20279 + return au_hinode(au_ii(inode), bindex)->hi_id;
20282 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20284 + IiMustAnyLock(inode);
20285 + return au_ii(inode)->ii_btop;
20288 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20290 + IiMustAnyLock(inode);
20291 + return au_ii(inode)->ii_bbot;
20294 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20296 + IiMustAnyLock(inode);
20297 + return au_ii(inode)->ii_vdir;
20300 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20302 + IiMustAnyLock(inode);
20303 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20306 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20308 + IiMustWriteLock(inode);
20309 + au_ii(inode)->ii_btop = bindex;
20312 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20314 + IiMustWriteLock(inode);
20315 + au_ii(inode)->ii_bbot = bindex;
20318 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20320 + IiMustWriteLock(inode);
20321 + au_ii(inode)->ii_vdir = vdir;
20324 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20326 + IiMustAnyLock(inode);
20327 + return au_hinode(au_ii(inode), bindex);
20330 +/* ---------------------------------------------------------------------- */
20332 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20335 + return pin->parent;
20339 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20341 + if (pin && pin->hdir)
20342 + return pin->hdir->hi_inode;
20346 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20349 + return pin->hdir;
20353 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20356 + pin->dentry = dentry;
20359 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20360 + unsigned char lflag)
20364 + au_fset_pin(pin->flags, DI_LOCKED);
20366 + au_fclr_pin(pin->flags, DI_LOCKED);
20370 +#if 0 /* reserved */
20371 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20374 + dput(pin->parent);
20375 + pin->parent = dget(parent);
20380 +/* ---------------------------------------------------------------------- */
20383 +#ifdef CONFIG_AUFS_HNOTIFY
20384 +struct au_hnotify_op {
20385 + void (*ctl)(struct au_hinode *hinode, int do_set);
20386 + int (*alloc)(struct au_hinode *hinode);
20389 + * if it returns true, the caller should free hinode->hi_notify,
20390 + * otherwise ->free() frees it.
20392 + int (*free)(struct au_hinode *hinode,
20393 + struct au_hnotify *hn) __must_check;
20395 + void (*fin)(void);
20396 + int (*init)(void);
20398 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20399 + void (*fin_br)(struct au_branch *br);
20400 + int (*init_br)(struct au_branch *br, int perm);
20404 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20405 +void au_hn_free(struct au_hinode *hinode);
20406 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20407 +void au_hn_reset(struct inode *inode, unsigned int flags);
20408 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20409 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20410 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20411 +int au_hnotify_init_br(struct au_branch *br, int perm);
20412 +void au_hnotify_fin_br(struct au_branch *br);
20413 +int __init au_hnotify_init(void);
20414 +void au_hnotify_fin(void);
20417 +extern const struct au_hnotify_op au_hnotify_op;
20420 +void au_hn_init(struct au_hinode *hinode)
20422 + hinode->hi_notify = NULL;
20425 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20427 + return hinode->hi_notify;
20431 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20432 + struct au_hinode *hinode __maybe_unused,
20433 + struct inode *inode __maybe_unused)
20434 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20435 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20436 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20437 + int do_set __maybe_unused)
20438 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20439 + unsigned int flags __maybe_unused)
20440 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20441 + struct au_branch *br __maybe_unused,
20442 + int perm __maybe_unused)
20443 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20444 + int perm __maybe_unused)
20445 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20446 +AuStubInt0(__init au_hnotify_init, void)
20447 +AuStubVoid(au_hnotify_fin, void)
20448 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20449 +#endif /* CONFIG_AUFS_HNOTIFY */
20451 +static inline void au_hn_suspend(struct au_hinode *hdir)
20453 + au_hn_ctl(hdir, /*do_set*/0);
20456 +static inline void au_hn_resume(struct au_hinode *hdir)
20458 + au_hn_ctl(hdir, /*do_set*/1);
20461 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20463 + inode_lock(hdir->hi_inode);
20464 + au_hn_suspend(hdir);
20467 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20468 + unsigned int sc __maybe_unused)
20470 + inode_lock_nested(hdir->hi_inode, sc);
20471 + au_hn_suspend(hdir);
20474 +#if 0 /* unused */
20475 +#include "vfsub.h"
20476 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20479 + inode_lock_shared_nested(hdir->hi_inode, sc);
20480 + au_hn_suspend(hdir);
20484 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20486 + au_hn_resume(hdir);
20487 + inode_unlock(hdir->hi_inode);
20490 +#endif /* __KERNEL__ */
20491 +#endif /* __AUFS_INODE_H__ */
20492 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20493 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20494 +++ linux/fs/aufs/ioctl.c 2022-03-21 14:49:05.726633010 +0100
20496 +// SPDX-License-Identifier: GPL-2.0
20498 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20500 + * This program, aufs is free software; you can redistribute it and/or modify
20501 + * it under the terms of the GNU General Public License as published by
20502 + * the Free Software Foundation; either version 2 of the License, or
20503 + * (at your option) any later version.
20505 + * This program is distributed in the hope that it will be useful,
20506 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20508 + * GNU General Public License for more details.
20510 + * You should have received a copy of the GNU General Public License
20511 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20516 + * plink-management and readdir in userspace.
20517 + * assist the pathconf(3) wrapper library.
20519 + * File-based Hierarchical Storage Management.
20522 +#include <linux/compat.h>
20523 +#include <linux/file.h>
20526 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20529 + aufs_bindex_t wbi, bindex, bbot;
20530 + struct file *h_file;
20531 + struct super_block *sb;
20532 + struct dentry *root;
20533 + struct au_branch *br;
20534 + struct aufs_wbr_fd wbrfd = {
20535 + .oflags = au_dir_roflags,
20538 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20539 + | O_NOATIME | O_CLOEXEC;
20541 + AuDebugOn(wbrfd.oflags & ~valid);
20544 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20545 + if (unlikely(err)) {
20551 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20552 + wbrfd.oflags |= au_dir_roflags;
20553 + AuDbg("0%o\n", wbrfd.oflags);
20554 + if (unlikely(wbrfd.oflags & ~valid))
20558 + fd = get_unused_fd_flags(0);
20560 + if (unlikely(fd < 0))
20563 + h_file = ERR_PTR(-EINVAL);
20566 + sb = path->dentry->d_sb;
20567 + root = sb->s_root;
20568 + aufs_read_lock(root, AuLock_IR);
20569 + bbot = au_sbbot(sb);
20570 + if (wbrfd.brid >= 0) {
20571 + wbi = au_br_index(sb, wbrfd.brid);
20572 + if (unlikely(wbi < 0 || wbi > bbot))
20576 + h_file = ERR_PTR(-ENOENT);
20577 + br = au_sbr(sb, wbi);
20578 + if (!au_br_writable(br->br_perm)) {
20582 + bindex = wbi + 1;
20584 + for (; bindex <= bbot; bindex++) {
20585 + br = au_sbr(sb, bindex);
20586 + if (au_br_writable(br->br_perm)) {
20588 + br = au_sbr(sb, wbi);
20593 + AuDbg("wbi %d\n", wbi);
20595 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20599 + aufs_read_unlock(root, AuLock_IR);
20600 + err = PTR_ERR(h_file);
20601 + if (IS_ERR(h_file))
20604 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20605 + fd_install(fd, h_file);
20607 + goto out; /* success */
20610 + put_unused_fd(fd);
20616 +/* ---------------------------------------------------------------------- */
20618 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20621 + struct dentry *dentry;
20624 + case AUFS_CTL_RDU:
20625 + case AUFS_CTL_RDU_INO:
20626 + err = au_rdu_ioctl(file, cmd, arg);
20629 + case AUFS_CTL_WBR_FD:
20630 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20633 + case AUFS_CTL_IBUSY:
20634 + err = au_ibusy_ioctl(file, arg);
20637 + case AUFS_CTL_BRINFO:
20638 + err = au_brinfo_ioctl(file, arg);
20641 + case AUFS_CTL_FHSM_FD:
20642 + dentry = file->f_path.dentry;
20643 + if (IS_ROOT(dentry))
20644 + err = au_fhsm_fd(dentry->d_sb, arg);
20650 + /* do not call the lower */
20651 + AuDbg("0x%x\n", cmd);
20659 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20664 + case AUFS_CTL_MVDOWN:
20665 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20668 + case AUFS_CTL_WBR_FD:
20669 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20673 + /* do not call the lower */
20674 + AuDbg("0x%x\n", cmd);
20682 +#ifdef CONFIG_COMPAT
20683 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20684 + unsigned long arg)
20689 + case AUFS_CTL_RDU:
20690 + case AUFS_CTL_RDU_INO:
20691 + err = au_rdu_compat_ioctl(file, cmd, arg);
20694 + case AUFS_CTL_IBUSY:
20695 + err = au_ibusy_compat_ioctl(file, arg);
20698 + case AUFS_CTL_BRINFO:
20699 + err = au_brinfo_compat_ioctl(file, arg);
20703 + err = aufs_ioctl_dir(file, cmd, arg);
20710 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20711 + unsigned long arg)
20713 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20716 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20717 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20718 +++ linux/fs/aufs/i_op_add.c 2022-03-21 14:49:05.726633010 +0100
20720 +// SPDX-License-Identifier: GPL-2.0
20722 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20724 + * This program, aufs is free software; you can redistribute it and/or modify
20725 + * it under the terms of the GNU General Public License as published by
20726 + * the Free Software Foundation; either version 2 of the License, or
20727 + * (at your option) any later version.
20729 + * This program is distributed in the hope that it will be useful,
20730 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20731 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20732 + * GNU General Public License for more details.
20734 + * You should have received a copy of the GNU General Public License
20735 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20739 + * inode operations (add entry)
20742 +#include <linux/iversion.h>
20746 + * final procedure of adding a new entry, except link(2).
20747 + * remove whiteout, instantiate, copyup the parent dir's times and size
20748 + * and update version.
20749 + * if it failed, re-create the removed whiteout.
20751 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20752 + struct dentry *wh_dentry, struct dentry *dentry)
20755 + aufs_bindex_t bwh;
20756 + struct path h_path;
20757 + struct super_block *sb;
20758 + struct inode *inode, *h_dir;
20759 + struct dentry *wh;
20764 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20765 + IMustLock(h_dir);
20766 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20767 + bwh = au_dbwh(dentry);
20768 + h_path.dentry = wh_dentry;
20769 + h_path.mnt = au_sbr_mnt(sb, bindex);
20770 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20772 + if (unlikely(err))
20776 + inode = au_new_inode(dentry, /*must_new*/1);
20777 + if (!IS_ERR(inode)) {
20778 + d_instantiate(dentry, inode);
20779 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20781 + au_dir_ts(dir, bindex);
20782 + inode_inc_iversion(dir);
20783 + au_fhsm_wrote(sb, bindex, /*force*/0);
20784 + return 0; /* success */
20787 + err = PTR_ERR(inode);
20792 + /* dir inode is locked */
20793 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20794 + rerr = PTR_ERR(wh);
20795 + if (IS_ERR(wh)) {
20796 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20797 + dentry, err, rerr);
20806 +static int au_d_may_add(struct dentry *dentry)
20811 + if (unlikely(d_unhashed(dentry)))
20813 + if (unlikely(d_really_is_positive(dentry)))
20819 + * simple tests for the adding inode operations.
20820 + * following the checks in vfs, plus the parent-child relationship.
20822 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20823 + struct dentry *h_parent, int isdir)
20827 + struct dentry *h_dentry;
20828 + struct inode *h_inode;
20830 + err = -ENAMETOOLONG;
20831 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20834 + h_dentry = au_h_dptr(dentry, bindex);
20835 + if (d_really_is_negative(dentry)) {
20837 + if (unlikely(d_is_positive(h_dentry)))
20840 + /* rename(2) case */
20842 + if (unlikely(d_is_negative(h_dentry)))
20844 + h_inode = d_inode(h_dentry);
20845 + if (unlikely(!h_inode->i_nlink))
20848 + h_mode = h_inode->i_mode;
20851 + if (unlikely(S_ISDIR(h_mode)))
20853 + } else if (unlikely(!S_ISDIR(h_mode))) {
20860 + /* expected parent dir is locked */
20861 + if (unlikely(h_parent != h_dentry->d_parent))
20870 + * initial procedure of adding a new entry.
20871 + * prepare writable branch and the parent dir, lock it,
20872 + * and lookup whiteout for the new entry.
20874 +static struct dentry*
20875 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20876 + struct dentry *src_dentry, struct au_pin *pin,
20877 + struct au_wr_dir_args *wr_dir_args)
20879 + struct dentry *wh_dentry, *h_parent;
20880 + struct super_block *sb;
20881 + struct au_branch *br;
20883 + unsigned int udba;
20884 + aufs_bindex_t bcpup;
20886 + AuDbg("%pd\n", dentry);
20888 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20890 + wh_dentry = ERR_PTR(err);
20891 + if (unlikely(err < 0))
20894 + sb = dentry->d_sb;
20895 + udba = au_opt_udba(sb);
20896 + err = au_pin(pin, dentry, bcpup, udba,
20897 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20898 + wh_dentry = ERR_PTR(err);
20899 + if (unlikely(err))
20902 + h_parent = au_pinned_h_parent(pin);
20903 + if (udba != AuOpt_UDBA_NONE
20904 + && au_dbtop(dentry) == bcpup)
20905 + err = au_may_add(dentry, bcpup, h_parent,
20906 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20907 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20908 + err = -ENAMETOOLONG;
20909 + wh_dentry = ERR_PTR(err);
20910 + if (unlikely(err))
20913 + br = au_sbr(sb, bcpup);
20915 + struct path tmp = {
20916 + .dentry = h_parent,
20917 + .mnt = au_br_mnt(br)
20919 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20922 + wh_dentry = NULL;
20923 + if (bcpup != au_dbwh(dentry))
20924 + goto out; /* success */
20927 + * ENAMETOOLONG here means that if we allowed create such name, then it
20928 + * would not be able to removed in the future. So we don't allow such
20929 + * name here and we don't handle ENAMETOOLONG differently here.
20931 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20934 + if (IS_ERR(wh_dentry))
20937 + return wh_dentry;
20940 +/* ---------------------------------------------------------------------- */
20942 +enum { Mknod, Symlink, Creat };
20943 +struct simple_arg {
20950 + struct vfsub_aopen_args *aopen;
20953 + const char *symname;
20962 +static int add_simple(struct inode *dir, struct dentry *dentry,
20963 + struct simple_arg *arg)
20966 + aufs_bindex_t btop;
20967 + unsigned char created;
20968 + const unsigned char try_aopen
20969 + = (arg->type == Creat && arg->u.c.try_aopen);
20970 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
20971 + struct dentry *wh_dentry, *parent;
20972 + struct inode *h_dir;
20973 + struct super_block *sb;
20974 + struct au_branch *br;
20975 + /* to reduce stack size */
20977 + struct au_dtime dt;
20978 + struct au_pin pin;
20979 + struct path h_path;
20980 + struct au_wr_dir_args wr_dir_args;
20983 + AuDbg("%pd\n", dentry);
20987 + a = kmalloc(sizeof(*a), GFP_NOFS);
20988 + if (unlikely(!a))
20990 + a->wr_dir_args.force_btgt = -1;
20991 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
20993 + parent = dentry->d_parent; /* dir inode is locked */
20994 + if (!try_aopen) {
20995 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20996 + if (unlikely(err))
20999 + err = au_d_may_add(dentry);
21000 + if (unlikely(err))
21003 + di_write_lock_parent(parent);
21004 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21005 + &a->pin, &a->wr_dir_args);
21006 + err = PTR_ERR(wh_dentry);
21007 + if (IS_ERR(wh_dentry))
21010 + btop = au_dbtop(dentry);
21011 + sb = dentry->d_sb;
21012 + br = au_sbr(sb, btop);
21013 + a->h_path.dentry = au_h_dptr(dentry, btop);
21014 + a->h_path.mnt = au_br_mnt(br);
21015 + h_dir = au_pinned_h_dir(&a->pin);
21016 + switch (arg->type) {
21018 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21019 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21020 + arg->u.c.want_excl);
21022 + if (!err && try_aopen)
21023 + aopen->file->f_mode |= FMODE_CREATED;
21026 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21027 + AuDbg("err %d\n", err);
21028 + AuDbgFile(aopen->file);
21029 + created = err >= 0
21030 + && !!(aopen->file->f_mode & FMODE_CREATED);
21034 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21038 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21045 + if (unlikely(err < 0))
21048 + err = epilog(dir, btop, wh_dentry, dentry);
21050 + goto out_unpin; /* success */
21053 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21054 + /* no delegation since it is just created */
21055 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21058 + AuIOErr("%pd revert failure(%d, %d)\n",
21059 + dentry, err, rerr);
21062 + au_dtime_revert(&a->dt);
21064 + if (try_aopen && h_dir->i_op->atomic_open
21065 + && (aopen->file->f_mode & FMODE_OPENED))
21066 + /* aopen->file is still opened */
21067 + au_lcnt_dec(&aopen->br->br_nfiles);
21070 + au_unpin(&a->pin);
21074 + di_write_unlock(parent);
21076 + if (unlikely(err)) {
21077 + au_update_dbtop(dentry);
21081 + aufs_read_unlock(dentry, AuLock_DW);
21088 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
21089 + struct dentry *dentry, umode_t mode, dev_t dev)
21091 + struct simple_arg arg = {
21098 + return add_simple(dir, dentry, &arg);
21101 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
21102 + struct dentry *dentry, const char *symname)
21104 + struct simple_arg arg = {
21106 + .u.s.symname = symname
21108 + return add_simple(dir, dentry, &arg);
21111 +int aufs_create(struct user_namespace *userns, struct inode *dir,
21112 + struct dentry *dentry, umode_t mode, bool want_excl)
21114 + struct simple_arg arg = {
21118 + .want_excl = want_excl
21121 + return add_simple(dir, dentry, &arg);
21124 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21125 + struct vfsub_aopen_args *aopen_args)
21127 + struct simple_arg arg = {
21130 + .mode = aopen_args->create_mode,
21131 + .want_excl = aopen_args->open_flag & O_EXCL,
21132 + .try_aopen = true,
21133 + .aopen = aopen_args
21136 + return add_simple(dir, dentry, &arg);
21139 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
21140 + struct dentry *dentry, umode_t mode)
21143 + aufs_bindex_t bindex;
21144 + struct super_block *sb;
21145 + struct dentry *parent, *h_parent, *h_dentry;
21146 + struct inode *h_dir, *inode;
21147 + struct vfsmount *h_mnt;
21148 + struct user_namespace *h_userns;
21149 + struct au_wr_dir_args wr_dir_args = {
21150 + .force_btgt = -1,
21151 + .flags = AuWrDir_TMPFILE
21154 + /* copy-up may happen */
21158 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21159 + if (unlikely(err))
21162 + err = au_di_init(dentry);
21163 + if (unlikely(err))
21167 + parent = d_find_any_alias(dir);
21168 + AuDebugOn(!parent);
21169 + di_write_lock_parent(parent);
21170 + if (unlikely(d_inode(parent) != dir))
21173 + err = au_digen_test(parent, au_sigen(sb));
21174 + if (unlikely(err))
21177 + bindex = au_dbtop(parent);
21178 + au_set_dbtop(dentry, bindex);
21179 + au_set_dbbot(dentry, bindex);
21180 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21182 + if (unlikely(err < 0))
21185 + err = -EOPNOTSUPP;
21186 + h_dir = au_h_iptr(dir, bindex);
21187 + if (unlikely(!h_dir->i_op->tmpfile))
21190 + h_mnt = au_sbr_mnt(sb, bindex);
21191 + err = vfsub_mnt_want_write(h_mnt);
21192 + if (unlikely(err))
21195 + h_userns = mnt_user_ns(h_mnt);
21196 + h_parent = au_h_dptr(parent, bindex);
21197 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
21198 + if (IS_ERR(h_dentry)) {
21199 + err = PTR_ERR(h_dentry);
21203 + au_set_dbtop(dentry, bindex);
21204 + au_set_dbbot(dentry, bindex);
21205 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21206 + inode = au_new_inode(dentry, /*must_new*/1);
21207 + if (IS_ERR(inode)) {
21208 + err = PTR_ERR(inode);
21209 + au_set_h_dptr(dentry, bindex, NULL);
21210 + au_set_dbtop(dentry, -1);
21211 + au_set_dbbot(dentry, -1);
21213 + if (!inode->i_nlink)
21214 + set_nlink(inode, 1);
21215 + d_tmpfile(dentry, inode);
21216 + au_di(dentry)->di_tmpfile = 1;
21218 + /* update without i_mutex */
21219 + if (au_ibtop(dir) == au_dbtop(dentry))
21220 + au_cpup_attr_timesizes(dir);
21225 + vfsub_mnt_drop_write(h_mnt);
21227 + di_write_unlock(parent);
21229 + di_write_unlock(dentry);
21230 + if (unlikely(err)) {
21231 + au_di_fin(dentry);
21232 + dentry->d_fsdata = NULL;
21235 + si_read_unlock(sb);
21237 + inode_unlock(dir);
21241 +/* ---------------------------------------------------------------------- */
21243 +struct au_link_args {
21244 + aufs_bindex_t bdst, bsrc;
21245 + struct au_pin pin;
21246 + struct path h_path;
21247 + struct dentry *src_parent, *parent;
21250 +static int au_cpup_before_link(struct dentry *src_dentry,
21251 + struct au_link_args *a)
21254 + struct dentry *h_src_dentry;
21255 + struct au_cp_generic cpg = {
21256 + .dentry = src_dentry,
21261 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21264 + di_read_lock_parent(a->src_parent, AuLock_IR);
21265 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21266 + if (unlikely(err))
21269 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21270 + err = au_pin(&a->pin, src_dentry, a->bdst,
21271 + au_opt_udba(src_dentry->d_sb),
21272 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21273 + if (unlikely(err))
21276 + err = au_sio_cpup_simple(&cpg);
21277 + au_unpin(&a->pin);
21280 + di_read_unlock(a->src_parent, AuLock_IR);
21284 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21285 + struct au_link_args *a)
21288 + unsigned char plink;
21289 + aufs_bindex_t bbot;
21290 + struct dentry *h_src_dentry;
21291 + struct inode *h_inode, *inode, *delegated;
21292 + struct super_block *sb;
21293 + struct file *h_file;
21297 + sb = src_dentry->d_sb;
21298 + inode = d_inode(src_dentry);
21299 + if (au_ibtop(inode) <= a->bdst)
21300 + h_inode = au_h_iptr(inode, a->bdst);
21301 + if (!h_inode || !h_inode->i_nlink) {
21302 + /* copyup src_dentry as the name of dentry. */
21303 + bbot = au_dbbot(dentry);
21304 + if (bbot < a->bsrc)
21305 + au_set_dbbot(dentry, a->bsrc);
21306 + au_set_h_dptr(dentry, a->bsrc,
21307 + dget(au_h_dptr(src_dentry, a->bsrc)));
21308 + dget(a->h_path.dentry);
21309 + au_set_h_dptr(dentry, a->bdst, NULL);
21310 + AuDbg("temporary d_inode...\n");
21311 + spin_lock(&dentry->d_lock);
21312 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21313 + spin_unlock(&dentry->d_lock);
21314 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21315 + if (IS_ERR(h_file))
21316 + err = PTR_ERR(h_file);
21318 + struct au_cp_generic cpg = {
21319 + .dentry = dentry,
21324 + .flags = AuCpup_KEEPLINO
21326 + err = au_sio_cpup_simple(&cpg);
21327 + au_h_open_post(dentry, a->bsrc, h_file);
21329 + dput(a->h_path.dentry);
21330 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21332 + au_set_h_dptr(dentry, a->bdst,
21333 + a->h_path.dentry);
21335 + spin_lock(&dentry->d_lock);
21336 + dentry->d_inode = NULL; /* restore */
21337 + spin_unlock(&dentry->d_lock);
21338 + AuDbg("temporary d_inode...done\n");
21339 + au_set_h_dptr(dentry, a->bsrc, NULL);
21340 + au_set_dbbot(dentry, bbot);
21342 + /* the inode of src_dentry already exists on a.bdst branch */
21343 + h_src_dentry = d_find_alias(h_inode);
21344 + if (!h_src_dentry && au_plink_test(inode)) {
21346 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21347 + err = PTR_ERR(h_src_dentry);
21348 + if (IS_ERR(h_src_dentry))
21351 + if (unlikely(d_is_negative(h_src_dentry))) {
21352 + dput(h_src_dentry);
21353 + h_src_dentry = NULL;
21357 + if (h_src_dentry) {
21358 + delegated = NULL;
21359 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21360 + &a->h_path, &delegated);
21361 + if (unlikely(err == -EWOULDBLOCK)) {
21362 + pr_warn("cannot retry for NFSv4 delegation"
21363 + " for an internal link\n");
21366 + dput(h_src_dentry);
21368 + AuIOErr("no dentry found for hi%lu on b%d\n",
21369 + h_inode->i_ino, a->bdst);
21374 + if (!err && !plink)
21375 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21382 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21383 + struct dentry *dentry)
21386 + struct au_dtime dt;
21387 + struct au_link_args *a;
21388 + struct dentry *wh_dentry, *h_src_dentry;
21389 + struct inode *inode, *delegated;
21390 + struct super_block *sb;
21391 + struct au_wr_dir_args wr_dir_args = {
21392 + /* .force_btgt = -1, */
21393 + .flags = AuWrDir_ADD_ENTRY
21397 + inode = d_inode(src_dentry);
21398 + IMustLock(inode);
21401 + a = kzalloc(sizeof(*a), GFP_NOFS);
21402 + if (unlikely(!a))
21405 + a->parent = dentry->d_parent; /* dir inode is locked */
21406 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21407 + AuLock_NOPLM | AuLock_GEN);
21408 + if (unlikely(err))
21410 + err = au_d_linkable(src_dentry);
21411 + if (unlikely(err))
21413 + err = au_d_may_add(dentry);
21414 + if (unlikely(err))
21417 + a->src_parent = dget_parent(src_dentry);
21418 + wr_dir_args.force_btgt = au_ibtop(inode);
21420 + di_write_lock_parent(a->parent);
21421 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21422 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21424 + err = PTR_ERR(wh_dentry);
21425 + if (IS_ERR(wh_dentry))
21429 + sb = dentry->d_sb;
21430 + a->bdst = au_dbtop(dentry);
21431 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21432 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21433 + a->bsrc = au_ibtop(inode);
21434 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21435 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21436 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21437 + if (!h_src_dentry) {
21438 + a->bsrc = au_dbtop(src_dentry);
21439 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21440 + AuDebugOn(!h_src_dentry);
21441 + } else if (IS_ERR(h_src_dentry)) {
21442 + err = PTR_ERR(h_src_dentry);
21447 + * aufs doesn't touch the credential so
21448 + * security_dentry_create_files_as() is unnecessary.
21450 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21451 + if (a->bdst < a->bsrc
21452 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21453 + err = au_cpup_or_link(src_dentry, dentry, a);
21455 + delegated = NULL;
21456 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21457 + &a->h_path, &delegated);
21458 + if (unlikely(err == -EWOULDBLOCK)) {
21459 + pr_warn("cannot retry for NFSv4 delegation"
21460 + " for an internal link\n");
21464 + dput(h_src_dentry);
21467 + * copyup src_dentry to the branch we process,
21468 + * and then link(2) to it.
21470 + dput(h_src_dentry);
21471 + if (a->bdst < a->bsrc
21472 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21473 + au_unpin(&a->pin);
21474 + di_write_unlock(a->parent);
21475 + err = au_cpup_before_link(src_dentry, a);
21476 + di_write_lock_parent(a->parent);
21478 + err = au_pin(&a->pin, dentry, a->bdst,
21480 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21481 + if (unlikely(err))
21485 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21487 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21488 + delegated = NULL;
21489 + err = vfsub_link(h_src_dentry,
21490 + au_pinned_h_dir(&a->pin),
21491 + &a->h_path, &delegated);
21492 + if (unlikely(err == -EWOULDBLOCK)) {
21493 + pr_warn("cannot retry"
21494 + " for NFSv4 delegation"
21495 + " for an internal link\n");
21501 + if (unlikely(err))
21505 + a->h_path.dentry = wh_dentry;
21506 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21508 + if (unlikely(err))
21512 + au_dir_ts(dir, a->bdst);
21513 + inode_inc_iversion(dir);
21514 + inc_nlink(inode);
21515 + inode->i_ctime = dir->i_ctime;
21516 + d_instantiate(dentry, au_igrab(inode));
21517 + if (d_unhashed(a->h_path.dentry))
21518 + /* some filesystem calls d_drop() */
21520 + /* some filesystems consume an inode even hardlink */
21521 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21522 + goto out_unpin; /* success */
21525 + /* no delegation since it is just created */
21526 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21527 + /*delegated*/NULL, /*force*/0);
21528 + if (unlikely(rerr)) {
21529 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21532 + au_dtime_revert(&dt);
21534 + au_unpin(&a->pin);
21538 + di_write_unlock(a->parent);
21539 + dput(a->src_parent);
21541 + if (unlikely(err)) {
21542 + au_update_dbtop(dentry);
21545 + aufs_read_and_write_unlock2(dentry, src_dentry);
21553 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
21554 + struct dentry *dentry, umode_t mode)
21557 + aufs_bindex_t bindex;
21558 + unsigned char diropq;
21559 + struct path h_path;
21560 + struct dentry *wh_dentry, *parent, *opq_dentry;
21561 + struct inode *h_inode;
21562 + struct super_block *sb;
21564 + struct au_pin pin;
21565 + struct au_dtime dt;
21566 + } *a; /* reduce the stack usage */
21567 + struct au_wr_dir_args wr_dir_args = {
21568 + .force_btgt = -1,
21569 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21575 + a = kmalloc(sizeof(*a), GFP_NOFS);
21576 + if (unlikely(!a))
21579 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21580 + if (unlikely(err))
21582 + err = au_d_may_add(dentry);
21583 + if (unlikely(err))
21586 + parent = dentry->d_parent; /* dir inode is locked */
21587 + di_write_lock_parent(parent);
21588 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21589 + &a->pin, &wr_dir_args);
21590 + err = PTR_ERR(wh_dentry);
21591 + if (IS_ERR(wh_dentry))
21594 + sb = dentry->d_sb;
21595 + bindex = au_dbtop(dentry);
21596 + h_path.dentry = au_h_dptr(dentry, bindex);
21597 + h_path.mnt = au_sbr_mnt(sb, bindex);
21598 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21599 + if (unlikely(err))
21602 + /* make the dir opaque */
21604 + h_inode = d_inode(h_path.dentry);
21606 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21607 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21608 + opq_dentry = au_diropq_create(dentry, bindex);
21609 + inode_unlock(h_inode);
21610 + err = PTR_ERR(opq_dentry);
21611 + if (IS_ERR(opq_dentry))
21613 + dput(opq_dentry);
21617 + err = epilog(dir, bindex, wh_dentry, dentry);
21620 + goto out_unpin; /* success */
21625 + AuLabel(revert opq);
21626 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21627 + rerr = au_diropq_remove(dentry, bindex);
21628 + inode_unlock(h_inode);
21630 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21631 + dentry, err, rerr);
21637 + AuLabel(revert dir);
21638 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21640 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21641 + dentry, err, rerr);
21644 + au_dtime_revert(&a->dt);
21646 + au_unpin(&a->pin);
21649 + di_write_unlock(parent);
21651 + if (unlikely(err)) {
21652 + au_update_dbtop(dentry);
21655 + aufs_read_unlock(dentry, AuLock_DW);
21661 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21662 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21663 +++ linux/fs/aufs/i_op.c 2022-03-21 14:49:05.726633010 +0100
21665 +// SPDX-License-Identifier: GPL-2.0
21667 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21669 + * This program, aufs is free software; you can redistribute it and/or modify
21670 + * it under the terms of the GNU General Public License as published by
21671 + * the Free Software Foundation; either version 2 of the License, or
21672 + * (at your option) any later version.
21674 + * This program is distributed in the hope that it will be useful,
21675 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21676 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21677 + * GNU General Public License for more details.
21679 + * You should have received a copy of the GNU General Public License
21680 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21684 + * inode operations (except add/del/rename)
21687 +#include <linux/device_cgroup.h>
21688 +#include <linux/fs_stack.h>
21689 +#include <linux/iversion.h>
21690 +#include <linux/security.h>
21693 +static int h_permission(struct inode *h_inode, int mask,
21694 + struct path *h_path, int brperm)
21697 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21698 + struct user_namespace *h_userns;
21701 + if (write_mask && IS_IMMUTABLE(h_inode))
21705 + if (((mask & MAY_EXEC)
21706 + && S_ISREG(h_inode->i_mode)
21707 + && (path_noexec(h_path)
21708 + || !(h_inode->i_mode & 0111))))
21712 + * - skip the lower fs test in the case of write to ro branch.
21713 + * - nfs dir permission write check is optimized, but a policy for
21714 + * link/rename requires a real check.
21715 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21716 + * in this case, generic_permission() returns -EOPNOTSUPP.
21718 + h_userns = mnt_user_ns(h_path->mnt);
21719 + if ((write_mask && !au_br_writable(brperm))
21720 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21721 + && write_mask && !(mask & MAY_READ))
21722 + || !h_inode->i_op->permission) {
21723 + /* AuLabel(generic_permission); */
21724 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
21725 + err = generic_permission(h_userns, h_inode, mask);
21726 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21727 + err = h_inode->i_op->permission(h_userns, h_inode,
21731 + /* AuLabel(h_inode->permission); */
21732 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
21737 + err = devcgroup_inode_permission(h_inode, mask);
21739 + err = security_inode_permission(h_inode, mask);
21745 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
21749 + aufs_bindex_t bindex, bbot;
21750 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21751 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21752 + struct inode *h_inode;
21753 + struct super_block *sb;
21754 + struct au_branch *br;
21756 + /* todo: support rcu-walk? */
21757 + if (mask & MAY_NOT_BLOCK)
21760 + sb = inode->i_sb;
21761 + si_read_lock(sb, AuLock_FLUSH);
21762 + ii_read_lock_child(inode);
21763 +#if 0 /* reserved for future use */
21765 + * This test may be rather 'too much' since the test is essentially done
21766 + * in the aufs_lookup(). Theoretically it is possible that the inode
21767 + * generation doesn't match to the superblock's here. But it isn't a
21768 + * big deal I suppose.
21770 + err = au_iigen_test(inode, au_sigen(sb));
21771 + if (unlikely(err))
21777 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21778 + err = au_busy_or_stale();
21779 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21780 + if (unlikely(!h_inode
21781 + || (h_inode->i_mode & S_IFMT)
21782 + != (inode->i_mode & S_IFMT)))
21786 + bindex = au_ibtop(inode);
21787 + br = au_sbr(sb, bindex);
21788 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21791 + && !special_file(h_inode->i_mode)) {
21792 + /* test whether the upper writable branch exists */
21794 + for (; bindex >= 0; bindex--)
21795 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21803 + /* non-write to dir */
21805 + bbot = au_ibbot(inode);
21806 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21807 + h_inode = au_h_iptr(inode, bindex);
21809 + err = au_busy_or_stale();
21810 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21813 + br = au_sbr(sb, bindex);
21814 + err = h_permission(h_inode, mask, &br->br_path,
21820 + ii_read_unlock(inode);
21821 + si_read_unlock(sb);
21825 +/* ---------------------------------------------------------------------- */
21827 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21828 + unsigned int flags)
21830 + struct dentry *ret, *parent;
21831 + struct inode *inode;
21832 + struct super_block *sb;
21833 + int err, npositive;
21837 + /* todo: support rcu-walk? */
21838 + ret = ERR_PTR(-ECHILD);
21839 + if (flags & LOOKUP_RCU)
21842 + ret = ERR_PTR(-ENAMETOOLONG);
21843 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21847 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21848 + ret = ERR_PTR(err);
21849 + if (unlikely(err))
21852 + err = au_di_init(dentry);
21853 + ret = ERR_PTR(err);
21854 + if (unlikely(err))
21858 + npositive = 0; /* suppress a warning */
21859 + parent = dentry->d_parent; /* dir inode is locked */
21860 + di_read_lock_parent(parent, AuLock_IR);
21861 + err = au_alive_dir(parent);
21863 + err = au_digen_test(parent, au_sigen(sb));
21865 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21866 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21867 + AuLkup_ALLOW_NEG);
21870 + di_read_unlock(parent, AuLock_IR);
21871 + ret = ERR_PTR(err);
21872 + if (unlikely(err < 0))
21876 + inode = au_new_inode(dentry, /*must_new*/0);
21877 + if (IS_ERR(inode)) {
21878 + ret = (void *)inode;
21885 + atomic_inc(&inode->i_count);
21886 + ret = d_splice_alias(inode, dentry);
21887 +#if 0 /* reserved for future use */
21888 + if (unlikely(d_need_lookup(dentry))) {
21889 + spin_lock(&dentry->d_lock);
21890 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21891 + spin_unlock(&dentry->d_lock);
21895 + if (!IS_ERR(ret)) {
21897 + if (ret && ret != dentry)
21898 + ii_write_unlock(inode);
21900 + ii_write_unlock(inode);
21907 + di_write_unlock(dentry);
21909 + si_read_unlock(sb);
21914 +/* ---------------------------------------------------------------------- */
21917 + * very dirty and complicated aufs ->atomic_open().
21918 + * aufs_atomic_open()
21919 + * + au_aopen_or_create()
21921 + * + vfsub_atomic_open()
21922 + * + branch fs ->atomic_open()
21923 + * may call the actual 'open' for h_file
21924 + * + inc br_nfiles only if opened
21925 + * + au_aopen_no_open() or au_aopen_do_open()
21927 + * au_aopen_do_open()
21928 + * + finish_open()
21929 + * + au_do_aopen()
21930 + * + au_do_open() the body of all 'open'
21931 + * + au_do_open_nondir()
21932 + * set the passed h_file
21934 + * au_aopen_no_open()
21935 + * + finish_no_open()
21938 +struct aopen_node {
21939 + struct hlist_bl_node hblist;
21940 + struct file *file, *h_file;
21943 +static int au_do_aopen(struct inode *inode, struct file *file)
21945 + struct hlist_bl_head *aopen;
21946 + struct hlist_bl_node *pos;
21947 + struct aopen_node *node;
21948 + struct au_do_open_args args = {
21950 + .open = au_do_open_nondir
21953 + aopen = &au_sbi(inode->i_sb)->si_aopen;
21954 + hlist_bl_lock(aopen);
21955 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
21956 + if (node->file == file) {
21957 + args.h_file = node->h_file;
21960 + hlist_bl_unlock(aopen);
21961 + /* AuDebugOn(!args.h_file); */
21963 + return au_do_open(file, &args);
21966 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
21967 + struct aopen_node *aopen_node)
21970 + struct hlist_bl_head *aopen;
21973 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
21974 + au_hbl_add(&aopen_node->hblist, aopen);
21975 + err = finish_open(file, dentry, au_do_aopen);
21976 + au_hbl_del(&aopen_node->hblist, aopen);
21977 + /* AuDbgFile(file); */
21978 + AuDbg("%pd%s%s\n", dentry,
21979 + (file->f_mode & FMODE_CREATED) ? " created" : "",
21980 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
21986 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
21992 + err = finish_no_open(file, dentry);
21998 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
21999 + struct file *file, unsigned int open_flag,
22000 + umode_t create_mode)
22002 + int err, did_open;
22003 + unsigned int lkup_flags;
22004 + aufs_bindex_t bindex;
22005 + struct super_block *sb;
22006 + struct dentry *parent, *d;
22007 + struct vfsub_aopen_args args = {
22008 + .open_flag = open_flag,
22009 + .create_mode = create_mode
22011 + struct aopen_node aopen_node = {
22016 + AuDbg("open_flag 0%o\n", open_flag);
22017 + AuDbgDentry(dentry);
22020 + if (!au_di(dentry)) {
22021 + lkup_flags = LOOKUP_OPEN;
22022 + if (open_flag & O_CREAT)
22023 + lkup_flags |= LOOKUP_CREATE;
22024 + d = aufs_lookup(dir, dentry, lkup_flags);
22026 + err = PTR_ERR(d);
22031 + * obsoleted dentry found.
22032 + * another error will be returned later.
22038 + AuDbgDentry(dentry);
22041 + if (d_is_positive(dentry)
22042 + || d_unhashed(dentry)
22043 + || d_unlinked(dentry)
22044 + || !(open_flag & O_CREAT)) {
22045 + err = au_aopen_no_open(file, dentry);
22046 + goto out; /* success */
22049 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22050 + if (unlikely(err))
22053 + sb = dentry->d_sb;
22054 + parent = dentry->d_parent; /* dir is locked */
22055 + di_write_lock_parent(parent);
22056 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22057 + if (unlikely(err < 0))
22060 + AuDbgDentry(dentry);
22061 + if (d_is_positive(dentry)) {
22062 + err = au_aopen_no_open(file, dentry);
22063 + goto out_parent; /* success */
22066 + args.file = alloc_empty_file(file->f_flags, current_cred());
22067 + err = PTR_ERR(args.file);
22068 + if (IS_ERR(args.file))
22071 + bindex = au_dbtop(dentry);
22072 + err = au_aopen_or_create(dir, dentry, &args);
22074 + AuDbgFile(args.file);
22075 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22076 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22079 + args.file = NULL;
22081 + di_write_unlock(parent);
22082 + di_write_unlock(dentry);
22083 + if (unlikely(err < 0)) {
22090 + err = au_aopen_no_open(file, dentry);
22092 + aopen_node.h_file = args.file;
22093 + err = au_aopen_do_open(file, dentry, &aopen_node);
22095 + if (unlikely(err < 0)) {
22099 + au_lcnt_dec(&args.br->br_nfiles);
22101 + goto out_sb; /* success */
22104 + di_write_unlock(parent);
22105 + di_write_unlock(dentry);
22107 + si_read_unlock(sb);
22115 +/* ---------------------------------------------------------------------- */
22117 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22118 + const unsigned char add_entry, aufs_bindex_t bcpup,
22119 + aufs_bindex_t btop)
22122 + struct dentry *h_parent;
22123 + struct inode *h_dir;
22126 + IMustLock(d_inode(parent));
22128 + di_write_lock_parent(parent);
22131 + if (!au_h_dptr(parent, bcpup)) {
22132 + if (btop > bcpup)
22133 + err = au_cpup_dirs(dentry, bcpup);
22134 + else if (btop < bcpup)
22135 + err = au_cpdown_dirs(dentry, bcpup);
22139 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22140 + h_parent = au_h_dptr(parent, bcpup);
22141 + h_dir = d_inode(h_parent);
22142 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22143 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22144 + /* todo: no unlock here */
22145 + inode_unlock_shared(h_dir);
22147 + AuDbg("bcpup %d\n", bcpup);
22149 + if (d_really_is_negative(dentry))
22150 + au_set_h_dptr(dentry, btop, NULL);
22151 + au_update_dbrange(dentry, /*do_put_zero*/0);
22156 + di_write_unlock(parent);
22158 + err = bcpup; /* success */
22165 + * decide the branch and the parent dir where we will create a new entry.
22166 + * returns new bindex or an error.
22167 + * copyup the parent dir if needed.
22169 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22170 + struct au_wr_dir_args *args)
22173 + unsigned int flags;
22174 + aufs_bindex_t bcpup, btop, src_btop;
22175 + const unsigned char add_entry
22176 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22177 + | au_ftest_wrdir(args->flags, TMPFILE);
22178 + struct super_block *sb;
22179 + struct dentry *parent;
22180 + struct au_sbinfo *sbinfo;
22182 + sb = dentry->d_sb;
22183 + sbinfo = au_sbi(sb);
22184 + parent = dget_parent(dentry);
22185 + btop = au_dbtop(dentry);
22187 + if (args->force_btgt < 0) {
22188 + if (src_dentry) {
22189 + src_btop = au_dbtop(src_dentry);
22190 + if (src_btop < btop)
22191 + bcpup = src_btop;
22192 + } else if (add_entry) {
22194 + if (au_ftest_wrdir(args->flags, ISDIR))
22195 + au_fset_wbr(flags, DIR);
22196 + err = AuWbrCreate(sbinfo, dentry, flags);
22200 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22202 + err = AuWbrCopyup(sbinfo, dentry);
22204 + if (!IS_ROOT(dentry)) {
22205 + di_read_lock_parent(parent, !AuLock_IR);
22206 + err = AuWbrCopyup(sbinfo, dentry);
22207 + di_read_unlock(parent, !AuLock_IR);
22209 + err = AuWbrCopyup(sbinfo, dentry);
22212 + if (unlikely(err < 0))
22216 + bcpup = args->force_btgt;
22217 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22220 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22222 + if (bcpup == btop)
22223 + goto out; /* success */
22225 + /* copyup the new parent into the branch we process */
22226 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22228 + if (d_really_is_negative(dentry)) {
22229 + au_set_h_dptr(dentry, btop, NULL);
22230 + au_set_dbtop(dentry, bcpup);
22231 + au_set_dbbot(dentry, bcpup);
22233 + AuDebugOn(add_entry
22234 + && !au_ftest_wrdir(args->flags, TMPFILE)
22235 + && !au_h_dptr(dentry, bcpup));
22243 +/* ---------------------------------------------------------------------- */
22245 +void au_pin_hdir_unlock(struct au_pin *p)
22248 + au_hn_inode_unlock(p->hdir);
22251 +int au_pin_hdir_lock(struct au_pin *p)
22259 + /* even if an error happens later, keep this lock */
22260 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22263 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22268 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22269 + p->h_parent, p->br);
22275 +int au_pin_hdir_relock(struct au_pin *p)
22278 + struct inode *h_i;
22279 + struct dentry *h_d[] = {
22284 + err = au_pin_hdir_lock(p);
22285 + if (unlikely(err))
22288 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22291 + if (d_is_positive(h_d[i])) {
22292 + h_i = d_inode(h_d[i]);
22293 + err = !h_i->i_nlink;
22301 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22303 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22306 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22309 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22310 + p->lsc_hi, 0, NULL, _RET_IP_);
22311 + au_pin_hdir_set_owner(p, current);
22315 +void au_pin_hdir_release(struct au_pin *p)
22318 + au_pin_hdir_set_owner(p, p->task);
22319 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22323 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22325 + if (pin && pin->parent)
22326 + return au_h_dptr(pin->parent, pin->bindex);
22330 +void au_unpin(struct au_pin *p)
22333 + au_pin_hdir_unlock(p);
22334 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22335 + vfsub_mnt_drop_write(p->h_mnt);
22339 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22340 + di_read_unlock(p->parent, AuLock_IR);
22341 + iput(p->hdir->hi_inode);
22343 + p->parent = NULL;
22346 + /* do not clear p->task */
22349 +int au_do_pin(struct au_pin *p)
22352 + struct super_block *sb;
22353 + struct inode *h_dir;
22356 + sb = p->dentry->d_sb;
22357 + p->br = au_sbr(sb, p->bindex);
22358 + if (IS_ROOT(p->dentry)) {
22359 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22360 + p->h_mnt = au_br_mnt(p->br);
22361 + err = vfsub_mnt_want_write(p->h_mnt);
22362 + if (unlikely(err)) {
22363 + au_fclr_pin(p->flags, MNT_WRITE);
22370 + p->h_dentry = NULL;
22371 + if (p->bindex <= au_dbbot(p->dentry))
22372 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22374 + p->parent = dget_parent(p->dentry);
22375 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22376 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22379 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22380 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22382 + h_dir = p->hdir->hi_inode;
22386 + * if DI_LOCKED is not set, then p->parent may be different
22387 + * and h_parent can be NULL.
22389 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22391 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22392 + di_read_unlock(p->parent, AuLock_IR);
22394 + p->parent = NULL;
22398 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22399 + p->h_mnt = au_br_mnt(p->br);
22400 + err = vfsub_mnt_want_write(p->h_mnt);
22401 + if (unlikely(err)) {
22402 + au_fclr_pin(p->flags, MNT_WRITE);
22403 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22404 + di_read_unlock(p->parent, AuLock_IR);
22406 + p->parent = NULL;
22412 + err = au_pin_hdir_lock(p);
22414 + goto out; /* success */
22419 + pr_err("err %d\n", err);
22420 + err = au_busy_or_stale();
22425 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22426 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22427 + unsigned int udba, unsigned char flags)
22429 + p->dentry = dentry;
22431 + p->lsc_di = lsc_di;
22432 + p->lsc_hi = lsc_hi;
22433 + p->flags = flags;
22434 + p->bindex = bindex;
22436 + p->parent = NULL;
22440 + p->h_dentry = NULL;
22441 + p->h_parent = NULL;
22443 + p->task = current;
22446 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22447 + unsigned int udba, unsigned char flags)
22449 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22451 + return au_do_pin(pin);
22454 +/* ---------------------------------------------------------------------- */
22457 + * ->setattr() and ->getattr() are called in various cases.
22458 + * chmod, stat: dentry is revalidated.
22459 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22461 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22463 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22464 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22467 + struct dentry *parent;
22470 + if (au_digen_test(dentry, sigen)) {
22471 + parent = dget_parent(dentry);
22472 + di_read_lock_parent(parent, AuLock_IR);
22473 + err = au_refresh_dentry(dentry, parent);
22474 + di_read_unlock(parent, AuLock_IR);
22482 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22483 + struct au_icpup_args *a)
22487 + aufs_bindex_t btop, ibtop;
22488 + struct dentry *hi_wh, *parent;
22489 + struct inode *inode;
22490 + struct au_wr_dir_args wr_dir_args = {
22491 + .force_btgt = -1,
22495 + if (d_is_dir(dentry))
22496 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22497 + /* plink or hi_wh() case */
22498 + btop = au_dbtop(dentry);
22499 + inode = d_inode(dentry);
22500 + ibtop = au_ibtop(inode);
22501 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22502 + wr_dir_args.force_btgt = ibtop;
22503 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22504 + if (unlikely(err < 0))
22508 + au_fset_icpup(a->flags, DID_CPUP);
22511 + a->pin_flags = AuPin_MNT_WRITE;
22513 + if (!IS_ROOT(dentry)) {
22514 + au_fset_pin(a->pin_flags, DI_LOCKED);
22515 + parent = dget_parent(dentry);
22516 + di_write_lock_parent(parent);
22519 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22520 + if (unlikely(err))
22524 + a->h_path.dentry = au_h_dptr(dentry, btop);
22525 + a->h_inode = d_inode(a->h_path.dentry);
22526 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22527 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22528 + if (ia->ia_size < i_size_read(a->h_inode))
22529 + sz = ia->ia_size;
22530 + inode_unlock_shared(a->h_inode);
22534 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22535 + hi_wh = au_hi_wh(inode, a->btgt);
22537 + struct au_cp_generic cpg = {
22538 + .dentry = dentry,
22544 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22545 + if (unlikely(err))
22547 + hi_wh = au_hi_wh(inode, a->btgt);
22548 + /* todo: revalidate hi_wh? */
22553 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22554 + di_downgrade_lock(parent, AuLock_IR);
22558 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22559 + goto out; /* success */
22561 + if (!d_unhashed(dentry)) {
22562 + struct au_cp_generic cpg = {
22563 + .dentry = dentry,
22568 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22570 + err = au_sio_cpup_simple(&cpg);
22572 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22573 + } else if (!hi_wh)
22574 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22576 + a->h_path.dentry = hi_wh; /* do not dget here */
22579 + a->h_inode = d_inode(a->h_path.dentry);
22581 + goto out; /* success */
22582 + au_unpin(&a->pin);
22585 + di_write_unlock(parent);
22590 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22594 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
22595 + struct iattr *ia)
22598 + struct inode *inode, *delegated;
22599 + struct super_block *sb;
22600 + struct file *file;
22601 + struct au_icpup_args *a;
22602 + struct user_namespace *h_userns;
22604 + inode = d_inode(dentry);
22605 + IMustLock(inode);
22607 + err = setattr_prepare(userns, dentry, ia);
22608 + if (unlikely(err))
22612 + a = kzalloc(sizeof(*a), GFP_NOFS);
22613 + if (unlikely(!a))
22616 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22617 + ia->ia_valid &= ~ATTR_MODE;
22620 + sb = dentry->d_sb;
22621 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22622 + if (unlikely(err))
22625 + if (ia->ia_valid & ATTR_FILE) {
22626 + /* currently ftruncate(2) only */
22627 + AuDebugOn(!d_is_reg(dentry));
22628 + file = ia->ia_file;
22629 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22631 + if (unlikely(err))
22633 + ia->ia_file = au_hf_top(file);
22634 + a->udba = AuOpt_UDBA_NONE;
22636 + /* fchmod() doesn't pass ia_file */
22637 + a->udba = au_opt_udba(sb);
22638 + di_write_lock_child(dentry);
22639 + /* no d_unlinked(), to set UDBA_NONE for root */
22640 + if (d_unhashed(dentry))
22641 + a->udba = AuOpt_UDBA_NONE;
22642 + if (a->udba != AuOpt_UDBA_NONE) {
22643 + AuDebugOn(IS_ROOT(dentry));
22644 + err = au_reval_for_attr(dentry, au_sigen(sb));
22645 + if (unlikely(err))
22650 + err = au_pin_and_icpup(dentry, ia, a);
22651 + if (unlikely(err < 0))
22653 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22654 + ia->ia_file = NULL;
22655 + ia->ia_valid &= ~ATTR_FILE;
22658 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22659 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22660 + == (ATTR_MODE | ATTR_CTIME)) {
22661 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22662 + if (unlikely(err))
22664 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22665 + && (ia->ia_valid & ATTR_CTIME)) {
22666 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22667 + if (unlikely(err))
22671 + if (ia->ia_valid & ATTR_SIZE) {
22674 + if (ia->ia_size < i_size_read(inode))
22676 + truncate_setsize(inode, ia->ia_size);
22679 + if (ia->ia_valid & ATTR_FILE)
22681 + inode_unlock(a->h_inode);
22682 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22683 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22685 + delegated = NULL;
22687 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22689 + err = break_deleg_wait(&delegated);
22697 + * regardless aufs 'acl' option setting.
22698 + * why don't all acl-aware fs call this func from their ->setattr()?
22700 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22701 + h_userns = mnt_user_ns(a->h_path.mnt);
22702 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
22705 + au_cpup_attr_changeable(inode);
22708 + inode_unlock(a->h_inode);
22709 + au_unpin(&a->pin);
22710 + if (unlikely(err))
22711 + au_update_dbtop(dentry);
22713 + di_write_unlock(dentry);
22715 + fi_write_unlock(file);
22716 + ia->ia_file = file;
22717 + ia->ia_valid |= ATTR_FILE;
22720 + si_read_unlock(sb);
22728 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22729 +static int au_h_path_to_set_attr(struct dentry *dentry,
22730 + struct au_icpup_args *a, struct path *h_path)
22733 + struct super_block *sb;
22735 + sb = dentry->d_sb;
22736 + a->udba = au_opt_udba(sb);
22737 + /* no d_unlinked(), to set UDBA_NONE for root */
22738 + if (d_unhashed(dentry))
22739 + a->udba = AuOpt_UDBA_NONE;
22740 + if (a->udba != AuOpt_UDBA_NONE) {
22741 + AuDebugOn(IS_ROOT(dentry));
22742 + err = au_reval_for_attr(dentry, au_sigen(sb));
22743 + if (unlikely(err))
22746 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22747 + if (unlikely(err < 0))
22750 + h_path->dentry = a->h_path.dentry;
22751 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22757 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22758 + struct au_sxattr *arg)
22761 + struct path h_path;
22762 + struct super_block *sb;
22763 + struct au_icpup_args *a;
22764 + struct inode *h_inode;
22765 + struct user_namespace *h_userns;
22767 + IMustLock(inode);
22770 + a = kzalloc(sizeof(*a), GFP_NOFS);
22771 + if (unlikely(!a))
22774 + sb = dentry->d_sb;
22775 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22776 + if (unlikely(err))
22779 + h_path.dentry = NULL; /* silence gcc */
22780 + di_write_lock_child(dentry);
22781 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22782 + if (unlikely(err))
22784 + h_userns = mnt_user_ns(h_path.mnt);
22786 + inode_unlock(a->h_inode);
22787 + switch (arg->type) {
22788 + case AU_XATTR_SET:
22789 + AuDebugOn(d_is_negative(h_path.dentry));
22790 + err = vfsub_setxattr(h_userns, h_path.dentry,
22791 + arg->u.set.name, arg->u.set.value,
22792 + arg->u.set.size, arg->u.set.flags);
22795 + err = -EOPNOTSUPP;
22796 + h_inode = d_inode(h_path.dentry);
22797 + if (h_inode->i_op->set_acl) {
22798 + /* this will call posix_acl_update_mode */
22799 + err = h_inode->i_op->set_acl(h_userns, h_inode,
22800 + arg->u.acl_set.acl,
22801 + arg->u.acl_set.type);
22806 + au_cpup_attr_timesizes(inode);
22808 + au_unpin(&a->pin);
22809 + if (unlikely(err))
22810 + au_update_dbtop(dentry);
22813 + di_write_unlock(dentry);
22814 + si_read_unlock(sb);
22823 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22824 + unsigned int nlink)
22828 + inode->i_mode = st->mode;
22829 + /* don't i_[ug]id_write() here */
22830 + inode->i_uid = st->uid;
22831 + inode->i_gid = st->gid;
22832 + inode->i_atime = st->atime;
22833 + inode->i_mtime = st->mtime;
22834 + inode->i_ctime = st->ctime;
22836 + au_cpup_attr_nlink(inode, /*force*/0);
22837 + if (S_ISDIR(inode->i_mode)) {
22838 + n = inode->i_nlink;
22841 + smp_mb(); /* for i_nlink */
22842 + /* 0 can happen */
22843 + set_nlink(inode, n);
22846 + spin_lock(&inode->i_lock);
22847 + inode->i_blocks = st->blocks;
22848 + i_size_write(inode, st->size);
22849 + spin_unlock(&inode->i_lock);
22853 + * common routine for aufs_getattr() and au_getxattr().
22854 + * returns zero or negative (an error).
22855 + * @dentry will be read-locked in success.
22857 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22858 + struct path *h_path, int locked)
22861 + unsigned int mnt_flags, sigen;
22862 + unsigned char udba_none;
22863 + aufs_bindex_t bindex;
22864 + struct super_block *sb, *h_sb;
22866 + h_path->mnt = NULL;
22867 + h_path->dentry = NULL;
22870 + sb = dentry->d_sb;
22871 + mnt_flags = au_mntflags(sb);
22872 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22874 + if (unlikely(locked))
22875 + goto body; /* skip locking dinfo */
22877 + /* support fstat(2) */
22878 + if (!d_unlinked(dentry) && !udba_none) {
22879 + sigen = au_sigen(sb);
22880 + err = au_digen_test(dentry, sigen);
22882 + di_read_lock_child(dentry, AuLock_IR);
22883 + err = au_dbrange_test(dentry);
22884 + if (unlikely(err)) {
22885 + di_read_unlock(dentry, AuLock_IR);
22889 + AuDebugOn(IS_ROOT(dentry));
22890 + di_write_lock_child(dentry);
22891 + err = au_dbrange_test(dentry);
22893 + err = au_reval_for_attr(dentry, sigen);
22895 + di_downgrade_lock(dentry, AuLock_IR);
22897 + di_write_unlock(dentry);
22902 + di_read_lock_child(dentry, AuLock_IR);
22906 + inode = d_inode(dentry);
22907 + if (unlikely(!inode))
22910 + bindex = au_ibtop(inode);
22911 + h_path->mnt = au_sbr_mnt(sb, bindex);
22912 + h_sb = h_path->mnt->mnt_sb;
22914 + && !au_test_fs_bad_iattr(h_sb)
22916 + goto out; /* success */
22918 + if (au_dbtop(dentry) == bindex)
22919 + h_path->dentry = au_h_dptr(dentry, bindex);
22920 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22921 + h_path->dentry = au_plink_lkup(inode, bindex);
22922 + if (IS_ERR(h_path->dentry))
22923 + /* pretending success */
22924 + h_path->dentry = NULL;
22926 + dput(h_path->dentry);
22933 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
22934 + struct kstat *st, u32 request, unsigned int query)
22937 + unsigned char positive;
22938 + struct path h_path;
22939 + struct dentry *dentry;
22940 + struct inode *inode;
22941 + struct super_block *sb;
22943 + dentry = path->dentry;
22944 + inode = d_inode(dentry);
22945 + sb = dentry->d_sb;
22946 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22947 + if (unlikely(err))
22949 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
22951 + if (unlikely(err))
22953 + if (unlikely(!h_path.dentry))
22954 + /* illegally overlapped or something */
22955 + goto out_fill; /* pretending success */
22957 + positive = d_is_positive(h_path.dentry);
22959 + /* no vfsub version */
22960 + err = vfs_getattr(&h_path, st, request, query);
22963 + au_refresh_iattr(inode, st,
22964 + d_inode(h_path.dentry)->i_nlink);
22965 + goto out_fill; /* success */
22971 + generic_fillattr(userns, inode, st);
22973 + di_read_unlock(dentry, AuLock_IR);
22975 + si_read_unlock(sb);
22981 +/* ---------------------------------------------------------------------- */
22983 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
22984 + struct delayed_call *done)
22987 + struct dentry *h_dentry;
22988 + struct inode *h_inode;
22990 + aufs_bindex_t bindex;
22992 + ret = NULL; /* suppress a warning */
22997 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
22998 + if (unlikely(err))
23001 + err = au_d_hashed_positive(dentry);
23002 + if (unlikely(err))
23006 + inode = d_inode(dentry);
23007 + bindex = au_ibtop(inode);
23008 + h_inode = au_h_iptr(inode, bindex);
23009 + if (unlikely(!h_inode->i_op->get_link))
23014 + if (au_dbtop(dentry) <= bindex) {
23015 + h_dentry = au_h_dptr(dentry, bindex);
23020 + h_dentry = d_find_any_alias(h_inode);
23021 + if (IS_ERR(h_dentry)) {
23022 + err = PTR_ERR(h_dentry);
23026 + if (unlikely(!h_dentry))
23030 + AuDbg("%ps\n", h_inode->i_op->get_link);
23031 + AuDbgDentry(h_dentry);
23032 + ret = vfs_get_link(h_dentry, done);
23035 + err = PTR_ERR(ret);
23038 + aufs_read_unlock(dentry, AuLock_IR);
23040 + if (unlikely(err))
23041 + ret = ERR_PTR(err);
23042 + AuTraceErrPtr(ret);
23046 +/* ---------------------------------------------------------------------- */
23048 +static int au_is_special(struct inode *inode)
23050 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23053 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
23057 + aufs_bindex_t bindex;
23058 + struct super_block *sb;
23059 + struct inode *h_inode;
23060 + struct vfsmount *h_mnt;
23062 + sb = inode->i_sb;
23063 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23064 + "unexpected s_flags 0x%lx", sb->s_flags);
23066 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23068 + si_read_lock(sb, AuLock_FLUSH);
23069 + ii_write_lock_child(inode);
23072 + bindex = au_ibtop(inode);
23073 + h_inode = au_h_iptr(inode, bindex);
23074 + if (!au_test_ro(sb, bindex, inode)) {
23075 + h_mnt = au_sbr_mnt(sb, bindex);
23076 + err = vfsub_mnt_want_write(h_mnt);
23078 + err = vfsub_update_time(h_inode, ts, flags);
23079 + vfsub_mnt_drop_write(h_mnt);
23081 + } else if (au_is_special(h_inode)) {
23083 + * Never copy-up here.
23084 + * These special files may already be opened and used for
23085 + * communicating. If we copied it up, then the communication
23086 + * would be corrupted.
23088 + AuWarn1("timestamps for i%lu are ignored "
23089 + "since it is on readonly branch (hi%lu).\n",
23090 + inode->i_ino, h_inode->i_ino);
23091 + } else if (flags & ~S_ATIME) {
23093 + AuIOErr1("unexpected flags 0x%x\n", flags);
23098 + au_cpup_attr_timesizes(inode);
23099 + ii_write_unlock(inode);
23100 + si_read_unlock(sb);
23103 + if (!err && (flags & S_VERSION))
23104 + inode_inc_iversion(inode);
23109 +/* ---------------------------------------------------------------------- */
23111 +/* no getattr version will be set by module.c:aufs_init() */
23112 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23114 + [AuIop_SYMLINK] = {
23115 + .permission = aufs_permission,
23116 +#ifdef CONFIG_FS_POSIX_ACL
23117 + .get_acl = aufs_get_acl,
23118 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23121 + .setattr = aufs_setattr,
23122 + .getattr = aufs_getattr,
23124 +#ifdef CONFIG_AUFS_XATTR
23125 + .listxattr = aufs_listxattr,
23128 + .get_link = aufs_get_link,
23130 + /* .update_time = aufs_update_time */
23133 + .create = aufs_create,
23134 + .lookup = aufs_lookup,
23135 + .link = aufs_link,
23136 + .unlink = aufs_unlink,
23137 + .symlink = aufs_symlink,
23138 + .mkdir = aufs_mkdir,
23139 + .rmdir = aufs_rmdir,
23140 + .mknod = aufs_mknod,
23141 + .rename = aufs_rename,
23143 + .permission = aufs_permission,
23144 +#ifdef CONFIG_FS_POSIX_ACL
23145 + .get_acl = aufs_get_acl,
23146 + .set_acl = aufs_set_acl,
23149 + .setattr = aufs_setattr,
23150 + .getattr = aufs_getattr,
23152 +#ifdef CONFIG_AUFS_XATTR
23153 + .listxattr = aufs_listxattr,
23156 + .update_time = aufs_update_time,
23157 + .atomic_open = aufs_atomic_open,
23158 + .tmpfile = aufs_tmpfile
23160 + [AuIop_OTHER] = {
23161 + .permission = aufs_permission,
23162 +#ifdef CONFIG_FS_POSIX_ACL
23163 + .get_acl = aufs_get_acl,
23164 + .set_acl = aufs_set_acl,
23167 + .setattr = aufs_setattr,
23168 + .getattr = aufs_getattr,
23170 +#ifdef CONFIG_AUFS_XATTR
23171 + .listxattr = aufs_listxattr,
23174 + .update_time = aufs_update_time
23177 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23178 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23179 +++ linux/fs/aufs/i_op_del.c 2022-03-21 14:49:05.726633010 +0100
23181 +// SPDX-License-Identifier: GPL-2.0
23183 + * Copyright (C) 2005-2021 Junjiro R. Okajima
23185 + * This program, aufs is free software; you can redistribute it and/or modify
23186 + * it under the terms of the GNU General Public License as published by
23187 + * the Free Software Foundation; either version 2 of the License, or
23188 + * (at your option) any later version.
23190 + * This program is distributed in the hope that it will be useful,
23191 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23192 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23193 + * GNU General Public License for more details.
23195 + * You should have received a copy of the GNU General Public License
23196 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23200 + * inode operations (del entry)
23203 +#include <linux/iversion.h>
23207 + * decide if a new whiteout for @dentry is necessary or not.
23208 + * when it is necessary, prepare the parent dir for the upper branch whose
23209 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23210 + * be done by caller.
23212 + * 0: wh is unnecessary
23213 + * plus: wh is necessary
23216 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23218 + int need_wh, err;
23219 + aufs_bindex_t btop;
23220 + struct super_block *sb;
23222 + sb = dentry->d_sb;
23223 + btop = au_dbtop(dentry);
23224 + if (*bcpup < 0) {
23226 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23227 + err = AuWbrCopyup(au_sbi(sb), dentry);
23229 + if (unlikely(err < 0))
23233 + AuDebugOn(btop < *bcpup
23234 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23235 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23237 + if (*bcpup != btop) {
23238 + err = au_cpup_dirs(dentry, *bcpup);
23239 + if (unlikely(err))
23243 + struct au_dinfo *dinfo, *tmp;
23245 + need_wh = -ENOMEM;
23246 + dinfo = au_di(dentry);
23247 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23249 + au_di_cp(tmp, dinfo);
23250 + au_di_swap(tmp, dinfo);
23251 + /* returns the number of positive dentries */
23252 + need_wh = au_lkup_dentry(dentry, btop + 1,
23253 + /* AuLkup_IGNORE_PERM */ 0);
23254 + au_di_swap(tmp, dinfo);
23255 + au_rw_write_unlock(&tmp->di_rwsem);
23259 + AuDbg("need_wh %d\n", need_wh);
23267 + * simple tests for the del-entry operations.
23268 + * following the checks in vfs, plus the parent-child relationship.
23270 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23271 + struct dentry *h_parent, int isdir)
23275 + struct dentry *h_dentry, *h_latest;
23276 + struct inode *h_inode;
23277 + struct path h_ppath;
23278 + struct super_block *sb;
23279 + struct au_branch *br;
23280 + struct user_namespace *h_userns;
23282 + h_dentry = au_h_dptr(dentry, bindex);
23283 + if (d_really_is_positive(dentry)) {
23285 + if (unlikely(d_is_negative(h_dentry)))
23287 + h_inode = d_inode(h_dentry);
23288 + if (unlikely(!h_inode->i_nlink))
23291 + h_mode = h_inode->i_mode;
23294 + if (unlikely(S_ISDIR(h_mode)))
23296 + } else if (unlikely(!S_ISDIR(h_mode))) {
23301 + /* rename(2) case */
23303 + if (unlikely(d_is_positive(h_dentry)))
23308 + /* expected parent dir is locked */
23309 + if (unlikely(h_parent != h_dentry->d_parent))
23314 + * rmdir a dir may break the consistency on some filesystem.
23315 + * let's try heavy test.
23318 + sb = dentry->d_sb;
23319 + br = au_sbr(sb, bindex);
23320 + h_userns = au_br_userns(br);
23321 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23322 + && au_test_h_perm(h_userns, d_inode(h_parent),
23323 + MAY_EXEC | MAY_WRITE)))
23326 + h_ppath.dentry = h_parent;
23327 + h_ppath.mnt = au_br_mnt(br);
23328 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
23330 + if (IS_ERR(h_latest))
23332 + if (h_latest == h_dentry)
23341 + * decide the branch where we operate for @dentry. the branch index will be set
23342 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23343 + * dir for reverting.
23344 + * when a new whiteout is necessary, create it.
23346 +static struct dentry*
23347 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23348 + struct au_dtime *dt, struct au_pin *pin)
23350 + struct dentry *wh_dentry;
23351 + struct super_block *sb;
23352 + struct path h_path;
23353 + int err, need_wh;
23354 + unsigned int udba;
23355 + aufs_bindex_t bcpup;
23357 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23358 + wh_dentry = ERR_PTR(need_wh);
23359 + if (unlikely(need_wh < 0))
23362 + sb = dentry->d_sb;
23363 + udba = au_opt_udba(sb);
23365 + err = au_pin(pin, dentry, bcpup, udba,
23366 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23367 + wh_dentry = ERR_PTR(err);
23368 + if (unlikely(err))
23371 + h_path.dentry = au_pinned_h_parent(pin);
23372 + if (udba != AuOpt_UDBA_NONE
23373 + && au_dbtop(dentry) == bcpup) {
23374 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23375 + wh_dentry = ERR_PTR(err);
23376 + if (unlikely(err))
23380 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23381 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23382 + wh_dentry = NULL;
23384 + goto out; /* success, no need to create whiteout */
23386 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23387 + if (IS_ERR(wh_dentry))
23390 + /* returns with the parent is locked and wh_dentry is dget-ed */
23391 + goto out; /* success */
23396 + return wh_dentry;
23400 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23401 + * in order to be revertible and save time for removing many child whiteouts
23403 + * returns 1 when there are too many child whiteout and caller should remove
23404 + * them asynchronously. returns 0 when the number of children is enough small to
23405 + * remove now or the branch fs is a remote fs.
23406 + * otherwise return an error.
23408 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23409 + struct au_nhash *whlist, struct inode *dir)
23411 + int rmdir_later, err, dirwh;
23412 + struct dentry *h_dentry;
23413 + struct super_block *sb;
23414 + struct inode *inode;
23416 + sb = dentry->d_sb;
23417 + SiMustAnyLock(sb);
23418 + h_dentry = au_h_dptr(dentry, bindex);
23419 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23420 + if (unlikely(err))
23423 + /* stop monitoring */
23424 + inode = d_inode(dentry);
23425 + au_hn_free(au_hi(inode, bindex));
23427 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23428 + dirwh = au_sbi(sb)->si_dirwh;
23429 + rmdir_later = (dirwh <= 1);
23430 + if (!rmdir_later)
23431 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23434 + return rmdir_later;
23437 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23438 + if (unlikely(err)) {
23439 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23440 + h_dentry, bindex, err);
23450 + * final procedure for deleting a entry.
23451 + * maintain dentry and iattr.
23453 +static void epilog(struct inode *dir, struct dentry *dentry,
23454 + aufs_bindex_t bindex)
23456 + struct inode *inode;
23458 + inode = d_inode(dentry);
23460 + inode->i_ctime = dir->i_ctime;
23462 + au_dir_ts(dir, bindex);
23463 + inode_inc_iversion(dir);
23467 + * when an error happened, remove the created whiteout and revert everything.
23469 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23470 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23471 + struct dentry *dentry, struct au_dtime *dt)
23474 + struct path h_path = {
23475 + .dentry = wh_dentry,
23476 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23479 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23481 + au_set_dbwh(dentry, bwh);
23482 + au_dtime_revert(dt);
23486 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23490 +/* ---------------------------------------------------------------------- */
23492 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23495 + aufs_bindex_t bwh, bindex, btop;
23496 + struct inode *inode, *h_dir, *delegated;
23497 + struct dentry *parent, *wh_dentry;
23498 + /* to reduce stack size */
23500 + struct au_dtime dt;
23501 + struct au_pin pin;
23502 + struct path h_path;
23508 + a = kmalloc(sizeof(*a), GFP_NOFS);
23509 + if (unlikely(!a))
23512 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23513 + if (unlikely(err))
23515 + err = au_d_hashed_positive(dentry);
23516 + if (unlikely(err))
23518 + inode = d_inode(dentry);
23519 + IMustLock(inode);
23521 + if (unlikely(d_is_dir(dentry)))
23522 + goto out_unlock; /* possible? */
23524 + btop = au_dbtop(dentry);
23525 + bwh = au_dbwh(dentry);
23527 + parent = dentry->d_parent; /* dir inode is locked */
23528 + di_write_lock_parent(parent);
23529 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23531 + err = PTR_ERR(wh_dentry);
23532 + if (IS_ERR(wh_dentry))
23535 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23536 + a->h_path.dentry = au_h_dptr(dentry, btop);
23537 + dget(a->h_path.dentry);
23538 + if (bindex == btop) {
23539 + h_dir = au_pinned_h_dir(&a->pin);
23540 + delegated = NULL;
23541 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23542 + if (unlikely(err == -EWOULDBLOCK)) {
23543 + pr_warn("cannot retry for NFSv4 delegation"
23544 + " for an internal unlink\n");
23548 + /* dir inode is locked */
23549 + h_dir = d_inode(wh_dentry->d_parent);
23550 + IMustLock(h_dir);
23555 + vfsub_drop_nlink(inode);
23556 + epilog(dir, dentry, bindex);
23558 + /* update target timestamps */
23559 + if (bindex == btop) {
23560 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23562 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23564 + /* todo: this timestamp may be reverted later */
23565 + inode->i_ctime = h_dir->i_ctime;
23566 + goto out_unpin; /* success */
23573 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23580 + au_unpin(&a->pin);
23582 + dput(a->h_path.dentry);
23584 + di_write_unlock(parent);
23586 + aufs_read_unlock(dentry, AuLock_DW);
23593 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23595 + int err, rmdir_later;
23596 + aufs_bindex_t bwh, bindex, btop;
23597 + struct inode *inode;
23598 + struct dentry *parent, *wh_dentry, *h_dentry;
23599 + struct au_whtmp_rmdir *args;
23600 + /* to reduce stack size */
23602 + struct au_dtime dt;
23603 + struct au_pin pin;
23609 + a = kmalloc(sizeof(*a), GFP_NOFS);
23610 + if (unlikely(!a))
23613 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23614 + if (unlikely(err))
23616 + err = au_alive_dir(dentry);
23617 + if (unlikely(err))
23619 + inode = d_inode(dentry);
23620 + IMustLock(inode);
23622 + if (unlikely(!d_is_dir(dentry)))
23623 + goto out_unlock; /* possible? */
23626 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23627 + if (unlikely(!args))
23630 + parent = dentry->d_parent; /* dir inode is locked */
23631 + di_write_lock_parent(parent);
23632 + err = au_test_empty(dentry, &args->whlist);
23633 + if (unlikely(err))
23636 + btop = au_dbtop(dentry);
23637 + bwh = au_dbwh(dentry);
23639 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23641 + err = PTR_ERR(wh_dentry);
23642 + if (IS_ERR(wh_dentry))
23645 + h_dentry = au_h_dptr(dentry, btop);
23648 + if (bindex == btop) {
23649 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23651 + rmdir_later = err;
23655 + /* stop monitoring */
23656 + au_hn_free(au_hi(inode, btop));
23658 + /* dir inode is locked */
23659 + IMustLock(d_inode(wh_dentry->d_parent));
23664 + vfsub_dead_dir(inode);
23665 + au_set_dbdiropq(dentry, -1);
23666 + epilog(dir, dentry, bindex);
23668 + if (rmdir_later) {
23669 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23673 + goto out_unpin; /* success */
23681 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23688 + au_unpin(&a->pin);
23692 + di_write_unlock(parent);
23694 + au_whtmp_rmdir_free(args);
23696 + aufs_read_unlock(dentry, AuLock_DW);
23703 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23704 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23705 +++ linux/fs/aufs/i_op_ren.c 2022-03-21 14:49:05.726633010 +0100
23707 +// SPDX-License-Identifier: GPL-2.0
23709 + * Copyright (C) 2005-2021 Junjiro R. Okajima
23711 + * This program, aufs is free software; you can redistribute it and/or modify
23712 + * it under the terms of the GNU General Public License as published by
23713 + * the Free Software Foundation; either version 2 of the License, or
23714 + * (at your option) any later version.
23716 + * This program is distributed in the hope that it will be useful,
23717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23719 + * GNU General Public License for more details.
23721 + * You should have received a copy of the GNU General Public License
23722 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23726 + * inode operation (rename entry)
23727 + * todo: this is crazy monster
23730 +#include <linux/iversion.h>
23733 +enum { AuSRC, AuDST, AuSrcDst };
23734 +enum { AuPARENT, AuCHILD, AuParentChild };
23736 +#define AuRen_ISDIR_SRC 1
23737 +#define AuRen_ISDIR_DST (1 << 1)
23738 +#define AuRen_ISSAMEDIR (1 << 2)
23739 +#define AuRen_WHSRC (1 << 3)
23740 +#define AuRen_WHDST (1 << 4)
23741 +#define AuRen_MNT_WRITE (1 << 5)
23742 +#define AuRen_DT_DSTDIR (1 << 6)
23743 +#define AuRen_DIROPQ_SRC (1 << 7)
23744 +#define AuRen_DIROPQ_DST (1 << 8)
23745 +#define AuRen_DIRREN (1 << 9)
23746 +#define AuRen_DROPPED_SRC (1 << 10)
23747 +#define AuRen_DROPPED_DST (1 << 11)
23748 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23749 +#define au_fset_ren(flags, name) \
23750 + do { (flags) |= AuRen_##name; } while (0)
23751 +#define au_fclr_ren(flags, name) \
23752 + do { (flags) &= ~AuRen_##name; } while (0)
23754 +#ifndef CONFIG_AUFS_DIRREN
23755 +#undef AuRen_DIRREN
23756 +#define AuRen_DIRREN 0
23759 +struct au_ren_args {
23761 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23763 + struct inode *dir, *inode;
23764 + struct au_hinode *hdir, *hinode;
23765 + struct au_dtime dt[AuParentChild];
23766 + aufs_bindex_t btop, bdiropq;
23769 +#define src_dentry sd[AuSRC].dentry
23770 +#define src_dir sd[AuSRC].dir
23771 +#define src_inode sd[AuSRC].inode
23772 +#define src_h_dentry sd[AuSRC].h_dentry
23773 +#define src_parent sd[AuSRC].parent
23774 +#define src_h_parent sd[AuSRC].h_parent
23775 +#define src_wh_dentry sd[AuSRC].wh_dentry
23776 +#define src_hdir sd[AuSRC].hdir
23777 +#define src_hinode sd[AuSRC].hinode
23778 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23779 +#define src_dt sd[AuSRC].dt
23780 +#define src_btop sd[AuSRC].btop
23781 +#define src_bdiropq sd[AuSRC].bdiropq
23783 +#define dst_dentry sd[AuDST].dentry
23784 +#define dst_dir sd[AuDST].dir
23785 +#define dst_inode sd[AuDST].inode
23786 +#define dst_h_dentry sd[AuDST].h_dentry
23787 +#define dst_parent sd[AuDST].parent
23788 +#define dst_h_parent sd[AuDST].h_parent
23789 +#define dst_wh_dentry sd[AuDST].wh_dentry
23790 +#define dst_hdir sd[AuDST].hdir
23791 +#define dst_hinode sd[AuDST].hinode
23792 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23793 +#define dst_dt sd[AuDST].dt
23794 +#define dst_btop sd[AuDST].btop
23795 +#define dst_bdiropq sd[AuDST].bdiropq
23797 + struct dentry *h_trap;
23798 + struct au_branch *br;
23799 + struct path h_path;
23800 + struct au_nhash whlist;
23801 + aufs_bindex_t btgt, src_bwh;
23804 + unsigned short auren_flags;
23805 + unsigned char flags; /* syscall parameter */
23806 + unsigned char exchange;
23809 + struct au_whtmp_rmdir *thargs;
23810 + struct dentry *h_dst;
23811 + struct au_hinode *h_root;
23814 +/* ---------------------------------------------------------------------- */
23817 + * functions for reverting.
23818 + * when an error happened in a single rename systemcall, we should revert
23819 + * everything as if nothing happened.
23820 + * we don't need to revert the copied-up/down the parent dir since they are
23824 +#define RevertFailure(fmt, ...) do { \
23825 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23826 + ##__VA_ARGS__, err, rerr); \
23830 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23833 + struct dentry *d;
23834 +#define src_or_dst(member) a->sd[idx].member
23836 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23837 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23838 + rerr = au_diropq_remove(d, a->btgt);
23839 + au_hn_inode_unlock(src_or_dst(hinode));
23840 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23842 + RevertFailure("remove diropq %pd", d);
23844 +#undef src_or_dst_
23847 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23849 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23850 + au_ren_do_rev_diropq(err, a, AuSRC);
23851 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23852 + au_ren_do_rev_diropq(err, a, AuDST);
23855 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23858 + struct inode *delegated;
23859 + struct path h_ppath = {
23860 + .dentry = a->src_h_parent,
23861 + .mnt = a->h_path.mnt
23864 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23865 + rerr = PTR_ERR(a->h_path.dentry);
23866 + if (IS_ERR(a->h_path.dentry)) {
23867 + RevertFailure("lkup one %pd", a->src_dentry);
23871 + delegated = NULL;
23872 + rerr = vfsub_rename(a->dst_h_dir,
23873 + au_h_dptr(a->src_dentry, a->btgt),
23874 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23875 + if (unlikely(rerr == -EWOULDBLOCK)) {
23876 + pr_warn("cannot retry for NFSv4 delegation"
23877 + " for an internal rename\n");
23880 + d_drop(a->h_path.dentry);
23881 + dput(a->h_path.dentry);
23882 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23884 + RevertFailure("rename %pd", a->src_dentry);
23887 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23890 + struct inode *delegated;
23891 + struct path h_ppath = {
23892 + .dentry = a->dst_h_parent,
23893 + .mnt = a->h_path.mnt
23896 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23897 + rerr = PTR_ERR(a->h_path.dentry);
23898 + if (IS_ERR(a->h_path.dentry)) {
23899 + RevertFailure("lkup one %pd", a->dst_dentry);
23902 + if (d_is_positive(a->h_path.dentry)) {
23903 + d_drop(a->h_path.dentry);
23904 + dput(a->h_path.dentry);
23908 + delegated = NULL;
23909 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23910 + &delegated, a->flags);
23911 + if (unlikely(rerr == -EWOULDBLOCK)) {
23912 + pr_warn("cannot retry for NFSv4 delegation"
23913 + " for an internal rename\n");
23916 + d_drop(a->h_path.dentry);
23917 + dput(a->h_path.dentry);
23919 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23921 + RevertFailure("rename %pd", a->h_dst);
23924 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23928 + a->h_path.dentry = a->src_wh_dentry;
23929 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23930 + au_set_dbwh(a->src_dentry, a->src_bwh);
23932 + RevertFailure("unlink %pd", a->src_wh_dentry);
23934 +#undef RevertFailure
23936 +/* ---------------------------------------------------------------------- */
23939 + * when we have to copyup the renaming entry, do it with the rename-target name
23940 + * in order to minimize the cost (the later actual rename is unnecessary).
23941 + * otherwise rename it on the target branch.
23943 +static int au_ren_or_cpup(struct au_ren_args *a)
23946 + struct dentry *d;
23947 + struct inode *delegated;
23949 + d = a->src_dentry;
23950 + if (au_dbtop(d) == a->btgt) {
23951 + a->h_path.dentry = a->dst_h_dentry;
23952 + AuDebugOn(au_dbtop(d) != a->btgt);
23953 + delegated = NULL;
23954 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
23955 + a->dst_h_dir, &a->h_path, &delegated,
23957 + if (unlikely(err == -EWOULDBLOCK)) {
23958 + pr_warn("cannot retry for NFSv4 delegation"
23959 + " for an internal rename\n");
23965 + if (!err && a->h_dst)
23966 + /* it will be set to dinfo later */
23972 +/* cf. aufs_rmdir() */
23973 +static int au_ren_del_whtmp(struct au_ren_args *a)
23976 + struct inode *dir;
23978 + dir = a->dst_dir;
23979 + SiMustAnyLock(dir->i_sb);
23980 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
23981 + au_sbi(dir->i_sb)->si_dirwh)
23982 + || au_test_fs_remote(a->h_dst->d_sb)) {
23983 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
23984 + if (unlikely(err))
23985 + pr_warn("failed removing whtmp dir %pd (%d), "
23986 + "ignored.\n", a->h_dst, err);
23988 + au_nhash_wh_free(&a->thargs->whlist);
23989 + a->thargs->whlist = a->whlist;
23990 + a->whlist.nh_num = 0;
23991 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
23993 + a->thargs = NULL;
23999 +/* make it 'opaque' dir. */
24000 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24003 + struct dentry *d, *diropq;
24004 +#define src_or_dst(member) a->sd[idx].member
24007 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24008 + src_or_dst(bdiropq) = au_dbdiropq(d);
24009 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24010 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24011 + diropq = au_diropq_create(d, a->btgt);
24012 + au_hn_inode_unlock(src_or_dst(hinode));
24013 + if (IS_ERR(diropq))
24014 + err = PTR_ERR(diropq);
24018 +#undef src_or_dst_
24022 +static int au_ren_diropq(struct au_ren_args *a)
24025 + unsigned char always;
24026 + struct dentry *d;
24029 + d = a->dst_dentry; /* already renamed on the branch */
24030 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24031 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24032 + && !au_ftest_ren(a->auren_flags, DIRREN)
24033 + && a->btgt != au_dbdiropq(a->src_dentry)
24034 + && (a->dst_wh_dentry
24035 + || a->btgt <= au_dbdiropq(d)
24036 + /* hide the lower to keep xino */
24037 + /* the lowers may not be a dir, but we hide them anyway */
24038 + || a->btgt < au_dbbot(d)
24041 + err = au_ren_do_diropq(a, AuSRC);
24042 + if (unlikely(err))
24044 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24046 + if (!a->exchange)
24047 + goto out; /* success */
24049 + d = a->src_dentry; /* already renamed on the branch */
24050 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24051 + && a->btgt != au_dbdiropq(a->dst_dentry)
24052 + && (a->btgt < au_dbdiropq(d)
24053 + || a->btgt < au_dbbot(d)
24055 + AuDbgDentry(a->src_dentry);
24056 + AuDbgDentry(a->dst_dentry);
24057 + err = au_ren_do_diropq(a, AuDST);
24058 + if (unlikely(err))
24059 + goto out_rev_src;
24060 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24062 + goto out; /* success */
24065 + AuDbg("err %d, reverting src\n", err);
24066 + au_ren_rev_diropq(err, a);
24071 +static int do_rename(struct au_ren_args *a)
24074 + struct dentry *d, *h_d;
24076 + if (!a->exchange) {
24077 + /* prepare workqueue args for asynchronous rmdir */
24078 + h_d = a->dst_h_dentry;
24079 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24080 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24081 + && d_is_positive(h_d)) {
24083 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24085 + if (unlikely(!a->thargs))
24087 + a->h_dst = dget(h_d);
24090 + /* create whiteout for src_dentry */
24091 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24092 + a->src_bwh = au_dbwh(a->src_dentry);
24093 + AuDebugOn(a->src_bwh >= 0);
24094 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24095 + a->src_h_parent);
24096 + err = PTR_ERR(a->src_wh_dentry);
24097 + if (IS_ERR(a->src_wh_dentry))
24101 + /* lookup whiteout for dentry */
24102 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24103 + h_d = au_wh_lkup(a->dst_h_parent,
24104 + &a->dst_dentry->d_name, a->br);
24105 + err = PTR_ERR(h_d);
24108 + if (d_is_negative(h_d))
24111 + a->dst_wh_dentry = h_d;
24114 + /* rename dentry to tmpwh */
24116 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24117 + if (unlikely(err))
24120 + d = a->dst_dentry;
24121 + au_set_h_dptr(d, a->btgt, NULL);
24122 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24123 + if (unlikely(err))
24125 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24129 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24130 +#if 0 /* debugging */
24131 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24132 + && d_is_positive(a->dst_h_dentry)
24133 + && a->src_btop != a->btgt);
24136 + /* rename by vfs_rename or cpup */
24137 + err = au_ren_or_cpup(a);
24138 + if (unlikely(err))
24139 + /* leave the copied-up one */
24142 + /* make dir opaque */
24143 + err = au_ren_diropq(a);
24144 + if (unlikely(err))
24147 + /* update target timestamps */
24148 + if (a->exchange) {
24149 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24150 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24151 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24152 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24154 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24155 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24156 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24157 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24159 + if (!a->exchange) {
24160 + /* remove whiteout for dentry */
24161 + if (a->dst_wh_dentry) {
24162 + a->h_path.dentry = a->dst_wh_dentry;
24163 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24165 + if (unlikely(err))
24169 + /* remove whtmp */
24171 + au_ren_del_whtmp(a); /* ignore this error */
24173 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24176 + goto out_success;
24179 + au_ren_rev_diropq(err, a);
24181 + au_ren_rev_rename(err, a);
24185 + au_ren_rev_whtmp(err, a);
24187 + dput(a->dst_wh_dentry);
24188 + a->dst_wh_dentry = NULL;
24190 + if (a->src_wh_dentry)
24191 + au_ren_rev_whsrc(err, a);
24193 + dput(a->src_wh_dentry);
24194 + dput(a->dst_wh_dentry);
24198 + au_whtmp_rmdir_free(a->thargs);
24199 + a->thargs = NULL;
24205 +/* ---------------------------------------------------------------------- */
24208 + * test if @dentry dir can be rename destination or not.
24209 + * success means, it is a logically empty dir.
24211 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24213 + return au_test_empty(dentry, whlist);
24217 + * test if @a->src_dentry dir can be rename source or not.
24218 + * if it can, return 0.
24220 + * - it is a logically empty dir.
24221 + * - or, it exists on writable branch and has no children including whiteouts
24222 + * on the lower branch unless DIRREN is on.
24224 +static int may_rename_srcdir(struct au_ren_args *a)
24227 + unsigned int rdhash;
24228 + aufs_bindex_t btop, btgt;
24229 + struct dentry *dentry;
24230 + struct super_block *sb;
24231 + struct au_sbinfo *sbinfo;
24233 + dentry = a->src_dentry;
24234 + sb = dentry->d_sb;
24235 + sbinfo = au_sbi(sb);
24236 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24237 + au_fset_ren(a->auren_flags, DIRREN);
24240 + btop = au_dbtop(dentry);
24241 + if (btop != btgt) {
24242 + struct au_nhash whlist;
24244 + SiMustAnyLock(sb);
24245 + rdhash = sbinfo->si_rdhash;
24247 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24249 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24250 + if (unlikely(err))
24252 + err = au_test_empty(dentry, &whlist);
24253 + au_nhash_wh_free(&whlist);
24257 + if (btop == au_dbtaildir(dentry))
24258 + return 0; /* success */
24260 + err = au_test_empty_lower(dentry);
24263 + if (err == -ENOTEMPTY) {
24264 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24267 + AuWarn1("renaming dir who has child(ren) on multiple "
24268 + "branches, is not supported\n");
24275 +/* side effect: sets whlist and h_dentry */
24276 +static int au_ren_may_dir(struct au_ren_args *a)
24279 + unsigned int rdhash;
24280 + struct dentry *d;
24282 + d = a->dst_dentry;
24283 + SiMustAnyLock(d->d_sb);
24286 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24287 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24289 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24290 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24291 + if (unlikely(err))
24294 + if (!a->exchange) {
24295 + au_set_dbtop(d, a->dst_btop);
24296 + err = may_rename_dstdir(d, &a->whlist);
24297 + au_set_dbtop(d, a->btgt);
24299 + err = may_rename_srcdir(a);
24301 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24302 + if (unlikely(err))
24305 + d = a->src_dentry;
24306 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24307 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24308 + err = may_rename_srcdir(a);
24309 + if (unlikely(err)) {
24310 + au_nhash_wh_free(&a->whlist);
24311 + a->whlist.nh_num = 0;
24318 +/* ---------------------------------------------------------------------- */
24321 + * simple tests for rename.
24322 + * following the checks in vfs, plus the parent-child relationship.
24324 +static int au_may_ren(struct au_ren_args *a)
24327 + struct inode *h_inode;
24329 + if (a->src_btop == a->btgt) {
24330 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24331 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24332 + if (unlikely(err))
24335 + if (unlikely(a->src_h_dentry == a->h_trap))
24340 + if (a->dst_btop != a->btgt)
24343 + err = -ENOTEMPTY;
24344 + if (unlikely(a->dst_h_dentry == a->h_trap))
24348 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24349 + if (d_really_is_negative(a->dst_dentry)) {
24350 + if (d_is_negative(a->dst_h_dentry))
24351 + err = au_may_add(a->dst_dentry, a->btgt,
24352 + a->dst_h_parent, isdir);
24354 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24356 + h_inode = d_inode(a->dst_h_dentry);
24357 + if (h_inode->i_nlink)
24358 + err = au_may_del(a->dst_dentry, a->btgt,
24359 + a->dst_h_parent, isdir);
24363 + if (unlikely(err == -ENOENT || err == -EEXIST))
24369 +/* ---------------------------------------------------------------------- */
24374 + * - src_dir and dir by lock_rename()
24375 + * - inode if exists
24378 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24380 + * + di_write_lock2_child()
24381 + * + di_write_lock_child()
24382 + * + ii_write_lock_child()
24383 + * + di_write_lock_child2()
24384 + * + ii_write_lock_child2()
24385 + * + src_parent and parent
24386 + * + di_write_lock_parent()
24387 + * + ii_write_lock_parent()
24388 + * + di_write_lock_parent2()
24389 + * + ii_write_lock_parent2()
24390 + * + lower src_dir and dir by vfsub_lock_rename()
24391 + * + verify the every relationships between child and parent. if any
24392 + * of them failed, unlock all and return -EBUSY.
24394 +static void au_ren_unlock(struct au_ren_args *a)
24396 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24397 + a->dst_h_parent, a->dst_hdir);
24398 + if (au_ftest_ren(a->auren_flags, DIRREN)
24400 + au_hn_inode_unlock(a->h_root);
24401 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24402 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24405 +static int au_ren_lock(struct au_ren_args *a)
24408 + unsigned int udba;
24411 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24412 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24413 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24414 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24416 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24417 + if (unlikely(err))
24419 + au_fset_ren(a->auren_flags, MNT_WRITE);
24420 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24421 + struct dentry *root;
24422 + struct inode *dir;
24425 + * sbinfo is already locked, so this ii_read_lock is
24426 + * unnecessary. but our debugging feature checks it.
24428 + root = a->src_inode->i_sb->s_root;
24429 + if (root != a->src_parent && root != a->dst_parent) {
24430 + dir = d_inode(root);
24431 + ii_read_lock_parent3(dir);
24432 + a->h_root = au_hi(dir, a->btgt);
24433 + ii_read_unlock(dir);
24434 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24437 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24438 + a->dst_h_parent, a->dst_hdir);
24439 + udba = au_opt_udba(a->src_dentry->d_sb);
24440 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24441 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24442 + err = au_busy_or_stale();
24443 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24444 + err = au_h_verify(a->src_h_dentry, udba,
24445 + d_inode(a->src_h_parent), a->src_h_parent,
24447 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24448 + err = au_h_verify(a->dst_h_dentry, udba,
24449 + d_inode(a->dst_h_parent), a->dst_h_parent,
24452 + goto out; /* success */
24454 + err = au_busy_or_stale();
24455 + au_ren_unlock(a);
24461 +/* ---------------------------------------------------------------------- */
24463 +static void au_ren_refresh_dir(struct au_ren_args *a)
24465 + struct inode *dir;
24467 + dir = a->dst_dir;
24468 + inode_inc_iversion(dir);
24469 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24470 + /* is this updating defined in POSIX? */
24471 + au_cpup_attr_timesizes(a->src_inode);
24472 + au_cpup_attr_nlink(dir, /*force*/1);
24474 + au_dir_ts(dir, a->btgt);
24476 + if (a->exchange) {
24477 + dir = a->src_dir;
24478 + inode_inc_iversion(dir);
24479 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24480 + /* is this updating defined in POSIX? */
24481 + au_cpup_attr_timesizes(a->dst_inode);
24482 + au_cpup_attr_nlink(dir, /*force*/1);
24484 + au_dir_ts(dir, a->btgt);
24487 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24490 + dir = a->src_dir;
24491 + inode_inc_iversion(dir);
24492 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24493 + au_cpup_attr_nlink(dir, /*force*/1);
24494 + au_dir_ts(dir, a->btgt);
24497 +static void au_ren_refresh(struct au_ren_args *a)
24499 + aufs_bindex_t bbot, bindex;
24500 + struct dentry *d, *h_d;
24501 + struct inode *i, *h_i;
24502 + struct super_block *sb;
24504 + d = a->dst_dentry;
24507 + /* already dget-ed by au_ren_or_cpup() */
24508 + au_set_h_dptr(d, a->btgt, a->h_dst);
24510 + i = a->dst_inode;
24512 + if (!a->exchange) {
24513 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24514 + vfsub_drop_nlink(i);
24516 + vfsub_dead_dir(i);
24517 + au_cpup_attr_timesizes(i);
24519 + au_update_dbrange(d, /*do_put_zero*/1);
24521 + au_cpup_attr_nlink(i, /*force*/1);
24524 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24525 + au_set_h_dptr(d, bindex, NULL);
24526 + bbot = au_dbbot(d);
24527 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24528 + au_set_h_dptr(d, bindex, NULL);
24529 + au_update_dbrange(d, /*do_put_zero*/0);
24533 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24534 + d_drop(a->src_dentry);
24535 + if (au_ftest_ren(a->auren_flags, DIRREN))
24536 + au_set_dbwh(a->src_dentry, -1);
24540 + d = a->src_dentry;
24541 + au_set_dbwh(d, -1);
24542 + bbot = au_dbbot(d);
24543 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24544 + h_d = au_h_dptr(d, bindex);
24546 + au_set_h_dptr(d, bindex, NULL);
24548 + au_set_dbbot(d, a->btgt);
24551 + i = a->src_inode;
24552 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24553 + return; /* success */
24555 + bbot = au_ibbot(i);
24556 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24557 + h_i = au_h_iptr(i, bindex);
24559 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24560 + /* ignore this error */
24561 + au_set_h_iptr(i, bindex, NULL, 0);
24564 + au_set_ibbot(i, a->btgt);
24567 +/* ---------------------------------------------------------------------- */
24569 +/* mainly for link(2) and rename(2) */
24570 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24572 + aufs_bindex_t bdiropq, bwh;
24573 + struct dentry *parent;
24574 + struct au_branch *br;
24576 + parent = dentry->d_parent;
24577 + IMustLock(d_inode(parent)); /* dir is locked */
24579 + bdiropq = au_dbdiropq(parent);
24580 + bwh = au_dbwh(dentry);
24581 + br = au_sbr(dentry->d_sb, btgt);
24582 + if (au_br_rdonly(br)
24583 + || (0 <= bdiropq && bdiropq < btgt)
24584 + || (0 <= bwh && bwh < btgt))
24587 + AuDbg("btgt %d\n", btgt);
24591 +/* sets src_btop, dst_btop and btgt */
24592 +static int au_ren_wbr(struct au_ren_args *a)
24595 + struct au_wr_dir_args wr_dir_args = {
24596 + /* .force_btgt = -1, */
24597 + .flags = AuWrDir_ADD_ENTRY
24600 + a->src_btop = au_dbtop(a->src_dentry);
24601 + a->dst_btop = au_dbtop(a->dst_dentry);
24602 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24603 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24604 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24605 + wr_dir_args.force_btgt = a->src_btop;
24606 + if (a->dst_inode && a->dst_btop < a->src_btop)
24607 + wr_dir_args.force_btgt = a->dst_btop;
24608 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24609 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24612 + au_update_dbtop(a->dst_dentry);
24617 +static void au_ren_dt(struct au_ren_args *a)
24619 + a->h_path.dentry = a->src_h_parent;
24620 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24621 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24622 + a->h_path.dentry = a->dst_h_parent;
24623 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24626 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24627 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24631 + a->h_path.dentry = a->src_h_dentry;
24632 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24633 + if (d_is_positive(a->dst_h_dentry)) {
24634 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24635 + a->h_path.dentry = a->dst_h_dentry;
24636 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24640 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24642 + struct dentry *h_d;
24643 + struct inode *h_inode;
24645 + au_dtime_revert(a->src_dt + AuPARENT);
24646 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24647 + au_dtime_revert(a->dst_dt + AuPARENT);
24649 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24650 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24651 + h_inode = d_inode(h_d);
24652 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24653 + au_dtime_revert(a->src_dt + AuCHILD);
24654 + inode_unlock(h_inode);
24656 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24657 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24658 + h_inode = d_inode(h_d);
24659 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24660 + au_dtime_revert(a->dst_dt + AuCHILD);
24661 + inode_unlock(h_inode);
24666 +/* ---------------------------------------------------------------------- */
24668 +int aufs_rename(struct user_namespace *userns,
24669 + struct inode *_src_dir, struct dentry *_src_dentry,
24670 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24671 + unsigned int _flags)
24673 + int err, lock_flags;
24675 + /* reduce stack space */
24676 + struct au_ren_args *a;
24677 + struct au_pin pin;
24679 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24680 + IMustLock(_src_dir);
24681 + IMustLock(_dst_dir);
24684 + if (unlikely(_flags & RENAME_WHITEOUT))
24688 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24689 + a = kzalloc(sizeof(*a), GFP_NOFS);
24690 + if (unlikely(!a))
24693 + a->flags = _flags;
24694 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24695 + && RENAME_EXCHANGE > U8_MAX);
24696 + a->exchange = _flags & RENAME_EXCHANGE;
24697 + a->src_dir = _src_dir;
24698 + a->src_dentry = _src_dentry;
24699 + a->src_inode = NULL;
24700 + if (d_really_is_positive(a->src_dentry))
24701 + a->src_inode = d_inode(a->src_dentry);
24702 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24703 + a->dst_dir = _dst_dir;
24704 + a->dst_dentry = _dst_dentry;
24705 + a->dst_inode = NULL;
24706 + if (d_really_is_positive(a->dst_dentry))
24707 + a->dst_inode = d_inode(a->dst_dentry);
24708 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24709 + if (a->dst_inode) {
24711 + * if EXCHANGE && src is non-dir && dst is dir,
24712 + * dst is not locked.
24714 + /* IMustLock(a->dst_inode); */
24715 + au_igrab(a->dst_inode);
24719 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24720 + if (d_is_dir(a->src_dentry)) {
24721 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24722 + if (unlikely(!a->exchange
24723 + && d_really_is_positive(a->dst_dentry)
24724 + && !d_is_dir(a->dst_dentry)))
24726 + lock_flags |= AuLock_DIRS;
24728 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24729 + au_fset_ren(a->auren_flags, ISDIR_DST);
24730 + if (unlikely(!a->exchange
24731 + && d_really_is_positive(a->src_dentry)
24732 + && !d_is_dir(a->src_dentry)))
24734 + lock_flags |= AuLock_DIRS;
24736 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24738 + if (unlikely(err))
24741 + err = au_d_hashed_positive(a->src_dentry);
24742 + if (unlikely(err))
24745 + if (a->dst_inode) {
24747 + * If it is a dir, VFS unhash it before this
24748 + * function. It means we cannot rely upon d_unhashed().
24750 + if (unlikely(!a->dst_inode->i_nlink))
24752 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24753 + err = au_d_hashed_positive(a->dst_dentry);
24754 + if (unlikely(err && !a->exchange))
24756 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24758 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24762 + * is it possible?
24763 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24764 + * there may exist a problem somewhere else.
24767 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24770 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24771 + di_write_lock_parent(a->dst_parent);
24773 + /* which branch we process */
24774 + err = au_ren_wbr(a);
24775 + if (unlikely(err < 0))
24777 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24778 + a->h_path.mnt = au_br_mnt(a->br);
24780 + /* are they available to be renamed */
24781 + err = au_ren_may_dir(a);
24782 + if (unlikely(err))
24783 + goto out_children;
24785 + /* prepare the writable parent dir on the same branch */
24786 + if (a->dst_btop == a->btgt) {
24787 + au_fset_ren(a->auren_flags, WHDST);
24789 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24790 + if (unlikely(err))
24791 + goto out_children;
24795 + if (!a->exchange) {
24796 + if (a->src_dir != a->dst_dir) {
24798 + * this temporary unlock is safe,
24799 + * because both dir->i_mutex are locked.
24801 + di_write_unlock(a->dst_parent);
24802 + di_write_lock_parent(a->src_parent);
24803 + err = au_wr_dir_need_wh(a->src_dentry,
24804 + au_ftest_ren(a->auren_flags,
24807 + di_write_unlock(a->src_parent);
24808 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24810 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24812 + err = au_wr_dir_need_wh(a->src_dentry,
24813 + au_ftest_ren(a->auren_flags,
24817 + if (unlikely(err < 0))
24818 + goto out_children;
24820 + au_fset_ren(a->auren_flags, WHSRC);
24823 + if (a->src_btop != a->btgt) {
24824 + err = au_pin(&pin, a->src_dentry, a->btgt,
24825 + au_opt_udba(a->src_dentry->d_sb),
24826 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24828 + struct au_cp_generic cpg = {
24829 + .dentry = a->src_dentry,
24831 + .bsrc = a->src_btop,
24834 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24836 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24837 + err = au_sio_cpup_simple(&cpg);
24840 + if (unlikely(err))
24841 + goto out_children;
24842 + a->src_btop = a->btgt;
24843 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24844 + if (!a->exchange)
24845 + au_fset_ren(a->auren_flags, WHSRC);
24849 + if (a->exchange && a->dst_inode
24850 + && a->dst_btop != a->btgt) {
24851 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24852 + au_opt_udba(a->dst_dentry->d_sb),
24853 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24855 + struct au_cp_generic cpg = {
24856 + .dentry = a->dst_dentry,
24858 + .bsrc = a->dst_btop,
24861 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24863 + err = au_sio_cpup_simple(&cpg);
24866 + if (unlikely(err))
24867 + goto out_children;
24868 + a->dst_btop = a->btgt;
24869 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24872 + /* lock them all */
24873 + err = au_ren_lock(a);
24874 + if (unlikely(err))
24875 + /* leave the copied-up one */
24876 + goto out_children;
24878 + if (!a->exchange) {
24879 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24880 + err = au_may_ren(a);
24881 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24882 + err = -ENAMETOOLONG;
24883 + if (unlikely(err))
24887 + /* store timestamps to be revertible */
24890 + /* store dirren info */
24891 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24892 + err = au_dr_rename(a->src_dentry, a->btgt,
24893 + &a->dst_dentry->d_name, &rev);
24895 + if (unlikely(err))
24900 + err = do_rename(a);
24901 + if (unlikely(err))
24904 + if (au_ftest_ren(a->auren_flags, DIRREN))
24905 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24907 + /* update dir attributes */
24908 + au_ren_refresh_dir(a);
24910 + /* dput/iput all lower dentries */
24911 + au_ren_refresh(a);
24913 + goto out_hdir; /* success */
24916 + if (au_ftest_ren(a->auren_flags, DIRREN))
24917 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24919 + au_ren_rev_dt(err, a);
24921 + au_ren_unlock(a);
24923 + au_nhash_wh_free(&a->whlist);
24924 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24925 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24926 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24927 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24931 + if (d_unhashed(a->src_dentry))
24932 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24933 + if (d_unhashed(a->dst_dentry))
24934 + au_fset_ren(a->auren_flags, DROPPED_DST);
24935 + if (!a->exchange)
24936 + d_move(a->src_dentry, a->dst_dentry);
24938 + d_exchange(a->src_dentry, a->dst_dentry);
24939 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
24940 + d_drop(a->dst_dentry);
24942 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
24943 + d_drop(a->src_dentry);
24945 + au_update_dbtop(a->dst_dentry);
24946 + if (!a->dst_inode)
24947 + d_drop(a->dst_dentry);
24949 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24950 + di_write_unlock(a->dst_parent);
24952 + di_write_unlock2(a->src_parent, a->dst_parent);
24954 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
24956 + iput(a->dst_inode);
24958 + au_whtmp_rmdir_free(a->thargs);
24964 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
24965 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
24966 +++ linux/fs/aufs/Kconfig 2022-03-21 14:49:05.716633010 +0100
24968 +# SPDX-License-Identifier: GPL-2.0
24970 + tristate "Aufs (Advanced multi layered unification filesystem) support"
24972 + Aufs is a stackable unification filesystem such as Unionfs,
24973 + which unifies several directories and provides a merged single
24975 + In the early days, aufs was entirely re-designed and
24976 + re-implemented Unionfs Version 1.x series. Introducing many
24977 + original ideas, approaches and improvements, it becomes totally
24978 + different from Unionfs while keeping the basic features.
24982 + prompt "Maximum number of branches"
24983 + default AUFS_BRANCH_MAX_127
24985 + Specifies the maximum number of branches (or member directories)
24986 + in a single aufs. The larger value consumes more system
24987 + resources and has a minor impact to performance.
24988 +config AUFS_BRANCH_MAX_127
24991 + Specifies the maximum number of branches (or member directories)
24992 + in a single aufs. The larger value consumes more system
24993 + resources and has a minor impact to performance.
24994 +config AUFS_BRANCH_MAX_511
24997 + Specifies the maximum number of branches (or member directories)
24998 + in a single aufs. The larger value consumes more system
24999 + resources and has a minor impact to performance.
25000 +config AUFS_BRANCH_MAX_1023
25003 + Specifies the maximum number of branches (or member directories)
25004 + in a single aufs. The larger value consumes more system
25005 + resources and has a minor impact to performance.
25006 +config AUFS_BRANCH_MAX_32767
25009 + Specifies the maximum number of branches (or member directories)
25010 + in a single aufs. The larger value consumes more system
25011 + resources and has a minor impact to performance.
25014 +config AUFS_SBILIST
25016 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25019 + Automatic configuration for internal use.
25020 + When aufs supports Magic SysRq or /proc, enabled automatically.
25022 +config AUFS_HNOTIFY
25023 + bool "Detect direct branch access (bypassing aufs)"
25025 + If you want to modify files on branches directly, eg. bypassing aufs,
25026 + and want aufs to detect the changes of them fully, then enable this
25027 + option and use 'udba=notify' mount option.
25028 + Currently there is only one available configuration, "fsnotify".
25029 + It will have a negative impact to the performance.
25030 + See detail in aufs.5.
25033 + prompt "method" if AUFS_HNOTIFY
25034 + default AUFS_HFSNOTIFY
25035 +config AUFS_HFSNOTIFY
25040 +config AUFS_EXPORT
25041 + bool "NFS-exportable aufs"
25042 + depends on EXPORTFS
25044 + If you want to export your mounted aufs via NFS, then enable this
25045 + option. There are several requirements for this configuration.
25046 + See detail in aufs.5.
25048 +config AUFS_INO_T_64
25050 + depends on AUFS_EXPORT
25051 + depends on 64BIT && !(ALPHA || S390)
25054 + Automatic configuration for internal use.
25055 + /* typedef unsigned long/int __kernel_ino_t */
25056 + /* alpha and s390x are int */
25059 + bool "support for XATTR/EA (including Security Labels)"
25061 + If your branch fs supports XATTR/EA and you want to make them
25062 + available in aufs too, then enable this opsion and specify the
25063 + branch attributes for EA.
25064 + See detail in aufs.5.
25067 + bool "File-based Hierarchical Storage Management"
25069 + Hierarchical Storage Management (or HSM) is a well-known feature
25070 + in the storage world. Aufs provides this feature as file-based.
25071 + with multiple branches.
25072 + These multiple branches are prioritized, ie. the topmost one
25073 + should be the fastest drive and be used heavily.
25076 + bool "Readdir in userspace"
25078 + Aufs has two methods to provide a merged view for a directory,
25079 + by a user-space library and by kernel-space natively. The latter
25080 + is always enabled but sometimes large and slow.
25081 + If you enable this option, install the library in aufs2-util
25082 + package, and set some environment variables for your readdir(3),
25083 + then the work will be handled in user-space which generally
25084 + shows better performance in most cases.
25085 + See detail in aufs.5.
25087 +config AUFS_DIRREN
25088 + bool "Workaround for rename(2)-ing a directory"
25090 + By default, aufs returns EXDEV error in renameing a dir who has
25091 + his child on the lower branch, since it is a bad idea to issue
25092 + rename(2) internally for every lower branch. But user may not
25093 + accept this behaviour. So here is a workaround to allow such
25094 + rename(2) and store some extra infromation on the writable
25095 + branch. Obviously this costs high (and I don't like it).
25096 + To use this feature, you need to enable this configuration AND
25097 + to specify the mount option `dirren.'
25098 + See details in aufs.5 and the design documents.
25101 + bool "Show whiteouts"
25103 + If you want to make the whiteouts in aufs visible, then enable
25104 + this option and specify 'shwh' mount option. Although it may
25105 + sounds like philosophy or something, but in technically it
25106 + simply shows the name of whiteout with keeping its behaviour.
25108 +config AUFS_BR_RAMFS
25109 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25111 + If you want to use ramfs as an aufs branch fs, then enable this
25112 + option. Generally tmpfs is recommended.
25113 + Aufs prohibited them to be a branch fs by default, because
25114 + initramfs becomes unusable after switch_root or something
25115 + generally. If you sets initramfs as an aufs branch and boot your
25116 + system by switch_root, you will meet a problem easily since the
25117 + files in initramfs may be inaccessible.
25118 + Unless you are going to use ramfs as an aufs branch fs without
25119 + switch_root or something, leave it N.
25121 +config AUFS_BR_FUSE
25122 + bool "Fuse fs as an aufs branch"
25123 + depends on FUSE_FS
25126 + If you want to use fuse-based userspace filesystem as an aufs
25127 + branch fs, then enable this option.
25128 + It implements the internal poll(2) operation which is
25129 + implemented by fuse only (curretnly).
25134 + Automatic configuration for internal use.
25136 +config AUFS_BR_HFSPLUS
25137 + bool "Hfsplus as an aufs branch"
25138 + depends on HFSPLUS_FS
25141 + If you want to use hfsplus fs as an aufs branch fs, then enable
25142 + this option. This option introduces a small overhead at
25143 + copying-up a file on hfsplus.
25145 +config AUFS_BDEV_LOOP
25147 + depends on BLK_DEV_LOOP
25150 + Automatic configuration for internal use.
25151 + Convert =[ym] into =y.
25154 + bool "Debug aufs"
25156 + Enable this to compile aufs internal debug code.
25157 + It will have a negative impact to the performance.
25159 +config AUFS_MAGIC_SYSRQ
25161 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25164 + Automatic configuration for internal use.
25165 + When aufs supports Magic SysRq, enabled automatically.
25167 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25168 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25169 +++ linux/fs/aufs/lcnt.h 2022-03-21 14:49:05.726633010 +0100
25171 +/* SPDX-License-Identifier: GPL-2.0 */
25173 + * Copyright (C) 2018-2021 Junjiro R. Okajima
25175 + * This program, aufs is free software; you can redistribute it and/or modify
25176 + * it under the terms of the GNU General Public License as published by
25177 + * the Free Software Foundation; either version 2 of the License, or
25178 + * (at your option) any later version.
25180 + * This program is distributed in the hope that it will be useful,
25181 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25182 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25183 + * GNU General Public License for more details.
25185 + * You should have received a copy of the GNU General Public License
25186 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25190 + * simple long counter wrapper
25193 +#ifndef __AUFS_LCNT_H__
25194 +#define __AUFS_LCNT_H__
25198 +#include "debug.h"
25200 +#define AuLCntATOMIC 1
25201 +#define AuLCntPCPUCNT 2
25203 + * why does percpu_refcount require extra synchronize_rcu()s in
25204 + * au_br_do_free()
25206 +#define AuLCntPCPUREF 3
25208 +/* #define AuLCntChosen AuLCntATOMIC */
25209 +#define AuLCntChosen AuLCntPCPUCNT
25210 +/* #define AuLCntChosen AuLCntPCPUREF */
25212 +#if AuLCntChosen == AuLCntATOMIC
25213 +#include <linux/atomic.h>
25215 +typedef atomic_long_t au_lcnt_t;
25217 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25219 + atomic_long_set(cnt, 0);
25223 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25228 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25229 + int do_sync __maybe_unused)
25234 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25236 + atomic_long_inc(cnt);
25239 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25241 + atomic_long_dec(cnt);
25244 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25246 + return atomic_long_read(cnt);
25250 +#if AuLCntChosen == AuLCntPCPUCNT
25251 +#include <linux/percpu_counter.h>
25253 +typedef struct percpu_counter au_lcnt_t;
25255 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25257 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25260 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25265 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25267 + percpu_counter_destroy(cnt);
25270 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25272 + percpu_counter_inc(cnt);
25275 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25277 + percpu_counter_dec(cnt);
25280 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25284 + n = percpu_counter_sum(cnt);
25286 + if (LONG_MAX != LLONG_MAX
25288 + AuWarn1("%s\n", "wrap-around");
25294 +#if AuLCntChosen == AuLCntPCPUREF
25295 +#include <linux/percpu-refcount.h>
25297 +typedef struct percpu_ref au_lcnt_t;
25299 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25302 + release = percpu_ref_exit;
25303 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25306 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25308 + synchronize_rcu();
25311 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25313 + percpu_ref_kill(cnt);
25315 + au_lcnt_wait_for_fin(cnt);
25318 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25320 + percpu_ref_get(cnt);
25323 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25325 + percpu_ref_put(cnt);
25329 + * avoid calling this func as possible.
25331 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25335 + percpu_ref_switch_to_atomic_sync(cnt);
25336 + l = atomic_long_read(&cnt->count);
25338 + percpu_ref_switch_to_percpu(cnt);
25340 + /* percpu_ref is initialized by 1 instead of 0 */
25345 +#ifdef CONFIG_AUFS_DEBUG
25346 +#define AuLCntZero(val) do { \
25349 + AuDbg("%s = %ld\n", #val, l); \
25352 +#define AuLCntZero(val) do {} while (0)
25355 +#endif /* __KERNEL__ */
25356 +#endif /* __AUFS_LCNT_H__ */
25357 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25358 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25359 +++ linux/fs/aufs/loop.c 2022-03-21 14:49:05.726633010 +0100
25361 +// SPDX-License-Identifier: GPL-2.0
25363 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25365 + * This program, aufs is free software; you can redistribute it and/or modify
25366 + * it under the terms of the GNU General Public License as published by
25367 + * the Free Software Foundation; either version 2 of the License, or
25368 + * (at your option) any later version.
25370 + * This program is distributed in the hope that it will be useful,
25371 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25372 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25373 + * GNU General Public License for more details.
25375 + * You should have received a copy of the GNU General Public License
25376 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25380 + * support for loopback block device as a branch
25385 +/* added into drivers/block/loop.c */
25386 +static struct file *(*backing_file_func)(struct super_block *sb);
25389 + * test if two lower dentries have overlapping branches.
25391 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25393 + struct super_block *h_sb;
25394 + struct file *backing_file;
25396 + if (unlikely(!backing_file_func)) {
25397 + /* don't load "loop" module here */
25398 + backing_file_func = symbol_get(loop_backing_file);
25399 + if (unlikely(!backing_file_func))
25400 + /* "loop" module is not loaded */
25404 + h_sb = h_adding->d_sb;
25405 + backing_file = backing_file_func(h_sb);
25406 + if (!backing_file)
25409 + h_adding = backing_file->f_path.dentry;
25411 + * h_adding can be local NFS.
25412 + * in this case aufs cannot detect the loop.
25414 + if (unlikely(h_adding->d_sb == sb))
25416 + return !!au_test_subdir(h_adding, sb->s_root);
25419 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25420 +int au_test_loopback_kthread(void)
25423 + struct task_struct *tsk = current;
25424 + char c, comm[sizeof(tsk->comm)];
25427 + if (tsk->flags & PF_KTHREAD) {
25428 + get_task_comm(comm, tsk);
25430 + ret = ('0' <= c && c <= '9'
25431 + && !strncmp(comm, "loop", 4));
25437 +/* ---------------------------------------------------------------------- */
25439 +#define au_warn_loopback_step 16
25440 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25441 +static unsigned long *au_warn_loopback_array;
25443 +void au_warn_loopback(struct super_block *h_sb)
25445 + int i, new_nelem;
25446 + unsigned long *a, magic;
25447 + static DEFINE_SPINLOCK(spin);
25449 + magic = h_sb->s_magic;
25450 + spin_lock(&spin);
25451 + a = au_warn_loopback_array;
25452 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25453 + if (a[i] == magic) {
25454 + spin_unlock(&spin);
25458 + /* h_sb is new to us, print it */
25459 + if (i < au_warn_loopback_nelem) {
25464 + /* expand the array */
25465 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25466 + a = au_kzrealloc(au_warn_loopback_array,
25467 + au_warn_loopback_nelem * sizeof(unsigned long),
25468 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25469 + /*may_shrink*/0);
25471 + au_warn_loopback_nelem = new_nelem;
25472 + au_warn_loopback_array = a;
25477 + spin_unlock(&spin);
25478 + AuWarn1("realloc failed, ignored\n");
25482 + spin_unlock(&spin);
25483 + pr_warn("you may want to try another patch for loopback file "
25484 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25487 +int au_loopback_init(void)
25490 + struct super_block *sb __maybe_unused;
25492 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25495 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25496 + sizeof(unsigned long), GFP_NOFS);
25497 + if (unlikely(!au_warn_loopback_array))
25503 +void au_loopback_fin(void)
25505 + if (backing_file_func)
25506 + symbol_put(loop_backing_file);
25507 + au_kfree_try_rcu(au_warn_loopback_array);
25509 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25510 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25511 +++ linux/fs/aufs/loop.h 2022-03-21 14:49:05.726633010 +0100
25513 +/* SPDX-License-Identifier: GPL-2.0 */
25515 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25517 + * This program, aufs is free software; you can redistribute it and/or modify
25518 + * it under the terms of the GNU General Public License as published by
25519 + * the Free Software Foundation; either version 2 of the License, or
25520 + * (at your option) any later version.
25522 + * This program is distributed in the hope that it will be useful,
25523 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25524 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25525 + * GNU General Public License for more details.
25527 + * You should have received a copy of the GNU General Public License
25528 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25532 + * support for loopback mount as a branch
25535 +#ifndef __AUFS_LOOP_H__
25536 +#define __AUFS_LOOP_H__
25541 +struct super_block;
25543 +#ifdef CONFIG_AUFS_BDEV_LOOP
25544 +/* drivers/block/loop.c */
25545 +struct file *loop_backing_file(struct super_block *sb);
25548 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25549 +int au_test_loopback_kthread(void);
25550 +void au_warn_loopback(struct super_block *h_sb);
25552 +int au_loopback_init(void);
25553 +void au_loopback_fin(void);
25555 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25557 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25558 + struct dentry *h_adding)
25559 +AuStubInt0(au_test_loopback_kthread, void)
25560 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25562 +AuStubInt0(au_loopback_init, void)
25563 +AuStubVoid(au_loopback_fin, void)
25564 +#endif /* BLK_DEV_LOOP */
25566 +#endif /* __KERNEL__ */
25567 +#endif /* __AUFS_LOOP_H__ */
25568 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25569 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25570 +++ linux/fs/aufs/magic.mk 2022-03-21 14:49:05.726633010 +0100
25572 +# SPDX-License-Identifier: GPL-2.0
25574 +# defined in ${srctree}/fs/fuse/inode.c
25576 +ifdef CONFIG_FUSE_FS
25577 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25580 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25582 +ifdef CONFIG_XFS_FS
25583 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25586 +# defined in ${srctree}/fs/configfs/mount.c
25588 +ifdef CONFIG_CONFIGFS_FS
25589 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25592 +# defined in ${srctree}/fs/ubifs/ubifs.h
25594 +ifdef CONFIG_UBIFS_FS
25595 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25598 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25600 +ifdef CONFIG_HFSPLUS_FS
25601 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25603 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25604 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25605 +++ linux/fs/aufs/Makefile 2022-03-21 14:49:05.716633010 +0100
25607 +# SPDX-License-Identifier: GPL-2.0
25609 +include ${src}/magic.mk
25610 +ifeq (${CONFIG_AUFS_FS},m)
25611 +include ${src}/conf.mk
25613 +-include ${src}/priv_def.mk
25615 +# cf. include/linux/kernel.h
25617 +ccflags-y += -DDEBUG
25618 +# sparse requires the full pathname
25620 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25622 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25625 +obj-$(CONFIG_AUFS_FS) += aufs.o
25626 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25627 + wkq.o vfsub.o dcsub.o \
25628 + cpup.o whout.o wbr_policy.o \
25629 + dinfo.o dentry.o \
25631 + finfo.o file.o f_op.o \
25633 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25637 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25638 +aufs-$(CONFIG_SYSFS) += sysfs.o
25639 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25640 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25641 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25642 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25643 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25644 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25645 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25646 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25647 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25648 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25649 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25650 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25651 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25652 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25653 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25654 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25655 +++ linux/fs/aufs/module.c 2022-03-21 14:49:05.726633010 +0100
25657 +// SPDX-License-Identifier: GPL-2.0
25659 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25661 + * This program, aufs is free software; you can redistribute it and/or modify
25662 + * it under the terms of the GNU General Public License as published by
25663 + * the Free Software Foundation; either version 2 of the License, or
25664 + * (at your option) any later version.
25666 + * This program is distributed in the hope that it will be useful,
25667 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25668 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25669 + * GNU General Public License for more details.
25671 + * You should have received a copy of the GNU General Public License
25672 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25676 + * module global variables and operations
25679 +#include <linux/module.h>
25680 +#include <linux/seq_file.h>
25683 +/* shrinkable realloc */
25684 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25692 +#if 0 /* unused */
25699 + AuDebugOn(!new_sz);
25702 + diff = au_kmidx_sub(sz, new_sz);
25708 + /* expand or SLOB */
25709 + p = krealloc(p, new_sz, gfp);
25710 + else if (new_sz < sz && may_shrink) {
25714 + q = kmalloc(new_sz, gfp);
25717 + memcpy(q, p, new_sz);
25718 + au_kfree_try_rcu(p);
25729 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25732 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25733 + if (p && new_sz > nused)
25734 + memset(p + nused, 0, new_sz - nused);
25738 +/* ---------------------------------------------------------------------- */
25742 +struct kmem_cache *au_cache[AuCache_Last];
25744 +static void au_cache_fin(void)
25749 + * Make sure all delayed rcu free inodes are flushed before we
25754 + /* excluding AuCache_HNOTIFY */
25755 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25756 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25757 + kmem_cache_destroy(au_cache[i]);
25758 + au_cache[i] = NULL;
25762 +static int __init au_cache_init(void)
25764 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25765 + if (au_cache[AuCache_DINFO])
25766 + /* SLAB_DESTROY_BY_RCU */
25767 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25768 + au_icntnr_init_once);
25769 + if (au_cache[AuCache_ICNTNR])
25770 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25771 + au_fi_init_once);
25772 + if (au_cache[AuCache_FINFO])
25773 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25774 + if (au_cache[AuCache_VDIR])
25775 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25776 + if (au_cache[AuCache_DEHSTR])
25783 +/* ---------------------------------------------------------------------- */
25785 +int au_dir_roflags;
25787 +#ifdef CONFIG_AUFS_SBILIST
25789 + * iterate_supers_type() doesn't protect us from
25790 + * remounting (branch management)
25792 +struct hlist_bl_head au_sbilist;
25796 + * functions for module interface.
25798 +MODULE_LICENSE("GPL");
25799 +/* MODULE_LICENSE("GPL v2"); */
25800 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25801 +MODULE_DESCRIPTION(AUFS_NAME
25802 + " -- Advanced multi layered unification filesystem");
25803 +MODULE_VERSION(AUFS_VERSION);
25804 +MODULE_ALIAS_FS(AUFS_NAME);
25806 +/* this module parameter has no meaning when SYSFS is disabled */
25807 +int sysaufs_brs = 1;
25808 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25809 +module_param_named(brs, sysaufs_brs, int, 0444);
25811 +/* this module parameter has no meaning when USER_NS is disabled */
25813 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25814 +module_param_named(allow_userns, au_userns, bool, 0444);
25816 +/* ---------------------------------------------------------------------- */
25818 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25820 +int au_seq_path(struct seq_file *seq, struct path *path)
25824 + err = seq_path(seq, path, au_esc_chars);
25833 +/* ---------------------------------------------------------------------- */
25835 +static int __init aufs_init(void)
25840 + p = au_esc_chars;
25841 + for (i = 1; i <= ' '; i++)
25847 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25849 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25850 + for (i = 0; i < AuIop_Last; i++)
25851 + aufs_iop_nogetattr[i].getattr = NULL;
25853 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25855 + au_sbilist_init();
25856 + sysaufs_brs_init();
25859 + err = sysaufs_init();
25860 + if (unlikely(err))
25862 + err = dbgaufs_init();
25863 + if (unlikely(err))
25864 + goto out_sysaufs;
25865 + err = au_procfs_init();
25866 + if (unlikely(err))
25867 + goto out_dbgaufs;
25868 + err = au_wkq_init();
25869 + if (unlikely(err))
25871 + err = au_loopback_init();
25872 + if (unlikely(err))
25874 + err = au_hnotify_init();
25875 + if (unlikely(err))
25876 + goto out_loopback;
25877 + err = au_sysrq_init();
25878 + if (unlikely(err))
25880 + err = au_cache_init();
25881 + if (unlikely(err))
25884 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25885 + err = register_filesystem(&aufs_fs_type);
25886 + if (unlikely(err))
25889 + /* since we define pr_fmt, call printk directly */
25890 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25891 + goto out; /* success */
25898 + au_hnotify_fin();
25900 + au_loopback_fin();
25914 +static void __exit aufs_exit(void)
25916 + unregister_filesystem(&aufs_fs_type);
25919 + au_hnotify_fin();
25920 + au_loopback_fin();
25928 +module_init(aufs_init);
25929 +module_exit(aufs_exit);
25930 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25931 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25932 +++ linux/fs/aufs/module.h 2022-03-21 14:49:05.726633010 +0100
25934 +/* SPDX-License-Identifier: GPL-2.0 */
25936 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25938 + * This program, aufs is free software; you can redistribute it and/or modify
25939 + * it under the terms of the GNU General Public License as published by
25940 + * the Free Software Foundation; either version 2 of the License, or
25941 + * (at your option) any later version.
25943 + * This program is distributed in the hope that it will be useful,
25944 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25945 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25946 + * GNU General Public License for more details.
25948 + * You should have received a copy of the GNU General Public License
25949 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25953 + * module initialization and module-global
25956 +#ifndef __AUFS_MODULE_H__
25957 +#define __AUFS_MODULE_H__
25961 +#include <linux/slab.h>
25962 +#include "debug.h"
25963 +#include "dentry.h"
25966 +#include "inode.h"
25971 +/* module parameters */
25972 +extern int sysaufs_brs;
25973 +extern bool au_userns;
25975 +/* ---------------------------------------------------------------------- */
25977 +extern int au_dir_roflags;
25979 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
25980 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25984 + * Comparing the size of the object with sizeof(struct rcu_head)
25985 + * case 1: object is always larger
25986 + * --> au_kfree_rcu() or au_kfree_do_rcu()
25987 + * case 2: object is always smaller
25988 + * --> au_kfree_small()
25989 + * case 3: object can be any size
25990 + * --> au_kfree_try_rcu()
25993 +static inline void au_kfree_do_rcu(const void *p)
25996 + struct rcu_head rcu;
25997 + } *a = (void *)p;
25999 + kfree_rcu(a, rcu);
26002 +#define au_kfree_rcu(_p) do { \
26003 + typeof(_p) p = (_p); \
26004 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26006 + au_kfree_do_rcu(p); \
26009 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26010 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26012 +static inline void au_kfree_try_rcu(const void *p)
26016 + if (au_kfree_sz_test(p))
26017 + au_kfree_do_rcu(p);
26022 +static inline void au_kfree_small(const void *p)
26026 + AuDebugOn(au_kfree_sz_test(p));
26030 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26032 +#ifndef CONFIG_SLOB
26033 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26035 + return -1; /* SLOB is untested */
26039 +int au_seq_path(struct seq_file *seq, struct path *path);
26041 +#ifdef CONFIG_PROC_FS
26043 +int __init au_procfs_init(void);
26044 +void au_procfs_fin(void);
26046 +AuStubInt0(au_procfs_init, void);
26047 +AuStubVoid(au_procfs_fin, void);
26050 +/* ---------------------------------------------------------------------- */
26059 + AuCache_HNOTIFY, /* must be last */
26063 +extern struct kmem_cache *au_cache[AuCache_Last];
26065 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26066 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26067 +#define AuCacheCtor(type, ctor) \
26068 + kmem_cache_create(#type, sizeof(struct type), \
26069 + __alignof__(struct type), AuCacheFlags, ctor)
26071 +#define AuCacheFuncs(name, index) \
26072 + static inline struct au_##name *au_cache_alloc_##name(void) \
26073 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
26074 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26075 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26077 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26078 + { void *p = rcu; \
26079 + p -= offsetof(struct au_##name, rcu); \
26080 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26081 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26082 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26083 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26085 + static inline void au_cache_free_##name(struct au_##name *p) \
26086 + { /* au_cache_free_##name##_norcu(p); */ \
26087 + au_cache_free_##name##_rcu(p); }
26089 +AuCacheFuncs(dinfo, DINFO);
26090 +AuCacheFuncs(icntnr, ICNTNR);
26091 +AuCacheFuncs(finfo, FINFO);
26092 +AuCacheFuncs(vdir, VDIR);
26093 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26094 +#ifdef CONFIG_AUFS_HNOTIFY
26095 +AuCacheFuncs(hnotify, HNOTIFY);
26098 +#endif /* __KERNEL__ */
26099 +#endif /* __AUFS_MODULE_H__ */
26100 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26101 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26102 +++ linux/fs/aufs/mvdown.c 2022-03-21 14:49:05.729966343 +0100
26104 +// SPDX-License-Identifier: GPL-2.0
26106 + * Copyright (C) 2011-2021 Junjiro R. Okajima
26108 + * This program, aufs is free software; you can redistribute it and/or modify
26109 + * it under the terms of the GNU General Public License as published by
26110 + * the Free Software Foundation; either version 2 of the License, or
26111 + * (at your option) any later version.
26113 + * This program is distributed in the hope that it will be useful,
26114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26116 + * GNU General Public License for more details.
26118 + * You should have received a copy of the GNU General Public License
26119 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26123 + * move-down, opposite of copy-up
26128 +struct au_mvd_args {
26130 + struct super_block *h_sb;
26131 + struct dentry *h_parent;
26132 + struct au_hinode *hdir;
26133 + struct inode *h_dir, *h_inode;
26134 + struct au_pin pin;
26135 + } info[AUFS_MVDOWN_NARRAY];
26137 + struct aufs_mvdown mvdown;
26138 + struct dentry *dentry, *parent;
26139 + struct inode *inode, *dir;
26140 + struct super_block *sb;
26141 + aufs_bindex_t bopq, bwh, bfound;
26142 + unsigned char rename_lock;
26145 +#define mvd_errno mvdown.au_errno
26146 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26147 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26148 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26149 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26151 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26152 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26153 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26154 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26155 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26156 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26158 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26159 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26160 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26161 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26162 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26163 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26165 +#define AU_MVD_PR(flag, ...) do { \
26167 + pr_err(__VA_ARGS__); \
26170 +static int find_lower_writable(struct au_mvd_args *a)
26172 + struct super_block *sb;
26173 + aufs_bindex_t bindex, bbot;
26174 + struct au_branch *br;
26177 + bindex = a->mvd_bsrc;
26178 + bbot = au_sbbot(sb);
26179 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26180 + for (bindex++; bindex <= bbot; bindex++) {
26181 + br = au_sbr(sb, bindex);
26182 + if (au_br_fhsm(br->br_perm)
26183 + && !sb_rdonly(au_br_sb(br)))
26186 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26187 + for (bindex++; bindex <= bbot; bindex++) {
26188 + br = au_sbr(sb, bindex);
26189 + if (!au_br_rdonly(br))
26193 + for (bindex++; bindex <= bbot; bindex++) {
26194 + br = au_sbr(sb, bindex);
26195 + if (!sb_rdonly(au_br_sb(br))) {
26196 + if (au_br_rdonly(br))
26198 + |= AUFS_MVDOWN_ROLOWER_R;
26206 +/* make the parent dir on bdst */
26207 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26212 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26213 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26214 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26215 + a->mvd_h_dst_parent = NULL;
26216 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26217 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26218 + if (!a->mvd_h_dst_parent) {
26219 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26220 + if (unlikely(err)) {
26221 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26224 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26232 +/* lock them all */
26233 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26236 + struct dentry *h_trap;
26238 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26239 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26240 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26241 + au_opt_udba(a->sb),
26242 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26244 + if (unlikely(err)) {
26245 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26249 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26250 + a->rename_lock = 0;
26251 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26252 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26253 + au_opt_udba(a->sb),
26254 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26255 + err = au_do_pin(&a->mvd_pin_src);
26257 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26258 + if (unlikely(err)) {
26259 + AU_MVD_PR(dmsg, "pin_src failed\n");
26262 + goto out; /* success */
26265 + a->rename_lock = 1;
26266 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26267 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26268 + au_opt_udba(a->sb),
26269 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26271 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26272 + if (unlikely(err)) {
26273 + AU_MVD_PR(dmsg, "pin_src failed\n");
26274 + au_pin_hdir_lock(&a->mvd_pin_dst);
26277 + au_pin_hdir_unlock(&a->mvd_pin_src);
26278 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26279 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26281 + err = (h_trap != a->mvd_h_src_parent);
26283 + err = (h_trap != a->mvd_h_dst_parent);
26285 + BUG_ON(err); /* it should never happen */
26286 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26289 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26290 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26291 + au_pin_hdir_lock(&a->mvd_pin_src);
26292 + au_unpin(&a->mvd_pin_src);
26293 + au_pin_hdir_lock(&a->mvd_pin_dst);
26296 + goto out; /* success */
26299 + au_unpin(&a->mvd_pin_dst);
26305 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26307 + if (!a->rename_lock)
26308 + au_unpin(&a->mvd_pin_src);
26310 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26311 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26312 + au_pin_hdir_lock(&a->mvd_pin_src);
26313 + au_unpin(&a->mvd_pin_src);
26314 + au_pin_hdir_lock(&a->mvd_pin_dst);
26316 + au_unpin(&a->mvd_pin_dst);
26319 +/* copy-down the file */
26320 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26323 + struct au_cp_generic cpg = {
26324 + .dentry = a->dentry,
26325 + .bdst = a->mvd_bdst,
26326 + .bsrc = a->mvd_bsrc,
26328 + .pin = &a->mvd_pin_dst,
26329 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26332 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26333 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26334 + au_fset_cpup(cpg.flags, OVERWRITE);
26335 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26336 + au_fset_cpup(cpg.flags, RWDST);
26337 + err = au_sio_cpdown_simple(&cpg);
26338 + if (unlikely(err))
26339 + AU_MVD_PR(dmsg, "cpdown failed\n");
26346 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26349 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26352 + struct path h_path;
26353 + struct au_branch *br;
26354 + struct inode *delegated;
26356 + br = au_sbr(a->sb, a->mvd_bdst);
26357 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26358 + err = PTR_ERR(h_path.dentry);
26359 + if (IS_ERR(h_path.dentry)) {
26360 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26365 + if (d_is_positive(h_path.dentry)) {
26366 + h_path.mnt = au_br_mnt(br);
26367 + delegated = NULL;
26368 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26369 + &delegated, /*force*/0);
26370 + if (unlikely(err == -EWOULDBLOCK)) {
26371 + pr_warn("cannot retry for NFSv4 delegation"
26372 + " for an internal unlink\n");
26375 + if (unlikely(err))
26376 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26378 + dput(h_path.dentry);
26386 + * unlink the topmost h_dentry
26388 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26391 + struct path h_path;
26392 + struct inode *delegated;
26394 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26395 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26396 + delegated = NULL;
26397 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26398 + if (unlikely(err == -EWOULDBLOCK)) {
26399 + pr_warn("cannot retry for NFSv4 delegation"
26400 + " for an internal unlink\n");
26403 + if (unlikely(err))
26404 + AU_MVD_PR(dmsg, "unlink failed\n");
26410 +/* Since mvdown succeeded, we ignore an error of this function */
26411 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26414 + struct au_branch *br;
26416 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26417 + br = au_sbr(a->sb, a->mvd_bsrc);
26418 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26420 + br = au_sbr(a->sb, a->mvd_bdst);
26421 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26422 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26425 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26427 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26431 + * copy-down the file and unlink the bsrc file.
26432 + * - unlink the bdst whout if exist
26433 + * - copy-down the file (with whtmp name and rename)
26434 + * - unlink the bsrc file
26436 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26440 + err = au_do_mkdir(dmsg, a);
26442 + err = au_do_lock(dmsg, a);
26443 + if (unlikely(err))
26447 + * do not revert the activities we made on bdst since they should be
26448 + * harmless in aufs.
26451 + err = au_do_cpdown(dmsg, a);
26453 + err = au_do_unlink_wh(dmsg, a);
26454 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26455 + err = au_do_unlink(dmsg, a);
26456 + if (unlikely(err))
26459 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26460 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26461 + if (find_lower_writable(a) < 0)
26462 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26464 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26465 + au_do_stfs(dmsg, a);
26467 + /* maintain internal array */
26468 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26469 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26470 + au_set_dbtop(a->dentry, a->mvd_bdst);
26471 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26472 + au_set_ibtop(a->inode, a->mvd_bdst);
26474 + /* hide the lower */
26475 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26476 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26477 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26478 + au_set_ibbot(a->inode, a->mvd_bsrc);
26480 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26481 + au_set_dbbot(a->dentry, a->mvd_bdst);
26482 + if (au_ibbot(a->inode) < a->mvd_bdst)
26483 + au_set_ibbot(a->inode, a->mvd_bdst);
26486 + au_do_unlock(dmsg, a);
26492 +/* ---------------------------------------------------------------------- */
26494 +/* make sure the file is idle */
26495 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26497 + int err, plinked;
26500 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26501 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26502 + && au_dcount(a->dentry) == 1
26503 + && atomic_read(&a->inode->i_count) == 1
26504 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26505 + && (!plinked || !au_plink_test(a->inode))
26506 + && a->inode->i_nlink == 1)
26511 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26512 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26513 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26514 + a->mvd_h_src_inode->i_nlink,
26515 + plinked, plinked ? au_plink_test(a->inode) : 0);
26522 +/* make sure the parent dir is fine */
26523 +static int au_mvd_args_parent(const unsigned char dmsg,
26524 + struct au_mvd_args *a)
26527 + aufs_bindex_t bindex;
26530 + if (unlikely(au_alive_dir(a->parent))) {
26532 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26536 + a->bopq = au_dbdiropq(a->parent);
26537 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26538 + AuDbg("b%d\n", bindex);
26539 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26540 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26542 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26543 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26544 + a->bopq, a->mvd_bdst);
26552 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26553 + struct au_mvd_args *a)
26556 + struct au_dinfo *dinfo, *tmp;
26558 + /* lookup the next lower positive entry */
26560 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26561 + if (unlikely(!tmp))
26566 + dinfo = au_di(a->dentry);
26567 + au_di_cp(tmp, dinfo);
26568 + au_di_swap(tmp, dinfo);
26570 + /* returns the number of positive dentries */
26571 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26572 + /* AuLkup_IGNORE_PERM */ 0);
26574 + a->bwh = au_dbwh(a->dentry);
26575 + else if (err > 0)
26576 + a->bfound = au_dbtop(a->dentry);
26578 + au_di_swap(tmp, dinfo);
26579 + au_rw_write_unlock(&tmp->di_rwsem);
26581 + if (unlikely(err < 0))
26582 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26585 + * here, we have these cases.
26587 + * no positive dentry under bsrc. there are more sub-cases.
26589 + * there no whiteout, we can safely move-down.
26592 + * bsrc < bwh && bwh < bdst
26593 + * there is a whiteout on RO branch. cannot proceed.
26595 + * there is a whiteout on the RW target branch. it should
26598 + * there is a whiteout somewhere unrelated branch.
26599 + * -1 < bfound && bfound <= bsrc
26602 + * found, but it is on RO branch between bsrc and bdst. cannot
26605 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26608 + * found, after we create the file on bdst, it will be hidden.
26611 + AuDebugOn(a->bfound == -1
26613 + && a->bwh <= a->mvd_bsrc);
26614 + AuDebugOn(-1 < a->bfound
26615 + && a->bfound <= a->mvd_bsrc);
26618 + if (a->bfound == -1
26619 + && a->mvd_bsrc < a->bwh
26621 + && a->bwh < a->mvd_bdst) {
26622 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26623 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26624 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26626 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26627 + a->mvd_errno = EAU_MVDOWN_UPPER;
26628 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26629 + a->mvd_bdst, a->bfound);
26633 + err = 0; /* success */
26640 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26645 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26646 + && a->bfound == a->mvd_bdst)
26652 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26655 + struct au_branch *br;
26658 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26662 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26663 + a->mvd_bsrc = au_ibtop(a->inode);
26665 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26666 + if (unlikely(a->mvd_bsrc < 0
26667 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26668 + || au_dbbot(a->dentry) < a->mvd_bsrc
26669 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26670 + || (a->mvd_bsrc < au_ibtop(a->inode)
26671 + || au_ibbot(a->inode) < a->mvd_bsrc
26672 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26673 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26674 + AU_MVD_PR(dmsg, "no upper\n");
26678 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26679 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26680 + AU_MVD_PR(dmsg, "on the bottom\n");
26683 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26684 + br = au_sbr(a->sb, a->mvd_bsrc);
26685 + err = au_br_rdonly(br);
26686 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26687 + if (unlikely(err))
26689 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26690 + || IS_APPEND(a->mvd_h_src_inode))) {
26692 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26698 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26699 + a->mvd_bdst = find_lower_writable(a);
26700 + if (unlikely(a->mvd_bdst < 0)) {
26701 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26702 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26706 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26707 + if (unlikely(a->mvd_bdst < 0
26708 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26709 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26710 + AU_MVD_PR(dmsg, "no lower brid\n");
26715 + err = au_mvd_args_busy(dmsg, a);
26717 + err = au_mvd_args_parent(dmsg, a);
26719 + err = au_mvd_args_intermediate(dmsg, a);
26721 + err = au_mvd_args_exist(dmsg, a);
26723 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26730 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26733 + unsigned char dmsg;
26734 + struct au_mvd_args *args;
26735 + struct inode *inode;
26737 + inode = d_inode(dentry);
26739 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26743 + args = kmalloc(sizeof(*args), GFP_NOFS);
26744 + if (unlikely(!args))
26747 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26749 + /* VERIFY_WRITE */
26750 + err = !access_ok(uarg, sizeof(*uarg));
26751 + if (unlikely(err)) {
26756 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26757 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26758 + args->mvdown.au_errno = 0;
26759 + args->dentry = dentry;
26760 + args->inode = inode;
26761 + args->sb = dentry->d_sb;
26764 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26765 + args->parent = dget_parent(dentry);
26766 + args->dir = d_inode(args->parent);
26767 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26768 + dput(args->parent);
26769 + if (unlikely(args->parent != dentry->d_parent)) {
26770 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26774 + inode_lock_nested(inode, I_MUTEX_CHILD);
26775 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26776 + if (unlikely(err))
26779 + di_write_lock_parent(args->parent);
26780 + err = au_mvd_args(dmsg, args);
26781 + if (unlikely(err))
26784 + err = au_do_mvdown(dmsg, args);
26785 + if (unlikely(err))
26788 + au_cpup_attr_timesizes(args->dir);
26789 + au_cpup_attr_timesizes(inode);
26790 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26791 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26792 + /* au_digen_dec(dentry); */
26795 + di_write_unlock(args->parent);
26796 + aufs_read_unlock(dentry, AuLock_DW);
26798 + inode_unlock(inode);
26800 + inode_unlock(args->dir);
26802 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26805 + au_kfree_rcu(args);
26810 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26811 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26812 +++ linux/fs/aufs/opts.c 2022-03-21 14:49:05.729966343 +0100
26814 +// SPDX-License-Identifier: GPL-2.0
26816 + * Copyright (C) 2005-2021 Junjiro R. Okajima
26818 + * This program, aufs is free software; you can redistribute it and/or modify
26819 + * it under the terms of the GNU General Public License as published by
26820 + * the Free Software Foundation; either version 2 of the License, or
26821 + * (at your option) any later version.
26823 + * This program is distributed in the hope that it will be useful,
26824 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26825 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26826 + * GNU General Public License for more details.
26828 + * You should have received a copy of the GNU General Public License
26829 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26833 + * mount options/flags
26836 +#include <linux/types.h> /* a distribution requires */
26837 +#include <linux/parser.h>
26840 +/* ---------------------------------------------------------------------- */
26842 +static const char *au_parser_pattern(int val, match_table_t tbl)
26844 + struct match_token *p;
26847 + while (p->pattern) {
26848 + if (p->token == val)
26849 + return p->pattern;
26856 +static const char *au_optstr(int *val, match_table_t tbl)
26858 + struct match_token *p;
26865 + while (p->pattern) {
26867 + && (v & p->token) == p->token) {
26868 + *val &= ~p->token;
26869 + return p->pattern;
26878 +/* ---------------------------------------------------------------------- */
26880 +static match_table_t brperm = {
26881 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26882 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26883 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26887 +static match_table_t brattr = {
26889 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26890 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26891 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26892 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26893 +#ifdef CONFIG_AUFS_FHSM
26894 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26896 +#ifdef CONFIG_AUFS_XATTR
26897 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26898 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26899 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26900 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26901 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26902 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26905 + /* ro/rr branch */
26906 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26909 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26910 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26915 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26922 + p = strchr(str, '+');
26925 + v = match_token(str, table, args);
26927 + if (v & AuBrAttr_CMOO_Mask)
26928 + attr &= ~AuBrAttr_CMOO_Mask;
26933 + pr_warn("ignored branch attribute %s\n", str);
26943 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26951 + p = au_optstr(&perm, brattr);
26954 + memcpy(q, p, sz + 1);
26960 + p = au_optstr(&perm, brattr);
26964 + memcpy(q, p, sz + 1);
26970 + return q - str->a;
26973 +int au_br_perm_val(char *perm)
26975 + int val, bad, sz;
26977 + substring_t args[MAX_OPT_ARGS];
26978 + au_br_perm_str_t attr;
26980 + p = strchr(perm, '+');
26983 + val = match_token(perm, brperm, args);
26987 + pr_warn("ignored branch permission %s\n", perm);
26988 + val = AuBrPerm_RO;
26994 + val |= br_attr_val(p + 1, brattr, args);
26997 + switch (val & AuBrPerm_Mask) {
26998 + case AuBrPerm_RO:
26999 + case AuBrPerm_RR:
27000 + bad = val & AuBrWAttr_Mask;
27001 + val &= ~AuBrWAttr_Mask;
27003 + case AuBrPerm_RW:
27004 + bad = val & AuBrRAttr_Mask;
27005 + val &= ~AuBrRAttr_Mask;
27010 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27011 + * does not treat it as an error, just warning.
27012 + * this is a tiny guard for the user operation.
27014 + if (val & AuBrAttr_UNPIN) {
27015 + bad |= AuBrAttr_UNPIN;
27016 + val &= ~AuBrAttr_UNPIN;
27019 + if (unlikely(bad)) {
27020 + sz = au_do_optstr_br_attr(&attr, bad);
27022 + pr_warn("ignored branch attribute %s\n", attr.a);
27029 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27031 + au_br_perm_str_t attr;
27037 + p = au_optstr(&perm, brperm);
27038 + AuDebugOn(!p || !*p);
27040 + memcpy(q, p, sz + 1);
27043 + sz = au_do_optstr_br_attr(&attr, perm);
27046 + memcpy(q, attr.a, sz + 1);
27049 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27052 +/* ---------------------------------------------------------------------- */
27054 +static match_table_t udbalevel = {
27055 + {AuOpt_UDBA_REVAL, "reval"},
27056 + {AuOpt_UDBA_NONE, "none"},
27057 +#ifdef CONFIG_AUFS_HNOTIFY
27058 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27059 +#ifdef CONFIG_AUFS_HFSNOTIFY
27060 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27066 +int au_udba_val(char *str)
27068 + substring_t args[MAX_OPT_ARGS];
27070 + return match_token(str, udbalevel, args);
27073 +const char *au_optstr_udba(int udba)
27075 + return au_parser_pattern(udba, udbalevel);
27078 +/* ---------------------------------------------------------------------- */
27080 +static match_table_t au_wbr_create_policy = {
27081 + {AuWbrCreate_TDP, "tdp"},
27082 + {AuWbrCreate_TDP, "top-down-parent"},
27083 + {AuWbrCreate_RR, "rr"},
27084 + {AuWbrCreate_RR, "round-robin"},
27085 + {AuWbrCreate_MFS, "mfs"},
27086 + {AuWbrCreate_MFS, "most-free-space"},
27087 + {AuWbrCreate_MFSV, "mfs:%d"},
27088 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27090 + /* top-down regardless the parent, and then mfs */
27091 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27092 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27094 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27095 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27096 + {AuWbrCreate_PMFS, "pmfs"},
27097 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27098 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27099 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27104 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27105 + struct au_opt_wbr_create *create)
27108 + unsigned long long ull;
27111 + if (!match_u64(arg, &ull))
27112 + create->mfsrr_watermark = ull;
27114 + pr_err("bad integer in %s\n", str);
27121 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27122 + struct au_opt_wbr_create *create)
27127 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27128 + create->mfs_second = n;
27130 + pr_err("bad integer in %s\n", str);
27137 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27140 + substring_t args[MAX_OPT_ARGS];
27142 + err = match_token(str, au_wbr_create_policy, args);
27143 + create->wbr_create = err;
27145 + case AuWbrCreate_MFSRRV:
27146 + case AuWbrCreate_TDMFSV:
27147 + case AuWbrCreate_PMFSRRV:
27148 + e = au_wbr_mfs_wmark(&args[0], str, create);
27150 + e = au_wbr_mfs_sec(&args[1], str, create);
27154 + case AuWbrCreate_MFSRR:
27155 + case AuWbrCreate_TDMFS:
27156 + case AuWbrCreate_PMFSRR:
27157 + e = au_wbr_mfs_wmark(&args[0], str, create);
27158 + if (unlikely(e)) {
27163 + case AuWbrCreate_MFS:
27164 + case AuWbrCreate_PMFS:
27165 + create->mfs_second = AUFS_MFS_DEF_SEC;
27167 + case AuWbrCreate_MFSV:
27168 + case AuWbrCreate_PMFSV:
27169 + e = au_wbr_mfs_sec(&args[0], str, create);
27178 +const char *au_optstr_wbr_create(int wbr_create)
27180 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27183 +static match_table_t au_wbr_copyup_policy = {
27184 + {AuWbrCopyup_TDP, "tdp"},
27185 + {AuWbrCopyup_TDP, "top-down-parent"},
27186 + {AuWbrCopyup_BUP, "bup"},
27187 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27188 + {AuWbrCopyup_BU, "bu"},
27189 + {AuWbrCopyup_BU, "bottom-up"},
27193 +int au_wbr_copyup_val(char *str)
27195 + substring_t args[MAX_OPT_ARGS];
27197 + return match_token(str, au_wbr_copyup_policy, args);
27200 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27202 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27205 +/* ---------------------------------------------------------------------- */
27207 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27208 + aufs_bindex_t bindex)
27211 + struct au_opt_add *add = &opt->add;
27214 + add->bindex = bindex;
27215 + add->perm = AuBrPerm_RO;
27216 + add->pathname = opt_str;
27217 + p = strchr(opt_str, '=');
27221 + add->perm = au_br_perm_val(p);
27224 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27227 + add->perm = AuBrPerm_RO;
27228 + if (au_test_fs_rr(add->path.dentry->d_sb))
27229 + add->perm = AuBrPerm_RR;
27230 + else if (!bindex && !(sb_flags & SB_RDONLY))
27231 + add->perm = AuBrPerm_RW;
27233 + opt->type = Opt_add;
27236 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27243 +static int au_opt_wbr_create(struct super_block *sb,
27244 + struct au_opt_wbr_create *create)
27247 + struct au_sbinfo *sbinfo;
27249 + SiMustWriteLock(sb);
27251 + err = 1; /* handled */
27252 + sbinfo = au_sbi(sb);
27253 + if (sbinfo->si_wbr_create_ops->fin) {
27254 + err = sbinfo->si_wbr_create_ops->fin(sb);
27259 + sbinfo->si_wbr_create = create->wbr_create;
27260 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27261 + switch (create->wbr_create) {
27262 + case AuWbrCreate_MFSRRV:
27263 + case AuWbrCreate_MFSRR:
27264 + case AuWbrCreate_TDMFS:
27265 + case AuWbrCreate_TDMFSV:
27266 + case AuWbrCreate_PMFSRR:
27267 + case AuWbrCreate_PMFSRRV:
27268 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27270 + case AuWbrCreate_MFS:
27271 + case AuWbrCreate_MFSV:
27272 + case AuWbrCreate_PMFS:
27273 + case AuWbrCreate_PMFSV:
27274 + sbinfo->si_wbr_mfs.mfs_expire
27275 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27279 + if (sbinfo->si_wbr_create_ops->init)
27280 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27287 + * plus: processed without an error
27288 + * zero: unprocessed
27290 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27291 + struct au_opts *opts)
27294 + struct au_sbinfo *sbinfo;
27296 + SiMustWriteLock(sb);
27298 + err = 1; /* handled */
27299 + sbinfo = au_sbi(sb);
27300 + switch (opt->type) {
27302 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27303 + sbinfo->si_mntflags |= opt->udba;
27304 + opts->given_udba |= opt->udba;
27309 + au_opt_set(sbinfo->si_mntflags, PLINK);
27311 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27312 + au_plink_put(sb, /*verbose*/1);
27313 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27316 + case Opt_list_plink:
27317 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27318 + au_plink_list(sb);
27323 + au_opt_set(sbinfo->si_mntflags, DIO);
27324 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27326 + au_opt_clr(sbinfo->si_mntflags, DIO);
27327 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27331 + case Opt_fhsm_sec:
27332 + au_fhsm_set(sbinfo, opt->fhsm_second);
27335 + case Opt_diropq_a:
27336 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27338 + case Opt_diropq_w:
27339 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27342 + case Opt_warn_perm:
27344 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27346 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27349 + case Opt_verbose:
27351 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27353 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27358 + au_opt_set(sbinfo->si_mntflags, SUM);
27360 + au_opt_clr(sbinfo->si_mntflags, SUM);
27361 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27365 + au_opt_clr(sbinfo->si_mntflags, SUM);
27366 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27369 + case Opt_wbr_create:
27370 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27372 + case Opt_wbr_copyup:
27373 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27374 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27378 + sbinfo->si_dirwh = opt->dirwh;
27381 + case Opt_rdcache:
27382 + sbinfo->si_rdcache
27383 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27386 + sbinfo->si_rdblk = opt->rdblk;
27389 + sbinfo->si_rdhash = opt->rdhash;
27394 + au_opt_set(sbinfo->si_mntflags, SHWH);
27396 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27399 + case Opt_dirperm1:
27401 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27403 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27406 + case Opt_trunc_xino:
27408 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27410 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27413 + case Opt_trunc_xino_path:
27414 + case Opt_itrunc_xino:
27415 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27421 + case Opt_trunc_xib:
27423 + au_fset_opts(opts->flags, TRUNC_XIB);
27425 + au_fclr_opts(opts->flags, TRUNC_XIB);
27431 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27432 + err = au_dr_opt_set(sb);
27437 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27439 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27440 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27446 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27452 + sb->s_flags |= SB_POSIXACL;
27454 + sb->s_flags &= ~SB_POSIXACL;
27466 + * returns tri-state.
27467 + * plus: processed without an error
27468 + * zero: unprocessed
27471 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27472 + struct au_opts *opts)
27474 + int err, do_refresh;
27477 + switch (opt->type) {
27479 + opt->add.bindex = au_sbbot(sb) + 1;
27480 + if (opt->add.bindex < 0)
27481 + opt->add.bindex = 0;
27483 + /* Always goto add, not fallthrough */
27484 + case Opt_prepend:
27485 + opt->add.bindex = 0;
27487 + add: /* indented label */
27489 + err = au_br_add(sb, &opt->add,
27490 + au_ftest_opts(opts->flags, REMOUNT));
27493 + au_fset_opts(opts->flags, REFRESH);
27499 + err = au_br_del(sb, &opt->del,
27500 + au_ftest_opts(opts->flags, REMOUNT));
27503 + au_fset_opts(opts->flags, TRUNC_XIB);
27504 + au_fset_opts(opts->flags, REFRESH);
27510 + err = au_br_mod(sb, &opt->mod,
27511 + au_ftest_opts(opts->flags, REMOUNT),
27516 + au_fset_opts(opts->flags, REFRESH);
27523 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27524 + struct au_opt_xino **opt_xino,
27525 + struct au_opts *opts)
27530 + switch (opt->type) {
27532 + err = au_xino_set(sb, &opt->xino,
27533 + !!au_ftest_opts(opts->flags, REMOUNT));
27535 + *opt_xino = &opt->xino;
27539 + *opt_xino = (void *)-1;
27546 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27547 + unsigned int pending)
27550 + aufs_bindex_t bindex, bbot;
27551 + unsigned char do_plink, skip, do_free, can_no_dreval;
27552 + struct au_branch *br;
27553 + struct au_wbr *wbr;
27554 + struct dentry *root, *dentry;
27555 + struct inode *dir, *h_dir;
27556 + struct au_sbinfo *sbinfo;
27557 + struct au_hinode *hdir;
27559 + SiMustAnyLock(sb);
27561 + sbinfo = au_sbi(sb);
27562 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27564 + if (!(sb_flags & SB_RDONLY)) {
27565 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27566 + pr_warn("first branch should be rw\n");
27567 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27568 + pr_warn_once("shwh should be used with ro\n");
27571 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27572 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27573 + pr_warn_once("udba=*notify requires xino\n");
27575 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27576 + pr_warn_once("dirperm1 breaks the protection"
27577 + " by the permission bits on the lower branch\n");
27581 + root = sb->s_root;
27582 + dir = d_inode(root);
27583 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27584 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27586 + bbot = au_sbbot(sb);
27587 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27589 + h_dir = au_h_iptr(dir, bindex);
27590 + br = au_sbr(sb, bindex);
27592 + if ((br->br_perm & AuBrAttr_ICEX)
27593 + && !h_dir->i_op->listxattr)
27594 + br->br_perm &= ~AuBrAttr_ICEX;
27595 +#if 0 /* untested */
27596 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27597 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27598 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27602 + wbr = br->br_wbr;
27604 + wbr_wh_read_lock(wbr);
27606 + if (!au_br_writable(br->br_perm)) {
27609 + || (!wbr->wbr_whbase
27610 + && !wbr->wbr_plink
27611 + && !wbr->wbr_orph));
27612 + } else if (!au_br_wh_linkable(br->br_perm)) {
27613 + /* skip = (!br->br_whbase && !br->br_orph); */
27614 + skip = (!wbr || !wbr->wbr_whbase);
27615 + if (skip && wbr) {
27617 + skip = !!wbr->wbr_plink;
27619 + skip = !wbr->wbr_plink;
27622 + /* skip = (br->br_whbase && br->br_ohph); */
27623 + skip = (wbr && wbr->wbr_whbase);
27626 + skip = !!wbr->wbr_plink;
27628 + skip = !wbr->wbr_plink;
27632 + wbr_wh_read_unlock(wbr);
27634 + if (can_no_dreval) {
27635 + dentry = br->br_path.dentry;
27636 + spin_lock(&dentry->d_lock);
27637 + if (dentry->d_flags &
27638 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27639 + can_no_dreval = 0;
27640 + spin_unlock(&dentry->d_lock);
27643 + if (au_br_fhsm(br->br_perm)) {
27645 + AuDebugOn(!br->br_fhsm);
27651 + hdir = au_hi(dir, bindex);
27652 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27654 + wbr_wh_write_lock(wbr);
27655 + err = au_wh_init(br, sb);
27657 + wbr_wh_write_unlock(wbr);
27658 + au_hn_inode_unlock(hdir);
27660 + if (!err && do_free) {
27661 + au_kfree_rcu(wbr);
27662 + br->br_wbr = NULL;
27666 + if (can_no_dreval)
27667 + au_fset_si(sbinfo, NO_DREVAL);
27669 + au_fclr_si(sbinfo, NO_DREVAL);
27672 + au_fset_si(sbinfo, FHSM);
27673 + for (bindex = bbot; bindex >= 0; bindex--) {
27674 + br = au_sbr(sb, bindex);
27675 + if (au_br_fhsm(br->br_perm)) {
27676 + au_fhsm_set_bottom(sb, bindex);
27681 + au_fclr_si(sbinfo, FHSM);
27682 + au_fhsm_set_bottom(sb, -1);
27688 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27691 + unsigned int tmp;
27692 + aufs_bindex_t bindex, bbot;
27693 + struct au_opt *opt;
27694 + struct au_opt_xino *opt_xino, xino;
27695 + struct au_sbinfo *sbinfo;
27696 + struct au_branch *br;
27697 + struct inode *dir;
27699 + SiMustWriteLock(sb);
27704 + while (err >= 0 && opt->type != Opt_tail)
27705 + err = au_opt_simple(sb, opt++, opts);
27708 + else if (unlikely(err < 0))
27711 + /* disable xino and udba temporary */
27712 + sbinfo = au_sbi(sb);
27713 + tmp = sbinfo->si_mntflags;
27714 + au_opt_clr(sbinfo->si_mntflags, XINO);
27715 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27718 + while (err >= 0 && opt->type != Opt_tail)
27719 + err = au_opt_br(sb, opt++, opts);
27722 + else if (unlikely(err < 0))
27725 + bbot = au_sbbot(sb);
27726 + if (unlikely(bbot < 0)) {
27728 + pr_err("no branches\n");
27732 + if (au_opt_test(tmp, XINO))
27733 + au_opt_set(sbinfo->si_mntflags, XINO);
27735 + while (!err && opt->type != Opt_tail)
27736 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27737 + if (unlikely(err))
27740 + err = au_opts_verify(sb, sb->s_flags, tmp);
27741 + if (unlikely(err))
27744 + /* restore xino */
27745 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27746 + xino.file = au_xino_def(sb);
27747 + err = PTR_ERR(xino.file);
27748 + if (IS_ERR(xino.file))
27751 + err = au_xino_set(sb, &xino, /*remount*/0);
27753 + if (unlikely(err))
27757 + /* restore udba */
27758 + tmp &= AuOptMask_UDBA;
27759 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27760 + sbinfo->si_mntflags |= tmp;
27761 + bbot = au_sbbot(sb);
27762 + for (bindex = 0; bindex <= bbot; bindex++) {
27763 + br = au_sbr(sb, bindex);
27764 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27765 + if (unlikely(err))
27766 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27768 + /* go on even if err */
27770 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27771 + dir = d_inode(sb->s_root);
27772 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27779 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27782 + unsigned char no_dreval;
27783 + struct inode *dir;
27784 + struct au_opt_xino *opt_xino;
27785 + struct au_opt *opt;
27786 + struct au_sbinfo *sbinfo;
27788 + SiMustWriteLock(sb);
27790 + err = au_dr_opt_flush(sb);
27791 + if (unlikely(err))
27793 + au_fset_opts(opts->flags, DR_FLUSHED);
27795 + dir = d_inode(sb->s_root);
27796 + sbinfo = au_sbi(sb);
27799 + while (err >= 0 && opt->type != Opt_tail) {
27800 + err = au_opt_simple(sb, opt, opts);
27802 + err = au_opt_br(sb, opt, opts);
27804 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27810 + /* go on even err */
27812 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27813 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27814 + if (unlikely(rerr && !err))
27817 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27818 + au_fset_opts(opts->flags, REFRESH_IDOP);
27820 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27821 + rerr = au_xib_trunc(sb);
27822 + if (unlikely(rerr && !err))
27826 + /* will be handled by the caller */
27827 + if (!au_ftest_opts(opts->flags, REFRESH)
27828 + && (opts->given_udba
27829 + || au_opt_test(sbinfo->si_mntflags, XINO)
27830 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27832 + au_fset_opts(opts->flags, REFRESH);
27834 + AuDbg("status 0x%x\n", opts->flags);
27840 +/* ---------------------------------------------------------------------- */
27842 +unsigned int au_opt_udba(struct super_block *sb)
27844 + return au_mntflags(sb) & AuOptMask_UDBA;
27846 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27847 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27848 +++ linux/fs/aufs/opts.h 2022-03-21 14:49:05.729966343 +0100
27850 +/* SPDX-License-Identifier: GPL-2.0 */
27852 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27854 + * This program, aufs is free software; you can redistribute it and/or modify
27855 + * it under the terms of the GNU General Public License as published by
27856 + * the Free Software Foundation; either version 2 of the License, or
27857 + * (at your option) any later version.
27859 + * This program is distributed in the hope that it will be useful,
27860 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27861 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27862 + * GNU General Public License for more details.
27864 + * You should have received a copy of the GNU General Public License
27865 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27869 + * mount options/flags
27872 +#ifndef __AUFS_OPTS_H__
27873 +#define __AUFS_OPTS_H__
27877 +#include <linux/fs_parser.h>
27878 +#include <linux/namei.h>
27879 +#include <linux/path.h>
27883 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27884 + Opt_idel, Opt_imod,
27885 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27886 + Opt_xino, Opt_noxino,
27887 + Opt_trunc_xino, Opt_trunc_xino_v,
27888 + Opt_trunc_xino_path, Opt_itrunc_xino,
27891 + Opt_plink, Opt_list_plink,
27894 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27896 + Opt_wbr_copyup, Opt_wbr_create,
27898 + Opt_verbose, Opt_noverbose,
27899 + Opt_sum, Opt_wsum,
27903 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27906 +/* ---------------------------------------------------------------------- */
27909 +#define AuOpt_XINO 1 /* external inode number bitmap
27910 + and translation table */
27911 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27912 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27913 +#define AuOpt_UDBA_REVAL (1 << 3)
27914 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27915 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27916 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27917 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27919 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27920 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27921 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27922 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27923 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27924 +#define AuOpt_DIO (1 << 14) /* direct io */
27925 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27927 +#ifndef CONFIG_AUFS_HNOTIFY
27928 +#undef AuOpt_UDBA_HNOTIFY
27929 +#define AuOpt_UDBA_HNOTIFY 0
27931 +#ifndef CONFIG_AUFS_DIRREN
27932 +#undef AuOpt_DIRREN
27933 +#define AuOpt_DIRREN 0
27935 +#ifndef CONFIG_AUFS_SHWH
27937 +#define AuOpt_SHWH 0
27940 +#define AuOpt_Def (AuOpt_XINO \
27941 + | AuOpt_UDBA_REVAL \
27943 + /* | AuOpt_DIRPERM1 */ \
27944 + | AuOpt_WARN_PERM)
27945 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27946 + | AuOpt_UDBA_REVAL \
27947 + | AuOpt_UDBA_HNOTIFY)
27949 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
27951 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27952 +#define au_opt_set(flags, name) do { \
27953 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27954 + ((flags) |= AuOpt_##name); \
27956 +#define au_opt_set_udba(flags, name) do { \
27957 + (flags) &= ~AuOptMask_UDBA; \
27958 + ((flags) |= AuOpt_##name); \
27960 +#define au_opt_clr(flags, name) do { \
27961 + ((flags) &= ~AuOpt_##name); \
27964 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27966 +#ifdef CONFIG_PROC_FS
27969 + return mntflags & ~AuOpt_PLINK;
27973 +/* ---------------------------------------------------------------------- */
27975 +/* policies to select one among multiple writable branches */
27977 + AuWbrCreate_TDP, /* top down parent */
27978 + AuWbrCreate_RR, /* round robin */
27979 + AuWbrCreate_MFS, /* most free space */
27980 + AuWbrCreate_MFSV, /* mfs with seconds */
27981 + AuWbrCreate_MFSRR, /* mfs then rr */
27982 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27983 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27984 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27985 + AuWbrCreate_PMFS, /* parent and mfs */
27986 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27987 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27988 + AuWbrCreate_PMFSRRV, /* plus seconds */
27990 + AuWbrCreate_Def = AuWbrCreate_TDP
27994 + AuWbrCopyup_TDP, /* top down parent */
27995 + AuWbrCopyup_BUP, /* bottom up parent */
27996 + AuWbrCopyup_BU, /* bottom up */
27998 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28001 +/* ---------------------------------------------------------------------- */
28005 +struct au_opt_add {
28006 + aufs_bindex_t bindex;
28009 + struct path path;
28012 +struct au_opt_del {
28014 + struct path h_path;
28017 +struct au_opt_mod {
28020 + struct dentry *h_root;
28023 +struct au_opt_xino {
28025 + struct file *file;
28028 +struct au_opt_xino_itrunc {
28029 + aufs_bindex_t bindex;
28032 +struct au_opt_wbr_create {
28035 + unsigned long long mfsrr_watermark;
28041 + struct au_opt_xino xino;
28042 + struct au_opt_xino_itrunc xino_itrunc;
28043 + struct au_opt_add add;
28044 + struct au_opt_del del;
28045 + struct au_opt_mod mod;
28048 + unsigned int rdblk;
28049 + unsigned int rdhash;
28051 + struct au_opt_wbr_create wbr_create;
28053 + unsigned int fhsm_second;
28054 + bool tf; /* generic flag, true or false */
28059 +#define AuOpts_REMOUNT 1
28060 +#define AuOpts_REFRESH (1 << 1)
28061 +#define AuOpts_TRUNC_XIB (1 << 2)
28062 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28063 +#define AuOpts_REFRESH_IDOP (1 << 4)
28064 +#define AuOpts_DR_FLUSHED (1 << 5)
28065 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28066 +#define au_fset_opts(flags, name) \
28067 + do { (flags) |= AuOpts_##name; } while (0)
28068 +#define au_fclr_opts(flags, name) \
28069 + do { (flags) &= ~AuOpts_##name; } while (0)
28071 +#ifndef CONFIG_AUFS_DIRREN
28072 +#undef AuOpts_DR_FLUSHED
28073 +#define AuOpts_DR_FLUSHED 0
28077 + struct au_opt *opt;
28080 + unsigned int given_udba;
28081 + unsigned int flags;
28082 + unsigned long sb_flags;
28085 +/* ---------------------------------------------------------------------- */
28088 +int au_br_perm_val(char *perm);
28089 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28090 +int au_udba_val(char *str);
28091 +const char *au_optstr_udba(int udba);
28092 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28093 +const char *au_optstr_wbr_create(int wbr_create);
28094 +int au_wbr_copyup_val(char *str);
28095 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28097 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28098 + aufs_bindex_t bindex);
28099 +struct super_block;
28100 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28101 + unsigned int pending);
28102 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28103 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28105 +unsigned int au_opt_udba(struct super_block *sb);
28108 +int aufs_fsctx_init(struct fs_context *fc);
28109 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28111 +#endif /* __KERNEL__ */
28112 +#endif /* __AUFS_OPTS_H__ */
28113 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28114 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28115 +++ linux/fs/aufs/plink.c 2022-03-21 14:49:05.729966343 +0100
28117 +// SPDX-License-Identifier: GPL-2.0
28119 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28121 + * This program, aufs is free software; you can redistribute it and/or modify
28122 + * it under the terms of the GNU General Public License as published by
28123 + * the Free Software Foundation; either version 2 of the License, or
28124 + * (at your option) any later version.
28126 + * This program is distributed in the hope that it will be useful,
28127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28129 + * GNU General Public License for more details.
28131 + * You should have received a copy of the GNU General Public License
28132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28142 + * the pseudo-link maintenance mode.
28143 + * during a user process maintains the pseudo-links,
28144 + * prohibit adding a new plink and branch manipulation.
28148 + * For entry functions which will handle plink, and i_mutex is already held
28150 + * They cannot wait and should return an error at once.
28151 + * Callers has to check the error.
28153 + * For entry functions which will handle plink, but i_mutex is not held
28155 + * They can wait the plink maintenance mode to finish.
28157 + * They behave like F_SETLK and F_SETLKW.
28158 + * If the caller never handle plink, then both flags are unnecessary.
28161 +int au_plink_maint(struct super_block *sb, int flags)
28165 + struct task_struct *parent, *prev;
28166 + struct au_sbinfo *sbi;
28168 + SiMustAnyLock(sb);
28171 + if (!au_opt_test(au_mntflags(sb), PLINK))
28174 + sbi = au_sbi(sb);
28175 + pid = sbi->si_plink_maint_pid;
28176 + if (!pid || pid == current->pid)
28179 + /* todo: it highly depends upon /sbin/mount.aufs */
28181 + parent = current;
28185 + parent = rcu_dereference(parent->real_parent);
28186 + if (parent == prev)
28188 + ppid = task_pid_vnr(parent);
28189 + if (pid == ppid) {
28190 + rcu_read_unlock();
28195 + rcu_read_unlock();
28197 + if (au_ftest_lock(flags, NOPLMW)) {
28198 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28199 + /* AuDebugOn(!lockdep_depth(current)); */
28200 + while (sbi->si_plink_maint_pid) {
28201 + si_read_unlock(sb);
28202 + /* gave up wake_up_bit() */
28203 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28205 + if (au_ftest_lock(flags, FLUSH))
28206 + au_nwt_flush(&sbi->si_nowait);
28207 + si_noflush_read_lock(sb);
28209 + } else if (au_ftest_lock(flags, NOPLM)) {
28210 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28218 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28220 + spin_lock(&sbinfo->si_plink_maint_lock);
28221 + sbinfo->si_plink_maint_pid = 0;
28222 + spin_unlock(&sbinfo->si_plink_maint_lock);
28223 + wake_up_all(&sbinfo->si_plink_wq);
28226 +int au_plink_maint_enter(struct super_block *sb)
28229 + struct au_sbinfo *sbinfo;
28232 + sbinfo = au_sbi(sb);
28233 + /* make sure i am the only one in this fs */
28234 + si_write_lock(sb, AuLock_FLUSH);
28235 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28236 + spin_lock(&sbinfo->si_plink_maint_lock);
28237 + if (!sbinfo->si_plink_maint_pid)
28238 + sbinfo->si_plink_maint_pid = current->pid;
28241 + spin_unlock(&sbinfo->si_plink_maint_lock);
28243 + si_write_unlock(sb);
28248 +/* ---------------------------------------------------------------------- */
28250 +#ifdef CONFIG_AUFS_DEBUG
28251 +void au_plink_list(struct super_block *sb)
28254 + struct au_sbinfo *sbinfo;
28255 + struct hlist_bl_head *hbl;
28256 + struct hlist_bl_node *pos;
28257 + struct au_icntnr *icntnr;
28259 + SiMustAnyLock(sb);
28261 + sbinfo = au_sbi(sb);
28262 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28263 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28265 + for (i = 0; i < AuPlink_NHASH; i++) {
28266 + hbl = sbinfo->si_plink + i;
28267 + hlist_bl_lock(hbl);
28268 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28269 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28270 + hlist_bl_unlock(hbl);
28275 +/* is the inode pseudo-linked? */
28276 +int au_plink_test(struct inode *inode)
28279 + struct au_sbinfo *sbinfo;
28280 + struct hlist_bl_head *hbl;
28281 + struct hlist_bl_node *pos;
28282 + struct au_icntnr *icntnr;
28284 + sbinfo = au_sbi(inode->i_sb);
28285 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28286 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28287 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28290 + i = au_plink_hash(inode->i_ino);
28291 + hbl = sbinfo->si_plink + i;
28292 + hlist_bl_lock(hbl);
28293 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28294 + if (&icntnr->vfs_inode == inode) {
28298 + hlist_bl_unlock(hbl);
28302 +/* ---------------------------------------------------------------------- */
28305 + * generate a name for plink.
28306 + * the file will be stored under AUFS_WH_PLINKDIR.
28308 +/* 20 is max digits length of ulong 64 */
28309 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28311 +static int plink_name(char *name, int len, struct inode *inode,
28312 + aufs_bindex_t bindex)
28315 + struct inode *h_inode;
28317 + h_inode = au_h_iptr(inode, bindex);
28318 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28322 +struct au_do_plink_lkup_args {
28323 + struct dentry **errp;
28324 + struct qstr *tgtname;
28325 + struct path *h_ppath;
28328 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28329 + struct path *h_ppath)
28331 + struct dentry *h_dentry;
28332 + struct inode *h_inode;
28334 + h_inode = d_inode(h_ppath->dentry);
28335 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28336 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28337 + inode_unlock_shared(h_inode);
28342 +static void au_call_do_plink_lkup(void *args)
28344 + struct au_do_plink_lkup_args *a = args;
28345 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28348 +/* lookup the plink-ed @inode under the branch at @bindex */
28349 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28351 + struct dentry *h_dentry;
28352 + struct au_branch *br;
28353 + struct path h_ppath;
28355 + char a[PLINK_NAME_LEN];
28356 + struct qstr tgtname = QSTR_INIT(a, 0);
28358 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28360 + br = au_sbr(inode->i_sb, bindex);
28361 + h_ppath.dentry = br->br_wbr->wbr_plink;
28362 + h_ppath.mnt = au_br_mnt(br);
28363 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28365 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28366 + struct au_do_plink_lkup_args args = {
28367 + .errp = &h_dentry,
28368 + .tgtname = &tgtname,
28369 + .h_ppath = &h_ppath
28372 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28373 + if (unlikely(wkq_err))
28374 + h_dentry = ERR_PTR(wkq_err);
28376 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28381 +/* create a pseudo-link */
28382 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28383 + struct dentry *h_dentry)
28386 + struct path h_path;
28387 + struct inode *h_dir, *delegated;
28389 + h_dir = d_inode(h_ppath->dentry);
28390 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28391 + h_path.mnt = h_ppath->mnt;
28393 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28394 + err = PTR_ERR(h_path.dentry);
28395 + if (IS_ERR(h_path.dentry))
28399 + /* wh.plink dir is not monitored */
28400 + /* todo: is it really safe? */
28401 + if (d_is_positive(h_path.dentry)
28402 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28403 + delegated = NULL;
28404 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28405 + if (unlikely(err == -EWOULDBLOCK)) {
28406 + pr_warn("cannot retry for NFSv4 delegation"
28407 + " for an internal unlink\n");
28410 + dput(h_path.dentry);
28411 + h_path.dentry = NULL;
28415 + if (!err && d_is_negative(h_path.dentry)) {
28416 + delegated = NULL;
28417 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28418 + if (unlikely(err == -EWOULDBLOCK)) {
28419 + pr_warn("cannot retry for NFSv4 delegation"
28420 + " for an internal link\n");
28424 + dput(h_path.dentry);
28427 + inode_unlock(h_dir);
28431 +struct do_whplink_args {
28433 + struct qstr *tgt;
28434 + struct path *h_ppath;
28435 + struct dentry *h_dentry;
28438 +static void call_do_whplink(void *args)
28440 + struct do_whplink_args *a = args;
28441 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28444 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28445 + aufs_bindex_t bindex)
28447 + int err, wkq_err;
28448 + struct au_branch *br;
28449 + struct au_wbr *wbr;
28450 + struct path h_ppath;
28451 + char a[PLINK_NAME_LEN];
28452 + struct qstr tgtname = QSTR_INIT(a, 0);
28454 + br = au_sbr(inode->i_sb, bindex);
28455 + wbr = br->br_wbr;
28456 + h_ppath.dentry = wbr->wbr_plink;
28457 + h_ppath.mnt = au_br_mnt(br);
28458 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28460 + /* always superio. */
28461 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28462 + struct do_whplink_args args = {
28465 + .h_ppath = &h_ppath,
28466 + .h_dentry = h_dentry
28468 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28469 + if (unlikely(wkq_err))
28472 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28478 + * create a new pseudo-link for @h_dentry on @bindex.
28479 + * the linked inode is held in aufs @inode.
28481 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28482 + struct dentry *h_dentry)
28484 + struct super_block *sb;
28485 + struct au_sbinfo *sbinfo;
28486 + struct hlist_bl_head *hbl;
28487 + struct hlist_bl_node *pos;
28488 + struct au_icntnr *icntnr;
28489 + int found, err, cnt, i;
28491 + sb = inode->i_sb;
28492 + sbinfo = au_sbi(sb);
28493 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28494 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28496 + found = au_plink_test(inode);
28500 + i = au_plink_hash(inode->i_ino);
28501 + hbl = sbinfo->si_plink + i;
28504 + hlist_bl_lock(hbl);
28505 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28506 + if (&icntnr->vfs_inode == inode) {
28512 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28513 + hlist_bl_add_head(&icntnr->plink, hbl);
28515 + hlist_bl_unlock(hbl);
28517 + cnt = au_hbl_count(hbl);
28518 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28519 + if (cnt > AUFS_PLINK_WARN)
28520 + AuWarn1(msg ", %d\n", cnt);
28522 + err = whplink(h_dentry, inode, bindex);
28523 + if (unlikely(err)) {
28524 + pr_warn("err %d, damaged pseudo link.\n", err);
28525 + au_hbl_del(&icntnr->plink, hbl);
28526 + iput(&icntnr->vfs_inode);
28529 + iput(&icntnr->vfs_inode);
28532 +/* free all plinks */
28533 +void au_plink_put(struct super_block *sb, int verbose)
28536 + struct au_sbinfo *sbinfo;
28537 + struct hlist_bl_head *hbl;
28538 + struct hlist_bl_node *pos, *tmp;
28539 + struct au_icntnr *icntnr;
28541 + SiMustWriteLock(sb);
28543 + sbinfo = au_sbi(sb);
28544 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28545 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28547 + /* no spin_lock since sbinfo is write-locked */
28549 + for (i = 0; i < AuPlink_NHASH; i++) {
28550 + hbl = sbinfo->si_plink + i;
28551 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28552 + pr_warn("pseudo-link is not flushed");
28555 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28556 + iput(&icntnr->vfs_inode);
28557 + INIT_HLIST_BL_HEAD(hbl);
28561 +void au_plink_clean(struct super_block *sb, int verbose)
28563 + struct dentry *root;
28565 + root = sb->s_root;
28566 + aufs_write_lock(root);
28567 + if (au_opt_test(au_mntflags(sb), PLINK))
28568 + au_plink_put(sb, verbose);
28569 + aufs_write_unlock(root);
28572 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28575 + aufs_bindex_t btop, bbot, bindex;
28578 + btop = au_ibtop(inode);
28579 + bbot = au_ibbot(inode);
28581 + for (bindex = btop; bindex <= bbot; bindex++) {
28582 + if (!au_h_iptr(inode, bindex)
28583 + || au_ii_br_id(inode, bindex) != br_id)
28585 + au_set_h_iptr(inode, bindex, NULL, 0);
28590 + for (bindex = btop; bindex <= bbot; bindex++)
28591 + if (au_h_iptr(inode, bindex)) {
28601 +/* free the plinks on a branch specified by @br_id */
28602 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28604 + struct au_sbinfo *sbinfo;
28605 + struct hlist_bl_head *hbl;
28606 + struct hlist_bl_node *pos, *tmp;
28607 + struct au_icntnr *icntnr;
28608 + struct inode *inode;
28611 + SiMustWriteLock(sb);
28613 + sbinfo = au_sbi(sb);
28614 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28615 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28617 + /* no bit_lock since sbinfo is write-locked */
28618 + for (i = 0; i < AuPlink_NHASH; i++) {
28619 + hbl = sbinfo->si_plink + i;
28620 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28621 + inode = au_igrab(&icntnr->vfs_inode);
28622 + ii_write_lock_child(inode);
28623 + do_put = au_plink_do_half_refresh(inode, br_id);
28625 + hlist_bl_del(&icntnr->plink);
28628 + ii_write_unlock(inode);
28633 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28634 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28635 +++ linux/fs/aufs/poll.c 2022-03-21 14:49:05.729966343 +0100
28637 +// SPDX-License-Identifier: GPL-2.0
28639 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28641 + * This program, aufs is free software; you can redistribute it and/or modify
28642 + * it under the terms of the GNU General Public License as published by
28643 + * the Free Software Foundation; either version 2 of the License, or
28644 + * (at your option) any later version.
28646 + * This program is distributed in the hope that it will be useful,
28647 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28648 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28649 + * GNU General Public License for more details.
28651 + * You should have received a copy of the GNU General Public License
28652 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28657 + * There is only one filesystem which implements ->poll operation, currently.
28662 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28665 + struct file *h_file;
28666 + struct super_block *sb;
28668 + /* We should pretend an error happened. */
28669 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28670 + sb = file->f_path.dentry->d_sb;
28671 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28673 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28674 + if (IS_ERR(h_file)) {
28675 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28679 + mask = vfs_poll(h_file, pt);
28680 + fput(h_file); /* instead of au_read_post() */
28683 + si_read_unlock(sb);
28684 + if (mask & EPOLLERR)
28685 + AuDbg("mask 0x%x\n", mask);
28688 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28689 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28690 +++ linux/fs/aufs/posix_acl.c 2022-03-21 14:49:05.729966343 +0100
28692 +// SPDX-License-Identifier: GPL-2.0
28694 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28696 + * This program, aufs is free software; you can redistribute it and/or modify
28697 + * it under the terms of the GNU General Public License as published by
28698 + * the Free Software Foundation; either version 2 of the License, or
28699 + * (at your option) any later version.
28701 + * This program is distributed in the hope that it will be useful,
28702 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28703 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28704 + * GNU General Public License for more details.
28706 + * You should have received a copy of the GNU General Public License
28707 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28711 + * posix acl operations
28714 +#include <linux/fs.h>
28717 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28719 + struct posix_acl *acl;
28721 + aufs_bindex_t bindex;
28722 + struct inode *h_inode;
28723 + struct super_block *sb;
28725 + acl = ERR_PTR(-ECHILD);
28730 + sb = inode->i_sb;
28731 + si_read_lock(sb, AuLock_FLUSH);
28732 + ii_read_lock_child(inode);
28733 + if (!(sb->s_flags & SB_POSIXACL))
28736 + bindex = au_ibtop(inode);
28737 + h_inode = au_h_iptr(inode, bindex);
28738 + if (unlikely(!h_inode
28739 + || ((h_inode->i_mode & S_IFMT)
28740 + != (inode->i_mode & S_IFMT)))) {
28741 + err = au_busy_or_stale();
28742 + acl = ERR_PTR(err);
28746 + /* always topmost only */
28747 + acl = get_acl(h_inode, type);
28749 + forget_cached_acl(inode, type);
28751 + set_cached_acl(inode, type, acl);
28754 + ii_read_unlock(inode);
28755 + si_read_unlock(sb);
28758 + AuTraceErrPtr(acl);
28762 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28763 + struct posix_acl *acl, int type)
28767 + struct dentry *dentry;
28768 + struct au_sxattr arg = {
28769 + .type = AU_ACL_SET,
28776 + IMustLock(inode);
28778 + if (inode->i_ino == AUFS_ROOT_INO)
28779 + dentry = dget(inode->i_sb->s_root);
28781 + dentry = d_find_alias(inode);
28783 + dentry = d_find_any_alias(inode);
28785 + pr_warn("cannot handle this inode, "
28786 + "please report to aufs-users ML\n");
28792 + ssz = au_sxattr(dentry, inode, &arg);
28793 + /* forget even it if succeeds since the branch might set differently */
28794 + forget_cached_acl(inode, type);
28803 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28804 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28805 +++ linux/fs/aufs/procfs.c 2022-03-21 14:49:05.729966343 +0100
28807 +// SPDX-License-Identifier: GPL-2.0
28809 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28811 + * This program, aufs is free software; you can redistribute it and/or modify
28812 + * it under the terms of the GNU General Public License as published by
28813 + * the Free Software Foundation; either version 2 of the License, or
28814 + * (at your option) any later version.
28816 + * This program is distributed in the hope that it will be useful,
28817 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28818 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28819 + * GNU General Public License for more details.
28821 + * You should have received a copy of the GNU General Public License
28822 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28826 + * procfs interfaces
28829 +#include <linux/proc_fs.h>
28832 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28834 + struct au_sbinfo *sbinfo;
28836 + sbinfo = file->private_data;
28838 + au_plink_maint_leave(sbinfo);
28839 + kobject_put(&sbinfo->si_kobj);
28845 +static void au_procfs_plm_write_clean(struct file *file)
28847 + struct au_sbinfo *sbinfo;
28849 + sbinfo = file->private_data;
28851 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28854 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28857 + struct super_block *sb;
28858 + struct au_sbinfo *sbinfo;
28859 + struct hlist_bl_node *pos;
28862 + if (unlikely(file->private_data))
28866 + /* don't use au_sbilist_lock() here */
28867 + hlist_bl_lock(&au_sbilist);
28868 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28869 + if (id == sysaufs_si_id(sbinfo)) {
28870 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28871 + sb = sbinfo->si_sb;
28874 + hlist_bl_unlock(&au_sbilist);
28877 + if (unlikely(!sb))
28880 + err = au_plink_maint_enter(sb);
28882 + /* keep kobject_get() */
28883 + file->private_data = sbinfo;
28885 + kobject_put(&sbinfo->si_kobj);
28891 + * Accept a valid "si=xxxx" only.
28892 + * Once it is accepted successfully, accept "clean" too.
28894 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28895 + size_t count, loff_t *ppos)
28898 + unsigned long id;
28899 + /* last newline is allowed */
28900 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28903 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28907 + if (unlikely(count > sizeof(buf)))
28910 + err = copy_from_user(buf, ubuf, count);
28911 + if (unlikely(err)) {
28918 + if (!strcmp("clean", buf)) {
28919 + au_procfs_plm_write_clean(file);
28920 + goto out_success;
28921 + } else if (unlikely(strncmp("si=", buf, 3)))
28924 + err = kstrtoul(buf + 3, 16, &id);
28925 + if (unlikely(err))
28928 + err = au_procfs_plm_write_si(file, id);
28929 + if (unlikely(err))
28933 + err = count; /* success */
28938 +static const struct proc_ops au_procfs_plm_op = {
28939 + .proc_write = au_procfs_plm_write,
28940 + .proc_release = au_procfs_plm_release
28943 +/* ---------------------------------------------------------------------- */
28945 +static struct proc_dir_entry *au_procfs_dir;
28947 +void au_procfs_fin(void)
28949 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28950 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28953 +int __init au_procfs_init(void)
28956 + struct proc_dir_entry *entry;
28959 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28960 + if (unlikely(!au_procfs_dir))
28963 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28964 + au_procfs_dir, &au_procfs_plm_op);
28965 + if (unlikely(!entry))
28969 + goto out; /* success */
28973 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28977 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28978 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28979 +++ linux/fs/aufs/rdu.c 2022-03-21 14:49:05.729966343 +0100
28981 +// SPDX-License-Identifier: GPL-2.0
28983 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28985 + * This program, aufs is free software; you can redistribute it and/or modify
28986 + * it under the terms of the GNU General Public License as published by
28987 + * the Free Software Foundation; either version 2 of the License, or
28988 + * (at your option) any later version.
28990 + * This program is distributed in the hope that it will be useful,
28991 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28992 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28993 + * GNU General Public License for more details.
28995 + * You should have received a copy of the GNU General Public License
28996 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29000 + * readdir in userspace.
29003 +#include <linux/compat.h>
29004 +#include <linux/fs_stack.h>
29005 +#include <linux/security.h>
29008 +/* bits for struct aufs_rdu.flags */
29009 +#define AuRdu_CALLED 1
29010 +#define AuRdu_CONT (1 << 1)
29011 +#define AuRdu_FULL (1 << 2)
29012 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29013 +#define au_fset_rdu(flags, name) \
29014 + do { (flags) |= AuRdu_##name; } while (0)
29015 +#define au_fclr_rdu(flags, name) \
29016 + do { (flags) &= ~AuRdu_##name; } while (0)
29018 +struct au_rdu_arg {
29019 + struct dir_context ctx;
29020 + struct aufs_rdu *rdu;
29021 + union au_rdu_ent_ul ent;
29022 + unsigned long end;
29024 + struct super_block *sb;
29028 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29029 + loff_t offset, u64 h_ino, unsigned int d_type)
29032 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29033 + struct aufs_rdu *rdu = arg->rdu;
29034 + struct au_rdu_ent ent;
29038 + au_fset_rdu(rdu->cookie.flags, CALLED);
29039 + len = au_rdu_len(nlen);
29040 + if (arg->ent.ul + len < arg->end) {
29042 + ent.bindex = rdu->cookie.bindex;
29043 + ent.type = d_type;
29045 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29046 + ent.type = DT_UNKNOWN;
29048 + /* unnecessary to support mmap_sem since this is a dir */
29050 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29052 + if (copy_to_user(arg->ent.e->name, name, nlen))
29054 + /* the terminating NULL */
29055 + if (__put_user(0, arg->ent.e->name + nlen))
29058 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29059 + arg->ent.ul += len;
29063 + au_fset_rdu(rdu->cookie.flags, FULL);
29065 + rdu->tail = arg->ent;
29069 + /* AuTraceErr(err); */
29073 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29077 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29079 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29080 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29082 + if (unlikely(offset != cookie->h_pos))
29088 + au_fclr_rdu(cookie->flags, CALLED);
29090 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29094 + && au_ftest_rdu(cookie->flags, CALLED)
29095 + && !au_ftest_rdu(cookie->flags, FULL));
29096 + cookie->h_pos = h_file->f_pos;
29103 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29106 + aufs_bindex_t bbot;
29107 + struct au_rdu_arg arg = {
29109 + .actor = au_rdu_fill
29112 + struct dentry *dentry;
29113 + struct inode *inode;
29114 + struct file *h_file;
29115 + struct au_rdu_cookie *cookie = &rdu->cookie;
29117 + /* VERIFY_WRITE */
29118 + err = !access_ok(rdu->ent.e, rdu->sz);
29119 + if (unlikely(err)) {
29125 + rdu->tail = rdu->ent;
29128 + arg.ent = rdu->ent;
29129 + arg.end = arg.ent.ul;
29130 + arg.end += rdu->sz;
29133 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
29136 + err = security_file_permission(file, MAY_READ);
29138 + if (unlikely(err))
29141 + dentry = file->f_path.dentry;
29142 + inode = d_inode(dentry);
29143 + inode_lock_shared(inode);
29145 + arg.sb = inode->i_sb;
29146 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29147 + if (unlikely(err))
29149 + err = au_alive_dir(dentry);
29150 + if (unlikely(err))
29152 + /* todo: reval? */
29153 + fi_read_lock(file);
29156 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29157 + && cookie->generation != au_figen(file)))
29162 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29164 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29166 + bbot = au_fbtop(file);
29167 + if (cookie->bindex < bbot)
29168 + cookie->bindex = bbot;
29169 + bbot = au_fbbot_dir(file);
29170 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29171 + for (; !err && cookie->bindex <= bbot;
29172 + cookie->bindex++, cookie->h_pos = 0) {
29173 + h_file = au_hf_dir(file, cookie->bindex);
29177 + au_fclr_rdu(cookie->flags, FULL);
29178 + err = au_rdu_do(h_file, &arg);
29180 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29183 + AuDbg("rent %llu\n", rdu->rent);
29185 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29186 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29187 + au_fset_rdu(cookie->flags, CONT);
29188 + cookie->generation = au_figen(file);
29191 + ii_read_lock_child(inode);
29192 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29193 + ii_read_unlock(inode);
29196 + fi_read_unlock(file);
29198 + si_read_unlock(arg.sb);
29200 + inode_unlock_shared(inode);
29206 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29210 + unsigned long long nent;
29211 + union au_rdu_ent_ul *u;
29212 + struct au_rdu_ent ent;
29213 + struct super_block *sb;
29216 + nent = rdu->nent;
29218 + sb = file->f_path.dentry->d_sb;
29219 + si_read_lock(sb, AuLock_FLUSH);
29220 + while (nent-- > 0) {
29221 + /* unnecessary to support mmap_sem since this is a dir */
29222 + err = copy_from_user(&ent, u->e, sizeof(ent));
29224 + /* VERIFY_WRITE */
29225 + err = !access_ok(&u->e->ino, sizeof(ino));
29226 + if (unlikely(err)) {
29232 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29234 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29236 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29238 + if (unlikely(err)) {
29243 + err = __put_user(ino, &u->e->ino);
29244 + if (unlikely(err)) {
29249 + u->ul += au_rdu_len(ent.nlen);
29251 + si_read_unlock(sb);
29256 +/* ---------------------------------------------------------------------- */
29258 +static int au_rdu_verify(struct aufs_rdu *rdu)
29260 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29261 + "%llu, b%d, 0x%x, g%u}\n",
29262 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29264 + rdu->rent, rdu->shwh, rdu->full,
29265 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29266 + rdu->cookie.generation);
29268 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29272 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29276 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29279 + struct aufs_rdu rdu;
29280 + void __user *p = (void __user *)arg;
29282 + err = copy_from_user(&rdu, p, sizeof(rdu));
29283 + if (unlikely(err)) {
29288 + err = au_rdu_verify(&rdu);
29289 + if (unlikely(err))
29293 + case AUFS_CTL_RDU:
29294 + err = au_rdu(file, &rdu);
29295 + if (unlikely(err))
29298 + e = copy_to_user(p, &rdu, sizeof(rdu));
29299 + if (unlikely(e)) {
29304 + case AUFS_CTL_RDU_INO:
29305 + err = au_rdu_ino(file, &rdu);
29309 + /* err = -ENOTTY; */
29318 +#ifdef CONFIG_COMPAT
29319 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29322 + struct aufs_rdu rdu;
29323 + void __user *p = compat_ptr(arg);
29325 + /* todo: get_user()? */
29326 + err = copy_from_user(&rdu, p, sizeof(rdu));
29327 + if (unlikely(err)) {
29332 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29333 + err = au_rdu_verify(&rdu);
29334 + if (unlikely(err))
29338 + case AUFS_CTL_RDU:
29339 + err = au_rdu(file, &rdu);
29340 + if (unlikely(err))
29343 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29344 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29345 + e = copy_to_user(p, &rdu, sizeof(rdu));
29346 + if (unlikely(e)) {
29351 + case AUFS_CTL_RDU_INO:
29352 + err = au_rdu_ino(file, &rdu);
29356 + /* err = -ENOTTY; */
29365 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29366 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29367 +++ linux/fs/aufs/rwsem.h 2022-03-21 14:49:05.729966343 +0100
29369 +/* SPDX-License-Identifier: GPL-2.0 */
29371 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29373 + * This program, aufs is free software; you can redistribute it and/or modify
29374 + * it under the terms of the GNU General Public License as published by
29375 + * the Free Software Foundation; either version 2 of the License, or
29376 + * (at your option) any later version.
29378 + * This program is distributed in the hope that it will be useful,
29379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29381 + * GNU General Public License for more details.
29383 + * You should have received a copy of the GNU General Public License
29384 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29388 + * simple read-write semaphore wrappers
29391 +#ifndef __AUFS_RWSEM_H__
29392 +#define __AUFS_RWSEM_H__
29396 +#include "debug.h"
29398 +/* in the future, the name 'au_rwsem' will be totally gone */
29399 +#define au_rwsem rw_semaphore
29401 +/* to debug easier, do not make them inlined functions */
29402 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29404 +#ifdef CONFIG_LOCKDEP
29405 +/* rwsem_is_locked() is unusable */
29406 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29407 + && !lockdep_recursing(current) \
29409 + && !lockdep_is_held_type(rw, 1))
29410 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29411 + && !lockdep_recursing(current) \
29413 + && !lockdep_is_held_type(rw, 0))
29414 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29415 + && !lockdep_recursing(current) \
29417 + && !lockdep_is_held(rw))
29418 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29419 + && !lockdep_recursing(current) \
29421 + && lockdep_is_held(rw))
29423 +#define AuRwMustReadLock(rw) do {} while (0)
29424 +#define AuRwMustWriteLock(rw) do {} while (0)
29425 +#define AuRwMustAnyLock(rw) do {} while (0)
29426 +#define AuRwDestroy(rw) do {} while (0)
29429 +#define au_rw_init(rw) init_rwsem(rw)
29431 +#define au_rw_init_wlock(rw) do { \
29432 + au_rw_init(rw); \
29433 + down_write(rw); \
29436 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29437 + au_rw_init(rw); \
29438 + down_write_nested(rw, lsc); \
29441 +#define au_rw_read_lock(rw) down_read(rw)
29442 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29443 +#define au_rw_read_unlock(rw) up_read(rw)
29444 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29445 +#define au_rw_write_lock(rw) down_write(rw)
29446 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29447 +#define au_rw_write_unlock(rw) up_write(rw)
29448 +/* why is not _nested version defined? */
29449 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29450 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29452 +#endif /* __KERNEL__ */
29453 +#endif /* __AUFS_RWSEM_H__ */
29454 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29455 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29456 +++ linux/fs/aufs/sbinfo.c 2022-03-21 14:49:05.729966343 +0100
29458 +// SPDX-License-Identifier: GPL-2.0
29460 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29462 + * This program, aufs is free software; you can redistribute it and/or modify
29463 + * it under the terms of the GNU General Public License as published by
29464 + * the Free Software Foundation; either version 2 of the License, or
29465 + * (at your option) any later version.
29467 + * This program is distributed in the hope that it will be useful,
29468 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29469 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29470 + * GNU General Public License for more details.
29472 + * You should have received a copy of the GNU General Public License
29473 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29477 + * superblock private data
29480 +#include <linux/iversion.h>
29484 + * they are necessary regardless sysfs is disabled.
29486 +void au_si_free(struct kobject *kobj)
29489 + struct au_sbinfo *sbinfo;
29490 + char *locked __maybe_unused; /* debug only */
29492 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29493 + for (i = 0; i < AuPlink_NHASH; i++)
29494 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29495 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29497 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29498 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29499 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29500 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29502 + dbgaufs_si_fin(sbinfo);
29503 + au_rw_write_lock(&sbinfo->si_rwsem);
29504 + au_br_free(sbinfo);
29505 + au_rw_write_unlock(&sbinfo->si_rwsem);
29507 + au_kfree_try_rcu(sbinfo->si_branch);
29508 + mutex_destroy(&sbinfo->si_xib_mtx);
29509 + AuRwDestroy(&sbinfo->si_rwsem);
29511 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29512 + /* si_nfiles is waited too */
29513 + au_kfree_rcu(sbinfo);
29516 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29518 + struct au_sbinfo *sbinfo;
29522 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29523 + if (unlikely(!sbinfo))
29526 + /* will be reallocated separately */
29527 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29528 + if (unlikely(!sbinfo->si_branch))
29531 + err = sysaufs_si_init(sbinfo);
29533 + dbgaufs_si_null(sbinfo);
29534 + err = dbgaufs_si_init(sbinfo);
29535 + if (unlikely(err))
29536 + kobject_put(&sbinfo->si_kobj);
29538 + if (unlikely(err))
29541 + au_nwt_init(&sbinfo->si_nowait);
29542 + au_rw_init_wlock(&sbinfo->si_rwsem);
29544 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29545 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29547 + sbinfo->si_bbot = -1;
29548 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29550 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29551 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29552 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29553 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29555 + au_fhsm_init(sbinfo);
29557 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29559 + sbinfo->si_xino_jiffy = jiffies;
29560 + sbinfo->si_xino_expire
29561 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29562 + mutex_init(&sbinfo->si_xib_mtx);
29563 + /* leave si_xib_last_pindex and si_xib_next_bit */
29565 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29567 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29568 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29569 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29570 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29572 + for (i = 0; i < AuPlink_NHASH; i++)
29573 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29574 + init_waitqueue_head(&sbinfo->si_plink_wq);
29575 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29577 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29579 + /* with getattr by default */
29580 + sbinfo->si_iop_array = aufs_iop;
29582 + /* leave other members for sysaufs and si_mnt. */
29583 + sbinfo->si_sb = sb;
29585 + sb->s_fs_info = sbinfo;
29588 + return sbinfo; /* success */
29591 + au_kfree_try_rcu(sbinfo->si_branch);
29593 + au_kfree_rcu(sbinfo);
29595 + return ERR_PTR(err);
29598 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29601 + struct au_branch **brp;
29603 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29606 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29607 + if (unlikely(!sz))
29608 + sz = sizeof(*brp);
29609 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29612 + sbinfo->si_branch = brp;
29619 +/* ---------------------------------------------------------------------- */
29621 +unsigned int au_sigen_inc(struct super_block *sb)
29623 + unsigned int gen;
29624 + struct inode *inode;
29626 + SiMustWriteLock(sb);
29628 + gen = ++au_sbi(sb)->si_generation;
29629 + au_update_digen(sb->s_root);
29630 + inode = d_inode(sb->s_root);
29631 + au_update_iigen(inode, /*half*/0);
29632 + inode_inc_iversion(inode);
29636 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29638 + aufs_bindex_t br_id;
29640 + struct au_sbinfo *sbinfo;
29642 + SiMustWriteLock(sb);
29644 + sbinfo = au_sbi(sb);
29645 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29646 + br_id = ++sbinfo->si_last_br_id;
29647 + AuDebugOn(br_id < 0);
29648 + if (br_id && au_br_index(sb, br_id) < 0)
29655 +/* ---------------------------------------------------------------------- */
29657 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29658 +int si_read_lock(struct super_block *sb, int flags)
29663 + if (au_ftest_lock(flags, FLUSH))
29664 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29666 + si_noflush_read_lock(sb);
29667 + err = au_plink_maint(sb, flags);
29668 + if (unlikely(err))
29669 + si_read_unlock(sb);
29674 +int si_write_lock(struct super_block *sb, int flags)
29678 + if (au_ftest_lock(flags, FLUSH))
29679 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29681 + si_noflush_write_lock(sb);
29682 + err = au_plink_maint(sb, flags);
29683 + if (unlikely(err))
29684 + si_write_unlock(sb);
29689 +/* dentry and super_block lock. call at entry point */
29690 +int aufs_read_lock(struct dentry *dentry, int flags)
29693 + struct super_block *sb;
29695 + sb = dentry->d_sb;
29696 + err = si_read_lock(sb, flags);
29697 + if (unlikely(err))
29700 + if (au_ftest_lock(flags, DW))
29701 + di_write_lock_child(dentry);
29703 + di_read_lock_child(dentry, flags);
29705 + if (au_ftest_lock(flags, GEN)) {
29706 + err = au_digen_test(dentry, au_sigen(sb));
29707 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29708 + AuDebugOn(!err && au_dbrange_test(dentry));
29710 + err = au_dbrange_test(dentry);
29711 + if (unlikely(err))
29712 + aufs_read_unlock(dentry, flags);
29719 +void aufs_read_unlock(struct dentry *dentry, int flags)
29721 + if (au_ftest_lock(flags, DW))
29722 + di_write_unlock(dentry);
29724 + di_read_unlock(dentry, flags);
29725 + si_read_unlock(dentry->d_sb);
29728 +void aufs_write_lock(struct dentry *dentry)
29730 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29731 + di_write_lock_child(dentry);
29734 +void aufs_write_unlock(struct dentry *dentry)
29736 + di_write_unlock(dentry);
29737 + si_write_unlock(dentry->d_sb);
29740 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29743 + unsigned int sigen;
29744 + struct super_block *sb;
29747 + err = si_read_lock(sb, flags);
29748 + if (unlikely(err))
29751 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29753 + if (au_ftest_lock(flags, GEN)) {
29754 + sigen = au_sigen(sb);
29755 + err = au_digen_test(d1, sigen);
29756 + AuDebugOn(!err && au_dbrange_test(d1));
29758 + err = au_digen_test(d2, sigen);
29759 + AuDebugOn(!err && au_dbrange_test(d2));
29761 + if (unlikely(err))
29762 + aufs_read_and_write_unlock2(d1, d2);
29769 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29771 + di_write_unlock2(d1, d2);
29772 + si_read_unlock(d1->d_sb);
29774 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29775 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29776 +++ linux/fs/aufs/super.c 2022-03-21 14:49:05.729966343 +0100
29778 +// SPDX-License-Identifier: GPL-2.0
29780 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29782 + * This program, aufs is free software; you can redistribute it and/or modify
29783 + * it under the terms of the GNU General Public License as published by
29784 + * the Free Software Foundation; either version 2 of the License, or
29785 + * (at your option) any later version.
29787 + * This program is distributed in the hope that it will be useful,
29788 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29789 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29790 + * GNU General Public License for more details.
29792 + * You should have received a copy of the GNU General Public License
29793 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29797 + * mount and super_block operations
29800 +#include <linux/iversion.h>
29801 +#include <linux/mm.h>
29802 +#include <linux/seq_file.h>
29803 +#include <linux/statfs.h>
29804 +#include <linux/vmalloc.h>
29808 + * super_operations
29810 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29812 + struct au_icntnr *c;
29814 + c = au_cache_alloc_icntnr();
29816 + au_icntnr_init(c);
29817 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29818 + c->iinfo.ii_hinode = NULL;
29819 + return &c->vfs_inode;
29824 +static void aufs_destroy_inode(struct inode *inode)
29826 + if (!au_is_bad_inode(inode))
29827 + au_iinfo_fin(inode);
29830 +static void aufs_free_inode(struct inode *inode)
29832 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29835 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29837 + struct inode *inode;
29840 + inode = iget_locked(sb, ino);
29841 + if (unlikely(!inode)) {
29842 + inode = ERR_PTR(-ENOMEM);
29845 + if (!(inode->i_state & I_NEW))
29848 + err = au_xigen_new(inode);
29850 + err = au_iinfo_init(inode);
29852 + inode_inc_iversion(inode);
29854 + iget_failed(inode);
29855 + inode = ERR_PTR(err);
29859 + /* never return NULL */
29860 + AuDebugOn(!inode);
29861 + AuTraceErrPtr(inode);
29865 +/* lock free root dinfo */
29866 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29869 + aufs_bindex_t bindex, bbot;
29870 + struct path path;
29871 + struct au_hdentry *hdp;
29872 + struct au_branch *br;
29873 + au_br_perm_str_t perm;
29876 + bbot = au_sbbot(sb);
29878 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29879 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29880 + br = au_sbr(sb, bindex);
29881 + path.mnt = au_br_mnt(br);
29882 + path.dentry = hdp->hd_dentry;
29883 + err = au_seq_path(seq, &path);
29885 + au_optstr_br_perm(&perm, br->br_perm);
29886 + seq_printf(seq, "=%s", perm.a);
29887 + if (bindex != bbot)
29888 + seq_putc(seq, ':');
29891 + if (unlikely(err || seq_has_overflowed(seq)))
29897 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29898 + const char *append)
29903 + while (*pat != ':')
29906 + strcpy(p, append);
29907 + AuDebugOn(strlen(fmt) >= len);
29910 +static void au_show_wbr_create(struct seq_file *m, int v,
29911 + struct au_sbinfo *sbinfo)
29915 + struct au_wbr_mfs *mfs;
29917 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29919 + seq_puts(m, ",create=");
29920 + pat = au_optstr_wbr_create(v);
29921 + mfs = &sbinfo->si_wbr_mfs;
29923 + case AuWbrCreate_TDP:
29924 + case AuWbrCreate_RR:
29925 + case AuWbrCreate_MFS:
29926 + case AuWbrCreate_PMFS:
29927 + seq_puts(m, pat);
29929 + case AuWbrCreate_MFSRR:
29930 + case AuWbrCreate_TDMFS:
29931 + case AuWbrCreate_PMFSRR:
29932 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29933 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29935 + case AuWbrCreate_MFSV:
29936 + case AuWbrCreate_PMFSV:
29937 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29938 + seq_printf(m, fmt,
29939 + jiffies_to_msecs(mfs->mfs_expire)
29942 + case AuWbrCreate_MFSRRV:
29943 + case AuWbrCreate_TDMFSV:
29944 + case AuWbrCreate_PMFSRRV:
29945 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29946 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29947 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29954 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29956 +#ifdef CONFIG_SYSFS
29960 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29961 + aufs_bindex_t bindex, brid;
29962 + struct qstr *name;
29964 + struct dentry *d, *h_root;
29965 + struct au_branch *br;
29967 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29970 + f = au_sbi(sb)->si_xib;
29974 + /* stop printing the default xino path on the first writable branch */
29976 + bindex = au_xi_root(sb, f->f_path.dentry);
29977 + if (bindex >= 0) {
29978 + br = au_sbr_sb(sb, bindex);
29979 + h_root = au_br_dentry(br);
29982 + d = f->f_path.dentry;
29983 + name = &d->d_name;
29984 + /* safe ->d_parent because the file is unlinked */
29985 + if (d->d_parent == h_root
29986 + && name->len == len
29987 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29990 + seq_puts(seq, ",xino=");
29991 + err = au_xino_path(seq, f);
29998 +/* seq_file will re-call me in case of too long string */
29999 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30002 + unsigned int mnt_flags, v;
30003 + struct super_block *sb;
30004 + struct au_sbinfo *sbinfo;
30006 +#define AuBool(name, str) do { \
30007 + v = au_opt_test(mnt_flags, name); \
30008 + if (v != au_opt_test(AuOpt_Def, name)) \
30009 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30012 +#define AuStr(name, str) do { \
30013 + v = mnt_flags & AuOptMask_##name; \
30014 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30015 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30018 +#define AuUInt(name, str, val) do { \
30019 + if (val != AUFS_##name##_DEF) \
30020 + seq_printf(m, "," #str "=%u", val); \
30023 + sb = dentry->d_sb;
30024 + if (sb->s_flags & SB_POSIXACL)
30025 + seq_puts(m, ",acl");
30026 +#if 0 /* reserved for future use */
30027 + if (sb->s_flags & SB_I_VERSION)
30028 + seq_puts(m, ",i_version");
30031 + /* lock free root dinfo */
30032 + si_noflush_read_lock(sb);
30033 + sbinfo = au_sbi(sb);
30034 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30036 + mnt_flags = au_mntflags(sb);
30037 + if (au_opt_test(mnt_flags, XINO)) {
30038 + err = au_show_xino(m, sb);
30039 + if (unlikely(err))
30042 + seq_puts(m, ",noxino");
30044 + AuBool(TRUNC_XINO, trunc_xino);
30045 + AuStr(UDBA, udba);
30046 + AuBool(SHWH, shwh);
30047 + AuBool(PLINK, plink);
30048 + AuBool(DIO, dio);
30049 + AuBool(DIRPERM1, dirperm1);
30051 + v = sbinfo->si_wbr_create;
30052 + if (v != AuWbrCreate_Def)
30053 + au_show_wbr_create(m, v, sbinfo);
30055 + v = sbinfo->si_wbr_copyup;
30056 + if (v != AuWbrCopyup_Def)
30057 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30059 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30060 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30061 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30063 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30065 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30066 + AuUInt(RDCACHE, rdcache, v);
30068 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30069 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30071 + au_fhsm_show(m, sbinfo);
30073 + AuBool(DIRREN, dirren);
30074 + AuBool(SUM, sum);
30075 + /* AuBool(SUM_W, wsum); */
30076 + AuBool(WARN_PERM, warn_perm);
30077 + AuBool(VERBOSE, verbose);
30080 + /* be sure to print "br:" last */
30081 + if (!sysaufs_brs) {
30082 + seq_puts(m, ",br:");
30083 + au_show_brs(m, sb);
30085 + si_read_unlock(sb);
30093 +/* ---------------------------------------------------------------------- */
30095 +/* sum mode which returns the summation for statfs(2) */
30097 +static u64 au_add_till_max(u64 a, u64 b)
30105 + return ULLONG_MAX;
30108 +static u64 au_mul_till_max(u64 a, long mul)
30116 + return ULLONG_MAX;
30119 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30122 + long bsize, factor;
30123 + u64 blocks, bfree, bavail, files, ffree;
30124 + aufs_bindex_t bbot, bindex, i;
30125 + unsigned char shared;
30126 + struct path h_path;
30127 + struct super_block *h_sb;
30130 + bsize = LONG_MAX;
30136 + bbot = au_sbbot(sb);
30137 + for (bindex = 0; bindex <= bbot; bindex++) {
30138 + h_path.mnt = au_sbr_mnt(sb, bindex);
30139 + h_sb = h_path.mnt->mnt_sb;
30141 + for (i = 0; !shared && i < bindex; i++)
30142 + shared = (au_sbr_sb(sb, i) == h_sb);
30146 + /* sb->s_root for NFS is unreliable */
30147 + h_path.dentry = h_path.mnt->mnt_root;
30148 + err = vfs_statfs(&h_path, buf);
30149 + if (unlikely(err))
30152 + if (bsize > buf->f_bsize) {
30154 + * we will reduce bsize, so we have to expand blocks
30155 + * etc. to match them again
30157 + factor = (bsize / buf->f_bsize);
30158 + blocks = au_mul_till_max(blocks, factor);
30159 + bfree = au_mul_till_max(bfree, factor);
30160 + bavail = au_mul_till_max(bavail, factor);
30161 + bsize = buf->f_bsize;
30164 + factor = (buf->f_bsize / bsize);
30165 + blocks = au_add_till_max(blocks,
30166 + au_mul_till_max(buf->f_blocks, factor));
30167 + bfree = au_add_till_max(bfree,
30168 + au_mul_till_max(buf->f_bfree, factor));
30169 + bavail = au_add_till_max(bavail,
30170 + au_mul_till_max(buf->f_bavail, factor));
30171 + files = au_add_till_max(files, buf->f_files);
30172 + ffree = au_add_till_max(ffree, buf->f_ffree);
30175 + buf->f_bsize = bsize;
30176 + buf->f_blocks = blocks;
30177 + buf->f_bfree = bfree;
30178 + buf->f_bavail = bavail;
30179 + buf->f_files = files;
30180 + buf->f_ffree = ffree;
30181 + buf->f_frsize = 0;
30187 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30190 + struct path h_path;
30191 + struct super_block *sb;
30193 + /* lock free root dinfo */
30194 + sb = dentry->d_sb;
30195 + si_noflush_read_lock(sb);
30196 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30197 + /* sb->s_root for NFS is unreliable */
30198 + h_path.mnt = au_sbr_mnt(sb, 0);
30199 + h_path.dentry = h_path.mnt->mnt_root;
30200 + err = vfs_statfs(&h_path, buf);
30202 + err = au_statfs_sum(sb, buf);
30203 + si_read_unlock(sb);
30206 + buf->f_type = AUFS_SUPER_MAGIC;
30207 + buf->f_namelen = AUFS_MAX_NAMELEN;
30208 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30210 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30215 +/* ---------------------------------------------------------------------- */
30217 +static int aufs_sync_fs(struct super_block *sb, int wait)
30220 + aufs_bindex_t bbot, bindex;
30221 + struct au_branch *br;
30222 + struct super_block *h_sb;
30225 + si_noflush_read_lock(sb);
30226 + bbot = au_sbbot(sb);
30227 + for (bindex = 0; bindex <= bbot; bindex++) {
30228 + br = au_sbr(sb, bindex);
30229 + if (!au_br_writable(br->br_perm))
30232 + h_sb = au_sbr_sb(sb, bindex);
30233 + e = vfsub_sync_filesystem(h_sb);
30234 + if (unlikely(e && !err))
30236 + /* go on even if an error happens */
30238 + si_read_unlock(sb);
30243 +/* ---------------------------------------------------------------------- */
30245 +/* final actions when unmounting a file system */
30246 +static void aufs_put_super(struct super_block *sb)
30248 + struct au_sbinfo *sbinfo;
30250 + sbinfo = au_sbi(sb);
30252 + kobject_put(&sbinfo->si_kobj);
30255 +/* ---------------------------------------------------------------------- */
30257 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30258 + struct super_block *sb, void *arg)
30261 + unsigned long long n, sz;
30268 + if (*hint > ULLONG_MAX / sizeof(array)) {
30269 + array = ERR_PTR(-EMFILE);
30270 + pr_err("hint %llu\n", *hint);
30274 + sz = sizeof(array) * *hint;
30275 + array = kzalloc(sz, GFP_NOFS);
30276 + if (unlikely(!array))
30277 + array = vzalloc(sz);
30278 + if (unlikely(!array)) {
30279 + array = ERR_PTR(-ENOMEM);
30283 + n = cb(sb, array, *hint, arg);
30284 + AuDebugOn(n > *hint);
30291 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30292 + unsigned long long max __maybe_unused,
30295 + unsigned long long n;
30296 + struct inode **p, *inode;
30297 + struct list_head *head;
30302 + spin_lock(&sb->s_inode_list_lock);
30303 + list_for_each_entry(inode, head, i_sb_list) {
30304 + if (!au_is_bad_inode(inode)
30305 + && au_ii(inode)->ii_btop >= 0) {
30306 + spin_lock(&inode->i_lock);
30307 + if (atomic_read(&inode->i_count)) {
30311 + AuDebugOn(n > max);
30313 + spin_unlock(&inode->i_lock);
30316 + spin_unlock(&sb->s_inode_list_lock);
30321 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30323 + struct au_sbinfo *sbi;
30325 + sbi = au_sbi(sb);
30326 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30327 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30330 +void au_iarray_free(struct inode **a, unsigned long long max)
30332 + unsigned long long ull;
30334 + for (ull = 0; ull < max; ull++)
30339 +/* ---------------------------------------------------------------------- */
30342 + * refresh dentry and inode at remount time.
30344 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30345 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30346 + struct dentry *parent)
30350 + di_write_lock_child(dentry);
30351 + di_read_lock_parent(parent, AuLock_IR);
30352 + err = au_refresh_dentry(dentry, parent);
30353 + if (!err && dir_flags)
30354 + au_hn_reset(d_inode(dentry), dir_flags);
30355 + di_read_unlock(parent, AuLock_IR);
30356 + di_write_unlock(dentry);
30361 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30362 + struct au_sbinfo *sbinfo,
30363 + const unsigned int dir_flags, unsigned int do_idop)
30366 + struct dentry *parent;
30369 + parent = dget_parent(dentry);
30370 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30371 + if (d_really_is_positive(dentry)) {
30372 + if (!d_is_dir(dentry))
30373 + err = au_do_refresh(dentry, /*dir_flags*/0,
30376 + err = au_do_refresh(dentry, dir_flags, parent);
30377 + if (unlikely(err))
30378 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30381 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30382 + AuDbgDentry(dentry);
30388 + au_refresh_dop(dentry, /*force_reval*/0);
30390 + au_refresh_dop(dentry, /*force_reval*/1);
30396 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30398 + int err, i, j, ndentry, e;
30399 + unsigned int sigen;
30400 + struct au_dcsub_pages dpages;
30401 + struct au_dpage *dpage;
30402 + struct dentry **dentries, *d;
30403 + struct au_sbinfo *sbinfo;
30404 + struct dentry *root = sb->s_root;
30405 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30408 + au_refresh_dop(root, /*force_reval*/0);
30410 + err = au_dpages_init(&dpages, GFP_NOFS);
30411 + if (unlikely(err))
30413 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30414 + if (unlikely(err))
30417 + sigen = au_sigen(sb);
30418 + sbinfo = au_sbi(sb);
30419 + for (i = 0; i < dpages.ndpage; i++) {
30420 + dpage = dpages.dpages + i;
30421 + dentries = dpage->dentries;
30422 + ndentry = dpage->ndentry;
30423 + for (j = 0; j < ndentry; j++) {
30425 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30427 + if (unlikely(e && !err))
30429 + /* go on even err */
30434 + au_dpages_free(&dpages);
30439 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30442 + unsigned int sigen;
30443 + unsigned long long max, ull;
30444 + struct inode *inode, **array;
30446 + array = au_iarray_alloc(sb, &max);
30447 + err = PTR_ERR(array);
30448 + if (IS_ERR(array))
30452 + sigen = au_sigen(sb);
30453 + for (ull = 0; ull < max; ull++) {
30454 + inode = array[ull];
30455 + if (unlikely(!inode))
30459 + ii_write_lock_child(inode);
30460 + if (au_iigen(inode, NULL) != sigen) {
30461 + e = au_refresh_hinode_self(inode);
30462 + if (unlikely(e)) {
30463 + au_refresh_iop(inode, /*force_getattr*/1);
30464 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30467 + /* go on even if err */
30470 + if (!e && do_idop)
30471 + au_refresh_iop(inode, /*force_getattr*/0);
30472 + ii_write_unlock(inode);
30475 + au_iarray_free(array, max);
30481 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30484 + unsigned int udba;
30485 + aufs_bindex_t bindex, bbot;
30486 + struct dentry *root;
30487 + struct inode *inode;
30488 + struct au_branch *br;
30489 + struct au_sbinfo *sbi;
30491 + au_sigen_inc(sb);
30492 + sbi = au_sbi(sb);
30493 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30495 + root = sb->s_root;
30496 + DiMustNoWaiters(root);
30497 + inode = d_inode(root);
30498 + IiMustNoWaiters(inode);
30500 + udba = au_opt_udba(sb);
30501 + bbot = au_sbbot(sb);
30502 + for (bindex = 0; bindex <= bbot; bindex++) {
30503 + br = au_sbr(sb, bindex);
30504 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30505 + if (unlikely(err))
30506 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30508 + /* go on even if err */
30510 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30513 + if (au_ftest_si(sbi, NO_DREVAL)) {
30514 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30515 + sb->s_d_op = &aufs_dop_noreval;
30516 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30517 + sbi->si_iop_array = aufs_iop_nogetattr;
30519 + AuDebugOn(sb->s_d_op == &aufs_dop);
30520 + sb->s_d_op = &aufs_dop;
30521 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30522 + sbi->si_iop_array = aufs_iop;
30524 + pr_info("reset to %ps and %ps\n",
30525 + sb->s_d_op, sbi->si_iop_array);
30528 + di_write_unlock(root);
30529 + err = au_refresh_d(sb, do_idop);
30530 + e = au_refresh_i(sb, do_idop);
30531 + if (unlikely(e && !err))
30533 + /* aufs_write_lock() calls ..._child() */
30534 + di_write_lock_child(root);
30536 + au_cpup_attr_all(inode, /*force*/1);
30538 + if (unlikely(err))
30539 + AuIOErr("refresh failed, ignored, %d\n", err);
30542 +const struct super_operations aufs_sop = {
30543 + .alloc_inode = aufs_alloc_inode,
30544 + .destroy_inode = aufs_destroy_inode,
30545 + .free_inode = aufs_free_inode,
30546 + /* always deleting, no clearing */
30547 + .drop_inode = generic_delete_inode,
30548 + .show_options = aufs_show_options,
30549 + .statfs = aufs_statfs,
30550 + .put_super = aufs_put_super,
30551 + .sync_fs = aufs_sync_fs
30554 +/* ---------------------------------------------------------------------- */
30556 +int au_alloc_root(struct super_block *sb)
30559 + struct inode *inode;
30560 + struct dentry *root;
30563 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30564 + err = PTR_ERR(inode);
30565 + if (IS_ERR(inode))
30568 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30569 + inode->i_fop = &aufs_dir_fop;
30570 + inode->i_mode = S_IFDIR;
30571 + set_nlink(inode, 2);
30572 + unlock_new_inode(inode);
30574 + root = d_make_root(inode);
30575 + if (unlikely(!root))
30577 + err = PTR_ERR(root);
30578 + if (IS_ERR(root))
30581 + err = au_di_init(root);
30583 + sb->s_root = root;
30584 + return 0; /* success */
30592 +/* ---------------------------------------------------------------------- */
30594 +static void aufs_kill_sb(struct super_block *sb)
30596 + struct au_sbinfo *sbinfo;
30597 + struct dentry *root;
30599 + sbinfo = au_sbi(sb);
30603 + au_sbilist_del(sb);
30605 + root = sb->s_root;
30607 + aufs_write_lock(root);
30609 + __si_write_lock(sb);
30612 + if (sbinfo->si_wbr_create_ops->fin)
30613 + sbinfo->si_wbr_create_ops->fin(sb);
30614 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30615 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30616 + au_remount_refresh(sb, /*do_idop*/0);
30618 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30619 + au_plink_put(sb, /*verbose*/1);
30622 + au_dr_opt_flush(sb);
30625 + aufs_write_unlock(root);
30627 + __si_write_unlock(sb);
30629 + sbinfo->si_sb = NULL;
30630 + au_nwt_flush(&sbinfo->si_nowait);
30633 + kill_anon_super(sb);
30636 +struct file_system_type aufs_fs_type = {
30637 + .name = AUFS_FSTYPE,
30638 + /* a race between rename and others */
30639 + .fs_flags = FS_RENAME_DOES_D_MOVE
30641 + /*| FS_ALLOW_IDMAP*/
30643 + .init_fs_context = aufs_fsctx_init,
30644 + .parameters = aufs_fsctx_paramspec,
30645 + .kill_sb = aufs_kill_sb,
30646 + /* no need to __module_get() and module_put(). */
30647 + .owner = THIS_MODULE,
30649 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30650 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30651 +++ linux/fs/aufs/super.h 2022-03-21 14:49:05.729966343 +0100
30653 +/* SPDX-License-Identifier: GPL-2.0 */
30655 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30657 + * This program, aufs is free software; you can redistribute it and/or modify
30658 + * it under the terms of the GNU General Public License as published by
30659 + * the Free Software Foundation; either version 2 of the License, or
30660 + * (at your option) any later version.
30662 + * This program is distributed in the hope that it will be useful,
30663 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30664 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30665 + * GNU General Public License for more details.
30667 + * You should have received a copy of the GNU General Public License
30668 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30672 + * super_block operations
30675 +#ifndef __AUFS_SUPER_H__
30676 +#define __AUFS_SUPER_H__
30680 +#include <linux/fs.h>
30681 +#include <linux/kobject.h>
30684 +#include "rwsem.h"
30687 +/* policies to select one among multiple writable branches */
30688 +struct au_wbr_copyup_operations {
30689 + int (*copyup)(struct dentry *dentry);
30692 +#define AuWbr_DIR 1 /* target is a dir */
30693 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30695 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30696 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30697 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30699 +struct au_wbr_create_operations {
30700 + int (*create)(struct dentry *dentry, unsigned int flags);
30701 + int (*init)(struct super_block *sb);
30702 + int (*fin)(struct super_block *sb);
30705 +struct au_wbr_mfs {
30706 + struct mutex mfs_lock; /* protect this structure */
30707 + unsigned long mfs_jiffy;
30708 + unsigned long mfs_expire;
30709 + aufs_bindex_t mfs_bindex;
30711 + unsigned long long mfsrr_bytes;
30712 + unsigned long long mfsrr_watermark;
30715 +#define AuPlink_NHASH 100
30716 +static inline int au_plink_hash(ino_t ino)
30718 + return ino % AuPlink_NHASH;
30721 +/* File-based Hierarchical Storage Management */
30723 +#ifdef CONFIG_AUFS_FHSM
30724 + /* allow only one process who can receive the notification */
30725 + spinlock_t fhsm_spin;
30727 + wait_queue_head_t fhsm_wqh;
30728 + atomic_t fhsm_readable;
30730 + /* these are protected by si_rwsem */
30731 + unsigned long fhsm_expire;
30732 + aufs_bindex_t fhsm_bottom;
30737 +struct au_sbinfo {
30738 + /* nowait tasks in the system-wide workqueue */
30739 + struct au_nowait_tasks si_nowait;
30742 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30743 + * rwsem for au_sbinfo is necessary.
30745 + struct au_rwsem si_rwsem;
30748 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30751 + au_lcnt_t si_ninodes, si_nfiles;
30753 + /* branch management */
30754 + unsigned int si_generation;
30756 + /* see AuSi_ flags */
30757 + unsigned char au_si_status;
30759 + aufs_bindex_t si_bbot;
30761 + /* dirty trick to keep br_id plus */
30762 + unsigned int si_last_br_id :
30763 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30764 + struct au_branch **si_branch;
30766 + /* policy to select a writable branch */
30767 + unsigned char si_wbr_copyup;
30768 + unsigned char si_wbr_create;
30769 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30770 + struct au_wbr_create_operations *si_wbr_create_ops;
30772 + /* round robin */
30773 + atomic_t si_wbr_rr_next;
30775 + /* most free space */
30776 + struct au_wbr_mfs si_wbr_mfs;
30778 + /* File-based Hierarchical Storage Management */
30779 + struct au_fhsm si_fhsm;
30781 + /* mount flags */
30782 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30783 + unsigned int si_mntflags;
30785 + /* external inode number (bitmap and translation table) */
30786 + loff_t si_ximaxent; /* max entries in a xino */
30788 + struct file *si_xib;
30789 + struct mutex si_xib_mtx; /* protect xib members */
30790 + unsigned long *si_xib_buf;
30791 + unsigned long si_xib_last_pindex;
30792 + int si_xib_next_bit;
30794 + unsigned long si_xino_jiffy;
30795 + unsigned long si_xino_expire;
30796 + /* reserved for future use */
30797 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30799 +#ifdef CONFIG_AUFS_EXPORT
30800 + /* i_generation */
30801 + /* todo: make xigen file an array to support many inode numbers */
30802 + struct file *si_xigen;
30803 + atomic_t si_xigen_next;
30806 + /* dirty trick to support atomic_open */
30807 + struct hlist_bl_head si_aopen;
30809 + /* vdir parameters */
30810 + unsigned long si_rdcache; /* max cache time in jiffies */
30811 + unsigned int si_rdblk; /* deblk size */
30812 + unsigned int si_rdhash; /* hash size */
30815 + * If the number of whiteouts are larger than si_dirwh, leave all of
30816 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30817 + * future fsck.aufs or kernel thread will remove them later.
30818 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30820 + unsigned int si_dirwh;
30822 + /* pseudo_link list */
30823 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30824 + wait_queue_head_t si_plink_wq;
30825 + spinlock_t si_plink_maint_lock;
30826 + pid_t si_plink_maint_pid;
30829 + struct hlist_bl_head si_files;
30831 + /* with/without getattr, brother of sb->s_d_op */
30832 + const struct inode_operations *si_iop_array;
30835 + * sysfs and lifetime management.
30836 + * this is not a small structure and it may be a waste of memory in case
30837 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30838 + * but using sysfs is majority.
30840 + struct kobject si_kobj;
30841 +#ifdef CONFIG_DEBUG_FS
30842 + struct dentry *si_dbgaufs;
30843 + struct dentry *si_dbgaufs_plink;
30844 + struct dentry *si_dbgaufs_xib;
30845 +#ifdef CONFIG_AUFS_EXPORT
30846 + struct dentry *si_dbgaufs_xigen;
30850 +#ifdef CONFIG_AUFS_SBILIST
30851 + struct hlist_bl_node si_list;
30854 + /* dirty, necessary for unmounting, sysfs and sysrq */
30855 + struct super_block *si_sb;
30858 +/* sbinfo status flags */
30860 + * set true when refresh_dirs() failed at remount time.
30861 + * then try refreshing dirs at access time again.
30862 + * if it is false, refreshing dirs at access time is unnecessary
30864 +#define AuSi_FAILED_REFRESH_DIR 1
30865 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30866 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30868 +#ifndef CONFIG_AUFS_FHSM
30870 +#define AuSi_FHSM 0
30873 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30874 + unsigned int flag)
30876 + AuRwMustAnyLock(&sbi->si_rwsem);
30877 + return sbi->au_si_status & flag;
30879 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30880 +#define au_fset_si(sbinfo, name) do { \
30881 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30882 + (sbinfo)->au_si_status |= AuSi_##name; \
30884 +#define au_fclr_si(sbinfo, name) do { \
30885 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30886 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30889 +/* ---------------------------------------------------------------------- */
30891 +/* policy to select one among writable branches */
30892 +#define AuWbrCopyup(sbinfo, ...) \
30893 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30894 +#define AuWbrCreate(sbinfo, ...) \
30895 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30897 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30898 +#define AuLock_DW 1 /* write-lock dentry */
30899 +#define AuLock_IR (1 << 1) /* read-lock inode */
30900 +#define AuLock_IW (1 << 2) /* write-lock inode */
30901 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30902 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30903 + /* except RENAME_EXCHANGE */
30904 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30905 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30906 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30907 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30908 +#define au_fset_lock(flags, name) \
30909 + do { (flags) |= AuLock_##name; } while (0)
30910 +#define au_fclr_lock(flags, name) \
30911 + do { (flags) &= ~AuLock_##name; } while (0)
30913 +/* ---------------------------------------------------------------------- */
30916 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30918 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30919 + unsigned long long max, void *arg);
30920 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30921 + struct super_block *sb, void *arg);
30922 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30923 +void au_iarray_free(struct inode **a, unsigned long long max);
30925 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
30926 +extern const struct super_operations aufs_sop;
30927 +int au_alloc_root(struct super_block *sb);
30928 +extern struct file_system_type aufs_fs_type;
30931 +void au_si_free(struct kobject *kobj);
30932 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
30933 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30935 +unsigned int au_sigen_inc(struct super_block *sb);
30936 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30938 +int si_read_lock(struct super_block *sb, int flags);
30939 +int si_write_lock(struct super_block *sb, int flags);
30940 +int aufs_read_lock(struct dentry *dentry, int flags);
30941 +void aufs_read_unlock(struct dentry *dentry, int flags);
30942 +void aufs_write_lock(struct dentry *dentry);
30943 +void aufs_write_unlock(struct dentry *dentry);
30944 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30945 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30947 +/* wbr_policy.c */
30948 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30949 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30950 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30951 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30952 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30955 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30957 +#ifdef CONFIG_AUFS_FHSM
30960 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30964 + spin_lock(&fhsm->fhsm_spin);
30965 + pid = fhsm->fhsm_pid;
30966 + spin_unlock(&fhsm->fhsm_spin);
30971 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30972 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30973 +int au_fhsm_fd(struct super_block *sb, int oflags);
30974 +int au_fhsm_br_alloc(struct au_branch *br);
30975 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30976 +void au_fhsm_fin(struct super_block *sb);
30977 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30978 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30979 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30981 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30983 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30984 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30985 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30986 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30987 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30988 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30989 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30990 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30991 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30994 +/* ---------------------------------------------------------------------- */
30996 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30998 + return sb->s_fs_info;
31001 +/* ---------------------------------------------------------------------- */
31003 +#ifdef CONFIG_AUFS_EXPORT
31004 +int au_test_nfsd(void);
31005 +void au_export_init(struct super_block *sb);
31006 +void au_xigen_inc(struct inode *inode);
31007 +int au_xigen_new(struct inode *inode);
31008 +int au_xigen_set(struct super_block *sb, struct path *path);
31009 +void au_xigen_clr(struct super_block *sb);
31011 +static inline int au_busy_or_stale(void)
31013 + if (!au_test_nfsd())
31018 +AuStubInt0(au_test_nfsd, void)
31019 +AuStubVoid(au_export_init, struct super_block *sb)
31020 +AuStubVoid(au_xigen_inc, struct inode *inode)
31021 +AuStubInt0(au_xigen_new, struct inode *inode)
31022 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31023 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31024 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31025 +#endif /* CONFIG_AUFS_EXPORT */
31027 +/* ---------------------------------------------------------------------- */
31029 +#ifdef CONFIG_AUFS_SBILIST
31031 +extern struct hlist_bl_head au_sbilist;
31033 +static inline void au_sbilist_init(void)
31035 + INIT_HLIST_BL_HEAD(&au_sbilist);
31038 +static inline void au_sbilist_add(struct super_block *sb)
31040 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31043 +static inline void au_sbilist_del(struct super_block *sb)
31045 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31048 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31049 +static inline void au_sbilist_lock(void)
31051 + hlist_bl_lock(&au_sbilist);
31054 +static inline void au_sbilist_unlock(void)
31056 + hlist_bl_unlock(&au_sbilist);
31058 +#define AuGFP_SBILIST GFP_ATOMIC
31060 +AuStubVoid(au_sbilist_lock, void)
31061 +AuStubVoid(au_sbilist_unlock, void)
31062 +#define AuGFP_SBILIST GFP_NOFS
31063 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31065 +AuStubVoid(au_sbilist_init, void)
31066 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31067 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31068 +AuStubVoid(au_sbilist_lock, void)
31069 +AuStubVoid(au_sbilist_unlock, void)
31070 +#define AuGFP_SBILIST GFP_NOFS
31073 +/* ---------------------------------------------------------------------- */
31075 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31078 + * This function is a dynamic '__init' function actually,
31079 + * so the tiny check for si_rwsem is unnecessary.
31081 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31082 +#ifdef CONFIG_DEBUG_FS
31083 + sbinfo->si_dbgaufs = NULL;
31084 + sbinfo->si_dbgaufs_plink = NULL;
31085 + sbinfo->si_dbgaufs_xib = NULL;
31086 +#ifdef CONFIG_AUFS_EXPORT
31087 + sbinfo->si_dbgaufs_xigen = NULL;
31092 +/* ---------------------------------------------------------------------- */
31094 +/* current->atomic_flags */
31095 +/* this value should never corrupt the ones defined in linux/sched.h */
31096 +#define PFA_AUFS 0x10
31098 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31099 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31100 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31102 +static inline int si_pid_test(struct super_block *sb)
31104 + return !!task_test_aufs(current);
31107 +static inline void si_pid_clr(struct super_block *sb)
31109 + AuDebugOn(!task_test_aufs(current));
31110 + task_clear_aufs(current);
31113 +static inline void si_pid_set(struct super_block *sb)
31115 + AuDebugOn(task_test_aufs(current));
31116 + task_set_aufs(current);
31119 +/* ---------------------------------------------------------------------- */
31121 +/* lock superblock. mainly for entry point functions */
31122 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31123 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31124 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31125 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31127 +#define __si_read_trylock_nested(sb) \
31128 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31129 +#define __si_write_trylock_nested(sb) \
31130 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31133 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31134 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31135 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31137 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31138 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31139 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31141 +static inline void si_noflush_read_lock(struct super_block *sb)
31143 + __si_read_lock(sb);
31147 +static inline int si_noflush_read_trylock(struct super_block *sb)
31151 + locked = __si_read_trylock(sb);
31157 +static inline void si_noflush_write_lock(struct super_block *sb)
31159 + __si_write_lock(sb);
31163 +static inline int si_noflush_write_trylock(struct super_block *sb)
31167 + locked = __si_write_trylock(sb);
31173 +#if 0 /* reserved */
31174 +static inline int si_read_trylock(struct super_block *sb, int flags)
31176 + if (au_ftest_lock(flags, FLUSH))
31177 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31178 + return si_noflush_read_trylock(sb);
31182 +static inline void si_read_unlock(struct super_block *sb)
31185 + __si_read_unlock(sb);
31188 +#if 0 /* reserved */
31189 +static inline int si_write_trylock(struct super_block *sb, int flags)
31191 + if (au_ftest_lock(flags, FLUSH))
31192 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31193 + return si_noflush_write_trylock(sb);
31197 +static inline void si_write_unlock(struct super_block *sb)
31200 + __si_write_unlock(sb);
31203 +#if 0 /* reserved */
31204 +static inline void si_downgrade_lock(struct super_block *sb)
31206 + __si_downgrade_lock(sb);
31210 +/* ---------------------------------------------------------------------- */
31212 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31214 + SiMustAnyLock(sb);
31215 + return au_sbi(sb)->si_bbot;
31218 +static inline unsigned int au_mntflags(struct super_block *sb)
31220 + SiMustAnyLock(sb);
31221 + return au_sbi(sb)->si_mntflags;
31224 +static inline unsigned int au_sigen(struct super_block *sb)
31226 + SiMustAnyLock(sb);
31227 + return au_sbi(sb)->si_generation;
31230 +static inline struct au_branch *au_sbr(struct super_block *sb,
31231 + aufs_bindex_t bindex)
31233 + SiMustAnyLock(sb);
31234 + return au_sbi(sb)->si_branch[0 + bindex];
31237 +static inline loff_t au_xi_maxent(struct super_block *sb)
31239 + SiMustAnyLock(sb);
31240 + return au_sbi(sb)->si_ximaxent;
31243 +#endif /* __KERNEL__ */
31244 +#endif /* __AUFS_SUPER_H__ */
31245 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31246 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31247 +++ linux/fs/aufs/sysaufs.c 2022-03-21 14:49:05.729966343 +0100
31249 +// SPDX-License-Identifier: GPL-2.0
31251 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31253 + * This program, aufs is free software; you can redistribute it and/or modify
31254 + * it under the terms of the GNU General Public License as published by
31255 + * the Free Software Foundation; either version 2 of the License, or
31256 + * (at your option) any later version.
31258 + * This program is distributed in the hope that it will be useful,
31259 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31260 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31261 + * GNU General Public License for more details.
31263 + * You should have received a copy of the GNU General Public License
31264 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31268 + * sysfs interface and lifetime management
31269 + * they are necessary regardless sysfs is disabled.
31272 +#include <linux/random.h>
31275 +unsigned long sysaufs_si_mask;
31276 +struct kset *sysaufs_kset;
31278 +#define AuSiAttr(_name) { \
31279 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31280 + .show = sysaufs_si_##_name, \
31283 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31284 +struct attribute *sysaufs_si_attrs[] = {
31285 + &sysaufs_si_attr_xi_path.attr,
31289 +static const struct sysfs_ops au_sbi_ops = {
31290 + .show = sysaufs_si_show
31293 +static struct kobj_type au_sbi_ktype = {
31294 + .release = au_si_free,
31295 + .sysfs_ops = &au_sbi_ops,
31296 + .default_attrs = sysaufs_si_attrs
31299 +/* ---------------------------------------------------------------------- */
31301 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31305 + sbinfo->si_kobj.kset = sysaufs_kset;
31306 + /* cf. sysaufs_name() */
31307 + err = kobject_init_and_add
31308 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31309 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31314 +void sysaufs_fin(void)
31316 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31317 + kset_unregister(sysaufs_kset);
31320 +int __init sysaufs_init(void)
31325 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31326 + } while (!sysaufs_si_mask);
31329 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31330 + if (unlikely(!sysaufs_kset))
31332 + err = PTR_ERR(sysaufs_kset);
31333 + if (IS_ERR(sysaufs_kset))
31335 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31336 + if (unlikely(err))
31337 + kset_unregister(sysaufs_kset);
31342 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31343 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31344 +++ linux/fs/aufs/sysaufs.h 2022-03-21 14:49:05.729966343 +0100
31346 +/* SPDX-License-Identifier: GPL-2.0 */
31348 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31350 + * This program, aufs is free software; you can redistribute it and/or modify
31351 + * it under the terms of the GNU General Public License as published by
31352 + * the Free Software Foundation; either version 2 of the License, or
31353 + * (at your option) any later version.
31355 + * This program is distributed in the hope that it will be useful,
31356 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31357 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31358 + * GNU General Public License for more details.
31360 + * You should have received a copy of the GNU General Public License
31361 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31365 + * sysfs interface and mount lifetime management
31368 +#ifndef __SYSAUFS_H__
31369 +#define __SYSAUFS_H__
31373 +#include <linux/sysfs.h>
31374 +#include "module.h"
31376 +struct super_block;
31379 +struct sysaufs_si_attr {
31380 + struct attribute attr;
31381 + int (*show)(struct seq_file *seq, struct super_block *sb);
31384 +/* ---------------------------------------------------------------------- */
31387 +extern unsigned long sysaufs_si_mask;
31388 +extern struct kset *sysaufs_kset;
31389 +extern struct attribute *sysaufs_si_attrs[];
31390 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31391 +int __init sysaufs_init(void);
31392 +void sysaufs_fin(void);
31394 +/* ---------------------------------------------------------------------- */
31396 +/* some people doesn't like to show a pointer in kernel */
31397 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31399 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31402 +#define SysaufsSiNamePrefix "si_"
31403 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31404 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31406 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31407 + sysaufs_si_id(sbinfo));
31411 +#ifdef CONFIG_SYSFS
31413 +extern struct attribute_group *sysaufs_attr_group;
31415 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31416 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31418 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31419 +#ifdef CONFIG_COMPAT
31420 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31423 +void sysaufs_br_init(struct au_branch *br);
31424 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31425 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31427 +#define sysaufs_brs_init() do {} while (0)
31430 +#define sysaufs_attr_group NULL
31432 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31433 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31434 + struct attribute *attr, char *buf)
31435 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31436 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31437 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31439 +static inline void sysaufs_brs_init(void)
31444 +#endif /* CONFIG_SYSFS */
31446 +#endif /* __KERNEL__ */
31447 +#endif /* __SYSAUFS_H__ */
31448 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31449 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31450 +++ linux/fs/aufs/sysfs.c 2022-03-21 14:49:05.729966343 +0100
31452 +// SPDX-License-Identifier: GPL-2.0
31454 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31456 + * This program, aufs is free software; you can redistribute it and/or modify
31457 + * it under the terms of the GNU General Public License as published by
31458 + * the Free Software Foundation; either version 2 of the License, or
31459 + * (at your option) any later version.
31461 + * This program is distributed in the hope that it will be useful,
31462 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31463 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31464 + * GNU General Public License for more details.
31466 + * You should have received a copy of the GNU General Public License
31467 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31471 + * sysfs interface
31474 +#include <linux/compat.h>
31475 +#include <linux/seq_file.h>
31478 +#ifdef CONFIG_AUFS_FS_MODULE
31479 +/* this entry violates the "one line per file" policy of sysfs */
31480 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31484 + static char *conf =
31485 +/* this file is generated at compiling */
31486 +#include "conf.str"
31489 + err = snprintf(buf, PAGE_SIZE, conf);
31490 + if (unlikely(err >= PAGE_SIZE))
31495 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31498 +static struct attribute *au_attr[] = {
31499 +#ifdef CONFIG_AUFS_FS_MODULE
31500 + &au_config_attr.attr,
31502 + NULL, /* need to NULL terminate the list of attributes */
31505 +static struct attribute_group sysaufs_attr_group_body = {
31509 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31511 +/* ---------------------------------------------------------------------- */
31513 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31517 + SiMustAnyLock(sb);
31520 + if (au_opt_test(au_mntflags(sb), XINO)) {
31521 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31522 + seq_putc(seq, '\n');
31528 + * the lifetime of branch is independent from the entry under sysfs.
31529 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31532 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31533 + aufs_bindex_t bindex, int idx)
31536 + struct path path;
31537 + struct dentry *root;
31538 + struct au_branch *br;
31539 + au_br_perm_str_t perm;
31541 + AuDbg("b%d\n", bindex);
31544 + root = sb->s_root;
31545 + di_read_lock_parent(root, !AuLock_IR);
31546 + br = au_sbr(sb, bindex);
31549 + case AuBrSysfs_BR:
31550 + path.mnt = au_br_mnt(br);
31551 + path.dentry = au_h_dptr(root, bindex);
31552 + err = au_seq_path(seq, &path);
31554 + au_optstr_br_perm(&perm, br->br_perm);
31555 + seq_printf(seq, "=%s\n", perm.a);
31558 + case AuBrSysfs_BRID:
31559 + seq_printf(seq, "%d\n", br->br_id);
31562 + di_read_unlock(root, !AuLock_IR);
31563 + if (unlikely(err || seq_has_overflowed(seq)))
31569 +/* ---------------------------------------------------------------------- */
31571 +static struct seq_file *au_seq(char *p, ssize_t len)
31573 + struct seq_file *seq;
31575 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31577 + /* mutex_init(&seq.lock); */
31580 + return seq; /* success */
31583 + seq = ERR_PTR(-ENOMEM);
31587 +#define SysaufsBr_PREFIX "br"
31588 +#define SysaufsBrid_PREFIX "brid"
31590 +/* todo: file size may exceed PAGE_SIZE */
31591 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31597 + aufs_bindex_t bbot;
31598 + struct au_sbinfo *sbinfo;
31599 + struct super_block *sb;
31600 + struct seq_file *seq;
31602 + struct attribute **cattr;
31604 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31605 + sb = sbinfo->si_sb;
31608 + * prevent a race condition between sysfs and aufs.
31609 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31610 + * prohibits maintaining the sysfs entries.
31611 + * hew we acquire read lock after sysfs_get_active_two().
31612 + * on the other hand, the remount process may maintain the sysfs/aufs
31613 + * entries after acquiring write lock.
31614 + * it can cause a deadlock.
31615 + * simply we gave up processing read here.
31618 + if (unlikely(!si_noflush_read_trylock(sb)))
31621 + seq = au_seq(buf, PAGE_SIZE);
31622 + err = PTR_ERR(seq);
31626 + name = (void *)attr->name;
31627 + cattr = sysaufs_si_attrs;
31629 + if (!strcmp(name, (*cattr)->name)) {
31630 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31637 + if (!strncmp(name, SysaufsBrid_PREFIX,
31638 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31639 + idx = AuBrSysfs_BRID;
31640 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31641 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31642 + sizeof(SysaufsBr_PREFIX) - 1)) {
31643 + idx = AuBrSysfs_BR;
31644 + name += sizeof(SysaufsBr_PREFIX) - 1;
31648 + err = kstrtol(name, 10, &l);
31650 + bbot = au_sbbot(sb);
31652 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31659 + err = seq->count;
31660 + /* sysfs limit */
31661 + if (unlikely(err == PAGE_SIZE))
31664 + au_kfree_rcu(seq);
31666 + si_read_unlock(sb);
31671 +/* ---------------------------------------------------------------------- */
31673 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31677 + aufs_bindex_t bindex, bbot;
31680 + struct seq_file *seq;
31681 + struct au_branch *br;
31683 + si_read_lock(sb, AuLock_FLUSH);
31684 + bbot = au_sbbot(sb);
31690 + buf = (void *)__get_free_page(GFP_NOFS);
31691 + if (unlikely(!buf))
31694 + seq = au_seq(buf, PAGE_SIZE);
31695 + err = PTR_ERR(seq);
31699 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31700 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31701 + /* VERIFY_WRITE */
31702 + err = !access_ok(arg, sizeof(*arg));
31703 + if (unlikely(err))
31706 + br = au_sbr(sb, bindex);
31707 + brid = br->br_id;
31708 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31709 + err = __put_user(brid, &arg->id);
31710 + if (unlikely(err))
31713 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31714 + err = __put_user(br->br_perm, &arg->perm);
31715 + if (unlikely(err))
31718 + err = au_seq_path(seq, &br->br_path);
31719 + if (unlikely(err))
31721 + seq_putc(seq, '\0');
31722 + if (!seq_has_overflowed(seq)) {
31723 + err = copy_to_user(arg->path, seq->buf, seq->count);
31725 + if (unlikely(err))
31732 + if (unlikely(err))
31736 + au_kfree_rcu(seq);
31738 + free_page((unsigned long)buf);
31740 + si_read_unlock(sb);
31744 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31746 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31749 +#ifdef CONFIG_COMPAT
31750 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31752 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31756 +/* ---------------------------------------------------------------------- */
31758 +void sysaufs_br_init(struct au_branch *br)
31761 + struct au_brsysfs *br_sysfs;
31762 + struct attribute *attr;
31764 + br_sysfs = br->br_sysfs;
31765 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31766 + attr = &br_sysfs->attr;
31767 + sysfs_attr_init(attr);
31768 + attr->name = br_sysfs->name;
31769 + attr->mode = 0444;
31774 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31776 + struct au_branch *br;
31777 + struct kobject *kobj;
31778 + struct au_brsysfs *br_sysfs;
31780 + aufs_bindex_t bbot;
31782 + if (!sysaufs_brs)
31785 + kobj = &au_sbi(sb)->si_kobj;
31786 + bbot = au_sbbot(sb);
31787 + for (; bindex <= bbot; bindex++) {
31788 + br = au_sbr(sb, bindex);
31789 + br_sysfs = br->br_sysfs;
31790 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31791 + sysfs_remove_file(kobj, &br_sysfs->attr);
31797 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31800 + aufs_bindex_t bbot;
31801 + struct kobject *kobj;
31802 + struct au_branch *br;
31803 + struct au_brsysfs *br_sysfs;
31805 + if (!sysaufs_brs)
31808 + kobj = &au_sbi(sb)->si_kobj;
31809 + bbot = au_sbbot(sb);
31810 + for (; bindex <= bbot; bindex++) {
31811 + br = au_sbr(sb, bindex);
31812 + br_sysfs = br->br_sysfs;
31813 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31814 + SysaufsBr_PREFIX "%d", bindex);
31815 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31816 + SysaufsBrid_PREFIX "%d", bindex);
31817 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31818 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31819 + if (unlikely(err))
31820 + pr_warn("failed %s under sysfs(%d)\n",
31821 + br_sysfs->name, err);
31826 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31827 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31828 +++ linux/fs/aufs/sysrq.c 2022-03-21 14:49:05.729966343 +0100
31830 +// SPDX-License-Identifier: GPL-2.0
31832 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31834 + * This program, aufs is free software; you can redistribute it and/or modify
31835 + * it under the terms of the GNU General Public License as published by
31836 + * the Free Software Foundation; either version 2 of the License, or
31837 + * (at your option) any later version.
31839 + * This program is distributed in the hope that it will be useful,
31840 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31841 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31842 + * GNU General Public License for more details.
31844 + * You should have received a copy of the GNU General Public License
31845 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31849 + * magic sysrq handler
31852 +/* #include <linux/sysrq.h> */
31853 +#include <linux/writeback.h>
31856 +/* ---------------------------------------------------------------------- */
31858 +static void sysrq_sb(struct super_block *sb)
31861 + struct au_sbinfo *sbinfo;
31862 + struct file *file;
31863 + struct hlist_bl_head *files;
31864 + struct hlist_bl_node *pos;
31865 + struct au_finfo *finfo;
31868 + plevel = au_plevel;
31869 + au_plevel = KERN_WARNING;
31871 + /* since we define pr_fmt, call printk directly */
31872 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31874 + sbinfo = au_sbi(sb);
31875 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31876 + pr("superblock\n");
31879 +#if 0 /* reserved */
31881 + int err, i, j, ndentry;
31882 + struct au_dcsub_pages dpages;
31883 + struct au_dpage *dpage;
31885 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31886 + if (unlikely(err))
31888 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31890 + for (i = 0; i < dpages.ndpage; i++) {
31891 + dpage = dpages.dpages + i;
31892 + ndentry = dpage->ndentry;
31893 + for (j = 0; j < ndentry; j++)
31894 + au_dpri_dentry(dpage->dentries[j]);
31896 + au_dpages_free(&dpages);
31900 + pr("isolated inode\n");
31901 + spin_lock(&sb->s_inode_list_lock);
31902 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31903 + spin_lock(&i->i_lock);
31904 + if (hlist_empty(&i->i_dentry))
31905 + au_dpri_inode(i);
31906 + spin_unlock(&i->i_lock);
31908 + spin_unlock(&sb->s_inode_list_lock);
31911 + files = &au_sbi(sb)->si_files;
31912 + hlist_bl_lock(files);
31913 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31916 + file = finfo->fi_file;
31917 + mode = file_inode(file)->i_mode;
31918 + if (!special_file(mode))
31919 + au_dpri_file(file);
31921 + hlist_bl_unlock(files);
31925 + au_plevel = plevel;
31928 +/* ---------------------------------------------------------------------- */
31930 +/* module parameter */
31931 +static char *aufs_sysrq_key = "a";
31932 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31933 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31935 +static void au_sysrq(int key __maybe_unused)
31937 + struct au_sbinfo *sbinfo;
31938 + struct hlist_bl_node *pos;
31941 + au_sbilist_lock();
31942 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31943 + sysrq_sb(sbinfo->si_sb);
31944 + au_sbilist_unlock();
31948 +static struct sysrq_key_op au_sysrq_op = {
31949 + .handler = au_sysrq,
31950 + .help_msg = "Aufs",
31951 + .action_msg = "Aufs",
31952 + .enable_mask = SYSRQ_ENABLE_DUMP
31955 +/* ---------------------------------------------------------------------- */
31957 +int __init au_sysrq_init(void)
31963 + key = *aufs_sysrq_key;
31964 + if ('a' <= key && key <= 'z')
31965 + err = register_sysrq_key(key, &au_sysrq_op);
31966 + if (unlikely(err))
31967 + pr_err("err %d, sysrq=%c\n", err, key);
31971 +void au_sysrq_fin(void)
31975 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31976 + if (unlikely(err))
31977 + pr_err("err %d (ignored)\n", err);
31979 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31980 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31981 +++ linux/fs/aufs/vdir.c 2022-03-21 14:49:05.733299677 +0100
31983 +// SPDX-License-Identifier: GPL-2.0
31985 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31987 + * This program, aufs is free software; you can redistribute it and/or modify
31988 + * it under the terms of the GNU General Public License as published by
31989 + * the Free Software Foundation; either version 2 of the License, or
31990 + * (at your option) any later version.
31992 + * This program is distributed in the hope that it will be useful,
31993 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31994 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31995 + * GNU General Public License for more details.
31997 + * You should have received a copy of the GNU General Public License
31998 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32002 + * virtual or vertical directory
32005 +#include <linux/iversion.h>
32008 +static unsigned int calc_size(int nlen)
32010 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32013 +static int set_deblk_end(union au_vdir_deblk_p *p,
32014 + union au_vdir_deblk_p *deblk_end)
32016 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32017 + p->de->de_str.len = 0;
32021 + return -1; /* error */
32024 +/* returns true or false */
32025 +static int is_deblk_end(union au_vdir_deblk_p *p,
32026 + union au_vdir_deblk_p *deblk_end)
32028 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32029 + return !p->de->de_str.len;
32033 +static unsigned char *last_deblk(struct au_vdir *vdir)
32035 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32038 +/* ---------------------------------------------------------------------- */
32040 +/* estimate the appropriate size for name hash table */
32041 +unsigned int au_rdhash_est(loff_t sz)
32049 + if (sz < AUFS_RDHASH_DEF)
32050 + n = AUFS_RDHASH_DEF;
32051 + /* pr_info("n %u\n", n); */
32056 + * the allocated memory has to be freed by
32057 + * au_nhash_wh_free() or au_nhash_de_free().
32059 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32061 + struct hlist_head *head;
32065 + sz = sizeof(*nhash->nh_head) * num_hash;
32066 + head = kmalloc(sz, gfp);
32068 + nhash->nh_num = num_hash;
32069 + nhash->nh_head = head;
32070 + for (u = 0; u < num_hash; u++)
32071 + INIT_HLIST_HEAD(head++);
32072 + return 0; /* success */
32078 +static void nhash_count(struct hlist_head *head)
32080 +#if 0 /* debugging */
32082 + struct hlist_node *pos;
32085 + hlist_for_each(pos, head)
32087 + pr_info("%lu\n", n);
32091 +static void au_nhash_wh_do_free(struct hlist_head *head)
32093 + struct au_vdir_wh *pos;
32094 + struct hlist_node *node;
32096 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32097 + au_kfree_rcu(pos);
32100 +static void au_nhash_de_do_free(struct hlist_head *head)
32102 + struct au_vdir_dehstr *pos;
32103 + struct hlist_node *node;
32105 + hlist_for_each_entry_safe(pos, node, head, hash)
32106 + au_cache_free_vdir_dehstr(pos);
32109 +static void au_nhash_do_free(struct au_nhash *nhash,
32110 + void (*free)(struct hlist_head *head))
32113 + struct hlist_head *head;
32115 + n = nhash->nh_num;
32119 + head = nhash->nh_head;
32120 + while (n-- > 0) {
32121 + nhash_count(head);
32124 + au_kfree_try_rcu(nhash->nh_head);
32127 +void au_nhash_wh_free(struct au_nhash *whlist)
32129 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32132 +static void au_nhash_de_free(struct au_nhash *delist)
32134 + au_nhash_do_free(delist, au_nhash_de_do_free);
32137 +/* ---------------------------------------------------------------------- */
32139 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32143 + unsigned int u, n;
32144 + struct hlist_head *head;
32145 + struct au_vdir_wh *pos;
32148 + n = whlist->nh_num;
32149 + head = whlist->nh_head;
32150 + for (u = 0; u < n; u++, head++)
32151 + hlist_for_each_entry(pos, head, wh_hash)
32152 + if (pos->wh_bindex == btgt && ++num > limit)
32157 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32158 + unsigned char *name,
32159 + unsigned int len)
32162 + /* const unsigned int magic_bit = 12; */
32164 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32171 + /* v = hash_long(v, magic_bit); */
32172 + v %= nhash->nh_num;
32173 + return nhash->nh_head + v;
32176 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32179 + return str->len == nlen && !memcmp(str->name, name, nlen);
32182 +/* returns found or not */
32183 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32185 + struct hlist_head *head;
32186 + struct au_vdir_wh *pos;
32187 + struct au_vdir_destr *str;
32189 + head = au_name_hash(whlist, name, nlen);
32190 + hlist_for_each_entry(pos, head, wh_hash) {
32191 + str = &pos->wh_str;
32192 + AuDbg("%.*s\n", str->len, str->name);
32193 + if (au_nhash_test_name(str, name, nlen))
32199 +/* returns found(true) or not */
32200 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32202 + struct hlist_head *head;
32203 + struct au_vdir_dehstr *pos;
32204 + struct au_vdir_destr *str;
32206 + head = au_name_hash(delist, name, nlen);
32207 + hlist_for_each_entry(pos, head, hash) {
32209 + AuDbg("%.*s\n", str->len, str->name);
32210 + if (au_nhash_test_name(str, name, nlen))
32216 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32217 + unsigned char d_type)
32219 +#ifdef CONFIG_AUFS_SHWH
32220 + wh->wh_ino = ino;
32221 + wh->wh_type = d_type;
32225 +/* ---------------------------------------------------------------------- */
32227 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32228 + unsigned int d_type, aufs_bindex_t bindex,
32229 + unsigned char shwh)
32232 + struct au_vdir_destr *str;
32233 + struct au_vdir_wh *wh;
32235 + AuDbg("%.*s\n", nlen, name);
32236 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32239 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32240 + if (unlikely(!wh))
32244 + wh->wh_bindex = bindex;
32246 + au_shwh_init_wh(wh, ino, d_type);
32247 + str = &wh->wh_str;
32249 + memcpy(str->name, name, nlen);
32250 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32257 +static int append_deblk(struct au_vdir *vdir)
32260 + unsigned long ul;
32261 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32262 + union au_vdir_deblk_p p, deblk_end;
32263 + unsigned char **o;
32266 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32267 + GFP_NOFS, /*may_shrink*/0);
32268 + if (unlikely(!o))
32271 + vdir->vd_deblk = o;
32272 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32274 + ul = vdir->vd_nblk++;
32275 + vdir->vd_deblk[ul] = p.deblk;
32276 + vdir->vd_last.ul = ul;
32277 + vdir->vd_last.p.deblk = p.deblk;
32278 + deblk_end.deblk = p.deblk + deblk_sz;
32279 + err = set_deblk_end(&p, &deblk_end);
32286 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32287 + unsigned int d_type, struct au_nhash *delist)
32291 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32292 + union au_vdir_deblk_p p, *room, deblk_end;
32293 + struct au_vdir_dehstr *dehstr;
32295 + p.deblk = last_deblk(vdir);
32296 + deblk_end.deblk = p.deblk + deblk_sz;
32297 + room = &vdir->vd_last.p;
32298 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32299 + || !is_deblk_end(room, &deblk_end));
32301 + sz = calc_size(nlen);
32302 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32303 + err = append_deblk(vdir);
32304 + if (unlikely(err))
32307 + p.deblk = last_deblk(vdir);
32308 + deblk_end.deblk = p.deblk + deblk_sz;
32310 + AuDebugOn(room->deblk != p.deblk);
32314 + dehstr = au_cache_alloc_vdir_dehstr();
32315 + if (unlikely(!dehstr))
32318 + dehstr->str = &room->de->de_str;
32319 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32320 + room->de->de_ino = ino;
32321 + room->de->de_type = d_type;
32322 + room->de->de_str.len = nlen;
32323 + memcpy(room->de->de_str.name, name, nlen);
32326 + room->deblk += sz;
32327 + if (unlikely(set_deblk_end(room, &deblk_end)))
32328 + err = append_deblk(vdir);
32335 +/* ---------------------------------------------------------------------- */
32337 +void au_vdir_free(struct au_vdir *vdir)
32339 + unsigned char **deblk;
32341 + deblk = vdir->vd_deblk;
32342 + while (vdir->vd_nblk--)
32343 + au_kfree_try_rcu(*deblk++);
32344 + au_kfree_try_rcu(vdir->vd_deblk);
32345 + au_cache_free_vdir(vdir);
32348 +static struct au_vdir *alloc_vdir(struct file *file)
32350 + struct au_vdir *vdir;
32351 + struct super_block *sb;
32354 + sb = file->f_path.dentry->d_sb;
32355 + SiMustAnyLock(sb);
32358 + vdir = au_cache_alloc_vdir();
32359 + if (unlikely(!vdir))
32362 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32363 + if (unlikely(!vdir->vd_deblk))
32366 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32367 + if (!vdir->vd_deblk_sz) {
32368 + /* estimate the appropriate size for deblk */
32369 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32370 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32372 + vdir->vd_nblk = 0;
32373 + vdir->vd_version = 0;
32374 + vdir->vd_jiffy = 0;
32375 + err = append_deblk(vdir);
32377 + return vdir; /* success */
32379 + au_kfree_try_rcu(vdir->vd_deblk);
32382 + au_cache_free_vdir(vdir);
32384 + vdir = ERR_PTR(err);
32388 +static int reinit_vdir(struct au_vdir *vdir)
32391 + union au_vdir_deblk_p p, deblk_end;
32393 + while (vdir->vd_nblk > 1) {
32394 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32395 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32398 + p.deblk = vdir->vd_deblk[0];
32399 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32400 + err = set_deblk_end(&p, &deblk_end);
32401 + /* keep vd_dblk_sz */
32402 + vdir->vd_last.ul = 0;
32403 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32404 + vdir->vd_version = 0;
32405 + vdir->vd_jiffy = 0;
32410 +/* ---------------------------------------------------------------------- */
32412 +#define AuFillVdir_CALLED 1
32413 +#define AuFillVdir_WHABLE (1 << 1)
32414 +#define AuFillVdir_SHWH (1 << 2)
32415 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32416 +#define au_fset_fillvdir(flags, name) \
32417 + do { (flags) |= AuFillVdir_##name; } while (0)
32418 +#define au_fclr_fillvdir(flags, name) \
32419 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32421 +#ifndef CONFIG_AUFS_SHWH
32422 +#undef AuFillVdir_SHWH
32423 +#define AuFillVdir_SHWH 0
32426 +struct fillvdir_arg {
32427 + struct dir_context ctx;
32428 + struct file *file;
32429 + struct au_vdir *vdir;
32430 + struct au_nhash delist;
32431 + struct au_nhash whlist;
32432 + aufs_bindex_t bindex;
32433 + unsigned int flags;
32437 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32438 + loff_t offset __maybe_unused, u64 h_ino,
32439 + unsigned int d_type)
32441 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32442 + char *name = (void *)__name;
32443 + struct super_block *sb;
32445 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32448 + sb = arg->file->f_path.dentry->d_sb;
32449 + au_fset_fillvdir(arg->flags, CALLED);
32451 + if (nlen <= AUFS_WH_PFX_LEN
32452 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32453 + if (test_known(&arg->delist, name, nlen)
32454 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32455 + goto out; /* already exists or whiteouted */
32457 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32459 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32460 + d_type = DT_UNKNOWN;
32461 + arg->err = append_de(arg->vdir, name, nlen, ino,
32462 + d_type, &arg->delist);
32464 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32465 + name += AUFS_WH_PFX_LEN;
32466 + nlen -= AUFS_WH_PFX_LEN;
32467 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32468 + goto out; /* already whiteouted */
32470 + ino = 0; /* just to suppress a warning */
32472 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32475 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32476 + d_type = DT_UNKNOWN;
32477 + arg->err = au_nhash_append_wh
32478 + (&arg->whlist, name, nlen, ino, d_type,
32479 + arg->bindex, shwh);
32485 + arg->vdir->vd_jiffy = jiffies;
32487 + AuTraceErr(arg->err);
32491 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32492 + struct au_nhash *whlist, struct au_nhash *delist)
32494 +#ifdef CONFIG_AUFS_SHWH
32496 + unsigned int nh, u;
32497 + struct hlist_head *head;
32498 + struct au_vdir_wh *pos;
32499 + struct hlist_node *n;
32501 + struct au_vdir_destr *destr;
32503 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32506 + o = p = (void *)__get_free_page(GFP_NOFS);
32507 + if (unlikely(!p))
32511 + nh = whlist->nh_num;
32512 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32513 + p += AUFS_WH_PFX_LEN;
32514 + for (u = 0; u < nh; u++) {
32515 + head = whlist->nh_head + u;
32516 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32517 + destr = &pos->wh_str;
32518 + memcpy(p, destr->name, destr->len);
32519 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32520 + pos->wh_ino, pos->wh_type, delist);
32521 + if (unlikely(err))
32526 + free_page((unsigned long)o);
32536 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32539 + unsigned int rdhash;
32541 + aufs_bindex_t bbot, bindex, btop;
32542 + unsigned char shwh;
32543 + struct file *hf, *file;
32544 + struct super_block *sb;
32546 + file = arg->file;
32547 + sb = file->f_path.dentry->d_sb;
32548 + SiMustAnyLock(sb);
32550 + rdhash = au_sbi(sb)->si_rdhash;
32552 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32553 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32554 + if (unlikely(err))
32556 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32557 + if (unlikely(err))
32563 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32565 + au_fset_fillvdir(arg->flags, SHWH);
32567 + btop = au_fbtop(file);
32568 + bbot = au_fbbot_dir(file);
32569 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32570 + hf = au_hf_dir(file, bindex);
32574 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32576 + if (unlikely(offset))
32579 + arg->bindex = bindex;
32580 + au_fclr_fillvdir(arg->flags, WHABLE);
32582 + || (bindex != bbot
32583 + && au_br_whable(au_sbr_perm(sb, bindex))))
32584 + au_fset_fillvdir(arg->flags, WHABLE);
32587 + au_fclr_fillvdir(arg->flags, CALLED);
32589 + err = vfsub_iterate_dir(hf, &arg->ctx);
32592 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32595 + * dir_relax() may be good for concurrency, but aufs should not
32596 + * use it since it will cause a lockdep problem.
32600 + if (!err && shwh)
32601 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32603 + au_nhash_wh_free(&arg->whlist);
32606 + au_nhash_de_free(&arg->delist);
32611 +static int read_vdir(struct file *file, int may_read)
32614 + unsigned long expire;
32615 + unsigned char do_read;
32616 + struct fillvdir_arg arg = {
32618 + .actor = fillvdir
32621 + struct inode *inode;
32622 + struct au_vdir *vdir, *allocated;
32625 + inode = file_inode(file);
32626 + IMustLock(inode);
32627 + IiMustWriteLock(inode);
32628 + SiMustAnyLock(inode->i_sb);
32630 + allocated = NULL;
32632 + expire = au_sbi(inode->i_sb)->si_rdcache;
32633 + vdir = au_ivdir(inode);
32636 + vdir = alloc_vdir(file);
32637 + err = PTR_ERR(vdir);
32638 + if (IS_ERR(vdir))
32641 + allocated = vdir;
32642 + } else if (may_read
32643 + && (!inode_eq_iversion(inode, vdir->vd_version)
32644 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32646 + err = reinit_vdir(vdir);
32647 + if (unlikely(err))
32652 + return 0; /* success */
32656 + err = au_do_read_vdir(&arg);
32658 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32659 + vdir->vd_version = inode_query_iversion(inode);
32660 + vdir->vd_last.ul = 0;
32661 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32663 + au_set_ivdir(inode, allocated);
32664 + } else if (allocated)
32665 + au_vdir_free(allocated);
32671 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32674 + unsigned long ul, n;
32675 + const unsigned int deblk_sz = src->vd_deblk_sz;
32677 + AuDebugOn(tgt->vd_nblk != 1);
32680 + if (tgt->vd_nblk < src->vd_nblk) {
32681 + unsigned char **p;
32683 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32684 + GFP_NOFS, /*may_shrink*/0);
32685 + if (unlikely(!p))
32687 + tgt->vd_deblk = p;
32690 + if (tgt->vd_deblk_sz != deblk_sz) {
32691 + unsigned char *p;
32693 + tgt->vd_deblk_sz = deblk_sz;
32694 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32695 + /*may_shrink*/1);
32696 + if (unlikely(!p))
32698 + tgt->vd_deblk[0] = p;
32700 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32701 + tgt->vd_version = src->vd_version;
32702 + tgt->vd_jiffy = src->vd_jiffy;
32704 + n = src->vd_nblk;
32705 + for (ul = 1; ul < n; ul++) {
32706 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32708 + if (unlikely(!tgt->vd_deblk[ul]))
32712 + tgt->vd_nblk = n;
32713 + tgt->vd_last.ul = tgt->vd_last.ul;
32714 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32715 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32716 + - src->vd_deblk[src->vd_last.ul];
32718 + return 0; /* success */
32721 + rerr = reinit_vdir(tgt);
32726 +int au_vdir_init(struct file *file)
32729 + struct inode *inode;
32730 + struct au_vdir *vdir_cache, *allocated;
32732 + /* test file->f_pos here instead of ctx->pos */
32733 + err = read_vdir(file, !file->f_pos);
32734 + if (unlikely(err))
32737 + allocated = NULL;
32738 + vdir_cache = au_fvdir_cache(file);
32739 + if (!vdir_cache) {
32740 + vdir_cache = alloc_vdir(file);
32741 + err = PTR_ERR(vdir_cache);
32742 + if (IS_ERR(vdir_cache))
32744 + allocated = vdir_cache;
32745 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32746 + /* test file->f_pos here instead of ctx->pos */
32747 + err = reinit_vdir(vdir_cache);
32748 + if (unlikely(err))
32751 + return 0; /* success */
32753 + inode = file_inode(file);
32754 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32756 + file->f_version = inode_query_iversion(inode);
32758 + au_set_fvdir_cache(file, allocated);
32759 + } else if (allocated)
32760 + au_vdir_free(allocated);
32766 +static loff_t calc_offset(struct au_vdir *vdir)
32769 + union au_vdir_deblk_p p;
32771 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32772 + offset = vdir->vd_last.p.deblk - p.deblk;
32773 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32777 +/* returns true or false */
32778 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32781 + unsigned int deblk_sz;
32782 + unsigned long ul, n;
32784 + union au_vdir_deblk_p p, deblk_end;
32785 + struct au_vdir *vdir_cache;
32788 + vdir_cache = au_fvdir_cache(file);
32789 + offset = calc_offset(vdir_cache);
32790 + AuDbg("offset %lld\n", offset);
32791 + if (ctx->pos == offset)
32794 + vdir_cache->vd_last.ul = 0;
32795 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32800 + deblk_sz = vdir_cache->vd_deblk_sz;
32801 + ul = div64_u64(ctx->pos, deblk_sz);
32802 + AuDbg("ul %lu\n", ul);
32803 + if (ul >= vdir_cache->vd_nblk)
32806 + n = vdir_cache->vd_nblk;
32807 + for (; ul < n; ul++) {
32808 + p.deblk = vdir_cache->vd_deblk[ul];
32809 + deblk_end.deblk = p.deblk + deblk_sz;
32811 + offset *= deblk_sz;
32812 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32815 + l = calc_size(p.de->de_str.len);
32819 + if (!is_deblk_end(&p, &deblk_end)) {
32821 + vdir_cache->vd_last.ul = ul;
32822 + vdir_cache->vd_last.p = p;
32830 + AuDbg("valid %d\n", !valid);
32834 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32836 + unsigned int l, deblk_sz;
32837 + union au_vdir_deblk_p deblk_end;
32838 + struct au_vdir *vdir_cache;
32839 + struct au_vdir_de *de;
32841 + if (!seek_vdir(file, ctx))
32844 + vdir_cache = au_fvdir_cache(file);
32845 + deblk_sz = vdir_cache->vd_deblk_sz;
32847 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32848 + deblk_end.deblk += deblk_sz;
32849 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32850 + de = vdir_cache->vd_last.p.de;
32851 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32852 + de->de_str.len, de->de_str.name, ctx->pos,
32853 + (unsigned long)de->de_ino, de->de_type);
32854 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32855 + de->de_str.len, de->de_ino,
32857 + /* todo: ignore the error caused by udba? */
32858 + /* return err; */
32862 + l = calc_size(de->de_str.len);
32863 + vdir_cache->vd_last.p.deblk += l;
32866 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32867 + vdir_cache->vd_last.ul++;
32868 + vdir_cache->vd_last.p.deblk
32869 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32870 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32879 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32880 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32881 +++ linux/fs/aufs/vfsub.c 2022-03-21 14:49:05.733299677 +0100
32883 +// SPDX-License-Identifier: GPL-2.0
32885 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32887 + * This program, aufs is free software; you can redistribute it and/or modify
32888 + * it under the terms of the GNU General Public License as published by
32889 + * the Free Software Foundation; either version 2 of the License, or
32890 + * (at your option) any later version.
32892 + * This program is distributed in the hope that it will be useful,
32893 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32894 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32895 + * GNU General Public License for more details.
32897 + * You should have received a copy of the GNU General Public License
32898 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32902 + * sub-routines for VFS
32905 +#include <linux/mnt_namespace.h>
32906 +#include <linux/nsproxy.h>
32907 +#include <linux/security.h>
32908 +#include <linux/splice.h>
32911 +#ifdef CONFIG_AUFS_BR_FUSE
32912 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32914 + if (!au_test_fuse(h_sb) || !au_userns)
32917 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32921 +int vfsub_sync_filesystem(struct super_block *h_sb)
32926 + down_read(&h_sb->s_umount);
32927 + err = sync_filesystem(h_sb);
32928 + up_read(&h_sb->s_umount);
32934 +/* ---------------------------------------------------------------------- */
32936 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32940 + struct super_block *h_sb;
32943 + * Always needs h_path->mnt for LSM or FUSE branch.
32945 + AuDebugOn(!h_path->mnt);
32947 + /* for remote fs, leave work for its getattr or d_revalidate */
32948 + /* for bad i_attr fs, handle them in aufs_getattr() */
32949 + /* still some fs may acquire i_mutex. we need to skip them */
32953 + h_sb = h_path->dentry->d_sb;
32954 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32956 + err = vfsub_getattr(h_path, &st);
32961 +/* ---------------------------------------------------------------------- */
32963 +struct file *vfsub_dentry_open(struct path *path, int flags)
32965 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32969 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32971 + struct file *file;
32974 + file = filp_open(path,
32975 + oflags /* | __FMODE_NONOTIFY */,
32978 + if (IS_ERR(file))
32980 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32987 + * Ideally this function should call VFS:do_last() in order to keep all its
32988 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32989 + * structure such as nameidata. This is a second (or third) best approach.
32990 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32992 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32993 + struct vfsub_aopen_args *args)
32996 + struct au_branch *br = args->br;
32997 + struct file *file = args->file;
32998 + /* copied from linux/fs/namei.c:atomic_open() */
32999 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33002 + AuDebugOn(!dir->i_op->atomic_open);
33004 + err = au_br_test_oflag(args->open_flag, br);
33005 + if (unlikely(err))
33008 + au_lcnt_inc(&br->br_nfiles);
33009 + file->f_path.dentry = DENTRY_NOT_SET;
33010 + file->f_path.mnt = au_br_mnt(br);
33011 + AuDbg("%ps\n", dir->i_op->atomic_open);
33012 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33013 + args->create_mode);
33014 + if (unlikely(err < 0)) {
33015 + au_lcnt_dec(&br->br_nfiles);
33019 + /* temporary workaround for nfsv4 branch */
33020 + if (au_test_nfs(dir->i_sb))
33021 + nfs_mark_for_revalidate(dir);
33023 + if (file->f_mode & FMODE_CREATED)
33024 + fsnotify_create(dir, dentry);
33025 + if (!(file->f_mode & FMODE_OPENED)) {
33026 + au_lcnt_dec(&br->br_nfiles);
33030 + /* todo: call VFS:may_open() here */
33031 + /* todo: ima_file_check() too? */
33032 + if (!err && (args->open_flag & __FMODE_EXEC))
33033 + err = deny_write_access(file);
33035 + fsnotify_open(file);
33037 + au_lcnt_dec(&br->br_nfiles);
33038 + /* note that the file is created and still opened */
33044 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33048 + err = kern_path(name, flags, path);
33049 + if (!err && d_is_positive(path->dentry))
33050 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33054 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33055 + struct path *ppath, int len)
33057 + struct path path;
33059 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33060 + if (IS_ERR(path.dentry))
33062 + if (d_is_positive(path.dentry)) {
33063 + path.mnt = ppath->mnt;
33064 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33068 + AuTraceErrPtr(path.dentry);
33069 + return path.dentry;
33072 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33075 + struct path path;
33077 + /* VFS checks it too, but by WARN_ON_ONCE() */
33078 + IMustLock(d_inode(ppath->dentry));
33080 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33081 + if (IS_ERR(path.dentry))
33083 + if (d_is_positive(path.dentry)) {
33084 + path.mnt = ppath->mnt;
33085 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33089 + AuTraceErrPtr(path.dentry);
33090 + return path.dentry;
33093 +void vfsub_call_lkup_one(void *args)
33095 + struct vfsub_lkup_one_args *a = args;
33096 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33099 +/* ---------------------------------------------------------------------- */
33101 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33102 + struct dentry *d2, struct au_hinode *hdir2)
33104 + struct dentry *d;
33107 + d = lock_rename(d1, d2);
33109 + au_hn_suspend(hdir1);
33110 + if (hdir1 != hdir2)
33111 + au_hn_suspend(hdir2);
33116 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33117 + struct dentry *d2, struct au_hinode *hdir2)
33119 + au_hn_resume(hdir1);
33120 + if (hdir1 != hdir2)
33121 + au_hn_resume(hdir2);
33123 + unlock_rename(d1, d2);
33127 +/* ---------------------------------------------------------------------- */
33129 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33132 + struct dentry *d;
33133 + struct user_namespace *userns;
33137 + d = path->dentry;
33138 + path->dentry = d->d_parent;
33139 + err = security_path_mknod(path, d, mode, 0);
33140 + path->dentry = d;
33141 + if (unlikely(err))
33143 + userns = mnt_user_ns(path->mnt);
33146 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
33149 + struct path tmp = *path;
33152 + vfsub_update_h_iattr(&tmp, &did);
33154 + tmp.dentry = path->dentry->d_parent;
33155 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33164 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33167 + struct dentry *d;
33168 + struct user_namespace *userns;
33172 + d = path->dentry;
33173 + path->dentry = d->d_parent;
33174 + err = security_path_symlink(path, d, symname);
33175 + path->dentry = d;
33176 + if (unlikely(err))
33178 + userns = mnt_user_ns(path->mnt);
33181 + err = vfs_symlink(userns, dir, path->dentry, symname);
33184 + struct path tmp = *path;
33187 + vfsub_update_h_iattr(&tmp, &did);
33189 + tmp.dentry = path->dentry->d_parent;
33190 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33199 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33202 + struct dentry *d;
33203 + struct user_namespace *userns;
33207 + d = path->dentry;
33208 + path->dentry = d->d_parent;
33209 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33210 + path->dentry = d;
33211 + if (unlikely(err))
33213 + userns = mnt_user_ns(path->mnt);
33216 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
33219 + struct path tmp = *path;
33222 + vfsub_update_h_iattr(&tmp, &did);
33224 + tmp.dentry = path->dentry->d_parent;
33225 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33234 +static int au_test_nlink(struct inode *inode)
33236 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33238 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33239 + || inode->i_nlink < link_max)
33244 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33245 + struct inode **delegated_inode)
33248 + struct dentry *d;
33249 + struct user_namespace *userns;
33253 + err = au_test_nlink(d_inode(src_dentry));
33254 + if (unlikely(err))
33257 + /* we don't call may_linkat() */
33258 + d = path->dentry;
33259 + path->dentry = d->d_parent;
33260 + err = security_path_link(src_dentry, path, d);
33261 + path->dentry = d;
33262 + if (unlikely(err))
33264 + userns = mnt_user_ns(path->mnt);
33267 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33270 + struct path tmp = *path;
33273 + /* fuse has different memory inode for the same inumber */
33274 + vfsub_update_h_iattr(&tmp, &did);
33276 + tmp.dentry = path->dentry->d_parent;
33277 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33278 + tmp.dentry = src_dentry;
33279 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33288 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33289 + struct inode *dir, struct path *path,
33290 + struct inode **delegated_inode, unsigned int flags)
33293 + struct renamedata rd;
33294 + struct path tmp = {
33297 + struct dentry *d;
33300 + IMustLock(src_dir);
33302 + d = path->dentry;
33303 + path->dentry = d->d_parent;
33304 + tmp.dentry = src_dentry->d_parent;
33305 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33306 + path->dentry = d;
33307 + if (unlikely(err))
33310 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33311 + rd.old_dir = src_dir;
33312 + rd.old_dentry = src_dentry;
33313 + rd.new_mnt_userns = rd.old_mnt_userns;
33314 + rd.new_dir = dir;
33315 + rd.new_dentry = path->dentry;
33316 + rd.delegated_inode = delegated_inode;
33317 + rd.flags = flags;
33319 + err = vfs_rename(&rd);
33324 + tmp.dentry = d->d_parent;
33325 + vfsub_update_h_iattr(&tmp, &did);
33327 + tmp.dentry = src_dentry;
33328 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33329 + tmp.dentry = src_dentry->d_parent;
33330 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33339 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33342 + struct dentry *d;
33343 + struct user_namespace *userns;
33347 + d = path->dentry;
33348 + path->dentry = d->d_parent;
33349 + err = security_path_mkdir(path, d, mode);
33350 + path->dentry = d;
33351 + if (unlikely(err))
33353 + userns = mnt_user_ns(path->mnt);
33356 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33359 + struct path tmp = *path;
33362 + vfsub_update_h_iattr(&tmp, &did);
33364 + tmp.dentry = path->dentry->d_parent;
33365 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33374 +int vfsub_rmdir(struct inode *dir, struct path *path)
33377 + struct dentry *d;
33378 + struct user_namespace *userns;
33382 + d = path->dentry;
33383 + path->dentry = d->d_parent;
33384 + err = security_path_rmdir(path, d);
33385 + path->dentry = d;
33386 + if (unlikely(err))
33388 + userns = mnt_user_ns(path->mnt);
33391 + err = vfs_rmdir(userns, dir, path->dentry);
33394 + struct path tmp = {
33395 + .dentry = path->dentry->d_parent,
33399 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33406 +/* ---------------------------------------------------------------------- */
33408 +/* todo: support mmap_sem? */
33409 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33415 + err = vfs_read(file, ubuf, count, ppos);
33418 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33422 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33428 + err = kernel_read(file, kbuf, count, ppos);
33432 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33436 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33442 + err = vfs_write(file, ubuf, count, ppos);
33445 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33449 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33454 + err = kernel_write(file, kbuf, count, ppos);
33457 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33461 +int vfsub_flush(struct file *file, fl_owner_t id)
33466 + if (file->f_op->flush) {
33467 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33468 + err = file->f_op->flush(file, id);
33471 + err = file->f_op->flush(file, id);
33475 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33481 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33485 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33488 + err = iterate_dir(file, ctx);
33491 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33496 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33497 + struct pipe_inode_info *pipe, size_t len,
33498 + unsigned int flags)
33503 + err = do_splice_to(in, ppos, pipe, len, flags);
33505 + file_accessed(in);
33507 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33511 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33512 + loff_t *ppos, size_t len, unsigned int flags)
33517 + err = do_splice_from(pipe, out, ppos, len, flags);
33520 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33524 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33528 + /* file can be NULL */
33530 + err = vfs_fsync(file, datasync);
33534 + AuDebugOn(!file);
33535 + path = &file->f_path;
33537 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33542 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33543 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33544 + struct file *h_file)
33547 + struct inode *h_inode;
33548 + struct super_block *h_sb;
33549 + struct user_namespace *h_userns;
33552 + err = vfsub_truncate(h_path, length);
33556 + h_inode = d_inode(h_path->dentry);
33557 + h_sb = h_inode->i_sb;
33559 + sb_start_write(h_sb);
33561 + err = security_path_truncate(h_path);
33563 + h_userns = mnt_user_ns(h_path->mnt);
33565 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33570 + sb_end_write(h_sb);
33577 +/* ---------------------------------------------------------------------- */
33579 +struct au_vfsub_mkdir_args {
33581 + struct inode *dir;
33582 + struct path *path;
33586 +static void au_call_vfsub_mkdir(void *args)
33588 + struct au_vfsub_mkdir_args *a = args;
33589 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33592 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33594 + int err, do_sio, wkq_err;
33595 + struct user_namespace *userns;
33597 + userns = mnt_user_ns(path->mnt);
33598 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33601 + err = vfsub_mkdir(dir, path, mode);
33604 + struct au_vfsub_mkdir_args args = {
33610 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33611 + if (unlikely(wkq_err))
33618 +struct au_vfsub_rmdir_args {
33620 + struct inode *dir;
33621 + struct path *path;
33624 +static void au_call_vfsub_rmdir(void *args)
33626 + struct au_vfsub_rmdir_args *a = args;
33627 + *a->errp = vfsub_rmdir(a->dir, a->path);
33630 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33632 + int err, do_sio, wkq_err;
33633 + struct user_namespace *userns;
33635 + userns = mnt_user_ns(path->mnt);
33636 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33639 + err = vfsub_rmdir(dir, path);
33642 + struct au_vfsub_rmdir_args args = {
33647 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33648 + if (unlikely(wkq_err))
33655 +/* ---------------------------------------------------------------------- */
33657 +struct notify_change_args {
33659 + struct path *path;
33660 + struct iattr *ia;
33661 + struct inode **delegated_inode;
33664 +static void call_notify_change(void *args)
33666 + struct notify_change_args *a = args;
33667 + struct inode *h_inode;
33668 + struct user_namespace *userns;
33670 + h_inode = d_inode(a->path->dentry);
33671 + IMustLock(h_inode);
33673 + *a->errp = -EPERM;
33674 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33675 + userns = mnt_user_ns(a->path->mnt);
33677 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33678 + a->delegated_inode);
33681 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33683 + AuTraceErr(*a->errp);
33686 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33687 + struct inode **delegated_inode)
33690 + struct notify_change_args args = {
33694 + .delegated_inode = delegated_inode
33697 + call_notify_change(&args);
33702 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33703 + struct inode **delegated_inode)
33705 + int err, wkq_err;
33706 + struct notify_change_args args = {
33710 + .delegated_inode = delegated_inode
33713 + wkq_err = au_wkq_wait(call_notify_change, &args);
33714 + if (unlikely(wkq_err))
33720 +/* ---------------------------------------------------------------------- */
33722 +struct unlink_args {
33724 + struct inode *dir;
33725 + struct path *path;
33726 + struct inode **delegated_inode;
33729 +static void call_unlink(void *args)
33731 + struct unlink_args *a = args;
33732 + struct dentry *d = a->path->dentry;
33733 + struct inode *h_inode;
33734 + struct user_namespace *userns;
33735 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33736 + && au_dcount(d) == 1);
33738 + IMustLock(a->dir);
33740 + a->path->dentry = d->d_parent;
33741 + *a->errp = security_path_unlink(a->path, d);
33742 + a->path->dentry = d;
33743 + if (unlikely(*a->errp))
33746 + if (!stop_sillyrename)
33749 + if (d_is_positive(d)) {
33750 + h_inode = d_inode(d);
33754 + userns = mnt_user_ns(a->path->mnt);
33756 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33759 + struct path tmp = {
33760 + .dentry = d->d_parent,
33761 + .mnt = a->path->mnt
33763 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33766 + if (!stop_sillyrename)
33771 + AuTraceErr(*a->errp);
33775 + * @dir: must be locked.
33776 + * @dentry: target dentry.
33778 +int vfsub_unlink(struct inode *dir, struct path *path,
33779 + struct inode **delegated_inode, int force)
33782 + struct unlink_args args = {
33786 + .delegated_inode = delegated_inode
33790 + call_unlink(&args);
33794 + wkq_err = au_wkq_wait(call_unlink, &args);
33795 + if (unlikely(wkq_err))
33801 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33802 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33803 +++ linux/fs/aufs/vfsub.h 2022-03-21 14:49:05.733299677 +0100
33805 +/* SPDX-License-Identifier: GPL-2.0 */
33807 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33809 + * This program, aufs is free software; you can redistribute it and/or modify
33810 + * it under the terms of the GNU General Public License as published by
33811 + * the Free Software Foundation; either version 2 of the License, or
33812 + * (at your option) any later version.
33814 + * This program is distributed in the hope that it will be useful,
33815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33817 + * GNU General Public License for more details.
33819 + * You should have received a copy of the GNU General Public License
33820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33824 + * sub-routines for VFS
33827 +#ifndef __AUFS_VFSUB_H__
33828 +#define __AUFS_VFSUB_H__
33832 +#include <linux/fs.h>
33833 +#include <linux/mount.h>
33834 +#include <linux/posix_acl.h>
33835 +#include <linux/xattr.h>
33836 +#include "debug.h"
33838 +/* copied from linux/fs/internal.h */
33839 +/* todo: BAD approach!! */
33840 +extern void __mnt_drop_write(struct vfsmount *);
33841 +extern struct file *alloc_empty_file(int, const struct cred *);
33843 +/* ---------------------------------------------------------------------- */
33845 +/* lock subclass for lower inode */
33846 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33847 +/* reduce? gave up. */
33849 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33850 + AuLsc_I_PARENT, /* lower inode, parent first */
33851 + AuLsc_I_PARENT2, /* copyup dirs */
33852 + AuLsc_I_PARENT3, /* copyup wh */
33858 +/* to debug easier, do not make them inlined functions */
33859 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33860 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33862 +/* ---------------------------------------------------------------------- */
33864 +static inline void vfsub_drop_nlink(struct inode *inode)
33866 + AuDebugOn(!inode->i_nlink);
33867 + drop_nlink(inode);
33870 +static inline void vfsub_dead_dir(struct inode *inode)
33872 + AuDebugOn(!S_ISDIR(inode->i_mode));
33873 + inode->i_flags |= S_DEAD;
33874 + clear_nlink(inode);
33877 +static inline int vfsub_native_ro(struct inode *inode)
33879 + return sb_rdonly(inode->i_sb)
33880 + || IS_RDONLY(inode)
33881 + /* || IS_APPEND(inode) */
33882 + || IS_IMMUTABLE(inode);
33885 +#ifdef CONFIG_AUFS_BR_FUSE
33886 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33888 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33891 +int vfsub_sync_filesystem(struct super_block *h_sb);
33893 +/* ---------------------------------------------------------------------- */
33895 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33896 +struct file *vfsub_dentry_open(struct path *path, int flags);
33897 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33899 +struct vfsub_aopen_args {
33900 + struct file *file;
33901 + unsigned int open_flag;
33902 + umode_t create_mode;
33903 + struct au_branch *br;
33905 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33906 + struct vfsub_aopen_args *args);
33907 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33909 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33910 + struct path *ppath, int len);
33911 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33914 +struct vfsub_lkup_one_args {
33915 + struct dentry **errp;
33916 + struct qstr *name;
33917 + struct path *ppath;
33920 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33921 + struct path *ppath)
33923 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33926 +void vfsub_call_lkup_one(void *args);
33928 +/* ---------------------------------------------------------------------- */
33930 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33935 + err = mnt_want_write(mnt);
33940 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33943 + mnt_drop_write(mnt);
33947 +#if 0 /* reserved */
33948 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33951 + mnt_drop_write_file(file);
33956 +/* ---------------------------------------------------------------------- */
33959 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33960 + struct dentry *d2, struct au_hinode *hdir2);
33961 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33962 + struct dentry *d2, struct au_hinode *hdir2);
33964 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33966 +int vfsub_symlink(struct inode *dir, struct path *path,
33967 + const char *symname);
33968 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33969 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33970 + struct path *path, struct inode **delegated_inode);
33971 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33972 + struct inode *hdir, struct path *path,
33973 + struct inode **delegated_inode, unsigned int flags);
33974 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33975 +int vfsub_rmdir(struct inode *dir, struct path *path);
33977 +/* ---------------------------------------------------------------------- */
33979 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33981 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33983 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33985 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33987 +int vfsub_flush(struct file *file, fl_owner_t id);
33988 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33990 +static inline loff_t vfsub_f_size_read(struct file *file)
33992 + return i_size_read(file_inode(file));
33995 +static inline unsigned int vfsub_file_flags(struct file *file)
33997 + unsigned int flags;
33999 + spin_lock(&file->f_lock);
34000 + flags = file->f_flags;
34001 + spin_unlock(&file->f_lock);
34006 +static inline int vfsub_file_execed(struct file *file)
34008 + /* todo: direct access f_flags */
34009 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34012 +#if 0 /* reserved */
34013 +static inline void vfsub_file_accessed(struct file *h_file)
34015 + file_accessed(h_file);
34016 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34020 +#if 0 /* reserved */
34021 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34022 + struct dentry *h_dentry)
34024 + struct path h_path = {
34025 + .dentry = h_dentry,
34028 + touch_atime(&h_path);
34029 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34033 +static inline int vfsub_update_time(struct inode *h_inode,
34034 + struct timespec64 *ts, int flags)
34036 + return inode_update_time(h_inode, ts, flags);
34037 + /* no vfsub_update_h_iattr() since we don't have struct path */
34040 +#ifdef CONFIG_FS_POSIX_ACL
34041 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
34042 + struct inode *h_inode, umode_t h_mode)
34046 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
34047 + if (err == -EOPNOTSUPP)
34052 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
34053 + struct inode *h_inode, umode_t h_mode);
34056 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34057 + struct pipe_inode_info *pipe, size_t len,
34058 + unsigned int flags);
34059 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34060 + loff_t *ppos, size_t len, unsigned int flags);
34062 +static inline long vfsub_truncate(struct path *path, loff_t length)
34067 + err = vfs_truncate(path, length);
34072 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34073 + struct file *h_file);
34074 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34077 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34080 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34086 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34092 +/* copy_file_range(2) is a systemcall */
34093 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34094 + struct file *dst, loff_t dst_pos,
34095 + size_t len, unsigned int flags)
34100 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34106 +/* ---------------------------------------------------------------------- */
34108 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34113 + err = vfs_llseek(file, offset, origin);
34118 +/* ---------------------------------------------------------------------- */
34120 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34121 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34122 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34123 + struct inode **delegated_inode);
34124 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34125 + struct inode **delegated_inode);
34126 +int vfsub_unlink(struct inode *dir, struct path *path,
34127 + struct inode **delegated_inode, int force);
34129 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34131 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34134 +/* ---------------------------------------------------------------------- */
34136 +static inline int vfsub_setxattr(struct user_namespace *userns,
34137 + struct dentry *dentry, const char *name,
34138 + const void *value, size_t size, int flags)
34143 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
34149 +static inline int vfsub_removexattr(struct user_namespace *userns,
34150 + struct dentry *dentry, const char *name)
34155 + err = vfs_removexattr(userns, dentry, name);
34161 +#endif /* __KERNEL__ */
34162 +#endif /* __AUFS_VFSUB_H__ */
34163 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34164 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34165 +++ linux/fs/aufs/wbr_policy.c 2022-03-21 14:49:05.733299677 +0100
34167 +// SPDX-License-Identifier: GPL-2.0
34169 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34171 + * This program, aufs is free software; you can redistribute it and/or modify
34172 + * it under the terms of the GNU General Public License as published by
34173 + * the Free Software Foundation; either version 2 of the License, or
34174 + * (at your option) any later version.
34176 + * This program is distributed in the hope that it will be useful,
34177 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34178 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34179 + * GNU General Public License for more details.
34181 + * You should have received a copy of the GNU General Public License
34182 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34186 + * policies for selecting one among multiple writable branches
34189 +#include <linux/statfs.h>
34192 +/* subset of cpup_attr() */
34193 +static noinline_for_stack
34194 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34198 + struct inode *h_isrc;
34200 + h_isrc = d_inode(h_src);
34201 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34202 + ia.ia_mode = h_isrc->i_mode;
34203 + ia.ia_uid = h_isrc->i_uid;
34204 + ia.ia_gid = h_isrc->i_gid;
34205 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34206 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34207 + /* no delegation since it is just created */
34208 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34210 + /* is this nfs only? */
34211 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34212 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34213 + ia.ia_mode = h_isrc->i_mode;
34214 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34220 +#define AuCpdown_PARENT_OPQ 1
34221 +#define AuCpdown_WHED (1 << 1)
34222 +#define AuCpdown_MADE_DIR (1 << 2)
34223 +#define AuCpdown_DIROPQ (1 << 3)
34224 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34225 +#define au_fset_cpdown(flags, name) \
34226 + do { (flags) |= AuCpdown_##name; } while (0)
34227 +#define au_fclr_cpdown(flags, name) \
34228 + do { (flags) &= ~AuCpdown_##name; } while (0)
34230 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34231 + unsigned int *flags)
34234 + struct dentry *opq_dentry;
34236 + opq_dentry = au_diropq_create(dentry, bdst);
34237 + err = PTR_ERR(opq_dentry);
34238 + if (IS_ERR(opq_dentry))
34240 + dput(opq_dentry);
34241 + au_fset_cpdown(*flags, DIROPQ);
34247 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34248 + struct inode *dir, aufs_bindex_t bdst)
34251 + struct path h_path;
34252 + struct au_branch *br;
34254 + br = au_sbr(dentry->d_sb, bdst);
34255 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34256 + err = PTR_ERR(h_path.dentry);
34257 + if (IS_ERR(h_path.dentry))
34261 + if (d_is_positive(h_path.dentry)) {
34262 + h_path.mnt = au_br_mnt(br);
34263 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34266 + dput(h_path.dentry);
34272 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34273 + struct au_pin *pin,
34274 + struct dentry *h_parent, void *arg)
34277 + aufs_bindex_t bopq, btop;
34278 + struct path h_path;
34279 + struct dentry *parent;
34280 + struct inode *h_dir, *h_inode, *inode, *dir;
34281 + unsigned int *flags = arg;
34283 + btop = au_dbtop(dentry);
34284 + /* dentry is di-locked */
34285 + parent = dget_parent(dentry);
34286 + dir = d_inode(parent);
34287 + h_dir = d_inode(h_parent);
34288 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34289 + IMustLock(h_dir);
34291 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34292 + if (unlikely(err < 0))
34294 + h_path.dentry = au_h_dptr(dentry, bdst);
34295 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34296 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34297 + if (unlikely(err))
34299 + au_fset_cpdown(*flags, MADE_DIR);
34301 + bopq = au_dbdiropq(dentry);
34302 + au_fclr_cpdown(*flags, WHED);
34303 + au_fclr_cpdown(*flags, DIROPQ);
34304 + if (au_dbwh(dentry) == bdst)
34305 + au_fset_cpdown(*flags, WHED);
34306 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34307 + au_fset_cpdown(*flags, PARENT_OPQ);
34308 + h_inode = d_inode(h_path.dentry);
34309 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34310 + if (au_ftest_cpdown(*flags, WHED)) {
34311 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34312 + if (unlikely(err)) {
34313 + inode_unlock(h_inode);
34318 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34319 + inode_unlock(h_inode);
34320 + if (unlikely(err))
34323 + if (au_ftest_cpdown(*flags, WHED)) {
34324 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34325 + if (unlikely(err))
34329 + inode = d_inode(dentry);
34330 + if (au_ibbot(inode) < bdst)
34331 + au_set_ibbot(inode, bdst);
34332 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34333 + au_hi_flags(inode, /*isdir*/1));
34334 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34335 + goto out; /* success */
34339 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34340 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34341 + rerr = au_diropq_remove(dentry, bdst);
34342 + inode_unlock(h_inode);
34343 + if (unlikely(rerr)) {
34344 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34345 + dentry, bdst, rerr);
34351 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34352 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34353 + if (unlikely(rerr)) {
34354 + AuIOErr("failed removing %pd b%d (%d)\n",
34355 + dentry, bdst, rerr);
34360 + au_set_h_dptr(dentry, bdst, NULL);
34361 + if (au_dbbot(dentry) == bdst)
34362 + au_update_dbbot(dentry);
34368 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34371 + unsigned int flags;
34374 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34379 +/* ---------------------------------------------------------------------- */
34381 +/* policies for create */
34383 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34385 + int err, i, j, ndentry;
34386 + aufs_bindex_t bopq;
34387 + struct au_dcsub_pages dpages;
34388 + struct au_dpage *dpage;
34389 + struct dentry **dentries, *parent, *d;
34391 + err = au_dpages_init(&dpages, GFP_NOFS);
34392 + if (unlikely(err))
34394 + parent = dget_parent(dentry);
34395 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34396 + if (unlikely(err))
34400 + for (i = 0; i < dpages.ndpage; i++) {
34401 + dpage = dpages.dpages + i;
34402 + dentries = dpage->dentries;
34403 + ndentry = dpage->ndentry;
34404 + for (j = 0; j < ndentry; j++) {
34406 + di_read_lock_parent2(d, !AuLock_IR);
34407 + bopq = au_dbdiropq(d);
34408 + di_read_unlock(d, !AuLock_IR);
34409 + if (bopq >= 0 && bopq < err)
34416 + au_dpages_free(&dpages);
34421 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34423 + for (; bindex >= 0; bindex--)
34424 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34429 +/* top down parent */
34430 +static int au_wbr_create_tdp(struct dentry *dentry,
34431 + unsigned int flags __maybe_unused)
34434 + aufs_bindex_t btop, bindex;
34435 + struct super_block *sb;
34436 + struct dentry *parent, *h_parent;
34438 + sb = dentry->d_sb;
34439 + btop = au_dbtop(dentry);
34441 + if (!au_br_rdonly(au_sbr(sb, btop)))
34445 + parent = dget_parent(dentry);
34446 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34447 + h_parent = au_h_dptr(parent, bindex);
34448 + if (!h_parent || d_is_negative(h_parent))
34451 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34458 + /* bottom up here */
34459 + if (unlikely(err < 0)) {
34460 + err = au_wbr_bu(sb, btop - 1);
34462 + err = au_wbr_nonopq(dentry, err);
34466 + AuDbg("b%d\n", err);
34470 +/* ---------------------------------------------------------------------- */
34472 +/* an exception for the policy other than tdp */
34473 +static int au_wbr_create_exp(struct dentry *dentry)
34476 + aufs_bindex_t bwh, bdiropq;
34477 + struct dentry *parent;
34480 + bwh = au_dbwh(dentry);
34481 + parent = dget_parent(dentry);
34482 + bdiropq = au_dbdiropq(parent);
34484 + if (bdiropq >= 0)
34485 + err = min(bdiropq, bwh);
34488 + AuDbg("%d\n", err);
34489 + } else if (bdiropq >= 0) {
34491 + AuDbg("%d\n", err);
34496 + err = au_wbr_nonopq(dentry, err);
34498 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34501 + AuDbg("%d\n", err);
34505 +/* ---------------------------------------------------------------------- */
34508 +static int au_wbr_create_init_rr(struct super_block *sb)
34512 + err = au_wbr_bu(sb, au_sbbot(sb));
34513 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34516 + AuDbg("b%d\n", err);
34520 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34524 + aufs_bindex_t bindex, bbot;
34525 + struct super_block *sb;
34528 + err = au_wbr_create_exp(dentry);
34532 + sb = dentry->d_sb;
34533 + next = &au_sbi(sb)->si_wbr_rr_next;
34534 + bbot = au_sbbot(sb);
34536 + for (bindex = 0; bindex <= bbot; bindex++) {
34537 + if (!au_ftest_wbr(flags, DIR)) {
34538 + err = atomic_dec_return(next) + 1;
34539 + /* modulo for 0 is meaningless */
34540 + if (unlikely(!err))
34541 + err = atomic_dec_return(next) + 1;
34543 + err = atomic_read(next);
34544 + AuDbg("%d\n", err);
34547 + AuDbg("%d\n", err);
34548 + if (!au_br_rdonly(au_sbr(sb, err)))
34554 + err = au_wbr_nonopq(dentry, err);
34557 + AuDbg("%d\n", err);
34561 +/* ---------------------------------------------------------------------- */
34563 +/* most free space */
34564 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34566 + struct super_block *sb;
34567 + struct au_branch *br;
34568 + struct au_wbr_mfs *mfs;
34569 + struct dentry *h_parent;
34570 + aufs_bindex_t bindex, bbot;
34572 + unsigned long long b, bavail;
34573 + struct path h_path;
34574 + /* reduce the stack usage */
34575 + struct kstatfs *st;
34577 + st = kmalloc(sizeof(*st), GFP_NOFS);
34578 + if (unlikely(!st)) {
34579 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34584 + sb = dentry->d_sb;
34585 + mfs = &au_sbi(sb)->si_wbr_mfs;
34586 + MtxMustLock(&mfs->mfs_lock);
34587 + mfs->mfs_bindex = -EROFS;
34588 + mfs->mfsrr_bytes = 0;
34591 + bbot = au_sbbot(sb);
34593 + bindex = au_dbtop(parent);
34594 + bbot = au_dbtaildir(parent);
34597 + for (; bindex <= bbot; bindex++) {
34599 + h_parent = au_h_dptr(parent, bindex);
34600 + if (!h_parent || d_is_negative(h_parent))
34603 + br = au_sbr(sb, bindex);
34604 + if (au_br_rdonly(br))
34607 + /* sb->s_root for NFS is unreliable */
34608 + h_path.mnt = au_br_mnt(br);
34609 + h_path.dentry = h_path.mnt->mnt_root;
34610 + err = vfs_statfs(&h_path, st);
34611 + if (unlikely(err)) {
34612 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34616 + /* when the available size is equal, select the lower one */
34617 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34618 + || sizeof(b) < sizeof(st->f_bsize));
34619 + b = st->f_bavail * st->f_bsize;
34620 + br->br_wbr->wbr_bytes = b;
34621 + if (b >= bavail) {
34623 + mfs->mfs_bindex = bindex;
34624 + mfs->mfs_jiffy = jiffies;
34628 + mfs->mfsrr_bytes = bavail;
34629 + AuDbg("b%d\n", mfs->mfs_bindex);
34630 + au_kfree_rcu(st);
34633 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34636 + struct dentry *parent;
34637 + struct super_block *sb;
34638 + struct au_wbr_mfs *mfs;
34640 + err = au_wbr_create_exp(dentry);
34644 + sb = dentry->d_sb;
34646 + if (au_ftest_wbr(flags, PARENT))
34647 + parent = dget_parent(dentry);
34648 + mfs = &au_sbi(sb)->si_wbr_mfs;
34649 + mutex_lock(&mfs->mfs_lock);
34650 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34651 + || mfs->mfs_bindex < 0
34652 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34653 + au_mfs(dentry, parent);
34654 + mutex_unlock(&mfs->mfs_lock);
34655 + err = mfs->mfs_bindex;
34659 + err = au_wbr_nonopq(dentry, err);
34662 + AuDbg("b%d\n", err);
34666 +static int au_wbr_create_init_mfs(struct super_block *sb)
34668 + struct au_wbr_mfs *mfs;
34670 + mfs = &au_sbi(sb)->si_wbr_mfs;
34671 + mutex_init(&mfs->mfs_lock);
34672 + mfs->mfs_jiffy = 0;
34673 + mfs->mfs_bindex = -EROFS;
34678 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34680 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34684 +/* ---------------------------------------------------------------------- */
34686 +/* top down regardless parent, and then mfs */
34687 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34688 + unsigned int flags __maybe_unused)
34691 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34692 + unsigned long long watermark;
34693 + struct super_block *sb;
34694 + struct au_wbr_mfs *mfs;
34695 + struct au_branch *br;
34696 + struct dentry *parent;
34698 + sb = dentry->d_sb;
34699 + mfs = &au_sbi(sb)->si_wbr_mfs;
34700 + mutex_lock(&mfs->mfs_lock);
34701 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34702 + || mfs->mfs_bindex < 0)
34703 + au_mfs(dentry, /*parent*/NULL);
34704 + watermark = mfs->mfsrr_watermark;
34705 + bmfs = mfs->mfs_bindex;
34706 + mutex_unlock(&mfs->mfs_lock);
34708 + /* another style of au_wbr_create_exp() */
34709 + bwh = au_dbwh(dentry);
34710 + parent = dget_parent(dentry);
34711 + btail = au_dbtaildir(parent);
34712 + if (bwh >= 0 && bwh < btail)
34715 + err = au_wbr_nonopq(dentry, btail);
34716 + if (unlikely(err < 0))
34720 + for (bindex = 0; bindex <= btail; bindex++) {
34721 + br = au_sbr(sb, bindex);
34722 + if (au_br_rdonly(br))
34724 + if (br->br_wbr->wbr_bytes > watermark) {
34735 + AuDbg("b%d\n", err);
34739 +/* ---------------------------------------------------------------------- */
34741 +/* most free space and then round robin */
34742 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34745 + struct au_wbr_mfs *mfs;
34747 + err = au_wbr_create_mfs(dentry, flags);
34749 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34750 + mutex_lock(&mfs->mfs_lock);
34751 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34752 + err = au_wbr_create_rr(dentry, flags);
34753 + mutex_unlock(&mfs->mfs_lock);
34756 + AuDbg("b%d\n", err);
34760 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34764 + au_wbr_create_init_mfs(sb); /* ignore */
34765 + err = au_wbr_create_init_rr(sb);
34770 +/* ---------------------------------------------------------------------- */
34772 +/* top down parent and most free space */
34773 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34776 + unsigned long long b;
34777 + aufs_bindex_t bindex, btop, bbot;
34778 + struct super_block *sb;
34779 + struct dentry *parent, *h_parent;
34780 + struct au_branch *br;
34782 + err = au_wbr_create_tdp(dentry, flags);
34783 + if (unlikely(err < 0))
34785 + parent = dget_parent(dentry);
34786 + btop = au_dbtop(parent);
34787 + bbot = au_dbtaildir(parent);
34788 + if (btop == bbot)
34789 + goto out_parent; /* success */
34791 + e2 = au_wbr_create_mfs(dentry, flags);
34793 + goto out_parent; /* success */
34795 + /* when the available size is equal, select upper one */
34796 + sb = dentry->d_sb;
34797 + br = au_sbr(sb, err);
34798 + b = br->br_wbr->wbr_bytes;
34799 + AuDbg("b%d, %llu\n", err, b);
34801 + for (bindex = btop; bindex <= bbot; bindex++) {
34802 + h_parent = au_h_dptr(parent, bindex);
34803 + if (!h_parent || d_is_negative(h_parent))
34806 + br = au_sbr(sb, bindex);
34807 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34808 + b = br->br_wbr->wbr_bytes;
34810 + AuDbg("b%d, %llu\n", err, b);
34815 + err = au_wbr_nonopq(dentry, err);
34820 + AuDbg("b%d\n", err);
34824 +/* ---------------------------------------------------------------------- */
34827 + * - top down parent
34828 + * - most free space with parent
34829 + * - most free space round-robin regardless parent
34831 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34834 + unsigned long long watermark;
34835 + struct super_block *sb;
34836 + struct au_branch *br;
34837 + struct au_wbr_mfs *mfs;
34839 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34840 + if (unlikely(err < 0))
34843 + sb = dentry->d_sb;
34844 + br = au_sbr(sb, err);
34845 + mfs = &au_sbi(sb)->si_wbr_mfs;
34846 + mutex_lock(&mfs->mfs_lock);
34847 + watermark = mfs->mfsrr_watermark;
34848 + mutex_unlock(&mfs->mfs_lock);
34849 + if (br->br_wbr->wbr_bytes < watermark)
34850 + /* regardless the parent dir */
34851 + err = au_wbr_create_mfsrr(dentry, flags);
34854 + AuDbg("b%d\n", err);
34858 +/* ---------------------------------------------------------------------- */
34860 +/* policies for copyup */
34862 +/* top down parent */
34863 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34865 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34868 +/* bottom up parent */
34869 +static int au_wbr_copyup_bup(struct dentry *dentry)
34872 + aufs_bindex_t bindex, btop;
34873 + struct dentry *parent, *h_parent;
34874 + struct super_block *sb;
34877 + sb = dentry->d_sb;
34878 + parent = dget_parent(dentry);
34879 + btop = au_dbtop(parent);
34880 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34881 + h_parent = au_h_dptr(parent, bindex);
34882 + if (!h_parent || d_is_negative(h_parent))
34885 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34892 + /* bottom up here */
34893 + if (unlikely(err < 0))
34894 + err = au_wbr_bu(sb, btop - 1);
34896 + AuDbg("b%d\n", err);
34901 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34905 + err = au_wbr_bu(dentry->d_sb, btop);
34906 + AuDbg("b%d\n", err);
34908 + err = au_wbr_nonopq(dentry, err);
34910 + AuDbg("b%d\n", err);
34914 +static int au_wbr_copyup_bu(struct dentry *dentry)
34917 + aufs_bindex_t btop;
34919 + btop = au_dbtop(dentry);
34920 + err = au_wbr_do_copyup_bu(dentry, btop);
34924 +/* ---------------------------------------------------------------------- */
34926 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34927 + [AuWbrCopyup_TDP] = {
34928 + .copyup = au_wbr_copyup_tdp
34930 + [AuWbrCopyup_BUP] = {
34931 + .copyup = au_wbr_copyup_bup
34933 + [AuWbrCopyup_BU] = {
34934 + .copyup = au_wbr_copyup_bu
34938 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34939 + [AuWbrCreate_TDP] = {
34940 + .create = au_wbr_create_tdp
34942 + [AuWbrCreate_RR] = {
34943 + .create = au_wbr_create_rr,
34944 + .init = au_wbr_create_init_rr
34946 + [AuWbrCreate_MFS] = {
34947 + .create = au_wbr_create_mfs,
34948 + .init = au_wbr_create_init_mfs,
34949 + .fin = au_wbr_create_fin_mfs
34951 + [AuWbrCreate_MFSV] = {
34952 + .create = au_wbr_create_mfs,
34953 + .init = au_wbr_create_init_mfs,
34954 + .fin = au_wbr_create_fin_mfs
34956 + [AuWbrCreate_MFSRR] = {
34957 + .create = au_wbr_create_mfsrr,
34958 + .init = au_wbr_create_init_mfsrr,
34959 + .fin = au_wbr_create_fin_mfs
34961 + [AuWbrCreate_MFSRRV] = {
34962 + .create = au_wbr_create_mfsrr,
34963 + .init = au_wbr_create_init_mfsrr,
34964 + .fin = au_wbr_create_fin_mfs
34966 + [AuWbrCreate_TDMFS] = {
34967 + .create = au_wbr_create_tdmfs,
34968 + .init = au_wbr_create_init_mfs,
34969 + .fin = au_wbr_create_fin_mfs
34971 + [AuWbrCreate_TDMFSV] = {
34972 + .create = au_wbr_create_tdmfs,
34973 + .init = au_wbr_create_init_mfs,
34974 + .fin = au_wbr_create_fin_mfs
34976 + [AuWbrCreate_PMFS] = {
34977 + .create = au_wbr_create_pmfs,
34978 + .init = au_wbr_create_init_mfs,
34979 + .fin = au_wbr_create_fin_mfs
34981 + [AuWbrCreate_PMFSV] = {
34982 + .create = au_wbr_create_pmfs,
34983 + .init = au_wbr_create_init_mfs,
34984 + .fin = au_wbr_create_fin_mfs
34986 + [AuWbrCreate_PMFSRR] = {
34987 + .create = au_wbr_create_pmfsrr,
34988 + .init = au_wbr_create_init_mfsrr,
34989 + .fin = au_wbr_create_fin_mfs
34991 + [AuWbrCreate_PMFSRRV] = {
34992 + .create = au_wbr_create_pmfsrr,
34993 + .init = au_wbr_create_init_mfsrr,
34994 + .fin = au_wbr_create_fin_mfs
34997 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34998 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34999 +++ linux/fs/aufs/whout.c 2022-03-21 14:49:05.733299677 +0100
35001 +// SPDX-License-Identifier: GPL-2.0
35003 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35005 + * This program, aufs is free software; you can redistribute it and/or modify
35006 + * it under the terms of the GNU General Public License as published by
35007 + * the Free Software Foundation; either version 2 of the License, or
35008 + * (at your option) any later version.
35010 + * This program is distributed in the hope that it will be useful,
35011 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35012 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35013 + * GNU General Public License for more details.
35015 + * You should have received a copy of the GNU General Public License
35016 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35020 + * whiteout for logical deletion and opaque directory
35025 +#define WH_MASK 0444
35028 + * If a directory contains this file, then it is opaque. We start with the
35029 + * .wh. flag so that it is blocked by lookup.
35031 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35032 + sizeof(AUFS_WH_DIROPQ) - 1);
35035 + * generate whiteout name, which is NOT terminated by NULL.
35036 + * @name: original d_name.name
35037 + * @len: original d_name.len
35038 + * @wh: whiteout qstr
35039 + * returns zero when succeeds, otherwise error.
35040 + * succeeded value as wh->name should be freed by kfree().
35042 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35046 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35047 + return -ENAMETOOLONG;
35049 + wh->len = name->len + AUFS_WH_PFX_LEN;
35050 + p = kmalloc(wh->len, GFP_NOFS);
35053 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35054 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35061 +/* ---------------------------------------------------------------------- */
35064 + * test if the @wh_name exists under @h_ppath.
35065 + * @try_sio specifies the necessary of super-io.
35067 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35068 + struct qstr *wh_name, int try_sio)
35071 + struct dentry *wh_dentry;
35074 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35076 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
35077 + err = PTR_ERR(wh_dentry);
35078 + if (IS_ERR(wh_dentry)) {
35079 + if (err == -ENAMETOOLONG)
35085 + if (d_is_negative(wh_dentry))
35086 + goto out_wh; /* success */
35089 + if (d_is_reg(wh_dentry))
35090 + goto out_wh; /* success */
35093 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35094 + wh_dentry, d_inode(wh_dentry)->i_mode);
35103 + * test if the @h_path->dentry sets opaque or not.
35105 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
35108 + struct inode *h_dir;
35110 + h_dir = d_inode(h_path->dentry);
35111 + err = au_wh_test(h_userns, h_path, &diropq_name,
35112 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
35117 + * returns a negative dentry whose name is unique and temporary.
35119 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35120 + struct qstr *prefix)
35122 + struct dentry *dentry;
35124 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35126 + /* strict atomic_t is unnecessary here */
35127 + static unsigned short cnt;
35129 + struct path h_ppath;
35130 + struct user_namespace *h_userns;
35132 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35135 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35136 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35137 + dentry = ERR_PTR(-ENAMETOOLONG);
35138 + if (unlikely(qs.len > NAME_MAX))
35140 + dentry = ERR_PTR(-ENOMEM);
35141 + name = kmalloc(qs.len + 1, GFP_NOFS);
35142 + if (unlikely(!name))
35146 + /* doubly whiteout-ed */
35147 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35148 + p = name + AUFS_WH_PFX_LEN * 2;
35149 + memcpy(p, prefix->name, prefix->len);
35150 + p += prefix->len;
35152 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35154 + h_ppath.dentry = h_parent;
35155 + h_ppath.mnt = au_br_mnt(br);
35156 + h_userns = au_br_userns(br);
35158 + for (i = 0; i < 3; i++) {
35159 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35160 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
35161 + if (IS_ERR(dentry) || d_is_negative(dentry))
35165 + /* pr_warn("could not get random name\n"); */
35166 + dentry = ERR_PTR(-EEXIST);
35167 + AuDbg("%.*s\n", AuLNPair(&qs));
35171 + if (name != defname)
35172 + au_kfree_try_rcu(name);
35174 + AuTraceErrPtr(dentry);
35179 + * rename the @h_dentry on @br to the whiteouted temporary name.
35181 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35184 + struct path h_path = {
35185 + .mnt = au_br_mnt(br)
35187 + struct inode *h_dir, *delegated;
35188 + struct dentry *h_parent;
35190 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35191 + h_dir = d_inode(h_parent);
35192 + IMustLock(h_dir);
35194 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35195 + err = PTR_ERR(h_path.dentry);
35196 + if (IS_ERR(h_path.dentry))
35199 + /* under the same dir, no need to lock_rename() */
35200 + delegated = NULL;
35201 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35204 + if (unlikely(err == -EWOULDBLOCK)) {
35205 + pr_warn("cannot retry for NFSv4 delegation"
35206 + " for an internal rename\n");
35209 + dput(h_path.dentry);
35216 +/* ---------------------------------------------------------------------- */
35218 + * functions for removing a whiteout
35221 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35224 + struct inode *delegated;
35227 + * forces superio when the dir has a sticky bit.
35228 + * this may be a violation of unix fs semantics.
35230 + force = (h_dir->i_mode & S_ISVTX)
35231 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35232 + delegated = NULL;
35233 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35234 + if (unlikely(err == -EWOULDBLOCK)) {
35235 + pr_warn("cannot retry for NFSv4 delegation"
35236 + " for an internal unlink\n");
35242 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35243 + struct dentry *dentry)
35247 + err = do_unlink_wh(h_dir, h_path);
35248 + if (!err && dentry)
35249 + au_set_dbwh(dentry, -1);
35254 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35257 + struct path h_path;
35260 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35261 + if (IS_ERR(h_path.dentry))
35262 + err = PTR_ERR(h_path.dentry);
35264 + if (d_is_reg(h_path.dentry)) {
35265 + h_path.mnt = h_ppath->mnt;
35266 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35268 + dput(h_path.dentry);
35274 +/* ---------------------------------------------------------------------- */
35276 + * initialize/clean whiteout for a branch
35279 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35283 + struct inode *delegated;
35285 + if (d_is_negative(whpath->dentry))
35289 + err = vfsub_rmdir(h_dir, whpath);
35291 + delegated = NULL;
35292 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35293 + if (unlikely(err == -EWOULDBLOCK)) {
35294 + pr_warn("cannot retry for NFSv4 delegation"
35295 + " for an internal unlink\n");
35299 + if (unlikely(err))
35300 + pr_warn("failed removing %pd (%d), ignored.\n",
35301 + whpath->dentry, err);
35304 +static int test_linkable(struct dentry *h_root)
35306 + struct inode *h_dir = d_inode(h_root);
35308 + if (h_dir->i_op->link)
35311 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35312 + h_root, au_sbtype(h_root->d_sb));
35313 + return -ENOSYS; /* the branch doesn't have its ->link() */
35316 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35317 +static int au_whdir(struct inode *h_dir, struct path *path)
35322 + if (d_is_negative(path->dentry)) {
35325 + if (au_test_nfs(path->dentry->d_sb))
35327 + err = vfsub_mkdir(h_dir, path, mode);
35328 + } else if (d_is_dir(path->dentry))
35331 + pr_err("unknown %pd exists\n", path->dentry);
35336 +struct au_wh_base {
35337 + const struct qstr *name;
35338 + struct dentry *dentry;
35341 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35342 + struct path *h_path)
35344 + h_path->dentry = base[AuBrWh_BASE].dentry;
35345 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35346 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35347 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35348 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35349 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35353 + * returns tri-state,
35354 + * minus: error, caller should print the message
35356 + * plus: error, caller should NOT print the message
35358 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35359 + int do_plink, struct au_wh_base base[],
35360 + struct path *h_path)
35363 + struct inode *h_dir;
35365 + h_dir = d_inode(h_root);
35366 + h_path->dentry = base[AuBrWh_BASE].dentry;
35367 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35368 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35370 + err = test_linkable(h_root);
35371 + if (unlikely(err)) {
35376 + err = au_whdir(h_dir, h_path);
35377 + if (unlikely(err))
35379 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35381 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35382 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35383 + err = au_whdir(h_dir, h_path);
35384 + if (unlikely(err))
35386 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35393 + * for the moment, aufs supports the branch filesystem which does not support
35394 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35395 + * copyup failed. finally, such filesystem will not be used as the writable
35398 + * returns tri-state, see above.
35400 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35401 + int do_plink, struct au_wh_base base[],
35402 + struct path *h_path)
35405 + struct inode *h_dir;
35407 + WbrWhMustWriteLock(wbr);
35409 + err = test_linkable(h_root);
35410 + if (unlikely(err)) {
35416 + * todo: should this create be done in /sbin/mount.aufs helper?
35419 + h_dir = d_inode(h_root);
35420 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35421 + h_path->dentry = base[AuBrWh_BASE].dentry;
35422 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35423 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35426 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35427 + if (unlikely(err))
35430 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35432 + err = au_whdir(h_dir, h_path);
35433 + if (unlikely(err))
35435 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35437 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35438 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35440 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35441 + err = au_whdir(h_dir, h_path);
35442 + if (unlikely(err))
35444 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35451 + * initialize the whiteout base file/dir for @br.
35453 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35456 + const unsigned char do_plink
35457 + = !!au_opt_test(au_mntflags(sb), PLINK);
35458 + struct inode *h_dir;
35459 + struct path path = br->br_path;
35460 + struct dentry *h_root = path.dentry;
35461 + struct au_wbr *wbr = br->br_wbr;
35462 + static const struct qstr base_name[] = {
35463 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35464 + sizeof(AUFS_BASE_NAME) - 1),
35465 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35466 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35467 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35468 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35470 + struct au_wh_base base[] = {
35471 + [AuBrWh_BASE] = {
35472 + .name = base_name + AuBrWh_BASE,
35475 + [AuBrWh_PLINK] = {
35476 + .name = base_name + AuBrWh_PLINK,
35479 + [AuBrWh_ORPH] = {
35480 + .name = base_name + AuBrWh_ORPH,
35486 + WbrWhMustWriteLock(wbr);
35488 + for (i = 0; i < AuBrWh_Last; i++) {
35489 + /* doubly whiteouted */
35490 + struct dentry *d;
35492 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35493 + err = PTR_ERR(d);
35497 + base[i].dentry = d;
35499 + && wbr->wbr_wh[i]
35500 + && wbr->wbr_wh[i] != base[i].dentry);
35504 + for (i = 0; i < AuBrWh_Last; i++) {
35505 + dput(wbr->wbr_wh[i]);
35506 + wbr->wbr_wh[i] = NULL;
35510 + if (!au_br_writable(br->br_perm)) {
35511 + h_dir = d_inode(h_root);
35512 + au_wh_init_ro(h_dir, base, &path);
35513 + } else if (!au_br_wh_linkable(br->br_perm)) {
35514 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35520 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35526 + goto out; /* success */
35529 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35530 + err, h_root, au_sbtype(h_root->d_sb));
35532 + for (i = 0; i < AuBrWh_Last; i++)
35533 + dput(base[i].dentry);
35537 +/* ---------------------------------------------------------------------- */
35539 + * whiteouts are all hard-linked usually.
35540 + * when its link count reaches a ceiling, we create a new whiteout base
35541 + * asynchronously.
35544 +struct reinit_br_wh {
35545 + struct super_block *sb;
35546 + struct au_branch *br;
35549 +static void reinit_br_wh(void *arg)
35552 + aufs_bindex_t bindex;
35553 + struct path h_path;
35554 + struct reinit_br_wh *a = arg;
35555 + struct au_wbr *wbr;
35556 + struct inode *dir, *delegated;
35557 + struct dentry *h_root;
35558 + struct au_hinode *hdir;
35561 + wbr = a->br->br_wbr;
35562 + /* big aufs lock */
35563 + si_noflush_write_lock(a->sb);
35564 + if (!au_br_writable(a->br->br_perm))
35566 + bindex = au_br_index(a->sb, a->br->br_id);
35567 + if (unlikely(bindex < 0))
35570 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35571 + dir = d_inode(a->sb->s_root);
35572 + hdir = au_hi(dir, bindex);
35573 + h_root = au_h_dptr(a->sb->s_root, bindex);
35574 + AuDebugOn(h_root != au_br_dentry(a->br));
35576 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35577 + wbr_wh_write_lock(wbr);
35578 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35581 + h_path.dentry = wbr->wbr_whbase;
35582 + h_path.mnt = au_br_mnt(a->br);
35583 + delegated = NULL;
35584 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35586 + if (unlikely(err == -EWOULDBLOCK)) {
35587 + pr_warn("cannot retry for NFSv4 delegation"
35588 + " for an internal unlink\n");
35592 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35595 + dput(wbr->wbr_whbase);
35596 + wbr->wbr_whbase = NULL;
35598 + err = au_wh_init(a->br, a->sb);
35599 + wbr_wh_write_unlock(wbr);
35600 + au_hn_inode_unlock(hdir);
35601 + di_read_unlock(a->sb->s_root, AuLock_IR);
35603 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35607 + atomic_dec(&wbr->wbr_wh_running);
35608 + au_lcnt_dec(&a->br->br_count);
35609 + si_write_unlock(a->sb);
35610 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35612 + if (unlikely(err))
35613 + AuIOErr("err %d\n", err);
35616 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35618 + int do_dec, wkq_err;
35619 + struct reinit_br_wh *arg;
35622 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35625 + /* ignore ENOMEM */
35626 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35629 + * dec(wh_running), kfree(arg) and dec(br_count)
35630 + * in reinit function
35634 + au_lcnt_inc(&br->br_count);
35635 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35636 + if (unlikely(wkq_err)) {
35637 + atomic_dec(&br->br_wbr->wbr_wh_running);
35638 + au_lcnt_dec(&br->br_count);
35639 + au_kfree_rcu(arg);
35646 + atomic_dec(&br->br_wbr->wbr_wh_running);
35649 +/* ---------------------------------------------------------------------- */
35652 + * create the whiteout @wh.
35654 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35655 + struct dentry *wh)
35658 + struct path h_path = {
35661 + struct au_branch *br;
35662 + struct au_wbr *wbr;
35663 + struct dentry *h_parent;
35664 + struct inode *h_dir, *delegated;
35666 + h_parent = wh->d_parent; /* dir inode is locked */
35667 + h_dir = d_inode(h_parent);
35668 + IMustLock(h_dir);
35670 + br = au_sbr(sb, bindex);
35671 + h_path.mnt = au_br_mnt(br);
35672 + wbr = br->br_wbr;
35673 + wbr_wh_read_lock(wbr);
35674 + if (wbr->wbr_whbase) {
35675 + delegated = NULL;
35676 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35677 + if (unlikely(err == -EWOULDBLOCK)) {
35678 + pr_warn("cannot retry for NFSv4 delegation"
35679 + " for an internal link\n");
35682 + if (!err || err != -EMLINK)
35685 + /* link count full. re-initialize br_whbase. */
35686 + kick_reinit_br_wh(sb, br);
35689 + /* return this error in this context */
35690 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35692 + au_fhsm_wrote(sb, bindex, /*force*/0);
35695 + wbr_wh_read_unlock(wbr);
35699 +/* ---------------------------------------------------------------------- */
35702 + * create or remove the diropq.
35704 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35705 + unsigned int flags)
35707 + struct dentry *opq_dentry;
35708 + struct super_block *sb;
35709 + struct au_branch *br;
35710 + struct path h_path;
35713 + sb = dentry->d_sb;
35714 + br = au_sbr(sb, bindex);
35715 + h_path.dentry = au_h_dptr(dentry, bindex);
35716 + h_path.mnt = au_br_mnt(br);
35717 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35718 + if (IS_ERR(opq_dentry))
35721 + if (au_ftest_diropq(flags, CREATE)) {
35722 + err = link_or_create_wh(sb, bindex, opq_dentry);
35724 + au_set_dbdiropq(dentry, bindex);
35725 + goto out; /* success */
35728 + h_path.dentry = opq_dentry;
35729 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35731 + au_set_dbdiropq(dentry, -1);
35733 + dput(opq_dentry);
35734 + opq_dentry = ERR_PTR(err);
35737 + return opq_dentry;
35740 +struct do_diropq_args {
35741 + struct dentry **errp;
35742 + struct dentry *dentry;
35743 + aufs_bindex_t bindex;
35744 + unsigned int flags;
35747 +static void call_do_diropq(void *args)
35749 + struct do_diropq_args *a = args;
35750 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35753 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35754 + unsigned int flags)
35756 + struct dentry *diropq, *h_dentry;
35757 + struct user_namespace *h_userns;
35759 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35760 + h_dentry = au_h_dptr(dentry, bindex);
35761 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35762 + MAY_EXEC | MAY_WRITE))
35763 + diropq = do_diropq(dentry, bindex, flags);
35766 + struct do_diropq_args args = {
35768 + .dentry = dentry,
35769 + .bindex = bindex,
35773 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35774 + if (unlikely(wkq_err))
35775 + diropq = ERR_PTR(wkq_err);
35781 +/* ---------------------------------------------------------------------- */
35784 + * lookup whiteout dentry.
35785 + * @h_parent: lower parent dentry which must exist and be locked
35786 + * @base_name: name of dentry which will be whiteouted
35787 + * returns dentry for whiteout.
35789 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35790 + struct au_branch *br)
35793 + struct qstr wh_name;
35794 + struct dentry *wh_dentry;
35795 + struct path h_path;
35797 + err = au_wh_name_alloc(&wh_name, base_name);
35798 + wh_dentry = ERR_PTR(err);
35800 + h_path.dentry = h_parent;
35801 + h_path.mnt = au_br_mnt(br);
35802 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35803 + au_kfree_try_rcu(wh_name.name);
35805 + return wh_dentry;
35809 + * link/create a whiteout for @dentry on @bindex.
35811 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35812 + struct dentry *h_parent)
35814 + struct dentry *wh_dentry;
35815 + struct super_block *sb;
35818 + sb = dentry->d_sb;
35819 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35820 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35821 + err = link_or_create_wh(sb, bindex, wh_dentry);
35823 + au_set_dbwh(dentry, bindex);
35824 + au_fhsm_wrote(sb, bindex, /*force*/0);
35827 + wh_dentry = ERR_PTR(err);
35831 + return wh_dentry;
35834 +/* ---------------------------------------------------------------------- */
35836 +/* Delete all whiteouts in this directory on branch bindex. */
35837 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35838 + aufs_bindex_t bindex)
35841 + unsigned long ul, n;
35842 + struct qstr wh_name;
35844 + struct hlist_head *head;
35845 + struct au_vdir_wh *pos;
35846 + struct au_vdir_destr *str;
35849 + p = (void *)__get_free_page(GFP_NOFS);
35850 + wh_name.name = p;
35851 + if (unlikely(!wh_name.name))
35855 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35856 + p += AUFS_WH_PFX_LEN;
35857 + n = whlist->nh_num;
35858 + head = whlist->nh_head;
35859 + for (ul = 0; !err && ul < n; ul++, head++) {
35860 + hlist_for_each_entry(pos, head, wh_hash) {
35861 + if (pos->wh_bindex != bindex)
35864 + str = &pos->wh_str;
35865 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35866 + memcpy(p, str->name, str->len);
35867 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35868 + err = unlink_wh_name(h_path, &wh_name);
35873 + AuIOErr("whiteout name too long %.*s\n",
35874 + str->len, str->name);
35879 + free_page((unsigned long)wh_name.name);
35885 +struct del_wh_children_args {
35887 + struct path *h_path;
35888 + struct au_nhash *whlist;
35889 + aufs_bindex_t bindex;
35892 +static void call_del_wh_children(void *args)
35894 + struct del_wh_children_args *a = args;
35895 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35898 +/* ---------------------------------------------------------------------- */
35900 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35902 + struct au_whtmp_rmdir *whtmp;
35904 + unsigned int rdhash;
35906 + SiMustAnyLock(sb);
35908 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35909 + if (unlikely(!whtmp)) {
35910 + whtmp = ERR_PTR(-ENOMEM);
35914 + /* no estimation for dir size */
35915 + rdhash = au_sbi(sb)->si_rdhash;
35917 + rdhash = AUFS_RDHASH_DEF;
35918 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35919 + if (unlikely(err)) {
35920 + au_kfree_rcu(whtmp);
35921 + whtmp = ERR_PTR(err);
35928 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35931 + au_lcnt_dec(&whtmp->br->br_count);
35932 + dput(whtmp->wh_dentry);
35933 + iput(whtmp->dir);
35934 + au_nhash_wh_free(&whtmp->whlist);
35935 + au_kfree_rcu(whtmp);
35939 + * rmdir the whiteouted temporary named dir @h_dentry.
35940 + * @whlist: whiteouted children.
35942 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35943 + struct dentry *wh_dentry, struct au_nhash *whlist)
35946 + unsigned int h_nlink;
35947 + struct path wh_path;
35948 + struct inode *wh_inode, *h_dir;
35949 + struct au_branch *br;
35950 + struct user_namespace *h_userns;
35952 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35953 + IMustLock(h_dir);
35955 + br = au_sbr(dir->i_sb, bindex);
35956 + wh_path.dentry = wh_dentry;
35957 + wh_path.mnt = au_br_mnt(br);
35958 + h_userns = au_br_userns(br);
35959 + wh_inode = d_inode(wh_dentry);
35960 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35963 + * someone else might change some whiteouts while we were sleeping.
35964 + * it means this whlist may have an obsoleted entry.
35966 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
35967 + err = del_wh_children(&wh_path, whlist, bindex);
35970 + struct del_wh_children_args args = {
35972 + .h_path = &wh_path,
35973 + .whlist = whlist,
35977 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35978 + if (unlikely(wkq_err))
35981 + inode_unlock(wh_inode);
35984 + h_nlink = h_dir->i_nlink;
35985 + err = vfsub_rmdir(h_dir, &wh_path);
35986 + /* some fs doesn't change the parent nlink in some cases */
35987 + h_nlink -= h_dir->i_nlink;
35991 + if (au_ibtop(dir) == bindex) {
35992 + /* todo: dir->i_mutex is necessary */
35993 + au_cpup_attr_timesizes(dir);
35995 + vfsub_drop_nlink(dir);
35997 + return 0; /* success */
36000 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36004 +static void call_rmdir_whtmp(void *args)
36007 + aufs_bindex_t bindex;
36008 + struct au_whtmp_rmdir *a = args;
36009 + struct super_block *sb;
36010 + struct dentry *h_parent;
36011 + struct inode *h_dir;
36012 + struct au_hinode *hdir;
36014 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36015 + /* inode_lock(a->dir); */
36017 + sb = a->dir->i_sb;
36018 + si_read_lock(sb, !AuLock_FLUSH);
36019 + if (!au_br_writable(a->br->br_perm))
36021 + bindex = au_br_index(sb, a->br->br_id);
36022 + if (unlikely(bindex < 0))
36026 + ii_write_lock_parent(a->dir);
36027 + h_parent = dget_parent(a->wh_dentry);
36028 + h_dir = d_inode(h_parent);
36029 + hdir = au_hi(a->dir, bindex);
36030 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36031 + if (unlikely(err))
36033 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36034 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36037 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36038 + au_hn_inode_unlock(hdir);
36039 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36043 + ii_write_unlock(a->dir);
36045 + /* inode_unlock(a->dir); */
36046 + au_whtmp_rmdir_free(a);
36047 + si_read_unlock(sb);
36048 + au_nwt_done(&au_sbi(sb)->si_nowait);
36049 + if (unlikely(err))
36050 + AuIOErr("err %d\n", err);
36053 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36054 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36057 + struct super_block *sb;
36061 + /* all post-process will be done in do_rmdir_whtmp(). */
36063 + args->dir = au_igrab(dir);
36064 + args->br = au_sbr(sb, bindex);
36065 + au_lcnt_inc(&args->br->br_count);
36066 + args->wh_dentry = dget(wh_dentry);
36067 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36068 + if (unlikely(wkq_err)) {
36069 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36070 + au_whtmp_rmdir_free(args);
36073 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36074 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36075 +++ linux/fs/aufs/whout.h 2022-03-21 14:49:05.733299677 +0100
36077 +/* SPDX-License-Identifier: GPL-2.0 */
36079 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36081 + * This program, aufs is free software; you can redistribute it and/or modify
36082 + * it under the terms of the GNU General Public License as published by
36083 + * the Free Software Foundation; either version 2 of the License, or
36084 + * (at your option) any later version.
36086 + * This program is distributed in the hope that it will be useful,
36087 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36089 + * GNU General Public License for more details.
36091 + * You should have received a copy of the GNU General Public License
36092 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36096 + * whiteout for logical deletion and opaque directory
36099 +#ifndef __AUFS_WHOUT_H__
36100 +#define __AUFS_WHOUT_H__
36107 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36108 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
36109 + struct qstr *wh_name, int try_sio);
36110 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
36112 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36113 + struct qstr *prefix);
36114 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36115 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36116 + struct dentry *dentry);
36117 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36119 +/* diropq flags */
36120 +#define AuDiropq_CREATE 1
36121 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36122 +#define au_fset_diropq(flags, name) \
36123 + do { (flags) |= AuDiropq_##name; } while (0)
36124 +#define au_fclr_diropq(flags, name) \
36125 + do { (flags) &= ~AuDiropq_##name; } while (0)
36127 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36128 + unsigned int flags);
36129 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36130 + struct au_branch *br);
36131 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36132 + struct dentry *h_parent);
36134 +/* real rmdir for the whiteout-ed dir */
36135 +struct au_whtmp_rmdir {
36136 + struct inode *dir;
36137 + struct au_branch *br;
36138 + struct dentry *wh_dentry;
36139 + struct au_nhash whlist;
36142 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36143 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36144 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36145 + struct dentry *wh_dentry, struct au_nhash *whlist);
36146 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36147 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36149 +/* ---------------------------------------------------------------------- */
36151 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36152 + aufs_bindex_t bindex)
36154 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36157 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36159 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36162 +#endif /* __KERNEL__ */
36163 +#endif /* __AUFS_WHOUT_H__ */
36164 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36165 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36166 +++ linux/fs/aufs/wkq.c 2022-03-21 14:49:05.733299677 +0100
36168 +// SPDX-License-Identifier: GPL-2.0
36170 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36172 + * This program, aufs is free software; you can redistribute it and/or modify
36173 + * it under the terms of the GNU General Public License as published by
36174 + * the Free Software Foundation; either version 2 of the License, or
36175 + * (at your option) any later version.
36177 + * This program is distributed in the hope that it will be useful,
36178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36180 + * GNU General Public License for more details.
36182 + * You should have received a copy of the GNU General Public License
36183 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36187 + * workqueue for asynchronous/super-io operations
36188 + * todo: try new credential scheme
36191 +#include <linux/module.h>
36194 +/* internal workqueue named AUFS_WKQ_NAME */
36196 +static struct workqueue_struct *au_wkq;
36198 +struct au_wkinfo {
36199 + struct work_struct wk;
36200 + struct kobject *kobj;
36202 + unsigned int flags; /* see wkq.h */
36204 + au_wkq_func_t func;
36207 +#ifdef CONFIG_LOCKDEP
36209 + struct held_lock **hlock;
36212 + struct completion *comp;
36215 +/* ---------------------------------------------------------------------- */
36217 + * Aufs passes some operations to the workqueue such as the internal copyup.
36218 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36219 + * job run by workqueue depends upon the locks acquired in the other task.
36220 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36221 + * information too. And the job in the workqueue restores the info in order to
36222 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36223 + * correctly and expectedly.
36226 +#ifndef CONFIG_LOCKDEP
36227 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36228 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36229 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36230 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36231 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36233 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36235 + wkinfo->hlock = NULL;
36236 + wkinfo->dont_check = 0;
36243 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36245 + static DEFINE_SPINLOCK(spin);
36248 + struct lock_class_key *key;
36250 + { .name = "&sbinfo->si_rwsem" },
36251 + { .name = "&finfo->fi_rwsem" },
36252 + { .name = "&dinfo->di_rwsem" },
36253 + { .name = "&iinfo->ii_rwsem" }
36258 + /* lockless read from 'set.' see below */
36259 + if (set == ARRAY_SIZE(a)) {
36260 + for (i = 0; i < ARRAY_SIZE(a); i++)
36261 + if (a[i].key == key)
36266 + spin_lock(&spin);
36268 + for (i = 0; i < ARRAY_SIZE(a); i++)
36269 + if (a[i].key == key) {
36270 + spin_unlock(&spin);
36273 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36275 + if (unlikely(a[i].key == key)) { /* rare but possible */
36276 + spin_unlock(&spin);
36281 + if (strstr(a[i].name, name)) {
36283 + * the order of these three lines is important for the
36284 + * lockless read above.
36287 + spin_unlock(&spin);
36289 + /* AuDbg("%d, %s\n", set, name); */
36293 + spin_unlock(&spin);
36302 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36305 + struct task_struct *curr;
36306 + struct held_lock **hl, *held_locks, *p;
36310 + wkinfo->dont_check = lockdep_recursing(curr);
36311 + if (wkinfo->dont_check)
36313 + n = curr->lockdep_depth;
36318 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36319 + if (unlikely(!wkinfo->hlock))
36323 +#if 0 /* left for debugging */
36324 + if (0 && au_debug_test())
36325 + lockdep_print_held_locks(curr);
36327 + held_locks = curr->held_locks;
36328 + hl = wkinfo->hlock;
36330 + p = held_locks++;
36331 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36340 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36342 + au_kfree_try_rcu(wkinfo->hlock);
36345 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36347 + struct held_lock *p, **hl = wkinfo->hlock;
36350 + if (wkinfo->dont_check)
36354 + while ((p = *hl++)) { /* assignment */
36355 + subclass = lockdep_hlock_class(p)->subclass;
36356 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36358 + rwsem_acquire_read(p->instance, subclass, 0,
36359 + /*p->acquire_ip*/_RET_IP_);
36361 + rwsem_acquire(p->instance, subclass, 0,
36362 + /*p->acquire_ip*/_RET_IP_);
36366 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36368 + struct held_lock *p, **hl = wkinfo->hlock;
36370 + if (wkinfo->dont_check)
36374 + while ((p = *hl++)) /* assignment */
36375 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36379 +static void wkq_func(struct work_struct *wk)
36381 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36383 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36384 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36386 + au_wkq_lockdep_pre(wkinfo);
36387 + wkinfo->func(wkinfo->args);
36388 + au_wkq_lockdep_post(wkinfo);
36389 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36390 + complete(wkinfo->comp);
36392 + kobject_put(wkinfo->kobj);
36393 + module_put(THIS_MODULE); /* todo: ?? */
36394 + au_kfree_rcu(wkinfo);
36399 + * Since struct completion is large, try allocating it dynamically.
36401 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36403 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36405 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36407 + init_completion(*comp);
36408 + wkinfo->comp = *comp;
36414 +static void au_wkq_comp_free(struct completion *comp)
36416 + au_kfree_rcu(comp);
36419 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36421 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36422 + if (au_wkq_test()) {
36423 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36424 + " due to a dead dir by UDBA,"
36425 + " or async xino write?\n");
36426 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36429 + au_dbg_verify_kthread();
36431 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36432 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36433 + queue_work(au_wkq, &wkinfo->wk);
36435 + INIT_WORK(&wkinfo->wk, wkq_func);
36436 + schedule_work(&wkinfo->wk);
36441 + * Be careful. It is easy to make deadlock happen.
36442 + * processA: lock, wkq and wait
36443 + * processB: wkq and wait, lock in wkq
36446 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36449 + AuWkqCompDeclare(comp);
36450 + struct au_wkinfo wkinfo = {
36456 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36457 + if (unlikely(err))
36459 + err = au_wkq_lockdep_alloc(&wkinfo);
36460 + if (unlikely(err))
36463 + au_wkq_run(&wkinfo);
36464 + /* no timeout, no interrupt */
36465 + wait_for_completion(wkinfo.comp);
36467 + au_wkq_lockdep_free(&wkinfo);
36470 + au_wkq_comp_free(comp);
36472 + destroy_work_on_stack(&wkinfo.wk);
36477 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36478 + * problem in a concurrent umounting.
36480 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36481 + unsigned int flags)
36484 + struct au_wkinfo *wkinfo;
36486 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36489 + * wkq_func() must free this wkinfo.
36490 + * it highly depends upon the implementation of workqueue.
36493 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36495 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36496 + wkinfo->flags = flags & ~AuWkq_WAIT;
36497 + wkinfo->func = func;
36498 + wkinfo->args = args;
36499 + wkinfo->comp = NULL;
36500 + au_wkq_lockdep_init(wkinfo);
36501 + kobject_get(wkinfo->kobj);
36502 + __module_get(THIS_MODULE); /* todo: ?? */
36504 + au_wkq_run(wkinfo);
36507 + au_nwt_done(&au_sbi(sb)->si_nowait);
36513 +/* ---------------------------------------------------------------------- */
36515 +void au_nwt_init(struct au_nowait_tasks *nwt)
36517 + atomic_set(&nwt->nw_len, 0);
36518 + /* smp_mb(); */ /* atomic_set */
36519 + init_waitqueue_head(&nwt->nw_wq);
36522 +void au_wkq_fin(void)
36524 + destroy_workqueue(au_wkq);
36527 +int __init au_wkq_init(void)
36532 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36533 + if (IS_ERR(au_wkq))
36534 + err = PTR_ERR(au_wkq);
36535 + else if (!au_wkq)
36540 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36541 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36542 +++ linux/fs/aufs/wkq.h 2022-03-21 14:49:05.733299677 +0100
36544 +/* SPDX-License-Identifier: GPL-2.0 */
36546 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36548 + * This program, aufs is free software; you can redistribute it and/or modify
36549 + * it under the terms of the GNU General Public License as published by
36550 + * the Free Software Foundation; either version 2 of the License, or
36551 + * (at your option) any later version.
36553 + * This program is distributed in the hope that it will be useful,
36554 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36555 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36556 + * GNU General Public License for more details.
36558 + * You should have received a copy of the GNU General Public License
36559 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36563 + * workqueue for asynchronous/super-io operations
36564 + * todo: try new credentials management scheme
36567 +#ifndef __AUFS_WKQ_H__
36568 +#define __AUFS_WKQ_H__
36572 +#include <linux/wait.h>
36574 +struct super_block;
36576 +/* ---------------------------------------------------------------------- */
36579 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36581 +struct au_nowait_tasks {
36583 + wait_queue_head_t nw_wq;
36586 +/* ---------------------------------------------------------------------- */
36588 +typedef void (*au_wkq_func_t)(void *args);
36591 +#define AuWkq_WAIT 1
36592 +#define AuWkq_NEST (1 << 1)
36593 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36594 +#define au_fset_wkq(flags, name) \
36595 + do { (flags) |= AuWkq_##name; } while (0)
36596 +#define au_fclr_wkq(flags, name) \
36597 + do { (flags) &= ~AuWkq_##name; } while (0)
36600 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36601 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36602 + unsigned int flags);
36603 +void au_nwt_init(struct au_nowait_tasks *nwt);
36604 +int __init au_wkq_init(void);
36605 +void au_wkq_fin(void);
36607 +/* ---------------------------------------------------------------------- */
36609 +static inline int au_wkq_test(void)
36611 + return current->flags & PF_WQ_WORKER;
36614 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36616 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36619 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36621 + if (atomic_dec_and_test(&nwt->nw_len))
36622 + wake_up_all(&nwt->nw_wq);
36625 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36627 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36631 +#endif /* __KERNEL__ */
36632 +#endif /* __AUFS_WKQ_H__ */
36633 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36634 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36635 +++ linux/fs/aufs/xattr.c 2022-03-21 14:49:05.733299677 +0100
36637 +// SPDX-License-Identifier: GPL-2.0
36639 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36641 + * This program, aufs is free software; you can redistribute it and/or modify
36642 + * it under the terms of the GNU General Public License as published by
36643 + * the Free Software Foundation; either version 2 of the License, or
36644 + * (at your option) any later version.
36646 + * This program is distributed in the hope that it will be useful,
36647 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36648 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36649 + * GNU General Public License for more details.
36651 + * You should have received a copy of the GNU General Public License
36652 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36656 + * handling xattr functions
36659 +#include <linux/fs.h>
36660 +#include <linux/posix_acl_xattr.h>
36661 +#include <linux/xattr.h>
36664 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36666 + if (!ignore_flags)
36674 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36679 +#define cmp(brattr, prefix) do { \
36680 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36681 + XATTR_##prefix##_PREFIX_LEN)) { \
36682 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36688 + cmp(SEC, SECURITY);
36689 + cmp(SYS, SYSTEM);
36690 + cmp(TR, TRUSTED);
36694 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36701 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36703 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36704 + char *name, char **buf, unsigned int ignore_flags,
36705 + unsigned int verbose)
36709 + struct inode *h_idst;
36710 + struct dentry *h_dst_dentry, *h_src_dentry;
36711 + struct user_namespace *h_dst_userns, *h_src_userns;
36713 + h_src_userns = mnt_user_ns(h_src->mnt);
36714 + h_src_dentry = h_src->dentry;
36715 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36718 + if (unlikely(err <= 0)) {
36719 + if (err == -ENODATA
36720 + || (err == -EOPNOTSUPP
36721 + && ((ignore_flags & au_xattr_out_of_list)
36722 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36723 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36725 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36728 + if (err && (verbose || au_debug_test()))
36729 + pr_err("%s, err %d\n", name, err);
36733 + /* unlock it temporary */
36734 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36735 + h_dst_dentry = h_dst->dentry;
36736 + h_idst = d_inode(h_dst_dentry);
36737 + inode_unlock(h_idst);
36738 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36740 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36741 + if (unlikely(err)) {
36742 + if (verbose || au_debug_test())
36743 + pr_err("%s, err %d\n", name, err);
36744 + err = au_xattr_ignore(err, name, ignore_flags);
36751 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36752 + unsigned int verbose)
36754 + int err, unlocked, acl_access, acl_default;
36756 + struct dentry *h_dst_dentry, *h_src_dentry;
36757 + struct inode *h_isrc, *h_idst;
36758 + char *value, *p, *o, *e;
36760 + /* try stopping to update the source inode while we are referencing */
36761 + /* there should not be the parent-child relationship between them */
36762 + h_dst_dentry = h_dst->dentry;
36763 + h_idst = d_inode(h_dst_dentry);
36764 + h_src_dentry = h_src->dentry;
36765 + h_isrc = d_inode(h_src_dentry);
36766 + inode_unlock(h_idst);
36767 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36768 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36771 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36772 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36774 + if (unlikely(err < 0)) {
36776 + if (err == -ENODATA
36777 + || err == -EOPNOTSUPP)
36778 + err = 0; /* ignore */
36787 + p = kmalloc(ssz, GFP_NOFS);
36789 + if (unlikely(!p))
36791 + err = vfs_listxattr(h_src_dentry, p, ssz);
36793 + inode_unlock_shared(h_isrc);
36795 + AuDbg("err %d, ssz %zd\n", err, ssz);
36796 + if (unlikely(err < 0))
36804 + while (!err && p < e) {
36805 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36806 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36807 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36808 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36810 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36812 + p += strlen(p) + 1;
36815 + ignore_flags |= au_xattr_out_of_list;
36816 + if (!err && !acl_access) {
36817 + err = au_do_cpup_xattr(h_dst, h_src,
36818 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36819 + ignore_flags, verbose);
36822 + if (!err && !acl_default) {
36823 + err = au_do_cpup_xattr(h_dst, h_src,
36824 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36825 + ignore_flags, verbose);
36829 + au_kfree_try_rcu(value);
36832 + au_kfree_try_rcu(o);
36835 + inode_unlock_shared(h_isrc);
36840 +/* ---------------------------------------------------------------------- */
36842 +static int au_smack_reentering(struct super_block *sb)
36844 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36846 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36847 + * i_op->getxattr(). ouch.
36849 + return si_pid_test(sb);
36860 +struct au_lgxattr {
36868 + const char *name;
36875 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36876 + struct au_lgxattr *arg)
36880 + struct path h_path;
36881 + struct super_block *sb;
36883 + sb = dentry->d_sb;
36884 + reenter = au_smack_reentering(sb);
36886 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36887 + if (unlikely(err))
36890 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36891 + if (unlikely(err))
36893 + if (unlikely(!h_path.dentry))
36894 + /* illegally overlapped or something */
36895 + goto out_di; /* pretending success */
36897 + /* always topmost entry only */
36898 + switch (arg->type) {
36899 + case AU_XATTR_LIST:
36900 + err = vfs_listxattr(h_path.dentry,
36901 + arg->u.list.list, arg->u.list.size);
36903 + case AU_XATTR_GET:
36904 + AuDebugOn(d_is_negative(h_path.dentry));
36905 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36906 + arg->u.get.name, arg->u.get.value,
36907 + arg->u.get.size);
36913 + di_read_unlock(dentry, AuLock_IR);
36916 + si_read_unlock(sb);
36922 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36924 + struct au_lgxattr arg = {
36925 + .type = AU_XATTR_LIST,
36932 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36935 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36936 + const char *name, void *value, size_t size)
36938 + struct au_lgxattr arg = {
36939 + .type = AU_XATTR_GET,
36947 + return au_lgxattr(dentry, inode, &arg);
36950 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36951 + const char *name, const void *value, size_t size,
36954 + struct au_sxattr arg = {
36955 + .type = AU_XATTR_SET,
36964 + return au_sxattr(dentry, inode, &arg);
36967 +/* ---------------------------------------------------------------------- */
36969 +static int au_xattr_get(const struct xattr_handler *handler,
36970 + struct dentry *dentry, struct inode *inode,
36971 + const char *name, void *buffer, size_t size)
36973 + return au_getxattr(dentry, inode, name, buffer, size);
36976 +static int au_xattr_set(const struct xattr_handler *handler,
36977 + struct user_namespace *userns,
36978 + struct dentry *dentry, struct inode *inode,
36979 + const char *name, const void *value, size_t size,
36982 + return au_setxattr(dentry, inode, name, value, size, flags);
36985 +static const struct xattr_handler au_xattr_handler = {
36988 + .get = au_xattr_get,
36989 + .set = au_xattr_set
36992 +static const struct xattr_handler *au_xattr_handlers[] = {
36993 +#ifdef CONFIG_FS_POSIX_ACL
36994 + &posix_acl_access_xattr_handler,
36995 + &posix_acl_default_xattr_handler,
36997 + &au_xattr_handler, /* must be last */
37001 +void au_xattr_init(struct super_block *sb)
37003 + sb->s_xattr = au_xattr_handlers;
37005 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37006 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37007 +++ linux/fs/aufs/xino.c 2022-03-21 14:49:05.733299677 +0100
37009 +// SPDX-License-Identifier: GPL-2.0
37011 + * Copyright (C) 2005-2021 Junjiro R. Okajima
37013 + * This program, aufs is free software; you can redistribute it and/or modify
37014 + * it under the terms of the GNU General Public License as published by
37015 + * the Free Software Foundation; either version 2 of the License, or
37016 + * (at your option) any later version.
37018 + * This program is distributed in the hope that it will be useful,
37019 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37020 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37021 + * GNU General Public License for more details.
37023 + * You should have received a copy of the GNU General Public License
37024 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37028 + * external inode number translation table and bitmap
37030 + * things to consider
37032 + * + au_xino object
37033 + * + XINO files (xino, xib, xigen)
37034 + * + dynamic debugfs entries (xiN)
37035 + * + static debugfs entries (xib, xigen)
37036 + * + static sysfs entry (xi_path)
37037 + * - several entry points to handle them.
37038 + * + mount(2) without xino option (default)
37039 + * + mount(2) with xino option
37040 + * + mount(2) with noxino option
37042 + * + remount with add/del branches
37043 + * + remount with xino/noxino options
37046 +#include <linux/seq_file.h>
37047 +#include <linux/statfs.h>
37050 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37051 + aufs_bindex_t bbot,
37052 + struct super_block *h_sb)
37054 + /* todo: try binary-search if the branches are many */
37055 + for (; btop <= bbot; btop++)
37056 + if (h_sb == au_sbr_sb(sb, btop))
37062 + * find another branch who is on the same filesystem of the specified
37063 + * branch{@btgt}. search until @bbot.
37065 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37066 + aufs_bindex_t bbot)
37068 + aufs_bindex_t bindex;
37069 + struct super_block *tgt_sb;
37071 + tgt_sb = au_sbr_sb(sb, btgt);
37072 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37074 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37079 +/* ---------------------------------------------------------------------- */
37082 + * stop unnecessary notify events at creating xino files
37085 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37087 + aufs_bindex_t bfound, bindex, bbot;
37088 + struct dentry *parent;
37089 + struct au_branch *br;
37092 + parent = dentry->d_parent; /* safe d_parent access */
37093 + bbot = au_sbbot(sb);
37094 + for (bindex = 0; bindex <= bbot; bindex++) {
37095 + br = au_sbr(sb, bindex);
37096 + if (au_br_dentry(br) == parent) {
37102 + AuDbg("bfound b%d\n", bfound);
37106 +struct au_xino_lock_dir {
37107 + struct au_hinode *hdir;
37108 + struct dentry *parent;
37109 + struct inode *dir;
37112 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37113 + unsigned int lsc)
37115 + struct dentry *parent;
37116 + struct inode *dir;
37118 + parent = dget_parent(dentry);
37119 + dir = d_inode(parent);
37120 + inode_lock_nested(dir, lsc);
37121 +#if 0 /* it should not happen */
37122 + spin_lock(&dentry->d_lock);
37123 + if (unlikely(dentry->d_parent != parent)) {
37124 + spin_unlock(&dentry->d_lock);
37125 + inode_unlock(dir);
37130 + spin_unlock(&dentry->d_lock);
37137 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37138 + struct au_xino_lock_dir *ldir)
37140 + aufs_bindex_t bindex;
37142 + ldir->hdir = NULL;
37143 + bindex = au_xi_root(sb, xipath->dentry);
37144 + if (bindex >= 0) {
37145 + /* rw branch root */
37146 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37147 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37150 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37152 + ldir->dir = d_inode(ldir->parent);
37156 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37159 + au_hn_inode_unlock(ldir->hdir);
37161 + inode_unlock(ldir->dir);
37162 + dput(ldir->parent);
37166 +/* ---------------------------------------------------------------------- */
37169 + * create and set a new xino file
37171 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37174 + struct file *file;
37175 + struct dentry *h_parent, *d;
37176 + struct inode *h_dir, *inode;
37178 + static DEFINE_MUTEX(mtx);
37181 + * at mount-time, and the xino file is the default path,
37182 + * hnotify is disabled so we have no notify events to ignore.
37183 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37186 + mutex_lock(&mtx);
37187 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37188 + /* | __FMODE_NONOTIFY */,
37190 + if (IS_ERR(file)) {
37192 + mutex_unlock(&mtx);
37194 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37198 + /* keep file count */
37200 + d = file->f_path.dentry;
37201 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37203 + mutex_unlock(&mtx);
37204 + /* mnt_want_write() is unnecessary here */
37205 + h_dir = d_inode(h_parent);
37206 + inode = file_inode(file);
37207 + /* no delegation since it is just created */
37208 + if (inode->i_nlink)
37209 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37211 + inode_unlock(h_dir);
37213 + if (unlikely(err)) {
37215 + pr_err("unlink %s(%d)\n", fpath, err);
37220 + if (unlikely(sb && sb == d->d_sb)) {
37222 + pr_err("%s must be outside\n", fpath);
37225 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37227 + pr_err("xino doesn't support %s(%s)\n",
37228 + fpath, au_sbtype(d->d_sb));
37231 + return file; /* success */
37235 + file = ERR_PTR(err);
37240 + * create a new xinofile at the same place/path as @base.
37242 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37243 + struct file *copy_src)
37245 + struct file *file;
37246 + struct dentry *dentry;
37247 + struct inode *dir, *delegated;
37248 + struct qstr *name;
37249 + struct path ppath, path;
37250 + int err, do_unlock;
37251 + struct au_xino_lock_dir ldir;
37254 + au_xino_lock_dir(sb, base, &ldir);
37255 + dentry = base->dentry;
37256 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37257 + ppath.mnt = base->mnt;
37258 + dir = d_inode(ppath.dentry);
37261 + name = &dentry->d_name;
37262 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37263 + if (IS_ERR(path.dentry)) {
37264 + file = (void *)path.dentry;
37265 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37269 + /* no need to mnt_want_write() since we call dentry_open() later */
37270 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37271 + if (unlikely(err)) {
37272 + file = ERR_PTR(err);
37273 + pr_err("%pd create err %d\n", dentry, err);
37277 + path.mnt = base->mnt;
37278 + file = vfsub_dentry_open(&path,
37279 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37280 + /* | __FMODE_NONOTIFY */);
37281 + if (IS_ERR(file)) {
37282 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37286 + delegated = NULL;
37287 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37288 + au_xino_unlock_dir(&ldir);
37290 + if (unlikely(err == -EWOULDBLOCK)) {
37291 + pr_warn("cannot retry for NFSv4 delegation"
37292 + " for an internal unlink\n");
37295 + if (unlikely(err)) {
37296 + pr_err("%pd unlink err %d\n", dentry, err);
37301 + /* no one can touch copy_src xino */
37302 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37303 + if (unlikely(err)) {
37304 + pr_err("%pd copy err %d\n", dentry, err);
37308 + goto out_dput; /* success */
37312 + file = ERR_PTR(err);
37314 + dput(path.dentry);
37317 + au_xino_unlock_dir(&ldir);
37321 +struct file *au_xino_file1(struct au_xino *xi)
37323 + struct file *file;
37324 + unsigned int u, nfile;
37327 + nfile = xi->xi_nfile;
37328 + for (u = 0; u < nfile; u++) {
37329 + file = xi->xi_file[u];
37337 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37348 + if (idx < xi->xi_nfile) {
37349 + f = xi->xi_file[idx];
37353 + p = au_kzrealloc(xi->xi_file,
37354 + sizeof(*xi->xi_file) * xi->xi_nfile,
37355 + sizeof(*xi->xi_file) * (idx + 1),
37356 + GFP_NOFS, /*may_shrink*/0);
37358 + MtxMustLock(&xi->xi_mtx);
37360 + xi->xi_nfile = idx + 1;
37368 + xi->xi_file[idx] = file;
37375 + * if @xinew->xi is not set, then create new xigen file.
37377 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37379 + struct file *file;
37382 + SiMustAnyLock(sb);
37384 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37385 + if (IS_ERR(file)) {
37386 + err = PTR_ERR(file);
37387 + pr_err("%s[%d], err %d\n",
37388 + xinew->xi ? "xino" : "xigen",
37389 + xinew->idx, err);
37394 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37397 + /* todo: make xigen file an array */
37398 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37401 + if (unlikely(err))
37402 + file = ERR_PTR(err);
37408 +/* ---------------------------------------------------------------------- */
37411 + * truncate xino files
37413 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37414 + int idx, struct kstatfs *st)
37418 + struct file *file, *new_xino;
37419 + struct au_xi_new xinew = {
37424 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37425 + file = au_xino_file(xinew.xi, idx);
37429 + xinew.base = &file->f_path;
37430 + err = vfs_statfs(xinew.base, st);
37431 + if (unlikely(err)) {
37432 + AuErr1("statfs err %d, ignored\n", err);
37437 + blocks = file_inode(file)->i_blocks;
37438 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37439 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37441 + xinew.copy_src = file;
37442 + new_xino = au_xi_new(sb, &xinew);
37443 + if (IS_ERR(new_xino)) {
37444 + err = PTR_ERR(new_xino);
37445 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37449 + err = vfs_statfs(&new_xino->f_path, st);
37451 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37452 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37453 + st->f_bfree, st->f_blocks);
37455 + AuErr1("statfs err %d, ignored\n", err);
37463 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37466 + unsigned long jiffy;
37467 + aufs_bindex_t bbot;
37468 + struct kstatfs *st;
37469 + struct au_branch *br;
37470 + struct au_xino *xi;
37473 + st = kmalloc(sizeof(*st), GFP_NOFS);
37474 + if (unlikely(!st))
37478 + bbot = au_sbbot(sb);
37479 + if (unlikely(bindex < 0 || bbot < bindex))
37484 + br = au_sbr(sb, bindex);
37485 + xi = br->br_xino;
37486 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37487 + err = au_xino_do_trunc(sb, bindex, i, st);
37489 + au_sbi(sb)->si_xino_jiffy = jiffy;
37492 + au_kfree_rcu(st);
37497 +struct xino_do_trunc_args {
37498 + struct super_block *sb;
37499 + struct au_branch *br;
37503 +static void xino_do_trunc(void *_args)
37505 + struct xino_do_trunc_args *args = _args;
37506 + struct super_block *sb;
37507 + struct au_branch *br;
37508 + struct inode *dir;
37510 + aufs_bindex_t bindex;
37514 + dir = d_inode(sb->s_root);
37518 + si_noflush_write_lock(sb);
37519 + ii_read_lock_parent(dir);
37520 + bindex = au_br_index(sb, br->br_id);
37521 + err = au_xino_trunc(sb, bindex, idx);
37522 + ii_read_unlock(dir);
37523 + if (unlikely(err))
37524 + pr_warn("err b%d, (%d)\n", bindex, err);
37525 + atomic_dec(&br->br_xino->xi_truncating);
37526 + au_lcnt_dec(&br->br_count);
37527 + si_write_unlock(sb);
37528 + au_nwt_done(&au_sbi(sb)->si_nowait);
37529 + au_kfree_rcu(args);
37533 + * returns the index in the xi_file array whose corresponding file is necessary
37534 + * to truncate, or -1 which means no need to truncate.
37536 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37540 + struct kstatfs st;
37541 + struct au_sbinfo *sbinfo;
37542 + struct au_xino *xi;
37543 + struct file *file;
37545 + /* todo: si_xino_expire and the ratio should be customizable */
37546 + sbinfo = au_sbi(sb);
37547 + if (time_before(jiffies,
37548 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37551 + /* truncation border */
37552 + xi = br->br_xino;
37553 + for (u = 0; u < xi->xi_nfile; u++) {
37554 + file = au_xino_file(xi, u);
37558 + err = vfs_statfs(&file->f_path, &st);
37559 + if (unlikely(err)) {
37560 + AuErr1("statfs err %d, ignored\n", err);
37563 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37564 + >= AUFS_XINO_DEF_TRUNC)
37571 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37574 + struct xino_do_trunc_args *args;
37577 + idx = xino_trunc_test(sb, br);
37581 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37584 + /* lock and kfree() will be called in trunc_xino() */
37585 + args = kmalloc(sizeof(*args), GFP_NOFS);
37586 + if (unlikely(!args)) {
37587 + AuErr1("no memory\n");
37591 + au_lcnt_inc(&br->br_count);
37595 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37597 + return; /* success */
37599 + pr_err("wkq %d\n", wkq_err);
37600 + au_lcnt_dec(&br->br_count);
37601 + au_kfree_rcu(args);
37604 + atomic_dec(&br->br_xino->xi_truncating);
37607 +/* ---------------------------------------------------------------------- */
37609 +struct au_xi_calc {
37614 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37615 + struct au_xi_calc *calc)
37619 + maxent = au_xi_maxent(sb);
37620 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37621 + calc->pos *= sizeof(ino_t);
37624 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37625 + struct au_xi_calc *calc)
37628 + struct file *file;
37629 + struct au_xino *xi = br->br_xino;
37630 + struct au_xi_new xinew = {
37634 + SiMustAnyLock(sb);
37640 + mutex_lock(&xi->xi_mtx);
37641 + file = au_xino_file(xi, calc->idx);
37645 + file = au_xino_file(xi, /*idx*/-1);
37646 + AuDebugOn(!file);
37647 + xinew.idx = calc->idx;
37648 + xinew.base = &file->f_path;
37649 + /* xinew.copy_src = NULL; */
37650 + file = au_xi_new(sb, &xinew);
37651 + if (IS_ERR(file))
37652 + err = PTR_ERR(file);
37655 + mutex_unlock(&xi->xi_mtx);
37660 +struct au_xino_do_new_async_args {
37661 + struct super_block *sb;
37662 + struct au_branch *br;
37663 + struct au_xi_calc calc;
37667 +struct au_xi_writing {
37668 + struct hlist_bl_node node;
37669 + ino_t h_ino, ino;
37672 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37675 +static void au_xino_call_do_new_async(void *args)
37677 + struct au_xino_do_new_async_args *a = args;
37678 + struct au_branch *br;
37679 + struct super_block *sb;
37680 + struct au_sbinfo *sbi;
37681 + struct inode *root;
37682 + struct file *file;
37683 + struct au_xi_writing *del, *p;
37684 + struct hlist_bl_head *hbl;
37685 + struct hlist_bl_node *pos;
37690 + sbi = au_sbi(sb);
37691 + si_noflush_read_lock(sb);
37692 + root = d_inode(sb->s_root);
37693 + ii_read_lock_child(root);
37694 + err = au_xino_do_new_async(sb, br, &a->calc);
37695 + if (unlikely(err)) {
37696 + AuIOErr("err %d\n", err);
37700 + file = au_xino_file(br->br_xino, a->calc.idx);
37701 + AuDebugOn(!file);
37702 + err = au_xino_do_write(file, &a->calc, a->ino);
37703 + if (unlikely(err)) {
37704 + AuIOErr("err %d\n", err);
37709 + hbl = &br->br_xino->xi_writing;
37710 + hlist_bl_lock(hbl);
37711 + au_hbl_for_each(pos, hbl) {
37712 + p = container_of(pos, struct au_xi_writing, node);
37713 + if (p->ino == a->ino) {
37715 + hlist_bl_del(&p->node);
37719 + hlist_bl_unlock(hbl);
37720 + au_kfree_rcu(del);
37723 + au_lcnt_dec(&br->br_count);
37724 + ii_read_unlock(root);
37725 + si_read_unlock(sb);
37726 + au_nwt_done(&sbi->si_nowait);
37731 + * create a new xino file asynchronously
37733 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37734 + struct au_xi_calc *calc, ino_t ino)
37737 + struct au_xino_do_new_async_args *arg;
37740 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37741 + if (unlikely(!arg))
37746 + arg->calc = *calc;
37748 + au_lcnt_inc(&br->br_count);
37749 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37750 + if (unlikely(err)) {
37751 + pr_err("wkq %d\n", err);
37752 + au_lcnt_dec(&br->br_count);
37753 + au_kfree_rcu(arg);
37761 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37762 + * at the position of @h_ino.
37764 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37769 + struct au_xi_calc calc;
37770 + struct au_sbinfo *sbinfo;
37771 + struct file *file;
37772 + struct au_xino *xi;
37773 + struct hlist_bl_head *hbl;
37774 + struct hlist_bl_node *pos;
37775 + struct au_xi_writing *p;
37778 + if (!au_opt_test(au_mntflags(sb), XINO))
37779 + return 0; /* no xino */
37782 + au_xi_calc(sb, h_ino, &calc);
37783 + xi = au_sbr(sb, bindex)->br_xino;
37784 + file = au_xino_file(xi, calc.idx);
37786 + hbl = &xi->xi_writing;
37787 + hlist_bl_lock(hbl);
37788 + au_hbl_for_each(pos, hbl) {
37789 + p = container_of(pos, struct au_xi_writing, node);
37790 + if (p->h_ino == h_ino) {
37791 + AuDbg("hi%llu, i%llu, found\n",
37792 + (u64)p->h_ino, (u64)p->ino);
37797 + hlist_bl_unlock(hbl);
37799 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37800 + return 0; /* no xino */
37802 + sbinfo = au_sbi(sb);
37803 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37804 + if (sz == sizeof(*ino))
37805 + return 0; /* success */
37808 + if (unlikely(sz >= 0)) {
37810 + AuIOErr("xino read error (%zd)\n", sz);
37815 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37820 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37821 + if (sz == sizeof(ino))
37822 + return 0; /* success */
37824 + AuIOErr("write failed (%zd)\n", sz);
37829 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37830 + * at the position of @h_ino.
37831 + * even if @ino is zero, it is written to the xinofile and means no entry.
37832 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37833 + * try truncating it.
37835 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37839 + unsigned int mnt_flags;
37840 + struct au_xi_calc calc;
37841 + struct file *file;
37842 + struct au_branch *br;
37843 + struct au_xino *xi;
37844 + struct au_xi_writing *p;
37846 + SiMustAnyLock(sb);
37848 + mnt_flags = au_mntflags(sb);
37849 + if (!au_opt_test(mnt_flags, XINO))
37852 + au_xi_calc(sb, h_ino, &calc);
37853 + br = au_sbr(sb, bindex);
37854 + xi = br->br_xino;
37855 + file = au_xino_file(xi, calc.idx);
37857 + /* store the inum pair into the list */
37858 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37859 + p->h_ino = h_ino;
37861 + au_hbl_add(&p->node, &xi->xi_writing);
37863 + /* create and write a new xino file asynchronously */
37864 + err = au_xino_new_async(sb, br, &calc, ino);
37866 + return 0; /* success */
37870 + err = au_xino_do_write(file, &calc, ino);
37872 + br = au_sbr(sb, bindex);
37873 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37874 + && au_test_fs_trunc_xino(au_br_sb(br)))
37875 + xino_try_trunc(sb, br);
37876 + return 0; /* success */
37880 + AuIOErr("write failed (%d)\n", err);
37884 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37887 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37888 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37892 + const int prevent_endless = 10;
37896 + err = vfsub_read_k(file, kbuf, size, pos);
37897 + if (err == -EINTR
37898 + && !au_wkq_test()
37899 + && fatal_signal_pending(current)) {
37900 + err = xino_fread_wkq(file, kbuf, size, pos);
37901 + BUG_ON(err == -EINTR);
37903 + } while (i++ < prevent_endless
37904 + && (err == -EAGAIN || err == -EINTR));
37906 +#if 0 /* reserved for future use */
37908 + fsnotify_access(file->f_path.dentry);
37914 +struct xino_fread_args {
37916 + struct file *file;
37922 +static void call_xino_fread(void *args)
37924 + struct xino_fread_args *a = args;
37925 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37928 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37933 + struct xino_fread_args args = {
37941 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37942 + if (unlikely(wkq_err))
37948 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37951 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37956 + const int prevent_endless = 10;
37960 + err = vfsub_write_k(file, kbuf, size, pos);
37961 + if (err == -EINTR
37962 + && !au_wkq_test()
37963 + && fatal_signal_pending(current)) {
37964 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37965 + BUG_ON(err == -EINTR);
37967 + } while (i++ < prevent_endless
37968 + && (err == -EAGAIN || err == -EINTR));
37970 +#if 0 /* reserved for future use */
37972 + fsnotify_modify(file->f_path.dentry);
37978 +struct do_xino_fwrite_args {
37980 + struct file *file;
37986 +static void call_do_xino_fwrite(void *args)
37988 + struct do_xino_fwrite_args *a = args;
37989 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37992 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37997 + struct do_xino_fwrite_args args = {
38006 + * it breaks RLIMIT_FSIZE and normal user's limit,
38007 + * users should care about quota and real 'filesystem full.'
38009 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38010 + if (unlikely(wkq_err))
38016 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38020 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38022 + err = do_xino_fwrite(file, buf, size, pos);
38026 + err = xino_fwrite_wkq(file, buf, size, pos);
38033 +/* ---------------------------------------------------------------------- */
38036 + * inode number bitmap
38038 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38039 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38043 + AuDebugOn(bit < 0 || page_bits <= bit);
38044 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38048 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38050 + AuDebugOn(ino < AUFS_FIRST_INO);
38051 + ino -= AUFS_FIRST_INO;
38052 + *pindex = ino / page_bits;
38053 + *bit = ino % page_bits;
38056 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38061 + struct au_sbinfo *sbinfo;
38062 + struct file *xib;
38063 + unsigned long *p;
38065 + sbinfo = au_sbi(sb);
38066 + MtxMustLock(&sbinfo->si_xib_mtx);
38067 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38068 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38070 + if (pindex == sbinfo->si_xib_last_pindex)
38073 + xib = sbinfo->si_xib;
38074 + p = sbinfo->si_xib_buf;
38075 + pos = sbinfo->si_xib_last_pindex;
38076 + pos *= PAGE_SIZE;
38077 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38078 + if (unlikely(sz != PAGE_SIZE))
38082 + pos *= PAGE_SIZE;
38083 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38084 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38086 + memset(p, 0, PAGE_SIZE);
38087 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38089 + if (sz == PAGE_SIZE) {
38090 + sbinfo->si_xib_last_pindex = pindex;
38091 + return 0; /* success */
38095 + AuIOErr1("write failed (%zd)\n", sz);
38102 +static void au_xib_clear_bit(struct inode *inode)
38105 + unsigned long pindex;
38106 + struct super_block *sb;
38107 + struct au_sbinfo *sbinfo;
38109 + AuDebugOn(inode->i_nlink);
38111 + sb = inode->i_sb;
38112 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38113 + AuDebugOn(page_bits <= bit);
38114 + sbinfo = au_sbi(sb);
38115 + mutex_lock(&sbinfo->si_xib_mtx);
38116 + err = xib_pindex(sb, pindex);
38118 + clear_bit(bit, sbinfo->si_xib_buf);
38119 + sbinfo->si_xib_next_bit = bit;
38121 + mutex_unlock(&sbinfo->si_xib_mtx);
38124 +/* ---------------------------------------------------------------------- */
38127 + * truncate a xino bitmap file
38131 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38135 + unsigned long pindex;
38136 + loff_t pos, pend;
38137 + struct au_sbinfo *sbinfo;
38139 + unsigned long *p;
38142 + sbinfo = au_sbi(sb);
38143 + MtxMustLock(&sbinfo->si_xib_mtx);
38144 + p = sbinfo->si_xib_buf;
38145 + pend = vfsub_f_size_read(file);
38147 + while (pos < pend) {
38148 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38150 + if (unlikely(sz <= 0))
38154 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38155 + if (unlikely(*ino < AUFS_FIRST_INO))
38158 + xib_calc_bit(*ino, &pindex, &bit);
38159 + AuDebugOn(page_bits <= bit);
38160 + err = xib_pindex(sb, pindex);
38172 +static int xib_restore(struct super_block *sb)
38175 + unsigned int nfile;
38176 + aufs_bindex_t bindex, bbot;
38178 + struct au_branch *br;
38179 + struct au_xino *xi;
38180 + struct file *file;
38183 + page = (void *)__get_free_page(GFP_NOFS);
38184 + if (unlikely(!page))
38188 + bbot = au_sbbot(sb);
38189 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38190 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38191 + br = au_sbr(sb, bindex);
38192 + xi = br->br_xino;
38193 + nfile = xi->xi_nfile;
38194 + for (i = 0; i < nfile; i++) {
38195 + file = au_xino_file(xi, i);
38197 + err = do_xib_restore(sb, file, page);
38200 + AuDbg("skip shared b%d\n", bindex);
38201 + free_page((unsigned long)page);
38207 +int au_xib_trunc(struct super_block *sb)
38212 + struct au_sbinfo *sbinfo;
38213 + unsigned long *p;
38214 + struct file *file;
38216 + SiMustWriteLock(sb);
38219 + sbinfo = au_sbi(sb);
38220 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38223 + file = sbinfo->si_xib;
38224 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38227 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38228 + err = PTR_ERR(file);
38229 + if (IS_ERR(file))
38231 + fput(sbinfo->si_xib);
38232 + sbinfo->si_xib = file;
38234 + p = sbinfo->si_xib_buf;
38235 + memset(p, 0, PAGE_SIZE);
38237 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38238 + if (unlikely(sz != PAGE_SIZE)) {
38240 + AuIOErr("err %d\n", err);
38246 + mutex_lock(&sbinfo->si_xib_mtx);
38247 + /* mnt_want_write() is unnecessary here */
38248 + err = xib_restore(sb);
38249 + mutex_unlock(&sbinfo->si_xib_mtx);
38255 +/* ---------------------------------------------------------------------- */
38257 +struct au_xino *au_xino_alloc(unsigned int nfile)
38259 + struct au_xino *xi;
38261 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38262 + if (unlikely(!xi))
38264 + xi->xi_nfile = nfile;
38265 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38266 + if (unlikely(!xi->xi_file))
38269 + xi->xi_nondir.total = 8; /* initial size */
38270 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38272 + if (unlikely(!xi->xi_nondir.array))
38275 + spin_lock_init(&xi->xi_nondir.spin);
38276 + init_waitqueue_head(&xi->xi_nondir.wqh);
38277 + mutex_init(&xi->xi_mtx);
38278 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38279 + atomic_set(&xi->xi_truncating, 0);
38280 + kref_init(&xi->xi_kref);
38281 + goto out; /* success */
38284 + au_kfree_try_rcu(xi->xi_file);
38286 + au_kfree_rcu(xi);
38292 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38295 + struct au_xino *xi;
38298 + xi = au_xino_alloc(idx + 1);
38299 + if (unlikely(!xi)) {
38306 + xi->xi_file[idx] = file;
38307 + AuDebugOn(br->br_xino);
38308 + br->br_xino = xi;
38314 +static void au_xino_release(struct kref *kref)
38316 + struct au_xino *xi;
38318 + unsigned long ul;
38319 + struct hlist_bl_head *hbl;
38320 + struct hlist_bl_node *pos, *n;
38321 + struct au_xi_writing *p;
38323 + xi = container_of(kref, struct au_xino, xi_kref);
38324 + for (i = 0; i < xi->xi_nfile; i++)
38325 + if (xi->xi_file[i])
38326 + fput(xi->xi_file[i]);
38327 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38328 + AuDebugOn(xi->xi_nondir.array[i]);
38329 + mutex_destroy(&xi->xi_mtx);
38330 + hbl = &xi->xi_writing;
38331 + ul = au_hbl_count(hbl);
38332 + if (unlikely(ul)) {
38333 + pr_warn("xi_writing %lu\n", ul);
38334 + hlist_bl_lock(hbl);
38335 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38336 + hlist_bl_del(&p->node);
38337 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38340 + hlist_bl_unlock(hbl);
38342 + au_kfree_try_rcu(xi->xi_file);
38343 + au_kfree_try_rcu(xi->xi_nondir.array);
38344 + au_kfree_rcu(xi);
38347 +int au_xino_put(struct au_branch *br)
38350 + struct au_xino *xi;
38353 + xi = br->br_xino;
38355 + br->br_xino = NULL;
38356 + ret = kref_put(&xi->xi_kref, au_xino_release);
38362 +/* ---------------------------------------------------------------------- */
38365 + * xino mount option handlers
38369 +static void xino_clear_xib(struct super_block *sb)
38371 + struct au_sbinfo *sbinfo;
38373 + SiMustWriteLock(sb);
38375 + sbinfo = au_sbi(sb);
38376 + if (sbinfo->si_xib)
38377 + fput(sbinfo->si_xib);
38378 + sbinfo->si_xib = NULL;
38379 + if (sbinfo->si_xib_buf)
38380 + free_page((unsigned long)sbinfo->si_xib_buf);
38381 + sbinfo->si_xib_buf = NULL;
38384 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38388 + struct au_sbinfo *sbinfo;
38389 + struct file *file;
38390 + struct super_block *xi_sb;
38392 + SiMustWriteLock(sb);
38394 + sbinfo = au_sbi(sb);
38395 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38396 + err = PTR_ERR(file);
38397 + if (IS_ERR(file))
38399 + if (sbinfo->si_xib)
38400 + fput(sbinfo->si_xib);
38401 + sbinfo->si_xib = file;
38402 + xi_sb = file_inode(file)->i_sb;
38403 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38404 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38406 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38407 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38410 + sbinfo->si_ximaxent /= sizeof(ino_t);
38413 + if (!sbinfo->si_xib_buf)
38414 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38415 + if (unlikely(!sbinfo->si_xib_buf))
38418 + sbinfo->si_xib_last_pindex = 0;
38419 + sbinfo->si_xib_next_bit = 0;
38420 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38422 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38423 + if (unlikely(err != PAGE_SIZE))
38427 + goto out; /* success */
38430 + if (sbinfo->si_xib_buf)
38431 + free_page((unsigned long)sbinfo->si_xib_buf);
38432 + sbinfo->si_xib_buf = NULL;
38436 + fput(sbinfo->si_xib);
38437 + sbinfo->si_xib = NULL;
38443 +/* xino for each branch */
38444 +static void xino_clear_br(struct super_block *sb)
38446 + aufs_bindex_t bindex, bbot;
38447 + struct au_branch *br;
38449 + bbot = au_sbbot(sb);
38450 + for (bindex = 0; bindex <= bbot; bindex++) {
38451 + br = au_sbr(sb, bindex);
38457 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38458 + aufs_bindex_t bshared)
38460 + struct au_branch *brshared;
38462 + brshared = au_sbr(sb, bshared);
38463 + AuDebugOn(!brshared->br_xino);
38464 + AuDebugOn(!brshared->br_xino->xi_file);
38465 + if (br->br_xino != brshared->br_xino) {
38466 + au_xino_get(brshared);
38468 + br->br_xino = brshared->br_xino;
38472 +struct au_xino_do_set_br {
38473 + struct au_branch *br;
38475 + aufs_bindex_t bshared;
38478 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38479 + struct au_xino_do_set_br *args)
38482 + struct au_xi_calc calc;
38483 + struct file *file;
38484 + struct au_branch *br;
38485 + struct au_xi_new xinew = {
38490 + xinew.xi = br->br_xino;
38491 + au_xi_calc(sb, args->h_ino, &calc);
38492 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38493 + if (args->bshared >= 0)
38494 + /* shared xino */
38495 + au_xino_set_br_shared(sb, br, args->bshared);
38496 + else if (!xinew.xi) {
38498 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38499 + if (unlikely(err))
38503 + /* force re-creating */
38504 + xinew.xi = br->br_xino;
38505 + xinew.idx = calc.idx;
38506 + mutex_lock(&xinew.xi->xi_mtx);
38507 + file = au_xi_new(sb, &xinew);
38508 + mutex_unlock(&xinew.xi->xi_mtx);
38509 + err = PTR_ERR(file);
38510 + if (IS_ERR(file))
38512 + AuDebugOn(!file);
38514 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38515 + if (unlikely(err))
38523 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38526 + aufs_bindex_t bindex, bbot;
38527 + struct au_xino_do_set_br args;
38528 + struct inode *inode;
38530 + SiMustWriteLock(sb);
38532 + bbot = au_sbbot(sb);
38533 + inode = d_inode(sb->s_root);
38534 + for (bindex = 0; bindex <= bbot; bindex++) {
38535 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38536 + args.br = au_sbr(sb, bindex);
38537 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38538 + err = au_xino_do_set_br(sb, path, &args);
38539 + if (unlikely(err))
38547 +void au_xino_clr(struct super_block *sb)
38549 + struct au_sbinfo *sbinfo;
38551 + au_xigen_clr(sb);
38552 + xino_clear_xib(sb);
38553 + xino_clear_br(sb);
38554 + dbgaufs_brs_del(sb, 0);
38555 + sbinfo = au_sbi(sb);
38556 + /* lvalue, do not call au_mntflags() */
38557 + au_opt_clr(sbinfo->si_mntflags, XINO);
38560 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38563 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38564 + struct qstr *dname, *cur_name;
38565 + struct file *cur_xino;
38566 + struct au_sbinfo *sbinfo;
38567 + struct path *path, *cur_path;
38569 + SiMustWriteLock(sb);
38572 + sbinfo = au_sbi(sb);
38573 + path = &xiopt->file->f_path;
38574 + dentry = path->dentry;
38575 + parent = dget_parent(dentry);
38578 + cur_xino = sbinfo->si_xib;
38580 + cur_path = &cur_xino->f_path;
38581 + cur_dentry = cur_path->dentry;
38582 + cur_parent = dget_parent(cur_dentry);
38583 + cur_name = &cur_dentry->d_name;
38584 + dname = &dentry->d_name;
38585 + skip = (cur_parent == parent
38586 + && au_qstreq(dname, cur_name));
38587 + dput(cur_parent);
38593 + au_opt_set(sbinfo->si_mntflags, XINO);
38594 + err = au_xino_set_xib(sb, path);
38595 + /* si_x{read,write} are set */
38597 + err = au_xigen_set(sb, path);
38599 + err = au_xino_set_br(sb, path);
38601 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38602 + goto out; /* success */
38606 + AuIOErr("failed setting xino(%d).\n", err);
38615 + * create a xinofile at the default place/path.
38617 +struct file *au_xino_def(struct super_block *sb)
38619 + struct file *file;
38621 + struct au_branch *br;
38622 + struct super_block *h_sb;
38623 + struct path path;
38624 + aufs_bindex_t bbot, bindex, bwr;
38627 + bbot = au_sbbot(sb);
38629 + for (bindex = 0; bindex <= bbot; bindex++) {
38630 + br = au_sbr(sb, bindex);
38631 + if (au_br_writable(br->br_perm)
38632 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38639 + file = ERR_PTR(-ENOMEM);
38640 + page = (void *)__get_free_page(GFP_NOFS);
38641 + if (unlikely(!page))
38643 + path.mnt = au_br_mnt(br);
38644 + path.dentry = au_h_dptr(sb->s_root, bwr);
38645 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38646 + file = (void *)p;
38647 + if (!IS_ERR(p)) {
38648 + strcat(p, "/" AUFS_XINO_FNAME);
38649 + AuDbg("%s\n", p);
38650 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38652 + free_page((unsigned long)page);
38654 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38656 + if (IS_ERR(file))
38658 + h_sb = file->f_path.dentry->d_sb;
38659 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38660 + pr_err("xino doesn't support %s(%s)\n",
38661 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38663 + file = ERR_PTR(-EINVAL);
38671 +/* ---------------------------------------------------------------------- */
38674 + * initialize the xinofile for the specified branch @br
38675 + * at the place/path where @base_file indicates.
38676 + * test whether another branch is on the same filesystem or not,
38677 + * if found then share the xinofile with another branch.
38679 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38680 + struct path *base)
38683 + struct au_xino_do_set_br args = {
38688 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38690 + err = au_xino_do_set_br(sb, base, &args);
38691 + if (unlikely(err))
38697 +/* ---------------------------------------------------------------------- */
38700 + * get an unused inode number from bitmap
38702 +ino_t au_xino_new_ino(struct super_block *sb)
38705 + unsigned long *p, pindex, ul, pend;
38706 + struct au_sbinfo *sbinfo;
38707 + struct file *file;
38708 + int free_bit, err;
38710 + if (!au_opt_test(au_mntflags(sb), XINO))
38711 + return iunique(sb, AUFS_FIRST_INO);
38713 + sbinfo = au_sbi(sb);
38714 + mutex_lock(&sbinfo->si_xib_mtx);
38715 + p = sbinfo->si_xib_buf;
38716 + free_bit = sbinfo->si_xib_next_bit;
38717 + if (free_bit < page_bits && !test_bit(free_bit, p))
38718 + goto out; /* success */
38719 + free_bit = find_first_zero_bit(p, page_bits);
38720 + if (free_bit < page_bits)
38721 + goto out; /* success */
38723 + pindex = sbinfo->si_xib_last_pindex;
38724 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38725 + err = xib_pindex(sb, ul);
38726 + if (unlikely(err))
38728 + free_bit = find_first_zero_bit(p, page_bits);
38729 + if (free_bit < page_bits)
38730 + goto out; /* success */
38733 + file = sbinfo->si_xib;
38734 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38735 + for (ul = pindex + 1; ul <= pend; ul++) {
38736 + err = xib_pindex(sb, ul);
38737 + if (unlikely(err))
38739 + free_bit = find_first_zero_bit(p, page_bits);
38740 + if (free_bit < page_bits)
38741 + goto out; /* success */
38746 + set_bit(free_bit, p);
38747 + sbinfo->si_xib_next_bit = free_bit + 1;
38748 + pindex = sbinfo->si_xib_last_pindex;
38749 + mutex_unlock(&sbinfo->si_xib_mtx);
38750 + ino = xib_calc_ino(pindex, free_bit);
38751 + AuDbg("i%lu\n", (unsigned long)ino);
38754 + mutex_unlock(&sbinfo->si_xib_mtx);
38759 +/* for s_op->delete_inode() */
38760 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38763 + unsigned int mnt_flags;
38764 + aufs_bindex_t bindex, bbot, bi;
38765 + unsigned char try_trunc;
38766 + struct au_iinfo *iinfo;
38767 + struct super_block *sb;
38768 + struct au_hinode *hi;
38769 + struct inode *h_inode;
38770 + struct au_branch *br;
38771 + struct au_xi_calc calc;
38772 + struct file *file;
38774 + AuDebugOn(au_is_bad_inode(inode));
38776 + sb = inode->i_sb;
38777 + mnt_flags = au_mntflags(sb);
38778 + if (!au_opt_test(mnt_flags, XINO)
38779 + || inode->i_ino == AUFS_ROOT_INO)
38783 + au_xigen_inc(inode);
38784 + au_xib_clear_bit(inode);
38787 + iinfo = au_ii(inode);
38788 + bindex = iinfo->ii_btop;
38792 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38793 + hi = au_hinode(iinfo, bindex);
38794 + bbot = iinfo->ii_bbot;
38795 + for (; bindex <= bbot; bindex++, hi++) {
38796 + h_inode = hi->hi_inode;
38798 + || (!unlinked && h_inode->i_nlink))
38801 + /* inode may not be revalidated */
38802 + bi = au_br_index(sb, hi->hi_id);
38806 + br = au_sbr(sb, bi);
38807 + au_xi_calc(sb, h_inode->i_ino, &calc);
38808 + file = au_xino_file(br->br_xino, calc.idx);
38809 + if (IS_ERR_OR_NULL(file))
38812 + err = au_xino_do_write(file, &calc, /*ino*/0);
38813 + if (!err && try_trunc
38814 + && au_test_fs_trunc_xino(au_br_sb(br)))
38815 + xino_try_trunc(sb, br);
38819 +/* ---------------------------------------------------------------------- */
38821 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38823 + int found, total, i;
38826 + total = xi->xi_nondir.total;
38827 + for (i = 0; i < total; i++) {
38828 + if (xi->xi_nondir.array[i] != h_ino)
38837 +static int au_xinondir_expand(struct au_xino *xi)
38842 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38845 + sz = xi->xi_nondir.total * sizeof(ino_t);
38846 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38848 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38849 + /*may_shrink*/0);
38851 + xi->xi_nondir.array = p;
38852 + xi->xi_nondir.total <<= 1;
38853 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38861 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38862 + ino_t h_ino, int idx)
38864 + struct au_xino *xi;
38866 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38867 + xi = au_sbr(sb, bindex)->br_xino;
38868 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38870 + spin_lock(&xi->xi_nondir.spin);
38871 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38872 + xi->xi_nondir.array[idx] = 0;
38873 + spin_unlock(&xi->xi_nondir.spin);
38874 + wake_up_all(&xi->xi_nondir.wqh);
38877 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38880 + int err, found, empty;
38881 + struct au_xino *xi;
38885 + if (!au_opt_test(au_mntflags(sb), XINO))
38886 + goto out; /* no xino */
38888 + xi = au_sbr(sb, bindex)->br_xino;
38891 + spin_lock(&xi->xi_nondir.spin);
38892 + found = au_xinondir_find(xi, h_ino);
38893 + if (found == -1) {
38894 + empty = au_xinondir_find(xi, /*h_ino*/0);
38895 + if (empty == -1) {
38896 + empty = xi->xi_nondir.total;
38897 + err = au_xinondir_expand(xi);
38898 + if (unlikely(err))
38901 + xi->xi_nondir.array[empty] = h_ino;
38904 + spin_unlock(&xi->xi_nondir.spin);
38905 + wait_event(xi->xi_nondir.wqh,
38906 + xi->xi_nondir.array[found] != h_ino);
38911 + spin_unlock(&xi->xi_nondir.spin);
38916 +/* ---------------------------------------------------------------------- */
38918 +int au_xino_path(struct seq_file *seq, struct file *file)
38922 + err = au_seq_path(seq, &file->f_path);
38923 + if (unlikely(err))
38926 +#define Deleted "\\040(deleted)"
38927 + seq->count -= sizeof(Deleted) - 1;
38928 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38929 + sizeof(Deleted) - 1));
38935 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38936 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38937 +++ linux/include/uapi/linux/aufs_type.h 2022-03-21 14:49:05.733299677 +0100
38939 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38941 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38943 + * This program, aufs is free software; you can redistribute it and/or modify
38944 + * it under the terms of the GNU General Public License as published by
38945 + * the Free Software Foundation; either version 2 of the License, or
38946 + * (at your option) any later version.
38948 + * This program is distributed in the hope that it will be useful,
38949 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38950 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38951 + * GNU General Public License for more details.
38953 + * You should have received a copy of the GNU General Public License
38954 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38957 +#ifndef __AUFS_TYPE_H__
38958 +#define __AUFS_TYPE_H__
38960 +#define AUFS_NAME "aufs"
38964 + * define it before including all other headers.
38965 + * sched.h may use pr_* macros before defining "current", so define the
38966 + * no-current version first, and re-define later.
38968 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38969 +#include <linux/sched.h>
38971 +#define pr_fmt(fmt) \
38972 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38973 + (int)sizeof(current->comm), current->comm, current->pid
38974 +#include <linux/limits.h>
38976 +#include <stdint.h>
38977 +#include <sys/types.h>
38978 +#include <limits.h>
38979 +#endif /* __KERNEL__ */
38981 +#define AUFS_VERSION "5.x-rcN-20220314"
38983 +/* todo? move this to linux-2.6.19/include/magic.h */
38984 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38986 +/* ---------------------------------------------------------------------- */
38989 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38990 +typedef int8_t aufs_bindex_t;
38991 +#define AUFS_BRANCH_MAX 127
38993 +typedef int16_t aufs_bindex_t;
38994 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38995 +#define AUFS_BRANCH_MAX 511
38996 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38997 +#define AUFS_BRANCH_MAX 1023
38998 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38999 +#define AUFS_BRANCH_MAX 32767
39003 +#ifndef AUFS_BRANCH_MAX
39004 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39006 +#endif /* __KERNEL__ */
39008 +/* ---------------------------------------------------------------------- */
39010 +#define AUFS_FSTYPE AUFS_NAME
39012 +#define AUFS_ROOT_INO 2
39013 +#define AUFS_FIRST_INO 11
39015 +#define AUFS_WH_PFX ".wh."
39016 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39017 +#define AUFS_WH_TMP_LEN 4
39018 +/* a limit for rmdir/rename a dir and copyup */
39019 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39020 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39022 + - AUFS_WH_TMP_LEN) /* hex */
39023 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39024 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39025 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39026 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39027 +#define AUFS_DIRWH_DEF 3
39028 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39029 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39030 +#define AUFS_RDBLK_DEF 512 /* bytes */
39031 +#define AUFS_RDHASH_DEF 32
39032 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39033 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39034 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39035 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39036 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39038 +/* pseudo-link maintenace under /proc */
39039 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39040 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39041 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39043 +/* dirren, renamed dir */
39044 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39045 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39046 +/* whiteouted doubly */
39047 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39048 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39050 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39051 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39053 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39054 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39055 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39057 +/* doubly whiteouted */
39058 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39059 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39060 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39062 +/* branch permissions and attributes */
39063 +#define AUFS_BRPERM_RW "rw"
39064 +#define AUFS_BRPERM_RO "ro"
39065 +#define AUFS_BRPERM_RR "rr"
39066 +#define AUFS_BRATTR_COO_REG "coo_reg"
39067 +#define AUFS_BRATTR_COO_ALL "coo_all"
39068 +#define AUFS_BRATTR_FHSM "fhsm"
39069 +#define AUFS_BRATTR_UNPIN "unpin"
39070 +#define AUFS_BRATTR_ICEX "icex"
39071 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39072 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39073 +#define AUFS_BRATTR_ICEX_TR "icextr"
39074 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39075 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39076 +#define AUFS_BRRATTR_WH "wh"
39077 +#define AUFS_BRWATTR_NLWH "nolwh"
39078 +#define AUFS_BRWATTR_MOO "moo"
39080 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39081 +#define AuBrPerm_RO (1 << 1) /* readonly */
39082 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39083 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39085 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39086 +#define AuBrAttr_COO_ALL (1 << 4)
39087 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39089 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39090 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39091 + branch. meaningless since
39092 + linux-3.18-rc1 */
39094 +/* ignore error in copying XATTR */
39095 +#define AuBrAttr_ICEX_SEC (1 << 7)
39096 +#define AuBrAttr_ICEX_SYS (1 << 8)
39097 +#define AuBrAttr_ICEX_TR (1 << 9)
39098 +#define AuBrAttr_ICEX_USR (1 << 10)
39099 +#define AuBrAttr_ICEX_OTH (1 << 11)
39100 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39101 + | AuBrAttr_ICEX_SYS \
39102 + | AuBrAttr_ICEX_TR \
39103 + | AuBrAttr_ICEX_USR \
39104 + | AuBrAttr_ICEX_OTH)
39106 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39107 +#define AuBrRAttr_Mask AuBrRAttr_WH
39109 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39110 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39111 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39113 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39115 +/* #warning test userspace */
39117 +#ifndef CONFIG_AUFS_FHSM
39118 +#undef AuBrAttr_FHSM
39119 +#define AuBrAttr_FHSM 0
39121 +#ifndef CONFIG_AUFS_XATTR
39122 +#undef AuBrAttr_ICEX
39123 +#define AuBrAttr_ICEX 0
39124 +#undef AuBrAttr_ICEX_SEC
39125 +#define AuBrAttr_ICEX_SEC 0
39126 +#undef AuBrAttr_ICEX_SYS
39127 +#define AuBrAttr_ICEX_SYS 0
39128 +#undef AuBrAttr_ICEX_TR
39129 +#define AuBrAttr_ICEX_TR 0
39130 +#undef AuBrAttr_ICEX_USR
39131 +#define AuBrAttr_ICEX_USR 0
39132 +#undef AuBrAttr_ICEX_OTH
39133 +#define AuBrAttr_ICEX_OTH 0
39137 +/* the longest combination */
39138 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39139 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39140 + "+" AUFS_BRATTR_COO_REG \
39141 + "+" AUFS_BRATTR_FHSM \
39142 + "+" AUFS_BRATTR_UNPIN \
39143 + "+" AUFS_BRATTR_ICEX_SEC \
39144 + "+" AUFS_BRATTR_ICEX_SYS \
39145 + "+" AUFS_BRATTR_ICEX_USR \
39146 + "+" AUFS_BRATTR_ICEX_OTH \
39147 + "+" AUFS_BRWATTR_NLWH)
39150 + char a[AuBrPermStrSz];
39151 +} au_br_perm_str_t;
39153 +static inline int au_br_writable(int brperm)
39155 + return brperm & AuBrPerm_RW;
39158 +static inline int au_br_whable(int brperm)
39160 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39163 +static inline int au_br_wh_linkable(int brperm)
39165 + return !(brperm & AuBrWAttr_NoLinkWH);
39168 +static inline int au_br_cmoo(int brperm)
39170 + return brperm & AuBrAttr_CMOO_Mask;
39173 +static inline int au_br_fhsm(int brperm)
39175 + return brperm & AuBrAttr_FHSM;
39178 +/* ---------------------------------------------------------------------- */
39182 + /* readdir in userspace */
39186 + AuCtl_WBR_FD, /* pathconf wrapper */
39187 + AuCtl_IBUSY, /* busy inode */
39188 + AuCtl_MVDOWN, /* move-down */
39189 + AuCtl_BR, /* info about branches */
39190 + AuCtl_FHSM_FD /* connection for fhsm */
39193 +/* borrowed from linux/include/linux/kernel.h */
39195 +#ifdef _GNU_SOURCE
39196 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39198 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39200 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39203 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39205 +#define __aligned(x) __attribute__((aligned(x)))
39210 +#define __packed __attribute__((packed))
39214 +struct au_rdu_cookie {
39219 + uint32_t generation;
39222 +struct au_rdu_ent {
39231 +static inline int au_rdu_len(int nlen)
39233 + /* include the terminating NULL */
39234 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39235 + sizeof(uint64_t));
39238 +union au_rdu_ent_ul {
39239 + struct au_rdu_ent __user *e;
39251 + uint64_t sz; /* AuCtl_RDU */
39252 + uint64_t nent; /* AuCtl_RDU_INO */
39254 + union au_rdu_ent_ul ent;
39255 + uint16_t verify[AufsCtlRduV_End];
39257 + /* input/output */
39261 + union au_rdu_ent_ul tail;
39262 + /* number of entries which were added in a single call */
39267 + struct au_rdu_cookie cookie;
39270 +/* ---------------------------------------------------------------------- */
39272 +/* dirren. the branch is identified by the filename who contains this */
39273 +struct au_drinfo {
39276 + uint8_t oldnamelen;
39277 + uint64_t _padding;
39279 + uint8_t oldname[];
39282 +struct au_drinfo_fdata {
39284 + struct au_drinfo drinfo;
39287 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39289 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39291 +/* ---------------------------------------------------------------------- */
39293 +struct aufs_wbr_fd {
39298 +/* ---------------------------------------------------------------------- */
39300 +struct aufs_ibusy {
39301 + uint64_t ino, h_ino;
39305 +/* ---------------------------------------------------------------------- */
39307 +/* error code for move-down */
39308 +/* the actual message strings are implemented in aufs-util.git */
39310 + EAU_MVDOWN_OPAQUE = 1,
39311 + EAU_MVDOWN_WHITEOUT,
39312 + EAU_MVDOWN_UPPER,
39313 + EAU_MVDOWN_BOTTOM,
39314 + EAU_MVDOWN_NOUPPER,
39315 + EAU_MVDOWN_NOLOWERBR,
39319 +/* flags for move-down */
39320 +#define AUFS_MVDOWN_DMSG 1
39321 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39322 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39323 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39324 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39325 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39326 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39327 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39328 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39329 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39330 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39331 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39332 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39334 +/* index for move-down */
39336 + AUFS_MVDOWN_UPPER,
39337 + AUFS_MVDOWN_LOWER,
39338 + AUFS_MVDOWN_NARRAY
39342 + * additional info of move-down
39343 + * number of free blocks and inodes.
39344 + * subset of struct kstatfs, but smaller and always 64bit.
39346 +struct aufs_stfs {
39347 + uint64_t f_blocks;
39348 + uint64_t f_bavail;
39349 + uint64_t f_files;
39350 + uint64_t f_ffree;
39353 +struct aufs_stbr {
39354 + int16_t brid; /* optional input */
39355 + int16_t bindex; /* output */
39356 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39359 +struct aufs_mvdown {
39360 + uint32_t flags; /* input/output */
39361 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39362 + int8_t au_errno; /* output */
39365 +/* ---------------------------------------------------------------------- */
39367 +union aufs_brinfo {
39368 + /* PATH_MAX may differ between kernel-space and user-space */
39369 + char _spacer[4096];
39377 +/* ---------------------------------------------------------------------- */
39379 +#define AuCtlType 'A'
39380 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39381 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39382 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39383 + struct aufs_wbr_fd)
39384 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39385 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39386 + struct aufs_mvdown)
39387 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39388 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39390 +#endif /* __AUFS_TYPE_H__ */
39391 SPDX-License-Identifier: GPL-2.0
39392 aufs5.x-rcN loopback patch
39394 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39395 index 9009a0efc4b28..60307b90fbead 100644
39396 --- a/drivers/block/loop.c
39397 +++ b/drivers/block/loop.c
39398 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39402 +static struct file *loop_real_file(struct file *file)
39404 + struct file *f = NULL;
39406 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39407 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39411 static void loop_reread_partitions(struct loop_device *lo)
39414 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39416 struct file *file = fget(arg);
39417 struct file *old_file;
39418 + struct file *f, *virt_file = NULL, *old_virt_file;
39422 @@ -586,11 +596,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39423 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39426 + f = loop_real_file(file);
39428 + virt_file = file;
39433 error = loop_validate_file(file, bdev);
39437 old_file = lo->lo_backing_file;
39438 + old_virt_file = lo->lo_backing_virt_file;
39442 @@ -603,6 +621,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39443 blk_mq_freeze_queue(lo->lo_queue);
39444 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39445 lo->lo_backing_file = file;
39446 + lo->lo_backing_virt_file = virt_file;
39447 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39448 mapping_set_gfp_mask(file->f_mapping,
39449 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39450 @@ -625,6 +644,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39454 + if (old_virt_file)
39455 + fput(old_virt_file);
39457 loop_reread_partitions(lo);
39459 @@ -633,6 +654,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39460 loop_global_unlock(lo, is_loop);
39468 @@ -971,6 +994,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39469 const struct loop_config *config)
39471 struct file *file = fget(config->fd);
39472 + struct file *f, *virt_file = NULL;
39473 struct inode *inode;
39474 struct address_space *mapping;
39476 @@ -986,6 +1010,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39477 /* This is safe, since we have a reference from open(). */
39478 __module_get(THIS_MODULE);
39480 + f = loop_real_file(file);
39482 + virt_file = file;
39488 * If we don't hold exclusive handle for the device, upgrade to it
39489 * here to avoid changing device under exclusive owner.
39490 @@ -1051,6 +1082,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39491 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39492 lo->lo_device = bdev;
39493 lo->lo_backing_file = file;
39494 + lo->lo_backing_virt_file = virt_file;
39495 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39496 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39498 @@ -1101,6 +1133,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39499 bd_abort_claiming(bdev, loop_configure);
39504 /* This is safe: open() is still holding a reference. */
39505 module_put(THIS_MODULE);
39507 @@ -1109,6 +1143,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39508 static void __loop_clr_fd(struct loop_device *lo, bool release)
39511 + struct file *virt_filp = lo->lo_backing_virt_file;
39512 gfp_t gfp = lo->old_gfp_mask;
39513 struct loop_worker *pos, *worker;
39515 @@ -1154,6 +1189,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39516 spin_lock_irq(&lo->lo_lock);
39517 filp = lo->lo_backing_file;
39518 lo->lo_backing_file = NULL;
39519 + lo->lo_backing_virt_file = NULL;
39520 spin_unlock_irq(&lo->lo_lock);
39522 lo->lo_device = NULL;
39523 @@ -1215,6 +1251,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39524 * fput can take open_mutex which is usually taken before lo_mutex.
39531 static int loop_clr_fd(struct loop_device *lo)
39532 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39533 index 082d4b6bfc6a6..61feca64688df 100644
39534 --- a/drivers/block/loop.h
39535 +++ b/drivers/block/loop.h
39536 @@ -34,7 +34,7 @@ struct loop_device {
39538 char lo_file_name[LO_NAME_SIZE];
39540 - struct file * lo_backing_file;
39541 + struct file *lo_backing_file, *lo_backing_virt_file;
39542 struct block_device *lo_device;
39544 gfp_t old_gfp_mask;
39545 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39546 index 99ceca1440449..e49dfe8550329 100644
39547 --- a/fs/aufs/f_op.c
39548 +++ b/fs/aufs/f_op.c
39549 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39550 if (IS_ERR(h_file))
39553 - if (au_test_loopback_kthread()) {
39554 + if (0 && au_test_loopback_kthread()) {
39555 au_warn_loopback(h_file->f_path.dentry->d_sb);
39556 if (file->f_mapping != h_file->f_mapping) {
39557 file->f_mapping = h_file->f_mapping;
39558 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39559 index 74347bd75b380..5ef888a1d53f4 100644
39560 --- a/fs/aufs/loop.c
39561 +++ b/fs/aufs/loop.c
39562 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39563 symbol_put(loop_backing_file);
39564 au_kfree_try_rcu(au_warn_loopback_array);
39567 +/* ---------------------------------------------------------------------- */
39569 +/* support the loopback block device insude aufs */
39571 +struct file *aufs_real_loop(struct file *file)
39575 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39576 + fi_read_lock(file);
39577 + f = au_hf_top(file);
39578 + fi_read_unlock(file);
39582 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39583 index 7293bee427f96..3345c098d0d47 100644
39584 --- a/fs/aufs/loop.h
39585 +++ b/fs/aufs/loop.h
39586 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39588 int au_loopback_init(void);
39589 void au_loopback_fin(void);
39591 +struct file *aufs_real_loop(struct file *file);
39593 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39595 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39597 AuStubInt0(au_loopback_init, void)
39598 AuStubVoid(au_loopback_fin, void)
39600 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39601 #endif /* BLK_DEV_LOOP */
39603 #endif /* __KERNEL__ */
39604 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39605 index 90043afec51c1..0835f6da42d97 100644
39606 --- a/fs/aufs/super.c
39607 +++ b/fs/aufs/super.c
39608 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39609 .show_options = aufs_show_options,
39610 .statfs = aufs_statfs,
39611 .put_super = aufs_put_super,
39612 - .sync_fs = aufs_sync_fs
39613 + .sync_fs = aufs_sync_fs,
39614 +#ifdef CONFIG_AUFS_BDEV_LOOP
39615 + .real_loop = aufs_real_loop
39619 /* ---------------------------------------------------------------------- */
39620 diff --git a/include/linux/fs.h b/include/linux/fs.h
39621 index 5479e6dc18a23..05fe92d076c19 100644
39622 --- a/include/linux/fs.h
39623 +++ b/include/linux/fs.h
39624 @@ -2137,6 +2137,10 @@ struct super_operations {
39625 struct shrink_control *);
39626 long (*free_cached_objects)(struct super_block *,
39627 struct shrink_control *);
39628 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39630 + struct file *(*real_loop)(struct file *);