1 SPDX-License-Identifier: GPL-2.0
2 aufs5.15.5 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
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 3b79fd441dde8..3fb0a57f61b05 100644
32 @@ -3122,6 +3122,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 dfc72a1f6500d..c9d1ef703673c 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -798,6 +798,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/fs/sync.c b/fs/sync.c
162 index 1373a610dc784..b7b5a0a0df6ff 100644
166 * wait == 1 case since in that case write_inode() functions do
167 * sync_dirty_buffer() and thus effectively write one block at a time.
169 -static int __sync_filesystem(struct super_block *sb, int wait)
170 +int __sync_filesystem(struct super_block *sb, int wait)
174 diff --git a/include/linux/fs.h b/include/linux/fs.h
175 index 56eba723477e3..e60d8ad854004 100644
176 --- a/include/linux/fs.h
177 +++ b/include/linux/fs.h
178 @@ -1381,6 +1381,7 @@ extern void fasync_free(struct fasync_struct *);
179 /* can be called from interrupts */
180 extern void kill_fasync(struct fasync_struct **, int, int);
182 +extern int setfl(int fd, struct file *filp, unsigned long arg);
183 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
184 extern int f_setown(struct file *filp, unsigned long arg, int force);
185 extern void f_delown(struct file *filp);
186 @@ -2092,6 +2093,7 @@ struct file_operations {
187 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
188 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
189 int (*check_flags)(int);
190 + int (*setfl)(struct file *, unsigned long);
191 int (*flock) (struct file *, int, struct file_lock *);
192 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
193 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
194 @@ -2615,6 +2617,7 @@ extern int current_umask(void);
195 extern void ihold(struct inode * inode);
196 extern void iput(struct inode *);
197 extern int generic_update_time(struct inode *, struct timespec64 *, int);
198 +extern int update_time(struct inode *, struct timespec64 *, int);
201 extern struct kobject *fs_kobj;
202 @@ -2778,6 +2781,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
205 void emergency_thaw_all(void);
206 +extern int __sync_filesystem(struct super_block *, int);
207 extern int sync_filesystem(struct super_block *);
208 extern const struct file_operations def_blk_fops;
209 extern const struct file_operations def_chr_fops;
210 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
211 index 9fe165beb0f9e..e47f7e15eeaf7 100644
212 --- a/include/linux/lockdep.h
213 +++ b/include/linux/lockdep.h
214 @@ -248,6 +248,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
215 return lock->key == key;
218 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
223 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
224 index 8f882f5881e87..6b9808f098435 100644
225 --- a/include/linux/mnt_namespace.h
226 +++ b/include/linux/mnt_namespace.h
227 @@ -7,12 +7,15 @@ struct mnt_namespace;
229 struct user_namespace;
233 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
234 struct user_namespace *, struct fs_struct *);
235 extern void put_mnt_ns(struct mnt_namespace *ns);
236 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
238 +extern int is_current_mnt_ns(struct vfsmount *mnt);
240 extern const struct file_operations proc_mounts_operations;
241 extern const struct file_operations proc_mountinfo_operations;
242 extern const struct file_operations proc_mountstats_operations;
243 diff --git a/include/linux/splice.h b/include/linux/splice.h
244 index a55179fd60fc3..8e21c53cf8831 100644
245 --- a/include/linux/splice.h
246 +++ b/include/linux/splice.h
247 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
249 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
250 extern const struct pipe_buf_operations default_pipe_buf_ops;
252 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
253 + loff_t *ppos, size_t len, unsigned int flags);
254 +extern long do_splice_to(struct file *in, loff_t *ppos,
255 + struct pipe_inode_info *pipe, size_t len,
256 + unsigned int flags);
258 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
259 index d624231eab2bb..eff2ca26e6c58 100644
260 --- a/kernel/locking/lockdep.c
261 +++ b/kernel/locking/lockdep.c
262 @@ -189,7 +189,7 @@ static
263 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
264 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
266 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
267 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
269 unsigned int class_idx = hlock->class_idx;
271 @@ -210,6 +210,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
273 return lock_classes + class_idx;
275 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
277 #ifdef CONFIG_LOCK_STAT
278 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
279 SPDX-License-Identifier: GPL-2.0
280 aufs5.15.5 mmap patch
282 diff --git a/fs/proc/base.c b/fs/proc/base.c
283 index 1f394095eb880..93f2479ef319e 100644
286 @@ -2189,7 +2189,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
288 vma = find_exact_vma(mm, vm_start, vm_end);
289 if (vma && vma->vm_file) {
290 - *path = vma->vm_file->f_path;
291 + *path = vma_pr_or_file(vma)->f_path;
295 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
296 index 13452b32e2bd5..38acccfef9d49 100644
297 --- a/fs/proc/nommu.c
298 +++ b/fs/proc/nommu.c
299 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
300 file = region->vm_file;
303 - struct inode *inode = file_inode(region->vm_file);
304 + struct inode *inode;
306 + file = vmr_pr_or_file(region);
307 + inode = file_inode(file);
308 dev = inode->i_sb->s_dev;
311 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
312 index cf25be3e03212..70af1c25ffa22 100644
313 --- a/fs/proc/task_mmu.c
314 +++ b/fs/proc/task_mmu.c
315 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
316 const char *name = NULL;
319 - struct inode *inode = file_inode(vma->vm_file);
320 + struct inode *inode;
322 + file = vma_pr_or_file(vma);
323 + inode = file_inode(file);
324 dev = inode->i_sb->s_dev;
326 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
327 @@ -1865,7 +1868,7 @@ static int show_numa_map(struct seq_file *m, void *v)
328 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
329 struct vm_area_struct *vma = v;
330 struct numa_maps *md = &numa_priv->md;
331 - struct file *file = vma->vm_file;
332 + struct file *file = vma_pr_or_file(vma);
333 struct mm_struct *mm = vma->vm_mm;
334 struct mempolicy *pol;
336 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
337 index a6d21fc0033c6..02c2de31196e0 100644
338 --- a/fs/proc/task_nommu.c
339 +++ b/fs/proc/task_nommu.c
340 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
344 - struct inode *inode = file_inode(vma->vm_file);
345 + struct inode *inode;
347 + file = vma_pr_or_file(vma);
348 + inode = file_inode(file);
349 dev = inode->i_sb->s_dev;
351 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
352 diff --git a/include/linux/mm.h b/include/linux/mm.h
353 index 73a52aba448f9..5dd42acf0707b 100644
354 --- a/include/linux/mm.h
355 +++ b/include/linux/mm.h
356 @@ -1806,6 +1806,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
357 unmap_mapping_range(mapping, holebegin, holelen, 0);
360 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
361 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
363 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
364 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
366 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
368 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
370 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
371 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
374 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
375 +extern void vmr_do_fput(struct vm_region *, const char[], int);
377 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
379 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
380 +#endif /* !CONFIG_MMU */
382 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
383 void *buf, int len, unsigned int gup_flags);
384 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
385 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
386 index 7f8ee09c711f4..3a9a798a4ae1f 100644
387 --- a/include/linux/mm_types.h
388 +++ b/include/linux/mm_types.h
389 @@ -294,6 +294,7 @@ struct vm_region {
390 unsigned long vm_top; /* region allocated to here */
391 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
392 struct file *vm_file; /* the backing file or NULL */
393 + struct file *vm_prfile; /* the virtual backing file or NULL */
395 int vm_usage; /* region usage count (access under nommu_region_sem) */
396 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
397 @@ -373,6 +374,7 @@ struct vm_area_struct {
398 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
400 struct file * vm_file; /* File we map to (can be NULL). */
401 + struct file *vm_prfile; /* shadow of vm_file */
402 void * vm_private_data; /* was vm_pte (shared mem) */
405 diff --git a/kernel/fork.c b/kernel/fork.c
406 index 10885c649ca42..f3a9cd12011b3 100644
409 @@ -573,7 +573,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
411 struct address_space *mapping = file->f_mapping;
415 i_mmap_lock_write(mapping);
416 if (tmp->vm_flags & VM_SHARED)
417 mapping_allow_writable(mapping);
418 diff --git a/mm/Makefile b/mm/Makefile
419 index fc60a40ce954b..c715b0138237b 100644
422 @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
423 mm_init.o percpu.o slab_common.o \
424 compaction.o vmacache.o \
425 interval_tree.o list_lru.o workingset.o \
426 - debug.o gup.o mmap_lock.o $(mmu-y)
427 + prfile.o debug.o gup.o mmap_lock.o $(mmu-y)
429 # Give 'page_alloc' its own module-parameter namespace
430 page-alloc-y := page_alloc.o
431 diff --git a/mm/filemap.c b/mm/filemap.c
432 index 82a17c35eb96b..348e22067abdc 100644
435 @@ -3349,7 +3349,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
436 vm_fault_t ret = VM_FAULT_LOCKED;
438 sb_start_pagefault(mapping->host->i_sb);
439 - file_update_time(vmf->vma->vm_file);
440 + vma_file_update_time(vmf->vma);
442 if (page->mapping != mapping) {
444 diff --git a/mm/mmap.c b/mm/mmap.c
445 index 88dcc5c252255..6c276614ca962 100644
448 @@ -183,7 +183,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
449 if (vma->vm_ops && vma->vm_ops->close)
450 vma->vm_ops->close(vma);
452 - fput(vma->vm_file);
454 mpol_put(vma_policy(vma));
457 @@ -952,7 +952,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
460 uprobe_munmap(next, next->vm_start, next->vm_end);
465 anon_vma_merge(vma, next);
466 @@ -1873,7 +1873,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
470 - fput(vma->vm_file);
474 /* Undo any partial mapping done by a device driver. */
475 @@ -2731,7 +2731,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
479 - get_file(new->vm_file);
482 if (new->vm_ops && new->vm_ops->open)
483 new->vm_ops->open(new);
484 @@ -2750,7 +2750,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
485 if (new->vm_ops && new->vm_ops->close)
486 new->vm_ops->close(new);
488 - fput(new->vm_file);
490 unlink_anon_vmas(new);
492 mpol_put(vma_policy(new));
493 @@ -2945,7 +2945,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
494 struct vm_area_struct *vma;
495 unsigned long populate = 0;
496 unsigned long ret = -EINVAL;
498 + struct file *file, *prfile;
500 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
501 current->comm, current->pid);
502 @@ -3001,10 +3001,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
503 if (vma->vm_flags & VM_LOCKED)
506 - file = get_file(vma->vm_file);
508 + file = vma->vm_file;
509 + prfile = vma->vm_prfile;
510 ret = do_mmap(vma->vm_file, start, size,
511 prot, flags, pgoff, &populate, NULL);
512 + if (!IS_ERR_VALUE(ret) && file && prfile) {
513 + struct vm_area_struct *new_vma;
515 + new_vma = find_vma(mm, ret);
516 + if (!new_vma->vm_prfile)
517 + new_vma->vm_prfile = prfile;
518 + if (new_vma != vma)
522 + * two fput()s instead of vma_fput(vma),
523 + * coz vma may not be available anymore.
529 mmap_write_unlock(mm);
531 @@ -3285,7 +3302,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
532 if (anon_vma_clone(new_vma, vma))
533 goto out_free_mempol;
534 if (new_vma->vm_file)
535 - get_file(new_vma->vm_file);
536 + vma_get_file(new_vma);
537 if (new_vma->vm_ops && new_vma->vm_ops->open)
538 new_vma->vm_ops->open(new_vma);
539 vma_link(mm, new_vma, prev, rb_link, rb_parent);
540 diff --git a/mm/nommu.c b/mm/nommu.c
541 index 02d2427b8f9e8..a7419302ab4ed 100644
544 @@ -523,7 +523,7 @@ static void __put_nommu_region(struct vm_region *region)
545 up_write(&nommu_region_sem);
548 - fput(region->vm_file);
551 /* IO memory and memory shared directly out of the pagecache
552 * from ramfs/tmpfs mustn't be released here */
553 @@ -655,7 +655,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
554 if (vma->vm_ops && vma->vm_ops->close)
555 vma->vm_ops->close(vma);
557 - fput(vma->vm_file);
559 put_nommu_region(vma->vm_region);
562 @@ -1175,7 +1175,7 @@ unsigned long do_mmap(struct file *file,
563 goto error_just_free;
566 - fput(region->vm_file);
568 kmem_cache_free(vm_region_jar, region);
571 @@ -1252,10 +1252,10 @@ unsigned long do_mmap(struct file *file,
572 up_write(&nommu_region_sem);
575 - fput(region->vm_file);
577 kmem_cache_free(vm_region_jar, region);
579 - fput(vma->vm_file);
584 diff --git a/mm/prfile.c b/mm/prfile.c
586 index 0000000000000..511543ab1b418
590 +// SPDX-License-Identifier: GPL-2.0
592 + * Mainly for aufs which mmap(2) different file and wants to print different
593 + * path in /proc/PID/maps.
594 + * Call these functions via macros defined in linux/mm.h.
596 + * See Documentation/filesystems/aufs/design/06mmap.txt
598 + * Copyright (c) 2014-2021 Junjro R. Okajima
599 + * Copyright (c) 2014 Ian Campbell
602 +#include <linux/mm.h>
603 +#include <linux/file.h>
604 +#include <linux/fs.h>
606 +/* #define PRFILE_TRACE */
607 +static inline void prfile_trace(struct file *f, struct file *pr,
608 + const char func[], int line, const char func2[])
612 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
616 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
619 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
621 + prfile_trace(f, pr, func, line, __func__);
622 + file_update_time(f);
624 + file_update_time(pr);
627 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
630 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
632 + prfile_trace(f, pr, func, line, __func__);
633 + return (f && pr) ? pr : f;
636 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
638 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
640 + prfile_trace(f, pr, func, line, __func__);
646 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
648 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
650 + prfile_trace(f, pr, func, line, __func__);
657 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
660 + struct file *f = region->vm_file, *pr = region->vm_prfile;
662 + prfile_trace(f, pr, func, line, __func__);
663 + return (f && pr) ? pr : f;
666 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
668 + struct file *f = region->vm_file, *pr = region->vm_prfile;
670 + prfile_trace(f, pr, func, line, __func__);
675 +#endif /* !CONFIG_MMU */
676 SPDX-License-Identifier: GPL-2.0
677 aufs5.15.5 standalone patch
679 diff --git a/fs/dcache.c b/fs/dcache.c
680 index bc5095b734f58..9508bd57a3bc0 100644
683 @@ -1425,6 +1425,7 @@ void d_walk(struct dentry *parent, void *data,
687 +EXPORT_SYMBOL_GPL(d_walk);
690 struct vfsmount *mnt;
691 @@ -2970,6 +2971,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
693 write_sequnlock(&rename_lock);
695 +EXPORT_SYMBOL_GPL(d_exchange);
698 * d_ancestor - search for an ancestor
699 diff --git a/fs/exec.c b/fs/exec.c
700 index ac7b51b51f38a..52a8be4ebc1e1 100644
703 @@ -111,6 +111,7 @@ bool path_noexec(const struct path *path)
704 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
705 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
707 +EXPORT_SYMBOL_GPL(path_noexec);
711 diff --git a/fs/fcntl.c b/fs/fcntl.c
712 index 02382fa9bd341..3418c60b90146 100644
715 @@ -86,6 +86,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
719 +EXPORT_SYMBOL_GPL(setfl);
721 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
723 diff --git a/fs/file_table.c b/fs/file_table.c
724 index 45437f8e1003e..786af52904fcf 100644
725 --- a/fs/file_table.c
726 +++ b/fs/file_table.c
727 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
729 return ERR_PTR(-ENFILE);
731 +EXPORT_SYMBOL_GPL(alloc_empty_file);
734 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
735 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
739 +EXPORT_SYMBOL_GPL(__fput_sync);
741 void __init files_init(void)
743 diff --git a/fs/namespace.c b/fs/namespace.c
744 index 1283670737826..db99365620118 100644
747 @@ -439,6 +439,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
748 mnt_dec_writers(real_mount(mnt));
751 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
754 * mnt_drop_write - give up write access to a mount
755 @@ -813,6 +814,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
757 return check_mnt(real_mount(mnt));
759 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
762 * vfsmount lock must be held for write
763 @@ -2011,6 +2013,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
767 +EXPORT_SYMBOL_GPL(iterate_mounts);
769 static void lock_mnt_tree(struct mount *mnt)
771 diff --git a/fs/notify/group.c b/fs/notify/group.c
772 index fb89c351295d6..460ad19c2570a 100644
773 --- a/fs/notify/group.c
774 +++ b/fs/notify/group.c
775 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
777 refcount_inc(&group->refcnt);
779 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
782 * Drop a reference to a group. Free it if it's through.
783 diff --git a/fs/open.c b/fs/open.c
784 index e0df1536eb69f..81b2d7c83addb 100644
787 @@ -65,6 +65,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
788 inode_unlock(dentry->d_inode);
791 +EXPORT_SYMBOL_GPL(do_truncate);
793 long vfs_truncate(const struct path *path, loff_t length)
795 diff --git a/fs/read_write.c b/fs/read_write.c
796 index af057c57bdc64..76017f8331fbf 100644
797 --- a/fs/read_write.c
798 +++ b/fs/read_write.c
799 @@ -492,6 +492,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
803 +EXPORT_SYMBOL_GPL(vfs_read);
805 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
807 @@ -602,6 +603,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
808 file_end_write(file);
811 +EXPORT_SYMBOL_GPL(vfs_write);
813 /* file_ppos returns &file->f_pos or NULL if file is stream */
814 static inline loff_t *file_ppos(struct file *file)
815 diff --git a/fs/splice.c b/fs/splice.c
816 index 3e6ba363b7775..7c1be373eb7cd 100644
819 @@ -766,6 +766,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
820 return warn_unsupported(out, "write");
821 return out->f_op->splice_write(pipe, out, ppos, len, flags);
823 +EXPORT_SYMBOL_GPL(do_splice_from);
826 * Attempt to initiate a splice from a file to a pipe.
827 @@ -795,6 +796,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
828 return warn_unsupported(in, "read");
829 return in->f_op->splice_read(in, ppos, pipe, len, flags);
831 +EXPORT_SYMBOL_GPL(do_splice_to);
834 * splice_direct_to_actor - splices data directly between two non-pipes
835 diff --git a/fs/sync.c b/fs/sync.c
836 index b7b5a0a0df6ff..fa5c7fba7f1ba 100644
839 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
840 sb->s_op->sync_fs(sb, wait);
841 return __sync_blockdev(sb->s_bdev, wait);
843 +EXPORT_SYMBOL_GPL(__sync_filesystem);
846 * Write out and wait upon all dirty data associated with this
847 diff --git a/fs/xattr.c b/fs/xattr.c
848 index 5c8c5175b385c..ff7e9ff774b73 100644
851 @@ -384,6 +384,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
852 *xattr_value = value;
855 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
858 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
859 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
860 index eff2ca26e6c58..0627584f7872a 100644
861 --- a/kernel/locking/lockdep.c
862 +++ b/kernel/locking/lockdep.c
863 @@ -210,6 +210,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
865 return lock_classes + class_idx;
867 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
868 #define hlock_class(hlock) lockdep_hlock_class(hlock)
870 #ifdef CONFIG_LOCK_STAT
871 diff --git a/kernel/task_work.c b/kernel/task_work.c
872 index 1698fbe6f0e13..081b05acadf82 100644
873 --- a/kernel/task_work.c
874 +++ b/kernel/task_work.c
875 @@ -167,3 +167,4 @@ void task_work_run(void)
879 +EXPORT_SYMBOL_GPL(task_work_run);
880 diff --git a/security/security.c b/security/security.c
881 index 67264cb08fb31..0d78065d71fe1 100644
882 --- a/security/security.c
883 +++ b/security/security.c
884 @@ -1147,6 +1147,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
886 return call_int_hook(path_rmdir, 0, dir, dentry);
888 +EXPORT_SYMBOL_GPL(security_path_rmdir);
890 int security_path_unlink(const struct path *dir, struct dentry *dentry)
892 @@ -1163,6 +1164,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
894 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
896 +EXPORT_SYMBOL_GPL(security_path_symlink);
898 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
899 struct dentry *new_dentry)
900 @@ -1171,6 +1173,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
902 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
904 +EXPORT_SYMBOL_GPL(security_path_link);
906 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
907 const struct path *new_dir, struct dentry *new_dentry,
908 @@ -1198,6 +1201,7 @@ int security_path_truncate(const struct path *path)
910 return call_int_hook(path_truncate, 0, path);
912 +EXPORT_SYMBOL_GPL(security_path_truncate);
914 int security_path_chmod(const struct path *path, umode_t mode)
916 @@ -1205,6 +1209,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
918 return call_int_hook(path_chmod, 0, path, mode);
920 +EXPORT_SYMBOL_GPL(security_path_chmod);
922 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
924 @@ -1212,6 +1217,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
926 return call_int_hook(path_chown, 0, path, uid, gid);
928 +EXPORT_SYMBOL_GPL(security_path_chown);
930 int security_path_chroot(const struct path *path)
932 @@ -1312,6 +1318,7 @@ int security_inode_permission(struct inode *inode, int mask)
934 return call_int_hook(inode_permission, 0, inode, mask);
936 +EXPORT_SYMBOL_GPL(security_inode_permission);
938 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
940 @@ -1509,6 +1516,7 @@ int security_file_permission(struct file *file, int mask)
942 return fsnotify_perm(file, mask);
944 +EXPORT_SYMBOL_GPL(security_file_permission);
946 int security_file_alloc(struct file *file)
948 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
949 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
950 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-12-03 15:38:59.926647310 +0100
952 +What: /debug/aufs/si_<id>/
954 +Contact: J. R. Okajima <hooanon05g@gmail.com>
956 + Under /debug/aufs, a directory named si_<id> is created
957 + per aufs mount, where <id> is a unique id generated
960 +What: /debug/aufs/si_<id>/plink
962 +Contact: J. R. Okajima <hooanon05g@gmail.com>
964 + It has three lines and shows the information about the
965 + pseudo-link. The first line is a single number
966 + representing a number of buckets. The second line is a
967 + number of pseudo-links per buckets (separated by a
968 + blank). The last line is a single number representing a
969 + total number of psedo-links.
970 + When the aufs mount option 'noplink' is specified, it
971 + will show "1\n0\n0\n".
973 +What: /debug/aufs/si_<id>/xib
975 +Contact: J. R. Okajima <hooanon05g@gmail.com>
977 + It shows the consumed blocks by xib (External Inode Number
978 + Bitmap), its block size and file size.
979 + When the aufs mount option 'noxino' is specified, it
980 + will be empty. About XINO files, see the aufs manual.
982 +What: /debug/aufs/si_<id>/xi<branch-index>
984 +Contact: J. R. Okajima <hooanon05g@gmail.com>
986 + It shows the consumed blocks by xino (External Inode Number
987 + Translation Table), its link count, block size and file
989 + Due to the file size limit, there may exist multiple
990 + xino files per branch. In this case, "-N" is added to
991 + the filename and it corresponds to the index of the
992 + internal xino array. "-0" is omitted.
993 + When the aufs mount option 'noxino' is specified, Those
994 + entries won't exist. About XINO files, see the aufs
997 +What: /debug/aufs/si_<id>/xigen
999 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1001 + It shows the consumed blocks by xigen (External Inode
1002 + Generation Table), its block size and file size.
1003 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1005 + When the aufs mount option 'noxino' is specified, it
1006 + will be empty. About XINO files, see the aufs manual.
1007 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1008 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1009 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-12-03 15:38:59.926647310 +0100
1011 +What: /sys/fs/aufs/si_<id>/
1013 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1015 + Under /sys/fs/aufs, a directory named si_<id> is created
1016 + per aufs mount, where <id> is a unique id generated
1019 +What: /sys/fs/aufs/si_<id>/br<idx>
1021 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1023 + It shows the abolute path of a member directory (which
1024 + is called branch) in aufs, and its permission.
1026 +What: /sys/fs/aufs/si_<id>/brid<idx>
1028 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1030 + It shows the id of a member directory (which is called
1033 +What: /sys/fs/aufs/si_<id>/xi_path
1035 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1037 + It shows the abolute path of XINO (External Inode Number
1038 + Bitmap, Translation Table and Generation Table) file
1039 + even if it is the default path.
1040 + When the aufs mount option 'noxino' is specified, it
1041 + will be empty. About XINO files, see the aufs manual.
1042 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1043 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1044 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-12-03 15:38:59.929980643 +0100
1047 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1049 +# This program is free software; you can redistribute it and/or modify
1050 +# it under the terms of the GNU General Public License as published by
1051 +# the Free Software Foundation; either version 2 of the License, or
1052 +# (at your option) any later version.
1054 +# This program is distributed in the hope that it will be useful,
1055 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1056 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1057 +# GNU General Public License for more details.
1059 +# You should have received a copy of the GNU General Public License
1060 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1063 +----------------------------------------
1065 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1066 +1. abbrev. for "advanced multi-layered unification filesystem".
1067 +2. abbrev. for "another unionfs".
1068 +3. abbrev. for "auf das" in German which means "on the" in English.
1069 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1070 + But "Filesystem aufs Filesystem" is hard to understand.
1071 +4. abbrev. for "African Urban Fashion Show".
1073 +AUFS is a filesystem with features:
1074 +- multi layered stackable unification filesystem, the member directory
1075 + is called as a branch.
1076 +- branch permission and attribute, 'readonly', 'real-readonly',
1077 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1079 +- internal "file copy-on-write".
1080 +- logical deletion, whiteout.
1081 +- dynamic branch manipulation, adding, deleting and changing permission.
1082 +- allow bypassing aufs, user's direct branch access.
1083 +- external inode number translation table and bitmap which maintains the
1084 + persistent aufs inode number.
1085 +- seekable directory, including NFS readdir.
1086 +- file mapping, mmap and sharing pages.
1087 +- pseudo-link, hardlink over branches.
1088 +- loopback mounted filesystem as a branch.
1089 +- several policies to select one among multiple writable branches.
1090 +- revert a single systemcall when an error occurs in aufs.
1094 +Multi Layered Stackable Unification Filesystem
1095 +----------------------------------------------------------------------
1096 +Most people already knows what it is.
1097 +It is a filesystem which unifies several directories and provides a
1098 +merged single directory. When users access a file, the access will be
1099 +passed/re-directed/converted (sorry, I am not sure which English word is
1100 +correct) to the real file on the member filesystem. The member
1101 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1102 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1103 +readonly branch is handled by creating 'whiteout' on the upper writable
1106 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1107 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1108 +different approaches to implement the merged-view.
1109 +The former tries putting it into VFS, and the latter implements as a
1110 +separate filesystem.
1111 +(If I misunderstand about these implementations, please let me know and
1112 +I shall correct it. Because it is a long time ago when I read their
1113 +source files last time).
1115 +UnionMount's approach will be able to small, but may be hard to share
1116 +branches between several UnionMount since the whiteout in it is
1117 +implemented in the inode on branch filesystem and always
1118 +shared. According to Bharata's post, readdir does not seems to be
1120 +There are several missing features known in this implementations such as
1121 +- for users, the inode number may change silently. eg. copy-up.
1122 +- link(2) may break by copy-up.
1123 +- read(2) may get an obsoleted filedata (fstat(2) too).
1124 +- fcntl(F_SETLK) may be broken by copy-up.
1125 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1128 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1129 +merged into mainline. This is another implementation of UnionMount as a
1130 +separated filesystem. All the limitations and known problems which
1131 +UnionMount are equally inherited to "overlay" filesystem.
1133 +Unionfs has a longer history. When I started implementing a stackable
1134 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1135 +inode, dentry and file objects and they have an array pointing lower
1136 +same kind objects. After contributing many patches for Unionfs, I
1137 +re-started my project AUFS (Jun 2006).
1139 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1140 +implemented my own ideas, approaches and enhancements and it became
1141 +totally different one.
1143 +Comparing DM snapshot and fs based implementation
1144 +- the number of bytes to be copied between devices is much smaller.
1145 +- the type of filesystem must be one and only.
1146 +- the fs must be writable, no readonly fs, even for the lower original
1147 + device. so the compression fs will not be usable. but if we use
1148 + loopback mount, we may address this issue.
1150 + mount /cdrom/squashfs.img /sq
1151 + losetup /sq/ext2.img
1152 + losetup /somewhere/cow
1153 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1154 +- it will be difficult (or needs more operations) to extract the
1155 + difference between the original device and COW.
1156 +- DM snapshot-merge may help a lot when users try merging. in the
1157 + fs-layer union, users will use rsync(1).
1159 +You may want to read my old paper "Filesystems in LiveCD"
1160 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1163 +Several characters/aspects/persona of aufs
1164 +----------------------------------------------------------------------
1166 +Aufs has several characters, aspects or persona.
1167 +1. a filesystem, callee of VFS helper
1168 +2. sub-VFS, caller of VFS helper for branches
1169 +3. a virtual filesystem which maintains persistent inode number
1170 +4. reader/writer of files on branches such like an application
1172 +1. Callee of VFS Helper
1173 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1174 +unlink(2) from an application reaches sys_unlink() kernel function and
1175 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1176 +calls filesystem specific unlink operation. Actually aufs implements the
1177 +unlink operation but it behaves like a redirector.
1179 +2. Caller of VFS Helper for Branches
1180 +aufs_unlink() passes the unlink request to the branch filesystem as if
1181 +it were called from VFS. So the called unlink operation of the branch
1182 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1183 +every necessary pre/post operation for the branch filesystem.
1184 +- acquire the lock for the parent dir on a branch
1185 +- lookup in a branch
1186 +- revalidate dentry on a branch
1187 +- mnt_want_write() for a branch
1188 +- vfs_unlink() for a branch
1189 +- mnt_drop_write() for a branch
1190 +- release the lock on a branch
1192 +3. Persistent Inode Number
1193 +One of the most important issue for a filesystem is to maintain inode
1194 +numbers. This is particularly important to support exporting a
1195 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1196 +backend block device for its own. But some storage is necessary to
1197 +keep and maintain the inode numbers. It may be a large space and may not
1198 +suit to keep in memory. Aufs rents some space from its first writable
1199 +branch filesystem (by default) and creates file(s) on it. These files
1200 +are created by aufs internally and removed soon (currently) keeping
1202 +Note: Because these files are removed, they are totally gone after
1203 + unmounting aufs. It means the inode numbers are not persistent
1204 + across unmount or reboot. I have a plan to make them really
1205 + persistent which will be important for aufs on NFS server.
1207 +4. Read/Write Files Internally (copy-on-write)
1208 +Because a branch can be readonly, when you write a file on it, aufs will
1209 +"copy-up" it to the upper writable branch internally. And then write the
1210 +originally requested thing to the file. Generally kernel doesn't
1211 +open/read/write file actively. In aufs, even a single write may cause a
1212 +internal "file copy". This behaviour is very similar to cp(1) command.
1214 +Some people may think it is better to pass such work to user space
1215 +helper, instead of doing in kernel space. Actually I am still thinking
1216 +about it. But currently I have implemented it in kernel space.
1217 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1218 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1219 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-12-03 15:38:59.929980643 +0100
1222 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1224 +# This program is free software; you can redistribute it and/or modify
1225 +# it under the terms of the GNU General Public License as published by
1226 +# the Free Software Foundation; either version 2 of the License, or
1227 +# (at your option) any later version.
1229 +# This program is distributed in the hope that it will be useful,
1230 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1231 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1232 +# GNU General Public License for more details.
1234 +# You should have received a copy of the GNU General Public License
1235 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1237 +Basic Aufs Internal Structure
1239 +Superblock/Inode/Dentry/File Objects
1240 +----------------------------------------------------------------------
1241 +As like an ordinary filesystem, aufs has its own
1242 +superblock/inode/dentry/file objects. All these objects have a
1243 +dynamically allocated array and store the same kind of pointers to the
1244 +lower filesystem, branch.
1245 +For example, when you build a union with one readwrite branch and one
1246 +readonly, mounted /au, /rw and /ro respectively.
1248 +- /ro/fileA exists but /rw/fileA
1250 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1251 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1252 +- [0] = NULL (because /rw/fileA doesn't exist)
1255 +This style of an array is essentially same to the aufs
1256 +superblock/inode/dentry/file objects.
1258 +Because aufs supports manipulating branches, ie. add/delete/change
1259 +branches dynamically, these objects has its own generation. When
1260 +branches are changed, the generation in aufs superblock is
1261 +incremented. And a generation in other object are compared when it is
1262 +accessed. When a generation in other objects are obsoleted, aufs
1263 +refreshes the internal array.
1267 +----------------------------------------------------------------------
1268 +Additionally aufs superblock has some data for policies to select one
1269 +among multiple writable branches, XIB files, pseudo-links and kobject.
1270 +See below in detail.
1271 +About the policies which supports copy-down a directory, see
1272 +wbr_policy.txt too.
1275 +Branch and XINO(External Inode Number Translation Table)
1276 +----------------------------------------------------------------------
1277 +Every branch has its own xino (external inode number translation table)
1278 +file. The xino file is created and unlinked by aufs internally. When two
1279 +members of a union exist on the same filesystem, they share the single
1281 +The struct of a xino file is simple, just a sequence of aufs inode
1282 +numbers which is indexed by the lower inode number.
1283 +In the above sample, assume the inode number of /ro/fileA is i111 and
1284 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1285 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1287 +When the inode numbers are not contiguous, the xino file will be sparse
1288 +which has a hole in it and doesn't consume as much disk space as it
1289 +might appear. If your branch filesystem consumes disk space for such
1290 +holes, then you should specify 'xino=' option at mounting aufs.
1292 +Aufs has a mount option to free the disk blocks for such holes in XINO
1293 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1294 +meet a problem of disk shortage due to XINO files, then you should try
1295 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1296 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1297 +the holes in XINO files.
1299 +Also a writable branch has three kinds of "whiteout bases". All these
1300 +are existed when the branch is joined to aufs, and their names are
1301 +whiteout-ed doubly, so that users will never see their names in aufs
1303 +1. a regular file which will be hardlinked to all whiteouts.
1304 +2. a directory to store a pseudo-link.
1305 +3. a directory to store an "orphan"-ed file temporary.
1308 + When you remove a file on a readonly branch, aufs handles it as a
1309 + logical deletion and creates a whiteout on the upper writable branch
1310 + as a hardlink of this file in order not to consume inode on the
1313 + See below, Pseudo-link.
1315 + When "fileC" exists on the lower readonly branch only and it is
1316 + opened and removed with its parent dir, and then user writes
1317 + something into it, then aufs copies-up fileC to this
1318 + directory. Because there is no other dir to store fileC. After
1319 + creating a file under this dir, the file is unlinked.
1321 +Because aufs supports manipulating branches, ie. add/delete/change
1322 +dynamically, a branch has its own id. When the branch order changes,
1323 +aufs finds the new index by searching the branch id.
1327 +----------------------------------------------------------------------
1328 +Assume "fileA" exists on the lower readonly branch only and it is
1329 +hardlinked to "fileB" on the branch. When you write something to fileA,
1330 +aufs copies-up it to the upper writable branch. Additionally aufs
1331 +creates a hardlink under the Pseudo-link Directory of the writable
1332 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1333 +simple list. If fileB is read after unlinking fileA, aufs returns
1334 +filedata from the pseudo-link instead of the lower readonly
1335 +branch. Because the pseudo-link is based upon the inode, to keep the
1336 +inode number by xino (see above) is essentially necessary.
1338 +All the hardlinks under the Pseudo-link Directory of the writable branch
1339 +should be restored in a proper location later. Aufs provides a utility
1340 +to do this. The userspace helpers executed at remounting and unmounting
1342 +During this utility is running, it puts aufs into the pseudo-link
1343 +maintenance mode. In this mode, only the process which began the
1344 +maintenance mode (and its child processes) is allowed to operate in
1345 +aufs. Some other processes which are not related to the pseudo-link will
1346 +be allowed to run too, but the rest have to return an error or wait
1347 +until the maintenance mode ends. If a process already acquires an inode
1348 +mutex (in VFS), it has to return an error.
1351 +XIB(external inode number bitmap)
1352 +----------------------------------------------------------------------
1353 +Addition to the xino file per a branch, aufs has an external inode number
1354 +bitmap in a superblock object. It is also an internal file such like a
1356 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1358 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1360 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1361 +reduce the number of consumed disk blocks for these files.
1364 +Virtual or Vertical Dir, and Readdir in Userspace
1365 +----------------------------------------------------------------------
1366 +In order to support multiple layers (branches), aufs readdir operation
1367 +constructs a virtual dir block on memory. For readdir, aufs calls
1368 +vfs_readdir() internally for each dir on branches, merges their entries
1369 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1370 +object. So the file object has its entry list until it is closed. The
1371 +entry list will be updated when the file position is zero and becomes
1372 +obsoleted. This decision is made in aufs automatically.
1374 +The dynamically allocated memory block for the name of entries has a
1375 +unit of 512 bytes (by default) and stores the names contiguously (no
1376 +padding). Another block for each entry is handled by kmem_cache too.
1377 +During building dir blocks, aufs creates hash list and judging whether
1378 +the entry is whiteouted by its upper branch or already listed.
1379 +The merged result is cached in the corresponding inode object and
1380 +maintained by a customizable life-time option.
1382 +Some people may call it can be a security hole or invite DoS attack
1383 +since the opened and once readdir-ed dir (file object) holds its entry
1384 +list and becomes a pressure for system memory. But I'd say it is similar
1385 +to files under /proc or /sys. The virtual files in them also holds a
1386 +memory page (generally) while they are opened. When an idea to reduce
1387 +memory for them is introduced, it will be applied to aufs too.
1388 +For those who really hate this situation, I've developed readdir(3)
1389 +library which operates this merging in userspace. You just need to set
1390 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1391 +kernel space for readdir(3).
1395 +----------------------------------------------------------------------
1396 +Aufs sometimes requires privilege access to a branch. For instance,
1397 +in copy-up/down operation. When a user process is going to make changes
1398 +to a file which exists in the lower readonly branch only, and the mode
1399 +of one of ancestor directories may not be writable by a user
1400 +process. Here aufs copy-up the file with its ancestors and they may
1401 +require privilege to set its owner/group/mode/etc.
1402 +This is a typical case of a application character of aufs (see
1405 +Aufs uses workqueue synchronously for this case. It creates its own
1406 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1407 +passes the request to call mkdir or write (for example), and wait for
1408 +its completion. This approach solves a problem of a signal handler
1410 +If aufs didn't adopt the workqueue and changed the privilege of the
1411 +process, then the process may receive the unexpected SIGXFSZ or other
1414 +Also aufs uses the system global workqueue ("events" kernel thread) too
1415 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1416 +whiteout base and etc. This is unrelated to a privilege.
1417 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1418 +superblock at the beginning, at the same time waits for the completion
1419 +of all queued asynchronous tasks.
1423 +----------------------------------------------------------------------
1424 +The whiteout in aufs is very similar to Unionfs's. That is represented
1425 +by its filename. UnionMount takes an approach of a file mode, but I am
1426 +afraid several utilities (find(1) or something) will have to support it.
1428 +Basically the whiteout represents "logical deletion" which stops aufs to
1429 +lookup further, but also it represents "dir is opaque" which also stop
1432 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1433 +In order to make several functions in a single systemcall to be
1434 +revertible, aufs adopts an approach to rename a directory to a temporary
1435 +unique whiteouted name.
1436 +For example, in rename(2) dir where the target dir already existed, aufs
1437 +renames the target dir to a temporary unique whiteouted name before the
1438 +actual rename on a branch, and then handles other actions (make it opaque,
1439 +update the attributes, etc). If an error happens in these actions, aufs
1440 +simply renames the whiteouted name back and returns an error. If all are
1441 +succeeded, aufs registers a function to remove the whiteouted unique
1442 +temporary name completely and asynchronously to the system global
1447 +----------------------------------------------------------------------
1448 +It is a well-known feature or concept.
1449 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1450 +internally and makes change to the new file on the upper writable branch.
1451 +When the trigger systemcall does not update the timestamps of the parent
1452 +dir, aufs reverts it after copy-up.
1455 +Move-down (aufs3.9 and later)
1456 +----------------------------------------------------------------------
1457 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1458 +the lower readonly branch to the upper writable branch when a user
1459 +changes something about the file.
1460 +"Move-down" is an opposite action of copy-up. Basically this action is
1461 +ran manually instead of automatically and internally.
1462 +For desgin and implementation, aufs has to consider these issues.
1463 +- whiteout for the file may exist on the lower branch.
1464 +- ancestor directories may not exist on the lower branch.
1465 +- diropq for the ancestor directories may exist on the upper branch.
1466 +- free space on the lower branch will reduce.
1467 +- another access to the file may happen during moving-down, including
1468 + UDBA (see "Revalidate Dentry and UDBA").
1469 +- the file should not be hard-linked nor pseudo-linked. they should be
1470 + handled by auplink utility later.
1472 +Sometimes users want to move-down a file from the upper writable branch
1473 +to the lower readonly or writable branch. For instance,
1474 +- the free space of the upper writable branch is going to run out.
1475 +- create a new intermediate branch between the upper and lower branch.
1478 +For this purpose, use "aumvdown" command in aufs-util.git.
1479 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1480 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1481 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-12-03 15:38:59.929980643 +0100
1484 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1486 +# This program is free software; you can redistribute it and/or modify
1487 +# it under the terms of the GNU General Public License as published by
1488 +# the Free Software Foundation; either version 2 of the License, or
1489 +# (at your option) any later version.
1491 +# This program is distributed in the hope that it will be useful,
1492 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1493 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1494 +# GNU General Public License for more details.
1496 +# You should have received a copy of the GNU General Public License
1497 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1499 +Support for a branch who has its ->atomic_open()
1500 +----------------------------------------------------------------------
1501 +The filesystems who implement its ->atomic_open() are not majority. For
1502 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1503 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1504 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1505 +sure whether all filesystems who have ->atomic_open() behave like this,
1506 +but NFSv4 surely returns the error.
1508 +In order to support ->atomic_open() for aufs, there are a few
1511 +A. Introduce aufs_atomic_open()
1512 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1514 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1515 + an aufs user Pip Cet's approach
1516 + - calls aufs_create(), VFS finish_open() and notify_change().
1517 + - pass fake-mode to finish_open(), and then correct the mode by
1519 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1520 + - no aufs_atomic_open().
1521 + - aufs_lookup() registers the TID to an aufs internal object.
1522 + - aufs_create() does nothing when the matching TID is registered, but
1523 + registers the mode.
1524 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1525 + TID is registered.
1526 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1528 + - no aufs_atomic_open().
1529 + - aufs_create() registers the TID to an internal object. this info
1530 + represents "this process created this file just now."
1531 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1532 + registered TID and re-try open() with superuser's credential.
1534 +Pros and cons for each approach.
1537 + - straightforward but highly depends upon VFS internal.
1538 + - the atomic behavaiour is kept.
1539 + - some of parameters such as nameidata are hard to reproduce for
1543 + - easy to implement.
1544 + - the atomic behavaiour is lost.
1546 + - the atomic behavaiour is kept.
1547 + - dirty and tricky.
1548 + - VFS checks whether the file is created correctly after calling
1549 + ->create(), which means this approach doesn't work.
1551 + - easy to implement.
1552 + - the atomic behavaiour is lost.
1553 + - to open a file with superuser's credential and give it to a user
1554 + process is a bad idea, since the file object keeps the credential
1555 + in it. It may affect LSM or something. This approach doesn't work
1558 +The approach A is ideal, but it hard to implement. So here is a
1559 +variation of A, which is to be implemented.
1561 +A-1. Introduce aufs_atomic_open()
1562 + - calls branch fs ->atomic_open() if exists. otherwise calls
1563 + vfs_create() and finish_open().
1564 + - the demerit is that the several checks after branch fs
1565 + ->atomic_open() are lost. in the ordinary case, the checks are
1566 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1567 + be implemented in aufs, but not all I am afraid.
1568 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1569 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1570 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-12-03 15:38:59.929980643 +0100
1573 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1575 +# This program is free software; you can redistribute it and/or modify
1576 +# it under the terms of the GNU General Public License as published by
1577 +# the Free Software Foundation; either version 2 of the License, or
1578 +# (at your option) any later version.
1580 +# This program is distributed in the hope that it will be useful,
1581 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1582 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1583 +# GNU General Public License for more details.
1585 +# You should have received a copy of the GNU General Public License
1586 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1589 +----------------------------------------------------------------------
1590 +Since aufs has a character of sub-VFS (see Introduction), it operates
1591 +lookup for branches as VFS does. It may be a heavy work. But almost all
1592 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1593 +directly connected to its parent. Digging down the directory hierarchy
1594 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1597 +When a branch is a remote filesystem, aufs basically relies upon its
1598 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1600 +For d_revalidate, aufs implements three levels of revalidate tests. See
1601 +"Revalidate Dentry and UDBA" in detail.
1604 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1605 +----------------------------------------------------------------------
1606 +Let's try case study.
1607 +- aufs has two branches, upper readwrite and lower readonly.
1609 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1610 +- user invoked "chmod a+rx /au/dirA"
1611 +- the internal copy-up is activated and "/rw/dirA" is created and its
1612 + permission bits are set to world readable.
1613 +- then "/au/dirA" becomes world readable?
1615 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1616 +or it may be a natively readonly filesystem. If aufs respects the lower
1617 +branch, it should not respond readdir request from other users. But user
1618 +allowed it by chmod. Should really aufs rejects showing the entries
1621 +To be honest, I don't have a good solution for this case. So aufs
1622 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1624 +When dirperm1 is specified, aufs checks only the highest one for the
1625 +directory permission, and shows the entries. Otherwise, as usual, checks
1626 +every dir existing on all branches and rejects the request.
1628 +As a side effect, dirperm1 option improves the performance of aufs
1629 +because the number of permission check is reduced when the number of
1633 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1634 +----------------------------------------------------------------------
1635 +Generally VFS helpers re-validate a dentry as a part of lookup.
1636 +0. digging down the directory hierarchy.
1637 +1. lock the parent dir by its i_mutex.
1638 +2. lookup the final (child) entry.
1640 +4. call the actual operation (create, unlink, etc.)
1641 +5. unlock the parent dir
1643 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1644 +called. Actually aufs implements it and checks the dentry on a branch is
1646 +But it is not enough. Because aufs has to release the lock for the
1647 +parent dir on a branch at the end of ->lookup() (step 2) and
1648 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1650 +If the file on a branch is changed directly, eg. bypassing aufs, after
1651 +aufs released the lock, then the subsequent operation may cause
1652 +something unpleasant result.
1654 +This situation is a result of VFS architecture, ->lookup() and
1655 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1656 +design from VFS's point of view. It is just not suitable for sub-VFS
1659 +Aufs supports such case by three level of revalidation which is
1660 +selectable by user.
1661 +1. Simple Revalidate
1662 + Addition to the native flow in VFS's, confirm the child-parent
1663 + relationship on the branch just after locking the parent dir on the
1664 + branch in the "actual operation" (step 4). When this validation
1665 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1666 + checks the validation of the dentry on branches.
1667 +2. Monitor Changes Internally by Inotify/Fsnotify
1668 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1669 + the dentry on the branch, and returns EBUSY if it finds different
1671 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1672 + during it is in cache. When the event is notified, aufs registers a
1673 + function to kernel 'events' thread by schedule_work(). And the
1674 + function sets some special status to the cached aufs dentry and inode
1675 + private data. If they are not cached, then aufs has nothing to
1676 + do. When the same file is accessed through aufs (step 0-3) later,
1677 + aufs will detect the status and refresh all necessary data.
1678 + In this mode, aufs has to ignore the event which is fired by aufs
1680 +3. No Extra Validation
1681 + This is the simplest test and doesn't add any additional revalidation
1682 + test, and skip the revalidation in step 4. It is useful and improves
1683 + aufs performance when system surely hide the aufs branches from user,
1684 + by over-mounting something (or another method).
1685 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1686 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1687 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-12-03 15:38:59.929980643 +0100
1690 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1692 +# This program is free software; you can redistribute it and/or modify
1693 +# it under the terms of the GNU General Public License as published by
1694 +# the Free Software Foundation; either version 2 of the License, or
1695 +# (at your option) any later version.
1697 +# This program is distributed in the hope that it will be useful,
1698 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1699 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1700 +# GNU General Public License for more details.
1702 +# You should have received a copy of the GNU General Public License
1703 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1705 +Branch Manipulation
1707 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1708 +and changing its permission/attribute, there are a lot of works to do.
1712 +----------------------------------------------------------------------
1713 +o Confirm the adding dir exists outside of aufs, including loopback
1714 + mount, and its various attributes.
1715 +o Initialize the xino file and whiteout bases if necessary.
1718 +o Check the owner/group/mode of the directory
1719 + When the owner/group/mode of the adding directory differs from the
1720 + existing branch, aufs issues a warning because it may impose a
1722 + For example, when a upper writable branch has a world writable empty
1723 + top directory, a malicious user can create any files on the writable
1724 + branch directly, like copy-up and modify manually. If something like
1725 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1726 + writable branch, and the writable branch is world-writable, then a
1727 + malicious guy may create /etc/passwd on the writable branch directly
1728 + and the infected file will be valid in aufs.
1729 + I am afraid it can be a security issue, but aufs can do nothing except
1730 + producing a warning.
1734 +----------------------------------------------------------------------
1735 +o Confirm the deleting branch is not busy
1736 + To be general, there is one merit to adopt "remount" interface to
1737 + manipulate branches. It is to discard caches. At deleting a branch,
1738 + aufs checks the still cached (and connected) dentries and inodes. If
1739 + there are any, then they are all in-use. An inode without its
1740 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1742 + For the cached one, aufs checks whether the same named entry exists on
1744 + If the cached one is a directory, because aufs provides a merged view
1745 + to users, as long as one dir is left on any branch aufs can show the
1746 + dir to users. In this case, the branch can be removed from aufs.
1747 + Otherwise aufs rejects deleting the branch.
1749 + If any file on the deleting branch is opened by aufs, then aufs
1753 +Modify the Permission of a Branch
1754 +----------------------------------------------------------------------
1755 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1758 +o rw --> ro: Confirm the modifying branch is not busy
1759 + Aufs rejects the request if any of these conditions are true.
1760 + - a file on the branch is mmap-ed.
1761 + - a regular file on the branch is opened for write and there is no
1762 + same named entry on the upper branch.
1763 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1764 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1765 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-12-03 15:38:59.929980643 +0100
1768 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1770 +# This program is free software; you can redistribute it and/or modify
1771 +# it under the terms of the GNU General Public License as published by
1772 +# the Free Software Foundation; either version 2 of the License, or
1773 +# (at your option) any later version.
1775 +# This program is distributed in the hope that it will be useful,
1776 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1777 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1778 +# GNU General Public License for more details.
1780 +# You should have received a copy of the GNU General Public License
1781 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1783 +Policies to Select One among Multiple Writable Branches
1784 +----------------------------------------------------------------------
1785 +When the number of writable branch is more than one, aufs has to decide
1786 +the target branch for file creation or copy-up. By default, the highest
1787 +writable branch which has the parent (or ancestor) dir of the target
1788 +file is chosen (top-down-parent policy).
1789 +By user's request, aufs implements some other policies to select the
1790 +writable branch, for file creation several policies, round-robin,
1791 +most-free-space, and other policies. For copy-up, top-down-parent,
1792 +bottom-up-parent, bottom-up and others.
1794 +As expected, the round-robin policy selects the branch in circular. When
1795 +you have two writable branches and creates 10 new files, 5 files will be
1796 +created for each branch. mkdir(2) systemcall is an exception. When you
1797 +create 10 new directories, all will be created on the same branch.
1798 +And the most-free-space policy selects the one which has most free
1799 +space among the writable branches. The amount of free space will be
1800 +checked by aufs internally, and users can specify its time interval.
1802 +The policies for copy-up is more simple,
1803 +top-down-parent is equivalent to the same named on in create policy,
1804 +bottom-up-parent selects the writable branch where the parent dir
1805 +exists and the nearest upper one from the copyup-source,
1806 +bottom-up selects the nearest upper writable branch from the
1807 +copyup-source, regardless the existence of the parent dir.
1809 +There are some rules or exceptions to apply these policies.
1810 +- If there is a readonly branch above the policy-selected branch and
1811 + the parent dir is marked as opaque (a variation of whiteout), or the
1812 + target (creating) file is whiteout-ed on the upper readonly branch,
1813 + then the result of the policy is ignored and the target file will be
1814 + created on the nearest upper writable branch than the readonly branch.
1815 +- If there is a writable branch above the policy-selected branch and
1816 + the parent dir is marked as opaque or the target file is whiteouted
1817 + on the branch, then the result of the policy is ignored and the target
1818 + file will be created on the highest one among the upper writable
1819 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1821 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1822 + They try selecting the branch where the source exists as possible
1823 + since copyup a large file will take long time. If it can't be,
1824 + ie. the branch where the source exists is readonly, then they will
1825 + follow the copyup policy.
1826 +- There is an exception for rename(2) when the target exists.
1827 + If the rename target exists, aufs compares the index of the branches
1828 + where the source and the target exists and selects the higher
1829 + one. If the selected branch is readonly, then aufs follows the
1831 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1832 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1833 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-12-03 15:38:59.929980643 +0100
1836 +// to view this graph, run dot(1) command in GRAPHVIZ.
1840 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1844 +aufs_rename -> whinfo [label="store/remove"];
1847 +inode_list [label="h_inum list in branch\ncache"];
1850 +whinode [label="h_inum list file"];
1853 +brmgmt [label="br_add/del/mod/umount"];
1855 +brmgmt -> inode_list [label="create/remove"];
1856 +brmgmt -> whinode [label="load/store"];
1858 +inode_list -> whinode [style=dashed,dir=both];
1860 +aufs_rename -> inode_list [label="add/del"];
1862 +aufs_lookup -> inode_list [label="search"];
1864 +aufs_lookup -> whinfo [label="load/remove"];
1866 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1867 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1868 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-12-03 15:38:59.929980643 +0100
1871 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1873 +# This program is free software; you can redistribute it and/or modify
1874 +# it under the terms of the GNU General Public License as published by
1875 +# the Free Software Foundation; either version 2 of the License, or
1876 +# (at your option) any later version.
1878 +# This program is distributed in the hope that it will be useful,
1879 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1880 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1881 +# GNU General Public License for more details.
1883 +# You should have received a copy of the GNU General Public License
1884 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1886 +Special handling for renaming a directory (DIRREN)
1887 +----------------------------------------------------------------------
1888 +First, let's assume we have a simple usecase.
1892 +- /ro/dirA and /ro/dirA/file exist too
1893 +- there is no dirB on both branches
1894 +- a user issues rename("dirA", "dirB")
1896 +Now, what should aufs behave against this rename(2)?
1897 +There are a few possible cases.
1900 + since dirA exists on a readonly branch which cannot be renamed.
1902 + it is possible to copy-up dirA (only the dir itself), but the child
1903 + entries ("file" in this case) should not be. it must be a bad
1904 + approach to copy-up recursively.
1905 +C. returns a success.
1906 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1907 + is a violation of aufs' policy.
1908 +D. construct an extra information which indicates that /ro/dirA should
1909 + be handled as the name of dirB.
1910 + overlayfs has a similar feature called REDIRECT.
1912 +Until now, aufs implements the case B only which returns EXDEV, and
1913 +expects the userspace application behaves like mv(1) which tries
1914 +issueing rename(2) recursively.
1916 +A new aufs feature called DIRREN is introduced which implements the case
1917 +D. There are several "extra information" added.
1919 +1. detailed info per renamed directory
1920 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1921 +2. the inode-number list of directories on a branch
1922 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1924 +The filename of "detailed info per directory" represents the lower
1925 +branch, and its format is
1926 +- a type of the branch id
1928 + + uuid (not implemented yet)
1931 +- the inode-number of the branch root dir
1933 +And it contains these info in a single regular file.
1935 +- branch's inode-number of the logically renamed dir
1936 +- the name of the before-renamed dir
1938 +The "detailed info per directory" file is created in aufs rename(2), and
1939 +loaded in any lookup.
1940 +The info is considered in lookup for the matching case only. Here
1941 +"matching" means that the root of branch (in the info filename) is same
1942 +to the current looking-up branch. After looking-up the before-renamed
1943 +name, the inode-number is compared. And the matched dentry is used.
1945 +The "inode-number list of directories" is a regular file which contains
1946 +simply the inode-numbers on the branch. The file is created or updated
1947 +in removing the branch, and loaded in adding the branch. Its lifetime is
1948 +equal to the branch.
1949 +The list is refered in lookup, and when the current target inode is
1950 +found in the list, the aufs tries loading the "detailed info per
1951 +directory" and get the changed and valid name of the dir.
1953 +Theoretically these "extra informaiton" may be able to be put into XATTR
1954 +in the dir inode. But aufs doesn't choose this way because
1955 +1. XATTR may not be supported by the branch (or its configuration)
1956 +2. XATTR may have its size limit.
1957 +3. XATTR may be less easy to convert than a regular file, when the
1958 + format of the info is changed in the future.
1959 +At the same time, I agree that the regular file approach is much slower
1960 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1963 +This DIRREN feature is enabled by aufs configuration, and is activated
1964 +by a new mount option.
1966 +For the more complicated case, there is a work with UDBA option, which
1967 +is to dected the direct access to the branches (by-passing aufs) and to
1968 +maintain the cashes in aufs. Since a single cached aufs dentry may
1969 +contains two names, before- and after-rename, the name comparision in
1970 +UDBA handler may not work correctly. In this case, the behaviour will be
1971 +equivalen to udba=reval case.
1972 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1973 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1974 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-12-03 15:38:59.929980643 +0100
1977 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1979 +# This program is free software; you can redistribute it and/or modify
1980 +# it under the terms of the GNU General Public License as published by
1981 +# the Free Software Foundation; either version 2 of the License, or
1982 +# (at your option) any later version.
1984 +# This program is distributed in the hope that it will be useful,
1985 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1986 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1987 +# GNU General Public License for more details.
1989 +# You should have received a copy of the GNU General Public License
1990 +# along with this program; if not, write to the Free Software
1991 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1994 +File-based Hierarchical Storage Management (FHSM)
1995 +----------------------------------------------------------------------
1996 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1997 +storage world. Aufs provides this feature as file-based with multiple
1998 +writable branches, based upon the principle of "Colder, the Lower".
1999 +Here the word "colder" means that the less used files, and "lower" means
2000 +that the position in the order of the stacked branches vertically.
2001 +These multiple writable branches are prioritized, ie. the topmost one
2002 +should be the fastest drive and be used heavily.
2004 +o Characters in aufs FHSM story
2005 +- aufs itself and a new branch attribute.
2006 +- a new ioctl interface to move-down and to establish a connection with
2007 + the daemon ("move-down" is a converse of "copy-up").
2008 +- userspace tool and daemon.
2010 +The userspace daemon establishes a connection with aufs and waits for
2011 +the notification. The notified information is very similar to struct
2012 +statfs containing the number of consumed blocks and inodes.
2013 +When the consumed blocks/inodes of a branch exceeds the user-specified
2014 +upper watermark, the daemon activates its move-down process until the
2015 +consumed blocks/inodes reaches the user-specified lower watermark.
2017 +The actual move-down is done by aufs based upon the request from
2018 +user-space since we need to maintain the inode number and the internal
2019 +pointer arrays in aufs.
2021 +Currently aufs FHSM handles the regular files only. Additionally they
2022 +must not be hard-linked nor pseudo-linked.
2025 +o Cowork of aufs and the user-space daemon
2026 + During the userspace daemon established the connection, aufs sends a
2027 + small notification to it whenever aufs writes something into the
2028 + writable branch. But it may cost high since aufs issues statfs(2)
2029 + internally. So user can specify a new option to cache the
2030 + info. Actually the notification is controlled by these factors.
2031 + + the specified cache time.
2032 + + classified as "force" by aufs internally.
2033 + Until the specified time expires, aufs doesn't send the info
2034 + except the forced cases. When aufs decide forcing, the info is always
2035 + notified to userspace.
2036 + For example, the number of free inodes is generally large enough and
2037 + the shortage of it happens rarely. So aufs doesn't force the
2038 + notification when creating a new file, directory and others. This is
2039 + the typical case which aufs doesn't force.
2040 + When aufs writes the actual filedata and the files consumes any of new
2041 + blocks, the aufs forces notifying.
2044 +o Interfaces in aufs
2045 +- New branch attribute.
2047 + Specifies that the branch is managed by FHSM feature. In other word,
2048 + participant in the FHSM.
2049 + When nofhsm is set to the branch, it will not be the source/target
2050 + branch of the move-down operation. This attribute is set
2051 + independently from coo and moo attributes, and if you want full
2052 + FHSM, you should specify them as well.
2053 +- New mount option.
2055 + Specifies a second to suppress many less important info to be
2058 + + AUFS_CTL_FHSM_FD
2059 + create a new file descriptor which userspace can read the notification
2060 + (a subset of struct statfs) from aufs.
2061 +- Module parameter 'brs'
2062 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2064 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2065 + When there are two or more branches with fhsm attributes,
2066 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2067 + terminates it. As a result of remounting and branch-manipulation, the
2068 + number of branches with fhsm attribute can be one. In this case,
2069 + /sbin/mount.aufs will terminate the user-space daemon.
2072 +Finally the operation is done as these steps in kernel-space.
2074 + + no one else is using the file.
2075 + + the file is not hard-linked.
2076 + + the file is not pseudo-linked.
2077 + + the file is a regular file.
2078 + + the parent dir is not opaqued.
2079 +- find the target writable branch.
2080 +- make sure the file is not whiteout-ed by the upper (than the target)
2082 +- make the parent dir on the target branch.
2083 +- mutex lock the inode on the branch.
2084 +- unlink the whiteout on the target branch (if exists).
2085 +- lookup and create the whiteout-ed temporary name on the target branch.
2086 +- copy the file as the whiteout-ed temporary name on the target branch.
2087 +- rename the whiteout-ed temporary name to the original name.
2088 +- unlink the file on the source branch.
2089 +- maintain the internal pointer array and the external inode number
2091 +- maintain the timestamps and other attributes of the parent dir and the
2094 +And of course, in every step, an error may happen. So the operation
2095 +should restore the original file state after an error happens.
2096 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2097 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2098 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-12-03 15:38:59.929980643 +0100
2101 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2103 +# This program is free software; you can redistribute it and/or modify
2104 +# it under the terms of the GNU General Public License as published by
2105 +# the Free Software Foundation; either version 2 of the License, or
2106 +# (at your option) any later version.
2108 +# This program is distributed in the hope that it will be useful,
2109 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2110 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2111 +# GNU General Public License for more details.
2113 +# You should have received a copy of the GNU General Public License
2114 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2116 +mmap(2) -- File Memory Mapping
2117 +----------------------------------------------------------------------
2118 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2119 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2121 +This approach is simple and good, but there is one problem.
2122 +Under /proc, several entries show the mmapped files by its path (with
2123 +device and inode number), and the printed path will be the path on the
2124 +branch fs's instead of virtual aufs's.
2125 +This is not a problem in most cases, but some utilities lsof(1) (and its
2126 +user) may expect the path on aufs.
2128 +To address this issue, aufs adds a new member called vm_prfile in struct
2129 +vm_area_struct (and struct vm_region). The original vm_file points to
2130 +the file on the branch fs in order to handle everything correctly as
2131 +usual. The new vm_prfile points to a virtual file in aufs, and the
2132 +show-functions in procfs refers to vm_prfile if it is set.
2133 +Also we need to maintain several other places where touching vm_file
2135 +- fork()/clone() copies vma and the reference count of vm_file is
2137 +- merging vma maintains the ref count too.
2139 +This is not a good approach. It just fakes the printed path. But it
2140 +leaves all behaviour around f_mapping unchanged. This is surely an
2142 +Actually aufs had adopted another complicated approach which calls
2143 +generic_file_mmap() and handles struct vm_operations_struct. In this
2144 +approach, aufs met a hard problem and I could not solve it without
2145 +switching the approach.
2147 +There may be one more another approach which is
2148 +- bind-mount the branch-root onto the aufs-root internally
2149 +- grab the new vfsmount (ie. struct mount)
2150 +- lazy-umount the branch-root internally
2151 +- in open(2) the aufs-file, open the branch-file with the hidden
2152 + vfsmount (instead of the original branch's vfsmount)
2153 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2154 + but it may be possible from userspace by the mount helper.
2156 +Adding the internal hidden vfsmount and using it in opening a file, the
2157 +file path under /proc will be printed correctly. This approach looks
2158 +smarter, but is not possible I am afraid.
2159 +- aufs-root may be bind-mount later. when it happens, another hidden
2160 + vfsmount will be required.
2161 +- it is hard to get the chance to bind-mount and lazy-umount
2162 + + in kernel-space, FS can have vfsmount in open(2) via
2163 + file->f_path, and aufs can know its vfsmount. But several locks are
2164 + already acquired, and if aufs tries to bind-mount and lazy-umount
2165 + here, then it may cause a deadlock.
2166 + + in user-space, bind-mount doesn't invoke the mount helper.
2167 +- since /proc shows dev and ino, aufs has to give vma these info. it
2168 + means a new member vm_prinode will be necessary. this is essentially
2169 + equivalent to vm_prfile described above.
2171 +I have to give up this "looks-smater" approach.
2172 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2173 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2174 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-12-03 15:38:59.929980643 +0100
2177 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2179 +# This program is free software; you can redistribute it and/or modify
2180 +# it under the terms of the GNU General Public License as published by
2181 +# the Free Software Foundation; either version 2 of the License, or
2182 +# (at your option) any later version.
2184 +# This program is distributed in the hope that it will be useful,
2185 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2186 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2187 +# GNU General Public License for more details.
2189 +# You should have received a copy of the GNU General Public License
2190 +# along with this program; if not, write to the Free Software
2191 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2194 +Listing XATTR/EA and getting the value
2195 +----------------------------------------------------------------------
2196 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2197 +shows the values from the topmost existing file. This behaviour is good
2198 +for the non-dir entries since the bahaviour exactly matches the shown
2199 +information. But for the directories, aufs considers all the same named
2200 +entries on the lower branches. Which means, if one of the lower entry
2201 +rejects readdir call, then aufs returns an error even if the topmost
2202 +entry allows it. This behaviour is necessary to respect the branch fs's
2203 +security, but can make users confused since the user-visible standard
2204 +attributes don't match the behaviour.
2205 +To address this issue, aufs has a mount option called dirperm1 which
2206 +checks the permission for the topmost entry only, and ignores the lower
2207 +entry's permission.
2209 +A similar issue can happen around XATTR.
2210 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2211 +always set. Otherwise these very unpleasant situation would happen.
2212 +- listxattr(2) may return the duplicated entries.
2213 +- users may not be able to remove or reset the XATTR forever,
2216 +XATTR/EA support in the internal (copy,move)-(up,down)
2217 +----------------------------------------------------------------------
2218 +Generally the extended attributes of inode are categorized as these.
2219 +- "security" for LSM and capability.
2220 +- "system" for posix ACL, 'acl' mount option is required for the branch
2222 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2223 +- "user" for userspace, 'user_xattr' mount option is required for the
2224 + branch fs generally.
2226 +Moreover there are some other categories. Aufs handles these rather
2227 +unpopular categories as the ordinary ones, ie. there is no special
2228 +condition nor exception.
2230 +In copy-up, the support for XATTR on the dst branch may differ from the
2231 +src branch. In this case, the copy-up operation will get an error and
2232 +the original user operation which triggered the copy-up will fail. It
2233 +can happen that even all copy-up will fail.
2234 +When both of src and dst branches support XATTR and if an error occurs
2235 +during copying XATTR, then the copy-up should fail obviously. That is a
2236 +good reason and aufs should return an error to userspace. But when only
2237 +the src branch support that XATTR, aufs should not return an error.
2238 +For example, the src branch supports ACL but the dst branch doesn't
2239 +because the dst branch may natively un-support it or temporary
2240 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2241 +may NOT return an error even if the XATTR is not supported. It is
2242 +totally up to the branch fs.
2244 +Anyway when the aufs internal copy-up gets an error from the dst branch
2245 +fs, then aufs tries removing the just copied entry and returns the error
2246 +to the userspace. The worst case of this situation will be all copy-up
2249 +For the copy-up operation, there two basic approaches.
2250 +- copy the specified XATTR only (by category above), and return the
2251 + error unconditionally if it happens.
2252 +- copy all XATTR, and ignore the error on the specified category only.
2254 +In order to support XATTR and to implement the correct behaviour, aufs
2255 +chooses the latter approach and introduces some new branch attributes,
2256 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2257 +They correspond to the XATTR namespaces (see above). Additionally, to be
2258 +convenient, "icex" is also provided which means all "icex*" attributes
2259 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2261 +The meaning of these attributes is to ignore the error from setting
2262 +XATTR on that branch.
2263 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2264 +error from the dst branch according to the specified attributes.
2266 +Some XATTR may have its default value. The default value may come from
2267 +the parent dir or the environment. If the default value is set at the
2268 +file creating-time, it will be overwritten by copy-up.
2269 +Some contradiction may happen I am afraid.
2270 +Do we need another attribute to stop copying XATTR? I am unsure. For
2271 +now, aufs implements the branch attributes to ignore the error.
2272 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2273 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2274 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-12-03 15:38:59.929980643 +0100
2277 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2279 +# This program is free software; you can redistribute it and/or modify
2280 +# it under the terms of the GNU General Public License as published by
2281 +# the Free Software Foundation; either version 2 of the License, or
2282 +# (at your option) any later version.
2284 +# This program is distributed in the hope that it will be useful,
2285 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2286 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2287 +# GNU General Public License for more details.
2289 +# You should have received a copy of the GNU General Public License
2290 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2292 +Export Aufs via NFS
2293 +----------------------------------------------------------------------
2294 +Here is an approach.
2295 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2297 +- iget_locked(): initialize aufs inode generation for a new inode, and
2298 + store it in xigen file.
2299 +- destroy_inode(): increment aufs inode generation and store it in xigen
2300 + file. it is necessary even if it is not unlinked, because any data of
2301 + inode may be changed by UDBA.
2302 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2303 + build file handle by
2304 + + branch id (4 bytes)
2305 + + superblock generation (4 bytes)
2306 + + inode number (4 or 8 bytes)
2307 + + parent dir inode number (4 or 8 bytes)
2308 + + inode generation (4 bytes))
2309 + + return value of exportfs_encode_fh() for the parent on a branch (4
2311 + + file handle for a branch (by exportfs_encode_fh())
2313 + + find the index of a branch from its id in handle, and check it is
2314 + still exist in aufs.
2315 + + 1st level: get the inode number from handle and search it in cache.
2316 + + 2nd level: if not found in cache, get the parent inode number from
2317 + the handle and search it in cache. and then open the found parent
2318 + dir, find the matching inode number by vfs_readdir() and get its
2319 + name, and call lookup_one_len() for the target dentry.
2320 + + 3rd level: if the parent dir is not cached, call
2321 + exportfs_decode_fh() for a branch and get the parent on a branch,
2322 + build a pathname of it, convert it a pathname in aufs, call
2323 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2325 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2326 + for every branch, but not itself. to get this, (currently) aufs
2327 + searches in current->nsproxy->mnt_ns list. it may not be a good
2328 + idea, but I didn't get other approach.
2329 + + test the generation of the gotten inode.
2330 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2331 + convert it into ESTALE for NFSD.
2332 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2333 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2334 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2335 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2336 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-12-03 15:38:59.929980643 +0100
2339 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2341 +# This program is free software; you can redistribute it and/or modify
2342 +# it under the terms of the GNU General Public License as published by
2343 +# the Free Software Foundation; either version 2 of the License, or
2344 +# (at your option) any later version.
2346 +# This program is distributed in the hope that it will be useful,
2347 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2348 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2349 +# GNU General Public License for more details.
2351 +# You should have received a copy of the GNU General Public License
2352 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2354 +Show Whiteout Mode (shwh)
2355 +----------------------------------------------------------------------
2356 +Generally aufs hides the name of whiteouts. But in some cases, to show
2357 +them is very useful for users. For instance, creating a new middle layer
2358 +(branch) by merging existing layers.
2360 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2361 +When you have three branches,
2362 +- Bottom: 'system', squashfs (underlying base system), read-only
2363 +- Middle: 'mods', squashfs, read-only
2364 +- Top: 'overlay', ram (tmpfs), read-write
2366 +The top layer is loaded at boot time and saved at shutdown, to preserve
2367 +the changes made to the system during the session.
2368 +When larger changes have been made, or smaller changes have accumulated,
2369 +the size of the saved top layer data grows. At this point, it would be
2370 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2371 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2372 +restoring save and load speed.
2374 +This merging is simplified by the use of another aufs mount, of just the
2375 +two overlay branches using the 'shwh' option.
2376 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2377 + aufs /livesys/merge_union
2379 +A merged view of these two branches is then available at
2380 +/livesys/merge_union, and the new feature is that the whiteouts are
2382 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2383 +writing to all branches. Also the default mode for all branches is 'ro'.
2384 +It is now possible to save the combined contents of the two overlay
2385 +branches to a new squashfs, e.g.:
2386 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2388 +This new squashfs archive can be stored on the boot device and the
2389 +initramfs will use it to replace the old one at the next boot.
2390 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2391 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2392 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-12-03 15:38:59.929980643 +0100
2395 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2397 +# This program is free software; you can redistribute it and/or modify
2398 +# it under the terms of the GNU General Public License as published by
2399 +# the Free Software Foundation; either version 2 of the License, or
2400 +# (at your option) any later version.
2402 +# This program is distributed in the hope that it will be useful,
2403 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2404 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2405 +# GNU General Public License for more details.
2407 +# You should have received a copy of the GNU General Public License
2408 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2410 +Dynamically customizable FS operations
2411 +----------------------------------------------------------------------
2412 +Generally FS operations (struct inode_operations, struct
2413 +address_space_operations, struct file_operations, etc.) are defined as
2414 +"static const", but it never means that FS have only one set of
2415 +operation. Some FS have multiple sets of them. For instance, ext2 has
2416 +three sets, one for XIP, for NOBH, and for normal.
2417 +Since aufs overrides and redirects these operations, sometimes aufs has
2418 +to change its behaviour according to the branch FS type. More importantly
2419 +VFS acts differently if a function (member in the struct) is set or
2420 +not. It means aufs should have several sets of operations and select one
2421 +among them according to the branch FS definition.
2423 +In order to solve this problem and not to affect the behaviour of VFS,
2424 +aufs defines these operations dynamically. For instance, aufs defines
2425 +dummy direct_IO function for struct address_space_operations, but it may
2426 +not be set to the address_space_operations actually. When the branch FS
2427 +doesn't have it, aufs doesn't set it to its address_space_operations
2428 +while the function definition itself is still alive. So the behaviour
2429 +itself will not change, and it will return an error when direct_IO is
2432 +The lifetime of these dynamically generated operation object is
2433 +maintained by aufs branch object. When the branch is removed from aufs,
2434 +the reference counter of the object is decremented. When it reaches
2435 +zero, the dynamically generated operation object will be freed.
2437 +This approach is designed to support AIO (io_submit), Direct I/O and
2439 +Currently this approach is applied to address_space_operations for
2440 +regular files only.
2441 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2442 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2443 +++ linux/Documentation/filesystems/aufs/README 2021-12-03 15:40:58.233313963 +0100
2446 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2452 +----------------------------------------
2453 +In the early days, aufs was entirely re-designed and re-implemented
2454 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2455 +improvements and implementations, it became totally different from
2456 +Unionfs while keeping the basic features.
2457 +Later, Unionfs Version 2.x series began taking some of the same
2458 +approaches to aufs1's.
2459 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2460 +University and his team.
2462 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2464 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2465 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2466 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2467 + or aufs1 from CVS on SourceForge.
2469 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2470 + According to Christoph Hellwig, linux rejects all union-type
2471 + filesystems but UnionMount.
2472 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2474 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2475 + UnionMount, and he pointed out an issue around a directory mutex
2476 + lock and aufs addressed it. But it is still unsure whether aufs will
2477 + be merged (or any other union solution).
2478 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2482 +----------------------------------------
2483 +- unite several directories into a single virtual filesystem. The member
2484 + directory is called as a branch.
2485 +- you can specify the permission flags to the branch, which are 'readonly',
2486 + 'readwrite' and 'whiteout-able.'
2487 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2488 + readonly branch are modifiable logically.
2489 +- dynamic branch manipulation, add, del.
2492 +Also there are many enhancements in aufs, such as:
2493 +- test only the highest one for the directory permission (dirperm1)
2494 +- copyup on open (coo=)
2495 +- 'move' policy for copy-up between two writable branches, after
2496 + checking free space.
2498 +- readdir(3) in userspace.
2499 +- keep inode number by external inode number table
2500 +- keep the timestamps of file/dir in internal copyup operation
2501 +- seekable directory, supporting NFS readdir.
2502 +- whiteout is hardlinked in order to reduce the consumption of inodes
2504 +- do not copyup, nor create a whiteout when it is unnecessary
2505 +- revert a single systemcall when an error occurs in aufs
2506 +- remount interface instead of ioctl
2507 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2508 +- loopback mounted filesystem as a branch
2509 +- kernel thread for removing the dir who has a plenty of whiteouts
2510 +- support copyup sparse file (a file which has a 'hole' in it)
2511 +- default permission flags for branches
2512 +- selectable permission flags for ro branch, whether whiteout can
2515 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2516 +- support multiple writable branches, some policies to select one
2517 + among multiple writable branches.
2518 +- a new semantics for link(2) and rename(2) to support multiple
2519 + writable branches.
2520 +- no glibc changes are required.
2521 +- pseudo hardlink (hardlink over branches)
2522 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2523 + including NFS or remote filesystem branch.
2524 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2527 +Currently these features are dropped temporary from aufs5.
2528 +See design/08plan.txt in detail.
2529 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2531 +- statistics of aufs thread (/sys/fs/aufs/stat)
2533 +Features or just an idea in the future (see also design/*.txt),
2534 +- reorder the branch index without del/re-add.
2535 +- permanent xino files for NFSD
2536 +- an option for refreshing the opened files after add/del branches
2537 +- light version, without branch manipulation. (unnecessary?)
2538 +- copyup in userspace
2539 +- inotify in userspace
2544 +----------------------------------------
2545 +There are three GIT trees for aufs5, aufs5-linux.git,
2546 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2548 +While the aufs-util is always necessary, you need either of aufs5-linux
2549 +or aufs5-standalone.
2551 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2552 +git://git.kernel.org/.../torvalds/linux.git.
2553 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2554 +build aufs5 as an external kernel module.
2555 +Several extra patches are not included in this tree. Only
2556 +aufs5-standalone tree contains them. They are described in the later
2557 +section "Configuration and Compilation."
2559 +On the other hand, the aufs5-standalone tree has only aufs source files
2560 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2561 +But you need to apply all aufs patches manually.
2563 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2564 +represents the linux kernel version, "linux-5.x". For instance,
2565 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2566 +"aufs5.x-rcN" branch.
2569 +$ git clone --reference /your/linux/git/tree \
2570 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2571 +- if you don't have linux GIT tree, then remove "--reference ..."
2572 +$ cd aufs5-linux.git
2573 +$ git checkout origin/aufs5.0
2575 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2576 +leave the patch-work to GIT.
2577 +$ cd /your/linux/git/tree
2578 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2580 +$ git checkout -b my5.0 v5.0
2581 +$ (add your local change...)
2582 +$ git pull aufs5 aufs5.0
2583 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2584 +- you may need to solve some conflicts between your_changes and
2585 + aufs5.0. in this case, git-rerere is recommended so that you can
2586 + solve the similar conflicts automatically when you upgrade to 5.1 or
2587 + later in the future.
2589 +o aufs5-standalone tree
2590 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2591 +$ cd aufs5-standalone.git
2592 +$ git checkout origin/aufs5.0
2595 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2596 +- note that the public aufs-util.git is on SourceForge instead of
2599 +$ git checkout origin/aufs5.0
2601 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2602 +The minor version number, 'x' in '5.x', of aufs may not always
2603 +follow the minor version number of the kernel.
2604 +Because changes in the kernel that cause the use of a new
2605 +minor version number do not always require changes to aufs-util.
2607 +Since aufs-util has its own minor version number, you may not be
2608 +able to find a GIT branch in aufs-util for your kernel's
2609 +exact minor version number.
2610 +In this case, you should git-checkout the branch for the
2611 +nearest lower number.
2613 +For (an unreleased) example:
2614 +If you are using "linux-5.10" and the "aufs5.10" branch
2615 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2616 +or something numerically smaller is the branch for your kernel.
2618 +Also you can view all branches by
2622 +3. Configuration and Compilation
2623 +----------------------------------------
2624 +Make sure you have git-checkout'ed the correct branch.
2626 +For aufs5-linux tree,
2627 +- enable CONFIG_AUFS_FS.
2628 +- set other aufs configurations if necessary.
2629 +- for aufs5.13 and later
2630 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2631 + also a caller of VFS functions for branch filesystems, subclassing of
2632 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2633 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2634 + need to customize some LOCKDEP numbers. Here are what I use on my
2636 + CONFIG_LOCKDEP_BITS=21
2637 + CONFIG_LOCKDEP_CHAINS_BITS=21
2638 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2640 +For aufs5-standalone tree,
2641 +There are several ways to build.
2644 +- apply ./aufs5-kbuild.patch to your kernel source files.
2645 +- apply ./aufs5-base.patch too.
2646 +- apply ./aufs5-mmap.patch too.
2647 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2648 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2649 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2650 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2651 +- enable CONFIG_AUFS_FS, you can select either
2653 +- and build your kernel as usual.
2654 +- install the built kernel.
2655 +- install the header files too by "make headers_install" to the
2656 + directory where you specify. By default, it is $PWD/usr.
2657 + "make help" shows a brief note for headers_install.
2658 +- and reboot your system.
2661 +- module only (CONFIG_AUFS_FS=m).
2662 +- apply ./aufs5-base.patch to your kernel source files.
2663 +- apply ./aufs5-mmap.patch too.
2664 +- apply ./aufs5-standalone.patch too.
2665 +- build your kernel, don't forget "make headers_install", and reboot.
2666 +- edit ./config.mk and set other aufs configurations if necessary.
2667 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2668 + every aufs configurations.
2669 +- build the module by simple "make".
2670 +- you can specify ${KDIR} make variable which points to your kernel
2672 +- install the files
2673 + + run "make install" to install the aufs module, or copy the built
2674 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2675 + + run "make install_headers" (instead of headers_install) to install
2676 + the modified aufs header file (you can specify DESTDIR which is
2677 + available in aufs standalone version's Makefile only), or copy
2678 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2679 + you like manually. By default, the target directory is $PWD/usr.
2680 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2681 + kernel source tree.
2683 +Note: The header file aufs_type.h is necessary to build aufs-util
2684 + as well as "make headers_install" in the kernel source tree.
2685 + headers_install is subject to be forgotten, but it is essentially
2686 + necessary, not only for building aufs-util.
2687 + You may not meet problems without headers_install in some older
2691 +- read README in aufs-util, build and install it
2692 +- note that your distribution may contain an obsoleted version of
2693 + aufs_type.h in /usr/include/linux or something. When you build aufs
2694 + utilities, make sure that your compiler refers the correct aufs header
2695 + file which is built by "make headers_install."
2696 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2697 + then run "make install_ulib" too. And refer to the aufs manual in
2700 +There several other patches in aufs5-standalone.git. They are all
2701 +optional. When you meet some problems, they will help you.
2702 +- aufs5-loopback.patch
2703 + Supports a nested loopback mount in a branch-fs. This patch is
2704 + unnecessary until aufs produces a message like "you may want to try
2705 + another patch for loopback file".
2707 + Modifies a system global kernel internal function get_next_ino() in
2708 + order to stop assigning 0 for an inode-number. Not directly related to
2709 + aufs, but recommended generally.
2711 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2712 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2713 + duplication of inode number, which is important for backup tools and
2714 + other utilities. When you find aufs XINO files for tmpfs branch
2715 + growing too much, try this patch.
2719 +----------------------------------------
2720 +At first, make sure aufs-util are installed, and please read the aufs
2721 +manual, aufs.5 in aufs-util.git tree.
2725 +$ mkdir /tmp/rw /tmp/aufs
2726 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2728 +Here is another example. The result is equivalent.
2729 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2731 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2732 +# mount -o remount,append:${HOME} /tmp/aufs
2734 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2735 +you modify a file under /tmp/aufs, the one on your home directory is
2736 +not affected, instead the same named file will be newly created under
2737 +/tmp/rw. And all of your modification to a file will be applied to
2738 +the one under /tmp/rw. This is called the file based Copy on Write
2740 +Aufs mount options are described in aufs.5.
2741 +If you run chroot or something and make your aufs as a root directory,
2742 +then you need to customize the shutdown script. See the aufs manual in
2745 +Additionally, there are some sample usages of aufs which are a
2746 +diskless system with network booting, and LiveCD over NFS.
2747 +See sample dir in CVS tree on SourceForge.
2751 +----------------------------------------
2752 +When you have any problems or strange behaviour in aufs, please let me
2754 +- /proc/mounts (instead of the output of mount(8))
2755 +- /sys/module/aufs/*
2756 +- /sys/fs/aufs/* (if you have them)
2757 +- /debug/aufs/* (if you have them)
2758 +- linux kernel version
2759 + if your kernel is not plain, for example modified by distributor,
2760 + the url where i can download its source is necessary too.
2761 +- aufs version which was printed at loading the module or booting the
2762 + system, instead of the date you downloaded.
2763 +- configuration (define/undefine CONFIG_AUFS_xxx)
2764 +- kernel configuration or /proc/config.gz (if you have it)
2765 +- LSM (linux security module, if you are using)
2766 +- behaviour which you think to be incorrect
2767 +- actual operation, reproducible one is better
2768 +- mailto: aufs-users at lists.sourceforge.net
2770 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2771 +and Feature Requests) on SourceForge. Please join and write to
2775 +6. Acknowledgements
2776 +----------------------------------------
2777 +Thanks to everyone who have tried and are using aufs, whoever
2778 +have reported a bug or any feedback.
2780 +Especially donators:
2781 +Tomas Matejicek(slax.org) made a donation (much more than once).
2782 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2783 + scripts) is making "doubling" donations.
2784 + Unfortunately I cannot list all of the donators, but I really
2786 + It ends Aug 2010, but the ordinary donation URL is still available.
2787 + <http://sourceforge.net/donate/index.php?group_id=167503>
2788 +Dai Itasaka made a donation (2007/8).
2789 +Chuck Smith made a donation (2008/4, 10 and 12).
2790 +Henk Schoneveld made a donation (2008/9).
2791 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2792 +Francois Dupoux made a donation (2008/11).
2793 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2794 + aufs2 GIT tree (2009/2).
2795 +William Grant made a donation (2009/3).
2796 +Patrick Lane made a donation (2009/4).
2797 +The Mail Archive (mail-archive.com) made donations (2009/5).
2798 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2799 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2800 +Pavel Pronskiy made a donation (2011/2).
2801 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2802 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2803 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2805 +Sam Liddicott made a donation (2011/9).
2806 +Era Scarecrow made a donation (2013/4).
2807 +Bor Ratajc made a donation (2013/4).
2808 +Alessandro Gorreta made a donation (2013/4).
2809 +POIRETTE Marc made a donation (2013/4).
2810 +Alessandro Gorreta made a donation (2013/4).
2811 +lauri kasvandik made a donation (2013/5).
2812 +"pemasu from Finland" made a donation (2013/7).
2813 +The Parted Magic Project made a donation (2013/9 and 11).
2814 +Pavel Barta made a donation (2013/10).
2815 +Nikolay Pertsev made a donation (2014/5).
2816 +James B made a donation (2014/7 and 2015/7).
2817 +Stefano Di Biase made a donation (2014/8).
2818 +Daniel Epellei made a donation (2015/1).
2819 +OmegaPhil made a donation (2016/1, 2018/4).
2820 +Tomasz Szewczyk made a donation (2016/4).
2821 +James Burry made a donation (2016/12).
2822 +Carsten Rose made a donation (2018/9).
2823 +Porteus Kiosk made a donation (2018/10).
2825 +Thank you very much.
2826 +Donations are always, including future donations, very important and
2827 +helpful for me to keep on developing aufs.
2831 +----------------------------------------
2832 +If you are an experienced user, no explanation is needed. Aufs is
2833 +just a linux filesystem.
2838 +# Local variables: ;
2841 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2842 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2843 +++ linux/fs/aufs/aufs.h 2021-12-03 15:38:59.929980643 +0100
2845 +/* SPDX-License-Identifier: GPL-2.0 */
2847 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2849 + * This program, aufs is free software; you can redistribute it and/or modify
2850 + * it under the terms of the GNU General Public License as published by
2851 + * the Free Software Foundation; either version 2 of the License, or
2852 + * (at your option) any later version.
2854 + * This program is distributed in the hope that it will be useful,
2855 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2856 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2857 + * GNU General Public License for more details.
2859 + * You should have received a copy of the GNU General Public License
2860 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2864 + * all header files
2872 +#define AuStub(type, name, body, ...) \
2873 + static inline type name(__VA_ARGS__) { body; }
2875 +#define AuStubVoid(name, ...) \
2876 + AuStub(void, name, , __VA_ARGS__)
2877 +#define AuStubInt0(name, ...) \
2878 + AuStub(int, name, return 0, __VA_ARGS__)
2882 +#include "branch.h"
2885 +#include "dbgaufs.h"
2886 +#include "dentry.h"
2888 +#include "dirren.h"
2891 +#include "fstype.h"
2896 +#include "module.h"
2900 +#include "sysaufs.h"
2905 +#endif /* __KERNEL__ */
2906 +#endif /* __AUFS_H__ */
2907 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2908 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2909 +++ linux/fs/aufs/branch.c 2021-12-03 15:38:59.933313976 +0100
2911 +// SPDX-License-Identifier: GPL-2.0
2913 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2915 + * This program, aufs is free software; you can redistribute it and/or modify
2916 + * it under the terms of the GNU General Public License as published by
2917 + * the Free Software Foundation; either version 2 of the License, or
2918 + * (at your option) any later version.
2920 + * This program is distributed in the hope that it will be useful,
2921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2923 + * GNU General Public License for more details.
2925 + * You should have received a copy of the GNU General Public License
2926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2930 + * branch management
2933 +#include <linux/compat.h>
2934 +#include <linux/statfs.h>
2938 + * free a single branch
2940 +static void au_br_do_free(struct au_branch *br)
2943 + struct au_wbr *wbr;
2944 + struct au_dykey **key;
2946 + au_hnotify_fin_br(br);
2947 + /* always, regardless the mount option */
2948 + au_dr_hino_free(&br->br_dirren);
2951 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2952 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2953 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2954 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2958 + for (i = 0; i < AuBrWh_Last; i++)
2959 + dput(wbr->wbr_wh[i]);
2960 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2961 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2964 + if (br->br_fhsm) {
2965 + au_br_fhsm_fin(br->br_fhsm);
2966 + au_kfree_try_rcu(br->br_fhsm);
2969 + key = br->br_dykey;
2970 + for (i = 0; i < AuBrDynOp; i++, key++)
2976 + /* recursive lock, s_umount of branch's */
2977 + /* synchronize_rcu(); */ /* why? */
2979 + path_put(&br->br_path);
2981 + au_kfree_rcu(wbr);
2982 + au_lcnt_wait_for_fin(&br->br_nfiles);
2983 + au_lcnt_wait_for_fin(&br->br_count);
2984 + /* I don't know why, but percpu_refcount requires this */
2985 + /* synchronize_rcu(); */
2990 + * frees all branches
2992 +void au_br_free(struct au_sbinfo *sbinfo)
2994 + aufs_bindex_t bmax;
2995 + struct au_branch **br;
2997 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2999 + bmax = sbinfo->si_bbot + 1;
3000 + br = sbinfo->si_branch;
3002 + au_br_do_free(*br++);
3006 + * find the index of a branch which is specified by @br_id.
3008 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3010 + aufs_bindex_t bindex, bbot;
3012 + bbot = au_sbbot(sb);
3013 + for (bindex = 0; bindex <= bbot; bindex++)
3014 + if (au_sbr_id(sb, bindex) == br_id)
3019 +/* ---------------------------------------------------------------------- */
3025 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3026 + struct dentry *h_root)
3028 + if (unlikely(h_adding == h_root
3029 + || au_test_loopback_overlap(sb, h_adding)))
3031 + if (h_adding->d_sb != h_root->d_sb)
3033 + return au_test_subdir(h_adding, h_root)
3034 + || au_test_subdir(h_root, h_adding);
3038 + * returns a newly allocated branch. @new_nbranch is a number of branches
3039 + * after adding a branch.
3041 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3044 + struct au_branch *add_branch;
3045 + struct dentry *root;
3046 + struct inode *inode;
3050 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3051 + if (unlikely(!add_branch))
3053 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3054 + if (unlikely(!add_branch->br_xino))
3056 + err = au_hnotify_init_br(add_branch, perm);
3057 + if (unlikely(err))
3060 + if (au_br_writable(perm)) {
3061 + /* may be freed separately at changing the branch permission */
3062 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3064 + if (unlikely(!add_branch->br_wbr))
3068 + if (au_br_fhsm(perm)) {
3069 + err = au_fhsm_br_alloc(add_branch);
3070 + if (unlikely(err))
3074 + root = sb->s_root;
3075 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3077 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3079 + inode = d_inode(root);
3080 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3084 + return add_branch; /* success */
3087 + au_kfree_rcu(add_branch->br_wbr);
3089 + au_hnotify_fin_br(add_branch);
3091 + au_xino_put(add_branch);
3093 + au_kfree_rcu(add_branch);
3095 + return ERR_PTR(err);
3099 + * test if the branch permission is legal or not.
3101 +static int test_br(struct inode *inode, int brperm, char *path)
3105 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3110 + pr_err("write permission for readonly mount or inode, %s\n", path);
3118 + * 0: success, the caller will add it
3119 + * plus: success, it is already unified, the caller should ignore it
3122 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3125 + aufs_bindex_t bbot, bindex;
3126 + struct dentry *root, *h_dentry;
3127 + struct inode *inode, *h_inode;
3129 + root = sb->s_root;
3130 + bbot = au_sbbot(sb);
3131 + if (unlikely(bbot >= 0
3132 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3136 + pr_err("%s duplicated\n", add->pathname);
3141 + err = -ENOSPC; /* -E2BIG; */
3142 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3143 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3144 + pr_err("number of branches exceeded %s\n", add->pathname);
3149 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3150 + pr_err("bad index %d\n", add->bindex);
3154 + inode = d_inode(add->path.dentry);
3156 + if (unlikely(!inode->i_nlink)) {
3157 + pr_err("no existence %s\n", add->pathname);
3162 + if (unlikely(inode->i_sb == sb)) {
3163 + pr_err("%s must be outside\n", add->pathname);
3167 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3168 + pr_err("unsupported filesystem, %s (%s)\n",
3169 + add->pathname, au_sbtype(inode->i_sb));
3173 + if (unlikely(inode->i_sb->s_stack_depth)) {
3174 + pr_err("already stacked, %s (%s)\n",
3175 + add->pathname, au_sbtype(inode->i_sb));
3179 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3180 + if (unlikely(err))
3184 + return 0; /* success */
3187 + for (bindex = 0; bindex <= bbot; bindex++)
3188 + if (unlikely(test_overlap(sb, add->path.dentry,
3189 + au_h_dptr(root, bindex)))) {
3190 + pr_err("%s is overlapped\n", add->pathname);
3195 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3196 + h_dentry = au_h_dptr(root, 0);
3197 + h_inode = d_inode(h_dentry);
3198 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3199 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3200 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3201 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3203 + i_uid_read(inode), i_gid_read(inode),
3204 + (inode->i_mode & S_IALLUGO),
3205 + i_uid_read(h_inode), i_gid_read(h_inode),
3206 + (h_inode->i_mode & S_IALLUGO));
3214 + * initialize or clean the whiteouts for an adding branch
3216 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3219 + int err, old_perm;
3220 + aufs_bindex_t bindex;
3221 + struct inode *h_inode;
3222 + struct au_wbr *wbr;
3223 + struct au_hinode *hdir;
3224 + struct dentry *h_dentry;
3226 + err = vfsub_mnt_want_write(au_br_mnt(br));
3227 + if (unlikely(err))
3231 + old_perm = br->br_perm;
3232 + br->br_perm = new_perm;
3235 + bindex = au_br_index(sb, br->br_id);
3236 + if (0 <= bindex) {
3237 + hdir = au_hi(d_inode(sb->s_root), bindex);
3238 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3240 + h_dentry = au_br_dentry(br);
3241 + h_inode = d_inode(h_dentry);
3242 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3245 + err = au_wh_init(br, sb);
3247 + wbr_wh_write_lock(wbr);
3248 + err = au_wh_init(br, sb);
3249 + wbr_wh_write_unlock(wbr);
3252 + au_hn_inode_unlock(hdir);
3254 + inode_unlock(h_inode);
3255 + vfsub_mnt_drop_write(au_br_mnt(br));
3256 + br->br_perm = old_perm;
3258 + if (!err && wbr && !au_br_writable(new_perm)) {
3259 + au_kfree_rcu(wbr);
3260 + br->br_wbr = NULL;
3267 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3271 + struct kstatfs kst;
3272 + struct au_wbr *wbr;
3275 + au_rw_init(&wbr->wbr_wh_rwsem);
3276 + atomic_set(&wbr->wbr_wh_running, 0);
3279 + * a limit for rmdir/rename a dir
3280 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3282 + err = vfs_statfs(&br->br_path, &kst);
3283 + if (unlikely(err))
3286 + if (kst.f_namelen >= NAME_MAX)
3287 + err = au_br_init_wh(sb, br, perm);
3289 + pr_err("%pd(%s), unsupported namelen %ld\n",
3291 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3297 +/* initialize a new branch */
3298 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3299 + struct au_opt_add *add)
3302 + struct au_branch *brbase;
3304 + struct inode *h_inode;
3307 + br->br_perm = add->perm;
3308 + br->br_path = add->path; /* set first, path_get() later */
3309 + spin_lock_init(&br->br_dykey_lock);
3310 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3311 + au_lcnt_init(&br->br_count, /*release*/NULL);
3312 + br->br_id = au_new_br_id(sb);
3313 + AuDebugOn(br->br_id < 0);
3315 + /* always, regardless the given option */
3316 + err = au_dr_br_init(sb, br, &add->path);
3317 + if (unlikely(err))
3320 + if (au_br_writable(add->perm)) {
3321 + err = au_wbr_init(br, sb, add->perm);
3322 + if (unlikely(err))
3326 + if (au_opt_test(au_mntflags(sb), XINO)) {
3327 + brbase = au_sbr(sb, 0);
3328 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3330 + h_inode = d_inode(add->path.dentry);
3331 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3332 + if (unlikely(err)) {
3333 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3338 + sysaufs_br_init(br);
3339 + path_get(&br->br_path);
3340 + goto out; /* success */
3343 + memset(&br->br_path, 0, sizeof(br->br_path));
3348 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3349 + struct au_branch *br, aufs_bindex_t bbot,
3350 + aufs_bindex_t amount)
3352 + struct au_branch **brp;
3354 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3356 + brp = sbinfo->si_branch + bindex;
3357 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3359 + sbinfo->si_bbot++;
3360 + if (unlikely(bbot < 0))
3361 + sbinfo->si_bbot = 0;
3364 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3365 + aufs_bindex_t bbot, aufs_bindex_t amount)
3367 + struct au_hdentry *hdp;
3369 + AuRwMustWriteLock(&dinfo->di_rwsem);
3371 + hdp = au_hdentry(dinfo, bindex);
3372 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3373 + au_h_dentry_init(hdp);
3375 + if (unlikely(bbot < 0))
3376 + dinfo->di_btop = 0;
3379 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3380 + aufs_bindex_t bbot, aufs_bindex_t amount)
3382 + struct au_hinode *hip;
3384 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3386 + hip = au_hinode(iinfo, bindex);
3387 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3388 + au_hinode_init(hip);
3390 + if (unlikely(bbot < 0))
3391 + iinfo->ii_btop = 0;
3394 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3395 + aufs_bindex_t bindex)
3397 + struct dentry *root, *h_dentry;
3398 + struct inode *root_inode, *h_inode;
3399 + aufs_bindex_t bbot, amount;
3401 + root = sb->s_root;
3402 + root_inode = d_inode(root);
3403 + bbot = au_sbbot(sb);
3404 + amount = bbot + 1 - bindex;
3405 + h_dentry = au_br_dentry(br);
3406 + au_sbilist_lock();
3407 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3408 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3409 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3410 + au_set_h_dptr(root, bindex, dget(h_dentry));
3411 + h_inode = d_inode(h_dentry);
3412 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3413 + au_sbilist_unlock();
3416 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3419 + aufs_bindex_t bbot, add_bindex;
3420 + struct dentry *root, *h_dentry;
3421 + struct inode *root_inode;
3422 + struct au_branch *add_branch;
3424 + root = sb->s_root;
3425 + root_inode = d_inode(root);
3426 + IMustLock(root_inode);
3427 + IiMustWriteLock(root_inode);
3428 + err = test_add(sb, add, remount);
3429 + if (unlikely(err < 0))
3433 + goto out; /* success */
3436 + bbot = au_sbbot(sb);
3437 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3438 + err = PTR_ERR(add_branch);
3439 + if (IS_ERR(add_branch))
3442 + err = au_br_init(add_branch, sb, add);
3443 + if (unlikely(err)) {
3444 + au_br_do_free(add_branch);
3448 + add_bindex = add->bindex;
3449 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3450 + au_br_do_add(sb, add_branch, add_bindex);
3451 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3452 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3454 + h_dentry = add->path.dentry;
3455 + if (!add_bindex) {
3456 + au_cpup_attr_all(root_inode, /*force*/1);
3457 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3459 + au_add_nlink(root_inode, d_inode(h_dentry));
3465 +/* ---------------------------------------------------------------------- */
3467 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3468 + unsigned long long max __maybe_unused,
3471 + unsigned long long n;
3472 + struct file **p, *f;
3473 + struct hlist_bl_head *files;
3474 + struct hlist_bl_node *pos;
3475 + struct au_finfo *finfo;
3479 + files = &au_sbi(sb)->si_files;
3480 + hlist_bl_lock(files);
3481 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3482 + f = finfo->fi_file;
3484 + && !special_file(file_inode(f)->i_mode)) {
3488 + AuDebugOn(n > max);
3491 + hlist_bl_unlock(files);
3496 +static struct file **au_farray_alloc(struct super_block *sb,
3497 + unsigned long long *max)
3499 + struct au_sbinfo *sbi;
3502 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3503 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3506 +static void au_farray_free(struct file **a, unsigned long long max)
3508 + unsigned long long ull;
3510 + for (ull = 0; ull < max; ull++)
3516 +/* ---------------------------------------------------------------------- */
3522 +/* to show the line number, do not make it inlined function */
3523 +#define AuVerbose(do_info, fmt, ...) do { \
3525 + pr_info(fmt, ##__VA_ARGS__); \
3528 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3529 + aufs_bindex_t bbot)
3531 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3534 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3535 + aufs_bindex_t bbot)
3537 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3541 + * test if the branch is deletable or not.
3543 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3544 + unsigned int sigen, const unsigned int verbose)
3546 + int err, i, j, ndentry;
3547 + aufs_bindex_t btop, bbot;
3548 + struct au_dcsub_pages dpages;
3549 + struct au_dpage *dpage;
3552 + err = au_dpages_init(&dpages, GFP_NOFS);
3553 + if (unlikely(err))
3555 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3556 + if (unlikely(err))
3559 + for (i = 0; !err && i < dpages.ndpage; i++) {
3560 + dpage = dpages.dpages + i;
3561 + ndentry = dpage->ndentry;
3562 + for (j = 0; !err && j < ndentry; j++) {
3563 + d = dpage->dentries[j];
3564 + AuDebugOn(au_dcount(d) <= 0);
3565 + if (!au_digen_test(d, sigen)) {
3566 + di_read_lock_child(d, AuLock_IR);
3567 + if (unlikely(au_dbrange_test(d))) {
3568 + di_read_unlock(d, AuLock_IR);
3572 + di_write_lock_child(d);
3573 + if (unlikely(au_dbrange_test(d))) {
3574 + di_write_unlock(d);
3577 + err = au_reval_dpath(d, sigen);
3579 + di_downgrade_lock(d, AuLock_IR);
3581 + di_write_unlock(d);
3586 + /* AuDbgDentry(d); */
3587 + btop = au_dbtop(d);
3588 + bbot = au_dbbot(d);
3589 + if (btop <= bindex
3591 + && au_h_dptr(d, bindex)
3592 + && au_test_dbusy(d, btop, bbot)) {
3594 + AuVerbose(verbose, "busy %pd\n", d);
3597 + di_read_unlock(d, AuLock_IR);
3602 + au_dpages_free(&dpages);
3607 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3608 + unsigned int sigen, const unsigned int verbose)
3611 + unsigned long long max, ull;
3612 + struct inode *i, **array;
3613 + aufs_bindex_t btop, bbot;
3615 + array = au_iarray_alloc(sb, &max);
3616 + err = PTR_ERR(array);
3617 + if (IS_ERR(array))
3621 + AuDbg("b%d\n", bindex);
3622 + for (ull = 0; !err && ull < max; ull++) {
3626 + if (i->i_ino == AUFS_ROOT_INO)
3629 + /* AuDbgInode(i); */
3630 + if (au_iigen(i, NULL) == sigen)
3631 + ii_read_lock_child(i);
3633 + ii_write_lock_child(i);
3634 + err = au_refresh_hinode_self(i);
3637 + ii_downgrade_lock(i);
3639 + ii_write_unlock(i);
3644 + btop = au_ibtop(i);
3645 + bbot = au_ibbot(i);
3646 + if (btop <= bindex
3648 + && au_h_iptr(i, bindex)
3649 + && au_test_ibusy(i, btop, bbot)) {
3651 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3654 + ii_read_unlock(i);
3656 + au_iarray_free(array, max);
3662 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3663 + const unsigned int verbose)
3666 + unsigned int sigen;
3668 + sigen = au_sigen(root->d_sb);
3669 + DiMustNoWaiters(root);
3670 + IiMustNoWaiters(d_inode(root));
3671 + di_write_unlock(root);
3672 + err = test_dentry_busy(root, bindex, sigen, verbose);
3674 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3675 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3680 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3681 + struct file **to_free, int *idx)
3684 + unsigned char matched, root;
3685 + aufs_bindex_t bindex, bbot;
3686 + struct au_fidir *fidir;
3687 + struct au_hfile *hfile;
3690 + root = IS_ROOT(file->f_path.dentry);
3693 + to_free[*idx] = file;
3699 + fidir = au_fi(file)->fi_hdir;
3700 + AuDebugOn(!fidir);
3701 + bbot = au_fbbot_dir(file);
3702 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3703 + hfile = fidir->fd_hfile + bindex;
3704 + if (!hfile->hf_file)
3707 + if (hfile->hf_br->br_id == br_id) {
3719 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3720 + struct file **to_free, int opened)
3723 + unsigned long long ull, max;
3724 + aufs_bindex_t btop;
3725 + struct file *file, **array;
3726 + struct dentry *root;
3727 + struct au_hfile *hfile;
3729 + array = au_farray_alloc(sb, &max);
3730 + err = PTR_ERR(array);
3731 + if (IS_ERR(array))
3736 + root = sb->s_root;
3737 + di_write_unlock(root);
3738 + for (ull = 0; ull < max; ull++) {
3739 + file = array[ull];
3740 + if (unlikely(!file))
3743 + /* AuDbg("%pD\n", file); */
3744 + fi_read_lock(file);
3745 + btop = au_fbtop(file);
3746 + if (!d_is_dir(file->f_path.dentry)) {
3747 + hfile = &au_fi(file)->fi_htop;
3748 + if (hfile->hf_br->br_id == br_id)
3751 + err = test_dir_busy(file, br_id, to_free, &idx);
3752 + fi_read_unlock(file);
3753 + if (unlikely(err))
3756 + di_write_lock_child(root);
3757 + au_farray_free(array, max);
3758 + AuDebugOn(idx > opened);
3764 +static void br_del_file(struct file **to_free, unsigned long long opened,
3765 + aufs_bindex_t br_id)
3767 + unsigned long long ull;
3768 + aufs_bindex_t bindex, btop, bbot, bfound;
3769 + struct file *file;
3770 + struct au_fidir *fidir;
3771 + struct au_hfile *hfile;
3773 + for (ull = 0; ull < opened; ull++) {
3774 + file = to_free[ull];
3775 + if (unlikely(!file))
3778 + /* AuDbg("%pD\n", file); */
3779 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3781 + fidir = au_fi(file)->fi_hdir;
3782 + AuDebugOn(!fidir);
3783 + fi_write_lock(file);
3784 + btop = au_fbtop(file);
3785 + bbot = au_fbbot_dir(file);
3786 + for (bindex = btop; bindex <= bbot; bindex++) {
3787 + hfile = fidir->fd_hfile + bindex;
3788 + if (!hfile->hf_file)
3791 + if (hfile->hf_br->br_id == br_id) {
3796 + AuDebugOn(bfound < 0);
3797 + au_set_h_fptr(file, bfound, NULL);
3798 + if (bfound == btop) {
3799 + for (btop++; btop <= bbot; btop++)
3800 + if (au_hf_dir(file, btop)) {
3801 + au_set_fbtop(file, btop);
3805 + fi_write_unlock(file);
3809 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3810 + const aufs_bindex_t bindex,
3811 + const aufs_bindex_t bbot)
3813 + struct au_branch **brp, **p;
3815 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3817 + brp = sbinfo->si_branch + bindex;
3818 + if (bindex < bbot)
3819 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3820 + sbinfo->si_branch[0 + bbot] = NULL;
3821 + sbinfo->si_bbot--;
3823 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3826 + sbinfo->si_branch = p;
3827 + /* harmless error */
3830 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3831 + const aufs_bindex_t bbot)
3833 + struct au_hdentry *hdp, *p;
3835 + AuRwMustWriteLock(&dinfo->di_rwsem);
3837 + hdp = au_hdentry(dinfo, bindex);
3838 + if (bindex < bbot)
3839 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3840 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3843 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3846 + dinfo->di_hdentry = p;
3847 + /* harmless error */
3850 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3851 + const aufs_bindex_t bbot)
3853 + struct au_hinode *hip, *p;
3855 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3857 + hip = au_hinode(iinfo, bindex);
3858 + if (bindex < bbot)
3859 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3860 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3863 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3866 + iinfo->ii_hinode = p;
3867 + /* harmless error */
3870 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3871 + struct au_branch *br)
3873 + aufs_bindex_t bbot;
3874 + struct au_sbinfo *sbinfo;
3875 + struct dentry *root, *h_root;
3876 + struct inode *inode, *h_inode;
3877 + struct au_hinode *hinode;
3879 + SiMustWriteLock(sb);
3881 + root = sb->s_root;
3882 + inode = d_inode(root);
3883 + sbinfo = au_sbi(sb);
3884 + bbot = sbinfo->si_bbot;
3886 + h_root = au_h_dptr(root, bindex);
3887 + hinode = au_hi(inode, bindex);
3888 + h_inode = au_igrab(hinode->hi_inode);
3891 + au_sbilist_lock();
3892 + au_br_do_del_brp(sbinfo, bindex, bbot);
3893 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3894 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3895 + au_sbilist_unlock();
3897 + /* ignore an error */
3898 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3902 + au_br_do_free(br);
3905 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3906 + unsigned long long max, void *arg)
3911 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3914 + unsigned long long opened;
3915 + unsigned int mnt_flags;
3916 + aufs_bindex_t bindex, bbot, br_id;
3917 + unsigned char do_wh, verbose;
3918 + struct au_branch *br;
3919 + struct au_wbr *wbr;
3920 + struct dentry *root;
3921 + struct file **to_free;
3926 + root = sb->s_root;
3927 + bindex = au_find_dbindex(root, del->h_path.dentry);
3930 + goto out; /* success */
3932 + pr_err("%s no such branch\n", del->pathname);
3935 + AuDbg("bindex b%d\n", bindex);
3938 + mnt_flags = au_mntflags(sb);
3939 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3940 + bbot = au_sbbot(sb);
3941 + if (unlikely(!bbot)) {
3942 + AuVerbose(verbose, "no more branches left\n");
3946 + br = au_sbr(sb, bindex);
3947 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3948 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3949 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3953 + br_id = br->br_id;
3954 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3955 + if (unlikely(opened)) {
3956 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3957 + err = PTR_ERR(to_free);
3958 + if (IS_ERR(to_free))
3961 + err = test_file_busy(sb, br_id, to_free, opened);
3962 + if (unlikely(err)) {
3963 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3969 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3971 + /* instead of WbrWhMustWriteLock(wbr) */
3972 + SiMustWriteLock(sb);
3973 + for (i = 0; i < AuBrWh_Last; i++) {
3974 + dput(wbr->wbr_wh[i]);
3975 + wbr->wbr_wh[i] = NULL;
3979 + err = test_children_busy(root, bindex, verbose);
3980 + if (unlikely(err)) {
3989 + * now we confirmed the branch is deletable.
3990 + * let's free the remaining opened dirs on the branch.
3992 + di_write_unlock(root);
3993 + br_del_file(to_free, opened, br_id);
3994 + di_write_lock_child(root);
3997 + sysaufs_brs_del(sb, bindex); /* remove successors */
3998 + dbgaufs_xino_del(br); /* remove one */
3999 + au_br_do_del(sb, bindex, br);
4000 + sysaufs_brs_add(sb, bindex); /* append successors */
4001 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4004 + au_cpup_attr_all(d_inode(root), /*force*/1);
4005 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4007 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4008 + if (au_opt_test(mnt_flags, PLINK))
4009 + au_plink_half_refresh(sb, br_id);
4011 + goto out; /* success */
4015 + rerr = au_br_init_wh(sb, br, br->br_perm);
4017 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4018 + del->pathname, rerr);
4021 + au_farray_free(to_free, opened);
4025 +/* ---------------------------------------------------------------------- */
4027 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4030 + aufs_bindex_t btop, bbot;
4031 + struct aufs_ibusy ibusy;
4032 + struct inode *inode, *h_inode;
4035 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4038 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4040 + /* VERIFY_WRITE */
4041 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4042 + if (unlikely(err)) {
4049 + si_read_lock(sb, AuLock_FLUSH);
4050 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4054 + ibusy.h_ino = 0; /* invalid */
4055 + inode = ilookup(sb, ibusy.ino);
4057 + || inode->i_ino == AUFS_ROOT_INO
4058 + || au_is_bad_inode(inode))
4061 + ii_read_lock_child(inode);
4062 + btop = au_ibtop(inode);
4063 + bbot = au_ibbot(inode);
4064 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4065 + h_inode = au_h_iptr(inode, ibusy.bindex);
4066 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4067 + ibusy.h_ino = h_inode->i_ino;
4069 + ii_read_unlock(inode);
4073 + si_read_unlock(sb);
4075 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4076 + if (unlikely(err)) {
4085 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4087 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4090 +#ifdef CONFIG_COMPAT
4091 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4093 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4097 +/* ---------------------------------------------------------------------- */
4100 + * change a branch permission
4103 +static void au_warn_ima(void)
4106 + /* since it doesn't support mark_files_ro() */
4107 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4111 +static int do_need_sigen_inc(int a, int b)
4113 + return au_br_whable(a) && !au_br_whable(b);
4116 +static int need_sigen_inc(int old, int new)
4118 + return do_need_sigen_inc(old, new)
4119 + || do_need_sigen_inc(new, old);
4122 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4125 + unsigned int mnt_flags;
4126 + unsigned long long ull, max;
4127 + aufs_bindex_t br_id;
4128 + unsigned char verbose, writer;
4129 + struct file *file, *hf, **array;
4130 + struct au_hfile *hfile;
4131 + struct inode *h_inode;
4133 + mnt_flags = au_mntflags(sb);
4134 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4136 + array = au_farray_alloc(sb, &max);
4137 + err = PTR_ERR(array);
4138 + if (IS_ERR(array))
4142 + br_id = au_sbr_id(sb, bindex);
4143 + for (ull = 0; ull < max; ull++) {
4144 + file = array[ull];
4145 + if (unlikely(!file))
4148 + /* AuDbg("%pD\n", file); */
4149 + fi_read_lock(file);
4150 + if (unlikely(au_test_mmapped(file))) {
4152 + AuVerbose(verbose, "mmapped %pD\n", file);
4154 + FiMustNoWaiters(file);
4155 + fi_read_unlock(file);
4159 + hfile = &au_fi(file)->fi_htop;
4160 + hf = hfile->hf_file;
4161 + if (!d_is_reg(file->f_path.dentry)
4162 + || !(file->f_mode & FMODE_WRITE)
4163 + || hfile->hf_br->br_id != br_id
4164 + || !(hf->f_mode & FMODE_WRITE))
4165 + array[ull] = NULL;
4171 + FiMustNoWaiters(file);
4172 + fi_read_unlock(file);
4180 + for (ull = 0; ull < max; ull++) {
4181 + file = array[ull];
4185 + /* todo: already flushed? */
4187 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4188 + * approach which resets f_mode and calls mnt_drop_write() and
4189 + * file_release_write() for each file, because the branch
4190 + * attribute in aufs world is totally different from the native
4193 + /* fi_read_lock(file); */
4194 + hfile = &au_fi(file)->fi_htop;
4195 + hf = hfile->hf_file;
4196 + /* fi_read_unlock(file); */
4197 + spin_lock(&hf->f_lock);
4198 + writer = !!(hf->f_mode & FMODE_WRITER);
4199 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4200 + spin_unlock(&hf->f_lock);
4202 + h_inode = file_inode(hf);
4203 + if (hf->f_mode & FMODE_READ)
4204 + i_readcount_inc(h_inode);
4205 + put_write_access(h_inode);
4206 + __mnt_drop_write(hf->f_path.mnt);
4211 + au_farray_free(array, max);
4217 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4221 + aufs_bindex_t bindex;
4222 + struct dentry *root;
4223 + struct au_branch *br;
4224 + struct au_br_fhsm *bf;
4226 + root = sb->s_root;
4227 + bindex = au_find_dbindex(root, mod->h_root);
4230 + return 0; /* success */
4232 + pr_err("%s no such branch\n", mod->path);
4235 + AuDbg("bindex b%d\n", bindex);
4237 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4238 + if (unlikely(err))
4241 + br = au_sbr(sb, bindex);
4242 + AuDebugOn(mod->h_root != au_br_dentry(br));
4243 + if (br->br_perm == mod->perm)
4244 + return 0; /* success */
4246 + /* pre-allocate for non-fhsm --> fhsm */
4248 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4249 + err = au_fhsm_br_alloc(br);
4250 + if (unlikely(err))
4253 + br->br_fhsm = NULL;
4256 + if (au_br_writable(br->br_perm)) {
4257 + /* remove whiteout base */
4258 + err = au_br_init_wh(sb, br, mod->perm);
4259 + if (unlikely(err))
4262 + if (!au_br_writable(mod->perm)) {
4263 + /* rw --> ro, file might be mmapped */
4264 + DiMustNoWaiters(root);
4265 + IiMustNoWaiters(d_inode(root));
4266 + di_write_unlock(root);
4267 + err = au_br_mod_files_ro(sb, bindex);
4268 + /* aufs_write_lock() calls ..._child() */
4269 + di_write_lock_child(root);
4271 + if (unlikely(err)) {
4273 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4276 + rerr = au_wbr_init(br, sb, br->br_perm);
4277 + if (unlikely(rerr)) {
4278 + AuIOErr("nested error %d (%d)\n",
4280 + br->br_perm = mod->perm;
4284 + } else if (au_br_writable(mod->perm)) {
4287 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4289 + err = au_wbr_init(br, sb, mod->perm);
4290 + if (unlikely(err)) {
4291 + au_kfree_rcu(br->br_wbr);
4292 + br->br_wbr = NULL;
4296 + if (unlikely(err))
4299 + if (au_br_fhsm(br->br_perm)) {
4300 + if (!au_br_fhsm(mod->perm)) {
4301 + /* fhsm --> non-fhsm */
4302 + au_br_fhsm_fin(br->br_fhsm);
4303 + au_kfree_rcu(br->br_fhsm);
4304 + br->br_fhsm = NULL;
4306 + } else if (au_br_fhsm(mod->perm))
4307 + /* non-fhsm --> fhsm */
4310 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4311 + br->br_perm = mod->perm;
4312 + goto out; /* success */
4315 + au_kfree_try_rcu(bf);
4321 +/* ---------------------------------------------------------------------- */
4323 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4326 + struct kstatfs kstfs;
4328 + err = vfs_statfs(&br->br_path, &kstfs);
4330 + stfs->f_blocks = kstfs.f_blocks;
4331 + stfs->f_bavail = kstfs.f_bavail;
4332 + stfs->f_files = kstfs.f_files;
4333 + stfs->f_ffree = kstfs.f_ffree;
4338 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4339 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4340 +++ linux/fs/aufs/branch.h 2021-12-03 15:40:58.233313963 +0100
4342 +/* SPDX-License-Identifier: GPL-2.0 */
4344 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4346 + * This program, aufs is free software; you can redistribute it and/or modify
4347 + * it under the terms of the GNU General Public License as published by
4348 + * the Free Software Foundation; either version 2 of the License, or
4349 + * (at your option) any later version.
4351 + * This program is distributed in the hope that it will be useful,
4352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4354 + * GNU General Public License for more details.
4356 + * You should have received a copy of the GNU General Public License
4357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4361 + * branch filesystems and xino for them
4364 +#ifndef __AUFS_BRANCH_H__
4365 +#define __AUFS_BRANCH_H__
4369 +#include <linux/mount.h>
4370 +#include "dirren.h"
4376 +/* ---------------------------------------------------------------------- */
4380 + struct file **xi_file;
4381 + unsigned int xi_nfile;
4387 + /* reserved for future use */
4388 + /* unsigned long *bitmap; */
4389 + wait_queue_head_t wqh;
4392 + struct mutex xi_mtx; /* protects xi_file array */
4393 + struct hlist_bl_head xi_writing;
4395 + atomic_t xi_truncating;
4397 + struct kref xi_kref;
4400 +/* File-based Hierarchical Storage Management */
4401 +struct au_br_fhsm {
4402 +#ifdef CONFIG_AUFS_FHSM
4403 + struct mutex bf_lock;
4404 + unsigned long bf_jiffy;
4405 + struct aufs_stfs bf_stfs;
4410 +/* members for writable branch only */
4411 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4413 + struct au_rwsem wbr_wh_rwsem;
4414 + struct dentry *wbr_wh[AuBrWh_Last];
4415 + atomic_t wbr_wh_running;
4416 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4417 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4418 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4421 + unsigned long long wbr_bytes;
4424 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4425 +#define AuBrDynOp (AuDyLast * 4)
4427 +#ifdef CONFIG_AUFS_HFSNOTIFY
4428 +/* support for asynchronous destruction */
4429 +struct au_br_hfsnotify {
4430 + struct fsnotify_group *hfsn_group;
4434 +/* sysfs entries */
4435 +struct au_brsysfs {
4437 + struct attribute attr;
4446 +/* protected by superblock rwsem */
4448 + struct au_xino *br_xino;
4450 + aufs_bindex_t br_id;
4453 + struct path br_path;
4454 + spinlock_t br_dykey_lock;
4455 + struct au_dykey *br_dykey[AuBrDynOp];
4456 + au_lcnt_t br_nfiles; /* opened files */
4457 + au_lcnt_t br_count; /* in-use for other */
4459 + struct au_wbr *br_wbr;
4460 + struct au_br_fhsm *br_fhsm;
4462 +#ifdef CONFIG_AUFS_HFSNOTIFY
4463 + struct au_br_hfsnotify *br_hfsn;
4466 +#ifdef CONFIG_SYSFS
4467 + /* entries under sysfs per mount-point */
4468 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4471 +#ifdef CONFIG_DEBUG_FS
4472 + struct dentry *br_dbgaufs; /* xino */
4475 + struct au_dr_br br_dirren;
4478 +/* ---------------------------------------------------------------------- */
4480 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4482 + return br->br_path.mnt;
4485 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4487 + return br->br_path.dentry;
4490 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4492 + return mnt_user_ns(br->br_path.mnt);
4495 +static inline struct super_block *au_br_sb(struct au_branch *br)
4497 + return au_br_mnt(br)->mnt_sb;
4500 +static inline int au_br_rdonly(struct au_branch *br)
4502 + return (sb_rdonly(au_br_sb(br))
4503 + || !au_br_writable(br->br_perm))
4507 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4509 +#ifdef CONFIG_AUFS_HNOTIFY
4510 + return !(brperm & AuBrPerm_RR);
4516 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4518 + int err, exec_flag;
4521 + exec_flag = oflag & __FMODE_EXEC;
4522 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4528 +static inline void au_xino_get(struct au_branch *br)
4530 + struct au_xino *xi;
4534 + kref_get(&xi->xi_kref);
4537 +static inline int au_xino_count(struct au_branch *br)
4540 + struct au_xino *xi;
4545 + v = kref_read(&xi->xi_kref);
4550 +/* ---------------------------------------------------------------------- */
4554 +void au_br_free(struct au_sbinfo *sinfo);
4555 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4557 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4559 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4560 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4561 +#ifdef CONFIG_COMPAT
4562 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4565 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4568 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4571 +static const loff_t au_loff_max = LLONG_MAX;
4573 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4574 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4576 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4577 + struct file *copy_src);
4579 + struct au_xino *xi; /* switch between xino and xigen */
4581 + struct path *base;
4582 + struct file *copy_src;
4584 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4586 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4588 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4590 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4591 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4593 +int au_xib_trunc(struct super_block *sb);
4594 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4596 +struct au_xino *au_xino_alloc(unsigned int nfile);
4597 +int au_xino_put(struct au_branch *br);
4598 +struct file *au_xino_file1(struct au_xino *xi);
4600 +struct au_opt_xino;
4601 +void au_xino_clr(struct super_block *sb);
4602 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4603 +struct file *au_xino_def(struct super_block *sb);
4604 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4605 + struct path *base);
4607 +ino_t au_xino_new_ino(struct super_block *sb);
4608 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4610 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4611 + ino_t h_ino, int idx);
4612 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4615 +int au_xino_path(struct seq_file *seq, struct file *file);
4617 +/* ---------------------------------------------------------------------- */
4619 +/* @idx is signed to accept -1 meaning the first file */
4620 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4622 + struct file *file;
4629 + if (idx < xi->xi_nfile)
4630 + file = xi->xi_file[idx];
4632 + file = au_xino_file1(xi);
4638 +/* ---------------------------------------------------------------------- */
4640 +/* Superblock to branch */
4642 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4644 + return au_sbr(sb, bindex)->br_id;
4648 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4650 + return au_br_mnt(au_sbr(sb, bindex));
4654 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4656 + return au_br_userns(au_sbr(sb, bindex));
4660 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4662 + return au_br_sb(au_sbr(sb, bindex));
4665 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4667 + return au_sbr(sb, bindex)->br_perm;
4670 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4672 + return au_br_whable(au_sbr_perm(sb, bindex));
4675 +/* ---------------------------------------------------------------------- */
4677 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4678 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4679 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4680 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4682 +#define wbr_wh_read_trylock_nested(wbr) \
4683 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4684 +#define wbr_wh_write_trylock_nested(wbr) \
4685 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4688 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4689 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4690 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4692 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4693 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4694 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4696 +/* ---------------------------------------------------------------------- */
4698 +#ifdef CONFIG_AUFS_FHSM
4699 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4701 + mutex_init(&brfhsm->bf_lock);
4702 + brfhsm->bf_jiffy = 0;
4703 + brfhsm->bf_readable = 0;
4706 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4708 + mutex_destroy(&brfhsm->bf_lock);
4711 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4712 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4715 +#endif /* __KERNEL__ */
4716 +#endif /* __AUFS_BRANCH_H__ */
4717 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4718 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4719 +++ linux/fs/aufs/conf.mk 2021-12-03 15:38:59.933313976 +0100
4721 +# SPDX-License-Identifier: GPL-2.0
4723 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4727 +AuConfStr += ${1}=${${1}}
4731 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4733 + HNOTIFY HFSNOTIFY \
4745 +$(foreach i, ${AuConfAll}, \
4746 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4748 +AuConfName = ${obj}/conf.str
4749 +${AuConfName}.tmp: FORCE
4750 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4751 +${AuConfName}: ${AuConfName}.tmp
4752 + @diff -q $< $@ > /dev/null 2>&1 || { \
4753 + echo ' GEN ' $@; \
4757 +clean-files += ${AuConfName} ${AuConfName}.tmp
4758 +${obj}/sysfs.o: ${AuConfName}
4760 +-include ${srctree}/${src}/conf_priv.mk
4761 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4762 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4763 +++ linux/fs/aufs/cpup.c 2021-12-03 15:40:58.233313963 +0100
4765 +// SPDX-License-Identifier: GPL-2.0
4767 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4769 + * This program, aufs is free software; you can redistribute it and/or modify
4770 + * it under the terms of the GNU General Public License as published by
4771 + * the Free Software Foundation; either version 2 of the License, or
4772 + * (at your option) any later version.
4774 + * This program is distributed in the hope that it will be useful,
4775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4777 + * GNU General Public License for more details.
4779 + * You should have received a copy of the GNU General Public License
4780 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4784 + * copy-up functions, see wbr_policy.c for copy-down
4787 +#include <linux/fs_stack.h>
4788 +#include <linux/mm.h>
4789 +#include <linux/task_work.h>
4792 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4794 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4795 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4797 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4799 + dst->i_flags |= iflags & ~mask;
4800 + if (au_test_fs_notime(dst->i_sb))
4801 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4804 +void au_cpup_attr_timesizes(struct inode *inode)
4806 + struct inode *h_inode;
4808 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4809 + fsstack_copy_attr_times(inode, h_inode);
4810 + fsstack_copy_inode_size(inode, h_inode);
4813 +void au_cpup_attr_nlink(struct inode *inode, int force)
4815 + struct inode *h_inode;
4816 + struct super_block *sb;
4817 + aufs_bindex_t bindex, bbot;
4820 + bindex = au_ibtop(inode);
4821 + h_inode = au_h_iptr(inode, bindex);
4823 + && !S_ISDIR(h_inode->i_mode)
4824 + && au_opt_test(au_mntflags(sb), PLINK)
4825 + && au_plink_test(inode))
4829 + * 0 can happen in revalidating.
4830 + * h_inode->i_mutex may not be held here, but it is harmless since once
4831 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4833 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4834 + * the incorrect link count.
4836 + set_nlink(inode, h_inode->i_nlink);
4839 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4840 + * it may includes whplink directory.
4842 + if (S_ISDIR(h_inode->i_mode)) {
4843 + bbot = au_ibbot(inode);
4844 + for (bindex++; bindex <= bbot; bindex++) {
4845 + h_inode = au_h_iptr(inode, bindex);
4847 + au_add_nlink(inode, h_inode);
4852 +void au_cpup_attr_changeable(struct inode *inode)
4854 + struct inode *h_inode;
4856 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4857 + inode->i_mode = h_inode->i_mode;
4858 + inode->i_uid = h_inode->i_uid;
4859 + inode->i_gid = h_inode->i_gid;
4860 + au_cpup_attr_timesizes(inode);
4861 + au_cpup_attr_flags(inode, h_inode->i_flags);
4864 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4866 + struct au_iinfo *iinfo = au_ii(inode);
4868 + IiMustWriteLock(inode);
4870 + iinfo->ii_higen = h_inode->i_generation;
4871 + iinfo->ii_hsb1 = h_inode->i_sb;
4874 +void au_cpup_attr_all(struct inode *inode, int force)
4876 + struct inode *h_inode;
4878 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4879 + au_cpup_attr_changeable(inode);
4880 + if (inode->i_nlink > 0)
4881 + au_cpup_attr_nlink(inode, force);
4882 + inode->i_rdev = h_inode->i_rdev;
4883 + inode->i_blkbits = h_inode->i_blkbits;
4884 + au_cpup_igen(inode, h_inode);
4887 +/* ---------------------------------------------------------------------- */
4889 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4891 +/* keep the timestamps of the parent dir when cpup */
4892 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4893 + struct path *h_path)
4895 + struct inode *h_inode;
4897 + dt->dt_dentry = dentry;
4898 + dt->dt_h_path = *h_path;
4899 + h_inode = d_inode(h_path->dentry);
4900 + dt->dt_atime = h_inode->i_atime;
4901 + dt->dt_mtime = h_inode->i_mtime;
4905 +void au_dtime_revert(struct au_dtime *dt)
4907 + struct iattr attr;
4910 + attr.ia_atime = dt->dt_atime;
4911 + attr.ia_mtime = dt->dt_mtime;
4912 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4913 + | ATTR_ATIME | ATTR_ATIME_SET;
4915 + /* no delegation since this is a directory */
4916 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4917 + if (unlikely(err))
4918 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4921 +/* ---------------------------------------------------------------------- */
4923 +/* internal use only */
4924 +struct au_cpup_reg_attr {
4927 + unsigned int iflags; /* inode->i_flags */
4930 +static noinline_for_stack
4931 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4932 + struct au_cpup_reg_attr *h_src_attr)
4934 + int err, sbits, icex;
4935 + unsigned int mnt_flags;
4936 + unsigned char verbose;
4938 + struct path h_path;
4939 + struct inode *h_isrc, *h_idst;
4940 + struct kstat *h_st;
4941 + struct au_branch *br;
4943 + br = au_sbr(dst->d_sb, bindex);
4944 + h_path.mnt = au_br_mnt(br);
4945 + h_path.dentry = au_h_dptr(dst, bindex);
4946 + h_idst = d_inode(h_path.dentry);
4947 + h_isrc = d_inode(h_src->dentry);
4948 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4949 + | ATTR_ATIME | ATTR_MTIME
4950 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4951 + if (h_src_attr && h_src_attr->valid) {
4952 + h_st = &h_src_attr->st;
4953 + ia.ia_uid = h_st->uid;
4954 + ia.ia_gid = h_st->gid;
4955 + ia.ia_atime = h_st->atime;
4956 + ia.ia_mtime = h_st->mtime;
4957 + if (h_idst->i_mode != h_st->mode
4958 + && !S_ISLNK(h_idst->i_mode)) {
4959 + ia.ia_valid |= ATTR_MODE;
4960 + ia.ia_mode = h_st->mode;
4962 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4963 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4965 + ia.ia_uid = h_isrc->i_uid;
4966 + ia.ia_gid = h_isrc->i_gid;
4967 + ia.ia_atime = h_isrc->i_atime;
4968 + ia.ia_mtime = h_isrc->i_mtime;
4969 + if (h_idst->i_mode != h_isrc->i_mode
4970 + && !S_ISLNK(h_idst->i_mode)) {
4971 + ia.ia_valid |= ATTR_MODE;
4972 + ia.ia_mode = h_isrc->i_mode;
4974 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4975 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4977 + /* no delegation since it is just created */
4978 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4980 + /* is this nfs only? */
4981 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4982 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4983 + ia.ia_mode = h_isrc->i_mode;
4984 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4987 + icex = br->br_perm & AuBrAttr_ICEX;
4989 + mnt_flags = au_mntflags(dst->d_sb);
4990 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4991 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4997 +/* ---------------------------------------------------------------------- */
4999 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5000 + char *buf, unsigned long blksize)
5003 + size_t sz, rbytes, wbytes;
5004 + unsigned char all_zero;
5006 + struct inode *h_inode;
5007 + /* reduce stack usage */
5010 + zp = page_address(ZERO_PAGE(0));
5011 + if (unlikely(!zp))
5012 + return -ENOMEM; /* possible? */
5017 + AuDbg("len %lld\n", len);
5019 + if (len < blksize)
5023 + /* todo: signal_pending? */
5024 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5025 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5028 + if (unlikely(err < 0))
5032 + if (len >= rbytes && rbytes == blksize)
5033 + all_zero = !memcmp(buf, zp, rbytes);
5040 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5042 + /* todo: signal_pending? */
5043 + if (unlikely(err == -EAGAIN || err == -EINTR))
5045 + if (unlikely(err < 0))
5050 + if (unlikely(err < 0))
5056 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5058 + if (unlikely(res < 0))
5065 + /* the last block may be a hole */
5066 + if (!err && all_zero) {
5067 + AuLabel(last hole);
5070 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5071 + /* nfs requires this step to make last hole */
5072 + /* is this only nfs? */
5074 + /* todo: signal_pending? */
5075 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5076 + } while (err == -EAGAIN || err == -EINTR);
5083 + ia->ia_size = dst->f_pos;
5084 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5085 + ia->ia_file = dst;
5086 + h_inode = file_inode(dst);
5087 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5088 + /* no delegation since it is just created */
5089 + err = vfsub_notify_change(&dst->f_path, ia,
5090 + /*delegated*/NULL);
5091 + inode_unlock(h_inode);
5098 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5101 + unsigned long blksize;
5102 + unsigned char do_kfree;
5104 + struct super_block *h_sb;
5107 + h_sb = file_inode(dst)->i_sb;
5108 + blksize = h_sb->s_blocksize;
5109 + if (!blksize || PAGE_SIZE < blksize)
5110 + blksize = PAGE_SIZE;
5111 + AuDbg("blksize %lu\n", blksize);
5112 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5114 + buf = kmalloc(blksize, GFP_NOFS);
5116 + buf = (void *)__get_free_page(GFP_NOFS);
5117 + if (unlikely(!buf))
5120 + if (len > (1 << 22))
5121 + AuDbg("copying a large file %lld\n", (long long)len);
5125 + err = au_do_copy_file(dst, src, len, buf, blksize);
5127 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5128 + au_kfree_do_rcu(buf);
5130 + free_page((unsigned long)buf);
5136 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5139 + struct super_block *h_src_sb;
5140 + struct inode *h_src_inode;
5142 + h_src_inode = file_inode(src);
5143 + h_src_sb = h_src_inode->i_sb;
5145 + /* XFS acquires inode_lock */
5146 + if (!au_test_xfs(h_src_sb))
5147 + err = au_copy_file(dst, src, len);
5149 + inode_unlock_shared(h_src_inode);
5150 + err = au_copy_file(dst, src, len);
5151 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5157 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5161 + struct super_block *h_src_sb;
5162 + struct inode *h_src_inode;
5164 + h_src_inode = file_inode(src);
5165 + h_src_sb = h_src_inode->i_sb;
5166 + if (h_src_sb != file_inode(dst)->i_sb
5167 + || !dst->f_op->remap_file_range) {
5168 + err = au_do_copy(dst, src, len);
5172 + if (!au_test_nfs(h_src_sb)) {
5173 + inode_unlock_shared(h_src_inode);
5174 + lo = vfsub_clone_file_range(src, dst, len);
5175 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5177 + lo = vfsub_clone_file_range(src, dst, len);
5180 + goto out; /* success */
5181 + } else if (lo >= 0)
5182 + /* todo: possible? */
5183 + /* paritially succeeded */
5184 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5185 + else if (lo != -EOPNOTSUPP) {
5186 + /* older XFS has a condition in cloning */
5191 + /* the backend fs on NFS may not support cloning */
5192 + err = au_do_copy(dst, src, len);
5200 + * to support a sparse file which is opened with O_APPEND,
5201 + * we need to close the file.
5203 +static int au_cp_regular(struct au_cp_generic *cpg)
5206 + enum { SRC, DST };
5208 + aufs_bindex_t bindex;
5209 + unsigned int flags;
5210 + struct dentry *dentry;
5212 + struct file *file;
5215 + .bindex = cpg->bsrc,
5216 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5219 + .bindex = cpg->bdst,
5220 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5221 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5224 + struct au_branch *br;
5225 + struct super_block *sb, *h_src_sb;
5226 + struct inode *h_src_inode;
5227 + struct task_struct *tsk = current;
5229 + /* bsrc branch can be ro/rw. */
5230 + sb = cpg->dentry->d_sb;
5232 + for (i = 0; i < 2; i++, f++) {
5233 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5234 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5235 + /*file*/NULL, f->force_wr);
5236 + if (IS_ERR(f->file)) {
5237 + err = PTR_ERR(f->file);
5245 + /* try stopping to update while we copyup */
5246 + h_src_inode = d_inode(file[SRC].dentry);
5247 + h_src_sb = h_src_inode->i_sb;
5248 + if (!au_test_nfs(h_src_sb))
5249 + IMustLock(h_src_inode);
5250 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5252 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5253 + if (tsk->flags & PF_KTHREAD)
5254 + __fput_sync(file[DST].file);
5256 + /* it happened actually */
5257 + fput(file[DST].file);
5260 + * we have to call both since we don't know which place the file
5264 + flush_delayed_fput();
5266 + br = au_sbr(sb, file[DST].bindex);
5267 + au_lcnt_dec(&br->br_nfiles);
5270 + fput(file[SRC].file);
5271 + br = au_sbr(sb, file[SRC].bindex);
5272 + au_lcnt_dec(&br->br_nfiles);
5277 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5278 + struct au_cpup_reg_attr *h_src_attr)
5282 + struct path h_path;
5283 + struct inode *h_src_inode, *h_dst_inode;
5286 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5287 + l = i_size_read(h_src_inode);
5288 + if (cpg->len == -1 || l < cpg->len)
5291 + /* try stopping to update while we are referencing */
5292 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5293 + au_pin_hdir_unlock(cpg->pin);
5295 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5296 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5297 + h_src_attr->iflags = h_src_inode->i_flags;
5298 + if (!au_test_nfs(h_src_inode->i_sb))
5299 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5301 + inode_unlock_shared(h_src_inode);
5302 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5303 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5305 + if (unlikely(err)) {
5306 + inode_unlock_shared(h_src_inode);
5309 + h_src_attr->valid = 1;
5310 + if (!au_test_nfs(h_src_inode->i_sb)) {
5311 + err = au_cp_regular(cpg);
5312 + inode_unlock_shared(h_src_inode);
5314 + inode_unlock_shared(h_src_inode);
5315 + err = au_cp_regular(cpg);
5317 + rerr = au_pin_hdir_relock(cpg->pin);
5321 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5322 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5323 + h_dst_inode = d_inode(h_path.dentry);
5324 + spin_lock(&h_dst_inode->i_lock);
5325 + h_dst_inode->i_state |= I_LINKABLE;
5326 + spin_unlock(&h_dst_inode->i_lock);
5333 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5334 + struct inode *h_dir)
5337 + DEFINE_DELAYED_CALL(done);
5340 + sym = vfs_get_link(h_src, &done);
5341 + err = PTR_ERR(sym);
5345 + err = vfsub_symlink(h_dir, h_path, sym);
5348 + do_delayed_call(&done);
5353 + * regardless 'acl' option, reset all ACL.
5354 + * All ACL will be copied up later from the original entry on the lower branch.
5356 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5359 + struct dentry *h_dentry;
5360 + struct inode *h_inode;
5361 + struct user_namespace *h_userns;
5363 + h_userns = mnt_user_ns(h_path->mnt);
5364 + h_dentry = h_path->dentry;
5365 + h_inode = d_inode(h_dentry);
5366 + /* forget_all_cached_acls(h_inode)); */
5367 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5369 + if (err == -EOPNOTSUPP)
5372 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5378 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5379 + struct inode *h_dir, struct path *h_path)
5382 + struct inode *dir, *inode;
5383 + struct user_namespace *h_userns;
5385 + h_userns = mnt_user_ns(h_path->mnt);
5386 + err = vfsub_removexattr(h_userns, h_path->dentry,
5387 + XATTR_NAME_POSIX_ACL_DEFAULT);
5389 + if (err == -EOPNOTSUPP)
5391 + if (unlikely(err))
5395 + * strange behaviour from the users view,
5396 + * particularly setattr case
5398 + dir = d_inode(dst_parent);
5399 + if (au_ibtop(dir) == cpg->bdst)
5400 + au_cpup_attr_nlink(dir, /*force*/1);
5401 + inode = d_inode(cpg->dentry);
5402 + au_cpup_attr_nlink(inode, /*force*/1);
5408 +static noinline_for_stack
5409 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5410 + struct au_cpup_reg_attr *h_src_attr)
5414 + unsigned int mnt_flags;
5415 + unsigned char isdir, isreg, force;
5416 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5417 + struct au_dtime dt;
5418 + struct path h_path;
5419 + struct dentry *h_src, *h_dst, *h_parent;
5420 + struct inode *h_inode, *h_dir;
5421 + struct super_block *sb;
5423 + /* bsrc branch can be ro/rw. */
5424 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5425 + h_inode = d_inode(h_src);
5426 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5428 + /* try stopping to be referenced while we are creating */
5429 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5430 + if (au_ftest_cpup(cpg->flags, RENAME))
5431 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5432 + AUFS_WH_PFX_LEN));
5433 + h_parent = h_dst->d_parent; /* dir inode is locked */
5434 + h_dir = d_inode(h_parent);
5436 + AuDebugOn(h_parent != h_dst->d_parent);
5438 + sb = cpg->dentry->d_sb;
5439 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5441 + h_path.dentry = h_parent;
5442 + au_dtime_store(&dt, dst_parent, &h_path);
5444 + h_path.dentry = h_dst;
5448 + mode = h_inode->i_mode;
5449 + switch (mode & S_IFMT) {
5452 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5454 + err = au_do_cpup_regular(cpg, h_src_attr);
5458 + err = vfsub_mkdir(h_dir, &h_path, mode);
5460 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5463 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5467 + AuDebugOn(!capable(CAP_MKNOD));
5471 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5474 + AuIOErr("Unknown inode type 0%o\n", mode);
5478 + err = au_reset_acl(h_dir, &h_path, mode);
5480 + mnt_flags = au_mntflags(sb);
5481 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5483 + && au_opt_test(mnt_flags, XINO)
5484 + && (h_inode->i_nlink == 1
5485 + || (h_inode->i_state & I_LINKABLE))
5486 + /* todo: unnecessary? */
5487 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5488 + && cpg->bdst < cpg->bsrc
5489 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5490 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5491 + /* ignore this error */
5496 + force = !!cpg->len;
5497 + if (cpg->len == -1)
5498 + force = !!i_size_read(h_inode);
5500 + au_fhsm_wrote(sb, cpg->bdst, force);
5504 + au_dtime_revert(&dt);
5508 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5511 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5512 + struct path h_ppath;
5513 + struct inode *h_dir;
5514 + aufs_bindex_t bdst;
5516 + dentry = cpg->dentry;
5518 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5519 + h_dentry = au_h_dptr(dentry, bdst);
5520 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5522 + au_set_h_dptr(dentry, bdst, NULL);
5523 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5525 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5526 + au_set_h_dptr(dentry, bdst, h_dentry);
5529 + parent = dget_parent(dentry);
5530 + h_ppath.dentry = au_h_dptr(parent, bdst);
5532 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5533 + if (IS_ERR(h_path->dentry))
5534 + err = PTR_ERR(h_path->dentry);
5536 + if (unlikely(err))
5539 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5540 + h_dir = d_inode(h_parent);
5542 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5543 + /* no delegation since it is just created */
5544 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5546 + dput(h_path->dentry);
5553 + * copyup the @dentry from @bsrc to @bdst.
5554 + * the caller must set the both of lower dentries.
5555 + * @len is for truncating when it is -1 copyup the entire file.
5556 + * in link/rename cases, @dst_parent may be different from the real one.
5557 + * basic->bsrc can be larger than basic->bdst.
5558 + * aufs doesn't touch the credential so
5559 + * security_inode_copy_up{,_xattr}() are unnecessary.
5561 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5564 + aufs_bindex_t old_ibtop;
5565 + unsigned char isdir, plink;
5566 + struct dentry *h_src, *h_dst, *h_parent;
5567 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5568 + struct super_block *sb;
5569 + struct au_branch *br;
5570 + struct path h_src_path;
5571 + /* to reduce stack size */
5573 + struct au_dtime dt;
5574 + struct path h_path;
5575 + struct au_cpup_reg_attr h_src_attr;
5579 + a = kmalloc(sizeof(*a), GFP_NOFS);
5582 + a->h_src_attr.valid = 0;
5584 + sb = cpg->dentry->d_sb;
5585 + br = au_sbr(sb, cpg->bdst);
5586 + a->h_path.mnt = au_br_mnt(br);
5587 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5588 + h_parent = h_dst->d_parent; /* dir inode is locked */
5589 + h_dir = d_inode(h_parent);
5592 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5593 + inode = d_inode(cpg->dentry);
5596 + dst_parent = dget_parent(cpg->dentry);
5600 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5601 + dst_inode = au_h_iptr(inode, cpg->bdst);
5603 + if (unlikely(!plink)) {
5605 + AuIOErr("hi%lu(i%lu) exists on b%d "
5606 + "but plink is disabled\n",
5607 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5611 + if (dst_inode->i_nlink) {
5612 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5614 + h_src = au_plink_lkup(inode, cpg->bdst);
5615 + err = PTR_ERR(h_src);
5616 + if (IS_ERR(h_src))
5618 + if (unlikely(d_is_negative(h_src))) {
5620 + AuIOErr("i%lu exists on b%d "
5621 + "but not pseudo-linked\n",
5622 + inode->i_ino, cpg->bdst);
5628 + a->h_path.dentry = h_parent;
5629 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5632 + a->h_path.dentry = h_dst;
5634 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5635 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5636 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5638 + au_dtime_revert(&a->dt);
5639 + if (unlikely(err == -EWOULDBLOCK)) {
5640 + pr_warn("cannot retry for NFSv4 delegation"
5641 + " for an internal link\n");
5647 + /* todo: cpup_wh_file? */
5649 + au_update_ibrange(inode, /*do_put_zero*/1);
5652 + isdir = S_ISDIR(inode->i_mode);
5653 + old_ibtop = au_ibtop(inode);
5654 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5655 + if (unlikely(err))
5657 + dst_inode = d_inode(h_dst);
5658 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5659 + /* todo: necessary? */
5660 + /* au_pin_hdir_unlock(cpg->pin); */
5662 + h_src_path.dentry = h_src;
5663 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5664 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5665 + if (unlikely(err)) {
5666 + /* todo: necessary? */
5667 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5668 + inode_unlock(dst_inode);
5672 + if (cpg->bdst < old_ibtop) {
5673 + if (S_ISREG(inode->i_mode)) {
5674 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5675 + if (unlikely(err)) {
5676 + /* ignore an error */
5677 + /* au_pin_hdir_relock(cpg->pin); */
5678 + inode_unlock(dst_inode);
5682 + au_set_ibtop(inode, cpg->bdst);
5684 + au_set_ibbot(inode, cpg->bdst);
5685 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5686 + au_hi_flags(inode, isdir));
5688 + /* todo: necessary? */
5689 + /* err = au_pin_hdir_relock(cpg->pin); */
5690 + inode_unlock(dst_inode);
5691 + if (unlikely(err))
5694 + src_inode = d_inode(h_src);
5696 + && (src_inode->i_nlink > 1
5697 + || src_inode->i_state & I_LINKABLE)
5699 + au_plink_append(inode, cpg->bdst, h_dst);
5701 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5702 + a->h_path.dentry = h_dst;
5703 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5706 + goto out_parent; /* success */
5710 + a->h_path.dentry = h_parent;
5711 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5712 + a->h_path.dentry = h_dst;
5714 + if (d_is_positive(h_dst)) {
5716 + /* no delegation since it is just created */
5717 + rerr = vfsub_unlink(h_dir, &a->h_path,
5718 + /*delegated*/NULL, /*force*/0);
5720 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5722 + au_dtime_revert(&a->dt);
5724 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5734 +#if 0 /* reserved */
5735 +struct au_cpup_single_args {
5737 + struct au_cp_generic *cpg;
5738 + struct dentry *dst_parent;
5741 +static void au_call_cpup_single(void *args)
5743 + struct au_cpup_single_args *a = args;
5745 + au_pin_hdir_acquire_nest(a->cpg->pin);
5746 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5747 + au_pin_hdir_release(a->cpg->pin);
5752 + * prevent SIGXFSZ in copy-up.
5753 + * testing CAP_MKNOD is for generic fs,
5754 + * but CAP_FSETID is for xfs only, currently.
5756 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5759 + struct super_block *sb;
5760 + struct inode *h_dir;
5763 + sb = au_pinned_parent(pin)->d_sb;
5764 + if (!au_wkq_test()
5765 + && (!au_sbi(sb)->si_plink_maint_pid
5766 + || au_plink_maint(sb, AuLock_NOPLM))) {
5767 + switch (mode & S_IFMT) {
5769 + /* no condition about RLIMIT_FSIZE and the file size */
5774 + do_sio = !capable(CAP_MKNOD);
5778 + do_sio = ((mode & (S_ISUID | S_ISGID))
5779 + && !capable(CAP_FSETID));
5780 + /* this workaround may be removed in the future */
5782 + h_dir = au_pinned_h_dir(pin);
5783 + do_sio = h_dir->i_mode & S_ISVTX;
5790 +#if 0 /* reserved */
5791 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5794 + struct dentry *h_dentry;
5796 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5797 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5798 + err = au_cpup_single(cpg, dst_parent);
5800 + struct au_cpup_single_args args = {
5803 + .dst_parent = dst_parent
5805 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5806 + if (unlikely(wkq_err))
5815 + * copyup the @dentry from the first active lower branch to @bdst,
5816 + * using au_cpup_single().
5818 +static int au_cpup_simple(struct au_cp_generic *cpg)
5821 + unsigned int flags_orig;
5822 + struct dentry *dentry;
5824 + AuDebugOn(cpg->bsrc < 0);
5826 + dentry = cpg->dentry;
5827 + DiMustWriteLock(dentry);
5829 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5831 + flags_orig = cpg->flags;
5832 + au_fset_cpup(cpg->flags, RENAME);
5833 + err = au_cpup_single(cpg, NULL);
5834 + cpg->flags = flags_orig;
5836 + return 0; /* success */
5839 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5840 + au_set_dbtop(dentry, cpg->bsrc);
5846 +struct au_cpup_simple_args {
5848 + struct au_cp_generic *cpg;
5851 +static void au_call_cpup_simple(void *args)
5853 + struct au_cpup_simple_args *a = args;
5855 + au_pin_hdir_acquire_nest(a->cpg->pin);
5856 + *a->errp = au_cpup_simple(a->cpg);
5857 + au_pin_hdir_release(a->cpg->pin);
5860 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5863 + struct dentry *dentry, *parent;
5864 + struct file *h_file;
5865 + struct inode *h_dir;
5866 + struct user_namespace *h_userns;
5868 + dentry = cpg->dentry;
5870 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5871 + AuDebugOn(cpg->bsrc < 0);
5872 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5873 + err = PTR_ERR(h_file);
5874 + if (IS_ERR(h_file))
5878 + parent = dget_parent(dentry);
5879 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5880 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5881 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5882 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5883 + err = au_cpup_simple(cpg);
5885 + struct au_cpup_simple_args args = {
5889 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5890 + if (unlikely(wkq_err))
5896 + au_h_open_post(dentry, cpg->bsrc, h_file);
5902 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5904 + aufs_bindex_t bsrc, bbot;
5905 + struct dentry *dentry, *h_dentry;
5907 + if (cpg->bsrc < 0) {
5908 + dentry = cpg->dentry;
5909 + bbot = au_dbbot(dentry);
5910 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5911 + h_dentry = au_h_dptr(dentry, bsrc);
5913 + AuDebugOn(d_is_negative(h_dentry));
5917 + AuDebugOn(bsrc > bbot);
5920 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5921 + return au_do_sio_cpup_simple(cpg);
5924 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5926 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5927 + return au_do_sio_cpup_simple(cpg);
5930 +/* ---------------------------------------------------------------------- */
5933 + * copyup the deleted file for writing.
5935 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5936 + struct file *file)
5939 + unsigned int flags_orig;
5940 + aufs_bindex_t bsrc_orig;
5941 + struct au_dinfo *dinfo;
5943 + struct au_hdentry *hd;
5944 + struct dentry *h_dentry;
5947 + dinfo = au_di(cpg->dentry);
5948 + AuRwMustWriteLock(&dinfo->di_rwsem);
5950 + bsrc_orig = cpg->bsrc;
5951 + cpg->bsrc = dinfo->di_btop;
5952 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5953 + hdst.h_dentry = hdst.hd->hd_dentry;
5954 + hdst.hd->hd_dentry = wh_dentry;
5955 + dinfo->di_btop = cpg->bdst;
5957 + hsrc.h_dentry = NULL;
5959 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5960 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5961 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5963 + flags_orig = cpg->flags;
5964 + cpg->flags = !AuCpup_DTIME;
5965 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5966 + cpg->flags = flags_orig;
5969 + err = au_reopen_nondir(file);
5970 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5972 + hdst.hd->hd_dentry = hdst.h_dentry;
5973 + dinfo->di_btop = cpg->bsrc;
5974 + cpg->bsrc = bsrc_orig;
5979 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5982 + aufs_bindex_t bdst;
5983 + struct au_dtime dt;
5984 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5985 + struct au_branch *br;
5986 + struct path h_path;
5988 + dentry = cpg->dentry;
5990 + br = au_sbr(dentry->d_sb, bdst);
5991 + parent = dget_parent(dentry);
5992 + h_parent = au_h_dptr(parent, bdst);
5993 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5994 + err = PTR_ERR(wh_dentry);
5995 + if (IS_ERR(wh_dentry))
5998 + h_path.dentry = h_parent;
5999 + h_path.mnt = au_br_mnt(br);
6000 + au_dtime_store(&dt, parent, &h_path);
6001 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6002 + if (unlikely(err))
6006 + h_path.dentry = wh_dentry;
6007 + if (!d_is_dir(wh_dentry)) {
6008 + /* no delegation since it is just created */
6009 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6010 + /*delegated*/NULL, /*force*/0);
6012 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6013 + if (unlikely(err)) {
6014 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6018 + au_dtime_revert(&dt);
6019 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6028 +struct au_cpup_wh_args {
6030 + struct au_cp_generic *cpg;
6031 + struct file *file;
6034 +static void au_call_cpup_wh(void *args)
6036 + struct au_cpup_wh_args *a = args;
6038 + au_pin_hdir_acquire_nest(a->cpg->pin);
6039 + *a->errp = au_cpup_wh(a->cpg, a->file);
6040 + au_pin_hdir_release(a->cpg->pin);
6043 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6046 + aufs_bindex_t bdst;
6047 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6048 + struct inode *dir, *h_dir, *h_tmpdir;
6049 + struct au_wbr *wbr;
6050 + struct au_pin wh_pin, *pin_orig;
6051 + struct user_namespace *h_userns;
6053 + dentry = cpg->dentry;
6055 + parent = dget_parent(dentry);
6056 + dir = d_inode(parent);
6059 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6062 + if (!h_dir->i_nlink) {
6063 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6064 + h_orph = wbr->wbr_orph;
6066 + h_parent = dget(au_h_dptr(parent, bdst));
6067 + au_set_h_dptr(parent, bdst, dget(h_orph));
6068 + h_tmpdir = d_inode(h_orph);
6069 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6071 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6072 + /* todo: au_h_open_pre()? */
6074 + pin_orig = cpg->pin;
6075 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6076 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6077 + cpg->pin = &wh_pin;
6080 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6081 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6082 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6083 + err = au_cpup_wh(cpg, file);
6085 + struct au_cpup_wh_args args = {
6090 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6091 + if (unlikely(wkq_err))
6096 + inode_unlock(h_tmpdir);
6097 + /* todo: au_h_open_post()? */
6098 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6099 + au_set_h_dptr(parent, bdst, h_parent);
6100 + AuDebugOn(!pin_orig);
6101 + cpg->pin = pin_orig;
6109 +/* ---------------------------------------------------------------------- */
6112 + * generic routine for both of copy-up and copy-down.
6114 +/* cf. revalidate function in file.c */
6115 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6116 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6117 + struct au_pin *pin,
6118 + struct dentry *h_parent, void *arg),
6122 + struct au_pin pin;
6123 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6126 + parent = dget_parent(dentry);
6127 + if (IS_ROOT(parent))
6130 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6131 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6133 + /* do not use au_dpage */
6134 + real_parent = parent;
6137 + parent = dget_parent(dentry);
6138 + h_parent = au_h_dptr(parent, bdst);
6140 + goto out; /* success */
6142 + /* find top dir which is necessary to cpup */
6146 + parent = dget_parent(d);
6147 + di_read_lock_parent3(parent, !AuLock_IR);
6148 + h_parent = au_h_dptr(parent, bdst);
6149 + di_read_unlock(parent, !AuLock_IR);
6150 + } while (!h_parent);
6152 + if (d != real_parent)
6153 + di_write_lock_child3(d);
6155 + /* somebody else might create while we were sleeping */
6156 + h_dentry = au_h_dptr(d, bdst);
6157 + if (!h_dentry || d_is_negative(h_dentry)) {
6159 + au_update_dbtop(d);
6161 + au_pin_set_dentry(&pin, d);
6162 + err = au_do_pin(&pin);
6164 + err = cp(d, bdst, &pin, h_parent, arg);
6169 + if (d != real_parent)
6170 + di_write_unlock(d);
6171 + if (unlikely(err))
6180 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6181 + struct au_pin *pin,
6182 + struct dentry *h_parent __maybe_unused,
6183 + void *arg __maybe_unused)
6185 + struct au_cp_generic cpg = {
6191 + .flags = AuCpup_DTIME
6193 + return au_sio_cpup_simple(&cpg);
6196 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6198 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6201 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6204 + struct dentry *parent;
6205 + struct inode *dir;
6207 + parent = dget_parent(dentry);
6208 + dir = d_inode(parent);
6210 + if (au_h_iptr(dir, bdst))
6213 + di_read_unlock(parent, AuLock_IR);
6214 + di_write_lock_parent(parent);
6215 + /* someone else might change our inode while we were sleeping */
6216 + if (!au_h_iptr(dir, bdst))
6217 + err = au_cpup_dirs(dentry, bdst);
6218 + di_downgrade_lock(parent, AuLock_IR);
6224 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6225 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6226 +++ linux/fs/aufs/cpup.h 2021-12-03 15:38:59.933313976 +0100
6228 +/* SPDX-License-Identifier: GPL-2.0 */
6230 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6232 + * This program, aufs is free software; you can redistribute it and/or modify
6233 + * it under the terms of the GNU General Public License as published by
6234 + * the Free Software Foundation; either version 2 of the License, or
6235 + * (at your option) any later version.
6237 + * This program is distributed in the hope that it will be useful,
6238 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6240 + * GNU General Public License for more details.
6242 + * You should have received a copy of the GNU General Public License
6243 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6247 + * copy-up/down functions
6250 +#ifndef __AUFS_CPUP_H__
6251 +#define __AUFS_CPUP_H__
6255 +#include <linux/path.h>
6261 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6262 +void au_cpup_attr_timesizes(struct inode *inode);
6263 +void au_cpup_attr_nlink(struct inode *inode, int force);
6264 +void au_cpup_attr_changeable(struct inode *inode);
6265 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6266 +void au_cpup_attr_all(struct inode *inode, int force);
6268 +/* ---------------------------------------------------------------------- */
6270 +struct au_cp_generic {
6271 + struct dentry *dentry;
6272 + aufs_bindex_t bdst, bsrc;
6274 + struct au_pin *pin;
6275 + unsigned int flags;
6279 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6280 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6282 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6283 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6285 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6287 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6288 + the branch is marked as RO */
6290 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6291 +#undef AuCpup_HOPEN
6292 +#define AuCpup_HOPEN 0
6295 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6296 +#define au_fset_cpup(flags, name) \
6297 + do { (flags) |= AuCpup_##name; } while (0)
6298 +#define au_fclr_cpup(flags, name) \
6299 + do { (flags) &= ~AuCpup_##name; } while (0)
6301 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6302 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6303 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6304 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6306 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6307 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6308 + struct au_pin *pin,
6309 + struct dentry *h_parent, void *arg),
6311 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6312 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6314 +/* ---------------------------------------------------------------------- */
6316 +/* keep timestamps when copyup */
6318 + struct dentry *dt_dentry;
6319 + struct path dt_h_path;
6320 + struct timespec64 dt_atime, dt_mtime;
6322 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6323 + struct path *h_path);
6324 +void au_dtime_revert(struct au_dtime *dt);
6326 +#endif /* __KERNEL__ */
6327 +#endif /* __AUFS_CPUP_H__ */
6328 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6329 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6330 +++ linux/fs/aufs/dbgaufs.c 2021-12-03 15:38:59.933313976 +0100
6332 +// SPDX-License-Identifier: GPL-2.0
6334 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6336 + * This program, aufs is free software; you can redistribute it and/or modify
6337 + * it under the terms of the GNU General Public License as published by
6338 + * the Free Software Foundation; either version 2 of the License, or
6339 + * (at your option) any later version.
6341 + * This program is distributed in the hope that it will be useful,
6342 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6343 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6344 + * GNU General Public License for more details.
6346 + * You should have received a copy of the GNU General Public License
6347 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6351 + * debugfs interface
6354 +#include <linux/debugfs.h>
6357 +#ifndef CONFIG_SYSFS
6358 +#error DEBUG_FS depends upon SYSFS
6361 +static struct dentry *dbgaufs;
6362 +static const mode_t dbgaufs_mode = 0444;
6364 +/* 20 is max digits length of ulong 64 */
6365 +struct dbgaufs_arg {
6371 + * common function for all XINO files
6373 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6374 + struct file *file)
6378 + p = file->private_data;
6380 + /* this is struct dbgaufs_arg */
6381 + AuDebugOn(!au_kfree_sz_test(p));
6382 + au_kfree_do_rcu(p);
6387 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6392 + struct dbgaufs_arg *p;
6395 + p = kmalloc(sizeof(*p), GFP_NOFS);
6401 + file->private_data = p;
6405 + err = vfsub_getattr(&xf->f_path, &st);
6409 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6410 + cnt, st.blocks, st.blksize,
6411 + (long long)st.size);
6413 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6414 + st.blocks, st.blksize,
6415 + (long long)st.size);
6416 + AuDebugOn(p->n >= sizeof(p->a));
6418 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6426 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6427 + size_t count, loff_t *ppos)
6429 + struct dbgaufs_arg *p;
6431 + p = file->private_data;
6432 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6435 +/* ---------------------------------------------------------------------- */
6437 +struct dbgaufs_plink_arg {
6442 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6443 + struct file *file)
6445 + free_page((unsigned long)file->private_data);
6449 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6451 + int err, i, limit;
6452 + unsigned long n, sum;
6453 + struct dbgaufs_plink_arg *p;
6454 + struct au_sbinfo *sbinfo;
6455 + struct super_block *sb;
6456 + struct hlist_bl_head *hbl;
6459 + p = (void *)get_zeroed_page(GFP_NOFS);
6464 + sbinfo = inode->i_private;
6465 + sb = sbinfo->si_sb;
6466 + si_noflush_read_lock(sb);
6467 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6468 + limit = PAGE_SIZE - sizeof(p->n);
6470 + /* the number of buckets */
6471 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6476 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6478 + n = au_hbl_count(hbl);
6481 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6484 + if (unlikely(limit <= 0))
6487 + p->a[p->n - 1] = '\n';
6489 + /* the sum of plinks */
6490 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6493 + if (unlikely(limit <= 0))
6496 +#define str "1\n0\n0\n"
6497 + p->n = sizeof(str) - 1;
6498 + strcpy(p->a, str);
6501 + si_read_unlock(sb);
6504 + file->private_data = p;
6505 + goto out; /* success */
6508 + free_page((unsigned long)p);
6513 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6514 + size_t count, loff_t *ppos)
6516 + struct dbgaufs_plink_arg *p;
6518 + p = file->private_data;
6519 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6522 +static const struct file_operations dbgaufs_plink_fop = {
6523 + .owner = THIS_MODULE,
6524 + .open = dbgaufs_plink_open,
6525 + .release = dbgaufs_plink_release,
6526 + .read = dbgaufs_plink_read
6529 +/* ---------------------------------------------------------------------- */
6531 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6534 + struct au_sbinfo *sbinfo;
6535 + struct super_block *sb;
6537 + sbinfo = inode->i_private;
6538 + sb = sbinfo->si_sb;
6539 + si_noflush_read_lock(sb);
6540 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6541 + si_read_unlock(sb);
6545 +static const struct file_operations dbgaufs_xib_fop = {
6546 + .owner = THIS_MODULE,
6547 + .open = dbgaufs_xib_open,
6548 + .release = dbgaufs_xi_release,
6549 + .read = dbgaufs_xi_read
6552 +/* ---------------------------------------------------------------------- */
6554 +#define DbgaufsXi_PREFIX "xi"
6556 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6560 + aufs_bindex_t bindex;
6561 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6562 + struct au_sbinfo *sbinfo;
6563 + struct super_block *sb;
6564 + struct au_xino *xi;
6566 + struct qstr *name;
6567 + struct au_branch *br;
6570 + name = &file->f_path.dentry->d_name;
6571 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6572 + || memcmp(name->name, DbgaufsXi_PREFIX,
6573 + sizeof(DbgaufsXi_PREFIX) - 1)))
6576 + AuDebugOn(name->len >= sizeof(a));
6577 + memcpy(a, name->name, name->len);
6578 + a[name->len] = '\0';
6579 + p = strchr(a, '-');
6582 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6583 + if (unlikely(err))
6588 + err = kstrtol(p + 1, 10, &l);
6589 + if (unlikely(err))
6595 + sbinfo = inode->i_private;
6596 + sb = sbinfo->si_sb;
6597 + si_noflush_read_lock(sb);
6598 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6600 + br = au_sbr(sb, bindex);
6602 + if (unlikely(idx >= xi->xi_nfile))
6604 + xf = au_xino_file(xi, idx);
6606 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6607 + au_xino_count(br));
6610 + si_read_unlock(sb);
6616 +static const struct file_operations dbgaufs_xino_fop = {
6617 + .owner = THIS_MODULE,
6618 + .open = dbgaufs_xino_open,
6619 + .release = dbgaufs_xi_release,
6620 + .read = dbgaufs_xi_read
6623 +void dbgaufs_xino_del(struct au_branch *br)
6625 + struct dentry *dbgaufs;
6627 + dbgaufs = br->br_dbgaufs;
6631 + br->br_dbgaufs = NULL;
6632 + /* debugfs acquires the parent i_mutex */
6634 + debugfs_remove(dbgaufs);
6638 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6640 + aufs_bindex_t bbot;
6641 + struct au_branch *br;
6643 + if (!au_sbi(sb)->si_dbgaufs)
6646 + bbot = au_sbbot(sb);
6647 + for (; bindex <= bbot; bindex++) {
6648 + br = au_sbr(sb, bindex);
6649 + dbgaufs_xino_del(br);
6653 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6654 + unsigned int idx, struct dentry *parent,
6655 + struct au_sbinfo *sbinfo)
6657 + struct au_branch *br;
6659 + /* "xi" bindex(5) "-" idx(2) NULL */
6660 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6663 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6665 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6667 + br = au_sbr(sb, bindex);
6668 + if (br->br_dbgaufs) {
6669 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6671 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6672 + /* debugfs acquires the parent i_mutex */
6674 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6678 + pr_warn("failed renaming %pd/%s, ignored.\n",
6683 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6684 + sbinfo, &dbgaufs_xino_fop);
6686 + if (unlikely(!br->br_dbgaufs))
6687 + pr_warn("failed creating %pd/%s, ignored.\n",
6692 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6693 + struct dentry *parent, struct au_sbinfo *sbinfo)
6695 + struct au_branch *br;
6696 + struct au_xino *xi;
6699 + br = au_sbr(sb, bindex);
6701 + for (u = 0; u < xi->xi_nfile; u++)
6702 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6705 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6707 + struct au_sbinfo *sbinfo;
6708 + struct dentry *parent;
6709 + aufs_bindex_t bbot;
6711 + if (!au_opt_test(au_mntflags(sb), XINO))
6714 + sbinfo = au_sbi(sb);
6715 + parent = sbinfo->si_dbgaufs;
6719 + bbot = au_sbbot(sb);
6721 + for (; bindex <= bbot; bindex++)
6722 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6724 + for (; bbot >= bindex; bbot--)
6725 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6728 +/* ---------------------------------------------------------------------- */
6730 +#ifdef CONFIG_AUFS_EXPORT
6731 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6734 + struct au_sbinfo *sbinfo;
6735 + struct super_block *sb;
6737 + sbinfo = inode->i_private;
6738 + sb = sbinfo->si_sb;
6739 + si_noflush_read_lock(sb);
6740 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6741 + si_read_unlock(sb);
6745 +static const struct file_operations dbgaufs_xigen_fop = {
6746 + .owner = THIS_MODULE,
6747 + .open = dbgaufs_xigen_open,
6748 + .release = dbgaufs_xi_release,
6749 + .read = dbgaufs_xi_read
6752 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6757 + * This function is a dynamic '__init' function actually,
6758 + * so the tiny check for si_rwsem is unnecessary.
6760 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6763 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6764 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6765 + &dbgaufs_xigen_fop);
6766 + if (sbinfo->si_dbgaufs_xigen)
6772 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6776 +#endif /* CONFIG_AUFS_EXPORT */
6778 +/* ---------------------------------------------------------------------- */
6780 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6783 + * This function is a dynamic '__fin' function actually,
6784 + * so the tiny check for si_rwsem is unnecessary.
6786 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6788 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6789 + sbinfo->si_dbgaufs = NULL;
6792 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6795 + char name[SysaufsSiNameLen];
6798 + * This function is a dynamic '__init' function actually,
6799 + * so the tiny check for si_rwsem is unnecessary.
6801 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6805 + AuErr1("/debug/aufs is uninitialized\n");
6810 + sysaufs_name(sbinfo, name);
6811 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6812 + if (unlikely(!sbinfo->si_dbgaufs))
6815 + /* regardless plink/noplink option */
6816 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6817 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6818 + &dbgaufs_plink_fop);
6819 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6822 + /* regardless xino/noxino option */
6823 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6824 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6825 + &dbgaufs_xib_fop);
6826 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6829 + err = dbgaufs_xigen_init(sbinfo);
6831 + goto out; /* success */
6834 + dbgaufs_si_fin(sbinfo);
6836 + if (unlikely(err))
6837 + pr_err("debugfs/aufs failed\n");
6841 +/* ---------------------------------------------------------------------- */
6843 +void dbgaufs_fin(void)
6845 + debugfs_remove(dbgaufs);
6848 +int __init dbgaufs_init(void)
6853 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6858 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6859 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6860 +++ linux/fs/aufs/dbgaufs.h 2021-12-03 15:38:59.933313976 +0100
6862 +/* SPDX-License-Identifier: GPL-2.0 */
6864 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6866 + * This program, aufs is free software; you can redistribute it and/or modify
6867 + * it under the terms of the GNU General Public License as published by
6868 + * the Free Software Foundation; either version 2 of the License, or
6869 + * (at your option) any later version.
6871 + * This program is distributed in the hope that it will be useful,
6872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6874 + * GNU General Public License for more details.
6876 + * You should have received a copy of the GNU General Public License
6877 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6881 + * debugfs interface
6884 +#ifndef __DBGAUFS_H__
6885 +#define __DBGAUFS_H__
6889 +struct super_block;
6893 +#ifdef CONFIG_DEBUG_FS
6895 +void dbgaufs_xino_del(struct au_branch *br);
6896 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6897 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6898 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6899 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6900 +void dbgaufs_fin(void);
6901 +int __init dbgaufs_init(void);
6903 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6904 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6905 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6907 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6908 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6909 +AuStubVoid(dbgaufs_fin, void)
6910 +AuStubInt0(__init dbgaufs_init, void)
6911 +#endif /* CONFIG_DEBUG_FS */
6913 +#endif /* __KERNEL__ */
6914 +#endif /* __DBGAUFS_H__ */
6915 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6916 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6917 +++ linux/fs/aufs/dcsub.c 2021-12-03 15:38:59.933313976 +0100
6919 +// SPDX-License-Identifier: GPL-2.0
6921 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6923 + * This program, aufs is free software; you can redistribute it and/or modify
6924 + * it under the terms of the GNU General Public License as published by
6925 + * the Free Software Foundation; either version 2 of the License, or
6926 + * (at your option) any later version.
6928 + * This program is distributed in the hope that it will be useful,
6929 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6930 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6931 + * GNU General Public License for more details.
6933 + * You should have received a copy of the GNU General Public License
6934 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6938 + * sub-routines for dentry cache
6943 +static void au_dpage_free(struct au_dpage *dpage)
6946 + struct dentry **p;
6948 + p = dpage->dentries;
6949 + for (i = 0; i < dpage->ndentry; i++)
6951 + free_page((unsigned long)dpage->dentries);
6954 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6960 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6961 + if (unlikely(!dpages->dpages))
6964 + p = (void *)__get_free_page(gfp);
6968 + dpages->dpages[0].ndentry = 0;
6969 + dpages->dpages[0].dentries = p;
6970 + dpages->ndpage = 1;
6971 + return 0; /* success */
6974 + au_kfree_try_rcu(dpages->dpages);
6979 +void au_dpages_free(struct au_dcsub_pages *dpages)
6982 + struct au_dpage *p;
6984 + p = dpages->dpages;
6985 + for (i = 0; i < dpages->ndpage; i++)
6986 + au_dpage_free(p++);
6987 + au_kfree_try_rcu(dpages->dpages);
6990 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6991 + struct dentry *dentry, gfp_t gfp)
6994 + struct au_dpage *dpage;
6997 + dpage = dpages->dpages + dpages->ndpage - 1;
6998 + sz = PAGE_SIZE / sizeof(dentry);
6999 + if (unlikely(dpage->ndentry >= sz)) {
7000 + AuLabel(new dpage);
7002 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7003 + p = au_kzrealloc(dpages->dpages, sz,
7004 + sz + sizeof(*dpages->dpages), gfp,
7009 + dpages->dpages = p;
7010 + dpage = dpages->dpages + dpages->ndpage;
7011 + p = (void *)__get_free_page(gfp);
7015 + dpage->ndentry = 0;
7016 + dpage->dentries = p;
7020 + AuDebugOn(au_dcount(dentry) <= 0);
7021 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7022 + return 0; /* success */
7028 +/* todo: BAD approach */
7029 +/* copied from linux/fs/dcache.c */
7037 +extern void d_walk(struct dentry *parent, void *data,
7038 + enum d_walk_ret (*enter)(void *, struct dentry *));
7040 +struct ac_dpages_arg {
7042 + struct au_dcsub_pages *dpages;
7043 + struct super_block *sb;
7044 + au_dpages_test test;
7048 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7050 + enum d_walk_ret ret;
7051 + struct ac_dpages_arg *arg = _arg;
7053 + ret = D_WALK_CONTINUE;
7054 + if (dentry->d_sb == arg->sb
7055 + && !IS_ROOT(dentry)
7056 + && au_dcount(dentry) > 0
7058 + && (!arg->test || arg->test(dentry, arg->arg))) {
7059 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7060 + if (unlikely(arg->err))
7061 + ret = D_WALK_QUIT;
7067 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7068 + au_dpages_test test, void *arg)
7070 + struct ac_dpages_arg args = {
7078 + d_walk(root, &args, au_call_dpages_append);
7083 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7084 + int do_include, au_dpages_test test, void *arg)
7089 + write_seqlock(&rename_lock);
7090 + spin_lock(&dentry->d_lock);
7092 + && au_dcount(dentry) > 0
7093 + && (!test || test(dentry, arg)))
7094 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7095 + spin_unlock(&dentry->d_lock);
7096 + if (unlikely(err))
7100 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7103 + while (!IS_ROOT(dentry)) {
7104 + dentry = dentry->d_parent; /* rename_lock is locked */
7105 + spin_lock(&dentry->d_lock);
7106 + if (au_dcount(dentry) > 0
7107 + && (!test || test(dentry, arg)))
7108 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7109 + spin_unlock(&dentry->d_lock);
7110 + if (unlikely(err))
7115 + write_sequnlock(&rename_lock);
7119 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7121 + return au_di(dentry) && dentry->d_sb == arg;
7124 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7125 + struct dentry *dentry, int do_include)
7127 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7128 + au_dcsub_dpages_aufs, dentry->d_sb);
7131 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7133 + struct path path[2] = {
7142 + return path_is_under(path + 0, path + 1);
7144 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7145 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7146 +++ linux/fs/aufs/dcsub.h 2021-12-03 15:38:59.933313976 +0100
7148 +/* SPDX-License-Identifier: GPL-2.0 */
7150 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7152 + * This program, aufs is free software; you can redistribute it and/or modify
7153 + * it under the terms of the GNU General Public License as published by
7154 + * the Free Software Foundation; either version 2 of the License, or
7155 + * (at your option) any later version.
7157 + * This program is distributed in the hope that it will be useful,
7158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7160 + * GNU General Public License for more details.
7162 + * You should have received a copy of the GNU General Public License
7163 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7167 + * sub-routines for dentry cache
7170 +#ifndef __AUFS_DCSUB_H__
7171 +#define __AUFS_DCSUB_H__
7175 +#include <linux/dcache.h>
7176 +#include <linux/fs.h>
7180 + struct dentry **dentries;
7183 +struct au_dcsub_pages {
7185 + struct au_dpage *dpages;
7188 +/* ---------------------------------------------------------------------- */
7191 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7192 +void au_dpages_free(struct au_dcsub_pages *dpages);
7193 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7194 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7195 + au_dpages_test test, void *arg);
7196 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7197 + int do_include, au_dpages_test test, void *arg);
7198 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7199 + struct dentry *dentry, int do_include);
7200 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7202 +/* ---------------------------------------------------------------------- */
7205 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7206 + * include/linux/dcache.h. Try them (in the future).
7209 +static inline int au_d_hashed_positive(struct dentry *d)
7212 + struct inode *inode = d_inode(d);
7215 + if (unlikely(d_unhashed(d)
7216 + || d_is_negative(d)
7217 + || !inode->i_nlink))
7222 +static inline int au_d_linkable(struct dentry *d)
7225 + struct inode *inode = d_inode(d);
7227 + err = au_d_hashed_positive(d);
7229 + && d_is_positive(d)
7230 + && (inode->i_state & I_LINKABLE))
7235 +static inline int au_d_alive(struct dentry *d)
7238 + struct inode *inode;
7242 + err = au_d_hashed_positive(d);
7244 + inode = d_inode(d);
7245 + if (unlikely(d_unlinked(d)
7246 + || d_is_negative(d)
7247 + || !inode->i_nlink))
7253 +static inline int au_alive_dir(struct dentry *d)
7257 + err = au_d_alive(d);
7258 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7263 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7265 + return a->len == b->len
7266 + && !memcmp(a->name, b->name, a->len);
7271 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7273 + * the type of d_lockref.count became int, but the inlined function d_count()
7274 + * still returns unsigned int.
7275 + * I don't know why. Maybe it is for every d_count() users?
7276 + * Anyway au_dcount() lives on.
7278 +static inline int au_dcount(struct dentry *d)
7280 + return (int)d_count(d);
7283 +#endif /* __KERNEL__ */
7284 +#endif /* __AUFS_DCSUB_H__ */
7285 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7286 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7287 +++ linux/fs/aufs/debug.c 2021-12-03 15:38:59.933313976 +0100
7289 +// SPDX-License-Identifier: GPL-2.0
7291 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7293 + * This program, aufs is free software; you can redistribute it and/or modify
7294 + * it under the terms of the GNU General Public License as published by
7295 + * the Free Software Foundation; either version 2 of the License, or
7296 + * (at your option) any later version.
7298 + * This program is distributed in the hope that it will be useful,
7299 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7300 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7301 + * GNU General Public License for more details.
7303 + * You should have received a copy of the GNU General Public License
7304 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7308 + * debug print functions
7311 +#include <linux/iversion.h>
7314 +/* Returns 0, or -errno. arg is in kp->arg. */
7315 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7319 + err = kstrtoint(val, 0, &n);
7329 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7330 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7335 + return sprintf(buffer, "%d", atomic_read(a));
7338 +static struct kernel_param_ops param_ops_atomic_t = {
7339 + .set = param_atomic_t_set,
7340 + .get = param_atomic_t_get
7341 + /* void (*free)(void *arg) */
7344 +atomic_t aufs_debug = ATOMIC_INIT(0);
7345 +MODULE_PARM_DESC(debug, "debug print");
7346 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7348 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7349 +char *au_plevel = KERN_DEBUG;
7350 +#define dpri(fmt, ...) do { \
7352 + && strcmp(au_plevel, KERN_DEBUG)) \
7353 + || au_debug_test()) \
7354 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7357 +/* ---------------------------------------------------------------------- */
7359 +void au_dpri_whlist(struct au_nhash *whlist)
7361 + unsigned long ul, n;
7362 + struct hlist_head *head;
7363 + struct au_vdir_wh *pos;
7365 + n = whlist->nh_num;
7366 + head = whlist->nh_head;
7367 + for (ul = 0; ul < n; ul++) {
7368 + hlist_for_each_entry(pos, head, wh_hash)
7369 + dpri("b%d, %.*s, %d\n",
7371 + pos->wh_str.len, pos->wh_str.name,
7377 +void au_dpri_vdir(struct au_vdir *vdir)
7380 + union au_vdir_deblk_p p;
7383 + if (!vdir || IS_ERR(vdir)) {
7384 + dpri("err %ld\n", PTR_ERR(vdir));
7388 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7389 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7390 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7391 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7392 + p.deblk = vdir->vd_deblk[ul];
7394 + dpri("[%lu]: %p\n", ul, o);
7398 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7399 + struct dentry *wh)
7404 + if (!inode || IS_ERR(inode)) {
7405 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7409 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7410 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7411 + && sizeof(inode->i_blocks) != sizeof(u64));
7413 + n = (void *)wh->d_name.name;
7414 + l = wh->d_name.len;
7417 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7418 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7420 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7421 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7422 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7423 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7424 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7425 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7426 + inode->i_generation,
7427 + l ? ", wh " : "", l, n);
7431 +void au_dpri_inode(struct inode *inode)
7433 + struct au_iinfo *iinfo;
7434 + struct au_hinode *hi;
7435 + aufs_bindex_t bindex;
7438 + err = do_pri_inode(-1, inode, -1, NULL);
7439 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7442 + iinfo = au_ii(inode);
7443 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7444 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7445 + if (iinfo->ii_btop < 0)
7448 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7449 + hi = au_hinode(iinfo, bindex);
7451 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7455 +void au_dpri_dalias(struct inode *inode)
7459 + spin_lock(&inode->i_lock);
7460 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7461 + au_dpri_dentry(d);
7462 + spin_unlock(&inode->i_lock);
7465 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7467 + struct dentry *wh = NULL;
7469 + struct inode *inode;
7470 + struct au_iinfo *iinfo;
7471 + struct au_hinode *hi;
7473 + if (!dentry || IS_ERR(dentry)) {
7474 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7477 + /* do not call dget_parent() here */
7478 + /* note: access d_xxx without d_lock */
7479 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7480 + bindex, dentry, dentry,
7481 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7482 + au_dcount(dentry), dentry->d_flags,
7483 + d_unhashed(dentry) ? "un" : "");
7486 + if (d_is_positive(dentry))
7487 + inode = d_inode(dentry);
7489 + && au_test_aufs(dentry->d_sb)
7491 + && !au_is_bad_inode(inode)) {
7492 + iinfo = au_ii(inode);
7493 + hi = au_hinode(iinfo, bindex);
7495 + wh = hi->hi_whdentry;
7497 + do_pri_inode(bindex, inode, hn, wh);
7501 +void au_dpri_dentry(struct dentry *dentry)
7503 + struct au_dinfo *dinfo;
7504 + aufs_bindex_t bindex;
7507 + err = do_pri_dentry(-1, dentry);
7508 + if (err || !au_test_aufs(dentry->d_sb))
7511 + dinfo = au_di(dentry);
7514 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7515 + dinfo->di_btop, dinfo->di_bbot,
7516 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7517 + dinfo->di_tmpfile);
7518 + if (dinfo->di_btop < 0)
7520 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7521 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7524 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7528 + if (!file || IS_ERR(file)) {
7529 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7534 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7535 + && au_test_aufs(file->f_path.dentry->d_sb)
7537 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7538 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7539 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7540 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7541 + file->f_version, file->f_pos, a);
7542 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7543 + do_pri_dentry(bindex, file->f_path.dentry);
7547 +void au_dpri_file(struct file *file)
7549 + struct au_finfo *finfo;
7550 + struct au_fidir *fidir;
7551 + struct au_hfile *hfile;
7552 + aufs_bindex_t bindex;
7555 + err = do_pri_file(-1, file);
7557 + || IS_ERR_OR_NULL(file->f_path.dentry)
7558 + || !au_test_aufs(file->f_path.dentry->d_sb))
7561 + finfo = au_fi(file);
7564 + if (finfo->fi_btop < 0)
7566 + fidir = finfo->fi_hdir;
7568 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7570 + for (bindex = finfo->fi_btop;
7571 + bindex >= 0 && bindex <= fidir->fd_bbot;
7573 + hfile = fidir->fd_hfile + bindex;
7574 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7578 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7580 + struct vfsmount *mnt;
7581 + struct super_block *sb;
7583 + if (!br || IS_ERR(br))
7585 + mnt = au_br_mnt(br);
7586 + if (!mnt || IS_ERR(mnt))
7589 + if (!sb || IS_ERR(sb))
7592 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7593 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7595 + bindex, br->br_perm, br->br_id, br->br_wbr,
7596 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7597 + sb->s_flags, sb->s_count,
7598 + atomic_read(&sb->s_active),
7599 + !!au_xino_file(br->br_xino, /*idx*/-1));
7603 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7607 +void au_dpri_sb(struct super_block *sb)
7609 + struct au_sbinfo *sbinfo;
7610 + aufs_bindex_t bindex;
7612 + /* to reduce stack size */
7614 + struct vfsmount mnt;
7615 + struct au_branch fake;
7618 + /* this function can be called from magic sysrq */
7619 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7620 + if (unlikely(!a)) {
7621 + dpri("no memory\n");
7625 + a->mnt.mnt_sb = sb;
7626 + a->fake.br_path.mnt = &a->mnt;
7627 + err = do_pri_br(-1, &a->fake);
7629 + dpri("dev 0x%x\n", sb->s_dev);
7630 + if (err || !au_test_aufs(sb))
7633 + sbinfo = au_sbi(sb);
7636 + dpri("nw %d, gen %u, kobj %d\n",
7637 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7638 + kref_read(&sbinfo->si_kobj.kref));
7639 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7640 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7643 +/* ---------------------------------------------------------------------- */
7645 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7647 + struct inode *h_inode, *inode = d_inode(dentry);
7648 + struct dentry *h_dentry;
7649 + aufs_bindex_t bindex, bbot, bi;
7651 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7654 + bbot = au_dbbot(dentry);
7655 + bi = au_ibbot(inode);
7658 + bindex = au_dbtop(dentry);
7659 + bi = au_ibtop(inode);
7663 + for (; bindex <= bbot; bindex++) {
7664 + h_dentry = au_h_dptr(dentry, bindex);
7667 + h_inode = au_h_iptr(inode, bindex);
7668 + if (unlikely(h_inode != d_inode(h_dentry))) {
7670 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7671 + AuDbgDentry(dentry);
7672 + AuDbgInode(inode);
7674 + if (au_test_fuse(h_inode->i_sb))
7682 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7685 + struct au_dcsub_pages dpages;
7686 + struct au_dpage *dpage;
7687 + struct dentry **dentries;
7689 + err = au_dpages_init(&dpages, GFP_NOFS);
7691 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7693 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7694 + dpage = dpages.dpages + i;
7695 + dentries = dpage->dentries;
7696 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7697 + AuDebugOn(au_digen_test(dentries[j], sigen));
7699 + au_dpages_free(&dpages);
7702 +void au_dbg_verify_kthread(void)
7704 + if (au_wkq_test()) {
7707 + * It may be recursive, but udba=notify between two aufs mounts,
7708 + * where a single ro branch is shared, is not a problem.
7714 +/* ---------------------------------------------------------------------- */
7716 +int __init au_debug_init(void)
7718 + aufs_bindex_t bindex;
7719 + struct au_vdir_destr destr;
7722 + AuDebugOn(bindex >= 0);
7725 + AuDebugOn(destr.len < NAME_MAX);
7727 +#ifdef CONFIG_4KSTACKS
7728 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7733 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7734 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7735 +++ linux/fs/aufs/debug.h 2021-12-03 15:38:59.933313976 +0100
7737 +/* SPDX-License-Identifier: GPL-2.0 */
7739 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7741 + * This program, aufs is free software; you can redistribute it and/or modify
7742 + * it under the terms of the GNU General Public License as published by
7743 + * the Free Software Foundation; either version 2 of the License, or
7744 + * (at your option) any later version.
7746 + * This program is distributed in the hope that it will be useful,
7747 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7748 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7749 + * GNU General Public License for more details.
7751 + * You should have received a copy of the GNU General Public License
7752 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7756 + * debug print functions
7759 +#ifndef __AUFS_DEBUG_H__
7760 +#define __AUFS_DEBUG_H__
7764 +#include <linux/atomic.h>
7765 +#include <linux/module.h>
7766 +#include <linux/kallsyms.h>
7767 +#include <linux/sysrq.h>
7769 +#ifdef CONFIG_AUFS_DEBUG
7770 +#define AuDebugOn(a) BUG_ON(a)
7772 +/* module parameter */
7773 +extern atomic_t aufs_debug;
7774 +static inline void au_debug_on(void)
7776 + atomic_inc(&aufs_debug);
7778 +static inline void au_debug_off(void)
7780 + atomic_dec_if_positive(&aufs_debug);
7783 +static inline int au_debug_test(void)
7785 + return atomic_read(&aufs_debug) > 0;
7788 +#define AuDebugOn(a) do {} while (0)
7789 +AuStubVoid(au_debug_on, void)
7790 +AuStubVoid(au_debug_off, void)
7791 +AuStubInt0(au_debug_test, void)
7792 +#endif /* CONFIG_AUFS_DEBUG */
7794 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7796 +/* ---------------------------------------------------------------------- */
7800 +#define AuDbg(fmt, ...) do { \
7801 + if (au_debug_test()) \
7802 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7804 +#define AuLabel(l) AuDbg(#l "\n")
7805 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7806 +#define AuWarn1(fmt, ...) do { \
7807 + static unsigned char _c; \
7809 + pr_warn(fmt, ##__VA_ARGS__); \
7812 +#define AuErr1(fmt, ...) do { \
7813 + static unsigned char _c; \
7815 + pr_err(fmt, ##__VA_ARGS__); \
7818 +#define AuIOErr1(fmt, ...) do { \
7819 + static unsigned char _c; \
7821 + AuIOErr(fmt, ##__VA_ARGS__); \
7824 +#define AuUnsupportMsg "This operation is not supported." \
7825 + " Please report this application to aufs-users ML."
7826 +#define AuUnsupport(fmt, ...) do { \
7827 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7831 +#define AuTraceErr(e) do { \
7832 + if (unlikely((e) < 0)) \
7833 + AuDbg("err %d\n", (int)(e)); \
7836 +#define AuTraceErrPtr(p) do { \
7838 + AuDbg("err %ld\n", PTR_ERR(p)); \
7841 +/* dirty macros for debug print, use with "%.*s" and caution */
7842 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7844 +/* ---------------------------------------------------------------------- */
7847 +#ifdef CONFIG_AUFS_DEBUG
7848 +extern struct mutex au_dbg_mtx;
7849 +extern char *au_plevel;
7851 +void au_dpri_whlist(struct au_nhash *whlist);
7853 +void au_dpri_vdir(struct au_vdir *vdir);
7855 +void au_dpri_inode(struct inode *inode);
7856 +void au_dpri_dalias(struct inode *inode);
7857 +void au_dpri_dentry(struct dentry *dentry);
7859 +void au_dpri_file(struct file *filp);
7860 +struct super_block;
7861 +void au_dpri_sb(struct super_block *sb);
7863 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7864 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7865 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7866 +void au_dbg_verify_kthread(void);
7868 +int __init au_debug_init(void);
7870 +#define AuDbgWhlist(w) do { \
7871 + mutex_lock(&au_dbg_mtx); \
7873 + au_dpri_whlist(w); \
7874 + mutex_unlock(&au_dbg_mtx); \
7877 +#define AuDbgVdir(v) do { \
7878 + mutex_lock(&au_dbg_mtx); \
7880 + au_dpri_vdir(v); \
7881 + mutex_unlock(&au_dbg_mtx); \
7884 +#define AuDbgInode(i) do { \
7885 + mutex_lock(&au_dbg_mtx); \
7887 + au_dpri_inode(i); \
7888 + mutex_unlock(&au_dbg_mtx); \
7891 +#define AuDbgDAlias(i) do { \
7892 + mutex_lock(&au_dbg_mtx); \
7894 + au_dpri_dalias(i); \
7895 + mutex_unlock(&au_dbg_mtx); \
7898 +#define AuDbgDentry(d) do { \
7899 + mutex_lock(&au_dbg_mtx); \
7901 + au_dpri_dentry(d); \
7902 + mutex_unlock(&au_dbg_mtx); \
7905 +#define AuDbgFile(f) do { \
7906 + mutex_lock(&au_dbg_mtx); \
7908 + au_dpri_file(f); \
7909 + mutex_unlock(&au_dbg_mtx); \
7912 +#define AuDbgSb(sb) do { \
7913 + mutex_lock(&au_dbg_mtx); \
7914 + AuDbg(#sb "\n"); \
7916 + mutex_unlock(&au_dbg_mtx); \
7919 +#define AuDbgSym(addr) do { \
7920 + char sym[KSYM_SYMBOL_LEN]; \
7921 + sprint_symbol(sym, (unsigned long)addr); \
7922 + AuDbg("%s\n", sym); \
7925 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7926 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7927 +AuStubVoid(au_dbg_verify_kthread, void)
7928 +AuStubInt0(__init au_debug_init, void)
7930 +#define AuDbgWhlist(w) do {} while (0)
7931 +#define AuDbgVdir(v) do {} while (0)
7932 +#define AuDbgInode(i) do {} while (0)
7933 +#define AuDbgDAlias(i) do {} while (0)
7934 +#define AuDbgDentry(d) do {} while (0)
7935 +#define AuDbgFile(f) do {} while (0)
7936 +#define AuDbgSb(sb) do {} while (0)
7937 +#define AuDbgSym(addr) do {} while (0)
7938 +#endif /* CONFIG_AUFS_DEBUG */
7940 +/* ---------------------------------------------------------------------- */
7942 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7943 +int __init au_sysrq_init(void);
7944 +void au_sysrq_fin(void);
7946 +#ifdef CONFIG_HW_CONSOLE
7947 +#define au_dbg_blocked() do { \
7949 + handle_sysrq('w'); \
7952 +AuStubVoid(au_dbg_blocked, void)
7956 +AuStubInt0(__init au_sysrq_init, void)
7957 +AuStubVoid(au_sysrq_fin, void)
7958 +AuStubVoid(au_dbg_blocked, void)
7959 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7961 +#endif /* __KERNEL__ */
7962 +#endif /* __AUFS_DEBUG_H__ */
7963 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7964 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7965 +++ linux/fs/aufs/dentry.c 2021-12-03 15:40:58.233313963 +0100
7967 +// SPDX-License-Identifier: GPL-2.0
7969 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7971 + * This program, aufs is free software; you can redistribute it and/or modify
7972 + * it under the terms of the GNU General Public License as published by
7973 + * the Free Software Foundation; either version 2 of the License, or
7974 + * (at your option) any later version.
7976 + * This program is distributed in the hope that it will be useful,
7977 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7978 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7979 + * GNU General Public License for more details.
7981 + * You should have received a copy of the GNU General Public License
7982 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7986 + * lookup and dentry operations
7989 +#include <linux/iversion.h>
7990 +#include <linux/namei.h>
7994 + * returns positive/negative dentry, NULL or an error.
7995 + * NULL means whiteout-ed or not-found.
7997 +static struct dentry*
7998 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7999 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8001 + struct dentry *h_dentry;
8002 + struct inode *h_inode;
8003 + struct au_branch *br;
8004 + struct user_namespace *h_userns;
8005 + struct path h_path;
8006 + int wh_found, opq;
8007 + unsigned char wh_able;
8008 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8009 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8013 + br = au_sbr(dentry->d_sb, bindex);
8014 + h_path.dentry = h_parent;
8015 + h_path.mnt = au_br_mnt(br);
8016 + h_userns = au_br_userns(br);
8017 + wh_able = !!au_br_whable(br->br_perm);
8019 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
8021 + h_dentry = ERR_PTR(wh_found);
8024 + if (unlikely(wh_found < 0))
8027 + /* We found a whiteout */
8028 + /* au_set_dbbot(dentry, bindex); */
8029 + au_set_dbwh(dentry, bindex);
8031 + return NULL; /* success */
8035 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8037 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8038 + if (IS_ERR(h_dentry)) {
8039 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8045 + h_inode = d_inode(h_dentry);
8046 + if (d_is_negative(h_dentry)) {
8049 + } else if (wh_found
8050 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8052 + else if (au_ftest_lkup(args->flags, DIRREN)
8054 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8055 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8056 + (unsigned long long)h_inode->i_ino);
8060 + if (au_dbbot(dentry) <= bindex)
8061 + au_set_dbbot(dentry, bindex);
8062 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8063 + au_set_dbtop(dentry, bindex);
8064 + au_set_h_dptr(dentry, bindex, h_dentry);
8066 + if (!d_is_dir(h_dentry)
8068 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8069 + goto out; /* success */
8071 + h_path.dentry = h_dentry;
8072 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8073 + opq = au_diropq_test(h_userns, &h_path);
8074 + inode_unlock_shared(h_inode);
8076 + au_set_dbdiropq(dentry, bindex);
8077 + else if (unlikely(opq < 0)) {
8078 + au_set_h_dptr(dentry, bindex, NULL);
8079 + h_dentry = ERR_PTR(opq);
8090 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8092 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8093 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8099 + * returns the number of lower positive dentries,
8100 + * otherwise an error.
8101 + * can be called at unlinking with @type is zero.
8103 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8104 + unsigned int flags)
8106 + int npositive, err;
8107 + aufs_bindex_t bindex, btail, bdiropq;
8108 + unsigned char isdir, dirperm1, dirren;
8109 + struct au_do_lookup_args args = {
8111 + .name = &dentry->d_name
8113 + struct dentry *parent;
8114 + struct super_block *sb;
8116 + sb = dentry->d_sb;
8117 + err = au_test_shwh(sb, args.name);
8118 + if (unlikely(err))
8121 + err = au_wh_name_alloc(&args.whname, args.name);
8122 + if (unlikely(err))
8125 + isdir = !!d_is_dir(dentry);
8126 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8127 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8129 + au_fset_lkup(args.flags, DIRREN);
8132 + parent = dget_parent(dentry);
8133 + btail = au_dbtaildir(parent);
8134 + for (bindex = btop; bindex <= btail; bindex++) {
8135 + struct dentry *h_parent, *h_dentry;
8136 + struct inode *h_inode, *h_dir;
8137 + struct au_branch *br;
8139 + h_dentry = au_h_dptr(dentry, bindex);
8141 + if (d_is_positive(h_dentry))
8145 + h_parent = au_h_dptr(parent, bindex);
8146 + if (!h_parent || !d_is_dir(h_parent))
8150 + /* if the inum matches, then use the prepared name */
8151 + err = au_dr_lkup_name(&args, bindex);
8152 + if (unlikely(err))
8156 + h_dir = d_inode(h_parent);
8157 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8158 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8159 + inode_unlock_shared(h_dir);
8160 + err = PTR_ERR(h_dentry);
8161 + if (IS_ERR(h_dentry))
8164 + au_fclr_lkup(args.flags, ALLOW_NEG);
8166 + au_fset_lkup(args.flags, IGNORE_PERM);
8168 + if (au_dbwh(dentry) == bindex)
8172 + if (d_is_negative(h_dentry))
8174 + h_inode = d_inode(h_dentry);
8177 + args.type = h_inode->i_mode & S_IFMT;
8178 + if (args.type != S_IFDIR)
8181 + /* the type of lower may be different */
8182 + bdiropq = au_dbdiropq(dentry);
8183 + if (bdiropq >= 0 && bdiropq <= bindex)
8186 + br = au_sbr(sb, bindex);
8188 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8189 + /*add_ent*/NULL)) {
8190 + /* prepare next name to lookup */
8191 + err = au_dr_lkup(&args, dentry, bindex);
8192 + if (unlikely(err))
8198 + AuLabel(positive);
8199 + au_update_dbtop(dentry);
8202 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8203 + && au_dbtop(dentry) < 0)) {
8205 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8211 + au_kfree_try_rcu(args.whname.name);
8213 + au_dr_lkup_fin(&args);
8218 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8219 + struct path *ppath)
8221 + struct dentry *dentry;
8224 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8225 + dentry = vfsub_lkup_one(name, ppath);
8227 + struct vfsub_lkup_one_args args = {
8233 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8234 + if (unlikely(wkq_err))
8235 + dentry = ERR_PTR(wkq_err);
8242 + * lookup @dentry on @bindex which should be negative.
8244 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8247 + struct dentry *parent, *h_dentry;
8248 + struct au_branch *br;
8249 + struct user_namespace *h_userns;
8250 + struct path h_ppath;
8252 + parent = dget_parent(dentry);
8253 + br = au_sbr(dentry->d_sb, bindex);
8254 + h_ppath.dentry = au_h_dptr(parent, bindex);
8255 + h_ppath.mnt = au_br_mnt(br);
8256 + h_userns = au_br_userns(br);
8258 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8260 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8261 + err = PTR_ERR(h_dentry);
8262 + if (IS_ERR(h_dentry))
8264 + if (unlikely(d_is_positive(h_dentry))) {
8266 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8272 + if (bindex < au_dbtop(dentry))
8273 + au_set_dbtop(dentry, bindex);
8274 + if (au_dbbot(dentry) < bindex)
8275 + au_set_dbbot(dentry, bindex);
8276 + au_set_h_dptr(dentry, bindex, h_dentry);
8283 +/* ---------------------------------------------------------------------- */
8285 +/* subset of struct inode */
8287 + unsigned long i_ino;
8288 + /* unsigned int i_nlink; */
8294 + blkcnt_t i_blocks;
8299 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8301 + ia->i_ino = h_inode->i_ino;
8302 + /* ia->i_nlink = h_inode->i_nlink; */
8303 + ia->i_uid = h_inode->i_uid;
8304 + ia->i_gid = h_inode->i_gid;
8305 + ia->i_version = inode_query_iversion(h_inode);
8307 + ia->i_size = h_inode->i_size;
8308 + ia->i_blocks = h_inode->i_blocks;
8310 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8313 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8315 + return ia->i_ino != h_inode->i_ino
8316 + /* || ia->i_nlink != h_inode->i_nlink */
8317 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8318 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8319 + || !inode_eq_iversion(h_inode, ia->i_version)
8321 + || ia->i_size != h_inode->i_size
8322 + || ia->i_blocks != h_inode->i_blocks
8324 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8327 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8328 + struct au_branch *br)
8331 + struct au_iattr ia;
8332 + struct inode *h_inode;
8333 + struct dentry *h_d;
8334 + struct super_block *h_sb;
8335 + struct path h_ppath;
8338 + memset(&ia, -1, sizeof(ia));
8339 + h_sb = h_dentry->d_sb;
8341 + if (d_is_positive(h_dentry)) {
8342 + h_inode = d_inode(h_dentry);
8343 + au_iattr_save(&ia, h_inode);
8344 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8345 + /* nfs d_revalidate may return 0 for negative dentry */
8346 + /* fuse d_revalidate always return 0 for negative dentry */
8349 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8350 + h_ppath.dentry = h_parent;
8351 + h_ppath.mnt = au_br_mnt(br);
8352 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8353 + err = PTR_ERR(h_d);
8358 + if (unlikely(h_d != h_dentry
8359 + || d_inode(h_d) != h_inode
8360 + || (h_inode && au_iattr_test(&ia, h_inode))))
8361 + err = au_busy_or_stale();
8369 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8370 + struct dentry *h_parent, struct au_branch *br)
8375 + if (udba == AuOpt_UDBA_REVAL
8376 + && !au_test_fs_remote(h_dentry->d_sb)) {
8378 + err = (d_inode(h_dentry->d_parent) != h_dir);
8379 + } else if (udba != AuOpt_UDBA_NONE)
8380 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8385 +/* ---------------------------------------------------------------------- */
8387 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8390 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8391 + struct au_hdentry tmp, *p, *q;
8392 + struct au_dinfo *dinfo;
8393 + struct super_block *sb;
8395 + DiMustWriteLock(dentry);
8397 + sb = dentry->d_sb;
8398 + dinfo = au_di(dentry);
8399 + bbot = dinfo->di_bbot;
8400 + bwh = dinfo->di_bwh;
8401 + bdiropq = dinfo->di_bdiropq;
8402 + bindex = dinfo->di_btop;
8403 + p = au_hdentry(dinfo, bindex);
8404 + for (; bindex <= bbot; bindex++, p++) {
8405 + if (!p->hd_dentry)
8408 + new_bindex = au_br_index(sb, p->hd_id);
8409 + if (new_bindex == bindex)
8412 + if (dinfo->di_bwh == bindex)
8414 + if (dinfo->di_bdiropq == bindex)
8415 + bdiropq = new_bindex;
8416 + if (new_bindex < 0) {
8418 + p->hd_dentry = NULL;
8422 + /* swap two lower dentries, and loop again */
8423 + q = au_hdentry(dinfo, new_bindex);
8427 + if (tmp.hd_dentry) {
8433 + dinfo->di_bwh = -1;
8434 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8435 + dinfo->di_bwh = bwh;
8437 + dinfo->di_bdiropq = -1;
8439 + && bdiropq <= au_sbbot(sb)
8440 + && au_sbr_whable(sb, bdiropq))
8441 + dinfo->di_bdiropq = bdiropq;
8444 + dinfo->di_btop = -1;
8445 + dinfo->di_bbot = -1;
8446 + bbot = au_dbbot(parent);
8448 + p = au_hdentry(dinfo, bindex);
8449 + for (; bindex <= bbot; bindex++, p++)
8450 + if (p->hd_dentry) {
8451 + dinfo->di_btop = bindex;
8455 + if (dinfo->di_btop >= 0) {
8457 + p = au_hdentry(dinfo, bindex);
8458 + for (; bindex >= 0; bindex--, p--)
8459 + if (p->hd_dentry) {
8460 + dinfo->di_bbot = bindex;
8469 +static void au_do_hide(struct dentry *dentry)
8471 + struct inode *inode;
8473 + if (d_really_is_positive(dentry)) {
8474 + inode = d_inode(dentry);
8475 + if (!d_is_dir(dentry)) {
8476 + if (inode->i_nlink && !d_unhashed(dentry))
8477 + drop_nlink(inode);
8479 + clear_nlink(inode);
8480 + /* stop next lookup */
8481 + inode->i_flags |= S_DEAD;
8483 + smp_mb(); /* necessary? */
8488 +static int au_hide_children(struct dentry *parent)
8490 + int err, i, j, ndentry;
8491 + struct au_dcsub_pages dpages;
8492 + struct au_dpage *dpage;
8493 + struct dentry *dentry;
8495 + err = au_dpages_init(&dpages, GFP_NOFS);
8496 + if (unlikely(err))
8498 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8499 + if (unlikely(err))
8502 + /* in reverse order */
8503 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8504 + dpage = dpages.dpages + i;
8505 + ndentry = dpage->ndentry;
8506 + for (j = ndentry - 1; j >= 0; j--) {
8507 + dentry = dpage->dentries[j];
8508 + if (dentry != parent)
8509 + au_do_hide(dentry);
8514 + au_dpages_free(&dpages);
8519 +static void au_hide(struct dentry *dentry)
8523 + AuDbgDentry(dentry);
8524 + if (d_is_dir(dentry)) {
8525 + /* shrink_dcache_parent(dentry); */
8526 + err = au_hide_children(dentry);
8527 + if (unlikely(err))
8528 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8531 + au_do_hide(dentry);
8535 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8537 + * a dirty branch is added
8538 + * - on the top of layers
8539 + * - in the middle of layers
8540 + * - to the bottom of layers
8542 + * on the added branch there exists
8545 + * - a same named entry
8547 + * * negative --> positive
8548 + * * positive --> positive
8549 + * - type is unchanged
8550 + * - type is changed
8552 + * * negative --> negative
8553 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8556 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8557 + struct au_dinfo *tmp)
8560 + aufs_bindex_t bindex, bbot;
8562 + struct dentry *dentry;
8563 + struct inode *inode;
8565 + } orig_h, tmp_h = {
8568 + struct au_hdentry *hd;
8569 + struct inode *inode, *h_inode;
8570 + struct dentry *h_dentry;
8573 + AuDebugOn(dinfo->di_btop < 0);
8575 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8576 + orig_h.inode = NULL;
8577 + if (d_is_positive(orig_h.dentry)) {
8578 + orig_h.inode = d_inode(orig_h.dentry);
8579 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8581 + if (tmp->di_btop >= 0) {
8582 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8583 + if (d_is_positive(tmp_h.dentry)) {
8584 + tmp_h.inode = d_inode(tmp_h.dentry);
8585 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8590 + if (d_really_is_positive(dentry))
8591 + inode = d_inode(dentry);
8592 + if (!orig_h.inode) {
8593 + AuDbg("negative originally\n");
8599 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8600 + AuDebugOn(dinfo->di_bdiropq != -1);
8602 + if (!tmp_h.inode) {
8603 + AuDbg("negative --> negative\n");
8604 + /* should have only one negative lower */
8605 + if (tmp->di_btop >= 0
8606 + && tmp->di_btop < dinfo->di_btop) {
8607 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8608 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8609 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8610 + au_di_cp(dinfo, tmp);
8611 + hd = au_hdentry(tmp, tmp->di_btop);
8612 + au_set_h_dptr(dentry, tmp->di_btop,
8613 + dget(hd->hd_dentry));
8615 + au_dbg_verify_dinode(dentry);
8617 + AuDbg("negative --> positive\n");
8619 + * similar to the behaviour of creating with bypassing
8621 + * unhash it in order to force an error in the
8622 + * succeeding create operation.
8623 + * we should not set S_DEAD here.
8626 + /* au_di_swap(tmp, dinfo); */
8627 + au_dbg_verify_dinode(dentry);
8630 + AuDbg("positive originally\n");
8631 + /* inode may be NULL */
8632 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8633 + if (!tmp_h.inode) {
8634 + AuDbg("positive --> negative\n");
8635 + /* or bypassing aufs */
8637 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8638 + dinfo->di_bwh = tmp->di_bwh;
8640 + err = au_refresh_hinode_self(inode);
8641 + au_dbg_verify_dinode(dentry);
8642 + } else if (orig_h.mode == tmp_h.mode) {
8643 + AuDbg("positive --> positive, same type\n");
8644 + if (!S_ISDIR(orig_h.mode)
8645 + && dinfo->di_btop > tmp->di_btop) {
8647 + * similar to the behaviour of removing and
8652 + err = au_refresh_hinode_self(inode);
8653 + au_dbg_verify_dinode(dentry);
8655 + /* fill empty slots */
8656 + if (dinfo->di_btop > tmp->di_btop)
8657 + dinfo->di_btop = tmp->di_btop;
8658 + if (dinfo->di_bbot < tmp->di_bbot)
8659 + dinfo->di_bbot = tmp->di_bbot;
8660 + dinfo->di_bwh = tmp->di_bwh;
8661 + dinfo->di_bdiropq = tmp->di_bdiropq;
8662 + bbot = dinfo->di_bbot;
8663 + bindex = tmp->di_btop;
8664 + hd = au_hdentry(tmp, bindex);
8665 + for (; bindex <= bbot; bindex++, hd++) {
8666 + if (au_h_dptr(dentry, bindex))
8668 + h_dentry = hd->hd_dentry;
8671 + AuDebugOn(d_is_negative(h_dentry));
8672 + h_inode = d_inode(h_dentry);
8673 + AuDebugOn(orig_h.mode
8674 + != (h_inode->i_mode
8676 + au_set_h_dptr(dentry, bindex,
8680 + err = au_refresh_hinode(inode, dentry);
8681 + au_dbg_verify_dinode(dentry);
8684 + AuDbg("positive --> positive, different type\n");
8685 + /* similar to the behaviour of removing and creating */
8688 + err = au_refresh_hinode_self(inode);
8689 + au_dbg_verify_dinode(dentry);
8697 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8699 + const struct dentry_operations *dop
8700 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8701 + static const unsigned int mask
8702 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8704 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8706 + if (dentry->d_op == dop)
8709 + AuDbg("%pd\n", dentry);
8710 + spin_lock(&dentry->d_lock);
8711 + if (dop == &aufs_dop)
8712 + dentry->d_flags |= mask;
8714 + dentry->d_flags &= ~mask;
8715 + dentry->d_op = dop;
8716 + spin_unlock(&dentry->d_lock);
8719 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8721 + int err, ebrange, nbr;
8722 + unsigned int sigen;
8723 + struct au_dinfo *dinfo, *tmp;
8724 + struct super_block *sb;
8725 + struct inode *inode;
8727 + DiMustWriteLock(dentry);
8728 + AuDebugOn(IS_ROOT(dentry));
8729 + AuDebugOn(d_really_is_negative(parent));
8731 + sb = dentry->d_sb;
8732 + sigen = au_sigen(sb);
8733 + err = au_digen_test(parent, sigen);
8734 + if (unlikely(err))
8737 + nbr = au_sbbot(sb) + 1;
8738 + dinfo = au_di(dentry);
8739 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8740 + if (unlikely(err))
8742 + ebrange = au_dbrange_test(dentry);
8744 + ebrange = au_do_refresh_hdentry(dentry, parent);
8746 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8747 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8748 + if (d_really_is_positive(dentry)) {
8749 + inode = d_inode(dentry);
8750 + err = au_refresh_hinode_self(inode);
8752 + au_dbg_verify_dinode(dentry);
8754 + goto out_dgen; /* success */
8758 + /* temporary dinfo */
8759 + AuDbgDentry(dentry);
8761 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8762 + if (unlikely(!tmp))
8764 + au_di_swap(tmp, dinfo);
8765 + /* returns the number of positive dentries */
8767 + * if current working dir is removed, it returns an error.
8768 + * but the dentry is legal.
8770 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8771 + AuDbgDentry(dentry);
8772 + au_di_swap(tmp, dinfo);
8773 + if (err == -ENOENT)
8776 + /* compare/refresh by dinfo */
8777 + AuDbgDentry(dentry);
8778 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8779 + au_dbg_verify_dinode(dentry);
8782 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8783 + au_rw_write_unlock(&tmp->di_rwsem);
8785 + if (unlikely(err))
8789 + au_update_digen(dentry);
8791 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8792 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8793 + AuDbgDentry(dentry);
8799 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8800 + struct dentry *dentry, aufs_bindex_t bindex)
8805 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8808 + AuDbg("b%d\n", bindex);
8810 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8811 + * due to whiteout and branch permission.
8813 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8814 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8815 + /* it may return tri-state */
8816 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8818 + if (unlikely(valid < 0))
8828 +/* todo: remove this */
8829 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8830 + unsigned int flags, int do_udba, int dirren)
8833 + umode_t mode, h_mode;
8834 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8835 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8836 + struct inode *h_inode, *h_cached_inode;
8837 + struct dentry *h_dentry;
8838 + struct qstr *name, *h_name;
8845 + unhashed = !!d_unhashed(dentry);
8846 + is_root = !!IS_ROOT(dentry);
8847 + name = &dentry->d_name;
8848 + tmpfile = au_di(dentry)->di_tmpfile;
8851 + * Theoretically, REVAL test should be unnecessary in case of
8853 + * But {fs,i}notify doesn't fire some necessary events,
8854 + * IN_ATTRIB for atime/nlink/pageio
8855 + * Let's do REVAL test too.
8857 + if (do_udba && inode) {
8858 + mode = (inode->i_mode & S_IFMT);
8859 + plus = (inode->i_nlink > 0);
8860 + ibs = au_ibtop(inode);
8861 + ibe = au_ibbot(inode);
8864 + btop = au_dbtop(dentry);
8866 + if (inode && S_ISDIR(inode->i_mode))
8867 + btail = au_dbtaildir(dentry);
8868 + for (bindex = btop; bindex <= btail; bindex++) {
8869 + h_dentry = au_h_dptr(dentry, bindex);
8873 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8874 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8875 + spin_lock(&h_dentry->d_lock);
8876 + h_name = &h_dentry->d_name;
8877 + if (unlikely(do_udba
8880 + && (unhashed != !!d_unhashed(h_dentry)
8881 + || (!tmpfile && !dirren
8882 + && !au_qstreq(name, h_name))
8885 + && !(flags & LOOKUP_OPEN)
8886 + && (h_dentry->d_flags
8887 + & DCACHE_NFSFS_RENAMED)))
8891 + h_unhashed = d_unhashed(h_dentry);
8892 + spin_unlock(&h_dentry->d_lock);
8893 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8894 + unhashed, h_unhashed, dentry, h_dentry);
8897 + spin_unlock(&h_dentry->d_lock);
8899 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8900 + if (unlikely(err))
8901 + /* do not goto err, to keep the errno */
8904 + /* todo: plink too? */
8909 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8913 + if (d_is_positive(h_dentry))
8914 + h_inode = d_inode(h_dentry);
8917 + h_cached_inode = h_inode;
8919 + h_mode = (h_inode->i_mode & S_IFMT);
8920 + h_plus = (h_inode->i_nlink > 0);
8922 + if (inode && ibs <= bindex && bindex <= ibe)
8923 + h_cached_inode = au_h_iptr(inode, bindex);
8926 + if (unlikely(plus != h_plus && !tmpfile))
8929 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8931 + && !IS_ROOT(h_dentry)
8932 + && unhashed != d_unhashed(h_dentry)))
8935 + if (unlikely(mode != h_mode
8936 + || h_cached_inode != h_inode))
8949 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8950 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8953 + struct dentry *parent;
8955 + if (!au_digen_test(dentry, sigen))
8958 + parent = dget_parent(dentry);
8959 + di_read_lock_parent(parent, AuLock_IR);
8960 + AuDebugOn(au_digen_test(parent, sigen));
8961 + au_dbg_verify_gen(parent, sigen);
8962 + err = au_refresh_dentry(dentry, parent);
8963 + di_read_unlock(parent, AuLock_IR);
8969 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8972 + struct dentry *d, *parent;
8974 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8975 + return simple_reval_dpath(dentry, sigen);
8977 + /* slow loop, keep it simple and stupid */
8978 + /* cf: au_cpup_dirs() */
8981 + while (au_digen_test(dentry, sigen)) {
8985 + parent = dget_parent(d);
8986 + if (!au_digen_test(parent, sigen))
8992 + di_write_lock_child2(d);
8994 + /* someone might update our dentry while we were sleeping */
8995 + if (au_digen_test(d, sigen)) {
8997 + * todo: consolidate with simple_reval_dpath(),
8998 + * do_refresh() and au_reval_for_attr().
9000 + di_read_lock_parent(parent, AuLock_IR);
9001 + err = au_refresh_dentry(d, parent);
9002 + di_read_unlock(parent, AuLock_IR);
9006 + di_write_unlock(d);
9008 + if (unlikely(err))
9016 + * if valid returns 1, otherwise 0.
9018 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9021 + unsigned int sigen;
9022 + unsigned char do_udba, dirren;
9023 + struct super_block *sb;
9024 + struct inode *inode;
9026 + /* todo: support rcu-walk? */
9027 + if (flags & LOOKUP_RCU)
9031 + if (unlikely(!au_di(dentry)))
9035 + sb = dentry->d_sb;
9038 + * i_mutex of parent dir may be held,
9039 + * but we should not return 'invalid' due to busy.
9041 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9042 + if (unlikely(err)) {
9048 + if (d_really_is_positive(dentry))
9049 + inode = d_inode(dentry);
9050 + if (unlikely(inode && au_is_bad_inode(inode))) {
9055 + if (unlikely(au_dbrange_test(dentry))) {
9061 + sigen = au_sigen(sb);
9062 + if (au_digen_test(dentry, sigen)) {
9063 + AuDebugOn(IS_ROOT(dentry));
9064 + err = au_reval_dpath(dentry, sigen);
9065 + if (unlikely(err)) {
9070 + di_downgrade_lock(dentry, AuLock_IR);
9073 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9075 + && !(inode->i_state && I_LINKABLE)
9076 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9081 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9082 + if (do_udba && inode) {
9083 + aufs_bindex_t btop = au_ibtop(inode);
9084 + struct inode *h_inode;
9087 + h_inode = au_h_iptr(inode, btop);
9088 + if (h_inode && au_test_higen(inode, h_inode)) {
9095 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9096 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9097 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9099 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9105 + di_downgrade_lock(dentry, AuLock_IR);
9107 + aufs_read_unlock(dentry, AuLock_IR);
9112 + AuDbg("%pd invalid, %d\n", dentry, valid);
9118 +static void aufs_d_release(struct dentry *dentry)
9120 + if (au_di(dentry)) {
9121 + au_di_fin(dentry);
9122 + au_hn_di_reinit(dentry);
9126 +const struct dentry_operations aufs_dop = {
9127 + .d_revalidate = aufs_d_revalidate,
9128 + .d_weak_revalidate = aufs_d_revalidate,
9129 + .d_release = aufs_d_release
9132 +/* aufs_dop without d_revalidate */
9133 +const struct dentry_operations aufs_dop_noreval = {
9134 + .d_release = aufs_d_release
9136 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9137 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9138 +++ linux/fs/aufs/dentry.h 2021-12-03 15:40:58.233313963 +0100
9140 +/* SPDX-License-Identifier: GPL-2.0 */
9142 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9144 + * This program, aufs is free software; you can redistribute it and/or modify
9145 + * it under the terms of the GNU General Public License as published by
9146 + * the Free Software Foundation; either version 2 of the License, or
9147 + * (at your option) any later version.
9149 + * This program is distributed in the hope that it will be useful,
9150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9152 + * GNU General Public License for more details.
9154 + * You should have received a copy of the GNU General Public License
9155 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9159 + * lookup and dentry operations
9162 +#ifndef __AUFS_DENTRY_H__
9163 +#define __AUFS_DENTRY_H__
9167 +#include <linux/dcache.h>
9168 +#include "dirren.h"
9171 +struct au_hdentry {
9172 + struct dentry *hd_dentry;
9173 + aufs_bindex_t hd_id;
9177 + atomic_t di_generation;
9179 + struct au_rwsem di_rwsem;
9180 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9181 + unsigned char di_tmpfile; /* to allow the different name */
9182 + struct au_hdentry *di_hdentry;
9183 + struct rcu_head rcu;
9184 +} ____cacheline_aligned_in_smp;
9186 +/* ---------------------------------------------------------------------- */
9188 +/* flags for au_lkup_dentry() */
9189 +#define AuLkup_ALLOW_NEG 1
9190 +#define AuLkup_IGNORE_PERM (1 << 1)
9191 +#define AuLkup_DIRREN (1 << 2)
9192 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9193 +#define au_fset_lkup(flags, name) \
9194 + do { (flags) |= AuLkup_##name; } while (0)
9195 +#define au_fclr_lkup(flags, name) \
9196 + do { (flags) &= ~AuLkup_##name; } while (0)
9198 +#ifndef CONFIG_AUFS_DIRREN
9199 +#undef AuLkup_DIRREN
9200 +#define AuLkup_DIRREN 0
9203 +struct au_do_lookup_args {
9204 + unsigned int flags;
9206 + struct qstr whname, *name;
9207 + struct au_dr_lookup dirren;
9210 +/* ---------------------------------------------------------------------- */
9213 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9215 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9216 + struct path *ppath);
9217 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9218 + struct dentry *h_parent, struct au_branch *br);
9220 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9221 + unsigned int flags);
9222 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9223 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9224 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9225 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9228 +void au_di_init_once(void *_di);
9229 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9230 +void au_di_free(struct au_dinfo *dinfo);
9231 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9232 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9233 +int au_di_init(struct dentry *dentry);
9234 +void au_di_fin(struct dentry *dentry);
9235 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9237 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9238 +void di_read_unlock(struct dentry *d, int flags);
9239 +void di_downgrade_lock(struct dentry *d, int flags);
9240 +void di_write_lock(struct dentry *d, unsigned int lsc);
9241 +void di_write_unlock(struct dentry *d);
9242 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9243 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9244 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9246 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9247 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9248 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9249 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9251 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9252 + struct dentry *h_dentry);
9253 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9254 +int au_dbrange_test(struct dentry *dentry);
9255 +void au_update_digen(struct dentry *dentry);
9256 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9257 +void au_update_dbtop(struct dentry *dentry);
9258 +void au_update_dbbot(struct dentry *dentry);
9259 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9261 +/* ---------------------------------------------------------------------- */
9263 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9265 + return dentry->d_fsdata;
9268 +/* ---------------------------------------------------------------------- */
9270 +/* lock subclass for dinfo */
9272 + AuLsc_DI_CHILD, /* child first */
9273 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9274 + AuLsc_DI_CHILD3, /* copyup dirs */
9278 + AuLsc_DI_TMP /* temp for replacing dinfo */
9282 + * di_read_lock_child, di_write_lock_child,
9283 + * di_read_lock_child2, di_write_lock_child2,
9284 + * di_read_lock_child3, di_write_lock_child3,
9285 + * di_read_lock_parent, di_write_lock_parent,
9286 + * di_read_lock_parent2, di_write_lock_parent2,
9287 + * di_read_lock_parent3, di_write_lock_parent3,
9289 +#define AuReadLockFunc(name, lsc) \
9290 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9291 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9293 +#define AuWriteLockFunc(name, lsc) \
9294 +static inline void di_write_lock_##name(struct dentry *d) \
9295 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9297 +#define AuRWLockFuncs(name, lsc) \
9298 + AuReadLockFunc(name, lsc) \
9299 + AuWriteLockFunc(name, lsc)
9301 +AuRWLockFuncs(child, CHILD);
9302 +AuRWLockFuncs(child2, CHILD2);
9303 +AuRWLockFuncs(child3, CHILD3);
9304 +AuRWLockFuncs(parent, PARENT);
9305 +AuRWLockFuncs(parent2, PARENT2);
9306 +AuRWLockFuncs(parent3, PARENT3);
9308 +#undef AuReadLockFunc
9309 +#undef AuWriteLockFunc
9310 +#undef AuRWLockFuncs
9312 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9313 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9314 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9316 +/* ---------------------------------------------------------------------- */
9318 +/* todo: memory barrier? */
9319 +static inline unsigned int au_digen(struct dentry *d)
9321 + return atomic_read(&au_di(d)->di_generation);
9324 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9326 + hdentry->hd_dentry = NULL;
9329 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9330 + aufs_bindex_t bindex)
9332 + return di->di_hdentry + bindex;
9335 +static inline void au_hdput(struct au_hdentry *hd)
9338 + dput(hd->hd_dentry);
9341 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9343 + DiMustAnyLock(dentry);
9344 + return au_di(dentry)->di_btop;
9347 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9349 + DiMustAnyLock(dentry);
9350 + return au_di(dentry)->di_bbot;
9353 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9355 + DiMustAnyLock(dentry);
9356 + return au_di(dentry)->di_bwh;
9359 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9361 + DiMustAnyLock(dentry);
9362 + return au_di(dentry)->di_bdiropq;
9365 +/* todo: hard/soft set? */
9366 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9368 + DiMustWriteLock(dentry);
9369 + au_di(dentry)->di_btop = bindex;
9372 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9374 + DiMustWriteLock(dentry);
9375 + au_di(dentry)->di_bbot = bindex;
9378 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9380 + DiMustWriteLock(dentry);
9381 + /* dbwh can be outside of btop - bbot range */
9382 + au_di(dentry)->di_bwh = bindex;
9385 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9387 + DiMustWriteLock(dentry);
9388 + au_di(dentry)->di_bdiropq = bindex;
9391 +/* ---------------------------------------------------------------------- */
9393 +#ifdef CONFIG_AUFS_HNOTIFY
9394 +static inline void au_digen_dec(struct dentry *d)
9396 + atomic_dec(&au_di(d)->di_generation);
9399 +static inline void au_hn_di_reinit(struct dentry *dentry)
9401 + dentry->d_fsdata = NULL;
9404 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9405 +#endif /* CONFIG_AUFS_HNOTIFY */
9407 +#endif /* __KERNEL__ */
9408 +#endif /* __AUFS_DENTRY_H__ */
9409 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9410 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9411 +++ linux/fs/aufs/dinfo.c 2021-12-03 15:38:59.933313976 +0100
9413 +// SPDX-License-Identifier: GPL-2.0
9415 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9417 + * This program, aufs is free software; you can redistribute it and/or modify
9418 + * it under the terms of the GNU General Public License as published by
9419 + * the Free Software Foundation; either version 2 of the License, or
9420 + * (at your option) any later version.
9422 + * This program is distributed in the hope that it will be useful,
9423 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9424 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9425 + * GNU General Public License for more details.
9427 + * You should have received a copy of the GNU General Public License
9428 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9432 + * dentry private data
9437 +void au_di_init_once(void *_dinfo)
9439 + struct au_dinfo *dinfo = _dinfo;
9441 + au_rw_init(&dinfo->di_rwsem);
9444 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9446 + struct au_dinfo *dinfo;
9449 + dinfo = au_cache_alloc_dinfo();
9450 + if (unlikely(!dinfo))
9453 + nbr = au_sbbot(sb) + 1;
9456 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9457 + if (dinfo->di_hdentry) {
9458 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9459 + dinfo->di_btop = -1;
9460 + dinfo->di_bbot = -1;
9461 + dinfo->di_bwh = -1;
9462 + dinfo->di_bdiropq = -1;
9463 + dinfo->di_tmpfile = 0;
9464 + for (i = 0; i < nbr; i++)
9465 + dinfo->di_hdentry[i].hd_id = -1;
9469 + au_cache_free_dinfo(dinfo);
9476 +void au_di_free(struct au_dinfo *dinfo)
9478 + struct au_hdentry *p;
9479 + aufs_bindex_t bbot, bindex;
9481 + /* dentry may not be revalidated */
9482 + bindex = dinfo->di_btop;
9483 + if (bindex >= 0) {
9484 + bbot = dinfo->di_bbot;
9485 + p = au_hdentry(dinfo, bindex);
9486 + while (bindex++ <= bbot)
9489 + au_kfree_try_rcu(dinfo->di_hdentry);
9490 + au_cache_free_dinfo(dinfo);
9493 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9495 + struct au_hdentry *p;
9498 + AuRwMustWriteLock(&a->di_rwsem);
9499 + AuRwMustWriteLock(&b->di_rwsem);
9501 +#define DiSwap(v, name) \
9503 + v = a->di_##name; \
9504 + a->di_##name = b->di_##name; \
9505 + b->di_##name = v; \
9508 + DiSwap(p, hdentry);
9512 + DiSwap(bi, bdiropq);
9518 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9520 + AuRwMustWriteLock(&dst->di_rwsem);
9521 + AuRwMustWriteLock(&src->di_rwsem);
9523 + dst->di_btop = src->di_btop;
9524 + dst->di_bbot = src->di_bbot;
9525 + dst->di_bwh = src->di_bwh;
9526 + dst->di_bdiropq = src->di_bdiropq;
9530 +int au_di_init(struct dentry *dentry)
9533 + struct super_block *sb;
9534 + struct au_dinfo *dinfo;
9537 + sb = dentry->d_sb;
9538 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9540 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9541 + /* smp_mb(); */ /* atomic_set */
9542 + dentry->d_fsdata = dinfo;
9549 +void au_di_fin(struct dentry *dentry)
9551 + struct au_dinfo *dinfo;
9553 + dinfo = au_di(dentry);
9554 + AuRwDestroy(&dinfo->di_rwsem);
9555 + au_di_free(dinfo);
9558 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9561 + struct au_hdentry *hdp;
9563 + AuRwMustWriteLock(&dinfo->di_rwsem);
9566 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9568 + sz = sizeof(*hdp);
9569 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9572 + dinfo->di_hdentry = hdp;
9579 +/* ---------------------------------------------------------------------- */
9581 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9584 + case AuLsc_DI_CHILD:
9585 + ii_write_lock_child(inode);
9587 + case AuLsc_DI_CHILD2:
9588 + ii_write_lock_child2(inode);
9590 + case AuLsc_DI_CHILD3:
9591 + ii_write_lock_child3(inode);
9593 + case AuLsc_DI_PARENT:
9594 + ii_write_lock_parent(inode);
9596 + case AuLsc_DI_PARENT2:
9597 + ii_write_lock_parent2(inode);
9599 + case AuLsc_DI_PARENT3:
9600 + ii_write_lock_parent3(inode);
9607 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9610 + case AuLsc_DI_CHILD:
9611 + ii_read_lock_child(inode);
9613 + case AuLsc_DI_CHILD2:
9614 + ii_read_lock_child2(inode);
9616 + case AuLsc_DI_CHILD3:
9617 + ii_read_lock_child3(inode);
9619 + case AuLsc_DI_PARENT:
9620 + ii_read_lock_parent(inode);
9622 + case AuLsc_DI_PARENT2:
9623 + ii_read_lock_parent2(inode);
9625 + case AuLsc_DI_PARENT3:
9626 + ii_read_lock_parent3(inode);
9633 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9635 + struct inode *inode;
9637 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9638 + if (d_really_is_positive(d)) {
9639 + inode = d_inode(d);
9640 + if (au_ftest_lock(flags, IW))
9641 + do_ii_write_lock(inode, lsc);
9642 + else if (au_ftest_lock(flags, IR))
9643 + do_ii_read_lock(inode, lsc);
9647 +void di_read_unlock(struct dentry *d, int flags)
9649 + struct inode *inode;
9651 + if (d_really_is_positive(d)) {
9652 + inode = d_inode(d);
9653 + if (au_ftest_lock(flags, IW)) {
9654 + au_dbg_verify_dinode(d);
9655 + ii_write_unlock(inode);
9656 + } else if (au_ftest_lock(flags, IR)) {
9657 + au_dbg_verify_dinode(d);
9658 + ii_read_unlock(inode);
9661 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9664 +void di_downgrade_lock(struct dentry *d, int flags)
9666 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9667 + ii_downgrade_lock(d_inode(d));
9668 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9671 +void di_write_lock(struct dentry *d, unsigned int lsc)
9673 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9674 + if (d_really_is_positive(d))
9675 + do_ii_write_lock(d_inode(d), lsc);
9678 +void di_write_unlock(struct dentry *d)
9680 + au_dbg_verify_dinode(d);
9681 + if (d_really_is_positive(d))
9682 + ii_write_unlock(d_inode(d));
9683 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9686 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9688 + AuDebugOn(d1 == d2
9689 + || d_inode(d1) == d_inode(d2)
9690 + || d1->d_sb != d2->d_sb);
9692 + if ((isdir && au_test_subdir(d1, d2))
9694 + di_write_lock_child(d1);
9695 + di_write_lock_child2(d2);
9697 + di_write_lock_child(d2);
9698 + di_write_lock_child2(d1);
9702 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9704 + AuDebugOn(d1 == d2
9705 + || d_inode(d1) == d_inode(d2)
9706 + || d1->d_sb != d2->d_sb);
9708 + if ((isdir && au_test_subdir(d1, d2))
9710 + di_write_lock_parent(d1);
9711 + di_write_lock_parent2(d2);
9713 + di_write_lock_parent(d2);
9714 + di_write_lock_parent2(d1);
9718 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9720 + di_write_unlock(d1);
9721 + if (d_inode(d1) == d_inode(d2))
9722 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9724 + di_write_unlock(d2);
9727 +/* ---------------------------------------------------------------------- */
9729 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9733 + DiMustAnyLock(dentry);
9735 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9737 + AuDebugOn(bindex < 0);
9738 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9739 + AuDebugOn(d && au_dcount(d) <= 0);
9744 + * extended version of au_h_dptr().
9745 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9748 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9750 + struct dentry *h_dentry;
9751 + struct inode *inode, *h_inode;
9753 + AuDebugOn(d_really_is_negative(dentry));
9756 + if (au_dbtop(dentry) <= bindex
9757 + && bindex <= au_dbbot(dentry))
9758 + h_dentry = au_h_dptr(dentry, bindex);
9759 + if (h_dentry && !au_d_linkable(h_dentry)) {
9761 + goto out; /* success */
9764 + inode = d_inode(dentry);
9765 + AuDebugOn(bindex < au_ibtop(inode));
9766 + AuDebugOn(au_ibbot(inode) < bindex);
9767 + h_inode = au_h_iptr(inode, bindex);
9768 + h_dentry = d_find_alias(h_inode);
9770 + if (!IS_ERR(h_dentry)) {
9771 + if (!au_d_linkable(h_dentry))
9772 + goto out; /* success */
9778 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9779 + h_dentry = au_plink_lkup(inode, bindex);
9780 + AuDebugOn(!h_dentry);
9781 + if (!IS_ERR(h_dentry)) {
9782 + if (!au_d_hashed_positive(h_dentry))
9783 + goto out; /* success */
9790 + AuDbgDentry(h_dentry);
9794 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9796 + aufs_bindex_t bbot, bwh;
9798 + bbot = au_dbbot(dentry);
9800 + bwh = au_dbwh(dentry);
9803 + if (0 < bwh && bwh < bbot)
9809 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9811 + aufs_bindex_t bbot, bopq;
9813 + bbot = au_dbtail(dentry);
9815 + bopq = au_dbdiropq(dentry);
9816 + if (0 <= bopq && bopq < bbot)
9822 +/* ---------------------------------------------------------------------- */
9824 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9825 + struct dentry *h_dentry)
9827 + struct au_dinfo *dinfo;
9828 + struct au_hdentry *hd;
9829 + struct au_branch *br;
9831 + DiMustWriteLock(dentry);
9833 + dinfo = au_di(dentry);
9834 + hd = au_hdentry(dinfo, bindex);
9836 + hd->hd_dentry = h_dentry;
9838 + br = au_sbr(dentry->d_sb, bindex);
9839 + hd->hd_id = br->br_id;
9843 +int au_dbrange_test(struct dentry *dentry)
9846 + aufs_bindex_t btop, bbot;
9849 + btop = au_dbtop(dentry);
9850 + bbot = au_dbbot(dentry);
9852 + AuDebugOn(bbot < 0 && btop > bbot);
9855 + AuDebugOn(bbot >= 0);
9861 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9866 + if (unlikely(au_digen(dentry) != sigen
9867 + || au_iigen_test(d_inode(dentry), sigen)))
9873 +void au_update_digen(struct dentry *dentry)
9875 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9876 + /* smp_mb(); */ /* atomic_set */
9879 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9881 + struct au_dinfo *dinfo;
9882 + struct dentry *h_d;
9883 + struct au_hdentry *hdp;
9884 + aufs_bindex_t bindex, bbot;
9886 + DiMustWriteLock(dentry);
9888 + dinfo = au_di(dentry);
9889 + if (!dinfo || dinfo->di_btop < 0)
9892 + if (do_put_zero) {
9893 + bbot = dinfo->di_bbot;
9894 + bindex = dinfo->di_btop;
9895 + hdp = au_hdentry(dinfo, bindex);
9896 + for (; bindex <= bbot; bindex++, hdp++) {
9897 + h_d = hdp->hd_dentry;
9898 + if (h_d && d_is_negative(h_d))
9899 + au_set_h_dptr(dentry, bindex, NULL);
9903 + dinfo->di_btop = 0;
9904 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9905 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9906 + if (hdp->hd_dentry)
9908 + if (dinfo->di_btop > dinfo->di_bbot) {
9909 + dinfo->di_btop = -1;
9910 + dinfo->di_bbot = -1;
9914 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9915 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9916 + if (hdp->hd_dentry)
9918 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9921 +void au_update_dbtop(struct dentry *dentry)
9923 + aufs_bindex_t bindex, bbot;
9924 + struct dentry *h_dentry;
9926 + bbot = au_dbbot(dentry);
9927 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9928 + h_dentry = au_h_dptr(dentry, bindex);
9931 + if (d_is_positive(h_dentry)) {
9932 + au_set_dbtop(dentry, bindex);
9935 + au_set_h_dptr(dentry, bindex, NULL);
9939 +void au_update_dbbot(struct dentry *dentry)
9941 + aufs_bindex_t bindex, btop;
9942 + struct dentry *h_dentry;
9944 + btop = au_dbtop(dentry);
9945 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9946 + h_dentry = au_h_dptr(dentry, bindex);
9949 + if (d_is_positive(h_dentry)) {
9950 + au_set_dbbot(dentry, bindex);
9953 + au_set_h_dptr(dentry, bindex, NULL);
9957 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9959 + aufs_bindex_t bindex, bbot;
9961 + bbot = au_dbbot(dentry);
9962 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9963 + if (au_h_dptr(dentry, bindex) == h_dentry)
9967 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9968 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9969 +++ linux/fs/aufs/dir.c 2021-12-03 15:40:58.233313963 +0100
9971 +// SPDX-License-Identifier: GPL-2.0
9973 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9975 + * This program, aufs is free software; you can redistribute it and/or modify
9976 + * it under the terms of the GNU General Public License as published by
9977 + * the Free Software Foundation; either version 2 of the License, or
9978 + * (at your option) any later version.
9980 + * This program is distributed in the hope that it will be useful,
9981 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9982 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9983 + * GNU General Public License for more details.
9985 + * You should have received a copy of the GNU General Public License
9986 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9990 + * directory operations
9993 +#include <linux/fs_stack.h>
9994 +#include <linux/iversion.h>
9997 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9999 + unsigned int nlink;
10001 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10003 + nlink = dir->i_nlink;
10004 + nlink += h_dir->i_nlink - 2;
10005 + if (h_dir->i_nlink < 2)
10007 + smp_mb(); /* for i_nlink */
10008 + /* 0 can happen in revaliding */
10009 + set_nlink(dir, nlink);
10012 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10014 + unsigned int nlink;
10016 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10018 + nlink = dir->i_nlink;
10019 + nlink -= h_dir->i_nlink - 2;
10020 + if (h_dir->i_nlink < 2)
10022 + smp_mb(); /* for i_nlink */
10023 + /* nlink == 0 means the branch-fs is broken */
10024 + set_nlink(dir, nlink);
10027 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10030 + aufs_bindex_t bindex, bbot;
10031 + struct file *h_file;
10032 + struct dentry *h_dentry;
10036 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10038 + bbot = au_fbbot_dir(file);
10039 + for (bindex = au_fbtop(file);
10040 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10042 + h_file = au_hf_dir(file, bindex);
10043 + if (h_file && file_inode(h_file))
10044 + sz += vfsub_f_size_read(h_file);
10047 + AuDebugOn(!dentry);
10048 + AuDebugOn(!d_is_dir(dentry));
10050 + bbot = au_dbtaildir(dentry);
10051 + for (bindex = au_dbtop(dentry);
10052 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10054 + h_dentry = au_h_dptr(dentry, bindex);
10055 + if (h_dentry && d_is_positive(h_dentry))
10056 + sz += i_size_read(d_inode(h_dentry));
10059 + if (sz < KMALLOC_MAX_SIZE)
10060 + sz = roundup_pow_of_two(sz);
10061 + if (sz > KMALLOC_MAX_SIZE)
10062 + sz = KMALLOC_MAX_SIZE;
10063 + else if (sz < NAME_MAX) {
10064 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10065 + sz = AUFS_RDBLK_DEF;
10070 +struct au_dir_ts_arg {
10071 + struct dentry *dentry;
10072 + aufs_bindex_t brid;
10075 +static void au_do_dir_ts(void *arg)
10077 + struct au_dir_ts_arg *a = arg;
10078 + struct au_dtime dt;
10079 + struct path h_path;
10080 + struct inode *dir, *h_dir;
10081 + struct super_block *sb;
10082 + struct au_branch *br;
10083 + struct au_hinode *hdir;
10085 + aufs_bindex_t btop, bindex;
10087 + sb = a->dentry->d_sb;
10088 + if (d_really_is_negative(a->dentry))
10090 + /* no dir->i_mutex lock */
10091 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10093 + dir = d_inode(a->dentry);
10094 + btop = au_ibtop(dir);
10095 + bindex = au_br_index(sb, a->brid);
10096 + if (bindex < btop)
10099 + br = au_sbr(sb, bindex);
10100 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10101 + if (!h_path.dentry)
10103 + h_path.mnt = au_br_mnt(br);
10104 + au_dtime_store(&dt, a->dentry, &h_path);
10106 + br = au_sbr(sb, btop);
10107 + if (!au_br_writable(br->br_perm))
10109 + h_path.dentry = au_h_dptr(a->dentry, btop);
10110 + h_path.mnt = au_br_mnt(br);
10111 + err = vfsub_mnt_want_write(h_path.mnt);
10114 + hdir = au_hi(dir, btop);
10115 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10116 + h_dir = au_h_iptr(dir, btop);
10117 + if (h_dir->i_nlink
10118 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10119 + dt.dt_h_path = h_path;
10120 + au_dtime_revert(&dt);
10122 + au_hn_inode_unlock(hdir);
10123 + vfsub_mnt_drop_write(h_path.mnt);
10124 + au_cpup_attr_timesizes(dir);
10127 + aufs_read_unlock(a->dentry, AuLock_DW);
10130 + au_nwt_done(&au_sbi(sb)->si_nowait);
10131 + au_kfree_try_rcu(arg);
10134 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10136 + int perm, wkq_err;
10137 + aufs_bindex_t btop;
10138 + struct au_dir_ts_arg *arg;
10139 + struct dentry *dentry;
10140 + struct super_block *sb;
10144 + dentry = d_find_any_alias(dir);
10145 + AuDebugOn(!dentry);
10146 + sb = dentry->d_sb;
10147 + btop = au_ibtop(dir);
10148 + if (btop == bindex) {
10149 + au_cpup_attr_timesizes(dir);
10153 + perm = au_sbr_perm(sb, btop);
10154 + if (!au_br_writable(perm))
10157 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10161 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10162 + arg->brid = au_sbr_id(sb, bindex);
10163 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10164 + if (unlikely(wkq_err)) {
10165 + pr_err("wkq %d\n", wkq_err);
10167 + au_kfree_try_rcu(arg);
10174 +/* ---------------------------------------------------------------------- */
10176 +static int reopen_dir(struct file *file)
10179 + unsigned int flags;
10180 + aufs_bindex_t bindex, btail, btop;
10181 + struct dentry *dentry, *h_dentry;
10182 + struct file *h_file;
10184 + /* open all lower dirs */
10185 + dentry = file->f_path.dentry;
10186 + btop = au_dbtop(dentry);
10187 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10188 + au_set_h_fptr(file, bindex, NULL);
10189 + au_set_fbtop(file, btop);
10191 + btail = au_dbtaildir(dentry);
10192 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10193 + au_set_h_fptr(file, bindex, NULL);
10194 + au_set_fbbot_dir(file, btail);
10196 + flags = vfsub_file_flags(file);
10197 + for (bindex = btop; bindex <= btail; bindex++) {
10198 + h_dentry = au_h_dptr(dentry, bindex);
10201 + h_file = au_hf_dir(file, bindex);
10205 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10206 + err = PTR_ERR(h_file);
10207 + if (IS_ERR(h_file))
10208 + goto out; /* close all? */
10209 + au_set_h_fptr(file, bindex, h_file);
10211 + au_update_figen(file);
10212 + /* todo: necessary? */
10213 + /* file->f_ra = h_file->f_ra; */
10220 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10223 + aufs_bindex_t bindex, btail;
10224 + struct dentry *dentry, *h_dentry;
10225 + struct vfsmount *mnt;
10227 + FiMustWriteLock(file);
10228 + AuDebugOn(h_file);
10231 + mnt = file->f_path.mnt;
10232 + dentry = file->f_path.dentry;
10233 + file->f_version = inode_query_iversion(d_inode(dentry));
10234 + bindex = au_dbtop(dentry);
10235 + au_set_fbtop(file, bindex);
10236 + btail = au_dbtaildir(dentry);
10237 + au_set_fbbot_dir(file, btail);
10238 + for (; !err && bindex <= btail; bindex++) {
10239 + h_dentry = au_h_dptr(dentry, bindex);
10243 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10244 + if (unlikely(err))
10246 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10247 + if (IS_ERR(h_file)) {
10248 + err = PTR_ERR(h_file);
10251 + au_set_h_fptr(file, bindex, h_file);
10253 + au_update_figen(file);
10254 + /* todo: necessary? */
10255 + /* file->f_ra = h_file->f_ra; */
10257 + return 0; /* success */
10260 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10261 + au_set_h_fptr(file, bindex, NULL);
10262 + au_set_fbtop(file, -1);
10263 + au_set_fbbot_dir(file, -1);
10268 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10269 + struct file *file)
10272 + struct super_block *sb;
10273 + struct au_fidir *fidir;
10276 + sb = file->f_path.dentry->d_sb;
10277 + si_read_lock(sb, AuLock_FLUSH);
10278 + fidir = au_fidir_alloc(sb);
10280 + struct au_do_open_args args = {
10281 + .open = do_open_dir,
10284 + err = au_do_open(file, &args);
10285 + if (unlikely(err))
10286 + au_kfree_rcu(fidir);
10288 + si_read_unlock(sb);
10292 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10293 + struct file *file)
10295 + struct au_vdir *vdir_cache;
10296 + struct au_finfo *finfo;
10297 + struct au_fidir *fidir;
10298 + struct au_hfile *hf;
10299 + aufs_bindex_t bindex, bbot;
10301 + finfo = au_fi(file);
10302 + fidir = finfo->fi_hdir;
10304 + au_hbl_del(&finfo->fi_hlist,
10305 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10306 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10308 + au_vdir_free(vdir_cache);
10310 + bindex = finfo->fi_btop;
10311 + if (bindex >= 0) {
10312 + hf = fidir->fd_hfile + bindex;
10314 + * calls fput() instead of filp_close(),
10315 + * since no dnotify or lock for the lower file.
10317 + bbot = fidir->fd_bbot;
10318 + for (; bindex <= bbot; bindex++, hf++)
10320 + au_hfput(hf, /*execed*/0);
10322 + au_kfree_rcu(fidir);
10323 + finfo->fi_hdir = NULL;
10325 + au_finfo_fin(file);
10329 +/* ---------------------------------------------------------------------- */
10331 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10334 + aufs_bindex_t bindex, bbot;
10335 + struct file *h_file;
10338 + bbot = au_fbbot_dir(file);
10339 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10340 + h_file = au_hf_dir(file, bindex);
10342 + err = vfsub_flush(h_file, id);
10347 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10349 + return au_do_flush(file, id, au_do_flush_dir);
10352 +/* ---------------------------------------------------------------------- */
10354 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10357 + aufs_bindex_t bbot, bindex;
10358 + struct inode *inode;
10359 + struct super_block *sb;
10362 + sb = dentry->d_sb;
10363 + inode = d_inode(dentry);
10364 + IMustLock(inode);
10365 + bbot = au_dbbot(dentry);
10366 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10367 + struct path h_path;
10369 + if (au_test_ro(sb, bindex, inode))
10371 + h_path.dentry = au_h_dptr(dentry, bindex);
10372 + if (!h_path.dentry)
10375 + h_path.mnt = au_sbr_mnt(sb, bindex);
10376 + err = vfsub_fsync(NULL, &h_path, datasync);
10382 +static int au_do_fsync_dir(struct file *file, int datasync)
10385 + aufs_bindex_t bbot, bindex;
10386 + struct file *h_file;
10387 + struct super_block *sb;
10388 + struct inode *inode;
10390 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10391 + if (unlikely(err))
10394 + inode = file_inode(file);
10395 + sb = inode->i_sb;
10396 + bbot = au_fbbot_dir(file);
10397 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10398 + h_file = au_hf_dir(file, bindex);
10399 + if (!h_file || au_test_ro(sb, bindex, inode))
10402 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10410 + * @file may be NULL
10412 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10416 + struct dentry *dentry;
10417 + struct inode *inode;
10418 + struct super_block *sb;
10421 + dentry = file->f_path.dentry;
10422 + inode = d_inode(dentry);
10423 + inode_lock(inode);
10424 + sb = dentry->d_sb;
10425 + si_noflush_read_lock(sb);
10427 + err = au_do_fsync_dir(file, datasync);
10429 + di_write_lock_child(dentry);
10430 + err = au_do_fsync_dir_no_file(dentry, datasync);
10432 + au_cpup_attr_timesizes(inode);
10433 + di_write_unlock(dentry);
10435 + fi_write_unlock(file);
10437 + si_read_unlock(sb);
10438 + inode_unlock(inode);
10442 +/* ---------------------------------------------------------------------- */
10444 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10447 + struct dentry *dentry;
10448 + struct inode *inode, *h_inode;
10449 + struct super_block *sb;
10451 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10453 + dentry = file->f_path.dentry;
10454 + inode = d_inode(dentry);
10455 + IMustLock(inode);
10457 + sb = dentry->d_sb;
10458 + si_read_lock(sb, AuLock_FLUSH);
10459 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10460 + if (unlikely(err))
10462 + err = au_alive_dir(dentry);
10464 + err = au_vdir_init(file);
10465 + di_downgrade_lock(dentry, AuLock_IR);
10466 + if (unlikely(err))
10469 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10470 + if (!au_test_nfsd()) {
10471 + err = au_vdir_fill_de(file, ctx);
10472 + fsstack_copy_attr_atime(inode, h_inode);
10475 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10476 + * encode_fh() and others.
10478 + atomic_inc(&h_inode->i_count);
10479 + di_read_unlock(dentry, AuLock_IR);
10480 + si_read_unlock(sb);
10481 + err = au_vdir_fill_de(file, ctx);
10482 + fsstack_copy_attr_atime(inode, h_inode);
10483 + fi_write_unlock(file);
10491 + di_read_unlock(dentry, AuLock_IR);
10492 + fi_write_unlock(file);
10494 + si_read_unlock(sb);
10498 +/* ---------------------------------------------------------------------- */
10500 +#define AuTestEmpty_WHONLY 1
10501 +#define AuTestEmpty_CALLED (1 << 1)
10502 +#define AuTestEmpty_SHWH (1 << 2)
10503 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10504 +#define au_fset_testempty(flags, name) \
10505 + do { (flags) |= AuTestEmpty_##name; } while (0)
10506 +#define au_fclr_testempty(flags, name) \
10507 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10509 +#ifndef CONFIG_AUFS_SHWH
10510 +#undef AuTestEmpty_SHWH
10511 +#define AuTestEmpty_SHWH 0
10514 +struct test_empty_arg {
10515 + struct dir_context ctx;
10516 + struct au_nhash *whlist;
10517 + unsigned int flags;
10519 + aufs_bindex_t bindex;
10522 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10523 + int namelen, loff_t offset __maybe_unused, u64 ino,
10524 + unsigned int d_type)
10526 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10528 + char *name = (void *)__name;
10531 + au_fset_testempty(arg->flags, CALLED);
10533 + if (name[0] == '.'
10534 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10535 + goto out; /* success */
10537 + if (namelen <= AUFS_WH_PFX_LEN
10538 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10539 + if (au_ftest_testempty(arg->flags, WHONLY)
10540 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10541 + arg->err = -ENOTEMPTY;
10545 + name += AUFS_WH_PFX_LEN;
10546 + namelen -= AUFS_WH_PFX_LEN;
10547 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10548 + arg->err = au_nhash_append_wh
10549 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10550 + au_ftest_testempty(arg->flags, SHWH));
10554 + AuTraceErr(arg->err);
10558 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10561 + struct file *h_file;
10562 + struct au_branch *br;
10564 + h_file = au_h_open(dentry, arg->bindex,
10565 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10566 + /*file*/NULL, /*force_wr*/0);
10567 + err = PTR_ERR(h_file);
10568 + if (IS_ERR(h_file))
10572 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10573 + && !file_inode(h_file)->i_nlink)
10578 + au_fclr_testempty(arg->flags, CALLED);
10580 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10583 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10587 + br = au_sbr(dentry->d_sb, arg->bindex);
10588 + au_lcnt_dec(&br->br_nfiles);
10593 +struct do_test_empty_args {
10595 + struct dentry *dentry;
10596 + struct test_empty_arg *arg;
10599 +static void call_do_test_empty(void *args)
10601 + struct do_test_empty_args *a = args;
10602 + *a->errp = do_test_empty(a->dentry, a->arg);
10605 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10607 + int err, wkq_err;
10608 + struct dentry *h_dentry;
10609 + struct inode *h_inode;
10610 + struct user_namespace *h_userns;
10612 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10613 + h_dentry = au_h_dptr(dentry, arg->bindex);
10614 + h_inode = d_inode(h_dentry);
10615 + /* todo: i_mode changes anytime? */
10616 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10617 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10618 + inode_unlock_shared(h_inode);
10620 + err = do_test_empty(dentry, arg);
10622 + struct do_test_empty_args args = {
10624 + .dentry = dentry,
10627 + unsigned int flags = arg->flags;
10629 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10630 + if (unlikely(wkq_err))
10632 + arg->flags = flags;
10638 +int au_test_empty_lower(struct dentry *dentry)
10641 + unsigned int rdhash;
10642 + aufs_bindex_t bindex, btop, btail;
10643 + struct au_nhash whlist;
10644 + struct test_empty_arg arg = {
10646 + .actor = test_empty_cb
10649 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10651 + SiMustAnyLock(dentry->d_sb);
10653 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10655 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10656 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10657 + if (unlikely(err))
10661 + arg.whlist = &whlist;
10662 + btop = au_dbtop(dentry);
10663 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10664 + au_fset_testempty(arg.flags, SHWH);
10665 + test_empty = do_test_empty;
10666 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10667 + test_empty = sio_test_empty;
10668 + arg.bindex = btop;
10669 + err = test_empty(dentry, &arg);
10670 + if (unlikely(err))
10673 + au_fset_testempty(arg.flags, WHONLY);
10674 + btail = au_dbtaildir(dentry);
10675 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10676 + struct dentry *h_dentry;
10678 + h_dentry = au_h_dptr(dentry, bindex);
10679 + if (h_dentry && d_is_positive(h_dentry)) {
10680 + arg.bindex = bindex;
10681 + err = test_empty(dentry, &arg);
10686 + au_nhash_wh_free(&whlist);
10691 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10694 + struct test_empty_arg arg = {
10696 + .actor = test_empty_cb
10699 + aufs_bindex_t bindex, btail;
10702 + arg.whlist = whlist;
10703 + arg.flags = AuTestEmpty_WHONLY;
10704 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10705 + au_fset_testempty(arg.flags, SHWH);
10706 + btail = au_dbtaildir(dentry);
10707 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10708 + struct dentry *h_dentry;
10710 + h_dentry = au_h_dptr(dentry, bindex);
10711 + if (h_dentry && d_is_positive(h_dentry)) {
10712 + arg.bindex = bindex;
10713 + err = sio_test_empty(dentry, &arg);
10720 +/* ---------------------------------------------------------------------- */
10722 +const struct file_operations aufs_dir_fop = {
10723 + .owner = THIS_MODULE,
10724 + .llseek = default_llseek,
10725 + .read = generic_read_dir,
10726 + .iterate_shared = aufs_iterate_shared,
10727 + .unlocked_ioctl = aufs_ioctl_dir,
10728 +#ifdef CONFIG_COMPAT
10729 + .compat_ioctl = aufs_compat_ioctl_dir,
10731 + .open = aufs_open_dir,
10732 + .release = aufs_release_dir,
10733 + .flush = aufs_flush_dir,
10734 + .fsync = aufs_fsync_dir
10736 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10737 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10738 +++ linux/fs/aufs/dir.h 2021-12-03 15:38:59.933313976 +0100
10740 +/* SPDX-License-Identifier: GPL-2.0 */
10742 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10744 + * This program, aufs is free software; you can redistribute it and/or modify
10745 + * it under the terms of the GNU General Public License as published by
10746 + * the Free Software Foundation; either version 2 of the License, or
10747 + * (at your option) any later version.
10749 + * This program is distributed in the hope that it will be useful,
10750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10752 + * GNU General Public License for more details.
10754 + * You should have received a copy of the GNU General Public License
10755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10759 + * directory operations
10762 +#ifndef __AUFS_DIR_H__
10763 +#define __AUFS_DIR_H__
10767 +#include <linux/fs.h>
10769 +/* ---------------------------------------------------------------------- */
10771 +/* need to be faster and smaller */
10774 + unsigned int nh_num;
10775 + struct hlist_head *nh_head;
10778 +struct au_vdir_destr {
10779 + unsigned char len;
10780 + unsigned char name[];
10783 +struct au_vdir_dehstr {
10784 + struct hlist_node hash;
10785 + struct au_vdir_destr *str;
10786 + struct rcu_head rcu;
10787 +} ____cacheline_aligned_in_smp;
10789 +struct au_vdir_de {
10791 + unsigned char de_type;
10792 + /* caution: packed */
10793 + struct au_vdir_destr de_str;
10796 +struct au_vdir_wh {
10797 + struct hlist_node wh_hash;
10798 +#ifdef CONFIG_AUFS_SHWH
10800 + aufs_bindex_t wh_bindex;
10801 + unsigned char wh_type;
10803 + aufs_bindex_t wh_bindex;
10805 + /* caution: packed */
10806 + struct au_vdir_destr wh_str;
10809 +union au_vdir_deblk_p {
10810 + unsigned char *deblk;
10811 + struct au_vdir_de *de;
10815 + unsigned char **vd_deblk;
10816 + unsigned long vd_nblk;
10818 + unsigned long ul;
10819 + union au_vdir_deblk_p p;
10823 + unsigned int vd_deblk_sz;
10824 + unsigned long vd_jiffy;
10825 + struct rcu_head rcu;
10826 +} ____cacheline_aligned_in_smp;
10828 +/* ---------------------------------------------------------------------- */
10831 +extern const struct file_operations aufs_dir_fop;
10832 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10833 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10834 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10835 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10836 +int au_test_empty_lower(struct dentry *dentry);
10837 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10840 +unsigned int au_rdhash_est(loff_t sz);
10841 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10842 +void au_nhash_wh_free(struct au_nhash *whlist);
10843 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10845 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10846 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10847 + unsigned int d_type, aufs_bindex_t bindex,
10848 + unsigned char shwh);
10849 +void au_vdir_free(struct au_vdir *vdir);
10850 +int au_vdir_init(struct file *file);
10851 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10854 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10856 +#ifdef CONFIG_AUFS_RDU
10858 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10859 +#ifdef CONFIG_COMPAT
10860 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10861 + unsigned long arg);
10864 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10865 + unsigned int cmd, unsigned long arg)
10866 +#ifdef CONFIG_COMPAT
10867 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10868 + unsigned int cmd, unsigned long arg)
10872 +#endif /* __KERNEL__ */
10873 +#endif /* __AUFS_DIR_H__ */
10874 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10875 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10876 +++ linux/fs/aufs/dirren.c 2021-12-03 15:38:59.933313976 +0100
10878 +// SPDX-License-Identifier: GPL-2.0
10880 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10882 + * This program, aufs is free software; you can redistribute it and/or modify
10883 + * it under the terms of the GNU General Public License as published by
10884 + * the Free Software Foundation; either version 2 of the License, or
10885 + * (at your option) any later version.
10887 + * This program is distributed in the hope that it will be useful,
10888 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10889 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10890 + * GNU General Public License for more details.
10892 + * You should have received a copy of the GNU General Public License
10893 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10897 + * special handling in renaming a directory
10898 + * in order to support looking-up the before-renamed name on the lower readonly
10902 +#include <linux/byteorder/generic.h>
10905 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10909 + idx = au_dr_ihash(ent->dr_h_ino);
10910 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10913 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10916 + struct hlist_bl_head *hbl;
10919 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10920 + hbl = dr->dr_h_ino + i;
10921 + hlist_bl_lock(hbl);
10922 + ret &= hlist_bl_empty(hbl);
10923 + hlist_bl_unlock(hbl);
10929 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10931 + struct au_dr_hino *found, *ent;
10932 + struct hlist_bl_head *hbl;
10933 + struct hlist_bl_node *pos;
10937 + idx = au_dr_ihash(ino);
10938 + hbl = dr->dr_h_ino + idx;
10939 + hlist_bl_lock(hbl);
10940 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10941 + if (ent->dr_h_ino == ino) {
10945 + hlist_bl_unlock(hbl);
10950 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10951 + struct au_dr_hino *add_ent)
10954 + struct hlist_bl_head *hbl;
10955 + struct hlist_bl_node *pos;
10956 + struct au_dr_hino *ent;
10959 + idx = au_dr_ihash(ino);
10960 + hbl = dr->dr_h_ino + idx;
10961 +#if 0 /* debug print */
10963 + struct hlist_bl_node *tmp;
10965 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10966 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10969 + hlist_bl_lock(hbl);
10970 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10971 + if (ent->dr_h_ino == ino) {
10975 + if (!found && add_ent)
10976 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10977 + hlist_bl_unlock(hbl);
10979 + if (!found && add_ent)
10980 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10985 +void au_dr_hino_free(struct au_dr_br *dr)
10988 + struct hlist_bl_head *hbl;
10989 + struct hlist_bl_node *pos, *tmp;
10990 + struct au_dr_hino *ent;
10992 + /* SiMustWriteLock(sb); */
10994 + for (i = 0; i < AuDirren_NHASH; i++) {
10995 + hbl = dr->dr_h_ino + i;
10996 + /* no spinlock since sbinfo must be write-locked */
10997 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10998 + au_kfree_rcu(ent);
10999 + INIT_HLIST_BL_HEAD(hbl);
11003 +/* returns the number of inodes or an error */
11004 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11005 + struct file *hinofile)
11009 + loff_t pos, oldsize;
11011 + struct inode *hinoinode;
11012 + struct hlist_bl_head *hbl;
11013 + struct hlist_bl_node *n1, *n2;
11014 + struct au_dr_hino *ent;
11016 + SiMustWriteLock(sb);
11017 + AuDebugOn(!au_br_writable(br->br_perm));
11019 + hinoinode = file_inode(hinofile);
11020 + oldsize = i_size_read(hinoinode);
11024 + hbl = br->br_dirren.dr_h_ino;
11025 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11026 + /* no bit-lock since sbinfo must be write-locked */
11027 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11028 + AuDbg("hi%llu, %pD2\n",
11029 + (unsigned long long)ent->dr_h_ino, hinofile);
11030 + u64 = cpu_to_be64(ent->dr_h_ino);
11031 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11032 + if (ssz == sizeof(u64))
11035 + /* write error */
11036 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11043 + /* regardless the error */
11044 + if (pos < oldsize) {
11045 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11053 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11060 + struct au_dr_hino *ent;
11061 + struct inode *hinoinode;
11062 + struct hlist_bl_head *hbl;
11066 + hbl = dr->dr_h_ino;
11067 + hinoinode = file_inode(hinofile);
11068 + sz = i_size_read(hinoinode);
11069 + AuDebugOn(sz % sizeof(u64));
11070 + n = sz / sizeof(u64);
11072 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11073 + if (unlikely(ssz != sizeof(u64))) {
11074 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11081 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11087 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11088 + AuDbg("hi%llu, %pD2\n",
11089 + (unsigned long long)ent->dr_h_ino, hinofile);
11090 + hidx = au_dr_ihash(ent->dr_h_ino);
11091 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11093 + goto out; /* success */
11096 + au_dr_hino_free(dr);
11103 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11104 + * @path is a switch to distinguish load and store.
11106 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11107 + struct au_branch *br, const struct path *path)
11110 + unsigned char load, suspend;
11111 + struct file *hinofile;
11112 + struct au_hinode *hdir;
11113 + struct inode *dir, *delegated;
11114 + struct path hinopath;
11115 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11116 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11118 + AuDebugOn(bindex < 0 && !br);
11119 + AuDebugOn(bindex >= 0 && br);
11124 + br = au_sbr(sb, bindex);
11127 + path = &br->br_path;
11128 + AuDebugOn(!au_br_writable(br->br_perm));
11129 + if (unlikely(!au_br_writable(br->br_perm)))
11135 + dir = d_inode(sb->s_root);
11136 + hdir = au_hinode(au_ii(dir), bindex);
11137 + dir = hdir->hi_inode;
11138 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11140 + dir = d_inode(path->dentry);
11141 + inode_lock_nested(dir, AuLsc_I_CHILD);
11143 + hinopath.mnt = path->mnt;
11144 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11145 + err = PTR_ERR(hinopath.dentry);
11146 + if (IS_ERR(hinopath.dentry))
11150 + flags = O_RDONLY;
11152 + if (d_is_negative(hinopath.dentry))
11153 + goto out_dput; /* success */
11155 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11156 + if (d_is_positive(hinopath.dentry)) {
11157 + delegated = NULL;
11158 + err = vfsub_unlink(dir, &hinopath, &delegated,
11161 + if (unlikely(err))
11162 + pr_err("ignored err %d, %pd2\n",
11163 + err, hinopath.dentry);
11164 + if (unlikely(err == -EWOULDBLOCK))
11169 + } else if (!d_is_positive(hinopath.dentry)) {
11170 + err = vfsub_create(dir, &hinopath, 0600,
11171 + /*want_excl*/false);
11173 + if (unlikely(err))
11176 + flags = O_WRONLY;
11178 + hinofile = vfsub_dentry_open(&hinopath, flags);
11180 + au_hn_inode_unlock(hdir);
11182 + inode_unlock(dir);
11183 + dput(hinopath.dentry);
11184 + AuTraceErrPtr(hinofile);
11185 + if (IS_ERR(hinofile)) {
11186 + err = PTR_ERR(hinofile);
11191 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11193 + err = au_dr_hino_store(sb, br, hinofile);
11198 + dput(hinopath.dentry);
11201 + au_hn_inode_unlock(hdir);
11203 + inode_unlock(dir);
11209 +/* ---------------------------------------------------------------------- */
11211 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11214 + struct kstatfs kstfs;
11216 + struct dentry *dentry;
11217 + struct super_block *sb;
11219 + err = vfs_statfs((void *)path, &kstfs);
11221 + if (unlikely(err))
11224 + /* todo: support for UUID */
11226 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11227 + brid->type = AuBrid_FSID;
11228 + brid->fsid = kstfs.f_fsid;
11230 + dentry = path->dentry;
11231 + sb = dentry->d_sb;
11234 + brid->type = AuBrid_DEV;
11243 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11244 + const struct path *path)
11247 + struct au_dr_br *dr;
11248 + struct hlist_bl_head *hbl;
11250 + dr = &br->br_dirren;
11251 + hbl = dr->dr_h_ino;
11252 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11253 + INIT_HLIST_BL_HEAD(hbl);
11255 + err = au_dr_brid_init(&dr->dr_brid, path);
11256 + if (unlikely(err))
11259 + if (au_opt_test(au_mntflags(sb), DIRREN))
11260 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11267 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11272 + if (au_br_writable(br->br_perm))
11273 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11275 + au_dr_hino_free(&br->br_dirren);
11280 +/* ---------------------------------------------------------------------- */
11282 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11283 + char *buf, size_t sz)
11286 + unsigned int major, minor;
11290 + err = snprintf(p, sz, "%d_", brid->type);
11291 + AuDebugOn(err > sz);
11294 + switch (brid->type) {
11295 + case AuBrid_Unset:
11297 + case AuBrid_UUID:
11298 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11300 + case AuBrid_FSID:
11301 + err = snprintf(p, sz, "%08x-%08x",
11302 + brid->fsid.val[0], brid->fsid.val[1]);
11305 + major = MAJOR(brid->dev);
11306 + minor = MINOR(brid->dev);
11307 + if (major <= 0xff && minor <= 0xff)
11308 + err = snprintf(p, sz, "%02x%02x", major, minor);
11310 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11313 + AuDebugOn(err > sz);
11316 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11317 + AuDebugOn(err > sz);
11324 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11327 + struct dentry *br_dentry;
11328 + struct inode *br_inode;
11330 + br_dentry = au_br_dentry(br);
11331 + br_inode = d_inode(br_dentry);
11332 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11333 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11334 + AuDebugOn(rlen > len);
11339 +/* ---------------------------------------------------------------------- */
11342 + * from the given @h_dentry, construct drinfo at @*fdata.
11343 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11346 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11347 + struct dentry *h_dentry,
11348 + unsigned char *allocated)
11351 + struct au_drinfo_fdata *f, *p;
11352 + struct au_drinfo *drinfo;
11353 + struct inode *h_inode;
11354 + struct qstr *qname;
11358 + h_inode = d_inode(h_dentry);
11359 + qname = &h_dentry->d_name;
11360 + drinfo = &f->drinfo;
11361 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11362 + drinfo->oldnamelen = qname->len;
11363 + if (*allocated < sizeof(*f) + qname->len) {
11364 + v = roundup_pow_of_two(*allocated + qname->len);
11365 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11366 + if (unlikely(!p)) {
11374 + drinfo = &f->drinfo;
11376 + memcpy(drinfo->oldname, qname->name, qname->len);
11377 + AuDbg("i%llu, %.*s\n",
11378 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11379 + drinfo->oldname);
11386 +/* callers have to free the return value */
11387 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11389 + struct au_drinfo *ret, *drinfo;
11390 + struct au_drinfo_fdata fdata;
11395 + ret = ERR_PTR(-EIO);
11397 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11398 + if (unlikely(ssz != sizeof(fdata))) {
11399 + AuIOErr("ssz %zd, %u, %pD2\n",
11400 + ssz, (unsigned int)sizeof(fdata), file);
11404 + fdata.magic = ntohl((__force __be32)fdata.magic);
11405 + switch (fdata.magic) {
11406 + case AUFS_DRINFO_MAGIC_V1:
11409 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11410 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11414 + drinfo = &fdata.drinfo;
11415 + len = drinfo->oldnamelen;
11417 + AuIOErr("broken drinfo %pD2\n", file);
11422 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11423 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11424 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11425 + (unsigned long long)drinfo->ino,
11426 + (unsigned long long)h_ino, file);
11427 + goto out; /* success */
11430 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11431 + if (unlikely(!ret)) {
11432 + ret = ERR_PTR(-ENOMEM);
11433 + AuTraceErrPtr(ret);
11438 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11439 + if (unlikely(ssz != len)) {
11440 + au_kfree_rcu(ret);
11441 + ret = ERR_PTR(-EIO);
11442 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11446 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11452 +/* ---------------------------------------------------------------------- */
11454 +/* in order to be revertible */
11455 +struct au_drinfo_rev_elm {
11457 + struct dentry *info_dentry;
11458 + struct au_drinfo *info_last;
11461 +struct au_drinfo_rev {
11462 + unsigned char already;
11463 + aufs_bindex_t nelm;
11464 + struct au_drinfo_rev_elm elm[];
11467 +/* todo: isn't it too large? */
11468 +struct au_drinfo_store {
11469 + struct path h_ppath;
11470 + struct dentry *h_dentry;
11471 + struct au_drinfo_fdata *fdata;
11472 + char *infoname; /* inside of whname, just after PFX */
11473 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11474 + aufs_bindex_t btgt, btail;
11475 + unsigned char no_sio,
11476 + allocated, /* current size of *fdata */
11477 + infonamelen, /* room size for p */
11478 + whnamelen, /* length of the generated name */
11479 + renameback; /* renamed back */
11482 +/* on rename(2) error, the caller should revert it using @elm */
11483 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11484 + struct au_drinfo_rev_elm *elm)
11489 + struct path infopath = {
11490 + .mnt = w->h_ppath.mnt
11492 + struct inode *h_dir, *h_inode, *delegated;
11493 + struct file *infofile;
11494 + struct qstr *qname;
11497 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11499 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11501 + AuTraceErrPtr(infopath.dentry);
11502 + if (IS_ERR(infopath.dentry)) {
11503 + err = PTR_ERR(infopath.dentry);
11508 + h_dir = d_inode(w->h_ppath.dentry);
11509 + if (elm && d_is_negative(infopath.dentry)) {
11510 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11512 + if (unlikely(err))
11514 + elm->created = 1;
11515 + elm->info_dentry = dget(infopath.dentry);
11518 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11519 + AuTraceErrPtr(infofile);
11520 + if (IS_ERR(infofile)) {
11521 + err = PTR_ERR(infofile);
11525 + h_inode = d_inode(infopath.dentry);
11526 + if (elm && i_size_read(h_inode)) {
11527 + h_inode = d_inode(w->h_dentry);
11528 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11529 + AuTraceErrPtr(elm->info_last);
11530 + if (IS_ERR(elm->info_last)) {
11531 + err = PTR_ERR(elm->info_last);
11532 + elm->info_last = NULL;
11533 + AuDebugOn(elm->info_dentry);
11538 + if (elm && w->renameback) {
11539 + delegated = NULL;
11540 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11542 + if (unlikely(err == -EWOULDBLOCK))
11548 + qname = &w->h_dentry->d_name;
11549 + len = sizeof(*w->fdata) + qname->len;
11551 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11552 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11553 + if (ssz == len) {
11554 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11555 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11556 + goto out_fput; /* success */
11561 + /* the caller should revert it using @elm */
11567 + dput(infopath.dentry);
11573 +struct au_call_drinfo_do_store_args {
11575 + struct au_drinfo_store *w;
11576 + struct au_drinfo_rev_elm *elm;
11579 +static void au_call_drinfo_do_store(void *args)
11581 + struct au_call_drinfo_do_store_args *a = args;
11583 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11586 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11587 + struct au_drinfo_rev_elm *elm)
11589 + int err, wkq_err;
11592 + err = au_drinfo_do_store(w, elm);
11594 + struct au_call_drinfo_do_store_args a = {
11599 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11600 + if (unlikely(wkq_err))
11608 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11609 + aufs_bindex_t btgt)
11613 + memset(w, 0, sizeof(*w));
11614 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11615 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11616 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11617 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11619 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11622 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11623 + if (unlikely(!w->fdata)) {
11627 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11634 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11636 + au_kfree_rcu(w->fdata);
11639 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11640 + struct au_drinfo_store *w)
11642 + struct au_drinfo_rev_elm *elm;
11643 + struct inode *h_dir, *delegated;
11645 + struct path infopath = {
11646 + .mnt = w->h_ppath.mnt
11649 + h_dir = d_inode(w->h_ppath.dentry);
11650 + IMustLock(h_dir);
11654 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11655 + AuDebugOn(elm->created && elm->info_last);
11656 + if (elm->created) {
11658 + delegated = NULL;
11659 + infopath.dentry = elm->info_dentry;
11660 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11663 + if (unlikely(err == -EWOULDBLOCK))
11665 + dput(elm->info_dentry);
11666 + } else if (elm->info_last) {
11668 + w->fdata->drinfo = *elm->info_last;
11669 + memcpy(w->fdata->drinfo.oldname,
11670 + elm->info_last->oldname,
11671 + elm->info_last->oldnamelen);
11672 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11673 + au_kfree_rcu(elm->info_last);
11675 + if (unlikely(err))
11676 + AuIOErr("%d, %s\n", err, w->whname);
11677 + /* go on even if err */
11681 +/* caller has to call au_dr_rename_fin() later */
11682 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11683 + struct qstr *dst_name, void *_rev)
11685 + int err, sz, nelm;
11686 + aufs_bindex_t bindex, btail;
11687 + struct au_drinfo_store work;
11688 + struct au_drinfo_rev *rev, **p;
11689 + struct au_drinfo_rev_elm *elm;
11690 + struct super_block *sb;
11691 + struct au_branch *br;
11692 + struct au_hinode *hdir;
11694 + err = au_drinfo_store_work_init(&work, btgt);
11696 + if (unlikely(err))
11700 + btail = au_dbtaildir(dentry);
11701 + nelm = btail - btgt;
11702 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11703 + rev = kcalloc(1, sz, GFP_NOFS);
11704 + if (unlikely(!rev)) {
11708 + rev->nelm = nelm;
11714 + sb = dentry->d_sb;
11715 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11716 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11717 + hdir = au_hi(d_inode(dentry), btgt);
11718 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11719 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11720 + work.h_dentry = au_h_dptr(dentry, bindex);
11721 + if (!work.h_dentry)
11724 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11725 + &work.allocated);
11727 + if (unlikely(err))
11730 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11731 + br = au_sbr(sb, bindex);
11732 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11733 + work.whnamelen += au_drinfo_name(br, work.infoname,
11734 + work.infonamelen);
11735 + AuDbg("whname %.*s, i%llu, %.*s\n",
11736 + work.whnamelen, work.whname,
11737 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11738 + work.fdata->drinfo.oldnamelen,
11739 + work.fdata->drinfo.oldname);
11741 + err = au_drinfo_store_sio(&work, elm);
11743 + if (unlikely(err))
11746 + if (unlikely(err)) {
11747 + /* revert all drinfo */
11748 + au_drinfo_store_rev(rev, &work);
11749 + au_kfree_try_rcu(rev);
11752 + au_hn_inode_unlock(hdir);
11755 + au_drinfo_store_work_fin(&work);
11760 +/* ---------------------------------------------------------------------- */
11762 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11763 + struct qstr *dst_name, void *_rev)
11765 + int err, already;
11767 + struct super_block *sb;
11768 + struct au_branch *br;
11769 + struct au_dr_br *dr;
11770 + struct dentry *h_dentry;
11771 + struct inode *h_inode;
11772 + struct au_dr_hino *ent;
11773 + struct au_drinfo_rev *rev, **p;
11775 + AuDbg("bindex %d\n", bindex);
11778 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11779 + if (unlikely(!ent))
11783 + br = au_sbr(sb, bindex);
11784 + dr = &br->br_dirren;
11785 + h_dentry = au_h_dptr(src, bindex);
11786 + h_inode = d_inode(h_dentry);
11787 + ino = h_inode->i_ino;
11788 + ent->dr_h_ino = ino;
11789 + already = au_dr_hino_test_add(dr, ino, ent);
11790 + AuDbg("b%d, hi%llu, already %d\n",
11791 + bindex, (unsigned long long)ino, already);
11793 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11798 + rev->already = already;
11799 + goto out; /* success */
11804 + au_dr_hino_del(dr, ent);
11805 + au_kfree_rcu(ent);
11812 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11814 + struct au_drinfo_rev *rev;
11815 + struct au_drinfo_rev_elm *elm;
11820 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11821 + dput(elm->info_dentry);
11822 + au_kfree_rcu(elm->info_last);
11824 + au_kfree_try_rcu(rev);
11827 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11830 + struct au_drinfo_store work;
11831 + struct au_drinfo_rev *rev = _rev;
11832 + struct super_block *sb;
11833 + struct au_branch *br;
11834 + struct inode *h_inode;
11835 + struct au_dr_br *dr;
11836 + struct au_dr_hino *ent;
11838 + err = au_drinfo_store_work_init(&work, btgt);
11839 + if (unlikely(err))
11843 + br = au_sbr(sb, btgt);
11844 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11845 + work.h_ppath.mnt = au_br_mnt(br);
11846 + au_drinfo_store_rev(rev, &work);
11847 + au_drinfo_store_work_fin(&work);
11848 + if (rev->already)
11851 + dr = &br->br_dirren;
11852 + h_inode = d_inode(work.h_ppath.dentry);
11853 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11855 + au_dr_hino_del(dr, ent);
11856 + au_kfree_rcu(ent);
11859 + au_kfree_try_rcu(rev);
11860 + if (unlikely(err))
11861 + pr_err("failed to remove dirren info\n");
11864 +/* ---------------------------------------------------------------------- */
11866 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11867 + char *whname, int whnamelen,
11868 + struct dentry **info_dentry)
11870 + struct au_drinfo *drinfo;
11872 + struct inode *h_dir;
11873 + struct path infopath;
11876 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11878 + *info_dentry = NULL;
11881 + h_dir = d_inode(h_ppath->dentry);
11882 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11883 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11884 + if (IS_ERR(infopath.dentry)) {
11885 + drinfo = (void *)infopath.dentry;
11889 + if (d_is_negative(infopath.dentry))
11890 + goto out_dput; /* success */
11892 + infopath.mnt = h_ppath->mnt;
11893 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11894 + inode_unlock_shared(h_dir);
11897 + drinfo = (void *)f;
11901 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11902 + if (IS_ERR_OR_NULL(drinfo))
11905 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11906 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11911 + dput(infopath.dentry);
11914 + inode_unlock_shared(h_dir);
11915 + AuTraceErrPtr(drinfo);
11919 +struct au_drinfo_do_load_args {
11920 + struct au_drinfo **drinfop;
11921 + struct path *h_ppath;
11924 + struct dentry **info_dentry;
11927 +static void au_call_drinfo_do_load(void *args)
11929 + struct au_drinfo_do_load_args *a = args;
11931 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11935 +struct au_drinfo_load {
11936 + struct path h_ppath;
11937 + struct qstr *qname;
11938 + unsigned char no_sio;
11940 + aufs_bindex_t ninfo;
11941 + struct au_drinfo **drinfo;
11944 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11945 + struct au_branch *br)
11947 + int err, wkq_err, whnamelen, e;
11948 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11949 + = AUFS_WH_DR_INFO_PFX;
11950 + struct au_drinfo *drinfo;
11951 + struct qstr oldname;
11952 + struct inode *h_dir, *delegated;
11953 + struct dentry *info_dentry;
11954 + struct path infopath;
11956 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11957 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11958 + sizeof(whname) - whnamelen);
11960 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11963 + struct au_drinfo_do_load_args args = {
11964 + .drinfop = &drinfo,
11965 + .h_ppath = &w->h_ppath,
11966 + .whname = whname,
11967 + .whnamelen = whnamelen,
11968 + .info_dentry = &info_dentry
11970 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11971 + if (unlikely(wkq_err))
11972 + drinfo = ERR_PTR(wkq_err);
11974 + err = PTR_ERR(drinfo);
11975 + if (IS_ERR_OR_NULL(drinfo))
11979 + oldname.len = drinfo->oldnamelen;
11980 + oldname.name = drinfo->oldname;
11981 + if (au_qstreq(w->qname, &oldname)) {
11982 + /* the name is renamed back */
11983 + au_kfree_rcu(drinfo);
11986 + infopath.dentry = info_dentry;
11987 + infopath.mnt = w->h_ppath.mnt;
11988 + h_dir = d_inode(w->h_ppath.dentry);
11989 + delegated = NULL;
11990 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11991 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11992 + inode_unlock(h_dir);
11994 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11995 + if (unlikely(e == -EWOULDBLOCK))
11998 + au_kfree_rcu(w->drinfo[bindex]);
11999 + w->drinfo[bindex] = drinfo;
12000 + dput(info_dentry);
12007 +/* ---------------------------------------------------------------------- */
12009 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12011 + struct au_drinfo **p = drinfo;
12014 + au_kfree_rcu(*drinfo++);
12015 + au_kfree_try_rcu(p);
12018 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12019 + aufs_bindex_t btgt)
12022 + struct au_drinfo_load w;
12023 + aufs_bindex_t bindex, bbot;
12024 + struct au_branch *br;
12025 + struct inode *h_dir;
12026 + struct au_dr_hino *ent;
12027 + struct super_block *sb;
12029 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12030 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12031 + AuLNPair(&lkup->whname), btgt);
12033 + sb = dentry->d_sb;
12034 + bbot = au_sbbot(sb);
12035 + w.ninfo = bbot + 1;
12036 + if (!lkup->dirren.drinfo) {
12037 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12038 + sizeof(*lkup->dirren.drinfo),
12040 + if (unlikely(!lkup->dirren.drinfo)) {
12044 + lkup->dirren.ninfo = w.ninfo;
12046 + w.drinfo = lkup->dirren.drinfo;
12047 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12048 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12049 + AuDebugOn(!w.h_ppath.dentry);
12050 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12051 + w.qname = &dentry->d_name;
12054 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12055 + br = au_sbr(sb, bindex);
12056 + err = au_drinfo_load(&w, bindex, br);
12057 + if (unlikely(err))
12059 + if (w.drinfo[bindex])
12063 + br = au_sbr(sb, btgt);
12064 + h_dir = d_inode(w.h_ppath.dentry);
12065 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12067 + au_dr_hino_del(&br->br_dirren, ent);
12068 + au_kfree_rcu(ent);
12070 + goto out; /* success */
12073 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12074 + lkup->dirren.ninfo = 0;
12075 + lkup->dirren.drinfo = NULL;
12081 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12083 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12086 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12089 + struct au_drinfo *drinfo;
12092 + if (!lkup->dirren.drinfo)
12094 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12095 + drinfo = lkup->dirren.drinfo[btgt];
12099 + au_kfree_try_rcu(lkup->whname.name);
12100 + lkup->whname.name = NULL;
12101 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12102 + lkup->dirren.dr_name.name = drinfo->oldname;
12103 + lkup->name = &lkup->dirren.dr_name;
12104 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12106 + AuDbg("name %.*s, whname %.*s, b%d\n",
12107 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12115 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12119 + struct au_drinfo *drinfo;
12122 + if (!lkup->dirren.drinfo)
12124 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12125 + drinfo = lkup->dirren.drinfo[bindex];
12129 + match = (drinfo->ino == h_ino);
12130 + AuDbg("match %d\n", match);
12136 +/* ---------------------------------------------------------------------- */
12138 +int au_dr_opt_set(struct super_block *sb)
12141 + aufs_bindex_t bindex, bbot;
12142 + struct au_branch *br;
12145 + bbot = au_sbbot(sb);
12146 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12147 + br = au_sbr(sb, bindex);
12148 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12154 +int au_dr_opt_flush(struct super_block *sb)
12157 + aufs_bindex_t bindex, bbot;
12158 + struct au_branch *br;
12161 + bbot = au_sbbot(sb);
12162 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12163 + br = au_sbr(sb, bindex);
12164 + if (au_br_writable(br->br_perm))
12165 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12171 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12174 + aufs_bindex_t bindex, bbot;
12175 + struct au_branch *br;
12179 + err = au_dr_opt_flush(sb);
12180 + if (unlikely(err))
12184 + bbot = au_sbbot(sb);
12185 + for (bindex = 0; bindex <= bbot; bindex++) {
12186 + br = au_sbr(sb, bindex);
12187 + au_dr_hino_free(&br->br_dirren);
12193 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12194 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12195 +++ linux/fs/aufs/dirren.h 2021-12-03 15:38:59.933313976 +0100
12197 +/* SPDX-License-Identifier: GPL-2.0 */
12199 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12201 + * This program, aufs is free software; you can redistribute it and/or modify
12202 + * it under the terms of the GNU General Public License as published by
12203 + * the Free Software Foundation; either version 2 of the License, or
12204 + * (at your option) any later version.
12206 + * This program is distributed in the hope that it will be useful,
12207 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12209 + * GNU General Public License for more details.
12211 + * You should have received a copy of the GNU General Public License
12212 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12216 + * renamed dir info
12219 +#ifndef __AUFS_DIRREN_H__
12220 +#define __AUFS_DIRREN_H__
12224 +#include <linux/dcache.h>
12225 +#include <linux/statfs.h>
12226 +#include <linux/uuid.h>
12229 +#define AuDirren_NHASH 100
12231 +#ifdef CONFIG_AUFS_DIRREN
12232 +enum au_brid_type {
12239 +struct au_dr_brid {
12240 + enum au_brid_type type;
12242 + uuid_t uuid; /* unimplemented yet */
12248 +/* 20 is the max digits length of ulong 64 */
12249 +/* brid-type "_" uuid "_" inum */
12250 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12251 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12253 +struct au_dr_hino {
12254 + struct hlist_bl_node dr_hnode;
12259 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12260 + struct au_dr_brid dr_brid;
12263 +struct au_dr_lookup {
12264 + /* dr_name is pointed by struct au_do_lookup_args.name */
12265 + struct qstr dr_name; /* subset of dr_info */
12266 + aufs_bindex_t ninfo;
12267 + struct au_drinfo **drinfo;
12270 +struct au_dr_hino;
12272 +struct au_dr_br { };
12273 +struct au_dr_lookup { };
12276 +/* ---------------------------------------------------------------------- */
12279 +struct au_do_lookup_args;
12281 +#ifdef CONFIG_AUFS_DIRREN
12282 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12283 + struct au_dr_hino *add_ent);
12284 +void au_dr_hino_free(struct au_dr_br *dr);
12285 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12286 + const struct path *path);
12287 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12288 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12289 + struct qstr *dst_name, void *_rev);
12290 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12291 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12292 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12293 + aufs_bindex_t bindex);
12294 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12295 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12297 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12298 +int au_dr_opt_set(struct super_block *sb);
12299 +int au_dr_opt_flush(struct super_block *sb);
12300 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12302 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12303 + struct au_dr_hino *add_ent);
12304 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12305 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12306 + const struct path *path);
12307 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12308 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12309 + struct qstr *dst_name, void *_rev);
12310 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12311 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12313 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12314 + aufs_bindex_t bindex);
12315 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12316 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12317 + aufs_bindex_t bindex, ino_t h_ino);
12318 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12319 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12320 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12321 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12324 +/* ---------------------------------------------------------------------- */
12326 +#ifdef CONFIG_AUFS_DIRREN
12327 +static inline int au_dr_ihash(ino_t h_ino)
12329 + return h_ino % AuDirren_NHASH;
12332 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12335 +#endif /* __KERNEL__ */
12336 +#endif /* __AUFS_DIRREN_H__ */
12337 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12338 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12339 +++ linux/fs/aufs/dynop.c 2021-12-03 15:38:59.933313976 +0100
12341 +// SPDX-License-Identifier: GPL-2.0
12343 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12345 + * This program, aufs is free software; you can redistribute it and/or modify
12346 + * it under the terms of the GNU General Public License as published by
12347 + * the Free Software Foundation; either version 2 of the License, or
12348 + * (at your option) any later version.
12350 + * This program is distributed in the hope that it will be useful,
12351 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12352 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12353 + * GNU General Public License for more details.
12355 + * You should have received a copy of the GNU General Public License
12356 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12360 + * dynamically customizable operations for regular files
12365 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12368 + * How large will these lists be?
12369 + * Usually just a few elements, 20-30 at most for each, I guess.
12371 +static struct hlist_bl_head dynop[AuDyLast];
12373 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12374 + const void *h_op)
12376 + struct au_dykey *key, *tmp;
12377 + struct hlist_bl_node *pos;
12380 + hlist_bl_lock(hbl);
12381 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12382 + if (tmp->dk_op.dy_hop == h_op) {
12383 + if (kref_get_unless_zero(&tmp->dk_kref))
12387 + hlist_bl_unlock(hbl);
12392 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12394 + struct au_dykey **k, *found;
12395 + const void *h_op = key->dk_op.dy_hop;
12399 + k = br->br_dykey;
12400 + for (i = 0; i < AuBrDynOp; i++)
12402 + if (k[i]->dk_op.dy_hop == h_op) {
12409 + spin_lock(&br->br_dykey_lock);
12410 + for (; i < AuBrDynOp; i++)
12412 + if (k[i]->dk_op.dy_hop == h_op) {
12420 + spin_unlock(&br->br_dykey_lock);
12421 + BUG_ON(i == AuBrDynOp); /* expand the array */
12427 +/* kref_get() if @key is already added */
12428 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12430 + struct au_dykey *tmp, *found;
12431 + struct hlist_bl_node *pos;
12432 + const void *h_op = key->dk_op.dy_hop;
12435 + hlist_bl_lock(hbl);
12436 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12437 + if (tmp->dk_op.dy_hop == h_op) {
12438 + if (kref_get_unless_zero(&tmp->dk_kref))
12443 + hlist_bl_add_head(&key->dk_hnode, hbl);
12444 + hlist_bl_unlock(hbl);
12451 +static void dy_free_rcu(struct rcu_head *rcu)
12453 + struct au_dykey *key;
12455 + key = container_of(rcu, struct au_dykey, dk_rcu);
12460 +static void dy_free(struct kref *kref)
12462 + struct au_dykey *key;
12463 + struct hlist_bl_head *hbl;
12465 + key = container_of(kref, struct au_dykey, dk_kref);
12466 + hbl = dynop + key->dk_op.dy_type;
12467 + au_hbl_del(&key->dk_hnode, hbl);
12468 + call_rcu(&key->dk_rcu, dy_free_rcu);
12471 +void au_dy_put(struct au_dykey *key)
12473 + kref_put(&key->dk_kref, dy_free);
12476 +/* ---------------------------------------------------------------------- */
12478 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12480 +#ifdef CONFIG_AUFS_DEBUG
12481 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12482 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12484 +#define DyDbgDeclare(cnt) do {} while (0)
12485 +#define DyDbgInc(cnt) do {} while (0)
12488 +#define DySet(func, dst, src, h_op, h_sb) do { \
12490 + if (h_op->func) { \
12492 + dst.func = src.func; \
12494 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12498 +#define DySetForce(func, dst, src) do { \
12499 + AuDebugOn(!src.func); \
12501 + dst.func = src.func; \
12504 +#define DySetAop(func) \
12505 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12506 +#define DySetAopForce(func) \
12507 + DySetForce(func, dyaop->da_op, aufs_aop)
12509 +static void dy_aop(struct au_dykey *key, const void *h_op,
12510 + struct super_block *h_sb __maybe_unused)
12512 + struct au_dyaop *dyaop = (void *)key;
12513 + const struct address_space_operations *h_aop = h_op;
12514 + DyDbgDeclare(cnt);
12516 + AuDbg("%s\n", au_sbtype(h_sb));
12518 + DySetAop(writepage);
12519 + DySetAopForce(readpage); /* force */
12520 + DySetAop(writepages);
12521 + DySetAop(set_page_dirty);
12522 + DySetAop(readpages);
12523 + DySetAop(readahead);
12524 + DySetAop(write_begin);
12525 + DySetAop(write_end);
12527 + DySetAop(invalidatepage);
12528 + DySetAop(releasepage);
12529 + DySetAop(freepage);
12530 + /* this one will be changed according to an aufs mount option */
12531 + DySetAop(direct_IO);
12532 + DySetAop(migratepage);
12533 + DySetAop(isolate_page);
12534 + DySetAop(putback_page);
12535 + DySetAop(launder_page);
12536 + DySetAop(is_partially_uptodate);
12537 + DySetAop(is_dirty_writeback);
12538 + DySetAop(error_remove_page);
12539 + DySetAop(swap_activate);
12540 + DySetAop(swap_deactivate);
12542 + DyDbgSize(cnt, *h_aop);
12545 +/* ---------------------------------------------------------------------- */
12547 +static void dy_bug(struct kref *kref)
12552 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12554 + struct au_dykey *key, *old;
12555 + struct hlist_bl_head *hbl;
12558 + void (*set)(struct au_dykey *key, const void *h_op,
12559 + struct super_block *h_sb __maybe_unused);
12561 + static const struct op a[] = {
12563 + .sz = sizeof(struct au_dyaop),
12567 + const struct op *p;
12569 + hbl = dynop + op->dy_type;
12570 + key = dy_gfind_get(hbl, op->dy_hop);
12572 + goto out_add; /* success */
12574 + p = a + op->dy_type;
12575 + key = kzalloc(p->sz, GFP_NOFS);
12576 + if (unlikely(!key)) {
12577 + key = ERR_PTR(-ENOMEM);
12581 + key->dk_op.dy_hop = op->dy_hop;
12582 + kref_init(&key->dk_kref);
12583 + p->set(key, op->dy_hop, au_br_sb(br));
12584 + old = dy_gadd(hbl, key);
12586 + au_kfree_rcu(key);
12591 + old = dy_bradd(br, key);
12593 + /* its ref-count should never be zero here */
12594 + kref_put(&key->dk_kref, dy_bug);
12599 +/* ---------------------------------------------------------------------- */
12601 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12602 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12603 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12604 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12605 + * See the aufs manual in detail.
12607 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12610 + dyaop->da_op.direct_IO = NULL;
12612 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12615 +static struct au_dyaop *dy_aget(struct au_branch *br,
12616 + const struct address_space_operations *h_aop,
12619 + struct au_dyaop *dyaop;
12620 + struct au_dynop op;
12622 + op.dy_type = AuDy_AOP;
12623 + op.dy_haop = h_aop;
12624 + dyaop = (void *)dy_get(&op, br);
12625 + if (IS_ERR(dyaop))
12627 + dy_adx(dyaop, do_dx);
12633 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12634 + struct inode *h_inode)
12637 + struct super_block *sb;
12638 + struct au_branch *br;
12639 + struct au_dyaop *dyaop;
12641 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12642 + IiMustWriteLock(inode);
12644 + sb = inode->i_sb;
12645 + br = au_sbr(sb, bindex);
12646 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12647 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12648 + err = PTR_ERR(dyaop);
12649 + if (IS_ERR(dyaop))
12650 + /* unnecessary to call dy_fput() */
12654 + inode->i_mapping->a_ops = &dyaop->da_op;
12661 + * Is it safe to replace a_ops during the inode/file is in operation?
12662 + * Yes, I hope so.
12664 +int au_dy_irefresh(struct inode *inode)
12667 + aufs_bindex_t btop;
12668 + struct inode *h_inode;
12671 + if (S_ISREG(inode->i_mode)) {
12672 + btop = au_ibtop(inode);
12673 + h_inode = au_h_iptr(inode, btop);
12674 + err = au_dy_iaop(inode, btop, h_inode);
12679 +void au_dy_arefresh(int do_dx)
12681 + struct hlist_bl_head *hbl;
12682 + struct hlist_bl_node *pos;
12683 + struct au_dykey *key;
12685 + hbl = dynop + AuDy_AOP;
12686 + hlist_bl_lock(hbl);
12687 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12688 + dy_adx((void *)key, do_dx);
12689 + hlist_bl_unlock(hbl);
12692 +/* ---------------------------------------------------------------------- */
12694 +void __init au_dy_init(void)
12698 + for (i = 0; i < AuDyLast; i++)
12699 + INIT_HLIST_BL_HEAD(dynop + i);
12702 +void au_dy_fin(void)
12706 + for (i = 0; i < AuDyLast; i++)
12707 + WARN_ON(!hlist_bl_empty(dynop + i));
12709 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12710 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12711 +++ linux/fs/aufs/dynop.h 2021-12-03 15:38:59.933313976 +0100
12713 +/* SPDX-License-Identifier: GPL-2.0 */
12715 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12717 + * This program, aufs is free software; you can redistribute it and/or modify
12718 + * it under the terms of the GNU General Public License as published by
12719 + * the Free Software Foundation; either version 2 of the License, or
12720 + * (at your option) any later version.
12722 + * This program is distributed in the hope that it will be useful,
12723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12725 + * GNU General Public License for more details.
12727 + * You should have received a copy of the GNU General Public License
12728 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12732 + * dynamically customizable operations (for regular files only)
12735 +#ifndef __AUFS_DYNOP_H__
12736 +#define __AUFS_DYNOP_H__
12740 +#include <linux/fs.h>
12741 +#include <linux/kref.h>
12743 +enum {AuDy_AOP, AuDyLast};
12748 + const void *dy_hop;
12749 + const struct address_space_operations *dy_haop;
12755 + struct hlist_bl_node dk_hnode;
12756 + struct rcu_head dk_rcu;
12758 + struct au_dynop dk_op;
12761 + * during I am in the branch local array, kref is gotten. when the
12762 + * branch is removed, kref is put.
12764 + struct kref dk_kref;
12767 +/* stop unioning since their sizes are very different from each other */
12769 + struct au_dykey da_key;
12770 + struct address_space_operations da_op; /* not const */
12772 +/* make sure that 'struct au_dykey *' can be any type */
12773 +static_assert(!offsetof(struct au_dyaop, da_key));
12775 +/* ---------------------------------------------------------------------- */
12779 +void au_dy_put(struct au_dykey *key);
12780 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12781 + struct inode *h_inode);
12782 +int au_dy_irefresh(struct inode *inode);
12783 +void au_dy_arefresh(int do_dio);
12785 +void __init au_dy_init(void);
12786 +void au_dy_fin(void);
12788 +#endif /* __KERNEL__ */
12789 +#endif /* __AUFS_DYNOP_H__ */
12790 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12791 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12792 +++ linux/fs/aufs/export.c 2021-12-03 15:40:58.233313963 +0100
12794 +// SPDX-License-Identifier: GPL-2.0
12796 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12798 + * This program, aufs is free software; you can redistribute it and/or modify
12799 + * it under the terms of the GNU General Public License as published by
12800 + * the Free Software Foundation; either version 2 of the License, or
12801 + * (at your option) any later version.
12803 + * This program is distributed in the hope that it will be useful,
12804 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12805 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12806 + * GNU General Public License for more details.
12808 + * You should have received a copy of the GNU General Public License
12809 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12816 +#include <linux/exportfs.h>
12817 +#include <linux/fs_struct.h>
12818 +#include <linux/namei.h>
12819 +#include <linux/nsproxy.h>
12820 +#include <linux/random.h>
12821 +#include <linux/writeback.h>
12825 +#ifdef CONFIG_AUFS_INO_T_64
12833 +static ino_t decode_ino(__u32 *a)
12837 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12839 +#ifdef CONFIG_AUFS_INO_T_64
12845 +static void encode_ino(__u32 *a, ino_t ino)
12851 +#ifdef CONFIG_AUFS_INO_T_64
12856 +/* NFS file handle */
12860 +#ifdef CONFIG_AUFS_INO_T_64
12861 + /* support 64bit inode number */
12874 + Fh_ino = Fh_ino1,
12875 + Fh_dir_ino = Fh_dir_ino1
12878 +static int au_test_anon(struct dentry *dentry)
12880 + /* note: read d_flags without d_lock */
12881 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12884 +int au_test_nfsd(void)
12887 + struct task_struct *tsk = current;
12888 + char comm[sizeof(tsk->comm)];
12891 + if (tsk->flags & PF_KTHREAD) {
12892 + get_task_comm(comm, tsk);
12893 + ret = !strcmp(comm, "nfsd");
12899 +/* ---------------------------------------------------------------------- */
12900 +/* inode generation external table */
12902 +void au_xigen_inc(struct inode *inode)
12907 + struct super_block *sb;
12908 + struct au_sbinfo *sbinfo;
12910 + sb = inode->i_sb;
12911 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12913 + sbinfo = au_sbi(sb);
12914 + pos = inode->i_ino;
12915 + pos *= sizeof(igen);
12916 + igen = inode->i_generation + 1;
12917 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12918 + if (sz == sizeof(igen))
12919 + return; /* success */
12921 + if (unlikely(sz >= 0))
12922 + AuIOErr("xigen error (%zd)\n", sz);
12925 +int au_xigen_new(struct inode *inode)
12930 + struct super_block *sb;
12931 + struct au_sbinfo *sbinfo;
12932 + struct file *file;
12935 + /* todo: dirty, at mount time */
12936 + if (inode->i_ino == AUFS_ROOT_INO)
12938 + sb = inode->i_sb;
12939 + SiMustAnyLock(sb);
12940 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12944 + pos = inode->i_ino;
12945 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12946 + AuIOErr1("too large i%lld\n", pos);
12949 + pos *= sizeof(inode->i_generation);
12952 + sbinfo = au_sbi(sb);
12953 + file = sbinfo->si_xigen;
12956 + if (vfsub_f_size_read(file)
12957 + < pos + sizeof(inode->i_generation)) {
12958 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12959 + sz = xino_fwrite(file, &inode->i_generation,
12960 + sizeof(inode->i_generation), &pos);
12962 + sz = xino_fread(file, &inode->i_generation,
12963 + sizeof(inode->i_generation), &pos);
12964 + if (sz == sizeof(inode->i_generation))
12965 + goto out; /* success */
12968 + if (unlikely(sz >= 0)) {
12970 + AuIOErr("xigen error (%zd)\n", sz);
12977 +int au_xigen_set(struct super_block *sb, struct path *path)
12980 + struct au_sbinfo *sbinfo;
12981 + struct file *file;
12983 + SiMustWriteLock(sb);
12985 + sbinfo = au_sbi(sb);
12986 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12987 + err = PTR_ERR(file);
12988 + if (IS_ERR(file))
12991 + if (sbinfo->si_xigen)
12992 + fput(sbinfo->si_xigen);
12993 + sbinfo->si_xigen = file;
13000 +void au_xigen_clr(struct super_block *sb)
13002 + struct au_sbinfo *sbinfo;
13004 + SiMustWriteLock(sb);
13006 + sbinfo = au_sbi(sb);
13007 + if (sbinfo->si_xigen) {
13008 + fput(sbinfo->si_xigen);
13009 + sbinfo->si_xigen = NULL;
13013 +/* ---------------------------------------------------------------------- */
13015 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13018 + struct dentry *dentry, *d;
13019 + struct inode *inode;
13020 + unsigned int sigen;
13023 + inode = ilookup(sb, ino);
13027 + dentry = ERR_PTR(-ESTALE);
13028 + sigen = au_sigen(sb);
13029 + if (unlikely(au_is_bad_inode(inode)
13030 + || IS_DEADDIR(inode)
13031 + || sigen != au_iigen(inode, NULL)))
13035 + if (!dir_ino || S_ISDIR(inode->i_mode))
13036 + dentry = d_find_alias(inode);
13038 + spin_lock(&inode->i_lock);
13039 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13040 + spin_lock(&d->d_lock);
13041 + if (!au_test_anon(d)
13042 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13043 + dentry = dget_dlock(d);
13044 + spin_unlock(&d->d_lock);
13047 + spin_unlock(&d->d_lock);
13049 + spin_unlock(&inode->i_lock);
13051 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13052 + /* need to refresh */
13060 + AuTraceErrPtr(dentry);
13064 +/* ---------------------------------------------------------------------- */
13066 +/* todo: dirty? */
13067 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13069 +struct au_compare_mnt_args {
13071 + struct super_block *sb;
13074 + struct vfsmount *mnt;
13077 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13079 + struct au_compare_mnt_args *a = arg;
13081 + if (mnt->mnt_sb != a->sb)
13083 + a->mnt = mntget(mnt);
13087 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13090 + struct path root;
13091 + struct au_compare_mnt_args args = {
13095 + get_fs_root(current->fs, &root);
13097 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13098 + rcu_read_unlock();
13101 + AuDebugOn(!args.mnt);
13105 +struct au_nfsd_si_lock {
13106 + unsigned int sigen;
13107 + aufs_bindex_t bindex, br_id;
13108 + unsigned char force_lock;
13111 +static int si_nfsd_read_lock(struct super_block *sb,
13112 + struct au_nfsd_si_lock *nsi_lock)
13115 + aufs_bindex_t bindex;
13117 + si_read_lock(sb, AuLock_FLUSH);
13119 + /* branch id may be wrapped around */
13121 + bindex = au_br_index(sb, nsi_lock->br_id);
13122 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13123 + goto out; /* success */
13127 + if (!nsi_lock->force_lock)
13128 + si_read_unlock(sb);
13131 + nsi_lock->bindex = bindex;
13135 +struct find_name_by_ino {
13136 + struct dir_context ctx;
13137 + int called, found;
13144 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13145 + loff_t offset, u64 ino, unsigned int d_type)
13147 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13151 + if (a->ino != ino)
13154 + memcpy(a->name, name, namelen);
13155 + a->namelen = namelen;
13160 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13161 + struct au_nfsd_si_lock *nsi_lock)
13163 + struct dentry *dentry, *parent;
13164 + struct file *file;
13165 + struct inode *dir;
13166 + struct find_name_by_ino arg = {
13168 + .actor = find_name_by_ino
13173 + parent = path->dentry;
13175 + si_read_unlock(parent->d_sb);
13176 + file = vfsub_dentry_open(path, au_dir_roflags);
13177 + dentry = (void *)file;
13178 + if (IS_ERR(file))
13181 + dentry = ERR_PTR(-ENOMEM);
13182 + arg.name = (void *)__get_free_page(GFP_NOFS);
13183 + if (unlikely(!arg.name))
13190 + err = vfsub_iterate_dir(file, &arg.ctx);
13191 + } while (!err && !arg.found && arg.called);
13192 + dentry = ERR_PTR(err);
13193 + if (unlikely(err))
13195 + /* instead of ENOENT */
13196 + dentry = ERR_PTR(-ESTALE);
13200 + /* do not call vfsub_lkup_one() */
13201 + dir = d_inode(parent);
13202 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13203 + AuTraceErrPtr(dentry);
13204 + if (IS_ERR(dentry))
13206 + AuDebugOn(au_test_anon(dentry));
13207 + if (unlikely(d_really_is_negative(dentry))) {
13209 + dentry = ERR_PTR(-ENOENT);
13213 + free_page((unsigned long)arg.name);
13217 + if (unlikely(nsi_lock
13218 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13219 + if (!IS_ERR(dentry)) {
13221 + dentry = ERR_PTR(-ESTALE);
13223 + AuTraceErrPtr(dentry);
13227 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13229 + struct au_nfsd_si_lock *nsi_lock)
13231 + struct dentry *dentry;
13232 + struct path path;
13234 + if (dir_ino != AUFS_ROOT_INO) {
13235 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13236 + dentry = path.dentry;
13237 + if (!path.dentry || IS_ERR(path.dentry))
13239 + AuDebugOn(au_test_anon(path.dentry));
13241 + path.dentry = dget(sb->s_root);
13243 + path.mnt = au_mnt_get(sb);
13244 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13248 + AuTraceErrPtr(dentry);
13252 +/* ---------------------------------------------------------------------- */
13254 +static int h_acceptable(void *expv, struct dentry *dentry)
13259 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13260 + char *buf, int len, struct super_block *sb)
13264 + struct path path;
13266 + p = d_path(h_rootpath, buf, len);
13271 + path.mnt = h_rootpath->mnt;
13272 + path.dentry = h_parent;
13273 + p = d_path(&path, buf, len);
13279 + path.mnt = au_mnt_get(sb);
13280 + path.dentry = sb->s_root;
13281 + p = d_path(&path, buf, len - strlen(p));
13282 + mntput(path.mnt);
13286 + p[strlen(p)] = '/';
13289 + AuTraceErrPtr(p);
13294 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13295 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13297 + struct dentry *dentry, *h_parent, *root;
13298 + struct super_block *h_sb;
13299 + char *pathname, *p;
13300 + struct vfsmount *h_mnt;
13301 + struct au_branch *br;
13303 + struct path path;
13305 + br = au_sbr(sb, nsi_lock->bindex);
13306 + h_mnt = au_br_mnt(br);
13307 + h_sb = h_mnt->mnt_sb;
13308 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13310 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13311 + fh_len - Fh_tail, fh[Fh_h_type],
13312 + h_acceptable, /*context*/NULL);
13314 + dentry = h_parent;
13315 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13316 + AuWarn1("%s decode_fh failed, %ld\n",
13317 + au_sbtype(h_sb), PTR_ERR(h_parent));
13321 + if (unlikely(au_test_anon(h_parent))) {
13322 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13323 + au_sbtype(h_sb));
13324 + goto out_h_parent;
13327 + dentry = ERR_PTR(-ENOMEM);
13328 + pathname = (void *)__get_free_page(GFP_NOFS);
13329 + if (unlikely(!pathname))
13330 + goto out_h_parent;
13332 + root = sb->s_root;
13333 + path.mnt = h_mnt;
13334 + di_read_lock_parent(root, !AuLock_IR);
13335 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13336 + di_read_unlock(root, !AuLock_IR);
13337 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13338 + dentry = (void *)p;
13340 + goto out_pathname;
13342 + si_read_unlock(sb);
13343 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13344 + dentry = ERR_PTR(err);
13345 + if (unlikely(err))
13348 + dentry = ERR_PTR(-ENOENT);
13349 + AuDebugOn(au_test_anon(path.dentry));
13350 + if (unlikely(d_really_is_negative(path.dentry)))
13353 + if (ino != d_inode(path.dentry)->i_ino)
13354 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13356 + dentry = dget(path.dentry);
13361 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13362 + if (!IS_ERR(dentry)) {
13364 + dentry = ERR_PTR(-ESTALE);
13367 + free_page((unsigned long)pathname);
13371 + AuTraceErrPtr(dentry);
13375 +/* ---------------------------------------------------------------------- */
13377 +static struct dentry *
13378 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13381 + struct dentry *dentry;
13382 + __u32 *fh = fid->raw;
13383 + struct au_branch *br;
13384 + ino_t ino, dir_ino;
13385 + struct au_nfsd_si_lock nsi_lock = {
13389 + dentry = ERR_PTR(-ESTALE);
13390 + /* it should never happen, but the file handle is unreliable */
13391 + if (unlikely(fh_len < Fh_tail))
13393 + nsi_lock.sigen = fh[Fh_sigen];
13394 + nsi_lock.br_id = fh[Fh_br_id];
13396 + /* branch id may be wrapped around */
13398 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13400 + nsi_lock.force_lock = 1;
13402 + /* is this inode still cached? */
13403 + ino = decode_ino(fh + Fh_ino);
13404 + /* it should never happen */
13405 + if (unlikely(ino == AUFS_ROOT_INO))
13408 + dir_ino = decode_ino(fh + Fh_dir_ino);
13409 + dentry = decode_by_ino(sb, ino, dir_ino);
13410 + if (IS_ERR(dentry))
13415 + /* is the parent dir cached? */
13416 + br = au_sbr(sb, nsi_lock.bindex);
13417 + au_lcnt_inc(&br->br_nfiles);
13418 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13419 + if (IS_ERR(dentry))
13424 + /* lookup path */
13425 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13426 + if (IS_ERR(dentry))
13428 + if (unlikely(!dentry))
13429 + /* todo?: make it ESTALE */
13433 + if (!au_digen_test(dentry, au_sigen(sb))
13434 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13435 + goto out_unlock; /* success */
13438 + dentry = ERR_PTR(-ESTALE);
13441 + au_lcnt_dec(&br->br_nfiles);
13442 + si_read_unlock(sb);
13444 + AuTraceErrPtr(dentry);
13448 +#if 0 /* reserved for future use */
13449 +/* support subtreecheck option */
13450 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13451 + int fh_len, int fh_type)
13453 + struct dentry *parent;
13454 + __u32 *fh = fid->raw;
13457 + dir_ino = decode_ino(fh + Fh_dir_ino);
13458 + parent = decode_by_ino(sb, dir_ino, 0);
13459 + if (IS_ERR(parent))
13462 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13463 + dir_ino, fh, fh_len);
13466 + AuTraceErrPtr(parent);
13471 +/* ---------------------------------------------------------------------- */
13473 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13474 + struct inode *dir)
13477 + aufs_bindex_t bindex;
13478 + struct super_block *sb, *h_sb;
13479 + struct dentry *dentry, *parent, *h_parent;
13480 + struct inode *h_dir;
13481 + struct au_branch *br;
13484 + if (unlikely(*max_len <= Fh_tail)) {
13485 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13489 + err = FILEID_ROOT;
13490 + if (inode->i_ino == AUFS_ROOT_INO) {
13491 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13496 + sb = inode->i_sb;
13497 + err = si_read_lock(sb, AuLock_FLUSH);
13498 + if (unlikely(err))
13501 +#ifdef CONFIG_AUFS_DEBUG
13502 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13503 + AuWarn1("NFS-exporting requires xino\n");
13507 + ii_read_lock_child(inode);
13508 + bindex = au_ibtop(inode);
13510 + dentry = d_find_any_alias(inode);
13511 + if (unlikely(!dentry))
13513 + AuDebugOn(au_test_anon(dentry));
13514 + parent = dget_parent(dentry);
13516 + if (unlikely(!parent))
13518 + if (d_really_is_positive(parent))
13519 + dir = d_inode(parent);
13522 + ii_read_lock_parent(dir);
13523 + h_dir = au_h_iptr(dir, bindex);
13524 + ii_read_unlock(dir);
13525 + if (unlikely(!h_dir))
13527 + h_parent = d_find_any_alias(h_dir);
13528 + if (unlikely(!h_parent))
13529 + goto out_hparent;
13532 + br = au_sbr(sb, bindex);
13533 + h_sb = au_br_sb(br);
13534 + if (unlikely(!h_sb->s_export_op)) {
13535 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13536 + goto out_hparent;
13539 + fh[Fh_br_id] = br->br_id;
13540 + fh[Fh_sigen] = au_sigen(sb);
13541 + encode_ino(fh + Fh_ino, inode->i_ino);
13542 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13543 + fh[Fh_igen] = inode->i_generation;
13545 + *max_len -= Fh_tail;
13546 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13548 + /*connectable or subtreecheck*/0);
13549 + err = fh[Fh_h_type];
13550 + *max_len += Fh_tail;
13551 + /* todo: macros? */
13552 + if (err != FILEID_INVALID)
13555 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13562 + ii_read_unlock(inode);
13563 + si_read_unlock(sb);
13565 + if (unlikely(err < 0))
13566 + err = FILEID_INVALID;
13570 +/* ---------------------------------------------------------------------- */
13572 +static int aufs_commit_metadata(struct inode *inode)
13575 + aufs_bindex_t bindex;
13576 + struct super_block *sb;
13577 + struct inode *h_inode;
13578 + int (*f)(struct inode *inode);
13580 + sb = inode->i_sb;
13581 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13582 + ii_write_lock_child(inode);
13583 + bindex = au_ibtop(inode);
13584 + AuDebugOn(bindex < 0);
13585 + h_inode = au_h_iptr(inode, bindex);
13587 + f = h_inode->i_sb->s_export_op->commit_metadata;
13589 + err = f(h_inode);
13591 + err = sync_inode_metadata(h_inode, /*wait*/1);
13593 + au_cpup_attr_timesizes(inode);
13594 + ii_write_unlock(inode);
13595 + si_read_unlock(sb);
13599 +/* ---------------------------------------------------------------------- */
13601 +static struct export_operations aufs_export_op = {
13602 + .fh_to_dentry = aufs_fh_to_dentry,
13603 + /* .fh_to_parent = aufs_fh_to_parent, */
13604 + .encode_fh = aufs_encode_fh,
13605 + .commit_metadata = aufs_commit_metadata
13608 +void au_export_init(struct super_block *sb)
13610 + struct au_sbinfo *sbinfo;
13613 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13614 + && IS_MODULE(CONFIG_EXPORTFS),
13615 + AUFS_NAME ": unsupported configuration "
13616 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13618 + sb->s_export_op = &aufs_export_op;
13619 + sbinfo = au_sbi(sb);
13620 + sbinfo->si_xigen = NULL;
13621 + get_random_bytes(&u, sizeof(u));
13622 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13623 + atomic_set(&sbinfo->si_xigen_next, u);
13625 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13626 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13627 +++ linux/fs/aufs/fhsm.c 2021-12-03 15:38:59.933313976 +0100
13629 +// SPDX-License-Identifier: GPL-2.0
13631 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13633 + * This program, aufs is free software; you can redistribute it and/or modify
13634 + * it under the terms of the GNU General Public License as published by
13635 + * the Free Software Foundation; either version 2 of the License, or
13636 + * (at your option) any later version.
13638 + * This program is distributed in the hope that it will be useful,
13639 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13640 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13641 + * GNU General Public License for more details.
13643 + * You should have received a copy of the GNU General Public License
13644 + * along with this program; if not, write to the Free Software
13645 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13649 + * File-based Hierarchy Storage Management
13652 +#include <linux/anon_inodes.h>
13653 +#include <linux/poll.h>
13654 +#include <linux/seq_file.h>
13655 +#include <linux/statfs.h>
13658 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13660 + struct au_sbinfo *sbinfo;
13661 + struct au_fhsm *fhsm;
13663 + SiMustAnyLock(sb);
13665 + sbinfo = au_sbi(sb);
13666 + fhsm = &sbinfo->si_fhsm;
13667 + AuDebugOn(!fhsm);
13668 + return fhsm->fhsm_bottom;
13671 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13673 + struct au_sbinfo *sbinfo;
13674 + struct au_fhsm *fhsm;
13676 + SiMustWriteLock(sb);
13678 + sbinfo = au_sbi(sb);
13679 + fhsm = &sbinfo->si_fhsm;
13680 + AuDebugOn(!fhsm);
13681 + fhsm->fhsm_bottom = bindex;
13684 +/* ---------------------------------------------------------------------- */
13686 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13688 + struct au_br_fhsm *bf;
13690 + bf = br->br_fhsm;
13691 + MtxMustLock(&bf->bf_lock);
13693 + return !bf->bf_readable
13694 + || time_after(jiffies,
13695 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13698 +/* ---------------------------------------------------------------------- */
13700 +static void au_fhsm_notify(struct super_block *sb, int val)
13702 + struct au_sbinfo *sbinfo;
13703 + struct au_fhsm *fhsm;
13705 + SiMustAnyLock(sb);
13707 + sbinfo = au_sbi(sb);
13708 + fhsm = &sbinfo->si_fhsm;
13709 + if (au_fhsm_pid(fhsm)
13710 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13711 + atomic_set(&fhsm->fhsm_readable, val);
13713 + wake_up(&fhsm->fhsm_wqh);
13717 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13718 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13721 + struct au_branch *br;
13722 + struct au_br_fhsm *bf;
13724 + br = au_sbr(sb, bindex);
13725 + AuDebugOn(au_br_rdonly(br));
13726 + bf = br->br_fhsm;
13730 + mutex_lock(&bf->bf_lock);
13732 + MtxMustLock(&bf->bf_lock);
13734 + /* sb->s_root for NFS is unreliable */
13735 + err = au_br_stfs(br, &bf->bf_stfs);
13736 + if (unlikely(err)) {
13737 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13741 + bf->bf_jiffy = jiffies;
13742 + bf->bf_readable = 1;
13744 + au_fhsm_notify(sb, /*val*/1);
13746 + *rstfs = bf->bf_stfs;
13750 + mutex_unlock(&bf->bf_lock);
13751 + au_fhsm_notify(sb, /*val*/1);
13756 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13759 + struct au_sbinfo *sbinfo;
13760 + struct au_fhsm *fhsm;
13761 + struct au_branch *br;
13762 + struct au_br_fhsm *bf;
13764 + AuDbg("b%d, force %d\n", bindex, force);
13765 + SiMustAnyLock(sb);
13767 + sbinfo = au_sbi(sb);
13768 + fhsm = &sbinfo->si_fhsm;
13769 + if (!au_ftest_si(sbinfo, FHSM)
13770 + || fhsm->fhsm_bottom == bindex)
13773 + br = au_sbr(sb, bindex);
13774 + bf = br->br_fhsm;
13776 + mutex_lock(&bf->bf_lock);
13778 + || au_fhsm_pid(fhsm)
13779 + || au_fhsm_test_jiffy(sbinfo, br))
13780 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13782 + mutex_unlock(&bf->bf_lock);
13785 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13787 + aufs_bindex_t bindex, bbot;
13788 + struct au_branch *br;
13790 + /* exclude the bottom */
13791 + bbot = au_fhsm_bottom(sb);
13792 + for (bindex = 0; bindex < bbot; bindex++) {
13793 + br = au_sbr(sb, bindex);
13794 + if (au_br_fhsm(br->br_perm))
13795 + au_fhsm_wrote(sb, bindex, force);
13799 +/* ---------------------------------------------------------------------- */
13801 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13804 + struct au_sbinfo *sbinfo;
13805 + struct au_fhsm *fhsm;
13808 + sbinfo = file->private_data;
13809 + fhsm = &sbinfo->si_fhsm;
13810 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13811 + if (atomic_read(&fhsm->fhsm_readable))
13812 + mask = EPOLLIN /* | EPOLLRDNORM */;
13815 + AuDbg("mask 0x%x\n", mask);
13819 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13820 + struct aufs_stfs *stfs, __s16 brid)
13824 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13826 + err = __put_user(brid, &stbr->brid);
13827 + if (unlikely(err))
13833 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13834 + struct aufs_stbr __user *stbr, size_t count)
13838 + aufs_bindex_t bindex, bbot;
13839 + struct au_branch *br;
13840 + struct au_br_fhsm *bf;
13842 + /* except the bottom branch */
13845 + bbot = au_fhsm_bottom(sb);
13846 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13847 + br = au_sbr(sb, bindex);
13848 + if (!au_br_fhsm(br->br_perm))
13851 + bf = br->br_fhsm;
13852 + mutex_lock(&bf->bf_lock);
13853 + if (bf->bf_readable) {
13855 + if (count >= sizeof(*stbr))
13856 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13859 + bf->bf_readable = 0;
13860 + count -= sizeof(*stbr);
13864 + mutex_unlock(&bf->bf_lock);
13867 + err = sizeof(*stbr) * nstbr;
13872 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13877 + aufs_bindex_t nfhsm, bindex, bbot;
13878 + struct au_sbinfo *sbinfo;
13879 + struct au_fhsm *fhsm;
13880 + struct au_branch *br;
13881 + struct super_block *sb;
13884 + sbinfo = file->private_data;
13885 + fhsm = &sbinfo->si_fhsm;
13887 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13888 + if (!atomic_read(&fhsm->fhsm_readable)) {
13889 + if (vfsub_file_flags(file) & O_NONBLOCK)
13892 + err = wait_event_interruptible_locked_irq
13894 + atomic_read(&fhsm->fhsm_readable));
13896 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13897 + if (unlikely(err))
13900 + /* sb may already be dead */
13901 + au_rw_read_lock(&sbinfo->si_rwsem);
13902 + readable = atomic_read(&fhsm->fhsm_readable);
13903 + if (readable > 0) {
13904 + sb = sbinfo->si_sb;
13906 + /* exclude the bottom branch */
13908 + bbot = au_fhsm_bottom(sb);
13909 + for (bindex = 0; bindex < bbot; bindex++) {
13910 + br = au_sbr(sb, bindex);
13911 + if (au_br_fhsm(br->br_perm))
13915 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13916 + atomic_set(&fhsm->fhsm_readable, 0);
13917 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13921 + au_rw_read_unlock(&sbinfo->si_rwsem);
13929 +static int au_fhsm_release(struct inode *inode, struct file *file)
13931 + struct au_sbinfo *sbinfo;
13932 + struct au_fhsm *fhsm;
13934 + /* sb may already be dead */
13935 + sbinfo = file->private_data;
13936 + fhsm = &sbinfo->si_fhsm;
13937 + spin_lock(&fhsm->fhsm_spin);
13938 + fhsm->fhsm_pid = 0;
13939 + spin_unlock(&fhsm->fhsm_spin);
13940 + kobject_put(&sbinfo->si_kobj);
13945 +static const struct file_operations au_fhsm_fops = {
13946 + .owner = THIS_MODULE,
13947 + .llseek = noop_llseek,
13948 + .read = au_fhsm_read,
13949 + .poll = au_fhsm_poll,
13950 + .release = au_fhsm_release
13953 +int au_fhsm_fd(struct super_block *sb, int oflags)
13956 + struct au_sbinfo *sbinfo;
13957 + struct au_fhsm *fhsm;
13960 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13964 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13968 + sbinfo = au_sbi(sb);
13969 + fhsm = &sbinfo->si_fhsm;
13970 + spin_lock(&fhsm->fhsm_spin);
13971 + if (!fhsm->fhsm_pid)
13972 + fhsm->fhsm_pid = current->pid;
13975 + spin_unlock(&fhsm->fhsm_spin);
13976 + if (unlikely(err))
13979 + oflags |= O_RDONLY;
13980 + /* oflags |= FMODE_NONOTIFY; */
13981 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13983 + if (unlikely(fd < 0))
13986 + /* succeed regardless 'fhsm' status */
13987 + kobject_get(&sbinfo->si_kobj);
13988 + si_noflush_read_lock(sb);
13989 + if (au_ftest_si(sbinfo, FHSM))
13990 + au_fhsm_wrote_all(sb, /*force*/0);
13991 + si_read_unlock(sb);
13992 + goto out; /* success */
13995 + spin_lock(&fhsm->fhsm_spin);
13996 + fhsm->fhsm_pid = 0;
13997 + spin_unlock(&fhsm->fhsm_spin);
14003 +/* ---------------------------------------------------------------------- */
14005 +int au_fhsm_br_alloc(struct au_branch *br)
14010 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14012 + au_br_fhsm_init(br->br_fhsm);
14019 +/* ---------------------------------------------------------------------- */
14021 +void au_fhsm_fin(struct super_block *sb)
14023 + au_fhsm_notify(sb, /*val*/-1);
14026 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14028 + struct au_fhsm *fhsm;
14030 + fhsm = &sbinfo->si_fhsm;
14031 + spin_lock_init(&fhsm->fhsm_spin);
14032 + init_waitqueue_head(&fhsm->fhsm_wqh);
14033 + atomic_set(&fhsm->fhsm_readable, 0);
14034 + fhsm->fhsm_expire
14035 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14036 + fhsm->fhsm_bottom = -1;
14039 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14041 + sbinfo->si_fhsm.fhsm_expire
14042 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14045 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14049 + if (!au_ftest_si(sbinfo, FHSM))
14052 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14053 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14054 + seq_printf(seq, ",fhsm_sec=%u", u);
14056 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14057 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14058 +++ linux/fs/aufs/file.c 2021-12-03 15:38:59.936647310 +0100
14060 +// SPDX-License-Identifier: GPL-2.0
14062 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14064 + * This program, aufs is free software; you can redistribute it and/or modify
14065 + * it under the terms of the GNU General Public License as published by
14066 + * the Free Software Foundation; either version 2 of the License, or
14067 + * (at your option) any later version.
14069 + * This program is distributed in the hope that it will be useful,
14070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14072 + * GNU General Public License for more details.
14074 + * You should have received a copy of the GNU General Public License
14075 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14079 + * handling file/dir, and address_space operation
14082 +#ifdef CONFIG_AUFS_DEBUG
14083 +#include <linux/migrate.h>
14085 +#include <linux/pagemap.h>
14088 +/* drop flags for writing */
14089 +unsigned int au_file_roflags(unsigned int flags)
14091 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14092 + flags |= O_RDONLY | O_NOATIME;
14096 +/* common functions to regular file and dir */
14097 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14098 + struct file *file, int force_wr)
14100 + struct file *h_file;
14101 + struct dentry *h_dentry;
14102 + struct inode *h_inode;
14103 + struct super_block *sb;
14104 + struct au_branch *br;
14105 + struct path h_path;
14108 + /* a race condition can happen between open and unlink/rmdir */
14109 + h_file = ERR_PTR(-ENOENT);
14110 + h_dentry = au_h_dptr(dentry, bindex);
14111 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14113 + h_inode = d_inode(h_dentry);
14114 + spin_lock(&h_dentry->d_lock);
14115 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14116 + /* || !d_inode(dentry)->i_nlink */
14118 + spin_unlock(&h_dentry->d_lock);
14119 + if (unlikely(err))
14122 + sb = dentry->d_sb;
14123 + br = au_sbr(sb, bindex);
14124 + err = au_br_test_oflag(flags, br);
14125 + h_file = ERR_PTR(err);
14126 + if (unlikely(err))
14129 + /* drop flags for writing */
14130 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14131 + if (force_wr && !(flags & O_WRONLY))
14133 + flags = au_file_roflags(flags);
14135 + h_file = ERR_PTR(-EROFS);
14136 + flags = au_file_roflags(flags);
14137 + if (unlikely(vfsub_native_ro(h_inode)
14138 + || IS_APPEND(h_inode)))
14140 + flags &= ~O_ACCMODE;
14141 + flags |= O_WRONLY;
14144 + flags &= ~O_CREAT;
14145 + au_lcnt_inc(&br->br_nfiles);
14146 + h_path.dentry = h_dentry;
14147 + h_path.mnt = au_br_mnt(br);
14148 + h_file = vfsub_dentry_open(&h_path, flags);
14149 + if (IS_ERR(h_file))
14152 + if (flags & __FMODE_EXEC) {
14153 + err = deny_write_access(h_file);
14154 + if (unlikely(err)) {
14156 + h_file = ERR_PTR(err);
14160 + fsnotify_open(h_file);
14161 + goto out; /* success */
14164 + au_lcnt_dec(&br->br_nfiles);
14169 +static int au_cmoo(struct dentry *dentry)
14171 + int err, cmoo, matched;
14172 + unsigned int udba;
14173 + struct path h_path;
14174 + struct au_pin pin;
14175 + struct au_cp_generic cpg = {
14176 + .dentry = dentry,
14181 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14183 + struct inode *delegated;
14184 + struct super_block *sb;
14185 + struct au_sbinfo *sbinfo;
14186 + struct au_fhsm *fhsm;
14188 + struct au_branch *br;
14189 + struct dentry *parent;
14190 + struct au_hinode *hdir;
14192 + DiMustWriteLock(dentry);
14193 + IiMustWriteLock(d_inode(dentry));
14196 + if (IS_ROOT(dentry))
14198 + cpg.bsrc = au_dbtop(dentry);
14202 + sb = dentry->d_sb;
14203 + sbinfo = au_sbi(sb);
14204 + fhsm = &sbinfo->si_fhsm;
14205 + pid = au_fhsm_pid(fhsm);
14208 + && (current->pid == pid
14209 + || rcu_dereference(current->real_parent)->pid == pid));
14210 + rcu_read_unlock();
14214 + br = au_sbr(sb, cpg.bsrc);
14215 + cmoo = au_br_cmoo(br->br_perm);
14218 + if (!d_is_reg(dentry))
14219 + cmoo &= AuBrAttr_COO_ALL;
14223 + parent = dget_parent(dentry);
14224 + di_write_lock_parent(parent);
14225 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14227 + if (unlikely(err < 0)) {
14228 + err = 0; /* there is no upper writable branch */
14231 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14233 + /* do not respect the coo attrib for the target branch */
14234 + err = au_cpup_dirs(dentry, cpg.bdst);
14235 + if (unlikely(err))
14238 + di_downgrade_lock(parent, AuLock_IR);
14239 + udba = au_opt_udba(sb);
14240 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14241 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14242 + if (unlikely(err))
14245 + err = au_sio_cpup_simple(&cpg);
14247 + if (unlikely(err))
14249 + if (!(cmoo & AuBrWAttr_MOO))
14250 + goto out_parent; /* success */
14252 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14253 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14254 + if (unlikely(err))
14257 + h_path.mnt = au_br_mnt(br);
14258 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14259 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14260 + delegated = NULL;
14261 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14263 + /* todo: keep h_dentry or not? */
14264 + if (unlikely(err == -EWOULDBLOCK)) {
14265 + pr_warn("cannot retry for NFSv4 delegation"
14266 + " for an internal unlink\n");
14269 + if (unlikely(err)) {
14270 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14274 + goto out_parent; /* success */
14277 + di_downgrade_lock(parent, AuLock_IR);
14279 + di_read_unlock(parent, AuLock_IR);
14286 +int au_do_open(struct file *file, struct au_do_open_args *args)
14288 + int err, aopen = args->aopen;
14289 + struct dentry *dentry;
14290 + struct au_finfo *finfo;
14293 + err = au_finfo_init(file, args->fidir);
14296 + err = au_finfo_init(file, args->fidir);
14299 + if (unlikely(err))
14302 + dentry = file->f_path.dentry;
14303 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14304 + di_write_lock_child(dentry);
14305 + err = au_cmoo(dentry);
14306 + di_downgrade_lock(dentry, AuLock_IR);
14309 + err = args->open(file, vfsub_file_flags(file), NULL);
14312 + err = args->open(file, vfsub_file_flags(file),
14317 + di_read_unlock(dentry, AuLock_IR);
14319 + finfo = au_fi(file);
14321 + finfo->fi_file = file;
14322 + au_hbl_add(&finfo->fi_hlist,
14323 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14326 + fi_write_unlock(file);
14329 + fi_write_unlock(file);
14332 + if (unlikely(err)) {
14333 + finfo->fi_hdir = NULL;
14334 + au_finfo_fin(file);
14342 +int au_reopen_nondir(struct file *file)
14345 + aufs_bindex_t btop;
14346 + struct dentry *dentry;
14347 + struct au_branch *br;
14348 + struct file *h_file, *h_file_tmp;
14350 + dentry = file->f_path.dentry;
14351 + btop = au_dbtop(dentry);
14352 + br = au_sbr(dentry->d_sb, btop);
14353 + h_file_tmp = NULL;
14354 + if (au_fbtop(file) == btop) {
14355 + h_file = au_hf_top(file);
14356 + if (file->f_mode == h_file->f_mode)
14357 + return 0; /* success */
14358 + h_file_tmp = h_file;
14359 + get_file(h_file_tmp);
14360 + au_lcnt_inc(&br->br_nfiles);
14361 + au_set_h_fptr(file, btop, NULL);
14363 + AuDebugOn(au_fi(file)->fi_hdir);
14366 + * file exists on both of rw and ro
14367 + * open --> dbtop and fbtop are both 0
14368 + * prepend a branch as rw, "rw" become ro
14370 + * delete the top branch, "rw" becomes rw again
14371 + * --> dbtop is 1, fbtop is still 0
14372 + * write --> fbtop is 0 but dbtop is 1
14374 + /* AuDebugOn(au_fbtop(file) < btop); */
14376 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14377 + file, /*force_wr*/0);
14378 + err = PTR_ERR(h_file);
14379 + if (IS_ERR(h_file)) {
14380 + if (h_file_tmp) {
14382 + au_set_h_fptr(file, btop, h_file_tmp);
14383 + h_file_tmp = NULL;
14385 + goto out; /* todo: close all? */
14389 + au_set_fbtop(file, btop);
14390 + au_set_h_fptr(file, btop, h_file);
14391 + au_update_figen(file);
14392 + /* todo: necessary? */
14393 + /* file->f_ra = h_file->f_ra; */
14396 + if (h_file_tmp) {
14397 + fput(h_file_tmp);
14398 + au_lcnt_dec(&br->br_nfiles);
14403 +/* ---------------------------------------------------------------------- */
14405 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14406 + struct dentry *hi_wh)
14409 + aufs_bindex_t btop;
14410 + struct au_dinfo *dinfo;
14411 + struct dentry *h_dentry;
14412 + struct au_hdentry *hdp;
14414 + dinfo = au_di(file->f_path.dentry);
14415 + AuRwMustWriteLock(&dinfo->di_rwsem);
14417 + btop = dinfo->di_btop;
14418 + dinfo->di_btop = btgt;
14419 + hdp = au_hdentry(dinfo, btgt);
14420 + h_dentry = hdp->hd_dentry;
14421 + hdp->hd_dentry = hi_wh;
14422 + err = au_reopen_nondir(file);
14423 + hdp->hd_dentry = h_dentry;
14424 + dinfo->di_btop = btop;
14429 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14430 + aufs_bindex_t bcpup, struct au_pin *pin)
14433 + struct inode *inode, *h_inode;
14434 + struct dentry *h_dentry, *hi_wh;
14435 + struct au_cp_generic cpg = {
14436 + .dentry = file->f_path.dentry,
14443 + au_update_dbtop(cpg.dentry);
14444 + inode = d_inode(cpg.dentry);
14446 + if (au_dbtop(cpg.dentry) <= bcpup
14447 + && au_dbbot(cpg.dentry) >= bcpup) {
14448 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14449 + if (h_dentry && d_is_positive(h_dentry))
14450 + h_inode = d_inode(h_dentry);
14452 + hi_wh = au_hi_wh(inode, bcpup);
14453 + if (!hi_wh && !h_inode)
14454 + err = au_sio_cpup_wh(&cpg, file);
14456 + /* already copied-up after unlink */
14457 + err = au_reopen_wh(file, bcpup, hi_wh);
14460 + && (inode->i_nlink > 1
14461 + || (inode->i_state & I_LINKABLE))
14462 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14463 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14469 + * prepare the @file for writing.
14471 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14474 + aufs_bindex_t dbtop;
14475 + struct dentry *parent;
14476 + struct inode *inode;
14477 + struct super_block *sb;
14478 + struct file *h_file;
14479 + struct au_cp_generic cpg = {
14480 + .dentry = file->f_path.dentry,
14485 + .flags = AuCpup_DTIME
14488 + sb = cpg.dentry->d_sb;
14489 + inode = d_inode(cpg.dentry);
14490 + cpg.bsrc = au_fbtop(file);
14491 + err = au_test_ro(sb, cpg.bsrc, inode);
14492 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14493 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14498 + /* need to cpup or reopen */
14499 + parent = dget_parent(cpg.dentry);
14500 + di_write_lock_parent(parent);
14501 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14503 + if (unlikely(err < 0))
14507 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14508 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14509 + if (unlikely(err))
14513 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14514 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14515 + if (unlikely(err))
14518 + dbtop = au_dbtop(cpg.dentry);
14519 + if (dbtop <= cpg.bdst)
14520 + cpg.bsrc = cpg.bdst;
14522 + if (dbtop <= cpg.bdst /* just reopen */
14523 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14525 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14526 + if (IS_ERR(h_file))
14527 + err = PTR_ERR(h_file);
14529 + di_downgrade_lock(parent, AuLock_IR);
14530 + if (dbtop > cpg.bdst)
14531 + err = au_sio_cpup_simple(&cpg);
14533 + err = au_reopen_nondir(file);
14534 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14536 + } else { /* copyup as wh and reopen */
14538 + * since writable hfsplus branch is not supported,
14539 + * h_open_pre/post() are unnecessary.
14541 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14542 + di_downgrade_lock(parent, AuLock_IR);
14546 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14547 + goto out_dput; /* success */
14553 + di_downgrade_lock(parent, AuLock_IR);
14555 + di_read_unlock(parent, AuLock_IR);
14562 +/* ---------------------------------------------------------------------- */
14564 +int au_do_flush(struct file *file, fl_owner_t id,
14565 + int (*flush)(struct file *file, fl_owner_t id))
14568 + struct super_block *sb;
14569 + struct inode *inode;
14571 + inode = file_inode(file);
14572 + sb = inode->i_sb;
14573 + si_noflush_read_lock(sb);
14574 + fi_read_lock(file);
14575 + ii_read_lock_child(inode);
14577 + err = flush(file, id);
14578 + au_cpup_attr_timesizes(inode);
14580 + ii_read_unlock(inode);
14581 + fi_read_unlock(file);
14582 + si_read_unlock(sb);
14586 +/* ---------------------------------------------------------------------- */
14588 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14591 + struct au_pin pin;
14592 + struct au_finfo *finfo;
14593 + struct dentry *parent, *hi_wh;
14594 + struct inode *inode;
14595 + struct super_block *sb;
14596 + struct au_cp_generic cpg = {
14597 + .dentry = file->f_path.dentry,
14602 + .flags = AuCpup_DTIME
14605 + FiMustWriteLock(file);
14608 + finfo = au_fi(file);
14609 + sb = cpg.dentry->d_sb;
14610 + inode = d_inode(cpg.dentry);
14611 + cpg.bdst = au_ibtop(inode);
14612 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14615 + parent = dget_parent(cpg.dentry);
14616 + if (au_test_ro(sb, cpg.bdst, inode)) {
14617 + di_read_lock_parent(parent, !AuLock_IR);
14618 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14620 + di_read_unlock(parent, !AuLock_IR);
14621 + if (unlikely(err < 0))
14626 + di_read_lock_parent(parent, AuLock_IR);
14627 + hi_wh = au_hi_wh(inode, cpg.bdst);
14628 + if (!S_ISDIR(inode->i_mode)
14629 + && au_opt_test(au_mntflags(sb), PLINK)
14630 + && au_plink_test(inode)
14631 + && !d_unhashed(cpg.dentry)
14632 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14633 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14634 + if (unlikely(err))
14637 + /* always superio. */
14638 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14639 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14641 + err = au_sio_cpup_simple(&cpg);
14644 + } else if (hi_wh) {
14645 + /* already copied-up after unlink */
14646 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14647 + *need_reopen = 0;
14651 + di_read_unlock(parent, AuLock_IR);
14658 +static void au_do_refresh_dir(struct file *file)
14660 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14661 + struct au_hfile *p, tmp, *q;
14662 + struct au_finfo *finfo;
14663 + struct super_block *sb;
14664 + struct au_fidir *fidir;
14666 + FiMustWriteLock(file);
14668 + sb = file->f_path.dentry->d_sb;
14669 + finfo = au_fi(file);
14670 + fidir = finfo->fi_hdir;
14671 + AuDebugOn(!fidir);
14672 + p = fidir->fd_hfile + finfo->fi_btop;
14673 + brid = p->hf_br->br_id;
14674 + bbot = fidir->fd_bbot;
14675 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14679 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14680 + if (new_bindex == bindex)
14682 + if (new_bindex < 0) {
14683 + au_set_h_fptr(file, bindex, NULL);
14687 + /* swap two lower inode, and loop again */
14688 + q = fidir->fd_hfile + new_bindex;
14692 + if (tmp.hf_file) {
14698 + p = fidir->fd_hfile;
14699 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14700 + bbot = au_sbbot(sb);
14701 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14702 + finfo->fi_btop++, p++)
14703 + if (p->hf_file) {
14704 + if (file_inode(p->hf_file))
14706 + au_hfput(p, /*execed*/0);
14709 + bbot = au_br_index(sb, brid);
14710 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14711 + finfo->fi_btop++, p++)
14713 + au_hfput(p, /*execed*/0);
14714 + bbot = au_sbbot(sb);
14717 + p = fidir->fd_hfile + bbot;
14718 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14719 + fidir->fd_bbot--, p--)
14720 + if (p->hf_file) {
14721 + if (file_inode(p->hf_file))
14723 + au_hfput(p, /*execed*/0);
14725 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14729 + * after branch manipulating, refresh the file.
14731 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14733 + int err, need_reopen, nbr;
14734 + aufs_bindex_t bbot, bindex;
14735 + struct dentry *dentry;
14736 + struct super_block *sb;
14737 + struct au_finfo *finfo;
14738 + struct au_hfile *hfile;
14740 + dentry = file->f_path.dentry;
14741 + sb = dentry->d_sb;
14742 + nbr = au_sbbot(sb) + 1;
14743 + finfo = au_fi(file);
14744 + if (!finfo->fi_hdir) {
14745 + hfile = &finfo->fi_htop;
14746 + AuDebugOn(!hfile->hf_file);
14747 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14748 + AuDebugOn(bindex < 0);
14749 + if (bindex != finfo->fi_btop)
14750 + au_set_fbtop(file, bindex);
14752 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14753 + if (unlikely(err))
14755 + au_do_refresh_dir(file);
14760 + if (!au_test_mmapped(file))
14761 + err = au_file_refresh_by_inode(file, &need_reopen);
14762 + if (finfo->fi_hdir)
14763 + /* harmless if err */
14764 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14765 + if (!err && need_reopen && !d_unlinked(dentry))
14766 + err = reopen(file);
14768 + au_update_figen(file);
14769 + goto out; /* success */
14772 + /* error, close all lower files */
14773 + if (finfo->fi_hdir) {
14774 + bbot = au_fbbot_dir(file);
14775 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14776 + au_set_h_fptr(file, bindex, NULL);
14783 +/* common function to regular file and dir */
14784 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14785 + int wlock, unsigned int fi_lsc)
14788 + unsigned int sigen, figen;
14789 + aufs_bindex_t btop;
14790 + unsigned char pseudo_link;
14791 + struct dentry *dentry;
14792 + struct inode *inode;
14795 + dentry = file->f_path.dentry;
14796 + inode = d_inode(dentry);
14797 + sigen = au_sigen(dentry->d_sb);
14798 + fi_write_lock_nested(file, fi_lsc);
14799 + figen = au_figen(file);
14801 + di_write_lock_child(dentry);
14803 + di_write_lock_child2(dentry);
14804 + btop = au_dbtop(dentry);
14805 + pseudo_link = (btop != au_ibtop(inode));
14806 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14808 + di_downgrade_lock(dentry, AuLock_IR);
14809 + fi_downgrade_lock(file);
14811 + goto out; /* success */
14814 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14815 + if (au_digen_test(dentry, sigen)) {
14816 + err = au_reval_dpath(dentry, sigen);
14817 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14821 + err = refresh_file(file, reopen);
14824 + di_downgrade_lock(dentry, AuLock_IR);
14825 + fi_downgrade_lock(file);
14828 + di_write_unlock(dentry);
14829 + fi_write_unlock(file);
14836 +/* ---------------------------------------------------------------------- */
14838 +/* cf. aufs_nopage() */
14839 +/* for madvise(2) */
14840 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14842 + unlock_page(page);
14846 +/* it will never be called, but necessary to support O_DIRECT */
14847 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14848 +{ BUG(); return 0; }
14850 +/* they will never be called. */
14851 +#ifdef CONFIG_AUFS_DEBUG
14852 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14853 + loff_t pos, unsigned len, unsigned flags,
14854 + struct page **pagep, void **fsdata)
14855 +{ AuUnsupport(); return 0; }
14856 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14857 + loff_t pos, unsigned len, unsigned copied,
14858 + struct page *page, void *fsdata)
14859 +{ AuUnsupport(); return 0; }
14860 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14861 +{ AuUnsupport(); return 0; }
14863 +static int aufs_set_page_dirty(struct page *page)
14864 +{ AuUnsupport(); return 0; }
14865 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14866 + unsigned int length)
14867 +{ AuUnsupport(); }
14868 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14869 +{ AuUnsupport(); return 0; }
14870 +#if 0 /* called by memory compaction regardless file */
14871 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14872 + struct page *page, enum migrate_mode mode)
14873 +{ AuUnsupport(); return 0; }
14875 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14876 +{ AuUnsupport(); return true; }
14877 +static void aufs_putback_page(struct page *page)
14878 +{ AuUnsupport(); }
14879 +static int aufs_launder_page(struct page *page)
14880 +{ AuUnsupport(); return 0; }
14881 +static int aufs_is_partially_uptodate(struct page *page,
14882 + unsigned long from,
14883 + unsigned long count)
14884 +{ AuUnsupport(); return 0; }
14885 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14887 +{ AuUnsupport(); }
14888 +static int aufs_error_remove_page(struct address_space *mapping,
14889 + struct page *page)
14890 +{ AuUnsupport(); return 0; }
14891 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14893 +{ AuUnsupport(); return 0; }
14894 +static void aufs_swap_deactivate(struct file *file)
14895 +{ AuUnsupport(); }
14896 +#endif /* CONFIG_AUFS_DEBUG */
14898 +const struct address_space_operations aufs_aop = {
14899 + .readpage = aufs_readpage,
14900 + .direct_IO = aufs_direct_IO,
14901 +#ifdef CONFIG_AUFS_DEBUG
14902 + .writepage = aufs_writepage,
14903 + /* no writepages, because of writepage */
14904 + .set_page_dirty = aufs_set_page_dirty,
14905 + /* no readpages, because of readpage */
14906 + .write_begin = aufs_write_begin,
14907 + .write_end = aufs_write_end,
14908 + /* no bmap, no block device */
14909 + .invalidatepage = aufs_invalidatepage,
14910 + .releasepage = aufs_releasepage,
14911 + /* is fallback_migrate_page ok? */
14912 + /* .migratepage = aufs_migratepage, */
14913 + .isolate_page = aufs_isolate_page,
14914 + .putback_page = aufs_putback_page,
14915 + .launder_page = aufs_launder_page,
14916 + .is_partially_uptodate = aufs_is_partially_uptodate,
14917 + .is_dirty_writeback = aufs_is_dirty_writeback,
14918 + .error_remove_page = aufs_error_remove_page,
14919 + .swap_activate = aufs_swap_activate,
14920 + .swap_deactivate = aufs_swap_deactivate
14921 +#endif /* CONFIG_AUFS_DEBUG */
14923 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14924 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14925 +++ linux/fs/aufs/file.h 2021-12-03 15:38:59.936647310 +0100
14927 +/* SPDX-License-Identifier: GPL-2.0 */
14929 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14931 + * This program, aufs is free software; you can redistribute it and/or modify
14932 + * it under the terms of the GNU General Public License as published by
14933 + * the Free Software Foundation; either version 2 of the License, or
14934 + * (at your option) any later version.
14936 + * This program is distributed in the hope that it will be useful,
14937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14939 + * GNU General Public License for more details.
14941 + * You should have received a copy of the GNU General Public License
14942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14946 + * file operations
14949 +#ifndef __AUFS_FILE_H__
14950 +#define __AUFS_FILE_H__
14954 +#include <linux/file.h>
14955 +#include <linux/fs.h>
14956 +#include <linux/mm_types.h>
14957 +#include <linux/poll.h>
14958 +#include "rwsem.h"
14962 + struct file *hf_file;
14963 + struct au_branch *hf_br;
14968 + aufs_bindex_t fd_bbot;
14969 + aufs_bindex_t fd_nent;
14970 + struct au_vdir *fd_vdir_cache;
14971 + struct au_hfile fd_hfile[];
14974 +static inline int au_fidir_sz(int nent)
14976 + AuDebugOn(nent < 0);
14977 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14981 + atomic_t fi_generation;
14983 + struct au_rwsem fi_rwsem;
14984 + aufs_bindex_t fi_btop;
14986 + /* do not union them */
14987 + struct { /* for non-dir */
14988 + struct au_hfile fi_htop;
14989 + atomic_t fi_mmapped;
14991 + struct au_fidir *fi_hdir; /* for dir only */
14993 + struct hlist_bl_node fi_hlist;
14994 + struct file *fi_file; /* very ugly */
14995 + struct rcu_head rcu;
14996 +} ____cacheline_aligned_in_smp;
14998 +/* ---------------------------------------------------------------------- */
15001 +extern const struct address_space_operations aufs_aop;
15002 +unsigned int au_file_roflags(unsigned int flags);
15003 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15004 + struct file *file, int force_wr);
15005 +struct au_do_open_args {
15007 + int (*open)(struct file *file, int flags,
15008 + struct file *h_file);
15009 + struct au_fidir *fidir;
15010 + struct file *h_file;
15012 +int au_do_open(struct file *file, struct au_do_open_args *args);
15013 +int au_reopen_nondir(struct file *file);
15015 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15016 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15017 + int wlock, unsigned int fi_lsc);
15018 +int au_do_flush(struct file *file, fl_owner_t id,
15019 + int (*flush)(struct file *file, fl_owner_t id));
15022 +#ifdef CONFIG_AUFS_POLL
15023 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15026 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15028 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15030 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15031 + struct file *h_file);
15033 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15034 + aufs_bindex_t bindex, int force_wr)
15035 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15036 + struct file *h_file);
15040 +extern const struct file_operations aufs_file_fop;
15041 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15042 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15043 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15046 +void au_hfput(struct au_hfile *hf, int execed);
15047 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15048 + struct file *h_file);
15050 +void au_update_figen(struct file *file);
15051 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15052 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15054 +void au_fi_init_once(void *_fi);
15055 +void au_finfo_fin(struct file *file);
15056 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15059 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15060 +#ifdef CONFIG_COMPAT
15061 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15062 + unsigned long arg);
15063 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15064 + unsigned long arg);
15067 +/* ---------------------------------------------------------------------- */
15069 +static inline struct au_finfo *au_fi(struct file *file)
15071 + return file->private_data;
15074 +/* ---------------------------------------------------------------------- */
15076 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15077 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15078 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15079 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15081 +#define fi_read_trylock_nested(f) \
15082 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15083 +#define fi_write_trylock_nested(f) \
15084 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15087 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15088 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15089 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15091 +/* lock subclass for finfo */
15097 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15099 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15102 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15104 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15108 + * fi_read_lock_1, fi_write_lock_1,
15109 + * fi_read_lock_2, fi_write_lock_2
15111 +#define AuReadLockFunc(name) \
15112 +static inline void fi_read_lock_##name(struct file *f) \
15113 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15115 +#define AuWriteLockFunc(name) \
15116 +static inline void fi_write_lock_##name(struct file *f) \
15117 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15119 +#define AuRWLockFuncs(name) \
15120 + AuReadLockFunc(name) \
15121 + AuWriteLockFunc(name)
15126 +#undef AuReadLockFunc
15127 +#undef AuWriteLockFunc
15128 +#undef AuRWLockFuncs
15130 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15131 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15132 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15134 +/* ---------------------------------------------------------------------- */
15136 +/* todo: hard/soft set? */
15137 +static inline aufs_bindex_t au_fbtop(struct file *file)
15139 + FiMustAnyLock(file);
15140 + return au_fi(file)->fi_btop;
15143 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15145 + FiMustAnyLock(file);
15146 + AuDebugOn(!au_fi(file)->fi_hdir);
15147 + return au_fi(file)->fi_hdir->fd_bbot;
15150 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15152 + FiMustAnyLock(file);
15153 + AuDebugOn(!au_fi(file)->fi_hdir);
15154 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15157 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15159 + FiMustWriteLock(file);
15160 + au_fi(file)->fi_btop = bindex;
15163 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15165 + FiMustWriteLock(file);
15166 + AuDebugOn(!au_fi(file)->fi_hdir);
15167 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15170 +static inline void au_set_fvdir_cache(struct file *file,
15171 + struct au_vdir *vdir_cache)
15173 + FiMustWriteLock(file);
15174 + AuDebugOn(!au_fi(file)->fi_hdir);
15175 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15178 +static inline struct file *au_hf_top(struct file *file)
15180 + FiMustAnyLock(file);
15181 + AuDebugOn(au_fi(file)->fi_hdir);
15182 + return au_fi(file)->fi_htop.hf_file;
15185 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15187 + FiMustAnyLock(file);
15188 + AuDebugOn(!au_fi(file)->fi_hdir);
15189 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15192 +/* todo: memory barrier? */
15193 +static inline unsigned int au_figen(struct file *f)
15195 + return atomic_read(&au_fi(f)->fi_generation);
15198 +static inline void au_set_mmapped(struct file *f)
15200 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15202 + pr_warn("fi_mmapped wrapped around\n");
15203 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15207 +static inline void au_unset_mmapped(struct file *f)
15209 + atomic_dec(&au_fi(f)->fi_mmapped);
15212 +static inline int au_test_mmapped(struct file *f)
15214 + return atomic_read(&au_fi(f)->fi_mmapped);
15217 +/* customize vma->vm_file */
15219 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15220 + struct file *file)
15224 + f = vma->vm_file;
15226 + vma->vm_file = file;
15231 +#define AuDbgVmRegion(file, vma) do {} while (0)
15233 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15234 + struct file *file)
15236 + au_do_vm_file_reset(vma, file);
15239 +#define AuDbgVmRegion(file, vma) \
15240 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15242 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15243 + struct file *file)
15247 + au_do_vm_file_reset(vma, file);
15248 + f = vma->vm_region->vm_file;
15250 + vma->vm_region->vm_file = file;
15253 +#endif /* CONFIG_MMU */
15255 +/* handle vma->vm_prfile */
15256 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15257 + struct file *file)
15260 + vma->vm_prfile = file;
15261 +#ifndef CONFIG_MMU
15263 + vma->vm_region->vm_prfile = file;
15267 +#endif /* __KERNEL__ */
15268 +#endif /* __AUFS_FILE_H__ */
15269 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15270 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15271 +++ linux/fs/aufs/finfo.c 2021-12-03 15:38:59.936647310 +0100
15273 +// SPDX-License-Identifier: GPL-2.0
15275 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15277 + * This program, aufs is free software; you can redistribute it and/or modify
15278 + * it under the terms of the GNU General Public License as published by
15279 + * the Free Software Foundation; either version 2 of the License, or
15280 + * (at your option) any later version.
15282 + * This program is distributed in the hope that it will be useful,
15283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15285 + * GNU General Public License for more details.
15287 + * You should have received a copy of the GNU General Public License
15288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15292 + * file private data
15297 +void au_hfput(struct au_hfile *hf, int execed)
15300 + allow_write_access(hf->hf_file);
15301 + fput(hf->hf_file);
15302 + hf->hf_file = NULL;
15303 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15304 + hf->hf_br = NULL;
15307 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15309 + struct au_finfo *finfo = au_fi(file);
15310 + struct au_hfile *hf;
15311 + struct au_fidir *fidir;
15313 + fidir = finfo->fi_hdir;
15315 + AuDebugOn(finfo->fi_btop != bindex);
15316 + hf = &finfo->fi_htop;
15318 + hf = fidir->fd_hfile + bindex;
15320 + if (hf && hf->hf_file)
15321 + au_hfput(hf, vfsub_file_execed(file));
15323 + FiMustWriteLock(file);
15324 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15325 + hf->hf_file = val;
15326 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15330 +void au_update_figen(struct file *file)
15332 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15333 + /* smp_mb(); */ /* atomic_set */
15336 +/* ---------------------------------------------------------------------- */
15338 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15340 + struct au_fidir *fidir;
15343 + nbr = au_sbbot(sb) + 1;
15345 + nbr = 2; /* initial allocate for 2 branches */
15346 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15348 + fidir->fd_bbot = -1;
15349 + fidir->fd_nent = nbr;
15355 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15358 + struct au_fidir *fidir, *p;
15360 + AuRwMustWriteLock(&finfo->fi_rwsem);
15361 + fidir = finfo->fi_hdir;
15362 + AuDebugOn(!fidir);
15365 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15366 + GFP_NOFS, may_shrink);
15368 + p->fd_nent = nbr;
15369 + finfo->fi_hdir = p;
15376 +/* ---------------------------------------------------------------------- */
15378 +void au_finfo_fin(struct file *file)
15380 + struct au_finfo *finfo;
15382 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15384 + finfo = au_fi(file);
15385 + AuDebugOn(finfo->fi_hdir);
15386 + AuRwDestroy(&finfo->fi_rwsem);
15387 + au_cache_free_finfo(finfo);
15390 +void au_fi_init_once(void *_finfo)
15392 + struct au_finfo *finfo = _finfo;
15394 + au_rw_init(&finfo->fi_rwsem);
15397 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15400 + struct au_finfo *finfo;
15401 + struct dentry *dentry;
15404 + dentry = file->f_path.dentry;
15405 + finfo = au_cache_alloc_finfo();
15406 + if (unlikely(!finfo))
15410 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15411 + au_rw_write_lock(&finfo->fi_rwsem);
15412 + finfo->fi_btop = -1;
15413 + finfo->fi_hdir = fidir;
15414 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15415 + /* smp_mb(); */ /* atomic_set */
15417 + file->private_data = finfo;
15422 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15423 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15424 +++ linux/fs/aufs/f_op.c 2021-12-03 15:38:59.933313976 +0100
15426 +// SPDX-License-Identifier: GPL-2.0
15428 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15430 + * This program, aufs is free software; you can redistribute it and/or modify
15431 + * it under the terms of the GNU General Public License as published by
15432 + * the Free Software Foundation; either version 2 of the License, or
15433 + * (at your option) any later version.
15435 + * This program is distributed in the hope that it will be useful,
15436 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15437 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15438 + * GNU General Public License for more details.
15440 + * You should have received a copy of the GNU General Public License
15441 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15445 + * file and vm operations
15448 +#include <linux/aio.h>
15449 +#include <linux/fs_stack.h>
15450 +#include <linux/mman.h>
15451 +#include <linux/security.h>
15454 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15457 + aufs_bindex_t bindex;
15458 + struct dentry *dentry, *h_dentry;
15459 + struct au_finfo *finfo;
15460 + struct inode *h_inode;
15462 + FiMustWriteLock(file);
15465 + dentry = file->f_path.dentry;
15466 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15467 + finfo = au_fi(file);
15468 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15469 + atomic_set(&finfo->fi_mmapped, 0);
15470 + bindex = au_dbtop(dentry);
15472 + h_dentry = au_h_dptr(dentry, bindex);
15473 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15474 + if (unlikely(err))
15476 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15477 + if (IS_ERR(h_file)) {
15478 + err = PTR_ERR(h_file);
15482 + h_dentry = h_file->f_path.dentry;
15483 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15484 + if (unlikely(err))
15486 + /* br ref is already inc-ed */
15489 + if ((flags & __O_TMPFILE)
15490 + && !(flags & O_EXCL)) {
15491 + h_inode = file_inode(h_file);
15492 + spin_lock(&h_inode->i_lock);
15493 + h_inode->i_state |= I_LINKABLE;
15494 + spin_unlock(&h_inode->i_lock);
15496 + au_set_fbtop(file, bindex);
15497 + au_set_h_fptr(file, bindex, h_file);
15498 + au_update_figen(file);
15499 + /* todo: necessary? */
15500 + /* file->f_ra = h_file->f_ra; */
15506 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15507 + struct file *file)
15510 + struct super_block *sb;
15511 + struct au_do_open_args args = {
15512 + .open = au_do_open_nondir
15515 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15516 + file, vfsub_file_flags(file), file->f_mode);
15518 + sb = file->f_path.dentry->d_sb;
15519 + si_read_lock(sb, AuLock_FLUSH);
15520 + err = au_do_open(file, &args);
15521 + si_read_unlock(sb);
15525 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15527 + struct au_finfo *finfo;
15528 + aufs_bindex_t bindex;
15530 + finfo = au_fi(file);
15531 + au_hbl_del(&finfo->fi_hlist,
15532 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15533 + bindex = finfo->fi_btop;
15535 + au_set_h_fptr(file, bindex, NULL);
15537 + au_finfo_fin(file);
15541 +/* ---------------------------------------------------------------------- */
15543 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15546 + struct file *h_file;
15549 + h_file = au_hf_top(file);
15551 + err = vfsub_flush(h_file, id);
15555 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15557 + return au_do_flush(file, id, au_do_flush_nondir);
15560 +/* ---------------------------------------------------------------------- */
15562 + * read and write functions acquire [fdi]_rwsem once, but release before
15563 + * mmap_sem. This is because to stop a race condition between mmap(2).
15564 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15565 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15566 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15569 +/* Callers should call au_read_post() or fput() in the end */
15570 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15572 + struct file *h_file;
15575 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15577 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15578 + h_file = au_hf_top(file);
15579 + get_file(h_file);
15581 + fi_read_unlock(file);
15583 + h_file = ERR_PTR(err);
15588 +static void au_read_post(struct inode *inode, struct file *h_file)
15590 + /* update without lock, I don't think it a problem */
15591 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15595 +struct au_write_pre {
15597 + unsigned int lsc;
15601 + aufs_bindex_t btop;
15605 + * return with iinfo is write-locked
15606 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15609 +static struct file *au_write_pre(struct file *file, int do_ready,
15610 + struct au_write_pre *wpre)
15612 + struct file *h_file;
15613 + struct dentry *dentry;
15615 + unsigned int lsc;
15616 + struct au_pin pin;
15621 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15622 + h_file = ERR_PTR(err);
15623 + if (unlikely(err))
15626 + dentry = file->f_path.dentry;
15628 + err = au_ready_to_write(file, -1, &pin);
15629 + if (unlikely(err)) {
15630 + h_file = ERR_PTR(err);
15631 + di_write_unlock(dentry);
15636 + di_downgrade_lock(dentry, /*flags*/0);
15638 + wpre->btop = au_fbtop(file);
15639 + h_file = au_hf_top(file);
15640 + get_file(h_file);
15642 + wpre->blks = file_inode(h_file)->i_blocks;
15645 + di_read_unlock(dentry, /*flags*/0);
15648 + fi_write_unlock(file);
15653 +static void au_write_post(struct inode *inode, struct file *h_file,
15654 + struct au_write_pre *wpre, ssize_t written)
15656 + struct inode *h_inode;
15658 + au_cpup_attr_timesizes(inode);
15659 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15660 + h_inode = file_inode(h_file);
15661 + inode->i_mode = h_inode->i_mode;
15662 + ii_write_unlock(inode);
15663 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15665 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15666 + /*force*/h_inode->i_blocks > wpre->blks);
15671 + * todo: very ugly
15672 + * it locks both of i_mutex and si_rwsem for read in safe.
15673 + * if the plink maintenance mode continues forever (that is the problem),
15674 + * may loop forever.
15676 +static void au_mtx_and_read_lock(struct inode *inode)
15679 + struct super_block *sb = inode->i_sb;
15682 + inode_lock(inode);
15683 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15686 + inode_unlock(inode);
15687 + si_read_lock(sb, AuLock_NOPLMW);
15688 + si_read_unlock(sb);
15692 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15693 + struct iov_iter *iov_iter)
15696 + struct file *file;
15697 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15699 + err = security_file_permission(h_file, rw);
15700 + if (unlikely(err))
15703 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15705 + if (rw == MAY_READ)
15706 + iter = h_file->f_op->read_iter;
15707 + else if (rw == MAY_WRITE)
15708 + iter = h_file->f_op->write_iter;
15710 + file = kio->ki_filp;
15711 + kio->ki_filp = h_file;
15714 + err = iter(kio, iov_iter);
15717 + /* currently there is no such fs */
15719 + kio->ki_filp = file;
15725 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15728 + struct file *file, *h_file;
15729 + struct inode *inode;
15730 + struct super_block *sb;
15732 + file = kio->ki_filp;
15733 + inode = file_inode(file);
15734 + sb = inode->i_sb;
15735 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15737 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15738 + err = PTR_ERR(h_file);
15739 + if (IS_ERR(h_file))
15742 + if (au_test_loopback_kthread()) {
15743 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15744 + if (file->f_mapping != h_file->f_mapping) {
15745 + file->f_mapping = h_file->f_mapping;
15746 + smp_mb(); /* unnecessary? */
15749 + fi_read_unlock(file);
15751 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15752 + /* todo: necessary? */
15753 + /* file->f_ra = h_file->f_ra; */
15754 + au_read_post(inode, h_file);
15757 + si_read_unlock(sb);
15761 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15764 + struct au_write_pre wpre;
15765 + struct inode *inode;
15766 + struct file *file, *h_file;
15768 + file = kio->ki_filp;
15769 + inode = file_inode(file);
15770 + au_mtx_and_read_lock(inode);
15773 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15774 + err = PTR_ERR(h_file);
15775 + if (IS_ERR(h_file))
15778 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15779 + au_write_post(inode, h_file, &wpre, err);
15782 + si_read_unlock(inode->i_sb);
15783 + inode_unlock(inode);
15788 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15789 + * don't have their own .splice_{read,write} implimentations, and they use
15790 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15791 + * simple converters to f_op->iter_read() and ->iter_write().
15792 + * But we keep our own implementations because some non-mainlined FSes may have
15793 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15794 + * away an opportunity to co-work with aufs from them.
15796 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15797 + struct pipe_inode_info *pipe, size_t len,
15798 + unsigned int flags)
15801 + struct file *h_file;
15802 + struct inode *inode;
15803 + struct super_block *sb;
15805 + inode = file_inode(file);
15806 + sb = inode->i_sb;
15807 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15809 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15810 + err = PTR_ERR(h_file);
15811 + if (IS_ERR(h_file))
15814 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15815 + /* todo: necessary? */
15816 + /* file->f_ra = h_file->f_ra; */
15817 + au_read_post(inode, h_file);
15820 + si_read_unlock(sb);
15825 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15826 + size_t len, unsigned int flags)
15829 + struct au_write_pre wpre;
15830 + struct inode *inode;
15831 + struct file *h_file;
15833 + inode = file_inode(file);
15834 + au_mtx_and_read_lock(inode);
15837 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15838 + err = PTR_ERR(h_file);
15839 + if (IS_ERR(h_file))
15842 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15843 + au_write_post(inode, h_file, &wpre, err);
15846 + si_read_unlock(inode->i_sb);
15847 + inode_unlock(inode);
15851 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15855 + struct au_write_pre wpre;
15856 + struct inode *inode;
15857 + struct file *h_file;
15859 + inode = file_inode(file);
15860 + au_mtx_and_read_lock(inode);
15863 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15864 + err = PTR_ERR(h_file);
15865 + if (IS_ERR(h_file))
15869 + err = vfs_fallocate(h_file, mode, offset, len);
15871 + au_write_post(inode, h_file, &wpre, /*written*/1);
15874 + si_read_unlock(inode->i_sb);
15875 + inode_unlock(inode);
15879 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15880 + struct file *dst, loff_t dst_pos,
15881 + size_t len, unsigned int flags)
15884 + struct au_write_pre wpre;
15885 + enum { SRC, DST };
15887 + struct inode *inode;
15888 + struct file *h_file;
15889 + struct super_block *h_sb;
15891 +#define a_src a[SRC]
15892 +#define a_dst a[DST]
15895 + a_src.inode = file_inode(src);
15896 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15898 + a_dst.inode = file_inode(dst);
15899 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15902 + au_mtx_and_read_lock(a_dst.inode);
15904 + * in order to match the order in di_write_lock2_{child,parent}(),
15905 + * use f_path.dentry for this comparison.
15907 + if (src->f_path.dentry < dst->f_path.dentry) {
15908 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15909 + err = PTR_ERR(a_src.h_file);
15910 + if (IS_ERR(a_src.h_file))
15913 + wpre.lsc = AuLsc_FI_2;
15914 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15915 + err = PTR_ERR(a_dst.h_file);
15916 + if (IS_ERR(a_dst.h_file)) {
15917 + au_read_post(a_src.inode, a_src.h_file);
15921 + wpre.lsc = AuLsc_FI_1;
15922 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15923 + err = PTR_ERR(a_dst.h_file);
15924 + if (IS_ERR(a_dst.h_file))
15927 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15928 + err = PTR_ERR(a_src.h_file);
15929 + if (IS_ERR(a_src.h_file)) {
15930 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15937 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15938 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15939 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15945 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15946 + dst_pos, len, flags);
15949 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15950 + fi_read_unlock(src);
15951 + au_read_post(a_src.inode, a_src.h_file);
15953 + si_read_unlock(a_dst.inode->i_sb);
15954 + inode_unlock(a_dst.inode);
15961 +/* ---------------------------------------------------------------------- */
15964 + * The locking order around current->mmap_sem.
15965 + * - in most and regular cases
15966 + * file I/O syscall -- aufs_read() or something
15967 + * -- si_rwsem for read -- mmap_sem
15968 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15970 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15971 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15972 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15973 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15974 + * It means that when aufs acquires si_rwsem for write, the process should never
15975 + * acquire mmap_sem.
15977 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15978 + * problem either since any directory is not able to be mmap-ed.
15979 + * The similar scenario is applied to aufs_readlink() too.
15982 +#if 0 /* stop calling security_file_mmap() */
15983 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15984 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15986 +static unsigned long au_arch_prot_conv(unsigned long flags)
15988 + /* currently ppc64 only */
15989 +#ifdef CONFIG_PPC64
15990 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15991 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15992 + return AuConv_VM_PROT(flags, SAO);
15994 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15999 +static unsigned long au_prot_conv(unsigned long flags)
16001 + return AuConv_VM_PROT(flags, READ)
16002 + | AuConv_VM_PROT(flags, WRITE)
16003 + | AuConv_VM_PROT(flags, EXEC)
16004 + | au_arch_prot_conv(flags);
16007 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16008 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16010 +static unsigned long au_flag_conv(unsigned long flags)
16012 + return AuConv_VM_MAP(flags, GROWSDOWN)
16013 + | AuConv_VM_MAP(flags, DENYWRITE)
16014 + | AuConv_VM_MAP(flags, LOCKED);
16018 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16021 + const unsigned char wlock
16022 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16023 + struct super_block *sb;
16024 + struct file *h_file;
16025 + struct inode *inode;
16027 + AuDbgVmRegion(file, vma);
16029 + inode = file_inode(file);
16030 + sb = inode->i_sb;
16032 + si_read_lock(sb, AuLock_NOPLMW);
16034 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16036 + err = PTR_ERR(h_file);
16037 + if (IS_ERR(h_file))
16041 + au_set_mmapped(file);
16042 + au_vm_file_reset(vma, h_file);
16044 + * we cannot call security_mmap_file() here since it may acquire
16045 + * mmap_sem or i_mutex.
16047 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16048 + * au_flag_conv(vma->vm_flags));
16051 + err = call_mmap(h_file, vma);
16053 + au_vm_prfile_set(vma, file);
16054 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16055 + goto out_fput; /* success */
16057 + au_unset_mmapped(file);
16058 + au_vm_file_reset(vma, file);
16062 + ii_write_unlock(inode);
16067 + si_read_unlock(sb);
16073 +/* ---------------------------------------------------------------------- */
16075 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16079 + struct au_write_pre wpre;
16080 + struct inode *inode;
16081 + struct file *h_file;
16083 + err = 0; /* -EBADF; */ /* posix? */
16084 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16087 + inode = file_inode(file);
16088 + au_mtx_and_read_lock(inode);
16091 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16092 + err = PTR_ERR(h_file);
16093 + if (IS_ERR(h_file))
16096 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16097 + au_write_post(inode, h_file, &wpre, /*written*/0);
16100 + si_read_unlock(inode->i_sb);
16101 + inode_unlock(inode);
16106 +static int aufs_fasync(int fd, struct file *file, int flag)
16109 + struct file *h_file;
16110 + struct super_block *sb;
16112 + sb = file->f_path.dentry->d_sb;
16113 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16115 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16116 + err = PTR_ERR(h_file);
16117 + if (IS_ERR(h_file))
16120 + if (h_file->f_op->fasync)
16121 + err = h_file->f_op->fasync(fd, h_file, flag);
16122 + fput(h_file); /* instead of au_read_post() */
16125 + si_read_unlock(sb);
16129 +static int aufs_setfl(struct file *file, unsigned long arg)
16132 + struct file *h_file;
16133 + struct super_block *sb;
16135 + sb = file->f_path.dentry->d_sb;
16136 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16138 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16139 + err = PTR_ERR(h_file);
16140 + if (IS_ERR(h_file))
16143 + /* stop calling h_file->fasync */
16144 + arg |= vfsub_file_flags(file) & FASYNC;
16145 + err = setfl(/*unused fd*/-1, h_file, arg);
16146 + fput(h_file); /* instead of au_read_post() */
16149 + si_read_unlock(sb);
16153 +/* ---------------------------------------------------------------------- */
16155 +/* no one supports this operation, currently */
16156 +#if 0 /* reserved for future use */
16157 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16158 + size_t len, loff_t *pos, int more)
16163 +/* ---------------------------------------------------------------------- */
16165 +const struct file_operations aufs_file_fop = {
16166 + .owner = THIS_MODULE,
16168 + .llseek = default_llseek,
16170 + .read_iter = aufs_read_iter,
16171 + .write_iter = aufs_write_iter,
16173 +#ifdef CONFIG_AUFS_POLL
16174 + .poll = aufs_poll,
16176 + .unlocked_ioctl = aufs_ioctl_nondir,
16177 +#ifdef CONFIG_COMPAT
16178 + .compat_ioctl = aufs_compat_ioctl_nondir,
16180 + .mmap = aufs_mmap,
16181 + .open = aufs_open_nondir,
16182 + .flush = aufs_flush_nondir,
16183 + .release = aufs_release_nondir,
16184 + .fsync = aufs_fsync_nondir,
16185 + .fasync = aufs_fasync,
16186 + /* .sendpage = aufs_sendpage, */
16187 + .setfl = aufs_setfl,
16188 + .splice_write = aufs_splice_write,
16189 + .splice_read = aufs_splice_read,
16190 +#if 0 /* reserved for future use */
16191 + .aio_splice_write = aufs_aio_splice_write,
16192 + .aio_splice_read = aufs_aio_splice_read,
16194 + .fallocate = aufs_fallocate,
16195 + .copy_file_range = aufs_copy_file_range
16197 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16198 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16199 +++ linux/fs/aufs/fstype.h 2021-12-03 15:38:59.936647310 +0100
16201 +/* SPDX-License-Identifier: GPL-2.0 */
16203 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16205 + * This program, aufs is free software; you can redistribute it and/or modify
16206 + * it under the terms of the GNU General Public License as published by
16207 + * the Free Software Foundation; either version 2 of the License, or
16208 + * (at your option) any later version.
16210 + * This program is distributed in the hope that it will be useful,
16211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16213 + * GNU General Public License for more details.
16215 + * You should have received a copy of the GNU General Public License
16216 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16220 + * judging filesystem type
16223 +#ifndef __AUFS_FSTYPE_H__
16224 +#define __AUFS_FSTYPE_H__
16228 +#include <linux/fs.h>
16229 +#include <linux/magic.h>
16230 +#include <linux/nfs_fs.h>
16231 +#include <linux/romfs_fs.h>
16233 +static inline int au_test_aufs(struct super_block *sb)
16235 + return sb->s_magic == AUFS_SUPER_MAGIC;
16238 +static inline const char *au_sbtype(struct super_block *sb)
16240 + return sb->s_type->name;
16243 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16245 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16246 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16252 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16254 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16255 + return sb->s_magic == ROMFS_MAGIC;
16261 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16263 +#if IS_ENABLED(CONFIG_CRAMFS)
16264 + return sb->s_magic == CRAMFS_MAGIC;
16269 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16271 +#if IS_ENABLED(CONFIG_NFS_FS)
16272 + return sb->s_magic == NFS_SUPER_MAGIC;
16278 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16280 +#if IS_ENABLED(CONFIG_FUSE_FS)
16281 + return sb->s_magic == FUSE_SUPER_MAGIC;
16287 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16289 +#if IS_ENABLED(CONFIG_XFS_FS)
16290 + return sb->s_magic == XFS_SB_MAGIC;
16296 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16298 +#ifdef CONFIG_TMPFS
16299 + return sb->s_magic == TMPFS_MAGIC;
16305 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16307 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16308 + return !strcmp(au_sbtype(sb), "ecryptfs");
16314 +static inline int au_test_ramfs(struct super_block *sb)
16316 + return sb->s_magic == RAMFS_MAGIC;
16319 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16321 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16322 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16328 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16330 +#ifdef CONFIG_PROC_FS
16331 + return sb->s_magic == PROC_SUPER_MAGIC;
16337 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16339 +#ifdef CONFIG_SYSFS
16340 + return sb->s_magic == SYSFS_MAGIC;
16346 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16348 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16349 + return sb->s_magic == CONFIGFS_MAGIC;
16355 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16357 +#if IS_ENABLED(CONFIG_MINIX_FS)
16358 + return sb->s_magic == MINIX3_SUPER_MAGIC
16359 + || sb->s_magic == MINIX2_SUPER_MAGIC
16360 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16361 + || sb->s_magic == MINIX_SUPER_MAGIC
16362 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16368 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16370 +#if IS_ENABLED(CONFIG_FAT_FS)
16371 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16377 +static inline int au_test_msdos(struct super_block *sb)
16379 + return au_test_fat(sb);
16382 +static inline int au_test_vfat(struct super_block *sb)
16384 + return au_test_fat(sb);
16387 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16389 +#ifdef CONFIG_SECURITYFS
16390 + return sb->s_magic == SECURITYFS_MAGIC;
16396 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16398 +#if IS_ENABLED(CONFIG_SQUASHFS)
16399 + return sb->s_magic == SQUASHFS_MAGIC;
16405 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16407 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16408 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16414 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16416 +#if IS_ENABLED(CONFIG_XENFS)
16417 + return sb->s_magic == XENFS_SUPER_MAGIC;
16423 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16425 +#ifdef CONFIG_DEBUG_FS
16426 + return sb->s_magic == DEBUGFS_MAGIC;
16432 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16434 +#if IS_ENABLED(CONFIG_NILFS)
16435 + return sb->s_magic == NILFS_SUPER_MAGIC;
16441 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16443 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16444 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16450 +/* ---------------------------------------------------------------------- */
16452 + * they can't be an aufs branch.
16454 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16457 +#ifndef CONFIG_AUFS_BR_RAMFS
16458 + au_test_ramfs(sb) ||
16460 + au_test_procfs(sb)
16461 + || au_test_sysfs(sb)
16462 + || au_test_configfs(sb)
16463 + || au_test_debugfs(sb)
16464 + || au_test_securityfs(sb)
16465 + || au_test_xenfs(sb)
16466 + || au_test_ecryptfs(sb)
16467 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16468 + || au_test_aufs(sb); /* will be supported in next version */
16471 +static inline int au_test_fs_remote(struct super_block *sb)
16473 + return !au_test_tmpfs(sb)
16474 +#ifdef CONFIG_AUFS_BR_RAMFS
16475 + && !au_test_ramfs(sb)
16477 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16480 +/* ---------------------------------------------------------------------- */
16483 + * Note: these functions (below) are created after reading ->getattr() in all
16484 + * filesystems under linux/fs. it means we have to do so in every update...
16488 + * some filesystems require getattr to refresh the inode attributes before
16490 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16491 + * and leave the work for d_revalidate()
16493 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16495 + return au_test_nfs(sb)
16496 + || au_test_fuse(sb)
16497 + /* || au_test_btrfs(sb) */ /* untested */
16502 + * filesystems which don't maintain i_size or i_blocks.
16504 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16506 + return au_test_xfs(sb)
16507 + || au_test_btrfs(sb)
16508 + || au_test_ubifs(sb)
16509 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16510 + /* || au_test_minix(sb) */ /* untested */
16515 + * filesystems which don't store the correct value in some of their inode
16518 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16520 + return au_test_fs_bad_iattr_size(sb)
16521 + || au_test_fat(sb)
16522 + || au_test_msdos(sb)
16523 + || au_test_vfat(sb);
16526 +/* they don't check i_nlink in link(2) */
16527 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16529 + return au_test_tmpfs(sb)
16530 +#ifdef CONFIG_AUFS_BR_RAMFS
16531 + || au_test_ramfs(sb)
16533 + || au_test_ubifs(sb)
16534 + || au_test_hfsplus(sb);
16538 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16540 +static inline int au_test_fs_notime(struct super_block *sb)
16542 + return au_test_nfs(sb)
16543 + || au_test_fuse(sb)
16544 + || au_test_ubifs(sb)
16548 +/* temporary support for i#1 in cramfs */
16549 +static inline int au_test_fs_unique_ino(struct inode *inode)
16551 + if (au_test_cramfs(inode->i_sb))
16552 + return inode->i_ino != 1;
16556 +/* ---------------------------------------------------------------------- */
16559 + * the filesystem where the xino files placed must support i/o after unlink and
16560 + * maintain i_size and i_blocks.
16562 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16564 + return au_test_fs_remote(sb)
16565 + || au_test_fs_bad_iattr_size(sb)
16566 + /* don't want unnecessary work for xino */
16567 + || au_test_aufs(sb)
16568 + || au_test_ecryptfs(sb)
16569 + || au_test_nilfs(sb);
16572 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16574 + return au_test_tmpfs(sb)
16575 + || au_test_ramfs(sb);
16579 + * test if the @sb is real-readonly.
16581 +static inline int au_test_fs_rr(struct super_block *sb)
16583 + return au_test_squashfs(sb)
16584 + || au_test_iso9660(sb)
16585 + || au_test_cramfs(sb)
16586 + || au_test_romfs(sb);
16590 + * test if the @inode is nfs with 'noacl' option
16591 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16593 +static inline int au_test_nfs_noacl(struct inode *inode)
16595 + return au_test_nfs(inode->i_sb)
16596 + /* && IS_POSIXACL(inode) */
16597 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16600 +#endif /* __KERNEL__ */
16601 +#endif /* __AUFS_FSTYPE_H__ */
16602 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16603 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16604 +++ linux/fs/aufs/hbl.h 2021-12-03 15:38:59.936647310 +0100
16606 +/* SPDX-License-Identifier: GPL-2.0 */
16608 + * Copyright (C) 2017-2021 Junjiro R. Okajima
16610 + * This program, aufs is free software; you can redistribute it and/or modify
16611 + * it under the terms of the GNU General Public License as published by
16612 + * the Free Software Foundation; either version 2 of the License, or
16613 + * (at your option) any later version.
16615 + * This program is distributed in the hope that it will be useful,
16616 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16617 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16618 + * GNU General Public License for more details.
16620 + * You should have received a copy of the GNU General Public License
16621 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16625 + * helpers for hlist_bl.h
16628 +#ifndef __AUFS_HBL_H__
16629 +#define __AUFS_HBL_H__
16633 +#include <linux/list_bl.h>
16635 +static inline void au_hbl_add(struct hlist_bl_node *node,
16636 + struct hlist_bl_head *hbl)
16638 + hlist_bl_lock(hbl);
16639 + hlist_bl_add_head(node, hbl);
16640 + hlist_bl_unlock(hbl);
16643 +static inline void au_hbl_del(struct hlist_bl_node *node,
16644 + struct hlist_bl_head *hbl)
16646 + hlist_bl_lock(hbl);
16647 + hlist_bl_del(node);
16648 + hlist_bl_unlock(hbl);
16651 +#define au_hbl_for_each(pos, head) \
16652 + for (pos = hlist_bl_first(head); \
16656 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16658 + unsigned long cnt;
16659 + struct hlist_bl_node *pos;
16662 + hlist_bl_lock(hbl);
16663 + au_hbl_for_each(pos, hbl)
16665 + hlist_bl_unlock(hbl);
16669 +#endif /* __KERNEL__ */
16670 +#endif /* __AUFS_HBL_H__ */
16671 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16672 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16673 +++ linux/fs/aufs/hfsnotify.c 2021-12-03 15:38:59.936647310 +0100
16675 +// SPDX-License-Identifier: GPL-2.0
16677 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16679 + * This program, aufs is free software; you can redistribute it and/or modify
16680 + * it under the terms of the GNU General Public License as published by
16681 + * the Free Software Foundation; either version 2 of the License, or
16682 + * (at your option) any later version.
16684 + * This program is distributed in the hope that it will be useful,
16685 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16686 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16687 + * GNU General Public License for more details.
16689 + * You should have received a copy of the GNU General Public License
16690 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16694 + * fsnotify for the lower directories
16699 +/* FS_IN_IGNORED is unnecessary */
16700 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16701 + | FS_CREATE | FS_EVENT_ON_CHILD);
16702 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16703 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16705 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16707 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16709 + /* AuDbg("here\n"); */
16710 + au_cache_free_hnotify(hn);
16711 + smp_mb__before_atomic(); /* for atomic64_dec */
16712 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16713 + wake_up(&au_hfsn_wq);
16716 +static int au_hfsn_alloc(struct au_hinode *hinode)
16719 + struct au_hnotify *hn;
16720 + struct super_block *sb;
16721 + struct au_branch *br;
16722 + struct fsnotify_mark *mark;
16723 + aufs_bindex_t bindex;
16725 + hn = hinode->hi_notify;
16726 + sb = hn->hn_aufs_inode->i_sb;
16727 + bindex = au_br_index(sb, hinode->hi_id);
16728 + br = au_sbr(sb, bindex);
16729 + AuDebugOn(!br->br_hfsn);
16731 + mark = &hn->hn_mark;
16732 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16733 + mark->mask = AuHfsnMask;
16735 + * by udba rename or rmdir, aufs assign a new inode to the known
16736 + * h_inode, so specify 1 to allow dups.
16739 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16745 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16747 + struct fsnotify_mark *mark;
16748 + unsigned long long ull;
16749 + struct fsnotify_group *group;
16751 + ull = atomic64_inc_return(&au_hfsn_ifree);
16754 + mark = &hn->hn_mark;
16755 + spin_lock(&mark->lock);
16756 + group = mark->group;
16757 + fsnotify_get_group(group);
16758 + spin_unlock(&mark->lock);
16760 + fsnotify_destroy_mark(mark, group);
16761 + fsnotify_put_mark(mark);
16762 + fsnotify_put_group(group);
16765 + /* free hn by myself */
16769 +/* ---------------------------------------------------------------------- */
16771 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16773 + struct fsnotify_mark *mark;
16775 + mark = &hinode->hi_notify->hn_mark;
16776 + spin_lock(&mark->lock);
16778 + AuDebugOn(mark->mask & AuHfsnMask);
16779 + mark->mask |= AuHfsnMask;
16781 + AuDebugOn(!(mark->mask & AuHfsnMask));
16782 + mark->mask &= ~AuHfsnMask;
16784 + spin_unlock(&mark->lock);
16785 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16788 +/* ---------------------------------------------------------------------- */
16790 +/* #define AuDbgHnotify */
16791 +#ifdef AuDbgHnotify
16792 +static char *au_hfsn_name(u32 mask)
16794 +#ifdef CONFIG_AUFS_DEBUG
16795 +#define test_ret(flag) \
16797 + if (mask & flag) \
16800 + test_ret(FS_ACCESS);
16801 + test_ret(FS_MODIFY);
16802 + test_ret(FS_ATTRIB);
16803 + test_ret(FS_CLOSE_WRITE);
16804 + test_ret(FS_CLOSE_NOWRITE);
16805 + test_ret(FS_OPEN);
16806 + test_ret(FS_MOVED_FROM);
16807 + test_ret(FS_MOVED_TO);
16808 + test_ret(FS_CREATE);
16809 + test_ret(FS_DELETE);
16810 + test_ret(FS_DELETE_SELF);
16811 + test_ret(FS_MOVE_SELF);
16812 + test_ret(FS_UNMOUNT);
16813 + test_ret(FS_Q_OVERFLOW);
16814 + test_ret(FS_IN_IGNORED);
16815 + test_ret(FS_ISDIR);
16816 + test_ret(FS_IN_ONESHOT);
16817 + test_ret(FS_EVENT_ON_CHILD);
16826 +/* ---------------------------------------------------------------------- */
16828 +static void au_hfsn_free_group(struct fsnotify_group *group)
16830 + struct au_br_hfsnotify *hfsn = group->private;
16832 + /* AuDbg("here\n"); */
16833 + au_kfree_try_rcu(hfsn);
16836 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16837 + u32 mask, const void *data, int data_type,
16838 + struct inode *dir,
16839 + const struct qstr *file_name, u32 cookie,
16840 + struct fsnotify_iter_info *iter_info)
16843 + struct au_hnotify *hnotify;
16844 + struct inode *h_dir, *h_inode;
16845 + struct fsnotify_mark *inode_mark;
16847 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16850 + /* if FS_UNMOUNT happens, there must be another bug */
16851 + AuDebugOn(mask & FS_UNMOUNT);
16852 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16857 +#ifdef AuDbgHnotify
16859 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16860 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16861 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16862 + h_dir->i_ino, mask, au_hfsn_name(mask),
16863 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16864 + /* WARN_ON(1); */
16869 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16870 + AuDebugOn(!inode_mark);
16871 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16872 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16878 +static struct fsnotify_ops au_hfsn_ops = {
16879 + .handle_event = au_hfsn_handle_event,
16880 + .free_group_priv = au_hfsn_free_group,
16881 + .free_mark = au_hfsn_free_mark
16884 +/* ---------------------------------------------------------------------- */
16886 +static void au_hfsn_fin_br(struct au_branch *br)
16888 + struct au_br_hfsnotify *hfsn;
16890 + hfsn = br->br_hfsn;
16893 + fsnotify_put_group(hfsn->hfsn_group);
16898 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16901 + struct fsnotify_group *group;
16902 + struct au_br_hfsnotify *hfsn;
16905 + br->br_hfsn = NULL;
16906 + if (!au_br_hnotifyable(perm))
16910 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16911 + if (unlikely(!hfsn))
16915 + group = fsnotify_alloc_group(&au_hfsn_ops);
16916 + if (IS_ERR(group)) {
16917 + err = PTR_ERR(group);
16918 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16922 + group->private = hfsn;
16923 + hfsn->hfsn_group = group;
16924 + br->br_hfsn = hfsn;
16925 + goto out; /* success */
16928 + au_kfree_try_rcu(hfsn);
16933 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16938 + if (!br->br_hfsn)
16939 + err = au_hfsn_init_br(br, perm);
16944 +/* ---------------------------------------------------------------------- */
16946 +static void au_hfsn_fin(void)
16948 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16949 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16952 +const struct au_hnotify_op au_hnotify_op = {
16953 + .ctl = au_hfsn_ctl,
16954 + .alloc = au_hfsn_alloc,
16955 + .free = au_hfsn_free,
16957 + .fin = au_hfsn_fin,
16959 + .reset_br = au_hfsn_reset_br,
16960 + .fin_br = au_hfsn_fin_br,
16961 + .init_br = au_hfsn_init_br
16963 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16964 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16965 +++ linux/fs/aufs/hfsplus.c 2021-12-03 15:38:59.936647310 +0100
16967 +// SPDX-License-Identifier: GPL-2.0
16969 + * Copyright (C) 2010-2021 Junjiro R. Okajima
16971 + * This program, aufs is free software; you can redistribute it and/or modify
16972 + * it under the terms of the GNU General Public License as published by
16973 + * the Free Software Foundation; either version 2 of the License, or
16974 + * (at your option) any later version.
16976 + * This program is distributed in the hope that it will be useful,
16977 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16978 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16979 + * GNU General Public License for more details.
16981 + * You should have received a copy of the GNU General Public License
16982 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16986 + * special support for filesystems which acquires an inode mutex
16987 + * at final closing a file, eg, hfsplus.
16989 + * This trick is very simple and stupid, just to open the file before really
16990 + * necessary open to tell hfsplus that this is not the final closing.
16991 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16992 + * and au_h_open_post() after releasing it.
16997 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17000 + struct file *h_file;
17001 + struct dentry *h_dentry;
17003 + h_dentry = au_h_dptr(dentry, bindex);
17004 + AuDebugOn(!h_dentry);
17005 + AuDebugOn(d_is_negative(h_dentry));
17008 + if (au_test_hfsplus(h_dentry->d_sb)
17009 + && d_is_reg(h_dentry))
17010 + h_file = au_h_open(dentry, bindex,
17011 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17012 + /*file*/NULL, force_wr);
17016 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17017 + struct file *h_file)
17019 + struct au_branch *br;
17023 + br = au_sbr(dentry->d_sb, bindex);
17024 + au_lcnt_dec(&br->br_nfiles);
17027 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17028 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17029 +++ linux/fs/aufs/hnotify.c 2021-12-03 15:38:59.936647310 +0100
17031 +// SPDX-License-Identifier: GPL-2.0
17033 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17035 + * This program, aufs is free software; you can redistribute it and/or modify
17036 + * it under the terms of the GNU General Public License as published by
17037 + * the Free Software Foundation; either version 2 of the License, or
17038 + * (at your option) any later version.
17040 + * This program is distributed in the hope that it will be useful,
17041 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17042 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17043 + * GNU General Public License for more details.
17045 + * You should have received a copy of the GNU General Public License
17046 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17050 + * abstraction to notify the direct changes on lower directories
17053 +/* #include <linux/iversion.h> */
17056 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17059 + struct au_hnotify *hn;
17062 + hn = au_cache_alloc_hnotify();
17064 + hn->hn_aufs_inode = inode;
17065 + hinode->hi_notify = hn;
17066 + err = au_hnotify_op.alloc(hinode);
17068 + if (unlikely(err)) {
17069 + hinode->hi_notify = NULL;
17070 + au_cache_free_hnotify(hn);
17072 + * The upper dir was removed by udba, but the same named
17073 + * dir left. In this case, aufs assigns a new inode
17074 + * number and set the monitor again.
17075 + * For the lower dir, the old monitor is still left.
17077 + if (err == -EEXIST)
17086 +void au_hn_free(struct au_hinode *hinode)
17088 + struct au_hnotify *hn;
17090 + hn = hinode->hi_notify;
17092 + hinode->hi_notify = NULL;
17093 + if (au_hnotify_op.free(hinode, hn))
17094 + au_cache_free_hnotify(hn);
17098 +/* ---------------------------------------------------------------------- */
17100 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17102 + if (hinode->hi_notify)
17103 + au_hnotify_op.ctl(hinode, do_set);
17106 +void au_hn_reset(struct inode *inode, unsigned int flags)
17108 + aufs_bindex_t bindex, bbot;
17109 + struct inode *hi;
17110 + struct dentry *iwhdentry;
17112 + bbot = au_ibbot(inode);
17113 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17114 + hi = au_h_iptr(inode, bindex);
17118 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17119 + iwhdentry = au_hi_wh(inode, bindex);
17123 + au_set_h_iptr(inode, bindex, NULL, 0);
17124 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17125 + flags & ~AuHi_XINO);
17128 + /* inode_unlock(hi); */
17132 +/* ---------------------------------------------------------------------- */
17134 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17137 + aufs_bindex_t bindex, bbot, bfound, btop;
17138 + struct inode *h_i;
17141 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17142 + pr_warn("branch root dir was changed\n");
17147 + bbot = au_ibbot(inode);
17148 + btop = au_ibtop(inode);
17149 +#if 0 /* reserved for future use */
17150 + if (bindex == bbot) {
17151 + /* keep this ino in rename case */
17155 + for (bindex = btop; bindex <= bbot; bindex++)
17156 + if (au_h_iptr(inode, bindex) == h_inode) {
17163 + for (bindex = btop; bindex <= bbot; bindex++) {
17164 + h_i = au_h_iptr(inode, bindex);
17168 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17169 + /* ignore this error */
17170 + /* bad action? */
17173 + /* children inode number will be broken */
17180 +static int hn_gen_tree(struct dentry *dentry)
17182 + int err, i, j, ndentry;
17183 + struct au_dcsub_pages dpages;
17184 + struct au_dpage *dpage;
17185 + struct dentry **dentries;
17187 + err = au_dpages_init(&dpages, GFP_NOFS);
17188 + if (unlikely(err))
17190 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17191 + if (unlikely(err))
17194 + for (i = 0; i < dpages.ndpage; i++) {
17195 + dpage = dpages.dpages + i;
17196 + dentries = dpage->dentries;
17197 + ndentry = dpage->ndentry;
17198 + for (j = 0; j < ndentry; j++) {
17199 + struct dentry *d;
17206 + if (d_really_is_positive(d))
17207 + /* todo: reset children xino?
17208 + cached children only? */
17209 + au_iigen_dec(d_inode(d));
17214 + au_dpages_free(&dpages);
17220 + * return 0 if processed.
17222 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17223 + const unsigned int isdir)
17226 + struct dentry *d;
17227 + struct qstr *dname;
17230 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17231 + pr_warn("branch root dir was changed\n");
17237 + AuDebugOn(!name);
17238 + au_iigen_dec(inode);
17239 + spin_lock(&inode->i_lock);
17240 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17241 + spin_lock(&d->d_lock);
17242 + dname = &d->d_name;
17243 + if (dname->len != nlen
17244 + && memcmp(dname->name, name, nlen)) {
17245 + spin_unlock(&d->d_lock);
17250 + spin_unlock(&d->d_lock);
17253 + spin_unlock(&inode->i_lock);
17255 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17256 + d = d_find_any_alias(inode);
17258 + au_iigen_dec(inode);
17262 + spin_lock(&d->d_lock);
17263 + dname = &d->d_name;
17264 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17265 + spin_unlock(&d->d_lock);
17266 + err = hn_gen_tree(d);
17267 + spin_lock(&d->d_lock);
17269 + spin_unlock(&d->d_lock);
17278 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17282 + if (IS_ROOT(dentry)) {
17283 + pr_warn("branch root dir was changed\n");
17289 + au_digen_dec(dentry);
17290 + if (d_really_is_positive(dentry))
17291 + au_iigen_dec(d_inode(dentry));
17293 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17294 + if (d_really_is_positive(dentry))
17295 + err = hn_gen_tree(dentry);
17302 +/* ---------------------------------------------------------------------- */
17304 +/* hnotify job flags */
17305 +#define AuHnJob_XINO0 1
17306 +#define AuHnJob_GEN (1 << 1)
17307 +#define AuHnJob_DIRENT (1 << 2)
17308 +#define AuHnJob_ISDIR (1 << 3)
17309 +#define AuHnJob_TRYXINO0 (1 << 4)
17310 +#define AuHnJob_MNTPNT (1 << 5)
17311 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17312 +#define au_fset_hnjob(flags, name) \
17313 + do { (flags) |= AuHnJob_##name; } while (0)
17314 +#define au_fclr_hnjob(flags, name) \
17315 + do { (flags) &= ~AuHnJob_##name; } while (0)
17323 +struct au_hnotify_args {
17324 + struct inode *h_dir, *dir, *h_child_inode;
17326 + unsigned int flags[AuHnLast];
17327 + unsigned int h_child_nlen;
17328 + char h_child_name[];
17331 +struct hn_job_args {
17332 + unsigned int flags;
17333 + struct inode *inode, *h_inode, *dir, *h_dir;
17334 + struct dentry *dentry;
17339 +static int hn_job(struct hn_job_args *a)
17341 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17345 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17346 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17348 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17351 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17352 + if (!a->h_inode->i_nlink
17353 + && !(a->h_inode->i_state & I_LINKABLE))
17354 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17355 + inode_unlock_shared(a->h_inode);
17358 + /* make the generation obsolete */
17359 + if (au_ftest_hnjob(a->flags, GEN)) {
17362 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17364 + if (e && a->dentry)
17365 + hn_gen_by_name(a->dentry, isdir);
17366 + /* ignore this error */
17369 + /* make dir entries obsolete */
17370 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17371 + struct au_vdir *vdir;
17373 + vdir = au_ivdir(a->inode);
17375 + vdir->vd_jiffy = 0;
17376 + /* IMustLock(a->inode); */
17377 + /* inode_inc_iversion(a->inode); */
17380 + /* can do nothing but warn */
17381 + if (au_ftest_hnjob(a->flags, MNTPNT)
17383 + && d_mountpoint(a->dentry))
17384 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17389 +/* ---------------------------------------------------------------------- */
17391 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17392 + struct inode *dir)
17394 + struct dentry *dentry, *d, *parent;
17395 + struct qstr *dname;
17397 + parent = d_find_any_alias(dir);
17402 + spin_lock(&parent->d_lock);
17403 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17404 + /* AuDbg("%pd\n", d); */
17405 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17406 + dname = &d->d_name;
17407 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17408 + goto cont_unlock;
17412 + goto cont_unlock;
17413 + if (au_dcount(d) > 0) {
17414 + dentry = dget_dlock(d);
17415 + spin_unlock(&d->d_lock);
17420 + spin_unlock(&d->d_lock);
17422 + spin_unlock(&parent->d_lock);
17426 + di_write_lock_child(dentry);
17431 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17432 + aufs_bindex_t bindex, ino_t h_ino)
17434 + struct inode *inode;
17439 + err = au_xino_read(sb, bindex, h_ino, &ino);
17441 + inode = ilookup(sb, ino);
17445 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17446 + pr_warn("wrong root branch\n");
17452 + ii_write_lock_child(inode);
17458 +static void au_hn_bh(void *_args)
17460 + struct au_hnotify_args *a = _args;
17461 + struct super_block *sb;
17462 + aufs_bindex_t bindex, bbot, bfound;
17463 + unsigned char xino, try_iput;
17465 + struct inode *inode;
17467 + struct hn_job_args args;
17468 + struct dentry *dentry;
17469 + struct au_sbinfo *sbinfo;
17471 + AuDebugOn(!_args);
17472 + AuDebugOn(!a->h_dir);
17473 + AuDebugOn(!a->dir);
17474 + AuDebugOn(!a->mask);
17475 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17476 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17477 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17482 + * do not lock a->dir->i_mutex here
17483 + * because of d_revalidate() may cause a deadlock.
17485 + sb = a->dir->i_sb;
17487 + sbinfo = au_sbi(sb);
17488 + AuDebugOn(!sbinfo);
17489 + si_write_lock(sb, AuLock_NOPLMW);
17491 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17492 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17493 + case FS_MOVED_FROM:
17494 + case FS_MOVED_TO:
17495 + AuWarn1("DIRREN with UDBA may not work correctly "
17496 + "for the direct rename(2)\n");
17499 + ii_read_lock_parent(a->dir);
17501 + bbot = au_ibbot(a->dir);
17502 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17503 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17507 + ii_read_unlock(a->dir);
17508 + if (unlikely(bfound < 0))
17511 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17513 + if (a->h_child_inode)
17514 + h_ino = a->h_child_inode->i_ino;
17516 + if (a->h_child_nlen
17517 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17518 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17519 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17522 + if (dentry && d_really_is_positive(dentry))
17523 + inode = d_inode(dentry);
17524 + if (xino && !inode && h_ino
17525 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17526 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17527 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17528 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17532 + args.flags = a->flags[AuHn_CHILD];
17533 + args.dentry = dentry;
17534 + args.inode = inode;
17535 + args.h_inode = a->h_child_inode;
17536 + args.dir = a->dir;
17537 + args.h_dir = a->h_dir;
17538 + args.h_name = a->h_child_name;
17539 + args.h_nlen = a->h_child_nlen;
17540 + err = hn_job(&args);
17542 + if (au_di(dentry))
17543 + di_write_unlock(dentry);
17546 + if (inode && try_iput) {
17547 + ii_write_unlock(inode);
17551 + ii_write_lock_parent(a->dir);
17552 + args.flags = a->flags[AuHn_PARENT];
17553 + args.dentry = NULL;
17554 + args.inode = a->dir;
17555 + args.h_inode = a->h_dir;
17557 + args.h_dir = NULL;
17558 + args.h_name = NULL;
17560 + err = hn_job(&args);
17561 + ii_write_unlock(a->dir);
17564 + iput(a->h_child_inode);
17567 + si_write_unlock(sb);
17568 + au_nwt_done(&sbinfo->si_nowait);
17572 +/* ---------------------------------------------------------------------- */
17574 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17575 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17578 + unsigned int flags[AuHnLast], f;
17579 + unsigned char isdir, isroot, wh;
17580 + struct inode *dir;
17581 + struct au_hnotify_args *args;
17582 + char *p, *h_child_name;
17585 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17586 + dir = igrab(hnotify->hn_aufs_inode);
17590 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17592 + h_child_name = (void *)h_child_qstr->name;
17593 + len = h_child_qstr->len;
17594 + if (h_child_name) {
17595 + if (len > AUFS_WH_PFX_LEN
17596 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17597 + h_child_name += AUFS_WH_PFX_LEN;
17598 + len -= AUFS_WH_PFX_LEN;
17604 + if (h_child_inode)
17605 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17606 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17607 + flags[AuHn_CHILD] = 0;
17609 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17610 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17611 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17612 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17613 + case FS_MOVED_FROM:
17614 + case FS_MOVED_TO:
17615 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17616 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17619 + AuDebugOn(!h_child_name);
17624 + * aufs never be able to get this child inode.
17625 + * revalidation should be in d_revalidate()
17626 + * by checking i_nlink, i_generation or d_unhashed().
17628 + AuDebugOn(!h_child_name);
17629 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17630 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17638 + h_child_inode = NULL;
17641 + /* iput() and kfree() will be called in au_hnotify() */
17642 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17643 + if (unlikely(!args)) {
17644 + AuErr1("no memory\n");
17648 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17649 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17650 + args->mask = mask;
17652 + args->h_dir = igrab(h_dir);
17653 + if (h_child_inode)
17654 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17655 + args->h_child_inode = h_child_inode;
17656 + args->h_child_nlen = len;
17658 + p = (void *)args;
17659 + p += sizeof(*args);
17660 + memcpy(p, h_child_name, len);
17664 + /* NFS fires the event for silly-renamed one from kworker */
17666 + if (!dir->i_nlink
17667 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17669 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17670 + if (unlikely(err)) {
17671 + pr_err("wkq %d\n", err);
17672 + iput(args->h_child_inode);
17673 + iput(args->h_dir);
17675 + au_kfree_rcu(args);
17682 +/* ---------------------------------------------------------------------- */
17684 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17688 + AuDebugOn(!(udba & AuOptMask_UDBA));
17691 + if (au_hnotify_op.reset_br)
17692 + err = au_hnotify_op.reset_br(udba, br, perm);
17697 +int au_hnotify_init_br(struct au_branch *br, int perm)
17702 + if (au_hnotify_op.init_br)
17703 + err = au_hnotify_op.init_br(br, perm);
17708 +void au_hnotify_fin_br(struct au_branch *br)
17710 + if (au_hnotify_op.fin_br)
17711 + au_hnotify_op.fin_br(br);
17714 +static void au_hn_destroy_cache(void)
17716 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17717 + au_cache[AuCache_HNOTIFY] = NULL;
17720 +int __init au_hnotify_init(void)
17725 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17726 + if (au_cache[AuCache_HNOTIFY]) {
17728 + if (au_hnotify_op.init)
17729 + err = au_hnotify_op.init();
17730 + if (unlikely(err))
17731 + au_hn_destroy_cache();
17737 +void au_hnotify_fin(void)
17739 + if (au_hnotify_op.fin)
17740 + au_hnotify_op.fin();
17742 + /* cf. au_cache_fin() */
17743 + if (au_cache[AuCache_HNOTIFY])
17744 + au_hn_destroy_cache();
17746 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17747 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17748 +++ linux/fs/aufs/iinfo.c 2021-12-03 15:38:59.936647310 +0100
17750 +// SPDX-License-Identifier: GPL-2.0
17752 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17754 + * This program, aufs is free software; you can redistribute it and/or modify
17755 + * it under the terms of the GNU General Public License as published by
17756 + * the Free Software Foundation; either version 2 of the License, or
17757 + * (at your option) any later version.
17759 + * This program is distributed in the hope that it will be useful,
17760 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17761 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17762 + * GNU General Public License for more details.
17764 + * You should have received a copy of the GNU General Public License
17765 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17769 + * inode private data
17774 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17776 + struct inode *h_inode;
17777 + struct au_hinode *hinode;
17779 + IiMustAnyLock(inode);
17781 + hinode = au_hinode(au_ii(inode), bindex);
17782 + h_inode = hinode->hi_inode;
17783 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17787 +/* todo: hard/soft set? */
17788 +void au_hiput(struct au_hinode *hinode)
17790 + au_hn_free(hinode);
17791 + dput(hinode->hi_whdentry);
17792 + iput(hinode->hi_inode);
17795 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17797 + unsigned int flags;
17798 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17801 + if (au_opt_test(mnt_flags, XINO))
17802 + au_fset_hi(flags, XINO);
17803 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17804 + au_fset_hi(flags, HNOTIFY);
17808 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17809 + struct inode *h_inode, unsigned int flags)
17811 + struct au_hinode *hinode;
17812 + struct inode *hi;
17813 + struct au_iinfo *iinfo = au_ii(inode);
17815 + IiMustWriteLock(inode);
17817 + hinode = au_hinode(iinfo, bindex);
17818 + hi = hinode->hi_inode;
17819 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17822 + au_hiput(hinode);
17823 + hinode->hi_inode = h_inode;
17826 + struct super_block *sb = inode->i_sb;
17827 + struct au_branch *br;
17829 + AuDebugOn(inode->i_mode
17830 + && (h_inode->i_mode & S_IFMT)
17831 + != (inode->i_mode & S_IFMT));
17832 + if (bindex == iinfo->ii_btop)
17833 + au_cpup_igen(inode, h_inode);
17834 + br = au_sbr(sb, bindex);
17835 + hinode->hi_id = br->br_id;
17836 + if (au_ftest_hi(flags, XINO)) {
17837 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17839 + if (unlikely(err))
17840 + AuIOErr1("failed au_xino_write() %d\n", err);
17843 + if (au_ftest_hi(flags, HNOTIFY)
17844 + && au_br_hnotifyable(br->br_perm)) {
17845 + err = au_hn_alloc(hinode, inode);
17846 + if (unlikely(err))
17847 + AuIOErr1("au_hn_alloc() %d\n", err);
17852 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17853 + struct dentry *h_wh)
17855 + struct au_hinode *hinode;
17857 + IiMustWriteLock(inode);
17859 + hinode = au_hinode(au_ii(inode), bindex);
17860 + AuDebugOn(hinode->hi_whdentry);
17861 + hinode->hi_whdentry = h_wh;
17864 +void au_update_iigen(struct inode *inode, int half)
17866 + struct au_iinfo *iinfo;
17867 + struct au_iigen *iigen;
17868 + unsigned int sigen;
17870 + sigen = au_sigen(inode->i_sb);
17871 + iinfo = au_ii(inode);
17872 + iigen = &iinfo->ii_generation;
17873 + spin_lock(&iigen->ig_spin);
17874 + iigen->ig_generation = sigen;
17876 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17878 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17879 + spin_unlock(&iigen->ig_spin);
17882 +/* it may be called at remount time, too */
17883 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17885 + struct au_iinfo *iinfo;
17886 + aufs_bindex_t bindex, bbot;
17888 + AuDebugOn(au_is_bad_inode(inode));
17889 + IiMustWriteLock(inode);
17891 + iinfo = au_ii(inode);
17892 + if (do_put_zero && iinfo->ii_btop >= 0) {
17893 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17895 + struct inode *h_i;
17897 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17900 + && !(h_i->i_state & I_LINKABLE))
17901 + au_set_h_iptr(inode, bindex, NULL, 0);
17905 + iinfo->ii_btop = -1;
17906 + iinfo->ii_bbot = -1;
17907 + bbot = au_sbbot(inode->i_sb);
17908 + for (bindex = 0; bindex <= bbot; bindex++)
17909 + if (au_hinode(iinfo, bindex)->hi_inode) {
17910 + iinfo->ii_btop = bindex;
17913 + if (iinfo->ii_btop >= 0)
17914 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17915 + if (au_hinode(iinfo, bindex)->hi_inode) {
17916 + iinfo->ii_bbot = bindex;
17919 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17922 +/* ---------------------------------------------------------------------- */
17924 +void au_icntnr_init_once(void *_c)
17926 + struct au_icntnr *c = _c;
17927 + struct au_iinfo *iinfo = &c->iinfo;
17929 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17930 + au_rw_init(&iinfo->ii_rwsem);
17931 + inode_init_once(&c->vfs_inode);
17934 +void au_hinode_init(struct au_hinode *hinode)
17936 + hinode->hi_inode = NULL;
17937 + hinode->hi_id = -1;
17938 + au_hn_init(hinode);
17939 + hinode->hi_whdentry = NULL;
17942 +int au_iinfo_init(struct inode *inode)
17944 + struct au_iinfo *iinfo;
17945 + struct super_block *sb;
17946 + struct au_hinode *hi;
17949 + sb = inode->i_sb;
17950 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17951 + nbr = au_sbbot(sb) + 1;
17952 + if (unlikely(nbr <= 0))
17954 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17956 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17958 + iinfo->ii_hinode = hi;
17959 + for (i = 0; i < nbr; i++, hi++)
17960 + au_hinode_init(hi);
17962 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17963 + iinfo->ii_btop = -1;
17964 + iinfo->ii_bbot = -1;
17965 + iinfo->ii_vdir = NULL;
17971 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17974 + struct au_hinode *hip;
17976 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17979 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17982 + iinfo->ii_hinode = hip;
17983 + i = iinfo->ii_bbot + 1;
17985 + for (; i < nbr; i++, hip++)
17986 + au_hinode_init(hip);
17993 +void au_iinfo_fin(struct inode *inode)
17995 + struct au_iinfo *iinfo;
17996 + struct au_hinode *hi;
17997 + struct super_block *sb;
17998 + aufs_bindex_t bindex, bbot;
17999 + const unsigned char unlinked = !inode->i_nlink;
18001 + AuDebugOn(au_is_bad_inode(inode));
18003 + sb = inode->i_sb;
18004 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18005 + if (si_pid_test(sb))
18006 + au_xino_delete_inode(inode, unlinked);
18009 + * it is safe to hide the dependency between sbinfo and
18013 + si_noflush_read_lock(sb);
18014 + au_xino_delete_inode(inode, unlinked);
18015 + si_read_unlock(sb);
18019 + iinfo = au_ii(inode);
18020 + if (iinfo->ii_vdir)
18021 + au_vdir_free(iinfo->ii_vdir);
18023 + bindex = iinfo->ii_btop;
18024 + if (bindex >= 0) {
18025 + hi = au_hinode(iinfo, bindex);
18026 + bbot = iinfo->ii_bbot;
18027 + while (bindex++ <= bbot) {
18028 + if (hi->hi_inode)
18033 + au_kfree_rcu(iinfo->ii_hinode);
18034 + AuRwDestroy(&iinfo->ii_rwsem);
18036 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18037 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18038 +++ linux/fs/aufs/inode.c 2021-12-03 15:40:58.236647297 +0100
18040 +// SPDX-License-Identifier: GPL-2.0
18042 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18044 + * This program, aufs is free software; you can redistribute it and/or modify
18045 + * it under the terms of the GNU General Public License as published by
18046 + * the Free Software Foundation; either version 2 of the License, or
18047 + * (at your option) any later version.
18049 + * This program is distributed in the hope that it will be useful,
18050 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18051 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18052 + * GNU General Public License for more details.
18054 + * You should have received a copy of the GNU General Public License
18055 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18059 + * inode functions
18062 +#include <linux/iversion.h>
18065 +struct inode *au_igrab(struct inode *inode)
18068 + AuDebugOn(!atomic_read(&inode->i_count));
18074 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18076 + au_cpup_attr_all(inode, /*force*/0);
18077 + au_update_iigen(inode, /*half*/1);
18079 + inode_inc_iversion(inode);
18082 +static int au_ii_refresh(struct inode *inode, int *update)
18086 + aufs_bindex_t bindex, new_bindex;
18087 + struct super_block *sb;
18088 + struct au_iinfo *iinfo;
18089 + struct au_hinode *p, *q, tmp;
18091 + AuDebugOn(au_is_bad_inode(inode));
18092 + IiMustWriteLock(inode);
18095 + sb = inode->i_sb;
18096 + nbr = au_sbbot(sb) + 1;
18097 + type = inode->i_mode & S_IFMT;
18098 + iinfo = au_ii(inode);
18099 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18100 + if (unlikely(err))
18103 + AuDebugOn(iinfo->ii_btop < 0);
18104 + p = au_hinode(iinfo, iinfo->ii_btop);
18105 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18107 + if (!p->hi_inode)
18110 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18111 + new_bindex = au_br_index(sb, p->hi_id);
18112 + if (new_bindex == bindex)
18115 + if (new_bindex < 0) {
18118 + p->hi_inode = NULL;
18122 + if (new_bindex < iinfo->ii_btop)
18123 + iinfo->ii_btop = new_bindex;
18124 + if (iinfo->ii_bbot < new_bindex)
18125 + iinfo->ii_bbot = new_bindex;
18126 + /* swap two lower inode, and loop again */
18127 + q = au_hinode(iinfo, new_bindex);
18131 + if (tmp.hi_inode) {
18136 + au_update_ibrange(inode, /*do_put_zero*/0);
18137 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18138 + e = au_dy_irefresh(inode);
18139 + if (unlikely(e && !err))
18147 +void au_refresh_iop(struct inode *inode, int force_getattr)
18150 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18151 + const struct inode_operations *iop
18152 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18154 + if (inode->i_op == iop)
18157 + switch (inode->i_mode & S_IFMT) {
18159 + type = AuIop_DIR;
18162 + type = AuIop_SYMLINK;
18165 + type = AuIop_OTHER;
18169 + inode->i_op = iop + type;
18170 + /* unnecessary smp_wmb() */
18173 +int au_refresh_hinode_self(struct inode *inode)
18177 + err = au_ii_refresh(inode, &update);
18179 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18185 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18187 + int err, e, update;
18188 + unsigned int flags;
18190 + aufs_bindex_t bindex, bbot;
18191 + unsigned char isdir;
18192 + struct au_hinode *p;
18193 + struct au_iinfo *iinfo;
18195 + err = au_ii_refresh(inode, &update);
18196 + if (unlikely(err))
18200 + iinfo = au_ii(inode);
18201 + p = au_hinode(iinfo, iinfo->ii_btop);
18202 + mode = (inode->i_mode & S_IFMT);
18203 + isdir = S_ISDIR(mode);
18204 + flags = au_hi_flags(inode, isdir);
18205 + bbot = au_dbbot(dentry);
18206 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18207 + struct inode *h_i, *h_inode;
18208 + struct dentry *h_d;
18210 + h_d = au_h_dptr(dentry, bindex);
18211 + if (!h_d || d_is_negative(h_d))
18214 + h_inode = d_inode(h_d);
18215 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18216 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18217 + h_i = au_h_iptr(inode, bindex);
18219 + if (h_i == h_inode)
18225 + if (bindex < iinfo->ii_btop)
18226 + iinfo->ii_btop = bindex;
18227 + if (iinfo->ii_bbot < bindex)
18228 + iinfo->ii_bbot = bindex;
18229 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18232 + au_update_ibrange(inode, /*do_put_zero*/0);
18233 + e = au_dy_irefresh(inode);
18234 + if (unlikely(e && !err))
18237 + au_refresh_hinode_attr(inode, update && isdir);
18244 +static int set_inode(struct inode *inode, struct dentry *dentry)
18247 + unsigned int flags;
18249 + aufs_bindex_t bindex, btop, btail;
18250 + unsigned char isdir;
18251 + struct dentry *h_dentry;
18252 + struct inode *h_inode;
18253 + struct au_iinfo *iinfo;
18254 + const struct inode_operations *iop;
18256 + IiMustWriteLock(inode);
18260 + iop = au_sbi(inode->i_sb)->si_iop_array;
18261 + btop = au_dbtop(dentry);
18262 + h_dentry = au_h_dptr(dentry, btop);
18263 + h_inode = d_inode(h_dentry);
18264 + mode = h_inode->i_mode;
18265 + switch (mode & S_IFMT) {
18267 + btail = au_dbtail(dentry);
18268 + inode->i_op = iop + AuIop_OTHER;
18269 + inode->i_fop = &aufs_file_fop;
18270 + err = au_dy_iaop(inode, btop, h_inode);
18271 + if (unlikely(err))
18276 + btail = au_dbtaildir(dentry);
18277 + inode->i_op = iop + AuIop_DIR;
18278 + inode->i_fop = &aufs_dir_fop;
18281 + btail = au_dbtail(dentry);
18282 + inode->i_op = iop + AuIop_SYMLINK;
18288 + btail = au_dbtail(dentry);
18289 + inode->i_op = iop + AuIop_OTHER;
18290 + init_special_inode(inode, mode, h_inode->i_rdev);
18293 + AuIOErr("Unknown file type 0%o\n", mode);
18298 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18299 + flags = au_hi_flags(inode, isdir);
18300 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18301 + && au_ftest_hi(flags, HNOTIFY)
18302 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18303 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18304 + au_fclr_hi(flags, HNOTIFY);
18305 + iinfo = au_ii(inode);
18306 + iinfo->ii_btop = btop;
18307 + iinfo->ii_bbot = btail;
18308 + for (bindex = btop; bindex <= btail; bindex++) {
18309 + h_dentry = au_h_dptr(dentry, bindex);
18311 + au_set_h_iptr(inode, bindex,
18312 + au_igrab(d_inode(h_dentry)), flags);
18314 + au_cpup_attr_all(inode, /*force*/1);
18316 + * to force calling aufs_get_acl() every time,
18317 + * do not call cache_no_acl() for aufs inode.
18325 + * successful returns with iinfo write_locked
18327 + * zero: success, matched
18328 + * plus: no error, but unmatched
18330 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18333 + unsigned int gen, igflags;
18334 + aufs_bindex_t bindex, bbot;
18335 + struct inode *h_inode, *h_dinode;
18336 + struct dentry *h_dentry;
18339 + * before this function, if aufs got any iinfo lock, it must be only
18340 + * one, the parent dir.
18341 + * it can happen by UDBA and the obsoleted inode number.
18344 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18348 + ii_write_lock_new_child(inode);
18349 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18350 + h_dinode = d_inode(h_dentry);
18351 + bbot = au_ibbot(inode);
18352 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18353 + h_inode = au_h_iptr(inode, bindex);
18354 + if (!h_inode || h_inode != h_dinode)
18358 + gen = au_iigen(inode, &igflags);
18359 + if (gen == au_digen(dentry)
18360 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18363 + /* fully refresh inode using dentry */
18364 + err = au_refresh_hinode(inode, dentry);
18366 + au_update_iigen(inode, /*half*/0);
18370 + if (unlikely(err))
18371 + ii_write_unlock(inode);
18376 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18377 + unsigned int d_type, ino_t *ino)
18380 + const int isnondir = d_type != DT_DIR;
18382 + /* prevent hardlinked inode number from race condition */
18384 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18385 + if (unlikely(err))
18389 + err = au_xino_read(sb, bindex, h_ino, ino);
18390 + if (unlikely(err))
18391 + goto out_xinondir;
18395 + *ino = au_xino_new_ino(sb);
18396 + if (unlikely(!*ino))
18397 + goto out_xinondir;
18398 + err = au_xino_write(sb, bindex, h_ino, *ino);
18399 + if (unlikely(err))
18400 + goto out_xinondir;
18404 + if (isnondir && idx >= 0)
18405 + au_xinondir_leave(sb, bindex, h_ino, idx);
18410 +/* successful returns with iinfo write_locked */
18411 +/* todo: return with unlocked? */
18412 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18414 + struct inode *inode, *h_inode;
18415 + struct dentry *h_dentry;
18416 + struct super_block *sb;
18417 + ino_t h_ino, ino;
18418 + int err, idx, hlinked;
18419 + aufs_bindex_t btop;
18421 + sb = dentry->d_sb;
18422 + btop = au_dbtop(dentry);
18423 + h_dentry = au_h_dptr(dentry, btop);
18424 + h_inode = d_inode(h_dentry);
18425 + h_ino = h_inode->i_ino;
18426 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18430 + * stop 'race'-ing between hardlinks under different
18434 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18435 + inode = ERR_PTR(err);
18436 + if (unlikely(err))
18440 + err = au_xino_read(sb, btop, h_ino, &ino);
18441 + inode = ERR_PTR(err);
18442 + if (unlikely(err))
18443 + goto out_xinondir;
18446 + ino = au_xino_new_ino(sb);
18447 + if (unlikely(!ino)) {
18448 + inode = ERR_PTR(-EIO);
18449 + goto out_xinondir;
18453 + AuDbg("i%lu\n", (unsigned long)ino);
18454 + inode = au_iget_locked(sb, ino);
18455 + err = PTR_ERR(inode);
18456 + if (IS_ERR(inode))
18457 + goto out_xinondir;
18459 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18460 + if (inode->i_state & I_NEW) {
18461 + ii_write_lock_new_child(inode);
18462 + err = set_inode(inode, dentry);
18464 + unlock_new_inode(inode);
18465 + goto out_xinondir; /* success */
18469 + * iget_failed() calls iput(), but we need to call
18470 + * ii_write_unlock() after iget_failed(). so dirty hack for
18473 + atomic_inc(&inode->i_count);
18474 + iget_failed(inode);
18475 + ii_write_unlock(inode);
18476 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18477 + /* ignore this error */
18479 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18481 + * horrible race condition between lookup, readdir and copyup
18482 + * (or something).
18484 + if (hlinked && idx >= 0)
18485 + au_xinondir_leave(sb, btop, h_ino, idx);
18486 + err = reval_inode(inode, dentry);
18487 + if (unlikely(err < 0)) {
18492 + goto out; /* success */
18493 + else if (hlinked && idx >= 0) {
18494 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18495 + if (unlikely(err)) {
18497 + inode = ERR_PTR(err);
18503 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18504 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18505 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18506 + btop, au_sbtype(h_dentry->d_sb), dentry,
18507 + (unsigned long)h_ino, (unsigned long)ino);
18509 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18512 + if (hlinked && idx >= 0)
18513 + au_xinondir_leave(sb, btop, h_ino, idx);
18519 + inode = ERR_PTR(err);
18521 + if (hlinked && idx >= 0)
18522 + au_xinondir_leave(sb, btop, h_ino, idx);
18527 +/* ---------------------------------------------------------------------- */
18529 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18530 + struct inode *inode)
18533 + struct inode *hi;
18535 + err = au_br_rdonly(au_sbr(sb, bindex));
18537 + /* pseudo-link after flushed may happen out of bounds */
18540 + && au_ibtop(inode) <= bindex
18541 + && bindex <= au_ibbot(inode)) {
18543 + * permission check is unnecessary since vfsub routine
18544 + * will be called later
18546 + hi = au_h_iptr(inode, bindex);
18548 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18554 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18557 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18559 + return inode_permission(h_userns, h_inode, mask);
18562 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18565 + if (au_test_nfs(h_inode->i_sb)
18566 + && (mask & MAY_WRITE)
18567 + && S_ISDIR(h_inode->i_mode))
18568 + mask |= MAY_READ; /* force permission check */
18569 + return au_test_h_perm(h_userns, h_inode, mask);
18571 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18572 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18573 +++ linux/fs/aufs/inode.h 2021-12-03 15:40:58.236647297 +0100
18575 +/* SPDX-License-Identifier: GPL-2.0 */
18577 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18579 + * This program, aufs is free software; you can redistribute it and/or modify
18580 + * it under the terms of the GNU General Public License as published by
18581 + * the Free Software Foundation; either version 2 of the License, or
18582 + * (at your option) any later version.
18584 + * This program is distributed in the hope that it will be useful,
18585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18587 + * GNU General Public License for more details.
18589 + * You should have received a copy of the GNU General Public License
18590 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18594 + * inode operations
18597 +#ifndef __AUFS_INODE_H__
18598 +#define __AUFS_INODE_H__
18602 +#include <linux/fsnotify.h>
18603 +#include "rwsem.h"
18607 +struct au_hnotify {
18608 +#ifdef CONFIG_AUFS_HNOTIFY
18609 +#ifdef CONFIG_AUFS_HFSNOTIFY
18610 + /* never use fsnotify_add_vfsmount_mark() */
18611 + struct fsnotify_mark hn_mark;
18613 + struct inode *hn_aufs_inode; /* no get/put */
18614 + struct rcu_head rcu;
18616 +} ____cacheline_aligned_in_smp;
18618 +struct au_hinode {
18619 + struct inode *hi_inode;
18620 + aufs_bindex_t hi_id;
18621 +#ifdef CONFIG_AUFS_HNOTIFY
18622 + struct au_hnotify *hi_notify;
18625 + /* reference to the copied-up whiteout with get/put */
18626 + struct dentry *hi_whdentry;
18630 +#define AuIG_HALF_REFRESHED 1
18631 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18632 +#define au_ig_fset(flags, name) \
18633 + do { (flags) |= AuIG_##name; } while (0)
18634 +#define au_ig_fclr(flags, name) \
18635 + do { (flags) &= ~AuIG_##name; } while (0)
18638 + spinlock_t ig_spin;
18639 + __u32 ig_generation, ig_flags;
18644 + struct au_iigen ii_generation;
18645 + struct super_block *ii_hsb1; /* no get/put */
18647 + struct au_rwsem ii_rwsem;
18648 + aufs_bindex_t ii_btop, ii_bbot;
18650 + struct au_hinode *ii_hinode;
18651 + struct au_vdir *ii_vdir;
18654 +struct au_icntnr {
18655 + struct au_iinfo iinfo;
18656 + struct inode vfs_inode;
18657 + struct hlist_bl_node plink;
18658 + struct rcu_head rcu;
18659 +} ____cacheline_aligned_in_smp;
18661 +/* au_pin flags */
18662 +#define AuPin_DI_LOCKED 1
18663 +#define AuPin_MNT_WRITE (1 << 1)
18664 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18665 +#define au_fset_pin(flags, name) \
18666 + do { (flags) |= AuPin_##name; } while (0)
18667 +#define au_fclr_pin(flags, name) \
18668 + do { (flags) &= ~AuPin_##name; } while (0)
18672 + struct dentry *dentry;
18673 + unsigned int udba;
18674 + unsigned char lsc_di, lsc_hi, flags;
18675 + aufs_bindex_t bindex;
18678 + struct dentry *parent;
18679 + struct au_hinode *hdir;
18680 + struct vfsmount *h_mnt;
18682 + /* temporary unlock/relock for copyup */
18683 + struct dentry *h_dentry, *h_parent;
18684 + struct au_branch *br;
18685 + struct task_struct *task;
18688 +void au_pin_hdir_unlock(struct au_pin *p);
18689 +int au_pin_hdir_lock(struct au_pin *p);
18690 +int au_pin_hdir_relock(struct au_pin *p);
18691 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18692 +void au_pin_hdir_release(struct au_pin *p);
18694 +/* ---------------------------------------------------------------------- */
18696 +static inline struct au_iinfo *au_ii(struct inode *inode)
18698 + BUG_ON(is_bad_inode(inode));
18699 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18702 +/* ---------------------------------------------------------------------- */
18705 +struct inode *au_igrab(struct inode *inode);
18706 +void au_refresh_iop(struct inode *inode, int force_getattr);
18707 +int au_refresh_hinode_self(struct inode *inode);
18708 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18709 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18710 + unsigned int d_type, ino_t *ino);
18711 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18712 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18713 + struct inode *inode);
18714 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18716 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18719 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18720 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18722 +#ifdef CONFIG_AUFS_SHWH
18723 + return au_ino(sb, bindex, h_ino, d_type, ino);
18736 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18737 + aufs_iop_nogetattr[AuIop_Last];
18739 +/* au_wr_dir flags */
18740 +#define AuWrDir_ADD_ENTRY 1
18741 +#define AuWrDir_ISDIR (1 << 1)
18742 +#define AuWrDir_TMPFILE (1 << 2)
18743 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18744 +#define au_fset_wrdir(flags, name) \
18745 + do { (flags) |= AuWrDir_##name; } while (0)
18746 +#define au_fclr_wrdir(flags, name) \
18747 + do { (flags) &= ~AuWrDir_##name; } while (0)
18749 +struct au_wr_dir_args {
18750 + aufs_bindex_t force_btgt;
18751 + unsigned char flags;
18753 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18754 + struct au_wr_dir_args *args);
18756 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18757 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18758 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18759 + unsigned int udba, unsigned char flags);
18760 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18761 + unsigned int udba, unsigned char flags) __must_check;
18762 +int au_do_pin(struct au_pin *pin) __must_check;
18763 +void au_unpin(struct au_pin *pin);
18764 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18766 +#define AuIcpup_DID_CPUP 1
18767 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18768 +#define au_fset_icpup(flags, name) \
18769 + do { (flags) |= AuIcpup_##name; } while (0)
18770 +#define au_fclr_icpup(flags, name) \
18771 + do { (flags) &= ~AuIcpup_##name; } while (0)
18773 +struct au_icpup_args {
18774 + unsigned char flags;
18775 + unsigned char pin_flags;
18776 + aufs_bindex_t btgt;
18777 + unsigned int udba;
18778 + struct au_pin pin;
18779 + struct path h_path;
18780 + struct inode *h_inode;
18783 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18784 + struct au_icpup_args *a);
18786 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18787 + struct path *h_path, int locked);
18790 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18791 + struct dentry *h_parent, int isdir);
18792 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
18793 + struct dentry *dentry, umode_t mode, dev_t dev);
18794 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
18795 + struct dentry *dentry, const char *symname);
18796 +int aufs_create(struct user_namespace *userns, struct inode *dir,
18797 + struct dentry *dentry, umode_t mode, bool want_excl);
18798 +struct vfsub_aopen_args;
18799 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18800 + struct vfsub_aopen_args *args);
18801 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
18802 + struct dentry *dentry, umode_t mode);
18803 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18804 + struct dentry *dentry);
18805 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
18806 + struct dentry *dentry, umode_t mode);
18809 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18810 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18811 + struct dentry *h_parent, int isdir);
18812 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18813 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18816 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18817 +int aufs_rename(struct user_namespace *userns,
18818 + struct inode *_src_dir, struct dentry *_src_dentry,
18819 + struct inode *_dst_dir, struct dentry *_dst_dentry,
18820 + unsigned int _flags);
18823 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18824 +void au_hiput(struct au_hinode *hinode);
18825 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18826 + struct dentry *h_wh);
18827 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18829 +/* hinode flags */
18830 +#define AuHi_XINO 1
18831 +#define AuHi_HNOTIFY (1 << 1)
18832 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18833 +#define au_fset_hi(flags, name) \
18834 + do { (flags) |= AuHi_##name; } while (0)
18835 +#define au_fclr_hi(flags, name) \
18836 + do { (flags) &= ~AuHi_##name; } while (0)
18838 +#ifndef CONFIG_AUFS_HNOTIFY
18839 +#undef AuHi_HNOTIFY
18840 +#define AuHi_HNOTIFY 0
18843 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18844 + struct inode *h_inode, unsigned int flags);
18846 +void au_update_iigen(struct inode *inode, int half);
18847 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18849 +void au_icntnr_init_once(void *_c);
18850 +void au_hinode_init(struct au_hinode *hinode);
18851 +int au_iinfo_init(struct inode *inode);
18852 +void au_iinfo_fin(struct inode *inode);
18853 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18855 +#ifdef CONFIG_PROC_FS
18857 +int au_plink_maint(struct super_block *sb, int flags);
18859 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18860 +int au_plink_maint_enter(struct super_block *sb);
18861 +#ifdef CONFIG_AUFS_DEBUG
18862 +void au_plink_list(struct super_block *sb);
18864 +AuStubVoid(au_plink_list, struct super_block *sb)
18866 +int au_plink_test(struct inode *inode);
18867 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18868 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18869 + struct dentry *h_dentry);
18870 +void au_plink_put(struct super_block *sb, int verbose);
18871 +void au_plink_clean(struct super_block *sb, int verbose);
18872 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18874 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18875 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18876 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18877 +AuStubVoid(au_plink_list, struct super_block *sb);
18878 +AuStubInt0(au_plink_test, struct inode *inode);
18879 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18880 + struct inode *inode, aufs_bindex_t bindex);
18881 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18882 + struct dentry *h_dentry);
18883 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18884 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18885 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18886 +#endif /* CONFIG_PROC_FS */
18888 +#ifdef CONFIG_AUFS_XATTR
18890 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
18891 + unsigned int verbose);
18892 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18893 +void au_xattr_init(struct super_block *sb);
18895 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
18896 + int ignore_flags, unsigned int verbose);
18897 +AuStubVoid(au_xattr_init, struct super_block *sb);
18900 +#ifdef CONFIG_FS_POSIX_ACL
18901 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
18902 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
18903 + struct posix_acl *acl, int type);
18906 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18912 +struct au_sxattr {
18916 + const char *name;
18917 + const void *value;
18922 + struct posix_acl *acl;
18927 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18928 + struct au_sxattr *arg);
18931 +/* ---------------------------------------------------------------------- */
18933 +/* lock subclass for iinfo */
18935 + AuLsc_II_CHILD, /* child first */
18936 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18937 + AuLsc_II_CHILD3, /* copyup dirs */
18938 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18939 + AuLsc_II_PARENT2,
18940 + AuLsc_II_PARENT3, /* copyup dirs */
18941 + AuLsc_II_NEW_CHILD
18945 + * ii_read_lock_child, ii_write_lock_child,
18946 + * ii_read_lock_child2, ii_write_lock_child2,
18947 + * ii_read_lock_child3, ii_write_lock_child3,
18948 + * ii_read_lock_parent, ii_write_lock_parent,
18949 + * ii_read_lock_parent2, ii_write_lock_parent2,
18950 + * ii_read_lock_parent3, ii_write_lock_parent3,
18951 + * ii_read_lock_new_child, ii_write_lock_new_child,
18953 +#define AuReadLockFunc(name, lsc) \
18954 +static inline void ii_read_lock_##name(struct inode *i) \
18956 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18959 +#define AuWriteLockFunc(name, lsc) \
18960 +static inline void ii_write_lock_##name(struct inode *i) \
18962 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18965 +#define AuRWLockFuncs(name, lsc) \
18966 + AuReadLockFunc(name, lsc) \
18967 + AuWriteLockFunc(name, lsc)
18969 +AuRWLockFuncs(child, CHILD);
18970 +AuRWLockFuncs(child2, CHILD2);
18971 +AuRWLockFuncs(child3, CHILD3);
18972 +AuRWLockFuncs(parent, PARENT);
18973 +AuRWLockFuncs(parent2, PARENT2);
18974 +AuRWLockFuncs(parent3, PARENT3);
18975 +AuRWLockFuncs(new_child, NEW_CHILD);
18977 +#undef AuReadLockFunc
18978 +#undef AuWriteLockFunc
18979 +#undef AuRWLockFuncs
18981 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18982 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18983 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18985 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18986 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18987 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18989 +/* ---------------------------------------------------------------------- */
18991 +static inline void au_icntnr_init(struct au_icntnr *c)
18993 +#ifdef CONFIG_AUFS_DEBUG
18994 + c->vfs_inode.i_mode = 0;
18998 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19000 + unsigned int gen;
19001 + struct au_iinfo *iinfo;
19002 + struct au_iigen *iigen;
19004 + iinfo = au_ii(inode);
19005 + iigen = &iinfo->ii_generation;
19006 + spin_lock(&iigen->ig_spin);
19008 + *igflags = iigen->ig_flags;
19009 + gen = iigen->ig_generation;
19010 + spin_unlock(&iigen->ig_spin);
19015 +/* tiny test for inode number */
19016 +/* tmpfs generation is too rough */
19017 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19019 + struct au_iinfo *iinfo;
19021 + iinfo = au_ii(inode);
19022 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19023 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19024 + && iinfo->ii_higen == h_inode->i_generation);
19027 +static inline void au_iigen_dec(struct inode *inode)
19029 + struct au_iinfo *iinfo;
19030 + struct au_iigen *iigen;
19032 + iinfo = au_ii(inode);
19033 + iigen = &iinfo->ii_generation;
19034 + spin_lock(&iigen->ig_spin);
19035 + iigen->ig_generation--;
19036 + spin_unlock(&iigen->ig_spin);
19039 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19044 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19050 +/* ---------------------------------------------------------------------- */
19052 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19053 + aufs_bindex_t bindex)
19055 + return iinfo->ii_hinode + bindex;
19058 +static inline int au_is_bad_inode(struct inode *inode)
19060 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19063 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19064 + aufs_bindex_t bindex)
19066 + IiMustAnyLock(inode);
19067 + return au_hinode(au_ii(inode), bindex)->hi_id;
19070 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19072 + IiMustAnyLock(inode);
19073 + return au_ii(inode)->ii_btop;
19076 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19078 + IiMustAnyLock(inode);
19079 + return au_ii(inode)->ii_bbot;
19082 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19084 + IiMustAnyLock(inode);
19085 + return au_ii(inode)->ii_vdir;
19088 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19090 + IiMustAnyLock(inode);
19091 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19094 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19096 + IiMustWriteLock(inode);
19097 + au_ii(inode)->ii_btop = bindex;
19100 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19102 + IiMustWriteLock(inode);
19103 + au_ii(inode)->ii_bbot = bindex;
19106 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19108 + IiMustWriteLock(inode);
19109 + au_ii(inode)->ii_vdir = vdir;
19112 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19114 + IiMustAnyLock(inode);
19115 + return au_hinode(au_ii(inode), bindex);
19118 +/* ---------------------------------------------------------------------- */
19120 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19123 + return pin->parent;
19127 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19129 + if (pin && pin->hdir)
19130 + return pin->hdir->hi_inode;
19134 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19137 + return pin->hdir;
19141 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19144 + pin->dentry = dentry;
19147 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19148 + unsigned char lflag)
19152 + au_fset_pin(pin->flags, DI_LOCKED);
19154 + au_fclr_pin(pin->flags, DI_LOCKED);
19158 +#if 0 /* reserved */
19159 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19162 + dput(pin->parent);
19163 + pin->parent = dget(parent);
19168 +/* ---------------------------------------------------------------------- */
19171 +#ifdef CONFIG_AUFS_HNOTIFY
19172 +struct au_hnotify_op {
19173 + void (*ctl)(struct au_hinode *hinode, int do_set);
19174 + int (*alloc)(struct au_hinode *hinode);
19177 + * if it returns true, the caller should free hinode->hi_notify,
19178 + * otherwise ->free() frees it.
19180 + int (*free)(struct au_hinode *hinode,
19181 + struct au_hnotify *hn) __must_check;
19183 + void (*fin)(void);
19184 + int (*init)(void);
19186 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19187 + void (*fin_br)(struct au_branch *br);
19188 + int (*init_br)(struct au_branch *br, int perm);
19192 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19193 +void au_hn_free(struct au_hinode *hinode);
19194 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19195 +void au_hn_reset(struct inode *inode, unsigned int flags);
19196 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19197 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19198 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19199 +int au_hnotify_init_br(struct au_branch *br, int perm);
19200 +void au_hnotify_fin_br(struct au_branch *br);
19201 +int __init au_hnotify_init(void);
19202 +void au_hnotify_fin(void);
19205 +extern const struct au_hnotify_op au_hnotify_op;
19208 +void au_hn_init(struct au_hinode *hinode)
19210 + hinode->hi_notify = NULL;
19213 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19215 + return hinode->hi_notify;
19219 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19220 + struct au_hinode *hinode __maybe_unused,
19221 + struct inode *inode __maybe_unused)
19222 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19223 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19224 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19225 + int do_set __maybe_unused)
19226 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19227 + unsigned int flags __maybe_unused)
19228 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19229 + struct au_branch *br __maybe_unused,
19230 + int perm __maybe_unused)
19231 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19232 + int perm __maybe_unused)
19233 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19234 +AuStubInt0(__init au_hnotify_init, void)
19235 +AuStubVoid(au_hnotify_fin, void)
19236 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19237 +#endif /* CONFIG_AUFS_HNOTIFY */
19239 +static inline void au_hn_suspend(struct au_hinode *hdir)
19241 + au_hn_ctl(hdir, /*do_set*/0);
19244 +static inline void au_hn_resume(struct au_hinode *hdir)
19246 + au_hn_ctl(hdir, /*do_set*/1);
19249 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19251 + inode_lock(hdir->hi_inode);
19252 + au_hn_suspend(hdir);
19255 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19256 + unsigned int sc __maybe_unused)
19258 + inode_lock_nested(hdir->hi_inode, sc);
19259 + au_hn_suspend(hdir);
19262 +#if 0 /* unused */
19263 +#include "vfsub.h"
19264 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19267 + inode_lock_shared_nested(hdir->hi_inode, sc);
19268 + au_hn_suspend(hdir);
19272 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19274 + au_hn_resume(hdir);
19275 + inode_unlock(hdir->hi_inode);
19278 +#endif /* __KERNEL__ */
19279 +#endif /* __AUFS_INODE_H__ */
19280 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19281 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19282 +++ linux/fs/aufs/ioctl.c 2021-12-03 15:38:59.936647310 +0100
19284 +// SPDX-License-Identifier: GPL-2.0
19286 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19288 + * This program, aufs is free software; you can redistribute it and/or modify
19289 + * it under the terms of the GNU General Public License as published by
19290 + * the Free Software Foundation; either version 2 of the License, or
19291 + * (at your option) any later version.
19293 + * This program is distributed in the hope that it will be useful,
19294 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19295 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19296 + * GNU General Public License for more details.
19298 + * You should have received a copy of the GNU General Public License
19299 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19304 + * plink-management and readdir in userspace.
19305 + * assist the pathconf(3) wrapper library.
19307 + * File-based Hierarchical Storage Management.
19310 +#include <linux/compat.h>
19311 +#include <linux/file.h>
19314 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19317 + aufs_bindex_t wbi, bindex, bbot;
19318 + struct file *h_file;
19319 + struct super_block *sb;
19320 + struct dentry *root;
19321 + struct au_branch *br;
19322 + struct aufs_wbr_fd wbrfd = {
19323 + .oflags = au_dir_roflags,
19326 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19327 + | O_NOATIME | O_CLOEXEC;
19329 + AuDebugOn(wbrfd.oflags & ~valid);
19332 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19333 + if (unlikely(err)) {
19339 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19340 + wbrfd.oflags |= au_dir_roflags;
19341 + AuDbg("0%o\n", wbrfd.oflags);
19342 + if (unlikely(wbrfd.oflags & ~valid))
19346 + fd = get_unused_fd_flags(0);
19348 + if (unlikely(fd < 0))
19351 + h_file = ERR_PTR(-EINVAL);
19354 + sb = path->dentry->d_sb;
19355 + root = sb->s_root;
19356 + aufs_read_lock(root, AuLock_IR);
19357 + bbot = au_sbbot(sb);
19358 + if (wbrfd.brid >= 0) {
19359 + wbi = au_br_index(sb, wbrfd.brid);
19360 + if (unlikely(wbi < 0 || wbi > bbot))
19364 + h_file = ERR_PTR(-ENOENT);
19365 + br = au_sbr(sb, wbi);
19366 + if (!au_br_writable(br->br_perm)) {
19370 + bindex = wbi + 1;
19372 + for (; bindex <= bbot; bindex++) {
19373 + br = au_sbr(sb, bindex);
19374 + if (au_br_writable(br->br_perm)) {
19376 + br = au_sbr(sb, wbi);
19381 + AuDbg("wbi %d\n", wbi);
19383 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19387 + aufs_read_unlock(root, AuLock_IR);
19388 + err = PTR_ERR(h_file);
19389 + if (IS_ERR(h_file))
19392 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19393 + fd_install(fd, h_file);
19395 + goto out; /* success */
19398 + put_unused_fd(fd);
19404 +/* ---------------------------------------------------------------------- */
19406 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19409 + struct dentry *dentry;
19412 + case AUFS_CTL_RDU:
19413 + case AUFS_CTL_RDU_INO:
19414 + err = au_rdu_ioctl(file, cmd, arg);
19417 + case AUFS_CTL_WBR_FD:
19418 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19421 + case AUFS_CTL_IBUSY:
19422 + err = au_ibusy_ioctl(file, arg);
19425 + case AUFS_CTL_BRINFO:
19426 + err = au_brinfo_ioctl(file, arg);
19429 + case AUFS_CTL_FHSM_FD:
19430 + dentry = file->f_path.dentry;
19431 + if (IS_ROOT(dentry))
19432 + err = au_fhsm_fd(dentry->d_sb, arg);
19438 + /* do not call the lower */
19439 + AuDbg("0x%x\n", cmd);
19447 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19452 + case AUFS_CTL_MVDOWN:
19453 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19456 + case AUFS_CTL_WBR_FD:
19457 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19461 + /* do not call the lower */
19462 + AuDbg("0x%x\n", cmd);
19470 +#ifdef CONFIG_COMPAT
19471 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19472 + unsigned long arg)
19477 + case AUFS_CTL_RDU:
19478 + case AUFS_CTL_RDU_INO:
19479 + err = au_rdu_compat_ioctl(file, cmd, arg);
19482 + case AUFS_CTL_IBUSY:
19483 + err = au_ibusy_compat_ioctl(file, arg);
19486 + case AUFS_CTL_BRINFO:
19487 + err = au_brinfo_compat_ioctl(file, arg);
19491 + err = aufs_ioctl_dir(file, cmd, arg);
19498 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19499 + unsigned long arg)
19501 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19504 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19505 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19506 +++ linux/fs/aufs/i_op_add.c 2021-12-03 15:40:58.236647297 +0100
19508 +// SPDX-License-Identifier: GPL-2.0
19510 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19512 + * This program, aufs is free software; you can redistribute it and/or modify
19513 + * it under the terms of the GNU General Public License as published by
19514 + * the Free Software Foundation; either version 2 of the License, or
19515 + * (at your option) any later version.
19517 + * This program is distributed in the hope that it will be useful,
19518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19520 + * GNU General Public License for more details.
19522 + * You should have received a copy of the GNU General Public License
19523 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19527 + * inode operations (add entry)
19530 +#include <linux/iversion.h>
19534 + * final procedure of adding a new entry, except link(2).
19535 + * remove whiteout, instantiate, copyup the parent dir's times and size
19536 + * and update version.
19537 + * if it failed, re-create the removed whiteout.
19539 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19540 + struct dentry *wh_dentry, struct dentry *dentry)
19543 + aufs_bindex_t bwh;
19544 + struct path h_path;
19545 + struct super_block *sb;
19546 + struct inode *inode, *h_dir;
19547 + struct dentry *wh;
19552 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19553 + IMustLock(h_dir);
19554 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19555 + bwh = au_dbwh(dentry);
19556 + h_path.dentry = wh_dentry;
19557 + h_path.mnt = au_sbr_mnt(sb, bindex);
19558 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19560 + if (unlikely(err))
19564 + inode = au_new_inode(dentry, /*must_new*/1);
19565 + if (!IS_ERR(inode)) {
19566 + d_instantiate(dentry, inode);
19567 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19569 + au_dir_ts(dir, bindex);
19570 + inode_inc_iversion(dir);
19571 + au_fhsm_wrote(sb, bindex, /*force*/0);
19572 + return 0; /* success */
19575 + err = PTR_ERR(inode);
19580 + /* dir inode is locked */
19581 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19582 + rerr = PTR_ERR(wh);
19583 + if (IS_ERR(wh)) {
19584 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19585 + dentry, err, rerr);
19594 +static int au_d_may_add(struct dentry *dentry)
19599 + if (unlikely(d_unhashed(dentry)))
19601 + if (unlikely(d_really_is_positive(dentry)))
19607 + * simple tests for the adding inode operations.
19608 + * following the checks in vfs, plus the parent-child relationship.
19610 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19611 + struct dentry *h_parent, int isdir)
19615 + struct dentry *h_dentry;
19616 + struct inode *h_inode;
19618 + err = -ENAMETOOLONG;
19619 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19622 + h_dentry = au_h_dptr(dentry, bindex);
19623 + if (d_really_is_negative(dentry)) {
19625 + if (unlikely(d_is_positive(h_dentry)))
19628 + /* rename(2) case */
19630 + if (unlikely(d_is_negative(h_dentry)))
19632 + h_inode = d_inode(h_dentry);
19633 + if (unlikely(!h_inode->i_nlink))
19636 + h_mode = h_inode->i_mode;
19639 + if (unlikely(S_ISDIR(h_mode)))
19641 + } else if (unlikely(!S_ISDIR(h_mode))) {
19648 + /* expected parent dir is locked */
19649 + if (unlikely(h_parent != h_dentry->d_parent))
19658 + * initial procedure of adding a new entry.
19659 + * prepare writable branch and the parent dir, lock it,
19660 + * and lookup whiteout for the new entry.
19662 +static struct dentry*
19663 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19664 + struct dentry *src_dentry, struct au_pin *pin,
19665 + struct au_wr_dir_args *wr_dir_args)
19667 + struct dentry *wh_dentry, *h_parent;
19668 + struct super_block *sb;
19669 + struct au_branch *br;
19671 + unsigned int udba;
19672 + aufs_bindex_t bcpup;
19674 + AuDbg("%pd\n", dentry);
19676 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19678 + wh_dentry = ERR_PTR(err);
19679 + if (unlikely(err < 0))
19682 + sb = dentry->d_sb;
19683 + udba = au_opt_udba(sb);
19684 + err = au_pin(pin, dentry, bcpup, udba,
19685 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19686 + wh_dentry = ERR_PTR(err);
19687 + if (unlikely(err))
19690 + h_parent = au_pinned_h_parent(pin);
19691 + if (udba != AuOpt_UDBA_NONE
19692 + && au_dbtop(dentry) == bcpup)
19693 + err = au_may_add(dentry, bcpup, h_parent,
19694 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19695 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19696 + err = -ENAMETOOLONG;
19697 + wh_dentry = ERR_PTR(err);
19698 + if (unlikely(err))
19701 + br = au_sbr(sb, bcpup);
19703 + struct path tmp = {
19704 + .dentry = h_parent,
19705 + .mnt = au_br_mnt(br)
19707 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19710 + wh_dentry = NULL;
19711 + if (bcpup != au_dbwh(dentry))
19712 + goto out; /* success */
19715 + * ENAMETOOLONG here means that if we allowed create such name, then it
19716 + * would not be able to removed in the future. So we don't allow such
19717 + * name here and we don't handle ENAMETOOLONG differently here.
19719 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19722 + if (IS_ERR(wh_dentry))
19725 + return wh_dentry;
19728 +/* ---------------------------------------------------------------------- */
19730 +enum { Mknod, Symlink, Creat };
19731 +struct simple_arg {
19738 + struct vfsub_aopen_args *aopen;
19741 + const char *symname;
19750 +static int add_simple(struct inode *dir, struct dentry *dentry,
19751 + struct simple_arg *arg)
19754 + aufs_bindex_t btop;
19755 + unsigned char created;
19756 + const unsigned char try_aopen
19757 + = (arg->type == Creat && arg->u.c.try_aopen);
19758 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19759 + struct dentry *wh_dentry, *parent;
19760 + struct inode *h_dir;
19761 + struct super_block *sb;
19762 + struct au_branch *br;
19763 + /* to reduce stack size */
19765 + struct au_dtime dt;
19766 + struct au_pin pin;
19767 + struct path h_path;
19768 + struct au_wr_dir_args wr_dir_args;
19771 + AuDbg("%pd\n", dentry);
19775 + a = kmalloc(sizeof(*a), GFP_NOFS);
19776 + if (unlikely(!a))
19778 + a->wr_dir_args.force_btgt = -1;
19779 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19781 + parent = dentry->d_parent; /* dir inode is locked */
19782 + if (!try_aopen) {
19783 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19784 + if (unlikely(err))
19787 + err = au_d_may_add(dentry);
19788 + if (unlikely(err))
19791 + di_write_lock_parent(parent);
19792 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19793 + &a->pin, &a->wr_dir_args);
19794 + err = PTR_ERR(wh_dentry);
19795 + if (IS_ERR(wh_dentry))
19798 + btop = au_dbtop(dentry);
19799 + sb = dentry->d_sb;
19800 + br = au_sbr(sb, btop);
19801 + a->h_path.dentry = au_h_dptr(dentry, btop);
19802 + a->h_path.mnt = au_br_mnt(br);
19803 + h_dir = au_pinned_h_dir(&a->pin);
19804 + switch (arg->type) {
19806 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19807 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19808 + arg->u.c.want_excl);
19810 + if (!err && try_aopen)
19811 + aopen->file->f_mode |= FMODE_CREATED;
19814 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19815 + AuDbg("err %d\n", err);
19816 + AuDbgFile(aopen->file);
19817 + created = err >= 0
19818 + && !!(aopen->file->f_mode & FMODE_CREATED);
19822 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19826 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19833 + if (unlikely(err < 0))
19836 + err = epilog(dir, btop, wh_dentry, dentry);
19838 + goto out_unpin; /* success */
19841 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19842 + /* no delegation since it is just created */
19843 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19846 + AuIOErr("%pd revert failure(%d, %d)\n",
19847 + dentry, err, rerr);
19850 + au_dtime_revert(&a->dt);
19852 + if (try_aopen && h_dir->i_op->atomic_open
19853 + && (aopen->file->f_mode & FMODE_OPENED))
19854 + /* aopen->file is still opened */
19855 + au_lcnt_dec(&aopen->br->br_nfiles);
19858 + au_unpin(&a->pin);
19862 + di_write_unlock(parent);
19864 + if (unlikely(err)) {
19865 + au_update_dbtop(dentry);
19869 + aufs_read_unlock(dentry, AuLock_DW);
19876 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
19877 + struct dentry *dentry, umode_t mode, dev_t dev)
19879 + struct simple_arg arg = {
19886 + return add_simple(dir, dentry, &arg);
19889 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
19890 + struct dentry *dentry, const char *symname)
19892 + struct simple_arg arg = {
19894 + .u.s.symname = symname
19896 + return add_simple(dir, dentry, &arg);
19899 +int aufs_create(struct user_namespace *userns, struct inode *dir,
19900 + struct dentry *dentry, umode_t mode, bool want_excl)
19902 + struct simple_arg arg = {
19906 + .want_excl = want_excl
19909 + return add_simple(dir, dentry, &arg);
19912 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19913 + struct vfsub_aopen_args *aopen_args)
19915 + struct simple_arg arg = {
19918 + .mode = aopen_args->create_mode,
19919 + .want_excl = aopen_args->open_flag & O_EXCL,
19920 + .try_aopen = true,
19921 + .aopen = aopen_args
19924 + return add_simple(dir, dentry, &arg);
19927 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
19928 + struct dentry *dentry, umode_t mode)
19931 + aufs_bindex_t bindex;
19932 + struct super_block *sb;
19933 + struct dentry *parent, *h_parent, *h_dentry;
19934 + struct inode *h_dir, *inode;
19935 + struct vfsmount *h_mnt;
19936 + struct user_namespace *h_userns;
19937 + struct au_wr_dir_args wr_dir_args = {
19938 + .force_btgt = -1,
19939 + .flags = AuWrDir_TMPFILE
19942 + /* copy-up may happen */
19946 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19947 + if (unlikely(err))
19950 + err = au_di_init(dentry);
19951 + if (unlikely(err))
19955 + parent = d_find_any_alias(dir);
19956 + AuDebugOn(!parent);
19957 + di_write_lock_parent(parent);
19958 + if (unlikely(d_inode(parent) != dir))
19961 + err = au_digen_test(parent, au_sigen(sb));
19962 + if (unlikely(err))
19965 + bindex = au_dbtop(parent);
19966 + au_set_dbtop(dentry, bindex);
19967 + au_set_dbbot(dentry, bindex);
19968 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19970 + if (unlikely(err < 0))
19973 + err = -EOPNOTSUPP;
19974 + h_dir = au_h_iptr(dir, bindex);
19975 + if (unlikely(!h_dir->i_op->tmpfile))
19978 + h_mnt = au_sbr_mnt(sb, bindex);
19979 + err = vfsub_mnt_want_write(h_mnt);
19980 + if (unlikely(err))
19983 + h_userns = mnt_user_ns(h_mnt);
19984 + h_parent = au_h_dptr(parent, bindex);
19985 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
19986 + if (IS_ERR(h_dentry)) {
19987 + err = PTR_ERR(h_dentry);
19991 + au_set_dbtop(dentry, bindex);
19992 + au_set_dbbot(dentry, bindex);
19993 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19994 + inode = au_new_inode(dentry, /*must_new*/1);
19995 + if (IS_ERR(inode)) {
19996 + err = PTR_ERR(inode);
19997 + au_set_h_dptr(dentry, bindex, NULL);
19998 + au_set_dbtop(dentry, -1);
19999 + au_set_dbbot(dentry, -1);
20001 + if (!inode->i_nlink)
20002 + set_nlink(inode, 1);
20003 + d_tmpfile(dentry, inode);
20004 + au_di(dentry)->di_tmpfile = 1;
20006 + /* update without i_mutex */
20007 + if (au_ibtop(dir) == au_dbtop(dentry))
20008 + au_cpup_attr_timesizes(dir);
20013 + vfsub_mnt_drop_write(h_mnt);
20015 + di_write_unlock(parent);
20017 + di_write_unlock(dentry);
20018 + if (unlikely(err)) {
20019 + au_di_fin(dentry);
20020 + dentry->d_fsdata = NULL;
20023 + si_read_unlock(sb);
20025 + inode_unlock(dir);
20029 +/* ---------------------------------------------------------------------- */
20031 +struct au_link_args {
20032 + aufs_bindex_t bdst, bsrc;
20033 + struct au_pin pin;
20034 + struct path h_path;
20035 + struct dentry *src_parent, *parent;
20038 +static int au_cpup_before_link(struct dentry *src_dentry,
20039 + struct au_link_args *a)
20042 + struct dentry *h_src_dentry;
20043 + struct au_cp_generic cpg = {
20044 + .dentry = src_dentry,
20049 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20052 + di_read_lock_parent(a->src_parent, AuLock_IR);
20053 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20054 + if (unlikely(err))
20057 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20058 + err = au_pin(&a->pin, src_dentry, a->bdst,
20059 + au_opt_udba(src_dentry->d_sb),
20060 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20061 + if (unlikely(err))
20064 + err = au_sio_cpup_simple(&cpg);
20065 + au_unpin(&a->pin);
20068 + di_read_unlock(a->src_parent, AuLock_IR);
20072 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20073 + struct au_link_args *a)
20076 + unsigned char plink;
20077 + aufs_bindex_t bbot;
20078 + struct dentry *h_src_dentry;
20079 + struct inode *h_inode, *inode, *delegated;
20080 + struct super_block *sb;
20081 + struct file *h_file;
20085 + sb = src_dentry->d_sb;
20086 + inode = d_inode(src_dentry);
20087 + if (au_ibtop(inode) <= a->bdst)
20088 + h_inode = au_h_iptr(inode, a->bdst);
20089 + if (!h_inode || !h_inode->i_nlink) {
20090 + /* copyup src_dentry as the name of dentry. */
20091 + bbot = au_dbbot(dentry);
20092 + if (bbot < a->bsrc)
20093 + au_set_dbbot(dentry, a->bsrc);
20094 + au_set_h_dptr(dentry, a->bsrc,
20095 + dget(au_h_dptr(src_dentry, a->bsrc)));
20096 + dget(a->h_path.dentry);
20097 + au_set_h_dptr(dentry, a->bdst, NULL);
20098 + AuDbg("temporary d_inode...\n");
20099 + spin_lock(&dentry->d_lock);
20100 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20101 + spin_unlock(&dentry->d_lock);
20102 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20103 + if (IS_ERR(h_file))
20104 + err = PTR_ERR(h_file);
20106 + struct au_cp_generic cpg = {
20107 + .dentry = dentry,
20112 + .flags = AuCpup_KEEPLINO
20114 + err = au_sio_cpup_simple(&cpg);
20115 + au_h_open_post(dentry, a->bsrc, h_file);
20117 + dput(a->h_path.dentry);
20118 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20120 + au_set_h_dptr(dentry, a->bdst,
20121 + a->h_path.dentry);
20123 + spin_lock(&dentry->d_lock);
20124 + dentry->d_inode = NULL; /* restore */
20125 + spin_unlock(&dentry->d_lock);
20126 + AuDbg("temporary d_inode...done\n");
20127 + au_set_h_dptr(dentry, a->bsrc, NULL);
20128 + au_set_dbbot(dentry, bbot);
20130 + /* the inode of src_dentry already exists on a.bdst branch */
20131 + h_src_dentry = d_find_alias(h_inode);
20132 + if (!h_src_dentry && au_plink_test(inode)) {
20134 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20135 + err = PTR_ERR(h_src_dentry);
20136 + if (IS_ERR(h_src_dentry))
20139 + if (unlikely(d_is_negative(h_src_dentry))) {
20140 + dput(h_src_dentry);
20141 + h_src_dentry = NULL;
20145 + if (h_src_dentry) {
20146 + delegated = NULL;
20147 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20148 + &a->h_path, &delegated);
20149 + if (unlikely(err == -EWOULDBLOCK)) {
20150 + pr_warn("cannot retry for NFSv4 delegation"
20151 + " for an internal link\n");
20154 + dput(h_src_dentry);
20156 + AuIOErr("no dentry found for hi%lu on b%d\n",
20157 + h_inode->i_ino, a->bdst);
20162 + if (!err && !plink)
20163 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20170 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20171 + struct dentry *dentry)
20174 + struct au_dtime dt;
20175 + struct au_link_args *a;
20176 + struct dentry *wh_dentry, *h_src_dentry;
20177 + struct inode *inode, *delegated;
20178 + struct super_block *sb;
20179 + struct au_wr_dir_args wr_dir_args = {
20180 + /* .force_btgt = -1, */
20181 + .flags = AuWrDir_ADD_ENTRY
20185 + inode = d_inode(src_dentry);
20186 + IMustLock(inode);
20189 + a = kzalloc(sizeof(*a), GFP_NOFS);
20190 + if (unlikely(!a))
20193 + a->parent = dentry->d_parent; /* dir inode is locked */
20194 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20195 + AuLock_NOPLM | AuLock_GEN);
20196 + if (unlikely(err))
20198 + err = au_d_linkable(src_dentry);
20199 + if (unlikely(err))
20201 + err = au_d_may_add(dentry);
20202 + if (unlikely(err))
20205 + a->src_parent = dget_parent(src_dentry);
20206 + wr_dir_args.force_btgt = au_ibtop(inode);
20208 + di_write_lock_parent(a->parent);
20209 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20210 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20212 + err = PTR_ERR(wh_dentry);
20213 + if (IS_ERR(wh_dentry))
20217 + sb = dentry->d_sb;
20218 + a->bdst = au_dbtop(dentry);
20219 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20220 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20221 + a->bsrc = au_ibtop(inode);
20222 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20223 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20224 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20225 + if (!h_src_dentry) {
20226 + a->bsrc = au_dbtop(src_dentry);
20227 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20228 + AuDebugOn(!h_src_dentry);
20229 + } else if (IS_ERR(h_src_dentry)) {
20230 + err = PTR_ERR(h_src_dentry);
20235 + * aufs doesn't touch the credential so
20236 + * security_dentry_create_files_as() is unnecessary.
20238 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20239 + if (a->bdst < a->bsrc
20240 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20241 + err = au_cpup_or_link(src_dentry, dentry, a);
20243 + delegated = NULL;
20244 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20245 + &a->h_path, &delegated);
20246 + if (unlikely(err == -EWOULDBLOCK)) {
20247 + pr_warn("cannot retry for NFSv4 delegation"
20248 + " for an internal link\n");
20252 + dput(h_src_dentry);
20255 + * copyup src_dentry to the branch we process,
20256 + * and then link(2) to it.
20258 + dput(h_src_dentry);
20259 + if (a->bdst < a->bsrc
20260 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20261 + au_unpin(&a->pin);
20262 + di_write_unlock(a->parent);
20263 + err = au_cpup_before_link(src_dentry, a);
20264 + di_write_lock_parent(a->parent);
20266 + err = au_pin(&a->pin, dentry, a->bdst,
20268 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20269 + if (unlikely(err))
20273 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20275 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20276 + delegated = NULL;
20277 + err = vfsub_link(h_src_dentry,
20278 + au_pinned_h_dir(&a->pin),
20279 + &a->h_path, &delegated);
20280 + if (unlikely(err == -EWOULDBLOCK)) {
20281 + pr_warn("cannot retry"
20282 + " for NFSv4 delegation"
20283 + " for an internal link\n");
20289 + if (unlikely(err))
20293 + a->h_path.dentry = wh_dentry;
20294 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20296 + if (unlikely(err))
20300 + au_dir_ts(dir, a->bdst);
20301 + inode_inc_iversion(dir);
20302 + inc_nlink(inode);
20303 + inode->i_ctime = dir->i_ctime;
20304 + d_instantiate(dentry, au_igrab(inode));
20305 + if (d_unhashed(a->h_path.dentry))
20306 + /* some filesystem calls d_drop() */
20308 + /* some filesystems consume an inode even hardlink */
20309 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20310 + goto out_unpin; /* success */
20313 + /* no delegation since it is just created */
20314 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20315 + /*delegated*/NULL, /*force*/0);
20316 + if (unlikely(rerr)) {
20317 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20320 + au_dtime_revert(&dt);
20322 + au_unpin(&a->pin);
20326 + di_write_unlock(a->parent);
20327 + dput(a->src_parent);
20329 + if (unlikely(err)) {
20330 + au_update_dbtop(dentry);
20333 + aufs_read_and_write_unlock2(dentry, src_dentry);
20341 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20342 + struct dentry *dentry, umode_t mode)
20345 + aufs_bindex_t bindex;
20346 + unsigned char diropq;
20347 + struct path h_path;
20348 + struct dentry *wh_dentry, *parent, *opq_dentry;
20349 + struct inode *h_inode;
20350 + struct super_block *sb;
20352 + struct au_pin pin;
20353 + struct au_dtime dt;
20354 + } *a; /* reduce the stack usage */
20355 + struct au_wr_dir_args wr_dir_args = {
20356 + .force_btgt = -1,
20357 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20363 + a = kmalloc(sizeof(*a), GFP_NOFS);
20364 + if (unlikely(!a))
20367 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20368 + if (unlikely(err))
20370 + err = au_d_may_add(dentry);
20371 + if (unlikely(err))
20374 + parent = dentry->d_parent; /* dir inode is locked */
20375 + di_write_lock_parent(parent);
20376 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20377 + &a->pin, &wr_dir_args);
20378 + err = PTR_ERR(wh_dentry);
20379 + if (IS_ERR(wh_dentry))
20382 + sb = dentry->d_sb;
20383 + bindex = au_dbtop(dentry);
20384 + h_path.dentry = au_h_dptr(dentry, bindex);
20385 + h_path.mnt = au_sbr_mnt(sb, bindex);
20386 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20387 + if (unlikely(err))
20390 + /* make the dir opaque */
20392 + h_inode = d_inode(h_path.dentry);
20394 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20395 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20396 + opq_dentry = au_diropq_create(dentry, bindex);
20397 + inode_unlock(h_inode);
20398 + err = PTR_ERR(opq_dentry);
20399 + if (IS_ERR(opq_dentry))
20401 + dput(opq_dentry);
20405 + err = epilog(dir, bindex, wh_dentry, dentry);
20408 + goto out_unpin; /* success */
20413 + AuLabel(revert opq);
20414 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20415 + rerr = au_diropq_remove(dentry, bindex);
20416 + inode_unlock(h_inode);
20418 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20419 + dentry, err, rerr);
20425 + AuLabel(revert dir);
20426 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20428 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20429 + dentry, err, rerr);
20432 + au_dtime_revert(&a->dt);
20434 + au_unpin(&a->pin);
20437 + di_write_unlock(parent);
20439 + if (unlikely(err)) {
20440 + au_update_dbtop(dentry);
20443 + aufs_read_unlock(dentry, AuLock_DW);
20449 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20450 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20451 +++ linux/fs/aufs/i_op.c 2021-12-03 15:40:58.236647297 +0100
20453 +// SPDX-License-Identifier: GPL-2.0
20455 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20457 + * This program, aufs is free software; you can redistribute it and/or modify
20458 + * it under the terms of the GNU General Public License as published by
20459 + * the Free Software Foundation; either version 2 of the License, or
20460 + * (at your option) any later version.
20462 + * This program is distributed in the hope that it will be useful,
20463 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20464 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20465 + * GNU General Public License for more details.
20467 + * You should have received a copy of the GNU General Public License
20468 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20472 + * inode operations (except add/del/rename)
20475 +#include <linux/device_cgroup.h>
20476 +#include <linux/fs_stack.h>
20477 +#include <linux/iversion.h>
20478 +#include <linux/namei.h>
20479 +#include <linux/security.h>
20482 +static int h_permission(struct inode *h_inode, int mask,
20483 + struct path *h_path, int brperm)
20486 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20487 + struct user_namespace *h_userns;
20490 + if (write_mask && IS_IMMUTABLE(h_inode))
20494 + if (((mask & MAY_EXEC)
20495 + && S_ISREG(h_inode->i_mode)
20496 + && (path_noexec(h_path)
20497 + || !(h_inode->i_mode & 0111))))
20501 + * - skip the lower fs test in the case of write to ro branch.
20502 + * - nfs dir permission write check is optimized, but a policy for
20503 + * link/rename requires a real check.
20504 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20505 + * in this case, generic_permission() returns -EOPNOTSUPP.
20507 + h_userns = mnt_user_ns(h_path->mnt);
20508 + if ((write_mask && !au_br_writable(brperm))
20509 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20510 + && write_mask && !(mask & MAY_READ))
20511 + || !h_inode->i_op->permission) {
20512 + /* AuLabel(generic_permission); */
20513 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20514 + err = generic_permission(h_userns, h_inode, mask);
20515 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20516 + err = h_inode->i_op->permission(h_userns, h_inode,
20520 + /* AuLabel(h_inode->permission); */
20521 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
20526 + err = devcgroup_inode_permission(h_inode, mask);
20528 + err = security_inode_permission(h_inode, mask);
20534 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
20538 + aufs_bindex_t bindex, bbot;
20539 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20540 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20541 + struct inode *h_inode;
20542 + struct super_block *sb;
20543 + struct au_branch *br;
20545 + /* todo: support rcu-walk? */
20546 + if (mask & MAY_NOT_BLOCK)
20549 + sb = inode->i_sb;
20550 + si_read_lock(sb, AuLock_FLUSH);
20551 + ii_read_lock_child(inode);
20552 +#if 0 /* reserved for future use */
20554 + * This test may be rather 'too much' since the test is essentially done
20555 + * in the aufs_lookup(). Theoretically it is possible that the inode
20556 + * generation doesn't match to the superblock's here. But it isn't a
20557 + * big deal I suppose.
20559 + err = au_iigen_test(inode, au_sigen(sb));
20560 + if (unlikely(err))
20566 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20567 + err = au_busy_or_stale();
20568 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20569 + if (unlikely(!h_inode
20570 + || (h_inode->i_mode & S_IFMT)
20571 + != (inode->i_mode & S_IFMT)))
20575 + bindex = au_ibtop(inode);
20576 + br = au_sbr(sb, bindex);
20577 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20580 + && !special_file(h_inode->i_mode)) {
20581 + /* test whether the upper writable branch exists */
20583 + for (; bindex >= 0; bindex--)
20584 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20592 + /* non-write to dir */
20594 + bbot = au_ibbot(inode);
20595 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20596 + h_inode = au_h_iptr(inode, bindex);
20598 + err = au_busy_or_stale();
20599 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20602 + br = au_sbr(sb, bindex);
20603 + err = h_permission(h_inode, mask, &br->br_path,
20609 + ii_read_unlock(inode);
20610 + si_read_unlock(sb);
20614 +/* ---------------------------------------------------------------------- */
20616 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20617 + unsigned int flags)
20619 + struct dentry *ret, *parent;
20620 + struct inode *inode;
20621 + struct super_block *sb;
20622 + int err, npositive;
20626 + /* todo: support rcu-walk? */
20627 + ret = ERR_PTR(-ECHILD);
20628 + if (flags & LOOKUP_RCU)
20631 + ret = ERR_PTR(-ENAMETOOLONG);
20632 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20636 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20637 + ret = ERR_PTR(err);
20638 + if (unlikely(err))
20641 + err = au_di_init(dentry);
20642 + ret = ERR_PTR(err);
20643 + if (unlikely(err))
20647 + npositive = 0; /* suppress a warning */
20648 + parent = dentry->d_parent; /* dir inode is locked */
20649 + di_read_lock_parent(parent, AuLock_IR);
20650 + err = au_alive_dir(parent);
20652 + err = au_digen_test(parent, au_sigen(sb));
20654 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20655 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20656 + AuLkup_ALLOW_NEG);
20659 + di_read_unlock(parent, AuLock_IR);
20660 + ret = ERR_PTR(err);
20661 + if (unlikely(err < 0))
20665 + inode = au_new_inode(dentry, /*must_new*/0);
20666 + if (IS_ERR(inode)) {
20667 + ret = (void *)inode;
20674 + atomic_inc(&inode->i_count);
20675 + ret = d_splice_alias(inode, dentry);
20676 +#if 0 /* reserved for future use */
20677 + if (unlikely(d_need_lookup(dentry))) {
20678 + spin_lock(&dentry->d_lock);
20679 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20680 + spin_unlock(&dentry->d_lock);
20684 + if (!IS_ERR(ret)) {
20686 + if (ret && ret != dentry)
20687 + ii_write_unlock(inode);
20689 + ii_write_unlock(inode);
20696 + di_write_unlock(dentry);
20698 + si_read_unlock(sb);
20703 +/* ---------------------------------------------------------------------- */
20706 + * very dirty and complicated aufs ->atomic_open().
20707 + * aufs_atomic_open()
20708 + * + au_aopen_or_create()
20710 + * + vfsub_atomic_open()
20711 + * + branch fs ->atomic_open()
20712 + * may call the actual 'open' for h_file
20713 + * + inc br_nfiles only if opened
20714 + * + au_aopen_no_open() or au_aopen_do_open()
20716 + * au_aopen_do_open()
20717 + * + finish_open()
20718 + * + au_do_aopen()
20719 + * + au_do_open() the body of all 'open'
20720 + * + au_do_open_nondir()
20721 + * set the passed h_file
20723 + * au_aopen_no_open()
20724 + * + finish_no_open()
20727 +struct aopen_node {
20728 + struct hlist_bl_node hblist;
20729 + struct file *file, *h_file;
20732 +static int au_do_aopen(struct inode *inode, struct file *file)
20734 + struct hlist_bl_head *aopen;
20735 + struct hlist_bl_node *pos;
20736 + struct aopen_node *node;
20737 + struct au_do_open_args args = {
20739 + .open = au_do_open_nondir
20742 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20743 + hlist_bl_lock(aopen);
20744 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20745 + if (node->file == file) {
20746 + args.h_file = node->h_file;
20749 + hlist_bl_unlock(aopen);
20750 + /* AuDebugOn(!args.h_file); */
20752 + return au_do_open(file, &args);
20755 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20756 + struct aopen_node *aopen_node)
20759 + struct hlist_bl_head *aopen;
20762 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20763 + au_hbl_add(&aopen_node->hblist, aopen);
20764 + err = finish_open(file, dentry, au_do_aopen);
20765 + au_hbl_del(&aopen_node->hblist, aopen);
20766 + /* AuDbgFile(file); */
20767 + AuDbg("%pd%s%s\n", dentry,
20768 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20769 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20775 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20781 + err = finish_no_open(file, dentry);
20787 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20788 + struct file *file, unsigned int open_flag,
20789 + umode_t create_mode)
20791 + int err, did_open;
20792 + unsigned int lkup_flags;
20793 + aufs_bindex_t bindex;
20794 + struct super_block *sb;
20795 + struct dentry *parent, *d;
20796 + struct vfsub_aopen_args args = {
20797 + .open_flag = open_flag,
20798 + .create_mode = create_mode
20800 + struct aopen_node aopen_node = {
20805 + AuDbg("open_flag 0%o\n", open_flag);
20806 + AuDbgDentry(dentry);
20809 + if (!au_di(dentry)) {
20810 + lkup_flags = LOOKUP_OPEN;
20811 + if (open_flag & O_CREAT)
20812 + lkup_flags |= LOOKUP_CREATE;
20813 + d = aufs_lookup(dir, dentry, lkup_flags);
20815 + err = PTR_ERR(d);
20820 + * obsoleted dentry found.
20821 + * another error will be returned later.
20827 + AuDbgDentry(dentry);
20830 + if (d_is_positive(dentry)
20831 + || d_unhashed(dentry)
20832 + || d_unlinked(dentry)
20833 + || !(open_flag & O_CREAT)) {
20834 + err = au_aopen_no_open(file, dentry);
20835 + goto out; /* success */
20838 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20839 + if (unlikely(err))
20842 + sb = dentry->d_sb;
20843 + parent = dentry->d_parent; /* dir is locked */
20844 + di_write_lock_parent(parent);
20845 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20846 + if (unlikely(err < 0))
20849 + AuDbgDentry(dentry);
20850 + if (d_is_positive(dentry)) {
20851 + err = au_aopen_no_open(file, dentry);
20852 + goto out_parent; /* success */
20855 + args.file = alloc_empty_file(file->f_flags, current_cred());
20856 + err = PTR_ERR(args.file);
20857 + if (IS_ERR(args.file))
20860 + bindex = au_dbtop(dentry);
20861 + err = au_aopen_or_create(dir, dentry, &args);
20863 + AuDbgFile(args.file);
20864 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20865 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20868 + args.file = NULL;
20870 + di_write_unlock(parent);
20871 + di_write_unlock(dentry);
20872 + if (unlikely(err < 0)) {
20879 + err = au_aopen_no_open(file, dentry);
20881 + aopen_node.h_file = args.file;
20882 + err = au_aopen_do_open(file, dentry, &aopen_node);
20884 + if (unlikely(err < 0)) {
20888 + au_lcnt_dec(&args.br->br_nfiles);
20890 + goto out_sb; /* success */
20893 + di_write_unlock(parent);
20894 + di_write_unlock(dentry);
20896 + si_read_unlock(sb);
20904 +/* ---------------------------------------------------------------------- */
20906 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20907 + const unsigned char add_entry, aufs_bindex_t bcpup,
20908 + aufs_bindex_t btop)
20911 + struct dentry *h_parent;
20912 + struct inode *h_dir;
20915 + IMustLock(d_inode(parent));
20917 + di_write_lock_parent(parent);
20920 + if (!au_h_dptr(parent, bcpup)) {
20921 + if (btop > bcpup)
20922 + err = au_cpup_dirs(dentry, bcpup);
20923 + else if (btop < bcpup)
20924 + err = au_cpdown_dirs(dentry, bcpup);
20928 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20929 + h_parent = au_h_dptr(parent, bcpup);
20930 + h_dir = d_inode(h_parent);
20931 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20932 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20933 + /* todo: no unlock here */
20934 + inode_unlock_shared(h_dir);
20936 + AuDbg("bcpup %d\n", bcpup);
20938 + if (d_really_is_negative(dentry))
20939 + au_set_h_dptr(dentry, btop, NULL);
20940 + au_update_dbrange(dentry, /*do_put_zero*/0);
20945 + di_write_unlock(parent);
20947 + err = bcpup; /* success */
20954 + * decide the branch and the parent dir where we will create a new entry.
20955 + * returns new bindex or an error.
20956 + * copyup the parent dir if needed.
20958 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20959 + struct au_wr_dir_args *args)
20962 + unsigned int flags;
20963 + aufs_bindex_t bcpup, btop, src_btop;
20964 + const unsigned char add_entry
20965 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20966 + | au_ftest_wrdir(args->flags, TMPFILE);
20967 + struct super_block *sb;
20968 + struct dentry *parent;
20969 + struct au_sbinfo *sbinfo;
20971 + sb = dentry->d_sb;
20972 + sbinfo = au_sbi(sb);
20973 + parent = dget_parent(dentry);
20974 + btop = au_dbtop(dentry);
20976 + if (args->force_btgt < 0) {
20977 + if (src_dentry) {
20978 + src_btop = au_dbtop(src_dentry);
20979 + if (src_btop < btop)
20980 + bcpup = src_btop;
20981 + } else if (add_entry) {
20983 + if (au_ftest_wrdir(args->flags, ISDIR))
20984 + au_fset_wbr(flags, DIR);
20985 + err = AuWbrCreate(sbinfo, dentry, flags);
20989 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20991 + err = AuWbrCopyup(sbinfo, dentry);
20993 + if (!IS_ROOT(dentry)) {
20994 + di_read_lock_parent(parent, !AuLock_IR);
20995 + err = AuWbrCopyup(sbinfo, dentry);
20996 + di_read_unlock(parent, !AuLock_IR);
20998 + err = AuWbrCopyup(sbinfo, dentry);
21001 + if (unlikely(err < 0))
21005 + bcpup = args->force_btgt;
21006 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21009 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21011 + if (bcpup == btop)
21012 + goto out; /* success */
21014 + /* copyup the new parent into the branch we process */
21015 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21017 + if (d_really_is_negative(dentry)) {
21018 + au_set_h_dptr(dentry, btop, NULL);
21019 + au_set_dbtop(dentry, bcpup);
21020 + au_set_dbbot(dentry, bcpup);
21022 + AuDebugOn(add_entry
21023 + && !au_ftest_wrdir(args->flags, TMPFILE)
21024 + && !au_h_dptr(dentry, bcpup));
21032 +/* ---------------------------------------------------------------------- */
21034 +void au_pin_hdir_unlock(struct au_pin *p)
21037 + au_hn_inode_unlock(p->hdir);
21040 +int au_pin_hdir_lock(struct au_pin *p)
21048 + /* even if an error happens later, keep this lock */
21049 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21052 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21057 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21058 + p->h_parent, p->br);
21064 +int au_pin_hdir_relock(struct au_pin *p)
21067 + struct inode *h_i;
21068 + struct dentry *h_d[] = {
21073 + err = au_pin_hdir_lock(p);
21074 + if (unlikely(err))
21077 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21080 + if (d_is_positive(h_d[i])) {
21081 + h_i = d_inode(h_d[i]);
21082 + err = !h_i->i_nlink;
21090 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21092 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21095 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21098 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21099 + p->lsc_hi, 0, NULL, _RET_IP_);
21100 + au_pin_hdir_set_owner(p, current);
21104 +void au_pin_hdir_release(struct au_pin *p)
21107 + au_pin_hdir_set_owner(p, p->task);
21108 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21112 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21114 + if (pin && pin->parent)
21115 + return au_h_dptr(pin->parent, pin->bindex);
21119 +void au_unpin(struct au_pin *p)
21122 + au_pin_hdir_unlock(p);
21123 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21124 + vfsub_mnt_drop_write(p->h_mnt);
21128 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21129 + di_read_unlock(p->parent, AuLock_IR);
21130 + iput(p->hdir->hi_inode);
21132 + p->parent = NULL;
21135 + /* do not clear p->task */
21138 +int au_do_pin(struct au_pin *p)
21141 + struct super_block *sb;
21142 + struct inode *h_dir;
21145 + sb = p->dentry->d_sb;
21146 + p->br = au_sbr(sb, p->bindex);
21147 + if (IS_ROOT(p->dentry)) {
21148 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21149 + p->h_mnt = au_br_mnt(p->br);
21150 + err = vfsub_mnt_want_write(p->h_mnt);
21151 + if (unlikely(err)) {
21152 + au_fclr_pin(p->flags, MNT_WRITE);
21159 + p->h_dentry = NULL;
21160 + if (p->bindex <= au_dbbot(p->dentry))
21161 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21163 + p->parent = dget_parent(p->dentry);
21164 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21165 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21168 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21169 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21171 + h_dir = p->hdir->hi_inode;
21175 + * if DI_LOCKED is not set, then p->parent may be different
21176 + * and h_parent can be NULL.
21178 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21180 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21181 + di_read_unlock(p->parent, AuLock_IR);
21183 + p->parent = NULL;
21187 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21188 + p->h_mnt = au_br_mnt(p->br);
21189 + err = vfsub_mnt_want_write(p->h_mnt);
21190 + if (unlikely(err)) {
21191 + au_fclr_pin(p->flags, MNT_WRITE);
21192 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21193 + di_read_unlock(p->parent, AuLock_IR);
21195 + p->parent = NULL;
21201 + err = au_pin_hdir_lock(p);
21203 + goto out; /* success */
21208 + pr_err("err %d\n", err);
21209 + err = au_busy_or_stale();
21214 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21215 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21216 + unsigned int udba, unsigned char flags)
21218 + p->dentry = dentry;
21220 + p->lsc_di = lsc_di;
21221 + p->lsc_hi = lsc_hi;
21222 + p->flags = flags;
21223 + p->bindex = bindex;
21225 + p->parent = NULL;
21229 + p->h_dentry = NULL;
21230 + p->h_parent = NULL;
21232 + p->task = current;
21235 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21236 + unsigned int udba, unsigned char flags)
21238 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21240 + return au_do_pin(pin);
21243 +/* ---------------------------------------------------------------------- */
21246 + * ->setattr() and ->getattr() are called in various cases.
21247 + * chmod, stat: dentry is revalidated.
21248 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21250 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21252 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21253 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21256 + struct dentry *parent;
21259 + if (au_digen_test(dentry, sigen)) {
21260 + parent = dget_parent(dentry);
21261 + di_read_lock_parent(parent, AuLock_IR);
21262 + err = au_refresh_dentry(dentry, parent);
21263 + di_read_unlock(parent, AuLock_IR);
21271 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21272 + struct au_icpup_args *a)
21276 + aufs_bindex_t btop, ibtop;
21277 + struct dentry *hi_wh, *parent;
21278 + struct inode *inode;
21279 + struct au_wr_dir_args wr_dir_args = {
21280 + .force_btgt = -1,
21284 + if (d_is_dir(dentry))
21285 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21286 + /* plink or hi_wh() case */
21287 + btop = au_dbtop(dentry);
21288 + inode = d_inode(dentry);
21289 + ibtop = au_ibtop(inode);
21290 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21291 + wr_dir_args.force_btgt = ibtop;
21292 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21293 + if (unlikely(err < 0))
21297 + au_fset_icpup(a->flags, DID_CPUP);
21300 + a->pin_flags = AuPin_MNT_WRITE;
21302 + if (!IS_ROOT(dentry)) {
21303 + au_fset_pin(a->pin_flags, DI_LOCKED);
21304 + parent = dget_parent(dentry);
21305 + di_write_lock_parent(parent);
21308 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21309 + if (unlikely(err))
21313 + a->h_path.dentry = au_h_dptr(dentry, btop);
21314 + a->h_inode = d_inode(a->h_path.dentry);
21315 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21316 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21317 + if (ia->ia_size < i_size_read(a->h_inode))
21318 + sz = ia->ia_size;
21319 + inode_unlock_shared(a->h_inode);
21323 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21324 + hi_wh = au_hi_wh(inode, a->btgt);
21326 + struct au_cp_generic cpg = {
21327 + .dentry = dentry,
21333 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21334 + if (unlikely(err))
21336 + hi_wh = au_hi_wh(inode, a->btgt);
21337 + /* todo: revalidate hi_wh? */
21342 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21343 + di_downgrade_lock(parent, AuLock_IR);
21347 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21348 + goto out; /* success */
21350 + if (!d_unhashed(dentry)) {
21351 + struct au_cp_generic cpg = {
21352 + .dentry = dentry,
21357 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21359 + err = au_sio_cpup_simple(&cpg);
21361 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21362 + } else if (!hi_wh)
21363 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21365 + a->h_path.dentry = hi_wh; /* do not dget here */
21368 + a->h_inode = d_inode(a->h_path.dentry);
21370 + goto out; /* success */
21371 + au_unpin(&a->pin);
21374 + di_write_unlock(parent);
21379 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21383 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
21384 + struct iattr *ia)
21387 + struct inode *inode, *delegated;
21388 + struct super_block *sb;
21389 + struct file *file;
21390 + struct au_icpup_args *a;
21391 + struct user_namespace *h_userns;
21393 + inode = d_inode(dentry);
21394 + IMustLock(inode);
21396 + err = setattr_prepare(userns, dentry, ia);
21397 + if (unlikely(err))
21401 + a = kzalloc(sizeof(*a), GFP_NOFS);
21402 + if (unlikely(!a))
21405 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21406 + ia->ia_valid &= ~ATTR_MODE;
21409 + sb = dentry->d_sb;
21410 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21411 + if (unlikely(err))
21414 + if (ia->ia_valid & ATTR_FILE) {
21415 + /* currently ftruncate(2) only */
21416 + AuDebugOn(!d_is_reg(dentry));
21417 + file = ia->ia_file;
21418 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21420 + if (unlikely(err))
21422 + ia->ia_file = au_hf_top(file);
21423 + a->udba = AuOpt_UDBA_NONE;
21425 + /* fchmod() doesn't pass ia_file */
21426 + a->udba = au_opt_udba(sb);
21427 + di_write_lock_child(dentry);
21428 + /* no d_unlinked(), to set UDBA_NONE for root */
21429 + if (d_unhashed(dentry))
21430 + a->udba = AuOpt_UDBA_NONE;
21431 + if (a->udba != AuOpt_UDBA_NONE) {
21432 + AuDebugOn(IS_ROOT(dentry));
21433 + err = au_reval_for_attr(dentry, au_sigen(sb));
21434 + if (unlikely(err))
21439 + err = au_pin_and_icpup(dentry, ia, a);
21440 + if (unlikely(err < 0))
21442 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21443 + ia->ia_file = NULL;
21444 + ia->ia_valid &= ~ATTR_FILE;
21447 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21448 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21449 + == (ATTR_MODE | ATTR_CTIME)) {
21450 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21451 + if (unlikely(err))
21453 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21454 + && (ia->ia_valid & ATTR_CTIME)) {
21455 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21456 + if (unlikely(err))
21460 + if (ia->ia_valid & ATTR_SIZE) {
21463 + if (ia->ia_size < i_size_read(inode))
21465 + truncate_setsize(inode, ia->ia_size);
21468 + if (ia->ia_valid & ATTR_FILE)
21470 + inode_unlock(a->h_inode);
21471 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21472 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21474 + delegated = NULL;
21476 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21478 + err = break_deleg_wait(&delegated);
21486 + * regardless aufs 'acl' option setting.
21487 + * why don't all acl-aware fs call this func from their ->setattr()?
21489 + if (!err && (ia->ia_valid & ATTR_MODE)) {
21490 + h_userns = mnt_user_ns(a->h_path.mnt);
21491 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
21494 + au_cpup_attr_changeable(inode);
21497 + inode_unlock(a->h_inode);
21498 + au_unpin(&a->pin);
21499 + if (unlikely(err))
21500 + au_update_dbtop(dentry);
21502 + di_write_unlock(dentry);
21504 + fi_write_unlock(file);
21505 + ia->ia_file = file;
21506 + ia->ia_valid |= ATTR_FILE;
21509 + si_read_unlock(sb);
21517 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21518 +static int au_h_path_to_set_attr(struct dentry *dentry,
21519 + struct au_icpup_args *a, struct path *h_path)
21522 + struct super_block *sb;
21524 + sb = dentry->d_sb;
21525 + a->udba = au_opt_udba(sb);
21526 + /* no d_unlinked(), to set UDBA_NONE for root */
21527 + if (d_unhashed(dentry))
21528 + a->udba = AuOpt_UDBA_NONE;
21529 + if (a->udba != AuOpt_UDBA_NONE) {
21530 + AuDebugOn(IS_ROOT(dentry));
21531 + err = au_reval_for_attr(dentry, au_sigen(sb));
21532 + if (unlikely(err))
21535 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21536 + if (unlikely(err < 0))
21539 + h_path->dentry = a->h_path.dentry;
21540 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21546 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21547 + struct au_sxattr *arg)
21550 + struct path h_path;
21551 + struct super_block *sb;
21552 + struct au_icpup_args *a;
21553 + struct inode *h_inode;
21554 + struct user_namespace *h_userns;
21556 + IMustLock(inode);
21559 + a = kzalloc(sizeof(*a), GFP_NOFS);
21560 + if (unlikely(!a))
21563 + sb = dentry->d_sb;
21564 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21565 + if (unlikely(err))
21568 + h_path.dentry = NULL; /* silence gcc */
21569 + di_write_lock_child(dentry);
21570 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21571 + if (unlikely(err))
21573 + h_userns = mnt_user_ns(h_path.mnt);
21575 + inode_unlock(a->h_inode);
21576 + switch (arg->type) {
21577 + case AU_XATTR_SET:
21578 + AuDebugOn(d_is_negative(h_path.dentry));
21579 + err = vfsub_setxattr(h_userns, h_path.dentry,
21580 + arg->u.set.name, arg->u.set.value,
21581 + arg->u.set.size, arg->u.set.flags);
21584 + err = -EOPNOTSUPP;
21585 + h_inode = d_inode(h_path.dentry);
21586 + if (h_inode->i_op->set_acl) {
21587 + /* this will call posix_acl_update_mode */
21588 + err = h_inode->i_op->set_acl(h_userns, h_inode,
21589 + arg->u.acl_set.acl,
21590 + arg->u.acl_set.type);
21595 + au_cpup_attr_timesizes(inode);
21597 + au_unpin(&a->pin);
21598 + if (unlikely(err))
21599 + au_update_dbtop(dentry);
21602 + di_write_unlock(dentry);
21603 + si_read_unlock(sb);
21612 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21613 + unsigned int nlink)
21617 + inode->i_mode = st->mode;
21618 + /* don't i_[ug]id_write() here */
21619 + inode->i_uid = st->uid;
21620 + inode->i_gid = st->gid;
21621 + inode->i_atime = st->atime;
21622 + inode->i_mtime = st->mtime;
21623 + inode->i_ctime = st->ctime;
21625 + au_cpup_attr_nlink(inode, /*force*/0);
21626 + if (S_ISDIR(inode->i_mode)) {
21627 + n = inode->i_nlink;
21630 + smp_mb(); /* for i_nlink */
21631 + /* 0 can happen */
21632 + set_nlink(inode, n);
21635 + spin_lock(&inode->i_lock);
21636 + inode->i_blocks = st->blocks;
21637 + i_size_write(inode, st->size);
21638 + spin_unlock(&inode->i_lock);
21642 + * common routine for aufs_getattr() and au_getxattr().
21643 + * returns zero or negative (an error).
21644 + * @dentry will be read-locked in success.
21646 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21647 + struct path *h_path, int locked)
21650 + unsigned int mnt_flags, sigen;
21651 + unsigned char udba_none;
21652 + aufs_bindex_t bindex;
21653 + struct super_block *sb, *h_sb;
21655 + h_path->mnt = NULL;
21656 + h_path->dentry = NULL;
21659 + sb = dentry->d_sb;
21660 + mnt_flags = au_mntflags(sb);
21661 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21663 + if (unlikely(locked))
21664 + goto body; /* skip locking dinfo */
21666 + /* support fstat(2) */
21667 + if (!d_unlinked(dentry) && !udba_none) {
21668 + sigen = au_sigen(sb);
21669 + err = au_digen_test(dentry, sigen);
21671 + di_read_lock_child(dentry, AuLock_IR);
21672 + err = au_dbrange_test(dentry);
21673 + if (unlikely(err)) {
21674 + di_read_unlock(dentry, AuLock_IR);
21678 + AuDebugOn(IS_ROOT(dentry));
21679 + di_write_lock_child(dentry);
21680 + err = au_dbrange_test(dentry);
21682 + err = au_reval_for_attr(dentry, sigen);
21684 + di_downgrade_lock(dentry, AuLock_IR);
21686 + di_write_unlock(dentry);
21691 + di_read_lock_child(dentry, AuLock_IR);
21695 + inode = d_inode(dentry);
21696 + if (unlikely(!inode))
21699 + bindex = au_ibtop(inode);
21700 + h_path->mnt = au_sbr_mnt(sb, bindex);
21701 + h_sb = h_path->mnt->mnt_sb;
21703 + && !au_test_fs_bad_iattr(h_sb)
21705 + goto out; /* success */
21707 + if (au_dbtop(dentry) == bindex)
21708 + h_path->dentry = au_h_dptr(dentry, bindex);
21709 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21710 + h_path->dentry = au_plink_lkup(inode, bindex);
21711 + if (IS_ERR(h_path->dentry))
21712 + /* pretending success */
21713 + h_path->dentry = NULL;
21715 + dput(h_path->dentry);
21722 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
21723 + struct kstat *st, u32 request, unsigned int query)
21726 + unsigned char positive;
21727 + struct path h_path;
21728 + struct dentry *dentry;
21729 + struct inode *inode;
21730 + struct super_block *sb;
21732 + dentry = path->dentry;
21733 + inode = d_inode(dentry);
21734 + sb = dentry->d_sb;
21735 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21736 + if (unlikely(err))
21738 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21740 + if (unlikely(err))
21742 + if (unlikely(!h_path.dentry))
21743 + /* illegally overlapped or something */
21744 + goto out_fill; /* pretending success */
21746 + positive = d_is_positive(h_path.dentry);
21748 + /* no vfsub version */
21749 + err = vfs_getattr(&h_path, st, request, query);
21752 + au_refresh_iattr(inode, st,
21753 + d_inode(h_path.dentry)->i_nlink);
21754 + goto out_fill; /* success */
21760 + generic_fillattr(userns, inode, st);
21762 + di_read_unlock(dentry, AuLock_IR);
21764 + si_read_unlock(sb);
21770 +/* ---------------------------------------------------------------------- */
21772 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21773 + struct delayed_call *done)
21776 + struct dentry *h_dentry;
21777 + struct inode *h_inode;
21779 + aufs_bindex_t bindex;
21781 + ret = NULL; /* suppress a warning */
21786 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21787 + if (unlikely(err))
21790 + err = au_d_hashed_positive(dentry);
21791 + if (unlikely(err))
21795 + inode = d_inode(dentry);
21796 + bindex = au_ibtop(inode);
21797 + h_inode = au_h_iptr(inode, bindex);
21798 + if (unlikely(!h_inode->i_op->get_link))
21803 + if (au_dbtop(dentry) <= bindex) {
21804 + h_dentry = au_h_dptr(dentry, bindex);
21809 + h_dentry = d_find_any_alias(h_inode);
21810 + if (IS_ERR(h_dentry)) {
21811 + err = PTR_ERR(h_dentry);
21815 + if (unlikely(!h_dentry))
21819 + AuDbg("%ps\n", h_inode->i_op->get_link);
21820 + AuDbgDentry(h_dentry);
21821 + ret = vfs_get_link(h_dentry, done);
21824 + err = PTR_ERR(ret);
21827 + aufs_read_unlock(dentry, AuLock_IR);
21829 + if (unlikely(err))
21830 + ret = ERR_PTR(err);
21831 + AuTraceErrPtr(ret);
21835 +/* ---------------------------------------------------------------------- */
21837 +static int au_is_special(struct inode *inode)
21839 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21842 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21846 + aufs_bindex_t bindex;
21847 + struct super_block *sb;
21848 + struct inode *h_inode;
21849 + struct vfsmount *h_mnt;
21851 + sb = inode->i_sb;
21852 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21853 + "unexpected s_flags 0x%lx", sb->s_flags);
21855 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21857 + si_read_lock(sb, AuLock_FLUSH);
21858 + ii_write_lock_child(inode);
21861 + bindex = au_ibtop(inode);
21862 + h_inode = au_h_iptr(inode, bindex);
21863 + if (!au_test_ro(sb, bindex, inode)) {
21864 + h_mnt = au_sbr_mnt(sb, bindex);
21865 + err = vfsub_mnt_want_write(h_mnt);
21867 + err = vfsub_update_time(h_inode, ts, flags);
21868 + vfsub_mnt_drop_write(h_mnt);
21870 + } else if (au_is_special(h_inode)) {
21872 + * Never copy-up here.
21873 + * These special files may already be opened and used for
21874 + * communicating. If we copied it up, then the communication
21875 + * would be corrupted.
21877 + AuWarn1("timestamps for i%lu are ignored "
21878 + "since it is on readonly branch (hi%lu).\n",
21879 + inode->i_ino, h_inode->i_ino);
21880 + } else if (flags & ~S_ATIME) {
21882 + AuIOErr1("unexpected flags 0x%x\n", flags);
21887 + au_cpup_attr_timesizes(inode);
21888 + ii_write_unlock(inode);
21889 + si_read_unlock(sb);
21892 + if (!err && (flags & S_VERSION))
21893 + inode_inc_iversion(inode);
21898 +/* ---------------------------------------------------------------------- */
21900 +/* no getattr version will be set by module.c:aufs_init() */
21901 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21903 + [AuIop_SYMLINK] = {
21904 + .permission = aufs_permission,
21905 +#ifdef CONFIG_FS_POSIX_ACL
21906 + .get_acl = aufs_get_acl,
21907 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21910 + .setattr = aufs_setattr,
21911 + .getattr = aufs_getattr,
21913 +#ifdef CONFIG_AUFS_XATTR
21914 + .listxattr = aufs_listxattr,
21917 + .get_link = aufs_get_link,
21919 + /* .update_time = aufs_update_time */
21922 + .create = aufs_create,
21923 + .lookup = aufs_lookup,
21924 + .link = aufs_link,
21925 + .unlink = aufs_unlink,
21926 + .symlink = aufs_symlink,
21927 + .mkdir = aufs_mkdir,
21928 + .rmdir = aufs_rmdir,
21929 + .mknod = aufs_mknod,
21930 + .rename = aufs_rename,
21932 + .permission = aufs_permission,
21933 +#ifdef CONFIG_FS_POSIX_ACL
21934 + .get_acl = aufs_get_acl,
21935 + .set_acl = aufs_set_acl,
21938 + .setattr = aufs_setattr,
21939 + .getattr = aufs_getattr,
21941 +#ifdef CONFIG_AUFS_XATTR
21942 + .listxattr = aufs_listxattr,
21945 + .update_time = aufs_update_time,
21946 + .atomic_open = aufs_atomic_open,
21947 + .tmpfile = aufs_tmpfile
21949 + [AuIop_OTHER] = {
21950 + .permission = aufs_permission,
21951 +#ifdef CONFIG_FS_POSIX_ACL
21952 + .get_acl = aufs_get_acl,
21953 + .set_acl = aufs_set_acl,
21956 + .setattr = aufs_setattr,
21957 + .getattr = aufs_getattr,
21959 +#ifdef CONFIG_AUFS_XATTR
21960 + .listxattr = aufs_listxattr,
21963 + .update_time = aufs_update_time
21966 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21967 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21968 +++ linux/fs/aufs/i_op_del.c 2021-12-03 15:40:58.236647297 +0100
21970 +// SPDX-License-Identifier: GPL-2.0
21972 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21974 + * This program, aufs is free software; you can redistribute it and/or modify
21975 + * it under the terms of the GNU General Public License as published by
21976 + * the Free Software Foundation; either version 2 of the License, or
21977 + * (at your option) any later version.
21979 + * This program is distributed in the hope that it will be useful,
21980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21982 + * GNU General Public License for more details.
21984 + * You should have received a copy of the GNU General Public License
21985 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21989 + * inode operations (del entry)
21992 +#include <linux/iversion.h>
21996 + * decide if a new whiteout for @dentry is necessary or not.
21997 + * when it is necessary, prepare the parent dir for the upper branch whose
21998 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21999 + * be done by caller.
22001 + * 0: wh is unnecessary
22002 + * plus: wh is necessary
22005 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22007 + int need_wh, err;
22008 + aufs_bindex_t btop;
22009 + struct super_block *sb;
22011 + sb = dentry->d_sb;
22012 + btop = au_dbtop(dentry);
22013 + if (*bcpup < 0) {
22015 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22016 + err = AuWbrCopyup(au_sbi(sb), dentry);
22018 + if (unlikely(err < 0))
22022 + AuDebugOn(btop < *bcpup
22023 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22024 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22026 + if (*bcpup != btop) {
22027 + err = au_cpup_dirs(dentry, *bcpup);
22028 + if (unlikely(err))
22032 + struct au_dinfo *dinfo, *tmp;
22034 + need_wh = -ENOMEM;
22035 + dinfo = au_di(dentry);
22036 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22038 + au_di_cp(tmp, dinfo);
22039 + au_di_swap(tmp, dinfo);
22040 + /* returns the number of positive dentries */
22041 + need_wh = au_lkup_dentry(dentry, btop + 1,
22042 + /* AuLkup_IGNORE_PERM */ 0);
22043 + au_di_swap(tmp, dinfo);
22044 + au_rw_write_unlock(&tmp->di_rwsem);
22048 + AuDbg("need_wh %d\n", need_wh);
22056 + * simple tests for the del-entry operations.
22057 + * following the checks in vfs, plus the parent-child relationship.
22059 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22060 + struct dentry *h_parent, int isdir)
22064 + struct dentry *h_dentry, *h_latest;
22065 + struct inode *h_inode;
22066 + struct path h_ppath;
22067 + struct super_block *sb;
22068 + struct au_branch *br;
22069 + struct user_namespace *h_userns;
22071 + h_dentry = au_h_dptr(dentry, bindex);
22072 + if (d_really_is_positive(dentry)) {
22074 + if (unlikely(d_is_negative(h_dentry)))
22076 + h_inode = d_inode(h_dentry);
22077 + if (unlikely(!h_inode->i_nlink))
22080 + h_mode = h_inode->i_mode;
22083 + if (unlikely(S_ISDIR(h_mode)))
22085 + } else if (unlikely(!S_ISDIR(h_mode))) {
22090 + /* rename(2) case */
22092 + if (unlikely(d_is_positive(h_dentry)))
22097 + /* expected parent dir is locked */
22098 + if (unlikely(h_parent != h_dentry->d_parent))
22103 + * rmdir a dir may break the consistency on some filesystem.
22104 + * let's try heavy test.
22107 + sb = dentry->d_sb;
22108 + br = au_sbr(sb, bindex);
22109 + h_userns = au_br_userns(br);
22110 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
22111 + && au_test_h_perm(h_userns, d_inode(h_parent),
22112 + MAY_EXEC | MAY_WRITE)))
22115 + h_ppath.dentry = h_parent;
22116 + h_ppath.mnt = au_br_mnt(br);
22117 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
22119 + if (IS_ERR(h_latest))
22121 + if (h_latest == h_dentry)
22130 + * decide the branch where we operate for @dentry. the branch index will be set
22131 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22132 + * dir for reverting.
22133 + * when a new whiteout is necessary, create it.
22135 +static struct dentry*
22136 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22137 + struct au_dtime *dt, struct au_pin *pin)
22139 + struct dentry *wh_dentry;
22140 + struct super_block *sb;
22141 + struct path h_path;
22142 + int err, need_wh;
22143 + unsigned int udba;
22144 + aufs_bindex_t bcpup;
22146 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22147 + wh_dentry = ERR_PTR(need_wh);
22148 + if (unlikely(need_wh < 0))
22151 + sb = dentry->d_sb;
22152 + udba = au_opt_udba(sb);
22154 + err = au_pin(pin, dentry, bcpup, udba,
22155 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22156 + wh_dentry = ERR_PTR(err);
22157 + if (unlikely(err))
22160 + h_path.dentry = au_pinned_h_parent(pin);
22161 + if (udba != AuOpt_UDBA_NONE
22162 + && au_dbtop(dentry) == bcpup) {
22163 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22164 + wh_dentry = ERR_PTR(err);
22165 + if (unlikely(err))
22169 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22170 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22171 + wh_dentry = NULL;
22173 + goto out; /* success, no need to create whiteout */
22175 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22176 + if (IS_ERR(wh_dentry))
22179 + /* returns with the parent is locked and wh_dentry is dget-ed */
22180 + goto out; /* success */
22185 + return wh_dentry;
22189 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22190 + * in order to be revertible and save time for removing many child whiteouts
22192 + * returns 1 when there are too many child whiteout and caller should remove
22193 + * them asynchronously. returns 0 when the number of children is enough small to
22194 + * remove now or the branch fs is a remote fs.
22195 + * otherwise return an error.
22197 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22198 + struct au_nhash *whlist, struct inode *dir)
22200 + int rmdir_later, err, dirwh;
22201 + struct dentry *h_dentry;
22202 + struct super_block *sb;
22203 + struct inode *inode;
22205 + sb = dentry->d_sb;
22206 + SiMustAnyLock(sb);
22207 + h_dentry = au_h_dptr(dentry, bindex);
22208 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22209 + if (unlikely(err))
22212 + /* stop monitoring */
22213 + inode = d_inode(dentry);
22214 + au_hn_free(au_hi(inode, bindex));
22216 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22217 + dirwh = au_sbi(sb)->si_dirwh;
22218 + rmdir_later = (dirwh <= 1);
22219 + if (!rmdir_later)
22220 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22223 + return rmdir_later;
22226 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22227 + if (unlikely(err)) {
22228 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22229 + h_dentry, bindex, err);
22239 + * final procedure for deleting a entry.
22240 + * maintain dentry and iattr.
22242 +static void epilog(struct inode *dir, struct dentry *dentry,
22243 + aufs_bindex_t bindex)
22245 + struct inode *inode;
22247 + inode = d_inode(dentry);
22249 + inode->i_ctime = dir->i_ctime;
22251 + au_dir_ts(dir, bindex);
22252 + inode_inc_iversion(dir);
22256 + * when an error happened, remove the created whiteout and revert everything.
22258 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22259 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22260 + struct dentry *dentry, struct au_dtime *dt)
22263 + struct path h_path = {
22264 + .dentry = wh_dentry,
22265 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22268 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22270 + au_set_dbwh(dentry, bwh);
22271 + au_dtime_revert(dt);
22275 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22279 +/* ---------------------------------------------------------------------- */
22281 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22284 + aufs_bindex_t bwh, bindex, btop;
22285 + struct inode *inode, *h_dir, *delegated;
22286 + struct dentry *parent, *wh_dentry;
22287 + /* to reduce stack size */
22289 + struct au_dtime dt;
22290 + struct au_pin pin;
22291 + struct path h_path;
22297 + a = kmalloc(sizeof(*a), GFP_NOFS);
22298 + if (unlikely(!a))
22301 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22302 + if (unlikely(err))
22304 + err = au_d_hashed_positive(dentry);
22305 + if (unlikely(err))
22307 + inode = d_inode(dentry);
22308 + IMustLock(inode);
22310 + if (unlikely(d_is_dir(dentry)))
22311 + goto out_unlock; /* possible? */
22313 + btop = au_dbtop(dentry);
22314 + bwh = au_dbwh(dentry);
22316 + parent = dentry->d_parent; /* dir inode is locked */
22317 + di_write_lock_parent(parent);
22318 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22320 + err = PTR_ERR(wh_dentry);
22321 + if (IS_ERR(wh_dentry))
22324 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22325 + a->h_path.dentry = au_h_dptr(dentry, btop);
22326 + dget(a->h_path.dentry);
22327 + if (bindex == btop) {
22328 + h_dir = au_pinned_h_dir(&a->pin);
22329 + delegated = NULL;
22330 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22331 + if (unlikely(err == -EWOULDBLOCK)) {
22332 + pr_warn("cannot retry for NFSv4 delegation"
22333 + " for an internal unlink\n");
22337 + /* dir inode is locked */
22338 + h_dir = d_inode(wh_dentry->d_parent);
22339 + IMustLock(h_dir);
22344 + vfsub_drop_nlink(inode);
22345 + epilog(dir, dentry, bindex);
22347 + /* update target timestamps */
22348 + if (bindex == btop) {
22349 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22351 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22353 + /* todo: this timestamp may be reverted later */
22354 + inode->i_ctime = h_dir->i_ctime;
22355 + goto out_unpin; /* success */
22362 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22369 + au_unpin(&a->pin);
22371 + dput(a->h_path.dentry);
22373 + di_write_unlock(parent);
22375 + aufs_read_unlock(dentry, AuLock_DW);
22382 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22384 + int err, rmdir_later;
22385 + aufs_bindex_t bwh, bindex, btop;
22386 + struct inode *inode;
22387 + struct dentry *parent, *wh_dentry, *h_dentry;
22388 + struct au_whtmp_rmdir *args;
22389 + /* to reduce stack size */
22391 + struct au_dtime dt;
22392 + struct au_pin pin;
22398 + a = kmalloc(sizeof(*a), GFP_NOFS);
22399 + if (unlikely(!a))
22402 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22403 + if (unlikely(err))
22405 + err = au_alive_dir(dentry);
22406 + if (unlikely(err))
22408 + inode = d_inode(dentry);
22409 + IMustLock(inode);
22411 + if (unlikely(!d_is_dir(dentry)))
22412 + goto out_unlock; /* possible? */
22415 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22416 + if (unlikely(!args))
22419 + parent = dentry->d_parent; /* dir inode is locked */
22420 + di_write_lock_parent(parent);
22421 + err = au_test_empty(dentry, &args->whlist);
22422 + if (unlikely(err))
22425 + btop = au_dbtop(dentry);
22426 + bwh = au_dbwh(dentry);
22428 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22430 + err = PTR_ERR(wh_dentry);
22431 + if (IS_ERR(wh_dentry))
22434 + h_dentry = au_h_dptr(dentry, btop);
22437 + if (bindex == btop) {
22438 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22440 + rmdir_later = err;
22444 + /* stop monitoring */
22445 + au_hn_free(au_hi(inode, btop));
22447 + /* dir inode is locked */
22448 + IMustLock(d_inode(wh_dentry->d_parent));
22453 + vfsub_dead_dir(inode);
22454 + au_set_dbdiropq(dentry, -1);
22455 + epilog(dir, dentry, bindex);
22457 + if (rmdir_later) {
22458 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22462 + goto out_unpin; /* success */
22470 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22477 + au_unpin(&a->pin);
22481 + di_write_unlock(parent);
22483 + au_whtmp_rmdir_free(args);
22485 + aufs_read_unlock(dentry, AuLock_DW);
22492 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22493 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22494 +++ linux/fs/aufs/i_op_ren.c 2021-12-03 15:40:58.236647297 +0100
22496 +// SPDX-License-Identifier: GPL-2.0
22498 + * Copyright (C) 2005-2021 Junjiro R. Okajima
22500 + * This program, aufs is free software; you can redistribute it and/or modify
22501 + * it under the terms of the GNU General Public License as published by
22502 + * the Free Software Foundation; either version 2 of the License, or
22503 + * (at your option) any later version.
22505 + * This program is distributed in the hope that it will be useful,
22506 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22508 + * GNU General Public License for more details.
22510 + * You should have received a copy of the GNU General Public License
22511 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22515 + * inode operation (rename entry)
22516 + * todo: this is crazy monster
22519 +#include <linux/iversion.h>
22522 +enum { AuSRC, AuDST, AuSrcDst };
22523 +enum { AuPARENT, AuCHILD, AuParentChild };
22525 +#define AuRen_ISDIR_SRC 1
22526 +#define AuRen_ISDIR_DST (1 << 1)
22527 +#define AuRen_ISSAMEDIR (1 << 2)
22528 +#define AuRen_WHSRC (1 << 3)
22529 +#define AuRen_WHDST (1 << 4)
22530 +#define AuRen_MNT_WRITE (1 << 5)
22531 +#define AuRen_DT_DSTDIR (1 << 6)
22532 +#define AuRen_DIROPQ_SRC (1 << 7)
22533 +#define AuRen_DIROPQ_DST (1 << 8)
22534 +#define AuRen_DIRREN (1 << 9)
22535 +#define AuRen_DROPPED_SRC (1 << 10)
22536 +#define AuRen_DROPPED_DST (1 << 11)
22537 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22538 +#define au_fset_ren(flags, name) \
22539 + do { (flags) |= AuRen_##name; } while (0)
22540 +#define au_fclr_ren(flags, name) \
22541 + do { (flags) &= ~AuRen_##name; } while (0)
22543 +#ifndef CONFIG_AUFS_DIRREN
22544 +#undef AuRen_DIRREN
22545 +#define AuRen_DIRREN 0
22548 +struct au_ren_args {
22550 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22552 + struct inode *dir, *inode;
22553 + struct au_hinode *hdir, *hinode;
22554 + struct au_dtime dt[AuParentChild];
22555 + aufs_bindex_t btop, bdiropq;
22558 +#define src_dentry sd[AuSRC].dentry
22559 +#define src_dir sd[AuSRC].dir
22560 +#define src_inode sd[AuSRC].inode
22561 +#define src_h_dentry sd[AuSRC].h_dentry
22562 +#define src_parent sd[AuSRC].parent
22563 +#define src_h_parent sd[AuSRC].h_parent
22564 +#define src_wh_dentry sd[AuSRC].wh_dentry
22565 +#define src_hdir sd[AuSRC].hdir
22566 +#define src_hinode sd[AuSRC].hinode
22567 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22568 +#define src_dt sd[AuSRC].dt
22569 +#define src_btop sd[AuSRC].btop
22570 +#define src_bdiropq sd[AuSRC].bdiropq
22572 +#define dst_dentry sd[AuDST].dentry
22573 +#define dst_dir sd[AuDST].dir
22574 +#define dst_inode sd[AuDST].inode
22575 +#define dst_h_dentry sd[AuDST].h_dentry
22576 +#define dst_parent sd[AuDST].parent
22577 +#define dst_h_parent sd[AuDST].h_parent
22578 +#define dst_wh_dentry sd[AuDST].wh_dentry
22579 +#define dst_hdir sd[AuDST].hdir
22580 +#define dst_hinode sd[AuDST].hinode
22581 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22582 +#define dst_dt sd[AuDST].dt
22583 +#define dst_btop sd[AuDST].btop
22584 +#define dst_bdiropq sd[AuDST].bdiropq
22586 + struct dentry *h_trap;
22587 + struct au_branch *br;
22588 + struct path h_path;
22589 + struct au_nhash whlist;
22590 + aufs_bindex_t btgt, src_bwh;
22593 + unsigned short auren_flags;
22594 + unsigned char flags; /* syscall parameter */
22595 + unsigned char exchange;
22598 + struct au_whtmp_rmdir *thargs;
22599 + struct dentry *h_dst;
22600 + struct au_hinode *h_root;
22603 +/* ---------------------------------------------------------------------- */
22606 + * functions for reverting.
22607 + * when an error happened in a single rename systemcall, we should revert
22608 + * everything as if nothing happened.
22609 + * we don't need to revert the copied-up/down the parent dir since they are
22613 +#define RevertFailure(fmt, ...) do { \
22614 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22615 + ##__VA_ARGS__, err, rerr); \
22619 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22622 + struct dentry *d;
22623 +#define src_or_dst(member) a->sd[idx].member
22625 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22626 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22627 + rerr = au_diropq_remove(d, a->btgt);
22628 + au_hn_inode_unlock(src_or_dst(hinode));
22629 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22631 + RevertFailure("remove diropq %pd", d);
22633 +#undef src_or_dst_
22636 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22638 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22639 + au_ren_do_rev_diropq(err, a, AuSRC);
22640 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22641 + au_ren_do_rev_diropq(err, a, AuDST);
22644 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22647 + struct inode *delegated;
22648 + struct path h_ppath = {
22649 + .dentry = a->src_h_parent,
22650 + .mnt = a->h_path.mnt
22653 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
22654 + rerr = PTR_ERR(a->h_path.dentry);
22655 + if (IS_ERR(a->h_path.dentry)) {
22656 + RevertFailure("lkup one %pd", a->src_dentry);
22660 + delegated = NULL;
22661 + rerr = vfsub_rename(a->dst_h_dir,
22662 + au_h_dptr(a->src_dentry, a->btgt),
22663 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22664 + if (unlikely(rerr == -EWOULDBLOCK)) {
22665 + pr_warn("cannot retry for NFSv4 delegation"
22666 + " for an internal rename\n");
22669 + d_drop(a->h_path.dentry);
22670 + dput(a->h_path.dentry);
22671 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22673 + RevertFailure("rename %pd", a->src_dentry);
22676 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22679 + struct inode *delegated;
22680 + struct path h_ppath = {
22681 + .dentry = a->dst_h_parent,
22682 + .mnt = a->h_path.mnt
22685 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
22686 + rerr = PTR_ERR(a->h_path.dentry);
22687 + if (IS_ERR(a->h_path.dentry)) {
22688 + RevertFailure("lkup one %pd", a->dst_dentry);
22691 + if (d_is_positive(a->h_path.dentry)) {
22692 + d_drop(a->h_path.dentry);
22693 + dput(a->h_path.dentry);
22697 + delegated = NULL;
22698 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22699 + &delegated, a->flags);
22700 + if (unlikely(rerr == -EWOULDBLOCK)) {
22701 + pr_warn("cannot retry for NFSv4 delegation"
22702 + " for an internal rename\n");
22705 + d_drop(a->h_path.dentry);
22706 + dput(a->h_path.dentry);
22708 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22710 + RevertFailure("rename %pd", a->h_dst);
22713 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22717 + a->h_path.dentry = a->src_wh_dentry;
22718 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22719 + au_set_dbwh(a->src_dentry, a->src_bwh);
22721 + RevertFailure("unlink %pd", a->src_wh_dentry);
22723 +#undef RevertFailure
22725 +/* ---------------------------------------------------------------------- */
22728 + * when we have to copyup the renaming entry, do it with the rename-target name
22729 + * in order to minimize the cost (the later actual rename is unnecessary).
22730 + * otherwise rename it on the target branch.
22732 +static int au_ren_or_cpup(struct au_ren_args *a)
22735 + struct dentry *d;
22736 + struct inode *delegated;
22738 + d = a->src_dentry;
22739 + if (au_dbtop(d) == a->btgt) {
22740 + a->h_path.dentry = a->dst_h_dentry;
22741 + AuDebugOn(au_dbtop(d) != a->btgt);
22742 + delegated = NULL;
22743 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22744 + a->dst_h_dir, &a->h_path, &delegated,
22746 + if (unlikely(err == -EWOULDBLOCK)) {
22747 + pr_warn("cannot retry for NFSv4 delegation"
22748 + " for an internal rename\n");
22754 + if (!err && a->h_dst)
22755 + /* it will be set to dinfo later */
22761 +/* cf. aufs_rmdir() */
22762 +static int au_ren_del_whtmp(struct au_ren_args *a)
22765 + struct inode *dir;
22767 + dir = a->dst_dir;
22768 + SiMustAnyLock(dir->i_sb);
22769 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22770 + au_sbi(dir->i_sb)->si_dirwh)
22771 + || au_test_fs_remote(a->h_dst->d_sb)) {
22772 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22773 + if (unlikely(err))
22774 + pr_warn("failed removing whtmp dir %pd (%d), "
22775 + "ignored.\n", a->h_dst, err);
22777 + au_nhash_wh_free(&a->thargs->whlist);
22778 + a->thargs->whlist = a->whlist;
22779 + a->whlist.nh_num = 0;
22780 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22782 + a->thargs = NULL;
22788 +/* make it 'opaque' dir. */
22789 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22792 + struct dentry *d, *diropq;
22793 +#define src_or_dst(member) a->sd[idx].member
22796 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22797 + src_or_dst(bdiropq) = au_dbdiropq(d);
22798 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22799 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22800 + diropq = au_diropq_create(d, a->btgt);
22801 + au_hn_inode_unlock(src_or_dst(hinode));
22802 + if (IS_ERR(diropq))
22803 + err = PTR_ERR(diropq);
22807 +#undef src_or_dst_
22811 +static int au_ren_diropq(struct au_ren_args *a)
22814 + unsigned char always;
22815 + struct dentry *d;
22818 + d = a->dst_dentry; /* already renamed on the branch */
22819 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22820 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22821 + && !au_ftest_ren(a->auren_flags, DIRREN)
22822 + && a->btgt != au_dbdiropq(a->src_dentry)
22823 + && (a->dst_wh_dentry
22824 + || a->btgt <= au_dbdiropq(d)
22825 + /* hide the lower to keep xino */
22826 + /* the lowers may not be a dir, but we hide them anyway */
22827 + || a->btgt < au_dbbot(d)
22830 + err = au_ren_do_diropq(a, AuSRC);
22831 + if (unlikely(err))
22833 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22835 + if (!a->exchange)
22836 + goto out; /* success */
22838 + d = a->src_dentry; /* already renamed on the branch */
22839 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22840 + && a->btgt != au_dbdiropq(a->dst_dentry)
22841 + && (a->btgt < au_dbdiropq(d)
22842 + || a->btgt < au_dbbot(d)
22844 + AuDbgDentry(a->src_dentry);
22845 + AuDbgDentry(a->dst_dentry);
22846 + err = au_ren_do_diropq(a, AuDST);
22847 + if (unlikely(err))
22848 + goto out_rev_src;
22849 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22851 + goto out; /* success */
22854 + AuDbg("err %d, reverting src\n", err);
22855 + au_ren_rev_diropq(err, a);
22860 +static int do_rename(struct au_ren_args *a)
22863 + struct dentry *d, *h_d;
22865 + if (!a->exchange) {
22866 + /* prepare workqueue args for asynchronous rmdir */
22867 + h_d = a->dst_h_dentry;
22868 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22869 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22870 + && d_is_positive(h_d)) {
22872 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22874 + if (unlikely(!a->thargs))
22876 + a->h_dst = dget(h_d);
22879 + /* create whiteout for src_dentry */
22880 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22881 + a->src_bwh = au_dbwh(a->src_dentry);
22882 + AuDebugOn(a->src_bwh >= 0);
22883 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22884 + a->src_h_parent);
22885 + err = PTR_ERR(a->src_wh_dentry);
22886 + if (IS_ERR(a->src_wh_dentry))
22890 + /* lookup whiteout for dentry */
22891 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22892 + h_d = au_wh_lkup(a->dst_h_parent,
22893 + &a->dst_dentry->d_name, a->br);
22894 + err = PTR_ERR(h_d);
22897 + if (d_is_negative(h_d))
22900 + a->dst_wh_dentry = h_d;
22903 + /* rename dentry to tmpwh */
22905 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22906 + if (unlikely(err))
22909 + d = a->dst_dentry;
22910 + au_set_h_dptr(d, a->btgt, NULL);
22911 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22912 + if (unlikely(err))
22914 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22918 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22919 +#if 0 /* debugging */
22920 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22921 + && d_is_positive(a->dst_h_dentry)
22922 + && a->src_btop != a->btgt);
22925 + /* rename by vfs_rename or cpup */
22926 + err = au_ren_or_cpup(a);
22927 + if (unlikely(err))
22928 + /* leave the copied-up one */
22931 + /* make dir opaque */
22932 + err = au_ren_diropq(a);
22933 + if (unlikely(err))
22936 + /* update target timestamps */
22937 + if (a->exchange) {
22938 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22939 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22940 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22941 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22943 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22944 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22945 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22946 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22948 + if (!a->exchange) {
22949 + /* remove whiteout for dentry */
22950 + if (a->dst_wh_dentry) {
22951 + a->h_path.dentry = a->dst_wh_dentry;
22952 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22954 + if (unlikely(err))
22958 + /* remove whtmp */
22960 + au_ren_del_whtmp(a); /* ignore this error */
22962 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22965 + goto out_success;
22968 + au_ren_rev_diropq(err, a);
22970 + au_ren_rev_rename(err, a);
22974 + au_ren_rev_whtmp(err, a);
22976 + dput(a->dst_wh_dentry);
22977 + a->dst_wh_dentry = NULL;
22979 + if (a->src_wh_dentry)
22980 + au_ren_rev_whsrc(err, a);
22982 + dput(a->src_wh_dentry);
22983 + dput(a->dst_wh_dentry);
22987 + au_whtmp_rmdir_free(a->thargs);
22988 + a->thargs = NULL;
22994 +/* ---------------------------------------------------------------------- */
22997 + * test if @dentry dir can be rename destination or not.
22998 + * success means, it is a logically empty dir.
23000 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23002 + return au_test_empty(dentry, whlist);
23006 + * test if @a->src_dentry dir can be rename source or not.
23007 + * if it can, return 0.
23009 + * - it is a logically empty dir.
23010 + * - or, it exists on writable branch and has no children including whiteouts
23011 + * on the lower branch unless DIRREN is on.
23013 +static int may_rename_srcdir(struct au_ren_args *a)
23016 + unsigned int rdhash;
23017 + aufs_bindex_t btop, btgt;
23018 + struct dentry *dentry;
23019 + struct super_block *sb;
23020 + struct au_sbinfo *sbinfo;
23022 + dentry = a->src_dentry;
23023 + sb = dentry->d_sb;
23024 + sbinfo = au_sbi(sb);
23025 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23026 + au_fset_ren(a->auren_flags, DIRREN);
23029 + btop = au_dbtop(dentry);
23030 + if (btop != btgt) {
23031 + struct au_nhash whlist;
23033 + SiMustAnyLock(sb);
23034 + rdhash = sbinfo->si_rdhash;
23036 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23038 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23039 + if (unlikely(err))
23041 + err = au_test_empty(dentry, &whlist);
23042 + au_nhash_wh_free(&whlist);
23046 + if (btop == au_dbtaildir(dentry))
23047 + return 0; /* success */
23049 + err = au_test_empty_lower(dentry);
23052 + if (err == -ENOTEMPTY) {
23053 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23056 + AuWarn1("renaming dir who has child(ren) on multiple "
23057 + "branches, is not supported\n");
23064 +/* side effect: sets whlist and h_dentry */
23065 +static int au_ren_may_dir(struct au_ren_args *a)
23068 + unsigned int rdhash;
23069 + struct dentry *d;
23071 + d = a->dst_dentry;
23072 + SiMustAnyLock(d->d_sb);
23075 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23076 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23078 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23079 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23080 + if (unlikely(err))
23083 + if (!a->exchange) {
23084 + au_set_dbtop(d, a->dst_btop);
23085 + err = may_rename_dstdir(d, &a->whlist);
23086 + au_set_dbtop(d, a->btgt);
23088 + err = may_rename_srcdir(a);
23090 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23091 + if (unlikely(err))
23094 + d = a->src_dentry;
23095 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23096 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23097 + err = may_rename_srcdir(a);
23098 + if (unlikely(err)) {
23099 + au_nhash_wh_free(&a->whlist);
23100 + a->whlist.nh_num = 0;
23107 +/* ---------------------------------------------------------------------- */
23110 + * simple tests for rename.
23111 + * following the checks in vfs, plus the parent-child relationship.
23113 +static int au_may_ren(struct au_ren_args *a)
23116 + struct inode *h_inode;
23118 + if (a->src_btop == a->btgt) {
23119 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23120 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23121 + if (unlikely(err))
23124 + if (unlikely(a->src_h_dentry == a->h_trap))
23129 + if (a->dst_btop != a->btgt)
23132 + err = -ENOTEMPTY;
23133 + if (unlikely(a->dst_h_dentry == a->h_trap))
23137 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23138 + if (d_really_is_negative(a->dst_dentry)) {
23139 + if (d_is_negative(a->dst_h_dentry))
23140 + err = au_may_add(a->dst_dentry, a->btgt,
23141 + a->dst_h_parent, isdir);
23143 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23145 + h_inode = d_inode(a->dst_h_dentry);
23146 + if (h_inode->i_nlink)
23147 + err = au_may_del(a->dst_dentry, a->btgt,
23148 + a->dst_h_parent, isdir);
23152 + if (unlikely(err == -ENOENT || err == -EEXIST))
23158 +/* ---------------------------------------------------------------------- */
23163 + * - src_dir and dir by lock_rename()
23164 + * - inode if exists
23167 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23169 + * + di_write_lock2_child()
23170 + * + di_write_lock_child()
23171 + * + ii_write_lock_child()
23172 + * + di_write_lock_child2()
23173 + * + ii_write_lock_child2()
23174 + * + src_parent and parent
23175 + * + di_write_lock_parent()
23176 + * + ii_write_lock_parent()
23177 + * + di_write_lock_parent2()
23178 + * + ii_write_lock_parent2()
23179 + * + lower src_dir and dir by vfsub_lock_rename()
23180 + * + verify the every relationships between child and parent. if any
23181 + * of them failed, unlock all and return -EBUSY.
23183 +static void au_ren_unlock(struct au_ren_args *a)
23185 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23186 + a->dst_h_parent, a->dst_hdir);
23187 + if (au_ftest_ren(a->auren_flags, DIRREN)
23189 + au_hn_inode_unlock(a->h_root);
23190 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23191 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23194 +static int au_ren_lock(struct au_ren_args *a)
23197 + unsigned int udba;
23200 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23201 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23202 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23203 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23205 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23206 + if (unlikely(err))
23208 + au_fset_ren(a->auren_flags, MNT_WRITE);
23209 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23210 + struct dentry *root;
23211 + struct inode *dir;
23214 + * sbinfo is already locked, so this ii_read_lock is
23215 + * unnecessary. but our debugging feature checks it.
23217 + root = a->src_inode->i_sb->s_root;
23218 + if (root != a->src_parent && root != a->dst_parent) {
23219 + dir = d_inode(root);
23220 + ii_read_lock_parent3(dir);
23221 + a->h_root = au_hi(dir, a->btgt);
23222 + ii_read_unlock(dir);
23223 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23226 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23227 + a->dst_h_parent, a->dst_hdir);
23228 + udba = au_opt_udba(a->src_dentry->d_sb);
23229 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23230 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23231 + err = au_busy_or_stale();
23232 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23233 + err = au_h_verify(a->src_h_dentry, udba,
23234 + d_inode(a->src_h_parent), a->src_h_parent,
23236 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23237 + err = au_h_verify(a->dst_h_dentry, udba,
23238 + d_inode(a->dst_h_parent), a->dst_h_parent,
23241 + goto out; /* success */
23243 + err = au_busy_or_stale();
23244 + au_ren_unlock(a);
23250 +/* ---------------------------------------------------------------------- */
23252 +static void au_ren_refresh_dir(struct au_ren_args *a)
23254 + struct inode *dir;
23256 + dir = a->dst_dir;
23257 + inode_inc_iversion(dir);
23258 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23259 + /* is this updating defined in POSIX? */
23260 + au_cpup_attr_timesizes(a->src_inode);
23261 + au_cpup_attr_nlink(dir, /*force*/1);
23263 + au_dir_ts(dir, a->btgt);
23265 + if (a->exchange) {
23266 + dir = a->src_dir;
23267 + inode_inc_iversion(dir);
23268 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23269 + /* is this updating defined in POSIX? */
23270 + au_cpup_attr_timesizes(a->dst_inode);
23271 + au_cpup_attr_nlink(dir, /*force*/1);
23273 + au_dir_ts(dir, a->btgt);
23276 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23279 + dir = a->src_dir;
23280 + inode_inc_iversion(dir);
23281 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23282 + au_cpup_attr_nlink(dir, /*force*/1);
23283 + au_dir_ts(dir, a->btgt);
23286 +static void au_ren_refresh(struct au_ren_args *a)
23288 + aufs_bindex_t bbot, bindex;
23289 + struct dentry *d, *h_d;
23290 + struct inode *i, *h_i;
23291 + struct super_block *sb;
23293 + d = a->dst_dentry;
23296 + /* already dget-ed by au_ren_or_cpup() */
23297 + au_set_h_dptr(d, a->btgt, a->h_dst);
23299 + i = a->dst_inode;
23301 + if (!a->exchange) {
23302 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23303 + vfsub_drop_nlink(i);
23305 + vfsub_dead_dir(i);
23306 + au_cpup_attr_timesizes(i);
23308 + au_update_dbrange(d, /*do_put_zero*/1);
23310 + au_cpup_attr_nlink(i, /*force*/1);
23313 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23314 + au_set_h_dptr(d, bindex, NULL);
23315 + bbot = au_dbbot(d);
23316 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23317 + au_set_h_dptr(d, bindex, NULL);
23318 + au_update_dbrange(d, /*do_put_zero*/0);
23322 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23323 + d_drop(a->src_dentry);
23324 + if (au_ftest_ren(a->auren_flags, DIRREN))
23325 + au_set_dbwh(a->src_dentry, -1);
23329 + d = a->src_dentry;
23330 + au_set_dbwh(d, -1);
23331 + bbot = au_dbbot(d);
23332 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23333 + h_d = au_h_dptr(d, bindex);
23335 + au_set_h_dptr(d, bindex, NULL);
23337 + au_set_dbbot(d, a->btgt);
23340 + i = a->src_inode;
23341 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23342 + return; /* success */
23344 + bbot = au_ibbot(i);
23345 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23346 + h_i = au_h_iptr(i, bindex);
23348 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23349 + /* ignore this error */
23350 + au_set_h_iptr(i, bindex, NULL, 0);
23353 + au_set_ibbot(i, a->btgt);
23356 +/* ---------------------------------------------------------------------- */
23358 +/* mainly for link(2) and rename(2) */
23359 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23361 + aufs_bindex_t bdiropq, bwh;
23362 + struct dentry *parent;
23363 + struct au_branch *br;
23365 + parent = dentry->d_parent;
23366 + IMustLock(d_inode(parent)); /* dir is locked */
23368 + bdiropq = au_dbdiropq(parent);
23369 + bwh = au_dbwh(dentry);
23370 + br = au_sbr(dentry->d_sb, btgt);
23371 + if (au_br_rdonly(br)
23372 + || (0 <= bdiropq && bdiropq < btgt)
23373 + || (0 <= bwh && bwh < btgt))
23376 + AuDbg("btgt %d\n", btgt);
23380 +/* sets src_btop, dst_btop and btgt */
23381 +static int au_ren_wbr(struct au_ren_args *a)
23384 + struct au_wr_dir_args wr_dir_args = {
23385 + /* .force_btgt = -1, */
23386 + .flags = AuWrDir_ADD_ENTRY
23389 + a->src_btop = au_dbtop(a->src_dentry);
23390 + a->dst_btop = au_dbtop(a->dst_dentry);
23391 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23392 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23393 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23394 + wr_dir_args.force_btgt = a->src_btop;
23395 + if (a->dst_inode && a->dst_btop < a->src_btop)
23396 + wr_dir_args.force_btgt = a->dst_btop;
23397 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23398 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23401 + au_update_dbtop(a->dst_dentry);
23406 +static void au_ren_dt(struct au_ren_args *a)
23408 + a->h_path.dentry = a->src_h_parent;
23409 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23410 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23411 + a->h_path.dentry = a->dst_h_parent;
23412 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23415 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23416 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23420 + a->h_path.dentry = a->src_h_dentry;
23421 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23422 + if (d_is_positive(a->dst_h_dentry)) {
23423 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23424 + a->h_path.dentry = a->dst_h_dentry;
23425 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23429 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23431 + struct dentry *h_d;
23432 + struct inode *h_inode;
23434 + au_dtime_revert(a->src_dt + AuPARENT);
23435 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23436 + au_dtime_revert(a->dst_dt + AuPARENT);
23438 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23439 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23440 + h_inode = d_inode(h_d);
23441 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23442 + au_dtime_revert(a->src_dt + AuCHILD);
23443 + inode_unlock(h_inode);
23445 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23446 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23447 + h_inode = d_inode(h_d);
23448 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23449 + au_dtime_revert(a->dst_dt + AuCHILD);
23450 + inode_unlock(h_inode);
23455 +/* ---------------------------------------------------------------------- */
23457 +int aufs_rename(struct user_namespace *userns,
23458 + struct inode *_src_dir, struct dentry *_src_dentry,
23459 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23460 + unsigned int _flags)
23462 + int err, lock_flags;
23464 + /* reduce stack space */
23465 + struct au_ren_args *a;
23466 + struct au_pin pin;
23468 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23469 + IMustLock(_src_dir);
23470 + IMustLock(_dst_dir);
23473 + if (unlikely(_flags & RENAME_WHITEOUT))
23477 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23478 + a = kzalloc(sizeof(*a), GFP_NOFS);
23479 + if (unlikely(!a))
23482 + a->flags = _flags;
23483 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23484 + && RENAME_EXCHANGE > U8_MAX);
23485 + a->exchange = _flags & RENAME_EXCHANGE;
23486 + a->src_dir = _src_dir;
23487 + a->src_dentry = _src_dentry;
23488 + a->src_inode = NULL;
23489 + if (d_really_is_positive(a->src_dentry))
23490 + a->src_inode = d_inode(a->src_dentry);
23491 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23492 + a->dst_dir = _dst_dir;
23493 + a->dst_dentry = _dst_dentry;
23494 + a->dst_inode = NULL;
23495 + if (d_really_is_positive(a->dst_dentry))
23496 + a->dst_inode = d_inode(a->dst_dentry);
23497 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23498 + if (a->dst_inode) {
23500 + * if EXCHANGE && src is non-dir && dst is dir,
23501 + * dst is not locked.
23503 + /* IMustLock(a->dst_inode); */
23504 + au_igrab(a->dst_inode);
23508 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23509 + if (d_is_dir(a->src_dentry)) {
23510 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23511 + if (unlikely(!a->exchange
23512 + && d_really_is_positive(a->dst_dentry)
23513 + && !d_is_dir(a->dst_dentry)))
23515 + lock_flags |= AuLock_DIRS;
23517 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23518 + au_fset_ren(a->auren_flags, ISDIR_DST);
23519 + if (unlikely(!a->exchange
23520 + && d_really_is_positive(a->src_dentry)
23521 + && !d_is_dir(a->src_dentry)))
23523 + lock_flags |= AuLock_DIRS;
23525 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23527 + if (unlikely(err))
23530 + err = au_d_hashed_positive(a->src_dentry);
23531 + if (unlikely(err))
23534 + if (a->dst_inode) {
23536 + * If it is a dir, VFS unhash it before this
23537 + * function. It means we cannot rely upon d_unhashed().
23539 + if (unlikely(!a->dst_inode->i_nlink))
23541 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23542 + err = au_d_hashed_positive(a->dst_dentry);
23543 + if (unlikely(err && !a->exchange))
23545 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23547 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23551 + * is it possible?
23552 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23553 + * there may exist a problem somewhere else.
23556 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23559 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23560 + di_write_lock_parent(a->dst_parent);
23562 + /* which branch we process */
23563 + err = au_ren_wbr(a);
23564 + if (unlikely(err < 0))
23566 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23567 + a->h_path.mnt = au_br_mnt(a->br);
23569 + /* are they available to be renamed */
23570 + err = au_ren_may_dir(a);
23571 + if (unlikely(err))
23572 + goto out_children;
23574 + /* prepare the writable parent dir on the same branch */
23575 + if (a->dst_btop == a->btgt) {
23576 + au_fset_ren(a->auren_flags, WHDST);
23578 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23579 + if (unlikely(err))
23580 + goto out_children;
23584 + if (!a->exchange) {
23585 + if (a->src_dir != a->dst_dir) {
23587 + * this temporary unlock is safe,
23588 + * because both dir->i_mutex are locked.
23590 + di_write_unlock(a->dst_parent);
23591 + di_write_lock_parent(a->src_parent);
23592 + err = au_wr_dir_need_wh(a->src_dentry,
23593 + au_ftest_ren(a->auren_flags,
23596 + di_write_unlock(a->src_parent);
23597 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23599 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23601 + err = au_wr_dir_need_wh(a->src_dentry,
23602 + au_ftest_ren(a->auren_flags,
23606 + if (unlikely(err < 0))
23607 + goto out_children;
23609 + au_fset_ren(a->auren_flags, WHSRC);
23612 + if (a->src_btop != a->btgt) {
23613 + err = au_pin(&pin, a->src_dentry, a->btgt,
23614 + au_opt_udba(a->src_dentry->d_sb),
23615 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23617 + struct au_cp_generic cpg = {
23618 + .dentry = a->src_dentry,
23620 + .bsrc = a->src_btop,
23623 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23625 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23626 + err = au_sio_cpup_simple(&cpg);
23629 + if (unlikely(err))
23630 + goto out_children;
23631 + a->src_btop = a->btgt;
23632 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23633 + if (!a->exchange)
23634 + au_fset_ren(a->auren_flags, WHSRC);
23638 + if (a->exchange && a->dst_inode
23639 + && a->dst_btop != a->btgt) {
23640 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23641 + au_opt_udba(a->dst_dentry->d_sb),
23642 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23644 + struct au_cp_generic cpg = {
23645 + .dentry = a->dst_dentry,
23647 + .bsrc = a->dst_btop,
23650 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23652 + err = au_sio_cpup_simple(&cpg);
23655 + if (unlikely(err))
23656 + goto out_children;
23657 + a->dst_btop = a->btgt;
23658 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23661 + /* lock them all */
23662 + err = au_ren_lock(a);
23663 + if (unlikely(err))
23664 + /* leave the copied-up one */
23665 + goto out_children;
23667 + if (!a->exchange) {
23668 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23669 + err = au_may_ren(a);
23670 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23671 + err = -ENAMETOOLONG;
23672 + if (unlikely(err))
23676 + /* store timestamps to be revertible */
23679 + /* store dirren info */
23680 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23681 + err = au_dr_rename(a->src_dentry, a->btgt,
23682 + &a->dst_dentry->d_name, &rev);
23684 + if (unlikely(err))
23689 + err = do_rename(a);
23690 + if (unlikely(err))
23693 + if (au_ftest_ren(a->auren_flags, DIRREN))
23694 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23696 + /* update dir attributes */
23697 + au_ren_refresh_dir(a);
23699 + /* dput/iput all lower dentries */
23700 + au_ren_refresh(a);
23702 + goto out_hdir; /* success */
23705 + if (au_ftest_ren(a->auren_flags, DIRREN))
23706 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23708 + au_ren_rev_dt(err, a);
23710 + au_ren_unlock(a);
23712 + au_nhash_wh_free(&a->whlist);
23713 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23714 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23715 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23716 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23720 + if (d_unhashed(a->src_dentry))
23721 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23722 + if (d_unhashed(a->dst_dentry))
23723 + au_fset_ren(a->auren_flags, DROPPED_DST);
23724 + if (!a->exchange)
23725 + d_move(a->src_dentry, a->dst_dentry);
23727 + d_exchange(a->src_dentry, a->dst_dentry);
23728 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23729 + d_drop(a->dst_dentry);
23731 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23732 + d_drop(a->src_dentry);
23734 + au_update_dbtop(a->dst_dentry);
23735 + if (!a->dst_inode)
23736 + d_drop(a->dst_dentry);
23738 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23739 + di_write_unlock(a->dst_parent);
23741 + di_write_unlock2(a->src_parent, a->dst_parent);
23743 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23745 + iput(a->dst_inode);
23747 + au_whtmp_rmdir_free(a->thargs);
23753 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23754 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23755 +++ linux/fs/aufs/Kconfig 2021-12-03 15:38:59.929980643 +0100
23757 +# SPDX-License-Identifier: GPL-2.0
23759 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23761 + Aufs is a stackable unification filesystem such as Unionfs,
23762 + which unifies several directories and provides a merged single
23764 + In the early days, aufs was entirely re-designed and
23765 + re-implemented Unionfs Version 1.x series. Introducing many
23766 + original ideas, approaches and improvements, it becomes totally
23767 + different from Unionfs while keeping the basic features.
23771 + prompt "Maximum number of branches"
23772 + default AUFS_BRANCH_MAX_127
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.
23777 +config AUFS_BRANCH_MAX_127
23780 + Specifies the maximum number of branches (or member directories)
23781 + in a single aufs. The larger value consumes more system
23782 + resources and has a minor impact to performance.
23783 +config AUFS_BRANCH_MAX_511
23786 + Specifies the maximum number of branches (or member directories)
23787 + in a single aufs. The larger value consumes more system
23788 + resources and has a minor impact to performance.
23789 +config AUFS_BRANCH_MAX_1023
23792 + Specifies the maximum number of branches (or member directories)
23793 + in a single aufs. The larger value consumes more system
23794 + resources and has a minor impact to performance.
23795 +config AUFS_BRANCH_MAX_32767
23798 + Specifies the maximum number of branches (or member directories)
23799 + in a single aufs. The larger value consumes more system
23800 + resources and has a minor impact to performance.
23803 +config AUFS_SBILIST
23805 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23808 + Automatic configuration for internal use.
23809 + When aufs supports Magic SysRq or /proc, enabled automatically.
23811 +config AUFS_HNOTIFY
23812 + bool "Detect direct branch access (bypassing aufs)"
23814 + If you want to modify files on branches directly, eg. bypassing aufs,
23815 + and want aufs to detect the changes of them fully, then enable this
23816 + option and use 'udba=notify' mount option.
23817 + Currently there is only one available configuration, "fsnotify".
23818 + It will have a negative impact to the performance.
23819 + See detail in aufs.5.
23822 + prompt "method" if AUFS_HNOTIFY
23823 + default AUFS_HFSNOTIFY
23824 +config AUFS_HFSNOTIFY
23829 +config AUFS_EXPORT
23830 + bool "NFS-exportable aufs"
23831 + depends on EXPORTFS
23833 + If you want to export your mounted aufs via NFS, then enable this
23834 + option. There are several requirements for this configuration.
23835 + See detail in aufs.5.
23837 +config AUFS_INO_T_64
23839 + depends on AUFS_EXPORT
23840 + depends on 64BIT && !(ALPHA || S390)
23843 + Automatic configuration for internal use.
23844 + /* typedef unsigned long/int __kernel_ino_t */
23845 + /* alpha and s390x are int */
23848 + bool "support for XATTR/EA (including Security Labels)"
23850 + If your branch fs supports XATTR/EA and you want to make them
23851 + available in aufs too, then enable this opsion and specify the
23852 + branch attributes for EA.
23853 + See detail in aufs.5.
23856 + bool "File-based Hierarchical Storage Management"
23858 + Hierarchical Storage Management (or HSM) is a well-known feature
23859 + in the storage world. Aufs provides this feature as file-based.
23860 + with multiple branches.
23861 + These multiple branches are prioritized, ie. the topmost one
23862 + should be the fastest drive and be used heavily.
23865 + bool "Readdir in userspace"
23867 + Aufs has two methods to provide a merged view for a directory,
23868 + by a user-space library and by kernel-space natively. The latter
23869 + is always enabled but sometimes large and slow.
23870 + If you enable this option, install the library in aufs2-util
23871 + package, and set some environment variables for your readdir(3),
23872 + then the work will be handled in user-space which generally
23873 + shows better performance in most cases.
23874 + See detail in aufs.5.
23876 +config AUFS_DIRREN
23877 + bool "Workaround for rename(2)-ing a directory"
23879 + By default, aufs returns EXDEV error in renameing a dir who has
23880 + his child on the lower branch, since it is a bad idea to issue
23881 + rename(2) internally for every lower branch. But user may not
23882 + accept this behaviour. So here is a workaround to allow such
23883 + rename(2) and store some extra infromation on the writable
23884 + branch. Obviously this costs high (and I don't like it).
23885 + To use this feature, you need to enable this configuration AND
23886 + to specify the mount option `dirren.'
23887 + See details in aufs.5 and the design documents.
23890 + bool "Show whiteouts"
23892 + If you want to make the whiteouts in aufs visible, then enable
23893 + this option and specify 'shwh' mount option. Although it may
23894 + sounds like philosophy or something, but in technically it
23895 + simply shows the name of whiteout with keeping its behaviour.
23897 +config AUFS_BR_RAMFS
23898 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23900 + If you want to use ramfs as an aufs branch fs, then enable this
23901 + option. Generally tmpfs is recommended.
23902 + Aufs prohibited them to be a branch fs by default, because
23903 + initramfs becomes unusable after switch_root or something
23904 + generally. If you sets initramfs as an aufs branch and boot your
23905 + system by switch_root, you will meet a problem easily since the
23906 + files in initramfs may be inaccessible.
23907 + Unless you are going to use ramfs as an aufs branch fs without
23908 + switch_root or something, leave it N.
23910 +config AUFS_BR_FUSE
23911 + bool "Fuse fs as an aufs branch"
23912 + depends on FUSE_FS
23915 + If you want to use fuse-based userspace filesystem as an aufs
23916 + branch fs, then enable this option.
23917 + It implements the internal poll(2) operation which is
23918 + implemented by fuse only (curretnly).
23923 + Automatic configuration for internal use.
23925 +config AUFS_BR_HFSPLUS
23926 + bool "Hfsplus as an aufs branch"
23927 + depends on HFSPLUS_FS
23930 + If you want to use hfsplus fs as an aufs branch fs, then enable
23931 + this option. This option introduces a small overhead at
23932 + copying-up a file on hfsplus.
23934 +config AUFS_BDEV_LOOP
23936 + depends on BLK_DEV_LOOP
23939 + Automatic configuration for internal use.
23940 + Convert =[ym] into =y.
23943 + bool "Debug aufs"
23945 + Enable this to compile aufs internal debug code.
23946 + It will have a negative impact to the performance.
23948 +config AUFS_MAGIC_SYSRQ
23950 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23953 + Automatic configuration for internal use.
23954 + When aufs supports Magic SysRq, enabled automatically.
23956 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23957 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23958 +++ linux/fs/aufs/lcnt.h 2021-12-03 15:38:59.936647310 +0100
23960 +/* SPDX-License-Identifier: GPL-2.0 */
23962 + * Copyright (C) 2018-2021 Junjiro R. Okajima
23964 + * This program, aufs is free software; you can redistribute it and/or modify
23965 + * it under the terms of the GNU General Public License as published by
23966 + * the Free Software Foundation; either version 2 of the License, or
23967 + * (at your option) any later version.
23969 + * This program is distributed in the hope that it will be useful,
23970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23972 + * GNU General Public License for more details.
23974 + * You should have received a copy of the GNU General Public License
23975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23979 + * simple long counter wrapper
23982 +#ifndef __AUFS_LCNT_H__
23983 +#define __AUFS_LCNT_H__
23987 +#include "debug.h"
23989 +#define AuLCntATOMIC 1
23990 +#define AuLCntPCPUCNT 2
23992 + * why does percpu_refcount require extra synchronize_rcu()s in
23993 + * au_br_do_free()
23995 +#define AuLCntPCPUREF 3
23997 +/* #define AuLCntChosen AuLCntATOMIC */
23998 +#define AuLCntChosen AuLCntPCPUCNT
23999 +/* #define AuLCntChosen AuLCntPCPUREF */
24001 +#if AuLCntChosen == AuLCntATOMIC
24002 +#include <linux/atomic.h>
24004 +typedef atomic_long_t au_lcnt_t;
24006 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24008 + atomic_long_set(cnt, 0);
24012 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24017 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24018 + int do_sync __maybe_unused)
24023 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24025 + atomic_long_inc(cnt);
24028 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24030 + atomic_long_dec(cnt);
24033 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24035 + return atomic_long_read(cnt);
24039 +#if AuLCntChosen == AuLCntPCPUCNT
24040 +#include <linux/percpu_counter.h>
24042 +typedef struct percpu_counter au_lcnt_t;
24044 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24046 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24049 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24054 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24056 + percpu_counter_destroy(cnt);
24059 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24061 + percpu_counter_inc(cnt);
24064 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24066 + percpu_counter_dec(cnt);
24069 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24073 + n = percpu_counter_sum(cnt);
24075 + if (LONG_MAX != LLONG_MAX
24077 + AuWarn1("%s\n", "wrap-around");
24083 +#if AuLCntChosen == AuLCntPCPUREF
24084 +#include <linux/percpu-refcount.h>
24086 +typedef struct percpu_ref au_lcnt_t;
24088 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24091 + release = percpu_ref_exit;
24092 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24095 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24097 + synchronize_rcu();
24100 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24102 + percpu_ref_kill(cnt);
24104 + au_lcnt_wait_for_fin(cnt);
24107 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24109 + percpu_ref_get(cnt);
24112 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24114 + percpu_ref_put(cnt);
24118 + * avoid calling this func as possible.
24120 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24124 + percpu_ref_switch_to_atomic_sync(cnt);
24125 + l = atomic_long_read(&cnt->count);
24127 + percpu_ref_switch_to_percpu(cnt);
24129 + /* percpu_ref is initialized by 1 instead of 0 */
24134 +#ifdef CONFIG_AUFS_DEBUG
24135 +#define AuLCntZero(val) do { \
24138 + AuDbg("%s = %ld\n", #val, l); \
24141 +#define AuLCntZero(val) do {} while (0)
24144 +#endif /* __KERNEL__ */
24145 +#endif /* __AUFS_LCNT_H__ */
24146 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24147 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24148 +++ linux/fs/aufs/loop.c 2021-12-03 15:38:59.936647310 +0100
24150 +// SPDX-License-Identifier: GPL-2.0
24152 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24154 + * This program, aufs is free software; you can redistribute it and/or modify
24155 + * it under the terms of the GNU General Public License as published by
24156 + * the Free Software Foundation; either version 2 of the License, or
24157 + * (at your option) any later version.
24159 + * This program is distributed in the hope that it will be useful,
24160 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24162 + * GNU General Public License for more details.
24164 + * You should have received a copy of the GNU General Public License
24165 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24169 + * support for loopback block device as a branch
24174 +/* added into drivers/block/loop.c */
24175 +static struct file *(*backing_file_func)(struct super_block *sb);
24178 + * test if two lower dentries have overlapping branches.
24180 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24182 + struct super_block *h_sb;
24183 + struct file *backing_file;
24185 + if (unlikely(!backing_file_func)) {
24186 + /* don't load "loop" module here */
24187 + backing_file_func = symbol_get(loop_backing_file);
24188 + if (unlikely(!backing_file_func))
24189 + /* "loop" module is not loaded */
24193 + h_sb = h_adding->d_sb;
24194 + backing_file = backing_file_func(h_sb);
24195 + if (!backing_file)
24198 + h_adding = backing_file->f_path.dentry;
24200 + * h_adding can be local NFS.
24201 + * in this case aufs cannot detect the loop.
24203 + if (unlikely(h_adding->d_sb == sb))
24205 + return !!au_test_subdir(h_adding, sb->s_root);
24208 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24209 +int au_test_loopback_kthread(void)
24212 + struct task_struct *tsk = current;
24213 + char c, comm[sizeof(tsk->comm)];
24216 + if (tsk->flags & PF_KTHREAD) {
24217 + get_task_comm(comm, tsk);
24219 + ret = ('0' <= c && c <= '9'
24220 + && !strncmp(comm, "loop", 4));
24226 +/* ---------------------------------------------------------------------- */
24228 +#define au_warn_loopback_step 16
24229 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24230 +static unsigned long *au_warn_loopback_array;
24232 +void au_warn_loopback(struct super_block *h_sb)
24234 + int i, new_nelem;
24235 + unsigned long *a, magic;
24236 + static DEFINE_SPINLOCK(spin);
24238 + magic = h_sb->s_magic;
24239 + spin_lock(&spin);
24240 + a = au_warn_loopback_array;
24241 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24242 + if (a[i] == magic) {
24243 + spin_unlock(&spin);
24247 + /* h_sb is new to us, print it */
24248 + if (i < au_warn_loopback_nelem) {
24253 + /* expand the array */
24254 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24255 + a = au_kzrealloc(au_warn_loopback_array,
24256 + au_warn_loopback_nelem * sizeof(unsigned long),
24257 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24258 + /*may_shrink*/0);
24260 + au_warn_loopback_nelem = new_nelem;
24261 + au_warn_loopback_array = a;
24266 + spin_unlock(&spin);
24267 + AuWarn1("realloc failed, ignored\n");
24271 + spin_unlock(&spin);
24272 + pr_warn("you may want to try another patch for loopback file "
24273 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24276 +int au_loopback_init(void)
24279 + struct super_block *sb __maybe_unused;
24281 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24284 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24285 + sizeof(unsigned long), GFP_NOFS);
24286 + if (unlikely(!au_warn_loopback_array))
24292 +void au_loopback_fin(void)
24294 + if (backing_file_func)
24295 + symbol_put(loop_backing_file);
24296 + au_kfree_try_rcu(au_warn_loopback_array);
24298 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24299 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24300 +++ linux/fs/aufs/loop.h 2021-12-03 15:38:59.936647310 +0100
24302 +/* SPDX-License-Identifier: GPL-2.0 */
24304 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24306 + * This program, aufs is free software; you can redistribute it and/or modify
24307 + * it under the terms of the GNU General Public License as published by
24308 + * the Free Software Foundation; either version 2 of the License, or
24309 + * (at your option) any later version.
24311 + * This program is distributed in the hope that it will be useful,
24312 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24313 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24314 + * GNU General Public License for more details.
24316 + * You should have received a copy of the GNU General Public License
24317 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24321 + * support for loopback mount as a branch
24324 +#ifndef __AUFS_LOOP_H__
24325 +#define __AUFS_LOOP_H__
24330 +struct super_block;
24332 +#ifdef CONFIG_AUFS_BDEV_LOOP
24333 +/* drivers/block/loop.c */
24334 +struct file *loop_backing_file(struct super_block *sb);
24337 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24338 +int au_test_loopback_kthread(void);
24339 +void au_warn_loopback(struct super_block *h_sb);
24341 +int au_loopback_init(void);
24342 +void au_loopback_fin(void);
24344 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24346 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24347 + struct dentry *h_adding)
24348 +AuStubInt0(au_test_loopback_kthread, void)
24349 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24351 +AuStubInt0(au_loopback_init, void)
24352 +AuStubVoid(au_loopback_fin, void)
24353 +#endif /* BLK_DEV_LOOP */
24355 +#endif /* __KERNEL__ */
24356 +#endif /* __AUFS_LOOP_H__ */
24357 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24358 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24359 +++ linux/fs/aufs/magic.mk 2021-12-03 15:38:59.936647310 +0100
24361 +# SPDX-License-Identifier: GPL-2.0
24363 +# defined in ${srctree}/fs/fuse/inode.c
24365 +ifdef CONFIG_FUSE_FS
24366 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24369 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24371 +ifdef CONFIG_XFS_FS
24372 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24375 +# defined in ${srctree}/fs/configfs/mount.c
24377 +ifdef CONFIG_CONFIGFS_FS
24378 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24381 +# defined in ${srctree}/fs/ubifs/ubifs.h
24383 +ifdef CONFIG_UBIFS_FS
24384 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24387 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24389 +ifdef CONFIG_HFSPLUS_FS
24390 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24392 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24393 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24394 +++ linux/fs/aufs/Makefile 2021-12-03 15:38:59.929980643 +0100
24396 +# SPDX-License-Identifier: GPL-2.0
24398 +include ${src}/magic.mk
24399 +ifeq (${CONFIG_AUFS_FS},m)
24400 +include ${src}/conf.mk
24402 +-include ${src}/priv_def.mk
24404 +# cf. include/linux/kernel.h
24406 +ccflags-y += -DDEBUG
24407 +# sparse requires the full pathname
24409 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24411 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24414 +obj-$(CONFIG_AUFS_FS) += aufs.o
24415 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24416 + wkq.o vfsub.o dcsub.o \
24417 + cpup.o whout.o wbr_policy.o \
24418 + dinfo.o dentry.o \
24420 + finfo.o file.o f_op.o \
24422 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24426 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24427 +aufs-$(CONFIG_SYSFS) += sysfs.o
24428 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24429 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24430 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24431 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24432 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24433 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24434 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24435 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24436 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24437 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24438 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24439 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24440 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24441 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24442 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24443 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24444 +++ linux/fs/aufs/module.c 2021-12-03 15:38:59.936647310 +0100
24446 +// SPDX-License-Identifier: GPL-2.0
24448 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24450 + * This program, aufs is free software; you can redistribute it and/or modify
24451 + * it under the terms of the GNU General Public License as published by
24452 + * the Free Software Foundation; either version 2 of the License, or
24453 + * (at your option) any later version.
24455 + * This program is distributed in the hope that it will be useful,
24456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24458 + * GNU General Public License for more details.
24460 + * You should have received a copy of the GNU General Public License
24461 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24465 + * module global variables and operations
24468 +#include <linux/module.h>
24469 +#include <linux/seq_file.h>
24472 +/* shrinkable realloc */
24473 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24481 +#if 0 /* unused */
24488 + AuDebugOn(!new_sz);
24491 + diff = au_kmidx_sub(sz, new_sz);
24497 + /* expand or SLOB */
24498 + p = krealloc(p, new_sz, gfp);
24499 + else if (new_sz < sz && may_shrink) {
24503 + q = kmalloc(new_sz, gfp);
24506 + memcpy(q, p, new_sz);
24507 + au_kfree_try_rcu(p);
24518 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24521 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24522 + if (p && new_sz > nused)
24523 + memset(p + nused, 0, new_sz - nused);
24527 +/* ---------------------------------------------------------------------- */
24531 +struct kmem_cache *au_cache[AuCache_Last];
24533 +static void au_cache_fin(void)
24538 + * Make sure all delayed rcu free inodes are flushed before we
24543 + /* excluding AuCache_HNOTIFY */
24544 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24545 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24546 + kmem_cache_destroy(au_cache[i]);
24547 + au_cache[i] = NULL;
24551 +static int __init au_cache_init(void)
24553 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24554 + if (au_cache[AuCache_DINFO])
24555 + /* SLAB_DESTROY_BY_RCU */
24556 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24557 + au_icntnr_init_once);
24558 + if (au_cache[AuCache_ICNTNR])
24559 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24560 + au_fi_init_once);
24561 + if (au_cache[AuCache_FINFO])
24562 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24563 + if (au_cache[AuCache_VDIR])
24564 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24565 + if (au_cache[AuCache_DEHSTR])
24572 +/* ---------------------------------------------------------------------- */
24574 +int au_dir_roflags;
24576 +#ifdef CONFIG_AUFS_SBILIST
24578 + * iterate_supers_type() doesn't protect us from
24579 + * remounting (branch management)
24581 +struct hlist_bl_head au_sbilist;
24585 + * functions for module interface.
24587 +MODULE_LICENSE("GPL");
24588 +/* MODULE_LICENSE("GPL v2"); */
24589 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24590 +MODULE_DESCRIPTION(AUFS_NAME
24591 + " -- Advanced multi layered unification filesystem");
24592 +MODULE_VERSION(AUFS_VERSION);
24593 +MODULE_ALIAS_FS(AUFS_NAME);
24595 +/* this module parameter has no meaning when SYSFS is disabled */
24596 +int sysaufs_brs = 1;
24597 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24598 +module_param_named(brs, sysaufs_brs, int, 0444);
24600 +/* this module parameter has no meaning when USER_NS is disabled */
24602 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24603 +module_param_named(allow_userns, au_userns, bool, 0444);
24605 +/* ---------------------------------------------------------------------- */
24607 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24609 +int au_seq_path(struct seq_file *seq, struct path *path)
24613 + err = seq_path(seq, path, au_esc_chars);
24622 +/* ---------------------------------------------------------------------- */
24624 +static int __init aufs_init(void)
24629 + p = au_esc_chars;
24630 + for (i = 1; i <= ' '; i++)
24636 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24638 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24639 + for (i = 0; i < AuIop_Last; i++)
24640 + aufs_iop_nogetattr[i].getattr = NULL;
24642 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24644 + au_sbilist_init();
24645 + sysaufs_brs_init();
24648 + err = sysaufs_init();
24649 + if (unlikely(err))
24651 + err = dbgaufs_init();
24652 + if (unlikely(err))
24653 + goto out_sysaufs;
24654 + err = au_procfs_init();
24655 + if (unlikely(err))
24656 + goto out_dbgaufs;
24657 + err = au_wkq_init();
24658 + if (unlikely(err))
24660 + err = au_loopback_init();
24661 + if (unlikely(err))
24663 + err = au_hnotify_init();
24664 + if (unlikely(err))
24665 + goto out_loopback;
24666 + err = au_sysrq_init();
24667 + if (unlikely(err))
24669 + err = au_cache_init();
24670 + if (unlikely(err))
24673 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24674 + err = register_filesystem(&aufs_fs_type);
24675 + if (unlikely(err))
24678 + /* since we define pr_fmt, call printk directly */
24679 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24680 + goto out; /* success */
24687 + au_hnotify_fin();
24689 + au_loopback_fin();
24703 +static void __exit aufs_exit(void)
24705 + unregister_filesystem(&aufs_fs_type);
24708 + au_hnotify_fin();
24709 + au_loopback_fin();
24717 +module_init(aufs_init);
24718 +module_exit(aufs_exit);
24719 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24720 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24721 +++ linux/fs/aufs/module.h 2021-12-03 15:40:58.236647297 +0100
24723 +/* SPDX-License-Identifier: GPL-2.0 */
24725 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24727 + * This program, aufs is free software; you can redistribute it and/or modify
24728 + * it under the terms of the GNU General Public License as published by
24729 + * the Free Software Foundation; either version 2 of the License, or
24730 + * (at your option) any later version.
24732 + * This program is distributed in the hope that it will be useful,
24733 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24735 + * GNU General Public License for more details.
24737 + * You should have received a copy of the GNU General Public License
24738 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24742 + * module initialization and module-global
24745 +#ifndef __AUFS_MODULE_H__
24746 +#define __AUFS_MODULE_H__
24750 +#include <linux/slab.h>
24751 +#include "debug.h"
24752 +#include "dentry.h"
24755 +#include "inode.h"
24760 +/* module parameters */
24761 +extern int sysaufs_brs;
24762 +extern bool au_userns;
24764 +/* ---------------------------------------------------------------------- */
24766 +extern int au_dir_roflags;
24768 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24769 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24773 + * Comparing the size of the object with sizeof(struct rcu_head)
24774 + * case 1: object is always larger
24775 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24776 + * case 2: object is always smaller
24777 + * --> au_kfree_small()
24778 + * case 3: object can be any size
24779 + * --> au_kfree_try_rcu()
24782 +static inline void au_kfree_do_rcu(const void *p)
24785 + struct rcu_head rcu;
24786 + } *a = (void *)p;
24788 + kfree_rcu(a, rcu);
24791 +#define au_kfree_rcu(_p) do { \
24792 + typeof(_p) p = (_p); \
24793 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24795 + au_kfree_do_rcu(p); \
24798 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24799 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24801 +static inline void au_kfree_try_rcu(const void *p)
24805 + if (au_kfree_sz_test(p))
24806 + au_kfree_do_rcu(p);
24811 +static inline void au_kfree_small(const void *p)
24815 + AuDebugOn(au_kfree_sz_test(p));
24819 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24821 +#ifndef CONFIG_SLOB
24822 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
24824 + return -1; /* SLOB is untested */
24828 +int au_seq_path(struct seq_file *seq, struct path *path);
24830 +#ifdef CONFIG_PROC_FS
24832 +int __init au_procfs_init(void);
24833 +void au_procfs_fin(void);
24835 +AuStubInt0(au_procfs_init, void);
24836 +AuStubVoid(au_procfs_fin, void);
24839 +/* ---------------------------------------------------------------------- */
24848 + AuCache_HNOTIFY, /* must be last */
24852 +extern struct kmem_cache *au_cache[AuCache_Last];
24854 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24855 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24856 +#define AuCacheCtor(type, ctor) \
24857 + kmem_cache_create(#type, sizeof(struct type), \
24858 + __alignof__(struct type), AuCacheFlags, ctor)
24860 +#define AuCacheFuncs(name, index) \
24861 + static inline struct au_##name *au_cache_alloc_##name(void) \
24862 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24863 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24864 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24866 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24867 + { void *p = rcu; \
24868 + p -= offsetof(struct au_##name, rcu); \
24869 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24870 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24871 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24872 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24874 + static inline void au_cache_free_##name(struct au_##name *p) \
24875 + { /* au_cache_free_##name##_norcu(p); */ \
24876 + au_cache_free_##name##_rcu(p); }
24878 +AuCacheFuncs(dinfo, DINFO);
24879 +AuCacheFuncs(icntnr, ICNTNR);
24880 +AuCacheFuncs(finfo, FINFO);
24881 +AuCacheFuncs(vdir, VDIR);
24882 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24883 +#ifdef CONFIG_AUFS_HNOTIFY
24884 +AuCacheFuncs(hnotify, HNOTIFY);
24887 +#endif /* __KERNEL__ */
24888 +#endif /* __AUFS_MODULE_H__ */
24889 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24890 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24891 +++ linux/fs/aufs/mvdown.c 2021-12-03 15:38:59.939980643 +0100
24893 +// SPDX-License-Identifier: GPL-2.0
24895 + * Copyright (C) 2011-2021 Junjiro R. Okajima
24897 + * This program, aufs is free software; you can redistribute it and/or modify
24898 + * it under the terms of the GNU General Public License as published by
24899 + * the Free Software Foundation; either version 2 of the License, or
24900 + * (at your option) any later version.
24902 + * This program is distributed in the hope that it will be useful,
24903 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24904 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24905 + * GNU General Public License for more details.
24907 + * You should have received a copy of the GNU General Public License
24908 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24912 + * move-down, opposite of copy-up
24917 +struct au_mvd_args {
24919 + struct super_block *h_sb;
24920 + struct dentry *h_parent;
24921 + struct au_hinode *hdir;
24922 + struct inode *h_dir, *h_inode;
24923 + struct au_pin pin;
24924 + } info[AUFS_MVDOWN_NARRAY];
24926 + struct aufs_mvdown mvdown;
24927 + struct dentry *dentry, *parent;
24928 + struct inode *inode, *dir;
24929 + struct super_block *sb;
24930 + aufs_bindex_t bopq, bwh, bfound;
24931 + unsigned char rename_lock;
24934 +#define mvd_errno mvdown.au_errno
24935 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24936 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24937 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24938 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24940 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24941 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24942 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24943 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24944 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24945 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24947 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24948 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24949 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24950 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24951 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24952 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24954 +#define AU_MVD_PR(flag, ...) do { \
24956 + pr_err(__VA_ARGS__); \
24959 +static int find_lower_writable(struct au_mvd_args *a)
24961 + struct super_block *sb;
24962 + aufs_bindex_t bindex, bbot;
24963 + struct au_branch *br;
24966 + bindex = a->mvd_bsrc;
24967 + bbot = au_sbbot(sb);
24968 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24969 + for (bindex++; bindex <= bbot; bindex++) {
24970 + br = au_sbr(sb, bindex);
24971 + if (au_br_fhsm(br->br_perm)
24972 + && !sb_rdonly(au_br_sb(br)))
24975 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24976 + for (bindex++; bindex <= bbot; bindex++) {
24977 + br = au_sbr(sb, bindex);
24978 + if (!au_br_rdonly(br))
24982 + for (bindex++; bindex <= bbot; bindex++) {
24983 + br = au_sbr(sb, bindex);
24984 + if (!sb_rdonly(au_br_sb(br))) {
24985 + if (au_br_rdonly(br))
24987 + |= AUFS_MVDOWN_ROLOWER_R;
24995 +/* make the parent dir on bdst */
24996 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25001 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25002 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25003 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25004 + a->mvd_h_dst_parent = NULL;
25005 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25006 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25007 + if (!a->mvd_h_dst_parent) {
25008 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25009 + if (unlikely(err)) {
25010 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25013 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25021 +/* lock them all */
25022 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25025 + struct dentry *h_trap;
25027 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25028 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25029 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25030 + au_opt_udba(a->sb),
25031 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25033 + if (unlikely(err)) {
25034 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25038 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25039 + a->rename_lock = 0;
25040 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25041 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25042 + au_opt_udba(a->sb),
25043 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25044 + err = au_do_pin(&a->mvd_pin_src);
25046 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25047 + if (unlikely(err)) {
25048 + AU_MVD_PR(dmsg, "pin_src failed\n");
25051 + goto out; /* success */
25054 + a->rename_lock = 1;
25055 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25056 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25057 + au_opt_udba(a->sb),
25058 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25060 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25061 + if (unlikely(err)) {
25062 + AU_MVD_PR(dmsg, "pin_src failed\n");
25063 + au_pin_hdir_lock(&a->mvd_pin_dst);
25066 + au_pin_hdir_unlock(&a->mvd_pin_src);
25067 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25068 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25070 + err = (h_trap != a->mvd_h_src_parent);
25072 + err = (h_trap != a->mvd_h_dst_parent);
25074 + BUG_ON(err); /* it should never happen */
25075 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25078 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25079 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25080 + au_pin_hdir_lock(&a->mvd_pin_src);
25081 + au_unpin(&a->mvd_pin_src);
25082 + au_pin_hdir_lock(&a->mvd_pin_dst);
25085 + goto out; /* success */
25088 + au_unpin(&a->mvd_pin_dst);
25094 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25096 + if (!a->rename_lock)
25097 + au_unpin(&a->mvd_pin_src);
25099 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25100 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25101 + au_pin_hdir_lock(&a->mvd_pin_src);
25102 + au_unpin(&a->mvd_pin_src);
25103 + au_pin_hdir_lock(&a->mvd_pin_dst);
25105 + au_unpin(&a->mvd_pin_dst);
25108 +/* copy-down the file */
25109 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25112 + struct au_cp_generic cpg = {
25113 + .dentry = a->dentry,
25114 + .bdst = a->mvd_bdst,
25115 + .bsrc = a->mvd_bsrc,
25117 + .pin = &a->mvd_pin_dst,
25118 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25121 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25122 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25123 + au_fset_cpup(cpg.flags, OVERWRITE);
25124 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25125 + au_fset_cpup(cpg.flags, RWDST);
25126 + err = au_sio_cpdown_simple(&cpg);
25127 + if (unlikely(err))
25128 + AU_MVD_PR(dmsg, "cpdown failed\n");
25135 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25138 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25141 + struct path h_path;
25142 + struct au_branch *br;
25143 + struct inode *delegated;
25145 + br = au_sbr(a->sb, a->mvd_bdst);
25146 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25147 + err = PTR_ERR(h_path.dentry);
25148 + if (IS_ERR(h_path.dentry)) {
25149 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25154 + if (d_is_positive(h_path.dentry)) {
25155 + h_path.mnt = au_br_mnt(br);
25156 + delegated = NULL;
25157 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25158 + &delegated, /*force*/0);
25159 + if (unlikely(err == -EWOULDBLOCK)) {
25160 + pr_warn("cannot retry for NFSv4 delegation"
25161 + " for an internal unlink\n");
25164 + if (unlikely(err))
25165 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25167 + dput(h_path.dentry);
25175 + * unlink the topmost h_dentry
25177 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25180 + struct path h_path;
25181 + struct inode *delegated;
25183 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25184 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25185 + delegated = NULL;
25186 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25187 + if (unlikely(err == -EWOULDBLOCK)) {
25188 + pr_warn("cannot retry for NFSv4 delegation"
25189 + " for an internal unlink\n");
25192 + if (unlikely(err))
25193 + AU_MVD_PR(dmsg, "unlink failed\n");
25199 +/* Since mvdown succeeded, we ignore an error of this function */
25200 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25203 + struct au_branch *br;
25205 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25206 + br = au_sbr(a->sb, a->mvd_bsrc);
25207 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25209 + br = au_sbr(a->sb, a->mvd_bdst);
25210 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25211 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25214 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25216 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25220 + * copy-down the file and unlink the bsrc file.
25221 + * - unlink the bdst whout if exist
25222 + * - copy-down the file (with whtmp name and rename)
25223 + * - unlink the bsrc file
25225 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25229 + err = au_do_mkdir(dmsg, a);
25231 + err = au_do_lock(dmsg, a);
25232 + if (unlikely(err))
25236 + * do not revert the activities we made on bdst since they should be
25237 + * harmless in aufs.
25240 + err = au_do_cpdown(dmsg, a);
25242 + err = au_do_unlink_wh(dmsg, a);
25243 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25244 + err = au_do_unlink(dmsg, a);
25245 + if (unlikely(err))
25248 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25249 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25250 + if (find_lower_writable(a) < 0)
25251 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25253 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25254 + au_do_stfs(dmsg, a);
25256 + /* maintain internal array */
25257 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25258 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25259 + au_set_dbtop(a->dentry, a->mvd_bdst);
25260 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25261 + au_set_ibtop(a->inode, a->mvd_bdst);
25263 + /* hide the lower */
25264 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25265 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25266 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25267 + au_set_ibbot(a->inode, a->mvd_bsrc);
25269 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25270 + au_set_dbbot(a->dentry, a->mvd_bdst);
25271 + if (au_ibbot(a->inode) < a->mvd_bdst)
25272 + au_set_ibbot(a->inode, a->mvd_bdst);
25275 + au_do_unlock(dmsg, a);
25281 +/* ---------------------------------------------------------------------- */
25283 +/* make sure the file is idle */
25284 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25286 + int err, plinked;
25289 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25290 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25291 + && au_dcount(a->dentry) == 1
25292 + && atomic_read(&a->inode->i_count) == 1
25293 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25294 + && (!plinked || !au_plink_test(a->inode))
25295 + && a->inode->i_nlink == 1)
25300 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25301 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25302 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25303 + a->mvd_h_src_inode->i_nlink,
25304 + plinked, plinked ? au_plink_test(a->inode) : 0);
25311 +/* make sure the parent dir is fine */
25312 +static int au_mvd_args_parent(const unsigned char dmsg,
25313 + struct au_mvd_args *a)
25316 + aufs_bindex_t bindex;
25319 + if (unlikely(au_alive_dir(a->parent))) {
25321 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25325 + a->bopq = au_dbdiropq(a->parent);
25326 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25327 + AuDbg("b%d\n", bindex);
25328 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25329 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25331 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25332 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25333 + a->bopq, a->mvd_bdst);
25341 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25342 + struct au_mvd_args *a)
25345 + struct au_dinfo *dinfo, *tmp;
25347 + /* lookup the next lower positive entry */
25349 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25350 + if (unlikely(!tmp))
25355 + dinfo = au_di(a->dentry);
25356 + au_di_cp(tmp, dinfo);
25357 + au_di_swap(tmp, dinfo);
25359 + /* returns the number of positive dentries */
25360 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25361 + /* AuLkup_IGNORE_PERM */ 0);
25363 + a->bwh = au_dbwh(a->dentry);
25364 + else if (err > 0)
25365 + a->bfound = au_dbtop(a->dentry);
25367 + au_di_swap(tmp, dinfo);
25368 + au_rw_write_unlock(&tmp->di_rwsem);
25370 + if (unlikely(err < 0))
25371 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25374 + * here, we have these cases.
25376 + * no positive dentry under bsrc. there are more sub-cases.
25378 + * there no whiteout, we can safely move-down.
25381 + * bsrc < bwh && bwh < bdst
25382 + * there is a whiteout on RO branch. cannot proceed.
25384 + * there is a whiteout on the RW target branch. it should
25387 + * there is a whiteout somewhere unrelated branch.
25388 + * -1 < bfound && bfound <= bsrc
25391 + * found, but it is on RO branch between bsrc and bdst. cannot
25394 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25397 + * found, after we create the file on bdst, it will be hidden.
25400 + AuDebugOn(a->bfound == -1
25402 + && a->bwh <= a->mvd_bsrc);
25403 + AuDebugOn(-1 < a->bfound
25404 + && a->bfound <= a->mvd_bsrc);
25407 + if (a->bfound == -1
25408 + && a->mvd_bsrc < a->bwh
25410 + && a->bwh < a->mvd_bdst) {
25411 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25412 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25413 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25415 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25416 + a->mvd_errno = EAU_MVDOWN_UPPER;
25417 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25418 + a->mvd_bdst, a->bfound);
25422 + err = 0; /* success */
25429 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25434 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25435 + && a->bfound == a->mvd_bdst)
25441 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25444 + struct au_branch *br;
25447 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25451 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25452 + a->mvd_bsrc = au_ibtop(a->inode);
25454 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25455 + if (unlikely(a->mvd_bsrc < 0
25456 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25457 + || au_dbbot(a->dentry) < a->mvd_bsrc
25458 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25459 + || (a->mvd_bsrc < au_ibtop(a->inode)
25460 + || au_ibbot(a->inode) < a->mvd_bsrc
25461 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25462 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25463 + AU_MVD_PR(dmsg, "no upper\n");
25467 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25468 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25469 + AU_MVD_PR(dmsg, "on the bottom\n");
25472 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25473 + br = au_sbr(a->sb, a->mvd_bsrc);
25474 + err = au_br_rdonly(br);
25475 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25476 + if (unlikely(err))
25478 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25479 + || IS_APPEND(a->mvd_h_src_inode))) {
25481 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25487 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25488 + a->mvd_bdst = find_lower_writable(a);
25489 + if (unlikely(a->mvd_bdst < 0)) {
25490 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25491 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25495 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25496 + if (unlikely(a->mvd_bdst < 0
25497 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25498 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25499 + AU_MVD_PR(dmsg, "no lower brid\n");
25504 + err = au_mvd_args_busy(dmsg, a);
25506 + err = au_mvd_args_parent(dmsg, a);
25508 + err = au_mvd_args_intermediate(dmsg, a);
25510 + err = au_mvd_args_exist(dmsg, a);
25512 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25519 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25522 + unsigned char dmsg;
25523 + struct au_mvd_args *args;
25524 + struct inode *inode;
25526 + inode = d_inode(dentry);
25528 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25532 + args = kmalloc(sizeof(*args), GFP_NOFS);
25533 + if (unlikely(!args))
25536 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25538 + /* VERIFY_WRITE */
25539 + err = !access_ok(uarg, sizeof(*uarg));
25540 + if (unlikely(err)) {
25545 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25546 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25547 + args->mvdown.au_errno = 0;
25548 + args->dentry = dentry;
25549 + args->inode = inode;
25550 + args->sb = dentry->d_sb;
25553 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25554 + args->parent = dget_parent(dentry);
25555 + args->dir = d_inode(args->parent);
25556 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25557 + dput(args->parent);
25558 + if (unlikely(args->parent != dentry->d_parent)) {
25559 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25563 + inode_lock_nested(inode, I_MUTEX_CHILD);
25564 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25565 + if (unlikely(err))
25568 + di_write_lock_parent(args->parent);
25569 + err = au_mvd_args(dmsg, args);
25570 + if (unlikely(err))
25573 + err = au_do_mvdown(dmsg, args);
25574 + if (unlikely(err))
25577 + au_cpup_attr_timesizes(args->dir);
25578 + au_cpup_attr_timesizes(inode);
25579 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25580 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25581 + /* au_digen_dec(dentry); */
25584 + di_write_unlock(args->parent);
25585 + aufs_read_unlock(dentry, AuLock_DW);
25587 + inode_unlock(inode);
25589 + inode_unlock(args->dir);
25591 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25594 + au_kfree_rcu(args);
25599 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25600 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25601 +++ linux/fs/aufs/opts.c 2021-12-03 15:38:59.939980643 +0100
25603 +// SPDX-License-Identifier: GPL-2.0
25605 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25607 + * This program, aufs is free software; you can redistribute it and/or modify
25608 + * it under the terms of the GNU General Public License as published by
25609 + * the Free Software Foundation; either version 2 of the License, or
25610 + * (at your option) any later version.
25612 + * This program is distributed in the hope that it will be useful,
25613 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25614 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25615 + * GNU General Public License for more details.
25617 + * You should have received a copy of the GNU General Public License
25618 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25622 + * mount options/flags
25625 +#include <linux/namei.h>
25626 +#include <linux/types.h> /* a distribution requires */
25627 +#include <linux/parser.h>
25630 +/* ---------------------------------------------------------------------- */
25634 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25635 + Opt_idel, Opt_imod,
25636 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25637 + Opt_rdblk_def, Opt_rdhash_def,
25638 + Opt_xino, Opt_noxino,
25639 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25640 + Opt_trunc_xino_path, Opt_itrunc_xino,
25641 + Opt_trunc_xib, Opt_notrunc_xib,
25642 + Opt_shwh, Opt_noshwh,
25643 + Opt_plink, Opt_noplink, Opt_list_plink,
25645 + Opt_dio, Opt_nodio,
25646 + Opt_diropq_a, Opt_diropq_w,
25647 + Opt_warn_perm, Opt_nowarn_perm,
25648 + Opt_wbr_copyup, Opt_wbr_create,
25650 + Opt_verbose, Opt_noverbose,
25651 + Opt_sum, Opt_nosum, Opt_wsum,
25652 + Opt_dirperm1, Opt_nodirperm1,
25653 + Opt_dirren, Opt_nodirren,
25654 + Opt_acl, Opt_noacl,
25655 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25658 +static match_table_t options = {
25659 + {Opt_br, "br=%s"},
25660 + {Opt_br, "br:%s"},
25662 + {Opt_add, "add=%d:%s"},
25663 + {Opt_add, "add:%d:%s"},
25664 + {Opt_add, "ins=%d:%s"},
25665 + {Opt_add, "ins:%d:%s"},
25666 + {Opt_append, "append=%s"},
25667 + {Opt_append, "append:%s"},
25668 + {Opt_prepend, "prepend=%s"},
25669 + {Opt_prepend, "prepend:%s"},
25671 + {Opt_del, "del=%s"},
25672 + {Opt_del, "del:%s"},
25673 + /* {Opt_idel, "idel:%d"}, */
25674 + {Opt_mod, "mod=%s"},
25675 + {Opt_mod, "mod:%s"},
25676 + /* {Opt_imod, "imod:%d:%s"}, */
25678 + {Opt_dirwh, "dirwh=%d"},
25680 + {Opt_xino, "xino=%s"},
25681 + {Opt_noxino, "noxino"},
25682 + {Opt_trunc_xino, "trunc_xino"},
25683 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25684 + {Opt_notrunc_xino, "notrunc_xino"},
25685 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25686 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25687 + /* {Opt_zxino, "zxino=%s"}, */
25688 + {Opt_trunc_xib, "trunc_xib"},
25689 + {Opt_notrunc_xib, "notrunc_xib"},
25691 +#ifdef CONFIG_PROC_FS
25692 + {Opt_plink, "plink"},
25694 + {Opt_ignore_silent, "plink"},
25697 + {Opt_noplink, "noplink"},
25699 +#ifdef CONFIG_AUFS_DEBUG
25700 + {Opt_list_plink, "list_plink"},
25703 + {Opt_udba, "udba=%s"},
25705 + {Opt_dio, "dio"},
25706 + {Opt_nodio, "nodio"},
25708 +#ifdef CONFIG_AUFS_DIRREN
25709 + {Opt_dirren, "dirren"},
25710 + {Opt_nodirren, "nodirren"},
25712 + {Opt_ignore, "dirren"},
25713 + {Opt_ignore_silent, "nodirren"},
25716 +#ifdef CONFIG_AUFS_FHSM
25717 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25719 + {Opt_ignore, "fhsm_sec=%d"},
25722 + {Opt_diropq_a, "diropq=always"},
25723 + {Opt_diropq_a, "diropq=a"},
25724 + {Opt_diropq_w, "diropq=whiteouted"},
25725 + {Opt_diropq_w, "diropq=w"},
25727 + {Opt_warn_perm, "warn_perm"},
25728 + {Opt_nowarn_perm, "nowarn_perm"},
25730 + /* keep them temporary */
25731 + {Opt_ignore_silent, "nodlgt"},
25732 + {Opt_ignore, "clean_plink"},
25734 +#ifdef CONFIG_AUFS_SHWH
25735 + {Opt_shwh, "shwh"},
25737 + {Opt_noshwh, "noshwh"},
25739 + {Opt_dirperm1, "dirperm1"},
25740 + {Opt_nodirperm1, "nodirperm1"},
25742 + {Opt_verbose, "verbose"},
25743 + {Opt_verbose, "v"},
25744 + {Opt_noverbose, "noverbose"},
25745 + {Opt_noverbose, "quiet"},
25746 + {Opt_noverbose, "q"},
25747 + {Opt_noverbose, "silent"},
25749 + {Opt_sum, "sum"},
25750 + {Opt_nosum, "nosum"},
25751 + {Opt_wsum, "wsum"},
25753 + {Opt_rdcache, "rdcache=%d"},
25754 + {Opt_rdblk, "rdblk=%d"},
25755 + {Opt_rdblk_def, "rdblk=def"},
25756 + {Opt_rdhash, "rdhash=%d"},
25757 + {Opt_rdhash_def, "rdhash=def"},
25759 + {Opt_wbr_create, "create=%s"},
25760 + {Opt_wbr_create, "create_policy=%s"},
25761 + {Opt_wbr_copyup, "cpup=%s"},
25762 + {Opt_wbr_copyup, "copyup=%s"},
25763 + {Opt_wbr_copyup, "copyup_policy=%s"},
25765 + /* generic VFS flag */
25766 +#ifdef CONFIG_FS_POSIX_ACL
25767 + {Opt_acl, "acl"},
25768 + {Opt_noacl, "noacl"},
25770 + {Opt_ignore, "acl"},
25771 + {Opt_ignore_silent, "noacl"},
25774 + /* internal use for the scripts */
25775 + {Opt_ignore_silent, "si=%s"},
25777 + {Opt_br, "dirs=%s"},
25778 + {Opt_ignore, "debug=%d"},
25779 + {Opt_ignore, "delete=whiteout"},
25780 + {Opt_ignore, "delete=all"},
25781 + {Opt_ignore, "imap=%s"},
25783 + /* temporary workaround, due to old mount(8)? */
25784 + {Opt_ignore_silent, "relatime"},
25789 +/* ---------------------------------------------------------------------- */
25791 +static const char *au_parser_pattern(int val, match_table_t tbl)
25793 + struct match_token *p;
25796 + while (p->pattern) {
25797 + if (p->token == val)
25798 + return p->pattern;
25805 +static const char *au_optstr(int *val, match_table_t tbl)
25807 + struct match_token *p;
25814 + while (p->pattern) {
25816 + && (v & p->token) == p->token) {
25817 + *val &= ~p->token;
25818 + return p->pattern;
25827 +/* ---------------------------------------------------------------------- */
25829 +static match_table_t brperm = {
25830 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25831 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25832 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25836 +static match_table_t brattr = {
25838 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25839 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25840 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25841 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25842 +#ifdef CONFIG_AUFS_FHSM
25843 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25845 +#ifdef CONFIG_AUFS_XATTR
25846 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25847 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25848 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25849 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25850 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25851 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25854 + /* ro/rr branch */
25855 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25858 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25859 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25864 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25871 + p = strchr(str, '+');
25874 + v = match_token(str, table, args);
25876 + if (v & AuBrAttr_CMOO_Mask)
25877 + attr &= ~AuBrAttr_CMOO_Mask;
25882 + pr_warn("ignored branch attribute %s\n", str);
25892 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25900 + p = au_optstr(&perm, brattr);
25903 + memcpy(q, p, sz + 1);
25909 + p = au_optstr(&perm, brattr);
25913 + memcpy(q, p, sz + 1);
25919 + return q - str->a;
25922 +static int noinline_for_stack br_perm_val(char *perm)
25924 + int val, bad, sz;
25926 + substring_t args[MAX_OPT_ARGS];
25927 + au_br_perm_str_t attr;
25929 + p = strchr(perm, '+');
25932 + val = match_token(perm, brperm, args);
25936 + pr_warn("ignored branch permission %s\n", perm);
25937 + val = AuBrPerm_RO;
25943 + val |= br_attr_val(p + 1, brattr, args);
25946 + switch (val & AuBrPerm_Mask) {
25947 + case AuBrPerm_RO:
25948 + case AuBrPerm_RR:
25949 + bad = val & AuBrWAttr_Mask;
25950 + val &= ~AuBrWAttr_Mask;
25952 + case AuBrPerm_RW:
25953 + bad = val & AuBrRAttr_Mask;
25954 + val &= ~AuBrRAttr_Mask;
25959 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25960 + * does not treat it as an error, just warning.
25961 + * this is a tiny guard for the user operation.
25963 + if (val & AuBrAttr_UNPIN) {
25964 + bad |= AuBrAttr_UNPIN;
25965 + val &= ~AuBrAttr_UNPIN;
25968 + if (unlikely(bad)) {
25969 + sz = au_do_optstr_br_attr(&attr, bad);
25971 + pr_warn("ignored branch attribute %s\n", attr.a);
25978 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25980 + au_br_perm_str_t attr;
25986 + p = au_optstr(&perm, brperm);
25987 + AuDebugOn(!p || !*p);
25989 + memcpy(q, p, sz + 1);
25992 + sz = au_do_optstr_br_attr(&attr, perm);
25995 + memcpy(q, attr.a, sz + 1);
25998 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26001 +/* ---------------------------------------------------------------------- */
26003 +static match_table_t udbalevel = {
26004 + {AuOpt_UDBA_REVAL, "reval"},
26005 + {AuOpt_UDBA_NONE, "none"},
26006 +#ifdef CONFIG_AUFS_HNOTIFY
26007 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26008 +#ifdef CONFIG_AUFS_HFSNOTIFY
26009 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26015 +static int noinline_for_stack udba_val(char *str)
26017 + substring_t args[MAX_OPT_ARGS];
26019 + return match_token(str, udbalevel, args);
26022 +const char *au_optstr_udba(int udba)
26024 + return au_parser_pattern(udba, udbalevel);
26027 +/* ---------------------------------------------------------------------- */
26029 +static match_table_t au_wbr_create_policy = {
26030 + {AuWbrCreate_TDP, "tdp"},
26031 + {AuWbrCreate_TDP, "top-down-parent"},
26032 + {AuWbrCreate_RR, "rr"},
26033 + {AuWbrCreate_RR, "round-robin"},
26034 + {AuWbrCreate_MFS, "mfs"},
26035 + {AuWbrCreate_MFS, "most-free-space"},
26036 + {AuWbrCreate_MFSV, "mfs:%d"},
26037 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26039 + /* top-down regardless the parent, and then mfs */
26040 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26041 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26043 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26044 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26045 + {AuWbrCreate_PMFS, "pmfs"},
26046 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26047 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26048 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26053 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26054 + struct au_opt_wbr_create *create)
26057 + unsigned long long ull;
26060 + if (!match_u64(arg, &ull))
26061 + create->mfsrr_watermark = ull;
26063 + pr_err("bad integer in %s\n", str);
26070 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26071 + struct au_opt_wbr_create *create)
26076 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26077 + create->mfs_second = n;
26079 + pr_err("bad integer in %s\n", str);
26086 +static int noinline_for_stack
26087 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26090 + substring_t args[MAX_OPT_ARGS];
26092 + err = match_token(str, au_wbr_create_policy, args);
26093 + create->wbr_create = err;
26095 + case AuWbrCreate_MFSRRV:
26096 + case AuWbrCreate_TDMFSV:
26097 + case AuWbrCreate_PMFSRRV:
26098 + e = au_wbr_mfs_wmark(&args[0], str, create);
26100 + e = au_wbr_mfs_sec(&args[1], str, create);
26104 + case AuWbrCreate_MFSRR:
26105 + case AuWbrCreate_TDMFS:
26106 + case AuWbrCreate_PMFSRR:
26107 + e = au_wbr_mfs_wmark(&args[0], str, create);
26108 + if (unlikely(e)) {
26113 + case AuWbrCreate_MFS:
26114 + case AuWbrCreate_PMFS:
26115 + create->mfs_second = AUFS_MFS_DEF_SEC;
26117 + case AuWbrCreate_MFSV:
26118 + case AuWbrCreate_PMFSV:
26119 + e = au_wbr_mfs_sec(&args[0], str, create);
26128 +const char *au_optstr_wbr_create(int wbr_create)
26130 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26133 +static match_table_t au_wbr_copyup_policy = {
26134 + {AuWbrCopyup_TDP, "tdp"},
26135 + {AuWbrCopyup_TDP, "top-down-parent"},
26136 + {AuWbrCopyup_BUP, "bup"},
26137 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26138 + {AuWbrCopyup_BU, "bu"},
26139 + {AuWbrCopyup_BU, "bottom-up"},
26143 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26145 + substring_t args[MAX_OPT_ARGS];
26147 + return match_token(str, au_wbr_copyup_policy, args);
26150 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26152 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26155 +/* ---------------------------------------------------------------------- */
26157 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26159 +static void dump_opts(struct au_opts *opts)
26161 +#ifdef CONFIG_AUFS_DEBUG
26162 + /* reduce stack space */
26164 + struct au_opt_add *add;
26165 + struct au_opt_del *del;
26166 + struct au_opt_mod *mod;
26167 + struct au_opt_xino *xino;
26168 + struct au_opt_xino_itrunc *xino_itrunc;
26169 + struct au_opt_wbr_create *create;
26171 + struct au_opt *opt;
26174 + while (opt->type != Opt_tail) {
26175 + switch (opt->type) {
26177 + u.add = &opt->add;
26178 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26179 + u.add->bindex, u.add->pathname, u.add->perm,
26180 + u.add->path.dentry);
26184 + u.del = &opt->del;
26185 + AuDbg("del {%s, %p}\n",
26186 + u.del->pathname, u.del->h_path.dentry);
26190 + u.mod = &opt->mod;
26191 + AuDbg("mod {%s, 0x%x, %p}\n",
26192 + u.mod->path, u.mod->perm, u.mod->h_root);
26195 + u.add = &opt->add;
26196 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26197 + u.add->bindex, u.add->pathname, u.add->perm,
26198 + u.add->path.dentry);
26200 + case Opt_prepend:
26201 + u.add = &opt->add;
26202 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26203 + u.add->bindex, u.add->pathname, u.add->perm,
26204 + u.add->path.dentry);
26207 + AuDbg("dirwh %d\n", opt->dirwh);
26209 + case Opt_rdcache:
26210 + AuDbg("rdcache %d\n", opt->rdcache);
26213 + AuDbg("rdblk %u\n", opt->rdblk);
26215 + case Opt_rdblk_def:
26216 + AuDbg("rdblk_def\n");
26219 + AuDbg("rdhash %u\n", opt->rdhash);
26221 + case Opt_rdhash_def:
26222 + AuDbg("rdhash_def\n");
26225 + u.xino = &opt->xino;
26226 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26228 + case Opt_trunc_xino:
26229 + AuLabel(trunc_xino);
26231 + case Opt_notrunc_xino:
26232 + AuLabel(notrunc_xino);
26234 + case Opt_trunc_xino_path:
26235 + case Opt_itrunc_xino:
26236 + u.xino_itrunc = &opt->xino_itrunc;
26237 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26242 + case Opt_trunc_xib:
26243 + AuLabel(trunc_xib);
26245 + case Opt_notrunc_xib:
26246 + AuLabel(notrunc_xib);
26254 + case Opt_dirperm1:
26255 + AuLabel(dirperm1);
26257 + case Opt_nodirperm1:
26258 + AuLabel(nodirperm1);
26263 + case Opt_noplink:
26264 + AuLabel(noplink);
26266 + case Opt_list_plink:
26267 + AuLabel(list_plink);
26270 + AuDbg("udba %d, %s\n",
26271 + opt->udba, au_optstr_udba(opt->udba));
26279 + case Opt_diropq_a:
26280 + AuLabel(diropq_a);
26282 + case Opt_diropq_w:
26283 + AuLabel(diropq_w);
26285 + case Opt_warn_perm:
26286 + AuLabel(warn_perm);
26288 + case Opt_nowarn_perm:
26289 + AuLabel(nowarn_perm);
26291 + case Opt_verbose:
26292 + AuLabel(verbose);
26294 + case Opt_noverbose:
26295 + AuLabel(noverbose);
26306 + case Opt_wbr_create:
26307 + u.create = &opt->wbr_create;
26308 + AuDbg("create %d, %s\n", u.create->wbr_create,
26309 + au_optstr_wbr_create(u.create->wbr_create));
26310 + switch (u.create->wbr_create) {
26311 + case AuWbrCreate_MFSV:
26312 + case AuWbrCreate_PMFSV:
26313 + AuDbg("%d sec\n", u.create->mfs_second);
26315 + case AuWbrCreate_MFSRR:
26316 + case AuWbrCreate_TDMFS:
26317 + AuDbg("%llu watermark\n",
26318 + u.create->mfsrr_watermark);
26320 + case AuWbrCreate_MFSRRV:
26321 + case AuWbrCreate_TDMFSV:
26322 + case AuWbrCreate_PMFSRRV:
26323 + AuDbg("%llu watermark, %d sec\n",
26324 + u.create->mfsrr_watermark,
26325 + u.create->mfs_second);
26329 + case Opt_wbr_copyup:
26330 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26331 + au_optstr_wbr_copyup(opt->wbr_copyup));
26333 + case Opt_fhsm_sec:
26334 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26339 + case Opt_nodirren:
26340 + AuLabel(nodirren);
26356 +void au_opts_free(struct au_opts *opts)
26358 + struct au_opt *opt;
26361 + while (opt->type != Opt_tail) {
26362 + switch (opt->type) {
26365 + case Opt_prepend:
26366 + path_put(&opt->add.path);
26370 + path_put(&opt->del.h_path);
26374 + dput(opt->mod.h_root);
26377 + fput(opt->xino.file);
26384 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26385 + aufs_bindex_t bindex)
26388 + struct au_opt_add *add = &opt->add;
26391 + add->bindex = bindex;
26392 + add->perm = AuBrPerm_RO;
26393 + add->pathname = opt_str;
26394 + p = strchr(opt_str, '=');
26398 + add->perm = br_perm_val(p);
26401 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26404 + add->perm = AuBrPerm_RO;
26405 + if (au_test_fs_rr(add->path.dentry->d_sb))
26406 + add->perm = AuBrPerm_RR;
26407 + else if (!bindex && !(sb_flags & SB_RDONLY))
26408 + add->perm = AuBrPerm_RW;
26410 + opt->type = Opt_add;
26413 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26420 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26424 + del->pathname = args[0].from;
26425 + AuDbg("del path %s\n", del->pathname);
26427 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26428 + if (unlikely(err))
26429 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26434 +#if 0 /* reserved for future use */
26435 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26436 + struct au_opt_del *del, substring_t args[])
26439 + struct dentry *root;
26442 + root = sb->s_root;
26443 + aufs_read_lock(root, AuLock_FLUSH);
26444 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26445 + pr_err("out of bounds, %d\n", bindex);
26450 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26451 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26454 + aufs_read_unlock(root, !AuLock_IR);
26459 +static int noinline_for_stack
26460 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26463 + struct path path;
26467 + mod->path = args[0].from;
26468 + p = strchr(mod->path, '=');
26469 + if (unlikely(!p)) {
26470 + pr_err("no permission %s\n", args[0].from);
26475 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26476 + if (unlikely(err)) {
26477 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26481 + mod->perm = br_perm_val(p);
26482 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26483 + mod->h_root = dget(path.dentry);
26490 +#if 0 /* reserved for future use */
26491 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26492 + struct au_opt_mod *mod, substring_t args[])
26495 + struct dentry *root;
26498 + root = sb->s_root;
26499 + aufs_read_lock(root, AuLock_FLUSH);
26500 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26501 + pr_err("out of bounds, %d\n", bindex);
26506 + mod->perm = br_perm_val(args[1].from);
26507 + AuDbg("mod path %s, perm 0x%x, %s\n",
26508 + mod->path, mod->perm, args[1].from);
26509 + mod->h_root = dget(au_h_dptr(root, bindex));
26512 + aufs_read_unlock(root, !AuLock_IR);
26517 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26518 + substring_t args[])
26521 + struct file *file;
26523 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26524 + err = PTR_ERR(file);
26525 + if (IS_ERR(file))
26529 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26531 + pr_err("%s must be outside\n", args[0].from);
26536 + xino->file = file;
26537 + xino->path = args[0].from;
26543 +static int noinline_for_stack
26544 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26545 + struct au_opt_xino_itrunc *xino_itrunc,
26546 + substring_t args[])
26549 + aufs_bindex_t bbot, bindex;
26550 + struct path path;
26551 + struct dentry *root;
26553 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26554 + if (unlikely(err)) {
26555 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26559 + xino_itrunc->bindex = -1;
26560 + root = sb->s_root;
26561 + aufs_read_lock(root, AuLock_FLUSH);
26562 + bbot = au_sbbot(sb);
26563 + for (bindex = 0; bindex <= bbot; bindex++) {
26564 + if (au_h_dptr(root, bindex) == path.dentry) {
26565 + xino_itrunc->bindex = bindex;
26569 + aufs_read_unlock(root, !AuLock_IR);
26572 + if (unlikely(xino_itrunc->bindex < 0)) {
26573 + pr_err("no such branch %s\n", args[0].from);
26581 +/* called without aufs lock */
26582 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26584 + int err, n, token;
26585 + aufs_bindex_t bindex;
26586 + unsigned char skipped;
26587 + struct dentry *root;
26588 + struct au_opt *opt, *opt_tail;
26590 + /* reduce the stack space */
26592 + struct au_opt_xino_itrunc *xino_itrunc;
26593 + struct au_opt_wbr_create *create;
26596 + substring_t args[MAX_OPT_ARGS];
26600 + a = kmalloc(sizeof(*a), GFP_NOFS);
26601 + if (unlikely(!a))
26604 + root = sb->s_root;
26608 + opt_tail = opt + opts->max_opt - 1;
26609 + opt->type = Opt_tail;
26610 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26613 + token = match_token(opt_str, options, a->args);
26617 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26619 + err = opt_add(opt, opt_str, opts->sb_flags,
26621 + if (unlikely(!err && ++opt > opt_tail)) {
26625 + opt->type = Opt_tail;
26630 + if (unlikely(match_int(&a->args[0], &n))) {
26631 + pr_err("bad integer in %s\n", opt_str);
26635 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26638 + opt->type = token;
26641 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26642 + /*dummy bindex*/1);
26644 + opt->type = token;
26646 + case Opt_prepend:
26647 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26650 + opt->type = token;
26653 + err = au_opts_parse_del(&opt->del, a->args);
26655 + opt->type = token;
26657 +#if 0 /* reserved for future use */
26659 + del->pathname = "(indexed)";
26660 + if (unlikely(match_int(&args[0], &n))) {
26661 + pr_err("bad integer in %s\n", opt_str);
26664 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26666 + opt->type = token;
26670 + err = au_opts_parse_mod(&opt->mod, a->args);
26672 + opt->type = token;
26674 +#ifdef IMOD /* reserved for future use */
26676 + u.mod->path = "(indexed)";
26677 + if (unlikely(match_int(&a->args[0], &n))) {
26678 + pr_err("bad integer in %s\n", opt_str);
26681 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26683 + opt->type = token;
26687 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26689 + opt->type = token;
26692 + case Opt_trunc_xino_path:
26693 + err = au_opts_parse_xino_itrunc_path
26694 + (sb, &opt->xino_itrunc, a->args);
26696 + opt->type = token;
26699 + case Opt_itrunc_xino:
26700 + u.xino_itrunc = &opt->xino_itrunc;
26701 + if (unlikely(match_int(&a->args[0], &n))) {
26702 + pr_err("bad integer in %s\n", opt_str);
26705 + u.xino_itrunc->bindex = n;
26706 + aufs_read_lock(root, AuLock_FLUSH);
26707 + if (n < 0 || au_sbbot(sb) < n) {
26708 + pr_err("out of bounds, %d\n", n);
26709 + aufs_read_unlock(root, !AuLock_IR);
26712 + aufs_read_unlock(root, !AuLock_IR);
26714 + opt->type = token;
26718 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26721 + opt->type = token;
26724 + case Opt_rdcache:
26725 + if (unlikely(match_int(&a->args[0], &n))) {
26726 + pr_err("bad integer in %s\n", opt_str);
26729 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26730 + pr_err("rdcache must be smaller than %d\n",
26731 + AUFS_RDCACHE_MAX);
26734 + opt->rdcache = n;
26736 + opt->type = token;
26739 + if (unlikely(match_int(&a->args[0], &n)
26741 + || n > KMALLOC_MAX_SIZE)) {
26742 + pr_err("bad integer in %s\n", opt_str);
26745 + if (unlikely(n && n < NAME_MAX)) {
26746 + pr_err("rdblk must be larger than %d\n",
26752 + opt->type = token;
26755 + if (unlikely(match_int(&a->args[0], &n)
26757 + || n * sizeof(struct hlist_head)
26758 + > KMALLOC_MAX_SIZE)) {
26759 + pr_err("bad integer in %s\n", opt_str);
26764 + opt->type = token;
26767 + case Opt_trunc_xino:
26768 + case Opt_notrunc_xino:
26770 + case Opt_trunc_xib:
26771 + case Opt_notrunc_xib:
26774 + case Opt_dirperm1:
26775 + case Opt_nodirperm1:
26777 + case Opt_noplink:
26778 + case Opt_list_plink:
26781 + case Opt_diropq_a:
26782 + case Opt_diropq_w:
26783 + case Opt_warn_perm:
26784 + case Opt_nowarn_perm:
26785 + case Opt_verbose:
26786 + case Opt_noverbose:
26790 + case Opt_rdblk_def:
26791 + case Opt_rdhash_def:
26793 + case Opt_nodirren:
26797 + opt->type = token;
26801 + opt->udba = udba_val(a->args[0].from);
26802 + if (opt->udba >= 0) {
26804 + opt->type = token;
26806 + pr_err("wrong value, %s\n", opt_str);
26809 + case Opt_wbr_create:
26810 + u.create = &opt->wbr_create;
26811 + u.create->wbr_create
26812 + = au_wbr_create_val(a->args[0].from, u.create);
26813 + if (u.create->wbr_create >= 0) {
26815 + opt->type = token;
26817 + pr_err("wrong value, %s\n", opt_str);
26819 + case Opt_wbr_copyup:
26820 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26821 + if (opt->wbr_copyup >= 0) {
26823 + opt->type = token;
26825 + pr_err("wrong value, %s\n", opt_str);
26828 + case Opt_fhsm_sec:
26829 + if (unlikely(match_int(&a->args[0], &n)
26831 + pr_err("bad integer in %s\n", opt_str);
26834 + if (sysaufs_brs) {
26835 + opt->fhsm_second = n;
26836 + opt->type = token;
26838 + pr_warn("ignored %s\n", opt_str);
26843 + pr_warn("ignored %s\n", opt_str);
26845 + case Opt_ignore_silent:
26850 + pr_err("unknown option %s\n", opt_str);
26854 + if (!err && !skipped) {
26855 + if (unlikely(++opt > opt_tail)) {
26858 + opt->type = Opt_tail;
26861 + opt->type = Opt_tail;
26867 + if (unlikely(err))
26868 + au_opts_free(opts);
26874 +static int au_opt_wbr_create(struct super_block *sb,
26875 + struct au_opt_wbr_create *create)
26878 + struct au_sbinfo *sbinfo;
26880 + SiMustWriteLock(sb);
26882 + err = 1; /* handled */
26883 + sbinfo = au_sbi(sb);
26884 + if (sbinfo->si_wbr_create_ops->fin) {
26885 + err = sbinfo->si_wbr_create_ops->fin(sb);
26890 + sbinfo->si_wbr_create = create->wbr_create;
26891 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26892 + switch (create->wbr_create) {
26893 + case AuWbrCreate_MFSRRV:
26894 + case AuWbrCreate_MFSRR:
26895 + case AuWbrCreate_TDMFS:
26896 + case AuWbrCreate_TDMFSV:
26897 + case AuWbrCreate_PMFSRR:
26898 + case AuWbrCreate_PMFSRRV:
26899 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26901 + case AuWbrCreate_MFS:
26902 + case AuWbrCreate_MFSV:
26903 + case AuWbrCreate_PMFS:
26904 + case AuWbrCreate_PMFSV:
26905 + sbinfo->si_wbr_mfs.mfs_expire
26906 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26910 + if (sbinfo->si_wbr_create_ops->init)
26911 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26918 + * plus: processed without an error
26919 + * zero: unprocessed
26921 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26922 + struct au_opts *opts)
26925 + struct au_sbinfo *sbinfo;
26927 + SiMustWriteLock(sb);
26929 + err = 1; /* handled */
26930 + sbinfo = au_sbi(sb);
26931 + switch (opt->type) {
26933 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26934 + sbinfo->si_mntflags |= opt->udba;
26935 + opts->given_udba |= opt->udba;
26939 + au_opt_set(sbinfo->si_mntflags, PLINK);
26941 + case Opt_noplink:
26942 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26943 + au_plink_put(sb, /*verbose*/1);
26944 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26946 + case Opt_list_plink:
26947 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26948 + au_plink_list(sb);
26952 + au_opt_set(sbinfo->si_mntflags, DIO);
26953 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26956 + au_opt_clr(sbinfo->si_mntflags, DIO);
26957 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26960 + case Opt_fhsm_sec:
26961 + au_fhsm_set(sbinfo, opt->fhsm_second);
26964 + case Opt_diropq_a:
26965 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26967 + case Opt_diropq_w:
26968 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26971 + case Opt_warn_perm:
26972 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26974 + case Opt_nowarn_perm:
26975 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26978 + case Opt_verbose:
26979 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26981 + case Opt_noverbose:
26982 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26986 + au_opt_set(sbinfo->si_mntflags, SUM);
26989 + au_opt_clr(sbinfo->si_mntflags, SUM);
26990 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26993 + au_opt_clr(sbinfo->si_mntflags, SUM);
26994 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26997 + case Opt_wbr_create:
26998 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27000 + case Opt_wbr_copyup:
27001 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27002 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27006 + sbinfo->si_dirwh = opt->dirwh;
27009 + case Opt_rdcache:
27010 + sbinfo->si_rdcache
27011 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27014 + sbinfo->si_rdblk = opt->rdblk;
27016 + case Opt_rdblk_def:
27017 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27020 + sbinfo->si_rdhash = opt->rdhash;
27022 + case Opt_rdhash_def:
27023 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27027 + au_opt_set(sbinfo->si_mntflags, SHWH);
27030 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27033 + case Opt_dirperm1:
27034 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27036 + case Opt_nodirperm1:
27037 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27040 + case Opt_trunc_xino:
27041 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27043 + case Opt_notrunc_xino:
27044 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27047 + case Opt_trunc_xino_path:
27048 + case Opt_itrunc_xino:
27049 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27055 + case Opt_trunc_xib:
27056 + au_fset_opts(opts->flags, TRUNC_XIB);
27058 + case Opt_notrunc_xib:
27059 + au_fclr_opts(opts->flags, TRUNC_XIB);
27064 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27065 + err = au_dr_opt_set(sb);
27070 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27072 + case Opt_nodirren:
27074 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27075 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27081 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27085 + sb->s_flags |= SB_POSIXACL;
27088 + sb->s_flags &= ~SB_POSIXACL;
27100 + * returns tri-state.
27101 + * plus: processed without an error
27102 + * zero: unprocessed
27105 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27106 + struct au_opts *opts)
27108 + int err, do_refresh;
27111 + switch (opt->type) {
27113 + opt->add.bindex = au_sbbot(sb) + 1;
27114 + if (opt->add.bindex < 0)
27115 + opt->add.bindex = 0;
27117 + /* Always goto add, not fallthrough */
27118 + case Opt_prepend:
27119 + opt->add.bindex = 0;
27121 + add: /* indented label */
27123 + err = au_br_add(sb, &opt->add,
27124 + au_ftest_opts(opts->flags, REMOUNT));
27127 + au_fset_opts(opts->flags, REFRESH);
27133 + err = au_br_del(sb, &opt->del,
27134 + au_ftest_opts(opts->flags, REMOUNT));
27137 + au_fset_opts(opts->flags, TRUNC_XIB);
27138 + au_fset_opts(opts->flags, REFRESH);
27144 + err = au_br_mod(sb, &opt->mod,
27145 + au_ftest_opts(opts->flags, REMOUNT),
27150 + au_fset_opts(opts->flags, REFRESH);
27157 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27158 + struct au_opt_xino **opt_xino,
27159 + struct au_opts *opts)
27164 + switch (opt->type) {
27166 + err = au_xino_set(sb, &opt->xino,
27167 + !!au_ftest_opts(opts->flags, REMOUNT));
27168 + if (unlikely(err))
27171 + *opt_xino = &opt->xino;
27176 + *opt_xino = (void *)-1;
27183 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27184 + unsigned int pending)
27187 + aufs_bindex_t bindex, bbot;
27188 + unsigned char do_plink, skip, do_free, can_no_dreval;
27189 + struct au_branch *br;
27190 + struct au_wbr *wbr;
27191 + struct dentry *root, *dentry;
27192 + struct inode *dir, *h_dir;
27193 + struct au_sbinfo *sbinfo;
27194 + struct au_hinode *hdir;
27196 + SiMustAnyLock(sb);
27198 + sbinfo = au_sbi(sb);
27199 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27201 + if (!(sb_flags & SB_RDONLY)) {
27202 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27203 + pr_warn("first branch should be rw\n");
27204 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27205 + pr_warn_once("shwh should be used with ro\n");
27208 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27209 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27210 + pr_warn_once("udba=*notify requires xino\n");
27212 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27213 + pr_warn_once("dirperm1 breaks the protection"
27214 + " by the permission bits on the lower branch\n");
27218 + root = sb->s_root;
27219 + dir = d_inode(root);
27220 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27221 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27223 + bbot = au_sbbot(sb);
27224 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27226 + h_dir = au_h_iptr(dir, bindex);
27227 + br = au_sbr(sb, bindex);
27229 + if ((br->br_perm & AuBrAttr_ICEX)
27230 + && !h_dir->i_op->listxattr)
27231 + br->br_perm &= ~AuBrAttr_ICEX;
27232 +#if 0 /* untested */
27233 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27234 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27235 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27239 + wbr = br->br_wbr;
27241 + wbr_wh_read_lock(wbr);
27243 + if (!au_br_writable(br->br_perm)) {
27246 + || (!wbr->wbr_whbase
27247 + && !wbr->wbr_plink
27248 + && !wbr->wbr_orph));
27249 + } else if (!au_br_wh_linkable(br->br_perm)) {
27250 + /* skip = (!br->br_whbase && !br->br_orph); */
27251 + skip = (!wbr || !wbr->wbr_whbase);
27252 + if (skip && wbr) {
27254 + skip = !!wbr->wbr_plink;
27256 + skip = !wbr->wbr_plink;
27259 + /* skip = (br->br_whbase && br->br_ohph); */
27260 + skip = (wbr && wbr->wbr_whbase);
27263 + skip = !!wbr->wbr_plink;
27265 + skip = !wbr->wbr_plink;
27269 + wbr_wh_read_unlock(wbr);
27271 + if (can_no_dreval) {
27272 + dentry = br->br_path.dentry;
27273 + spin_lock(&dentry->d_lock);
27274 + if (dentry->d_flags &
27275 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27276 + can_no_dreval = 0;
27277 + spin_unlock(&dentry->d_lock);
27280 + if (au_br_fhsm(br->br_perm)) {
27282 + AuDebugOn(!br->br_fhsm);
27288 + hdir = au_hi(dir, bindex);
27289 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27291 + wbr_wh_write_lock(wbr);
27292 + err = au_wh_init(br, sb);
27294 + wbr_wh_write_unlock(wbr);
27295 + au_hn_inode_unlock(hdir);
27297 + if (!err && do_free) {
27298 + au_kfree_rcu(wbr);
27299 + br->br_wbr = NULL;
27303 + if (can_no_dreval)
27304 + au_fset_si(sbinfo, NO_DREVAL);
27306 + au_fclr_si(sbinfo, NO_DREVAL);
27309 + au_fset_si(sbinfo, FHSM);
27310 + for (bindex = bbot; bindex >= 0; bindex--) {
27311 + br = au_sbr(sb, bindex);
27312 + if (au_br_fhsm(br->br_perm)) {
27313 + au_fhsm_set_bottom(sb, bindex);
27318 + au_fclr_si(sbinfo, FHSM);
27319 + au_fhsm_set_bottom(sb, -1);
27325 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27328 + unsigned int tmp;
27329 + aufs_bindex_t bindex, bbot;
27330 + struct au_opt *opt;
27331 + struct au_opt_xino *opt_xino, xino;
27332 + struct au_sbinfo *sbinfo;
27333 + struct au_branch *br;
27334 + struct inode *dir;
27336 + SiMustWriteLock(sb);
27341 + while (err >= 0 && opt->type != Opt_tail)
27342 + err = au_opt_simple(sb, opt++, opts);
27345 + else if (unlikely(err < 0))
27348 + /* disable xino and udba temporary */
27349 + sbinfo = au_sbi(sb);
27350 + tmp = sbinfo->si_mntflags;
27351 + au_opt_clr(sbinfo->si_mntflags, XINO);
27352 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27355 + while (err >= 0 && opt->type != Opt_tail)
27356 + err = au_opt_br(sb, opt++, opts);
27359 + else if (unlikely(err < 0))
27362 + bbot = au_sbbot(sb);
27363 + if (unlikely(bbot < 0)) {
27365 + pr_err("no branches\n");
27369 + if (au_opt_test(tmp, XINO))
27370 + au_opt_set(sbinfo->si_mntflags, XINO);
27372 + while (!err && opt->type != Opt_tail)
27373 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27374 + if (unlikely(err))
27377 + err = au_opts_verify(sb, sb->s_flags, tmp);
27378 + if (unlikely(err))
27381 + /* restore xino */
27382 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27383 + xino.file = au_xino_def(sb);
27384 + err = PTR_ERR(xino.file);
27385 + if (IS_ERR(xino.file))
27388 + err = au_xino_set(sb, &xino, /*remount*/0);
27390 + if (unlikely(err))
27394 + /* restore udba */
27395 + tmp &= AuOptMask_UDBA;
27396 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27397 + sbinfo->si_mntflags |= tmp;
27398 + bbot = au_sbbot(sb);
27399 + for (bindex = 0; bindex <= bbot; bindex++) {
27400 + br = au_sbr(sb, bindex);
27401 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27402 + if (unlikely(err))
27403 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27405 + /* go on even if err */
27407 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27408 + dir = d_inode(sb->s_root);
27409 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27416 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27419 + unsigned char no_dreval;
27420 + struct inode *dir;
27421 + struct au_opt_xino *opt_xino;
27422 + struct au_opt *opt;
27423 + struct au_sbinfo *sbinfo;
27425 + SiMustWriteLock(sb);
27427 + err = au_dr_opt_flush(sb);
27428 + if (unlikely(err))
27430 + au_fset_opts(opts->flags, DR_FLUSHED);
27432 + dir = d_inode(sb->s_root);
27433 + sbinfo = au_sbi(sb);
27436 + while (err >= 0 && opt->type != Opt_tail) {
27437 + err = au_opt_simple(sb, opt, opts);
27439 + err = au_opt_br(sb, opt, opts);
27441 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27447 + /* go on even err */
27449 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27450 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27451 + if (unlikely(rerr && !err))
27454 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27455 + au_fset_opts(opts->flags, REFRESH_IDOP);
27457 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27458 + rerr = au_xib_trunc(sb);
27459 + if (unlikely(rerr && !err))
27463 + /* will be handled by the caller */
27464 + if (!au_ftest_opts(opts->flags, REFRESH)
27465 + && (opts->given_udba
27466 + || au_opt_test(sbinfo->si_mntflags, XINO)
27467 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27469 + au_fset_opts(opts->flags, REFRESH);
27471 + AuDbg("status 0x%x\n", opts->flags);
27477 +/* ---------------------------------------------------------------------- */
27479 +unsigned int au_opt_udba(struct super_block *sb)
27481 + return au_mntflags(sb) & AuOptMask_UDBA;
27483 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27484 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27485 +++ linux/fs/aufs/opts.h 2021-12-03 15:38:59.939980643 +0100
27487 +/* SPDX-License-Identifier: GPL-2.0 */
27489 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27491 + * This program, aufs is free software; you can redistribute it and/or modify
27492 + * it under the terms of the GNU General Public License as published by
27493 + * the Free Software Foundation; either version 2 of the License, or
27494 + * (at your option) any later version.
27496 + * This program is distributed in the hope that it will be useful,
27497 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27499 + * GNU General Public License for more details.
27501 + * You should have received a copy of the GNU General Public License
27502 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27506 + * mount options/flags
27509 +#ifndef __AUFS_OPTS_H__
27510 +#define __AUFS_OPTS_H__
27514 +#include <linux/path.h>
27518 +/* ---------------------------------------------------------------------- */
27521 +#define AuOpt_XINO 1 /* external inode number bitmap
27522 + and translation table */
27523 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27524 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27525 +#define AuOpt_UDBA_REVAL (1 << 3)
27526 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27527 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27528 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27529 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27531 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27532 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27533 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27534 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27535 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27536 +#define AuOpt_DIO (1 << 14) /* direct io */
27537 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27539 +#ifndef CONFIG_AUFS_HNOTIFY
27540 +#undef AuOpt_UDBA_HNOTIFY
27541 +#define AuOpt_UDBA_HNOTIFY 0
27543 +#ifndef CONFIG_AUFS_DIRREN
27544 +#undef AuOpt_DIRREN
27545 +#define AuOpt_DIRREN 0
27547 +#ifndef CONFIG_AUFS_SHWH
27549 +#define AuOpt_SHWH 0
27552 +#define AuOpt_Def (AuOpt_XINO \
27553 + | AuOpt_UDBA_REVAL \
27555 + /* | AuOpt_DIRPERM1 */ \
27556 + | AuOpt_WARN_PERM)
27557 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27558 + | AuOpt_UDBA_REVAL \
27559 + | AuOpt_UDBA_HNOTIFY)
27561 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27562 +#define au_opt_set(flags, name) do { \
27563 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27564 + ((flags) |= AuOpt_##name); \
27566 +#define au_opt_set_udba(flags, name) do { \
27567 + (flags) &= ~AuOptMask_UDBA; \
27568 + ((flags) |= AuOpt_##name); \
27570 +#define au_opt_clr(flags, name) do { \
27571 + ((flags) &= ~AuOpt_##name); \
27574 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27576 +#ifdef CONFIG_PROC_FS
27579 + return mntflags & ~AuOpt_PLINK;
27583 +/* ---------------------------------------------------------------------- */
27585 +/* policies to select one among multiple writable branches */
27587 + AuWbrCreate_TDP, /* top down parent */
27588 + AuWbrCreate_RR, /* round robin */
27589 + AuWbrCreate_MFS, /* most free space */
27590 + AuWbrCreate_MFSV, /* mfs with seconds */
27591 + AuWbrCreate_MFSRR, /* mfs then rr */
27592 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27593 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27594 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27595 + AuWbrCreate_PMFS, /* parent and mfs */
27596 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27597 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27598 + AuWbrCreate_PMFSRRV, /* plus seconds */
27600 + AuWbrCreate_Def = AuWbrCreate_TDP
27604 + AuWbrCopyup_TDP, /* top down parent */
27605 + AuWbrCopyup_BUP, /* bottom up parent */
27606 + AuWbrCopyup_BU, /* bottom up */
27608 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27611 +/* ---------------------------------------------------------------------- */
27613 +struct au_opt_add {
27614 + aufs_bindex_t bindex;
27617 + struct path path;
27620 +struct au_opt_del {
27622 + struct path h_path;
27625 +struct au_opt_mod {
27628 + struct dentry *h_root;
27631 +struct au_opt_xino {
27633 + struct file *file;
27636 +struct au_opt_xino_itrunc {
27637 + aufs_bindex_t bindex;
27640 +struct au_opt_wbr_create {
27643 + unsigned long long mfsrr_watermark;
27649 + struct au_opt_xino xino;
27650 + struct au_opt_xino_itrunc xino_itrunc;
27651 + struct au_opt_add add;
27652 + struct au_opt_del del;
27653 + struct au_opt_mod mod;
27656 + unsigned int rdblk;
27657 + unsigned int rdhash;
27659 + struct au_opt_wbr_create wbr_create;
27661 + unsigned int fhsm_second;
27666 +#define AuOpts_REMOUNT 1
27667 +#define AuOpts_REFRESH (1 << 1)
27668 +#define AuOpts_TRUNC_XIB (1 << 2)
27669 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27670 +#define AuOpts_REFRESH_IDOP (1 << 4)
27671 +#define AuOpts_DR_FLUSHED (1 << 5)
27672 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27673 +#define au_fset_opts(flags, name) \
27674 + do { (flags) |= AuOpts_##name; } while (0)
27675 +#define au_fclr_opts(flags, name) \
27676 + do { (flags) &= ~AuOpts_##name; } while (0)
27678 +#ifndef CONFIG_AUFS_DIRREN
27679 +#undef AuOpts_DR_FLUSHED
27680 +#define AuOpts_DR_FLUSHED 0
27684 + struct au_opt *opt;
27687 + unsigned int given_udba;
27688 + unsigned int flags;
27689 + unsigned long sb_flags;
27692 +/* ---------------------------------------------------------------------- */
27695 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27696 +const char *au_optstr_udba(int udba);
27697 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27698 +const char *au_optstr_wbr_create(int wbr_create);
27700 +void au_opts_free(struct au_opts *opts);
27701 +struct super_block;
27702 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27703 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27704 + unsigned int pending);
27705 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27706 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27708 +unsigned int au_opt_udba(struct super_block *sb);
27710 +#endif /* __KERNEL__ */
27711 +#endif /* __AUFS_OPTS_H__ */
27712 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27713 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27714 +++ linux/fs/aufs/plink.c 2021-12-03 15:38:59.939980643 +0100
27716 +// SPDX-License-Identifier: GPL-2.0
27718 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27720 + * This program, aufs is free software; you can redistribute it and/or modify
27721 + * it under the terms of the GNU General Public License as published by
27722 + * the Free Software Foundation; either version 2 of the License, or
27723 + * (at your option) any later version.
27725 + * This program is distributed in the hope that it will be useful,
27726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27728 + * GNU General Public License for more details.
27730 + * You should have received a copy of the GNU General Public License
27731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27741 + * the pseudo-link maintenance mode.
27742 + * during a user process maintains the pseudo-links,
27743 + * prohibit adding a new plink and branch manipulation.
27747 + * For entry functions which will handle plink, and i_mutex is already held
27749 + * They cannot wait and should return an error at once.
27750 + * Callers has to check the error.
27752 + * For entry functions which will handle plink, but i_mutex is not held
27754 + * They can wait the plink maintenance mode to finish.
27756 + * They behave like F_SETLK and F_SETLKW.
27757 + * If the caller never handle plink, then both flags are unnecessary.
27760 +int au_plink_maint(struct super_block *sb, int flags)
27764 + struct task_struct *parent, *prev;
27765 + struct au_sbinfo *sbi;
27767 + SiMustAnyLock(sb);
27770 + if (!au_opt_test(au_mntflags(sb), PLINK))
27773 + sbi = au_sbi(sb);
27774 + pid = sbi->si_plink_maint_pid;
27775 + if (!pid || pid == current->pid)
27778 + /* todo: it highly depends upon /sbin/mount.aufs */
27780 + parent = current;
27784 + parent = rcu_dereference(parent->real_parent);
27785 + if (parent == prev)
27787 + ppid = task_pid_vnr(parent);
27788 + if (pid == ppid) {
27789 + rcu_read_unlock();
27794 + rcu_read_unlock();
27796 + if (au_ftest_lock(flags, NOPLMW)) {
27797 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27798 + /* AuDebugOn(!lockdep_depth(current)); */
27799 + while (sbi->si_plink_maint_pid) {
27800 + si_read_unlock(sb);
27801 + /* gave up wake_up_bit() */
27802 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27804 + if (au_ftest_lock(flags, FLUSH))
27805 + au_nwt_flush(&sbi->si_nowait);
27806 + si_noflush_read_lock(sb);
27808 + } else if (au_ftest_lock(flags, NOPLM)) {
27809 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27817 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27819 + spin_lock(&sbinfo->si_plink_maint_lock);
27820 + sbinfo->si_plink_maint_pid = 0;
27821 + spin_unlock(&sbinfo->si_plink_maint_lock);
27822 + wake_up_all(&sbinfo->si_plink_wq);
27825 +int au_plink_maint_enter(struct super_block *sb)
27828 + struct au_sbinfo *sbinfo;
27831 + sbinfo = au_sbi(sb);
27832 + /* make sure i am the only one in this fs */
27833 + si_write_lock(sb, AuLock_FLUSH);
27834 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27835 + spin_lock(&sbinfo->si_plink_maint_lock);
27836 + if (!sbinfo->si_plink_maint_pid)
27837 + sbinfo->si_plink_maint_pid = current->pid;
27840 + spin_unlock(&sbinfo->si_plink_maint_lock);
27842 + si_write_unlock(sb);
27847 +/* ---------------------------------------------------------------------- */
27849 +#ifdef CONFIG_AUFS_DEBUG
27850 +void au_plink_list(struct super_block *sb)
27853 + struct au_sbinfo *sbinfo;
27854 + struct hlist_bl_head *hbl;
27855 + struct hlist_bl_node *pos;
27856 + struct au_icntnr *icntnr;
27858 + SiMustAnyLock(sb);
27860 + sbinfo = au_sbi(sb);
27861 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27862 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27864 + for (i = 0; i < AuPlink_NHASH; i++) {
27865 + hbl = sbinfo->si_plink + i;
27866 + hlist_bl_lock(hbl);
27867 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27868 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27869 + hlist_bl_unlock(hbl);
27874 +/* is the inode pseudo-linked? */
27875 +int au_plink_test(struct inode *inode)
27878 + struct au_sbinfo *sbinfo;
27879 + struct hlist_bl_head *hbl;
27880 + struct hlist_bl_node *pos;
27881 + struct au_icntnr *icntnr;
27883 + sbinfo = au_sbi(inode->i_sb);
27884 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27885 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27886 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27889 + i = au_plink_hash(inode->i_ino);
27890 + hbl = sbinfo->si_plink + i;
27891 + hlist_bl_lock(hbl);
27892 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27893 + if (&icntnr->vfs_inode == inode) {
27897 + hlist_bl_unlock(hbl);
27901 +/* ---------------------------------------------------------------------- */
27904 + * generate a name for plink.
27905 + * the file will be stored under AUFS_WH_PLINKDIR.
27907 +/* 20 is max digits length of ulong 64 */
27908 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27910 +static int plink_name(char *name, int len, struct inode *inode,
27911 + aufs_bindex_t bindex)
27914 + struct inode *h_inode;
27916 + h_inode = au_h_iptr(inode, bindex);
27917 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27921 +struct au_do_plink_lkup_args {
27922 + struct dentry **errp;
27923 + struct qstr *tgtname;
27924 + struct path *h_ppath;
27927 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27928 + struct path *h_ppath)
27930 + struct dentry *h_dentry;
27931 + struct inode *h_inode;
27933 + h_inode = d_inode(h_ppath->dentry);
27934 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27935 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
27936 + inode_unlock_shared(h_inode);
27941 +static void au_call_do_plink_lkup(void *args)
27943 + struct au_do_plink_lkup_args *a = args;
27944 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
27947 +/* lookup the plink-ed @inode under the branch at @bindex */
27948 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27950 + struct dentry *h_dentry;
27951 + struct au_branch *br;
27952 + struct path h_ppath;
27954 + char a[PLINK_NAME_LEN];
27955 + struct qstr tgtname = QSTR_INIT(a, 0);
27957 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27959 + br = au_sbr(inode->i_sb, bindex);
27960 + h_ppath.dentry = br->br_wbr->wbr_plink;
27961 + h_ppath.mnt = au_br_mnt(br);
27962 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27964 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27965 + struct au_do_plink_lkup_args args = {
27966 + .errp = &h_dentry,
27967 + .tgtname = &tgtname,
27968 + .h_ppath = &h_ppath
27971 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27972 + if (unlikely(wkq_err))
27973 + h_dentry = ERR_PTR(wkq_err);
27975 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
27980 +/* create a pseudo-link */
27981 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
27982 + struct dentry *h_dentry)
27985 + struct path h_path;
27986 + struct inode *h_dir, *delegated;
27988 + h_dir = d_inode(h_ppath->dentry);
27989 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27990 + h_path.mnt = h_ppath->mnt;
27992 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
27993 + err = PTR_ERR(h_path.dentry);
27994 + if (IS_ERR(h_path.dentry))
27998 + /* wh.plink dir is not monitored */
27999 + /* todo: is it really safe? */
28000 + if (d_is_positive(h_path.dentry)
28001 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28002 + delegated = NULL;
28003 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28004 + if (unlikely(err == -EWOULDBLOCK)) {
28005 + pr_warn("cannot retry for NFSv4 delegation"
28006 + " for an internal unlink\n");
28009 + dput(h_path.dentry);
28010 + h_path.dentry = NULL;
28014 + if (!err && d_is_negative(h_path.dentry)) {
28015 + delegated = NULL;
28016 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28017 + if (unlikely(err == -EWOULDBLOCK)) {
28018 + pr_warn("cannot retry for NFSv4 delegation"
28019 + " for an internal link\n");
28023 + dput(h_path.dentry);
28026 + inode_unlock(h_dir);
28030 +struct do_whplink_args {
28032 + struct qstr *tgt;
28033 + struct path *h_ppath;
28034 + struct dentry *h_dentry;
28037 +static void call_do_whplink(void *args)
28039 + struct do_whplink_args *a = args;
28040 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28043 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28044 + aufs_bindex_t bindex)
28046 + int err, wkq_err;
28047 + struct au_branch *br;
28048 + struct au_wbr *wbr;
28049 + struct path h_ppath;
28050 + char a[PLINK_NAME_LEN];
28051 + struct qstr tgtname = QSTR_INIT(a, 0);
28053 + br = au_sbr(inode->i_sb, bindex);
28054 + wbr = br->br_wbr;
28055 + h_ppath.dentry = wbr->wbr_plink;
28056 + h_ppath.mnt = au_br_mnt(br);
28057 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28059 + /* always superio. */
28060 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28061 + struct do_whplink_args args = {
28064 + .h_ppath = &h_ppath,
28065 + .h_dentry = h_dentry
28067 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28068 + if (unlikely(wkq_err))
28071 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28077 + * create a new pseudo-link for @h_dentry on @bindex.
28078 + * the linked inode is held in aufs @inode.
28080 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28081 + struct dentry *h_dentry)
28083 + struct super_block *sb;
28084 + struct au_sbinfo *sbinfo;
28085 + struct hlist_bl_head *hbl;
28086 + struct hlist_bl_node *pos;
28087 + struct au_icntnr *icntnr;
28088 + int found, err, cnt, i;
28090 + sb = inode->i_sb;
28091 + sbinfo = au_sbi(sb);
28092 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28093 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28095 + found = au_plink_test(inode);
28099 + i = au_plink_hash(inode->i_ino);
28100 + hbl = sbinfo->si_plink + i;
28103 + hlist_bl_lock(hbl);
28104 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28105 + if (&icntnr->vfs_inode == inode) {
28111 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28112 + hlist_bl_add_head(&icntnr->plink, hbl);
28114 + hlist_bl_unlock(hbl);
28116 + cnt = au_hbl_count(hbl);
28117 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28118 + if (cnt > AUFS_PLINK_WARN)
28119 + AuWarn1(msg ", %d\n", cnt);
28121 + err = whplink(h_dentry, inode, bindex);
28122 + if (unlikely(err)) {
28123 + pr_warn("err %d, damaged pseudo link.\n", err);
28124 + au_hbl_del(&icntnr->plink, hbl);
28125 + iput(&icntnr->vfs_inode);
28128 + iput(&icntnr->vfs_inode);
28131 +/* free all plinks */
28132 +void au_plink_put(struct super_block *sb, int verbose)
28135 + struct au_sbinfo *sbinfo;
28136 + struct hlist_bl_head *hbl;
28137 + struct hlist_bl_node *pos, *tmp;
28138 + struct au_icntnr *icntnr;
28140 + SiMustWriteLock(sb);
28142 + sbinfo = au_sbi(sb);
28143 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28144 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28146 + /* no spin_lock since sbinfo is write-locked */
28148 + for (i = 0; i < AuPlink_NHASH; i++) {
28149 + hbl = sbinfo->si_plink + i;
28150 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28151 + pr_warn("pseudo-link is not flushed");
28154 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28155 + iput(&icntnr->vfs_inode);
28156 + INIT_HLIST_BL_HEAD(hbl);
28160 +void au_plink_clean(struct super_block *sb, int verbose)
28162 + struct dentry *root;
28164 + root = sb->s_root;
28165 + aufs_write_lock(root);
28166 + if (au_opt_test(au_mntflags(sb), PLINK))
28167 + au_plink_put(sb, verbose);
28168 + aufs_write_unlock(root);
28171 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28174 + aufs_bindex_t btop, bbot, bindex;
28177 + btop = au_ibtop(inode);
28178 + bbot = au_ibbot(inode);
28180 + for (bindex = btop; bindex <= bbot; bindex++) {
28181 + if (!au_h_iptr(inode, bindex)
28182 + || au_ii_br_id(inode, bindex) != br_id)
28184 + au_set_h_iptr(inode, bindex, NULL, 0);
28189 + for (bindex = btop; bindex <= bbot; bindex++)
28190 + if (au_h_iptr(inode, bindex)) {
28200 +/* free the plinks on a branch specified by @br_id */
28201 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28203 + struct au_sbinfo *sbinfo;
28204 + struct hlist_bl_head *hbl;
28205 + struct hlist_bl_node *pos, *tmp;
28206 + struct au_icntnr *icntnr;
28207 + struct inode *inode;
28210 + SiMustWriteLock(sb);
28212 + sbinfo = au_sbi(sb);
28213 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28214 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28216 + /* no bit_lock since sbinfo is write-locked */
28217 + for (i = 0; i < AuPlink_NHASH; i++) {
28218 + hbl = sbinfo->si_plink + i;
28219 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28220 + inode = au_igrab(&icntnr->vfs_inode);
28221 + ii_write_lock_child(inode);
28222 + do_put = au_plink_do_half_refresh(inode, br_id);
28224 + hlist_bl_del(&icntnr->plink);
28227 + ii_write_unlock(inode);
28232 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28233 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28234 +++ linux/fs/aufs/poll.c 2021-12-03 15:38:59.939980643 +0100
28236 +// SPDX-License-Identifier: GPL-2.0
28238 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28240 + * This program, aufs is free software; you can redistribute it and/or modify
28241 + * it under the terms of the GNU General Public License as published by
28242 + * the Free Software Foundation; either version 2 of the License, or
28243 + * (at your option) any later version.
28245 + * This program is distributed in the hope that it will be useful,
28246 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28247 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28248 + * GNU General Public License for more details.
28250 + * You should have received a copy of the GNU General Public License
28251 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28256 + * There is only one filesystem which implements ->poll operation, currently.
28261 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28264 + struct file *h_file;
28265 + struct super_block *sb;
28267 + /* We should pretend an error happened. */
28268 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28269 + sb = file->f_path.dentry->d_sb;
28270 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28272 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28273 + if (IS_ERR(h_file)) {
28274 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28278 + mask = vfs_poll(h_file, pt);
28279 + fput(h_file); /* instead of au_read_post() */
28282 + si_read_unlock(sb);
28283 + if (mask & EPOLLERR)
28284 + AuDbg("mask 0x%x\n", mask);
28287 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28288 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28289 +++ linux/fs/aufs/posix_acl.c 2021-12-03 15:40:58.236647297 +0100
28291 +// SPDX-License-Identifier: GPL-2.0
28293 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28295 + * This program, aufs is free software; you can redistribute it and/or modify
28296 + * it under the terms of the GNU General Public License as published by
28297 + * the Free Software Foundation; either version 2 of the License, or
28298 + * (at your option) any later version.
28300 + * This program is distributed in the hope that it will be useful,
28301 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28302 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28303 + * GNU General Public License for more details.
28305 + * You should have received a copy of the GNU General Public License
28306 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28310 + * posix acl operations
28313 +#include <linux/fs.h>
28316 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28318 + struct posix_acl *acl;
28320 + aufs_bindex_t bindex;
28321 + struct inode *h_inode;
28322 + struct super_block *sb;
28324 + acl = ERR_PTR(-ECHILD);
28329 + sb = inode->i_sb;
28330 + si_read_lock(sb, AuLock_FLUSH);
28331 + ii_read_lock_child(inode);
28332 + if (!(sb->s_flags & SB_POSIXACL))
28335 + bindex = au_ibtop(inode);
28336 + h_inode = au_h_iptr(inode, bindex);
28337 + if (unlikely(!h_inode
28338 + || ((h_inode->i_mode & S_IFMT)
28339 + != (inode->i_mode & S_IFMT)))) {
28340 + err = au_busy_or_stale();
28341 + acl = ERR_PTR(err);
28345 + /* always topmost only */
28346 + acl = get_acl(h_inode, type);
28348 + forget_cached_acl(inode, type);
28350 + set_cached_acl(inode, type, acl);
28353 + ii_read_unlock(inode);
28354 + si_read_unlock(sb);
28357 + AuTraceErrPtr(acl);
28361 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28362 + struct posix_acl *acl, int type)
28366 + struct dentry *dentry;
28367 + struct au_sxattr arg = {
28368 + .type = AU_ACL_SET,
28375 + IMustLock(inode);
28377 + if (inode->i_ino == AUFS_ROOT_INO)
28378 + dentry = dget(inode->i_sb->s_root);
28380 + dentry = d_find_alias(inode);
28382 + dentry = d_find_any_alias(inode);
28384 + pr_warn("cannot handle this inode, "
28385 + "please report to aufs-users ML\n");
28391 + ssz = au_sxattr(dentry, inode, &arg);
28392 + /* forget even it if succeeds since the branch might set differently */
28393 + forget_cached_acl(inode, type);
28402 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28403 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28404 +++ linux/fs/aufs/procfs.c 2021-12-03 15:38:59.939980643 +0100
28406 +// SPDX-License-Identifier: GPL-2.0
28408 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28410 + * This program, aufs is free software; you can redistribute it and/or modify
28411 + * it under the terms of the GNU General Public License as published by
28412 + * the Free Software Foundation; either version 2 of the License, or
28413 + * (at your option) any later version.
28415 + * This program is distributed in the hope that it will be useful,
28416 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28417 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28418 + * GNU General Public License for more details.
28420 + * You should have received a copy of the GNU General Public License
28421 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28425 + * procfs interfaces
28428 +#include <linux/proc_fs.h>
28431 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28433 + struct au_sbinfo *sbinfo;
28435 + sbinfo = file->private_data;
28437 + au_plink_maint_leave(sbinfo);
28438 + kobject_put(&sbinfo->si_kobj);
28444 +static void au_procfs_plm_write_clean(struct file *file)
28446 + struct au_sbinfo *sbinfo;
28448 + sbinfo = file->private_data;
28450 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28453 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28456 + struct super_block *sb;
28457 + struct au_sbinfo *sbinfo;
28458 + struct hlist_bl_node *pos;
28461 + if (unlikely(file->private_data))
28465 + /* don't use au_sbilist_lock() here */
28466 + hlist_bl_lock(&au_sbilist);
28467 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28468 + if (id == sysaufs_si_id(sbinfo)) {
28469 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28470 + sb = sbinfo->si_sb;
28473 + hlist_bl_unlock(&au_sbilist);
28476 + if (unlikely(!sb))
28479 + err = au_plink_maint_enter(sb);
28481 + /* keep kobject_get() */
28482 + file->private_data = sbinfo;
28484 + kobject_put(&sbinfo->si_kobj);
28490 + * Accept a valid "si=xxxx" only.
28491 + * Once it is accepted successfully, accept "clean" too.
28493 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28494 + size_t count, loff_t *ppos)
28497 + unsigned long id;
28498 + /* last newline is allowed */
28499 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28502 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28506 + if (unlikely(count > sizeof(buf)))
28509 + err = copy_from_user(buf, ubuf, count);
28510 + if (unlikely(err)) {
28517 + if (!strcmp("clean", buf)) {
28518 + au_procfs_plm_write_clean(file);
28519 + goto out_success;
28520 + } else if (unlikely(strncmp("si=", buf, 3)))
28523 + err = kstrtoul(buf + 3, 16, &id);
28524 + if (unlikely(err))
28527 + err = au_procfs_plm_write_si(file, id);
28528 + if (unlikely(err))
28532 + err = count; /* success */
28537 +static const struct proc_ops au_procfs_plm_op = {
28538 + .proc_write = au_procfs_plm_write,
28539 + .proc_release = au_procfs_plm_release
28542 +/* ---------------------------------------------------------------------- */
28544 +static struct proc_dir_entry *au_procfs_dir;
28546 +void au_procfs_fin(void)
28548 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28549 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28552 +int __init au_procfs_init(void)
28555 + struct proc_dir_entry *entry;
28558 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28559 + if (unlikely(!au_procfs_dir))
28562 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28563 + au_procfs_dir, &au_procfs_plm_op);
28564 + if (unlikely(!entry))
28568 + goto out; /* success */
28572 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28576 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28577 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28578 +++ linux/fs/aufs/rdu.c 2021-12-03 15:38:59.939980643 +0100
28580 +// SPDX-License-Identifier: GPL-2.0
28582 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28584 + * This program, aufs is free software; you can redistribute it and/or modify
28585 + * it under the terms of the GNU General Public License as published by
28586 + * the Free Software Foundation; either version 2 of the License, or
28587 + * (at your option) any later version.
28589 + * This program is distributed in the hope that it will be useful,
28590 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28591 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28592 + * GNU General Public License for more details.
28594 + * You should have received a copy of the GNU General Public License
28595 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28599 + * readdir in userspace.
28602 +#include <linux/compat.h>
28603 +#include <linux/fs_stack.h>
28604 +#include <linux/security.h>
28607 +/* bits for struct aufs_rdu.flags */
28608 +#define AuRdu_CALLED 1
28609 +#define AuRdu_CONT (1 << 1)
28610 +#define AuRdu_FULL (1 << 2)
28611 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28612 +#define au_fset_rdu(flags, name) \
28613 + do { (flags) |= AuRdu_##name; } while (0)
28614 +#define au_fclr_rdu(flags, name) \
28615 + do { (flags) &= ~AuRdu_##name; } while (0)
28617 +struct au_rdu_arg {
28618 + struct dir_context ctx;
28619 + struct aufs_rdu *rdu;
28620 + union au_rdu_ent_ul ent;
28621 + unsigned long end;
28623 + struct super_block *sb;
28627 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28628 + loff_t offset, u64 h_ino, unsigned int d_type)
28631 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28632 + struct aufs_rdu *rdu = arg->rdu;
28633 + struct au_rdu_ent ent;
28637 + au_fset_rdu(rdu->cookie.flags, CALLED);
28638 + len = au_rdu_len(nlen);
28639 + if (arg->ent.ul + len < arg->end) {
28641 + ent.bindex = rdu->cookie.bindex;
28642 + ent.type = d_type;
28644 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28645 + ent.type = DT_UNKNOWN;
28647 + /* unnecessary to support mmap_sem since this is a dir */
28649 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28651 + if (copy_to_user(arg->ent.e->name, name, nlen))
28653 + /* the terminating NULL */
28654 + if (__put_user(0, arg->ent.e->name + nlen))
28657 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28658 + arg->ent.ul += len;
28662 + au_fset_rdu(rdu->cookie.flags, FULL);
28664 + rdu->tail = arg->ent;
28668 + /* AuTraceErr(err); */
28672 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28676 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28678 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28679 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28681 + if (unlikely(offset != cookie->h_pos))
28687 + au_fclr_rdu(cookie->flags, CALLED);
28689 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28693 + && au_ftest_rdu(cookie->flags, CALLED)
28694 + && !au_ftest_rdu(cookie->flags, FULL));
28695 + cookie->h_pos = h_file->f_pos;
28702 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28705 + aufs_bindex_t bbot;
28706 + struct au_rdu_arg arg = {
28708 + .actor = au_rdu_fill
28711 + struct dentry *dentry;
28712 + struct inode *inode;
28713 + struct file *h_file;
28714 + struct au_rdu_cookie *cookie = &rdu->cookie;
28716 + /* VERIFY_WRITE */
28717 + err = !access_ok(rdu->ent.e, rdu->sz);
28718 + if (unlikely(err)) {
28724 + rdu->tail = rdu->ent;
28727 + arg.ent = rdu->ent;
28728 + arg.end = arg.ent.ul;
28729 + arg.end += rdu->sz;
28732 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28735 + err = security_file_permission(file, MAY_READ);
28737 + if (unlikely(err))
28740 + dentry = file->f_path.dentry;
28741 + inode = d_inode(dentry);
28742 + inode_lock_shared(inode);
28744 + arg.sb = inode->i_sb;
28745 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28746 + if (unlikely(err))
28748 + err = au_alive_dir(dentry);
28749 + if (unlikely(err))
28751 + /* todo: reval? */
28752 + fi_read_lock(file);
28755 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28756 + && cookie->generation != au_figen(file)))
28761 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28763 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28765 + bbot = au_fbtop(file);
28766 + if (cookie->bindex < bbot)
28767 + cookie->bindex = bbot;
28768 + bbot = au_fbbot_dir(file);
28769 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28770 + for (; !err && cookie->bindex <= bbot;
28771 + cookie->bindex++, cookie->h_pos = 0) {
28772 + h_file = au_hf_dir(file, cookie->bindex);
28776 + au_fclr_rdu(cookie->flags, FULL);
28777 + err = au_rdu_do(h_file, &arg);
28779 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28782 + AuDbg("rent %llu\n", rdu->rent);
28784 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28785 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28786 + au_fset_rdu(cookie->flags, CONT);
28787 + cookie->generation = au_figen(file);
28790 + ii_read_lock_child(inode);
28791 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28792 + ii_read_unlock(inode);
28795 + fi_read_unlock(file);
28797 + si_read_unlock(arg.sb);
28799 + inode_unlock_shared(inode);
28805 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28809 + unsigned long long nent;
28810 + union au_rdu_ent_ul *u;
28811 + struct au_rdu_ent ent;
28812 + struct super_block *sb;
28815 + nent = rdu->nent;
28817 + sb = file->f_path.dentry->d_sb;
28818 + si_read_lock(sb, AuLock_FLUSH);
28819 + while (nent-- > 0) {
28820 + /* unnecessary to support mmap_sem since this is a dir */
28821 + err = copy_from_user(&ent, u->e, sizeof(ent));
28823 + /* VERIFY_WRITE */
28824 + err = !access_ok(&u->e->ino, sizeof(ino));
28825 + if (unlikely(err)) {
28831 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28833 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28835 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28837 + if (unlikely(err)) {
28842 + err = __put_user(ino, &u->e->ino);
28843 + if (unlikely(err)) {
28848 + u->ul += au_rdu_len(ent.nlen);
28850 + si_read_unlock(sb);
28855 +/* ---------------------------------------------------------------------- */
28857 +static int au_rdu_verify(struct aufs_rdu *rdu)
28859 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28860 + "%llu, b%d, 0x%x, g%u}\n",
28861 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28863 + rdu->rent, rdu->shwh, rdu->full,
28864 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28865 + rdu->cookie.generation);
28867 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28871 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28875 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28878 + struct aufs_rdu rdu;
28879 + void __user *p = (void __user *)arg;
28881 + err = copy_from_user(&rdu, p, sizeof(rdu));
28882 + if (unlikely(err)) {
28887 + err = au_rdu_verify(&rdu);
28888 + if (unlikely(err))
28892 + case AUFS_CTL_RDU:
28893 + err = au_rdu(file, &rdu);
28894 + if (unlikely(err))
28897 + e = copy_to_user(p, &rdu, sizeof(rdu));
28898 + if (unlikely(e)) {
28903 + case AUFS_CTL_RDU_INO:
28904 + err = au_rdu_ino(file, &rdu);
28908 + /* err = -ENOTTY; */
28917 +#ifdef CONFIG_COMPAT
28918 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28921 + struct aufs_rdu rdu;
28922 + void __user *p = compat_ptr(arg);
28924 + /* todo: get_user()? */
28925 + err = copy_from_user(&rdu, p, sizeof(rdu));
28926 + if (unlikely(err)) {
28931 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28932 + err = au_rdu_verify(&rdu);
28933 + if (unlikely(err))
28937 + case AUFS_CTL_RDU:
28938 + err = au_rdu(file, &rdu);
28939 + if (unlikely(err))
28942 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28943 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28944 + e = copy_to_user(p, &rdu, sizeof(rdu));
28945 + if (unlikely(e)) {
28950 + case AUFS_CTL_RDU_INO:
28951 + err = au_rdu_ino(file, &rdu);
28955 + /* err = -ENOTTY; */
28964 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28965 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28966 +++ linux/fs/aufs/rwsem.h 2021-12-03 15:40:58.236647297 +0100
28968 +/* SPDX-License-Identifier: GPL-2.0 */
28970 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28972 + * This program, aufs is free software; you can redistribute it and/or modify
28973 + * it under the terms of the GNU General Public License as published by
28974 + * the Free Software Foundation; either version 2 of the License, or
28975 + * (at your option) any later version.
28977 + * This program is distributed in the hope that it will be useful,
28978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28980 + * GNU General Public License for more details.
28982 + * You should have received a copy of the GNU General Public License
28983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28987 + * simple read-write semaphore wrappers
28990 +#ifndef __AUFS_RWSEM_H__
28991 +#define __AUFS_RWSEM_H__
28995 +#include "debug.h"
28997 +/* in the future, the name 'au_rwsem' will be totally gone */
28998 +#define au_rwsem rw_semaphore
29000 +/* to debug easier, do not make them inlined functions */
29001 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29003 +#ifdef CONFIG_LOCKDEP
29004 +/* rwsem_is_locked() is unusable */
29005 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29006 + && !lockdep_recursing(current) \
29008 + && !lockdep_is_held_type(rw, 1))
29009 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29010 + && !lockdep_recursing(current) \
29012 + && !lockdep_is_held_type(rw, 0))
29013 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29014 + && !lockdep_recursing(current) \
29016 + && !lockdep_is_held(rw))
29017 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29018 + && !lockdep_recursing(current) \
29020 + && lockdep_is_held(rw))
29022 +#define AuRwMustReadLock(rw) do {} while (0)
29023 +#define AuRwMustWriteLock(rw) do {} while (0)
29024 +#define AuRwMustAnyLock(rw) do {} while (0)
29025 +#define AuRwDestroy(rw) do {} while (0)
29028 +#define au_rw_init(rw) init_rwsem(rw)
29030 +#define au_rw_init_wlock(rw) do { \
29031 + au_rw_init(rw); \
29032 + down_write(rw); \
29035 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29036 + au_rw_init(rw); \
29037 + down_write_nested(rw, lsc); \
29040 +#define au_rw_read_lock(rw) down_read(rw)
29041 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29042 +#define au_rw_read_unlock(rw) up_read(rw)
29043 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29044 +#define au_rw_write_lock(rw) down_write(rw)
29045 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29046 +#define au_rw_write_unlock(rw) up_write(rw)
29047 +/* why is not _nested version defined? */
29048 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29049 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29051 +#endif /* __KERNEL__ */
29052 +#endif /* __AUFS_RWSEM_H__ */
29053 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29054 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29055 +++ linux/fs/aufs/sbinfo.c 2021-12-03 15:38:59.939980643 +0100
29057 +// SPDX-License-Identifier: GPL-2.0
29059 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29061 + * This program, aufs is free software; you can redistribute it and/or modify
29062 + * it under the terms of the GNU General Public License as published by
29063 + * the Free Software Foundation; either version 2 of the License, or
29064 + * (at your option) any later version.
29066 + * This program is distributed in the hope that it will be useful,
29067 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29068 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29069 + * GNU General Public License for more details.
29071 + * You should have received a copy of the GNU General Public License
29072 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29076 + * superblock private data
29079 +#include <linux/iversion.h>
29083 + * they are necessary regardless sysfs is disabled.
29085 +void au_si_free(struct kobject *kobj)
29088 + struct au_sbinfo *sbinfo;
29089 + char *locked __maybe_unused; /* debug only */
29091 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29092 + for (i = 0; i < AuPlink_NHASH; i++)
29093 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29094 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29096 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29097 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29098 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29099 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29101 + dbgaufs_si_fin(sbinfo);
29102 + au_rw_write_lock(&sbinfo->si_rwsem);
29103 + au_br_free(sbinfo);
29104 + au_rw_write_unlock(&sbinfo->si_rwsem);
29106 + au_kfree_try_rcu(sbinfo->si_branch);
29107 + mutex_destroy(&sbinfo->si_xib_mtx);
29108 + AuRwDestroy(&sbinfo->si_rwsem);
29110 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29111 + /* si_nfiles is waited too */
29112 + au_kfree_rcu(sbinfo);
29115 +int au_si_alloc(struct super_block *sb)
29118 + struct au_sbinfo *sbinfo;
29121 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29122 + if (unlikely(!sbinfo))
29125 + /* will be reallocated separately */
29126 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29127 + if (unlikely(!sbinfo->si_branch))
29130 + err = sysaufs_si_init(sbinfo);
29132 + dbgaufs_si_null(sbinfo);
29133 + err = dbgaufs_si_init(sbinfo);
29134 + if (unlikely(err))
29135 + kobject_put(&sbinfo->si_kobj);
29137 + if (unlikely(err))
29140 + au_nwt_init(&sbinfo->si_nowait);
29141 + au_rw_init_wlock(&sbinfo->si_rwsem);
29143 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29144 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29146 + sbinfo->si_bbot = -1;
29147 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29149 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29150 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29151 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29152 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29154 + au_fhsm_init(sbinfo);
29156 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29158 + sbinfo->si_xino_jiffy = jiffies;
29159 + sbinfo->si_xino_expire
29160 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29161 + mutex_init(&sbinfo->si_xib_mtx);
29162 + /* leave si_xib_last_pindex and si_xib_next_bit */
29164 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29166 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29167 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29168 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29169 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29171 + for (i = 0; i < AuPlink_NHASH; i++)
29172 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29173 + init_waitqueue_head(&sbinfo->si_plink_wq);
29174 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29176 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29178 + /* with getattr by default */
29179 + sbinfo->si_iop_array = aufs_iop;
29181 + /* leave other members for sysaufs and si_mnt. */
29182 + sbinfo->si_sb = sb;
29183 + sb->s_fs_info = sbinfo;
29185 + return 0; /* success */
29188 + au_kfree_try_rcu(sbinfo->si_branch);
29190 + au_kfree_rcu(sbinfo);
29195 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29198 + struct au_branch **brp;
29200 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29203 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29204 + if (unlikely(!sz))
29205 + sz = sizeof(*brp);
29206 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29209 + sbinfo->si_branch = brp;
29216 +/* ---------------------------------------------------------------------- */
29218 +unsigned int au_sigen_inc(struct super_block *sb)
29220 + unsigned int gen;
29221 + struct inode *inode;
29223 + SiMustWriteLock(sb);
29225 + gen = ++au_sbi(sb)->si_generation;
29226 + au_update_digen(sb->s_root);
29227 + inode = d_inode(sb->s_root);
29228 + au_update_iigen(inode, /*half*/0);
29229 + inode_inc_iversion(inode);
29233 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29235 + aufs_bindex_t br_id;
29237 + struct au_sbinfo *sbinfo;
29239 + SiMustWriteLock(sb);
29241 + sbinfo = au_sbi(sb);
29242 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29243 + br_id = ++sbinfo->si_last_br_id;
29244 + AuDebugOn(br_id < 0);
29245 + if (br_id && au_br_index(sb, br_id) < 0)
29252 +/* ---------------------------------------------------------------------- */
29254 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29255 +int si_read_lock(struct super_block *sb, int flags)
29260 + if (au_ftest_lock(flags, FLUSH))
29261 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29263 + si_noflush_read_lock(sb);
29264 + err = au_plink_maint(sb, flags);
29265 + if (unlikely(err))
29266 + si_read_unlock(sb);
29271 +int si_write_lock(struct super_block *sb, int flags)
29275 + if (au_ftest_lock(flags, FLUSH))
29276 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29278 + si_noflush_write_lock(sb);
29279 + err = au_plink_maint(sb, flags);
29280 + if (unlikely(err))
29281 + si_write_unlock(sb);
29286 +/* dentry and super_block lock. call at entry point */
29287 +int aufs_read_lock(struct dentry *dentry, int flags)
29290 + struct super_block *sb;
29292 + sb = dentry->d_sb;
29293 + err = si_read_lock(sb, flags);
29294 + if (unlikely(err))
29297 + if (au_ftest_lock(flags, DW))
29298 + di_write_lock_child(dentry);
29300 + di_read_lock_child(dentry, flags);
29302 + if (au_ftest_lock(flags, GEN)) {
29303 + err = au_digen_test(dentry, au_sigen(sb));
29304 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29305 + AuDebugOn(!err && au_dbrange_test(dentry));
29307 + err = au_dbrange_test(dentry);
29308 + if (unlikely(err))
29309 + aufs_read_unlock(dentry, flags);
29316 +void aufs_read_unlock(struct dentry *dentry, int flags)
29318 + if (au_ftest_lock(flags, DW))
29319 + di_write_unlock(dentry);
29321 + di_read_unlock(dentry, flags);
29322 + si_read_unlock(dentry->d_sb);
29325 +void aufs_write_lock(struct dentry *dentry)
29327 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29328 + di_write_lock_child(dentry);
29331 +void aufs_write_unlock(struct dentry *dentry)
29333 + di_write_unlock(dentry);
29334 + si_write_unlock(dentry->d_sb);
29337 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29340 + unsigned int sigen;
29341 + struct super_block *sb;
29344 + err = si_read_lock(sb, flags);
29345 + if (unlikely(err))
29348 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29350 + if (au_ftest_lock(flags, GEN)) {
29351 + sigen = au_sigen(sb);
29352 + err = au_digen_test(d1, sigen);
29353 + AuDebugOn(!err && au_dbrange_test(d1));
29355 + err = au_digen_test(d2, sigen);
29356 + AuDebugOn(!err && au_dbrange_test(d2));
29358 + if (unlikely(err))
29359 + aufs_read_and_write_unlock2(d1, d2);
29366 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29368 + di_write_unlock2(d1, d2);
29369 + si_read_unlock(d1->d_sb);
29371 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29372 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29373 +++ linux/fs/aufs/super.c 2021-12-03 15:40:58.236647297 +0100
29375 +// SPDX-License-Identifier: GPL-2.0
29377 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29379 + * This program, aufs is free software; you can redistribute it and/or modify
29380 + * it under the terms of the GNU General Public License as published by
29381 + * the Free Software Foundation; either version 2 of the License, or
29382 + * (at your option) any later version.
29384 + * This program is distributed in the hope that it will be useful,
29385 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29387 + * GNU General Public License for more details.
29389 + * You should have received a copy of the GNU General Public License
29390 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29394 + * mount and super_block operations
29397 +#include <linux/iversion.h>
29398 +#include <linux/mm.h>
29399 +#include <linux/seq_file.h>
29400 +#include <linux/statfs.h>
29401 +#include <linux/vmalloc.h>
29405 + * super_operations
29407 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29409 + struct au_icntnr *c;
29411 + c = au_cache_alloc_icntnr();
29413 + au_icntnr_init(c);
29414 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29415 + c->iinfo.ii_hinode = NULL;
29416 + return &c->vfs_inode;
29421 +static void aufs_destroy_inode(struct inode *inode)
29423 + if (!au_is_bad_inode(inode))
29424 + au_iinfo_fin(inode);
29427 +static void aufs_free_inode(struct inode *inode)
29429 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29432 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29434 + struct inode *inode;
29437 + inode = iget_locked(sb, ino);
29438 + if (unlikely(!inode)) {
29439 + inode = ERR_PTR(-ENOMEM);
29442 + if (!(inode->i_state & I_NEW))
29445 + err = au_xigen_new(inode);
29447 + err = au_iinfo_init(inode);
29449 + inode_inc_iversion(inode);
29451 + iget_failed(inode);
29452 + inode = ERR_PTR(err);
29456 + /* never return NULL */
29457 + AuDebugOn(!inode);
29458 + AuTraceErrPtr(inode);
29462 +/* lock free root dinfo */
29463 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29466 + aufs_bindex_t bindex, bbot;
29467 + struct path path;
29468 + struct au_hdentry *hdp;
29469 + struct au_branch *br;
29470 + au_br_perm_str_t perm;
29473 + bbot = au_sbbot(sb);
29475 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29476 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29477 + br = au_sbr(sb, bindex);
29478 + path.mnt = au_br_mnt(br);
29479 + path.dentry = hdp->hd_dentry;
29480 + err = au_seq_path(seq, &path);
29482 + au_optstr_br_perm(&perm, br->br_perm);
29483 + seq_printf(seq, "=%s", perm.a);
29484 + if (bindex != bbot)
29485 + seq_putc(seq, ':');
29488 + if (unlikely(err || seq_has_overflowed(seq)))
29494 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29495 + const char *append)
29500 + while (*pat != ':')
29503 + strcpy(p, append);
29504 + AuDebugOn(strlen(fmt) >= len);
29507 +static void au_show_wbr_create(struct seq_file *m, int v,
29508 + struct au_sbinfo *sbinfo)
29512 + struct au_wbr_mfs *mfs;
29514 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29516 + seq_puts(m, ",create=");
29517 + pat = au_optstr_wbr_create(v);
29518 + mfs = &sbinfo->si_wbr_mfs;
29520 + case AuWbrCreate_TDP:
29521 + case AuWbrCreate_RR:
29522 + case AuWbrCreate_MFS:
29523 + case AuWbrCreate_PMFS:
29524 + seq_puts(m, pat);
29526 + case AuWbrCreate_MFSRR:
29527 + case AuWbrCreate_TDMFS:
29528 + case AuWbrCreate_PMFSRR:
29529 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29530 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29532 + case AuWbrCreate_MFSV:
29533 + case AuWbrCreate_PMFSV:
29534 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29535 + seq_printf(m, fmt,
29536 + jiffies_to_msecs(mfs->mfs_expire)
29539 + case AuWbrCreate_MFSRRV:
29540 + case AuWbrCreate_TDMFSV:
29541 + case AuWbrCreate_PMFSRRV:
29542 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29543 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29544 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29551 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29553 +#ifdef CONFIG_SYSFS
29557 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29558 + aufs_bindex_t bindex, brid;
29559 + struct qstr *name;
29561 + struct dentry *d, *h_root;
29562 + struct au_branch *br;
29564 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29567 + f = au_sbi(sb)->si_xib;
29571 + /* stop printing the default xino path on the first writable branch */
29573 + bindex = au_xi_root(sb, f->f_path.dentry);
29574 + if (bindex >= 0) {
29575 + br = au_sbr_sb(sb, bindex);
29576 + h_root = au_br_dentry(br);
29579 + d = f->f_path.dentry;
29580 + name = &d->d_name;
29581 + /* safe ->d_parent because the file is unlinked */
29582 + if (d->d_parent == h_root
29583 + && name->len == len
29584 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29587 + seq_puts(seq, ",xino=");
29588 + err = au_xino_path(seq, f);
29595 +/* seq_file will re-call me in case of too long string */
29596 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29599 + unsigned int mnt_flags, v;
29600 + struct super_block *sb;
29601 + struct au_sbinfo *sbinfo;
29603 +#define AuBool(name, str) do { \
29604 + v = au_opt_test(mnt_flags, name); \
29605 + if (v != au_opt_test(AuOpt_Def, name)) \
29606 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29609 +#define AuStr(name, str) do { \
29610 + v = mnt_flags & AuOptMask_##name; \
29611 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29612 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29615 +#define AuUInt(name, str, val) do { \
29616 + if (val != AUFS_##name##_DEF) \
29617 + seq_printf(m, "," #str "=%u", val); \
29620 + sb = dentry->d_sb;
29621 + if (sb->s_flags & SB_POSIXACL)
29622 + seq_puts(m, ",acl");
29623 +#if 0 /* reserved for future use */
29624 + if (sb->s_flags & SB_I_VERSION)
29625 + seq_puts(m, ",i_version");
29628 + /* lock free root dinfo */
29629 + si_noflush_read_lock(sb);
29630 + sbinfo = au_sbi(sb);
29631 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29633 + mnt_flags = au_mntflags(sb);
29634 + if (au_opt_test(mnt_flags, XINO)) {
29635 + err = au_show_xino(m, sb);
29636 + if (unlikely(err))
29639 + seq_puts(m, ",noxino");
29641 + AuBool(TRUNC_XINO, trunc_xino);
29642 + AuStr(UDBA, udba);
29643 + AuBool(SHWH, shwh);
29644 + AuBool(PLINK, plink);
29645 + AuBool(DIO, dio);
29646 + AuBool(DIRPERM1, dirperm1);
29648 + v = sbinfo->si_wbr_create;
29649 + if (v != AuWbrCreate_Def)
29650 + au_show_wbr_create(m, v, sbinfo);
29652 + v = sbinfo->si_wbr_copyup;
29653 + if (v != AuWbrCopyup_Def)
29654 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29656 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29657 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29658 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29660 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29662 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29663 + AuUInt(RDCACHE, rdcache, v);
29665 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29666 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29668 + au_fhsm_show(m, sbinfo);
29670 + AuBool(DIRREN, dirren);
29671 + AuBool(SUM, sum);
29672 + /* AuBool(SUM_W, wsum); */
29673 + AuBool(WARN_PERM, warn_perm);
29674 + AuBool(VERBOSE, verbose);
29677 + /* be sure to print "br:" last */
29678 + if (!sysaufs_brs) {
29679 + seq_puts(m, ",br:");
29680 + au_show_brs(m, sb);
29682 + si_read_unlock(sb);
29690 +/* ---------------------------------------------------------------------- */
29692 +/* sum mode which returns the summation for statfs(2) */
29694 +static u64 au_add_till_max(u64 a, u64 b)
29702 + return ULLONG_MAX;
29705 +static u64 au_mul_till_max(u64 a, long mul)
29713 + return ULLONG_MAX;
29716 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29719 + long bsize, factor;
29720 + u64 blocks, bfree, bavail, files, ffree;
29721 + aufs_bindex_t bbot, bindex, i;
29722 + unsigned char shared;
29723 + struct path h_path;
29724 + struct super_block *h_sb;
29727 + bsize = LONG_MAX;
29733 + bbot = au_sbbot(sb);
29734 + for (bindex = 0; bindex <= bbot; bindex++) {
29735 + h_path.mnt = au_sbr_mnt(sb, bindex);
29736 + h_sb = h_path.mnt->mnt_sb;
29738 + for (i = 0; !shared && i < bindex; i++)
29739 + shared = (au_sbr_sb(sb, i) == h_sb);
29743 + /* sb->s_root for NFS is unreliable */
29744 + h_path.dentry = h_path.mnt->mnt_root;
29745 + err = vfs_statfs(&h_path, buf);
29746 + if (unlikely(err))
29749 + if (bsize > buf->f_bsize) {
29751 + * we will reduce bsize, so we have to expand blocks
29752 + * etc. to match them again
29754 + factor = (bsize / buf->f_bsize);
29755 + blocks = au_mul_till_max(blocks, factor);
29756 + bfree = au_mul_till_max(bfree, factor);
29757 + bavail = au_mul_till_max(bavail, factor);
29758 + bsize = buf->f_bsize;
29761 + factor = (buf->f_bsize / bsize);
29762 + blocks = au_add_till_max(blocks,
29763 + au_mul_till_max(buf->f_blocks, factor));
29764 + bfree = au_add_till_max(bfree,
29765 + au_mul_till_max(buf->f_bfree, factor));
29766 + bavail = au_add_till_max(bavail,
29767 + au_mul_till_max(buf->f_bavail, factor));
29768 + files = au_add_till_max(files, buf->f_files);
29769 + ffree = au_add_till_max(ffree, buf->f_ffree);
29772 + buf->f_bsize = bsize;
29773 + buf->f_blocks = blocks;
29774 + buf->f_bfree = bfree;
29775 + buf->f_bavail = bavail;
29776 + buf->f_files = files;
29777 + buf->f_ffree = ffree;
29778 + buf->f_frsize = 0;
29784 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29787 + struct path h_path;
29788 + struct super_block *sb;
29790 + /* lock free root dinfo */
29791 + sb = dentry->d_sb;
29792 + si_noflush_read_lock(sb);
29793 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29794 + /* sb->s_root for NFS is unreliable */
29795 + h_path.mnt = au_sbr_mnt(sb, 0);
29796 + h_path.dentry = h_path.mnt->mnt_root;
29797 + err = vfs_statfs(&h_path, buf);
29799 + err = au_statfs_sum(sb, buf);
29800 + si_read_unlock(sb);
29803 + buf->f_type = AUFS_SUPER_MAGIC;
29804 + buf->f_namelen = AUFS_MAX_NAMELEN;
29805 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29807 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29812 +/* ---------------------------------------------------------------------- */
29814 +static int aufs_sync_fs(struct super_block *sb, int wait)
29817 + aufs_bindex_t bbot, bindex;
29818 + struct au_branch *br;
29819 + struct super_block *h_sb;
29822 + si_noflush_read_lock(sb);
29823 + bbot = au_sbbot(sb);
29824 + for (bindex = 0; bindex <= bbot; bindex++) {
29825 + br = au_sbr(sb, bindex);
29826 + if (!au_br_writable(br->br_perm))
29829 + h_sb = au_sbr_sb(sb, bindex);
29830 + e = vfsub_sync_filesystem(h_sb, wait);
29831 + if (unlikely(e && !err))
29833 + /* go on even if an error happens */
29835 + si_read_unlock(sb);
29840 +/* ---------------------------------------------------------------------- */
29842 +/* final actions when unmounting a file system */
29843 +static void aufs_put_super(struct super_block *sb)
29845 + struct au_sbinfo *sbinfo;
29847 + sbinfo = au_sbi(sb);
29849 + kobject_put(&sbinfo->si_kobj);
29852 +/* ---------------------------------------------------------------------- */
29854 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29855 + struct super_block *sb, void *arg)
29858 + unsigned long long n, sz;
29865 + if (*hint > ULLONG_MAX / sizeof(array)) {
29866 + array = ERR_PTR(-EMFILE);
29867 + pr_err("hint %llu\n", *hint);
29871 + sz = sizeof(array) * *hint;
29872 + array = kzalloc(sz, GFP_NOFS);
29873 + if (unlikely(!array))
29874 + array = vzalloc(sz);
29875 + if (unlikely(!array)) {
29876 + array = ERR_PTR(-ENOMEM);
29880 + n = cb(sb, array, *hint, arg);
29881 + AuDebugOn(n > *hint);
29888 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29889 + unsigned long long max __maybe_unused,
29892 + unsigned long long n;
29893 + struct inode **p, *inode;
29894 + struct list_head *head;
29899 + spin_lock(&sb->s_inode_list_lock);
29900 + list_for_each_entry(inode, head, i_sb_list) {
29901 + if (!au_is_bad_inode(inode)
29902 + && au_ii(inode)->ii_btop >= 0) {
29903 + spin_lock(&inode->i_lock);
29904 + if (atomic_read(&inode->i_count)) {
29908 + AuDebugOn(n > max);
29910 + spin_unlock(&inode->i_lock);
29913 + spin_unlock(&sb->s_inode_list_lock);
29918 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29920 + struct au_sbinfo *sbi;
29922 + sbi = au_sbi(sb);
29923 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29924 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29927 +void au_iarray_free(struct inode **a, unsigned long long max)
29929 + unsigned long long ull;
29931 + for (ull = 0; ull < max; ull++)
29936 +/* ---------------------------------------------------------------------- */
29939 + * refresh dentry and inode at remount time.
29941 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29942 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29943 + struct dentry *parent)
29947 + di_write_lock_child(dentry);
29948 + di_read_lock_parent(parent, AuLock_IR);
29949 + err = au_refresh_dentry(dentry, parent);
29950 + if (!err && dir_flags)
29951 + au_hn_reset(d_inode(dentry), dir_flags);
29952 + di_read_unlock(parent, AuLock_IR);
29953 + di_write_unlock(dentry);
29958 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29959 + struct au_sbinfo *sbinfo,
29960 + const unsigned int dir_flags, unsigned int do_idop)
29963 + struct dentry *parent;
29966 + parent = dget_parent(dentry);
29967 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29968 + if (d_really_is_positive(dentry)) {
29969 + if (!d_is_dir(dentry))
29970 + err = au_do_refresh(dentry, /*dir_flags*/0,
29973 + err = au_do_refresh(dentry, dir_flags, parent);
29974 + if (unlikely(err))
29975 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29978 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29979 + AuDbgDentry(dentry);
29985 + au_refresh_dop(dentry, /*force_reval*/0);
29987 + au_refresh_dop(dentry, /*force_reval*/1);
29993 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29995 + int err, i, j, ndentry, e;
29996 + unsigned int sigen;
29997 + struct au_dcsub_pages dpages;
29998 + struct au_dpage *dpage;
29999 + struct dentry **dentries, *d;
30000 + struct au_sbinfo *sbinfo;
30001 + struct dentry *root = sb->s_root;
30002 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30005 + au_refresh_dop(root, /*force_reval*/0);
30007 + err = au_dpages_init(&dpages, GFP_NOFS);
30008 + if (unlikely(err))
30010 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30011 + if (unlikely(err))
30014 + sigen = au_sigen(sb);
30015 + sbinfo = au_sbi(sb);
30016 + for (i = 0; i < dpages.ndpage; i++) {
30017 + dpage = dpages.dpages + i;
30018 + dentries = dpage->dentries;
30019 + ndentry = dpage->ndentry;
30020 + for (j = 0; j < ndentry; j++) {
30022 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30024 + if (unlikely(e && !err))
30026 + /* go on even err */
30031 + au_dpages_free(&dpages);
30036 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30039 + unsigned int sigen;
30040 + unsigned long long max, ull;
30041 + struct inode *inode, **array;
30043 + array = au_iarray_alloc(sb, &max);
30044 + err = PTR_ERR(array);
30045 + if (IS_ERR(array))
30049 + sigen = au_sigen(sb);
30050 + for (ull = 0; ull < max; ull++) {
30051 + inode = array[ull];
30052 + if (unlikely(!inode))
30056 + ii_write_lock_child(inode);
30057 + if (au_iigen(inode, NULL) != sigen) {
30058 + e = au_refresh_hinode_self(inode);
30059 + if (unlikely(e)) {
30060 + au_refresh_iop(inode, /*force_getattr*/1);
30061 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30064 + /* go on even if err */
30067 + if (!e && do_idop)
30068 + au_refresh_iop(inode, /*force_getattr*/0);
30069 + ii_write_unlock(inode);
30072 + au_iarray_free(array, max);
30078 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30081 + unsigned int udba;
30082 + aufs_bindex_t bindex, bbot;
30083 + struct dentry *root;
30084 + struct inode *inode;
30085 + struct au_branch *br;
30086 + struct au_sbinfo *sbi;
30088 + au_sigen_inc(sb);
30089 + sbi = au_sbi(sb);
30090 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30092 + root = sb->s_root;
30093 + DiMustNoWaiters(root);
30094 + inode = d_inode(root);
30095 + IiMustNoWaiters(inode);
30097 + udba = au_opt_udba(sb);
30098 + bbot = au_sbbot(sb);
30099 + for (bindex = 0; bindex <= bbot; bindex++) {
30100 + br = au_sbr(sb, bindex);
30101 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30102 + if (unlikely(err))
30103 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30105 + /* go on even if err */
30107 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30110 + if (au_ftest_si(sbi, NO_DREVAL)) {
30111 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30112 + sb->s_d_op = &aufs_dop_noreval;
30113 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30114 + sbi->si_iop_array = aufs_iop_nogetattr;
30116 + AuDebugOn(sb->s_d_op == &aufs_dop);
30117 + sb->s_d_op = &aufs_dop;
30118 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30119 + sbi->si_iop_array = aufs_iop;
30121 + pr_info("reset to %ps and %ps\n",
30122 + sb->s_d_op, sbi->si_iop_array);
30125 + di_write_unlock(root);
30126 + err = au_refresh_d(sb, do_idop);
30127 + e = au_refresh_i(sb, do_idop);
30128 + if (unlikely(e && !err))
30130 + /* aufs_write_lock() calls ..._child() */
30131 + di_write_lock_child(root);
30133 + au_cpup_attr_all(inode, /*force*/1);
30135 + if (unlikely(err))
30136 + AuIOErr("refresh failed, ignored, %d\n", err);
30139 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30140 +static int cvt_err(int err)
30154 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30157 + unsigned int mntflags;
30158 + struct au_opts opts = {
30161 + struct dentry *root;
30162 + struct inode *inode;
30163 + struct au_sbinfo *sbinfo;
30166 + root = sb->s_root;
30167 + if (!data || !*data) {
30168 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30170 + di_write_lock_child(root);
30171 + err = au_opts_verify(sb, *flags, /*pending*/0);
30172 + aufs_write_unlock(root);
30178 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30179 + if (unlikely(!opts.opt))
30181 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30182 + opts.flags = AuOpts_REMOUNT;
30183 + opts.sb_flags = *flags;
30185 + /* parse it before aufs lock */
30186 + err = au_opts_parse(sb, data, &opts);
30187 + if (unlikely(err))
30190 + sbinfo = au_sbi(sb);
30191 + inode = d_inode(root);
30192 + inode_lock(inode);
30193 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30194 + if (unlikely(err))
30196 + di_write_lock_child(root);
30198 + /* au_opts_remount() may return an error */
30199 + err = au_opts_remount(sb, &opts);
30200 + au_opts_free(&opts);
30202 + if (au_ftest_opts(opts.flags, REFRESH))
30203 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30205 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30206 + mntflags = au_mntflags(sb);
30207 + do_dx = !!au_opt_test(mntflags, DIO);
30208 + au_dy_arefresh(do_dx);
30211 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30212 + aufs_write_unlock(root);
30215 + inode_unlock(inode);
30217 + free_page((unsigned long)opts.opt);
30219 + err = cvt_err(err);
30224 +static const struct super_operations aufs_sop = {
30225 + .alloc_inode = aufs_alloc_inode,
30226 + .destroy_inode = aufs_destroy_inode,
30227 + .free_inode = aufs_free_inode,
30228 + /* always deleting, no clearing */
30229 + .drop_inode = generic_delete_inode,
30230 + .show_options = aufs_show_options,
30231 + .statfs = aufs_statfs,
30232 + .put_super = aufs_put_super,
30233 + .sync_fs = aufs_sync_fs,
30234 + .remount_fs = aufs_remount_fs
30237 +/* ---------------------------------------------------------------------- */
30239 +static int alloc_root(struct super_block *sb)
30242 + struct inode *inode;
30243 + struct dentry *root;
30246 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30247 + err = PTR_ERR(inode);
30248 + if (IS_ERR(inode))
30251 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30252 + inode->i_fop = &aufs_dir_fop;
30253 + inode->i_mode = S_IFDIR;
30254 + set_nlink(inode, 2);
30255 + unlock_new_inode(inode);
30257 + root = d_make_root(inode);
30258 + if (unlikely(!root))
30260 + err = PTR_ERR(root);
30261 + if (IS_ERR(root))
30264 + err = au_di_init(root);
30266 + sb->s_root = root;
30267 + return 0; /* success */
30275 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30276 + int silent __maybe_unused)
30279 + struct au_opts opts = {
30282 + struct au_sbinfo *sbinfo;
30283 + struct dentry *root;
30284 + struct inode *inode;
30285 + char *arg = raw_data;
30287 + if (unlikely(!arg || !*arg)) {
30289 + pr_err("no arg\n");
30294 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30295 + if (unlikely(!opts.opt))
30297 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30298 + opts.sb_flags = sb->s_flags;
30300 + err = au_si_alloc(sb);
30301 + if (unlikely(err))
30303 + sbinfo = au_sbi(sb);
30305 + /* all timestamps always follow the ones on the branch */
30306 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30307 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30308 + sb->s_op = &aufs_sop;
30309 + sb->s_d_op = &aufs_dop;
30310 + sb->s_magic = AUFS_SUPER_MAGIC;
30311 + sb->s_maxbytes = 0;
30312 + sb->s_stack_depth = 1;
30313 + au_export_init(sb);
30314 + au_xattr_init(sb);
30316 + err = alloc_root(sb);
30317 + if (unlikely(err)) {
30318 + si_write_unlock(sb);
30321 + root = sb->s_root;
30322 + inode = d_inode(root);
30325 + * actually we can parse options regardless aufs lock here.
30326 + * but at remount time, parsing must be done before aufs lock.
30327 + * so we follow the same rule.
30329 + ii_write_lock_parent(inode);
30330 + aufs_write_unlock(root);
30331 + err = au_opts_parse(sb, arg, &opts);
30332 + if (unlikely(err))
30335 + /* lock vfs_inode first, then aufs. */
30336 + inode_lock(inode);
30337 + aufs_write_lock(root);
30338 + err = au_opts_mount(sb, &opts);
30339 + au_opts_free(&opts);
30340 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30341 + sb->s_d_op = &aufs_dop_noreval;
30342 + pr_info("%ps\n", sb->s_d_op);
30343 + au_refresh_dop(root, /*force_reval*/0);
30344 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30345 + au_refresh_iop(inode, /*force_getattr*/0);
30347 + aufs_write_unlock(root);
30348 + inode_unlock(inode);
30350 + goto out_opts; /* success */
30354 + sb->s_root = NULL;
30356 + kobject_put(&sbinfo->si_kobj);
30357 + sb->s_fs_info = NULL;
30359 + free_page((unsigned long)opts.opt);
30362 + err = cvt_err(err);
30367 +/* ---------------------------------------------------------------------- */
30369 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30370 + const char *dev_name __maybe_unused,
30373 + struct dentry *root;
30375 + /* all timestamps always follow the ones on the branch */
30376 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30377 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30378 + if (IS_ERR(root))
30381 + au_sbilist_add(root->d_sb);
30387 +static void aufs_kill_sb(struct super_block *sb)
30389 + struct au_sbinfo *sbinfo;
30391 + sbinfo = au_sbi(sb);
30393 + au_sbilist_del(sb);
30394 + aufs_write_lock(sb->s_root);
30396 + if (sbinfo->si_wbr_create_ops->fin)
30397 + sbinfo->si_wbr_create_ops->fin(sb);
30398 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30399 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30400 + au_remount_refresh(sb, /*do_idop*/0);
30402 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30403 + au_plink_put(sb, /*verbose*/1);
30405 + au_dr_opt_flush(sb);
30406 + sbinfo->si_sb = NULL;
30407 + aufs_write_unlock(sb->s_root);
30408 + au_nwt_flush(&sbinfo->si_nowait);
30410 + kill_anon_super(sb);
30413 +struct file_system_type aufs_fs_type = {
30414 + .name = AUFS_FSTYPE,
30415 + /* a race between rename and others */
30416 + .fs_flags = FS_RENAME_DOES_D_MOVE
30418 + /*| FS_ALLOW_IDMAP*/
30420 + .mount = aufs_mount,
30421 + .kill_sb = aufs_kill_sb,
30422 + /* no need to __module_get() and module_put(). */
30423 + .owner = THIS_MODULE,
30425 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30426 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30427 +++ linux/fs/aufs/super.h 2021-12-03 15:38:59.939980643 +0100
30429 +/* SPDX-License-Identifier: GPL-2.0 */
30431 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30433 + * This program, aufs is free software; you can redistribute it and/or modify
30434 + * it under the terms of the GNU General Public License as published by
30435 + * the Free Software Foundation; either version 2 of the License, or
30436 + * (at your option) any later version.
30438 + * This program is distributed in the hope that it will be useful,
30439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30441 + * GNU General Public License for more details.
30443 + * You should have received a copy of the GNU General Public License
30444 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30448 + * super_block operations
30451 +#ifndef __AUFS_SUPER_H__
30452 +#define __AUFS_SUPER_H__
30456 +#include <linux/fs.h>
30457 +#include <linux/kobject.h>
30460 +#include "rwsem.h"
30463 +/* policies to select one among multiple writable branches */
30464 +struct au_wbr_copyup_operations {
30465 + int (*copyup)(struct dentry *dentry);
30468 +#define AuWbr_DIR 1 /* target is a dir */
30469 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30471 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30472 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30473 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30475 +struct au_wbr_create_operations {
30476 + int (*create)(struct dentry *dentry, unsigned int flags);
30477 + int (*init)(struct super_block *sb);
30478 + int (*fin)(struct super_block *sb);
30481 +struct au_wbr_mfs {
30482 + struct mutex mfs_lock; /* protect this structure */
30483 + unsigned long mfs_jiffy;
30484 + unsigned long mfs_expire;
30485 + aufs_bindex_t mfs_bindex;
30487 + unsigned long long mfsrr_bytes;
30488 + unsigned long long mfsrr_watermark;
30491 +#define AuPlink_NHASH 100
30492 +static inline int au_plink_hash(ino_t ino)
30494 + return ino % AuPlink_NHASH;
30497 +/* File-based Hierarchical Storage Management */
30499 +#ifdef CONFIG_AUFS_FHSM
30500 + /* allow only one process who can receive the notification */
30501 + spinlock_t fhsm_spin;
30503 + wait_queue_head_t fhsm_wqh;
30504 + atomic_t fhsm_readable;
30506 + /* these are protected by si_rwsem */
30507 + unsigned long fhsm_expire;
30508 + aufs_bindex_t fhsm_bottom;
30513 +struct au_sbinfo {
30514 + /* nowait tasks in the system-wide workqueue */
30515 + struct au_nowait_tasks si_nowait;
30518 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30519 + * rwsem for au_sbinfo is necessary.
30521 + struct au_rwsem si_rwsem;
30524 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30527 + au_lcnt_t si_ninodes, si_nfiles;
30529 + /* branch management */
30530 + unsigned int si_generation;
30532 + /* see AuSi_ flags */
30533 + unsigned char au_si_status;
30535 + aufs_bindex_t si_bbot;
30537 + /* dirty trick to keep br_id plus */
30538 + unsigned int si_last_br_id :
30539 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30540 + struct au_branch **si_branch;
30542 + /* policy to select a writable branch */
30543 + unsigned char si_wbr_copyup;
30544 + unsigned char si_wbr_create;
30545 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30546 + struct au_wbr_create_operations *si_wbr_create_ops;
30548 + /* round robin */
30549 + atomic_t si_wbr_rr_next;
30551 + /* most free space */
30552 + struct au_wbr_mfs si_wbr_mfs;
30554 + /* File-based Hierarchical Storage Management */
30555 + struct au_fhsm si_fhsm;
30557 + /* mount flags */
30558 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30559 + unsigned int si_mntflags;
30561 + /* external inode number (bitmap and translation table) */
30562 + loff_t si_ximaxent; /* max entries in a xino */
30564 + struct file *si_xib;
30565 + struct mutex si_xib_mtx; /* protect xib members */
30566 + unsigned long *si_xib_buf;
30567 + unsigned long si_xib_last_pindex;
30568 + int si_xib_next_bit;
30570 + unsigned long si_xino_jiffy;
30571 + unsigned long si_xino_expire;
30572 + /* reserved for future use */
30573 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30575 +#ifdef CONFIG_AUFS_EXPORT
30576 + /* i_generation */
30577 + /* todo: make xigen file an array to support many inode numbers */
30578 + struct file *si_xigen;
30579 + atomic_t si_xigen_next;
30582 + /* dirty trick to support atomic_open */
30583 + struct hlist_bl_head si_aopen;
30585 + /* vdir parameters */
30586 + unsigned long si_rdcache; /* max cache time in jiffies */
30587 + unsigned int si_rdblk; /* deblk size */
30588 + unsigned int si_rdhash; /* hash size */
30591 + * If the number of whiteouts are larger than si_dirwh, leave all of
30592 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30593 + * future fsck.aufs or kernel thread will remove them later.
30594 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30596 + unsigned int si_dirwh;
30598 + /* pseudo_link list */
30599 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30600 + wait_queue_head_t si_plink_wq;
30601 + spinlock_t si_plink_maint_lock;
30602 + pid_t si_plink_maint_pid;
30605 + struct hlist_bl_head si_files;
30607 + /* with/without getattr, brother of sb->s_d_op */
30608 + const struct inode_operations *si_iop_array;
30611 + * sysfs and lifetime management.
30612 + * this is not a small structure and it may be a waste of memory in case
30613 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30614 + * but using sysfs is majority.
30616 + struct kobject si_kobj;
30617 +#ifdef CONFIG_DEBUG_FS
30618 + struct dentry *si_dbgaufs;
30619 + struct dentry *si_dbgaufs_plink;
30620 + struct dentry *si_dbgaufs_xib;
30621 +#ifdef CONFIG_AUFS_EXPORT
30622 + struct dentry *si_dbgaufs_xigen;
30626 +#ifdef CONFIG_AUFS_SBILIST
30627 + struct hlist_bl_node si_list;
30630 + /* dirty, necessary for unmounting, sysfs and sysrq */
30631 + struct super_block *si_sb;
30634 +/* sbinfo status flags */
30636 + * set true when refresh_dirs() failed at remount time.
30637 + * then try refreshing dirs at access time again.
30638 + * if it is false, refreshing dirs at access time is unnecessary
30640 +#define AuSi_FAILED_REFRESH_DIR 1
30641 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30642 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30644 +#ifndef CONFIG_AUFS_FHSM
30646 +#define AuSi_FHSM 0
30649 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30650 + unsigned int flag)
30652 + AuRwMustAnyLock(&sbi->si_rwsem);
30653 + return sbi->au_si_status & flag;
30655 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30656 +#define au_fset_si(sbinfo, name) do { \
30657 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30658 + (sbinfo)->au_si_status |= AuSi_##name; \
30660 +#define au_fclr_si(sbinfo, name) do { \
30661 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30662 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30665 +/* ---------------------------------------------------------------------- */
30667 +/* policy to select one among writable branches */
30668 +#define AuWbrCopyup(sbinfo, ...) \
30669 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30670 +#define AuWbrCreate(sbinfo, ...) \
30671 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30673 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30674 +#define AuLock_DW 1 /* write-lock dentry */
30675 +#define AuLock_IR (1 << 1) /* read-lock inode */
30676 +#define AuLock_IW (1 << 2) /* write-lock inode */
30677 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30678 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30679 + /* except RENAME_EXCHANGE */
30680 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30681 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30682 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30683 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30684 +#define au_fset_lock(flags, name) \
30685 + do { (flags) |= AuLock_##name; } while (0)
30686 +#define au_fclr_lock(flags, name) \
30687 + do { (flags) &= ~AuLock_##name; } while (0)
30689 +/* ---------------------------------------------------------------------- */
30692 +extern struct file_system_type aufs_fs_type;
30693 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30694 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30695 + unsigned long long max, void *arg);
30696 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30697 + struct super_block *sb, void *arg);
30698 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30699 +void au_iarray_free(struct inode **a, unsigned long long max);
30702 +void au_si_free(struct kobject *kobj);
30703 +int au_si_alloc(struct super_block *sb);
30704 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30706 +unsigned int au_sigen_inc(struct super_block *sb);
30707 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30709 +int si_read_lock(struct super_block *sb, int flags);
30710 +int si_write_lock(struct super_block *sb, int flags);
30711 +int aufs_read_lock(struct dentry *dentry, int flags);
30712 +void aufs_read_unlock(struct dentry *dentry, int flags);
30713 +void aufs_write_lock(struct dentry *dentry);
30714 +void aufs_write_unlock(struct dentry *dentry);
30715 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30716 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30718 +/* wbr_policy.c */
30719 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30720 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30721 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30722 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30723 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30726 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30728 +#ifdef CONFIG_AUFS_FHSM
30731 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30735 + spin_lock(&fhsm->fhsm_spin);
30736 + pid = fhsm->fhsm_pid;
30737 + spin_unlock(&fhsm->fhsm_spin);
30742 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30743 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30744 +int au_fhsm_fd(struct super_block *sb, int oflags);
30745 +int au_fhsm_br_alloc(struct au_branch *br);
30746 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30747 +void au_fhsm_fin(struct super_block *sb);
30748 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30749 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30750 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30752 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30754 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30755 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30756 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30757 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30758 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30759 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30760 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30761 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30762 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30765 +/* ---------------------------------------------------------------------- */
30767 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30769 + return sb->s_fs_info;
30772 +/* ---------------------------------------------------------------------- */
30774 +#ifdef CONFIG_AUFS_EXPORT
30775 +int au_test_nfsd(void);
30776 +void au_export_init(struct super_block *sb);
30777 +void au_xigen_inc(struct inode *inode);
30778 +int au_xigen_new(struct inode *inode);
30779 +int au_xigen_set(struct super_block *sb, struct path *path);
30780 +void au_xigen_clr(struct super_block *sb);
30782 +static inline int au_busy_or_stale(void)
30784 + if (!au_test_nfsd())
30789 +AuStubInt0(au_test_nfsd, void)
30790 +AuStubVoid(au_export_init, struct super_block *sb)
30791 +AuStubVoid(au_xigen_inc, struct inode *inode)
30792 +AuStubInt0(au_xigen_new, struct inode *inode)
30793 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30794 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30795 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30796 +#endif /* CONFIG_AUFS_EXPORT */
30798 +/* ---------------------------------------------------------------------- */
30800 +#ifdef CONFIG_AUFS_SBILIST
30802 +extern struct hlist_bl_head au_sbilist;
30804 +static inline void au_sbilist_init(void)
30806 + INIT_HLIST_BL_HEAD(&au_sbilist);
30809 +static inline void au_sbilist_add(struct super_block *sb)
30811 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30814 +static inline void au_sbilist_del(struct super_block *sb)
30816 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30819 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30820 +static inline void au_sbilist_lock(void)
30822 + hlist_bl_lock(&au_sbilist);
30825 +static inline void au_sbilist_unlock(void)
30827 + hlist_bl_unlock(&au_sbilist);
30829 +#define AuGFP_SBILIST GFP_ATOMIC
30831 +AuStubVoid(au_sbilist_lock, void)
30832 +AuStubVoid(au_sbilist_unlock, void)
30833 +#define AuGFP_SBILIST GFP_NOFS
30834 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30836 +AuStubVoid(au_sbilist_init, void)
30837 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30838 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30839 +AuStubVoid(au_sbilist_lock, void)
30840 +AuStubVoid(au_sbilist_unlock, void)
30841 +#define AuGFP_SBILIST GFP_NOFS
30844 +/* ---------------------------------------------------------------------- */
30846 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30849 + * This function is a dynamic '__init' function actually,
30850 + * so the tiny check for si_rwsem is unnecessary.
30852 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30853 +#ifdef CONFIG_DEBUG_FS
30854 + sbinfo->si_dbgaufs = NULL;
30855 + sbinfo->si_dbgaufs_plink = NULL;
30856 + sbinfo->si_dbgaufs_xib = NULL;
30857 +#ifdef CONFIG_AUFS_EXPORT
30858 + sbinfo->si_dbgaufs_xigen = NULL;
30863 +/* ---------------------------------------------------------------------- */
30865 +/* current->atomic_flags */
30866 +/* this value should never corrupt the ones defined in linux/sched.h */
30867 +#define PFA_AUFS 0x10
30869 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30870 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30871 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30873 +static inline int si_pid_test(struct super_block *sb)
30875 + return !!task_test_aufs(current);
30878 +static inline void si_pid_clr(struct super_block *sb)
30880 + AuDebugOn(!task_test_aufs(current));
30881 + task_clear_aufs(current);
30884 +static inline void si_pid_set(struct super_block *sb)
30886 + AuDebugOn(task_test_aufs(current));
30887 + task_set_aufs(current);
30890 +/* ---------------------------------------------------------------------- */
30892 +/* lock superblock. mainly for entry point functions */
30893 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30894 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30895 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30896 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30898 +#define __si_read_trylock_nested(sb) \
30899 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30900 +#define __si_write_trylock_nested(sb) \
30901 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30904 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30905 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30906 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30908 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30909 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30910 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30912 +static inline void si_noflush_read_lock(struct super_block *sb)
30914 + __si_read_lock(sb);
30918 +static inline int si_noflush_read_trylock(struct super_block *sb)
30922 + locked = __si_read_trylock(sb);
30928 +static inline void si_noflush_write_lock(struct super_block *sb)
30930 + __si_write_lock(sb);
30934 +static inline int si_noflush_write_trylock(struct super_block *sb)
30938 + locked = __si_write_trylock(sb);
30944 +#if 0 /* reserved */
30945 +static inline int si_read_trylock(struct super_block *sb, int flags)
30947 + if (au_ftest_lock(flags, FLUSH))
30948 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30949 + return si_noflush_read_trylock(sb);
30953 +static inline void si_read_unlock(struct super_block *sb)
30956 + __si_read_unlock(sb);
30959 +#if 0 /* reserved */
30960 +static inline int si_write_trylock(struct super_block *sb, int flags)
30962 + if (au_ftest_lock(flags, FLUSH))
30963 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30964 + return si_noflush_write_trylock(sb);
30968 +static inline void si_write_unlock(struct super_block *sb)
30971 + __si_write_unlock(sb);
30974 +#if 0 /* reserved */
30975 +static inline void si_downgrade_lock(struct super_block *sb)
30977 + __si_downgrade_lock(sb);
30981 +/* ---------------------------------------------------------------------- */
30983 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30985 + SiMustAnyLock(sb);
30986 + return au_sbi(sb)->si_bbot;
30989 +static inline unsigned int au_mntflags(struct super_block *sb)
30991 + SiMustAnyLock(sb);
30992 + return au_sbi(sb)->si_mntflags;
30995 +static inline unsigned int au_sigen(struct super_block *sb)
30997 + SiMustAnyLock(sb);
30998 + return au_sbi(sb)->si_generation;
31001 +static inline struct au_branch *au_sbr(struct super_block *sb,
31002 + aufs_bindex_t bindex)
31004 + SiMustAnyLock(sb);
31005 + return au_sbi(sb)->si_branch[0 + bindex];
31008 +static inline loff_t au_xi_maxent(struct super_block *sb)
31010 + SiMustAnyLock(sb);
31011 + return au_sbi(sb)->si_ximaxent;
31014 +#endif /* __KERNEL__ */
31015 +#endif /* __AUFS_SUPER_H__ */
31016 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31017 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31018 +++ linux/fs/aufs/sysaufs.c 2021-12-03 15:38:59.939980643 +0100
31020 +// SPDX-License-Identifier: GPL-2.0
31022 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31024 + * This program, aufs is free software; you can redistribute it and/or modify
31025 + * it under the terms of the GNU General Public License as published by
31026 + * the Free Software Foundation; either version 2 of the License, or
31027 + * (at your option) any later version.
31029 + * This program is distributed in the hope that it will be useful,
31030 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31031 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31032 + * GNU General Public License for more details.
31034 + * You should have received a copy of the GNU General Public License
31035 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31039 + * sysfs interface and lifetime management
31040 + * they are necessary regardless sysfs is disabled.
31043 +#include <linux/random.h>
31046 +unsigned long sysaufs_si_mask;
31047 +struct kset *sysaufs_kset;
31049 +#define AuSiAttr(_name) { \
31050 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31051 + .show = sysaufs_si_##_name, \
31054 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31055 +struct attribute *sysaufs_si_attrs[] = {
31056 + &sysaufs_si_attr_xi_path.attr,
31060 +static const struct sysfs_ops au_sbi_ops = {
31061 + .show = sysaufs_si_show
31064 +static struct kobj_type au_sbi_ktype = {
31065 + .release = au_si_free,
31066 + .sysfs_ops = &au_sbi_ops,
31067 + .default_attrs = sysaufs_si_attrs
31070 +/* ---------------------------------------------------------------------- */
31072 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31076 + sbinfo->si_kobj.kset = sysaufs_kset;
31077 + /* cf. sysaufs_name() */
31078 + err = kobject_init_and_add
31079 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31080 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31085 +void sysaufs_fin(void)
31087 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31088 + kset_unregister(sysaufs_kset);
31091 +int __init sysaufs_init(void)
31096 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31097 + } while (!sysaufs_si_mask);
31100 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31101 + if (unlikely(!sysaufs_kset))
31103 + err = PTR_ERR(sysaufs_kset);
31104 + if (IS_ERR(sysaufs_kset))
31106 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31107 + if (unlikely(err))
31108 + kset_unregister(sysaufs_kset);
31113 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31114 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31115 +++ linux/fs/aufs/sysaufs.h 2021-12-03 15:38:59.939980643 +0100
31117 +/* SPDX-License-Identifier: GPL-2.0 */
31119 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31121 + * This program, aufs is free software; you can redistribute it and/or modify
31122 + * it under the terms of the GNU General Public License as published by
31123 + * the Free Software Foundation; either version 2 of the License, or
31124 + * (at your option) any later version.
31126 + * This program is distributed in the hope that it will be useful,
31127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31129 + * GNU General Public License for more details.
31131 + * You should have received a copy of the GNU General Public License
31132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31136 + * sysfs interface and mount lifetime management
31139 +#ifndef __SYSAUFS_H__
31140 +#define __SYSAUFS_H__
31144 +#include <linux/sysfs.h>
31145 +#include "module.h"
31147 +struct super_block;
31150 +struct sysaufs_si_attr {
31151 + struct attribute attr;
31152 + int (*show)(struct seq_file *seq, struct super_block *sb);
31155 +/* ---------------------------------------------------------------------- */
31158 +extern unsigned long sysaufs_si_mask;
31159 +extern struct kset *sysaufs_kset;
31160 +extern struct attribute *sysaufs_si_attrs[];
31161 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31162 +int __init sysaufs_init(void);
31163 +void sysaufs_fin(void);
31165 +/* ---------------------------------------------------------------------- */
31167 +/* some people doesn't like to show a pointer in kernel */
31168 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31170 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31173 +#define SysaufsSiNamePrefix "si_"
31174 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31175 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31177 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31178 + sysaufs_si_id(sbinfo));
31182 +#ifdef CONFIG_SYSFS
31184 +extern struct attribute_group *sysaufs_attr_group;
31186 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31187 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31189 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31190 +#ifdef CONFIG_COMPAT
31191 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31194 +void sysaufs_br_init(struct au_branch *br);
31195 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31196 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31198 +#define sysaufs_brs_init() do {} while (0)
31201 +#define sysaufs_attr_group NULL
31203 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31204 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31205 + struct attribute *attr, char *buf)
31206 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31207 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31208 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31210 +static inline void sysaufs_brs_init(void)
31215 +#endif /* CONFIG_SYSFS */
31217 +#endif /* __KERNEL__ */
31218 +#endif /* __SYSAUFS_H__ */
31219 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31220 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31221 +++ linux/fs/aufs/sysfs.c 2021-12-03 15:38:59.939980643 +0100
31223 +// SPDX-License-Identifier: GPL-2.0
31225 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31227 + * This program, aufs is free software; you can redistribute it and/or modify
31228 + * it under the terms of the GNU General Public License as published by
31229 + * the Free Software Foundation; either version 2 of the License, or
31230 + * (at your option) any later version.
31232 + * This program is distributed in the hope that it will be useful,
31233 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31234 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31235 + * GNU General Public License for more details.
31237 + * You should have received a copy of the GNU General Public License
31238 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31242 + * sysfs interface
31245 +#include <linux/compat.h>
31246 +#include <linux/seq_file.h>
31249 +#ifdef CONFIG_AUFS_FS_MODULE
31250 +/* this entry violates the "one line per file" policy of sysfs */
31251 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31255 + static char *conf =
31256 +/* this file is generated at compiling */
31257 +#include "conf.str"
31260 + err = snprintf(buf, PAGE_SIZE, conf);
31261 + if (unlikely(err >= PAGE_SIZE))
31266 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31269 +static struct attribute *au_attr[] = {
31270 +#ifdef CONFIG_AUFS_FS_MODULE
31271 + &au_config_attr.attr,
31273 + NULL, /* need to NULL terminate the list of attributes */
31276 +static struct attribute_group sysaufs_attr_group_body = {
31280 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31282 +/* ---------------------------------------------------------------------- */
31284 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31288 + SiMustAnyLock(sb);
31291 + if (au_opt_test(au_mntflags(sb), XINO)) {
31292 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31293 + seq_putc(seq, '\n');
31299 + * the lifetime of branch is independent from the entry under sysfs.
31300 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31303 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31304 + aufs_bindex_t bindex, int idx)
31307 + struct path path;
31308 + struct dentry *root;
31309 + struct au_branch *br;
31310 + au_br_perm_str_t perm;
31312 + AuDbg("b%d\n", bindex);
31315 + root = sb->s_root;
31316 + di_read_lock_parent(root, !AuLock_IR);
31317 + br = au_sbr(sb, bindex);
31320 + case AuBrSysfs_BR:
31321 + path.mnt = au_br_mnt(br);
31322 + path.dentry = au_h_dptr(root, bindex);
31323 + err = au_seq_path(seq, &path);
31325 + au_optstr_br_perm(&perm, br->br_perm);
31326 + seq_printf(seq, "=%s\n", perm.a);
31329 + case AuBrSysfs_BRID:
31330 + seq_printf(seq, "%d\n", br->br_id);
31333 + di_read_unlock(root, !AuLock_IR);
31334 + if (unlikely(err || seq_has_overflowed(seq)))
31340 +/* ---------------------------------------------------------------------- */
31342 +static struct seq_file *au_seq(char *p, ssize_t len)
31344 + struct seq_file *seq;
31346 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31348 + /* mutex_init(&seq.lock); */
31351 + return seq; /* success */
31354 + seq = ERR_PTR(-ENOMEM);
31358 +#define SysaufsBr_PREFIX "br"
31359 +#define SysaufsBrid_PREFIX "brid"
31361 +/* todo: file size may exceed PAGE_SIZE */
31362 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31368 + aufs_bindex_t bbot;
31369 + struct au_sbinfo *sbinfo;
31370 + struct super_block *sb;
31371 + struct seq_file *seq;
31373 + struct attribute **cattr;
31375 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31376 + sb = sbinfo->si_sb;
31379 + * prevent a race condition between sysfs and aufs.
31380 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31381 + * prohibits maintaining the sysfs entries.
31382 + * hew we acquire read lock after sysfs_get_active_two().
31383 + * on the other hand, the remount process may maintain the sysfs/aufs
31384 + * entries after acquiring write lock.
31385 + * it can cause a deadlock.
31386 + * simply we gave up processing read here.
31389 + if (unlikely(!si_noflush_read_trylock(sb)))
31392 + seq = au_seq(buf, PAGE_SIZE);
31393 + err = PTR_ERR(seq);
31397 + name = (void *)attr->name;
31398 + cattr = sysaufs_si_attrs;
31400 + if (!strcmp(name, (*cattr)->name)) {
31401 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31408 + if (!strncmp(name, SysaufsBrid_PREFIX,
31409 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31410 + idx = AuBrSysfs_BRID;
31411 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31412 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31413 + sizeof(SysaufsBr_PREFIX) - 1)) {
31414 + idx = AuBrSysfs_BR;
31415 + name += sizeof(SysaufsBr_PREFIX) - 1;
31419 + err = kstrtol(name, 10, &l);
31421 + bbot = au_sbbot(sb);
31423 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31430 + err = seq->count;
31431 + /* sysfs limit */
31432 + if (unlikely(err == PAGE_SIZE))
31435 + au_kfree_rcu(seq);
31437 + si_read_unlock(sb);
31442 +/* ---------------------------------------------------------------------- */
31444 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31448 + aufs_bindex_t bindex, bbot;
31451 + struct seq_file *seq;
31452 + struct au_branch *br;
31454 + si_read_lock(sb, AuLock_FLUSH);
31455 + bbot = au_sbbot(sb);
31461 + buf = (void *)__get_free_page(GFP_NOFS);
31462 + if (unlikely(!buf))
31465 + seq = au_seq(buf, PAGE_SIZE);
31466 + err = PTR_ERR(seq);
31470 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31471 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31472 + /* VERIFY_WRITE */
31473 + err = !access_ok(arg, sizeof(*arg));
31474 + if (unlikely(err))
31477 + br = au_sbr(sb, bindex);
31478 + brid = br->br_id;
31479 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31480 + err = __put_user(brid, &arg->id);
31481 + if (unlikely(err))
31484 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31485 + err = __put_user(br->br_perm, &arg->perm);
31486 + if (unlikely(err))
31489 + err = au_seq_path(seq, &br->br_path);
31490 + if (unlikely(err))
31492 + seq_putc(seq, '\0');
31493 + if (!seq_has_overflowed(seq)) {
31494 + err = copy_to_user(arg->path, seq->buf, seq->count);
31496 + if (unlikely(err))
31503 + if (unlikely(err))
31507 + au_kfree_rcu(seq);
31509 + free_page((unsigned long)buf);
31511 + si_read_unlock(sb);
31515 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31517 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31520 +#ifdef CONFIG_COMPAT
31521 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31523 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31527 +/* ---------------------------------------------------------------------- */
31529 +void sysaufs_br_init(struct au_branch *br)
31532 + struct au_brsysfs *br_sysfs;
31533 + struct attribute *attr;
31535 + br_sysfs = br->br_sysfs;
31536 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31537 + attr = &br_sysfs->attr;
31538 + sysfs_attr_init(attr);
31539 + attr->name = br_sysfs->name;
31540 + attr->mode = 0444;
31545 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31547 + struct au_branch *br;
31548 + struct kobject *kobj;
31549 + struct au_brsysfs *br_sysfs;
31551 + aufs_bindex_t bbot;
31553 + if (!sysaufs_brs)
31556 + kobj = &au_sbi(sb)->si_kobj;
31557 + bbot = au_sbbot(sb);
31558 + for (; bindex <= bbot; bindex++) {
31559 + br = au_sbr(sb, bindex);
31560 + br_sysfs = br->br_sysfs;
31561 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31562 + sysfs_remove_file(kobj, &br_sysfs->attr);
31568 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31571 + aufs_bindex_t bbot;
31572 + struct kobject *kobj;
31573 + struct au_branch *br;
31574 + struct au_brsysfs *br_sysfs;
31576 + if (!sysaufs_brs)
31579 + kobj = &au_sbi(sb)->si_kobj;
31580 + bbot = au_sbbot(sb);
31581 + for (; bindex <= bbot; bindex++) {
31582 + br = au_sbr(sb, bindex);
31583 + br_sysfs = br->br_sysfs;
31584 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31585 + SysaufsBr_PREFIX "%d", bindex);
31586 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31587 + SysaufsBrid_PREFIX "%d", bindex);
31588 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31589 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31590 + if (unlikely(err))
31591 + pr_warn("failed %s under sysfs(%d)\n",
31592 + br_sysfs->name, err);
31597 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31598 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31599 +++ linux/fs/aufs/sysrq.c 2021-12-03 15:38:59.939980643 +0100
31601 +// SPDX-License-Identifier: GPL-2.0
31603 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31605 + * This program, aufs is free software; you can redistribute it and/or modify
31606 + * it under the terms of the GNU General Public License as published by
31607 + * the Free Software Foundation; either version 2 of the License, or
31608 + * (at your option) any later version.
31610 + * This program is distributed in the hope that it will be useful,
31611 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31612 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31613 + * GNU General Public License for more details.
31615 + * You should have received a copy of the GNU General Public License
31616 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31620 + * magic sysrq handler
31623 +/* #include <linux/sysrq.h> */
31624 +#include <linux/writeback.h>
31627 +/* ---------------------------------------------------------------------- */
31629 +static void sysrq_sb(struct super_block *sb)
31632 + struct au_sbinfo *sbinfo;
31633 + struct file *file;
31634 + struct hlist_bl_head *files;
31635 + struct hlist_bl_node *pos;
31636 + struct au_finfo *finfo;
31639 + plevel = au_plevel;
31640 + au_plevel = KERN_WARNING;
31642 + /* since we define pr_fmt, call printk directly */
31643 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31645 + sbinfo = au_sbi(sb);
31646 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31647 + pr("superblock\n");
31650 +#if 0 /* reserved */
31652 + int err, i, j, ndentry;
31653 + struct au_dcsub_pages dpages;
31654 + struct au_dpage *dpage;
31656 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31657 + if (unlikely(err))
31659 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31661 + for (i = 0; i < dpages.ndpage; i++) {
31662 + dpage = dpages.dpages + i;
31663 + ndentry = dpage->ndentry;
31664 + for (j = 0; j < ndentry; j++)
31665 + au_dpri_dentry(dpage->dentries[j]);
31667 + au_dpages_free(&dpages);
31671 + pr("isolated inode\n");
31672 + spin_lock(&sb->s_inode_list_lock);
31673 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31674 + spin_lock(&i->i_lock);
31675 + if (hlist_empty(&i->i_dentry))
31676 + au_dpri_inode(i);
31677 + spin_unlock(&i->i_lock);
31679 + spin_unlock(&sb->s_inode_list_lock);
31682 + files = &au_sbi(sb)->si_files;
31683 + hlist_bl_lock(files);
31684 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31687 + file = finfo->fi_file;
31688 + mode = file_inode(file)->i_mode;
31689 + if (!special_file(mode))
31690 + au_dpri_file(file);
31692 + hlist_bl_unlock(files);
31696 + au_plevel = plevel;
31699 +/* ---------------------------------------------------------------------- */
31701 +/* module parameter */
31702 +static char *aufs_sysrq_key = "a";
31703 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31704 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31706 +static void au_sysrq(int key __maybe_unused)
31708 + struct au_sbinfo *sbinfo;
31709 + struct hlist_bl_node *pos;
31712 + au_sbilist_lock();
31713 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31714 + sysrq_sb(sbinfo->si_sb);
31715 + au_sbilist_unlock();
31719 +static struct sysrq_key_op au_sysrq_op = {
31720 + .handler = au_sysrq,
31721 + .help_msg = "Aufs",
31722 + .action_msg = "Aufs",
31723 + .enable_mask = SYSRQ_ENABLE_DUMP
31726 +/* ---------------------------------------------------------------------- */
31728 +int __init au_sysrq_init(void)
31734 + key = *aufs_sysrq_key;
31735 + if ('a' <= key && key <= 'z')
31736 + err = register_sysrq_key(key, &au_sysrq_op);
31737 + if (unlikely(err))
31738 + pr_err("err %d, sysrq=%c\n", err, key);
31742 +void au_sysrq_fin(void)
31746 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31747 + if (unlikely(err))
31748 + pr_err("err %d (ignored)\n", err);
31750 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31751 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31752 +++ linux/fs/aufs/vdir.c 2021-12-03 15:38:59.939980643 +0100
31754 +// SPDX-License-Identifier: GPL-2.0
31756 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31758 + * This program, aufs is free software; you can redistribute it and/or modify
31759 + * it under the terms of the GNU General Public License as published by
31760 + * the Free Software Foundation; either version 2 of the License, or
31761 + * (at your option) any later version.
31763 + * This program is distributed in the hope that it will be useful,
31764 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31765 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31766 + * GNU General Public License for more details.
31768 + * You should have received a copy of the GNU General Public License
31769 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31773 + * virtual or vertical directory
31776 +#include <linux/iversion.h>
31779 +static unsigned int calc_size(int nlen)
31781 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31784 +static int set_deblk_end(union au_vdir_deblk_p *p,
31785 + union au_vdir_deblk_p *deblk_end)
31787 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31788 + p->de->de_str.len = 0;
31792 + return -1; /* error */
31795 +/* returns true or false */
31796 +static int is_deblk_end(union au_vdir_deblk_p *p,
31797 + union au_vdir_deblk_p *deblk_end)
31799 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31800 + return !p->de->de_str.len;
31804 +static unsigned char *last_deblk(struct au_vdir *vdir)
31806 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31809 +/* ---------------------------------------------------------------------- */
31811 +/* estimate the appropriate size for name hash table */
31812 +unsigned int au_rdhash_est(loff_t sz)
31820 + if (sz < AUFS_RDHASH_DEF)
31821 + n = AUFS_RDHASH_DEF;
31822 + /* pr_info("n %u\n", n); */
31827 + * the allocated memory has to be freed by
31828 + * au_nhash_wh_free() or au_nhash_de_free().
31830 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31832 + struct hlist_head *head;
31836 + sz = sizeof(*nhash->nh_head) * num_hash;
31837 + head = kmalloc(sz, gfp);
31839 + nhash->nh_num = num_hash;
31840 + nhash->nh_head = head;
31841 + for (u = 0; u < num_hash; u++)
31842 + INIT_HLIST_HEAD(head++);
31843 + return 0; /* success */
31849 +static void nhash_count(struct hlist_head *head)
31851 +#if 0 /* debugging */
31853 + struct hlist_node *pos;
31856 + hlist_for_each(pos, head)
31858 + pr_info("%lu\n", n);
31862 +static void au_nhash_wh_do_free(struct hlist_head *head)
31864 + struct au_vdir_wh *pos;
31865 + struct hlist_node *node;
31867 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31868 + au_kfree_rcu(pos);
31871 +static void au_nhash_de_do_free(struct hlist_head *head)
31873 + struct au_vdir_dehstr *pos;
31874 + struct hlist_node *node;
31876 + hlist_for_each_entry_safe(pos, node, head, hash)
31877 + au_cache_free_vdir_dehstr(pos);
31880 +static void au_nhash_do_free(struct au_nhash *nhash,
31881 + void (*free)(struct hlist_head *head))
31884 + struct hlist_head *head;
31886 + n = nhash->nh_num;
31890 + head = nhash->nh_head;
31891 + while (n-- > 0) {
31892 + nhash_count(head);
31895 + au_kfree_try_rcu(nhash->nh_head);
31898 +void au_nhash_wh_free(struct au_nhash *whlist)
31900 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31903 +static void au_nhash_de_free(struct au_nhash *delist)
31905 + au_nhash_do_free(delist, au_nhash_de_do_free);
31908 +/* ---------------------------------------------------------------------- */
31910 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31914 + unsigned int u, n;
31915 + struct hlist_head *head;
31916 + struct au_vdir_wh *pos;
31919 + n = whlist->nh_num;
31920 + head = whlist->nh_head;
31921 + for (u = 0; u < n; u++, head++)
31922 + hlist_for_each_entry(pos, head, wh_hash)
31923 + if (pos->wh_bindex == btgt && ++num > limit)
31928 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31929 + unsigned char *name,
31930 + unsigned int len)
31933 + /* const unsigned int magic_bit = 12; */
31935 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31942 + /* v = hash_long(v, magic_bit); */
31943 + v %= nhash->nh_num;
31944 + return nhash->nh_head + v;
31947 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31950 + return str->len == nlen && !memcmp(str->name, name, nlen);
31953 +/* returns found or not */
31954 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31956 + struct hlist_head *head;
31957 + struct au_vdir_wh *pos;
31958 + struct au_vdir_destr *str;
31960 + head = au_name_hash(whlist, name, nlen);
31961 + hlist_for_each_entry(pos, head, wh_hash) {
31962 + str = &pos->wh_str;
31963 + AuDbg("%.*s\n", str->len, str->name);
31964 + if (au_nhash_test_name(str, name, nlen))
31970 +/* returns found(true) or not */
31971 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31973 + struct hlist_head *head;
31974 + struct au_vdir_dehstr *pos;
31975 + struct au_vdir_destr *str;
31977 + head = au_name_hash(delist, name, nlen);
31978 + hlist_for_each_entry(pos, head, hash) {
31980 + AuDbg("%.*s\n", str->len, str->name);
31981 + if (au_nhash_test_name(str, name, nlen))
31987 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31988 + unsigned char d_type)
31990 +#ifdef CONFIG_AUFS_SHWH
31991 + wh->wh_ino = ino;
31992 + wh->wh_type = d_type;
31996 +/* ---------------------------------------------------------------------- */
31998 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31999 + unsigned int d_type, aufs_bindex_t bindex,
32000 + unsigned char shwh)
32003 + struct au_vdir_destr *str;
32004 + struct au_vdir_wh *wh;
32006 + AuDbg("%.*s\n", nlen, name);
32007 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32010 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32011 + if (unlikely(!wh))
32015 + wh->wh_bindex = bindex;
32017 + au_shwh_init_wh(wh, ino, d_type);
32018 + str = &wh->wh_str;
32020 + memcpy(str->name, name, nlen);
32021 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32028 +static int append_deblk(struct au_vdir *vdir)
32031 + unsigned long ul;
32032 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32033 + union au_vdir_deblk_p p, deblk_end;
32034 + unsigned char **o;
32037 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32038 + GFP_NOFS, /*may_shrink*/0);
32039 + if (unlikely(!o))
32042 + vdir->vd_deblk = o;
32043 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32045 + ul = vdir->vd_nblk++;
32046 + vdir->vd_deblk[ul] = p.deblk;
32047 + vdir->vd_last.ul = ul;
32048 + vdir->vd_last.p.deblk = p.deblk;
32049 + deblk_end.deblk = p.deblk + deblk_sz;
32050 + err = set_deblk_end(&p, &deblk_end);
32057 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32058 + unsigned int d_type, struct au_nhash *delist)
32062 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32063 + union au_vdir_deblk_p p, *room, deblk_end;
32064 + struct au_vdir_dehstr *dehstr;
32066 + p.deblk = last_deblk(vdir);
32067 + deblk_end.deblk = p.deblk + deblk_sz;
32068 + room = &vdir->vd_last.p;
32069 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32070 + || !is_deblk_end(room, &deblk_end));
32072 + sz = calc_size(nlen);
32073 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32074 + err = append_deblk(vdir);
32075 + if (unlikely(err))
32078 + p.deblk = last_deblk(vdir);
32079 + deblk_end.deblk = p.deblk + deblk_sz;
32081 + AuDebugOn(room->deblk != p.deblk);
32085 + dehstr = au_cache_alloc_vdir_dehstr();
32086 + if (unlikely(!dehstr))
32089 + dehstr->str = &room->de->de_str;
32090 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32091 + room->de->de_ino = ino;
32092 + room->de->de_type = d_type;
32093 + room->de->de_str.len = nlen;
32094 + memcpy(room->de->de_str.name, name, nlen);
32097 + room->deblk += sz;
32098 + if (unlikely(set_deblk_end(room, &deblk_end)))
32099 + err = append_deblk(vdir);
32106 +/* ---------------------------------------------------------------------- */
32108 +void au_vdir_free(struct au_vdir *vdir)
32110 + unsigned char **deblk;
32112 + deblk = vdir->vd_deblk;
32113 + while (vdir->vd_nblk--)
32114 + au_kfree_try_rcu(*deblk++);
32115 + au_kfree_try_rcu(vdir->vd_deblk);
32116 + au_cache_free_vdir(vdir);
32119 +static struct au_vdir *alloc_vdir(struct file *file)
32121 + struct au_vdir *vdir;
32122 + struct super_block *sb;
32125 + sb = file->f_path.dentry->d_sb;
32126 + SiMustAnyLock(sb);
32129 + vdir = au_cache_alloc_vdir();
32130 + if (unlikely(!vdir))
32133 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32134 + if (unlikely(!vdir->vd_deblk))
32137 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32138 + if (!vdir->vd_deblk_sz) {
32139 + /* estimate the appropriate size for deblk */
32140 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32141 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32143 + vdir->vd_nblk = 0;
32144 + vdir->vd_version = 0;
32145 + vdir->vd_jiffy = 0;
32146 + err = append_deblk(vdir);
32148 + return vdir; /* success */
32150 + au_kfree_try_rcu(vdir->vd_deblk);
32153 + au_cache_free_vdir(vdir);
32155 + vdir = ERR_PTR(err);
32159 +static int reinit_vdir(struct au_vdir *vdir)
32162 + union au_vdir_deblk_p p, deblk_end;
32164 + while (vdir->vd_nblk > 1) {
32165 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32166 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32169 + p.deblk = vdir->vd_deblk[0];
32170 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32171 + err = set_deblk_end(&p, &deblk_end);
32172 + /* keep vd_dblk_sz */
32173 + vdir->vd_last.ul = 0;
32174 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32175 + vdir->vd_version = 0;
32176 + vdir->vd_jiffy = 0;
32181 +/* ---------------------------------------------------------------------- */
32183 +#define AuFillVdir_CALLED 1
32184 +#define AuFillVdir_WHABLE (1 << 1)
32185 +#define AuFillVdir_SHWH (1 << 2)
32186 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32187 +#define au_fset_fillvdir(flags, name) \
32188 + do { (flags) |= AuFillVdir_##name; } while (0)
32189 +#define au_fclr_fillvdir(flags, name) \
32190 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32192 +#ifndef CONFIG_AUFS_SHWH
32193 +#undef AuFillVdir_SHWH
32194 +#define AuFillVdir_SHWH 0
32197 +struct fillvdir_arg {
32198 + struct dir_context ctx;
32199 + struct file *file;
32200 + struct au_vdir *vdir;
32201 + struct au_nhash delist;
32202 + struct au_nhash whlist;
32203 + aufs_bindex_t bindex;
32204 + unsigned int flags;
32208 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32209 + loff_t offset __maybe_unused, u64 h_ino,
32210 + unsigned int d_type)
32212 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32213 + char *name = (void *)__name;
32214 + struct super_block *sb;
32216 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32219 + sb = arg->file->f_path.dentry->d_sb;
32220 + au_fset_fillvdir(arg->flags, CALLED);
32222 + if (nlen <= AUFS_WH_PFX_LEN
32223 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32224 + if (test_known(&arg->delist, name, nlen)
32225 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32226 + goto out; /* already exists or whiteouted */
32228 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32230 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32231 + d_type = DT_UNKNOWN;
32232 + arg->err = append_de(arg->vdir, name, nlen, ino,
32233 + d_type, &arg->delist);
32235 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32236 + name += AUFS_WH_PFX_LEN;
32237 + nlen -= AUFS_WH_PFX_LEN;
32238 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32239 + goto out; /* already whiteouted */
32241 + ino = 0; /* just to suppress a warning */
32243 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32246 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32247 + d_type = DT_UNKNOWN;
32248 + arg->err = au_nhash_append_wh
32249 + (&arg->whlist, name, nlen, ino, d_type,
32250 + arg->bindex, shwh);
32256 + arg->vdir->vd_jiffy = jiffies;
32258 + AuTraceErr(arg->err);
32262 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32263 + struct au_nhash *whlist, struct au_nhash *delist)
32265 +#ifdef CONFIG_AUFS_SHWH
32267 + unsigned int nh, u;
32268 + struct hlist_head *head;
32269 + struct au_vdir_wh *pos;
32270 + struct hlist_node *n;
32272 + struct au_vdir_destr *destr;
32274 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32277 + o = p = (void *)__get_free_page(GFP_NOFS);
32278 + if (unlikely(!p))
32282 + nh = whlist->nh_num;
32283 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32284 + p += AUFS_WH_PFX_LEN;
32285 + for (u = 0; u < nh; u++) {
32286 + head = whlist->nh_head + u;
32287 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32288 + destr = &pos->wh_str;
32289 + memcpy(p, destr->name, destr->len);
32290 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32291 + pos->wh_ino, pos->wh_type, delist);
32292 + if (unlikely(err))
32297 + free_page((unsigned long)o);
32307 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32310 + unsigned int rdhash;
32312 + aufs_bindex_t bbot, bindex, btop;
32313 + unsigned char shwh;
32314 + struct file *hf, *file;
32315 + struct super_block *sb;
32317 + file = arg->file;
32318 + sb = file->f_path.dentry->d_sb;
32319 + SiMustAnyLock(sb);
32321 + rdhash = au_sbi(sb)->si_rdhash;
32323 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32324 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32325 + if (unlikely(err))
32327 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32328 + if (unlikely(err))
32334 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32336 + au_fset_fillvdir(arg->flags, SHWH);
32338 + btop = au_fbtop(file);
32339 + bbot = au_fbbot_dir(file);
32340 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32341 + hf = au_hf_dir(file, bindex);
32345 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32347 + if (unlikely(offset))
32350 + arg->bindex = bindex;
32351 + au_fclr_fillvdir(arg->flags, WHABLE);
32353 + || (bindex != bbot
32354 + && au_br_whable(au_sbr_perm(sb, bindex))))
32355 + au_fset_fillvdir(arg->flags, WHABLE);
32358 + au_fclr_fillvdir(arg->flags, CALLED);
32360 + err = vfsub_iterate_dir(hf, &arg->ctx);
32363 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32366 + * dir_relax() may be good for concurrency, but aufs should not
32367 + * use it since it will cause a lockdep problem.
32371 + if (!err && shwh)
32372 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32374 + au_nhash_wh_free(&arg->whlist);
32377 + au_nhash_de_free(&arg->delist);
32382 +static int read_vdir(struct file *file, int may_read)
32385 + unsigned long expire;
32386 + unsigned char do_read;
32387 + struct fillvdir_arg arg = {
32389 + .actor = fillvdir
32392 + struct inode *inode;
32393 + struct au_vdir *vdir, *allocated;
32396 + inode = file_inode(file);
32397 + IMustLock(inode);
32398 + IiMustWriteLock(inode);
32399 + SiMustAnyLock(inode->i_sb);
32401 + allocated = NULL;
32403 + expire = au_sbi(inode->i_sb)->si_rdcache;
32404 + vdir = au_ivdir(inode);
32407 + vdir = alloc_vdir(file);
32408 + err = PTR_ERR(vdir);
32409 + if (IS_ERR(vdir))
32412 + allocated = vdir;
32413 + } else if (may_read
32414 + && (!inode_eq_iversion(inode, vdir->vd_version)
32415 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32417 + err = reinit_vdir(vdir);
32418 + if (unlikely(err))
32423 + return 0; /* success */
32427 + err = au_do_read_vdir(&arg);
32429 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32430 + vdir->vd_version = inode_query_iversion(inode);
32431 + vdir->vd_last.ul = 0;
32432 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32434 + au_set_ivdir(inode, allocated);
32435 + } else if (allocated)
32436 + au_vdir_free(allocated);
32442 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32445 + unsigned long ul, n;
32446 + const unsigned int deblk_sz = src->vd_deblk_sz;
32448 + AuDebugOn(tgt->vd_nblk != 1);
32451 + if (tgt->vd_nblk < src->vd_nblk) {
32452 + unsigned char **p;
32454 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32455 + GFP_NOFS, /*may_shrink*/0);
32456 + if (unlikely(!p))
32458 + tgt->vd_deblk = p;
32461 + if (tgt->vd_deblk_sz != deblk_sz) {
32462 + unsigned char *p;
32464 + tgt->vd_deblk_sz = deblk_sz;
32465 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32466 + /*may_shrink*/1);
32467 + if (unlikely(!p))
32469 + tgt->vd_deblk[0] = p;
32471 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32472 + tgt->vd_version = src->vd_version;
32473 + tgt->vd_jiffy = src->vd_jiffy;
32475 + n = src->vd_nblk;
32476 + for (ul = 1; ul < n; ul++) {
32477 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32479 + if (unlikely(!tgt->vd_deblk[ul]))
32483 + tgt->vd_nblk = n;
32484 + tgt->vd_last.ul = tgt->vd_last.ul;
32485 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32486 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32487 + - src->vd_deblk[src->vd_last.ul];
32489 + return 0; /* success */
32492 + rerr = reinit_vdir(tgt);
32497 +int au_vdir_init(struct file *file)
32500 + struct inode *inode;
32501 + struct au_vdir *vdir_cache, *allocated;
32503 + /* test file->f_pos here instead of ctx->pos */
32504 + err = read_vdir(file, !file->f_pos);
32505 + if (unlikely(err))
32508 + allocated = NULL;
32509 + vdir_cache = au_fvdir_cache(file);
32510 + if (!vdir_cache) {
32511 + vdir_cache = alloc_vdir(file);
32512 + err = PTR_ERR(vdir_cache);
32513 + if (IS_ERR(vdir_cache))
32515 + allocated = vdir_cache;
32516 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32517 + /* test file->f_pos here instead of ctx->pos */
32518 + err = reinit_vdir(vdir_cache);
32519 + if (unlikely(err))
32522 + return 0; /* success */
32524 + inode = file_inode(file);
32525 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32527 + file->f_version = inode_query_iversion(inode);
32529 + au_set_fvdir_cache(file, allocated);
32530 + } else if (allocated)
32531 + au_vdir_free(allocated);
32537 +static loff_t calc_offset(struct au_vdir *vdir)
32540 + union au_vdir_deblk_p p;
32542 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32543 + offset = vdir->vd_last.p.deblk - p.deblk;
32544 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32548 +/* returns true or false */
32549 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32552 + unsigned int deblk_sz;
32553 + unsigned long ul, n;
32555 + union au_vdir_deblk_p p, deblk_end;
32556 + struct au_vdir *vdir_cache;
32559 + vdir_cache = au_fvdir_cache(file);
32560 + offset = calc_offset(vdir_cache);
32561 + AuDbg("offset %lld\n", offset);
32562 + if (ctx->pos == offset)
32565 + vdir_cache->vd_last.ul = 0;
32566 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32571 + deblk_sz = vdir_cache->vd_deblk_sz;
32572 + ul = div64_u64(ctx->pos, deblk_sz);
32573 + AuDbg("ul %lu\n", ul);
32574 + if (ul >= vdir_cache->vd_nblk)
32577 + n = vdir_cache->vd_nblk;
32578 + for (; ul < n; ul++) {
32579 + p.deblk = vdir_cache->vd_deblk[ul];
32580 + deblk_end.deblk = p.deblk + deblk_sz;
32582 + offset *= deblk_sz;
32583 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32586 + l = calc_size(p.de->de_str.len);
32590 + if (!is_deblk_end(&p, &deblk_end)) {
32592 + vdir_cache->vd_last.ul = ul;
32593 + vdir_cache->vd_last.p = p;
32601 + AuDbg("valid %d\n", !valid);
32605 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32607 + unsigned int l, deblk_sz;
32608 + union au_vdir_deblk_p deblk_end;
32609 + struct au_vdir *vdir_cache;
32610 + struct au_vdir_de *de;
32612 + if (!seek_vdir(file, ctx))
32615 + vdir_cache = au_fvdir_cache(file);
32616 + deblk_sz = vdir_cache->vd_deblk_sz;
32618 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32619 + deblk_end.deblk += deblk_sz;
32620 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32621 + de = vdir_cache->vd_last.p.de;
32622 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32623 + de->de_str.len, de->de_str.name, ctx->pos,
32624 + (unsigned long)de->de_ino, de->de_type);
32625 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32626 + de->de_str.len, de->de_ino,
32628 + /* todo: ignore the error caused by udba? */
32629 + /* return err; */
32633 + l = calc_size(de->de_str.len);
32634 + vdir_cache->vd_last.p.deblk += l;
32637 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32638 + vdir_cache->vd_last.ul++;
32639 + vdir_cache->vd_last.p.deblk
32640 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32641 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32650 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32651 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32652 +++ linux/fs/aufs/vfsub.c 2021-12-03 15:40:58.236647297 +0100
32654 +// SPDX-License-Identifier: GPL-2.0
32656 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32658 + * This program, aufs is free software; you can redistribute it and/or modify
32659 + * it under the terms of the GNU General Public License as published by
32660 + * the Free Software Foundation; either version 2 of the License, or
32661 + * (at your option) any later version.
32663 + * This program is distributed in the hope that it will be useful,
32664 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32665 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32666 + * GNU General Public License for more details.
32668 + * You should have received a copy of the GNU General Public License
32669 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32673 + * sub-routines for VFS
32676 +#include <linux/mnt_namespace.h>
32677 +#include <linux/namei.h>
32678 +#include <linux/nsproxy.h>
32679 +#include <linux/security.h>
32680 +#include <linux/splice.h>
32683 +#ifdef CONFIG_AUFS_BR_FUSE
32684 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32686 + if (!au_test_fuse(h_sb) || !au_userns)
32689 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32693 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32698 + down_read(&h_sb->s_umount);
32699 + err = __sync_filesystem(h_sb, wait);
32700 + up_read(&h_sb->s_umount);
32706 +/* ---------------------------------------------------------------------- */
32708 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32712 + struct super_block *h_sb;
32715 + * Always needs h_path->mnt for LSM or FUSE branch.
32717 + AuDebugOn(!h_path->mnt);
32719 + /* for remote fs, leave work for its getattr or d_revalidate */
32720 + /* for bad i_attr fs, handle them in aufs_getattr() */
32721 + /* still some fs may acquire i_mutex. we need to skip them */
32725 + h_sb = h_path->dentry->d_sb;
32726 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32728 + err = vfsub_getattr(h_path, &st);
32733 +/* ---------------------------------------------------------------------- */
32735 +struct file *vfsub_dentry_open(struct path *path, int flags)
32737 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32741 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32743 + struct file *file;
32746 + file = filp_open(path,
32747 + oflags /* | __FMODE_NONOTIFY */,
32750 + if (IS_ERR(file))
32752 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32759 + * Ideally this function should call VFS:do_last() in order to keep all its
32760 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32761 + * structure such as nameidata. This is a second (or third) best approach.
32762 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32764 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32765 + struct vfsub_aopen_args *args)
32768 + struct au_branch *br = args->br;
32769 + struct file *file = args->file;
32770 + /* copied from linux/fs/namei.c:atomic_open() */
32771 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32774 + AuDebugOn(!dir->i_op->atomic_open);
32776 + err = au_br_test_oflag(args->open_flag, br);
32777 + if (unlikely(err))
32780 + au_lcnt_inc(&br->br_nfiles);
32781 + file->f_path.dentry = DENTRY_NOT_SET;
32782 + file->f_path.mnt = au_br_mnt(br);
32783 + AuDbg("%ps\n", dir->i_op->atomic_open);
32784 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32785 + args->create_mode);
32786 + if (unlikely(err < 0)) {
32787 + au_lcnt_dec(&br->br_nfiles);
32791 + /* temporary workaround for nfsv4 branch */
32792 + if (au_test_nfs(dir->i_sb))
32793 + nfs_mark_for_revalidate(dir);
32795 + if (file->f_mode & FMODE_CREATED)
32796 + fsnotify_create(dir, dentry);
32797 + if (!(file->f_mode & FMODE_OPENED)) {
32798 + au_lcnt_dec(&br->br_nfiles);
32802 + /* todo: call VFS:may_open() here */
32803 + /* todo: ima_file_check() too? */
32804 + if (!err && (args->open_flag & __FMODE_EXEC))
32805 + err = deny_write_access(file);
32807 + fsnotify_open(file);
32809 + au_lcnt_dec(&br->br_nfiles);
32810 + /* note that the file is created and still opened */
32816 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32820 + err = kern_path(name, flags, path);
32821 + if (!err && d_is_positive(path->dentry))
32822 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32826 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32827 + struct path *ppath, int len)
32829 + struct path path;
32831 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
32832 + if (IS_ERR(path.dentry))
32834 + if (d_is_positive(path.dentry)) {
32835 + path.mnt = ppath->mnt;
32836 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32840 + AuTraceErrPtr(path.dentry);
32841 + return path.dentry;
32844 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
32847 + struct path path;
32849 + /* VFS checks it too, but by WARN_ON_ONCE() */
32850 + IMustLock(d_inode(ppath->dentry));
32852 + path.dentry = lookup_one_len(name, ppath->dentry, len);
32853 + if (IS_ERR(path.dentry))
32855 + if (d_is_positive(path.dentry)) {
32856 + path.mnt = ppath->mnt;
32857 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32861 + AuTraceErrPtr(path.dentry);
32862 + return path.dentry;
32865 +void vfsub_call_lkup_one(void *args)
32867 + struct vfsub_lkup_one_args *a = args;
32868 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
32871 +/* ---------------------------------------------------------------------- */
32873 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32874 + struct dentry *d2, struct au_hinode *hdir2)
32876 + struct dentry *d;
32879 + d = lock_rename(d1, d2);
32881 + au_hn_suspend(hdir1);
32882 + if (hdir1 != hdir2)
32883 + au_hn_suspend(hdir2);
32888 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32889 + struct dentry *d2, struct au_hinode *hdir2)
32891 + au_hn_resume(hdir1);
32892 + if (hdir1 != hdir2)
32893 + au_hn_resume(hdir2);
32895 + unlock_rename(d1, d2);
32899 +/* ---------------------------------------------------------------------- */
32901 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32904 + struct dentry *d;
32905 + struct user_namespace *userns;
32909 + d = path->dentry;
32910 + path->dentry = d->d_parent;
32911 + err = security_path_mknod(path, d, mode, 0);
32912 + path->dentry = d;
32913 + if (unlikely(err))
32915 + userns = mnt_user_ns(path->mnt);
32918 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
32921 + struct path tmp = *path;
32924 + vfsub_update_h_iattr(&tmp, &did);
32926 + tmp.dentry = path->dentry->d_parent;
32927 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32936 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32939 + struct dentry *d;
32940 + struct user_namespace *userns;
32944 + d = path->dentry;
32945 + path->dentry = d->d_parent;
32946 + err = security_path_symlink(path, d, symname);
32947 + path->dentry = d;
32948 + if (unlikely(err))
32950 + userns = mnt_user_ns(path->mnt);
32953 + err = vfs_symlink(userns, dir, path->dentry, symname);
32956 + struct path tmp = *path;
32959 + vfsub_update_h_iattr(&tmp, &did);
32961 + tmp.dentry = path->dentry->d_parent;
32962 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32971 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32974 + struct dentry *d;
32975 + struct user_namespace *userns;
32979 + d = path->dentry;
32980 + path->dentry = d->d_parent;
32981 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32982 + path->dentry = d;
32983 + if (unlikely(err))
32985 + userns = mnt_user_ns(path->mnt);
32988 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
32991 + struct path tmp = *path;
32994 + vfsub_update_h_iattr(&tmp, &did);
32996 + tmp.dentry = path->dentry->d_parent;
32997 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33006 +static int au_test_nlink(struct inode *inode)
33008 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33010 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33011 + || inode->i_nlink < link_max)
33016 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33017 + struct inode **delegated_inode)
33020 + struct dentry *d;
33021 + struct user_namespace *userns;
33025 + err = au_test_nlink(d_inode(src_dentry));
33026 + if (unlikely(err))
33029 + /* we don't call may_linkat() */
33030 + d = path->dentry;
33031 + path->dentry = d->d_parent;
33032 + err = security_path_link(src_dentry, path, d);
33033 + path->dentry = d;
33034 + if (unlikely(err))
33036 + userns = mnt_user_ns(path->mnt);
33039 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33042 + struct path tmp = *path;
33045 + /* fuse has different memory inode for the same inumber */
33046 + vfsub_update_h_iattr(&tmp, &did);
33048 + tmp.dentry = path->dentry->d_parent;
33049 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33050 + tmp.dentry = src_dentry;
33051 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33060 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33061 + struct inode *dir, struct path *path,
33062 + struct inode **delegated_inode, unsigned int flags)
33065 + struct renamedata rd;
33066 + struct path tmp = {
33069 + struct dentry *d;
33072 + IMustLock(src_dir);
33074 + d = path->dentry;
33075 + path->dentry = d->d_parent;
33076 + tmp.dentry = src_dentry->d_parent;
33077 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33078 + path->dentry = d;
33079 + if (unlikely(err))
33082 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33083 + rd.old_dir = src_dir;
33084 + rd.old_dentry = src_dentry;
33085 + rd.new_mnt_userns = rd.old_mnt_userns;
33086 + rd.new_dir = dir;
33087 + rd.new_dentry = path->dentry;
33088 + rd.delegated_inode = delegated_inode;
33089 + rd.flags = flags;
33091 + err = vfs_rename(&rd);
33096 + tmp.dentry = d->d_parent;
33097 + vfsub_update_h_iattr(&tmp, &did);
33099 + tmp.dentry = src_dentry;
33100 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33101 + tmp.dentry = src_dentry->d_parent;
33102 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33111 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33114 + struct dentry *d;
33115 + struct user_namespace *userns;
33119 + d = path->dentry;
33120 + path->dentry = d->d_parent;
33121 + err = security_path_mkdir(path, d, mode);
33122 + path->dentry = d;
33123 + if (unlikely(err))
33125 + userns = mnt_user_ns(path->mnt);
33128 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33131 + struct path tmp = *path;
33134 + vfsub_update_h_iattr(&tmp, &did);
33136 + tmp.dentry = path->dentry->d_parent;
33137 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33146 +int vfsub_rmdir(struct inode *dir, struct path *path)
33149 + struct dentry *d;
33150 + struct user_namespace *userns;
33154 + d = path->dentry;
33155 + path->dentry = d->d_parent;
33156 + err = security_path_rmdir(path, d);
33157 + path->dentry = d;
33158 + if (unlikely(err))
33160 + userns = mnt_user_ns(path->mnt);
33163 + err = vfs_rmdir(userns, dir, path->dentry);
33166 + struct path tmp = {
33167 + .dentry = path->dentry->d_parent,
33171 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33178 +/* ---------------------------------------------------------------------- */
33180 +/* todo: support mmap_sem? */
33181 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33187 + err = vfs_read(file, ubuf, count, ppos);
33190 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33194 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33200 + err = kernel_read(file, kbuf, count, ppos);
33204 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33208 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33214 + err = vfs_write(file, ubuf, count, ppos);
33217 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33221 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33226 + err = kernel_write(file, kbuf, count, ppos);
33229 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33233 +int vfsub_flush(struct file *file, fl_owner_t id)
33238 + if (file->f_op->flush) {
33239 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33240 + err = file->f_op->flush(file, id);
33243 + err = file->f_op->flush(file, id);
33247 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33253 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33257 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33260 + err = iterate_dir(file, ctx);
33263 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33268 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33269 + struct pipe_inode_info *pipe, size_t len,
33270 + unsigned int flags)
33275 + err = do_splice_to(in, ppos, pipe, len, flags);
33277 + file_accessed(in);
33279 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33283 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33284 + loff_t *ppos, size_t len, unsigned int flags)
33289 + err = do_splice_from(pipe, out, ppos, len, flags);
33292 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33296 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33300 + /* file can be NULL */
33302 + err = vfs_fsync(file, datasync);
33306 + AuDebugOn(!file);
33307 + path = &file->f_path;
33309 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33314 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33315 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33316 + struct file *h_file)
33319 + struct inode *h_inode;
33320 + struct super_block *h_sb;
33321 + struct user_namespace *h_userns;
33324 + err = vfsub_truncate(h_path, length);
33328 + h_inode = d_inode(h_path->dentry);
33329 + h_sb = h_inode->i_sb;
33331 + sb_start_write(h_sb);
33333 + err = security_path_truncate(h_path);
33335 + h_userns = mnt_user_ns(h_path->mnt);
33337 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33342 + sb_end_write(h_sb);
33349 +/* ---------------------------------------------------------------------- */
33351 +struct au_vfsub_mkdir_args {
33353 + struct inode *dir;
33354 + struct path *path;
33358 +static void au_call_vfsub_mkdir(void *args)
33360 + struct au_vfsub_mkdir_args *a = args;
33361 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33364 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33366 + int err, do_sio, wkq_err;
33367 + struct user_namespace *userns;
33369 + userns = mnt_user_ns(path->mnt);
33370 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33373 + err = vfsub_mkdir(dir, path, mode);
33376 + struct au_vfsub_mkdir_args args = {
33382 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33383 + if (unlikely(wkq_err))
33390 +struct au_vfsub_rmdir_args {
33392 + struct inode *dir;
33393 + struct path *path;
33396 +static void au_call_vfsub_rmdir(void *args)
33398 + struct au_vfsub_rmdir_args *a = args;
33399 + *a->errp = vfsub_rmdir(a->dir, a->path);
33402 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33404 + int err, do_sio, wkq_err;
33405 + struct user_namespace *userns;
33407 + userns = mnt_user_ns(path->mnt);
33408 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33411 + err = vfsub_rmdir(dir, path);
33414 + struct au_vfsub_rmdir_args args = {
33419 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33420 + if (unlikely(wkq_err))
33427 +/* ---------------------------------------------------------------------- */
33429 +struct notify_change_args {
33431 + struct path *path;
33432 + struct iattr *ia;
33433 + struct inode **delegated_inode;
33436 +static void call_notify_change(void *args)
33438 + struct notify_change_args *a = args;
33439 + struct inode *h_inode;
33440 + struct user_namespace *userns;
33442 + h_inode = d_inode(a->path->dentry);
33443 + IMustLock(h_inode);
33445 + *a->errp = -EPERM;
33446 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33447 + userns = mnt_user_ns(a->path->mnt);
33449 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33450 + a->delegated_inode);
33453 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33455 + AuTraceErr(*a->errp);
33458 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33459 + struct inode **delegated_inode)
33462 + struct notify_change_args args = {
33466 + .delegated_inode = delegated_inode
33469 + call_notify_change(&args);
33474 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33475 + struct inode **delegated_inode)
33477 + int err, wkq_err;
33478 + struct notify_change_args args = {
33482 + .delegated_inode = delegated_inode
33485 + wkq_err = au_wkq_wait(call_notify_change, &args);
33486 + if (unlikely(wkq_err))
33492 +/* ---------------------------------------------------------------------- */
33494 +struct unlink_args {
33496 + struct inode *dir;
33497 + struct path *path;
33498 + struct inode **delegated_inode;
33501 +static void call_unlink(void *args)
33503 + struct unlink_args *a = args;
33504 + struct dentry *d = a->path->dentry;
33505 + struct inode *h_inode;
33506 + struct user_namespace *userns;
33507 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33508 + && au_dcount(d) == 1);
33510 + IMustLock(a->dir);
33512 + a->path->dentry = d->d_parent;
33513 + *a->errp = security_path_unlink(a->path, d);
33514 + a->path->dentry = d;
33515 + if (unlikely(*a->errp))
33518 + if (!stop_sillyrename)
33521 + if (d_is_positive(d)) {
33522 + h_inode = d_inode(d);
33526 + userns = mnt_user_ns(a->path->mnt);
33528 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33531 + struct path tmp = {
33532 + .dentry = d->d_parent,
33533 + .mnt = a->path->mnt
33535 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33538 + if (!stop_sillyrename)
33543 + AuTraceErr(*a->errp);
33547 + * @dir: must be locked.
33548 + * @dentry: target dentry.
33550 +int vfsub_unlink(struct inode *dir, struct path *path,
33551 + struct inode **delegated_inode, int force)
33554 + struct unlink_args args = {
33558 + .delegated_inode = delegated_inode
33562 + call_unlink(&args);
33566 + wkq_err = au_wkq_wait(call_unlink, &args);
33567 + if (unlikely(wkq_err))
33573 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33574 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33575 +++ linux/fs/aufs/vfsub.h 2021-12-03 15:40:58.236647297 +0100
33577 +/* SPDX-License-Identifier: GPL-2.0 */
33579 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33581 + * This program, aufs is free software; you can redistribute it and/or modify
33582 + * it under the terms of the GNU General Public License as published by
33583 + * the Free Software Foundation; either version 2 of the License, or
33584 + * (at your option) any later version.
33586 + * This program is distributed in the hope that it will be useful,
33587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33589 + * GNU General Public License for more details.
33591 + * You should have received a copy of the GNU General Public License
33592 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33596 + * sub-routines for VFS
33599 +#ifndef __AUFS_VFSUB_H__
33600 +#define __AUFS_VFSUB_H__
33604 +#include <linux/fs.h>
33605 +#include <linux/mount.h>
33606 +#include <linux/posix_acl.h>
33607 +#include <linux/xattr.h>
33608 +#include "debug.h"
33610 +/* copied from linux/fs/internal.h */
33611 +/* todo: BAD approach!! */
33612 +extern void __mnt_drop_write(struct vfsmount *);
33613 +extern struct file *alloc_empty_file(int, const struct cred *);
33615 +/* ---------------------------------------------------------------------- */
33617 +/* lock subclass for lower inode */
33618 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33619 +/* reduce? gave up. */
33621 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33622 + AuLsc_I_PARENT, /* lower inode, parent first */
33623 + AuLsc_I_PARENT2, /* copyup dirs */
33624 + AuLsc_I_PARENT3, /* copyup wh */
33630 +/* to debug easier, do not make them inlined functions */
33631 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33632 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33634 +/* ---------------------------------------------------------------------- */
33636 +static inline void vfsub_drop_nlink(struct inode *inode)
33638 + AuDebugOn(!inode->i_nlink);
33639 + drop_nlink(inode);
33642 +static inline void vfsub_dead_dir(struct inode *inode)
33644 + AuDebugOn(!S_ISDIR(inode->i_mode));
33645 + inode->i_flags |= S_DEAD;
33646 + clear_nlink(inode);
33649 +static inline int vfsub_native_ro(struct inode *inode)
33651 + return sb_rdonly(inode->i_sb)
33652 + || IS_RDONLY(inode)
33653 + /* || IS_APPEND(inode) */
33654 + || IS_IMMUTABLE(inode);
33657 +#ifdef CONFIG_AUFS_BR_FUSE
33658 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33660 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33663 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33665 +/* ---------------------------------------------------------------------- */
33667 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33668 +struct file *vfsub_dentry_open(struct path *path, int flags);
33669 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33671 +struct vfsub_aopen_args {
33672 + struct file *file;
33673 + unsigned int open_flag;
33674 + umode_t create_mode;
33675 + struct au_branch *br;
33677 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33678 + struct vfsub_aopen_args *args);
33679 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33681 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33682 + struct path *ppath, int len);
33683 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33686 +struct vfsub_lkup_one_args {
33687 + struct dentry **errp;
33688 + struct qstr *name;
33689 + struct path *ppath;
33692 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33693 + struct path *ppath)
33695 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33698 +void vfsub_call_lkup_one(void *args);
33700 +/* ---------------------------------------------------------------------- */
33702 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33707 + err = mnt_want_write(mnt);
33712 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33715 + mnt_drop_write(mnt);
33719 +#if 0 /* reserved */
33720 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33723 + mnt_drop_write_file(file);
33728 +/* ---------------------------------------------------------------------- */
33731 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33732 + struct dentry *d2, struct au_hinode *hdir2);
33733 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33734 + struct dentry *d2, struct au_hinode *hdir2);
33736 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33738 +int vfsub_symlink(struct inode *dir, struct path *path,
33739 + const char *symname);
33740 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33741 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33742 + struct path *path, struct inode **delegated_inode);
33743 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33744 + struct inode *hdir, struct path *path,
33745 + struct inode **delegated_inode, unsigned int flags);
33746 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33747 +int vfsub_rmdir(struct inode *dir, struct path *path);
33749 +/* ---------------------------------------------------------------------- */
33751 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33753 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33755 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33757 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33759 +int vfsub_flush(struct file *file, fl_owner_t id);
33760 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33762 +static inline loff_t vfsub_f_size_read(struct file *file)
33764 + return i_size_read(file_inode(file));
33767 +static inline unsigned int vfsub_file_flags(struct file *file)
33769 + unsigned int flags;
33771 + spin_lock(&file->f_lock);
33772 + flags = file->f_flags;
33773 + spin_unlock(&file->f_lock);
33778 +static inline int vfsub_file_execed(struct file *file)
33780 + /* todo: direct access f_flags */
33781 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33784 +#if 0 /* reserved */
33785 +static inline void vfsub_file_accessed(struct file *h_file)
33787 + file_accessed(h_file);
33788 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33792 +#if 0 /* reserved */
33793 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33794 + struct dentry *h_dentry)
33796 + struct path h_path = {
33797 + .dentry = h_dentry,
33800 + touch_atime(&h_path);
33801 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33805 +static inline int vfsub_update_time(struct inode *h_inode,
33806 + struct timespec64 *ts, int flags)
33808 + return inode_update_time(h_inode, ts, flags);
33809 + /* no vfsub_update_h_iattr() since we don't have struct path */
33812 +#ifdef CONFIG_FS_POSIX_ACL
33813 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
33814 + struct inode *h_inode, umode_t h_mode)
33818 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
33819 + if (err == -EOPNOTSUPP)
33824 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
33825 + struct inode *h_inode, umode_t h_mode);
33828 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33829 + struct pipe_inode_info *pipe, size_t len,
33830 + unsigned int flags);
33831 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33832 + loff_t *ppos, size_t len, unsigned int flags);
33834 +static inline long vfsub_truncate(struct path *path, loff_t length)
33839 + err = vfs_truncate(path, length);
33844 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33845 + struct file *h_file);
33846 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33849 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33852 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33858 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33864 +/* copy_file_range(2) is a systemcall */
33865 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33866 + struct file *dst, loff_t dst_pos,
33867 + size_t len, unsigned int flags)
33872 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33878 +/* ---------------------------------------------------------------------- */
33880 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33885 + err = vfs_llseek(file, offset, origin);
33890 +/* ---------------------------------------------------------------------- */
33892 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33893 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33894 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33895 + struct inode **delegated_inode);
33896 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33897 + struct inode **delegated_inode);
33898 +int vfsub_unlink(struct inode *dir, struct path *path,
33899 + struct inode **delegated_inode, int force);
33901 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33903 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33906 +/* ---------------------------------------------------------------------- */
33908 +static inline int vfsub_setxattr(struct user_namespace *userns,
33909 + struct dentry *dentry, const char *name,
33910 + const void *value, size_t size, int flags)
33915 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
33921 +static inline int vfsub_removexattr(struct user_namespace *userns,
33922 + struct dentry *dentry, const char *name)
33927 + err = vfs_removexattr(userns, dentry, name);
33933 +#endif /* __KERNEL__ */
33934 +#endif /* __AUFS_VFSUB_H__ */
33935 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33936 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33937 +++ linux/fs/aufs/wbr_policy.c 2021-12-03 15:38:59.939980643 +0100
33939 +// SPDX-License-Identifier: GPL-2.0
33941 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33943 + * This program, aufs is free software; you can redistribute it and/or modify
33944 + * it under the terms of the GNU General Public License as published by
33945 + * the Free Software Foundation; either version 2 of the License, or
33946 + * (at your option) any later version.
33948 + * This program is distributed in the hope that it will be useful,
33949 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33950 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33951 + * GNU General Public License for more details.
33953 + * You should have received a copy of the GNU General Public License
33954 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33958 + * policies for selecting one among multiple writable branches
33961 +#include <linux/statfs.h>
33964 +/* subset of cpup_attr() */
33965 +static noinline_for_stack
33966 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33970 + struct inode *h_isrc;
33972 + h_isrc = d_inode(h_src);
33973 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33974 + ia.ia_mode = h_isrc->i_mode;
33975 + ia.ia_uid = h_isrc->i_uid;
33976 + ia.ia_gid = h_isrc->i_gid;
33977 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33978 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33979 + /* no delegation since it is just created */
33980 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33982 + /* is this nfs only? */
33983 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33984 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33985 + ia.ia_mode = h_isrc->i_mode;
33986 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33992 +#define AuCpdown_PARENT_OPQ 1
33993 +#define AuCpdown_WHED (1 << 1)
33994 +#define AuCpdown_MADE_DIR (1 << 2)
33995 +#define AuCpdown_DIROPQ (1 << 3)
33996 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33997 +#define au_fset_cpdown(flags, name) \
33998 + do { (flags) |= AuCpdown_##name; } while (0)
33999 +#define au_fclr_cpdown(flags, name) \
34000 + do { (flags) &= ~AuCpdown_##name; } while (0)
34002 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34003 + unsigned int *flags)
34006 + struct dentry *opq_dentry;
34008 + opq_dentry = au_diropq_create(dentry, bdst);
34009 + err = PTR_ERR(opq_dentry);
34010 + if (IS_ERR(opq_dentry))
34012 + dput(opq_dentry);
34013 + au_fset_cpdown(*flags, DIROPQ);
34019 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34020 + struct inode *dir, aufs_bindex_t bdst)
34023 + struct path h_path;
34024 + struct au_branch *br;
34026 + br = au_sbr(dentry->d_sb, bdst);
34027 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34028 + err = PTR_ERR(h_path.dentry);
34029 + if (IS_ERR(h_path.dentry))
34033 + if (d_is_positive(h_path.dentry)) {
34034 + h_path.mnt = au_br_mnt(br);
34035 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34038 + dput(h_path.dentry);
34044 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34045 + struct au_pin *pin,
34046 + struct dentry *h_parent, void *arg)
34049 + aufs_bindex_t bopq, btop;
34050 + struct path h_path;
34051 + struct dentry *parent;
34052 + struct inode *h_dir, *h_inode, *inode, *dir;
34053 + unsigned int *flags = arg;
34055 + btop = au_dbtop(dentry);
34056 + /* dentry is di-locked */
34057 + parent = dget_parent(dentry);
34058 + dir = d_inode(parent);
34059 + h_dir = d_inode(h_parent);
34060 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34061 + IMustLock(h_dir);
34063 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34064 + if (unlikely(err < 0))
34066 + h_path.dentry = au_h_dptr(dentry, bdst);
34067 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34068 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34069 + if (unlikely(err))
34071 + au_fset_cpdown(*flags, MADE_DIR);
34073 + bopq = au_dbdiropq(dentry);
34074 + au_fclr_cpdown(*flags, WHED);
34075 + au_fclr_cpdown(*flags, DIROPQ);
34076 + if (au_dbwh(dentry) == bdst)
34077 + au_fset_cpdown(*flags, WHED);
34078 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34079 + au_fset_cpdown(*flags, PARENT_OPQ);
34080 + h_inode = d_inode(h_path.dentry);
34081 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34082 + if (au_ftest_cpdown(*flags, WHED)) {
34083 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34084 + if (unlikely(err)) {
34085 + inode_unlock(h_inode);
34090 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34091 + inode_unlock(h_inode);
34092 + if (unlikely(err))
34095 + if (au_ftest_cpdown(*flags, WHED)) {
34096 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34097 + if (unlikely(err))
34101 + inode = d_inode(dentry);
34102 + if (au_ibbot(inode) < bdst)
34103 + au_set_ibbot(inode, bdst);
34104 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34105 + au_hi_flags(inode, /*isdir*/1));
34106 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34107 + goto out; /* success */
34111 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34112 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34113 + rerr = au_diropq_remove(dentry, bdst);
34114 + inode_unlock(h_inode);
34115 + if (unlikely(rerr)) {
34116 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34117 + dentry, bdst, rerr);
34123 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34124 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34125 + if (unlikely(rerr)) {
34126 + AuIOErr("failed removing %pd b%d (%d)\n",
34127 + dentry, bdst, rerr);
34132 + au_set_h_dptr(dentry, bdst, NULL);
34133 + if (au_dbbot(dentry) == bdst)
34134 + au_update_dbbot(dentry);
34140 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34143 + unsigned int flags;
34146 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34151 +/* ---------------------------------------------------------------------- */
34153 +/* policies for create */
34155 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34157 + int err, i, j, ndentry;
34158 + aufs_bindex_t bopq;
34159 + struct au_dcsub_pages dpages;
34160 + struct au_dpage *dpage;
34161 + struct dentry **dentries, *parent, *d;
34163 + err = au_dpages_init(&dpages, GFP_NOFS);
34164 + if (unlikely(err))
34166 + parent = dget_parent(dentry);
34167 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34168 + if (unlikely(err))
34172 + for (i = 0; i < dpages.ndpage; i++) {
34173 + dpage = dpages.dpages + i;
34174 + dentries = dpage->dentries;
34175 + ndentry = dpage->ndentry;
34176 + for (j = 0; j < ndentry; j++) {
34178 + di_read_lock_parent2(d, !AuLock_IR);
34179 + bopq = au_dbdiropq(d);
34180 + di_read_unlock(d, !AuLock_IR);
34181 + if (bopq >= 0 && bopq < err)
34188 + au_dpages_free(&dpages);
34193 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34195 + for (; bindex >= 0; bindex--)
34196 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34201 +/* top down parent */
34202 +static int au_wbr_create_tdp(struct dentry *dentry,
34203 + unsigned int flags __maybe_unused)
34206 + aufs_bindex_t btop, bindex;
34207 + struct super_block *sb;
34208 + struct dentry *parent, *h_parent;
34210 + sb = dentry->d_sb;
34211 + btop = au_dbtop(dentry);
34213 + if (!au_br_rdonly(au_sbr(sb, btop)))
34217 + parent = dget_parent(dentry);
34218 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34219 + h_parent = au_h_dptr(parent, bindex);
34220 + if (!h_parent || d_is_negative(h_parent))
34223 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34230 + /* bottom up here */
34231 + if (unlikely(err < 0)) {
34232 + err = au_wbr_bu(sb, btop - 1);
34234 + err = au_wbr_nonopq(dentry, err);
34238 + AuDbg("b%d\n", err);
34242 +/* ---------------------------------------------------------------------- */
34244 +/* an exception for the policy other than tdp */
34245 +static int au_wbr_create_exp(struct dentry *dentry)
34248 + aufs_bindex_t bwh, bdiropq;
34249 + struct dentry *parent;
34252 + bwh = au_dbwh(dentry);
34253 + parent = dget_parent(dentry);
34254 + bdiropq = au_dbdiropq(parent);
34256 + if (bdiropq >= 0)
34257 + err = min(bdiropq, bwh);
34260 + AuDbg("%d\n", err);
34261 + } else if (bdiropq >= 0) {
34263 + AuDbg("%d\n", err);
34268 + err = au_wbr_nonopq(dentry, err);
34270 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34273 + AuDbg("%d\n", err);
34277 +/* ---------------------------------------------------------------------- */
34280 +static int au_wbr_create_init_rr(struct super_block *sb)
34284 + err = au_wbr_bu(sb, au_sbbot(sb));
34285 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34288 + AuDbg("b%d\n", err);
34292 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34296 + aufs_bindex_t bindex, bbot;
34297 + struct super_block *sb;
34300 + err = au_wbr_create_exp(dentry);
34304 + sb = dentry->d_sb;
34305 + next = &au_sbi(sb)->si_wbr_rr_next;
34306 + bbot = au_sbbot(sb);
34308 + for (bindex = 0; bindex <= bbot; bindex++) {
34309 + if (!au_ftest_wbr(flags, DIR)) {
34310 + err = atomic_dec_return(next) + 1;
34311 + /* modulo for 0 is meaningless */
34312 + if (unlikely(!err))
34313 + err = atomic_dec_return(next) + 1;
34315 + err = atomic_read(next);
34316 + AuDbg("%d\n", err);
34319 + AuDbg("%d\n", err);
34320 + if (!au_br_rdonly(au_sbr(sb, err)))
34326 + err = au_wbr_nonopq(dentry, err);
34329 + AuDbg("%d\n", err);
34333 +/* ---------------------------------------------------------------------- */
34335 +/* most free space */
34336 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34338 + struct super_block *sb;
34339 + struct au_branch *br;
34340 + struct au_wbr_mfs *mfs;
34341 + struct dentry *h_parent;
34342 + aufs_bindex_t bindex, bbot;
34344 + unsigned long long b, bavail;
34345 + struct path h_path;
34346 + /* reduce the stack usage */
34347 + struct kstatfs *st;
34349 + st = kmalloc(sizeof(*st), GFP_NOFS);
34350 + if (unlikely(!st)) {
34351 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34356 + sb = dentry->d_sb;
34357 + mfs = &au_sbi(sb)->si_wbr_mfs;
34358 + MtxMustLock(&mfs->mfs_lock);
34359 + mfs->mfs_bindex = -EROFS;
34360 + mfs->mfsrr_bytes = 0;
34363 + bbot = au_sbbot(sb);
34365 + bindex = au_dbtop(parent);
34366 + bbot = au_dbtaildir(parent);
34369 + for (; bindex <= bbot; bindex++) {
34371 + h_parent = au_h_dptr(parent, bindex);
34372 + if (!h_parent || d_is_negative(h_parent))
34375 + br = au_sbr(sb, bindex);
34376 + if (au_br_rdonly(br))
34379 + /* sb->s_root for NFS is unreliable */
34380 + h_path.mnt = au_br_mnt(br);
34381 + h_path.dentry = h_path.mnt->mnt_root;
34382 + err = vfs_statfs(&h_path, st);
34383 + if (unlikely(err)) {
34384 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34388 + /* when the available size is equal, select the lower one */
34389 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34390 + || sizeof(b) < sizeof(st->f_bsize));
34391 + b = st->f_bavail * st->f_bsize;
34392 + br->br_wbr->wbr_bytes = b;
34393 + if (b >= bavail) {
34395 + mfs->mfs_bindex = bindex;
34396 + mfs->mfs_jiffy = jiffies;
34400 + mfs->mfsrr_bytes = bavail;
34401 + AuDbg("b%d\n", mfs->mfs_bindex);
34402 + au_kfree_rcu(st);
34405 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34408 + struct dentry *parent;
34409 + struct super_block *sb;
34410 + struct au_wbr_mfs *mfs;
34412 + err = au_wbr_create_exp(dentry);
34416 + sb = dentry->d_sb;
34418 + if (au_ftest_wbr(flags, PARENT))
34419 + parent = dget_parent(dentry);
34420 + mfs = &au_sbi(sb)->si_wbr_mfs;
34421 + mutex_lock(&mfs->mfs_lock);
34422 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34423 + || mfs->mfs_bindex < 0
34424 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34425 + au_mfs(dentry, parent);
34426 + mutex_unlock(&mfs->mfs_lock);
34427 + err = mfs->mfs_bindex;
34431 + err = au_wbr_nonopq(dentry, err);
34434 + AuDbg("b%d\n", err);
34438 +static int au_wbr_create_init_mfs(struct super_block *sb)
34440 + struct au_wbr_mfs *mfs;
34442 + mfs = &au_sbi(sb)->si_wbr_mfs;
34443 + mutex_init(&mfs->mfs_lock);
34444 + mfs->mfs_jiffy = 0;
34445 + mfs->mfs_bindex = -EROFS;
34450 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34452 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34456 +/* ---------------------------------------------------------------------- */
34458 +/* top down regardless parent, and then mfs */
34459 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34460 + unsigned int flags __maybe_unused)
34463 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34464 + unsigned long long watermark;
34465 + struct super_block *sb;
34466 + struct au_wbr_mfs *mfs;
34467 + struct au_branch *br;
34468 + struct dentry *parent;
34470 + sb = dentry->d_sb;
34471 + mfs = &au_sbi(sb)->si_wbr_mfs;
34472 + mutex_lock(&mfs->mfs_lock);
34473 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34474 + || mfs->mfs_bindex < 0)
34475 + au_mfs(dentry, /*parent*/NULL);
34476 + watermark = mfs->mfsrr_watermark;
34477 + bmfs = mfs->mfs_bindex;
34478 + mutex_unlock(&mfs->mfs_lock);
34480 + /* another style of au_wbr_create_exp() */
34481 + bwh = au_dbwh(dentry);
34482 + parent = dget_parent(dentry);
34483 + btail = au_dbtaildir(parent);
34484 + if (bwh >= 0 && bwh < btail)
34487 + err = au_wbr_nonopq(dentry, btail);
34488 + if (unlikely(err < 0))
34492 + for (bindex = 0; bindex <= btail; bindex++) {
34493 + br = au_sbr(sb, bindex);
34494 + if (au_br_rdonly(br))
34496 + if (br->br_wbr->wbr_bytes > watermark) {
34507 + AuDbg("b%d\n", err);
34511 +/* ---------------------------------------------------------------------- */
34513 +/* most free space and then round robin */
34514 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34517 + struct au_wbr_mfs *mfs;
34519 + err = au_wbr_create_mfs(dentry, flags);
34521 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34522 + mutex_lock(&mfs->mfs_lock);
34523 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34524 + err = au_wbr_create_rr(dentry, flags);
34525 + mutex_unlock(&mfs->mfs_lock);
34528 + AuDbg("b%d\n", err);
34532 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34536 + au_wbr_create_init_mfs(sb); /* ignore */
34537 + err = au_wbr_create_init_rr(sb);
34542 +/* ---------------------------------------------------------------------- */
34544 +/* top down parent and most free space */
34545 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34548 + unsigned long long b;
34549 + aufs_bindex_t bindex, btop, bbot;
34550 + struct super_block *sb;
34551 + struct dentry *parent, *h_parent;
34552 + struct au_branch *br;
34554 + err = au_wbr_create_tdp(dentry, flags);
34555 + if (unlikely(err < 0))
34557 + parent = dget_parent(dentry);
34558 + btop = au_dbtop(parent);
34559 + bbot = au_dbtaildir(parent);
34560 + if (btop == bbot)
34561 + goto out_parent; /* success */
34563 + e2 = au_wbr_create_mfs(dentry, flags);
34565 + goto out_parent; /* success */
34567 + /* when the available size is equal, select upper one */
34568 + sb = dentry->d_sb;
34569 + br = au_sbr(sb, err);
34570 + b = br->br_wbr->wbr_bytes;
34571 + AuDbg("b%d, %llu\n", err, b);
34573 + for (bindex = btop; bindex <= bbot; bindex++) {
34574 + h_parent = au_h_dptr(parent, bindex);
34575 + if (!h_parent || d_is_negative(h_parent))
34578 + br = au_sbr(sb, bindex);
34579 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34580 + b = br->br_wbr->wbr_bytes;
34582 + AuDbg("b%d, %llu\n", err, b);
34587 + err = au_wbr_nonopq(dentry, err);
34592 + AuDbg("b%d\n", err);
34596 +/* ---------------------------------------------------------------------- */
34599 + * - top down parent
34600 + * - most free space with parent
34601 + * - most free space round-robin regardless parent
34603 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34606 + unsigned long long watermark;
34607 + struct super_block *sb;
34608 + struct au_branch *br;
34609 + struct au_wbr_mfs *mfs;
34611 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34612 + if (unlikely(err < 0))
34615 + sb = dentry->d_sb;
34616 + br = au_sbr(sb, err);
34617 + mfs = &au_sbi(sb)->si_wbr_mfs;
34618 + mutex_lock(&mfs->mfs_lock);
34619 + watermark = mfs->mfsrr_watermark;
34620 + mutex_unlock(&mfs->mfs_lock);
34621 + if (br->br_wbr->wbr_bytes < watermark)
34622 + /* regardless the parent dir */
34623 + err = au_wbr_create_mfsrr(dentry, flags);
34626 + AuDbg("b%d\n", err);
34630 +/* ---------------------------------------------------------------------- */
34632 +/* policies for copyup */
34634 +/* top down parent */
34635 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34637 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34640 +/* bottom up parent */
34641 +static int au_wbr_copyup_bup(struct dentry *dentry)
34644 + aufs_bindex_t bindex, btop;
34645 + struct dentry *parent, *h_parent;
34646 + struct super_block *sb;
34649 + sb = dentry->d_sb;
34650 + parent = dget_parent(dentry);
34651 + btop = au_dbtop(parent);
34652 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34653 + h_parent = au_h_dptr(parent, bindex);
34654 + if (!h_parent || d_is_negative(h_parent))
34657 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34664 + /* bottom up here */
34665 + if (unlikely(err < 0))
34666 + err = au_wbr_bu(sb, btop - 1);
34668 + AuDbg("b%d\n", err);
34673 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34677 + err = au_wbr_bu(dentry->d_sb, btop);
34678 + AuDbg("b%d\n", err);
34680 + err = au_wbr_nonopq(dentry, err);
34682 + AuDbg("b%d\n", err);
34686 +static int au_wbr_copyup_bu(struct dentry *dentry)
34689 + aufs_bindex_t btop;
34691 + btop = au_dbtop(dentry);
34692 + err = au_wbr_do_copyup_bu(dentry, btop);
34696 +/* ---------------------------------------------------------------------- */
34698 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34699 + [AuWbrCopyup_TDP] = {
34700 + .copyup = au_wbr_copyup_tdp
34702 + [AuWbrCopyup_BUP] = {
34703 + .copyup = au_wbr_copyup_bup
34705 + [AuWbrCopyup_BU] = {
34706 + .copyup = au_wbr_copyup_bu
34710 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34711 + [AuWbrCreate_TDP] = {
34712 + .create = au_wbr_create_tdp
34714 + [AuWbrCreate_RR] = {
34715 + .create = au_wbr_create_rr,
34716 + .init = au_wbr_create_init_rr
34718 + [AuWbrCreate_MFS] = {
34719 + .create = au_wbr_create_mfs,
34720 + .init = au_wbr_create_init_mfs,
34721 + .fin = au_wbr_create_fin_mfs
34723 + [AuWbrCreate_MFSV] = {
34724 + .create = au_wbr_create_mfs,
34725 + .init = au_wbr_create_init_mfs,
34726 + .fin = au_wbr_create_fin_mfs
34728 + [AuWbrCreate_MFSRR] = {
34729 + .create = au_wbr_create_mfsrr,
34730 + .init = au_wbr_create_init_mfsrr,
34731 + .fin = au_wbr_create_fin_mfs
34733 + [AuWbrCreate_MFSRRV] = {
34734 + .create = au_wbr_create_mfsrr,
34735 + .init = au_wbr_create_init_mfsrr,
34736 + .fin = au_wbr_create_fin_mfs
34738 + [AuWbrCreate_TDMFS] = {
34739 + .create = au_wbr_create_tdmfs,
34740 + .init = au_wbr_create_init_mfs,
34741 + .fin = au_wbr_create_fin_mfs
34743 + [AuWbrCreate_TDMFSV] = {
34744 + .create = au_wbr_create_tdmfs,
34745 + .init = au_wbr_create_init_mfs,
34746 + .fin = au_wbr_create_fin_mfs
34748 + [AuWbrCreate_PMFS] = {
34749 + .create = au_wbr_create_pmfs,
34750 + .init = au_wbr_create_init_mfs,
34751 + .fin = au_wbr_create_fin_mfs
34753 + [AuWbrCreate_PMFSV] = {
34754 + .create = au_wbr_create_pmfs,
34755 + .init = au_wbr_create_init_mfs,
34756 + .fin = au_wbr_create_fin_mfs
34758 + [AuWbrCreate_PMFSRR] = {
34759 + .create = au_wbr_create_pmfsrr,
34760 + .init = au_wbr_create_init_mfsrr,
34761 + .fin = au_wbr_create_fin_mfs
34763 + [AuWbrCreate_PMFSRRV] = {
34764 + .create = au_wbr_create_pmfsrr,
34765 + .init = au_wbr_create_init_mfsrr,
34766 + .fin = au_wbr_create_fin_mfs
34769 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34770 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34771 +++ linux/fs/aufs/whout.c 2021-12-03 15:40:58.236647297 +0100
34773 +// SPDX-License-Identifier: GPL-2.0
34775 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34777 + * This program, aufs is free software; you can redistribute it and/or modify
34778 + * it under the terms of the GNU General Public License as published by
34779 + * the Free Software Foundation; either version 2 of the License, or
34780 + * (at your option) any later version.
34782 + * This program is distributed in the hope that it will be useful,
34783 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34784 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34785 + * GNU General Public License for more details.
34787 + * You should have received a copy of the GNU General Public License
34788 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34792 + * whiteout for logical deletion and opaque directory
34797 +#define WH_MASK 0444
34800 + * If a directory contains this file, then it is opaque. We start with the
34801 + * .wh. flag so that it is blocked by lookup.
34803 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34804 + sizeof(AUFS_WH_DIROPQ) - 1);
34807 + * generate whiteout name, which is NOT terminated by NULL.
34808 + * @name: original d_name.name
34809 + * @len: original d_name.len
34810 + * @wh: whiteout qstr
34811 + * returns zero when succeeds, otherwise error.
34812 + * succeeded value as wh->name should be freed by kfree().
34814 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34818 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34819 + return -ENAMETOOLONG;
34821 + wh->len = name->len + AUFS_WH_PFX_LEN;
34822 + p = kmalloc(wh->len, GFP_NOFS);
34825 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34826 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34833 +/* ---------------------------------------------------------------------- */
34836 + * test if the @wh_name exists under @h_ppath.
34837 + * @try_sio specifies the necessary of super-io.
34839 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
34840 + struct qstr *wh_name, int try_sio)
34843 + struct dentry *wh_dentry;
34846 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
34848 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
34849 + err = PTR_ERR(wh_dentry);
34850 + if (IS_ERR(wh_dentry)) {
34851 + if (err == -ENAMETOOLONG)
34857 + if (d_is_negative(wh_dentry))
34858 + goto out_wh; /* success */
34861 + if (d_is_reg(wh_dentry))
34862 + goto out_wh; /* success */
34865 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34866 + wh_dentry, d_inode(wh_dentry)->i_mode);
34875 + * test if the @h_path->dentry sets opaque or not.
34877 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
34880 + struct inode *h_dir;
34882 + h_dir = d_inode(h_path->dentry);
34883 + err = au_wh_test(h_userns, h_path, &diropq_name,
34884 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
34889 + * returns a negative dentry whose name is unique and temporary.
34891 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34892 + struct qstr *prefix)
34894 + struct dentry *dentry;
34896 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34898 + /* strict atomic_t is unnecessary here */
34899 + static unsigned short cnt;
34901 + struct path h_ppath;
34902 + struct user_namespace *h_userns;
34904 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34907 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34908 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34909 + dentry = ERR_PTR(-ENAMETOOLONG);
34910 + if (unlikely(qs.len > NAME_MAX))
34912 + dentry = ERR_PTR(-ENOMEM);
34913 + name = kmalloc(qs.len + 1, GFP_NOFS);
34914 + if (unlikely(!name))
34918 + /* doubly whiteout-ed */
34919 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34920 + p = name + AUFS_WH_PFX_LEN * 2;
34921 + memcpy(p, prefix->name, prefix->len);
34922 + p += prefix->len;
34924 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34926 + h_ppath.dentry = h_parent;
34927 + h_ppath.mnt = au_br_mnt(br);
34928 + h_userns = au_br_userns(br);
34930 + for (i = 0; i < 3; i++) {
34931 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34932 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
34933 + if (IS_ERR(dentry) || d_is_negative(dentry))
34937 + /* pr_warn("could not get random name\n"); */
34938 + dentry = ERR_PTR(-EEXIST);
34939 + AuDbg("%.*s\n", AuLNPair(&qs));
34943 + if (name != defname)
34944 + au_kfree_try_rcu(name);
34946 + AuTraceErrPtr(dentry);
34951 + * rename the @h_dentry on @br to the whiteouted temporary name.
34953 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34956 + struct path h_path = {
34957 + .mnt = au_br_mnt(br)
34959 + struct inode *h_dir, *delegated;
34960 + struct dentry *h_parent;
34962 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34963 + h_dir = d_inode(h_parent);
34964 + IMustLock(h_dir);
34966 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34967 + err = PTR_ERR(h_path.dentry);
34968 + if (IS_ERR(h_path.dentry))
34971 + /* under the same dir, no need to lock_rename() */
34972 + delegated = NULL;
34973 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34976 + if (unlikely(err == -EWOULDBLOCK)) {
34977 + pr_warn("cannot retry for NFSv4 delegation"
34978 + " for an internal rename\n");
34981 + dput(h_path.dentry);
34988 +/* ---------------------------------------------------------------------- */
34990 + * functions for removing a whiteout
34993 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34996 + struct inode *delegated;
34999 + * forces superio when the dir has a sticky bit.
35000 + * this may be a violation of unix fs semantics.
35002 + force = (h_dir->i_mode & S_ISVTX)
35003 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35004 + delegated = NULL;
35005 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35006 + if (unlikely(err == -EWOULDBLOCK)) {
35007 + pr_warn("cannot retry for NFSv4 delegation"
35008 + " for an internal unlink\n");
35014 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35015 + struct dentry *dentry)
35019 + err = do_unlink_wh(h_dir, h_path);
35020 + if (!err && dentry)
35021 + au_set_dbwh(dentry, -1);
35026 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35029 + struct path h_path;
35032 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35033 + if (IS_ERR(h_path.dentry))
35034 + err = PTR_ERR(h_path.dentry);
35036 + if (d_is_reg(h_path.dentry)) {
35037 + h_path.mnt = h_ppath->mnt;
35038 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35040 + dput(h_path.dentry);
35046 +/* ---------------------------------------------------------------------- */
35048 + * initialize/clean whiteout for a branch
35051 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35055 + struct inode *delegated;
35057 + if (d_is_negative(whpath->dentry))
35061 + err = vfsub_rmdir(h_dir, whpath);
35063 + delegated = NULL;
35064 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35065 + if (unlikely(err == -EWOULDBLOCK)) {
35066 + pr_warn("cannot retry for NFSv4 delegation"
35067 + " for an internal unlink\n");
35071 + if (unlikely(err))
35072 + pr_warn("failed removing %pd (%d), ignored.\n",
35073 + whpath->dentry, err);
35076 +static int test_linkable(struct dentry *h_root)
35078 + struct inode *h_dir = d_inode(h_root);
35080 + if (h_dir->i_op->link)
35083 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35084 + h_root, au_sbtype(h_root->d_sb));
35085 + return -ENOSYS; /* the branch doesn't have its ->link() */
35088 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35089 +static int au_whdir(struct inode *h_dir, struct path *path)
35094 + if (d_is_negative(path->dentry)) {
35097 + if (au_test_nfs(path->dentry->d_sb))
35099 + err = vfsub_mkdir(h_dir, path, mode);
35100 + } else if (d_is_dir(path->dentry))
35103 + pr_err("unknown %pd exists\n", path->dentry);
35108 +struct au_wh_base {
35109 + const struct qstr *name;
35110 + struct dentry *dentry;
35113 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35114 + struct path *h_path)
35116 + h_path->dentry = base[AuBrWh_BASE].dentry;
35117 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35118 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35119 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35120 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35121 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35125 + * returns tri-state,
35126 + * minus: error, caller should print the message
35128 + * plus: error, caller should NOT print the message
35130 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35131 + int do_plink, struct au_wh_base base[],
35132 + struct path *h_path)
35135 + struct inode *h_dir;
35137 + h_dir = d_inode(h_root);
35138 + h_path->dentry = base[AuBrWh_BASE].dentry;
35139 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35140 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35142 + err = test_linkable(h_root);
35143 + if (unlikely(err)) {
35148 + err = au_whdir(h_dir, h_path);
35149 + if (unlikely(err))
35151 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35153 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35154 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35155 + err = au_whdir(h_dir, h_path);
35156 + if (unlikely(err))
35158 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35165 + * for the moment, aufs supports the branch filesystem which does not support
35166 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35167 + * copyup failed. finally, such filesystem will not be used as the writable
35170 + * returns tri-state, see above.
35172 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35173 + int do_plink, struct au_wh_base base[],
35174 + struct path *h_path)
35177 + struct inode *h_dir;
35179 + WbrWhMustWriteLock(wbr);
35181 + err = test_linkable(h_root);
35182 + if (unlikely(err)) {
35188 + * todo: should this create be done in /sbin/mount.aufs helper?
35191 + h_dir = d_inode(h_root);
35192 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35193 + h_path->dentry = base[AuBrWh_BASE].dentry;
35194 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35195 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35198 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35199 + if (unlikely(err))
35202 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35204 + err = au_whdir(h_dir, h_path);
35205 + if (unlikely(err))
35207 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35209 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35210 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35212 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35213 + err = au_whdir(h_dir, h_path);
35214 + if (unlikely(err))
35216 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35223 + * initialize the whiteout base file/dir for @br.
35225 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35228 + const unsigned char do_plink
35229 + = !!au_opt_test(au_mntflags(sb), PLINK);
35230 + struct inode *h_dir;
35231 + struct path path = br->br_path;
35232 + struct dentry *h_root = path.dentry;
35233 + struct au_wbr *wbr = br->br_wbr;
35234 + static const struct qstr base_name[] = {
35235 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35236 + sizeof(AUFS_BASE_NAME) - 1),
35237 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35238 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35239 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35240 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35242 + struct au_wh_base base[] = {
35243 + [AuBrWh_BASE] = {
35244 + .name = base_name + AuBrWh_BASE,
35247 + [AuBrWh_PLINK] = {
35248 + .name = base_name + AuBrWh_PLINK,
35251 + [AuBrWh_ORPH] = {
35252 + .name = base_name + AuBrWh_ORPH,
35258 + WbrWhMustWriteLock(wbr);
35260 + for (i = 0; i < AuBrWh_Last; i++) {
35261 + /* doubly whiteouted */
35262 + struct dentry *d;
35264 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35265 + err = PTR_ERR(d);
35269 + base[i].dentry = d;
35271 + && wbr->wbr_wh[i]
35272 + && wbr->wbr_wh[i] != base[i].dentry);
35276 + for (i = 0; i < AuBrWh_Last; i++) {
35277 + dput(wbr->wbr_wh[i]);
35278 + wbr->wbr_wh[i] = NULL;
35282 + if (!au_br_writable(br->br_perm)) {
35283 + h_dir = d_inode(h_root);
35284 + au_wh_init_ro(h_dir, base, &path);
35285 + } else if (!au_br_wh_linkable(br->br_perm)) {
35286 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35292 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35298 + goto out; /* success */
35301 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35302 + err, h_root, au_sbtype(h_root->d_sb));
35304 + for (i = 0; i < AuBrWh_Last; i++)
35305 + dput(base[i].dentry);
35309 +/* ---------------------------------------------------------------------- */
35311 + * whiteouts are all hard-linked usually.
35312 + * when its link count reaches a ceiling, we create a new whiteout base
35313 + * asynchronously.
35316 +struct reinit_br_wh {
35317 + struct super_block *sb;
35318 + struct au_branch *br;
35321 +static void reinit_br_wh(void *arg)
35324 + aufs_bindex_t bindex;
35325 + struct path h_path;
35326 + struct reinit_br_wh *a = arg;
35327 + struct au_wbr *wbr;
35328 + struct inode *dir, *delegated;
35329 + struct dentry *h_root;
35330 + struct au_hinode *hdir;
35333 + wbr = a->br->br_wbr;
35334 + /* big aufs lock */
35335 + si_noflush_write_lock(a->sb);
35336 + if (!au_br_writable(a->br->br_perm))
35338 + bindex = au_br_index(a->sb, a->br->br_id);
35339 + if (unlikely(bindex < 0))
35342 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35343 + dir = d_inode(a->sb->s_root);
35344 + hdir = au_hi(dir, bindex);
35345 + h_root = au_h_dptr(a->sb->s_root, bindex);
35346 + AuDebugOn(h_root != au_br_dentry(a->br));
35348 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35349 + wbr_wh_write_lock(wbr);
35350 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35353 + h_path.dentry = wbr->wbr_whbase;
35354 + h_path.mnt = au_br_mnt(a->br);
35355 + delegated = NULL;
35356 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35358 + if (unlikely(err == -EWOULDBLOCK)) {
35359 + pr_warn("cannot retry for NFSv4 delegation"
35360 + " for an internal unlink\n");
35364 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35367 + dput(wbr->wbr_whbase);
35368 + wbr->wbr_whbase = NULL;
35370 + err = au_wh_init(a->br, a->sb);
35371 + wbr_wh_write_unlock(wbr);
35372 + au_hn_inode_unlock(hdir);
35373 + di_read_unlock(a->sb->s_root, AuLock_IR);
35375 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35379 + atomic_dec(&wbr->wbr_wh_running);
35380 + au_lcnt_dec(&a->br->br_count);
35381 + si_write_unlock(a->sb);
35382 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35384 + if (unlikely(err))
35385 + AuIOErr("err %d\n", err);
35388 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35390 + int do_dec, wkq_err;
35391 + struct reinit_br_wh *arg;
35394 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35397 + /* ignore ENOMEM */
35398 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35401 + * dec(wh_running), kfree(arg) and dec(br_count)
35402 + * in reinit function
35406 + au_lcnt_inc(&br->br_count);
35407 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35408 + if (unlikely(wkq_err)) {
35409 + atomic_dec(&br->br_wbr->wbr_wh_running);
35410 + au_lcnt_dec(&br->br_count);
35411 + au_kfree_rcu(arg);
35418 + atomic_dec(&br->br_wbr->wbr_wh_running);
35421 +/* ---------------------------------------------------------------------- */
35424 + * create the whiteout @wh.
35426 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35427 + struct dentry *wh)
35430 + struct path h_path = {
35433 + struct au_branch *br;
35434 + struct au_wbr *wbr;
35435 + struct dentry *h_parent;
35436 + struct inode *h_dir, *delegated;
35438 + h_parent = wh->d_parent; /* dir inode is locked */
35439 + h_dir = d_inode(h_parent);
35440 + IMustLock(h_dir);
35442 + br = au_sbr(sb, bindex);
35443 + h_path.mnt = au_br_mnt(br);
35444 + wbr = br->br_wbr;
35445 + wbr_wh_read_lock(wbr);
35446 + if (wbr->wbr_whbase) {
35447 + delegated = NULL;
35448 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35449 + if (unlikely(err == -EWOULDBLOCK)) {
35450 + pr_warn("cannot retry for NFSv4 delegation"
35451 + " for an internal link\n");
35454 + if (!err || err != -EMLINK)
35457 + /* link count full. re-initialize br_whbase. */
35458 + kick_reinit_br_wh(sb, br);
35461 + /* return this error in this context */
35462 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35464 + au_fhsm_wrote(sb, bindex, /*force*/0);
35467 + wbr_wh_read_unlock(wbr);
35471 +/* ---------------------------------------------------------------------- */
35474 + * create or remove the diropq.
35476 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35477 + unsigned int flags)
35479 + struct dentry *opq_dentry;
35480 + struct super_block *sb;
35481 + struct au_branch *br;
35482 + struct path h_path;
35485 + sb = dentry->d_sb;
35486 + br = au_sbr(sb, bindex);
35487 + h_path.dentry = au_h_dptr(dentry, bindex);
35488 + h_path.mnt = au_br_mnt(br);
35489 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35490 + if (IS_ERR(opq_dentry))
35493 + if (au_ftest_diropq(flags, CREATE)) {
35494 + err = link_or_create_wh(sb, bindex, opq_dentry);
35496 + au_set_dbdiropq(dentry, bindex);
35497 + goto out; /* success */
35500 + h_path.dentry = opq_dentry;
35501 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35503 + au_set_dbdiropq(dentry, -1);
35505 + dput(opq_dentry);
35506 + opq_dentry = ERR_PTR(err);
35509 + return opq_dentry;
35512 +struct do_diropq_args {
35513 + struct dentry **errp;
35514 + struct dentry *dentry;
35515 + aufs_bindex_t bindex;
35516 + unsigned int flags;
35519 +static void call_do_diropq(void *args)
35521 + struct do_diropq_args *a = args;
35522 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35525 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35526 + unsigned int flags)
35528 + struct dentry *diropq, *h_dentry;
35529 + struct user_namespace *h_userns;
35531 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35532 + h_dentry = au_h_dptr(dentry, bindex);
35533 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35534 + MAY_EXEC | MAY_WRITE))
35535 + diropq = do_diropq(dentry, bindex, flags);
35538 + struct do_diropq_args args = {
35540 + .dentry = dentry,
35541 + .bindex = bindex,
35545 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35546 + if (unlikely(wkq_err))
35547 + diropq = ERR_PTR(wkq_err);
35553 +/* ---------------------------------------------------------------------- */
35556 + * lookup whiteout dentry.
35557 + * @h_parent: lower parent dentry which must exist and be locked
35558 + * @base_name: name of dentry which will be whiteouted
35559 + * returns dentry for whiteout.
35561 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35562 + struct au_branch *br)
35565 + struct qstr wh_name;
35566 + struct dentry *wh_dentry;
35567 + struct path h_path;
35569 + err = au_wh_name_alloc(&wh_name, base_name);
35570 + wh_dentry = ERR_PTR(err);
35572 + h_path.dentry = h_parent;
35573 + h_path.mnt = au_br_mnt(br);
35574 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35575 + au_kfree_try_rcu(wh_name.name);
35577 + return wh_dentry;
35581 + * link/create a whiteout for @dentry on @bindex.
35583 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35584 + struct dentry *h_parent)
35586 + struct dentry *wh_dentry;
35587 + struct super_block *sb;
35590 + sb = dentry->d_sb;
35591 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35592 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35593 + err = link_or_create_wh(sb, bindex, wh_dentry);
35595 + au_set_dbwh(dentry, bindex);
35596 + au_fhsm_wrote(sb, bindex, /*force*/0);
35599 + wh_dentry = ERR_PTR(err);
35603 + return wh_dentry;
35606 +/* ---------------------------------------------------------------------- */
35608 +/* Delete all whiteouts in this directory on branch bindex. */
35609 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35610 + aufs_bindex_t bindex)
35613 + unsigned long ul, n;
35614 + struct qstr wh_name;
35616 + struct hlist_head *head;
35617 + struct au_vdir_wh *pos;
35618 + struct au_vdir_destr *str;
35621 + p = (void *)__get_free_page(GFP_NOFS);
35622 + wh_name.name = p;
35623 + if (unlikely(!wh_name.name))
35627 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35628 + p += AUFS_WH_PFX_LEN;
35629 + n = whlist->nh_num;
35630 + head = whlist->nh_head;
35631 + for (ul = 0; !err && ul < n; ul++, head++) {
35632 + hlist_for_each_entry(pos, head, wh_hash) {
35633 + if (pos->wh_bindex != bindex)
35636 + str = &pos->wh_str;
35637 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35638 + memcpy(p, str->name, str->len);
35639 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35640 + err = unlink_wh_name(h_path, &wh_name);
35645 + AuIOErr("whiteout name too long %.*s\n",
35646 + str->len, str->name);
35651 + free_page((unsigned long)wh_name.name);
35657 +struct del_wh_children_args {
35659 + struct path *h_path;
35660 + struct au_nhash *whlist;
35661 + aufs_bindex_t bindex;
35664 +static void call_del_wh_children(void *args)
35666 + struct del_wh_children_args *a = args;
35667 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35670 +/* ---------------------------------------------------------------------- */
35672 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35674 + struct au_whtmp_rmdir *whtmp;
35676 + unsigned int rdhash;
35678 + SiMustAnyLock(sb);
35680 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35681 + if (unlikely(!whtmp)) {
35682 + whtmp = ERR_PTR(-ENOMEM);
35686 + /* no estimation for dir size */
35687 + rdhash = au_sbi(sb)->si_rdhash;
35689 + rdhash = AUFS_RDHASH_DEF;
35690 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35691 + if (unlikely(err)) {
35692 + au_kfree_rcu(whtmp);
35693 + whtmp = ERR_PTR(err);
35700 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35703 + au_lcnt_dec(&whtmp->br->br_count);
35704 + dput(whtmp->wh_dentry);
35705 + iput(whtmp->dir);
35706 + au_nhash_wh_free(&whtmp->whlist);
35707 + au_kfree_rcu(whtmp);
35711 + * rmdir the whiteouted temporary named dir @h_dentry.
35712 + * @whlist: whiteouted children.
35714 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35715 + struct dentry *wh_dentry, struct au_nhash *whlist)
35718 + unsigned int h_nlink;
35719 + struct path wh_path;
35720 + struct inode *wh_inode, *h_dir;
35721 + struct au_branch *br;
35722 + struct user_namespace *h_userns;
35724 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35725 + IMustLock(h_dir);
35727 + br = au_sbr(dir->i_sb, bindex);
35728 + wh_path.dentry = wh_dentry;
35729 + wh_path.mnt = au_br_mnt(br);
35730 + h_userns = au_br_userns(br);
35731 + wh_inode = d_inode(wh_dentry);
35732 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35735 + * someone else might change some whiteouts while we were sleeping.
35736 + * it means this whlist may have an obsoleted entry.
35738 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
35739 + err = del_wh_children(&wh_path, whlist, bindex);
35742 + struct del_wh_children_args args = {
35744 + .h_path = &wh_path,
35745 + .whlist = whlist,
35749 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35750 + if (unlikely(wkq_err))
35753 + inode_unlock(wh_inode);
35756 + h_nlink = h_dir->i_nlink;
35757 + err = vfsub_rmdir(h_dir, &wh_path);
35758 + /* some fs doesn't change the parent nlink in some cases */
35759 + h_nlink -= h_dir->i_nlink;
35763 + if (au_ibtop(dir) == bindex) {
35764 + /* todo: dir->i_mutex is necessary */
35765 + au_cpup_attr_timesizes(dir);
35767 + vfsub_drop_nlink(dir);
35769 + return 0; /* success */
35772 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35776 +static void call_rmdir_whtmp(void *args)
35779 + aufs_bindex_t bindex;
35780 + struct au_whtmp_rmdir *a = args;
35781 + struct super_block *sb;
35782 + struct dentry *h_parent;
35783 + struct inode *h_dir;
35784 + struct au_hinode *hdir;
35786 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35787 + /* inode_lock(a->dir); */
35789 + sb = a->dir->i_sb;
35790 + si_read_lock(sb, !AuLock_FLUSH);
35791 + if (!au_br_writable(a->br->br_perm))
35793 + bindex = au_br_index(sb, a->br->br_id);
35794 + if (unlikely(bindex < 0))
35798 + ii_write_lock_parent(a->dir);
35799 + h_parent = dget_parent(a->wh_dentry);
35800 + h_dir = d_inode(h_parent);
35801 + hdir = au_hi(a->dir, bindex);
35802 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35803 + if (unlikely(err))
35805 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35806 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35809 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35810 + au_hn_inode_unlock(hdir);
35811 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35815 + ii_write_unlock(a->dir);
35817 + /* inode_unlock(a->dir); */
35818 + au_whtmp_rmdir_free(a);
35819 + si_read_unlock(sb);
35820 + au_nwt_done(&au_sbi(sb)->si_nowait);
35821 + if (unlikely(err))
35822 + AuIOErr("err %d\n", err);
35825 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35826 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35829 + struct super_block *sb;
35833 + /* all post-process will be done in do_rmdir_whtmp(). */
35835 + args->dir = au_igrab(dir);
35836 + args->br = au_sbr(sb, bindex);
35837 + au_lcnt_inc(&args->br->br_count);
35838 + args->wh_dentry = dget(wh_dentry);
35839 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35840 + if (unlikely(wkq_err)) {
35841 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35842 + au_whtmp_rmdir_free(args);
35845 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35846 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35847 +++ linux/fs/aufs/whout.h 2021-12-03 15:40:58.236647297 +0100
35849 +/* SPDX-License-Identifier: GPL-2.0 */
35851 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35853 + * This program, aufs is free software; you can redistribute it and/or modify
35854 + * it under the terms of the GNU General Public License as published by
35855 + * the Free Software Foundation; either version 2 of the License, or
35856 + * (at your option) any later version.
35858 + * This program is distributed in the hope that it will be useful,
35859 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35860 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35861 + * GNU General Public License for more details.
35863 + * You should have received a copy of the GNU General Public License
35864 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35868 + * whiteout for logical deletion and opaque directory
35871 +#ifndef __AUFS_WHOUT_H__
35872 +#define __AUFS_WHOUT_H__
35879 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35880 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35881 + struct qstr *wh_name, int try_sio);
35882 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
35884 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35885 + struct qstr *prefix);
35886 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35887 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35888 + struct dentry *dentry);
35889 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35891 +/* diropq flags */
35892 +#define AuDiropq_CREATE 1
35893 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35894 +#define au_fset_diropq(flags, name) \
35895 + do { (flags) |= AuDiropq_##name; } while (0)
35896 +#define au_fclr_diropq(flags, name) \
35897 + do { (flags) &= ~AuDiropq_##name; } while (0)
35899 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35900 + unsigned int flags);
35901 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35902 + struct au_branch *br);
35903 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35904 + struct dentry *h_parent);
35906 +/* real rmdir for the whiteout-ed dir */
35907 +struct au_whtmp_rmdir {
35908 + struct inode *dir;
35909 + struct au_branch *br;
35910 + struct dentry *wh_dentry;
35911 + struct au_nhash whlist;
35914 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35915 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35916 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35917 + struct dentry *wh_dentry, struct au_nhash *whlist);
35918 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35919 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35921 +/* ---------------------------------------------------------------------- */
35923 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35924 + aufs_bindex_t bindex)
35926 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35929 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35931 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35934 +#endif /* __KERNEL__ */
35935 +#endif /* __AUFS_WHOUT_H__ */
35936 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35937 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35938 +++ linux/fs/aufs/wkq.c 2021-12-03 15:38:59.943313977 +0100
35940 +// SPDX-License-Identifier: GPL-2.0
35942 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35944 + * This program, aufs is free software; you can redistribute it and/or modify
35945 + * it under the terms of the GNU General Public License as published by
35946 + * the Free Software Foundation; either version 2 of the License, or
35947 + * (at your option) any later version.
35949 + * This program is distributed in the hope that it will be useful,
35950 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35951 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35952 + * GNU General Public License for more details.
35954 + * You should have received a copy of the GNU General Public License
35955 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35959 + * workqueue for asynchronous/super-io operations
35960 + * todo: try new credential scheme
35963 +#include <linux/module.h>
35966 +/* internal workqueue named AUFS_WKQ_NAME */
35968 +static struct workqueue_struct *au_wkq;
35970 +struct au_wkinfo {
35971 + struct work_struct wk;
35972 + struct kobject *kobj;
35974 + unsigned int flags; /* see wkq.h */
35976 + au_wkq_func_t func;
35979 +#ifdef CONFIG_LOCKDEP
35981 + struct held_lock **hlock;
35984 + struct completion *comp;
35987 +/* ---------------------------------------------------------------------- */
35989 + * Aufs passes some operations to the workqueue such as the internal copyup.
35990 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35991 + * job run by workqueue depends upon the locks acquired in the other task.
35992 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35993 + * information too. And the job in the workqueue restores the info in order to
35994 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35995 + * correctly and expectedly.
35998 +#ifndef CONFIG_LOCKDEP
35999 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36000 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36001 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36002 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36003 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36005 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36007 + wkinfo->hlock = NULL;
36008 + wkinfo->dont_check = 0;
36015 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36017 + static DEFINE_SPINLOCK(spin);
36020 + struct lock_class_key *key;
36022 + { .name = "&sbinfo->si_rwsem" },
36023 + { .name = "&finfo->fi_rwsem" },
36024 + { .name = "&dinfo->di_rwsem" },
36025 + { .name = "&iinfo->ii_rwsem" }
36030 + /* lockless read from 'set.' see below */
36031 + if (set == ARRAY_SIZE(a)) {
36032 + for (i = 0; i < ARRAY_SIZE(a); i++)
36033 + if (a[i].key == key)
36038 + spin_lock(&spin);
36040 + for (i = 0; i < ARRAY_SIZE(a); i++)
36041 + if (a[i].key == key) {
36042 + spin_unlock(&spin);
36045 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36047 + if (unlikely(a[i].key == key)) { /* rare but possible */
36048 + spin_unlock(&spin);
36053 + if (strstr(a[i].name, name)) {
36055 + * the order of these three lines is important for the
36056 + * lockless read above.
36059 + spin_unlock(&spin);
36061 + /* AuDbg("%d, %s\n", set, name); */
36065 + spin_unlock(&spin);
36074 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36077 + struct task_struct *curr;
36078 + struct held_lock **hl, *held_locks, *p;
36082 + wkinfo->dont_check = lockdep_recursing(curr);
36083 + if (wkinfo->dont_check)
36085 + n = curr->lockdep_depth;
36090 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36091 + if (unlikely(!wkinfo->hlock))
36095 +#if 0 /* left for debugging */
36096 + if (0 && au_debug_test())
36097 + lockdep_print_held_locks(curr);
36099 + held_locks = curr->held_locks;
36100 + hl = wkinfo->hlock;
36102 + p = held_locks++;
36103 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36112 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36114 + au_kfree_try_rcu(wkinfo->hlock);
36117 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36119 + struct held_lock *p, **hl = wkinfo->hlock;
36122 + if (wkinfo->dont_check)
36126 + while ((p = *hl++)) { /* assignment */
36127 + subclass = lockdep_hlock_class(p)->subclass;
36128 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36130 + rwsem_acquire_read(p->instance, subclass, 0,
36131 + /*p->acquire_ip*/_RET_IP_);
36133 + rwsem_acquire(p->instance, subclass, 0,
36134 + /*p->acquire_ip*/_RET_IP_);
36138 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36140 + struct held_lock *p, **hl = wkinfo->hlock;
36142 + if (wkinfo->dont_check)
36146 + while ((p = *hl++)) /* assignment */
36147 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36151 +static void wkq_func(struct work_struct *wk)
36153 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36155 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36156 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36158 + au_wkq_lockdep_pre(wkinfo);
36159 + wkinfo->func(wkinfo->args);
36160 + au_wkq_lockdep_post(wkinfo);
36161 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36162 + complete(wkinfo->comp);
36164 + kobject_put(wkinfo->kobj);
36165 + module_put(THIS_MODULE); /* todo: ?? */
36166 + au_kfree_rcu(wkinfo);
36171 + * Since struct completion is large, try allocating it dynamically.
36173 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36175 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36177 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36179 + init_completion(*comp);
36180 + wkinfo->comp = *comp;
36186 +static void au_wkq_comp_free(struct completion *comp)
36188 + au_kfree_rcu(comp);
36191 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36193 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36194 + if (au_wkq_test()) {
36195 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36196 + " due to a dead dir by UDBA,"
36197 + " or async xino write?\n");
36198 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36201 + au_dbg_verify_kthread();
36203 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36204 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36205 + queue_work(au_wkq, &wkinfo->wk);
36207 + INIT_WORK(&wkinfo->wk, wkq_func);
36208 + schedule_work(&wkinfo->wk);
36213 + * Be careful. It is easy to make deadlock happen.
36214 + * processA: lock, wkq and wait
36215 + * processB: wkq and wait, lock in wkq
36218 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36221 + AuWkqCompDeclare(comp);
36222 + struct au_wkinfo wkinfo = {
36228 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36229 + if (unlikely(err))
36231 + err = au_wkq_lockdep_alloc(&wkinfo);
36232 + if (unlikely(err))
36235 + au_wkq_run(&wkinfo);
36236 + /* no timeout, no interrupt */
36237 + wait_for_completion(wkinfo.comp);
36239 + au_wkq_lockdep_free(&wkinfo);
36242 + au_wkq_comp_free(comp);
36244 + destroy_work_on_stack(&wkinfo.wk);
36249 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36250 + * problem in a concurrent umounting.
36252 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36253 + unsigned int flags)
36256 + struct au_wkinfo *wkinfo;
36258 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36261 + * wkq_func() must free this wkinfo.
36262 + * it highly depends upon the implementation of workqueue.
36265 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36267 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36268 + wkinfo->flags = flags & ~AuWkq_WAIT;
36269 + wkinfo->func = func;
36270 + wkinfo->args = args;
36271 + wkinfo->comp = NULL;
36272 + au_wkq_lockdep_init(wkinfo);
36273 + kobject_get(wkinfo->kobj);
36274 + __module_get(THIS_MODULE); /* todo: ?? */
36276 + au_wkq_run(wkinfo);
36279 + au_nwt_done(&au_sbi(sb)->si_nowait);
36285 +/* ---------------------------------------------------------------------- */
36287 +void au_nwt_init(struct au_nowait_tasks *nwt)
36289 + atomic_set(&nwt->nw_len, 0);
36290 + /* smp_mb(); */ /* atomic_set */
36291 + init_waitqueue_head(&nwt->nw_wq);
36294 +void au_wkq_fin(void)
36296 + destroy_workqueue(au_wkq);
36299 +int __init au_wkq_init(void)
36304 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36305 + if (IS_ERR(au_wkq))
36306 + err = PTR_ERR(au_wkq);
36307 + else if (!au_wkq)
36312 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36313 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36314 +++ linux/fs/aufs/wkq.h 2021-12-03 15:38:59.943313977 +0100
36316 +/* SPDX-License-Identifier: GPL-2.0 */
36318 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36320 + * This program, aufs is free software; you can redistribute it and/or modify
36321 + * it under the terms of the GNU General Public License as published by
36322 + * the Free Software Foundation; either version 2 of the License, or
36323 + * (at your option) any later version.
36325 + * This program is distributed in the hope that it will be useful,
36326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36328 + * GNU General Public License for more details.
36330 + * You should have received a copy of the GNU General Public License
36331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36335 + * workqueue for asynchronous/super-io operations
36336 + * todo: try new credentials management scheme
36339 +#ifndef __AUFS_WKQ_H__
36340 +#define __AUFS_WKQ_H__
36344 +#include <linux/wait.h>
36346 +struct super_block;
36348 +/* ---------------------------------------------------------------------- */
36351 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36353 +struct au_nowait_tasks {
36355 + wait_queue_head_t nw_wq;
36358 +/* ---------------------------------------------------------------------- */
36360 +typedef void (*au_wkq_func_t)(void *args);
36363 +#define AuWkq_WAIT 1
36364 +#define AuWkq_NEST (1 << 1)
36365 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36366 +#define au_fset_wkq(flags, name) \
36367 + do { (flags) |= AuWkq_##name; } while (0)
36368 +#define au_fclr_wkq(flags, name) \
36369 + do { (flags) &= ~AuWkq_##name; } while (0)
36372 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36373 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36374 + unsigned int flags);
36375 +void au_nwt_init(struct au_nowait_tasks *nwt);
36376 +int __init au_wkq_init(void);
36377 +void au_wkq_fin(void);
36379 +/* ---------------------------------------------------------------------- */
36381 +static inline int au_wkq_test(void)
36383 + return current->flags & PF_WQ_WORKER;
36386 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36388 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36391 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36393 + if (atomic_dec_and_test(&nwt->nw_len))
36394 + wake_up_all(&nwt->nw_wq);
36397 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36399 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36403 +#endif /* __KERNEL__ */
36404 +#endif /* __AUFS_WKQ_H__ */
36405 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36406 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36407 +++ linux/fs/aufs/xattr.c 2021-12-03 15:40:58.236647297 +0100
36409 +// SPDX-License-Identifier: GPL-2.0
36411 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36413 + * This program, aufs is free software; you can redistribute it and/or modify
36414 + * it under the terms of the GNU General Public License as published by
36415 + * the Free Software Foundation; either version 2 of the License, or
36416 + * (at your option) any later version.
36418 + * This program is distributed in the hope that it will be useful,
36419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36421 + * GNU General Public License for more details.
36423 + * You should have received a copy of the GNU General Public License
36424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36428 + * handling xattr functions
36431 +#include <linux/fs.h>
36432 +#include <linux/posix_acl_xattr.h>
36433 +#include <linux/xattr.h>
36436 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36438 + if (!ignore_flags)
36446 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36451 +#define cmp(brattr, prefix) do { \
36452 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36453 + XATTR_##prefix##_PREFIX_LEN)) { \
36454 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36460 + cmp(SEC, SECURITY);
36461 + cmp(SYS, SYSTEM);
36462 + cmp(TR, TRUSTED);
36466 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36473 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36475 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36476 + char *name, char **buf, unsigned int ignore_flags,
36477 + unsigned int verbose)
36481 + struct inode *h_idst;
36482 + struct dentry *h_dst_dentry, *h_src_dentry;
36483 + struct user_namespace *h_dst_userns, *h_src_userns;
36485 + h_src_userns = mnt_user_ns(h_src->mnt);
36486 + h_src_dentry = h_src->dentry;
36487 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36490 + if (unlikely(err <= 0)) {
36491 + if (err == -ENODATA
36492 + || (err == -EOPNOTSUPP
36493 + && ((ignore_flags & au_xattr_out_of_list)
36494 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36495 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36497 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36500 + if (err && (verbose || au_debug_test()))
36501 + pr_err("%s, err %d\n", name, err);
36505 + /* unlock it temporary */
36506 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36507 + h_dst_dentry = h_dst->dentry;
36508 + h_idst = d_inode(h_dst_dentry);
36509 + inode_unlock(h_idst);
36510 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36512 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36513 + if (unlikely(err)) {
36514 + if (verbose || au_debug_test())
36515 + pr_err("%s, err %d\n", name, err);
36516 + err = au_xattr_ignore(err, name, ignore_flags);
36523 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36524 + unsigned int verbose)
36526 + int err, unlocked, acl_access, acl_default;
36528 + struct dentry *h_dst_dentry, *h_src_dentry;
36529 + struct inode *h_isrc, *h_idst;
36530 + char *value, *p, *o, *e;
36532 + /* try stopping to update the source inode while we are referencing */
36533 + /* there should not be the parent-child relationship between them */
36534 + h_dst_dentry = h_dst->dentry;
36535 + h_idst = d_inode(h_dst_dentry);
36536 + h_src_dentry = h_src->dentry;
36537 + h_isrc = d_inode(h_src_dentry);
36538 + inode_unlock(h_idst);
36539 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36540 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36543 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36544 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36546 + if (unlikely(err < 0)) {
36548 + if (err == -ENODATA
36549 + || err == -EOPNOTSUPP)
36550 + err = 0; /* ignore */
36559 + p = kmalloc(ssz, GFP_NOFS);
36561 + if (unlikely(!p))
36563 + err = vfs_listxattr(h_src_dentry, p, ssz);
36565 + inode_unlock_shared(h_isrc);
36567 + AuDbg("err %d, ssz %zd\n", err, ssz);
36568 + if (unlikely(err < 0))
36576 + while (!err && p < e) {
36577 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36578 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36579 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36580 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36582 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36584 + p += strlen(p) + 1;
36587 + ignore_flags |= au_xattr_out_of_list;
36588 + if (!err && !acl_access) {
36589 + err = au_do_cpup_xattr(h_dst, h_src,
36590 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36591 + ignore_flags, verbose);
36594 + if (!err && !acl_default) {
36595 + err = au_do_cpup_xattr(h_dst, h_src,
36596 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36597 + ignore_flags, verbose);
36601 + au_kfree_try_rcu(value);
36604 + au_kfree_try_rcu(o);
36607 + inode_unlock_shared(h_isrc);
36612 +/* ---------------------------------------------------------------------- */
36614 +static int au_smack_reentering(struct super_block *sb)
36616 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36618 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36619 + * i_op->getxattr(). ouch.
36621 + return si_pid_test(sb);
36632 +struct au_lgxattr {
36640 + const char *name;
36647 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36648 + struct au_lgxattr *arg)
36652 + struct path h_path;
36653 + struct super_block *sb;
36655 + sb = dentry->d_sb;
36656 + reenter = au_smack_reentering(sb);
36658 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36659 + if (unlikely(err))
36662 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36663 + if (unlikely(err))
36665 + if (unlikely(!h_path.dentry))
36666 + /* illegally overlapped or something */
36667 + goto out_di; /* pretending success */
36669 + /* always topmost entry only */
36670 + switch (arg->type) {
36671 + case AU_XATTR_LIST:
36672 + err = vfs_listxattr(h_path.dentry,
36673 + arg->u.list.list, arg->u.list.size);
36675 + case AU_XATTR_GET:
36676 + AuDebugOn(d_is_negative(h_path.dentry));
36677 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36678 + arg->u.get.name, arg->u.get.value,
36679 + arg->u.get.size);
36685 + di_read_unlock(dentry, AuLock_IR);
36688 + si_read_unlock(sb);
36694 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36696 + struct au_lgxattr arg = {
36697 + .type = AU_XATTR_LIST,
36704 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36707 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36708 + const char *name, void *value, size_t size)
36710 + struct au_lgxattr arg = {
36711 + .type = AU_XATTR_GET,
36719 + return au_lgxattr(dentry, inode, &arg);
36722 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36723 + const char *name, const void *value, size_t size,
36726 + struct au_sxattr arg = {
36727 + .type = AU_XATTR_SET,
36736 + return au_sxattr(dentry, inode, &arg);
36739 +/* ---------------------------------------------------------------------- */
36741 +static int au_xattr_get(const struct xattr_handler *handler,
36742 + struct dentry *dentry, struct inode *inode,
36743 + const char *name, void *buffer, size_t size)
36745 + return au_getxattr(dentry, inode, name, buffer, size);
36748 +static int au_xattr_set(const struct xattr_handler *handler,
36749 + struct user_namespace *userns,
36750 + struct dentry *dentry, struct inode *inode,
36751 + const char *name, const void *value, size_t size,
36754 + return au_setxattr(dentry, inode, name, value, size, flags);
36757 +static const struct xattr_handler au_xattr_handler = {
36760 + .get = au_xattr_get,
36761 + .set = au_xattr_set
36764 +static const struct xattr_handler *au_xattr_handlers[] = {
36765 +#ifdef CONFIG_FS_POSIX_ACL
36766 + &posix_acl_access_xattr_handler,
36767 + &posix_acl_default_xattr_handler,
36769 + &au_xattr_handler, /* must be last */
36773 +void au_xattr_init(struct super_block *sb)
36775 + sb->s_xattr = au_xattr_handlers;
36777 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36778 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36779 +++ linux/fs/aufs/xino.c 2021-12-03 15:40:58.236647297 +0100
36781 +// SPDX-License-Identifier: GPL-2.0
36783 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36785 + * This program, aufs is free software; you can redistribute it and/or modify
36786 + * it under the terms of the GNU General Public License as published by
36787 + * the Free Software Foundation; either version 2 of the License, or
36788 + * (at your option) any later version.
36790 + * This program is distributed in the hope that it will be useful,
36791 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36792 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36793 + * GNU General Public License for more details.
36795 + * You should have received a copy of the GNU General Public License
36796 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36800 + * external inode number translation table and bitmap
36802 + * things to consider
36804 + * + au_xino object
36805 + * + XINO files (xino, xib, xigen)
36806 + * + dynamic debugfs entries (xiN)
36807 + * + static debugfs entries (xib, xigen)
36808 + * + static sysfs entry (xi_path)
36809 + * - several entry points to handle them.
36810 + * + mount(2) without xino option (default)
36811 + * + mount(2) with xino option
36812 + * + mount(2) with noxino option
36814 + * + remount with add/del branches
36815 + * + remount with xino/noxino options
36818 +#include <linux/seq_file.h>
36819 +#include <linux/statfs.h>
36822 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36823 + aufs_bindex_t bbot,
36824 + struct super_block *h_sb)
36826 + /* todo: try binary-search if the branches are many */
36827 + for (; btop <= bbot; btop++)
36828 + if (h_sb == au_sbr_sb(sb, btop))
36834 + * find another branch who is on the same filesystem of the specified
36835 + * branch{@btgt}. search until @bbot.
36837 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36838 + aufs_bindex_t bbot)
36840 + aufs_bindex_t bindex;
36841 + struct super_block *tgt_sb;
36843 + tgt_sb = au_sbr_sb(sb, btgt);
36844 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36846 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36851 +/* ---------------------------------------------------------------------- */
36854 + * stop unnecessary notify events at creating xino files
36857 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36859 + aufs_bindex_t bfound, bindex, bbot;
36860 + struct dentry *parent;
36861 + struct au_branch *br;
36864 + parent = dentry->d_parent; /* safe d_parent access */
36865 + bbot = au_sbbot(sb);
36866 + for (bindex = 0; bindex <= bbot; bindex++) {
36867 + br = au_sbr(sb, bindex);
36868 + if (au_br_dentry(br) == parent) {
36874 + AuDbg("bfound b%d\n", bfound);
36878 +struct au_xino_lock_dir {
36879 + struct au_hinode *hdir;
36880 + struct dentry *parent;
36881 + struct inode *dir;
36884 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36885 + unsigned int lsc)
36887 + struct dentry *parent;
36888 + struct inode *dir;
36890 + parent = dget_parent(dentry);
36891 + dir = d_inode(parent);
36892 + inode_lock_nested(dir, lsc);
36893 +#if 0 /* it should not happen */
36894 + spin_lock(&dentry->d_lock);
36895 + if (unlikely(dentry->d_parent != parent)) {
36896 + spin_unlock(&dentry->d_lock);
36897 + inode_unlock(dir);
36902 + spin_unlock(&dentry->d_lock);
36909 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36910 + struct au_xino_lock_dir *ldir)
36912 + aufs_bindex_t bindex;
36914 + ldir->hdir = NULL;
36915 + bindex = au_xi_root(sb, xipath->dentry);
36916 + if (bindex >= 0) {
36917 + /* rw branch root */
36918 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36919 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36922 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36924 + ldir->dir = d_inode(ldir->parent);
36928 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36931 + au_hn_inode_unlock(ldir->hdir);
36933 + inode_unlock(ldir->dir);
36934 + dput(ldir->parent);
36938 +/* ---------------------------------------------------------------------- */
36941 + * create and set a new xino file
36943 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36946 + struct file *file;
36947 + struct dentry *h_parent, *d;
36948 + struct inode *h_dir, *inode;
36950 + static DEFINE_MUTEX(mtx);
36953 + * at mount-time, and the xino file is the default path,
36954 + * hnotify is disabled so we have no notify events to ignore.
36955 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36958 + mutex_lock(&mtx);
36959 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36960 + /* | __FMODE_NONOTIFY */,
36962 + if (IS_ERR(file)) {
36964 + mutex_unlock(&mtx);
36966 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36970 + /* keep file count */
36972 + d = file->f_path.dentry;
36973 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36975 + mutex_unlock(&mtx);
36976 + /* mnt_want_write() is unnecessary here */
36977 + h_dir = d_inode(h_parent);
36978 + inode = file_inode(file);
36979 + /* no delegation since it is just created */
36980 + if (inode->i_nlink)
36981 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36983 + inode_unlock(h_dir);
36985 + if (unlikely(err)) {
36987 + pr_err("unlink %s(%d)\n", fpath, err);
36992 + if (unlikely(sb == d->d_sb)) {
36994 + pr_err("%s must be outside\n", fpath);
36997 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36999 + pr_err("xino doesn't support %s(%s)\n",
37000 + fpath, au_sbtype(d->d_sb));
37003 + return file; /* success */
37007 + file = ERR_PTR(err);
37012 + * create a new xinofile at the same place/path as @base.
37014 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37015 + struct file *copy_src)
37017 + struct file *file;
37018 + struct dentry *dentry;
37019 + struct inode *dir, *delegated;
37020 + struct qstr *name;
37021 + struct path ppath, path;
37022 + int err, do_unlock;
37023 + struct au_xino_lock_dir ldir;
37026 + au_xino_lock_dir(sb, base, &ldir);
37027 + dentry = base->dentry;
37028 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37029 + ppath.mnt = base->mnt;
37030 + dir = d_inode(ppath.dentry);
37033 + name = &dentry->d_name;
37034 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37035 + if (IS_ERR(path.dentry)) {
37036 + file = (void *)path.dentry;
37037 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37041 + /* no need to mnt_want_write() since we call dentry_open() later */
37042 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37043 + if (unlikely(err)) {
37044 + file = ERR_PTR(err);
37045 + pr_err("%pd create err %d\n", dentry, err);
37049 + path.mnt = base->mnt;
37050 + file = vfsub_dentry_open(&path,
37051 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37052 + /* | __FMODE_NONOTIFY */);
37053 + if (IS_ERR(file)) {
37054 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37058 + delegated = NULL;
37059 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37060 + au_xino_unlock_dir(&ldir);
37062 + if (unlikely(err == -EWOULDBLOCK)) {
37063 + pr_warn("cannot retry for NFSv4 delegation"
37064 + " for an internal unlink\n");
37067 + if (unlikely(err)) {
37068 + pr_err("%pd unlink err %d\n", dentry, err);
37073 + /* no one can touch copy_src xino */
37074 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37075 + if (unlikely(err)) {
37076 + pr_err("%pd copy err %d\n", dentry, err);
37080 + goto out_dput; /* success */
37084 + file = ERR_PTR(err);
37086 + dput(path.dentry);
37089 + au_xino_unlock_dir(&ldir);
37093 +struct file *au_xino_file1(struct au_xino *xi)
37095 + struct file *file;
37096 + unsigned int u, nfile;
37099 + nfile = xi->xi_nfile;
37100 + for (u = 0; u < nfile; u++) {
37101 + file = xi->xi_file[u];
37109 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37120 + if (idx < xi->xi_nfile) {
37121 + f = xi->xi_file[idx];
37125 + p = au_kzrealloc(xi->xi_file,
37126 + sizeof(*xi->xi_file) * xi->xi_nfile,
37127 + sizeof(*xi->xi_file) * (idx + 1),
37128 + GFP_NOFS, /*may_shrink*/0);
37130 + MtxMustLock(&xi->xi_mtx);
37132 + xi->xi_nfile = idx + 1;
37140 + xi->xi_file[idx] = file;
37147 + * if @xinew->xi is not set, then create new xigen file.
37149 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37151 + struct file *file;
37154 + SiMustAnyLock(sb);
37156 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37157 + if (IS_ERR(file)) {
37158 + err = PTR_ERR(file);
37159 + pr_err("%s[%d], err %d\n",
37160 + xinew->xi ? "xino" : "xigen",
37161 + xinew->idx, err);
37166 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37169 + /* todo: make xigen file an array */
37170 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37173 + if (unlikely(err))
37174 + file = ERR_PTR(err);
37180 +/* ---------------------------------------------------------------------- */
37183 + * truncate xino files
37185 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37186 + int idx, struct kstatfs *st)
37190 + struct file *file, *new_xino;
37191 + struct au_xi_new xinew = {
37196 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37197 + file = au_xino_file(xinew.xi, idx);
37201 + xinew.base = &file->f_path;
37202 + err = vfs_statfs(xinew.base, st);
37203 + if (unlikely(err)) {
37204 + AuErr1("statfs err %d, ignored\n", err);
37209 + blocks = file_inode(file)->i_blocks;
37210 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37211 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37213 + xinew.copy_src = file;
37214 + new_xino = au_xi_new(sb, &xinew);
37215 + if (IS_ERR(new_xino)) {
37216 + err = PTR_ERR(new_xino);
37217 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37221 + err = vfs_statfs(&new_xino->f_path, st);
37223 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37224 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37225 + st->f_bfree, st->f_blocks);
37227 + AuErr1("statfs err %d, ignored\n", err);
37235 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37238 + unsigned long jiffy;
37239 + aufs_bindex_t bbot;
37240 + struct kstatfs *st;
37241 + struct au_branch *br;
37242 + struct au_xino *xi;
37245 + st = kmalloc(sizeof(*st), GFP_NOFS);
37246 + if (unlikely(!st))
37250 + bbot = au_sbbot(sb);
37251 + if (unlikely(bindex < 0 || bbot < bindex))
37256 + br = au_sbr(sb, bindex);
37257 + xi = br->br_xino;
37258 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37259 + err = au_xino_do_trunc(sb, bindex, i, st);
37261 + au_sbi(sb)->si_xino_jiffy = jiffy;
37264 + au_kfree_rcu(st);
37269 +struct xino_do_trunc_args {
37270 + struct super_block *sb;
37271 + struct au_branch *br;
37275 +static void xino_do_trunc(void *_args)
37277 + struct xino_do_trunc_args *args = _args;
37278 + struct super_block *sb;
37279 + struct au_branch *br;
37280 + struct inode *dir;
37282 + aufs_bindex_t bindex;
37286 + dir = d_inode(sb->s_root);
37290 + si_noflush_write_lock(sb);
37291 + ii_read_lock_parent(dir);
37292 + bindex = au_br_index(sb, br->br_id);
37293 + err = au_xino_trunc(sb, bindex, idx);
37294 + ii_read_unlock(dir);
37295 + if (unlikely(err))
37296 + pr_warn("err b%d, (%d)\n", bindex, err);
37297 + atomic_dec(&br->br_xino->xi_truncating);
37298 + au_lcnt_dec(&br->br_count);
37299 + si_write_unlock(sb);
37300 + au_nwt_done(&au_sbi(sb)->si_nowait);
37301 + au_kfree_rcu(args);
37305 + * returns the index in the xi_file array whose corresponding file is necessary
37306 + * to truncate, or -1 which means no need to truncate.
37308 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37312 + struct kstatfs st;
37313 + struct au_sbinfo *sbinfo;
37314 + struct au_xino *xi;
37315 + struct file *file;
37317 + /* todo: si_xino_expire and the ratio should be customizable */
37318 + sbinfo = au_sbi(sb);
37319 + if (time_before(jiffies,
37320 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37323 + /* truncation border */
37324 + xi = br->br_xino;
37325 + for (u = 0; u < xi->xi_nfile; u++) {
37326 + file = au_xino_file(xi, u);
37330 + err = vfs_statfs(&file->f_path, &st);
37331 + if (unlikely(err)) {
37332 + AuErr1("statfs err %d, ignored\n", err);
37335 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37336 + >= AUFS_XINO_DEF_TRUNC)
37343 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37346 + struct xino_do_trunc_args *args;
37349 + idx = xino_trunc_test(sb, br);
37353 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37356 + /* lock and kfree() will be called in trunc_xino() */
37357 + args = kmalloc(sizeof(*args), GFP_NOFS);
37358 + if (unlikely(!args)) {
37359 + AuErr1("no memory\n");
37363 + au_lcnt_inc(&br->br_count);
37367 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37369 + return; /* success */
37371 + pr_err("wkq %d\n", wkq_err);
37372 + au_lcnt_dec(&br->br_count);
37373 + au_kfree_rcu(args);
37376 + atomic_dec(&br->br_xino->xi_truncating);
37379 +/* ---------------------------------------------------------------------- */
37381 +struct au_xi_calc {
37386 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37387 + struct au_xi_calc *calc)
37391 + maxent = au_xi_maxent(sb);
37392 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37393 + calc->pos *= sizeof(ino_t);
37396 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37397 + struct au_xi_calc *calc)
37400 + struct file *file;
37401 + struct au_xino *xi = br->br_xino;
37402 + struct au_xi_new xinew = {
37406 + SiMustAnyLock(sb);
37412 + mutex_lock(&xi->xi_mtx);
37413 + file = au_xino_file(xi, calc->idx);
37417 + file = au_xino_file(xi, /*idx*/-1);
37418 + AuDebugOn(!file);
37419 + xinew.idx = calc->idx;
37420 + xinew.base = &file->f_path;
37421 + /* xinew.copy_src = NULL; */
37422 + file = au_xi_new(sb, &xinew);
37423 + if (IS_ERR(file))
37424 + err = PTR_ERR(file);
37427 + mutex_unlock(&xi->xi_mtx);
37432 +struct au_xino_do_new_async_args {
37433 + struct super_block *sb;
37434 + struct au_branch *br;
37435 + struct au_xi_calc calc;
37439 +struct au_xi_writing {
37440 + struct hlist_bl_node node;
37441 + ino_t h_ino, ino;
37444 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37447 +static void au_xino_call_do_new_async(void *args)
37449 + struct au_xino_do_new_async_args *a = args;
37450 + struct au_branch *br;
37451 + struct super_block *sb;
37452 + struct au_sbinfo *sbi;
37453 + struct inode *root;
37454 + struct file *file;
37455 + struct au_xi_writing *del, *p;
37456 + struct hlist_bl_head *hbl;
37457 + struct hlist_bl_node *pos;
37462 + sbi = au_sbi(sb);
37463 + si_noflush_read_lock(sb);
37464 + root = d_inode(sb->s_root);
37465 + ii_read_lock_child(root);
37466 + err = au_xino_do_new_async(sb, br, &a->calc);
37467 + if (unlikely(err)) {
37468 + AuIOErr("err %d\n", err);
37472 + file = au_xino_file(br->br_xino, a->calc.idx);
37473 + AuDebugOn(!file);
37474 + err = au_xino_do_write(file, &a->calc, a->ino);
37475 + if (unlikely(err)) {
37476 + AuIOErr("err %d\n", err);
37481 + hbl = &br->br_xino->xi_writing;
37482 + hlist_bl_lock(hbl);
37483 + au_hbl_for_each(pos, hbl) {
37484 + p = container_of(pos, struct au_xi_writing, node);
37485 + if (p->ino == a->ino) {
37487 + hlist_bl_del(&p->node);
37491 + hlist_bl_unlock(hbl);
37492 + au_kfree_rcu(del);
37495 + au_lcnt_dec(&br->br_count);
37496 + ii_read_unlock(root);
37497 + si_read_unlock(sb);
37498 + au_nwt_done(&sbi->si_nowait);
37503 + * create a new xino file asynchronously
37505 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37506 + struct au_xi_calc *calc, ino_t ino)
37509 + struct au_xino_do_new_async_args *arg;
37512 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37513 + if (unlikely(!arg))
37518 + arg->calc = *calc;
37520 + au_lcnt_inc(&br->br_count);
37521 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37522 + if (unlikely(err)) {
37523 + pr_err("wkq %d\n", err);
37524 + au_lcnt_dec(&br->br_count);
37525 + au_kfree_rcu(arg);
37533 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37534 + * at the position of @h_ino.
37536 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37541 + struct au_xi_calc calc;
37542 + struct au_sbinfo *sbinfo;
37543 + struct file *file;
37544 + struct au_xino *xi;
37545 + struct hlist_bl_head *hbl;
37546 + struct hlist_bl_node *pos;
37547 + struct au_xi_writing *p;
37550 + if (!au_opt_test(au_mntflags(sb), XINO))
37551 + return 0; /* no xino */
37554 + au_xi_calc(sb, h_ino, &calc);
37555 + xi = au_sbr(sb, bindex)->br_xino;
37556 + file = au_xino_file(xi, calc.idx);
37558 + hbl = &xi->xi_writing;
37559 + hlist_bl_lock(hbl);
37560 + au_hbl_for_each(pos, hbl) {
37561 + p = container_of(pos, struct au_xi_writing, node);
37562 + if (p->h_ino == h_ino) {
37563 + AuDbg("hi%llu, i%llu, found\n",
37564 + (u64)p->h_ino, (u64)p->ino);
37569 + hlist_bl_unlock(hbl);
37571 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37572 + return 0; /* no xino */
37574 + sbinfo = au_sbi(sb);
37575 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37576 + if (sz == sizeof(*ino))
37577 + return 0; /* success */
37580 + if (unlikely(sz >= 0)) {
37582 + AuIOErr("xino read error (%zd)\n", sz);
37587 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37592 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37593 + if (sz == sizeof(ino))
37594 + return 0; /* success */
37596 + AuIOErr("write failed (%zd)\n", sz);
37601 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37602 + * at the position of @h_ino.
37603 + * even if @ino is zero, it is written to the xinofile and means no entry.
37604 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37605 + * try truncating it.
37607 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37611 + unsigned int mnt_flags;
37612 + struct au_xi_calc calc;
37613 + struct file *file;
37614 + struct au_branch *br;
37615 + struct au_xino *xi;
37616 + struct au_xi_writing *p;
37618 + SiMustAnyLock(sb);
37620 + mnt_flags = au_mntflags(sb);
37621 + if (!au_opt_test(mnt_flags, XINO))
37624 + au_xi_calc(sb, h_ino, &calc);
37625 + br = au_sbr(sb, bindex);
37626 + xi = br->br_xino;
37627 + file = au_xino_file(xi, calc.idx);
37629 + /* store the inum pair into the list */
37630 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37631 + p->h_ino = h_ino;
37633 + au_hbl_add(&p->node, &xi->xi_writing);
37635 + /* create and write a new xino file asynchronously */
37636 + err = au_xino_new_async(sb, br, &calc, ino);
37638 + return 0; /* success */
37642 + err = au_xino_do_write(file, &calc, ino);
37644 + br = au_sbr(sb, bindex);
37645 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37646 + && au_test_fs_trunc_xino(au_br_sb(br)))
37647 + xino_try_trunc(sb, br);
37648 + return 0; /* success */
37652 + AuIOErr("write failed (%d)\n", err);
37656 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37659 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37660 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37664 + const int prevent_endless = 10;
37668 + err = vfsub_read_k(file, kbuf, size, pos);
37669 + if (err == -EINTR
37670 + && !au_wkq_test()
37671 + && fatal_signal_pending(current)) {
37672 + err = xino_fread_wkq(file, kbuf, size, pos);
37673 + BUG_ON(err == -EINTR);
37675 + } while (i++ < prevent_endless
37676 + && (err == -EAGAIN || err == -EINTR));
37678 +#if 0 /* reserved for future use */
37680 + fsnotify_access(file->f_path.dentry);
37686 +struct xino_fread_args {
37688 + struct file *file;
37694 +static void call_xino_fread(void *args)
37696 + struct xino_fread_args *a = args;
37697 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37700 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37705 + struct xino_fread_args args = {
37713 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37714 + if (unlikely(wkq_err))
37720 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37723 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37728 + const int prevent_endless = 10;
37732 + err = vfsub_write_k(file, kbuf, size, pos);
37733 + if (err == -EINTR
37734 + && !au_wkq_test()
37735 + && fatal_signal_pending(current)) {
37736 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37737 + BUG_ON(err == -EINTR);
37739 + } while (i++ < prevent_endless
37740 + && (err == -EAGAIN || err == -EINTR));
37742 +#if 0 /* reserved for future use */
37744 + fsnotify_modify(file->f_path.dentry);
37750 +struct do_xino_fwrite_args {
37752 + struct file *file;
37758 +static void call_do_xino_fwrite(void *args)
37760 + struct do_xino_fwrite_args *a = args;
37761 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37764 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37769 + struct do_xino_fwrite_args args = {
37778 + * it breaks RLIMIT_FSIZE and normal user's limit,
37779 + * users should care about quota and real 'filesystem full.'
37781 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37782 + if (unlikely(wkq_err))
37788 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37792 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37794 + err = do_xino_fwrite(file, buf, size, pos);
37798 + err = xino_fwrite_wkq(file, buf, size, pos);
37805 +/* ---------------------------------------------------------------------- */
37808 + * inode number bitmap
37810 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37811 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37815 + AuDebugOn(bit < 0 || page_bits <= bit);
37816 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37820 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37822 + AuDebugOn(ino < AUFS_FIRST_INO);
37823 + ino -= AUFS_FIRST_INO;
37824 + *pindex = ino / page_bits;
37825 + *bit = ino % page_bits;
37828 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37833 + struct au_sbinfo *sbinfo;
37834 + struct file *xib;
37835 + unsigned long *p;
37837 + sbinfo = au_sbi(sb);
37838 + MtxMustLock(&sbinfo->si_xib_mtx);
37839 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37840 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37842 + if (pindex == sbinfo->si_xib_last_pindex)
37845 + xib = sbinfo->si_xib;
37846 + p = sbinfo->si_xib_buf;
37847 + pos = sbinfo->si_xib_last_pindex;
37848 + pos *= PAGE_SIZE;
37849 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37850 + if (unlikely(sz != PAGE_SIZE))
37854 + pos *= PAGE_SIZE;
37855 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37856 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37858 + memset(p, 0, PAGE_SIZE);
37859 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37861 + if (sz == PAGE_SIZE) {
37862 + sbinfo->si_xib_last_pindex = pindex;
37863 + return 0; /* success */
37867 + AuIOErr1("write failed (%zd)\n", sz);
37874 +static void au_xib_clear_bit(struct inode *inode)
37877 + unsigned long pindex;
37878 + struct super_block *sb;
37879 + struct au_sbinfo *sbinfo;
37881 + AuDebugOn(inode->i_nlink);
37883 + sb = inode->i_sb;
37884 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37885 + AuDebugOn(page_bits <= bit);
37886 + sbinfo = au_sbi(sb);
37887 + mutex_lock(&sbinfo->si_xib_mtx);
37888 + err = xib_pindex(sb, pindex);
37890 + clear_bit(bit, sbinfo->si_xib_buf);
37891 + sbinfo->si_xib_next_bit = bit;
37893 + mutex_unlock(&sbinfo->si_xib_mtx);
37896 +/* ---------------------------------------------------------------------- */
37899 + * truncate a xino bitmap file
37903 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37907 + unsigned long pindex;
37908 + loff_t pos, pend;
37909 + struct au_sbinfo *sbinfo;
37911 + unsigned long *p;
37914 + sbinfo = au_sbi(sb);
37915 + MtxMustLock(&sbinfo->si_xib_mtx);
37916 + p = sbinfo->si_xib_buf;
37917 + pend = vfsub_f_size_read(file);
37919 + while (pos < pend) {
37920 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37922 + if (unlikely(sz <= 0))
37926 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37927 + if (unlikely(*ino < AUFS_FIRST_INO))
37930 + xib_calc_bit(*ino, &pindex, &bit);
37931 + AuDebugOn(page_bits <= bit);
37932 + err = xib_pindex(sb, pindex);
37944 +static int xib_restore(struct super_block *sb)
37947 + unsigned int nfile;
37948 + aufs_bindex_t bindex, bbot;
37950 + struct au_branch *br;
37951 + struct au_xino *xi;
37952 + struct file *file;
37955 + page = (void *)__get_free_page(GFP_NOFS);
37956 + if (unlikely(!page))
37960 + bbot = au_sbbot(sb);
37961 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37962 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37963 + br = au_sbr(sb, bindex);
37964 + xi = br->br_xino;
37965 + nfile = xi->xi_nfile;
37966 + for (i = 0; i < nfile; i++) {
37967 + file = au_xino_file(xi, i);
37969 + err = do_xib_restore(sb, file, page);
37972 + AuDbg("skip shared b%d\n", bindex);
37973 + free_page((unsigned long)page);
37979 +int au_xib_trunc(struct super_block *sb)
37984 + struct au_sbinfo *sbinfo;
37985 + unsigned long *p;
37986 + struct file *file;
37988 + SiMustWriteLock(sb);
37991 + sbinfo = au_sbi(sb);
37992 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37995 + file = sbinfo->si_xib;
37996 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37999 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38000 + err = PTR_ERR(file);
38001 + if (IS_ERR(file))
38003 + fput(sbinfo->si_xib);
38004 + sbinfo->si_xib = file;
38006 + p = sbinfo->si_xib_buf;
38007 + memset(p, 0, PAGE_SIZE);
38009 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38010 + if (unlikely(sz != PAGE_SIZE)) {
38012 + AuIOErr("err %d\n", err);
38018 + mutex_lock(&sbinfo->si_xib_mtx);
38019 + /* mnt_want_write() is unnecessary here */
38020 + err = xib_restore(sb);
38021 + mutex_unlock(&sbinfo->si_xib_mtx);
38027 +/* ---------------------------------------------------------------------- */
38029 +struct au_xino *au_xino_alloc(unsigned int nfile)
38031 + struct au_xino *xi;
38033 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38034 + if (unlikely(!xi))
38036 + xi->xi_nfile = nfile;
38037 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38038 + if (unlikely(!xi->xi_file))
38041 + xi->xi_nondir.total = 8; /* initial size */
38042 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38044 + if (unlikely(!xi->xi_nondir.array))
38047 + spin_lock_init(&xi->xi_nondir.spin);
38048 + init_waitqueue_head(&xi->xi_nondir.wqh);
38049 + mutex_init(&xi->xi_mtx);
38050 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38051 + atomic_set(&xi->xi_truncating, 0);
38052 + kref_init(&xi->xi_kref);
38053 + goto out; /* success */
38056 + au_kfree_try_rcu(xi->xi_file);
38058 + au_kfree_rcu(xi);
38064 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38067 + struct au_xino *xi;
38070 + xi = au_xino_alloc(idx + 1);
38071 + if (unlikely(!xi)) {
38078 + xi->xi_file[idx] = file;
38079 + AuDebugOn(br->br_xino);
38080 + br->br_xino = xi;
38086 +static void au_xino_release(struct kref *kref)
38088 + struct au_xino *xi;
38090 + unsigned long ul;
38091 + struct hlist_bl_head *hbl;
38092 + struct hlist_bl_node *pos, *n;
38093 + struct au_xi_writing *p;
38095 + xi = container_of(kref, struct au_xino, xi_kref);
38096 + for (i = 0; i < xi->xi_nfile; i++)
38097 + if (xi->xi_file[i])
38098 + fput(xi->xi_file[i]);
38099 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38100 + AuDebugOn(xi->xi_nondir.array[i]);
38101 + mutex_destroy(&xi->xi_mtx);
38102 + hbl = &xi->xi_writing;
38103 + ul = au_hbl_count(hbl);
38104 + if (unlikely(ul)) {
38105 + pr_warn("xi_writing %lu\n", ul);
38106 + hlist_bl_lock(hbl);
38107 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38108 + hlist_bl_del(&p->node);
38109 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38112 + hlist_bl_unlock(hbl);
38114 + au_kfree_try_rcu(xi->xi_file);
38115 + au_kfree_try_rcu(xi->xi_nondir.array);
38116 + au_kfree_rcu(xi);
38119 +int au_xino_put(struct au_branch *br)
38122 + struct au_xino *xi;
38125 + xi = br->br_xino;
38127 + br->br_xino = NULL;
38128 + ret = kref_put(&xi->xi_kref, au_xino_release);
38134 +/* ---------------------------------------------------------------------- */
38137 + * xino mount option handlers
38141 +static void xino_clear_xib(struct super_block *sb)
38143 + struct au_sbinfo *sbinfo;
38145 + SiMustWriteLock(sb);
38147 + sbinfo = au_sbi(sb);
38148 + if (sbinfo->si_xib)
38149 + fput(sbinfo->si_xib);
38150 + sbinfo->si_xib = NULL;
38151 + if (sbinfo->si_xib_buf)
38152 + free_page((unsigned long)sbinfo->si_xib_buf);
38153 + sbinfo->si_xib_buf = NULL;
38156 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38160 + struct au_sbinfo *sbinfo;
38161 + struct file *file;
38162 + struct super_block *xi_sb;
38164 + SiMustWriteLock(sb);
38166 + sbinfo = au_sbi(sb);
38167 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38168 + err = PTR_ERR(file);
38169 + if (IS_ERR(file))
38171 + if (sbinfo->si_xib)
38172 + fput(sbinfo->si_xib);
38173 + sbinfo->si_xib = file;
38174 + xi_sb = file_inode(file)->i_sb;
38175 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38176 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38178 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38179 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38182 + sbinfo->si_ximaxent /= sizeof(ino_t);
38185 + if (!sbinfo->si_xib_buf)
38186 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38187 + if (unlikely(!sbinfo->si_xib_buf))
38190 + sbinfo->si_xib_last_pindex = 0;
38191 + sbinfo->si_xib_next_bit = 0;
38192 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38194 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38195 + if (unlikely(err != PAGE_SIZE))
38199 + goto out; /* success */
38202 + if (sbinfo->si_xib_buf)
38203 + free_page((unsigned long)sbinfo->si_xib_buf);
38204 + sbinfo->si_xib_buf = NULL;
38208 + fput(sbinfo->si_xib);
38209 + sbinfo->si_xib = NULL;
38215 +/* xino for each branch */
38216 +static void xino_clear_br(struct super_block *sb)
38218 + aufs_bindex_t bindex, bbot;
38219 + struct au_branch *br;
38221 + bbot = au_sbbot(sb);
38222 + for (bindex = 0; bindex <= bbot; bindex++) {
38223 + br = au_sbr(sb, bindex);
38229 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38230 + aufs_bindex_t bshared)
38232 + struct au_branch *brshared;
38234 + brshared = au_sbr(sb, bshared);
38235 + AuDebugOn(!brshared->br_xino);
38236 + AuDebugOn(!brshared->br_xino->xi_file);
38237 + if (br->br_xino != brshared->br_xino) {
38238 + au_xino_get(brshared);
38240 + br->br_xino = brshared->br_xino;
38244 +struct au_xino_do_set_br {
38245 + struct au_branch *br;
38247 + aufs_bindex_t bshared;
38250 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38251 + struct au_xino_do_set_br *args)
38254 + struct au_xi_calc calc;
38255 + struct file *file;
38256 + struct au_branch *br;
38257 + struct au_xi_new xinew = {
38262 + xinew.xi = br->br_xino;
38263 + au_xi_calc(sb, args->h_ino, &calc);
38264 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38265 + if (args->bshared >= 0)
38266 + /* shared xino */
38267 + au_xino_set_br_shared(sb, br, args->bshared);
38268 + else if (!xinew.xi) {
38270 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38271 + if (unlikely(err))
38275 + /* force re-creating */
38276 + xinew.xi = br->br_xino;
38277 + xinew.idx = calc.idx;
38278 + mutex_lock(&xinew.xi->xi_mtx);
38279 + file = au_xi_new(sb, &xinew);
38280 + mutex_unlock(&xinew.xi->xi_mtx);
38281 + err = PTR_ERR(file);
38282 + if (IS_ERR(file))
38284 + AuDebugOn(!file);
38286 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38287 + if (unlikely(err))
38295 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38298 + aufs_bindex_t bindex, bbot;
38299 + struct au_xino_do_set_br args;
38300 + struct inode *inode;
38302 + SiMustWriteLock(sb);
38304 + bbot = au_sbbot(sb);
38305 + inode = d_inode(sb->s_root);
38306 + for (bindex = 0; bindex <= bbot; bindex++) {
38307 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38308 + args.br = au_sbr(sb, bindex);
38309 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38310 + err = au_xino_do_set_br(sb, path, &args);
38311 + if (unlikely(err))
38319 +void au_xino_clr(struct super_block *sb)
38321 + struct au_sbinfo *sbinfo;
38323 + au_xigen_clr(sb);
38324 + xino_clear_xib(sb);
38325 + xino_clear_br(sb);
38326 + dbgaufs_brs_del(sb, 0);
38327 + sbinfo = au_sbi(sb);
38328 + /* lvalue, do not call au_mntflags() */
38329 + au_opt_clr(sbinfo->si_mntflags, XINO);
38332 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38335 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38336 + struct qstr *dname, *cur_name;
38337 + struct file *cur_xino;
38338 + struct au_sbinfo *sbinfo;
38339 + struct path *path, *cur_path;
38341 + SiMustWriteLock(sb);
38344 + sbinfo = au_sbi(sb);
38345 + path = &xiopt->file->f_path;
38346 + dentry = path->dentry;
38347 + parent = dget_parent(dentry);
38350 + cur_xino = sbinfo->si_xib;
38352 + cur_path = &cur_xino->f_path;
38353 + cur_dentry = cur_path->dentry;
38354 + cur_parent = dget_parent(cur_dentry);
38355 + cur_name = &cur_dentry->d_name;
38356 + dname = &dentry->d_name;
38357 + skip = (cur_parent == parent
38358 + && au_qstreq(dname, cur_name));
38359 + dput(cur_parent);
38365 + au_opt_set(sbinfo->si_mntflags, XINO);
38366 + err = au_xino_set_xib(sb, path);
38367 + /* si_x{read,write} are set */
38369 + err = au_xigen_set(sb, path);
38371 + err = au_xino_set_br(sb, path);
38373 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38374 + goto out; /* success */
38378 + AuIOErr("failed setting xino(%d).\n", err);
38387 + * create a xinofile at the default place/path.
38389 +struct file *au_xino_def(struct super_block *sb)
38391 + struct file *file;
38393 + struct au_branch *br;
38394 + struct super_block *h_sb;
38395 + struct path path;
38396 + aufs_bindex_t bbot, bindex, bwr;
38399 + bbot = au_sbbot(sb);
38401 + for (bindex = 0; bindex <= bbot; bindex++) {
38402 + br = au_sbr(sb, bindex);
38403 + if (au_br_writable(br->br_perm)
38404 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38411 + file = ERR_PTR(-ENOMEM);
38412 + page = (void *)__get_free_page(GFP_NOFS);
38413 + if (unlikely(!page))
38415 + path.mnt = au_br_mnt(br);
38416 + path.dentry = au_h_dptr(sb->s_root, bwr);
38417 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38418 + file = (void *)p;
38419 + if (!IS_ERR(p)) {
38420 + strcat(p, "/" AUFS_XINO_FNAME);
38421 + AuDbg("%s\n", p);
38422 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38424 + free_page((unsigned long)page);
38426 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38428 + if (IS_ERR(file))
38430 + h_sb = file->f_path.dentry->d_sb;
38431 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38432 + pr_err("xino doesn't support %s(%s)\n",
38433 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38435 + file = ERR_PTR(-EINVAL);
38443 +/* ---------------------------------------------------------------------- */
38446 + * initialize the xinofile for the specified branch @br
38447 + * at the place/path where @base_file indicates.
38448 + * test whether another branch is on the same filesystem or not,
38449 + * if found then share the xinofile with another branch.
38451 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38452 + struct path *base)
38455 + struct au_xino_do_set_br args = {
38460 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38462 + err = au_xino_do_set_br(sb, base, &args);
38463 + if (unlikely(err))
38469 +/* ---------------------------------------------------------------------- */
38472 + * get an unused inode number from bitmap
38474 +ino_t au_xino_new_ino(struct super_block *sb)
38477 + unsigned long *p, pindex, ul, pend;
38478 + struct au_sbinfo *sbinfo;
38479 + struct file *file;
38480 + int free_bit, err;
38482 + if (!au_opt_test(au_mntflags(sb), XINO))
38483 + return iunique(sb, AUFS_FIRST_INO);
38485 + sbinfo = au_sbi(sb);
38486 + mutex_lock(&sbinfo->si_xib_mtx);
38487 + p = sbinfo->si_xib_buf;
38488 + free_bit = sbinfo->si_xib_next_bit;
38489 + if (free_bit < page_bits && !test_bit(free_bit, p))
38490 + goto out; /* success */
38491 + free_bit = find_first_zero_bit(p, page_bits);
38492 + if (free_bit < page_bits)
38493 + goto out; /* success */
38495 + pindex = sbinfo->si_xib_last_pindex;
38496 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38497 + err = xib_pindex(sb, ul);
38498 + if (unlikely(err))
38500 + free_bit = find_first_zero_bit(p, page_bits);
38501 + if (free_bit < page_bits)
38502 + goto out; /* success */
38505 + file = sbinfo->si_xib;
38506 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38507 + for (ul = pindex + 1; ul <= pend; ul++) {
38508 + err = xib_pindex(sb, ul);
38509 + if (unlikely(err))
38511 + free_bit = find_first_zero_bit(p, page_bits);
38512 + if (free_bit < page_bits)
38513 + goto out; /* success */
38518 + set_bit(free_bit, p);
38519 + sbinfo->si_xib_next_bit = free_bit + 1;
38520 + pindex = sbinfo->si_xib_last_pindex;
38521 + mutex_unlock(&sbinfo->si_xib_mtx);
38522 + ino = xib_calc_ino(pindex, free_bit);
38523 + AuDbg("i%lu\n", (unsigned long)ino);
38526 + mutex_unlock(&sbinfo->si_xib_mtx);
38531 +/* for s_op->delete_inode() */
38532 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38535 + unsigned int mnt_flags;
38536 + aufs_bindex_t bindex, bbot, bi;
38537 + unsigned char try_trunc;
38538 + struct au_iinfo *iinfo;
38539 + struct super_block *sb;
38540 + struct au_hinode *hi;
38541 + struct inode *h_inode;
38542 + struct au_branch *br;
38543 + struct au_xi_calc calc;
38544 + struct file *file;
38546 + AuDebugOn(au_is_bad_inode(inode));
38548 + sb = inode->i_sb;
38549 + mnt_flags = au_mntflags(sb);
38550 + if (!au_opt_test(mnt_flags, XINO)
38551 + || inode->i_ino == AUFS_ROOT_INO)
38555 + au_xigen_inc(inode);
38556 + au_xib_clear_bit(inode);
38559 + iinfo = au_ii(inode);
38560 + bindex = iinfo->ii_btop;
38564 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38565 + hi = au_hinode(iinfo, bindex);
38566 + bbot = iinfo->ii_bbot;
38567 + for (; bindex <= bbot; bindex++, hi++) {
38568 + h_inode = hi->hi_inode;
38570 + || (!unlinked && h_inode->i_nlink))
38573 + /* inode may not be revalidated */
38574 + bi = au_br_index(sb, hi->hi_id);
38578 + br = au_sbr(sb, bi);
38579 + au_xi_calc(sb, h_inode->i_ino, &calc);
38580 + file = au_xino_file(br->br_xino, calc.idx);
38581 + if (IS_ERR_OR_NULL(file))
38584 + err = au_xino_do_write(file, &calc, /*ino*/0);
38585 + if (!err && try_trunc
38586 + && au_test_fs_trunc_xino(au_br_sb(br)))
38587 + xino_try_trunc(sb, br);
38591 +/* ---------------------------------------------------------------------- */
38593 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38595 + int found, total, i;
38598 + total = xi->xi_nondir.total;
38599 + for (i = 0; i < total; i++) {
38600 + if (xi->xi_nondir.array[i] != h_ino)
38609 +static int au_xinondir_expand(struct au_xino *xi)
38614 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38617 + sz = xi->xi_nondir.total * sizeof(ino_t);
38618 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38620 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38621 + /*may_shrink*/0);
38623 + xi->xi_nondir.array = p;
38624 + xi->xi_nondir.total <<= 1;
38625 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38633 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38634 + ino_t h_ino, int idx)
38636 + struct au_xino *xi;
38638 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38639 + xi = au_sbr(sb, bindex)->br_xino;
38640 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38642 + spin_lock(&xi->xi_nondir.spin);
38643 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38644 + xi->xi_nondir.array[idx] = 0;
38645 + spin_unlock(&xi->xi_nondir.spin);
38646 + wake_up_all(&xi->xi_nondir.wqh);
38649 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38652 + int err, found, empty;
38653 + struct au_xino *xi;
38657 + if (!au_opt_test(au_mntflags(sb), XINO))
38658 + goto out; /* no xino */
38660 + xi = au_sbr(sb, bindex)->br_xino;
38663 + spin_lock(&xi->xi_nondir.spin);
38664 + found = au_xinondir_find(xi, h_ino);
38665 + if (found == -1) {
38666 + empty = au_xinondir_find(xi, /*h_ino*/0);
38667 + if (empty == -1) {
38668 + empty = xi->xi_nondir.total;
38669 + err = au_xinondir_expand(xi);
38670 + if (unlikely(err))
38673 + xi->xi_nondir.array[empty] = h_ino;
38676 + spin_unlock(&xi->xi_nondir.spin);
38677 + wait_event(xi->xi_nondir.wqh,
38678 + xi->xi_nondir.array[found] != h_ino);
38683 + spin_unlock(&xi->xi_nondir.spin);
38688 +/* ---------------------------------------------------------------------- */
38690 +int au_xino_path(struct seq_file *seq, struct file *file)
38694 + err = au_seq_path(seq, &file->f_path);
38695 + if (unlikely(err))
38698 +#define Deleted "\\040(deleted)"
38699 + seq->count -= sizeof(Deleted) - 1;
38700 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38701 + sizeof(Deleted) - 1));
38707 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38708 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38709 +++ linux/include/uapi/linux/aufs_type.h 2021-12-03 15:40:58.239980630 +0100
38711 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38713 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38715 + * This program, aufs is free software; you can redistribute it and/or modify
38716 + * it under the terms of the GNU General Public License as published by
38717 + * the Free Software Foundation; either version 2 of the License, or
38718 + * (at your option) any later version.
38720 + * This program is distributed in the hope that it will be useful,
38721 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38722 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38723 + * GNU General Public License for more details.
38725 + * You should have received a copy of the GNU General Public License
38726 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38729 +#ifndef __AUFS_TYPE_H__
38730 +#define __AUFS_TYPE_H__
38732 +#define AUFS_NAME "aufs"
38736 + * define it before including all other headers.
38737 + * sched.h may use pr_* macros before defining "current", so define the
38738 + * no-current version first, and re-define later.
38740 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38741 +#include <linux/sched.h>
38743 +#define pr_fmt(fmt) \
38744 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38745 + (int)sizeof(current->comm), current->comm, current->pid
38746 +#include <linux/limits.h>
38748 +#include <stdint.h>
38749 +#include <sys/types.h>
38750 +#include <limits.h>
38751 +#endif /* __KERNEL__ */
38753 +#define AUFS_VERSION "5.15.5-20211129"
38755 +/* todo? move this to linux-2.6.19/include/magic.h */
38756 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38758 +/* ---------------------------------------------------------------------- */
38761 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38762 +typedef int8_t aufs_bindex_t;
38763 +#define AUFS_BRANCH_MAX 127
38765 +typedef int16_t aufs_bindex_t;
38766 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38767 +#define AUFS_BRANCH_MAX 511
38768 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38769 +#define AUFS_BRANCH_MAX 1023
38770 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38771 +#define AUFS_BRANCH_MAX 32767
38775 +#ifndef AUFS_BRANCH_MAX
38776 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38778 +#endif /* __KERNEL__ */
38780 +/* ---------------------------------------------------------------------- */
38782 +#define AUFS_FSTYPE AUFS_NAME
38784 +#define AUFS_ROOT_INO 2
38785 +#define AUFS_FIRST_INO 11
38787 +#define AUFS_WH_PFX ".wh."
38788 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38789 +#define AUFS_WH_TMP_LEN 4
38790 +/* a limit for rmdir/rename a dir and copyup */
38791 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38792 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38794 + - AUFS_WH_TMP_LEN) /* hex */
38795 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38796 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38797 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38798 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38799 +#define AUFS_DIRWH_DEF 3
38800 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38801 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38802 +#define AUFS_RDBLK_DEF 512 /* bytes */
38803 +#define AUFS_RDHASH_DEF 32
38804 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38805 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38806 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38807 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38808 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38810 +/* pseudo-link maintenace under /proc */
38811 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38812 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38813 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38815 +/* dirren, renamed dir */
38816 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38817 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38818 +/* whiteouted doubly */
38819 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38820 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38822 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38823 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38825 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38826 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38827 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38829 +/* doubly whiteouted */
38830 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38831 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38832 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38834 +/* branch permissions and attributes */
38835 +#define AUFS_BRPERM_RW "rw"
38836 +#define AUFS_BRPERM_RO "ro"
38837 +#define AUFS_BRPERM_RR "rr"
38838 +#define AUFS_BRATTR_COO_REG "coo_reg"
38839 +#define AUFS_BRATTR_COO_ALL "coo_all"
38840 +#define AUFS_BRATTR_FHSM "fhsm"
38841 +#define AUFS_BRATTR_UNPIN "unpin"
38842 +#define AUFS_BRATTR_ICEX "icex"
38843 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38844 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38845 +#define AUFS_BRATTR_ICEX_TR "icextr"
38846 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38847 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38848 +#define AUFS_BRRATTR_WH "wh"
38849 +#define AUFS_BRWATTR_NLWH "nolwh"
38850 +#define AUFS_BRWATTR_MOO "moo"
38852 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38853 +#define AuBrPerm_RO (1 << 1) /* readonly */
38854 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38855 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38857 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38858 +#define AuBrAttr_COO_ALL (1 << 4)
38859 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38861 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38862 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38863 + branch. meaningless since
38864 + linux-3.18-rc1 */
38866 +/* ignore error in copying XATTR */
38867 +#define AuBrAttr_ICEX_SEC (1 << 7)
38868 +#define AuBrAttr_ICEX_SYS (1 << 8)
38869 +#define AuBrAttr_ICEX_TR (1 << 9)
38870 +#define AuBrAttr_ICEX_USR (1 << 10)
38871 +#define AuBrAttr_ICEX_OTH (1 << 11)
38872 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38873 + | AuBrAttr_ICEX_SYS \
38874 + | AuBrAttr_ICEX_TR \
38875 + | AuBrAttr_ICEX_USR \
38876 + | AuBrAttr_ICEX_OTH)
38878 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38879 +#define AuBrRAttr_Mask AuBrRAttr_WH
38881 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38882 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38883 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38885 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38887 +/* #warning test userspace */
38889 +#ifndef CONFIG_AUFS_FHSM
38890 +#undef AuBrAttr_FHSM
38891 +#define AuBrAttr_FHSM 0
38893 +#ifndef CONFIG_AUFS_XATTR
38894 +#undef AuBrAttr_ICEX
38895 +#define AuBrAttr_ICEX 0
38896 +#undef AuBrAttr_ICEX_SEC
38897 +#define AuBrAttr_ICEX_SEC 0
38898 +#undef AuBrAttr_ICEX_SYS
38899 +#define AuBrAttr_ICEX_SYS 0
38900 +#undef AuBrAttr_ICEX_TR
38901 +#define AuBrAttr_ICEX_TR 0
38902 +#undef AuBrAttr_ICEX_USR
38903 +#define AuBrAttr_ICEX_USR 0
38904 +#undef AuBrAttr_ICEX_OTH
38905 +#define AuBrAttr_ICEX_OTH 0
38909 +/* the longest combination */
38910 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38911 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38912 + "+" AUFS_BRATTR_COO_REG \
38913 + "+" AUFS_BRATTR_FHSM \
38914 + "+" AUFS_BRATTR_UNPIN \
38915 + "+" AUFS_BRATTR_ICEX_SEC \
38916 + "+" AUFS_BRATTR_ICEX_SYS \
38917 + "+" AUFS_BRATTR_ICEX_USR \
38918 + "+" AUFS_BRATTR_ICEX_OTH \
38919 + "+" AUFS_BRWATTR_NLWH)
38922 + char a[AuBrPermStrSz];
38923 +} au_br_perm_str_t;
38925 +static inline int au_br_writable(int brperm)
38927 + return brperm & AuBrPerm_RW;
38930 +static inline int au_br_whable(int brperm)
38932 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38935 +static inline int au_br_wh_linkable(int brperm)
38937 + return !(brperm & AuBrWAttr_NoLinkWH);
38940 +static inline int au_br_cmoo(int brperm)
38942 + return brperm & AuBrAttr_CMOO_Mask;
38945 +static inline int au_br_fhsm(int brperm)
38947 + return brperm & AuBrAttr_FHSM;
38950 +/* ---------------------------------------------------------------------- */
38954 + /* readdir in userspace */
38958 + AuCtl_WBR_FD, /* pathconf wrapper */
38959 + AuCtl_IBUSY, /* busy inode */
38960 + AuCtl_MVDOWN, /* move-down */
38961 + AuCtl_BR, /* info about branches */
38962 + AuCtl_FHSM_FD /* connection for fhsm */
38965 +/* borrowed from linux/include/linux/kernel.h */
38967 +#ifdef _GNU_SOURCE
38968 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38970 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38972 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38975 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38977 +#define __aligned(x) __attribute__((aligned(x)))
38982 +#define __packed __attribute__((packed))
38986 +struct au_rdu_cookie {
38991 + uint32_t generation;
38994 +struct au_rdu_ent {
39003 +static inline int au_rdu_len(int nlen)
39005 + /* include the terminating NULL */
39006 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39007 + sizeof(uint64_t));
39010 +union au_rdu_ent_ul {
39011 + struct au_rdu_ent __user *e;
39023 + uint64_t sz; /* AuCtl_RDU */
39024 + uint64_t nent; /* AuCtl_RDU_INO */
39026 + union au_rdu_ent_ul ent;
39027 + uint16_t verify[AufsCtlRduV_End];
39029 + /* input/output */
39033 + union au_rdu_ent_ul tail;
39034 + /* number of entries which were added in a single call */
39039 + struct au_rdu_cookie cookie;
39042 +/* ---------------------------------------------------------------------- */
39044 +/* dirren. the branch is identified by the filename who contains this */
39045 +struct au_drinfo {
39048 + uint8_t oldnamelen;
39049 + uint64_t _padding;
39051 + uint8_t oldname[];
39054 +struct au_drinfo_fdata {
39056 + struct au_drinfo drinfo;
39059 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39061 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39063 +/* ---------------------------------------------------------------------- */
39065 +struct aufs_wbr_fd {
39070 +/* ---------------------------------------------------------------------- */
39072 +struct aufs_ibusy {
39073 + uint64_t ino, h_ino;
39077 +/* ---------------------------------------------------------------------- */
39079 +/* error code for move-down */
39080 +/* the actual message strings are implemented in aufs-util.git */
39082 + EAU_MVDOWN_OPAQUE = 1,
39083 + EAU_MVDOWN_WHITEOUT,
39084 + EAU_MVDOWN_UPPER,
39085 + EAU_MVDOWN_BOTTOM,
39086 + EAU_MVDOWN_NOUPPER,
39087 + EAU_MVDOWN_NOLOWERBR,
39091 +/* flags for move-down */
39092 +#define AUFS_MVDOWN_DMSG 1
39093 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39094 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39095 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39096 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39097 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39098 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39099 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39100 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39101 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39102 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39103 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39104 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39106 +/* index for move-down */
39108 + AUFS_MVDOWN_UPPER,
39109 + AUFS_MVDOWN_LOWER,
39110 + AUFS_MVDOWN_NARRAY
39114 + * additional info of move-down
39115 + * number of free blocks and inodes.
39116 + * subset of struct kstatfs, but smaller and always 64bit.
39118 +struct aufs_stfs {
39119 + uint64_t f_blocks;
39120 + uint64_t f_bavail;
39121 + uint64_t f_files;
39122 + uint64_t f_ffree;
39125 +struct aufs_stbr {
39126 + int16_t brid; /* optional input */
39127 + int16_t bindex; /* output */
39128 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39131 +struct aufs_mvdown {
39132 + uint32_t flags; /* input/output */
39133 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39134 + int8_t au_errno; /* output */
39137 +/* ---------------------------------------------------------------------- */
39139 +union aufs_brinfo {
39140 + /* PATH_MAX may differ between kernel-space and user-space */
39141 + char _spacer[4096];
39149 +/* ---------------------------------------------------------------------- */
39151 +#define AuCtlType 'A'
39152 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39153 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39154 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39155 + struct aufs_wbr_fd)
39156 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39157 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39158 + struct aufs_mvdown)
39159 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39160 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39162 +#endif /* __AUFS_TYPE_H__ */
39163 SPDX-License-Identifier: GPL-2.0
39164 aufs5.15.5 loopback patch
39166 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39167 index c9d1ef703673c..ca8b0b1146a60 100644
39168 --- a/drivers/block/loop.c
39169 +++ b/drivers/block/loop.c
39170 @@ -672,6 +672,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39174 +static struct file *loop_real_file(struct file *file)
39176 + struct file *f = NULL;
39178 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39179 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39183 static void loop_reread_partitions(struct loop_device *lo)
39186 @@ -729,6 +738,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39188 struct file *file = fget(arg);
39189 struct file *old_file;
39190 + struct file *f, *virt_file = NULL, *old_virt_file;
39194 @@ -748,11 +758,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39195 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39198 + f = loop_real_file(file);
39200 + virt_file = file;
39205 error = loop_validate_file(file, bdev);
39209 old_file = lo->lo_backing_file;
39210 + old_virt_file = lo->lo_backing_virt_file;
39214 @@ -765,6 +783,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39215 blk_mq_freeze_queue(lo->lo_queue);
39216 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39217 lo->lo_backing_file = file;
39218 + lo->lo_backing_virt_file = virt_file;
39219 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39220 mapping_set_gfp_mask(file->f_mapping,
39221 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39222 @@ -787,6 +806,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39226 + if (old_virt_file)
39227 + fput(old_virt_file);
39229 loop_reread_partitions(lo);
39231 @@ -795,6 +816,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39232 loop_global_unlock(lo, is_loop);
39240 @@ -1195,6 +1218,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39241 const struct loop_config *config)
39243 struct file *file = fget(config->fd);
39244 + struct file *f, *virt_file = NULL;
39245 struct inode *inode;
39246 struct address_space *mapping;
39248 @@ -1210,6 +1234,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39249 /* This is safe, since we have a reference from open(). */
39250 __module_get(THIS_MODULE);
39252 + f = loop_real_file(file);
39254 + virt_file = file;
39260 * If we don't hold exclusive handle for the device, upgrade to it
39261 * here to avoid changing device under exclusive owner.
39262 @@ -1275,6 +1306,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39263 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39264 lo->lo_device = bdev;
39265 lo->lo_backing_file = file;
39266 + lo->lo_backing_virt_file = virt_file;
39267 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39268 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39270 @@ -1325,6 +1357,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39271 bd_abort_claiming(bdev, loop_configure);
39276 /* This is safe: open() is still holding a reference. */
39277 module_put(THIS_MODULE);
39279 @@ -1333,6 +1367,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39280 static int __loop_clr_fd(struct loop_device *lo, bool release)
39282 struct file *filp = NULL;
39283 + struct file *virt_filp = lo->lo_backing_virt_file;
39284 gfp_t gfp = lo->old_gfp_mask;
39285 struct block_device *bdev = lo->lo_device;
39287 @@ -1384,6 +1419,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39289 spin_lock_irq(&lo->lo_lock);
39290 lo->lo_backing_file = NULL;
39291 + lo->lo_backing_virt_file = NULL;
39292 spin_unlock_irq(&lo->lo_lock);
39294 loop_release_xfer(lo);
39295 @@ -1464,6 +1500,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39304 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39305 index 04c88dd6eabd6..0ff3ba22ee170 100644
39306 --- a/drivers/block/loop.h
39307 +++ b/drivers/block/loop.h
39308 @@ -46,7 +46,7 @@ struct loop_device {
39309 int (*ioctl)(struct loop_device *, int cmd,
39310 unsigned long arg);
39312 - struct file * lo_backing_file;
39313 + struct file *lo_backing_file, *lo_backing_virt_file;
39314 struct block_device *lo_device;
39317 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39318 index 99ceca1440449..e49dfe8550329 100644
39319 --- a/fs/aufs/f_op.c
39320 +++ b/fs/aufs/f_op.c
39321 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39322 if (IS_ERR(h_file))
39325 - if (au_test_loopback_kthread()) {
39326 + if (0 && au_test_loopback_kthread()) {
39327 au_warn_loopback(h_file->f_path.dentry->d_sb);
39328 if (file->f_mapping != h_file->f_mapping) {
39329 file->f_mapping = h_file->f_mapping;
39330 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39331 index 74347bd75b380..5ef888a1d53f4 100644
39332 --- a/fs/aufs/loop.c
39333 +++ b/fs/aufs/loop.c
39334 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39335 symbol_put(loop_backing_file);
39336 au_kfree_try_rcu(au_warn_loopback_array);
39339 +/* ---------------------------------------------------------------------- */
39341 +/* support the loopback block device insude aufs */
39343 +struct file *aufs_real_loop(struct file *file)
39347 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39348 + fi_read_lock(file);
39349 + f = au_hf_top(file);
39350 + fi_read_unlock(file);
39354 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39355 index 7293bee427f96..3345c098d0d47 100644
39356 --- a/fs/aufs/loop.h
39357 +++ b/fs/aufs/loop.h
39358 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39360 int au_loopback_init(void);
39361 void au_loopback_fin(void);
39363 +struct file *aufs_real_loop(struct file *file);
39365 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39367 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39369 AuStubInt0(au_loopback_init, void)
39370 AuStubVoid(au_loopback_fin, void)
39372 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39373 #endif /* BLK_DEV_LOOP */
39375 #endif /* __KERNEL__ */
39376 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39377 index ae38857541533..af32f0960e595 100644
39378 --- a/fs/aufs/super.c
39379 +++ b/fs/aufs/super.c
39380 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39381 .statfs = aufs_statfs,
39382 .put_super = aufs_put_super,
39383 .sync_fs = aufs_sync_fs,
39384 - .remount_fs = aufs_remount_fs
39385 + .remount_fs = aufs_remount_fs,
39386 +#ifdef CONFIG_AUFS_BDEV_LOOP
39387 + .real_loop = aufs_real_loop
39391 /* ---------------------------------------------------------------------- */
39392 diff --git a/include/linux/fs.h b/include/linux/fs.h
39393 index e60d8ad854004..2ac5317f9b795 100644
39394 --- a/include/linux/fs.h
39395 +++ b/include/linux/fs.h
39396 @@ -2226,6 +2226,10 @@ struct super_operations {
39397 struct shrink_control *);
39398 long (*free_cached_objects)(struct super_block *,
39399 struct shrink_control *);
39400 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39402 + struct file *(*real_loop)(struct file *);