1 SPDX-License-Identifier: GPL-2.0
2 aufs5.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index a6313a969bc5f..aca4b89d41a14 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 84c5e4cdfee5a..b4fcdad8412ed 100644
20 @@ -138,3 +138,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 5250298d28170..6b11c93d6750a 100644
32 @@ -3169,6 +3169,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 a154cab6cd989..52776d48e306a 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -635,6 +635,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 cf871a81f4fdc..bc5095b734f58 100644
85 @@ -1320,7 +1320,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 659a8f39c61af..1283670737826 100644
120 @@ -808,6 +808,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 1cb616fc11053..02ce64c28ef15 100644
163 --- a/include/linux/fs.h
164 +++ b/include/linux/fs.h
165 @@ -1378,6 +1378,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 @@ -2091,6 +2092,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 @@ -2614,6 +2616,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 @@ -2777,6 +2780,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 2270ec68f10a1..fbb8e650c1749 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 static 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 13eda8de29981..24fd5e986cb79 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 ad667dbc96f5c..d50423613c8ed 100644
300 --- a/fs/proc/task_mmu.c
301 +++ b/fs/proc/task_mmu.c
302 @@ -280,7 +280,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 @@ -1869,7 +1872,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 a7e4a9e7d807a..30699240b45d6 100644
341 --- a/include/linux/mm.h
342 +++ b/include/linux/mm.h
343 @@ -1926,6 +1926,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 c3a6e62096006..45f5754d51cd1 100644
374 --- a/include/linux/mm_types.h
375 +++ b/include/linux/mm_types.h
376 @@ -370,6 +370,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 @@ -449,6 +450,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 3244cc56b697d..ae63cce182fdc 100644
396 @@ -572,7 +572,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 d6c0042e3aa0d..1f11c655a632b 100644
409 @@ -52,7 +52,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 daa0e23a6ee66..1c1f517516f26 100644
422 @@ -3358,7 +3358,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 (page->mapping != mapping) {
431 diff --git a/mm/mmap.c b/mm/mmap.c
432 index bfb0ea164a90a..6bbc17d4733df 100644
435 @@ -183,7 +183,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 @@ -952,7 +952,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 @@ -1872,7 +1872,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 @@ -2730,7 +2730,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 @@ -2749,7 +2749,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 @@ -2944,7 +2944,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 @@ -3000,10 +3000,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 @@ -3284,7 +3301,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 bc5095b734f58..9508bd57a3bc0 100644
670 @@ -1425,6 +1425,7 @@ void d_walk(struct dentry *parent, void *data,
674 +EXPORT_SYMBOL_GPL(d_walk);
677 struct vfsmount *mnt;
678 @@ -2970,6 +2971,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 537d92c41105b..0ab811e0fdaae 100644
690 @@ -111,6 +111,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 45437f8e1003e..786af52904fcf 100644
712 --- a/fs/file_table.c
713 +++ b/fs/file_table.c
714 @@ -161,6 +161,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 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
726 +EXPORT_SYMBOL_GPL(__fput_sync);
728 void __init files_init(void)
730 diff --git a/fs/namespace.c b/fs/namespace.c
731 index 1283670737826..db99365620118 100644
734 @@ -439,6 +439,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
735 mnt_dec_writers(real_mount(mnt));
738 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
741 * mnt_drop_write - give up write access to a mount
742 @@ -813,6 +814,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
744 return check_mnt(real_mount(mnt));
746 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
749 * vfsmount lock must be held for write
750 @@ -2011,6 +2013,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
754 +EXPORT_SYMBOL_GPL(iterate_mounts);
756 static void lock_mnt_tree(struct mount *mnt)
758 diff --git a/fs/notify/group.c b/fs/notify/group.c
759 index 6a297efc47887..ed394ccb10e00 100644
760 --- a/fs/notify/group.c
761 +++ b/fs/notify/group.c
762 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
764 refcount_inc(&group->refcnt);
766 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
769 * Drop a reference to a group. Free it if it's through.
770 diff --git a/fs/open.c b/fs/open.c
771 index f732fb94600ce..ca33d86e73fd2 100644
774 @@ -65,6 +65,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
775 inode_unlock(dentry->d_inode);
778 +EXPORT_SYMBOL_GPL(do_truncate);
780 long vfs_truncate(const struct path *path, loff_t length)
782 diff --git a/fs/read_write.c b/fs/read_write.c
783 index 0074afa7ecb3e..612cf04d9f6b9 100644
784 --- a/fs/read_write.c
785 +++ b/fs/read_write.c
786 @@ -488,6 +488,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
790 +EXPORT_SYMBOL_GPL(vfs_read);
792 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
794 @@ -598,6 +599,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
795 file_end_write(file);
798 +EXPORT_SYMBOL_GPL(vfs_write);
800 /* file_ppos returns &file->f_pos or NULL if file is stream */
801 static inline loff_t *file_ppos(struct file *file)
802 diff --git a/fs/splice.c b/fs/splice.c
803 index 3e6ba363b7775..7c1be373eb7cd 100644
806 @@ -766,6 +766,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
807 return warn_unsupported(out, "write");
808 return out->f_op->splice_write(pipe, out, ppos, len, flags);
810 +EXPORT_SYMBOL_GPL(do_splice_from);
813 * Attempt to initiate a splice from a file to a pipe.
814 @@ -795,6 +796,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
815 return warn_unsupported(in, "read");
816 return in->f_op->splice_read(in, ppos, pipe, len, flags);
818 +EXPORT_SYMBOL_GPL(do_splice_to);
821 * splice_direct_to_actor - splices data directly between two non-pipes
822 diff --git a/fs/xattr.c b/fs/xattr.c
823 index 5c8c5175b385c..ff7e9ff774b73 100644
826 @@ -384,6 +384,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
827 *xattr_value = value;
830 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
833 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
834 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
835 index fbb8e650c1749..49c4d11b08938 100644
836 --- a/kernel/locking/lockdep.c
837 +++ b/kernel/locking/lockdep.c
838 @@ -210,6 +210,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
840 return lock_classes + class_idx;
842 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
843 #define hlock_class(hlock) lockdep_hlock_class(hlock)
845 #ifdef CONFIG_LOCK_STAT
846 diff --git a/kernel/task_work.c b/kernel/task_work.c
847 index 1698fbe6f0e13..081b05acadf82 100644
848 --- a/kernel/task_work.c
849 +++ b/kernel/task_work.c
850 @@ -167,3 +167,4 @@ void task_work_run(void)
854 +EXPORT_SYMBOL_GPL(task_work_run);
855 diff --git a/security/security.c b/security/security.c
856 index c88167a414b41..125724525d5c0 100644
857 --- a/security/security.c
858 +++ b/security/security.c
859 @@ -1148,6 +1148,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
861 return call_int_hook(path_rmdir, 0, dir, dentry);
863 +EXPORT_SYMBOL_GPL(security_path_rmdir);
865 int security_path_unlink(const struct path *dir, struct dentry *dentry)
867 @@ -1164,6 +1165,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
869 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
871 +EXPORT_SYMBOL_GPL(security_path_symlink);
873 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
874 struct dentry *new_dentry)
875 @@ -1172,6 +1174,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
877 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
879 +EXPORT_SYMBOL_GPL(security_path_link);
881 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
882 const struct path *new_dir, struct dentry *new_dentry,
883 @@ -1199,6 +1202,7 @@ int security_path_truncate(const struct path *path)
885 return call_int_hook(path_truncate, 0, path);
887 +EXPORT_SYMBOL_GPL(security_path_truncate);
889 int security_path_chmod(const struct path *path, umode_t mode)
891 @@ -1206,6 +1210,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
893 return call_int_hook(path_chmod, 0, path, mode);
895 +EXPORT_SYMBOL_GPL(security_path_chmod);
897 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
899 @@ -1213,6 +1218,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
901 return call_int_hook(path_chown, 0, path, uid, gid);
903 +EXPORT_SYMBOL_GPL(security_path_chown);
905 int security_path_chroot(const struct path *path)
907 @@ -1313,6 +1319,7 @@ int security_inode_permission(struct inode *inode, int mask)
909 return call_int_hook(inode_permission, 0, inode, mask);
911 +EXPORT_SYMBOL_GPL(security_inode_permission);
913 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
915 @@ -1510,6 +1517,7 @@ int security_file_permission(struct file *file, int mask)
917 return fsnotify_perm(file, mask);
919 +EXPORT_SYMBOL_GPL(security_file_permission);
921 int security_file_alloc(struct file *file)
923 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
924 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
925 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-12-03 15:38:59.926647310 +0100
927 +What: /debug/aufs/si_<id>/
929 +Contact: J. R. Okajima <hooanon05g@gmail.com>
931 + Under /debug/aufs, a directory named si_<id> is created
932 + per aufs mount, where <id> is a unique id generated
935 +What: /debug/aufs/si_<id>/plink
937 +Contact: J. R. Okajima <hooanon05g@gmail.com>
939 + It has three lines and shows the information about the
940 + pseudo-link. The first line is a single number
941 + representing a number of buckets. The second line is a
942 + number of pseudo-links per buckets (separated by a
943 + blank). The last line is a single number representing a
944 + total number of psedo-links.
945 + When the aufs mount option 'noplink' is specified, it
946 + will show "1\n0\n0\n".
948 +What: /debug/aufs/si_<id>/xib
950 +Contact: J. R. Okajima <hooanon05g@gmail.com>
952 + It shows the consumed blocks by xib (External Inode Number
953 + Bitmap), its block size and file size.
954 + When the aufs mount option 'noxino' is specified, it
955 + will be empty. About XINO files, see the aufs manual.
957 +What: /debug/aufs/si_<id>/xi<branch-index>
959 +Contact: J. R. Okajima <hooanon05g@gmail.com>
961 + It shows the consumed blocks by xino (External Inode Number
962 + Translation Table), its link count, block size and file
964 + Due to the file size limit, there may exist multiple
965 + xino files per branch. In this case, "-N" is added to
966 + the filename and it corresponds to the index of the
967 + internal xino array. "-0" is omitted.
968 + When the aufs mount option 'noxino' is specified, Those
969 + entries won't exist. About XINO files, see the aufs
972 +What: /debug/aufs/si_<id>/xigen
974 +Contact: J. R. Okajima <hooanon05g@gmail.com>
976 + It shows the consumed blocks by xigen (External Inode
977 + Generation Table), its block size and file size.
978 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
980 + When the aufs mount option 'noxino' is specified, it
981 + will be empty. About XINO files, see the aufs manual.
982 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
983 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
984 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-12-03 15:38:59.926647310 +0100
986 +What: /sys/fs/aufs/si_<id>/
988 +Contact: J. R. Okajima <hooanon05g@gmail.com>
990 + Under /sys/fs/aufs, a directory named si_<id> is created
991 + per aufs mount, where <id> is a unique id generated
994 +What: /sys/fs/aufs/si_<id>/br<idx>
996 +Contact: J. R. Okajima <hooanon05g@gmail.com>
998 + It shows the abolute path of a member directory (which
999 + is called branch) in aufs, and its permission.
1001 +What: /sys/fs/aufs/si_<id>/brid<idx>
1003 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1005 + It shows the id of a member directory (which is called
1008 +What: /sys/fs/aufs/si_<id>/xi_path
1010 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1012 + It shows the abolute path of XINO (External Inode Number
1013 + Bitmap, Translation Table and Generation Table) file
1014 + even if it is the default path.
1015 + When the aufs mount option 'noxino' is specified, it
1016 + will be empty. About XINO files, see the aufs manual.
1017 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1018 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1019 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-12-03 15:38:59.929980643 +0100
1022 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1024 +# This program is free software; you can redistribute it and/or modify
1025 +# it under the terms of the GNU General Public License as published by
1026 +# the Free Software Foundation; either version 2 of the License, or
1027 +# (at your option) any later version.
1029 +# This program is distributed in the hope that it will be useful,
1030 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1031 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1032 +# GNU General Public License for more details.
1034 +# You should have received a copy of the GNU General Public License
1035 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1038 +----------------------------------------
1040 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1041 +1. abbrev. for "advanced multi-layered unification filesystem".
1042 +2. abbrev. for "another unionfs".
1043 +3. abbrev. for "auf das" in German which means "on the" in English.
1044 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1045 + But "Filesystem aufs Filesystem" is hard to understand.
1046 +4. abbrev. for "African Urban Fashion Show".
1048 +AUFS is a filesystem with features:
1049 +- multi layered stackable unification filesystem, the member directory
1050 + is called as a branch.
1051 +- branch permission and attribute, 'readonly', 'real-readonly',
1052 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1054 +- internal "file copy-on-write".
1055 +- logical deletion, whiteout.
1056 +- dynamic branch manipulation, adding, deleting and changing permission.
1057 +- allow bypassing aufs, user's direct branch access.
1058 +- external inode number translation table and bitmap which maintains the
1059 + persistent aufs inode number.
1060 +- seekable directory, including NFS readdir.
1061 +- file mapping, mmap and sharing pages.
1062 +- pseudo-link, hardlink over branches.
1063 +- loopback mounted filesystem as a branch.
1064 +- several policies to select one among multiple writable branches.
1065 +- revert a single systemcall when an error occurs in aufs.
1069 +Multi Layered Stackable Unification Filesystem
1070 +----------------------------------------------------------------------
1071 +Most people already knows what it is.
1072 +It is a filesystem which unifies several directories and provides a
1073 +merged single directory. When users access a file, the access will be
1074 +passed/re-directed/converted (sorry, I am not sure which English word is
1075 +correct) to the real file on the member filesystem. The member
1076 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1077 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1078 +readonly branch is handled by creating 'whiteout' on the upper writable
1081 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1082 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1083 +different approaches to implement the merged-view.
1084 +The former tries putting it into VFS, and the latter implements as a
1085 +separate filesystem.
1086 +(If I misunderstand about these implementations, please let me know and
1087 +I shall correct it. Because it is a long time ago when I read their
1088 +source files last time).
1090 +UnionMount's approach will be able to small, but may be hard to share
1091 +branches between several UnionMount since the whiteout in it is
1092 +implemented in the inode on branch filesystem and always
1093 +shared. According to Bharata's post, readdir does not seems to be
1095 +There are several missing features known in this implementations such as
1096 +- for users, the inode number may change silently. eg. copy-up.
1097 +- link(2) may break by copy-up.
1098 +- read(2) may get an obsoleted filedata (fstat(2) too).
1099 +- fcntl(F_SETLK) may be broken by copy-up.
1100 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1103 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1104 +merged into mainline. This is another implementation of UnionMount as a
1105 +separated filesystem. All the limitations and known problems which
1106 +UnionMount are equally inherited to "overlay" filesystem.
1108 +Unionfs has a longer history. When I started implementing a stackable
1109 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1110 +inode, dentry and file objects and they have an array pointing lower
1111 +same kind objects. After contributing many patches for Unionfs, I
1112 +re-started my project AUFS (Jun 2006).
1114 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1115 +implemented my own ideas, approaches and enhancements and it became
1116 +totally different one.
1118 +Comparing DM snapshot and fs based implementation
1119 +- the number of bytes to be copied between devices is much smaller.
1120 +- the type of filesystem must be one and only.
1121 +- the fs must be writable, no readonly fs, even for the lower original
1122 + device. so the compression fs will not be usable. but if we use
1123 + loopback mount, we may address this issue.
1125 + mount /cdrom/squashfs.img /sq
1126 + losetup /sq/ext2.img
1127 + losetup /somewhere/cow
1128 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1129 +- it will be difficult (or needs more operations) to extract the
1130 + difference between the original device and COW.
1131 +- DM snapshot-merge may help a lot when users try merging. in the
1132 + fs-layer union, users will use rsync(1).
1134 +You may want to read my old paper "Filesystems in LiveCD"
1135 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1138 +Several characters/aspects/persona of aufs
1139 +----------------------------------------------------------------------
1141 +Aufs has several characters, aspects or persona.
1142 +1. a filesystem, callee of VFS helper
1143 +2. sub-VFS, caller of VFS helper for branches
1144 +3. a virtual filesystem which maintains persistent inode number
1145 +4. reader/writer of files on branches such like an application
1147 +1. Callee of VFS Helper
1148 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1149 +unlink(2) from an application reaches sys_unlink() kernel function and
1150 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1151 +calls filesystem specific unlink operation. Actually aufs implements the
1152 +unlink operation but it behaves like a redirector.
1154 +2. Caller of VFS Helper for Branches
1155 +aufs_unlink() passes the unlink request to the branch filesystem as if
1156 +it were called from VFS. So the called unlink operation of the branch
1157 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1158 +every necessary pre/post operation for the branch filesystem.
1159 +- acquire the lock for the parent dir on a branch
1160 +- lookup in a branch
1161 +- revalidate dentry on a branch
1162 +- mnt_want_write() for a branch
1163 +- vfs_unlink() for a branch
1164 +- mnt_drop_write() for a branch
1165 +- release the lock on a branch
1167 +3. Persistent Inode Number
1168 +One of the most important issue for a filesystem is to maintain inode
1169 +numbers. This is particularly important to support exporting a
1170 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1171 +backend block device for its own. But some storage is necessary to
1172 +keep and maintain the inode numbers. It may be a large space and may not
1173 +suit to keep in memory. Aufs rents some space from its first writable
1174 +branch filesystem (by default) and creates file(s) on it. These files
1175 +are created by aufs internally and removed soon (currently) keeping
1177 +Note: Because these files are removed, they are totally gone after
1178 + unmounting aufs. It means the inode numbers are not persistent
1179 + across unmount or reboot. I have a plan to make them really
1180 + persistent which will be important for aufs on NFS server.
1182 +4. Read/Write Files Internally (copy-on-write)
1183 +Because a branch can be readonly, when you write a file on it, aufs will
1184 +"copy-up" it to the upper writable branch internally. And then write the
1185 +originally requested thing to the file. Generally kernel doesn't
1186 +open/read/write file actively. In aufs, even a single write may cause a
1187 +internal "file copy". This behaviour is very similar to cp(1) command.
1189 +Some people may think it is better to pass such work to user space
1190 +helper, instead of doing in kernel space. Actually I am still thinking
1191 +about it. But currently I have implemented it in kernel space.
1192 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1193 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1194 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-12-03 15:38:59.929980643 +0100
1197 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1199 +# This program is free software; you can redistribute it and/or modify
1200 +# it under the terms of the GNU General Public License as published by
1201 +# the Free Software Foundation; either version 2 of the License, or
1202 +# (at your option) any later version.
1204 +# This program is distributed in the hope that it will be useful,
1205 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1206 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1207 +# GNU General Public License for more details.
1209 +# You should have received a copy of the GNU General Public License
1210 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1212 +Basic Aufs Internal Structure
1214 +Superblock/Inode/Dentry/File Objects
1215 +----------------------------------------------------------------------
1216 +As like an ordinary filesystem, aufs has its own
1217 +superblock/inode/dentry/file objects. All these objects have a
1218 +dynamically allocated array and store the same kind of pointers to the
1219 +lower filesystem, branch.
1220 +For example, when you build a union with one readwrite branch and one
1221 +readonly, mounted /au, /rw and /ro respectively.
1223 +- /ro/fileA exists but /rw/fileA
1225 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1226 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1227 +- [0] = NULL (because /rw/fileA doesn't exist)
1230 +This style of an array is essentially same to the aufs
1231 +superblock/inode/dentry/file objects.
1233 +Because aufs supports manipulating branches, ie. add/delete/change
1234 +branches dynamically, these objects has its own generation. When
1235 +branches are changed, the generation in aufs superblock is
1236 +incremented. And a generation in other object are compared when it is
1237 +accessed. When a generation in other objects are obsoleted, aufs
1238 +refreshes the internal array.
1242 +----------------------------------------------------------------------
1243 +Additionally aufs superblock has some data for policies to select one
1244 +among multiple writable branches, XIB files, pseudo-links and kobject.
1245 +See below in detail.
1246 +About the policies which supports copy-down a directory, see
1247 +wbr_policy.txt too.
1250 +Branch and XINO(External Inode Number Translation Table)
1251 +----------------------------------------------------------------------
1252 +Every branch has its own xino (external inode number translation table)
1253 +file. The xino file is created and unlinked by aufs internally. When two
1254 +members of a union exist on the same filesystem, they share the single
1256 +The struct of a xino file is simple, just a sequence of aufs inode
1257 +numbers which is indexed by the lower inode number.
1258 +In the above sample, assume the inode number of /ro/fileA is i111 and
1259 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1260 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1262 +When the inode numbers are not contiguous, the xino file will be sparse
1263 +which has a hole in it and doesn't consume as much disk space as it
1264 +might appear. If your branch filesystem consumes disk space for such
1265 +holes, then you should specify 'xino=' option at mounting aufs.
1267 +Aufs has a mount option to free the disk blocks for such holes in XINO
1268 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1269 +meet a problem of disk shortage due to XINO files, then you should try
1270 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1271 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1272 +the holes in XINO files.
1274 +Also a writable branch has three kinds of "whiteout bases". All these
1275 +are existed when the branch is joined to aufs, and their names are
1276 +whiteout-ed doubly, so that users will never see their names in aufs
1278 +1. a regular file which will be hardlinked to all whiteouts.
1279 +2. a directory to store a pseudo-link.
1280 +3. a directory to store an "orphan"-ed file temporary.
1283 + When you remove a file on a readonly branch, aufs handles it as a
1284 + logical deletion and creates a whiteout on the upper writable branch
1285 + as a hardlink of this file in order not to consume inode on the
1288 + See below, Pseudo-link.
1290 + When "fileC" exists on the lower readonly branch only and it is
1291 + opened and removed with its parent dir, and then user writes
1292 + something into it, then aufs copies-up fileC to this
1293 + directory. Because there is no other dir to store fileC. After
1294 + creating a file under this dir, the file is unlinked.
1296 +Because aufs supports manipulating branches, ie. add/delete/change
1297 +dynamically, a branch has its own id. When the branch order changes,
1298 +aufs finds the new index by searching the branch id.
1302 +----------------------------------------------------------------------
1303 +Assume "fileA" exists on the lower readonly branch only and it is
1304 +hardlinked to "fileB" on the branch. When you write something to fileA,
1305 +aufs copies-up it to the upper writable branch. Additionally aufs
1306 +creates a hardlink under the Pseudo-link Directory of the writable
1307 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1308 +simple list. If fileB is read after unlinking fileA, aufs returns
1309 +filedata from the pseudo-link instead of the lower readonly
1310 +branch. Because the pseudo-link is based upon the inode, to keep the
1311 +inode number by xino (see above) is essentially necessary.
1313 +All the hardlinks under the Pseudo-link Directory of the writable branch
1314 +should be restored in a proper location later. Aufs provides a utility
1315 +to do this. The userspace helpers executed at remounting and unmounting
1317 +During this utility is running, it puts aufs into the pseudo-link
1318 +maintenance mode. In this mode, only the process which began the
1319 +maintenance mode (and its child processes) is allowed to operate in
1320 +aufs. Some other processes which are not related to the pseudo-link will
1321 +be allowed to run too, but the rest have to return an error or wait
1322 +until the maintenance mode ends. If a process already acquires an inode
1323 +mutex (in VFS), it has to return an error.
1326 +XIB(external inode number bitmap)
1327 +----------------------------------------------------------------------
1328 +Addition to the xino file per a branch, aufs has an external inode number
1329 +bitmap in a superblock object. It is also an internal file such like a
1331 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1333 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1335 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1336 +reduce the number of consumed disk blocks for these files.
1339 +Virtual or Vertical Dir, and Readdir in Userspace
1340 +----------------------------------------------------------------------
1341 +In order to support multiple layers (branches), aufs readdir operation
1342 +constructs a virtual dir block on memory. For readdir, aufs calls
1343 +vfs_readdir() internally for each dir on branches, merges their entries
1344 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1345 +object. So the file object has its entry list until it is closed. The
1346 +entry list will be updated when the file position is zero and becomes
1347 +obsoleted. This decision is made in aufs automatically.
1349 +The dynamically allocated memory block for the name of entries has a
1350 +unit of 512 bytes (by default) and stores the names contiguously (no
1351 +padding). Another block for each entry is handled by kmem_cache too.
1352 +During building dir blocks, aufs creates hash list and judging whether
1353 +the entry is whiteouted by its upper branch or already listed.
1354 +The merged result is cached in the corresponding inode object and
1355 +maintained by a customizable life-time option.
1357 +Some people may call it can be a security hole or invite DoS attack
1358 +since the opened and once readdir-ed dir (file object) holds its entry
1359 +list and becomes a pressure for system memory. But I'd say it is similar
1360 +to files under /proc or /sys. The virtual files in them also holds a
1361 +memory page (generally) while they are opened. When an idea to reduce
1362 +memory for them is introduced, it will be applied to aufs too.
1363 +For those who really hate this situation, I've developed readdir(3)
1364 +library which operates this merging in userspace. You just need to set
1365 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1366 +kernel space for readdir(3).
1370 +----------------------------------------------------------------------
1371 +Aufs sometimes requires privilege access to a branch. For instance,
1372 +in copy-up/down operation. When a user process is going to make changes
1373 +to a file which exists in the lower readonly branch only, and the mode
1374 +of one of ancestor directories may not be writable by a user
1375 +process. Here aufs copy-up the file with its ancestors and they may
1376 +require privilege to set its owner/group/mode/etc.
1377 +This is a typical case of a application character of aufs (see
1380 +Aufs uses workqueue synchronously for this case. It creates its own
1381 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1382 +passes the request to call mkdir or write (for example), and wait for
1383 +its completion. This approach solves a problem of a signal handler
1385 +If aufs didn't adopt the workqueue and changed the privilege of the
1386 +process, then the process may receive the unexpected SIGXFSZ or other
1389 +Also aufs uses the system global workqueue ("events" kernel thread) too
1390 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1391 +whiteout base and etc. This is unrelated to a privilege.
1392 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1393 +superblock at the beginning, at the same time waits for the completion
1394 +of all queued asynchronous tasks.
1398 +----------------------------------------------------------------------
1399 +The whiteout in aufs is very similar to Unionfs's. That is represented
1400 +by its filename. UnionMount takes an approach of a file mode, but I am
1401 +afraid several utilities (find(1) or something) will have to support it.
1403 +Basically the whiteout represents "logical deletion" which stops aufs to
1404 +lookup further, but also it represents "dir is opaque" which also stop
1407 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1408 +In order to make several functions in a single systemcall to be
1409 +revertible, aufs adopts an approach to rename a directory to a temporary
1410 +unique whiteouted name.
1411 +For example, in rename(2) dir where the target dir already existed, aufs
1412 +renames the target dir to a temporary unique whiteouted name before the
1413 +actual rename on a branch, and then handles other actions (make it opaque,
1414 +update the attributes, etc). If an error happens in these actions, aufs
1415 +simply renames the whiteouted name back and returns an error. If all are
1416 +succeeded, aufs registers a function to remove the whiteouted unique
1417 +temporary name completely and asynchronously to the system global
1422 +----------------------------------------------------------------------
1423 +It is a well-known feature or concept.
1424 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1425 +internally and makes change to the new file on the upper writable branch.
1426 +When the trigger systemcall does not update the timestamps of the parent
1427 +dir, aufs reverts it after copy-up.
1430 +Move-down (aufs3.9 and later)
1431 +----------------------------------------------------------------------
1432 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1433 +the lower readonly branch to the upper writable branch when a user
1434 +changes something about the file.
1435 +"Move-down" is an opposite action of copy-up. Basically this action is
1436 +ran manually instead of automatically and internally.
1437 +For desgin and implementation, aufs has to consider these issues.
1438 +- whiteout for the file may exist on the lower branch.
1439 +- ancestor directories may not exist on the lower branch.
1440 +- diropq for the ancestor directories may exist on the upper branch.
1441 +- free space on the lower branch will reduce.
1442 +- another access to the file may happen during moving-down, including
1443 + UDBA (see "Revalidate Dentry and UDBA").
1444 +- the file should not be hard-linked nor pseudo-linked. they should be
1445 + handled by auplink utility later.
1447 +Sometimes users want to move-down a file from the upper writable branch
1448 +to the lower readonly or writable branch. For instance,
1449 +- the free space of the upper writable branch is going to run out.
1450 +- create a new intermediate branch between the upper and lower branch.
1453 +For this purpose, use "aumvdown" command in aufs-util.git.
1454 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1455 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1456 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-12-03 15:38:59.929980643 +0100
1459 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1461 +# This program is free software; you can redistribute it and/or modify
1462 +# it under the terms of the GNU General Public License as published by
1463 +# the Free Software Foundation; either version 2 of the License, or
1464 +# (at your option) any later version.
1466 +# This program is distributed in the hope that it will be useful,
1467 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1468 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1469 +# GNU General Public License for more details.
1471 +# You should have received a copy of the GNU General Public License
1472 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1474 +Support for a branch who has its ->atomic_open()
1475 +----------------------------------------------------------------------
1476 +The filesystems who implement its ->atomic_open() are not majority. For
1477 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1478 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1479 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1480 +sure whether all filesystems who have ->atomic_open() behave like this,
1481 +but NFSv4 surely returns the error.
1483 +In order to support ->atomic_open() for aufs, there are a few
1486 +A. Introduce aufs_atomic_open()
1487 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1489 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1490 + an aufs user Pip Cet's approach
1491 + - calls aufs_create(), VFS finish_open() and notify_change().
1492 + - pass fake-mode to finish_open(), and then correct the mode by
1494 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1495 + - no aufs_atomic_open().
1496 + - aufs_lookup() registers the TID to an aufs internal object.
1497 + - aufs_create() does nothing when the matching TID is registered, but
1498 + registers the mode.
1499 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1500 + TID is registered.
1501 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1503 + - no aufs_atomic_open().
1504 + - aufs_create() registers the TID to an internal object. this info
1505 + represents "this process created this file just now."
1506 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1507 + registered TID and re-try open() with superuser's credential.
1509 +Pros and cons for each approach.
1512 + - straightforward but highly depends upon VFS internal.
1513 + - the atomic behavaiour is kept.
1514 + - some of parameters such as nameidata are hard to reproduce for
1518 + - easy to implement.
1519 + - the atomic behavaiour is lost.
1521 + - the atomic behavaiour is kept.
1522 + - dirty and tricky.
1523 + - VFS checks whether the file is created correctly after calling
1524 + ->create(), which means this approach doesn't work.
1526 + - easy to implement.
1527 + - the atomic behavaiour is lost.
1528 + - to open a file with superuser's credential and give it to a user
1529 + process is a bad idea, since the file object keeps the credential
1530 + in it. It may affect LSM or something. This approach doesn't work
1533 +The approach A is ideal, but it hard to implement. So here is a
1534 +variation of A, which is to be implemented.
1536 +A-1. Introduce aufs_atomic_open()
1537 + - calls branch fs ->atomic_open() if exists. otherwise calls
1538 + vfs_create() and finish_open().
1539 + - the demerit is that the several checks after branch fs
1540 + ->atomic_open() are lost. in the ordinary case, the checks are
1541 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1542 + be implemented in aufs, but not all I am afraid.
1543 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1544 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1545 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-12-03 15:38:59.929980643 +0100
1548 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1550 +# This program is free software; you can redistribute it and/or modify
1551 +# it under the terms of the GNU General Public License as published by
1552 +# the Free Software Foundation; either version 2 of the License, or
1553 +# (at your option) any later version.
1555 +# This program is distributed in the hope that it will be useful,
1556 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1557 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1558 +# GNU General Public License for more details.
1560 +# You should have received a copy of the GNU General Public License
1561 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1564 +----------------------------------------------------------------------
1565 +Since aufs has a character of sub-VFS (see Introduction), it operates
1566 +lookup for branches as VFS does. It may be a heavy work. But almost all
1567 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1568 +directly connected to its parent. Digging down the directory hierarchy
1569 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1572 +When a branch is a remote filesystem, aufs basically relies upon its
1573 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1575 +For d_revalidate, aufs implements three levels of revalidate tests. See
1576 +"Revalidate Dentry and UDBA" in detail.
1579 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1580 +----------------------------------------------------------------------
1581 +Let's try case study.
1582 +- aufs has two branches, upper readwrite and lower readonly.
1584 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1585 +- user invoked "chmod a+rx /au/dirA"
1586 +- the internal copy-up is activated and "/rw/dirA" is created and its
1587 + permission bits are set to world readable.
1588 +- then "/au/dirA" becomes world readable?
1590 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1591 +or it may be a natively readonly filesystem. If aufs respects the lower
1592 +branch, it should not respond readdir request from other users. But user
1593 +allowed it by chmod. Should really aufs rejects showing the entries
1596 +To be honest, I don't have a good solution for this case. So aufs
1597 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1599 +When dirperm1 is specified, aufs checks only the highest one for the
1600 +directory permission, and shows the entries. Otherwise, as usual, checks
1601 +every dir existing on all branches and rejects the request.
1603 +As a side effect, dirperm1 option improves the performance of aufs
1604 +because the number of permission check is reduced when the number of
1608 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1609 +----------------------------------------------------------------------
1610 +Generally VFS helpers re-validate a dentry as a part of lookup.
1611 +0. digging down the directory hierarchy.
1612 +1. lock the parent dir by its i_mutex.
1613 +2. lookup the final (child) entry.
1615 +4. call the actual operation (create, unlink, etc.)
1616 +5. unlock the parent dir
1618 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1619 +called. Actually aufs implements it and checks the dentry on a branch is
1621 +But it is not enough. Because aufs has to release the lock for the
1622 +parent dir on a branch at the end of ->lookup() (step 2) and
1623 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1625 +If the file on a branch is changed directly, eg. bypassing aufs, after
1626 +aufs released the lock, then the subsequent operation may cause
1627 +something unpleasant result.
1629 +This situation is a result of VFS architecture, ->lookup() and
1630 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1631 +design from VFS's point of view. It is just not suitable for sub-VFS
1634 +Aufs supports such case by three level of revalidation which is
1635 +selectable by user.
1636 +1. Simple Revalidate
1637 + Addition to the native flow in VFS's, confirm the child-parent
1638 + relationship on the branch just after locking the parent dir on the
1639 + branch in the "actual operation" (step 4). When this validation
1640 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1641 + checks the validation of the dentry on branches.
1642 +2. Monitor Changes Internally by Inotify/Fsnotify
1643 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1644 + the dentry on the branch, and returns EBUSY if it finds different
1646 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1647 + during it is in cache. When the event is notified, aufs registers a
1648 + function to kernel 'events' thread by schedule_work(). And the
1649 + function sets some special status to the cached aufs dentry and inode
1650 + private data. If they are not cached, then aufs has nothing to
1651 + do. When the same file is accessed through aufs (step 0-3) later,
1652 + aufs will detect the status and refresh all necessary data.
1653 + In this mode, aufs has to ignore the event which is fired by aufs
1655 +3. No Extra Validation
1656 + This is the simplest test and doesn't add any additional revalidation
1657 + test, and skip the revalidation in step 4. It is useful and improves
1658 + aufs performance when system surely hide the aufs branches from user,
1659 + by over-mounting something (or another method).
1660 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1661 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1662 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-12-03 15:38:59.929980643 +0100
1665 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1667 +# This program is free software; you can redistribute it and/or modify
1668 +# it under the terms of the GNU General Public License as published by
1669 +# the Free Software Foundation; either version 2 of the License, or
1670 +# (at your option) any later version.
1672 +# This program is distributed in the hope that it will be useful,
1673 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1674 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1675 +# GNU General Public License for more details.
1677 +# You should have received a copy of the GNU General Public License
1678 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1680 +Branch Manipulation
1682 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1683 +and changing its permission/attribute, there are a lot of works to do.
1687 +----------------------------------------------------------------------
1688 +o Confirm the adding dir exists outside of aufs, including loopback
1689 + mount, and its various attributes.
1690 +o Initialize the xino file and whiteout bases if necessary.
1693 +o Check the owner/group/mode of the directory
1694 + When the owner/group/mode of the adding directory differs from the
1695 + existing branch, aufs issues a warning because it may impose a
1697 + For example, when a upper writable branch has a world writable empty
1698 + top directory, a malicious user can create any files on the writable
1699 + branch directly, like copy-up and modify manually. If something like
1700 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1701 + writable branch, and the writable branch is world-writable, then a
1702 + malicious guy may create /etc/passwd on the writable branch directly
1703 + and the infected file will be valid in aufs.
1704 + I am afraid it can be a security issue, but aufs can do nothing except
1705 + producing a warning.
1709 +----------------------------------------------------------------------
1710 +o Confirm the deleting branch is not busy
1711 + To be general, there is one merit to adopt "remount" interface to
1712 + manipulate branches. It is to discard caches. At deleting a branch,
1713 + aufs checks the still cached (and connected) dentries and inodes. If
1714 + there are any, then they are all in-use. An inode without its
1715 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1717 + For the cached one, aufs checks whether the same named entry exists on
1719 + If the cached one is a directory, because aufs provides a merged view
1720 + to users, as long as one dir is left on any branch aufs can show the
1721 + dir to users. In this case, the branch can be removed from aufs.
1722 + Otherwise aufs rejects deleting the branch.
1724 + If any file on the deleting branch is opened by aufs, then aufs
1728 +Modify the Permission of a Branch
1729 +----------------------------------------------------------------------
1730 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1733 +o rw --> ro: Confirm the modifying branch is not busy
1734 + Aufs rejects the request if any of these conditions are true.
1735 + - a file on the branch is mmap-ed.
1736 + - a regular file on the branch is opened for write and there is no
1737 + same named entry on the upper branch.
1738 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1739 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1740 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-12-03 15:38:59.929980643 +0100
1743 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1745 +# This program is free software; you can redistribute it and/or modify
1746 +# it under the terms of the GNU General Public License as published by
1747 +# the Free Software Foundation; either version 2 of the License, or
1748 +# (at your option) any later version.
1750 +# This program is distributed in the hope that it will be useful,
1751 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1752 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1753 +# GNU General Public License for more details.
1755 +# You should have received a copy of the GNU General Public License
1756 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1758 +Policies to Select One among Multiple Writable Branches
1759 +----------------------------------------------------------------------
1760 +When the number of writable branch is more than one, aufs has to decide
1761 +the target branch for file creation or copy-up. By default, the highest
1762 +writable branch which has the parent (or ancestor) dir of the target
1763 +file is chosen (top-down-parent policy).
1764 +By user's request, aufs implements some other policies to select the
1765 +writable branch, for file creation several policies, round-robin,
1766 +most-free-space, and other policies. For copy-up, top-down-parent,
1767 +bottom-up-parent, bottom-up and others.
1769 +As expected, the round-robin policy selects the branch in circular. When
1770 +you have two writable branches and creates 10 new files, 5 files will be
1771 +created for each branch. mkdir(2) systemcall is an exception. When you
1772 +create 10 new directories, all will be created on the same branch.
1773 +And the most-free-space policy selects the one which has most free
1774 +space among the writable branches. The amount of free space will be
1775 +checked by aufs internally, and users can specify its time interval.
1777 +The policies for copy-up is more simple,
1778 +top-down-parent is equivalent to the same named on in create policy,
1779 +bottom-up-parent selects the writable branch where the parent dir
1780 +exists and the nearest upper one from the copyup-source,
1781 +bottom-up selects the nearest upper writable branch from the
1782 +copyup-source, regardless the existence of the parent dir.
1784 +There are some rules or exceptions to apply these policies.
1785 +- If there is a readonly branch above the policy-selected branch and
1786 + the parent dir is marked as opaque (a variation of whiteout), or the
1787 + target (creating) file is whiteout-ed on the upper readonly branch,
1788 + then the result of the policy is ignored and the target file will be
1789 + created on the nearest upper writable branch than the readonly branch.
1790 +- If there is a writable branch above the policy-selected branch and
1791 + the parent dir is marked as opaque or the target file is whiteouted
1792 + on the branch, then the result of the policy is ignored and the target
1793 + file will be created on the highest one among the upper writable
1794 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1796 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1797 + They try selecting the branch where the source exists as possible
1798 + since copyup a large file will take long time. If it can't be,
1799 + ie. the branch where the source exists is readonly, then they will
1800 + follow the copyup policy.
1801 +- There is an exception for rename(2) when the target exists.
1802 + If the rename target exists, aufs compares the index of the branches
1803 + where the source and the target exists and selects the higher
1804 + one. If the selected branch is readonly, then aufs follows the
1806 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1807 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1808 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-12-03 15:38:59.929980643 +0100
1811 +// to view this graph, run dot(1) command in GRAPHVIZ.
1815 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1819 +aufs_rename -> whinfo [label="store/remove"];
1822 +inode_list [label="h_inum list in branch\ncache"];
1825 +whinode [label="h_inum list file"];
1828 +brmgmt [label="br_add/del/mod/umount"];
1830 +brmgmt -> inode_list [label="create/remove"];
1831 +brmgmt -> whinode [label="load/store"];
1833 +inode_list -> whinode [style=dashed,dir=both];
1835 +aufs_rename -> inode_list [label="add/del"];
1837 +aufs_lookup -> inode_list [label="search"];
1839 +aufs_lookup -> whinfo [label="load/remove"];
1841 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1842 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1843 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-12-03 15:38:59.929980643 +0100
1846 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1848 +# This program is free software; you can redistribute it and/or modify
1849 +# it under the terms of the GNU General Public License as published by
1850 +# the Free Software Foundation; either version 2 of the License, or
1851 +# (at your option) any later version.
1853 +# This program is distributed in the hope that it will be useful,
1854 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1855 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1856 +# GNU General Public License for more details.
1858 +# You should have received a copy of the GNU General Public License
1859 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1861 +Special handling for renaming a directory (DIRREN)
1862 +----------------------------------------------------------------------
1863 +First, let's assume we have a simple usecase.
1867 +- /ro/dirA and /ro/dirA/file exist too
1868 +- there is no dirB on both branches
1869 +- a user issues rename("dirA", "dirB")
1871 +Now, what should aufs behave against this rename(2)?
1872 +There are a few possible cases.
1875 + since dirA exists on a readonly branch which cannot be renamed.
1877 + it is possible to copy-up dirA (only the dir itself), but the child
1878 + entries ("file" in this case) should not be. it must be a bad
1879 + approach to copy-up recursively.
1880 +C. returns a success.
1881 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1882 + is a violation of aufs' policy.
1883 +D. construct an extra information which indicates that /ro/dirA should
1884 + be handled as the name of dirB.
1885 + overlayfs has a similar feature called REDIRECT.
1887 +Until now, aufs implements the case B only which returns EXDEV, and
1888 +expects the userspace application behaves like mv(1) which tries
1889 +issueing rename(2) recursively.
1891 +A new aufs feature called DIRREN is introduced which implements the case
1892 +D. There are several "extra information" added.
1894 +1. detailed info per renamed directory
1895 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1896 +2. the inode-number list of directories on a branch
1897 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1899 +The filename of "detailed info per directory" represents the lower
1900 +branch, and its format is
1901 +- a type of the branch id
1903 + + uuid (not implemented yet)
1906 +- the inode-number of the branch root dir
1908 +And it contains these info in a single regular file.
1910 +- branch's inode-number of the logically renamed dir
1911 +- the name of the before-renamed dir
1913 +The "detailed info per directory" file is created in aufs rename(2), and
1914 +loaded in any lookup.
1915 +The info is considered in lookup for the matching case only. Here
1916 +"matching" means that the root of branch (in the info filename) is same
1917 +to the current looking-up branch. After looking-up the before-renamed
1918 +name, the inode-number is compared. And the matched dentry is used.
1920 +The "inode-number list of directories" is a regular file which contains
1921 +simply the inode-numbers on the branch. The file is created or updated
1922 +in removing the branch, and loaded in adding the branch. Its lifetime is
1923 +equal to the branch.
1924 +The list is refered in lookup, and when the current target inode is
1925 +found in the list, the aufs tries loading the "detailed info per
1926 +directory" and get the changed and valid name of the dir.
1928 +Theoretically these "extra informaiton" may be able to be put into XATTR
1929 +in the dir inode. But aufs doesn't choose this way because
1930 +1. XATTR may not be supported by the branch (or its configuration)
1931 +2. XATTR may have its size limit.
1932 +3. XATTR may be less easy to convert than a regular file, when the
1933 + format of the info is changed in the future.
1934 +At the same time, I agree that the regular file approach is much slower
1935 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1938 +This DIRREN feature is enabled by aufs configuration, and is activated
1939 +by a new mount option.
1941 +For the more complicated case, there is a work with UDBA option, which
1942 +is to dected the direct access to the branches (by-passing aufs) and to
1943 +maintain the cashes in aufs. Since a single cached aufs dentry may
1944 +contains two names, before- and after-rename, the name comparision in
1945 +UDBA handler may not work correctly. In this case, the behaviour will be
1946 +equivalen to udba=reval case.
1947 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1948 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1949 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-12-03 15:38:59.929980643 +0100
1952 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1954 +# This program is free software; you can redistribute it and/or modify
1955 +# it under the terms of the GNU General Public License as published by
1956 +# the Free Software Foundation; either version 2 of the License, or
1957 +# (at your option) any later version.
1959 +# This program is distributed in the hope that it will be useful,
1960 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1961 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1962 +# GNU General Public License for more details.
1964 +# You should have received a copy of the GNU General Public License
1965 +# along with this program; if not, write to the Free Software
1966 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1969 +File-based Hierarchical Storage Management (FHSM)
1970 +----------------------------------------------------------------------
1971 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1972 +storage world. Aufs provides this feature as file-based with multiple
1973 +writable branches, based upon the principle of "Colder, the Lower".
1974 +Here the word "colder" means that the less used files, and "lower" means
1975 +that the position in the order of the stacked branches vertically.
1976 +These multiple writable branches are prioritized, ie. the topmost one
1977 +should be the fastest drive and be used heavily.
1979 +o Characters in aufs FHSM story
1980 +- aufs itself and a new branch attribute.
1981 +- a new ioctl interface to move-down and to establish a connection with
1982 + the daemon ("move-down" is a converse of "copy-up").
1983 +- userspace tool and daemon.
1985 +The userspace daemon establishes a connection with aufs and waits for
1986 +the notification. The notified information is very similar to struct
1987 +statfs containing the number of consumed blocks and inodes.
1988 +When the consumed blocks/inodes of a branch exceeds the user-specified
1989 +upper watermark, the daemon activates its move-down process until the
1990 +consumed blocks/inodes reaches the user-specified lower watermark.
1992 +The actual move-down is done by aufs based upon the request from
1993 +user-space since we need to maintain the inode number and the internal
1994 +pointer arrays in aufs.
1996 +Currently aufs FHSM handles the regular files only. Additionally they
1997 +must not be hard-linked nor pseudo-linked.
2000 +o Cowork of aufs and the user-space daemon
2001 + During the userspace daemon established the connection, aufs sends a
2002 + small notification to it whenever aufs writes something into the
2003 + writable branch. But it may cost high since aufs issues statfs(2)
2004 + internally. So user can specify a new option to cache the
2005 + info. Actually the notification is controlled by these factors.
2006 + + the specified cache time.
2007 + + classified as "force" by aufs internally.
2008 + Until the specified time expires, aufs doesn't send the info
2009 + except the forced cases. When aufs decide forcing, the info is always
2010 + notified to userspace.
2011 + For example, the number of free inodes is generally large enough and
2012 + the shortage of it happens rarely. So aufs doesn't force the
2013 + notification when creating a new file, directory and others. This is
2014 + the typical case which aufs doesn't force.
2015 + When aufs writes the actual filedata and the files consumes any of new
2016 + blocks, the aufs forces notifying.
2019 +o Interfaces in aufs
2020 +- New branch attribute.
2022 + Specifies that the branch is managed by FHSM feature. In other word,
2023 + participant in the FHSM.
2024 + When nofhsm is set to the branch, it will not be the source/target
2025 + branch of the move-down operation. This attribute is set
2026 + independently from coo and moo attributes, and if you want full
2027 + FHSM, you should specify them as well.
2028 +- New mount option.
2030 + Specifies a second to suppress many less important info to be
2033 + + AUFS_CTL_FHSM_FD
2034 + create a new file descriptor which userspace can read the notification
2035 + (a subset of struct statfs) from aufs.
2036 +- Module parameter 'brs'
2037 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2039 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2040 + When there are two or more branches with fhsm attributes,
2041 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2042 + terminates it. As a result of remounting and branch-manipulation, the
2043 + number of branches with fhsm attribute can be one. In this case,
2044 + /sbin/mount.aufs will terminate the user-space daemon.
2047 +Finally the operation is done as these steps in kernel-space.
2049 + + no one else is using the file.
2050 + + the file is not hard-linked.
2051 + + the file is not pseudo-linked.
2052 + + the file is a regular file.
2053 + + the parent dir is not opaqued.
2054 +- find the target writable branch.
2055 +- make sure the file is not whiteout-ed by the upper (than the target)
2057 +- make the parent dir on the target branch.
2058 +- mutex lock the inode on the branch.
2059 +- unlink the whiteout on the target branch (if exists).
2060 +- lookup and create the whiteout-ed temporary name on the target branch.
2061 +- copy the file as the whiteout-ed temporary name on the target branch.
2062 +- rename the whiteout-ed temporary name to the original name.
2063 +- unlink the file on the source branch.
2064 +- maintain the internal pointer array and the external inode number
2066 +- maintain the timestamps and other attributes of the parent dir and the
2069 +And of course, in every step, an error may happen. So the operation
2070 +should restore the original file state after an error happens.
2071 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2072 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2073 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-12-03 15:38:59.929980643 +0100
2076 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2078 +# This program is free software; you can redistribute it and/or modify
2079 +# it under the terms of the GNU General Public License as published by
2080 +# the Free Software Foundation; either version 2 of the License, or
2081 +# (at your option) any later version.
2083 +# This program is distributed in the hope that it will be useful,
2084 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2085 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2086 +# GNU General Public License for more details.
2088 +# You should have received a copy of the GNU General Public License
2089 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2091 +mmap(2) -- File Memory Mapping
2092 +----------------------------------------------------------------------
2093 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2094 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2096 +This approach is simple and good, but there is one problem.
2097 +Under /proc, several entries show the mmapped files by its path (with
2098 +device and inode number), and the printed path will be the path on the
2099 +branch fs's instead of virtual aufs's.
2100 +This is not a problem in most cases, but some utilities lsof(1) (and its
2101 +user) may expect the path on aufs.
2103 +To address this issue, aufs adds a new member called vm_prfile in struct
2104 +vm_area_struct (and struct vm_region). The original vm_file points to
2105 +the file on the branch fs in order to handle everything correctly as
2106 +usual. The new vm_prfile points to a virtual file in aufs, and the
2107 +show-functions in procfs refers to vm_prfile if it is set.
2108 +Also we need to maintain several other places where touching vm_file
2110 +- fork()/clone() copies vma and the reference count of vm_file is
2112 +- merging vma maintains the ref count too.
2114 +This is not a good approach. It just fakes the printed path. But it
2115 +leaves all behaviour around f_mapping unchanged. This is surely an
2117 +Actually aufs had adopted another complicated approach which calls
2118 +generic_file_mmap() and handles struct vm_operations_struct. In this
2119 +approach, aufs met a hard problem and I could not solve it without
2120 +switching the approach.
2122 +There may be one more another approach which is
2123 +- bind-mount the branch-root onto the aufs-root internally
2124 +- grab the new vfsmount (ie. struct mount)
2125 +- lazy-umount the branch-root internally
2126 +- in open(2) the aufs-file, open the branch-file with the hidden
2127 + vfsmount (instead of the original branch's vfsmount)
2128 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2129 + but it may be possible from userspace by the mount helper.
2131 +Adding the internal hidden vfsmount and using it in opening a file, the
2132 +file path under /proc will be printed correctly. This approach looks
2133 +smarter, but is not possible I am afraid.
2134 +- aufs-root may be bind-mount later. when it happens, another hidden
2135 + vfsmount will be required.
2136 +- it is hard to get the chance to bind-mount and lazy-umount
2137 + + in kernel-space, FS can have vfsmount in open(2) via
2138 + file->f_path, and aufs can know its vfsmount. But several locks are
2139 + already acquired, and if aufs tries to bind-mount and lazy-umount
2140 + here, then it may cause a deadlock.
2141 + + in user-space, bind-mount doesn't invoke the mount helper.
2142 +- since /proc shows dev and ino, aufs has to give vma these info. it
2143 + means a new member vm_prinode will be necessary. this is essentially
2144 + equivalent to vm_prfile described above.
2146 +I have to give up this "looks-smater" approach.
2147 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2148 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2149 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-12-03 15:38:59.929980643 +0100
2152 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2154 +# This program is free software; you can redistribute it and/or modify
2155 +# it under the terms of the GNU General Public License as published by
2156 +# the Free Software Foundation; either version 2 of the License, or
2157 +# (at your option) any later version.
2159 +# This program is distributed in the hope that it will be useful,
2160 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2161 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2162 +# GNU General Public License for more details.
2164 +# You should have received a copy of the GNU General Public License
2165 +# along with this program; if not, write to the Free Software
2166 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2169 +Listing XATTR/EA and getting the value
2170 +----------------------------------------------------------------------
2171 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2172 +shows the values from the topmost existing file. This behaviour is good
2173 +for the non-dir entries since the bahaviour exactly matches the shown
2174 +information. But for the directories, aufs considers all the same named
2175 +entries on the lower branches. Which means, if one of the lower entry
2176 +rejects readdir call, then aufs returns an error even if the topmost
2177 +entry allows it. This behaviour is necessary to respect the branch fs's
2178 +security, but can make users confused since the user-visible standard
2179 +attributes don't match the behaviour.
2180 +To address this issue, aufs has a mount option called dirperm1 which
2181 +checks the permission for the topmost entry only, and ignores the lower
2182 +entry's permission.
2184 +A similar issue can happen around XATTR.
2185 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2186 +always set. Otherwise these very unpleasant situation would happen.
2187 +- listxattr(2) may return the duplicated entries.
2188 +- users may not be able to remove or reset the XATTR forever,
2191 +XATTR/EA support in the internal (copy,move)-(up,down)
2192 +----------------------------------------------------------------------
2193 +Generally the extended attributes of inode are categorized as these.
2194 +- "security" for LSM and capability.
2195 +- "system" for posix ACL, 'acl' mount option is required for the branch
2197 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2198 +- "user" for userspace, 'user_xattr' mount option is required for the
2199 + branch fs generally.
2201 +Moreover there are some other categories. Aufs handles these rather
2202 +unpopular categories as the ordinary ones, ie. there is no special
2203 +condition nor exception.
2205 +In copy-up, the support for XATTR on the dst branch may differ from the
2206 +src branch. In this case, the copy-up operation will get an error and
2207 +the original user operation which triggered the copy-up will fail. It
2208 +can happen that even all copy-up will fail.
2209 +When both of src and dst branches support XATTR and if an error occurs
2210 +during copying XATTR, then the copy-up should fail obviously. That is a
2211 +good reason and aufs should return an error to userspace. But when only
2212 +the src branch support that XATTR, aufs should not return an error.
2213 +For example, the src branch supports ACL but the dst branch doesn't
2214 +because the dst branch may natively un-support it or temporary
2215 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2216 +may NOT return an error even if the XATTR is not supported. It is
2217 +totally up to the branch fs.
2219 +Anyway when the aufs internal copy-up gets an error from the dst branch
2220 +fs, then aufs tries removing the just copied entry and returns the error
2221 +to the userspace. The worst case of this situation will be all copy-up
2224 +For the copy-up operation, there two basic approaches.
2225 +- copy the specified XATTR only (by category above), and return the
2226 + error unconditionally if it happens.
2227 +- copy all XATTR, and ignore the error on the specified category only.
2229 +In order to support XATTR and to implement the correct behaviour, aufs
2230 +chooses the latter approach and introduces some new branch attributes,
2231 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2232 +They correspond to the XATTR namespaces (see above). Additionally, to be
2233 +convenient, "icex" is also provided which means all "icex*" attributes
2234 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2236 +The meaning of these attributes is to ignore the error from setting
2237 +XATTR on that branch.
2238 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2239 +error from the dst branch according to the specified attributes.
2241 +Some XATTR may have its default value. The default value may come from
2242 +the parent dir or the environment. If the default value is set at the
2243 +file creating-time, it will be overwritten by copy-up.
2244 +Some contradiction may happen I am afraid.
2245 +Do we need another attribute to stop copying XATTR? I am unsure. For
2246 +now, aufs implements the branch attributes to ignore the error.
2247 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2248 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2249 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-12-03 15:38:59.929980643 +0100
2252 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2254 +# This program is free software; you can redistribute it and/or modify
2255 +# it under the terms of the GNU General Public License as published by
2256 +# the Free Software Foundation; either version 2 of the License, or
2257 +# (at your option) any later version.
2259 +# This program is distributed in the hope that it will be useful,
2260 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2261 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2262 +# GNU General Public License for more details.
2264 +# You should have received a copy of the GNU General Public License
2265 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2267 +Export Aufs via NFS
2268 +----------------------------------------------------------------------
2269 +Here is an approach.
2270 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2272 +- iget_locked(): initialize aufs inode generation for a new inode, and
2273 + store it in xigen file.
2274 +- destroy_inode(): increment aufs inode generation and store it in xigen
2275 + file. it is necessary even if it is not unlinked, because any data of
2276 + inode may be changed by UDBA.
2277 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2278 + build file handle by
2279 + + branch id (4 bytes)
2280 + + superblock generation (4 bytes)
2281 + + inode number (4 or 8 bytes)
2282 + + parent dir inode number (4 or 8 bytes)
2283 + + inode generation (4 bytes))
2284 + + return value of exportfs_encode_fh() for the parent on a branch (4
2286 + + file handle for a branch (by exportfs_encode_fh())
2288 + + find the index of a branch from its id in handle, and check it is
2289 + still exist in aufs.
2290 + + 1st level: get the inode number from handle and search it in cache.
2291 + + 2nd level: if not found in cache, get the parent inode number from
2292 + the handle and search it in cache. and then open the found parent
2293 + dir, find the matching inode number by vfs_readdir() and get its
2294 + name, and call lookup_one_len() for the target dentry.
2295 + + 3rd level: if the parent dir is not cached, call
2296 + exportfs_decode_fh() for a branch and get the parent on a branch,
2297 + build a pathname of it, convert it a pathname in aufs, call
2298 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2300 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2301 + for every branch, but not itself. to get this, (currently) aufs
2302 + searches in current->nsproxy->mnt_ns list. it may not be a good
2303 + idea, but I didn't get other approach.
2304 + + test the generation of the gotten inode.
2305 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2306 + convert it into ESTALE for NFSD.
2307 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2308 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2309 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2310 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2311 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-12-03 15:38:59.929980643 +0100
2314 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2316 +# This program is free software; you can redistribute it and/or modify
2317 +# it under the terms of the GNU General Public License as published by
2318 +# the Free Software Foundation; either version 2 of the License, or
2319 +# (at your option) any later version.
2321 +# This program is distributed in the hope that it will be useful,
2322 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2323 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2324 +# GNU General Public License for more details.
2326 +# You should have received a copy of the GNU General Public License
2327 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2329 +Show Whiteout Mode (shwh)
2330 +----------------------------------------------------------------------
2331 +Generally aufs hides the name of whiteouts. But in some cases, to show
2332 +them is very useful for users. For instance, creating a new middle layer
2333 +(branch) by merging existing layers.
2335 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2336 +When you have three branches,
2337 +- Bottom: 'system', squashfs (underlying base system), read-only
2338 +- Middle: 'mods', squashfs, read-only
2339 +- Top: 'overlay', ram (tmpfs), read-write
2341 +The top layer is loaded at boot time and saved at shutdown, to preserve
2342 +the changes made to the system during the session.
2343 +When larger changes have been made, or smaller changes have accumulated,
2344 +the size of the saved top layer data grows. At this point, it would be
2345 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2346 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2347 +restoring save and load speed.
2349 +This merging is simplified by the use of another aufs mount, of just the
2350 +two overlay branches using the 'shwh' option.
2351 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2352 + aufs /livesys/merge_union
2354 +A merged view of these two branches is then available at
2355 +/livesys/merge_union, and the new feature is that the whiteouts are
2357 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2358 +writing to all branches. Also the default mode for all branches is 'ro'.
2359 +It is now possible to save the combined contents of the two overlay
2360 +branches to a new squashfs, e.g.:
2361 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2363 +This new squashfs archive can be stored on the boot device and the
2364 +initramfs will use it to replace the old one at the next boot.
2365 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2366 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2367 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-12-03 15:38:59.929980643 +0100
2370 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2372 +# This program is free software; you can redistribute it and/or modify
2373 +# it under the terms of the GNU General Public License as published by
2374 +# the Free Software Foundation; either version 2 of the License, or
2375 +# (at your option) any later version.
2377 +# This program is distributed in the hope that it will be useful,
2378 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2379 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2380 +# GNU General Public License for more details.
2382 +# You should have received a copy of the GNU General Public License
2383 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2385 +Dynamically customizable FS operations
2386 +----------------------------------------------------------------------
2387 +Generally FS operations (struct inode_operations, struct
2388 +address_space_operations, struct file_operations, etc.) are defined as
2389 +"static const", but it never means that FS have only one set of
2390 +operation. Some FS have multiple sets of them. For instance, ext2 has
2391 +three sets, one for XIP, for NOBH, and for normal.
2392 +Since aufs overrides and redirects these operations, sometimes aufs has
2393 +to change its behaviour according to the branch FS type. More importantly
2394 +VFS acts differently if a function (member in the struct) is set or
2395 +not. It means aufs should have several sets of operations and select one
2396 +among them according to the branch FS definition.
2398 +In order to solve this problem and not to affect the behaviour of VFS,
2399 +aufs defines these operations dynamically. For instance, aufs defines
2400 +dummy direct_IO function for struct address_space_operations, but it may
2401 +not be set to the address_space_operations actually. When the branch FS
2402 +doesn't have it, aufs doesn't set it to its address_space_operations
2403 +while the function definition itself is still alive. So the behaviour
2404 +itself will not change, and it will return an error when direct_IO is
2407 +The lifetime of these dynamically generated operation object is
2408 +maintained by aufs branch object. When the branch is removed from aufs,
2409 +the reference counter of the object is decremented. When it reaches
2410 +zero, the dynamically generated operation object will be freed.
2412 +This approach is designed to support AIO (io_submit), Direct I/O and
2414 +Currently this approach is applied to address_space_operations for
2415 +regular files only.
2416 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2417 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2418 +++ linux/Documentation/filesystems/aufs/README 2021-12-03 15:40:58.233313963 +0100
2421 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2427 +----------------------------------------
2428 +In the early days, aufs was entirely re-designed and re-implemented
2429 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2430 +improvements and implementations, it became totally different from
2431 +Unionfs while keeping the basic features.
2432 +Later, Unionfs Version 2.x series began taking some of the same
2433 +approaches to aufs1's.
2434 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2435 +University and his team.
2437 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2439 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2440 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2441 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2442 + or aufs1 from CVS on SourceForge.
2444 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2445 + According to Christoph Hellwig, linux rejects all union-type
2446 + filesystems but UnionMount.
2447 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2449 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2450 + UnionMount, and he pointed out an issue around a directory mutex
2451 + lock and aufs addressed it. But it is still unsure whether aufs will
2452 + be merged (or any other union solution).
2453 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2457 +----------------------------------------
2458 +- unite several directories into a single virtual filesystem. The member
2459 + directory is called as a branch.
2460 +- you can specify the permission flags to the branch, which are 'readonly',
2461 + 'readwrite' and 'whiteout-able.'
2462 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2463 + readonly branch are modifiable logically.
2464 +- dynamic branch manipulation, add, del.
2467 +Also there are many enhancements in aufs, such as:
2468 +- test only the highest one for the directory permission (dirperm1)
2469 +- copyup on open (coo=)
2470 +- 'move' policy for copy-up between two writable branches, after
2471 + checking free space.
2473 +- readdir(3) in userspace.
2474 +- keep inode number by external inode number table
2475 +- keep the timestamps of file/dir in internal copyup operation
2476 +- seekable directory, supporting NFS readdir.
2477 +- whiteout is hardlinked in order to reduce the consumption of inodes
2479 +- do not copyup, nor create a whiteout when it is unnecessary
2480 +- revert a single systemcall when an error occurs in aufs
2481 +- remount interface instead of ioctl
2482 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2483 +- loopback mounted filesystem as a branch
2484 +- kernel thread for removing the dir who has a plenty of whiteouts
2485 +- support copyup sparse file (a file which has a 'hole' in it)
2486 +- default permission flags for branches
2487 +- selectable permission flags for ro branch, whether whiteout can
2490 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2491 +- support multiple writable branches, some policies to select one
2492 + among multiple writable branches.
2493 +- a new semantics for link(2) and rename(2) to support multiple
2494 + writable branches.
2495 +- no glibc changes are required.
2496 +- pseudo hardlink (hardlink over branches)
2497 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2498 + including NFS or remote filesystem branch.
2499 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2502 +Currently these features are dropped temporary from aufs5.
2503 +See design/08plan.txt in detail.
2504 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2506 +- statistics of aufs thread (/sys/fs/aufs/stat)
2508 +Features or just an idea in the future (see also design/*.txt),
2509 +- reorder the branch index without del/re-add.
2510 +- permanent xino files for NFSD
2511 +- an option for refreshing the opened files after add/del branches
2512 +- light version, without branch manipulation. (unnecessary?)
2513 +- copyup in userspace
2514 +- inotify in userspace
2519 +----------------------------------------
2520 +There are three GIT trees for aufs5, aufs5-linux.git,
2521 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2523 +While the aufs-util is always necessary, you need either of aufs5-linux
2524 +or aufs5-standalone.
2526 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2527 +git://git.kernel.org/.../torvalds/linux.git.
2528 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2529 +build aufs5 as an external kernel module.
2530 +Several extra patches are not included in this tree. Only
2531 +aufs5-standalone tree contains them. They are described in the later
2532 +section "Configuration and Compilation."
2534 +On the other hand, the aufs5-standalone tree has only aufs source files
2535 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2536 +But you need to apply all aufs patches manually.
2538 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2539 +represents the linux kernel version, "linux-5.x". For instance,
2540 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2541 +"aufs5.x-rcN" branch.
2544 +$ git clone --reference /your/linux/git/tree \
2545 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2546 +- if you don't have linux GIT tree, then remove "--reference ..."
2547 +$ cd aufs5-linux.git
2548 +$ git checkout origin/aufs5.0
2550 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2551 +leave the patch-work to GIT.
2552 +$ cd /your/linux/git/tree
2553 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2555 +$ git checkout -b my5.0 v5.0
2556 +$ (add your local change...)
2557 +$ git pull aufs5 aufs5.0
2558 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2559 +- you may need to solve some conflicts between your_changes and
2560 + aufs5.0. in this case, git-rerere is recommended so that you can
2561 + solve the similar conflicts automatically when you upgrade to 5.1 or
2562 + later in the future.
2564 +o aufs5-standalone tree
2565 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2566 +$ cd aufs5-standalone.git
2567 +$ git checkout origin/aufs5.0
2570 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2571 +- note that the public aufs-util.git is on SourceForge instead of
2574 +$ git checkout origin/aufs5.0
2576 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2577 +The minor version number, 'x' in '5.x', of aufs may not always
2578 +follow the minor version number of the kernel.
2579 +Because changes in the kernel that cause the use of a new
2580 +minor version number do not always require changes to aufs-util.
2582 +Since aufs-util has its own minor version number, you may not be
2583 +able to find a GIT branch in aufs-util for your kernel's
2584 +exact minor version number.
2585 +In this case, you should git-checkout the branch for the
2586 +nearest lower number.
2588 +For (an unreleased) example:
2589 +If you are using "linux-5.10" and the "aufs5.10" branch
2590 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2591 +or something numerically smaller is the branch for your kernel.
2593 +Also you can view all branches by
2597 +3. Configuration and Compilation
2598 +----------------------------------------
2599 +Make sure you have git-checkout'ed the correct branch.
2601 +For aufs5-linux tree,
2602 +- enable CONFIG_AUFS_FS.
2603 +- set other aufs configurations if necessary.
2604 +- for aufs5.13 and later
2605 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2606 + also a caller of VFS functions for branch filesystems, subclassing of
2607 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2608 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2609 + need to customize some LOCKDEP numbers. Here are what I use on my
2611 + CONFIG_LOCKDEP_BITS=21
2612 + CONFIG_LOCKDEP_CHAINS_BITS=21
2613 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2615 +For aufs5-standalone tree,
2616 +There are several ways to build.
2619 +- apply ./aufs5-kbuild.patch to your kernel source files.
2620 +- apply ./aufs5-base.patch too.
2621 +- apply ./aufs5-mmap.patch too.
2622 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2623 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2624 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2625 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2626 +- enable CONFIG_AUFS_FS, you can select either
2628 +- and build your kernel as usual.
2629 +- install the built kernel.
2630 +- install the header files too by "make headers_install" to the
2631 + directory where you specify. By default, it is $PWD/usr.
2632 + "make help" shows a brief note for headers_install.
2633 +- and reboot your system.
2636 +- module only (CONFIG_AUFS_FS=m).
2637 +- apply ./aufs5-base.patch to your kernel source files.
2638 +- apply ./aufs5-mmap.patch too.
2639 +- apply ./aufs5-standalone.patch too.
2640 +- build your kernel, don't forget "make headers_install", and reboot.
2641 +- edit ./config.mk and set other aufs configurations if necessary.
2642 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2643 + every aufs configurations.
2644 +- build the module by simple "make".
2645 +- you can specify ${KDIR} make variable which points to your kernel
2647 +- install the files
2648 + + run "make install" to install the aufs module, or copy the built
2649 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2650 + + run "make install_headers" (instead of headers_install) to install
2651 + the modified aufs header file (you can specify DESTDIR which is
2652 + available in aufs standalone version's Makefile only), or copy
2653 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2654 + you like manually. By default, the target directory is $PWD/usr.
2655 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2656 + kernel source tree.
2658 +Note: The header file aufs_type.h is necessary to build aufs-util
2659 + as well as "make headers_install" in the kernel source tree.
2660 + headers_install is subject to be forgotten, but it is essentially
2661 + necessary, not only for building aufs-util.
2662 + You may not meet problems without headers_install in some older
2666 +- read README in aufs-util, build and install it
2667 +- note that your distribution may contain an obsoleted version of
2668 + aufs_type.h in /usr/include/linux or something. When you build aufs
2669 + utilities, make sure that your compiler refers the correct aufs header
2670 + file which is built by "make headers_install."
2671 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2672 + then run "make install_ulib" too. And refer to the aufs manual in
2675 +There several other patches in aufs5-standalone.git. They are all
2676 +optional. When you meet some problems, they will help you.
2677 +- aufs5-loopback.patch
2678 + Supports a nested loopback mount in a branch-fs. This patch is
2679 + unnecessary until aufs produces a message like "you may want to try
2680 + another patch for loopback file".
2682 + Modifies a system global kernel internal function get_next_ino() in
2683 + order to stop assigning 0 for an inode-number. Not directly related to
2684 + aufs, but recommended generally.
2686 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2687 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2688 + duplication of inode number, which is important for backup tools and
2689 + other utilities. When you find aufs XINO files for tmpfs branch
2690 + growing too much, try this patch.
2694 +----------------------------------------
2695 +At first, make sure aufs-util are installed, and please read the aufs
2696 +manual, aufs.5 in aufs-util.git tree.
2700 +$ mkdir /tmp/rw /tmp/aufs
2701 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2703 +Here is another example. The result is equivalent.
2704 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2706 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2707 +# mount -o remount,append:${HOME} /tmp/aufs
2709 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2710 +you modify a file under /tmp/aufs, the one on your home directory is
2711 +not affected, instead the same named file will be newly created under
2712 +/tmp/rw. And all of your modification to a file will be applied to
2713 +the one under /tmp/rw. This is called the file based Copy on Write
2715 +Aufs mount options are described in aufs.5.
2716 +If you run chroot or something and make your aufs as a root directory,
2717 +then you need to customize the shutdown script. See the aufs manual in
2720 +Additionally, there are some sample usages of aufs which are a
2721 +diskless system with network booting, and LiveCD over NFS.
2722 +See sample dir in CVS tree on SourceForge.
2726 +----------------------------------------
2727 +When you have any problems or strange behaviour in aufs, please let me
2729 +- /proc/mounts (instead of the output of mount(8))
2730 +- /sys/module/aufs/*
2731 +- /sys/fs/aufs/* (if you have them)
2732 +- /debug/aufs/* (if you have them)
2733 +- linux kernel version
2734 + if your kernel is not plain, for example modified by distributor,
2735 + the url where i can download its source is necessary too.
2736 +- aufs version which was printed at loading the module or booting the
2737 + system, instead of the date you downloaded.
2738 +- configuration (define/undefine CONFIG_AUFS_xxx)
2739 +- kernel configuration or /proc/config.gz (if you have it)
2740 +- LSM (linux security module, if you are using)
2741 +- behaviour which you think to be incorrect
2742 +- actual operation, reproducible one is better
2743 +- mailto: aufs-users at lists.sourceforge.net
2745 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2746 +and Feature Requests) on SourceForge. Please join and write to
2750 +6. Acknowledgements
2751 +----------------------------------------
2752 +Thanks to everyone who have tried and are using aufs, whoever
2753 +have reported a bug or any feedback.
2755 +Especially donators:
2756 +Tomas Matejicek(slax.org) made a donation (much more than once).
2757 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2758 + scripts) is making "doubling" donations.
2759 + Unfortunately I cannot list all of the donators, but I really
2761 + It ends Aug 2010, but the ordinary donation URL is still available.
2762 + <http://sourceforge.net/donate/index.php?group_id=167503>
2763 +Dai Itasaka made a donation (2007/8).
2764 +Chuck Smith made a donation (2008/4, 10 and 12).
2765 +Henk Schoneveld made a donation (2008/9).
2766 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2767 +Francois Dupoux made a donation (2008/11).
2768 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2769 + aufs2 GIT tree (2009/2).
2770 +William Grant made a donation (2009/3).
2771 +Patrick Lane made a donation (2009/4).
2772 +The Mail Archive (mail-archive.com) made donations (2009/5).
2773 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2774 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2775 +Pavel Pronskiy made a donation (2011/2).
2776 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2777 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2778 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2780 +Sam Liddicott made a donation (2011/9).
2781 +Era Scarecrow made a donation (2013/4).
2782 +Bor Ratajc made a donation (2013/4).
2783 +Alessandro Gorreta made a donation (2013/4).
2784 +POIRETTE Marc made a donation (2013/4).
2785 +Alessandro Gorreta made a donation (2013/4).
2786 +lauri kasvandik made a donation (2013/5).
2787 +"pemasu from Finland" made a donation (2013/7).
2788 +The Parted Magic Project made a donation (2013/9 and 11).
2789 +Pavel Barta made a donation (2013/10).
2790 +Nikolay Pertsev made a donation (2014/5).
2791 +James B made a donation (2014/7 and 2015/7).
2792 +Stefano Di Biase made a donation (2014/8).
2793 +Daniel Epellei made a donation (2015/1).
2794 +OmegaPhil made a donation (2016/1, 2018/4).
2795 +Tomasz Szewczyk made a donation (2016/4).
2796 +James Burry made a donation (2016/12).
2797 +Carsten Rose made a donation (2018/9).
2798 +Porteus Kiosk made a donation (2018/10).
2800 +Thank you very much.
2801 +Donations are always, including future donations, very important and
2802 +helpful for me to keep on developing aufs.
2806 +----------------------------------------
2807 +If you are an experienced user, no explanation is needed. Aufs is
2808 +just a linux filesystem.
2813 +# Local variables: ;
2816 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2817 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2818 +++ linux/fs/aufs/aufs.h 2021-12-03 15:38:59.929980643 +0100
2820 +/* SPDX-License-Identifier: GPL-2.0 */
2822 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2824 + * This program, aufs is free software; you can redistribute it and/or modify
2825 + * it under the terms of the GNU General Public License as published by
2826 + * the Free Software Foundation; either version 2 of the License, or
2827 + * (at your option) any later version.
2829 + * This program is distributed in the hope that it will be useful,
2830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2832 + * GNU General Public License for more details.
2834 + * You should have received a copy of the GNU General Public License
2835 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2839 + * all header files
2847 +#define AuStub(type, name, body, ...) \
2848 + static inline type name(__VA_ARGS__) { body; }
2850 +#define AuStubVoid(name, ...) \
2851 + AuStub(void, name, , __VA_ARGS__)
2852 +#define AuStubInt0(name, ...) \
2853 + AuStub(int, name, return 0, __VA_ARGS__)
2857 +#include "branch.h"
2860 +#include "dbgaufs.h"
2861 +#include "dentry.h"
2863 +#include "dirren.h"
2866 +#include "fstype.h"
2871 +#include "module.h"
2875 +#include "sysaufs.h"
2880 +#endif /* __KERNEL__ */
2881 +#endif /* __AUFS_H__ */
2882 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2883 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2884 +++ linux/fs/aufs/branch.c 2021-12-03 15:38:59.933313976 +0100
2886 +// SPDX-License-Identifier: GPL-2.0
2888 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2890 + * This program, aufs is free software; you can redistribute it and/or modify
2891 + * it under the terms of the GNU General Public License as published by
2892 + * the Free Software Foundation; either version 2 of the License, or
2893 + * (at your option) any later version.
2895 + * This program is distributed in the hope that it will be useful,
2896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2898 + * GNU General Public License for more details.
2900 + * You should have received a copy of the GNU General Public License
2901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2905 + * branch management
2908 +#include <linux/compat.h>
2909 +#include <linux/statfs.h>
2913 + * free a single branch
2915 +static void au_br_do_free(struct au_branch *br)
2918 + struct au_wbr *wbr;
2919 + struct au_dykey **key;
2921 + au_hnotify_fin_br(br);
2922 + /* always, regardless the mount option */
2923 + au_dr_hino_free(&br->br_dirren);
2926 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2927 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2928 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2929 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2933 + for (i = 0; i < AuBrWh_Last; i++)
2934 + dput(wbr->wbr_wh[i]);
2935 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2936 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2939 + if (br->br_fhsm) {
2940 + au_br_fhsm_fin(br->br_fhsm);
2941 + au_kfree_try_rcu(br->br_fhsm);
2944 + key = br->br_dykey;
2945 + for (i = 0; i < AuBrDynOp; i++, key++)
2951 + /* recursive lock, s_umount of branch's */
2952 + /* synchronize_rcu(); */ /* why? */
2954 + path_put(&br->br_path);
2956 + au_kfree_rcu(wbr);
2957 + au_lcnt_wait_for_fin(&br->br_nfiles);
2958 + au_lcnt_wait_for_fin(&br->br_count);
2959 + /* I don't know why, but percpu_refcount requires this */
2960 + /* synchronize_rcu(); */
2965 + * frees all branches
2967 +void au_br_free(struct au_sbinfo *sbinfo)
2969 + aufs_bindex_t bmax;
2970 + struct au_branch **br;
2972 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2974 + bmax = sbinfo->si_bbot + 1;
2975 + br = sbinfo->si_branch;
2977 + au_br_do_free(*br++);
2981 + * find the index of a branch which is specified by @br_id.
2983 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2985 + aufs_bindex_t bindex, bbot;
2987 + bbot = au_sbbot(sb);
2988 + for (bindex = 0; bindex <= bbot; bindex++)
2989 + if (au_sbr_id(sb, bindex) == br_id)
2994 +/* ---------------------------------------------------------------------- */
3000 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3001 + struct dentry *h_root)
3003 + if (unlikely(h_adding == h_root
3004 + || au_test_loopback_overlap(sb, h_adding)))
3006 + if (h_adding->d_sb != h_root->d_sb)
3008 + return au_test_subdir(h_adding, h_root)
3009 + || au_test_subdir(h_root, h_adding);
3013 + * returns a newly allocated branch. @new_nbranch is a number of branches
3014 + * after adding a branch.
3016 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3019 + struct au_branch *add_branch;
3020 + struct dentry *root;
3021 + struct inode *inode;
3025 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3026 + if (unlikely(!add_branch))
3028 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3029 + if (unlikely(!add_branch->br_xino))
3031 + err = au_hnotify_init_br(add_branch, perm);
3032 + if (unlikely(err))
3035 + if (au_br_writable(perm)) {
3036 + /* may be freed separately at changing the branch permission */
3037 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3039 + if (unlikely(!add_branch->br_wbr))
3043 + if (au_br_fhsm(perm)) {
3044 + err = au_fhsm_br_alloc(add_branch);
3045 + if (unlikely(err))
3049 + root = sb->s_root;
3050 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3052 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3054 + inode = d_inode(root);
3055 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3059 + return add_branch; /* success */
3062 + au_kfree_rcu(add_branch->br_wbr);
3064 + au_hnotify_fin_br(add_branch);
3066 + au_xino_put(add_branch);
3068 + au_kfree_rcu(add_branch);
3070 + return ERR_PTR(err);
3074 + * test if the branch permission is legal or not.
3076 +static int test_br(struct inode *inode, int brperm, char *path)
3080 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3085 + pr_err("write permission for readonly mount or inode, %s\n", path);
3093 + * 0: success, the caller will add it
3094 + * plus: success, it is already unified, the caller should ignore it
3097 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3100 + aufs_bindex_t bbot, bindex;
3101 + struct dentry *root, *h_dentry;
3102 + struct inode *inode, *h_inode;
3104 + root = sb->s_root;
3105 + bbot = au_sbbot(sb);
3106 + if (unlikely(bbot >= 0
3107 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3111 + pr_err("%s duplicated\n", add->pathname);
3116 + err = -ENOSPC; /* -E2BIG; */
3117 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3118 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3119 + pr_err("number of branches exceeded %s\n", add->pathname);
3124 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3125 + pr_err("bad index %d\n", add->bindex);
3129 + inode = d_inode(add->path.dentry);
3131 + if (unlikely(!inode->i_nlink)) {
3132 + pr_err("no existence %s\n", add->pathname);
3137 + if (unlikely(inode->i_sb == sb)) {
3138 + pr_err("%s must be outside\n", add->pathname);
3142 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3143 + pr_err("unsupported filesystem, %s (%s)\n",
3144 + add->pathname, au_sbtype(inode->i_sb));
3148 + if (unlikely(inode->i_sb->s_stack_depth)) {
3149 + pr_err("already stacked, %s (%s)\n",
3150 + add->pathname, au_sbtype(inode->i_sb));
3154 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3155 + if (unlikely(err))
3159 + return 0; /* success */
3162 + for (bindex = 0; bindex <= bbot; bindex++)
3163 + if (unlikely(test_overlap(sb, add->path.dentry,
3164 + au_h_dptr(root, bindex)))) {
3165 + pr_err("%s is overlapped\n", add->pathname);
3170 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3171 + h_dentry = au_h_dptr(root, 0);
3172 + h_inode = d_inode(h_dentry);
3173 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3174 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3175 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3176 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3178 + i_uid_read(inode), i_gid_read(inode),
3179 + (inode->i_mode & S_IALLUGO),
3180 + i_uid_read(h_inode), i_gid_read(h_inode),
3181 + (h_inode->i_mode & S_IALLUGO));
3189 + * initialize or clean the whiteouts for an adding branch
3191 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3194 + int err, old_perm;
3195 + aufs_bindex_t bindex;
3196 + struct inode *h_inode;
3197 + struct au_wbr *wbr;
3198 + struct au_hinode *hdir;
3199 + struct dentry *h_dentry;
3201 + err = vfsub_mnt_want_write(au_br_mnt(br));
3202 + if (unlikely(err))
3206 + old_perm = br->br_perm;
3207 + br->br_perm = new_perm;
3210 + bindex = au_br_index(sb, br->br_id);
3211 + if (0 <= bindex) {
3212 + hdir = au_hi(d_inode(sb->s_root), bindex);
3213 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3215 + h_dentry = au_br_dentry(br);
3216 + h_inode = d_inode(h_dentry);
3217 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3220 + err = au_wh_init(br, sb);
3222 + wbr_wh_write_lock(wbr);
3223 + err = au_wh_init(br, sb);
3224 + wbr_wh_write_unlock(wbr);
3227 + au_hn_inode_unlock(hdir);
3229 + inode_unlock(h_inode);
3230 + vfsub_mnt_drop_write(au_br_mnt(br));
3231 + br->br_perm = old_perm;
3233 + if (!err && wbr && !au_br_writable(new_perm)) {
3234 + au_kfree_rcu(wbr);
3235 + br->br_wbr = NULL;
3242 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3246 + struct kstatfs kst;
3247 + struct au_wbr *wbr;
3250 + au_rw_init(&wbr->wbr_wh_rwsem);
3251 + atomic_set(&wbr->wbr_wh_running, 0);
3254 + * a limit for rmdir/rename a dir
3255 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3257 + err = vfs_statfs(&br->br_path, &kst);
3258 + if (unlikely(err))
3261 + if (kst.f_namelen >= NAME_MAX)
3262 + err = au_br_init_wh(sb, br, perm);
3264 + pr_err("%pd(%s), unsupported namelen %ld\n",
3266 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3272 +/* initialize a new branch */
3273 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3274 + struct au_opt_add *add)
3277 + struct au_branch *brbase;
3279 + struct inode *h_inode;
3282 + br->br_perm = add->perm;
3283 + br->br_path = add->path; /* set first, path_get() later */
3284 + spin_lock_init(&br->br_dykey_lock);
3285 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3286 + au_lcnt_init(&br->br_count, /*release*/NULL);
3287 + br->br_id = au_new_br_id(sb);
3288 + AuDebugOn(br->br_id < 0);
3290 + /* always, regardless the given option */
3291 + err = au_dr_br_init(sb, br, &add->path);
3292 + if (unlikely(err))
3295 + if (au_br_writable(add->perm)) {
3296 + err = au_wbr_init(br, sb, add->perm);
3297 + if (unlikely(err))
3301 + if (au_opt_test(au_mntflags(sb), XINO)) {
3302 + brbase = au_sbr(sb, 0);
3303 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3305 + h_inode = d_inode(add->path.dentry);
3306 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3307 + if (unlikely(err)) {
3308 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3313 + sysaufs_br_init(br);
3314 + path_get(&br->br_path);
3315 + goto out; /* success */
3318 + memset(&br->br_path, 0, sizeof(br->br_path));
3323 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3324 + struct au_branch *br, aufs_bindex_t bbot,
3325 + aufs_bindex_t amount)
3327 + struct au_branch **brp;
3329 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3331 + brp = sbinfo->si_branch + bindex;
3332 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3334 + sbinfo->si_bbot++;
3335 + if (unlikely(bbot < 0))
3336 + sbinfo->si_bbot = 0;
3339 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3340 + aufs_bindex_t bbot, aufs_bindex_t amount)
3342 + struct au_hdentry *hdp;
3344 + AuRwMustWriteLock(&dinfo->di_rwsem);
3346 + hdp = au_hdentry(dinfo, bindex);
3347 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3348 + au_h_dentry_init(hdp);
3350 + if (unlikely(bbot < 0))
3351 + dinfo->di_btop = 0;
3354 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3355 + aufs_bindex_t bbot, aufs_bindex_t amount)
3357 + struct au_hinode *hip;
3359 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3361 + hip = au_hinode(iinfo, bindex);
3362 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3363 + au_hinode_init(hip);
3365 + if (unlikely(bbot < 0))
3366 + iinfo->ii_btop = 0;
3369 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3370 + aufs_bindex_t bindex)
3372 + struct dentry *root, *h_dentry;
3373 + struct inode *root_inode, *h_inode;
3374 + aufs_bindex_t bbot, amount;
3376 + root = sb->s_root;
3377 + root_inode = d_inode(root);
3378 + bbot = au_sbbot(sb);
3379 + amount = bbot + 1 - bindex;
3380 + h_dentry = au_br_dentry(br);
3381 + au_sbilist_lock();
3382 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3383 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3384 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3385 + au_set_h_dptr(root, bindex, dget(h_dentry));
3386 + h_inode = d_inode(h_dentry);
3387 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3388 + au_sbilist_unlock();
3391 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3394 + aufs_bindex_t bbot, add_bindex;
3395 + struct dentry *root, *h_dentry;
3396 + struct inode *root_inode;
3397 + struct au_branch *add_branch;
3399 + root = sb->s_root;
3400 + root_inode = d_inode(root);
3401 + IMustLock(root_inode);
3402 + IiMustWriteLock(root_inode);
3403 + err = test_add(sb, add, remount);
3404 + if (unlikely(err < 0))
3408 + goto out; /* success */
3411 + bbot = au_sbbot(sb);
3412 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3413 + err = PTR_ERR(add_branch);
3414 + if (IS_ERR(add_branch))
3417 + err = au_br_init(add_branch, sb, add);
3418 + if (unlikely(err)) {
3419 + au_br_do_free(add_branch);
3423 + add_bindex = add->bindex;
3424 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3425 + au_br_do_add(sb, add_branch, add_bindex);
3426 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3427 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3429 + h_dentry = add->path.dentry;
3430 + if (!add_bindex) {
3431 + au_cpup_attr_all(root_inode, /*force*/1);
3432 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3434 + au_add_nlink(root_inode, d_inode(h_dentry));
3440 +/* ---------------------------------------------------------------------- */
3442 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3443 + unsigned long long max __maybe_unused,
3446 + unsigned long long n;
3447 + struct file **p, *f;
3448 + struct hlist_bl_head *files;
3449 + struct hlist_bl_node *pos;
3450 + struct au_finfo *finfo;
3454 + files = &au_sbi(sb)->si_files;
3455 + hlist_bl_lock(files);
3456 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3457 + f = finfo->fi_file;
3459 + && !special_file(file_inode(f)->i_mode)) {
3463 + AuDebugOn(n > max);
3466 + hlist_bl_unlock(files);
3471 +static struct file **au_farray_alloc(struct super_block *sb,
3472 + unsigned long long *max)
3474 + struct au_sbinfo *sbi;
3477 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3478 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3481 +static void au_farray_free(struct file **a, unsigned long long max)
3483 + unsigned long long ull;
3485 + for (ull = 0; ull < max; ull++)
3491 +/* ---------------------------------------------------------------------- */
3497 +/* to show the line number, do not make it inlined function */
3498 +#define AuVerbose(do_info, fmt, ...) do { \
3500 + pr_info(fmt, ##__VA_ARGS__); \
3503 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3504 + aufs_bindex_t bbot)
3506 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3509 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3510 + aufs_bindex_t bbot)
3512 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3516 + * test if the branch is deletable or not.
3518 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3519 + unsigned int sigen, const unsigned int verbose)
3521 + int err, i, j, ndentry;
3522 + aufs_bindex_t btop, bbot;
3523 + struct au_dcsub_pages dpages;
3524 + struct au_dpage *dpage;
3527 + err = au_dpages_init(&dpages, GFP_NOFS);
3528 + if (unlikely(err))
3530 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3531 + if (unlikely(err))
3534 + for (i = 0; !err && i < dpages.ndpage; i++) {
3535 + dpage = dpages.dpages + i;
3536 + ndentry = dpage->ndentry;
3537 + for (j = 0; !err && j < ndentry; j++) {
3538 + d = dpage->dentries[j];
3539 + AuDebugOn(au_dcount(d) <= 0);
3540 + if (!au_digen_test(d, sigen)) {
3541 + di_read_lock_child(d, AuLock_IR);
3542 + if (unlikely(au_dbrange_test(d))) {
3543 + di_read_unlock(d, AuLock_IR);
3547 + di_write_lock_child(d);
3548 + if (unlikely(au_dbrange_test(d))) {
3549 + di_write_unlock(d);
3552 + err = au_reval_dpath(d, sigen);
3554 + di_downgrade_lock(d, AuLock_IR);
3556 + di_write_unlock(d);
3561 + /* AuDbgDentry(d); */
3562 + btop = au_dbtop(d);
3563 + bbot = au_dbbot(d);
3564 + if (btop <= bindex
3566 + && au_h_dptr(d, bindex)
3567 + && au_test_dbusy(d, btop, bbot)) {
3569 + AuVerbose(verbose, "busy %pd\n", d);
3572 + di_read_unlock(d, AuLock_IR);
3577 + au_dpages_free(&dpages);
3582 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3583 + unsigned int sigen, const unsigned int verbose)
3586 + unsigned long long max, ull;
3587 + struct inode *i, **array;
3588 + aufs_bindex_t btop, bbot;
3590 + array = au_iarray_alloc(sb, &max);
3591 + err = PTR_ERR(array);
3592 + if (IS_ERR(array))
3596 + AuDbg("b%d\n", bindex);
3597 + for (ull = 0; !err && ull < max; ull++) {
3601 + if (i->i_ino == AUFS_ROOT_INO)
3604 + /* AuDbgInode(i); */
3605 + if (au_iigen(i, NULL) == sigen)
3606 + ii_read_lock_child(i);
3608 + ii_write_lock_child(i);
3609 + err = au_refresh_hinode_self(i);
3612 + ii_downgrade_lock(i);
3614 + ii_write_unlock(i);
3619 + btop = au_ibtop(i);
3620 + bbot = au_ibbot(i);
3621 + if (btop <= bindex
3623 + && au_h_iptr(i, bindex)
3624 + && au_test_ibusy(i, btop, bbot)) {
3626 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3629 + ii_read_unlock(i);
3631 + au_iarray_free(array, max);
3637 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3638 + const unsigned int verbose)
3641 + unsigned int sigen;
3643 + sigen = au_sigen(root->d_sb);
3644 + DiMustNoWaiters(root);
3645 + IiMustNoWaiters(d_inode(root));
3646 + di_write_unlock(root);
3647 + err = test_dentry_busy(root, bindex, sigen, verbose);
3649 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3650 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3655 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3656 + struct file **to_free, int *idx)
3659 + unsigned char matched, root;
3660 + aufs_bindex_t bindex, bbot;
3661 + struct au_fidir *fidir;
3662 + struct au_hfile *hfile;
3665 + root = IS_ROOT(file->f_path.dentry);
3668 + to_free[*idx] = file;
3674 + fidir = au_fi(file)->fi_hdir;
3675 + AuDebugOn(!fidir);
3676 + bbot = au_fbbot_dir(file);
3677 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3678 + hfile = fidir->fd_hfile + bindex;
3679 + if (!hfile->hf_file)
3682 + if (hfile->hf_br->br_id == br_id) {
3694 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3695 + struct file **to_free, int opened)
3698 + unsigned long long ull, max;
3699 + aufs_bindex_t btop;
3700 + struct file *file, **array;
3701 + struct dentry *root;
3702 + struct au_hfile *hfile;
3704 + array = au_farray_alloc(sb, &max);
3705 + err = PTR_ERR(array);
3706 + if (IS_ERR(array))
3711 + root = sb->s_root;
3712 + di_write_unlock(root);
3713 + for (ull = 0; ull < max; ull++) {
3714 + file = array[ull];
3715 + if (unlikely(!file))
3718 + /* AuDbg("%pD\n", file); */
3719 + fi_read_lock(file);
3720 + btop = au_fbtop(file);
3721 + if (!d_is_dir(file->f_path.dentry)) {
3722 + hfile = &au_fi(file)->fi_htop;
3723 + if (hfile->hf_br->br_id == br_id)
3726 + err = test_dir_busy(file, br_id, to_free, &idx);
3727 + fi_read_unlock(file);
3728 + if (unlikely(err))
3731 + di_write_lock_child(root);
3732 + au_farray_free(array, max);
3733 + AuDebugOn(idx > opened);
3739 +static void br_del_file(struct file **to_free, unsigned long long opened,
3740 + aufs_bindex_t br_id)
3742 + unsigned long long ull;
3743 + aufs_bindex_t bindex, btop, bbot, bfound;
3744 + struct file *file;
3745 + struct au_fidir *fidir;
3746 + struct au_hfile *hfile;
3748 + for (ull = 0; ull < opened; ull++) {
3749 + file = to_free[ull];
3750 + if (unlikely(!file))
3753 + /* AuDbg("%pD\n", file); */
3754 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3756 + fidir = au_fi(file)->fi_hdir;
3757 + AuDebugOn(!fidir);
3758 + fi_write_lock(file);
3759 + btop = au_fbtop(file);
3760 + bbot = au_fbbot_dir(file);
3761 + for (bindex = btop; bindex <= bbot; bindex++) {
3762 + hfile = fidir->fd_hfile + bindex;
3763 + if (!hfile->hf_file)
3766 + if (hfile->hf_br->br_id == br_id) {
3771 + AuDebugOn(bfound < 0);
3772 + au_set_h_fptr(file, bfound, NULL);
3773 + if (bfound == btop) {
3774 + for (btop++; btop <= bbot; btop++)
3775 + if (au_hf_dir(file, btop)) {
3776 + au_set_fbtop(file, btop);
3780 + fi_write_unlock(file);
3784 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3785 + const aufs_bindex_t bindex,
3786 + const aufs_bindex_t bbot)
3788 + struct au_branch **brp, **p;
3790 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3792 + brp = sbinfo->si_branch + bindex;
3793 + if (bindex < bbot)
3794 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3795 + sbinfo->si_branch[0 + bbot] = NULL;
3796 + sbinfo->si_bbot--;
3798 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3801 + sbinfo->si_branch = p;
3802 + /* harmless error */
3805 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3806 + const aufs_bindex_t bbot)
3808 + struct au_hdentry *hdp, *p;
3810 + AuRwMustWriteLock(&dinfo->di_rwsem);
3812 + hdp = au_hdentry(dinfo, bindex);
3813 + if (bindex < bbot)
3814 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3815 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3818 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3821 + dinfo->di_hdentry = p;
3822 + /* harmless error */
3825 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3826 + const aufs_bindex_t bbot)
3828 + struct au_hinode *hip, *p;
3830 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3832 + hip = au_hinode(iinfo, bindex);
3833 + if (bindex < bbot)
3834 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3835 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3838 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3841 + iinfo->ii_hinode = p;
3842 + /* harmless error */
3845 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3846 + struct au_branch *br)
3848 + aufs_bindex_t bbot;
3849 + struct au_sbinfo *sbinfo;
3850 + struct dentry *root, *h_root;
3851 + struct inode *inode, *h_inode;
3852 + struct au_hinode *hinode;
3854 + SiMustWriteLock(sb);
3856 + root = sb->s_root;
3857 + inode = d_inode(root);
3858 + sbinfo = au_sbi(sb);
3859 + bbot = sbinfo->si_bbot;
3861 + h_root = au_h_dptr(root, bindex);
3862 + hinode = au_hi(inode, bindex);
3863 + h_inode = au_igrab(hinode->hi_inode);
3866 + au_sbilist_lock();
3867 + au_br_do_del_brp(sbinfo, bindex, bbot);
3868 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3869 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3870 + au_sbilist_unlock();
3872 + /* ignore an error */
3873 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3877 + au_br_do_free(br);
3880 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3881 + unsigned long long max, void *arg)
3886 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3889 + unsigned long long opened;
3890 + unsigned int mnt_flags;
3891 + aufs_bindex_t bindex, bbot, br_id;
3892 + unsigned char do_wh, verbose;
3893 + struct au_branch *br;
3894 + struct au_wbr *wbr;
3895 + struct dentry *root;
3896 + struct file **to_free;
3901 + root = sb->s_root;
3902 + bindex = au_find_dbindex(root, del->h_path.dentry);
3905 + goto out; /* success */
3907 + pr_err("%s no such branch\n", del->pathname);
3910 + AuDbg("bindex b%d\n", bindex);
3913 + mnt_flags = au_mntflags(sb);
3914 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3915 + bbot = au_sbbot(sb);
3916 + if (unlikely(!bbot)) {
3917 + AuVerbose(verbose, "no more branches left\n");
3921 + br = au_sbr(sb, bindex);
3922 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3923 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3924 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3928 + br_id = br->br_id;
3929 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3930 + if (unlikely(opened)) {
3931 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3932 + err = PTR_ERR(to_free);
3933 + if (IS_ERR(to_free))
3936 + err = test_file_busy(sb, br_id, to_free, opened);
3937 + if (unlikely(err)) {
3938 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3944 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3946 + /* instead of WbrWhMustWriteLock(wbr) */
3947 + SiMustWriteLock(sb);
3948 + for (i = 0; i < AuBrWh_Last; i++) {
3949 + dput(wbr->wbr_wh[i]);
3950 + wbr->wbr_wh[i] = NULL;
3954 + err = test_children_busy(root, bindex, verbose);
3955 + if (unlikely(err)) {
3964 + * now we confirmed the branch is deletable.
3965 + * let's free the remaining opened dirs on the branch.
3967 + di_write_unlock(root);
3968 + br_del_file(to_free, opened, br_id);
3969 + di_write_lock_child(root);
3972 + sysaufs_brs_del(sb, bindex); /* remove successors */
3973 + dbgaufs_xino_del(br); /* remove one */
3974 + au_br_do_del(sb, bindex, br);
3975 + sysaufs_brs_add(sb, bindex); /* append successors */
3976 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3979 + au_cpup_attr_all(d_inode(root), /*force*/1);
3980 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3982 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3983 + if (au_opt_test(mnt_flags, PLINK))
3984 + au_plink_half_refresh(sb, br_id);
3986 + goto out; /* success */
3990 + rerr = au_br_init_wh(sb, br, br->br_perm);
3992 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3993 + del->pathname, rerr);
3996 + au_farray_free(to_free, opened);
4000 +/* ---------------------------------------------------------------------- */
4002 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4005 + aufs_bindex_t btop, bbot;
4006 + struct aufs_ibusy ibusy;
4007 + struct inode *inode, *h_inode;
4010 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4013 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4015 + /* VERIFY_WRITE */
4016 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4017 + if (unlikely(err)) {
4024 + si_read_lock(sb, AuLock_FLUSH);
4025 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4029 + ibusy.h_ino = 0; /* invalid */
4030 + inode = ilookup(sb, ibusy.ino);
4032 + || inode->i_ino == AUFS_ROOT_INO
4033 + || au_is_bad_inode(inode))
4036 + ii_read_lock_child(inode);
4037 + btop = au_ibtop(inode);
4038 + bbot = au_ibbot(inode);
4039 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4040 + h_inode = au_h_iptr(inode, ibusy.bindex);
4041 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4042 + ibusy.h_ino = h_inode->i_ino;
4044 + ii_read_unlock(inode);
4048 + si_read_unlock(sb);
4050 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4051 + if (unlikely(err)) {
4060 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4062 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4065 +#ifdef CONFIG_COMPAT
4066 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4068 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4072 +/* ---------------------------------------------------------------------- */
4075 + * change a branch permission
4078 +static void au_warn_ima(void)
4081 + /* since it doesn't support mark_files_ro() */
4082 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4086 +static int do_need_sigen_inc(int a, int b)
4088 + return au_br_whable(a) && !au_br_whable(b);
4091 +static int need_sigen_inc(int old, int new)
4093 + return do_need_sigen_inc(old, new)
4094 + || do_need_sigen_inc(new, old);
4097 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4100 + unsigned int mnt_flags;
4101 + unsigned long long ull, max;
4102 + aufs_bindex_t br_id;
4103 + unsigned char verbose, writer;
4104 + struct file *file, *hf, **array;
4105 + struct au_hfile *hfile;
4106 + struct inode *h_inode;
4108 + mnt_flags = au_mntflags(sb);
4109 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4111 + array = au_farray_alloc(sb, &max);
4112 + err = PTR_ERR(array);
4113 + if (IS_ERR(array))
4117 + br_id = au_sbr_id(sb, bindex);
4118 + for (ull = 0; ull < max; ull++) {
4119 + file = array[ull];
4120 + if (unlikely(!file))
4123 + /* AuDbg("%pD\n", file); */
4124 + fi_read_lock(file);
4125 + if (unlikely(au_test_mmapped(file))) {
4127 + AuVerbose(verbose, "mmapped %pD\n", file);
4129 + FiMustNoWaiters(file);
4130 + fi_read_unlock(file);
4134 + hfile = &au_fi(file)->fi_htop;
4135 + hf = hfile->hf_file;
4136 + if (!d_is_reg(file->f_path.dentry)
4137 + || !(file->f_mode & FMODE_WRITE)
4138 + || hfile->hf_br->br_id != br_id
4139 + || !(hf->f_mode & FMODE_WRITE))
4140 + array[ull] = NULL;
4146 + FiMustNoWaiters(file);
4147 + fi_read_unlock(file);
4155 + for (ull = 0; ull < max; ull++) {
4156 + file = array[ull];
4160 + /* todo: already flushed? */
4162 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4163 + * approach which resets f_mode and calls mnt_drop_write() and
4164 + * file_release_write() for each file, because the branch
4165 + * attribute in aufs world is totally different from the native
4168 + /* fi_read_lock(file); */
4169 + hfile = &au_fi(file)->fi_htop;
4170 + hf = hfile->hf_file;
4171 + /* fi_read_unlock(file); */
4172 + spin_lock(&hf->f_lock);
4173 + writer = !!(hf->f_mode & FMODE_WRITER);
4174 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4175 + spin_unlock(&hf->f_lock);
4177 + h_inode = file_inode(hf);
4178 + if (hf->f_mode & FMODE_READ)
4179 + i_readcount_inc(h_inode);
4180 + put_write_access(h_inode);
4181 + __mnt_drop_write(hf->f_path.mnt);
4186 + au_farray_free(array, max);
4192 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4196 + aufs_bindex_t bindex;
4197 + struct dentry *root;
4198 + struct au_branch *br;
4199 + struct au_br_fhsm *bf;
4201 + root = sb->s_root;
4202 + bindex = au_find_dbindex(root, mod->h_root);
4205 + return 0; /* success */
4207 + pr_err("%s no such branch\n", mod->path);
4210 + AuDbg("bindex b%d\n", bindex);
4212 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4213 + if (unlikely(err))
4216 + br = au_sbr(sb, bindex);
4217 + AuDebugOn(mod->h_root != au_br_dentry(br));
4218 + if (br->br_perm == mod->perm)
4219 + return 0; /* success */
4221 + /* pre-allocate for non-fhsm --> fhsm */
4223 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4224 + err = au_fhsm_br_alloc(br);
4225 + if (unlikely(err))
4228 + br->br_fhsm = NULL;
4231 + if (au_br_writable(br->br_perm)) {
4232 + /* remove whiteout base */
4233 + err = au_br_init_wh(sb, br, mod->perm);
4234 + if (unlikely(err))
4237 + if (!au_br_writable(mod->perm)) {
4238 + /* rw --> ro, file might be mmapped */
4239 + DiMustNoWaiters(root);
4240 + IiMustNoWaiters(d_inode(root));
4241 + di_write_unlock(root);
4242 + err = au_br_mod_files_ro(sb, bindex);
4243 + /* aufs_write_lock() calls ..._child() */
4244 + di_write_lock_child(root);
4246 + if (unlikely(err)) {
4248 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4251 + rerr = au_wbr_init(br, sb, br->br_perm);
4252 + if (unlikely(rerr)) {
4253 + AuIOErr("nested error %d (%d)\n",
4255 + br->br_perm = mod->perm;
4259 + } else if (au_br_writable(mod->perm)) {
4262 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4264 + err = au_wbr_init(br, sb, mod->perm);
4265 + if (unlikely(err)) {
4266 + au_kfree_rcu(br->br_wbr);
4267 + br->br_wbr = NULL;
4271 + if (unlikely(err))
4274 + if (au_br_fhsm(br->br_perm)) {
4275 + if (!au_br_fhsm(mod->perm)) {
4276 + /* fhsm --> non-fhsm */
4277 + au_br_fhsm_fin(br->br_fhsm);
4278 + au_kfree_rcu(br->br_fhsm);
4279 + br->br_fhsm = NULL;
4281 + } else if (au_br_fhsm(mod->perm))
4282 + /* non-fhsm --> fhsm */
4285 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4286 + br->br_perm = mod->perm;
4287 + goto out; /* success */
4290 + au_kfree_try_rcu(bf);
4296 +/* ---------------------------------------------------------------------- */
4298 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4301 + struct kstatfs kstfs;
4303 + err = vfs_statfs(&br->br_path, &kstfs);
4305 + stfs->f_blocks = kstfs.f_blocks;
4306 + stfs->f_bavail = kstfs.f_bavail;
4307 + stfs->f_files = kstfs.f_files;
4308 + stfs->f_ffree = kstfs.f_ffree;
4313 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4314 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4315 +++ linux/fs/aufs/branch.h 2021-12-03 15:40:58.233313963 +0100
4317 +/* SPDX-License-Identifier: GPL-2.0 */
4319 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4321 + * This program, aufs is free software; you can redistribute it and/or modify
4322 + * it under the terms of the GNU General Public License as published by
4323 + * the Free Software Foundation; either version 2 of the License, or
4324 + * (at your option) any later version.
4326 + * This program is distributed in the hope that it will be useful,
4327 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4329 + * GNU General Public License for more details.
4331 + * You should have received a copy of the GNU General Public License
4332 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4336 + * branch filesystems and xino for them
4339 +#ifndef __AUFS_BRANCH_H__
4340 +#define __AUFS_BRANCH_H__
4344 +#include <linux/mount.h>
4345 +#include "dirren.h"
4351 +/* ---------------------------------------------------------------------- */
4355 + struct file **xi_file;
4356 + unsigned int xi_nfile;
4362 + /* reserved for future use */
4363 + /* unsigned long *bitmap; */
4364 + wait_queue_head_t wqh;
4367 + struct mutex xi_mtx; /* protects xi_file array */
4368 + struct hlist_bl_head xi_writing;
4370 + atomic_t xi_truncating;
4372 + struct kref xi_kref;
4375 +/* File-based Hierarchical Storage Management */
4376 +struct au_br_fhsm {
4377 +#ifdef CONFIG_AUFS_FHSM
4378 + struct mutex bf_lock;
4379 + unsigned long bf_jiffy;
4380 + struct aufs_stfs bf_stfs;
4385 +/* members for writable branch only */
4386 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4388 + struct au_rwsem wbr_wh_rwsem;
4389 + struct dentry *wbr_wh[AuBrWh_Last];
4390 + atomic_t wbr_wh_running;
4391 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4392 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4393 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4396 + unsigned long long wbr_bytes;
4399 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4400 +#define AuBrDynOp (AuDyLast * 4)
4402 +#ifdef CONFIG_AUFS_HFSNOTIFY
4403 +/* support for asynchronous destruction */
4404 +struct au_br_hfsnotify {
4405 + struct fsnotify_group *hfsn_group;
4409 +/* sysfs entries */
4410 +struct au_brsysfs {
4412 + struct attribute attr;
4421 +/* protected by superblock rwsem */
4423 + struct au_xino *br_xino;
4425 + aufs_bindex_t br_id;
4428 + struct path br_path;
4429 + spinlock_t br_dykey_lock;
4430 + struct au_dykey *br_dykey[AuBrDynOp];
4431 + au_lcnt_t br_nfiles; /* opened files */
4432 + au_lcnt_t br_count; /* in-use for other */
4434 + struct au_wbr *br_wbr;
4435 + struct au_br_fhsm *br_fhsm;
4437 +#ifdef CONFIG_AUFS_HFSNOTIFY
4438 + struct au_br_hfsnotify *br_hfsn;
4441 +#ifdef CONFIG_SYSFS
4442 + /* entries under sysfs per mount-point */
4443 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4446 +#ifdef CONFIG_DEBUG_FS
4447 + struct dentry *br_dbgaufs; /* xino */
4450 + struct au_dr_br br_dirren;
4453 +/* ---------------------------------------------------------------------- */
4455 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4457 + return br->br_path.mnt;
4460 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4462 + return br->br_path.dentry;
4465 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4467 + return mnt_user_ns(br->br_path.mnt);
4470 +static inline struct super_block *au_br_sb(struct au_branch *br)
4472 + return au_br_mnt(br)->mnt_sb;
4475 +static inline int au_br_rdonly(struct au_branch *br)
4477 + return (sb_rdonly(au_br_sb(br))
4478 + || !au_br_writable(br->br_perm))
4482 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4484 +#ifdef CONFIG_AUFS_HNOTIFY
4485 + return !(brperm & AuBrPerm_RR);
4491 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4493 + int err, exec_flag;
4496 + exec_flag = oflag & __FMODE_EXEC;
4497 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4503 +static inline void au_xino_get(struct au_branch *br)
4505 + struct au_xino *xi;
4509 + kref_get(&xi->xi_kref);
4512 +static inline int au_xino_count(struct au_branch *br)
4515 + struct au_xino *xi;
4520 + v = kref_read(&xi->xi_kref);
4525 +/* ---------------------------------------------------------------------- */
4529 +void au_br_free(struct au_sbinfo *sinfo);
4530 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4532 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4534 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4535 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4536 +#ifdef CONFIG_COMPAT
4537 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4540 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4543 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4546 +static const loff_t au_loff_max = LLONG_MAX;
4548 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4549 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4551 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4552 + struct file *copy_src);
4554 + struct au_xino *xi; /* switch between xino and xigen */
4556 + struct path *base;
4557 + struct file *copy_src;
4559 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4561 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4563 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4565 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4566 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4568 +int au_xib_trunc(struct super_block *sb);
4569 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4571 +struct au_xino *au_xino_alloc(unsigned int nfile);
4572 +int au_xino_put(struct au_branch *br);
4573 +struct file *au_xino_file1(struct au_xino *xi);
4575 +struct au_opt_xino;
4576 +void au_xino_clr(struct super_block *sb);
4577 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4578 +struct file *au_xino_def(struct super_block *sb);
4579 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4580 + struct path *base);
4582 +ino_t au_xino_new_ino(struct super_block *sb);
4583 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4585 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4586 + ino_t h_ino, int idx);
4587 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4590 +int au_xino_path(struct seq_file *seq, struct file *file);
4592 +/* ---------------------------------------------------------------------- */
4594 +/* @idx is signed to accept -1 meaning the first file */
4595 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4597 + struct file *file;
4604 + if (idx < xi->xi_nfile)
4605 + file = xi->xi_file[idx];
4607 + file = au_xino_file1(xi);
4613 +/* ---------------------------------------------------------------------- */
4615 +/* Superblock to branch */
4617 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4619 + return au_sbr(sb, bindex)->br_id;
4623 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4625 + return au_br_mnt(au_sbr(sb, bindex));
4629 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4631 + return au_br_userns(au_sbr(sb, bindex));
4635 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4637 + return au_br_sb(au_sbr(sb, bindex));
4640 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4642 + return au_sbr(sb, bindex)->br_perm;
4645 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4647 + return au_br_whable(au_sbr_perm(sb, bindex));
4650 +/* ---------------------------------------------------------------------- */
4652 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4653 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4654 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4655 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4657 +#define wbr_wh_read_trylock_nested(wbr) \
4658 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4659 +#define wbr_wh_write_trylock_nested(wbr) \
4660 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4663 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4664 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4665 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4667 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4668 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4669 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4671 +/* ---------------------------------------------------------------------- */
4673 +#ifdef CONFIG_AUFS_FHSM
4674 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4676 + mutex_init(&brfhsm->bf_lock);
4677 + brfhsm->bf_jiffy = 0;
4678 + brfhsm->bf_readable = 0;
4681 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4683 + mutex_destroy(&brfhsm->bf_lock);
4686 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4687 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4690 +#endif /* __KERNEL__ */
4691 +#endif /* __AUFS_BRANCH_H__ */
4692 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4693 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4694 +++ linux/fs/aufs/conf.mk 2021-12-03 15:38:59.933313976 +0100
4696 +# SPDX-License-Identifier: GPL-2.0
4698 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4702 +AuConfStr += ${1}=${${1}}
4706 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4708 + HNOTIFY HFSNOTIFY \
4720 +$(foreach i, ${AuConfAll}, \
4721 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4723 +AuConfName = ${obj}/conf.str
4724 +${AuConfName}.tmp: FORCE
4725 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4726 +${AuConfName}: ${AuConfName}.tmp
4727 + @diff -q $< $@ > /dev/null 2>&1 || { \
4728 + echo ' GEN ' $@; \
4732 +clean-files += ${AuConfName} ${AuConfName}.tmp
4733 +${obj}/sysfs.o: ${AuConfName}
4735 +-include ${srctree}/${src}/conf_priv.mk
4736 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4737 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4738 +++ linux/fs/aufs/cpup.c 2021-12-03 15:40:58.233313963 +0100
4740 +// SPDX-License-Identifier: GPL-2.0
4742 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4744 + * This program, aufs is free software; you can redistribute it and/or modify
4745 + * it under the terms of the GNU General Public License as published by
4746 + * the Free Software Foundation; either version 2 of the License, or
4747 + * (at your option) any later version.
4749 + * This program is distributed in the hope that it will be useful,
4750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4752 + * GNU General Public License for more details.
4754 + * You should have received a copy of the GNU General Public License
4755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4759 + * copy-up functions, see wbr_policy.c for copy-down
4762 +#include <linux/fs_stack.h>
4763 +#include <linux/mm.h>
4764 +#include <linux/task_work.h>
4767 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4769 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4770 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4772 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4774 + dst->i_flags |= iflags & ~mask;
4775 + if (au_test_fs_notime(dst->i_sb))
4776 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4779 +void au_cpup_attr_timesizes(struct inode *inode)
4781 + struct inode *h_inode;
4783 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4784 + fsstack_copy_attr_times(inode, h_inode);
4785 + fsstack_copy_inode_size(inode, h_inode);
4788 +void au_cpup_attr_nlink(struct inode *inode, int force)
4790 + struct inode *h_inode;
4791 + struct super_block *sb;
4792 + aufs_bindex_t bindex, bbot;
4795 + bindex = au_ibtop(inode);
4796 + h_inode = au_h_iptr(inode, bindex);
4798 + && !S_ISDIR(h_inode->i_mode)
4799 + && au_opt_test(au_mntflags(sb), PLINK)
4800 + && au_plink_test(inode))
4804 + * 0 can happen in revalidating.
4805 + * h_inode->i_mutex may not be held here, but it is harmless since once
4806 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4808 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4809 + * the incorrect link count.
4811 + set_nlink(inode, h_inode->i_nlink);
4814 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4815 + * it may includes whplink directory.
4817 + if (S_ISDIR(h_inode->i_mode)) {
4818 + bbot = au_ibbot(inode);
4819 + for (bindex++; bindex <= bbot; bindex++) {
4820 + h_inode = au_h_iptr(inode, bindex);
4822 + au_add_nlink(inode, h_inode);
4827 +void au_cpup_attr_changeable(struct inode *inode)
4829 + struct inode *h_inode;
4831 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4832 + inode->i_mode = h_inode->i_mode;
4833 + inode->i_uid = h_inode->i_uid;
4834 + inode->i_gid = h_inode->i_gid;
4835 + au_cpup_attr_timesizes(inode);
4836 + au_cpup_attr_flags(inode, h_inode->i_flags);
4839 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4841 + struct au_iinfo *iinfo = au_ii(inode);
4843 + IiMustWriteLock(inode);
4845 + iinfo->ii_higen = h_inode->i_generation;
4846 + iinfo->ii_hsb1 = h_inode->i_sb;
4849 +void au_cpup_attr_all(struct inode *inode, int force)
4851 + struct inode *h_inode;
4853 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4854 + au_cpup_attr_changeable(inode);
4855 + if (inode->i_nlink > 0)
4856 + au_cpup_attr_nlink(inode, force);
4857 + inode->i_rdev = h_inode->i_rdev;
4858 + inode->i_blkbits = h_inode->i_blkbits;
4859 + au_cpup_igen(inode, h_inode);
4862 +/* ---------------------------------------------------------------------- */
4864 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4866 +/* keep the timestamps of the parent dir when cpup */
4867 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4868 + struct path *h_path)
4870 + struct inode *h_inode;
4872 + dt->dt_dentry = dentry;
4873 + dt->dt_h_path = *h_path;
4874 + h_inode = d_inode(h_path->dentry);
4875 + dt->dt_atime = h_inode->i_atime;
4876 + dt->dt_mtime = h_inode->i_mtime;
4880 +void au_dtime_revert(struct au_dtime *dt)
4882 + struct iattr attr;
4885 + attr.ia_atime = dt->dt_atime;
4886 + attr.ia_mtime = dt->dt_mtime;
4887 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4888 + | ATTR_ATIME | ATTR_ATIME_SET;
4890 + /* no delegation since this is a directory */
4891 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4892 + if (unlikely(err))
4893 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4896 +/* ---------------------------------------------------------------------- */
4898 +/* internal use only */
4899 +struct au_cpup_reg_attr {
4902 + unsigned int iflags; /* inode->i_flags */
4905 +static noinline_for_stack
4906 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4907 + struct au_cpup_reg_attr *h_src_attr)
4909 + int err, sbits, icex;
4910 + unsigned int mnt_flags;
4911 + unsigned char verbose;
4913 + struct path h_path;
4914 + struct inode *h_isrc, *h_idst;
4915 + struct kstat *h_st;
4916 + struct au_branch *br;
4918 + br = au_sbr(dst->d_sb, bindex);
4919 + h_path.mnt = au_br_mnt(br);
4920 + h_path.dentry = au_h_dptr(dst, bindex);
4921 + h_idst = d_inode(h_path.dentry);
4922 + h_isrc = d_inode(h_src->dentry);
4923 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4924 + | ATTR_ATIME | ATTR_MTIME
4925 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4926 + if (h_src_attr && h_src_attr->valid) {
4927 + h_st = &h_src_attr->st;
4928 + ia.ia_uid = h_st->uid;
4929 + ia.ia_gid = h_st->gid;
4930 + ia.ia_atime = h_st->atime;
4931 + ia.ia_mtime = h_st->mtime;
4932 + if (h_idst->i_mode != h_st->mode
4933 + && !S_ISLNK(h_idst->i_mode)) {
4934 + ia.ia_valid |= ATTR_MODE;
4935 + ia.ia_mode = h_st->mode;
4937 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4938 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4940 + ia.ia_uid = h_isrc->i_uid;
4941 + ia.ia_gid = h_isrc->i_gid;
4942 + ia.ia_atime = h_isrc->i_atime;
4943 + ia.ia_mtime = h_isrc->i_mtime;
4944 + if (h_idst->i_mode != h_isrc->i_mode
4945 + && !S_ISLNK(h_idst->i_mode)) {
4946 + ia.ia_valid |= ATTR_MODE;
4947 + ia.ia_mode = h_isrc->i_mode;
4949 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4950 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4952 + /* no delegation since it is just created */
4953 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4955 + /* is this nfs only? */
4956 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4957 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4958 + ia.ia_mode = h_isrc->i_mode;
4959 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4962 + icex = br->br_perm & AuBrAttr_ICEX;
4964 + mnt_flags = au_mntflags(dst->d_sb);
4965 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4966 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4972 +/* ---------------------------------------------------------------------- */
4974 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4975 + char *buf, unsigned long blksize)
4978 + size_t sz, rbytes, wbytes;
4979 + unsigned char all_zero;
4981 + struct inode *h_inode;
4982 + /* reduce stack usage */
4985 + zp = page_address(ZERO_PAGE(0));
4986 + if (unlikely(!zp))
4987 + return -ENOMEM; /* possible? */
4992 + AuDbg("len %lld\n", len);
4994 + if (len < blksize)
4998 + /* todo: signal_pending? */
4999 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5000 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5003 + if (unlikely(err < 0))
5007 + if (len >= rbytes && rbytes == blksize)
5008 + all_zero = !memcmp(buf, zp, rbytes);
5015 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5017 + /* todo: signal_pending? */
5018 + if (unlikely(err == -EAGAIN || err == -EINTR))
5020 + if (unlikely(err < 0))
5025 + if (unlikely(err < 0))
5031 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5033 + if (unlikely(res < 0))
5040 + /* the last block may be a hole */
5041 + if (!err && all_zero) {
5042 + AuLabel(last hole);
5045 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5046 + /* nfs requires this step to make last hole */
5047 + /* is this only nfs? */
5049 + /* todo: signal_pending? */
5050 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5051 + } while (err == -EAGAIN || err == -EINTR);
5058 + ia->ia_size = dst->f_pos;
5059 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5060 + ia->ia_file = dst;
5061 + h_inode = file_inode(dst);
5062 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5063 + /* no delegation since it is just created */
5064 + err = vfsub_notify_change(&dst->f_path, ia,
5065 + /*delegated*/NULL);
5066 + inode_unlock(h_inode);
5073 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5076 + unsigned long blksize;
5077 + unsigned char do_kfree;
5079 + struct super_block *h_sb;
5082 + h_sb = file_inode(dst)->i_sb;
5083 + blksize = h_sb->s_blocksize;
5084 + if (!blksize || PAGE_SIZE < blksize)
5085 + blksize = PAGE_SIZE;
5086 + AuDbg("blksize %lu\n", blksize);
5087 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5089 + buf = kmalloc(blksize, GFP_NOFS);
5091 + buf = (void *)__get_free_page(GFP_NOFS);
5092 + if (unlikely(!buf))
5095 + if (len > (1 << 22))
5096 + AuDbg("copying a large file %lld\n", (long long)len);
5100 + err = au_do_copy_file(dst, src, len, buf, blksize);
5102 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5103 + au_kfree_do_rcu(buf);
5105 + free_page((unsigned long)buf);
5111 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5114 + struct super_block *h_src_sb;
5115 + struct inode *h_src_inode;
5117 + h_src_inode = file_inode(src);
5118 + h_src_sb = h_src_inode->i_sb;
5120 + /* XFS acquires inode_lock */
5121 + if (!au_test_xfs(h_src_sb))
5122 + err = au_copy_file(dst, src, len);
5124 + inode_unlock_shared(h_src_inode);
5125 + err = au_copy_file(dst, src, len);
5126 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5132 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5136 + struct super_block *h_src_sb;
5137 + struct inode *h_src_inode;
5139 + h_src_inode = file_inode(src);
5140 + h_src_sb = h_src_inode->i_sb;
5141 + if (h_src_sb != file_inode(dst)->i_sb
5142 + || !dst->f_op->remap_file_range) {
5143 + err = au_do_copy(dst, src, len);
5147 + if (!au_test_nfs(h_src_sb)) {
5148 + inode_unlock_shared(h_src_inode);
5149 + lo = vfsub_clone_file_range(src, dst, len);
5150 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5152 + lo = vfsub_clone_file_range(src, dst, len);
5155 + goto out; /* success */
5156 + } else if (lo >= 0)
5157 + /* todo: possible? */
5158 + /* paritially succeeded */
5159 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5160 + else if (lo != -EOPNOTSUPP) {
5161 + /* older XFS has a condition in cloning */
5166 + /* the backend fs on NFS may not support cloning */
5167 + err = au_do_copy(dst, src, len);
5175 + * to support a sparse file which is opened with O_APPEND,
5176 + * we need to close the file.
5178 +static int au_cp_regular(struct au_cp_generic *cpg)
5181 + enum { SRC, DST };
5183 + aufs_bindex_t bindex;
5184 + unsigned int flags;
5185 + struct dentry *dentry;
5187 + struct file *file;
5190 + .bindex = cpg->bsrc,
5191 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5194 + .bindex = cpg->bdst,
5195 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5196 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5199 + struct au_branch *br;
5200 + struct super_block *sb, *h_src_sb;
5201 + struct inode *h_src_inode;
5202 + struct task_struct *tsk = current;
5204 + /* bsrc branch can be ro/rw. */
5205 + sb = cpg->dentry->d_sb;
5207 + for (i = 0; i < 2; i++, f++) {
5208 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5209 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5210 + /*file*/NULL, f->force_wr);
5211 + if (IS_ERR(f->file)) {
5212 + err = PTR_ERR(f->file);
5220 + /* try stopping to update while we copyup */
5221 + h_src_inode = d_inode(file[SRC].dentry);
5222 + h_src_sb = h_src_inode->i_sb;
5223 + if (!au_test_nfs(h_src_sb))
5224 + IMustLock(h_src_inode);
5225 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5227 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5228 + if (tsk->flags & PF_KTHREAD)
5229 + __fput_sync(file[DST].file);
5231 + /* it happened actually */
5232 + fput(file[DST].file);
5235 + * we have to call both since we don't know which place the file
5239 + flush_delayed_fput();
5241 + br = au_sbr(sb, file[DST].bindex);
5242 + au_lcnt_dec(&br->br_nfiles);
5245 + fput(file[SRC].file);
5246 + br = au_sbr(sb, file[SRC].bindex);
5247 + au_lcnt_dec(&br->br_nfiles);
5252 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5253 + struct au_cpup_reg_attr *h_src_attr)
5257 + struct path h_path;
5258 + struct inode *h_src_inode, *h_dst_inode;
5261 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5262 + l = i_size_read(h_src_inode);
5263 + if (cpg->len == -1 || l < cpg->len)
5266 + /* try stopping to update while we are referencing */
5267 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5268 + au_pin_hdir_unlock(cpg->pin);
5270 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5271 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5272 + h_src_attr->iflags = h_src_inode->i_flags;
5273 + if (!au_test_nfs(h_src_inode->i_sb))
5274 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5276 + inode_unlock_shared(h_src_inode);
5277 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5278 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5280 + if (unlikely(err)) {
5281 + inode_unlock_shared(h_src_inode);
5284 + h_src_attr->valid = 1;
5285 + if (!au_test_nfs(h_src_inode->i_sb)) {
5286 + err = au_cp_regular(cpg);
5287 + inode_unlock_shared(h_src_inode);
5289 + inode_unlock_shared(h_src_inode);
5290 + err = au_cp_regular(cpg);
5292 + rerr = au_pin_hdir_relock(cpg->pin);
5296 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5297 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5298 + h_dst_inode = d_inode(h_path.dentry);
5299 + spin_lock(&h_dst_inode->i_lock);
5300 + h_dst_inode->i_state |= I_LINKABLE;
5301 + spin_unlock(&h_dst_inode->i_lock);
5308 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5309 + struct inode *h_dir)
5312 + DEFINE_DELAYED_CALL(done);
5315 + sym = vfs_get_link(h_src, &done);
5316 + err = PTR_ERR(sym);
5320 + err = vfsub_symlink(h_dir, h_path, sym);
5323 + do_delayed_call(&done);
5328 + * regardless 'acl' option, reset all ACL.
5329 + * All ACL will be copied up later from the original entry on the lower branch.
5331 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5334 + struct dentry *h_dentry;
5335 + struct inode *h_inode;
5336 + struct user_namespace *h_userns;
5338 + h_userns = mnt_user_ns(h_path->mnt);
5339 + h_dentry = h_path->dentry;
5340 + h_inode = d_inode(h_dentry);
5341 + /* forget_all_cached_acls(h_inode)); */
5342 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5344 + if (err == -EOPNOTSUPP)
5347 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5353 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5354 + struct inode *h_dir, struct path *h_path)
5357 + struct inode *dir, *inode;
5358 + struct user_namespace *h_userns;
5360 + h_userns = mnt_user_ns(h_path->mnt);
5361 + err = vfsub_removexattr(h_userns, h_path->dentry,
5362 + XATTR_NAME_POSIX_ACL_DEFAULT);
5364 + if (err == -EOPNOTSUPP)
5366 + if (unlikely(err))
5370 + * strange behaviour from the users view,
5371 + * particularly setattr case
5373 + dir = d_inode(dst_parent);
5374 + if (au_ibtop(dir) == cpg->bdst)
5375 + au_cpup_attr_nlink(dir, /*force*/1);
5376 + inode = d_inode(cpg->dentry);
5377 + au_cpup_attr_nlink(inode, /*force*/1);
5383 +static noinline_for_stack
5384 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5385 + struct au_cpup_reg_attr *h_src_attr)
5389 + unsigned int mnt_flags;
5390 + unsigned char isdir, isreg, force;
5391 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5392 + struct au_dtime dt;
5393 + struct path h_path;
5394 + struct dentry *h_src, *h_dst, *h_parent;
5395 + struct inode *h_inode, *h_dir;
5396 + struct super_block *sb;
5398 + /* bsrc branch can be ro/rw. */
5399 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5400 + h_inode = d_inode(h_src);
5401 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5403 + /* try stopping to be referenced while we are creating */
5404 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5405 + if (au_ftest_cpup(cpg->flags, RENAME))
5406 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5407 + AUFS_WH_PFX_LEN));
5408 + h_parent = h_dst->d_parent; /* dir inode is locked */
5409 + h_dir = d_inode(h_parent);
5411 + AuDebugOn(h_parent != h_dst->d_parent);
5413 + sb = cpg->dentry->d_sb;
5414 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5416 + h_path.dentry = h_parent;
5417 + au_dtime_store(&dt, dst_parent, &h_path);
5419 + h_path.dentry = h_dst;
5423 + mode = h_inode->i_mode;
5424 + switch (mode & S_IFMT) {
5427 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5429 + err = au_do_cpup_regular(cpg, h_src_attr);
5433 + err = vfsub_mkdir(h_dir, &h_path, mode);
5435 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5438 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5442 + AuDebugOn(!capable(CAP_MKNOD));
5446 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5449 + AuIOErr("Unknown inode type 0%o\n", mode);
5453 + err = au_reset_acl(h_dir, &h_path, mode);
5455 + mnt_flags = au_mntflags(sb);
5456 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5458 + && au_opt_test(mnt_flags, XINO)
5459 + && (h_inode->i_nlink == 1
5460 + || (h_inode->i_state & I_LINKABLE))
5461 + /* todo: unnecessary? */
5462 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5463 + && cpg->bdst < cpg->bsrc
5464 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5465 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5466 + /* ignore this error */
5471 + force = !!cpg->len;
5472 + if (cpg->len == -1)
5473 + force = !!i_size_read(h_inode);
5475 + au_fhsm_wrote(sb, cpg->bdst, force);
5479 + au_dtime_revert(&dt);
5483 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5486 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5487 + struct path h_ppath;
5488 + struct inode *h_dir;
5489 + aufs_bindex_t bdst;
5491 + dentry = cpg->dentry;
5493 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5494 + h_dentry = au_h_dptr(dentry, bdst);
5495 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5497 + au_set_h_dptr(dentry, bdst, NULL);
5498 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5500 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5501 + au_set_h_dptr(dentry, bdst, h_dentry);
5504 + parent = dget_parent(dentry);
5505 + h_ppath.dentry = au_h_dptr(parent, bdst);
5507 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5508 + if (IS_ERR(h_path->dentry))
5509 + err = PTR_ERR(h_path->dentry);
5511 + if (unlikely(err))
5514 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5515 + h_dir = d_inode(h_parent);
5517 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5518 + /* no delegation since it is just created */
5519 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5521 + dput(h_path->dentry);
5528 + * copyup the @dentry from @bsrc to @bdst.
5529 + * the caller must set the both of lower dentries.
5530 + * @len is for truncating when it is -1 copyup the entire file.
5531 + * in link/rename cases, @dst_parent may be different from the real one.
5532 + * basic->bsrc can be larger than basic->bdst.
5533 + * aufs doesn't touch the credential so
5534 + * security_inode_copy_up{,_xattr}() are unnecessary.
5536 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5539 + aufs_bindex_t old_ibtop;
5540 + unsigned char isdir, plink;
5541 + struct dentry *h_src, *h_dst, *h_parent;
5542 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5543 + struct super_block *sb;
5544 + struct au_branch *br;
5545 + struct path h_src_path;
5546 + /* to reduce stack size */
5548 + struct au_dtime dt;
5549 + struct path h_path;
5550 + struct au_cpup_reg_attr h_src_attr;
5554 + a = kmalloc(sizeof(*a), GFP_NOFS);
5557 + a->h_src_attr.valid = 0;
5559 + sb = cpg->dentry->d_sb;
5560 + br = au_sbr(sb, cpg->bdst);
5561 + a->h_path.mnt = au_br_mnt(br);
5562 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5563 + h_parent = h_dst->d_parent; /* dir inode is locked */
5564 + h_dir = d_inode(h_parent);
5567 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5568 + inode = d_inode(cpg->dentry);
5571 + dst_parent = dget_parent(cpg->dentry);
5575 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5576 + dst_inode = au_h_iptr(inode, cpg->bdst);
5578 + if (unlikely(!plink)) {
5580 + AuIOErr("hi%lu(i%lu) exists on b%d "
5581 + "but plink is disabled\n",
5582 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5586 + if (dst_inode->i_nlink) {
5587 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5589 + h_src = au_plink_lkup(inode, cpg->bdst);
5590 + err = PTR_ERR(h_src);
5591 + if (IS_ERR(h_src))
5593 + if (unlikely(d_is_negative(h_src))) {
5595 + AuIOErr("i%lu exists on b%d "
5596 + "but not pseudo-linked\n",
5597 + inode->i_ino, cpg->bdst);
5603 + a->h_path.dentry = h_parent;
5604 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5607 + a->h_path.dentry = h_dst;
5609 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5610 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5611 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5613 + au_dtime_revert(&a->dt);
5614 + if (unlikely(err == -EWOULDBLOCK)) {
5615 + pr_warn("cannot retry for NFSv4 delegation"
5616 + " for an internal link\n");
5622 + /* todo: cpup_wh_file? */
5624 + au_update_ibrange(inode, /*do_put_zero*/1);
5627 + isdir = S_ISDIR(inode->i_mode);
5628 + old_ibtop = au_ibtop(inode);
5629 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5630 + if (unlikely(err))
5632 + dst_inode = d_inode(h_dst);
5633 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5634 + /* todo: necessary? */
5635 + /* au_pin_hdir_unlock(cpg->pin); */
5637 + h_src_path.dentry = h_src;
5638 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5639 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5640 + if (unlikely(err)) {
5641 + /* todo: necessary? */
5642 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5643 + inode_unlock(dst_inode);
5647 + if (cpg->bdst < old_ibtop) {
5648 + if (S_ISREG(inode->i_mode)) {
5649 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5650 + if (unlikely(err)) {
5651 + /* ignore an error */
5652 + /* au_pin_hdir_relock(cpg->pin); */
5653 + inode_unlock(dst_inode);
5657 + au_set_ibtop(inode, cpg->bdst);
5659 + au_set_ibbot(inode, cpg->bdst);
5660 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5661 + au_hi_flags(inode, isdir));
5663 + /* todo: necessary? */
5664 + /* err = au_pin_hdir_relock(cpg->pin); */
5665 + inode_unlock(dst_inode);
5666 + if (unlikely(err))
5669 + src_inode = d_inode(h_src);
5671 + && (src_inode->i_nlink > 1
5672 + || src_inode->i_state & I_LINKABLE)
5674 + au_plink_append(inode, cpg->bdst, h_dst);
5676 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5677 + a->h_path.dentry = h_dst;
5678 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5681 + goto out_parent; /* success */
5685 + a->h_path.dentry = h_parent;
5686 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5687 + a->h_path.dentry = h_dst;
5689 + if (d_is_positive(h_dst)) {
5691 + /* no delegation since it is just created */
5692 + rerr = vfsub_unlink(h_dir, &a->h_path,
5693 + /*delegated*/NULL, /*force*/0);
5695 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5697 + au_dtime_revert(&a->dt);
5699 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5709 +#if 0 /* reserved */
5710 +struct au_cpup_single_args {
5712 + struct au_cp_generic *cpg;
5713 + struct dentry *dst_parent;
5716 +static void au_call_cpup_single(void *args)
5718 + struct au_cpup_single_args *a = args;
5720 + au_pin_hdir_acquire_nest(a->cpg->pin);
5721 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5722 + au_pin_hdir_release(a->cpg->pin);
5727 + * prevent SIGXFSZ in copy-up.
5728 + * testing CAP_MKNOD is for generic fs,
5729 + * but CAP_FSETID is for xfs only, currently.
5731 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5734 + struct super_block *sb;
5735 + struct inode *h_dir;
5738 + sb = au_pinned_parent(pin)->d_sb;
5739 + if (!au_wkq_test()
5740 + && (!au_sbi(sb)->si_plink_maint_pid
5741 + || au_plink_maint(sb, AuLock_NOPLM))) {
5742 + switch (mode & S_IFMT) {
5744 + /* no condition about RLIMIT_FSIZE and the file size */
5749 + do_sio = !capable(CAP_MKNOD);
5753 + do_sio = ((mode & (S_ISUID | S_ISGID))
5754 + && !capable(CAP_FSETID));
5755 + /* this workaround may be removed in the future */
5757 + h_dir = au_pinned_h_dir(pin);
5758 + do_sio = h_dir->i_mode & S_ISVTX;
5765 +#if 0 /* reserved */
5766 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5769 + struct dentry *h_dentry;
5771 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5772 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5773 + err = au_cpup_single(cpg, dst_parent);
5775 + struct au_cpup_single_args args = {
5778 + .dst_parent = dst_parent
5780 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5781 + if (unlikely(wkq_err))
5790 + * copyup the @dentry from the first active lower branch to @bdst,
5791 + * using au_cpup_single().
5793 +static int au_cpup_simple(struct au_cp_generic *cpg)
5796 + unsigned int flags_orig;
5797 + struct dentry *dentry;
5799 + AuDebugOn(cpg->bsrc < 0);
5801 + dentry = cpg->dentry;
5802 + DiMustWriteLock(dentry);
5804 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5806 + flags_orig = cpg->flags;
5807 + au_fset_cpup(cpg->flags, RENAME);
5808 + err = au_cpup_single(cpg, NULL);
5809 + cpg->flags = flags_orig;
5811 + return 0; /* success */
5814 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5815 + au_set_dbtop(dentry, cpg->bsrc);
5821 +struct au_cpup_simple_args {
5823 + struct au_cp_generic *cpg;
5826 +static void au_call_cpup_simple(void *args)
5828 + struct au_cpup_simple_args *a = args;
5830 + au_pin_hdir_acquire_nest(a->cpg->pin);
5831 + *a->errp = au_cpup_simple(a->cpg);
5832 + au_pin_hdir_release(a->cpg->pin);
5835 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5838 + struct dentry *dentry, *parent;
5839 + struct file *h_file;
5840 + struct inode *h_dir;
5841 + struct user_namespace *h_userns;
5843 + dentry = cpg->dentry;
5845 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5846 + AuDebugOn(cpg->bsrc < 0);
5847 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5848 + err = PTR_ERR(h_file);
5849 + if (IS_ERR(h_file))
5853 + parent = dget_parent(dentry);
5854 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5855 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5856 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5857 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5858 + err = au_cpup_simple(cpg);
5860 + struct au_cpup_simple_args args = {
5864 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5865 + if (unlikely(wkq_err))
5871 + au_h_open_post(dentry, cpg->bsrc, h_file);
5877 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5879 + aufs_bindex_t bsrc, bbot;
5880 + struct dentry *dentry, *h_dentry;
5882 + if (cpg->bsrc < 0) {
5883 + dentry = cpg->dentry;
5884 + bbot = au_dbbot(dentry);
5885 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5886 + h_dentry = au_h_dptr(dentry, bsrc);
5888 + AuDebugOn(d_is_negative(h_dentry));
5892 + AuDebugOn(bsrc > bbot);
5895 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5896 + return au_do_sio_cpup_simple(cpg);
5899 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5901 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5902 + return au_do_sio_cpup_simple(cpg);
5905 +/* ---------------------------------------------------------------------- */
5908 + * copyup the deleted file for writing.
5910 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5911 + struct file *file)
5914 + unsigned int flags_orig;
5915 + aufs_bindex_t bsrc_orig;
5916 + struct au_dinfo *dinfo;
5918 + struct au_hdentry *hd;
5919 + struct dentry *h_dentry;
5922 + dinfo = au_di(cpg->dentry);
5923 + AuRwMustWriteLock(&dinfo->di_rwsem);
5925 + bsrc_orig = cpg->bsrc;
5926 + cpg->bsrc = dinfo->di_btop;
5927 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5928 + hdst.h_dentry = hdst.hd->hd_dentry;
5929 + hdst.hd->hd_dentry = wh_dentry;
5930 + dinfo->di_btop = cpg->bdst;
5932 + hsrc.h_dentry = NULL;
5934 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5935 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5936 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5938 + flags_orig = cpg->flags;
5939 + cpg->flags = !AuCpup_DTIME;
5940 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5941 + cpg->flags = flags_orig;
5944 + err = au_reopen_nondir(file);
5945 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5947 + hdst.hd->hd_dentry = hdst.h_dentry;
5948 + dinfo->di_btop = cpg->bsrc;
5949 + cpg->bsrc = bsrc_orig;
5954 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5957 + aufs_bindex_t bdst;
5958 + struct au_dtime dt;
5959 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5960 + struct au_branch *br;
5961 + struct path h_path;
5963 + dentry = cpg->dentry;
5965 + br = au_sbr(dentry->d_sb, bdst);
5966 + parent = dget_parent(dentry);
5967 + h_parent = au_h_dptr(parent, bdst);
5968 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5969 + err = PTR_ERR(wh_dentry);
5970 + if (IS_ERR(wh_dentry))
5973 + h_path.dentry = h_parent;
5974 + h_path.mnt = au_br_mnt(br);
5975 + au_dtime_store(&dt, parent, &h_path);
5976 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5977 + if (unlikely(err))
5981 + h_path.dentry = wh_dentry;
5982 + if (!d_is_dir(wh_dentry)) {
5983 + /* no delegation since it is just created */
5984 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5985 + /*delegated*/NULL, /*force*/0);
5987 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5988 + if (unlikely(err)) {
5989 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5993 + au_dtime_revert(&dt);
5994 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6003 +struct au_cpup_wh_args {
6005 + struct au_cp_generic *cpg;
6006 + struct file *file;
6009 +static void au_call_cpup_wh(void *args)
6011 + struct au_cpup_wh_args *a = args;
6013 + au_pin_hdir_acquire_nest(a->cpg->pin);
6014 + *a->errp = au_cpup_wh(a->cpg, a->file);
6015 + au_pin_hdir_release(a->cpg->pin);
6018 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6021 + aufs_bindex_t bdst;
6022 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6023 + struct inode *dir, *h_dir, *h_tmpdir;
6024 + struct au_wbr *wbr;
6025 + struct au_pin wh_pin, *pin_orig;
6026 + struct user_namespace *h_userns;
6028 + dentry = cpg->dentry;
6030 + parent = dget_parent(dentry);
6031 + dir = d_inode(parent);
6034 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6037 + if (!h_dir->i_nlink) {
6038 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6039 + h_orph = wbr->wbr_orph;
6041 + h_parent = dget(au_h_dptr(parent, bdst));
6042 + au_set_h_dptr(parent, bdst, dget(h_orph));
6043 + h_tmpdir = d_inode(h_orph);
6044 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6046 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6047 + /* todo: au_h_open_pre()? */
6049 + pin_orig = cpg->pin;
6050 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6051 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6052 + cpg->pin = &wh_pin;
6055 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6056 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6057 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6058 + err = au_cpup_wh(cpg, file);
6060 + struct au_cpup_wh_args args = {
6065 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6066 + if (unlikely(wkq_err))
6071 + inode_unlock(h_tmpdir);
6072 + /* todo: au_h_open_post()? */
6073 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6074 + au_set_h_dptr(parent, bdst, h_parent);
6075 + AuDebugOn(!pin_orig);
6076 + cpg->pin = pin_orig;
6084 +/* ---------------------------------------------------------------------- */
6087 + * generic routine for both of copy-up and copy-down.
6089 +/* cf. revalidate function in file.c */
6090 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6091 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6092 + struct au_pin *pin,
6093 + struct dentry *h_parent, void *arg),
6097 + struct au_pin pin;
6098 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6101 + parent = dget_parent(dentry);
6102 + if (IS_ROOT(parent))
6105 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6106 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6108 + /* do not use au_dpage */
6109 + real_parent = parent;
6112 + parent = dget_parent(dentry);
6113 + h_parent = au_h_dptr(parent, bdst);
6115 + goto out; /* success */
6117 + /* find top dir which is necessary to cpup */
6121 + parent = dget_parent(d);
6122 + di_read_lock_parent3(parent, !AuLock_IR);
6123 + h_parent = au_h_dptr(parent, bdst);
6124 + di_read_unlock(parent, !AuLock_IR);
6125 + } while (!h_parent);
6127 + if (d != real_parent)
6128 + di_write_lock_child3(d);
6130 + /* somebody else might create while we were sleeping */
6131 + h_dentry = au_h_dptr(d, bdst);
6132 + if (!h_dentry || d_is_negative(h_dentry)) {
6134 + au_update_dbtop(d);
6136 + au_pin_set_dentry(&pin, d);
6137 + err = au_do_pin(&pin);
6139 + err = cp(d, bdst, &pin, h_parent, arg);
6144 + if (d != real_parent)
6145 + di_write_unlock(d);
6146 + if (unlikely(err))
6155 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6156 + struct au_pin *pin,
6157 + struct dentry *h_parent __maybe_unused,
6158 + void *arg __maybe_unused)
6160 + struct au_cp_generic cpg = {
6166 + .flags = AuCpup_DTIME
6168 + return au_sio_cpup_simple(&cpg);
6171 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6173 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6176 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6179 + struct dentry *parent;
6180 + struct inode *dir;
6182 + parent = dget_parent(dentry);
6183 + dir = d_inode(parent);
6185 + if (au_h_iptr(dir, bdst))
6188 + di_read_unlock(parent, AuLock_IR);
6189 + di_write_lock_parent(parent);
6190 + /* someone else might change our inode while we were sleeping */
6191 + if (!au_h_iptr(dir, bdst))
6192 + err = au_cpup_dirs(dentry, bdst);
6193 + di_downgrade_lock(parent, AuLock_IR);
6199 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6200 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6201 +++ linux/fs/aufs/cpup.h 2021-12-03 15:38:59.933313976 +0100
6203 +/* SPDX-License-Identifier: GPL-2.0 */
6205 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6207 + * This program, aufs is free software; you can redistribute it and/or modify
6208 + * it under the terms of the GNU General Public License as published by
6209 + * the Free Software Foundation; either version 2 of the License, or
6210 + * (at your option) any later version.
6212 + * This program is distributed in the hope that it will be useful,
6213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6215 + * GNU General Public License for more details.
6217 + * You should have received a copy of the GNU General Public License
6218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6222 + * copy-up/down functions
6225 +#ifndef __AUFS_CPUP_H__
6226 +#define __AUFS_CPUP_H__
6230 +#include <linux/path.h>
6236 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6237 +void au_cpup_attr_timesizes(struct inode *inode);
6238 +void au_cpup_attr_nlink(struct inode *inode, int force);
6239 +void au_cpup_attr_changeable(struct inode *inode);
6240 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6241 +void au_cpup_attr_all(struct inode *inode, int force);
6243 +/* ---------------------------------------------------------------------- */
6245 +struct au_cp_generic {
6246 + struct dentry *dentry;
6247 + aufs_bindex_t bdst, bsrc;
6249 + struct au_pin *pin;
6250 + unsigned int flags;
6254 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6255 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6257 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6258 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6260 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6262 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6263 + the branch is marked as RO */
6265 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6266 +#undef AuCpup_HOPEN
6267 +#define AuCpup_HOPEN 0
6270 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6271 +#define au_fset_cpup(flags, name) \
6272 + do { (flags) |= AuCpup_##name; } while (0)
6273 +#define au_fclr_cpup(flags, name) \
6274 + do { (flags) &= ~AuCpup_##name; } while (0)
6276 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6277 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6278 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6279 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6281 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6282 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6283 + struct au_pin *pin,
6284 + struct dentry *h_parent, void *arg),
6286 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6287 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6289 +/* ---------------------------------------------------------------------- */
6291 +/* keep timestamps when copyup */
6293 + struct dentry *dt_dentry;
6294 + struct path dt_h_path;
6295 + struct timespec64 dt_atime, dt_mtime;
6297 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6298 + struct path *h_path);
6299 +void au_dtime_revert(struct au_dtime *dt);
6301 +#endif /* __KERNEL__ */
6302 +#endif /* __AUFS_CPUP_H__ */
6303 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6304 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6305 +++ linux/fs/aufs/dbgaufs.c 2021-12-03 15:38:59.933313976 +0100
6307 +// SPDX-License-Identifier: GPL-2.0
6309 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6311 + * This program, aufs is free software; you can redistribute it and/or modify
6312 + * it under the terms of the GNU General Public License as published by
6313 + * the Free Software Foundation; either version 2 of the License, or
6314 + * (at your option) any later version.
6316 + * This program is distributed in the hope that it will be useful,
6317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6319 + * GNU General Public License for more details.
6321 + * You should have received a copy of the GNU General Public License
6322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6326 + * debugfs interface
6329 +#include <linux/debugfs.h>
6332 +#ifndef CONFIG_SYSFS
6333 +#error DEBUG_FS depends upon SYSFS
6336 +static struct dentry *dbgaufs;
6337 +static const mode_t dbgaufs_mode = 0444;
6339 +/* 20 is max digits length of ulong 64 */
6340 +struct dbgaufs_arg {
6346 + * common function for all XINO files
6348 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6349 + struct file *file)
6353 + p = file->private_data;
6355 + /* this is struct dbgaufs_arg */
6356 + AuDebugOn(!au_kfree_sz_test(p));
6357 + au_kfree_do_rcu(p);
6362 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6367 + struct dbgaufs_arg *p;
6370 + p = kmalloc(sizeof(*p), GFP_NOFS);
6376 + file->private_data = p;
6380 + err = vfsub_getattr(&xf->f_path, &st);
6384 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6385 + cnt, st.blocks, st.blksize,
6386 + (long long)st.size);
6388 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6389 + st.blocks, st.blksize,
6390 + (long long)st.size);
6391 + AuDebugOn(p->n >= sizeof(p->a));
6393 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6401 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6402 + size_t count, loff_t *ppos)
6404 + struct dbgaufs_arg *p;
6406 + p = file->private_data;
6407 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6410 +/* ---------------------------------------------------------------------- */
6412 +struct dbgaufs_plink_arg {
6417 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6418 + struct file *file)
6420 + free_page((unsigned long)file->private_data);
6424 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6426 + int err, i, limit;
6427 + unsigned long n, sum;
6428 + struct dbgaufs_plink_arg *p;
6429 + struct au_sbinfo *sbinfo;
6430 + struct super_block *sb;
6431 + struct hlist_bl_head *hbl;
6434 + p = (void *)get_zeroed_page(GFP_NOFS);
6439 + sbinfo = inode->i_private;
6440 + sb = sbinfo->si_sb;
6441 + si_noflush_read_lock(sb);
6442 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6443 + limit = PAGE_SIZE - sizeof(p->n);
6445 + /* the number of buckets */
6446 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6451 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6453 + n = au_hbl_count(hbl);
6456 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6459 + if (unlikely(limit <= 0))
6462 + p->a[p->n - 1] = '\n';
6464 + /* the sum of plinks */
6465 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6468 + if (unlikely(limit <= 0))
6471 +#define str "1\n0\n0\n"
6472 + p->n = sizeof(str) - 1;
6473 + strcpy(p->a, str);
6476 + si_read_unlock(sb);
6479 + file->private_data = p;
6480 + goto out; /* success */
6483 + free_page((unsigned long)p);
6488 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6489 + size_t count, loff_t *ppos)
6491 + struct dbgaufs_plink_arg *p;
6493 + p = file->private_data;
6494 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6497 +static const struct file_operations dbgaufs_plink_fop = {
6498 + .owner = THIS_MODULE,
6499 + .open = dbgaufs_plink_open,
6500 + .release = dbgaufs_plink_release,
6501 + .read = dbgaufs_plink_read
6504 +/* ---------------------------------------------------------------------- */
6506 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6509 + struct au_sbinfo *sbinfo;
6510 + struct super_block *sb;
6512 + sbinfo = inode->i_private;
6513 + sb = sbinfo->si_sb;
6514 + si_noflush_read_lock(sb);
6515 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6516 + si_read_unlock(sb);
6520 +static const struct file_operations dbgaufs_xib_fop = {
6521 + .owner = THIS_MODULE,
6522 + .open = dbgaufs_xib_open,
6523 + .release = dbgaufs_xi_release,
6524 + .read = dbgaufs_xi_read
6527 +/* ---------------------------------------------------------------------- */
6529 +#define DbgaufsXi_PREFIX "xi"
6531 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6535 + aufs_bindex_t bindex;
6536 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6537 + struct au_sbinfo *sbinfo;
6538 + struct super_block *sb;
6539 + struct au_xino *xi;
6541 + struct qstr *name;
6542 + struct au_branch *br;
6545 + name = &file->f_path.dentry->d_name;
6546 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6547 + || memcmp(name->name, DbgaufsXi_PREFIX,
6548 + sizeof(DbgaufsXi_PREFIX) - 1)))
6551 + AuDebugOn(name->len >= sizeof(a));
6552 + memcpy(a, name->name, name->len);
6553 + a[name->len] = '\0';
6554 + p = strchr(a, '-');
6557 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6558 + if (unlikely(err))
6563 + err = kstrtol(p + 1, 10, &l);
6564 + if (unlikely(err))
6570 + sbinfo = inode->i_private;
6571 + sb = sbinfo->si_sb;
6572 + si_noflush_read_lock(sb);
6573 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6575 + br = au_sbr(sb, bindex);
6577 + if (unlikely(idx >= xi->xi_nfile))
6579 + xf = au_xino_file(xi, idx);
6581 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6582 + au_xino_count(br));
6585 + si_read_unlock(sb);
6591 +static const struct file_operations dbgaufs_xino_fop = {
6592 + .owner = THIS_MODULE,
6593 + .open = dbgaufs_xino_open,
6594 + .release = dbgaufs_xi_release,
6595 + .read = dbgaufs_xi_read
6598 +void dbgaufs_xino_del(struct au_branch *br)
6600 + struct dentry *dbgaufs;
6602 + dbgaufs = br->br_dbgaufs;
6606 + br->br_dbgaufs = NULL;
6607 + /* debugfs acquires the parent i_mutex */
6609 + debugfs_remove(dbgaufs);
6613 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6615 + aufs_bindex_t bbot;
6616 + struct au_branch *br;
6618 + if (!au_sbi(sb)->si_dbgaufs)
6621 + bbot = au_sbbot(sb);
6622 + for (; bindex <= bbot; bindex++) {
6623 + br = au_sbr(sb, bindex);
6624 + dbgaufs_xino_del(br);
6628 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6629 + unsigned int idx, struct dentry *parent,
6630 + struct au_sbinfo *sbinfo)
6632 + struct au_branch *br;
6634 + /* "xi" bindex(5) "-" idx(2) NULL */
6635 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6638 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6640 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6642 + br = au_sbr(sb, bindex);
6643 + if (br->br_dbgaufs) {
6644 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6646 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6647 + /* debugfs acquires the parent i_mutex */
6649 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6653 + pr_warn("failed renaming %pd/%s, ignored.\n",
6658 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6659 + sbinfo, &dbgaufs_xino_fop);
6661 + if (unlikely(!br->br_dbgaufs))
6662 + pr_warn("failed creating %pd/%s, ignored.\n",
6667 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6668 + struct dentry *parent, struct au_sbinfo *sbinfo)
6670 + struct au_branch *br;
6671 + struct au_xino *xi;
6674 + br = au_sbr(sb, bindex);
6676 + for (u = 0; u < xi->xi_nfile; u++)
6677 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6680 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6682 + struct au_sbinfo *sbinfo;
6683 + struct dentry *parent;
6684 + aufs_bindex_t bbot;
6686 + if (!au_opt_test(au_mntflags(sb), XINO))
6689 + sbinfo = au_sbi(sb);
6690 + parent = sbinfo->si_dbgaufs;
6694 + bbot = au_sbbot(sb);
6696 + for (; bindex <= bbot; bindex++)
6697 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6699 + for (; bbot >= bindex; bbot--)
6700 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6703 +/* ---------------------------------------------------------------------- */
6705 +#ifdef CONFIG_AUFS_EXPORT
6706 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6709 + struct au_sbinfo *sbinfo;
6710 + struct super_block *sb;
6712 + sbinfo = inode->i_private;
6713 + sb = sbinfo->si_sb;
6714 + si_noflush_read_lock(sb);
6715 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6716 + si_read_unlock(sb);
6720 +static const struct file_operations dbgaufs_xigen_fop = {
6721 + .owner = THIS_MODULE,
6722 + .open = dbgaufs_xigen_open,
6723 + .release = dbgaufs_xi_release,
6724 + .read = dbgaufs_xi_read
6727 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6732 + * This function is a dynamic '__init' function actually,
6733 + * so the tiny check for si_rwsem is unnecessary.
6735 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6738 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6739 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6740 + &dbgaufs_xigen_fop);
6741 + if (sbinfo->si_dbgaufs_xigen)
6747 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6751 +#endif /* CONFIG_AUFS_EXPORT */
6753 +/* ---------------------------------------------------------------------- */
6755 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6758 + * This function is a dynamic '__fin' function actually,
6759 + * so the tiny check for si_rwsem is unnecessary.
6761 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6763 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6764 + sbinfo->si_dbgaufs = NULL;
6767 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6770 + char name[SysaufsSiNameLen];
6773 + * This function is a dynamic '__init' function actually,
6774 + * so the tiny check for si_rwsem is unnecessary.
6776 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6780 + AuErr1("/debug/aufs is uninitialized\n");
6785 + sysaufs_name(sbinfo, name);
6786 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6787 + if (unlikely(!sbinfo->si_dbgaufs))
6790 + /* regardless plink/noplink option */
6791 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6792 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6793 + &dbgaufs_plink_fop);
6794 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6797 + /* regardless xino/noxino option */
6798 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6799 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6800 + &dbgaufs_xib_fop);
6801 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6804 + err = dbgaufs_xigen_init(sbinfo);
6806 + goto out; /* success */
6809 + dbgaufs_si_fin(sbinfo);
6811 + if (unlikely(err))
6812 + pr_err("debugfs/aufs failed\n");
6816 +/* ---------------------------------------------------------------------- */
6818 +void dbgaufs_fin(void)
6820 + debugfs_remove(dbgaufs);
6823 +int __init dbgaufs_init(void)
6828 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6833 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6834 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6835 +++ linux/fs/aufs/dbgaufs.h 2021-12-03 15:38:59.933313976 +0100
6837 +/* SPDX-License-Identifier: GPL-2.0 */
6839 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6841 + * This program, aufs is free software; you can redistribute it and/or modify
6842 + * it under the terms of the GNU General Public License as published by
6843 + * the Free Software Foundation; either version 2 of the License, or
6844 + * (at your option) any later version.
6846 + * This program is distributed in the hope that it will be useful,
6847 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6848 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6849 + * GNU General Public License for more details.
6851 + * You should have received a copy of the GNU General Public License
6852 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6856 + * debugfs interface
6859 +#ifndef __DBGAUFS_H__
6860 +#define __DBGAUFS_H__
6864 +struct super_block;
6868 +#ifdef CONFIG_DEBUG_FS
6870 +void dbgaufs_xino_del(struct au_branch *br);
6871 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6872 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6873 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6874 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6875 +void dbgaufs_fin(void);
6876 +int __init dbgaufs_init(void);
6878 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6879 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6880 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6882 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6883 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6884 +AuStubVoid(dbgaufs_fin, void)
6885 +AuStubInt0(__init dbgaufs_init, void)
6886 +#endif /* CONFIG_DEBUG_FS */
6888 +#endif /* __KERNEL__ */
6889 +#endif /* __DBGAUFS_H__ */
6890 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6891 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6892 +++ linux/fs/aufs/dcsub.c 2021-12-03 15:38:59.933313976 +0100
6894 +// SPDX-License-Identifier: GPL-2.0
6896 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6898 + * This program, aufs is free software; you can redistribute it and/or modify
6899 + * it under the terms of the GNU General Public License as published by
6900 + * the Free Software Foundation; either version 2 of the License, or
6901 + * (at your option) any later version.
6903 + * This program is distributed in the hope that it will be useful,
6904 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6905 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6906 + * GNU General Public License for more details.
6908 + * You should have received a copy of the GNU General Public License
6909 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6913 + * sub-routines for dentry cache
6918 +static void au_dpage_free(struct au_dpage *dpage)
6921 + struct dentry **p;
6923 + p = dpage->dentries;
6924 + for (i = 0; i < dpage->ndentry; i++)
6926 + free_page((unsigned long)dpage->dentries);
6929 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6935 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6936 + if (unlikely(!dpages->dpages))
6939 + p = (void *)__get_free_page(gfp);
6943 + dpages->dpages[0].ndentry = 0;
6944 + dpages->dpages[0].dentries = p;
6945 + dpages->ndpage = 1;
6946 + return 0; /* success */
6949 + au_kfree_try_rcu(dpages->dpages);
6954 +void au_dpages_free(struct au_dcsub_pages *dpages)
6957 + struct au_dpage *p;
6959 + p = dpages->dpages;
6960 + for (i = 0; i < dpages->ndpage; i++)
6961 + au_dpage_free(p++);
6962 + au_kfree_try_rcu(dpages->dpages);
6965 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6966 + struct dentry *dentry, gfp_t gfp)
6969 + struct au_dpage *dpage;
6972 + dpage = dpages->dpages + dpages->ndpage - 1;
6973 + sz = PAGE_SIZE / sizeof(dentry);
6974 + if (unlikely(dpage->ndentry >= sz)) {
6975 + AuLabel(new dpage);
6977 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6978 + p = au_kzrealloc(dpages->dpages, sz,
6979 + sz + sizeof(*dpages->dpages), gfp,
6984 + dpages->dpages = p;
6985 + dpage = dpages->dpages + dpages->ndpage;
6986 + p = (void *)__get_free_page(gfp);
6990 + dpage->ndentry = 0;
6991 + dpage->dentries = p;
6995 + AuDebugOn(au_dcount(dentry) <= 0);
6996 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6997 + return 0; /* success */
7003 +/* todo: BAD approach */
7004 +/* copied from linux/fs/dcache.c */
7012 +extern void d_walk(struct dentry *parent, void *data,
7013 + enum d_walk_ret (*enter)(void *, struct dentry *));
7015 +struct ac_dpages_arg {
7017 + struct au_dcsub_pages *dpages;
7018 + struct super_block *sb;
7019 + au_dpages_test test;
7023 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7025 + enum d_walk_ret ret;
7026 + struct ac_dpages_arg *arg = _arg;
7028 + ret = D_WALK_CONTINUE;
7029 + if (dentry->d_sb == arg->sb
7030 + && !IS_ROOT(dentry)
7031 + && au_dcount(dentry) > 0
7033 + && (!arg->test || arg->test(dentry, arg->arg))) {
7034 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7035 + if (unlikely(arg->err))
7036 + ret = D_WALK_QUIT;
7042 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7043 + au_dpages_test test, void *arg)
7045 + struct ac_dpages_arg args = {
7053 + d_walk(root, &args, au_call_dpages_append);
7058 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7059 + int do_include, au_dpages_test test, void *arg)
7064 + write_seqlock(&rename_lock);
7065 + spin_lock(&dentry->d_lock);
7067 + && au_dcount(dentry) > 0
7068 + && (!test || test(dentry, arg)))
7069 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7070 + spin_unlock(&dentry->d_lock);
7071 + if (unlikely(err))
7075 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7078 + while (!IS_ROOT(dentry)) {
7079 + dentry = dentry->d_parent; /* rename_lock is locked */
7080 + spin_lock(&dentry->d_lock);
7081 + if (au_dcount(dentry) > 0
7082 + && (!test || test(dentry, arg)))
7083 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7084 + spin_unlock(&dentry->d_lock);
7085 + if (unlikely(err))
7090 + write_sequnlock(&rename_lock);
7094 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7096 + return au_di(dentry) && dentry->d_sb == arg;
7099 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7100 + struct dentry *dentry, int do_include)
7102 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7103 + au_dcsub_dpages_aufs, dentry->d_sb);
7106 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7108 + struct path path[2] = {
7117 + return path_is_under(path + 0, path + 1);
7119 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7120 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7121 +++ linux/fs/aufs/dcsub.h 2021-12-03 15:38:59.933313976 +0100
7123 +/* SPDX-License-Identifier: GPL-2.0 */
7125 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7127 + * This program, aufs is free software; you can redistribute it and/or modify
7128 + * it under the terms of the GNU General Public License as published by
7129 + * the Free Software Foundation; either version 2 of the License, or
7130 + * (at your option) any later version.
7132 + * This program is distributed in the hope that it will be useful,
7133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7135 + * GNU General Public License for more details.
7137 + * You should have received a copy of the GNU General Public License
7138 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7142 + * sub-routines for dentry cache
7145 +#ifndef __AUFS_DCSUB_H__
7146 +#define __AUFS_DCSUB_H__
7150 +#include <linux/dcache.h>
7151 +#include <linux/fs.h>
7155 + struct dentry **dentries;
7158 +struct au_dcsub_pages {
7160 + struct au_dpage *dpages;
7163 +/* ---------------------------------------------------------------------- */
7166 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7167 +void au_dpages_free(struct au_dcsub_pages *dpages);
7168 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7169 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7170 + au_dpages_test test, void *arg);
7171 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7172 + int do_include, au_dpages_test test, void *arg);
7173 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7174 + struct dentry *dentry, int do_include);
7175 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7177 +/* ---------------------------------------------------------------------- */
7180 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7181 + * include/linux/dcache.h. Try them (in the future).
7184 +static inline int au_d_hashed_positive(struct dentry *d)
7187 + struct inode *inode = d_inode(d);
7190 + if (unlikely(d_unhashed(d)
7191 + || d_is_negative(d)
7192 + || !inode->i_nlink))
7197 +static inline int au_d_linkable(struct dentry *d)
7200 + struct inode *inode = d_inode(d);
7202 + err = au_d_hashed_positive(d);
7204 + && d_is_positive(d)
7205 + && (inode->i_state & I_LINKABLE))
7210 +static inline int au_d_alive(struct dentry *d)
7213 + struct inode *inode;
7217 + err = au_d_hashed_positive(d);
7219 + inode = d_inode(d);
7220 + if (unlikely(d_unlinked(d)
7221 + || d_is_negative(d)
7222 + || !inode->i_nlink))
7228 +static inline int au_alive_dir(struct dentry *d)
7232 + err = au_d_alive(d);
7233 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7238 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7240 + return a->len == b->len
7241 + && !memcmp(a->name, b->name, a->len);
7246 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7248 + * the type of d_lockref.count became int, but the inlined function d_count()
7249 + * still returns unsigned int.
7250 + * I don't know why. Maybe it is for every d_count() users?
7251 + * Anyway au_dcount() lives on.
7253 +static inline int au_dcount(struct dentry *d)
7255 + return (int)d_count(d);
7258 +#endif /* __KERNEL__ */
7259 +#endif /* __AUFS_DCSUB_H__ */
7260 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7261 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7262 +++ linux/fs/aufs/debug.c 2021-12-03 15:38:59.933313976 +0100
7264 +// SPDX-License-Identifier: GPL-2.0
7266 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7268 + * This program, aufs is free software; you can redistribute it and/or modify
7269 + * it under the terms of the GNU General Public License as published by
7270 + * the Free Software Foundation; either version 2 of the License, or
7271 + * (at your option) any later version.
7273 + * This program is distributed in the hope that it will be useful,
7274 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7275 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7276 + * GNU General Public License for more details.
7278 + * You should have received a copy of the GNU General Public License
7279 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7283 + * debug print functions
7286 +#include <linux/iversion.h>
7289 +/* Returns 0, or -errno. arg is in kp->arg. */
7290 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7294 + err = kstrtoint(val, 0, &n);
7304 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7305 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7310 + return sprintf(buffer, "%d", atomic_read(a));
7313 +static struct kernel_param_ops param_ops_atomic_t = {
7314 + .set = param_atomic_t_set,
7315 + .get = param_atomic_t_get
7316 + /* void (*free)(void *arg) */
7319 +atomic_t aufs_debug = ATOMIC_INIT(0);
7320 +MODULE_PARM_DESC(debug, "debug print");
7321 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7323 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7324 +char *au_plevel = KERN_DEBUG;
7325 +#define dpri(fmt, ...) do { \
7327 + && strcmp(au_plevel, KERN_DEBUG)) \
7328 + || au_debug_test()) \
7329 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7332 +/* ---------------------------------------------------------------------- */
7334 +void au_dpri_whlist(struct au_nhash *whlist)
7336 + unsigned long ul, n;
7337 + struct hlist_head *head;
7338 + struct au_vdir_wh *pos;
7340 + n = whlist->nh_num;
7341 + head = whlist->nh_head;
7342 + for (ul = 0; ul < n; ul++) {
7343 + hlist_for_each_entry(pos, head, wh_hash)
7344 + dpri("b%d, %.*s, %d\n",
7346 + pos->wh_str.len, pos->wh_str.name,
7352 +void au_dpri_vdir(struct au_vdir *vdir)
7355 + union au_vdir_deblk_p p;
7358 + if (!vdir || IS_ERR(vdir)) {
7359 + dpri("err %ld\n", PTR_ERR(vdir));
7363 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7364 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7365 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7366 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7367 + p.deblk = vdir->vd_deblk[ul];
7369 + dpri("[%lu]: %p\n", ul, o);
7373 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7374 + struct dentry *wh)
7379 + if (!inode || IS_ERR(inode)) {
7380 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7384 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7385 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7386 + && sizeof(inode->i_blocks) != sizeof(u64));
7388 + n = (void *)wh->d_name.name;
7389 + l = wh->d_name.len;
7392 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7393 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7395 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7396 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7397 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7398 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7399 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7400 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7401 + inode->i_generation,
7402 + l ? ", wh " : "", l, n);
7406 +void au_dpri_inode(struct inode *inode)
7408 + struct au_iinfo *iinfo;
7409 + struct au_hinode *hi;
7410 + aufs_bindex_t bindex;
7413 + err = do_pri_inode(-1, inode, -1, NULL);
7414 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7417 + iinfo = au_ii(inode);
7418 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7419 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7420 + if (iinfo->ii_btop < 0)
7423 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7424 + hi = au_hinode(iinfo, bindex);
7426 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7430 +void au_dpri_dalias(struct inode *inode)
7434 + spin_lock(&inode->i_lock);
7435 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7436 + au_dpri_dentry(d);
7437 + spin_unlock(&inode->i_lock);
7440 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7442 + struct dentry *wh = NULL;
7444 + struct inode *inode;
7445 + struct au_iinfo *iinfo;
7446 + struct au_hinode *hi;
7448 + if (!dentry || IS_ERR(dentry)) {
7449 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7452 + /* do not call dget_parent() here */
7453 + /* note: access d_xxx without d_lock */
7454 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7455 + bindex, dentry, dentry,
7456 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7457 + au_dcount(dentry), dentry->d_flags,
7458 + d_unhashed(dentry) ? "un" : "");
7461 + if (d_is_positive(dentry))
7462 + inode = d_inode(dentry);
7464 + && au_test_aufs(dentry->d_sb)
7466 + && !au_is_bad_inode(inode)) {
7467 + iinfo = au_ii(inode);
7468 + hi = au_hinode(iinfo, bindex);
7470 + wh = hi->hi_whdentry;
7472 + do_pri_inode(bindex, inode, hn, wh);
7476 +void au_dpri_dentry(struct dentry *dentry)
7478 + struct au_dinfo *dinfo;
7479 + aufs_bindex_t bindex;
7482 + err = do_pri_dentry(-1, dentry);
7483 + if (err || !au_test_aufs(dentry->d_sb))
7486 + dinfo = au_di(dentry);
7489 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7490 + dinfo->di_btop, dinfo->di_bbot,
7491 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7492 + dinfo->di_tmpfile);
7493 + if (dinfo->di_btop < 0)
7495 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7496 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7499 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7503 + if (!file || IS_ERR(file)) {
7504 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7509 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7510 + && au_test_aufs(file->f_path.dentry->d_sb)
7512 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7513 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7514 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7515 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7516 + file->f_version, file->f_pos, a);
7517 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7518 + do_pri_dentry(bindex, file->f_path.dentry);
7522 +void au_dpri_file(struct file *file)
7524 + struct au_finfo *finfo;
7525 + struct au_fidir *fidir;
7526 + struct au_hfile *hfile;
7527 + aufs_bindex_t bindex;
7530 + err = do_pri_file(-1, file);
7532 + || IS_ERR_OR_NULL(file->f_path.dentry)
7533 + || !au_test_aufs(file->f_path.dentry->d_sb))
7536 + finfo = au_fi(file);
7539 + if (finfo->fi_btop < 0)
7541 + fidir = finfo->fi_hdir;
7543 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7545 + for (bindex = finfo->fi_btop;
7546 + bindex >= 0 && bindex <= fidir->fd_bbot;
7548 + hfile = fidir->fd_hfile + bindex;
7549 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7553 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7555 + struct vfsmount *mnt;
7556 + struct super_block *sb;
7558 + if (!br || IS_ERR(br))
7560 + mnt = au_br_mnt(br);
7561 + if (!mnt || IS_ERR(mnt))
7564 + if (!sb || IS_ERR(sb))
7567 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7568 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7570 + bindex, br->br_perm, br->br_id, br->br_wbr,
7571 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7572 + sb->s_flags, sb->s_count,
7573 + atomic_read(&sb->s_active),
7574 + !!au_xino_file(br->br_xino, /*idx*/-1));
7578 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7582 +void au_dpri_sb(struct super_block *sb)
7584 + struct au_sbinfo *sbinfo;
7585 + aufs_bindex_t bindex;
7587 + /* to reduce stack size */
7589 + struct vfsmount mnt;
7590 + struct au_branch fake;
7593 + /* this function can be called from magic sysrq */
7594 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7595 + if (unlikely(!a)) {
7596 + dpri("no memory\n");
7600 + a->mnt.mnt_sb = sb;
7601 + a->fake.br_path.mnt = &a->mnt;
7602 + err = do_pri_br(-1, &a->fake);
7604 + dpri("dev 0x%x\n", sb->s_dev);
7605 + if (err || !au_test_aufs(sb))
7608 + sbinfo = au_sbi(sb);
7611 + dpri("nw %d, gen %u, kobj %d\n",
7612 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7613 + kref_read(&sbinfo->si_kobj.kref));
7614 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7615 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7618 +/* ---------------------------------------------------------------------- */
7620 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7622 + struct inode *h_inode, *inode = d_inode(dentry);
7623 + struct dentry *h_dentry;
7624 + aufs_bindex_t bindex, bbot, bi;
7626 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7629 + bbot = au_dbbot(dentry);
7630 + bi = au_ibbot(inode);
7633 + bindex = au_dbtop(dentry);
7634 + bi = au_ibtop(inode);
7638 + for (; bindex <= bbot; bindex++) {
7639 + h_dentry = au_h_dptr(dentry, bindex);
7642 + h_inode = au_h_iptr(inode, bindex);
7643 + if (unlikely(h_inode != d_inode(h_dentry))) {
7645 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7646 + AuDbgDentry(dentry);
7647 + AuDbgInode(inode);
7649 + if (au_test_fuse(h_inode->i_sb))
7657 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7660 + struct au_dcsub_pages dpages;
7661 + struct au_dpage *dpage;
7662 + struct dentry **dentries;
7664 + err = au_dpages_init(&dpages, GFP_NOFS);
7666 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7668 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7669 + dpage = dpages.dpages + i;
7670 + dentries = dpage->dentries;
7671 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7672 + AuDebugOn(au_digen_test(dentries[j], sigen));
7674 + au_dpages_free(&dpages);
7677 +void au_dbg_verify_kthread(void)
7679 + if (au_wkq_test()) {
7682 + * It may be recursive, but udba=notify between two aufs mounts,
7683 + * where a single ro branch is shared, is not a problem.
7689 +/* ---------------------------------------------------------------------- */
7691 +int __init au_debug_init(void)
7693 + aufs_bindex_t bindex;
7694 + struct au_vdir_destr destr;
7697 + AuDebugOn(bindex >= 0);
7700 + AuDebugOn(destr.len < NAME_MAX);
7702 +#ifdef CONFIG_4KSTACKS
7703 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7708 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7709 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7710 +++ linux/fs/aufs/debug.h 2021-12-03 15:38:59.933313976 +0100
7712 +/* SPDX-License-Identifier: GPL-2.0 */
7714 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7716 + * This program, aufs is free software; you can redistribute it and/or modify
7717 + * it under the terms of the GNU General Public License as published by
7718 + * the Free Software Foundation; either version 2 of the License, or
7719 + * (at your option) any later version.
7721 + * This program is distributed in the hope that it will be useful,
7722 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7723 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7724 + * GNU General Public License for more details.
7726 + * You should have received a copy of the GNU General Public License
7727 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7731 + * debug print functions
7734 +#ifndef __AUFS_DEBUG_H__
7735 +#define __AUFS_DEBUG_H__
7739 +#include <linux/atomic.h>
7740 +#include <linux/module.h>
7741 +#include <linux/kallsyms.h>
7742 +#include <linux/sysrq.h>
7744 +#ifdef CONFIG_AUFS_DEBUG
7745 +#define AuDebugOn(a) BUG_ON(a)
7747 +/* module parameter */
7748 +extern atomic_t aufs_debug;
7749 +static inline void au_debug_on(void)
7751 + atomic_inc(&aufs_debug);
7753 +static inline void au_debug_off(void)
7755 + atomic_dec_if_positive(&aufs_debug);
7758 +static inline int au_debug_test(void)
7760 + return atomic_read(&aufs_debug) > 0;
7763 +#define AuDebugOn(a) do {} while (0)
7764 +AuStubVoid(au_debug_on, void)
7765 +AuStubVoid(au_debug_off, void)
7766 +AuStubInt0(au_debug_test, void)
7767 +#endif /* CONFIG_AUFS_DEBUG */
7769 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7771 +/* ---------------------------------------------------------------------- */
7775 +#define AuDbg(fmt, ...) do { \
7776 + if (au_debug_test()) \
7777 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7779 +#define AuLabel(l) AuDbg(#l "\n")
7780 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7781 +#define AuWarn1(fmt, ...) do { \
7782 + static unsigned char _c; \
7784 + pr_warn(fmt, ##__VA_ARGS__); \
7787 +#define AuErr1(fmt, ...) do { \
7788 + static unsigned char _c; \
7790 + pr_err(fmt, ##__VA_ARGS__); \
7793 +#define AuIOErr1(fmt, ...) do { \
7794 + static unsigned char _c; \
7796 + AuIOErr(fmt, ##__VA_ARGS__); \
7799 +#define AuUnsupportMsg "This operation is not supported." \
7800 + " Please report this application to aufs-users ML."
7801 +#define AuUnsupport(fmt, ...) do { \
7802 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7806 +#define AuTraceErr(e) do { \
7807 + if (unlikely((e) < 0)) \
7808 + AuDbg("err %d\n", (int)(e)); \
7811 +#define AuTraceErrPtr(p) do { \
7813 + AuDbg("err %ld\n", PTR_ERR(p)); \
7816 +/* dirty macros for debug print, use with "%.*s" and caution */
7817 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7819 +/* ---------------------------------------------------------------------- */
7822 +#ifdef CONFIG_AUFS_DEBUG
7823 +extern struct mutex au_dbg_mtx;
7824 +extern char *au_plevel;
7826 +void au_dpri_whlist(struct au_nhash *whlist);
7828 +void au_dpri_vdir(struct au_vdir *vdir);
7830 +void au_dpri_inode(struct inode *inode);
7831 +void au_dpri_dalias(struct inode *inode);
7832 +void au_dpri_dentry(struct dentry *dentry);
7834 +void au_dpri_file(struct file *filp);
7835 +struct super_block;
7836 +void au_dpri_sb(struct super_block *sb);
7838 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7839 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7840 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7841 +void au_dbg_verify_kthread(void);
7843 +int __init au_debug_init(void);
7845 +#define AuDbgWhlist(w) do { \
7846 + mutex_lock(&au_dbg_mtx); \
7848 + au_dpri_whlist(w); \
7849 + mutex_unlock(&au_dbg_mtx); \
7852 +#define AuDbgVdir(v) do { \
7853 + mutex_lock(&au_dbg_mtx); \
7855 + au_dpri_vdir(v); \
7856 + mutex_unlock(&au_dbg_mtx); \
7859 +#define AuDbgInode(i) do { \
7860 + mutex_lock(&au_dbg_mtx); \
7862 + au_dpri_inode(i); \
7863 + mutex_unlock(&au_dbg_mtx); \
7866 +#define AuDbgDAlias(i) do { \
7867 + mutex_lock(&au_dbg_mtx); \
7869 + au_dpri_dalias(i); \
7870 + mutex_unlock(&au_dbg_mtx); \
7873 +#define AuDbgDentry(d) do { \
7874 + mutex_lock(&au_dbg_mtx); \
7876 + au_dpri_dentry(d); \
7877 + mutex_unlock(&au_dbg_mtx); \
7880 +#define AuDbgFile(f) do { \
7881 + mutex_lock(&au_dbg_mtx); \
7883 + au_dpri_file(f); \
7884 + mutex_unlock(&au_dbg_mtx); \
7887 +#define AuDbgSb(sb) do { \
7888 + mutex_lock(&au_dbg_mtx); \
7889 + AuDbg(#sb "\n"); \
7891 + mutex_unlock(&au_dbg_mtx); \
7894 +#define AuDbgSym(addr) do { \
7895 + char sym[KSYM_SYMBOL_LEN]; \
7896 + sprint_symbol(sym, (unsigned long)addr); \
7897 + AuDbg("%s\n", sym); \
7900 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7901 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7902 +AuStubVoid(au_dbg_verify_kthread, void)
7903 +AuStubInt0(__init au_debug_init, void)
7905 +#define AuDbgWhlist(w) do {} while (0)
7906 +#define AuDbgVdir(v) do {} while (0)
7907 +#define AuDbgInode(i) do {} while (0)
7908 +#define AuDbgDAlias(i) do {} while (0)
7909 +#define AuDbgDentry(d) do {} while (0)
7910 +#define AuDbgFile(f) do {} while (0)
7911 +#define AuDbgSb(sb) do {} while (0)
7912 +#define AuDbgSym(addr) do {} while (0)
7913 +#endif /* CONFIG_AUFS_DEBUG */
7915 +/* ---------------------------------------------------------------------- */
7917 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7918 +int __init au_sysrq_init(void);
7919 +void au_sysrq_fin(void);
7921 +#ifdef CONFIG_HW_CONSOLE
7922 +#define au_dbg_blocked() do { \
7924 + handle_sysrq('w'); \
7927 +AuStubVoid(au_dbg_blocked, void)
7931 +AuStubInt0(__init au_sysrq_init, void)
7932 +AuStubVoid(au_sysrq_fin, void)
7933 +AuStubVoid(au_dbg_blocked, void)
7934 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7936 +#endif /* __KERNEL__ */
7937 +#endif /* __AUFS_DEBUG_H__ */
7938 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7939 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7940 +++ linux/fs/aufs/dentry.c 2021-12-03 15:40:58.233313963 +0100
7942 +// SPDX-License-Identifier: GPL-2.0
7944 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7946 + * This program, aufs is free software; you can redistribute it and/or modify
7947 + * it under the terms of the GNU General Public License as published by
7948 + * the Free Software Foundation; either version 2 of the License, or
7949 + * (at your option) any later version.
7951 + * This program is distributed in the hope that it will be useful,
7952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7954 + * GNU General Public License for more details.
7956 + * You should have received a copy of the GNU General Public License
7957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7961 + * lookup and dentry operations
7964 +#include <linux/iversion.h>
7965 +#include <linux/namei.h>
7969 + * returns positive/negative dentry, NULL or an error.
7970 + * NULL means whiteout-ed or not-found.
7972 +static struct dentry*
7973 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7974 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7976 + struct dentry *h_dentry;
7977 + struct inode *h_inode;
7978 + struct au_branch *br;
7979 + struct user_namespace *h_userns;
7980 + struct path h_path;
7981 + int wh_found, opq;
7982 + unsigned char wh_able;
7983 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7984 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7988 + br = au_sbr(dentry->d_sb, bindex);
7989 + h_path.dentry = h_parent;
7990 + h_path.mnt = au_br_mnt(br);
7991 + h_userns = au_br_userns(br);
7992 + wh_able = !!au_br_whable(br->br_perm);
7994 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
7996 + h_dentry = ERR_PTR(wh_found);
7999 + if (unlikely(wh_found < 0))
8002 + /* We found a whiteout */
8003 + /* au_set_dbbot(dentry, bindex); */
8004 + au_set_dbwh(dentry, bindex);
8006 + return NULL; /* success */
8010 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8012 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8013 + if (IS_ERR(h_dentry)) {
8014 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8020 + h_inode = d_inode(h_dentry);
8021 + if (d_is_negative(h_dentry)) {
8024 + } else if (wh_found
8025 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8027 + else if (au_ftest_lkup(args->flags, DIRREN)
8029 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8030 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8031 + (unsigned long long)h_inode->i_ino);
8035 + if (au_dbbot(dentry) <= bindex)
8036 + au_set_dbbot(dentry, bindex);
8037 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8038 + au_set_dbtop(dentry, bindex);
8039 + au_set_h_dptr(dentry, bindex, h_dentry);
8041 + if (!d_is_dir(h_dentry)
8043 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8044 + goto out; /* success */
8046 + h_path.dentry = h_dentry;
8047 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8048 + opq = au_diropq_test(h_userns, &h_path);
8049 + inode_unlock_shared(h_inode);
8051 + au_set_dbdiropq(dentry, bindex);
8052 + else if (unlikely(opq < 0)) {
8053 + au_set_h_dptr(dentry, bindex, NULL);
8054 + h_dentry = ERR_PTR(opq);
8065 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8067 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8068 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8074 + * returns the number of lower positive dentries,
8075 + * otherwise an error.
8076 + * can be called at unlinking with @type is zero.
8078 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8079 + unsigned int flags)
8081 + int npositive, err;
8082 + aufs_bindex_t bindex, btail, bdiropq;
8083 + unsigned char isdir, dirperm1, dirren;
8084 + struct au_do_lookup_args args = {
8086 + .name = &dentry->d_name
8088 + struct dentry *parent;
8089 + struct super_block *sb;
8091 + sb = dentry->d_sb;
8092 + err = au_test_shwh(sb, args.name);
8093 + if (unlikely(err))
8096 + err = au_wh_name_alloc(&args.whname, args.name);
8097 + if (unlikely(err))
8100 + isdir = !!d_is_dir(dentry);
8101 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8102 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8104 + au_fset_lkup(args.flags, DIRREN);
8107 + parent = dget_parent(dentry);
8108 + btail = au_dbtaildir(parent);
8109 + for (bindex = btop; bindex <= btail; bindex++) {
8110 + struct dentry *h_parent, *h_dentry;
8111 + struct inode *h_inode, *h_dir;
8112 + struct au_branch *br;
8114 + h_dentry = au_h_dptr(dentry, bindex);
8116 + if (d_is_positive(h_dentry))
8120 + h_parent = au_h_dptr(parent, bindex);
8121 + if (!h_parent || !d_is_dir(h_parent))
8125 + /* if the inum matches, then use the prepared name */
8126 + err = au_dr_lkup_name(&args, bindex);
8127 + if (unlikely(err))
8131 + h_dir = d_inode(h_parent);
8132 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8133 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8134 + inode_unlock_shared(h_dir);
8135 + err = PTR_ERR(h_dentry);
8136 + if (IS_ERR(h_dentry))
8139 + au_fclr_lkup(args.flags, ALLOW_NEG);
8141 + au_fset_lkup(args.flags, IGNORE_PERM);
8143 + if (au_dbwh(dentry) == bindex)
8147 + if (d_is_negative(h_dentry))
8149 + h_inode = d_inode(h_dentry);
8152 + args.type = h_inode->i_mode & S_IFMT;
8153 + if (args.type != S_IFDIR)
8156 + /* the type of lower may be different */
8157 + bdiropq = au_dbdiropq(dentry);
8158 + if (bdiropq >= 0 && bdiropq <= bindex)
8161 + br = au_sbr(sb, bindex);
8163 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8164 + /*add_ent*/NULL)) {
8165 + /* prepare next name to lookup */
8166 + err = au_dr_lkup(&args, dentry, bindex);
8167 + if (unlikely(err))
8173 + AuLabel(positive);
8174 + au_update_dbtop(dentry);
8177 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8178 + && au_dbtop(dentry) < 0)) {
8180 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8186 + au_kfree_try_rcu(args.whname.name);
8188 + au_dr_lkup_fin(&args);
8193 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8194 + struct path *ppath)
8196 + struct dentry *dentry;
8199 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8200 + dentry = vfsub_lkup_one(name, ppath);
8202 + struct vfsub_lkup_one_args args = {
8208 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8209 + if (unlikely(wkq_err))
8210 + dentry = ERR_PTR(wkq_err);
8217 + * lookup @dentry on @bindex which should be negative.
8219 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8222 + struct dentry *parent, *h_dentry;
8223 + struct au_branch *br;
8224 + struct user_namespace *h_userns;
8225 + struct path h_ppath;
8227 + parent = dget_parent(dentry);
8228 + br = au_sbr(dentry->d_sb, bindex);
8229 + h_ppath.dentry = au_h_dptr(parent, bindex);
8230 + h_ppath.mnt = au_br_mnt(br);
8231 + h_userns = au_br_userns(br);
8233 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8235 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8236 + err = PTR_ERR(h_dentry);
8237 + if (IS_ERR(h_dentry))
8239 + if (unlikely(d_is_positive(h_dentry))) {
8241 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8247 + if (bindex < au_dbtop(dentry))
8248 + au_set_dbtop(dentry, bindex);
8249 + if (au_dbbot(dentry) < bindex)
8250 + au_set_dbbot(dentry, bindex);
8251 + au_set_h_dptr(dentry, bindex, h_dentry);
8258 +/* ---------------------------------------------------------------------- */
8260 +/* subset of struct inode */
8262 + unsigned long i_ino;
8263 + /* unsigned int i_nlink; */
8269 + blkcnt_t i_blocks;
8274 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8276 + ia->i_ino = h_inode->i_ino;
8277 + /* ia->i_nlink = h_inode->i_nlink; */
8278 + ia->i_uid = h_inode->i_uid;
8279 + ia->i_gid = h_inode->i_gid;
8280 + ia->i_version = inode_query_iversion(h_inode);
8282 + ia->i_size = h_inode->i_size;
8283 + ia->i_blocks = h_inode->i_blocks;
8285 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8288 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8290 + return ia->i_ino != h_inode->i_ino
8291 + /* || ia->i_nlink != h_inode->i_nlink */
8292 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8293 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8294 + || !inode_eq_iversion(h_inode, ia->i_version)
8296 + || ia->i_size != h_inode->i_size
8297 + || ia->i_blocks != h_inode->i_blocks
8299 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8302 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8303 + struct au_branch *br)
8306 + struct au_iattr ia;
8307 + struct inode *h_inode;
8308 + struct dentry *h_d;
8309 + struct super_block *h_sb;
8310 + struct path h_ppath;
8313 + memset(&ia, -1, sizeof(ia));
8314 + h_sb = h_dentry->d_sb;
8316 + if (d_is_positive(h_dentry)) {
8317 + h_inode = d_inode(h_dentry);
8318 + au_iattr_save(&ia, h_inode);
8319 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8320 + /* nfs d_revalidate may return 0 for negative dentry */
8321 + /* fuse d_revalidate always return 0 for negative dentry */
8324 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8325 + h_ppath.dentry = h_parent;
8326 + h_ppath.mnt = au_br_mnt(br);
8327 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8328 + err = PTR_ERR(h_d);
8333 + if (unlikely(h_d != h_dentry
8334 + || d_inode(h_d) != h_inode
8335 + || (h_inode && au_iattr_test(&ia, h_inode))))
8336 + err = au_busy_or_stale();
8344 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8345 + struct dentry *h_parent, struct au_branch *br)
8350 + if (udba == AuOpt_UDBA_REVAL
8351 + && !au_test_fs_remote(h_dentry->d_sb)) {
8353 + err = (d_inode(h_dentry->d_parent) != h_dir);
8354 + } else if (udba != AuOpt_UDBA_NONE)
8355 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8360 +/* ---------------------------------------------------------------------- */
8362 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8365 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8366 + struct au_hdentry tmp, *p, *q;
8367 + struct au_dinfo *dinfo;
8368 + struct super_block *sb;
8370 + DiMustWriteLock(dentry);
8372 + sb = dentry->d_sb;
8373 + dinfo = au_di(dentry);
8374 + bbot = dinfo->di_bbot;
8375 + bwh = dinfo->di_bwh;
8376 + bdiropq = dinfo->di_bdiropq;
8377 + bindex = dinfo->di_btop;
8378 + p = au_hdentry(dinfo, bindex);
8379 + for (; bindex <= bbot; bindex++, p++) {
8380 + if (!p->hd_dentry)
8383 + new_bindex = au_br_index(sb, p->hd_id);
8384 + if (new_bindex == bindex)
8387 + if (dinfo->di_bwh == bindex)
8389 + if (dinfo->di_bdiropq == bindex)
8390 + bdiropq = new_bindex;
8391 + if (new_bindex < 0) {
8393 + p->hd_dentry = NULL;
8397 + /* swap two lower dentries, and loop again */
8398 + q = au_hdentry(dinfo, new_bindex);
8402 + if (tmp.hd_dentry) {
8408 + dinfo->di_bwh = -1;
8409 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8410 + dinfo->di_bwh = bwh;
8412 + dinfo->di_bdiropq = -1;
8414 + && bdiropq <= au_sbbot(sb)
8415 + && au_sbr_whable(sb, bdiropq))
8416 + dinfo->di_bdiropq = bdiropq;
8419 + dinfo->di_btop = -1;
8420 + dinfo->di_bbot = -1;
8421 + bbot = au_dbbot(parent);
8423 + p = au_hdentry(dinfo, bindex);
8424 + for (; bindex <= bbot; bindex++, p++)
8425 + if (p->hd_dentry) {
8426 + dinfo->di_btop = bindex;
8430 + if (dinfo->di_btop >= 0) {
8432 + p = au_hdentry(dinfo, bindex);
8433 + for (; bindex >= 0; bindex--, p--)
8434 + if (p->hd_dentry) {
8435 + dinfo->di_bbot = bindex;
8444 +static void au_do_hide(struct dentry *dentry)
8446 + struct inode *inode;
8448 + if (d_really_is_positive(dentry)) {
8449 + inode = d_inode(dentry);
8450 + if (!d_is_dir(dentry)) {
8451 + if (inode->i_nlink && !d_unhashed(dentry))
8452 + drop_nlink(inode);
8454 + clear_nlink(inode);
8455 + /* stop next lookup */
8456 + inode->i_flags |= S_DEAD;
8458 + smp_mb(); /* necessary? */
8463 +static int au_hide_children(struct dentry *parent)
8465 + int err, i, j, ndentry;
8466 + struct au_dcsub_pages dpages;
8467 + struct au_dpage *dpage;
8468 + struct dentry *dentry;
8470 + err = au_dpages_init(&dpages, GFP_NOFS);
8471 + if (unlikely(err))
8473 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8474 + if (unlikely(err))
8477 + /* in reverse order */
8478 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8479 + dpage = dpages.dpages + i;
8480 + ndentry = dpage->ndentry;
8481 + for (j = ndentry - 1; j >= 0; j--) {
8482 + dentry = dpage->dentries[j];
8483 + if (dentry != parent)
8484 + au_do_hide(dentry);
8489 + au_dpages_free(&dpages);
8494 +static void au_hide(struct dentry *dentry)
8498 + AuDbgDentry(dentry);
8499 + if (d_is_dir(dentry)) {
8500 + /* shrink_dcache_parent(dentry); */
8501 + err = au_hide_children(dentry);
8502 + if (unlikely(err))
8503 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8506 + au_do_hide(dentry);
8510 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8512 + * a dirty branch is added
8513 + * - on the top of layers
8514 + * - in the middle of layers
8515 + * - to the bottom of layers
8517 + * on the added branch there exists
8520 + * - a same named entry
8522 + * * negative --> positive
8523 + * * positive --> positive
8524 + * - type is unchanged
8525 + * - type is changed
8527 + * * negative --> negative
8528 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8531 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8532 + struct au_dinfo *tmp)
8535 + aufs_bindex_t bindex, bbot;
8537 + struct dentry *dentry;
8538 + struct inode *inode;
8540 + } orig_h, tmp_h = {
8543 + struct au_hdentry *hd;
8544 + struct inode *inode, *h_inode;
8545 + struct dentry *h_dentry;
8548 + AuDebugOn(dinfo->di_btop < 0);
8550 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8551 + orig_h.inode = NULL;
8552 + if (d_is_positive(orig_h.dentry)) {
8553 + orig_h.inode = d_inode(orig_h.dentry);
8554 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8556 + if (tmp->di_btop >= 0) {
8557 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8558 + if (d_is_positive(tmp_h.dentry)) {
8559 + tmp_h.inode = d_inode(tmp_h.dentry);
8560 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8565 + if (d_really_is_positive(dentry))
8566 + inode = d_inode(dentry);
8567 + if (!orig_h.inode) {
8568 + AuDbg("negative originally\n");
8574 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8575 + AuDebugOn(dinfo->di_bdiropq != -1);
8577 + if (!tmp_h.inode) {
8578 + AuDbg("negative --> negative\n");
8579 + /* should have only one negative lower */
8580 + if (tmp->di_btop >= 0
8581 + && tmp->di_btop < dinfo->di_btop) {
8582 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8583 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8584 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8585 + au_di_cp(dinfo, tmp);
8586 + hd = au_hdentry(tmp, tmp->di_btop);
8587 + au_set_h_dptr(dentry, tmp->di_btop,
8588 + dget(hd->hd_dentry));
8590 + au_dbg_verify_dinode(dentry);
8592 + AuDbg("negative --> positive\n");
8594 + * similar to the behaviour of creating with bypassing
8596 + * unhash it in order to force an error in the
8597 + * succeeding create operation.
8598 + * we should not set S_DEAD here.
8601 + /* au_di_swap(tmp, dinfo); */
8602 + au_dbg_verify_dinode(dentry);
8605 + AuDbg("positive originally\n");
8606 + /* inode may be NULL */
8607 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8608 + if (!tmp_h.inode) {
8609 + AuDbg("positive --> negative\n");
8610 + /* or bypassing aufs */
8612 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8613 + dinfo->di_bwh = tmp->di_bwh;
8615 + err = au_refresh_hinode_self(inode);
8616 + au_dbg_verify_dinode(dentry);
8617 + } else if (orig_h.mode == tmp_h.mode) {
8618 + AuDbg("positive --> positive, same type\n");
8619 + if (!S_ISDIR(orig_h.mode)
8620 + && dinfo->di_btop > tmp->di_btop) {
8622 + * similar to the behaviour of removing and
8627 + err = au_refresh_hinode_self(inode);
8628 + au_dbg_verify_dinode(dentry);
8630 + /* fill empty slots */
8631 + if (dinfo->di_btop > tmp->di_btop)
8632 + dinfo->di_btop = tmp->di_btop;
8633 + if (dinfo->di_bbot < tmp->di_bbot)
8634 + dinfo->di_bbot = tmp->di_bbot;
8635 + dinfo->di_bwh = tmp->di_bwh;
8636 + dinfo->di_bdiropq = tmp->di_bdiropq;
8637 + bbot = dinfo->di_bbot;
8638 + bindex = tmp->di_btop;
8639 + hd = au_hdentry(tmp, bindex);
8640 + for (; bindex <= bbot; bindex++, hd++) {
8641 + if (au_h_dptr(dentry, bindex))
8643 + h_dentry = hd->hd_dentry;
8646 + AuDebugOn(d_is_negative(h_dentry));
8647 + h_inode = d_inode(h_dentry);
8648 + AuDebugOn(orig_h.mode
8649 + != (h_inode->i_mode
8651 + au_set_h_dptr(dentry, bindex,
8655 + err = au_refresh_hinode(inode, dentry);
8656 + au_dbg_verify_dinode(dentry);
8659 + AuDbg("positive --> positive, different type\n");
8660 + /* similar to the behaviour of removing and creating */
8663 + err = au_refresh_hinode_self(inode);
8664 + au_dbg_verify_dinode(dentry);
8672 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8674 + const struct dentry_operations *dop
8675 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8676 + static const unsigned int mask
8677 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8679 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8681 + if (dentry->d_op == dop)
8684 + AuDbg("%pd\n", dentry);
8685 + spin_lock(&dentry->d_lock);
8686 + if (dop == &aufs_dop)
8687 + dentry->d_flags |= mask;
8689 + dentry->d_flags &= ~mask;
8690 + dentry->d_op = dop;
8691 + spin_unlock(&dentry->d_lock);
8694 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8696 + int err, ebrange, nbr;
8697 + unsigned int sigen;
8698 + struct au_dinfo *dinfo, *tmp;
8699 + struct super_block *sb;
8700 + struct inode *inode;
8702 + DiMustWriteLock(dentry);
8703 + AuDebugOn(IS_ROOT(dentry));
8704 + AuDebugOn(d_really_is_negative(parent));
8706 + sb = dentry->d_sb;
8707 + sigen = au_sigen(sb);
8708 + err = au_digen_test(parent, sigen);
8709 + if (unlikely(err))
8712 + nbr = au_sbbot(sb) + 1;
8713 + dinfo = au_di(dentry);
8714 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8715 + if (unlikely(err))
8717 + ebrange = au_dbrange_test(dentry);
8719 + ebrange = au_do_refresh_hdentry(dentry, parent);
8721 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8722 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8723 + if (d_really_is_positive(dentry)) {
8724 + inode = d_inode(dentry);
8725 + err = au_refresh_hinode_self(inode);
8727 + au_dbg_verify_dinode(dentry);
8729 + goto out_dgen; /* success */
8733 + /* temporary dinfo */
8734 + AuDbgDentry(dentry);
8736 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8737 + if (unlikely(!tmp))
8739 + au_di_swap(tmp, dinfo);
8740 + /* returns the number of positive dentries */
8742 + * if current working dir is removed, it returns an error.
8743 + * but the dentry is legal.
8745 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8746 + AuDbgDentry(dentry);
8747 + au_di_swap(tmp, dinfo);
8748 + if (err == -ENOENT)
8751 + /* compare/refresh by dinfo */
8752 + AuDbgDentry(dentry);
8753 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8754 + au_dbg_verify_dinode(dentry);
8757 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8758 + au_rw_write_unlock(&tmp->di_rwsem);
8760 + if (unlikely(err))
8764 + au_update_digen(dentry);
8766 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8767 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8768 + AuDbgDentry(dentry);
8774 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8775 + struct dentry *dentry, aufs_bindex_t bindex)
8780 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8783 + AuDbg("b%d\n", bindex);
8785 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8786 + * due to whiteout and branch permission.
8788 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8789 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8790 + /* it may return tri-state */
8791 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8793 + if (unlikely(valid < 0))
8803 +/* todo: remove this */
8804 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8805 + unsigned int flags, int do_udba, int dirren)
8808 + umode_t mode, h_mode;
8809 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8810 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8811 + struct inode *h_inode, *h_cached_inode;
8812 + struct dentry *h_dentry;
8813 + struct qstr *name, *h_name;
8820 + unhashed = !!d_unhashed(dentry);
8821 + is_root = !!IS_ROOT(dentry);
8822 + name = &dentry->d_name;
8823 + tmpfile = au_di(dentry)->di_tmpfile;
8826 + * Theoretically, REVAL test should be unnecessary in case of
8828 + * But {fs,i}notify doesn't fire some necessary events,
8829 + * IN_ATTRIB for atime/nlink/pageio
8830 + * Let's do REVAL test too.
8832 + if (do_udba && inode) {
8833 + mode = (inode->i_mode & S_IFMT);
8834 + plus = (inode->i_nlink > 0);
8835 + ibs = au_ibtop(inode);
8836 + ibe = au_ibbot(inode);
8839 + btop = au_dbtop(dentry);
8841 + if (inode && S_ISDIR(inode->i_mode))
8842 + btail = au_dbtaildir(dentry);
8843 + for (bindex = btop; bindex <= btail; bindex++) {
8844 + h_dentry = au_h_dptr(dentry, bindex);
8848 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8849 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8850 + spin_lock(&h_dentry->d_lock);
8851 + h_name = &h_dentry->d_name;
8852 + if (unlikely(do_udba
8855 + && (unhashed != !!d_unhashed(h_dentry)
8856 + || (!tmpfile && !dirren
8857 + && !au_qstreq(name, h_name))
8860 + && !(flags & LOOKUP_OPEN)
8861 + && (h_dentry->d_flags
8862 + & DCACHE_NFSFS_RENAMED)))
8866 + h_unhashed = d_unhashed(h_dentry);
8867 + spin_unlock(&h_dentry->d_lock);
8868 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8869 + unhashed, h_unhashed, dentry, h_dentry);
8872 + spin_unlock(&h_dentry->d_lock);
8874 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8875 + if (unlikely(err))
8876 + /* do not goto err, to keep the errno */
8879 + /* todo: plink too? */
8884 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8888 + if (d_is_positive(h_dentry))
8889 + h_inode = d_inode(h_dentry);
8892 + h_cached_inode = h_inode;
8894 + h_mode = (h_inode->i_mode & S_IFMT);
8895 + h_plus = (h_inode->i_nlink > 0);
8897 + if (inode && ibs <= bindex && bindex <= ibe)
8898 + h_cached_inode = au_h_iptr(inode, bindex);
8901 + if (unlikely(plus != h_plus && !tmpfile))
8904 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8906 + && !IS_ROOT(h_dentry)
8907 + && unhashed != d_unhashed(h_dentry)))
8910 + if (unlikely(mode != h_mode
8911 + || h_cached_inode != h_inode))
8924 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8925 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8928 + struct dentry *parent;
8930 + if (!au_digen_test(dentry, sigen))
8933 + parent = dget_parent(dentry);
8934 + di_read_lock_parent(parent, AuLock_IR);
8935 + AuDebugOn(au_digen_test(parent, sigen));
8936 + au_dbg_verify_gen(parent, sigen);
8937 + err = au_refresh_dentry(dentry, parent);
8938 + di_read_unlock(parent, AuLock_IR);
8944 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8947 + struct dentry *d, *parent;
8949 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8950 + return simple_reval_dpath(dentry, sigen);
8952 + /* slow loop, keep it simple and stupid */
8953 + /* cf: au_cpup_dirs() */
8956 + while (au_digen_test(dentry, sigen)) {
8960 + parent = dget_parent(d);
8961 + if (!au_digen_test(parent, sigen))
8967 + di_write_lock_child2(d);
8969 + /* someone might update our dentry while we were sleeping */
8970 + if (au_digen_test(d, sigen)) {
8972 + * todo: consolidate with simple_reval_dpath(),
8973 + * do_refresh() and au_reval_for_attr().
8975 + di_read_lock_parent(parent, AuLock_IR);
8976 + err = au_refresh_dentry(d, parent);
8977 + di_read_unlock(parent, AuLock_IR);
8981 + di_write_unlock(d);
8983 + if (unlikely(err))
8991 + * if valid returns 1, otherwise 0.
8993 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8996 + unsigned int sigen;
8997 + unsigned char do_udba, dirren;
8998 + struct super_block *sb;
8999 + struct inode *inode;
9001 + /* todo: support rcu-walk? */
9002 + if (flags & LOOKUP_RCU)
9006 + if (unlikely(!au_di(dentry)))
9010 + sb = dentry->d_sb;
9013 + * i_mutex of parent dir may be held,
9014 + * but we should not return 'invalid' due to busy.
9016 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9017 + if (unlikely(err)) {
9023 + if (d_really_is_positive(dentry))
9024 + inode = d_inode(dentry);
9025 + if (unlikely(inode && au_is_bad_inode(inode))) {
9030 + if (unlikely(au_dbrange_test(dentry))) {
9036 + sigen = au_sigen(sb);
9037 + if (au_digen_test(dentry, sigen)) {
9038 + AuDebugOn(IS_ROOT(dentry));
9039 + err = au_reval_dpath(dentry, sigen);
9040 + if (unlikely(err)) {
9045 + di_downgrade_lock(dentry, AuLock_IR);
9048 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9050 + && !(inode->i_state && I_LINKABLE)
9051 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9056 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9057 + if (do_udba && inode) {
9058 + aufs_bindex_t btop = au_ibtop(inode);
9059 + struct inode *h_inode;
9062 + h_inode = au_h_iptr(inode, btop);
9063 + if (h_inode && au_test_higen(inode, h_inode)) {
9070 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9071 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9072 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9074 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9080 + di_downgrade_lock(dentry, AuLock_IR);
9082 + aufs_read_unlock(dentry, AuLock_IR);
9087 + AuDbg("%pd invalid, %d\n", dentry, valid);
9093 +static void aufs_d_release(struct dentry *dentry)
9095 + if (au_di(dentry)) {
9096 + au_di_fin(dentry);
9097 + au_hn_di_reinit(dentry);
9101 +const struct dentry_operations aufs_dop = {
9102 + .d_revalidate = aufs_d_revalidate,
9103 + .d_weak_revalidate = aufs_d_revalidate,
9104 + .d_release = aufs_d_release
9107 +/* aufs_dop without d_revalidate */
9108 +const struct dentry_operations aufs_dop_noreval = {
9109 + .d_release = aufs_d_release
9111 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9112 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9113 +++ linux/fs/aufs/dentry.h 2021-12-03 15:40:58.233313963 +0100
9115 +/* SPDX-License-Identifier: GPL-2.0 */
9117 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9119 + * This program, aufs is free software; you can redistribute it and/or modify
9120 + * it under the terms of the GNU General Public License as published by
9121 + * the Free Software Foundation; either version 2 of the License, or
9122 + * (at your option) any later version.
9124 + * This program is distributed in the hope that it will be useful,
9125 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9126 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9127 + * GNU General Public License for more details.
9129 + * You should have received a copy of the GNU General Public License
9130 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9134 + * lookup and dentry operations
9137 +#ifndef __AUFS_DENTRY_H__
9138 +#define __AUFS_DENTRY_H__
9142 +#include <linux/dcache.h>
9143 +#include "dirren.h"
9146 +struct au_hdentry {
9147 + struct dentry *hd_dentry;
9148 + aufs_bindex_t hd_id;
9152 + atomic_t di_generation;
9154 + struct au_rwsem di_rwsem;
9155 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9156 + unsigned char di_tmpfile; /* to allow the different name */
9157 + struct au_hdentry *di_hdentry;
9158 + struct rcu_head rcu;
9159 +} ____cacheline_aligned_in_smp;
9161 +/* ---------------------------------------------------------------------- */
9163 +/* flags for au_lkup_dentry() */
9164 +#define AuLkup_ALLOW_NEG 1
9165 +#define AuLkup_IGNORE_PERM (1 << 1)
9166 +#define AuLkup_DIRREN (1 << 2)
9167 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9168 +#define au_fset_lkup(flags, name) \
9169 + do { (flags) |= AuLkup_##name; } while (0)
9170 +#define au_fclr_lkup(flags, name) \
9171 + do { (flags) &= ~AuLkup_##name; } while (0)
9173 +#ifndef CONFIG_AUFS_DIRREN
9174 +#undef AuLkup_DIRREN
9175 +#define AuLkup_DIRREN 0
9178 +struct au_do_lookup_args {
9179 + unsigned int flags;
9181 + struct qstr whname, *name;
9182 + struct au_dr_lookup dirren;
9185 +/* ---------------------------------------------------------------------- */
9188 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9190 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9191 + struct path *ppath);
9192 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9193 + struct dentry *h_parent, struct au_branch *br);
9195 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9196 + unsigned int flags);
9197 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9198 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9199 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9200 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9203 +void au_di_init_once(void *_di);
9204 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9205 +void au_di_free(struct au_dinfo *dinfo);
9206 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9207 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9208 +int au_di_init(struct dentry *dentry);
9209 +void au_di_fin(struct dentry *dentry);
9210 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9212 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9213 +void di_read_unlock(struct dentry *d, int flags);
9214 +void di_downgrade_lock(struct dentry *d, int flags);
9215 +void di_write_lock(struct dentry *d, unsigned int lsc);
9216 +void di_write_unlock(struct dentry *d);
9217 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9218 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9219 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9221 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9222 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9223 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9224 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9226 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9227 + struct dentry *h_dentry);
9228 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9229 +int au_dbrange_test(struct dentry *dentry);
9230 +void au_update_digen(struct dentry *dentry);
9231 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9232 +void au_update_dbtop(struct dentry *dentry);
9233 +void au_update_dbbot(struct dentry *dentry);
9234 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9236 +/* ---------------------------------------------------------------------- */
9238 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9240 + return dentry->d_fsdata;
9243 +/* ---------------------------------------------------------------------- */
9245 +/* lock subclass for dinfo */
9247 + AuLsc_DI_CHILD, /* child first */
9248 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9249 + AuLsc_DI_CHILD3, /* copyup dirs */
9253 + AuLsc_DI_TMP /* temp for replacing dinfo */
9257 + * di_read_lock_child, di_write_lock_child,
9258 + * di_read_lock_child2, di_write_lock_child2,
9259 + * di_read_lock_child3, di_write_lock_child3,
9260 + * di_read_lock_parent, di_write_lock_parent,
9261 + * di_read_lock_parent2, di_write_lock_parent2,
9262 + * di_read_lock_parent3, di_write_lock_parent3,
9264 +#define AuReadLockFunc(name, lsc) \
9265 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9266 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9268 +#define AuWriteLockFunc(name, lsc) \
9269 +static inline void di_write_lock_##name(struct dentry *d) \
9270 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9272 +#define AuRWLockFuncs(name, lsc) \
9273 + AuReadLockFunc(name, lsc) \
9274 + AuWriteLockFunc(name, lsc)
9276 +AuRWLockFuncs(child, CHILD);
9277 +AuRWLockFuncs(child2, CHILD2);
9278 +AuRWLockFuncs(child3, CHILD3);
9279 +AuRWLockFuncs(parent, PARENT);
9280 +AuRWLockFuncs(parent2, PARENT2);
9281 +AuRWLockFuncs(parent3, PARENT3);
9283 +#undef AuReadLockFunc
9284 +#undef AuWriteLockFunc
9285 +#undef AuRWLockFuncs
9287 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9288 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9289 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9291 +/* ---------------------------------------------------------------------- */
9293 +/* todo: memory barrier? */
9294 +static inline unsigned int au_digen(struct dentry *d)
9296 + return atomic_read(&au_di(d)->di_generation);
9299 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9301 + hdentry->hd_dentry = NULL;
9304 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9305 + aufs_bindex_t bindex)
9307 + return di->di_hdentry + bindex;
9310 +static inline void au_hdput(struct au_hdentry *hd)
9313 + dput(hd->hd_dentry);
9316 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9318 + DiMustAnyLock(dentry);
9319 + return au_di(dentry)->di_btop;
9322 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9324 + DiMustAnyLock(dentry);
9325 + return au_di(dentry)->di_bbot;
9328 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9330 + DiMustAnyLock(dentry);
9331 + return au_di(dentry)->di_bwh;
9334 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9336 + DiMustAnyLock(dentry);
9337 + return au_di(dentry)->di_bdiropq;
9340 +/* todo: hard/soft set? */
9341 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9343 + DiMustWriteLock(dentry);
9344 + au_di(dentry)->di_btop = bindex;
9347 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9349 + DiMustWriteLock(dentry);
9350 + au_di(dentry)->di_bbot = bindex;
9353 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9355 + DiMustWriteLock(dentry);
9356 + /* dbwh can be outside of btop - bbot range */
9357 + au_di(dentry)->di_bwh = bindex;
9360 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9362 + DiMustWriteLock(dentry);
9363 + au_di(dentry)->di_bdiropq = bindex;
9366 +/* ---------------------------------------------------------------------- */
9368 +#ifdef CONFIG_AUFS_HNOTIFY
9369 +static inline void au_digen_dec(struct dentry *d)
9371 + atomic_dec(&au_di(d)->di_generation);
9374 +static inline void au_hn_di_reinit(struct dentry *dentry)
9376 + dentry->d_fsdata = NULL;
9379 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9380 +#endif /* CONFIG_AUFS_HNOTIFY */
9382 +#endif /* __KERNEL__ */
9383 +#endif /* __AUFS_DENTRY_H__ */
9384 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9385 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9386 +++ linux/fs/aufs/dinfo.c 2021-12-03 15:38:59.933313976 +0100
9388 +// SPDX-License-Identifier: GPL-2.0
9390 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9392 + * This program, aufs is free software; you can redistribute it and/or modify
9393 + * it under the terms of the GNU General Public License as published by
9394 + * the Free Software Foundation; either version 2 of the License, or
9395 + * (at your option) any later version.
9397 + * This program is distributed in the hope that it will be useful,
9398 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9399 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9400 + * GNU General Public License for more details.
9402 + * You should have received a copy of the GNU General Public License
9403 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9407 + * dentry private data
9412 +void au_di_init_once(void *_dinfo)
9414 + struct au_dinfo *dinfo = _dinfo;
9416 + au_rw_init(&dinfo->di_rwsem);
9419 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9421 + struct au_dinfo *dinfo;
9424 + dinfo = au_cache_alloc_dinfo();
9425 + if (unlikely(!dinfo))
9428 + nbr = au_sbbot(sb) + 1;
9431 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9432 + if (dinfo->di_hdentry) {
9433 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9434 + dinfo->di_btop = -1;
9435 + dinfo->di_bbot = -1;
9436 + dinfo->di_bwh = -1;
9437 + dinfo->di_bdiropq = -1;
9438 + dinfo->di_tmpfile = 0;
9439 + for (i = 0; i < nbr; i++)
9440 + dinfo->di_hdentry[i].hd_id = -1;
9444 + au_cache_free_dinfo(dinfo);
9451 +void au_di_free(struct au_dinfo *dinfo)
9453 + struct au_hdentry *p;
9454 + aufs_bindex_t bbot, bindex;
9456 + /* dentry may not be revalidated */
9457 + bindex = dinfo->di_btop;
9458 + if (bindex >= 0) {
9459 + bbot = dinfo->di_bbot;
9460 + p = au_hdentry(dinfo, bindex);
9461 + while (bindex++ <= bbot)
9464 + au_kfree_try_rcu(dinfo->di_hdentry);
9465 + au_cache_free_dinfo(dinfo);
9468 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9470 + struct au_hdentry *p;
9473 + AuRwMustWriteLock(&a->di_rwsem);
9474 + AuRwMustWriteLock(&b->di_rwsem);
9476 +#define DiSwap(v, name) \
9478 + v = a->di_##name; \
9479 + a->di_##name = b->di_##name; \
9480 + b->di_##name = v; \
9483 + DiSwap(p, hdentry);
9487 + DiSwap(bi, bdiropq);
9493 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9495 + AuRwMustWriteLock(&dst->di_rwsem);
9496 + AuRwMustWriteLock(&src->di_rwsem);
9498 + dst->di_btop = src->di_btop;
9499 + dst->di_bbot = src->di_bbot;
9500 + dst->di_bwh = src->di_bwh;
9501 + dst->di_bdiropq = src->di_bdiropq;
9505 +int au_di_init(struct dentry *dentry)
9508 + struct super_block *sb;
9509 + struct au_dinfo *dinfo;
9512 + sb = dentry->d_sb;
9513 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9515 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9516 + /* smp_mb(); */ /* atomic_set */
9517 + dentry->d_fsdata = dinfo;
9524 +void au_di_fin(struct dentry *dentry)
9526 + struct au_dinfo *dinfo;
9528 + dinfo = au_di(dentry);
9529 + AuRwDestroy(&dinfo->di_rwsem);
9530 + au_di_free(dinfo);
9533 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9536 + struct au_hdentry *hdp;
9538 + AuRwMustWriteLock(&dinfo->di_rwsem);
9541 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9543 + sz = sizeof(*hdp);
9544 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9547 + dinfo->di_hdentry = hdp;
9554 +/* ---------------------------------------------------------------------- */
9556 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9559 + case AuLsc_DI_CHILD:
9560 + ii_write_lock_child(inode);
9562 + case AuLsc_DI_CHILD2:
9563 + ii_write_lock_child2(inode);
9565 + case AuLsc_DI_CHILD3:
9566 + ii_write_lock_child3(inode);
9568 + case AuLsc_DI_PARENT:
9569 + ii_write_lock_parent(inode);
9571 + case AuLsc_DI_PARENT2:
9572 + ii_write_lock_parent2(inode);
9574 + case AuLsc_DI_PARENT3:
9575 + ii_write_lock_parent3(inode);
9582 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9585 + case AuLsc_DI_CHILD:
9586 + ii_read_lock_child(inode);
9588 + case AuLsc_DI_CHILD2:
9589 + ii_read_lock_child2(inode);
9591 + case AuLsc_DI_CHILD3:
9592 + ii_read_lock_child3(inode);
9594 + case AuLsc_DI_PARENT:
9595 + ii_read_lock_parent(inode);
9597 + case AuLsc_DI_PARENT2:
9598 + ii_read_lock_parent2(inode);
9600 + case AuLsc_DI_PARENT3:
9601 + ii_read_lock_parent3(inode);
9608 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9610 + struct inode *inode;
9612 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9613 + if (d_really_is_positive(d)) {
9614 + inode = d_inode(d);
9615 + if (au_ftest_lock(flags, IW))
9616 + do_ii_write_lock(inode, lsc);
9617 + else if (au_ftest_lock(flags, IR))
9618 + do_ii_read_lock(inode, lsc);
9622 +void di_read_unlock(struct dentry *d, int flags)
9624 + struct inode *inode;
9626 + if (d_really_is_positive(d)) {
9627 + inode = d_inode(d);
9628 + if (au_ftest_lock(flags, IW)) {
9629 + au_dbg_verify_dinode(d);
9630 + ii_write_unlock(inode);
9631 + } else if (au_ftest_lock(flags, IR)) {
9632 + au_dbg_verify_dinode(d);
9633 + ii_read_unlock(inode);
9636 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9639 +void di_downgrade_lock(struct dentry *d, int flags)
9641 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9642 + ii_downgrade_lock(d_inode(d));
9643 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9646 +void di_write_lock(struct dentry *d, unsigned int lsc)
9648 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9649 + if (d_really_is_positive(d))
9650 + do_ii_write_lock(d_inode(d), lsc);
9653 +void di_write_unlock(struct dentry *d)
9655 + au_dbg_verify_dinode(d);
9656 + if (d_really_is_positive(d))
9657 + ii_write_unlock(d_inode(d));
9658 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9661 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9663 + AuDebugOn(d1 == d2
9664 + || d_inode(d1) == d_inode(d2)
9665 + || d1->d_sb != d2->d_sb);
9667 + if ((isdir && au_test_subdir(d1, d2))
9669 + di_write_lock_child(d1);
9670 + di_write_lock_child2(d2);
9672 + di_write_lock_child(d2);
9673 + di_write_lock_child2(d1);
9677 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9679 + AuDebugOn(d1 == d2
9680 + || d_inode(d1) == d_inode(d2)
9681 + || d1->d_sb != d2->d_sb);
9683 + if ((isdir && au_test_subdir(d1, d2))
9685 + di_write_lock_parent(d1);
9686 + di_write_lock_parent2(d2);
9688 + di_write_lock_parent(d2);
9689 + di_write_lock_parent2(d1);
9693 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9695 + di_write_unlock(d1);
9696 + if (d_inode(d1) == d_inode(d2))
9697 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9699 + di_write_unlock(d2);
9702 +/* ---------------------------------------------------------------------- */
9704 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9708 + DiMustAnyLock(dentry);
9710 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9712 + AuDebugOn(bindex < 0);
9713 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9714 + AuDebugOn(d && au_dcount(d) <= 0);
9719 + * extended version of au_h_dptr().
9720 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9723 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9725 + struct dentry *h_dentry;
9726 + struct inode *inode, *h_inode;
9728 + AuDebugOn(d_really_is_negative(dentry));
9731 + if (au_dbtop(dentry) <= bindex
9732 + && bindex <= au_dbbot(dentry))
9733 + h_dentry = au_h_dptr(dentry, bindex);
9734 + if (h_dentry && !au_d_linkable(h_dentry)) {
9736 + goto out; /* success */
9739 + inode = d_inode(dentry);
9740 + AuDebugOn(bindex < au_ibtop(inode));
9741 + AuDebugOn(au_ibbot(inode) < bindex);
9742 + h_inode = au_h_iptr(inode, bindex);
9743 + h_dentry = d_find_alias(h_inode);
9745 + if (!IS_ERR(h_dentry)) {
9746 + if (!au_d_linkable(h_dentry))
9747 + goto out; /* success */
9753 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9754 + h_dentry = au_plink_lkup(inode, bindex);
9755 + AuDebugOn(!h_dentry);
9756 + if (!IS_ERR(h_dentry)) {
9757 + if (!au_d_hashed_positive(h_dentry))
9758 + goto out; /* success */
9765 + AuDbgDentry(h_dentry);
9769 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9771 + aufs_bindex_t bbot, bwh;
9773 + bbot = au_dbbot(dentry);
9775 + bwh = au_dbwh(dentry);
9778 + if (0 < bwh && bwh < bbot)
9784 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9786 + aufs_bindex_t bbot, bopq;
9788 + bbot = au_dbtail(dentry);
9790 + bopq = au_dbdiropq(dentry);
9791 + if (0 <= bopq && bopq < bbot)
9797 +/* ---------------------------------------------------------------------- */
9799 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9800 + struct dentry *h_dentry)
9802 + struct au_dinfo *dinfo;
9803 + struct au_hdentry *hd;
9804 + struct au_branch *br;
9806 + DiMustWriteLock(dentry);
9808 + dinfo = au_di(dentry);
9809 + hd = au_hdentry(dinfo, bindex);
9811 + hd->hd_dentry = h_dentry;
9813 + br = au_sbr(dentry->d_sb, bindex);
9814 + hd->hd_id = br->br_id;
9818 +int au_dbrange_test(struct dentry *dentry)
9821 + aufs_bindex_t btop, bbot;
9824 + btop = au_dbtop(dentry);
9825 + bbot = au_dbbot(dentry);
9827 + AuDebugOn(bbot < 0 && btop > bbot);
9830 + AuDebugOn(bbot >= 0);
9836 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9841 + if (unlikely(au_digen(dentry) != sigen
9842 + || au_iigen_test(d_inode(dentry), sigen)))
9848 +void au_update_digen(struct dentry *dentry)
9850 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9851 + /* smp_mb(); */ /* atomic_set */
9854 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9856 + struct au_dinfo *dinfo;
9857 + struct dentry *h_d;
9858 + struct au_hdentry *hdp;
9859 + aufs_bindex_t bindex, bbot;
9861 + DiMustWriteLock(dentry);
9863 + dinfo = au_di(dentry);
9864 + if (!dinfo || dinfo->di_btop < 0)
9867 + if (do_put_zero) {
9868 + bbot = dinfo->di_bbot;
9869 + bindex = dinfo->di_btop;
9870 + hdp = au_hdentry(dinfo, bindex);
9871 + for (; bindex <= bbot; bindex++, hdp++) {
9872 + h_d = hdp->hd_dentry;
9873 + if (h_d && d_is_negative(h_d))
9874 + au_set_h_dptr(dentry, bindex, NULL);
9878 + dinfo->di_btop = 0;
9879 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9880 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9881 + if (hdp->hd_dentry)
9883 + if (dinfo->di_btop > dinfo->di_bbot) {
9884 + dinfo->di_btop = -1;
9885 + dinfo->di_bbot = -1;
9889 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9890 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9891 + if (hdp->hd_dentry)
9893 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9896 +void au_update_dbtop(struct dentry *dentry)
9898 + aufs_bindex_t bindex, bbot;
9899 + struct dentry *h_dentry;
9901 + bbot = au_dbbot(dentry);
9902 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9903 + h_dentry = au_h_dptr(dentry, bindex);
9906 + if (d_is_positive(h_dentry)) {
9907 + au_set_dbtop(dentry, bindex);
9910 + au_set_h_dptr(dentry, bindex, NULL);
9914 +void au_update_dbbot(struct dentry *dentry)
9916 + aufs_bindex_t bindex, btop;
9917 + struct dentry *h_dentry;
9919 + btop = au_dbtop(dentry);
9920 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9921 + h_dentry = au_h_dptr(dentry, bindex);
9924 + if (d_is_positive(h_dentry)) {
9925 + au_set_dbbot(dentry, bindex);
9928 + au_set_h_dptr(dentry, bindex, NULL);
9932 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9934 + aufs_bindex_t bindex, bbot;
9936 + bbot = au_dbbot(dentry);
9937 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9938 + if (au_h_dptr(dentry, bindex) == h_dentry)
9942 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9943 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9944 +++ linux/fs/aufs/dir.c 2021-12-03 15:40:58.233313963 +0100
9946 +// SPDX-License-Identifier: GPL-2.0
9948 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9950 + * This program, aufs is free software; you can redistribute it and/or modify
9951 + * it under the terms of the GNU General Public License as published by
9952 + * the Free Software Foundation; either version 2 of the License, or
9953 + * (at your option) any later version.
9955 + * This program is distributed in the hope that it will be useful,
9956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9958 + * GNU General Public License for more details.
9960 + * You should have received a copy of the GNU General Public License
9961 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9965 + * directory operations
9968 +#include <linux/fs_stack.h>
9969 +#include <linux/iversion.h>
9972 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9974 + unsigned int nlink;
9976 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9978 + nlink = dir->i_nlink;
9979 + nlink += h_dir->i_nlink - 2;
9980 + if (h_dir->i_nlink < 2)
9982 + smp_mb(); /* for i_nlink */
9983 + /* 0 can happen in revaliding */
9984 + set_nlink(dir, nlink);
9987 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9989 + unsigned int nlink;
9991 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9993 + nlink = dir->i_nlink;
9994 + nlink -= h_dir->i_nlink - 2;
9995 + if (h_dir->i_nlink < 2)
9997 + smp_mb(); /* for i_nlink */
9998 + /* nlink == 0 means the branch-fs is broken */
9999 + set_nlink(dir, nlink);
10002 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10005 + aufs_bindex_t bindex, bbot;
10006 + struct file *h_file;
10007 + struct dentry *h_dentry;
10011 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10013 + bbot = au_fbbot_dir(file);
10014 + for (bindex = au_fbtop(file);
10015 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10017 + h_file = au_hf_dir(file, bindex);
10018 + if (h_file && file_inode(h_file))
10019 + sz += vfsub_f_size_read(h_file);
10022 + AuDebugOn(!dentry);
10023 + AuDebugOn(!d_is_dir(dentry));
10025 + bbot = au_dbtaildir(dentry);
10026 + for (bindex = au_dbtop(dentry);
10027 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10029 + h_dentry = au_h_dptr(dentry, bindex);
10030 + if (h_dentry && d_is_positive(h_dentry))
10031 + sz += i_size_read(d_inode(h_dentry));
10034 + if (sz < KMALLOC_MAX_SIZE)
10035 + sz = roundup_pow_of_two(sz);
10036 + if (sz > KMALLOC_MAX_SIZE)
10037 + sz = KMALLOC_MAX_SIZE;
10038 + else if (sz < NAME_MAX) {
10039 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10040 + sz = AUFS_RDBLK_DEF;
10045 +struct au_dir_ts_arg {
10046 + struct dentry *dentry;
10047 + aufs_bindex_t brid;
10050 +static void au_do_dir_ts(void *arg)
10052 + struct au_dir_ts_arg *a = arg;
10053 + struct au_dtime dt;
10054 + struct path h_path;
10055 + struct inode *dir, *h_dir;
10056 + struct super_block *sb;
10057 + struct au_branch *br;
10058 + struct au_hinode *hdir;
10060 + aufs_bindex_t btop, bindex;
10062 + sb = a->dentry->d_sb;
10063 + if (d_really_is_negative(a->dentry))
10065 + /* no dir->i_mutex lock */
10066 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10068 + dir = d_inode(a->dentry);
10069 + btop = au_ibtop(dir);
10070 + bindex = au_br_index(sb, a->brid);
10071 + if (bindex < btop)
10074 + br = au_sbr(sb, bindex);
10075 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10076 + if (!h_path.dentry)
10078 + h_path.mnt = au_br_mnt(br);
10079 + au_dtime_store(&dt, a->dentry, &h_path);
10081 + br = au_sbr(sb, btop);
10082 + if (!au_br_writable(br->br_perm))
10084 + h_path.dentry = au_h_dptr(a->dentry, btop);
10085 + h_path.mnt = au_br_mnt(br);
10086 + err = vfsub_mnt_want_write(h_path.mnt);
10089 + hdir = au_hi(dir, btop);
10090 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10091 + h_dir = au_h_iptr(dir, btop);
10092 + if (h_dir->i_nlink
10093 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10094 + dt.dt_h_path = h_path;
10095 + au_dtime_revert(&dt);
10097 + au_hn_inode_unlock(hdir);
10098 + vfsub_mnt_drop_write(h_path.mnt);
10099 + au_cpup_attr_timesizes(dir);
10102 + aufs_read_unlock(a->dentry, AuLock_DW);
10105 + au_nwt_done(&au_sbi(sb)->si_nowait);
10106 + au_kfree_try_rcu(arg);
10109 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10111 + int perm, wkq_err;
10112 + aufs_bindex_t btop;
10113 + struct au_dir_ts_arg *arg;
10114 + struct dentry *dentry;
10115 + struct super_block *sb;
10119 + dentry = d_find_any_alias(dir);
10120 + AuDebugOn(!dentry);
10121 + sb = dentry->d_sb;
10122 + btop = au_ibtop(dir);
10123 + if (btop == bindex) {
10124 + au_cpup_attr_timesizes(dir);
10128 + perm = au_sbr_perm(sb, btop);
10129 + if (!au_br_writable(perm))
10132 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10136 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10137 + arg->brid = au_sbr_id(sb, bindex);
10138 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10139 + if (unlikely(wkq_err)) {
10140 + pr_err("wkq %d\n", wkq_err);
10142 + au_kfree_try_rcu(arg);
10149 +/* ---------------------------------------------------------------------- */
10151 +static int reopen_dir(struct file *file)
10154 + unsigned int flags;
10155 + aufs_bindex_t bindex, btail, btop;
10156 + struct dentry *dentry, *h_dentry;
10157 + struct file *h_file;
10159 + /* open all lower dirs */
10160 + dentry = file->f_path.dentry;
10161 + btop = au_dbtop(dentry);
10162 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10163 + au_set_h_fptr(file, bindex, NULL);
10164 + au_set_fbtop(file, btop);
10166 + btail = au_dbtaildir(dentry);
10167 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10168 + au_set_h_fptr(file, bindex, NULL);
10169 + au_set_fbbot_dir(file, btail);
10171 + flags = vfsub_file_flags(file);
10172 + for (bindex = btop; bindex <= btail; bindex++) {
10173 + h_dentry = au_h_dptr(dentry, bindex);
10176 + h_file = au_hf_dir(file, bindex);
10180 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10181 + err = PTR_ERR(h_file);
10182 + if (IS_ERR(h_file))
10183 + goto out; /* close all? */
10184 + au_set_h_fptr(file, bindex, h_file);
10186 + au_update_figen(file);
10187 + /* todo: necessary? */
10188 + /* file->f_ra = h_file->f_ra; */
10195 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10198 + aufs_bindex_t bindex, btail;
10199 + struct dentry *dentry, *h_dentry;
10200 + struct vfsmount *mnt;
10202 + FiMustWriteLock(file);
10203 + AuDebugOn(h_file);
10206 + mnt = file->f_path.mnt;
10207 + dentry = file->f_path.dentry;
10208 + file->f_version = inode_query_iversion(d_inode(dentry));
10209 + bindex = au_dbtop(dentry);
10210 + au_set_fbtop(file, bindex);
10211 + btail = au_dbtaildir(dentry);
10212 + au_set_fbbot_dir(file, btail);
10213 + for (; !err && bindex <= btail; bindex++) {
10214 + h_dentry = au_h_dptr(dentry, bindex);
10218 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10219 + if (unlikely(err))
10221 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10222 + if (IS_ERR(h_file)) {
10223 + err = PTR_ERR(h_file);
10226 + au_set_h_fptr(file, bindex, h_file);
10228 + au_update_figen(file);
10229 + /* todo: necessary? */
10230 + /* file->f_ra = h_file->f_ra; */
10232 + return 0; /* success */
10235 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10236 + au_set_h_fptr(file, bindex, NULL);
10237 + au_set_fbtop(file, -1);
10238 + au_set_fbbot_dir(file, -1);
10243 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10244 + struct file *file)
10247 + struct super_block *sb;
10248 + struct au_fidir *fidir;
10251 + sb = file->f_path.dentry->d_sb;
10252 + si_read_lock(sb, AuLock_FLUSH);
10253 + fidir = au_fidir_alloc(sb);
10255 + struct au_do_open_args args = {
10256 + .open = do_open_dir,
10259 + err = au_do_open(file, &args);
10260 + if (unlikely(err))
10261 + au_kfree_rcu(fidir);
10263 + si_read_unlock(sb);
10267 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10268 + struct file *file)
10270 + struct au_vdir *vdir_cache;
10271 + struct au_finfo *finfo;
10272 + struct au_fidir *fidir;
10273 + struct au_hfile *hf;
10274 + aufs_bindex_t bindex, bbot;
10276 + finfo = au_fi(file);
10277 + fidir = finfo->fi_hdir;
10279 + au_hbl_del(&finfo->fi_hlist,
10280 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10281 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10283 + au_vdir_free(vdir_cache);
10285 + bindex = finfo->fi_btop;
10286 + if (bindex >= 0) {
10287 + hf = fidir->fd_hfile + bindex;
10289 + * calls fput() instead of filp_close(),
10290 + * since no dnotify or lock for the lower file.
10292 + bbot = fidir->fd_bbot;
10293 + for (; bindex <= bbot; bindex++, hf++)
10295 + au_hfput(hf, /*execed*/0);
10297 + au_kfree_rcu(fidir);
10298 + finfo->fi_hdir = NULL;
10300 + au_finfo_fin(file);
10304 +/* ---------------------------------------------------------------------- */
10306 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10309 + aufs_bindex_t bindex, bbot;
10310 + struct file *h_file;
10313 + bbot = au_fbbot_dir(file);
10314 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10315 + h_file = au_hf_dir(file, bindex);
10317 + err = vfsub_flush(h_file, id);
10322 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10324 + return au_do_flush(file, id, au_do_flush_dir);
10327 +/* ---------------------------------------------------------------------- */
10329 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10332 + aufs_bindex_t bbot, bindex;
10333 + struct inode *inode;
10334 + struct super_block *sb;
10337 + sb = dentry->d_sb;
10338 + inode = d_inode(dentry);
10339 + IMustLock(inode);
10340 + bbot = au_dbbot(dentry);
10341 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10342 + struct path h_path;
10344 + if (au_test_ro(sb, bindex, inode))
10346 + h_path.dentry = au_h_dptr(dentry, bindex);
10347 + if (!h_path.dentry)
10350 + h_path.mnt = au_sbr_mnt(sb, bindex);
10351 + err = vfsub_fsync(NULL, &h_path, datasync);
10357 +static int au_do_fsync_dir(struct file *file, int datasync)
10360 + aufs_bindex_t bbot, bindex;
10361 + struct file *h_file;
10362 + struct super_block *sb;
10363 + struct inode *inode;
10365 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10366 + if (unlikely(err))
10369 + inode = file_inode(file);
10370 + sb = inode->i_sb;
10371 + bbot = au_fbbot_dir(file);
10372 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10373 + h_file = au_hf_dir(file, bindex);
10374 + if (!h_file || au_test_ro(sb, bindex, inode))
10377 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10385 + * @file may be NULL
10387 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10391 + struct dentry *dentry;
10392 + struct inode *inode;
10393 + struct super_block *sb;
10396 + dentry = file->f_path.dentry;
10397 + inode = d_inode(dentry);
10398 + inode_lock(inode);
10399 + sb = dentry->d_sb;
10400 + si_noflush_read_lock(sb);
10402 + err = au_do_fsync_dir(file, datasync);
10404 + di_write_lock_child(dentry);
10405 + err = au_do_fsync_dir_no_file(dentry, datasync);
10407 + au_cpup_attr_timesizes(inode);
10408 + di_write_unlock(dentry);
10410 + fi_write_unlock(file);
10412 + si_read_unlock(sb);
10413 + inode_unlock(inode);
10417 +/* ---------------------------------------------------------------------- */
10419 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10422 + struct dentry *dentry;
10423 + struct inode *inode, *h_inode;
10424 + struct super_block *sb;
10426 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10428 + dentry = file->f_path.dentry;
10429 + inode = d_inode(dentry);
10430 + IMustLock(inode);
10432 + sb = dentry->d_sb;
10433 + si_read_lock(sb, AuLock_FLUSH);
10434 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10435 + if (unlikely(err))
10437 + err = au_alive_dir(dentry);
10439 + err = au_vdir_init(file);
10440 + di_downgrade_lock(dentry, AuLock_IR);
10441 + if (unlikely(err))
10444 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10445 + if (!au_test_nfsd()) {
10446 + err = au_vdir_fill_de(file, ctx);
10447 + fsstack_copy_attr_atime(inode, h_inode);
10450 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10451 + * encode_fh() and others.
10453 + atomic_inc(&h_inode->i_count);
10454 + di_read_unlock(dentry, AuLock_IR);
10455 + si_read_unlock(sb);
10456 + err = au_vdir_fill_de(file, ctx);
10457 + fsstack_copy_attr_atime(inode, h_inode);
10458 + fi_write_unlock(file);
10466 + di_read_unlock(dentry, AuLock_IR);
10467 + fi_write_unlock(file);
10469 + si_read_unlock(sb);
10473 +/* ---------------------------------------------------------------------- */
10475 +#define AuTestEmpty_WHONLY 1
10476 +#define AuTestEmpty_CALLED (1 << 1)
10477 +#define AuTestEmpty_SHWH (1 << 2)
10478 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10479 +#define au_fset_testempty(flags, name) \
10480 + do { (flags) |= AuTestEmpty_##name; } while (0)
10481 +#define au_fclr_testempty(flags, name) \
10482 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10484 +#ifndef CONFIG_AUFS_SHWH
10485 +#undef AuTestEmpty_SHWH
10486 +#define AuTestEmpty_SHWH 0
10489 +struct test_empty_arg {
10490 + struct dir_context ctx;
10491 + struct au_nhash *whlist;
10492 + unsigned int flags;
10494 + aufs_bindex_t bindex;
10497 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10498 + int namelen, loff_t offset __maybe_unused, u64 ino,
10499 + unsigned int d_type)
10501 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10503 + char *name = (void *)__name;
10506 + au_fset_testempty(arg->flags, CALLED);
10508 + if (name[0] == '.'
10509 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10510 + goto out; /* success */
10512 + if (namelen <= AUFS_WH_PFX_LEN
10513 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10514 + if (au_ftest_testempty(arg->flags, WHONLY)
10515 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10516 + arg->err = -ENOTEMPTY;
10520 + name += AUFS_WH_PFX_LEN;
10521 + namelen -= AUFS_WH_PFX_LEN;
10522 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10523 + arg->err = au_nhash_append_wh
10524 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10525 + au_ftest_testempty(arg->flags, SHWH));
10529 + AuTraceErr(arg->err);
10533 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10536 + struct file *h_file;
10537 + struct au_branch *br;
10539 + h_file = au_h_open(dentry, arg->bindex,
10540 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10541 + /*file*/NULL, /*force_wr*/0);
10542 + err = PTR_ERR(h_file);
10543 + if (IS_ERR(h_file))
10547 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10548 + && !file_inode(h_file)->i_nlink)
10553 + au_fclr_testempty(arg->flags, CALLED);
10555 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10558 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10562 + br = au_sbr(dentry->d_sb, arg->bindex);
10563 + au_lcnt_dec(&br->br_nfiles);
10568 +struct do_test_empty_args {
10570 + struct dentry *dentry;
10571 + struct test_empty_arg *arg;
10574 +static void call_do_test_empty(void *args)
10576 + struct do_test_empty_args *a = args;
10577 + *a->errp = do_test_empty(a->dentry, a->arg);
10580 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10582 + int err, wkq_err;
10583 + struct dentry *h_dentry;
10584 + struct inode *h_inode;
10585 + struct user_namespace *h_userns;
10587 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10588 + h_dentry = au_h_dptr(dentry, arg->bindex);
10589 + h_inode = d_inode(h_dentry);
10590 + /* todo: i_mode changes anytime? */
10591 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10592 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10593 + inode_unlock_shared(h_inode);
10595 + err = do_test_empty(dentry, arg);
10597 + struct do_test_empty_args args = {
10599 + .dentry = dentry,
10602 + unsigned int flags = arg->flags;
10604 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10605 + if (unlikely(wkq_err))
10607 + arg->flags = flags;
10613 +int au_test_empty_lower(struct dentry *dentry)
10616 + unsigned int rdhash;
10617 + aufs_bindex_t bindex, btop, btail;
10618 + struct au_nhash whlist;
10619 + struct test_empty_arg arg = {
10621 + .actor = test_empty_cb
10624 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10626 + SiMustAnyLock(dentry->d_sb);
10628 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10630 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10631 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10632 + if (unlikely(err))
10636 + arg.whlist = &whlist;
10637 + btop = au_dbtop(dentry);
10638 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10639 + au_fset_testempty(arg.flags, SHWH);
10640 + test_empty = do_test_empty;
10641 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10642 + test_empty = sio_test_empty;
10643 + arg.bindex = btop;
10644 + err = test_empty(dentry, &arg);
10645 + if (unlikely(err))
10648 + au_fset_testempty(arg.flags, WHONLY);
10649 + btail = au_dbtaildir(dentry);
10650 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10651 + struct dentry *h_dentry;
10653 + h_dentry = au_h_dptr(dentry, bindex);
10654 + if (h_dentry && d_is_positive(h_dentry)) {
10655 + arg.bindex = bindex;
10656 + err = test_empty(dentry, &arg);
10661 + au_nhash_wh_free(&whlist);
10666 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10669 + struct test_empty_arg arg = {
10671 + .actor = test_empty_cb
10674 + aufs_bindex_t bindex, btail;
10677 + arg.whlist = whlist;
10678 + arg.flags = AuTestEmpty_WHONLY;
10679 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10680 + au_fset_testempty(arg.flags, SHWH);
10681 + btail = au_dbtaildir(dentry);
10682 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10683 + struct dentry *h_dentry;
10685 + h_dentry = au_h_dptr(dentry, bindex);
10686 + if (h_dentry && d_is_positive(h_dentry)) {
10687 + arg.bindex = bindex;
10688 + err = sio_test_empty(dentry, &arg);
10695 +/* ---------------------------------------------------------------------- */
10697 +const struct file_operations aufs_dir_fop = {
10698 + .owner = THIS_MODULE,
10699 + .llseek = default_llseek,
10700 + .read = generic_read_dir,
10701 + .iterate_shared = aufs_iterate_shared,
10702 + .unlocked_ioctl = aufs_ioctl_dir,
10703 +#ifdef CONFIG_COMPAT
10704 + .compat_ioctl = aufs_compat_ioctl_dir,
10706 + .open = aufs_open_dir,
10707 + .release = aufs_release_dir,
10708 + .flush = aufs_flush_dir,
10709 + .fsync = aufs_fsync_dir
10711 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10712 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10713 +++ linux/fs/aufs/dir.h 2021-12-03 15:38:59.933313976 +0100
10715 +/* SPDX-License-Identifier: GPL-2.0 */
10717 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10719 + * This program, aufs is free software; you can redistribute it and/or modify
10720 + * it under the terms of the GNU General Public License as published by
10721 + * the Free Software Foundation; either version 2 of the License, or
10722 + * (at your option) any later version.
10724 + * This program is distributed in the hope that it will be useful,
10725 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10726 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10727 + * GNU General Public License for more details.
10729 + * You should have received a copy of the GNU General Public License
10730 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10734 + * directory operations
10737 +#ifndef __AUFS_DIR_H__
10738 +#define __AUFS_DIR_H__
10742 +#include <linux/fs.h>
10744 +/* ---------------------------------------------------------------------- */
10746 +/* need to be faster and smaller */
10749 + unsigned int nh_num;
10750 + struct hlist_head *nh_head;
10753 +struct au_vdir_destr {
10754 + unsigned char len;
10755 + unsigned char name[];
10758 +struct au_vdir_dehstr {
10759 + struct hlist_node hash;
10760 + struct au_vdir_destr *str;
10761 + struct rcu_head rcu;
10762 +} ____cacheline_aligned_in_smp;
10764 +struct au_vdir_de {
10766 + unsigned char de_type;
10767 + /* caution: packed */
10768 + struct au_vdir_destr de_str;
10771 +struct au_vdir_wh {
10772 + struct hlist_node wh_hash;
10773 +#ifdef CONFIG_AUFS_SHWH
10775 + aufs_bindex_t wh_bindex;
10776 + unsigned char wh_type;
10778 + aufs_bindex_t wh_bindex;
10780 + /* caution: packed */
10781 + struct au_vdir_destr wh_str;
10784 +union au_vdir_deblk_p {
10785 + unsigned char *deblk;
10786 + struct au_vdir_de *de;
10790 + unsigned char **vd_deblk;
10791 + unsigned long vd_nblk;
10793 + unsigned long ul;
10794 + union au_vdir_deblk_p p;
10798 + unsigned int vd_deblk_sz;
10799 + unsigned long vd_jiffy;
10800 + struct rcu_head rcu;
10801 +} ____cacheline_aligned_in_smp;
10803 +/* ---------------------------------------------------------------------- */
10806 +extern const struct file_operations aufs_dir_fop;
10807 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10808 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10809 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10810 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10811 +int au_test_empty_lower(struct dentry *dentry);
10812 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10815 +unsigned int au_rdhash_est(loff_t sz);
10816 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10817 +void au_nhash_wh_free(struct au_nhash *whlist);
10818 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10820 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10821 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10822 + unsigned int d_type, aufs_bindex_t bindex,
10823 + unsigned char shwh);
10824 +void au_vdir_free(struct au_vdir *vdir);
10825 +int au_vdir_init(struct file *file);
10826 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10829 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10831 +#ifdef CONFIG_AUFS_RDU
10833 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10834 +#ifdef CONFIG_COMPAT
10835 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10836 + unsigned long arg);
10839 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10840 + unsigned int cmd, unsigned long arg)
10841 +#ifdef CONFIG_COMPAT
10842 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10843 + unsigned int cmd, unsigned long arg)
10847 +#endif /* __KERNEL__ */
10848 +#endif /* __AUFS_DIR_H__ */
10849 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10850 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10851 +++ linux/fs/aufs/dirren.c 2021-12-03 15:38:59.933313976 +0100
10853 +// SPDX-License-Identifier: GPL-2.0
10855 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10857 + * This program, aufs is free software; you can redistribute it and/or modify
10858 + * it under the terms of the GNU General Public License as published by
10859 + * the Free Software Foundation; either version 2 of the License, or
10860 + * (at your option) any later version.
10862 + * This program is distributed in the hope that it will be useful,
10863 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10864 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10865 + * GNU General Public License for more details.
10867 + * You should have received a copy of the GNU General Public License
10868 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10872 + * special handling in renaming a directory
10873 + * in order to support looking-up the before-renamed name on the lower readonly
10877 +#include <linux/byteorder/generic.h>
10880 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10884 + idx = au_dr_ihash(ent->dr_h_ino);
10885 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10888 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10891 + struct hlist_bl_head *hbl;
10894 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10895 + hbl = dr->dr_h_ino + i;
10896 + hlist_bl_lock(hbl);
10897 + ret &= hlist_bl_empty(hbl);
10898 + hlist_bl_unlock(hbl);
10904 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10906 + struct au_dr_hino *found, *ent;
10907 + struct hlist_bl_head *hbl;
10908 + struct hlist_bl_node *pos;
10912 + idx = au_dr_ihash(ino);
10913 + hbl = dr->dr_h_ino + idx;
10914 + hlist_bl_lock(hbl);
10915 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10916 + if (ent->dr_h_ino == ino) {
10920 + hlist_bl_unlock(hbl);
10925 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10926 + struct au_dr_hino *add_ent)
10929 + struct hlist_bl_head *hbl;
10930 + struct hlist_bl_node *pos;
10931 + struct au_dr_hino *ent;
10934 + idx = au_dr_ihash(ino);
10935 + hbl = dr->dr_h_ino + idx;
10936 +#if 0 /* debug print */
10938 + struct hlist_bl_node *tmp;
10940 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10941 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10944 + hlist_bl_lock(hbl);
10945 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10946 + if (ent->dr_h_ino == ino) {
10950 + if (!found && add_ent)
10951 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10952 + hlist_bl_unlock(hbl);
10954 + if (!found && add_ent)
10955 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10960 +void au_dr_hino_free(struct au_dr_br *dr)
10963 + struct hlist_bl_head *hbl;
10964 + struct hlist_bl_node *pos, *tmp;
10965 + struct au_dr_hino *ent;
10967 + /* SiMustWriteLock(sb); */
10969 + for (i = 0; i < AuDirren_NHASH; i++) {
10970 + hbl = dr->dr_h_ino + i;
10971 + /* no spinlock since sbinfo must be write-locked */
10972 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10973 + au_kfree_rcu(ent);
10974 + INIT_HLIST_BL_HEAD(hbl);
10978 +/* returns the number of inodes or an error */
10979 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10980 + struct file *hinofile)
10984 + loff_t pos, oldsize;
10986 + struct inode *hinoinode;
10987 + struct hlist_bl_head *hbl;
10988 + struct hlist_bl_node *n1, *n2;
10989 + struct au_dr_hino *ent;
10991 + SiMustWriteLock(sb);
10992 + AuDebugOn(!au_br_writable(br->br_perm));
10994 + hinoinode = file_inode(hinofile);
10995 + oldsize = i_size_read(hinoinode);
10999 + hbl = br->br_dirren.dr_h_ino;
11000 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11001 + /* no bit-lock since sbinfo must be write-locked */
11002 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11003 + AuDbg("hi%llu, %pD2\n",
11004 + (unsigned long long)ent->dr_h_ino, hinofile);
11005 + u64 = cpu_to_be64(ent->dr_h_ino);
11006 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11007 + if (ssz == sizeof(u64))
11010 + /* write error */
11011 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11018 + /* regardless the error */
11019 + if (pos < oldsize) {
11020 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11028 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11035 + struct au_dr_hino *ent;
11036 + struct inode *hinoinode;
11037 + struct hlist_bl_head *hbl;
11041 + hbl = dr->dr_h_ino;
11042 + hinoinode = file_inode(hinofile);
11043 + sz = i_size_read(hinoinode);
11044 + AuDebugOn(sz % sizeof(u64));
11045 + n = sz / sizeof(u64);
11047 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11048 + if (unlikely(ssz != sizeof(u64))) {
11049 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11056 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11062 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11063 + AuDbg("hi%llu, %pD2\n",
11064 + (unsigned long long)ent->dr_h_ino, hinofile);
11065 + hidx = au_dr_ihash(ent->dr_h_ino);
11066 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11068 + goto out; /* success */
11071 + au_dr_hino_free(dr);
11078 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11079 + * @path is a switch to distinguish load and store.
11081 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11082 + struct au_branch *br, const struct path *path)
11085 + unsigned char load, suspend;
11086 + struct file *hinofile;
11087 + struct au_hinode *hdir;
11088 + struct inode *dir, *delegated;
11089 + struct path hinopath;
11090 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11091 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11093 + AuDebugOn(bindex < 0 && !br);
11094 + AuDebugOn(bindex >= 0 && br);
11099 + br = au_sbr(sb, bindex);
11102 + path = &br->br_path;
11103 + AuDebugOn(!au_br_writable(br->br_perm));
11104 + if (unlikely(!au_br_writable(br->br_perm)))
11110 + dir = d_inode(sb->s_root);
11111 + hdir = au_hinode(au_ii(dir), bindex);
11112 + dir = hdir->hi_inode;
11113 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11115 + dir = d_inode(path->dentry);
11116 + inode_lock_nested(dir, AuLsc_I_CHILD);
11118 + hinopath.mnt = path->mnt;
11119 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11120 + err = PTR_ERR(hinopath.dentry);
11121 + if (IS_ERR(hinopath.dentry))
11125 + flags = O_RDONLY;
11127 + if (d_is_negative(hinopath.dentry))
11128 + goto out_dput; /* success */
11130 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11131 + if (d_is_positive(hinopath.dentry)) {
11132 + delegated = NULL;
11133 + err = vfsub_unlink(dir, &hinopath, &delegated,
11136 + if (unlikely(err))
11137 + pr_err("ignored err %d, %pd2\n",
11138 + err, hinopath.dentry);
11139 + if (unlikely(err == -EWOULDBLOCK))
11144 + } else if (!d_is_positive(hinopath.dentry)) {
11145 + err = vfsub_create(dir, &hinopath, 0600,
11146 + /*want_excl*/false);
11148 + if (unlikely(err))
11151 + flags = O_WRONLY;
11153 + hinofile = vfsub_dentry_open(&hinopath, flags);
11155 + au_hn_inode_unlock(hdir);
11157 + inode_unlock(dir);
11158 + dput(hinopath.dentry);
11159 + AuTraceErrPtr(hinofile);
11160 + if (IS_ERR(hinofile)) {
11161 + err = PTR_ERR(hinofile);
11166 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11168 + err = au_dr_hino_store(sb, br, hinofile);
11173 + dput(hinopath.dentry);
11176 + au_hn_inode_unlock(hdir);
11178 + inode_unlock(dir);
11184 +/* ---------------------------------------------------------------------- */
11186 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11189 + struct kstatfs kstfs;
11191 + struct dentry *dentry;
11192 + struct super_block *sb;
11194 + err = vfs_statfs((void *)path, &kstfs);
11196 + if (unlikely(err))
11199 + /* todo: support for UUID */
11201 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11202 + brid->type = AuBrid_FSID;
11203 + brid->fsid = kstfs.f_fsid;
11205 + dentry = path->dentry;
11206 + sb = dentry->d_sb;
11209 + brid->type = AuBrid_DEV;
11218 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11219 + const struct path *path)
11222 + struct au_dr_br *dr;
11223 + struct hlist_bl_head *hbl;
11225 + dr = &br->br_dirren;
11226 + hbl = dr->dr_h_ino;
11227 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11228 + INIT_HLIST_BL_HEAD(hbl);
11230 + err = au_dr_brid_init(&dr->dr_brid, path);
11231 + if (unlikely(err))
11234 + if (au_opt_test(au_mntflags(sb), DIRREN))
11235 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11242 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11247 + if (au_br_writable(br->br_perm))
11248 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11250 + au_dr_hino_free(&br->br_dirren);
11255 +/* ---------------------------------------------------------------------- */
11257 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11258 + char *buf, size_t sz)
11261 + unsigned int major, minor;
11265 + err = snprintf(p, sz, "%d_", brid->type);
11266 + AuDebugOn(err > sz);
11269 + switch (brid->type) {
11270 + case AuBrid_Unset:
11272 + case AuBrid_UUID:
11273 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11275 + case AuBrid_FSID:
11276 + err = snprintf(p, sz, "%08x-%08x",
11277 + brid->fsid.val[0], brid->fsid.val[1]);
11280 + major = MAJOR(brid->dev);
11281 + minor = MINOR(brid->dev);
11282 + if (major <= 0xff && minor <= 0xff)
11283 + err = snprintf(p, sz, "%02x%02x", major, minor);
11285 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11288 + AuDebugOn(err > sz);
11291 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11292 + AuDebugOn(err > sz);
11299 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11302 + struct dentry *br_dentry;
11303 + struct inode *br_inode;
11305 + br_dentry = au_br_dentry(br);
11306 + br_inode = d_inode(br_dentry);
11307 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11308 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11309 + AuDebugOn(rlen > len);
11314 +/* ---------------------------------------------------------------------- */
11317 + * from the given @h_dentry, construct drinfo at @*fdata.
11318 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11321 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11322 + struct dentry *h_dentry,
11323 + unsigned char *allocated)
11326 + struct au_drinfo_fdata *f, *p;
11327 + struct au_drinfo *drinfo;
11328 + struct inode *h_inode;
11329 + struct qstr *qname;
11333 + h_inode = d_inode(h_dentry);
11334 + qname = &h_dentry->d_name;
11335 + drinfo = &f->drinfo;
11336 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11337 + drinfo->oldnamelen = qname->len;
11338 + if (*allocated < sizeof(*f) + qname->len) {
11339 + v = roundup_pow_of_two(*allocated + qname->len);
11340 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11341 + if (unlikely(!p)) {
11349 + drinfo = &f->drinfo;
11351 + memcpy(drinfo->oldname, qname->name, qname->len);
11352 + AuDbg("i%llu, %.*s\n",
11353 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11354 + drinfo->oldname);
11361 +/* callers have to free the return value */
11362 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11364 + struct au_drinfo *ret, *drinfo;
11365 + struct au_drinfo_fdata fdata;
11370 + ret = ERR_PTR(-EIO);
11372 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11373 + if (unlikely(ssz != sizeof(fdata))) {
11374 + AuIOErr("ssz %zd, %u, %pD2\n",
11375 + ssz, (unsigned int)sizeof(fdata), file);
11379 + fdata.magic = ntohl((__force __be32)fdata.magic);
11380 + switch (fdata.magic) {
11381 + case AUFS_DRINFO_MAGIC_V1:
11384 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11385 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11389 + drinfo = &fdata.drinfo;
11390 + len = drinfo->oldnamelen;
11392 + AuIOErr("broken drinfo %pD2\n", file);
11397 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11398 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11399 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11400 + (unsigned long long)drinfo->ino,
11401 + (unsigned long long)h_ino, file);
11402 + goto out; /* success */
11405 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11406 + if (unlikely(!ret)) {
11407 + ret = ERR_PTR(-ENOMEM);
11408 + AuTraceErrPtr(ret);
11413 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11414 + if (unlikely(ssz != len)) {
11415 + au_kfree_rcu(ret);
11416 + ret = ERR_PTR(-EIO);
11417 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11421 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11427 +/* ---------------------------------------------------------------------- */
11429 +/* in order to be revertible */
11430 +struct au_drinfo_rev_elm {
11432 + struct dentry *info_dentry;
11433 + struct au_drinfo *info_last;
11436 +struct au_drinfo_rev {
11437 + unsigned char already;
11438 + aufs_bindex_t nelm;
11439 + struct au_drinfo_rev_elm elm[];
11442 +/* todo: isn't it too large? */
11443 +struct au_drinfo_store {
11444 + struct path h_ppath;
11445 + struct dentry *h_dentry;
11446 + struct au_drinfo_fdata *fdata;
11447 + char *infoname; /* inside of whname, just after PFX */
11448 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11449 + aufs_bindex_t btgt, btail;
11450 + unsigned char no_sio,
11451 + allocated, /* current size of *fdata */
11452 + infonamelen, /* room size for p */
11453 + whnamelen, /* length of the generated name */
11454 + renameback; /* renamed back */
11457 +/* on rename(2) error, the caller should revert it using @elm */
11458 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11459 + struct au_drinfo_rev_elm *elm)
11464 + struct path infopath = {
11465 + .mnt = w->h_ppath.mnt
11467 + struct inode *h_dir, *h_inode, *delegated;
11468 + struct file *infofile;
11469 + struct qstr *qname;
11472 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11474 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11476 + AuTraceErrPtr(infopath.dentry);
11477 + if (IS_ERR(infopath.dentry)) {
11478 + err = PTR_ERR(infopath.dentry);
11483 + h_dir = d_inode(w->h_ppath.dentry);
11484 + if (elm && d_is_negative(infopath.dentry)) {
11485 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11487 + if (unlikely(err))
11489 + elm->created = 1;
11490 + elm->info_dentry = dget(infopath.dentry);
11493 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11494 + AuTraceErrPtr(infofile);
11495 + if (IS_ERR(infofile)) {
11496 + err = PTR_ERR(infofile);
11500 + h_inode = d_inode(infopath.dentry);
11501 + if (elm && i_size_read(h_inode)) {
11502 + h_inode = d_inode(w->h_dentry);
11503 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11504 + AuTraceErrPtr(elm->info_last);
11505 + if (IS_ERR(elm->info_last)) {
11506 + err = PTR_ERR(elm->info_last);
11507 + elm->info_last = NULL;
11508 + AuDebugOn(elm->info_dentry);
11513 + if (elm && w->renameback) {
11514 + delegated = NULL;
11515 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11517 + if (unlikely(err == -EWOULDBLOCK))
11523 + qname = &w->h_dentry->d_name;
11524 + len = sizeof(*w->fdata) + qname->len;
11526 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11527 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11528 + if (ssz == len) {
11529 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11530 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11531 + goto out_fput; /* success */
11536 + /* the caller should revert it using @elm */
11542 + dput(infopath.dentry);
11548 +struct au_call_drinfo_do_store_args {
11550 + struct au_drinfo_store *w;
11551 + struct au_drinfo_rev_elm *elm;
11554 +static void au_call_drinfo_do_store(void *args)
11556 + struct au_call_drinfo_do_store_args *a = args;
11558 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11561 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11562 + struct au_drinfo_rev_elm *elm)
11564 + int err, wkq_err;
11567 + err = au_drinfo_do_store(w, elm);
11569 + struct au_call_drinfo_do_store_args a = {
11574 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11575 + if (unlikely(wkq_err))
11583 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11584 + aufs_bindex_t btgt)
11588 + memset(w, 0, sizeof(*w));
11589 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11590 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11591 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11592 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11594 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11597 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11598 + if (unlikely(!w->fdata)) {
11602 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11609 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11611 + au_kfree_rcu(w->fdata);
11614 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11615 + struct au_drinfo_store *w)
11617 + struct au_drinfo_rev_elm *elm;
11618 + struct inode *h_dir, *delegated;
11620 + struct path infopath = {
11621 + .mnt = w->h_ppath.mnt
11624 + h_dir = d_inode(w->h_ppath.dentry);
11625 + IMustLock(h_dir);
11629 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11630 + AuDebugOn(elm->created && elm->info_last);
11631 + if (elm->created) {
11633 + delegated = NULL;
11634 + infopath.dentry = elm->info_dentry;
11635 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11638 + if (unlikely(err == -EWOULDBLOCK))
11640 + dput(elm->info_dentry);
11641 + } else if (elm->info_last) {
11643 + w->fdata->drinfo = *elm->info_last;
11644 + memcpy(w->fdata->drinfo.oldname,
11645 + elm->info_last->oldname,
11646 + elm->info_last->oldnamelen);
11647 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11648 + au_kfree_rcu(elm->info_last);
11650 + if (unlikely(err))
11651 + AuIOErr("%d, %s\n", err, w->whname);
11652 + /* go on even if err */
11656 +/* caller has to call au_dr_rename_fin() later */
11657 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11658 + struct qstr *dst_name, void *_rev)
11660 + int err, sz, nelm;
11661 + aufs_bindex_t bindex, btail;
11662 + struct au_drinfo_store work;
11663 + struct au_drinfo_rev *rev, **p;
11664 + struct au_drinfo_rev_elm *elm;
11665 + struct super_block *sb;
11666 + struct au_branch *br;
11667 + struct au_hinode *hdir;
11669 + err = au_drinfo_store_work_init(&work, btgt);
11671 + if (unlikely(err))
11675 + btail = au_dbtaildir(dentry);
11676 + nelm = btail - btgt;
11677 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11678 + rev = kcalloc(1, sz, GFP_NOFS);
11679 + if (unlikely(!rev)) {
11683 + rev->nelm = nelm;
11689 + sb = dentry->d_sb;
11690 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11691 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11692 + hdir = au_hi(d_inode(dentry), btgt);
11693 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11694 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11695 + work.h_dentry = au_h_dptr(dentry, bindex);
11696 + if (!work.h_dentry)
11699 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11700 + &work.allocated);
11702 + if (unlikely(err))
11705 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11706 + br = au_sbr(sb, bindex);
11707 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11708 + work.whnamelen += au_drinfo_name(br, work.infoname,
11709 + work.infonamelen);
11710 + AuDbg("whname %.*s, i%llu, %.*s\n",
11711 + work.whnamelen, work.whname,
11712 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11713 + work.fdata->drinfo.oldnamelen,
11714 + work.fdata->drinfo.oldname);
11716 + err = au_drinfo_store_sio(&work, elm);
11718 + if (unlikely(err))
11721 + if (unlikely(err)) {
11722 + /* revert all drinfo */
11723 + au_drinfo_store_rev(rev, &work);
11724 + au_kfree_try_rcu(rev);
11727 + au_hn_inode_unlock(hdir);
11730 + au_drinfo_store_work_fin(&work);
11735 +/* ---------------------------------------------------------------------- */
11737 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11738 + struct qstr *dst_name, void *_rev)
11740 + int err, already;
11742 + struct super_block *sb;
11743 + struct au_branch *br;
11744 + struct au_dr_br *dr;
11745 + struct dentry *h_dentry;
11746 + struct inode *h_inode;
11747 + struct au_dr_hino *ent;
11748 + struct au_drinfo_rev *rev, **p;
11750 + AuDbg("bindex %d\n", bindex);
11753 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11754 + if (unlikely(!ent))
11758 + br = au_sbr(sb, bindex);
11759 + dr = &br->br_dirren;
11760 + h_dentry = au_h_dptr(src, bindex);
11761 + h_inode = d_inode(h_dentry);
11762 + ino = h_inode->i_ino;
11763 + ent->dr_h_ino = ino;
11764 + already = au_dr_hino_test_add(dr, ino, ent);
11765 + AuDbg("b%d, hi%llu, already %d\n",
11766 + bindex, (unsigned long long)ino, already);
11768 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11773 + rev->already = already;
11774 + goto out; /* success */
11779 + au_dr_hino_del(dr, ent);
11780 + au_kfree_rcu(ent);
11787 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11789 + struct au_drinfo_rev *rev;
11790 + struct au_drinfo_rev_elm *elm;
11795 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11796 + dput(elm->info_dentry);
11797 + au_kfree_rcu(elm->info_last);
11799 + au_kfree_try_rcu(rev);
11802 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11805 + struct au_drinfo_store work;
11806 + struct au_drinfo_rev *rev = _rev;
11807 + struct super_block *sb;
11808 + struct au_branch *br;
11809 + struct inode *h_inode;
11810 + struct au_dr_br *dr;
11811 + struct au_dr_hino *ent;
11813 + err = au_drinfo_store_work_init(&work, btgt);
11814 + if (unlikely(err))
11818 + br = au_sbr(sb, btgt);
11819 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11820 + work.h_ppath.mnt = au_br_mnt(br);
11821 + au_drinfo_store_rev(rev, &work);
11822 + au_drinfo_store_work_fin(&work);
11823 + if (rev->already)
11826 + dr = &br->br_dirren;
11827 + h_inode = d_inode(work.h_ppath.dentry);
11828 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11830 + au_dr_hino_del(dr, ent);
11831 + au_kfree_rcu(ent);
11834 + au_kfree_try_rcu(rev);
11835 + if (unlikely(err))
11836 + pr_err("failed to remove dirren info\n");
11839 +/* ---------------------------------------------------------------------- */
11841 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11842 + char *whname, int whnamelen,
11843 + struct dentry **info_dentry)
11845 + struct au_drinfo *drinfo;
11847 + struct inode *h_dir;
11848 + struct path infopath;
11851 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11853 + *info_dentry = NULL;
11856 + h_dir = d_inode(h_ppath->dentry);
11857 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11858 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11859 + if (IS_ERR(infopath.dentry)) {
11860 + drinfo = (void *)infopath.dentry;
11864 + if (d_is_negative(infopath.dentry))
11865 + goto out_dput; /* success */
11867 + infopath.mnt = h_ppath->mnt;
11868 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11869 + inode_unlock_shared(h_dir);
11872 + drinfo = (void *)f;
11876 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11877 + if (IS_ERR_OR_NULL(drinfo))
11880 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11881 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11886 + dput(infopath.dentry);
11889 + inode_unlock_shared(h_dir);
11890 + AuTraceErrPtr(drinfo);
11894 +struct au_drinfo_do_load_args {
11895 + struct au_drinfo **drinfop;
11896 + struct path *h_ppath;
11899 + struct dentry **info_dentry;
11902 +static void au_call_drinfo_do_load(void *args)
11904 + struct au_drinfo_do_load_args *a = args;
11906 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11910 +struct au_drinfo_load {
11911 + struct path h_ppath;
11912 + struct qstr *qname;
11913 + unsigned char no_sio;
11915 + aufs_bindex_t ninfo;
11916 + struct au_drinfo **drinfo;
11919 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11920 + struct au_branch *br)
11922 + int err, wkq_err, whnamelen, e;
11923 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11924 + = AUFS_WH_DR_INFO_PFX;
11925 + struct au_drinfo *drinfo;
11926 + struct qstr oldname;
11927 + struct inode *h_dir, *delegated;
11928 + struct dentry *info_dentry;
11929 + struct path infopath;
11931 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11932 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11933 + sizeof(whname) - whnamelen);
11935 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11938 + struct au_drinfo_do_load_args args = {
11939 + .drinfop = &drinfo,
11940 + .h_ppath = &w->h_ppath,
11941 + .whname = whname,
11942 + .whnamelen = whnamelen,
11943 + .info_dentry = &info_dentry
11945 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11946 + if (unlikely(wkq_err))
11947 + drinfo = ERR_PTR(wkq_err);
11949 + err = PTR_ERR(drinfo);
11950 + if (IS_ERR_OR_NULL(drinfo))
11954 + oldname.len = drinfo->oldnamelen;
11955 + oldname.name = drinfo->oldname;
11956 + if (au_qstreq(w->qname, &oldname)) {
11957 + /* the name is renamed back */
11958 + au_kfree_rcu(drinfo);
11961 + infopath.dentry = info_dentry;
11962 + infopath.mnt = w->h_ppath.mnt;
11963 + h_dir = d_inode(w->h_ppath.dentry);
11964 + delegated = NULL;
11965 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11966 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11967 + inode_unlock(h_dir);
11969 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11970 + if (unlikely(e == -EWOULDBLOCK))
11973 + au_kfree_rcu(w->drinfo[bindex]);
11974 + w->drinfo[bindex] = drinfo;
11975 + dput(info_dentry);
11982 +/* ---------------------------------------------------------------------- */
11984 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11986 + struct au_drinfo **p = drinfo;
11989 + au_kfree_rcu(*drinfo++);
11990 + au_kfree_try_rcu(p);
11993 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
11994 + aufs_bindex_t btgt)
11997 + struct au_drinfo_load w;
11998 + aufs_bindex_t bindex, bbot;
11999 + struct au_branch *br;
12000 + struct inode *h_dir;
12001 + struct au_dr_hino *ent;
12002 + struct super_block *sb;
12004 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12005 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12006 + AuLNPair(&lkup->whname), btgt);
12008 + sb = dentry->d_sb;
12009 + bbot = au_sbbot(sb);
12010 + w.ninfo = bbot + 1;
12011 + if (!lkup->dirren.drinfo) {
12012 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12013 + sizeof(*lkup->dirren.drinfo),
12015 + if (unlikely(!lkup->dirren.drinfo)) {
12019 + lkup->dirren.ninfo = w.ninfo;
12021 + w.drinfo = lkup->dirren.drinfo;
12022 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12023 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12024 + AuDebugOn(!w.h_ppath.dentry);
12025 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12026 + w.qname = &dentry->d_name;
12029 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12030 + br = au_sbr(sb, bindex);
12031 + err = au_drinfo_load(&w, bindex, br);
12032 + if (unlikely(err))
12034 + if (w.drinfo[bindex])
12038 + br = au_sbr(sb, btgt);
12039 + h_dir = d_inode(w.h_ppath.dentry);
12040 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12042 + au_dr_hino_del(&br->br_dirren, ent);
12043 + au_kfree_rcu(ent);
12045 + goto out; /* success */
12048 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12049 + lkup->dirren.ninfo = 0;
12050 + lkup->dirren.drinfo = NULL;
12056 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12058 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12061 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12064 + struct au_drinfo *drinfo;
12067 + if (!lkup->dirren.drinfo)
12069 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12070 + drinfo = lkup->dirren.drinfo[btgt];
12074 + au_kfree_try_rcu(lkup->whname.name);
12075 + lkup->whname.name = NULL;
12076 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12077 + lkup->dirren.dr_name.name = drinfo->oldname;
12078 + lkup->name = &lkup->dirren.dr_name;
12079 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12081 + AuDbg("name %.*s, whname %.*s, b%d\n",
12082 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12090 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12094 + struct au_drinfo *drinfo;
12097 + if (!lkup->dirren.drinfo)
12099 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12100 + drinfo = lkup->dirren.drinfo[bindex];
12104 + match = (drinfo->ino == h_ino);
12105 + AuDbg("match %d\n", match);
12111 +/* ---------------------------------------------------------------------- */
12113 +int au_dr_opt_set(struct super_block *sb)
12116 + aufs_bindex_t bindex, bbot;
12117 + struct au_branch *br;
12120 + bbot = au_sbbot(sb);
12121 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12122 + br = au_sbr(sb, bindex);
12123 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12129 +int au_dr_opt_flush(struct super_block *sb)
12132 + aufs_bindex_t bindex, bbot;
12133 + struct au_branch *br;
12136 + bbot = au_sbbot(sb);
12137 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12138 + br = au_sbr(sb, bindex);
12139 + if (au_br_writable(br->br_perm))
12140 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12146 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12149 + aufs_bindex_t bindex, bbot;
12150 + struct au_branch *br;
12154 + err = au_dr_opt_flush(sb);
12155 + if (unlikely(err))
12159 + bbot = au_sbbot(sb);
12160 + for (bindex = 0; bindex <= bbot; bindex++) {
12161 + br = au_sbr(sb, bindex);
12162 + au_dr_hino_free(&br->br_dirren);
12168 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12169 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12170 +++ linux/fs/aufs/dirren.h 2021-12-03 15:38:59.933313976 +0100
12172 +/* SPDX-License-Identifier: GPL-2.0 */
12174 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12176 + * This program, aufs is free software; you can redistribute it and/or modify
12177 + * it under the terms of the GNU General Public License as published by
12178 + * the Free Software Foundation; either version 2 of the License, or
12179 + * (at your option) any later version.
12181 + * This program is distributed in the hope that it will be useful,
12182 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12183 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12184 + * GNU General Public License for more details.
12186 + * You should have received a copy of the GNU General Public License
12187 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12191 + * renamed dir info
12194 +#ifndef __AUFS_DIRREN_H__
12195 +#define __AUFS_DIRREN_H__
12199 +#include <linux/dcache.h>
12200 +#include <linux/statfs.h>
12201 +#include <linux/uuid.h>
12204 +#define AuDirren_NHASH 100
12206 +#ifdef CONFIG_AUFS_DIRREN
12207 +enum au_brid_type {
12214 +struct au_dr_brid {
12215 + enum au_brid_type type;
12217 + uuid_t uuid; /* unimplemented yet */
12223 +/* 20 is the max digits length of ulong 64 */
12224 +/* brid-type "_" uuid "_" inum */
12225 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12226 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12228 +struct au_dr_hino {
12229 + struct hlist_bl_node dr_hnode;
12234 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12235 + struct au_dr_brid dr_brid;
12238 +struct au_dr_lookup {
12239 + /* dr_name is pointed by struct au_do_lookup_args.name */
12240 + struct qstr dr_name; /* subset of dr_info */
12241 + aufs_bindex_t ninfo;
12242 + struct au_drinfo **drinfo;
12245 +struct au_dr_hino;
12247 +struct au_dr_br { };
12248 +struct au_dr_lookup { };
12251 +/* ---------------------------------------------------------------------- */
12254 +struct au_do_lookup_args;
12256 +#ifdef CONFIG_AUFS_DIRREN
12257 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12258 + struct au_dr_hino *add_ent);
12259 +void au_dr_hino_free(struct au_dr_br *dr);
12260 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12261 + const struct path *path);
12262 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12263 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12264 + struct qstr *dst_name, void *_rev);
12265 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12266 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12267 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12268 + aufs_bindex_t bindex);
12269 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12270 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12272 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12273 +int au_dr_opt_set(struct super_block *sb);
12274 +int au_dr_opt_flush(struct super_block *sb);
12275 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12277 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12278 + struct au_dr_hino *add_ent);
12279 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12280 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12281 + const struct path *path);
12282 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12283 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12284 + struct qstr *dst_name, void *_rev);
12285 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12286 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12288 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12289 + aufs_bindex_t bindex);
12290 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12291 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12292 + aufs_bindex_t bindex, ino_t h_ino);
12293 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12294 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12295 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12296 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12299 +/* ---------------------------------------------------------------------- */
12301 +#ifdef CONFIG_AUFS_DIRREN
12302 +static inline int au_dr_ihash(ino_t h_ino)
12304 + return h_ino % AuDirren_NHASH;
12307 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12310 +#endif /* __KERNEL__ */
12311 +#endif /* __AUFS_DIRREN_H__ */
12312 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12313 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12314 +++ linux/fs/aufs/dynop.c 2021-12-03 15:38:59.933313976 +0100
12316 +// SPDX-License-Identifier: GPL-2.0
12318 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12320 + * This program, aufs is free software; you can redistribute it and/or modify
12321 + * it under the terms of the GNU General Public License as published by
12322 + * the Free Software Foundation; either version 2 of the License, or
12323 + * (at your option) any later version.
12325 + * This program is distributed in the hope that it will be useful,
12326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12328 + * GNU General Public License for more details.
12330 + * You should have received a copy of the GNU General Public License
12331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12335 + * dynamically customizable operations for regular files
12340 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12343 + * How large will these lists be?
12344 + * Usually just a few elements, 20-30 at most for each, I guess.
12346 +static struct hlist_bl_head dynop[AuDyLast];
12348 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12349 + const void *h_op)
12351 + struct au_dykey *key, *tmp;
12352 + struct hlist_bl_node *pos;
12355 + hlist_bl_lock(hbl);
12356 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12357 + if (tmp->dk_op.dy_hop == h_op) {
12358 + if (kref_get_unless_zero(&tmp->dk_kref))
12362 + hlist_bl_unlock(hbl);
12367 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12369 + struct au_dykey **k, *found;
12370 + const void *h_op = key->dk_op.dy_hop;
12374 + k = br->br_dykey;
12375 + for (i = 0; i < AuBrDynOp; i++)
12377 + if (k[i]->dk_op.dy_hop == h_op) {
12384 + spin_lock(&br->br_dykey_lock);
12385 + for (; i < AuBrDynOp; i++)
12387 + if (k[i]->dk_op.dy_hop == h_op) {
12395 + spin_unlock(&br->br_dykey_lock);
12396 + BUG_ON(i == AuBrDynOp); /* expand the array */
12402 +/* kref_get() if @key is already added */
12403 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12405 + struct au_dykey *tmp, *found;
12406 + struct hlist_bl_node *pos;
12407 + const void *h_op = key->dk_op.dy_hop;
12410 + hlist_bl_lock(hbl);
12411 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12412 + if (tmp->dk_op.dy_hop == h_op) {
12413 + if (kref_get_unless_zero(&tmp->dk_kref))
12418 + hlist_bl_add_head(&key->dk_hnode, hbl);
12419 + hlist_bl_unlock(hbl);
12426 +static void dy_free_rcu(struct rcu_head *rcu)
12428 + struct au_dykey *key;
12430 + key = container_of(rcu, struct au_dykey, dk_rcu);
12435 +static void dy_free(struct kref *kref)
12437 + struct au_dykey *key;
12438 + struct hlist_bl_head *hbl;
12440 + key = container_of(kref, struct au_dykey, dk_kref);
12441 + hbl = dynop + key->dk_op.dy_type;
12442 + au_hbl_del(&key->dk_hnode, hbl);
12443 + call_rcu(&key->dk_rcu, dy_free_rcu);
12446 +void au_dy_put(struct au_dykey *key)
12448 + kref_put(&key->dk_kref, dy_free);
12451 +/* ---------------------------------------------------------------------- */
12453 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12455 +#ifdef CONFIG_AUFS_DEBUG
12456 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12457 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12459 +#define DyDbgDeclare(cnt) do {} while (0)
12460 +#define DyDbgInc(cnt) do {} while (0)
12463 +#define DySet(func, dst, src, h_op, h_sb) do { \
12465 + if (h_op->func) { \
12467 + dst.func = src.func; \
12469 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12473 +#define DySetForce(func, dst, src) do { \
12474 + AuDebugOn(!src.func); \
12476 + dst.func = src.func; \
12479 +#define DySetAop(func) \
12480 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12481 +#define DySetAopForce(func) \
12482 + DySetForce(func, dyaop->da_op, aufs_aop)
12484 +static void dy_aop(struct au_dykey *key, const void *h_op,
12485 + struct super_block *h_sb __maybe_unused)
12487 + struct au_dyaop *dyaop = (void *)key;
12488 + const struct address_space_operations *h_aop = h_op;
12489 + DyDbgDeclare(cnt);
12491 + AuDbg("%s\n", au_sbtype(h_sb));
12493 + DySetAop(writepage);
12494 + DySetAopForce(readpage); /* force */
12495 + DySetAop(writepages);
12496 + DySetAop(set_page_dirty);
12497 + DySetAop(readpages);
12498 + DySetAop(readahead);
12499 + DySetAop(write_begin);
12500 + DySetAop(write_end);
12502 + DySetAop(invalidatepage);
12503 + DySetAop(releasepage);
12504 + DySetAop(freepage);
12505 + /* this one will be changed according to an aufs mount option */
12506 + DySetAop(direct_IO);
12507 + DySetAop(migratepage);
12508 + DySetAop(isolate_page);
12509 + DySetAop(putback_page);
12510 + DySetAop(launder_page);
12511 + DySetAop(is_partially_uptodate);
12512 + DySetAop(is_dirty_writeback);
12513 + DySetAop(error_remove_page);
12514 + DySetAop(swap_activate);
12515 + DySetAop(swap_deactivate);
12517 + DyDbgSize(cnt, *h_aop);
12520 +/* ---------------------------------------------------------------------- */
12522 +static void dy_bug(struct kref *kref)
12527 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12529 + struct au_dykey *key, *old;
12530 + struct hlist_bl_head *hbl;
12533 + void (*set)(struct au_dykey *key, const void *h_op,
12534 + struct super_block *h_sb __maybe_unused);
12536 + static const struct op a[] = {
12538 + .sz = sizeof(struct au_dyaop),
12542 + const struct op *p;
12544 + hbl = dynop + op->dy_type;
12545 + key = dy_gfind_get(hbl, op->dy_hop);
12547 + goto out_add; /* success */
12549 + p = a + op->dy_type;
12550 + key = kzalloc(p->sz, GFP_NOFS);
12551 + if (unlikely(!key)) {
12552 + key = ERR_PTR(-ENOMEM);
12556 + key->dk_op.dy_hop = op->dy_hop;
12557 + kref_init(&key->dk_kref);
12558 + p->set(key, op->dy_hop, au_br_sb(br));
12559 + old = dy_gadd(hbl, key);
12561 + au_kfree_rcu(key);
12566 + old = dy_bradd(br, key);
12568 + /* its ref-count should never be zero here */
12569 + kref_put(&key->dk_kref, dy_bug);
12574 +/* ---------------------------------------------------------------------- */
12576 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12577 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12578 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12579 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12580 + * See the aufs manual in detail.
12582 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12585 + dyaop->da_op.direct_IO = NULL;
12587 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12590 +static struct au_dyaop *dy_aget(struct au_branch *br,
12591 + const struct address_space_operations *h_aop,
12594 + struct au_dyaop *dyaop;
12595 + struct au_dynop op;
12597 + op.dy_type = AuDy_AOP;
12598 + op.dy_haop = h_aop;
12599 + dyaop = (void *)dy_get(&op, br);
12600 + if (IS_ERR(dyaop))
12602 + dy_adx(dyaop, do_dx);
12608 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12609 + struct inode *h_inode)
12612 + struct super_block *sb;
12613 + struct au_branch *br;
12614 + struct au_dyaop *dyaop;
12616 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12617 + IiMustWriteLock(inode);
12619 + sb = inode->i_sb;
12620 + br = au_sbr(sb, bindex);
12621 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12622 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12623 + err = PTR_ERR(dyaop);
12624 + if (IS_ERR(dyaop))
12625 + /* unnecessary to call dy_fput() */
12629 + inode->i_mapping->a_ops = &dyaop->da_op;
12636 + * Is it safe to replace a_ops during the inode/file is in operation?
12637 + * Yes, I hope so.
12639 +int au_dy_irefresh(struct inode *inode)
12642 + aufs_bindex_t btop;
12643 + struct inode *h_inode;
12646 + if (S_ISREG(inode->i_mode)) {
12647 + btop = au_ibtop(inode);
12648 + h_inode = au_h_iptr(inode, btop);
12649 + err = au_dy_iaop(inode, btop, h_inode);
12654 +void au_dy_arefresh(int do_dx)
12656 + struct hlist_bl_head *hbl;
12657 + struct hlist_bl_node *pos;
12658 + struct au_dykey *key;
12660 + hbl = dynop + AuDy_AOP;
12661 + hlist_bl_lock(hbl);
12662 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12663 + dy_adx((void *)key, do_dx);
12664 + hlist_bl_unlock(hbl);
12667 +/* ---------------------------------------------------------------------- */
12669 +void __init au_dy_init(void)
12673 + for (i = 0; i < AuDyLast; i++)
12674 + INIT_HLIST_BL_HEAD(dynop + i);
12677 +void au_dy_fin(void)
12681 + for (i = 0; i < AuDyLast; i++)
12682 + WARN_ON(!hlist_bl_empty(dynop + i));
12684 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12685 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12686 +++ linux/fs/aufs/dynop.h 2021-12-03 15:38:59.933313976 +0100
12688 +/* SPDX-License-Identifier: GPL-2.0 */
12690 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12692 + * This program, aufs is free software; you can redistribute it and/or modify
12693 + * it under the terms of the GNU General Public License as published by
12694 + * the Free Software Foundation; either version 2 of the License, or
12695 + * (at your option) any later version.
12697 + * This program is distributed in the hope that it will be useful,
12698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12700 + * GNU General Public License for more details.
12702 + * You should have received a copy of the GNU General Public License
12703 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12707 + * dynamically customizable operations (for regular files only)
12710 +#ifndef __AUFS_DYNOP_H__
12711 +#define __AUFS_DYNOP_H__
12715 +#include <linux/fs.h>
12716 +#include <linux/kref.h>
12718 +enum {AuDy_AOP, AuDyLast};
12723 + const void *dy_hop;
12724 + const struct address_space_operations *dy_haop;
12730 + struct hlist_bl_node dk_hnode;
12731 + struct rcu_head dk_rcu;
12733 + struct au_dynop dk_op;
12736 + * during I am in the branch local array, kref is gotten. when the
12737 + * branch is removed, kref is put.
12739 + struct kref dk_kref;
12742 +/* stop unioning since their sizes are very different from each other */
12744 + struct au_dykey da_key;
12745 + struct address_space_operations da_op; /* not const */
12747 +/* make sure that 'struct au_dykey *' can be any type */
12748 +static_assert(!offsetof(struct au_dyaop, da_key));
12750 +/* ---------------------------------------------------------------------- */
12754 +void au_dy_put(struct au_dykey *key);
12755 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12756 + struct inode *h_inode);
12757 +int au_dy_irefresh(struct inode *inode);
12758 +void au_dy_arefresh(int do_dio);
12760 +void __init au_dy_init(void);
12761 +void au_dy_fin(void);
12763 +#endif /* __KERNEL__ */
12764 +#endif /* __AUFS_DYNOP_H__ */
12765 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12766 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12767 +++ linux/fs/aufs/export.c 2021-12-03 15:40:58.233313963 +0100
12769 +// SPDX-License-Identifier: GPL-2.0
12771 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12773 + * This program, aufs is free software; you can redistribute it and/or modify
12774 + * it under the terms of the GNU General Public License as published by
12775 + * the Free Software Foundation; either version 2 of the License, or
12776 + * (at your option) any later version.
12778 + * This program is distributed in the hope that it will be useful,
12779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12781 + * GNU General Public License for more details.
12783 + * You should have received a copy of the GNU General Public License
12784 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12791 +#include <linux/exportfs.h>
12792 +#include <linux/fs_struct.h>
12793 +#include <linux/namei.h>
12794 +#include <linux/nsproxy.h>
12795 +#include <linux/random.h>
12796 +#include <linux/writeback.h>
12800 +#ifdef CONFIG_AUFS_INO_T_64
12808 +static ino_t decode_ino(__u32 *a)
12812 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12814 +#ifdef CONFIG_AUFS_INO_T_64
12820 +static void encode_ino(__u32 *a, ino_t ino)
12826 +#ifdef CONFIG_AUFS_INO_T_64
12831 +/* NFS file handle */
12835 +#ifdef CONFIG_AUFS_INO_T_64
12836 + /* support 64bit inode number */
12849 + Fh_ino = Fh_ino1,
12850 + Fh_dir_ino = Fh_dir_ino1
12853 +static int au_test_anon(struct dentry *dentry)
12855 + /* note: read d_flags without d_lock */
12856 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12859 +int au_test_nfsd(void)
12862 + struct task_struct *tsk = current;
12863 + char comm[sizeof(tsk->comm)];
12866 + if (tsk->flags & PF_KTHREAD) {
12867 + get_task_comm(comm, tsk);
12868 + ret = !strcmp(comm, "nfsd");
12874 +/* ---------------------------------------------------------------------- */
12875 +/* inode generation external table */
12877 +void au_xigen_inc(struct inode *inode)
12882 + struct super_block *sb;
12883 + struct au_sbinfo *sbinfo;
12885 + sb = inode->i_sb;
12886 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12888 + sbinfo = au_sbi(sb);
12889 + pos = inode->i_ino;
12890 + pos *= sizeof(igen);
12891 + igen = inode->i_generation + 1;
12892 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12893 + if (sz == sizeof(igen))
12894 + return; /* success */
12896 + if (unlikely(sz >= 0))
12897 + AuIOErr("xigen error (%zd)\n", sz);
12900 +int au_xigen_new(struct inode *inode)
12905 + struct super_block *sb;
12906 + struct au_sbinfo *sbinfo;
12907 + struct file *file;
12910 + /* todo: dirty, at mount time */
12911 + if (inode->i_ino == AUFS_ROOT_INO)
12913 + sb = inode->i_sb;
12914 + SiMustAnyLock(sb);
12915 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12919 + pos = inode->i_ino;
12920 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12921 + AuIOErr1("too large i%lld\n", pos);
12924 + pos *= sizeof(inode->i_generation);
12927 + sbinfo = au_sbi(sb);
12928 + file = sbinfo->si_xigen;
12931 + if (vfsub_f_size_read(file)
12932 + < pos + sizeof(inode->i_generation)) {
12933 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12934 + sz = xino_fwrite(file, &inode->i_generation,
12935 + sizeof(inode->i_generation), &pos);
12937 + sz = xino_fread(file, &inode->i_generation,
12938 + sizeof(inode->i_generation), &pos);
12939 + if (sz == sizeof(inode->i_generation))
12940 + goto out; /* success */
12943 + if (unlikely(sz >= 0)) {
12945 + AuIOErr("xigen error (%zd)\n", sz);
12952 +int au_xigen_set(struct super_block *sb, struct path *path)
12955 + struct au_sbinfo *sbinfo;
12956 + struct file *file;
12958 + SiMustWriteLock(sb);
12960 + sbinfo = au_sbi(sb);
12961 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12962 + err = PTR_ERR(file);
12963 + if (IS_ERR(file))
12966 + if (sbinfo->si_xigen)
12967 + fput(sbinfo->si_xigen);
12968 + sbinfo->si_xigen = file;
12975 +void au_xigen_clr(struct super_block *sb)
12977 + struct au_sbinfo *sbinfo;
12979 + SiMustWriteLock(sb);
12981 + sbinfo = au_sbi(sb);
12982 + if (sbinfo->si_xigen) {
12983 + fput(sbinfo->si_xigen);
12984 + sbinfo->si_xigen = NULL;
12988 +/* ---------------------------------------------------------------------- */
12990 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
12993 + struct dentry *dentry, *d;
12994 + struct inode *inode;
12995 + unsigned int sigen;
12998 + inode = ilookup(sb, ino);
13002 + dentry = ERR_PTR(-ESTALE);
13003 + sigen = au_sigen(sb);
13004 + if (unlikely(au_is_bad_inode(inode)
13005 + || IS_DEADDIR(inode)
13006 + || sigen != au_iigen(inode, NULL)))
13010 + if (!dir_ino || S_ISDIR(inode->i_mode))
13011 + dentry = d_find_alias(inode);
13013 + spin_lock(&inode->i_lock);
13014 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13015 + spin_lock(&d->d_lock);
13016 + if (!au_test_anon(d)
13017 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13018 + dentry = dget_dlock(d);
13019 + spin_unlock(&d->d_lock);
13022 + spin_unlock(&d->d_lock);
13024 + spin_unlock(&inode->i_lock);
13026 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13027 + /* need to refresh */
13035 + AuTraceErrPtr(dentry);
13039 +/* ---------------------------------------------------------------------- */
13041 +/* todo: dirty? */
13042 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13044 +struct au_compare_mnt_args {
13046 + struct super_block *sb;
13049 + struct vfsmount *mnt;
13052 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13054 + struct au_compare_mnt_args *a = arg;
13056 + if (mnt->mnt_sb != a->sb)
13058 + a->mnt = mntget(mnt);
13062 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13065 + struct path root;
13066 + struct au_compare_mnt_args args = {
13070 + get_fs_root(current->fs, &root);
13072 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13073 + rcu_read_unlock();
13076 + AuDebugOn(!args.mnt);
13080 +struct au_nfsd_si_lock {
13081 + unsigned int sigen;
13082 + aufs_bindex_t bindex, br_id;
13083 + unsigned char force_lock;
13086 +static int si_nfsd_read_lock(struct super_block *sb,
13087 + struct au_nfsd_si_lock *nsi_lock)
13090 + aufs_bindex_t bindex;
13092 + si_read_lock(sb, AuLock_FLUSH);
13094 + /* branch id may be wrapped around */
13096 + bindex = au_br_index(sb, nsi_lock->br_id);
13097 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13098 + goto out; /* success */
13102 + if (!nsi_lock->force_lock)
13103 + si_read_unlock(sb);
13106 + nsi_lock->bindex = bindex;
13110 +struct find_name_by_ino {
13111 + struct dir_context ctx;
13112 + int called, found;
13119 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13120 + loff_t offset, u64 ino, unsigned int d_type)
13122 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13126 + if (a->ino != ino)
13129 + memcpy(a->name, name, namelen);
13130 + a->namelen = namelen;
13135 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13136 + struct au_nfsd_si_lock *nsi_lock)
13138 + struct dentry *dentry, *parent;
13139 + struct file *file;
13140 + struct inode *dir;
13141 + struct find_name_by_ino arg = {
13143 + .actor = find_name_by_ino
13148 + parent = path->dentry;
13150 + si_read_unlock(parent->d_sb);
13151 + file = vfsub_dentry_open(path, au_dir_roflags);
13152 + dentry = (void *)file;
13153 + if (IS_ERR(file))
13156 + dentry = ERR_PTR(-ENOMEM);
13157 + arg.name = (void *)__get_free_page(GFP_NOFS);
13158 + if (unlikely(!arg.name))
13165 + err = vfsub_iterate_dir(file, &arg.ctx);
13166 + } while (!err && !arg.found && arg.called);
13167 + dentry = ERR_PTR(err);
13168 + if (unlikely(err))
13170 + /* instead of ENOENT */
13171 + dentry = ERR_PTR(-ESTALE);
13175 + /* do not call vfsub_lkup_one() */
13176 + dir = d_inode(parent);
13177 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13178 + AuTraceErrPtr(dentry);
13179 + if (IS_ERR(dentry))
13181 + AuDebugOn(au_test_anon(dentry));
13182 + if (unlikely(d_really_is_negative(dentry))) {
13184 + dentry = ERR_PTR(-ENOENT);
13188 + free_page((unsigned long)arg.name);
13192 + if (unlikely(nsi_lock
13193 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13194 + if (!IS_ERR(dentry)) {
13196 + dentry = ERR_PTR(-ESTALE);
13198 + AuTraceErrPtr(dentry);
13202 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13204 + struct au_nfsd_si_lock *nsi_lock)
13206 + struct dentry *dentry;
13207 + struct path path;
13209 + if (dir_ino != AUFS_ROOT_INO) {
13210 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13211 + dentry = path.dentry;
13212 + if (!path.dentry || IS_ERR(path.dentry))
13214 + AuDebugOn(au_test_anon(path.dentry));
13216 + path.dentry = dget(sb->s_root);
13218 + path.mnt = au_mnt_get(sb);
13219 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13223 + AuTraceErrPtr(dentry);
13227 +/* ---------------------------------------------------------------------- */
13229 +static int h_acceptable(void *expv, struct dentry *dentry)
13234 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13235 + char *buf, int len, struct super_block *sb)
13239 + struct path path;
13241 + p = d_path(h_rootpath, buf, len);
13246 + path.mnt = h_rootpath->mnt;
13247 + path.dentry = h_parent;
13248 + p = d_path(&path, buf, len);
13254 + path.mnt = au_mnt_get(sb);
13255 + path.dentry = sb->s_root;
13256 + p = d_path(&path, buf, len - strlen(p));
13257 + mntput(path.mnt);
13261 + p[strlen(p)] = '/';
13264 + AuTraceErrPtr(p);
13269 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13270 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13272 + struct dentry *dentry, *h_parent, *root;
13273 + struct super_block *h_sb;
13274 + char *pathname, *p;
13275 + struct vfsmount *h_mnt;
13276 + struct au_branch *br;
13278 + struct path path;
13280 + br = au_sbr(sb, nsi_lock->bindex);
13281 + h_mnt = au_br_mnt(br);
13282 + h_sb = h_mnt->mnt_sb;
13283 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13285 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13286 + fh_len - Fh_tail, fh[Fh_h_type],
13287 + h_acceptable, /*context*/NULL);
13289 + dentry = h_parent;
13290 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13291 + AuWarn1("%s decode_fh failed, %ld\n",
13292 + au_sbtype(h_sb), PTR_ERR(h_parent));
13296 + if (unlikely(au_test_anon(h_parent))) {
13297 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13298 + au_sbtype(h_sb));
13299 + goto out_h_parent;
13302 + dentry = ERR_PTR(-ENOMEM);
13303 + pathname = (void *)__get_free_page(GFP_NOFS);
13304 + if (unlikely(!pathname))
13305 + goto out_h_parent;
13307 + root = sb->s_root;
13308 + path.mnt = h_mnt;
13309 + di_read_lock_parent(root, !AuLock_IR);
13310 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13311 + di_read_unlock(root, !AuLock_IR);
13312 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13313 + dentry = (void *)p;
13315 + goto out_pathname;
13317 + si_read_unlock(sb);
13318 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13319 + dentry = ERR_PTR(err);
13320 + if (unlikely(err))
13323 + dentry = ERR_PTR(-ENOENT);
13324 + AuDebugOn(au_test_anon(path.dentry));
13325 + if (unlikely(d_really_is_negative(path.dentry)))
13328 + if (ino != d_inode(path.dentry)->i_ino)
13329 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13331 + dentry = dget(path.dentry);
13336 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13337 + if (!IS_ERR(dentry)) {
13339 + dentry = ERR_PTR(-ESTALE);
13342 + free_page((unsigned long)pathname);
13346 + AuTraceErrPtr(dentry);
13350 +/* ---------------------------------------------------------------------- */
13352 +static struct dentry *
13353 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13356 + struct dentry *dentry;
13357 + __u32 *fh = fid->raw;
13358 + struct au_branch *br;
13359 + ino_t ino, dir_ino;
13360 + struct au_nfsd_si_lock nsi_lock = {
13364 + dentry = ERR_PTR(-ESTALE);
13365 + /* it should never happen, but the file handle is unreliable */
13366 + if (unlikely(fh_len < Fh_tail))
13368 + nsi_lock.sigen = fh[Fh_sigen];
13369 + nsi_lock.br_id = fh[Fh_br_id];
13371 + /* branch id may be wrapped around */
13373 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13375 + nsi_lock.force_lock = 1;
13377 + /* is this inode still cached? */
13378 + ino = decode_ino(fh + Fh_ino);
13379 + /* it should never happen */
13380 + if (unlikely(ino == AUFS_ROOT_INO))
13383 + dir_ino = decode_ino(fh + Fh_dir_ino);
13384 + dentry = decode_by_ino(sb, ino, dir_ino);
13385 + if (IS_ERR(dentry))
13390 + /* is the parent dir cached? */
13391 + br = au_sbr(sb, nsi_lock.bindex);
13392 + au_lcnt_inc(&br->br_nfiles);
13393 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13394 + if (IS_ERR(dentry))
13399 + /* lookup path */
13400 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13401 + if (IS_ERR(dentry))
13403 + if (unlikely(!dentry))
13404 + /* todo?: make it ESTALE */
13408 + if (!au_digen_test(dentry, au_sigen(sb))
13409 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13410 + goto out_unlock; /* success */
13413 + dentry = ERR_PTR(-ESTALE);
13416 + au_lcnt_dec(&br->br_nfiles);
13417 + si_read_unlock(sb);
13419 + AuTraceErrPtr(dentry);
13423 +#if 0 /* reserved for future use */
13424 +/* support subtreecheck option */
13425 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13426 + int fh_len, int fh_type)
13428 + struct dentry *parent;
13429 + __u32 *fh = fid->raw;
13432 + dir_ino = decode_ino(fh + Fh_dir_ino);
13433 + parent = decode_by_ino(sb, dir_ino, 0);
13434 + if (IS_ERR(parent))
13437 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13438 + dir_ino, fh, fh_len);
13441 + AuTraceErrPtr(parent);
13446 +/* ---------------------------------------------------------------------- */
13448 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13449 + struct inode *dir)
13452 + aufs_bindex_t bindex;
13453 + struct super_block *sb, *h_sb;
13454 + struct dentry *dentry, *parent, *h_parent;
13455 + struct inode *h_dir;
13456 + struct au_branch *br;
13459 + if (unlikely(*max_len <= Fh_tail)) {
13460 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13464 + err = FILEID_ROOT;
13465 + if (inode->i_ino == AUFS_ROOT_INO) {
13466 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13471 + sb = inode->i_sb;
13472 + err = si_read_lock(sb, AuLock_FLUSH);
13473 + if (unlikely(err))
13476 +#ifdef CONFIG_AUFS_DEBUG
13477 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13478 + AuWarn1("NFS-exporting requires xino\n");
13482 + ii_read_lock_child(inode);
13483 + bindex = au_ibtop(inode);
13485 + dentry = d_find_any_alias(inode);
13486 + if (unlikely(!dentry))
13488 + AuDebugOn(au_test_anon(dentry));
13489 + parent = dget_parent(dentry);
13491 + if (unlikely(!parent))
13493 + if (d_really_is_positive(parent))
13494 + dir = d_inode(parent);
13497 + ii_read_lock_parent(dir);
13498 + h_dir = au_h_iptr(dir, bindex);
13499 + ii_read_unlock(dir);
13500 + if (unlikely(!h_dir))
13502 + h_parent = d_find_any_alias(h_dir);
13503 + if (unlikely(!h_parent))
13504 + goto out_hparent;
13507 + br = au_sbr(sb, bindex);
13508 + h_sb = au_br_sb(br);
13509 + if (unlikely(!h_sb->s_export_op)) {
13510 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13511 + goto out_hparent;
13514 + fh[Fh_br_id] = br->br_id;
13515 + fh[Fh_sigen] = au_sigen(sb);
13516 + encode_ino(fh + Fh_ino, inode->i_ino);
13517 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13518 + fh[Fh_igen] = inode->i_generation;
13520 + *max_len -= Fh_tail;
13521 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13523 + /*connectable or subtreecheck*/0);
13524 + err = fh[Fh_h_type];
13525 + *max_len += Fh_tail;
13526 + /* todo: macros? */
13527 + if (err != FILEID_INVALID)
13530 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13537 + ii_read_unlock(inode);
13538 + si_read_unlock(sb);
13540 + if (unlikely(err < 0))
13541 + err = FILEID_INVALID;
13545 +/* ---------------------------------------------------------------------- */
13547 +static int aufs_commit_metadata(struct inode *inode)
13550 + aufs_bindex_t bindex;
13551 + struct super_block *sb;
13552 + struct inode *h_inode;
13553 + int (*f)(struct inode *inode);
13555 + sb = inode->i_sb;
13556 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13557 + ii_write_lock_child(inode);
13558 + bindex = au_ibtop(inode);
13559 + AuDebugOn(bindex < 0);
13560 + h_inode = au_h_iptr(inode, bindex);
13562 + f = h_inode->i_sb->s_export_op->commit_metadata;
13564 + err = f(h_inode);
13566 + err = sync_inode_metadata(h_inode, /*wait*/1);
13568 + au_cpup_attr_timesizes(inode);
13569 + ii_write_unlock(inode);
13570 + si_read_unlock(sb);
13574 +/* ---------------------------------------------------------------------- */
13576 +static struct export_operations aufs_export_op = {
13577 + .fh_to_dentry = aufs_fh_to_dentry,
13578 + /* .fh_to_parent = aufs_fh_to_parent, */
13579 + .encode_fh = aufs_encode_fh,
13580 + .commit_metadata = aufs_commit_metadata
13583 +void au_export_init(struct super_block *sb)
13585 + struct au_sbinfo *sbinfo;
13588 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13589 + && IS_MODULE(CONFIG_EXPORTFS),
13590 + AUFS_NAME ": unsupported configuration "
13591 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13593 + sb->s_export_op = &aufs_export_op;
13594 + sbinfo = au_sbi(sb);
13595 + sbinfo->si_xigen = NULL;
13596 + get_random_bytes(&u, sizeof(u));
13597 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13598 + atomic_set(&sbinfo->si_xigen_next, u);
13600 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13601 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13602 +++ linux/fs/aufs/fhsm.c 2021-12-03 15:38:59.933313976 +0100
13604 +// SPDX-License-Identifier: GPL-2.0
13606 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13608 + * This program, aufs is free software; you can redistribute it and/or modify
13609 + * it under the terms of the GNU General Public License as published by
13610 + * the Free Software Foundation; either version 2 of the License, or
13611 + * (at your option) any later version.
13613 + * This program is distributed in the hope that it will be useful,
13614 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13615 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13616 + * GNU General Public License for more details.
13618 + * You should have received a copy of the GNU General Public License
13619 + * along with this program; if not, write to the Free Software
13620 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13624 + * File-based Hierarchy Storage Management
13627 +#include <linux/anon_inodes.h>
13628 +#include <linux/poll.h>
13629 +#include <linux/seq_file.h>
13630 +#include <linux/statfs.h>
13633 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13635 + struct au_sbinfo *sbinfo;
13636 + struct au_fhsm *fhsm;
13638 + SiMustAnyLock(sb);
13640 + sbinfo = au_sbi(sb);
13641 + fhsm = &sbinfo->si_fhsm;
13642 + AuDebugOn(!fhsm);
13643 + return fhsm->fhsm_bottom;
13646 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13648 + struct au_sbinfo *sbinfo;
13649 + struct au_fhsm *fhsm;
13651 + SiMustWriteLock(sb);
13653 + sbinfo = au_sbi(sb);
13654 + fhsm = &sbinfo->si_fhsm;
13655 + AuDebugOn(!fhsm);
13656 + fhsm->fhsm_bottom = bindex;
13659 +/* ---------------------------------------------------------------------- */
13661 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13663 + struct au_br_fhsm *bf;
13665 + bf = br->br_fhsm;
13666 + MtxMustLock(&bf->bf_lock);
13668 + return !bf->bf_readable
13669 + || time_after(jiffies,
13670 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13673 +/* ---------------------------------------------------------------------- */
13675 +static void au_fhsm_notify(struct super_block *sb, int val)
13677 + struct au_sbinfo *sbinfo;
13678 + struct au_fhsm *fhsm;
13680 + SiMustAnyLock(sb);
13682 + sbinfo = au_sbi(sb);
13683 + fhsm = &sbinfo->si_fhsm;
13684 + if (au_fhsm_pid(fhsm)
13685 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13686 + atomic_set(&fhsm->fhsm_readable, val);
13688 + wake_up(&fhsm->fhsm_wqh);
13692 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13693 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13696 + struct au_branch *br;
13697 + struct au_br_fhsm *bf;
13699 + br = au_sbr(sb, bindex);
13700 + AuDebugOn(au_br_rdonly(br));
13701 + bf = br->br_fhsm;
13705 + mutex_lock(&bf->bf_lock);
13707 + MtxMustLock(&bf->bf_lock);
13709 + /* sb->s_root for NFS is unreliable */
13710 + err = au_br_stfs(br, &bf->bf_stfs);
13711 + if (unlikely(err)) {
13712 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13716 + bf->bf_jiffy = jiffies;
13717 + bf->bf_readable = 1;
13719 + au_fhsm_notify(sb, /*val*/1);
13721 + *rstfs = bf->bf_stfs;
13725 + mutex_unlock(&bf->bf_lock);
13726 + au_fhsm_notify(sb, /*val*/1);
13731 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13734 + struct au_sbinfo *sbinfo;
13735 + struct au_fhsm *fhsm;
13736 + struct au_branch *br;
13737 + struct au_br_fhsm *bf;
13739 + AuDbg("b%d, force %d\n", bindex, force);
13740 + SiMustAnyLock(sb);
13742 + sbinfo = au_sbi(sb);
13743 + fhsm = &sbinfo->si_fhsm;
13744 + if (!au_ftest_si(sbinfo, FHSM)
13745 + || fhsm->fhsm_bottom == bindex)
13748 + br = au_sbr(sb, bindex);
13749 + bf = br->br_fhsm;
13751 + mutex_lock(&bf->bf_lock);
13753 + || au_fhsm_pid(fhsm)
13754 + || au_fhsm_test_jiffy(sbinfo, br))
13755 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13757 + mutex_unlock(&bf->bf_lock);
13760 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13762 + aufs_bindex_t bindex, bbot;
13763 + struct au_branch *br;
13765 + /* exclude the bottom */
13766 + bbot = au_fhsm_bottom(sb);
13767 + for (bindex = 0; bindex < bbot; bindex++) {
13768 + br = au_sbr(sb, bindex);
13769 + if (au_br_fhsm(br->br_perm))
13770 + au_fhsm_wrote(sb, bindex, force);
13774 +/* ---------------------------------------------------------------------- */
13776 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13779 + struct au_sbinfo *sbinfo;
13780 + struct au_fhsm *fhsm;
13783 + sbinfo = file->private_data;
13784 + fhsm = &sbinfo->si_fhsm;
13785 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13786 + if (atomic_read(&fhsm->fhsm_readable))
13787 + mask = EPOLLIN /* | EPOLLRDNORM */;
13790 + AuDbg("mask 0x%x\n", mask);
13794 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13795 + struct aufs_stfs *stfs, __s16 brid)
13799 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13801 + err = __put_user(brid, &stbr->brid);
13802 + if (unlikely(err))
13808 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13809 + struct aufs_stbr __user *stbr, size_t count)
13813 + aufs_bindex_t bindex, bbot;
13814 + struct au_branch *br;
13815 + struct au_br_fhsm *bf;
13817 + /* except the bottom branch */
13820 + bbot = au_fhsm_bottom(sb);
13821 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13822 + br = au_sbr(sb, bindex);
13823 + if (!au_br_fhsm(br->br_perm))
13826 + bf = br->br_fhsm;
13827 + mutex_lock(&bf->bf_lock);
13828 + if (bf->bf_readable) {
13830 + if (count >= sizeof(*stbr))
13831 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13834 + bf->bf_readable = 0;
13835 + count -= sizeof(*stbr);
13839 + mutex_unlock(&bf->bf_lock);
13842 + err = sizeof(*stbr) * nstbr;
13847 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13852 + aufs_bindex_t nfhsm, bindex, bbot;
13853 + struct au_sbinfo *sbinfo;
13854 + struct au_fhsm *fhsm;
13855 + struct au_branch *br;
13856 + struct super_block *sb;
13859 + sbinfo = file->private_data;
13860 + fhsm = &sbinfo->si_fhsm;
13862 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13863 + if (!atomic_read(&fhsm->fhsm_readable)) {
13864 + if (vfsub_file_flags(file) & O_NONBLOCK)
13867 + err = wait_event_interruptible_locked_irq
13869 + atomic_read(&fhsm->fhsm_readable));
13871 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13872 + if (unlikely(err))
13875 + /* sb may already be dead */
13876 + au_rw_read_lock(&sbinfo->si_rwsem);
13877 + readable = atomic_read(&fhsm->fhsm_readable);
13878 + if (readable > 0) {
13879 + sb = sbinfo->si_sb;
13881 + /* exclude the bottom branch */
13883 + bbot = au_fhsm_bottom(sb);
13884 + for (bindex = 0; bindex < bbot; bindex++) {
13885 + br = au_sbr(sb, bindex);
13886 + if (au_br_fhsm(br->br_perm))
13890 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13891 + atomic_set(&fhsm->fhsm_readable, 0);
13892 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13896 + au_rw_read_unlock(&sbinfo->si_rwsem);
13904 +static int au_fhsm_release(struct inode *inode, struct file *file)
13906 + struct au_sbinfo *sbinfo;
13907 + struct au_fhsm *fhsm;
13909 + /* sb may already be dead */
13910 + sbinfo = file->private_data;
13911 + fhsm = &sbinfo->si_fhsm;
13912 + spin_lock(&fhsm->fhsm_spin);
13913 + fhsm->fhsm_pid = 0;
13914 + spin_unlock(&fhsm->fhsm_spin);
13915 + kobject_put(&sbinfo->si_kobj);
13920 +static const struct file_operations au_fhsm_fops = {
13921 + .owner = THIS_MODULE,
13922 + .llseek = noop_llseek,
13923 + .read = au_fhsm_read,
13924 + .poll = au_fhsm_poll,
13925 + .release = au_fhsm_release
13928 +int au_fhsm_fd(struct super_block *sb, int oflags)
13931 + struct au_sbinfo *sbinfo;
13932 + struct au_fhsm *fhsm;
13935 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13939 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13943 + sbinfo = au_sbi(sb);
13944 + fhsm = &sbinfo->si_fhsm;
13945 + spin_lock(&fhsm->fhsm_spin);
13946 + if (!fhsm->fhsm_pid)
13947 + fhsm->fhsm_pid = current->pid;
13950 + spin_unlock(&fhsm->fhsm_spin);
13951 + if (unlikely(err))
13954 + oflags |= O_RDONLY;
13955 + /* oflags |= FMODE_NONOTIFY; */
13956 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13958 + if (unlikely(fd < 0))
13961 + /* succeed regardless 'fhsm' status */
13962 + kobject_get(&sbinfo->si_kobj);
13963 + si_noflush_read_lock(sb);
13964 + if (au_ftest_si(sbinfo, FHSM))
13965 + au_fhsm_wrote_all(sb, /*force*/0);
13966 + si_read_unlock(sb);
13967 + goto out; /* success */
13970 + spin_lock(&fhsm->fhsm_spin);
13971 + fhsm->fhsm_pid = 0;
13972 + spin_unlock(&fhsm->fhsm_spin);
13978 +/* ---------------------------------------------------------------------- */
13980 +int au_fhsm_br_alloc(struct au_branch *br)
13985 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13987 + au_br_fhsm_init(br->br_fhsm);
13994 +/* ---------------------------------------------------------------------- */
13996 +void au_fhsm_fin(struct super_block *sb)
13998 + au_fhsm_notify(sb, /*val*/-1);
14001 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14003 + struct au_fhsm *fhsm;
14005 + fhsm = &sbinfo->si_fhsm;
14006 + spin_lock_init(&fhsm->fhsm_spin);
14007 + init_waitqueue_head(&fhsm->fhsm_wqh);
14008 + atomic_set(&fhsm->fhsm_readable, 0);
14009 + fhsm->fhsm_expire
14010 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14011 + fhsm->fhsm_bottom = -1;
14014 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14016 + sbinfo->si_fhsm.fhsm_expire
14017 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14020 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14024 + if (!au_ftest_si(sbinfo, FHSM))
14027 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14028 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14029 + seq_printf(seq, ",fhsm_sec=%u", u);
14031 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14032 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14033 +++ linux/fs/aufs/file.c 2021-12-03 15:38:59.936647310 +0100
14035 +// SPDX-License-Identifier: GPL-2.0
14037 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14039 + * This program, aufs is free software; you can redistribute it and/or modify
14040 + * it under the terms of the GNU General Public License as published by
14041 + * the Free Software Foundation; either version 2 of the License, or
14042 + * (at your option) any later version.
14044 + * This program is distributed in the hope that it will be useful,
14045 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14046 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14047 + * GNU General Public License for more details.
14049 + * You should have received a copy of the GNU General Public License
14050 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14054 + * handling file/dir, and address_space operation
14057 +#ifdef CONFIG_AUFS_DEBUG
14058 +#include <linux/migrate.h>
14060 +#include <linux/pagemap.h>
14063 +/* drop flags for writing */
14064 +unsigned int au_file_roflags(unsigned int flags)
14066 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14067 + flags |= O_RDONLY | O_NOATIME;
14071 +/* common functions to regular file and dir */
14072 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14073 + struct file *file, int force_wr)
14075 + struct file *h_file;
14076 + struct dentry *h_dentry;
14077 + struct inode *h_inode;
14078 + struct super_block *sb;
14079 + struct au_branch *br;
14080 + struct path h_path;
14083 + /* a race condition can happen between open and unlink/rmdir */
14084 + h_file = ERR_PTR(-ENOENT);
14085 + h_dentry = au_h_dptr(dentry, bindex);
14086 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14088 + h_inode = d_inode(h_dentry);
14089 + spin_lock(&h_dentry->d_lock);
14090 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14091 + /* || !d_inode(dentry)->i_nlink */
14093 + spin_unlock(&h_dentry->d_lock);
14094 + if (unlikely(err))
14097 + sb = dentry->d_sb;
14098 + br = au_sbr(sb, bindex);
14099 + err = au_br_test_oflag(flags, br);
14100 + h_file = ERR_PTR(err);
14101 + if (unlikely(err))
14104 + /* drop flags for writing */
14105 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14106 + if (force_wr && !(flags & O_WRONLY))
14108 + flags = au_file_roflags(flags);
14110 + h_file = ERR_PTR(-EROFS);
14111 + flags = au_file_roflags(flags);
14112 + if (unlikely(vfsub_native_ro(h_inode)
14113 + || IS_APPEND(h_inode)))
14115 + flags &= ~O_ACCMODE;
14116 + flags |= O_WRONLY;
14119 + flags &= ~O_CREAT;
14120 + au_lcnt_inc(&br->br_nfiles);
14121 + h_path.dentry = h_dentry;
14122 + h_path.mnt = au_br_mnt(br);
14123 + h_file = vfsub_dentry_open(&h_path, flags);
14124 + if (IS_ERR(h_file))
14127 + if (flags & __FMODE_EXEC) {
14128 + err = deny_write_access(h_file);
14129 + if (unlikely(err)) {
14131 + h_file = ERR_PTR(err);
14135 + fsnotify_open(h_file);
14136 + goto out; /* success */
14139 + au_lcnt_dec(&br->br_nfiles);
14144 +static int au_cmoo(struct dentry *dentry)
14146 + int err, cmoo, matched;
14147 + unsigned int udba;
14148 + struct path h_path;
14149 + struct au_pin pin;
14150 + struct au_cp_generic cpg = {
14151 + .dentry = dentry,
14156 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14158 + struct inode *delegated;
14159 + struct super_block *sb;
14160 + struct au_sbinfo *sbinfo;
14161 + struct au_fhsm *fhsm;
14163 + struct au_branch *br;
14164 + struct dentry *parent;
14165 + struct au_hinode *hdir;
14167 + DiMustWriteLock(dentry);
14168 + IiMustWriteLock(d_inode(dentry));
14171 + if (IS_ROOT(dentry))
14173 + cpg.bsrc = au_dbtop(dentry);
14177 + sb = dentry->d_sb;
14178 + sbinfo = au_sbi(sb);
14179 + fhsm = &sbinfo->si_fhsm;
14180 + pid = au_fhsm_pid(fhsm);
14183 + && (current->pid == pid
14184 + || rcu_dereference(current->real_parent)->pid == pid));
14185 + rcu_read_unlock();
14189 + br = au_sbr(sb, cpg.bsrc);
14190 + cmoo = au_br_cmoo(br->br_perm);
14193 + if (!d_is_reg(dentry))
14194 + cmoo &= AuBrAttr_COO_ALL;
14198 + parent = dget_parent(dentry);
14199 + di_write_lock_parent(parent);
14200 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14202 + if (unlikely(err < 0)) {
14203 + err = 0; /* there is no upper writable branch */
14206 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14208 + /* do not respect the coo attrib for the target branch */
14209 + err = au_cpup_dirs(dentry, cpg.bdst);
14210 + if (unlikely(err))
14213 + di_downgrade_lock(parent, AuLock_IR);
14214 + udba = au_opt_udba(sb);
14215 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14216 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14217 + if (unlikely(err))
14220 + err = au_sio_cpup_simple(&cpg);
14222 + if (unlikely(err))
14224 + if (!(cmoo & AuBrWAttr_MOO))
14225 + goto out_parent; /* success */
14227 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14228 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14229 + if (unlikely(err))
14232 + h_path.mnt = au_br_mnt(br);
14233 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14234 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14235 + delegated = NULL;
14236 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14238 + /* todo: keep h_dentry or not? */
14239 + if (unlikely(err == -EWOULDBLOCK)) {
14240 + pr_warn("cannot retry for NFSv4 delegation"
14241 + " for an internal unlink\n");
14244 + if (unlikely(err)) {
14245 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14249 + goto out_parent; /* success */
14252 + di_downgrade_lock(parent, AuLock_IR);
14254 + di_read_unlock(parent, AuLock_IR);
14261 +int au_do_open(struct file *file, struct au_do_open_args *args)
14263 + int err, aopen = args->aopen;
14264 + struct dentry *dentry;
14265 + struct au_finfo *finfo;
14268 + err = au_finfo_init(file, args->fidir);
14271 + err = au_finfo_init(file, args->fidir);
14274 + if (unlikely(err))
14277 + dentry = file->f_path.dentry;
14278 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14279 + di_write_lock_child(dentry);
14280 + err = au_cmoo(dentry);
14281 + di_downgrade_lock(dentry, AuLock_IR);
14284 + err = args->open(file, vfsub_file_flags(file), NULL);
14287 + err = args->open(file, vfsub_file_flags(file),
14292 + di_read_unlock(dentry, AuLock_IR);
14294 + finfo = au_fi(file);
14296 + finfo->fi_file = file;
14297 + au_hbl_add(&finfo->fi_hlist,
14298 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14301 + fi_write_unlock(file);
14304 + fi_write_unlock(file);
14307 + if (unlikely(err)) {
14308 + finfo->fi_hdir = NULL;
14309 + au_finfo_fin(file);
14317 +int au_reopen_nondir(struct file *file)
14320 + aufs_bindex_t btop;
14321 + struct dentry *dentry;
14322 + struct au_branch *br;
14323 + struct file *h_file, *h_file_tmp;
14325 + dentry = file->f_path.dentry;
14326 + btop = au_dbtop(dentry);
14327 + br = au_sbr(dentry->d_sb, btop);
14328 + h_file_tmp = NULL;
14329 + if (au_fbtop(file) == btop) {
14330 + h_file = au_hf_top(file);
14331 + if (file->f_mode == h_file->f_mode)
14332 + return 0; /* success */
14333 + h_file_tmp = h_file;
14334 + get_file(h_file_tmp);
14335 + au_lcnt_inc(&br->br_nfiles);
14336 + au_set_h_fptr(file, btop, NULL);
14338 + AuDebugOn(au_fi(file)->fi_hdir);
14341 + * file exists on both of rw and ro
14342 + * open --> dbtop and fbtop are both 0
14343 + * prepend a branch as rw, "rw" become ro
14345 + * delete the top branch, "rw" becomes rw again
14346 + * --> dbtop is 1, fbtop is still 0
14347 + * write --> fbtop is 0 but dbtop is 1
14349 + /* AuDebugOn(au_fbtop(file) < btop); */
14351 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14352 + file, /*force_wr*/0);
14353 + err = PTR_ERR(h_file);
14354 + if (IS_ERR(h_file)) {
14355 + if (h_file_tmp) {
14357 + au_set_h_fptr(file, btop, h_file_tmp);
14358 + h_file_tmp = NULL;
14360 + goto out; /* todo: close all? */
14364 + au_set_fbtop(file, btop);
14365 + au_set_h_fptr(file, btop, h_file);
14366 + au_update_figen(file);
14367 + /* todo: necessary? */
14368 + /* file->f_ra = h_file->f_ra; */
14371 + if (h_file_tmp) {
14372 + fput(h_file_tmp);
14373 + au_lcnt_dec(&br->br_nfiles);
14378 +/* ---------------------------------------------------------------------- */
14380 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14381 + struct dentry *hi_wh)
14384 + aufs_bindex_t btop;
14385 + struct au_dinfo *dinfo;
14386 + struct dentry *h_dentry;
14387 + struct au_hdentry *hdp;
14389 + dinfo = au_di(file->f_path.dentry);
14390 + AuRwMustWriteLock(&dinfo->di_rwsem);
14392 + btop = dinfo->di_btop;
14393 + dinfo->di_btop = btgt;
14394 + hdp = au_hdentry(dinfo, btgt);
14395 + h_dentry = hdp->hd_dentry;
14396 + hdp->hd_dentry = hi_wh;
14397 + err = au_reopen_nondir(file);
14398 + hdp->hd_dentry = h_dentry;
14399 + dinfo->di_btop = btop;
14404 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14405 + aufs_bindex_t bcpup, struct au_pin *pin)
14408 + struct inode *inode, *h_inode;
14409 + struct dentry *h_dentry, *hi_wh;
14410 + struct au_cp_generic cpg = {
14411 + .dentry = file->f_path.dentry,
14418 + au_update_dbtop(cpg.dentry);
14419 + inode = d_inode(cpg.dentry);
14421 + if (au_dbtop(cpg.dentry) <= bcpup
14422 + && au_dbbot(cpg.dentry) >= bcpup) {
14423 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14424 + if (h_dentry && d_is_positive(h_dentry))
14425 + h_inode = d_inode(h_dentry);
14427 + hi_wh = au_hi_wh(inode, bcpup);
14428 + if (!hi_wh && !h_inode)
14429 + err = au_sio_cpup_wh(&cpg, file);
14431 + /* already copied-up after unlink */
14432 + err = au_reopen_wh(file, bcpup, hi_wh);
14435 + && (inode->i_nlink > 1
14436 + || (inode->i_state & I_LINKABLE))
14437 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14438 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14444 + * prepare the @file for writing.
14446 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14449 + aufs_bindex_t dbtop;
14450 + struct dentry *parent;
14451 + struct inode *inode;
14452 + struct super_block *sb;
14453 + struct file *h_file;
14454 + struct au_cp_generic cpg = {
14455 + .dentry = file->f_path.dentry,
14460 + .flags = AuCpup_DTIME
14463 + sb = cpg.dentry->d_sb;
14464 + inode = d_inode(cpg.dentry);
14465 + cpg.bsrc = au_fbtop(file);
14466 + err = au_test_ro(sb, cpg.bsrc, inode);
14467 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14468 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14473 + /* need to cpup or reopen */
14474 + parent = dget_parent(cpg.dentry);
14475 + di_write_lock_parent(parent);
14476 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14478 + if (unlikely(err < 0))
14482 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14483 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14484 + if (unlikely(err))
14488 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14489 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14490 + if (unlikely(err))
14493 + dbtop = au_dbtop(cpg.dentry);
14494 + if (dbtop <= cpg.bdst)
14495 + cpg.bsrc = cpg.bdst;
14497 + if (dbtop <= cpg.bdst /* just reopen */
14498 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14500 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14501 + if (IS_ERR(h_file))
14502 + err = PTR_ERR(h_file);
14504 + di_downgrade_lock(parent, AuLock_IR);
14505 + if (dbtop > cpg.bdst)
14506 + err = au_sio_cpup_simple(&cpg);
14508 + err = au_reopen_nondir(file);
14509 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14511 + } else { /* copyup as wh and reopen */
14513 + * since writable hfsplus branch is not supported,
14514 + * h_open_pre/post() are unnecessary.
14516 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14517 + di_downgrade_lock(parent, AuLock_IR);
14521 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14522 + goto out_dput; /* success */
14528 + di_downgrade_lock(parent, AuLock_IR);
14530 + di_read_unlock(parent, AuLock_IR);
14537 +/* ---------------------------------------------------------------------- */
14539 +int au_do_flush(struct file *file, fl_owner_t id,
14540 + int (*flush)(struct file *file, fl_owner_t id))
14543 + struct super_block *sb;
14544 + struct inode *inode;
14546 + inode = file_inode(file);
14547 + sb = inode->i_sb;
14548 + si_noflush_read_lock(sb);
14549 + fi_read_lock(file);
14550 + ii_read_lock_child(inode);
14552 + err = flush(file, id);
14553 + au_cpup_attr_timesizes(inode);
14555 + ii_read_unlock(inode);
14556 + fi_read_unlock(file);
14557 + si_read_unlock(sb);
14561 +/* ---------------------------------------------------------------------- */
14563 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14566 + struct au_pin pin;
14567 + struct au_finfo *finfo;
14568 + struct dentry *parent, *hi_wh;
14569 + struct inode *inode;
14570 + struct super_block *sb;
14571 + struct au_cp_generic cpg = {
14572 + .dentry = file->f_path.dentry,
14577 + .flags = AuCpup_DTIME
14580 + FiMustWriteLock(file);
14583 + finfo = au_fi(file);
14584 + sb = cpg.dentry->d_sb;
14585 + inode = d_inode(cpg.dentry);
14586 + cpg.bdst = au_ibtop(inode);
14587 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14590 + parent = dget_parent(cpg.dentry);
14591 + if (au_test_ro(sb, cpg.bdst, inode)) {
14592 + di_read_lock_parent(parent, !AuLock_IR);
14593 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14595 + di_read_unlock(parent, !AuLock_IR);
14596 + if (unlikely(err < 0))
14601 + di_read_lock_parent(parent, AuLock_IR);
14602 + hi_wh = au_hi_wh(inode, cpg.bdst);
14603 + if (!S_ISDIR(inode->i_mode)
14604 + && au_opt_test(au_mntflags(sb), PLINK)
14605 + && au_plink_test(inode)
14606 + && !d_unhashed(cpg.dentry)
14607 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14608 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14609 + if (unlikely(err))
14612 + /* always superio. */
14613 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14614 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14616 + err = au_sio_cpup_simple(&cpg);
14619 + } else if (hi_wh) {
14620 + /* already copied-up after unlink */
14621 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14622 + *need_reopen = 0;
14626 + di_read_unlock(parent, AuLock_IR);
14633 +static void au_do_refresh_dir(struct file *file)
14635 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14636 + struct au_hfile *p, tmp, *q;
14637 + struct au_finfo *finfo;
14638 + struct super_block *sb;
14639 + struct au_fidir *fidir;
14641 + FiMustWriteLock(file);
14643 + sb = file->f_path.dentry->d_sb;
14644 + finfo = au_fi(file);
14645 + fidir = finfo->fi_hdir;
14646 + AuDebugOn(!fidir);
14647 + p = fidir->fd_hfile + finfo->fi_btop;
14648 + brid = p->hf_br->br_id;
14649 + bbot = fidir->fd_bbot;
14650 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14654 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14655 + if (new_bindex == bindex)
14657 + if (new_bindex < 0) {
14658 + au_set_h_fptr(file, bindex, NULL);
14662 + /* swap two lower inode, and loop again */
14663 + q = fidir->fd_hfile + new_bindex;
14667 + if (tmp.hf_file) {
14673 + p = fidir->fd_hfile;
14674 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14675 + bbot = au_sbbot(sb);
14676 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14677 + finfo->fi_btop++, p++)
14678 + if (p->hf_file) {
14679 + if (file_inode(p->hf_file))
14681 + au_hfput(p, /*execed*/0);
14684 + bbot = au_br_index(sb, brid);
14685 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14686 + finfo->fi_btop++, p++)
14688 + au_hfput(p, /*execed*/0);
14689 + bbot = au_sbbot(sb);
14692 + p = fidir->fd_hfile + bbot;
14693 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14694 + fidir->fd_bbot--, p--)
14695 + if (p->hf_file) {
14696 + if (file_inode(p->hf_file))
14698 + au_hfput(p, /*execed*/0);
14700 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14704 + * after branch manipulating, refresh the file.
14706 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14708 + int err, need_reopen, nbr;
14709 + aufs_bindex_t bbot, bindex;
14710 + struct dentry *dentry;
14711 + struct super_block *sb;
14712 + struct au_finfo *finfo;
14713 + struct au_hfile *hfile;
14715 + dentry = file->f_path.dentry;
14716 + sb = dentry->d_sb;
14717 + nbr = au_sbbot(sb) + 1;
14718 + finfo = au_fi(file);
14719 + if (!finfo->fi_hdir) {
14720 + hfile = &finfo->fi_htop;
14721 + AuDebugOn(!hfile->hf_file);
14722 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14723 + AuDebugOn(bindex < 0);
14724 + if (bindex != finfo->fi_btop)
14725 + au_set_fbtop(file, bindex);
14727 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14728 + if (unlikely(err))
14730 + au_do_refresh_dir(file);
14735 + if (!au_test_mmapped(file))
14736 + err = au_file_refresh_by_inode(file, &need_reopen);
14737 + if (finfo->fi_hdir)
14738 + /* harmless if err */
14739 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14740 + if (!err && need_reopen && !d_unlinked(dentry))
14741 + err = reopen(file);
14743 + au_update_figen(file);
14744 + goto out; /* success */
14747 + /* error, close all lower files */
14748 + if (finfo->fi_hdir) {
14749 + bbot = au_fbbot_dir(file);
14750 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14751 + au_set_h_fptr(file, bindex, NULL);
14758 +/* common function to regular file and dir */
14759 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14760 + int wlock, unsigned int fi_lsc)
14763 + unsigned int sigen, figen;
14764 + aufs_bindex_t btop;
14765 + unsigned char pseudo_link;
14766 + struct dentry *dentry;
14767 + struct inode *inode;
14770 + dentry = file->f_path.dentry;
14771 + inode = d_inode(dentry);
14772 + sigen = au_sigen(dentry->d_sb);
14773 + fi_write_lock_nested(file, fi_lsc);
14774 + figen = au_figen(file);
14776 + di_write_lock_child(dentry);
14778 + di_write_lock_child2(dentry);
14779 + btop = au_dbtop(dentry);
14780 + pseudo_link = (btop != au_ibtop(inode));
14781 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14783 + di_downgrade_lock(dentry, AuLock_IR);
14784 + fi_downgrade_lock(file);
14786 + goto out; /* success */
14789 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14790 + if (au_digen_test(dentry, sigen)) {
14791 + err = au_reval_dpath(dentry, sigen);
14792 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14796 + err = refresh_file(file, reopen);
14799 + di_downgrade_lock(dentry, AuLock_IR);
14800 + fi_downgrade_lock(file);
14803 + di_write_unlock(dentry);
14804 + fi_write_unlock(file);
14811 +/* ---------------------------------------------------------------------- */
14813 +/* cf. aufs_nopage() */
14814 +/* for madvise(2) */
14815 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14817 + unlock_page(page);
14821 +/* it will never be called, but necessary to support O_DIRECT */
14822 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14823 +{ BUG(); return 0; }
14825 +/* they will never be called. */
14826 +#ifdef CONFIG_AUFS_DEBUG
14827 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14828 + loff_t pos, unsigned len, unsigned flags,
14829 + struct page **pagep, void **fsdata)
14830 +{ AuUnsupport(); return 0; }
14831 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14832 + loff_t pos, unsigned len, unsigned copied,
14833 + struct page *page, void *fsdata)
14834 +{ AuUnsupport(); return 0; }
14835 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14836 +{ AuUnsupport(); return 0; }
14838 +static int aufs_set_page_dirty(struct page *page)
14839 +{ AuUnsupport(); return 0; }
14840 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14841 + unsigned int length)
14842 +{ AuUnsupport(); }
14843 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14844 +{ AuUnsupport(); return 0; }
14845 +#if 0 /* called by memory compaction regardless file */
14846 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14847 + struct page *page, enum migrate_mode mode)
14848 +{ AuUnsupport(); return 0; }
14850 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14851 +{ AuUnsupport(); return true; }
14852 +static void aufs_putback_page(struct page *page)
14853 +{ AuUnsupport(); }
14854 +static int aufs_launder_page(struct page *page)
14855 +{ AuUnsupport(); return 0; }
14856 +static int aufs_is_partially_uptodate(struct page *page,
14857 + unsigned long from,
14858 + unsigned long count)
14859 +{ AuUnsupport(); return 0; }
14860 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14862 +{ AuUnsupport(); }
14863 +static int aufs_error_remove_page(struct address_space *mapping,
14864 + struct page *page)
14865 +{ AuUnsupport(); return 0; }
14866 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14868 +{ AuUnsupport(); return 0; }
14869 +static void aufs_swap_deactivate(struct file *file)
14870 +{ AuUnsupport(); }
14871 +#endif /* CONFIG_AUFS_DEBUG */
14873 +const struct address_space_operations aufs_aop = {
14874 + .readpage = aufs_readpage,
14875 + .direct_IO = aufs_direct_IO,
14876 +#ifdef CONFIG_AUFS_DEBUG
14877 + .writepage = aufs_writepage,
14878 + /* no writepages, because of writepage */
14879 + .set_page_dirty = aufs_set_page_dirty,
14880 + /* no readpages, because of readpage */
14881 + .write_begin = aufs_write_begin,
14882 + .write_end = aufs_write_end,
14883 + /* no bmap, no block device */
14884 + .invalidatepage = aufs_invalidatepage,
14885 + .releasepage = aufs_releasepage,
14886 + /* is fallback_migrate_page ok? */
14887 + /* .migratepage = aufs_migratepage, */
14888 + .isolate_page = aufs_isolate_page,
14889 + .putback_page = aufs_putback_page,
14890 + .launder_page = aufs_launder_page,
14891 + .is_partially_uptodate = aufs_is_partially_uptodate,
14892 + .is_dirty_writeback = aufs_is_dirty_writeback,
14893 + .error_remove_page = aufs_error_remove_page,
14894 + .swap_activate = aufs_swap_activate,
14895 + .swap_deactivate = aufs_swap_deactivate
14896 +#endif /* CONFIG_AUFS_DEBUG */
14898 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14899 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14900 +++ linux/fs/aufs/file.h 2021-12-03 15:38:59.936647310 +0100
14902 +/* SPDX-License-Identifier: GPL-2.0 */
14904 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14906 + * This program, aufs is free software; you can redistribute it and/or modify
14907 + * it under the terms of the GNU General Public License as published by
14908 + * the Free Software Foundation; either version 2 of the License, or
14909 + * (at your option) any later version.
14911 + * This program is distributed in the hope that it will be useful,
14912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14914 + * GNU General Public License for more details.
14916 + * You should have received a copy of the GNU General Public License
14917 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14921 + * file operations
14924 +#ifndef __AUFS_FILE_H__
14925 +#define __AUFS_FILE_H__
14929 +#include <linux/file.h>
14930 +#include <linux/fs.h>
14931 +#include <linux/mm_types.h>
14932 +#include <linux/poll.h>
14933 +#include "rwsem.h"
14937 + struct file *hf_file;
14938 + struct au_branch *hf_br;
14943 + aufs_bindex_t fd_bbot;
14944 + aufs_bindex_t fd_nent;
14945 + struct au_vdir *fd_vdir_cache;
14946 + struct au_hfile fd_hfile[];
14949 +static inline int au_fidir_sz(int nent)
14951 + AuDebugOn(nent < 0);
14952 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14956 + atomic_t fi_generation;
14958 + struct au_rwsem fi_rwsem;
14959 + aufs_bindex_t fi_btop;
14961 + /* do not union them */
14962 + struct { /* for non-dir */
14963 + struct au_hfile fi_htop;
14964 + atomic_t fi_mmapped;
14966 + struct au_fidir *fi_hdir; /* for dir only */
14968 + struct hlist_bl_node fi_hlist;
14969 + struct file *fi_file; /* very ugly */
14970 + struct rcu_head rcu;
14971 +} ____cacheline_aligned_in_smp;
14973 +/* ---------------------------------------------------------------------- */
14976 +extern const struct address_space_operations aufs_aop;
14977 +unsigned int au_file_roflags(unsigned int flags);
14978 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14979 + struct file *file, int force_wr);
14980 +struct au_do_open_args {
14982 + int (*open)(struct file *file, int flags,
14983 + struct file *h_file);
14984 + struct au_fidir *fidir;
14985 + struct file *h_file;
14987 +int au_do_open(struct file *file, struct au_do_open_args *args);
14988 +int au_reopen_nondir(struct file *file);
14990 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14991 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14992 + int wlock, unsigned int fi_lsc);
14993 +int au_do_flush(struct file *file, fl_owner_t id,
14994 + int (*flush)(struct file *file, fl_owner_t id));
14997 +#ifdef CONFIG_AUFS_POLL
14998 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15001 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15003 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15005 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15006 + struct file *h_file);
15008 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15009 + aufs_bindex_t bindex, int force_wr)
15010 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15011 + struct file *h_file);
15015 +extern const struct file_operations aufs_file_fop;
15016 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15017 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15018 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15021 +void au_hfput(struct au_hfile *hf, int execed);
15022 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15023 + struct file *h_file);
15025 +void au_update_figen(struct file *file);
15026 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15027 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15029 +void au_fi_init_once(void *_fi);
15030 +void au_finfo_fin(struct file *file);
15031 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15034 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15035 +#ifdef CONFIG_COMPAT
15036 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15037 + unsigned long arg);
15038 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15039 + unsigned long arg);
15042 +/* ---------------------------------------------------------------------- */
15044 +static inline struct au_finfo *au_fi(struct file *file)
15046 + return file->private_data;
15049 +/* ---------------------------------------------------------------------- */
15051 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15052 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15053 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15054 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15056 +#define fi_read_trylock_nested(f) \
15057 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15058 +#define fi_write_trylock_nested(f) \
15059 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15062 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15063 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15064 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15066 +/* lock subclass for finfo */
15072 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15074 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15077 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15079 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15083 + * fi_read_lock_1, fi_write_lock_1,
15084 + * fi_read_lock_2, fi_write_lock_2
15086 +#define AuReadLockFunc(name) \
15087 +static inline void fi_read_lock_##name(struct file *f) \
15088 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15090 +#define AuWriteLockFunc(name) \
15091 +static inline void fi_write_lock_##name(struct file *f) \
15092 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15094 +#define AuRWLockFuncs(name) \
15095 + AuReadLockFunc(name) \
15096 + AuWriteLockFunc(name)
15101 +#undef AuReadLockFunc
15102 +#undef AuWriteLockFunc
15103 +#undef AuRWLockFuncs
15105 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15106 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15107 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15109 +/* ---------------------------------------------------------------------- */
15111 +/* todo: hard/soft set? */
15112 +static inline aufs_bindex_t au_fbtop(struct file *file)
15114 + FiMustAnyLock(file);
15115 + return au_fi(file)->fi_btop;
15118 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15120 + FiMustAnyLock(file);
15121 + AuDebugOn(!au_fi(file)->fi_hdir);
15122 + return au_fi(file)->fi_hdir->fd_bbot;
15125 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15127 + FiMustAnyLock(file);
15128 + AuDebugOn(!au_fi(file)->fi_hdir);
15129 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15132 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15134 + FiMustWriteLock(file);
15135 + au_fi(file)->fi_btop = bindex;
15138 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15140 + FiMustWriteLock(file);
15141 + AuDebugOn(!au_fi(file)->fi_hdir);
15142 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15145 +static inline void au_set_fvdir_cache(struct file *file,
15146 + struct au_vdir *vdir_cache)
15148 + FiMustWriteLock(file);
15149 + AuDebugOn(!au_fi(file)->fi_hdir);
15150 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15153 +static inline struct file *au_hf_top(struct file *file)
15155 + FiMustAnyLock(file);
15156 + AuDebugOn(au_fi(file)->fi_hdir);
15157 + return au_fi(file)->fi_htop.hf_file;
15160 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15162 + FiMustAnyLock(file);
15163 + AuDebugOn(!au_fi(file)->fi_hdir);
15164 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15167 +/* todo: memory barrier? */
15168 +static inline unsigned int au_figen(struct file *f)
15170 + return atomic_read(&au_fi(f)->fi_generation);
15173 +static inline void au_set_mmapped(struct file *f)
15175 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15177 + pr_warn("fi_mmapped wrapped around\n");
15178 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15182 +static inline void au_unset_mmapped(struct file *f)
15184 + atomic_dec(&au_fi(f)->fi_mmapped);
15187 +static inline int au_test_mmapped(struct file *f)
15189 + return atomic_read(&au_fi(f)->fi_mmapped);
15192 +/* customize vma->vm_file */
15194 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15195 + struct file *file)
15199 + f = vma->vm_file;
15201 + vma->vm_file = file;
15206 +#define AuDbgVmRegion(file, vma) do {} while (0)
15208 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15209 + struct file *file)
15211 + au_do_vm_file_reset(vma, file);
15214 +#define AuDbgVmRegion(file, vma) \
15215 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15217 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15218 + struct file *file)
15222 + au_do_vm_file_reset(vma, file);
15223 + f = vma->vm_region->vm_file;
15225 + vma->vm_region->vm_file = file;
15228 +#endif /* CONFIG_MMU */
15230 +/* handle vma->vm_prfile */
15231 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15232 + struct file *file)
15235 + vma->vm_prfile = file;
15236 +#ifndef CONFIG_MMU
15238 + vma->vm_region->vm_prfile = file;
15242 +#endif /* __KERNEL__ */
15243 +#endif /* __AUFS_FILE_H__ */
15244 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15245 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15246 +++ linux/fs/aufs/finfo.c 2021-12-03 15:38:59.936647310 +0100
15248 +// SPDX-License-Identifier: GPL-2.0
15250 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15252 + * This program, aufs is free software; you can redistribute it and/or modify
15253 + * it under the terms of the GNU General Public License as published by
15254 + * the Free Software Foundation; either version 2 of the License, or
15255 + * (at your option) any later version.
15257 + * This program is distributed in the hope that it will be useful,
15258 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15259 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15260 + * GNU General Public License for more details.
15262 + * You should have received a copy of the GNU General Public License
15263 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15267 + * file private data
15272 +void au_hfput(struct au_hfile *hf, int execed)
15275 + allow_write_access(hf->hf_file);
15276 + fput(hf->hf_file);
15277 + hf->hf_file = NULL;
15278 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15279 + hf->hf_br = NULL;
15282 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15284 + struct au_finfo *finfo = au_fi(file);
15285 + struct au_hfile *hf;
15286 + struct au_fidir *fidir;
15288 + fidir = finfo->fi_hdir;
15290 + AuDebugOn(finfo->fi_btop != bindex);
15291 + hf = &finfo->fi_htop;
15293 + hf = fidir->fd_hfile + bindex;
15295 + if (hf && hf->hf_file)
15296 + au_hfput(hf, vfsub_file_execed(file));
15298 + FiMustWriteLock(file);
15299 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15300 + hf->hf_file = val;
15301 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15305 +void au_update_figen(struct file *file)
15307 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15308 + /* smp_mb(); */ /* atomic_set */
15311 +/* ---------------------------------------------------------------------- */
15313 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15315 + struct au_fidir *fidir;
15318 + nbr = au_sbbot(sb) + 1;
15320 + nbr = 2; /* initial allocate for 2 branches */
15321 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15323 + fidir->fd_bbot = -1;
15324 + fidir->fd_nent = nbr;
15330 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15333 + struct au_fidir *fidir, *p;
15335 + AuRwMustWriteLock(&finfo->fi_rwsem);
15336 + fidir = finfo->fi_hdir;
15337 + AuDebugOn(!fidir);
15340 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15341 + GFP_NOFS, may_shrink);
15343 + p->fd_nent = nbr;
15344 + finfo->fi_hdir = p;
15351 +/* ---------------------------------------------------------------------- */
15353 +void au_finfo_fin(struct file *file)
15355 + struct au_finfo *finfo;
15357 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15359 + finfo = au_fi(file);
15360 + AuDebugOn(finfo->fi_hdir);
15361 + AuRwDestroy(&finfo->fi_rwsem);
15362 + au_cache_free_finfo(finfo);
15365 +void au_fi_init_once(void *_finfo)
15367 + struct au_finfo *finfo = _finfo;
15369 + au_rw_init(&finfo->fi_rwsem);
15372 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15375 + struct au_finfo *finfo;
15376 + struct dentry *dentry;
15379 + dentry = file->f_path.dentry;
15380 + finfo = au_cache_alloc_finfo();
15381 + if (unlikely(!finfo))
15385 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15386 + au_rw_write_lock(&finfo->fi_rwsem);
15387 + finfo->fi_btop = -1;
15388 + finfo->fi_hdir = fidir;
15389 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15390 + /* smp_mb(); */ /* atomic_set */
15392 + file->private_data = finfo;
15397 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15398 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15399 +++ linux/fs/aufs/f_op.c 2021-12-03 15:38:59.933313976 +0100
15401 +// SPDX-License-Identifier: GPL-2.0
15403 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15405 + * This program, aufs is free software; you can redistribute it and/or modify
15406 + * it under the terms of the GNU General Public License as published by
15407 + * the Free Software Foundation; either version 2 of the License, or
15408 + * (at your option) any later version.
15410 + * This program is distributed in the hope that it will be useful,
15411 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15412 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15413 + * GNU General Public License for more details.
15415 + * You should have received a copy of the GNU General Public License
15416 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15420 + * file and vm operations
15423 +#include <linux/aio.h>
15424 +#include <linux/fs_stack.h>
15425 +#include <linux/mman.h>
15426 +#include <linux/security.h>
15429 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15432 + aufs_bindex_t bindex;
15433 + struct dentry *dentry, *h_dentry;
15434 + struct au_finfo *finfo;
15435 + struct inode *h_inode;
15437 + FiMustWriteLock(file);
15440 + dentry = file->f_path.dentry;
15441 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15442 + finfo = au_fi(file);
15443 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15444 + atomic_set(&finfo->fi_mmapped, 0);
15445 + bindex = au_dbtop(dentry);
15447 + h_dentry = au_h_dptr(dentry, bindex);
15448 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15449 + if (unlikely(err))
15451 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15452 + if (IS_ERR(h_file)) {
15453 + err = PTR_ERR(h_file);
15457 + h_dentry = h_file->f_path.dentry;
15458 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15459 + if (unlikely(err))
15461 + /* br ref is already inc-ed */
15464 + if ((flags & __O_TMPFILE)
15465 + && !(flags & O_EXCL)) {
15466 + h_inode = file_inode(h_file);
15467 + spin_lock(&h_inode->i_lock);
15468 + h_inode->i_state |= I_LINKABLE;
15469 + spin_unlock(&h_inode->i_lock);
15471 + au_set_fbtop(file, bindex);
15472 + au_set_h_fptr(file, bindex, h_file);
15473 + au_update_figen(file);
15474 + /* todo: necessary? */
15475 + /* file->f_ra = h_file->f_ra; */
15481 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15482 + struct file *file)
15485 + struct super_block *sb;
15486 + struct au_do_open_args args = {
15487 + .open = au_do_open_nondir
15490 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15491 + file, vfsub_file_flags(file), file->f_mode);
15493 + sb = file->f_path.dentry->d_sb;
15494 + si_read_lock(sb, AuLock_FLUSH);
15495 + err = au_do_open(file, &args);
15496 + si_read_unlock(sb);
15500 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15502 + struct au_finfo *finfo;
15503 + aufs_bindex_t bindex;
15505 + finfo = au_fi(file);
15506 + au_hbl_del(&finfo->fi_hlist,
15507 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15508 + bindex = finfo->fi_btop;
15510 + au_set_h_fptr(file, bindex, NULL);
15512 + au_finfo_fin(file);
15516 +/* ---------------------------------------------------------------------- */
15518 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15521 + struct file *h_file;
15524 + h_file = au_hf_top(file);
15526 + err = vfsub_flush(h_file, id);
15530 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15532 + return au_do_flush(file, id, au_do_flush_nondir);
15535 +/* ---------------------------------------------------------------------- */
15537 + * read and write functions acquire [fdi]_rwsem once, but release before
15538 + * mmap_sem. This is because to stop a race condition between mmap(2).
15539 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15540 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15541 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15544 +/* Callers should call au_read_post() or fput() in the end */
15545 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15547 + struct file *h_file;
15550 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15552 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15553 + h_file = au_hf_top(file);
15554 + get_file(h_file);
15556 + fi_read_unlock(file);
15558 + h_file = ERR_PTR(err);
15563 +static void au_read_post(struct inode *inode, struct file *h_file)
15565 + /* update without lock, I don't think it a problem */
15566 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15570 +struct au_write_pre {
15572 + unsigned int lsc;
15576 + aufs_bindex_t btop;
15580 + * return with iinfo is write-locked
15581 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15584 +static struct file *au_write_pre(struct file *file, int do_ready,
15585 + struct au_write_pre *wpre)
15587 + struct file *h_file;
15588 + struct dentry *dentry;
15590 + unsigned int lsc;
15591 + struct au_pin pin;
15596 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15597 + h_file = ERR_PTR(err);
15598 + if (unlikely(err))
15601 + dentry = file->f_path.dentry;
15603 + err = au_ready_to_write(file, -1, &pin);
15604 + if (unlikely(err)) {
15605 + h_file = ERR_PTR(err);
15606 + di_write_unlock(dentry);
15611 + di_downgrade_lock(dentry, /*flags*/0);
15613 + wpre->btop = au_fbtop(file);
15614 + h_file = au_hf_top(file);
15615 + get_file(h_file);
15617 + wpre->blks = file_inode(h_file)->i_blocks;
15620 + di_read_unlock(dentry, /*flags*/0);
15623 + fi_write_unlock(file);
15628 +static void au_write_post(struct inode *inode, struct file *h_file,
15629 + struct au_write_pre *wpre, ssize_t written)
15631 + struct inode *h_inode;
15633 + au_cpup_attr_timesizes(inode);
15634 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15635 + h_inode = file_inode(h_file);
15636 + inode->i_mode = h_inode->i_mode;
15637 + ii_write_unlock(inode);
15638 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15640 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15641 + /*force*/h_inode->i_blocks > wpre->blks);
15646 + * todo: very ugly
15647 + * it locks both of i_mutex and si_rwsem for read in safe.
15648 + * if the plink maintenance mode continues forever (that is the problem),
15649 + * may loop forever.
15651 +static void au_mtx_and_read_lock(struct inode *inode)
15654 + struct super_block *sb = inode->i_sb;
15657 + inode_lock(inode);
15658 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15661 + inode_unlock(inode);
15662 + si_read_lock(sb, AuLock_NOPLMW);
15663 + si_read_unlock(sb);
15667 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15668 + struct iov_iter *iov_iter)
15671 + struct file *file;
15672 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15674 + err = security_file_permission(h_file, rw);
15675 + if (unlikely(err))
15678 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15680 + if (rw == MAY_READ)
15681 + iter = h_file->f_op->read_iter;
15682 + else if (rw == MAY_WRITE)
15683 + iter = h_file->f_op->write_iter;
15685 + file = kio->ki_filp;
15686 + kio->ki_filp = h_file;
15689 + err = iter(kio, iov_iter);
15692 + /* currently there is no such fs */
15694 + kio->ki_filp = file;
15700 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15703 + struct file *file, *h_file;
15704 + struct inode *inode;
15705 + struct super_block *sb;
15707 + file = kio->ki_filp;
15708 + inode = file_inode(file);
15709 + sb = inode->i_sb;
15710 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15712 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15713 + err = PTR_ERR(h_file);
15714 + if (IS_ERR(h_file))
15717 + if (au_test_loopback_kthread()) {
15718 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15719 + if (file->f_mapping != h_file->f_mapping) {
15720 + file->f_mapping = h_file->f_mapping;
15721 + smp_mb(); /* unnecessary? */
15724 + fi_read_unlock(file);
15726 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15727 + /* todo: necessary? */
15728 + /* file->f_ra = h_file->f_ra; */
15729 + au_read_post(inode, h_file);
15732 + si_read_unlock(sb);
15736 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15739 + struct au_write_pre wpre;
15740 + struct inode *inode;
15741 + struct file *file, *h_file;
15743 + file = kio->ki_filp;
15744 + inode = file_inode(file);
15745 + au_mtx_and_read_lock(inode);
15748 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15749 + err = PTR_ERR(h_file);
15750 + if (IS_ERR(h_file))
15753 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15754 + au_write_post(inode, h_file, &wpre, err);
15757 + si_read_unlock(inode->i_sb);
15758 + inode_unlock(inode);
15763 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15764 + * don't have their own .splice_{read,write} implimentations, and they use
15765 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15766 + * simple converters to f_op->iter_read() and ->iter_write().
15767 + * But we keep our own implementations because some non-mainlined FSes may have
15768 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15769 + * away an opportunity to co-work with aufs from them.
15771 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15772 + struct pipe_inode_info *pipe, size_t len,
15773 + unsigned int flags)
15776 + struct file *h_file;
15777 + struct inode *inode;
15778 + struct super_block *sb;
15780 + inode = file_inode(file);
15781 + sb = inode->i_sb;
15782 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15784 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15785 + err = PTR_ERR(h_file);
15786 + if (IS_ERR(h_file))
15789 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15790 + /* todo: necessary? */
15791 + /* file->f_ra = h_file->f_ra; */
15792 + au_read_post(inode, h_file);
15795 + si_read_unlock(sb);
15800 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15801 + size_t len, unsigned int flags)
15804 + struct au_write_pre wpre;
15805 + struct inode *inode;
15806 + struct file *h_file;
15808 + inode = file_inode(file);
15809 + au_mtx_and_read_lock(inode);
15812 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15813 + err = PTR_ERR(h_file);
15814 + if (IS_ERR(h_file))
15817 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15818 + au_write_post(inode, h_file, &wpre, err);
15821 + si_read_unlock(inode->i_sb);
15822 + inode_unlock(inode);
15826 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15830 + struct au_write_pre wpre;
15831 + struct inode *inode;
15832 + struct file *h_file;
15834 + inode = file_inode(file);
15835 + au_mtx_and_read_lock(inode);
15838 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15839 + err = PTR_ERR(h_file);
15840 + if (IS_ERR(h_file))
15844 + err = vfs_fallocate(h_file, mode, offset, len);
15846 + au_write_post(inode, h_file, &wpre, /*written*/1);
15849 + si_read_unlock(inode->i_sb);
15850 + inode_unlock(inode);
15854 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15855 + struct file *dst, loff_t dst_pos,
15856 + size_t len, unsigned int flags)
15859 + struct au_write_pre wpre;
15860 + enum { SRC, DST };
15862 + struct inode *inode;
15863 + struct file *h_file;
15864 + struct super_block *h_sb;
15866 +#define a_src a[SRC]
15867 +#define a_dst a[DST]
15870 + a_src.inode = file_inode(src);
15871 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15873 + a_dst.inode = file_inode(dst);
15874 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15877 + au_mtx_and_read_lock(a_dst.inode);
15879 + * in order to match the order in di_write_lock2_{child,parent}(),
15880 + * use f_path.dentry for this comparison.
15882 + if (src->f_path.dentry < dst->f_path.dentry) {
15883 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15884 + err = PTR_ERR(a_src.h_file);
15885 + if (IS_ERR(a_src.h_file))
15888 + wpre.lsc = AuLsc_FI_2;
15889 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15890 + err = PTR_ERR(a_dst.h_file);
15891 + if (IS_ERR(a_dst.h_file)) {
15892 + au_read_post(a_src.inode, a_src.h_file);
15896 + wpre.lsc = AuLsc_FI_1;
15897 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15898 + err = PTR_ERR(a_dst.h_file);
15899 + if (IS_ERR(a_dst.h_file))
15902 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15903 + err = PTR_ERR(a_src.h_file);
15904 + if (IS_ERR(a_src.h_file)) {
15905 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15912 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15913 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15914 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15920 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15921 + dst_pos, len, flags);
15924 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15925 + fi_read_unlock(src);
15926 + au_read_post(a_src.inode, a_src.h_file);
15928 + si_read_unlock(a_dst.inode->i_sb);
15929 + inode_unlock(a_dst.inode);
15936 +/* ---------------------------------------------------------------------- */
15939 + * The locking order around current->mmap_sem.
15940 + * - in most and regular cases
15941 + * file I/O syscall -- aufs_read() or something
15942 + * -- si_rwsem for read -- mmap_sem
15943 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15945 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15946 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15947 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15948 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15949 + * It means that when aufs acquires si_rwsem for write, the process should never
15950 + * acquire mmap_sem.
15952 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15953 + * problem either since any directory is not able to be mmap-ed.
15954 + * The similar scenario is applied to aufs_readlink() too.
15957 +#if 0 /* stop calling security_file_mmap() */
15958 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15959 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15961 +static unsigned long au_arch_prot_conv(unsigned long flags)
15963 + /* currently ppc64 only */
15964 +#ifdef CONFIG_PPC64
15965 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15966 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15967 + return AuConv_VM_PROT(flags, SAO);
15969 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15974 +static unsigned long au_prot_conv(unsigned long flags)
15976 + return AuConv_VM_PROT(flags, READ)
15977 + | AuConv_VM_PROT(flags, WRITE)
15978 + | AuConv_VM_PROT(flags, EXEC)
15979 + | au_arch_prot_conv(flags);
15982 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15983 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15985 +static unsigned long au_flag_conv(unsigned long flags)
15987 + return AuConv_VM_MAP(flags, GROWSDOWN)
15988 + | AuConv_VM_MAP(flags, DENYWRITE)
15989 + | AuConv_VM_MAP(flags, LOCKED);
15993 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
15996 + const unsigned char wlock
15997 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
15998 + struct super_block *sb;
15999 + struct file *h_file;
16000 + struct inode *inode;
16002 + AuDbgVmRegion(file, vma);
16004 + inode = file_inode(file);
16005 + sb = inode->i_sb;
16007 + si_read_lock(sb, AuLock_NOPLMW);
16009 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16011 + err = PTR_ERR(h_file);
16012 + if (IS_ERR(h_file))
16016 + au_set_mmapped(file);
16017 + au_vm_file_reset(vma, h_file);
16019 + * we cannot call security_mmap_file() here since it may acquire
16020 + * mmap_sem or i_mutex.
16022 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16023 + * au_flag_conv(vma->vm_flags));
16026 + err = call_mmap(h_file, vma);
16028 + au_vm_prfile_set(vma, file);
16029 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16030 + goto out_fput; /* success */
16032 + au_unset_mmapped(file);
16033 + au_vm_file_reset(vma, file);
16037 + ii_write_unlock(inode);
16042 + si_read_unlock(sb);
16048 +/* ---------------------------------------------------------------------- */
16050 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16054 + struct au_write_pre wpre;
16055 + struct inode *inode;
16056 + struct file *h_file;
16058 + err = 0; /* -EBADF; */ /* posix? */
16059 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16062 + inode = file_inode(file);
16063 + au_mtx_and_read_lock(inode);
16066 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16067 + err = PTR_ERR(h_file);
16068 + if (IS_ERR(h_file))
16071 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16072 + au_write_post(inode, h_file, &wpre, /*written*/0);
16075 + si_read_unlock(inode->i_sb);
16076 + inode_unlock(inode);
16081 +static int aufs_fasync(int fd, struct file *file, int flag)
16084 + struct file *h_file;
16085 + struct super_block *sb;
16087 + sb = file->f_path.dentry->d_sb;
16088 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16090 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16091 + err = PTR_ERR(h_file);
16092 + if (IS_ERR(h_file))
16095 + if (h_file->f_op->fasync)
16096 + err = h_file->f_op->fasync(fd, h_file, flag);
16097 + fput(h_file); /* instead of au_read_post() */
16100 + si_read_unlock(sb);
16104 +static int aufs_setfl(struct file *file, unsigned long arg)
16107 + struct file *h_file;
16108 + struct super_block *sb;
16110 + sb = file->f_path.dentry->d_sb;
16111 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16113 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16114 + err = PTR_ERR(h_file);
16115 + if (IS_ERR(h_file))
16118 + /* stop calling h_file->fasync */
16119 + arg |= vfsub_file_flags(file) & FASYNC;
16120 + err = setfl(/*unused fd*/-1, h_file, arg);
16121 + fput(h_file); /* instead of au_read_post() */
16124 + si_read_unlock(sb);
16128 +/* ---------------------------------------------------------------------- */
16130 +/* no one supports this operation, currently */
16131 +#if 0 /* reserved for future use */
16132 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16133 + size_t len, loff_t *pos, int more)
16138 +/* ---------------------------------------------------------------------- */
16140 +const struct file_operations aufs_file_fop = {
16141 + .owner = THIS_MODULE,
16143 + .llseek = default_llseek,
16145 + .read_iter = aufs_read_iter,
16146 + .write_iter = aufs_write_iter,
16148 +#ifdef CONFIG_AUFS_POLL
16149 + .poll = aufs_poll,
16151 + .unlocked_ioctl = aufs_ioctl_nondir,
16152 +#ifdef CONFIG_COMPAT
16153 + .compat_ioctl = aufs_compat_ioctl_nondir,
16155 + .mmap = aufs_mmap,
16156 + .open = aufs_open_nondir,
16157 + .flush = aufs_flush_nondir,
16158 + .release = aufs_release_nondir,
16159 + .fsync = aufs_fsync_nondir,
16160 + .fasync = aufs_fasync,
16161 + /* .sendpage = aufs_sendpage, */
16162 + .setfl = aufs_setfl,
16163 + .splice_write = aufs_splice_write,
16164 + .splice_read = aufs_splice_read,
16165 +#if 0 /* reserved for future use */
16166 + .aio_splice_write = aufs_aio_splice_write,
16167 + .aio_splice_read = aufs_aio_splice_read,
16169 + .fallocate = aufs_fallocate,
16170 + .copy_file_range = aufs_copy_file_range
16172 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16173 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16174 +++ linux/fs/aufs/fstype.h 2021-12-03 15:38:59.936647310 +0100
16176 +/* SPDX-License-Identifier: GPL-2.0 */
16178 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16180 + * This program, aufs is free software; you can redistribute it and/or modify
16181 + * it under the terms of the GNU General Public License as published by
16182 + * the Free Software Foundation; either version 2 of the License, or
16183 + * (at your option) any later version.
16185 + * This program is distributed in the hope that it will be useful,
16186 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16187 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16188 + * GNU General Public License for more details.
16190 + * You should have received a copy of the GNU General Public License
16191 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16195 + * judging filesystem type
16198 +#ifndef __AUFS_FSTYPE_H__
16199 +#define __AUFS_FSTYPE_H__
16203 +#include <linux/fs.h>
16204 +#include <linux/magic.h>
16205 +#include <linux/nfs_fs.h>
16206 +#include <linux/romfs_fs.h>
16208 +static inline int au_test_aufs(struct super_block *sb)
16210 + return sb->s_magic == AUFS_SUPER_MAGIC;
16213 +static inline const char *au_sbtype(struct super_block *sb)
16215 + return sb->s_type->name;
16218 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16220 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16221 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16227 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16229 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16230 + return sb->s_magic == ROMFS_MAGIC;
16236 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16238 +#if IS_ENABLED(CONFIG_CRAMFS)
16239 + return sb->s_magic == CRAMFS_MAGIC;
16244 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16246 +#if IS_ENABLED(CONFIG_NFS_FS)
16247 + return sb->s_magic == NFS_SUPER_MAGIC;
16253 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16255 +#if IS_ENABLED(CONFIG_FUSE_FS)
16256 + return sb->s_magic == FUSE_SUPER_MAGIC;
16262 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16264 +#if IS_ENABLED(CONFIG_XFS_FS)
16265 + return sb->s_magic == XFS_SB_MAGIC;
16271 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16273 +#ifdef CONFIG_TMPFS
16274 + return sb->s_magic == TMPFS_MAGIC;
16280 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16282 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16283 + return !strcmp(au_sbtype(sb), "ecryptfs");
16289 +static inline int au_test_ramfs(struct super_block *sb)
16291 + return sb->s_magic == RAMFS_MAGIC;
16294 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16296 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16297 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16303 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16305 +#ifdef CONFIG_PROC_FS
16306 + return sb->s_magic == PROC_SUPER_MAGIC;
16312 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16314 +#ifdef CONFIG_SYSFS
16315 + return sb->s_magic == SYSFS_MAGIC;
16321 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16323 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16324 + return sb->s_magic == CONFIGFS_MAGIC;
16330 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16332 +#if IS_ENABLED(CONFIG_MINIX_FS)
16333 + return sb->s_magic == MINIX3_SUPER_MAGIC
16334 + || sb->s_magic == MINIX2_SUPER_MAGIC
16335 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16336 + || sb->s_magic == MINIX_SUPER_MAGIC
16337 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16343 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16345 +#if IS_ENABLED(CONFIG_FAT_FS)
16346 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16352 +static inline int au_test_msdos(struct super_block *sb)
16354 + return au_test_fat(sb);
16357 +static inline int au_test_vfat(struct super_block *sb)
16359 + return au_test_fat(sb);
16362 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16364 +#ifdef CONFIG_SECURITYFS
16365 + return sb->s_magic == SECURITYFS_MAGIC;
16371 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16373 +#if IS_ENABLED(CONFIG_SQUASHFS)
16374 + return sb->s_magic == SQUASHFS_MAGIC;
16380 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16382 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16383 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16389 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16391 +#if IS_ENABLED(CONFIG_XENFS)
16392 + return sb->s_magic == XENFS_SUPER_MAGIC;
16398 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16400 +#ifdef CONFIG_DEBUG_FS
16401 + return sb->s_magic == DEBUGFS_MAGIC;
16407 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16409 +#if IS_ENABLED(CONFIG_NILFS)
16410 + return sb->s_magic == NILFS_SUPER_MAGIC;
16416 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16418 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16419 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16425 +/* ---------------------------------------------------------------------- */
16427 + * they can't be an aufs branch.
16429 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16432 +#ifndef CONFIG_AUFS_BR_RAMFS
16433 + au_test_ramfs(sb) ||
16435 + au_test_procfs(sb)
16436 + || au_test_sysfs(sb)
16437 + || au_test_configfs(sb)
16438 + || au_test_debugfs(sb)
16439 + || au_test_securityfs(sb)
16440 + || au_test_xenfs(sb)
16441 + || au_test_ecryptfs(sb)
16442 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16443 + || au_test_aufs(sb); /* will be supported in next version */
16446 +static inline int au_test_fs_remote(struct super_block *sb)
16448 + return !au_test_tmpfs(sb)
16449 +#ifdef CONFIG_AUFS_BR_RAMFS
16450 + && !au_test_ramfs(sb)
16452 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16455 +/* ---------------------------------------------------------------------- */
16458 + * Note: these functions (below) are created after reading ->getattr() in all
16459 + * filesystems under linux/fs. it means we have to do so in every update...
16463 + * some filesystems require getattr to refresh the inode attributes before
16465 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16466 + * and leave the work for d_revalidate()
16468 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16470 + return au_test_nfs(sb)
16471 + || au_test_fuse(sb)
16472 + /* || au_test_btrfs(sb) */ /* untested */
16477 + * filesystems which don't maintain i_size or i_blocks.
16479 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16481 + return au_test_xfs(sb)
16482 + || au_test_btrfs(sb)
16483 + || au_test_ubifs(sb)
16484 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16485 + /* || au_test_minix(sb) */ /* untested */
16490 + * filesystems which don't store the correct value in some of their inode
16493 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16495 + return au_test_fs_bad_iattr_size(sb)
16496 + || au_test_fat(sb)
16497 + || au_test_msdos(sb)
16498 + || au_test_vfat(sb);
16501 +/* they don't check i_nlink in link(2) */
16502 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16504 + return au_test_tmpfs(sb)
16505 +#ifdef CONFIG_AUFS_BR_RAMFS
16506 + || au_test_ramfs(sb)
16508 + || au_test_ubifs(sb)
16509 + || au_test_hfsplus(sb);
16513 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16515 +static inline int au_test_fs_notime(struct super_block *sb)
16517 + return au_test_nfs(sb)
16518 + || au_test_fuse(sb)
16519 + || au_test_ubifs(sb)
16523 +/* temporary support for i#1 in cramfs */
16524 +static inline int au_test_fs_unique_ino(struct inode *inode)
16526 + if (au_test_cramfs(inode->i_sb))
16527 + return inode->i_ino != 1;
16531 +/* ---------------------------------------------------------------------- */
16534 + * the filesystem where the xino files placed must support i/o after unlink and
16535 + * maintain i_size and i_blocks.
16537 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16539 + return au_test_fs_remote(sb)
16540 + || au_test_fs_bad_iattr_size(sb)
16541 + /* don't want unnecessary work for xino */
16542 + || au_test_aufs(sb)
16543 + || au_test_ecryptfs(sb)
16544 + || au_test_nilfs(sb);
16547 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16549 + return au_test_tmpfs(sb)
16550 + || au_test_ramfs(sb);
16554 + * test if the @sb is real-readonly.
16556 +static inline int au_test_fs_rr(struct super_block *sb)
16558 + return au_test_squashfs(sb)
16559 + || au_test_iso9660(sb)
16560 + || au_test_cramfs(sb)
16561 + || au_test_romfs(sb);
16565 + * test if the @inode is nfs with 'noacl' option
16566 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16568 +static inline int au_test_nfs_noacl(struct inode *inode)
16570 + return au_test_nfs(inode->i_sb)
16571 + /* && IS_POSIXACL(inode) */
16572 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16575 +#endif /* __KERNEL__ */
16576 +#endif /* __AUFS_FSTYPE_H__ */
16577 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16578 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16579 +++ linux/fs/aufs/hbl.h 2021-12-03 15:38:59.936647310 +0100
16581 +/* SPDX-License-Identifier: GPL-2.0 */
16583 + * Copyright (C) 2017-2021 Junjiro R. Okajima
16585 + * This program, aufs is free software; you can redistribute it and/or modify
16586 + * it under the terms of the GNU General Public License as published by
16587 + * the Free Software Foundation; either version 2 of the License, or
16588 + * (at your option) any later version.
16590 + * This program is distributed in the hope that it will be useful,
16591 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16592 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16593 + * GNU General Public License for more details.
16595 + * You should have received a copy of the GNU General Public License
16596 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16600 + * helpers for hlist_bl.h
16603 +#ifndef __AUFS_HBL_H__
16604 +#define __AUFS_HBL_H__
16608 +#include <linux/list_bl.h>
16610 +static inline void au_hbl_add(struct hlist_bl_node *node,
16611 + struct hlist_bl_head *hbl)
16613 + hlist_bl_lock(hbl);
16614 + hlist_bl_add_head(node, hbl);
16615 + hlist_bl_unlock(hbl);
16618 +static inline void au_hbl_del(struct hlist_bl_node *node,
16619 + struct hlist_bl_head *hbl)
16621 + hlist_bl_lock(hbl);
16622 + hlist_bl_del(node);
16623 + hlist_bl_unlock(hbl);
16626 +#define au_hbl_for_each(pos, head) \
16627 + for (pos = hlist_bl_first(head); \
16631 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16633 + unsigned long cnt;
16634 + struct hlist_bl_node *pos;
16637 + hlist_bl_lock(hbl);
16638 + au_hbl_for_each(pos, hbl)
16640 + hlist_bl_unlock(hbl);
16644 +#endif /* __KERNEL__ */
16645 +#endif /* __AUFS_HBL_H__ */
16646 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16647 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16648 +++ linux/fs/aufs/hfsnotify.c 2022-01-13 12:42:15.929566135 +0100
16650 +// SPDX-License-Identifier: GPL-2.0
16652 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16654 + * This program, aufs is free software; you can redistribute it and/or modify
16655 + * it under the terms of the GNU General Public License as published by
16656 + * the Free Software Foundation; either version 2 of the License, or
16657 + * (at your option) any later version.
16659 + * This program is distributed in the hope that it will be useful,
16660 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16661 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16662 + * GNU General Public License for more details.
16664 + * You should have received a copy of the GNU General Public License
16665 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16669 + * fsnotify for the lower directories
16674 +/* FS_IN_IGNORED is unnecessary */
16675 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16676 + | FS_CREATE | FS_EVENT_ON_CHILD);
16677 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16678 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16680 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16682 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16684 + /* AuDbg("here\n"); */
16685 + au_cache_free_hnotify(hn);
16686 + smp_mb__before_atomic(); /* for atomic64_dec */
16687 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16688 + wake_up(&au_hfsn_wq);
16691 +static int au_hfsn_alloc(struct au_hinode *hinode)
16694 + struct au_hnotify *hn;
16695 + struct super_block *sb;
16696 + struct au_branch *br;
16697 + struct fsnotify_mark *mark;
16698 + aufs_bindex_t bindex;
16700 + hn = hinode->hi_notify;
16701 + sb = hn->hn_aufs_inode->i_sb;
16702 + bindex = au_br_index(sb, hinode->hi_id);
16703 + br = au_sbr(sb, bindex);
16704 + AuDebugOn(!br->br_hfsn);
16706 + mark = &hn->hn_mark;
16707 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16708 + mark->mask = AuHfsnMask;
16710 + * by udba rename or rmdir, aufs assign a new inode to the known
16711 + * h_inode, so specify 1 to allow dups.
16714 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16720 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16722 + struct fsnotify_mark *mark;
16723 + unsigned long long ull;
16724 + struct fsnotify_group *group;
16726 + ull = atomic64_inc_return(&au_hfsn_ifree);
16729 + mark = &hn->hn_mark;
16730 + spin_lock(&mark->lock);
16731 + group = mark->group;
16732 + fsnotify_get_group(group);
16733 + spin_unlock(&mark->lock);
16735 + fsnotify_destroy_mark(mark, group);
16736 + fsnotify_put_mark(mark);
16737 + fsnotify_put_group(group);
16740 + /* free hn by myself */
16744 +/* ---------------------------------------------------------------------- */
16746 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16748 + struct fsnotify_mark *mark;
16750 + mark = &hinode->hi_notify->hn_mark;
16751 + spin_lock(&mark->lock);
16753 + AuDebugOn(mark->mask & AuHfsnMask);
16754 + mark->mask |= AuHfsnMask;
16756 + AuDebugOn(!(mark->mask & AuHfsnMask));
16757 + mark->mask &= ~AuHfsnMask;
16759 + spin_unlock(&mark->lock);
16760 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16763 +/* ---------------------------------------------------------------------- */
16765 +/* #define AuDbgHnotify */
16766 +#ifdef AuDbgHnotify
16767 +static char *au_hfsn_name(u32 mask)
16769 +#ifdef CONFIG_AUFS_DEBUG
16770 +#define test_ret(flag) \
16772 + if (mask & flag) \
16775 + test_ret(FS_ACCESS);
16776 + test_ret(FS_MODIFY);
16777 + test_ret(FS_ATTRIB);
16778 + test_ret(FS_CLOSE_WRITE);
16779 + test_ret(FS_CLOSE_NOWRITE);
16780 + test_ret(FS_OPEN);
16781 + test_ret(FS_MOVED_FROM);
16782 + test_ret(FS_MOVED_TO);
16783 + test_ret(FS_CREATE);
16784 + test_ret(FS_DELETE);
16785 + test_ret(FS_DELETE_SELF);
16786 + test_ret(FS_MOVE_SELF);
16787 + test_ret(FS_UNMOUNT);
16788 + test_ret(FS_Q_OVERFLOW);
16789 + test_ret(FS_IN_IGNORED);
16790 + test_ret(FS_ISDIR);
16791 + test_ret(FS_IN_ONESHOT);
16792 + test_ret(FS_EVENT_ON_CHILD);
16801 +/* ---------------------------------------------------------------------- */
16803 +static void au_hfsn_free_group(struct fsnotify_group *group)
16805 + struct au_br_hfsnotify *hfsn = group->private;
16807 + /* AuDbg("here\n"); */
16808 + au_kfree_try_rcu(hfsn);
16811 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16812 + u32 mask, const void *data, int data_type,
16813 + struct inode *dir,
16814 + const struct qstr *file_name, u32 cookie,
16815 + struct fsnotify_iter_info *iter_info)
16818 + struct au_hnotify *hnotify;
16819 + struct inode *h_dir, *h_inode;
16820 + struct fsnotify_mark *inode_mark;
16822 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
16823 + || data_type == FSNOTIFY_EVENT_DENTRY));
16826 + /* if FS_UNMOUNT happens, there must be another bug */
16827 + AuDebugOn(mask & FS_UNMOUNT);
16828 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16833 +#ifdef AuDbgHnotify
16835 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16836 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16837 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16838 + h_dir->i_ino, mask, au_hfsn_name(mask),
16839 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16840 + /* WARN_ON(1); */
16845 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16846 + AuDebugOn(!inode_mark);
16847 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16848 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16854 +static struct fsnotify_ops au_hfsn_ops = {
16855 + .handle_event = au_hfsn_handle_event,
16856 + .free_group_priv = au_hfsn_free_group,
16857 + .free_mark = au_hfsn_free_mark
16860 +/* ---------------------------------------------------------------------- */
16862 +static void au_hfsn_fin_br(struct au_branch *br)
16864 + struct au_br_hfsnotify *hfsn;
16866 + hfsn = br->br_hfsn;
16869 + fsnotify_put_group(hfsn->hfsn_group);
16874 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16877 + struct fsnotify_group *group;
16878 + struct au_br_hfsnotify *hfsn;
16881 + br->br_hfsn = NULL;
16882 + if (!au_br_hnotifyable(perm))
16886 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16887 + if (unlikely(!hfsn))
16891 + group = fsnotify_alloc_group(&au_hfsn_ops);
16892 + if (IS_ERR(group)) {
16893 + err = PTR_ERR(group);
16894 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16898 + group->private = hfsn;
16899 + hfsn->hfsn_group = group;
16900 + br->br_hfsn = hfsn;
16901 + goto out; /* success */
16904 + au_kfree_try_rcu(hfsn);
16909 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16914 + if (!br->br_hfsn)
16915 + err = au_hfsn_init_br(br, perm);
16920 +/* ---------------------------------------------------------------------- */
16922 +static void au_hfsn_fin(void)
16924 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16925 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16928 +const struct au_hnotify_op au_hnotify_op = {
16929 + .ctl = au_hfsn_ctl,
16930 + .alloc = au_hfsn_alloc,
16931 + .free = au_hfsn_free,
16933 + .fin = au_hfsn_fin,
16935 + .reset_br = au_hfsn_reset_br,
16936 + .fin_br = au_hfsn_fin_br,
16937 + .init_br = au_hfsn_init_br
16939 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16940 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16941 +++ linux/fs/aufs/hfsplus.c 2021-12-03 15:38:59.936647310 +0100
16943 +// SPDX-License-Identifier: GPL-2.0
16945 + * Copyright (C) 2010-2021 Junjiro R. Okajima
16947 + * This program, aufs is free software; you can redistribute it and/or modify
16948 + * it under the terms of the GNU General Public License as published by
16949 + * the Free Software Foundation; either version 2 of the License, or
16950 + * (at your option) any later version.
16952 + * This program is distributed in the hope that it will be useful,
16953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16955 + * GNU General Public License for more details.
16957 + * You should have received a copy of the GNU General Public License
16958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16962 + * special support for filesystems which acquires an inode mutex
16963 + * at final closing a file, eg, hfsplus.
16965 + * This trick is very simple and stupid, just to open the file before really
16966 + * necessary open to tell hfsplus that this is not the final closing.
16967 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16968 + * and au_h_open_post() after releasing it.
16973 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16976 + struct file *h_file;
16977 + struct dentry *h_dentry;
16979 + h_dentry = au_h_dptr(dentry, bindex);
16980 + AuDebugOn(!h_dentry);
16981 + AuDebugOn(d_is_negative(h_dentry));
16984 + if (au_test_hfsplus(h_dentry->d_sb)
16985 + && d_is_reg(h_dentry))
16986 + h_file = au_h_open(dentry, bindex,
16987 + O_RDONLY | O_NOATIME | O_LARGEFILE,
16988 + /*file*/NULL, force_wr);
16992 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
16993 + struct file *h_file)
16995 + struct au_branch *br;
16999 + br = au_sbr(dentry->d_sb, bindex);
17000 + au_lcnt_dec(&br->br_nfiles);
17003 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17004 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17005 +++ linux/fs/aufs/hnotify.c 2021-12-03 15:38:59.936647310 +0100
17007 +// SPDX-License-Identifier: GPL-2.0
17009 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17011 + * This program, aufs is free software; you can redistribute it and/or modify
17012 + * it under the terms of the GNU General Public License as published by
17013 + * the Free Software Foundation; either version 2 of the License, or
17014 + * (at your option) any later version.
17016 + * This program is distributed in the hope that it will be useful,
17017 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17018 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17019 + * GNU General Public License for more details.
17021 + * You should have received a copy of the GNU General Public License
17022 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17026 + * abstraction to notify the direct changes on lower directories
17029 +/* #include <linux/iversion.h> */
17032 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17035 + struct au_hnotify *hn;
17038 + hn = au_cache_alloc_hnotify();
17040 + hn->hn_aufs_inode = inode;
17041 + hinode->hi_notify = hn;
17042 + err = au_hnotify_op.alloc(hinode);
17044 + if (unlikely(err)) {
17045 + hinode->hi_notify = NULL;
17046 + au_cache_free_hnotify(hn);
17048 + * The upper dir was removed by udba, but the same named
17049 + * dir left. In this case, aufs assigns a new inode
17050 + * number and set the monitor again.
17051 + * For the lower dir, the old monitor is still left.
17053 + if (err == -EEXIST)
17062 +void au_hn_free(struct au_hinode *hinode)
17064 + struct au_hnotify *hn;
17066 + hn = hinode->hi_notify;
17068 + hinode->hi_notify = NULL;
17069 + if (au_hnotify_op.free(hinode, hn))
17070 + au_cache_free_hnotify(hn);
17074 +/* ---------------------------------------------------------------------- */
17076 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17078 + if (hinode->hi_notify)
17079 + au_hnotify_op.ctl(hinode, do_set);
17082 +void au_hn_reset(struct inode *inode, unsigned int flags)
17084 + aufs_bindex_t bindex, bbot;
17085 + struct inode *hi;
17086 + struct dentry *iwhdentry;
17088 + bbot = au_ibbot(inode);
17089 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17090 + hi = au_h_iptr(inode, bindex);
17094 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17095 + iwhdentry = au_hi_wh(inode, bindex);
17099 + au_set_h_iptr(inode, bindex, NULL, 0);
17100 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17101 + flags & ~AuHi_XINO);
17104 + /* inode_unlock(hi); */
17108 +/* ---------------------------------------------------------------------- */
17110 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17113 + aufs_bindex_t bindex, bbot, bfound, btop;
17114 + struct inode *h_i;
17117 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17118 + pr_warn("branch root dir was changed\n");
17123 + bbot = au_ibbot(inode);
17124 + btop = au_ibtop(inode);
17125 +#if 0 /* reserved for future use */
17126 + if (bindex == bbot) {
17127 + /* keep this ino in rename case */
17131 + for (bindex = btop; bindex <= bbot; bindex++)
17132 + if (au_h_iptr(inode, bindex) == h_inode) {
17139 + for (bindex = btop; bindex <= bbot; bindex++) {
17140 + h_i = au_h_iptr(inode, bindex);
17144 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17145 + /* ignore this error */
17146 + /* bad action? */
17149 + /* children inode number will be broken */
17156 +static int hn_gen_tree(struct dentry *dentry)
17158 + int err, i, j, ndentry;
17159 + struct au_dcsub_pages dpages;
17160 + struct au_dpage *dpage;
17161 + struct dentry **dentries;
17163 + err = au_dpages_init(&dpages, GFP_NOFS);
17164 + if (unlikely(err))
17166 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17167 + if (unlikely(err))
17170 + for (i = 0; i < dpages.ndpage; i++) {
17171 + dpage = dpages.dpages + i;
17172 + dentries = dpage->dentries;
17173 + ndentry = dpage->ndentry;
17174 + for (j = 0; j < ndentry; j++) {
17175 + struct dentry *d;
17182 + if (d_really_is_positive(d))
17183 + /* todo: reset children xino?
17184 + cached children only? */
17185 + au_iigen_dec(d_inode(d));
17190 + au_dpages_free(&dpages);
17196 + * return 0 if processed.
17198 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17199 + const unsigned int isdir)
17202 + struct dentry *d;
17203 + struct qstr *dname;
17206 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17207 + pr_warn("branch root dir was changed\n");
17213 + AuDebugOn(!name);
17214 + au_iigen_dec(inode);
17215 + spin_lock(&inode->i_lock);
17216 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17217 + spin_lock(&d->d_lock);
17218 + dname = &d->d_name;
17219 + if (dname->len != nlen
17220 + && memcmp(dname->name, name, nlen)) {
17221 + spin_unlock(&d->d_lock);
17226 + spin_unlock(&d->d_lock);
17229 + spin_unlock(&inode->i_lock);
17231 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17232 + d = d_find_any_alias(inode);
17234 + au_iigen_dec(inode);
17238 + spin_lock(&d->d_lock);
17239 + dname = &d->d_name;
17240 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17241 + spin_unlock(&d->d_lock);
17242 + err = hn_gen_tree(d);
17243 + spin_lock(&d->d_lock);
17245 + spin_unlock(&d->d_lock);
17254 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17258 + if (IS_ROOT(dentry)) {
17259 + pr_warn("branch root dir was changed\n");
17265 + au_digen_dec(dentry);
17266 + if (d_really_is_positive(dentry))
17267 + au_iigen_dec(d_inode(dentry));
17269 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17270 + if (d_really_is_positive(dentry))
17271 + err = hn_gen_tree(dentry);
17278 +/* ---------------------------------------------------------------------- */
17280 +/* hnotify job flags */
17281 +#define AuHnJob_XINO0 1
17282 +#define AuHnJob_GEN (1 << 1)
17283 +#define AuHnJob_DIRENT (1 << 2)
17284 +#define AuHnJob_ISDIR (1 << 3)
17285 +#define AuHnJob_TRYXINO0 (1 << 4)
17286 +#define AuHnJob_MNTPNT (1 << 5)
17287 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17288 +#define au_fset_hnjob(flags, name) \
17289 + do { (flags) |= AuHnJob_##name; } while (0)
17290 +#define au_fclr_hnjob(flags, name) \
17291 + do { (flags) &= ~AuHnJob_##name; } while (0)
17299 +struct au_hnotify_args {
17300 + struct inode *h_dir, *dir, *h_child_inode;
17302 + unsigned int flags[AuHnLast];
17303 + unsigned int h_child_nlen;
17304 + char h_child_name[];
17307 +struct hn_job_args {
17308 + unsigned int flags;
17309 + struct inode *inode, *h_inode, *dir, *h_dir;
17310 + struct dentry *dentry;
17315 +static int hn_job(struct hn_job_args *a)
17317 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17321 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17322 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17324 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17327 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17328 + if (!a->h_inode->i_nlink
17329 + && !(a->h_inode->i_state & I_LINKABLE))
17330 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17331 + inode_unlock_shared(a->h_inode);
17334 + /* make the generation obsolete */
17335 + if (au_ftest_hnjob(a->flags, GEN)) {
17338 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17340 + if (e && a->dentry)
17341 + hn_gen_by_name(a->dentry, isdir);
17342 + /* ignore this error */
17345 + /* make dir entries obsolete */
17346 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17347 + struct au_vdir *vdir;
17349 + vdir = au_ivdir(a->inode);
17351 + vdir->vd_jiffy = 0;
17352 + /* IMustLock(a->inode); */
17353 + /* inode_inc_iversion(a->inode); */
17356 + /* can do nothing but warn */
17357 + if (au_ftest_hnjob(a->flags, MNTPNT)
17359 + && d_mountpoint(a->dentry))
17360 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17365 +/* ---------------------------------------------------------------------- */
17367 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17368 + struct inode *dir)
17370 + struct dentry *dentry, *d, *parent;
17371 + struct qstr *dname;
17373 + parent = d_find_any_alias(dir);
17378 + spin_lock(&parent->d_lock);
17379 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17380 + /* AuDbg("%pd\n", d); */
17381 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17382 + dname = &d->d_name;
17383 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17384 + goto cont_unlock;
17388 + goto cont_unlock;
17389 + if (au_dcount(d) > 0) {
17390 + dentry = dget_dlock(d);
17391 + spin_unlock(&d->d_lock);
17396 + spin_unlock(&d->d_lock);
17398 + spin_unlock(&parent->d_lock);
17402 + di_write_lock_child(dentry);
17407 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17408 + aufs_bindex_t bindex, ino_t h_ino)
17410 + struct inode *inode;
17415 + err = au_xino_read(sb, bindex, h_ino, &ino);
17417 + inode = ilookup(sb, ino);
17421 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17422 + pr_warn("wrong root branch\n");
17428 + ii_write_lock_child(inode);
17434 +static void au_hn_bh(void *_args)
17436 + struct au_hnotify_args *a = _args;
17437 + struct super_block *sb;
17438 + aufs_bindex_t bindex, bbot, bfound;
17439 + unsigned char xino, try_iput;
17441 + struct inode *inode;
17443 + struct hn_job_args args;
17444 + struct dentry *dentry;
17445 + struct au_sbinfo *sbinfo;
17447 + AuDebugOn(!_args);
17448 + AuDebugOn(!a->h_dir);
17449 + AuDebugOn(!a->dir);
17450 + AuDebugOn(!a->mask);
17451 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17452 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17453 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17458 + * do not lock a->dir->i_mutex here
17459 + * because of d_revalidate() may cause a deadlock.
17461 + sb = a->dir->i_sb;
17463 + sbinfo = au_sbi(sb);
17464 + AuDebugOn(!sbinfo);
17465 + si_write_lock(sb, AuLock_NOPLMW);
17467 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17468 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17469 + case FS_MOVED_FROM:
17470 + case FS_MOVED_TO:
17471 + AuWarn1("DIRREN with UDBA may not work correctly "
17472 + "for the direct rename(2)\n");
17475 + ii_read_lock_parent(a->dir);
17477 + bbot = au_ibbot(a->dir);
17478 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17479 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17483 + ii_read_unlock(a->dir);
17484 + if (unlikely(bfound < 0))
17487 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17489 + if (a->h_child_inode)
17490 + h_ino = a->h_child_inode->i_ino;
17492 + if (a->h_child_nlen
17493 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17494 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17495 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17498 + if (dentry && d_really_is_positive(dentry))
17499 + inode = d_inode(dentry);
17500 + if (xino && !inode && h_ino
17501 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17502 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17503 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17504 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17508 + args.flags = a->flags[AuHn_CHILD];
17509 + args.dentry = dentry;
17510 + args.inode = inode;
17511 + args.h_inode = a->h_child_inode;
17512 + args.dir = a->dir;
17513 + args.h_dir = a->h_dir;
17514 + args.h_name = a->h_child_name;
17515 + args.h_nlen = a->h_child_nlen;
17516 + err = hn_job(&args);
17518 + if (au_di(dentry))
17519 + di_write_unlock(dentry);
17522 + if (inode && try_iput) {
17523 + ii_write_unlock(inode);
17527 + ii_write_lock_parent(a->dir);
17528 + args.flags = a->flags[AuHn_PARENT];
17529 + args.dentry = NULL;
17530 + args.inode = a->dir;
17531 + args.h_inode = a->h_dir;
17533 + args.h_dir = NULL;
17534 + args.h_name = NULL;
17536 + err = hn_job(&args);
17537 + ii_write_unlock(a->dir);
17540 + iput(a->h_child_inode);
17543 + si_write_unlock(sb);
17544 + au_nwt_done(&sbinfo->si_nowait);
17548 +/* ---------------------------------------------------------------------- */
17550 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17551 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17554 + unsigned int flags[AuHnLast], f;
17555 + unsigned char isdir, isroot, wh;
17556 + struct inode *dir;
17557 + struct au_hnotify_args *args;
17558 + char *p, *h_child_name;
17561 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17562 + dir = igrab(hnotify->hn_aufs_inode);
17566 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17568 + h_child_name = (void *)h_child_qstr->name;
17569 + len = h_child_qstr->len;
17570 + if (h_child_name) {
17571 + if (len > AUFS_WH_PFX_LEN
17572 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17573 + h_child_name += AUFS_WH_PFX_LEN;
17574 + len -= AUFS_WH_PFX_LEN;
17580 + if (h_child_inode)
17581 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17582 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17583 + flags[AuHn_CHILD] = 0;
17585 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17586 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17587 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17588 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17589 + case FS_MOVED_FROM:
17590 + case FS_MOVED_TO:
17591 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17592 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17595 + AuDebugOn(!h_child_name);
17600 + * aufs never be able to get this child inode.
17601 + * revalidation should be in d_revalidate()
17602 + * by checking i_nlink, i_generation or d_unhashed().
17604 + AuDebugOn(!h_child_name);
17605 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17606 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17614 + h_child_inode = NULL;
17617 + /* iput() and kfree() will be called in au_hnotify() */
17618 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17619 + if (unlikely(!args)) {
17620 + AuErr1("no memory\n");
17624 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17625 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17626 + args->mask = mask;
17628 + args->h_dir = igrab(h_dir);
17629 + if (h_child_inode)
17630 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17631 + args->h_child_inode = h_child_inode;
17632 + args->h_child_nlen = len;
17634 + p = (void *)args;
17635 + p += sizeof(*args);
17636 + memcpy(p, h_child_name, len);
17640 + /* NFS fires the event for silly-renamed one from kworker */
17642 + if (!dir->i_nlink
17643 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17645 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17646 + if (unlikely(err)) {
17647 + pr_err("wkq %d\n", err);
17648 + iput(args->h_child_inode);
17649 + iput(args->h_dir);
17651 + au_kfree_rcu(args);
17658 +/* ---------------------------------------------------------------------- */
17660 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17664 + AuDebugOn(!(udba & AuOptMask_UDBA));
17667 + if (au_hnotify_op.reset_br)
17668 + err = au_hnotify_op.reset_br(udba, br, perm);
17673 +int au_hnotify_init_br(struct au_branch *br, int perm)
17678 + if (au_hnotify_op.init_br)
17679 + err = au_hnotify_op.init_br(br, perm);
17684 +void au_hnotify_fin_br(struct au_branch *br)
17686 + if (au_hnotify_op.fin_br)
17687 + au_hnotify_op.fin_br(br);
17690 +static void au_hn_destroy_cache(void)
17692 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17693 + au_cache[AuCache_HNOTIFY] = NULL;
17696 +int __init au_hnotify_init(void)
17701 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17702 + if (au_cache[AuCache_HNOTIFY]) {
17704 + if (au_hnotify_op.init)
17705 + err = au_hnotify_op.init();
17706 + if (unlikely(err))
17707 + au_hn_destroy_cache();
17713 +void au_hnotify_fin(void)
17715 + if (au_hnotify_op.fin)
17716 + au_hnotify_op.fin();
17718 + /* cf. au_cache_fin() */
17719 + if (au_cache[AuCache_HNOTIFY])
17720 + au_hn_destroy_cache();
17722 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17723 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17724 +++ linux/fs/aufs/iinfo.c 2021-12-03 15:38:59.936647310 +0100
17726 +// SPDX-License-Identifier: GPL-2.0
17728 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17730 + * This program, aufs is free software; you can redistribute it and/or modify
17731 + * it under the terms of the GNU General Public License as published by
17732 + * the Free Software Foundation; either version 2 of the License, or
17733 + * (at your option) any later version.
17735 + * This program is distributed in the hope that it will be useful,
17736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17738 + * GNU General Public License for more details.
17740 + * You should have received a copy of the GNU General Public License
17741 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17745 + * inode private data
17750 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17752 + struct inode *h_inode;
17753 + struct au_hinode *hinode;
17755 + IiMustAnyLock(inode);
17757 + hinode = au_hinode(au_ii(inode), bindex);
17758 + h_inode = hinode->hi_inode;
17759 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17763 +/* todo: hard/soft set? */
17764 +void au_hiput(struct au_hinode *hinode)
17766 + au_hn_free(hinode);
17767 + dput(hinode->hi_whdentry);
17768 + iput(hinode->hi_inode);
17771 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17773 + unsigned int flags;
17774 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17777 + if (au_opt_test(mnt_flags, XINO))
17778 + au_fset_hi(flags, XINO);
17779 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17780 + au_fset_hi(flags, HNOTIFY);
17784 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17785 + struct inode *h_inode, unsigned int flags)
17787 + struct au_hinode *hinode;
17788 + struct inode *hi;
17789 + struct au_iinfo *iinfo = au_ii(inode);
17791 + IiMustWriteLock(inode);
17793 + hinode = au_hinode(iinfo, bindex);
17794 + hi = hinode->hi_inode;
17795 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17798 + au_hiput(hinode);
17799 + hinode->hi_inode = h_inode;
17802 + struct super_block *sb = inode->i_sb;
17803 + struct au_branch *br;
17805 + AuDebugOn(inode->i_mode
17806 + && (h_inode->i_mode & S_IFMT)
17807 + != (inode->i_mode & S_IFMT));
17808 + if (bindex == iinfo->ii_btop)
17809 + au_cpup_igen(inode, h_inode);
17810 + br = au_sbr(sb, bindex);
17811 + hinode->hi_id = br->br_id;
17812 + if (au_ftest_hi(flags, XINO)) {
17813 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17815 + if (unlikely(err))
17816 + AuIOErr1("failed au_xino_write() %d\n", err);
17819 + if (au_ftest_hi(flags, HNOTIFY)
17820 + && au_br_hnotifyable(br->br_perm)) {
17821 + err = au_hn_alloc(hinode, inode);
17822 + if (unlikely(err))
17823 + AuIOErr1("au_hn_alloc() %d\n", err);
17828 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17829 + struct dentry *h_wh)
17831 + struct au_hinode *hinode;
17833 + IiMustWriteLock(inode);
17835 + hinode = au_hinode(au_ii(inode), bindex);
17836 + AuDebugOn(hinode->hi_whdentry);
17837 + hinode->hi_whdentry = h_wh;
17840 +void au_update_iigen(struct inode *inode, int half)
17842 + struct au_iinfo *iinfo;
17843 + struct au_iigen *iigen;
17844 + unsigned int sigen;
17846 + sigen = au_sigen(inode->i_sb);
17847 + iinfo = au_ii(inode);
17848 + iigen = &iinfo->ii_generation;
17849 + spin_lock(&iigen->ig_spin);
17850 + iigen->ig_generation = sigen;
17852 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17854 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17855 + spin_unlock(&iigen->ig_spin);
17858 +/* it may be called at remount time, too */
17859 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17861 + struct au_iinfo *iinfo;
17862 + aufs_bindex_t bindex, bbot;
17864 + AuDebugOn(au_is_bad_inode(inode));
17865 + IiMustWriteLock(inode);
17867 + iinfo = au_ii(inode);
17868 + if (do_put_zero && iinfo->ii_btop >= 0) {
17869 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17871 + struct inode *h_i;
17873 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17876 + && !(h_i->i_state & I_LINKABLE))
17877 + au_set_h_iptr(inode, bindex, NULL, 0);
17881 + iinfo->ii_btop = -1;
17882 + iinfo->ii_bbot = -1;
17883 + bbot = au_sbbot(inode->i_sb);
17884 + for (bindex = 0; bindex <= bbot; bindex++)
17885 + if (au_hinode(iinfo, bindex)->hi_inode) {
17886 + iinfo->ii_btop = bindex;
17889 + if (iinfo->ii_btop >= 0)
17890 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17891 + if (au_hinode(iinfo, bindex)->hi_inode) {
17892 + iinfo->ii_bbot = bindex;
17895 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17898 +/* ---------------------------------------------------------------------- */
17900 +void au_icntnr_init_once(void *_c)
17902 + struct au_icntnr *c = _c;
17903 + struct au_iinfo *iinfo = &c->iinfo;
17905 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17906 + au_rw_init(&iinfo->ii_rwsem);
17907 + inode_init_once(&c->vfs_inode);
17910 +void au_hinode_init(struct au_hinode *hinode)
17912 + hinode->hi_inode = NULL;
17913 + hinode->hi_id = -1;
17914 + au_hn_init(hinode);
17915 + hinode->hi_whdentry = NULL;
17918 +int au_iinfo_init(struct inode *inode)
17920 + struct au_iinfo *iinfo;
17921 + struct super_block *sb;
17922 + struct au_hinode *hi;
17925 + sb = inode->i_sb;
17926 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17927 + nbr = au_sbbot(sb) + 1;
17928 + if (unlikely(nbr <= 0))
17930 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17932 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17934 + iinfo->ii_hinode = hi;
17935 + for (i = 0; i < nbr; i++, hi++)
17936 + au_hinode_init(hi);
17938 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17939 + iinfo->ii_btop = -1;
17940 + iinfo->ii_bbot = -1;
17941 + iinfo->ii_vdir = NULL;
17947 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17950 + struct au_hinode *hip;
17952 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17955 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17958 + iinfo->ii_hinode = hip;
17959 + i = iinfo->ii_bbot + 1;
17961 + for (; i < nbr; i++, hip++)
17962 + au_hinode_init(hip);
17969 +void au_iinfo_fin(struct inode *inode)
17971 + struct au_iinfo *iinfo;
17972 + struct au_hinode *hi;
17973 + struct super_block *sb;
17974 + aufs_bindex_t bindex, bbot;
17975 + const unsigned char unlinked = !inode->i_nlink;
17977 + AuDebugOn(au_is_bad_inode(inode));
17979 + sb = inode->i_sb;
17980 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
17981 + if (si_pid_test(sb))
17982 + au_xino_delete_inode(inode, unlinked);
17985 + * it is safe to hide the dependency between sbinfo and
17989 + si_noflush_read_lock(sb);
17990 + au_xino_delete_inode(inode, unlinked);
17991 + si_read_unlock(sb);
17995 + iinfo = au_ii(inode);
17996 + if (iinfo->ii_vdir)
17997 + au_vdir_free(iinfo->ii_vdir);
17999 + bindex = iinfo->ii_btop;
18000 + if (bindex >= 0) {
18001 + hi = au_hinode(iinfo, bindex);
18002 + bbot = iinfo->ii_bbot;
18003 + while (bindex++ <= bbot) {
18004 + if (hi->hi_inode)
18009 + au_kfree_rcu(iinfo->ii_hinode);
18010 + AuRwDestroy(&iinfo->ii_rwsem);
18012 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18013 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18014 +++ linux/fs/aufs/inode.c 2021-12-03 15:40:58.236647297 +0100
18016 +// SPDX-License-Identifier: GPL-2.0
18018 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18020 + * This program, aufs is free software; you can redistribute it and/or modify
18021 + * it under the terms of the GNU General Public License as published by
18022 + * the Free Software Foundation; either version 2 of the License, or
18023 + * (at your option) any later version.
18025 + * This program is distributed in the hope that it will be useful,
18026 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18027 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18028 + * GNU General Public License for more details.
18030 + * You should have received a copy of the GNU General Public License
18031 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18035 + * inode functions
18038 +#include <linux/iversion.h>
18041 +struct inode *au_igrab(struct inode *inode)
18044 + AuDebugOn(!atomic_read(&inode->i_count));
18050 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18052 + au_cpup_attr_all(inode, /*force*/0);
18053 + au_update_iigen(inode, /*half*/1);
18055 + inode_inc_iversion(inode);
18058 +static int au_ii_refresh(struct inode *inode, int *update)
18062 + aufs_bindex_t bindex, new_bindex;
18063 + struct super_block *sb;
18064 + struct au_iinfo *iinfo;
18065 + struct au_hinode *p, *q, tmp;
18067 + AuDebugOn(au_is_bad_inode(inode));
18068 + IiMustWriteLock(inode);
18071 + sb = inode->i_sb;
18072 + nbr = au_sbbot(sb) + 1;
18073 + type = inode->i_mode & S_IFMT;
18074 + iinfo = au_ii(inode);
18075 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18076 + if (unlikely(err))
18079 + AuDebugOn(iinfo->ii_btop < 0);
18080 + p = au_hinode(iinfo, iinfo->ii_btop);
18081 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18083 + if (!p->hi_inode)
18086 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18087 + new_bindex = au_br_index(sb, p->hi_id);
18088 + if (new_bindex == bindex)
18091 + if (new_bindex < 0) {
18094 + p->hi_inode = NULL;
18098 + if (new_bindex < iinfo->ii_btop)
18099 + iinfo->ii_btop = new_bindex;
18100 + if (iinfo->ii_bbot < new_bindex)
18101 + iinfo->ii_bbot = new_bindex;
18102 + /* swap two lower inode, and loop again */
18103 + q = au_hinode(iinfo, new_bindex);
18107 + if (tmp.hi_inode) {
18112 + au_update_ibrange(inode, /*do_put_zero*/0);
18113 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18114 + e = au_dy_irefresh(inode);
18115 + if (unlikely(e && !err))
18123 +void au_refresh_iop(struct inode *inode, int force_getattr)
18126 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18127 + const struct inode_operations *iop
18128 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18130 + if (inode->i_op == iop)
18133 + switch (inode->i_mode & S_IFMT) {
18135 + type = AuIop_DIR;
18138 + type = AuIop_SYMLINK;
18141 + type = AuIop_OTHER;
18145 + inode->i_op = iop + type;
18146 + /* unnecessary smp_wmb() */
18149 +int au_refresh_hinode_self(struct inode *inode)
18153 + err = au_ii_refresh(inode, &update);
18155 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18161 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18163 + int err, e, update;
18164 + unsigned int flags;
18166 + aufs_bindex_t bindex, bbot;
18167 + unsigned char isdir;
18168 + struct au_hinode *p;
18169 + struct au_iinfo *iinfo;
18171 + err = au_ii_refresh(inode, &update);
18172 + if (unlikely(err))
18176 + iinfo = au_ii(inode);
18177 + p = au_hinode(iinfo, iinfo->ii_btop);
18178 + mode = (inode->i_mode & S_IFMT);
18179 + isdir = S_ISDIR(mode);
18180 + flags = au_hi_flags(inode, isdir);
18181 + bbot = au_dbbot(dentry);
18182 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18183 + struct inode *h_i, *h_inode;
18184 + struct dentry *h_d;
18186 + h_d = au_h_dptr(dentry, bindex);
18187 + if (!h_d || d_is_negative(h_d))
18190 + h_inode = d_inode(h_d);
18191 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18192 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18193 + h_i = au_h_iptr(inode, bindex);
18195 + if (h_i == h_inode)
18201 + if (bindex < iinfo->ii_btop)
18202 + iinfo->ii_btop = bindex;
18203 + if (iinfo->ii_bbot < bindex)
18204 + iinfo->ii_bbot = bindex;
18205 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18208 + au_update_ibrange(inode, /*do_put_zero*/0);
18209 + e = au_dy_irefresh(inode);
18210 + if (unlikely(e && !err))
18213 + au_refresh_hinode_attr(inode, update && isdir);
18220 +static int set_inode(struct inode *inode, struct dentry *dentry)
18223 + unsigned int flags;
18225 + aufs_bindex_t bindex, btop, btail;
18226 + unsigned char isdir;
18227 + struct dentry *h_dentry;
18228 + struct inode *h_inode;
18229 + struct au_iinfo *iinfo;
18230 + const struct inode_operations *iop;
18232 + IiMustWriteLock(inode);
18236 + iop = au_sbi(inode->i_sb)->si_iop_array;
18237 + btop = au_dbtop(dentry);
18238 + h_dentry = au_h_dptr(dentry, btop);
18239 + h_inode = d_inode(h_dentry);
18240 + mode = h_inode->i_mode;
18241 + switch (mode & S_IFMT) {
18243 + btail = au_dbtail(dentry);
18244 + inode->i_op = iop + AuIop_OTHER;
18245 + inode->i_fop = &aufs_file_fop;
18246 + err = au_dy_iaop(inode, btop, h_inode);
18247 + if (unlikely(err))
18252 + btail = au_dbtaildir(dentry);
18253 + inode->i_op = iop + AuIop_DIR;
18254 + inode->i_fop = &aufs_dir_fop;
18257 + btail = au_dbtail(dentry);
18258 + inode->i_op = iop + AuIop_SYMLINK;
18264 + btail = au_dbtail(dentry);
18265 + inode->i_op = iop + AuIop_OTHER;
18266 + init_special_inode(inode, mode, h_inode->i_rdev);
18269 + AuIOErr("Unknown file type 0%o\n", mode);
18274 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18275 + flags = au_hi_flags(inode, isdir);
18276 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18277 + && au_ftest_hi(flags, HNOTIFY)
18278 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18279 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18280 + au_fclr_hi(flags, HNOTIFY);
18281 + iinfo = au_ii(inode);
18282 + iinfo->ii_btop = btop;
18283 + iinfo->ii_bbot = btail;
18284 + for (bindex = btop; bindex <= btail; bindex++) {
18285 + h_dentry = au_h_dptr(dentry, bindex);
18287 + au_set_h_iptr(inode, bindex,
18288 + au_igrab(d_inode(h_dentry)), flags);
18290 + au_cpup_attr_all(inode, /*force*/1);
18292 + * to force calling aufs_get_acl() every time,
18293 + * do not call cache_no_acl() for aufs inode.
18301 + * successful returns with iinfo write_locked
18303 + * zero: success, matched
18304 + * plus: no error, but unmatched
18306 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18309 + unsigned int gen, igflags;
18310 + aufs_bindex_t bindex, bbot;
18311 + struct inode *h_inode, *h_dinode;
18312 + struct dentry *h_dentry;
18315 + * before this function, if aufs got any iinfo lock, it must be only
18316 + * one, the parent dir.
18317 + * it can happen by UDBA and the obsoleted inode number.
18320 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18324 + ii_write_lock_new_child(inode);
18325 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18326 + h_dinode = d_inode(h_dentry);
18327 + bbot = au_ibbot(inode);
18328 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18329 + h_inode = au_h_iptr(inode, bindex);
18330 + if (!h_inode || h_inode != h_dinode)
18334 + gen = au_iigen(inode, &igflags);
18335 + if (gen == au_digen(dentry)
18336 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18339 + /* fully refresh inode using dentry */
18340 + err = au_refresh_hinode(inode, dentry);
18342 + au_update_iigen(inode, /*half*/0);
18346 + if (unlikely(err))
18347 + ii_write_unlock(inode);
18352 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18353 + unsigned int d_type, ino_t *ino)
18356 + const int isnondir = d_type != DT_DIR;
18358 + /* prevent hardlinked inode number from race condition */
18360 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18361 + if (unlikely(err))
18365 + err = au_xino_read(sb, bindex, h_ino, ino);
18366 + if (unlikely(err))
18367 + goto out_xinondir;
18371 + *ino = au_xino_new_ino(sb);
18372 + if (unlikely(!*ino))
18373 + goto out_xinondir;
18374 + err = au_xino_write(sb, bindex, h_ino, *ino);
18375 + if (unlikely(err))
18376 + goto out_xinondir;
18380 + if (isnondir && idx >= 0)
18381 + au_xinondir_leave(sb, bindex, h_ino, idx);
18386 +/* successful returns with iinfo write_locked */
18387 +/* todo: return with unlocked? */
18388 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18390 + struct inode *inode, *h_inode;
18391 + struct dentry *h_dentry;
18392 + struct super_block *sb;
18393 + ino_t h_ino, ino;
18394 + int err, idx, hlinked;
18395 + aufs_bindex_t btop;
18397 + sb = dentry->d_sb;
18398 + btop = au_dbtop(dentry);
18399 + h_dentry = au_h_dptr(dentry, btop);
18400 + h_inode = d_inode(h_dentry);
18401 + h_ino = h_inode->i_ino;
18402 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18406 + * stop 'race'-ing between hardlinks under different
18410 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18411 + inode = ERR_PTR(err);
18412 + if (unlikely(err))
18416 + err = au_xino_read(sb, btop, h_ino, &ino);
18417 + inode = ERR_PTR(err);
18418 + if (unlikely(err))
18419 + goto out_xinondir;
18422 + ino = au_xino_new_ino(sb);
18423 + if (unlikely(!ino)) {
18424 + inode = ERR_PTR(-EIO);
18425 + goto out_xinondir;
18429 + AuDbg("i%lu\n", (unsigned long)ino);
18430 + inode = au_iget_locked(sb, ino);
18431 + err = PTR_ERR(inode);
18432 + if (IS_ERR(inode))
18433 + goto out_xinondir;
18435 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18436 + if (inode->i_state & I_NEW) {
18437 + ii_write_lock_new_child(inode);
18438 + err = set_inode(inode, dentry);
18440 + unlock_new_inode(inode);
18441 + goto out_xinondir; /* success */
18445 + * iget_failed() calls iput(), but we need to call
18446 + * ii_write_unlock() after iget_failed(). so dirty hack for
18449 + atomic_inc(&inode->i_count);
18450 + iget_failed(inode);
18451 + ii_write_unlock(inode);
18452 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18453 + /* ignore this error */
18455 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18457 + * horrible race condition between lookup, readdir and copyup
18458 + * (or something).
18460 + if (hlinked && idx >= 0)
18461 + au_xinondir_leave(sb, btop, h_ino, idx);
18462 + err = reval_inode(inode, dentry);
18463 + if (unlikely(err < 0)) {
18468 + goto out; /* success */
18469 + else if (hlinked && idx >= 0) {
18470 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18471 + if (unlikely(err)) {
18473 + inode = ERR_PTR(err);
18479 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18480 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18481 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18482 + btop, au_sbtype(h_dentry->d_sb), dentry,
18483 + (unsigned long)h_ino, (unsigned long)ino);
18485 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18488 + if (hlinked && idx >= 0)
18489 + au_xinondir_leave(sb, btop, h_ino, idx);
18495 + inode = ERR_PTR(err);
18497 + if (hlinked && idx >= 0)
18498 + au_xinondir_leave(sb, btop, h_ino, idx);
18503 +/* ---------------------------------------------------------------------- */
18505 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18506 + struct inode *inode)
18509 + struct inode *hi;
18511 + err = au_br_rdonly(au_sbr(sb, bindex));
18513 + /* pseudo-link after flushed may happen out of bounds */
18516 + && au_ibtop(inode) <= bindex
18517 + && bindex <= au_ibbot(inode)) {
18519 + * permission check is unnecessary since vfsub routine
18520 + * will be called later
18522 + hi = au_h_iptr(inode, bindex);
18524 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18530 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18533 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18535 + return inode_permission(h_userns, h_inode, mask);
18538 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18541 + if (au_test_nfs(h_inode->i_sb)
18542 + && (mask & MAY_WRITE)
18543 + && S_ISDIR(h_inode->i_mode))
18544 + mask |= MAY_READ; /* force permission check */
18545 + return au_test_h_perm(h_userns, h_inode, mask);
18547 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18548 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18549 +++ linux/fs/aufs/inode.h 2021-12-03 15:40:58.236647297 +0100
18551 +/* SPDX-License-Identifier: GPL-2.0 */
18553 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18555 + * This program, aufs is free software; you can redistribute it and/or modify
18556 + * it under the terms of the GNU General Public License as published by
18557 + * the Free Software Foundation; either version 2 of the License, or
18558 + * (at your option) any later version.
18560 + * This program is distributed in the hope that it will be useful,
18561 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18562 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18563 + * GNU General Public License for more details.
18565 + * You should have received a copy of the GNU General Public License
18566 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18570 + * inode operations
18573 +#ifndef __AUFS_INODE_H__
18574 +#define __AUFS_INODE_H__
18578 +#include <linux/fsnotify.h>
18579 +#include "rwsem.h"
18583 +struct au_hnotify {
18584 +#ifdef CONFIG_AUFS_HNOTIFY
18585 +#ifdef CONFIG_AUFS_HFSNOTIFY
18586 + /* never use fsnotify_add_vfsmount_mark() */
18587 + struct fsnotify_mark hn_mark;
18589 + struct inode *hn_aufs_inode; /* no get/put */
18590 + struct rcu_head rcu;
18592 +} ____cacheline_aligned_in_smp;
18594 +struct au_hinode {
18595 + struct inode *hi_inode;
18596 + aufs_bindex_t hi_id;
18597 +#ifdef CONFIG_AUFS_HNOTIFY
18598 + struct au_hnotify *hi_notify;
18601 + /* reference to the copied-up whiteout with get/put */
18602 + struct dentry *hi_whdentry;
18606 +#define AuIG_HALF_REFRESHED 1
18607 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18608 +#define au_ig_fset(flags, name) \
18609 + do { (flags) |= AuIG_##name; } while (0)
18610 +#define au_ig_fclr(flags, name) \
18611 + do { (flags) &= ~AuIG_##name; } while (0)
18614 + spinlock_t ig_spin;
18615 + __u32 ig_generation, ig_flags;
18620 + struct au_iigen ii_generation;
18621 + struct super_block *ii_hsb1; /* no get/put */
18623 + struct au_rwsem ii_rwsem;
18624 + aufs_bindex_t ii_btop, ii_bbot;
18626 + struct au_hinode *ii_hinode;
18627 + struct au_vdir *ii_vdir;
18630 +struct au_icntnr {
18631 + struct au_iinfo iinfo;
18632 + struct inode vfs_inode;
18633 + struct hlist_bl_node plink;
18634 + struct rcu_head rcu;
18635 +} ____cacheline_aligned_in_smp;
18637 +/* au_pin flags */
18638 +#define AuPin_DI_LOCKED 1
18639 +#define AuPin_MNT_WRITE (1 << 1)
18640 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18641 +#define au_fset_pin(flags, name) \
18642 + do { (flags) |= AuPin_##name; } while (0)
18643 +#define au_fclr_pin(flags, name) \
18644 + do { (flags) &= ~AuPin_##name; } while (0)
18648 + struct dentry *dentry;
18649 + unsigned int udba;
18650 + unsigned char lsc_di, lsc_hi, flags;
18651 + aufs_bindex_t bindex;
18654 + struct dentry *parent;
18655 + struct au_hinode *hdir;
18656 + struct vfsmount *h_mnt;
18658 + /* temporary unlock/relock for copyup */
18659 + struct dentry *h_dentry, *h_parent;
18660 + struct au_branch *br;
18661 + struct task_struct *task;
18664 +void au_pin_hdir_unlock(struct au_pin *p);
18665 +int au_pin_hdir_lock(struct au_pin *p);
18666 +int au_pin_hdir_relock(struct au_pin *p);
18667 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18668 +void au_pin_hdir_release(struct au_pin *p);
18670 +/* ---------------------------------------------------------------------- */
18672 +static inline struct au_iinfo *au_ii(struct inode *inode)
18674 + BUG_ON(is_bad_inode(inode));
18675 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18678 +/* ---------------------------------------------------------------------- */
18681 +struct inode *au_igrab(struct inode *inode);
18682 +void au_refresh_iop(struct inode *inode, int force_getattr);
18683 +int au_refresh_hinode_self(struct inode *inode);
18684 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18685 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18686 + unsigned int d_type, ino_t *ino);
18687 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18688 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18689 + struct inode *inode);
18690 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18692 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18695 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18696 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18698 +#ifdef CONFIG_AUFS_SHWH
18699 + return au_ino(sb, bindex, h_ino, d_type, ino);
18712 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18713 + aufs_iop_nogetattr[AuIop_Last];
18715 +/* au_wr_dir flags */
18716 +#define AuWrDir_ADD_ENTRY 1
18717 +#define AuWrDir_ISDIR (1 << 1)
18718 +#define AuWrDir_TMPFILE (1 << 2)
18719 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18720 +#define au_fset_wrdir(flags, name) \
18721 + do { (flags) |= AuWrDir_##name; } while (0)
18722 +#define au_fclr_wrdir(flags, name) \
18723 + do { (flags) &= ~AuWrDir_##name; } while (0)
18725 +struct au_wr_dir_args {
18726 + aufs_bindex_t force_btgt;
18727 + unsigned char flags;
18729 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18730 + struct au_wr_dir_args *args);
18732 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18733 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18734 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18735 + unsigned int udba, unsigned char flags);
18736 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18737 + unsigned int udba, unsigned char flags) __must_check;
18738 +int au_do_pin(struct au_pin *pin) __must_check;
18739 +void au_unpin(struct au_pin *pin);
18740 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18742 +#define AuIcpup_DID_CPUP 1
18743 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18744 +#define au_fset_icpup(flags, name) \
18745 + do { (flags) |= AuIcpup_##name; } while (0)
18746 +#define au_fclr_icpup(flags, name) \
18747 + do { (flags) &= ~AuIcpup_##name; } while (0)
18749 +struct au_icpup_args {
18750 + unsigned char flags;
18751 + unsigned char pin_flags;
18752 + aufs_bindex_t btgt;
18753 + unsigned int udba;
18754 + struct au_pin pin;
18755 + struct path h_path;
18756 + struct inode *h_inode;
18759 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18760 + struct au_icpup_args *a);
18762 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18763 + struct path *h_path, int locked);
18766 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18767 + struct dentry *h_parent, int isdir);
18768 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
18769 + struct dentry *dentry, umode_t mode, dev_t dev);
18770 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
18771 + struct dentry *dentry, const char *symname);
18772 +int aufs_create(struct user_namespace *userns, struct inode *dir,
18773 + struct dentry *dentry, umode_t mode, bool want_excl);
18774 +struct vfsub_aopen_args;
18775 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18776 + struct vfsub_aopen_args *args);
18777 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
18778 + struct dentry *dentry, umode_t mode);
18779 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18780 + struct dentry *dentry);
18781 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
18782 + struct dentry *dentry, umode_t mode);
18785 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18786 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18787 + struct dentry *h_parent, int isdir);
18788 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18789 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18792 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18793 +int aufs_rename(struct user_namespace *userns,
18794 + struct inode *_src_dir, struct dentry *_src_dentry,
18795 + struct inode *_dst_dir, struct dentry *_dst_dentry,
18796 + unsigned int _flags);
18799 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18800 +void au_hiput(struct au_hinode *hinode);
18801 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18802 + struct dentry *h_wh);
18803 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18805 +/* hinode flags */
18806 +#define AuHi_XINO 1
18807 +#define AuHi_HNOTIFY (1 << 1)
18808 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18809 +#define au_fset_hi(flags, name) \
18810 + do { (flags) |= AuHi_##name; } while (0)
18811 +#define au_fclr_hi(flags, name) \
18812 + do { (flags) &= ~AuHi_##name; } while (0)
18814 +#ifndef CONFIG_AUFS_HNOTIFY
18815 +#undef AuHi_HNOTIFY
18816 +#define AuHi_HNOTIFY 0
18819 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18820 + struct inode *h_inode, unsigned int flags);
18822 +void au_update_iigen(struct inode *inode, int half);
18823 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18825 +void au_icntnr_init_once(void *_c);
18826 +void au_hinode_init(struct au_hinode *hinode);
18827 +int au_iinfo_init(struct inode *inode);
18828 +void au_iinfo_fin(struct inode *inode);
18829 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18831 +#ifdef CONFIG_PROC_FS
18833 +int au_plink_maint(struct super_block *sb, int flags);
18835 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18836 +int au_plink_maint_enter(struct super_block *sb);
18837 +#ifdef CONFIG_AUFS_DEBUG
18838 +void au_plink_list(struct super_block *sb);
18840 +AuStubVoid(au_plink_list, struct super_block *sb)
18842 +int au_plink_test(struct inode *inode);
18843 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18844 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18845 + struct dentry *h_dentry);
18846 +void au_plink_put(struct super_block *sb, int verbose);
18847 +void au_plink_clean(struct super_block *sb, int verbose);
18848 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18850 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18851 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18852 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18853 +AuStubVoid(au_plink_list, struct super_block *sb);
18854 +AuStubInt0(au_plink_test, struct inode *inode);
18855 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18856 + struct inode *inode, aufs_bindex_t bindex);
18857 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18858 + struct dentry *h_dentry);
18859 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18860 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18861 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18862 +#endif /* CONFIG_PROC_FS */
18864 +#ifdef CONFIG_AUFS_XATTR
18866 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
18867 + unsigned int verbose);
18868 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18869 +void au_xattr_init(struct super_block *sb);
18871 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
18872 + int ignore_flags, unsigned int verbose);
18873 +AuStubVoid(au_xattr_init, struct super_block *sb);
18876 +#ifdef CONFIG_FS_POSIX_ACL
18877 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
18878 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
18879 + struct posix_acl *acl, int type);
18882 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18888 +struct au_sxattr {
18892 + const char *name;
18893 + const void *value;
18898 + struct posix_acl *acl;
18903 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18904 + struct au_sxattr *arg);
18907 +/* ---------------------------------------------------------------------- */
18909 +/* lock subclass for iinfo */
18911 + AuLsc_II_CHILD, /* child first */
18912 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18913 + AuLsc_II_CHILD3, /* copyup dirs */
18914 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18915 + AuLsc_II_PARENT2,
18916 + AuLsc_II_PARENT3, /* copyup dirs */
18917 + AuLsc_II_NEW_CHILD
18921 + * ii_read_lock_child, ii_write_lock_child,
18922 + * ii_read_lock_child2, ii_write_lock_child2,
18923 + * ii_read_lock_child3, ii_write_lock_child3,
18924 + * ii_read_lock_parent, ii_write_lock_parent,
18925 + * ii_read_lock_parent2, ii_write_lock_parent2,
18926 + * ii_read_lock_parent3, ii_write_lock_parent3,
18927 + * ii_read_lock_new_child, ii_write_lock_new_child,
18929 +#define AuReadLockFunc(name, lsc) \
18930 +static inline void ii_read_lock_##name(struct inode *i) \
18932 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18935 +#define AuWriteLockFunc(name, lsc) \
18936 +static inline void ii_write_lock_##name(struct inode *i) \
18938 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18941 +#define AuRWLockFuncs(name, lsc) \
18942 + AuReadLockFunc(name, lsc) \
18943 + AuWriteLockFunc(name, lsc)
18945 +AuRWLockFuncs(child, CHILD);
18946 +AuRWLockFuncs(child2, CHILD2);
18947 +AuRWLockFuncs(child3, CHILD3);
18948 +AuRWLockFuncs(parent, PARENT);
18949 +AuRWLockFuncs(parent2, PARENT2);
18950 +AuRWLockFuncs(parent3, PARENT3);
18951 +AuRWLockFuncs(new_child, NEW_CHILD);
18953 +#undef AuReadLockFunc
18954 +#undef AuWriteLockFunc
18955 +#undef AuRWLockFuncs
18957 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18958 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18959 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18961 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18962 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18963 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18965 +/* ---------------------------------------------------------------------- */
18967 +static inline void au_icntnr_init(struct au_icntnr *c)
18969 +#ifdef CONFIG_AUFS_DEBUG
18970 + c->vfs_inode.i_mode = 0;
18974 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18976 + unsigned int gen;
18977 + struct au_iinfo *iinfo;
18978 + struct au_iigen *iigen;
18980 + iinfo = au_ii(inode);
18981 + iigen = &iinfo->ii_generation;
18982 + spin_lock(&iigen->ig_spin);
18984 + *igflags = iigen->ig_flags;
18985 + gen = iigen->ig_generation;
18986 + spin_unlock(&iigen->ig_spin);
18991 +/* tiny test for inode number */
18992 +/* tmpfs generation is too rough */
18993 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
18995 + struct au_iinfo *iinfo;
18997 + iinfo = au_ii(inode);
18998 + AuRwMustAnyLock(&iinfo->ii_rwsem);
18999 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19000 + && iinfo->ii_higen == h_inode->i_generation);
19003 +static inline void au_iigen_dec(struct inode *inode)
19005 + struct au_iinfo *iinfo;
19006 + struct au_iigen *iigen;
19008 + iinfo = au_ii(inode);
19009 + iigen = &iinfo->ii_generation;
19010 + spin_lock(&iigen->ig_spin);
19011 + iigen->ig_generation--;
19012 + spin_unlock(&iigen->ig_spin);
19015 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19020 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19026 +/* ---------------------------------------------------------------------- */
19028 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19029 + aufs_bindex_t bindex)
19031 + return iinfo->ii_hinode + bindex;
19034 +static inline int au_is_bad_inode(struct inode *inode)
19036 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19039 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19040 + aufs_bindex_t bindex)
19042 + IiMustAnyLock(inode);
19043 + return au_hinode(au_ii(inode), bindex)->hi_id;
19046 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19048 + IiMustAnyLock(inode);
19049 + return au_ii(inode)->ii_btop;
19052 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19054 + IiMustAnyLock(inode);
19055 + return au_ii(inode)->ii_bbot;
19058 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19060 + IiMustAnyLock(inode);
19061 + return au_ii(inode)->ii_vdir;
19064 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19066 + IiMustAnyLock(inode);
19067 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19070 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19072 + IiMustWriteLock(inode);
19073 + au_ii(inode)->ii_btop = bindex;
19076 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19078 + IiMustWriteLock(inode);
19079 + au_ii(inode)->ii_bbot = bindex;
19082 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19084 + IiMustWriteLock(inode);
19085 + au_ii(inode)->ii_vdir = vdir;
19088 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19090 + IiMustAnyLock(inode);
19091 + return au_hinode(au_ii(inode), bindex);
19094 +/* ---------------------------------------------------------------------- */
19096 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19099 + return pin->parent;
19103 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19105 + if (pin && pin->hdir)
19106 + return pin->hdir->hi_inode;
19110 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19113 + return pin->hdir;
19117 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19120 + pin->dentry = dentry;
19123 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19124 + unsigned char lflag)
19128 + au_fset_pin(pin->flags, DI_LOCKED);
19130 + au_fclr_pin(pin->flags, DI_LOCKED);
19134 +#if 0 /* reserved */
19135 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19138 + dput(pin->parent);
19139 + pin->parent = dget(parent);
19144 +/* ---------------------------------------------------------------------- */
19147 +#ifdef CONFIG_AUFS_HNOTIFY
19148 +struct au_hnotify_op {
19149 + void (*ctl)(struct au_hinode *hinode, int do_set);
19150 + int (*alloc)(struct au_hinode *hinode);
19153 + * if it returns true, the caller should free hinode->hi_notify,
19154 + * otherwise ->free() frees it.
19156 + int (*free)(struct au_hinode *hinode,
19157 + struct au_hnotify *hn) __must_check;
19159 + void (*fin)(void);
19160 + int (*init)(void);
19162 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19163 + void (*fin_br)(struct au_branch *br);
19164 + int (*init_br)(struct au_branch *br, int perm);
19168 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19169 +void au_hn_free(struct au_hinode *hinode);
19170 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19171 +void au_hn_reset(struct inode *inode, unsigned int flags);
19172 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19173 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19174 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19175 +int au_hnotify_init_br(struct au_branch *br, int perm);
19176 +void au_hnotify_fin_br(struct au_branch *br);
19177 +int __init au_hnotify_init(void);
19178 +void au_hnotify_fin(void);
19181 +extern const struct au_hnotify_op au_hnotify_op;
19184 +void au_hn_init(struct au_hinode *hinode)
19186 + hinode->hi_notify = NULL;
19189 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19191 + return hinode->hi_notify;
19195 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19196 + struct au_hinode *hinode __maybe_unused,
19197 + struct inode *inode __maybe_unused)
19198 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19199 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19200 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19201 + int do_set __maybe_unused)
19202 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19203 + unsigned int flags __maybe_unused)
19204 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19205 + struct au_branch *br __maybe_unused,
19206 + int perm __maybe_unused)
19207 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19208 + int perm __maybe_unused)
19209 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19210 +AuStubInt0(__init au_hnotify_init, void)
19211 +AuStubVoid(au_hnotify_fin, void)
19212 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19213 +#endif /* CONFIG_AUFS_HNOTIFY */
19215 +static inline void au_hn_suspend(struct au_hinode *hdir)
19217 + au_hn_ctl(hdir, /*do_set*/0);
19220 +static inline void au_hn_resume(struct au_hinode *hdir)
19222 + au_hn_ctl(hdir, /*do_set*/1);
19225 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19227 + inode_lock(hdir->hi_inode);
19228 + au_hn_suspend(hdir);
19231 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19232 + unsigned int sc __maybe_unused)
19234 + inode_lock_nested(hdir->hi_inode, sc);
19235 + au_hn_suspend(hdir);
19238 +#if 0 /* unused */
19239 +#include "vfsub.h"
19240 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19243 + inode_lock_shared_nested(hdir->hi_inode, sc);
19244 + au_hn_suspend(hdir);
19248 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19250 + au_hn_resume(hdir);
19251 + inode_unlock(hdir->hi_inode);
19254 +#endif /* __KERNEL__ */
19255 +#endif /* __AUFS_INODE_H__ */
19256 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19257 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19258 +++ linux/fs/aufs/ioctl.c 2021-12-03 15:38:59.936647310 +0100
19260 +// SPDX-License-Identifier: GPL-2.0
19262 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19264 + * This program, aufs is free software; you can redistribute it and/or modify
19265 + * it under the terms of the GNU General Public License as published by
19266 + * the Free Software Foundation; either version 2 of the License, or
19267 + * (at your option) any later version.
19269 + * This program is distributed in the hope that it will be useful,
19270 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19271 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19272 + * GNU General Public License for more details.
19274 + * You should have received a copy of the GNU General Public License
19275 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19280 + * plink-management and readdir in userspace.
19281 + * assist the pathconf(3) wrapper library.
19283 + * File-based Hierarchical Storage Management.
19286 +#include <linux/compat.h>
19287 +#include <linux/file.h>
19290 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19293 + aufs_bindex_t wbi, bindex, bbot;
19294 + struct file *h_file;
19295 + struct super_block *sb;
19296 + struct dentry *root;
19297 + struct au_branch *br;
19298 + struct aufs_wbr_fd wbrfd = {
19299 + .oflags = au_dir_roflags,
19302 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19303 + | O_NOATIME | O_CLOEXEC;
19305 + AuDebugOn(wbrfd.oflags & ~valid);
19308 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19309 + if (unlikely(err)) {
19315 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19316 + wbrfd.oflags |= au_dir_roflags;
19317 + AuDbg("0%o\n", wbrfd.oflags);
19318 + if (unlikely(wbrfd.oflags & ~valid))
19322 + fd = get_unused_fd_flags(0);
19324 + if (unlikely(fd < 0))
19327 + h_file = ERR_PTR(-EINVAL);
19330 + sb = path->dentry->d_sb;
19331 + root = sb->s_root;
19332 + aufs_read_lock(root, AuLock_IR);
19333 + bbot = au_sbbot(sb);
19334 + if (wbrfd.brid >= 0) {
19335 + wbi = au_br_index(sb, wbrfd.brid);
19336 + if (unlikely(wbi < 0 || wbi > bbot))
19340 + h_file = ERR_PTR(-ENOENT);
19341 + br = au_sbr(sb, wbi);
19342 + if (!au_br_writable(br->br_perm)) {
19346 + bindex = wbi + 1;
19348 + for (; bindex <= bbot; bindex++) {
19349 + br = au_sbr(sb, bindex);
19350 + if (au_br_writable(br->br_perm)) {
19352 + br = au_sbr(sb, wbi);
19357 + AuDbg("wbi %d\n", wbi);
19359 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19363 + aufs_read_unlock(root, AuLock_IR);
19364 + err = PTR_ERR(h_file);
19365 + if (IS_ERR(h_file))
19368 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19369 + fd_install(fd, h_file);
19371 + goto out; /* success */
19374 + put_unused_fd(fd);
19380 +/* ---------------------------------------------------------------------- */
19382 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19385 + struct dentry *dentry;
19388 + case AUFS_CTL_RDU:
19389 + case AUFS_CTL_RDU_INO:
19390 + err = au_rdu_ioctl(file, cmd, arg);
19393 + case AUFS_CTL_WBR_FD:
19394 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19397 + case AUFS_CTL_IBUSY:
19398 + err = au_ibusy_ioctl(file, arg);
19401 + case AUFS_CTL_BRINFO:
19402 + err = au_brinfo_ioctl(file, arg);
19405 + case AUFS_CTL_FHSM_FD:
19406 + dentry = file->f_path.dentry;
19407 + if (IS_ROOT(dentry))
19408 + err = au_fhsm_fd(dentry->d_sb, arg);
19414 + /* do not call the lower */
19415 + AuDbg("0x%x\n", cmd);
19423 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19428 + case AUFS_CTL_MVDOWN:
19429 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19432 + case AUFS_CTL_WBR_FD:
19433 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19437 + /* do not call the lower */
19438 + AuDbg("0x%x\n", cmd);
19446 +#ifdef CONFIG_COMPAT
19447 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19448 + unsigned long arg)
19453 + case AUFS_CTL_RDU:
19454 + case AUFS_CTL_RDU_INO:
19455 + err = au_rdu_compat_ioctl(file, cmd, arg);
19458 + case AUFS_CTL_IBUSY:
19459 + err = au_ibusy_compat_ioctl(file, arg);
19462 + case AUFS_CTL_BRINFO:
19463 + err = au_brinfo_compat_ioctl(file, arg);
19467 + err = aufs_ioctl_dir(file, cmd, arg);
19474 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19475 + unsigned long arg)
19477 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19480 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19481 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19482 +++ linux/fs/aufs/i_op_add.c 2021-12-03 15:40:58.236647297 +0100
19484 +// SPDX-License-Identifier: GPL-2.0
19486 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19488 + * This program, aufs is free software; you can redistribute it and/or modify
19489 + * it under the terms of the GNU General Public License as published by
19490 + * the Free Software Foundation; either version 2 of the License, or
19491 + * (at your option) any later version.
19493 + * This program is distributed in the hope that it will be useful,
19494 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19496 + * GNU General Public License for more details.
19498 + * You should have received a copy of the GNU General Public License
19499 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19503 + * inode operations (add entry)
19506 +#include <linux/iversion.h>
19510 + * final procedure of adding a new entry, except link(2).
19511 + * remove whiteout, instantiate, copyup the parent dir's times and size
19512 + * and update version.
19513 + * if it failed, re-create the removed whiteout.
19515 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19516 + struct dentry *wh_dentry, struct dentry *dentry)
19519 + aufs_bindex_t bwh;
19520 + struct path h_path;
19521 + struct super_block *sb;
19522 + struct inode *inode, *h_dir;
19523 + struct dentry *wh;
19528 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19529 + IMustLock(h_dir);
19530 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19531 + bwh = au_dbwh(dentry);
19532 + h_path.dentry = wh_dentry;
19533 + h_path.mnt = au_sbr_mnt(sb, bindex);
19534 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19536 + if (unlikely(err))
19540 + inode = au_new_inode(dentry, /*must_new*/1);
19541 + if (!IS_ERR(inode)) {
19542 + d_instantiate(dentry, inode);
19543 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19545 + au_dir_ts(dir, bindex);
19546 + inode_inc_iversion(dir);
19547 + au_fhsm_wrote(sb, bindex, /*force*/0);
19548 + return 0; /* success */
19551 + err = PTR_ERR(inode);
19556 + /* dir inode is locked */
19557 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19558 + rerr = PTR_ERR(wh);
19559 + if (IS_ERR(wh)) {
19560 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19561 + dentry, err, rerr);
19570 +static int au_d_may_add(struct dentry *dentry)
19575 + if (unlikely(d_unhashed(dentry)))
19577 + if (unlikely(d_really_is_positive(dentry)))
19583 + * simple tests for the adding inode operations.
19584 + * following the checks in vfs, plus the parent-child relationship.
19586 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19587 + struct dentry *h_parent, int isdir)
19591 + struct dentry *h_dentry;
19592 + struct inode *h_inode;
19594 + err = -ENAMETOOLONG;
19595 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19598 + h_dentry = au_h_dptr(dentry, bindex);
19599 + if (d_really_is_negative(dentry)) {
19601 + if (unlikely(d_is_positive(h_dentry)))
19604 + /* rename(2) case */
19606 + if (unlikely(d_is_negative(h_dentry)))
19608 + h_inode = d_inode(h_dentry);
19609 + if (unlikely(!h_inode->i_nlink))
19612 + h_mode = h_inode->i_mode;
19615 + if (unlikely(S_ISDIR(h_mode)))
19617 + } else if (unlikely(!S_ISDIR(h_mode))) {
19624 + /* expected parent dir is locked */
19625 + if (unlikely(h_parent != h_dentry->d_parent))
19634 + * initial procedure of adding a new entry.
19635 + * prepare writable branch and the parent dir, lock it,
19636 + * and lookup whiteout for the new entry.
19638 +static struct dentry*
19639 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19640 + struct dentry *src_dentry, struct au_pin *pin,
19641 + struct au_wr_dir_args *wr_dir_args)
19643 + struct dentry *wh_dentry, *h_parent;
19644 + struct super_block *sb;
19645 + struct au_branch *br;
19647 + unsigned int udba;
19648 + aufs_bindex_t bcpup;
19650 + AuDbg("%pd\n", dentry);
19652 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19654 + wh_dentry = ERR_PTR(err);
19655 + if (unlikely(err < 0))
19658 + sb = dentry->d_sb;
19659 + udba = au_opt_udba(sb);
19660 + err = au_pin(pin, dentry, bcpup, udba,
19661 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19662 + wh_dentry = ERR_PTR(err);
19663 + if (unlikely(err))
19666 + h_parent = au_pinned_h_parent(pin);
19667 + if (udba != AuOpt_UDBA_NONE
19668 + && au_dbtop(dentry) == bcpup)
19669 + err = au_may_add(dentry, bcpup, h_parent,
19670 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19671 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19672 + err = -ENAMETOOLONG;
19673 + wh_dentry = ERR_PTR(err);
19674 + if (unlikely(err))
19677 + br = au_sbr(sb, bcpup);
19679 + struct path tmp = {
19680 + .dentry = h_parent,
19681 + .mnt = au_br_mnt(br)
19683 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19686 + wh_dentry = NULL;
19687 + if (bcpup != au_dbwh(dentry))
19688 + goto out; /* success */
19691 + * ENAMETOOLONG here means that if we allowed create such name, then it
19692 + * would not be able to removed in the future. So we don't allow such
19693 + * name here and we don't handle ENAMETOOLONG differently here.
19695 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19698 + if (IS_ERR(wh_dentry))
19701 + return wh_dentry;
19704 +/* ---------------------------------------------------------------------- */
19706 +enum { Mknod, Symlink, Creat };
19707 +struct simple_arg {
19714 + struct vfsub_aopen_args *aopen;
19717 + const char *symname;
19726 +static int add_simple(struct inode *dir, struct dentry *dentry,
19727 + struct simple_arg *arg)
19730 + aufs_bindex_t btop;
19731 + unsigned char created;
19732 + const unsigned char try_aopen
19733 + = (arg->type == Creat && arg->u.c.try_aopen);
19734 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19735 + struct dentry *wh_dentry, *parent;
19736 + struct inode *h_dir;
19737 + struct super_block *sb;
19738 + struct au_branch *br;
19739 + /* to reduce stack size */
19741 + struct au_dtime dt;
19742 + struct au_pin pin;
19743 + struct path h_path;
19744 + struct au_wr_dir_args wr_dir_args;
19747 + AuDbg("%pd\n", dentry);
19751 + a = kmalloc(sizeof(*a), GFP_NOFS);
19752 + if (unlikely(!a))
19754 + a->wr_dir_args.force_btgt = -1;
19755 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19757 + parent = dentry->d_parent; /* dir inode is locked */
19758 + if (!try_aopen) {
19759 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19760 + if (unlikely(err))
19763 + err = au_d_may_add(dentry);
19764 + if (unlikely(err))
19767 + di_write_lock_parent(parent);
19768 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19769 + &a->pin, &a->wr_dir_args);
19770 + err = PTR_ERR(wh_dentry);
19771 + if (IS_ERR(wh_dentry))
19774 + btop = au_dbtop(dentry);
19775 + sb = dentry->d_sb;
19776 + br = au_sbr(sb, btop);
19777 + a->h_path.dentry = au_h_dptr(dentry, btop);
19778 + a->h_path.mnt = au_br_mnt(br);
19779 + h_dir = au_pinned_h_dir(&a->pin);
19780 + switch (arg->type) {
19782 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19783 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19784 + arg->u.c.want_excl);
19786 + if (!err && try_aopen)
19787 + aopen->file->f_mode |= FMODE_CREATED;
19790 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19791 + AuDbg("err %d\n", err);
19792 + AuDbgFile(aopen->file);
19793 + created = err >= 0
19794 + && !!(aopen->file->f_mode & FMODE_CREATED);
19798 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19802 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19809 + if (unlikely(err < 0))
19812 + err = epilog(dir, btop, wh_dentry, dentry);
19814 + goto out_unpin; /* success */
19817 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19818 + /* no delegation since it is just created */
19819 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19822 + AuIOErr("%pd revert failure(%d, %d)\n",
19823 + dentry, err, rerr);
19826 + au_dtime_revert(&a->dt);
19828 + if (try_aopen && h_dir->i_op->atomic_open
19829 + && (aopen->file->f_mode & FMODE_OPENED))
19830 + /* aopen->file is still opened */
19831 + au_lcnt_dec(&aopen->br->br_nfiles);
19834 + au_unpin(&a->pin);
19838 + di_write_unlock(parent);
19840 + if (unlikely(err)) {
19841 + au_update_dbtop(dentry);
19845 + aufs_read_unlock(dentry, AuLock_DW);
19852 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
19853 + struct dentry *dentry, umode_t mode, dev_t dev)
19855 + struct simple_arg arg = {
19862 + return add_simple(dir, dentry, &arg);
19865 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
19866 + struct dentry *dentry, const char *symname)
19868 + struct simple_arg arg = {
19870 + .u.s.symname = symname
19872 + return add_simple(dir, dentry, &arg);
19875 +int aufs_create(struct user_namespace *userns, struct inode *dir,
19876 + struct dentry *dentry, umode_t mode, bool want_excl)
19878 + struct simple_arg arg = {
19882 + .want_excl = want_excl
19885 + return add_simple(dir, dentry, &arg);
19888 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19889 + struct vfsub_aopen_args *aopen_args)
19891 + struct simple_arg arg = {
19894 + .mode = aopen_args->create_mode,
19895 + .want_excl = aopen_args->open_flag & O_EXCL,
19896 + .try_aopen = true,
19897 + .aopen = aopen_args
19900 + return add_simple(dir, dentry, &arg);
19903 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
19904 + struct dentry *dentry, umode_t mode)
19907 + aufs_bindex_t bindex;
19908 + struct super_block *sb;
19909 + struct dentry *parent, *h_parent, *h_dentry;
19910 + struct inode *h_dir, *inode;
19911 + struct vfsmount *h_mnt;
19912 + struct user_namespace *h_userns;
19913 + struct au_wr_dir_args wr_dir_args = {
19914 + .force_btgt = -1,
19915 + .flags = AuWrDir_TMPFILE
19918 + /* copy-up may happen */
19922 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19923 + if (unlikely(err))
19926 + err = au_di_init(dentry);
19927 + if (unlikely(err))
19931 + parent = d_find_any_alias(dir);
19932 + AuDebugOn(!parent);
19933 + di_write_lock_parent(parent);
19934 + if (unlikely(d_inode(parent) != dir))
19937 + err = au_digen_test(parent, au_sigen(sb));
19938 + if (unlikely(err))
19941 + bindex = au_dbtop(parent);
19942 + au_set_dbtop(dentry, bindex);
19943 + au_set_dbbot(dentry, bindex);
19944 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19946 + if (unlikely(err < 0))
19949 + err = -EOPNOTSUPP;
19950 + h_dir = au_h_iptr(dir, bindex);
19951 + if (unlikely(!h_dir->i_op->tmpfile))
19954 + h_mnt = au_sbr_mnt(sb, bindex);
19955 + err = vfsub_mnt_want_write(h_mnt);
19956 + if (unlikely(err))
19959 + h_userns = mnt_user_ns(h_mnt);
19960 + h_parent = au_h_dptr(parent, bindex);
19961 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
19962 + if (IS_ERR(h_dentry)) {
19963 + err = PTR_ERR(h_dentry);
19967 + au_set_dbtop(dentry, bindex);
19968 + au_set_dbbot(dentry, bindex);
19969 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19970 + inode = au_new_inode(dentry, /*must_new*/1);
19971 + if (IS_ERR(inode)) {
19972 + err = PTR_ERR(inode);
19973 + au_set_h_dptr(dentry, bindex, NULL);
19974 + au_set_dbtop(dentry, -1);
19975 + au_set_dbbot(dentry, -1);
19977 + if (!inode->i_nlink)
19978 + set_nlink(inode, 1);
19979 + d_tmpfile(dentry, inode);
19980 + au_di(dentry)->di_tmpfile = 1;
19982 + /* update without i_mutex */
19983 + if (au_ibtop(dir) == au_dbtop(dentry))
19984 + au_cpup_attr_timesizes(dir);
19989 + vfsub_mnt_drop_write(h_mnt);
19991 + di_write_unlock(parent);
19993 + di_write_unlock(dentry);
19994 + if (unlikely(err)) {
19995 + au_di_fin(dentry);
19996 + dentry->d_fsdata = NULL;
19999 + si_read_unlock(sb);
20001 + inode_unlock(dir);
20005 +/* ---------------------------------------------------------------------- */
20007 +struct au_link_args {
20008 + aufs_bindex_t bdst, bsrc;
20009 + struct au_pin pin;
20010 + struct path h_path;
20011 + struct dentry *src_parent, *parent;
20014 +static int au_cpup_before_link(struct dentry *src_dentry,
20015 + struct au_link_args *a)
20018 + struct dentry *h_src_dentry;
20019 + struct au_cp_generic cpg = {
20020 + .dentry = src_dentry,
20025 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20028 + di_read_lock_parent(a->src_parent, AuLock_IR);
20029 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20030 + if (unlikely(err))
20033 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20034 + err = au_pin(&a->pin, src_dentry, a->bdst,
20035 + au_opt_udba(src_dentry->d_sb),
20036 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20037 + if (unlikely(err))
20040 + err = au_sio_cpup_simple(&cpg);
20041 + au_unpin(&a->pin);
20044 + di_read_unlock(a->src_parent, AuLock_IR);
20048 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20049 + struct au_link_args *a)
20052 + unsigned char plink;
20053 + aufs_bindex_t bbot;
20054 + struct dentry *h_src_dentry;
20055 + struct inode *h_inode, *inode, *delegated;
20056 + struct super_block *sb;
20057 + struct file *h_file;
20061 + sb = src_dentry->d_sb;
20062 + inode = d_inode(src_dentry);
20063 + if (au_ibtop(inode) <= a->bdst)
20064 + h_inode = au_h_iptr(inode, a->bdst);
20065 + if (!h_inode || !h_inode->i_nlink) {
20066 + /* copyup src_dentry as the name of dentry. */
20067 + bbot = au_dbbot(dentry);
20068 + if (bbot < a->bsrc)
20069 + au_set_dbbot(dentry, a->bsrc);
20070 + au_set_h_dptr(dentry, a->bsrc,
20071 + dget(au_h_dptr(src_dentry, a->bsrc)));
20072 + dget(a->h_path.dentry);
20073 + au_set_h_dptr(dentry, a->bdst, NULL);
20074 + AuDbg("temporary d_inode...\n");
20075 + spin_lock(&dentry->d_lock);
20076 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20077 + spin_unlock(&dentry->d_lock);
20078 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20079 + if (IS_ERR(h_file))
20080 + err = PTR_ERR(h_file);
20082 + struct au_cp_generic cpg = {
20083 + .dentry = dentry,
20088 + .flags = AuCpup_KEEPLINO
20090 + err = au_sio_cpup_simple(&cpg);
20091 + au_h_open_post(dentry, a->bsrc, h_file);
20093 + dput(a->h_path.dentry);
20094 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20096 + au_set_h_dptr(dentry, a->bdst,
20097 + a->h_path.dentry);
20099 + spin_lock(&dentry->d_lock);
20100 + dentry->d_inode = NULL; /* restore */
20101 + spin_unlock(&dentry->d_lock);
20102 + AuDbg("temporary d_inode...done\n");
20103 + au_set_h_dptr(dentry, a->bsrc, NULL);
20104 + au_set_dbbot(dentry, bbot);
20106 + /* the inode of src_dentry already exists on a.bdst branch */
20107 + h_src_dentry = d_find_alias(h_inode);
20108 + if (!h_src_dentry && au_plink_test(inode)) {
20110 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20111 + err = PTR_ERR(h_src_dentry);
20112 + if (IS_ERR(h_src_dentry))
20115 + if (unlikely(d_is_negative(h_src_dentry))) {
20116 + dput(h_src_dentry);
20117 + h_src_dentry = NULL;
20121 + if (h_src_dentry) {
20122 + delegated = NULL;
20123 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20124 + &a->h_path, &delegated);
20125 + if (unlikely(err == -EWOULDBLOCK)) {
20126 + pr_warn("cannot retry for NFSv4 delegation"
20127 + " for an internal link\n");
20130 + dput(h_src_dentry);
20132 + AuIOErr("no dentry found for hi%lu on b%d\n",
20133 + h_inode->i_ino, a->bdst);
20138 + if (!err && !plink)
20139 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20146 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20147 + struct dentry *dentry)
20150 + struct au_dtime dt;
20151 + struct au_link_args *a;
20152 + struct dentry *wh_dentry, *h_src_dentry;
20153 + struct inode *inode, *delegated;
20154 + struct super_block *sb;
20155 + struct au_wr_dir_args wr_dir_args = {
20156 + /* .force_btgt = -1, */
20157 + .flags = AuWrDir_ADD_ENTRY
20161 + inode = d_inode(src_dentry);
20162 + IMustLock(inode);
20165 + a = kzalloc(sizeof(*a), GFP_NOFS);
20166 + if (unlikely(!a))
20169 + a->parent = dentry->d_parent; /* dir inode is locked */
20170 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20171 + AuLock_NOPLM | AuLock_GEN);
20172 + if (unlikely(err))
20174 + err = au_d_linkable(src_dentry);
20175 + if (unlikely(err))
20177 + err = au_d_may_add(dentry);
20178 + if (unlikely(err))
20181 + a->src_parent = dget_parent(src_dentry);
20182 + wr_dir_args.force_btgt = au_ibtop(inode);
20184 + di_write_lock_parent(a->parent);
20185 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20186 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20188 + err = PTR_ERR(wh_dentry);
20189 + if (IS_ERR(wh_dentry))
20193 + sb = dentry->d_sb;
20194 + a->bdst = au_dbtop(dentry);
20195 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20196 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20197 + a->bsrc = au_ibtop(inode);
20198 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20199 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20200 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20201 + if (!h_src_dentry) {
20202 + a->bsrc = au_dbtop(src_dentry);
20203 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20204 + AuDebugOn(!h_src_dentry);
20205 + } else if (IS_ERR(h_src_dentry)) {
20206 + err = PTR_ERR(h_src_dentry);
20211 + * aufs doesn't touch the credential so
20212 + * security_dentry_create_files_as() is unnecessary.
20214 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20215 + if (a->bdst < a->bsrc
20216 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20217 + err = au_cpup_or_link(src_dentry, dentry, a);
20219 + delegated = NULL;
20220 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20221 + &a->h_path, &delegated);
20222 + if (unlikely(err == -EWOULDBLOCK)) {
20223 + pr_warn("cannot retry for NFSv4 delegation"
20224 + " for an internal link\n");
20228 + dput(h_src_dentry);
20231 + * copyup src_dentry to the branch we process,
20232 + * and then link(2) to it.
20234 + dput(h_src_dentry);
20235 + if (a->bdst < a->bsrc
20236 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20237 + au_unpin(&a->pin);
20238 + di_write_unlock(a->parent);
20239 + err = au_cpup_before_link(src_dentry, a);
20240 + di_write_lock_parent(a->parent);
20242 + err = au_pin(&a->pin, dentry, a->bdst,
20244 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20245 + if (unlikely(err))
20249 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20251 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20252 + delegated = NULL;
20253 + err = vfsub_link(h_src_dentry,
20254 + au_pinned_h_dir(&a->pin),
20255 + &a->h_path, &delegated);
20256 + if (unlikely(err == -EWOULDBLOCK)) {
20257 + pr_warn("cannot retry"
20258 + " for NFSv4 delegation"
20259 + " for an internal link\n");
20265 + if (unlikely(err))
20269 + a->h_path.dentry = wh_dentry;
20270 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20272 + if (unlikely(err))
20276 + au_dir_ts(dir, a->bdst);
20277 + inode_inc_iversion(dir);
20278 + inc_nlink(inode);
20279 + inode->i_ctime = dir->i_ctime;
20280 + d_instantiate(dentry, au_igrab(inode));
20281 + if (d_unhashed(a->h_path.dentry))
20282 + /* some filesystem calls d_drop() */
20284 + /* some filesystems consume an inode even hardlink */
20285 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20286 + goto out_unpin; /* success */
20289 + /* no delegation since it is just created */
20290 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20291 + /*delegated*/NULL, /*force*/0);
20292 + if (unlikely(rerr)) {
20293 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20296 + au_dtime_revert(&dt);
20298 + au_unpin(&a->pin);
20302 + di_write_unlock(a->parent);
20303 + dput(a->src_parent);
20305 + if (unlikely(err)) {
20306 + au_update_dbtop(dentry);
20309 + aufs_read_and_write_unlock2(dentry, src_dentry);
20317 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20318 + struct dentry *dentry, umode_t mode)
20321 + aufs_bindex_t bindex;
20322 + unsigned char diropq;
20323 + struct path h_path;
20324 + struct dentry *wh_dentry, *parent, *opq_dentry;
20325 + struct inode *h_inode;
20326 + struct super_block *sb;
20328 + struct au_pin pin;
20329 + struct au_dtime dt;
20330 + } *a; /* reduce the stack usage */
20331 + struct au_wr_dir_args wr_dir_args = {
20332 + .force_btgt = -1,
20333 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20339 + a = kmalloc(sizeof(*a), GFP_NOFS);
20340 + if (unlikely(!a))
20343 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20344 + if (unlikely(err))
20346 + err = au_d_may_add(dentry);
20347 + if (unlikely(err))
20350 + parent = dentry->d_parent; /* dir inode is locked */
20351 + di_write_lock_parent(parent);
20352 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20353 + &a->pin, &wr_dir_args);
20354 + err = PTR_ERR(wh_dentry);
20355 + if (IS_ERR(wh_dentry))
20358 + sb = dentry->d_sb;
20359 + bindex = au_dbtop(dentry);
20360 + h_path.dentry = au_h_dptr(dentry, bindex);
20361 + h_path.mnt = au_sbr_mnt(sb, bindex);
20362 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20363 + if (unlikely(err))
20366 + /* make the dir opaque */
20368 + h_inode = d_inode(h_path.dentry);
20370 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20371 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20372 + opq_dentry = au_diropq_create(dentry, bindex);
20373 + inode_unlock(h_inode);
20374 + err = PTR_ERR(opq_dentry);
20375 + if (IS_ERR(opq_dentry))
20377 + dput(opq_dentry);
20381 + err = epilog(dir, bindex, wh_dentry, dentry);
20384 + goto out_unpin; /* success */
20389 + AuLabel(revert opq);
20390 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20391 + rerr = au_diropq_remove(dentry, bindex);
20392 + inode_unlock(h_inode);
20394 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20395 + dentry, err, rerr);
20401 + AuLabel(revert dir);
20402 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20404 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20405 + dentry, err, rerr);
20408 + au_dtime_revert(&a->dt);
20410 + au_unpin(&a->pin);
20413 + di_write_unlock(parent);
20415 + if (unlikely(err)) {
20416 + au_update_dbtop(dentry);
20419 + aufs_read_unlock(dentry, AuLock_DW);
20425 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20426 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20427 +++ linux/fs/aufs/i_op.c 2021-12-03 15:40:58.236647297 +0100
20429 +// SPDX-License-Identifier: GPL-2.0
20431 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20433 + * This program, aufs is free software; you can redistribute it and/or modify
20434 + * it under the terms of the GNU General Public License as published by
20435 + * the Free Software Foundation; either version 2 of the License, or
20436 + * (at your option) any later version.
20438 + * This program is distributed in the hope that it will be useful,
20439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20441 + * GNU General Public License for more details.
20443 + * You should have received a copy of the GNU General Public License
20444 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20448 + * inode operations (except add/del/rename)
20451 +#include <linux/device_cgroup.h>
20452 +#include <linux/fs_stack.h>
20453 +#include <linux/iversion.h>
20454 +#include <linux/namei.h>
20455 +#include <linux/security.h>
20458 +static int h_permission(struct inode *h_inode, int mask,
20459 + struct path *h_path, int brperm)
20462 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20463 + struct user_namespace *h_userns;
20466 + if (write_mask && IS_IMMUTABLE(h_inode))
20470 + if (((mask & MAY_EXEC)
20471 + && S_ISREG(h_inode->i_mode)
20472 + && (path_noexec(h_path)
20473 + || !(h_inode->i_mode & 0111))))
20477 + * - skip the lower fs test in the case of write to ro branch.
20478 + * - nfs dir permission write check is optimized, but a policy for
20479 + * link/rename requires a real check.
20480 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20481 + * in this case, generic_permission() returns -EOPNOTSUPP.
20483 + h_userns = mnt_user_ns(h_path->mnt);
20484 + if ((write_mask && !au_br_writable(brperm))
20485 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20486 + && write_mask && !(mask & MAY_READ))
20487 + || !h_inode->i_op->permission) {
20488 + /* AuLabel(generic_permission); */
20489 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20490 + err = generic_permission(h_userns, h_inode, mask);
20491 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20492 + err = h_inode->i_op->permission(h_userns, h_inode,
20496 + /* AuLabel(h_inode->permission); */
20497 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
20502 + err = devcgroup_inode_permission(h_inode, mask);
20504 + err = security_inode_permission(h_inode, mask);
20510 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
20514 + aufs_bindex_t bindex, bbot;
20515 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20516 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20517 + struct inode *h_inode;
20518 + struct super_block *sb;
20519 + struct au_branch *br;
20521 + /* todo: support rcu-walk? */
20522 + if (mask & MAY_NOT_BLOCK)
20525 + sb = inode->i_sb;
20526 + si_read_lock(sb, AuLock_FLUSH);
20527 + ii_read_lock_child(inode);
20528 +#if 0 /* reserved for future use */
20530 + * This test may be rather 'too much' since the test is essentially done
20531 + * in the aufs_lookup(). Theoretically it is possible that the inode
20532 + * generation doesn't match to the superblock's here. But it isn't a
20533 + * big deal I suppose.
20535 + err = au_iigen_test(inode, au_sigen(sb));
20536 + if (unlikely(err))
20542 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20543 + err = au_busy_or_stale();
20544 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20545 + if (unlikely(!h_inode
20546 + || (h_inode->i_mode & S_IFMT)
20547 + != (inode->i_mode & S_IFMT)))
20551 + bindex = au_ibtop(inode);
20552 + br = au_sbr(sb, bindex);
20553 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20556 + && !special_file(h_inode->i_mode)) {
20557 + /* test whether the upper writable branch exists */
20559 + for (; bindex >= 0; bindex--)
20560 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20568 + /* non-write to dir */
20570 + bbot = au_ibbot(inode);
20571 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20572 + h_inode = au_h_iptr(inode, bindex);
20574 + err = au_busy_or_stale();
20575 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20578 + br = au_sbr(sb, bindex);
20579 + err = h_permission(h_inode, mask, &br->br_path,
20585 + ii_read_unlock(inode);
20586 + si_read_unlock(sb);
20590 +/* ---------------------------------------------------------------------- */
20592 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20593 + unsigned int flags)
20595 + struct dentry *ret, *parent;
20596 + struct inode *inode;
20597 + struct super_block *sb;
20598 + int err, npositive;
20602 + /* todo: support rcu-walk? */
20603 + ret = ERR_PTR(-ECHILD);
20604 + if (flags & LOOKUP_RCU)
20607 + ret = ERR_PTR(-ENAMETOOLONG);
20608 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20612 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20613 + ret = ERR_PTR(err);
20614 + if (unlikely(err))
20617 + err = au_di_init(dentry);
20618 + ret = ERR_PTR(err);
20619 + if (unlikely(err))
20623 + npositive = 0; /* suppress a warning */
20624 + parent = dentry->d_parent; /* dir inode is locked */
20625 + di_read_lock_parent(parent, AuLock_IR);
20626 + err = au_alive_dir(parent);
20628 + err = au_digen_test(parent, au_sigen(sb));
20630 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20631 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20632 + AuLkup_ALLOW_NEG);
20635 + di_read_unlock(parent, AuLock_IR);
20636 + ret = ERR_PTR(err);
20637 + if (unlikely(err < 0))
20641 + inode = au_new_inode(dentry, /*must_new*/0);
20642 + if (IS_ERR(inode)) {
20643 + ret = (void *)inode;
20650 + atomic_inc(&inode->i_count);
20651 + ret = d_splice_alias(inode, dentry);
20652 +#if 0 /* reserved for future use */
20653 + if (unlikely(d_need_lookup(dentry))) {
20654 + spin_lock(&dentry->d_lock);
20655 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20656 + spin_unlock(&dentry->d_lock);
20660 + if (!IS_ERR(ret)) {
20662 + if (ret && ret != dentry)
20663 + ii_write_unlock(inode);
20665 + ii_write_unlock(inode);
20672 + di_write_unlock(dentry);
20674 + si_read_unlock(sb);
20679 +/* ---------------------------------------------------------------------- */
20682 + * very dirty and complicated aufs ->atomic_open().
20683 + * aufs_atomic_open()
20684 + * + au_aopen_or_create()
20686 + * + vfsub_atomic_open()
20687 + * + branch fs ->atomic_open()
20688 + * may call the actual 'open' for h_file
20689 + * + inc br_nfiles only if opened
20690 + * + au_aopen_no_open() or au_aopen_do_open()
20692 + * au_aopen_do_open()
20693 + * + finish_open()
20694 + * + au_do_aopen()
20695 + * + au_do_open() the body of all 'open'
20696 + * + au_do_open_nondir()
20697 + * set the passed h_file
20699 + * au_aopen_no_open()
20700 + * + finish_no_open()
20703 +struct aopen_node {
20704 + struct hlist_bl_node hblist;
20705 + struct file *file, *h_file;
20708 +static int au_do_aopen(struct inode *inode, struct file *file)
20710 + struct hlist_bl_head *aopen;
20711 + struct hlist_bl_node *pos;
20712 + struct aopen_node *node;
20713 + struct au_do_open_args args = {
20715 + .open = au_do_open_nondir
20718 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20719 + hlist_bl_lock(aopen);
20720 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20721 + if (node->file == file) {
20722 + args.h_file = node->h_file;
20725 + hlist_bl_unlock(aopen);
20726 + /* AuDebugOn(!args.h_file); */
20728 + return au_do_open(file, &args);
20731 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20732 + struct aopen_node *aopen_node)
20735 + struct hlist_bl_head *aopen;
20738 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20739 + au_hbl_add(&aopen_node->hblist, aopen);
20740 + err = finish_open(file, dentry, au_do_aopen);
20741 + au_hbl_del(&aopen_node->hblist, aopen);
20742 + /* AuDbgFile(file); */
20743 + AuDbg("%pd%s%s\n", dentry,
20744 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20745 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20751 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20757 + err = finish_no_open(file, dentry);
20763 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20764 + struct file *file, unsigned int open_flag,
20765 + umode_t create_mode)
20767 + int err, did_open;
20768 + unsigned int lkup_flags;
20769 + aufs_bindex_t bindex;
20770 + struct super_block *sb;
20771 + struct dentry *parent, *d;
20772 + struct vfsub_aopen_args args = {
20773 + .open_flag = open_flag,
20774 + .create_mode = create_mode
20776 + struct aopen_node aopen_node = {
20781 + AuDbg("open_flag 0%o\n", open_flag);
20782 + AuDbgDentry(dentry);
20785 + if (!au_di(dentry)) {
20786 + lkup_flags = LOOKUP_OPEN;
20787 + if (open_flag & O_CREAT)
20788 + lkup_flags |= LOOKUP_CREATE;
20789 + d = aufs_lookup(dir, dentry, lkup_flags);
20791 + err = PTR_ERR(d);
20796 + * obsoleted dentry found.
20797 + * another error will be returned later.
20803 + AuDbgDentry(dentry);
20806 + if (d_is_positive(dentry)
20807 + || d_unhashed(dentry)
20808 + || d_unlinked(dentry)
20809 + || !(open_flag & O_CREAT)) {
20810 + err = au_aopen_no_open(file, dentry);
20811 + goto out; /* success */
20814 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20815 + if (unlikely(err))
20818 + sb = dentry->d_sb;
20819 + parent = dentry->d_parent; /* dir is locked */
20820 + di_write_lock_parent(parent);
20821 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20822 + if (unlikely(err < 0))
20825 + AuDbgDentry(dentry);
20826 + if (d_is_positive(dentry)) {
20827 + err = au_aopen_no_open(file, dentry);
20828 + goto out_parent; /* success */
20831 + args.file = alloc_empty_file(file->f_flags, current_cred());
20832 + err = PTR_ERR(args.file);
20833 + if (IS_ERR(args.file))
20836 + bindex = au_dbtop(dentry);
20837 + err = au_aopen_or_create(dir, dentry, &args);
20839 + AuDbgFile(args.file);
20840 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20841 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20844 + args.file = NULL;
20846 + di_write_unlock(parent);
20847 + di_write_unlock(dentry);
20848 + if (unlikely(err < 0)) {
20855 + err = au_aopen_no_open(file, dentry);
20857 + aopen_node.h_file = args.file;
20858 + err = au_aopen_do_open(file, dentry, &aopen_node);
20860 + if (unlikely(err < 0)) {
20864 + au_lcnt_dec(&args.br->br_nfiles);
20866 + goto out_sb; /* success */
20869 + di_write_unlock(parent);
20870 + di_write_unlock(dentry);
20872 + si_read_unlock(sb);
20880 +/* ---------------------------------------------------------------------- */
20882 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20883 + const unsigned char add_entry, aufs_bindex_t bcpup,
20884 + aufs_bindex_t btop)
20887 + struct dentry *h_parent;
20888 + struct inode *h_dir;
20891 + IMustLock(d_inode(parent));
20893 + di_write_lock_parent(parent);
20896 + if (!au_h_dptr(parent, bcpup)) {
20897 + if (btop > bcpup)
20898 + err = au_cpup_dirs(dentry, bcpup);
20899 + else if (btop < bcpup)
20900 + err = au_cpdown_dirs(dentry, bcpup);
20904 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20905 + h_parent = au_h_dptr(parent, bcpup);
20906 + h_dir = d_inode(h_parent);
20907 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20908 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20909 + /* todo: no unlock here */
20910 + inode_unlock_shared(h_dir);
20912 + AuDbg("bcpup %d\n", bcpup);
20914 + if (d_really_is_negative(dentry))
20915 + au_set_h_dptr(dentry, btop, NULL);
20916 + au_update_dbrange(dentry, /*do_put_zero*/0);
20921 + di_write_unlock(parent);
20923 + err = bcpup; /* success */
20930 + * decide the branch and the parent dir where we will create a new entry.
20931 + * returns new bindex or an error.
20932 + * copyup the parent dir if needed.
20934 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20935 + struct au_wr_dir_args *args)
20938 + unsigned int flags;
20939 + aufs_bindex_t bcpup, btop, src_btop;
20940 + const unsigned char add_entry
20941 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20942 + | au_ftest_wrdir(args->flags, TMPFILE);
20943 + struct super_block *sb;
20944 + struct dentry *parent;
20945 + struct au_sbinfo *sbinfo;
20947 + sb = dentry->d_sb;
20948 + sbinfo = au_sbi(sb);
20949 + parent = dget_parent(dentry);
20950 + btop = au_dbtop(dentry);
20952 + if (args->force_btgt < 0) {
20953 + if (src_dentry) {
20954 + src_btop = au_dbtop(src_dentry);
20955 + if (src_btop < btop)
20956 + bcpup = src_btop;
20957 + } else if (add_entry) {
20959 + if (au_ftest_wrdir(args->flags, ISDIR))
20960 + au_fset_wbr(flags, DIR);
20961 + err = AuWbrCreate(sbinfo, dentry, flags);
20965 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20967 + err = AuWbrCopyup(sbinfo, dentry);
20969 + if (!IS_ROOT(dentry)) {
20970 + di_read_lock_parent(parent, !AuLock_IR);
20971 + err = AuWbrCopyup(sbinfo, dentry);
20972 + di_read_unlock(parent, !AuLock_IR);
20974 + err = AuWbrCopyup(sbinfo, dentry);
20977 + if (unlikely(err < 0))
20981 + bcpup = args->force_btgt;
20982 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
20985 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
20987 + if (bcpup == btop)
20988 + goto out; /* success */
20990 + /* copyup the new parent into the branch we process */
20991 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
20993 + if (d_really_is_negative(dentry)) {
20994 + au_set_h_dptr(dentry, btop, NULL);
20995 + au_set_dbtop(dentry, bcpup);
20996 + au_set_dbbot(dentry, bcpup);
20998 + AuDebugOn(add_entry
20999 + && !au_ftest_wrdir(args->flags, TMPFILE)
21000 + && !au_h_dptr(dentry, bcpup));
21008 +/* ---------------------------------------------------------------------- */
21010 +void au_pin_hdir_unlock(struct au_pin *p)
21013 + au_hn_inode_unlock(p->hdir);
21016 +int au_pin_hdir_lock(struct au_pin *p)
21024 + /* even if an error happens later, keep this lock */
21025 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21028 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21033 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21034 + p->h_parent, p->br);
21040 +int au_pin_hdir_relock(struct au_pin *p)
21043 + struct inode *h_i;
21044 + struct dentry *h_d[] = {
21049 + err = au_pin_hdir_lock(p);
21050 + if (unlikely(err))
21053 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21056 + if (d_is_positive(h_d[i])) {
21057 + h_i = d_inode(h_d[i]);
21058 + err = !h_i->i_nlink;
21066 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21068 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21071 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21074 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21075 + p->lsc_hi, 0, NULL, _RET_IP_);
21076 + au_pin_hdir_set_owner(p, current);
21080 +void au_pin_hdir_release(struct au_pin *p)
21083 + au_pin_hdir_set_owner(p, p->task);
21084 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21088 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21090 + if (pin && pin->parent)
21091 + return au_h_dptr(pin->parent, pin->bindex);
21095 +void au_unpin(struct au_pin *p)
21098 + au_pin_hdir_unlock(p);
21099 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21100 + vfsub_mnt_drop_write(p->h_mnt);
21104 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21105 + di_read_unlock(p->parent, AuLock_IR);
21106 + iput(p->hdir->hi_inode);
21108 + p->parent = NULL;
21111 + /* do not clear p->task */
21114 +int au_do_pin(struct au_pin *p)
21117 + struct super_block *sb;
21118 + struct inode *h_dir;
21121 + sb = p->dentry->d_sb;
21122 + p->br = au_sbr(sb, p->bindex);
21123 + if (IS_ROOT(p->dentry)) {
21124 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21125 + p->h_mnt = au_br_mnt(p->br);
21126 + err = vfsub_mnt_want_write(p->h_mnt);
21127 + if (unlikely(err)) {
21128 + au_fclr_pin(p->flags, MNT_WRITE);
21135 + p->h_dentry = NULL;
21136 + if (p->bindex <= au_dbbot(p->dentry))
21137 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21139 + p->parent = dget_parent(p->dentry);
21140 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21141 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21144 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21145 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21147 + h_dir = p->hdir->hi_inode;
21151 + * if DI_LOCKED is not set, then p->parent may be different
21152 + * and h_parent can be NULL.
21154 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21156 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21157 + di_read_unlock(p->parent, AuLock_IR);
21159 + p->parent = NULL;
21163 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21164 + p->h_mnt = au_br_mnt(p->br);
21165 + err = vfsub_mnt_want_write(p->h_mnt);
21166 + if (unlikely(err)) {
21167 + au_fclr_pin(p->flags, MNT_WRITE);
21168 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21169 + di_read_unlock(p->parent, AuLock_IR);
21171 + p->parent = NULL;
21177 + err = au_pin_hdir_lock(p);
21179 + goto out; /* success */
21184 + pr_err("err %d\n", err);
21185 + err = au_busy_or_stale();
21190 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21191 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21192 + unsigned int udba, unsigned char flags)
21194 + p->dentry = dentry;
21196 + p->lsc_di = lsc_di;
21197 + p->lsc_hi = lsc_hi;
21198 + p->flags = flags;
21199 + p->bindex = bindex;
21201 + p->parent = NULL;
21205 + p->h_dentry = NULL;
21206 + p->h_parent = NULL;
21208 + p->task = current;
21211 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21212 + unsigned int udba, unsigned char flags)
21214 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21216 + return au_do_pin(pin);
21219 +/* ---------------------------------------------------------------------- */
21222 + * ->setattr() and ->getattr() are called in various cases.
21223 + * chmod, stat: dentry is revalidated.
21224 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21226 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21228 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21229 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21232 + struct dentry *parent;
21235 + if (au_digen_test(dentry, sigen)) {
21236 + parent = dget_parent(dentry);
21237 + di_read_lock_parent(parent, AuLock_IR);
21238 + err = au_refresh_dentry(dentry, parent);
21239 + di_read_unlock(parent, AuLock_IR);
21247 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21248 + struct au_icpup_args *a)
21252 + aufs_bindex_t btop, ibtop;
21253 + struct dentry *hi_wh, *parent;
21254 + struct inode *inode;
21255 + struct au_wr_dir_args wr_dir_args = {
21256 + .force_btgt = -1,
21260 + if (d_is_dir(dentry))
21261 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21262 + /* plink or hi_wh() case */
21263 + btop = au_dbtop(dentry);
21264 + inode = d_inode(dentry);
21265 + ibtop = au_ibtop(inode);
21266 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21267 + wr_dir_args.force_btgt = ibtop;
21268 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21269 + if (unlikely(err < 0))
21273 + au_fset_icpup(a->flags, DID_CPUP);
21276 + a->pin_flags = AuPin_MNT_WRITE;
21278 + if (!IS_ROOT(dentry)) {
21279 + au_fset_pin(a->pin_flags, DI_LOCKED);
21280 + parent = dget_parent(dentry);
21281 + di_write_lock_parent(parent);
21284 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21285 + if (unlikely(err))
21289 + a->h_path.dentry = au_h_dptr(dentry, btop);
21290 + a->h_inode = d_inode(a->h_path.dentry);
21291 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21292 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21293 + if (ia->ia_size < i_size_read(a->h_inode))
21294 + sz = ia->ia_size;
21295 + inode_unlock_shared(a->h_inode);
21299 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21300 + hi_wh = au_hi_wh(inode, a->btgt);
21302 + struct au_cp_generic cpg = {
21303 + .dentry = dentry,
21309 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21310 + if (unlikely(err))
21312 + hi_wh = au_hi_wh(inode, a->btgt);
21313 + /* todo: revalidate hi_wh? */
21318 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21319 + di_downgrade_lock(parent, AuLock_IR);
21323 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21324 + goto out; /* success */
21326 + if (!d_unhashed(dentry)) {
21327 + struct au_cp_generic cpg = {
21328 + .dentry = dentry,
21333 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21335 + err = au_sio_cpup_simple(&cpg);
21337 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21338 + } else if (!hi_wh)
21339 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21341 + a->h_path.dentry = hi_wh; /* do not dget here */
21344 + a->h_inode = d_inode(a->h_path.dentry);
21346 + goto out; /* success */
21347 + au_unpin(&a->pin);
21350 + di_write_unlock(parent);
21355 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21359 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
21360 + struct iattr *ia)
21363 + struct inode *inode, *delegated;
21364 + struct super_block *sb;
21365 + struct file *file;
21366 + struct au_icpup_args *a;
21367 + struct user_namespace *h_userns;
21369 + inode = d_inode(dentry);
21370 + IMustLock(inode);
21372 + err = setattr_prepare(userns, dentry, ia);
21373 + if (unlikely(err))
21377 + a = kzalloc(sizeof(*a), GFP_NOFS);
21378 + if (unlikely(!a))
21381 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21382 + ia->ia_valid &= ~ATTR_MODE;
21385 + sb = dentry->d_sb;
21386 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21387 + if (unlikely(err))
21390 + if (ia->ia_valid & ATTR_FILE) {
21391 + /* currently ftruncate(2) only */
21392 + AuDebugOn(!d_is_reg(dentry));
21393 + file = ia->ia_file;
21394 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21396 + if (unlikely(err))
21398 + ia->ia_file = au_hf_top(file);
21399 + a->udba = AuOpt_UDBA_NONE;
21401 + /* fchmod() doesn't pass ia_file */
21402 + a->udba = au_opt_udba(sb);
21403 + di_write_lock_child(dentry);
21404 + /* no d_unlinked(), to set UDBA_NONE for root */
21405 + if (d_unhashed(dentry))
21406 + a->udba = AuOpt_UDBA_NONE;
21407 + if (a->udba != AuOpt_UDBA_NONE) {
21408 + AuDebugOn(IS_ROOT(dentry));
21409 + err = au_reval_for_attr(dentry, au_sigen(sb));
21410 + if (unlikely(err))
21415 + err = au_pin_and_icpup(dentry, ia, a);
21416 + if (unlikely(err < 0))
21418 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21419 + ia->ia_file = NULL;
21420 + ia->ia_valid &= ~ATTR_FILE;
21423 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21424 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21425 + == (ATTR_MODE | ATTR_CTIME)) {
21426 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21427 + if (unlikely(err))
21429 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21430 + && (ia->ia_valid & ATTR_CTIME)) {
21431 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21432 + if (unlikely(err))
21436 + if (ia->ia_valid & ATTR_SIZE) {
21439 + if (ia->ia_size < i_size_read(inode))
21441 + truncate_setsize(inode, ia->ia_size);
21444 + if (ia->ia_valid & ATTR_FILE)
21446 + inode_unlock(a->h_inode);
21447 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21448 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21450 + delegated = NULL;
21452 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21454 + err = break_deleg_wait(&delegated);
21462 + * regardless aufs 'acl' option setting.
21463 + * why don't all acl-aware fs call this func from their ->setattr()?
21465 + if (!err && (ia->ia_valid & ATTR_MODE)) {
21466 + h_userns = mnt_user_ns(a->h_path.mnt);
21467 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
21470 + au_cpup_attr_changeable(inode);
21473 + inode_unlock(a->h_inode);
21474 + au_unpin(&a->pin);
21475 + if (unlikely(err))
21476 + au_update_dbtop(dentry);
21478 + di_write_unlock(dentry);
21480 + fi_write_unlock(file);
21481 + ia->ia_file = file;
21482 + ia->ia_valid |= ATTR_FILE;
21485 + si_read_unlock(sb);
21493 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21494 +static int au_h_path_to_set_attr(struct dentry *dentry,
21495 + struct au_icpup_args *a, struct path *h_path)
21498 + struct super_block *sb;
21500 + sb = dentry->d_sb;
21501 + a->udba = au_opt_udba(sb);
21502 + /* no d_unlinked(), to set UDBA_NONE for root */
21503 + if (d_unhashed(dentry))
21504 + a->udba = AuOpt_UDBA_NONE;
21505 + if (a->udba != AuOpt_UDBA_NONE) {
21506 + AuDebugOn(IS_ROOT(dentry));
21507 + err = au_reval_for_attr(dentry, au_sigen(sb));
21508 + if (unlikely(err))
21511 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21512 + if (unlikely(err < 0))
21515 + h_path->dentry = a->h_path.dentry;
21516 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21522 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21523 + struct au_sxattr *arg)
21526 + struct path h_path;
21527 + struct super_block *sb;
21528 + struct au_icpup_args *a;
21529 + struct inode *h_inode;
21530 + struct user_namespace *h_userns;
21532 + IMustLock(inode);
21535 + a = kzalloc(sizeof(*a), GFP_NOFS);
21536 + if (unlikely(!a))
21539 + sb = dentry->d_sb;
21540 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21541 + if (unlikely(err))
21544 + h_path.dentry = NULL; /* silence gcc */
21545 + di_write_lock_child(dentry);
21546 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21547 + if (unlikely(err))
21549 + h_userns = mnt_user_ns(h_path.mnt);
21551 + inode_unlock(a->h_inode);
21552 + switch (arg->type) {
21553 + case AU_XATTR_SET:
21554 + AuDebugOn(d_is_negative(h_path.dentry));
21555 + err = vfsub_setxattr(h_userns, h_path.dentry,
21556 + arg->u.set.name, arg->u.set.value,
21557 + arg->u.set.size, arg->u.set.flags);
21560 + err = -EOPNOTSUPP;
21561 + h_inode = d_inode(h_path.dentry);
21562 + if (h_inode->i_op->set_acl) {
21563 + /* this will call posix_acl_update_mode */
21564 + err = h_inode->i_op->set_acl(h_userns, h_inode,
21565 + arg->u.acl_set.acl,
21566 + arg->u.acl_set.type);
21571 + au_cpup_attr_timesizes(inode);
21573 + au_unpin(&a->pin);
21574 + if (unlikely(err))
21575 + au_update_dbtop(dentry);
21578 + di_write_unlock(dentry);
21579 + si_read_unlock(sb);
21588 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21589 + unsigned int nlink)
21593 + inode->i_mode = st->mode;
21594 + /* don't i_[ug]id_write() here */
21595 + inode->i_uid = st->uid;
21596 + inode->i_gid = st->gid;
21597 + inode->i_atime = st->atime;
21598 + inode->i_mtime = st->mtime;
21599 + inode->i_ctime = st->ctime;
21601 + au_cpup_attr_nlink(inode, /*force*/0);
21602 + if (S_ISDIR(inode->i_mode)) {
21603 + n = inode->i_nlink;
21606 + smp_mb(); /* for i_nlink */
21607 + /* 0 can happen */
21608 + set_nlink(inode, n);
21611 + spin_lock(&inode->i_lock);
21612 + inode->i_blocks = st->blocks;
21613 + i_size_write(inode, st->size);
21614 + spin_unlock(&inode->i_lock);
21618 + * common routine for aufs_getattr() and au_getxattr().
21619 + * returns zero or negative (an error).
21620 + * @dentry will be read-locked in success.
21622 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21623 + struct path *h_path, int locked)
21626 + unsigned int mnt_flags, sigen;
21627 + unsigned char udba_none;
21628 + aufs_bindex_t bindex;
21629 + struct super_block *sb, *h_sb;
21631 + h_path->mnt = NULL;
21632 + h_path->dentry = NULL;
21635 + sb = dentry->d_sb;
21636 + mnt_flags = au_mntflags(sb);
21637 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21639 + if (unlikely(locked))
21640 + goto body; /* skip locking dinfo */
21642 + /* support fstat(2) */
21643 + if (!d_unlinked(dentry) && !udba_none) {
21644 + sigen = au_sigen(sb);
21645 + err = au_digen_test(dentry, sigen);
21647 + di_read_lock_child(dentry, AuLock_IR);
21648 + err = au_dbrange_test(dentry);
21649 + if (unlikely(err)) {
21650 + di_read_unlock(dentry, AuLock_IR);
21654 + AuDebugOn(IS_ROOT(dentry));
21655 + di_write_lock_child(dentry);
21656 + err = au_dbrange_test(dentry);
21658 + err = au_reval_for_attr(dentry, sigen);
21660 + di_downgrade_lock(dentry, AuLock_IR);
21662 + di_write_unlock(dentry);
21667 + di_read_lock_child(dentry, AuLock_IR);
21671 + inode = d_inode(dentry);
21672 + if (unlikely(!inode))
21675 + bindex = au_ibtop(inode);
21676 + h_path->mnt = au_sbr_mnt(sb, bindex);
21677 + h_sb = h_path->mnt->mnt_sb;
21679 + && !au_test_fs_bad_iattr(h_sb)
21681 + goto out; /* success */
21683 + if (au_dbtop(dentry) == bindex)
21684 + h_path->dentry = au_h_dptr(dentry, bindex);
21685 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21686 + h_path->dentry = au_plink_lkup(inode, bindex);
21687 + if (IS_ERR(h_path->dentry))
21688 + /* pretending success */
21689 + h_path->dentry = NULL;
21691 + dput(h_path->dentry);
21698 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
21699 + struct kstat *st, u32 request, unsigned int query)
21702 + unsigned char positive;
21703 + struct path h_path;
21704 + struct dentry *dentry;
21705 + struct inode *inode;
21706 + struct super_block *sb;
21708 + dentry = path->dentry;
21709 + inode = d_inode(dentry);
21710 + sb = dentry->d_sb;
21711 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21712 + if (unlikely(err))
21714 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21716 + if (unlikely(err))
21718 + if (unlikely(!h_path.dentry))
21719 + /* illegally overlapped or something */
21720 + goto out_fill; /* pretending success */
21722 + positive = d_is_positive(h_path.dentry);
21724 + /* no vfsub version */
21725 + err = vfs_getattr(&h_path, st, request, query);
21728 + au_refresh_iattr(inode, st,
21729 + d_inode(h_path.dentry)->i_nlink);
21730 + goto out_fill; /* success */
21736 + generic_fillattr(userns, inode, st);
21738 + di_read_unlock(dentry, AuLock_IR);
21740 + si_read_unlock(sb);
21746 +/* ---------------------------------------------------------------------- */
21748 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21749 + struct delayed_call *done)
21752 + struct dentry *h_dentry;
21753 + struct inode *h_inode;
21755 + aufs_bindex_t bindex;
21757 + ret = NULL; /* suppress a warning */
21762 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21763 + if (unlikely(err))
21766 + err = au_d_hashed_positive(dentry);
21767 + if (unlikely(err))
21771 + inode = d_inode(dentry);
21772 + bindex = au_ibtop(inode);
21773 + h_inode = au_h_iptr(inode, bindex);
21774 + if (unlikely(!h_inode->i_op->get_link))
21779 + if (au_dbtop(dentry) <= bindex) {
21780 + h_dentry = au_h_dptr(dentry, bindex);
21785 + h_dentry = d_find_any_alias(h_inode);
21786 + if (IS_ERR(h_dentry)) {
21787 + err = PTR_ERR(h_dentry);
21791 + if (unlikely(!h_dentry))
21795 + AuDbg("%ps\n", h_inode->i_op->get_link);
21796 + AuDbgDentry(h_dentry);
21797 + ret = vfs_get_link(h_dentry, done);
21800 + err = PTR_ERR(ret);
21803 + aufs_read_unlock(dentry, AuLock_IR);
21805 + if (unlikely(err))
21806 + ret = ERR_PTR(err);
21807 + AuTraceErrPtr(ret);
21811 +/* ---------------------------------------------------------------------- */
21813 +static int au_is_special(struct inode *inode)
21815 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21818 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21822 + aufs_bindex_t bindex;
21823 + struct super_block *sb;
21824 + struct inode *h_inode;
21825 + struct vfsmount *h_mnt;
21827 + sb = inode->i_sb;
21828 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21829 + "unexpected s_flags 0x%lx", sb->s_flags);
21831 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21833 + si_read_lock(sb, AuLock_FLUSH);
21834 + ii_write_lock_child(inode);
21837 + bindex = au_ibtop(inode);
21838 + h_inode = au_h_iptr(inode, bindex);
21839 + if (!au_test_ro(sb, bindex, inode)) {
21840 + h_mnt = au_sbr_mnt(sb, bindex);
21841 + err = vfsub_mnt_want_write(h_mnt);
21843 + err = vfsub_update_time(h_inode, ts, flags);
21844 + vfsub_mnt_drop_write(h_mnt);
21846 + } else if (au_is_special(h_inode)) {
21848 + * Never copy-up here.
21849 + * These special files may already be opened and used for
21850 + * communicating. If we copied it up, then the communication
21851 + * would be corrupted.
21853 + AuWarn1("timestamps for i%lu are ignored "
21854 + "since it is on readonly branch (hi%lu).\n",
21855 + inode->i_ino, h_inode->i_ino);
21856 + } else if (flags & ~S_ATIME) {
21858 + AuIOErr1("unexpected flags 0x%x\n", flags);
21863 + au_cpup_attr_timesizes(inode);
21864 + ii_write_unlock(inode);
21865 + si_read_unlock(sb);
21868 + if (!err && (flags & S_VERSION))
21869 + inode_inc_iversion(inode);
21874 +/* ---------------------------------------------------------------------- */
21876 +/* no getattr version will be set by module.c:aufs_init() */
21877 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21879 + [AuIop_SYMLINK] = {
21880 + .permission = aufs_permission,
21881 +#ifdef CONFIG_FS_POSIX_ACL
21882 + .get_acl = aufs_get_acl,
21883 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21886 + .setattr = aufs_setattr,
21887 + .getattr = aufs_getattr,
21889 +#ifdef CONFIG_AUFS_XATTR
21890 + .listxattr = aufs_listxattr,
21893 + .get_link = aufs_get_link,
21895 + /* .update_time = aufs_update_time */
21898 + .create = aufs_create,
21899 + .lookup = aufs_lookup,
21900 + .link = aufs_link,
21901 + .unlink = aufs_unlink,
21902 + .symlink = aufs_symlink,
21903 + .mkdir = aufs_mkdir,
21904 + .rmdir = aufs_rmdir,
21905 + .mknod = aufs_mknod,
21906 + .rename = aufs_rename,
21908 + .permission = aufs_permission,
21909 +#ifdef CONFIG_FS_POSIX_ACL
21910 + .get_acl = aufs_get_acl,
21911 + .set_acl = aufs_set_acl,
21914 + .setattr = aufs_setattr,
21915 + .getattr = aufs_getattr,
21917 +#ifdef CONFIG_AUFS_XATTR
21918 + .listxattr = aufs_listxattr,
21921 + .update_time = aufs_update_time,
21922 + .atomic_open = aufs_atomic_open,
21923 + .tmpfile = aufs_tmpfile
21925 + [AuIop_OTHER] = {
21926 + .permission = aufs_permission,
21927 +#ifdef CONFIG_FS_POSIX_ACL
21928 + .get_acl = aufs_get_acl,
21929 + .set_acl = aufs_set_acl,
21932 + .setattr = aufs_setattr,
21933 + .getattr = aufs_getattr,
21935 +#ifdef CONFIG_AUFS_XATTR
21936 + .listxattr = aufs_listxattr,
21939 + .update_time = aufs_update_time
21942 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21943 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21944 +++ linux/fs/aufs/i_op_del.c 2021-12-03 15:40:58.236647297 +0100
21946 +// SPDX-License-Identifier: GPL-2.0
21948 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21950 + * This program, aufs is free software; you can redistribute it and/or modify
21951 + * it under the terms of the GNU General Public License as published by
21952 + * the Free Software Foundation; either version 2 of the License, or
21953 + * (at your option) any later version.
21955 + * This program is distributed in the hope that it will be useful,
21956 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21957 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21958 + * GNU General Public License for more details.
21960 + * You should have received a copy of the GNU General Public License
21961 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21965 + * inode operations (del entry)
21968 +#include <linux/iversion.h>
21972 + * decide if a new whiteout for @dentry is necessary or not.
21973 + * when it is necessary, prepare the parent dir for the upper branch whose
21974 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21975 + * be done by caller.
21977 + * 0: wh is unnecessary
21978 + * plus: wh is necessary
21981 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21983 + int need_wh, err;
21984 + aufs_bindex_t btop;
21985 + struct super_block *sb;
21987 + sb = dentry->d_sb;
21988 + btop = au_dbtop(dentry);
21989 + if (*bcpup < 0) {
21991 + if (au_test_ro(sb, btop, d_inode(dentry))) {
21992 + err = AuWbrCopyup(au_sbi(sb), dentry);
21994 + if (unlikely(err < 0))
21998 + AuDebugOn(btop < *bcpup
21999 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22000 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22002 + if (*bcpup != btop) {
22003 + err = au_cpup_dirs(dentry, *bcpup);
22004 + if (unlikely(err))
22008 + struct au_dinfo *dinfo, *tmp;
22010 + need_wh = -ENOMEM;
22011 + dinfo = au_di(dentry);
22012 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22014 + au_di_cp(tmp, dinfo);
22015 + au_di_swap(tmp, dinfo);
22016 + /* returns the number of positive dentries */
22017 + need_wh = au_lkup_dentry(dentry, btop + 1,
22018 + /* AuLkup_IGNORE_PERM */ 0);
22019 + au_di_swap(tmp, dinfo);
22020 + au_rw_write_unlock(&tmp->di_rwsem);
22024 + AuDbg("need_wh %d\n", need_wh);
22032 + * simple tests for the del-entry operations.
22033 + * following the checks in vfs, plus the parent-child relationship.
22035 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22036 + struct dentry *h_parent, int isdir)
22040 + struct dentry *h_dentry, *h_latest;
22041 + struct inode *h_inode;
22042 + struct path h_ppath;
22043 + struct super_block *sb;
22044 + struct au_branch *br;
22045 + struct user_namespace *h_userns;
22047 + h_dentry = au_h_dptr(dentry, bindex);
22048 + if (d_really_is_positive(dentry)) {
22050 + if (unlikely(d_is_negative(h_dentry)))
22052 + h_inode = d_inode(h_dentry);
22053 + if (unlikely(!h_inode->i_nlink))
22056 + h_mode = h_inode->i_mode;
22059 + if (unlikely(S_ISDIR(h_mode)))
22061 + } else if (unlikely(!S_ISDIR(h_mode))) {
22066 + /* rename(2) case */
22068 + if (unlikely(d_is_positive(h_dentry)))
22073 + /* expected parent dir is locked */
22074 + if (unlikely(h_parent != h_dentry->d_parent))
22079 + * rmdir a dir may break the consistency on some filesystem.
22080 + * let's try heavy test.
22083 + sb = dentry->d_sb;
22084 + br = au_sbr(sb, bindex);
22085 + h_userns = au_br_userns(br);
22086 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
22087 + && au_test_h_perm(h_userns, d_inode(h_parent),
22088 + MAY_EXEC | MAY_WRITE)))
22091 + h_ppath.dentry = h_parent;
22092 + h_ppath.mnt = au_br_mnt(br);
22093 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
22095 + if (IS_ERR(h_latest))
22097 + if (h_latest == h_dentry)
22106 + * decide the branch where we operate for @dentry. the branch index will be set
22107 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22108 + * dir for reverting.
22109 + * when a new whiteout is necessary, create it.
22111 +static struct dentry*
22112 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22113 + struct au_dtime *dt, struct au_pin *pin)
22115 + struct dentry *wh_dentry;
22116 + struct super_block *sb;
22117 + struct path h_path;
22118 + int err, need_wh;
22119 + unsigned int udba;
22120 + aufs_bindex_t bcpup;
22122 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22123 + wh_dentry = ERR_PTR(need_wh);
22124 + if (unlikely(need_wh < 0))
22127 + sb = dentry->d_sb;
22128 + udba = au_opt_udba(sb);
22130 + err = au_pin(pin, dentry, bcpup, udba,
22131 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22132 + wh_dentry = ERR_PTR(err);
22133 + if (unlikely(err))
22136 + h_path.dentry = au_pinned_h_parent(pin);
22137 + if (udba != AuOpt_UDBA_NONE
22138 + && au_dbtop(dentry) == bcpup) {
22139 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22140 + wh_dentry = ERR_PTR(err);
22141 + if (unlikely(err))
22145 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22146 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22147 + wh_dentry = NULL;
22149 + goto out; /* success, no need to create whiteout */
22151 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22152 + if (IS_ERR(wh_dentry))
22155 + /* returns with the parent is locked and wh_dentry is dget-ed */
22156 + goto out; /* success */
22161 + return wh_dentry;
22165 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22166 + * in order to be revertible and save time for removing many child whiteouts
22168 + * returns 1 when there are too many child whiteout and caller should remove
22169 + * them asynchronously. returns 0 when the number of children is enough small to
22170 + * remove now or the branch fs is a remote fs.
22171 + * otherwise return an error.
22173 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22174 + struct au_nhash *whlist, struct inode *dir)
22176 + int rmdir_later, err, dirwh;
22177 + struct dentry *h_dentry;
22178 + struct super_block *sb;
22179 + struct inode *inode;
22181 + sb = dentry->d_sb;
22182 + SiMustAnyLock(sb);
22183 + h_dentry = au_h_dptr(dentry, bindex);
22184 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22185 + if (unlikely(err))
22188 + /* stop monitoring */
22189 + inode = d_inode(dentry);
22190 + au_hn_free(au_hi(inode, bindex));
22192 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22193 + dirwh = au_sbi(sb)->si_dirwh;
22194 + rmdir_later = (dirwh <= 1);
22195 + if (!rmdir_later)
22196 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22199 + return rmdir_later;
22202 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22203 + if (unlikely(err)) {
22204 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22205 + h_dentry, bindex, err);
22215 + * final procedure for deleting a entry.
22216 + * maintain dentry and iattr.
22218 +static void epilog(struct inode *dir, struct dentry *dentry,
22219 + aufs_bindex_t bindex)
22221 + struct inode *inode;
22223 + inode = d_inode(dentry);
22225 + inode->i_ctime = dir->i_ctime;
22227 + au_dir_ts(dir, bindex);
22228 + inode_inc_iversion(dir);
22232 + * when an error happened, remove the created whiteout and revert everything.
22234 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22235 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22236 + struct dentry *dentry, struct au_dtime *dt)
22239 + struct path h_path = {
22240 + .dentry = wh_dentry,
22241 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22244 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22246 + au_set_dbwh(dentry, bwh);
22247 + au_dtime_revert(dt);
22251 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22255 +/* ---------------------------------------------------------------------- */
22257 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22260 + aufs_bindex_t bwh, bindex, btop;
22261 + struct inode *inode, *h_dir, *delegated;
22262 + struct dentry *parent, *wh_dentry;
22263 + /* to reduce stack size */
22265 + struct au_dtime dt;
22266 + struct au_pin pin;
22267 + struct path h_path;
22273 + a = kmalloc(sizeof(*a), GFP_NOFS);
22274 + if (unlikely(!a))
22277 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22278 + if (unlikely(err))
22280 + err = au_d_hashed_positive(dentry);
22281 + if (unlikely(err))
22283 + inode = d_inode(dentry);
22284 + IMustLock(inode);
22286 + if (unlikely(d_is_dir(dentry)))
22287 + goto out_unlock; /* possible? */
22289 + btop = au_dbtop(dentry);
22290 + bwh = au_dbwh(dentry);
22292 + parent = dentry->d_parent; /* dir inode is locked */
22293 + di_write_lock_parent(parent);
22294 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22296 + err = PTR_ERR(wh_dentry);
22297 + if (IS_ERR(wh_dentry))
22300 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22301 + a->h_path.dentry = au_h_dptr(dentry, btop);
22302 + dget(a->h_path.dentry);
22303 + if (bindex == btop) {
22304 + h_dir = au_pinned_h_dir(&a->pin);
22305 + delegated = NULL;
22306 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22307 + if (unlikely(err == -EWOULDBLOCK)) {
22308 + pr_warn("cannot retry for NFSv4 delegation"
22309 + " for an internal unlink\n");
22313 + /* dir inode is locked */
22314 + h_dir = d_inode(wh_dentry->d_parent);
22315 + IMustLock(h_dir);
22320 + vfsub_drop_nlink(inode);
22321 + epilog(dir, dentry, bindex);
22323 + /* update target timestamps */
22324 + if (bindex == btop) {
22325 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22327 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22329 + /* todo: this timestamp may be reverted later */
22330 + inode->i_ctime = h_dir->i_ctime;
22331 + goto out_unpin; /* success */
22338 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22345 + au_unpin(&a->pin);
22347 + dput(a->h_path.dentry);
22349 + di_write_unlock(parent);
22351 + aufs_read_unlock(dentry, AuLock_DW);
22358 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22360 + int err, rmdir_later;
22361 + aufs_bindex_t bwh, bindex, btop;
22362 + struct inode *inode;
22363 + struct dentry *parent, *wh_dentry, *h_dentry;
22364 + struct au_whtmp_rmdir *args;
22365 + /* to reduce stack size */
22367 + struct au_dtime dt;
22368 + struct au_pin pin;
22374 + a = kmalloc(sizeof(*a), GFP_NOFS);
22375 + if (unlikely(!a))
22378 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22379 + if (unlikely(err))
22381 + err = au_alive_dir(dentry);
22382 + if (unlikely(err))
22384 + inode = d_inode(dentry);
22385 + IMustLock(inode);
22387 + if (unlikely(!d_is_dir(dentry)))
22388 + goto out_unlock; /* possible? */
22391 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22392 + if (unlikely(!args))
22395 + parent = dentry->d_parent; /* dir inode is locked */
22396 + di_write_lock_parent(parent);
22397 + err = au_test_empty(dentry, &args->whlist);
22398 + if (unlikely(err))
22401 + btop = au_dbtop(dentry);
22402 + bwh = au_dbwh(dentry);
22404 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22406 + err = PTR_ERR(wh_dentry);
22407 + if (IS_ERR(wh_dentry))
22410 + h_dentry = au_h_dptr(dentry, btop);
22413 + if (bindex == btop) {
22414 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22416 + rmdir_later = err;
22420 + /* stop monitoring */
22421 + au_hn_free(au_hi(inode, btop));
22423 + /* dir inode is locked */
22424 + IMustLock(d_inode(wh_dentry->d_parent));
22429 + vfsub_dead_dir(inode);
22430 + au_set_dbdiropq(dentry, -1);
22431 + epilog(dir, dentry, bindex);
22433 + if (rmdir_later) {
22434 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22438 + goto out_unpin; /* success */
22446 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22453 + au_unpin(&a->pin);
22457 + di_write_unlock(parent);
22459 + au_whtmp_rmdir_free(args);
22461 + aufs_read_unlock(dentry, AuLock_DW);
22468 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22469 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22470 +++ linux/fs/aufs/i_op_ren.c 2021-12-03 15:40:58.236647297 +0100
22472 +// SPDX-License-Identifier: GPL-2.0
22474 + * Copyright (C) 2005-2021 Junjiro R. Okajima
22476 + * This program, aufs is free software; you can redistribute it and/or modify
22477 + * it under the terms of the GNU General Public License as published by
22478 + * the Free Software Foundation; either version 2 of the License, or
22479 + * (at your option) any later version.
22481 + * This program is distributed in the hope that it will be useful,
22482 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22483 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22484 + * GNU General Public License for more details.
22486 + * You should have received a copy of the GNU General Public License
22487 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22491 + * inode operation (rename entry)
22492 + * todo: this is crazy monster
22495 +#include <linux/iversion.h>
22498 +enum { AuSRC, AuDST, AuSrcDst };
22499 +enum { AuPARENT, AuCHILD, AuParentChild };
22501 +#define AuRen_ISDIR_SRC 1
22502 +#define AuRen_ISDIR_DST (1 << 1)
22503 +#define AuRen_ISSAMEDIR (1 << 2)
22504 +#define AuRen_WHSRC (1 << 3)
22505 +#define AuRen_WHDST (1 << 4)
22506 +#define AuRen_MNT_WRITE (1 << 5)
22507 +#define AuRen_DT_DSTDIR (1 << 6)
22508 +#define AuRen_DIROPQ_SRC (1 << 7)
22509 +#define AuRen_DIROPQ_DST (1 << 8)
22510 +#define AuRen_DIRREN (1 << 9)
22511 +#define AuRen_DROPPED_SRC (1 << 10)
22512 +#define AuRen_DROPPED_DST (1 << 11)
22513 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22514 +#define au_fset_ren(flags, name) \
22515 + do { (flags) |= AuRen_##name; } while (0)
22516 +#define au_fclr_ren(flags, name) \
22517 + do { (flags) &= ~AuRen_##name; } while (0)
22519 +#ifndef CONFIG_AUFS_DIRREN
22520 +#undef AuRen_DIRREN
22521 +#define AuRen_DIRREN 0
22524 +struct au_ren_args {
22526 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22528 + struct inode *dir, *inode;
22529 + struct au_hinode *hdir, *hinode;
22530 + struct au_dtime dt[AuParentChild];
22531 + aufs_bindex_t btop, bdiropq;
22534 +#define src_dentry sd[AuSRC].dentry
22535 +#define src_dir sd[AuSRC].dir
22536 +#define src_inode sd[AuSRC].inode
22537 +#define src_h_dentry sd[AuSRC].h_dentry
22538 +#define src_parent sd[AuSRC].parent
22539 +#define src_h_parent sd[AuSRC].h_parent
22540 +#define src_wh_dentry sd[AuSRC].wh_dentry
22541 +#define src_hdir sd[AuSRC].hdir
22542 +#define src_hinode sd[AuSRC].hinode
22543 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22544 +#define src_dt sd[AuSRC].dt
22545 +#define src_btop sd[AuSRC].btop
22546 +#define src_bdiropq sd[AuSRC].bdiropq
22548 +#define dst_dentry sd[AuDST].dentry
22549 +#define dst_dir sd[AuDST].dir
22550 +#define dst_inode sd[AuDST].inode
22551 +#define dst_h_dentry sd[AuDST].h_dentry
22552 +#define dst_parent sd[AuDST].parent
22553 +#define dst_h_parent sd[AuDST].h_parent
22554 +#define dst_wh_dentry sd[AuDST].wh_dentry
22555 +#define dst_hdir sd[AuDST].hdir
22556 +#define dst_hinode sd[AuDST].hinode
22557 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22558 +#define dst_dt sd[AuDST].dt
22559 +#define dst_btop sd[AuDST].btop
22560 +#define dst_bdiropq sd[AuDST].bdiropq
22562 + struct dentry *h_trap;
22563 + struct au_branch *br;
22564 + struct path h_path;
22565 + struct au_nhash whlist;
22566 + aufs_bindex_t btgt, src_bwh;
22569 + unsigned short auren_flags;
22570 + unsigned char flags; /* syscall parameter */
22571 + unsigned char exchange;
22574 + struct au_whtmp_rmdir *thargs;
22575 + struct dentry *h_dst;
22576 + struct au_hinode *h_root;
22579 +/* ---------------------------------------------------------------------- */
22582 + * functions for reverting.
22583 + * when an error happened in a single rename systemcall, we should revert
22584 + * everything as if nothing happened.
22585 + * we don't need to revert the copied-up/down the parent dir since they are
22589 +#define RevertFailure(fmt, ...) do { \
22590 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22591 + ##__VA_ARGS__, err, rerr); \
22595 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22598 + struct dentry *d;
22599 +#define src_or_dst(member) a->sd[idx].member
22601 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22602 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22603 + rerr = au_diropq_remove(d, a->btgt);
22604 + au_hn_inode_unlock(src_or_dst(hinode));
22605 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22607 + RevertFailure("remove diropq %pd", d);
22609 +#undef src_or_dst_
22612 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22614 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22615 + au_ren_do_rev_diropq(err, a, AuSRC);
22616 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22617 + au_ren_do_rev_diropq(err, a, AuDST);
22620 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22623 + struct inode *delegated;
22624 + struct path h_ppath = {
22625 + .dentry = a->src_h_parent,
22626 + .mnt = a->h_path.mnt
22629 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
22630 + rerr = PTR_ERR(a->h_path.dentry);
22631 + if (IS_ERR(a->h_path.dentry)) {
22632 + RevertFailure("lkup one %pd", a->src_dentry);
22636 + delegated = NULL;
22637 + rerr = vfsub_rename(a->dst_h_dir,
22638 + au_h_dptr(a->src_dentry, a->btgt),
22639 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22640 + if (unlikely(rerr == -EWOULDBLOCK)) {
22641 + pr_warn("cannot retry for NFSv4 delegation"
22642 + " for an internal rename\n");
22645 + d_drop(a->h_path.dentry);
22646 + dput(a->h_path.dentry);
22647 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22649 + RevertFailure("rename %pd", a->src_dentry);
22652 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22655 + struct inode *delegated;
22656 + struct path h_ppath = {
22657 + .dentry = a->dst_h_parent,
22658 + .mnt = a->h_path.mnt
22661 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
22662 + rerr = PTR_ERR(a->h_path.dentry);
22663 + if (IS_ERR(a->h_path.dentry)) {
22664 + RevertFailure("lkup one %pd", a->dst_dentry);
22667 + if (d_is_positive(a->h_path.dentry)) {
22668 + d_drop(a->h_path.dentry);
22669 + dput(a->h_path.dentry);
22673 + delegated = NULL;
22674 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22675 + &delegated, a->flags);
22676 + if (unlikely(rerr == -EWOULDBLOCK)) {
22677 + pr_warn("cannot retry for NFSv4 delegation"
22678 + " for an internal rename\n");
22681 + d_drop(a->h_path.dentry);
22682 + dput(a->h_path.dentry);
22684 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22686 + RevertFailure("rename %pd", a->h_dst);
22689 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22693 + a->h_path.dentry = a->src_wh_dentry;
22694 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22695 + au_set_dbwh(a->src_dentry, a->src_bwh);
22697 + RevertFailure("unlink %pd", a->src_wh_dentry);
22699 +#undef RevertFailure
22701 +/* ---------------------------------------------------------------------- */
22704 + * when we have to copyup the renaming entry, do it with the rename-target name
22705 + * in order to minimize the cost (the later actual rename is unnecessary).
22706 + * otherwise rename it on the target branch.
22708 +static int au_ren_or_cpup(struct au_ren_args *a)
22711 + struct dentry *d;
22712 + struct inode *delegated;
22714 + d = a->src_dentry;
22715 + if (au_dbtop(d) == a->btgt) {
22716 + a->h_path.dentry = a->dst_h_dentry;
22717 + AuDebugOn(au_dbtop(d) != a->btgt);
22718 + delegated = NULL;
22719 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22720 + a->dst_h_dir, &a->h_path, &delegated,
22722 + if (unlikely(err == -EWOULDBLOCK)) {
22723 + pr_warn("cannot retry for NFSv4 delegation"
22724 + " for an internal rename\n");
22730 + if (!err && a->h_dst)
22731 + /* it will be set to dinfo later */
22737 +/* cf. aufs_rmdir() */
22738 +static int au_ren_del_whtmp(struct au_ren_args *a)
22741 + struct inode *dir;
22743 + dir = a->dst_dir;
22744 + SiMustAnyLock(dir->i_sb);
22745 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22746 + au_sbi(dir->i_sb)->si_dirwh)
22747 + || au_test_fs_remote(a->h_dst->d_sb)) {
22748 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22749 + if (unlikely(err))
22750 + pr_warn("failed removing whtmp dir %pd (%d), "
22751 + "ignored.\n", a->h_dst, err);
22753 + au_nhash_wh_free(&a->thargs->whlist);
22754 + a->thargs->whlist = a->whlist;
22755 + a->whlist.nh_num = 0;
22756 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22758 + a->thargs = NULL;
22764 +/* make it 'opaque' dir. */
22765 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22768 + struct dentry *d, *diropq;
22769 +#define src_or_dst(member) a->sd[idx].member
22772 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22773 + src_or_dst(bdiropq) = au_dbdiropq(d);
22774 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22775 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22776 + diropq = au_diropq_create(d, a->btgt);
22777 + au_hn_inode_unlock(src_or_dst(hinode));
22778 + if (IS_ERR(diropq))
22779 + err = PTR_ERR(diropq);
22783 +#undef src_or_dst_
22787 +static int au_ren_diropq(struct au_ren_args *a)
22790 + unsigned char always;
22791 + struct dentry *d;
22794 + d = a->dst_dentry; /* already renamed on the branch */
22795 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22796 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22797 + && !au_ftest_ren(a->auren_flags, DIRREN)
22798 + && a->btgt != au_dbdiropq(a->src_dentry)
22799 + && (a->dst_wh_dentry
22800 + || a->btgt <= au_dbdiropq(d)
22801 + /* hide the lower to keep xino */
22802 + /* the lowers may not be a dir, but we hide them anyway */
22803 + || a->btgt < au_dbbot(d)
22806 + err = au_ren_do_diropq(a, AuSRC);
22807 + if (unlikely(err))
22809 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22811 + if (!a->exchange)
22812 + goto out; /* success */
22814 + d = a->src_dentry; /* already renamed on the branch */
22815 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22816 + && a->btgt != au_dbdiropq(a->dst_dentry)
22817 + && (a->btgt < au_dbdiropq(d)
22818 + || a->btgt < au_dbbot(d)
22820 + AuDbgDentry(a->src_dentry);
22821 + AuDbgDentry(a->dst_dentry);
22822 + err = au_ren_do_diropq(a, AuDST);
22823 + if (unlikely(err))
22824 + goto out_rev_src;
22825 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22827 + goto out; /* success */
22830 + AuDbg("err %d, reverting src\n", err);
22831 + au_ren_rev_diropq(err, a);
22836 +static int do_rename(struct au_ren_args *a)
22839 + struct dentry *d, *h_d;
22841 + if (!a->exchange) {
22842 + /* prepare workqueue args for asynchronous rmdir */
22843 + h_d = a->dst_h_dentry;
22844 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22845 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22846 + && d_is_positive(h_d)) {
22848 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22850 + if (unlikely(!a->thargs))
22852 + a->h_dst = dget(h_d);
22855 + /* create whiteout for src_dentry */
22856 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22857 + a->src_bwh = au_dbwh(a->src_dentry);
22858 + AuDebugOn(a->src_bwh >= 0);
22859 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22860 + a->src_h_parent);
22861 + err = PTR_ERR(a->src_wh_dentry);
22862 + if (IS_ERR(a->src_wh_dentry))
22866 + /* lookup whiteout for dentry */
22867 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22868 + h_d = au_wh_lkup(a->dst_h_parent,
22869 + &a->dst_dentry->d_name, a->br);
22870 + err = PTR_ERR(h_d);
22873 + if (d_is_negative(h_d))
22876 + a->dst_wh_dentry = h_d;
22879 + /* rename dentry to tmpwh */
22881 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22882 + if (unlikely(err))
22885 + d = a->dst_dentry;
22886 + au_set_h_dptr(d, a->btgt, NULL);
22887 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22888 + if (unlikely(err))
22890 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22894 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22895 +#if 0 /* debugging */
22896 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22897 + && d_is_positive(a->dst_h_dentry)
22898 + && a->src_btop != a->btgt);
22901 + /* rename by vfs_rename or cpup */
22902 + err = au_ren_or_cpup(a);
22903 + if (unlikely(err))
22904 + /* leave the copied-up one */
22907 + /* make dir opaque */
22908 + err = au_ren_diropq(a);
22909 + if (unlikely(err))
22912 + /* update target timestamps */
22913 + if (a->exchange) {
22914 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22915 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22916 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22917 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22919 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22920 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22921 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22922 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22924 + if (!a->exchange) {
22925 + /* remove whiteout for dentry */
22926 + if (a->dst_wh_dentry) {
22927 + a->h_path.dentry = a->dst_wh_dentry;
22928 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22930 + if (unlikely(err))
22934 + /* remove whtmp */
22936 + au_ren_del_whtmp(a); /* ignore this error */
22938 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22941 + goto out_success;
22944 + au_ren_rev_diropq(err, a);
22946 + au_ren_rev_rename(err, a);
22950 + au_ren_rev_whtmp(err, a);
22952 + dput(a->dst_wh_dentry);
22953 + a->dst_wh_dentry = NULL;
22955 + if (a->src_wh_dentry)
22956 + au_ren_rev_whsrc(err, a);
22958 + dput(a->src_wh_dentry);
22959 + dput(a->dst_wh_dentry);
22963 + au_whtmp_rmdir_free(a->thargs);
22964 + a->thargs = NULL;
22970 +/* ---------------------------------------------------------------------- */
22973 + * test if @dentry dir can be rename destination or not.
22974 + * success means, it is a logically empty dir.
22976 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22978 + return au_test_empty(dentry, whlist);
22982 + * test if @a->src_dentry dir can be rename source or not.
22983 + * if it can, return 0.
22985 + * - it is a logically empty dir.
22986 + * - or, it exists on writable branch and has no children including whiteouts
22987 + * on the lower branch unless DIRREN is on.
22989 +static int may_rename_srcdir(struct au_ren_args *a)
22992 + unsigned int rdhash;
22993 + aufs_bindex_t btop, btgt;
22994 + struct dentry *dentry;
22995 + struct super_block *sb;
22996 + struct au_sbinfo *sbinfo;
22998 + dentry = a->src_dentry;
22999 + sb = dentry->d_sb;
23000 + sbinfo = au_sbi(sb);
23001 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23002 + au_fset_ren(a->auren_flags, DIRREN);
23005 + btop = au_dbtop(dentry);
23006 + if (btop != btgt) {
23007 + struct au_nhash whlist;
23009 + SiMustAnyLock(sb);
23010 + rdhash = sbinfo->si_rdhash;
23012 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23014 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23015 + if (unlikely(err))
23017 + err = au_test_empty(dentry, &whlist);
23018 + au_nhash_wh_free(&whlist);
23022 + if (btop == au_dbtaildir(dentry))
23023 + return 0; /* success */
23025 + err = au_test_empty_lower(dentry);
23028 + if (err == -ENOTEMPTY) {
23029 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23032 + AuWarn1("renaming dir who has child(ren) on multiple "
23033 + "branches, is not supported\n");
23040 +/* side effect: sets whlist and h_dentry */
23041 +static int au_ren_may_dir(struct au_ren_args *a)
23044 + unsigned int rdhash;
23045 + struct dentry *d;
23047 + d = a->dst_dentry;
23048 + SiMustAnyLock(d->d_sb);
23051 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23052 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23054 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23055 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23056 + if (unlikely(err))
23059 + if (!a->exchange) {
23060 + au_set_dbtop(d, a->dst_btop);
23061 + err = may_rename_dstdir(d, &a->whlist);
23062 + au_set_dbtop(d, a->btgt);
23064 + err = may_rename_srcdir(a);
23066 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23067 + if (unlikely(err))
23070 + d = a->src_dentry;
23071 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23072 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23073 + err = may_rename_srcdir(a);
23074 + if (unlikely(err)) {
23075 + au_nhash_wh_free(&a->whlist);
23076 + a->whlist.nh_num = 0;
23083 +/* ---------------------------------------------------------------------- */
23086 + * simple tests for rename.
23087 + * following the checks in vfs, plus the parent-child relationship.
23089 +static int au_may_ren(struct au_ren_args *a)
23092 + struct inode *h_inode;
23094 + if (a->src_btop == a->btgt) {
23095 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23096 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23097 + if (unlikely(err))
23100 + if (unlikely(a->src_h_dentry == a->h_trap))
23105 + if (a->dst_btop != a->btgt)
23108 + err = -ENOTEMPTY;
23109 + if (unlikely(a->dst_h_dentry == a->h_trap))
23113 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23114 + if (d_really_is_negative(a->dst_dentry)) {
23115 + if (d_is_negative(a->dst_h_dentry))
23116 + err = au_may_add(a->dst_dentry, a->btgt,
23117 + a->dst_h_parent, isdir);
23119 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23121 + h_inode = d_inode(a->dst_h_dentry);
23122 + if (h_inode->i_nlink)
23123 + err = au_may_del(a->dst_dentry, a->btgt,
23124 + a->dst_h_parent, isdir);
23128 + if (unlikely(err == -ENOENT || err == -EEXIST))
23134 +/* ---------------------------------------------------------------------- */
23139 + * - src_dir and dir by lock_rename()
23140 + * - inode if exists
23143 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23145 + * + di_write_lock2_child()
23146 + * + di_write_lock_child()
23147 + * + ii_write_lock_child()
23148 + * + di_write_lock_child2()
23149 + * + ii_write_lock_child2()
23150 + * + src_parent and parent
23151 + * + di_write_lock_parent()
23152 + * + ii_write_lock_parent()
23153 + * + di_write_lock_parent2()
23154 + * + ii_write_lock_parent2()
23155 + * + lower src_dir and dir by vfsub_lock_rename()
23156 + * + verify the every relationships between child and parent. if any
23157 + * of them failed, unlock all and return -EBUSY.
23159 +static void au_ren_unlock(struct au_ren_args *a)
23161 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23162 + a->dst_h_parent, a->dst_hdir);
23163 + if (au_ftest_ren(a->auren_flags, DIRREN)
23165 + au_hn_inode_unlock(a->h_root);
23166 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23167 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23170 +static int au_ren_lock(struct au_ren_args *a)
23173 + unsigned int udba;
23176 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23177 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23178 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23179 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23181 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23182 + if (unlikely(err))
23184 + au_fset_ren(a->auren_flags, MNT_WRITE);
23185 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23186 + struct dentry *root;
23187 + struct inode *dir;
23190 + * sbinfo is already locked, so this ii_read_lock is
23191 + * unnecessary. but our debugging feature checks it.
23193 + root = a->src_inode->i_sb->s_root;
23194 + if (root != a->src_parent && root != a->dst_parent) {
23195 + dir = d_inode(root);
23196 + ii_read_lock_parent3(dir);
23197 + a->h_root = au_hi(dir, a->btgt);
23198 + ii_read_unlock(dir);
23199 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23202 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23203 + a->dst_h_parent, a->dst_hdir);
23204 + udba = au_opt_udba(a->src_dentry->d_sb);
23205 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23206 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23207 + err = au_busy_or_stale();
23208 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23209 + err = au_h_verify(a->src_h_dentry, udba,
23210 + d_inode(a->src_h_parent), a->src_h_parent,
23212 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23213 + err = au_h_verify(a->dst_h_dentry, udba,
23214 + d_inode(a->dst_h_parent), a->dst_h_parent,
23217 + goto out; /* success */
23219 + err = au_busy_or_stale();
23220 + au_ren_unlock(a);
23226 +/* ---------------------------------------------------------------------- */
23228 +static void au_ren_refresh_dir(struct au_ren_args *a)
23230 + struct inode *dir;
23232 + dir = a->dst_dir;
23233 + inode_inc_iversion(dir);
23234 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23235 + /* is this updating defined in POSIX? */
23236 + au_cpup_attr_timesizes(a->src_inode);
23237 + au_cpup_attr_nlink(dir, /*force*/1);
23239 + au_dir_ts(dir, a->btgt);
23241 + if (a->exchange) {
23242 + dir = a->src_dir;
23243 + inode_inc_iversion(dir);
23244 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23245 + /* is this updating defined in POSIX? */
23246 + au_cpup_attr_timesizes(a->dst_inode);
23247 + au_cpup_attr_nlink(dir, /*force*/1);
23249 + au_dir_ts(dir, a->btgt);
23252 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23255 + dir = a->src_dir;
23256 + inode_inc_iversion(dir);
23257 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23258 + au_cpup_attr_nlink(dir, /*force*/1);
23259 + au_dir_ts(dir, a->btgt);
23262 +static void au_ren_refresh(struct au_ren_args *a)
23264 + aufs_bindex_t bbot, bindex;
23265 + struct dentry *d, *h_d;
23266 + struct inode *i, *h_i;
23267 + struct super_block *sb;
23269 + d = a->dst_dentry;
23272 + /* already dget-ed by au_ren_or_cpup() */
23273 + au_set_h_dptr(d, a->btgt, a->h_dst);
23275 + i = a->dst_inode;
23277 + if (!a->exchange) {
23278 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23279 + vfsub_drop_nlink(i);
23281 + vfsub_dead_dir(i);
23282 + au_cpup_attr_timesizes(i);
23284 + au_update_dbrange(d, /*do_put_zero*/1);
23286 + au_cpup_attr_nlink(i, /*force*/1);
23289 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23290 + au_set_h_dptr(d, bindex, NULL);
23291 + bbot = au_dbbot(d);
23292 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23293 + au_set_h_dptr(d, bindex, NULL);
23294 + au_update_dbrange(d, /*do_put_zero*/0);
23298 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23299 + d_drop(a->src_dentry);
23300 + if (au_ftest_ren(a->auren_flags, DIRREN))
23301 + au_set_dbwh(a->src_dentry, -1);
23305 + d = a->src_dentry;
23306 + au_set_dbwh(d, -1);
23307 + bbot = au_dbbot(d);
23308 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23309 + h_d = au_h_dptr(d, bindex);
23311 + au_set_h_dptr(d, bindex, NULL);
23313 + au_set_dbbot(d, a->btgt);
23316 + i = a->src_inode;
23317 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23318 + return; /* success */
23320 + bbot = au_ibbot(i);
23321 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23322 + h_i = au_h_iptr(i, bindex);
23324 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23325 + /* ignore this error */
23326 + au_set_h_iptr(i, bindex, NULL, 0);
23329 + au_set_ibbot(i, a->btgt);
23332 +/* ---------------------------------------------------------------------- */
23334 +/* mainly for link(2) and rename(2) */
23335 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23337 + aufs_bindex_t bdiropq, bwh;
23338 + struct dentry *parent;
23339 + struct au_branch *br;
23341 + parent = dentry->d_parent;
23342 + IMustLock(d_inode(parent)); /* dir is locked */
23344 + bdiropq = au_dbdiropq(parent);
23345 + bwh = au_dbwh(dentry);
23346 + br = au_sbr(dentry->d_sb, btgt);
23347 + if (au_br_rdonly(br)
23348 + || (0 <= bdiropq && bdiropq < btgt)
23349 + || (0 <= bwh && bwh < btgt))
23352 + AuDbg("btgt %d\n", btgt);
23356 +/* sets src_btop, dst_btop and btgt */
23357 +static int au_ren_wbr(struct au_ren_args *a)
23360 + struct au_wr_dir_args wr_dir_args = {
23361 + /* .force_btgt = -1, */
23362 + .flags = AuWrDir_ADD_ENTRY
23365 + a->src_btop = au_dbtop(a->src_dentry);
23366 + a->dst_btop = au_dbtop(a->dst_dentry);
23367 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23368 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23369 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23370 + wr_dir_args.force_btgt = a->src_btop;
23371 + if (a->dst_inode && a->dst_btop < a->src_btop)
23372 + wr_dir_args.force_btgt = a->dst_btop;
23373 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23374 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23377 + au_update_dbtop(a->dst_dentry);
23382 +static void au_ren_dt(struct au_ren_args *a)
23384 + a->h_path.dentry = a->src_h_parent;
23385 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23386 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23387 + a->h_path.dentry = a->dst_h_parent;
23388 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23391 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23392 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23396 + a->h_path.dentry = a->src_h_dentry;
23397 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23398 + if (d_is_positive(a->dst_h_dentry)) {
23399 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23400 + a->h_path.dentry = a->dst_h_dentry;
23401 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23405 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23407 + struct dentry *h_d;
23408 + struct inode *h_inode;
23410 + au_dtime_revert(a->src_dt + AuPARENT);
23411 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23412 + au_dtime_revert(a->dst_dt + AuPARENT);
23414 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23415 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23416 + h_inode = d_inode(h_d);
23417 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23418 + au_dtime_revert(a->src_dt + AuCHILD);
23419 + inode_unlock(h_inode);
23421 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23422 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23423 + h_inode = d_inode(h_d);
23424 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23425 + au_dtime_revert(a->dst_dt + AuCHILD);
23426 + inode_unlock(h_inode);
23431 +/* ---------------------------------------------------------------------- */
23433 +int aufs_rename(struct user_namespace *userns,
23434 + struct inode *_src_dir, struct dentry *_src_dentry,
23435 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23436 + unsigned int _flags)
23438 + int err, lock_flags;
23440 + /* reduce stack space */
23441 + struct au_ren_args *a;
23442 + struct au_pin pin;
23444 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23445 + IMustLock(_src_dir);
23446 + IMustLock(_dst_dir);
23449 + if (unlikely(_flags & RENAME_WHITEOUT))
23453 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23454 + a = kzalloc(sizeof(*a), GFP_NOFS);
23455 + if (unlikely(!a))
23458 + a->flags = _flags;
23459 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23460 + && RENAME_EXCHANGE > U8_MAX);
23461 + a->exchange = _flags & RENAME_EXCHANGE;
23462 + a->src_dir = _src_dir;
23463 + a->src_dentry = _src_dentry;
23464 + a->src_inode = NULL;
23465 + if (d_really_is_positive(a->src_dentry))
23466 + a->src_inode = d_inode(a->src_dentry);
23467 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23468 + a->dst_dir = _dst_dir;
23469 + a->dst_dentry = _dst_dentry;
23470 + a->dst_inode = NULL;
23471 + if (d_really_is_positive(a->dst_dentry))
23472 + a->dst_inode = d_inode(a->dst_dentry);
23473 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23474 + if (a->dst_inode) {
23476 + * if EXCHANGE && src is non-dir && dst is dir,
23477 + * dst is not locked.
23479 + /* IMustLock(a->dst_inode); */
23480 + au_igrab(a->dst_inode);
23484 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23485 + if (d_is_dir(a->src_dentry)) {
23486 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23487 + if (unlikely(!a->exchange
23488 + && d_really_is_positive(a->dst_dentry)
23489 + && !d_is_dir(a->dst_dentry)))
23491 + lock_flags |= AuLock_DIRS;
23493 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23494 + au_fset_ren(a->auren_flags, ISDIR_DST);
23495 + if (unlikely(!a->exchange
23496 + && d_really_is_positive(a->src_dentry)
23497 + && !d_is_dir(a->src_dentry)))
23499 + lock_flags |= AuLock_DIRS;
23501 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23503 + if (unlikely(err))
23506 + err = au_d_hashed_positive(a->src_dentry);
23507 + if (unlikely(err))
23510 + if (a->dst_inode) {
23512 + * If it is a dir, VFS unhash it before this
23513 + * function. It means we cannot rely upon d_unhashed().
23515 + if (unlikely(!a->dst_inode->i_nlink))
23517 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23518 + err = au_d_hashed_positive(a->dst_dentry);
23519 + if (unlikely(err && !a->exchange))
23521 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23523 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23527 + * is it possible?
23528 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23529 + * there may exist a problem somewhere else.
23532 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23535 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23536 + di_write_lock_parent(a->dst_parent);
23538 + /* which branch we process */
23539 + err = au_ren_wbr(a);
23540 + if (unlikely(err < 0))
23542 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23543 + a->h_path.mnt = au_br_mnt(a->br);
23545 + /* are they available to be renamed */
23546 + err = au_ren_may_dir(a);
23547 + if (unlikely(err))
23548 + goto out_children;
23550 + /* prepare the writable parent dir on the same branch */
23551 + if (a->dst_btop == a->btgt) {
23552 + au_fset_ren(a->auren_flags, WHDST);
23554 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23555 + if (unlikely(err))
23556 + goto out_children;
23560 + if (!a->exchange) {
23561 + if (a->src_dir != a->dst_dir) {
23563 + * this temporary unlock is safe,
23564 + * because both dir->i_mutex are locked.
23566 + di_write_unlock(a->dst_parent);
23567 + di_write_lock_parent(a->src_parent);
23568 + err = au_wr_dir_need_wh(a->src_dentry,
23569 + au_ftest_ren(a->auren_flags,
23572 + di_write_unlock(a->src_parent);
23573 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23575 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23577 + err = au_wr_dir_need_wh(a->src_dentry,
23578 + au_ftest_ren(a->auren_flags,
23582 + if (unlikely(err < 0))
23583 + goto out_children;
23585 + au_fset_ren(a->auren_flags, WHSRC);
23588 + if (a->src_btop != a->btgt) {
23589 + err = au_pin(&pin, a->src_dentry, a->btgt,
23590 + au_opt_udba(a->src_dentry->d_sb),
23591 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23593 + struct au_cp_generic cpg = {
23594 + .dentry = a->src_dentry,
23596 + .bsrc = a->src_btop,
23599 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23601 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23602 + err = au_sio_cpup_simple(&cpg);
23605 + if (unlikely(err))
23606 + goto out_children;
23607 + a->src_btop = a->btgt;
23608 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23609 + if (!a->exchange)
23610 + au_fset_ren(a->auren_flags, WHSRC);
23614 + if (a->exchange && a->dst_inode
23615 + && a->dst_btop != a->btgt) {
23616 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23617 + au_opt_udba(a->dst_dentry->d_sb),
23618 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23620 + struct au_cp_generic cpg = {
23621 + .dentry = a->dst_dentry,
23623 + .bsrc = a->dst_btop,
23626 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23628 + err = au_sio_cpup_simple(&cpg);
23631 + if (unlikely(err))
23632 + goto out_children;
23633 + a->dst_btop = a->btgt;
23634 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23637 + /* lock them all */
23638 + err = au_ren_lock(a);
23639 + if (unlikely(err))
23640 + /* leave the copied-up one */
23641 + goto out_children;
23643 + if (!a->exchange) {
23644 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23645 + err = au_may_ren(a);
23646 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23647 + err = -ENAMETOOLONG;
23648 + if (unlikely(err))
23652 + /* store timestamps to be revertible */
23655 + /* store dirren info */
23656 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23657 + err = au_dr_rename(a->src_dentry, a->btgt,
23658 + &a->dst_dentry->d_name, &rev);
23660 + if (unlikely(err))
23665 + err = do_rename(a);
23666 + if (unlikely(err))
23669 + if (au_ftest_ren(a->auren_flags, DIRREN))
23670 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23672 + /* update dir attributes */
23673 + au_ren_refresh_dir(a);
23675 + /* dput/iput all lower dentries */
23676 + au_ren_refresh(a);
23678 + goto out_hdir; /* success */
23681 + if (au_ftest_ren(a->auren_flags, DIRREN))
23682 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23684 + au_ren_rev_dt(err, a);
23686 + au_ren_unlock(a);
23688 + au_nhash_wh_free(&a->whlist);
23689 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23690 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23691 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23692 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23696 + if (d_unhashed(a->src_dentry))
23697 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23698 + if (d_unhashed(a->dst_dentry))
23699 + au_fset_ren(a->auren_flags, DROPPED_DST);
23700 + if (!a->exchange)
23701 + d_move(a->src_dentry, a->dst_dentry);
23703 + d_exchange(a->src_dentry, a->dst_dentry);
23704 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23705 + d_drop(a->dst_dentry);
23707 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23708 + d_drop(a->src_dentry);
23710 + au_update_dbtop(a->dst_dentry);
23711 + if (!a->dst_inode)
23712 + d_drop(a->dst_dentry);
23714 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23715 + di_write_unlock(a->dst_parent);
23717 + di_write_unlock2(a->src_parent, a->dst_parent);
23719 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23721 + iput(a->dst_inode);
23723 + au_whtmp_rmdir_free(a->thargs);
23729 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23730 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23731 +++ linux/fs/aufs/Kconfig 2021-12-03 15:38:59.929980643 +0100
23733 +# SPDX-License-Identifier: GPL-2.0
23735 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23737 + Aufs is a stackable unification filesystem such as Unionfs,
23738 + which unifies several directories and provides a merged single
23740 + In the early days, aufs was entirely re-designed and
23741 + re-implemented Unionfs Version 1.x series. Introducing many
23742 + original ideas, approaches and improvements, it becomes totally
23743 + different from Unionfs while keeping the basic features.
23747 + prompt "Maximum number of branches"
23748 + default AUFS_BRANCH_MAX_127
23750 + Specifies the maximum number of branches (or member directories)
23751 + in a single aufs. The larger value consumes more system
23752 + resources and has a minor impact to performance.
23753 +config AUFS_BRANCH_MAX_127
23756 + Specifies the maximum number of branches (or member directories)
23757 + in a single aufs. The larger value consumes more system
23758 + resources and has a minor impact to performance.
23759 +config AUFS_BRANCH_MAX_511
23762 + Specifies the maximum number of branches (or member directories)
23763 + in a single aufs. The larger value consumes more system
23764 + resources and has a minor impact to performance.
23765 +config AUFS_BRANCH_MAX_1023
23768 + Specifies the maximum number of branches (or member directories)
23769 + in a single aufs. The larger value consumes more system
23770 + resources and has a minor impact to performance.
23771 +config AUFS_BRANCH_MAX_32767
23774 + Specifies the maximum number of branches (or member directories)
23775 + in a single aufs. The larger value consumes more system
23776 + resources and has a minor impact to performance.
23779 +config AUFS_SBILIST
23781 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23784 + Automatic configuration for internal use.
23785 + When aufs supports Magic SysRq or /proc, enabled automatically.
23787 +config AUFS_HNOTIFY
23788 + bool "Detect direct branch access (bypassing aufs)"
23790 + If you want to modify files on branches directly, eg. bypassing aufs,
23791 + and want aufs to detect the changes of them fully, then enable this
23792 + option and use 'udba=notify' mount option.
23793 + Currently there is only one available configuration, "fsnotify".
23794 + It will have a negative impact to the performance.
23795 + See detail in aufs.5.
23798 + prompt "method" if AUFS_HNOTIFY
23799 + default AUFS_HFSNOTIFY
23800 +config AUFS_HFSNOTIFY
23805 +config AUFS_EXPORT
23806 + bool "NFS-exportable aufs"
23807 + depends on EXPORTFS
23809 + If you want to export your mounted aufs via NFS, then enable this
23810 + option. There are several requirements for this configuration.
23811 + See detail in aufs.5.
23813 +config AUFS_INO_T_64
23815 + depends on AUFS_EXPORT
23816 + depends on 64BIT && !(ALPHA || S390)
23819 + Automatic configuration for internal use.
23820 + /* typedef unsigned long/int __kernel_ino_t */
23821 + /* alpha and s390x are int */
23824 + bool "support for XATTR/EA (including Security Labels)"
23826 + If your branch fs supports XATTR/EA and you want to make them
23827 + available in aufs too, then enable this opsion and specify the
23828 + branch attributes for EA.
23829 + See detail in aufs.5.
23832 + bool "File-based Hierarchical Storage Management"
23834 + Hierarchical Storage Management (or HSM) is a well-known feature
23835 + in the storage world. Aufs provides this feature as file-based.
23836 + with multiple branches.
23837 + These multiple branches are prioritized, ie. the topmost one
23838 + should be the fastest drive and be used heavily.
23841 + bool "Readdir in userspace"
23843 + Aufs has two methods to provide a merged view for a directory,
23844 + by a user-space library and by kernel-space natively. The latter
23845 + is always enabled but sometimes large and slow.
23846 + If you enable this option, install the library in aufs2-util
23847 + package, and set some environment variables for your readdir(3),
23848 + then the work will be handled in user-space which generally
23849 + shows better performance in most cases.
23850 + See detail in aufs.5.
23852 +config AUFS_DIRREN
23853 + bool "Workaround for rename(2)-ing a directory"
23855 + By default, aufs returns EXDEV error in renameing a dir who has
23856 + his child on the lower branch, since it is a bad idea to issue
23857 + rename(2) internally for every lower branch. But user may not
23858 + accept this behaviour. So here is a workaround to allow such
23859 + rename(2) and store some extra infromation on the writable
23860 + branch. Obviously this costs high (and I don't like it).
23861 + To use this feature, you need to enable this configuration AND
23862 + to specify the mount option `dirren.'
23863 + See details in aufs.5 and the design documents.
23866 + bool "Show whiteouts"
23868 + If you want to make the whiteouts in aufs visible, then enable
23869 + this option and specify 'shwh' mount option. Although it may
23870 + sounds like philosophy or something, but in technically it
23871 + simply shows the name of whiteout with keeping its behaviour.
23873 +config AUFS_BR_RAMFS
23874 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23876 + If you want to use ramfs as an aufs branch fs, then enable this
23877 + option. Generally tmpfs is recommended.
23878 + Aufs prohibited them to be a branch fs by default, because
23879 + initramfs becomes unusable after switch_root or something
23880 + generally. If you sets initramfs as an aufs branch and boot your
23881 + system by switch_root, you will meet a problem easily since the
23882 + files in initramfs may be inaccessible.
23883 + Unless you are going to use ramfs as an aufs branch fs without
23884 + switch_root or something, leave it N.
23886 +config AUFS_BR_FUSE
23887 + bool "Fuse fs as an aufs branch"
23888 + depends on FUSE_FS
23891 + If you want to use fuse-based userspace filesystem as an aufs
23892 + branch fs, then enable this option.
23893 + It implements the internal poll(2) operation which is
23894 + implemented by fuse only (curretnly).
23899 + Automatic configuration for internal use.
23901 +config AUFS_BR_HFSPLUS
23902 + bool "Hfsplus as an aufs branch"
23903 + depends on HFSPLUS_FS
23906 + If you want to use hfsplus fs as an aufs branch fs, then enable
23907 + this option. This option introduces a small overhead at
23908 + copying-up a file on hfsplus.
23910 +config AUFS_BDEV_LOOP
23912 + depends on BLK_DEV_LOOP
23915 + Automatic configuration for internal use.
23916 + Convert =[ym] into =y.
23919 + bool "Debug aufs"
23921 + Enable this to compile aufs internal debug code.
23922 + It will have a negative impact to the performance.
23924 +config AUFS_MAGIC_SYSRQ
23926 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23929 + Automatic configuration for internal use.
23930 + When aufs supports Magic SysRq, enabled automatically.
23932 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23933 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23934 +++ linux/fs/aufs/lcnt.h 2021-12-03 15:38:59.936647310 +0100
23936 +/* SPDX-License-Identifier: GPL-2.0 */
23938 + * Copyright (C) 2018-2021 Junjiro R. Okajima
23940 + * This program, aufs is free software; you can redistribute it and/or modify
23941 + * it under the terms of the GNU General Public License as published by
23942 + * the Free Software Foundation; either version 2 of the License, or
23943 + * (at your option) any later version.
23945 + * This program is distributed in the hope that it will be useful,
23946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23948 + * GNU General Public License for more details.
23950 + * You should have received a copy of the GNU General Public License
23951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23955 + * simple long counter wrapper
23958 +#ifndef __AUFS_LCNT_H__
23959 +#define __AUFS_LCNT_H__
23963 +#include "debug.h"
23965 +#define AuLCntATOMIC 1
23966 +#define AuLCntPCPUCNT 2
23968 + * why does percpu_refcount require extra synchronize_rcu()s in
23969 + * au_br_do_free()
23971 +#define AuLCntPCPUREF 3
23973 +/* #define AuLCntChosen AuLCntATOMIC */
23974 +#define AuLCntChosen AuLCntPCPUCNT
23975 +/* #define AuLCntChosen AuLCntPCPUREF */
23977 +#if AuLCntChosen == AuLCntATOMIC
23978 +#include <linux/atomic.h>
23980 +typedef atomic_long_t au_lcnt_t;
23982 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23984 + atomic_long_set(cnt, 0);
23988 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23993 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
23994 + int do_sync __maybe_unused)
23999 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24001 + atomic_long_inc(cnt);
24004 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24006 + atomic_long_dec(cnt);
24009 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24011 + return atomic_long_read(cnt);
24015 +#if AuLCntChosen == AuLCntPCPUCNT
24016 +#include <linux/percpu_counter.h>
24018 +typedef struct percpu_counter au_lcnt_t;
24020 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24022 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24025 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24030 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24032 + percpu_counter_destroy(cnt);
24035 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24037 + percpu_counter_inc(cnt);
24040 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24042 + percpu_counter_dec(cnt);
24045 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24049 + n = percpu_counter_sum(cnt);
24051 + if (LONG_MAX != LLONG_MAX
24053 + AuWarn1("%s\n", "wrap-around");
24059 +#if AuLCntChosen == AuLCntPCPUREF
24060 +#include <linux/percpu-refcount.h>
24062 +typedef struct percpu_ref au_lcnt_t;
24064 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24067 + release = percpu_ref_exit;
24068 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24071 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24073 + synchronize_rcu();
24076 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24078 + percpu_ref_kill(cnt);
24080 + au_lcnt_wait_for_fin(cnt);
24083 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24085 + percpu_ref_get(cnt);
24088 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24090 + percpu_ref_put(cnt);
24094 + * avoid calling this func as possible.
24096 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24100 + percpu_ref_switch_to_atomic_sync(cnt);
24101 + l = atomic_long_read(&cnt->count);
24103 + percpu_ref_switch_to_percpu(cnt);
24105 + /* percpu_ref is initialized by 1 instead of 0 */
24110 +#ifdef CONFIG_AUFS_DEBUG
24111 +#define AuLCntZero(val) do { \
24114 + AuDbg("%s = %ld\n", #val, l); \
24117 +#define AuLCntZero(val) do {} while (0)
24120 +#endif /* __KERNEL__ */
24121 +#endif /* __AUFS_LCNT_H__ */
24122 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24123 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24124 +++ linux/fs/aufs/loop.c 2021-12-03 15:38:59.936647310 +0100
24126 +// SPDX-License-Identifier: GPL-2.0
24128 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24130 + * This program, aufs is free software; you can redistribute it and/or modify
24131 + * it under the terms of the GNU General Public License as published by
24132 + * the Free Software Foundation; either version 2 of the License, or
24133 + * (at your option) any later version.
24135 + * This program is distributed in the hope that it will be useful,
24136 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24137 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24138 + * GNU General Public License for more details.
24140 + * You should have received a copy of the GNU General Public License
24141 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24145 + * support for loopback block device as a branch
24150 +/* added into drivers/block/loop.c */
24151 +static struct file *(*backing_file_func)(struct super_block *sb);
24154 + * test if two lower dentries have overlapping branches.
24156 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24158 + struct super_block *h_sb;
24159 + struct file *backing_file;
24161 + if (unlikely(!backing_file_func)) {
24162 + /* don't load "loop" module here */
24163 + backing_file_func = symbol_get(loop_backing_file);
24164 + if (unlikely(!backing_file_func))
24165 + /* "loop" module is not loaded */
24169 + h_sb = h_adding->d_sb;
24170 + backing_file = backing_file_func(h_sb);
24171 + if (!backing_file)
24174 + h_adding = backing_file->f_path.dentry;
24176 + * h_adding can be local NFS.
24177 + * in this case aufs cannot detect the loop.
24179 + if (unlikely(h_adding->d_sb == sb))
24181 + return !!au_test_subdir(h_adding, sb->s_root);
24184 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24185 +int au_test_loopback_kthread(void)
24188 + struct task_struct *tsk = current;
24189 + char c, comm[sizeof(tsk->comm)];
24192 + if (tsk->flags & PF_KTHREAD) {
24193 + get_task_comm(comm, tsk);
24195 + ret = ('0' <= c && c <= '9'
24196 + && !strncmp(comm, "loop", 4));
24202 +/* ---------------------------------------------------------------------- */
24204 +#define au_warn_loopback_step 16
24205 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24206 +static unsigned long *au_warn_loopback_array;
24208 +void au_warn_loopback(struct super_block *h_sb)
24210 + int i, new_nelem;
24211 + unsigned long *a, magic;
24212 + static DEFINE_SPINLOCK(spin);
24214 + magic = h_sb->s_magic;
24215 + spin_lock(&spin);
24216 + a = au_warn_loopback_array;
24217 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24218 + if (a[i] == magic) {
24219 + spin_unlock(&spin);
24223 + /* h_sb is new to us, print it */
24224 + if (i < au_warn_loopback_nelem) {
24229 + /* expand the array */
24230 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24231 + a = au_kzrealloc(au_warn_loopback_array,
24232 + au_warn_loopback_nelem * sizeof(unsigned long),
24233 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24234 + /*may_shrink*/0);
24236 + au_warn_loopback_nelem = new_nelem;
24237 + au_warn_loopback_array = a;
24242 + spin_unlock(&spin);
24243 + AuWarn1("realloc failed, ignored\n");
24247 + spin_unlock(&spin);
24248 + pr_warn("you may want to try another patch for loopback file "
24249 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24252 +int au_loopback_init(void)
24255 + struct super_block *sb __maybe_unused;
24257 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24260 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24261 + sizeof(unsigned long), GFP_NOFS);
24262 + if (unlikely(!au_warn_loopback_array))
24268 +void au_loopback_fin(void)
24270 + if (backing_file_func)
24271 + symbol_put(loop_backing_file);
24272 + au_kfree_try_rcu(au_warn_loopback_array);
24274 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24275 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24276 +++ linux/fs/aufs/loop.h 2021-12-03 15:38:59.936647310 +0100
24278 +/* SPDX-License-Identifier: GPL-2.0 */
24280 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24282 + * This program, aufs is free software; you can redistribute it and/or modify
24283 + * it under the terms of the GNU General Public License as published by
24284 + * the Free Software Foundation; either version 2 of the License, or
24285 + * (at your option) any later version.
24287 + * This program is distributed in the hope that it will be useful,
24288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24290 + * GNU General Public License for more details.
24292 + * You should have received a copy of the GNU General Public License
24293 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24297 + * support for loopback mount as a branch
24300 +#ifndef __AUFS_LOOP_H__
24301 +#define __AUFS_LOOP_H__
24306 +struct super_block;
24308 +#ifdef CONFIG_AUFS_BDEV_LOOP
24309 +/* drivers/block/loop.c */
24310 +struct file *loop_backing_file(struct super_block *sb);
24313 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24314 +int au_test_loopback_kthread(void);
24315 +void au_warn_loopback(struct super_block *h_sb);
24317 +int au_loopback_init(void);
24318 +void au_loopback_fin(void);
24320 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24322 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24323 + struct dentry *h_adding)
24324 +AuStubInt0(au_test_loopback_kthread, void)
24325 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24327 +AuStubInt0(au_loopback_init, void)
24328 +AuStubVoid(au_loopback_fin, void)
24329 +#endif /* BLK_DEV_LOOP */
24331 +#endif /* __KERNEL__ */
24332 +#endif /* __AUFS_LOOP_H__ */
24333 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24334 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24335 +++ linux/fs/aufs/magic.mk 2021-12-03 15:38:59.936647310 +0100
24337 +# SPDX-License-Identifier: GPL-2.0
24339 +# defined in ${srctree}/fs/fuse/inode.c
24341 +ifdef CONFIG_FUSE_FS
24342 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24345 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24347 +ifdef CONFIG_XFS_FS
24348 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24351 +# defined in ${srctree}/fs/configfs/mount.c
24353 +ifdef CONFIG_CONFIGFS_FS
24354 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24357 +# defined in ${srctree}/fs/ubifs/ubifs.h
24359 +ifdef CONFIG_UBIFS_FS
24360 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24363 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24365 +ifdef CONFIG_HFSPLUS_FS
24366 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24368 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24369 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24370 +++ linux/fs/aufs/Makefile 2021-12-03 15:38:59.929980643 +0100
24372 +# SPDX-License-Identifier: GPL-2.0
24374 +include ${src}/magic.mk
24375 +ifeq (${CONFIG_AUFS_FS},m)
24376 +include ${src}/conf.mk
24378 +-include ${src}/priv_def.mk
24380 +# cf. include/linux/kernel.h
24382 +ccflags-y += -DDEBUG
24383 +# sparse requires the full pathname
24385 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24387 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24390 +obj-$(CONFIG_AUFS_FS) += aufs.o
24391 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24392 + wkq.o vfsub.o dcsub.o \
24393 + cpup.o whout.o wbr_policy.o \
24394 + dinfo.o dentry.o \
24396 + finfo.o file.o f_op.o \
24398 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24402 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24403 +aufs-$(CONFIG_SYSFS) += sysfs.o
24404 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24405 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24406 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24407 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24408 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24409 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24410 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24411 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24412 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24413 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24414 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24415 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24416 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24417 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24418 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24419 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24420 +++ linux/fs/aufs/module.c 2021-12-03 15:38:59.936647310 +0100
24422 +// SPDX-License-Identifier: GPL-2.0
24424 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24426 + * This program, aufs is free software; you can redistribute it and/or modify
24427 + * it under the terms of the GNU General Public License as published by
24428 + * the Free Software Foundation; either version 2 of the License, or
24429 + * (at your option) any later version.
24431 + * This program is distributed in the hope that it will be useful,
24432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24434 + * GNU General Public License for more details.
24436 + * You should have received a copy of the GNU General Public License
24437 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24441 + * module global variables and operations
24444 +#include <linux/module.h>
24445 +#include <linux/seq_file.h>
24448 +/* shrinkable realloc */
24449 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24457 +#if 0 /* unused */
24464 + AuDebugOn(!new_sz);
24467 + diff = au_kmidx_sub(sz, new_sz);
24473 + /* expand or SLOB */
24474 + p = krealloc(p, new_sz, gfp);
24475 + else if (new_sz < sz && may_shrink) {
24479 + q = kmalloc(new_sz, gfp);
24482 + memcpy(q, p, new_sz);
24483 + au_kfree_try_rcu(p);
24494 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24497 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24498 + if (p && new_sz > nused)
24499 + memset(p + nused, 0, new_sz - nused);
24503 +/* ---------------------------------------------------------------------- */
24507 +struct kmem_cache *au_cache[AuCache_Last];
24509 +static void au_cache_fin(void)
24514 + * Make sure all delayed rcu free inodes are flushed before we
24519 + /* excluding AuCache_HNOTIFY */
24520 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24521 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24522 + kmem_cache_destroy(au_cache[i]);
24523 + au_cache[i] = NULL;
24527 +static int __init au_cache_init(void)
24529 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24530 + if (au_cache[AuCache_DINFO])
24531 + /* SLAB_DESTROY_BY_RCU */
24532 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24533 + au_icntnr_init_once);
24534 + if (au_cache[AuCache_ICNTNR])
24535 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24536 + au_fi_init_once);
24537 + if (au_cache[AuCache_FINFO])
24538 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24539 + if (au_cache[AuCache_VDIR])
24540 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24541 + if (au_cache[AuCache_DEHSTR])
24548 +/* ---------------------------------------------------------------------- */
24550 +int au_dir_roflags;
24552 +#ifdef CONFIG_AUFS_SBILIST
24554 + * iterate_supers_type() doesn't protect us from
24555 + * remounting (branch management)
24557 +struct hlist_bl_head au_sbilist;
24561 + * functions for module interface.
24563 +MODULE_LICENSE("GPL");
24564 +/* MODULE_LICENSE("GPL v2"); */
24565 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24566 +MODULE_DESCRIPTION(AUFS_NAME
24567 + " -- Advanced multi layered unification filesystem");
24568 +MODULE_VERSION(AUFS_VERSION);
24569 +MODULE_ALIAS_FS(AUFS_NAME);
24571 +/* this module parameter has no meaning when SYSFS is disabled */
24572 +int sysaufs_brs = 1;
24573 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24574 +module_param_named(brs, sysaufs_brs, int, 0444);
24576 +/* this module parameter has no meaning when USER_NS is disabled */
24578 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24579 +module_param_named(allow_userns, au_userns, bool, 0444);
24581 +/* ---------------------------------------------------------------------- */
24583 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24585 +int au_seq_path(struct seq_file *seq, struct path *path)
24589 + err = seq_path(seq, path, au_esc_chars);
24598 +/* ---------------------------------------------------------------------- */
24600 +static int __init aufs_init(void)
24605 + p = au_esc_chars;
24606 + for (i = 1; i <= ' '; i++)
24612 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24614 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24615 + for (i = 0; i < AuIop_Last; i++)
24616 + aufs_iop_nogetattr[i].getattr = NULL;
24618 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24620 + au_sbilist_init();
24621 + sysaufs_brs_init();
24624 + err = sysaufs_init();
24625 + if (unlikely(err))
24627 + err = dbgaufs_init();
24628 + if (unlikely(err))
24629 + goto out_sysaufs;
24630 + err = au_procfs_init();
24631 + if (unlikely(err))
24632 + goto out_dbgaufs;
24633 + err = au_wkq_init();
24634 + if (unlikely(err))
24636 + err = au_loopback_init();
24637 + if (unlikely(err))
24639 + err = au_hnotify_init();
24640 + if (unlikely(err))
24641 + goto out_loopback;
24642 + err = au_sysrq_init();
24643 + if (unlikely(err))
24645 + err = au_cache_init();
24646 + if (unlikely(err))
24649 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24650 + err = register_filesystem(&aufs_fs_type);
24651 + if (unlikely(err))
24654 + /* since we define pr_fmt, call printk directly */
24655 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24656 + goto out; /* success */
24663 + au_hnotify_fin();
24665 + au_loopback_fin();
24679 +static void __exit aufs_exit(void)
24681 + unregister_filesystem(&aufs_fs_type);
24684 + au_hnotify_fin();
24685 + au_loopback_fin();
24693 +module_init(aufs_init);
24694 +module_exit(aufs_exit);
24695 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24696 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24697 +++ linux/fs/aufs/module.h 2021-12-03 15:40:58.236647297 +0100
24699 +/* SPDX-License-Identifier: GPL-2.0 */
24701 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24703 + * This program, aufs is free software; you can redistribute it and/or modify
24704 + * it under the terms of the GNU General Public License as published by
24705 + * the Free Software Foundation; either version 2 of the License, or
24706 + * (at your option) any later version.
24708 + * This program is distributed in the hope that it will be useful,
24709 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24710 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24711 + * GNU General Public License for more details.
24713 + * You should have received a copy of the GNU General Public License
24714 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24718 + * module initialization and module-global
24721 +#ifndef __AUFS_MODULE_H__
24722 +#define __AUFS_MODULE_H__
24726 +#include <linux/slab.h>
24727 +#include "debug.h"
24728 +#include "dentry.h"
24731 +#include "inode.h"
24736 +/* module parameters */
24737 +extern int sysaufs_brs;
24738 +extern bool au_userns;
24740 +/* ---------------------------------------------------------------------- */
24742 +extern int au_dir_roflags;
24744 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24745 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24749 + * Comparing the size of the object with sizeof(struct rcu_head)
24750 + * case 1: object is always larger
24751 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24752 + * case 2: object is always smaller
24753 + * --> au_kfree_small()
24754 + * case 3: object can be any size
24755 + * --> au_kfree_try_rcu()
24758 +static inline void au_kfree_do_rcu(const void *p)
24761 + struct rcu_head rcu;
24762 + } *a = (void *)p;
24764 + kfree_rcu(a, rcu);
24767 +#define au_kfree_rcu(_p) do { \
24768 + typeof(_p) p = (_p); \
24769 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24771 + au_kfree_do_rcu(p); \
24774 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24775 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24777 +static inline void au_kfree_try_rcu(const void *p)
24781 + if (au_kfree_sz_test(p))
24782 + au_kfree_do_rcu(p);
24787 +static inline void au_kfree_small(const void *p)
24791 + AuDebugOn(au_kfree_sz_test(p));
24795 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24797 +#ifndef CONFIG_SLOB
24798 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
24800 + return -1; /* SLOB is untested */
24804 +int au_seq_path(struct seq_file *seq, struct path *path);
24806 +#ifdef CONFIG_PROC_FS
24808 +int __init au_procfs_init(void);
24809 +void au_procfs_fin(void);
24811 +AuStubInt0(au_procfs_init, void);
24812 +AuStubVoid(au_procfs_fin, void);
24815 +/* ---------------------------------------------------------------------- */
24824 + AuCache_HNOTIFY, /* must be last */
24828 +extern struct kmem_cache *au_cache[AuCache_Last];
24830 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24831 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24832 +#define AuCacheCtor(type, ctor) \
24833 + kmem_cache_create(#type, sizeof(struct type), \
24834 + __alignof__(struct type), AuCacheFlags, ctor)
24836 +#define AuCacheFuncs(name, index) \
24837 + static inline struct au_##name *au_cache_alloc_##name(void) \
24838 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24839 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24840 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24842 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24843 + { void *p = rcu; \
24844 + p -= offsetof(struct au_##name, rcu); \
24845 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24846 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24847 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24848 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24850 + static inline void au_cache_free_##name(struct au_##name *p) \
24851 + { /* au_cache_free_##name##_norcu(p); */ \
24852 + au_cache_free_##name##_rcu(p); }
24854 +AuCacheFuncs(dinfo, DINFO);
24855 +AuCacheFuncs(icntnr, ICNTNR);
24856 +AuCacheFuncs(finfo, FINFO);
24857 +AuCacheFuncs(vdir, VDIR);
24858 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24859 +#ifdef CONFIG_AUFS_HNOTIFY
24860 +AuCacheFuncs(hnotify, HNOTIFY);
24863 +#endif /* __KERNEL__ */
24864 +#endif /* __AUFS_MODULE_H__ */
24865 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24866 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24867 +++ linux/fs/aufs/mvdown.c 2021-12-03 15:38:59.939980643 +0100
24869 +// SPDX-License-Identifier: GPL-2.0
24871 + * Copyright (C) 2011-2021 Junjiro R. Okajima
24873 + * This program, aufs is free software; you can redistribute it and/or modify
24874 + * it under the terms of the GNU General Public License as published by
24875 + * the Free Software Foundation; either version 2 of the License, or
24876 + * (at your option) any later version.
24878 + * This program is distributed in the hope that it will be useful,
24879 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24880 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24881 + * GNU General Public License for more details.
24883 + * You should have received a copy of the GNU General Public License
24884 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24888 + * move-down, opposite of copy-up
24893 +struct au_mvd_args {
24895 + struct super_block *h_sb;
24896 + struct dentry *h_parent;
24897 + struct au_hinode *hdir;
24898 + struct inode *h_dir, *h_inode;
24899 + struct au_pin pin;
24900 + } info[AUFS_MVDOWN_NARRAY];
24902 + struct aufs_mvdown mvdown;
24903 + struct dentry *dentry, *parent;
24904 + struct inode *inode, *dir;
24905 + struct super_block *sb;
24906 + aufs_bindex_t bopq, bwh, bfound;
24907 + unsigned char rename_lock;
24910 +#define mvd_errno mvdown.au_errno
24911 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24912 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24913 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24914 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24916 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24917 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24918 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24919 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24920 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24921 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24923 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24924 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24925 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24926 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24927 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24928 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24930 +#define AU_MVD_PR(flag, ...) do { \
24932 + pr_err(__VA_ARGS__); \
24935 +static int find_lower_writable(struct au_mvd_args *a)
24937 + struct super_block *sb;
24938 + aufs_bindex_t bindex, bbot;
24939 + struct au_branch *br;
24942 + bindex = a->mvd_bsrc;
24943 + bbot = au_sbbot(sb);
24944 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24945 + for (bindex++; bindex <= bbot; bindex++) {
24946 + br = au_sbr(sb, bindex);
24947 + if (au_br_fhsm(br->br_perm)
24948 + && !sb_rdonly(au_br_sb(br)))
24951 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24952 + for (bindex++; bindex <= bbot; bindex++) {
24953 + br = au_sbr(sb, bindex);
24954 + if (!au_br_rdonly(br))
24958 + for (bindex++; bindex <= bbot; bindex++) {
24959 + br = au_sbr(sb, bindex);
24960 + if (!sb_rdonly(au_br_sb(br))) {
24961 + if (au_br_rdonly(br))
24963 + |= AUFS_MVDOWN_ROLOWER_R;
24971 +/* make the parent dir on bdst */
24972 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24977 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24978 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24979 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24980 + a->mvd_h_dst_parent = NULL;
24981 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24982 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24983 + if (!a->mvd_h_dst_parent) {
24984 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24985 + if (unlikely(err)) {
24986 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24989 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24997 +/* lock them all */
24998 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25001 + struct dentry *h_trap;
25003 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25004 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25005 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25006 + au_opt_udba(a->sb),
25007 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25009 + if (unlikely(err)) {
25010 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25014 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25015 + a->rename_lock = 0;
25016 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25017 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25018 + au_opt_udba(a->sb),
25019 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25020 + err = au_do_pin(&a->mvd_pin_src);
25022 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25023 + if (unlikely(err)) {
25024 + AU_MVD_PR(dmsg, "pin_src failed\n");
25027 + goto out; /* success */
25030 + a->rename_lock = 1;
25031 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25032 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25033 + au_opt_udba(a->sb),
25034 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25036 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25037 + if (unlikely(err)) {
25038 + AU_MVD_PR(dmsg, "pin_src failed\n");
25039 + au_pin_hdir_lock(&a->mvd_pin_dst);
25042 + au_pin_hdir_unlock(&a->mvd_pin_src);
25043 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25044 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25046 + err = (h_trap != a->mvd_h_src_parent);
25048 + err = (h_trap != a->mvd_h_dst_parent);
25050 + BUG_ON(err); /* it should never happen */
25051 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25054 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25055 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25056 + au_pin_hdir_lock(&a->mvd_pin_src);
25057 + au_unpin(&a->mvd_pin_src);
25058 + au_pin_hdir_lock(&a->mvd_pin_dst);
25061 + goto out; /* success */
25064 + au_unpin(&a->mvd_pin_dst);
25070 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25072 + if (!a->rename_lock)
25073 + au_unpin(&a->mvd_pin_src);
25075 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25076 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25077 + au_pin_hdir_lock(&a->mvd_pin_src);
25078 + au_unpin(&a->mvd_pin_src);
25079 + au_pin_hdir_lock(&a->mvd_pin_dst);
25081 + au_unpin(&a->mvd_pin_dst);
25084 +/* copy-down the file */
25085 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25088 + struct au_cp_generic cpg = {
25089 + .dentry = a->dentry,
25090 + .bdst = a->mvd_bdst,
25091 + .bsrc = a->mvd_bsrc,
25093 + .pin = &a->mvd_pin_dst,
25094 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25097 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25098 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25099 + au_fset_cpup(cpg.flags, OVERWRITE);
25100 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25101 + au_fset_cpup(cpg.flags, RWDST);
25102 + err = au_sio_cpdown_simple(&cpg);
25103 + if (unlikely(err))
25104 + AU_MVD_PR(dmsg, "cpdown failed\n");
25111 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25114 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25117 + struct path h_path;
25118 + struct au_branch *br;
25119 + struct inode *delegated;
25121 + br = au_sbr(a->sb, a->mvd_bdst);
25122 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25123 + err = PTR_ERR(h_path.dentry);
25124 + if (IS_ERR(h_path.dentry)) {
25125 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25130 + if (d_is_positive(h_path.dentry)) {
25131 + h_path.mnt = au_br_mnt(br);
25132 + delegated = NULL;
25133 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25134 + &delegated, /*force*/0);
25135 + if (unlikely(err == -EWOULDBLOCK)) {
25136 + pr_warn("cannot retry for NFSv4 delegation"
25137 + " for an internal unlink\n");
25140 + if (unlikely(err))
25141 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25143 + dput(h_path.dentry);
25151 + * unlink the topmost h_dentry
25153 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25156 + struct path h_path;
25157 + struct inode *delegated;
25159 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25160 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25161 + delegated = NULL;
25162 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25163 + if (unlikely(err == -EWOULDBLOCK)) {
25164 + pr_warn("cannot retry for NFSv4 delegation"
25165 + " for an internal unlink\n");
25168 + if (unlikely(err))
25169 + AU_MVD_PR(dmsg, "unlink failed\n");
25175 +/* Since mvdown succeeded, we ignore an error of this function */
25176 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25179 + struct au_branch *br;
25181 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25182 + br = au_sbr(a->sb, a->mvd_bsrc);
25183 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25185 + br = au_sbr(a->sb, a->mvd_bdst);
25186 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25187 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25190 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25192 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25196 + * copy-down the file and unlink the bsrc file.
25197 + * - unlink the bdst whout if exist
25198 + * - copy-down the file (with whtmp name and rename)
25199 + * - unlink the bsrc file
25201 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25205 + err = au_do_mkdir(dmsg, a);
25207 + err = au_do_lock(dmsg, a);
25208 + if (unlikely(err))
25212 + * do not revert the activities we made on bdst since they should be
25213 + * harmless in aufs.
25216 + err = au_do_cpdown(dmsg, a);
25218 + err = au_do_unlink_wh(dmsg, a);
25219 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25220 + err = au_do_unlink(dmsg, a);
25221 + if (unlikely(err))
25224 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25225 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25226 + if (find_lower_writable(a) < 0)
25227 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25229 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25230 + au_do_stfs(dmsg, a);
25232 + /* maintain internal array */
25233 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25234 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25235 + au_set_dbtop(a->dentry, a->mvd_bdst);
25236 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25237 + au_set_ibtop(a->inode, a->mvd_bdst);
25239 + /* hide the lower */
25240 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25241 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25242 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25243 + au_set_ibbot(a->inode, a->mvd_bsrc);
25245 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25246 + au_set_dbbot(a->dentry, a->mvd_bdst);
25247 + if (au_ibbot(a->inode) < a->mvd_bdst)
25248 + au_set_ibbot(a->inode, a->mvd_bdst);
25251 + au_do_unlock(dmsg, a);
25257 +/* ---------------------------------------------------------------------- */
25259 +/* make sure the file is idle */
25260 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25262 + int err, plinked;
25265 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25266 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25267 + && au_dcount(a->dentry) == 1
25268 + && atomic_read(&a->inode->i_count) == 1
25269 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25270 + && (!plinked || !au_plink_test(a->inode))
25271 + && a->inode->i_nlink == 1)
25276 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25277 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25278 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25279 + a->mvd_h_src_inode->i_nlink,
25280 + plinked, plinked ? au_plink_test(a->inode) : 0);
25287 +/* make sure the parent dir is fine */
25288 +static int au_mvd_args_parent(const unsigned char dmsg,
25289 + struct au_mvd_args *a)
25292 + aufs_bindex_t bindex;
25295 + if (unlikely(au_alive_dir(a->parent))) {
25297 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25301 + a->bopq = au_dbdiropq(a->parent);
25302 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25303 + AuDbg("b%d\n", bindex);
25304 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25305 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25307 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25308 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25309 + a->bopq, a->mvd_bdst);
25317 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25318 + struct au_mvd_args *a)
25321 + struct au_dinfo *dinfo, *tmp;
25323 + /* lookup the next lower positive entry */
25325 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25326 + if (unlikely(!tmp))
25331 + dinfo = au_di(a->dentry);
25332 + au_di_cp(tmp, dinfo);
25333 + au_di_swap(tmp, dinfo);
25335 + /* returns the number of positive dentries */
25336 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25337 + /* AuLkup_IGNORE_PERM */ 0);
25339 + a->bwh = au_dbwh(a->dentry);
25340 + else if (err > 0)
25341 + a->bfound = au_dbtop(a->dentry);
25343 + au_di_swap(tmp, dinfo);
25344 + au_rw_write_unlock(&tmp->di_rwsem);
25346 + if (unlikely(err < 0))
25347 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25350 + * here, we have these cases.
25352 + * no positive dentry under bsrc. there are more sub-cases.
25354 + * there no whiteout, we can safely move-down.
25357 + * bsrc < bwh && bwh < bdst
25358 + * there is a whiteout on RO branch. cannot proceed.
25360 + * there is a whiteout on the RW target branch. it should
25363 + * there is a whiteout somewhere unrelated branch.
25364 + * -1 < bfound && bfound <= bsrc
25367 + * found, but it is on RO branch between bsrc and bdst. cannot
25370 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25373 + * found, after we create the file on bdst, it will be hidden.
25376 + AuDebugOn(a->bfound == -1
25378 + && a->bwh <= a->mvd_bsrc);
25379 + AuDebugOn(-1 < a->bfound
25380 + && a->bfound <= a->mvd_bsrc);
25383 + if (a->bfound == -1
25384 + && a->mvd_bsrc < a->bwh
25386 + && a->bwh < a->mvd_bdst) {
25387 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25388 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25389 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25391 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25392 + a->mvd_errno = EAU_MVDOWN_UPPER;
25393 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25394 + a->mvd_bdst, a->bfound);
25398 + err = 0; /* success */
25405 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25410 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25411 + && a->bfound == a->mvd_bdst)
25417 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25420 + struct au_branch *br;
25423 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25427 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25428 + a->mvd_bsrc = au_ibtop(a->inode);
25430 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25431 + if (unlikely(a->mvd_bsrc < 0
25432 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25433 + || au_dbbot(a->dentry) < a->mvd_bsrc
25434 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25435 + || (a->mvd_bsrc < au_ibtop(a->inode)
25436 + || au_ibbot(a->inode) < a->mvd_bsrc
25437 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25438 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25439 + AU_MVD_PR(dmsg, "no upper\n");
25443 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25444 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25445 + AU_MVD_PR(dmsg, "on the bottom\n");
25448 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25449 + br = au_sbr(a->sb, a->mvd_bsrc);
25450 + err = au_br_rdonly(br);
25451 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25452 + if (unlikely(err))
25454 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25455 + || IS_APPEND(a->mvd_h_src_inode))) {
25457 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25463 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25464 + a->mvd_bdst = find_lower_writable(a);
25465 + if (unlikely(a->mvd_bdst < 0)) {
25466 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25467 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25471 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25472 + if (unlikely(a->mvd_bdst < 0
25473 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25474 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25475 + AU_MVD_PR(dmsg, "no lower brid\n");
25480 + err = au_mvd_args_busy(dmsg, a);
25482 + err = au_mvd_args_parent(dmsg, a);
25484 + err = au_mvd_args_intermediate(dmsg, a);
25486 + err = au_mvd_args_exist(dmsg, a);
25488 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25495 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25498 + unsigned char dmsg;
25499 + struct au_mvd_args *args;
25500 + struct inode *inode;
25502 + inode = d_inode(dentry);
25504 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25508 + args = kmalloc(sizeof(*args), GFP_NOFS);
25509 + if (unlikely(!args))
25512 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25514 + /* VERIFY_WRITE */
25515 + err = !access_ok(uarg, sizeof(*uarg));
25516 + if (unlikely(err)) {
25521 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25522 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25523 + args->mvdown.au_errno = 0;
25524 + args->dentry = dentry;
25525 + args->inode = inode;
25526 + args->sb = dentry->d_sb;
25529 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25530 + args->parent = dget_parent(dentry);
25531 + args->dir = d_inode(args->parent);
25532 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25533 + dput(args->parent);
25534 + if (unlikely(args->parent != dentry->d_parent)) {
25535 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25539 + inode_lock_nested(inode, I_MUTEX_CHILD);
25540 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25541 + if (unlikely(err))
25544 + di_write_lock_parent(args->parent);
25545 + err = au_mvd_args(dmsg, args);
25546 + if (unlikely(err))
25549 + err = au_do_mvdown(dmsg, args);
25550 + if (unlikely(err))
25553 + au_cpup_attr_timesizes(args->dir);
25554 + au_cpup_attr_timesizes(inode);
25555 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25556 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25557 + /* au_digen_dec(dentry); */
25560 + di_write_unlock(args->parent);
25561 + aufs_read_unlock(dentry, AuLock_DW);
25563 + inode_unlock(inode);
25565 + inode_unlock(args->dir);
25567 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25570 + au_kfree_rcu(args);
25575 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25576 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25577 +++ linux/fs/aufs/opts.c 2021-12-03 15:38:59.939980643 +0100
25579 +// SPDX-License-Identifier: GPL-2.0
25581 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25583 + * This program, aufs is free software; you can redistribute it and/or modify
25584 + * it under the terms of the GNU General Public License as published by
25585 + * the Free Software Foundation; either version 2 of the License, or
25586 + * (at your option) any later version.
25588 + * This program is distributed in the hope that it will be useful,
25589 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25590 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25591 + * GNU General Public License for more details.
25593 + * You should have received a copy of the GNU General Public License
25594 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25598 + * mount options/flags
25601 +#include <linux/namei.h>
25602 +#include <linux/types.h> /* a distribution requires */
25603 +#include <linux/parser.h>
25606 +/* ---------------------------------------------------------------------- */
25610 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25611 + Opt_idel, Opt_imod,
25612 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25613 + Opt_rdblk_def, Opt_rdhash_def,
25614 + Opt_xino, Opt_noxino,
25615 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25616 + Opt_trunc_xino_path, Opt_itrunc_xino,
25617 + Opt_trunc_xib, Opt_notrunc_xib,
25618 + Opt_shwh, Opt_noshwh,
25619 + Opt_plink, Opt_noplink, Opt_list_plink,
25621 + Opt_dio, Opt_nodio,
25622 + Opt_diropq_a, Opt_diropq_w,
25623 + Opt_warn_perm, Opt_nowarn_perm,
25624 + Opt_wbr_copyup, Opt_wbr_create,
25626 + Opt_verbose, Opt_noverbose,
25627 + Opt_sum, Opt_nosum, Opt_wsum,
25628 + Opt_dirperm1, Opt_nodirperm1,
25629 + Opt_dirren, Opt_nodirren,
25630 + Opt_acl, Opt_noacl,
25631 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25634 +static match_table_t options = {
25635 + {Opt_br, "br=%s"},
25636 + {Opt_br, "br:%s"},
25638 + {Opt_add, "add=%d:%s"},
25639 + {Opt_add, "add:%d:%s"},
25640 + {Opt_add, "ins=%d:%s"},
25641 + {Opt_add, "ins:%d:%s"},
25642 + {Opt_append, "append=%s"},
25643 + {Opt_append, "append:%s"},
25644 + {Opt_prepend, "prepend=%s"},
25645 + {Opt_prepend, "prepend:%s"},
25647 + {Opt_del, "del=%s"},
25648 + {Opt_del, "del:%s"},
25649 + /* {Opt_idel, "idel:%d"}, */
25650 + {Opt_mod, "mod=%s"},
25651 + {Opt_mod, "mod:%s"},
25652 + /* {Opt_imod, "imod:%d:%s"}, */
25654 + {Opt_dirwh, "dirwh=%d"},
25656 + {Opt_xino, "xino=%s"},
25657 + {Opt_noxino, "noxino"},
25658 + {Opt_trunc_xino, "trunc_xino"},
25659 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25660 + {Opt_notrunc_xino, "notrunc_xino"},
25661 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25662 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25663 + /* {Opt_zxino, "zxino=%s"}, */
25664 + {Opt_trunc_xib, "trunc_xib"},
25665 + {Opt_notrunc_xib, "notrunc_xib"},
25667 +#ifdef CONFIG_PROC_FS
25668 + {Opt_plink, "plink"},
25670 + {Opt_ignore_silent, "plink"},
25673 + {Opt_noplink, "noplink"},
25675 +#ifdef CONFIG_AUFS_DEBUG
25676 + {Opt_list_plink, "list_plink"},
25679 + {Opt_udba, "udba=%s"},
25681 + {Opt_dio, "dio"},
25682 + {Opt_nodio, "nodio"},
25684 +#ifdef CONFIG_AUFS_DIRREN
25685 + {Opt_dirren, "dirren"},
25686 + {Opt_nodirren, "nodirren"},
25688 + {Opt_ignore, "dirren"},
25689 + {Opt_ignore_silent, "nodirren"},
25692 +#ifdef CONFIG_AUFS_FHSM
25693 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25695 + {Opt_ignore, "fhsm_sec=%d"},
25698 + {Opt_diropq_a, "diropq=always"},
25699 + {Opt_diropq_a, "diropq=a"},
25700 + {Opt_diropq_w, "diropq=whiteouted"},
25701 + {Opt_diropq_w, "diropq=w"},
25703 + {Opt_warn_perm, "warn_perm"},
25704 + {Opt_nowarn_perm, "nowarn_perm"},
25706 + /* keep them temporary */
25707 + {Opt_ignore_silent, "nodlgt"},
25708 + {Opt_ignore, "clean_plink"},
25710 +#ifdef CONFIG_AUFS_SHWH
25711 + {Opt_shwh, "shwh"},
25713 + {Opt_noshwh, "noshwh"},
25715 + {Opt_dirperm1, "dirperm1"},
25716 + {Opt_nodirperm1, "nodirperm1"},
25718 + {Opt_verbose, "verbose"},
25719 + {Opt_verbose, "v"},
25720 + {Opt_noverbose, "noverbose"},
25721 + {Opt_noverbose, "quiet"},
25722 + {Opt_noverbose, "q"},
25723 + {Opt_noverbose, "silent"},
25725 + {Opt_sum, "sum"},
25726 + {Opt_nosum, "nosum"},
25727 + {Opt_wsum, "wsum"},
25729 + {Opt_rdcache, "rdcache=%d"},
25730 + {Opt_rdblk, "rdblk=%d"},
25731 + {Opt_rdblk_def, "rdblk=def"},
25732 + {Opt_rdhash, "rdhash=%d"},
25733 + {Opt_rdhash_def, "rdhash=def"},
25735 + {Opt_wbr_create, "create=%s"},
25736 + {Opt_wbr_create, "create_policy=%s"},
25737 + {Opt_wbr_copyup, "cpup=%s"},
25738 + {Opt_wbr_copyup, "copyup=%s"},
25739 + {Opt_wbr_copyup, "copyup_policy=%s"},
25741 + /* generic VFS flag */
25742 +#ifdef CONFIG_FS_POSIX_ACL
25743 + {Opt_acl, "acl"},
25744 + {Opt_noacl, "noacl"},
25746 + {Opt_ignore, "acl"},
25747 + {Opt_ignore_silent, "noacl"},
25750 + /* internal use for the scripts */
25751 + {Opt_ignore_silent, "si=%s"},
25753 + {Opt_br, "dirs=%s"},
25754 + {Opt_ignore, "debug=%d"},
25755 + {Opt_ignore, "delete=whiteout"},
25756 + {Opt_ignore, "delete=all"},
25757 + {Opt_ignore, "imap=%s"},
25759 + /* temporary workaround, due to old mount(8)? */
25760 + {Opt_ignore_silent, "relatime"},
25765 +/* ---------------------------------------------------------------------- */
25767 +static const char *au_parser_pattern(int val, match_table_t tbl)
25769 + struct match_token *p;
25772 + while (p->pattern) {
25773 + if (p->token == val)
25774 + return p->pattern;
25781 +static const char *au_optstr(int *val, match_table_t tbl)
25783 + struct match_token *p;
25790 + while (p->pattern) {
25792 + && (v & p->token) == p->token) {
25793 + *val &= ~p->token;
25794 + return p->pattern;
25803 +/* ---------------------------------------------------------------------- */
25805 +static match_table_t brperm = {
25806 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25807 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25808 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25812 +static match_table_t brattr = {
25814 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25815 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25816 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25817 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25818 +#ifdef CONFIG_AUFS_FHSM
25819 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25821 +#ifdef CONFIG_AUFS_XATTR
25822 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25823 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25824 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25825 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25826 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25827 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25830 + /* ro/rr branch */
25831 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25834 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25835 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25840 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25847 + p = strchr(str, '+');
25850 + v = match_token(str, table, args);
25852 + if (v & AuBrAttr_CMOO_Mask)
25853 + attr &= ~AuBrAttr_CMOO_Mask;
25858 + pr_warn("ignored branch attribute %s\n", str);
25868 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25876 + p = au_optstr(&perm, brattr);
25879 + memcpy(q, p, sz + 1);
25885 + p = au_optstr(&perm, brattr);
25889 + memcpy(q, p, sz + 1);
25895 + return q - str->a;
25898 +static int noinline_for_stack br_perm_val(char *perm)
25900 + int val, bad, sz;
25902 + substring_t args[MAX_OPT_ARGS];
25903 + au_br_perm_str_t attr;
25905 + p = strchr(perm, '+');
25908 + val = match_token(perm, brperm, args);
25912 + pr_warn("ignored branch permission %s\n", perm);
25913 + val = AuBrPerm_RO;
25919 + val |= br_attr_val(p + 1, brattr, args);
25922 + switch (val & AuBrPerm_Mask) {
25923 + case AuBrPerm_RO:
25924 + case AuBrPerm_RR:
25925 + bad = val & AuBrWAttr_Mask;
25926 + val &= ~AuBrWAttr_Mask;
25928 + case AuBrPerm_RW:
25929 + bad = val & AuBrRAttr_Mask;
25930 + val &= ~AuBrRAttr_Mask;
25935 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25936 + * does not treat it as an error, just warning.
25937 + * this is a tiny guard for the user operation.
25939 + if (val & AuBrAttr_UNPIN) {
25940 + bad |= AuBrAttr_UNPIN;
25941 + val &= ~AuBrAttr_UNPIN;
25944 + if (unlikely(bad)) {
25945 + sz = au_do_optstr_br_attr(&attr, bad);
25947 + pr_warn("ignored branch attribute %s\n", attr.a);
25954 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25956 + au_br_perm_str_t attr;
25962 + p = au_optstr(&perm, brperm);
25963 + AuDebugOn(!p || !*p);
25965 + memcpy(q, p, sz + 1);
25968 + sz = au_do_optstr_br_attr(&attr, perm);
25971 + memcpy(q, attr.a, sz + 1);
25974 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25977 +/* ---------------------------------------------------------------------- */
25979 +static match_table_t udbalevel = {
25980 + {AuOpt_UDBA_REVAL, "reval"},
25981 + {AuOpt_UDBA_NONE, "none"},
25982 +#ifdef CONFIG_AUFS_HNOTIFY
25983 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25984 +#ifdef CONFIG_AUFS_HFSNOTIFY
25985 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25991 +static int noinline_for_stack udba_val(char *str)
25993 + substring_t args[MAX_OPT_ARGS];
25995 + return match_token(str, udbalevel, args);
25998 +const char *au_optstr_udba(int udba)
26000 + return au_parser_pattern(udba, udbalevel);
26003 +/* ---------------------------------------------------------------------- */
26005 +static match_table_t au_wbr_create_policy = {
26006 + {AuWbrCreate_TDP, "tdp"},
26007 + {AuWbrCreate_TDP, "top-down-parent"},
26008 + {AuWbrCreate_RR, "rr"},
26009 + {AuWbrCreate_RR, "round-robin"},
26010 + {AuWbrCreate_MFS, "mfs"},
26011 + {AuWbrCreate_MFS, "most-free-space"},
26012 + {AuWbrCreate_MFSV, "mfs:%d"},
26013 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26015 + /* top-down regardless the parent, and then mfs */
26016 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26017 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26019 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26020 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26021 + {AuWbrCreate_PMFS, "pmfs"},
26022 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26023 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26024 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26029 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26030 + struct au_opt_wbr_create *create)
26033 + unsigned long long ull;
26036 + if (!match_u64(arg, &ull))
26037 + create->mfsrr_watermark = ull;
26039 + pr_err("bad integer in %s\n", str);
26046 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26047 + struct au_opt_wbr_create *create)
26052 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26053 + create->mfs_second = n;
26055 + pr_err("bad integer in %s\n", str);
26062 +static int noinline_for_stack
26063 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26066 + substring_t args[MAX_OPT_ARGS];
26068 + err = match_token(str, au_wbr_create_policy, args);
26069 + create->wbr_create = err;
26071 + case AuWbrCreate_MFSRRV:
26072 + case AuWbrCreate_TDMFSV:
26073 + case AuWbrCreate_PMFSRRV:
26074 + e = au_wbr_mfs_wmark(&args[0], str, create);
26076 + e = au_wbr_mfs_sec(&args[1], str, create);
26080 + case AuWbrCreate_MFSRR:
26081 + case AuWbrCreate_TDMFS:
26082 + case AuWbrCreate_PMFSRR:
26083 + e = au_wbr_mfs_wmark(&args[0], str, create);
26084 + if (unlikely(e)) {
26089 + case AuWbrCreate_MFS:
26090 + case AuWbrCreate_PMFS:
26091 + create->mfs_second = AUFS_MFS_DEF_SEC;
26093 + case AuWbrCreate_MFSV:
26094 + case AuWbrCreate_PMFSV:
26095 + e = au_wbr_mfs_sec(&args[0], str, create);
26104 +const char *au_optstr_wbr_create(int wbr_create)
26106 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26109 +static match_table_t au_wbr_copyup_policy = {
26110 + {AuWbrCopyup_TDP, "tdp"},
26111 + {AuWbrCopyup_TDP, "top-down-parent"},
26112 + {AuWbrCopyup_BUP, "bup"},
26113 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26114 + {AuWbrCopyup_BU, "bu"},
26115 + {AuWbrCopyup_BU, "bottom-up"},
26119 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26121 + substring_t args[MAX_OPT_ARGS];
26123 + return match_token(str, au_wbr_copyup_policy, args);
26126 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26128 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26131 +/* ---------------------------------------------------------------------- */
26133 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26135 +static void dump_opts(struct au_opts *opts)
26137 +#ifdef CONFIG_AUFS_DEBUG
26138 + /* reduce stack space */
26140 + struct au_opt_add *add;
26141 + struct au_opt_del *del;
26142 + struct au_opt_mod *mod;
26143 + struct au_opt_xino *xino;
26144 + struct au_opt_xino_itrunc *xino_itrunc;
26145 + struct au_opt_wbr_create *create;
26147 + struct au_opt *opt;
26150 + while (opt->type != Opt_tail) {
26151 + switch (opt->type) {
26153 + u.add = &opt->add;
26154 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26155 + u.add->bindex, u.add->pathname, u.add->perm,
26156 + u.add->path.dentry);
26160 + u.del = &opt->del;
26161 + AuDbg("del {%s, %p}\n",
26162 + u.del->pathname, u.del->h_path.dentry);
26166 + u.mod = &opt->mod;
26167 + AuDbg("mod {%s, 0x%x, %p}\n",
26168 + u.mod->path, u.mod->perm, u.mod->h_root);
26171 + u.add = &opt->add;
26172 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26173 + u.add->bindex, u.add->pathname, u.add->perm,
26174 + u.add->path.dentry);
26176 + case Opt_prepend:
26177 + u.add = &opt->add;
26178 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26179 + u.add->bindex, u.add->pathname, u.add->perm,
26180 + u.add->path.dentry);
26183 + AuDbg("dirwh %d\n", opt->dirwh);
26185 + case Opt_rdcache:
26186 + AuDbg("rdcache %d\n", opt->rdcache);
26189 + AuDbg("rdblk %u\n", opt->rdblk);
26191 + case Opt_rdblk_def:
26192 + AuDbg("rdblk_def\n");
26195 + AuDbg("rdhash %u\n", opt->rdhash);
26197 + case Opt_rdhash_def:
26198 + AuDbg("rdhash_def\n");
26201 + u.xino = &opt->xino;
26202 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26204 + case Opt_trunc_xino:
26205 + AuLabel(trunc_xino);
26207 + case Opt_notrunc_xino:
26208 + AuLabel(notrunc_xino);
26210 + case Opt_trunc_xino_path:
26211 + case Opt_itrunc_xino:
26212 + u.xino_itrunc = &opt->xino_itrunc;
26213 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26218 + case Opt_trunc_xib:
26219 + AuLabel(trunc_xib);
26221 + case Opt_notrunc_xib:
26222 + AuLabel(notrunc_xib);
26230 + case Opt_dirperm1:
26231 + AuLabel(dirperm1);
26233 + case Opt_nodirperm1:
26234 + AuLabel(nodirperm1);
26239 + case Opt_noplink:
26240 + AuLabel(noplink);
26242 + case Opt_list_plink:
26243 + AuLabel(list_plink);
26246 + AuDbg("udba %d, %s\n",
26247 + opt->udba, au_optstr_udba(opt->udba));
26255 + case Opt_diropq_a:
26256 + AuLabel(diropq_a);
26258 + case Opt_diropq_w:
26259 + AuLabel(diropq_w);
26261 + case Opt_warn_perm:
26262 + AuLabel(warn_perm);
26264 + case Opt_nowarn_perm:
26265 + AuLabel(nowarn_perm);
26267 + case Opt_verbose:
26268 + AuLabel(verbose);
26270 + case Opt_noverbose:
26271 + AuLabel(noverbose);
26282 + case Opt_wbr_create:
26283 + u.create = &opt->wbr_create;
26284 + AuDbg("create %d, %s\n", u.create->wbr_create,
26285 + au_optstr_wbr_create(u.create->wbr_create));
26286 + switch (u.create->wbr_create) {
26287 + case AuWbrCreate_MFSV:
26288 + case AuWbrCreate_PMFSV:
26289 + AuDbg("%d sec\n", u.create->mfs_second);
26291 + case AuWbrCreate_MFSRR:
26292 + case AuWbrCreate_TDMFS:
26293 + AuDbg("%llu watermark\n",
26294 + u.create->mfsrr_watermark);
26296 + case AuWbrCreate_MFSRRV:
26297 + case AuWbrCreate_TDMFSV:
26298 + case AuWbrCreate_PMFSRRV:
26299 + AuDbg("%llu watermark, %d sec\n",
26300 + u.create->mfsrr_watermark,
26301 + u.create->mfs_second);
26305 + case Opt_wbr_copyup:
26306 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26307 + au_optstr_wbr_copyup(opt->wbr_copyup));
26309 + case Opt_fhsm_sec:
26310 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26315 + case Opt_nodirren:
26316 + AuLabel(nodirren);
26332 +void au_opts_free(struct au_opts *opts)
26334 + struct au_opt *opt;
26337 + while (opt->type != Opt_tail) {
26338 + switch (opt->type) {
26341 + case Opt_prepend:
26342 + path_put(&opt->add.path);
26346 + path_put(&opt->del.h_path);
26350 + dput(opt->mod.h_root);
26353 + fput(opt->xino.file);
26360 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26361 + aufs_bindex_t bindex)
26364 + struct au_opt_add *add = &opt->add;
26367 + add->bindex = bindex;
26368 + add->perm = AuBrPerm_RO;
26369 + add->pathname = opt_str;
26370 + p = strchr(opt_str, '=');
26374 + add->perm = br_perm_val(p);
26377 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26380 + add->perm = AuBrPerm_RO;
26381 + if (au_test_fs_rr(add->path.dentry->d_sb))
26382 + add->perm = AuBrPerm_RR;
26383 + else if (!bindex && !(sb_flags & SB_RDONLY))
26384 + add->perm = AuBrPerm_RW;
26386 + opt->type = Opt_add;
26389 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26396 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26400 + del->pathname = args[0].from;
26401 + AuDbg("del path %s\n", del->pathname);
26403 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26404 + if (unlikely(err))
26405 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26410 +#if 0 /* reserved for future use */
26411 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26412 + struct au_opt_del *del, substring_t args[])
26415 + struct dentry *root;
26418 + root = sb->s_root;
26419 + aufs_read_lock(root, AuLock_FLUSH);
26420 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26421 + pr_err("out of bounds, %d\n", bindex);
26426 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26427 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26430 + aufs_read_unlock(root, !AuLock_IR);
26435 +static int noinline_for_stack
26436 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26439 + struct path path;
26443 + mod->path = args[0].from;
26444 + p = strchr(mod->path, '=');
26445 + if (unlikely(!p)) {
26446 + pr_err("no permission %s\n", args[0].from);
26451 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26452 + if (unlikely(err)) {
26453 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26457 + mod->perm = br_perm_val(p);
26458 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26459 + mod->h_root = dget(path.dentry);
26466 +#if 0 /* reserved for future use */
26467 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26468 + struct au_opt_mod *mod, substring_t args[])
26471 + struct dentry *root;
26474 + root = sb->s_root;
26475 + aufs_read_lock(root, AuLock_FLUSH);
26476 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26477 + pr_err("out of bounds, %d\n", bindex);
26482 + mod->perm = br_perm_val(args[1].from);
26483 + AuDbg("mod path %s, perm 0x%x, %s\n",
26484 + mod->path, mod->perm, args[1].from);
26485 + mod->h_root = dget(au_h_dptr(root, bindex));
26488 + aufs_read_unlock(root, !AuLock_IR);
26493 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26494 + substring_t args[])
26497 + struct file *file;
26499 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26500 + err = PTR_ERR(file);
26501 + if (IS_ERR(file))
26505 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26507 + pr_err("%s must be outside\n", args[0].from);
26512 + xino->file = file;
26513 + xino->path = args[0].from;
26519 +static int noinline_for_stack
26520 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26521 + struct au_opt_xino_itrunc *xino_itrunc,
26522 + substring_t args[])
26525 + aufs_bindex_t bbot, bindex;
26526 + struct path path;
26527 + struct dentry *root;
26529 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26530 + if (unlikely(err)) {
26531 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26535 + xino_itrunc->bindex = -1;
26536 + root = sb->s_root;
26537 + aufs_read_lock(root, AuLock_FLUSH);
26538 + bbot = au_sbbot(sb);
26539 + for (bindex = 0; bindex <= bbot; bindex++) {
26540 + if (au_h_dptr(root, bindex) == path.dentry) {
26541 + xino_itrunc->bindex = bindex;
26545 + aufs_read_unlock(root, !AuLock_IR);
26548 + if (unlikely(xino_itrunc->bindex < 0)) {
26549 + pr_err("no such branch %s\n", args[0].from);
26557 +/* called without aufs lock */
26558 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26560 + int err, n, token;
26561 + aufs_bindex_t bindex;
26562 + unsigned char skipped;
26563 + struct dentry *root;
26564 + struct au_opt *opt, *opt_tail;
26566 + /* reduce the stack space */
26568 + struct au_opt_xino_itrunc *xino_itrunc;
26569 + struct au_opt_wbr_create *create;
26572 + substring_t args[MAX_OPT_ARGS];
26576 + a = kmalloc(sizeof(*a), GFP_NOFS);
26577 + if (unlikely(!a))
26580 + root = sb->s_root;
26584 + opt_tail = opt + opts->max_opt - 1;
26585 + opt->type = Opt_tail;
26586 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26589 + token = match_token(opt_str, options, a->args);
26593 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26595 + err = opt_add(opt, opt_str, opts->sb_flags,
26597 + if (unlikely(!err && ++opt > opt_tail)) {
26601 + opt->type = Opt_tail;
26606 + if (unlikely(match_int(&a->args[0], &n))) {
26607 + pr_err("bad integer in %s\n", opt_str);
26611 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26614 + opt->type = token;
26617 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26618 + /*dummy bindex*/1);
26620 + opt->type = token;
26622 + case Opt_prepend:
26623 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26626 + opt->type = token;
26629 + err = au_opts_parse_del(&opt->del, a->args);
26631 + opt->type = token;
26633 +#if 0 /* reserved for future use */
26635 + del->pathname = "(indexed)";
26636 + if (unlikely(match_int(&args[0], &n))) {
26637 + pr_err("bad integer in %s\n", opt_str);
26640 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26642 + opt->type = token;
26646 + err = au_opts_parse_mod(&opt->mod, a->args);
26648 + opt->type = token;
26650 +#ifdef IMOD /* reserved for future use */
26652 + u.mod->path = "(indexed)";
26653 + if (unlikely(match_int(&a->args[0], &n))) {
26654 + pr_err("bad integer in %s\n", opt_str);
26657 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26659 + opt->type = token;
26663 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26665 + opt->type = token;
26668 + case Opt_trunc_xino_path:
26669 + err = au_opts_parse_xino_itrunc_path
26670 + (sb, &opt->xino_itrunc, a->args);
26672 + opt->type = token;
26675 + case Opt_itrunc_xino:
26676 + u.xino_itrunc = &opt->xino_itrunc;
26677 + if (unlikely(match_int(&a->args[0], &n))) {
26678 + pr_err("bad integer in %s\n", opt_str);
26681 + u.xino_itrunc->bindex = n;
26682 + aufs_read_lock(root, AuLock_FLUSH);
26683 + if (n < 0 || au_sbbot(sb) < n) {
26684 + pr_err("out of bounds, %d\n", n);
26685 + aufs_read_unlock(root, !AuLock_IR);
26688 + aufs_read_unlock(root, !AuLock_IR);
26690 + opt->type = token;
26694 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26697 + opt->type = token;
26700 + case Opt_rdcache:
26701 + if (unlikely(match_int(&a->args[0], &n))) {
26702 + pr_err("bad integer in %s\n", opt_str);
26705 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26706 + pr_err("rdcache must be smaller than %d\n",
26707 + AUFS_RDCACHE_MAX);
26710 + opt->rdcache = n;
26712 + opt->type = token;
26715 + if (unlikely(match_int(&a->args[0], &n)
26717 + || n > KMALLOC_MAX_SIZE)) {
26718 + pr_err("bad integer in %s\n", opt_str);
26721 + if (unlikely(n && n < NAME_MAX)) {
26722 + pr_err("rdblk must be larger than %d\n",
26728 + opt->type = token;
26731 + if (unlikely(match_int(&a->args[0], &n)
26733 + || n * sizeof(struct hlist_head)
26734 + > KMALLOC_MAX_SIZE)) {
26735 + pr_err("bad integer in %s\n", opt_str);
26740 + opt->type = token;
26743 + case Opt_trunc_xino:
26744 + case Opt_notrunc_xino:
26746 + case Opt_trunc_xib:
26747 + case Opt_notrunc_xib:
26750 + case Opt_dirperm1:
26751 + case Opt_nodirperm1:
26753 + case Opt_noplink:
26754 + case Opt_list_plink:
26757 + case Opt_diropq_a:
26758 + case Opt_diropq_w:
26759 + case Opt_warn_perm:
26760 + case Opt_nowarn_perm:
26761 + case Opt_verbose:
26762 + case Opt_noverbose:
26766 + case Opt_rdblk_def:
26767 + case Opt_rdhash_def:
26769 + case Opt_nodirren:
26773 + opt->type = token;
26777 + opt->udba = udba_val(a->args[0].from);
26778 + if (opt->udba >= 0) {
26780 + opt->type = token;
26782 + pr_err("wrong value, %s\n", opt_str);
26785 + case Opt_wbr_create:
26786 + u.create = &opt->wbr_create;
26787 + u.create->wbr_create
26788 + = au_wbr_create_val(a->args[0].from, u.create);
26789 + if (u.create->wbr_create >= 0) {
26791 + opt->type = token;
26793 + pr_err("wrong value, %s\n", opt_str);
26795 + case Opt_wbr_copyup:
26796 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26797 + if (opt->wbr_copyup >= 0) {
26799 + opt->type = token;
26801 + pr_err("wrong value, %s\n", opt_str);
26804 + case Opt_fhsm_sec:
26805 + if (unlikely(match_int(&a->args[0], &n)
26807 + pr_err("bad integer in %s\n", opt_str);
26810 + if (sysaufs_brs) {
26811 + opt->fhsm_second = n;
26812 + opt->type = token;
26814 + pr_warn("ignored %s\n", opt_str);
26819 + pr_warn("ignored %s\n", opt_str);
26821 + case Opt_ignore_silent:
26826 + pr_err("unknown option %s\n", opt_str);
26830 + if (!err && !skipped) {
26831 + if (unlikely(++opt > opt_tail)) {
26834 + opt->type = Opt_tail;
26837 + opt->type = Opt_tail;
26843 + if (unlikely(err))
26844 + au_opts_free(opts);
26850 +static int au_opt_wbr_create(struct super_block *sb,
26851 + struct au_opt_wbr_create *create)
26854 + struct au_sbinfo *sbinfo;
26856 + SiMustWriteLock(sb);
26858 + err = 1; /* handled */
26859 + sbinfo = au_sbi(sb);
26860 + if (sbinfo->si_wbr_create_ops->fin) {
26861 + err = sbinfo->si_wbr_create_ops->fin(sb);
26866 + sbinfo->si_wbr_create = create->wbr_create;
26867 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26868 + switch (create->wbr_create) {
26869 + case AuWbrCreate_MFSRRV:
26870 + case AuWbrCreate_MFSRR:
26871 + case AuWbrCreate_TDMFS:
26872 + case AuWbrCreate_TDMFSV:
26873 + case AuWbrCreate_PMFSRR:
26874 + case AuWbrCreate_PMFSRRV:
26875 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26877 + case AuWbrCreate_MFS:
26878 + case AuWbrCreate_MFSV:
26879 + case AuWbrCreate_PMFS:
26880 + case AuWbrCreate_PMFSV:
26881 + sbinfo->si_wbr_mfs.mfs_expire
26882 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26886 + if (sbinfo->si_wbr_create_ops->init)
26887 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26894 + * plus: processed without an error
26895 + * zero: unprocessed
26897 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26898 + struct au_opts *opts)
26901 + struct au_sbinfo *sbinfo;
26903 + SiMustWriteLock(sb);
26905 + err = 1; /* handled */
26906 + sbinfo = au_sbi(sb);
26907 + switch (opt->type) {
26909 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26910 + sbinfo->si_mntflags |= opt->udba;
26911 + opts->given_udba |= opt->udba;
26915 + au_opt_set(sbinfo->si_mntflags, PLINK);
26917 + case Opt_noplink:
26918 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26919 + au_plink_put(sb, /*verbose*/1);
26920 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26922 + case Opt_list_plink:
26923 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26924 + au_plink_list(sb);
26928 + au_opt_set(sbinfo->si_mntflags, DIO);
26929 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26932 + au_opt_clr(sbinfo->si_mntflags, DIO);
26933 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26936 + case Opt_fhsm_sec:
26937 + au_fhsm_set(sbinfo, opt->fhsm_second);
26940 + case Opt_diropq_a:
26941 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26943 + case Opt_diropq_w:
26944 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26947 + case Opt_warn_perm:
26948 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26950 + case Opt_nowarn_perm:
26951 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26954 + case Opt_verbose:
26955 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26957 + case Opt_noverbose:
26958 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26962 + au_opt_set(sbinfo->si_mntflags, SUM);
26965 + au_opt_clr(sbinfo->si_mntflags, SUM);
26966 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26969 + au_opt_clr(sbinfo->si_mntflags, SUM);
26970 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26973 + case Opt_wbr_create:
26974 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26976 + case Opt_wbr_copyup:
26977 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26978 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26982 + sbinfo->si_dirwh = opt->dirwh;
26985 + case Opt_rdcache:
26986 + sbinfo->si_rdcache
26987 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26990 + sbinfo->si_rdblk = opt->rdblk;
26992 + case Opt_rdblk_def:
26993 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26996 + sbinfo->si_rdhash = opt->rdhash;
26998 + case Opt_rdhash_def:
26999 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27003 + au_opt_set(sbinfo->si_mntflags, SHWH);
27006 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27009 + case Opt_dirperm1:
27010 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27012 + case Opt_nodirperm1:
27013 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27016 + case Opt_trunc_xino:
27017 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27019 + case Opt_notrunc_xino:
27020 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27023 + case Opt_trunc_xino_path:
27024 + case Opt_itrunc_xino:
27025 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27031 + case Opt_trunc_xib:
27032 + au_fset_opts(opts->flags, TRUNC_XIB);
27034 + case Opt_notrunc_xib:
27035 + au_fclr_opts(opts->flags, TRUNC_XIB);
27040 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27041 + err = au_dr_opt_set(sb);
27046 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27048 + case Opt_nodirren:
27050 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27051 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27057 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27061 + sb->s_flags |= SB_POSIXACL;
27064 + sb->s_flags &= ~SB_POSIXACL;
27076 + * returns tri-state.
27077 + * plus: processed without an error
27078 + * zero: unprocessed
27081 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27082 + struct au_opts *opts)
27084 + int err, do_refresh;
27087 + switch (opt->type) {
27089 + opt->add.bindex = au_sbbot(sb) + 1;
27090 + if (opt->add.bindex < 0)
27091 + opt->add.bindex = 0;
27093 + /* Always goto add, not fallthrough */
27094 + case Opt_prepend:
27095 + opt->add.bindex = 0;
27097 + add: /* indented label */
27099 + err = au_br_add(sb, &opt->add,
27100 + au_ftest_opts(opts->flags, REMOUNT));
27103 + au_fset_opts(opts->flags, REFRESH);
27109 + err = au_br_del(sb, &opt->del,
27110 + au_ftest_opts(opts->flags, REMOUNT));
27113 + au_fset_opts(opts->flags, TRUNC_XIB);
27114 + au_fset_opts(opts->flags, REFRESH);
27120 + err = au_br_mod(sb, &opt->mod,
27121 + au_ftest_opts(opts->flags, REMOUNT),
27126 + au_fset_opts(opts->flags, REFRESH);
27133 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27134 + struct au_opt_xino **opt_xino,
27135 + struct au_opts *opts)
27140 + switch (opt->type) {
27142 + err = au_xino_set(sb, &opt->xino,
27143 + !!au_ftest_opts(opts->flags, REMOUNT));
27144 + if (unlikely(err))
27147 + *opt_xino = &opt->xino;
27152 + *opt_xino = (void *)-1;
27159 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27160 + unsigned int pending)
27163 + aufs_bindex_t bindex, bbot;
27164 + unsigned char do_plink, skip, do_free, can_no_dreval;
27165 + struct au_branch *br;
27166 + struct au_wbr *wbr;
27167 + struct dentry *root, *dentry;
27168 + struct inode *dir, *h_dir;
27169 + struct au_sbinfo *sbinfo;
27170 + struct au_hinode *hdir;
27172 + SiMustAnyLock(sb);
27174 + sbinfo = au_sbi(sb);
27175 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27177 + if (!(sb_flags & SB_RDONLY)) {
27178 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27179 + pr_warn("first branch should be rw\n");
27180 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27181 + pr_warn_once("shwh should be used with ro\n");
27184 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27185 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27186 + pr_warn_once("udba=*notify requires xino\n");
27188 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27189 + pr_warn_once("dirperm1 breaks the protection"
27190 + " by the permission bits on the lower branch\n");
27194 + root = sb->s_root;
27195 + dir = d_inode(root);
27196 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27197 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27199 + bbot = au_sbbot(sb);
27200 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27202 + h_dir = au_h_iptr(dir, bindex);
27203 + br = au_sbr(sb, bindex);
27205 + if ((br->br_perm & AuBrAttr_ICEX)
27206 + && !h_dir->i_op->listxattr)
27207 + br->br_perm &= ~AuBrAttr_ICEX;
27208 +#if 0 /* untested */
27209 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27210 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27211 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27215 + wbr = br->br_wbr;
27217 + wbr_wh_read_lock(wbr);
27219 + if (!au_br_writable(br->br_perm)) {
27222 + || (!wbr->wbr_whbase
27223 + && !wbr->wbr_plink
27224 + && !wbr->wbr_orph));
27225 + } else if (!au_br_wh_linkable(br->br_perm)) {
27226 + /* skip = (!br->br_whbase && !br->br_orph); */
27227 + skip = (!wbr || !wbr->wbr_whbase);
27228 + if (skip && wbr) {
27230 + skip = !!wbr->wbr_plink;
27232 + skip = !wbr->wbr_plink;
27235 + /* skip = (br->br_whbase && br->br_ohph); */
27236 + skip = (wbr && wbr->wbr_whbase);
27239 + skip = !!wbr->wbr_plink;
27241 + skip = !wbr->wbr_plink;
27245 + wbr_wh_read_unlock(wbr);
27247 + if (can_no_dreval) {
27248 + dentry = br->br_path.dentry;
27249 + spin_lock(&dentry->d_lock);
27250 + if (dentry->d_flags &
27251 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27252 + can_no_dreval = 0;
27253 + spin_unlock(&dentry->d_lock);
27256 + if (au_br_fhsm(br->br_perm)) {
27258 + AuDebugOn(!br->br_fhsm);
27264 + hdir = au_hi(dir, bindex);
27265 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27267 + wbr_wh_write_lock(wbr);
27268 + err = au_wh_init(br, sb);
27270 + wbr_wh_write_unlock(wbr);
27271 + au_hn_inode_unlock(hdir);
27273 + if (!err && do_free) {
27274 + au_kfree_rcu(wbr);
27275 + br->br_wbr = NULL;
27279 + if (can_no_dreval)
27280 + au_fset_si(sbinfo, NO_DREVAL);
27282 + au_fclr_si(sbinfo, NO_DREVAL);
27285 + au_fset_si(sbinfo, FHSM);
27286 + for (bindex = bbot; bindex >= 0; bindex--) {
27287 + br = au_sbr(sb, bindex);
27288 + if (au_br_fhsm(br->br_perm)) {
27289 + au_fhsm_set_bottom(sb, bindex);
27294 + au_fclr_si(sbinfo, FHSM);
27295 + au_fhsm_set_bottom(sb, -1);
27301 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27304 + unsigned int tmp;
27305 + aufs_bindex_t bindex, bbot;
27306 + struct au_opt *opt;
27307 + struct au_opt_xino *opt_xino, xino;
27308 + struct au_sbinfo *sbinfo;
27309 + struct au_branch *br;
27310 + struct inode *dir;
27312 + SiMustWriteLock(sb);
27317 + while (err >= 0 && opt->type != Opt_tail)
27318 + err = au_opt_simple(sb, opt++, opts);
27321 + else if (unlikely(err < 0))
27324 + /* disable xino and udba temporary */
27325 + sbinfo = au_sbi(sb);
27326 + tmp = sbinfo->si_mntflags;
27327 + au_opt_clr(sbinfo->si_mntflags, XINO);
27328 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27331 + while (err >= 0 && opt->type != Opt_tail)
27332 + err = au_opt_br(sb, opt++, opts);
27335 + else if (unlikely(err < 0))
27338 + bbot = au_sbbot(sb);
27339 + if (unlikely(bbot < 0)) {
27341 + pr_err("no branches\n");
27345 + if (au_opt_test(tmp, XINO))
27346 + au_opt_set(sbinfo->si_mntflags, XINO);
27348 + while (!err && opt->type != Opt_tail)
27349 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27350 + if (unlikely(err))
27353 + err = au_opts_verify(sb, sb->s_flags, tmp);
27354 + if (unlikely(err))
27357 + /* restore xino */
27358 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27359 + xino.file = au_xino_def(sb);
27360 + err = PTR_ERR(xino.file);
27361 + if (IS_ERR(xino.file))
27364 + err = au_xino_set(sb, &xino, /*remount*/0);
27366 + if (unlikely(err))
27370 + /* restore udba */
27371 + tmp &= AuOptMask_UDBA;
27372 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27373 + sbinfo->si_mntflags |= tmp;
27374 + bbot = au_sbbot(sb);
27375 + for (bindex = 0; bindex <= bbot; bindex++) {
27376 + br = au_sbr(sb, bindex);
27377 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27378 + if (unlikely(err))
27379 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27381 + /* go on even if err */
27383 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27384 + dir = d_inode(sb->s_root);
27385 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27392 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27395 + unsigned char no_dreval;
27396 + struct inode *dir;
27397 + struct au_opt_xino *opt_xino;
27398 + struct au_opt *opt;
27399 + struct au_sbinfo *sbinfo;
27401 + SiMustWriteLock(sb);
27403 + err = au_dr_opt_flush(sb);
27404 + if (unlikely(err))
27406 + au_fset_opts(opts->flags, DR_FLUSHED);
27408 + dir = d_inode(sb->s_root);
27409 + sbinfo = au_sbi(sb);
27412 + while (err >= 0 && opt->type != Opt_tail) {
27413 + err = au_opt_simple(sb, opt, opts);
27415 + err = au_opt_br(sb, opt, opts);
27417 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27423 + /* go on even err */
27425 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27426 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27427 + if (unlikely(rerr && !err))
27430 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27431 + au_fset_opts(opts->flags, REFRESH_IDOP);
27433 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27434 + rerr = au_xib_trunc(sb);
27435 + if (unlikely(rerr && !err))
27439 + /* will be handled by the caller */
27440 + if (!au_ftest_opts(opts->flags, REFRESH)
27441 + && (opts->given_udba
27442 + || au_opt_test(sbinfo->si_mntflags, XINO)
27443 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27445 + au_fset_opts(opts->flags, REFRESH);
27447 + AuDbg("status 0x%x\n", opts->flags);
27453 +/* ---------------------------------------------------------------------- */
27455 +unsigned int au_opt_udba(struct super_block *sb)
27457 + return au_mntflags(sb) & AuOptMask_UDBA;
27459 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27460 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27461 +++ linux/fs/aufs/opts.h 2021-12-03 15:38:59.939980643 +0100
27463 +/* SPDX-License-Identifier: GPL-2.0 */
27465 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27467 + * This program, aufs is free software; you can redistribute it and/or modify
27468 + * it under the terms of the GNU General Public License as published by
27469 + * the Free Software Foundation; either version 2 of the License, or
27470 + * (at your option) any later version.
27472 + * This program is distributed in the hope that it will be useful,
27473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27475 + * GNU General Public License for more details.
27477 + * You should have received a copy of the GNU General Public License
27478 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27482 + * mount options/flags
27485 +#ifndef __AUFS_OPTS_H__
27486 +#define __AUFS_OPTS_H__
27490 +#include <linux/path.h>
27494 +/* ---------------------------------------------------------------------- */
27497 +#define AuOpt_XINO 1 /* external inode number bitmap
27498 + and translation table */
27499 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27500 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27501 +#define AuOpt_UDBA_REVAL (1 << 3)
27502 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27503 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27504 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27505 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27507 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27508 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27509 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27510 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27511 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27512 +#define AuOpt_DIO (1 << 14) /* direct io */
27513 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27515 +#ifndef CONFIG_AUFS_HNOTIFY
27516 +#undef AuOpt_UDBA_HNOTIFY
27517 +#define AuOpt_UDBA_HNOTIFY 0
27519 +#ifndef CONFIG_AUFS_DIRREN
27520 +#undef AuOpt_DIRREN
27521 +#define AuOpt_DIRREN 0
27523 +#ifndef CONFIG_AUFS_SHWH
27525 +#define AuOpt_SHWH 0
27528 +#define AuOpt_Def (AuOpt_XINO \
27529 + | AuOpt_UDBA_REVAL \
27531 + /* | AuOpt_DIRPERM1 */ \
27532 + | AuOpt_WARN_PERM)
27533 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27534 + | AuOpt_UDBA_REVAL \
27535 + | AuOpt_UDBA_HNOTIFY)
27537 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27538 +#define au_opt_set(flags, name) do { \
27539 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27540 + ((flags) |= AuOpt_##name); \
27542 +#define au_opt_set_udba(flags, name) do { \
27543 + (flags) &= ~AuOptMask_UDBA; \
27544 + ((flags) |= AuOpt_##name); \
27546 +#define au_opt_clr(flags, name) do { \
27547 + ((flags) &= ~AuOpt_##name); \
27550 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27552 +#ifdef CONFIG_PROC_FS
27555 + return mntflags & ~AuOpt_PLINK;
27559 +/* ---------------------------------------------------------------------- */
27561 +/* policies to select one among multiple writable branches */
27563 + AuWbrCreate_TDP, /* top down parent */
27564 + AuWbrCreate_RR, /* round robin */
27565 + AuWbrCreate_MFS, /* most free space */
27566 + AuWbrCreate_MFSV, /* mfs with seconds */
27567 + AuWbrCreate_MFSRR, /* mfs then rr */
27568 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27569 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27570 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27571 + AuWbrCreate_PMFS, /* parent and mfs */
27572 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27573 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27574 + AuWbrCreate_PMFSRRV, /* plus seconds */
27576 + AuWbrCreate_Def = AuWbrCreate_TDP
27580 + AuWbrCopyup_TDP, /* top down parent */
27581 + AuWbrCopyup_BUP, /* bottom up parent */
27582 + AuWbrCopyup_BU, /* bottom up */
27584 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27587 +/* ---------------------------------------------------------------------- */
27589 +struct au_opt_add {
27590 + aufs_bindex_t bindex;
27593 + struct path path;
27596 +struct au_opt_del {
27598 + struct path h_path;
27601 +struct au_opt_mod {
27604 + struct dentry *h_root;
27607 +struct au_opt_xino {
27609 + struct file *file;
27612 +struct au_opt_xino_itrunc {
27613 + aufs_bindex_t bindex;
27616 +struct au_opt_wbr_create {
27619 + unsigned long long mfsrr_watermark;
27625 + struct au_opt_xino xino;
27626 + struct au_opt_xino_itrunc xino_itrunc;
27627 + struct au_opt_add add;
27628 + struct au_opt_del del;
27629 + struct au_opt_mod mod;
27632 + unsigned int rdblk;
27633 + unsigned int rdhash;
27635 + struct au_opt_wbr_create wbr_create;
27637 + unsigned int fhsm_second;
27642 +#define AuOpts_REMOUNT 1
27643 +#define AuOpts_REFRESH (1 << 1)
27644 +#define AuOpts_TRUNC_XIB (1 << 2)
27645 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27646 +#define AuOpts_REFRESH_IDOP (1 << 4)
27647 +#define AuOpts_DR_FLUSHED (1 << 5)
27648 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27649 +#define au_fset_opts(flags, name) \
27650 + do { (flags) |= AuOpts_##name; } while (0)
27651 +#define au_fclr_opts(flags, name) \
27652 + do { (flags) &= ~AuOpts_##name; } while (0)
27654 +#ifndef CONFIG_AUFS_DIRREN
27655 +#undef AuOpts_DR_FLUSHED
27656 +#define AuOpts_DR_FLUSHED 0
27660 + struct au_opt *opt;
27663 + unsigned int given_udba;
27664 + unsigned int flags;
27665 + unsigned long sb_flags;
27668 +/* ---------------------------------------------------------------------- */
27671 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27672 +const char *au_optstr_udba(int udba);
27673 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27674 +const char *au_optstr_wbr_create(int wbr_create);
27676 +void au_opts_free(struct au_opts *opts);
27677 +struct super_block;
27678 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27679 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27680 + unsigned int pending);
27681 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27682 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27684 +unsigned int au_opt_udba(struct super_block *sb);
27686 +#endif /* __KERNEL__ */
27687 +#endif /* __AUFS_OPTS_H__ */
27688 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27689 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27690 +++ linux/fs/aufs/plink.c 2021-12-03 15:38:59.939980643 +0100
27692 +// SPDX-License-Identifier: GPL-2.0
27694 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27696 + * This program, aufs is free software; you can redistribute it and/or modify
27697 + * it under the terms of the GNU General Public License as published by
27698 + * the Free Software Foundation; either version 2 of the License, or
27699 + * (at your option) any later version.
27701 + * This program is distributed in the hope that it will be useful,
27702 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27703 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27704 + * GNU General Public License for more details.
27706 + * You should have received a copy of the GNU General Public License
27707 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27717 + * the pseudo-link maintenance mode.
27718 + * during a user process maintains the pseudo-links,
27719 + * prohibit adding a new plink and branch manipulation.
27723 + * For entry functions which will handle plink, and i_mutex is already held
27725 + * They cannot wait and should return an error at once.
27726 + * Callers has to check the error.
27728 + * For entry functions which will handle plink, but i_mutex is not held
27730 + * They can wait the plink maintenance mode to finish.
27732 + * They behave like F_SETLK and F_SETLKW.
27733 + * If the caller never handle plink, then both flags are unnecessary.
27736 +int au_plink_maint(struct super_block *sb, int flags)
27740 + struct task_struct *parent, *prev;
27741 + struct au_sbinfo *sbi;
27743 + SiMustAnyLock(sb);
27746 + if (!au_opt_test(au_mntflags(sb), PLINK))
27749 + sbi = au_sbi(sb);
27750 + pid = sbi->si_plink_maint_pid;
27751 + if (!pid || pid == current->pid)
27754 + /* todo: it highly depends upon /sbin/mount.aufs */
27756 + parent = current;
27760 + parent = rcu_dereference(parent->real_parent);
27761 + if (parent == prev)
27763 + ppid = task_pid_vnr(parent);
27764 + if (pid == ppid) {
27765 + rcu_read_unlock();
27770 + rcu_read_unlock();
27772 + if (au_ftest_lock(flags, NOPLMW)) {
27773 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27774 + /* AuDebugOn(!lockdep_depth(current)); */
27775 + while (sbi->si_plink_maint_pid) {
27776 + si_read_unlock(sb);
27777 + /* gave up wake_up_bit() */
27778 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27780 + if (au_ftest_lock(flags, FLUSH))
27781 + au_nwt_flush(&sbi->si_nowait);
27782 + si_noflush_read_lock(sb);
27784 + } else if (au_ftest_lock(flags, NOPLM)) {
27785 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27793 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27795 + spin_lock(&sbinfo->si_plink_maint_lock);
27796 + sbinfo->si_plink_maint_pid = 0;
27797 + spin_unlock(&sbinfo->si_plink_maint_lock);
27798 + wake_up_all(&sbinfo->si_plink_wq);
27801 +int au_plink_maint_enter(struct super_block *sb)
27804 + struct au_sbinfo *sbinfo;
27807 + sbinfo = au_sbi(sb);
27808 + /* make sure i am the only one in this fs */
27809 + si_write_lock(sb, AuLock_FLUSH);
27810 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27811 + spin_lock(&sbinfo->si_plink_maint_lock);
27812 + if (!sbinfo->si_plink_maint_pid)
27813 + sbinfo->si_plink_maint_pid = current->pid;
27816 + spin_unlock(&sbinfo->si_plink_maint_lock);
27818 + si_write_unlock(sb);
27823 +/* ---------------------------------------------------------------------- */
27825 +#ifdef CONFIG_AUFS_DEBUG
27826 +void au_plink_list(struct super_block *sb)
27829 + struct au_sbinfo *sbinfo;
27830 + struct hlist_bl_head *hbl;
27831 + struct hlist_bl_node *pos;
27832 + struct au_icntnr *icntnr;
27834 + SiMustAnyLock(sb);
27836 + sbinfo = au_sbi(sb);
27837 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27838 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27840 + for (i = 0; i < AuPlink_NHASH; i++) {
27841 + hbl = sbinfo->si_plink + i;
27842 + hlist_bl_lock(hbl);
27843 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27844 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27845 + hlist_bl_unlock(hbl);
27850 +/* is the inode pseudo-linked? */
27851 +int au_plink_test(struct inode *inode)
27854 + struct au_sbinfo *sbinfo;
27855 + struct hlist_bl_head *hbl;
27856 + struct hlist_bl_node *pos;
27857 + struct au_icntnr *icntnr;
27859 + sbinfo = au_sbi(inode->i_sb);
27860 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27861 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27862 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27865 + i = au_plink_hash(inode->i_ino);
27866 + hbl = sbinfo->si_plink + i;
27867 + hlist_bl_lock(hbl);
27868 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27869 + if (&icntnr->vfs_inode == inode) {
27873 + hlist_bl_unlock(hbl);
27877 +/* ---------------------------------------------------------------------- */
27880 + * generate a name for plink.
27881 + * the file will be stored under AUFS_WH_PLINKDIR.
27883 +/* 20 is max digits length of ulong 64 */
27884 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27886 +static int plink_name(char *name, int len, struct inode *inode,
27887 + aufs_bindex_t bindex)
27890 + struct inode *h_inode;
27892 + h_inode = au_h_iptr(inode, bindex);
27893 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27897 +struct au_do_plink_lkup_args {
27898 + struct dentry **errp;
27899 + struct qstr *tgtname;
27900 + struct path *h_ppath;
27903 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27904 + struct path *h_ppath)
27906 + struct dentry *h_dentry;
27907 + struct inode *h_inode;
27909 + h_inode = d_inode(h_ppath->dentry);
27910 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27911 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
27912 + inode_unlock_shared(h_inode);
27917 +static void au_call_do_plink_lkup(void *args)
27919 + struct au_do_plink_lkup_args *a = args;
27920 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
27923 +/* lookup the plink-ed @inode under the branch at @bindex */
27924 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27926 + struct dentry *h_dentry;
27927 + struct au_branch *br;
27928 + struct path h_ppath;
27930 + char a[PLINK_NAME_LEN];
27931 + struct qstr tgtname = QSTR_INIT(a, 0);
27933 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27935 + br = au_sbr(inode->i_sb, bindex);
27936 + h_ppath.dentry = br->br_wbr->wbr_plink;
27937 + h_ppath.mnt = au_br_mnt(br);
27938 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27940 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27941 + struct au_do_plink_lkup_args args = {
27942 + .errp = &h_dentry,
27943 + .tgtname = &tgtname,
27944 + .h_ppath = &h_ppath
27947 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27948 + if (unlikely(wkq_err))
27949 + h_dentry = ERR_PTR(wkq_err);
27951 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
27956 +/* create a pseudo-link */
27957 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
27958 + struct dentry *h_dentry)
27961 + struct path h_path;
27962 + struct inode *h_dir, *delegated;
27964 + h_dir = d_inode(h_ppath->dentry);
27965 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27966 + h_path.mnt = h_ppath->mnt;
27968 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
27969 + err = PTR_ERR(h_path.dentry);
27970 + if (IS_ERR(h_path.dentry))
27974 + /* wh.plink dir is not monitored */
27975 + /* todo: is it really safe? */
27976 + if (d_is_positive(h_path.dentry)
27977 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27978 + delegated = NULL;
27979 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27980 + if (unlikely(err == -EWOULDBLOCK)) {
27981 + pr_warn("cannot retry for NFSv4 delegation"
27982 + " for an internal unlink\n");
27985 + dput(h_path.dentry);
27986 + h_path.dentry = NULL;
27990 + if (!err && d_is_negative(h_path.dentry)) {
27991 + delegated = NULL;
27992 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27993 + if (unlikely(err == -EWOULDBLOCK)) {
27994 + pr_warn("cannot retry for NFSv4 delegation"
27995 + " for an internal link\n");
27999 + dput(h_path.dentry);
28002 + inode_unlock(h_dir);
28006 +struct do_whplink_args {
28008 + struct qstr *tgt;
28009 + struct path *h_ppath;
28010 + struct dentry *h_dentry;
28013 +static void call_do_whplink(void *args)
28015 + struct do_whplink_args *a = args;
28016 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28019 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28020 + aufs_bindex_t bindex)
28022 + int err, wkq_err;
28023 + struct au_branch *br;
28024 + struct au_wbr *wbr;
28025 + struct path h_ppath;
28026 + char a[PLINK_NAME_LEN];
28027 + struct qstr tgtname = QSTR_INIT(a, 0);
28029 + br = au_sbr(inode->i_sb, bindex);
28030 + wbr = br->br_wbr;
28031 + h_ppath.dentry = wbr->wbr_plink;
28032 + h_ppath.mnt = au_br_mnt(br);
28033 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28035 + /* always superio. */
28036 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28037 + struct do_whplink_args args = {
28040 + .h_ppath = &h_ppath,
28041 + .h_dentry = h_dentry
28043 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28044 + if (unlikely(wkq_err))
28047 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28053 + * create a new pseudo-link for @h_dentry on @bindex.
28054 + * the linked inode is held in aufs @inode.
28056 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28057 + struct dentry *h_dentry)
28059 + struct super_block *sb;
28060 + struct au_sbinfo *sbinfo;
28061 + struct hlist_bl_head *hbl;
28062 + struct hlist_bl_node *pos;
28063 + struct au_icntnr *icntnr;
28064 + int found, err, cnt, i;
28066 + sb = inode->i_sb;
28067 + sbinfo = au_sbi(sb);
28068 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28069 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28071 + found = au_plink_test(inode);
28075 + i = au_plink_hash(inode->i_ino);
28076 + hbl = sbinfo->si_plink + i;
28079 + hlist_bl_lock(hbl);
28080 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28081 + if (&icntnr->vfs_inode == inode) {
28087 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28088 + hlist_bl_add_head(&icntnr->plink, hbl);
28090 + hlist_bl_unlock(hbl);
28092 + cnt = au_hbl_count(hbl);
28093 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28094 + if (cnt > AUFS_PLINK_WARN)
28095 + AuWarn1(msg ", %d\n", cnt);
28097 + err = whplink(h_dentry, inode, bindex);
28098 + if (unlikely(err)) {
28099 + pr_warn("err %d, damaged pseudo link.\n", err);
28100 + au_hbl_del(&icntnr->plink, hbl);
28101 + iput(&icntnr->vfs_inode);
28104 + iput(&icntnr->vfs_inode);
28107 +/* free all plinks */
28108 +void au_plink_put(struct super_block *sb, int verbose)
28111 + struct au_sbinfo *sbinfo;
28112 + struct hlist_bl_head *hbl;
28113 + struct hlist_bl_node *pos, *tmp;
28114 + struct au_icntnr *icntnr;
28116 + SiMustWriteLock(sb);
28118 + sbinfo = au_sbi(sb);
28119 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28120 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28122 + /* no spin_lock since sbinfo is write-locked */
28124 + for (i = 0; i < AuPlink_NHASH; i++) {
28125 + hbl = sbinfo->si_plink + i;
28126 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28127 + pr_warn("pseudo-link is not flushed");
28130 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28131 + iput(&icntnr->vfs_inode);
28132 + INIT_HLIST_BL_HEAD(hbl);
28136 +void au_plink_clean(struct super_block *sb, int verbose)
28138 + struct dentry *root;
28140 + root = sb->s_root;
28141 + aufs_write_lock(root);
28142 + if (au_opt_test(au_mntflags(sb), PLINK))
28143 + au_plink_put(sb, verbose);
28144 + aufs_write_unlock(root);
28147 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28150 + aufs_bindex_t btop, bbot, bindex;
28153 + btop = au_ibtop(inode);
28154 + bbot = au_ibbot(inode);
28156 + for (bindex = btop; bindex <= bbot; bindex++) {
28157 + if (!au_h_iptr(inode, bindex)
28158 + || au_ii_br_id(inode, bindex) != br_id)
28160 + au_set_h_iptr(inode, bindex, NULL, 0);
28165 + for (bindex = btop; bindex <= bbot; bindex++)
28166 + if (au_h_iptr(inode, bindex)) {
28176 +/* free the plinks on a branch specified by @br_id */
28177 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28179 + struct au_sbinfo *sbinfo;
28180 + struct hlist_bl_head *hbl;
28181 + struct hlist_bl_node *pos, *tmp;
28182 + struct au_icntnr *icntnr;
28183 + struct inode *inode;
28186 + SiMustWriteLock(sb);
28188 + sbinfo = au_sbi(sb);
28189 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28190 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28192 + /* no bit_lock since sbinfo is write-locked */
28193 + for (i = 0; i < AuPlink_NHASH; i++) {
28194 + hbl = sbinfo->si_plink + i;
28195 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28196 + inode = au_igrab(&icntnr->vfs_inode);
28197 + ii_write_lock_child(inode);
28198 + do_put = au_plink_do_half_refresh(inode, br_id);
28200 + hlist_bl_del(&icntnr->plink);
28203 + ii_write_unlock(inode);
28208 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28209 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28210 +++ linux/fs/aufs/poll.c 2021-12-03 15:38:59.939980643 +0100
28212 +// SPDX-License-Identifier: GPL-2.0
28214 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28216 + * This program, aufs is free software; you can redistribute it and/or modify
28217 + * it under the terms of the GNU General Public License as published by
28218 + * the Free Software Foundation; either version 2 of the License, or
28219 + * (at your option) any later version.
28221 + * This program is distributed in the hope that it will be useful,
28222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28224 + * GNU General Public License for more details.
28226 + * You should have received a copy of the GNU General Public License
28227 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28232 + * There is only one filesystem which implements ->poll operation, currently.
28237 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28240 + struct file *h_file;
28241 + struct super_block *sb;
28243 + /* We should pretend an error happened. */
28244 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28245 + sb = file->f_path.dentry->d_sb;
28246 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28248 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28249 + if (IS_ERR(h_file)) {
28250 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28254 + mask = vfs_poll(h_file, pt);
28255 + fput(h_file); /* instead of au_read_post() */
28258 + si_read_unlock(sb);
28259 + if (mask & EPOLLERR)
28260 + AuDbg("mask 0x%x\n", mask);
28263 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28264 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28265 +++ linux/fs/aufs/posix_acl.c 2021-12-03 15:40:58.236647297 +0100
28267 +// SPDX-License-Identifier: GPL-2.0
28269 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28271 + * This program, aufs is free software; you can redistribute it and/or modify
28272 + * it under the terms of the GNU General Public License as published by
28273 + * the Free Software Foundation; either version 2 of the License, or
28274 + * (at your option) any later version.
28276 + * This program is distributed in the hope that it will be useful,
28277 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28278 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28279 + * GNU General Public License for more details.
28281 + * You should have received a copy of the GNU General Public License
28282 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28286 + * posix acl operations
28289 +#include <linux/fs.h>
28292 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28294 + struct posix_acl *acl;
28296 + aufs_bindex_t bindex;
28297 + struct inode *h_inode;
28298 + struct super_block *sb;
28300 + acl = ERR_PTR(-ECHILD);
28305 + sb = inode->i_sb;
28306 + si_read_lock(sb, AuLock_FLUSH);
28307 + ii_read_lock_child(inode);
28308 + if (!(sb->s_flags & SB_POSIXACL))
28311 + bindex = au_ibtop(inode);
28312 + h_inode = au_h_iptr(inode, bindex);
28313 + if (unlikely(!h_inode
28314 + || ((h_inode->i_mode & S_IFMT)
28315 + != (inode->i_mode & S_IFMT)))) {
28316 + err = au_busy_or_stale();
28317 + acl = ERR_PTR(err);
28321 + /* always topmost only */
28322 + acl = get_acl(h_inode, type);
28324 + forget_cached_acl(inode, type);
28326 + set_cached_acl(inode, type, acl);
28329 + ii_read_unlock(inode);
28330 + si_read_unlock(sb);
28333 + AuTraceErrPtr(acl);
28337 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28338 + struct posix_acl *acl, int type)
28342 + struct dentry *dentry;
28343 + struct au_sxattr arg = {
28344 + .type = AU_ACL_SET,
28351 + IMustLock(inode);
28353 + if (inode->i_ino == AUFS_ROOT_INO)
28354 + dentry = dget(inode->i_sb->s_root);
28356 + dentry = d_find_alias(inode);
28358 + dentry = d_find_any_alias(inode);
28360 + pr_warn("cannot handle this inode, "
28361 + "please report to aufs-users ML\n");
28367 + ssz = au_sxattr(dentry, inode, &arg);
28368 + /* forget even it if succeeds since the branch might set differently */
28369 + forget_cached_acl(inode, type);
28378 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28379 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28380 +++ linux/fs/aufs/procfs.c 2021-12-03 15:38:59.939980643 +0100
28382 +// SPDX-License-Identifier: GPL-2.0
28384 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28386 + * This program, aufs is free software; you can redistribute it and/or modify
28387 + * it under the terms of the GNU General Public License as published by
28388 + * the Free Software Foundation; either version 2 of the License, or
28389 + * (at your option) any later version.
28391 + * This program is distributed in the hope that it will be useful,
28392 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28393 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28394 + * GNU General Public License for more details.
28396 + * You should have received a copy of the GNU General Public License
28397 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28401 + * procfs interfaces
28404 +#include <linux/proc_fs.h>
28407 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28409 + struct au_sbinfo *sbinfo;
28411 + sbinfo = file->private_data;
28413 + au_plink_maint_leave(sbinfo);
28414 + kobject_put(&sbinfo->si_kobj);
28420 +static void au_procfs_plm_write_clean(struct file *file)
28422 + struct au_sbinfo *sbinfo;
28424 + sbinfo = file->private_data;
28426 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28429 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28432 + struct super_block *sb;
28433 + struct au_sbinfo *sbinfo;
28434 + struct hlist_bl_node *pos;
28437 + if (unlikely(file->private_data))
28441 + /* don't use au_sbilist_lock() here */
28442 + hlist_bl_lock(&au_sbilist);
28443 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28444 + if (id == sysaufs_si_id(sbinfo)) {
28445 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28446 + sb = sbinfo->si_sb;
28449 + hlist_bl_unlock(&au_sbilist);
28452 + if (unlikely(!sb))
28455 + err = au_plink_maint_enter(sb);
28457 + /* keep kobject_get() */
28458 + file->private_data = sbinfo;
28460 + kobject_put(&sbinfo->si_kobj);
28466 + * Accept a valid "si=xxxx" only.
28467 + * Once it is accepted successfully, accept "clean" too.
28469 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28470 + size_t count, loff_t *ppos)
28473 + unsigned long id;
28474 + /* last newline is allowed */
28475 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28478 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28482 + if (unlikely(count > sizeof(buf)))
28485 + err = copy_from_user(buf, ubuf, count);
28486 + if (unlikely(err)) {
28493 + if (!strcmp("clean", buf)) {
28494 + au_procfs_plm_write_clean(file);
28495 + goto out_success;
28496 + } else if (unlikely(strncmp("si=", buf, 3)))
28499 + err = kstrtoul(buf + 3, 16, &id);
28500 + if (unlikely(err))
28503 + err = au_procfs_plm_write_si(file, id);
28504 + if (unlikely(err))
28508 + err = count; /* success */
28513 +static const struct proc_ops au_procfs_plm_op = {
28514 + .proc_write = au_procfs_plm_write,
28515 + .proc_release = au_procfs_plm_release
28518 +/* ---------------------------------------------------------------------- */
28520 +static struct proc_dir_entry *au_procfs_dir;
28522 +void au_procfs_fin(void)
28524 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28525 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28528 +int __init au_procfs_init(void)
28531 + struct proc_dir_entry *entry;
28534 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28535 + if (unlikely(!au_procfs_dir))
28538 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28539 + au_procfs_dir, &au_procfs_plm_op);
28540 + if (unlikely(!entry))
28544 + goto out; /* success */
28548 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28552 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28553 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28554 +++ linux/fs/aufs/rdu.c 2021-12-03 15:38:59.939980643 +0100
28556 +// SPDX-License-Identifier: GPL-2.0
28558 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28560 + * This program, aufs is free software; you can redistribute it and/or modify
28561 + * it under the terms of the GNU General Public License as published by
28562 + * the Free Software Foundation; either version 2 of the License, or
28563 + * (at your option) any later version.
28565 + * This program is distributed in the hope that it will be useful,
28566 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28567 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28568 + * GNU General Public License for more details.
28570 + * You should have received a copy of the GNU General Public License
28571 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28575 + * readdir in userspace.
28578 +#include <linux/compat.h>
28579 +#include <linux/fs_stack.h>
28580 +#include <linux/security.h>
28583 +/* bits for struct aufs_rdu.flags */
28584 +#define AuRdu_CALLED 1
28585 +#define AuRdu_CONT (1 << 1)
28586 +#define AuRdu_FULL (1 << 2)
28587 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28588 +#define au_fset_rdu(flags, name) \
28589 + do { (flags) |= AuRdu_##name; } while (0)
28590 +#define au_fclr_rdu(flags, name) \
28591 + do { (flags) &= ~AuRdu_##name; } while (0)
28593 +struct au_rdu_arg {
28594 + struct dir_context ctx;
28595 + struct aufs_rdu *rdu;
28596 + union au_rdu_ent_ul ent;
28597 + unsigned long end;
28599 + struct super_block *sb;
28603 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28604 + loff_t offset, u64 h_ino, unsigned int d_type)
28607 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28608 + struct aufs_rdu *rdu = arg->rdu;
28609 + struct au_rdu_ent ent;
28613 + au_fset_rdu(rdu->cookie.flags, CALLED);
28614 + len = au_rdu_len(nlen);
28615 + if (arg->ent.ul + len < arg->end) {
28617 + ent.bindex = rdu->cookie.bindex;
28618 + ent.type = d_type;
28620 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28621 + ent.type = DT_UNKNOWN;
28623 + /* unnecessary to support mmap_sem since this is a dir */
28625 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28627 + if (copy_to_user(arg->ent.e->name, name, nlen))
28629 + /* the terminating NULL */
28630 + if (__put_user(0, arg->ent.e->name + nlen))
28633 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28634 + arg->ent.ul += len;
28638 + au_fset_rdu(rdu->cookie.flags, FULL);
28640 + rdu->tail = arg->ent;
28644 + /* AuTraceErr(err); */
28648 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28652 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28654 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28655 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28657 + if (unlikely(offset != cookie->h_pos))
28663 + au_fclr_rdu(cookie->flags, CALLED);
28665 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28669 + && au_ftest_rdu(cookie->flags, CALLED)
28670 + && !au_ftest_rdu(cookie->flags, FULL));
28671 + cookie->h_pos = h_file->f_pos;
28678 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28681 + aufs_bindex_t bbot;
28682 + struct au_rdu_arg arg = {
28684 + .actor = au_rdu_fill
28687 + struct dentry *dentry;
28688 + struct inode *inode;
28689 + struct file *h_file;
28690 + struct au_rdu_cookie *cookie = &rdu->cookie;
28692 + /* VERIFY_WRITE */
28693 + err = !access_ok(rdu->ent.e, rdu->sz);
28694 + if (unlikely(err)) {
28700 + rdu->tail = rdu->ent;
28703 + arg.ent = rdu->ent;
28704 + arg.end = arg.ent.ul;
28705 + arg.end += rdu->sz;
28708 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28711 + err = security_file_permission(file, MAY_READ);
28713 + if (unlikely(err))
28716 + dentry = file->f_path.dentry;
28717 + inode = d_inode(dentry);
28718 + inode_lock_shared(inode);
28720 + arg.sb = inode->i_sb;
28721 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28722 + if (unlikely(err))
28724 + err = au_alive_dir(dentry);
28725 + if (unlikely(err))
28727 + /* todo: reval? */
28728 + fi_read_lock(file);
28731 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28732 + && cookie->generation != au_figen(file)))
28737 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28739 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28741 + bbot = au_fbtop(file);
28742 + if (cookie->bindex < bbot)
28743 + cookie->bindex = bbot;
28744 + bbot = au_fbbot_dir(file);
28745 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28746 + for (; !err && cookie->bindex <= bbot;
28747 + cookie->bindex++, cookie->h_pos = 0) {
28748 + h_file = au_hf_dir(file, cookie->bindex);
28752 + au_fclr_rdu(cookie->flags, FULL);
28753 + err = au_rdu_do(h_file, &arg);
28755 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28758 + AuDbg("rent %llu\n", rdu->rent);
28760 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28761 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28762 + au_fset_rdu(cookie->flags, CONT);
28763 + cookie->generation = au_figen(file);
28766 + ii_read_lock_child(inode);
28767 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28768 + ii_read_unlock(inode);
28771 + fi_read_unlock(file);
28773 + si_read_unlock(arg.sb);
28775 + inode_unlock_shared(inode);
28781 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28785 + unsigned long long nent;
28786 + union au_rdu_ent_ul *u;
28787 + struct au_rdu_ent ent;
28788 + struct super_block *sb;
28791 + nent = rdu->nent;
28793 + sb = file->f_path.dentry->d_sb;
28794 + si_read_lock(sb, AuLock_FLUSH);
28795 + while (nent-- > 0) {
28796 + /* unnecessary to support mmap_sem since this is a dir */
28797 + err = copy_from_user(&ent, u->e, sizeof(ent));
28799 + /* VERIFY_WRITE */
28800 + err = !access_ok(&u->e->ino, sizeof(ino));
28801 + if (unlikely(err)) {
28807 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28809 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28811 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28813 + if (unlikely(err)) {
28818 + err = __put_user(ino, &u->e->ino);
28819 + if (unlikely(err)) {
28824 + u->ul += au_rdu_len(ent.nlen);
28826 + si_read_unlock(sb);
28831 +/* ---------------------------------------------------------------------- */
28833 +static int au_rdu_verify(struct aufs_rdu *rdu)
28835 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28836 + "%llu, b%d, 0x%x, g%u}\n",
28837 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28839 + rdu->rent, rdu->shwh, rdu->full,
28840 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28841 + rdu->cookie.generation);
28843 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28847 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28851 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28854 + struct aufs_rdu rdu;
28855 + void __user *p = (void __user *)arg;
28857 + err = copy_from_user(&rdu, p, sizeof(rdu));
28858 + if (unlikely(err)) {
28863 + err = au_rdu_verify(&rdu);
28864 + if (unlikely(err))
28868 + case AUFS_CTL_RDU:
28869 + err = au_rdu(file, &rdu);
28870 + if (unlikely(err))
28873 + e = copy_to_user(p, &rdu, sizeof(rdu));
28874 + if (unlikely(e)) {
28879 + case AUFS_CTL_RDU_INO:
28880 + err = au_rdu_ino(file, &rdu);
28884 + /* err = -ENOTTY; */
28893 +#ifdef CONFIG_COMPAT
28894 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28897 + struct aufs_rdu rdu;
28898 + void __user *p = compat_ptr(arg);
28900 + /* todo: get_user()? */
28901 + err = copy_from_user(&rdu, p, sizeof(rdu));
28902 + if (unlikely(err)) {
28907 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28908 + err = au_rdu_verify(&rdu);
28909 + if (unlikely(err))
28913 + case AUFS_CTL_RDU:
28914 + err = au_rdu(file, &rdu);
28915 + if (unlikely(err))
28918 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28919 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28920 + e = copy_to_user(p, &rdu, sizeof(rdu));
28921 + if (unlikely(e)) {
28926 + case AUFS_CTL_RDU_INO:
28927 + err = au_rdu_ino(file, &rdu);
28931 + /* err = -ENOTTY; */
28940 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28941 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28942 +++ linux/fs/aufs/rwsem.h 2021-12-03 15:40:58.236647297 +0100
28944 +/* SPDX-License-Identifier: GPL-2.0 */
28946 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28948 + * This program, aufs is free software; you can redistribute it and/or modify
28949 + * it under the terms of the GNU General Public License as published by
28950 + * the Free Software Foundation; either version 2 of the License, or
28951 + * (at your option) any later version.
28953 + * This program is distributed in the hope that it will be useful,
28954 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28955 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28956 + * GNU General Public License for more details.
28958 + * You should have received a copy of the GNU General Public License
28959 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28963 + * simple read-write semaphore wrappers
28966 +#ifndef __AUFS_RWSEM_H__
28967 +#define __AUFS_RWSEM_H__
28971 +#include "debug.h"
28973 +/* in the future, the name 'au_rwsem' will be totally gone */
28974 +#define au_rwsem rw_semaphore
28976 +/* to debug easier, do not make them inlined functions */
28977 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28979 +#ifdef CONFIG_LOCKDEP
28980 +/* rwsem_is_locked() is unusable */
28981 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28982 + && !lockdep_recursing(current) \
28984 + && !lockdep_is_held_type(rw, 1))
28985 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28986 + && !lockdep_recursing(current) \
28988 + && !lockdep_is_held_type(rw, 0))
28989 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28990 + && !lockdep_recursing(current) \
28992 + && !lockdep_is_held(rw))
28993 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28994 + && !lockdep_recursing(current) \
28996 + && lockdep_is_held(rw))
28998 +#define AuRwMustReadLock(rw) do {} while (0)
28999 +#define AuRwMustWriteLock(rw) do {} while (0)
29000 +#define AuRwMustAnyLock(rw) do {} while (0)
29001 +#define AuRwDestroy(rw) do {} while (0)
29004 +#define au_rw_init(rw) init_rwsem(rw)
29006 +#define au_rw_init_wlock(rw) do { \
29007 + au_rw_init(rw); \
29008 + down_write(rw); \
29011 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29012 + au_rw_init(rw); \
29013 + down_write_nested(rw, lsc); \
29016 +#define au_rw_read_lock(rw) down_read(rw)
29017 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29018 +#define au_rw_read_unlock(rw) up_read(rw)
29019 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29020 +#define au_rw_write_lock(rw) down_write(rw)
29021 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29022 +#define au_rw_write_unlock(rw) up_write(rw)
29023 +/* why is not _nested version defined? */
29024 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29025 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29027 +#endif /* __KERNEL__ */
29028 +#endif /* __AUFS_RWSEM_H__ */
29029 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29030 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29031 +++ linux/fs/aufs/sbinfo.c 2021-12-03 15:38:59.939980643 +0100
29033 +// SPDX-License-Identifier: GPL-2.0
29035 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29037 + * This program, aufs is free software; you can redistribute it and/or modify
29038 + * it under the terms of the GNU General Public License as published by
29039 + * the Free Software Foundation; either version 2 of the License, or
29040 + * (at your option) any later version.
29042 + * This program is distributed in the hope that it will be useful,
29043 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29044 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29045 + * GNU General Public License for more details.
29047 + * You should have received a copy of the GNU General Public License
29048 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29052 + * superblock private data
29055 +#include <linux/iversion.h>
29059 + * they are necessary regardless sysfs is disabled.
29061 +void au_si_free(struct kobject *kobj)
29064 + struct au_sbinfo *sbinfo;
29065 + char *locked __maybe_unused; /* debug only */
29067 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29068 + for (i = 0; i < AuPlink_NHASH; i++)
29069 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29070 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29072 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29073 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29074 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29075 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29077 + dbgaufs_si_fin(sbinfo);
29078 + au_rw_write_lock(&sbinfo->si_rwsem);
29079 + au_br_free(sbinfo);
29080 + au_rw_write_unlock(&sbinfo->si_rwsem);
29082 + au_kfree_try_rcu(sbinfo->si_branch);
29083 + mutex_destroy(&sbinfo->si_xib_mtx);
29084 + AuRwDestroy(&sbinfo->si_rwsem);
29086 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29087 + /* si_nfiles is waited too */
29088 + au_kfree_rcu(sbinfo);
29091 +int au_si_alloc(struct super_block *sb)
29094 + struct au_sbinfo *sbinfo;
29097 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29098 + if (unlikely(!sbinfo))
29101 + /* will be reallocated separately */
29102 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29103 + if (unlikely(!sbinfo->si_branch))
29106 + err = sysaufs_si_init(sbinfo);
29108 + dbgaufs_si_null(sbinfo);
29109 + err = dbgaufs_si_init(sbinfo);
29110 + if (unlikely(err))
29111 + kobject_put(&sbinfo->si_kobj);
29113 + if (unlikely(err))
29116 + au_nwt_init(&sbinfo->si_nowait);
29117 + au_rw_init_wlock(&sbinfo->si_rwsem);
29119 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29120 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29122 + sbinfo->si_bbot = -1;
29123 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29125 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29126 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29127 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29128 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29130 + au_fhsm_init(sbinfo);
29132 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29134 + sbinfo->si_xino_jiffy = jiffies;
29135 + sbinfo->si_xino_expire
29136 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29137 + mutex_init(&sbinfo->si_xib_mtx);
29138 + /* leave si_xib_last_pindex and si_xib_next_bit */
29140 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29142 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29143 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29144 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29145 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29147 + for (i = 0; i < AuPlink_NHASH; i++)
29148 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29149 + init_waitqueue_head(&sbinfo->si_plink_wq);
29150 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29152 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29154 + /* with getattr by default */
29155 + sbinfo->si_iop_array = aufs_iop;
29157 + /* leave other members for sysaufs and si_mnt. */
29158 + sbinfo->si_sb = sb;
29159 + sb->s_fs_info = sbinfo;
29161 + return 0; /* success */
29164 + au_kfree_try_rcu(sbinfo->si_branch);
29166 + au_kfree_rcu(sbinfo);
29171 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29174 + struct au_branch **brp;
29176 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29179 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29180 + if (unlikely(!sz))
29181 + sz = sizeof(*brp);
29182 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29185 + sbinfo->si_branch = brp;
29192 +/* ---------------------------------------------------------------------- */
29194 +unsigned int au_sigen_inc(struct super_block *sb)
29196 + unsigned int gen;
29197 + struct inode *inode;
29199 + SiMustWriteLock(sb);
29201 + gen = ++au_sbi(sb)->si_generation;
29202 + au_update_digen(sb->s_root);
29203 + inode = d_inode(sb->s_root);
29204 + au_update_iigen(inode, /*half*/0);
29205 + inode_inc_iversion(inode);
29209 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29211 + aufs_bindex_t br_id;
29213 + struct au_sbinfo *sbinfo;
29215 + SiMustWriteLock(sb);
29217 + sbinfo = au_sbi(sb);
29218 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29219 + br_id = ++sbinfo->si_last_br_id;
29220 + AuDebugOn(br_id < 0);
29221 + if (br_id && au_br_index(sb, br_id) < 0)
29228 +/* ---------------------------------------------------------------------- */
29230 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29231 +int si_read_lock(struct super_block *sb, int flags)
29236 + if (au_ftest_lock(flags, FLUSH))
29237 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29239 + si_noflush_read_lock(sb);
29240 + err = au_plink_maint(sb, flags);
29241 + if (unlikely(err))
29242 + si_read_unlock(sb);
29247 +int si_write_lock(struct super_block *sb, int flags)
29251 + if (au_ftest_lock(flags, FLUSH))
29252 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29254 + si_noflush_write_lock(sb);
29255 + err = au_plink_maint(sb, flags);
29256 + if (unlikely(err))
29257 + si_write_unlock(sb);
29262 +/* dentry and super_block lock. call at entry point */
29263 +int aufs_read_lock(struct dentry *dentry, int flags)
29266 + struct super_block *sb;
29268 + sb = dentry->d_sb;
29269 + err = si_read_lock(sb, flags);
29270 + if (unlikely(err))
29273 + if (au_ftest_lock(flags, DW))
29274 + di_write_lock_child(dentry);
29276 + di_read_lock_child(dentry, flags);
29278 + if (au_ftest_lock(flags, GEN)) {
29279 + err = au_digen_test(dentry, au_sigen(sb));
29280 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29281 + AuDebugOn(!err && au_dbrange_test(dentry));
29283 + err = au_dbrange_test(dentry);
29284 + if (unlikely(err))
29285 + aufs_read_unlock(dentry, flags);
29292 +void aufs_read_unlock(struct dentry *dentry, int flags)
29294 + if (au_ftest_lock(flags, DW))
29295 + di_write_unlock(dentry);
29297 + di_read_unlock(dentry, flags);
29298 + si_read_unlock(dentry->d_sb);
29301 +void aufs_write_lock(struct dentry *dentry)
29303 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29304 + di_write_lock_child(dentry);
29307 +void aufs_write_unlock(struct dentry *dentry)
29309 + di_write_unlock(dentry);
29310 + si_write_unlock(dentry->d_sb);
29313 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29316 + unsigned int sigen;
29317 + struct super_block *sb;
29320 + err = si_read_lock(sb, flags);
29321 + if (unlikely(err))
29324 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29326 + if (au_ftest_lock(flags, GEN)) {
29327 + sigen = au_sigen(sb);
29328 + err = au_digen_test(d1, sigen);
29329 + AuDebugOn(!err && au_dbrange_test(d1));
29331 + err = au_digen_test(d2, sigen);
29332 + AuDebugOn(!err && au_dbrange_test(d2));
29334 + if (unlikely(err))
29335 + aufs_read_and_write_unlock2(d1, d2);
29342 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29344 + di_write_unlock2(d1, d2);
29345 + si_read_unlock(d1->d_sb);
29347 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29348 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29349 +++ linux/fs/aufs/super.c 2022-01-13 12:42:15.932899468 +0100
29351 +// SPDX-License-Identifier: GPL-2.0
29353 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29355 + * This program, aufs is free software; you can redistribute it and/or modify
29356 + * it under the terms of the GNU General Public License as published by
29357 + * the Free Software Foundation; either version 2 of the License, or
29358 + * (at your option) any later version.
29360 + * This program is distributed in the hope that it will be useful,
29361 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29362 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29363 + * GNU General Public License for more details.
29365 + * You should have received a copy of the GNU General Public License
29366 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29370 + * mount and super_block operations
29373 +#include <linux/iversion.h>
29374 +#include <linux/mm.h>
29375 +#include <linux/seq_file.h>
29376 +#include <linux/statfs.h>
29377 +#include <linux/vmalloc.h>
29381 + * super_operations
29383 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29385 + struct au_icntnr *c;
29387 + c = au_cache_alloc_icntnr();
29389 + au_icntnr_init(c);
29390 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29391 + c->iinfo.ii_hinode = NULL;
29392 + return &c->vfs_inode;
29397 +static void aufs_destroy_inode(struct inode *inode)
29399 + if (!au_is_bad_inode(inode))
29400 + au_iinfo_fin(inode);
29403 +static void aufs_free_inode(struct inode *inode)
29405 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29408 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29410 + struct inode *inode;
29413 + inode = iget_locked(sb, ino);
29414 + if (unlikely(!inode)) {
29415 + inode = ERR_PTR(-ENOMEM);
29418 + if (!(inode->i_state & I_NEW))
29421 + err = au_xigen_new(inode);
29423 + err = au_iinfo_init(inode);
29425 + inode_inc_iversion(inode);
29427 + iget_failed(inode);
29428 + inode = ERR_PTR(err);
29432 + /* never return NULL */
29433 + AuDebugOn(!inode);
29434 + AuTraceErrPtr(inode);
29438 +/* lock free root dinfo */
29439 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29442 + aufs_bindex_t bindex, bbot;
29443 + struct path path;
29444 + struct au_hdentry *hdp;
29445 + struct au_branch *br;
29446 + au_br_perm_str_t perm;
29449 + bbot = au_sbbot(sb);
29451 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29452 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29453 + br = au_sbr(sb, bindex);
29454 + path.mnt = au_br_mnt(br);
29455 + path.dentry = hdp->hd_dentry;
29456 + err = au_seq_path(seq, &path);
29458 + au_optstr_br_perm(&perm, br->br_perm);
29459 + seq_printf(seq, "=%s", perm.a);
29460 + if (bindex != bbot)
29461 + seq_putc(seq, ':');
29464 + if (unlikely(err || seq_has_overflowed(seq)))
29470 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29471 + const char *append)
29476 + while (*pat != ':')
29479 + strcpy(p, append);
29480 + AuDebugOn(strlen(fmt) >= len);
29483 +static void au_show_wbr_create(struct seq_file *m, int v,
29484 + struct au_sbinfo *sbinfo)
29488 + struct au_wbr_mfs *mfs;
29490 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29492 + seq_puts(m, ",create=");
29493 + pat = au_optstr_wbr_create(v);
29494 + mfs = &sbinfo->si_wbr_mfs;
29496 + case AuWbrCreate_TDP:
29497 + case AuWbrCreate_RR:
29498 + case AuWbrCreate_MFS:
29499 + case AuWbrCreate_PMFS:
29500 + seq_puts(m, pat);
29502 + case AuWbrCreate_MFSRR:
29503 + case AuWbrCreate_TDMFS:
29504 + case AuWbrCreate_PMFSRR:
29505 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29506 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29508 + case AuWbrCreate_MFSV:
29509 + case AuWbrCreate_PMFSV:
29510 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29511 + seq_printf(m, fmt,
29512 + jiffies_to_msecs(mfs->mfs_expire)
29515 + case AuWbrCreate_MFSRRV:
29516 + case AuWbrCreate_TDMFSV:
29517 + case AuWbrCreate_PMFSRRV:
29518 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29519 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29520 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29527 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29529 +#ifdef CONFIG_SYSFS
29533 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29534 + aufs_bindex_t bindex, brid;
29535 + struct qstr *name;
29537 + struct dentry *d, *h_root;
29538 + struct au_branch *br;
29540 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29543 + f = au_sbi(sb)->si_xib;
29547 + /* stop printing the default xino path on the first writable branch */
29549 + bindex = au_xi_root(sb, f->f_path.dentry);
29550 + if (bindex >= 0) {
29551 + br = au_sbr_sb(sb, bindex);
29552 + h_root = au_br_dentry(br);
29555 + d = f->f_path.dentry;
29556 + name = &d->d_name;
29557 + /* safe ->d_parent because the file is unlinked */
29558 + if (d->d_parent == h_root
29559 + && name->len == len
29560 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29563 + seq_puts(seq, ",xino=");
29564 + err = au_xino_path(seq, f);
29571 +/* seq_file will re-call me in case of too long string */
29572 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29575 + unsigned int mnt_flags, v;
29576 + struct super_block *sb;
29577 + struct au_sbinfo *sbinfo;
29579 +#define AuBool(name, str) do { \
29580 + v = au_opt_test(mnt_flags, name); \
29581 + if (v != au_opt_test(AuOpt_Def, name)) \
29582 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29585 +#define AuStr(name, str) do { \
29586 + v = mnt_flags & AuOptMask_##name; \
29587 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29588 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29591 +#define AuUInt(name, str, val) do { \
29592 + if (val != AUFS_##name##_DEF) \
29593 + seq_printf(m, "," #str "=%u", val); \
29596 + sb = dentry->d_sb;
29597 + if (sb->s_flags & SB_POSIXACL)
29598 + seq_puts(m, ",acl");
29599 +#if 0 /* reserved for future use */
29600 + if (sb->s_flags & SB_I_VERSION)
29601 + seq_puts(m, ",i_version");
29604 + /* lock free root dinfo */
29605 + si_noflush_read_lock(sb);
29606 + sbinfo = au_sbi(sb);
29607 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29609 + mnt_flags = au_mntflags(sb);
29610 + if (au_opt_test(mnt_flags, XINO)) {
29611 + err = au_show_xino(m, sb);
29612 + if (unlikely(err))
29615 + seq_puts(m, ",noxino");
29617 + AuBool(TRUNC_XINO, trunc_xino);
29618 + AuStr(UDBA, udba);
29619 + AuBool(SHWH, shwh);
29620 + AuBool(PLINK, plink);
29621 + AuBool(DIO, dio);
29622 + AuBool(DIRPERM1, dirperm1);
29624 + v = sbinfo->si_wbr_create;
29625 + if (v != AuWbrCreate_Def)
29626 + au_show_wbr_create(m, v, sbinfo);
29628 + v = sbinfo->si_wbr_copyup;
29629 + if (v != AuWbrCopyup_Def)
29630 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29632 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29633 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29634 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29636 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29638 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29639 + AuUInt(RDCACHE, rdcache, v);
29641 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29642 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29644 + au_fhsm_show(m, sbinfo);
29646 + AuBool(DIRREN, dirren);
29647 + AuBool(SUM, sum);
29648 + /* AuBool(SUM_W, wsum); */
29649 + AuBool(WARN_PERM, warn_perm);
29650 + AuBool(VERBOSE, verbose);
29653 + /* be sure to print "br:" last */
29654 + if (!sysaufs_brs) {
29655 + seq_puts(m, ",br:");
29656 + au_show_brs(m, sb);
29658 + si_read_unlock(sb);
29666 +/* ---------------------------------------------------------------------- */
29668 +/* sum mode which returns the summation for statfs(2) */
29670 +static u64 au_add_till_max(u64 a, u64 b)
29678 + return ULLONG_MAX;
29681 +static u64 au_mul_till_max(u64 a, long mul)
29689 + return ULLONG_MAX;
29692 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29695 + long bsize, factor;
29696 + u64 blocks, bfree, bavail, files, ffree;
29697 + aufs_bindex_t bbot, bindex, i;
29698 + unsigned char shared;
29699 + struct path h_path;
29700 + struct super_block *h_sb;
29703 + bsize = LONG_MAX;
29709 + bbot = au_sbbot(sb);
29710 + for (bindex = 0; bindex <= bbot; bindex++) {
29711 + h_path.mnt = au_sbr_mnt(sb, bindex);
29712 + h_sb = h_path.mnt->mnt_sb;
29714 + for (i = 0; !shared && i < bindex; i++)
29715 + shared = (au_sbr_sb(sb, i) == h_sb);
29719 + /* sb->s_root for NFS is unreliable */
29720 + h_path.dentry = h_path.mnt->mnt_root;
29721 + err = vfs_statfs(&h_path, buf);
29722 + if (unlikely(err))
29725 + if (bsize > buf->f_bsize) {
29727 + * we will reduce bsize, so we have to expand blocks
29728 + * etc. to match them again
29730 + factor = (bsize / buf->f_bsize);
29731 + blocks = au_mul_till_max(blocks, factor);
29732 + bfree = au_mul_till_max(bfree, factor);
29733 + bavail = au_mul_till_max(bavail, factor);
29734 + bsize = buf->f_bsize;
29737 + factor = (buf->f_bsize / bsize);
29738 + blocks = au_add_till_max(blocks,
29739 + au_mul_till_max(buf->f_blocks, factor));
29740 + bfree = au_add_till_max(bfree,
29741 + au_mul_till_max(buf->f_bfree, factor));
29742 + bavail = au_add_till_max(bavail,
29743 + au_mul_till_max(buf->f_bavail, factor));
29744 + files = au_add_till_max(files, buf->f_files);
29745 + ffree = au_add_till_max(ffree, buf->f_ffree);
29748 + buf->f_bsize = bsize;
29749 + buf->f_blocks = blocks;
29750 + buf->f_bfree = bfree;
29751 + buf->f_bavail = bavail;
29752 + buf->f_files = files;
29753 + buf->f_ffree = ffree;
29754 + buf->f_frsize = 0;
29760 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29763 + struct path h_path;
29764 + struct super_block *sb;
29766 + /* lock free root dinfo */
29767 + sb = dentry->d_sb;
29768 + si_noflush_read_lock(sb);
29769 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29770 + /* sb->s_root for NFS is unreliable */
29771 + h_path.mnt = au_sbr_mnt(sb, 0);
29772 + h_path.dentry = h_path.mnt->mnt_root;
29773 + err = vfs_statfs(&h_path, buf);
29775 + err = au_statfs_sum(sb, buf);
29776 + si_read_unlock(sb);
29779 + buf->f_type = AUFS_SUPER_MAGIC;
29780 + buf->f_namelen = AUFS_MAX_NAMELEN;
29781 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29783 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29788 +/* ---------------------------------------------------------------------- */
29790 +static int aufs_sync_fs(struct super_block *sb, int wait)
29793 + aufs_bindex_t bbot, bindex;
29794 + struct au_branch *br;
29795 + struct super_block *h_sb;
29798 + si_noflush_read_lock(sb);
29799 + bbot = au_sbbot(sb);
29800 + for (bindex = 0; bindex <= bbot; bindex++) {
29801 + br = au_sbr(sb, bindex);
29802 + if (!au_br_writable(br->br_perm))
29805 + h_sb = au_sbr_sb(sb, bindex);
29806 + e = vfsub_sync_filesystem(h_sb);
29807 + if (unlikely(e && !err))
29809 + /* go on even if an error happens */
29811 + si_read_unlock(sb);
29816 +/* ---------------------------------------------------------------------- */
29818 +/* final actions when unmounting a file system */
29819 +static void aufs_put_super(struct super_block *sb)
29821 + struct au_sbinfo *sbinfo;
29823 + sbinfo = au_sbi(sb);
29825 + kobject_put(&sbinfo->si_kobj);
29828 +/* ---------------------------------------------------------------------- */
29830 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29831 + struct super_block *sb, void *arg)
29834 + unsigned long long n, sz;
29841 + if (*hint > ULLONG_MAX / sizeof(array)) {
29842 + array = ERR_PTR(-EMFILE);
29843 + pr_err("hint %llu\n", *hint);
29847 + sz = sizeof(array) * *hint;
29848 + array = kzalloc(sz, GFP_NOFS);
29849 + if (unlikely(!array))
29850 + array = vzalloc(sz);
29851 + if (unlikely(!array)) {
29852 + array = ERR_PTR(-ENOMEM);
29856 + n = cb(sb, array, *hint, arg);
29857 + AuDebugOn(n > *hint);
29864 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29865 + unsigned long long max __maybe_unused,
29868 + unsigned long long n;
29869 + struct inode **p, *inode;
29870 + struct list_head *head;
29875 + spin_lock(&sb->s_inode_list_lock);
29876 + list_for_each_entry(inode, head, i_sb_list) {
29877 + if (!au_is_bad_inode(inode)
29878 + && au_ii(inode)->ii_btop >= 0) {
29879 + spin_lock(&inode->i_lock);
29880 + if (atomic_read(&inode->i_count)) {
29884 + AuDebugOn(n > max);
29886 + spin_unlock(&inode->i_lock);
29889 + spin_unlock(&sb->s_inode_list_lock);
29894 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29896 + struct au_sbinfo *sbi;
29898 + sbi = au_sbi(sb);
29899 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29900 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29903 +void au_iarray_free(struct inode **a, unsigned long long max)
29905 + unsigned long long ull;
29907 + for (ull = 0; ull < max; ull++)
29912 +/* ---------------------------------------------------------------------- */
29915 + * refresh dentry and inode at remount time.
29917 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29918 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29919 + struct dentry *parent)
29923 + di_write_lock_child(dentry);
29924 + di_read_lock_parent(parent, AuLock_IR);
29925 + err = au_refresh_dentry(dentry, parent);
29926 + if (!err && dir_flags)
29927 + au_hn_reset(d_inode(dentry), dir_flags);
29928 + di_read_unlock(parent, AuLock_IR);
29929 + di_write_unlock(dentry);
29934 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29935 + struct au_sbinfo *sbinfo,
29936 + const unsigned int dir_flags, unsigned int do_idop)
29939 + struct dentry *parent;
29942 + parent = dget_parent(dentry);
29943 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29944 + if (d_really_is_positive(dentry)) {
29945 + if (!d_is_dir(dentry))
29946 + err = au_do_refresh(dentry, /*dir_flags*/0,
29949 + err = au_do_refresh(dentry, dir_flags, parent);
29950 + if (unlikely(err))
29951 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29954 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29955 + AuDbgDentry(dentry);
29961 + au_refresh_dop(dentry, /*force_reval*/0);
29963 + au_refresh_dop(dentry, /*force_reval*/1);
29969 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29971 + int err, i, j, ndentry, e;
29972 + unsigned int sigen;
29973 + struct au_dcsub_pages dpages;
29974 + struct au_dpage *dpage;
29975 + struct dentry **dentries, *d;
29976 + struct au_sbinfo *sbinfo;
29977 + struct dentry *root = sb->s_root;
29978 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29981 + au_refresh_dop(root, /*force_reval*/0);
29983 + err = au_dpages_init(&dpages, GFP_NOFS);
29984 + if (unlikely(err))
29986 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29987 + if (unlikely(err))
29990 + sigen = au_sigen(sb);
29991 + sbinfo = au_sbi(sb);
29992 + for (i = 0; i < dpages.ndpage; i++) {
29993 + dpage = dpages.dpages + i;
29994 + dentries = dpage->dentries;
29995 + ndentry = dpage->ndentry;
29996 + for (j = 0; j < ndentry; j++) {
29998 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30000 + if (unlikely(e && !err))
30002 + /* go on even err */
30007 + au_dpages_free(&dpages);
30012 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30015 + unsigned int sigen;
30016 + unsigned long long max, ull;
30017 + struct inode *inode, **array;
30019 + array = au_iarray_alloc(sb, &max);
30020 + err = PTR_ERR(array);
30021 + if (IS_ERR(array))
30025 + sigen = au_sigen(sb);
30026 + for (ull = 0; ull < max; ull++) {
30027 + inode = array[ull];
30028 + if (unlikely(!inode))
30032 + ii_write_lock_child(inode);
30033 + if (au_iigen(inode, NULL) != sigen) {
30034 + e = au_refresh_hinode_self(inode);
30035 + if (unlikely(e)) {
30036 + au_refresh_iop(inode, /*force_getattr*/1);
30037 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30040 + /* go on even if err */
30043 + if (!e && do_idop)
30044 + au_refresh_iop(inode, /*force_getattr*/0);
30045 + ii_write_unlock(inode);
30048 + au_iarray_free(array, max);
30054 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30057 + unsigned int udba;
30058 + aufs_bindex_t bindex, bbot;
30059 + struct dentry *root;
30060 + struct inode *inode;
30061 + struct au_branch *br;
30062 + struct au_sbinfo *sbi;
30064 + au_sigen_inc(sb);
30065 + sbi = au_sbi(sb);
30066 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30068 + root = sb->s_root;
30069 + DiMustNoWaiters(root);
30070 + inode = d_inode(root);
30071 + IiMustNoWaiters(inode);
30073 + udba = au_opt_udba(sb);
30074 + bbot = au_sbbot(sb);
30075 + for (bindex = 0; bindex <= bbot; bindex++) {
30076 + br = au_sbr(sb, bindex);
30077 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30078 + if (unlikely(err))
30079 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30081 + /* go on even if err */
30083 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30086 + if (au_ftest_si(sbi, NO_DREVAL)) {
30087 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30088 + sb->s_d_op = &aufs_dop_noreval;
30089 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30090 + sbi->si_iop_array = aufs_iop_nogetattr;
30092 + AuDebugOn(sb->s_d_op == &aufs_dop);
30093 + sb->s_d_op = &aufs_dop;
30094 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30095 + sbi->si_iop_array = aufs_iop;
30097 + pr_info("reset to %ps and %ps\n",
30098 + sb->s_d_op, sbi->si_iop_array);
30101 + di_write_unlock(root);
30102 + err = au_refresh_d(sb, do_idop);
30103 + e = au_refresh_i(sb, do_idop);
30104 + if (unlikely(e && !err))
30106 + /* aufs_write_lock() calls ..._child() */
30107 + di_write_lock_child(root);
30109 + au_cpup_attr_all(inode, /*force*/1);
30111 + if (unlikely(err))
30112 + AuIOErr("refresh failed, ignored, %d\n", err);
30115 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30116 +static int cvt_err(int err)
30130 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30133 + unsigned int mntflags;
30134 + struct au_opts opts = {
30137 + struct dentry *root;
30138 + struct inode *inode;
30139 + struct au_sbinfo *sbinfo;
30142 + root = sb->s_root;
30143 + if (!data || !*data) {
30144 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30146 + di_write_lock_child(root);
30147 + err = au_opts_verify(sb, *flags, /*pending*/0);
30148 + aufs_write_unlock(root);
30154 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30155 + if (unlikely(!opts.opt))
30157 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30158 + opts.flags = AuOpts_REMOUNT;
30159 + opts.sb_flags = *flags;
30161 + /* parse it before aufs lock */
30162 + err = au_opts_parse(sb, data, &opts);
30163 + if (unlikely(err))
30166 + sbinfo = au_sbi(sb);
30167 + inode = d_inode(root);
30168 + inode_lock(inode);
30169 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30170 + if (unlikely(err))
30172 + di_write_lock_child(root);
30174 + /* au_opts_remount() may return an error */
30175 + err = au_opts_remount(sb, &opts);
30176 + au_opts_free(&opts);
30178 + if (au_ftest_opts(opts.flags, REFRESH))
30179 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30181 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30182 + mntflags = au_mntflags(sb);
30183 + do_dx = !!au_opt_test(mntflags, DIO);
30184 + au_dy_arefresh(do_dx);
30187 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30188 + aufs_write_unlock(root);
30191 + inode_unlock(inode);
30193 + free_page((unsigned long)opts.opt);
30195 + err = cvt_err(err);
30200 +static const struct super_operations aufs_sop = {
30201 + .alloc_inode = aufs_alloc_inode,
30202 + .destroy_inode = aufs_destroy_inode,
30203 + .free_inode = aufs_free_inode,
30204 + /* always deleting, no clearing */
30205 + .drop_inode = generic_delete_inode,
30206 + .show_options = aufs_show_options,
30207 + .statfs = aufs_statfs,
30208 + .put_super = aufs_put_super,
30209 + .sync_fs = aufs_sync_fs,
30210 + .remount_fs = aufs_remount_fs
30213 +/* ---------------------------------------------------------------------- */
30215 +static int alloc_root(struct super_block *sb)
30218 + struct inode *inode;
30219 + struct dentry *root;
30222 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30223 + err = PTR_ERR(inode);
30224 + if (IS_ERR(inode))
30227 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30228 + inode->i_fop = &aufs_dir_fop;
30229 + inode->i_mode = S_IFDIR;
30230 + set_nlink(inode, 2);
30231 + unlock_new_inode(inode);
30233 + root = d_make_root(inode);
30234 + if (unlikely(!root))
30236 + err = PTR_ERR(root);
30237 + if (IS_ERR(root))
30240 + err = au_di_init(root);
30242 + sb->s_root = root;
30243 + return 0; /* success */
30251 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30252 + int silent __maybe_unused)
30255 + struct au_opts opts = {
30258 + struct au_sbinfo *sbinfo;
30259 + struct dentry *root;
30260 + struct inode *inode;
30261 + char *arg = raw_data;
30263 + if (unlikely(!arg || !*arg)) {
30265 + pr_err("no arg\n");
30270 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30271 + if (unlikely(!opts.opt))
30273 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30274 + opts.sb_flags = sb->s_flags;
30276 + err = au_si_alloc(sb);
30277 + if (unlikely(err))
30279 + sbinfo = au_sbi(sb);
30281 + /* all timestamps always follow the ones on the branch */
30282 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30283 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30284 + sb->s_op = &aufs_sop;
30285 + sb->s_d_op = &aufs_dop;
30286 + sb->s_magic = AUFS_SUPER_MAGIC;
30287 + sb->s_maxbytes = 0;
30288 + sb->s_stack_depth = 1;
30289 + au_export_init(sb);
30290 + au_xattr_init(sb);
30292 + err = alloc_root(sb);
30293 + if (unlikely(err)) {
30294 + si_write_unlock(sb);
30297 + root = sb->s_root;
30298 + inode = d_inode(root);
30301 + * actually we can parse options regardless aufs lock here.
30302 + * but at remount time, parsing must be done before aufs lock.
30303 + * so we follow the same rule.
30305 + ii_write_lock_parent(inode);
30306 + aufs_write_unlock(root);
30307 + err = au_opts_parse(sb, arg, &opts);
30308 + if (unlikely(err))
30311 + /* lock vfs_inode first, then aufs. */
30312 + inode_lock(inode);
30313 + aufs_write_lock(root);
30314 + err = au_opts_mount(sb, &opts);
30315 + au_opts_free(&opts);
30316 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30317 + sb->s_d_op = &aufs_dop_noreval;
30318 + pr_info("%ps\n", sb->s_d_op);
30319 + au_refresh_dop(root, /*force_reval*/0);
30320 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30321 + au_refresh_iop(inode, /*force_getattr*/0);
30323 + aufs_write_unlock(root);
30324 + inode_unlock(inode);
30326 + goto out_opts; /* success */
30330 + sb->s_root = NULL;
30332 + kobject_put(&sbinfo->si_kobj);
30333 + sb->s_fs_info = NULL;
30335 + free_page((unsigned long)opts.opt);
30338 + err = cvt_err(err);
30343 +/* ---------------------------------------------------------------------- */
30345 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30346 + const char *dev_name __maybe_unused,
30349 + struct dentry *root;
30351 + /* all timestamps always follow the ones on the branch */
30352 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30353 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30354 + if (IS_ERR(root))
30357 + au_sbilist_add(root->d_sb);
30363 +static void aufs_kill_sb(struct super_block *sb)
30365 + struct au_sbinfo *sbinfo;
30367 + sbinfo = au_sbi(sb);
30369 + au_sbilist_del(sb);
30370 + aufs_write_lock(sb->s_root);
30372 + if (sbinfo->si_wbr_create_ops->fin)
30373 + sbinfo->si_wbr_create_ops->fin(sb);
30374 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30375 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30376 + au_remount_refresh(sb, /*do_idop*/0);
30378 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30379 + au_plink_put(sb, /*verbose*/1);
30381 + au_dr_opt_flush(sb);
30382 + sbinfo->si_sb = NULL;
30383 + aufs_write_unlock(sb->s_root);
30384 + au_nwt_flush(&sbinfo->si_nowait);
30386 + kill_anon_super(sb);
30389 +struct file_system_type aufs_fs_type = {
30390 + .name = AUFS_FSTYPE,
30391 + /* a race between rename and others */
30392 + .fs_flags = FS_RENAME_DOES_D_MOVE
30394 + /*| FS_ALLOW_IDMAP*/
30396 + .mount = aufs_mount,
30397 + .kill_sb = aufs_kill_sb,
30398 + /* no need to __module_get() and module_put(). */
30399 + .owner = THIS_MODULE,
30401 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30402 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30403 +++ linux/fs/aufs/super.h 2021-12-03 15:38:59.939980643 +0100
30405 +/* SPDX-License-Identifier: GPL-2.0 */
30407 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30409 + * This program, aufs is free software; you can redistribute it and/or modify
30410 + * it under the terms of the GNU General Public License as published by
30411 + * the Free Software Foundation; either version 2 of the License, or
30412 + * (at your option) any later version.
30414 + * This program is distributed in the hope that it will be useful,
30415 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30416 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30417 + * GNU General Public License for more details.
30419 + * You should have received a copy of the GNU General Public License
30420 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30424 + * super_block operations
30427 +#ifndef __AUFS_SUPER_H__
30428 +#define __AUFS_SUPER_H__
30432 +#include <linux/fs.h>
30433 +#include <linux/kobject.h>
30436 +#include "rwsem.h"
30439 +/* policies to select one among multiple writable branches */
30440 +struct au_wbr_copyup_operations {
30441 + int (*copyup)(struct dentry *dentry);
30444 +#define AuWbr_DIR 1 /* target is a dir */
30445 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30447 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30448 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30449 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30451 +struct au_wbr_create_operations {
30452 + int (*create)(struct dentry *dentry, unsigned int flags);
30453 + int (*init)(struct super_block *sb);
30454 + int (*fin)(struct super_block *sb);
30457 +struct au_wbr_mfs {
30458 + struct mutex mfs_lock; /* protect this structure */
30459 + unsigned long mfs_jiffy;
30460 + unsigned long mfs_expire;
30461 + aufs_bindex_t mfs_bindex;
30463 + unsigned long long mfsrr_bytes;
30464 + unsigned long long mfsrr_watermark;
30467 +#define AuPlink_NHASH 100
30468 +static inline int au_plink_hash(ino_t ino)
30470 + return ino % AuPlink_NHASH;
30473 +/* File-based Hierarchical Storage Management */
30475 +#ifdef CONFIG_AUFS_FHSM
30476 + /* allow only one process who can receive the notification */
30477 + spinlock_t fhsm_spin;
30479 + wait_queue_head_t fhsm_wqh;
30480 + atomic_t fhsm_readable;
30482 + /* these are protected by si_rwsem */
30483 + unsigned long fhsm_expire;
30484 + aufs_bindex_t fhsm_bottom;
30489 +struct au_sbinfo {
30490 + /* nowait tasks in the system-wide workqueue */
30491 + struct au_nowait_tasks si_nowait;
30494 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30495 + * rwsem for au_sbinfo is necessary.
30497 + struct au_rwsem si_rwsem;
30500 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30503 + au_lcnt_t si_ninodes, si_nfiles;
30505 + /* branch management */
30506 + unsigned int si_generation;
30508 + /* see AuSi_ flags */
30509 + unsigned char au_si_status;
30511 + aufs_bindex_t si_bbot;
30513 + /* dirty trick to keep br_id plus */
30514 + unsigned int si_last_br_id :
30515 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30516 + struct au_branch **si_branch;
30518 + /* policy to select a writable branch */
30519 + unsigned char si_wbr_copyup;
30520 + unsigned char si_wbr_create;
30521 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30522 + struct au_wbr_create_operations *si_wbr_create_ops;
30524 + /* round robin */
30525 + atomic_t si_wbr_rr_next;
30527 + /* most free space */
30528 + struct au_wbr_mfs si_wbr_mfs;
30530 + /* File-based Hierarchical Storage Management */
30531 + struct au_fhsm si_fhsm;
30533 + /* mount flags */
30534 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30535 + unsigned int si_mntflags;
30537 + /* external inode number (bitmap and translation table) */
30538 + loff_t si_ximaxent; /* max entries in a xino */
30540 + struct file *si_xib;
30541 + struct mutex si_xib_mtx; /* protect xib members */
30542 + unsigned long *si_xib_buf;
30543 + unsigned long si_xib_last_pindex;
30544 + int si_xib_next_bit;
30546 + unsigned long si_xino_jiffy;
30547 + unsigned long si_xino_expire;
30548 + /* reserved for future use */
30549 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30551 +#ifdef CONFIG_AUFS_EXPORT
30552 + /* i_generation */
30553 + /* todo: make xigen file an array to support many inode numbers */
30554 + struct file *si_xigen;
30555 + atomic_t si_xigen_next;
30558 + /* dirty trick to support atomic_open */
30559 + struct hlist_bl_head si_aopen;
30561 + /* vdir parameters */
30562 + unsigned long si_rdcache; /* max cache time in jiffies */
30563 + unsigned int si_rdblk; /* deblk size */
30564 + unsigned int si_rdhash; /* hash size */
30567 + * If the number of whiteouts are larger than si_dirwh, leave all of
30568 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30569 + * future fsck.aufs or kernel thread will remove them later.
30570 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30572 + unsigned int si_dirwh;
30574 + /* pseudo_link list */
30575 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30576 + wait_queue_head_t si_plink_wq;
30577 + spinlock_t si_plink_maint_lock;
30578 + pid_t si_plink_maint_pid;
30581 + struct hlist_bl_head si_files;
30583 + /* with/without getattr, brother of sb->s_d_op */
30584 + const struct inode_operations *si_iop_array;
30587 + * sysfs and lifetime management.
30588 + * this is not a small structure and it may be a waste of memory in case
30589 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30590 + * but using sysfs is majority.
30592 + struct kobject si_kobj;
30593 +#ifdef CONFIG_DEBUG_FS
30594 + struct dentry *si_dbgaufs;
30595 + struct dentry *si_dbgaufs_plink;
30596 + struct dentry *si_dbgaufs_xib;
30597 +#ifdef CONFIG_AUFS_EXPORT
30598 + struct dentry *si_dbgaufs_xigen;
30602 +#ifdef CONFIG_AUFS_SBILIST
30603 + struct hlist_bl_node si_list;
30606 + /* dirty, necessary for unmounting, sysfs and sysrq */
30607 + struct super_block *si_sb;
30610 +/* sbinfo status flags */
30612 + * set true when refresh_dirs() failed at remount time.
30613 + * then try refreshing dirs at access time again.
30614 + * if it is false, refreshing dirs at access time is unnecessary
30616 +#define AuSi_FAILED_REFRESH_DIR 1
30617 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30618 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30620 +#ifndef CONFIG_AUFS_FHSM
30622 +#define AuSi_FHSM 0
30625 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30626 + unsigned int flag)
30628 + AuRwMustAnyLock(&sbi->si_rwsem);
30629 + return sbi->au_si_status & flag;
30631 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30632 +#define au_fset_si(sbinfo, name) do { \
30633 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30634 + (sbinfo)->au_si_status |= AuSi_##name; \
30636 +#define au_fclr_si(sbinfo, name) do { \
30637 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30638 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30641 +/* ---------------------------------------------------------------------- */
30643 +/* policy to select one among writable branches */
30644 +#define AuWbrCopyup(sbinfo, ...) \
30645 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30646 +#define AuWbrCreate(sbinfo, ...) \
30647 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30649 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30650 +#define AuLock_DW 1 /* write-lock dentry */
30651 +#define AuLock_IR (1 << 1) /* read-lock inode */
30652 +#define AuLock_IW (1 << 2) /* write-lock inode */
30653 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30654 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30655 + /* except RENAME_EXCHANGE */
30656 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30657 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30658 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30659 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30660 +#define au_fset_lock(flags, name) \
30661 + do { (flags) |= AuLock_##name; } while (0)
30662 +#define au_fclr_lock(flags, name) \
30663 + do { (flags) &= ~AuLock_##name; } while (0)
30665 +/* ---------------------------------------------------------------------- */
30668 +extern struct file_system_type aufs_fs_type;
30669 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30670 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30671 + unsigned long long max, void *arg);
30672 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30673 + struct super_block *sb, void *arg);
30674 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30675 +void au_iarray_free(struct inode **a, unsigned long long max);
30678 +void au_si_free(struct kobject *kobj);
30679 +int au_si_alloc(struct super_block *sb);
30680 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30682 +unsigned int au_sigen_inc(struct super_block *sb);
30683 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30685 +int si_read_lock(struct super_block *sb, int flags);
30686 +int si_write_lock(struct super_block *sb, int flags);
30687 +int aufs_read_lock(struct dentry *dentry, int flags);
30688 +void aufs_read_unlock(struct dentry *dentry, int flags);
30689 +void aufs_write_lock(struct dentry *dentry);
30690 +void aufs_write_unlock(struct dentry *dentry);
30691 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30692 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30694 +/* wbr_policy.c */
30695 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30696 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30697 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30698 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30699 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30702 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30704 +#ifdef CONFIG_AUFS_FHSM
30707 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30711 + spin_lock(&fhsm->fhsm_spin);
30712 + pid = fhsm->fhsm_pid;
30713 + spin_unlock(&fhsm->fhsm_spin);
30718 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30719 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30720 +int au_fhsm_fd(struct super_block *sb, int oflags);
30721 +int au_fhsm_br_alloc(struct au_branch *br);
30722 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30723 +void au_fhsm_fin(struct super_block *sb);
30724 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30725 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30726 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30728 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30730 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30731 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30732 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30733 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30734 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30735 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30736 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30737 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30738 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30741 +/* ---------------------------------------------------------------------- */
30743 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30745 + return sb->s_fs_info;
30748 +/* ---------------------------------------------------------------------- */
30750 +#ifdef CONFIG_AUFS_EXPORT
30751 +int au_test_nfsd(void);
30752 +void au_export_init(struct super_block *sb);
30753 +void au_xigen_inc(struct inode *inode);
30754 +int au_xigen_new(struct inode *inode);
30755 +int au_xigen_set(struct super_block *sb, struct path *path);
30756 +void au_xigen_clr(struct super_block *sb);
30758 +static inline int au_busy_or_stale(void)
30760 + if (!au_test_nfsd())
30765 +AuStubInt0(au_test_nfsd, void)
30766 +AuStubVoid(au_export_init, struct super_block *sb)
30767 +AuStubVoid(au_xigen_inc, struct inode *inode)
30768 +AuStubInt0(au_xigen_new, struct inode *inode)
30769 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30770 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30771 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30772 +#endif /* CONFIG_AUFS_EXPORT */
30774 +/* ---------------------------------------------------------------------- */
30776 +#ifdef CONFIG_AUFS_SBILIST
30778 +extern struct hlist_bl_head au_sbilist;
30780 +static inline void au_sbilist_init(void)
30782 + INIT_HLIST_BL_HEAD(&au_sbilist);
30785 +static inline void au_sbilist_add(struct super_block *sb)
30787 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30790 +static inline void au_sbilist_del(struct super_block *sb)
30792 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30795 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30796 +static inline void au_sbilist_lock(void)
30798 + hlist_bl_lock(&au_sbilist);
30801 +static inline void au_sbilist_unlock(void)
30803 + hlist_bl_unlock(&au_sbilist);
30805 +#define AuGFP_SBILIST GFP_ATOMIC
30807 +AuStubVoid(au_sbilist_lock, void)
30808 +AuStubVoid(au_sbilist_unlock, void)
30809 +#define AuGFP_SBILIST GFP_NOFS
30810 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30812 +AuStubVoid(au_sbilist_init, void)
30813 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30814 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30815 +AuStubVoid(au_sbilist_lock, void)
30816 +AuStubVoid(au_sbilist_unlock, void)
30817 +#define AuGFP_SBILIST GFP_NOFS
30820 +/* ---------------------------------------------------------------------- */
30822 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30825 + * This function is a dynamic '__init' function actually,
30826 + * so the tiny check for si_rwsem is unnecessary.
30828 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30829 +#ifdef CONFIG_DEBUG_FS
30830 + sbinfo->si_dbgaufs = NULL;
30831 + sbinfo->si_dbgaufs_plink = NULL;
30832 + sbinfo->si_dbgaufs_xib = NULL;
30833 +#ifdef CONFIG_AUFS_EXPORT
30834 + sbinfo->si_dbgaufs_xigen = NULL;
30839 +/* ---------------------------------------------------------------------- */
30841 +/* current->atomic_flags */
30842 +/* this value should never corrupt the ones defined in linux/sched.h */
30843 +#define PFA_AUFS 0x10
30845 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30846 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30847 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30849 +static inline int si_pid_test(struct super_block *sb)
30851 + return !!task_test_aufs(current);
30854 +static inline void si_pid_clr(struct super_block *sb)
30856 + AuDebugOn(!task_test_aufs(current));
30857 + task_clear_aufs(current);
30860 +static inline void si_pid_set(struct super_block *sb)
30862 + AuDebugOn(task_test_aufs(current));
30863 + task_set_aufs(current);
30866 +/* ---------------------------------------------------------------------- */
30868 +/* lock superblock. mainly for entry point functions */
30869 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30870 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30871 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30872 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30874 +#define __si_read_trylock_nested(sb) \
30875 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30876 +#define __si_write_trylock_nested(sb) \
30877 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30880 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30881 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30882 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30884 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30885 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30886 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30888 +static inline void si_noflush_read_lock(struct super_block *sb)
30890 + __si_read_lock(sb);
30894 +static inline int si_noflush_read_trylock(struct super_block *sb)
30898 + locked = __si_read_trylock(sb);
30904 +static inline void si_noflush_write_lock(struct super_block *sb)
30906 + __si_write_lock(sb);
30910 +static inline int si_noflush_write_trylock(struct super_block *sb)
30914 + locked = __si_write_trylock(sb);
30920 +#if 0 /* reserved */
30921 +static inline int si_read_trylock(struct super_block *sb, int flags)
30923 + if (au_ftest_lock(flags, FLUSH))
30924 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30925 + return si_noflush_read_trylock(sb);
30929 +static inline void si_read_unlock(struct super_block *sb)
30932 + __si_read_unlock(sb);
30935 +#if 0 /* reserved */
30936 +static inline int si_write_trylock(struct super_block *sb, int flags)
30938 + if (au_ftest_lock(flags, FLUSH))
30939 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30940 + return si_noflush_write_trylock(sb);
30944 +static inline void si_write_unlock(struct super_block *sb)
30947 + __si_write_unlock(sb);
30950 +#if 0 /* reserved */
30951 +static inline void si_downgrade_lock(struct super_block *sb)
30953 + __si_downgrade_lock(sb);
30957 +/* ---------------------------------------------------------------------- */
30959 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30961 + SiMustAnyLock(sb);
30962 + return au_sbi(sb)->si_bbot;
30965 +static inline unsigned int au_mntflags(struct super_block *sb)
30967 + SiMustAnyLock(sb);
30968 + return au_sbi(sb)->si_mntflags;
30971 +static inline unsigned int au_sigen(struct super_block *sb)
30973 + SiMustAnyLock(sb);
30974 + return au_sbi(sb)->si_generation;
30977 +static inline struct au_branch *au_sbr(struct super_block *sb,
30978 + aufs_bindex_t bindex)
30980 + SiMustAnyLock(sb);
30981 + return au_sbi(sb)->si_branch[0 + bindex];
30984 +static inline loff_t au_xi_maxent(struct super_block *sb)
30986 + SiMustAnyLock(sb);
30987 + return au_sbi(sb)->si_ximaxent;
30990 +#endif /* __KERNEL__ */
30991 +#endif /* __AUFS_SUPER_H__ */
30992 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30993 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30994 +++ linux/fs/aufs/sysaufs.c 2021-12-03 15:38:59.939980643 +0100
30996 +// SPDX-License-Identifier: GPL-2.0
30998 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31000 + * This program, aufs is free software; you can redistribute it and/or modify
31001 + * it under the terms of the GNU General Public License as published by
31002 + * the Free Software Foundation; either version 2 of the License, or
31003 + * (at your option) any later version.
31005 + * This program is distributed in the hope that it will be useful,
31006 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31007 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31008 + * GNU General Public License for more details.
31010 + * You should have received a copy of the GNU General Public License
31011 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31015 + * sysfs interface and lifetime management
31016 + * they are necessary regardless sysfs is disabled.
31019 +#include <linux/random.h>
31022 +unsigned long sysaufs_si_mask;
31023 +struct kset *sysaufs_kset;
31025 +#define AuSiAttr(_name) { \
31026 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31027 + .show = sysaufs_si_##_name, \
31030 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31031 +struct attribute *sysaufs_si_attrs[] = {
31032 + &sysaufs_si_attr_xi_path.attr,
31036 +static const struct sysfs_ops au_sbi_ops = {
31037 + .show = sysaufs_si_show
31040 +static struct kobj_type au_sbi_ktype = {
31041 + .release = au_si_free,
31042 + .sysfs_ops = &au_sbi_ops,
31043 + .default_attrs = sysaufs_si_attrs
31046 +/* ---------------------------------------------------------------------- */
31048 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31052 + sbinfo->si_kobj.kset = sysaufs_kset;
31053 + /* cf. sysaufs_name() */
31054 + err = kobject_init_and_add
31055 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31056 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31061 +void sysaufs_fin(void)
31063 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31064 + kset_unregister(sysaufs_kset);
31067 +int __init sysaufs_init(void)
31072 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31073 + } while (!sysaufs_si_mask);
31076 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31077 + if (unlikely(!sysaufs_kset))
31079 + err = PTR_ERR(sysaufs_kset);
31080 + if (IS_ERR(sysaufs_kset))
31082 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31083 + if (unlikely(err))
31084 + kset_unregister(sysaufs_kset);
31089 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31090 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31091 +++ linux/fs/aufs/sysaufs.h 2021-12-03 15:38:59.939980643 +0100
31093 +/* SPDX-License-Identifier: GPL-2.0 */
31095 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31097 + * This program, aufs is free software; you can redistribute it and/or modify
31098 + * it under the terms of the GNU General Public License as published by
31099 + * the Free Software Foundation; either version 2 of the License, or
31100 + * (at your option) any later version.
31102 + * This program is distributed in the hope that it will be useful,
31103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31105 + * GNU General Public License for more details.
31107 + * You should have received a copy of the GNU General Public License
31108 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31112 + * sysfs interface and mount lifetime management
31115 +#ifndef __SYSAUFS_H__
31116 +#define __SYSAUFS_H__
31120 +#include <linux/sysfs.h>
31121 +#include "module.h"
31123 +struct super_block;
31126 +struct sysaufs_si_attr {
31127 + struct attribute attr;
31128 + int (*show)(struct seq_file *seq, struct super_block *sb);
31131 +/* ---------------------------------------------------------------------- */
31134 +extern unsigned long sysaufs_si_mask;
31135 +extern struct kset *sysaufs_kset;
31136 +extern struct attribute *sysaufs_si_attrs[];
31137 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31138 +int __init sysaufs_init(void);
31139 +void sysaufs_fin(void);
31141 +/* ---------------------------------------------------------------------- */
31143 +/* some people doesn't like to show a pointer in kernel */
31144 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31146 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31149 +#define SysaufsSiNamePrefix "si_"
31150 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31151 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31153 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31154 + sysaufs_si_id(sbinfo));
31158 +#ifdef CONFIG_SYSFS
31160 +extern struct attribute_group *sysaufs_attr_group;
31162 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31163 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31165 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31166 +#ifdef CONFIG_COMPAT
31167 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31170 +void sysaufs_br_init(struct au_branch *br);
31171 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31172 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31174 +#define sysaufs_brs_init() do {} while (0)
31177 +#define sysaufs_attr_group NULL
31179 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31180 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31181 + struct attribute *attr, char *buf)
31182 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31183 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31184 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31186 +static inline void sysaufs_brs_init(void)
31191 +#endif /* CONFIG_SYSFS */
31193 +#endif /* __KERNEL__ */
31194 +#endif /* __SYSAUFS_H__ */
31195 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31196 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31197 +++ linux/fs/aufs/sysfs.c 2021-12-03 15:38:59.939980643 +0100
31199 +// SPDX-License-Identifier: GPL-2.0
31201 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31203 + * This program, aufs is free software; you can redistribute it and/or modify
31204 + * it under the terms of the GNU General Public License as published by
31205 + * the Free Software Foundation; either version 2 of the License, or
31206 + * (at your option) any later version.
31208 + * This program is distributed in the hope that it will be useful,
31209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31211 + * GNU General Public License for more details.
31213 + * You should have received a copy of the GNU General Public License
31214 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31218 + * sysfs interface
31221 +#include <linux/compat.h>
31222 +#include <linux/seq_file.h>
31225 +#ifdef CONFIG_AUFS_FS_MODULE
31226 +/* this entry violates the "one line per file" policy of sysfs */
31227 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31231 + static char *conf =
31232 +/* this file is generated at compiling */
31233 +#include "conf.str"
31236 + err = snprintf(buf, PAGE_SIZE, conf);
31237 + if (unlikely(err >= PAGE_SIZE))
31242 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31245 +static struct attribute *au_attr[] = {
31246 +#ifdef CONFIG_AUFS_FS_MODULE
31247 + &au_config_attr.attr,
31249 + NULL, /* need to NULL terminate the list of attributes */
31252 +static struct attribute_group sysaufs_attr_group_body = {
31256 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31258 +/* ---------------------------------------------------------------------- */
31260 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31264 + SiMustAnyLock(sb);
31267 + if (au_opt_test(au_mntflags(sb), XINO)) {
31268 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31269 + seq_putc(seq, '\n');
31275 + * the lifetime of branch is independent from the entry under sysfs.
31276 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31279 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31280 + aufs_bindex_t bindex, int idx)
31283 + struct path path;
31284 + struct dentry *root;
31285 + struct au_branch *br;
31286 + au_br_perm_str_t perm;
31288 + AuDbg("b%d\n", bindex);
31291 + root = sb->s_root;
31292 + di_read_lock_parent(root, !AuLock_IR);
31293 + br = au_sbr(sb, bindex);
31296 + case AuBrSysfs_BR:
31297 + path.mnt = au_br_mnt(br);
31298 + path.dentry = au_h_dptr(root, bindex);
31299 + err = au_seq_path(seq, &path);
31301 + au_optstr_br_perm(&perm, br->br_perm);
31302 + seq_printf(seq, "=%s\n", perm.a);
31305 + case AuBrSysfs_BRID:
31306 + seq_printf(seq, "%d\n", br->br_id);
31309 + di_read_unlock(root, !AuLock_IR);
31310 + if (unlikely(err || seq_has_overflowed(seq)))
31316 +/* ---------------------------------------------------------------------- */
31318 +static struct seq_file *au_seq(char *p, ssize_t len)
31320 + struct seq_file *seq;
31322 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31324 + /* mutex_init(&seq.lock); */
31327 + return seq; /* success */
31330 + seq = ERR_PTR(-ENOMEM);
31334 +#define SysaufsBr_PREFIX "br"
31335 +#define SysaufsBrid_PREFIX "brid"
31337 +/* todo: file size may exceed PAGE_SIZE */
31338 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31344 + aufs_bindex_t bbot;
31345 + struct au_sbinfo *sbinfo;
31346 + struct super_block *sb;
31347 + struct seq_file *seq;
31349 + struct attribute **cattr;
31351 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31352 + sb = sbinfo->si_sb;
31355 + * prevent a race condition between sysfs and aufs.
31356 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31357 + * prohibits maintaining the sysfs entries.
31358 + * hew we acquire read lock after sysfs_get_active_two().
31359 + * on the other hand, the remount process may maintain the sysfs/aufs
31360 + * entries after acquiring write lock.
31361 + * it can cause a deadlock.
31362 + * simply we gave up processing read here.
31365 + if (unlikely(!si_noflush_read_trylock(sb)))
31368 + seq = au_seq(buf, PAGE_SIZE);
31369 + err = PTR_ERR(seq);
31373 + name = (void *)attr->name;
31374 + cattr = sysaufs_si_attrs;
31376 + if (!strcmp(name, (*cattr)->name)) {
31377 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31384 + if (!strncmp(name, SysaufsBrid_PREFIX,
31385 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31386 + idx = AuBrSysfs_BRID;
31387 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31388 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31389 + sizeof(SysaufsBr_PREFIX) - 1)) {
31390 + idx = AuBrSysfs_BR;
31391 + name += sizeof(SysaufsBr_PREFIX) - 1;
31395 + err = kstrtol(name, 10, &l);
31397 + bbot = au_sbbot(sb);
31399 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31406 + err = seq->count;
31407 + /* sysfs limit */
31408 + if (unlikely(err == PAGE_SIZE))
31411 + au_kfree_rcu(seq);
31413 + si_read_unlock(sb);
31418 +/* ---------------------------------------------------------------------- */
31420 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31424 + aufs_bindex_t bindex, bbot;
31427 + struct seq_file *seq;
31428 + struct au_branch *br;
31430 + si_read_lock(sb, AuLock_FLUSH);
31431 + bbot = au_sbbot(sb);
31437 + buf = (void *)__get_free_page(GFP_NOFS);
31438 + if (unlikely(!buf))
31441 + seq = au_seq(buf, PAGE_SIZE);
31442 + err = PTR_ERR(seq);
31446 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31447 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31448 + /* VERIFY_WRITE */
31449 + err = !access_ok(arg, sizeof(*arg));
31450 + if (unlikely(err))
31453 + br = au_sbr(sb, bindex);
31454 + brid = br->br_id;
31455 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31456 + err = __put_user(brid, &arg->id);
31457 + if (unlikely(err))
31460 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31461 + err = __put_user(br->br_perm, &arg->perm);
31462 + if (unlikely(err))
31465 + err = au_seq_path(seq, &br->br_path);
31466 + if (unlikely(err))
31468 + seq_putc(seq, '\0');
31469 + if (!seq_has_overflowed(seq)) {
31470 + err = copy_to_user(arg->path, seq->buf, seq->count);
31472 + if (unlikely(err))
31479 + if (unlikely(err))
31483 + au_kfree_rcu(seq);
31485 + free_page((unsigned long)buf);
31487 + si_read_unlock(sb);
31491 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31493 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31496 +#ifdef CONFIG_COMPAT
31497 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31499 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31503 +/* ---------------------------------------------------------------------- */
31505 +void sysaufs_br_init(struct au_branch *br)
31508 + struct au_brsysfs *br_sysfs;
31509 + struct attribute *attr;
31511 + br_sysfs = br->br_sysfs;
31512 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31513 + attr = &br_sysfs->attr;
31514 + sysfs_attr_init(attr);
31515 + attr->name = br_sysfs->name;
31516 + attr->mode = 0444;
31521 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31523 + struct au_branch *br;
31524 + struct kobject *kobj;
31525 + struct au_brsysfs *br_sysfs;
31527 + aufs_bindex_t bbot;
31529 + if (!sysaufs_brs)
31532 + kobj = &au_sbi(sb)->si_kobj;
31533 + bbot = au_sbbot(sb);
31534 + for (; bindex <= bbot; bindex++) {
31535 + br = au_sbr(sb, bindex);
31536 + br_sysfs = br->br_sysfs;
31537 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31538 + sysfs_remove_file(kobj, &br_sysfs->attr);
31544 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31547 + aufs_bindex_t bbot;
31548 + struct kobject *kobj;
31549 + struct au_branch *br;
31550 + struct au_brsysfs *br_sysfs;
31552 + if (!sysaufs_brs)
31555 + kobj = &au_sbi(sb)->si_kobj;
31556 + bbot = au_sbbot(sb);
31557 + for (; bindex <= bbot; bindex++) {
31558 + br = au_sbr(sb, bindex);
31559 + br_sysfs = br->br_sysfs;
31560 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31561 + SysaufsBr_PREFIX "%d", bindex);
31562 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31563 + SysaufsBrid_PREFIX "%d", bindex);
31564 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31565 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31566 + if (unlikely(err))
31567 + pr_warn("failed %s under sysfs(%d)\n",
31568 + br_sysfs->name, err);
31573 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31574 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31575 +++ linux/fs/aufs/sysrq.c 2021-12-03 15:38:59.939980643 +0100
31577 +// SPDX-License-Identifier: GPL-2.0
31579 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31581 + * This program, aufs is free software; you can redistribute it and/or modify
31582 + * it under the terms of the GNU General Public License as published by
31583 + * the Free Software Foundation; either version 2 of the License, or
31584 + * (at your option) any later version.
31586 + * This program is distributed in the hope that it will be useful,
31587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31589 + * GNU General Public License for more details.
31591 + * You should have received a copy of the GNU General Public License
31592 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31596 + * magic sysrq handler
31599 +/* #include <linux/sysrq.h> */
31600 +#include <linux/writeback.h>
31603 +/* ---------------------------------------------------------------------- */
31605 +static void sysrq_sb(struct super_block *sb)
31608 + struct au_sbinfo *sbinfo;
31609 + struct file *file;
31610 + struct hlist_bl_head *files;
31611 + struct hlist_bl_node *pos;
31612 + struct au_finfo *finfo;
31615 + plevel = au_plevel;
31616 + au_plevel = KERN_WARNING;
31618 + /* since we define pr_fmt, call printk directly */
31619 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31621 + sbinfo = au_sbi(sb);
31622 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31623 + pr("superblock\n");
31626 +#if 0 /* reserved */
31628 + int err, i, j, ndentry;
31629 + struct au_dcsub_pages dpages;
31630 + struct au_dpage *dpage;
31632 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31633 + if (unlikely(err))
31635 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31637 + for (i = 0; i < dpages.ndpage; i++) {
31638 + dpage = dpages.dpages + i;
31639 + ndentry = dpage->ndentry;
31640 + for (j = 0; j < ndentry; j++)
31641 + au_dpri_dentry(dpage->dentries[j]);
31643 + au_dpages_free(&dpages);
31647 + pr("isolated inode\n");
31648 + spin_lock(&sb->s_inode_list_lock);
31649 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31650 + spin_lock(&i->i_lock);
31651 + if (hlist_empty(&i->i_dentry))
31652 + au_dpri_inode(i);
31653 + spin_unlock(&i->i_lock);
31655 + spin_unlock(&sb->s_inode_list_lock);
31658 + files = &au_sbi(sb)->si_files;
31659 + hlist_bl_lock(files);
31660 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31663 + file = finfo->fi_file;
31664 + mode = file_inode(file)->i_mode;
31665 + if (!special_file(mode))
31666 + au_dpri_file(file);
31668 + hlist_bl_unlock(files);
31672 + au_plevel = plevel;
31675 +/* ---------------------------------------------------------------------- */
31677 +/* module parameter */
31678 +static char *aufs_sysrq_key = "a";
31679 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31680 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31682 +static void au_sysrq(int key __maybe_unused)
31684 + struct au_sbinfo *sbinfo;
31685 + struct hlist_bl_node *pos;
31688 + au_sbilist_lock();
31689 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31690 + sysrq_sb(sbinfo->si_sb);
31691 + au_sbilist_unlock();
31695 +static struct sysrq_key_op au_sysrq_op = {
31696 + .handler = au_sysrq,
31697 + .help_msg = "Aufs",
31698 + .action_msg = "Aufs",
31699 + .enable_mask = SYSRQ_ENABLE_DUMP
31702 +/* ---------------------------------------------------------------------- */
31704 +int __init au_sysrq_init(void)
31710 + key = *aufs_sysrq_key;
31711 + if ('a' <= key && key <= 'z')
31712 + err = register_sysrq_key(key, &au_sysrq_op);
31713 + if (unlikely(err))
31714 + pr_err("err %d, sysrq=%c\n", err, key);
31718 +void au_sysrq_fin(void)
31722 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31723 + if (unlikely(err))
31724 + pr_err("err %d (ignored)\n", err);
31726 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31727 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31728 +++ linux/fs/aufs/vdir.c 2021-12-03 15:38:59.939980643 +0100
31730 +// SPDX-License-Identifier: GPL-2.0
31732 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31734 + * This program, aufs is free software; you can redistribute it and/or modify
31735 + * it under the terms of the GNU General Public License as published by
31736 + * the Free Software Foundation; either version 2 of the License, or
31737 + * (at your option) any later version.
31739 + * This program is distributed in the hope that it will be useful,
31740 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31741 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31742 + * GNU General Public License for more details.
31744 + * You should have received a copy of the GNU General Public License
31745 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31749 + * virtual or vertical directory
31752 +#include <linux/iversion.h>
31755 +static unsigned int calc_size(int nlen)
31757 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31760 +static int set_deblk_end(union au_vdir_deblk_p *p,
31761 + union au_vdir_deblk_p *deblk_end)
31763 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31764 + p->de->de_str.len = 0;
31768 + return -1; /* error */
31771 +/* returns true or false */
31772 +static int is_deblk_end(union au_vdir_deblk_p *p,
31773 + union au_vdir_deblk_p *deblk_end)
31775 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31776 + return !p->de->de_str.len;
31780 +static unsigned char *last_deblk(struct au_vdir *vdir)
31782 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31785 +/* ---------------------------------------------------------------------- */
31787 +/* estimate the appropriate size for name hash table */
31788 +unsigned int au_rdhash_est(loff_t sz)
31796 + if (sz < AUFS_RDHASH_DEF)
31797 + n = AUFS_RDHASH_DEF;
31798 + /* pr_info("n %u\n", n); */
31803 + * the allocated memory has to be freed by
31804 + * au_nhash_wh_free() or au_nhash_de_free().
31806 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31808 + struct hlist_head *head;
31812 + sz = sizeof(*nhash->nh_head) * num_hash;
31813 + head = kmalloc(sz, gfp);
31815 + nhash->nh_num = num_hash;
31816 + nhash->nh_head = head;
31817 + for (u = 0; u < num_hash; u++)
31818 + INIT_HLIST_HEAD(head++);
31819 + return 0; /* success */
31825 +static void nhash_count(struct hlist_head *head)
31827 +#if 0 /* debugging */
31829 + struct hlist_node *pos;
31832 + hlist_for_each(pos, head)
31834 + pr_info("%lu\n", n);
31838 +static void au_nhash_wh_do_free(struct hlist_head *head)
31840 + struct au_vdir_wh *pos;
31841 + struct hlist_node *node;
31843 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31844 + au_kfree_rcu(pos);
31847 +static void au_nhash_de_do_free(struct hlist_head *head)
31849 + struct au_vdir_dehstr *pos;
31850 + struct hlist_node *node;
31852 + hlist_for_each_entry_safe(pos, node, head, hash)
31853 + au_cache_free_vdir_dehstr(pos);
31856 +static void au_nhash_do_free(struct au_nhash *nhash,
31857 + void (*free)(struct hlist_head *head))
31860 + struct hlist_head *head;
31862 + n = nhash->nh_num;
31866 + head = nhash->nh_head;
31867 + while (n-- > 0) {
31868 + nhash_count(head);
31871 + au_kfree_try_rcu(nhash->nh_head);
31874 +void au_nhash_wh_free(struct au_nhash *whlist)
31876 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31879 +static void au_nhash_de_free(struct au_nhash *delist)
31881 + au_nhash_do_free(delist, au_nhash_de_do_free);
31884 +/* ---------------------------------------------------------------------- */
31886 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31890 + unsigned int u, n;
31891 + struct hlist_head *head;
31892 + struct au_vdir_wh *pos;
31895 + n = whlist->nh_num;
31896 + head = whlist->nh_head;
31897 + for (u = 0; u < n; u++, head++)
31898 + hlist_for_each_entry(pos, head, wh_hash)
31899 + if (pos->wh_bindex == btgt && ++num > limit)
31904 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31905 + unsigned char *name,
31906 + unsigned int len)
31909 + /* const unsigned int magic_bit = 12; */
31911 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31918 + /* v = hash_long(v, magic_bit); */
31919 + v %= nhash->nh_num;
31920 + return nhash->nh_head + v;
31923 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31926 + return str->len == nlen && !memcmp(str->name, name, nlen);
31929 +/* returns found or not */
31930 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31932 + struct hlist_head *head;
31933 + struct au_vdir_wh *pos;
31934 + struct au_vdir_destr *str;
31936 + head = au_name_hash(whlist, name, nlen);
31937 + hlist_for_each_entry(pos, head, wh_hash) {
31938 + str = &pos->wh_str;
31939 + AuDbg("%.*s\n", str->len, str->name);
31940 + if (au_nhash_test_name(str, name, nlen))
31946 +/* returns found(true) or not */
31947 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31949 + struct hlist_head *head;
31950 + struct au_vdir_dehstr *pos;
31951 + struct au_vdir_destr *str;
31953 + head = au_name_hash(delist, name, nlen);
31954 + hlist_for_each_entry(pos, head, hash) {
31956 + AuDbg("%.*s\n", str->len, str->name);
31957 + if (au_nhash_test_name(str, name, nlen))
31963 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31964 + unsigned char d_type)
31966 +#ifdef CONFIG_AUFS_SHWH
31967 + wh->wh_ino = ino;
31968 + wh->wh_type = d_type;
31972 +/* ---------------------------------------------------------------------- */
31974 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31975 + unsigned int d_type, aufs_bindex_t bindex,
31976 + unsigned char shwh)
31979 + struct au_vdir_destr *str;
31980 + struct au_vdir_wh *wh;
31982 + AuDbg("%.*s\n", nlen, name);
31983 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31986 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31987 + if (unlikely(!wh))
31991 + wh->wh_bindex = bindex;
31993 + au_shwh_init_wh(wh, ino, d_type);
31994 + str = &wh->wh_str;
31996 + memcpy(str->name, name, nlen);
31997 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32004 +static int append_deblk(struct au_vdir *vdir)
32007 + unsigned long ul;
32008 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32009 + union au_vdir_deblk_p p, deblk_end;
32010 + unsigned char **o;
32013 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32014 + GFP_NOFS, /*may_shrink*/0);
32015 + if (unlikely(!o))
32018 + vdir->vd_deblk = o;
32019 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32021 + ul = vdir->vd_nblk++;
32022 + vdir->vd_deblk[ul] = p.deblk;
32023 + vdir->vd_last.ul = ul;
32024 + vdir->vd_last.p.deblk = p.deblk;
32025 + deblk_end.deblk = p.deblk + deblk_sz;
32026 + err = set_deblk_end(&p, &deblk_end);
32033 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32034 + unsigned int d_type, struct au_nhash *delist)
32038 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32039 + union au_vdir_deblk_p p, *room, deblk_end;
32040 + struct au_vdir_dehstr *dehstr;
32042 + p.deblk = last_deblk(vdir);
32043 + deblk_end.deblk = p.deblk + deblk_sz;
32044 + room = &vdir->vd_last.p;
32045 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32046 + || !is_deblk_end(room, &deblk_end));
32048 + sz = calc_size(nlen);
32049 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32050 + err = append_deblk(vdir);
32051 + if (unlikely(err))
32054 + p.deblk = last_deblk(vdir);
32055 + deblk_end.deblk = p.deblk + deblk_sz;
32057 + AuDebugOn(room->deblk != p.deblk);
32061 + dehstr = au_cache_alloc_vdir_dehstr();
32062 + if (unlikely(!dehstr))
32065 + dehstr->str = &room->de->de_str;
32066 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32067 + room->de->de_ino = ino;
32068 + room->de->de_type = d_type;
32069 + room->de->de_str.len = nlen;
32070 + memcpy(room->de->de_str.name, name, nlen);
32073 + room->deblk += sz;
32074 + if (unlikely(set_deblk_end(room, &deblk_end)))
32075 + err = append_deblk(vdir);
32082 +/* ---------------------------------------------------------------------- */
32084 +void au_vdir_free(struct au_vdir *vdir)
32086 + unsigned char **deblk;
32088 + deblk = vdir->vd_deblk;
32089 + while (vdir->vd_nblk--)
32090 + au_kfree_try_rcu(*deblk++);
32091 + au_kfree_try_rcu(vdir->vd_deblk);
32092 + au_cache_free_vdir(vdir);
32095 +static struct au_vdir *alloc_vdir(struct file *file)
32097 + struct au_vdir *vdir;
32098 + struct super_block *sb;
32101 + sb = file->f_path.dentry->d_sb;
32102 + SiMustAnyLock(sb);
32105 + vdir = au_cache_alloc_vdir();
32106 + if (unlikely(!vdir))
32109 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32110 + if (unlikely(!vdir->vd_deblk))
32113 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32114 + if (!vdir->vd_deblk_sz) {
32115 + /* estimate the appropriate size for deblk */
32116 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32117 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32119 + vdir->vd_nblk = 0;
32120 + vdir->vd_version = 0;
32121 + vdir->vd_jiffy = 0;
32122 + err = append_deblk(vdir);
32124 + return vdir; /* success */
32126 + au_kfree_try_rcu(vdir->vd_deblk);
32129 + au_cache_free_vdir(vdir);
32131 + vdir = ERR_PTR(err);
32135 +static int reinit_vdir(struct au_vdir *vdir)
32138 + union au_vdir_deblk_p p, deblk_end;
32140 + while (vdir->vd_nblk > 1) {
32141 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32142 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32145 + p.deblk = vdir->vd_deblk[0];
32146 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32147 + err = set_deblk_end(&p, &deblk_end);
32148 + /* keep vd_dblk_sz */
32149 + vdir->vd_last.ul = 0;
32150 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32151 + vdir->vd_version = 0;
32152 + vdir->vd_jiffy = 0;
32157 +/* ---------------------------------------------------------------------- */
32159 +#define AuFillVdir_CALLED 1
32160 +#define AuFillVdir_WHABLE (1 << 1)
32161 +#define AuFillVdir_SHWH (1 << 2)
32162 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32163 +#define au_fset_fillvdir(flags, name) \
32164 + do { (flags) |= AuFillVdir_##name; } while (0)
32165 +#define au_fclr_fillvdir(flags, name) \
32166 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32168 +#ifndef CONFIG_AUFS_SHWH
32169 +#undef AuFillVdir_SHWH
32170 +#define AuFillVdir_SHWH 0
32173 +struct fillvdir_arg {
32174 + struct dir_context ctx;
32175 + struct file *file;
32176 + struct au_vdir *vdir;
32177 + struct au_nhash delist;
32178 + struct au_nhash whlist;
32179 + aufs_bindex_t bindex;
32180 + unsigned int flags;
32184 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32185 + loff_t offset __maybe_unused, u64 h_ino,
32186 + unsigned int d_type)
32188 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32189 + char *name = (void *)__name;
32190 + struct super_block *sb;
32192 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32195 + sb = arg->file->f_path.dentry->d_sb;
32196 + au_fset_fillvdir(arg->flags, CALLED);
32198 + if (nlen <= AUFS_WH_PFX_LEN
32199 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32200 + if (test_known(&arg->delist, name, nlen)
32201 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32202 + goto out; /* already exists or whiteouted */
32204 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32206 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32207 + d_type = DT_UNKNOWN;
32208 + arg->err = append_de(arg->vdir, name, nlen, ino,
32209 + d_type, &arg->delist);
32211 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32212 + name += AUFS_WH_PFX_LEN;
32213 + nlen -= AUFS_WH_PFX_LEN;
32214 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32215 + goto out; /* already whiteouted */
32217 + ino = 0; /* just to suppress a warning */
32219 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32222 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32223 + d_type = DT_UNKNOWN;
32224 + arg->err = au_nhash_append_wh
32225 + (&arg->whlist, name, nlen, ino, d_type,
32226 + arg->bindex, shwh);
32232 + arg->vdir->vd_jiffy = jiffies;
32234 + AuTraceErr(arg->err);
32238 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32239 + struct au_nhash *whlist, struct au_nhash *delist)
32241 +#ifdef CONFIG_AUFS_SHWH
32243 + unsigned int nh, u;
32244 + struct hlist_head *head;
32245 + struct au_vdir_wh *pos;
32246 + struct hlist_node *n;
32248 + struct au_vdir_destr *destr;
32250 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32253 + o = p = (void *)__get_free_page(GFP_NOFS);
32254 + if (unlikely(!p))
32258 + nh = whlist->nh_num;
32259 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32260 + p += AUFS_WH_PFX_LEN;
32261 + for (u = 0; u < nh; u++) {
32262 + head = whlist->nh_head + u;
32263 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32264 + destr = &pos->wh_str;
32265 + memcpy(p, destr->name, destr->len);
32266 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32267 + pos->wh_ino, pos->wh_type, delist);
32268 + if (unlikely(err))
32273 + free_page((unsigned long)o);
32283 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32286 + unsigned int rdhash;
32288 + aufs_bindex_t bbot, bindex, btop;
32289 + unsigned char shwh;
32290 + struct file *hf, *file;
32291 + struct super_block *sb;
32293 + file = arg->file;
32294 + sb = file->f_path.dentry->d_sb;
32295 + SiMustAnyLock(sb);
32297 + rdhash = au_sbi(sb)->si_rdhash;
32299 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32300 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32301 + if (unlikely(err))
32303 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32304 + if (unlikely(err))
32310 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32312 + au_fset_fillvdir(arg->flags, SHWH);
32314 + btop = au_fbtop(file);
32315 + bbot = au_fbbot_dir(file);
32316 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32317 + hf = au_hf_dir(file, bindex);
32321 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32323 + if (unlikely(offset))
32326 + arg->bindex = bindex;
32327 + au_fclr_fillvdir(arg->flags, WHABLE);
32329 + || (bindex != bbot
32330 + && au_br_whable(au_sbr_perm(sb, bindex))))
32331 + au_fset_fillvdir(arg->flags, WHABLE);
32334 + au_fclr_fillvdir(arg->flags, CALLED);
32336 + err = vfsub_iterate_dir(hf, &arg->ctx);
32339 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32342 + * dir_relax() may be good for concurrency, but aufs should not
32343 + * use it since it will cause a lockdep problem.
32347 + if (!err && shwh)
32348 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32350 + au_nhash_wh_free(&arg->whlist);
32353 + au_nhash_de_free(&arg->delist);
32358 +static int read_vdir(struct file *file, int may_read)
32361 + unsigned long expire;
32362 + unsigned char do_read;
32363 + struct fillvdir_arg arg = {
32365 + .actor = fillvdir
32368 + struct inode *inode;
32369 + struct au_vdir *vdir, *allocated;
32372 + inode = file_inode(file);
32373 + IMustLock(inode);
32374 + IiMustWriteLock(inode);
32375 + SiMustAnyLock(inode->i_sb);
32377 + allocated = NULL;
32379 + expire = au_sbi(inode->i_sb)->si_rdcache;
32380 + vdir = au_ivdir(inode);
32383 + vdir = alloc_vdir(file);
32384 + err = PTR_ERR(vdir);
32385 + if (IS_ERR(vdir))
32388 + allocated = vdir;
32389 + } else if (may_read
32390 + && (!inode_eq_iversion(inode, vdir->vd_version)
32391 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32393 + err = reinit_vdir(vdir);
32394 + if (unlikely(err))
32399 + return 0; /* success */
32403 + err = au_do_read_vdir(&arg);
32405 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32406 + vdir->vd_version = inode_query_iversion(inode);
32407 + vdir->vd_last.ul = 0;
32408 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32410 + au_set_ivdir(inode, allocated);
32411 + } else if (allocated)
32412 + au_vdir_free(allocated);
32418 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32421 + unsigned long ul, n;
32422 + const unsigned int deblk_sz = src->vd_deblk_sz;
32424 + AuDebugOn(tgt->vd_nblk != 1);
32427 + if (tgt->vd_nblk < src->vd_nblk) {
32428 + unsigned char **p;
32430 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32431 + GFP_NOFS, /*may_shrink*/0);
32432 + if (unlikely(!p))
32434 + tgt->vd_deblk = p;
32437 + if (tgt->vd_deblk_sz != deblk_sz) {
32438 + unsigned char *p;
32440 + tgt->vd_deblk_sz = deblk_sz;
32441 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32442 + /*may_shrink*/1);
32443 + if (unlikely(!p))
32445 + tgt->vd_deblk[0] = p;
32447 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32448 + tgt->vd_version = src->vd_version;
32449 + tgt->vd_jiffy = src->vd_jiffy;
32451 + n = src->vd_nblk;
32452 + for (ul = 1; ul < n; ul++) {
32453 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32455 + if (unlikely(!tgt->vd_deblk[ul]))
32459 + tgt->vd_nblk = n;
32460 + tgt->vd_last.ul = tgt->vd_last.ul;
32461 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32462 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32463 + - src->vd_deblk[src->vd_last.ul];
32465 + return 0; /* success */
32468 + rerr = reinit_vdir(tgt);
32473 +int au_vdir_init(struct file *file)
32476 + struct inode *inode;
32477 + struct au_vdir *vdir_cache, *allocated;
32479 + /* test file->f_pos here instead of ctx->pos */
32480 + err = read_vdir(file, !file->f_pos);
32481 + if (unlikely(err))
32484 + allocated = NULL;
32485 + vdir_cache = au_fvdir_cache(file);
32486 + if (!vdir_cache) {
32487 + vdir_cache = alloc_vdir(file);
32488 + err = PTR_ERR(vdir_cache);
32489 + if (IS_ERR(vdir_cache))
32491 + allocated = vdir_cache;
32492 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32493 + /* test file->f_pos here instead of ctx->pos */
32494 + err = reinit_vdir(vdir_cache);
32495 + if (unlikely(err))
32498 + return 0; /* success */
32500 + inode = file_inode(file);
32501 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32503 + file->f_version = inode_query_iversion(inode);
32505 + au_set_fvdir_cache(file, allocated);
32506 + } else if (allocated)
32507 + au_vdir_free(allocated);
32513 +static loff_t calc_offset(struct au_vdir *vdir)
32516 + union au_vdir_deblk_p p;
32518 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32519 + offset = vdir->vd_last.p.deblk - p.deblk;
32520 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32524 +/* returns true or false */
32525 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32528 + unsigned int deblk_sz;
32529 + unsigned long ul, n;
32531 + union au_vdir_deblk_p p, deblk_end;
32532 + struct au_vdir *vdir_cache;
32535 + vdir_cache = au_fvdir_cache(file);
32536 + offset = calc_offset(vdir_cache);
32537 + AuDbg("offset %lld\n", offset);
32538 + if (ctx->pos == offset)
32541 + vdir_cache->vd_last.ul = 0;
32542 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32547 + deblk_sz = vdir_cache->vd_deblk_sz;
32548 + ul = div64_u64(ctx->pos, deblk_sz);
32549 + AuDbg("ul %lu\n", ul);
32550 + if (ul >= vdir_cache->vd_nblk)
32553 + n = vdir_cache->vd_nblk;
32554 + for (; ul < n; ul++) {
32555 + p.deblk = vdir_cache->vd_deblk[ul];
32556 + deblk_end.deblk = p.deblk + deblk_sz;
32558 + offset *= deblk_sz;
32559 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32562 + l = calc_size(p.de->de_str.len);
32566 + if (!is_deblk_end(&p, &deblk_end)) {
32568 + vdir_cache->vd_last.ul = ul;
32569 + vdir_cache->vd_last.p = p;
32577 + AuDbg("valid %d\n", !valid);
32581 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32583 + unsigned int l, deblk_sz;
32584 + union au_vdir_deblk_p deblk_end;
32585 + struct au_vdir *vdir_cache;
32586 + struct au_vdir_de *de;
32588 + if (!seek_vdir(file, ctx))
32591 + vdir_cache = au_fvdir_cache(file);
32592 + deblk_sz = vdir_cache->vd_deblk_sz;
32594 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32595 + deblk_end.deblk += deblk_sz;
32596 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32597 + de = vdir_cache->vd_last.p.de;
32598 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32599 + de->de_str.len, de->de_str.name, ctx->pos,
32600 + (unsigned long)de->de_ino, de->de_type);
32601 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32602 + de->de_str.len, de->de_ino,
32604 + /* todo: ignore the error caused by udba? */
32605 + /* return err; */
32609 + l = calc_size(de->de_str.len);
32610 + vdir_cache->vd_last.p.deblk += l;
32613 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32614 + vdir_cache->vd_last.ul++;
32615 + vdir_cache->vd_last.p.deblk
32616 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32617 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32626 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32627 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32628 +++ linux/fs/aufs/vfsub.c 2022-01-13 12:42:15.932899468 +0100
32630 +// SPDX-License-Identifier: GPL-2.0
32632 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32634 + * This program, aufs is free software; you can redistribute it and/or modify
32635 + * it under the terms of the GNU General Public License as published by
32636 + * the Free Software Foundation; either version 2 of the License, or
32637 + * (at your option) any later version.
32639 + * This program is distributed in the hope that it will be useful,
32640 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32641 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32642 + * GNU General Public License for more details.
32644 + * You should have received a copy of the GNU General Public License
32645 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32649 + * sub-routines for VFS
32652 +#include <linux/mnt_namespace.h>
32653 +#include <linux/namei.h>
32654 +#include <linux/nsproxy.h>
32655 +#include <linux/security.h>
32656 +#include <linux/splice.h>
32659 +#ifdef CONFIG_AUFS_BR_FUSE
32660 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32662 + if (!au_test_fuse(h_sb) || !au_userns)
32665 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32669 +int vfsub_sync_filesystem(struct super_block *h_sb)
32674 + down_read(&h_sb->s_umount);
32675 + err = sync_filesystem(h_sb);
32676 + up_read(&h_sb->s_umount);
32682 +/* ---------------------------------------------------------------------- */
32684 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32688 + struct super_block *h_sb;
32691 + * Always needs h_path->mnt for LSM or FUSE branch.
32693 + AuDebugOn(!h_path->mnt);
32695 + /* for remote fs, leave work for its getattr or d_revalidate */
32696 + /* for bad i_attr fs, handle them in aufs_getattr() */
32697 + /* still some fs may acquire i_mutex. we need to skip them */
32701 + h_sb = h_path->dentry->d_sb;
32702 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32704 + err = vfsub_getattr(h_path, &st);
32709 +/* ---------------------------------------------------------------------- */
32711 +struct file *vfsub_dentry_open(struct path *path, int flags)
32713 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32717 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32719 + struct file *file;
32722 + file = filp_open(path,
32723 + oflags /* | __FMODE_NONOTIFY */,
32726 + if (IS_ERR(file))
32728 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32735 + * Ideally this function should call VFS:do_last() in order to keep all its
32736 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32737 + * structure such as nameidata. This is a second (or third) best approach.
32738 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32740 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32741 + struct vfsub_aopen_args *args)
32744 + struct au_branch *br = args->br;
32745 + struct file *file = args->file;
32746 + /* copied from linux/fs/namei.c:atomic_open() */
32747 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32750 + AuDebugOn(!dir->i_op->atomic_open);
32752 + err = au_br_test_oflag(args->open_flag, br);
32753 + if (unlikely(err))
32756 + au_lcnt_inc(&br->br_nfiles);
32757 + file->f_path.dentry = DENTRY_NOT_SET;
32758 + file->f_path.mnt = au_br_mnt(br);
32759 + AuDbg("%ps\n", dir->i_op->atomic_open);
32760 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32761 + args->create_mode);
32762 + if (unlikely(err < 0)) {
32763 + au_lcnt_dec(&br->br_nfiles);
32767 + /* temporary workaround for nfsv4 branch */
32768 + if (au_test_nfs(dir->i_sb))
32769 + nfs_mark_for_revalidate(dir);
32771 + if (file->f_mode & FMODE_CREATED)
32772 + fsnotify_create(dir, dentry);
32773 + if (!(file->f_mode & FMODE_OPENED)) {
32774 + au_lcnt_dec(&br->br_nfiles);
32778 + /* todo: call VFS:may_open() here */
32779 + /* todo: ima_file_check() too? */
32780 + if (!err && (args->open_flag & __FMODE_EXEC))
32781 + err = deny_write_access(file);
32783 + fsnotify_open(file);
32785 + au_lcnt_dec(&br->br_nfiles);
32786 + /* note that the file is created and still opened */
32792 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32796 + err = kern_path(name, flags, path);
32797 + if (!err && d_is_positive(path->dentry))
32798 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32802 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32803 + struct path *ppath, int len)
32805 + struct path path;
32807 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
32808 + if (IS_ERR(path.dentry))
32810 + if (d_is_positive(path.dentry)) {
32811 + path.mnt = ppath->mnt;
32812 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32816 + AuTraceErrPtr(path.dentry);
32817 + return path.dentry;
32820 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
32823 + struct path path;
32825 + /* VFS checks it too, but by WARN_ON_ONCE() */
32826 + IMustLock(d_inode(ppath->dentry));
32828 + path.dentry = lookup_one_len(name, ppath->dentry, len);
32829 + if (IS_ERR(path.dentry))
32831 + if (d_is_positive(path.dentry)) {
32832 + path.mnt = ppath->mnt;
32833 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32837 + AuTraceErrPtr(path.dentry);
32838 + return path.dentry;
32841 +void vfsub_call_lkup_one(void *args)
32843 + struct vfsub_lkup_one_args *a = args;
32844 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
32847 +/* ---------------------------------------------------------------------- */
32849 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32850 + struct dentry *d2, struct au_hinode *hdir2)
32852 + struct dentry *d;
32855 + d = lock_rename(d1, d2);
32857 + au_hn_suspend(hdir1);
32858 + if (hdir1 != hdir2)
32859 + au_hn_suspend(hdir2);
32864 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32865 + struct dentry *d2, struct au_hinode *hdir2)
32867 + au_hn_resume(hdir1);
32868 + if (hdir1 != hdir2)
32869 + au_hn_resume(hdir2);
32871 + unlock_rename(d1, d2);
32875 +/* ---------------------------------------------------------------------- */
32877 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32880 + struct dentry *d;
32881 + struct user_namespace *userns;
32885 + d = path->dentry;
32886 + path->dentry = d->d_parent;
32887 + err = security_path_mknod(path, d, mode, 0);
32888 + path->dentry = d;
32889 + if (unlikely(err))
32891 + userns = mnt_user_ns(path->mnt);
32894 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
32897 + struct path tmp = *path;
32900 + vfsub_update_h_iattr(&tmp, &did);
32902 + tmp.dentry = path->dentry->d_parent;
32903 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32912 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32915 + struct dentry *d;
32916 + struct user_namespace *userns;
32920 + d = path->dentry;
32921 + path->dentry = d->d_parent;
32922 + err = security_path_symlink(path, d, symname);
32923 + path->dentry = d;
32924 + if (unlikely(err))
32926 + userns = mnt_user_ns(path->mnt);
32929 + err = vfs_symlink(userns, dir, path->dentry, symname);
32932 + struct path tmp = *path;
32935 + vfsub_update_h_iattr(&tmp, &did);
32937 + tmp.dentry = path->dentry->d_parent;
32938 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32947 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32950 + struct dentry *d;
32951 + struct user_namespace *userns;
32955 + d = path->dentry;
32956 + path->dentry = d->d_parent;
32957 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32958 + path->dentry = d;
32959 + if (unlikely(err))
32961 + userns = mnt_user_ns(path->mnt);
32964 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
32967 + struct path tmp = *path;
32970 + vfsub_update_h_iattr(&tmp, &did);
32972 + tmp.dentry = path->dentry->d_parent;
32973 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32982 +static int au_test_nlink(struct inode *inode)
32984 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32986 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32987 + || inode->i_nlink < link_max)
32992 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32993 + struct inode **delegated_inode)
32996 + struct dentry *d;
32997 + struct user_namespace *userns;
33001 + err = au_test_nlink(d_inode(src_dentry));
33002 + if (unlikely(err))
33005 + /* we don't call may_linkat() */
33006 + d = path->dentry;
33007 + path->dentry = d->d_parent;
33008 + err = security_path_link(src_dentry, path, d);
33009 + path->dentry = d;
33010 + if (unlikely(err))
33012 + userns = mnt_user_ns(path->mnt);
33015 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33018 + struct path tmp = *path;
33021 + /* fuse has different memory inode for the same inumber */
33022 + vfsub_update_h_iattr(&tmp, &did);
33024 + tmp.dentry = path->dentry->d_parent;
33025 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33026 + tmp.dentry = src_dentry;
33027 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33036 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33037 + struct inode *dir, struct path *path,
33038 + struct inode **delegated_inode, unsigned int flags)
33041 + struct renamedata rd;
33042 + struct path tmp = {
33045 + struct dentry *d;
33048 + IMustLock(src_dir);
33050 + d = path->dentry;
33051 + path->dentry = d->d_parent;
33052 + tmp.dentry = src_dentry->d_parent;
33053 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33054 + path->dentry = d;
33055 + if (unlikely(err))
33058 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33059 + rd.old_dir = src_dir;
33060 + rd.old_dentry = src_dentry;
33061 + rd.new_mnt_userns = rd.old_mnt_userns;
33062 + rd.new_dir = dir;
33063 + rd.new_dentry = path->dentry;
33064 + rd.delegated_inode = delegated_inode;
33065 + rd.flags = flags;
33067 + err = vfs_rename(&rd);
33072 + tmp.dentry = d->d_parent;
33073 + vfsub_update_h_iattr(&tmp, &did);
33075 + tmp.dentry = src_dentry;
33076 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33077 + tmp.dentry = src_dentry->d_parent;
33078 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33087 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33090 + struct dentry *d;
33091 + struct user_namespace *userns;
33095 + d = path->dentry;
33096 + path->dentry = d->d_parent;
33097 + err = security_path_mkdir(path, d, mode);
33098 + path->dentry = d;
33099 + if (unlikely(err))
33101 + userns = mnt_user_ns(path->mnt);
33104 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33107 + struct path tmp = *path;
33110 + vfsub_update_h_iattr(&tmp, &did);
33112 + tmp.dentry = path->dentry->d_parent;
33113 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33122 +int vfsub_rmdir(struct inode *dir, struct path *path)
33125 + struct dentry *d;
33126 + struct user_namespace *userns;
33130 + d = path->dentry;
33131 + path->dentry = d->d_parent;
33132 + err = security_path_rmdir(path, d);
33133 + path->dentry = d;
33134 + if (unlikely(err))
33136 + userns = mnt_user_ns(path->mnt);
33139 + err = vfs_rmdir(userns, dir, path->dentry);
33142 + struct path tmp = {
33143 + .dentry = path->dentry->d_parent,
33147 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33154 +/* ---------------------------------------------------------------------- */
33156 +/* todo: support mmap_sem? */
33157 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33163 + err = vfs_read(file, ubuf, count, ppos);
33166 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33170 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33176 + err = kernel_read(file, kbuf, count, ppos);
33180 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33184 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33190 + err = vfs_write(file, ubuf, count, ppos);
33193 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33197 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33202 + err = kernel_write(file, kbuf, count, ppos);
33205 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33209 +int vfsub_flush(struct file *file, fl_owner_t id)
33214 + if (file->f_op->flush) {
33215 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33216 + err = file->f_op->flush(file, id);
33219 + err = file->f_op->flush(file, id);
33223 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33229 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33233 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33236 + err = iterate_dir(file, ctx);
33239 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33244 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33245 + struct pipe_inode_info *pipe, size_t len,
33246 + unsigned int flags)
33251 + err = do_splice_to(in, ppos, pipe, len, flags);
33253 + file_accessed(in);
33255 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33259 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33260 + loff_t *ppos, size_t len, unsigned int flags)
33265 + err = do_splice_from(pipe, out, ppos, len, flags);
33268 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33272 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33276 + /* file can be NULL */
33278 + err = vfs_fsync(file, datasync);
33282 + AuDebugOn(!file);
33283 + path = &file->f_path;
33285 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33290 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33291 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33292 + struct file *h_file)
33295 + struct inode *h_inode;
33296 + struct super_block *h_sb;
33297 + struct user_namespace *h_userns;
33300 + err = vfsub_truncate(h_path, length);
33304 + h_inode = d_inode(h_path->dentry);
33305 + h_sb = h_inode->i_sb;
33307 + sb_start_write(h_sb);
33309 + err = security_path_truncate(h_path);
33311 + h_userns = mnt_user_ns(h_path->mnt);
33313 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33318 + sb_end_write(h_sb);
33325 +/* ---------------------------------------------------------------------- */
33327 +struct au_vfsub_mkdir_args {
33329 + struct inode *dir;
33330 + struct path *path;
33334 +static void au_call_vfsub_mkdir(void *args)
33336 + struct au_vfsub_mkdir_args *a = args;
33337 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33340 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33342 + int err, do_sio, wkq_err;
33343 + struct user_namespace *userns;
33345 + userns = mnt_user_ns(path->mnt);
33346 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33349 + err = vfsub_mkdir(dir, path, mode);
33352 + struct au_vfsub_mkdir_args args = {
33358 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33359 + if (unlikely(wkq_err))
33366 +struct au_vfsub_rmdir_args {
33368 + struct inode *dir;
33369 + struct path *path;
33372 +static void au_call_vfsub_rmdir(void *args)
33374 + struct au_vfsub_rmdir_args *a = args;
33375 + *a->errp = vfsub_rmdir(a->dir, a->path);
33378 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33380 + int err, do_sio, wkq_err;
33381 + struct user_namespace *userns;
33383 + userns = mnt_user_ns(path->mnt);
33384 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33387 + err = vfsub_rmdir(dir, path);
33390 + struct au_vfsub_rmdir_args args = {
33395 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33396 + if (unlikely(wkq_err))
33403 +/* ---------------------------------------------------------------------- */
33405 +struct notify_change_args {
33407 + struct path *path;
33408 + struct iattr *ia;
33409 + struct inode **delegated_inode;
33412 +static void call_notify_change(void *args)
33414 + struct notify_change_args *a = args;
33415 + struct inode *h_inode;
33416 + struct user_namespace *userns;
33418 + h_inode = d_inode(a->path->dentry);
33419 + IMustLock(h_inode);
33421 + *a->errp = -EPERM;
33422 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33423 + userns = mnt_user_ns(a->path->mnt);
33425 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33426 + a->delegated_inode);
33429 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33431 + AuTraceErr(*a->errp);
33434 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33435 + struct inode **delegated_inode)
33438 + struct notify_change_args args = {
33442 + .delegated_inode = delegated_inode
33445 + call_notify_change(&args);
33450 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33451 + struct inode **delegated_inode)
33453 + int err, wkq_err;
33454 + struct notify_change_args args = {
33458 + .delegated_inode = delegated_inode
33461 + wkq_err = au_wkq_wait(call_notify_change, &args);
33462 + if (unlikely(wkq_err))
33468 +/* ---------------------------------------------------------------------- */
33470 +struct unlink_args {
33472 + struct inode *dir;
33473 + struct path *path;
33474 + struct inode **delegated_inode;
33477 +static void call_unlink(void *args)
33479 + struct unlink_args *a = args;
33480 + struct dentry *d = a->path->dentry;
33481 + struct inode *h_inode;
33482 + struct user_namespace *userns;
33483 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33484 + && au_dcount(d) == 1);
33486 + IMustLock(a->dir);
33488 + a->path->dentry = d->d_parent;
33489 + *a->errp = security_path_unlink(a->path, d);
33490 + a->path->dentry = d;
33491 + if (unlikely(*a->errp))
33494 + if (!stop_sillyrename)
33497 + if (d_is_positive(d)) {
33498 + h_inode = d_inode(d);
33502 + userns = mnt_user_ns(a->path->mnt);
33504 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33507 + struct path tmp = {
33508 + .dentry = d->d_parent,
33509 + .mnt = a->path->mnt
33511 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33514 + if (!stop_sillyrename)
33519 + AuTraceErr(*a->errp);
33523 + * @dir: must be locked.
33524 + * @dentry: target dentry.
33526 +int vfsub_unlink(struct inode *dir, struct path *path,
33527 + struct inode **delegated_inode, int force)
33530 + struct unlink_args args = {
33534 + .delegated_inode = delegated_inode
33538 + call_unlink(&args);
33542 + wkq_err = au_wkq_wait(call_unlink, &args);
33543 + if (unlikely(wkq_err))
33549 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33550 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33551 +++ linux/fs/aufs/vfsub.h 2022-01-13 12:42:15.932899468 +0100
33553 +/* SPDX-License-Identifier: GPL-2.0 */
33555 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33557 + * This program, aufs is free software; you can redistribute it and/or modify
33558 + * it under the terms of the GNU General Public License as published by
33559 + * the Free Software Foundation; either version 2 of the License, or
33560 + * (at your option) any later version.
33562 + * This program is distributed in the hope that it will be useful,
33563 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33564 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33565 + * GNU General Public License for more details.
33567 + * You should have received a copy of the GNU General Public License
33568 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33572 + * sub-routines for VFS
33575 +#ifndef __AUFS_VFSUB_H__
33576 +#define __AUFS_VFSUB_H__
33580 +#include <linux/fs.h>
33581 +#include <linux/mount.h>
33582 +#include <linux/posix_acl.h>
33583 +#include <linux/xattr.h>
33584 +#include "debug.h"
33586 +/* copied from linux/fs/internal.h */
33587 +/* todo: BAD approach!! */
33588 +extern void __mnt_drop_write(struct vfsmount *);
33589 +extern struct file *alloc_empty_file(int, const struct cred *);
33591 +/* ---------------------------------------------------------------------- */
33593 +/* lock subclass for lower inode */
33594 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33595 +/* reduce? gave up. */
33597 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33598 + AuLsc_I_PARENT, /* lower inode, parent first */
33599 + AuLsc_I_PARENT2, /* copyup dirs */
33600 + AuLsc_I_PARENT3, /* copyup wh */
33606 +/* to debug easier, do not make them inlined functions */
33607 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33608 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33610 +/* ---------------------------------------------------------------------- */
33612 +static inline void vfsub_drop_nlink(struct inode *inode)
33614 + AuDebugOn(!inode->i_nlink);
33615 + drop_nlink(inode);
33618 +static inline void vfsub_dead_dir(struct inode *inode)
33620 + AuDebugOn(!S_ISDIR(inode->i_mode));
33621 + inode->i_flags |= S_DEAD;
33622 + clear_nlink(inode);
33625 +static inline int vfsub_native_ro(struct inode *inode)
33627 + return sb_rdonly(inode->i_sb)
33628 + || IS_RDONLY(inode)
33629 + /* || IS_APPEND(inode) */
33630 + || IS_IMMUTABLE(inode);
33633 +#ifdef CONFIG_AUFS_BR_FUSE
33634 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33636 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33639 +int vfsub_sync_filesystem(struct super_block *h_sb);
33641 +/* ---------------------------------------------------------------------- */
33643 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33644 +struct file *vfsub_dentry_open(struct path *path, int flags);
33645 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33647 +struct vfsub_aopen_args {
33648 + struct file *file;
33649 + unsigned int open_flag;
33650 + umode_t create_mode;
33651 + struct au_branch *br;
33653 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33654 + struct vfsub_aopen_args *args);
33655 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33657 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33658 + struct path *ppath, int len);
33659 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33662 +struct vfsub_lkup_one_args {
33663 + struct dentry **errp;
33664 + struct qstr *name;
33665 + struct path *ppath;
33668 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33669 + struct path *ppath)
33671 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33674 +void vfsub_call_lkup_one(void *args);
33676 +/* ---------------------------------------------------------------------- */
33678 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33683 + err = mnt_want_write(mnt);
33688 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33691 + mnt_drop_write(mnt);
33695 +#if 0 /* reserved */
33696 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33699 + mnt_drop_write_file(file);
33704 +/* ---------------------------------------------------------------------- */
33707 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33708 + struct dentry *d2, struct au_hinode *hdir2);
33709 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33710 + struct dentry *d2, struct au_hinode *hdir2);
33712 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33714 +int vfsub_symlink(struct inode *dir, struct path *path,
33715 + const char *symname);
33716 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33717 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33718 + struct path *path, struct inode **delegated_inode);
33719 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33720 + struct inode *hdir, struct path *path,
33721 + struct inode **delegated_inode, unsigned int flags);
33722 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33723 +int vfsub_rmdir(struct inode *dir, struct path *path);
33725 +/* ---------------------------------------------------------------------- */
33727 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33729 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33731 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33733 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33735 +int vfsub_flush(struct file *file, fl_owner_t id);
33736 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33738 +static inline loff_t vfsub_f_size_read(struct file *file)
33740 + return i_size_read(file_inode(file));
33743 +static inline unsigned int vfsub_file_flags(struct file *file)
33745 + unsigned int flags;
33747 + spin_lock(&file->f_lock);
33748 + flags = file->f_flags;
33749 + spin_unlock(&file->f_lock);
33754 +static inline int vfsub_file_execed(struct file *file)
33756 + /* todo: direct access f_flags */
33757 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33760 +#if 0 /* reserved */
33761 +static inline void vfsub_file_accessed(struct file *h_file)
33763 + file_accessed(h_file);
33764 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33768 +#if 0 /* reserved */
33769 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33770 + struct dentry *h_dentry)
33772 + struct path h_path = {
33773 + .dentry = h_dentry,
33776 + touch_atime(&h_path);
33777 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33781 +static inline int vfsub_update_time(struct inode *h_inode,
33782 + struct timespec64 *ts, int flags)
33784 + return inode_update_time(h_inode, ts, flags);
33785 + /* no vfsub_update_h_iattr() since we don't have struct path */
33788 +#ifdef CONFIG_FS_POSIX_ACL
33789 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
33790 + struct inode *h_inode, umode_t h_mode)
33794 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
33795 + if (err == -EOPNOTSUPP)
33800 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
33801 + struct inode *h_inode, umode_t h_mode);
33804 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33805 + struct pipe_inode_info *pipe, size_t len,
33806 + unsigned int flags);
33807 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33808 + loff_t *ppos, size_t len, unsigned int flags);
33810 +static inline long vfsub_truncate(struct path *path, loff_t length)
33815 + err = vfs_truncate(path, length);
33820 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33821 + struct file *h_file);
33822 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33825 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33828 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33834 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33840 +/* copy_file_range(2) is a systemcall */
33841 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33842 + struct file *dst, loff_t dst_pos,
33843 + size_t len, unsigned int flags)
33848 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33854 +/* ---------------------------------------------------------------------- */
33856 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33861 + err = vfs_llseek(file, offset, origin);
33866 +/* ---------------------------------------------------------------------- */
33868 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33869 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33870 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33871 + struct inode **delegated_inode);
33872 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33873 + struct inode **delegated_inode);
33874 +int vfsub_unlink(struct inode *dir, struct path *path,
33875 + struct inode **delegated_inode, int force);
33877 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33879 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33882 +/* ---------------------------------------------------------------------- */
33884 +static inline int vfsub_setxattr(struct user_namespace *userns,
33885 + struct dentry *dentry, const char *name,
33886 + const void *value, size_t size, int flags)
33891 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
33897 +static inline int vfsub_removexattr(struct user_namespace *userns,
33898 + struct dentry *dentry, const char *name)
33903 + err = vfs_removexattr(userns, dentry, name);
33909 +#endif /* __KERNEL__ */
33910 +#endif /* __AUFS_VFSUB_H__ */
33911 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33912 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33913 +++ linux/fs/aufs/wbr_policy.c 2021-12-03 15:38:59.939980643 +0100
33915 +// SPDX-License-Identifier: GPL-2.0
33917 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33919 + * This program, aufs is free software; you can redistribute it and/or modify
33920 + * it under the terms of the GNU General Public License as published by
33921 + * the Free Software Foundation; either version 2 of the License, or
33922 + * (at your option) any later version.
33924 + * This program is distributed in the hope that it will be useful,
33925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33927 + * GNU General Public License for more details.
33929 + * You should have received a copy of the GNU General Public License
33930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33934 + * policies for selecting one among multiple writable branches
33937 +#include <linux/statfs.h>
33940 +/* subset of cpup_attr() */
33941 +static noinline_for_stack
33942 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33946 + struct inode *h_isrc;
33948 + h_isrc = d_inode(h_src);
33949 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33950 + ia.ia_mode = h_isrc->i_mode;
33951 + ia.ia_uid = h_isrc->i_uid;
33952 + ia.ia_gid = h_isrc->i_gid;
33953 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33954 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33955 + /* no delegation since it is just created */
33956 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33958 + /* is this nfs only? */
33959 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33960 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33961 + ia.ia_mode = h_isrc->i_mode;
33962 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33968 +#define AuCpdown_PARENT_OPQ 1
33969 +#define AuCpdown_WHED (1 << 1)
33970 +#define AuCpdown_MADE_DIR (1 << 2)
33971 +#define AuCpdown_DIROPQ (1 << 3)
33972 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33973 +#define au_fset_cpdown(flags, name) \
33974 + do { (flags) |= AuCpdown_##name; } while (0)
33975 +#define au_fclr_cpdown(flags, name) \
33976 + do { (flags) &= ~AuCpdown_##name; } while (0)
33978 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33979 + unsigned int *flags)
33982 + struct dentry *opq_dentry;
33984 + opq_dentry = au_diropq_create(dentry, bdst);
33985 + err = PTR_ERR(opq_dentry);
33986 + if (IS_ERR(opq_dentry))
33988 + dput(opq_dentry);
33989 + au_fset_cpdown(*flags, DIROPQ);
33995 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33996 + struct inode *dir, aufs_bindex_t bdst)
33999 + struct path h_path;
34000 + struct au_branch *br;
34002 + br = au_sbr(dentry->d_sb, bdst);
34003 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34004 + err = PTR_ERR(h_path.dentry);
34005 + if (IS_ERR(h_path.dentry))
34009 + if (d_is_positive(h_path.dentry)) {
34010 + h_path.mnt = au_br_mnt(br);
34011 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34014 + dput(h_path.dentry);
34020 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34021 + struct au_pin *pin,
34022 + struct dentry *h_parent, void *arg)
34025 + aufs_bindex_t bopq, btop;
34026 + struct path h_path;
34027 + struct dentry *parent;
34028 + struct inode *h_dir, *h_inode, *inode, *dir;
34029 + unsigned int *flags = arg;
34031 + btop = au_dbtop(dentry);
34032 + /* dentry is di-locked */
34033 + parent = dget_parent(dentry);
34034 + dir = d_inode(parent);
34035 + h_dir = d_inode(h_parent);
34036 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34037 + IMustLock(h_dir);
34039 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34040 + if (unlikely(err < 0))
34042 + h_path.dentry = au_h_dptr(dentry, bdst);
34043 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34044 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34045 + if (unlikely(err))
34047 + au_fset_cpdown(*flags, MADE_DIR);
34049 + bopq = au_dbdiropq(dentry);
34050 + au_fclr_cpdown(*flags, WHED);
34051 + au_fclr_cpdown(*flags, DIROPQ);
34052 + if (au_dbwh(dentry) == bdst)
34053 + au_fset_cpdown(*flags, WHED);
34054 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34055 + au_fset_cpdown(*flags, PARENT_OPQ);
34056 + h_inode = d_inode(h_path.dentry);
34057 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34058 + if (au_ftest_cpdown(*flags, WHED)) {
34059 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34060 + if (unlikely(err)) {
34061 + inode_unlock(h_inode);
34066 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34067 + inode_unlock(h_inode);
34068 + if (unlikely(err))
34071 + if (au_ftest_cpdown(*flags, WHED)) {
34072 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34073 + if (unlikely(err))
34077 + inode = d_inode(dentry);
34078 + if (au_ibbot(inode) < bdst)
34079 + au_set_ibbot(inode, bdst);
34080 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34081 + au_hi_flags(inode, /*isdir*/1));
34082 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34083 + goto out; /* success */
34087 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34088 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34089 + rerr = au_diropq_remove(dentry, bdst);
34090 + inode_unlock(h_inode);
34091 + if (unlikely(rerr)) {
34092 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34093 + dentry, bdst, rerr);
34099 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34100 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34101 + if (unlikely(rerr)) {
34102 + AuIOErr("failed removing %pd b%d (%d)\n",
34103 + dentry, bdst, rerr);
34108 + au_set_h_dptr(dentry, bdst, NULL);
34109 + if (au_dbbot(dentry) == bdst)
34110 + au_update_dbbot(dentry);
34116 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34119 + unsigned int flags;
34122 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34127 +/* ---------------------------------------------------------------------- */
34129 +/* policies for create */
34131 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34133 + int err, i, j, ndentry;
34134 + aufs_bindex_t bopq;
34135 + struct au_dcsub_pages dpages;
34136 + struct au_dpage *dpage;
34137 + struct dentry **dentries, *parent, *d;
34139 + err = au_dpages_init(&dpages, GFP_NOFS);
34140 + if (unlikely(err))
34142 + parent = dget_parent(dentry);
34143 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34144 + if (unlikely(err))
34148 + for (i = 0; i < dpages.ndpage; i++) {
34149 + dpage = dpages.dpages + i;
34150 + dentries = dpage->dentries;
34151 + ndentry = dpage->ndentry;
34152 + for (j = 0; j < ndentry; j++) {
34154 + di_read_lock_parent2(d, !AuLock_IR);
34155 + bopq = au_dbdiropq(d);
34156 + di_read_unlock(d, !AuLock_IR);
34157 + if (bopq >= 0 && bopq < err)
34164 + au_dpages_free(&dpages);
34169 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34171 + for (; bindex >= 0; bindex--)
34172 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34177 +/* top down parent */
34178 +static int au_wbr_create_tdp(struct dentry *dentry,
34179 + unsigned int flags __maybe_unused)
34182 + aufs_bindex_t btop, bindex;
34183 + struct super_block *sb;
34184 + struct dentry *parent, *h_parent;
34186 + sb = dentry->d_sb;
34187 + btop = au_dbtop(dentry);
34189 + if (!au_br_rdonly(au_sbr(sb, btop)))
34193 + parent = dget_parent(dentry);
34194 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34195 + h_parent = au_h_dptr(parent, bindex);
34196 + if (!h_parent || d_is_negative(h_parent))
34199 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34206 + /* bottom up here */
34207 + if (unlikely(err < 0)) {
34208 + err = au_wbr_bu(sb, btop - 1);
34210 + err = au_wbr_nonopq(dentry, err);
34214 + AuDbg("b%d\n", err);
34218 +/* ---------------------------------------------------------------------- */
34220 +/* an exception for the policy other than tdp */
34221 +static int au_wbr_create_exp(struct dentry *dentry)
34224 + aufs_bindex_t bwh, bdiropq;
34225 + struct dentry *parent;
34228 + bwh = au_dbwh(dentry);
34229 + parent = dget_parent(dentry);
34230 + bdiropq = au_dbdiropq(parent);
34232 + if (bdiropq >= 0)
34233 + err = min(bdiropq, bwh);
34236 + AuDbg("%d\n", err);
34237 + } else if (bdiropq >= 0) {
34239 + AuDbg("%d\n", err);
34244 + err = au_wbr_nonopq(dentry, err);
34246 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34249 + AuDbg("%d\n", err);
34253 +/* ---------------------------------------------------------------------- */
34256 +static int au_wbr_create_init_rr(struct super_block *sb)
34260 + err = au_wbr_bu(sb, au_sbbot(sb));
34261 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34264 + AuDbg("b%d\n", err);
34268 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34272 + aufs_bindex_t bindex, bbot;
34273 + struct super_block *sb;
34276 + err = au_wbr_create_exp(dentry);
34280 + sb = dentry->d_sb;
34281 + next = &au_sbi(sb)->si_wbr_rr_next;
34282 + bbot = au_sbbot(sb);
34284 + for (bindex = 0; bindex <= bbot; bindex++) {
34285 + if (!au_ftest_wbr(flags, DIR)) {
34286 + err = atomic_dec_return(next) + 1;
34287 + /* modulo for 0 is meaningless */
34288 + if (unlikely(!err))
34289 + err = atomic_dec_return(next) + 1;
34291 + err = atomic_read(next);
34292 + AuDbg("%d\n", err);
34295 + AuDbg("%d\n", err);
34296 + if (!au_br_rdonly(au_sbr(sb, err)))
34302 + err = au_wbr_nonopq(dentry, err);
34305 + AuDbg("%d\n", err);
34309 +/* ---------------------------------------------------------------------- */
34311 +/* most free space */
34312 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34314 + struct super_block *sb;
34315 + struct au_branch *br;
34316 + struct au_wbr_mfs *mfs;
34317 + struct dentry *h_parent;
34318 + aufs_bindex_t bindex, bbot;
34320 + unsigned long long b, bavail;
34321 + struct path h_path;
34322 + /* reduce the stack usage */
34323 + struct kstatfs *st;
34325 + st = kmalloc(sizeof(*st), GFP_NOFS);
34326 + if (unlikely(!st)) {
34327 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34332 + sb = dentry->d_sb;
34333 + mfs = &au_sbi(sb)->si_wbr_mfs;
34334 + MtxMustLock(&mfs->mfs_lock);
34335 + mfs->mfs_bindex = -EROFS;
34336 + mfs->mfsrr_bytes = 0;
34339 + bbot = au_sbbot(sb);
34341 + bindex = au_dbtop(parent);
34342 + bbot = au_dbtaildir(parent);
34345 + for (; bindex <= bbot; bindex++) {
34347 + h_parent = au_h_dptr(parent, bindex);
34348 + if (!h_parent || d_is_negative(h_parent))
34351 + br = au_sbr(sb, bindex);
34352 + if (au_br_rdonly(br))
34355 + /* sb->s_root for NFS is unreliable */
34356 + h_path.mnt = au_br_mnt(br);
34357 + h_path.dentry = h_path.mnt->mnt_root;
34358 + err = vfs_statfs(&h_path, st);
34359 + if (unlikely(err)) {
34360 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34364 + /* when the available size is equal, select the lower one */
34365 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34366 + || sizeof(b) < sizeof(st->f_bsize));
34367 + b = st->f_bavail * st->f_bsize;
34368 + br->br_wbr->wbr_bytes = b;
34369 + if (b >= bavail) {
34371 + mfs->mfs_bindex = bindex;
34372 + mfs->mfs_jiffy = jiffies;
34376 + mfs->mfsrr_bytes = bavail;
34377 + AuDbg("b%d\n", mfs->mfs_bindex);
34378 + au_kfree_rcu(st);
34381 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34384 + struct dentry *parent;
34385 + struct super_block *sb;
34386 + struct au_wbr_mfs *mfs;
34388 + err = au_wbr_create_exp(dentry);
34392 + sb = dentry->d_sb;
34394 + if (au_ftest_wbr(flags, PARENT))
34395 + parent = dget_parent(dentry);
34396 + mfs = &au_sbi(sb)->si_wbr_mfs;
34397 + mutex_lock(&mfs->mfs_lock);
34398 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34399 + || mfs->mfs_bindex < 0
34400 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34401 + au_mfs(dentry, parent);
34402 + mutex_unlock(&mfs->mfs_lock);
34403 + err = mfs->mfs_bindex;
34407 + err = au_wbr_nonopq(dentry, err);
34410 + AuDbg("b%d\n", err);
34414 +static int au_wbr_create_init_mfs(struct super_block *sb)
34416 + struct au_wbr_mfs *mfs;
34418 + mfs = &au_sbi(sb)->si_wbr_mfs;
34419 + mutex_init(&mfs->mfs_lock);
34420 + mfs->mfs_jiffy = 0;
34421 + mfs->mfs_bindex = -EROFS;
34426 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34428 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34432 +/* ---------------------------------------------------------------------- */
34434 +/* top down regardless parent, and then mfs */
34435 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34436 + unsigned int flags __maybe_unused)
34439 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34440 + unsigned long long watermark;
34441 + struct super_block *sb;
34442 + struct au_wbr_mfs *mfs;
34443 + struct au_branch *br;
34444 + struct dentry *parent;
34446 + sb = dentry->d_sb;
34447 + mfs = &au_sbi(sb)->si_wbr_mfs;
34448 + mutex_lock(&mfs->mfs_lock);
34449 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34450 + || mfs->mfs_bindex < 0)
34451 + au_mfs(dentry, /*parent*/NULL);
34452 + watermark = mfs->mfsrr_watermark;
34453 + bmfs = mfs->mfs_bindex;
34454 + mutex_unlock(&mfs->mfs_lock);
34456 + /* another style of au_wbr_create_exp() */
34457 + bwh = au_dbwh(dentry);
34458 + parent = dget_parent(dentry);
34459 + btail = au_dbtaildir(parent);
34460 + if (bwh >= 0 && bwh < btail)
34463 + err = au_wbr_nonopq(dentry, btail);
34464 + if (unlikely(err < 0))
34468 + for (bindex = 0; bindex <= btail; bindex++) {
34469 + br = au_sbr(sb, bindex);
34470 + if (au_br_rdonly(br))
34472 + if (br->br_wbr->wbr_bytes > watermark) {
34483 + AuDbg("b%d\n", err);
34487 +/* ---------------------------------------------------------------------- */
34489 +/* most free space and then round robin */
34490 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34493 + struct au_wbr_mfs *mfs;
34495 + err = au_wbr_create_mfs(dentry, flags);
34497 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34498 + mutex_lock(&mfs->mfs_lock);
34499 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34500 + err = au_wbr_create_rr(dentry, flags);
34501 + mutex_unlock(&mfs->mfs_lock);
34504 + AuDbg("b%d\n", err);
34508 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34512 + au_wbr_create_init_mfs(sb); /* ignore */
34513 + err = au_wbr_create_init_rr(sb);
34518 +/* ---------------------------------------------------------------------- */
34520 +/* top down parent and most free space */
34521 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34524 + unsigned long long b;
34525 + aufs_bindex_t bindex, btop, bbot;
34526 + struct super_block *sb;
34527 + struct dentry *parent, *h_parent;
34528 + struct au_branch *br;
34530 + err = au_wbr_create_tdp(dentry, flags);
34531 + if (unlikely(err < 0))
34533 + parent = dget_parent(dentry);
34534 + btop = au_dbtop(parent);
34535 + bbot = au_dbtaildir(parent);
34536 + if (btop == bbot)
34537 + goto out_parent; /* success */
34539 + e2 = au_wbr_create_mfs(dentry, flags);
34541 + goto out_parent; /* success */
34543 + /* when the available size is equal, select upper one */
34544 + sb = dentry->d_sb;
34545 + br = au_sbr(sb, err);
34546 + b = br->br_wbr->wbr_bytes;
34547 + AuDbg("b%d, %llu\n", err, b);
34549 + for (bindex = btop; bindex <= bbot; bindex++) {
34550 + h_parent = au_h_dptr(parent, bindex);
34551 + if (!h_parent || d_is_negative(h_parent))
34554 + br = au_sbr(sb, bindex);
34555 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34556 + b = br->br_wbr->wbr_bytes;
34558 + AuDbg("b%d, %llu\n", err, b);
34563 + err = au_wbr_nonopq(dentry, err);
34568 + AuDbg("b%d\n", err);
34572 +/* ---------------------------------------------------------------------- */
34575 + * - top down parent
34576 + * - most free space with parent
34577 + * - most free space round-robin regardless parent
34579 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34582 + unsigned long long watermark;
34583 + struct super_block *sb;
34584 + struct au_branch *br;
34585 + struct au_wbr_mfs *mfs;
34587 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34588 + if (unlikely(err < 0))
34591 + sb = dentry->d_sb;
34592 + br = au_sbr(sb, err);
34593 + mfs = &au_sbi(sb)->si_wbr_mfs;
34594 + mutex_lock(&mfs->mfs_lock);
34595 + watermark = mfs->mfsrr_watermark;
34596 + mutex_unlock(&mfs->mfs_lock);
34597 + if (br->br_wbr->wbr_bytes < watermark)
34598 + /* regardless the parent dir */
34599 + err = au_wbr_create_mfsrr(dentry, flags);
34602 + AuDbg("b%d\n", err);
34606 +/* ---------------------------------------------------------------------- */
34608 +/* policies for copyup */
34610 +/* top down parent */
34611 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34613 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34616 +/* bottom up parent */
34617 +static int au_wbr_copyup_bup(struct dentry *dentry)
34620 + aufs_bindex_t bindex, btop;
34621 + struct dentry *parent, *h_parent;
34622 + struct super_block *sb;
34625 + sb = dentry->d_sb;
34626 + parent = dget_parent(dentry);
34627 + btop = au_dbtop(parent);
34628 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34629 + h_parent = au_h_dptr(parent, bindex);
34630 + if (!h_parent || d_is_negative(h_parent))
34633 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34640 + /* bottom up here */
34641 + if (unlikely(err < 0))
34642 + err = au_wbr_bu(sb, btop - 1);
34644 + AuDbg("b%d\n", err);
34649 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34653 + err = au_wbr_bu(dentry->d_sb, btop);
34654 + AuDbg("b%d\n", err);
34656 + err = au_wbr_nonopq(dentry, err);
34658 + AuDbg("b%d\n", err);
34662 +static int au_wbr_copyup_bu(struct dentry *dentry)
34665 + aufs_bindex_t btop;
34667 + btop = au_dbtop(dentry);
34668 + err = au_wbr_do_copyup_bu(dentry, btop);
34672 +/* ---------------------------------------------------------------------- */
34674 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34675 + [AuWbrCopyup_TDP] = {
34676 + .copyup = au_wbr_copyup_tdp
34678 + [AuWbrCopyup_BUP] = {
34679 + .copyup = au_wbr_copyup_bup
34681 + [AuWbrCopyup_BU] = {
34682 + .copyup = au_wbr_copyup_bu
34686 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34687 + [AuWbrCreate_TDP] = {
34688 + .create = au_wbr_create_tdp
34690 + [AuWbrCreate_RR] = {
34691 + .create = au_wbr_create_rr,
34692 + .init = au_wbr_create_init_rr
34694 + [AuWbrCreate_MFS] = {
34695 + .create = au_wbr_create_mfs,
34696 + .init = au_wbr_create_init_mfs,
34697 + .fin = au_wbr_create_fin_mfs
34699 + [AuWbrCreate_MFSV] = {
34700 + .create = au_wbr_create_mfs,
34701 + .init = au_wbr_create_init_mfs,
34702 + .fin = au_wbr_create_fin_mfs
34704 + [AuWbrCreate_MFSRR] = {
34705 + .create = au_wbr_create_mfsrr,
34706 + .init = au_wbr_create_init_mfsrr,
34707 + .fin = au_wbr_create_fin_mfs
34709 + [AuWbrCreate_MFSRRV] = {
34710 + .create = au_wbr_create_mfsrr,
34711 + .init = au_wbr_create_init_mfsrr,
34712 + .fin = au_wbr_create_fin_mfs
34714 + [AuWbrCreate_TDMFS] = {
34715 + .create = au_wbr_create_tdmfs,
34716 + .init = au_wbr_create_init_mfs,
34717 + .fin = au_wbr_create_fin_mfs
34719 + [AuWbrCreate_TDMFSV] = {
34720 + .create = au_wbr_create_tdmfs,
34721 + .init = au_wbr_create_init_mfs,
34722 + .fin = au_wbr_create_fin_mfs
34724 + [AuWbrCreate_PMFS] = {
34725 + .create = au_wbr_create_pmfs,
34726 + .init = au_wbr_create_init_mfs,
34727 + .fin = au_wbr_create_fin_mfs
34729 + [AuWbrCreate_PMFSV] = {
34730 + .create = au_wbr_create_pmfs,
34731 + .init = au_wbr_create_init_mfs,
34732 + .fin = au_wbr_create_fin_mfs
34734 + [AuWbrCreate_PMFSRR] = {
34735 + .create = au_wbr_create_pmfsrr,
34736 + .init = au_wbr_create_init_mfsrr,
34737 + .fin = au_wbr_create_fin_mfs
34739 + [AuWbrCreate_PMFSRRV] = {
34740 + .create = au_wbr_create_pmfsrr,
34741 + .init = au_wbr_create_init_mfsrr,
34742 + .fin = au_wbr_create_fin_mfs
34745 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34746 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34747 +++ linux/fs/aufs/whout.c 2021-12-03 15:40:58.236647297 +0100
34749 +// SPDX-License-Identifier: GPL-2.0
34751 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34753 + * This program, aufs is free software; you can redistribute it and/or modify
34754 + * it under the terms of the GNU General Public License as published by
34755 + * the Free Software Foundation; either version 2 of the License, or
34756 + * (at your option) any later version.
34758 + * This program is distributed in the hope that it will be useful,
34759 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34760 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34761 + * GNU General Public License for more details.
34763 + * You should have received a copy of the GNU General Public License
34764 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34768 + * whiteout for logical deletion and opaque directory
34773 +#define WH_MASK 0444
34776 + * If a directory contains this file, then it is opaque. We start with the
34777 + * .wh. flag so that it is blocked by lookup.
34779 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34780 + sizeof(AUFS_WH_DIROPQ) - 1);
34783 + * generate whiteout name, which is NOT terminated by NULL.
34784 + * @name: original d_name.name
34785 + * @len: original d_name.len
34786 + * @wh: whiteout qstr
34787 + * returns zero when succeeds, otherwise error.
34788 + * succeeded value as wh->name should be freed by kfree().
34790 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34794 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34795 + return -ENAMETOOLONG;
34797 + wh->len = name->len + AUFS_WH_PFX_LEN;
34798 + p = kmalloc(wh->len, GFP_NOFS);
34801 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34802 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34809 +/* ---------------------------------------------------------------------- */
34812 + * test if the @wh_name exists under @h_ppath.
34813 + * @try_sio specifies the necessary of super-io.
34815 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
34816 + struct qstr *wh_name, int try_sio)
34819 + struct dentry *wh_dentry;
34822 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
34824 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
34825 + err = PTR_ERR(wh_dentry);
34826 + if (IS_ERR(wh_dentry)) {
34827 + if (err == -ENAMETOOLONG)
34833 + if (d_is_negative(wh_dentry))
34834 + goto out_wh; /* success */
34837 + if (d_is_reg(wh_dentry))
34838 + goto out_wh; /* success */
34841 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34842 + wh_dentry, d_inode(wh_dentry)->i_mode);
34851 + * test if the @h_path->dentry sets opaque or not.
34853 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
34856 + struct inode *h_dir;
34858 + h_dir = d_inode(h_path->dentry);
34859 + err = au_wh_test(h_userns, h_path, &diropq_name,
34860 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
34865 + * returns a negative dentry whose name is unique and temporary.
34867 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34868 + struct qstr *prefix)
34870 + struct dentry *dentry;
34872 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34874 + /* strict atomic_t is unnecessary here */
34875 + static unsigned short cnt;
34877 + struct path h_ppath;
34878 + struct user_namespace *h_userns;
34880 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34883 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34884 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34885 + dentry = ERR_PTR(-ENAMETOOLONG);
34886 + if (unlikely(qs.len > NAME_MAX))
34888 + dentry = ERR_PTR(-ENOMEM);
34889 + name = kmalloc(qs.len + 1, GFP_NOFS);
34890 + if (unlikely(!name))
34894 + /* doubly whiteout-ed */
34895 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34896 + p = name + AUFS_WH_PFX_LEN * 2;
34897 + memcpy(p, prefix->name, prefix->len);
34898 + p += prefix->len;
34900 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34902 + h_ppath.dentry = h_parent;
34903 + h_ppath.mnt = au_br_mnt(br);
34904 + h_userns = au_br_userns(br);
34906 + for (i = 0; i < 3; i++) {
34907 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34908 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
34909 + if (IS_ERR(dentry) || d_is_negative(dentry))
34913 + /* pr_warn("could not get random name\n"); */
34914 + dentry = ERR_PTR(-EEXIST);
34915 + AuDbg("%.*s\n", AuLNPair(&qs));
34919 + if (name != defname)
34920 + au_kfree_try_rcu(name);
34922 + AuTraceErrPtr(dentry);
34927 + * rename the @h_dentry on @br to the whiteouted temporary name.
34929 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34932 + struct path h_path = {
34933 + .mnt = au_br_mnt(br)
34935 + struct inode *h_dir, *delegated;
34936 + struct dentry *h_parent;
34938 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34939 + h_dir = d_inode(h_parent);
34940 + IMustLock(h_dir);
34942 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34943 + err = PTR_ERR(h_path.dentry);
34944 + if (IS_ERR(h_path.dentry))
34947 + /* under the same dir, no need to lock_rename() */
34948 + delegated = NULL;
34949 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34952 + if (unlikely(err == -EWOULDBLOCK)) {
34953 + pr_warn("cannot retry for NFSv4 delegation"
34954 + " for an internal rename\n");
34957 + dput(h_path.dentry);
34964 +/* ---------------------------------------------------------------------- */
34966 + * functions for removing a whiteout
34969 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34972 + struct inode *delegated;
34975 + * forces superio when the dir has a sticky bit.
34976 + * this may be a violation of unix fs semantics.
34978 + force = (h_dir->i_mode & S_ISVTX)
34979 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34980 + delegated = NULL;
34981 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34982 + if (unlikely(err == -EWOULDBLOCK)) {
34983 + pr_warn("cannot retry for NFSv4 delegation"
34984 + " for an internal unlink\n");
34990 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34991 + struct dentry *dentry)
34995 + err = do_unlink_wh(h_dir, h_path);
34996 + if (!err && dentry)
34997 + au_set_dbwh(dentry, -1);
35002 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35005 + struct path h_path;
35008 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35009 + if (IS_ERR(h_path.dentry))
35010 + err = PTR_ERR(h_path.dentry);
35012 + if (d_is_reg(h_path.dentry)) {
35013 + h_path.mnt = h_ppath->mnt;
35014 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35016 + dput(h_path.dentry);
35022 +/* ---------------------------------------------------------------------- */
35024 + * initialize/clean whiteout for a branch
35027 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35031 + struct inode *delegated;
35033 + if (d_is_negative(whpath->dentry))
35037 + err = vfsub_rmdir(h_dir, whpath);
35039 + delegated = NULL;
35040 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35041 + if (unlikely(err == -EWOULDBLOCK)) {
35042 + pr_warn("cannot retry for NFSv4 delegation"
35043 + " for an internal unlink\n");
35047 + if (unlikely(err))
35048 + pr_warn("failed removing %pd (%d), ignored.\n",
35049 + whpath->dentry, err);
35052 +static int test_linkable(struct dentry *h_root)
35054 + struct inode *h_dir = d_inode(h_root);
35056 + if (h_dir->i_op->link)
35059 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35060 + h_root, au_sbtype(h_root->d_sb));
35061 + return -ENOSYS; /* the branch doesn't have its ->link() */
35064 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35065 +static int au_whdir(struct inode *h_dir, struct path *path)
35070 + if (d_is_negative(path->dentry)) {
35073 + if (au_test_nfs(path->dentry->d_sb))
35075 + err = vfsub_mkdir(h_dir, path, mode);
35076 + } else if (d_is_dir(path->dentry))
35079 + pr_err("unknown %pd exists\n", path->dentry);
35084 +struct au_wh_base {
35085 + const struct qstr *name;
35086 + struct dentry *dentry;
35089 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35090 + struct path *h_path)
35092 + h_path->dentry = base[AuBrWh_BASE].dentry;
35093 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35094 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35095 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35096 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35097 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35101 + * returns tri-state,
35102 + * minus: error, caller should print the message
35104 + * plus: error, caller should NOT print the message
35106 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35107 + int do_plink, struct au_wh_base base[],
35108 + struct path *h_path)
35111 + struct inode *h_dir;
35113 + h_dir = d_inode(h_root);
35114 + h_path->dentry = base[AuBrWh_BASE].dentry;
35115 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35116 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35118 + err = test_linkable(h_root);
35119 + if (unlikely(err)) {
35124 + err = au_whdir(h_dir, h_path);
35125 + if (unlikely(err))
35127 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35129 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35130 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35131 + err = au_whdir(h_dir, h_path);
35132 + if (unlikely(err))
35134 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35141 + * for the moment, aufs supports the branch filesystem which does not support
35142 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35143 + * copyup failed. finally, such filesystem will not be used as the writable
35146 + * returns tri-state, see above.
35148 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35149 + int do_plink, struct au_wh_base base[],
35150 + struct path *h_path)
35153 + struct inode *h_dir;
35155 + WbrWhMustWriteLock(wbr);
35157 + err = test_linkable(h_root);
35158 + if (unlikely(err)) {
35164 + * todo: should this create be done in /sbin/mount.aufs helper?
35167 + h_dir = d_inode(h_root);
35168 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35169 + h_path->dentry = base[AuBrWh_BASE].dentry;
35170 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35171 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35174 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35175 + if (unlikely(err))
35178 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35180 + err = au_whdir(h_dir, h_path);
35181 + if (unlikely(err))
35183 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35185 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35186 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35188 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35189 + err = au_whdir(h_dir, h_path);
35190 + if (unlikely(err))
35192 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35199 + * initialize the whiteout base file/dir for @br.
35201 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35204 + const unsigned char do_plink
35205 + = !!au_opt_test(au_mntflags(sb), PLINK);
35206 + struct inode *h_dir;
35207 + struct path path = br->br_path;
35208 + struct dentry *h_root = path.dentry;
35209 + struct au_wbr *wbr = br->br_wbr;
35210 + static const struct qstr base_name[] = {
35211 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35212 + sizeof(AUFS_BASE_NAME) - 1),
35213 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35214 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35215 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35216 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35218 + struct au_wh_base base[] = {
35219 + [AuBrWh_BASE] = {
35220 + .name = base_name + AuBrWh_BASE,
35223 + [AuBrWh_PLINK] = {
35224 + .name = base_name + AuBrWh_PLINK,
35227 + [AuBrWh_ORPH] = {
35228 + .name = base_name + AuBrWh_ORPH,
35234 + WbrWhMustWriteLock(wbr);
35236 + for (i = 0; i < AuBrWh_Last; i++) {
35237 + /* doubly whiteouted */
35238 + struct dentry *d;
35240 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35241 + err = PTR_ERR(d);
35245 + base[i].dentry = d;
35247 + && wbr->wbr_wh[i]
35248 + && wbr->wbr_wh[i] != base[i].dentry);
35252 + for (i = 0; i < AuBrWh_Last; i++) {
35253 + dput(wbr->wbr_wh[i]);
35254 + wbr->wbr_wh[i] = NULL;
35258 + if (!au_br_writable(br->br_perm)) {
35259 + h_dir = d_inode(h_root);
35260 + au_wh_init_ro(h_dir, base, &path);
35261 + } else if (!au_br_wh_linkable(br->br_perm)) {
35262 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35268 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35274 + goto out; /* success */
35277 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35278 + err, h_root, au_sbtype(h_root->d_sb));
35280 + for (i = 0; i < AuBrWh_Last; i++)
35281 + dput(base[i].dentry);
35285 +/* ---------------------------------------------------------------------- */
35287 + * whiteouts are all hard-linked usually.
35288 + * when its link count reaches a ceiling, we create a new whiteout base
35289 + * asynchronously.
35292 +struct reinit_br_wh {
35293 + struct super_block *sb;
35294 + struct au_branch *br;
35297 +static void reinit_br_wh(void *arg)
35300 + aufs_bindex_t bindex;
35301 + struct path h_path;
35302 + struct reinit_br_wh *a = arg;
35303 + struct au_wbr *wbr;
35304 + struct inode *dir, *delegated;
35305 + struct dentry *h_root;
35306 + struct au_hinode *hdir;
35309 + wbr = a->br->br_wbr;
35310 + /* big aufs lock */
35311 + si_noflush_write_lock(a->sb);
35312 + if (!au_br_writable(a->br->br_perm))
35314 + bindex = au_br_index(a->sb, a->br->br_id);
35315 + if (unlikely(bindex < 0))
35318 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35319 + dir = d_inode(a->sb->s_root);
35320 + hdir = au_hi(dir, bindex);
35321 + h_root = au_h_dptr(a->sb->s_root, bindex);
35322 + AuDebugOn(h_root != au_br_dentry(a->br));
35324 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35325 + wbr_wh_write_lock(wbr);
35326 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35329 + h_path.dentry = wbr->wbr_whbase;
35330 + h_path.mnt = au_br_mnt(a->br);
35331 + delegated = NULL;
35332 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35334 + if (unlikely(err == -EWOULDBLOCK)) {
35335 + pr_warn("cannot retry for NFSv4 delegation"
35336 + " for an internal unlink\n");
35340 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35343 + dput(wbr->wbr_whbase);
35344 + wbr->wbr_whbase = NULL;
35346 + err = au_wh_init(a->br, a->sb);
35347 + wbr_wh_write_unlock(wbr);
35348 + au_hn_inode_unlock(hdir);
35349 + di_read_unlock(a->sb->s_root, AuLock_IR);
35351 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35355 + atomic_dec(&wbr->wbr_wh_running);
35356 + au_lcnt_dec(&a->br->br_count);
35357 + si_write_unlock(a->sb);
35358 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35360 + if (unlikely(err))
35361 + AuIOErr("err %d\n", err);
35364 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35366 + int do_dec, wkq_err;
35367 + struct reinit_br_wh *arg;
35370 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35373 + /* ignore ENOMEM */
35374 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35377 + * dec(wh_running), kfree(arg) and dec(br_count)
35378 + * in reinit function
35382 + au_lcnt_inc(&br->br_count);
35383 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35384 + if (unlikely(wkq_err)) {
35385 + atomic_dec(&br->br_wbr->wbr_wh_running);
35386 + au_lcnt_dec(&br->br_count);
35387 + au_kfree_rcu(arg);
35394 + atomic_dec(&br->br_wbr->wbr_wh_running);
35397 +/* ---------------------------------------------------------------------- */
35400 + * create the whiteout @wh.
35402 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35403 + struct dentry *wh)
35406 + struct path h_path = {
35409 + struct au_branch *br;
35410 + struct au_wbr *wbr;
35411 + struct dentry *h_parent;
35412 + struct inode *h_dir, *delegated;
35414 + h_parent = wh->d_parent; /* dir inode is locked */
35415 + h_dir = d_inode(h_parent);
35416 + IMustLock(h_dir);
35418 + br = au_sbr(sb, bindex);
35419 + h_path.mnt = au_br_mnt(br);
35420 + wbr = br->br_wbr;
35421 + wbr_wh_read_lock(wbr);
35422 + if (wbr->wbr_whbase) {
35423 + delegated = NULL;
35424 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35425 + if (unlikely(err == -EWOULDBLOCK)) {
35426 + pr_warn("cannot retry for NFSv4 delegation"
35427 + " for an internal link\n");
35430 + if (!err || err != -EMLINK)
35433 + /* link count full. re-initialize br_whbase. */
35434 + kick_reinit_br_wh(sb, br);
35437 + /* return this error in this context */
35438 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35440 + au_fhsm_wrote(sb, bindex, /*force*/0);
35443 + wbr_wh_read_unlock(wbr);
35447 +/* ---------------------------------------------------------------------- */
35450 + * create or remove the diropq.
35452 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35453 + unsigned int flags)
35455 + struct dentry *opq_dentry;
35456 + struct super_block *sb;
35457 + struct au_branch *br;
35458 + struct path h_path;
35461 + sb = dentry->d_sb;
35462 + br = au_sbr(sb, bindex);
35463 + h_path.dentry = au_h_dptr(dentry, bindex);
35464 + h_path.mnt = au_br_mnt(br);
35465 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35466 + if (IS_ERR(opq_dentry))
35469 + if (au_ftest_diropq(flags, CREATE)) {
35470 + err = link_or_create_wh(sb, bindex, opq_dentry);
35472 + au_set_dbdiropq(dentry, bindex);
35473 + goto out; /* success */
35476 + h_path.dentry = opq_dentry;
35477 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35479 + au_set_dbdiropq(dentry, -1);
35481 + dput(opq_dentry);
35482 + opq_dentry = ERR_PTR(err);
35485 + return opq_dentry;
35488 +struct do_diropq_args {
35489 + struct dentry **errp;
35490 + struct dentry *dentry;
35491 + aufs_bindex_t bindex;
35492 + unsigned int flags;
35495 +static void call_do_diropq(void *args)
35497 + struct do_diropq_args *a = args;
35498 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35501 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35502 + unsigned int flags)
35504 + struct dentry *diropq, *h_dentry;
35505 + struct user_namespace *h_userns;
35507 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35508 + h_dentry = au_h_dptr(dentry, bindex);
35509 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35510 + MAY_EXEC | MAY_WRITE))
35511 + diropq = do_diropq(dentry, bindex, flags);
35514 + struct do_diropq_args args = {
35516 + .dentry = dentry,
35517 + .bindex = bindex,
35521 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35522 + if (unlikely(wkq_err))
35523 + diropq = ERR_PTR(wkq_err);
35529 +/* ---------------------------------------------------------------------- */
35532 + * lookup whiteout dentry.
35533 + * @h_parent: lower parent dentry which must exist and be locked
35534 + * @base_name: name of dentry which will be whiteouted
35535 + * returns dentry for whiteout.
35537 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35538 + struct au_branch *br)
35541 + struct qstr wh_name;
35542 + struct dentry *wh_dentry;
35543 + struct path h_path;
35545 + err = au_wh_name_alloc(&wh_name, base_name);
35546 + wh_dentry = ERR_PTR(err);
35548 + h_path.dentry = h_parent;
35549 + h_path.mnt = au_br_mnt(br);
35550 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35551 + au_kfree_try_rcu(wh_name.name);
35553 + return wh_dentry;
35557 + * link/create a whiteout for @dentry on @bindex.
35559 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35560 + struct dentry *h_parent)
35562 + struct dentry *wh_dentry;
35563 + struct super_block *sb;
35566 + sb = dentry->d_sb;
35567 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35568 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35569 + err = link_or_create_wh(sb, bindex, wh_dentry);
35571 + au_set_dbwh(dentry, bindex);
35572 + au_fhsm_wrote(sb, bindex, /*force*/0);
35575 + wh_dentry = ERR_PTR(err);
35579 + return wh_dentry;
35582 +/* ---------------------------------------------------------------------- */
35584 +/* Delete all whiteouts in this directory on branch bindex. */
35585 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35586 + aufs_bindex_t bindex)
35589 + unsigned long ul, n;
35590 + struct qstr wh_name;
35592 + struct hlist_head *head;
35593 + struct au_vdir_wh *pos;
35594 + struct au_vdir_destr *str;
35597 + p = (void *)__get_free_page(GFP_NOFS);
35598 + wh_name.name = p;
35599 + if (unlikely(!wh_name.name))
35603 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35604 + p += AUFS_WH_PFX_LEN;
35605 + n = whlist->nh_num;
35606 + head = whlist->nh_head;
35607 + for (ul = 0; !err && ul < n; ul++, head++) {
35608 + hlist_for_each_entry(pos, head, wh_hash) {
35609 + if (pos->wh_bindex != bindex)
35612 + str = &pos->wh_str;
35613 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35614 + memcpy(p, str->name, str->len);
35615 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35616 + err = unlink_wh_name(h_path, &wh_name);
35621 + AuIOErr("whiteout name too long %.*s\n",
35622 + str->len, str->name);
35627 + free_page((unsigned long)wh_name.name);
35633 +struct del_wh_children_args {
35635 + struct path *h_path;
35636 + struct au_nhash *whlist;
35637 + aufs_bindex_t bindex;
35640 +static void call_del_wh_children(void *args)
35642 + struct del_wh_children_args *a = args;
35643 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35646 +/* ---------------------------------------------------------------------- */
35648 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35650 + struct au_whtmp_rmdir *whtmp;
35652 + unsigned int rdhash;
35654 + SiMustAnyLock(sb);
35656 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35657 + if (unlikely(!whtmp)) {
35658 + whtmp = ERR_PTR(-ENOMEM);
35662 + /* no estimation for dir size */
35663 + rdhash = au_sbi(sb)->si_rdhash;
35665 + rdhash = AUFS_RDHASH_DEF;
35666 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35667 + if (unlikely(err)) {
35668 + au_kfree_rcu(whtmp);
35669 + whtmp = ERR_PTR(err);
35676 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35679 + au_lcnt_dec(&whtmp->br->br_count);
35680 + dput(whtmp->wh_dentry);
35681 + iput(whtmp->dir);
35682 + au_nhash_wh_free(&whtmp->whlist);
35683 + au_kfree_rcu(whtmp);
35687 + * rmdir the whiteouted temporary named dir @h_dentry.
35688 + * @whlist: whiteouted children.
35690 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35691 + struct dentry *wh_dentry, struct au_nhash *whlist)
35694 + unsigned int h_nlink;
35695 + struct path wh_path;
35696 + struct inode *wh_inode, *h_dir;
35697 + struct au_branch *br;
35698 + struct user_namespace *h_userns;
35700 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35701 + IMustLock(h_dir);
35703 + br = au_sbr(dir->i_sb, bindex);
35704 + wh_path.dentry = wh_dentry;
35705 + wh_path.mnt = au_br_mnt(br);
35706 + h_userns = au_br_userns(br);
35707 + wh_inode = d_inode(wh_dentry);
35708 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35711 + * someone else might change some whiteouts while we were sleeping.
35712 + * it means this whlist may have an obsoleted entry.
35714 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
35715 + err = del_wh_children(&wh_path, whlist, bindex);
35718 + struct del_wh_children_args args = {
35720 + .h_path = &wh_path,
35721 + .whlist = whlist,
35725 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35726 + if (unlikely(wkq_err))
35729 + inode_unlock(wh_inode);
35732 + h_nlink = h_dir->i_nlink;
35733 + err = vfsub_rmdir(h_dir, &wh_path);
35734 + /* some fs doesn't change the parent nlink in some cases */
35735 + h_nlink -= h_dir->i_nlink;
35739 + if (au_ibtop(dir) == bindex) {
35740 + /* todo: dir->i_mutex is necessary */
35741 + au_cpup_attr_timesizes(dir);
35743 + vfsub_drop_nlink(dir);
35745 + return 0; /* success */
35748 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35752 +static void call_rmdir_whtmp(void *args)
35755 + aufs_bindex_t bindex;
35756 + struct au_whtmp_rmdir *a = args;
35757 + struct super_block *sb;
35758 + struct dentry *h_parent;
35759 + struct inode *h_dir;
35760 + struct au_hinode *hdir;
35762 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35763 + /* inode_lock(a->dir); */
35765 + sb = a->dir->i_sb;
35766 + si_read_lock(sb, !AuLock_FLUSH);
35767 + if (!au_br_writable(a->br->br_perm))
35769 + bindex = au_br_index(sb, a->br->br_id);
35770 + if (unlikely(bindex < 0))
35774 + ii_write_lock_parent(a->dir);
35775 + h_parent = dget_parent(a->wh_dentry);
35776 + h_dir = d_inode(h_parent);
35777 + hdir = au_hi(a->dir, bindex);
35778 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35779 + if (unlikely(err))
35781 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35782 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35785 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35786 + au_hn_inode_unlock(hdir);
35787 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35791 + ii_write_unlock(a->dir);
35793 + /* inode_unlock(a->dir); */
35794 + au_whtmp_rmdir_free(a);
35795 + si_read_unlock(sb);
35796 + au_nwt_done(&au_sbi(sb)->si_nowait);
35797 + if (unlikely(err))
35798 + AuIOErr("err %d\n", err);
35801 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35802 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35805 + struct super_block *sb;
35809 + /* all post-process will be done in do_rmdir_whtmp(). */
35811 + args->dir = au_igrab(dir);
35812 + args->br = au_sbr(sb, bindex);
35813 + au_lcnt_inc(&args->br->br_count);
35814 + args->wh_dentry = dget(wh_dentry);
35815 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35816 + if (unlikely(wkq_err)) {
35817 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35818 + au_whtmp_rmdir_free(args);
35821 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35822 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35823 +++ linux/fs/aufs/whout.h 2021-12-03 15:40:58.236647297 +0100
35825 +/* SPDX-License-Identifier: GPL-2.0 */
35827 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35829 + * This program, aufs is free software; you can redistribute it and/or modify
35830 + * it under the terms of the GNU General Public License as published by
35831 + * the Free Software Foundation; either version 2 of the License, or
35832 + * (at your option) any later version.
35834 + * This program is distributed in the hope that it will be useful,
35835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35837 + * GNU General Public License for more details.
35839 + * You should have received a copy of the GNU General Public License
35840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35844 + * whiteout for logical deletion and opaque directory
35847 +#ifndef __AUFS_WHOUT_H__
35848 +#define __AUFS_WHOUT_H__
35855 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35856 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35857 + struct qstr *wh_name, int try_sio);
35858 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
35860 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35861 + struct qstr *prefix);
35862 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35863 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35864 + struct dentry *dentry);
35865 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35867 +/* diropq flags */
35868 +#define AuDiropq_CREATE 1
35869 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35870 +#define au_fset_diropq(flags, name) \
35871 + do { (flags) |= AuDiropq_##name; } while (0)
35872 +#define au_fclr_diropq(flags, name) \
35873 + do { (flags) &= ~AuDiropq_##name; } while (0)
35875 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35876 + unsigned int flags);
35877 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35878 + struct au_branch *br);
35879 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35880 + struct dentry *h_parent);
35882 +/* real rmdir for the whiteout-ed dir */
35883 +struct au_whtmp_rmdir {
35884 + struct inode *dir;
35885 + struct au_branch *br;
35886 + struct dentry *wh_dentry;
35887 + struct au_nhash whlist;
35890 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35891 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35892 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35893 + struct dentry *wh_dentry, struct au_nhash *whlist);
35894 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35895 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35897 +/* ---------------------------------------------------------------------- */
35899 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35900 + aufs_bindex_t bindex)
35902 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35905 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35907 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35910 +#endif /* __KERNEL__ */
35911 +#endif /* __AUFS_WHOUT_H__ */
35912 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35913 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35914 +++ linux/fs/aufs/wkq.c 2021-12-03 15:38:59.943313977 +0100
35916 +// SPDX-License-Identifier: GPL-2.0
35918 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35920 + * This program, aufs is free software; you can redistribute it and/or modify
35921 + * it under the terms of the GNU General Public License as published by
35922 + * the Free Software Foundation; either version 2 of the License, or
35923 + * (at your option) any later version.
35925 + * This program is distributed in the hope that it will be useful,
35926 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35927 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35928 + * GNU General Public License for more details.
35930 + * You should have received a copy of the GNU General Public License
35931 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35935 + * workqueue for asynchronous/super-io operations
35936 + * todo: try new credential scheme
35939 +#include <linux/module.h>
35942 +/* internal workqueue named AUFS_WKQ_NAME */
35944 +static struct workqueue_struct *au_wkq;
35946 +struct au_wkinfo {
35947 + struct work_struct wk;
35948 + struct kobject *kobj;
35950 + unsigned int flags; /* see wkq.h */
35952 + au_wkq_func_t func;
35955 +#ifdef CONFIG_LOCKDEP
35957 + struct held_lock **hlock;
35960 + struct completion *comp;
35963 +/* ---------------------------------------------------------------------- */
35965 + * Aufs passes some operations to the workqueue such as the internal copyup.
35966 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35967 + * job run by workqueue depends upon the locks acquired in the other task.
35968 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35969 + * information too. And the job in the workqueue restores the info in order to
35970 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35971 + * correctly and expectedly.
35974 +#ifndef CONFIG_LOCKDEP
35975 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35976 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35977 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35978 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35979 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35981 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35983 + wkinfo->hlock = NULL;
35984 + wkinfo->dont_check = 0;
35991 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35993 + static DEFINE_SPINLOCK(spin);
35996 + struct lock_class_key *key;
35998 + { .name = "&sbinfo->si_rwsem" },
35999 + { .name = "&finfo->fi_rwsem" },
36000 + { .name = "&dinfo->di_rwsem" },
36001 + { .name = "&iinfo->ii_rwsem" }
36006 + /* lockless read from 'set.' see below */
36007 + if (set == ARRAY_SIZE(a)) {
36008 + for (i = 0; i < ARRAY_SIZE(a); i++)
36009 + if (a[i].key == key)
36014 + spin_lock(&spin);
36016 + for (i = 0; i < ARRAY_SIZE(a); i++)
36017 + if (a[i].key == key) {
36018 + spin_unlock(&spin);
36021 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36023 + if (unlikely(a[i].key == key)) { /* rare but possible */
36024 + spin_unlock(&spin);
36029 + if (strstr(a[i].name, name)) {
36031 + * the order of these three lines is important for the
36032 + * lockless read above.
36035 + spin_unlock(&spin);
36037 + /* AuDbg("%d, %s\n", set, name); */
36041 + spin_unlock(&spin);
36050 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36053 + struct task_struct *curr;
36054 + struct held_lock **hl, *held_locks, *p;
36058 + wkinfo->dont_check = lockdep_recursing(curr);
36059 + if (wkinfo->dont_check)
36061 + n = curr->lockdep_depth;
36066 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36067 + if (unlikely(!wkinfo->hlock))
36071 +#if 0 /* left for debugging */
36072 + if (0 && au_debug_test())
36073 + lockdep_print_held_locks(curr);
36075 + held_locks = curr->held_locks;
36076 + hl = wkinfo->hlock;
36078 + p = held_locks++;
36079 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36088 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36090 + au_kfree_try_rcu(wkinfo->hlock);
36093 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36095 + struct held_lock *p, **hl = wkinfo->hlock;
36098 + if (wkinfo->dont_check)
36102 + while ((p = *hl++)) { /* assignment */
36103 + subclass = lockdep_hlock_class(p)->subclass;
36104 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36106 + rwsem_acquire_read(p->instance, subclass, 0,
36107 + /*p->acquire_ip*/_RET_IP_);
36109 + rwsem_acquire(p->instance, subclass, 0,
36110 + /*p->acquire_ip*/_RET_IP_);
36114 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36116 + struct held_lock *p, **hl = wkinfo->hlock;
36118 + if (wkinfo->dont_check)
36122 + while ((p = *hl++)) /* assignment */
36123 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36127 +static void wkq_func(struct work_struct *wk)
36129 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36131 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36132 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36134 + au_wkq_lockdep_pre(wkinfo);
36135 + wkinfo->func(wkinfo->args);
36136 + au_wkq_lockdep_post(wkinfo);
36137 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36138 + complete(wkinfo->comp);
36140 + kobject_put(wkinfo->kobj);
36141 + module_put(THIS_MODULE); /* todo: ?? */
36142 + au_kfree_rcu(wkinfo);
36147 + * Since struct completion is large, try allocating it dynamically.
36149 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36151 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36153 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36155 + init_completion(*comp);
36156 + wkinfo->comp = *comp;
36162 +static void au_wkq_comp_free(struct completion *comp)
36164 + au_kfree_rcu(comp);
36167 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36169 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36170 + if (au_wkq_test()) {
36171 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36172 + " due to a dead dir by UDBA,"
36173 + " or async xino write?\n");
36174 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36177 + au_dbg_verify_kthread();
36179 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36180 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36181 + queue_work(au_wkq, &wkinfo->wk);
36183 + INIT_WORK(&wkinfo->wk, wkq_func);
36184 + schedule_work(&wkinfo->wk);
36189 + * Be careful. It is easy to make deadlock happen.
36190 + * processA: lock, wkq and wait
36191 + * processB: wkq and wait, lock in wkq
36194 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36197 + AuWkqCompDeclare(comp);
36198 + struct au_wkinfo wkinfo = {
36204 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36205 + if (unlikely(err))
36207 + err = au_wkq_lockdep_alloc(&wkinfo);
36208 + if (unlikely(err))
36211 + au_wkq_run(&wkinfo);
36212 + /* no timeout, no interrupt */
36213 + wait_for_completion(wkinfo.comp);
36215 + au_wkq_lockdep_free(&wkinfo);
36218 + au_wkq_comp_free(comp);
36220 + destroy_work_on_stack(&wkinfo.wk);
36225 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36226 + * problem in a concurrent umounting.
36228 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36229 + unsigned int flags)
36232 + struct au_wkinfo *wkinfo;
36234 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36237 + * wkq_func() must free this wkinfo.
36238 + * it highly depends upon the implementation of workqueue.
36241 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36243 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36244 + wkinfo->flags = flags & ~AuWkq_WAIT;
36245 + wkinfo->func = func;
36246 + wkinfo->args = args;
36247 + wkinfo->comp = NULL;
36248 + au_wkq_lockdep_init(wkinfo);
36249 + kobject_get(wkinfo->kobj);
36250 + __module_get(THIS_MODULE); /* todo: ?? */
36252 + au_wkq_run(wkinfo);
36255 + au_nwt_done(&au_sbi(sb)->si_nowait);
36261 +/* ---------------------------------------------------------------------- */
36263 +void au_nwt_init(struct au_nowait_tasks *nwt)
36265 + atomic_set(&nwt->nw_len, 0);
36266 + /* smp_mb(); */ /* atomic_set */
36267 + init_waitqueue_head(&nwt->nw_wq);
36270 +void au_wkq_fin(void)
36272 + destroy_workqueue(au_wkq);
36275 +int __init au_wkq_init(void)
36280 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36281 + if (IS_ERR(au_wkq))
36282 + err = PTR_ERR(au_wkq);
36283 + else if (!au_wkq)
36288 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36289 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36290 +++ linux/fs/aufs/wkq.h 2021-12-03 15:38:59.943313977 +0100
36292 +/* SPDX-License-Identifier: GPL-2.0 */
36294 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36296 + * This program, aufs is free software; you can redistribute it and/or modify
36297 + * it under the terms of the GNU General Public License as published by
36298 + * the Free Software Foundation; either version 2 of the License, or
36299 + * (at your option) any later version.
36301 + * This program is distributed in the hope that it will be useful,
36302 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36303 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36304 + * GNU General Public License for more details.
36306 + * You should have received a copy of the GNU General Public License
36307 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36311 + * workqueue for asynchronous/super-io operations
36312 + * todo: try new credentials management scheme
36315 +#ifndef __AUFS_WKQ_H__
36316 +#define __AUFS_WKQ_H__
36320 +#include <linux/wait.h>
36322 +struct super_block;
36324 +/* ---------------------------------------------------------------------- */
36327 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36329 +struct au_nowait_tasks {
36331 + wait_queue_head_t nw_wq;
36334 +/* ---------------------------------------------------------------------- */
36336 +typedef void (*au_wkq_func_t)(void *args);
36339 +#define AuWkq_WAIT 1
36340 +#define AuWkq_NEST (1 << 1)
36341 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36342 +#define au_fset_wkq(flags, name) \
36343 + do { (flags) |= AuWkq_##name; } while (0)
36344 +#define au_fclr_wkq(flags, name) \
36345 + do { (flags) &= ~AuWkq_##name; } while (0)
36348 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36349 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36350 + unsigned int flags);
36351 +void au_nwt_init(struct au_nowait_tasks *nwt);
36352 +int __init au_wkq_init(void);
36353 +void au_wkq_fin(void);
36355 +/* ---------------------------------------------------------------------- */
36357 +static inline int au_wkq_test(void)
36359 + return current->flags & PF_WQ_WORKER;
36362 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36364 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36367 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36369 + if (atomic_dec_and_test(&nwt->nw_len))
36370 + wake_up_all(&nwt->nw_wq);
36373 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36375 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36379 +#endif /* __KERNEL__ */
36380 +#endif /* __AUFS_WKQ_H__ */
36381 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36382 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36383 +++ linux/fs/aufs/xattr.c 2021-12-03 15:40:58.236647297 +0100
36385 +// SPDX-License-Identifier: GPL-2.0
36387 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36389 + * This program, aufs is free software; you can redistribute it and/or modify
36390 + * it under the terms of the GNU General Public License as published by
36391 + * the Free Software Foundation; either version 2 of the License, or
36392 + * (at your option) any later version.
36394 + * This program is distributed in the hope that it will be useful,
36395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36397 + * GNU General Public License for more details.
36399 + * You should have received a copy of the GNU General Public License
36400 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36404 + * handling xattr functions
36407 +#include <linux/fs.h>
36408 +#include <linux/posix_acl_xattr.h>
36409 +#include <linux/xattr.h>
36412 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36414 + if (!ignore_flags)
36422 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36427 +#define cmp(brattr, prefix) do { \
36428 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36429 + XATTR_##prefix##_PREFIX_LEN)) { \
36430 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36436 + cmp(SEC, SECURITY);
36437 + cmp(SYS, SYSTEM);
36438 + cmp(TR, TRUSTED);
36442 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36449 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36451 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36452 + char *name, char **buf, unsigned int ignore_flags,
36453 + unsigned int verbose)
36457 + struct inode *h_idst;
36458 + struct dentry *h_dst_dentry, *h_src_dentry;
36459 + struct user_namespace *h_dst_userns, *h_src_userns;
36461 + h_src_userns = mnt_user_ns(h_src->mnt);
36462 + h_src_dentry = h_src->dentry;
36463 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36466 + if (unlikely(err <= 0)) {
36467 + if (err == -ENODATA
36468 + || (err == -EOPNOTSUPP
36469 + && ((ignore_flags & au_xattr_out_of_list)
36470 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36471 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36473 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36476 + if (err && (verbose || au_debug_test()))
36477 + pr_err("%s, err %d\n", name, err);
36481 + /* unlock it temporary */
36482 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36483 + h_dst_dentry = h_dst->dentry;
36484 + h_idst = d_inode(h_dst_dentry);
36485 + inode_unlock(h_idst);
36486 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36488 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36489 + if (unlikely(err)) {
36490 + if (verbose || au_debug_test())
36491 + pr_err("%s, err %d\n", name, err);
36492 + err = au_xattr_ignore(err, name, ignore_flags);
36499 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36500 + unsigned int verbose)
36502 + int err, unlocked, acl_access, acl_default;
36504 + struct dentry *h_dst_dentry, *h_src_dentry;
36505 + struct inode *h_isrc, *h_idst;
36506 + char *value, *p, *o, *e;
36508 + /* try stopping to update the source inode while we are referencing */
36509 + /* there should not be the parent-child relationship between them */
36510 + h_dst_dentry = h_dst->dentry;
36511 + h_idst = d_inode(h_dst_dentry);
36512 + h_src_dentry = h_src->dentry;
36513 + h_isrc = d_inode(h_src_dentry);
36514 + inode_unlock(h_idst);
36515 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36516 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36519 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36520 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36522 + if (unlikely(err < 0)) {
36524 + if (err == -ENODATA
36525 + || err == -EOPNOTSUPP)
36526 + err = 0; /* ignore */
36535 + p = kmalloc(ssz, GFP_NOFS);
36537 + if (unlikely(!p))
36539 + err = vfs_listxattr(h_src_dentry, p, ssz);
36541 + inode_unlock_shared(h_isrc);
36543 + AuDbg("err %d, ssz %zd\n", err, ssz);
36544 + if (unlikely(err < 0))
36552 + while (!err && p < e) {
36553 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36554 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36555 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36556 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36558 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36560 + p += strlen(p) + 1;
36563 + ignore_flags |= au_xattr_out_of_list;
36564 + if (!err && !acl_access) {
36565 + err = au_do_cpup_xattr(h_dst, h_src,
36566 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36567 + ignore_flags, verbose);
36570 + if (!err && !acl_default) {
36571 + err = au_do_cpup_xattr(h_dst, h_src,
36572 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36573 + ignore_flags, verbose);
36577 + au_kfree_try_rcu(value);
36580 + au_kfree_try_rcu(o);
36583 + inode_unlock_shared(h_isrc);
36588 +/* ---------------------------------------------------------------------- */
36590 +static int au_smack_reentering(struct super_block *sb)
36592 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36594 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36595 + * i_op->getxattr(). ouch.
36597 + return si_pid_test(sb);
36608 +struct au_lgxattr {
36616 + const char *name;
36623 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36624 + struct au_lgxattr *arg)
36628 + struct path h_path;
36629 + struct super_block *sb;
36631 + sb = dentry->d_sb;
36632 + reenter = au_smack_reentering(sb);
36634 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36635 + if (unlikely(err))
36638 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36639 + if (unlikely(err))
36641 + if (unlikely(!h_path.dentry))
36642 + /* illegally overlapped or something */
36643 + goto out_di; /* pretending success */
36645 + /* always topmost entry only */
36646 + switch (arg->type) {
36647 + case AU_XATTR_LIST:
36648 + err = vfs_listxattr(h_path.dentry,
36649 + arg->u.list.list, arg->u.list.size);
36651 + case AU_XATTR_GET:
36652 + AuDebugOn(d_is_negative(h_path.dentry));
36653 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36654 + arg->u.get.name, arg->u.get.value,
36655 + arg->u.get.size);
36661 + di_read_unlock(dentry, AuLock_IR);
36664 + si_read_unlock(sb);
36670 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36672 + struct au_lgxattr arg = {
36673 + .type = AU_XATTR_LIST,
36680 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36683 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36684 + const char *name, void *value, size_t size)
36686 + struct au_lgxattr arg = {
36687 + .type = AU_XATTR_GET,
36695 + return au_lgxattr(dentry, inode, &arg);
36698 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36699 + const char *name, const void *value, size_t size,
36702 + struct au_sxattr arg = {
36703 + .type = AU_XATTR_SET,
36712 + return au_sxattr(dentry, inode, &arg);
36715 +/* ---------------------------------------------------------------------- */
36717 +static int au_xattr_get(const struct xattr_handler *handler,
36718 + struct dentry *dentry, struct inode *inode,
36719 + const char *name, void *buffer, size_t size)
36721 + return au_getxattr(dentry, inode, name, buffer, size);
36724 +static int au_xattr_set(const struct xattr_handler *handler,
36725 + struct user_namespace *userns,
36726 + struct dentry *dentry, struct inode *inode,
36727 + const char *name, const void *value, size_t size,
36730 + return au_setxattr(dentry, inode, name, value, size, flags);
36733 +static const struct xattr_handler au_xattr_handler = {
36736 + .get = au_xattr_get,
36737 + .set = au_xattr_set
36740 +static const struct xattr_handler *au_xattr_handlers[] = {
36741 +#ifdef CONFIG_FS_POSIX_ACL
36742 + &posix_acl_access_xattr_handler,
36743 + &posix_acl_default_xattr_handler,
36745 + &au_xattr_handler, /* must be last */
36749 +void au_xattr_init(struct super_block *sb)
36751 + sb->s_xattr = au_xattr_handlers;
36753 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36754 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36755 +++ linux/fs/aufs/xino.c 2021-12-03 15:40:58.236647297 +0100
36757 +// SPDX-License-Identifier: GPL-2.0
36759 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36761 + * This program, aufs is free software; you can redistribute it and/or modify
36762 + * it under the terms of the GNU General Public License as published by
36763 + * the Free Software Foundation; either version 2 of the License, or
36764 + * (at your option) any later version.
36766 + * This program is distributed in the hope that it will be useful,
36767 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36768 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36769 + * GNU General Public License for more details.
36771 + * You should have received a copy of the GNU General Public License
36772 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36776 + * external inode number translation table and bitmap
36778 + * things to consider
36780 + * + au_xino object
36781 + * + XINO files (xino, xib, xigen)
36782 + * + dynamic debugfs entries (xiN)
36783 + * + static debugfs entries (xib, xigen)
36784 + * + static sysfs entry (xi_path)
36785 + * - several entry points to handle them.
36786 + * + mount(2) without xino option (default)
36787 + * + mount(2) with xino option
36788 + * + mount(2) with noxino option
36790 + * + remount with add/del branches
36791 + * + remount with xino/noxino options
36794 +#include <linux/seq_file.h>
36795 +#include <linux/statfs.h>
36798 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36799 + aufs_bindex_t bbot,
36800 + struct super_block *h_sb)
36802 + /* todo: try binary-search if the branches are many */
36803 + for (; btop <= bbot; btop++)
36804 + if (h_sb == au_sbr_sb(sb, btop))
36810 + * find another branch who is on the same filesystem of the specified
36811 + * branch{@btgt}. search until @bbot.
36813 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36814 + aufs_bindex_t bbot)
36816 + aufs_bindex_t bindex;
36817 + struct super_block *tgt_sb;
36819 + tgt_sb = au_sbr_sb(sb, btgt);
36820 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36822 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36827 +/* ---------------------------------------------------------------------- */
36830 + * stop unnecessary notify events at creating xino files
36833 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36835 + aufs_bindex_t bfound, bindex, bbot;
36836 + struct dentry *parent;
36837 + struct au_branch *br;
36840 + parent = dentry->d_parent; /* safe d_parent access */
36841 + bbot = au_sbbot(sb);
36842 + for (bindex = 0; bindex <= bbot; bindex++) {
36843 + br = au_sbr(sb, bindex);
36844 + if (au_br_dentry(br) == parent) {
36850 + AuDbg("bfound b%d\n", bfound);
36854 +struct au_xino_lock_dir {
36855 + struct au_hinode *hdir;
36856 + struct dentry *parent;
36857 + struct inode *dir;
36860 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36861 + unsigned int lsc)
36863 + struct dentry *parent;
36864 + struct inode *dir;
36866 + parent = dget_parent(dentry);
36867 + dir = d_inode(parent);
36868 + inode_lock_nested(dir, lsc);
36869 +#if 0 /* it should not happen */
36870 + spin_lock(&dentry->d_lock);
36871 + if (unlikely(dentry->d_parent != parent)) {
36872 + spin_unlock(&dentry->d_lock);
36873 + inode_unlock(dir);
36878 + spin_unlock(&dentry->d_lock);
36885 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36886 + struct au_xino_lock_dir *ldir)
36888 + aufs_bindex_t bindex;
36890 + ldir->hdir = NULL;
36891 + bindex = au_xi_root(sb, xipath->dentry);
36892 + if (bindex >= 0) {
36893 + /* rw branch root */
36894 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36895 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36898 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36900 + ldir->dir = d_inode(ldir->parent);
36904 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36907 + au_hn_inode_unlock(ldir->hdir);
36909 + inode_unlock(ldir->dir);
36910 + dput(ldir->parent);
36914 +/* ---------------------------------------------------------------------- */
36917 + * create and set a new xino file
36919 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36922 + struct file *file;
36923 + struct dentry *h_parent, *d;
36924 + struct inode *h_dir, *inode;
36926 + static DEFINE_MUTEX(mtx);
36929 + * at mount-time, and the xino file is the default path,
36930 + * hnotify is disabled so we have no notify events to ignore.
36931 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36934 + mutex_lock(&mtx);
36935 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36936 + /* | __FMODE_NONOTIFY */,
36938 + if (IS_ERR(file)) {
36940 + mutex_unlock(&mtx);
36942 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36946 + /* keep file count */
36948 + d = file->f_path.dentry;
36949 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36951 + mutex_unlock(&mtx);
36952 + /* mnt_want_write() is unnecessary here */
36953 + h_dir = d_inode(h_parent);
36954 + inode = file_inode(file);
36955 + /* no delegation since it is just created */
36956 + if (inode->i_nlink)
36957 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36959 + inode_unlock(h_dir);
36961 + if (unlikely(err)) {
36963 + pr_err("unlink %s(%d)\n", fpath, err);
36968 + if (unlikely(sb == d->d_sb)) {
36970 + pr_err("%s must be outside\n", fpath);
36973 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36975 + pr_err("xino doesn't support %s(%s)\n",
36976 + fpath, au_sbtype(d->d_sb));
36979 + return file; /* success */
36983 + file = ERR_PTR(err);
36988 + * create a new xinofile at the same place/path as @base.
36990 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36991 + struct file *copy_src)
36993 + struct file *file;
36994 + struct dentry *dentry;
36995 + struct inode *dir, *delegated;
36996 + struct qstr *name;
36997 + struct path ppath, path;
36998 + int err, do_unlock;
36999 + struct au_xino_lock_dir ldir;
37002 + au_xino_lock_dir(sb, base, &ldir);
37003 + dentry = base->dentry;
37004 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37005 + ppath.mnt = base->mnt;
37006 + dir = d_inode(ppath.dentry);
37009 + name = &dentry->d_name;
37010 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37011 + if (IS_ERR(path.dentry)) {
37012 + file = (void *)path.dentry;
37013 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37017 + /* no need to mnt_want_write() since we call dentry_open() later */
37018 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37019 + if (unlikely(err)) {
37020 + file = ERR_PTR(err);
37021 + pr_err("%pd create err %d\n", dentry, err);
37025 + path.mnt = base->mnt;
37026 + file = vfsub_dentry_open(&path,
37027 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37028 + /* | __FMODE_NONOTIFY */);
37029 + if (IS_ERR(file)) {
37030 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37034 + delegated = NULL;
37035 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37036 + au_xino_unlock_dir(&ldir);
37038 + if (unlikely(err == -EWOULDBLOCK)) {
37039 + pr_warn("cannot retry for NFSv4 delegation"
37040 + " for an internal unlink\n");
37043 + if (unlikely(err)) {
37044 + pr_err("%pd unlink err %d\n", dentry, err);
37049 + /* no one can touch copy_src xino */
37050 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37051 + if (unlikely(err)) {
37052 + pr_err("%pd copy err %d\n", dentry, err);
37056 + goto out_dput; /* success */
37060 + file = ERR_PTR(err);
37062 + dput(path.dentry);
37065 + au_xino_unlock_dir(&ldir);
37069 +struct file *au_xino_file1(struct au_xino *xi)
37071 + struct file *file;
37072 + unsigned int u, nfile;
37075 + nfile = xi->xi_nfile;
37076 + for (u = 0; u < nfile; u++) {
37077 + file = xi->xi_file[u];
37085 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37096 + if (idx < xi->xi_nfile) {
37097 + f = xi->xi_file[idx];
37101 + p = au_kzrealloc(xi->xi_file,
37102 + sizeof(*xi->xi_file) * xi->xi_nfile,
37103 + sizeof(*xi->xi_file) * (idx + 1),
37104 + GFP_NOFS, /*may_shrink*/0);
37106 + MtxMustLock(&xi->xi_mtx);
37108 + xi->xi_nfile = idx + 1;
37116 + xi->xi_file[idx] = file;
37123 + * if @xinew->xi is not set, then create new xigen file.
37125 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37127 + struct file *file;
37130 + SiMustAnyLock(sb);
37132 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37133 + if (IS_ERR(file)) {
37134 + err = PTR_ERR(file);
37135 + pr_err("%s[%d], err %d\n",
37136 + xinew->xi ? "xino" : "xigen",
37137 + xinew->idx, err);
37142 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37145 + /* todo: make xigen file an array */
37146 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37149 + if (unlikely(err))
37150 + file = ERR_PTR(err);
37156 +/* ---------------------------------------------------------------------- */
37159 + * truncate xino files
37161 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37162 + int idx, struct kstatfs *st)
37166 + struct file *file, *new_xino;
37167 + struct au_xi_new xinew = {
37172 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37173 + file = au_xino_file(xinew.xi, idx);
37177 + xinew.base = &file->f_path;
37178 + err = vfs_statfs(xinew.base, st);
37179 + if (unlikely(err)) {
37180 + AuErr1("statfs err %d, ignored\n", err);
37185 + blocks = file_inode(file)->i_blocks;
37186 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37187 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37189 + xinew.copy_src = file;
37190 + new_xino = au_xi_new(sb, &xinew);
37191 + if (IS_ERR(new_xino)) {
37192 + err = PTR_ERR(new_xino);
37193 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37197 + err = vfs_statfs(&new_xino->f_path, st);
37199 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37200 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37201 + st->f_bfree, st->f_blocks);
37203 + AuErr1("statfs err %d, ignored\n", err);
37211 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37214 + unsigned long jiffy;
37215 + aufs_bindex_t bbot;
37216 + struct kstatfs *st;
37217 + struct au_branch *br;
37218 + struct au_xino *xi;
37221 + st = kmalloc(sizeof(*st), GFP_NOFS);
37222 + if (unlikely(!st))
37226 + bbot = au_sbbot(sb);
37227 + if (unlikely(bindex < 0 || bbot < bindex))
37232 + br = au_sbr(sb, bindex);
37233 + xi = br->br_xino;
37234 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37235 + err = au_xino_do_trunc(sb, bindex, i, st);
37237 + au_sbi(sb)->si_xino_jiffy = jiffy;
37240 + au_kfree_rcu(st);
37245 +struct xino_do_trunc_args {
37246 + struct super_block *sb;
37247 + struct au_branch *br;
37251 +static void xino_do_trunc(void *_args)
37253 + struct xino_do_trunc_args *args = _args;
37254 + struct super_block *sb;
37255 + struct au_branch *br;
37256 + struct inode *dir;
37258 + aufs_bindex_t bindex;
37262 + dir = d_inode(sb->s_root);
37266 + si_noflush_write_lock(sb);
37267 + ii_read_lock_parent(dir);
37268 + bindex = au_br_index(sb, br->br_id);
37269 + err = au_xino_trunc(sb, bindex, idx);
37270 + ii_read_unlock(dir);
37271 + if (unlikely(err))
37272 + pr_warn("err b%d, (%d)\n", bindex, err);
37273 + atomic_dec(&br->br_xino->xi_truncating);
37274 + au_lcnt_dec(&br->br_count);
37275 + si_write_unlock(sb);
37276 + au_nwt_done(&au_sbi(sb)->si_nowait);
37277 + au_kfree_rcu(args);
37281 + * returns the index in the xi_file array whose corresponding file is necessary
37282 + * to truncate, or -1 which means no need to truncate.
37284 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37288 + struct kstatfs st;
37289 + struct au_sbinfo *sbinfo;
37290 + struct au_xino *xi;
37291 + struct file *file;
37293 + /* todo: si_xino_expire and the ratio should be customizable */
37294 + sbinfo = au_sbi(sb);
37295 + if (time_before(jiffies,
37296 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37299 + /* truncation border */
37300 + xi = br->br_xino;
37301 + for (u = 0; u < xi->xi_nfile; u++) {
37302 + file = au_xino_file(xi, u);
37306 + err = vfs_statfs(&file->f_path, &st);
37307 + if (unlikely(err)) {
37308 + AuErr1("statfs err %d, ignored\n", err);
37311 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37312 + >= AUFS_XINO_DEF_TRUNC)
37319 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37322 + struct xino_do_trunc_args *args;
37325 + idx = xino_trunc_test(sb, br);
37329 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37332 + /* lock and kfree() will be called in trunc_xino() */
37333 + args = kmalloc(sizeof(*args), GFP_NOFS);
37334 + if (unlikely(!args)) {
37335 + AuErr1("no memory\n");
37339 + au_lcnt_inc(&br->br_count);
37343 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37345 + return; /* success */
37347 + pr_err("wkq %d\n", wkq_err);
37348 + au_lcnt_dec(&br->br_count);
37349 + au_kfree_rcu(args);
37352 + atomic_dec(&br->br_xino->xi_truncating);
37355 +/* ---------------------------------------------------------------------- */
37357 +struct au_xi_calc {
37362 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37363 + struct au_xi_calc *calc)
37367 + maxent = au_xi_maxent(sb);
37368 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37369 + calc->pos *= sizeof(ino_t);
37372 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37373 + struct au_xi_calc *calc)
37376 + struct file *file;
37377 + struct au_xino *xi = br->br_xino;
37378 + struct au_xi_new xinew = {
37382 + SiMustAnyLock(sb);
37388 + mutex_lock(&xi->xi_mtx);
37389 + file = au_xino_file(xi, calc->idx);
37393 + file = au_xino_file(xi, /*idx*/-1);
37394 + AuDebugOn(!file);
37395 + xinew.idx = calc->idx;
37396 + xinew.base = &file->f_path;
37397 + /* xinew.copy_src = NULL; */
37398 + file = au_xi_new(sb, &xinew);
37399 + if (IS_ERR(file))
37400 + err = PTR_ERR(file);
37403 + mutex_unlock(&xi->xi_mtx);
37408 +struct au_xino_do_new_async_args {
37409 + struct super_block *sb;
37410 + struct au_branch *br;
37411 + struct au_xi_calc calc;
37415 +struct au_xi_writing {
37416 + struct hlist_bl_node node;
37417 + ino_t h_ino, ino;
37420 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37423 +static void au_xino_call_do_new_async(void *args)
37425 + struct au_xino_do_new_async_args *a = args;
37426 + struct au_branch *br;
37427 + struct super_block *sb;
37428 + struct au_sbinfo *sbi;
37429 + struct inode *root;
37430 + struct file *file;
37431 + struct au_xi_writing *del, *p;
37432 + struct hlist_bl_head *hbl;
37433 + struct hlist_bl_node *pos;
37438 + sbi = au_sbi(sb);
37439 + si_noflush_read_lock(sb);
37440 + root = d_inode(sb->s_root);
37441 + ii_read_lock_child(root);
37442 + err = au_xino_do_new_async(sb, br, &a->calc);
37443 + if (unlikely(err)) {
37444 + AuIOErr("err %d\n", err);
37448 + file = au_xino_file(br->br_xino, a->calc.idx);
37449 + AuDebugOn(!file);
37450 + err = au_xino_do_write(file, &a->calc, a->ino);
37451 + if (unlikely(err)) {
37452 + AuIOErr("err %d\n", err);
37457 + hbl = &br->br_xino->xi_writing;
37458 + hlist_bl_lock(hbl);
37459 + au_hbl_for_each(pos, hbl) {
37460 + p = container_of(pos, struct au_xi_writing, node);
37461 + if (p->ino == a->ino) {
37463 + hlist_bl_del(&p->node);
37467 + hlist_bl_unlock(hbl);
37468 + au_kfree_rcu(del);
37471 + au_lcnt_dec(&br->br_count);
37472 + ii_read_unlock(root);
37473 + si_read_unlock(sb);
37474 + au_nwt_done(&sbi->si_nowait);
37479 + * create a new xino file asynchronously
37481 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37482 + struct au_xi_calc *calc, ino_t ino)
37485 + struct au_xino_do_new_async_args *arg;
37488 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37489 + if (unlikely(!arg))
37494 + arg->calc = *calc;
37496 + au_lcnt_inc(&br->br_count);
37497 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37498 + if (unlikely(err)) {
37499 + pr_err("wkq %d\n", err);
37500 + au_lcnt_dec(&br->br_count);
37501 + au_kfree_rcu(arg);
37509 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37510 + * at the position of @h_ino.
37512 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37517 + struct au_xi_calc calc;
37518 + struct au_sbinfo *sbinfo;
37519 + struct file *file;
37520 + struct au_xino *xi;
37521 + struct hlist_bl_head *hbl;
37522 + struct hlist_bl_node *pos;
37523 + struct au_xi_writing *p;
37526 + if (!au_opt_test(au_mntflags(sb), XINO))
37527 + return 0; /* no xino */
37530 + au_xi_calc(sb, h_ino, &calc);
37531 + xi = au_sbr(sb, bindex)->br_xino;
37532 + file = au_xino_file(xi, calc.idx);
37534 + hbl = &xi->xi_writing;
37535 + hlist_bl_lock(hbl);
37536 + au_hbl_for_each(pos, hbl) {
37537 + p = container_of(pos, struct au_xi_writing, node);
37538 + if (p->h_ino == h_ino) {
37539 + AuDbg("hi%llu, i%llu, found\n",
37540 + (u64)p->h_ino, (u64)p->ino);
37545 + hlist_bl_unlock(hbl);
37547 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37548 + return 0; /* no xino */
37550 + sbinfo = au_sbi(sb);
37551 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37552 + if (sz == sizeof(*ino))
37553 + return 0; /* success */
37556 + if (unlikely(sz >= 0)) {
37558 + AuIOErr("xino read error (%zd)\n", sz);
37563 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37568 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37569 + if (sz == sizeof(ino))
37570 + return 0; /* success */
37572 + AuIOErr("write failed (%zd)\n", sz);
37577 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37578 + * at the position of @h_ino.
37579 + * even if @ino is zero, it is written to the xinofile and means no entry.
37580 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37581 + * try truncating it.
37583 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37587 + unsigned int mnt_flags;
37588 + struct au_xi_calc calc;
37589 + struct file *file;
37590 + struct au_branch *br;
37591 + struct au_xino *xi;
37592 + struct au_xi_writing *p;
37594 + SiMustAnyLock(sb);
37596 + mnt_flags = au_mntflags(sb);
37597 + if (!au_opt_test(mnt_flags, XINO))
37600 + au_xi_calc(sb, h_ino, &calc);
37601 + br = au_sbr(sb, bindex);
37602 + xi = br->br_xino;
37603 + file = au_xino_file(xi, calc.idx);
37605 + /* store the inum pair into the list */
37606 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37607 + p->h_ino = h_ino;
37609 + au_hbl_add(&p->node, &xi->xi_writing);
37611 + /* create and write a new xino file asynchronously */
37612 + err = au_xino_new_async(sb, br, &calc, ino);
37614 + return 0; /* success */
37618 + err = au_xino_do_write(file, &calc, ino);
37620 + br = au_sbr(sb, bindex);
37621 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37622 + && au_test_fs_trunc_xino(au_br_sb(br)))
37623 + xino_try_trunc(sb, br);
37624 + return 0; /* success */
37628 + AuIOErr("write failed (%d)\n", err);
37632 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37635 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37636 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37640 + const int prevent_endless = 10;
37644 + err = vfsub_read_k(file, kbuf, size, pos);
37645 + if (err == -EINTR
37646 + && !au_wkq_test()
37647 + && fatal_signal_pending(current)) {
37648 + err = xino_fread_wkq(file, kbuf, size, pos);
37649 + BUG_ON(err == -EINTR);
37651 + } while (i++ < prevent_endless
37652 + && (err == -EAGAIN || err == -EINTR));
37654 +#if 0 /* reserved for future use */
37656 + fsnotify_access(file->f_path.dentry);
37662 +struct xino_fread_args {
37664 + struct file *file;
37670 +static void call_xino_fread(void *args)
37672 + struct xino_fread_args *a = args;
37673 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37676 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37681 + struct xino_fread_args args = {
37689 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37690 + if (unlikely(wkq_err))
37696 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37699 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37704 + const int prevent_endless = 10;
37708 + err = vfsub_write_k(file, kbuf, size, pos);
37709 + if (err == -EINTR
37710 + && !au_wkq_test()
37711 + && fatal_signal_pending(current)) {
37712 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37713 + BUG_ON(err == -EINTR);
37715 + } while (i++ < prevent_endless
37716 + && (err == -EAGAIN || err == -EINTR));
37718 +#if 0 /* reserved for future use */
37720 + fsnotify_modify(file->f_path.dentry);
37726 +struct do_xino_fwrite_args {
37728 + struct file *file;
37734 +static void call_do_xino_fwrite(void *args)
37736 + struct do_xino_fwrite_args *a = args;
37737 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37740 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37745 + struct do_xino_fwrite_args args = {
37754 + * it breaks RLIMIT_FSIZE and normal user's limit,
37755 + * users should care about quota and real 'filesystem full.'
37757 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37758 + if (unlikely(wkq_err))
37764 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37768 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37770 + err = do_xino_fwrite(file, buf, size, pos);
37774 + err = xino_fwrite_wkq(file, buf, size, pos);
37781 +/* ---------------------------------------------------------------------- */
37784 + * inode number bitmap
37786 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37787 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37791 + AuDebugOn(bit < 0 || page_bits <= bit);
37792 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37796 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37798 + AuDebugOn(ino < AUFS_FIRST_INO);
37799 + ino -= AUFS_FIRST_INO;
37800 + *pindex = ino / page_bits;
37801 + *bit = ino % page_bits;
37804 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37809 + struct au_sbinfo *sbinfo;
37810 + struct file *xib;
37811 + unsigned long *p;
37813 + sbinfo = au_sbi(sb);
37814 + MtxMustLock(&sbinfo->si_xib_mtx);
37815 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37816 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37818 + if (pindex == sbinfo->si_xib_last_pindex)
37821 + xib = sbinfo->si_xib;
37822 + p = sbinfo->si_xib_buf;
37823 + pos = sbinfo->si_xib_last_pindex;
37824 + pos *= PAGE_SIZE;
37825 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37826 + if (unlikely(sz != PAGE_SIZE))
37830 + pos *= PAGE_SIZE;
37831 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37832 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37834 + memset(p, 0, PAGE_SIZE);
37835 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37837 + if (sz == PAGE_SIZE) {
37838 + sbinfo->si_xib_last_pindex = pindex;
37839 + return 0; /* success */
37843 + AuIOErr1("write failed (%zd)\n", sz);
37850 +static void au_xib_clear_bit(struct inode *inode)
37853 + unsigned long pindex;
37854 + struct super_block *sb;
37855 + struct au_sbinfo *sbinfo;
37857 + AuDebugOn(inode->i_nlink);
37859 + sb = inode->i_sb;
37860 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37861 + AuDebugOn(page_bits <= bit);
37862 + sbinfo = au_sbi(sb);
37863 + mutex_lock(&sbinfo->si_xib_mtx);
37864 + err = xib_pindex(sb, pindex);
37866 + clear_bit(bit, sbinfo->si_xib_buf);
37867 + sbinfo->si_xib_next_bit = bit;
37869 + mutex_unlock(&sbinfo->si_xib_mtx);
37872 +/* ---------------------------------------------------------------------- */
37875 + * truncate a xino bitmap file
37879 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37883 + unsigned long pindex;
37884 + loff_t pos, pend;
37885 + struct au_sbinfo *sbinfo;
37887 + unsigned long *p;
37890 + sbinfo = au_sbi(sb);
37891 + MtxMustLock(&sbinfo->si_xib_mtx);
37892 + p = sbinfo->si_xib_buf;
37893 + pend = vfsub_f_size_read(file);
37895 + while (pos < pend) {
37896 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37898 + if (unlikely(sz <= 0))
37902 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37903 + if (unlikely(*ino < AUFS_FIRST_INO))
37906 + xib_calc_bit(*ino, &pindex, &bit);
37907 + AuDebugOn(page_bits <= bit);
37908 + err = xib_pindex(sb, pindex);
37920 +static int xib_restore(struct super_block *sb)
37923 + unsigned int nfile;
37924 + aufs_bindex_t bindex, bbot;
37926 + struct au_branch *br;
37927 + struct au_xino *xi;
37928 + struct file *file;
37931 + page = (void *)__get_free_page(GFP_NOFS);
37932 + if (unlikely(!page))
37936 + bbot = au_sbbot(sb);
37937 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37938 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37939 + br = au_sbr(sb, bindex);
37940 + xi = br->br_xino;
37941 + nfile = xi->xi_nfile;
37942 + for (i = 0; i < nfile; i++) {
37943 + file = au_xino_file(xi, i);
37945 + err = do_xib_restore(sb, file, page);
37948 + AuDbg("skip shared b%d\n", bindex);
37949 + free_page((unsigned long)page);
37955 +int au_xib_trunc(struct super_block *sb)
37960 + struct au_sbinfo *sbinfo;
37961 + unsigned long *p;
37962 + struct file *file;
37964 + SiMustWriteLock(sb);
37967 + sbinfo = au_sbi(sb);
37968 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37971 + file = sbinfo->si_xib;
37972 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37975 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37976 + err = PTR_ERR(file);
37977 + if (IS_ERR(file))
37979 + fput(sbinfo->si_xib);
37980 + sbinfo->si_xib = file;
37982 + p = sbinfo->si_xib_buf;
37983 + memset(p, 0, PAGE_SIZE);
37985 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
37986 + if (unlikely(sz != PAGE_SIZE)) {
37988 + AuIOErr("err %d\n", err);
37994 + mutex_lock(&sbinfo->si_xib_mtx);
37995 + /* mnt_want_write() is unnecessary here */
37996 + err = xib_restore(sb);
37997 + mutex_unlock(&sbinfo->si_xib_mtx);
38003 +/* ---------------------------------------------------------------------- */
38005 +struct au_xino *au_xino_alloc(unsigned int nfile)
38007 + struct au_xino *xi;
38009 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38010 + if (unlikely(!xi))
38012 + xi->xi_nfile = nfile;
38013 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38014 + if (unlikely(!xi->xi_file))
38017 + xi->xi_nondir.total = 8; /* initial size */
38018 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38020 + if (unlikely(!xi->xi_nondir.array))
38023 + spin_lock_init(&xi->xi_nondir.spin);
38024 + init_waitqueue_head(&xi->xi_nondir.wqh);
38025 + mutex_init(&xi->xi_mtx);
38026 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38027 + atomic_set(&xi->xi_truncating, 0);
38028 + kref_init(&xi->xi_kref);
38029 + goto out; /* success */
38032 + au_kfree_try_rcu(xi->xi_file);
38034 + au_kfree_rcu(xi);
38040 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38043 + struct au_xino *xi;
38046 + xi = au_xino_alloc(idx + 1);
38047 + if (unlikely(!xi)) {
38054 + xi->xi_file[idx] = file;
38055 + AuDebugOn(br->br_xino);
38056 + br->br_xino = xi;
38062 +static void au_xino_release(struct kref *kref)
38064 + struct au_xino *xi;
38066 + unsigned long ul;
38067 + struct hlist_bl_head *hbl;
38068 + struct hlist_bl_node *pos, *n;
38069 + struct au_xi_writing *p;
38071 + xi = container_of(kref, struct au_xino, xi_kref);
38072 + for (i = 0; i < xi->xi_nfile; i++)
38073 + if (xi->xi_file[i])
38074 + fput(xi->xi_file[i]);
38075 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38076 + AuDebugOn(xi->xi_nondir.array[i]);
38077 + mutex_destroy(&xi->xi_mtx);
38078 + hbl = &xi->xi_writing;
38079 + ul = au_hbl_count(hbl);
38080 + if (unlikely(ul)) {
38081 + pr_warn("xi_writing %lu\n", ul);
38082 + hlist_bl_lock(hbl);
38083 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38084 + hlist_bl_del(&p->node);
38085 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38088 + hlist_bl_unlock(hbl);
38090 + au_kfree_try_rcu(xi->xi_file);
38091 + au_kfree_try_rcu(xi->xi_nondir.array);
38092 + au_kfree_rcu(xi);
38095 +int au_xino_put(struct au_branch *br)
38098 + struct au_xino *xi;
38101 + xi = br->br_xino;
38103 + br->br_xino = NULL;
38104 + ret = kref_put(&xi->xi_kref, au_xino_release);
38110 +/* ---------------------------------------------------------------------- */
38113 + * xino mount option handlers
38117 +static void xino_clear_xib(struct super_block *sb)
38119 + struct au_sbinfo *sbinfo;
38121 + SiMustWriteLock(sb);
38123 + sbinfo = au_sbi(sb);
38124 + if (sbinfo->si_xib)
38125 + fput(sbinfo->si_xib);
38126 + sbinfo->si_xib = NULL;
38127 + if (sbinfo->si_xib_buf)
38128 + free_page((unsigned long)sbinfo->si_xib_buf);
38129 + sbinfo->si_xib_buf = NULL;
38132 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38136 + struct au_sbinfo *sbinfo;
38137 + struct file *file;
38138 + struct super_block *xi_sb;
38140 + SiMustWriteLock(sb);
38142 + sbinfo = au_sbi(sb);
38143 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38144 + err = PTR_ERR(file);
38145 + if (IS_ERR(file))
38147 + if (sbinfo->si_xib)
38148 + fput(sbinfo->si_xib);
38149 + sbinfo->si_xib = file;
38150 + xi_sb = file_inode(file)->i_sb;
38151 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38152 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38154 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38155 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38158 + sbinfo->si_ximaxent /= sizeof(ino_t);
38161 + if (!sbinfo->si_xib_buf)
38162 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38163 + if (unlikely(!sbinfo->si_xib_buf))
38166 + sbinfo->si_xib_last_pindex = 0;
38167 + sbinfo->si_xib_next_bit = 0;
38168 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38170 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38171 + if (unlikely(err != PAGE_SIZE))
38175 + goto out; /* success */
38178 + if (sbinfo->si_xib_buf)
38179 + free_page((unsigned long)sbinfo->si_xib_buf);
38180 + sbinfo->si_xib_buf = NULL;
38184 + fput(sbinfo->si_xib);
38185 + sbinfo->si_xib = NULL;
38191 +/* xino for each branch */
38192 +static void xino_clear_br(struct super_block *sb)
38194 + aufs_bindex_t bindex, bbot;
38195 + struct au_branch *br;
38197 + bbot = au_sbbot(sb);
38198 + for (bindex = 0; bindex <= bbot; bindex++) {
38199 + br = au_sbr(sb, bindex);
38205 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38206 + aufs_bindex_t bshared)
38208 + struct au_branch *brshared;
38210 + brshared = au_sbr(sb, bshared);
38211 + AuDebugOn(!brshared->br_xino);
38212 + AuDebugOn(!brshared->br_xino->xi_file);
38213 + if (br->br_xino != brshared->br_xino) {
38214 + au_xino_get(brshared);
38216 + br->br_xino = brshared->br_xino;
38220 +struct au_xino_do_set_br {
38221 + struct au_branch *br;
38223 + aufs_bindex_t bshared;
38226 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38227 + struct au_xino_do_set_br *args)
38230 + struct au_xi_calc calc;
38231 + struct file *file;
38232 + struct au_branch *br;
38233 + struct au_xi_new xinew = {
38238 + xinew.xi = br->br_xino;
38239 + au_xi_calc(sb, args->h_ino, &calc);
38240 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38241 + if (args->bshared >= 0)
38242 + /* shared xino */
38243 + au_xino_set_br_shared(sb, br, args->bshared);
38244 + else if (!xinew.xi) {
38246 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38247 + if (unlikely(err))
38251 + /* force re-creating */
38252 + xinew.xi = br->br_xino;
38253 + xinew.idx = calc.idx;
38254 + mutex_lock(&xinew.xi->xi_mtx);
38255 + file = au_xi_new(sb, &xinew);
38256 + mutex_unlock(&xinew.xi->xi_mtx);
38257 + err = PTR_ERR(file);
38258 + if (IS_ERR(file))
38260 + AuDebugOn(!file);
38262 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38263 + if (unlikely(err))
38271 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38274 + aufs_bindex_t bindex, bbot;
38275 + struct au_xino_do_set_br args;
38276 + struct inode *inode;
38278 + SiMustWriteLock(sb);
38280 + bbot = au_sbbot(sb);
38281 + inode = d_inode(sb->s_root);
38282 + for (bindex = 0; bindex <= bbot; bindex++) {
38283 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38284 + args.br = au_sbr(sb, bindex);
38285 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38286 + err = au_xino_do_set_br(sb, path, &args);
38287 + if (unlikely(err))
38295 +void au_xino_clr(struct super_block *sb)
38297 + struct au_sbinfo *sbinfo;
38299 + au_xigen_clr(sb);
38300 + xino_clear_xib(sb);
38301 + xino_clear_br(sb);
38302 + dbgaufs_brs_del(sb, 0);
38303 + sbinfo = au_sbi(sb);
38304 + /* lvalue, do not call au_mntflags() */
38305 + au_opt_clr(sbinfo->si_mntflags, XINO);
38308 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38311 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38312 + struct qstr *dname, *cur_name;
38313 + struct file *cur_xino;
38314 + struct au_sbinfo *sbinfo;
38315 + struct path *path, *cur_path;
38317 + SiMustWriteLock(sb);
38320 + sbinfo = au_sbi(sb);
38321 + path = &xiopt->file->f_path;
38322 + dentry = path->dentry;
38323 + parent = dget_parent(dentry);
38326 + cur_xino = sbinfo->si_xib;
38328 + cur_path = &cur_xino->f_path;
38329 + cur_dentry = cur_path->dentry;
38330 + cur_parent = dget_parent(cur_dentry);
38331 + cur_name = &cur_dentry->d_name;
38332 + dname = &dentry->d_name;
38333 + skip = (cur_parent == parent
38334 + && au_qstreq(dname, cur_name));
38335 + dput(cur_parent);
38341 + au_opt_set(sbinfo->si_mntflags, XINO);
38342 + err = au_xino_set_xib(sb, path);
38343 + /* si_x{read,write} are set */
38345 + err = au_xigen_set(sb, path);
38347 + err = au_xino_set_br(sb, path);
38349 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38350 + goto out; /* success */
38354 + AuIOErr("failed setting xino(%d).\n", err);
38363 + * create a xinofile at the default place/path.
38365 +struct file *au_xino_def(struct super_block *sb)
38367 + struct file *file;
38369 + struct au_branch *br;
38370 + struct super_block *h_sb;
38371 + struct path path;
38372 + aufs_bindex_t bbot, bindex, bwr;
38375 + bbot = au_sbbot(sb);
38377 + for (bindex = 0; bindex <= bbot; bindex++) {
38378 + br = au_sbr(sb, bindex);
38379 + if (au_br_writable(br->br_perm)
38380 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38387 + file = ERR_PTR(-ENOMEM);
38388 + page = (void *)__get_free_page(GFP_NOFS);
38389 + if (unlikely(!page))
38391 + path.mnt = au_br_mnt(br);
38392 + path.dentry = au_h_dptr(sb->s_root, bwr);
38393 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38394 + file = (void *)p;
38395 + if (!IS_ERR(p)) {
38396 + strcat(p, "/" AUFS_XINO_FNAME);
38397 + AuDbg("%s\n", p);
38398 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38400 + free_page((unsigned long)page);
38402 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38404 + if (IS_ERR(file))
38406 + h_sb = file->f_path.dentry->d_sb;
38407 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38408 + pr_err("xino doesn't support %s(%s)\n",
38409 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38411 + file = ERR_PTR(-EINVAL);
38419 +/* ---------------------------------------------------------------------- */
38422 + * initialize the xinofile for the specified branch @br
38423 + * at the place/path where @base_file indicates.
38424 + * test whether another branch is on the same filesystem or not,
38425 + * if found then share the xinofile with another branch.
38427 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38428 + struct path *base)
38431 + struct au_xino_do_set_br args = {
38436 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38438 + err = au_xino_do_set_br(sb, base, &args);
38439 + if (unlikely(err))
38445 +/* ---------------------------------------------------------------------- */
38448 + * get an unused inode number from bitmap
38450 +ino_t au_xino_new_ino(struct super_block *sb)
38453 + unsigned long *p, pindex, ul, pend;
38454 + struct au_sbinfo *sbinfo;
38455 + struct file *file;
38456 + int free_bit, err;
38458 + if (!au_opt_test(au_mntflags(sb), XINO))
38459 + return iunique(sb, AUFS_FIRST_INO);
38461 + sbinfo = au_sbi(sb);
38462 + mutex_lock(&sbinfo->si_xib_mtx);
38463 + p = sbinfo->si_xib_buf;
38464 + free_bit = sbinfo->si_xib_next_bit;
38465 + if (free_bit < page_bits && !test_bit(free_bit, p))
38466 + goto out; /* success */
38467 + free_bit = find_first_zero_bit(p, page_bits);
38468 + if (free_bit < page_bits)
38469 + goto out; /* success */
38471 + pindex = sbinfo->si_xib_last_pindex;
38472 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38473 + err = xib_pindex(sb, ul);
38474 + if (unlikely(err))
38476 + free_bit = find_first_zero_bit(p, page_bits);
38477 + if (free_bit < page_bits)
38478 + goto out; /* success */
38481 + file = sbinfo->si_xib;
38482 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38483 + for (ul = pindex + 1; ul <= pend; ul++) {
38484 + err = xib_pindex(sb, ul);
38485 + if (unlikely(err))
38487 + free_bit = find_first_zero_bit(p, page_bits);
38488 + if (free_bit < page_bits)
38489 + goto out; /* success */
38494 + set_bit(free_bit, p);
38495 + sbinfo->si_xib_next_bit = free_bit + 1;
38496 + pindex = sbinfo->si_xib_last_pindex;
38497 + mutex_unlock(&sbinfo->si_xib_mtx);
38498 + ino = xib_calc_ino(pindex, free_bit);
38499 + AuDbg("i%lu\n", (unsigned long)ino);
38502 + mutex_unlock(&sbinfo->si_xib_mtx);
38507 +/* for s_op->delete_inode() */
38508 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38511 + unsigned int mnt_flags;
38512 + aufs_bindex_t bindex, bbot, bi;
38513 + unsigned char try_trunc;
38514 + struct au_iinfo *iinfo;
38515 + struct super_block *sb;
38516 + struct au_hinode *hi;
38517 + struct inode *h_inode;
38518 + struct au_branch *br;
38519 + struct au_xi_calc calc;
38520 + struct file *file;
38522 + AuDebugOn(au_is_bad_inode(inode));
38524 + sb = inode->i_sb;
38525 + mnt_flags = au_mntflags(sb);
38526 + if (!au_opt_test(mnt_flags, XINO)
38527 + || inode->i_ino == AUFS_ROOT_INO)
38531 + au_xigen_inc(inode);
38532 + au_xib_clear_bit(inode);
38535 + iinfo = au_ii(inode);
38536 + bindex = iinfo->ii_btop;
38540 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38541 + hi = au_hinode(iinfo, bindex);
38542 + bbot = iinfo->ii_bbot;
38543 + for (; bindex <= bbot; bindex++, hi++) {
38544 + h_inode = hi->hi_inode;
38546 + || (!unlinked && h_inode->i_nlink))
38549 + /* inode may not be revalidated */
38550 + bi = au_br_index(sb, hi->hi_id);
38554 + br = au_sbr(sb, bi);
38555 + au_xi_calc(sb, h_inode->i_ino, &calc);
38556 + file = au_xino_file(br->br_xino, calc.idx);
38557 + if (IS_ERR_OR_NULL(file))
38560 + err = au_xino_do_write(file, &calc, /*ino*/0);
38561 + if (!err && try_trunc
38562 + && au_test_fs_trunc_xino(au_br_sb(br)))
38563 + xino_try_trunc(sb, br);
38567 +/* ---------------------------------------------------------------------- */
38569 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38571 + int found, total, i;
38574 + total = xi->xi_nondir.total;
38575 + for (i = 0; i < total; i++) {
38576 + if (xi->xi_nondir.array[i] != h_ino)
38585 +static int au_xinondir_expand(struct au_xino *xi)
38590 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38593 + sz = xi->xi_nondir.total * sizeof(ino_t);
38594 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38596 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38597 + /*may_shrink*/0);
38599 + xi->xi_nondir.array = p;
38600 + xi->xi_nondir.total <<= 1;
38601 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38609 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38610 + ino_t h_ino, int idx)
38612 + struct au_xino *xi;
38614 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38615 + xi = au_sbr(sb, bindex)->br_xino;
38616 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38618 + spin_lock(&xi->xi_nondir.spin);
38619 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38620 + xi->xi_nondir.array[idx] = 0;
38621 + spin_unlock(&xi->xi_nondir.spin);
38622 + wake_up_all(&xi->xi_nondir.wqh);
38625 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38628 + int err, found, empty;
38629 + struct au_xino *xi;
38633 + if (!au_opt_test(au_mntflags(sb), XINO))
38634 + goto out; /* no xino */
38636 + xi = au_sbr(sb, bindex)->br_xino;
38639 + spin_lock(&xi->xi_nondir.spin);
38640 + found = au_xinondir_find(xi, h_ino);
38641 + if (found == -1) {
38642 + empty = au_xinondir_find(xi, /*h_ino*/0);
38643 + if (empty == -1) {
38644 + empty = xi->xi_nondir.total;
38645 + err = au_xinondir_expand(xi);
38646 + if (unlikely(err))
38649 + xi->xi_nondir.array[empty] = h_ino;
38652 + spin_unlock(&xi->xi_nondir.spin);
38653 + wait_event(xi->xi_nondir.wqh,
38654 + xi->xi_nondir.array[found] != h_ino);
38659 + spin_unlock(&xi->xi_nondir.spin);
38664 +/* ---------------------------------------------------------------------- */
38666 +int au_xino_path(struct seq_file *seq, struct file *file)
38670 + err = au_seq_path(seq, &file->f_path);
38671 + if (unlikely(err))
38674 +#define Deleted "\\040(deleted)"
38675 + seq->count -= sizeof(Deleted) - 1;
38676 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38677 + sizeof(Deleted) - 1));
38683 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38684 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38685 +++ linux/include/uapi/linux/aufs_type.h 2022-01-13 12:42:15.932899468 +0100
38687 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38689 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38691 + * This program, aufs is free software; you can redistribute it and/or modify
38692 + * it under the terms of the GNU General Public License as published by
38693 + * the Free Software Foundation; either version 2 of the License, or
38694 + * (at your option) any later version.
38696 + * This program is distributed in the hope that it will be useful,
38697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38699 + * GNU General Public License for more details.
38701 + * You should have received a copy of the GNU General Public License
38702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38705 +#ifndef __AUFS_TYPE_H__
38706 +#define __AUFS_TYPE_H__
38708 +#define AUFS_NAME "aufs"
38712 + * define it before including all other headers.
38713 + * sched.h may use pr_* macros before defining "current", so define the
38714 + * no-current version first, and re-define later.
38716 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38717 +#include <linux/sched.h>
38719 +#define pr_fmt(fmt) \
38720 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38721 + (int)sizeof(current->comm), current->comm, current->pid
38722 +#include <linux/limits.h>
38724 +#include <stdint.h>
38725 +#include <sys/types.h>
38726 +#include <limits.h>
38727 +#endif /* __KERNEL__ */
38729 +#define AUFS_VERSION "5.x-rcN-20211129"
38731 +/* todo? move this to linux-2.6.19/include/magic.h */
38732 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38734 +/* ---------------------------------------------------------------------- */
38737 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38738 +typedef int8_t aufs_bindex_t;
38739 +#define AUFS_BRANCH_MAX 127
38741 +typedef int16_t aufs_bindex_t;
38742 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38743 +#define AUFS_BRANCH_MAX 511
38744 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38745 +#define AUFS_BRANCH_MAX 1023
38746 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38747 +#define AUFS_BRANCH_MAX 32767
38751 +#ifndef AUFS_BRANCH_MAX
38752 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38754 +#endif /* __KERNEL__ */
38756 +/* ---------------------------------------------------------------------- */
38758 +#define AUFS_FSTYPE AUFS_NAME
38760 +#define AUFS_ROOT_INO 2
38761 +#define AUFS_FIRST_INO 11
38763 +#define AUFS_WH_PFX ".wh."
38764 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38765 +#define AUFS_WH_TMP_LEN 4
38766 +/* a limit for rmdir/rename a dir and copyup */
38767 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38768 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38770 + - AUFS_WH_TMP_LEN) /* hex */
38771 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38772 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38773 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38774 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38775 +#define AUFS_DIRWH_DEF 3
38776 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38777 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38778 +#define AUFS_RDBLK_DEF 512 /* bytes */
38779 +#define AUFS_RDHASH_DEF 32
38780 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38781 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38782 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38783 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38784 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38786 +/* pseudo-link maintenace under /proc */
38787 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38788 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38789 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38791 +/* dirren, renamed dir */
38792 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38793 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38794 +/* whiteouted doubly */
38795 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38796 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38798 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38799 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38801 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38802 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38803 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38805 +/* doubly whiteouted */
38806 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38807 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38808 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38810 +/* branch permissions and attributes */
38811 +#define AUFS_BRPERM_RW "rw"
38812 +#define AUFS_BRPERM_RO "ro"
38813 +#define AUFS_BRPERM_RR "rr"
38814 +#define AUFS_BRATTR_COO_REG "coo_reg"
38815 +#define AUFS_BRATTR_COO_ALL "coo_all"
38816 +#define AUFS_BRATTR_FHSM "fhsm"
38817 +#define AUFS_BRATTR_UNPIN "unpin"
38818 +#define AUFS_BRATTR_ICEX "icex"
38819 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38820 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38821 +#define AUFS_BRATTR_ICEX_TR "icextr"
38822 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38823 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38824 +#define AUFS_BRRATTR_WH "wh"
38825 +#define AUFS_BRWATTR_NLWH "nolwh"
38826 +#define AUFS_BRWATTR_MOO "moo"
38828 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38829 +#define AuBrPerm_RO (1 << 1) /* readonly */
38830 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38831 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38833 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38834 +#define AuBrAttr_COO_ALL (1 << 4)
38835 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38837 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38838 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38839 + branch. meaningless since
38840 + linux-3.18-rc1 */
38842 +/* ignore error in copying XATTR */
38843 +#define AuBrAttr_ICEX_SEC (1 << 7)
38844 +#define AuBrAttr_ICEX_SYS (1 << 8)
38845 +#define AuBrAttr_ICEX_TR (1 << 9)
38846 +#define AuBrAttr_ICEX_USR (1 << 10)
38847 +#define AuBrAttr_ICEX_OTH (1 << 11)
38848 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38849 + | AuBrAttr_ICEX_SYS \
38850 + | AuBrAttr_ICEX_TR \
38851 + | AuBrAttr_ICEX_USR \
38852 + | AuBrAttr_ICEX_OTH)
38854 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38855 +#define AuBrRAttr_Mask AuBrRAttr_WH
38857 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38858 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38859 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38861 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38863 +/* #warning test userspace */
38865 +#ifndef CONFIG_AUFS_FHSM
38866 +#undef AuBrAttr_FHSM
38867 +#define AuBrAttr_FHSM 0
38869 +#ifndef CONFIG_AUFS_XATTR
38870 +#undef AuBrAttr_ICEX
38871 +#define AuBrAttr_ICEX 0
38872 +#undef AuBrAttr_ICEX_SEC
38873 +#define AuBrAttr_ICEX_SEC 0
38874 +#undef AuBrAttr_ICEX_SYS
38875 +#define AuBrAttr_ICEX_SYS 0
38876 +#undef AuBrAttr_ICEX_TR
38877 +#define AuBrAttr_ICEX_TR 0
38878 +#undef AuBrAttr_ICEX_USR
38879 +#define AuBrAttr_ICEX_USR 0
38880 +#undef AuBrAttr_ICEX_OTH
38881 +#define AuBrAttr_ICEX_OTH 0
38885 +/* the longest combination */
38886 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38887 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38888 + "+" AUFS_BRATTR_COO_REG \
38889 + "+" AUFS_BRATTR_FHSM \
38890 + "+" AUFS_BRATTR_UNPIN \
38891 + "+" AUFS_BRATTR_ICEX_SEC \
38892 + "+" AUFS_BRATTR_ICEX_SYS \
38893 + "+" AUFS_BRATTR_ICEX_USR \
38894 + "+" AUFS_BRATTR_ICEX_OTH \
38895 + "+" AUFS_BRWATTR_NLWH)
38898 + char a[AuBrPermStrSz];
38899 +} au_br_perm_str_t;
38901 +static inline int au_br_writable(int brperm)
38903 + return brperm & AuBrPerm_RW;
38906 +static inline int au_br_whable(int brperm)
38908 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38911 +static inline int au_br_wh_linkable(int brperm)
38913 + return !(brperm & AuBrWAttr_NoLinkWH);
38916 +static inline int au_br_cmoo(int brperm)
38918 + return brperm & AuBrAttr_CMOO_Mask;
38921 +static inline int au_br_fhsm(int brperm)
38923 + return brperm & AuBrAttr_FHSM;
38926 +/* ---------------------------------------------------------------------- */
38930 + /* readdir in userspace */
38934 + AuCtl_WBR_FD, /* pathconf wrapper */
38935 + AuCtl_IBUSY, /* busy inode */
38936 + AuCtl_MVDOWN, /* move-down */
38937 + AuCtl_BR, /* info about branches */
38938 + AuCtl_FHSM_FD /* connection for fhsm */
38941 +/* borrowed from linux/include/linux/kernel.h */
38943 +#ifdef _GNU_SOURCE
38944 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38946 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38948 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38951 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38953 +#define __aligned(x) __attribute__((aligned(x)))
38958 +#define __packed __attribute__((packed))
38962 +struct au_rdu_cookie {
38967 + uint32_t generation;
38970 +struct au_rdu_ent {
38979 +static inline int au_rdu_len(int nlen)
38981 + /* include the terminating NULL */
38982 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38983 + sizeof(uint64_t));
38986 +union au_rdu_ent_ul {
38987 + struct au_rdu_ent __user *e;
38999 + uint64_t sz; /* AuCtl_RDU */
39000 + uint64_t nent; /* AuCtl_RDU_INO */
39002 + union au_rdu_ent_ul ent;
39003 + uint16_t verify[AufsCtlRduV_End];
39005 + /* input/output */
39009 + union au_rdu_ent_ul tail;
39010 + /* number of entries which were added in a single call */
39015 + struct au_rdu_cookie cookie;
39018 +/* ---------------------------------------------------------------------- */
39020 +/* dirren. the branch is identified by the filename who contains this */
39021 +struct au_drinfo {
39024 + uint8_t oldnamelen;
39025 + uint64_t _padding;
39027 + uint8_t oldname[];
39030 +struct au_drinfo_fdata {
39032 + struct au_drinfo drinfo;
39035 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39037 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39039 +/* ---------------------------------------------------------------------- */
39041 +struct aufs_wbr_fd {
39046 +/* ---------------------------------------------------------------------- */
39048 +struct aufs_ibusy {
39049 + uint64_t ino, h_ino;
39053 +/* ---------------------------------------------------------------------- */
39055 +/* error code for move-down */
39056 +/* the actual message strings are implemented in aufs-util.git */
39058 + EAU_MVDOWN_OPAQUE = 1,
39059 + EAU_MVDOWN_WHITEOUT,
39060 + EAU_MVDOWN_UPPER,
39061 + EAU_MVDOWN_BOTTOM,
39062 + EAU_MVDOWN_NOUPPER,
39063 + EAU_MVDOWN_NOLOWERBR,
39067 +/* flags for move-down */
39068 +#define AUFS_MVDOWN_DMSG 1
39069 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39070 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39071 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39072 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39073 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39074 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39075 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39076 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39077 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39078 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39079 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39080 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39082 +/* index for move-down */
39084 + AUFS_MVDOWN_UPPER,
39085 + AUFS_MVDOWN_LOWER,
39086 + AUFS_MVDOWN_NARRAY
39090 + * additional info of move-down
39091 + * number of free blocks and inodes.
39092 + * subset of struct kstatfs, but smaller and always 64bit.
39094 +struct aufs_stfs {
39095 + uint64_t f_blocks;
39096 + uint64_t f_bavail;
39097 + uint64_t f_files;
39098 + uint64_t f_ffree;
39101 +struct aufs_stbr {
39102 + int16_t brid; /* optional input */
39103 + int16_t bindex; /* output */
39104 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39107 +struct aufs_mvdown {
39108 + uint32_t flags; /* input/output */
39109 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39110 + int8_t au_errno; /* output */
39113 +/* ---------------------------------------------------------------------- */
39115 +union aufs_brinfo {
39116 + /* PATH_MAX may differ between kernel-space and user-space */
39117 + char _spacer[4096];
39125 +/* ---------------------------------------------------------------------- */
39127 +#define AuCtlType 'A'
39128 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39129 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39130 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39131 + struct aufs_wbr_fd)
39132 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39133 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39134 + struct aufs_mvdown)
39135 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39136 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39138 +#endif /* __AUFS_TYPE_H__ */
39139 SPDX-License-Identifier: GPL-2.0
39140 aufs5.x-rcN loopback patch
39142 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39143 index 52776d48e306a..64112f1cf8b18 100644
39144 --- a/drivers/block/loop.c
39145 +++ b/drivers/block/loop.c
39146 @@ -509,6 +509,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39150 +static struct file *loop_real_file(struct file *file)
39152 + struct file *f = NULL;
39154 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39155 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39159 static void loop_reread_partitions(struct loop_device *lo)
39162 @@ -566,6 +575,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39164 struct file *file = fget(arg);
39165 struct file *old_file;
39166 + struct file *f, *virt_file = NULL, *old_virt_file;
39170 @@ -585,11 +595,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39171 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39174 + f = loop_real_file(file);
39176 + virt_file = file;
39181 error = loop_validate_file(file, bdev);
39185 old_file = lo->lo_backing_file;
39186 + old_virt_file = lo->lo_backing_virt_file;
39190 @@ -602,6 +620,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39191 blk_mq_freeze_queue(lo->lo_queue);
39192 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39193 lo->lo_backing_file = file;
39194 + lo->lo_backing_virt_file = virt_file;
39195 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39196 mapping_set_gfp_mask(file->f_mapping,
39197 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39198 @@ -624,6 +643,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39202 + if (old_virt_file)
39203 + fput(old_virt_file);
39205 loop_reread_partitions(lo);
39207 @@ -632,6 +653,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39208 loop_global_unlock(lo, is_loop);
39216 @@ -965,6 +988,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39217 const struct loop_config *config)
39219 struct file *file = fget(config->fd);
39220 + struct file *f, *virt_file = NULL;
39221 struct inode *inode;
39222 struct address_space *mapping;
39224 @@ -980,6 +1004,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39225 /* This is safe, since we have a reference from open(). */
39226 __module_get(THIS_MODULE);
39228 + f = loop_real_file(file);
39230 + virt_file = file;
39236 * If we don't hold exclusive handle for the device, upgrade to it
39237 * here to avoid changing device under exclusive owner.
39238 @@ -1045,6 +1076,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39239 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39240 lo->lo_device = bdev;
39241 lo->lo_backing_file = file;
39242 + lo->lo_backing_virt_file = virt_file;
39243 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39244 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39246 @@ -1095,6 +1127,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39247 bd_abort_claiming(bdev, loop_configure);
39252 /* This is safe: open() is still holding a reference. */
39253 module_put(THIS_MODULE);
39255 @@ -1103,6 +1137,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39256 static int __loop_clr_fd(struct loop_device *lo, bool release)
39258 struct file *filp = NULL;
39259 + struct file *virt_filp = lo->lo_backing_virt_file;
39260 gfp_t gfp = lo->old_gfp_mask;
39262 bool partscan = false;
39263 @@ -1153,6 +1188,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39265 spin_lock_irq(&lo->lo_lock);
39266 lo->lo_backing_file = NULL;
39267 + lo->lo_backing_virt_file = NULL;
39268 spin_unlock_irq(&lo->lo_lock);
39270 lo->lo_device = NULL;
39271 @@ -1220,6 +1256,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39280 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39281 index 082d4b6bfc6a6..61feca64688df 100644
39282 --- a/drivers/block/loop.h
39283 +++ b/drivers/block/loop.h
39284 @@ -34,7 +34,7 @@ struct loop_device {
39286 char lo_file_name[LO_NAME_SIZE];
39288 - struct file * lo_backing_file;
39289 + struct file *lo_backing_file, *lo_backing_virt_file;
39290 struct block_device *lo_device;
39292 gfp_t old_gfp_mask;
39293 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39294 index 99ceca1440449..e49dfe8550329 100644
39295 --- a/fs/aufs/f_op.c
39296 +++ b/fs/aufs/f_op.c
39297 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39298 if (IS_ERR(h_file))
39301 - if (au_test_loopback_kthread()) {
39302 + if (0 && au_test_loopback_kthread()) {
39303 au_warn_loopback(h_file->f_path.dentry->d_sb);
39304 if (file->f_mapping != h_file->f_mapping) {
39305 file->f_mapping = h_file->f_mapping;
39306 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39307 index 74347bd75b380..5ef888a1d53f4 100644
39308 --- a/fs/aufs/loop.c
39309 +++ b/fs/aufs/loop.c
39310 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39311 symbol_put(loop_backing_file);
39312 au_kfree_try_rcu(au_warn_loopback_array);
39315 +/* ---------------------------------------------------------------------- */
39317 +/* support the loopback block device insude aufs */
39319 +struct file *aufs_real_loop(struct file *file)
39323 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39324 + fi_read_lock(file);
39325 + f = au_hf_top(file);
39326 + fi_read_unlock(file);
39330 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39331 index 7293bee427f96..3345c098d0d47 100644
39332 --- a/fs/aufs/loop.h
39333 +++ b/fs/aufs/loop.h
39334 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39336 int au_loopback_init(void);
39337 void au_loopback_fin(void);
39339 +struct file *aufs_real_loop(struct file *file);
39341 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39343 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39345 AuStubInt0(au_loopback_init, void)
39346 AuStubVoid(au_loopback_fin, void)
39348 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39349 #endif /* BLK_DEV_LOOP */
39351 #endif /* __KERNEL__ */
39352 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39353 index cfa90537d9d38..028ee1ceeed1a 100644
39354 --- a/fs/aufs/super.c
39355 +++ b/fs/aufs/super.c
39356 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39357 .statfs = aufs_statfs,
39358 .put_super = aufs_put_super,
39359 .sync_fs = aufs_sync_fs,
39360 - .remount_fs = aufs_remount_fs
39361 + .remount_fs = aufs_remount_fs,
39362 +#ifdef CONFIG_AUFS_BDEV_LOOP
39363 + .real_loop = aufs_real_loop
39367 /* ---------------------------------------------------------------------- */
39368 diff --git a/include/linux/fs.h b/include/linux/fs.h
39369 index 02ce64c28ef15..eed5ad4a414ac 100644
39370 --- a/include/linux/fs.h
39371 +++ b/include/linux/fs.h
39372 @@ -2225,6 +2225,10 @@ struct super_operations {
39373 struct shrink_control *);
39374 long (*free_cached_objects)(struct super_block *,
39375 struct shrink_control *);
39376 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39378 + struct file *(*real_loop)(struct file *);